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 #include <memory> | 14 #include <memory> |
15 | 15 |
16 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
| 17 #include "webrtc/base/checks.h" |
| 18 #include "webrtc/base/safe_conversions.h" |
17 #include "webrtc/modules/audio_coding/include/audio_coding_module.h" | 19 #include "webrtc/modules/audio_coding/include/audio_coding_module.h" |
18 #include "webrtc/modules/audio_coding/acm2/audio_coding_module_impl.h" | 20 #include "webrtc/modules/audio_coding/acm2/audio_coding_module_impl.h" |
19 #include "webrtc/modules/audio_coding/neteq/tools/rtp_generator.h" | 21 #include "webrtc/modules/audio_coding/neteq/tools/rtp_generator.h" |
20 #include "webrtc/system_wrappers/include/clock.h" | 22 #include "webrtc/system_wrappers/include/clock.h" |
21 #include "webrtc/test/test_suite.h" | 23 #include "webrtc/test/test_suite.h" |
22 #include "webrtc/test/testsupport/fileutils.h" | 24 #include "webrtc/test/testsupport/fileutils.h" |
23 | 25 |
24 namespace webrtc { | 26 namespace webrtc { |
25 | 27 |
26 namespace acm2 { | 28 namespace acm2 { |
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
282 const CodecIdInst codec(codec_id); | 284 const CodecIdInst codec(codec_id); |
283 const int num_10ms_frames = codec.inst.pacsize / (codec.inst.plfreq / 100); | 285 const int num_10ms_frames = codec.inst.pacsize / (codec.inst.plfreq / 100); |
284 InsertOnePacketOfSilence(codec.id); | 286 InsertOnePacketOfSilence(codec.id); |
285 for (int k = 0; k < num_10ms_frames; ++k) { | 287 for (int k = 0; k < num_10ms_frames; ++k) { |
286 EXPECT_EQ(0, receiver_->GetAudio(kOutSampleRateHz, &frame)); | 288 EXPECT_EQ(0, receiver_->GetAudio(kOutSampleRateHz, &frame)); |
287 } | 289 } |
288 EXPECT_EQ(codec.inst.plfreq, receiver_->last_output_sample_rate_hz()); | 290 EXPECT_EQ(codec.inst.plfreq, receiver_->last_output_sample_rate_hz()); |
289 } | 291 } |
290 } | 292 } |
291 | 293 |
| 294 class AcmReceiverTestFaxModeOldApi : public AcmReceiverTestOldApi { |
| 295 protected: |
| 296 AcmReceiverTestFaxModeOldApi() { |
| 297 config_.neteq_config.playout_mode = kPlayoutFax; |
| 298 } |
| 299 |
| 300 void RunVerifyAudioFrame(RentACodec::CodecId codec_id) { |
| 301 // Make sure "fax mode" is enabled. This will avoid delay changes unless the |
| 302 // packet-loss concealment is made. We do this in order to make the |
| 303 // timestamp increments predictable; in normal mode, NetEq may decide to do |
| 304 // accelerate or pre-emptive expand operations after some time, offsetting |
| 305 // the timestamp. |
| 306 EXPECT_EQ(kPlayoutFax, config_.neteq_config.playout_mode); |
| 307 |
| 308 const RentACodec::CodecId kCodecId[] = {codec_id}; |
| 309 AddSetOfCodecs(kCodecId); |
| 310 |
| 311 const CodecIdInst codec(codec_id); |
| 312 const int output_sample_rate_hz = codec.inst.plfreq; |
| 313 const size_t output_channels = codec.inst.channels; |
| 314 const size_t samples_per_ms = rtc::checked_cast<size_t>( |
| 315 rtc::CheckedDivExact(output_sample_rate_hz, 1000)); |
| 316 const int num_10ms_frames = rtc::CheckedDivExact( |
| 317 codec.inst.pacsize, rtc::checked_cast<int>(10 * samples_per_ms)); |
| 318 const AudioFrame::VADActivity expected_vad_activity = |
| 319 output_sample_rate_hz > 16000 ? AudioFrame::kVadActive |
| 320 : AudioFrame::kVadPassive; |
| 321 |
| 322 // Expect the first output timestamp to be 5*fs/8000 samples before the |
| 323 // first inserted timestamp (because of NetEq's look-ahead). (This value is |
| 324 // defined in Expand::overlap_length_.) |
| 325 uint32_t expected_output_ts = last_packet_send_timestamp_ - |
| 326 rtc::CheckedDivExact(5 * output_sample_rate_hz, 8000); |
| 327 |
| 328 AudioFrame frame; |
| 329 for (int i = 0; i < 5; ++i) { |
| 330 InsertOnePacketOfSilence(codec.id); |
| 331 for (int k = 0; k < num_10ms_frames; ++k) { |
| 332 EXPECT_EQ(0, receiver_->GetAudio(output_sample_rate_hz, &frame)); |
| 333 EXPECT_EQ(expected_output_ts, frame.timestamp_); |
| 334 expected_output_ts += 10 * samples_per_ms; |
| 335 EXPECT_EQ(10 * samples_per_ms, frame.samples_per_channel_); |
| 336 EXPECT_EQ(output_sample_rate_hz, frame.sample_rate_hz_); |
| 337 EXPECT_EQ(output_channels, frame.num_channels_); |
| 338 EXPECT_EQ(AudioFrame::kNormalSpeech, frame.speech_type_); |
| 339 EXPECT_EQ(expected_vad_activity, frame.vad_activity_); |
| 340 } |
| 341 } |
| 342 } |
| 343 }; |
| 344 |
| 345 #if defined(WEBRTC_ANDROID) |
| 346 #define MAYBE_VerifyAudioFramePCMU DISABLED_VerifyAudioFramePCMU |
| 347 #else |
| 348 #define MAYBE_VerifyAudioFramePCMU VerifyAudioFramePCMU |
| 349 #endif |
| 350 TEST_F(AcmReceiverTestFaxModeOldApi, MAYBE_VerifyAudioFramePCMU) { |
| 351 RunVerifyAudioFrame(RentACodec::CodecId::kPCMU); |
| 352 } |
| 353 |
| 354 #if defined(WEBRTC_ANDROID) |
| 355 #define MAYBE_VerifyAudioFrameISAC DISABLED_VerifyAudioFrameISAC |
| 356 #else |
| 357 #define MAYBE_VerifyAudioFrameISAC VerifyAudioFrameISAC |
| 358 #endif |
| 359 TEST_F(AcmReceiverTestFaxModeOldApi, MAYBE_VerifyAudioFrameISAC) { |
| 360 RunVerifyAudioFrame(RentACodec::CodecId::kISAC); |
| 361 } |
| 362 |
| 363 #if defined(WEBRTC_ANDROID) |
| 364 #define MAYBE_VerifyAudioFrameOpus DISABLED_VerifyAudioFrameOpus |
| 365 #else |
| 366 #define MAYBE_VerifyAudioFrameOpus VerifyAudioFrameOpus |
| 367 #endif |
| 368 TEST_F(AcmReceiverTestFaxModeOldApi, MAYBE_VerifyAudioFrameOpus) { |
| 369 RunVerifyAudioFrame(RentACodec::CodecId::kOpus); |
| 370 } |
| 371 |
292 #if defined(WEBRTC_ANDROID) | 372 #if defined(WEBRTC_ANDROID) |
293 #define MAYBE_PostdecodingVad DISABLED_PostdecodingVad | 373 #define MAYBE_PostdecodingVad DISABLED_PostdecodingVad |
294 #else | 374 #else |
295 #define MAYBE_PostdecodingVad PostdecodingVad | 375 #define MAYBE_PostdecodingVad PostdecodingVad |
296 #endif | 376 #endif |
297 TEST_F(AcmReceiverTestOldApi, MAYBE_PostdecodingVad) { | 377 TEST_F(AcmReceiverTestOldApi, MAYBE_PostdecodingVad) { |
298 EXPECT_TRUE(config_.neteq_config.enable_post_decode_vad); | 378 EXPECT_TRUE(config_.neteq_config.enable_post_decode_vad); |
299 const CodecIdInst codec(RentACodec::CodecId::kPCM16Bwb); | 379 const CodecIdInst codec(RentACodec::CodecId::kPCM16Bwb); |
300 ASSERT_EQ( | 380 ASSERT_EQ( |
301 0, receiver_->AddCodec(codec.id, codec.inst.pltype, codec.inst.channels, | 381 0, receiver_->AddCodec(codec.id, codec.inst.pltype, codec.inst.channels, |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
407 receiver_->last_packet_sample_rate_hz()); | 487 receiver_->last_packet_sample_rate_hz()); |
408 EXPECT_EQ(0, receiver_->LastAudioCodec(&codec)); | 488 EXPECT_EQ(0, receiver_->LastAudioCodec(&codec)); |
409 EXPECT_TRUE(CodecsEqual(c.inst, codec)); | 489 EXPECT_TRUE(CodecsEqual(c.inst, codec)); |
410 } | 490 } |
411 } | 491 } |
412 #endif | 492 #endif |
413 | 493 |
414 } // namespace acm2 | 494 } // namespace acm2 |
415 | 495 |
416 } // namespace webrtc | 496 } // namespace webrtc |
OLD | NEW |