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/basictypes.h" | 5 #include "base/basictypes.h" |
| 6 #include "base/file_util.h" | 6 #include "base/file_util.h" |
| 7 #include "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
| 8 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
| 9 #include "base/path_service.h" | 9 #include "base/path_service.h" |
| 10 #include "base/strings/stringprintf.h" | 10 #include "base/strings/stringprintf.h" |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 77 return std::string("CHANNEL_LAYOUT_UNSUPPORTED"); | 77 return std::string("CHANNEL_LAYOUT_UNSUPPORTED"); |
| 78 } | 78 } |
| 79 } | 79 } |
| 80 | 80 |
| 81 static double ExpectedTimeBetweenCallbacks(AudioParameters params) { | 81 static double ExpectedTimeBetweenCallbacks(AudioParameters params) { |
| 82 return (base::TimeDelta::FromMicroseconds( | 82 return (base::TimeDelta::FromMicroseconds( |
| 83 params.frames_per_buffer() * base::Time::kMicrosecondsPerSecond / | 83 params.frames_per_buffer() * base::Time::kMicrosecondsPerSecond / |
| 84 static_cast<double>(params.sample_rate()))).InMillisecondsF(); | 84 static_cast<double>(params.sample_rate()))).InMillisecondsF(); |
| 85 } | 85 } |
| 86 | 86 |
| 87 // Helper method which verifies that the device list starts with a valid | |
| 88 // default device name followed by non-default device names. | |
| 89 static void CheckDeviceNames(const AudioDeviceNames& device_names) { | |
| 90 VLOG(2) << "Got " << device_names.size() << " audio devices."; | |
| 91 if (device_names.empty()) { | |
| 92 // Log a warning so we can see the status on the build bots. No need to | |
| 93 // break the test though since this does successfully test the code and | |
| 94 // some failure cases. | |
| 95 LOG(WARNING) << "No input devices detected"; | |
|
bulach
2013/12/13 15:17:05
nit: perhaps return here? otherwise 101 will fail,
| |
| 96 } | |
| 97 | |
| 98 AudioDeviceNames::const_iterator it = device_names.begin(); | |
| 99 | |
| 100 // The first device in the list should always be the default device. | |
| 101 EXPECT_EQ(std::string(AudioManagerBase::kDefaultDeviceName), | |
| 102 it->device_name); | |
| 103 EXPECT_EQ(std::string(AudioManagerBase::kDefaultDeviceId), it->unique_id); | |
| 104 ++it; | |
| 105 | |
| 106 // Other devices should have non-empty name and id and should not contain | |
| 107 // default name or id. | |
| 108 while (it != device_names.end()) { | |
| 109 EXPECT_FALSE(it->device_name.empty()); | |
| 110 EXPECT_FALSE(it->unique_id.empty()); | |
| 111 VLOG(2) << "Device ID(" << it->unique_id | |
| 112 << "), label: " << it->device_name; | |
| 113 EXPECT_NE(std::string(AudioManagerBase::kDefaultDeviceName), | |
| 114 it->device_name); | |
| 115 EXPECT_NE(std::string(AudioManagerBase::kDefaultDeviceId), | |
| 116 it->unique_id); | |
| 117 ++it; | |
| 118 } | |
| 119 } | |
| 120 | |
| 87 std::ostream& operator<<(std::ostream& os, const AudioParameters& params) { | 121 std::ostream& operator<<(std::ostream& os, const AudioParameters& params) { |
| 88 using namespace std; | 122 using namespace std; |
| 89 os << endl << "format: " << FormatToString(params.format()) << endl | 123 os << endl << "format: " << FormatToString(params.format()) << endl |
| 90 << "channel layout: " << LayoutToString(params.channel_layout()) << endl | 124 << "channel layout: " << LayoutToString(params.channel_layout()) << endl |
| 91 << "sample rate: " << params.sample_rate() << endl | 125 << "sample rate: " << params.sample_rate() << endl |
| 92 << "bits per sample: " << params.bits_per_sample() << endl | 126 << "bits per sample: " << params.bits_per_sample() << endl |
| 93 << "frames per buffer: " << params.frames_per_buffer() << endl | 127 << "frames per buffer: " << params.frames_per_buffer() << endl |
| 94 << "channels: " << params.channels() << endl | 128 << "channels: " << params.channels() << endl |
| 95 << "bytes per buffer: " << params.GetBytesPerBuffer() << endl | 129 << "bytes per buffer: " << params.GetBytesPerBuffer() << endl |
| 96 << "bytes per second: " << params.GetBytesPerSecond() << endl | 130 << "bytes per second: " << params.GetBytesPerSecond() << endl |
| (...skipping 420 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 517 | 551 |
| 518 // Check if low-latency output is supported and log the result as output. | 552 // Check if low-latency output is supported and log the result as output. |
| 519 TEST_F(AudioAndroidTest, IsAudioLowLatencySupported) { | 553 TEST_F(AudioAndroidTest, IsAudioLowLatencySupported) { |
| 520 AudioManagerAndroid* manager = | 554 AudioManagerAndroid* manager = |
| 521 static_cast<AudioManagerAndroid*>(audio_manager()); | 555 static_cast<AudioManagerAndroid*>(audio_manager()); |
| 522 bool low_latency = manager->IsAudioLowLatencySupported(); | 556 bool low_latency = manager->IsAudioLowLatencySupported(); |
| 523 low_latency ? VLOG(0) << "Low latency output is supported" | 557 low_latency ? VLOG(0) << "Low latency output is supported" |
| 524 : VLOG(0) << "Low latency output is *not* supported"; | 558 : VLOG(0) << "Low latency output is *not* supported"; |
| 525 } | 559 } |
| 526 | 560 |
| 561 // Verify input device enumeration. | |
| 562 TEST_F(AudioAndroidTest, GetAudioInputDeviceNames) { | |
| 563 if (!audio_manager()->HasAudioInputDevices()) | |
| 564 return; | |
| 565 AudioDeviceNames devices; | |
| 566 audio_manager()->GetAudioInputDeviceNames(&devices); | |
| 567 CheckDeviceNames(devices); | |
| 568 } | |
| 569 | |
| 570 // Verify output device enumeration. | |
| 571 TEST_F(AudioAndroidTest, GetAudioOutputDeviceNames) { | |
| 572 if (!audio_manager()->HasAudioOutputDevices()) | |
| 573 return; | |
| 574 AudioDeviceNames devices; | |
| 575 audio_manager()->GetAudioOutputDeviceNames(&devices); | |
| 576 CheckDeviceNames(devices); | |
| 577 } | |
| 578 | |
| 527 // Ensure that a default input stream can be created and closed. | 579 // Ensure that a default input stream can be created and closed. |
| 528 TEST_F(AudioAndroidTest, CreateAndCloseInputStream) { | 580 TEST_F(AudioAndroidTest, CreateAndCloseInputStream) { |
| 529 AudioParameters params = GetDefaultInputStreamParameters(); | 581 AudioParameters params = GetDefaultInputStreamParameters(); |
| 530 AudioInputStream* ais = audio_manager()->MakeAudioInputStream( | 582 AudioInputStream* ais = audio_manager()->MakeAudioInputStream( |
| 531 params, AudioManagerBase::kDefaultDeviceId); | 583 params, AudioManagerBase::kDefaultDeviceId); |
| 532 EXPECT_TRUE(ais); | 584 EXPECT_TRUE(ais); |
| 533 ais->Close(); | 585 ais->Close(); |
| 534 } | 586 } |
| 535 | 587 |
| 536 // Ensure that a default output stream can be created and closed. | 588 // Ensure that a default output stream can be created and closed. |
| (...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 760 fflush(stdout); | 812 fflush(stdout); |
| 761 base::PlatformThread::Sleep(base::TimeDelta::FromSeconds(20)); | 813 base::PlatformThread::Sleep(base::TimeDelta::FromSeconds(20)); |
| 762 printf("\n"); | 814 printf("\n"); |
| 763 aos->Stop(); | 815 aos->Stop(); |
| 764 ais->Stop(); | 816 ais->Stop(); |
| 765 aos->Close(); | 817 aos->Close(); |
| 766 ais->Close(); | 818 ais->Close(); |
| 767 } | 819 } |
| 768 | 820 |
| 769 } // namespace media | 821 } // namespace media |
| OLD | NEW |