| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 <windows.h> | 5 #include <windows.h> |
| 6 #include <mmsystem.h> | 6 #include <mmsystem.h> |
| 7 | 7 |
| 8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
| 9 #include "base/base_paths.h" | 9 #include "base/base_paths.h" |
| 10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
| (...skipping 18 matching lines...) Expand all Loading... |
| 29 | 29 |
| 30 const wchar_t kAudioFile1_16b_m_16K[] | 30 const wchar_t kAudioFile1_16b_m_16K[] |
| 31 = L"media\\test\\data\\sweep02_16b_mono_16KHz.raw"; | 31 = L"media\\test\\data\\sweep02_16b_mono_16KHz.raw"; |
| 32 | 32 |
| 33 // This class allows to find out if the callbacks are occurring as | 33 // This class allows to find out if the callbacks are occurring as |
| 34 // expected and if any error has been reported. | 34 // expected and if any error has been reported. |
| 35 class TestSourceBasic : public AudioOutputStream::AudioSourceCallback { | 35 class TestSourceBasic : public AudioOutputStream::AudioSourceCallback { |
| 36 public: | 36 public: |
| 37 explicit TestSourceBasic() | 37 explicit TestSourceBasic() |
| 38 : callback_count_(0), | 38 : callback_count_(0), |
| 39 had_error_(0), | 39 had_error_(0) { |
| 40 was_closed_(0) { | |
| 41 } | 40 } |
| 42 // AudioSourceCallback::OnMoreData implementation: | 41 // AudioSourceCallback::OnMoreData implementation: |
| 43 virtual uint32 OnMoreData(AudioOutputStream* stream, uint8* dest, | 42 virtual uint32 OnMoreData(AudioOutputStream* stream, uint8* dest, |
| 44 uint32 max_size, AudioBuffersState buffers_state) { | 43 uint32 max_size, AudioBuffersState buffers_state) { |
| 45 ++callback_count_; | 44 ++callback_count_; |
| 46 // Touch the first byte to make sure memory is good. | 45 // Touch the first byte to make sure memory is good. |
| 47 if (max_size) | 46 if (max_size) |
| 48 reinterpret_cast<char*>(dest)[0] = 1; | 47 reinterpret_cast<char*>(dest)[0] = 1; |
| 49 return max_size; | 48 return max_size; |
| 50 } | 49 } |
| 51 // AudioSourceCallback::OnClose implementation: | |
| 52 virtual void OnClose(AudioOutputStream* stream) { | |
| 53 ++was_closed_; | |
| 54 } | |
| 55 // AudioSourceCallback::OnError implementation: | 50 // AudioSourceCallback::OnError implementation: |
| 56 virtual void OnError(AudioOutputStream* stream, int code) { | 51 virtual void OnError(AudioOutputStream* stream, int code) { |
| 57 ++had_error_; | 52 ++had_error_; |
| 58 } | 53 } |
| 59 // Returns how many times OnMoreData() has been called. | 54 // Returns how many times OnMoreData() has been called. |
| 60 int callback_count() const { | 55 int callback_count() const { |
| 61 return callback_count_; | 56 return callback_count_; |
| 62 } | 57 } |
| 63 // Returns how many times the OnError callback was called. | 58 // Returns how many times the OnError callback was called. |
| 64 int had_error() const { | 59 int had_error() const { |
| 65 return had_error_; | 60 return had_error_; |
| 66 } | 61 } |
| 67 | 62 |
| 68 void set_error(bool error) { | 63 void set_error(bool error) { |
| 69 had_error_ += error ? 1 : 0; | 64 had_error_ += error ? 1 : 0; |
| 70 } | 65 } |
| 71 // Returns how many times the OnClose callback was called. | |
| 72 int was_closed() const { | |
| 73 return was_closed_; | |
| 74 } | |
| 75 | 66 |
| 76 private: | 67 private: |
| 77 int callback_count_; | 68 int callback_count_; |
| 78 int had_error_; | 69 int had_error_; |
| 79 int was_closed_; | |
| 80 }; | 70 }; |
| 81 | 71 |
| 82 bool IsRunningHeadless() { | 72 bool IsRunningHeadless() { |
| 83 return (0 != ::GetEnvironmentVariableW(L"CHROME_HEADLESS", NULL, 0)); | 73 return (0 != ::GetEnvironmentVariableW(L"CHROME_HEADLESS", NULL, 0)); |
| 84 } | 74 } |
| 85 | 75 |
| 86 } // namespace. | 76 } // namespace. |
| 87 | 77 |
| 88 const int kNumBuffers = 3; | 78 const int kNumBuffers = 3; |
| 89 // Specializes TestSourceBasic to detect that the AudioStream is using | 79 // Specializes TestSourceBasic to detect that the AudioStream is using |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 146 private: | 136 private: |
| 147 int laggy_after_buffer_; | 137 int laggy_after_buffer_; |
| 148 int lag_in_ms_; | 138 int lag_in_ms_; |
| 149 }; | 139 }; |
| 150 | 140 |
| 151 class MockAudioSource : public AudioOutputStream::AudioSourceCallback { | 141 class MockAudioSource : public AudioOutputStream::AudioSourceCallback { |
| 152 public: | 142 public: |
| 153 MOCK_METHOD4(OnMoreData, uint32(AudioOutputStream* stream, uint8* dest, | 143 MOCK_METHOD4(OnMoreData, uint32(AudioOutputStream* stream, uint8* dest, |
| 154 uint32 max_size, | 144 uint32 max_size, |
| 155 AudioBuffersState buffers_state)); | 145 AudioBuffersState buffers_state)); |
| 156 MOCK_METHOD1(OnClose, void(AudioOutputStream* stream)); | |
| 157 MOCK_METHOD2(OnError, void(AudioOutputStream* stream, int code)); | 146 MOCK_METHOD2(OnError, void(AudioOutputStream* stream, int code)); |
| 158 }; | 147 }; |
| 159 | 148 |
| 160 // Helper class to memory map an entire file. The mapping is read-only. Don't | 149 // Helper class to memory map an entire file. The mapping is read-only. Don't |
| 161 // use for gigabyte-sized files. Attempts to write to this memory generate | 150 // use for gigabyte-sized files. Attempts to write to this memory generate |
| 162 // memory access violations. | 151 // memory access violations. |
| 163 class ReadOnlyMappedFile { | 152 class ReadOnlyMappedFile { |
| 164 public: | 153 public: |
| 165 explicit ReadOnlyMappedFile(const wchar_t* file_name) | 154 explicit ReadOnlyMappedFile(const wchar_t* file_name) |
| 166 : fmap_(NULL), start_(NULL), size_(0) { | 155 : fmap_(NULL), start_(NULL), size_(0) { |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 204 char* start_; | 193 char* start_; |
| 205 uint32 size_; | 194 uint32 size_; |
| 206 }; | 195 }; |
| 207 | 196 |
| 208 // ============================================================================ | 197 // ============================================================================ |
| 209 // Validate that the AudioManager::AUDIO_MOCK callbacks work. | 198 // Validate that the AudioManager::AUDIO_MOCK callbacks work. |
| 210 TEST(WinAudioTest, MockStreamBasicCallbacks) { | 199 TEST(WinAudioTest, MockStreamBasicCallbacks) { |
| 211 AudioManager* audio_man = AudioManager::GetAudioManager(); | 200 AudioManager* audio_man = AudioManager::GetAudioManager(); |
| 212 ASSERT_TRUE(NULL != audio_man); | 201 ASSERT_TRUE(NULL != audio_man); |
| 213 AudioOutputStream* oas = audio_man->MakeAudioOutputStream( | 202 AudioOutputStream* oas = audio_man->MakeAudioOutputStream( |
| 214 AudioParameters(AudioParameters::AUDIO_MOCK, 2, 8000, 8)); | 203 AudioParameters(AudioParameters::AUDIO_MOCK, 2, 8000, 8, 128)); |
| 215 ASSERT_TRUE(NULL != oas); | 204 ASSERT_TRUE(NULL != oas); |
| 216 EXPECT_TRUE(oas->Open(256)); | 205 EXPECT_TRUE(oas->Open()); |
| 217 TestSourceBasic source; | 206 TestSourceBasic source; |
| 218 oas->Start(&source); | 207 oas->Start(&source); |
| 219 EXPECT_GT(source.callback_count(), 0); | 208 EXPECT_GT(source.callback_count(), 0); |
| 220 oas->Stop(); | 209 oas->Stop(); |
| 221 oas->Close(); | 210 oas->Close(); |
| 222 EXPECT_EQ(0, source.had_error()); | 211 EXPECT_EQ(0, source.had_error()); |
| 223 EXPECT_EQ(1, source.was_closed()); | |
| 224 } | 212 } |
| 225 | 213 |
| 226 // =========================================================================== | 214 // =========================================================================== |
| 227 // Validation of AudioManager::AUDIO_PCM_LINEAR | 215 // Validation of AudioManager::AUDIO_PCM_LINEAR |
| 228 // | 216 // |
| 229 // The tests tend to fail in the build bots when somebody connects to them via | 217 // The tests tend to fail in the build bots when somebody connects to them via |
| 230 // via remote-desktop because it installs an audio device that fails to open | 218 // via remote-desktop because it installs an audio device that fails to open |
| 231 // at some point, possibly when the connection goes idle. So that is why we | 219 // at some point, possibly when the connection goes idle. So that is why we |
| 232 // skipped them in headless mode. | 220 // skipped them in headless mode. |
| 233 | 221 |
| 234 // Test that can it be created and closed. | 222 // Test that can it be created and closed. |
| 235 TEST(WinAudioTest, PCMWaveStreamGetAndClose) { | 223 TEST(WinAudioTest, PCMWaveStreamGetAndClose) { |
| 236 if (IsRunningHeadless()) | 224 if (IsRunningHeadless()) |
| 237 return; | 225 return; |
| 238 AudioManager* audio_man = AudioManager::GetAudioManager(); | 226 AudioManager* audio_man = AudioManager::GetAudioManager(); |
| 239 ASSERT_TRUE(NULL != audio_man); | 227 ASSERT_TRUE(NULL != audio_man); |
| 240 if (!audio_man->HasAudioOutputDevices()) | 228 if (!audio_man->HasAudioOutputDevices()) |
| 241 return; | 229 return; |
| 242 AudioOutputStream* oas = audio_man->MakeAudioOutputStream( | 230 AudioOutputStream* oas = audio_man->MakeAudioOutputStream( |
| 243 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, 2, 8000, 16)); | 231 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, 2, 8000, 16, 256)); |
| 244 ASSERT_TRUE(NULL != oas); | 232 ASSERT_TRUE(NULL != oas); |
| 245 oas->Close(); | 233 oas->Close(); |
| 246 } | 234 } |
| 247 | 235 |
| 248 // Test that can it be cannot be created with crazy parameters | 236 // Test that can it be cannot be created with crazy parameters |
| 249 TEST(WinAudioTest, SanityOnMakeParams) { | 237 TEST(WinAudioTest, SanityOnMakeParams) { |
| 250 if (IsRunningHeadless()) | 238 if (IsRunningHeadless()) |
| 251 return; | 239 return; |
| 252 AudioManager* audio_man = AudioManager::GetAudioManager(); | 240 AudioManager* audio_man = AudioManager::GetAudioManager(); |
| 253 ASSERT_TRUE(NULL != audio_man); | 241 ASSERT_TRUE(NULL != audio_man); |
| 254 if (!audio_man->HasAudioOutputDevices()) | 242 if (!audio_man->HasAudioOutputDevices()) |
| 255 return; | 243 return; |
| 256 AudioParameters::Format fmt = AudioParameters::AUDIO_PCM_LINEAR; | 244 AudioParameters::Format fmt = AudioParameters::AUDIO_PCM_LINEAR; |
| 257 EXPECT_TRUE(NULL == audio_man->MakeAudioOutputStream( | 245 EXPECT_TRUE(NULL == audio_man->MakeAudioOutputStream( |
| 258 AudioParameters(fmt, 9, 8000, 16))); | 246 AudioParameters(fmt, 9, 8000, 16, 256))); |
| 259 EXPECT_TRUE(NULL == audio_man->MakeAudioOutputStream( | 247 EXPECT_TRUE(NULL == audio_man->MakeAudioOutputStream( |
| 260 AudioParameters(fmt, 1, 1024 * 1024, 16))); | 248 AudioParameters(fmt, 1, 1024 * 1024, 16, 256))); |
| 261 EXPECT_TRUE(NULL == audio_man->MakeAudioOutputStream( | 249 EXPECT_TRUE(NULL == audio_man->MakeAudioOutputStream( |
| 262 AudioParameters(fmt, 2, 8000, 80))); | 250 AudioParameters(fmt, 2, 8000, 80, 256))); |
| 263 EXPECT_TRUE(NULL == audio_man->MakeAudioOutputStream( | 251 EXPECT_TRUE(NULL == audio_man->MakeAudioOutputStream( |
| 264 AudioParameters(fmt, -2, 8000, 16))); | 252 AudioParameters(fmt, -2, 8000, 16, 256))); |
| 265 EXPECT_TRUE(NULL == audio_man->MakeAudioOutputStream( | 253 EXPECT_TRUE(NULL == audio_man->MakeAudioOutputStream( |
| 266 AudioParameters(fmt, 2, -8000, 16))); | 254 AudioParameters(fmt, 2, -8000, 16, 256))); |
| 267 EXPECT_TRUE(NULL == audio_man->MakeAudioOutputStream( | 255 EXPECT_TRUE(NULL == audio_man->MakeAudioOutputStream( |
| 268 AudioParameters(fmt, 2, -8000, -16))); | 256 AudioParameters(fmt, 1, 8000, 16, -100))); |
| 257 EXPECT_TRUE(NULL == audio_man->MakeAudioOutputStream( |
| 258 AudioParameters(fmt, 1, 8000, 16, 0))); |
| 259 EXPECT_TRUE(NULL == audio_man->MakeAudioOutputStream( |
| 260 AudioParameters(fmt, 1, 8000, 16, 100000))); |
| 269 } | 261 } |
| 270 | 262 |
| 271 // Test that it can be opened and closed. | 263 // Test that it can be opened and closed. |
| 272 TEST(WinAudioTest, PCMWaveStreamOpenAndClose) { | 264 TEST(WinAudioTest, PCMWaveStreamOpenAndClose) { |
| 273 if (IsRunningHeadless()) | 265 if (IsRunningHeadless()) |
| 274 return; | 266 return; |
| 275 AudioManager* audio_man = AudioManager::GetAudioManager(); | 267 AudioManager* audio_man = AudioManager::GetAudioManager(); |
| 276 ASSERT_TRUE(NULL != audio_man); | 268 ASSERT_TRUE(NULL != audio_man); |
| 277 if (!audio_man->HasAudioOutputDevices()) | 269 if (!audio_man->HasAudioOutputDevices()) |
| 278 return; | 270 return; |
| 279 AudioOutputStream* oas = audio_man->MakeAudioOutputStream( | 271 AudioOutputStream* oas = audio_man->MakeAudioOutputStream( |
| 280 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, 2, 8000, 16)); | 272 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, 2, 8000, 16, 256)); |
| 281 ASSERT_TRUE(NULL != oas); | 273 ASSERT_TRUE(NULL != oas); |
| 282 EXPECT_TRUE(oas->Open(1024)); | 274 EXPECT_TRUE(oas->Open()); |
| 283 oas->Close(); | 275 oas->Close(); |
| 284 } | 276 } |
| 285 | 277 |
| 286 // Test that it has a maximum packet size. | 278 // Test that it has a maximum packet size. |
| 287 TEST(WinAudioTest, PCMWaveStreamOpenLimit) { | 279 TEST(WinAudioTest, PCMWaveStreamOpenLimit) { |
| 288 if (IsRunningHeadless()) | 280 if (IsRunningHeadless()) |
| 289 return; | 281 return; |
| 290 AudioManager* audio_man = AudioManager::GetAudioManager(); | 282 AudioManager* audio_man = AudioManager::GetAudioManager(); |
| 291 ASSERT_TRUE(NULL != audio_man); | 283 ASSERT_TRUE(NULL != audio_man); |
| 292 if (!audio_man->HasAudioOutputDevices()) | 284 if (!audio_man->HasAudioOutputDevices()) |
| 293 return; | 285 return; |
| 294 AudioOutputStream* oas = audio_man->MakeAudioOutputStream( | 286 AudioOutputStream* oas = audio_man->MakeAudioOutputStream( |
| 295 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, 2, 8000, 16)); | 287 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, 2, 8000, 16, |
| 296 ASSERT_TRUE(NULL != oas); | 288 1024 * 1024 * 1024)); |
| 297 EXPECT_FALSE(oas->Open(1024 * 1024 * 1024)); | 289 ASSERT_TRUE(NULL == oas); |
| 298 oas->Close(); | 290 oas->Close(); |
| 299 } | 291 } |
| 300 | 292 |
| 301 // Test that it uses the triple buffers correctly. Because it uses the actual | 293 // Test that it uses the triple buffers correctly. Because it uses the actual |
| 302 // audio device, you might hear a short pop noise for a short time. | 294 // audio device, you might hear a short pop noise for a short time. |
| 303 TEST(WinAudioTest, PCMWaveStreamTripleBuffer) { | 295 TEST(WinAudioTest, PCMWaveStreamTripleBuffer) { |
| 304 if (IsRunningHeadless()) | 296 if (IsRunningHeadless()) |
| 305 return; | 297 return; |
| 306 AudioManager* audio_man = AudioManager::GetAudioManager(); | 298 AudioManager* audio_man = AudioManager::GetAudioManager(); |
| 307 ASSERT_TRUE(NULL != audio_man); | 299 ASSERT_TRUE(NULL != audio_man); |
| 308 if (!audio_man->HasAudioOutputDevices()) | 300 if (!audio_man->HasAudioOutputDevices()) |
| 309 return; | 301 return; |
| 310 AudioOutputStream* oas = audio_man->MakeAudioOutputStream( | 302 AudioOutputStream* oas = audio_man->MakeAudioOutputStream( |
| 311 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, 1, 16000, 16)); | 303 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, 1, 16000, 16, 256)); |
| 312 ASSERT_TRUE(NULL != oas); | 304 ASSERT_TRUE(NULL != oas); |
| 313 TestSourceTripleBuffer test_triple_buffer; | 305 TestSourceTripleBuffer test_triple_buffer; |
| 314 EXPECT_TRUE(oas->Open(512)); | 306 EXPECT_TRUE(oas->Open()); |
| 315 oas->Start(&test_triple_buffer); | 307 oas->Start(&test_triple_buffer); |
| 316 ::Sleep(300); | 308 ::Sleep(300); |
| 317 EXPECT_GT(test_triple_buffer.callback_count(), kNumBuffers); | 309 EXPECT_GT(test_triple_buffer.callback_count(), kNumBuffers); |
| 318 EXPECT_FALSE(test_triple_buffer.had_error()); | 310 EXPECT_FALSE(test_triple_buffer.had_error()); |
| 319 oas->Stop(); | 311 oas->Stop(); |
| 320 ::Sleep(500); | 312 ::Sleep(500); |
| 321 oas->Close(); | 313 oas->Close(); |
| 322 } | 314 } |
| 323 | 315 |
| 324 // Test potential deadlock situation if the source is slow or blocks for some | 316 // Test potential deadlock situation if the source is slow or blocks for some |
| 325 // time. The actual EXPECT_GT are mostly meaningless and the real test is that | 317 // time. The actual EXPECT_GT are mostly meaningless and the real test is that |
| 326 // the test completes in reasonable time. | 318 // the test completes in reasonable time. |
| 327 TEST(WinAudioTest, PCMWaveSlowSource) { | 319 TEST(WinAudioTest, PCMWaveSlowSource) { |
| 328 if (IsRunningHeadless()) | 320 if (IsRunningHeadless()) |
| 329 return; | 321 return; |
| 330 AudioManager* audio_man = AudioManager::GetAudioManager(); | 322 AudioManager* audio_man = AudioManager::GetAudioManager(); |
| 331 ASSERT_TRUE(NULL != audio_man); | 323 ASSERT_TRUE(NULL != audio_man); |
| 332 if (!audio_man->HasAudioOutputDevices()) | 324 if (!audio_man->HasAudioOutputDevices()) |
| 333 return; | 325 return; |
| 334 AudioOutputStream* oas = audio_man->MakeAudioOutputStream( | 326 AudioOutputStream* oas = audio_man->MakeAudioOutputStream( |
| 335 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, 1, 16000, 16)); | 327 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, 1, 16000, 16, 256)); |
| 336 ASSERT_TRUE(NULL != oas); | 328 ASSERT_TRUE(NULL != oas); |
| 337 TestSourceLaggy test_laggy(2, 90); | 329 TestSourceLaggy test_laggy(2, 90); |
| 338 EXPECT_TRUE(oas->Open(512)); | 330 EXPECT_TRUE(oas->Open()); |
| 339 // The test parameters cause a callback every 32 ms and the source is | 331 // The test parameters cause a callback every 32 ms and the source is |
| 340 // sleeping for 90 ms, so it is guaranteed that we run out of ready buffers. | 332 // sleeping for 90 ms, so it is guaranteed that we run out of ready buffers. |
| 341 oas->Start(&test_laggy); | 333 oas->Start(&test_laggy); |
| 342 ::Sleep(500); | 334 ::Sleep(500); |
| 343 EXPECT_GT(test_laggy.callback_count(), 2); | 335 EXPECT_GT(test_laggy.callback_count(), 2); |
| 344 EXPECT_FALSE(test_laggy.had_error()); | 336 EXPECT_FALSE(test_laggy.had_error()); |
| 345 oas->Stop(); | 337 oas->Stop(); |
| 346 ::Sleep(500); | 338 ::Sleep(500); |
| 347 oas->Close(); | 339 oas->Close(); |
| 348 } | 340 } |
| 349 | 341 |
| 350 // Test another potential deadlock situation if the thread that calls Start() | 342 // Test another potential deadlock situation if the thread that calls Start() |
| 351 // gets paused. This test is best when run over RDP with audio enabled. See | 343 // gets paused. This test is best when run over RDP with audio enabled. See |
| 352 // bug 19276 for more details. | 344 // bug 19276 for more details. |
| 353 TEST(WinAudioTest, PCMWaveStreamPlaySlowLoop) { | 345 TEST(WinAudioTest, PCMWaveStreamPlaySlowLoop) { |
| 354 if (IsRunningHeadless()) | 346 if (IsRunningHeadless()) |
| 355 return; | 347 return; |
| 356 AudioManager* audio_man = AudioManager::GetAudioManager(); | 348 AudioManager* audio_man = AudioManager::GetAudioManager(); |
| 357 ASSERT_TRUE(NULL != audio_man); | 349 ASSERT_TRUE(NULL != audio_man); |
| 358 if (!audio_man->HasAudioOutputDevices()) | 350 if (!audio_man->HasAudioOutputDevices()) |
| 359 return; | 351 return; |
| 352 uint32 samples_100_ms = AudioParameters::kAudioCDSampleRate / 10; |
| 360 AudioOutputStream* oas = audio_man->MakeAudioOutputStream( | 353 AudioOutputStream* oas = audio_man->MakeAudioOutputStream( |
| 361 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, 1, | 354 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, 1, |
| 362 AudioParameters::kAudioCDSampleRate, 16)); | 355 AudioParameters::kAudioCDSampleRate, 16, samples_100_ms)); |
| 363 ASSERT_TRUE(NULL != oas); | 356 ASSERT_TRUE(NULL != oas); |
| 364 | 357 |
| 365 SineWaveAudioSource source(SineWaveAudioSource::FORMAT_16BIT_LINEAR_PCM, 1, | 358 SineWaveAudioSource source(SineWaveAudioSource::FORMAT_16BIT_LINEAR_PCM, 1, |
| 366 200.0, AudioParameters::kAudioCDSampleRate); | 359 200.0, AudioParameters::kAudioCDSampleRate); |
| 367 uint32 bytes_100_ms = (AudioParameters::kAudioCDSampleRate / 10) * 2; | |
| 368 | 360 |
| 369 EXPECT_TRUE(oas->Open(bytes_100_ms)); | 361 EXPECT_TRUE(oas->Open()); |
| 370 oas->SetVolume(1.0); | 362 oas->SetVolume(1.0); |
| 371 | 363 |
| 372 for (int ix = 0; ix != 5; ++ix) { | 364 for (int ix = 0; ix != 5; ++ix) { |
| 373 oas->Start(&source); | 365 oas->Start(&source); |
| 374 ::Sleep(10); | 366 ::Sleep(10); |
| 375 oas->Stop(); | 367 oas->Stop(); |
| 376 } | 368 } |
| 377 oas->Close(); | 369 oas->Close(); |
| 378 } | 370 } |
| 379 | 371 |
| 380 | 372 |
| 381 // This test produces actual audio for .5 seconds on the default wave | 373 // This test produces actual audio for .5 seconds on the default wave |
| 382 // device at 44.1K s/sec. Parameters have been chosen carefully so you should | 374 // device at 44.1K s/sec. Parameters have been chosen carefully so you should |
| 383 // not hear pops or noises while the sound is playing. | 375 // not hear pops or noises while the sound is playing. |
| 384 TEST(WinAudioTest, PCMWaveStreamPlay200HzTone44Kss) { | 376 TEST(WinAudioTest, PCMWaveStreamPlay200HzTone44Kss) { |
| 385 if (IsRunningHeadless()) | 377 if (IsRunningHeadless()) |
| 386 return; | 378 return; |
| 387 AudioManager* audio_man = AudioManager::GetAudioManager(); | 379 AudioManager* audio_man = AudioManager::GetAudioManager(); |
| 388 ASSERT_TRUE(NULL != audio_man); | 380 ASSERT_TRUE(NULL != audio_man); |
| 389 if (!audio_man->HasAudioOutputDevices()) | 381 if (!audio_man->HasAudioOutputDevices()) |
| 390 return; | 382 return; |
| 383 uint32 samples_100_ms = AudioParameters::kAudioCDSampleRate / 10; |
| 391 AudioOutputStream* oas = audio_man->MakeAudioOutputStream( | 384 AudioOutputStream* oas = audio_man->MakeAudioOutputStream( |
| 392 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, 1, | 385 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, 1, |
| 393 AudioParameters::kAudioCDSampleRate, 16)); | 386 AudioParameters::kAudioCDSampleRate, 16, samples_100_ms)); |
| 394 ASSERT_TRUE(NULL != oas); | 387 ASSERT_TRUE(NULL != oas); |
| 395 | 388 |
| 396 SineWaveAudioSource source(SineWaveAudioSource::FORMAT_16BIT_LINEAR_PCM, 1, | 389 SineWaveAudioSource source(SineWaveAudioSource::FORMAT_16BIT_LINEAR_PCM, 1, |
| 397 200.0, AudioParameters::kAudioCDSampleRate); | 390 200.0, AudioParameters::kAudioCDSampleRate); |
| 398 uint32 bytes_100_ms = (AudioParameters::kAudioCDSampleRate / 10) * 2; | |
| 399 | 391 |
| 400 EXPECT_TRUE(oas->Open(bytes_100_ms)); | 392 EXPECT_TRUE(oas->Open()); |
| 401 oas->SetVolume(1.0); | 393 oas->SetVolume(1.0); |
| 402 oas->Start(&source); | 394 oas->Start(&source); |
| 403 ::Sleep(500); | 395 ::Sleep(500); |
| 404 oas->Stop(); | 396 oas->Stop(); |
| 405 oas->Close(); | 397 oas->Close(); |
| 406 } | 398 } |
| 407 | 399 |
| 408 // This test produces actual audio for for .5 seconds on the default wave | 400 // This test produces actual audio for for .5 seconds on the default wave |
| 409 // device at 22K s/sec. Parameters have been chosen carefully so you should | 401 // device at 22K s/sec. Parameters have been chosen carefully so you should |
| 410 // not hear pops or noises while the sound is playing. The audio also should | 402 // not hear pops or noises while the sound is playing. The audio also should |
| 411 // sound with a lower volume than PCMWaveStreamPlay200HzTone44Kss. | 403 // sound with a lower volume than PCMWaveStreamPlay200HzTone44Kss. |
| 412 TEST(WinAudioTest, PCMWaveStreamPlay200HzTone22Kss) { | 404 TEST(WinAudioTest, PCMWaveStreamPlay200HzTone22Kss) { |
| 413 if (IsRunningHeadless()) | 405 if (IsRunningHeadless()) |
| 414 return; | 406 return; |
| 415 AudioManager* audio_man = AudioManager::GetAudioManager(); | 407 AudioManager* audio_man = AudioManager::GetAudioManager(); |
| 416 ASSERT_TRUE(NULL != audio_man); | 408 ASSERT_TRUE(NULL != audio_man); |
| 417 if (!audio_man->HasAudioOutputDevices()) | 409 if (!audio_man->HasAudioOutputDevices()) |
| 418 return; | 410 return; |
| 411 uint32 samples_100_ms = AudioParameters::kAudioCDSampleRate / 20; |
| 419 AudioOutputStream* oas = audio_man->MakeAudioOutputStream( | 412 AudioOutputStream* oas = audio_man->MakeAudioOutputStream( |
| 420 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, 1, | 413 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, 1, |
| 421 AudioParameters::kAudioCDSampleRate / 2, 16)); | 414 AudioParameters::kAudioCDSampleRate / 2, 16, |
| 415 samples_100_ms)); |
| 422 ASSERT_TRUE(NULL != oas); | 416 ASSERT_TRUE(NULL != oas); |
| 423 | 417 |
| 424 SineWaveAudioSource source(SineWaveAudioSource::FORMAT_16BIT_LINEAR_PCM, 1, | 418 SineWaveAudioSource source(SineWaveAudioSource::FORMAT_16BIT_LINEAR_PCM, 1, |
| 425 200.0, AudioParameters::kAudioCDSampleRate/2); | 419 200.0, AudioParameters::kAudioCDSampleRate/2); |
| 426 uint32 bytes_100_ms = (AudioParameters::kAudioCDSampleRate / 20) * 2; | |
| 427 | 420 |
| 428 EXPECT_TRUE(oas->Open(bytes_100_ms)); | 421 EXPECT_TRUE(oas->Open()); |
| 429 | 422 |
| 430 oas->SetVolume(0.5); | 423 oas->SetVolume(0.5); |
| 431 oas->Start(&source); | 424 oas->Start(&source); |
| 432 ::Sleep(500); | 425 ::Sleep(500); |
| 433 | 426 |
| 434 // Test that the volume is within the set limits. | 427 // Test that the volume is within the set limits. |
| 435 double volume = 0.0; | 428 double volume = 0.0; |
| 436 oas->GetVolume(&volume); | 429 oas->GetVolume(&volume); |
| 437 EXPECT_LT(volume, 0.51); | 430 EXPECT_LT(volume, 0.51); |
| 438 EXPECT_GT(volume, 0.49); | 431 EXPECT_GT(volume, 0.49); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 455 ASSERT_TRUE(PathService::Get(base::DIR_SOURCE_ROOT, &audio_file)); | 448 ASSERT_TRUE(PathService::Get(base::DIR_SOURCE_ROOT, &audio_file)); |
| 456 audio_file = audio_file.Append(kAudioFile1_16b_m_16K); | 449 audio_file = audio_file.Append(kAudioFile1_16b_m_16K); |
| 457 // Map the entire file in memory. | 450 // Map the entire file in memory. |
| 458 ReadOnlyMappedFile file_reader(audio_file.value().c_str()); | 451 ReadOnlyMappedFile file_reader(audio_file.value().c_str()); |
| 459 ASSERT_TRUE(file_reader.is_valid()); | 452 ASSERT_TRUE(file_reader.is_valid()); |
| 460 | 453 |
| 461 AudioManager* audio_man = AudioManager::GetAudioManager(); | 454 AudioManager* audio_man = AudioManager::GetAudioManager(); |
| 462 ASSERT_TRUE(NULL != audio_man); | 455 ASSERT_TRUE(NULL != audio_man); |
| 463 if (!audio_man->HasAudioOutputDevices()) | 456 if (!audio_man->HasAudioOutputDevices()) |
| 464 return; | 457 return; |
| 458 |
| 459 // Compute buffer size for 100ms of audio. |
| 460 const uint32 kSamples100ms = (16000 / 1000) * 100; |
| 461 const uint32 kSize100ms = kSamples100ms * 2; |
| 462 |
| 465 AudioOutputStream* oas = audio_man->MakeAudioOutputStream( | 463 AudioOutputStream* oas = audio_man->MakeAudioOutputStream( |
| 466 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, 1, 16000, 16)); | 464 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, 1, 16000, 16, |
| 465 kSamples100ms)); |
| 467 ASSERT_TRUE(NULL != oas); | 466 ASSERT_TRUE(NULL != oas); |
| 468 | 467 |
| 469 // compute buffer size for 100ms of audio. Which is 3200 bytes. | 468 EXPECT_TRUE(oas->Open()); |
| 470 const uint32 kSize50ms = 2 * (16000 / 1000) * 100; | |
| 471 EXPECT_TRUE(oas->Open(kSize50ms)); | |
| 472 | 469 |
| 473 uint32 offset = 0; | 470 uint32 offset = 0; |
| 474 const uint32 kMaxStartOffset = file_reader.size() - kSize50ms; | 471 const uint32 kMaxStartOffset = file_reader.size() - kSize100ms; |
| 475 | 472 |
| 476 // We buffer and play at the same time, buffering happens every ~10ms and the | 473 // We buffer and play at the same time, buffering happens every ~10ms and the |
| 477 // consuming of the buffer happens every ~50ms. We do 100 buffers which | 474 // consuming of the buffer happens every ~100ms. We do 100 buffers which |
| 478 // effectively wrap around the file more than once. | 475 // effectively wrap around the file more than once. |
| 479 PushSource push_source; | 476 PushSource push_source; |
| 480 for (uint32 ix = 0; ix != 100; ++ix) { | 477 for (uint32 ix = 0; ix != 100; ++ix) { |
| 481 push_source.Write(file_reader.GetChunkAt(offset), kSize50ms); | 478 push_source.Write(file_reader.GetChunkAt(offset), kSize100ms); |
| 482 if (ix == 2) { | 479 if (ix == 2) { |
| 483 // For glitch free, start playing after some buffers are in. | 480 // For glitch free, start playing after some buffers are in. |
| 484 oas->Start(&push_source); | 481 oas->Start(&push_source); |
| 485 } | 482 } |
| 486 ::Sleep(10); | 483 ::Sleep(10); |
| 487 offset += kSize50ms; | 484 offset += kSize100ms; |
| 488 if (offset > kMaxStartOffset) | 485 if (offset > kMaxStartOffset) |
| 489 offset = 0; | 486 offset = 0; |
| 490 } | 487 } |
| 491 | 488 |
| 492 // Play a little bit more of the file. | 489 // Play a little bit more of the file. |
| 493 ::Sleep(500); | 490 ::Sleep(500); |
| 494 | 491 |
| 495 oas->Stop(); | 492 oas->Stop(); |
| 496 oas->Close(); | 493 oas->Close(); |
| 497 } | 494 } |
| 498 | 495 |
| 499 // This test is to make sure an AudioOutputStream can be started after it was | 496 // This test is to make sure an AudioOutputStream can be started after it was |
| 500 // stopped. You will here two .5 seconds wave signal separated by 0.5 seconds | 497 // stopped. You will here two .5 seconds wave signal separated by 0.5 seconds |
| 501 // of silence. | 498 // of silence. |
| 502 TEST(WinAudioTest, PCMWaveStreamPlayTwice200HzTone44Kss) { | 499 TEST(WinAudioTest, PCMWaveStreamPlayTwice200HzTone44Kss) { |
| 503 if (IsRunningHeadless()) | 500 if (IsRunningHeadless()) |
| 504 return; | 501 return; |
| 505 AudioManager* audio_man = AudioManager::GetAudioManager(); | 502 AudioManager* audio_man = AudioManager::GetAudioManager(); |
| 506 ASSERT_TRUE(NULL != audio_man); | 503 ASSERT_TRUE(NULL != audio_man); |
| 507 if (!audio_man->HasAudioOutputDevices()) | 504 if (!audio_man->HasAudioOutputDevices()) |
| 508 return; | 505 return; |
| 506 |
| 507 uint32 samples_100_ms = AudioParameters::kAudioCDSampleRate / 10; |
| 509 AudioOutputStream* oas = audio_man->MakeAudioOutputStream( | 508 AudioOutputStream* oas = audio_man->MakeAudioOutputStream( |
| 510 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, 1, | 509 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, 1, |
| 511 AudioParameters::kAudioCDSampleRate, 16)); | 510 AudioParameters::kAudioCDSampleRate, 16, samples_100_ms)); |
| 512 ASSERT_TRUE(NULL != oas); | 511 ASSERT_TRUE(NULL != oas); |
| 513 | 512 |
| 514 SineWaveAudioSource source(SineWaveAudioSource::FORMAT_16BIT_LINEAR_PCM, 1, | 513 SineWaveAudioSource source(SineWaveAudioSource::FORMAT_16BIT_LINEAR_PCM, 1, |
| 515 200.0, AudioParameters::kAudioCDSampleRate); | 514 200.0, AudioParameters::kAudioCDSampleRate); |
| 516 uint32 bytes_100_ms = (AudioParameters::kAudioCDSampleRate / 10) * 2; | 515 EXPECT_TRUE(oas->Open()); |
| 517 | |
| 518 EXPECT_TRUE(oas->Open(bytes_100_ms)); | |
| 519 oas->SetVolume(1.0); | 516 oas->SetVolume(1.0); |
| 520 | 517 |
| 521 // Play the wave for .5 seconds. | 518 // Play the wave for .5 seconds. |
| 522 oas->Start(&source); | 519 oas->Start(&source); |
| 523 ::Sleep(500); | 520 ::Sleep(500); |
| 524 oas->Stop(); | 521 oas->Stop(); |
| 525 | 522 |
| 526 // Sleep to give silence after stopping the AudioOutputStream. | 523 // Sleep to give silence after stopping the AudioOutputStream. |
| 527 ::Sleep(250); | 524 ::Sleep(250); |
| 528 | 525 |
| 529 // Start again and play for .5 seconds. | 526 // Start again and play for .5 seconds. |
| 530 oas->Start(&source); | 527 oas->Start(&source); |
| 531 ::Sleep(500); | 528 ::Sleep(500); |
| 532 oas->Stop(); | 529 oas->Stop(); |
| 533 | 530 |
| 534 oas->Close(); | 531 oas->Close(); |
| 535 } | 532 } |
| 536 | 533 |
| 537 // With the low latency mode, we have two buffers instead of 3 and we | 534 // With the low latency mode, we have two buffers instead of 3 and we |
| 538 // should be able to handle 20ms buffers at 44KHz. See also the SyncSocketBasic | 535 // should be able to handle 20ms buffers at 44KHz. See also the SyncSocketBasic |
| 539 // test below. | 536 // test below. |
| 540 // TODO(cpu): right now the best we can do is 50ms before it sounds choppy. | 537 // TODO(cpu): right now the best we can do is 50ms before it sounds choppy. |
| 541 TEST(WinAudioTest, PCMWaveStreamPlay200HzTone44KssLowLatency) { | 538 TEST(WinAudioTest, PCMWaveStreamPlay200HzTone44KssLowLatency) { |
| 542 if (IsRunningHeadless()) | 539 if (IsRunningHeadless()) |
| 543 return; | 540 return; |
| 544 AudioManager* audio_man = AudioManager::GetAudioManager(); | 541 AudioManager* audio_man = AudioManager::GetAudioManager(); |
| 545 ASSERT_TRUE(NULL != audio_man); | 542 ASSERT_TRUE(NULL != audio_man); |
| 546 if (!audio_man->HasAudioOutputDevices()) | 543 if (!audio_man->HasAudioOutputDevices()) |
| 547 return; | 544 return; |
| 545 |
| 546 uint32 samples_50_ms = AudioParameters::kAudioCDSampleRate / 20; |
| 548 AudioOutputStream* oas = audio_man->MakeAudioOutputStream( | 547 AudioOutputStream* oas = audio_man->MakeAudioOutputStream( |
| 549 AudioParameters(AudioParameters::AUDIO_PCM_LOW_LATENCY, 1, | 548 AudioParameters(AudioParameters::AUDIO_PCM_LOW_LATENCY, 1, |
| 550 AudioParameters::kAudioCDSampleRate, 16)); | 549 AudioParameters::kAudioCDSampleRate, 16, samples_50_ms)); |
| 551 ASSERT_TRUE(NULL != oas); | 550 ASSERT_TRUE(NULL != oas); |
| 552 | 551 |
| 553 SineWaveAudioSource source(SineWaveAudioSource::FORMAT_16BIT_LINEAR_PCM, 1, | 552 SineWaveAudioSource source(SineWaveAudioSource::FORMAT_16BIT_LINEAR_PCM, 1, |
| 554 200.0, AudioParameters::kAudioCDSampleRate); | 553 200.0, AudioParameters::kAudioCDSampleRate); |
| 555 uint32 bytes_50_ms = (AudioParameters::kAudioCDSampleRate / 20) * | |
| 556 sizeof(uint16); | |
| 557 | 554 |
| 558 EXPECT_TRUE(oas->Open(bytes_50_ms)); | 555 EXPECT_TRUE(oas->Open()); |
| 559 oas->SetVolume(1.0); | 556 oas->SetVolume(1.0); |
| 560 | 557 |
| 561 // Play the wave for .8 seconds. | 558 // Play the wave for .8 seconds. |
| 562 oas->Start(&source); | 559 oas->Start(&source); |
| 563 ::Sleep(800); | 560 ::Sleep(800); |
| 564 oas->Stop(); | 561 oas->Stop(); |
| 565 oas->Close(); | 562 oas->Close(); |
| 566 } | 563 } |
| 567 | 564 |
| 568 // Check that the pending bytes value is correct what the stream starts. | 565 // Check that the pending bytes value is correct what the stream starts. |
| 569 TEST(WinAudioTest, PCMWaveStreamPendingBytes) { | 566 TEST(WinAudioTest, PCMWaveStreamPendingBytes) { |
| 570 if (IsRunningHeadless()) | 567 if (IsRunningHeadless()) |
| 571 return; | 568 return; |
| 572 AudioManager* audio_man = AudioManager::GetAudioManager(); | 569 AudioManager* audio_man = AudioManager::GetAudioManager(); |
| 573 ASSERT_TRUE(NULL != audio_man); | 570 ASSERT_TRUE(NULL != audio_man); |
| 574 if (!audio_man->HasAudioOutputDevices()) | 571 if (!audio_man->HasAudioOutputDevices()) |
| 575 return; | 572 return; |
| 573 |
| 574 uint32 samples_100_ms = AudioParameters::kAudioCDSampleRate / 10; |
| 576 AudioOutputStream* oas = audio_man->MakeAudioOutputStream( | 575 AudioOutputStream* oas = audio_man->MakeAudioOutputStream( |
| 577 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, 1, | 576 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, 1, |
| 578 AudioParameters::kAudioCDSampleRate, 16)); | 577 AudioParameters::kAudioCDSampleRate, 16, samples_100_ms)); |
| 579 ASSERT_TRUE(NULL != oas); | 578 ASSERT_TRUE(NULL != oas); |
| 580 | 579 |
| 581 NiceMock<MockAudioSource> source; | 580 NiceMock<MockAudioSource> source; |
| 582 uint32 bytes_100_ms = (AudioParameters::kAudioCDSampleRate / 10) * 2; | 581 EXPECT_TRUE(oas->Open()); |
| 583 EXPECT_TRUE(oas->Open(bytes_100_ms)); | 582 |
| 583 uint32 bytes_100_ms = samples_100_ms * 2; |
| 584 | 584 |
| 585 // We expect the amount of pending bytes will reaching 2 times of | 585 // We expect the amount of pending bytes will reaching 2 times of |
| 586 // |bytes_100_ms| because the audio output stream has a triple buffer scheme. | 586 // |bytes_100_ms| because the audio output stream has a triple buffer scheme. |
| 587 // And then we will try to provide zero data so the amount of pending bytes | 587 // And then we will try to provide zero data so the amount of pending bytes |
| 588 // will go down and eventually read zero. | 588 // will go down and eventually read zero. |
| 589 InSequence s; | 589 InSequence s; |
| 590 EXPECT_CALL(source, OnMoreData(oas, NotNull(), bytes_100_ms, | 590 EXPECT_CALL(source, OnMoreData(oas, NotNull(), bytes_100_ms, |
| 591 Field(&AudioBuffersState::pending_bytes, 0))) | 591 Field(&AudioBuffersState::pending_bytes, 0))) |
| 592 .WillOnce(Return(bytes_100_ms)); | 592 .WillOnce(Return(bytes_100_ms)); |
| 593 EXPECT_CALL(source, OnMoreData(oas, NotNull(), bytes_100_ms, | 593 EXPECT_CALL(source, OnMoreData(oas, NotNull(), bytes_100_ms, |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 630 } | 630 } |
| 631 | 631 |
| 632 // AudioSourceCallback::OnMoreData implementation: | 632 // AudioSourceCallback::OnMoreData implementation: |
| 633 virtual uint32 OnMoreData(AudioOutputStream* stream, | 633 virtual uint32 OnMoreData(AudioOutputStream* stream, |
| 634 uint8* dest, uint32 max_size, | 634 uint8* dest, uint32 max_size, |
| 635 AudioBuffersState buffers_state) { | 635 AudioBuffersState buffers_state) { |
| 636 socket_->Send(&buffers_state, sizeof(buffers_state)); | 636 socket_->Send(&buffers_state, sizeof(buffers_state)); |
| 637 uint32 got = socket_->Receive(dest, max_size); | 637 uint32 got = socket_->Receive(dest, max_size); |
| 638 return got; | 638 return got; |
| 639 } | 639 } |
| 640 // AudioSourceCallback::OnClose implementation: | |
| 641 virtual void OnClose(AudioOutputStream* stream) { | |
| 642 } | |
| 643 // AudioSourceCallback::OnError implementation: | 640 // AudioSourceCallback::OnError implementation: |
| 644 virtual void OnError(AudioOutputStream* stream, int code) { | 641 virtual void OnError(AudioOutputStream* stream, int code) { |
| 645 } | 642 } |
| 646 | 643 |
| 647 private: | 644 private: |
| 648 base::SyncSocket* socket_; | 645 base::SyncSocket* socket_; |
| 649 }; | 646 }; |
| 650 | 647 |
| 651 struct SyncThreadContext { | 648 struct SyncThreadContext { |
| 652 base::SyncSocket* socket; | 649 base::SyncSocket* socket; |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 696 TEST(WinAudioTest, SyncSocketBasic) { | 693 TEST(WinAudioTest, SyncSocketBasic) { |
| 697 if (IsRunningHeadless()) | 694 if (IsRunningHeadless()) |
| 698 return; | 695 return; |
| 699 | 696 |
| 700 AudioManager* audio_man = AudioManager::GetAudioManager(); | 697 AudioManager* audio_man = AudioManager::GetAudioManager(); |
| 701 ASSERT_TRUE(NULL != audio_man); | 698 ASSERT_TRUE(NULL != audio_man); |
| 702 if (!audio_man->HasAudioOutputDevices()) | 699 if (!audio_man->HasAudioOutputDevices()) |
| 703 return; | 700 return; |
| 704 | 701 |
| 705 int sample_rate = AudioParameters::kAudioCDSampleRate; | 702 int sample_rate = AudioParameters::kAudioCDSampleRate; |
| 703 const uint32 kSamples20ms = sample_rate / 50; |
| 706 AudioOutputStream* oas = audio_man->MakeAudioOutputStream( | 704 AudioOutputStream* oas = audio_man->MakeAudioOutputStream( |
| 707 AudioParameters(AudioParameters::AUDIO_PCM_LOW_LATENCY, 1, | 705 AudioParameters(AudioParameters::AUDIO_PCM_LOW_LATENCY, 1, |
| 708 sample_rate, 16)); | 706 sample_rate, 16, kSamples20ms)); |
| 709 ASSERT_TRUE(NULL != oas); | 707 ASSERT_TRUE(NULL != oas); |
| 710 | 708 |
| 711 // compute buffer size for 20ms of audio, 882 samples (mono). | 709 // compute buffer size for 20ms of audio, 882 samples (mono). |
| 712 const uint32 kSamples20ms = sample_rate / 50 * sizeof(uint16); | 710 ASSERT_TRUE(oas->Open()); |
| 713 ASSERT_TRUE(oas->Open(kSamples20ms)); | |
| 714 | 711 |
| 715 base::SyncSocket* sockets[2]; | 712 base::SyncSocket* sockets[2]; |
| 716 ASSERT_TRUE(base::SyncSocket::CreatePair(sockets)); | 713 ASSERT_TRUE(base::SyncSocket::CreatePair(sockets)); |
| 717 | 714 |
| 718 SyncSocketSource source(sockets[0]); | 715 SyncSocketSource source(sockets[0]); |
| 719 | 716 |
| 720 SyncThreadContext thread_context; | 717 SyncThreadContext thread_context; |
| 721 thread_context.sample_rate = sample_rate; | 718 thread_context.sample_rate = sample_rate; |
| 722 thread_context.sine_freq = 200.0; | 719 thread_context.sine_freq = 200.0; |
| 723 thread_context.packet_size = kSamples20ms; | 720 thread_context.packet_size = kSamples20ms; |
| 724 thread_context.socket = sockets[1]; | 721 thread_context.socket = sockets[1]; |
| 725 | 722 |
| 726 HANDLE thread = ::CreateThread(NULL, 0, SyncSocketThread, | 723 HANDLE thread = ::CreateThread(NULL, 0, SyncSocketThread, |
| 727 &thread_context, 0, NULL); | 724 &thread_context, 0, NULL); |
| 728 | 725 |
| 729 oas->Start(&source); | 726 oas->Start(&source); |
| 730 | 727 |
| 731 ::WaitForSingleObject(thread, INFINITE); | 728 ::WaitForSingleObject(thread, INFINITE); |
| 732 ::CloseHandle(thread); | 729 ::CloseHandle(thread); |
| 733 delete sockets[1]; | 730 delete sockets[1]; |
| 734 | 731 |
| 735 oas->Stop(); | 732 oas->Stop(); |
| 736 oas->Close(); | 733 oas->Close(); |
| 737 } | 734 } |
| OLD | NEW |