| 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 { audio_manager_->Shutdown(); } |
| 122 audio_manager_.reset(); | |
| 123 base::RunLoop().RunUntilIdle(); | |
| 124 } | |
| 125 | 124 |
| 126 bool InputDevicesAvailable() { | 125 bool InputDevicesAvailable() { |
| 127 return AudioDeviceInfoAccessorForTests(audio_manager_.get()) | 126 return AudioDeviceInfoAccessorForTests(audio_manager_.get()) |
| 128 .HasAudioInputDevices(); | 127 .HasAudioInputDevices(); |
| 129 } | 128 } |
| 130 | 129 |
| 131 // Convenience method which creates a default AudioInputStream object using | 130 // Convenience method which creates a default AudioInputStream object using |
| 132 // a 10ms frame size and a sample rate which is set to the hardware sample | 131 // a 10ms frame size and a sample rate which is set to the hardware sample |
| 133 // rate. | 132 // rate. |
| 134 AudioInputStream* CreateDefaultAudioInputStream() { | 133 AudioInputStream* CreateDefaultAudioInputStream() { |
| (...skipping 18 matching lines...) Expand all Loading... |
| 153 fs, 16, samples_per_packet), | 152 fs, 16, samples_per_packet), |
| 154 AudioDeviceDescription::kDefaultDeviceId, | 153 AudioDeviceDescription::kDefaultDeviceId, |
| 155 base::Bind(&MacAudioInputTest::OnLogMessage, base::Unretained(this))); | 154 base::Bind(&MacAudioInputTest::OnLogMessage, base::Unretained(this))); |
| 156 EXPECT_TRUE(ais); | 155 EXPECT_TRUE(ais); |
| 157 return ais; | 156 return ais; |
| 158 } | 157 } |
| 159 | 158 |
| 160 void OnLogMessage(const std::string& message) { log_message_ = message; } | 159 void OnLogMessage(const std::string& message) { log_message_ = message; } |
| 161 | 160 |
| 162 base::MessageLoop message_loop_; | 161 base::MessageLoop message_loop_; |
| 163 ScopedAudioManagerPtr audio_manager_; | 162 std::unique_ptr<AudioManager> audio_manager_; |
| 164 std::string log_message_; | 163 std::string log_message_; |
| 165 }; | 164 }; |
| 166 | 165 |
| 167 // Test Create(), Close(). | 166 // Test Create(), Close(). |
| 168 TEST_F(MacAudioInputTest, AUAudioInputStreamCreateAndClose) { | 167 TEST_F(MacAudioInputTest, AUAudioInputStreamCreateAndClose) { |
| 169 ABORT_AUDIO_TEST_IF_NOT(InputDevicesAvailable()); | 168 ABORT_AUDIO_TEST_IF_NOT(InputDevicesAvailable()); |
| 170 AudioInputStream* ais = CreateDefaultAudioInputStream(); | 169 AudioInputStream* ais = CreateDefaultAudioInputStream(); |
| 171 ais->Close(); | 170 ais->Close(); |
| 172 } | 171 } |
| 173 | 172 |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 282 WriteToFileAudioSink file_sink(file_name); | 281 WriteToFileAudioSink file_sink(file_name); |
| 283 fprintf(stderr, " >> Speak into the mic while recording...\n"); | 282 fprintf(stderr, " >> Speak into the mic while recording...\n"); |
| 284 ais->Start(&file_sink); | 283 ais->Start(&file_sink); |
| 285 base::PlatformThread::Sleep(TestTimeouts::action_timeout()); | 284 base::PlatformThread::Sleep(TestTimeouts::action_timeout()); |
| 286 ais->Stop(); | 285 ais->Stop(); |
| 287 fprintf(stderr, " >> Recording has stopped.\n"); | 286 fprintf(stderr, " >> Recording has stopped.\n"); |
| 288 ais->Close(); | 287 ais->Close(); |
| 289 } | 288 } |
| 290 | 289 |
| 291 } // namespace media | 290 } // namespace media |
| OLD | NEW |