OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "base/basictypes.h" | 5 #include "base/basictypes.h" |
6 #include "base/environment.h" | 6 #include "base/environment.h" |
7 #include "base/test/test_timeouts.h" | 7 #include "base/test/test_timeouts.h" |
8 #include "base/threading/platform_thread.h" | 8 #include "base/threading/platform_thread.h" |
9 #include "media/audio/audio_io.h" | 9 #include "media/audio/audio_io.h" |
10 #include "media/audio/audio_manager_base.h" | 10 #include "media/audio/audio_manager_base.h" |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
85 }; | 85 }; |
86 | 86 |
87 class MacAudioInputTest : public testing::Test { | 87 class MacAudioInputTest : public testing::Test { |
88 protected: | 88 protected: |
89 MacAudioInputTest() : audio_manager_(AudioManager::Create()) {} | 89 MacAudioInputTest() : audio_manager_(AudioManager::Create()) {} |
90 virtual ~MacAudioInputTest() {} | 90 virtual ~MacAudioInputTest() {} |
91 | 91 |
92 // Convenience method which ensures that we are not running on the build | 92 // Convenience method which ensures that we are not running on the build |
93 // bots and that at least one valid input device can be found. | 93 // bots and that at least one valid input device can be found. |
94 bool CanRunAudioTests() { | 94 bool CanRunAudioTests() { |
95 scoped_ptr<base::Environment> env(base::Environment::Create()); | 95 bool has_input = audio_manager_->HasAudioInputDevices(); |
96 if (env->HasVar("CHROME_HEADLESS")) | 96 if (!has_input) |
97 return false; | 97 LOG(WARNING) << "No input devices detected"; |
98 return audio_manager_->HasAudioInputDevices(); | 98 return has_input; |
99 } | 99 } |
100 | 100 |
101 // Convenience method which creates a default AudioInputStream object using | 101 // Convenience method which creates a default AudioInputStream object using |
102 // a 10ms frame size and a sample rate which is set to the hardware sample | 102 // a 10ms frame size and a sample rate which is set to the hardware sample |
103 // rate. | 103 // rate. |
104 AudioInputStream* CreateDefaultAudioInputStream() { | 104 AudioInputStream* CreateDefaultAudioInputStream() { |
105 int fs = static_cast<int>(AUAudioInputStream::HardwareSampleRate()); | 105 int fs = static_cast<int>(AUAudioInputStream::HardwareSampleRate()); |
106 int samples_per_packet = fs / 100; | 106 int samples_per_packet = fs / 100; |
107 AudioInputStream* ais = audio_manager_->MakeAudioInputStream( | 107 AudioInputStream* ais = audio_manager_->MakeAudioInputStream( |
108 AudioParameters(AudioParameters::AUDIO_PCM_LOW_LATENCY, | 108 AudioParameters(AudioParameters::AUDIO_PCM_LOW_LATENCY, |
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
289 fprintf(stderr, " Sample rate: %d\n", fs); | 289 fprintf(stderr, " Sample rate: %d\n", fs); |
290 WriteToFileAudioSink file_sink(file_name); | 290 WriteToFileAudioSink file_sink(file_name); |
291 fprintf(stderr, " >> Speak into the mic while recording...\n"); | 291 fprintf(stderr, " >> Speak into the mic while recording...\n"); |
292 ais->Start(&file_sink); | 292 ais->Start(&file_sink); |
293 base::PlatformThread::Sleep(TestTimeouts::action_timeout_ms()); | 293 base::PlatformThread::Sleep(TestTimeouts::action_timeout_ms()); |
294 ais->Stop(); | 294 ais->Stop(); |
295 fprintf(stderr, " >> Recording has stopped.\n"); | 295 fprintf(stderr, " >> Recording has stopped.\n"); |
296 ais->Close(); | 296 ais->Close(); |
297 } | 297 } |
298 | 298 |
OLD | NEW |