| 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/command_line.h" |
| 7 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
| 8 #include "base/message_loop_proxy.h" | 9 #include "base/message_loop_proxy.h" |
| 9 #include "base/threading/platform_thread.h" | 10 #include "base/threading/platform_thread.h" |
| 10 #include "base/threading/simple_thread.h" | 11 #include "base/threading/simple_thread.h" |
| 11 #include "media/audio/audio_output_dispatcher_impl.h" | 12 #include "media/audio/audio_output_dispatcher_impl.h" |
| 12 #include "media/audio/audio_output_proxy.h" | 13 #include "media/audio/audio_output_proxy.h" |
| 13 #include "media/audio/audio_output_resampler.h" | 14 #include "media/audio/audio_output_resampler.h" |
| 14 #include "media/audio/audio_manager.h" | 15 #include "media/audio/audio_manager.h" |
| 16 #include "media/base/media_switches.h" |
| 15 #include "testing/gmock/include/gmock/gmock.h" | 17 #include "testing/gmock/include/gmock/gmock.h" |
| 16 #include "testing/gtest/include/gtest/gtest.h" | 18 #include "testing/gtest/include/gtest/gtest.h" |
| 17 | 19 |
| 18 // TODO(dalecurtis): Temporarily disabled while switching pipeline to use float, | 20 // TODO(dalecurtis): Temporarily disabled while switching pipeline to use float, |
| 19 // http://crbug.com/114700 | 21 // http://crbug.com/114700 |
| 20 #if defined(ENABLE_AUDIO_MIXER) | 22 #if defined(ENABLE_AUDIO_MIXER) |
| 21 #include "media/audio/audio_output_mixer.h" | 23 #include "media/audio/audio_output_mixer.h" |
| 22 #endif | 24 #endif |
| 23 | 25 |
| 24 using ::testing::_; | 26 using ::testing::_; |
| (...skipping 452 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 477 if (!audio_thread_.get()) { | 479 if (!audio_thread_.get()) { |
| 478 ASSERT_FALSE(audio_thread_runner_.get()); | 480 ASSERT_FALSE(audio_thread_runner_.get()); |
| 479 return; | 481 return; |
| 480 } | 482 } |
| 481 ASSERT_TRUE(audio_thread_runner_.get()); | 483 ASSERT_TRUE(audio_thread_runner_.get()); |
| 482 audio_thread_runner_->Stop(); | 484 audio_thread_runner_->Stop(); |
| 483 audio_thread_->Join(); | 485 audio_thread_->Join(); |
| 484 } | 486 } |
| 485 | 487 |
| 486 virtual void InitDispatcher(base::TimeDelta close_delay) { | 488 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) { | |
| 492 AudioOutputProxyTest::InitDispatcher(close_delay); | 489 AudioOutputProxyTest::InitDispatcher(close_delay); |
| 493 // Attempt shutdown of audio thread in case InitDispatcher() was called | 490 // Attempt shutdown of audio thread in case InitDispatcher() was called |
| 494 // previously. | 491 // previously. |
| 495 ShutdownAudioThread(); | 492 ShutdownAudioThread(); |
| 496 resampler_params_ = AudioParameters( | 493 resampler_params_ = AudioParameters( |
| 497 output_format, CHANNEL_LAYOUT_STEREO, 48000, 16, 128); | 494 AudioParameters::AUDIO_PCM_LOW_LATENCY, CHANNEL_LAYOUT_STEREO, |
| 495 48000, 16, 128); |
| 498 resampler_ = new AudioOutputResampler( | 496 resampler_ = new AudioOutputResampler( |
| 499 &manager(), params_, resampler_params_, close_delay); | 497 &manager(), params_, resampler_params_, close_delay); |
| 500 StartAudioThread(); | 498 StartAudioThread(); |
| 501 } | 499 } |
| 502 | 500 |
| 503 virtual void OnStart() { | 501 virtual void OnStart() { |
| 504 // Let start run for a bit. | 502 // Let start run for a bit. |
| 505 message_loop_.RunAllPending(); | 503 message_loop_.RunAllPending(); |
| 506 base::PlatformThread::Sleep( | 504 base::PlatformThread::Sleep( |
| 507 base::TimeDelta::FromMilliseconds(kStartRunTimeMs)); | 505 base::TimeDelta::FromMilliseconds(kStartRunTimeMs)); |
| (...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 726 OpenFailed(dispatcher_impl_); | 724 OpenFailed(dispatcher_impl_); |
| 727 } | 725 } |
| 728 | 726 |
| 729 #if defined(ENABLE_AUDIO_MIXER) | 727 #if defined(ENABLE_AUDIO_MIXER) |
| 730 TEST_F(AudioOutputProxyTest, OpenFailed_Mixer) { | 728 TEST_F(AudioOutputProxyTest, OpenFailed_Mixer) { |
| 731 OpenFailed(mixer_); | 729 OpenFailed(mixer_); |
| 732 } | 730 } |
| 733 #endif | 731 #endif |
| 734 | 732 |
| 735 TEST_F(AudioOutputResamplerTest, OpenFailed) { | 733 TEST_F(AudioOutputResamplerTest, OpenFailed) { |
| 734 CommandLine::ForCurrentProcess()->AppendSwitch( |
| 735 switches::kDisableAudioFallback); |
| 736 OpenFailed(resampler_); | 736 OpenFailed(resampler_); |
| 737 } | 737 } |
| 738 | 738 |
| 739 // Start() method failed. | 739 // Start() method failed. |
| 740 TEST_F(AudioOutputProxyTest, StartFailed) { | 740 TEST_F(AudioOutputProxyTest, StartFailed) { |
| 741 StartFailed(dispatcher_impl_); | 741 StartFailed(dispatcher_impl_); |
| 742 } | 742 } |
| 743 | 743 |
| 744 #if defined(ENABLE_AUDIO_MIXER) | 744 #if defined(ENABLE_AUDIO_MIXER) |
| 745 // Start() method failed. | 745 // Start() method failed. |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 787 } | 787 } |
| 788 #endif | 788 #endif |
| 789 | 789 |
| 790 TEST_F(AudioOutputResamplerTest, StartFailed) { | 790 TEST_F(AudioOutputResamplerTest, StartFailed) { |
| 791 StartFailed(resampler_); | 791 StartFailed(resampler_); |
| 792 } | 792 } |
| 793 | 793 |
| 794 // Simulate AudioOutputStream::Create() failure with a low latency stream and | 794 // Simulate AudioOutputStream::Create() failure with a low latency stream and |
| 795 // ensure AudioOutputResampler falls back to the high latency path. | 795 // ensure AudioOutputResampler falls back to the high latency path. |
| 796 TEST_F(AudioOutputResamplerTest, LowLatencyCreateFailedFallback) { | 796 TEST_F(AudioOutputResamplerTest, LowLatencyCreateFailedFallback) { |
| 797 InitDispatcher(base::TimeDelta::FromSeconds(kTestCloseDelayMs), | |
| 798 AudioParameters::AUDIO_PCM_LOW_LATENCY); | |
| 799 | |
| 800 MockAudioOutputStream stream; | 797 MockAudioOutputStream stream; |
| 801 EXPECT_CALL(manager(), MakeAudioOutputStream(_)) | 798 EXPECT_CALL(manager(), MakeAudioOutputStream(_)) |
| 802 .Times(2) | 799 .Times(2) |
| 803 .WillOnce(Return(static_cast<AudioOutputStream*>(NULL))) | 800 .WillOnce(Return(static_cast<AudioOutputStream*>(NULL))) |
| 804 .WillRepeatedly(Return(&stream)); | 801 .WillRepeatedly(Return(&stream)); |
| 805 EXPECT_CALL(stream, Open()) | 802 EXPECT_CALL(stream, Open()) |
| 806 .WillOnce(Return(true)); | 803 .WillOnce(Return(true)); |
| 807 EXPECT_CALL(stream, Close()) | 804 EXPECT_CALL(stream, Close()) |
| 808 .Times(1); | 805 .Times(1); |
| 809 | 806 |
| 810 AudioOutputProxy* proxy = new AudioOutputProxy(resampler_); | 807 AudioOutputProxy* proxy = new AudioOutputProxy(resampler_); |
| 811 EXPECT_TRUE(proxy->Open()); | 808 EXPECT_TRUE(proxy->Open()); |
| 812 proxy->Close(); | 809 proxy->Close(); |
| 813 WaitForCloseTimer(kTestCloseDelayMs); | 810 WaitForCloseTimer(kTestCloseDelayMs); |
| 814 } | 811 } |
| 815 | 812 |
| 816 // Simulate AudioOutputStream::Open() failure with a low latency stream and | 813 // Simulate AudioOutputStream::Open() failure with a low latency stream and |
| 817 // ensure AudioOutputResampler falls back to the high latency path. | 814 // ensure AudioOutputResampler falls back to the high latency path. |
| 818 TEST_F(AudioOutputResamplerTest, LowLatencyOpenFailedFallback) { | 815 TEST_F(AudioOutputResamplerTest, LowLatencyOpenFailedFallback) { |
| 819 InitDispatcher(base::TimeDelta::FromSeconds(kTestCloseDelayMs), | |
| 820 AudioParameters::AUDIO_PCM_LOW_LATENCY); | |
| 821 | |
| 822 MockAudioOutputStream failed_stream; | 816 MockAudioOutputStream failed_stream; |
| 823 MockAudioOutputStream okay_stream; | 817 MockAudioOutputStream okay_stream; |
| 824 EXPECT_CALL(manager(), MakeAudioOutputStream(_)) | 818 EXPECT_CALL(manager(), MakeAudioOutputStream(_)) |
| 825 .Times(2) | 819 .Times(2) |
| 826 .WillOnce(Return(&failed_stream)) | 820 .WillOnce(Return(&failed_stream)) |
| 827 .WillRepeatedly(Return(&okay_stream)); | 821 .WillRepeatedly(Return(&okay_stream)); |
| 828 EXPECT_CALL(failed_stream, Open()) | 822 EXPECT_CALL(failed_stream, Open()) |
| 829 .WillOnce(Return(false)); | 823 .WillOnce(Return(false)); |
| 830 EXPECT_CALL(failed_stream, Close()) | 824 EXPECT_CALL(failed_stream, Close()) |
| 831 .Times(1); | 825 .Times(1); |
| 832 EXPECT_CALL(okay_stream, Open()) | 826 EXPECT_CALL(okay_stream, Open()) |
| 833 .WillOnce(Return(true)); | 827 .WillOnce(Return(true)); |
| 834 EXPECT_CALL(okay_stream, Close()) | 828 EXPECT_CALL(okay_stream, Close()) |
| 835 .Times(1); | 829 .Times(1); |
| 836 | 830 |
| 837 AudioOutputProxy* proxy = new AudioOutputProxy(resampler_); | 831 AudioOutputProxy* proxy = new AudioOutputProxy(resampler_); |
| 838 EXPECT_TRUE(proxy->Open()); | 832 EXPECT_TRUE(proxy->Open()); |
| 839 proxy->Close(); | 833 proxy->Close(); |
| 840 WaitForCloseTimer(kTestCloseDelayMs); | 834 WaitForCloseTimer(kTestCloseDelayMs); |
| 841 } | 835 } |
| 842 | 836 |
| 843 // Simulate failures to open both the low latency and the fallback high latency | 837 // Simulate failures to open both the low latency and the fallback high latency |
| 844 // stream and ensure AudioOutputResampler terminates normally. | 838 // stream and ensure AudioOutputResampler terminates normally. |
| 845 TEST_F(AudioOutputResamplerTest, LowLatencyFallbackFailed) { | 839 TEST_F(AudioOutputResamplerTest, LowLatencyFallbackFailed) { |
| 846 InitDispatcher(base::TimeDelta::FromSeconds(kTestCloseDelayMs), | |
| 847 AudioParameters::AUDIO_PCM_LOW_LATENCY); | |
| 848 | |
| 849 EXPECT_CALL(manager(), MakeAudioOutputStream(_)) | 840 EXPECT_CALL(manager(), MakeAudioOutputStream(_)) |
| 850 .Times(2) | 841 .Times(2) |
| 851 .WillRepeatedly(Return(static_cast<AudioOutputStream*>(NULL))); | 842 .WillRepeatedly(Return(static_cast<AudioOutputStream*>(NULL))); |
| 852 | 843 |
| 853 AudioOutputProxy* proxy = new AudioOutputProxy(resampler_); | 844 AudioOutputProxy* proxy = new AudioOutputProxy(resampler_); |
| 854 EXPECT_FALSE(proxy->Open()); | 845 EXPECT_FALSE(proxy->Open()); |
| 855 proxy->Close(); | 846 proxy->Close(); |
| 856 WaitForCloseTimer(kTestCloseDelayMs); | 847 WaitForCloseTimer(kTestCloseDelayMs); |
| 857 } | 848 } |
| 858 | 849 |
| 859 } // namespace media | 850 } // namespace media |
| OLD | NEW |