OLD | NEW |
1 // Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2009 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/waitable_event.h" | 7 #include "base/waitable_event.h" |
8 #include "media/base/pipeline_impl.h" | 8 #include "media/base/pipeline_impl.h" |
9 #include "media/base/media_format.h" | 9 #include "media/base/media_format.h" |
10 #include "media/base/filters.h" | 10 #include "media/base/filters.h" |
11 #include "media/base/factory.h" | 11 #include "media/base/factory.h" |
12 #include "media/base/filter_host.h" | 12 #include "media/base/filter_host.h" |
13 #include "media/base/mock_filters.h" | 13 #include "media/base/mock_filters.h" |
14 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
15 | 15 |
16 using ::testing::DoAll; | 16 using ::testing::DoAll; |
| 17 using ::testing::Invoke; |
17 using ::testing::Mock; | 18 using ::testing::Mock; |
| 19 using ::testing::NotNull; |
18 using ::testing::Return; | 20 using ::testing::Return; |
19 using ::testing::StrictMock; | 21 using ::testing::StrictMock; |
20 | 22 |
21 namespace media { | 23 namespace media { |
22 | 24 |
23 // Used for setting expectations on pipeline callbacks. Using a StrictMock | 25 // Used for setting expectations on pipeline callbacks. Using a StrictMock |
24 // also lets us test for missing callbacks. | 26 // also lets us test for missing callbacks. |
25 class CallbackHelper { | 27 class CallbackHelper { |
26 public: | 28 public: |
27 CallbackHelper() {} | 29 CallbackHelper() {} |
(...skipping 28 matching lines...) Expand all Loading... |
56 // Expect a stop callback if we were started. | 58 // Expect a stop callback if we were started. |
57 EXPECT_CALL(callbacks_, OnStop()); | 59 EXPECT_CALL(callbacks_, OnStop()); |
58 pipeline_.Stop(NewCallback(reinterpret_cast<CallbackHelper*>(&callbacks_), | 60 pipeline_.Stop(NewCallback(reinterpret_cast<CallbackHelper*>(&callbacks_), |
59 &CallbackHelper::OnStop)); | 61 &CallbackHelper::OnStop)); |
60 message_loop_.RunAllPending(); | 62 message_loop_.RunAllPending(); |
61 } | 63 } |
62 | 64 |
63 protected: | 65 protected: |
64 // Sets up expectations to allow the data source to initialize. | 66 // Sets up expectations to allow the data source to initialize. |
65 void InitializeDataSource() { | 67 void InitializeDataSource() { |
66 EXPECT_CALL(*mocks_->data_source(), Initialize("")) | 68 EXPECT_CALL(*mocks_->data_source(), Initialize("", NotNull())) |
67 .WillOnce(DoAll(InitializationComplete(mocks_->data_source()), | 69 .WillOnce(Invoke(&RunFilterCallback)); |
68 Return(true))); | |
69 EXPECT_CALL(*mocks_->data_source(), SetPlaybackRate(0.0f)); | 70 EXPECT_CALL(*mocks_->data_source(), SetPlaybackRate(0.0f)); |
70 EXPECT_CALL(*mocks_->data_source(), Stop()); | 71 EXPECT_CALL(*mocks_->data_source(), Stop()); |
71 } | 72 } |
72 | 73 |
73 // Sets up expectations to allow the demuxer to initialize. | 74 // Sets up expectations to allow the demuxer to initialize. |
74 typedef std::vector<MockDemuxerStream*> MockDemuxerStreamVector; | 75 typedef std::vector<MockDemuxerStream*> MockDemuxerStreamVector; |
75 void InitializeDemuxer(MockDemuxerStreamVector* streams) { | 76 void InitializeDemuxer(MockDemuxerStreamVector* streams) { |
76 EXPECT_CALL(*mocks_->demuxer(), Initialize(mocks_->data_source())) | 77 EXPECT_CALL(*mocks_->demuxer(), |
77 .WillOnce(DoAll(InitializationComplete(mocks_->demuxer()), | 78 Initialize(mocks_->data_source(), NotNull())) |
78 Return(true))); | 79 .WillOnce(Invoke(&RunFilterCallback)); |
79 EXPECT_CALL(*mocks_->demuxer(), GetNumberOfStreams()) | 80 EXPECT_CALL(*mocks_->demuxer(), GetNumberOfStreams()) |
80 .WillRepeatedly(Return(streams->size())); | 81 .WillRepeatedly(Return(streams->size())); |
81 EXPECT_CALL(*mocks_->demuxer(), SetPlaybackRate(0.0f)); | 82 EXPECT_CALL(*mocks_->demuxer(), SetPlaybackRate(0.0f)); |
82 EXPECT_CALL(*mocks_->demuxer(), Stop()); | 83 EXPECT_CALL(*mocks_->demuxer(), Stop()); |
83 | 84 |
84 // Configure the demuxer to return the streams. | 85 // Configure the demuxer to return the streams. |
85 for (size_t i = 0; i < streams->size(); ++i) { | 86 for (size_t i = 0; i < streams->size(); ++i) { |
86 scoped_refptr<DemuxerStream> stream = (*streams)[i]; | 87 scoped_refptr<DemuxerStream> stream = (*streams)[i]; |
87 EXPECT_CALL(*mocks_->demuxer(), GetStream(i)) | 88 EXPECT_CALL(*mocks_->demuxer(), GetStream(i)) |
88 .WillRepeatedly(Return(stream)); | 89 .WillRepeatedly(Return(stream)); |
89 } | 90 } |
90 } | 91 } |
91 | 92 |
92 // Sets up expectations to allow the video decoder to initialize. | 93 // Sets up expectations to allow the video decoder to initialize. |
93 void InitializeVideoDecoder(MockDemuxerStream* stream) { | 94 void InitializeVideoDecoder(MockDemuxerStream* stream) { |
94 EXPECT_CALL(*mocks_->video_decoder(), Initialize(stream)) | 95 EXPECT_CALL(*mocks_->video_decoder(), Initialize(stream, NotNull())) |
95 .WillOnce(DoAll(InitializationComplete(mocks_->video_decoder()), | 96 .WillOnce(Invoke(&RunFilterCallback)); |
96 Return(true))); | |
97 EXPECT_CALL(*mocks_->video_decoder(), SetPlaybackRate(0.0f)); | 97 EXPECT_CALL(*mocks_->video_decoder(), SetPlaybackRate(0.0f)); |
98 EXPECT_CALL(*mocks_->video_decoder(), Stop()); | 98 EXPECT_CALL(*mocks_->video_decoder(), Stop()); |
99 } | 99 } |
100 | 100 |
101 // Sets up expectations to allow the audio decoder to initialize. | 101 // Sets up expectations to allow the audio decoder to initialize. |
102 void InitializeAudioDecoder(MockDemuxerStream* stream) { | 102 void InitializeAudioDecoder(MockDemuxerStream* stream) { |
103 EXPECT_CALL(*mocks_->audio_decoder(), Initialize(stream)) | 103 EXPECT_CALL(*mocks_->audio_decoder(), Initialize(stream, NotNull())) |
104 .WillOnce(DoAll(InitializationComplete(mocks_->audio_decoder()), | 104 .WillOnce(Invoke(&RunFilterCallback)); |
105 Return(true))); | |
106 EXPECT_CALL(*mocks_->audio_decoder(), SetPlaybackRate(0.0f)); | 105 EXPECT_CALL(*mocks_->audio_decoder(), SetPlaybackRate(0.0f)); |
107 EXPECT_CALL(*mocks_->audio_decoder(), Stop()); | 106 EXPECT_CALL(*mocks_->audio_decoder(), Stop()); |
108 } | 107 } |
109 | 108 |
110 // Sets up expectations to allow the video renderer to initialize. | 109 // Sets up expectations to allow the video renderer to initialize. |
111 void InitializeVideoRenderer() { | 110 void InitializeVideoRenderer() { |
112 EXPECT_CALL(*mocks_->video_renderer(), Initialize(mocks_->video_decoder())) | 111 EXPECT_CALL(*mocks_->video_renderer(), |
113 .WillOnce(DoAll(InitializationComplete(mocks_->video_renderer()), | 112 Initialize(mocks_->video_decoder(), NotNull())) |
114 Return(true))); | 113 .WillOnce(Invoke(&RunFilterCallback)); |
115 EXPECT_CALL(*mocks_->video_renderer(), SetPlaybackRate(0.0f)); | 114 EXPECT_CALL(*mocks_->video_renderer(), SetPlaybackRate(0.0f)); |
116 EXPECT_CALL(*mocks_->video_renderer(), Stop()); | 115 EXPECT_CALL(*mocks_->video_renderer(), Stop()); |
117 } | 116 } |
118 | 117 |
119 // Sets up expectations to allow the audio renderer to initialize. | 118 // Sets up expectations to allow the audio renderer to initialize. |
120 void InitializeAudioRenderer() { | 119 void InitializeAudioRenderer() { |
121 EXPECT_CALL(*mocks_->audio_renderer(), Initialize(mocks_->audio_decoder())) | 120 EXPECT_CALL(*mocks_->audio_renderer(), |
122 .WillOnce(DoAll(InitializationComplete(mocks_->audio_renderer()), | 121 Initialize(mocks_->audio_decoder(), NotNull())) |
123 Return(true))); | 122 .WillOnce(Invoke(&RunFilterCallback)); |
124 EXPECT_CALL(*mocks_->audio_renderer(), SetPlaybackRate(0.0f)); | 123 EXPECT_CALL(*mocks_->audio_renderer(), SetPlaybackRate(0.0f)); |
125 EXPECT_CALL(*mocks_->audio_renderer(), SetVolume(1.0f)); | 124 EXPECT_CALL(*mocks_->audio_renderer(), SetVolume(1.0f)); |
126 EXPECT_CALL(*mocks_->audio_renderer(), Stop()); | 125 EXPECT_CALL(*mocks_->audio_renderer(), Stop()); |
127 } | 126 } |
128 | 127 |
129 // Sets up expectations on the callback and initializes the pipeline. Called | 128 // Sets up expectations on the callback and initializes the pipeline. Called |
130 // afters tests have set expectations any filters they wish to use. | 129 // afters tests have set expectations any filters they wish to use. |
131 void InitializePipeline( ) { | 130 void InitializePipeline() { |
132 // Expect an initialization callback. | 131 // Expect an initialization callback. |
133 EXPECT_CALL(callbacks_, OnStart()); | 132 EXPECT_CALL(callbacks_, OnStart()); |
134 pipeline_.Start(mocks_, "", | 133 pipeline_.Start(mocks_, "", |
135 NewCallback(reinterpret_cast<CallbackHelper*>(&callbacks_), | 134 NewCallback(reinterpret_cast<CallbackHelper*>(&callbacks_), |
136 &CallbackHelper::OnStart)); | 135 &CallbackHelper::OnStart)); |
137 message_loop_.RunAllPending(); | 136 message_loop_.RunAllPending(); |
138 } | 137 } |
139 | 138 |
140 // Fixture members. | 139 // Fixture members. |
141 StrictMock<CallbackHelper> callbacks_; | 140 StrictMock<CallbackHelper> callbacks_; |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
194 size_t width = 1u; | 193 size_t width = 1u; |
195 size_t height = 1u; | 194 size_t height = 1u; |
196 pipeline_.GetVideoSize(&width, &height); | 195 pipeline_.GetVideoSize(&width, &height); |
197 EXPECT_EQ(0u, width); | 196 EXPECT_EQ(0u, width); |
198 EXPECT_EQ(0u, height); | 197 EXPECT_EQ(0u, height); |
199 | 198 |
200 EXPECT_EQ(PIPELINE_OK, pipeline_.GetError()); | 199 EXPECT_EQ(PIPELINE_OK, pipeline_.GetError()); |
201 } | 200 } |
202 | 201 |
203 TEST_F(PipelineImplTest, NeverInitializes) { | 202 TEST_F(PipelineImplTest, NeverInitializes) { |
204 EXPECT_CALL(*mocks_->data_source(), Initialize("")) | 203 EXPECT_CALL(*mocks_->data_source(), Initialize("", NotNull())) |
205 .WillOnce(Return(true)); | 204 .WillOnce(Invoke(&DestroyFilterCallback)); |
206 EXPECT_CALL(*mocks_->data_source(), Stop()); | 205 EXPECT_CALL(*mocks_->data_source(), Stop()); |
207 | 206 |
208 // This test hangs during initialization by never calling | 207 // This test hangs during initialization by never calling |
209 // InitializationComplete(). StrictMock<> will ensure that the callback is | 208 // InitializationComplete(). StrictMock<> will ensure that the callback is |
210 // never executed. | 209 // never executed. |
211 pipeline_.Start(mocks_, "", | 210 pipeline_.Start(mocks_, "", |
212 NewCallback(reinterpret_cast<CallbackHelper*>(&callbacks_), | 211 NewCallback(reinterpret_cast<CallbackHelper*>(&callbacks_), |
213 &CallbackHelper::OnStart)); | 212 &CallbackHelper::OnStart)); |
214 message_loop_.RunAllPending(); | 213 message_loop_.RunAllPending(); |
215 | 214 |
(...skipping 10 matching lines...) Expand all Loading... |
226 TEST_F(PipelineImplTest, RequiredFilterMissing) { | 225 TEST_F(PipelineImplTest, RequiredFilterMissing) { |
227 mocks_->set_creation_successful(false); | 226 mocks_->set_creation_successful(false); |
228 | 227 |
229 InitializePipeline(); | 228 InitializePipeline(); |
230 EXPECT_FALSE(pipeline_.IsInitialized()); | 229 EXPECT_FALSE(pipeline_.IsInitialized()); |
231 EXPECT_EQ(PIPELINE_ERROR_REQUIRED_FILTER_MISSING, | 230 EXPECT_EQ(PIPELINE_ERROR_REQUIRED_FILTER_MISSING, |
232 pipeline_.GetError()); | 231 pipeline_.GetError()); |
233 } | 232 } |
234 | 233 |
235 TEST_F(PipelineImplTest, URLNotFound) { | 234 TEST_F(PipelineImplTest, URLNotFound) { |
236 EXPECT_CALL(*mocks_->data_source(), Initialize("")) | 235 EXPECT_CALL(*mocks_->data_source(), Initialize("", NotNull())) |
237 .WillOnce(DoAll(Error(mocks_->data_source(), | 236 .WillOnce(DoAll(Error(mocks_->data_source(), |
238 PIPELINE_ERROR_URL_NOT_FOUND), | 237 PIPELINE_ERROR_URL_NOT_FOUND), |
239 Return(false))); | 238 Invoke(&RunFilterCallback))); |
240 EXPECT_CALL(*mocks_->data_source(), Stop()); | 239 EXPECT_CALL(*mocks_->data_source(), Stop()); |
241 | 240 |
242 InitializePipeline(); | 241 InitializePipeline(); |
243 EXPECT_FALSE(pipeline_.IsInitialized()); | 242 EXPECT_FALSE(pipeline_.IsInitialized()); |
244 EXPECT_EQ(PIPELINE_ERROR_URL_NOT_FOUND, pipeline_.GetError()); | 243 EXPECT_EQ(PIPELINE_ERROR_URL_NOT_FOUND, pipeline_.GetError()); |
245 } | 244 } |
246 | 245 |
247 TEST_F(PipelineImplTest, NoStreams) { | 246 TEST_F(PipelineImplTest, NoStreams) { |
248 // Manually set these expecations because SetPlaybackRate() is not called if | 247 // Manually set these expecations because SetPlaybackRate() is not called if |
249 // we cannot fully initialize the pipeline. | 248 // we cannot fully initialize the pipeline. |
250 EXPECT_CALL(*mocks_->data_source(), Initialize("")) | 249 EXPECT_CALL(*mocks_->data_source(), Initialize("", NotNull())) |
251 .WillOnce(DoAll(InitializationComplete(mocks_->data_source()), | 250 .WillOnce(Invoke(&RunFilterCallback)); |
252 Return(true))); | |
253 EXPECT_CALL(*mocks_->data_source(), Stop()); | 251 EXPECT_CALL(*mocks_->data_source(), Stop()); |
254 | 252 |
255 EXPECT_CALL(*mocks_->demuxer(), Initialize(mocks_->data_source())) | 253 EXPECT_CALL(*mocks_->demuxer(), Initialize(mocks_->data_source(), NotNull())) |
256 .WillOnce(DoAll(InitializationComplete(mocks_->demuxer()), | 254 .WillOnce(Invoke(&RunFilterCallback)); |
257 Return(true))); | |
258 EXPECT_CALL(*mocks_->demuxer(), GetNumberOfStreams()) | 255 EXPECT_CALL(*mocks_->demuxer(), GetNumberOfStreams()) |
259 .WillRepeatedly(Return(0)); | 256 .WillRepeatedly(Return(0)); |
260 EXPECT_CALL(*mocks_->demuxer(), Stop()); | 257 EXPECT_CALL(*mocks_->demuxer(), Stop()); |
261 | 258 |
262 InitializePipeline(); | 259 InitializePipeline(); |
263 EXPECT_FALSE(pipeline_.IsInitialized()); | 260 EXPECT_FALSE(pipeline_.IsInitialized()); |
264 EXPECT_EQ(PIPELINE_ERROR_COULD_NOT_RENDER, pipeline_.GetError()); | 261 EXPECT_EQ(PIPELINE_ERROR_COULD_NOT_RENDER, pipeline_.GetError()); |
265 } | 262 } |
266 | 263 |
267 TEST_F(PipelineImplTest, AudioStream) { | 264 TEST_F(PipelineImplTest, AudioStream) { |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
334 | 331 |
335 InitializeDataSource(); | 332 InitializeDataSource(); |
336 InitializeDemuxer(&streams); | 333 InitializeDemuxer(&streams); |
337 InitializeAudioDecoder(audio_stream); | 334 InitializeAudioDecoder(audio_stream); |
338 InitializeAudioRenderer(); | 335 InitializeAudioRenderer(); |
339 InitializeVideoDecoder(video_stream); | 336 InitializeVideoDecoder(video_stream); |
340 InitializeVideoRenderer(); | 337 InitializeVideoRenderer(); |
341 | 338 |
342 // Every filter should receive a call to Seek(). | 339 // Every filter should receive a call to Seek(). |
343 base::TimeDelta expected = base::TimeDelta::FromSeconds(2000); | 340 base::TimeDelta expected = base::TimeDelta::FromSeconds(2000); |
344 EXPECT_CALL(*mocks_->data_source(), Seek(expected)); | 341 EXPECT_CALL(*mocks_->data_source(), Seek(expected, NotNull())) |
345 EXPECT_CALL(*mocks_->demuxer(), Seek(expected)); | 342 .WillOnce(Invoke(&RunFilterCallback)); |
346 EXPECT_CALL(*mocks_->audio_decoder(), Seek(expected)); | 343 EXPECT_CALL(*mocks_->demuxer(), Seek(expected, NotNull())) |
347 EXPECT_CALL(*mocks_->audio_renderer(), Seek(expected)); | 344 .WillOnce(Invoke(&RunFilterCallback)); |
348 EXPECT_CALL(*mocks_->video_decoder(), Seek(expected)); | 345 EXPECT_CALL(*mocks_->audio_decoder(), Seek(expected, NotNull())) |
349 EXPECT_CALL(*mocks_->video_renderer(), Seek(expected)); | 346 .WillOnce(Invoke(&RunFilterCallback)); |
| 347 EXPECT_CALL(*mocks_->audio_renderer(), Seek(expected, NotNull())) |
| 348 .WillOnce(Invoke(&RunFilterCallback)); |
| 349 EXPECT_CALL(*mocks_->video_decoder(), Seek(expected, NotNull())) |
| 350 .WillOnce(Invoke(&RunFilterCallback)); |
| 351 EXPECT_CALL(*mocks_->video_renderer(), Seek(expected, NotNull())) |
| 352 .WillOnce(Invoke(&RunFilterCallback)); |
350 | 353 |
351 // We expect a successful seek callback. | 354 // We expect a successful seek callback. |
352 EXPECT_CALL(callbacks_, OnSeek()); | 355 EXPECT_CALL(callbacks_, OnSeek()); |
353 | 356 |
354 // Initialize then seek! | 357 // Initialize then seek! |
355 InitializePipeline(); | 358 InitializePipeline(); |
356 pipeline_.Seek(expected, | 359 pipeline_.Seek(expected, |
357 NewCallback(reinterpret_cast<CallbackHelper*>(&callbacks_), | 360 NewCallback(reinterpret_cast<CallbackHelper*>(&callbacks_), |
358 &CallbackHelper::OnSeek)); | 361 &CallbackHelper::OnSeek)); |
359 message_loop_.RunAllPending(); | 362 message_loop_.RunAllPending(); |
(...skipping 13 matching lines...) Expand all Loading... |
373 // The audio renderer should receive a call to SetVolume(). | 376 // The audio renderer should receive a call to SetVolume(). |
374 float expected = 0.5f; | 377 float expected = 0.5f; |
375 EXPECT_CALL(*mocks_->audio_renderer(), SetVolume(expected)); | 378 EXPECT_CALL(*mocks_->audio_renderer(), SetVolume(expected)); |
376 | 379 |
377 // Initialize then set volume! | 380 // Initialize then set volume! |
378 InitializePipeline(); | 381 InitializePipeline(); |
379 pipeline_.SetVolume(expected); | 382 pipeline_.SetVolume(expected); |
380 } | 383 } |
381 | 384 |
382 } // namespace media | 385 } // namespace media |
OLD | NEW |