Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(228)

Side by Side Diff: media/audio/audio_output_proxy_unittest.cc

Issue 10909151: Automatically fall back to non-low latency on open() failure. (Closed) Base URL: http://git.chromium.org/chromium/src.git@resampler2
Patch Set: Rebase. Comments. Created 8 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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, false);
488 }
489
490 virtual void InitDispatcher(base::TimeDelta close_delay, bool low_latency) {
scherkus (not reviewing) 2012/09/12 13:45:15 can you replace the bool with the enum itself? in
DaleCurtis 2012/09/12 14:16:51 Done.
487 AudioOutputProxyTest::InitDispatcher(close_delay); 491 AudioOutputProxyTest::InitDispatcher(close_delay);
488 // Attempt shutdown of audio thread in case InitDispatcher() was called 492 // Attempt shutdown of audio thread in case InitDispatcher() was called
489 // previously. 493 // previously.
490 ShutdownAudioThread(); 494 ShutdownAudioThread();
491 resampler_params_ = AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, 495 resampler_params_ = AudioParameters(
492 CHANNEL_LAYOUT_STEREO, 48000, 16, 128); 496 (low_latency ? AudioParameters::AUDIO_PCM_LOW_LATENCY :
497 AudioParameters::AUDIO_PCM_LINEAR),
498 CHANNEL_LAYOUT_STEREO, 48000, 16, 128);
493 resampler_ = new AudioOutputResampler( 499 resampler_ = new AudioOutputResampler(
494 &manager(), params_, resampler_params_, close_delay); 500 &manager(), params_, resampler_params_, close_delay);
495 StartAudioThread(); 501 StartAudioThread();
496 } 502 }
497 503
498 virtual void OnStart() { 504 virtual void OnStart() {
499 // Let start run for a bit. 505 // Let start run for a bit.
500 message_loop_.RunAllPending(); 506 message_loop_.RunAllPending();
501 base::PlatformThread::Sleep( 507 base::PlatformThread::Sleep(
502 base::TimeDelta::FromMilliseconds(kStartRunTimeMs)); 508 base::TimeDelta::FromMilliseconds(kStartRunTimeMs));
(...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after
779 785
780 proxy2->Close(); 786 proxy2->Close();
781 WaitForCloseTimer(kTestCloseDelayMs); 787 WaitForCloseTimer(kTestCloseDelayMs);
782 } 788 }
783 #endif 789 #endif
784 790
785 TEST_F(AudioOutputResamplerTest, StartFailed) { 791 TEST_F(AudioOutputResamplerTest, StartFailed) {
786 StartFailed(resampler_); 792 StartFailed(resampler_);
787 } 793 }
788 794
795 // Simulate AudioOutputStream::Create() failure with a low latency stream and
796 // ensure AudioOutputResampler falls back to the high latency path.
797 TEST_F(AudioOutputResamplerTest, LowLatencyCreateFailedFallback) {
798 InitDispatcher(base::TimeDelta::FromSeconds(kTestCloseDelayMs), true);
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), true);
820
821 MockAudioOutputStream failed_stream;
822 MockAudioOutputStream okay_stream;
823 EXPECT_CALL(manager(), MakeAudioOutputStream(_))
824 .Times(2)
825 .WillOnce(Return(&failed_stream))
826 .WillRepeatedly(Return(&okay_stream));
827 EXPECT_CALL(failed_stream, Open())
828 .WillOnce(Return(false));
829 EXPECT_CALL(failed_stream, Close())
830 .Times(1);
831 EXPECT_CALL(okay_stream, Open())
832 .WillOnce(Return(true));
833 EXPECT_CALL(okay_stream, Close())
834 .Times(1);
835
836 AudioOutputProxy* proxy = new AudioOutputProxy(resampler_);
837 EXPECT_TRUE(proxy->Open());
838 proxy->Close();
839 WaitForCloseTimer(kTestCloseDelayMs);
840 }
841
842 // Simulate failures to open both the low latency and the fallback high latency
843 // stream and ensure AudioOutputResampler terminates normally.
844 TEST_F(AudioOutputResamplerTest, LowLatencyFallbackFailed) {
845 InitDispatcher(base::TimeDelta::FromSeconds(kTestCloseDelayMs), true);
846
847 EXPECT_CALL(manager(), MakeAudioOutputStream(_))
848 .Times(2)
849 .WillRepeatedly(Return(static_cast<AudioOutputStream*>(NULL)));
850
851 AudioOutputProxy* proxy = new AudioOutputProxy(resampler_);
852 EXPECT_FALSE(proxy->Open());
853 proxy->Close();
854 WaitForCloseTimer(kTestCloseDelayMs);
855 }
856
789 } // namespace media 857 } // namespace media
OLDNEW
« no previous file with comments | « no previous file | media/audio/audio_output_resampler.h » ('j') | media/audio/audio_output_resampler.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698