| 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 <memory> | 5 #include <memory> |
| 6 #include <vector> | 6 #include <vector> |
| 7 | 7 |
| 8 #include "base/bind.h" | 8 #include "base/bind.h" |
| 9 #include "base/memory/ptr_util.h" | 9 #include "base/memory/ptr_util.h" |
| 10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
| 11 #include "base/run_loop.h" |
| 12 #include "base/single_thread_task_runner.h" |
| 11 #include "chromecast/media/base/decrypt_context_impl.h" | 13 #include "chromecast/media/base/decrypt_context_impl.h" |
| 12 #include "chromecast/media/cdm/cast_cdm_context.h" | 14 #include "chromecast/media/cdm/cast_cdm_context.h" |
| 13 #include "chromecast/media/cma/backend/audio_decoder_default.h" | 15 #include "chromecast/media/cma/backend/audio_decoder_default.h" |
| 14 #include "chromecast/media/cma/backend/media_pipeline_backend_default.h" | 16 #include "chromecast/media/cma/backend/media_pipeline_backend_default.h" |
| 15 #include "chromecast/media/cma/backend/video_decoder_default.h" | 17 #include "chromecast/media/cma/backend/video_decoder_default.h" |
| 16 #include "chromecast/media/cma/pipeline/av_pipeline_client.h" | 18 #include "chromecast/media/cma/pipeline/av_pipeline_client.h" |
| 17 #include "chromecast/media/cma/pipeline/media_pipeline_impl.h" | 19 #include "chromecast/media/cma/pipeline/media_pipeline_impl.h" |
| 18 #include "chromecast/media/cma/pipeline/video_pipeline_client.h" | 20 #include "chromecast/media/cma/pipeline/video_pipeline_client.h" |
| 19 #include "chromecast/media/cma/test/frame_generator_for_test.h" | 21 #include "chromecast/media/cma/test/frame_generator_for_test.h" |
| 20 #include "chromecast/media/cma/test/mock_frame_provider.h" | 22 #include "chromecast/media/cma/test/mock_frame_provider.h" |
| (...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 225 EXPECT_EQ(kLastFrameTimestamp, audio_decoder->last_push_pts()); | 227 EXPECT_EQ(kLastFrameTimestamp, audio_decoder->last_push_pts()); |
| 226 if (video_decoder) | 228 if (video_decoder) |
| 227 EXPECT_EQ(kLastFrameTimestamp, video_decoder->last_push_pts()); | 229 EXPECT_EQ(kLastFrameTimestamp, video_decoder->last_push_pts()); |
| 228 | 230 |
| 229 pipeline_helper->Stop(); | 231 pipeline_helper->Stop(); |
| 230 } | 232 } |
| 231 | 233 |
| 232 TEST_P(AudioVideoPipelineImplTest, Play) { | 234 TEST_P(AudioVideoPipelineImplTest, Play) { |
| 233 base::Closure verify_task = | 235 base::Closure verify_task = |
| 234 base::Bind(&VerifyPlay, base::Unretained(pipeline_helper_.get())); | 236 base::Bind(&VerifyPlay, base::Unretained(pipeline_helper_.get())); |
| 235 message_loop_.PostTask( | 237 message_loop_.task_runner()->PostTask( |
| 236 FROM_HERE, | 238 FROM_HERE, |
| 237 base::Bind(&PipelineHelper::Start, | 239 base::Bind(&PipelineHelper::Start, |
| 238 base::Unretained(pipeline_helper_.get()), verify_task)); | 240 base::Unretained(pipeline_helper_.get()), verify_task)); |
| 239 message_loop_.Run(); | 241 base::RunLoop().Run(); |
| 240 } | 242 } |
| 241 | 243 |
| 242 static void VerifyFlush(PipelineHelper* pipeline_helper) { | 244 static void VerifyFlush(PipelineHelper* pipeline_helper) { |
| 243 // The backend must have been stopped. | 245 // The backend must have been stopped. |
| 244 MediaPipelineBackendDefault* backend = pipeline_helper->pipeline_backend(); | 246 MediaPipelineBackendDefault* backend = pipeline_helper->pipeline_backend(); |
| 245 EXPECT_FALSE(backend->running()); | 247 EXPECT_FALSE(backend->running()); |
| 246 | 248 |
| 247 // The decoders must not have received any frame. | 249 // The decoders must not have received any frame. |
| 248 const AudioDecoderDefault* audio_decoder = backend->audio_decoder(); | 250 const AudioDecoderDefault* audio_decoder = backend->audio_decoder(); |
| 249 const VideoDecoderDefault* video_decoder = backend->video_decoder(); | 251 const VideoDecoderDefault* video_decoder = backend->video_decoder(); |
| 250 ASSERT_TRUE(audio_decoder || video_decoder); | 252 ASSERT_TRUE(audio_decoder || video_decoder); |
| 251 if (audio_decoder) | 253 if (audio_decoder) |
| 252 EXPECT_LT(audio_decoder->last_push_pts(), 0); | 254 EXPECT_LT(audio_decoder->last_push_pts(), 0); |
| 253 if (video_decoder) | 255 if (video_decoder) |
| 254 EXPECT_LT(video_decoder->last_push_pts(), 0); | 256 EXPECT_LT(video_decoder->last_push_pts(), 0); |
| 255 | 257 |
| 256 pipeline_helper->Stop(); | 258 pipeline_helper->Stop(); |
| 257 } | 259 } |
| 258 | 260 |
| 259 static void VerifyNotReached() { | 261 static void VerifyNotReached() { |
| 260 EXPECT_TRUE(false); | 262 EXPECT_TRUE(false); |
| 261 } | 263 } |
| 262 | 264 |
| 263 TEST_P(AudioVideoPipelineImplTest, Flush) { | 265 TEST_P(AudioVideoPipelineImplTest, Flush) { |
| 264 base::Closure verify_task = | 266 base::Closure verify_task = |
| 265 base::Bind(&VerifyFlush, base::Unretained(pipeline_helper_.get())); | 267 base::Bind(&VerifyFlush, base::Unretained(pipeline_helper_.get())); |
| 266 message_loop_.PostTask(FROM_HERE, | 268 message_loop_.task_runner()->PostTask( |
| 267 base::Bind(&PipelineHelper::Start, | 269 FROM_HERE, base::Bind(&PipelineHelper::Start, |
| 268 base::Unretained(pipeline_helper_.get()), | 270 base::Unretained(pipeline_helper_.get()), |
| 269 base::Bind(&VerifyNotReached))); | 271 base::Bind(&VerifyNotReached))); |
| 270 message_loop_.PostTask( | 272 message_loop_.task_runner()->PostTask( |
| 271 FROM_HERE, | 273 FROM_HERE, |
| 272 base::Bind(&PipelineHelper::Flush, | 274 base::Bind(&PipelineHelper::Flush, |
| 273 base::Unretained(pipeline_helper_.get()), verify_task)); | 275 base::Unretained(pipeline_helper_.get()), verify_task)); |
| 274 | 276 |
| 275 message_loop_.Run(); | 277 base::RunLoop().Run(); |
| 276 } | 278 } |
| 277 | 279 |
| 278 TEST_P(AudioVideoPipelineImplTest, FullCycle) { | 280 TEST_P(AudioVideoPipelineImplTest, FullCycle) { |
| 279 base::Closure stop_task = base::Bind( | 281 base::Closure stop_task = base::Bind( |
| 280 &PipelineHelper::Stop, base::Unretained(pipeline_helper_.get())); | 282 &PipelineHelper::Stop, base::Unretained(pipeline_helper_.get())); |
| 281 base::Closure eos_cb = | 283 base::Closure eos_cb = |
| 282 base::Bind(&PipelineHelper::Flush, | 284 base::Bind(&PipelineHelper::Flush, |
| 283 base::Unretained(pipeline_helper_.get()), stop_task); | 285 base::Unretained(pipeline_helper_.get()), stop_task); |
| 284 | 286 |
| 285 message_loop_.PostTask( | 287 message_loop_.task_runner()->PostTask( |
| 286 FROM_HERE, base::Bind(&PipelineHelper::Start, | 288 FROM_HERE, base::Bind(&PipelineHelper::Start, |
| 287 base::Unretained(pipeline_helper_.get()), eos_cb)); | 289 base::Unretained(pipeline_helper_.get()), eos_cb)); |
| 288 message_loop_.Run(); | 290 base::RunLoop().Run(); |
| 289 }; | 291 }; |
| 290 | 292 |
| 291 // Test all three types of pipeline: audio-only, video-only, audio-video. | 293 // Test all three types of pipeline: audio-only, video-only, audio-video. |
| 292 INSTANTIATE_TEST_CASE_P( | 294 INSTANTIATE_TEST_CASE_P( |
| 293 MediaPipelineImplTests, | 295 MediaPipelineImplTests, |
| 294 AudioVideoPipelineImplTest, | 296 AudioVideoPipelineImplTest, |
| 295 ::testing::Values(AudioVideoTuple(true, false), // Audio only. | 297 ::testing::Values(AudioVideoTuple(true, false), // Audio only. |
| 296 AudioVideoTuple(false, true), // Video only. | 298 AudioVideoTuple(false, true), // Video only. |
| 297 AudioVideoTuple(true, true))); // Audio and Video. | 299 AudioVideoTuple(true, true))); // Audio and Video. |
| 298 | 300 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 312 base::MessageLoop message_loop_; | 314 base::MessageLoop message_loop_; |
| 313 std::unique_ptr<PipelineHelper> pipeline_helper_; | 315 std::unique_ptr<PipelineHelper> pipeline_helper_; |
| 314 | 316 |
| 315 DISALLOW_COPY_AND_ASSIGN(EncryptedAVPipelineImplTest); | 317 DISALLOW_COPY_AND_ASSIGN(EncryptedAVPipelineImplTest); |
| 316 }; | 318 }; |
| 317 | 319 |
| 318 // Sets a CDM with license already installed before starting the pipeline. | 320 // Sets a CDM with license already installed before starting the pipeline. |
| 319 TEST_F(EncryptedAVPipelineImplTest, SetCdmWithLicenseBeforeStart) { | 321 TEST_F(EncryptedAVPipelineImplTest, SetCdmWithLicenseBeforeStart) { |
| 320 base::Closure verify_task = | 322 base::Closure verify_task = |
| 321 base::Bind(&VerifyPlay, base::Unretained(pipeline_helper_.get())); | 323 base::Bind(&VerifyPlay, base::Unretained(pipeline_helper_.get())); |
| 322 message_loop_.PostTask(FROM_HERE, | 324 message_loop_.task_runner()->PostTask( |
| 323 base::Bind(&PipelineHelper::SetCdm, | 325 FROM_HERE, base::Bind(&PipelineHelper::SetCdm, |
| 324 base::Unretained(pipeline_helper_.get()))); | 326 base::Unretained(pipeline_helper_.get()))); |
| 325 message_loop_.PostTask(FROM_HERE, | 327 message_loop_.task_runner()->PostTask( |
| 326 base::Bind(&PipelineHelper::SetCdmLicenseInstalled, | 328 FROM_HERE, base::Bind(&PipelineHelper::SetCdmLicenseInstalled, |
| 327 base::Unretained(pipeline_helper_.get()))); | 329 base::Unretained(pipeline_helper_.get()))); |
| 328 message_loop_.PostTask( | 330 message_loop_.task_runner()->PostTask( |
| 329 FROM_HERE, | 331 FROM_HERE, |
| 330 base::Bind(&PipelineHelper::Start, | 332 base::Bind(&PipelineHelper::Start, |
| 331 base::Unretained(pipeline_helper_.get()), verify_task)); | 333 base::Unretained(pipeline_helper_.get()), verify_task)); |
| 332 message_loop_.Run(); | 334 base::RunLoop().Run(); |
| 333 } | 335 } |
| 334 | 336 |
| 335 // Start the pipeline, then set a CDM with existing license. | 337 // Start the pipeline, then set a CDM with existing license. |
| 336 TEST_F(EncryptedAVPipelineImplTest, SetCdmWithLicenseAfterStart) { | 338 TEST_F(EncryptedAVPipelineImplTest, SetCdmWithLicenseAfterStart) { |
| 337 base::Closure verify_task = | 339 base::Closure verify_task = |
| 338 base::Bind(&VerifyPlay, base::Unretained(pipeline_helper_.get())); | 340 base::Bind(&VerifyPlay, base::Unretained(pipeline_helper_.get())); |
| 339 message_loop_.PostTask( | 341 message_loop_.task_runner()->PostTask( |
| 340 FROM_HERE, | 342 FROM_HERE, |
| 341 base::Bind(&PipelineHelper::Start, | 343 base::Bind(&PipelineHelper::Start, |
| 342 base::Unretained(pipeline_helper_.get()), verify_task)); | 344 base::Unretained(pipeline_helper_.get()), verify_task)); |
| 343 | 345 |
| 344 message_loop_.RunUntilIdle(); | 346 base::RunLoop().RunUntilIdle(); |
| 345 message_loop_.PostTask(FROM_HERE, | 347 message_loop_.task_runner()->PostTask( |
| 346 base::Bind(&PipelineHelper::SetCdmLicenseInstalled, | 348 FROM_HERE, base::Bind(&PipelineHelper::SetCdmLicenseInstalled, |
| 347 base::Unretained(pipeline_helper_.get()))); | 349 base::Unretained(pipeline_helper_.get()))); |
| 348 message_loop_.PostTask(FROM_HERE, | 350 message_loop_.task_runner()->PostTask( |
| 349 base::Bind(&PipelineHelper::SetCdm, | 351 FROM_HERE, base::Bind(&PipelineHelper::SetCdm, |
| 350 base::Unretained(pipeline_helper_.get()))); | 352 base::Unretained(pipeline_helper_.get()))); |
| 351 message_loop_.Run(); | 353 base::RunLoop().Run(); |
| 352 } | 354 } |
| 353 | 355 |
| 354 // Start the pipeline, set a CDM, and then install the license. | 356 // Start the pipeline, set a CDM, and then install the license. |
| 355 TEST_F(EncryptedAVPipelineImplTest, SetCdmAndInstallLicenseAfterStart) { | 357 TEST_F(EncryptedAVPipelineImplTest, SetCdmAndInstallLicenseAfterStart) { |
| 356 base::Closure verify_task = | 358 base::Closure verify_task = |
| 357 base::Bind(&VerifyPlay, base::Unretained(pipeline_helper_.get())); | 359 base::Bind(&VerifyPlay, base::Unretained(pipeline_helper_.get())); |
| 358 message_loop_.PostTask( | 360 message_loop_.task_runner()->PostTask( |
| 359 FROM_HERE, | 361 FROM_HERE, |
| 360 base::Bind(&PipelineHelper::Start, | 362 base::Bind(&PipelineHelper::Start, |
| 361 base::Unretained(pipeline_helper_.get()), verify_task)); | 363 base::Unretained(pipeline_helper_.get()), verify_task)); |
| 362 message_loop_.PostTask(FROM_HERE, | 364 message_loop_.task_runner()->PostTask( |
| 363 base::Bind(&PipelineHelper::SetCdm, | 365 FROM_HERE, base::Bind(&PipelineHelper::SetCdm, |
| 364 base::Unretained(pipeline_helper_.get()))); | 366 base::Unretained(pipeline_helper_.get()))); |
| 365 | 367 |
| 366 message_loop_.RunUntilIdle(); | 368 base::RunLoop().RunUntilIdle(); |
| 367 message_loop_.PostTask(FROM_HERE, | 369 message_loop_.task_runner()->PostTask( |
| 368 base::Bind(&PipelineHelper::SetCdmLicenseInstalled, | 370 FROM_HERE, base::Bind(&PipelineHelper::SetCdmLicenseInstalled, |
| 369 base::Unretained(pipeline_helper_.get()))); | 371 base::Unretained(pipeline_helper_.get()))); |
| 370 message_loop_.Run(); | 372 base::RunLoop().Run(); |
| 371 } | 373 } |
| 372 | 374 |
| 373 } // namespace media | 375 } // namespace media |
| 374 } // namespace chromecast | 376 } // namespace chromecast |
| OLD | NEW |