| 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 <string> | 5 #include <string> |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
| 9 #include "base/stl_util.h" | 9 #include "base/stl_util.h" |
| 10 #include "base/threading/simple_thread.h" | 10 #include "base/threading/simple_thread.h" |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 99 protected: | 99 protected: |
| 100 // Sets up expectations to allow the demuxer to initialize. | 100 // Sets up expectations to allow the demuxer to initialize. |
| 101 typedef std::vector<MockDemuxerStream*> MockDemuxerStreamVector; | 101 typedef std::vector<MockDemuxerStream*> MockDemuxerStreamVector; |
| 102 void InitializeDemuxer(MockDemuxerStreamVector* streams, | 102 void InitializeDemuxer(MockDemuxerStreamVector* streams, |
| 103 const base::TimeDelta& duration) { | 103 const base::TimeDelta& duration) { |
| 104 mocks_->demuxer()->SetTotalAndBufferedBytesAndDuration( | 104 mocks_->demuxer()->SetTotalAndBufferedBytesAndDuration( |
| 105 kTotalBytes, kBufferedBytes, duration); | 105 kTotalBytes, kBufferedBytes, duration); |
| 106 EXPECT_CALL(*mocks_->demuxer(), SetPlaybackRate(0.0f)); | 106 EXPECT_CALL(*mocks_->demuxer(), SetPlaybackRate(0.0f)); |
| 107 EXPECT_CALL(*mocks_->demuxer(), SetPreload(AUTO)); | 107 EXPECT_CALL(*mocks_->demuxer(), SetPreload(AUTO)); |
| 108 EXPECT_CALL(*mocks_->demuxer(), Seek(mocks_->demuxer()->GetStartTime(), _)) | 108 EXPECT_CALL(*mocks_->demuxer(), Seek(mocks_->demuxer()->GetStartTime(), _)) |
| 109 .WillOnce(Invoke(&RunFilterStatusCB)); | 109 .WillOnce(Invoke(&RunPipelineStatusCB)); |
| 110 EXPECT_CALL(*mocks_->demuxer(), Stop(_)) | 110 EXPECT_CALL(*mocks_->demuxer(), Stop(_)) |
| 111 .WillOnce(Invoke(&RunStopFilterCallback)); | 111 .WillOnce(Invoke(&RunStopFilterCallback)); |
| 112 | 112 |
| 113 // Configure the demuxer to return the streams. | 113 // Configure the demuxer to return the streams. |
| 114 for (size_t i = 0; i < streams->size(); ++i) { | 114 for (size_t i = 0; i < streams->size(); ++i) { |
| 115 scoped_refptr<DemuxerStream> stream((*streams)[i]); | 115 scoped_refptr<DemuxerStream> stream((*streams)[i]); |
| 116 EXPECT_CALL(*mocks_->demuxer(), GetStream(stream->type())) | 116 EXPECT_CALL(*mocks_->demuxer(), GetStream(stream->type())) |
| 117 .WillRepeatedly(Return(stream)); | 117 .WillRepeatedly(Return(stream)); |
| 118 } | 118 } |
| 119 } | 119 } |
| 120 | 120 |
| 121 StrictMock<MockDemuxerStream>* CreateStream(DemuxerStream::Type type) { | 121 StrictMock<MockDemuxerStream>* CreateStream(DemuxerStream::Type type) { |
| 122 StrictMock<MockDemuxerStream>* stream = | 122 StrictMock<MockDemuxerStream>* stream = |
| 123 new StrictMock<MockDemuxerStream>(); | 123 new StrictMock<MockDemuxerStream>(); |
| 124 EXPECT_CALL(*stream, type()) | 124 EXPECT_CALL(*stream, type()) |
| 125 .WillRepeatedly(Return(type)); | 125 .WillRepeatedly(Return(type)); |
| 126 return stream; | 126 return stream; |
| 127 } | 127 } |
| 128 | 128 |
| 129 // Sets up expectations to allow the video decoder to initialize. | 129 // Sets up expectations to allow the video decoder to initialize. |
| 130 void InitializeVideoDecoder(MockDemuxerStream* stream) { | 130 void InitializeVideoDecoder(MockDemuxerStream* stream) { |
| 131 EXPECT_CALL(*mocks_->video_decoder(), | 131 EXPECT_CALL(*mocks_->video_decoder(), |
| 132 Initialize(stream, _, _)) | 132 Initialize(stream, _, _)) |
| 133 .WillOnce(WithArg<1>(Invoke(&RunPipelineStatusOKCB))); | 133 .WillOnce(WithArg<1>(Invoke(&RunPipelineStatusOKCB))); |
| 134 EXPECT_CALL(*mocks_->video_decoder(), SetPlaybackRate(0.0f)); | 134 EXPECT_CALL(*mocks_->video_decoder(), SetPlaybackRate(0.0f)); |
| 135 EXPECT_CALL(*mocks_->video_decoder(), | 135 EXPECT_CALL(*mocks_->video_decoder(), |
| 136 Seek(mocks_->demuxer()->GetStartTime(), _)) | 136 Seek(mocks_->demuxer()->GetStartTime(), _)) |
| 137 .WillOnce(Invoke(&RunFilterStatusCB)); | 137 .WillOnce(Invoke(&RunPipelineStatusCB)); |
| 138 EXPECT_CALL(*mocks_->video_decoder(), Stop(_)) | 138 EXPECT_CALL(*mocks_->video_decoder(), Stop(_)) |
| 139 .WillOnce(Invoke(&RunStopFilterCallback)); | 139 .WillOnce(Invoke(&RunStopFilterCallback)); |
| 140 } | 140 } |
| 141 | 141 |
| 142 // Sets up expectations to allow the audio decoder to initialize. | 142 // Sets up expectations to allow the audio decoder to initialize. |
| 143 void InitializeAudioDecoder(const scoped_refptr<DemuxerStream>& stream) { | 143 void InitializeAudioDecoder(const scoped_refptr<DemuxerStream>& stream) { |
| 144 EXPECT_CALL(*mocks_->audio_decoder(), Initialize(stream, _, _)) | 144 EXPECT_CALL(*mocks_->audio_decoder(), Initialize(stream, _, _)) |
| 145 .WillOnce(Invoke(&RunPipelineStatusCB3)); | 145 .WillOnce(Invoke(&RunPipelineStatusCB3)); |
| 146 } | 146 } |
| 147 | 147 |
| 148 // Sets up expectations to allow the video renderer to initialize. | 148 // Sets up expectations to allow the video renderer to initialize. |
| 149 void InitializeVideoRenderer() { | 149 void InitializeVideoRenderer() { |
| 150 EXPECT_CALL(*mocks_->video_renderer(), | 150 EXPECT_CALL(*mocks_->video_renderer(), |
| 151 Initialize(mocks_->video_decoder(), _, _, _)) | 151 Initialize(mocks_->video_decoder(), _, _, _)) |
| 152 .WillOnce(Invoke(&RunPipelineStatusCB4)); | 152 .WillOnce(Invoke(&RunPipelineStatusCB4)); |
| 153 EXPECT_CALL(*mocks_->video_renderer(), SetPlaybackRate(0.0f)); | 153 EXPECT_CALL(*mocks_->video_renderer(), SetPlaybackRate(0.0f)); |
| 154 EXPECT_CALL(*mocks_->video_renderer(), | 154 EXPECT_CALL(*mocks_->video_renderer(), |
| 155 Seek(mocks_->demuxer()->GetStartTime(), _)) | 155 Seek(mocks_->demuxer()->GetStartTime(), _)) |
| 156 .WillOnce(Invoke(&RunFilterStatusCB)); | 156 .WillOnce(Invoke(&RunPipelineStatusCB)); |
| 157 EXPECT_CALL(*mocks_->video_renderer(), Stop(_)) | 157 EXPECT_CALL(*mocks_->video_renderer(), Stop(_)) |
| 158 .WillOnce(Invoke(&RunStopFilterCallback)); | 158 .WillOnce(Invoke(&RunStopFilterCallback)); |
| 159 } | 159 } |
| 160 | 160 |
| 161 // Sets up expectations to allow the audio renderer to initialize. | 161 // Sets up expectations to allow the audio renderer to initialize. |
| 162 void InitializeAudioRenderer(bool disable_after_init_cb = false) { | 162 void InitializeAudioRenderer(bool disable_after_init_cb = false) { |
| 163 if (disable_after_init_cb) { | 163 if (disable_after_init_cb) { |
| 164 EXPECT_CALL(*mocks_->audio_renderer(), Initialize( | 164 EXPECT_CALL(*mocks_->audio_renderer(), Initialize( |
| 165 scoped_refptr<AudioDecoder>(mocks_->audio_decoder()), _, _, _)) | 165 scoped_refptr<AudioDecoder>(mocks_->audio_decoder()), _, _, _)) |
| 166 .WillOnce(DoAll(Invoke(&RunPipelineStatusCB4), | 166 .WillOnce(DoAll(Invoke(&RunPipelineStatusCB4), |
| 167 DisableAudioRenderer(mocks_->audio_renderer()))); | 167 DisableAudioRenderer(mocks_->audio_renderer()))); |
| 168 } else { | 168 } else { |
| 169 EXPECT_CALL(*mocks_->audio_renderer(), Initialize( | 169 EXPECT_CALL(*mocks_->audio_renderer(), Initialize( |
| 170 scoped_refptr<AudioDecoder>(mocks_->audio_decoder()), _, _, _)) | 170 scoped_refptr<AudioDecoder>(mocks_->audio_decoder()), _, _, _)) |
| 171 .WillOnce(Invoke(&RunPipelineStatusCB4)); | 171 .WillOnce(Invoke(&RunPipelineStatusCB4)); |
| 172 } | 172 } |
| 173 EXPECT_CALL(*mocks_->audio_renderer(), SetPlaybackRate(0.0f)); | 173 EXPECT_CALL(*mocks_->audio_renderer(), SetPlaybackRate(0.0f)); |
| 174 EXPECT_CALL(*mocks_->audio_renderer(), SetVolume(1.0f)); | 174 EXPECT_CALL(*mocks_->audio_renderer(), SetVolume(1.0f)); |
| 175 EXPECT_CALL(*mocks_->audio_renderer(), Seek(base::TimeDelta(), _)) | 175 EXPECT_CALL(*mocks_->audio_renderer(), Seek(base::TimeDelta(), _)) |
| 176 .WillOnce(Invoke(&RunFilterStatusCB)); | 176 .WillOnce(Invoke(&RunPipelineStatusCB)); |
| 177 EXPECT_CALL(*mocks_->audio_renderer(), Stop(_)) | 177 EXPECT_CALL(*mocks_->audio_renderer(), Stop(_)) |
| 178 .WillOnce(Invoke(&RunStopFilterCallback)); | 178 .WillOnce(Invoke(&RunStopFilterCallback)); |
| 179 } | 179 } |
| 180 | 180 |
| 181 // Sets up expectations on the callback and initializes the pipeline. Called | 181 // Sets up expectations on the callback and initializes the pipeline. Called |
| 182 // after tests have set expectations any filters they wish to use. | 182 // after tests have set expectations any filters they wish to use. |
| 183 void InitializePipeline() { | 183 void InitializePipeline() { |
| 184 InitializePipeline(PIPELINE_OK); | 184 InitializePipeline(PIPELINE_OK); |
| 185 } | 185 } |
| 186 // Most tests can expect the |filter_collection|'s |build_status| to get | 186 // Most tests can expect the |filter_collection|'s |build_status| to get |
| (...skipping 30 matching lines...) Expand all Loading... |
| 217 return audio_stream_; | 217 return audio_stream_; |
| 218 } | 218 } |
| 219 | 219 |
| 220 MockDemuxerStream* video_stream() { | 220 MockDemuxerStream* video_stream() { |
| 221 return video_stream_; | 221 return video_stream_; |
| 222 } | 222 } |
| 223 | 223 |
| 224 void ExpectSeek(const base::TimeDelta& seek_time) { | 224 void ExpectSeek(const base::TimeDelta& seek_time) { |
| 225 // Every filter should receive a call to Seek(). | 225 // Every filter should receive a call to Seek(). |
| 226 EXPECT_CALL(*mocks_->demuxer(), Seek(seek_time, _)) | 226 EXPECT_CALL(*mocks_->demuxer(), Seek(seek_time, _)) |
| 227 .WillOnce(Invoke(&RunFilterStatusCB)); | 227 .WillOnce(Invoke(&RunPipelineStatusCB)); |
| 228 | 228 |
| 229 if (audio_stream_) { | 229 if (audio_stream_) { |
| 230 EXPECT_CALL(*mocks_->audio_renderer(), Seek(seek_time, _)) | 230 EXPECT_CALL(*mocks_->audio_renderer(), Seek(seek_time, _)) |
| 231 .WillOnce(Invoke(&RunFilterStatusCB)); | 231 .WillOnce(Invoke(&RunPipelineStatusCB)); |
| 232 } | 232 } |
| 233 | 233 |
| 234 if (video_stream_) { | 234 if (video_stream_) { |
| 235 EXPECT_CALL(*mocks_->video_decoder(), Seek(seek_time, _)) | 235 EXPECT_CALL(*mocks_->video_decoder(), Seek(seek_time, _)) |
| 236 .WillOnce(Invoke(&RunFilterStatusCB)); | 236 .WillOnce(Invoke(&RunPipelineStatusCB)); |
| 237 EXPECT_CALL(*mocks_->video_renderer(), Seek(seek_time, _)) | 237 EXPECT_CALL(*mocks_->video_renderer(), Seek(seek_time, _)) |
| 238 .WillOnce(Invoke(&RunFilterStatusCB)); | 238 .WillOnce(Invoke(&RunPipelineStatusCB)); |
| 239 } | 239 } |
| 240 | 240 |
| 241 // We expect a successful seek callback. | 241 // We expect a successful seek callback. |
| 242 EXPECT_CALL(callbacks_, OnSeek(PIPELINE_OK)); | 242 EXPECT_CALL(callbacks_, OnSeek(PIPELINE_OK)); |
| 243 } | 243 } |
| 244 | 244 |
| 245 void DoSeek(const base::TimeDelta& seek_time) { | 245 void DoSeek(const base::TimeDelta& seek_time) { |
| 246 pipeline_->Seek(seek_time, | 246 pipeline_->Seek(seek_time, |
| 247 base::Bind(&CallbackHelper::OnSeek, | 247 base::Bind(&CallbackHelper::OnSeek, |
| 248 base::Unretained(&callbacks_))); | 248 base::Unretained(&callbacks_))); |
| (...skipping 470 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 719 | 719 |
| 720 // Signal end of video stream and make sure OnEnded() callback occurs. | 720 // Signal end of video stream and make sure OnEnded() callback occurs. |
| 721 EXPECT_CALL(*mocks_->audio_renderer(), HasEnded()) | 721 EXPECT_CALL(*mocks_->audio_renderer(), HasEnded()) |
| 722 .WillOnce(Return(true)); | 722 .WillOnce(Return(true)); |
| 723 EXPECT_CALL(*mocks_->video_renderer(), HasEnded()) | 723 EXPECT_CALL(*mocks_->video_renderer(), HasEnded()) |
| 724 .WillOnce(Return(true)); | 724 .WillOnce(Return(true)); |
| 725 EXPECT_CALL(callbacks_, OnEnded(PIPELINE_OK)); | 725 EXPECT_CALL(callbacks_, OnEnded(PIPELINE_OK)); |
| 726 host->NotifyEnded(); | 726 host->NotifyEnded(); |
| 727 } | 727 } |
| 728 | 728 |
| 729 void SendReadErrorToCB(::testing::Unused, const FilterStatusCB& cb) { | 729 void SendReadErrorToCB(::testing::Unused, const PipelineStatusCB& cb) { |
| 730 cb.Run(PIPELINE_ERROR_READ); | 730 cb.Run(PIPELINE_ERROR_READ); |
| 731 } | 731 } |
| 732 | 732 |
| 733 TEST_F(PipelineTest, ErrorDuringSeek) { | 733 TEST_F(PipelineTest, ErrorDuringSeek) { |
| 734 CreateAudioStream(); | 734 CreateAudioStream(); |
| 735 MockDemuxerStreamVector streams; | 735 MockDemuxerStreamVector streams; |
| 736 streams.push_back(audio_stream()); | 736 streams.push_back(audio_stream()); |
| 737 | 737 |
| 738 InitializeDemuxer(&streams, base::TimeDelta::FromSeconds(10)); | 738 InitializeDemuxer(&streams, base::TimeDelta::FromSeconds(10)); |
| 739 InitializeAudioDecoder(audio_stream()); | 739 InitializeAudioDecoder(audio_stream()); |
| (...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 898 TestPipelineStatusNotification(base::TimeDelta::FromMilliseconds(0)); | 898 TestPipelineStatusNotification(base::TimeDelta::FromMilliseconds(0)); |
| 899 } | 899 } |
| 900 | 900 |
| 901 // Test that different-thread, some-delay callback (the expected common case) | 901 // Test that different-thread, some-delay callback (the expected common case) |
| 902 // works correctly. | 902 // works correctly. |
| 903 TEST(PipelineStatusNotificationTest, DelayedCallback) { | 903 TEST(PipelineStatusNotificationTest, DelayedCallback) { |
| 904 TestPipelineStatusNotification(base::TimeDelta::FromMilliseconds(20)); | 904 TestPipelineStatusNotification(base::TimeDelta::FromMilliseconds(20)); |
| 905 } | 905 } |
| 906 | 906 |
| 907 } // namespace media | 907 } // namespace media |
| OLD | NEW |