OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
11 #include <memory> | |
12 #include <SLES/OpenSLES_Android.h> | 11 #include <SLES/OpenSLES_Android.h> |
13 | 12 |
14 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
15 #include "webrtc/base/arraysize.h" | 14 #include "webrtc/base/arraysize.h" |
16 #include "webrtc/base/format_macros.h" | 15 #include "webrtc/base/format_macros.h" |
17 #include "webrtc/modules/audio_device/android/build_info.h" | 16 #include "webrtc/modules/audio_device/android/build_info.h" |
18 #include "webrtc/modules/audio_device/android/audio_manager.h" | 17 #include "webrtc/modules/audio_device/android/audio_manager.h" |
19 #include "webrtc/modules/audio_device/android/ensure_initialized.h" | 18 #include "webrtc/modules/audio_device/android/ensure_initialized.h" |
20 | 19 |
21 #define PRINT(...) fprintf(stderr, __VA_ARGS__); | 20 #define PRINT(...) fprintf(stderr, __VA_ARGS__); |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
121 TEST_F(AudioManagerTest, IsNoiseSuppressorSupported) { | 120 TEST_F(AudioManagerTest, IsNoiseSuppressorSupported) { |
122 PRINT("%sNoise Suppressor support: %s\n", kTag, | 121 PRINT("%sNoise Suppressor support: %s\n", kTag, |
123 audio_manager()->IsNoiseSuppressorSupported() ? "Yes" : "No"); | 122 audio_manager()->IsNoiseSuppressorSupported() ? "Yes" : "No"); |
124 } | 123 } |
125 | 124 |
126 TEST_F(AudioManagerTest, IsLowLatencyPlayoutSupported) { | 125 TEST_F(AudioManagerTest, IsLowLatencyPlayoutSupported) { |
127 PRINT("%sLow latency output support: %s\n", kTag, | 126 PRINT("%sLow latency output support: %s\n", kTag, |
128 audio_manager()->IsLowLatencyPlayoutSupported() ? "Yes" : "No"); | 127 audio_manager()->IsLowLatencyPlayoutSupported() ? "Yes" : "No"); |
129 } | 128 } |
130 | 129 |
| 130 TEST_F(AudioManagerTest, IsLowLatencyRecordSupported) { |
| 131 PRINT("%sLow latency input support: %s\n", kTag, |
| 132 audio_manager()->IsLowLatencyRecordSupported() ? "Yes" : "No"); |
| 133 } |
| 134 |
131 TEST_F(AudioManagerTest, IsProAudioSupported) { | 135 TEST_F(AudioManagerTest, IsProAudioSupported) { |
132 PRINT("%sPro audio support: %s\n", kTag, | 136 PRINT("%sPro audio support: %s\n", kTag, |
133 audio_manager()->IsProAudioSupported() ? "Yes" : "No"); | 137 audio_manager()->IsProAudioSupported() ? "Yes" : "No"); |
134 } | 138 } |
135 | 139 |
136 TEST_F(AudioManagerTest, ShowAudioParameterInfo) { | 140 TEST_F(AudioManagerTest, ShowAudioParameterInfo) { |
137 const bool low_latency_out = audio_manager()->IsLowLatencyPlayoutSupported(); | 141 const bool low_latency_out = audio_manager()->IsLowLatencyPlayoutSupported(); |
| 142 const bool low_latency_in = audio_manager()->IsLowLatencyRecordSupported(); |
138 PRINT("PLAYOUT:\n"); | 143 PRINT("PLAYOUT:\n"); |
139 PRINT("%saudio layer: %s\n", kTag, | 144 PRINT("%saudio layer: %s\n", kTag, |
140 low_latency_out ? "Low latency OpenSL" : "Java/JNI based AudioTrack"); | 145 low_latency_out ? "Low latency OpenSL" : "Java/JNI based AudioTrack"); |
141 PRINT("%ssample rate: %d Hz\n", kTag, playout_parameters_.sample_rate()); | 146 PRINT("%ssample rate: %d Hz\n", kTag, playout_parameters_.sample_rate()); |
142 PRINT("%schannels: %" PRIuS "\n", kTag, playout_parameters_.channels()); | 147 PRINT("%schannels: %" PRIuS "\n", kTag, playout_parameters_.channels()); |
143 PRINT("%sframes per buffer: %" PRIuS " <=> %.2f ms\n", kTag, | 148 PRINT("%sframes per buffer: %" PRIuS " <=> %.2f ms\n", kTag, |
144 playout_parameters_.frames_per_buffer(), | 149 playout_parameters_.frames_per_buffer(), |
145 playout_parameters_.GetBufferSizeInMilliseconds()); | 150 playout_parameters_.GetBufferSizeInMilliseconds()); |
146 PRINT("RECORD: \n"); | 151 PRINT("RECORD: \n"); |
147 PRINT("%saudio layer: %s\n", kTag, "Java/JNI based AudioRecord"); | 152 PRINT("%saudio layer: %s\n", kTag, |
| 153 low_latency_in ? "Low latency OpenSL" : "Java/JNI based AudioRecord"); |
148 PRINT("%ssample rate: %d Hz\n", kTag, record_parameters_.sample_rate()); | 154 PRINT("%ssample rate: %d Hz\n", kTag, record_parameters_.sample_rate()); |
149 PRINT("%schannels: %" PRIuS "\n", kTag, record_parameters_.channels()); | 155 PRINT("%schannels: %" PRIuS "\n", kTag, record_parameters_.channels()); |
150 PRINT("%sframes per buffer: %" PRIuS " <=> %.2f ms\n", kTag, | 156 PRINT("%sframes per buffer: %" PRIuS " <=> %.2f ms\n", kTag, |
151 record_parameters_.frames_per_buffer(), | 157 record_parameters_.frames_per_buffer(), |
152 record_parameters_.GetBufferSizeInMilliseconds()); | 158 record_parameters_.GetBufferSizeInMilliseconds()); |
153 } | 159 } |
154 | 160 |
| 161 // The audio device module only suppors the same sample rate in both directions. |
| 162 // In addition, in full-duplex low-latency mode (OpenSL ES), both input and |
| 163 // output must use the same native buffer size to allow for usage of the fast |
| 164 // audio track in Android. |
| 165 TEST_F(AudioManagerTest, VerifyAudioParameters) { |
| 166 const bool low_latency_out = audio_manager()->IsLowLatencyPlayoutSupported(); |
| 167 const bool low_latency_in = audio_manager()->IsLowLatencyRecordSupported(); |
| 168 EXPECT_EQ(playout_parameters_.sample_rate(), |
| 169 record_parameters_.sample_rate()); |
| 170 if (low_latency_out && low_latency_in) { |
| 171 EXPECT_EQ(playout_parameters_.frames_per_buffer(), |
| 172 record_parameters_.frames_per_buffer()); |
| 173 } |
| 174 } |
| 175 |
155 // Add device-specific information to the test for logging purposes. | 176 // Add device-specific information to the test for logging purposes. |
156 TEST_F(AudioManagerTest, ShowDeviceInfo) { | 177 TEST_F(AudioManagerTest, ShowDeviceInfo) { |
157 BuildInfo build_info; | 178 BuildInfo build_info; |
158 PRINT("%smodel: %s\n", kTag, build_info.GetDeviceModel().c_str()); | 179 PRINT("%smodel: %s\n", kTag, build_info.GetDeviceModel().c_str()); |
159 PRINT("%sbrand: %s\n", kTag, build_info.GetBrand().c_str()); | 180 PRINT("%sbrand: %s\n", kTag, build_info.GetBrand().c_str()); |
160 PRINT("%smanufacturer: %s\n", | 181 PRINT("%smanufacturer: %s\n", |
161 kTag, build_info.GetDeviceManufacturer().c_str()); | 182 kTag, build_info.GetDeviceManufacturer().c_str()); |
162 } | 183 } |
163 | 184 |
164 // Add Android build information to the test for logging purposes. | 185 // Add Android build information to the test for logging purposes. |
165 TEST_F(AudioManagerTest, ShowBuildInfo) { | 186 TEST_F(AudioManagerTest, ShowBuildInfo) { |
166 BuildInfo build_info; | 187 BuildInfo build_info; |
167 PRINT("%sbuild release: %s\n", kTag, build_info.GetBuildRelease().c_str()); | 188 PRINT("%sbuild release: %s\n", kTag, build_info.GetBuildRelease().c_str()); |
168 PRINT("%sbuild id: %s\n", kTag, build_info.GetAndroidBuildId().c_str()); | 189 PRINT("%sbuild id: %s\n", kTag, build_info.GetAndroidBuildId().c_str()); |
169 PRINT("%sbuild type: %s\n", kTag, build_info.GetBuildType().c_str()); | 190 PRINT("%sbuild type: %s\n", kTag, build_info.GetBuildType().c_str()); |
170 PRINT("%sSDK version: %s\n", kTag, build_info.GetSdkVersion().c_str()); | 191 PRINT("%sSDK version: %d\n", kTag, build_info.GetSdkVersion()); |
171 } | 192 } |
172 | 193 |
173 // Basic test of the AudioParameters class using default construction where | 194 // Basic test of the AudioParameters class using default construction where |
174 // all members are set to zero. | 195 // all members are set to zero. |
175 TEST_F(AudioManagerTest, AudioParametersWithDefaultConstruction) { | 196 TEST_F(AudioManagerTest, AudioParametersWithDefaultConstruction) { |
176 AudioParameters params; | 197 AudioParameters params; |
177 EXPECT_FALSE(params.is_valid()); | 198 EXPECT_FALSE(params.is_valid()); |
178 EXPECT_EQ(0, params.sample_rate()); | 199 EXPECT_EQ(0, params.sample_rate()); |
179 EXPECT_EQ(0U, params.channels()); | 200 EXPECT_EQ(0U, params.channels()); |
180 EXPECT_EQ(0U, params.frames_per_buffer()); | 201 EXPECT_EQ(0U, params.frames_per_buffer()); |
(...skipping 21 matching lines...) Expand all Loading... |
202 params.frames_per_10ms_buffer()); | 223 params.frames_per_10ms_buffer()); |
203 EXPECT_EQ(kBytesPerFrame, params.GetBytesPerFrame()); | 224 EXPECT_EQ(kBytesPerFrame, params.GetBytesPerFrame()); |
204 EXPECT_EQ(kBytesPerFrame * kFramesPerBuffer, params.GetBytesPerBuffer()); | 225 EXPECT_EQ(kBytesPerFrame * kFramesPerBuffer, params.GetBytesPerBuffer()); |
205 EXPECT_EQ(kBytesPerFrame * kFramesPer10msBuffer, | 226 EXPECT_EQ(kBytesPerFrame * kFramesPer10msBuffer, |
206 params.GetBytesPer10msBuffer()); | 227 params.GetBytesPer10msBuffer()); |
207 EXPECT_EQ(kBufferSizeInMs, params.GetBufferSizeInMilliseconds()); | 228 EXPECT_EQ(kBufferSizeInMs, params.GetBufferSizeInMilliseconds()); |
208 } | 229 } |
209 | 230 |
210 } // namespace webrtc | 231 } // namespace webrtc |
211 | 232 |
OLD | NEW |