OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/test/fake_media_source.h" | 5 #include "media/cast/test/fake_media_source.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/files/scoped_file.h" | 10 #include "base/files/scoped_file.h" |
(...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
276 inserted_video_frame_queue_.push(video_frame); | 276 inserted_video_frame_queue_.push(video_frame); |
277 video_frame_input_->InsertRawVideoFrame(video_frame, | 277 video_frame_input_->InsertRawVideoFrame(video_frame, |
278 start_time_ + video_time); | 278 start_time_ + video_time); |
279 | 279 |
280 // Send just enough audio data to match next video frame's time. | 280 // Send just enough audio data to match next video frame's time. |
281 base::TimeDelta audio_time = AudioFrameTime(audio_frame_count_); | 281 base::TimeDelta audio_time = AudioFrameTime(audio_frame_count_); |
282 while (audio_time < video_time) { | 282 while (audio_time < video_time) { |
283 if (is_transcoding_audio()) { | 283 if (is_transcoding_audio()) { |
284 Decode(true); | 284 Decode(true); |
285 CHECK(!audio_bus_queue_.empty()) << "No audio decoded."; | 285 CHECK(!audio_bus_queue_.empty()) << "No audio decoded."; |
286 scoped_ptr<AudioBus> bus(audio_bus_queue_.front()); | 286 std::unique_ptr<AudioBus> bus(audio_bus_queue_.front()); |
287 audio_bus_queue_.pop(); | 287 audio_bus_queue_.pop(); |
288 audio_frame_input_->InsertAudio(std::move(bus), start_time_ + audio_time); | 288 audio_frame_input_->InsertAudio(std::move(bus), start_time_ + audio_time); |
289 } else { | 289 } else { |
290 audio_frame_input_->InsertAudio( | 290 audio_frame_input_->InsertAudio( |
291 audio_bus_factory_->NextAudioBus( | 291 audio_bus_factory_->NextAudioBus( |
292 base::TimeDelta::FromMilliseconds(kAudioFrameMs)), | 292 base::TimeDelta::FromMilliseconds(kAudioFrameMs)), |
293 start_time_ + audio_time); | 293 start_time_ + audio_time); |
294 } | 294 } |
295 audio_time = AudioFrameTime(++audio_frame_count_); | 295 audio_time = AudioFrameTime(++audio_frame_count_); |
296 } | 296 } |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
367 if (!is_transcoding_audio()) | 367 if (!is_transcoding_audio()) |
368 return false; | 368 return false; |
369 | 369 |
370 Decode(true); | 370 Decode(true); |
371 if (audio_bus_queue_.empty()) | 371 if (audio_bus_queue_.empty()) |
372 return false; | 372 return false; |
373 | 373 |
374 base::TimeDelta audio_time = audio_sent_ts_->GetTimestamp(); | 374 base::TimeDelta audio_time = audio_sent_ts_->GetTimestamp(); |
375 if (elapsed_time < audio_time) | 375 if (elapsed_time < audio_time) |
376 return false; | 376 return false; |
377 scoped_ptr<AudioBus> bus(audio_bus_queue_.front()); | 377 std::unique_ptr<AudioBus> bus(audio_bus_queue_.front()); |
378 audio_bus_queue_.pop(); | 378 audio_bus_queue_.pop(); |
379 audio_sent_ts_->AddFrames(bus->frames()); | 379 audio_sent_ts_->AddFrames(bus->frames()); |
380 audio_frame_input_->InsertAudio(std::move(bus), start_time_ + audio_time); | 380 audio_frame_input_->InsertAudio(std::move(bus), start_time_ + audio_time); |
381 | 381 |
382 // Make sure queue is not empty. | 382 // Make sure queue is not empty. |
383 Decode(true); | 383 Decode(true); |
384 return true; | 384 return true; |
385 } | 385 } |
386 | 386 |
387 void FakeMediaSource::SendNextFrame() { | 387 void FakeMediaSource::SendNextFrame() { |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
512 } else { | 512 } else { |
513 LOG(WARNING) << "Audio FIFO full; dropping samples."; | 513 LOG(WARNING) << "Audio FIFO full; dropping samples."; |
514 } | 514 } |
515 | 515 |
516 // Make sure there's enough data to resample audio. | 516 // Make sure there's enough data to resample audio. |
517 if (audio_fifo_->frames() < | 517 if (audio_fifo_->frames() < |
518 2 * source_audio_params_.sample_rate() / kAudioPacketsPerSecond) { | 518 2 * source_audio_params_.sample_rate() / kAudioPacketsPerSecond) { |
519 continue; | 519 continue; |
520 } | 520 } |
521 | 521 |
522 scoped_ptr<media::AudioBus> resampled_bus( | 522 std::unique_ptr<media::AudioBus> resampled_bus(media::AudioBus::Create( |
523 media::AudioBus::Create( | 523 output_audio_params_.channels(), |
524 output_audio_params_.channels(), | 524 output_audio_params_.sample_rate() / kAudioPacketsPerSecond)); |
525 output_audio_params_.sample_rate() / kAudioPacketsPerSecond)); | |
526 audio_converter_->Convert(resampled_bus.get()); | 525 audio_converter_->Convert(resampled_bus.get()); |
527 audio_bus_queue_.push(resampled_bus.release()); | 526 audio_bus_queue_.push(resampled_bus.release()); |
528 } | 527 } |
529 } | 528 } |
530 | 529 |
531 void FakeMediaSource::DecodeVideo(ScopedAVPacket packet) { | 530 void FakeMediaSource::DecodeVideo(ScopedAVPacket packet) { |
532 // Video. | 531 // Video. |
533 int got_picture; | 532 int got_picture; |
534 AVFrame* avframe = av_frame_alloc(); | 533 AVFrame* avframe = av_frame_alloc(); |
535 CHECK(avcodec_decode_video2( | 534 CHECK(avcodec_decode_video2( |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
624 AVCodecContext* FakeMediaSource::av_audio_context() { | 623 AVCodecContext* FakeMediaSource::av_audio_context() { |
625 return av_audio_stream()->codec; | 624 return av_audio_stream()->codec; |
626 } | 625 } |
627 | 626 |
628 AVCodecContext* FakeMediaSource::av_video_context() { | 627 AVCodecContext* FakeMediaSource::av_video_context() { |
629 return av_video_stream()->codec; | 628 return av_video_stream()->codec; |
630 } | 629 } |
631 | 630 |
632 } // namespace cast | 631 } // namespace cast |
633 } // namespace media | 632 } // namespace media |
OLD | NEW |