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 | |
301 #if defined(WEBRTC_ANDROID) | |
302 #define MAYBE_VerifyAudioFrame DISABLED_VerifyAudioFrame | |
303 #else | |
304 #define MAYBE_VerifyAudioFrame VerifyAudioFrame | |
305 #endif | |
306 TEST_F(AcmReceiverTestFaxModeOldApi, MAYBE_VerifyAudioFrame) { | |
307 // Make sure "fax mode" is enabled. This will avoid delay changes unless the | |
308 // packet-loss concealment is made. We do this in order to make the timestamp | |
309 // increments predictable; in normal mode, NetEq may decide to do accelerate | |
310 // or pre-emptive expand operations after some time, offsetting the timestamp. | |
311 EXPECT_EQ(kPlayoutFax, config_.neteq_config.playout_mode); | |
312 | |
313 const RentACodec::CodecId codec_id = RentACodec::CodecId::kOpus; | |
314 const RentACodec::CodecId kCodecId[] = {codec_id}; | |
315 AddSetOfCodecs(kCodecId); | |
316 | |
317 const CodecIdInst codec(codec_id); | |
318 const int output_sample_rate_hz = codec.inst.plfreq; | |
319 const size_t output_channels = codec.inst.channels; | |
320 const size_t samples_per_ms = rtc::checked_cast<size_t>( | |
321 rtc::CheckedDivExact(output_sample_rate_hz, 1000)); | |
322 const int num_10ms_frames = rtc::CheckedDivExact( | |
323 codec.inst.pacsize, rtc::checked_cast<int>(10 * samples_per_ms)); | |
324 const AudioFrame::VADActivity expected_vad_activity = | |
325 output_sample_rate_hz > 16000 ? AudioFrame::kVadActive | |
326 : AudioFrame::kVadPassive; | |
327 | |
328 // Expect the first output timestamp to be 5*fs/8000 samples before the first | |
329 // inserted timestamp (because of NetEq's look-ahead). (This value is defined | |
330 // in Expand::overlap_length_.) | |
331 uint32_t expected_output_ts = | |
332 last_packet_send_timestamp_ - | |
minyue-webrtc
2016/04/05 14:08:59
better moving this line up
hlundin-webrtc
2016/04/05 14:24:15
Done.
| |
333 rtc::CheckedDivExact(5 * output_sample_rate_hz, 8000); | |
334 | |
335 AudioFrame frame; | |
336 for (int i = 0; i < 5; ++i) { | |
337 InsertOnePacketOfSilence(codec.id); | |
338 for (int k = 0; k < num_10ms_frames; ++k) { | |
339 EXPECT_EQ(0, receiver_->GetAudio(output_sample_rate_hz, &frame)); | |
340 EXPECT_EQ(expected_output_ts, frame.timestamp_); | |
341 expected_output_ts += 10 * samples_per_ms; | |
342 EXPECT_EQ(10 * samples_per_ms, frame.samples_per_channel_); | |
343 EXPECT_EQ(output_sample_rate_hz, frame.sample_rate_hz_); | |
344 EXPECT_EQ(output_channels, frame.num_channels_); | |
345 EXPECT_EQ(AudioFrame::kNormalSpeech, frame.speech_type_); | |
346 EXPECT_EQ(expected_vad_activity, frame.vad_activity_); | |
347 } | |
348 } | |
349 } | |
350 | |
292 #if defined(WEBRTC_ANDROID) | 351 #if defined(WEBRTC_ANDROID) |
293 #define MAYBE_PostdecodingVad DISABLED_PostdecodingVad | 352 #define MAYBE_PostdecodingVad DISABLED_PostdecodingVad |
294 #else | 353 #else |
295 #define MAYBE_PostdecodingVad PostdecodingVad | 354 #define MAYBE_PostdecodingVad PostdecodingVad |
296 #endif | 355 #endif |
297 TEST_F(AcmReceiverTestOldApi, MAYBE_PostdecodingVad) { | 356 TEST_F(AcmReceiverTestOldApi, MAYBE_PostdecodingVad) { |
298 EXPECT_TRUE(config_.neteq_config.enable_post_decode_vad); | 357 EXPECT_TRUE(config_.neteq_config.enable_post_decode_vad); |
299 const CodecIdInst codec(RentACodec::CodecId::kPCM16Bwb); | 358 const CodecIdInst codec(RentACodec::CodecId::kPCM16Bwb); |
300 ASSERT_EQ( | 359 ASSERT_EQ( |
301 0, receiver_->AddCodec(codec.id, codec.inst.pltype, codec.inst.channels, | 360 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()); | 466 receiver_->last_packet_sample_rate_hz()); |
408 EXPECT_EQ(0, receiver_->LastAudioCodec(&codec)); | 467 EXPECT_EQ(0, receiver_->LastAudioCodec(&codec)); |
409 EXPECT_TRUE(CodecsEqual(c.inst, codec)); | 468 EXPECT_TRUE(CodecsEqual(c.inst, codec)); |
410 } | 469 } |
411 } | 470 } |
412 #endif | 471 #endif |
413 | 472 |
414 } // namespace acm2 | 473 } // namespace acm2 |
415 | 474 |
416 } // namespace webrtc | 475 } // namespace webrtc |
OLD | NEW |