Chromium Code Reviews| 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" |
| (...skipping 490 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 501 tests.push_back(true); | 501 tests.push_back(true); |
| 502 return tests; | 502 return tests; |
| 503 } | 503 } |
| 504 | 504 |
| 505 // Test fixture class for tests which exercise the input path, or both input and | 505 // Test fixture class for tests which exercise the input path, or both input and |
| 506 // output paths. It is value-parameterized to test against both the Java | 506 // output paths. It is value-parameterized to test against both the Java |
| 507 // AudioRecord (when true) and native OpenSLES (when false) input paths. | 507 // AudioRecord (when true) and native OpenSLES (when false) input paths. |
| 508 class AudioAndroidInputTest : public AudioAndroidOutputTest, | 508 class AudioAndroidInputTest : public AudioAndroidOutputTest, |
| 509 public testing::WithParamInterface<bool> { | 509 public testing::WithParamInterface<bool> { |
| 510 public: | 510 public: |
| 511 AudioAndroidInputTest() {} | 511 AudioAndroidInputTest() : audio_input_stream_(NULL) {} |
| 512 | 512 |
| 513 protected: | 513 protected: |
| 514 AudioInputStream* audio_input_stream() { return audio_input_stream_; } | |
| 515 | |
| 514 AudioParameters GetInputStreamParameters() { | 516 AudioParameters GetInputStreamParameters() { |
| 515 AudioParameters input_params = audio_manager()->GetInputStreamParameters( | 517 AudioParameters input_params = audio_manager()->GetInputStreamParameters( |
| 516 AudioManagerBase::kDefaultDeviceId); | 518 AudioManagerBase::kDefaultDeviceId); |
| 517 // Override the platform effects setting to use the AudioRecord or OpenSLES | 519 // Override the platform effects setting to use the AudioRecord or OpenSLES |
| 518 // path as requested. | 520 // path as requested. |
| 519 int effects = GetParam() ? AudioParameters::ECHO_CANCELLER : | 521 int effects = GetParam() ? AudioParameters::ECHO_CANCELLER : |
| 520 AudioParameters::NO_EFFECTS; | 522 AudioParameters::NO_EFFECTS; |
| 521 AudioParameters params(input_params.format(), | 523 AudioParameters params(input_params.format(), |
| 522 input_params.channel_layout(), | 524 input_params.channel_layout(), |
| 523 input_params.input_channels(), | 525 input_params.input_channels(), |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 560 VLOG(0) << "expected time between callbacks: " | 562 VLOG(0) << "expected time between callbacks: " |
| 561 << expected_time_between_callbacks_ms << " ms"; | 563 << expected_time_between_callbacks_ms << " ms"; |
| 562 VLOG(0) << "average time between callbacks: " | 564 VLOG(0) << "average time between callbacks: " |
| 563 << average_time_between_callbacks_ms << " ms"; | 565 << average_time_between_callbacks_ms << " ms"; |
| 564 EXPECT_GE(average_time_between_callbacks_ms, | 566 EXPECT_GE(average_time_between_callbacks_ms, |
| 565 0.70 * expected_time_between_callbacks_ms); | 567 0.70 * expected_time_between_callbacks_ms); |
| 566 EXPECT_LE(average_time_between_callbacks_ms, | 568 EXPECT_LE(average_time_between_callbacks_ms, |
| 567 1.30 * expected_time_between_callbacks_ms); | 569 1.30 * expected_time_between_callbacks_ms); |
| 568 } | 570 } |
| 569 | 571 |
| 572 // Calls CreateAndClose() on the audio thread. | |
| 573 void CreateAndCloseAISOnAudioThread() { | |
| 574 AudioParameters params = GetInputStreamParameters(); | |
| 575 RunOnAudioThread( | |
| 576 base::Bind(&AudioAndroidInputTest::CreateAndClose, | |
| 577 base::Unretained(this), | |
| 578 params)); | |
| 579 } | |
| 580 | |
| 581 // Calls OpenAndClose() on the audio thread. | |
| 582 void OpenAndCloseAISOnAudioThread() { | |
| 583 AudioParameters params = GetInputStreamParameters(); | |
| 584 RunOnAudioThread( | |
| 585 base::Bind(&AudioAndroidInputTest::OpenAndClose, | |
| 586 base::Unretained(this), | |
| 587 params)); | |
| 588 } | |
| 589 | |
| 590 void MakeInputStream(const AudioParameters& params) { | |
| 591 audio_input_stream_ = audio_manager()->MakeAudioInputStream( | |
| 592 params, AudioManagerBase::kDefaultDeviceId); | |
| 593 EXPECT_TRUE(audio_input_stream_); | |
| 594 } | |
| 595 | |
| 596 void CreateAndClose(const AudioParameters& params) { | |
| 597 MakeInputStream(params); | |
| 598 EXPECT_TRUE(audio_input_stream_->Open()); | |
|
tommi (sloooow) - chröme
2014/01/30 17:34:19
I think this line should be in OpenAndClose and no
henrika (OOO until Aug 14)
2014/01/31 08:06:01
Ooops ;-) Thanks.
| |
| 599 audio_input_stream_->Close(); | |
| 600 } | |
| 601 | |
| 602 void OpenAndClose(const AudioParameters& params) { | |
| 603 MakeInputStream(params); | |
| 604 audio_input_stream_->Close(); | |
| 605 } | |
| 606 | |
| 607 // Synchronously runs the provided callback/closure on the audio thread. | |
| 608 void RunOnAudioThread(const base::Closure& closure) { | |
| 609 if (!audio_manager()->GetTaskRunner()->BelongsToCurrentThread()) { | |
| 610 base::WaitableEvent event(false, false); | |
| 611 audio_manager()->GetTaskRunner()->PostTask( | |
| 612 FROM_HERE, | |
| 613 base::Bind(&AudioAndroidInputTest::RunOnAudioThreadImpl, | |
| 614 base::Unretained(this), | |
| 615 closure, | |
| 616 &event)); | |
| 617 event.Wait(); | |
| 618 } else { | |
| 619 closure.Run(); | |
| 620 } | |
| 621 } | |
| 622 | |
| 623 void RunOnAudioThreadImpl(const base::Closure& closure, | |
| 624 base::WaitableEvent* event) { | |
| 625 DCHECK(audio_manager()->GetTaskRunner()->BelongsToCurrentThread()); | |
| 626 closure.Run(); | |
| 627 event->Signal(); | |
| 628 } | |
| 570 | 629 |
| 571 private: | 630 private: |
| 631 AudioInputStream* audio_input_stream_; | |
| 572 DISALLOW_COPY_AND_ASSIGN(AudioAndroidInputTest); | 632 DISALLOW_COPY_AND_ASSIGN(AudioAndroidInputTest); |
| 573 }; | 633 }; |
| 574 | 634 |
| 575 // Get the default audio input parameters and log the result. | 635 // Get the default audio input parameters and log the result. |
| 576 TEST_P(AudioAndroidInputTest, GetDefaultInputStreamParameters) { | 636 TEST_P(AudioAndroidInputTest, GetDefaultInputStreamParameters) { |
| 577 // We don't go through AudioAndroidInputTest::GetInputStreamParameters() here | 637 // We don't go through AudioAndroidInputTest::GetInputStreamParameters() here |
| 578 // so that we can log the real (non-overridden) values of the effects. | 638 // so that we can log the real (non-overridden) values of the effects. |
| 579 AudioParameters params = audio_manager()->GetInputStreamParameters( | 639 AudioParameters params = audio_manager()->GetInputStreamParameters( |
| 580 AudioManagerBase::kDefaultDeviceId); | 640 AudioManagerBase::kDefaultDeviceId); |
| 581 EXPECT_TRUE(params.IsValid()); | 641 EXPECT_TRUE(params.IsValid()); |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 611 TEST_F(AudioAndroidOutputTest, GetAudioOutputDeviceNames) { | 671 TEST_F(AudioAndroidOutputTest, GetAudioOutputDeviceNames) { |
| 612 if (!audio_manager()->HasAudioOutputDevices()) | 672 if (!audio_manager()->HasAudioOutputDevices()) |
| 613 return; | 673 return; |
| 614 AudioDeviceNames devices; | 674 AudioDeviceNames devices; |
| 615 audio_manager()->GetAudioOutputDeviceNames(&devices); | 675 audio_manager()->GetAudioOutputDeviceNames(&devices); |
| 616 CheckDeviceNames(devices); | 676 CheckDeviceNames(devices); |
| 617 } | 677 } |
| 618 | 678 |
| 619 // Ensure that a default input stream can be created and closed. | 679 // Ensure that a default input stream can be created and closed. |
| 620 TEST_P(AudioAndroidInputTest, CreateAndCloseInputStream) { | 680 TEST_P(AudioAndroidInputTest, CreateAndCloseInputStream) { |
| 621 AudioParameters params = GetInputStreamParameters(); | 681 CreateAndCloseAISOnAudioThread(); |
| 622 AudioInputStream* ais = audio_manager()->MakeAudioInputStream( | |
| 623 params, AudioManagerBase::kDefaultDeviceId); | |
| 624 EXPECT_TRUE(ais); | |
| 625 ais->Close(); | |
| 626 } | 682 } |
| 627 | 683 |
| 628 // Ensure that a default output stream can be created and closed. | 684 // Ensure that a default output stream can be created and closed. |
| 629 // TODO(henrika): should we also verify that this API changes the audio mode | 685 // TODO(henrika): should we also verify that this API changes the audio mode |
| 630 // to communication mode, and calls RegisterHeadsetReceiver, the first time | 686 // to communication mode, and calls RegisterHeadsetReceiver, the first time |
| 631 // it is called? | 687 // it is called? |
| 632 TEST_F(AudioAndroidOutputTest, CreateAndCloseOutputStream) { | 688 TEST_F(AudioAndroidOutputTest, CreateAndCloseOutputStream) { |
| 633 AudioParameters params = GetDefaultOutputStreamParameters(); | 689 AudioParameters params = GetDefaultOutputStreamParameters(); |
| 634 AudioOutputStream* aos = audio_manager()->MakeAudioOutputStream( | 690 AudioOutputStream* aos = audio_manager()->MakeAudioOutputStream( |
| 635 params, std::string(), std::string()); | 691 params, std::string(), std::string()); |
| 636 EXPECT_TRUE(aos); | 692 EXPECT_TRUE(aos); |
| 637 aos->Close(); | 693 aos->Close(); |
| 638 } | 694 } |
| 639 | 695 |
| 640 // Ensure that a default input stream can be opened and closed. | 696 // Ensure that a default input stream can be opened and closed. |
| 641 TEST_P(AudioAndroidInputTest, OpenAndCloseInputStream) { | 697 TEST_P(AudioAndroidInputTest, OpenAndCloseInputStream) { |
| 642 AudioParameters params = GetInputStreamParameters(); | 698 OpenAndCloseAISOnAudioThread(); |
| 643 AudioInputStream* ais = audio_manager()->MakeAudioInputStream( | |
| 644 params, AudioManagerBase::kDefaultDeviceId); | |
| 645 EXPECT_TRUE(ais); | |
| 646 EXPECT_TRUE(ais->Open()); | |
| 647 ais->Close(); | |
| 648 } | 699 } |
| 649 | 700 |
| 650 // Ensure that a default output stream can be opened and closed. | 701 // Ensure that a default output stream can be opened and closed. |
| 651 TEST_F(AudioAndroidOutputTest, OpenAndCloseOutputStream) { | 702 TEST_F(AudioAndroidOutputTest, OpenAndCloseOutputStream) { |
| 652 AudioParameters params = GetDefaultOutputStreamParameters(); | 703 AudioParameters params = GetDefaultOutputStreamParameters(); |
| 653 AudioOutputStream* aos = audio_manager()->MakeAudioOutputStream( | 704 AudioOutputStream* aos = audio_manager()->MakeAudioOutputStream( |
| 654 params, std::string(), std::string()); | 705 params, std::string(), std::string()); |
| 655 EXPECT_TRUE(aos); | 706 EXPECT_TRUE(aos); |
| 656 EXPECT_TRUE(aos->Open()); | 707 EXPECT_TRUE(aos->Open()); |
| 657 aos->Close(); | 708 aos->Close(); |
| (...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 862 aos->Stop(); | 913 aos->Stop(); |
| 863 ais->Stop(); | 914 ais->Stop(); |
| 864 aos->Close(); | 915 aos->Close(); |
| 865 ais->Close(); | 916 ais->Close(); |
| 866 } | 917 } |
| 867 | 918 |
| 868 INSTANTIATE_TEST_CASE_P(AudioAndroidInputTest, AudioAndroidInputTest, | 919 INSTANTIATE_TEST_CASE_P(AudioAndroidInputTest, AudioAndroidInputTest, |
| 869 testing::ValuesIn(RunAudioRecordInputPathTests())); | 920 testing::ValuesIn(RunAudioRecordInputPathTests())); |
| 870 | 921 |
| 871 } // namespace media | 922 } // namespace media |
| OLD | NEW |