Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(237)

Side by Side Diff: media/base/android/media_codec_player_unittest.cc

Issue 1312103006: MediaCodecPlayer - preroll and reconfiguration fixes (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@mtplayer-reconfig
Patch Set: Rebased Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « media/base/android/media_codec_player.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/timestamp_constants.h" 16 #include "media/base/timestamp_constants.h"
(...skipping 21 matching lines...) Expand all
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 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
210 } 217 }
211 218
212 DemuxerConfigs CreateAudioVideoConfigs(const TestDataFactory* audio, 219 DemuxerConfigs CreateAudioVideoConfigs(const TestDataFactory* audio,
213 const TestDataFactory* video) { 220 const TestDataFactory* video) {
214 DemuxerConfigs result = audio->GetConfigs(); 221 DemuxerConfigs result = audio->GetConfigs();
215 DemuxerConfigs vconf = video->GetConfigs(); 222 DemuxerConfigs vconf = video->GetConfigs();
216 223
217 result.video_codec = vconf.video_codec; 224 result.video_codec = vconf.video_codec;
218 result.video_size = vconf.video_size; 225 result.video_size = vconf.video_size;
219 result.is_video_encrypted = vconf.is_video_encrypted; 226 result.is_video_encrypted = vconf.is_video_encrypted;
227 result.duration = std::max(result.duration, vconf.duration);
220 return result; 228 return result;
221 } 229 }
222 230
223 // AudioFactory creates data chunks that simulate audio stream from demuxer. 231 // AudioFactory creates data chunks that simulate audio stream from demuxer.
224 232
225 class AudioFactory : public TestDataFactory { 233 class AudioFactory : public TestDataFactory {
226 public: 234 public:
227 AudioFactory(base::TimeDelta duration) 235 AudioFactory(base::TimeDelta duration)
228 : TestDataFactory("aac-44100-packet-%d", duration, kAudioFramePeriod) {} 236 : TestDataFactory("aac-44100-packet-%d", duration, kAudioFramePeriod) {}
229 237
(...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after
523 // reaches the given value or for timeout to expire. Returns true if the 531 // reaches the given value or for timeout to expire. Returns true if the
524 // playback has passed the given position. 532 // playback has passed the given position.
525 bool WaitForPlaybackBeyondPosition( 533 bool WaitForPlaybackBeyondPosition(
526 const base::TimeDelta& pts, 534 const base::TimeDelta& pts,
527 const base::TimeDelta& timeout = kDefaultTimeout); 535 const base::TimeDelta& timeout = kDefaultTimeout);
528 536
529 // Helper method that starts video only stream. Waits till it actually 537 // Helper method that starts video only stream. Waits till it actually
530 // started. 538 // started.
531 bool StartVideoPlayback(base::TimeDelta duration, const char* test_name); 539 bool StartVideoPlayback(base::TimeDelta duration, const char* test_name);
532 540
541 // Helper method that starts audio and video streams.
542 bool StartAVPlayback(scoped_ptr<AudioFactory> audio_factory,
543 scoped_ptr<VideoFactory> video_factory,
544 uint32_t flags,
545 const char* test_name);
546
533 // Helper method that starts audio and video streams with preroll. 547 // Helper method that starts audio and video streams with preroll.
534 // The preroll is achieved by setting significant video preroll interval 548 // The preroll is achieved by setting significant video preroll interval
535 // so video will have to catch up with audio. To make room for this interval 549 // so video will have to catch up with audio. To make room for this interval
536 // the Start() command is preceded by SeekTo(). 550 // the Start() command is preceded by SeekTo().
537 bool StartAVSeekAndPreroll(base::TimeDelta duration, 551 bool StartAVSeekAndPreroll(scoped_ptr<AudioFactory> audio_factory,
552 scoped_ptr<VideoFactory> video_factory,
538 base::TimeDelta seek_position, 553 base::TimeDelta seek_position,
539 base::TimeDelta video_preroll, 554 uint32_t flags,
540 const char* test_name); 555 const char* test_name);
541 556
542 // Callback sent when demuxer is being deleted. 557 // Callback sent when demuxer is being deleted.
543 void OnDemuxerDeleted() { demuxer_ = nullptr; } 558 void OnDemuxerDeleted() { demuxer_ = nullptr; }
544 559
545 bool IsDemuxerDeleted() const { return !demuxer_; } 560 bool IsDemuxerDeleted() const { return !demuxer_; }
546 561
547 base::MessageLoop message_loop_; 562 base::MessageLoop message_loop_;
548 MockMediaPlayerManager manager_; 563 MockMediaPlayerManager manager_;
549 MockDemuxerAndroid* demuxer_; // owned by player_ 564 MockDemuxerAndroid* demuxer_; // owned by player_
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
695 start_timeout)); 710 start_timeout));
696 711
697 if (!manager_.IsPlaybackStarted()) { 712 if (!manager_.IsPlaybackStarted()) {
698 DVLOG(0) << test_name << ": playback did not start"; 713 DVLOG(0) << test_name << ": playback did not start";
699 return false; 714 return false;
700 } 715 }
701 716
702 return true; 717 return true;
703 } 718 }
704 719
705 bool MediaCodecPlayerTest::StartAVSeekAndPreroll(base::TimeDelta duration, 720 bool MediaCodecPlayerTest::StartAVPlayback(
706 base::TimeDelta seek_position, 721 scoped_ptr<AudioFactory> audio_factory,
707 base::TimeDelta video_preroll, 722 scoped_ptr<VideoFactory> video_factory,
708 const char* test_name) { 723 uint32_t flags,
709 const base::TimeDelta start_timeout = base::TimeDelta::FromMilliseconds(800); 724 const char* test_name) {
710 725 demuxer_->SetAudioFactory(audio_factory.Pass());
711 demuxer_->SetVideoPrerollInterval(video_preroll); 726 demuxer_->SetVideoFactory(video_factory.Pass());
712
713 demuxer_->SetAudioFactory(
714 scoped_ptr<AudioFactory>(new AudioFactory(duration)));
715 demuxer_->SetVideoFactory(
716 scoped_ptr<VideoFactory>(new VideoFactory(duration)));
717 727
718 CreatePlayer(); 728 CreatePlayer();
729 SetVideoSurface();
719 730
720 // Set special testing callback to receive PTS from decoders. 731 // Wait till the player is initialized on media thread.
732 EXPECT_TRUE(WaitForCondition(base::Bind(&MockDemuxerAndroid::IsInitialized,
733 base::Unretained(demuxer_))));
734
735 if (!demuxer_->IsInitialized()) {
736 DVLOG(0) << test_name << ": demuxer is not initialized";
737 return false;
738 }
739
740 // Ask decoders to always reconfigure after the player has been initialized.
741 if (flags & kAlwaysReconfigAudio)
742 player_->SetAlwaysReconfigureForTests(DemuxerStream::AUDIO);
743 if (flags & kAlwaysReconfigVideo)
744 player_->SetAlwaysReconfigureForTests(DemuxerStream::VIDEO);
745
746 // Set a testing callback to receive PTS from decoders.
721 player_->SetDecodersTimeCallbackForTests( 747 player_->SetDecodersTimeCallbackForTests(
722 base::Bind(&MockMediaPlayerManager::OnDecodersTimeUpdate, 748 base::Bind(&MockMediaPlayerManager::OnDecodersTimeUpdate,
723 base::Unretained(&manager_))); 749 base::Unretained(&manager_)));
724 750
751 // Set a testing callback to receive MediaCodec creation events from decoders.
752 player_->SetCodecCreatedCallbackForTests(
753 base::Bind(&MockMediaPlayerManager::OnMediaCodecCreated,
754 base::Unretained(&manager_)));
755
756 // Post configuration after the player has been initialized.
757 demuxer_->PostInternalConfigs();
758
759 // Start and wait for playback.
760 player_->Start();
761
762 // Wait till we start to play.
763 base::TimeDelta start_timeout = base::TimeDelta::FromMilliseconds(2000);
764
765 EXPECT_TRUE(
766 WaitForCondition(base::Bind(&MockMediaPlayerManager::IsPlaybackStarted,
767 base::Unretained(&manager_)),
768 start_timeout));
769
770 if (!manager_.IsPlaybackStarted()) {
771 DVLOG(0) << test_name << ": playback did not start";
772 return false;
773 }
774
775 return true;
776 }
777
778 bool MediaCodecPlayerTest::StartAVSeekAndPreroll(
779 scoped_ptr<AudioFactory> audio_factory,
780 scoped_ptr<VideoFactory> video_factory,
781 base::TimeDelta seek_position,
782 uint32_t flags,
783 const char* test_name) {
784 // Initialize A/V playback
785
786 demuxer_->SetAudioFactory(audio_factory.Pass());
787 demuxer_->SetVideoFactory(video_factory.Pass());
788
789 CreatePlayer();
790 SetVideoSurface();
791
725 // Wait till the player is initialized on media thread. 792 // Wait till the player is initialized on media thread.
726 EXPECT_TRUE(WaitForCondition(base::Bind(&MockDemuxerAndroid::IsInitialized, 793 EXPECT_TRUE(WaitForCondition(base::Bind(&MockDemuxerAndroid::IsInitialized,
727 base::Unretained(demuxer_)))); 794 base::Unretained(demuxer_))));
728 795
729 if (!demuxer_->IsInitialized()) { 796 if (!demuxer_->IsInitialized()) {
730 DVLOG(0) << test_name << ": demuxer is not initialized"; 797 DVLOG(0) << test_name << ": demuxer is not initialized";
731 return false; 798 return false;
732 } 799 }
733 800
734 SetVideoSurface(); 801 // Ask decoders to always reconfigure after the player has been initialized.
802 if (flags & kAlwaysReconfigAudio)
803 player_->SetAlwaysReconfigureForTests(DemuxerStream::AUDIO);
804 if (flags & kAlwaysReconfigVideo)
805 player_->SetAlwaysReconfigureForTests(DemuxerStream::VIDEO);
806
807 // Set a testing callback to receive PTS from decoders.
808 player_->SetDecodersTimeCallbackForTests(
809 base::Bind(&MockMediaPlayerManager::OnDecodersTimeUpdate,
810 base::Unretained(&manager_)));
811
812 // Set a testing callback to receive MediaCodec creation events from decoders.
813 player_->SetCodecCreatedCallbackForTests(
814 base::Bind(&MockMediaPlayerManager::OnMediaCodecCreated,
815 base::Unretained(&manager_)));
735 816
736 // Post configuration after the player has been initialized. 817 // Post configuration after the player has been initialized.
737 demuxer_->PostInternalConfigs(); 818 demuxer_->PostInternalConfigs();
738 819
739 // Issue SeekTo(). 820 // Issue SeekTo().
740 player_->SeekTo(seek_position); 821 player_->SeekTo(seek_position);
741 822
742 // Start the playback. 823 // Start the playback.
743 player_->Start(); 824 player_->Start();
744 825
745 // Wait till preroll starts. 826 // Wait till preroll starts.
827 base::TimeDelta start_timeout = base::TimeDelta::FromMilliseconds(2000);
746 EXPECT_TRUE(WaitForCondition( 828 EXPECT_TRUE(WaitForCondition(
747 base::Bind(&MediaCodecPlayer::IsPrerollingForTests, 829 base::Bind(&MediaCodecPlayer::IsPrerollingForTests,
748 base::Unretained(player_), DemuxerStream::VIDEO), 830 base::Unretained(player_), DemuxerStream::VIDEO),
749 start_timeout)); 831 start_timeout));
750 832
751 if (!player_->IsPrerollingForTests(DemuxerStream::VIDEO)) { 833 if (!player_->IsPrerollingForTests(DemuxerStream::VIDEO)) {
752 DVLOG(0) << test_name << ": preroll did not happen for video"; 834 DVLOG(0) << test_name << ": preroll did not happen for video";
753 return false; 835 return false;
754 } 836 }
755 837
(...skipping 604 matching lines...) Expand 10 before | Expand all | Expand 10 after
1360 // with a decoder PTS that is delivered by a test-only callback. 1442 // with a decoder PTS that is delivered by a test-only callback.
1361 1443
1362 base::TimeDelta duration = base::TimeDelta::FromMilliseconds(2000); 1444 base::TimeDelta duration = base::TimeDelta::FromMilliseconds(2000);
1363 1445
1364 // Set significant preroll interval. 500 ms means 25 frames, at 10 ms 1446 // Set significant preroll interval. 500 ms means 25 frames, at 10 ms
1365 // per frame it would take 250 ms to preroll. 1447 // per frame it would take 250 ms to preroll.
1366 base::TimeDelta seek_position = base::TimeDelta::FromMilliseconds(1000); 1448 base::TimeDelta seek_position = base::TimeDelta::FromMilliseconds(1000);
1367 base::TimeDelta preroll_intvl = base::TimeDelta::FromMilliseconds(500); 1449 base::TimeDelta preroll_intvl = base::TimeDelta::FromMilliseconds(500);
1368 base::TimeDelta preroll_timeout = base::TimeDelta::FromMilliseconds(1000); 1450 base::TimeDelta preroll_timeout = base::TimeDelta::FromMilliseconds(1000);
1369 1451
1370 ASSERT_TRUE(StartAVSeekAndPreroll(duration, seek_position, preroll_intvl, 1452 scoped_ptr<AudioFactory> audio_factory(new AudioFactory(duration));
1453 scoped_ptr<VideoFactory> video_factory(new VideoFactory(duration));
1454
1455 demuxer_->SetVideoPrerollInterval(preroll_intvl);
1456
1457 ASSERT_TRUE(StartAVSeekAndPreroll(audio_factory.Pass(), video_factory.Pass(),
1458 seek_position, 0,
1371 "AVPrerollAudioWaitsForVideo")); 1459 "AVPrerollAudioWaitsForVideo"));
1372 1460
1373 // Wait till preroll finishes and the real playback starts. 1461 // Wait till preroll finishes and the real playback starts.
1374 EXPECT_TRUE( 1462 EXPECT_TRUE(
1375 WaitForCondition(base::Bind(&MockMediaPlayerManager::IsPlaybackStarted, 1463 WaitForCondition(base::Bind(&MockMediaPlayerManager::IsPlaybackStarted,
1376 base::Unretained(&manager_)), 1464 base::Unretained(&manager_)),
1377 preroll_timeout)); 1465 preroll_timeout));
1378 1466
1379 // Ensure that the first audio and video pts are close to each other and are 1467 // Ensure that the first audio and video pts are close to each other and are
1380 // reported at the close moments in time. 1468 // reported at the close moments in time.
(...skipping 22 matching lines...) Expand all
1403 base::TimeDelta duration = base::TimeDelta::FromMilliseconds(2000); 1491 base::TimeDelta duration = base::TimeDelta::FromMilliseconds(2000);
1404 1492
1405 // Set significant preroll interval. 500 ms means 25 frames, at 10 ms 1493 // Set significant preroll interval. 500 ms means 25 frames, at 10 ms
1406 // per frame it would take 250 ms to preroll. 1494 // per frame it would take 250 ms to preroll.
1407 base::TimeDelta seek_position = base::TimeDelta::FromMilliseconds(1000); 1495 base::TimeDelta seek_position = base::TimeDelta::FromMilliseconds(1000);
1408 base::TimeDelta preroll_intvl = base::TimeDelta::FromMilliseconds(500); 1496 base::TimeDelta preroll_intvl = base::TimeDelta::FromMilliseconds(500);
1409 1497
1410 base::TimeDelta start_timeout = base::TimeDelta::FromMilliseconds(800); 1498 base::TimeDelta start_timeout = base::TimeDelta::FromMilliseconds(800);
1411 base::TimeDelta preroll_timeout = base::TimeDelta::FromMilliseconds(1000); 1499 base::TimeDelta preroll_timeout = base::TimeDelta::FromMilliseconds(1000);
1412 1500
1413 ASSERT_TRUE(StartAVSeekAndPreroll(duration, seek_position, preroll_intvl, 1501 scoped_ptr<AudioFactory> audio_factory(new AudioFactory(duration));
1502 scoped_ptr<VideoFactory> video_factory(new VideoFactory(duration));
1503
1504 demuxer_->SetVideoPrerollInterval(preroll_intvl);
1505
1506 ASSERT_TRUE(StartAVSeekAndPreroll(audio_factory.Pass(), video_factory.Pass(),
1507 seek_position, 0,
1414 "AVPrerollReleaseAndRestart")); 1508 "AVPrerollReleaseAndRestart"));
1415 1509
1416 // Issue Release(). 1510 // Issue Release().
1417 player_->Release(); 1511 player_->Release();
1418 1512
1419 // Make sure we have not been playing. 1513 // Make sure we have not been playing.
1420 WaitForDelay(base::TimeDelta::FromMilliseconds(400)); 1514 WaitForDelay(base::TimeDelta::FromMilliseconds(400));
1421 1515
1422 EXPECT_FALSE(manager_.HasFirstFrame(DemuxerStream::AUDIO)); 1516 EXPECT_FALSE(manager_.HasFirstFrame(DemuxerStream::AUDIO));
1423 EXPECT_FALSE(manager_.HasFirstFrame(DemuxerStream::VIDEO)); 1517 EXPECT_FALSE(manager_.HasFirstFrame(DemuxerStream::VIDEO));
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
1471 base::TimeDelta duration = base::TimeDelta::FromMilliseconds(1200); 1565 base::TimeDelta duration = base::TimeDelta::FromMilliseconds(1200);
1472 1566
1473 // Set significant preroll interval. 500 ms means 25 frames, at 10 ms 1567 // Set significant preroll interval. 500 ms means 25 frames, at 10 ms
1474 // per frame it would take 250 ms to preroll. 1568 // per frame it would take 250 ms to preroll.
1475 base::TimeDelta seek_position = base::TimeDelta::FromMilliseconds(1000); 1569 base::TimeDelta seek_position = base::TimeDelta::FromMilliseconds(1000);
1476 base::TimeDelta preroll_intvl = base::TimeDelta::FromMilliseconds(500); 1570 base::TimeDelta preroll_intvl = base::TimeDelta::FromMilliseconds(500);
1477 1571
1478 base::TimeDelta start_timeout = base::TimeDelta::FromMilliseconds(800); 1572 base::TimeDelta start_timeout = base::TimeDelta::FromMilliseconds(800);
1479 base::TimeDelta preroll_timeout = base::TimeDelta::FromMilliseconds(1000); 1573 base::TimeDelta preroll_timeout = base::TimeDelta::FromMilliseconds(1000);
1480 1574
1481 ASSERT_TRUE(StartAVSeekAndPreroll(duration, seek_position, preroll_intvl, 1575 scoped_ptr<AudioFactory> audio_factory(new AudioFactory(duration));
1576 scoped_ptr<VideoFactory> video_factory(new VideoFactory(duration));
1577
1578 demuxer_->SetVideoPrerollInterval(preroll_intvl);
1579
1580 ASSERT_TRUE(StartAVSeekAndPreroll(audio_factory.Pass(), video_factory.Pass(),
1581 seek_position, 0,
1482 "AVPrerollStopAndRestart")); 1582 "AVPrerollStopAndRestart"));
1483 1583
1484 // Video stream should be prerolling. Request to stop. 1584 // Video stream should be prerolling. Request to stop.
1485 EXPECT_FALSE(IsPaused()); 1585 EXPECT_FALSE(IsPaused());
1486 player_->Pause(true); 1586 player_->Pause(true);
1487 1587
1488 EXPECT_TRUE(WaitForCondition( 1588 EXPECT_TRUE(WaitForCondition(
1489 base::Bind(&MediaCodecPlayerTest::IsPaused, base::Unretained(this)))); 1589 base::Bind(&MediaCodecPlayerTest::IsPaused, base::Unretained(this))));
1490 1590
1491 // Test that we have not been playing. 1591 // Test that we have not been playing.
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
1674 demuxer_->video_factory()->RequestConfigChange(config_change_position); 1774 demuxer_->video_factory()->RequestConfigChange(config_change_position);
1675 1775
1676 CreatePlayer(); 1776 CreatePlayer();
1677 SetVideoSurface(); 1777 SetVideoSurface();
1678 1778
1679 // Wait till the player is initialized on media thread. 1779 // Wait till the player is initialized on media thread.
1680 EXPECT_TRUE(WaitForCondition(base::Bind(&MockDemuxerAndroid::IsInitialized, 1780 EXPECT_TRUE(WaitForCondition(base::Bind(&MockDemuxerAndroid::IsInitialized,
1681 base::Unretained(demuxer_)))); 1781 base::Unretained(demuxer_))));
1682 1782
1683 if (!demuxer_->IsInitialized()) { 1783 if (!demuxer_->IsInitialized()) {
1684 DVLOG(0) << "AVConfigChangeWhilePlaying: demuxer is not initialized"; 1784 DVLOG(0) << "VideoConfigChangeWhilePlaying: demuxer is not initialized";
1685 return; 1785 return;
1686 } 1786 }
1687 1787
1688 // Ask decoders to always reconfigure after the player has been initialized. 1788 // Ask decoders to always reconfigure after the player has been initialized.
1689 player_->SetAlwaysReconfigureForTests(DemuxerStream::VIDEO); 1789 player_->SetAlwaysReconfigureForTests(DemuxerStream::VIDEO);
1690 1790
1691 // Set a testing callback to receive PTS from decoders. 1791 // Set a testing callback to receive PTS from decoders.
1692 player_->SetDecodersTimeCallbackForTests( 1792 player_->SetDecodersTimeCallbackForTests(
1693 base::Bind(&MockMediaPlayerManager::OnDecodersTimeUpdate, 1793 base::Bind(&MockMediaPlayerManager::OnDecodersTimeUpdate,
1694 base::Unretained(&manager_))); 1794 base::Unretained(&manager_)));
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
1728 TEST_F(MediaCodecPlayerTest, AVVideoConfigChangeWhilePlaying) { 1828 TEST_F(MediaCodecPlayerTest, AVVideoConfigChangeWhilePlaying) {
1729 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); 1829 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
1730 1830
1731 // Test that A/V playback continues after video config change. 1831 // Test that A/V playback continues after video config change.
1732 1832
1733 // Initialize A/V playback 1833 // Initialize A/V playback
1734 base::TimeDelta duration = base::TimeDelta::FromMilliseconds(1200); 1834 base::TimeDelta duration = base::TimeDelta::FromMilliseconds(1200);
1735 base::TimeDelta config_change_position = 1835 base::TimeDelta config_change_position =
1736 base::TimeDelta::FromMilliseconds(1000); 1836 base::TimeDelta::FromMilliseconds(1000);
1737 1837
1738 base::TimeDelta start_timeout = base::TimeDelta::FromMilliseconds(2000);
1739 base::TimeDelta completion_timeout = base::TimeDelta::FromMilliseconds(3000); 1838 base::TimeDelta completion_timeout = base::TimeDelta::FromMilliseconds(3000);
1740 1839
1741 demuxer_->SetAudioFactory( 1840 scoped_ptr<AudioFactory> audio_factory(new AudioFactory(duration));
1742 scoped_ptr<AudioFactory>(new AudioFactory(duration))); 1841 scoped_ptr<VideoFactory> video_factory(new VideoFactory(duration));
1743 demuxer_->SetVideoFactory(
1744 scoped_ptr<VideoFactory>(new VideoFactory(duration)));
1745 1842
1746 demuxer_->video_factory()->RequestConfigChange(config_change_position); 1843 video_factory->RequestConfigChange(config_change_position);
1747 1844
1748 CreatePlayer(); 1845 ASSERT_TRUE(StartAVPlayback(audio_factory.Pass(), video_factory.Pass(),
1749 SetVideoSurface(); 1846 kAlwaysReconfigVideo,
1750 1847 "AVVideoConfigChangeWhilePlaying"));
1751 // Wait till the player is initialized on media thread.
1752 EXPECT_TRUE(WaitForCondition(base::Bind(&MockDemuxerAndroid::IsInitialized,
1753 base::Unretained(demuxer_))));
1754
1755 if (!demuxer_->IsInitialized()) {
1756 DVLOG(0) << "AVConfigChangeWhilePlaying: demuxer is not initialized";
1757 return;
1758 }
1759
1760 // Ask decoders to always reconfigure after the player has been initialized.
1761 player_->SetAlwaysReconfigureForTests(DemuxerStream::VIDEO);
1762
1763 // Set a testing callback to receive PTS from decoders.
1764 player_->SetDecodersTimeCallbackForTests(
1765 base::Bind(&MockMediaPlayerManager::OnDecodersTimeUpdate,
1766 base::Unretained(&manager_)));
1767
1768 // Set a testing callback to receive MediaCodec creation events from decoders.
1769 player_->SetCodecCreatedCallbackForTests(
1770 base::Bind(&MockMediaPlayerManager::OnMediaCodecCreated,
1771 base::Unretained(&manager_)));
1772
1773 // Post configuration after the player has been initialized.
1774 demuxer_->PostInternalConfigs();
1775
1776 // Start and wait for playback.
1777 player_->Start();
1778
1779 // Wait till we start to play.
1780 EXPECT_TRUE(
1781 WaitForCondition(base::Bind(&MockMediaPlayerManager::IsPlaybackStarted,
1782 base::Unretained(&manager_)),
1783 start_timeout));
1784 1848
1785 // Wait till completion 1849 // Wait till completion
1786 EXPECT_TRUE( 1850 EXPECT_TRUE(
1787 WaitForCondition(base::Bind(&MockMediaPlayerManager::IsPlaybackCompleted, 1851 WaitForCondition(base::Bind(&MockMediaPlayerManager::IsPlaybackCompleted,
1788 base::Unretained(&manager_)), 1852 base::Unretained(&manager_)),
1789 completion_timeout)); 1853 completion_timeout));
1790 1854
1791 // The audio codec should be kept. 1855 // The audio codec should be kept.
1792 EXPECT_EQ(1, manager_.num_audio_codecs_created()); 1856 EXPECT_EQ(1, manager_.num_audio_codecs_created());
1793 1857
1794 // The video codec should be recreated upon config changes. 1858 // The video codec should be recreated upon config changes.
1795 EXPECT_EQ(2, manager_.num_video_codecs_created()); 1859 EXPECT_EQ(2, manager_.num_video_codecs_created());
1796 1860
1797 // Check that we did not miss video frames 1861 // Check that we did not miss video frames
1798 int expected_video_frames = duration / kVideoFramePeriod + 1; 1862 int expected_video_frames = duration / kVideoFramePeriod + 1;
1799 EXPECT_EQ(expected_video_frames, 1863 EXPECT_EQ(expected_video_frames,
1800 manager_.render_stat_[DemuxerStream::VIDEO].num_values()); 1864 manager_.render_stat_[DemuxerStream::VIDEO].num_values());
1801 1865
1802 // Check that we did not miss audio frames. We expect two postponed frames 1866 // Check that we did not miss audio frames. We expect one postponed frames
1803 // that are not reported. 1867 // that are not reported.
1804 // For Nexus 4 KitKat the AAC decoder seems to swallow the first frame 1868 // For Nexus 4 KitKat the AAC decoder seems to swallow the first frame
1805 // but reports the last pts twice, maybe it just shifts the reported PTS. 1869 // but reports the last pts twice, maybe it just shifts the reported PTS.
1806 int expected_audio_frames = duration / kAudioFramePeriod + 1 - 2; 1870 int expected_audio_frames = duration / kAudioFramePeriod + 1 - 1;
1807 EXPECT_EQ(expected_audio_frames, 1871 EXPECT_EQ(expected_audio_frames,
1808 manager_.render_stat_[DemuxerStream::AUDIO].num_values()); 1872 manager_.render_stat_[DemuxerStream::AUDIO].num_values());
1809 } 1873 }
1810 1874
1811 TEST_F(MediaCodecPlayerTest, AVAudioConfigChangeWhilePlaying) { 1875 TEST_F(MediaCodecPlayerTest, AVAudioConfigChangeWhilePlaying) {
1812 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); 1876 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
1813 1877
1814 // Test that A/V playback continues after audio config change. 1878 // Test that A/V playback continues after audio config change.
1815 1879
1816 // Initialize A/V playback
1817 base::TimeDelta duration = base::TimeDelta::FromMilliseconds(1200); 1880 base::TimeDelta duration = base::TimeDelta::FromMilliseconds(1200);
1818 base::TimeDelta config_change_position = 1881 base::TimeDelta config_change_position =
1819 base::TimeDelta::FromMilliseconds(1000); 1882 base::TimeDelta::FromMilliseconds(1000);
1820 1883
1821 base::TimeDelta start_timeout = base::TimeDelta::FromMilliseconds(2000);
1822 base::TimeDelta completion_timeout = base::TimeDelta::FromMilliseconds(3000); 1884 base::TimeDelta completion_timeout = base::TimeDelta::FromMilliseconds(3000);
1823 1885
1824 demuxer_->SetAudioFactory( 1886 scoped_ptr<AudioFactory> audio_factory(new AudioFactory(duration));
1825 scoped_ptr<AudioFactory>(new AudioFactory(duration))); 1887 scoped_ptr<VideoFactory> video_factory(new VideoFactory(duration));
1826 demuxer_->SetVideoFactory(
1827 scoped_ptr<VideoFactory>(new VideoFactory(duration)));
1828 1888
1829 demuxer_->audio_factory()->RequestConfigChange(config_change_position); 1889 audio_factory->RequestConfigChange(config_change_position);
1830 1890
1831 CreatePlayer(); 1891 ASSERT_TRUE(StartAVPlayback(audio_factory.Pass(), video_factory.Pass(),
1832 SetVideoSurface(); 1892 kAlwaysReconfigAudio,
1833 1893 "AVAudioConfigChangeWhilePlaying"));
1834 // Wait till the player is initialized on media thread.
1835 EXPECT_TRUE(WaitForCondition(base::Bind(&MockDemuxerAndroid::IsInitialized,
1836 base::Unretained(demuxer_))));
1837
1838 if (!demuxer_->IsInitialized()) {
1839 DVLOG(0) << "AVConfigChangeWhilePlaying: demuxer is not initialized";
1840 return;
1841 }
1842
1843 // Ask decoders to always reconfigure after the player has been initialized.
1844 player_->SetAlwaysReconfigureForTests(DemuxerStream::AUDIO);
1845
1846 // Set a testing callback to receive PTS from decoders.
1847 player_->SetDecodersTimeCallbackForTests(
1848 base::Bind(&MockMediaPlayerManager::OnDecodersTimeUpdate,
1849 base::Unretained(&manager_)));
1850
1851 // Set a testing callback to receive MediaCodec creation events from decoders.
1852 player_->SetCodecCreatedCallbackForTests(
1853 base::Bind(&MockMediaPlayerManager::OnMediaCodecCreated,
1854 base::Unretained(&manager_)));
1855
1856 // Post configuration after the player has been initialized.
1857 demuxer_->PostInternalConfigs();
1858
1859 // Start and wait for playback.
1860 player_->Start();
1861
1862 // Wait till we start to play.
1863 EXPECT_TRUE(
1864 WaitForCondition(base::Bind(&MockMediaPlayerManager::IsPlaybackStarted,
1865 base::Unretained(&manager_)),
1866 start_timeout));
1867 1894
1868 // Wait till completion 1895 // Wait till completion
1869 EXPECT_TRUE( 1896 EXPECT_TRUE(
1897 WaitForCondition(base::Bind(&MockMediaPlayerManager::IsPlaybackCompleted,
1898 base::Unretained(&manager_)),
1899 completion_timeout));
1900
1901 // The audio codec should be recreated upon config changes.
1902 EXPECT_EQ(2, manager_.num_audio_codecs_created());
1903
1904 // The video codec should be kept.
1905 EXPECT_EQ(1, manager_.num_video_codecs_created());
1906
1907 // Check that we did not miss video frames.
1908 int expected_video_frames = duration / kVideoFramePeriod + 1;
1909 EXPECT_EQ(expected_video_frames,
1910 manager_.render_stat_[DemuxerStream::VIDEO].num_values());
1911
1912 // Check that we did not miss audio frames. We expect two postponed frames
1913 // that are not reported.
1914 int expected_audio_frames = duration / kAudioFramePeriod + 1 - 2;
1915 EXPECT_EQ(expected_audio_frames,
1916 manager_.render_stat_[DemuxerStream::AUDIO].num_values());
1917 }
1918
1919 TEST_F(MediaCodecPlayerTest, AVSimultaneousConfigChange_1) {
1920 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
1921
1922 // Test that the playback continues if audio and video config changes happen
1923 // at the same time.
1924
1925 base::TimeDelta duration = base::TimeDelta::FromMilliseconds(1200);
1926 base::TimeDelta config_change_audio = base::TimeDelta::FromMilliseconds(1000);
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_1"));
1940
1941 // Wait till completion
1942 EXPECT_TRUE(
1943 WaitForCondition(base::Bind(&MockMediaPlayerManager::IsPlaybackCompleted,
1944 base::Unretained(&manager_)),
1945 completion_timeout));
1946
1947 // The audio codec should be recreated upon config changes.
1948 EXPECT_EQ(2, manager_.num_audio_codecs_created());
1949
1950 // The video codec should be recreated upon config changes.
1951 EXPECT_EQ(2, manager_.num_video_codecs_created());
1952
1953 // Check that we did not miss video frames.
1954 int expected_video_frames = duration / kVideoFramePeriod + 1;
1955 EXPECT_EQ(expected_video_frames,
1956 manager_.render_stat_[DemuxerStream::VIDEO].num_values());
1957
1958 // Check that we did not miss audio frames. We expect two postponed frames
1959 // that are not reported.
1960 int expected_audio_frames = duration / kAudioFramePeriod + 1 - 2;
1961 EXPECT_EQ(expected_audio_frames,
1962 manager_.render_stat_[DemuxerStream::AUDIO].num_values());
1963 }
1964
1965 TEST_F(MediaCodecPlayerTest, AVSimultaneousConfigChange_2) {
1966 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
1967
1968 // Test that the playback continues if audio and video config changes happen
1969 // at the same time. Move audio change moment slightly to make it drained
1970 // after video.
1971
1972 base::TimeDelta duration = base::TimeDelta::FromMilliseconds(1200);
1973 base::TimeDelta config_change_audio = base::TimeDelta::FromMilliseconds(1020);
1974 base::TimeDelta config_change_video = base::TimeDelta::FromMilliseconds(1000);
1975
1976 base::TimeDelta completion_timeout = base::TimeDelta::FromMilliseconds(3000);
1977
1978 scoped_ptr<AudioFactory> audio_factory(new AudioFactory(duration));
1979 scoped_ptr<VideoFactory> video_factory(new VideoFactory(duration));
1980
1981 audio_factory->RequestConfigChange(config_change_audio);
1982 video_factory->RequestConfigChange(config_change_video);
1983
1984 ASSERT_TRUE(StartAVPlayback(audio_factory.Pass(), video_factory.Pass(),
1985 kAlwaysReconfigAudio | kAlwaysReconfigVideo,
1986 "AVSimultaneousConfigChange_2"));
1987
1988 // Wait till completion
1989 EXPECT_TRUE(
1870 WaitForCondition(base::Bind(&MockMediaPlayerManager::IsPlaybackCompleted, 1990 WaitForCondition(base::Bind(&MockMediaPlayerManager::IsPlaybackCompleted,
1871 base::Unretained(&manager_)), 1991 base::Unretained(&manager_)),
1872 completion_timeout)); 1992 completion_timeout));
1873 1993
1874 // The audio codec should be recreated upon config changes. 1994 // The audio codec should be recreated upon config changes.
1875 EXPECT_EQ(2, manager_.num_audio_codecs_created()); 1995 EXPECT_EQ(2, manager_.num_audio_codecs_created());
1876 1996
1877 // The video codec should be kept. 1997 // The video codec should be recreated upon config changes.
1878 EXPECT_EQ(1, manager_.num_video_codecs_created()); 1998 EXPECT_EQ(2, manager_.num_video_codecs_created());
1879 1999
1880 // Check that we did not miss video frames. 2000 // Check that we did not miss video frames.
1881 int expected_video_frames = duration / kVideoFramePeriod + 1; 2001 int expected_video_frames = duration / kVideoFramePeriod + 1;
1882 EXPECT_EQ(expected_video_frames, 2002 EXPECT_EQ(expected_video_frames,
1883 manager_.render_stat_[DemuxerStream::VIDEO].num_values()); 2003 manager_.render_stat_[DemuxerStream::VIDEO].num_values());
1884 2004
1885 // Check that we did not miss audio frames. We expect two postponed frames 2005 // Check that we did not miss audio frames. We expect two postponed frames
1886 // that are not reported. 2006 // that are not reported.
1887 int expected_audio_frames = duration / kAudioFramePeriod + 1 - 2; 2007 int expected_audio_frames = duration / kAudioFramePeriod + 1 - 2;
1888 EXPECT_EQ(expected_audio_frames, 2008 EXPECT_EQ(expected_audio_frames,
1889 manager_.render_stat_[DemuxerStream::AUDIO].num_values()); 2009 manager_.render_stat_[DemuxerStream::AUDIO].num_values());
1890 } 2010 }
1891 2011
2012 TEST_F(MediaCodecPlayerTest, AVAudioEndsAcrossVideoConfigChange) {
2013 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
2014
2015 // Test that audio can end while video config change processing.
2016
2017 base::TimeDelta audio_duration = base::TimeDelta::FromMilliseconds(1000);
2018 base::TimeDelta video_duration = base::TimeDelta::FromMilliseconds(1200);
2019 base::TimeDelta config_change_video = base::TimeDelta::FromMilliseconds(1000);
2020
2021 base::TimeDelta completion_timeout = base::TimeDelta::FromMilliseconds(3000);
2022
2023 scoped_ptr<AudioFactory> audio_factory(new AudioFactory(audio_duration));
2024 scoped_ptr<VideoFactory> video_factory(new VideoFactory(video_duration));
2025
2026 video_factory->RequestConfigChange(config_change_video);
2027
2028 ASSERT_TRUE(StartAVPlayback(audio_factory.Pass(), video_factory.Pass(),
2029 kAlwaysReconfigVideo,
2030 "AVAudioEndsAcrossVideoConfigChange"));
2031
2032 // Wait till completion
2033 EXPECT_TRUE(
2034 WaitForCondition(base::Bind(&MockMediaPlayerManager::IsPlaybackCompleted,
2035 base::Unretained(&manager_)),
2036 completion_timeout));
2037
2038 // The audio codec should not be recreated.
2039 EXPECT_EQ(1, manager_.num_audio_codecs_created());
2040
2041 // The video codec should be recreated upon config changes.
2042 EXPECT_EQ(2, manager_.num_video_codecs_created());
2043
2044 // Check that we did not miss video frames.
2045 int expected_video_frames = video_duration / kVideoFramePeriod + 1;
2046 EXPECT_EQ(expected_video_frames,
2047 manager_.render_stat_[DemuxerStream::VIDEO].num_values());
2048
2049 // Check the last video frame timestamp. The maximum render pts may differ
2050 // from |video_duration| because of the testing artefact: if the last video
2051 // chunk is incomplete if will have different last pts due to B-frames
2052 // rearrangements.
2053 EXPECT_LE(video_duration,
2054 manager_.render_stat_[DemuxerStream::VIDEO].max().pts);
2055
2056 // Check that the playback time reported by the player goes past
2057 // the audio time and corresponds to video after the audio ended.
2058 EXPECT_EQ(video_duration, manager_.pts_stat_.max());
2059 }
2060
2061 TEST_F(MediaCodecPlayerTest, AVVideoEndsAcrossAudioConfigChange) {
2062 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
2063
2064 // Test that video can end while audio config change processing.
2065 base::TimeDelta audio_duration = base::TimeDelta::FromMilliseconds(1200);
2066 base::TimeDelta video_duration = base::TimeDelta::FromMilliseconds(1000);
2067 base::TimeDelta config_change_audio = base::TimeDelta::FromMilliseconds(1000);
2068
2069 base::TimeDelta completion_timeout = base::TimeDelta::FromMilliseconds(3000);
2070
2071 scoped_ptr<AudioFactory> audio_factory(new AudioFactory(audio_duration));
2072 scoped_ptr<VideoFactory> video_factory(new VideoFactory(video_duration));
2073
2074 audio_factory->RequestConfigChange(config_change_audio);
2075
2076 ASSERT_TRUE(StartAVPlayback(audio_factory.Pass(), video_factory.Pass(),
2077 kAlwaysReconfigAudio,
2078 "AVVideoEndsAcrossAudioConfigChange"));
2079
2080 // Wait till completion
2081 EXPECT_TRUE(
2082 WaitForCondition(base::Bind(&MockMediaPlayerManager::IsPlaybackCompleted,
2083 base::Unretained(&manager_)),
2084 completion_timeout));
2085
2086 // The audio codec should be recreated upon config changes.
2087 EXPECT_EQ(2, manager_.num_audio_codecs_created());
2088
2089 // The video codec should not be recreated.
2090 EXPECT_EQ(1, manager_.num_video_codecs_created());
2091
2092 // Check that we did not miss audio frames. We expect two postponed frames
2093 // that are not reported.
2094 int expected_audio_frames = audio_duration / kAudioFramePeriod + 1 - 2;
2095 EXPECT_EQ(expected_audio_frames,
2096 manager_.render_stat_[DemuxerStream::AUDIO].num_values());
2097 }
2098
2099 TEST_F(MediaCodecPlayerTest, AVPrerollAcrossVideoConfigChange) {
2100 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
2101
2102 // Test that preroll continues if interrupted by video config change.
2103
2104 base::TimeDelta duration = base::TimeDelta::FromMilliseconds(1200);
2105 base::TimeDelta seek_position = base::TimeDelta::FromMilliseconds(1000);
2106 base::TimeDelta config_change_position =
2107 base::TimeDelta::FromMilliseconds(800);
2108 base::TimeDelta video_preroll_intvl = base::TimeDelta::FromMilliseconds(500);
2109 base::TimeDelta preroll_timeout = base::TimeDelta::FromMilliseconds(3000);
2110
2111 demuxer_->SetVideoPrerollInterval(video_preroll_intvl);
2112
2113 scoped_ptr<AudioFactory> audio_factory(new AudioFactory(duration));
2114
2115 scoped_ptr<VideoFactory> video_factory(new VideoFactory(duration));
2116 video_factory->RequestConfigChange(config_change_position);
2117
2118 ASSERT_TRUE(StartAVSeekAndPreroll(audio_factory.Pass(), video_factory.Pass(),
2119 seek_position, kAlwaysReconfigVideo,
2120 "AVPrerollAcrossVideoConfigChange"));
2121
2122 // Wait till preroll finishes and the real playback starts.
2123 EXPECT_TRUE(
2124 WaitForCondition(base::Bind(&MockMediaPlayerManager::IsPlaybackStarted,
2125 base::Unretained(&manager_)),
2126 preroll_timeout));
2127
2128 // The presense of config change should not affect preroll behavior:
2129
2130 // Ensure that the first audio and video pts are close to each other and are
2131 // reported at the close moments in time.
2132
2133 EXPECT_TRUE(manager_.HasFirstFrame(DemuxerStream::AUDIO));
2134 EXPECT_TRUE(WaitForCondition(
2135 base::Bind(&MockMediaPlayerManager::HasFirstFrame,
2136 base::Unretained(&manager_), DemuxerStream::VIDEO)));
2137
2138 EXPECT_TRUE(AlmostEqual(manager_.FirstFramePTS(DemuxerStream::AUDIO),
2139 manager_.FirstFramePTS(DemuxerStream::VIDEO), 25));
2140
2141 EXPECT_TRUE(AlmostEqual(manager_.FirstFrameTime(DemuxerStream::AUDIO),
2142 manager_.FirstFrameTime(DemuxerStream::VIDEO), 50));
2143
2144 // The playback should start at |seek_position|
2145 EXPECT_TRUE(AlmostEqual(seek_position, manager_.pts_stat_.min(), 25));
2146 }
2147
2148 TEST_F(MediaCodecPlayerTest, AVPrerollAcrossAudioConfigChange) {
2149 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
2150
2151 // Test that preroll continues if interrupted by video config change.
2152
2153 base::TimeDelta duration = base::TimeDelta::FromMilliseconds(1200);
2154 base::TimeDelta seek_position = base::TimeDelta::FromMilliseconds(1000);
2155 base::TimeDelta config_change_position =
2156 base::TimeDelta::FromMilliseconds(800);
2157 base::TimeDelta audio_preroll_intvl = base::TimeDelta::FromMilliseconds(400);
2158 base::TimeDelta preroll_timeout = base::TimeDelta::FromMilliseconds(3000);
2159
2160 demuxer_->SetAudioPrerollInterval(audio_preroll_intvl);
2161
2162 scoped_ptr<AudioFactory> audio_factory(new AudioFactory(duration));
2163 audio_factory->RequestConfigChange(config_change_position);
2164
2165 scoped_ptr<VideoFactory> video_factory(new VideoFactory(duration));
2166
2167 ASSERT_TRUE(StartAVSeekAndPreroll(audio_factory.Pass(), video_factory.Pass(),
2168 seek_position, kAlwaysReconfigAudio,
2169 "AVPrerollAcrossAudioConfigChange"));
2170
2171 // Wait till preroll finishes and the real playback starts.
2172 EXPECT_TRUE(
2173 WaitForCondition(base::Bind(&MockMediaPlayerManager::IsPlaybackStarted,
2174 base::Unretained(&manager_)),
2175 preroll_timeout));
2176
2177 // The presense of config change should not affect preroll behavior:
2178
2179 // Ensure that the first audio and video pts are close to each other and are
2180 // reported at the close moments in time.
2181
2182 EXPECT_TRUE(manager_.HasFirstFrame(DemuxerStream::AUDIO));
2183 EXPECT_TRUE(WaitForCondition(
2184 base::Bind(&MockMediaPlayerManager::HasFirstFrame,
2185 base::Unretained(&manager_), DemuxerStream::VIDEO)));
2186
2187 // Wait for some more video
2188 WaitForDelay(base::TimeDelta::FromMilliseconds(100));
2189
2190 EXPECT_TRUE(AlmostEqual(manager_.FirstFramePTS(DemuxerStream::AUDIO),
2191 manager_.FirstFramePTS(DemuxerStream::VIDEO), 25));
2192
2193 // Because for video preroll the first frame after preroll renders during the
2194 // preroll stage (and not after the preroll is done) we cannot guarantee the
2195 // proper video timimg in this test.
2196 // TODO(timav): maybe we should not call the testing callback for
2197 // kRenderAfterPreroll for video (for audio we already do not call).
2198 // EXPECT_TRUE(AlmostEqual(manager_.FirstFrameTime(DemuxerStream::AUDIO),
2199 // manager_.FirstFrameTime(DemuxerStream::VIDEO), 50));
2200
2201 // The playback should start at |seek_position|
2202 EXPECT_TRUE(AlmostEqual(seek_position, manager_.pts_stat_.min(), 25));
2203 }
2204
1892 } // namespace media 2205 } // namespace media
OLDNEW
« no previous file with comments | « media/base/android/media_codec_player.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698