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 "base/environment.h" | 7 #include "base/environment.h" |
8 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
9 #include "base/run_loop.h" | 9 #include "base/run_loop.h" |
10 #include "base/test/test_timeouts.h" | 10 #include "base/test/test_timeouts.h" |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
100 private: | 100 private: |
101 media::SeekableBuffer buffer_; | 101 media::SeekableBuffer buffer_; |
102 FILE* file_; | 102 FILE* file_; |
103 int bytes_to_write_; | 103 int bytes_to_write_; |
104 }; | 104 }; |
105 | 105 |
106 class MacAudioInputTest : public testing::Test { | 106 class MacAudioInputTest : public testing::Test { |
107 protected: | 107 protected: |
108 MacAudioInputTest() | 108 MacAudioInputTest() |
109 : message_loop_(base::MessageLoop::TYPE_UI), | 109 : message_loop_(base::MessageLoop::TYPE_UI), |
110 audio_manager_( | 110 audio_manager_(AudioManager::CreateForTesting()) { |
111 AudioManager::CreateForTesting(message_loop_.task_runner())) { | |
112 // Wait for the AudioManager to finish any initialization on the audio loop. | 111 // Wait for the AudioManager to finish any initialization on the audio loop. |
113 base::RunLoop().RunUntilIdle(); | 112 base::RunLoop().RunUntilIdle(); |
114 } | 113 } |
115 | 114 |
116 ~MacAudioInputTest() override { | 115 ~MacAudioInputTest() override { base::RunLoop().RunUntilIdle(); } |
117 audio_manager_.reset(); | |
118 base::RunLoop().RunUntilIdle(); | |
119 } | |
120 | 116 |
121 bool InputDevicesAvailable() { | 117 bool InputDevicesAvailable() { |
122 return audio_manager_->HasAudioInputDevices(); | 118 return audio_manager_->HasAudioInputDevices(); |
123 } | 119 } |
124 | 120 |
125 // Convenience method which creates a default AudioInputStream object using | 121 // Convenience method which creates a default AudioInputStream object using |
126 // a 10ms frame size and a sample rate which is set to the hardware sample | 122 // a 10ms frame size and a sample rate which is set to the hardware sample |
127 // rate. | 123 // rate. |
128 AudioInputStream* CreateDefaultAudioInputStream() { | 124 AudioInputStream* CreateDefaultAudioInputStream() { |
129 int fs = static_cast<int>(AUAudioInputStream::HardwareSampleRate()); | 125 int fs = static_cast<int>(AUAudioInputStream::HardwareSampleRate()); |
(...skipping 13 matching lines...) Expand all Loading... |
143 int samples_per_packet = fs / 100; | 139 int samples_per_packet = fs / 100; |
144 AudioInputStream* ais = audio_manager_->MakeAudioInputStream( | 140 AudioInputStream* ais = audio_manager_->MakeAudioInputStream( |
145 AudioParameters(AudioParameters::AUDIO_PCM_LOW_LATENCY, | 141 AudioParameters(AudioParameters::AUDIO_PCM_LOW_LATENCY, |
146 channel_layout, fs, 16, samples_per_packet), | 142 channel_layout, fs, 16, samples_per_packet), |
147 AudioManagerBase::kDefaultDeviceId); | 143 AudioManagerBase::kDefaultDeviceId); |
148 EXPECT_TRUE(ais); | 144 EXPECT_TRUE(ais); |
149 return ais; | 145 return ais; |
150 } | 146 } |
151 | 147 |
152 base::MessageLoop message_loop_; | 148 base::MessageLoop message_loop_; |
153 ScopedAudioManagerPtr audio_manager_; | 149 scoped_ptr<AudioManager> audio_manager_; |
154 }; | 150 }; |
155 | 151 |
156 // Test Create(), Close(). | 152 // Test Create(), Close(). |
157 TEST_F(MacAudioInputTest, AUAudioInputStreamCreateAndClose) { | 153 TEST_F(MacAudioInputTest, AUAudioInputStreamCreateAndClose) { |
158 ABORT_AUDIO_TEST_IF_NOT(InputDevicesAvailable()); | 154 ABORT_AUDIO_TEST_IF_NOT(InputDevicesAvailable()); |
159 AudioInputStream* ais = CreateDefaultAudioInputStream(); | 155 AudioInputStream* ais = CreateDefaultAudioInputStream(); |
160 ais->Close(); | 156 ais->Close(); |
161 } | 157 } |
162 | 158 |
163 // Test Open(), Close(). | 159 // Test Open(), Close(). |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
267 WriteToFileAudioSink file_sink(file_name); | 263 WriteToFileAudioSink file_sink(file_name); |
268 fprintf(stderr, " >> Speak into the mic while recording...\n"); | 264 fprintf(stderr, " >> Speak into the mic while recording...\n"); |
269 ais->Start(&file_sink); | 265 ais->Start(&file_sink); |
270 base::PlatformThread::Sleep(TestTimeouts::action_timeout()); | 266 base::PlatformThread::Sleep(TestTimeouts::action_timeout()); |
271 ais->Stop(); | 267 ais->Stop(); |
272 fprintf(stderr, " >> Recording has stopped.\n"); | 268 fprintf(stderr, " >> Recording has stopped.\n"); |
273 ais->Close(); | 269 ais->Close(); |
274 } | 270 } |
275 | 271 |
276 } // namespace media | 272 } // namespace media |
OLD | NEW |