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() |
| 512 : event_(false, false), | |
| 513 audio_input_stream_(NULL) {} | |
| 512 | 514 |
| 513 protected: | 515 protected: |
| 516 AudioInputStream* audio_input_stream() { return audio_input_stream_; } | |
| 517 | |
| 514 AudioParameters GetInputStreamParameters() { | 518 AudioParameters GetInputStreamParameters() { |
| 515 AudioParameters input_params = audio_manager()->GetInputStreamParameters( | 519 AudioParameters input_params = audio_manager()->GetInputStreamParameters( |
| 516 AudioManagerBase::kDefaultDeviceId); | 520 AudioManagerBase::kDefaultDeviceId); |
| 517 // Override the platform effects setting to use the AudioRecord or OpenSLES | 521 // Override the platform effects setting to use the AudioRecord or OpenSLES |
| 518 // path as requested. | 522 // path as requested. |
| 519 int effects = GetParam() ? AudioParameters::ECHO_CANCELLER : | 523 int effects = GetParam() ? AudioParameters::ECHO_CANCELLER : |
| 520 AudioParameters::NO_EFFECTS; | 524 AudioParameters::NO_EFFECTS; |
| 521 AudioParameters params(input_params.format(), | 525 AudioParameters params(input_params.format(), |
| 522 input_params.channel_layout(), | 526 input_params.channel_layout(), |
| 523 input_params.input_channels(), | 527 input_params.input_channels(), |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 560 VLOG(0) << "expected time between callbacks: " | 564 VLOG(0) << "expected time between callbacks: " |
| 561 << expected_time_between_callbacks_ms << " ms"; | 565 << expected_time_between_callbacks_ms << " ms"; |
| 562 VLOG(0) << "average time between callbacks: " | 566 VLOG(0) << "average time between callbacks: " |
| 563 << average_time_between_callbacks_ms << " ms"; | 567 << average_time_between_callbacks_ms << " ms"; |
| 564 EXPECT_GE(average_time_between_callbacks_ms, | 568 EXPECT_GE(average_time_between_callbacks_ms, |
| 565 0.70 * expected_time_between_callbacks_ms); | 569 0.70 * expected_time_between_callbacks_ms); |
| 566 EXPECT_LE(average_time_between_callbacks_ms, | 570 EXPECT_LE(average_time_between_callbacks_ms, |
| 567 1.30 * expected_time_between_callbacks_ms); | 571 1.30 * expected_time_between_callbacks_ms); |
| 568 } | 572 } |
| 569 | 573 |
| 574 void CreateAndCloseAISOnAudioThread(const AudioParameters& params) { | |
| 575 if (!audio_manager()->GetTaskRunner()->BelongsToCurrentThread()) { | |
| 576 audio_manager()->GetTaskRunner()->PostTask( | |
| 577 FROM_HERE, | |
| 578 base::Bind(&AudioAndroidInputTest::CreateAndCloseAISOnAudioThread, | |
| 579 base::Unretained(this), | |
| 580 params)); | |
| 581 event_.Wait(); | |
| 582 } else { | |
| 583 audio_input_stream_ = audio_manager()->MakeAudioInputStream( | |
| 584 params, AudioManagerBase::kDefaultDeviceId); | |
| 585 EXPECT_TRUE(audio_input_stream_); | |
| 586 audio_input_stream_->Close(); | |
| 587 event_.Signal(); | |
| 588 } | |
| 589 } | |
| 570 | 590 |
| 571 private: | 591 private: |
| 592 base::WaitableEvent event_; | |
|
tommi (sloooow) - chröme
2014/01/30 15:26:04
This pattern is racy and could throw TSAN off.
Cre
henrika (OOO until Aug 14)
2014/01/30 17:20:23
Uploaded new and improved version after offline di
| |
| 593 AudioInputStream* audio_input_stream_; | |
| 572 DISALLOW_COPY_AND_ASSIGN(AudioAndroidInputTest); | 594 DISALLOW_COPY_AND_ASSIGN(AudioAndroidInputTest); |
| 573 }; | 595 }; |
| 574 | 596 |
| 575 // Get the default audio input parameters and log the result. | 597 // Get the default audio input parameters and log the result. |
| 576 TEST_P(AudioAndroidInputTest, GetDefaultInputStreamParameters) { | 598 TEST_P(AudioAndroidInputTest, GetDefaultInputStreamParameters) { |
| 577 // We don't go through AudioAndroidInputTest::GetInputStreamParameters() here | 599 // We don't go through AudioAndroidInputTest::GetInputStreamParameters() here |
| 578 // so that we can log the real (non-overridden) values of the effects. | 600 // so that we can log the real (non-overridden) values of the effects. |
| 579 AudioParameters params = audio_manager()->GetInputStreamParameters( | 601 AudioParameters params = audio_manager()->GetInputStreamParameters( |
| 580 AudioManagerBase::kDefaultDeviceId); | 602 AudioManagerBase::kDefaultDeviceId); |
| 581 EXPECT_TRUE(params.IsValid()); | 603 EXPECT_TRUE(params.IsValid()); |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 612 if (!audio_manager()->HasAudioOutputDevices()) | 634 if (!audio_manager()->HasAudioOutputDevices()) |
| 613 return; | 635 return; |
| 614 AudioDeviceNames devices; | 636 AudioDeviceNames devices; |
| 615 audio_manager()->GetAudioOutputDeviceNames(&devices); | 637 audio_manager()->GetAudioOutputDeviceNames(&devices); |
| 616 CheckDeviceNames(devices); | 638 CheckDeviceNames(devices); |
| 617 } | 639 } |
| 618 | 640 |
| 619 // Ensure that a default input stream can be created and closed. | 641 // Ensure that a default input stream can be created and closed. |
| 620 TEST_P(AudioAndroidInputTest, CreateAndCloseInputStream) { | 642 TEST_P(AudioAndroidInputTest, CreateAndCloseInputStream) { |
| 621 AudioParameters params = GetInputStreamParameters(); | 643 AudioParameters params = GetInputStreamParameters(); |
| 622 AudioInputStream* ais = audio_manager()->MakeAudioInputStream( | 644 CreateAndCloseAISOnAudioThread(params); |
| 623 params, AudioManagerBase::kDefaultDeviceId); | |
| 624 EXPECT_TRUE(ais); | |
| 625 ais->Close(); | |
| 626 } | 645 } |
| 627 | 646 |
| 628 // Ensure that a default output stream can be created and closed. | 647 // 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 | 648 // TODO(henrika): should we also verify that this API changes the audio mode |
| 630 // to communication mode, and calls RegisterHeadsetReceiver, the first time | 649 // to communication mode, and calls RegisterHeadsetReceiver, the first time |
| 631 // it is called? | 650 // it is called? |
| 632 TEST_F(AudioAndroidOutputTest, CreateAndCloseOutputStream) { | 651 TEST_F(AudioAndroidOutputTest, CreateAndCloseOutputStream) { |
| 633 AudioParameters params = GetDefaultOutputStreamParameters(); | 652 AudioParameters params = GetDefaultOutputStreamParameters(); |
| 634 AudioOutputStream* aos = audio_manager()->MakeAudioOutputStream( | 653 AudioOutputStream* aos = audio_manager()->MakeAudioOutputStream( |
| 635 params, std::string(), std::string()); | 654 params, std::string(), std::string()); |
| (...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 862 aos->Stop(); | 881 aos->Stop(); |
| 863 ais->Stop(); | 882 ais->Stop(); |
| 864 aos->Close(); | 883 aos->Close(); |
| 865 ais->Close(); | 884 ais->Close(); |
| 866 } | 885 } |
| 867 | 886 |
| 868 INSTANTIATE_TEST_CASE_P(AudioAndroidInputTest, AudioAndroidInputTest, | 887 INSTANTIATE_TEST_CASE_P(AudioAndroidInputTest, AudioAndroidInputTest, |
| 869 testing::ValuesIn(RunAudioRecordInputPathTests())); | 888 testing::ValuesIn(RunAudioRecordInputPathTests())); |
| 870 | 889 |
| 871 } // namespace media | 890 } // namespace media |
| OLD | NEW |