| 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/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
| 8 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
| 9 #include "base/threading/platform_thread.h" | 9 #include "base/threading/platform_thread.h" |
| 10 #include "media/audio/audio_io.h" | 10 #include "media/audio/audio_io.h" |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 81 if (callback_count() > block_after_callback_) | 81 if (callback_count() > block_after_callback_) |
| 82 base::PlatformThread::Sleep(block_for_ms_); | 82 base::PlatformThread::Sleep(block_for_ms_); |
| 83 } | 83 } |
| 84 | 84 |
| 85 private: | 85 private: |
| 86 int block_after_callback_; | 86 int block_after_callback_; |
| 87 int block_for_ms_; | 87 int block_for_ms_; |
| 88 }; | 88 }; |
| 89 | 89 |
| 90 static bool CanRunAudioTests(AudioManager* audio_man) { | 90 static bool CanRunAudioTests(AudioManager* audio_man) { |
| 91 if (NULL == audio_man) | 91 bool has_input = audio_man->HasAudioInputDevices(); |
| 92 return false; | |
| 93 | 92 |
| 94 scoped_ptr<base::Environment> env(base::Environment::Create()); | 93 if (!has_input) |
| 95 if (env->HasVar("CHROME_HEADLESS")) | 94 LOG(WARNING) << "No input devices detected"; |
| 96 return false; | |
| 97 | 95 |
| 98 return audio_man->HasAudioInputDevices(); | 96 return has_input; |
| 99 } | 97 } |
| 100 | 98 |
| 101 static AudioInputStream* CreateTestAudioInputStream(AudioManager* audio_man) { | 99 static AudioInputStream* CreateTestAudioInputStream(AudioManager* audio_man) { |
| 102 AudioInputStream* ais = audio_man->MakeAudioInputStream( | 100 AudioInputStream* ais = audio_man->MakeAudioInputStream( |
| 103 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_STEREO, | 101 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_STEREO, |
| 104 kSamplingRate, 16, kSamplesPerPacket), | 102 kSamplingRate, 16, kSamplesPerPacket), |
| 105 AudioManagerBase::kDefaultDeviceId); | 103 AudioManagerBase::kDefaultDeviceId); |
| 106 EXPECT_TRUE(NULL != ais); | 104 EXPECT_TRUE(NULL != ais); |
| 107 return ais; | 105 return ais; |
| 108 } | 106 } |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 187 message_loop.PostDelayedTask(FROM_HERE, MessageLoop::QuitClosure(), 590); | 185 message_loop.PostDelayedTask(FROM_HERE, MessageLoop::QuitClosure(), 590); |
| 188 message_loop.Run(); | 186 message_loop.Run(); |
| 189 EXPECT_GE(test_callback.callback_count(), 10); | 187 EXPECT_GE(test_callback.callback_count(), 10); |
| 190 EXPECT_FALSE(test_callback.had_error()); | 188 EXPECT_FALSE(test_callback.had_error()); |
| 191 | 189 |
| 192 ais->Stop(); | 190 ais->Stop(); |
| 193 ais->Close(); | 191 ais->Close(); |
| 194 } | 192 } |
| 195 | 193 |
| 196 // Test a recording sequence with delays in the audio callback. | 194 // Test a recording sequence with delays in the audio callback. |
| 195 // TODO(joth): See bug 107546. This fails on slow bots. Once fixed, remove the |
| 196 // CHROME_HEADLESS check below. |
| 197 TEST(AudioInputTest, RecordWithSlowSink) { | 197 TEST(AudioInputTest, RecordWithSlowSink) { |
| 198 scoped_refptr<AudioManager> audio_man(AudioManager::Create()); | 198 scoped_refptr<AudioManager> audio_man(AudioManager::Create()); |
| 199 if (!CanRunAudioTests(audio_man.get())) | 199 if (!CanRunAudioTests(audio_man.get())) |
| 200 return; | 200 return; |
| 201 |
| 202 scoped_ptr<base::Environment> env(base::Environment::Create()); |
| 203 if (env->HasVar("CHROME_HEADLESS")) |
| 204 return; |
| 205 |
| 201 MessageLoop message_loop(MessageLoop::TYPE_DEFAULT); | 206 MessageLoop message_loop(MessageLoop::TYPE_DEFAULT); |
| 202 AudioInputStream* ais = CreateTestAudioInputStream(audio_man.get()); | 207 AudioInputStream* ais = CreateTestAudioInputStream(audio_man.get()); |
| 203 EXPECT_TRUE(ais->Open()); | 208 EXPECT_TRUE(ais->Open()); |
| 204 | 209 |
| 205 // We should normally get a callback every 50ms, and a 20ms delay inside each | 210 // We should normally get a callback every 50ms, and a 20ms delay inside each |
| 206 // callback should not change this sequence. | 211 // callback should not change this sequence. |
| 207 TestInputCallbackBlocking test_callback(kSamplesPerPacket * 4, 0, 20); | 212 TestInputCallbackBlocking test_callback(kSamplesPerPacket * 4, 0, 20); |
| 208 ais->Start(&test_callback); | 213 ais->Start(&test_callback); |
| 209 // Verify at least 500ms worth of audio was recorded, after giving sufficient | 214 // Verify at least 500ms worth of audio was recorded, after giving sufficient |
| 210 // extra time. | 215 // extra time. |
| 211 message_loop.PostDelayedTask(FROM_HERE, MessageLoop::QuitClosure(), 590); | 216 message_loop.PostDelayedTask(FROM_HERE, MessageLoop::QuitClosure(), 590); |
| 212 message_loop.Run(); | 217 message_loop.Run(); |
| 213 EXPECT_GE(test_callback.callback_count(), 10); | 218 EXPECT_GE(test_callback.callback_count(), 10); |
| 214 EXPECT_FALSE(test_callback.had_error()); | 219 EXPECT_FALSE(test_callback.had_error()); |
| 215 | 220 |
| 216 ais->Stop(); | 221 ais->Stop(); |
| 217 ais->Close(); | 222 ais->Close(); |
| 218 } | 223 } |
| OLD | NEW |