| 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 "base/threading/simple_thread.h" | 10 #include "base/threading/simple_thread.h" |
| (...skipping 466 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 477 if (!audio_thread_.get()) { | 477 if (!audio_thread_.get()) { |
| 478 ASSERT_FALSE(audio_thread_runner_.get()); | 478 ASSERT_FALSE(audio_thread_runner_.get()); |
| 479 return; | 479 return; |
| 480 } | 480 } |
| 481 ASSERT_TRUE(audio_thread_runner_.get()); | 481 ASSERT_TRUE(audio_thread_runner_.get()); |
| 482 audio_thread_runner_->Stop(); | 482 audio_thread_runner_->Stop(); |
| 483 audio_thread_->Join(); | 483 audio_thread_->Join(); |
| 484 } | 484 } |
| 485 | 485 |
| 486 virtual void InitDispatcher(base::TimeDelta close_delay) { | 486 virtual void InitDispatcher(base::TimeDelta close_delay) { |
| 487 InitDispatcher(close_delay, AudioParameters::AUDIO_PCM_LINEAR); |
| 488 } |
| 489 |
| 490 virtual void InitDispatcher(base::TimeDelta close_delay, |
| 491 AudioParameters::Format output_format) { |
| 487 AudioOutputProxyTest::InitDispatcher(close_delay); | 492 AudioOutputProxyTest::InitDispatcher(close_delay); |
| 488 // Attempt shutdown of audio thread in case InitDispatcher() was called | 493 // Attempt shutdown of audio thread in case InitDispatcher() was called |
| 489 // previously. | 494 // previously. |
| 490 ShutdownAudioThread(); | 495 ShutdownAudioThread(); |
| 491 resampler_params_ = AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, | 496 resampler_params_ = AudioParameters( |
| 492 CHANNEL_LAYOUT_STEREO, 48000, 16, 128); | 497 output_format, CHANNEL_LAYOUT_STEREO, 48000, 16, 128); |
| 493 resampler_ = new AudioOutputResampler( | 498 resampler_ = new AudioOutputResampler( |
| 494 &manager(), params_, resampler_params_, close_delay); | 499 &manager(), params_, resampler_params_, close_delay); |
| 495 StartAudioThread(); | 500 StartAudioThread(); |
| 496 } | 501 } |
| 497 | 502 |
| 498 virtual void OnStart() { | 503 virtual void OnStart() { |
| 499 // Let start run for a bit. | 504 // Let start run for a bit. |
| 500 message_loop_.RunAllPending(); | 505 message_loop_.RunAllPending(); |
| 501 base::PlatformThread::Sleep( | 506 base::PlatformThread::Sleep( |
| 502 base::TimeDelta::FromMilliseconds(kStartRunTimeMs)); | 507 base::TimeDelta::FromMilliseconds(kStartRunTimeMs)); |
| (...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 779 | 784 |
| 780 proxy2->Close(); | 785 proxy2->Close(); |
| 781 WaitForCloseTimer(kTestCloseDelayMs); | 786 WaitForCloseTimer(kTestCloseDelayMs); |
| 782 } | 787 } |
| 783 #endif | 788 #endif |
| 784 | 789 |
| 785 TEST_F(AudioOutputResamplerTest, StartFailed) { | 790 TEST_F(AudioOutputResamplerTest, StartFailed) { |
| 786 StartFailed(resampler_); | 791 StartFailed(resampler_); |
| 787 } | 792 } |
| 788 | 793 |
| 794 // Simulate AudioOutputStream::Create() failure with a low latency stream and |
| 795 // ensure AudioOutputResampler falls back to the high latency path. |
| 796 TEST_F(AudioOutputResamplerTest, LowLatencyCreateFailedFallback) { |
| 797 InitDispatcher(base::TimeDelta::FromSeconds(kTestCloseDelayMs), |
| 798 AudioParameters::AUDIO_PCM_LOW_LATENCY); |
| 799 |
| 800 MockAudioOutputStream stream; |
| 801 EXPECT_CALL(manager(), MakeAudioOutputStream(_)) |
| 802 .Times(2) |
| 803 .WillOnce(Return(static_cast<AudioOutputStream*>(NULL))) |
| 804 .WillRepeatedly(Return(&stream)); |
| 805 EXPECT_CALL(stream, Open()) |
| 806 .WillOnce(Return(true)); |
| 807 EXPECT_CALL(stream, Close()) |
| 808 .Times(1); |
| 809 |
| 810 AudioOutputProxy* proxy = new AudioOutputProxy(resampler_); |
| 811 EXPECT_TRUE(proxy->Open()); |
| 812 proxy->Close(); |
| 813 WaitForCloseTimer(kTestCloseDelayMs); |
| 814 } |
| 815 |
| 816 // Simulate AudioOutputStream::Open() failure with a low latency stream and |
| 817 // ensure AudioOutputResampler falls back to the high latency path. |
| 818 TEST_F(AudioOutputResamplerTest, LowLatencyOpenFailedFallback) { |
| 819 InitDispatcher(base::TimeDelta::FromSeconds(kTestCloseDelayMs), |
| 820 AudioParameters::AUDIO_PCM_LOW_LATENCY); |
| 821 |
| 822 MockAudioOutputStream failed_stream; |
| 823 MockAudioOutputStream okay_stream; |
| 824 EXPECT_CALL(manager(), MakeAudioOutputStream(_)) |
| 825 .Times(2) |
| 826 .WillOnce(Return(&failed_stream)) |
| 827 .WillRepeatedly(Return(&okay_stream)); |
| 828 EXPECT_CALL(failed_stream, Open()) |
| 829 .WillOnce(Return(false)); |
| 830 EXPECT_CALL(failed_stream, Close()) |
| 831 .Times(1); |
| 832 EXPECT_CALL(okay_stream, Open()) |
| 833 .WillOnce(Return(true)); |
| 834 EXPECT_CALL(okay_stream, Close()) |
| 835 .Times(1); |
| 836 |
| 837 AudioOutputProxy* proxy = new AudioOutputProxy(resampler_); |
| 838 EXPECT_TRUE(proxy->Open()); |
| 839 proxy->Close(); |
| 840 WaitForCloseTimer(kTestCloseDelayMs); |
| 841 } |
| 842 |
| 843 // Simulate failures to open both the low latency and the fallback high latency |
| 844 // stream and ensure AudioOutputResampler terminates normally. |
| 845 TEST_F(AudioOutputResamplerTest, LowLatencyFallbackFailed) { |
| 846 InitDispatcher(base::TimeDelta::FromSeconds(kTestCloseDelayMs), |
| 847 AudioParameters::AUDIO_PCM_LOW_LATENCY); |
| 848 |
| 849 EXPECT_CALL(manager(), MakeAudioOutputStream(_)) |
| 850 .Times(2) |
| 851 .WillRepeatedly(Return(static_cast<AudioOutputStream*>(NULL))); |
| 852 |
| 853 AudioOutputProxy* proxy = new AudioOutputProxy(resampler_); |
| 854 EXPECT_FALSE(proxy->Open()); |
| 855 proxy->Close(); |
| 856 WaitForCloseTimer(kTestCloseDelayMs); |
| 857 } |
| 858 |
| 789 } // namespace media | 859 } // namespace media |
| OLD | NEW |