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