| 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 <stdint.h> | 5 #include <stdint.h> |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 | 8 |
| 9 #include "base/android/build_info.h" | 9 #include "base/android/build_info.h" |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| 11 #include "base/files/file_util.h" | 11 #include "base/files/file_util.h" |
| 12 #include "base/macros.h" | 12 #include "base/macros.h" |
| 13 #include "base/message_loop/message_loop.h" | 13 #include "base/message_loop/message_loop.h" |
| 14 #include "base/path_service.h" | 14 #include "base/path_service.h" |
| 15 #include "base/run_loop.h" | 15 #include "base/run_loop.h" |
| 16 #include "base/strings/stringprintf.h" | 16 #include "base/strings/stringprintf.h" |
| 17 #include "base/synchronization/lock.h" | 17 #include "base/synchronization/lock.h" |
| 18 #include "base/synchronization/waitable_event.h" | 18 #include "base/synchronization/waitable_event.h" |
| 19 #include "base/test/test_timeouts.h" | 19 #include "base/test/test_timeouts.h" |
| 20 #include "base/threading/thread_task_runner_handle.h" | 20 #include "base/threading/thread_task_runner_handle.h" |
| 21 #include "base/time/time.h" | 21 #include "base/time/time.h" |
| 22 #include "build/build_config.h" | 22 #include "build/build_config.h" |
| 23 #include "media/audio/android/audio_manager_android.h" | 23 #include "media/audio/android/audio_manager_android.h" |
| 24 #include "media/audio/audio_device_description.h" | 24 #include "media/audio/audio_device_description.h" |
| 25 #include "media/audio/audio_device_info_accessor_for_tests.h" |
| 25 #include "media/audio/audio_io.h" | 26 #include "media/audio/audio_io.h" |
| 26 #include "media/audio/audio_unittest_util.h" | 27 #include "media/audio/audio_unittest_util.h" |
| 27 #include "media/audio/mock_audio_source_callback.h" | 28 #include "media/audio/mock_audio_source_callback.h" |
| 28 #include "media/base/decoder_buffer.h" | 29 #include "media/base/decoder_buffer.h" |
| 29 #include "media/base/seekable_buffer.h" | 30 #include "media/base/seekable_buffer.h" |
| 30 #include "media/base/test_data_util.h" | 31 #include "media/base/test_data_util.h" |
| 31 #include "testing/gmock/include/gmock/gmock.h" | 32 #include "testing/gmock/include/gmock/gmock.h" |
| 32 #include "testing/gtest/include/gtest/gtest.h" | 33 #include "testing/gtest/include/gtest/gtest.h" |
| 33 | 34 |
| 34 using ::testing::_; | 35 using ::testing::_; |
| (...skipping 381 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 416 | 417 |
| 417 DISALLOW_COPY_AND_ASSIGN(FullDuplexAudioSinkSource); | 418 DISALLOW_COPY_AND_ASSIGN(FullDuplexAudioSinkSource); |
| 418 }; | 419 }; |
| 419 | 420 |
| 420 // Test fixture class for tests which only exercise the output path. | 421 // Test fixture class for tests which only exercise the output path. |
| 421 class AudioAndroidOutputTest : public testing::Test { | 422 class AudioAndroidOutputTest : public testing::Test { |
| 422 public: | 423 public: |
| 423 AudioAndroidOutputTest() | 424 AudioAndroidOutputTest() |
| 424 : loop_(new base::MessageLoopForUI()), | 425 : loop_(new base::MessageLoopForUI()), |
| 425 audio_manager_(AudioManager::CreateForTesting(loop_->task_runner())), | 426 audio_manager_(AudioManager::CreateForTesting(loop_->task_runner())), |
| 427 audio_manager_device_info_(audio_manager_.get()), |
| 426 audio_output_stream_(NULL) { | 428 audio_output_stream_(NULL) { |
| 427 // Flush the message loop to ensure that AudioManager is fully initialized. | 429 // Flush the message loop to ensure that AudioManager is fully initialized. |
| 428 base::RunLoop().RunUntilIdle(); | 430 base::RunLoop().RunUntilIdle(); |
| 429 } | 431 } |
| 430 | 432 |
| 431 ~AudioAndroidOutputTest() override { | 433 ~AudioAndroidOutputTest() override { |
| 432 audio_manager_.reset(); | 434 audio_manager_.reset(); |
| 433 base::RunLoop().RunUntilIdle(); | 435 base::RunLoop().RunUntilIdle(); |
| 434 } | 436 } |
| 435 | 437 |
| 436 protected: | 438 protected: |
| 437 AudioManager* audio_manager() { return audio_manager_.get(); } | 439 AudioManager* audio_manager() { return audio_manager_.get(); } |
| 440 AudioDeviceInfoAccessorForTests* audio_manager_device_info() { |
| 441 return &audio_manager_device_info_; |
| 442 } |
| 438 const AudioParameters& audio_output_parameters() { | 443 const AudioParameters& audio_output_parameters() { |
| 439 return audio_output_parameters_; | 444 return audio_output_parameters_; |
| 440 } | 445 } |
| 441 | 446 |
| 442 // Synchronously runs the provided callback/closure on the audio thread. | 447 // Synchronously runs the provided callback/closure on the audio thread. |
| 443 void RunOnAudioThread(const base::Closure& closure) { | 448 void RunOnAudioThread(const base::Closure& closure) { |
| 444 if (!audio_manager()->GetTaskRunner()->BelongsToCurrentThread()) { | 449 if (!audio_manager()->GetTaskRunner()->BelongsToCurrentThread()) { |
| 445 base::WaitableEvent event( | 450 base::WaitableEvent event( |
| 446 base::WaitableEvent::ResetPolicy::AUTOMATIC, | 451 base::WaitableEvent::ResetPolicy::AUTOMATIC, |
| 447 base::WaitableEvent::InitialState::NOT_SIGNALED); | 452 base::WaitableEvent::InitialState::NOT_SIGNALED); |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 538 << average_time_between_callbacks_ms << " ms"; | 543 << average_time_between_callbacks_ms << " ms"; |
| 539 EXPECT_GE(average_time_between_callbacks_ms, | 544 EXPECT_GE(average_time_between_callbacks_ms, |
| 540 0.70 * expected_time_between_callbacks_ms); | 545 0.70 * expected_time_between_callbacks_ms); |
| 541 EXPECT_LE(average_time_between_callbacks_ms, | 546 EXPECT_LE(average_time_between_callbacks_ms, |
| 542 1.50 * expected_time_between_callbacks_ms); | 547 1.50 * expected_time_between_callbacks_ms); |
| 543 } | 548 } |
| 544 | 549 |
| 545 void GetDefaultOutputStreamParameters() { | 550 void GetDefaultOutputStreamParameters() { |
| 546 DCHECK(audio_manager()->GetTaskRunner()->BelongsToCurrentThread()); | 551 DCHECK(audio_manager()->GetTaskRunner()->BelongsToCurrentThread()); |
| 547 audio_output_parameters_ = | 552 audio_output_parameters_ = |
| 548 audio_manager()->GetDefaultOutputStreamParameters(); | 553 audio_manager_device_info()->GetDefaultOutputStreamParameters(); |
| 549 EXPECT_TRUE(audio_output_parameters_.IsValid()); | 554 EXPECT_TRUE(audio_output_parameters_.IsValid()); |
| 550 } | 555 } |
| 551 | 556 |
| 552 void MakeOutputStream(const AudioParameters& params) { | 557 void MakeOutputStream(const AudioParameters& params) { |
| 553 DCHECK(audio_manager()->GetTaskRunner()->BelongsToCurrentThread()); | 558 DCHECK(audio_manager()->GetTaskRunner()->BelongsToCurrentThread()); |
| 554 audio_output_stream_ = audio_manager()->MakeAudioOutputStream( | 559 audio_output_stream_ = audio_manager()->MakeAudioOutputStream( |
| 555 params, std::string(), AudioManager::LogCallback()); | 560 params, std::string(), AudioManager::LogCallback()); |
| 556 EXPECT_TRUE(audio_output_stream_); | 561 EXPECT_TRUE(audio_output_stream_); |
| 557 } | 562 } |
| 558 | 563 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 571 | 576 |
| 572 void StopAndClose() { | 577 void StopAndClose() { |
| 573 DCHECK(audio_manager()->GetTaskRunner()->BelongsToCurrentThread()); | 578 DCHECK(audio_manager()->GetTaskRunner()->BelongsToCurrentThread()); |
| 574 audio_output_stream_->Stop(); | 579 audio_output_stream_->Stop(); |
| 575 audio_output_stream_->Close(); | 580 audio_output_stream_->Close(); |
| 576 audio_output_stream_ = NULL; | 581 audio_output_stream_ = NULL; |
| 577 } | 582 } |
| 578 | 583 |
| 579 std::unique_ptr<base::MessageLoopForUI> loop_; | 584 std::unique_ptr<base::MessageLoopForUI> loop_; |
| 580 ScopedAudioManagerPtr audio_manager_; | 585 ScopedAudioManagerPtr audio_manager_; |
| 586 AudioDeviceInfoAccessorForTests audio_manager_device_info_; |
| 581 AudioParameters audio_output_parameters_; | 587 AudioParameters audio_output_parameters_; |
| 582 AudioOutputStream* audio_output_stream_; | 588 AudioOutputStream* audio_output_stream_; |
| 583 base::TimeTicks start_time_; | 589 base::TimeTicks start_time_; |
| 584 base::TimeTicks end_time_; | 590 base::TimeTicks end_time_; |
| 585 | 591 |
| 586 private: | 592 private: |
| 587 DISALLOW_COPY_AND_ASSIGN(AudioAndroidOutputTest); | 593 DISALLOW_COPY_AND_ASSIGN(AudioAndroidOutputTest); |
| 588 }; | 594 }; |
| 589 | 595 |
| 590 // Test fixture class for tests which exercise the input path, or both input and | 596 // Test fixture class for tests which exercise the input path, or both input and |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 679 DVLOG(0) << "average time between callbacks: " | 685 DVLOG(0) << "average time between callbacks: " |
| 680 << average_time_between_callbacks_ms << " ms"; | 686 << average_time_between_callbacks_ms << " ms"; |
| 681 EXPECT_GE(average_time_between_callbacks_ms, | 687 EXPECT_GE(average_time_between_callbacks_ms, |
| 682 0.70 * expected_time_between_callbacks_ms); | 688 0.70 * expected_time_between_callbacks_ms); |
| 683 EXPECT_LE(average_time_between_callbacks_ms, | 689 EXPECT_LE(average_time_between_callbacks_ms, |
| 684 1.30 * expected_time_between_callbacks_ms); | 690 1.30 * expected_time_between_callbacks_ms); |
| 685 } | 691 } |
| 686 | 692 |
| 687 void GetDefaultInputStreamParameters() { | 693 void GetDefaultInputStreamParameters() { |
| 688 DCHECK(audio_manager()->GetTaskRunner()->BelongsToCurrentThread()); | 694 DCHECK(audio_manager()->GetTaskRunner()->BelongsToCurrentThread()); |
| 689 audio_input_parameters_ = audio_manager()->GetInputStreamParameters( | 695 audio_input_parameters_ = |
| 690 AudioDeviceDescription::kDefaultDeviceId); | 696 audio_manager_device_info()->GetInputStreamParameters( |
| 697 AudioDeviceDescription::kDefaultDeviceId); |
| 691 } | 698 } |
| 692 | 699 |
| 693 void MakeInputStream(const AudioParameters& params) { | 700 void MakeInputStream(const AudioParameters& params) { |
| 694 DCHECK(audio_manager()->GetTaskRunner()->BelongsToCurrentThread()); | 701 DCHECK(audio_manager()->GetTaskRunner()->BelongsToCurrentThread()); |
| 695 audio_input_stream_ = audio_manager()->MakeAudioInputStream( | 702 audio_input_stream_ = audio_manager()->MakeAudioInputStream( |
| 696 params, AudioDeviceDescription::kDefaultDeviceId, | 703 params, AudioDeviceDescription::kDefaultDeviceId, |
| 697 AudioManager::LogCallback()); | 704 AudioManager::LogCallback()); |
| 698 EXPECT_TRUE(audio_input_stream_); | 705 EXPECT_TRUE(audio_input_stream_); |
| 699 } | 706 } |
| 700 | 707 |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 735 } | 742 } |
| 736 | 743 |
| 737 // Get the default audio output parameters and log the result. | 744 // Get the default audio output parameters and log the result. |
| 738 TEST_F(AudioAndroidOutputTest, GetDefaultOutputStreamParameters) { | 745 TEST_F(AudioAndroidOutputTest, GetDefaultOutputStreamParameters) { |
| 739 GetDefaultOutputStreamParametersOnAudioThread(); | 746 GetDefaultOutputStreamParametersOnAudioThread(); |
| 740 DVLOG(1) << audio_output_parameters(); | 747 DVLOG(1) << audio_output_parameters(); |
| 741 } | 748 } |
| 742 | 749 |
| 743 // Verify input device enumeration. | 750 // Verify input device enumeration. |
| 744 TEST_F(AudioAndroidInputTest, GetAudioInputDeviceDescriptions) { | 751 TEST_F(AudioAndroidInputTest, GetAudioInputDeviceDescriptions) { |
| 745 ABORT_AUDIO_TEST_IF_NOT(audio_manager()->HasAudioInputDevices()); | 752 ABORT_AUDIO_TEST_IF_NOT(audio_manager_device_info()->HasAudioInputDevices()); |
| 746 AudioDeviceDescriptions devices; | 753 AudioDeviceDescriptions devices; |
| 747 RunOnAudioThread(base::Bind(&AudioManager::GetAudioInputDeviceDescriptions, | 754 RunOnAudioThread(base::Bind( |
| 748 base::Unretained(audio_manager()), &devices)); | 755 &AudioDeviceInfoAccessorForTests::GetAudioInputDeviceDescriptions, |
| 756 base::Unretained(audio_manager_device_info()), &devices)); |
| 749 CheckDeviceDescriptions(devices); | 757 CheckDeviceDescriptions(devices); |
| 750 } | 758 } |
| 751 | 759 |
| 752 // Verify output device enumeration. | 760 // Verify output device enumeration. |
| 753 TEST_F(AudioAndroidOutputTest, GetAudioOutputDeviceDescriptions) { | 761 TEST_F(AudioAndroidOutputTest, GetAudioOutputDeviceDescriptions) { |
| 754 ABORT_AUDIO_TEST_IF_NOT(audio_manager()->HasAudioOutputDevices()); | 762 ABORT_AUDIO_TEST_IF_NOT(audio_manager_device_info()->HasAudioOutputDevices()); |
| 755 AudioDeviceDescriptions devices; | 763 AudioDeviceDescriptions devices; |
| 756 RunOnAudioThread(base::Bind(&AudioManager::GetAudioOutputDeviceDescriptions, | 764 RunOnAudioThread(base::Bind( |
| 757 base::Unretained(audio_manager()), &devices)); | 765 &AudioDeviceInfoAccessorForTests::GetAudioOutputDeviceDescriptions, |
| 766 base::Unretained(audio_manager_device_info()), &devices)); |
| 758 CheckDeviceDescriptions(devices); | 767 CheckDeviceDescriptions(devices); |
| 759 } | 768 } |
| 760 | 769 |
| 761 // Ensure that a default input stream can be created and closed. | 770 // Ensure that a default input stream can be created and closed. |
| 762 TEST_P(AudioAndroidInputTest, CreateAndCloseInputStream) { | 771 TEST_P(AudioAndroidInputTest, CreateAndCloseInputStream) { |
| 763 AudioParameters params = GetInputStreamParameters(); | 772 AudioParameters params = GetInputStreamParameters(); |
| 764 MakeAudioInputStreamOnAudioThread(params); | 773 MakeAudioInputStreamOnAudioThread(params); |
| 765 RunOnAudioThread( | 774 RunOnAudioThread( |
| 766 base::Bind(&AudioInputStream::Close, | 775 base::Bind(&AudioInputStream::Close, |
| 767 base::Unretained(audio_input_stream_))); | 776 base::Unretained(audio_input_stream_))); |
| (...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 963 printf("\n"); | 972 printf("\n"); |
| 964 StopAndCloseAudioOutputStreamOnAudioThread(); | 973 StopAndCloseAudioOutputStreamOnAudioThread(); |
| 965 StopAndCloseAudioInputStreamOnAudioThread(); | 974 StopAndCloseAudioInputStreamOnAudioThread(); |
| 966 } | 975 } |
| 967 | 976 |
| 968 INSTANTIATE_TEST_CASE_P(AudioAndroidInputTest, | 977 INSTANTIATE_TEST_CASE_P(AudioAndroidInputTest, |
| 969 AudioAndroidInputTest, | 978 AudioAndroidInputTest, |
| 970 testing::Bool()); | 979 testing::Bool()); |
| 971 | 980 |
| 972 } // namespace media | 981 } // namespace media |
| OLD | NEW |