OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 <utility> | 6 #include <utility> |
7 | 7 |
8 #include "base/bind.h" | 8 #include "base/bind.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/macros.h" | 10 #include "base/macros.h" |
(...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
260 return true; | 260 return true; |
261 } | 261 } |
262 message_loop_.RunUntilIdle(); | 262 message_loop_.RunUntilIdle(); |
263 } while (!is_timeout_expired()); | 263 } while (!is_timeout_expired()); |
264 | 264 |
265 DCHECK(!timer.IsRunning()); | 265 DCHECK(!timer.IsRunning()); |
266 return false; | 266 return false; |
267 } | 267 } |
268 | 268 |
269 void MediaCodecDecoderTest::CreateAudioDecoder() { | 269 void MediaCodecDecoderTest::CreateAudioDecoder() { |
270 decoder_ = base::WrapUnique(new AudioMediaCodecDecoder( | 270 decoder_ = base::MakeUnique<AudioMediaCodecDecoder>( |
271 task_runner_, &frame_statistics_, | 271 task_runner_, &frame_statistics_, |
272 base::Bind(&MediaCodecDecoderTest::OnDataRequested, | 272 base::Bind(&MediaCodecDecoderTest::OnDataRequested, |
273 base::Unretained(this)), | 273 base::Unretained(this)), |
274 base::Bind(&MediaCodecDecoderTest::OnStarvation, base::Unretained(this)), | 274 base::Bind(&MediaCodecDecoderTest::OnStarvation, base::Unretained(this)), |
275 base::Bind(&MediaCodecDecoderTest::OnDecoderDrained, | 275 base::Bind(&MediaCodecDecoderTest::OnDecoderDrained, |
276 base::Unretained(this)), | 276 base::Unretained(this)), |
277 base::Bind(&MediaCodecDecoderTest::OnStopDone, base::Unretained(this)), | 277 base::Bind(&MediaCodecDecoderTest::OnStopDone, base::Unretained(this)), |
278 base::Bind(&MediaCodecDecoderTest::OnKeyRequired, base::Unretained(this)), | 278 base::Bind(&MediaCodecDecoderTest::OnKeyRequired, base::Unretained(this)), |
279 base::Bind(&MediaCodecDecoderTest::OnError, base::Unretained(this)), | 279 base::Bind(&MediaCodecDecoderTest::OnError, base::Unretained(this)), |
280 base::Bind(&MediaCodecDecoderTest::OnUpdateCurrentTime, | 280 base::Bind(&MediaCodecDecoderTest::OnUpdateCurrentTime, |
281 base::Unretained(this)))); | 281 base::Unretained(this))); |
282 | 282 |
283 data_available_cb_ = base::Bind(&MediaCodecDecoder::OnDemuxerDataAvailable, | 283 data_available_cb_ = base::Bind(&MediaCodecDecoder::OnDemuxerDataAvailable, |
284 base::Unretained(decoder_.get())); | 284 base::Unretained(decoder_.get())); |
285 } | 285 } |
286 | 286 |
287 void MediaCodecDecoderTest::CreateVideoDecoder() { | 287 void MediaCodecDecoderTest::CreateVideoDecoder() { |
288 decoder_ = base::WrapUnique(new VideoMediaCodecDecoder( | 288 decoder_ = base::MakeUnique<VideoMediaCodecDecoder>( |
289 task_runner_, &frame_statistics_, | 289 task_runner_, &frame_statistics_, |
290 base::Bind(&MediaCodecDecoderTest::OnDataRequested, | 290 base::Bind(&MediaCodecDecoderTest::OnDataRequested, |
291 base::Unretained(this)), | 291 base::Unretained(this)), |
292 base::Bind(&MediaCodecDecoderTest::OnStarvation, base::Unretained(this)), | 292 base::Bind(&MediaCodecDecoderTest::OnStarvation, base::Unretained(this)), |
293 base::Bind(&MediaCodecDecoderTest::OnDecoderDrained, | 293 base::Bind(&MediaCodecDecoderTest::OnDecoderDrained, |
294 base::Unretained(this)), | 294 base::Unretained(this)), |
295 base::Bind(&MediaCodecDecoderTest::OnStopDone, base::Unretained(this)), | 295 base::Bind(&MediaCodecDecoderTest::OnStopDone, base::Unretained(this)), |
296 base::Bind(&MediaCodecDecoderTest::OnKeyRequired, base::Unretained(this)), | 296 base::Bind(&MediaCodecDecoderTest::OnKeyRequired, base::Unretained(this)), |
297 base::Bind(&MediaCodecDecoderTest::OnError, base::Unretained(this)), | 297 base::Bind(&MediaCodecDecoderTest::OnError, base::Unretained(this)), |
298 base::Bind(&MediaCodecDecoderTest::OnUpdateCurrentTime, | 298 base::Bind(&MediaCodecDecoderTest::OnUpdateCurrentTime, |
299 base::Unretained(this)), | 299 base::Unretained(this)), |
300 base::Bind(&MediaCodecDecoderTest::OnVideoSizeChanged, | 300 base::Bind(&MediaCodecDecoderTest::OnVideoSizeChanged, |
301 base::Unretained(this)))); | 301 base::Unretained(this))); |
302 | 302 |
303 data_available_cb_ = base::Bind(&MediaCodecDecoder::OnDemuxerDataAvailable, | 303 data_available_cb_ = base::Bind(&MediaCodecDecoder::OnDemuxerDataAvailable, |
304 base::Unretained(decoder_.get())); | 304 base::Unretained(decoder_.get())); |
305 } | 305 } |
306 | 306 |
307 void MediaCodecDecoderTest::OnDataRequested() { | 307 void MediaCodecDecoderTest::OnDataRequested() { |
308 if (!data_factory_) | 308 if (!data_factory_) |
309 return; | 309 return; |
310 | 310 |
311 DemuxerData data; | 311 DemuxerData data; |
(...skipping 11 matching lines...) Expand all Loading... |
323 ASSERT_NE(nullptr, decoder_.get()); | 323 ASSERT_NE(nullptr, decoder_.get()); |
324 VideoMediaCodecDecoder* video_decoder = | 324 VideoMediaCodecDecoder* video_decoder = |
325 static_cast<VideoMediaCodecDecoder*>(decoder_.get()); | 325 static_cast<VideoMediaCodecDecoder*>(decoder_.get()); |
326 video_decoder->SetVideoSurface(std::move(surface)); | 326 video_decoder->SetVideoSurface(std::move(surface)); |
327 } | 327 } |
328 | 328 |
329 TEST_F(MediaCodecDecoderTest, AudioPrefetch) { | 329 TEST_F(MediaCodecDecoderTest, AudioPrefetch) { |
330 CreateAudioDecoder(); | 330 CreateAudioDecoder(); |
331 | 331 |
332 base::TimeDelta duration = base::TimeDelta::FromMilliseconds(500); | 332 base::TimeDelta duration = base::TimeDelta::FromMilliseconds(500); |
333 SetDataFactory(base::WrapUnique(new AudioFactory(duration))); | 333 SetDataFactory(base::MakeUnique<AudioFactory>(duration)); |
334 | 334 |
335 decoder_->Prefetch(base::Bind(&MediaCodecDecoderTest::SetPrefetched, | 335 decoder_->Prefetch(base::Bind(&MediaCodecDecoderTest::SetPrefetched, |
336 base::Unretained(this), true)); | 336 base::Unretained(this), true)); |
337 | 337 |
338 EXPECT_TRUE(WaitForCondition(base::Bind(&MediaCodecDecoderTest::is_prefetched, | 338 EXPECT_TRUE(WaitForCondition(base::Bind(&MediaCodecDecoderTest::is_prefetched, |
339 base::Unretained(this)))); | 339 base::Unretained(this)))); |
340 } | 340 } |
341 | 341 |
342 TEST_F(MediaCodecDecoderTest, VideoPrefetch) { | 342 TEST_F(MediaCodecDecoderTest, VideoPrefetch) { |
343 CreateVideoDecoder(); | 343 CreateVideoDecoder(); |
344 | 344 |
345 base::TimeDelta duration = base::TimeDelta::FromMilliseconds(500); | 345 base::TimeDelta duration = base::TimeDelta::FromMilliseconds(500); |
346 SetDataFactory(base::WrapUnique(new VideoFactory(duration))); | 346 SetDataFactory(base::MakeUnique<VideoFactory>(duration)); |
347 | 347 |
348 decoder_->Prefetch(base::Bind(&MediaCodecDecoderTest::SetPrefetched, | 348 decoder_->Prefetch(base::Bind(&MediaCodecDecoderTest::SetPrefetched, |
349 base::Unretained(this), true)); | 349 base::Unretained(this), true)); |
350 | 350 |
351 EXPECT_TRUE(WaitForCondition(base::Bind(&MediaCodecDecoderTest::is_prefetched, | 351 EXPECT_TRUE(WaitForCondition(base::Bind(&MediaCodecDecoderTest::is_prefetched, |
352 base::Unretained(this)))); | 352 base::Unretained(this)))); |
353 } | 353 } |
354 | 354 |
355 TEST_F(MediaCodecDecoderTest, AudioConfigureNoParams) { | 355 TEST_F(MediaCodecDecoderTest, AudioConfigureNoParams) { |
356 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); | 356 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); |
(...skipping 18 matching lines...) Expand all Loading... |
375 | 375 |
376 TEST_F(MediaCodecDecoderTest, VideoConfigureNoParams) { | 376 TEST_F(MediaCodecDecoderTest, VideoConfigureNoParams) { |
377 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); | 377 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); |
378 | 378 |
379 CreateVideoDecoder(); | 379 CreateVideoDecoder(); |
380 | 380 |
381 // decoder_->Configure() searches back for the key frame. | 381 // decoder_->Configure() searches back for the key frame. |
382 // We have to prefetch decoder. | 382 // We have to prefetch decoder. |
383 | 383 |
384 base::TimeDelta duration = base::TimeDelta::FromMilliseconds(500); | 384 base::TimeDelta duration = base::TimeDelta::FromMilliseconds(500); |
385 SetDataFactory(base::WrapUnique(new VideoFactory(duration))); | 385 SetDataFactory(base::MakeUnique<VideoFactory>(duration)); |
386 | 386 |
387 decoder_->Prefetch(base::Bind(&MediaCodecDecoderTest::SetPrefetched, | 387 decoder_->Prefetch(base::Bind(&MediaCodecDecoderTest::SetPrefetched, |
388 base::Unretained(this), true)); | 388 base::Unretained(this), true)); |
389 | 389 |
390 EXPECT_TRUE(WaitForCondition(base::Bind(&MediaCodecDecoderTest::is_prefetched, | 390 EXPECT_TRUE(WaitForCondition(base::Bind(&MediaCodecDecoderTest::is_prefetched, |
391 base::Unretained(this)))); | 391 base::Unretained(this)))); |
392 | 392 |
393 SetVideoSurface(); | 393 SetVideoSurface(); |
394 | 394 |
395 // Cannot configure without config parameters. | 395 // Cannot configure without config parameters. |
396 EXPECT_EQ(MediaCodecDecoder::kConfigFailure, decoder_->Configure(nullptr)); | 396 EXPECT_EQ(MediaCodecDecoder::kConfigFailure, decoder_->Configure(nullptr)); |
397 } | 397 } |
398 | 398 |
399 TEST_F(MediaCodecDecoderTest, VideoConfigureNoSurface) { | 399 TEST_F(MediaCodecDecoderTest, VideoConfigureNoSurface) { |
400 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); | 400 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); |
401 | 401 |
402 CreateVideoDecoder(); | 402 CreateVideoDecoder(); |
403 | 403 |
404 // decoder_->Configure() searches back for the key frame. | 404 // decoder_->Configure() searches back for the key frame. |
405 // We have to prefetch decoder. | 405 // We have to prefetch decoder. |
406 | 406 |
407 base::TimeDelta duration = base::TimeDelta::FromMilliseconds(500); | 407 base::TimeDelta duration = base::TimeDelta::FromMilliseconds(500); |
408 SetDataFactory(base::WrapUnique(new VideoFactory(duration))); | 408 SetDataFactory(base::MakeUnique<VideoFactory>(duration)); |
409 | 409 |
410 decoder_->Prefetch(base::Bind(&MediaCodecDecoderTest::SetPrefetched, | 410 decoder_->Prefetch(base::Bind(&MediaCodecDecoderTest::SetPrefetched, |
411 base::Unretained(this), true)); | 411 base::Unretained(this), true)); |
412 | 412 |
413 EXPECT_TRUE(WaitForCondition(base::Bind(&MediaCodecDecoderTest::is_prefetched, | 413 EXPECT_TRUE(WaitForCondition(base::Bind(&MediaCodecDecoderTest::is_prefetched, |
414 base::Unretained(this)))); | 414 base::Unretained(this)))); |
415 | 415 |
416 decoder_->SetDemuxerConfigs(GetConfigs()); | 416 decoder_->SetDemuxerConfigs(GetConfigs()); |
417 | 417 |
418 // Surface is not set, Configure() should fail. | 418 // Surface is not set, Configure() should fail. |
419 | 419 |
420 EXPECT_EQ(MediaCodecDecoder::kConfigFailure, decoder_->Configure(nullptr)); | 420 EXPECT_EQ(MediaCodecDecoder::kConfigFailure, decoder_->Configure(nullptr)); |
421 } | 421 } |
422 | 422 |
423 TEST_F(MediaCodecDecoderTest, VideoConfigureInvalidSurface) { | 423 TEST_F(MediaCodecDecoderTest, VideoConfigureInvalidSurface) { |
424 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); | 424 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); |
425 | 425 |
426 CreateVideoDecoder(); | 426 CreateVideoDecoder(); |
427 | 427 |
428 // decoder_->Configure() searches back for the key frame. | 428 // decoder_->Configure() searches back for the key frame. |
429 // We have to prefetch decoder. | 429 // We have to prefetch decoder. |
430 | 430 |
431 base::TimeDelta duration = base::TimeDelta::FromMilliseconds(500); | 431 base::TimeDelta duration = base::TimeDelta::FromMilliseconds(500); |
432 SetDataFactory(base::WrapUnique(new VideoFactory(duration))); | 432 SetDataFactory(base::MakeUnique<VideoFactory>(duration)); |
433 | 433 |
434 decoder_->Prefetch(base::Bind(&MediaCodecDecoderTest::SetPrefetched, | 434 decoder_->Prefetch(base::Bind(&MediaCodecDecoderTest::SetPrefetched, |
435 base::Unretained(this), true)); | 435 base::Unretained(this), true)); |
436 | 436 |
437 EXPECT_TRUE(WaitForCondition(base::Bind(&MediaCodecDecoderTest::is_prefetched, | 437 EXPECT_TRUE(WaitForCondition(base::Bind(&MediaCodecDecoderTest::is_prefetched, |
438 base::Unretained(this)))); | 438 base::Unretained(this)))); |
439 | 439 |
440 decoder_->SetDemuxerConfigs(GetConfigs()); | 440 decoder_->SetDemuxerConfigs(GetConfigs()); |
441 | 441 |
442 // Prepare the surface. | 442 // Prepare the surface. |
(...skipping 13 matching lines...) Expand all Loading... |
456 | 456 |
457 TEST_F(MediaCodecDecoderTest, VideoConfigureValidParams) { | 457 TEST_F(MediaCodecDecoderTest, VideoConfigureValidParams) { |
458 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); | 458 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); |
459 | 459 |
460 CreateVideoDecoder(); | 460 CreateVideoDecoder(); |
461 | 461 |
462 // decoder_->Configure() searches back for the key frame. | 462 // decoder_->Configure() searches back for the key frame. |
463 // We have to prefetch decoder. | 463 // We have to prefetch decoder. |
464 | 464 |
465 base::TimeDelta duration = base::TimeDelta::FromMilliseconds(500); | 465 base::TimeDelta duration = base::TimeDelta::FromMilliseconds(500); |
466 SetDataFactory(base::WrapUnique(new VideoFactory(duration))); | 466 SetDataFactory(base::MakeUnique<VideoFactory>(duration)); |
467 | 467 |
468 decoder_->Prefetch(base::Bind(&MediaCodecDecoderTest::SetPrefetched, | 468 decoder_->Prefetch(base::Bind(&MediaCodecDecoderTest::SetPrefetched, |
469 base::Unretained(this), true)); | 469 base::Unretained(this), true)); |
470 | 470 |
471 EXPECT_TRUE(WaitForCondition(base::Bind(&MediaCodecDecoderTest::is_prefetched, | 471 EXPECT_TRUE(WaitForCondition(base::Bind(&MediaCodecDecoderTest::is_prefetched, |
472 base::Unretained(this)))); | 472 base::Unretained(this)))); |
473 | 473 |
474 decoder_->SetDemuxerConfigs(GetConfigs()); | 474 decoder_->SetDemuxerConfigs(GetConfigs()); |
475 | 475 |
476 SetVideoSurface(); | 476 SetVideoSurface(); |
477 | 477 |
478 // Now we can expect Configure() to succeed. | 478 // Now we can expect Configure() to succeed. |
479 | 479 |
480 EXPECT_EQ(MediaCodecDecoder::kConfigOk, decoder_->Configure(nullptr)); | 480 EXPECT_EQ(MediaCodecDecoder::kConfigOk, decoder_->Configure(nullptr)); |
481 } | 481 } |
482 | 482 |
483 TEST_F(MediaCodecDecoderTest, AudioStartWithoutConfigure) { | 483 TEST_F(MediaCodecDecoderTest, AudioStartWithoutConfigure) { |
484 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); | 484 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); |
485 | 485 |
486 CreateAudioDecoder(); | 486 CreateAudioDecoder(); |
487 | 487 |
488 // Decoder has to be prefetched and configured before the start. | 488 // Decoder has to be prefetched and configured before the start. |
489 | 489 |
490 // Wrong state: not prefetched | 490 // Wrong state: not prefetched |
491 EXPECT_FALSE(decoder_->Start(base::TimeDelta::FromMilliseconds(0))); | 491 EXPECT_FALSE(decoder_->Start(base::TimeDelta::FromMilliseconds(0))); |
492 | 492 |
493 // Do the prefetch. | 493 // Do the prefetch. |
494 base::TimeDelta duration = base::TimeDelta::FromMilliseconds(500); | 494 base::TimeDelta duration = base::TimeDelta::FromMilliseconds(500); |
495 SetDataFactory(base::WrapUnique(new AudioFactory(duration))); | 495 SetDataFactory(base::MakeUnique<AudioFactory>(duration)); |
496 | 496 |
497 // Prefetch to avoid starvation at the beginning of playback. | 497 // Prefetch to avoid starvation at the beginning of playback. |
498 decoder_->Prefetch(base::Bind(&MediaCodecDecoderTest::SetPrefetched, | 498 decoder_->Prefetch(base::Bind(&MediaCodecDecoderTest::SetPrefetched, |
499 base::Unretained(this), true)); | 499 base::Unretained(this), true)); |
500 | 500 |
501 EXPECT_TRUE(WaitForCondition(base::Bind(&MediaCodecDecoderTest::is_prefetched, | 501 EXPECT_TRUE(WaitForCondition(base::Bind(&MediaCodecDecoderTest::is_prefetched, |
502 base::Unretained(this)))); | 502 base::Unretained(this)))); |
503 | 503 |
504 // Still, decoder is not configured. | 504 // Still, decoder is not configured. |
505 EXPECT_FALSE(decoder_->Start(base::TimeDelta::FromMilliseconds(0))); | 505 EXPECT_FALSE(decoder_->Start(base::TimeDelta::FromMilliseconds(0))); |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
557 TEST_F(MediaCodecDecoderTest, MAYBE_VideoPlayTillCompletion) { | 557 TEST_F(MediaCodecDecoderTest, MAYBE_VideoPlayTillCompletion) { |
558 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); | 558 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); |
559 | 559 |
560 CreateVideoDecoder(); | 560 CreateVideoDecoder(); |
561 | 561 |
562 base::TimeDelta duration = base::TimeDelta::FromMilliseconds(500); | 562 base::TimeDelta duration = base::TimeDelta::FromMilliseconds(500); |
563 // The first output frame might come out with significant delay. Apparently | 563 // The first output frame might come out with significant delay. Apparently |
564 // the codec does initial configuration at this time. We increase the timeout | 564 // the codec does initial configuration at this time. We increase the timeout |
565 // to leave a room of 1 second for this initial configuration. | 565 // to leave a room of 1 second for this initial configuration. |
566 base::TimeDelta timeout = base::TimeDelta::FromMilliseconds(1500); | 566 base::TimeDelta timeout = base::TimeDelta::FromMilliseconds(1500); |
567 SetDataFactory(base::WrapUnique(new VideoFactory(duration))); | 567 SetDataFactory(base::MakeUnique<VideoFactory>(duration)); |
568 | 568 |
569 // Prefetch | 569 // Prefetch |
570 decoder_->Prefetch(base::Bind(&MediaCodecDecoderTest::SetPrefetched, | 570 decoder_->Prefetch(base::Bind(&MediaCodecDecoderTest::SetPrefetched, |
571 base::Unretained(this), true)); | 571 base::Unretained(this), true)); |
572 | 572 |
573 EXPECT_TRUE(WaitForCondition(base::Bind(&MediaCodecDecoderTest::is_prefetched, | 573 EXPECT_TRUE(WaitForCondition(base::Bind(&MediaCodecDecoderTest::is_prefetched, |
574 base::Unretained(this)))); | 574 base::Unretained(this)))); |
575 | 575 |
576 decoder_->SetDemuxerConfigs(GetConfigs()); | 576 decoder_->SetDemuxerConfigs(GetConfigs()); |
577 | 577 |
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
761 | 761 |
762 EXPECT_TRUE(decoder_->IsStopped()); | 762 EXPECT_TRUE(decoder_->IsStopped()); |
763 EXPECT_TRUE(decoder_->IsCompleted()); | 763 EXPECT_TRUE(decoder_->IsCompleted()); |
764 EXPECT_EQ(data_factory_->last_pts(), pts_stat_.max()); | 764 EXPECT_EQ(data_factory_->last_pts(), pts_stat_.max()); |
765 | 765 |
766 // Check that the reported video size is the one from the in-stream configs. | 766 // Check that the reported video size is the one from the in-stream configs. |
767 EXPECT_EQ(data_factory_->GetConfigs().video_size, video_size_); | 767 EXPECT_EQ(data_factory_->GetConfigs().video_size, video_size_); |
768 } | 768 } |
769 | 769 |
770 } // namespace media | 770 } // namespace media |
OLD | NEW |