| 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 "base/bind.h" | 5 #include "base/bind.h" |
| 6 #include "base/command_line.h" | 6 #include "base/command_line.h" |
| 7 #include "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
| 8 #include "base/stl_util.h" | 8 #include "base/stl_util.h" |
| 9 #include "base/strings/string_split.h" | 9 #include "base/strings/string_split.h" |
| 10 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 98 const int kAppendTimeMs = kAppendTimeSec * 1000; | 98 const int kAppendTimeMs = kAppendTimeSec * 1000; |
| 99 const int k320WebMFileDurationMs = 2736; | 99 const int k320WebMFileDurationMs = 2736; |
| 100 #if !defined(DISABLE_EME_TESTS) | 100 #if !defined(DISABLE_EME_TESTS) |
| 101 const int k320EncWebMFileDurationMs = 2737; | 101 const int k320EncWebMFileDurationMs = 2737; |
| 102 #endif // !defined(DISABLE_EME_TESTS) | 102 #endif // !defined(DISABLE_EME_TESTS) |
| 103 const int k640WebMFileDurationMs = 2749; | 103 const int k640WebMFileDurationMs = 2749; |
| 104 const int kOpusEndTrimmingWebMFileDurationMs = 2741; | 104 const int kOpusEndTrimmingWebMFileDurationMs = 2741; |
| 105 const int kVP9WebMFileDurationMs = 2736; | 105 const int kVP9WebMFileDurationMs = 2736; |
| 106 const int kVP8AWebMFileDurationMs = 2734; | 106 const int kVP8AWebMFileDurationMs = 2734; |
| 107 | 107 |
| 108 #if !defined(MOJO_RENDERER) |
| 109 // Hash for a full playthrough of "opus-trimming-test.(webm|ogg)". |
| 110 static const char kOpusEndTrimmingHash_1[] = |
| 111 "-4.56,-5.65,-6.51,-6.29,-4.36,-3.59,"; |
| 112 // The above hash, plus an additional playthrough starting from T=1s. |
| 113 static const char kOpusEndTrimmingHash_2[] = |
| 114 "-11.89,-11.09,-8.25,-7.11,-7.84,-9.97,"; |
| 115 // The above hash, plus an additional playthrough starting from T=6.36s. |
| 116 static const char kOpusEndTrimmingHash_3[] = |
| 117 "-13.28,-14.35,-13.67,-11.68,-10.18,-10.46,"; |
| 118 #endif |
| 119 |
| 108 #if defined(USE_PROPRIETARY_CODECS) | 120 #if defined(USE_PROPRIETARY_CODECS) |
| 109 #if !defined(DISABLE_EME_TESTS) | 121 #if !defined(DISABLE_EME_TESTS) |
| 110 const int k640IsoFileDurationMs = 2737; | 122 const int k640IsoFileDurationMs = 2737; |
| 111 const int k640IsoCencFileDurationMs = 2736; | 123 const int k640IsoCencFileDurationMs = 2736; |
| 112 #endif // !defined(DISABLE_EME_TESTS) | 124 #endif // !defined(DISABLE_EME_TESTS) |
| 113 const int k1280IsoFileDurationMs = 2736; | 125 const int k1280IsoFileDurationMs = 2736; |
| 114 const int k1280IsoAVC3FileDurationMs = 2736; | 126 const int k1280IsoAVC3FileDurationMs = 2736; |
| 115 #endif // defined(USE_PROPRIETARY_CODECS) | 127 #endif // defined(USE_PROPRIETARY_CODECS) |
| 116 | 128 |
| 117 // Return a timeline offset for bear-320x240-live.webm. | 129 // Return a timeline offset for bear-320x240-live.webm. |
| (...skipping 362 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 480 kSourceId, | 492 kSourceId, |
| 481 base::TimeDelta(), kInfiniteDuration(), &last_timestamp_offset_); | 493 base::TimeDelta(), kInfiniteDuration(), &last_timestamp_offset_); |
| 482 | 494 |
| 483 DCHECK_GE(new_position, 0); | 495 DCHECK_GE(new_position, 0); |
| 484 DCHECK_LT(new_position, file_data_->data_size()); | 496 DCHECK_LT(new_position, file_data_->data_size()); |
| 485 current_position_ = new_position; | 497 current_position_ = new_position; |
| 486 | 498 |
| 487 AppendData(seek_append_size); | 499 AppendData(seek_append_size); |
| 488 } | 500 } |
| 489 | 501 |
| 502 void Seek(base::TimeDelta seek_time) { |
| 503 chunk_demuxer_->StartWaitingForSeek(seek_time); |
| 504 } |
| 505 |
| 490 void AppendData(int size) { | 506 void AppendData(int size) { |
| 491 DCHECK(chunk_demuxer_); | 507 DCHECK(chunk_demuxer_); |
| 492 DCHECK_LT(current_position_, file_data_->data_size()); | 508 DCHECK_LT(current_position_, file_data_->data_size()); |
| 493 DCHECK_LE(current_position_ + size, file_data_->data_size()); | 509 DCHECK_LE(current_position_ + size, file_data_->data_size()); |
| 494 | 510 |
| 495 chunk_demuxer_->AppendData( | 511 chunk_demuxer_->AppendData( |
| 496 kSourceId, file_data_->data() + current_position_, size, | 512 kSourceId, file_data_->data() + current_position_, size, |
| 497 base::TimeDelta(), kInfiniteDuration(), &last_timestamp_offset_, | 513 base::TimeDelta(), kInfiniteDuration(), &last_timestamp_offset_, |
| 498 base::Bind(&MockMediaSource::InitSegmentReceived, | 514 base::Bind(&MockMediaSource::InitSegmentReceived, |
| 499 base::Unretained(this))); | 515 base::Unretained(this))); |
| (...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 670 base::Unretained(this))); | 686 base::Unretained(this))); |
| 671 message_loop_.Run(); | 687 message_loop_.Run(); |
| 672 EXPECT_EQ(PIPELINE_OK, pipeline_status_); | 688 EXPECT_EQ(PIPELINE_OK, pipeline_status_); |
| 673 } | 689 } |
| 674 | 690 |
| 675 void StartHashedPipelineWithMediaSource(MockMediaSource* source) { | 691 void StartHashedPipelineWithMediaSource(MockMediaSource* source) { |
| 676 hashing_enabled_ = true; | 692 hashing_enabled_ = true; |
| 677 StartPipelineWithMediaSource(source); | 693 StartPipelineWithMediaSource(source); |
| 678 } | 694 } |
| 679 | 695 |
| 696 void StartHashedClocklessPipelineWithMediaSource(MockMediaSource* source) { |
| 697 hashing_enabled_ = true; |
| 698 clockless_playback_ = true; |
| 699 StartPipelineWithMediaSource(source); |
| 700 } |
| 701 |
| 680 void StartPipelineWithEncryptedMedia( | 702 void StartPipelineWithEncryptedMedia( |
| 681 MockMediaSource* source, | 703 MockMediaSource* source, |
| 682 FakeEncryptedMedia* encrypted_media) { | 704 FakeEncryptedMedia* encrypted_media) { |
| 683 EXPECT_CALL(*source, InitSegmentReceived()).Times(AtLeast(1)); | 705 EXPECT_CALL(*source, InitSegmentReceived()).Times(AtLeast(1)); |
| 684 EXPECT_CALL(*this, OnMetadata(_)) | 706 EXPECT_CALL(*this, OnMetadata(_)) |
| 685 .Times(AtMost(1)) | 707 .Times(AtMost(1)) |
| 686 .WillRepeatedly(SaveArg<0>(&metadata_)); | 708 .WillRepeatedly(SaveArg<0>(&metadata_)); |
| 687 EXPECT_CALL(*this, OnBufferingStateChanged(BUFFERING_HAVE_ENOUGH)) | 709 EXPECT_CALL(*this, OnBufferingStateChanged(BUFFERING_HAVE_ENOUGH)) |
| 688 .Times(AnyNumber()); | 710 .Times(AnyNumber()); |
| 689 EXPECT_CALL(*this, OnBufferingStateChanged(BUFFERING_HAVE_NOTHING)) | 711 EXPECT_CALL(*this, OnBufferingStateChanged(BUFFERING_HAVE_NOTHING)) |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 776 | 798 |
| 777 Play(); | 799 Play(); |
| 778 | 800 |
| 779 ASSERT_TRUE(WaitUntilOnEnded()); | 801 ASSERT_TRUE(WaitUntilOnEnded()); |
| 780 | 802 |
| 781 EXPECT_HASH_EQ("f0be120a90a811506777c99a2cdf7cc1", GetVideoHash()); | 803 EXPECT_HASH_EQ("f0be120a90a811506777c99a2cdf7cc1", GetVideoHash()); |
| 782 EXPECT_HASH_EQ("-3.59,-2.06,-0.43,2.15,0.77,-0.95,", GetAudioHash()); | 804 EXPECT_HASH_EQ("-3.59,-2.06,-0.43,2.15,0.77,-0.95,", GetAudioHash()); |
| 783 EXPECT_TRUE(demuxer_->GetTimelineOffset().is_null()); | 805 EXPECT_TRUE(demuxer_->GetTimelineOffset().is_null()); |
| 784 } | 806 } |
| 785 | 807 |
| 808 TEST_F(PipelineIntegrationTest, BasicPlaybackOpusOggTrimmingHashed) { |
| 809 ASSERT_EQ(PIPELINE_OK, |
| 810 Start("opus-trimming-test.webm", kHashed | kClockless)); |
| 811 |
| 812 Play(); |
| 813 |
| 814 ASSERT_TRUE(WaitUntilOnEnded()); |
| 815 EXPECT_HASH_EQ(kOpusEndTrimmingHash_1, GetAudioHash()); |
| 816 |
| 817 // Seek within the pre-skip section, this should not cause a beep. |
| 818 ASSERT_TRUE(Seek(base::TimeDelta::FromSeconds(1))); |
| 819 Play(); |
| 820 ASSERT_TRUE(WaitUntilOnEnded()); |
| 821 EXPECT_HASH_EQ(kOpusEndTrimmingHash_2, GetAudioHash()); |
| 822 |
| 823 // Seek somewhere outside of the pre-skip / end-trim section, demxuer should |
| 824 // correctly preroll enough to accurately decode this segment. |
| 825 ASSERT_TRUE(Seek(base::TimeDelta::FromMilliseconds(6360))); |
| 826 Play(); |
| 827 ASSERT_TRUE(WaitUntilOnEnded()); |
| 828 EXPECT_HASH_EQ(kOpusEndTrimmingHash_3, GetAudioHash()); |
| 829 } |
| 830 |
| 831 TEST_F(PipelineIntegrationTest, BasicPlaybackOpusWebmTrimmingHashed) { |
| 832 ASSERT_EQ(PIPELINE_OK, |
| 833 Start("opus-trimming-test.webm", kHashed | kClockless)); |
| 834 |
| 835 Play(); |
| 836 |
| 837 ASSERT_TRUE(WaitUntilOnEnded()); |
| 838 EXPECT_HASH_EQ(kOpusEndTrimmingHash_1, GetAudioHash()); |
| 839 |
| 840 // Seek within the pre-skip section, this should not cause a beep. |
| 841 ASSERT_TRUE(Seek(base::TimeDelta::FromSeconds(1))); |
| 842 Play(); |
| 843 ASSERT_TRUE(WaitUntilOnEnded()); |
| 844 EXPECT_HASH_EQ(kOpusEndTrimmingHash_2, GetAudioHash()); |
| 845 |
| 846 // Seek somewhere outside of the pre-skip / end-trim section, demxuer should |
| 847 // correctly preroll enough to accurately decode this segment. |
| 848 ASSERT_TRUE(Seek(base::TimeDelta::FromMilliseconds(6360))); |
| 849 Play(); |
| 850 ASSERT_TRUE(WaitUntilOnEnded()); |
| 851 EXPECT_HASH_EQ(kOpusEndTrimmingHash_3, GetAudioHash()); |
| 852 } |
| 853 |
| 854 TEST_F(PipelineIntegrationTest, |
| 855 BasicPlaybackOpusWebmTrimmingHashed_MediaSource) { |
| 856 MockMediaSource source("opus-trimming-test.webm", kOpusAudioOnlyWebM, |
| 857 kAppendWholeFile); |
| 858 StartHashedClocklessPipelineWithMediaSource(&source); |
| 859 source.EndOfStream(); |
| 860 |
| 861 Play(); |
| 862 |
| 863 ASSERT_TRUE(WaitUntilOnEnded()); |
| 864 EXPECT_HASH_EQ(kOpusEndTrimmingHash_1, GetAudioHash()); |
| 865 |
| 866 // Seek within the pre-skip section, this should not cause a beep. |
| 867 base::TimeDelta seek_time = base::TimeDelta::FromSeconds(1); |
| 868 source.Seek(seek_time); |
| 869 ASSERT_TRUE(Seek(seek_time)); |
| 870 Play(); |
| 871 ASSERT_TRUE(WaitUntilOnEnded()); |
| 872 EXPECT_HASH_EQ(kOpusEndTrimmingHash_2, GetAudioHash()); |
| 873 |
| 874 // Seek somewhere outside of the pre-skip / end-trim section, demuxer should |
| 875 // correctly preroll enough to accurately decode this segment. |
| 876 seek_time = base::TimeDelta::FromMilliseconds(6360); |
| 877 source.Seek(seek_time); |
| 878 ASSERT_TRUE(Seek(seek_time)); |
| 879 Play(); |
| 880 ASSERT_TRUE(WaitUntilOnEnded()); |
| 881 EXPECT_HASH_EQ(kOpusEndTrimmingHash_3, GetAudioHash()); |
| 882 } |
| 883 |
| 884 // TODO(dalecurtis): Add an opus test file which FFmpeg and ChunkDemuxer will |
| 885 // both seek the same in and shows the difference of preroll. |
| 886 // http://crbug.com/509894 |
| 887 |
| 786 TEST_F(PipelineIntegrationTest, BasicPlaybackLive) { | 888 TEST_F(PipelineIntegrationTest, BasicPlaybackLive) { |
| 787 ASSERT_EQ(PIPELINE_OK, Start("bear-320x240-live.webm", kHashed)); | 889 ASSERT_EQ(PIPELINE_OK, Start("bear-320x240-live.webm", kHashed)); |
| 788 | 890 |
| 789 Play(); | 891 Play(); |
| 790 | 892 |
| 791 ASSERT_TRUE(WaitUntilOnEnded()); | 893 ASSERT_TRUE(WaitUntilOnEnded()); |
| 792 | 894 |
| 793 EXPECT_HASH_EQ("f0be120a90a811506777c99a2cdf7cc1", GetVideoHash()); | 895 EXPECT_HASH_EQ("f0be120a90a811506777c99a2cdf7cc1", GetVideoHash()); |
| 794 EXPECT_HASH_EQ("-3.59,-2.06,-0.43,2.15,0.77,-0.95,", GetAudioHash()); | 896 EXPECT_HASH_EQ("-3.59,-2.06,-0.43,2.15,0.77,-0.95,", GetAudioHash()); |
| 795 | 897 |
| (...skipping 928 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1724 | 1826 |
| 1725 TEST_F(PipelineIntegrationTest, BasicPlaybackPositiveStartTime) { | 1827 TEST_F(PipelineIntegrationTest, BasicPlaybackPositiveStartTime) { |
| 1726 ASSERT_EQ(PIPELINE_OK, Start("nonzero-start-time.webm")); | 1828 ASSERT_EQ(PIPELINE_OK, Start("nonzero-start-time.webm")); |
| 1727 Play(); | 1829 Play(); |
| 1728 ASSERT_TRUE(WaitUntilOnEnded()); | 1830 ASSERT_TRUE(WaitUntilOnEnded()); |
| 1729 ASSERT_EQ(base::TimeDelta::FromMicroseconds(396000), | 1831 ASSERT_EQ(base::TimeDelta::FromMicroseconds(396000), |
| 1730 demuxer_->GetStartTime()); | 1832 demuxer_->GetStartTime()); |
| 1731 } | 1833 } |
| 1732 | 1834 |
| 1733 } // namespace media | 1835 } // namespace media |
| OLD | NEW |