| 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 469 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 480 kSourceId, | 480 kSourceId, |
| 481 base::TimeDelta(), kInfiniteDuration(), &last_timestamp_offset_); | 481 base::TimeDelta(), kInfiniteDuration(), &last_timestamp_offset_); |
| 482 | 482 |
| 483 DCHECK_GE(new_position, 0); | 483 DCHECK_GE(new_position, 0); |
| 484 DCHECK_LT(new_position, file_data_->data_size()); | 484 DCHECK_LT(new_position, file_data_->data_size()); |
| 485 current_position_ = new_position; | 485 current_position_ = new_position; |
| 486 | 486 |
| 487 AppendData(seek_append_size); | 487 AppendData(seek_append_size); |
| 488 } | 488 } |
| 489 | 489 |
| 490 void Seek(base::TimeDelta seek_time) { |
| 491 chunk_demuxer_->StartWaitingForSeek(seek_time); |
| 492 chunk_demuxer_->Abort( |
| 493 kSourceId, |
| 494 base::TimeDelta(), kInfiniteDuration(), &last_timestamp_offset_); |
| 495 } |
| 496 |
| 490 void AppendData(int size) { | 497 void AppendData(int size) { |
| 491 DCHECK(chunk_demuxer_); | 498 DCHECK(chunk_demuxer_); |
| 492 DCHECK_LT(current_position_, file_data_->data_size()); | 499 DCHECK_LT(current_position_, file_data_->data_size()); |
| 493 DCHECK_LE(current_position_ + size, file_data_->data_size()); | 500 DCHECK_LE(current_position_ + size, file_data_->data_size()); |
| 494 | 501 |
| 495 chunk_demuxer_->AppendData( | 502 chunk_demuxer_->AppendData( |
| 496 kSourceId, file_data_->data() + current_position_, size, | 503 kSourceId, file_data_->data() + current_position_, size, |
| 497 base::TimeDelta(), kInfiniteDuration(), &last_timestamp_offset_, | 504 base::TimeDelta(), kInfiniteDuration(), &last_timestamp_offset_, |
| 498 base::Bind(&MockMediaSource::InitSegmentReceived, | 505 base::Bind(&MockMediaSource::InitSegmentReceived, |
| 499 base::Unretained(this))); | 506 base::Unretained(this))); |
| (...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 671 base::Unretained(this))); | 678 base::Unretained(this))); |
| 672 message_loop_.Run(); | 679 message_loop_.Run(); |
| 673 EXPECT_EQ(PIPELINE_OK, pipeline_status_); | 680 EXPECT_EQ(PIPELINE_OK, pipeline_status_); |
| 674 } | 681 } |
| 675 | 682 |
| 676 void StartHashedPipelineWithMediaSource(MockMediaSource* source) { | 683 void StartHashedPipelineWithMediaSource(MockMediaSource* source) { |
| 677 hashing_enabled_ = true; | 684 hashing_enabled_ = true; |
| 678 StartPipelineWithMediaSource(source); | 685 StartPipelineWithMediaSource(source); |
| 679 } | 686 } |
| 680 | 687 |
| 688 void StartHashedClocklessPipelineWithMediaSource(MockMediaSource* source) { |
| 689 hashing_enabled_ = true; |
| 690 clockless_playback_ = true; |
| 691 StartPipelineWithMediaSource(source); |
| 692 } |
| 693 |
| 681 void StartPipelineWithEncryptedMedia( | 694 void StartPipelineWithEncryptedMedia( |
| 682 MockMediaSource* source, | 695 MockMediaSource* source, |
| 683 FakeEncryptedMedia* encrypted_media) { | 696 FakeEncryptedMedia* encrypted_media) { |
| 684 EXPECT_CALL(*source, InitSegmentReceived()).Times(AtLeast(1)); | 697 EXPECT_CALL(*source, InitSegmentReceived()).Times(AtLeast(1)); |
| 685 EXPECT_CALL(*this, OnMetadata(_)) | 698 EXPECT_CALL(*this, OnMetadata(_)) |
| 686 .Times(AtMost(1)) | 699 .Times(AtMost(1)) |
| 687 .WillRepeatedly(SaveArg<0>(&metadata_)); | 700 .WillRepeatedly(SaveArg<0>(&metadata_)); |
| 688 EXPECT_CALL(*this, OnBufferingStateChanged(BUFFERING_HAVE_ENOUGH)) | 701 EXPECT_CALL(*this, OnBufferingStateChanged(BUFFERING_HAVE_ENOUGH)) |
| 689 .Times(AnyNumber()); | 702 .Times(AnyNumber()); |
| 690 EXPECT_CALL(*this, OnBufferingStateChanged(BUFFERING_HAVE_NOTHING)) | 703 EXPECT_CALL(*this, OnBufferingStateChanged(BUFFERING_HAVE_NOTHING)) |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 777 | 790 |
| 778 Play(); | 791 Play(); |
| 779 | 792 |
| 780 ASSERT_TRUE(WaitUntilOnEnded()); | 793 ASSERT_TRUE(WaitUntilOnEnded()); |
| 781 | 794 |
| 782 EXPECT_HASH_EQ("f0be120a90a811506777c99a2cdf7cc1", GetVideoHash()); | 795 EXPECT_HASH_EQ("f0be120a90a811506777c99a2cdf7cc1", GetVideoHash()); |
| 783 EXPECT_HASH_EQ("-3.59,-2.06,-0.43,2.15,0.77,-0.95,", GetAudioHash()); | 796 EXPECT_HASH_EQ("-3.59,-2.06,-0.43,2.15,0.77,-0.95,", GetAudioHash()); |
| 784 EXPECT_TRUE(demuxer_->GetTimelineOffset().is_null()); | 797 EXPECT_TRUE(demuxer_->GetTimelineOffset().is_null()); |
| 785 } | 798 } |
| 786 | 799 |
| 800 TEST_F(PipelineIntegrationTest, BasicPlaybackOpusOggTrimmingHashed) { |
| 801 ASSERT_EQ(PIPELINE_OK, |
| 802 Start("opus-trimming-test.webm", kHashed | kClockless)); |
| 803 |
| 804 Play(); |
| 805 |
| 806 ASSERT_TRUE(WaitUntilOnEnded()); |
| 807 EXPECT_HASH_EQ("-4.56,-5.65,-6.51,-6.29,-4.36,-3.59,", GetAudioHash()); |
| 808 |
| 809 // Seek within the pre-skip section, this should not cause a beep. |
| 810 ASSERT_TRUE(Seek(base::TimeDelta::FromSeconds(1))); |
| 811 Play(); |
| 812 ASSERT_TRUE(WaitUntilOnEnded()); |
| 813 EXPECT_HASH_EQ("-13.37,-12.74,-10.02,-8.76,-9.25,-11.33,", GetAudioHash()); |
| 814 |
| 815 // Seek somewhere outside of the pre-skip / end-trim section, demxuer should |
| 816 // correctly preroll enough to accurately decode this segment. |
| 817 ASSERT_TRUE(Seek(pipeline_->GetMediaDuration() / 2)); |
| 818 Play(); |
| 819 ASSERT_TRUE(WaitUntilOnEnded()); |
| 820 EXPECT_HASH_EQ("-14.28,-14.28,-13.46,-12.81,-12.09,-12.82,", GetAudioHash()); |
| 821 } |
| 822 |
| 823 TEST_F(PipelineIntegrationTest, BasicPlaybackOpusWebmTrimmingHashed) { |
| 824 ASSERT_EQ(PIPELINE_OK, |
| 825 Start("opus-trimming-test.webm", kHashed | kClockless)); |
| 826 |
| 827 Play(); |
| 828 |
| 829 ASSERT_TRUE(WaitUntilOnEnded()); |
| 830 EXPECT_HASH_EQ("-4.56,-5.65,-6.51,-6.29,-4.36,-3.59,", GetAudioHash()); |
| 831 |
| 832 // Seek within the pre-skip section, this should not cause a beep. |
| 833 ASSERT_TRUE(Seek(base::TimeDelta::FromSeconds(1))); |
| 834 Play(); |
| 835 ASSERT_TRUE(WaitUntilOnEnded()); |
| 836 EXPECT_HASH_EQ("-13.37,-12.74,-10.02,-8.76,-9.25,-11.33,", GetAudioHash()); |
| 837 |
| 838 // Seek somewhere outside of the pre-skip / end-trim section, demxuer should |
| 839 // correctly preroll enough to accurately decode this segment. |
| 840 ASSERT_TRUE(Seek(pipeline_->GetMediaDuration() / 2)); |
| 841 Play(); |
| 842 ASSERT_TRUE(WaitUntilOnEnded()); |
| 843 EXPECT_HASH_EQ("-14.28,-14.28,-13.46,-12.81,-12.09,-12.82,", GetAudioHash()); |
| 844 } |
| 845 |
| 846 TEST_F(PipelineIntegrationTest, |
| 847 BasicPlaybackOpusWebmTrimmingHashed_MediaSource) { |
| 848 MockMediaSource source("opus-trimming-test.webm", kOpusAudioOnlyWebM, |
| 849 kAppendWholeFile); |
| 850 StartHashedClocklessPipelineWithMediaSource(&source); |
| 851 source.EndOfStream(); |
| 852 |
| 853 Play(); |
| 854 |
| 855 ASSERT_TRUE(WaitUntilOnEnded()); |
| 856 EXPECT_HASH_EQ("-4.56,-5.65,-6.51,-6.29,-4.36,-3.59,", GetAudioHash()); |
| 857 |
| 858 // TODO(chcunningham): MSE can't pass the following tests currently because it |
| 859 // does not provide enough preroll to the opus decoder for accurate decode. |
| 860 // See http://crbug.com/509894 for more information. |
| 861 #if 0 |
| 862 // Seek within the pre-skip section, this should not cause a beep. |
| 863 source.Seek(base::TimeDelta::FromSeconds(1)); |
| 864 ASSERT_TRUE(Seek(base::TimeDelta::FromSeconds(1))); |
| 865 Play(); |
| 866 ASSERT_TRUE(WaitUntilOnEnded()); |
| 867 EXPECT_HASH_EQ("-13.37,-12.74,-10.02,-8.76,-9.25,-11.33,", GetAudioHash()); |
| 868 |
| 869 // Seek somewhere outside of the pre-skip / end-trim section, demxuer should |
| 870 // correctly preroll enough to accurately decode this segment. |
| 871 source.Seek(pipeline_->GetMediaDuration() / 2); |
| 872 ASSERT_TRUE(Seek(pipeline_->GetMediaDuration() / 2)); |
| 873 Play(); |
| 874 ASSERT_TRUE(WaitUntilOnEnded()); |
| 875 EXPECT_HASH_EQ("-14.28,-14.28,-13.46,-12.81,-12.09,-12.82,", GetAudioHash()); |
| 876 #endif |
| 877 } |
| 878 |
| 787 TEST_F(PipelineIntegrationTest, BasicPlaybackLive) { | 879 TEST_F(PipelineIntegrationTest, BasicPlaybackLive) { |
| 788 ASSERT_EQ(PIPELINE_OK, Start("bear-320x240-live.webm", kHashed)); | 880 ASSERT_EQ(PIPELINE_OK, Start("bear-320x240-live.webm", kHashed)); |
| 789 | 881 |
| 790 Play(); | 882 Play(); |
| 791 | 883 |
| 792 ASSERT_TRUE(WaitUntilOnEnded()); | 884 ASSERT_TRUE(WaitUntilOnEnded()); |
| 793 | 885 |
| 794 EXPECT_HASH_EQ("f0be120a90a811506777c99a2cdf7cc1", GetVideoHash()); | 886 EXPECT_HASH_EQ("f0be120a90a811506777c99a2cdf7cc1", GetVideoHash()); |
| 795 EXPECT_HASH_EQ("-3.59,-2.06,-0.43,2.15,0.77,-0.95,", GetAudioHash()); | 887 EXPECT_HASH_EQ("-3.59,-2.06,-0.43,2.15,0.77,-0.95,", GetAudioHash()); |
| 796 | 888 |
| (...skipping 928 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1725 | 1817 |
| 1726 TEST_F(PipelineIntegrationTest, BasicPlaybackPositiveStartTime) { | 1818 TEST_F(PipelineIntegrationTest, BasicPlaybackPositiveStartTime) { |
| 1727 ASSERT_EQ(PIPELINE_OK, Start("nonzero-start-time.webm")); | 1819 ASSERT_EQ(PIPELINE_OK, Start("nonzero-start-time.webm")); |
| 1728 Play(); | 1820 Play(); |
| 1729 ASSERT_TRUE(WaitUntilOnEnded()); | 1821 ASSERT_TRUE(WaitUntilOnEnded()); |
| 1730 ASSERT_EQ(base::TimeDelta::FromMicroseconds(396000), | 1822 ASSERT_EQ(base::TimeDelta::FromMicroseconds(396000), |
| 1731 demuxer_->GetStartTime()); | 1823 demuxer_->GetStartTime()); |
| 1732 } | 1824 } |
| 1733 | 1825 |
| 1734 } // namespace media | 1826 } // namespace media |
| OLD | NEW |