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 #define MAYBE_AddCodecGetCodec DISABLED_AddCodecGetCodec |
| 168 #else |
| 169 #define MAYBE_AddCodecGetCodec AddCodecGetCodec |
| 170 #endif |
| 171 TEST_F(AcmReceiverTestOldApi, MAYBE_AddCodecGetCodec) { |
168 // Add codec. | 172 // Add codec. |
169 for (size_t n = 0; n < codecs_.size(); ++n) { | 173 for (size_t n = 0; n < codecs_.size(); ++n) { |
170 if (n & 0x1) // Just add codecs with odd index. | 174 if (n & 0x1) // Just add codecs with odd index. |
171 EXPECT_EQ(0, | 175 EXPECT_EQ(0, |
172 receiver_->AddCodec(n, codecs_[n].pltype, codecs_[n].channels, | 176 receiver_->AddCodec(n, codecs_[n].pltype, codecs_[n].channels, |
173 codecs_[n].plfreq, NULL, "")); | 177 codecs_[n].plfreq, NULL, "")); |
174 } | 178 } |
175 // Get codec and compare. | 179 // Get codec and compare. |
176 for (size_t n = 0; n < codecs_.size(); ++n) { | 180 for (size_t n = 0; n < codecs_.size(); ++n) { |
177 CodecInst my_codec; | 181 CodecInst my_codec; |
178 if (n & 0x1) { | 182 if (n & 0x1) { |
179 // Codecs with odd index should match the reference. | 183 // Codecs with odd index should match the reference. |
180 EXPECT_EQ(0, receiver_->DecoderByPayloadType(codecs_[n].pltype, | 184 EXPECT_EQ(0, receiver_->DecoderByPayloadType(codecs_[n].pltype, |
181 &my_codec)); | 185 &my_codec)); |
182 EXPECT_TRUE(CodecsEqual(codecs_[n], my_codec)); | 186 EXPECT_TRUE(CodecsEqual(codecs_[n], my_codec)); |
183 } else { | 187 } else { |
184 // Codecs with even index are not registered. | 188 // Codecs with even index are not registered. |
185 EXPECT_EQ(-1, receiver_->DecoderByPayloadType(codecs_[n].pltype, | 189 EXPECT_EQ(-1, receiver_->DecoderByPayloadType(codecs_[n].pltype, |
186 &my_codec)); | 190 &my_codec)); |
187 } | 191 } |
188 } | 192 } |
189 } | 193 } |
190 | 194 |
191 TEST_F(AcmReceiverTestOldApi, DISABLED_ON_ANDROID(AddCodecChangePayloadType)) { | 195 #if defined(WEBRTC_ANDROID) |
| 196 #define MAYBE_AddCodecChangePayloadType DISABLED_AddCodecChangePayloadType |
| 197 #else |
| 198 #define MAYBE_AddCodecChangePayloadType AddCodecChangePayloadType |
| 199 #endif |
| 200 TEST_F(AcmReceiverTestOldApi, MAYBE_AddCodecChangePayloadType) { |
192 const CodecIdInst codec1(RentACodec::CodecId::kPCMA); | 201 const CodecIdInst codec1(RentACodec::CodecId::kPCMA); |
193 CodecInst codec2 = codec1.inst; | 202 CodecInst codec2 = codec1.inst; |
194 ++codec2.pltype; | 203 ++codec2.pltype; |
195 CodecInst test_codec; | 204 CodecInst test_codec; |
196 | 205 |
197 // Register the same codec with different payloads. | 206 // Register the same codec with different payloads. |
198 EXPECT_EQ(0, receiver_->AddCodec(codec1.id, codec1.inst.pltype, | 207 EXPECT_EQ(0, receiver_->AddCodec(codec1.id, codec1.inst.pltype, |
199 codec1.inst.channels, codec1.inst.plfreq, | 208 codec1.inst.channels, codec1.inst.plfreq, |
200 nullptr, "")); | 209 nullptr, "")); |
201 EXPECT_EQ(0, receiver_->AddCodec(codec1.id, codec2.pltype, codec2.channels, | 210 EXPECT_EQ(0, receiver_->AddCodec(codec1.id, codec2.pltype, codec2.channels, |
202 codec2.plfreq, NULL, "")); | 211 codec2.plfreq, NULL, "")); |
203 | 212 |
204 // Both payload types should exist. | 213 // Both payload types should exist. |
205 EXPECT_EQ(0, | 214 EXPECT_EQ(0, |
206 receiver_->DecoderByPayloadType(codec1.inst.pltype, &test_codec)); | 215 receiver_->DecoderByPayloadType(codec1.inst.pltype, &test_codec)); |
207 EXPECT_EQ(true, CodecsEqual(codec1.inst, test_codec)); | 216 EXPECT_EQ(true, CodecsEqual(codec1.inst, test_codec)); |
208 EXPECT_EQ(0, receiver_->DecoderByPayloadType(codec2.pltype, &test_codec)); | 217 EXPECT_EQ(0, receiver_->DecoderByPayloadType(codec2.pltype, &test_codec)); |
209 EXPECT_EQ(true, CodecsEqual(codec2, test_codec)); | 218 EXPECT_EQ(true, CodecsEqual(codec2, test_codec)); |
210 } | 219 } |
211 | 220 |
212 TEST_F(AcmReceiverTestOldApi, DISABLED_ON_ANDROID(AddCodecChangeCodecId)) { | 221 #if defined(WEBRTC_ANDROID) |
| 222 #define MAYBE_AddCodecChangeCodecId DISABLED_AddCodecChangeCodecId |
| 223 #else |
| 224 #define MAYBE_AddCodecChangeCodecId AddCodecChangeCodecId |
| 225 #endif |
| 226 TEST_F(AcmReceiverTestOldApi, AddCodecChangeCodecId) { |
213 const CodecIdInst codec1(RentACodec::CodecId::kPCMU); | 227 const CodecIdInst codec1(RentACodec::CodecId::kPCMU); |
214 CodecIdInst codec2(RentACodec::CodecId::kPCMA); | 228 CodecIdInst codec2(RentACodec::CodecId::kPCMA); |
215 codec2.inst.pltype = codec1.inst.pltype; | 229 codec2.inst.pltype = codec1.inst.pltype; |
216 CodecInst test_codec; | 230 CodecInst test_codec; |
217 | 231 |
218 // Register the same payload type with different codec ID. | 232 // Register the same payload type with different codec ID. |
219 EXPECT_EQ(0, receiver_->AddCodec(codec1.id, codec1.inst.pltype, | 233 EXPECT_EQ(0, receiver_->AddCodec(codec1.id, codec1.inst.pltype, |
220 codec1.inst.channels, codec1.inst.plfreq, | 234 codec1.inst.channels, codec1.inst.plfreq, |
221 nullptr, "")); | 235 nullptr, "")); |
222 EXPECT_EQ(0, receiver_->AddCodec(codec2.id, codec2.inst.pltype, | 236 EXPECT_EQ(0, receiver_->AddCodec(codec2.id, codec2.inst.pltype, |
223 codec2.inst.channels, codec2.inst.plfreq, | 237 codec2.inst.channels, codec2.inst.plfreq, |
224 nullptr, "")); | 238 nullptr, "")); |
225 | 239 |
226 // Make sure that the last codec is used. | 240 // Make sure that the last codec is used. |
227 EXPECT_EQ(0, | 241 EXPECT_EQ(0, |
228 receiver_->DecoderByPayloadType(codec2.inst.pltype, &test_codec)); | 242 receiver_->DecoderByPayloadType(codec2.inst.pltype, &test_codec)); |
229 EXPECT_EQ(true, CodecsEqual(codec2.inst, test_codec)); | 243 EXPECT_EQ(true, CodecsEqual(codec2.inst, test_codec)); |
230 } | 244 } |
231 | 245 |
232 TEST_F(AcmReceiverTestOldApi, DISABLED_ON_ANDROID(AddCodecRemoveCodec)) { | 246 #if defined(WEBRTC_ANDROID) |
| 247 #define MAYBE_AddCodecRemoveCodec DISABLED_AddCodecRemoveCodec |
| 248 #else |
| 249 #define MAYBE_AddCodecRemoveCodec AddCodecRemoveCodec |
| 250 #endif |
| 251 TEST_F(AcmReceiverTestOldApi, MAYBE_AddCodecRemoveCodec) { |
233 const CodecIdInst codec(RentACodec::CodecId::kPCMA); | 252 const CodecIdInst codec(RentACodec::CodecId::kPCMA); |
234 const int payload_type = codec.inst.pltype; | 253 const int payload_type = codec.inst.pltype; |
235 EXPECT_EQ( | 254 EXPECT_EQ( |
236 0, receiver_->AddCodec(codec.id, codec.inst.pltype, codec.inst.channels, | 255 0, receiver_->AddCodec(codec.id, codec.inst.pltype, codec.inst.channels, |
237 codec.inst.plfreq, nullptr, "")); | 256 codec.inst.plfreq, nullptr, "")); |
238 | 257 |
239 // Remove non-existing codec should not fail. ACM1 legacy. | 258 // Remove non-existing codec should not fail. ACM1 legacy. |
240 EXPECT_EQ(0, receiver_->RemoveCodec(payload_type + 1)); | 259 EXPECT_EQ(0, receiver_->RemoveCodec(payload_type + 1)); |
241 | 260 |
242 // Remove an existing codec. | 261 // Remove an existing codec. |
243 EXPECT_EQ(0, receiver_->RemoveCodec(payload_type)); | 262 EXPECT_EQ(0, receiver_->RemoveCodec(payload_type)); |
244 | 263 |
245 // Ask for the removed codec, must fail. | 264 // Ask for the removed codec, must fail. |
246 CodecInst ci; | 265 CodecInst ci; |
247 EXPECT_EQ(-1, receiver_->DecoderByPayloadType(payload_type, &ci)); | 266 EXPECT_EQ(-1, receiver_->DecoderByPayloadType(payload_type, &ci)); |
248 } | 267 } |
249 | 268 |
250 TEST_F(AcmReceiverTestOldApi, DISABLED_ON_ANDROID(SampleRate)) { | 269 #if defined(WEBRTC_ANDROID) |
| 270 #define MAYBE_SampleRate DISABLED_SampleRate |
| 271 #else |
| 272 #define MAYBE_SampleRate SampleRate |
| 273 #endif |
| 274 TEST_F(AcmReceiverTestOldApi, MAYBE_SampleRate) { |
251 const RentACodec::CodecId kCodecId[] = {RentACodec::CodecId::kISAC, | 275 const RentACodec::CodecId kCodecId[] = {RentACodec::CodecId::kISAC, |
252 RentACodec::CodecId::kISACSWB}; | 276 RentACodec::CodecId::kISACSWB}; |
253 AddSetOfCodecs(kCodecId); | 277 AddSetOfCodecs(kCodecId); |
254 | 278 |
255 AudioFrame frame; | 279 AudioFrame frame; |
256 const int kOutSampleRateHz = 8000; // Different than codec sample rate. | 280 const int kOutSampleRateHz = 8000; // Different than codec sample rate. |
257 for (const auto codec_id : kCodecId) { | 281 for (const auto codec_id : kCodecId) { |
258 const CodecIdInst codec(codec_id); | 282 const CodecIdInst codec(codec_id); |
259 const int num_10ms_frames = codec.inst.pacsize / (codec.inst.plfreq / 100); | 283 const int num_10ms_frames = codec.inst.pacsize / (codec.inst.plfreq / 100); |
260 InsertOnePacketOfSilence(codec.id); | 284 InsertOnePacketOfSilence(codec.id); |
261 for (int k = 0; k < num_10ms_frames; ++k) { | 285 for (int k = 0; k < num_10ms_frames; ++k) { |
262 EXPECT_EQ(0, receiver_->GetAudio(kOutSampleRateHz, &frame)); | 286 EXPECT_EQ(0, receiver_->GetAudio(kOutSampleRateHz, &frame)); |
263 } | 287 } |
264 EXPECT_EQ(codec.inst.plfreq, receiver_->last_output_sample_rate_hz()); | 288 EXPECT_EQ(codec.inst.plfreq, receiver_->last_output_sample_rate_hz()); |
265 } | 289 } |
266 } | 290 } |
267 | 291 |
268 TEST_F(AcmReceiverTestOldApi, DISABLED_ON_ANDROID(PostdecodingVad)) { | 292 #if defined(WEBRTC_ANDROID) |
| 293 #define MAYBE_PostdecodingVad DISABLED_PostdecodingVad |
| 294 #else |
| 295 #define MAYBE_PostdecodingVad PostdecodingVad |
| 296 #endif |
| 297 TEST_F(AcmReceiverTestOldApi, MAYBE_PostdecodingVad) { |
269 receiver_->EnableVad(); | 298 receiver_->EnableVad(); |
270 EXPECT_TRUE(receiver_->vad_enabled()); | 299 EXPECT_TRUE(receiver_->vad_enabled()); |
271 const CodecIdInst codec(RentACodec::CodecId::kPCM16Bwb); | 300 const CodecIdInst codec(RentACodec::CodecId::kPCM16Bwb); |
272 ASSERT_EQ( | 301 ASSERT_EQ( |
273 0, receiver_->AddCodec(codec.id, codec.inst.pltype, codec.inst.channels, | 302 0, receiver_->AddCodec(codec.id, codec.inst.pltype, codec.inst.channels, |
274 codec.inst.plfreq, nullptr, "")); | 303 codec.inst.plfreq, nullptr, "")); |
275 const int kNumPackets = 5; | 304 const int kNumPackets = 5; |
276 const int num_10ms_frames = codec.inst.pacsize / (codec.inst.plfreq / 100); | 305 const int num_10ms_frames = codec.inst.pacsize / (codec.inst.plfreq / 100); |
277 AudioFrame frame; | 306 AudioFrame frame; |
278 for (int n = 0; n < kNumPackets; ++n) { | 307 for (int n = 0; n < kNumPackets; ++n) { |
279 InsertOnePacketOfSilence(codec.id); | 308 InsertOnePacketOfSilence(codec.id); |
280 for (int k = 0; k < num_10ms_frames; ++k) | 309 for (int k = 0; k < num_10ms_frames; ++k) |
281 ASSERT_EQ(0, receiver_->GetAudio(codec.inst.plfreq, &frame)); | 310 ASSERT_EQ(0, receiver_->GetAudio(codec.inst.plfreq, &frame)); |
282 } | 311 } |
283 EXPECT_EQ(AudioFrame::kVadPassive, frame.vad_activity_); | 312 EXPECT_EQ(AudioFrame::kVadPassive, frame.vad_activity_); |
284 | 313 |
285 receiver_->DisableVad(); | 314 receiver_->DisableVad(); |
286 EXPECT_FALSE(receiver_->vad_enabled()); | 315 EXPECT_FALSE(receiver_->vad_enabled()); |
287 | 316 |
288 for (int n = 0; n < kNumPackets; ++n) { | 317 for (int n = 0; n < kNumPackets; ++n) { |
289 InsertOnePacketOfSilence(codec.id); | 318 InsertOnePacketOfSilence(codec.id); |
290 for (int k = 0; k < num_10ms_frames; ++k) | 319 for (int k = 0; k < num_10ms_frames; ++k) |
291 ASSERT_EQ(0, receiver_->GetAudio(codec.inst.plfreq, &frame)); | 320 ASSERT_EQ(0, receiver_->GetAudio(codec.inst.plfreq, &frame)); |
292 } | 321 } |
293 EXPECT_EQ(AudioFrame::kVadUnknown, frame.vad_activity_); | 322 EXPECT_EQ(AudioFrame::kVadUnknown, frame.vad_activity_); |
294 } | 323 } |
295 | 324 |
296 #ifdef WEBRTC_CODEC_ISAC | 325 #if defined(WEBRTC_ANDROID) |
297 #define IF_ISAC_FLOAT(x) x | 326 #define MAYBE_LastAudioCodec DISABLED_LastAudioCodec |
298 #else | 327 #else |
299 #define IF_ISAC_FLOAT(x) DISABLED_##x | 328 #define MAYBE_LastAudioCodec LastAudioCodec |
300 #endif | 329 #endif |
301 | 330 #if defined(WEBRTC_CODEC_ISAC) |
302 TEST_F(AcmReceiverTestOldApi, | 331 TEST_F(AcmReceiverTestOldApi, MAYBE_LastAudioCodec) { |
303 DISABLED_ON_ANDROID(IF_ISAC_FLOAT(LastAudioCodec))) { | |
304 const RentACodec::CodecId kCodecId[] = { | 332 const RentACodec::CodecId kCodecId[] = { |
305 RentACodec::CodecId::kISAC, RentACodec::CodecId::kPCMA, | 333 RentACodec::CodecId::kISAC, RentACodec::CodecId::kPCMA, |
306 RentACodec::CodecId::kISACSWB, RentACodec::CodecId::kPCM16Bswb32kHz}; | 334 RentACodec::CodecId::kISACSWB, RentACodec::CodecId::kPCM16Bswb32kHz}; |
307 AddSetOfCodecs(kCodecId); | 335 AddSetOfCodecs(kCodecId); |
308 | 336 |
309 const RentACodec::CodecId kCngId[] = { | 337 const RentACodec::CodecId kCngId[] = { |
310 // Not including full-band. | 338 // Not including full-band. |
311 RentACodec::CodecId::kCNNB, RentACodec::CodecId::kCNWB, | 339 RentACodec::CodecId::kCNNB, RentACodec::CodecId::kCNWB, |
312 RentACodec::CodecId::kCNSWB}; | 340 RentACodec::CodecId::kCNSWB}; |
313 AddSetOfCodecs(kCngId); | 341 AddSetOfCodecs(kCngId); |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
356 packet_sent_ = false; | 384 packet_sent_ = false; |
357 InsertOnePacketOfSilence(c.id); | 385 InsertOnePacketOfSilence(c.id); |
358 ASSERT_TRUE(packet_sent_); | 386 ASSERT_TRUE(packet_sent_); |
359 } | 387 } |
360 EXPECT_EQ(rtc::Optional<int>(c.inst.plfreq), | 388 EXPECT_EQ(rtc::Optional<int>(c.inst.plfreq), |
361 receiver_->last_packet_sample_rate_hz()); | 389 receiver_->last_packet_sample_rate_hz()); |
362 EXPECT_EQ(0, receiver_->LastAudioCodec(&codec)); | 390 EXPECT_EQ(0, receiver_->LastAudioCodec(&codec)); |
363 EXPECT_TRUE(CodecsEqual(c.inst, codec)); | 391 EXPECT_TRUE(CodecsEqual(c.inst, codec)); |
364 } | 392 } |
365 } | 393 } |
| 394 #endif |
366 | 395 |
367 } // namespace acm2 | 396 } // namespace acm2 |
368 | 397 |
369 } // namespace webrtc | 398 } // namespace webrtc |
OLD | NEW |