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/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
11 #include "base/run_loop.h" | 11 #include "base/run_loop.h" |
| 12 #include "base/single_thread_task_runner.h" |
12 #include "base/threading/thread_task_runner_handle.h" | 13 #include "base/threading/thread_task_runner_handle.h" |
13 #include "build/build_config.h" | 14 #include "build/build_config.h" |
14 #include "media/audio/audio_manager.h" | 15 #include "media/audio/audio_manager.h" |
15 #include "media/audio/audio_manager_base.h" | 16 #include "media/audio/audio_manager_base.h" |
16 #include "media/audio/audio_output_dispatcher_impl.h" | 17 #include "media/audio/audio_output_dispatcher_impl.h" |
17 #include "media/audio/audio_output_proxy.h" | 18 #include "media/audio/audio_output_proxy.h" |
18 #include "media/audio/audio_output_resampler.h" | 19 #include "media/audio/audio_output_resampler.h" |
19 #include "media/audio/fake_audio_log_factory.h" | 20 #include "media/audio/fake_audio_log_factory.h" |
20 #include "media/audio/fake_audio_output_stream.h" | 21 #include "media/audio/fake_audio_output_stream.h" |
21 #include "testing/gmock/include/gmock/gmock.h" | 22 #include "testing/gmock/include/gmock/gmock.h" |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
160 // FakeAudioOutputStream will keep the message loop busy indefinitely; i.e., | 161 // FakeAudioOutputStream will keep the message loop busy indefinitely; i.e., |
161 // RunUntilIdle() will never terminate. | 162 // RunUntilIdle() will never terminate. |
162 params_ = AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, | 163 params_ = AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, |
163 CHANNEL_LAYOUT_STEREO, 8000, 16, 2048); | 164 CHANNEL_LAYOUT_STEREO, 8000, 16, 2048); |
164 InitDispatcher(base::TimeDelta::FromMilliseconds(kTestCloseDelayMs)); | 165 InitDispatcher(base::TimeDelta::FromMilliseconds(kTestCloseDelayMs)); |
165 } | 166 } |
166 | 167 |
167 void TearDown() override { | 168 void TearDown() override { |
168 // This is necessary to free all proxy objects that have been | 169 // This is necessary to free all proxy objects that have been |
169 // closed by the test. | 170 // closed by the test. |
170 message_loop_.RunUntilIdle(); | 171 base::RunLoop().RunUntilIdle(); |
171 } | 172 } |
172 | 173 |
173 virtual void InitDispatcher(base::TimeDelta close_delay) { | 174 virtual void InitDispatcher(base::TimeDelta close_delay) { |
174 dispatcher_impl_ = new AudioOutputDispatcherImpl(&manager(), | 175 dispatcher_impl_ = new AudioOutputDispatcherImpl(&manager(), |
175 params_, | 176 params_, |
176 std::string(), | 177 std::string(), |
177 close_delay); | 178 close_delay); |
178 } | 179 } |
179 | 180 |
180 virtual void OnStart() {} | 181 virtual void OnStart() {} |
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
436 resampler_params_ = AudioParameters( | 437 resampler_params_ = AudioParameters( |
437 AudioParameters::AUDIO_PCM_LOW_LATENCY, CHANNEL_LAYOUT_STEREO, | 438 AudioParameters::AUDIO_PCM_LOW_LATENCY, CHANNEL_LAYOUT_STEREO, |
438 16000, 16, 1024); | 439 16000, 16, 1024); |
439 resampler_ = new AudioOutputResampler( | 440 resampler_ = new AudioOutputResampler( |
440 &manager(), params_, resampler_params_, std::string(), close_delay); | 441 &manager(), params_, resampler_params_, std::string(), close_delay); |
441 } | 442 } |
442 | 443 |
443 void OnStart() override { | 444 void OnStart() override { |
444 // Let Start() run for a bit. | 445 // Let Start() run for a bit. |
445 base::RunLoop run_loop; | 446 base::RunLoop run_loop; |
446 message_loop_.PostDelayedTask( | 447 message_loop_.task_runner()->PostDelayedTask( |
447 FROM_HERE, | 448 FROM_HERE, run_loop.QuitClosure(), |
448 run_loop.QuitClosure(), | |
449 base::TimeDelta::FromMilliseconds(kStartRunTimeMs)); | 449 base::TimeDelta::FromMilliseconds(kStartRunTimeMs)); |
450 run_loop.Run(); | 450 run_loop.Run(); |
451 } | 451 } |
452 | 452 |
453 protected: | 453 protected: |
454 AudioParameters resampler_params_; | 454 AudioParameters resampler_params_; |
455 scoped_refptr<AudioOutputResampler> resampler_; | 455 scoped_refptr<AudioOutputResampler> resampler_; |
456 }; | 456 }; |
457 | 457 |
458 TEST_F(AudioOutputProxyTest, CreateAndClose) { | 458 TEST_F(AudioOutputProxyTest, CreateAndClose) { |
(...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
718 _, _)) | 718 _, _)) |
719 .WillOnce(Return(&fake_stream)); | 719 .WillOnce(Return(&fake_stream)); |
720 EXPECT_CALL(fake_stream, Open()).WillOnce(Return(true)); | 720 EXPECT_CALL(fake_stream, Open()).WillOnce(Return(true)); |
721 AudioOutputProxy* proxy = new AudioOutputProxy(resampler_.get()); | 721 AudioOutputProxy* proxy = new AudioOutputProxy(resampler_.get()); |
722 EXPECT_TRUE(proxy->Open()); | 722 EXPECT_TRUE(proxy->Open()); |
723 CloseAndWaitForCloseTimer(proxy, &fake_stream); | 723 CloseAndWaitForCloseTimer(proxy, &fake_stream); |
724 | 724 |
725 // Once all proxies have been closed, AudioOutputResampler will start the | 725 // Once all proxies have been closed, AudioOutputResampler will start the |
726 // reinitialization timer and execute it after the close delay elapses. | 726 // reinitialization timer and execute it after the close delay elapses. |
727 base::RunLoop run_loop; | 727 base::RunLoop run_loop; |
728 message_loop_.PostDelayedTask( | 728 message_loop_.task_runner()->PostDelayedTask( |
729 FROM_HERE, run_loop.QuitClosure(), | 729 FROM_HERE, run_loop.QuitClosure(), |
730 base::TimeDelta::FromMilliseconds(2 * kTestCloseDelayMs)); | 730 base::TimeDelta::FromMilliseconds(2 * kTestCloseDelayMs)); |
731 run_loop.Run(); | 731 run_loop.Run(); |
732 | 732 |
733 // Verify a non-fake stream can be created. | 733 // Verify a non-fake stream can be created. |
734 MockAudioOutputStream real_stream(&manager_, params_); | 734 MockAudioOutputStream real_stream(&manager_, params_); |
735 EXPECT_CALL(manager(), | 735 EXPECT_CALL(manager(), |
736 MakeAudioOutputStream( | 736 MakeAudioOutputStream( |
737 testing::Property(&AudioParameters::format, | 737 testing::Property(&AudioParameters::format, |
738 testing::Ne(AudioParameters::AUDIO_FAKE)), | 738 testing::Ne(AudioParameters::AUDIO_FAKE)), |
739 _, _)) | 739 _, _)) |
740 .WillOnce(Return(&real_stream)); | 740 .WillOnce(Return(&real_stream)); |
741 | 741 |
742 // Stream1 should be able to successfully open and start. | 742 // Stream1 should be able to successfully open and start. |
743 EXPECT_CALL(real_stream, Open()).WillOnce(Return(true)); | 743 EXPECT_CALL(real_stream, Open()).WillOnce(Return(true)); |
744 proxy = new AudioOutputProxy(resampler_.get()); | 744 proxy = new AudioOutputProxy(resampler_.get()); |
745 EXPECT_TRUE(proxy->Open()); | 745 EXPECT_TRUE(proxy->Open()); |
746 CloseAndWaitForCloseTimer(proxy, &real_stream); | 746 CloseAndWaitForCloseTimer(proxy, &real_stream); |
747 } | 747 } |
748 | 748 |
749 } // namespace media | 749 } // namespace media |
OLD | NEW |