OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/callback.h" | 7 #include "base/callback.h" |
8 #include "base/stl_util-inl.h" | 8 #include "base/stl_util-inl.h" |
9 #include "base/threading/simple_thread.h" | 9 #include "base/threading/simple_thread.h" |
10 #include "media/base/pipeline_impl.h" | 10 #include "media/base/pipeline_impl.h" |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
94 | 94 |
95 protected: | 95 protected: |
96 // Sets up expectations to allow the demuxer to initialize. | 96 // Sets up expectations to allow the demuxer to initialize. |
97 typedef std::vector<MockDemuxerStream*> MockDemuxerStreamVector; | 97 typedef std::vector<MockDemuxerStream*> MockDemuxerStreamVector; |
98 void InitializeDemuxer(MockDemuxerStreamVector* streams, | 98 void InitializeDemuxer(MockDemuxerStreamVector* streams, |
99 const base::TimeDelta& duration) { | 99 const base::TimeDelta& duration) { |
100 mocks_->demuxer()->SetTotalAndBufferedBytesAndDuration( | 100 mocks_->demuxer()->SetTotalAndBufferedBytesAndDuration( |
101 kTotalBytes, kBufferedBytes, duration); | 101 kTotalBytes, kBufferedBytes, duration); |
102 EXPECT_CALL(*mocks_->demuxer(), SetPlaybackRate(0.0f)); | 102 EXPECT_CALL(*mocks_->demuxer(), SetPlaybackRate(0.0f)); |
103 EXPECT_CALL(*mocks_->demuxer(), SetPreload(AUTO)); | 103 EXPECT_CALL(*mocks_->demuxer(), SetPreload(AUTO)); |
104 EXPECT_CALL(*mocks_->demuxer(), Seek(base::TimeDelta(), NotNull())) | 104 EXPECT_CALL(*mocks_->demuxer(), Seek(base::TimeDelta(), _)) |
105 .WillOnce(Invoke(&RunFilterCallback)); | 105 .WillOnce(Invoke(&RunFilterStatusCB)); |
106 EXPECT_CALL(*mocks_->demuxer(), Stop(NotNull())) | 106 EXPECT_CALL(*mocks_->demuxer(), Stop(NotNull())) |
107 .WillOnce(Invoke(&RunStopFilterCallback)); | 107 .WillOnce(Invoke(&RunStopFilterCallback)); |
108 | 108 |
109 // Configure the demuxer to return the streams. | 109 // Configure the demuxer to return the streams. |
110 for (size_t i = 0; i < streams->size(); ++i) { | 110 for (size_t i = 0; i < streams->size(); ++i) { |
111 scoped_refptr<DemuxerStream> stream((*streams)[i]); | 111 scoped_refptr<DemuxerStream> stream((*streams)[i]); |
112 EXPECT_CALL(*mocks_->demuxer(), GetStream(stream->type())) | 112 EXPECT_CALL(*mocks_->demuxer(), GetStream(stream->type())) |
113 .WillRepeatedly(Return(stream)); | 113 .WillRepeatedly(Return(stream)); |
114 } | 114 } |
115 } | 115 } |
116 | 116 |
117 StrictMock<MockDemuxerStream>* CreateStream(DemuxerStream::Type type) { | 117 StrictMock<MockDemuxerStream>* CreateStream(DemuxerStream::Type type) { |
118 StrictMock<MockDemuxerStream>* stream = | 118 StrictMock<MockDemuxerStream>* stream = |
119 new StrictMock<MockDemuxerStream>(); | 119 new StrictMock<MockDemuxerStream>(); |
120 EXPECT_CALL(*stream, type()) | 120 EXPECT_CALL(*stream, type()) |
121 .WillRepeatedly(Return(type)); | 121 .WillRepeatedly(Return(type)); |
122 return stream; | 122 return stream; |
123 } | 123 } |
124 | 124 |
125 // Sets up expectations to allow the video decoder to initialize. | 125 // Sets up expectations to allow the video decoder to initialize. |
126 void InitializeVideoDecoder(MockDemuxerStream* stream) { | 126 void InitializeVideoDecoder(MockDemuxerStream* stream) { |
127 EXPECT_CALL(*mocks_->video_decoder(), | 127 EXPECT_CALL(*mocks_->video_decoder(), |
128 Initialize(stream, NotNull(), NotNull())) | 128 Initialize(stream, NotNull(), NotNull())) |
129 .WillOnce(DoAll(Invoke(&RunFilterCallback3), DeleteArg<2>())); | 129 .WillOnce(DoAll(Invoke(&RunFilterCallback3), DeleteArg<2>())); |
130 EXPECT_CALL(*mocks_->video_decoder(), SetPlaybackRate(0.0f)); | 130 EXPECT_CALL(*mocks_->video_decoder(), SetPlaybackRate(0.0f)); |
131 EXPECT_CALL(*mocks_->video_decoder(), Seek(base::TimeDelta(), NotNull())) | 131 EXPECT_CALL(*mocks_->video_decoder(), Seek(base::TimeDelta(), _)) |
132 .WillOnce(Invoke(&RunFilterCallback)); | 132 .WillOnce(Invoke(&RunFilterStatusCB)); |
133 EXPECT_CALL(*mocks_->video_decoder(), Stop(NotNull())) | 133 EXPECT_CALL(*mocks_->video_decoder(), Stop(NotNull())) |
134 .WillOnce(Invoke(&RunStopFilterCallback)); | 134 .WillOnce(Invoke(&RunStopFilterCallback)); |
135 } | 135 } |
136 | 136 |
137 // Sets up expectations to allow the audio decoder to initialize. | 137 // Sets up expectations to allow the audio decoder to initialize. |
138 void InitializeAudioDecoder(MockDemuxerStream* stream) { | 138 void InitializeAudioDecoder(MockDemuxerStream* stream) { |
139 EXPECT_CALL(*mocks_->audio_decoder(), | 139 EXPECT_CALL(*mocks_->audio_decoder(), |
140 Initialize(stream, NotNull(), NotNull())) | 140 Initialize(stream, NotNull(), NotNull())) |
141 .WillOnce(DoAll(Invoke(&RunFilterCallback3), DeleteArg<2>())); | 141 .WillOnce(DoAll(Invoke(&RunFilterCallback3), DeleteArg<2>())); |
142 EXPECT_CALL(*mocks_->audio_decoder(), SetPlaybackRate(0.0f)); | 142 EXPECT_CALL(*mocks_->audio_decoder(), SetPlaybackRate(0.0f)); |
143 EXPECT_CALL(*mocks_->audio_decoder(), Seek(base::TimeDelta(), NotNull())) | 143 EXPECT_CALL(*mocks_->audio_decoder(), Seek(base::TimeDelta(), _)) |
144 .WillOnce(Invoke(&RunFilterCallback)); | 144 .WillOnce(Invoke(&RunFilterStatusCB)); |
145 EXPECT_CALL(*mocks_->audio_decoder(), Stop(NotNull())) | 145 EXPECT_CALL(*mocks_->audio_decoder(), Stop(NotNull())) |
146 .WillOnce(Invoke(&RunStopFilterCallback)); | 146 .WillOnce(Invoke(&RunStopFilterCallback)); |
147 } | 147 } |
148 | 148 |
149 // Sets up expectations to allow the video renderer to initialize. | 149 // Sets up expectations to allow the video renderer to initialize. |
150 void InitializeVideoRenderer() { | 150 void InitializeVideoRenderer() { |
151 EXPECT_CALL(*mocks_->video_renderer(), | 151 EXPECT_CALL(*mocks_->video_renderer(), |
152 Initialize(mocks_->video_decoder(), NotNull(), NotNull())) | 152 Initialize(mocks_->video_decoder(), NotNull(), NotNull())) |
153 .WillOnce(DoAll(Invoke(&RunFilterCallback3), DeleteArg<2>())); | 153 .WillOnce(DoAll(Invoke(&RunFilterCallback3), DeleteArg<2>())); |
154 EXPECT_CALL(*mocks_->video_renderer(), SetPlaybackRate(0.0f)); | 154 EXPECT_CALL(*mocks_->video_renderer(), SetPlaybackRate(0.0f)); |
155 EXPECT_CALL(*mocks_->video_renderer(), Seek(base::TimeDelta(), NotNull())) | 155 EXPECT_CALL(*mocks_->video_renderer(), Seek(base::TimeDelta(), _)) |
156 .WillOnce(Invoke(&RunFilterCallback)); | 156 .WillOnce(Invoke(&RunFilterStatusCB)); |
157 EXPECT_CALL(*mocks_->video_renderer(), Stop(NotNull())) | 157 EXPECT_CALL(*mocks_->video_renderer(), Stop(NotNull())) |
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_callback = false) { | 162 void InitializeAudioRenderer(bool disable_after_init_callback = false) { |
163 if (disable_after_init_callback) { | 163 if (disable_after_init_callback) { |
164 EXPECT_CALL(*mocks_->audio_renderer(), | 164 EXPECT_CALL(*mocks_->audio_renderer(), |
165 Initialize(mocks_->audio_decoder(), NotNull())) | 165 Initialize(mocks_->audio_decoder(), NotNull())) |
166 .WillOnce(DoAll(Invoke(&RunFilterCallback), | 166 .WillOnce(DoAll(Invoke(&RunFilterCallback), |
167 DisableAudioRenderer(mocks_->audio_renderer()))); | 167 DisableAudioRenderer(mocks_->audio_renderer()))); |
168 } else { | 168 } else { |
169 EXPECT_CALL(*mocks_->audio_renderer(), | 169 EXPECT_CALL(*mocks_->audio_renderer(), |
170 Initialize(mocks_->audio_decoder(), NotNull())) | 170 Initialize(mocks_->audio_decoder(), NotNull())) |
171 .WillOnce(Invoke(&RunFilterCallback)); | 171 .WillOnce(Invoke(&RunFilterCallback)); |
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(), NotNull())) | 175 EXPECT_CALL(*mocks_->audio_renderer(), Seek(base::TimeDelta(), _)) |
176 .WillOnce(Invoke(&RunFilterCallback)); | 176 .WillOnce(Invoke(&RunFilterStatusCB)); |
177 EXPECT_CALL(*mocks_->audio_renderer(), Stop(NotNull())) | 177 EXPECT_CALL(*mocks_->audio_renderer(), Stop(NotNull())) |
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 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
226 MockDemuxerStream* audio_stream() { | 226 MockDemuxerStream* audio_stream() { |
227 return audio_stream_; | 227 return audio_stream_; |
228 } | 228 } |
229 | 229 |
230 MockDemuxerStream* video_stream() { | 230 MockDemuxerStream* video_stream() { |
231 return video_stream_; | 231 return video_stream_; |
232 } | 232 } |
233 | 233 |
234 void ExpectSeek(const base::TimeDelta& seek_time) { | 234 void ExpectSeek(const base::TimeDelta& seek_time) { |
235 // Every filter should receive a call to Seek(). | 235 // Every filter should receive a call to Seek(). |
236 EXPECT_CALL(*mocks_->demuxer(), Seek(seek_time, NotNull())) | 236 EXPECT_CALL(*mocks_->demuxer(), Seek(seek_time, _)) |
237 .WillOnce(Invoke(&RunFilterCallback)); | 237 .WillOnce(Invoke(&RunFilterStatusCB)); |
238 | 238 |
239 if (audio_stream_) { | 239 if (audio_stream_) { |
240 EXPECT_CALL(*mocks_->audio_decoder(), Seek(seek_time, NotNull())) | 240 EXPECT_CALL(*mocks_->audio_decoder(), Seek(seek_time, _)) |
241 .WillOnce(Invoke(&RunFilterCallback)); | 241 .WillOnce(Invoke(&RunFilterStatusCB)); |
242 EXPECT_CALL(*mocks_->audio_renderer(), Seek(seek_time, NotNull())) | 242 EXPECT_CALL(*mocks_->audio_renderer(), Seek(seek_time, _)) |
243 .WillOnce(Invoke(&RunFilterCallback)); | 243 .WillOnce(Invoke(&RunFilterStatusCB)); |
244 } | 244 } |
245 | 245 |
246 if (video_stream_) { | 246 if (video_stream_) { |
247 EXPECT_CALL(*mocks_->video_decoder(), Seek(seek_time, NotNull())) | 247 EXPECT_CALL(*mocks_->video_decoder(), Seek(seek_time, _)) |
248 .WillOnce(Invoke(&RunFilterCallback)); | 248 .WillOnce(Invoke(&RunFilterStatusCB)); |
249 EXPECT_CALL(*mocks_->video_renderer(), Seek(seek_time, NotNull())) | 249 EXPECT_CALL(*mocks_->video_renderer(), Seek(seek_time, _)) |
250 .WillOnce(Invoke(&RunFilterCallback)); | 250 .WillOnce(Invoke(&RunFilterStatusCB)); |
251 } | 251 } |
252 | 252 |
253 // We expect a successful seek callback. | 253 // We expect a successful seek callback. |
254 EXPECT_CALL(callbacks_, OnSeek(PIPELINE_OK)); | 254 EXPECT_CALL(callbacks_, OnSeek(PIPELINE_OK)); |
255 } | 255 } |
256 | 256 |
257 void DoSeek(const base::TimeDelta& seek_time) { | 257 void DoSeek(const base::TimeDelta& seek_time) { |
258 pipeline_->Seek(seek_time, | 258 pipeline_->Seek(seek_time, |
259 NewCallback(reinterpret_cast<CallbackHelper*>(&callbacks_), | 259 NewCallback(reinterpret_cast<CallbackHelper*>(&callbacks_), |
260 &CallbackHelper::OnSeek)); | 260 &CallbackHelper::OnSeek)); |
(...skipping 498 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
759 | 759 |
760 // Signal end of video stream and make sure OnEnded() callback occurs. | 760 // Signal end of video stream and make sure OnEnded() callback occurs. |
761 EXPECT_CALL(*mocks_->audio_renderer(), HasEnded()) | 761 EXPECT_CALL(*mocks_->audio_renderer(), HasEnded()) |
762 .WillOnce(Return(true)); | 762 .WillOnce(Return(true)); |
763 EXPECT_CALL(*mocks_->video_renderer(), HasEnded()) | 763 EXPECT_CALL(*mocks_->video_renderer(), HasEnded()) |
764 .WillOnce(Return(true)); | 764 .WillOnce(Return(true)); |
765 EXPECT_CALL(callbacks_, OnEnded(PIPELINE_OK)); | 765 EXPECT_CALL(callbacks_, OnEnded(PIPELINE_OK)); |
766 host->NotifyEnded(); | 766 host->NotifyEnded(); |
767 } | 767 } |
768 | 768 |
| 769 void SendReadErrorToCB(::testing::Unused, const FilterStatusCB& cb) { |
| 770 cb.Run(PIPELINE_ERROR_READ); |
| 771 } |
| 772 |
769 TEST_F(PipelineImplTest, ErrorDuringSeek) { | 773 TEST_F(PipelineImplTest, ErrorDuringSeek) { |
770 CreateAudioStream(); | 774 CreateAudioStream(); |
771 MockDemuxerStreamVector streams; | 775 MockDemuxerStreamVector streams; |
772 streams.push_back(audio_stream()); | 776 streams.push_back(audio_stream()); |
773 | 777 |
774 InitializeDemuxer(&streams, base::TimeDelta::FromSeconds(10)); | 778 InitializeDemuxer(&streams, base::TimeDelta::FromSeconds(10)); |
775 InitializeAudioDecoder(audio_stream()); | 779 InitializeAudioDecoder(audio_stream()); |
776 InitializeAudioRenderer(); | 780 InitializeAudioRenderer(); |
777 InitializePipeline(PIPELINE_OK); | 781 InitializePipeline(PIPELINE_OK); |
778 | 782 |
779 float playback_rate = 1.0f; | 783 float playback_rate = 1.0f; |
780 EXPECT_CALL(*mocks_->demuxer(), SetPlaybackRate(playback_rate)); | 784 EXPECT_CALL(*mocks_->demuxer(), SetPlaybackRate(playback_rate)); |
781 EXPECT_CALL(*mocks_->audio_decoder(), SetPlaybackRate(playback_rate)); | 785 EXPECT_CALL(*mocks_->audio_decoder(), SetPlaybackRate(playback_rate)); |
782 EXPECT_CALL(*mocks_->audio_renderer(), SetPlaybackRate(playback_rate)); | 786 EXPECT_CALL(*mocks_->audio_renderer(), SetPlaybackRate(playback_rate)); |
783 pipeline_->SetPlaybackRate(playback_rate); | 787 pipeline_->SetPlaybackRate(playback_rate); |
784 message_loop_.RunAllPending(); | 788 message_loop_.RunAllPending(); |
785 | 789 |
786 InSequence s; | 790 InSequence s; |
787 | 791 |
788 base::TimeDelta seek_time = base::TimeDelta::FromSeconds(5); | 792 base::TimeDelta seek_time = base::TimeDelta::FromSeconds(5); |
789 | 793 |
790 EXPECT_CALL(*mocks_->demuxer(), Seek(seek_time, NotNull())) | 794 EXPECT_CALL(*mocks_->demuxer(), Seek(seek_time, _)) |
791 .WillOnce(DoAll(SetError(mocks_->demuxer(), | 795 .WillOnce(Invoke(&SendReadErrorToCB)); |
792 PIPELINE_ERROR_READ), | |
793 Invoke(&RunFilterCallback))); | |
794 | 796 |
795 pipeline_->Seek(seek_time, NewCallback( | 797 pipeline_->Seek(seek_time, NewCallback( |
796 reinterpret_cast<CallbackHelper*>(&callbacks_), &CallbackHelper::OnSeek)); | 798 reinterpret_cast<CallbackHelper*>(&callbacks_), &CallbackHelper::OnSeek)); |
797 EXPECT_CALL(callbacks_, OnSeek(PIPELINE_ERROR_READ)); | 799 EXPECT_CALL(callbacks_, OnSeek(PIPELINE_ERROR_READ)); |
798 EXPECT_CALL(callbacks_, OnError(PIPELINE_ERROR_READ)); | 800 EXPECT_CALL(callbacks_, OnError(PIPELINE_ERROR_READ)); |
799 message_loop_.RunAllPending(); | 801 message_loop_.RunAllPending(); |
800 } | 802 } |
801 | 803 |
802 class FlexibleCallbackRunner : public base::DelegateSimpleThread::Delegate { | 804 class FlexibleCallbackRunner : public base::DelegateSimpleThread::Delegate { |
803 public: | 805 public: |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
844 TestPipelineStatusNotification(0); | 846 TestPipelineStatusNotification(0); |
845 } | 847 } |
846 | 848 |
847 // Test that different-thread, some-delay callback (the expected common case) | 849 // Test that different-thread, some-delay callback (the expected common case) |
848 // works correctly. | 850 // works correctly. |
849 TEST(PipelineStatusNotificationTest, DelayedCallback) { | 851 TEST(PipelineStatusNotificationTest, DelayedCallback) { |
850 TestPipelineStatusNotification(20); | 852 TestPipelineStatusNotification(20); |
851 } | 853 } |
852 | 854 |
853 } // namespace media | 855 } // namespace media |
OLD | NEW |