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 17 matching lines...) Expand all Loading... |
28 #include "testing/gtest/include/gtest/gtest.h" | 28 #include "testing/gtest/include/gtest/gtest.h" |
29 | 29 |
30 using ::testing::_; | 30 using ::testing::_; |
31 using ::testing::AtLeast; | 31 using ::testing::AtLeast; |
32 using ::testing::DoAll; | 32 using ::testing::DoAll; |
33 using ::testing::Invoke; | 33 using ::testing::Invoke; |
34 using ::testing::NotNull; | 34 using ::testing::NotNull; |
35 using ::testing::Return; | 35 using ::testing::Return; |
36 | 36 |
37 namespace media { | 37 namespace media { |
| 38 namespace { |
38 | 39 |
39 ACTION_P3(CheckCountAndPostQuitTask, count, limit, loop) { | 40 ACTION_P3(CheckCountAndPostQuitTask, count, limit, loop) { |
40 if (++*count >= limit) { | 41 if (++*count >= limit) { |
41 loop->PostTask(FROM_HERE, base::MessageLoop::QuitClosure()); | 42 loop->PostTask(FROM_HERE, base::MessageLoop::QuitClosure()); |
42 } | 43 } |
43 } | 44 } |
44 | 45 |
45 static const char kSpeechFile_16b_s_48k[] = "speech_16b_stereo_48kHz.raw"; | 46 const char kSpeechFile_16b_s_48k[] = "speech_16b_stereo_48kHz.raw"; |
46 static const char kSpeechFile_16b_m_48k[] = "speech_16b_mono_48kHz.raw"; | 47 const char kSpeechFile_16b_m_48k[] = "speech_16b_mono_48kHz.raw"; |
47 static const char kSpeechFile_16b_s_44k[] = "speech_16b_stereo_44kHz.raw"; | 48 const char kSpeechFile_16b_s_44k[] = "speech_16b_stereo_44kHz.raw"; |
48 static const char kSpeechFile_16b_m_44k[] = "speech_16b_mono_44kHz.raw"; | 49 const char kSpeechFile_16b_m_44k[] = "speech_16b_mono_44kHz.raw"; |
49 | 50 |
50 static const float kCallbackTestTimeMs = 2000.0; | 51 const float kCallbackTestTimeMs = 2000.0; |
51 static const int kBitsPerSample = 16; | 52 const int kBitsPerSample = 16; |
52 static const int kBytesPerSample = kBitsPerSample / 8; | 53 const int kBytesPerSample = kBitsPerSample / 8; |
53 | 54 |
54 // Converts AudioParameters::Format enumerator to readable string. | 55 // Converts AudioParameters::Format enumerator to readable string. |
55 static std::string FormatToString(AudioParameters::Format format) { | 56 std::string FormatToString(AudioParameters::Format format) { |
56 switch (format) { | 57 switch (format) { |
57 case AudioParameters::AUDIO_PCM_LINEAR: | 58 case AudioParameters::AUDIO_PCM_LINEAR: |
58 return std::string("AUDIO_PCM_LINEAR"); | 59 return std::string("AUDIO_PCM_LINEAR"); |
59 case AudioParameters::AUDIO_PCM_LOW_LATENCY: | 60 case AudioParameters::AUDIO_PCM_LOW_LATENCY: |
60 return std::string("AUDIO_PCM_LOW_LATENCY"); | 61 return std::string("AUDIO_PCM_LOW_LATENCY"); |
61 case AudioParameters::AUDIO_FAKE: | 62 case AudioParameters::AUDIO_FAKE: |
62 return std::string("AUDIO_FAKE"); | 63 return std::string("AUDIO_FAKE"); |
63 default: | 64 default: |
64 return std::string(); | 65 return std::string(); |
65 } | 66 } |
66 } | 67 } |
67 | 68 |
68 // Converts ChannelLayout enumerator to readable string. Does not include | 69 // Converts ChannelLayout enumerator to readable string. Does not include |
69 // multi-channel cases since these layouts are not supported on Android. | 70 // multi-channel cases since these layouts are not supported on Android. |
70 static std::string LayoutToString(ChannelLayout channel_layout) { | 71 std::string LayoutToString(ChannelLayout channel_layout) { |
71 switch (channel_layout) { | 72 switch (channel_layout) { |
72 case CHANNEL_LAYOUT_NONE: | 73 case CHANNEL_LAYOUT_NONE: |
73 return std::string("CHANNEL_LAYOUT_NONE"); | 74 return std::string("CHANNEL_LAYOUT_NONE"); |
74 case CHANNEL_LAYOUT_MONO: | 75 case CHANNEL_LAYOUT_MONO: |
75 return std::string("CHANNEL_LAYOUT_MONO"); | 76 return std::string("CHANNEL_LAYOUT_MONO"); |
76 case CHANNEL_LAYOUT_STEREO: | 77 case CHANNEL_LAYOUT_STEREO: |
77 return std::string("CHANNEL_LAYOUT_STEREO"); | 78 return std::string("CHANNEL_LAYOUT_STEREO"); |
78 case CHANNEL_LAYOUT_UNSUPPORTED: | 79 case CHANNEL_LAYOUT_UNSUPPORTED: |
79 default: | 80 default: |
80 return std::string("CHANNEL_LAYOUT_UNSUPPORTED"); | 81 return std::string("CHANNEL_LAYOUT_UNSUPPORTED"); |
81 } | 82 } |
82 } | 83 } |
83 | 84 |
84 static double ExpectedTimeBetweenCallbacks(AudioParameters params) { | 85 double ExpectedTimeBetweenCallbacks(AudioParameters params) { |
85 return (base::TimeDelta::FromMicroseconds( | 86 return (base::TimeDelta::FromMicroseconds( |
86 params.frames_per_buffer() * base::Time::kMicrosecondsPerSecond / | 87 params.frames_per_buffer() * base::Time::kMicrosecondsPerSecond / |
87 static_cast<double>(params.sample_rate()))).InMillisecondsF(); | 88 static_cast<double>(params.sample_rate()))).InMillisecondsF(); |
88 } | 89 } |
89 | 90 |
90 // Helper method which verifies that the device list starts with a valid | 91 // Helper method which verifies that the device list starts with a valid |
91 // default device name followed by non-default device names. | 92 // default device name followed by non-default device names. |
92 static void CheckDeviceNames(const AudioDeviceNames& device_names) { | 93 void CheckDeviceNames(const AudioDeviceNames& device_names) { |
93 DVLOG(2) << "Got " << device_names.size() << " audio devices."; | 94 DVLOG(2) << "Got " << device_names.size() << " audio devices."; |
94 if (device_names.empty()) { | 95 if (device_names.empty()) { |
95 // Log a warning so we can see the status on the build bots. No need to | 96 // 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 // break the test though since this does successfully test the code and |
97 // some failure cases. | 98 // some failure cases. |
98 LOG(WARNING) << "No input devices detected"; | 99 LOG(WARNING) << "No input devices detected"; |
99 return; | 100 return; |
100 } | 101 } |
101 | 102 |
102 AudioDeviceNames::const_iterator it = device_names.begin(); | 103 AudioDeviceNames::const_iterator it = device_names.begin(); |
103 | 104 |
104 // The first device in the list should always be the default device. | 105 // The first device in the list should always be the default device. |
105 EXPECT_EQ(std::string(AudioManagerBase::kDefaultDeviceName), | 106 EXPECT_EQ(AudioManager::GetDefaultDeviceName(), it->device_name); |
106 it->device_name); | |
107 EXPECT_EQ(std::string(AudioManagerBase::kDefaultDeviceId), it->unique_id); | 107 EXPECT_EQ(std::string(AudioManagerBase::kDefaultDeviceId), it->unique_id); |
108 ++it; | 108 ++it; |
109 | 109 |
110 // Other devices should have non-empty name and id and should not contain | 110 // Other devices should have non-empty name and id and should not contain |
111 // default name or id. | 111 // default name or id. |
112 while (it != device_names.end()) { | 112 while (it != device_names.end()) { |
113 EXPECT_FALSE(it->device_name.empty()); | 113 EXPECT_FALSE(it->device_name.empty()); |
114 EXPECT_FALSE(it->unique_id.empty()); | 114 EXPECT_FALSE(it->unique_id.empty()); |
115 DVLOG(2) << "Device ID(" << it->unique_id | 115 DVLOG(2) << "Device ID(" << it->unique_id |
116 << "), label: " << it->device_name; | 116 << "), label: " << it->device_name; |
117 EXPECT_NE(std::string(AudioManagerBase::kDefaultDeviceName), | 117 EXPECT_NE(AudioManager::GetDefaultDeviceName(), it->device_name); |
118 it->device_name); | 118 EXPECT_NE(std::string(AudioManagerBase::kDefaultDeviceId), it->unique_id); |
119 EXPECT_NE(std::string(AudioManagerBase::kDefaultDeviceId), | |
120 it->unique_id); | |
121 ++it; | 119 ++it; |
122 } | 120 } |
123 } | 121 } |
124 | 122 |
125 // We clear the data bus to ensure that the test does not cause noise. | 123 // We clear the data bus to ensure that the test does not cause noise. |
126 static int RealOnMoreData(AudioBus* dest, uint32 total_bytes_delay) { | 124 int RealOnMoreData(AudioBus* dest, uint32 total_bytes_delay) { |
127 dest->Zero(); | 125 dest->Zero(); |
128 return dest->frames(); | 126 return dest->frames(); |
129 } | 127 } |
130 | 128 |
| 129 } // namespace |
| 130 |
131 std::ostream& operator<<(std::ostream& os, const AudioParameters& params) { | 131 std::ostream& operator<<(std::ostream& os, const AudioParameters& params) { |
132 using namespace std; | 132 using namespace std; |
133 os << endl << "format: " << FormatToString(params.format()) << endl | 133 os << endl << "format: " << FormatToString(params.format()) << endl |
134 << "channel layout: " << LayoutToString(params.channel_layout()) << endl | 134 << "channel layout: " << LayoutToString(params.channel_layout()) << endl |
135 << "sample rate: " << params.sample_rate() << endl | 135 << "sample rate: " << params.sample_rate() << endl |
136 << "bits per sample: " << params.bits_per_sample() << endl | 136 << "bits per sample: " << params.bits_per_sample() << endl |
137 << "frames per buffer: " << params.frames_per_buffer() << endl | 137 << "frames per buffer: " << params.frames_per_buffer() << endl |
138 << "channels: " << params.channels() << endl | 138 << "channels: " << params.channels() << endl |
139 << "bytes per buffer: " << params.GetBytesPerBuffer() << endl | 139 << "bytes per buffer: " << params.GetBytesPerBuffer() << endl |
140 << "bytes per second: " << params.GetBytesPerSecond() << endl | 140 << "bytes per second: " << params.GetBytesPerSecond() << endl |
(...skipping 805 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
946 base::PlatformThread::Sleep(base::TimeDelta::FromSeconds(20)); | 946 base::PlatformThread::Sleep(base::TimeDelta::FromSeconds(20)); |
947 printf("\n"); | 947 printf("\n"); |
948 StopAndCloseAudioOutputStreamOnAudioThread(); | 948 StopAndCloseAudioOutputStreamOnAudioThread(); |
949 StopAndCloseAudioInputStreamOnAudioThread(); | 949 StopAndCloseAudioInputStreamOnAudioThread(); |
950 } | 950 } |
951 | 951 |
952 INSTANTIATE_TEST_CASE_P(AudioAndroidInputTest, AudioAndroidInputTest, | 952 INSTANTIATE_TEST_CASE_P(AudioAndroidInputTest, AudioAndroidInputTest, |
953 testing::ValuesIn(RunAudioRecordInputPathTests())); | 953 testing::ValuesIn(RunAudioRecordInputPathTests())); |
954 | 954 |
955 } // namespace media | 955 } // namespace media |
OLD | NEW |