| 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_proxy.h" | 11 #include "media/audio/audio_output_proxy.h" |
| 12 #include "media/audio/audio_output_resampler.h" |
| 12 #include "media/audio/audio_manager.h" | 13 #include "media/audio/audio_manager.h" |
| 13 #include "testing/gmock/include/gmock/gmock.h" | 14 #include "testing/gmock/include/gmock/gmock.h" |
| 14 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
| 15 | 16 |
| 16 // TODO(dalecurtis): Temporarily disabled while switching pipeline to use float, | 17 // TODO(dalecurtis): Temporarily disabled while switching pipeline to use float, |
| 17 // http://crbug.com/114700 | 18 // http://crbug.com/114700 |
| 18 #if defined(ENABLE_AUDIO_MIXER) | 19 #if defined(ENABLE_AUDIO_MIXER) |
| 19 #include "media/audio/audio_output_mixer.h" | 20 #include "media/audio/audio_output_mixer.h" |
| 20 #endif | 21 #endif |
| 21 | 22 |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 108 void InitDispatcher(base::TimeDelta close_delay) { | 109 void InitDispatcher(base::TimeDelta close_delay) { |
| 109 AudioParameters params(AudioParameters::AUDIO_PCM_LINEAR, | 110 AudioParameters params(AudioParameters::AUDIO_PCM_LINEAR, |
| 110 CHANNEL_LAYOUT_STEREO, 44100, 16, 1024); | 111 CHANNEL_LAYOUT_STEREO, 44100, 16, 1024); |
| 111 dispatcher_impl_ = new AudioOutputDispatcherImpl(&manager(), | 112 dispatcher_impl_ = new AudioOutputDispatcherImpl(&manager(), |
| 112 params, | 113 params, |
| 113 close_delay); | 114 close_delay); |
| 114 #if defined(ENABLE_AUDIO_MIXER) | 115 #if defined(ENABLE_AUDIO_MIXER) |
| 115 mixer_ = new AudioOutputMixer(&manager(), params, close_delay); | 116 mixer_ = new AudioOutputMixer(&manager(), params, close_delay); |
| 116 #endif | 117 #endif |
| 117 | 118 |
| 119 AudioParameters out_params(AudioParameters::AUDIO_PCM_LINEAR, |
| 120 CHANNEL_LAYOUT_STEREO, 48000, 16, 128); |
| 121 resampler_ = new AudioOutputResampler( |
| 122 &manager(), params, out_params, close_delay); |
| 123 |
| 118 // Necessary to know how long the dispatcher will wait before posting | 124 // Necessary to know how long the dispatcher will wait before posting |
| 119 // StopStreamTask. | 125 // StopStreamTask. |
| 120 pause_delay_ = dispatcher_impl_->pause_delay_; | 126 pause_delay_ = dispatcher_impl_->pause_delay_; |
| 121 } | 127 } |
| 122 | 128 |
| 123 MockAudioManager& manager() { | 129 MockAudioManager& manager() { |
| 124 return manager_; | 130 return manager_; |
| 125 } | 131 } |
| 126 | 132 |
| 127 // Wait for the close timer to fire. | 133 // Wait for the close timer to fire. |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 239 .WillOnce(Return(false)); | 245 .WillOnce(Return(false)); |
| 240 EXPECT_CALL(stream, Close()) | 246 EXPECT_CALL(stream, Close()) |
| 241 .Times(1); | 247 .Times(1); |
| 242 | 248 |
| 243 AudioOutputProxy* proxy = new AudioOutputProxy(dispatcher); | 249 AudioOutputProxy* proxy = new AudioOutputProxy(dispatcher); |
| 244 EXPECT_FALSE(proxy->Open()); | 250 EXPECT_FALSE(proxy->Open()); |
| 245 proxy->Close(); | 251 proxy->Close(); |
| 246 WaitForCloseTimer(kTestCloseDelayMs); | 252 WaitForCloseTimer(kTestCloseDelayMs); |
| 247 } | 253 } |
| 248 | 254 |
| 255 void CreateAndWait(AudioOutputDispatcher* dispatcher) { |
| 256 MockAudioOutputStream stream; |
| 257 |
| 258 EXPECT_CALL(manager(), MakeAudioOutputStream(_)) |
| 259 .WillOnce(Return(&stream)); |
| 260 EXPECT_CALL(stream, Open()) |
| 261 .WillOnce(Return(true)); |
| 262 EXPECT_CALL(stream, Close()) |
| 263 .Times(1); |
| 264 |
| 265 AudioOutputProxy* proxy = new AudioOutputProxy(dispatcher); |
| 266 EXPECT_TRUE(proxy->Open()); |
| 267 |
| 268 // Simulate a delay. |
| 269 base::PlatformThread::Sleep( |
| 270 base::TimeDelta::FromMilliseconds(kTestCloseDelayMs) * 2); |
| 271 message_loop_.RunAllPending(); |
| 272 |
| 273 // Verify expectation before calling Close(). |
| 274 Mock::VerifyAndClear(&stream); |
| 275 |
| 276 proxy->Close(); |
| 277 } |
| 278 |
| 279 void TwoStreams_OnePlaying(AudioOutputDispatcher* dispatcher) { |
| 280 MockAudioOutputStream stream1; |
| 281 MockAudioOutputStream stream2; |
| 282 |
| 283 EXPECT_CALL(manager(), MakeAudioOutputStream(_)) |
| 284 .WillOnce(Return(&stream1)) |
| 285 .WillOnce(Return(&stream2)); |
| 286 |
| 287 EXPECT_CALL(stream1, Open()) |
| 288 .WillOnce(Return(true)); |
| 289 EXPECT_CALL(stream1, Start(_)) |
| 290 .Times(1); |
| 291 EXPECT_CALL(stream1, SetVolume(_)) |
| 292 .Times(1); |
| 293 EXPECT_CALL(stream1, Stop()) |
| 294 .Times(1); |
| 295 EXPECT_CALL(stream1, Close()) |
| 296 .Times(1); |
| 297 |
| 298 EXPECT_CALL(stream2, Open()) |
| 299 .WillOnce(Return(true)); |
| 300 EXPECT_CALL(stream2, Close()) |
| 301 .Times(1); |
| 302 |
| 303 AudioOutputProxy* proxy1 = new AudioOutputProxy(dispatcher); |
| 304 AudioOutputProxy* proxy2 = new AudioOutputProxy(dispatcher); |
| 305 EXPECT_TRUE(proxy1->Open()); |
| 306 EXPECT_TRUE(proxy2->Open()); |
| 307 |
| 308 proxy1->Start(&callback_); |
| 309 message_loop_.RunAllPending(); |
| 310 proxy1->Stop(); |
| 311 |
| 312 proxy1->Close(); |
| 313 proxy2->Close(); |
| 314 } |
| 315 |
| 316 void TwoStreams_BothPlaying(AudioOutputDispatcher* dispatcher) { |
| 317 MockAudioOutputStream stream1; |
| 318 MockAudioOutputStream stream2; |
| 319 |
| 320 EXPECT_CALL(manager(), MakeAudioOutputStream(_)) |
| 321 .WillOnce(Return(&stream1)) |
| 322 .WillOnce(Return(&stream2)); |
| 323 |
| 324 EXPECT_CALL(stream1, Open()) |
| 325 .WillOnce(Return(true)); |
| 326 EXPECT_CALL(stream1, Start(_)) |
| 327 .Times(1); |
| 328 EXPECT_CALL(stream1, SetVolume(_)) |
| 329 .Times(1); |
| 330 EXPECT_CALL(stream1, Stop()) |
| 331 .Times(1); |
| 332 EXPECT_CALL(stream1, Close()) |
| 333 .Times(1); |
| 334 |
| 335 EXPECT_CALL(stream2, Open()) |
| 336 .WillOnce(Return(true)); |
| 337 EXPECT_CALL(stream2, Start(_)) |
| 338 .Times(1); |
| 339 EXPECT_CALL(stream2, SetVolume(_)) |
| 340 .Times(1); |
| 341 EXPECT_CALL(stream2, Stop()) |
| 342 .Times(1); |
| 343 EXPECT_CALL(stream2, Close()) |
| 344 .Times(1); |
| 345 |
| 346 AudioOutputProxy* proxy1 = new AudioOutputProxy(dispatcher); |
| 347 AudioOutputProxy* proxy2 = new AudioOutputProxy(dispatcher); |
| 348 EXPECT_TRUE(proxy1->Open()); |
| 349 EXPECT_TRUE(proxy2->Open()); |
| 350 |
| 351 proxy1->Start(&callback_); |
| 352 proxy2->Start(&callback_); |
| 353 proxy1->Stop(); |
| 354 proxy2->Stop(); |
| 355 |
| 356 proxy1->Close(); |
| 357 proxy2->Close(); |
| 358 } |
| 359 |
| 360 void StartFailed(AudioOutputDispatcher* dispatcher) { |
| 361 MockAudioOutputStream stream; |
| 362 |
| 363 EXPECT_CALL(manager(), MakeAudioOutputStream(_)) |
| 364 .WillOnce(Return(&stream)); |
| 365 EXPECT_CALL(stream, Open()) |
| 366 .WillOnce(Return(true)); |
| 367 EXPECT_CALL(stream, Close()) |
| 368 .Times(1); |
| 369 |
| 370 AudioOutputProxy* proxy = new AudioOutputProxy(dispatcher_impl_); |
| 371 EXPECT_TRUE(proxy->Open()); |
| 372 |
| 373 // Simulate a delay. |
| 374 base::PlatformThread::Sleep( |
| 375 base::TimeDelta::FromMilliseconds(kTestCloseDelayMs) * 2); |
| 376 message_loop_.RunAllPending(); |
| 377 |
| 378 // Verify expectation before calling Close(). |
| 379 Mock::VerifyAndClear(&stream); |
| 380 |
| 381 // |stream| is closed at this point. Start() should reopen it again. |
| 382 EXPECT_CALL(manager(), MakeAudioOutputStream(_)) |
| 383 .WillOnce(Return(reinterpret_cast<AudioOutputStream*>(NULL))); |
| 384 |
| 385 EXPECT_CALL(callback_, OnError(_, _)) |
| 386 .Times(1); |
| 387 |
| 388 proxy->Start(&callback_); |
| 389 |
| 390 Mock::VerifyAndClear(&callback_); |
| 391 |
| 392 proxy->Close(); |
| 393 } |
| 394 |
| 249 MessageLoop message_loop_; | 395 MessageLoop message_loop_; |
| 250 scoped_refptr<AudioOutputDispatcherImpl> dispatcher_impl_; | 396 scoped_refptr<AudioOutputDispatcherImpl> dispatcher_impl_; |
| 251 #if defined(ENABLE_AUDIO_MIXER) | 397 #if defined(ENABLE_AUDIO_MIXER) |
| 252 scoped_refptr<AudioOutputMixer> mixer_; | 398 scoped_refptr<AudioOutputMixer> mixer_; |
| 253 #endif | 399 #endif |
| 400 scoped_refptr<AudioOutputResampler> resampler_; |
| 254 base::TimeDelta pause_delay_; | 401 base::TimeDelta pause_delay_; |
| 255 MockAudioManager manager_; | 402 MockAudioManager manager_; |
| 256 MockAudioSourceCallback callback_; | 403 MockAudioSourceCallback callback_; |
| 257 }; | 404 }; |
| 258 | 405 |
| 259 TEST_F(AudioOutputProxyTest, CreateAndClose) { | 406 TEST_F(AudioOutputProxyTest, CreateAndClose) { |
| 260 AudioOutputProxy* proxy = new AudioOutputProxy(dispatcher_impl_); | 407 AudioOutputProxy* proxy = new AudioOutputProxy(dispatcher_impl_); |
| 261 proxy->Close(); | 408 proxy->Close(); |
| 262 } | 409 } |
| 263 | 410 |
| 264 #if defined(ENABLE_AUDIO_MIXER) | 411 #if defined(ENABLE_AUDIO_MIXER) |
| 265 TEST_F(AudioOutputProxyTest, CreateAndClose_Mixer) { | 412 TEST_F(AudioOutputProxyTest, CreateAndClose_Mixer) { |
| 266 AudioOutputProxy* proxy = new AudioOutputProxy(mixer_); | 413 AudioOutputProxy* proxy = new AudioOutputProxy(mixer_); |
| 267 proxy->Close(); | 414 proxy->Close(); |
| 268 } | 415 } |
| 269 #endif | 416 #endif |
| 270 | 417 |
| 418 TEST_F(AudioOutputProxyTest, CreateAndClose_Resampler) { |
| 419 AudioOutputProxy* proxy = new AudioOutputProxy(resampler_); |
| 420 proxy->Close(); |
| 421 } |
| 422 |
| 271 TEST_F(AudioOutputProxyTest, OpenAndClose) { | 423 TEST_F(AudioOutputProxyTest, OpenAndClose) { |
| 272 OpenAndClose(dispatcher_impl_); | 424 OpenAndClose(dispatcher_impl_); |
| 273 } | 425 } |
| 274 | 426 |
| 275 #if defined(ENABLE_AUDIO_MIXER) | 427 #if defined(ENABLE_AUDIO_MIXER) |
| 276 TEST_F(AudioOutputProxyTest, OpenAndClose_Mixer) { | 428 TEST_F(AudioOutputProxyTest, OpenAndClose_Mixer) { |
| 277 OpenAndClose(mixer_); | 429 OpenAndClose(mixer_); |
| 278 } | 430 } |
| 279 #endif | 431 #endif |
| 280 | 432 |
| 433 TEST_F(AudioOutputProxyTest, OpenAndClose_Resampler) { |
| 434 OpenAndClose(resampler_); |
| 435 } |
| 436 |
| 281 // Create a stream, and verify that it is closed after kTestCloseDelayMs. | 437 // Create a stream, and verify that it is closed after kTestCloseDelayMs. |
| 282 // if it doesn't start playing. | 438 // if it doesn't start playing. |
| 283 TEST_F(AudioOutputProxyTest, CreateAndWait) { | 439 TEST_F(AudioOutputProxyTest, CreateAndWait) { |
| 284 MockAudioOutputStream stream; | 440 CreateAndWait(dispatcher_impl_); |
| 441 } |
| 285 | 442 |
| 286 EXPECT_CALL(manager(), MakeAudioOutputStream(_)) | 443 // Create a stream, and verify that it is closed after kTestCloseDelayMs. |
| 287 .WillOnce(Return(&stream)); | 444 // if it doesn't start playing. |
| 288 EXPECT_CALL(stream, Open()) | 445 TEST_F(AudioOutputProxyTest, CreateAndWait_Resampler) { |
| 289 .WillOnce(Return(true)); | 446 CreateAndWait(resampler_); |
| 290 EXPECT_CALL(stream, Close()) | |
| 291 .Times(1); | |
| 292 | |
| 293 AudioOutputProxy* proxy = new AudioOutputProxy(dispatcher_impl_); | |
| 294 EXPECT_TRUE(proxy->Open()); | |
| 295 | |
| 296 // Simulate a delay. | |
| 297 base::PlatformThread::Sleep( | |
| 298 base::TimeDelta::FromMilliseconds(kTestCloseDelayMs) * 2); | |
| 299 message_loop_.RunAllPending(); | |
| 300 | |
| 301 // Verify expectation before calling Close(). | |
| 302 Mock::VerifyAndClear(&stream); | |
| 303 | |
| 304 proxy->Close(); | |
| 305 } | 447 } |
| 306 | 448 |
| 307 TEST_F(AudioOutputProxyTest, StartAndStop) { | 449 TEST_F(AudioOutputProxyTest, StartAndStop) { |
| 308 StartAndStop(dispatcher_impl_); | 450 StartAndStop(dispatcher_impl_); |
| 309 } | 451 } |
| 310 | 452 |
| 311 #if defined(ENABLE_AUDIO_MIXER) | 453 #if defined(ENABLE_AUDIO_MIXER) |
| 312 TEST_F(AudioOutputProxyTest, StartAndStop_Mixer) { | 454 TEST_F(AudioOutputProxyTest, StartAndStop_Mixer) { |
| 313 StartAndStop(mixer_); | 455 StartAndStop(mixer_); |
| 314 } | 456 } |
| 315 #endif | 457 #endif |
| 316 | 458 |
| 459 TEST_F(AudioOutputProxyTest, StartAndStop_Resampler) { |
| 460 StartAndStop(resampler_); |
| 461 } |
| 462 |
| 317 TEST_F(AudioOutputProxyTest, CloseAfterStop) { | 463 TEST_F(AudioOutputProxyTest, CloseAfterStop) { |
| 318 CloseAfterStop(dispatcher_impl_); | 464 CloseAfterStop(dispatcher_impl_); |
| 319 } | 465 } |
| 320 | 466 |
| 321 #if defined(ENABLE_AUDIO_MIXER) | 467 #if defined(ENABLE_AUDIO_MIXER) |
| 322 TEST_F(AudioOutputProxyTest, CloseAfterStop_Mixer) { | 468 TEST_F(AudioOutputProxyTest, CloseAfterStop_Mixer) { |
| 323 CloseAfterStop(mixer_); | 469 CloseAfterStop(mixer_); |
| 324 } | 470 } |
| 325 #endif | 471 #endif |
| 326 | 472 |
| 473 TEST_F(AudioOutputProxyTest, CloseAfterStop_Resampler) { |
| 474 CloseAfterStop(resampler_); |
| 475 } |
| 476 |
| 327 TEST_F(AudioOutputProxyTest, TwoStreams) { | 477 TEST_F(AudioOutputProxyTest, TwoStreams) { |
| 328 TwoStreams(dispatcher_impl_); | 478 TwoStreams(dispatcher_impl_); |
| 329 } | 479 } |
| 330 | 480 |
| 331 #if defined(ENABLE_AUDIO_MIXER) | 481 #if defined(ENABLE_AUDIO_MIXER) |
| 332 TEST_F(AudioOutputProxyTest, TwoStreams_Mixer) { | 482 TEST_F(AudioOutputProxyTest, TwoStreams_Mixer) { |
| 333 TwoStreams(mixer_); | 483 TwoStreams(mixer_); |
| 334 } | 484 } |
| 335 #endif | 485 #endif |
| 336 | 486 |
| 487 TEST_F(AudioOutputProxyTest, TwoStreams_Resampler) { |
| 488 TwoStreams(resampler_); |
| 489 } |
| 490 |
| 337 // Two streams: verify that second stream is allocated when the first | 491 // Two streams: verify that second stream is allocated when the first |
| 338 // starts playing. | 492 // starts playing. |
| 339 TEST_F(AudioOutputProxyTest, TwoStreams_OnePlaying) { | 493 TEST_F(AudioOutputProxyTest, TwoStreams_OnePlaying) { |
| 340 MockAudioOutputStream stream1; | |
| 341 MockAudioOutputStream stream2; | |
| 342 | |
| 343 InitDispatcher(base::TimeDelta::FromSeconds(kTestBigCloseDelaySeconds)); | 494 InitDispatcher(base::TimeDelta::FromSeconds(kTestBigCloseDelaySeconds)); |
| 344 | 495 TwoStreams_OnePlaying(dispatcher_impl_); |
| 345 EXPECT_CALL(manager(), MakeAudioOutputStream(_)) | |
| 346 .WillOnce(Return(&stream1)) | |
| 347 .WillOnce(Return(&stream2)); | |
| 348 | |
| 349 EXPECT_CALL(stream1, Open()) | |
| 350 .WillOnce(Return(true)); | |
| 351 EXPECT_CALL(stream1, Start(_)) | |
| 352 .Times(1); | |
| 353 EXPECT_CALL(stream1, SetVolume(_)) | |
| 354 .Times(1); | |
| 355 EXPECT_CALL(stream1, Stop()) | |
| 356 .Times(1); | |
| 357 EXPECT_CALL(stream1, Close()) | |
| 358 .Times(1); | |
| 359 | |
| 360 EXPECT_CALL(stream2, Open()) | |
| 361 .WillOnce(Return(true)); | |
| 362 EXPECT_CALL(stream2, Close()) | |
| 363 .Times(1); | |
| 364 | |
| 365 AudioOutputProxy* proxy1 = new AudioOutputProxy(dispatcher_impl_); | |
| 366 AudioOutputProxy* proxy2 = new AudioOutputProxy(dispatcher_impl_); | |
| 367 EXPECT_TRUE(proxy1->Open()); | |
| 368 EXPECT_TRUE(proxy2->Open()); | |
| 369 | |
| 370 proxy1->Start(&callback_); | |
| 371 message_loop_.RunAllPending(); | |
| 372 proxy1->Stop(); | |
| 373 | |
| 374 proxy1->Close(); | |
| 375 proxy2->Close(); | |
| 376 } | 496 } |
| 377 | 497 |
| 378 #if defined(ENABLE_AUDIO_MIXER) | 498 #if defined(ENABLE_AUDIO_MIXER) |
| 379 // Two streams: verify that only one device will be created. | 499 // Two streams: verify that only one device will be created. |
| 380 TEST_F(AudioOutputProxyTest, TwoStreams_OnePlaying_Mixer) { | 500 TEST_F(AudioOutputProxyTest, TwoStreams_OnePlaying_Mixer) { |
| 381 MockAudioOutputStream stream; | 501 MockAudioOutputStream stream; |
| 382 | 502 |
| 383 InitDispatcher(base::TimeDelta::FromMilliseconds(kTestCloseDelayMs)); | 503 InitDispatcher(base::TimeDelta::FromMilliseconds(kTestCloseDelayMs)); |
| 384 | 504 |
| 385 EXPECT_CALL(manager(), MakeAudioOutputStream(_)) | 505 EXPECT_CALL(manager(), MakeAudioOutputStream(_)) |
| (...skipping 17 matching lines...) Expand all Loading... |
| 403 | 523 |
| 404 proxy1->Start(&callback_); | 524 proxy1->Start(&callback_); |
| 405 proxy1->Stop(); | 525 proxy1->Stop(); |
| 406 | 526 |
| 407 proxy1->Close(); | 527 proxy1->Close(); |
| 408 proxy2->Close(); | 528 proxy2->Close(); |
| 409 WaitForCloseTimer(kTestCloseDelayMs); | 529 WaitForCloseTimer(kTestCloseDelayMs); |
| 410 } | 530 } |
| 411 #endif | 531 #endif |
| 412 | 532 |
| 533 TEST_F(AudioOutputProxyTest, TwoStreams_OnePlaying_Resampler) { |
| 534 InitDispatcher(base::TimeDelta::FromSeconds(kTestBigCloseDelaySeconds)); |
| 535 TwoStreams_OnePlaying(resampler_); |
| 536 } |
| 537 |
| 413 // Two streams, both are playing. Dispatcher should not open a third stream. | 538 // Two streams, both are playing. Dispatcher should not open a third stream. |
| 414 TEST_F(AudioOutputProxyTest, TwoStreams_BothPlaying) { | 539 TEST_F(AudioOutputProxyTest, TwoStreams_BothPlaying) { |
| 415 MockAudioOutputStream stream1; | |
| 416 MockAudioOutputStream stream2; | |
| 417 | |
| 418 InitDispatcher(base::TimeDelta::FromSeconds(kTestBigCloseDelaySeconds)); | 540 InitDispatcher(base::TimeDelta::FromSeconds(kTestBigCloseDelaySeconds)); |
| 419 | 541 TwoStreams_BothPlaying(dispatcher_impl_); |
| 420 EXPECT_CALL(manager(), MakeAudioOutputStream(_)) | |
| 421 .WillOnce(Return(&stream1)) | |
| 422 .WillOnce(Return(&stream2)); | |
| 423 | |
| 424 EXPECT_CALL(stream1, Open()) | |
| 425 .WillOnce(Return(true)); | |
| 426 EXPECT_CALL(stream1, Start(_)) | |
| 427 .Times(1); | |
| 428 EXPECT_CALL(stream1, SetVolume(_)) | |
| 429 .Times(1); | |
| 430 EXPECT_CALL(stream1, Stop()) | |
| 431 .Times(1); | |
| 432 EXPECT_CALL(stream1, Close()) | |
| 433 .Times(1); | |
| 434 | |
| 435 EXPECT_CALL(stream2, Open()) | |
| 436 .WillOnce(Return(true)); | |
| 437 EXPECT_CALL(stream2, Start(_)) | |
| 438 .Times(1); | |
| 439 EXPECT_CALL(stream2, SetVolume(_)) | |
| 440 .Times(1); | |
| 441 EXPECT_CALL(stream2, Stop()) | |
| 442 .Times(1); | |
| 443 EXPECT_CALL(stream2, Close()) | |
| 444 .Times(1); | |
| 445 | |
| 446 AudioOutputProxy* proxy1 = new AudioOutputProxy(dispatcher_impl_); | |
| 447 AudioOutputProxy* proxy2 = new AudioOutputProxy(dispatcher_impl_); | |
| 448 EXPECT_TRUE(proxy1->Open()); | |
| 449 EXPECT_TRUE(proxy2->Open()); | |
| 450 | |
| 451 proxy1->Start(&callback_); | |
| 452 proxy2->Start(&callback_); | |
| 453 proxy1->Stop(); | |
| 454 proxy2->Stop(); | |
| 455 | |
| 456 proxy1->Close(); | |
| 457 proxy2->Close(); | |
| 458 } | 542 } |
| 459 | 543 |
| 460 #if defined(ENABLE_AUDIO_MIXER) | 544 #if defined(ENABLE_AUDIO_MIXER) |
| 461 // Two streams, both are playing. Still have to use single device. | 545 // Two streams, both are playing. Still have to use single device. |
| 462 // Also verifies that every proxy stream gets its own pending_bytes. | 546 // Also verifies that every proxy stream gets its own pending_bytes. |
| 463 TEST_F(AudioOutputProxyTest, TwoStreams_BothPlaying_Mixer) { | 547 TEST_F(AudioOutputProxyTest, TwoStreams_BothPlaying_Mixer) { |
| 464 MockAudioOutputStream stream; | 548 MockAudioOutputStream stream; |
| 465 | 549 |
| 466 InitDispatcher(base::TimeDelta::FromMilliseconds(kTestCloseDelayMs)); | 550 InitDispatcher(base::TimeDelta::FromMilliseconds(kTestCloseDelayMs)); |
| 467 | 551 |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 515 mixer_->OnMoreData(buf2, sizeof(buf2), AudioBuffersState(4, 0)); | 599 mixer_->OnMoreData(buf2, sizeof(buf2), AudioBuffersState(4, 0)); |
| 516 proxy1->Stop(); | 600 proxy1->Stop(); |
| 517 proxy2->Stop(); | 601 proxy2->Stop(); |
| 518 | 602 |
| 519 proxy1->Close(); | 603 proxy1->Close(); |
| 520 proxy2->Close(); | 604 proxy2->Close(); |
| 521 WaitForCloseTimer(kTestCloseDelayMs); | 605 WaitForCloseTimer(kTestCloseDelayMs); |
| 522 } | 606 } |
| 523 #endif | 607 #endif |
| 524 | 608 |
| 609 TEST_F(AudioOutputProxyTest, TwoStreams_BothPlaying_Resampler) { |
| 610 InitDispatcher(base::TimeDelta::FromSeconds(kTestBigCloseDelaySeconds)); |
| 611 TwoStreams_BothPlaying(resampler_); |
| 612 } |
| 613 |
| 525 TEST_F(AudioOutputProxyTest, OpenFailed) { | 614 TEST_F(AudioOutputProxyTest, OpenFailed) { |
| 526 OpenFailed(dispatcher_impl_); | 615 OpenFailed(dispatcher_impl_); |
| 527 } | 616 } |
| 528 | 617 |
| 529 #if defined(ENABLE_AUDIO_MIXER) | 618 #if defined(ENABLE_AUDIO_MIXER) |
| 530 TEST_F(AudioOutputProxyTest, OpenFailed_Mixer) { | 619 TEST_F(AudioOutputProxyTest, OpenFailed_Mixer) { |
| 531 OpenFailed(mixer_); | 620 OpenFailed(mixer_); |
| 532 } | 621 } |
| 533 #endif | 622 #endif |
| 534 | 623 |
| 624 TEST_F(AudioOutputProxyTest, OpenFailed_Resampler) { |
| 625 OpenFailed(resampler_); |
| 626 } |
| 627 |
| 535 // Start() method failed. | 628 // Start() method failed. |
| 536 TEST_F(AudioOutputProxyTest, StartFailed) { | 629 TEST_F(AudioOutputProxyTest, StartFailed) { |
| 537 MockAudioOutputStream stream; | 630 StartFailed(dispatcher_impl_); |
| 538 | |
| 539 EXPECT_CALL(manager(), MakeAudioOutputStream(_)) | |
| 540 .WillOnce(Return(&stream)); | |
| 541 EXPECT_CALL(stream, Open()) | |
| 542 .WillOnce(Return(true)); | |
| 543 EXPECT_CALL(stream, Close()) | |
| 544 .Times(1); | |
| 545 | |
| 546 AudioOutputProxy* proxy = new AudioOutputProxy(dispatcher_impl_); | |
| 547 EXPECT_TRUE(proxy->Open()); | |
| 548 | |
| 549 // Simulate a delay. | |
| 550 base::PlatformThread::Sleep( | |
| 551 base::TimeDelta::FromMilliseconds(kTestCloseDelayMs) * 2); | |
| 552 message_loop_.RunAllPending(); | |
| 553 | |
| 554 // Verify expectation before calling Close(). | |
| 555 Mock::VerifyAndClear(&stream); | |
| 556 | |
| 557 // |stream| is closed at this point. Start() should reopen it again. | |
| 558 EXPECT_CALL(manager(), MakeAudioOutputStream(_)) | |
| 559 .WillOnce(Return(reinterpret_cast<AudioOutputStream*>(NULL))); | |
| 560 | |
| 561 EXPECT_CALL(callback_, OnError(_, _)) | |
| 562 .Times(1); | |
| 563 | |
| 564 proxy->Start(&callback_); | |
| 565 | |
| 566 Mock::VerifyAndClear(&callback_); | |
| 567 | |
| 568 proxy->Close(); | |
| 569 } | 631 } |
| 570 | 632 |
| 571 #if defined(ENABLE_AUDIO_MIXER) | 633 #if defined(ENABLE_AUDIO_MIXER) |
| 572 // Start() method failed. | 634 // Start() method failed. |
| 573 TEST_F(AudioOutputProxyTest, StartFailed_Mixer) { | 635 TEST_F(AudioOutputProxyTest, StartFailed_Mixer) { |
| 574 MockAudioOutputStream stream; | 636 MockAudioOutputStream stream; |
| 575 | 637 |
| 576 EXPECT_CALL(manager(), MakeAudioOutputStream(_)) | 638 EXPECT_CALL(manager(), MakeAudioOutputStream(_)) |
| 577 .WillOnce(Return(&stream)); | 639 .WillOnce(Return(&stream)); |
| 578 EXPECT_CALL(stream, Open()) | 640 EXPECT_CALL(stream, Open()) |
| (...skipping 28 matching lines...) Expand all Loading... |
| 607 | 669 |
| 608 proxy2->Start(&callback_); | 670 proxy2->Start(&callback_); |
| 609 | 671 |
| 610 Mock::VerifyAndClear(&callback_); | 672 Mock::VerifyAndClear(&callback_); |
| 611 | 673 |
| 612 proxy2->Close(); | 674 proxy2->Close(); |
| 613 WaitForCloseTimer(kTestCloseDelayMs); | 675 WaitForCloseTimer(kTestCloseDelayMs); |
| 614 } | 676 } |
| 615 #endif | 677 #endif |
| 616 | 678 |
| 679 TEST_F(AudioOutputProxyTest, StartFailed_Resampler) { |
| 680 StartFailed(resampler_); |
| 681 } |
| 682 |
| 617 } // namespace media | 683 } // namespace media |
| OLD | NEW |