| 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 | 7 |
| 8 #include <memory> | 8 #include <memory> |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| 11 #include "base/bind.h" | 11 #include "base/bind.h" |
| 12 #include "base/command_line.h" | 12 #include "base/command_line.h" |
| 13 #include "base/location.h" | |
| 14 #include "base/macros.h" | 13 #include "base/macros.h" |
| 15 #include "base/memory/ptr_util.h" | 14 #include "base/memory/ptr_util.h" |
| 16 #include "base/memory/ref_counted.h" | 15 #include "base/memory/ref_counted.h" |
| 17 #include "base/run_loop.h" | 16 #include "base/run_loop.h" |
| 18 #include "base/single_thread_task_runner.h" | |
| 19 #include "base/strings/string_split.h" | 17 #include "base/strings/string_split.h" |
| 20 #include "base/strings/string_util.h" | 18 #include "base/strings/string_util.h" |
| 21 #include "base/threading/thread_task_runner_handle.h" | 19 #include "base/threading/thread_task_runner_handle.h" |
| 22 #include "build/build_config.h" | 20 #include "build/build_config.h" |
| 23 #include "media/base/cdm_callback_promise.h" | 21 #include "media/base/cdm_callback_promise.h" |
| 24 #include "media/base/cdm_context.h" | 22 #include "media/base/cdm_context.h" |
| 25 #include "media/base/cdm_key_information.h" | 23 #include "media/base/cdm_key_information.h" |
| 26 #include "media/base/decoder_buffer.h" | 24 #include "media/base/decoder_buffer.h" |
| 27 #include "media/base/media.h" | 25 #include "media/base/media.h" |
| 28 #include "media/base/media_keys.h" | 26 #include "media/base/media_keys.h" |
| (...skipping 916 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 945 EXPECT_HASH_EQ("-3.59,-2.06,-0.43,2.15,0.77,-0.95,", GetAudioHash()); | 943 EXPECT_HASH_EQ("-3.59,-2.06,-0.43,2.15,0.77,-0.95,", GetAudioHash()); |
| 946 EXPECT_TRUE(demuxer_->GetTimelineOffset().is_null()); | 944 EXPECT_TRUE(demuxer_->GetTimelineOffset().is_null()); |
| 947 } | 945 } |
| 948 | 946 |
| 949 TEST_F(PipelineIntegrationTest, PlaybackWithAudioTrackDisabledThenEnabled) { | 947 TEST_F(PipelineIntegrationTest, PlaybackWithAudioTrackDisabledThenEnabled) { |
| 950 ASSERT_EQ(PIPELINE_OK, Start("bear-320x240.webm", kHashed)); | 948 ASSERT_EQ(PIPELINE_OK, Start("bear-320x240.webm", kHashed)); |
| 951 | 949 |
| 952 // Disable audio. | 950 // Disable audio. |
| 953 std::vector<MediaTrack::Id> empty; | 951 std::vector<MediaTrack::Id> empty; |
| 954 pipeline_->OnEnabledAudioTracksChanged(empty); | 952 pipeline_->OnEnabledAudioTracksChanged(empty); |
| 955 message_loop_.RunUntilIdle(); | 953 base::RunLoop().RunUntilIdle(); |
| 956 | 954 |
| 957 // Seek to flush the pipeline and ensure there's no prerolled audio data. | 955 // Seek to flush the pipeline and ensure there's no prerolled audio data. |
| 958 ASSERT_TRUE(Seek(base::TimeDelta())); | 956 ASSERT_TRUE(Seek(base::TimeDelta())); |
| 959 | 957 |
| 960 Play(); | 958 Play(); |
| 961 const base::TimeDelta k500ms = base::TimeDelta::FromMilliseconds(500); | 959 const base::TimeDelta k500ms = base::TimeDelta::FromMilliseconds(500); |
| 962 ASSERT_TRUE(WaitUntilCurrentTimeIsAfter(k500ms)); | 960 ASSERT_TRUE(WaitUntilCurrentTimeIsAfter(k500ms)); |
| 963 Pause(); | 961 Pause(); |
| 964 | 962 |
| 965 // Verify that no audio has been played, since we disabled audio tracks. | 963 // Verify that no audio has been played, since we disabled audio tracks. |
| 966 EXPECT_HASH_EQ(kNullAudioHash, GetAudioHash()); | 964 EXPECT_HASH_EQ(kNullAudioHash, GetAudioHash()); |
| 967 | 965 |
| 968 // Re-enable audio. | 966 // Re-enable audio. |
| 969 std::vector<MediaTrack::Id> audioTrackId; | 967 std::vector<MediaTrack::Id> audioTrackId; |
| 970 audioTrackId.push_back("2"); | 968 audioTrackId.push_back("2"); |
| 971 pipeline_->OnEnabledAudioTracksChanged(audioTrackId); | 969 pipeline_->OnEnabledAudioTracksChanged(audioTrackId); |
| 972 message_loop_.RunUntilIdle(); | 970 base::RunLoop().RunUntilIdle(); |
| 973 | 971 |
| 974 // Restart playback from 500ms position. | 972 // Restart playback from 500ms position. |
| 975 ASSERT_TRUE(Seek(k500ms)); | 973 ASSERT_TRUE(Seek(k500ms)); |
| 976 Play(); | 974 Play(); |
| 977 ASSERT_TRUE(WaitUntilOnEnded()); | 975 ASSERT_TRUE(WaitUntilOnEnded()); |
| 978 | 976 |
| 979 // Verify that audio has been playing after being enabled. | 977 // Verify that audio has been playing after being enabled. |
| 980 EXPECT_HASH_EQ("-1.53,0.21,1.23,1.56,-0.34,-0.94,", GetAudioHash()); | 978 EXPECT_HASH_EQ("-1.53,0.21,1.23,1.56,-0.34,-0.94,", GetAudioHash()); |
| 981 } | 979 } |
| 982 | 980 |
| 983 TEST_F(PipelineIntegrationTest, PlaybackWithVideoTrackDisabledThenEnabled) { | 981 TEST_F(PipelineIntegrationTest, PlaybackWithVideoTrackDisabledThenEnabled) { |
| 984 ASSERT_EQ(PIPELINE_OK, Start("bear-320x240.webm", kHashed)); | 982 ASSERT_EQ(PIPELINE_OK, Start("bear-320x240.webm", kHashed)); |
| 985 | 983 |
| 986 // Disable video. | 984 // Disable video. |
| 987 std::vector<MediaTrack::Id> empty; | 985 std::vector<MediaTrack::Id> empty; |
| 988 pipeline_->OnSelectedVideoTrackChanged(empty); | 986 pipeline_->OnSelectedVideoTrackChanged(empty); |
| 989 message_loop_.RunUntilIdle(); | 987 base::RunLoop().RunUntilIdle(); |
| 990 | 988 |
| 991 // Seek to flush the pipeline and ensure there's no prerolled video data. | 989 // Seek to flush the pipeline and ensure there's no prerolled video data. |
| 992 ASSERT_TRUE(Seek(base::TimeDelta())); | 990 ASSERT_TRUE(Seek(base::TimeDelta())); |
| 993 | 991 |
| 994 // Reset the video hash in case some of the prerolled video frames have been | 992 // Reset the video hash in case some of the prerolled video frames have been |
| 995 // hashed already. | 993 // hashed already. |
| 996 ResetVideoHash(); | 994 ResetVideoHash(); |
| 997 | 995 |
| 998 Play(); | 996 Play(); |
| 999 const base::TimeDelta k500ms = base::TimeDelta::FromMilliseconds(500); | 997 const base::TimeDelta k500ms = base::TimeDelta::FromMilliseconds(500); |
| 1000 ASSERT_TRUE(WaitUntilCurrentTimeIsAfter(k500ms)); | 998 ASSERT_TRUE(WaitUntilCurrentTimeIsAfter(k500ms)); |
| 1001 Pause(); | 999 Pause(); |
| 1002 | 1000 |
| 1003 // Verify that no video has been rendered, since we disabled video tracks. | 1001 // Verify that no video has been rendered, since we disabled video tracks. |
| 1004 EXPECT_HASH_EQ(kNullVideoHash, GetVideoHash()); | 1002 EXPECT_HASH_EQ(kNullVideoHash, GetVideoHash()); |
| 1005 | 1003 |
| 1006 // Re-enable video. | 1004 // Re-enable video. |
| 1007 std::vector<MediaTrack::Id> videoTrackId; | 1005 std::vector<MediaTrack::Id> videoTrackId; |
| 1008 videoTrackId.push_back("1"); | 1006 videoTrackId.push_back("1"); |
| 1009 pipeline_->OnSelectedVideoTrackChanged(videoTrackId); | 1007 pipeline_->OnSelectedVideoTrackChanged(videoTrackId); |
| 1010 message_loop_.RunUntilIdle(); | 1008 base::RunLoop().RunUntilIdle(); |
| 1011 | 1009 |
| 1012 // Seek to flush video pipeline and reset the video hash again to clear state | 1010 // Seek to flush video pipeline and reset the video hash again to clear state |
| 1013 // if some prerolled frames got hashed after enabling video. | 1011 // if some prerolled frames got hashed after enabling video. |
| 1014 ASSERT_TRUE(Seek(base::TimeDelta())); | 1012 ASSERT_TRUE(Seek(base::TimeDelta())); |
| 1015 ResetVideoHash(); | 1013 ResetVideoHash(); |
| 1016 | 1014 |
| 1017 // Restart playback from 500ms position. | 1015 // Restart playback from 500ms position. |
| 1018 ASSERT_TRUE(Seek(k500ms)); | 1016 ASSERT_TRUE(Seek(k500ms)); |
| 1019 Play(); | 1017 Play(); |
| 1020 ASSERT_TRUE(WaitUntilOnEnded()); | 1018 ASSERT_TRUE(WaitUntilOnEnded()); |
| (...skipping 733 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1754 | 1752 |
| 1755 EXPECT_CALL(*this, OnVideoNaturalSizeChange(gfx::Size(1280, 720))).Times(1); | 1753 EXPECT_CALL(*this, OnVideoNaturalSizeChange(gfx::Size(1280, 720))).Times(1); |
| 1756 scoped_refptr<DecoderBuffer> second_file = | 1754 scoped_refptr<DecoderBuffer> second_file = |
| 1757 ReadTestDataFile("bear-1280x720-v_frag-cenc.mp4"); | 1755 ReadTestDataFile("bear-1280x720-v_frag-cenc.mp4"); |
| 1758 ASSERT_FALSE(source.AppendAtTime(base::TimeDelta::FromSeconds(kAppendTimeSec), | 1756 ASSERT_FALSE(source.AppendAtTime(base::TimeDelta::FromSeconds(kAppendTimeSec), |
| 1759 second_file->data(), | 1757 second_file->data(), |
| 1760 second_file->data_size())); | 1758 second_file->data_size())); |
| 1761 | 1759 |
| 1762 source.EndOfStream(); | 1760 source.EndOfStream(); |
| 1763 | 1761 |
| 1764 message_loop_.Run(); | 1762 base::RunLoop().Run(); |
| 1765 EXPECT_EQ(CHUNK_DEMUXER_ERROR_APPEND_FAILED, pipeline_status_); | 1763 EXPECT_EQ(CHUNK_DEMUXER_ERROR_APPEND_FAILED, pipeline_status_); |
| 1766 | 1764 |
| 1767 EXPECT_EQ(1u, pipeline_->GetBufferedTimeRanges().size()); | 1765 EXPECT_EQ(1u, pipeline_->GetBufferedTimeRanges().size()); |
| 1768 EXPECT_EQ(0, pipeline_->GetBufferedTimeRanges().start(0).InMilliseconds()); | 1766 EXPECT_EQ(0, pipeline_->GetBufferedTimeRanges().start(0).InMilliseconds()); |
| 1769 // The second video was not added, so its time has not been added. | 1767 // The second video was not added, so its time has not been added. |
| 1770 EXPECT_EQ(k640IsoFileDurationMs, | 1768 EXPECT_EQ(k640IsoFileDurationMs, |
| 1771 pipeline_->GetBufferedTimeRanges().end(0).InMilliseconds()); | 1769 pipeline_->GetBufferedTimeRanges().end(0).InMilliseconds()); |
| 1772 | 1770 |
| 1773 Play(); | 1771 Play(); |
| 1774 | 1772 |
| (...skipping 625 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2400 | 2398 |
| 2401 TEST_F(PipelineIntegrationTest, BasicPlaybackPositiveStartTime) { | 2399 TEST_F(PipelineIntegrationTest, BasicPlaybackPositiveStartTime) { |
| 2402 ASSERT_EQ(PIPELINE_OK, Start("nonzero-start-time.webm")); | 2400 ASSERT_EQ(PIPELINE_OK, Start("nonzero-start-time.webm")); |
| 2403 Play(); | 2401 Play(); |
| 2404 ASSERT_TRUE(WaitUntilOnEnded()); | 2402 ASSERT_TRUE(WaitUntilOnEnded()); |
| 2405 ASSERT_EQ(base::TimeDelta::FromMicroseconds(396000), | 2403 ASSERT_EQ(base::TimeDelta::FromMicroseconds(396000), |
| 2406 demuxer_->GetStartTime()); | 2404 demuxer_->GetStartTime()); |
| 2407 } | 2405 } |
| 2408 | 2406 |
| 2409 } // namespace media | 2407 } // namespace media |
| OLD | NEW |