| 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/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
| 11 #include "base/run_loop.h" | 11 #include "base/run_loop.h" |
| 12 #include "base/test/test_timeouts.h" | 12 #include "base/test/test_timeouts.h" |
| 13 #include "base/threading/platform_thread.h" | 13 #include "base/threading/platform_thread.h" |
| 14 #include "media/audio/audio_device_description.h" |
| 14 #include "media/audio/audio_io.h" | 15 #include "media/audio/audio_io.h" |
| 15 #include "media/audio/audio_manager_base.h" | 16 #include "media/audio/audio_manager_base.h" |
| 16 #include "media/audio/audio_unittest_util.h" | 17 #include "media/audio/audio_unittest_util.h" |
| 17 #include "media/audio/mac/audio_low_latency_input_mac.h" | 18 #include "media/audio/mac/audio_low_latency_input_mac.h" |
| 18 #include "media/base/seekable_buffer.h" | 19 #include "media/base/seekable_buffer.h" |
| 19 #include "testing/gmock/include/gmock/gmock.h" | 20 #include "testing/gmock/include/gmock/gmock.h" |
| 20 #include "testing/gtest/include/gtest/gtest.h" | 21 #include "testing/gtest/include/gtest/gtest.h" |
| 21 | 22 |
| 22 using ::testing::_; | 23 using ::testing::_; |
| 23 using ::testing::AnyNumber; | 24 using ::testing::AnyNumber; |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 125 } | 126 } |
| 126 | 127 |
| 127 // Convenience method which creates a default AudioInputStream object using | 128 // Convenience method which creates a default AudioInputStream object using |
| 128 // a 10ms frame size and a sample rate which is set to the hardware sample | 129 // a 10ms frame size and a sample rate which is set to the hardware sample |
| 129 // rate. | 130 // rate. |
| 130 AudioInputStream* CreateDefaultAudioInputStream() { | 131 AudioInputStream* CreateDefaultAudioInputStream() { |
| 131 int fs = static_cast<int>(AUAudioInputStream::HardwareSampleRate()); | 132 int fs = static_cast<int>(AUAudioInputStream::HardwareSampleRate()); |
| 132 int samples_per_packet = fs / 100; | 133 int samples_per_packet = fs / 100; |
| 133 AudioInputStream* ais = audio_manager_->MakeAudioInputStream( | 134 AudioInputStream* ais = audio_manager_->MakeAudioInputStream( |
| 134 AudioParameters(AudioParameters::AUDIO_PCM_LOW_LATENCY, | 135 AudioParameters(AudioParameters::AUDIO_PCM_LOW_LATENCY, |
| 135 CHANNEL_LAYOUT_STEREO, fs, 16, samples_per_packet), | 136 CHANNEL_LAYOUT_STEREO, fs, 16, samples_per_packet), |
| 136 AudioManagerBase::kDefaultDeviceId); | 137 AudioDeviceDescription::kDefaultDeviceId); |
| 137 EXPECT_TRUE(ais); | 138 EXPECT_TRUE(ais); |
| 138 return ais; | 139 return ais; |
| 139 } | 140 } |
| 140 | 141 |
| 141 // Convenience method which creates an AudioInputStream object with a | 142 // Convenience method which creates an AudioInputStream object with a |
| 142 // specified channel layout. | 143 // specified channel layout. |
| 143 AudioInputStream* CreateAudioInputStream(ChannelLayout channel_layout) { | 144 AudioInputStream* CreateAudioInputStream(ChannelLayout channel_layout) { |
| 144 int fs = static_cast<int>(AUAudioInputStream::HardwareSampleRate()); | 145 int fs = static_cast<int>(AUAudioInputStream::HardwareSampleRate()); |
| 145 int samples_per_packet = fs / 100; | 146 int samples_per_packet = fs / 100; |
| 146 AudioInputStream* ais = audio_manager_->MakeAudioInputStream( | 147 AudioInputStream* ais = audio_manager_->MakeAudioInputStream( |
| 147 AudioParameters(AudioParameters::AUDIO_PCM_LOW_LATENCY, | 148 AudioParameters(AudioParameters::AUDIO_PCM_LOW_LATENCY, channel_layout, |
| 148 channel_layout, fs, 16, samples_per_packet), | 149 fs, 16, samples_per_packet), |
| 149 AudioManagerBase::kDefaultDeviceId); | 150 AudioDeviceDescription::kDefaultDeviceId); |
| 150 EXPECT_TRUE(ais); | 151 EXPECT_TRUE(ais); |
| 151 return ais; | 152 return ais; |
| 152 } | 153 } |
| 153 | 154 |
| 154 base::MessageLoop message_loop_; | 155 base::MessageLoop message_loop_; |
| 155 ScopedAudioManagerPtr audio_manager_; | 156 ScopedAudioManagerPtr audio_manager_; |
| 156 }; | 157 }; |
| 157 | 158 |
| 158 // Test Create(), Close(). | 159 // Test Create(), Close(). |
| 159 TEST_F(MacAudioInputTest, AUAudioInputStreamCreateAndClose) { | 160 TEST_F(MacAudioInputTest, AUAudioInputStreamCreateAndClose) { |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 269 WriteToFileAudioSink file_sink(file_name); | 270 WriteToFileAudioSink file_sink(file_name); |
| 270 fprintf(stderr, " >> Speak into the mic while recording...\n"); | 271 fprintf(stderr, " >> Speak into the mic while recording...\n"); |
| 271 ais->Start(&file_sink); | 272 ais->Start(&file_sink); |
| 272 base::PlatformThread::Sleep(TestTimeouts::action_timeout()); | 273 base::PlatformThread::Sleep(TestTimeouts::action_timeout()); |
| 273 ais->Stop(); | 274 ais->Stop(); |
| 274 fprintf(stderr, " >> Recording has stopped.\n"); | 275 fprintf(stderr, " >> Recording has stopped.\n"); |
| 275 ais->Close(); | 276 ais->Close(); |
| 276 } | 277 } |
| 277 | 278 |
| 278 } // namespace media | 279 } // namespace media |
| OLD | NEW |