| 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/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/files/file_util.h" | 8 #include "base/files/file_util.h" |
| 9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 80 return std::string("CHANNEL_LAYOUT_UNSUPPORTED"); | 80 return std::string("CHANNEL_LAYOUT_UNSUPPORTED"); |
| 81 } | 81 } |
| 82 } | 82 } |
| 83 | 83 |
| 84 static double ExpectedTimeBetweenCallbacks(AudioParameters params) { | 84 static double ExpectedTimeBetweenCallbacks(AudioParameters params) { |
| 85 return (base::TimeDelta::FromMicroseconds( | 85 return (base::TimeDelta::FromMicroseconds( |
| 86 params.frames_per_buffer() * base::Time::kMicrosecondsPerSecond / | 86 params.frames_per_buffer() * base::Time::kMicrosecondsPerSecond / |
| 87 static_cast<double>(params.sample_rate()))).InMillisecondsF(); | 87 static_cast<double>(params.sample_rate()))).InMillisecondsF(); |
| 88 } | 88 } |
| 89 | 89 |
| 90 // Helper method which verifies that the device list starts with a valid | |
| 91 // default device name followed by non-default device names. | |
| 92 static void CheckDeviceNames(const AudioDeviceNames& device_names) { | |
| 93 DVLOG(2) << "Got " << device_names.size() << " audio devices."; | |
| 94 if (device_names.empty()) { | |
| 95 // Log a warning so we can see the status on the build bots. No need to | |
| 96 // break the test though since this does successfully test the code and | |
| 97 // some failure cases. | |
| 98 LOG(WARNING) << "No input devices detected"; | |
| 99 return; | |
| 100 } | |
| 101 | |
| 102 AudioDeviceNames::const_iterator it = device_names.begin(); | |
| 103 | |
| 104 // The first device in the list should always be the default device. | |
| 105 EXPECT_EQ(std::string(AudioManagerBase::kDefaultDeviceName), | |
| 106 it->device_name); | |
| 107 EXPECT_EQ(std::string(AudioManagerBase::kDefaultDeviceId), it->unique_id); | |
| 108 ++it; | |
| 109 | |
| 110 // Other devices should have non-empty name and id and should not contain | |
| 111 // default name or id. | |
| 112 while (it != device_names.end()) { | |
| 113 EXPECT_FALSE(it->device_name.empty()); | |
| 114 EXPECT_FALSE(it->unique_id.empty()); | |
| 115 DVLOG(2) << "Device ID(" << it->unique_id | |
| 116 << "), label: " << it->device_name; | |
| 117 EXPECT_NE(std::string(AudioManagerBase::kDefaultDeviceName), | |
| 118 it->device_name); | |
| 119 EXPECT_NE(std::string(AudioManagerBase::kDefaultDeviceId), | |
| 120 it->unique_id); | |
| 121 ++it; | |
| 122 } | |
| 123 } | |
| 124 | |
| 125 // We clear the data bus to ensure that the test does not cause noise. | 90 // We clear the data bus to ensure that the test does not cause noise. |
| 126 static int RealOnMoreData(AudioBus* dest, uint32 total_bytes_delay) { | 91 static int RealOnMoreData(AudioBus* dest, uint32 total_bytes_delay) { |
| 127 dest->Zero(); | 92 dest->Zero(); |
| 128 return dest->frames(); | 93 return dest->frames(); |
| 129 } | 94 } |
| 130 | 95 |
| 131 std::ostream& operator<<(std::ostream& os, const AudioParameters& params) { | 96 std::ostream& operator<<(std::ostream& os, const AudioParameters& params) { |
| 132 using namespace std; | 97 using namespace std; |
| 133 os << endl << "format: " << FormatToString(params.format()) << endl | 98 os << endl << "format: " << FormatToString(params.format()) << endl |
| 134 << "channel layout: " << LayoutToString(params.channel_layout()) << endl | 99 << "channel layout: " << LayoutToString(params.channel_layout()) << endl |
| (...skipping 410 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 545 audio_output_stream_->Start(source); | 510 audio_output_stream_->Start(source); |
| 546 } | 511 } |
| 547 | 512 |
| 548 void StopAndClose() { | 513 void StopAndClose() { |
| 549 DCHECK(audio_manager()->GetTaskRunner()->BelongsToCurrentThread()); | 514 DCHECK(audio_manager()->GetTaskRunner()->BelongsToCurrentThread()); |
| 550 audio_output_stream_->Stop(); | 515 audio_output_stream_->Stop(); |
| 551 audio_output_stream_->Close(); | 516 audio_output_stream_->Close(); |
| 552 audio_output_stream_ = NULL; | 517 audio_output_stream_ = NULL; |
| 553 } | 518 } |
| 554 | 519 |
| 520 // Helper method which verifies that the device list starts with a valid |
| 521 // default device name followed by non-default device names. |
| 522 void CheckDeviceNames(const AudioDeviceNames& device_names) { |
| 523 DVLOG(2) << "Got " << device_names.size() << " audio devices."; |
| 524 if (device_names.empty()) { |
| 525 // Log a warning so we can see the status on the build bots. No need to |
| 526 // break the test though since this does successfully test the code and |
| 527 // some failure cases. |
| 528 LOG(WARNING) << "No input devices detected"; |
| 529 return; |
| 530 } |
| 531 |
| 532 AudioDeviceNames::const_iterator it = device_names.begin(); |
| 533 |
| 534 // The first device in the list should always be the default device. |
| 535 EXPECT_EQ(audio_manager()->GetDefaultDeviceName(), it->device_name); |
| 536 EXPECT_EQ(std::string(AudioManagerBase::kDefaultDeviceId), it->unique_id); |
| 537 ++it; |
| 538 |
| 539 // Other devices should have non-empty name and id and should not contain |
| 540 // default name or id. |
| 541 while (it != device_names.end()) { |
| 542 EXPECT_FALSE(it->device_name.empty()); |
| 543 EXPECT_FALSE(it->unique_id.empty()); |
| 544 DVLOG(2) << "Device ID(" << it->unique_id |
| 545 << "), label: " << it->device_name; |
| 546 EXPECT_NE(audio_manager()->GetDefaultDeviceName(), it->device_name); |
| 547 EXPECT_NE(std::string(AudioManagerBase::kDefaultDeviceId), it->unique_id); |
| 548 ++it; |
| 549 } |
| 550 } |
| 551 |
| 555 scoped_ptr<base::MessageLoopForUI> loop_; | 552 scoped_ptr<base::MessageLoopForUI> loop_; |
| 556 scoped_ptr<AudioManager> audio_manager_; | 553 scoped_ptr<AudioManager> audio_manager_; |
| 557 AudioParameters audio_output_parameters_; | 554 AudioParameters audio_output_parameters_; |
| 558 AudioOutputStream* audio_output_stream_; | 555 AudioOutputStream* audio_output_stream_; |
| 559 base::TimeTicks start_time_; | 556 base::TimeTicks start_time_; |
| 560 base::TimeTicks end_time_; | 557 base::TimeTicks end_time_; |
| 561 | 558 |
| 562 private: | 559 private: |
| 563 DISALLOW_COPY_AND_ASSIGN(AudioAndroidOutputTest); | 560 DISALLOW_COPY_AND_ASSIGN(AudioAndroidOutputTest); |
| 564 }; | 561 }; |
| (...skipping 381 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 946 base::PlatformThread::Sleep(base::TimeDelta::FromSeconds(20)); | 943 base::PlatformThread::Sleep(base::TimeDelta::FromSeconds(20)); |
| 947 printf("\n"); | 944 printf("\n"); |
| 948 StopAndCloseAudioOutputStreamOnAudioThread(); | 945 StopAndCloseAudioOutputStreamOnAudioThread(); |
| 949 StopAndCloseAudioInputStreamOnAudioThread(); | 946 StopAndCloseAudioInputStreamOnAudioThread(); |
| 950 } | 947 } |
| 951 | 948 |
| 952 INSTANTIATE_TEST_CASE_P(AudioAndroidInputTest, AudioAndroidInputTest, | 949 INSTANTIATE_TEST_CASE_P(AudioAndroidInputTest, AudioAndroidInputTest, |
| 953 testing::ValuesIn(RunAudioRecordInputPathTests())); | 950 testing::ValuesIn(RunAudioRecordInputPathTests())); |
| 954 | 951 |
| 955 } // namespace media | 952 } // namespace media |
| OLD | NEW |