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