OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include <stddef.h> | 5 #include <stddef.h> |
6 #include <stdint.h> | 6 #include <stdint.h> |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 666 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
677 private: | 677 private: |
678 interfaces::ServiceFactoryPtr media_service_factory_; | 678 interfaces::ServiceFactoryPtr media_service_factory_; |
679 }; | 679 }; |
680 #else | 680 #else |
681 class PipelineIntegrationTestHost : public testing::Test, | 681 class PipelineIntegrationTestHost : public testing::Test, |
682 public PipelineIntegrationTestBase {}; | 682 public PipelineIntegrationTestBase {}; |
683 #endif // defined(MOJO_RENDERER) | 683 #endif // defined(MOJO_RENDERER) |
684 | 684 |
685 class PipelineIntegrationTest : public PipelineIntegrationTestHost { | 685 class PipelineIntegrationTest : public PipelineIntegrationTestHost { |
686 public: | 686 public: |
687 void StartPipelineWithMediaSource(MockMediaSource* source) { | 687 PipelineStatus StartPipelineWithMediaSource(MockMediaSource* source) { |
| 688 return StartPipelineWithMediaSource(source, kNormal); |
| 689 } |
| 690 |
| 691 PipelineStatus StartPipelineWithMediaSource(MockMediaSource* source, |
| 692 uint8_t test_type) { |
| 693 hashing_enabled_ = test_type & kHashed; |
| 694 clockless_playback_ = test_type & kClockless; |
| 695 |
688 EXPECT_CALL(*source, InitSegmentReceived(_)).Times(AtLeast(1)); | 696 EXPECT_CALL(*source, InitSegmentReceived(_)).Times(AtLeast(1)); |
689 EXPECT_CALL(*this, OnMetadata(_)) | 697 EXPECT_CALL(*this, OnMetadata(_)) |
690 .Times(AtMost(1)) | 698 .Times(AtMost(1)) |
691 .WillRepeatedly(SaveArg<0>(&metadata_)); | 699 .WillRepeatedly(SaveArg<0>(&metadata_)); |
692 EXPECT_CALL(*this, OnBufferingStateChanged(BUFFERING_HAVE_ENOUGH)) | 700 EXPECT_CALL(*this, OnBufferingStateChanged(BUFFERING_HAVE_ENOUGH)) |
693 .Times(AnyNumber()); | 701 .Times(AnyNumber()); |
694 EXPECT_CALL(*this, OnBufferingStateChanged(BUFFERING_HAVE_NOTHING)) | 702 EXPECT_CALL(*this, OnBufferingStateChanged(BUFFERING_HAVE_NOTHING)) |
695 .Times(AnyNumber()); | 703 .Times(AnyNumber()); |
696 | 704 |
697 // Encrypted content not used, so this is never called. | 705 // Encrypted content not used, so this is never called. |
698 EXPECT_CALL(*this, OnWaitingForDecryptionKey()).Times(0); | 706 EXPECT_CALL(*this, OnWaitingForDecryptionKey()).Times(0); |
699 | 707 |
700 demuxer_ = source->GetDemuxer(); | 708 demuxer_ = source->GetDemuxer(); |
701 pipeline_->Start( | 709 pipeline_->Start( |
702 demuxer_.get(), CreateRenderer(), | 710 demuxer_.get(), CreateRenderer(), |
703 base::Bind(&PipelineIntegrationTest::OnEnded, base::Unretained(this)), | 711 base::Bind(&PipelineIntegrationTest::OnEnded, base::Unretained(this)), |
704 base::Bind(&PipelineIntegrationTest::OnError, base::Unretained(this)), | 712 base::Bind(&PipelineIntegrationTest::OnError, base::Unretained(this)), |
705 base::Bind(&PipelineIntegrationTest::OnStatusCallback, | 713 base::Bind(&PipelineIntegrationTest::OnStatusCallback, |
706 base::Unretained(this)), | 714 base::Unretained(this)), |
707 base::Bind(&PipelineIntegrationTest::OnMetadata, | 715 base::Bind(&PipelineIntegrationTest::OnMetadata, |
708 base::Unretained(this)), | 716 base::Unretained(this)), |
709 base::Bind(&PipelineIntegrationTest::OnBufferingStateChanged, | 717 base::Bind(&PipelineIntegrationTest::OnBufferingStateChanged, |
710 base::Unretained(this)), | 718 base::Unretained(this)), |
711 base::Closure(), base::Bind(&PipelineIntegrationTest::OnAddTextTrack, | 719 base::Closure(), base::Bind(&PipelineIntegrationTest::OnAddTextTrack, |
712 base::Unretained(this)), | 720 base::Unretained(this)), |
713 base::Bind(&PipelineIntegrationTest::OnWaitingForDecryptionKey, | 721 base::Bind(&PipelineIntegrationTest::OnWaitingForDecryptionKey, |
714 base::Unretained(this))); | 722 base::Unretained(this))); |
715 message_loop_.Run(); | 723 message_loop_.Run(); |
716 EXPECT_EQ(PIPELINE_OK, pipeline_status_); | 724 EXPECT_EQ(PIPELINE_OK, pipeline_status_); |
717 } | 725 return pipeline_status_; |
718 | |
719 void StartHashedPipelineWithMediaSource(MockMediaSource* source) { | |
720 hashing_enabled_ = true; | |
721 StartPipelineWithMediaSource(source); | |
722 } | |
723 | |
724 void StartHashedClocklessPipelineWithMediaSource(MockMediaSource* source) { | |
725 hashing_enabled_ = true; | |
726 clockless_playback_ = true; | |
727 StartPipelineWithMediaSource(source); | |
728 } | 726 } |
729 | 727 |
730 void StartPipelineWithEncryptedMedia(MockMediaSource* source, | 728 void StartPipelineWithEncryptedMedia(MockMediaSource* source, |
731 FakeEncryptedMedia* encrypted_media) { | 729 FakeEncryptedMedia* encrypted_media) { |
732 EXPECT_CALL(*source, InitSegmentReceived(_)).Times(AtLeast(1)); | 730 EXPECT_CALL(*source, InitSegmentReceived(_)).Times(AtLeast(1)); |
733 EXPECT_CALL(*this, OnMetadata(_)) | 731 EXPECT_CALL(*this, OnMetadata(_)) |
734 .Times(AtMost(1)) | 732 .Times(AtMost(1)) |
735 .WillRepeatedly(SaveArg<0>(&metadata_)); | 733 .WillRepeatedly(SaveArg<0>(&metadata_)); |
736 EXPECT_CALL(*this, OnBufferingStateChanged(BUFFERING_HAVE_ENOUGH)) | 734 EXPECT_CALL(*this, OnBufferingStateChanged(BUFFERING_HAVE_ENOUGH)) |
737 .Times(AnyNumber()); | 735 .Times(AnyNumber()); |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
797 return false; | 795 return false; |
798 | 796 |
799 source.EndOfStream(); | 797 source.EndOfStream(); |
800 | 798 |
801 source.Shutdown(); | 799 source.Shutdown(); |
802 Stop(); | 800 Stop(); |
803 return true; | 801 return true; |
804 } | 802 } |
805 }; | 803 }; |
806 | 804 |
| 805 struct PlaybackTestData { |
| 806 const std::string filename; |
| 807 const uint32_t start_time_ms; |
| 808 const uint32_t duration_ms; |
| 809 }; |
| 810 |
| 811 struct MSEPlaybackTestData { |
| 812 const std::string filename; |
| 813 const std::string mimetype; |
| 814 const size_t append_bytes; |
| 815 const uint32_t duration_ms; |
| 816 }; |
| 817 |
| 818 // Tells gtest how to print our PlaybackTestData structure. |
| 819 std::ostream& operator<<(std::ostream& os, const PlaybackTestData& data) { |
| 820 return os << data.filename; |
| 821 } |
| 822 |
| 823 std::ostream& operator<<(std::ostream& os, const MSEPlaybackTestData& data) { |
| 824 return os << data.filename; |
| 825 } |
| 826 |
| 827 class BasicPlaybackTest : public PipelineIntegrationTest, |
| 828 public testing::WithParamInterface<PlaybackTestData> { |
| 829 }; |
| 830 |
| 831 class BasicMSEPlaybackTest |
| 832 : public ::testing::WithParamInterface<MSEPlaybackTestData>, |
| 833 public PipelineIntegrationTest {}; |
| 834 |
| 835 TEST_P(BasicPlaybackTest, PlayToEnd) { |
| 836 PlaybackTestData data = GetParam(); |
| 837 |
| 838 ASSERT_EQ(PIPELINE_OK, Start(data.filename, kClockless)); |
| 839 EXPECT_EQ(data.start_time_ms, demuxer_->GetStartTime().InMilliseconds()); |
| 840 EXPECT_EQ(data.duration_ms, pipeline_->GetMediaDuration().InMilliseconds()); |
| 841 |
| 842 Play(); |
| 843 ASSERT_TRUE(WaitUntilOnEnded()); |
| 844 } |
| 845 |
| 846 TEST_P(BasicMSEPlaybackTest, PlayToEnd) { |
| 847 MSEPlaybackTestData data = GetParam(); |
| 848 |
| 849 MockMediaSource source(data.filename, data.mimetype, data.append_bytes); |
| 850 // TODO -- ADD uint8_t test_type to StartWithMSE and pass clockless flags |
| 851 ASSERT_EQ(PIPELINE_OK, StartPipelineWithMediaSource(&source, kClockless)); |
| 852 source.EndOfStream(); |
| 853 |
| 854 EXPECT_EQ(1u, pipeline_->GetBufferedTimeRanges().size()); |
| 855 EXPECT_EQ(0, pipeline_->GetBufferedTimeRanges().start(0).InMilliseconds()); |
| 856 EXPECT_EQ(data.duration_ms, |
| 857 pipeline_->GetBufferedTimeRanges().end(0).InMilliseconds()); |
| 858 |
| 859 Play(); |
| 860 |
| 861 ASSERT_TRUE(WaitUntilOnEnded()); |
| 862 |
| 863 EXPECT_TRUE(demuxer_->GetTimelineOffset().is_null()); |
| 864 source.Shutdown(); |
| 865 Stop(); |
| 866 } |
| 867 |
| 868 #if defined(USE_PROPRIETARY_CODECS) |
| 869 |
| 870 const PlaybackTestData kADTSTests[] = { |
| 871 {"bear-audio-main-aac.aac", 0, 2724}, |
| 872 {"bear-audio-lc-aac.aac", 0, 2858}, |
| 873 {"bear-audio-implicit-he-aac-v1.aac", 0, 2812}, |
| 874 {"bear-audio-implicit-he-aac-v2.aac", 0, 3047}, |
| 875 }; |
| 876 |
| 877 // TODO(chcunningham): Migrate other basic playback tests to TEST_P. |
| 878 INSTANTIATE_TEST_CASE_P(PropritaryCodecs, |
| 879 BasicPlaybackTest, |
| 880 testing::ValuesIn(kADTSTests)); |
| 881 |
| 882 const MSEPlaybackTestData kMediaSourceADTSTests[] = { |
| 883 {"bear-audio-main-aac.aac", kADTS, kAppendWholeFile, 2773}, |
| 884 {"bear-audio-lc-aac.aac", kADTS, kAppendWholeFile, 2794}, |
| 885 {"bear-audio-implicit-he-aac-v1.aac", kADTS, kAppendWholeFile, 2858}, |
| 886 {"bear-audio-implicit-he-aac-v2.aac", kADTS, kAppendWholeFile, 2901}, |
| 887 }; |
| 888 |
| 889 // TODO(chcunningham): Migrate other basic MSE playback tests to TEST_P. |
| 890 INSTANTIATE_TEST_CASE_P(PropritaryCodecs, |
| 891 BasicMSEPlaybackTest, |
| 892 testing::ValuesIn(kMediaSourceADTSTests)); |
| 893 |
| 894 #endif // defined(USE_PROPRIETARY_CODECS) |
| 895 |
807 TEST_F(PipelineIntegrationTest, BasicPlayback) { | 896 TEST_F(PipelineIntegrationTest, BasicPlayback) { |
808 ASSERT_EQ(PIPELINE_OK, Start("bear-320x240.webm")); | 897 ASSERT_EQ(PIPELINE_OK, Start("bear-320x240.webm")); |
809 | 898 |
810 Play(); | 899 Play(); |
811 | 900 |
812 ASSERT_TRUE(WaitUntilOnEnded()); | 901 ASSERT_TRUE(WaitUntilOnEnded()); |
813 } | 902 } |
814 | 903 |
815 TEST_F(PipelineIntegrationTest, BasicPlaybackOpusOgg) { | 904 TEST_F(PipelineIntegrationTest, BasicPlaybackOpusOgg) { |
816 ASSERT_EQ(PIPELINE_OK, Start("bear-opus.ogg")); | 905 ASSERT_EQ(PIPELINE_OK, Start("bear-opus.ogg")); |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
877 ASSERT_TRUE(Seek(base::TimeDelta::FromMilliseconds(6360))); | 966 ASSERT_TRUE(Seek(base::TimeDelta::FromMilliseconds(6360))); |
878 Play(); | 967 Play(); |
879 ASSERT_TRUE(WaitUntilOnEnded()); | 968 ASSERT_TRUE(WaitUntilOnEnded()); |
880 EXPECT_HASH_EQ(kOpusEndTrimmingHash_3, GetAudioHash()); | 969 EXPECT_HASH_EQ(kOpusEndTrimmingHash_3, GetAudioHash()); |
881 } | 970 } |
882 | 971 |
883 TEST_F(PipelineIntegrationTest, | 972 TEST_F(PipelineIntegrationTest, |
884 MAYBE_CLOCKLESS(BasicPlaybackOpusWebmTrimmingHashed_MediaSource)) { | 973 MAYBE_CLOCKLESS(BasicPlaybackOpusWebmTrimmingHashed_MediaSource)) { |
885 MockMediaSource source("opus-trimming-test.webm", kOpusAudioOnlyWebM, | 974 MockMediaSource source("opus-trimming-test.webm", kOpusAudioOnlyWebM, |
886 kAppendWholeFile); | 975 kAppendWholeFile); |
887 StartHashedClocklessPipelineWithMediaSource(&source); | 976 StartPipelineWithMediaSource(&source, kClockless | kHashed); |
888 source.EndOfStream(); | 977 source.EndOfStream(); |
889 | 978 |
890 Play(); | 979 Play(); |
891 | 980 |
892 ASSERT_TRUE(WaitUntilOnEnded()); | 981 ASSERT_TRUE(WaitUntilOnEnded()); |
893 EXPECT_HASH_EQ(kOpusEndTrimmingHash_1, GetAudioHash()); | 982 EXPECT_HASH_EQ(kOpusEndTrimmingHash_1, GetAudioHash()); |
894 | 983 |
895 // Seek within the pre-skip section, this should not cause a beep. | 984 // Seek within the pre-skip section, this should not cause a beep. |
896 base::TimeDelta seek_time = base::TimeDelta::FromSeconds(1); | 985 base::TimeDelta seek_time = base::TimeDelta::FromSeconds(1); |
897 source.Seek(seek_time); | 986 source.Seek(seek_time); |
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1047 | 1136 |
1048 ASSERT_TRUE(WaitUntilOnEnded()); | 1137 ASSERT_TRUE(WaitUntilOnEnded()); |
1049 source.Shutdown(); | 1138 source.Shutdown(); |
1050 Stop(); | 1139 Stop(); |
1051 } | 1140 } |
1052 | 1141 |
1053 // Flaky. http://crbug.com/304776 | 1142 // Flaky. http://crbug.com/304776 |
1054 TEST_F(PipelineIntegrationTest, DISABLED_MediaSource_Opus_Seeking_WebM) { | 1143 TEST_F(PipelineIntegrationTest, DISABLED_MediaSource_Opus_Seeking_WebM) { |
1055 MockMediaSource source("bear-opus-end-trimming.webm", kOpusAudioOnlyWebM, | 1144 MockMediaSource source("bear-opus-end-trimming.webm", kOpusAudioOnlyWebM, |
1056 kAppendWholeFile); | 1145 kAppendWholeFile); |
1057 StartHashedPipelineWithMediaSource(&source); | 1146 StartPipelineWithMediaSource(&source, kHashed); |
1058 | 1147 |
1059 EXPECT_EQ(1u, pipeline_->GetBufferedTimeRanges().size()); | 1148 EXPECT_EQ(1u, pipeline_->GetBufferedTimeRanges().size()); |
1060 EXPECT_EQ(0, pipeline_->GetBufferedTimeRanges().start(0).InMilliseconds()); | 1149 EXPECT_EQ(0, pipeline_->GetBufferedTimeRanges().start(0).InMilliseconds()); |
1061 EXPECT_EQ(kOpusEndTrimmingWebMFileDurationMs, | 1150 EXPECT_EQ(kOpusEndTrimmingWebMFileDurationMs, |
1062 pipeline_->GetBufferedTimeRanges().end(0).InMilliseconds()); | 1151 pipeline_->GetBufferedTimeRanges().end(0).InMilliseconds()); |
1063 | 1152 |
1064 base::TimeDelta start_seek_time = base::TimeDelta::FromMilliseconds(1000); | 1153 base::TimeDelta start_seek_time = base::TimeDelta::FromMilliseconds(1000); |
1065 base::TimeDelta seek_time = base::TimeDelta::FromMilliseconds(2000); | 1154 base::TimeDelta seek_time = base::TimeDelta::FromMilliseconds(2000); |
1066 | 1155 |
1067 Play(); | 1156 Play(); |
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1262 EXPECT_EQ(0, pipeline_->GetBufferedTimeRanges().start(0).InMilliseconds()); | 1351 EXPECT_EQ(0, pipeline_->GetBufferedTimeRanges().start(0).InMilliseconds()); |
1263 EXPECT_EQ(325, pipeline_->GetBufferedTimeRanges().end(0).InMilliseconds()); | 1352 EXPECT_EQ(325, pipeline_->GetBufferedTimeRanges().end(0).InMilliseconds()); |
1264 | 1353 |
1265 Play(); | 1354 Play(); |
1266 | 1355 |
1267 EXPECT_TRUE(WaitUntilOnEnded()); | 1356 EXPECT_TRUE(WaitUntilOnEnded()); |
1268 } | 1357 } |
1269 | 1358 |
1270 TEST_F(PipelineIntegrationTest, MediaSource_ADTS_TimestampOffset) { | 1359 TEST_F(PipelineIntegrationTest, MediaSource_ADTS_TimestampOffset) { |
1271 MockMediaSource source("sfx.adts", kADTS, kAppendWholeFile); | 1360 MockMediaSource source("sfx.adts", kADTS, kAppendWholeFile); |
1272 StartHashedPipelineWithMediaSource(&source); | 1361 StartPipelineWithMediaSource(&source, kHashed); |
1273 EXPECT_EQ(325, source.last_timestamp_offset().InMilliseconds()); | 1362 EXPECT_EQ(325, source.last_timestamp_offset().InMilliseconds()); |
1274 | 1363 |
1275 // Trim off multiple frames off the beginning of the segment which will cause | 1364 // Trim off multiple frames off the beginning of the segment which will cause |
1276 // the first decoded frame to be incorrect if preroll isn't implemented. | 1365 // the first decoded frame to be incorrect if preroll isn't implemented. |
1277 const base::TimeDelta adts_preroll_duration = | 1366 const base::TimeDelta adts_preroll_duration = |
1278 base::TimeDelta::FromSecondsD(2.5 * 1024 / 44100); | 1367 base::TimeDelta::FromSecondsD(2.5 * 1024 / 44100); |
1279 const base::TimeDelta append_time = | 1368 const base::TimeDelta append_time = |
1280 source.last_timestamp_offset() - adts_preroll_duration; | 1369 source.last_timestamp_offset() - adts_preroll_duration; |
1281 | 1370 |
1282 scoped_refptr<DecoderBuffer> second_file = ReadTestDataFile("sfx.adts"); | 1371 scoped_refptr<DecoderBuffer> second_file = ReadTestDataFile("sfx.adts"); |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1377 | 1466 |
1378 INSTANTIATE_TEST_CASE_P( | 1467 INSTANTIATE_TEST_CASE_P( |
1379 VBRSeeks_NoTOC, | 1468 VBRSeeks_NoTOC, |
1380 Mp3FastSeekIntegrationTest, | 1469 Mp3FastSeekIntegrationTest, |
1381 ::testing::Values(Mp3FastSeekParams("bear-audio-10s-VBR-no-TOC.mp3", | 1470 ::testing::Values(Mp3FastSeekParams("bear-audio-10s-VBR-no-TOC.mp3", |
1382 "-0.22,0.80,1.19,0.73,-0.31,-1.12,"))); | 1471 "-0.22,0.80,1.19,0.73,-0.31,-1.12,"))); |
1383 #endif // !defined(DISABLE_CLOCKLESS_TESTS) | 1472 #endif // !defined(DISABLE_CLOCKLESS_TESTS) |
1384 | 1473 |
1385 TEST_F(PipelineIntegrationTest, MediaSource_MP3) { | 1474 TEST_F(PipelineIntegrationTest, MediaSource_MP3) { |
1386 MockMediaSource source("sfx.mp3", kMP3, kAppendWholeFile); | 1475 MockMediaSource source("sfx.mp3", kMP3, kAppendWholeFile); |
1387 StartHashedPipelineWithMediaSource(&source); | 1476 StartPipelineWithMediaSource(&source, kHashed); |
1388 source.EndOfStream(); | 1477 source.EndOfStream(); |
1389 | 1478 |
1390 EXPECT_EQ(1u, pipeline_->GetBufferedTimeRanges().size()); | 1479 EXPECT_EQ(1u, pipeline_->GetBufferedTimeRanges().size()); |
1391 EXPECT_EQ(0, pipeline_->GetBufferedTimeRanges().start(0).InMilliseconds()); | 1480 EXPECT_EQ(0, pipeline_->GetBufferedTimeRanges().start(0).InMilliseconds()); |
1392 EXPECT_EQ(313, pipeline_->GetBufferedTimeRanges().end(0).InMilliseconds()); | 1481 EXPECT_EQ(313, pipeline_->GetBufferedTimeRanges().end(0).InMilliseconds()); |
1393 | 1482 |
1394 Play(); | 1483 Play(); |
1395 | 1484 |
1396 EXPECT_TRUE(WaitUntilOnEnded()); | 1485 EXPECT_TRUE(WaitUntilOnEnded()); |
1397 | 1486 |
(...skipping 642 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2040 | 2129 |
2041 TEST_F(PipelineIntegrationTest, BasicPlaybackPositiveStartTime) { | 2130 TEST_F(PipelineIntegrationTest, BasicPlaybackPositiveStartTime) { |
2042 ASSERT_EQ(PIPELINE_OK, Start("nonzero-start-time.webm")); | 2131 ASSERT_EQ(PIPELINE_OK, Start("nonzero-start-time.webm")); |
2043 Play(); | 2132 Play(); |
2044 ASSERT_TRUE(WaitUntilOnEnded()); | 2133 ASSERT_TRUE(WaitUntilOnEnded()); |
2045 ASSERT_EQ(base::TimeDelta::FromMicroseconds(396000), | 2134 ASSERT_EQ(base::TimeDelta::FromMicroseconds(396000), |
2046 demuxer_->GetStartTime()); | 2135 demuxer_->GetStartTime()); |
2047 } | 2136 } |
2048 | 2137 |
2049 } // namespace media | 2138 } // namespace media |
OLD | NEW |