The first two were offensive guard Evan Mathis (Philadelphia Eagles, five years, $25 million) and defensive end Mark Anderson (Buffalo Bills, four years, $27.5 million).
With 42 players under contract, the Ravens are $5.054 million under the NFL salary cap limit.
A former Miami Dolphins first-round draft pick from Ohio State, Ginn, 26, caught 19 passes last season, scoring on both punt and kickoff returns.
He ranked second in the league in punt return yardage with a 13.3 average.
Ginn has caught 159 career passes for 2,047 yards and six touchdowns.
Three years ago, he returned kickoffs for 101 and 100 yards for touchdowns against the New York Jets to tie an NFL record.
“We are glad that Ted has decided to return to the 49ers in 2012,” 49ers general manager Trent Baalke said in a statement. “He is a versatile player and an excellent teammate that will continue to play an important role for us on both offense and special teams.”