OLD | NEW |
1 // Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2009 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 | 6 |
7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
8 #include "base/base_paths.h" | 8 #include "base/base_paths.h" |
9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
10 #include "media/audio/audio_output.h" | 10 #include "media/audio/audio_output.h" |
(...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
296 AudioOutputStream* oas = | 296 AudioOutputStream* oas = |
297 audio_man->MakeAudioStream(AudioManager::AUDIO_PCM_LINEAR, 1, 16000, 16); | 297 audio_man->MakeAudioStream(AudioManager::AUDIO_PCM_LINEAR, 1, 16000, 16); |
298 ASSERT_TRUE(NULL != oas); | 298 ASSERT_TRUE(NULL != oas); |
299 TestSourceTripleBuffer test_triple_buffer; | 299 TestSourceTripleBuffer test_triple_buffer; |
300 EXPECT_TRUE(oas->Open(512)); | 300 EXPECT_TRUE(oas->Open(512)); |
301 oas->Start(&test_triple_buffer); | 301 oas->Start(&test_triple_buffer); |
302 ::Sleep(300); | 302 ::Sleep(300); |
303 EXPECT_GT(test_triple_buffer.callback_count(), kNumBuffers); | 303 EXPECT_GT(test_triple_buffer.callback_count(), kNumBuffers); |
304 EXPECT_FALSE(test_triple_buffer.had_error()); | 304 EXPECT_FALSE(test_triple_buffer.had_error()); |
305 oas->Stop(); | 305 oas->Stop(); |
306 ::Sleep(1000); | 306 ::Sleep(500); |
307 oas->Close(); | 307 oas->Close(); |
308 } | 308 } |
309 | 309 |
310 // Test potential deadlock situation if the source is slow or blocks for some | 310 // Test potential deadlock situation if the source is slow or blocks for some |
311 // time. The actual EXPECT_GT are mostly meaningless and the real test is that | 311 // time. The actual EXPECT_GT are mostly meaningless and the real test is that |
312 // the test completes in reasonable time. | 312 // the test completes in reasonable time. |
313 TEST(WinAudioTest, PCMWaveSlowSource) { | 313 TEST(WinAudioTest, PCMWaveSlowSource) { |
314 if (IsRunningHeadless()) | 314 if (IsRunningHeadless()) |
315 return; | 315 return; |
316 AudioManager* audio_man = AudioManager::GetAudioManager(); | 316 AudioManager* audio_man = AudioManager::GetAudioManager(); |
317 ASSERT_TRUE(NULL != audio_man); | 317 ASSERT_TRUE(NULL != audio_man); |
318 if (!audio_man->HasAudioDevices()) | 318 if (!audio_man->HasAudioDevices()) |
319 return; | 319 return; |
320 AudioOutputStream* oas = | 320 AudioOutputStream* oas = |
321 audio_man->MakeAudioStream(AudioManager::AUDIO_PCM_LINEAR, 1, 16000, 16); | 321 audio_man->MakeAudioStream(AudioManager::AUDIO_PCM_LINEAR, 1, 16000, 16); |
322 ASSERT_TRUE(NULL != oas); | 322 ASSERT_TRUE(NULL != oas); |
323 TestSourceLaggy test_laggy(2, 90); | 323 TestSourceLaggy test_laggy(2, 90); |
324 EXPECT_TRUE(oas->Open(512)); | 324 EXPECT_TRUE(oas->Open(512)); |
325 // The test parameters cause a callback every 32 ms and the source is | 325 // The test parameters cause a callback every 32 ms and the source is |
326 // sleeping for 90 ms, so it is guaranteed that we run out of ready buffers. | 326 // sleeping for 90 ms, so it is guaranteed that we run out of ready buffers. |
327 oas->Start(&test_laggy); | 327 oas->Start(&test_laggy); |
328 ::Sleep(1000); | 328 ::Sleep(500); |
329 EXPECT_GT(test_laggy.callback_count(), 2); | 329 EXPECT_GT(test_laggy.callback_count(), 2); |
330 EXPECT_FALSE(test_laggy.had_error()); | 330 EXPECT_FALSE(test_laggy.had_error()); |
331 oas->Stop(); | 331 oas->Stop(); |
332 ::Sleep(1000); | 332 ::Sleep(500); |
333 oas->Close(); | 333 oas->Close(); |
334 } | 334 } |
335 | 335 |
336 // Test another potential deadlock situation if the thread that calls Start() | 336 // Test another potential deadlock situation if the thread that calls Start() |
337 // gets paused. This test is best when run over RDP with audio enabled. See | 337 // gets paused. This test is best when run over RDP with audio enabled. See |
338 // bug 19276 for more details. | 338 // bug 19276 for more details. |
339 TEST(WinAudioTest, PCMWaveStreamPlaySlowLoop) { | 339 TEST(WinAudioTest, PCMWaveStreamPlaySlowLoop) { |
340 if (IsRunningHeadless()) | 340 if (IsRunningHeadless()) |
341 return; | 341 return; |
342 AudioManager* audio_man = AudioManager::GetAudioManager(); | 342 AudioManager* audio_man = AudioManager::GetAudioManager(); |
343 ASSERT_TRUE(NULL != audio_man); | 343 ASSERT_TRUE(NULL != audio_man); |
344 if (!audio_man->HasAudioDevices()) | 344 if (!audio_man->HasAudioDevices()) |
345 return; | 345 return; |
346 AudioOutputStream* oas = | 346 AudioOutputStream* oas = |
347 audio_man->MakeAudioStream(AudioManager::AUDIO_PCM_LINEAR, 1, | 347 audio_man->MakeAudioStream(AudioManager::AUDIO_PCM_LINEAR, 1, |
348 AudioManager::kAudioCDSampleRate, 16); | 348 AudioManager::kAudioCDSampleRate, 16); |
349 ASSERT_TRUE(NULL != oas); | 349 ASSERT_TRUE(NULL != oas); |
350 | 350 |
351 SineWaveAudioSource source(SineWaveAudioSource::FORMAT_16BIT_LINEAR_PCM, 1, | 351 SineWaveAudioSource source(SineWaveAudioSource::FORMAT_16BIT_LINEAR_PCM, 1, |
352 200.0, AudioManager::kAudioCDSampleRate); | 352 200.0, AudioManager::kAudioCDSampleRate); |
353 size_t bytes_100_ms = (AudioManager::kAudioCDSampleRate / 10) * 2; | 353 size_t bytes_100_ms = (AudioManager::kAudioCDSampleRate / 10) * 2; |
354 | 354 |
355 EXPECT_TRUE(oas->Open(bytes_100_ms)); | 355 EXPECT_TRUE(oas->Open(bytes_100_ms)); |
356 oas->SetVolume(1.0, 1.0); | 356 oas->SetVolume(1.0); |
357 | 357 |
358 for (int ix = 0; ix != 25; ++ix) { | 358 for (int ix = 0; ix != 5; ++ix) { |
359 oas->Start(&source); | 359 oas->Start(&source); |
360 ::Sleep(10); | 360 ::Sleep(10); |
361 oas->Stop(); | 361 oas->Stop(); |
362 } | 362 } |
363 oas->Close(); | 363 oas->Close(); |
364 } | 364 } |
365 | 365 |
366 | 366 |
367 // This test produces actual audio for 1.5 seconds on the default wave | 367 // This test produces actual audio for .5 seconds on the default wave |
368 // device at 44.1K s/sec. Parameters have been chosen carefully so you should | 368 // device at 44.1K s/sec. Parameters have been chosen carefully so you should |
369 // not hear pops or noises while the sound is playing. | 369 // not hear pops or noises while the sound is playing. |
370 TEST(WinAudioTest, PCMWaveStreamPlay200HzTone44Kss) { | 370 TEST(WinAudioTest, PCMWaveStreamPlay200HzTone44Kss) { |
371 if (IsRunningHeadless()) | 371 if (IsRunningHeadless()) |
372 return; | 372 return; |
373 AudioManager* audio_man = AudioManager::GetAudioManager(); | 373 AudioManager* audio_man = AudioManager::GetAudioManager(); |
374 ASSERT_TRUE(NULL != audio_man); | 374 ASSERT_TRUE(NULL != audio_man); |
375 if (!audio_man->HasAudioDevices()) | 375 if (!audio_man->HasAudioDevices()) |
376 return; | 376 return; |
377 AudioOutputStream* oas = | 377 AudioOutputStream* oas = |
378 audio_man->MakeAudioStream(AudioManager::AUDIO_PCM_LINEAR, 1, | 378 audio_man->MakeAudioStream(AudioManager::AUDIO_PCM_LINEAR, 1, |
379 AudioManager::kAudioCDSampleRate, 16); | 379 AudioManager::kAudioCDSampleRate, 16); |
380 ASSERT_TRUE(NULL != oas); | 380 ASSERT_TRUE(NULL != oas); |
381 | 381 |
382 SineWaveAudioSource source(SineWaveAudioSource::FORMAT_16BIT_LINEAR_PCM, 1, | 382 SineWaveAudioSource source(SineWaveAudioSource::FORMAT_16BIT_LINEAR_PCM, 1, |
383 200.0, AudioManager::kAudioCDSampleRate); | 383 200.0, AudioManager::kAudioCDSampleRate); |
384 size_t bytes_100_ms = (AudioManager::kAudioCDSampleRate / 10) * 2; | 384 size_t bytes_100_ms = (AudioManager::kAudioCDSampleRate / 10) * 2; |
385 | 385 |
386 EXPECT_TRUE(oas->Open(bytes_100_ms)); | 386 EXPECT_TRUE(oas->Open(bytes_100_ms)); |
387 oas->SetVolume(1.0, 1.0); | 387 oas->SetVolume(1.0); |
388 oas->Start(&source); | 388 oas->Start(&source); |
389 ::Sleep(1500); | 389 ::Sleep(500); |
390 oas->Stop(); | 390 oas->Stop(); |
391 oas->Close(); | 391 oas->Close(); |
392 } | 392 } |
393 | 393 |
394 // This test produces actual audio for for 1.5 seconds on the default wave | 394 // This test produces actual audio for for .5 seconds on the default wave |
395 // device at 22K s/sec. Parameters have been chosen carefully so you should | 395 // device at 22K s/sec. Parameters have been chosen carefully so you should |
396 // not hear pops or noises while the sound is playing. The audio also should | 396 // not hear pops or noises while the sound is playing. The audio also should |
397 // sound with a lower volume than PCMWaveStreamPlay200HzTone44Kss. | 397 // sound with a lower volume than PCMWaveStreamPlay200HzTone44Kss. |
398 TEST(WinAudioTest, PCMWaveStreamPlay200HzTone22Kss) { | 398 TEST(WinAudioTest, PCMWaveStreamPlay200HzTone22Kss) { |
399 if (IsRunningHeadless()) | 399 if (IsRunningHeadless()) |
400 return; | 400 return; |
401 AudioManager* audio_man = AudioManager::GetAudioManager(); | 401 AudioManager* audio_man = AudioManager::GetAudioManager(); |
402 ASSERT_TRUE(NULL != audio_man); | 402 ASSERT_TRUE(NULL != audio_man); |
403 if (!audio_man->HasAudioDevices()) | 403 if (!audio_man->HasAudioDevices()) |
404 return; | 404 return; |
405 AudioOutputStream* oas = | 405 AudioOutputStream* oas = |
406 audio_man->MakeAudioStream(AudioManager::AUDIO_PCM_LINEAR, 1, | 406 audio_man->MakeAudioStream(AudioManager::AUDIO_PCM_LINEAR, 1, |
407 AudioManager::kAudioCDSampleRate/2, 16); | 407 AudioManager::kAudioCDSampleRate/2, 16); |
408 ASSERT_TRUE(NULL != oas); | 408 ASSERT_TRUE(NULL != oas); |
409 | 409 |
410 SineWaveAudioSource source(SineWaveAudioSource::FORMAT_16BIT_LINEAR_PCM, 1, | 410 SineWaveAudioSource source(SineWaveAudioSource::FORMAT_16BIT_LINEAR_PCM, 1, |
411 200.0, AudioManager::kAudioCDSampleRate/2); | 411 200.0, AudioManager::kAudioCDSampleRate/2); |
412 size_t bytes_100_ms = (AudioManager::kAudioCDSampleRate / 20) * 2; | 412 size_t bytes_100_ms = (AudioManager::kAudioCDSampleRate / 20) * 2; |
413 | 413 |
414 EXPECT_TRUE(oas->Open(bytes_100_ms)); | 414 EXPECT_TRUE(oas->Open(bytes_100_ms)); |
415 | 415 |
416 oas->SetVolume(0.5, 0.5); | 416 oas->SetVolume(0.5); |
417 oas->Start(&source); | 417 oas->Start(&source); |
418 ::Sleep(1500); | 418 ::Sleep(500); |
419 | 419 |
420 // Test that the volume is within the set limits. | 420 // Test that the volume is within the set limits. |
421 double left_volume = 0.0; | 421 double volume = 0.0; |
422 double right_volume = 0.0; | 422 oas->GetVolume(&volume); |
423 oas->GetVolume(&left_volume, &right_volume); | 423 EXPECT_LT(volume, 0.51); |
424 EXPECT_LT(left_volume, 0.51); | 424 EXPECT_GT(volume, 0.49); |
425 EXPECT_GT(left_volume, 0.49); | |
426 EXPECT_LT(right_volume, 0.51); | |
427 EXPECT_GT(right_volume, 0.49); | |
428 oas->Stop(); | 425 oas->Stop(); |
429 oas->Close(); | 426 oas->Close(); |
430 } | 427 } |
431 | 428 |
432 // Uses the PushSource to play a 2 seconds file clip for about 5 seconds. We | 429 // Uses the PushSource to play a 2 seconds file clip for about 5 seconds. We |
433 // try hard to generate situation where the two threads are accessing the | 430 // try hard to generate situation where the two threads are accessing the |
434 // object roughly at the same time. What you hear is a sweeping tone from 1KHz | 431 // object roughly at the same time. What you hear is a sweeping tone from 1KHz |
435 // to 2KHz with a bit of fade out at the end for one second. The file is two | 432 // to 2KHz with a bit of fade out at the end for one second. The file is two |
436 // of these sweeping tones back to back. | 433 // of these sweeping tones back to back. |
437 TEST(WinAudioTest, PushSourceFile16KHz) { | 434 TEST(WinAudioTest, PushSourceFile16KHz) { |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
472 // For glitch free, start playing after some buffers are in. | 469 // For glitch free, start playing after some buffers are in. |
473 oas->Start(&push_source); | 470 oas->Start(&push_source); |
474 } | 471 } |
475 ::Sleep(10); | 472 ::Sleep(10); |
476 offset += kSize50ms; | 473 offset += kSize50ms; |
477 if (offset > kMaxStartOffset) | 474 if (offset > kMaxStartOffset) |
478 offset = 0; | 475 offset = 0; |
479 } | 476 } |
480 | 477 |
481 // Play a little bit more of the file. | 478 // Play a little bit more of the file. |
482 ::Sleep(4000); | 479 ::Sleep(500); |
483 | 480 |
484 oas->Stop(); | 481 oas->Stop(); |
485 oas->Close(); | 482 oas->Close(); |
486 } | 483 } |
487 | 484 |
488 // This test is to make sure an AudioOutputStream can be started after it was | 485 // This test is to make sure an AudioOutputStream can be started after it was |
489 // stopped. You will here two 1.5 seconds wave signal separated by 0.5 seconds | 486 // stopped. You will here two .5 seconds wave signal separated by 0.5 seconds |
490 // of silence. | 487 // of silence. |
491 TEST(WinAudioTest, PCMWaveStreamPlayTwice200HzTone44Kss) { | 488 TEST(WinAudioTest, PCMWaveStreamPlayTwice200HzTone44Kss) { |
492 if (IsRunningHeadless()) | 489 if (IsRunningHeadless()) |
493 return; | 490 return; |
494 AudioManager* audio_man = AudioManager::GetAudioManager(); | 491 AudioManager* audio_man = AudioManager::GetAudioManager(); |
495 ASSERT_TRUE(NULL != audio_man); | 492 ASSERT_TRUE(NULL != audio_man); |
496 if (!audio_man->HasAudioDevices()) | 493 if (!audio_man->HasAudioDevices()) |
497 return; | 494 return; |
498 AudioOutputStream* oas = | 495 AudioOutputStream* oas = |
499 audio_man->MakeAudioStream(AudioManager::AUDIO_PCM_LINEAR, 1, | 496 audio_man->MakeAudioStream(AudioManager::AUDIO_PCM_LINEAR, 1, |
500 AudioManager::kAudioCDSampleRate, 16); | 497 AudioManager::kAudioCDSampleRate, 16); |
501 ASSERT_TRUE(NULL != oas); | 498 ASSERT_TRUE(NULL != oas); |
502 | 499 |
503 SineWaveAudioSource source(SineWaveAudioSource::FORMAT_16BIT_LINEAR_PCM, 1, | 500 SineWaveAudioSource source(SineWaveAudioSource::FORMAT_16BIT_LINEAR_PCM, 1, |
504 200.0, AudioManager::kAudioCDSampleRate); | 501 200.0, AudioManager::kAudioCDSampleRate); |
505 size_t bytes_100_ms = (AudioManager::kAudioCDSampleRate / 10) * 2; | 502 size_t bytes_100_ms = (AudioManager::kAudioCDSampleRate / 10) * 2; |
506 | 503 |
507 EXPECT_TRUE(oas->Open(bytes_100_ms)); | 504 EXPECT_TRUE(oas->Open(bytes_100_ms)); |
508 oas->SetVolume(1.0, 1.0); | 505 oas->SetVolume(1.0); |
509 | 506 |
510 // Play the wave for 1.5 seconds. | 507 // Play the wave for .5 seconds. |
511 oas->Start(&source); | 508 oas->Start(&source); |
512 ::Sleep(1500); | 509 ::Sleep(500); |
513 oas->Stop(); | 510 oas->Stop(); |
514 | 511 |
515 // Sleep to give silence after stopping the AudioOutputStream. | 512 // Sleep to give silence after stopping the AudioOutputStream. |
| 513 ::Sleep(250); |
| 514 |
| 515 // Start again and play for .5 seconds. |
| 516 oas->Start(&source); |
516 ::Sleep(500); | 517 ::Sleep(500); |
517 | |
518 // Start again and play for 1.5 seconds. | |
519 oas->Start(&source); | |
520 ::Sleep(1500); | |
521 oas->Stop(); | 518 oas->Stop(); |
522 | 519 |
523 oas->Close(); | 520 oas->Close(); |
524 } | 521 } |
525 | 522 |
526 // Check that the pending bytes value is correct what the stream starts. | 523 // Check that the pending bytes value is correct what the stream starts. |
527 TEST(WinAudioTest, PCMWaveStreamPendingBytes) { | 524 TEST(WinAudioTest, PCMWaveStreamPendingBytes) { |
528 if (IsRunningHeadless()) | 525 if (IsRunningHeadless()) |
529 return; | 526 return; |
530 AudioManager* audio_man = AudioManager::GetAudioManager(); | 527 AudioManager* audio_man = AudioManager::GetAudioManager(); |
(...skipping 28 matching lines...) Expand all Loading... |
559 .WillOnce(Return(0)); | 556 .WillOnce(Return(0)); |
560 EXPECT_CALL(source, OnMoreData(oas, NotNull(), bytes_100_ms, 0)) | 557 EXPECT_CALL(source, OnMoreData(oas, NotNull(), bytes_100_ms, 0)) |
561 .Times(AnyNumber()) | 558 .Times(AnyNumber()) |
562 .WillRepeatedly(Return(0)); | 559 .WillRepeatedly(Return(0)); |
563 | 560 |
564 oas->Start(&source); | 561 oas->Start(&source); |
565 ::Sleep(500); | 562 ::Sleep(500); |
566 oas->Stop(); | 563 oas->Stop(); |
567 oas->Close(); | 564 oas->Close(); |
568 } | 565 } |
OLD | NEW |