Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(51)

Side by Side Diff: media/base/pipeline_impl_unittest.cc

Issue 2101015: Change MediaFilter::Stop() to accept a callback so that Stop() is asynchronous. (Closed) Base URL: http://src.chromium.org/git/chromium.git
Patch Set: Revert filter changes. Going to make that another patch. Created 10 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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/waitable_event.h" 9 #include "base/waitable_event.h"
10 #include "media/base/pipeline_impl.h" 10 #include "media/base/pipeline_impl.h"
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
91 protected: 91 protected:
92 // Sets up expectations to allow the data source to initialize. 92 // Sets up expectations to allow the data source to initialize.
93 void InitializeDataSource() { 93 void InitializeDataSource() {
94 EXPECT_CALL(*mocks_->data_source(), Initialize("", NotNull())) 94 EXPECT_CALL(*mocks_->data_source(), Initialize("", NotNull()))
95 .WillOnce(DoAll(SetTotalBytes(mocks_->data_source(), kTotalBytes), 95 .WillOnce(DoAll(SetTotalBytes(mocks_->data_source(), kTotalBytes),
96 SetBufferedBytes(mocks_->data_source(), kBufferedBytes), 96 SetBufferedBytes(mocks_->data_source(), kBufferedBytes),
97 Invoke(&RunFilterCallback))); 97 Invoke(&RunFilterCallback)));
98 EXPECT_CALL(*mocks_->data_source(), SetPlaybackRate(0.0f)); 98 EXPECT_CALL(*mocks_->data_source(), SetPlaybackRate(0.0f));
99 EXPECT_CALL(*mocks_->data_source(), Seek(base::TimeDelta(), NotNull())) 99 EXPECT_CALL(*mocks_->data_source(), Seek(base::TimeDelta(), NotNull()))
100 .WillOnce(Invoke(&RunFilterCallback)); 100 .WillOnce(Invoke(&RunFilterCallback));
101 EXPECT_CALL(*mocks_->data_source(), Stop()); 101 EXPECT_CALL(*mocks_->data_source(), Stop(NotNull()))
102 .WillOnce(Invoke(&RunStopFilterCallback));
102 EXPECT_CALL(*mocks_->data_source(), media_format()) 103 EXPECT_CALL(*mocks_->data_source(), media_format())
103 .WillOnce(ReturnRef(data_source_media_format_)); 104 .WillOnce(ReturnRef(data_source_media_format_));
104 } 105 }
105 106
106 // Sets up expectations to allow the demuxer to initialize. 107 // Sets up expectations to allow the demuxer to initialize.
107 typedef std::vector<MockDemuxerStream*> MockDemuxerStreamVector; 108 typedef std::vector<MockDemuxerStream*> MockDemuxerStreamVector;
108 void InitializeDemuxer(MockDemuxerStreamVector* streams, 109 void InitializeDemuxer(MockDemuxerStreamVector* streams,
109 const base::TimeDelta& duration) { 110 const base::TimeDelta& duration) {
110 EXPECT_CALL(*mocks_->demuxer(), 111 EXPECT_CALL(*mocks_->demuxer(),
111 Initialize(mocks_->data_source(), NotNull())) 112 Initialize(mocks_->data_source(), NotNull()))
112 .WillOnce(DoAll(SetDuration(mocks_->data_source(), duration), 113 .WillOnce(DoAll(SetDuration(mocks_->data_source(), duration),
113 Invoke(&RunFilterCallback))); 114 Invoke(&RunFilterCallback)));
114 EXPECT_CALL(*mocks_->demuxer(), GetNumberOfStreams()) 115 EXPECT_CALL(*mocks_->demuxer(), GetNumberOfStreams())
115 .WillRepeatedly(Return(streams->size())); 116 .WillRepeatedly(Return(streams->size()));
116 EXPECT_CALL(*mocks_->demuxer(), SetPlaybackRate(0.0f)); 117 EXPECT_CALL(*mocks_->demuxer(), SetPlaybackRate(0.0f));
117 EXPECT_CALL(*mocks_->demuxer(), Seek(base::TimeDelta(), NotNull())) 118 EXPECT_CALL(*mocks_->demuxer(), Seek(base::TimeDelta(), NotNull()))
118 .WillOnce(Invoke(&RunFilterCallback)); 119 .WillOnce(Invoke(&RunFilterCallback));
119 EXPECT_CALL(*mocks_->demuxer(), Stop()); 120 EXPECT_CALL(*mocks_->demuxer(), Stop(NotNull()))
121 .WillOnce(Invoke(&RunStopFilterCallback));
120 122
121 // Configure the demuxer to return the streams. 123 // Configure the demuxer to return the streams.
122 for (size_t i = 0; i < streams->size(); ++i) { 124 for (size_t i = 0; i < streams->size(); ++i) {
123 scoped_refptr<DemuxerStream> stream = (*streams)[i]; 125 scoped_refptr<DemuxerStream> stream = (*streams)[i];
124 EXPECT_CALL(*mocks_->demuxer(), GetStream(i)) 126 EXPECT_CALL(*mocks_->demuxer(), GetStream(i))
125 .WillRepeatedly(Return(stream)); 127 .WillRepeatedly(Return(stream));
126 } 128 }
127 } 129 }
128 130
129 // Create a stream with an associated media format. 131 // Create a stream with an associated media format.
(...skipping 12 matching lines...) Expand all
142 return stream; 144 return stream;
143 } 145 }
144 146
145 // Sets up expectations to allow the video decoder to initialize. 147 // Sets up expectations to allow the video decoder to initialize.
146 void InitializeVideoDecoder(MockDemuxerStream* stream) { 148 void InitializeVideoDecoder(MockDemuxerStream* stream) {
147 EXPECT_CALL(*mocks_->video_decoder(), Initialize(stream, NotNull())) 149 EXPECT_CALL(*mocks_->video_decoder(), Initialize(stream, NotNull()))
148 .WillOnce(Invoke(&RunFilterCallback)); 150 .WillOnce(Invoke(&RunFilterCallback));
149 EXPECT_CALL(*mocks_->video_decoder(), SetPlaybackRate(0.0f)); 151 EXPECT_CALL(*mocks_->video_decoder(), SetPlaybackRate(0.0f));
150 EXPECT_CALL(*mocks_->video_decoder(), Seek(base::TimeDelta(), NotNull())) 152 EXPECT_CALL(*mocks_->video_decoder(), Seek(base::TimeDelta(), NotNull()))
151 .WillOnce(Invoke(&RunFilterCallback)); 153 .WillOnce(Invoke(&RunFilterCallback));
152 EXPECT_CALL(*mocks_->video_decoder(), Stop()); 154 EXPECT_CALL(*mocks_->video_decoder(), Stop(NotNull()))
155 .WillOnce(Invoke(&RunStopFilterCallback));
153 EXPECT_CALL(*mocks_->video_decoder(), media_format()) 156 EXPECT_CALL(*mocks_->video_decoder(), media_format())
154 .WillOnce(ReturnRef(video_decoder_media_format_)); 157 .WillOnce(ReturnRef(video_decoder_media_format_));
155 } 158 }
156 159
157 // Sets up expectations to allow the audio decoder to initialize. 160 // Sets up expectations to allow the audio decoder to initialize.
158 void InitializeAudioDecoder(MockDemuxerStream* stream) { 161 void InitializeAudioDecoder(MockDemuxerStream* stream) {
159 EXPECT_CALL(*mocks_->audio_decoder(), Initialize(stream, NotNull())) 162 EXPECT_CALL(*mocks_->audio_decoder(), Initialize(stream, NotNull()))
160 .WillOnce(Invoke(&RunFilterCallback)); 163 .WillOnce(Invoke(&RunFilterCallback));
161 EXPECT_CALL(*mocks_->audio_decoder(), SetPlaybackRate(0.0f)); 164 EXPECT_CALL(*mocks_->audio_decoder(), SetPlaybackRate(0.0f));
162 EXPECT_CALL(*mocks_->audio_decoder(), Seek(base::TimeDelta(), NotNull())) 165 EXPECT_CALL(*mocks_->audio_decoder(), Seek(base::TimeDelta(), NotNull()))
163 .WillOnce(Invoke(&RunFilterCallback)); 166 .WillOnce(Invoke(&RunFilterCallback));
164 EXPECT_CALL(*mocks_->audio_decoder(), Stop()); 167 EXPECT_CALL(*mocks_->audio_decoder(), Stop(NotNull()))
168 .WillOnce(Invoke(&RunStopFilterCallback));
165 EXPECT_CALL(*mocks_->audio_decoder(), media_format()) 169 EXPECT_CALL(*mocks_->audio_decoder(), media_format())
166 .WillOnce(ReturnRef(audio_decoder_media_format_)); 170 .WillOnce(ReturnRef(audio_decoder_media_format_));
167 } 171 }
168 172
169 // Sets up expectations to allow the video renderer to initialize. 173 // Sets up expectations to allow the video renderer to initialize.
170 void InitializeVideoRenderer() { 174 void InitializeVideoRenderer() {
171 EXPECT_CALL(*mocks_->video_renderer(), 175 EXPECT_CALL(*mocks_->video_renderer(),
172 Initialize(mocks_->video_decoder(), NotNull())) 176 Initialize(mocks_->video_decoder(), NotNull()))
173 .WillOnce(Invoke(&RunFilterCallback)); 177 .WillOnce(Invoke(&RunFilterCallback));
174 EXPECT_CALL(*mocks_->video_renderer(), SetPlaybackRate(0.0f)); 178 EXPECT_CALL(*mocks_->video_renderer(), SetPlaybackRate(0.0f));
175 EXPECT_CALL(*mocks_->video_renderer(), Seek(base::TimeDelta(), NotNull())) 179 EXPECT_CALL(*mocks_->video_renderer(), Seek(base::TimeDelta(), NotNull()))
176 .WillOnce(Invoke(&RunFilterCallback)); 180 .WillOnce(Invoke(&RunFilterCallback));
177 EXPECT_CALL(*mocks_->video_renderer(), Stop()); 181 EXPECT_CALL(*mocks_->video_renderer(), Stop(NotNull()))
182 .WillOnce(Invoke(&RunStopFilterCallback));
178 } 183 }
179 184
180 // Sets up expectations to allow the audio renderer to initialize. 185 // Sets up expectations to allow the audio renderer to initialize.
181 void InitializeAudioRenderer() { 186 void InitializeAudioRenderer() {
182 EXPECT_CALL(*mocks_->audio_renderer(), 187 EXPECT_CALL(*mocks_->audio_renderer(),
183 Initialize(mocks_->audio_decoder(), NotNull())) 188 Initialize(mocks_->audio_decoder(), NotNull()))
184 .WillOnce(Invoke(&RunFilterCallback)); 189 .WillOnce(Invoke(&RunFilterCallback));
185 EXPECT_CALL(*mocks_->audio_renderer(), SetPlaybackRate(0.0f)); 190 EXPECT_CALL(*mocks_->audio_renderer(), SetPlaybackRate(0.0f));
186 EXPECT_CALL(*mocks_->audio_renderer(), SetVolume(1.0f)); 191 EXPECT_CALL(*mocks_->audio_renderer(), SetVolume(1.0f));
187 EXPECT_CALL(*mocks_->audio_renderer(), Seek(base::TimeDelta(), NotNull())) 192 EXPECT_CALL(*mocks_->audio_renderer(), Seek(base::TimeDelta(), NotNull()))
188 .WillOnce(Invoke(&RunFilterCallback)); 193 .WillOnce(Invoke(&RunFilterCallback));
189 EXPECT_CALL(*mocks_->audio_renderer(), Stop()); 194 EXPECT_CALL(*mocks_->audio_renderer(), Stop(NotNull()))
195 .WillOnce(Invoke(&RunStopFilterCallback));
190 } 196 }
191 197
192 // Sets up expectations on the callback and initializes the pipeline. Called 198 // Sets up expectations on the callback and initializes the pipeline. Called
193 // after tests have set expectations any filters they wish to use. 199 // after tests have set expectations any filters they wish to use.
194 void InitializePipeline() { 200 void InitializePipeline() {
195 // Expect an initialization callback. 201 // Expect an initialization callback.
196 EXPECT_CALL(callbacks_, OnStart()); 202 EXPECT_CALL(callbacks_, OnStart());
197 pipeline_->Start(mocks_, "", 203 pipeline_->Start(mocks_, "",
198 NewCallback(reinterpret_cast<CallbackHelper*>(&callbacks_), 204 NewCallback(reinterpret_cast<CallbackHelper*>(&callbacks_),
199 &CallbackHelper::OnStart)); 205 &CallbackHelper::OnStart));
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
281 pipeline_->GetVideoSize(&width, &height); 287 pipeline_->GetVideoSize(&width, &height);
282 EXPECT_EQ(0u, width); 288 EXPECT_EQ(0u, width);
283 EXPECT_EQ(0u, height); 289 EXPECT_EQ(0u, height);
284 290
285 EXPECT_EQ(PIPELINE_OK, pipeline_->GetError()); 291 EXPECT_EQ(PIPELINE_OK, pipeline_->GetError());
286 } 292 }
287 293
288 TEST_F(PipelineImplTest, NeverInitializes) { 294 TEST_F(PipelineImplTest, NeverInitializes) {
289 EXPECT_CALL(*mocks_->data_source(), Initialize("", NotNull())) 295 EXPECT_CALL(*mocks_->data_source(), Initialize("", NotNull()))
290 .WillOnce(Invoke(&DestroyFilterCallback)); 296 .WillOnce(Invoke(&DestroyFilterCallback));
291 EXPECT_CALL(*mocks_->data_source(), Stop()); 297 EXPECT_CALL(*mocks_->data_source(), Stop(NotNull()))
298 .WillOnce(Invoke(&RunStopFilterCallback));
292 299
293 // This test hangs during initialization by never calling 300 // This test hangs during initialization by never calling
294 // InitializationComplete(). StrictMock<> will ensure that the callback is 301 // InitializationComplete(). StrictMock<> will ensure that the callback is
295 // never executed. 302 // never executed.
296 pipeline_->Start(mocks_, "", 303 pipeline_->Start(mocks_, "",
297 NewCallback(reinterpret_cast<CallbackHelper*>(&callbacks_), 304 NewCallback(reinterpret_cast<CallbackHelper*>(&callbacks_),
298 &CallbackHelper::OnStart)); 305 &CallbackHelper::OnStart));
299 message_loop_.RunAllPending(); 306 message_loop_.RunAllPending();
300 307
301 EXPECT_FALSE(pipeline_->IsInitialized()); 308 EXPECT_FALSE(pipeline_->IsInitialized());
(...skipping 15 matching lines...) Expand all
317 EXPECT_EQ(PIPELINE_ERROR_REQUIRED_FILTER_MISSING, 324 EXPECT_EQ(PIPELINE_ERROR_REQUIRED_FILTER_MISSING,
318 pipeline_->GetError()); 325 pipeline_->GetError());
319 } 326 }
320 327
321 TEST_F(PipelineImplTest, URLNotFound) { 328 TEST_F(PipelineImplTest, URLNotFound) {
322 EXPECT_CALL(*mocks_->data_source(), Initialize("", NotNull())) 329 EXPECT_CALL(*mocks_->data_source(), Initialize("", NotNull()))
323 .WillOnce(DoAll(SetError(mocks_->data_source(), 330 .WillOnce(DoAll(SetError(mocks_->data_source(),
324 PIPELINE_ERROR_URL_NOT_FOUND), 331 PIPELINE_ERROR_URL_NOT_FOUND),
325 Invoke(&RunFilterCallback))); 332 Invoke(&RunFilterCallback)));
326 EXPECT_CALL(callbacks_, OnError()); 333 EXPECT_CALL(callbacks_, OnError());
327 EXPECT_CALL(*mocks_->data_source(), Stop()); 334 EXPECT_CALL(*mocks_->data_source(), Stop(NotNull()))
335 .WillOnce(Invoke(&RunStopFilterCallback));
328 336
329 InitializePipeline(); 337 InitializePipeline();
330 EXPECT_FALSE(pipeline_->IsInitialized()); 338 EXPECT_FALSE(pipeline_->IsInitialized());
331 EXPECT_EQ(PIPELINE_ERROR_URL_NOT_FOUND, pipeline_->GetError()); 339 EXPECT_EQ(PIPELINE_ERROR_URL_NOT_FOUND, pipeline_->GetError());
332 } 340 }
333 341
334 TEST_F(PipelineImplTest, NoStreams) { 342 TEST_F(PipelineImplTest, NoStreams) {
335 // Manually set these expectations because SetPlaybackRate() is not called if 343 // Manually set these expectations because SetPlaybackRate() is not called if
336 // we cannot fully initialize the pipeline. 344 // we cannot fully initialize the pipeline.
337 EXPECT_CALL(*mocks_->data_source(), Initialize("", NotNull())) 345 EXPECT_CALL(*mocks_->data_source(), Initialize("", NotNull()))
338 .WillOnce(Invoke(&RunFilterCallback)); 346 .WillOnce(Invoke(&RunFilterCallback));
339 EXPECT_CALL(*mocks_->data_source(), Stop()); 347 EXPECT_CALL(*mocks_->data_source(), Stop(NotNull()))
348 .WillOnce(Invoke(&RunStopFilterCallback));
340 EXPECT_CALL(*mocks_->data_source(), media_format()) 349 EXPECT_CALL(*mocks_->data_source(), media_format())
341 .WillOnce(ReturnRef(data_source_media_format_)); 350 .WillOnce(ReturnRef(data_source_media_format_));
342 351
343 EXPECT_CALL(*mocks_->demuxer(), Initialize(mocks_->data_source(), NotNull())) 352 EXPECT_CALL(*mocks_->demuxer(), Initialize(mocks_->data_source(), NotNull()))
344 .WillOnce(Invoke(&RunFilterCallback)); 353 .WillOnce(Invoke(&RunFilterCallback));
345 EXPECT_CALL(*mocks_->demuxer(), GetNumberOfStreams()) 354 EXPECT_CALL(*mocks_->demuxer(), GetNumberOfStreams())
346 .WillRepeatedly(Return(0)); 355 .WillRepeatedly(Return(0));
347 EXPECT_CALL(*mocks_->demuxer(), Stop()); 356 EXPECT_CALL(*mocks_->demuxer(), Stop(NotNull()))
357 .WillOnce(Invoke(&RunStopFilterCallback));
348 EXPECT_CALL(callbacks_, OnError()); 358 EXPECT_CALL(callbacks_, OnError());
349 359
350 InitializePipeline(); 360 InitializePipeline();
351 EXPECT_FALSE(pipeline_->IsInitialized()); 361 EXPECT_FALSE(pipeline_->IsInitialized());
352 EXPECT_EQ(PIPELINE_ERROR_COULD_NOT_RENDER, pipeline_->GetError()); 362 EXPECT_EQ(PIPELINE_ERROR_COULD_NOT_RENDER, pipeline_->GetError());
353 } 363 }
354 364
355 TEST_F(PipelineImplTest, AudioStream) { 365 TEST_F(PipelineImplTest, AudioStream) {
356 CreateAudioStream(); 366 CreateAudioStream();
357 MockDemuxerStreamVector streams; 367 MockDemuxerStreamVector streams;
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after
567 577
568 EXPECT_CALL(*mocks_->audio_renderer(), HasEnded()) 578 EXPECT_CALL(*mocks_->audio_renderer(), HasEnded())
569 .WillOnce(Return(true)); 579 .WillOnce(Return(true));
570 EXPECT_CALL(*mocks_->video_renderer(), HasEnded()) 580 EXPECT_CALL(*mocks_->video_renderer(), HasEnded())
571 .WillOnce(Return(true)); 581 .WillOnce(Return(true));
572 EXPECT_CALL(callbacks_, OnEnded()); 582 EXPECT_CALL(callbacks_, OnEnded());
573 host->NotifyEnded(); 583 host->NotifyEnded();
574 } 584 }
575 585
576 } // namespace media 586 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698