| 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 427 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 438 base::TimeDelta::FromMilliseconds(kStartRunTimeMs)); | 438 base::TimeDelta::FromMilliseconds(kStartRunTimeMs)); |
| 439 run_loop.Run(); | 439 run_loop.Run(); |
| 440 } | 440 } |
| 441 | 441 |
| 442 protected: | 442 protected: |
| 443 AudioParameters resampler_params_; | 443 AudioParameters resampler_params_; |
| 444 scoped_refptr<AudioOutputResampler> resampler_; | 444 scoped_refptr<AudioOutputResampler> resampler_; |
| 445 }; | 445 }; |
| 446 | 446 |
| 447 TEST_F(AudioOutputProxyTest, CreateAndClose) { | 447 TEST_F(AudioOutputProxyTest, CreateAndClose) { |
| 448 AudioOutputProxy* proxy = new AudioOutputProxy(dispatcher_impl_); | 448 AudioOutputProxy* proxy = new AudioOutputProxy(dispatcher_impl_.get()); |
| 449 proxy->Close(); | 449 proxy->Close(); |
| 450 } | 450 } |
| 451 | 451 |
| 452 TEST_F(AudioOutputResamplerTest, CreateAndClose) { | 452 TEST_F(AudioOutputResamplerTest, CreateAndClose) { |
| 453 AudioOutputProxy* proxy = new AudioOutputProxy(resampler_); | 453 AudioOutputProxy* proxy = new AudioOutputProxy(resampler_.get()); |
| 454 proxy->Close(); | 454 proxy->Close(); |
| 455 } | 455 } |
| 456 | 456 |
| 457 TEST_F(AudioOutputProxyTest, OpenAndClose) { | 457 TEST_F(AudioOutputProxyTest, OpenAndClose) { |
| 458 OpenAndClose(dispatcher_impl_); | 458 OpenAndClose(dispatcher_impl_.get()); |
| 459 } | 459 } |
| 460 | 460 |
| 461 TEST_F(AudioOutputResamplerTest, OpenAndClose) { | 461 TEST_F(AudioOutputResamplerTest, OpenAndClose) { |
| 462 OpenAndClose(resampler_); | 462 OpenAndClose(resampler_.get()); |
| 463 } | 463 } |
| 464 | 464 |
| 465 // Create a stream, and verify that it is closed after kTestCloseDelayMs. | 465 // Create a stream, and verify that it is closed after kTestCloseDelayMs. |
| 466 // if it doesn't start playing. | 466 // if it doesn't start playing. |
| 467 TEST_F(AudioOutputProxyTest, CreateAndWait) { | 467 TEST_F(AudioOutputProxyTest, CreateAndWait) { |
| 468 CreateAndWait(dispatcher_impl_); | 468 CreateAndWait(dispatcher_impl_.get()); |
| 469 } | 469 } |
| 470 | 470 |
| 471 // Create a stream, and verify that it is closed after kTestCloseDelayMs. | 471 // Create a stream, and verify that it is closed after kTestCloseDelayMs. |
| 472 // if it doesn't start playing. | 472 // if it doesn't start playing. |
| 473 TEST_F(AudioOutputResamplerTest, CreateAndWait) { | 473 TEST_F(AudioOutputResamplerTest, CreateAndWait) { |
| 474 CreateAndWait(resampler_); | 474 CreateAndWait(resampler_.get()); |
| 475 } | 475 } |
| 476 | 476 |
| 477 TEST_F(AudioOutputProxyTest, StartAndStop) { | 477 TEST_F(AudioOutputProxyTest, StartAndStop) { |
| 478 StartAndStop(dispatcher_impl_); | 478 StartAndStop(dispatcher_impl_.get()); |
| 479 } | 479 } |
| 480 | 480 |
| 481 TEST_F(AudioOutputResamplerTest, StartAndStop) { | 481 TEST_F(AudioOutputResamplerTest, StartAndStop) { |
| 482 StartAndStop(resampler_); | 482 StartAndStop(resampler_.get()); |
| 483 } | 483 } |
| 484 | 484 |
| 485 TEST_F(AudioOutputProxyTest, CloseAfterStop) { | 485 TEST_F(AudioOutputProxyTest, CloseAfterStop) { |
| 486 CloseAfterStop(dispatcher_impl_); | 486 CloseAfterStop(dispatcher_impl_.get()); |
| 487 } | 487 } |
| 488 | 488 |
| 489 TEST_F(AudioOutputResamplerTest, CloseAfterStop) { | 489 TEST_F(AudioOutputResamplerTest, CloseAfterStop) { |
| 490 CloseAfterStop(resampler_); | 490 CloseAfterStop(resampler_.get()); |
| 491 } | 491 } |
| 492 | 492 |
| 493 TEST_F(AudioOutputProxyTest, TwoStreams) { TwoStreams(dispatcher_impl_); } | 493 TEST_F(AudioOutputProxyTest, TwoStreams) { |
| 494 TwoStreams(dispatcher_impl_.get()); |
| 495 } |
| 494 | 496 |
| 495 TEST_F(AudioOutputResamplerTest, TwoStreams) { TwoStreams(resampler_); } | 497 TEST_F(AudioOutputResamplerTest, TwoStreams) { |
| 498 TwoStreams(resampler_.get()); |
| 499 } |
| 496 | 500 |
| 497 // Two streams: verify that second stream is allocated when the first | 501 // Two streams: verify that second stream is allocated when the first |
| 498 // starts playing. | 502 // starts playing. |
| 499 TEST_F(AudioOutputProxyTest, OneStream_TwoPlays) { | 503 TEST_F(AudioOutputProxyTest, OneStream_TwoPlays) { |
| 500 OneStream_TwoPlays(dispatcher_impl_); | 504 OneStream_TwoPlays(dispatcher_impl_.get()); |
| 501 } | 505 } |
| 502 | 506 |
| 503 TEST_F(AudioOutputResamplerTest, OneStream_TwoPlays) { | 507 TEST_F(AudioOutputResamplerTest, OneStream_TwoPlays) { |
| 504 OneStream_TwoPlays(resampler_); | 508 OneStream_TwoPlays(resampler_.get()); |
| 505 } | 509 } |
| 506 | 510 |
| 507 // Two streams, both are playing. Dispatcher should not open a third stream. | 511 // Two streams, both are playing. Dispatcher should not open a third stream. |
| 508 TEST_F(AudioOutputProxyTest, TwoStreams_BothPlaying) { | 512 TEST_F(AudioOutputProxyTest, TwoStreams_BothPlaying) { |
| 509 TwoStreams_BothPlaying(dispatcher_impl_); | 513 TwoStreams_BothPlaying(dispatcher_impl_.get()); |
| 510 } | 514 } |
| 511 | 515 |
| 512 TEST_F(AudioOutputResamplerTest, TwoStreams_BothPlaying) { | 516 TEST_F(AudioOutputResamplerTest, TwoStreams_BothPlaying) { |
| 513 TwoStreams_BothPlaying(resampler_); | 517 TwoStreams_BothPlaying(resampler_.get()); |
| 514 } | 518 } |
| 515 | 519 |
| 516 TEST_F(AudioOutputProxyTest, OpenFailed) { OpenFailed(dispatcher_impl_); } | 520 TEST_F(AudioOutputProxyTest, OpenFailed) { |
| 521 OpenFailed(dispatcher_impl_.get()); |
| 522 } |
| 517 | 523 |
| 518 // Start() method failed. | 524 // Start() method failed. |
| 519 TEST_F(AudioOutputProxyTest, StartFailed) { | 525 TEST_F(AudioOutputProxyTest, StartFailed) { |
| 520 StartFailed(dispatcher_impl_); | 526 StartFailed(dispatcher_impl_.get()); |
| 521 } | 527 } |
| 522 | 528 |
| 523 TEST_F(AudioOutputResamplerTest, StartFailed) { StartFailed(resampler_); } | 529 TEST_F(AudioOutputResamplerTest, StartFailed) { |
| 530 StartFailed(resampler_.get()); |
| 531 } |
| 524 | 532 |
| 525 // Simulate AudioOutputStream::Create() failure with a low latency stream and | 533 // Simulate AudioOutputStream::Create() failure with a low latency stream and |
| 526 // ensure AudioOutputResampler falls back to the high latency path. | 534 // ensure AudioOutputResampler falls back to the high latency path. |
| 527 TEST_F(AudioOutputResamplerTest, LowLatencyCreateFailedFallback) { | 535 TEST_F(AudioOutputResamplerTest, LowLatencyCreateFailedFallback) { |
| 528 MockAudioOutputStream stream(&manager_, params_); | 536 MockAudioOutputStream stream(&manager_, params_); |
| 529 EXPECT_CALL(manager(), MakeAudioOutputStream(_, _)) | 537 EXPECT_CALL(manager(), MakeAudioOutputStream(_, _)) |
| 530 .Times(2) | 538 .Times(2) |
| 531 .WillOnce(Return(static_cast<AudioOutputStream*>(NULL))) | 539 .WillOnce(Return(static_cast<AudioOutputStream*>(NULL))) |
| 532 .WillRepeatedly(Return(&stream)); | 540 .WillRepeatedly(Return(&stream)); |
| 533 EXPECT_CALL(stream, Open()) | 541 EXPECT_CALL(stream, Open()) |
| 534 .WillOnce(Return(true)); | 542 .WillOnce(Return(true)); |
| 535 | 543 |
| 536 AudioOutputProxy* proxy = new AudioOutputProxy(resampler_); | 544 AudioOutputProxy* proxy = new AudioOutputProxy(resampler_.get()); |
| 537 EXPECT_TRUE(proxy->Open()); | 545 EXPECT_TRUE(proxy->Open()); |
| 538 CloseAndWaitForCloseTimer(proxy, &stream); | 546 CloseAndWaitForCloseTimer(proxy, &stream); |
| 539 } | 547 } |
| 540 | 548 |
| 541 // Simulate AudioOutputStream::Open() failure with a low latency stream and | 549 // Simulate AudioOutputStream::Open() failure with a low latency stream and |
| 542 // ensure AudioOutputResampler falls back to the high latency path. | 550 // ensure AudioOutputResampler falls back to the high latency path. |
| 543 TEST_F(AudioOutputResamplerTest, LowLatencyOpenFailedFallback) { | 551 TEST_F(AudioOutputResamplerTest, LowLatencyOpenFailedFallback) { |
| 544 MockAudioOutputStream failed_stream(&manager_, params_); | 552 MockAudioOutputStream failed_stream(&manager_, params_); |
| 545 MockAudioOutputStream okay_stream(&manager_, params_); | 553 MockAudioOutputStream okay_stream(&manager_, params_); |
| 546 EXPECT_CALL(manager(), MakeAudioOutputStream(_, _)) | 554 EXPECT_CALL(manager(), MakeAudioOutputStream(_, _)) |
| 547 .Times(2) | 555 .Times(2) |
| 548 .WillOnce(Return(&failed_stream)) | 556 .WillOnce(Return(&failed_stream)) |
| 549 .WillRepeatedly(Return(&okay_stream)); | 557 .WillRepeatedly(Return(&okay_stream)); |
| 550 EXPECT_CALL(failed_stream, Open()) | 558 EXPECT_CALL(failed_stream, Open()) |
| 551 .WillOnce(Return(false)); | 559 .WillOnce(Return(false)); |
| 552 EXPECT_CALL(failed_stream, Close()) | 560 EXPECT_CALL(failed_stream, Close()) |
| 553 .Times(1); | 561 .Times(1); |
| 554 EXPECT_CALL(okay_stream, Open()) | 562 EXPECT_CALL(okay_stream, Open()) |
| 555 .WillOnce(Return(true)); | 563 .WillOnce(Return(true)); |
| 556 | 564 |
| 557 AudioOutputProxy* proxy = new AudioOutputProxy(resampler_); | 565 AudioOutputProxy* proxy = new AudioOutputProxy(resampler_.get()); |
| 558 EXPECT_TRUE(proxy->Open()); | 566 EXPECT_TRUE(proxy->Open()); |
| 559 CloseAndWaitForCloseTimer(proxy, &okay_stream); | 567 CloseAndWaitForCloseTimer(proxy, &okay_stream); |
| 560 } | 568 } |
| 561 | 569 |
| 562 // Simulate failures to open both the low latency and the fallback high latency | 570 // Simulate failures to open both the low latency and the fallback high latency |
| 563 // stream and ensure AudioOutputResampler falls back to a fake stream. | 571 // stream and ensure AudioOutputResampler falls back to a fake stream. |
| 564 TEST_F(AudioOutputResamplerTest, HighLatencyFallbackFailed) { | 572 TEST_F(AudioOutputResamplerTest, HighLatencyFallbackFailed) { |
| 565 MockAudioOutputStream okay_stream(&manager_, params_); | 573 MockAudioOutputStream okay_stream(&manager_, params_); |
| 566 | 574 |
| 567 // Only Windows has a high latency output driver that is not the same as the low | 575 // Only Windows has a high latency output driver that is not the same as the low |
| (...skipping 13 matching lines...) Expand all Loading... |
| 581 testing::Property(&AudioParameters::format, AudioParameters::AUDIO_FAKE), | 589 testing::Property(&AudioParameters::format, AudioParameters::AUDIO_FAKE), |
| 582 testing::Property(&AudioParameters::sample_rate, params_.sample_rate()), | 590 testing::Property(&AudioParameters::sample_rate, params_.sample_rate()), |
| 583 testing::Property( | 591 testing::Property( |
| 584 &AudioParameters::frames_per_buffer, params_.frames_per_buffer())), | 592 &AudioParameters::frames_per_buffer, params_.frames_per_buffer())), |
| 585 _)) | 593 _)) |
| 586 .Times(1) | 594 .Times(1) |
| 587 .WillOnce(Return(&okay_stream)); | 595 .WillOnce(Return(&okay_stream)); |
| 588 EXPECT_CALL(okay_stream, Open()) | 596 EXPECT_CALL(okay_stream, Open()) |
| 589 .WillOnce(Return(true)); | 597 .WillOnce(Return(true)); |
| 590 | 598 |
| 591 AudioOutputProxy* proxy = new AudioOutputProxy(resampler_); | 599 AudioOutputProxy* proxy = new AudioOutputProxy(resampler_.get()); |
| 592 EXPECT_TRUE(proxy->Open()); | 600 EXPECT_TRUE(proxy->Open()); |
| 593 CloseAndWaitForCloseTimer(proxy, &okay_stream); | 601 CloseAndWaitForCloseTimer(proxy, &okay_stream); |
| 594 } | 602 } |
| 595 | 603 |
| 596 // Simulate failures to open both the low latency, the fallback high latency | 604 // Simulate failures to open both the low latency, the fallback high latency |
| 597 // stream, and the fake audio output stream and ensure AudioOutputResampler | 605 // stream, and the fake audio output stream and ensure AudioOutputResampler |
| 598 // terminates normally. | 606 // terminates normally. |
| 599 TEST_F(AudioOutputResamplerTest, AllFallbackFailed) { | 607 TEST_F(AudioOutputResamplerTest, AllFallbackFailed) { |
| 600 // Only Windows has a high latency output driver that is not the same as the low | 608 // Only Windows has a high latency output driver that is not the same as the low |
| 601 // latency path. | 609 // latency path. |
| 602 #if defined(OS_WIN) | 610 #if defined(OS_WIN) |
| 603 static const int kFallbackCount = 3; | 611 static const int kFallbackCount = 3; |
| 604 #else | 612 #else |
| 605 static const int kFallbackCount = 2; | 613 static const int kFallbackCount = 2; |
| 606 #endif | 614 #endif |
| 607 EXPECT_CALL(manager(), MakeAudioOutputStream(_, _)) | 615 EXPECT_CALL(manager(), MakeAudioOutputStream(_, _)) |
| 608 .Times(kFallbackCount) | 616 .Times(kFallbackCount) |
| 609 .WillRepeatedly(Return(static_cast<AudioOutputStream*>(NULL))); | 617 .WillRepeatedly(Return(static_cast<AudioOutputStream*>(NULL))); |
| 610 | 618 |
| 611 AudioOutputProxy* proxy = new AudioOutputProxy(resampler_); | 619 AudioOutputProxy* proxy = new AudioOutputProxy(resampler_.get()); |
| 612 EXPECT_FALSE(proxy->Open()); | 620 EXPECT_FALSE(proxy->Open()); |
| 613 proxy->Close(); | 621 proxy->Close(); |
| 614 } | 622 } |
| 615 | 623 |
| 616 // Simulate an eventual OpenStream() failure; i.e. successful OpenStream() calls | 624 // Simulate an eventual OpenStream() failure; i.e. successful OpenStream() calls |
| 617 // eventually followed by one which fails; root cause of http://crbug.com/150619 | 625 // eventually followed by one which fails; root cause of http://crbug.com/150619 |
| 618 TEST_F(AudioOutputResamplerTest, LowLatencyOpenEventuallyFails) { | 626 TEST_F(AudioOutputResamplerTest, LowLatencyOpenEventuallyFails) { |
| 619 MockAudioOutputStream stream1(&manager_, params_); | 627 MockAudioOutputStream stream1(&manager_, params_); |
| 620 MockAudioOutputStream stream2(&manager_, params_); | 628 MockAudioOutputStream stream2(&manager_, params_); |
| 621 | 629 |
| 622 // Setup the mock such that all three streams are successfully created. | 630 // Setup the mock such that all three streams are successfully created. |
| 623 EXPECT_CALL(manager(), MakeAudioOutputStream(_, _)) | 631 EXPECT_CALL(manager(), MakeAudioOutputStream(_, _)) |
| 624 .WillOnce(Return(&stream1)) | 632 .WillOnce(Return(&stream1)) |
| 625 .WillOnce(Return(&stream2)) | 633 .WillOnce(Return(&stream2)) |
| 626 .WillRepeatedly(Return(static_cast<AudioOutputStream*>(NULL))); | 634 .WillRepeatedly(Return(static_cast<AudioOutputStream*>(NULL))); |
| 627 | 635 |
| 628 // Stream1 should be able to successfully open and start. | 636 // Stream1 should be able to successfully open and start. |
| 629 EXPECT_CALL(stream1, Open()) | 637 EXPECT_CALL(stream1, Open()) |
| 630 .WillOnce(Return(true)); | 638 .WillOnce(Return(true)); |
| 631 EXPECT_CALL(stream1, SetVolume(_)) | 639 EXPECT_CALL(stream1, SetVolume(_)) |
| 632 .Times(1); | 640 .Times(1); |
| 633 | 641 |
| 634 // Stream2 should also be able to successfully open and start. | 642 // Stream2 should also be able to successfully open and start. |
| 635 EXPECT_CALL(stream2, Open()) | 643 EXPECT_CALL(stream2, Open()) |
| 636 .WillOnce(Return(true)); | 644 .WillOnce(Return(true)); |
| 637 EXPECT_CALL(stream2, SetVolume(_)) | 645 EXPECT_CALL(stream2, SetVolume(_)) |
| 638 .Times(1); | 646 .Times(1); |
| 639 | 647 |
| 640 // Open and start the first proxy and stream. | 648 // Open and start the first proxy and stream. |
| 641 AudioOutputProxy* proxy1 = new AudioOutputProxy(resampler_); | 649 AudioOutputProxy* proxy1 = new AudioOutputProxy(resampler_.get()); |
| 642 EXPECT_TRUE(proxy1->Open()); | 650 EXPECT_TRUE(proxy1->Open()); |
| 643 proxy1->Start(&callback_); | 651 proxy1->Start(&callback_); |
| 644 OnStart(); | 652 OnStart(); |
| 645 | 653 |
| 646 // Open and start the second proxy and stream. | 654 // Open and start the second proxy and stream. |
| 647 AudioOutputProxy* proxy2 = new AudioOutputProxy(resampler_); | 655 AudioOutputProxy* proxy2 = new AudioOutputProxy(resampler_.get()); |
| 648 EXPECT_TRUE(proxy2->Open()); | 656 EXPECT_TRUE(proxy2->Open()); |
| 649 proxy2->Start(&callback_); | 657 proxy2->Start(&callback_); |
| 650 OnStart(); | 658 OnStart(); |
| 651 | 659 |
| 652 // Attempt to open the third stream which should fail. | 660 // Attempt to open the third stream which should fail. |
| 653 AudioOutputProxy* proxy3 = new AudioOutputProxy(resampler_); | 661 AudioOutputProxy* proxy3 = new AudioOutputProxy(resampler_.get()); |
| 654 EXPECT_FALSE(proxy3->Open()); | 662 EXPECT_FALSE(proxy3->Open()); |
| 655 proxy3->Close(); | 663 proxy3->Close(); |
| 656 | 664 |
| 657 // Perform the required Stop()/Close() shutdown dance for each proxy. Under | 665 // Perform the required Stop()/Close() shutdown dance for each proxy. Under |
| 658 // the hood each proxy should correctly call CloseStream() if OpenStream() | 666 // the hood each proxy should correctly call CloseStream() if OpenStream() |
| 659 // succeeded or not. | 667 // succeeded or not. |
| 660 proxy2->Stop(); | 668 proxy2->Stop(); |
| 661 CloseAndWaitForCloseTimer(proxy2, &stream2); | 669 CloseAndWaitForCloseTimer(proxy2, &stream2); |
| 662 | 670 |
| 663 proxy1->Stop(); | 671 proxy1->Stop(); |
| 664 CloseAndWaitForCloseTimer(proxy1, &stream1); | 672 CloseAndWaitForCloseTimer(proxy1, &stream1); |
| 665 | 673 |
| 666 EXPECT_TRUE(stream1.stop_called()); | 674 EXPECT_TRUE(stream1.stop_called()); |
| 667 EXPECT_TRUE(stream1.start_called()); | 675 EXPECT_TRUE(stream1.start_called()); |
| 668 EXPECT_TRUE(stream2.stop_called()); | 676 EXPECT_TRUE(stream2.stop_called()); |
| 669 EXPECT_TRUE(stream2.start_called()); | 677 EXPECT_TRUE(stream2.start_called()); |
| 670 } | 678 } |
| 671 | 679 |
| 672 } // namespace media | 680 } // namespace media |
| OLD | NEW |