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 <stdint.h> |
| 6 |
5 #include "base/bind.h" | 7 #include "base/bind.h" |
6 #include "base/logging.h" | 8 #include "base/logging.h" |
7 #include "base/timer/timer.h" | 9 #include "base/timer/timer.h" |
8 #include "media/base/android/demuxer_android.h" | 10 #include "media/base/android/demuxer_android.h" |
9 #include "media/base/android/media_codec_bridge.h" | 11 #include "media/base/android/media_codec_bridge.h" |
10 #include "media/base/android/media_codec_player.h" | 12 #include "media/base/android/media_codec_player.h" |
11 #include "media/base/android/media_player_manager.h" | 13 #include "media/base/android/media_player_manager.h" |
12 #include "media/base/android/test_data_factory.h" | 14 #include "media/base/android/test_data_factory.h" |
13 #include "media/base/android/test_statistics.h" | 15 #include "media/base/android/test_statistics.h" |
14 #include "media/base/buffers.h" | 16 #include "media/base/buffers.h" |
(...skipping 21 matching lines...) Expand all Loading... |
36 } \ | 38 } \ |
37 } while (0) | 39 } while (0) |
38 | 40 |
39 namespace { | 41 namespace { |
40 | 42 |
41 const base::TimeDelta kDefaultTimeout = base::TimeDelta::FromMilliseconds(200); | 43 const base::TimeDelta kDefaultTimeout = base::TimeDelta::FromMilliseconds(200); |
42 const base::TimeDelta kAudioFramePeriod = | 44 const base::TimeDelta kAudioFramePeriod = |
43 base::TimeDelta::FromSecondsD(1024.0 / 44100); // 1024 samples @ 44100 Hz | 45 base::TimeDelta::FromSecondsD(1024.0 / 44100); // 1024 samples @ 44100 Hz |
44 const base::TimeDelta kVideoFramePeriod = base::TimeDelta::FromMilliseconds(20); | 46 const base::TimeDelta kVideoFramePeriod = base::TimeDelta::FromMilliseconds(20); |
45 | 47 |
| 48 enum Flags { |
| 49 kAlwaysReconfigAudio = 0x1, |
| 50 kAlwaysReconfigVideo = 0x2, |
| 51 }; |
| 52 |
46 // The predicate that always returns false, used for WaitForDelay implementation | 53 // The predicate that always returns false, used for WaitForDelay implementation |
47 bool AlwaysFalse() { | 54 bool AlwaysFalse() { |
48 return false; | 55 return false; |
49 } | 56 } |
50 | 57 |
51 // The method used to compare two time values of type T in expectations. | 58 // The method used to compare two time values of type T in expectations. |
52 // Type T requires that a difference of type base::TimeDelta is defined. | 59 // Type T requires that a difference of type base::TimeDelta is defined. |
53 template <typename T> | 60 template <typename T> |
54 bool AlmostEqual(T a, T b, double tolerance_ms) { | 61 bool AlmostEqual(T a, T b, double tolerance_ms) { |
55 return (a - b).magnitude().InMilliseconds() <= tolerance_ms; | 62 return (a - b).magnitude().InMilliseconds() <= tolerance_ms; |
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
199 } | 206 } |
200 | 207 |
201 DemuxerConfigs CreateAudioVideoConfigs(const TestDataFactory* audio, | 208 DemuxerConfigs CreateAudioVideoConfigs(const TestDataFactory* audio, |
202 const TestDataFactory* video) { | 209 const TestDataFactory* video) { |
203 DemuxerConfigs result = audio->GetConfigs(); | 210 DemuxerConfigs result = audio->GetConfigs(); |
204 DemuxerConfigs vconf = video->GetConfigs(); | 211 DemuxerConfigs vconf = video->GetConfigs(); |
205 | 212 |
206 result.video_codec = vconf.video_codec; | 213 result.video_codec = vconf.video_codec; |
207 result.video_size = vconf.video_size; | 214 result.video_size = vconf.video_size; |
208 result.is_video_encrypted = vconf.is_video_encrypted; | 215 result.is_video_encrypted = vconf.is_video_encrypted; |
| 216 result.duration = std::max(result.duration, vconf.duration); |
209 return result; | 217 return result; |
210 } | 218 } |
211 | 219 |
212 // AudioFactory creates data chunks that simulate audio stream from demuxer. | 220 // AudioFactory creates data chunks that simulate audio stream from demuxer. |
213 | 221 |
214 class AudioFactory : public TestDataFactory { | 222 class AudioFactory : public TestDataFactory { |
215 public: | 223 public: |
216 AudioFactory(base::TimeDelta duration) | 224 AudioFactory(base::TimeDelta duration) |
217 : TestDataFactory("aac-44100-packet-%d", duration, kAudioFramePeriod) {} | 225 : TestDataFactory("aac-44100-packet-%d", duration, kAudioFramePeriod) {} |
218 | 226 |
(...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
512 // reaches the given value or for timeout to expire. Returns true if the | 520 // reaches the given value or for timeout to expire. Returns true if the |
513 // playback has passed the given position. | 521 // playback has passed the given position. |
514 bool WaitForPlaybackBeyondPosition( | 522 bool WaitForPlaybackBeyondPosition( |
515 const base::TimeDelta& pts, | 523 const base::TimeDelta& pts, |
516 const base::TimeDelta& timeout = kDefaultTimeout); | 524 const base::TimeDelta& timeout = kDefaultTimeout); |
517 | 525 |
518 // Helper method that starts video only stream. Waits till it actually | 526 // Helper method that starts video only stream. Waits till it actually |
519 // started. | 527 // started. |
520 bool StartVideoPlayback(base::TimeDelta duration, const char* test_name); | 528 bool StartVideoPlayback(base::TimeDelta duration, const char* test_name); |
521 | 529 |
| 530 // Helper method that starts audio and video streams. |
| 531 bool StartAVPlayback(scoped_ptr<AudioFactory> audio_factory, |
| 532 scoped_ptr<VideoFactory> video_factory, |
| 533 uint32_t flags, |
| 534 const char* test_name); |
| 535 |
522 // Helper method that starts audio and video streams with preroll. | 536 // Helper method that starts audio and video streams with preroll. |
523 // The preroll is achieved by setting significant video preroll interval | 537 // The preroll is achieved by setting significant video preroll interval |
524 // so video will have to catch up with audio. To make room for this interval | 538 // so video will have to catch up with audio. To make room for this interval |
525 // the Start() command is preceded by SeekTo(). | 539 // the Start() command is preceded by SeekTo(). |
526 bool StartAVSeekAndPreroll(base::TimeDelta duration, | 540 bool StartAVSeekAndPreroll(scoped_ptr<AudioFactory> audio_factory, |
| 541 scoped_ptr<VideoFactory> video_factory, |
527 base::TimeDelta seek_position, | 542 base::TimeDelta seek_position, |
528 base::TimeDelta video_preroll, | 543 uint32_t flags, |
529 const char* test_name); | 544 const char* test_name); |
530 | 545 |
531 // Callback sent when demuxer is being deleted. | 546 // Callback sent when demuxer is being deleted. |
532 void OnDemuxerDeleted() { demuxer_ = nullptr; } | 547 void OnDemuxerDeleted() { demuxer_ = nullptr; } |
533 | 548 |
534 bool IsDemuxerDeleted() const { return !demuxer_; } | 549 bool IsDemuxerDeleted() const { return !demuxer_; } |
535 | 550 |
536 base::MessageLoop message_loop_; | 551 base::MessageLoop message_loop_; |
537 MockMediaPlayerManager manager_; | 552 MockMediaPlayerManager manager_; |
538 MockDemuxerAndroid* demuxer_; // owned by player_ | 553 MockDemuxerAndroid* demuxer_; // owned by player_ |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
684 start_timeout)); | 699 start_timeout)); |
685 | 700 |
686 if (!manager_.IsPlaybackStarted()) { | 701 if (!manager_.IsPlaybackStarted()) { |
687 DVLOG(0) << test_name << ": playback did not start"; | 702 DVLOG(0) << test_name << ": playback did not start"; |
688 return false; | 703 return false; |
689 } | 704 } |
690 | 705 |
691 return true; | 706 return true; |
692 } | 707 } |
693 | 708 |
694 bool MediaCodecPlayerTest::StartAVSeekAndPreroll(base::TimeDelta duration, | 709 bool MediaCodecPlayerTest::StartAVPlayback( |
695 base::TimeDelta seek_position, | 710 scoped_ptr<AudioFactory> audio_factory, |
696 base::TimeDelta video_preroll, | 711 scoped_ptr<VideoFactory> video_factory, |
697 const char* test_name) { | 712 uint32_t flags, |
698 const base::TimeDelta start_timeout = base::TimeDelta::FromMilliseconds(800); | 713 const char* test_name) { |
699 | 714 demuxer_->SetAudioFactory(audio_factory.Pass()); |
700 demuxer_->SetVideoPrerollInterval(video_preroll); | 715 demuxer_->SetVideoFactory(video_factory.Pass()); |
701 | |
702 demuxer_->SetAudioFactory( | |
703 scoped_ptr<AudioFactory>(new AudioFactory(duration))); | |
704 demuxer_->SetVideoFactory( | |
705 scoped_ptr<VideoFactory>(new VideoFactory(duration))); | |
706 | 716 |
707 CreatePlayer(); | 717 CreatePlayer(); |
| 718 SetVideoSurface(); |
708 | 719 |
709 // Set special testing callback to receive PTS from decoders. | 720 // Wait till the player is initialized on media thread. |
| 721 EXPECT_TRUE(WaitForCondition(base::Bind(&MockDemuxerAndroid::IsInitialized, |
| 722 base::Unretained(demuxer_)))); |
| 723 |
| 724 if (!demuxer_->IsInitialized()) { |
| 725 DVLOG(0) << test_name << ": demuxer is not initialized"; |
| 726 return false; |
| 727 } |
| 728 |
| 729 // Ask decoders to always reconfigure after the player has been initialized. |
| 730 if (flags & kAlwaysReconfigAudio) |
| 731 player_->SetAlwaysReconfigureForTests(DemuxerStream::AUDIO); |
| 732 if (flags & kAlwaysReconfigVideo) |
| 733 player_->SetAlwaysReconfigureForTests(DemuxerStream::VIDEO); |
| 734 |
| 735 // Set a testing callback to receive PTS from decoders. |
710 player_->SetDecodersTimeCallbackForTests( | 736 player_->SetDecodersTimeCallbackForTests( |
711 base::Bind(&MockMediaPlayerManager::OnDecodersTimeUpdate, | 737 base::Bind(&MockMediaPlayerManager::OnDecodersTimeUpdate, |
712 base::Unretained(&manager_))); | 738 base::Unretained(&manager_))); |
713 | 739 |
| 740 // Set a testing callback to receive MediaCodec creation events from decoders. |
| 741 player_->SetCodecCreatedCallbackForTests( |
| 742 base::Bind(&MockMediaPlayerManager::OnMediaCodecCreated, |
| 743 base::Unretained(&manager_))); |
| 744 |
| 745 // Post configuration after the player has been initialized. |
| 746 demuxer_->PostInternalConfigs(); |
| 747 |
| 748 // Start and wait for playback. |
| 749 player_->Start(); |
| 750 |
| 751 // Wait till we start to play. |
| 752 base::TimeDelta start_timeout = base::TimeDelta::FromMilliseconds(2000); |
| 753 |
| 754 EXPECT_TRUE( |
| 755 WaitForCondition(base::Bind(&MockMediaPlayerManager::IsPlaybackStarted, |
| 756 base::Unretained(&manager_)), |
| 757 start_timeout)); |
| 758 |
| 759 if (!manager_.IsPlaybackStarted()) { |
| 760 DVLOG(0) << test_name << ": playback did not start"; |
| 761 return false; |
| 762 } |
| 763 |
| 764 return true; |
| 765 } |
| 766 |
| 767 bool MediaCodecPlayerTest::StartAVSeekAndPreroll( |
| 768 scoped_ptr<AudioFactory> audio_factory, |
| 769 scoped_ptr<VideoFactory> video_factory, |
| 770 base::TimeDelta seek_position, |
| 771 uint32_t flags, |
| 772 const char* test_name) { |
| 773 // Initialize A/V playback |
| 774 |
| 775 demuxer_->SetAudioFactory(audio_factory.Pass()); |
| 776 demuxer_->SetVideoFactory(video_factory.Pass()); |
| 777 |
| 778 CreatePlayer(); |
| 779 SetVideoSurface(); |
| 780 |
714 // Wait till the player is initialized on media thread. | 781 // Wait till the player is initialized on media thread. |
715 EXPECT_TRUE(WaitForCondition(base::Bind(&MockDemuxerAndroid::IsInitialized, | 782 EXPECT_TRUE(WaitForCondition(base::Bind(&MockDemuxerAndroid::IsInitialized, |
716 base::Unretained(demuxer_)))); | 783 base::Unretained(demuxer_)))); |
717 | 784 |
718 if (!demuxer_->IsInitialized()) { | 785 if (!demuxer_->IsInitialized()) { |
719 DVLOG(0) << test_name << ": demuxer is not initialized"; | 786 DVLOG(0) << test_name << ": demuxer is not initialized"; |
720 return false; | 787 return false; |
721 } | 788 } |
722 | 789 |
723 SetVideoSurface(); | 790 // Ask decoders to always reconfigure after the player has been initialized. |
| 791 if (flags & kAlwaysReconfigAudio) |
| 792 player_->SetAlwaysReconfigureForTests(DemuxerStream::AUDIO); |
| 793 if (flags & kAlwaysReconfigVideo) |
| 794 player_->SetAlwaysReconfigureForTests(DemuxerStream::VIDEO); |
| 795 |
| 796 // Set a testing callback to receive PTS from decoders. |
| 797 player_->SetDecodersTimeCallbackForTests( |
| 798 base::Bind(&MockMediaPlayerManager::OnDecodersTimeUpdate, |
| 799 base::Unretained(&manager_))); |
| 800 |
| 801 // Set a testing callback to receive MediaCodec creation events from decoders. |
| 802 player_->SetCodecCreatedCallbackForTests( |
| 803 base::Bind(&MockMediaPlayerManager::OnMediaCodecCreated, |
| 804 base::Unretained(&manager_))); |
724 | 805 |
725 // Post configuration after the player has been initialized. | 806 // Post configuration after the player has been initialized. |
726 demuxer_->PostInternalConfigs(); | 807 demuxer_->PostInternalConfigs(); |
727 | 808 |
728 // Issue SeekTo(). | 809 // Issue SeekTo(). |
729 player_->SeekTo(seek_position); | 810 player_->SeekTo(seek_position); |
730 | 811 |
731 // Start the playback. | 812 // Start the playback. |
732 player_->Start(); | 813 player_->Start(); |
733 | 814 |
734 // Wait till preroll starts. | 815 // Wait till preroll starts. |
| 816 base::TimeDelta start_timeout = base::TimeDelta::FromMilliseconds(2000); |
735 EXPECT_TRUE(WaitForCondition( | 817 EXPECT_TRUE(WaitForCondition( |
736 base::Bind(&MediaCodecPlayer::IsPrerollingForTests, | 818 base::Bind(&MediaCodecPlayer::IsPrerollingForTests, |
737 base::Unretained(player_), DemuxerStream::VIDEO), | 819 base::Unretained(player_), DemuxerStream::VIDEO), |
738 start_timeout)); | 820 start_timeout)); |
739 | 821 |
740 if (!player_->IsPrerollingForTests(DemuxerStream::VIDEO)) { | 822 if (!player_->IsPrerollingForTests(DemuxerStream::VIDEO)) { |
741 DVLOG(0) << test_name << ": preroll did not happen for video"; | 823 DVLOG(0) << test_name << ": preroll did not happen for video"; |
742 return false; | 824 return false; |
743 } | 825 } |
744 | 826 |
(...skipping 604 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1349 // with a decoder PTS that is delivered by a test-only callback. | 1431 // with a decoder PTS that is delivered by a test-only callback. |
1350 | 1432 |
1351 base::TimeDelta duration = base::TimeDelta::FromMilliseconds(2000); | 1433 base::TimeDelta duration = base::TimeDelta::FromMilliseconds(2000); |
1352 | 1434 |
1353 // Set significant preroll interval. 500 ms means 25 frames, at 10 ms | 1435 // Set significant preroll interval. 500 ms means 25 frames, at 10 ms |
1354 // per frame it would take 250 ms to preroll. | 1436 // per frame it would take 250 ms to preroll. |
1355 base::TimeDelta seek_position = base::TimeDelta::FromMilliseconds(1000); | 1437 base::TimeDelta seek_position = base::TimeDelta::FromMilliseconds(1000); |
1356 base::TimeDelta preroll_intvl = base::TimeDelta::FromMilliseconds(500); | 1438 base::TimeDelta preroll_intvl = base::TimeDelta::FromMilliseconds(500); |
1357 base::TimeDelta preroll_timeout = base::TimeDelta::FromMilliseconds(1000); | 1439 base::TimeDelta preroll_timeout = base::TimeDelta::FromMilliseconds(1000); |
1358 | 1440 |
1359 ASSERT_TRUE(StartAVSeekAndPreroll(duration, seek_position, preroll_intvl, | 1441 scoped_ptr<AudioFactory> audio_factory(new AudioFactory(duration)); |
| 1442 scoped_ptr<VideoFactory> video_factory(new VideoFactory(duration)); |
| 1443 |
| 1444 demuxer_->SetVideoPrerollInterval(preroll_intvl); |
| 1445 |
| 1446 ASSERT_TRUE(StartAVSeekAndPreroll(audio_factory.Pass(), video_factory.Pass(), |
| 1447 seek_position, 0, |
1360 "AVPrerollAudioWaitsForVideo")); | 1448 "AVPrerollAudioWaitsForVideo")); |
1361 | 1449 |
1362 // Wait till preroll finishes and the real playback starts. | 1450 // Wait till preroll finishes and the real playback starts. |
1363 EXPECT_TRUE( | 1451 EXPECT_TRUE( |
1364 WaitForCondition(base::Bind(&MockMediaPlayerManager::IsPlaybackStarted, | 1452 WaitForCondition(base::Bind(&MockMediaPlayerManager::IsPlaybackStarted, |
1365 base::Unretained(&manager_)), | 1453 base::Unretained(&manager_)), |
1366 preroll_timeout)); | 1454 preroll_timeout)); |
1367 | 1455 |
1368 // Ensure that the first audio and video pts are close to each other and are | 1456 // Ensure that the first audio and video pts are close to each other and are |
1369 // reported at the close moments in time. | 1457 // reported at the close moments in time. |
(...skipping 22 matching lines...) Expand all Loading... |
1392 base::TimeDelta duration = base::TimeDelta::FromMilliseconds(2000); | 1480 base::TimeDelta duration = base::TimeDelta::FromMilliseconds(2000); |
1393 | 1481 |
1394 // Set significant preroll interval. 500 ms means 25 frames, at 10 ms | 1482 // Set significant preroll interval. 500 ms means 25 frames, at 10 ms |
1395 // per frame it would take 250 ms to preroll. | 1483 // per frame it would take 250 ms to preroll. |
1396 base::TimeDelta seek_position = base::TimeDelta::FromMilliseconds(1000); | 1484 base::TimeDelta seek_position = base::TimeDelta::FromMilliseconds(1000); |
1397 base::TimeDelta preroll_intvl = base::TimeDelta::FromMilliseconds(500); | 1485 base::TimeDelta preroll_intvl = base::TimeDelta::FromMilliseconds(500); |
1398 | 1486 |
1399 base::TimeDelta start_timeout = base::TimeDelta::FromMilliseconds(800); | 1487 base::TimeDelta start_timeout = base::TimeDelta::FromMilliseconds(800); |
1400 base::TimeDelta preroll_timeout = base::TimeDelta::FromMilliseconds(1000); | 1488 base::TimeDelta preroll_timeout = base::TimeDelta::FromMilliseconds(1000); |
1401 | 1489 |
1402 ASSERT_TRUE(StartAVSeekAndPreroll(duration, seek_position, preroll_intvl, | 1490 scoped_ptr<AudioFactory> audio_factory(new AudioFactory(duration)); |
| 1491 scoped_ptr<VideoFactory> video_factory(new VideoFactory(duration)); |
| 1492 |
| 1493 demuxer_->SetVideoPrerollInterval(preroll_intvl); |
| 1494 |
| 1495 ASSERT_TRUE(StartAVSeekAndPreroll(audio_factory.Pass(), video_factory.Pass(), |
| 1496 seek_position, 0, |
1403 "AVPrerollReleaseAndRestart")); | 1497 "AVPrerollReleaseAndRestart")); |
1404 | 1498 |
1405 // Issue Release(). | 1499 // Issue Release(). |
1406 player_->Release(); | 1500 player_->Release(); |
1407 | 1501 |
1408 // Make sure we have not been playing. | 1502 // Make sure we have not been playing. |
1409 WaitForDelay(base::TimeDelta::FromMilliseconds(400)); | 1503 WaitForDelay(base::TimeDelta::FromMilliseconds(400)); |
1410 | 1504 |
1411 EXPECT_FALSE(manager_.HasFirstFrame(DemuxerStream::AUDIO)); | 1505 EXPECT_FALSE(manager_.HasFirstFrame(DemuxerStream::AUDIO)); |
1412 EXPECT_FALSE(manager_.HasFirstFrame(DemuxerStream::VIDEO)); | 1506 EXPECT_FALSE(manager_.HasFirstFrame(DemuxerStream::VIDEO)); |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1460 base::TimeDelta duration = base::TimeDelta::FromMilliseconds(1200); | 1554 base::TimeDelta duration = base::TimeDelta::FromMilliseconds(1200); |
1461 | 1555 |
1462 // Set significant preroll interval. 500 ms means 25 frames, at 10 ms | 1556 // Set significant preroll interval. 500 ms means 25 frames, at 10 ms |
1463 // per frame it would take 250 ms to preroll. | 1557 // per frame it would take 250 ms to preroll. |
1464 base::TimeDelta seek_position = base::TimeDelta::FromMilliseconds(1000); | 1558 base::TimeDelta seek_position = base::TimeDelta::FromMilliseconds(1000); |
1465 base::TimeDelta preroll_intvl = base::TimeDelta::FromMilliseconds(500); | 1559 base::TimeDelta preroll_intvl = base::TimeDelta::FromMilliseconds(500); |
1466 | 1560 |
1467 base::TimeDelta start_timeout = base::TimeDelta::FromMilliseconds(800); | 1561 base::TimeDelta start_timeout = base::TimeDelta::FromMilliseconds(800); |
1468 base::TimeDelta preroll_timeout = base::TimeDelta::FromMilliseconds(1000); | 1562 base::TimeDelta preroll_timeout = base::TimeDelta::FromMilliseconds(1000); |
1469 | 1563 |
1470 ASSERT_TRUE(StartAVSeekAndPreroll(duration, seek_position, preroll_intvl, | 1564 scoped_ptr<AudioFactory> audio_factory(new AudioFactory(duration)); |
| 1565 scoped_ptr<VideoFactory> video_factory(new VideoFactory(duration)); |
| 1566 |
| 1567 demuxer_->SetVideoPrerollInterval(preroll_intvl); |
| 1568 |
| 1569 ASSERT_TRUE(StartAVSeekAndPreroll(audio_factory.Pass(), video_factory.Pass(), |
| 1570 seek_position, 0, |
1471 "AVPrerollStopAndRestart")); | 1571 "AVPrerollStopAndRestart")); |
1472 | 1572 |
1473 // Video stream should be prerolling. Request to stop. | 1573 // Video stream should be prerolling. Request to stop. |
1474 EXPECT_FALSE(IsPaused()); | 1574 EXPECT_FALSE(IsPaused()); |
1475 player_->Pause(true); | 1575 player_->Pause(true); |
1476 | 1576 |
1477 EXPECT_TRUE(WaitForCondition( | 1577 EXPECT_TRUE(WaitForCondition( |
1478 base::Bind(&MediaCodecPlayerTest::IsPaused, base::Unretained(this)))); | 1578 base::Bind(&MediaCodecPlayerTest::IsPaused, base::Unretained(this)))); |
1479 | 1579 |
1480 // Test that we have not been playing. | 1580 // Test that we have not been playing. |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1627 demuxer_->video_factory()->RequestConfigChange(config_change_position); | 1727 demuxer_->video_factory()->RequestConfigChange(config_change_position); |
1628 | 1728 |
1629 CreatePlayer(); | 1729 CreatePlayer(); |
1630 SetVideoSurface(); | 1730 SetVideoSurface(); |
1631 | 1731 |
1632 // Wait till the player is initialized on media thread. | 1732 // Wait till the player is initialized on media thread. |
1633 EXPECT_TRUE(WaitForCondition(base::Bind(&MockDemuxerAndroid::IsInitialized, | 1733 EXPECT_TRUE(WaitForCondition(base::Bind(&MockDemuxerAndroid::IsInitialized, |
1634 base::Unretained(demuxer_)))); | 1734 base::Unretained(demuxer_)))); |
1635 | 1735 |
1636 if (!demuxer_->IsInitialized()) { | 1736 if (!demuxer_->IsInitialized()) { |
1637 DVLOG(0) << "AVConfigChangeWhilePlaying: demuxer is not initialized"; | 1737 DVLOG(0) << "VideoConfigChangeWhilePlaying: demuxer is not initialized"; |
1638 return; | 1738 return; |
1639 } | 1739 } |
1640 | 1740 |
1641 // Ask decoders to always reconfigure after the player has been initialized. | 1741 // Ask decoders to always reconfigure after the player has been initialized. |
1642 player_->SetAlwaysReconfigureForTests(DemuxerStream::VIDEO); | 1742 player_->SetAlwaysReconfigureForTests(DemuxerStream::VIDEO); |
1643 | 1743 |
1644 // Set a testing callback to receive PTS from decoders. | 1744 // Set a testing callback to receive PTS from decoders. |
1645 player_->SetDecodersTimeCallbackForTests( | 1745 player_->SetDecodersTimeCallbackForTests( |
1646 base::Bind(&MockMediaPlayerManager::OnDecodersTimeUpdate, | 1746 base::Bind(&MockMediaPlayerManager::OnDecodersTimeUpdate, |
1647 base::Unretained(&manager_))); | 1747 base::Unretained(&manager_))); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1681 TEST_F(MediaCodecPlayerTest, AVVideoConfigChangeWhilePlaying) { | 1781 TEST_F(MediaCodecPlayerTest, AVVideoConfigChangeWhilePlaying) { |
1682 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); | 1782 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); |
1683 | 1783 |
1684 // Test that A/V playback continues after video config change. | 1784 // Test that A/V playback continues after video config change. |
1685 | 1785 |
1686 // Initialize A/V playback | 1786 // Initialize A/V playback |
1687 base::TimeDelta duration = base::TimeDelta::FromMilliseconds(1200); | 1787 base::TimeDelta duration = base::TimeDelta::FromMilliseconds(1200); |
1688 base::TimeDelta config_change_position = | 1788 base::TimeDelta config_change_position = |
1689 base::TimeDelta::FromMilliseconds(1000); | 1789 base::TimeDelta::FromMilliseconds(1000); |
1690 | 1790 |
1691 base::TimeDelta start_timeout = base::TimeDelta::FromMilliseconds(2000); | |
1692 base::TimeDelta completion_timeout = base::TimeDelta::FromMilliseconds(3000); | 1791 base::TimeDelta completion_timeout = base::TimeDelta::FromMilliseconds(3000); |
1693 | 1792 |
1694 demuxer_->SetAudioFactory( | 1793 scoped_ptr<AudioFactory> audio_factory(new AudioFactory(duration)); |
1695 scoped_ptr<AudioFactory>(new AudioFactory(duration))); | 1794 scoped_ptr<VideoFactory> video_factory(new VideoFactory(duration)); |
1696 demuxer_->SetVideoFactory( | |
1697 scoped_ptr<VideoFactory>(new VideoFactory(duration))); | |
1698 | 1795 |
1699 demuxer_->video_factory()->RequestConfigChange(config_change_position); | 1796 video_factory->RequestConfigChange(config_change_position); |
1700 | 1797 |
1701 CreatePlayer(); | 1798 ASSERT_TRUE(StartAVPlayback(audio_factory.Pass(), video_factory.Pass(), |
1702 SetVideoSurface(); | 1799 kAlwaysReconfigVideo, |
1703 | 1800 "AVVideoConfigChangeWhilePlaying")); |
1704 // Wait till the player is initialized on media thread. | |
1705 EXPECT_TRUE(WaitForCondition(base::Bind(&MockDemuxerAndroid::IsInitialized, | |
1706 base::Unretained(demuxer_)))); | |
1707 | |
1708 if (!demuxer_->IsInitialized()) { | |
1709 DVLOG(0) << "AVConfigChangeWhilePlaying: demuxer is not initialized"; | |
1710 return; | |
1711 } | |
1712 | |
1713 // Ask decoders to always reconfigure after the player has been initialized. | |
1714 player_->SetAlwaysReconfigureForTests(DemuxerStream::VIDEO); | |
1715 | |
1716 // Set a testing callback to receive PTS from decoders. | |
1717 player_->SetDecodersTimeCallbackForTests( | |
1718 base::Bind(&MockMediaPlayerManager::OnDecodersTimeUpdate, | |
1719 base::Unretained(&manager_))); | |
1720 | |
1721 // Set a testing callback to receive MediaCodec creation events from decoders. | |
1722 player_->SetCodecCreatedCallbackForTests( | |
1723 base::Bind(&MockMediaPlayerManager::OnMediaCodecCreated, | |
1724 base::Unretained(&manager_))); | |
1725 | |
1726 // Post configuration after the player has been initialized. | |
1727 demuxer_->PostInternalConfigs(); | |
1728 | |
1729 // Start and wait for playback. | |
1730 player_->Start(); | |
1731 | |
1732 // Wait till we start to play. | |
1733 EXPECT_TRUE( | |
1734 WaitForCondition(base::Bind(&MockMediaPlayerManager::IsPlaybackStarted, | |
1735 base::Unretained(&manager_)), | |
1736 start_timeout)); | |
1737 | 1801 |
1738 // Wait till completion | 1802 // Wait till completion |
1739 EXPECT_TRUE( | 1803 EXPECT_TRUE( |
1740 WaitForCondition(base::Bind(&MockMediaPlayerManager::IsPlaybackCompleted, | 1804 WaitForCondition(base::Bind(&MockMediaPlayerManager::IsPlaybackCompleted, |
1741 base::Unretained(&manager_)), | 1805 base::Unretained(&manager_)), |
1742 completion_timeout)); | 1806 completion_timeout)); |
1743 | 1807 |
1744 // The audio codec should be kept. | 1808 // The audio codec should be kept. |
1745 EXPECT_EQ(1, manager_.num_audio_codecs_created()); | 1809 EXPECT_EQ(1, manager_.num_audio_codecs_created()); |
1746 | 1810 |
1747 // The video codec should be recreated upon config changes. | 1811 // The video codec should be recreated upon config changes. |
1748 EXPECT_EQ(2, manager_.num_video_codecs_created()); | 1812 EXPECT_EQ(2, manager_.num_video_codecs_created()); |
1749 | 1813 |
1750 // Check that we did not miss video frames | 1814 // Check that we did not miss video frames |
1751 int expected_video_frames = duration / kVideoFramePeriod + 1; | 1815 int expected_video_frames = duration / kVideoFramePeriod + 1; |
1752 EXPECT_EQ(expected_video_frames, | 1816 EXPECT_EQ(expected_video_frames, |
1753 manager_.render_stat_[DemuxerStream::VIDEO].num_values()); | 1817 manager_.render_stat_[DemuxerStream::VIDEO].num_values()); |
1754 | 1818 |
1755 // Check that we did not miss audio frames. We expect two postponed frames | 1819 // Check that we did not miss audio frames. We expect one postponed frames |
1756 // that are not reported. | 1820 // that are not reported. |
1757 // For Nexus 4 KitKat the AAC decoder seems to swallow the first frame | 1821 // For Nexus 4 KitKat the AAC decoder seems to swallow the first frame |
1758 // but reports the last pts twice, maybe it just shifts the reported PTS. | 1822 // but reports the last pts twice, maybe it just shifts the reported PTS. |
1759 int expected_audio_frames = duration / kAudioFramePeriod + 1 - 2; | 1823 int expected_audio_frames = duration / kAudioFramePeriod + 1 - 1; |
1760 EXPECT_EQ(expected_audio_frames, | 1824 EXPECT_EQ(expected_audio_frames, |
1761 manager_.render_stat_[DemuxerStream::AUDIO].num_values()); | 1825 manager_.render_stat_[DemuxerStream::AUDIO].num_values()); |
1762 } | 1826 } |
1763 | 1827 |
1764 TEST_F(MediaCodecPlayerTest, AVAudioConfigChangeWhilePlaying) { | 1828 TEST_F(MediaCodecPlayerTest, AVAudioConfigChangeWhilePlaying) { |
1765 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); | 1829 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); |
1766 | 1830 |
1767 // Test that A/V playback continues after audio config change. | 1831 // Test that A/V playback continues after audio config change. |
1768 | 1832 |
1769 // Initialize A/V playback | |
1770 base::TimeDelta duration = base::TimeDelta::FromMilliseconds(1200); | 1833 base::TimeDelta duration = base::TimeDelta::FromMilliseconds(1200); |
1771 base::TimeDelta config_change_position = | 1834 base::TimeDelta config_change_position = |
1772 base::TimeDelta::FromMilliseconds(1000); | 1835 base::TimeDelta::FromMilliseconds(1000); |
1773 | 1836 |
1774 base::TimeDelta start_timeout = base::TimeDelta::FromMilliseconds(2000); | |
1775 base::TimeDelta completion_timeout = base::TimeDelta::FromMilliseconds(3000); | 1837 base::TimeDelta completion_timeout = base::TimeDelta::FromMilliseconds(3000); |
1776 | 1838 |
1777 demuxer_->SetAudioFactory( | 1839 scoped_ptr<AudioFactory> audio_factory(new AudioFactory(duration)); |
1778 scoped_ptr<AudioFactory>(new AudioFactory(duration))); | 1840 scoped_ptr<VideoFactory> video_factory(new VideoFactory(duration)); |
1779 demuxer_->SetVideoFactory( | |
1780 scoped_ptr<VideoFactory>(new VideoFactory(duration))); | |
1781 | 1841 |
1782 demuxer_->audio_factory()->RequestConfigChange(config_change_position); | 1842 audio_factory->RequestConfigChange(config_change_position); |
1783 | 1843 |
1784 CreatePlayer(); | 1844 ASSERT_TRUE(StartAVPlayback(audio_factory.Pass(), video_factory.Pass(), |
1785 SetVideoSurface(); | 1845 kAlwaysReconfigAudio, |
1786 | 1846 "AVAudioConfigChangeWhilePlaying")); |
1787 // Wait till the player is initialized on media thread. | |
1788 EXPECT_TRUE(WaitForCondition(base::Bind(&MockDemuxerAndroid::IsInitialized, | |
1789 base::Unretained(demuxer_)))); | |
1790 | |
1791 if (!demuxer_->IsInitialized()) { | |
1792 DVLOG(0) << "AVConfigChangeWhilePlaying: demuxer is not initialized"; | |
1793 return; | |
1794 } | |
1795 | |
1796 // Ask decoders to always reconfigure after the player has been initialized. | |
1797 player_->SetAlwaysReconfigureForTests(DemuxerStream::AUDIO); | |
1798 | |
1799 // Set a testing callback to receive PTS from decoders. | |
1800 player_->SetDecodersTimeCallbackForTests( | |
1801 base::Bind(&MockMediaPlayerManager::OnDecodersTimeUpdate, | |
1802 base::Unretained(&manager_))); | |
1803 | |
1804 // Set a testing callback to receive MediaCodec creation events from decoders. | |
1805 player_->SetCodecCreatedCallbackForTests( | |
1806 base::Bind(&MockMediaPlayerManager::OnMediaCodecCreated, | |
1807 base::Unretained(&manager_))); | |
1808 | |
1809 // Post configuration after the player has been initialized. | |
1810 demuxer_->PostInternalConfigs(); | |
1811 | |
1812 // Start and wait for playback. | |
1813 player_->Start(); | |
1814 | |
1815 // Wait till we start to play. | |
1816 EXPECT_TRUE( | |
1817 WaitForCondition(base::Bind(&MockMediaPlayerManager::IsPlaybackStarted, | |
1818 base::Unretained(&manager_)), | |
1819 start_timeout)); | |
1820 | 1847 |
1821 // Wait till completion | 1848 // Wait till completion |
1822 EXPECT_TRUE( | 1849 EXPECT_TRUE( |
| 1850 WaitForCondition(base::Bind(&MockMediaPlayerManager::IsPlaybackCompleted, |
| 1851 base::Unretained(&manager_)), |
| 1852 completion_timeout)); |
| 1853 |
| 1854 // The audio codec should be recreated upon config changes. |
| 1855 EXPECT_EQ(2, manager_.num_audio_codecs_created()); |
| 1856 |
| 1857 // The video codec should be kept. |
| 1858 EXPECT_EQ(1, manager_.num_video_codecs_created()); |
| 1859 |
| 1860 // Check that we did not miss video frames. |
| 1861 int expected_video_frames = duration / kVideoFramePeriod + 1; |
| 1862 EXPECT_EQ(expected_video_frames, |
| 1863 manager_.render_stat_[DemuxerStream::VIDEO].num_values()); |
| 1864 |
| 1865 // Check that we did not miss audio frames. We expect two postponed frames |
| 1866 // that are not reported. |
| 1867 int expected_audio_frames = duration / kAudioFramePeriod + 1 - 2; |
| 1868 EXPECT_EQ(expected_audio_frames, |
| 1869 manager_.render_stat_[DemuxerStream::AUDIO].num_values()); |
| 1870 } |
| 1871 |
| 1872 TEST_F(MediaCodecPlayerTest, AVSimultaneousConfigChange_1) { |
| 1873 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); |
| 1874 |
| 1875 // Test that the playback continues if audio and video config changes happen |
| 1876 // at the same time. |
| 1877 |
| 1878 base::TimeDelta duration = base::TimeDelta::FromMilliseconds(1200); |
| 1879 base::TimeDelta config_change_audio = base::TimeDelta::FromMilliseconds(1000); |
| 1880 base::TimeDelta config_change_video = base::TimeDelta::FromMilliseconds(1000); |
| 1881 |
| 1882 base::TimeDelta completion_timeout = base::TimeDelta::FromMilliseconds(3000); |
| 1883 |
| 1884 scoped_ptr<AudioFactory> audio_factory(new AudioFactory(duration)); |
| 1885 scoped_ptr<VideoFactory> video_factory(new VideoFactory(duration)); |
| 1886 |
| 1887 audio_factory->RequestConfigChange(config_change_audio); |
| 1888 video_factory->RequestConfigChange(config_change_video); |
| 1889 |
| 1890 ASSERT_TRUE(StartAVPlayback(audio_factory.Pass(), video_factory.Pass(), |
| 1891 kAlwaysReconfigAudio | kAlwaysReconfigVideo, |
| 1892 "AVSimultaneousConfigChange_1")); |
| 1893 |
| 1894 // Wait till completion |
| 1895 EXPECT_TRUE( |
| 1896 WaitForCondition(base::Bind(&MockMediaPlayerManager::IsPlaybackCompleted, |
| 1897 base::Unretained(&manager_)), |
| 1898 completion_timeout)); |
| 1899 |
| 1900 // The audio codec should be recreated upon config changes. |
| 1901 EXPECT_EQ(2, manager_.num_audio_codecs_created()); |
| 1902 |
| 1903 // The video codec should be recreated upon config changes. |
| 1904 EXPECT_EQ(2, manager_.num_video_codecs_created()); |
| 1905 |
| 1906 // Check that we did not miss video frames. |
| 1907 int expected_video_frames = duration / kVideoFramePeriod + 1; |
| 1908 EXPECT_EQ(expected_video_frames, |
| 1909 manager_.render_stat_[DemuxerStream::VIDEO].num_values()); |
| 1910 |
| 1911 // Check that we did not miss audio frames. We expect two postponed frames |
| 1912 // that are not reported. |
| 1913 int expected_audio_frames = duration / kAudioFramePeriod + 1 - 2; |
| 1914 EXPECT_EQ(expected_audio_frames, |
| 1915 manager_.render_stat_[DemuxerStream::AUDIO].num_values()); |
| 1916 } |
| 1917 |
| 1918 TEST_F(MediaCodecPlayerTest, AVSimultaneousConfigChange_2) { |
| 1919 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); |
| 1920 |
| 1921 // Test that the playback continues if audio and video config changes happen |
| 1922 // at the same time. Move audio change moment slightly to make it drained |
| 1923 // after video. |
| 1924 |
| 1925 base::TimeDelta duration = base::TimeDelta::FromMilliseconds(1200); |
| 1926 base::TimeDelta config_change_audio = base::TimeDelta::FromMilliseconds(1020); |
| 1927 base::TimeDelta config_change_video = base::TimeDelta::FromMilliseconds(1000); |
| 1928 |
| 1929 base::TimeDelta completion_timeout = base::TimeDelta::FromMilliseconds(3000); |
| 1930 |
| 1931 scoped_ptr<AudioFactory> audio_factory(new AudioFactory(duration)); |
| 1932 scoped_ptr<VideoFactory> video_factory(new VideoFactory(duration)); |
| 1933 |
| 1934 audio_factory->RequestConfigChange(config_change_audio); |
| 1935 video_factory->RequestConfigChange(config_change_video); |
| 1936 |
| 1937 ASSERT_TRUE(StartAVPlayback(audio_factory.Pass(), video_factory.Pass(), |
| 1938 kAlwaysReconfigAudio | kAlwaysReconfigVideo, |
| 1939 "AVSimultaneousConfigChange_2")); |
| 1940 |
| 1941 // Wait till completion |
| 1942 EXPECT_TRUE( |
1823 WaitForCondition(base::Bind(&MockMediaPlayerManager::IsPlaybackCompleted, | 1943 WaitForCondition(base::Bind(&MockMediaPlayerManager::IsPlaybackCompleted, |
1824 base::Unretained(&manager_)), | 1944 base::Unretained(&manager_)), |
1825 completion_timeout)); | 1945 completion_timeout)); |
1826 | 1946 |
1827 // The audio codec should be recreated upon config changes. | 1947 // The audio codec should be recreated upon config changes. |
1828 EXPECT_EQ(2, manager_.num_audio_codecs_created()); | 1948 EXPECT_EQ(2, manager_.num_audio_codecs_created()); |
1829 | 1949 |
1830 // The video codec should be kept. | 1950 // The video codec should be recreated upon config changes. |
1831 EXPECT_EQ(1, manager_.num_video_codecs_created()); | 1951 EXPECT_EQ(2, manager_.num_video_codecs_created()); |
1832 | 1952 |
1833 // Check that we did not miss video frames. | 1953 // Check that we did not miss video frames. |
1834 int expected_video_frames = duration / kVideoFramePeriod + 1; | 1954 int expected_video_frames = duration / kVideoFramePeriod + 1; |
1835 EXPECT_EQ(expected_video_frames, | 1955 EXPECT_EQ(expected_video_frames, |
1836 manager_.render_stat_[DemuxerStream::VIDEO].num_values()); | 1956 manager_.render_stat_[DemuxerStream::VIDEO].num_values()); |
1837 | 1957 |
1838 // Check that we did not miss audio frames. We expect two postponed frames | 1958 // Check that we did not miss audio frames. We expect two postponed frames |
1839 // that are not reported. | 1959 // that are not reported. |
1840 int expected_audio_frames = duration / kAudioFramePeriod + 1 - 2; | 1960 int expected_audio_frames = duration / kAudioFramePeriod + 1 - 2; |
1841 EXPECT_EQ(expected_audio_frames, | 1961 EXPECT_EQ(expected_audio_frames, |
1842 manager_.render_stat_[DemuxerStream::AUDIO].num_values()); | 1962 manager_.render_stat_[DemuxerStream::AUDIO].num_values()); |
1843 } | 1963 } |
1844 | 1964 |
| 1965 TEST_F(MediaCodecPlayerTest, AVAudioEndsAcrossVideoConfigChange) { |
| 1966 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); |
| 1967 |
| 1968 // Test that audio can end while video config change processing. |
| 1969 |
| 1970 base::TimeDelta audio_duration = base::TimeDelta::FromMilliseconds(1000); |
| 1971 base::TimeDelta video_duration = base::TimeDelta::FromMilliseconds(1200); |
| 1972 base::TimeDelta config_change_video = base::TimeDelta::FromMilliseconds(1000); |
| 1973 |
| 1974 base::TimeDelta completion_timeout = base::TimeDelta::FromMilliseconds(3000); |
| 1975 |
| 1976 scoped_ptr<AudioFactory> audio_factory(new AudioFactory(audio_duration)); |
| 1977 scoped_ptr<VideoFactory> video_factory(new VideoFactory(video_duration)); |
| 1978 |
| 1979 video_factory->RequestConfigChange(config_change_video); |
| 1980 |
| 1981 ASSERT_TRUE(StartAVPlayback(audio_factory.Pass(), video_factory.Pass(), |
| 1982 kAlwaysReconfigVideo, |
| 1983 "AVAudioEndsAcrossVideoConfigChange")); |
| 1984 |
| 1985 // Wait till completion |
| 1986 EXPECT_TRUE( |
| 1987 WaitForCondition(base::Bind(&MockMediaPlayerManager::IsPlaybackCompleted, |
| 1988 base::Unretained(&manager_)), |
| 1989 completion_timeout)); |
| 1990 |
| 1991 // The audio codec should not be recreated. |
| 1992 EXPECT_EQ(1, manager_.num_audio_codecs_created()); |
| 1993 |
| 1994 // The video codec should be recreated upon config changes. |
| 1995 EXPECT_EQ(2, manager_.num_video_codecs_created()); |
| 1996 |
| 1997 // Check that we did not miss video frames. |
| 1998 int expected_video_frames = video_duration / kVideoFramePeriod + 1; |
| 1999 EXPECT_EQ(expected_video_frames, |
| 2000 manager_.render_stat_[DemuxerStream::VIDEO].num_values()); |
| 2001 |
| 2002 // Check the last video frame timestamp. The maximum render pts may differ |
| 2003 // from |video_duration| because of the testing artefact: if the last video |
| 2004 // chunk is incomplete if will have different last pts due to B-frames |
| 2005 // rearrangements. |
| 2006 EXPECT_LE(video_duration, |
| 2007 manager_.render_stat_[DemuxerStream::VIDEO].max().pts); |
| 2008 |
| 2009 // Check that the playback time reported by the player goes past |
| 2010 // the audio time and corresponds to video after the audio ended. |
| 2011 EXPECT_EQ(video_duration, manager_.pts_stat_.max()); |
| 2012 } |
| 2013 |
| 2014 TEST_F(MediaCodecPlayerTest, AVVideoEndsAcrossAudioConfigChange) { |
| 2015 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); |
| 2016 |
| 2017 // Test that video can end while audio config change processing. |
| 2018 base::TimeDelta audio_duration = base::TimeDelta::FromMilliseconds(1200); |
| 2019 base::TimeDelta video_duration = base::TimeDelta::FromMilliseconds(1000); |
| 2020 base::TimeDelta config_change_audio = base::TimeDelta::FromMilliseconds(1000); |
| 2021 |
| 2022 base::TimeDelta completion_timeout = base::TimeDelta::FromMilliseconds(3000); |
| 2023 |
| 2024 scoped_ptr<AudioFactory> audio_factory(new AudioFactory(audio_duration)); |
| 2025 scoped_ptr<VideoFactory> video_factory(new VideoFactory(video_duration)); |
| 2026 |
| 2027 audio_factory->RequestConfigChange(config_change_audio); |
| 2028 |
| 2029 ASSERT_TRUE(StartAVPlayback(audio_factory.Pass(), video_factory.Pass(), |
| 2030 kAlwaysReconfigAudio, |
| 2031 "AVVideoEndsAcrossAudioConfigChange")); |
| 2032 |
| 2033 // Wait till completion |
| 2034 EXPECT_TRUE( |
| 2035 WaitForCondition(base::Bind(&MockMediaPlayerManager::IsPlaybackCompleted, |
| 2036 base::Unretained(&manager_)), |
| 2037 completion_timeout)); |
| 2038 |
| 2039 // The audio codec should be recreated upon config changes. |
| 2040 EXPECT_EQ(2, manager_.num_audio_codecs_created()); |
| 2041 |
| 2042 // The video codec should not be recreated. |
| 2043 EXPECT_EQ(1, manager_.num_video_codecs_created()); |
| 2044 |
| 2045 // Check that we did not miss audio frames. We expect two postponed frames |
| 2046 // that are not reported. |
| 2047 int expected_audio_frames = audio_duration / kAudioFramePeriod + 1 - 2; |
| 2048 EXPECT_EQ(expected_audio_frames, |
| 2049 manager_.render_stat_[DemuxerStream::AUDIO].num_values()); |
| 2050 } |
| 2051 |
| 2052 TEST_F(MediaCodecPlayerTest, AVPrerollAcrossVideoConfigChange) { |
| 2053 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); |
| 2054 |
| 2055 // Test that preroll continues if interrupted by video config change. |
| 2056 |
| 2057 base::TimeDelta duration = base::TimeDelta::FromMilliseconds(1200); |
| 2058 base::TimeDelta seek_position = base::TimeDelta::FromMilliseconds(1000); |
| 2059 base::TimeDelta config_change_position = |
| 2060 base::TimeDelta::FromMilliseconds(800); |
| 2061 base::TimeDelta video_preroll_intvl = base::TimeDelta::FromMilliseconds(500); |
| 2062 base::TimeDelta preroll_timeout = base::TimeDelta::FromMilliseconds(3000); |
| 2063 |
| 2064 demuxer_->SetVideoPrerollInterval(video_preroll_intvl); |
| 2065 |
| 2066 scoped_ptr<AudioFactory> audio_factory(new AudioFactory(duration)); |
| 2067 |
| 2068 scoped_ptr<VideoFactory> video_factory(new VideoFactory(duration)); |
| 2069 video_factory->RequestConfigChange(config_change_position); |
| 2070 |
| 2071 ASSERT_TRUE(StartAVSeekAndPreroll(audio_factory.Pass(), video_factory.Pass(), |
| 2072 seek_position, kAlwaysReconfigVideo, |
| 2073 "AVPrerollAcrossVideoConfigChange")); |
| 2074 |
| 2075 // Wait till preroll finishes and the real playback starts. |
| 2076 EXPECT_TRUE( |
| 2077 WaitForCondition(base::Bind(&MockMediaPlayerManager::IsPlaybackStarted, |
| 2078 base::Unretained(&manager_)), |
| 2079 preroll_timeout)); |
| 2080 |
| 2081 // The presense of config change should not affect preroll behavior: |
| 2082 |
| 2083 // Ensure that the first audio and video pts are close to each other and are |
| 2084 // reported at the close moments in time. |
| 2085 |
| 2086 EXPECT_TRUE(manager_.HasFirstFrame(DemuxerStream::AUDIO)); |
| 2087 EXPECT_TRUE(WaitForCondition( |
| 2088 base::Bind(&MockMediaPlayerManager::HasFirstFrame, |
| 2089 base::Unretained(&manager_), DemuxerStream::VIDEO))); |
| 2090 |
| 2091 EXPECT_TRUE(AlmostEqual(manager_.FirstFramePTS(DemuxerStream::AUDIO), |
| 2092 manager_.FirstFramePTS(DemuxerStream::VIDEO), 25)); |
| 2093 |
| 2094 EXPECT_TRUE(AlmostEqual(manager_.FirstFrameTime(DemuxerStream::AUDIO), |
| 2095 manager_.FirstFrameTime(DemuxerStream::VIDEO), 50)); |
| 2096 |
| 2097 // The playback should start at |seek_position| |
| 2098 EXPECT_TRUE(AlmostEqual(seek_position, manager_.pts_stat_.min(), 25)); |
| 2099 } |
| 2100 |
| 2101 TEST_F(MediaCodecPlayerTest, AVPrerollAcrossAudioConfigChange) { |
| 2102 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); |
| 2103 |
| 2104 // Test that preroll continues if interrupted by video config change. |
| 2105 |
| 2106 base::TimeDelta duration = base::TimeDelta::FromMilliseconds(1200); |
| 2107 base::TimeDelta seek_position = base::TimeDelta::FromMilliseconds(1000); |
| 2108 base::TimeDelta config_change_position = |
| 2109 base::TimeDelta::FromMilliseconds(800); |
| 2110 base::TimeDelta audio_preroll_intvl = base::TimeDelta::FromMilliseconds(400); |
| 2111 base::TimeDelta preroll_timeout = base::TimeDelta::FromMilliseconds(3000); |
| 2112 |
| 2113 demuxer_->SetAudioPrerollInterval(audio_preroll_intvl); |
| 2114 |
| 2115 scoped_ptr<AudioFactory> audio_factory(new AudioFactory(duration)); |
| 2116 audio_factory->RequestConfigChange(config_change_position); |
| 2117 |
| 2118 scoped_ptr<VideoFactory> video_factory(new VideoFactory(duration)); |
| 2119 |
| 2120 ASSERT_TRUE(StartAVSeekAndPreroll(audio_factory.Pass(), video_factory.Pass(), |
| 2121 seek_position, kAlwaysReconfigAudio, |
| 2122 "AVPrerollAcrossAudioConfigChange")); |
| 2123 |
| 2124 // Wait till preroll finishes and the real playback starts. |
| 2125 EXPECT_TRUE( |
| 2126 WaitForCondition(base::Bind(&MockMediaPlayerManager::IsPlaybackStarted, |
| 2127 base::Unretained(&manager_)), |
| 2128 preroll_timeout)); |
| 2129 |
| 2130 // The presense of config change should not affect preroll behavior: |
| 2131 |
| 2132 // Ensure that the first audio and video pts are close to each other and are |
| 2133 // reported at the close moments in time. |
| 2134 |
| 2135 EXPECT_TRUE(manager_.HasFirstFrame(DemuxerStream::AUDIO)); |
| 2136 EXPECT_TRUE(WaitForCondition( |
| 2137 base::Bind(&MockMediaPlayerManager::HasFirstFrame, |
| 2138 base::Unretained(&manager_), DemuxerStream::VIDEO))); |
| 2139 |
| 2140 // Wait for some more video |
| 2141 WaitForDelay(base::TimeDelta::FromMilliseconds(100)); |
| 2142 |
| 2143 EXPECT_TRUE(AlmostEqual(manager_.FirstFramePTS(DemuxerStream::AUDIO), |
| 2144 manager_.FirstFramePTS(DemuxerStream::VIDEO), 25)); |
| 2145 |
| 2146 // Because for video preroll the first frame after preroll renders during the |
| 2147 // preroll stage (and not after the preroll is done) we cannot guarantee the |
| 2148 // proper video timimg in this test. |
| 2149 // TODO(timav): maybe we should not call the testing callback for |
| 2150 // kRenderAfterPreroll for video (for audio we already do not call). |
| 2151 // EXPECT_TRUE(AlmostEqual(manager_.FirstFrameTime(DemuxerStream::AUDIO), |
| 2152 // manager_.FirstFrameTime(DemuxerStream::VIDEO), 50)); |
| 2153 |
| 2154 // The playback should start at |seek_position| |
| 2155 EXPECT_TRUE(AlmostEqual(seek_position, manager_.pts_stat_.min(), 25)); |
| 2156 } |
| 2157 |
1845 } // namespace media | 2158 } // namespace media |
OLD | NEW |