OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "media/cast/audio_receiver/audio_receiver.h" | 5 #include "media/cast/audio_receiver/audio_receiver.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
162 void AudioReceiver::EmitAvailableEncodedFrames() { | 162 void AudioReceiver::EmitAvailableEncodedFrames() { |
163 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN)); | 163 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN)); |
164 | 164 |
165 while (!frame_request_queue_.empty()) { | 165 while (!frame_request_queue_.empty()) { |
166 // Attempt to peek at the next completed frame from the |framer_|. | 166 // Attempt to peek at the next completed frame from the |framer_|. |
167 // TODO(miu): We should only be peeking at the metadata, and not copying the | 167 // TODO(miu): We should only be peeking at the metadata, and not copying the |
168 // payload yet! Or, at least, peek using a StringPiece instead of a copy. | 168 // payload yet! Or, at least, peek using a StringPiece instead of a copy. |
169 scoped_ptr<transport::EncodedFrame> encoded_frame( | 169 scoped_ptr<transport::EncodedFrame> encoded_frame( |
170 new transport::EncodedFrame()); | 170 new transport::EncodedFrame()); |
171 bool is_consecutively_next_frame = false; | 171 bool is_consecutively_next_frame = false; |
172 if (!framer_.GetEncodedAudioFrame(encoded_frame.get(), | 172 bool have_multiple_complete_frames = false; |
173 &is_consecutively_next_frame)) { | 173 if (!framer_.GetEncodedFrame(encoded_frame.get(), |
| 174 &is_consecutively_next_frame, |
| 175 &have_multiple_complete_frames)) { |
174 VLOG(1) << "Wait for more audio packets to produce a completed frame."; | 176 VLOG(1) << "Wait for more audio packets to produce a completed frame."; |
175 return; // OnReceivedPayloadData() will invoke this method in the future. | 177 return; // OnReceivedPayloadData() will invoke this method in the future. |
176 } | 178 } |
177 | 179 |
| 180 const base::TimeTicks now = cast_environment_->Clock()->NowTicks(); |
| 181 const base::TimeTicks playout_time = |
| 182 GetPlayoutTime(now, encoded_frame->rtp_timestamp); |
| 183 |
| 184 // If we have multiple decodable frames, and the current frame is |
| 185 // too old, then skip it and decode the next frame instead. |
| 186 if (have_multiple_complete_frames && now > playout_time) { |
| 187 framer_.ReleaseFrame(encoded_frame->frame_id); |
| 188 continue; |
| 189 } |
| 190 |
178 // If |framer_| has a frame ready that is out of sequence, examine the | 191 // If |framer_| has a frame ready that is out of sequence, examine the |
179 // playout time to determine whether it's acceptable to continue, thereby | 192 // playout time to determine whether it's acceptable to continue, thereby |
180 // skipping one or more frames. Skip if the missing frame wouldn't complete | 193 // skipping one or more frames. Skip if the missing frame wouldn't complete |
181 // playing before the start of playback of the available frame. | 194 // playing before the start of playback of the available frame. |
182 const base::TimeTicks now = cast_environment_->Clock()->NowTicks(); | |
183 const base::TimeTicks playout_time = | |
184 GetPlayoutTime(now, encoded_frame->rtp_timestamp); | |
185 if (!is_consecutively_next_frame) { | 195 if (!is_consecutively_next_frame) { |
186 // TODO(miu): Also account for expected decode time here? | 196 // TODO(miu): Also account for expected decode time here? |
187 const base::TimeTicks earliest_possible_end_time_of_missing_frame = | 197 const base::TimeTicks earliest_possible_end_time_of_missing_frame = |
188 now + base::TimeDelta::FromMilliseconds(kTypicalAudioFrameDurationMs); | 198 now + base::TimeDelta::FromMilliseconds(kTypicalAudioFrameDurationMs); |
189 if (earliest_possible_end_time_of_missing_frame < playout_time) { | 199 if (earliest_possible_end_time_of_missing_frame < playout_time) { |
190 VLOG(1) << "Wait for next consecutive frame instead of skipping."; | 200 VLOG(1) << "Wait for next consecutive frame instead of skipping."; |
191 if (!is_waiting_for_consecutive_frame_) { | 201 if (!is_waiting_for_consecutive_frame_) { |
192 is_waiting_for_consecutive_frame_ = true; | 202 is_waiting_for_consecutive_frame_ = true; |
193 cast_environment_->PostDelayedTask( | 203 cast_environment_->PostDelayedTask( |
194 CastEnvironment::MAIN, | 204 CastEnvironment::MAIN, |
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
362 } | 372 } |
363 | 373 |
364 void AudioReceiver::SendNextCastMessage() { | 374 void AudioReceiver::SendNextCastMessage() { |
365 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN)); | 375 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN)); |
366 framer_.SendCastMessage(); // Will only send a message if it is time. | 376 framer_.SendCastMessage(); // Will only send a message if it is time. |
367 ScheduleNextCastMessage(); | 377 ScheduleNextCastMessage(); |
368 } | 378 } |
369 | 379 |
370 } // namespace cast | 380 } // namespace cast |
371 } // namespace media | 381 } // namespace media |
OLD | NEW |