OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2013 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 "webrtc/modules/audio_coding/acm2/acm_receiver.h" | 11 #include "webrtc/modules/audio_coding/acm2/acm_receiver.h" |
12 | 12 |
13 #include <algorithm> // std::min | 13 #include <algorithm> // std::min |
14 | 14 |
15 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
16 #include "webrtc/base/scoped_ptr.h" | 16 #include "webrtc/base/scoped_ptr.h" |
17 #include "webrtc/modules/audio_coding/include/audio_coding_module.h" | 17 #include "webrtc/modules/audio_coding/include/audio_coding_module.h" |
18 #include "webrtc/modules/audio_coding/acm2/audio_coding_module_impl.h" | 18 #include "webrtc/modules/audio_coding/acm2/audio_coding_module_impl.h" |
19 #include "webrtc/modules/audio_coding/neteq/tools/rtp_generator.h" | 19 #include "webrtc/modules/audio_coding/neteq/tools/rtp_generator.h" |
20 #include "webrtc/system_wrappers/include/clock.h" | 20 #include "webrtc/system_wrappers/include/clock.h" |
21 #include "webrtc/test/test_suite.h" | 21 #include "webrtc/test/test_suite.h" |
22 #include "webrtc/test/testsupport/fileutils.h" | 22 #include "webrtc/test/testsupport/fileutils.h" |
23 #include "webrtc/test/testsupport/gtest_disable.h" | |
24 | 23 |
25 namespace webrtc { | 24 namespace webrtc { |
26 | 25 |
27 namespace acm2 { | 26 namespace acm2 { |
28 namespace { | 27 namespace { |
29 | 28 |
30 bool CodecsEqual(const CodecInst& codec_a, const CodecInst& codec_b) { | 29 bool CodecsEqual(const CodecInst& codec_a, const CodecInst& codec_b) { |
31 if (strcmp(codec_a.plname, codec_b.plname) != 0 || | 30 if (strcmp(codec_a.plname, codec_b.plname) != 0 || |
32 codec_a.plfreq != codec_b.plfreq || | 31 codec_a.plfreq != codec_b.plfreq || |
33 codec_a.pltype != codec_b.pltype || | 32 codec_a.pltype != codec_b.pltype || |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
157 rtc::scoped_ptr<AcmReceiver> receiver_; | 156 rtc::scoped_ptr<AcmReceiver> receiver_; |
158 rtc::ArrayView<const CodecInst> codecs_; | 157 rtc::ArrayView<const CodecInst> codecs_; |
159 rtc::scoped_ptr<AudioCodingModule> acm_; | 158 rtc::scoped_ptr<AudioCodingModule> acm_; |
160 WebRtcRTPHeader rtp_header_; | 159 WebRtcRTPHeader rtp_header_; |
161 uint32_t timestamp_; | 160 uint32_t timestamp_; |
162 bool packet_sent_; // Set when SendData is called reset when inserting audio. | 161 bool packet_sent_; // Set when SendData is called reset when inserting audio. |
163 uint32_t last_packet_send_timestamp_; | 162 uint32_t last_packet_send_timestamp_; |
164 FrameType last_frame_type_; | 163 FrameType last_frame_type_; |
165 }; | 164 }; |
166 | 165 |
167 TEST_F(AcmReceiverTestOldApi, DISABLED_ON_ANDROID(AddCodecGetCodec)) { | 166 #if defined(WEBRTC_ANDROID) |
| 167 TEST_F(AcmReceiverTestOldApi, DISABLED_AddCodecGetCodec) { |
| 168 #else |
| 169 TEST_F(AcmReceiverTestOldApi, AddCodecGetCodec) { |
| 170 #endif |
168 // Add codec. | 171 // Add codec. |
169 for (size_t n = 0; n < codecs_.size(); ++n) { | 172 for (size_t n = 0; n < codecs_.size(); ++n) { |
170 if (n & 0x1) // Just add codecs with odd index. | 173 if (n & 0x1) // Just add codecs with odd index. |
171 EXPECT_EQ(0, | 174 EXPECT_EQ(0, |
172 receiver_->AddCodec(n, codecs_[n].pltype, codecs_[n].channels, | 175 receiver_->AddCodec(n, codecs_[n].pltype, codecs_[n].channels, |
173 codecs_[n].plfreq, NULL, "")); | 176 codecs_[n].plfreq, NULL, "")); |
174 } | 177 } |
175 // Get codec and compare. | 178 // Get codec and compare. |
176 for (size_t n = 0; n < codecs_.size(); ++n) { | 179 for (size_t n = 0; n < codecs_.size(); ++n) { |
177 CodecInst my_codec; | 180 CodecInst my_codec; |
178 if (n & 0x1) { | 181 if (n & 0x1) { |
179 // Codecs with odd index should match the reference. | 182 // Codecs with odd index should match the reference. |
180 EXPECT_EQ(0, receiver_->DecoderByPayloadType(codecs_[n].pltype, | 183 EXPECT_EQ(0, receiver_->DecoderByPayloadType(codecs_[n].pltype, |
181 &my_codec)); | 184 &my_codec)); |
182 EXPECT_TRUE(CodecsEqual(codecs_[n], my_codec)); | 185 EXPECT_TRUE(CodecsEqual(codecs_[n], my_codec)); |
183 } else { | 186 } else { |
184 // Codecs with even index are not registered. | 187 // Codecs with even index are not registered. |
185 EXPECT_EQ(-1, receiver_->DecoderByPayloadType(codecs_[n].pltype, | 188 EXPECT_EQ(-1, receiver_->DecoderByPayloadType(codecs_[n].pltype, |
186 &my_codec)); | 189 &my_codec)); |
187 } | 190 } |
188 } | 191 } |
189 } | 192 } |
190 | 193 |
191 TEST_F(AcmReceiverTestOldApi, DISABLED_ON_ANDROID(AddCodecChangePayloadType)) { | 194 #if defined(WEBRTC_ANDROID) |
| 195 TEST_F(AcmReceiverTestOldApi, DISABLED_AddCodecChangePayloadType) { |
| 196 #else |
| 197 TEST_F(AcmReceiverTestOldApi, AddCodecChangePayloadType) { |
| 198 #endif |
192 const CodecIdInst codec1(RentACodec::CodecId::kPCMA); | 199 const CodecIdInst codec1(RentACodec::CodecId::kPCMA); |
193 CodecInst codec2 = codec1.inst; | 200 CodecInst codec2 = codec1.inst; |
194 ++codec2.pltype; | 201 ++codec2.pltype; |
195 CodecInst test_codec; | 202 CodecInst test_codec; |
196 | 203 |
197 // Register the same codec with different payloads. | 204 // Register the same codec with different payloads. |
198 EXPECT_EQ(0, receiver_->AddCodec(codec1.id, codec1.inst.pltype, | 205 EXPECT_EQ(0, receiver_->AddCodec(codec1.id, codec1.inst.pltype, |
199 codec1.inst.channels, codec1.inst.plfreq, | 206 codec1.inst.channels, codec1.inst.plfreq, |
200 nullptr, "")); | 207 nullptr, "")); |
201 EXPECT_EQ(0, receiver_->AddCodec(codec1.id, codec2.pltype, codec2.channels, | 208 EXPECT_EQ(0, receiver_->AddCodec(codec1.id, codec2.pltype, codec2.channels, |
202 codec2.plfreq, NULL, "")); | 209 codec2.plfreq, NULL, "")); |
203 | 210 |
204 // Both payload types should exist. | 211 // Both payload types should exist. |
205 EXPECT_EQ(0, | 212 EXPECT_EQ(0, |
206 receiver_->DecoderByPayloadType(codec1.inst.pltype, &test_codec)); | 213 receiver_->DecoderByPayloadType(codec1.inst.pltype, &test_codec)); |
207 EXPECT_EQ(true, CodecsEqual(codec1.inst, test_codec)); | 214 EXPECT_EQ(true, CodecsEqual(codec1.inst, test_codec)); |
208 EXPECT_EQ(0, receiver_->DecoderByPayloadType(codec2.pltype, &test_codec)); | 215 EXPECT_EQ(0, receiver_->DecoderByPayloadType(codec2.pltype, &test_codec)); |
209 EXPECT_EQ(true, CodecsEqual(codec2, test_codec)); | 216 EXPECT_EQ(true, CodecsEqual(codec2, test_codec)); |
210 } | 217 } |
211 | 218 |
212 TEST_F(AcmReceiverTestOldApi, DISABLED_ON_ANDROID(AddCodecChangeCodecId)) { | 219 #if defined(WEBRTC_ANDROID) |
| 220 TEST_F(AcmReceiverTestOldApi, DISABLED_AddCodecChangeCodecId) { |
| 221 #else |
| 222 TEST_F(AcmReceiverTestOldApi, AddCodecChangeCodecId) { |
| 223 #endif |
213 const CodecIdInst codec1(RentACodec::CodecId::kPCMU); | 224 const CodecIdInst codec1(RentACodec::CodecId::kPCMU); |
214 CodecIdInst codec2(RentACodec::CodecId::kPCMA); | 225 CodecIdInst codec2(RentACodec::CodecId::kPCMA); |
215 codec2.inst.pltype = codec1.inst.pltype; | 226 codec2.inst.pltype = codec1.inst.pltype; |
216 CodecInst test_codec; | 227 CodecInst test_codec; |
217 | 228 |
218 // Register the same payload type with different codec ID. | 229 // Register the same payload type with different codec ID. |
219 EXPECT_EQ(0, receiver_->AddCodec(codec1.id, codec1.inst.pltype, | 230 EXPECT_EQ(0, receiver_->AddCodec(codec1.id, codec1.inst.pltype, |
220 codec1.inst.channels, codec1.inst.plfreq, | 231 codec1.inst.channels, codec1.inst.plfreq, |
221 nullptr, "")); | 232 nullptr, "")); |
222 EXPECT_EQ(0, receiver_->AddCodec(codec2.id, codec2.inst.pltype, | 233 EXPECT_EQ(0, receiver_->AddCodec(codec2.id, codec2.inst.pltype, |
223 codec2.inst.channels, codec2.inst.plfreq, | 234 codec2.inst.channels, codec2.inst.plfreq, |
224 nullptr, "")); | 235 nullptr, "")); |
225 | 236 |
226 // Make sure that the last codec is used. | 237 // Make sure that the last codec is used. |
227 EXPECT_EQ(0, | 238 EXPECT_EQ(0, |
228 receiver_->DecoderByPayloadType(codec2.inst.pltype, &test_codec)); | 239 receiver_->DecoderByPayloadType(codec2.inst.pltype, &test_codec)); |
229 EXPECT_EQ(true, CodecsEqual(codec2.inst, test_codec)); | 240 EXPECT_EQ(true, CodecsEqual(codec2.inst, test_codec)); |
230 } | 241 } |
231 | 242 |
232 TEST_F(AcmReceiverTestOldApi, DISABLED_ON_ANDROID(AddCodecRemoveCodec)) { | 243 #if defined(WEBRTC_ANDROID) |
| 244 TEST_F(AcmReceiverTestOldApi, DISABLED_AddCodecRemoveCodec) { |
| 245 #else |
| 246 TEST_F(AcmReceiverTestOldApi, AddCodecRemoveCodec) { |
| 247 #endif |
233 const CodecIdInst codec(RentACodec::CodecId::kPCMA); | 248 const CodecIdInst codec(RentACodec::CodecId::kPCMA); |
234 const int payload_type = codec.inst.pltype; | 249 const int payload_type = codec.inst.pltype; |
235 EXPECT_EQ( | 250 EXPECT_EQ( |
236 0, receiver_->AddCodec(codec.id, codec.inst.pltype, codec.inst.channels, | 251 0, receiver_->AddCodec(codec.id, codec.inst.pltype, codec.inst.channels, |
237 codec.inst.plfreq, nullptr, "")); | 252 codec.inst.plfreq, nullptr, "")); |
238 | 253 |
239 // Remove non-existing codec should not fail. ACM1 legacy. | 254 // Remove non-existing codec should not fail. ACM1 legacy. |
240 EXPECT_EQ(0, receiver_->RemoveCodec(payload_type + 1)); | 255 EXPECT_EQ(0, receiver_->RemoveCodec(payload_type + 1)); |
241 | 256 |
242 // Remove an existing codec. | 257 // Remove an existing codec. |
243 EXPECT_EQ(0, receiver_->RemoveCodec(payload_type)); | 258 EXPECT_EQ(0, receiver_->RemoveCodec(payload_type)); |
244 | 259 |
245 // Ask for the removed codec, must fail. | 260 // Ask for the removed codec, must fail. |
246 CodecInst ci; | 261 CodecInst ci; |
247 EXPECT_EQ(-1, receiver_->DecoderByPayloadType(payload_type, &ci)); | 262 EXPECT_EQ(-1, receiver_->DecoderByPayloadType(payload_type, &ci)); |
248 } | 263 } |
249 | 264 |
250 TEST_F(AcmReceiverTestOldApi, DISABLED_ON_ANDROID(SampleRate)) { | 265 #if defined(WEBRTC_ANDROID) |
| 266 TEST_F(AcmReceiverTestOldApi, DISABLED_SampleRate) { |
| 267 #else |
| 268 TEST_F(AcmReceiverTestOldApi, SampleRate) { |
| 269 #endif |
251 const RentACodec::CodecId kCodecId[] = {RentACodec::CodecId::kISAC, | 270 const RentACodec::CodecId kCodecId[] = {RentACodec::CodecId::kISAC, |
252 RentACodec::CodecId::kISACSWB}; | 271 RentACodec::CodecId::kISACSWB}; |
253 AddSetOfCodecs(kCodecId); | 272 AddSetOfCodecs(kCodecId); |
254 | 273 |
255 AudioFrame frame; | 274 AudioFrame frame; |
256 const int kOutSampleRateHz = 8000; // Different than codec sample rate. | 275 const int kOutSampleRateHz = 8000; // Different than codec sample rate. |
257 for (const auto codec_id : kCodecId) { | 276 for (const auto codec_id : kCodecId) { |
258 const CodecIdInst codec(codec_id); | 277 const CodecIdInst codec(codec_id); |
259 const int num_10ms_frames = codec.inst.pacsize / (codec.inst.plfreq / 100); | 278 const int num_10ms_frames = codec.inst.pacsize / (codec.inst.plfreq / 100); |
260 InsertOnePacketOfSilence(codec.id); | 279 InsertOnePacketOfSilence(codec.id); |
261 for (int k = 0; k < num_10ms_frames; ++k) { | 280 for (int k = 0; k < num_10ms_frames; ++k) { |
262 EXPECT_EQ(0, receiver_->GetAudio(kOutSampleRateHz, &frame)); | 281 EXPECT_EQ(0, receiver_->GetAudio(kOutSampleRateHz, &frame)); |
263 } | 282 } |
264 EXPECT_EQ(codec.inst.plfreq, receiver_->last_output_sample_rate_hz()); | 283 EXPECT_EQ(codec.inst.plfreq, receiver_->last_output_sample_rate_hz()); |
265 } | 284 } |
266 } | 285 } |
267 | 286 |
268 TEST_F(AcmReceiverTestOldApi, DISABLED_ON_ANDROID(PostdecodingVad)) { | 287 #if defined(WEBRTC_ANDROID) |
| 288 TEST_F(AcmReceiverTestOldApi, DISABLED_PostdecodingVad) { |
| 289 #else |
| 290 TEST_F(AcmReceiverTestOldApi, PostdecodingVad) { |
| 291 #endif |
269 receiver_->EnableVad(); | 292 receiver_->EnableVad(); |
270 EXPECT_TRUE(receiver_->vad_enabled()); | 293 EXPECT_TRUE(receiver_->vad_enabled()); |
271 const CodecIdInst codec(RentACodec::CodecId::kPCM16Bwb); | 294 const CodecIdInst codec(RentACodec::CodecId::kPCM16Bwb); |
272 ASSERT_EQ( | 295 ASSERT_EQ( |
273 0, receiver_->AddCodec(codec.id, codec.inst.pltype, codec.inst.channels, | 296 0, receiver_->AddCodec(codec.id, codec.inst.pltype, codec.inst.channels, |
274 codec.inst.plfreq, nullptr, "")); | 297 codec.inst.plfreq, nullptr, "")); |
275 const int kNumPackets = 5; | 298 const int kNumPackets = 5; |
276 const int num_10ms_frames = codec.inst.pacsize / (codec.inst.plfreq / 100); | 299 const int num_10ms_frames = codec.inst.pacsize / (codec.inst.plfreq / 100); |
277 AudioFrame frame; | 300 AudioFrame frame; |
278 for (int n = 0; n < kNumPackets; ++n) { | 301 for (int n = 0; n < kNumPackets; ++n) { |
(...skipping 13 matching lines...) Expand all Loading... |
292 } | 315 } |
293 EXPECT_EQ(AudioFrame::kVadUnknown, frame.vad_activity_); | 316 EXPECT_EQ(AudioFrame::kVadUnknown, frame.vad_activity_); |
294 } | 317 } |
295 | 318 |
296 #ifdef WEBRTC_CODEC_ISAC | 319 #ifdef WEBRTC_CODEC_ISAC |
297 #define IF_ISAC_FLOAT(x) x | 320 #define IF_ISAC_FLOAT(x) x |
298 #else | 321 #else |
299 #define IF_ISAC_FLOAT(x) DISABLED_##x | 322 #define IF_ISAC_FLOAT(x) DISABLED_##x |
300 #endif | 323 #endif |
301 | 324 |
302 TEST_F(AcmReceiverTestOldApi, | 325 #if defined(WEBRTC_ANDROID) |
303 DISABLED_ON_ANDROID(IF_ISAC_FLOAT(LastAudioCodec))) { | 326 TEST_F(AcmReceiverTestOldApi, DISABLED_LastAudioCodec) { |
| 327 #else |
| 328 TEST_F(AcmReceiverTestOldApi, IF_ISAC_FLOAT(LastAudioCodec)) { |
| 329 #endif |
304 const RentACodec::CodecId kCodecId[] = { | 330 const RentACodec::CodecId kCodecId[] = { |
305 RentACodec::CodecId::kISAC, RentACodec::CodecId::kPCMA, | 331 RentACodec::CodecId::kISAC, RentACodec::CodecId::kPCMA, |
306 RentACodec::CodecId::kISACSWB, RentACodec::CodecId::kPCM16Bswb32kHz}; | 332 RentACodec::CodecId::kISACSWB, RentACodec::CodecId::kPCM16Bswb32kHz}; |
307 AddSetOfCodecs(kCodecId); | 333 AddSetOfCodecs(kCodecId); |
308 | 334 |
309 const RentACodec::CodecId kCngId[] = { | 335 const RentACodec::CodecId kCngId[] = { |
310 // Not including full-band. | 336 // Not including full-band. |
311 RentACodec::CodecId::kCNNB, RentACodec::CodecId::kCNWB, | 337 RentACodec::CodecId::kCNNB, RentACodec::CodecId::kCNWB, |
312 RentACodec::CodecId::kCNSWB}; | 338 RentACodec::CodecId::kCNSWB}; |
313 AddSetOfCodecs(kCngId); | 339 AddSetOfCodecs(kCngId); |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
360 EXPECT_EQ(rtc::Optional<int>(c.inst.plfreq), | 386 EXPECT_EQ(rtc::Optional<int>(c.inst.plfreq), |
361 receiver_->last_packet_sample_rate_hz()); | 387 receiver_->last_packet_sample_rate_hz()); |
362 EXPECT_EQ(0, receiver_->LastAudioCodec(&codec)); | 388 EXPECT_EQ(0, receiver_->LastAudioCodec(&codec)); |
363 EXPECT_TRUE(CodecsEqual(c.inst, codec)); | 389 EXPECT_TRUE(CodecsEqual(c.inst, codec)); |
364 } | 390 } |
365 } | 391 } |
366 | 392 |
367 } // namespace acm2 | 393 } // namespace acm2 |
368 | 394 |
369 } // namespace webrtc | 395 } // namespace webrtc |
OLD | NEW |