| 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 <list> | 7 #include <list> |
| 8 #include <memory> | 8 #include <memory> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 17 matching lines...) Expand all Loading... |
| 28 namespace media { | 28 namespace media { |
| 29 | 29 |
| 30 namespace { | 30 namespace { |
| 31 | 31 |
| 32 const AudioParameters kParams( | 32 const AudioParameters kParams( |
| 33 AudioParameters::AUDIO_PCM_LOW_LATENCY, CHANNEL_LAYOUT_STEREO, 8000, 8, 10); | 33 AudioParameters::AUDIO_PCM_LOW_LATENCY, CHANNEL_LAYOUT_STEREO, 8000, 8, 10); |
| 34 | 34 |
| 35 class MockInputCallback : public AudioInputStream::AudioInputCallback { | 35 class MockInputCallback : public AudioInputStream::AudioInputCallback { |
| 36 public: | 36 public: |
| 37 MockInputCallback() | 37 MockInputCallback() |
| 38 : data_pushed_(false, false) { | 38 : data_pushed_(base::WaitableEvent::ResetPolicy::AUTOMATIC, |
| 39 base::WaitableEvent::InitialState::NOT_SIGNALED) { |
| 39 ON_CALL(*this, OnData(_, _, _, _)).WillByDefault( | 40 ON_CALL(*this, OnData(_, _, _, _)).WillByDefault( |
| 40 InvokeWithoutArgs(&data_pushed_, &base::WaitableEvent::Signal)); | 41 InvokeWithoutArgs(&data_pushed_, &base::WaitableEvent::Signal)); |
| 41 } | 42 } |
| 42 | 43 |
| 43 virtual ~MockInputCallback() {} | 44 virtual ~MockInputCallback() {} |
| 44 | 45 |
| 45 MOCK_METHOD4(OnData, | 46 MOCK_METHOD4(OnData, |
| 46 void(AudioInputStream* stream, | 47 void(AudioInputStream* stream, |
| 47 const AudioBus* source, | 48 const AudioBus* source, |
| 48 uint32_t hardware_delay_bytes, | 49 uint32_t hardware_delay_bytes, |
| 49 double volume)); | 50 double volume)); |
| 50 MOCK_METHOD1(OnError, void(AudioInputStream* stream)); | 51 MOCK_METHOD1(OnError, void(AudioInputStream* stream)); |
| 51 | 52 |
| 52 void WaitForDataPushes() { | 53 void WaitForDataPushes() { |
| 53 for (int i = 0; i < 3; ++i) { | 54 for (int i = 0; i < 3; ++i) { |
| 54 data_pushed_.Wait(); | 55 data_pushed_.Wait(); |
| 55 } | 56 } |
| 56 } | 57 } |
| 57 | 58 |
| 58 private: | 59 private: |
| 59 base::WaitableEvent data_pushed_; | 60 base::WaitableEvent data_pushed_; |
| 60 | 61 |
| 61 DISALLOW_COPY_AND_ASSIGN(MockInputCallback); | 62 DISALLOW_COPY_AND_ASSIGN(MockInputCallback); |
| 62 }; | 63 }; |
| 63 | 64 |
| 64 class TestAudioSource : public SineWaveAudioSource { | 65 class TestAudioSource : public SineWaveAudioSource { |
| 65 public: | 66 public: |
| 66 TestAudioSource() | 67 TestAudioSource() |
| 67 : SineWaveAudioSource( | 68 : SineWaveAudioSource(kParams.channel_layout(), |
| 68 kParams.channel_layout(), 200.0, kParams.sample_rate()), | 69 200.0, |
| 69 data_pulled_(false, false) {} | 70 kParams.sample_rate()), |
| 71 data_pulled_(base::WaitableEvent::ResetPolicy::AUTOMATIC, |
| 72 base::WaitableEvent::InitialState::NOT_SIGNALED) {} |
| 70 | 73 |
| 71 ~TestAudioSource() override {} | 74 ~TestAudioSource() override {} |
| 72 | 75 |
| 73 int OnMoreData(AudioBus* audio_bus, | 76 int OnMoreData(AudioBus* audio_bus, |
| 74 uint32_t total_bytes_delay, | 77 uint32_t total_bytes_delay, |
| 75 uint32_t frames_skipped) override { | 78 uint32_t frames_skipped) override { |
| 76 const int ret = SineWaveAudioSource::OnMoreData( | 79 const int ret = SineWaveAudioSource::OnMoreData( |
| 77 audio_bus, total_bytes_delay, frames_skipped); | 80 audio_bus, total_bytes_delay, frames_skipped); |
| 78 data_pulled_.Signal(); | 81 data_pulled_.Signal(); |
| 79 return ret; | 82 return ret; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 92 }; | 95 }; |
| 93 | 96 |
| 94 } // namespace | 97 } // namespace |
| 95 | 98 |
| 96 class VirtualAudioInputStreamTest : public testing::TestWithParam<bool> { | 99 class VirtualAudioInputStreamTest : public testing::TestWithParam<bool> { |
| 97 public: | 100 public: |
| 98 VirtualAudioInputStreamTest() | 101 VirtualAudioInputStreamTest() |
| 99 : audio_thread_(new base::Thread("AudioThread")), | 102 : audio_thread_(new base::Thread("AudioThread")), |
| 100 worker_thread_(new base::Thread("AudioWorkerThread")), | 103 worker_thread_(new base::Thread("AudioWorkerThread")), |
| 101 stream_(NULL), | 104 stream_(NULL), |
| 102 closed_stream_(false, false) { | 105 closed_stream_(base::WaitableEvent::ResetPolicy::AUTOMATIC, |
| 106 base::WaitableEvent::InitialState::NOT_SIGNALED) { |
| 103 audio_thread_->Start(); | 107 audio_thread_->Start(); |
| 104 audio_task_runner_ = audio_thread_->task_runner(); | 108 audio_task_runner_ = audio_thread_->task_runner(); |
| 105 } | 109 } |
| 106 | 110 |
| 107 virtual ~VirtualAudioInputStreamTest() { | 111 virtual ~VirtualAudioInputStreamTest() { |
| 108 SyncWithAudioThread(); | 112 SyncWithAudioThread(); |
| 109 | 113 |
| 110 DCHECK(output_streams_.empty()); | 114 DCHECK(output_streams_.empty()); |
| 111 DCHECK(stopped_output_streams_.empty()); | 115 DCHECK(stopped_output_streams_.empty()); |
| 112 } | 116 } |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 215 worker_task_runner_ = worker_thread_->task_runner(); | 219 worker_task_runner_ = worker_thread_->task_runner(); |
| 216 } | 220 } |
| 217 return worker_task_runner_; | 221 return worker_task_runner_; |
| 218 } else { | 222 } else { |
| 219 return audio_task_runner_; | 223 return audio_task_runner_; |
| 220 } | 224 } |
| 221 } | 225 } |
| 222 | 226 |
| 223 private: | 227 private: |
| 224 void SyncWithAudioThread() { | 228 void SyncWithAudioThread() { |
| 225 base::WaitableEvent done(false, false); | 229 base::WaitableEvent done(base::WaitableEvent::ResetPolicy::AUTOMATIC, |
| 230 base::WaitableEvent::InitialState::NOT_SIGNALED); |
| 226 audio_task_runner_->PostTask( | 231 audio_task_runner_->PostTask( |
| 227 FROM_HERE, | 232 FROM_HERE, |
| 228 base::Bind(&base::WaitableEvent::Signal, base::Unretained(&done))); | 233 base::Bind(&base::WaitableEvent::Signal, base::Unretained(&done))); |
| 229 done.Wait(); | 234 done.Wait(); |
| 230 } | 235 } |
| 231 | 236 |
| 232 std::unique_ptr<base::Thread> audio_thread_; | 237 std::unique_ptr<base::Thread> audio_thread_; |
| 233 scoped_refptr<base::SingleThreadTaskRunner> audio_task_runner_; | 238 scoped_refptr<base::SingleThreadTaskRunner> audio_task_runner_; |
| 234 std::unique_ptr<base::Thread> worker_thread_; | 239 std::unique_ptr<base::Thread> worker_thread_; |
| 235 scoped_refptr<base::SingleThreadTaskRunner> worker_task_runner_; | 240 scoped_refptr<base::SingleThreadTaskRunner> worker_task_runner_; |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 343 } | 348 } |
| 344 RUN_ON_AUDIO_THREAD(Close); | 349 RUN_ON_AUDIO_THREAD(Close); |
| 345 WaitUntilClosed(); | 350 WaitUntilClosed(); |
| 346 } | 351 } |
| 347 | 352 |
| 348 INSTANTIATE_TEST_CASE_P(SingleVersusMultithreaded, | 353 INSTANTIATE_TEST_CASE_P(SingleVersusMultithreaded, |
| 349 VirtualAudioInputStreamTest, | 354 VirtualAudioInputStreamTest, |
| 350 ::testing::Values(false, true)); | 355 ::testing::Values(false, true)); |
| 351 | 356 |
| 352 } // namespace media | 357 } // namespace media |
| OLD | NEW |