Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(19)

Side by Side Diff: media/cast/audio_receiver/audio_receiver.cc

Issue 289483003: Cast: Only ACK decodable frames (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: duplicate logic for audio Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
163 void AudioReceiver::EmitAvailableEncodedFrames() { 163 void AudioReceiver::EmitAvailableEncodedFrames() {
164 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN)); 164 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN));
165 165
166 while (!frame_request_queue_.empty()) { 166 while (!frame_request_queue_.empty()) {
167 // Attempt to peek at the next completed frame from the |framer_|. 167 // Attempt to peek at the next completed frame from the |framer_|.
168 // TODO(miu): We should only be peeking at the metadata, and not copying the 168 // TODO(miu): We should only be peeking at the metadata, and not copying the
169 // payload yet! Or, at least, peek using a StringPiece instead of a copy. 169 // payload yet! Or, at least, peek using a StringPiece instead of a copy.
170 scoped_ptr<transport::EncodedAudioFrame> encoded_frame( 170 scoped_ptr<transport::EncodedAudioFrame> encoded_frame(
171 new transport::EncodedAudioFrame()); 171 new transport::EncodedAudioFrame());
172 bool is_consecutively_next_frame = false; 172 bool is_consecutively_next_frame = false;
173 bool have_multiple_complete_frames = false;
173 if (!framer_.GetEncodedAudioFrame(encoded_frame.get(), 174 if (!framer_.GetEncodedAudioFrame(encoded_frame.get(),
174 &is_consecutively_next_frame)) { 175 &is_consecutively_next_frame,
176 &have_multiple_complete_frames)) {
175 VLOG(1) << "Wait for more audio packets to produce a completed frame."; 177 VLOG(1) << "Wait for more audio packets to produce a completed frame.";
176 return; // OnReceivedPayloadData() will invoke this method in the future. 178 return; // OnReceivedPayloadData() will invoke this method in the future.
177 } 179 }
178 180
181 const base::TimeTicks now = cast_environment_->Clock()->NowTicks();
182 const base::TimeTicks playout_time =
183 GetPlayoutTime(now, encoded_frame->rtp_timestamp);
184
185 // If we have multiple decodable frames, and the current frame is
186 // too old, then skip it and decode the next frame instead.
187 if (have_multiple_complete_frames && now > playout_time) {
188 framer_.ReleaseFrame(encoded_frame->frame_id);
189 continue;
190 }
191
179 // If |framer_| has a frame ready that is out of sequence, examine the 192 // If |framer_| has a frame ready that is out of sequence, examine the
180 // playout time to determine whether it's acceptable to continue, thereby 193 // playout time to determine whether it's acceptable to continue, thereby
181 // skipping one or more frames. Skip if the missing frame wouldn't complete 194 // skipping one or more frames. Skip if the missing frame wouldn't complete
182 // playing before the start of playback of the available frame. 195 // playing before the start of playback of the available frame.
183 const base::TimeTicks now = cast_environment_->Clock()->NowTicks();
184 const base::TimeTicks playout_time =
185 GetPlayoutTime(now, encoded_frame->rtp_timestamp);
186 if (!is_consecutively_next_frame) { 196 if (!is_consecutively_next_frame) {
187 // TODO(miu): Also account for expected decode time here? 197 // TODO(miu): Also account for expected decode time here?
188 const base::TimeTicks earliest_possible_end_time_of_missing_frame = 198 const base::TimeTicks earliest_possible_end_time_of_missing_frame =
189 now + base::TimeDelta::FromMilliseconds(kTypicalAudioFrameDurationMs); 199 now + base::TimeDelta::FromMilliseconds(kTypicalAudioFrameDurationMs);
190 if (earliest_possible_end_time_of_missing_frame < playout_time) { 200 if (earliest_possible_end_time_of_missing_frame < playout_time) {
191 VLOG(1) << "Wait for next consecutive frame instead of skipping."; 201 VLOG(1) << "Wait for next consecutive frame instead of skipping.";
192 if (!is_waiting_for_consecutive_frame_) { 202 if (!is_waiting_for_consecutive_frame_) {
193 is_waiting_for_consecutive_frame_ = true; 203 is_waiting_for_consecutive_frame_ = true;
194 cast_environment_->PostDelayedTask( 204 cast_environment_->PostDelayedTask(
195 CastEnvironment::MAIN, 205 CastEnvironment::MAIN,
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
364 } 374 }
365 375
366 void AudioReceiver::SendNextCastMessage() { 376 void AudioReceiver::SendNextCastMessage() {
367 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN)); 377 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN));
368 framer_.SendCastMessage(); // Will only send a message if it is time. 378 framer_.SendCastMessage(); // Will only send a message if it is time.
369 ScheduleNextCastMessage(); 379 ScheduleNextCastMessage();
370 } 380 }
371 381
372 } // namespace cast 382 } // namespace cast
373 } // namespace media 383 } // namespace media
OLDNEW
« no previous file with comments | « no previous file | media/cast/framer/cast_message_builder.h » ('j') | media/cast/framer/framer_unittest.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698