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/message_loop/message_loop.h" | 7 #include "base/message_loop/message_loop.h" |
8 #include "base/run_loop.h" | 8 #include "base/run_loop.h" |
9 #include "media/audio/audio_manager.h" | 9 #include "media/audio/audio_manager.h" |
10 #include "media/audio/audio_manager_base.h" | 10 #include "media/audio/audio_manager_base.h" |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
86 class MockAudioManager : public AudioManagerBase { | 86 class MockAudioManager : public AudioManagerBase { |
87 public: | 87 public: |
88 MockAudioManager() : AudioManagerBase(&fake_audio_log_factory_) {} | 88 MockAudioManager() : AudioManagerBase(&fake_audio_log_factory_) {} |
89 virtual ~MockAudioManager() { | 89 virtual ~MockAudioManager() { |
90 Shutdown(); | 90 Shutdown(); |
91 } | 91 } |
92 | 92 |
93 MOCK_METHOD0(HasAudioOutputDevices, bool()); | 93 MOCK_METHOD0(HasAudioOutputDevices, bool()); |
94 MOCK_METHOD0(HasAudioInputDevices, bool()); | 94 MOCK_METHOD0(HasAudioInputDevices, bool()); |
95 MOCK_METHOD0(GetAudioInputDeviceModel, base::string16()); | 95 MOCK_METHOD0(GetAudioInputDeviceModel, base::string16()); |
96 MOCK_METHOD3(MakeAudioOutputStream, AudioOutputStream*( | 96 MOCK_METHOD2(MakeAudioOutputStream, AudioOutputStream*( |
97 const AudioParameters& params, | 97 const AudioParameters& params, |
98 const std::string& device_id, | 98 const std::string& device_id)); |
99 const std::string& input_device_id)); | 99 MOCK_METHOD2(MakeAudioOutputStreamProxy, AudioOutputStream*( |
100 MOCK_METHOD3(MakeAudioOutputStreamProxy, AudioOutputStream*( | |
101 const AudioParameters& params, | 100 const AudioParameters& params, |
102 const std::string& device_id, | 101 const std::string& device_id)); |
103 const std::string& input_device_id)); | |
104 MOCK_METHOD2(MakeAudioInputStream, AudioInputStream*( | 102 MOCK_METHOD2(MakeAudioInputStream, AudioInputStream*( |
105 const AudioParameters& params, const std::string& device_id)); | 103 const AudioParameters& params, const std::string& device_id)); |
106 MOCK_METHOD0(ShowAudioInputSettings, void()); | 104 MOCK_METHOD0(ShowAudioInputSettings, void()); |
107 MOCK_METHOD0(GetTaskRunner, scoped_refptr<base::SingleThreadTaskRunner>()); | 105 MOCK_METHOD0(GetTaskRunner, scoped_refptr<base::SingleThreadTaskRunner>()); |
108 MOCK_METHOD0(GetWorkerTaskRunner, | 106 MOCK_METHOD0(GetWorkerTaskRunner, |
109 scoped_refptr<base::SingleThreadTaskRunner>()); | 107 scoped_refptr<base::SingleThreadTaskRunner>()); |
110 MOCK_METHOD1(GetAudioInputDeviceNames, void( | 108 MOCK_METHOD1(GetAudioInputDeviceNames, void( |
111 media::AudioDeviceNames* device_name)); | 109 media::AudioDeviceNames* device_name)); |
112 | 110 |
113 MOCK_METHOD1(MakeLinearOutputStream, AudioOutputStream*( | 111 MOCK_METHOD1(MakeLinearOutputStream, AudioOutputStream*( |
114 const AudioParameters& params)); | 112 const AudioParameters& params)); |
115 MOCK_METHOD3(MakeLowLatencyOutputStream, AudioOutputStream*( | 113 MOCK_METHOD2(MakeLowLatencyOutputStream, AudioOutputStream*( |
116 const AudioParameters& params, const std::string& device_id, | 114 const AudioParameters& params, const std::string& device_id)); |
117 const std::string& input_device_id)); | |
118 MOCK_METHOD2(MakeLinearInputStream, AudioInputStream*( | 115 MOCK_METHOD2(MakeLinearInputStream, AudioInputStream*( |
119 const AudioParameters& params, const std::string& device_id)); | 116 const AudioParameters& params, const std::string& device_id)); |
120 MOCK_METHOD2(MakeLowLatencyInputStream, AudioInputStream*( | 117 MOCK_METHOD2(MakeLowLatencyInputStream, AudioInputStream*( |
121 const AudioParameters& params, const std::string& device_id)); | 118 const AudioParameters& params, const std::string& device_id)); |
122 MOCK_METHOD2(GetPreferredOutputStreamParameters, AudioParameters( | 119 MOCK_METHOD2(GetPreferredOutputStreamParameters, AudioParameters( |
123 const std::string& device_id, const AudioParameters& params)); | 120 const std::string& device_id, const AudioParameters& params)); |
124 | 121 |
125 private: | 122 private: |
126 media::FakeAudioLogFactory fake_audio_log_factory_; | 123 media::FakeAudioLogFactory fake_audio_log_factory_; |
127 }; | 124 }; |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
161 virtual void TearDown() { | 158 virtual void TearDown() { |
162 // This is necessary to free all proxy objects that have been | 159 // This is necessary to free all proxy objects that have been |
163 // closed by the test. | 160 // closed by the test. |
164 message_loop_.RunUntilIdle(); | 161 message_loop_.RunUntilIdle(); |
165 } | 162 } |
166 | 163 |
167 virtual void InitDispatcher(base::TimeDelta close_delay) { | 164 virtual void InitDispatcher(base::TimeDelta close_delay) { |
168 dispatcher_impl_ = new AudioOutputDispatcherImpl(&manager(), | 165 dispatcher_impl_ = new AudioOutputDispatcherImpl(&manager(), |
169 params_, | 166 params_, |
170 std::string(), | 167 std::string(), |
171 std::string(), | |
172 close_delay); | 168 close_delay); |
173 } | 169 } |
174 | 170 |
175 virtual void OnStart() {} | 171 virtual void OnStart() {} |
176 | 172 |
177 MockAudioManager& manager() { | 173 MockAudioManager& manager() { |
178 return manager_; | 174 return manager_; |
179 } | 175 } |
180 | 176 |
181 void WaitForCloseTimer(MockAudioOutputStream* stream) { | 177 void WaitForCloseTimer(MockAudioOutputStream* stream) { |
(...skipping 10 matching lines...) Expand all Loading... |
192 Mock::VerifyAndClear(stream); | 188 Mock::VerifyAndClear(stream); |
193 | 189 |
194 // Wait for the actual close event to come from the close timer. | 190 // Wait for the actual close event to come from the close timer. |
195 WaitForCloseTimer(stream); | 191 WaitForCloseTimer(stream); |
196 } | 192 } |
197 | 193 |
198 // Basic Open() and Close() test. | 194 // Basic Open() and Close() test. |
199 void OpenAndClose(AudioOutputDispatcher* dispatcher) { | 195 void OpenAndClose(AudioOutputDispatcher* dispatcher) { |
200 MockAudioOutputStream stream(&manager_, params_); | 196 MockAudioOutputStream stream(&manager_, params_); |
201 | 197 |
202 EXPECT_CALL(manager(), MakeAudioOutputStream(_, _, _)) | 198 EXPECT_CALL(manager(), MakeAudioOutputStream(_, _)) |
203 .WillOnce(Return(&stream)); | 199 .WillOnce(Return(&stream)); |
204 EXPECT_CALL(stream, Open()) | 200 EXPECT_CALL(stream, Open()) |
205 .WillOnce(Return(true)); | 201 .WillOnce(Return(true)); |
206 | 202 |
207 AudioOutputProxy* proxy = new AudioOutputProxy(dispatcher); | 203 AudioOutputProxy* proxy = new AudioOutputProxy(dispatcher); |
208 EXPECT_TRUE(proxy->Open()); | 204 EXPECT_TRUE(proxy->Open()); |
209 CloseAndWaitForCloseTimer(proxy, &stream); | 205 CloseAndWaitForCloseTimer(proxy, &stream); |
210 } | 206 } |
211 | 207 |
212 // Creates a stream, and then calls Start() and Stop(). | 208 // Creates a stream, and then calls Start() and Stop(). |
213 void StartAndStop(AudioOutputDispatcher* dispatcher) { | 209 void StartAndStop(AudioOutputDispatcher* dispatcher) { |
214 MockAudioOutputStream stream(&manager_, params_); | 210 MockAudioOutputStream stream(&manager_, params_); |
215 | 211 |
216 EXPECT_CALL(manager(), MakeAudioOutputStream(_, _, _)) | 212 EXPECT_CALL(manager(), MakeAudioOutputStream(_, _)) |
217 .WillOnce(Return(&stream)); | 213 .WillOnce(Return(&stream)); |
218 EXPECT_CALL(stream, Open()) | 214 EXPECT_CALL(stream, Open()) |
219 .WillOnce(Return(true)); | 215 .WillOnce(Return(true)); |
220 EXPECT_CALL(stream, SetVolume(_)) | 216 EXPECT_CALL(stream, SetVolume(_)) |
221 .Times(1); | 217 .Times(1); |
222 | 218 |
223 AudioOutputProxy* proxy = new AudioOutputProxy(dispatcher); | 219 AudioOutputProxy* proxy = new AudioOutputProxy(dispatcher); |
224 EXPECT_TRUE(proxy->Open()); | 220 EXPECT_TRUE(proxy->Open()); |
225 | 221 |
226 proxy->Start(&callback_); | 222 proxy->Start(&callback_); |
227 OnStart(); | 223 OnStart(); |
228 proxy->Stop(); | 224 proxy->Stop(); |
229 | 225 |
230 CloseAndWaitForCloseTimer(proxy, &stream); | 226 CloseAndWaitForCloseTimer(proxy, &stream); |
231 EXPECT_TRUE(stream.stop_called()); | 227 EXPECT_TRUE(stream.stop_called()); |
232 EXPECT_TRUE(stream.start_called()); | 228 EXPECT_TRUE(stream.start_called()); |
233 } | 229 } |
234 | 230 |
235 // Verify that the stream is closed after Stop() is called. | 231 // Verify that the stream is closed after Stop() is called. |
236 void CloseAfterStop(AudioOutputDispatcher* dispatcher) { | 232 void CloseAfterStop(AudioOutputDispatcher* dispatcher) { |
237 MockAudioOutputStream stream(&manager_, params_); | 233 MockAudioOutputStream stream(&manager_, params_); |
238 | 234 |
239 EXPECT_CALL(manager(), MakeAudioOutputStream(_, _, _)) | 235 EXPECT_CALL(manager(), MakeAudioOutputStream(_, _)) |
240 .WillOnce(Return(&stream)); | 236 .WillOnce(Return(&stream)); |
241 EXPECT_CALL(stream, Open()) | 237 EXPECT_CALL(stream, Open()) |
242 .WillOnce(Return(true)); | 238 .WillOnce(Return(true)); |
243 EXPECT_CALL(stream, SetVolume(_)) | 239 EXPECT_CALL(stream, SetVolume(_)) |
244 .Times(1); | 240 .Times(1); |
245 | 241 |
246 AudioOutputProxy* proxy = new AudioOutputProxy(dispatcher); | 242 AudioOutputProxy* proxy = new AudioOutputProxy(dispatcher); |
247 EXPECT_TRUE(proxy->Open()); | 243 EXPECT_TRUE(proxy->Open()); |
248 | 244 |
249 proxy->Start(&callback_); | 245 proxy->Start(&callback_); |
250 OnStart(); | 246 OnStart(); |
251 proxy->Stop(); | 247 proxy->Stop(); |
252 | 248 |
253 // Wait for the close timer to fire after StopStream(). | 249 // Wait for the close timer to fire after StopStream(). |
254 WaitForCloseTimer(&stream); | 250 WaitForCloseTimer(&stream); |
255 proxy->Close(); | 251 proxy->Close(); |
256 EXPECT_TRUE(stream.stop_called()); | 252 EXPECT_TRUE(stream.stop_called()); |
257 EXPECT_TRUE(stream.start_called()); | 253 EXPECT_TRUE(stream.start_called()); |
258 } | 254 } |
259 | 255 |
260 // Create two streams, but don't start them. Only one device must be opened. | 256 // Create two streams, but don't start them. Only one device must be opened. |
261 void TwoStreams(AudioOutputDispatcher* dispatcher) { | 257 void TwoStreams(AudioOutputDispatcher* dispatcher) { |
262 MockAudioOutputStream stream(&manager_, params_); | 258 MockAudioOutputStream stream(&manager_, params_); |
263 | 259 |
264 EXPECT_CALL(manager(), MakeAudioOutputStream(_, _, _)) | 260 EXPECT_CALL(manager(), MakeAudioOutputStream(_, _)) |
265 .WillOnce(Return(&stream)); | 261 .WillOnce(Return(&stream)); |
266 EXPECT_CALL(stream, Open()) | 262 EXPECT_CALL(stream, Open()) |
267 .WillOnce(Return(true)); | 263 .WillOnce(Return(true)); |
268 | 264 |
269 AudioOutputProxy* proxy1 = new AudioOutputProxy(dispatcher); | 265 AudioOutputProxy* proxy1 = new AudioOutputProxy(dispatcher); |
270 AudioOutputProxy* proxy2 = new AudioOutputProxy(dispatcher); | 266 AudioOutputProxy* proxy2 = new AudioOutputProxy(dispatcher); |
271 EXPECT_TRUE(proxy1->Open()); | 267 EXPECT_TRUE(proxy1->Open()); |
272 EXPECT_TRUE(proxy2->Open()); | 268 EXPECT_TRUE(proxy2->Open()); |
273 proxy1->Close(); | 269 proxy1->Close(); |
274 CloseAndWaitForCloseTimer(proxy2, &stream); | 270 CloseAndWaitForCloseTimer(proxy2, &stream); |
275 EXPECT_FALSE(stream.stop_called()); | 271 EXPECT_FALSE(stream.stop_called()); |
276 EXPECT_FALSE(stream.start_called()); | 272 EXPECT_FALSE(stream.start_called()); |
277 } | 273 } |
278 | 274 |
279 // Open() method failed. | 275 // Open() method failed. |
280 void OpenFailed(AudioOutputDispatcher* dispatcher) { | 276 void OpenFailed(AudioOutputDispatcher* dispatcher) { |
281 MockAudioOutputStream stream(&manager_, params_); | 277 MockAudioOutputStream stream(&manager_, params_); |
282 | 278 |
283 EXPECT_CALL(manager(), MakeAudioOutputStream(_, _, _)) | 279 EXPECT_CALL(manager(), MakeAudioOutputStream(_, _)) |
284 .WillOnce(Return(&stream)); | 280 .WillOnce(Return(&stream)); |
285 EXPECT_CALL(stream, Open()) | 281 EXPECT_CALL(stream, Open()) |
286 .WillOnce(Return(false)); | 282 .WillOnce(Return(false)); |
287 EXPECT_CALL(stream, Close()) | 283 EXPECT_CALL(stream, Close()) |
288 .Times(1); | 284 .Times(1); |
289 | 285 |
290 AudioOutputProxy* proxy = new AudioOutputProxy(dispatcher); | 286 AudioOutputProxy* proxy = new AudioOutputProxy(dispatcher); |
291 EXPECT_FALSE(proxy->Open()); | 287 EXPECT_FALSE(proxy->Open()); |
292 proxy->Close(); | 288 proxy->Close(); |
293 EXPECT_FALSE(stream.stop_called()); | 289 EXPECT_FALSE(stream.stop_called()); |
294 EXPECT_FALSE(stream.start_called()); | 290 EXPECT_FALSE(stream.start_called()); |
295 } | 291 } |
296 | 292 |
297 void CreateAndWait(AudioOutputDispatcher* dispatcher) { | 293 void CreateAndWait(AudioOutputDispatcher* dispatcher) { |
298 MockAudioOutputStream stream(&manager_, params_); | 294 MockAudioOutputStream stream(&manager_, params_); |
299 | 295 |
300 EXPECT_CALL(manager(), MakeAudioOutputStream(_, _, _)) | 296 EXPECT_CALL(manager(), MakeAudioOutputStream(_, _)) |
301 .WillOnce(Return(&stream)); | 297 .WillOnce(Return(&stream)); |
302 EXPECT_CALL(stream, Open()) | 298 EXPECT_CALL(stream, Open()) |
303 .WillOnce(Return(true)); | 299 .WillOnce(Return(true)); |
304 | 300 |
305 AudioOutputProxy* proxy = new AudioOutputProxy(dispatcher); | 301 AudioOutputProxy* proxy = new AudioOutputProxy(dispatcher); |
306 EXPECT_TRUE(proxy->Open()); | 302 EXPECT_TRUE(proxy->Open()); |
307 | 303 |
308 WaitForCloseTimer(&stream); | 304 WaitForCloseTimer(&stream); |
309 proxy->Close(); | 305 proxy->Close(); |
310 EXPECT_FALSE(stream.stop_called()); | 306 EXPECT_FALSE(stream.stop_called()); |
311 EXPECT_FALSE(stream.start_called()); | 307 EXPECT_FALSE(stream.start_called()); |
312 } | 308 } |
313 | 309 |
314 void OneStream_TwoPlays(AudioOutputDispatcher* dispatcher) { | 310 void OneStream_TwoPlays(AudioOutputDispatcher* dispatcher) { |
315 MockAudioOutputStream stream(&manager_, params_); | 311 MockAudioOutputStream stream(&manager_, params_); |
316 | 312 |
317 EXPECT_CALL(manager(), MakeAudioOutputStream(_, _, _)) | 313 EXPECT_CALL(manager(), MakeAudioOutputStream(_, _)) |
318 .WillOnce(Return(&stream)); | 314 .WillOnce(Return(&stream)); |
319 | 315 |
320 EXPECT_CALL(stream, Open()) | 316 EXPECT_CALL(stream, Open()) |
321 .WillOnce(Return(true)); | 317 .WillOnce(Return(true)); |
322 EXPECT_CALL(stream, SetVolume(_)) | 318 EXPECT_CALL(stream, SetVolume(_)) |
323 .Times(2); | 319 .Times(2); |
324 | 320 |
325 AudioOutputProxy* proxy1 = new AudioOutputProxy(dispatcher); | 321 AudioOutputProxy* proxy1 = new AudioOutputProxy(dispatcher); |
326 EXPECT_TRUE(proxy1->Open()); | 322 EXPECT_TRUE(proxy1->Open()); |
327 | 323 |
(...skipping 11 matching lines...) Expand all Loading... |
339 proxy1->Close(); | 335 proxy1->Close(); |
340 CloseAndWaitForCloseTimer(proxy2, &stream); | 336 CloseAndWaitForCloseTimer(proxy2, &stream); |
341 EXPECT_TRUE(stream.stop_called()); | 337 EXPECT_TRUE(stream.stop_called()); |
342 EXPECT_TRUE(stream.start_called()); | 338 EXPECT_TRUE(stream.start_called()); |
343 } | 339 } |
344 | 340 |
345 void TwoStreams_BothPlaying(AudioOutputDispatcher* dispatcher) { | 341 void TwoStreams_BothPlaying(AudioOutputDispatcher* dispatcher) { |
346 MockAudioOutputStream stream1(&manager_, params_); | 342 MockAudioOutputStream stream1(&manager_, params_); |
347 MockAudioOutputStream stream2(&manager_, params_); | 343 MockAudioOutputStream stream2(&manager_, params_); |
348 | 344 |
349 EXPECT_CALL(manager(), MakeAudioOutputStream(_, _, _)) | 345 EXPECT_CALL(manager(), MakeAudioOutputStream(_, _)) |
350 .WillOnce(Return(&stream1)) | 346 .WillOnce(Return(&stream1)) |
351 .WillOnce(Return(&stream2)); | 347 .WillOnce(Return(&stream2)); |
352 | 348 |
353 EXPECT_CALL(stream1, Open()) | 349 EXPECT_CALL(stream1, Open()) |
354 .WillOnce(Return(true)); | 350 .WillOnce(Return(true)); |
355 EXPECT_CALL(stream1, SetVolume(_)) | 351 EXPECT_CALL(stream1, SetVolume(_)) |
356 .Times(1); | 352 .Times(1); |
357 | 353 |
358 EXPECT_CALL(stream2, Open()) | 354 EXPECT_CALL(stream2, Open()) |
359 .WillOnce(Return(true)); | 355 .WillOnce(Return(true)); |
(...skipping 16 matching lines...) Expand all Loading... |
376 | 372 |
377 EXPECT_TRUE(stream1.stop_called()); | 373 EXPECT_TRUE(stream1.stop_called()); |
378 EXPECT_TRUE(stream1.start_called()); | 374 EXPECT_TRUE(stream1.start_called()); |
379 EXPECT_TRUE(stream2.stop_called()); | 375 EXPECT_TRUE(stream2.stop_called()); |
380 EXPECT_TRUE(stream2.start_called()); | 376 EXPECT_TRUE(stream2.start_called()); |
381 } | 377 } |
382 | 378 |
383 void StartFailed(AudioOutputDispatcher* dispatcher) { | 379 void StartFailed(AudioOutputDispatcher* dispatcher) { |
384 MockAudioOutputStream stream(&manager_, params_); | 380 MockAudioOutputStream stream(&manager_, params_); |
385 | 381 |
386 EXPECT_CALL(manager(), MakeAudioOutputStream(_, _, _)) | 382 EXPECT_CALL(manager(), MakeAudioOutputStream(_, _)) |
387 .WillOnce(Return(&stream)); | 383 .WillOnce(Return(&stream)); |
388 EXPECT_CALL(stream, Open()) | 384 EXPECT_CALL(stream, Open()) |
389 .WillOnce(Return(true)); | 385 .WillOnce(Return(true)); |
390 | 386 |
391 AudioOutputProxy* proxy = new AudioOutputProxy(dispatcher); | 387 AudioOutputProxy* proxy = new AudioOutputProxy(dispatcher); |
392 EXPECT_TRUE(proxy->Open()); | 388 EXPECT_TRUE(proxy->Open()); |
393 | 389 |
394 WaitForCloseTimer(&stream); | 390 WaitForCloseTimer(&stream); |
395 | 391 |
396 // |stream| is closed at this point. Start() should reopen it again. | 392 // |stream| is closed at this point. Start() should reopen it again. |
397 EXPECT_CALL(manager(), MakeAudioOutputStream(_, _, _)) | 393 EXPECT_CALL(manager(), MakeAudioOutputStream(_, _)) |
398 .Times(2) | 394 .Times(2) |
399 .WillRepeatedly(Return(reinterpret_cast<AudioOutputStream*>(NULL))); | 395 .WillRepeatedly(Return(reinterpret_cast<AudioOutputStream*>(NULL))); |
400 | 396 |
401 EXPECT_CALL(callback_, OnError(_)) | 397 EXPECT_CALL(callback_, OnError(_)) |
402 .Times(2); | 398 .Times(2); |
403 | 399 |
404 proxy->Start(&callback_); | 400 proxy->Start(&callback_); |
405 | 401 |
406 // Double Start() in the error case should be allowed since it's possible a | 402 // Double Start() in the error case should be allowed since it's possible a |
407 // callback may not have had time to process the OnError() in between. | 403 // callback may not have had time to process the OnError() in between. |
(...skipping 19 matching lines...) Expand all Loading... |
427 } | 423 } |
428 | 424 |
429 virtual void InitDispatcher(base::TimeDelta close_delay) OVERRIDE { | 425 virtual void InitDispatcher(base::TimeDelta close_delay) OVERRIDE { |
430 // Use a low sample rate and large buffer size when testing otherwise the | 426 // Use a low sample rate and large buffer size when testing otherwise the |
431 // FakeAudioOutputStream will keep the message loop busy indefinitely; i.e., | 427 // FakeAudioOutputStream will keep the message loop busy indefinitely; i.e., |
432 // RunUntilIdle() will never terminate. | 428 // RunUntilIdle() will never terminate. |
433 resampler_params_ = AudioParameters( | 429 resampler_params_ = AudioParameters( |
434 AudioParameters::AUDIO_PCM_LOW_LATENCY, CHANNEL_LAYOUT_STEREO, | 430 AudioParameters::AUDIO_PCM_LOW_LATENCY, CHANNEL_LAYOUT_STEREO, |
435 16000, 16, 1024); | 431 16000, 16, 1024); |
436 resampler_ = new AudioOutputResampler( | 432 resampler_ = new AudioOutputResampler( |
437 &manager(), params_, resampler_params_, std::string(), std::string(), | 433 &manager(), params_, resampler_params_, std::string(), close_delay); |
438 close_delay); | |
439 } | 434 } |
440 | 435 |
441 virtual void OnStart() OVERRIDE { | 436 virtual void OnStart() OVERRIDE { |
442 // Let Start() run for a bit. | 437 // Let Start() run for a bit. |
443 base::RunLoop run_loop; | 438 base::RunLoop run_loop; |
444 message_loop_.PostDelayedTask( | 439 message_loop_.PostDelayedTask( |
445 FROM_HERE, | 440 FROM_HERE, |
446 run_loop.QuitClosure(), | 441 run_loop.QuitClosure(), |
447 base::TimeDelta::FromMilliseconds(kStartRunTimeMs)); | 442 base::TimeDelta::FromMilliseconds(kStartRunTimeMs)); |
448 run_loop.Run(); | 443 run_loop.Run(); |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
528 TEST_F(AudioOutputProxyTest, StartFailed) { | 523 TEST_F(AudioOutputProxyTest, StartFailed) { |
529 StartFailed(dispatcher_impl_); | 524 StartFailed(dispatcher_impl_); |
530 } | 525 } |
531 | 526 |
532 TEST_F(AudioOutputResamplerTest, StartFailed) { StartFailed(resampler_); } | 527 TEST_F(AudioOutputResamplerTest, StartFailed) { StartFailed(resampler_); } |
533 | 528 |
534 // Simulate AudioOutputStream::Create() failure with a low latency stream and | 529 // Simulate AudioOutputStream::Create() failure with a low latency stream and |
535 // ensure AudioOutputResampler falls back to the high latency path. | 530 // ensure AudioOutputResampler falls back to the high latency path. |
536 TEST_F(AudioOutputResamplerTest, LowLatencyCreateFailedFallback) { | 531 TEST_F(AudioOutputResamplerTest, LowLatencyCreateFailedFallback) { |
537 MockAudioOutputStream stream(&manager_, params_); | 532 MockAudioOutputStream stream(&manager_, params_); |
538 EXPECT_CALL(manager(), MakeAudioOutputStream(_, _, _)) | 533 EXPECT_CALL(manager(), MakeAudioOutputStream(_, _)) |
539 .Times(2) | 534 .Times(2) |
540 .WillOnce(Return(static_cast<AudioOutputStream*>(NULL))) | 535 .WillOnce(Return(static_cast<AudioOutputStream*>(NULL))) |
541 .WillRepeatedly(Return(&stream)); | 536 .WillRepeatedly(Return(&stream)); |
542 EXPECT_CALL(stream, Open()) | 537 EXPECT_CALL(stream, Open()) |
543 .WillOnce(Return(true)); | 538 .WillOnce(Return(true)); |
544 | 539 |
545 AudioOutputProxy* proxy = new AudioOutputProxy(resampler_); | 540 AudioOutputProxy* proxy = new AudioOutputProxy(resampler_); |
546 EXPECT_TRUE(proxy->Open()); | 541 EXPECT_TRUE(proxy->Open()); |
547 CloseAndWaitForCloseTimer(proxy, &stream); | 542 CloseAndWaitForCloseTimer(proxy, &stream); |
548 } | 543 } |
549 | 544 |
550 // Simulate AudioOutputStream::Open() failure with a low latency stream and | 545 // Simulate AudioOutputStream::Open() failure with a low latency stream and |
551 // ensure AudioOutputResampler falls back to the high latency path. | 546 // ensure AudioOutputResampler falls back to the high latency path. |
552 TEST_F(AudioOutputResamplerTest, LowLatencyOpenFailedFallback) { | 547 TEST_F(AudioOutputResamplerTest, LowLatencyOpenFailedFallback) { |
553 MockAudioOutputStream failed_stream(&manager_, params_); | 548 MockAudioOutputStream failed_stream(&manager_, params_); |
554 MockAudioOutputStream okay_stream(&manager_, params_); | 549 MockAudioOutputStream okay_stream(&manager_, params_); |
555 EXPECT_CALL(manager(), MakeAudioOutputStream(_, _, _)) | 550 EXPECT_CALL(manager(), MakeAudioOutputStream(_, _)) |
556 .Times(2) | 551 .Times(2) |
557 .WillOnce(Return(&failed_stream)) | 552 .WillOnce(Return(&failed_stream)) |
558 .WillRepeatedly(Return(&okay_stream)); | 553 .WillRepeatedly(Return(&okay_stream)); |
559 EXPECT_CALL(failed_stream, Open()) | 554 EXPECT_CALL(failed_stream, Open()) |
560 .WillOnce(Return(false)); | 555 .WillOnce(Return(false)); |
561 EXPECT_CALL(failed_stream, Close()) | 556 EXPECT_CALL(failed_stream, Close()) |
562 .Times(1); | 557 .Times(1); |
563 EXPECT_CALL(okay_stream, Open()) | 558 EXPECT_CALL(okay_stream, Open()) |
564 .WillOnce(Return(true)); | 559 .WillOnce(Return(true)); |
565 | 560 |
566 AudioOutputProxy* proxy = new AudioOutputProxy(resampler_); | 561 AudioOutputProxy* proxy = new AudioOutputProxy(resampler_); |
567 EXPECT_TRUE(proxy->Open()); | 562 EXPECT_TRUE(proxy->Open()); |
568 CloseAndWaitForCloseTimer(proxy, &okay_stream); | 563 CloseAndWaitForCloseTimer(proxy, &okay_stream); |
569 } | 564 } |
570 | 565 |
571 // Simulate failures to open both the low latency and the fallback high latency | 566 // Simulate failures to open both the low latency and the fallback high latency |
572 // stream and ensure AudioOutputResampler falls back to a fake stream. | 567 // stream and ensure AudioOutputResampler falls back to a fake stream. |
573 TEST_F(AudioOutputResamplerTest, HighLatencyFallbackFailed) { | 568 TEST_F(AudioOutputResamplerTest, HighLatencyFallbackFailed) { |
574 MockAudioOutputStream okay_stream(&manager_, params_); | 569 MockAudioOutputStream okay_stream(&manager_, params_); |
575 | 570 |
576 // Only Windows has a high latency output driver that is not the same as the low | 571 // Only Windows has a high latency output driver that is not the same as the low |
577 // latency path. | 572 // latency path. |
578 #if defined(OS_WIN) | 573 #if defined(OS_WIN) |
579 static const int kFallbackCount = 2; | 574 static const int kFallbackCount = 2; |
580 #else | 575 #else |
581 static const int kFallbackCount = 1; | 576 static const int kFallbackCount = 1; |
582 #endif | 577 #endif |
583 EXPECT_CALL(manager(), MakeAudioOutputStream(_, _, _)) | 578 EXPECT_CALL(manager(), MakeAudioOutputStream(_, _)) |
584 .Times(kFallbackCount) | 579 .Times(kFallbackCount) |
585 .WillRepeatedly(Return(static_cast<AudioOutputStream*>(NULL))); | 580 .WillRepeatedly(Return(static_cast<AudioOutputStream*>(NULL))); |
586 | 581 |
587 // To prevent shared memory issues the sample rate and buffer size should | 582 // To prevent shared memory issues the sample rate and buffer size should |
588 // match the input stream parameters. | 583 // match the input stream parameters. |
589 EXPECT_CALL(manager(), MakeAudioOutputStream(AllOf( | 584 EXPECT_CALL(manager(), MakeAudioOutputStream(AllOf( |
590 testing::Property(&AudioParameters::format, AudioParameters::AUDIO_FAKE), | 585 testing::Property(&AudioParameters::format, AudioParameters::AUDIO_FAKE), |
591 testing::Property(&AudioParameters::sample_rate, params_.sample_rate()), | 586 testing::Property(&AudioParameters::sample_rate, params_.sample_rate()), |
592 testing::Property( | 587 testing::Property( |
593 &AudioParameters::frames_per_buffer, params_.frames_per_buffer())), | 588 &AudioParameters::frames_per_buffer, params_.frames_per_buffer())), |
594 _, _)) | 589 _)) |
595 .Times(1) | 590 .Times(1) |
596 .WillOnce(Return(&okay_stream)); | 591 .WillOnce(Return(&okay_stream)); |
597 EXPECT_CALL(okay_stream, Open()) | 592 EXPECT_CALL(okay_stream, Open()) |
598 .WillOnce(Return(true)); | 593 .WillOnce(Return(true)); |
599 | 594 |
600 AudioOutputProxy* proxy = new AudioOutputProxy(resampler_); | 595 AudioOutputProxy* proxy = new AudioOutputProxy(resampler_); |
601 EXPECT_TRUE(proxy->Open()); | 596 EXPECT_TRUE(proxy->Open()); |
602 CloseAndWaitForCloseTimer(proxy, &okay_stream); | 597 CloseAndWaitForCloseTimer(proxy, &okay_stream); |
603 } | 598 } |
604 | 599 |
605 // Simulate failures to open both the low latency, the fallback high latency | 600 // Simulate failures to open both the low latency, the fallback high latency |
606 // stream, and the fake audio output stream and ensure AudioOutputResampler | 601 // stream, and the fake audio output stream and ensure AudioOutputResampler |
607 // terminates normally. | 602 // terminates normally. |
608 TEST_F(AudioOutputResamplerTest, AllFallbackFailed) { | 603 TEST_F(AudioOutputResamplerTest, AllFallbackFailed) { |
609 // Only Windows has a high latency output driver that is not the same as the low | 604 // Only Windows has a high latency output driver that is not the same as the low |
610 // latency path. | 605 // latency path. |
611 #if defined(OS_WIN) | 606 #if defined(OS_WIN) |
612 static const int kFallbackCount = 3; | 607 static const int kFallbackCount = 3; |
613 #else | 608 #else |
614 static const int kFallbackCount = 2; | 609 static const int kFallbackCount = 2; |
615 #endif | 610 #endif |
616 EXPECT_CALL(manager(), MakeAudioOutputStream(_, _, _)) | 611 EXPECT_CALL(manager(), MakeAudioOutputStream(_, _)) |
617 .Times(kFallbackCount) | 612 .Times(kFallbackCount) |
618 .WillRepeatedly(Return(static_cast<AudioOutputStream*>(NULL))); | 613 .WillRepeatedly(Return(static_cast<AudioOutputStream*>(NULL))); |
619 | 614 |
620 AudioOutputProxy* proxy = new AudioOutputProxy(resampler_); | 615 AudioOutputProxy* proxy = new AudioOutputProxy(resampler_); |
621 EXPECT_FALSE(proxy->Open()); | 616 EXPECT_FALSE(proxy->Open()); |
622 proxy->Close(); | 617 proxy->Close(); |
623 } | 618 } |
624 | 619 |
625 // Simulate an eventual OpenStream() failure; i.e. successful OpenStream() calls | 620 // Simulate an eventual OpenStream() failure; i.e. successful OpenStream() calls |
626 // eventually followed by one which fails; root cause of http://crbug.com/150619 | 621 // eventually followed by one which fails; root cause of http://crbug.com/150619 |
627 TEST_F(AudioOutputResamplerTest, LowLatencyOpenEventuallyFails) { | 622 TEST_F(AudioOutputResamplerTest, LowLatencyOpenEventuallyFails) { |
628 MockAudioOutputStream stream1(&manager_, params_); | 623 MockAudioOutputStream stream1(&manager_, params_); |
629 MockAudioOutputStream stream2(&manager_, params_); | 624 MockAudioOutputStream stream2(&manager_, params_); |
630 | 625 |
631 // Setup the mock such that all three streams are successfully created. | 626 // Setup the mock such that all three streams are successfully created. |
632 EXPECT_CALL(manager(), MakeAudioOutputStream(_, _, _)) | 627 EXPECT_CALL(manager(), MakeAudioOutputStream(_, _)) |
633 .WillOnce(Return(&stream1)) | 628 .WillOnce(Return(&stream1)) |
634 .WillOnce(Return(&stream2)) | 629 .WillOnce(Return(&stream2)) |
635 .WillRepeatedly(Return(static_cast<AudioOutputStream*>(NULL))); | 630 .WillRepeatedly(Return(static_cast<AudioOutputStream*>(NULL))); |
636 | 631 |
637 // Stream1 should be able to successfully open and start. | 632 // Stream1 should be able to successfully open and start. |
638 EXPECT_CALL(stream1, Open()) | 633 EXPECT_CALL(stream1, Open()) |
639 .WillOnce(Return(true)); | 634 .WillOnce(Return(true)); |
640 EXPECT_CALL(stream1, SetVolume(_)) | 635 EXPECT_CALL(stream1, SetVolume(_)) |
641 .Times(1); | 636 .Times(1); |
642 | 637 |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
678 EXPECT_TRUE(stream2.start_called()); | 673 EXPECT_TRUE(stream2.start_called()); |
679 } | 674 } |
680 | 675 |
681 // Ensures the methods used to fix audio output wedges are working correctly. | 676 // Ensures the methods used to fix audio output wedges are working correctly. |
682 TEST_F(AudioOutputResamplerTest, WedgeFix) { | 677 TEST_F(AudioOutputResamplerTest, WedgeFix) { |
683 MockAudioOutputStream stream1(&manager_, params_); | 678 MockAudioOutputStream stream1(&manager_, params_); |
684 MockAudioOutputStream stream2(&manager_, params_); | 679 MockAudioOutputStream stream2(&manager_, params_); |
685 MockAudioOutputStream stream3(&manager_, params_); | 680 MockAudioOutputStream stream3(&manager_, params_); |
686 | 681 |
687 // Setup the mock such that all three streams are successfully created. | 682 // Setup the mock such that all three streams are successfully created. |
688 EXPECT_CALL(manager(), MakeAudioOutputStream(_, _, _)) | 683 EXPECT_CALL(manager(), MakeAudioOutputStream(_, _)) |
689 .WillOnce(Return(&stream1)) | 684 .WillOnce(Return(&stream1)) |
690 .WillOnce(Return(&stream2)) | 685 .WillOnce(Return(&stream2)) |
691 .WillOnce(Return(&stream3)); | 686 .WillOnce(Return(&stream3)); |
692 | 687 |
693 // Stream1 should be able to successfully open and start. | 688 // Stream1 should be able to successfully open and start. |
694 EXPECT_CALL(stream1, Open()) | 689 EXPECT_CALL(stream1, Open()) |
695 .WillOnce(Return(true)); | 690 .WillOnce(Return(true)); |
696 EXPECT_CALL(stream1, SetVolume(_)); | 691 EXPECT_CALL(stream1, SetVolume(_)); |
697 EXPECT_CALL(stream2, Open()) | 692 EXPECT_CALL(stream2, Open()) |
698 .WillOnce(Return(true)); | 693 .WillOnce(Return(true)); |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
743 // Wait for all of the messages to fly and then verify stream behavior. | 738 // Wait for all of the messages to fly and then verify stream behavior. |
744 EXPECT_TRUE(stream1.stop_called()); | 739 EXPECT_TRUE(stream1.stop_called()); |
745 EXPECT_TRUE(stream1.start_called()); | 740 EXPECT_TRUE(stream1.start_called()); |
746 EXPECT_TRUE(stream2.stop_called()); | 741 EXPECT_TRUE(stream2.stop_called()); |
747 EXPECT_TRUE(stream2.start_called()); | 742 EXPECT_TRUE(stream2.start_called()); |
748 EXPECT_TRUE(stream3.stop_called()); | 743 EXPECT_TRUE(stream3.stop_called()); |
749 EXPECT_TRUE(stream3.start_called()); | 744 EXPECT_TRUE(stream3.start_called()); |
750 } | 745 } |
751 | 746 |
752 } // namespace media | 747 } // namespace media |
OLD | NEW |