| 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 <stdint.h> | 5 #include <stdint.h> |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/memory/ptr_util.h" |
| 10 #include "base/message_loop/message_loop.h" | 11 #include "base/message_loop/message_loop.h" |
| 11 #include "base/run_loop.h" | 12 #include "base/run_loop.h" |
| 12 #include "base/single_thread_task_runner.h" | 13 #include "base/single_thread_task_runner.h" |
| 13 #include "base/threading/thread_task_runner_handle.h" | 14 #include "base/threading/thread_task_runner_handle.h" |
| 14 #include "build/build_config.h" | 15 #include "build/build_config.h" |
| 15 #include "media/audio/audio_manager.h" | 16 #include "media/audio/audio_manager.h" |
| 16 #include "media/audio/audio_manager_base.h" | 17 #include "media/audio/audio_manager_base.h" |
| 17 #include "media/audio/audio_output_dispatcher_impl.h" | 18 #include "media/audio/audio_output_dispatcher_impl.h" |
| 18 #include "media/audio/audio_output_proxy.h" | 19 #include "media/audio/audio_output_proxy.h" |
| 19 #include "media/audio/audio_output_resampler.h" | 20 #include "media/audio/audio_output_resampler.h" |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 167 InitDispatcher(base::TimeDelta::FromMilliseconds(kTestCloseDelayMs)); | 168 InitDispatcher(base::TimeDelta::FromMilliseconds(kTestCloseDelayMs)); |
| 168 } | 169 } |
| 169 | 170 |
| 170 void TearDown() override { | 171 void TearDown() override { |
| 171 // This is necessary to free all proxy objects that have been | 172 // This is necessary to free all proxy objects that have been |
| 172 // closed by the test. | 173 // closed by the test. |
| 173 base::RunLoop().RunUntilIdle(); | 174 base::RunLoop().RunUntilIdle(); |
| 174 } | 175 } |
| 175 | 176 |
| 176 virtual void InitDispatcher(base::TimeDelta close_delay) { | 177 virtual void InitDispatcher(base::TimeDelta close_delay) { |
| 177 dispatcher_impl_ = new AudioOutputDispatcherImpl(&manager(), | 178 dispatcher_impl_ = base::MakeUnique<AudioOutputDispatcherImpl>( |
| 178 params_, | 179 &manager(), params_, std::string(), close_delay); |
| 179 std::string(), | |
| 180 close_delay); | |
| 181 } | 180 } |
| 182 | 181 |
| 183 virtual void OnStart() {} | 182 virtual void OnStart() {} |
| 184 | 183 |
| 185 MockAudioManager& manager() { | 184 MockAudioManager& manager() { |
| 186 return manager_; | 185 return manager_; |
| 187 } | 186 } |
| 188 | 187 |
| 189 void WaitForCloseTimer(MockAudioOutputStream* stream) { | 188 void WaitForCloseTimer(MockAudioOutputStream* stream) { |
| 190 base::RunLoop run_loop; | 189 base::RunLoop run_loop; |
| (...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 415 // callback may not have had time to process the OnError() in between. | 414 // callback may not have had time to process the OnError() in between. |
| 416 proxy->Stop(); | 415 proxy->Stop(); |
| 417 proxy->Start(&callback_); | 416 proxy->Start(&callback_); |
| 418 | 417 |
| 419 Mock::VerifyAndClear(&callback_); | 418 Mock::VerifyAndClear(&callback_); |
| 420 | 419 |
| 421 proxy->Close(); | 420 proxy->Close(); |
| 422 } | 421 } |
| 423 | 422 |
| 424 base::MessageLoop message_loop_; | 423 base::MessageLoop message_loop_; |
| 425 scoped_refptr<AudioOutputDispatcherImpl> dispatcher_impl_; | 424 std::unique_ptr<AudioOutputDispatcherImpl> dispatcher_impl_; |
| 426 MockAudioManager manager_; | 425 MockAudioManager manager_; |
| 427 MockAudioSourceCallback callback_; | 426 MockAudioSourceCallback callback_; |
| 428 AudioParameters params_; | 427 AudioParameters params_; |
| 429 }; | 428 }; |
| 430 | 429 |
| 431 class AudioOutputResamplerTest : public AudioOutputProxyTest { | 430 class AudioOutputResamplerTest : public AudioOutputProxyTest { |
| 432 public: | 431 public: |
| 433 void TearDown() override { AudioOutputProxyTest::TearDown(); } | 432 void TearDown() override { AudioOutputProxyTest::TearDown(); } |
| 434 | 433 |
| 435 void InitDispatcher(base::TimeDelta close_delay) override { | 434 void InitDispatcher(base::TimeDelta close_delay) override { |
| 436 // Use a low sample rate and large buffer size when testing otherwise the | 435 // Use a low sample rate and large buffer size when testing otherwise the |
| 437 // FakeAudioOutputStream will keep the message loop busy indefinitely; i.e., | 436 // FakeAudioOutputStream will keep the message loop busy indefinitely; i.e., |
| 438 // RunUntilIdle() will never terminate. | 437 // RunUntilIdle() will never terminate. |
| 439 resampler_params_ = AudioParameters( | 438 resampler_params_ = AudioParameters( |
| 440 AudioParameters::AUDIO_PCM_LOW_LATENCY, CHANNEL_LAYOUT_STEREO, | 439 AudioParameters::AUDIO_PCM_LOW_LATENCY, CHANNEL_LAYOUT_STEREO, |
| 441 16000, 16, 1024); | 440 16000, 16, 1024); |
| 442 resampler_ = new AudioOutputResampler( | 441 resampler_ = base::MakeUnique<AudioOutputResampler>( |
| 443 &manager(), params_, resampler_params_, std::string(), close_delay); | 442 &manager(), params_, resampler_params_, std::string(), close_delay); |
| 444 } | 443 } |
| 445 | 444 |
| 446 void OnStart() override { | 445 void OnStart() override { |
| 447 // Let Start() run for a bit. | 446 // Let Start() run for a bit. |
| 448 base::RunLoop run_loop; | 447 base::RunLoop run_loop; |
| 449 message_loop_.task_runner()->PostDelayedTask( | 448 message_loop_.task_runner()->PostDelayedTask( |
| 450 FROM_HERE, run_loop.QuitClosure(), | 449 FROM_HERE, run_loop.QuitClosure(), |
| 451 base::TimeDelta::FromMilliseconds(kStartRunTimeMs)); | 450 base::TimeDelta::FromMilliseconds(kStartRunTimeMs)); |
| 452 run_loop.Run(); | 451 run_loop.Run(); |
| 453 } | 452 } |
| 454 | 453 |
| 455 protected: | 454 protected: |
| 456 AudioParameters resampler_params_; | 455 AudioParameters resampler_params_; |
| 457 scoped_refptr<AudioOutputResampler> resampler_; | 456 std::unique_ptr<AudioOutputResampler> resampler_; |
| 458 }; | 457 }; |
| 459 | 458 |
| 460 TEST_F(AudioOutputProxyTest, CreateAndClose) { | 459 TEST_F(AudioOutputProxyTest, CreateAndClose) { |
| 461 AudioOutputProxy* proxy = new AudioOutputProxy(dispatcher_impl_.get()); | 460 AudioOutputProxy* proxy = new AudioOutputProxy(dispatcher_impl_.get()); |
| 462 proxy->Close(); | 461 proxy->Close(); |
| 463 } | 462 } |
| 464 | 463 |
| 465 TEST_F(AudioOutputResamplerTest, CreateAndClose) { | 464 TEST_F(AudioOutputResamplerTest, CreateAndClose) { |
| 466 AudioOutputProxy* proxy = new AudioOutputProxy(resampler_.get()); | 465 AudioOutputProxy* proxy = new AudioOutputProxy(resampler_.get()); |
| 467 proxy->Close(); | 466 proxy->Close(); |
| (...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 742 .WillOnce(Return(&real_stream)); | 741 .WillOnce(Return(&real_stream)); |
| 743 | 742 |
| 744 // Stream1 should be able to successfully open and start. | 743 // Stream1 should be able to successfully open and start. |
| 745 EXPECT_CALL(real_stream, Open()).WillOnce(Return(true)); | 744 EXPECT_CALL(real_stream, Open()).WillOnce(Return(true)); |
| 746 proxy = new AudioOutputProxy(resampler_.get()); | 745 proxy = new AudioOutputProxy(resampler_.get()); |
| 747 EXPECT_TRUE(proxy->Open()); | 746 EXPECT_TRUE(proxy->Open()); |
| 748 CloseAndWaitForCloseTimer(proxy, &real_stream); | 747 CloseAndWaitForCloseTimer(proxy, &real_stream); |
| 749 } | 748 } |
| 750 | 749 |
| 751 } // namespace media | 750 } // namespace media |
| OLD | NEW |