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 "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/files/scoped_file.h" | 8 #include "base/files/scoped_file.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/rand_util.h" | 10 #include "base/rand_util.h" |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
158 LOG(ERROR) << "Unsupported audio channels layout."; | 158 LOG(ERROR) << "Unsupported audio channels layout."; |
159 continue; | 159 continue; |
160 } | 160 } |
161 if (audio_stream_index_ != -1) { | 161 if (audio_stream_index_ != -1) { |
162 LOG(WARNING) << "Found multiple audio streams."; | 162 LOG(WARNING) << "Found multiple audio streams."; |
163 } | 163 } |
164 audio_stream_index_ = static_cast<int>(i); | 164 audio_stream_index_ = static_cast<int>(i); |
165 source_audio_params_.Reset( | 165 source_audio_params_.Reset( |
166 AudioParameters::AUDIO_PCM_LINEAR, | 166 AudioParameters::AUDIO_PCM_LINEAR, |
167 layout, | 167 layout, |
168 av_codec_context->channels, | |
169 av_codec_context->sample_rate, | 168 av_codec_context->sample_rate, |
170 8 * av_get_bytes_per_sample(av_codec_context->sample_fmt), | 169 8 * av_get_bytes_per_sample(av_codec_context->sample_fmt), |
171 av_codec_context->sample_rate / kAudioPacketsPerSecond); | 170 av_codec_context->sample_rate / kAudioPacketsPerSecond); |
| 171 source_audio_params_.set_channels_for_discrete( |
| 172 av_codec_context->channels); |
172 CHECK(source_audio_params_.IsValid()); | 173 CHECK(source_audio_params_.IsValid()); |
173 LOG(INFO) << "Source file has audio."; | 174 LOG(INFO) << "Source file has audio."; |
174 } else if (av_codec->type == AVMEDIA_TYPE_VIDEO) { | 175 } else if (av_codec->type == AVMEDIA_TYPE_VIDEO) { |
175 VideoPixelFormat format = | 176 VideoPixelFormat format = |
176 AVPixelFormatToVideoPixelFormat(av_codec_context->pix_fmt); | 177 AVPixelFormatToVideoPixelFormat(av_codec_context->pix_fmt); |
177 if (format != PIXEL_FORMAT_YV12) { | 178 if (format != PIXEL_FORMAT_YV12) { |
178 LOG(ERROR) << "Cannot handle non YV12 video format: " << format; | 179 LOG(ERROR) << "Cannot handle non YV12 video format: " << format; |
179 continue; | 180 continue; |
180 } | 181 } |
181 if (video_stream_index_ != -1) { | 182 if (video_stream_index_ != -1) { |
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
368 bus.Pass(), start_time_ + audio_time); | 369 bus.Pass(), start_time_ + audio_time); |
369 | 370 |
370 // Make sure queue is not empty. | 371 // Make sure queue is not empty. |
371 Decode(true); | 372 Decode(true); |
372 return true; | 373 return true; |
373 } | 374 } |
374 | 375 |
375 void FakeMediaSource::SendNextFrame() { | 376 void FakeMediaSource::SendNextFrame() { |
376 // Send as much as possible. Audio is sent according to | 377 // Send as much as possible. Audio is sent according to |
377 // system time. | 378 // system time. |
378 while (SendNextTranscodedAudio(clock_->NowTicks() - start_time_)); | 379 while (SendNextTranscodedAudio(clock_->NowTicks() - start_time_)) { |
| 380 } |
379 | 381 |
380 // Video is sync'ed to audio. | 382 // Video is sync'ed to audio. |
381 while (SendNextTranscodedVideo(audio_sent_ts_->GetTimestamp())); | 383 while (SendNextTranscodedVideo(audio_sent_ts_->GetTimestamp())) { |
| 384 } |
382 | 385 |
383 if (audio_bus_queue_.empty() && video_frame_queue_.empty()) { | 386 if (audio_bus_queue_.empty() && video_frame_queue_.empty()) { |
384 // Both queues are empty can only mean that we have reached | 387 // Both queues are empty can only mean that we have reached |
385 // the end of the stream. | 388 // the end of the stream. |
386 LOG(INFO) << "Rewind."; | 389 LOG(INFO) << "Rewind."; |
387 Rewind(); | 390 Rewind(); |
388 } | 391 } |
389 | 392 |
390 // Send next send. | 393 // Send next send. |
391 task_runner_->PostDelayedTask( | 394 task_runner_->PostDelayedTask( |
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
610 AVCodecContext* FakeMediaSource::av_audio_context() { | 613 AVCodecContext* FakeMediaSource::av_audio_context() { |
611 return av_audio_stream()->codec; | 614 return av_audio_stream()->codec; |
612 } | 615 } |
613 | 616 |
614 AVCodecContext* FakeMediaSource::av_video_context() { | 617 AVCodecContext* FakeMediaSource::av_video_context() { |
615 return av_video_stream()->codec; | 618 return av_video_stream()->codec; |
616 } | 619 } |
617 | 620 |
618 } // namespace cast | 621 } // namespace cast |
619 } // namespace media | 622 } // namespace media |
OLD | NEW |