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

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

Issue 109413004: Cast:Adding cast_transport_config and cleaning up (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: nits Created 6 years, 11 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 | Annotate | Revision Log
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 "base/bind.h" 7 #include "base/bind.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/message_loop/message_loop.h" 9 #include "base/message_loop/message_loop.h"
10 #include "crypto/encryptor.h" 10 #include "crypto/encryptor.h"
(...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after
284 284
285 void AudioReceiver::PlayoutTimeout() { 285 void AudioReceiver::PlayoutTimeout() {
286 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN)); 286 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN));
287 DCHECK(audio_buffer_) << "Invalid function call in this configuration"; 287 DCHECK(audio_buffer_) << "Invalid function call in this configuration";
288 if (queued_encoded_callbacks_.empty()) { 288 if (queued_encoded_callbacks_.empty()) {
289 // Already released by incoming packet. 289 // Already released by incoming packet.
290 return; 290 return;
291 } 291 }
292 uint32 rtp_timestamp = 0; 292 uint32 rtp_timestamp = 0;
293 bool next_frame = false; 293 bool next_frame = false;
294 scoped_ptr<EncodedAudioFrame> encoded_frame(new EncodedAudioFrame()); 294 scoped_ptr<transport::EncodedAudioFrame> encoded_frame(
295 new transport::EncodedAudioFrame());
295 296
296 if (!audio_buffer_->GetEncodedAudioFrame(encoded_frame.get(), 297 if (!audio_buffer_->GetEncodedAudioFrame(encoded_frame.get(),
297 &rtp_timestamp, &next_frame)) { 298 &rtp_timestamp, &next_frame)) {
298 // We have no audio frames. Wait for new packet(s). 299 // We have no audio frames. Wait for new packet(s).
299 // Since the application can post multiple AudioFrameEncodedCallback and 300 // Since the application can post multiple AudioFrameEncodedCallback and
300 // we only check the next frame to play out we might have multiple timeout 301 // we only check the next frame to play out we might have multiple timeout
301 // events firing after each other; however this should be a rare event. 302 // events firing after each other; however this should be a rare event.
302 VLOG(1) << "Failed to retrieved a complete frame at this point in time"; 303 VLOG(1) << "Failed to retrieved a complete frame at this point in time";
303 return; 304 return;
304 } 305 }
(...skipping 10 matching lines...) Expand all
315 } 316 }
316 } 317 }
317 318
318 void AudioReceiver::GetEncodedAudioFrame( 319 void AudioReceiver::GetEncodedAudioFrame(
319 const AudioFrameEncodedCallback& callback) { 320 const AudioFrameEncodedCallback& callback) {
320 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN)); 321 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN));
321 DCHECK(audio_buffer_) << "Invalid function call in this configuration"; 322 DCHECK(audio_buffer_) << "Invalid function call in this configuration";
322 323
323 uint32 rtp_timestamp = 0; 324 uint32 rtp_timestamp = 0;
324 bool next_frame = false; 325 bool next_frame = false;
325 scoped_ptr<EncodedAudioFrame> encoded_frame(new EncodedAudioFrame()); 326 scoped_ptr<transport::EncodedAudioFrame> encoded_frame(
327 new transport::EncodedAudioFrame());
326 328
327 if (!audio_buffer_->GetEncodedAudioFrame(encoded_frame.get(), 329 if (!audio_buffer_->GetEncodedAudioFrame(encoded_frame.get(),
328 &rtp_timestamp, &next_frame)) { 330 &rtp_timestamp, &next_frame)) {
329 // We have no audio frames. Wait for new packet(s). 331 // We have no audio frames. Wait for new packet(s).
330 VLOG(1) << "Wait for more audio packets in frame"; 332 VLOG(1) << "Wait for more audio packets in frame";
331 queued_encoded_callbacks_.push_back(callback); 333 queued_encoded_callbacks_.push_back(callback);
332 return; 334 return;
333 } 335 }
334 if (decryptor_ && !DecryptAudioFrame(&encoded_frame)) { 336 if (decryptor_ && !DecryptAudioFrame(&encoded_frame)) {
335 // Logging already done. 337 // Logging already done.
336 queued_encoded_callbacks_.push_back(callback); 338 queued_encoded_callbacks_.push_back(callback);
337 return; 339 return;
338 } 340 }
339 if (!PostEncodedAudioFrame(callback, rtp_timestamp, next_frame, 341 if (!PostEncodedAudioFrame(callback, rtp_timestamp, next_frame,
340 &encoded_frame)) { 342 &encoded_frame)) {
341 // We have an audio frame; however we are missing packets and we have time 343 // We have an audio frame; however we are missing packets and we have time
342 // to wait for new packet(s). 344 // to wait for new packet(s).
343 queued_encoded_callbacks_.push_back(callback); 345 queued_encoded_callbacks_.push_back(callback);
344 } 346 }
345 } 347 }
346 348
347 bool AudioReceiver::PostEncodedAudioFrame( 349 bool AudioReceiver::PostEncodedAudioFrame(
348 const AudioFrameEncodedCallback& callback, 350 const AudioFrameEncodedCallback& callback,
349 uint32 rtp_timestamp, 351 uint32 rtp_timestamp,
350 bool next_frame, 352 bool next_frame,
351 scoped_ptr<EncodedAudioFrame>* encoded_frame) { 353 scoped_ptr<transport::EncodedAudioFrame>* encoded_frame) {
352 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN)); 354 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN));
353 DCHECK(audio_buffer_) << "Invalid function call in this configuration"; 355 DCHECK(audio_buffer_) << "Invalid function call in this configuration";
354 356
355 base::TimeTicks now = cast_environment_->Clock()->NowTicks(); 357 base::TimeTicks now = cast_environment_->Clock()->NowTicks();
356 base::TimeTicks playout_time = GetPlayoutTime(now, rtp_timestamp); 358 base::TimeTicks playout_time = GetPlayoutTime(now, rtp_timestamp);
357 base::TimeDelta time_until_playout = playout_time - now; 359 base::TimeDelta time_until_playout = playout_time - now;
358 base::TimeDelta min_wait_delta = 360 base::TimeDelta min_wait_delta =
359 base::TimeDelta::FromMilliseconds(kMaxAudioFrameWaitMs); 361 base::TimeDelta::FromMilliseconds(kMaxAudioFrameWaitMs);
360 362
361 if (!next_frame && (time_until_playout > min_wait_delta)) { 363 if (!next_frame && (time_until_playout > min_wait_delta)) {
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
425 rtp_timestamp_in_ticks + time_offset_ + target_delay_delta_ : now; 427 rtp_timestamp_in_ticks + time_offset_ + target_delay_delta_ : now;
426 } 428 }
427 // Don't allow the playout time to go backwards. 429 // Don't allow the playout time to go backwards.
428 if (last_playout_time_ > playout_time) 430 if (last_playout_time_ > playout_time)
429 playout_time = last_playout_time_; 431 playout_time = last_playout_time_;
430 last_playout_time_ = playout_time; 432 last_playout_time_ = playout_time;
431 return playout_time; 433 return playout_time;
432 } 434 }
433 435
434 bool AudioReceiver::DecryptAudioFrame( 436 bool AudioReceiver::DecryptAudioFrame(
435 scoped_ptr<EncodedAudioFrame>* audio_frame) { 437 scoped_ptr<transport::EncodedAudioFrame>* audio_frame) {
436 DCHECK(decryptor_) << "Invalid state"; 438 DCHECK(decryptor_) << "Invalid state";
437 439
438 if (!decryptor_->SetCounter(GetAesNonce((*audio_frame)->frame_id, 440 if (!decryptor_->SetCounter(GetAesNonce((*audio_frame)->frame_id,
439 iv_mask_))) { 441 iv_mask_))) {
440 NOTREACHED() << "Failed to set counter"; 442 NOTREACHED() << "Failed to set counter";
441 return false; 443 return false;
442 } 444 }
443 std::string decrypted_audio_data; 445 std::string decrypted_audio_data;
444 if (!decryptor_->Decrypt((*audio_frame)->data, &decrypted_audio_data)) { 446 if (!decryptor_->Decrypt((*audio_frame)->data, &decrypted_audio_data)) {
445 VLOG(0) << "Decryption error"; 447 VLOG(0) << "Decryption error";
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
501 } 503 }
502 if (audio_decoder_) { 504 if (audio_decoder_) {
503 // Will only send a message if it is time. 505 // Will only send a message if it is time.
504 audio_decoder_->SendCastMessage(); 506 audio_decoder_->SendCastMessage();
505 } 507 }
506 ScheduleNextCastMessage(); 508 ScheduleNextCastMessage();
507 } 509 }
508 510
509 } // namespace cast 511 } // namespace cast
510 } // namespace media 512 } // namespace media
OLDNEW
« no previous file with comments | « media/cast/audio_receiver/audio_receiver.h ('k') | media/cast/audio_receiver/audio_receiver_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698