OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/android/build_info.h" | 5 #include "base/android/build_info.h" |
6 #include "base/basictypes.h" | 6 #include "base/basictypes.h" |
7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
10 #include "base/path_service.h" | 10 #include "base/path_service.h" |
| 11 #include "base/run_loop.h" |
11 #include "base/strings/stringprintf.h" | 12 #include "base/strings/stringprintf.h" |
12 #include "base/synchronization/lock.h" | 13 #include "base/synchronization/lock.h" |
13 #include "base/synchronization/waitable_event.h" | 14 #include "base/synchronization/waitable_event.h" |
14 #include "base/test/test_timeouts.h" | 15 #include "base/test/test_timeouts.h" |
15 #include "base/time/time.h" | 16 #include "base/time/time.h" |
16 #include "build/build_config.h" | 17 #include "build/build_config.h" |
17 #include "media/audio/android/audio_manager_android.h" | 18 #include "media/audio/android/audio_manager_android.h" |
18 #include "media/audio/audio_io.h" | 19 #include "media/audio/audio_io.h" |
19 #include "media/audio/audio_manager_base.h" | 20 #include "media/audio/audio_manager_base.h" |
20 #include "media/audio/mock_audio_source_callback.h" | 21 #include "media/audio/mock_audio_source_callback.h" |
(...skipping 382 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
403 scoped_ptr<media::SeekableBuffer> fifo_; | 404 scoped_ptr<media::SeekableBuffer> fifo_; |
404 scoped_ptr<uint8[]> buffer_; | 405 scoped_ptr<uint8[]> buffer_; |
405 bool started_; | 406 bool started_; |
406 | 407 |
407 DISALLOW_COPY_AND_ASSIGN(FullDuplexAudioSinkSource); | 408 DISALLOW_COPY_AND_ASSIGN(FullDuplexAudioSinkSource); |
408 }; | 409 }; |
409 | 410 |
410 // Test fixture class for tests which only exercise the output path. | 411 // Test fixture class for tests which only exercise the output path. |
411 class AudioAndroidOutputTest : public testing::Test { | 412 class AudioAndroidOutputTest : public testing::Test { |
412 public: | 413 public: |
413 AudioAndroidOutputTest() {} | 414 AudioAndroidOutputTest() |
| 415 : loop_(new base::MessageLoopForUI()), |
| 416 audio_manager_(AudioManager::CreateForTesting()), |
| 417 audio_output_stream_(NULL) { |
| 418 } |
| 419 |
| 420 virtual ~AudioAndroidOutputTest() { |
| 421 } |
414 | 422 |
415 protected: | 423 protected: |
416 virtual void SetUp() { | 424 AudioManager* audio_manager() { return audio_manager_.get(); } |
417 audio_manager_.reset(AudioManager::CreateForTesting()); | 425 base::MessageLoopForUI* loop() { return loop_.get(); } |
418 loop_.reset(new base::MessageLoopForUI()); | 426 AudioOutputStream* audio_output_stream() const { |
| 427 return audio_output_stream_; |
419 } | 428 } |
420 | 429 |
421 virtual void TearDown() {} | 430 // Synchronously runs the provided callback/closure on the audio thread. |
| 431 void RunOnAudioThread(const base::Closure& closure) { |
| 432 if (!audio_manager()->GetTaskRunner()->BelongsToCurrentThread()) { |
| 433 base::WaitableEvent event(false, false); |
| 434 audio_manager()->GetTaskRunner()->PostTask( |
| 435 FROM_HERE, |
| 436 base::Bind(&AudioAndroidOutputTest::RunOnAudioThreadImpl, |
| 437 base::Unretained(this), |
| 438 closure, |
| 439 &event)); |
| 440 event.Wait(); |
| 441 } else { |
| 442 closure.Run(); |
| 443 } |
| 444 } |
422 | 445 |
423 AudioManager* audio_manager() { return audio_manager_.get(); } | 446 void RunOnAudioThreadImpl(const base::Closure& closure, |
424 base::MessageLoopForUI* loop() { return loop_.get(); } | 447 base::WaitableEvent* event) { |
| 448 DCHECK(audio_manager()->GetTaskRunner()->BelongsToCurrentThread()); |
| 449 closure.Run(); |
| 450 event->Signal(); |
| 451 } |
425 | 452 |
426 AudioParameters GetDefaultOutputStreamParameters() { | 453 AudioParameters GetDefaultOutputStreamParameters() { |
427 return audio_manager()->GetDefaultOutputStreamParameters(); | 454 return audio_manager()->GetDefaultOutputStreamParameters(); |
428 } | 455 } |
429 | 456 |
| 457 void MakeAOSOnAudioThread(const AudioParameters& params) { |
| 458 RunOnAudioThread( |
| 459 base::Bind(&AudioAndroidOutputTest::MakeOutputStream, |
| 460 base::Unretained(this), |
| 461 params)); |
| 462 } |
| 463 |
| 464 void OpenAndCloseAOSOnAudioThread() { |
| 465 RunOnAudioThread( |
| 466 base::Bind(&AudioAndroidOutputTest::OpenAndClose, |
| 467 base::Unretained(this))); |
| 468 } |
| 469 |
| 470 void OpenAndStartAOSOnAudioThread( |
| 471 AudioOutputStream::AudioSourceCallback* source) { |
| 472 RunOnAudioThread( |
| 473 base::Bind(&AudioAndroidOutputTest::OpenAndStart, |
| 474 base::Unretained(this), |
| 475 source)); |
| 476 } |
| 477 |
| 478 void StopAndCloseAOSOnAudioThread() { |
| 479 RunOnAudioThread( |
| 480 base::Bind(&AudioAndroidOutputTest::StopAndClose, |
| 481 base::Unretained(this))); |
| 482 } |
| 483 |
430 double AverageTimeBetweenCallbacks(int num_callbacks) const { | 484 double AverageTimeBetweenCallbacks(int num_callbacks) const { |
431 return ((end_time_ - start_time_) / static_cast<double>(num_callbacks - 1)) | 485 return ((end_time_ - start_time_) / static_cast<double>(num_callbacks - 1)) |
432 .InMillisecondsF(); | 486 .InMillisecondsF(); |
433 } | 487 } |
434 | 488 |
435 void StartOutputStreamCallbacks(const AudioParameters& params) { | 489 void StartOutputStreamCallbacks(const AudioParameters& params) { |
436 double expected_time_between_callbacks_ms = | 490 double expected_time_between_callbacks_ms = |
437 ExpectedTimeBetweenCallbacks(params); | 491 ExpectedTimeBetweenCallbacks(params); |
438 const int num_callbacks = | 492 const int num_callbacks = |
439 (kCallbackTestTimeMs / expected_time_between_callbacks_ms); | 493 (kCallbackTestTimeMs / expected_time_between_callbacks_ms); |
440 AudioOutputStream* stream = audio_manager()->MakeAudioOutputStream( | 494 |
441 params, std::string(), std::string()); | 495 MakeAOSOnAudioThread(params); |
442 EXPECT_TRUE(stream); | |
443 | 496 |
444 int count = 0; | 497 int count = 0; |
445 MockAudioSourceCallback source; | 498 MockAudioSourceCallback source; |
446 | 499 |
447 EXPECT_CALL(source, OnMoreData(NotNull(), _)) | 500 EXPECT_CALL(source, OnMoreData(NotNull(), _)) |
448 .Times(AtLeast(num_callbacks)) | 501 .Times(AtLeast(num_callbacks)) |
449 .WillRepeatedly( | 502 .WillRepeatedly( |
450 DoAll(CheckCountAndPostQuitTask(&count, num_callbacks, loop()), | 503 DoAll(CheckCountAndPostQuitTask(&count, num_callbacks, loop()), |
451 Invoke(RealOnMoreData))); | 504 Invoke(RealOnMoreData))); |
452 EXPECT_CALL(source, OnError(stream)).Times(0); | 505 EXPECT_CALL(source, OnError(audio_output_stream())).Times(0); |
453 EXPECT_CALL(source, OnMoreIOData(_, _, _)).Times(0); | 506 EXPECT_CALL(source, OnMoreIOData(_, _, _)).Times(0); |
454 | 507 |
455 EXPECT_TRUE(stream->Open()); | 508 OpenAndStartAOSOnAudioThread(&source); |
456 stream->Start(&source); | 509 |
457 start_time_ = base::TimeTicks::Now(); | 510 start_time_ = base::TimeTicks::Now(); |
458 loop()->Run(); | 511 loop()->Run(); |
459 end_time_ = base::TimeTicks::Now(); | 512 end_time_ = base::TimeTicks::Now(); |
460 stream->Stop(); | 513 |
461 stream->Close(); | 514 StopAndCloseAOSOnAudioThread(); |
462 | 515 |
463 double average_time_between_callbacks_ms = | 516 double average_time_between_callbacks_ms = |
464 AverageTimeBetweenCallbacks(num_callbacks); | 517 AverageTimeBetweenCallbacks(num_callbacks); |
465 VLOG(0) << "expected time between callbacks: " | 518 VLOG(0) << "expected time between callbacks: " |
466 << expected_time_between_callbacks_ms << " ms"; | 519 << expected_time_between_callbacks_ms << " ms"; |
467 VLOG(0) << "average time between callbacks: " | 520 VLOG(0) << "average time between callbacks: " |
468 << average_time_between_callbacks_ms << " ms"; | 521 << average_time_between_callbacks_ms << " ms"; |
469 EXPECT_GE(average_time_between_callbacks_ms, | 522 EXPECT_GE(average_time_between_callbacks_ms, |
470 0.70 * expected_time_between_callbacks_ms); | 523 0.70 * expected_time_between_callbacks_ms); |
471 EXPECT_LE(average_time_between_callbacks_ms, | 524 EXPECT_LE(average_time_between_callbacks_ms, |
472 1.30 * expected_time_between_callbacks_ms); | 525 1.30 * expected_time_between_callbacks_ms); |
473 } | 526 } |
474 | 527 |
| 528 void MakeOutputStream(const AudioParameters& params) { |
| 529 DCHECK(audio_manager()->GetTaskRunner()->BelongsToCurrentThread()); |
| 530 audio_output_stream_ = audio_manager()->MakeAudioOutputStream( |
| 531 params, std::string(), std::string()); |
| 532 EXPECT_TRUE(audio_output_stream_); |
| 533 } |
| 534 |
| 535 void OpenAndClose() { |
| 536 DCHECK(audio_manager()->GetTaskRunner()->BelongsToCurrentThread()); |
| 537 EXPECT_TRUE(audio_output_stream()->Open()); |
| 538 audio_output_stream()->Close(); |
| 539 } |
| 540 |
| 541 void OpenAndStart(AudioOutputStream::AudioSourceCallback* source) { |
| 542 DCHECK(audio_manager()->GetTaskRunner()->BelongsToCurrentThread()); |
| 543 EXPECT_TRUE(audio_output_stream()->Open()); |
| 544 audio_output_stream()->Start(source); |
| 545 } |
| 546 |
| 547 void StopAndClose() { |
| 548 DCHECK(audio_manager()->GetTaskRunner()->BelongsToCurrentThread()); |
| 549 audio_output_stream()->Stop(); |
| 550 audio_output_stream()->Close(); |
| 551 } |
| 552 |
475 scoped_ptr<base::MessageLoopForUI> loop_; | 553 scoped_ptr<base::MessageLoopForUI> loop_; |
476 scoped_ptr<AudioManager> audio_manager_; | 554 scoped_ptr<AudioManager> audio_manager_; |
| 555 AudioOutputStream* audio_output_stream_; |
477 base::TimeTicks start_time_; | 556 base::TimeTicks start_time_; |
478 base::TimeTicks end_time_; | 557 base::TimeTicks end_time_; |
479 | 558 |
480 private: | 559 private: |
481 DISALLOW_COPY_AND_ASSIGN(AudioAndroidOutputTest); | 560 DISALLOW_COPY_AND_ASSIGN(AudioAndroidOutputTest); |
482 }; | 561 }; |
483 | 562 |
484 // AudioRecordInputStream should only be created on Jelly Bean and higher. This | 563 // AudioRecordInputStream should only be created on Jelly Bean and higher. This |
485 // ensures we only test against the AudioRecord path when that is satisfied. | 564 // ensures we only test against the AudioRecord path when that is satisfied. |
486 std::vector<bool> RunAudioRecordInputPathTests() { | 565 std::vector<bool> RunAudioRecordInputPathTests() { |
487 std::vector<bool> tests; | 566 std::vector<bool> tests; |
488 tests.push_back(false); | 567 tests.push_back(false); |
489 if (base::android::BuildInfo::GetInstance()->sdk_int() >= 16) | 568 if (base::android::BuildInfo::GetInstance()->sdk_int() >= 16) |
490 tests.push_back(true); | 569 tests.push_back(true); |
491 return tests; | 570 return tests; |
492 } | 571 } |
493 | 572 |
494 // Test fixture class for tests which exercise the input path, or both input and | 573 // Test fixture class for tests which exercise the input path, or both input and |
495 // output paths. It is value-parameterized to test against both the Java | 574 // output paths. It is value-parameterized to test against both the Java |
496 // AudioRecord (when true) and native OpenSLES (when false) input paths. | 575 // AudioRecord (when true) and native OpenSLES (when false) input paths. |
497 class AudioAndroidInputTest : public AudioAndroidOutputTest, | 576 class AudioAndroidInputTest : public AudioAndroidOutputTest, |
498 public testing::WithParamInterface<bool> { | 577 public testing::WithParamInterface<bool> { |
499 public: | 578 public: |
500 AudioAndroidInputTest() {} | 579 AudioAndroidInputTest() : audio_input_stream_(NULL) {} |
501 | 580 |
502 protected: | 581 protected: |
| 582 AudioInputStream* audio_input_stream() { return audio_input_stream_; } |
| 583 |
503 AudioParameters GetInputStreamParameters() { | 584 AudioParameters GetInputStreamParameters() { |
504 AudioParameters input_params = audio_manager()->GetInputStreamParameters( | 585 AudioParameters input_params = audio_manager()->GetInputStreamParameters( |
505 AudioManagerBase::kDefaultDeviceId); | 586 AudioManagerBase::kDefaultDeviceId); |
506 // Override the platform effects setting to use the AudioRecord or OpenSLES | 587 // Override the platform effects setting to use the AudioRecord or OpenSLES |
507 // path as requested. | 588 // path as requested. |
508 int effects = GetParam() ? AudioParameters::ECHO_CANCELLER : | 589 int effects = GetParam() ? AudioParameters::ECHO_CANCELLER : |
509 AudioParameters::NO_EFFECTS; | 590 AudioParameters::NO_EFFECTS; |
510 AudioParameters params(input_params.format(), | 591 AudioParameters params(input_params.format(), |
511 input_params.channel_layout(), | 592 input_params.channel_layout(), |
512 input_params.input_channels(), | 593 input_params.input_channels(), |
513 input_params.sample_rate(), | 594 input_params.sample_rate(), |
514 input_params.bits_per_sample(), | 595 input_params.bits_per_sample(), |
515 input_params.frames_per_buffer(), | 596 input_params.frames_per_buffer(), |
516 effects); | 597 effects); |
517 return params; | 598 return params; |
518 } | 599 } |
519 | 600 |
| 601 void MakeAISOnAudioThread(const AudioParameters& params) { |
| 602 RunOnAudioThread( |
| 603 base::Bind(&AudioAndroidInputTest::MakeInputStream, |
| 604 base::Unretained(this), |
| 605 params)); |
| 606 } |
| 607 |
| 608 void OpenAndCloseAISOnAudioThread() { |
| 609 RunOnAudioThread( |
| 610 base::Bind(&AudioAndroidInputTest::OpenAndClose, |
| 611 base::Unretained(this))); |
| 612 } |
| 613 |
| 614 void OpenAndStartAISOnAudioThread( |
| 615 AudioInputStream::AudioInputCallback* sink) { |
| 616 RunOnAudioThread( |
| 617 base::Bind(&AudioAndroidInputTest::OpenAndStart, |
| 618 base::Unretained(this), |
| 619 sink)); |
| 620 } |
| 621 |
| 622 void StopAndCloseAISOnAudioThread() { |
| 623 RunOnAudioThread( |
| 624 base::Bind(&AudioAndroidInputTest::StopAndClose, |
| 625 base::Unretained(this))); |
| 626 } |
| 627 |
520 void StartInputStreamCallbacks(const AudioParameters& params) { | 628 void StartInputStreamCallbacks(const AudioParameters& params) { |
521 double expected_time_between_callbacks_ms = | 629 double expected_time_between_callbacks_ms = |
522 ExpectedTimeBetweenCallbacks(params); | 630 ExpectedTimeBetweenCallbacks(params); |
523 const int num_callbacks = | 631 const int num_callbacks = |
524 (kCallbackTestTimeMs / expected_time_between_callbacks_ms); | 632 (kCallbackTestTimeMs / expected_time_between_callbacks_ms); |
525 AudioInputStream* stream = audio_manager()->MakeAudioInputStream( | 633 |
526 params, AudioManagerBase::kDefaultDeviceId); | 634 MakeAISOnAudioThread(params); |
527 EXPECT_TRUE(stream); | |
528 | 635 |
529 int count = 0; | 636 int count = 0; |
530 MockAudioInputCallback sink; | 637 MockAudioInputCallback sink; |
531 | 638 |
532 EXPECT_CALL(sink, | 639 EXPECT_CALL(sink, |
533 OnData(stream, NotNull(), params.GetBytesPerBuffer(), _, _)) | 640 OnData(audio_input_stream(), |
| 641 NotNull(), |
| 642 params. |
| 643 GetBytesPerBuffer(), _, _)) |
534 .Times(AtLeast(num_callbacks)) | 644 .Times(AtLeast(num_callbacks)) |
535 .WillRepeatedly( | 645 .WillRepeatedly( |
536 CheckCountAndPostQuitTask(&count, num_callbacks, loop())); | 646 CheckCountAndPostQuitTask(&count, num_callbacks, loop())); |
537 EXPECT_CALL(sink, OnError(stream)).Times(0); | 647 EXPECT_CALL(sink, OnError(audio_input_stream())).Times(0); |
538 | 648 |
539 EXPECT_TRUE(stream->Open()); | 649 OpenAndStartAISOnAudioThread(&sink); |
540 stream->Start(&sink); | 650 |
541 start_time_ = base::TimeTicks::Now(); | 651 start_time_ = base::TimeTicks::Now(); |
542 loop()->Run(); | 652 loop()->Run(); |
543 end_time_ = base::TimeTicks::Now(); | 653 end_time_ = base::TimeTicks::Now(); |
544 stream->Stop(); | 654 |
545 stream->Close(); | 655 StopAndCloseAISOnAudioThread(); |
546 | 656 |
547 double average_time_between_callbacks_ms = | 657 double average_time_between_callbacks_ms = |
548 AverageTimeBetweenCallbacks(num_callbacks); | 658 AverageTimeBetweenCallbacks(num_callbacks); |
549 VLOG(0) << "expected time between callbacks: " | 659 VLOG(0) << "expected time between callbacks: " |
550 << expected_time_between_callbacks_ms << " ms"; | 660 << expected_time_between_callbacks_ms << " ms"; |
551 VLOG(0) << "average time between callbacks: " | 661 VLOG(0) << "average time between callbacks: " |
552 << average_time_between_callbacks_ms << " ms"; | 662 << average_time_between_callbacks_ms << " ms"; |
553 EXPECT_GE(average_time_between_callbacks_ms, | 663 EXPECT_GE(average_time_between_callbacks_ms, |
554 0.70 * expected_time_between_callbacks_ms); | 664 0.70 * expected_time_between_callbacks_ms); |
555 EXPECT_LE(average_time_between_callbacks_ms, | 665 EXPECT_LE(average_time_between_callbacks_ms, |
556 1.30 * expected_time_between_callbacks_ms); | 666 1.30 * expected_time_between_callbacks_ms); |
557 } | 667 } |
558 | 668 |
| 669 void MakeInputStream(const AudioParameters& params) { |
| 670 DCHECK(audio_manager()->GetTaskRunner()->BelongsToCurrentThread()); |
| 671 audio_input_stream_ = audio_manager()->MakeAudioInputStream( |
| 672 params, AudioManagerBase::kDefaultDeviceId); |
| 673 EXPECT_TRUE(audio_input_stream_); |
| 674 } |
| 675 |
| 676 void OpenAndClose() { |
| 677 DCHECK(audio_manager()->GetTaskRunner()->BelongsToCurrentThread()); |
| 678 EXPECT_TRUE(audio_input_stream()->Open()); |
| 679 audio_input_stream()->Close(); |
| 680 } |
| 681 |
| 682 void OpenAndStart(AudioInputStream::AudioInputCallback* sink) { |
| 683 DCHECK(audio_manager()->GetTaskRunner()->BelongsToCurrentThread()); |
| 684 EXPECT_TRUE(audio_input_stream()->Open()); |
| 685 audio_input_stream()->Start(sink); |
| 686 } |
| 687 |
| 688 void StopAndClose() { |
| 689 DCHECK(audio_manager()->GetTaskRunner()->BelongsToCurrentThread()); |
| 690 audio_input_stream()->Stop(); |
| 691 audio_input_stream()->Close(); |
| 692 } |
559 | 693 |
560 private: | 694 private: |
| 695 AudioInputStream* audio_input_stream_; |
561 DISALLOW_COPY_AND_ASSIGN(AudioAndroidInputTest); | 696 DISALLOW_COPY_AND_ASSIGN(AudioAndroidInputTest); |
562 }; | 697 }; |
563 | 698 |
564 // Get the default audio input parameters and log the result. | 699 // Get the default audio input parameters and log the result. |
565 TEST_P(AudioAndroidInputTest, GetDefaultInputStreamParameters) { | 700 TEST_P(AudioAndroidInputTest, GetDefaultInputStreamParameters) { |
566 // We don't go through AudioAndroidInputTest::GetInputStreamParameters() here | 701 // We don't go through AudioAndroidInputTest::GetInputStreamParameters() here |
567 // so that we can log the real (non-overridden) values of the effects. | 702 // so that we can log the real (non-overridden) values of the effects. |
568 AudioParameters params = audio_manager()->GetInputStreamParameters( | 703 AudioParameters params = audio_manager()->GetInputStreamParameters( |
569 AudioManagerBase::kDefaultDeviceId); | 704 AudioManagerBase::kDefaultDeviceId); |
570 EXPECT_TRUE(params.IsValid()); | 705 EXPECT_TRUE(params.IsValid()); |
571 VLOG(1) << params; | 706 VLOG(1) << params; |
572 } | 707 } |
573 | 708 |
574 // Get the default audio output parameters and log the result. | 709 // Get the default audio output parameters and log the result. |
575 TEST_F(AudioAndroidOutputTest, GetDefaultOutputStreamParameters) { | 710 TEST_F(AudioAndroidOutputTest, GetDefaultOutputStreamParameters) { |
576 AudioParameters params = GetDefaultOutputStreamParameters(); | 711 AudioParameters params = GetDefaultOutputStreamParameters(); |
577 EXPECT_TRUE(params.IsValid()); | 712 EXPECT_TRUE(params.IsValid()); |
578 VLOG(1) << params; | 713 VLOG(1) << params; |
579 } | 714 } |
580 | 715 |
581 // Check if low-latency output is supported and log the result as output. | |
582 TEST_F(AudioAndroidOutputTest, IsAudioLowLatencySupported) { | |
583 AudioManagerAndroid* manager = | |
584 static_cast<AudioManagerAndroid*>(audio_manager()); | |
585 bool low_latency = manager->IsAudioLowLatencySupported(); | |
586 low_latency ? VLOG(0) << "Low latency output is supported" | |
587 : VLOG(0) << "Low latency output is *not* supported"; | |
588 } | |
589 | |
590 // Verify input device enumeration. | 716 // Verify input device enumeration. |
| 717 // GetAudioInputDeviceNames() is mainly called from a dedicated device thread |
| 718 // in Chrome but perform the test on the main thread here. The call will be |
| 719 // sent to the audio thread in AudioManagerAndroid::GetAudioInputDeviceNames(). |
591 TEST_F(AudioAndroidInputTest, GetAudioInputDeviceNames) { | 720 TEST_F(AudioAndroidInputTest, GetAudioInputDeviceNames) { |
592 if (!audio_manager()->HasAudioInputDevices()) | 721 if (!audio_manager()->HasAudioInputDevices()) |
593 return; | 722 return; |
594 AudioDeviceNames devices; | 723 AudioDeviceNames devices; |
595 audio_manager()->GetAudioInputDeviceNames(&devices); | 724 audio_manager()->GetAudioInputDeviceNames(&devices); |
596 CheckDeviceNames(devices); | 725 CheckDeviceNames(devices); |
597 } | 726 } |
598 | 727 |
599 // Verify output device enumeration. | 728 // Verify output device enumeration. |
600 TEST_F(AudioAndroidOutputTest, GetAudioOutputDeviceNames) { | 729 TEST_F(AudioAndroidOutputTest, GetAudioOutputDeviceNames) { |
601 if (!audio_manager()->HasAudioOutputDevices()) | 730 if (!audio_manager()->HasAudioOutputDevices()) |
602 return; | 731 return; |
603 AudioDeviceNames devices; | 732 AudioDeviceNames devices; |
604 audio_manager()->GetAudioOutputDeviceNames(&devices); | 733 audio_manager()->GetAudioOutputDeviceNames(&devices); |
605 CheckDeviceNames(devices); | 734 CheckDeviceNames(devices); |
606 } | 735 } |
607 | 736 |
608 // Ensure that a default input stream can be created and closed. | 737 // Ensure that a default input stream can be created and closed. |
609 TEST_P(AudioAndroidInputTest, CreateAndCloseInputStream) { | 738 TEST_P(AudioAndroidInputTest, CreateAndCloseInputStream) { |
610 AudioParameters params = GetInputStreamParameters(); | 739 AudioParameters params = GetInputStreamParameters(); |
611 AudioInputStream* ais = audio_manager()->MakeAudioInputStream( | 740 MakeAISOnAudioThread(params); |
612 params, AudioManagerBase::kDefaultDeviceId); | 741 RunOnAudioThread( |
613 EXPECT_TRUE(ais); | 742 base::Bind(&AudioInputStream::Close, |
614 ais->Close(); | 743 base::Unretained(audio_input_stream()))); |
615 } | 744 } |
616 | 745 |
617 // Ensure that a default output stream can be created and closed. | 746 // Ensure that a default output stream can be created and closed. |
618 // TODO(henrika): should we also verify that this API changes the audio mode | 747 // TODO(henrika): should we also verify that this API changes the audio mode |
619 // to communication mode, and calls RegisterHeadsetReceiver, the first time | 748 // to communication mode, and calls RegisterHeadsetReceiver, the first time |
620 // it is called? | 749 // it is called? |
621 TEST_F(AudioAndroidOutputTest, CreateAndCloseOutputStream) { | 750 TEST_F(AudioAndroidOutputTest, CreateAndCloseOutputStream) { |
622 AudioParameters params = GetDefaultOutputStreamParameters(); | 751 AudioParameters params = GetDefaultOutputStreamParameters(); |
623 AudioOutputStream* aos = audio_manager()->MakeAudioOutputStream( | 752 MakeAOSOnAudioThread(params); |
624 params, std::string(), std::string()); | 753 RunOnAudioThread( |
625 EXPECT_TRUE(aos); | 754 base::Bind(&AudioOutputStream::Close, |
626 aos->Close(); | 755 base::Unretained(audio_output_stream()))); |
627 } | 756 } |
628 | 757 |
629 // Ensure that a default input stream can be opened and closed. | 758 // Ensure that a default input stream can be opened and closed. |
630 TEST_P(AudioAndroidInputTest, OpenAndCloseInputStream) { | 759 TEST_P(AudioAndroidInputTest, OpenAndCloseInputStream) { |
631 AudioParameters params = GetInputStreamParameters(); | 760 AudioParameters params = GetInputStreamParameters(); |
632 AudioInputStream* ais = audio_manager()->MakeAudioInputStream( | 761 MakeAISOnAudioThread(params); |
633 params, AudioManagerBase::kDefaultDeviceId); | 762 OpenAndCloseAISOnAudioThread(); |
634 EXPECT_TRUE(ais); | |
635 EXPECT_TRUE(ais->Open()); | |
636 ais->Close(); | |
637 } | 763 } |
638 | 764 |
639 // Ensure that a default output stream can be opened and closed. | 765 // Ensure that a default output stream can be opened and closed. |
640 TEST_F(AudioAndroidOutputTest, OpenAndCloseOutputStream) { | 766 TEST_F(AudioAndroidOutputTest, OpenAndCloseOutputStream) { |
641 AudioParameters params = GetDefaultOutputStreamParameters(); | 767 AudioParameters params = GetDefaultOutputStreamParameters(); |
642 AudioOutputStream* aos = audio_manager()->MakeAudioOutputStream( | 768 MakeAOSOnAudioThread(params); |
643 params, std::string(), std::string()); | 769 OpenAndCloseAOSOnAudioThread(); |
644 EXPECT_TRUE(aos); | |
645 EXPECT_TRUE(aos->Open()); | |
646 aos->Close(); | |
647 } | 770 } |
648 | 771 |
649 // Start input streaming using default input parameters and ensure that the | 772 // Start input streaming using default input parameters and ensure that the |
650 // callback sequence is sane. | 773 // callback sequence is sane. |
651 // Disabled per crbug/337867 | 774 TEST_P(AudioAndroidInputTest, StartInputStreamCallbacks) { |
652 TEST_P(AudioAndroidInputTest, DISABLED_StartInputStreamCallbacks) { | 775 AudioParameters native_params = GetInputStreamParameters(); |
653 AudioParameters params = GetInputStreamParameters(); | 776 StartInputStreamCallbacks(native_params); |
654 StartInputStreamCallbacks(params); | |
655 } | 777 } |
656 | 778 |
657 // Start input streaming using non default input parameters and ensure that the | 779 // Start input streaming using non default input parameters and ensure that the |
658 // callback sequence is sane. The only change we make in this test is to select | 780 // callback sequence is sane. The only change we make in this test is to select |
659 // a 10ms buffer size instead of the default size. | 781 // a 10ms buffer size instead of the default size. |
660 // TODO(henrika): possibly add support for more variations. | 782 TEST_P(AudioAndroidInputTest, StartInputStreamCallbacksNonDefaultParameters) { |
661 // Disabled per crbug/337867 | |
662 TEST_P(AudioAndroidInputTest, DISABLED_StartInputStreamCallbacksNonDefaultParame
ters) { | |
663 AudioParameters native_params = GetInputStreamParameters(); | 783 AudioParameters native_params = GetInputStreamParameters(); |
664 AudioParameters params(native_params.format(), | 784 AudioParameters params(native_params.format(), |
665 native_params.channel_layout(), | 785 native_params.channel_layout(), |
666 native_params.input_channels(), | 786 native_params.input_channels(), |
667 native_params.sample_rate(), | 787 native_params.sample_rate(), |
668 native_params.bits_per_sample(), | 788 native_params.bits_per_sample(), |
669 native_params.sample_rate() / 100, | 789 native_params.sample_rate() / 100, |
670 native_params.effects()); | 790 native_params.effects()); |
671 StartInputStreamCallbacks(params); | 791 StartInputStreamCallbacks(params); |
672 } | 792 } |
(...skipping 20 matching lines...) Expand all Loading... |
693 StartOutputStreamCallbacks(params); | 813 StartOutputStreamCallbacks(params); |
694 } | 814 } |
695 | 815 |
696 // Play out a PCM file segment in real time and allow the user to verify that | 816 // Play out a PCM file segment in real time and allow the user to verify that |
697 // the rendered audio sounds OK. | 817 // the rendered audio sounds OK. |
698 // NOTE: this test requires user interaction and is not designed to run as an | 818 // NOTE: this test requires user interaction and is not designed to run as an |
699 // automatized test on bots. | 819 // automatized test on bots. |
700 TEST_F(AudioAndroidOutputTest, DISABLED_RunOutputStreamWithFileAsSource) { | 820 TEST_F(AudioAndroidOutputTest, DISABLED_RunOutputStreamWithFileAsSource) { |
701 AudioParameters params = GetDefaultOutputStreamParameters(); | 821 AudioParameters params = GetDefaultOutputStreamParameters(); |
702 VLOG(1) << params; | 822 VLOG(1) << params; |
703 AudioOutputStream* aos = audio_manager()->MakeAudioOutputStream( | 823 MakeAOSOnAudioThread(params); |
704 params, std::string(), std::string()); | |
705 EXPECT_TRUE(aos); | |
706 | 824 |
707 std::string file_name; | 825 std::string file_name; |
708 if (params.sample_rate() == 48000 && params.channels() == 2) { | 826 if (params.sample_rate() == 48000 && params.channels() == 2) { |
709 file_name = kSpeechFile_16b_s_48k; | 827 file_name = kSpeechFile_16b_s_48k; |
710 } else if (params.sample_rate() == 48000 && params.channels() == 1) { | 828 } else if (params.sample_rate() == 48000 && params.channels() == 1) { |
711 file_name = kSpeechFile_16b_m_48k; | 829 file_name = kSpeechFile_16b_m_48k; |
712 } else if (params.sample_rate() == 44100 && params.channels() == 2) { | 830 } else if (params.sample_rate() == 44100 && params.channels() == 2) { |
713 file_name = kSpeechFile_16b_s_44k; | 831 file_name = kSpeechFile_16b_s_44k; |
714 } else if (params.sample_rate() == 44100 && params.channels() == 1) { | 832 } else if (params.sample_rate() == 44100 && params.channels() == 1) { |
715 file_name = kSpeechFile_16b_m_44k; | 833 file_name = kSpeechFile_16b_m_44k; |
716 } else { | 834 } else { |
717 FAIL() << "This test supports 44.1kHz and 48kHz mono/stereo only."; | 835 FAIL() << "This test supports 44.1kHz and 48kHz mono/stereo only."; |
718 return; | 836 return; |
719 } | 837 } |
720 | 838 |
721 base::WaitableEvent event(false, false); | 839 base::WaitableEvent event(false, false); |
722 FileAudioSource source(&event, file_name); | 840 FileAudioSource source(&event, file_name); |
723 | 841 |
724 EXPECT_TRUE(aos->Open()); | 842 OpenAndStartAOSOnAudioThread(&source); |
725 aos->SetVolume(1.0); | |
726 aos->Start(&source); | |
727 VLOG(0) << ">> Verify that the file is played out correctly..."; | 843 VLOG(0) << ">> Verify that the file is played out correctly..."; |
728 EXPECT_TRUE(event.TimedWait(TestTimeouts::action_max_timeout())); | 844 EXPECT_TRUE(event.TimedWait(TestTimeouts::action_max_timeout())); |
729 aos->Stop(); | 845 StopAndCloseAOSOnAudioThread(); |
730 aos->Close(); | |
731 } | 846 } |
732 | 847 |
733 // Start input streaming and run it for ten seconds while recording to a | 848 // Start input streaming and run it for ten seconds while recording to a |
734 // local audio file. | 849 // local audio file. |
735 // NOTE: this test requires user interaction and is not designed to run as an | 850 // NOTE: this test requires user interaction and is not designed to run as an |
736 // automatized test on bots. | 851 // automatized test on bots. |
737 TEST_P(AudioAndroidInputTest, DISABLED_RunSimplexInputStreamWithFileAsSink) { | 852 TEST_P(AudioAndroidInputTest, DISABLED_RunSimplexInputStreamWithFileAsSink) { |
738 AudioParameters params = GetInputStreamParameters(); | 853 AudioParameters params = GetInputStreamParameters(); |
739 VLOG(1) << params; | 854 VLOG(1) << params; |
740 AudioInputStream* ais = audio_manager()->MakeAudioInputStream( | 855 MakeAISOnAudioThread(params); |
741 params, AudioManagerBase::kDefaultDeviceId); | |
742 EXPECT_TRUE(ais); | |
743 | 856 |
744 std::string file_name = base::StringPrintf("out_simplex_%d_%d_%d.pcm", | 857 std::string file_name = base::StringPrintf("out_simplex_%d_%d_%d.pcm", |
745 params.sample_rate(), | 858 params.sample_rate(), |
746 params.frames_per_buffer(), | 859 params.frames_per_buffer(), |
747 params.channels()); | 860 params.channels()); |
748 | 861 |
749 base::WaitableEvent event(false, false); | 862 base::WaitableEvent event(false, false); |
750 FileAudioSink sink(&event, params, file_name); | 863 FileAudioSink sink(&event, params, file_name); |
751 | 864 |
752 EXPECT_TRUE(ais->Open()); | 865 OpenAndStartAISOnAudioThread(&sink); |
753 ais->Start(&sink); | |
754 VLOG(0) << ">> Speak into the microphone to record audio..."; | 866 VLOG(0) << ">> Speak into the microphone to record audio..."; |
755 EXPECT_TRUE(event.TimedWait(TestTimeouts::action_max_timeout())); | 867 EXPECT_TRUE(event.TimedWait(TestTimeouts::action_max_timeout())); |
756 ais->Stop(); | 868 StopAndCloseAISOnAudioThread(); |
757 ais->Close(); | |
758 } | 869 } |
759 | 870 |
760 // Same test as RunSimplexInputStreamWithFileAsSink but this time output | 871 // Same test as RunSimplexInputStreamWithFileAsSink but this time output |
761 // streaming is active as well (reads zeros only). | 872 // streaming is active as well (reads zeros only). |
762 // NOTE: this test requires user interaction and is not designed to run as an | 873 // NOTE: this test requires user interaction and is not designed to run as an |
763 // automatized test on bots. | 874 // automatized test on bots. |
764 TEST_P(AudioAndroidInputTest, DISABLED_RunDuplexInputStreamWithFileAsSink) { | 875 TEST_P(AudioAndroidInputTest, DISABLED_RunDuplexInputStreamWithFileAsSink) { |
765 AudioParameters in_params = GetInputStreamParameters(); | 876 AudioParameters in_params = GetInputStreamParameters(); |
766 AudioInputStream* ais = audio_manager()->MakeAudioInputStream( | 877 VLOG(1) << in_params; |
767 in_params, AudioManagerBase::kDefaultDeviceId); | 878 MakeAISOnAudioThread(in_params); |
768 EXPECT_TRUE(ais); | |
769 | 879 |
770 AudioParameters out_params = | 880 AudioParameters out_params = |
771 audio_manager()->GetDefaultOutputStreamParameters(); | 881 audio_manager()->GetDefaultOutputStreamParameters(); |
772 AudioOutputStream* aos = audio_manager()->MakeAudioOutputStream( | 882 VLOG(1) << out_params; |
773 out_params, std::string(), std::string()); | 883 MakeAOSOnAudioThread(out_params); |
774 EXPECT_TRUE(aos); | |
775 | 884 |
776 std::string file_name = base::StringPrintf("out_duplex_%d_%d_%d.pcm", | 885 std::string file_name = base::StringPrintf("out_duplex_%d_%d_%d.pcm", |
777 in_params.sample_rate(), | 886 in_params.sample_rate(), |
778 in_params.frames_per_buffer(), | 887 in_params.frames_per_buffer(), |
779 in_params.channels()); | 888 in_params.channels()); |
780 | 889 |
781 base::WaitableEvent event(false, false); | 890 base::WaitableEvent event(false, false); |
782 FileAudioSink sink(&event, in_params, file_name); | 891 FileAudioSink sink(&event, in_params, file_name); |
783 MockAudioSourceCallback source; | 892 MockAudioSourceCallback source; |
784 | 893 |
785 EXPECT_CALL(source, OnMoreData(NotNull(), _)) | 894 EXPECT_CALL(source, OnMoreData(NotNull(), _)) |
786 .WillRepeatedly(Invoke(RealOnMoreData)); | 895 .WillRepeatedly(Invoke(RealOnMoreData)); |
787 EXPECT_CALL(source, OnError(aos)).Times(0); | 896 EXPECT_CALL(source, OnError(audio_output_stream())).Times(0); |
788 EXPECT_CALL(source, OnMoreIOData(_, _, _)).Times(0); | 897 EXPECT_CALL(source, OnMoreIOData(_, _, _)).Times(0); |
789 | 898 |
790 EXPECT_TRUE(ais->Open()); | 899 OpenAndStartAISOnAudioThread(&sink); |
791 EXPECT_TRUE(aos->Open()); | 900 OpenAndStartAOSOnAudioThread(&source); |
792 ais->Start(&sink); | |
793 aos->Start(&source); | |
794 VLOG(0) << ">> Speak into the microphone to record audio"; | 901 VLOG(0) << ">> Speak into the microphone to record audio"; |
795 EXPECT_TRUE(event.TimedWait(TestTimeouts::action_max_timeout())); | 902 EXPECT_TRUE(event.TimedWait(TestTimeouts::action_max_timeout())); |
796 aos->Stop(); | 903 StopAndCloseAOSOnAudioThread(); |
797 ais->Stop(); | 904 StopAndCloseAISOnAudioThread(); |
798 aos->Close(); | |
799 ais->Close(); | |
800 } | 905 } |
801 | 906 |
802 // Start audio in both directions while feeding captured data into a FIFO so | 907 // Start audio in both directions while feeding captured data into a FIFO so |
803 // it can be read directly (in loopback) by the render side. A small extra | 908 // it can be read directly (in loopback) by the render side. A small extra |
804 // delay will be added by the FIFO and an estimate of this delay will be | 909 // delay will be added by the FIFO and an estimate of this delay will be |
805 // printed out during the test. | 910 // printed out during the test. |
806 // NOTE: this test requires user interaction and is not designed to run as an | 911 // NOTE: this test requires user interaction and is not designed to run as an |
807 // automatized test on bots. | 912 // automatized test on bots. |
808 TEST_P(AudioAndroidInputTest, | 913 TEST_P(AudioAndroidInputTest, |
809 DISABLED_RunSymmetricInputAndOutputStreamsInFullDuplex) { | 914 DISABLED_RunSymmetricInputAndOutputStreamsInFullDuplex) { |
810 // Get native audio parameters for the input side. | 915 // Get native audio parameters for the input side. |
811 AudioParameters default_input_params = GetInputStreamParameters(); | 916 AudioParameters default_input_params = GetInputStreamParameters(); |
812 | 917 |
813 // Modify the parameters so that both input and output can use the same | 918 // Modify the parameters so that both input and output can use the same |
814 // parameters by selecting 10ms as buffer size. This will also ensure that | 919 // parameters by selecting 10ms as buffer size. This will also ensure that |
815 // the output stream will be a mono stream since mono is default for input | 920 // the output stream will be a mono stream since mono is default for input |
816 // audio on Android. | 921 // audio on Android. |
817 AudioParameters io_params(default_input_params.format(), | 922 AudioParameters io_params(default_input_params.format(), |
818 default_input_params.channel_layout(), | 923 default_input_params.channel_layout(), |
819 ChannelLayoutToChannelCount( | 924 ChannelLayoutToChannelCount( |
820 default_input_params.channel_layout()), | 925 default_input_params.channel_layout()), |
821 default_input_params.sample_rate(), | 926 default_input_params.sample_rate(), |
822 default_input_params.bits_per_sample(), | 927 default_input_params.bits_per_sample(), |
823 default_input_params.sample_rate() / 100, | 928 default_input_params.sample_rate() / 100, |
824 default_input_params.effects()); | 929 default_input_params.effects()); |
825 VLOG(1) << io_params; | 930 VLOG(1) << io_params; |
826 | 931 |
827 // Create input and output streams using the common audio parameters. | 932 // Create input and output streams using the common audio parameters. |
828 AudioInputStream* ais = audio_manager()->MakeAudioInputStream( | 933 MakeAISOnAudioThread(io_params); |
829 io_params, AudioManagerBase::kDefaultDeviceId); | 934 MakeAOSOnAudioThread(io_params); |
830 EXPECT_TRUE(ais); | |
831 AudioOutputStream* aos = audio_manager()->MakeAudioOutputStream( | |
832 io_params, std::string(), std::string()); | |
833 EXPECT_TRUE(aos); | |
834 | 935 |
835 FullDuplexAudioSinkSource full_duplex(io_params); | 936 FullDuplexAudioSinkSource full_duplex(io_params); |
836 | 937 |
837 // Start a full duplex audio session and print out estimates of the extra | 938 // Start a full duplex audio session and print out estimates of the extra |
838 // delay we should expect from the FIFO. If real-time delay measurements are | 939 // delay we should expect from the FIFO. If real-time delay measurements are |
839 // performed, the result should be reduced by this extra delay since it is | 940 // performed, the result should be reduced by this extra delay since it is |
840 // something that has been added by the test. | 941 // something that has been added by the test. |
841 EXPECT_TRUE(ais->Open()); | 942 OpenAndStartAISOnAudioThread(&full_duplex); |
842 EXPECT_TRUE(aos->Open()); | 943 OpenAndStartAOSOnAudioThread(&full_duplex); |
843 ais->Start(&full_duplex); | |
844 aos->Start(&full_duplex); | |
845 VLOG(1) << "HINT: an estimate of the extra FIFO delay will be updated " | 944 VLOG(1) << "HINT: an estimate of the extra FIFO delay will be updated " |
846 << "once per second during this test."; | 945 << "once per second during this test."; |
847 VLOG(0) << ">> Speak into the mic and listen to the audio in loopback..."; | 946 VLOG(0) << ">> Speak into the mic and listen to the audio in loopback..."; |
848 fflush(stdout); | 947 fflush(stdout); |
849 base::PlatformThread::Sleep(base::TimeDelta::FromSeconds(20)); | 948 base::PlatformThread::Sleep(base::TimeDelta::FromSeconds(20)); |
850 printf("\n"); | 949 printf("\n"); |
851 aos->Stop(); | 950 StopAndCloseAOSOnAudioThread(); |
852 ais->Stop(); | 951 StopAndCloseAISOnAudioThread(); |
853 aos->Close(); | |
854 ais->Close(); | |
855 } | 952 } |
856 | 953 |
857 INSTANTIATE_TEST_CASE_P(AudioAndroidInputTest, AudioAndroidInputTest, | 954 INSTANTIATE_TEST_CASE_P(AudioAndroidInputTest, AudioAndroidInputTest, |
858 testing::ValuesIn(RunAudioRecordInputPathTests())); | 955 testing::ValuesIn(RunAudioRecordInputPathTests())); |
859 | 956 |
860 } // namespace media | 957 } // namespace media |
OLD | NEW |