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 656 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
667 | 667 |
668 proxy1->Stop(); | 668 proxy1->Stop(); |
669 CloseAndWaitForCloseTimer(proxy1, &stream1); | 669 CloseAndWaitForCloseTimer(proxy1, &stream1); |
670 | 670 |
671 EXPECT_TRUE(stream1.stop_called()); | 671 EXPECT_TRUE(stream1.stop_called()); |
672 EXPECT_TRUE(stream1.start_called()); | 672 EXPECT_TRUE(stream1.start_called()); |
673 EXPECT_TRUE(stream2.stop_called()); | 673 EXPECT_TRUE(stream2.stop_called()); |
674 EXPECT_TRUE(stream2.start_called()); | 674 EXPECT_TRUE(stream2.start_called()); |
675 } | 675 } |
676 | 676 |
| 677 // Simulate failures to open both the low latency and the fallback high latency |
| 678 // stream and ensure AudioOutputResampler falls back to a fake stream. Ensure |
| 679 // that after the close delay elapses, opening another stream succeeds with a |
| 680 // non-fake stream. |
| 681 TEST_F(AudioOutputResamplerTest, FallbackRecovery) { |
| 682 MockAudioOutputStream fake_stream(&manager_, params_); |
| 683 |
| 684 // Trigger the fallback mechanism until a fake output stream is created. |
| 685 #if defined(OS_WIN) |
| 686 static const int kFallbackCount = 2; |
| 687 #else |
| 688 static const int kFallbackCount = 1; |
| 689 #endif |
| 690 EXPECT_CALL(manager(), MakeAudioOutputStream(_, _)) |
| 691 .Times(kFallbackCount) |
| 692 .WillRepeatedly(Return(static_cast<AudioOutputStream*>(NULL))); |
| 693 EXPECT_CALL(manager(), |
| 694 MakeAudioOutputStream( |
| 695 AllOf(testing::Property(&AudioParameters::format, |
| 696 AudioParameters::AUDIO_FAKE), |
| 697 testing::Property(&AudioParameters::sample_rate, |
| 698 params_.sample_rate()), |
| 699 testing::Property(&AudioParameters::frames_per_buffer, |
| 700 params_.frames_per_buffer())), |
| 701 _)).WillOnce(Return(&fake_stream)); |
| 702 EXPECT_CALL(fake_stream, Open()).WillOnce(Return(true)); |
| 703 AudioOutputProxy* proxy = new AudioOutputProxy(resampler_.get()); |
| 704 EXPECT_TRUE(proxy->Open()); |
| 705 CloseAndWaitForCloseTimer(proxy, &fake_stream); |
| 706 |
| 707 // Once all proxies have been closed, AudioOutputResampler will start the |
| 708 // reinitialization timer and execute it after the close delay elapses. |
| 709 base::RunLoop run_loop; |
| 710 message_loop_.PostDelayedTask( |
| 711 FROM_HERE, run_loop.QuitClosure(), |
| 712 base::TimeDelta::FromMilliseconds(2 * kTestCloseDelayMs)); |
| 713 run_loop.Run(); |
| 714 |
| 715 // Verify a non-fake stream can be created. |
| 716 MockAudioOutputStream real_stream(&manager_, params_); |
| 717 EXPECT_CALL(manager(), |
| 718 MakeAudioOutputStream( |
| 719 testing::Property(&AudioParameters::format, |
| 720 testing::Ne(AudioParameters::AUDIO_FAKE)), |
| 721 _)).WillOnce(Return(&real_stream)); |
| 722 |
| 723 // Stream1 should be able to successfully open and start. |
| 724 EXPECT_CALL(real_stream, Open()).WillOnce(Return(true)); |
| 725 proxy = new AudioOutputProxy(resampler_.get()); |
| 726 EXPECT_TRUE(proxy->Open()); |
| 727 CloseAndWaitForCloseTimer(proxy, &real_stream); |
| 728 } |
| 729 |
677 } // namespace media | 730 } // namespace media |
OLD | NEW |