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 | 8 |
9 #include "base/environment.h" | 9 #include "base/environment.h" |
| 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/test/test_timeouts.h" | 14 #include "base/test/test_timeouts.h" |
14 #include "base/threading/platform_thread.h" | 15 #include "base/threading/platform_thread.h" |
15 #include "media/audio/audio_device_description.h" | 16 #include "media/audio/audio_device_description.h" |
16 #include "media/audio/audio_device_info_accessor_for_tests.h" | 17 #include "media/audio/audio_device_info_accessor_for_tests.h" |
17 #include "media/audio/audio_io.h" | 18 #include "media/audio/audio_io.h" |
18 #include "media/audio/audio_manager_base.h" | 19 #include "media/audio/audio_manager_base.h" |
19 #include "media/audio/audio_unittest_util.h" | 20 #include "media/audio/audio_unittest_util.h" |
20 #include "media/audio/mac/audio_low_latency_input_mac.h" | 21 #include "media/audio/mac/audio_low_latency_input_mac.h" |
| 22 #include "media/audio/test_audio_thread.h" |
21 #include "media/base/seekable_buffer.h" | 23 #include "media/base/seekable_buffer.h" |
22 #include "testing/gmock/include/gmock/gmock.h" | 24 #include "testing/gmock/include/gmock/gmock.h" |
23 #include "testing/gtest/include/gtest/gtest.h" | 25 #include "testing/gtest/include/gtest/gtest.h" |
24 | 26 |
25 using ::testing::_; | 27 using ::testing::_; |
26 using ::testing::AnyNumber; | 28 using ::testing::AnyNumber; |
27 using ::testing::AtLeast; | 29 using ::testing::AtLeast; |
28 using ::testing::Ge; | 30 using ::testing::Ge; |
29 using ::testing::NotNull; | 31 using ::testing::NotNull; |
30 | 32 |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
105 private: | 107 private: |
106 media::SeekableBuffer buffer_; | 108 media::SeekableBuffer buffer_; |
107 FILE* file_; | 109 FILE* file_; |
108 int bytes_to_write_; | 110 int bytes_to_write_; |
109 }; | 111 }; |
110 | 112 |
111 class MacAudioInputTest : public testing::Test { | 113 class MacAudioInputTest : public testing::Test { |
112 protected: | 114 protected: |
113 MacAudioInputTest() | 115 MacAudioInputTest() |
114 : message_loop_(base::MessageLoop::TYPE_UI), | 116 : message_loop_(base::MessageLoop::TYPE_UI), |
115 audio_manager_( | 117 audio_manager_(AudioManager::CreateForTesting( |
116 AudioManager::CreateForTesting(message_loop_.task_runner())) { | 118 base::MakeUnique<TestAudioThread>())) { |
117 // Wait for the AudioManager to finish any initialization on the audio loop. | 119 // Wait for the AudioManager to finish any initialization on the audio loop. |
118 base::RunLoop().RunUntilIdle(); | 120 base::RunLoop().RunUntilIdle(); |
119 } | 121 } |
120 | 122 |
121 ~MacAudioInputTest() override { | 123 ~MacAudioInputTest() override { |
122 audio_manager_.reset(); | 124 audio_manager_.reset(); |
123 base::RunLoop().RunUntilIdle(); | 125 base::RunLoop().RunUntilIdle(); |
124 } | 126 } |
125 | 127 |
126 bool InputDevicesAvailable() { | 128 bool InputDevicesAvailable() { |
(...skipping 26 matching lines...) Expand all Loading... |
153 fs, 16, samples_per_packet), | 155 fs, 16, samples_per_packet), |
154 AudioDeviceDescription::kDefaultDeviceId, | 156 AudioDeviceDescription::kDefaultDeviceId, |
155 base::Bind(&MacAudioInputTest::OnLogMessage, base::Unretained(this))); | 157 base::Bind(&MacAudioInputTest::OnLogMessage, base::Unretained(this))); |
156 EXPECT_TRUE(ais); | 158 EXPECT_TRUE(ais); |
157 return ais; | 159 return ais; |
158 } | 160 } |
159 | 161 |
160 void OnLogMessage(const std::string& message) { log_message_ = message; } | 162 void OnLogMessage(const std::string& message) { log_message_ = message; } |
161 | 163 |
162 base::MessageLoop message_loop_; | 164 base::MessageLoop message_loop_; |
163 ScopedAudioManagerPtr audio_manager_; | 165 std::unique_ptr<AudioManager> audio_manager_; |
164 std::string log_message_; | 166 std::string log_message_; |
165 }; | 167 }; |
166 | 168 |
167 // Test Create(), Close(). | 169 // Test Create(), Close(). |
168 TEST_F(MacAudioInputTest, AUAudioInputStreamCreateAndClose) { | 170 TEST_F(MacAudioInputTest, AUAudioInputStreamCreateAndClose) { |
169 ABORT_AUDIO_TEST_IF_NOT(InputDevicesAvailable()); | 171 ABORT_AUDIO_TEST_IF_NOT(InputDevicesAvailable()); |
170 AudioInputStream* ais = CreateDefaultAudioInputStream(); | 172 AudioInputStream* ais = CreateDefaultAudioInputStream(); |
171 ais->Close(); | 173 ais->Close(); |
172 } | 174 } |
173 | 175 |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
282 WriteToFileAudioSink file_sink(file_name); | 284 WriteToFileAudioSink file_sink(file_name); |
283 fprintf(stderr, " >> Speak into the mic while recording...\n"); | 285 fprintf(stderr, " >> Speak into the mic while recording...\n"); |
284 ais->Start(&file_sink); | 286 ais->Start(&file_sink); |
285 base::PlatformThread::Sleep(TestTimeouts::action_timeout()); | 287 base::PlatformThread::Sleep(TestTimeouts::action_timeout()); |
286 ais->Stop(); | 288 ais->Stop(); |
287 fprintf(stderr, " >> Recording has stopped.\n"); | 289 fprintf(stderr, " >> Recording has stopped.\n"); |
288 ais->Close(); | 290 ais->Close(); |
289 } | 291 } |
290 | 292 |
291 } // namespace media | 293 } // namespace media |
OLD | NEW |