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 <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 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
192 | 192 |
193 private: | 193 private: |
194 HANDLE fmap_; | 194 HANDLE fmap_; |
195 char* start_; | 195 char* start_; |
196 uint32 size_; | 196 uint32 size_; |
197 }; | 197 }; |
198 | 198 |
199 // ============================================================================ | 199 // ============================================================================ |
200 // Validate that the AudioManager::AUDIO_MOCK callbacks work. | 200 // Validate that the AudioManager::AUDIO_MOCK callbacks work. |
201 TEST(WinAudioTest, MockStreamBasicCallbacks) { | 201 TEST(WinAudioTest, MockStreamBasicCallbacks) { |
202 AudioManager* audio_man = AudioManager::GetAudioManager(); | 202 scoped_refptr<AudioManager> audio_man(AudioManager::Create()); |
203 ASSERT_TRUE(NULL != audio_man); | |
204 AudioOutputStream* oas = audio_man->MakeAudioOutputStream( | 203 AudioOutputStream* oas = audio_man->MakeAudioOutputStream( |
205 AudioParameters(AudioParameters::AUDIO_MOCK, CHANNEL_LAYOUT_STEREO, 8000, | 204 AudioParameters(AudioParameters::AUDIO_MOCK, CHANNEL_LAYOUT_STEREO, 8000, |
206 8, 128)); | 205 8, 128)); |
207 ASSERT_TRUE(NULL != oas); | 206 ASSERT_TRUE(NULL != oas); |
208 EXPECT_TRUE(oas->Open()); | 207 EXPECT_TRUE(oas->Open()); |
209 TestSourceBasic source; | 208 TestSourceBasic source; |
210 oas->Start(&source); | 209 oas->Start(&source); |
211 EXPECT_GT(source.callback_count(), 0); | 210 EXPECT_GT(source.callback_count(), 0); |
212 oas->Stop(); | 211 oas->Stop(); |
213 oas->Close(); | 212 oas->Close(); |
214 EXPECT_EQ(0, source.had_error()); | 213 EXPECT_EQ(0, source.had_error()); |
215 } | 214 } |
216 | 215 |
217 // =========================================================================== | 216 // =========================================================================== |
218 // Validation of AudioManager::AUDIO_PCM_LINEAR | 217 // Validation of AudioManager::AUDIO_PCM_LINEAR |
219 // | 218 // |
220 // The tests tend to fail in the build bots when somebody connects to them via | 219 // The tests tend to fail in the build bots when somebody connects to them via |
221 // via remote-desktop because it installs an audio device that fails to open | 220 // via remote-desktop because it installs an audio device that fails to open |
222 // at some point, possibly when the connection goes idle. So that is why we | 221 // at some point, possibly when the connection goes idle. So that is why we |
223 // skipped them in headless mode. | 222 // skipped them in headless mode. |
224 | 223 |
225 // Test that can it be created and closed. | 224 // Test that can it be created and closed. |
226 TEST(WinAudioTest, PCMWaveStreamGetAndClose) { | 225 TEST(WinAudioTest, PCMWaveStreamGetAndClose) { |
227 if (IsRunningHeadless()) | 226 if (IsRunningHeadless()) |
228 return; | 227 return; |
229 AudioManager* audio_man = AudioManager::GetAudioManager(); | 228 scoped_refptr<AudioManager> audio_man(AudioManager::Create()); |
230 ASSERT_TRUE(NULL != audio_man); | |
231 if (!audio_man->HasAudioOutputDevices()) | 229 if (!audio_man->HasAudioOutputDevices()) |
232 return; | 230 return; |
233 AudioOutputStream* oas = audio_man->MakeAudioOutputStream( | 231 AudioOutputStream* oas = audio_man->MakeAudioOutputStream( |
234 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_STEREO, | 232 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_STEREO, |
235 8000, 16, 256)); | 233 8000, 16, 256)); |
236 ASSERT_TRUE(NULL != oas); | 234 ASSERT_TRUE(NULL != oas); |
237 oas->Close(); | 235 oas->Close(); |
238 } | 236 } |
239 | 237 |
240 // Test that can it be cannot be created with invalid parameters. | 238 // Test that can it be cannot be created with invalid parameters. |
241 TEST(WinAudioTest, SanityOnMakeParams) { | 239 TEST(WinAudioTest, SanityOnMakeParams) { |
242 if (IsRunningHeadless()) | 240 if (IsRunningHeadless()) |
243 return; | 241 return; |
244 AudioManager* audio_man = AudioManager::GetAudioManager(); | 242 scoped_refptr<AudioManager> audio_man(AudioManager::Create()); |
245 ASSERT_TRUE(NULL != audio_man); | |
246 if (!audio_man->HasAudioOutputDevices()) | 243 if (!audio_man->HasAudioOutputDevices()) |
247 return; | 244 return; |
248 AudioParameters::Format fmt = AudioParameters::AUDIO_PCM_LINEAR; | 245 AudioParameters::Format fmt = AudioParameters::AUDIO_PCM_LINEAR; |
249 EXPECT_TRUE(NULL == audio_man->MakeAudioOutputStream( | 246 EXPECT_TRUE(NULL == audio_man->MakeAudioOutputStream( |
250 AudioParameters(fmt, CHANNEL_LAYOUT_UNSUPPORTED, 8000, 16, 256))); | 247 AudioParameters(fmt, CHANNEL_LAYOUT_UNSUPPORTED, 8000, 16, 256))); |
251 EXPECT_TRUE(NULL == audio_man->MakeAudioOutputStream( | 248 EXPECT_TRUE(NULL == audio_man->MakeAudioOutputStream( |
252 AudioParameters(fmt, CHANNEL_LAYOUT_MONO, 1024 * 1024, 16, 256))); | 249 AudioParameters(fmt, CHANNEL_LAYOUT_MONO, 1024 * 1024, 16, 256))); |
253 EXPECT_TRUE(NULL == audio_man->MakeAudioOutputStream( | 250 EXPECT_TRUE(NULL == audio_man->MakeAudioOutputStream( |
254 AudioParameters(fmt, CHANNEL_LAYOUT_STEREO, 8000, 80, 256))); | 251 AudioParameters(fmt, CHANNEL_LAYOUT_STEREO, 8000, 80, 256))); |
255 EXPECT_TRUE(NULL == audio_man->MakeAudioOutputStream( | 252 EXPECT_TRUE(NULL == audio_man->MakeAudioOutputStream( |
256 AudioParameters(fmt, CHANNEL_LAYOUT_UNSUPPORTED, 8000, 16, 256))); | 253 AudioParameters(fmt, CHANNEL_LAYOUT_UNSUPPORTED, 8000, 16, 256))); |
257 EXPECT_TRUE(NULL == audio_man->MakeAudioOutputStream( | 254 EXPECT_TRUE(NULL == audio_man->MakeAudioOutputStream( |
258 AudioParameters(fmt, CHANNEL_LAYOUT_STEREO, -8000, 16, 256))); | 255 AudioParameters(fmt, CHANNEL_LAYOUT_STEREO, -8000, 16, 256))); |
259 EXPECT_TRUE(NULL == audio_man->MakeAudioOutputStream( | 256 EXPECT_TRUE(NULL == audio_man->MakeAudioOutputStream( |
260 AudioParameters(fmt, CHANNEL_LAYOUT_MONO, 8000, 16, -100))); | 257 AudioParameters(fmt, CHANNEL_LAYOUT_MONO, 8000, 16, -100))); |
261 EXPECT_TRUE(NULL == audio_man->MakeAudioOutputStream( | 258 EXPECT_TRUE(NULL == audio_man->MakeAudioOutputStream( |
262 AudioParameters(fmt, CHANNEL_LAYOUT_MONO, 8000, 16, 0))); | 259 AudioParameters(fmt, CHANNEL_LAYOUT_MONO, 8000, 16, 0))); |
263 EXPECT_TRUE(NULL == audio_man->MakeAudioOutputStream( | 260 EXPECT_TRUE(NULL == audio_man->MakeAudioOutputStream( |
264 AudioParameters(fmt, CHANNEL_LAYOUT_MONO, 8000, 16, | 261 AudioParameters(fmt, CHANNEL_LAYOUT_MONO, 8000, 16, |
265 media::Limits::kMaxSamplesPerPacket + 1))); | 262 media::Limits::kMaxSamplesPerPacket + 1))); |
266 } | 263 } |
267 | 264 |
268 // Test that it can be opened and closed. | 265 // Test that it can be opened and closed. |
269 TEST(WinAudioTest, PCMWaveStreamOpenAndClose) { | 266 TEST(WinAudioTest, PCMWaveStreamOpenAndClose) { |
270 if (IsRunningHeadless()) | 267 if (IsRunningHeadless()) |
271 return; | 268 return; |
272 AudioManager* audio_man = AudioManager::GetAudioManager(); | 269 scoped_refptr<AudioManager> audio_man(AudioManager::Create()); |
273 ASSERT_TRUE(NULL != audio_man); | |
274 if (!audio_man->HasAudioOutputDevices()) | 270 if (!audio_man->HasAudioOutputDevices()) |
275 return; | 271 return; |
276 AudioOutputStream* oas = audio_man->MakeAudioOutputStream( | 272 AudioOutputStream* oas = audio_man->MakeAudioOutputStream( |
277 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_STEREO, | 273 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_STEREO, |
278 8000, 16, 256)); | 274 8000, 16, 256)); |
279 ASSERT_TRUE(NULL != oas); | 275 ASSERT_TRUE(NULL != oas); |
280 EXPECT_TRUE(oas->Open()); | 276 EXPECT_TRUE(oas->Open()); |
281 oas->Close(); | 277 oas->Close(); |
282 } | 278 } |
283 | 279 |
284 // Test that it has a maximum packet size. | 280 // Test that it has a maximum packet size. |
285 TEST(WinAudioTest, PCMWaveStreamOpenLimit) { | 281 TEST(WinAudioTest, PCMWaveStreamOpenLimit) { |
286 if (IsRunningHeadless()) | 282 if (IsRunningHeadless()) |
287 return; | 283 return; |
288 AudioManager* audio_man = AudioManager::GetAudioManager(); | 284 scoped_refptr<AudioManager> audio_man(AudioManager::Create()); |
289 ASSERT_TRUE(NULL != audio_man); | |
290 if (!audio_man->HasAudioOutputDevices()) | 285 if (!audio_man->HasAudioOutputDevices()) |
291 return; | 286 return; |
292 AudioOutputStream* oas = audio_man->MakeAudioOutputStream( | 287 AudioOutputStream* oas = audio_man->MakeAudioOutputStream( |
293 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_STEREO, | 288 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_STEREO, |
294 8000, 16, 1024 * 1024 * 1024)); | 289 8000, 16, 1024 * 1024 * 1024)); |
295 EXPECT_TRUE(NULL == oas); | 290 EXPECT_TRUE(NULL == oas); |
296 if (oas) | 291 if (oas) |
297 oas->Close(); | 292 oas->Close(); |
298 } | 293 } |
299 | 294 |
300 // Test that it uses the triple buffers correctly. Because it uses the actual | 295 // Test that it uses the triple buffers correctly. Because it uses the actual |
301 // audio device, you might hear a short pop noise for a short time. | 296 // audio device, you might hear a short pop noise for a short time. |
302 TEST(WinAudioTest, PCMWaveStreamTripleBuffer) { | 297 TEST(WinAudioTest, PCMWaveStreamTripleBuffer) { |
303 if (IsRunningHeadless()) | 298 if (IsRunningHeadless()) |
304 return; | 299 return; |
305 AudioManager* audio_man = AudioManager::GetAudioManager(); | 300 scoped_refptr<AudioManager> audio_man(AudioManager::Create()); |
306 ASSERT_TRUE(NULL != audio_man); | |
307 if (!audio_man->HasAudioOutputDevices()) | 301 if (!audio_man->HasAudioOutputDevices()) |
308 return; | 302 return; |
309 AudioOutputStream* oas = audio_man->MakeAudioOutputStream( | 303 AudioOutputStream* oas = audio_man->MakeAudioOutputStream( |
310 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_MONO, | 304 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_MONO, |
311 16000, 16, 256)); | 305 16000, 16, 256)); |
312 ASSERT_TRUE(NULL != oas); | 306 ASSERT_TRUE(NULL != oas); |
313 TestSourceTripleBuffer test_triple_buffer; | 307 TestSourceTripleBuffer test_triple_buffer; |
314 EXPECT_TRUE(oas->Open()); | 308 EXPECT_TRUE(oas->Open()); |
315 oas->Start(&test_triple_buffer); | 309 oas->Start(&test_triple_buffer); |
316 ::Sleep(300); | 310 ::Sleep(300); |
317 EXPECT_GT(test_triple_buffer.callback_count(), kNumBuffers); | 311 EXPECT_GT(test_triple_buffer.callback_count(), kNumBuffers); |
318 EXPECT_FALSE(test_triple_buffer.had_error()); | 312 EXPECT_FALSE(test_triple_buffer.had_error()); |
319 oas->Stop(); | 313 oas->Stop(); |
320 ::Sleep(500); | 314 ::Sleep(500); |
321 oas->Close(); | 315 oas->Close(); |
322 } | 316 } |
323 | 317 |
324 // Test potential deadlock situation if the source is slow or blocks for some | 318 // 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 | 319 // time. The actual EXPECT_GT are mostly meaningless and the real test is that |
326 // the test completes in reasonable time. | 320 // the test completes in reasonable time. |
327 TEST(WinAudioTest, PCMWaveSlowSource) { | 321 TEST(WinAudioTest, PCMWaveSlowSource) { |
328 if (IsRunningHeadless()) | 322 if (IsRunningHeadless()) |
329 return; | 323 return; |
330 AudioManager* audio_man = AudioManager::GetAudioManager(); | 324 scoped_refptr<AudioManager> audio_man(AudioManager::Create()); |
331 ASSERT_TRUE(NULL != audio_man); | |
332 if (!audio_man->HasAudioOutputDevices()) | 325 if (!audio_man->HasAudioOutputDevices()) |
333 return; | 326 return; |
334 AudioOutputStream* oas = audio_man->MakeAudioOutputStream( | 327 AudioOutputStream* oas = audio_man->MakeAudioOutputStream( |
335 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_MONO, | 328 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_MONO, |
336 16000, 16, 256)); | 329 16000, 16, 256)); |
337 ASSERT_TRUE(NULL != oas); | 330 ASSERT_TRUE(NULL != oas); |
338 TestSourceLaggy test_laggy(2, 90); | 331 TestSourceLaggy test_laggy(2, 90); |
339 EXPECT_TRUE(oas->Open()); | 332 EXPECT_TRUE(oas->Open()); |
340 // The test parameters cause a callback every 32 ms and the source is | 333 // The test parameters cause a callback every 32 ms and the source is |
341 // sleeping for 90 ms, so it is guaranteed that we run out of ready buffers. | 334 // sleeping for 90 ms, so it is guaranteed that we run out of ready buffers. |
342 oas->Start(&test_laggy); | 335 oas->Start(&test_laggy); |
343 ::Sleep(500); | 336 ::Sleep(500); |
344 EXPECT_GT(test_laggy.callback_count(), 2); | 337 EXPECT_GT(test_laggy.callback_count(), 2); |
345 EXPECT_FALSE(test_laggy.had_error()); | 338 EXPECT_FALSE(test_laggy.had_error()); |
346 oas->Stop(); | 339 oas->Stop(); |
347 ::Sleep(500); | 340 ::Sleep(500); |
348 oas->Close(); | 341 oas->Close(); |
349 } | 342 } |
350 | 343 |
351 // Test another potential deadlock situation if the thread that calls Start() | 344 // Test another potential deadlock situation if the thread that calls Start() |
352 // gets paused. This test is best when run over RDP with audio enabled. See | 345 // gets paused. This test is best when run over RDP with audio enabled. See |
353 // bug 19276 for more details. | 346 // bug 19276 for more details. |
354 TEST(WinAudioTest, PCMWaveStreamPlaySlowLoop) { | 347 TEST(WinAudioTest, PCMWaveStreamPlaySlowLoop) { |
355 if (IsRunningHeadless()) | 348 if (IsRunningHeadless()) |
356 return; | 349 return; |
357 AudioManager* audio_man = AudioManager::GetAudioManager(); | 350 scoped_refptr<AudioManager> audio_man(AudioManager::Create()); |
358 ASSERT_TRUE(NULL != audio_man); | |
359 if (!audio_man->HasAudioOutputDevices()) | 351 if (!audio_man->HasAudioOutputDevices()) |
360 return; | 352 return; |
361 uint32 samples_100_ms = AudioParameters::kAudioCDSampleRate / 10; | 353 uint32 samples_100_ms = AudioParameters::kAudioCDSampleRate / 10; |
362 AudioOutputStream* oas = audio_man->MakeAudioOutputStream( | 354 AudioOutputStream* oas = audio_man->MakeAudioOutputStream( |
363 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_MONO, | 355 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_MONO, |
364 AudioParameters::kAudioCDSampleRate, 16, samples_100_ms)); | 356 AudioParameters::kAudioCDSampleRate, 16, samples_100_ms)); |
365 ASSERT_TRUE(NULL != oas); | 357 ASSERT_TRUE(NULL != oas); |
366 | 358 |
367 SineWaveAudioSource source(SineWaveAudioSource::FORMAT_16BIT_LINEAR_PCM, 1, | 359 SineWaveAudioSource source(SineWaveAudioSource::FORMAT_16BIT_LINEAR_PCM, 1, |
368 200.0, AudioParameters::kAudioCDSampleRate); | 360 200.0, AudioParameters::kAudioCDSampleRate); |
369 | 361 |
370 EXPECT_TRUE(oas->Open()); | 362 EXPECT_TRUE(oas->Open()); |
371 oas->SetVolume(1.0); | 363 oas->SetVolume(1.0); |
372 | 364 |
373 for (int ix = 0; ix != 5; ++ix) { | 365 for (int ix = 0; ix != 5; ++ix) { |
374 oas->Start(&source); | 366 oas->Start(&source); |
375 ::Sleep(10); | 367 ::Sleep(10); |
376 oas->Stop(); | 368 oas->Stop(); |
377 } | 369 } |
378 oas->Close(); | 370 oas->Close(); |
379 } | 371 } |
380 | 372 |
381 | 373 |
382 // This test produces actual audio for .5 seconds on the default wave | 374 // This test produces actual audio for .5 seconds on the default wave |
383 // device at 44.1K s/sec. Parameters have been chosen carefully so you should | 375 // device at 44.1K s/sec. Parameters have been chosen carefully so you should |
384 // not hear pops or noises while the sound is playing. | 376 // not hear pops or noises while the sound is playing. |
385 TEST(WinAudioTest, PCMWaveStreamPlay200HzTone44Kss) { | 377 TEST(WinAudioTest, PCMWaveStreamPlay200HzTone44Kss) { |
386 if (IsRunningHeadless()) | 378 if (IsRunningHeadless()) |
387 return; | 379 return; |
388 AudioManager* audio_man = AudioManager::GetAudioManager(); | 380 scoped_refptr<AudioManager> audio_man(AudioManager::Create()); |
389 ASSERT_TRUE(NULL != audio_man); | |
390 if (!audio_man->HasAudioOutputDevices()) | 381 if (!audio_man->HasAudioOutputDevices()) |
391 return; | 382 return; |
392 uint32 samples_100_ms = AudioParameters::kAudioCDSampleRate / 10; | 383 uint32 samples_100_ms = AudioParameters::kAudioCDSampleRate / 10; |
393 AudioOutputStream* oas = audio_man->MakeAudioOutputStream( | 384 AudioOutputStream* oas = audio_man->MakeAudioOutputStream( |
394 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_MONO, | 385 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_MONO, |
395 AudioParameters::kAudioCDSampleRate, 16, samples_100_ms)); | 386 AudioParameters::kAudioCDSampleRate, 16, samples_100_ms)); |
396 ASSERT_TRUE(NULL != oas); | 387 ASSERT_TRUE(NULL != oas); |
397 | 388 |
398 SineWaveAudioSource source(SineWaveAudioSource::FORMAT_16BIT_LINEAR_PCM, 1, | 389 SineWaveAudioSource source(SineWaveAudioSource::FORMAT_16BIT_LINEAR_PCM, 1, |
399 200.0, AudioParameters::kAudioCDSampleRate); | 390 200.0, AudioParameters::kAudioCDSampleRate); |
400 | 391 |
401 EXPECT_TRUE(oas->Open()); | 392 EXPECT_TRUE(oas->Open()); |
402 oas->SetVolume(1.0); | 393 oas->SetVolume(1.0); |
403 oas->Start(&source); | 394 oas->Start(&source); |
404 ::Sleep(500); | 395 ::Sleep(500); |
405 oas->Stop(); | 396 oas->Stop(); |
406 oas->Close(); | 397 oas->Close(); |
407 } | 398 } |
408 | 399 |
409 // 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 |
410 // 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 |
411 // 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 |
412 // sound with a lower volume than PCMWaveStreamPlay200HzTone44Kss. | 403 // sound with a lower volume than PCMWaveStreamPlay200HzTone44Kss. |
413 TEST(WinAudioTest, PCMWaveStreamPlay200HzTone22Kss) { | 404 TEST(WinAudioTest, PCMWaveStreamPlay200HzTone22Kss) { |
414 if (IsRunningHeadless()) | 405 if (IsRunningHeadless()) |
415 return; | 406 return; |
416 AudioManager* audio_man = AudioManager::GetAudioManager(); | 407 scoped_refptr<AudioManager> audio_man(AudioManager::Create()); |
417 ASSERT_TRUE(NULL != audio_man); | |
418 if (!audio_man->HasAudioOutputDevices()) | 408 if (!audio_man->HasAudioOutputDevices()) |
419 return; | 409 return; |
420 uint32 samples_100_ms = AudioParameters::kAudioCDSampleRate / 20; | 410 uint32 samples_100_ms = AudioParameters::kAudioCDSampleRate / 20; |
421 AudioOutputStream* oas = audio_man->MakeAudioOutputStream( | 411 AudioOutputStream* oas = audio_man->MakeAudioOutputStream( |
422 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_MONO, | 412 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_MONO, |
423 AudioParameters::kAudioCDSampleRate / 2, 16, | 413 AudioParameters::kAudioCDSampleRate / 2, 16, |
424 samples_100_ms)); | 414 samples_100_ms)); |
425 ASSERT_TRUE(NULL != oas); | 415 ASSERT_TRUE(NULL != oas); |
426 | 416 |
427 SineWaveAudioSource source(SineWaveAudioSource::FORMAT_16BIT_LINEAR_PCM, 1, | 417 SineWaveAudioSource source(SineWaveAudioSource::FORMAT_16BIT_LINEAR_PCM, 1, |
(...skipping 25 matching lines...) Expand all Loading... | |
453 // Open sweep02_16b_mono_16KHz.raw which has no format. It contains the | 443 // Open sweep02_16b_mono_16KHz.raw which has no format. It contains the |
454 // raw 16 bit samples for a single channel in little-endian format. The | 444 // raw 16 bit samples for a single channel in little-endian format. The |
455 // creation sample rate is 16KHz. | 445 // creation sample rate is 16KHz. |
456 FilePath audio_file; | 446 FilePath audio_file; |
457 ASSERT_TRUE(PathService::Get(base::DIR_SOURCE_ROOT, &audio_file)); | 447 ASSERT_TRUE(PathService::Get(base::DIR_SOURCE_ROOT, &audio_file)); |
458 audio_file = audio_file.Append(kAudioFile1_16b_m_16K); | 448 audio_file = audio_file.Append(kAudioFile1_16b_m_16K); |
459 // Map the entire file in memory. | 449 // Map the entire file in memory. |
460 ReadOnlyMappedFile file_reader(audio_file.value().c_str()); | 450 ReadOnlyMappedFile file_reader(audio_file.value().c_str()); |
461 ASSERT_TRUE(file_reader.is_valid()); | 451 ASSERT_TRUE(file_reader.is_valid()); |
462 | 452 |
463 AudioManager* audio_man = AudioManager::GetAudioManager(); | 453 scoped_refptr<AudioManager> audio_man(AudioManager::Create()); |
464 ASSERT_TRUE(NULL != audio_man); | |
465 if (!audio_man->HasAudioOutputDevices()) | 454 if (!audio_man->HasAudioOutputDevices()) |
466 return; | 455 return; |
467 | 456 |
468 // Compute buffer size for 100ms of audio. | 457 // Compute buffer size for 100ms of audio. |
469 const uint32 kSamples100ms = (16000 / 1000) * 100; | 458 const uint32 kSamples100ms = (16000 / 1000) * 100; |
470 const uint32 kSize100ms = kSamples100ms * 2; | 459 const uint32 kSize100ms = kSamples100ms * 2; |
471 | 460 |
472 AudioOutputStream* oas = audio_man->MakeAudioOutputStream( | 461 AudioOutputStream* oas = audio_man->MakeAudioOutputStream( |
473 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_MONO, | 462 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_MONO, |
474 16000, 16, kSamples100ms)); | 463 16000, 16, kSamples100ms)); |
(...skipping 26 matching lines...) Expand all Loading... | |
501 oas->Stop(); | 490 oas->Stop(); |
502 oas->Close(); | 491 oas->Close(); |
503 } | 492 } |
504 | 493 |
505 // This test is to make sure an AudioOutputStream can be started after it was | 494 // This test is to make sure an AudioOutputStream can be started after it was |
506 // stopped. You will here two .5 seconds wave signal separated by 0.5 seconds | 495 // stopped. You will here two .5 seconds wave signal separated by 0.5 seconds |
507 // of silence. | 496 // of silence. |
508 TEST(WinAudioTest, PCMWaveStreamPlayTwice200HzTone44Kss) { | 497 TEST(WinAudioTest, PCMWaveStreamPlayTwice200HzTone44Kss) { |
509 if (IsRunningHeadless()) | 498 if (IsRunningHeadless()) |
510 return; | 499 return; |
511 AudioManager* audio_man = AudioManager::GetAudioManager(); | 500 scoped_refptr<AudioManager> audio_man(AudioManager::Create()); |
512 ASSERT_TRUE(NULL != audio_man); | |
513 if (!audio_man->HasAudioOutputDevices()) | 501 if (!audio_man->HasAudioOutputDevices()) |
514 return; | 502 return; |
515 | 503 |
516 uint32 samples_100_ms = AudioParameters::kAudioCDSampleRate / 10; | 504 uint32 samples_100_ms = AudioParameters::kAudioCDSampleRate / 10; |
517 AudioOutputStream* oas = audio_man->MakeAudioOutputStream( | 505 AudioOutputStream* oas = audio_man->MakeAudioOutputStream( |
518 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_MONO, | 506 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_MONO, |
519 AudioParameters::kAudioCDSampleRate, 16, samples_100_ms)); | 507 AudioParameters::kAudioCDSampleRate, 16, samples_100_ms)); |
520 ASSERT_TRUE(NULL != oas); | 508 ASSERT_TRUE(NULL != oas); |
521 | 509 |
522 SineWaveAudioSource source(SineWaveAudioSource::FORMAT_16BIT_LINEAR_PCM, 1, | 510 SineWaveAudioSource source(SineWaveAudioSource::FORMAT_16BIT_LINEAR_PCM, 1, |
(...skipping 16 matching lines...) Expand all Loading... | |
539 | 527 |
540 oas->Close(); | 528 oas->Close(); |
541 } | 529 } |
542 | 530 |
543 // With the low latency mode, WASAPI is utilized by default for Vista and | 531 // With the low latency mode, WASAPI is utilized by default for Vista and |
544 // higher and Wave is used for XP and lower. It is possible to utilize a | 532 // higher and Wave is used for XP and lower. It is possible to utilize a |
545 // smaller buffer size for WASAPI than for Wave. | 533 // smaller buffer size for WASAPI than for Wave. |
546 TEST(WinAudioTest, PCMWaveStreamPlay200HzToneLowLatency) { | 534 TEST(WinAudioTest, PCMWaveStreamPlay200HzToneLowLatency) { |
547 if (IsRunningHeadless()) | 535 if (IsRunningHeadless()) |
548 return; | 536 return; |
549 AudioManager* audio_man = AudioManager::GetAudioManager(); | 537 scoped_refptr<AudioManager> audio_man(AudioManager::Create()); |
550 ASSERT_TRUE(NULL != audio_man); | |
551 if (!audio_man->HasAudioOutputDevices()) | 538 if (!audio_man->HasAudioOutputDevices()) |
552 return; | 539 return; |
553 | 540 |
554 // The WASAPI API requires a correct COM environment. | 541 // The WASAPI API requires a correct COM environment. |
555 ScopedCOMInitializer com_init(ScopedCOMInitializer::kMTA); | 542 ScopedCOMInitializer com_init(ScopedCOMInitializer::kMTA); |
556 | 543 |
557 // Use 10 ms buffer size for WASAPI and 50 ms buffer size for Wave. | 544 // Use 10 ms buffer size for WASAPI and 50 ms buffer size for Wave. |
558 // Take the existing native sample rate into account. | 545 // Take the existing native sample rate into account. |
559 int sample_rate = static_cast<int>(media::GetAudioHardwareSampleRate()); | 546 int sample_rate = static_cast<int>(media::GetAudioHardwareSampleRate()); |
560 uint32 samples_10_ms = sample_rate / 100; | 547 uint32 samples_10_ms = sample_rate / 100; |
561 int n = 1; | 548 int n = 1; |
562 (base::win::GetVersion() <= base::win::VERSION_XP) ? n = 5 : n = 1; | 549 (base::win::GetVersion() <= base::win::VERSION_XP) ? n = 5 : n = 1; |
563 AudioOutputStream* oas = audio_man->MakeAudioOutputStream( | 550 AudioOutputStream* oas = audio_man->MakeAudioOutputStream( |
564 AudioParameters(AudioParameters::AUDIO_PCM_LOW_LATENCY, | 551 AudioParameters(AudioParameters::AUDIO_PCM_LOW_LATENCY, |
565 CHANNEL_LAYOUT_MONO, sample_rate, | 552 CHANNEL_LAYOUT_MONO, sample_rate, |
566 16, n * samples_10_ms)); | 553 16, n * samples_10_ms)); |
567 ASSERT_TRUE(NULL != oas); | 554 ASSERT_TRUE(NULL != oas); |
568 | 555 |
569 SineWaveAudioSource source(SineWaveAudioSource::FORMAT_16BIT_LINEAR_PCM, 1, | 556 SineWaveAudioSource source(SineWaveAudioSource::FORMAT_16BIT_LINEAR_PCM, 1, |
570 200.0, sample_rate); | 557 200.0, sample_rate); |
571 | 558 |
572 EXPECT_TRUE(oas->Open()); | |
573 oas->SetVolume(1.0); | |
574 | 559 |
575 // Play the wave for .8 seconds. | 560 bool opened; |
576 oas->Start(&source); | 561 EXPECT_TRUE(opened = oas->Open()); |
scherkus (not reviewing)
2011/12/09 22:47:30
ASSERT_TRUE(oas->Open())?
would do away w/ opened
tommi (sloooow) - chröme
2011/12/10 00:11:14
We still need to call Close(), but I've fixed this
| |
577 ::Sleep(800); | 562 if (opened) { |
578 oas->Stop(); | 563 oas->SetVolume(1.0); |
564 | |
565 // Play the wave for .8 seconds. | |
566 oas->Start(&source); | |
567 ::Sleep(800); | |
568 oas->Stop(); | |
569 } | |
579 oas->Close(); | 570 oas->Close(); |
580 } | 571 } |
581 | 572 |
582 // Check that the pending bytes value is correct what the stream starts. | 573 // Check that the pending bytes value is correct what the stream starts. |
583 TEST(WinAudioTest, PCMWaveStreamPendingBytes) { | 574 TEST(WinAudioTest, PCMWaveStreamPendingBytes) { |
584 if (IsRunningHeadless()) | 575 if (IsRunningHeadless()) |
585 return; | 576 return; |
586 AudioManager* audio_man = AudioManager::GetAudioManager(); | 577 scoped_refptr<AudioManager> audio_man(AudioManager::Create()); |
587 ASSERT_TRUE(NULL != audio_man); | |
588 if (!audio_man->HasAudioOutputDevices()) | 578 if (!audio_man->HasAudioOutputDevices()) |
589 return; | 579 return; |
590 | 580 |
591 uint32 samples_100_ms = AudioParameters::kAudioCDSampleRate / 10; | 581 uint32 samples_100_ms = AudioParameters::kAudioCDSampleRate / 10; |
592 AudioOutputStream* oas = audio_man->MakeAudioOutputStream( | 582 AudioOutputStream* oas = audio_man->MakeAudioOutputStream( |
593 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_MONO, | 583 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_MONO, |
594 AudioParameters::kAudioCDSampleRate, 16, samples_100_ms)); | 584 AudioParameters::kAudioCDSampleRate, 16, samples_100_ms)); |
595 ASSERT_TRUE(NULL != oas); | 585 ASSERT_TRUE(NULL != oas); |
596 | 586 |
597 NiceMock<MockAudioSource> source; | 587 NiceMock<MockAudioSource> source; |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
674 // This thread provides the data that the SyncSocketSource above needs | 664 // This thread provides the data that the SyncSocketSource above needs |
675 // using the other end of a SyncSocket. The protocol is as follows: | 665 // using the other end of a SyncSocket. The protocol is as follows: |
676 // | 666 // |
677 // SyncSocketSource ---send 4 bytes ------------> SyncSocketThread | 667 // SyncSocketSource ---send 4 bytes ------------> SyncSocketThread |
678 // <--- audio packet ---------- | 668 // <--- audio packet ---------- |
679 // | 669 // |
680 DWORD __stdcall SyncSocketThread(void* context) { | 670 DWORD __stdcall SyncSocketThread(void* context) { |
681 SyncThreadContext& ctx = *(reinterpret_cast<SyncThreadContext*>(context)); | 671 SyncThreadContext& ctx = *(reinterpret_cast<SyncThreadContext*>(context)); |
682 | 672 |
683 const int kTwoSecBytes = | 673 const int kTwoSecBytes = |
684 AudioParameters::kAudioCDSampleRate * 2 * sizeof(uint16); | 674 AudioParameters::kAudioCDSampleRate * 2 * sizeof(uint16); // NOLINT |
685 uint8* buffer = new uint8[kTwoSecBytes]; | 675 uint8* buffer = new uint8[kTwoSecBytes]; |
686 SineWaveAudioSource sine(SineWaveAudioSource::FORMAT_16BIT_LINEAR_PCM, | 676 SineWaveAudioSource sine(SineWaveAudioSource::FORMAT_16BIT_LINEAR_PCM, |
687 1, ctx.sine_freq, ctx.sample_rate); | 677 1, ctx.sine_freq, ctx.sample_rate); |
688 sine.OnMoreData(NULL, buffer, kTwoSecBytes, AudioBuffersState()); | 678 sine.OnMoreData(NULL, buffer, kTwoSecBytes, AudioBuffersState()); |
689 | 679 |
690 AudioBuffersState buffers_state; | 680 AudioBuffersState buffers_state; |
691 int times = 0; | 681 int times = 0; |
692 for (int ix = 0; ix < kTwoSecBytes; ix += ctx.packet_size_bytes) { | 682 for (int ix = 0; ix < kTwoSecBytes; ix += ctx.packet_size_bytes) { |
693 if (ctx.socket->Receive(&buffers_state, sizeof(buffers_state)) == 0) | 683 if (ctx.socket->Receive(&buffers_state, sizeof(buffers_state)) == 0) |
694 break; | 684 break; |
(...skipping 11 matching lines...) Expand all Loading... | |
706 // layer using a source based on SyncSocket. In a real situation we would | 696 // layer using a source based on SyncSocket. In a real situation we would |
707 // go for the low-latency version in combination with SyncSocket, but to keep | 697 // go for the low-latency version in combination with SyncSocket, but to keep |
708 // the test more simple, AUDIO_PCM_LINEAR is utilized instead. The main | 698 // the test more simple, AUDIO_PCM_LINEAR is utilized instead. The main |
709 // principle of the test still remains and we avoid the additional complexity | 699 // principle of the test still remains and we avoid the additional complexity |
710 // related to the two different audio-layers for AUDIO_PCM_LOW_LATENCY. | 700 // related to the two different audio-layers for AUDIO_PCM_LOW_LATENCY. |
711 // In this test you should hear a continuous 200Hz tone for 2 seconds. | 701 // In this test you should hear a continuous 200Hz tone for 2 seconds. |
712 TEST(WinAudioTest, SyncSocketBasic) { | 702 TEST(WinAudioTest, SyncSocketBasic) { |
713 if (IsRunningHeadless()) | 703 if (IsRunningHeadless()) |
714 return; | 704 return; |
715 | 705 |
716 AudioManager* audio_man = AudioManager::GetAudioManager(); | 706 scoped_refptr<AudioManager> audio_man(AudioManager::Create()); |
717 ASSERT_TRUE(NULL != audio_man); | |
718 if (!audio_man->HasAudioOutputDevices()) | 707 if (!audio_man->HasAudioOutputDevices()) |
719 return; | 708 return; |
720 | 709 |
721 int sample_rate = AudioParameters::kAudioCDSampleRate; | 710 int sample_rate = AudioParameters::kAudioCDSampleRate; |
722 const uint32 kSamples20ms = sample_rate / 50; | 711 const uint32 kSamples20ms = sample_rate / 50; |
723 AudioOutputStream* oas = audio_man->MakeAudioOutputStream( | 712 AudioOutputStream* oas = audio_man->MakeAudioOutputStream( |
724 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, | 713 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, |
725 CHANNEL_LAYOUT_MONO, sample_rate, 16, kSamples20ms)); | 714 CHANNEL_LAYOUT_MONO, sample_rate, 16, kSamples20ms)); |
726 ASSERT_TRUE(NULL != oas); | 715 ASSERT_TRUE(NULL != oas); |
727 | 716 |
(...skipping 15 matching lines...) Expand all Loading... | |
743 | 732 |
744 oas->Start(&source); | 733 oas->Start(&source); |
745 | 734 |
746 ::WaitForSingleObject(thread, INFINITE); | 735 ::WaitForSingleObject(thread, INFINITE); |
747 ::CloseHandle(thread); | 736 ::CloseHandle(thread); |
748 delete sockets[1]; | 737 delete sockets[1]; |
749 | 738 |
750 oas->Stop(); | 739 oas->Stop(); |
751 oas->Close(); | 740 oas->Close(); |
752 } | 741 } |
OLD | NEW |