| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/test/pipeline_integration_test_base.h" | 5 #include "media/test/pipeline_integration_test_base.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 128 DCHECK_NE(status, PIPELINE_OK); | 128 DCHECK_NE(status, PIPELINE_OK); |
| 129 pipeline_status_ = status; | 129 pipeline_status_ = status; |
| 130 message_loop_.task_runner()->PostTask( | 130 message_loop_.task_runner()->PostTask( |
| 131 FROM_HERE, base::MessageLoop::QuitWhenIdleClosure()); | 131 FROM_HERE, base::MessageLoop::QuitWhenIdleClosure()); |
| 132 } | 132 } |
| 133 | 133 |
| 134 PipelineStatus PipelineIntegrationTestBase::StartInternal( | 134 PipelineStatus PipelineIntegrationTestBase::StartInternal( |
| 135 std::unique_ptr<DataSource> data_source, | 135 std::unique_ptr<DataSource> data_source, |
| 136 CdmContext* cdm_context, | 136 CdmContext* cdm_context, |
| 137 uint8_t test_type, | 137 uint8_t test_type, |
| 138 ScopedVector<VideoDecoder> prepend_video_decoders, | 138 CreateVideoDecodersCB prepend_video_decoders_cb, |
| 139 ScopedVector<AudioDecoder> prepend_audio_decoders) { | 139 CreateAudioDecodersCB prepend_audio_decoders_cb) { |
| 140 hashing_enabled_ = test_type & kHashed; | 140 hashing_enabled_ = test_type & kHashed; |
| 141 clockless_playback_ = test_type & kClockless; | 141 clockless_playback_ = test_type & kClockless; |
| 142 | 142 |
| 143 EXPECT_CALL(*this, OnMetadata(_)) | 143 EXPECT_CALL(*this, OnMetadata(_)) |
| 144 .Times(AtMost(1)) | 144 .Times(AtMost(1)) |
| 145 .WillRepeatedly(SaveArg<0>(&metadata_)); | 145 .WillRepeatedly(SaveArg<0>(&metadata_)); |
| 146 EXPECT_CALL(*this, OnBufferingStateChange(BUFFERING_HAVE_ENOUGH)) | 146 EXPECT_CALL(*this, OnBufferingStateChange(BUFFERING_HAVE_ENOUGH)) |
| 147 .Times(AnyNumber()); | 147 .Times(AnyNumber()); |
| 148 EXPECT_CALL(*this, OnBufferingStateChange(BUFFERING_HAVE_NOTHING)) | 148 EXPECT_CALL(*this, OnBufferingStateChange(BUFFERING_HAVE_NOTHING)) |
| 149 .Times(AnyNumber()); | 149 .Times(AnyNumber()); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 172 pipeline_->SetCdm( | 172 pipeline_->SetCdm( |
| 173 cdm_context, base::Bind(&PipelineIntegrationTestBase::DecryptorAttached, | 173 cdm_context, base::Bind(&PipelineIntegrationTestBase::DecryptorAttached, |
| 174 base::Unretained(this))); | 174 base::Unretained(this))); |
| 175 } | 175 } |
| 176 | 176 |
| 177 // Should never be called as the required decryption keys for the encrypted | 177 // Should never be called as the required decryption keys for the encrypted |
| 178 // media files are provided in advance. | 178 // media files are provided in advance. |
| 179 EXPECT_CALL(*this, OnWaitingForDecryptionKey()).Times(0); | 179 EXPECT_CALL(*this, OnWaitingForDecryptionKey()).Times(0); |
| 180 | 180 |
| 181 pipeline_->Start( | 181 pipeline_->Start( |
| 182 demuxer_.get(), CreateRenderer(std::move(prepend_video_decoders), | 182 demuxer_.get(), |
| 183 std::move(prepend_audio_decoders)), | 183 CreateRenderer(prepend_video_decoders_cb, prepend_audio_decoders_cb), |
| 184 this, base::Bind(&PipelineIntegrationTestBase::OnStatusCallback, | 184 this, |
| 185 base::Unretained(this))); | 185 base::Bind(&PipelineIntegrationTestBase::OnStatusCallback, |
| 186 base::Unretained(this))); |
| 186 base::RunLoop().Run(); | 187 base::RunLoop().Run(); |
| 187 return pipeline_status_; | 188 return pipeline_status_; |
| 188 } | 189 } |
| 189 | 190 |
| 190 PipelineStatus PipelineIntegrationTestBase::StartWithFile( | 191 PipelineStatus PipelineIntegrationTestBase::StartWithFile( |
| 191 const std::string& filename, | 192 const std::string& filename, |
| 192 CdmContext* cdm_context, | 193 CdmContext* cdm_context, |
| 193 uint8_t test_type, | 194 uint8_t test_type, |
| 194 ScopedVector<VideoDecoder> prepend_video_decoders, | 195 CreateVideoDecodersCB prepend_video_decoders_cb, |
| 195 ScopedVector<AudioDecoder> prepend_audio_decoders) { | 196 CreateAudioDecodersCB prepend_audio_decoders_cb) { |
| 196 std::unique_ptr<FileDataSource> file_data_source(new FileDataSource()); | 197 std::unique_ptr<FileDataSource> file_data_source(new FileDataSource()); |
| 197 base::FilePath file_path(GetTestDataFilePath(filename)); | 198 base::FilePath file_path(GetTestDataFilePath(filename)); |
| 198 CHECK(file_data_source->Initialize(file_path)) << "Is " << file_path.value() | 199 CHECK(file_data_source->Initialize(file_path)) << "Is " << file_path.value() |
| 199 << " missing?"; | 200 << " missing?"; |
| 200 return StartInternal(std::move(file_data_source), cdm_context, test_type, | 201 return StartInternal(std::move(file_data_source), cdm_context, test_type, |
| 201 std::move(prepend_video_decoders), | 202 prepend_video_decoders_cb, prepend_audio_decoders_cb); |
| 202 std::move(prepend_audio_decoders)); | |
| 203 } | 203 } |
| 204 | 204 |
| 205 PipelineStatus PipelineIntegrationTestBase::Start(const std::string& filename) { | 205 PipelineStatus PipelineIntegrationTestBase::Start(const std::string& filename) { |
| 206 return StartWithFile(filename, nullptr, kNormal); | 206 return StartWithFile(filename, nullptr, kNormal); |
| 207 } | 207 } |
| 208 | 208 |
| 209 PipelineStatus PipelineIntegrationTestBase::Start(const std::string& filename, | 209 PipelineStatus PipelineIntegrationTestBase::Start(const std::string& filename, |
| 210 CdmContext* cdm_context) { | 210 CdmContext* cdm_context) { |
| 211 return StartWithFile(filename, cdm_context, kNormal); | 211 return StartWithFile(filename, cdm_context, kNormal); |
| 212 } | 212 } |
| 213 | 213 |
| 214 PipelineStatus PipelineIntegrationTestBase::Start( | 214 PipelineStatus PipelineIntegrationTestBase::Start( |
| 215 const std::string& filename, | 215 const std::string& filename, |
| 216 uint8_t test_type, | 216 uint8_t test_type, |
| 217 ScopedVector<VideoDecoder> prepend_video_decoders, | 217 CreateVideoDecodersCB prepend_video_decoders_cb, |
| 218 ScopedVector<AudioDecoder> prepend_audio_decoders) { | 218 CreateAudioDecodersCB prepend_audio_decoders_cb) { |
| 219 return StartWithFile(filename, nullptr, test_type, | 219 return StartWithFile(filename, nullptr, test_type, prepend_video_decoders_cb, |
| 220 std::move(prepend_video_decoders), | 220 prepend_audio_decoders_cb); |
| 221 std::move(prepend_audio_decoders)); | |
| 222 } | 221 } |
| 223 | 222 |
| 224 PipelineStatus PipelineIntegrationTestBase::Start(const uint8_t* data, | 223 PipelineStatus PipelineIntegrationTestBase::Start(const uint8_t* data, |
| 225 size_t size, | 224 size_t size, |
| 226 uint8_t test_type) { | 225 uint8_t test_type) { |
| 227 return StartInternal(base::MakeUnique<MemoryDataSource>(data, size), nullptr, | 226 return StartInternal(base::MakeUnique<MemoryDataSource>(data, size), nullptr, |
| 228 test_type); | 227 test_type); |
| 229 } | 228 } |
| 230 | 229 |
| 231 void PipelineIntegrationTestBase::Play() { | 230 void PipelineIntegrationTestBase::Play() { |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 317 demuxer_ = std::unique_ptr<Demuxer>(new FFmpegDemuxer( | 316 demuxer_ = std::unique_ptr<Demuxer>(new FFmpegDemuxer( |
| 318 message_loop_.task_runner(), data_source_.get(), | 317 message_loop_.task_runner(), data_source_.get(), |
| 319 base::Bind(&PipelineIntegrationTestBase::DemuxerEncryptedMediaInitDataCB, | 318 base::Bind(&PipelineIntegrationTestBase::DemuxerEncryptedMediaInitDataCB, |
| 320 base::Unretained(this)), | 319 base::Unretained(this)), |
| 321 base::Bind(&PipelineIntegrationTestBase::DemuxerMediaTracksUpdatedCB, | 320 base::Bind(&PipelineIntegrationTestBase::DemuxerMediaTracksUpdatedCB, |
| 322 base::Unretained(this)), | 321 base::Unretained(this)), |
| 323 new MediaLog())); | 322 new MediaLog())); |
| 324 #endif | 323 #endif |
| 325 } | 324 } |
| 326 | 325 |
| 327 std::unique_ptr<Renderer> PipelineIntegrationTestBase::CreateRenderer( | 326 ScopedVector<VideoDecoder> CreateVideoDecodersForTest( |
| 328 ScopedVector<VideoDecoder> prepend_video_decoders, | 327 CreateVideoDecodersCB prepend_video_decoders_cb) { |
| 329 ScopedVector<AudioDecoder> prepend_audio_decoders) { | 328 ScopedVector<VideoDecoder> video_decoders; |
| 330 ScopedVector<VideoDecoder> video_decoders = std::move(prepend_video_decoders); | 329 |
| 330 if (!prepend_video_decoders_cb.is_null()) { |
| 331 video_decoders = prepend_video_decoders_cb.Run(); |
| 332 DCHECK(!video_decoders.empty()); |
| 333 } |
| 334 |
| 331 #if !defined(MEDIA_DISABLE_LIBVPX) | 335 #if !defined(MEDIA_DISABLE_LIBVPX) |
| 332 video_decoders.push_back(new VpxVideoDecoder()); | 336 video_decoders.push_back(new VpxVideoDecoder()); |
| 333 #endif // !defined(MEDIA_DISABLE_LIBVPX) | 337 #endif // !defined(MEDIA_DISABLE_LIBVPX) |
| 334 | 338 |
| 335 // Android does not have an ffmpeg video decoder. | 339 // Android does not have an ffmpeg video decoder. |
| 336 #if !defined(MEDIA_DISABLE_FFMPEG) && !defined(OS_ANDROID) | 340 #if !defined(MEDIA_DISABLE_FFMPEG) && !defined(OS_ANDROID) |
| 337 video_decoders.push_back( | 341 video_decoders.push_back( |
| 338 new FFmpegVideoDecoder(make_scoped_refptr(new MediaLog()))); | 342 new FFmpegVideoDecoder(make_scoped_refptr(new MediaLog()))); |
| 339 #endif | 343 #endif |
| 344 return video_decoders; |
| 345 } |
| 340 | 346 |
| 347 ScopedVector<AudioDecoder> CreateAudioDecodersForTest( |
| 348 const scoped_refptr<base::SingleThreadTaskRunner>& media_task_runner, |
| 349 CreateAudioDecodersCB prepend_audio_decoders_cb) { |
| 350 ScopedVector<AudioDecoder> audio_decoders; |
| 351 |
| 352 if (!prepend_audio_decoders_cb.is_null()) { |
| 353 audio_decoders = prepend_audio_decoders_cb.Run(); |
| 354 DCHECK(!audio_decoders.empty()); |
| 355 } |
| 356 |
| 357 #if !defined(MEDIA_DISABLE_FFMPEG) |
| 358 audio_decoders.push_back( |
| 359 new FFmpegAudioDecoder(media_task_runner, new MediaLog())); |
| 360 #endif |
| 361 return audio_decoders; |
| 362 } |
| 363 |
| 364 std::unique_ptr<Renderer> PipelineIntegrationTestBase::CreateRenderer( |
| 365 CreateVideoDecodersCB prepend_video_decoders_cb, |
| 366 CreateAudioDecodersCB prepend_audio_decoders_cb) { |
| 341 // Simulate a 60Hz rendering sink. | 367 // Simulate a 60Hz rendering sink. |
| 342 video_sink_.reset(new NullVideoSink( | 368 video_sink_.reset(new NullVideoSink( |
| 343 clockless_playback_, base::TimeDelta::FromSecondsD(1.0 / 60), | 369 clockless_playback_, base::TimeDelta::FromSecondsD(1.0 / 60), |
| 344 base::Bind(&PipelineIntegrationTestBase::OnVideoFramePaint, | 370 base::Bind(&PipelineIntegrationTestBase::OnVideoFramePaint, |
| 345 base::Unretained(this)), | 371 base::Unretained(this)), |
| 346 message_loop_.task_runner())); | 372 message_loop_.task_runner())); |
| 347 | 373 |
| 348 // Disable frame dropping if hashing is enabled. | 374 // Disable frame dropping if hashing is enabled. |
| 349 std::unique_ptr<VideoRenderer> video_renderer(new VideoRendererImpl( | 375 std::unique_ptr<VideoRenderer> video_renderer(new VideoRendererImpl( |
| 350 message_loop_.task_runner(), message_loop_.task_runner().get(), | 376 message_loop_.task_runner(), message_loop_.task_runner().get(), |
| 351 video_sink_.get(), std::move(video_decoders), false, nullptr, | 377 video_sink_.get(), |
| 352 new MediaLog())); | 378 base::Bind(&CreateVideoDecodersForTest, prepend_video_decoders_cb), false, |
| 353 | 379 nullptr, new MediaLog())); |
| 354 ScopedVector<AudioDecoder> audio_decoders = std::move(prepend_audio_decoders); | |
| 355 | |
| 356 #if !defined(MEDIA_DISABLE_FFMPEG) | |
| 357 audio_decoders.push_back( | |
| 358 new FFmpegAudioDecoder(message_loop_.task_runner(), new MediaLog())); | |
| 359 #endif | |
| 360 | 380 |
| 361 if (!clockless_playback_) { | 381 if (!clockless_playback_) { |
| 362 audio_sink_ = new NullAudioSink(message_loop_.task_runner()); | 382 audio_sink_ = new NullAudioSink(message_loop_.task_runner()); |
| 363 } else { | 383 } else { |
| 364 clockless_audio_sink_ = new ClocklessAudioSink(OutputDeviceInfo( | 384 clockless_audio_sink_ = new ClocklessAudioSink(OutputDeviceInfo( |
| 365 "", OUTPUT_DEVICE_STATUS_OK, | 385 "", OUTPUT_DEVICE_STATUS_OK, |
| 366 // Don't allow the audio renderer to resample buffers if hashing is | 386 // Don't allow the audio renderer to resample buffers if hashing is |
| 367 // enabled: | 387 // enabled: |
| 368 hashing_enabled_ | 388 hashing_enabled_ |
| 369 ? AudioParameters() | 389 ? AudioParameters() |
| 370 : AudioParameters(AudioParameters::AUDIO_PCM_LOW_LATENCY, | 390 : AudioParameters(AudioParameters::AUDIO_PCM_LOW_LATENCY, |
| 371 CHANNEL_LAYOUT_STEREO, 44100, 16, 512))); | 391 CHANNEL_LAYOUT_STEREO, 44100, 16, 512))); |
| 372 } | 392 } |
| 373 | 393 |
| 374 std::unique_ptr<AudioRenderer> audio_renderer(new AudioRendererImpl( | 394 std::unique_ptr<AudioRenderer> audio_renderer(new AudioRendererImpl( |
| 375 message_loop_.task_runner(), | 395 message_loop_.task_runner(), |
| 376 (clockless_playback_) | 396 (clockless_playback_) |
| 377 ? static_cast<AudioRendererSink*>(clockless_audio_sink_.get()) | 397 ? static_cast<AudioRendererSink*>(clockless_audio_sink_.get()) |
| 378 : audio_sink_.get(), | 398 : audio_sink_.get(), |
| 379 std::move(audio_decoders), new MediaLog())); | 399 base::Bind(&CreateAudioDecodersForTest, message_loop_.task_runner(), |
| 400 prepend_audio_decoders_cb), |
| 401 new MediaLog())); |
| 380 if (hashing_enabled_) { | 402 if (hashing_enabled_) { |
| 381 if (clockless_playback_) | 403 if (clockless_playback_) |
| 382 clockless_audio_sink_->StartAudioHashForTesting(); | 404 clockless_audio_sink_->StartAudioHashForTesting(); |
| 383 else | 405 else |
| 384 audio_sink_->StartAudioHashForTesting(); | 406 audio_sink_->StartAudioHashForTesting(); |
| 385 } | 407 } |
| 386 | 408 |
| 387 std::unique_ptr<RendererImpl> renderer_impl( | 409 std::unique_ptr<RendererImpl> renderer_impl( |
| 388 new RendererImpl(message_loop_.task_runner(), std::move(audio_renderer), | 410 new RendererImpl(message_loop_.task_runner(), std::move(audio_renderer), |
| 389 std::move(video_renderer))); | 411 std::move(video_renderer))); |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 447 DCHECK(clockless_playback_); | 469 DCHECK(clockless_playback_); |
| 448 return clockless_audio_sink_->render_time(); | 470 return clockless_audio_sink_->render_time(); |
| 449 } | 471 } |
| 450 | 472 |
| 451 base::TimeTicks DummyTickClock::NowTicks() { | 473 base::TimeTicks DummyTickClock::NowTicks() { |
| 452 now_ += base::TimeDelta::FromSeconds(60); | 474 now_ += base::TimeDelta::FromSeconds(60); |
| 453 return now_; | 475 return now_; |
| 454 } | 476 } |
| 455 | 477 |
| 456 } // namespace media | 478 } // namespace media |
| OLD | NEW |