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.h" | 7 #include "base/message_loop.h" |
8 #include "base/message_loop_proxy.h" | 8 #include "base/message_loop_proxy.h" |
9 #include "base/threading/platform_thread.h" | 9 #include "base/threading/platform_thread.h" |
10 #include "media/audio/audio_output_dispatcher_impl.h" | 10 #include "media/audio/audio_output_dispatcher_impl.h" |
11 #include "media/audio/audio_output_mixer.h" | |
12 #include "media/audio/audio_output_proxy.h" | 11 #include "media/audio/audio_output_proxy.h" |
13 #include "media/audio/audio_manager.h" | 12 #include "media/audio/audio_manager.h" |
14 #include "testing/gmock/include/gmock/gmock.h" | 13 #include "testing/gmock/include/gmock/gmock.h" |
15 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
16 | 15 |
| 16 // TODO(dalecurtis): Temporarily disabled while switching pipeline to use float, |
| 17 // http://crbug.com/114700 |
| 18 #if defined(ENABLE_AUDIO_MIXER) |
| 19 #include "media/audio/audio_output_mixer.h" |
| 20 #endif |
| 21 |
17 using ::testing::_; | 22 using ::testing::_; |
18 using ::testing::AllOf; | 23 using ::testing::AllOf; |
19 using ::testing::DoAll; | 24 using ::testing::DoAll; |
20 using ::testing::Field; | 25 using ::testing::Field; |
21 using ::testing::Mock; | 26 using ::testing::Mock; |
22 using ::testing::NotNull; | 27 using ::testing::NotNull; |
23 using ::testing::Return; | 28 using ::testing::Return; |
24 using ::testing::SetArrayArgument; | 29 using ::testing::SetArrayArgument; |
25 using media::AudioBuffersState; | 30 using media::AudioBuffersState; |
26 using media::AudioInputStream; | 31 using media::AudioInputStream; |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
98 // closed by the test. | 103 // closed by the test. |
99 message_loop_.RunAllPending(); | 104 message_loop_.RunAllPending(); |
100 } | 105 } |
101 | 106 |
102 void InitDispatcher(base::TimeDelta close_delay) { | 107 void InitDispatcher(base::TimeDelta close_delay) { |
103 AudioParameters params(AudioParameters::AUDIO_PCM_LINEAR, | 108 AudioParameters params(AudioParameters::AUDIO_PCM_LINEAR, |
104 CHANNEL_LAYOUT_STEREO, 44100, 16, 1024); | 109 CHANNEL_LAYOUT_STEREO, 44100, 16, 1024); |
105 dispatcher_impl_ = new AudioOutputDispatcherImpl(&manager(), | 110 dispatcher_impl_ = new AudioOutputDispatcherImpl(&manager(), |
106 params, | 111 params, |
107 close_delay); | 112 close_delay); |
| 113 #if defined(ENABLE_AUDIO_MIXER) |
108 mixer_ = new AudioOutputMixer(&manager(), params, close_delay); | 114 mixer_ = new AudioOutputMixer(&manager(), params, close_delay); |
| 115 #endif |
109 | 116 |
110 // Necessary to know how long the dispatcher will wait before posting | 117 // Necessary to know how long the dispatcher will wait before posting |
111 // StopStreamTask. | 118 // StopStreamTask. |
112 pause_delay_ = dispatcher_impl_->pause_delay_; | 119 pause_delay_ = dispatcher_impl_->pause_delay_; |
113 } | 120 } |
114 | 121 |
115 MockAudioManager& manager() { | 122 MockAudioManager& manager() { |
116 return manager_; | 123 return manager_; |
117 } | 124 } |
118 | 125 |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
233 .Times(1); | 240 .Times(1); |
234 | 241 |
235 AudioOutputProxy* proxy = new AudioOutputProxy(dispatcher); | 242 AudioOutputProxy* proxy = new AudioOutputProxy(dispatcher); |
236 EXPECT_FALSE(proxy->Open()); | 243 EXPECT_FALSE(proxy->Open()); |
237 proxy->Close(); | 244 proxy->Close(); |
238 WaitForCloseTimer(kTestCloseDelayMs); | 245 WaitForCloseTimer(kTestCloseDelayMs); |
239 } | 246 } |
240 | 247 |
241 MessageLoop message_loop_; | 248 MessageLoop message_loop_; |
242 scoped_refptr<AudioOutputDispatcherImpl> dispatcher_impl_; | 249 scoped_refptr<AudioOutputDispatcherImpl> dispatcher_impl_; |
| 250 #if defined(ENABLE_AUDIO_MIXER) |
243 scoped_refptr<AudioOutputMixer> mixer_; | 251 scoped_refptr<AudioOutputMixer> mixer_; |
| 252 #endif |
244 base::TimeDelta pause_delay_; | 253 base::TimeDelta pause_delay_; |
245 MockAudioManager manager_; | 254 MockAudioManager manager_; |
246 MockAudioSourceCallback callback_; | 255 MockAudioSourceCallback callback_; |
247 }; | 256 }; |
248 | 257 |
249 TEST_F(AudioOutputProxyTest, CreateAndClose) { | 258 TEST_F(AudioOutputProxyTest, CreateAndClose) { |
250 AudioOutputProxy* proxy = new AudioOutputProxy(dispatcher_impl_); | 259 AudioOutputProxy* proxy = new AudioOutputProxy(dispatcher_impl_); |
251 proxy->Close(); | 260 proxy->Close(); |
252 } | 261 } |
253 | 262 |
| 263 #if defined(ENABLE_AUDIO_MIXER) |
254 TEST_F(AudioOutputProxyTest, CreateAndClose_Mixer) { | 264 TEST_F(AudioOutputProxyTest, CreateAndClose_Mixer) { |
255 AudioOutputProxy* proxy = new AudioOutputProxy(mixer_); | 265 AudioOutputProxy* proxy = new AudioOutputProxy(mixer_); |
256 proxy->Close(); | 266 proxy->Close(); |
257 } | 267 } |
| 268 #endif |
258 | 269 |
259 TEST_F(AudioOutputProxyTest, OpenAndClose) { | 270 TEST_F(AudioOutputProxyTest, OpenAndClose) { |
260 OpenAndClose(dispatcher_impl_); | 271 OpenAndClose(dispatcher_impl_); |
261 } | 272 } |
262 | 273 |
| 274 #if defined(ENABLE_AUDIO_MIXER) |
263 TEST_F(AudioOutputProxyTest, OpenAndClose_Mixer) { | 275 TEST_F(AudioOutputProxyTest, OpenAndClose_Mixer) { |
264 OpenAndClose(mixer_); | 276 OpenAndClose(mixer_); |
265 } | 277 } |
| 278 #endif |
266 | 279 |
267 // Create a stream, and verify that it is closed after kTestCloseDelayMs. | 280 // Create a stream, and verify that it is closed after kTestCloseDelayMs. |
268 // if it doesn't start playing. | 281 // if it doesn't start playing. |
269 TEST_F(AudioOutputProxyTest, CreateAndWait) { | 282 TEST_F(AudioOutputProxyTest, CreateAndWait) { |
270 MockAudioOutputStream stream; | 283 MockAudioOutputStream stream; |
271 | 284 |
272 EXPECT_CALL(manager(), MakeAudioOutputStream(_)) | 285 EXPECT_CALL(manager(), MakeAudioOutputStream(_)) |
273 .WillOnce(Return(&stream)); | 286 .WillOnce(Return(&stream)); |
274 EXPECT_CALL(stream, Open()) | 287 EXPECT_CALL(stream, Open()) |
275 .WillOnce(Return(true)); | 288 .WillOnce(Return(true)); |
(...skipping 11 matching lines...) Expand all Loading... |
287 // Verify expectation before calling Close(). | 300 // Verify expectation before calling Close(). |
288 Mock::VerifyAndClear(&stream); | 301 Mock::VerifyAndClear(&stream); |
289 | 302 |
290 proxy->Close(); | 303 proxy->Close(); |
291 } | 304 } |
292 | 305 |
293 TEST_F(AudioOutputProxyTest, StartAndStop) { | 306 TEST_F(AudioOutputProxyTest, StartAndStop) { |
294 StartAndStop(dispatcher_impl_); | 307 StartAndStop(dispatcher_impl_); |
295 } | 308 } |
296 | 309 |
| 310 #if defined(ENABLE_AUDIO_MIXER) |
297 TEST_F(AudioOutputProxyTest, StartAndStop_Mixer) { | 311 TEST_F(AudioOutputProxyTest, StartAndStop_Mixer) { |
298 StartAndStop(mixer_); | 312 StartAndStop(mixer_); |
299 } | 313 } |
| 314 #endif |
300 | 315 |
301 TEST_F(AudioOutputProxyTest, CloseAfterStop) { | 316 TEST_F(AudioOutputProxyTest, CloseAfterStop) { |
302 CloseAfterStop(dispatcher_impl_); | 317 CloseAfterStop(dispatcher_impl_); |
303 } | 318 } |
304 | 319 |
| 320 #if defined(ENABLE_AUDIO_MIXER) |
305 TEST_F(AudioOutputProxyTest, CloseAfterStop_Mixer) { | 321 TEST_F(AudioOutputProxyTest, CloseAfterStop_Mixer) { |
306 CloseAfterStop(mixer_); | 322 CloseAfterStop(mixer_); |
307 } | 323 } |
| 324 #endif |
308 | 325 |
309 TEST_F(AudioOutputProxyTest, TwoStreams) { | 326 TEST_F(AudioOutputProxyTest, TwoStreams) { |
310 TwoStreams(dispatcher_impl_); | 327 TwoStreams(dispatcher_impl_); |
311 } | 328 } |
312 | 329 |
| 330 #if defined(ENABLE_AUDIO_MIXER) |
313 TEST_F(AudioOutputProxyTest, TwoStreams_Mixer) { | 331 TEST_F(AudioOutputProxyTest, TwoStreams_Mixer) { |
314 TwoStreams(mixer_); | 332 TwoStreams(mixer_); |
315 } | 333 } |
| 334 #endif |
316 | 335 |
317 // Two streams: verify that second stream is allocated when the first | 336 // Two streams: verify that second stream is allocated when the first |
318 // starts playing. | 337 // starts playing. |
319 TEST_F(AudioOutputProxyTest, TwoStreams_OnePlaying) { | 338 TEST_F(AudioOutputProxyTest, TwoStreams_OnePlaying) { |
320 MockAudioOutputStream stream1; | 339 MockAudioOutputStream stream1; |
321 MockAudioOutputStream stream2; | 340 MockAudioOutputStream stream2; |
322 | 341 |
323 InitDispatcher(base::TimeDelta::FromSeconds(kTestBigCloseDelaySeconds)); | 342 InitDispatcher(base::TimeDelta::FromSeconds(kTestBigCloseDelaySeconds)); |
324 | 343 |
325 EXPECT_CALL(manager(), MakeAudioOutputStream(_)) | 344 EXPECT_CALL(manager(), MakeAudioOutputStream(_)) |
(...skipping 22 matching lines...) Expand all Loading... |
348 EXPECT_TRUE(proxy2->Open()); | 367 EXPECT_TRUE(proxy2->Open()); |
349 | 368 |
350 proxy1->Start(&callback_); | 369 proxy1->Start(&callback_); |
351 message_loop_.RunAllPending(); | 370 message_loop_.RunAllPending(); |
352 proxy1->Stop(); | 371 proxy1->Stop(); |
353 | 372 |
354 proxy1->Close(); | 373 proxy1->Close(); |
355 proxy2->Close(); | 374 proxy2->Close(); |
356 } | 375 } |
357 | 376 |
| 377 #if defined(ENABLE_AUDIO_MIXER) |
358 // Two streams: verify that only one device will be created. | 378 // Two streams: verify that only one device will be created. |
359 TEST_F(AudioOutputProxyTest, TwoStreams_OnePlaying_Mixer) { | 379 TEST_F(AudioOutputProxyTest, TwoStreams_OnePlaying_Mixer) { |
360 MockAudioOutputStream stream; | 380 MockAudioOutputStream stream; |
361 | 381 |
362 InitDispatcher(base::TimeDelta::FromMilliseconds(kTestCloseDelayMs)); | 382 InitDispatcher(base::TimeDelta::FromMilliseconds(kTestCloseDelayMs)); |
363 | 383 |
364 EXPECT_CALL(manager(), MakeAudioOutputStream(_)) | 384 EXPECT_CALL(manager(), MakeAudioOutputStream(_)) |
365 .WillOnce(Return(&stream)); | 385 .WillOnce(Return(&stream)); |
366 | 386 |
367 EXPECT_CALL(stream, Open()) | 387 EXPECT_CALL(stream, Open()) |
(...skipping 12 matching lines...) Expand all Loading... |
380 EXPECT_TRUE(proxy1->Open()); | 400 EXPECT_TRUE(proxy1->Open()); |
381 EXPECT_TRUE(proxy2->Open()); | 401 EXPECT_TRUE(proxy2->Open()); |
382 | 402 |
383 proxy1->Start(&callback_); | 403 proxy1->Start(&callback_); |
384 proxy1->Stop(); | 404 proxy1->Stop(); |
385 | 405 |
386 proxy1->Close(); | 406 proxy1->Close(); |
387 proxy2->Close(); | 407 proxy2->Close(); |
388 WaitForCloseTimer(kTestCloseDelayMs); | 408 WaitForCloseTimer(kTestCloseDelayMs); |
389 } | 409 } |
| 410 #endif |
390 | 411 |
391 // Two streams, both are playing. Dispatcher should not open a third stream. | 412 // Two streams, both are playing. Dispatcher should not open a third stream. |
392 TEST_F(AudioOutputProxyTest, TwoStreams_BothPlaying) { | 413 TEST_F(AudioOutputProxyTest, TwoStreams_BothPlaying) { |
393 MockAudioOutputStream stream1; | 414 MockAudioOutputStream stream1; |
394 MockAudioOutputStream stream2; | 415 MockAudioOutputStream stream2; |
395 | 416 |
396 InitDispatcher(base::TimeDelta::FromSeconds(kTestBigCloseDelaySeconds)); | 417 InitDispatcher(base::TimeDelta::FromSeconds(kTestBigCloseDelaySeconds)); |
397 | 418 |
398 EXPECT_CALL(manager(), MakeAudioOutputStream(_)) | 419 EXPECT_CALL(manager(), MakeAudioOutputStream(_)) |
399 .WillOnce(Return(&stream1)) | 420 .WillOnce(Return(&stream1)) |
(...skipping 28 matching lines...) Expand all Loading... |
428 | 449 |
429 proxy1->Start(&callback_); | 450 proxy1->Start(&callback_); |
430 proxy2->Start(&callback_); | 451 proxy2->Start(&callback_); |
431 proxy1->Stop(); | 452 proxy1->Stop(); |
432 proxy2->Stop(); | 453 proxy2->Stop(); |
433 | 454 |
434 proxy1->Close(); | 455 proxy1->Close(); |
435 proxy2->Close(); | 456 proxy2->Close(); |
436 } | 457 } |
437 | 458 |
| 459 #if defined(ENABLE_AUDIO_MIXER) |
438 // Two streams, both are playing. Still have to use single device. | 460 // Two streams, both are playing. Still have to use single device. |
439 // Also verifies that every proxy stream gets its own pending_bytes. | 461 // Also verifies that every proxy stream gets its own pending_bytes. |
440 TEST_F(AudioOutputProxyTest, TwoStreams_BothPlaying_Mixer) { | 462 TEST_F(AudioOutputProxyTest, TwoStreams_BothPlaying_Mixer) { |
441 MockAudioOutputStream stream; | 463 MockAudioOutputStream stream; |
442 | 464 |
443 InitDispatcher(base::TimeDelta::FromMilliseconds(kTestCloseDelayMs)); | 465 InitDispatcher(base::TimeDelta::FromMilliseconds(kTestCloseDelayMs)); |
444 | 466 |
445 EXPECT_CALL(manager(), MakeAudioOutputStream(_)) | 467 EXPECT_CALL(manager(), MakeAudioOutputStream(_)) |
446 .WillOnce(Return(&stream)); | 468 .WillOnce(Return(&stream)); |
447 | 469 |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
490 .WillOnce(DoAll(SetArrayArgument<0>(zeroes, zeroes + sizeof(zeroes)), | 512 .WillOnce(DoAll(SetArrayArgument<0>(zeroes, zeroes + sizeof(zeroes)), |
491 Return(4))); | 513 Return(4))); |
492 mixer_->OnMoreData(buf2, sizeof(buf2), AudioBuffersState(4, 0)); | 514 mixer_->OnMoreData(buf2, sizeof(buf2), AudioBuffersState(4, 0)); |
493 proxy1->Stop(); | 515 proxy1->Stop(); |
494 proxy2->Stop(); | 516 proxy2->Stop(); |
495 | 517 |
496 proxy1->Close(); | 518 proxy1->Close(); |
497 proxy2->Close(); | 519 proxy2->Close(); |
498 WaitForCloseTimer(kTestCloseDelayMs); | 520 WaitForCloseTimer(kTestCloseDelayMs); |
499 } | 521 } |
| 522 #endif |
500 | 523 |
501 TEST_F(AudioOutputProxyTest, OpenFailed) { | 524 TEST_F(AudioOutputProxyTest, OpenFailed) { |
502 OpenFailed(dispatcher_impl_); | 525 OpenFailed(dispatcher_impl_); |
503 } | 526 } |
504 | 527 |
| 528 #if defined(ENABLE_AUDIO_MIXER) |
505 TEST_F(AudioOutputProxyTest, OpenFailed_Mixer) { | 529 TEST_F(AudioOutputProxyTest, OpenFailed_Mixer) { |
506 OpenFailed(mixer_); | 530 OpenFailed(mixer_); |
507 } | 531 } |
| 532 #endif |
508 | 533 |
509 // Start() method failed. | 534 // Start() method failed. |
510 TEST_F(AudioOutputProxyTest, StartFailed) { | 535 TEST_F(AudioOutputProxyTest, StartFailed) { |
511 MockAudioOutputStream stream; | 536 MockAudioOutputStream stream; |
512 | 537 |
513 EXPECT_CALL(manager(), MakeAudioOutputStream(_)) | 538 EXPECT_CALL(manager(), MakeAudioOutputStream(_)) |
514 .WillOnce(Return(&stream)); | 539 .WillOnce(Return(&stream)); |
515 EXPECT_CALL(stream, Open()) | 540 EXPECT_CALL(stream, Open()) |
516 .WillOnce(Return(true)); | 541 .WillOnce(Return(true)); |
517 EXPECT_CALL(stream, Close()) | 542 EXPECT_CALL(stream, Close()) |
(...skipping 17 matching lines...) Expand all Loading... |
535 EXPECT_CALL(callback_, OnError(_, _)) | 560 EXPECT_CALL(callback_, OnError(_, _)) |
536 .Times(1); | 561 .Times(1); |
537 | 562 |
538 proxy->Start(&callback_); | 563 proxy->Start(&callback_); |
539 | 564 |
540 Mock::VerifyAndClear(&callback_); | 565 Mock::VerifyAndClear(&callback_); |
541 | 566 |
542 proxy->Close(); | 567 proxy->Close(); |
543 } | 568 } |
544 | 569 |
| 570 #if defined(ENABLE_AUDIO_MIXER) |
545 // Start() method failed. | 571 // Start() method failed. |
546 TEST_F(AudioOutputProxyTest, StartFailed_Mixer) { | 572 TEST_F(AudioOutputProxyTest, StartFailed_Mixer) { |
547 MockAudioOutputStream stream; | 573 MockAudioOutputStream stream; |
548 | 574 |
549 EXPECT_CALL(manager(), MakeAudioOutputStream(_)) | 575 EXPECT_CALL(manager(), MakeAudioOutputStream(_)) |
550 .WillOnce(Return(&stream)); | 576 .WillOnce(Return(&stream)); |
551 EXPECT_CALL(stream, Open()) | 577 EXPECT_CALL(stream, Open()) |
552 .WillOnce(Return(true)); | 578 .WillOnce(Return(true)); |
553 EXPECT_CALL(stream, Close()) | 579 EXPECT_CALL(stream, Close()) |
554 .Times(1); | 580 .Times(1); |
(...skipping 23 matching lines...) Expand all Loading... |
578 EXPECT_CALL(callback_, OnError(_, _)) | 604 EXPECT_CALL(callback_, OnError(_, _)) |
579 .Times(1); | 605 .Times(1); |
580 | 606 |
581 proxy2->Start(&callback_); | 607 proxy2->Start(&callback_); |
582 | 608 |
583 Mock::VerifyAndClear(&callback_); | 609 Mock::VerifyAndClear(&callback_); |
584 | 610 |
585 proxy2->Close(); | 611 proxy2->Close(); |
586 WaitForCloseTimer(kTestCloseDelayMs); | 612 WaitForCloseTimer(kTestCloseDelayMs); |
587 } | 613 } |
| 614 #endif |
588 | 615 |
589 } // namespace media | 616 } // namespace media |
OLD | NEW |