blob: 350183bf3aa1b4878d1e71e199c79de692171dd3 [file] [log] [blame]
andresp@webrtc.org4f6f22f2014-09-23 11:37:57 +00001/*
2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved.
3 *
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
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020011#include "modules/audio_coding/acm2/acm_receiver.h"
andresp@webrtc.org4f6f22f2014-09-23 11:37:57 +000012
13#include <algorithm> // std::min
kwiberg16c5a962016-02-15 02:27:22 -080014#include <memory>
andresp@webrtc.org4f6f22f2014-09-23 11:37:57 +000015
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020016#include "api/audio_codecs/builtin_audio_decoder_factory.h"
17#include "modules/audio_coding/acm2/rent_a_codec.h"
18#include "modules/audio_coding/include/audio_coding_module.h"
19#include "modules/audio_coding/neteq/tools/rtp_generator.h"
Fredrik Solenbergbbf21a32018-04-12 22:44:09 +020020#include "modules/include/module_common_types.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020021#include "rtc_base/checks.h"
Karl Wiberge40468b2017-11-22 10:42:26 +010022#include "rtc_base/numerics/safe_conversions.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020023#include "system_wrappers/include/clock.h"
24#include "test/gtest.h"
25#include "test/testsupport/fileutils.h"
andresp@webrtc.org4f6f22f2014-09-23 11:37:57 +000026
27namespace webrtc {
28
29namespace acm2 {
30namespace {
31
32bool CodecsEqual(const CodecInst& codec_a, const CodecInst& codec_b) {
Yves Gerey665174f2018-06-19 15:03:05 +020033 if (strcmp(codec_a.plname, codec_b.plname) != 0 ||
34 codec_a.plfreq != codec_b.plfreq || codec_a.pltype != codec_b.pltype ||
35 codec_b.channels != codec_a.channels)
36 return false;
37 return true;
andresp@webrtc.org4f6f22f2014-09-23 11:37:57 +000038}
39
kwibergfce4a942015-10-27 11:40:24 -070040struct CodecIdInst {
41 explicit CodecIdInst(RentACodec::CodecId codec_id) {
42 const auto codec_ix = RentACodec::CodecIndexFromId(codec_id);
43 EXPECT_TRUE(codec_ix);
44 id = *codec_ix;
45 const auto codec_inst = RentACodec::CodecInstById(codec_id);
46 EXPECT_TRUE(codec_inst);
47 inst = *codec_inst;
48 }
49 int id;
50 CodecInst inst;
51};
52
andresp@webrtc.org4f6f22f2014-09-23 11:37:57 +000053} // namespace
54
55class AcmReceiverTestOldApi : public AudioPacketizationCallback,
56 public ::testing::Test {
57 protected:
58 AcmReceiverTestOldApi()
59 : timestamp_(0),
60 packet_sent_(false),
61 last_packet_send_timestamp_(timestamp_),
pbos22993e12015-10-19 02:39:06 -070062 last_frame_type_(kEmptyFrame) {
ossue3525782016-05-25 07:37:43 -070063 config_.decoder_factory = CreateBuiltinAudioDecoderFactory();
andresp@webrtc.org4f6f22f2014-09-23 11:37:57 +000064 }
65
66 ~AcmReceiverTestOldApi() {}
67
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +000068 void SetUp() override {
kwibergc13ded52016-06-17 06:00:45 -070069 acm_.reset(AudioCodingModule::Create(config_));
henrik.lundin500c04b2016-03-08 02:36:04 -080070 receiver_.reset(new AcmReceiver(config_));
andresp@webrtc.org4f6f22f2014-09-23 11:37:57 +000071 ASSERT_TRUE(receiver_.get() != NULL);
72 ASSERT_TRUE(acm_.get() != NULL);
kwibergfce4a942015-10-27 11:40:24 -070073 codecs_ = RentACodec::Database();
andresp@webrtc.org4f6f22f2014-09-23 11:37:57 +000074
75 acm_->InitializeReceiver();
andresp@webrtc.org4f6f22f2014-09-23 11:37:57 +000076 acm_->RegisterTransportCallback(this);
77
78 rtp_header_.header.sequenceNumber = 0;
79 rtp_header_.header.timestamp = 0;
80 rtp_header_.header.markerBit = false;
81 rtp_header_.header.ssrc = 0x12345678; // Arbitrary.
82 rtp_header_.header.numCSRCs = 0;
83 rtp_header_.header.payloadType = 0;
84 rtp_header_.frameType = kAudioFrameSpeech;
85 rtp_header_.type.Audio.isCNG = false;
86 }
87
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +000088 void TearDown() override {}
andresp@webrtc.org4f6f22f2014-09-23 11:37:57 +000089
90 void InsertOnePacketOfSilence(int codec_id) {
kwibergd6c0f8c2015-11-06 14:28:00 -080091 CodecInst codec =
92 *RentACodec::CodecInstById(*RentACodec::CodecIdFromIndex(codec_id));
andresp@webrtc.org4f6f22f2014-09-23 11:37:57 +000093 if (timestamp_ == 0) { // This is the first time inserting audio.
94 ASSERT_EQ(0, acm_->RegisterSendCodec(codec));
95 } else {
kwiberg1fd4a4a2015-11-03 11:20:50 -080096 auto current_codec = acm_->SendCodec();
97 ASSERT_TRUE(current_codec);
98 if (!CodecsEqual(codec, *current_codec))
andresp@webrtc.org4f6f22f2014-09-23 11:37:57 +000099 ASSERT_EQ(0, acm_->RegisterSendCodec(codec));
100 }
101 AudioFrame frame;
102 // Frame setup according to the codec.
103 frame.sample_rate_hz_ = codec.plfreq;
104 frame.samples_per_channel_ = codec.plfreq / 100; // 10 ms.
105 frame.num_channels_ = codec.channels;
yujo36b1a5f2017-06-12 12:45:32 -0700106 frame.Mute();
andresp@webrtc.org4f6f22f2014-09-23 11:37:57 +0000107 packet_sent_ = false;
108 last_packet_send_timestamp_ = timestamp_;
henrik.lundin@webrtc.orgf56c1622015-03-02 12:29:30 +0000109 while (!packet_sent_) {
andresp@webrtc.org4f6f22f2014-09-23 11:37:57 +0000110 frame.timestamp_ = timestamp_;
Mirko Bonadei737e0732017-10-19 09:00:17 +0200111 timestamp_ += rtc::checked_cast<uint32_t>(frame.samples_per_channel_);
henrik.lundin@webrtc.orgf56c1622015-03-02 12:29:30 +0000112 ASSERT_GE(acm_->Add10MsData(frame), 0);
andresp@webrtc.org4f6f22f2014-09-23 11:37:57 +0000113 }
andresp@webrtc.org4f6f22f2014-09-23 11:37:57 +0000114 }
115
kwibergfce4a942015-10-27 11:40:24 -0700116 template <size_t N>
Yves Gerey665174f2018-06-19 15:03:05 +0200117 void AddSetOfCodecs(const RentACodec::CodecId (&ids)[N]) {
kwibergfce4a942015-10-27 11:40:24 -0700118 for (auto id : ids) {
119 const auto i = RentACodec::CodecIndexFromId(id);
120 ASSERT_TRUE(i);
kwiberg6f0f6162016-09-20 03:07:46 -0700121 ASSERT_EQ(0, receiver_->AddCodec(*i, codecs_[*i].pltype,
122 codecs_[*i].channels, codecs_[*i].plfreq,
123 nullptr, codecs_[*i].plname));
andresp@webrtc.org4f6f22f2014-09-23 11:37:57 +0000124 }
125 }
126
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000127 int SendData(FrameType frame_type,
128 uint8_t payload_type,
129 uint32_t timestamp,
130 const uint8_t* payload_data,
131 size_t payload_len_bytes,
132 const RTPFragmentationHeader* fragmentation) override {
pbos22993e12015-10-19 02:39:06 -0700133 if (frame_type == kEmptyFrame)
andresp@webrtc.org4f6f22f2014-09-23 11:37:57 +0000134 return 0;
135
136 rtp_header_.header.payloadType = payload_type;
137 rtp_header_.frameType = frame_type;
138 if (frame_type == kAudioFrameSpeech)
139 rtp_header_.type.Audio.isCNG = false;
140 else
141 rtp_header_.type.Audio.isCNG = true;
142 rtp_header_.header.timestamp = timestamp;
143
kwibergee2bac22015-11-11 10:34:00 -0800144 int ret_val = receiver_->InsertPacket(
145 rtp_header_,
146 rtc::ArrayView<const uint8_t>(payload_data, payload_len_bytes));
andresp@webrtc.org4f6f22f2014-09-23 11:37:57 +0000147 if (ret_val < 0) {
148 assert(false);
149 return -1;
150 }
151 rtp_header_.header.sequenceNumber++;
152 packet_sent_ = true;
153 last_frame_type_ = frame_type;
154 return 0;
155 }
156
henrik.lundin500c04b2016-03-08 02:36:04 -0800157 AudioCodingModule::Config config_;
kwiberg16c5a962016-02-15 02:27:22 -0800158 std::unique_ptr<AcmReceiver> receiver_;
kwibergfce4a942015-10-27 11:40:24 -0700159 rtc::ArrayView<const CodecInst> codecs_;
kwiberg16c5a962016-02-15 02:27:22 -0800160 std::unique_ptr<AudioCodingModule> acm_;
andresp@webrtc.org4f6f22f2014-09-23 11:37:57 +0000161 WebRtcRTPHeader rtp_header_;
162 uint32_t timestamp_;
163 bool packet_sent_; // Set when SendData is called reset when inserting audio.
164 uint32_t last_packet_send_timestamp_;
165 FrameType last_frame_type_;
166};
167
Peter Boströme2976c82016-01-04 22:44:05 +0100168#if defined(WEBRTC_ANDROID)
169#define MAYBE_AddCodecGetCodec DISABLED_AddCodecGetCodec
170#else
171#define MAYBE_AddCodecGetCodec AddCodecGetCodec
172#endif
173TEST_F(AcmReceiverTestOldApi, MAYBE_AddCodecGetCodec) {
andresp@webrtc.org4f6f22f2014-09-23 11:37:57 +0000174 // Add codec.
kwibergfce4a942015-10-27 11:40:24 -0700175 for (size_t n = 0; n < codecs_.size(); ++n) {
kwibergd1201922016-09-20 15:18:21 -0700176 if (n & 0x1) { // Just add codecs with odd index.
177 EXPECT_EQ(
Mirko Bonadei737e0732017-10-19 09:00:17 +0200178 0, receiver_->AddCodec(rtc::checked_cast<int>(n), codecs_[n].pltype,
179 codecs_[n].channels, codecs_[n].plfreq, NULL,
180 codecs_[n].plname));
kwibergd1201922016-09-20 15:18:21 -0700181 }
andresp@webrtc.org4f6f22f2014-09-23 11:37:57 +0000182 }
183 // Get codec and compare.
kwibergfce4a942015-10-27 11:40:24 -0700184 for (size_t n = 0; n < codecs_.size(); ++n) {
andresp@webrtc.org4f6f22f2014-09-23 11:37:57 +0000185 CodecInst my_codec;
186 if (n & 0x1) {
187 // Codecs with odd index should match the reference.
Yves Gerey665174f2018-06-19 15:03:05 +0200188 EXPECT_EQ(0,
189 receiver_->DecoderByPayloadType(codecs_[n].pltype, &my_codec));
andresp@webrtc.org4f6f22f2014-09-23 11:37:57 +0000190 EXPECT_TRUE(CodecsEqual(codecs_[n], my_codec));
191 } else {
192 // Codecs with even index are not registered.
Yves Gerey665174f2018-06-19 15:03:05 +0200193 EXPECT_EQ(-1,
194 receiver_->DecoderByPayloadType(codecs_[n].pltype, &my_codec));
andresp@webrtc.org4f6f22f2014-09-23 11:37:57 +0000195 }
196 }
197}
198
Peter Boströme2976c82016-01-04 22:44:05 +0100199#if defined(WEBRTC_ANDROID)
200#define MAYBE_AddCodecChangePayloadType DISABLED_AddCodecChangePayloadType
201#else
202#define MAYBE_AddCodecChangePayloadType AddCodecChangePayloadType
203#endif
204TEST_F(AcmReceiverTestOldApi, MAYBE_AddCodecChangePayloadType) {
kwibergfce4a942015-10-27 11:40:24 -0700205 const CodecIdInst codec1(RentACodec::CodecId::kPCMA);
206 CodecInst codec2 = codec1.inst;
207 ++codec2.pltype;
andresp@webrtc.org4f6f22f2014-09-23 11:37:57 +0000208 CodecInst test_codec;
andresp@webrtc.org4f6f22f2014-09-23 11:37:57 +0000209
Jelena Marusica9907842015-03-26 14:01:30 +0100210 // Register the same codec with different payloads.
kwibergfce4a942015-10-27 11:40:24 -0700211 EXPECT_EQ(0, receiver_->AddCodec(codec1.id, codec1.inst.pltype,
212 codec1.inst.channels, codec1.inst.plfreq,
kwibergd1201922016-09-20 15:18:21 -0700213 nullptr, codec1.inst.plname));
kwibergfce4a942015-10-27 11:40:24 -0700214 EXPECT_EQ(0, receiver_->AddCodec(codec1.id, codec2.pltype, codec2.channels,
kwibergd1201922016-09-20 15:18:21 -0700215 codec2.plfreq, NULL, codec2.plname));
andresp@webrtc.org4f6f22f2014-09-23 11:37:57 +0000216
Jelena Marusica9907842015-03-26 14:01:30 +0100217 // Both payload types should exist.
kwibergfce4a942015-10-27 11:40:24 -0700218 EXPECT_EQ(0,
219 receiver_->DecoderByPayloadType(codec1.inst.pltype, &test_codec));
220 EXPECT_EQ(true, CodecsEqual(codec1.inst, test_codec));
221 EXPECT_EQ(0, receiver_->DecoderByPayloadType(codec2.pltype, &test_codec));
222 EXPECT_EQ(true, CodecsEqual(codec2, test_codec));
Jelena Marusica9907842015-03-26 14:01:30 +0100223}
andresp@webrtc.org4f6f22f2014-09-23 11:37:57 +0000224
Peter Boströme2976c82016-01-04 22:44:05 +0100225#if defined(WEBRTC_ANDROID)
226#define MAYBE_AddCodecChangeCodecId DISABLED_AddCodecChangeCodecId
227#else
228#define MAYBE_AddCodecChangeCodecId AddCodecChangeCodecId
229#endif
230TEST_F(AcmReceiverTestOldApi, AddCodecChangeCodecId) {
kwibergfce4a942015-10-27 11:40:24 -0700231 const CodecIdInst codec1(RentACodec::CodecId::kPCMU);
232 CodecIdInst codec2(RentACodec::CodecId::kPCMA);
233 codec2.inst.pltype = codec1.inst.pltype;
Jelena Marusica9907842015-03-26 14:01:30 +0100234 CodecInst test_codec;
235
236 // Register the same payload type with different codec ID.
kwibergfce4a942015-10-27 11:40:24 -0700237 EXPECT_EQ(0, receiver_->AddCodec(codec1.id, codec1.inst.pltype,
238 codec1.inst.channels, codec1.inst.plfreq,
kwibergd1201922016-09-20 15:18:21 -0700239 nullptr, codec1.inst.plname));
kwibergfce4a942015-10-27 11:40:24 -0700240 EXPECT_EQ(0, receiver_->AddCodec(codec2.id, codec2.inst.pltype,
241 codec2.inst.channels, codec2.inst.plfreq,
kwibergd1201922016-09-20 15:18:21 -0700242 nullptr, codec2.inst.plname));
Jelena Marusica9907842015-03-26 14:01:30 +0100243
244 // Make sure that the last codec is used.
kwibergfce4a942015-10-27 11:40:24 -0700245 EXPECT_EQ(0,
246 receiver_->DecoderByPayloadType(codec2.inst.pltype, &test_codec));
247 EXPECT_EQ(true, CodecsEqual(codec2.inst, test_codec));
andresp@webrtc.org4f6f22f2014-09-23 11:37:57 +0000248}
249
Peter Boströme2976c82016-01-04 22:44:05 +0100250#if defined(WEBRTC_ANDROID)
251#define MAYBE_AddCodecRemoveCodec DISABLED_AddCodecRemoveCodec
252#else
253#define MAYBE_AddCodecRemoveCodec AddCodecRemoveCodec
254#endif
255TEST_F(AcmReceiverTestOldApi, MAYBE_AddCodecRemoveCodec) {
kwibergfce4a942015-10-27 11:40:24 -0700256 const CodecIdInst codec(RentACodec::CodecId::kPCMA);
257 const int payload_type = codec.inst.pltype;
258 EXPECT_EQ(
259 0, receiver_->AddCodec(codec.id, codec.inst.pltype, codec.inst.channels,
kwibergd1201922016-09-20 15:18:21 -0700260 codec.inst.plfreq, nullptr, codec.inst.plname));
andresp@webrtc.org4f6f22f2014-09-23 11:37:57 +0000261
262 // Remove non-existing codec should not fail. ACM1 legacy.
263 EXPECT_EQ(0, receiver_->RemoveCodec(payload_type + 1));
264
265 // Remove an existing codec.
266 EXPECT_EQ(0, receiver_->RemoveCodec(payload_type));
267
268 // Ask for the removed codec, must fail.
kwibergfce4a942015-10-27 11:40:24 -0700269 CodecInst ci;
270 EXPECT_EQ(-1, receiver_->DecoderByPayloadType(payload_type, &ci));
andresp@webrtc.org4f6f22f2014-09-23 11:37:57 +0000271}
272
Peter Boströme2976c82016-01-04 22:44:05 +0100273#if defined(WEBRTC_ANDROID)
274#define MAYBE_SampleRate DISABLED_SampleRate
275#else
276#define MAYBE_SampleRate SampleRate
277#endif
278TEST_F(AcmReceiverTestOldApi, MAYBE_SampleRate) {
kwibergfce4a942015-10-27 11:40:24 -0700279 const RentACodec::CodecId kCodecId[] = {RentACodec::CodecId::kISAC,
280 RentACodec::CodecId::kISACSWB};
andresp@webrtc.org4f6f22f2014-09-23 11:37:57 +0000281 AddSetOfCodecs(kCodecId);
282
283 AudioFrame frame;
284 const int kOutSampleRateHz = 8000; // Different than codec sample rate.
kwibergfce4a942015-10-27 11:40:24 -0700285 for (const auto codec_id : kCodecId) {
286 const CodecIdInst codec(codec_id);
287 const int num_10ms_frames = codec.inst.pacsize / (codec.inst.plfreq / 100);
288 InsertOnePacketOfSilence(codec.id);
andresp@webrtc.org4f6f22f2014-09-23 11:37:57 +0000289 for (int k = 0; k < num_10ms_frames; ++k) {
henrik.lundin834a6ea2016-05-13 03:45:24 -0700290 bool muted;
291 EXPECT_EQ(0, receiver_->GetAudio(kOutSampleRateHz, &frame, &muted));
andresp@webrtc.org4f6f22f2014-09-23 11:37:57 +0000292 }
henrik.lundind89814b2015-11-23 06:49:25 -0800293 EXPECT_EQ(codec.inst.plfreq, receiver_->last_output_sample_rate_hz());
andresp@webrtc.org4f6f22f2014-09-23 11:37:57 +0000294 }
295}
296
henrik.lundin7dc68892016-04-06 01:03:02 -0700297class AcmReceiverTestFaxModeOldApi : public AcmReceiverTestOldApi {
298 protected:
299 AcmReceiverTestFaxModeOldApi() {
300 config_.neteq_config.playout_mode = kPlayoutFax;
301 }
302
303 void RunVerifyAudioFrame(RentACodec::CodecId codec_id) {
304 // Make sure "fax mode" is enabled. This will avoid delay changes unless the
305 // packet-loss concealment is made. We do this in order to make the
306 // timestamp increments predictable; in normal mode, NetEq may decide to do
307 // accelerate or pre-emptive expand operations after some time, offsetting
308 // the timestamp.
309 EXPECT_EQ(kPlayoutFax, config_.neteq_config.playout_mode);
310
311 const RentACodec::CodecId kCodecId[] = {codec_id};
312 AddSetOfCodecs(kCodecId);
313
314 const CodecIdInst codec(codec_id);
315 const int output_sample_rate_hz = codec.inst.plfreq;
316 const size_t output_channels = codec.inst.channels;
317 const size_t samples_per_ms = rtc::checked_cast<size_t>(
318 rtc::CheckedDivExact(output_sample_rate_hz, 1000));
319 const int num_10ms_frames = rtc::CheckedDivExact(
320 codec.inst.pacsize, rtc::checked_cast<int>(10 * samples_per_ms));
321 const AudioFrame::VADActivity expected_vad_activity =
322 output_sample_rate_hz > 16000 ? AudioFrame::kVadActive
323 : AudioFrame::kVadPassive;
324
325 // Expect the first output timestamp to be 5*fs/8000 samples before the
326 // first inserted timestamp (because of NetEq's look-ahead). (This value is
327 // defined in Expand::overlap_length_.)
Yves Gerey665174f2018-06-19 15:03:05 +0200328 uint32_t expected_output_ts =
329 last_packet_send_timestamp_ -
henrik.lundin7dc68892016-04-06 01:03:02 -0700330 rtc::CheckedDivExact(5 * output_sample_rate_hz, 8000);
331
332 AudioFrame frame;
henrik.lundin834a6ea2016-05-13 03:45:24 -0700333 bool muted;
334 EXPECT_EQ(0, receiver_->GetAudio(output_sample_rate_hz, &frame, &muted));
henrik.lundin15c51e32016-04-06 08:38:56 -0700335 // Expect timestamp = 0 before first packet is inserted.
336 EXPECT_EQ(0u, frame.timestamp_);
henrik.lundin7dc68892016-04-06 01:03:02 -0700337 for (int i = 0; i < 5; ++i) {
338 InsertOnePacketOfSilence(codec.id);
339 for (int k = 0; k < num_10ms_frames; ++k) {
henrik.lundin834a6ea2016-05-13 03:45:24 -0700340 EXPECT_EQ(0,
341 receiver_->GetAudio(output_sample_rate_hz, &frame, &muted));
henrik.lundin7dc68892016-04-06 01:03:02 -0700342 EXPECT_EQ(expected_output_ts, frame.timestamp_);
Mirko Bonadei737e0732017-10-19 09:00:17 +0200343 expected_output_ts += rtc::checked_cast<uint32_t>(10 * samples_per_ms);
henrik.lundin7dc68892016-04-06 01:03:02 -0700344 EXPECT_EQ(10 * samples_per_ms, frame.samples_per_channel_);
345 EXPECT_EQ(output_sample_rate_hz, frame.sample_rate_hz_);
346 EXPECT_EQ(output_channels, frame.num_channels_);
347 EXPECT_EQ(AudioFrame::kNormalSpeech, frame.speech_type_);
348 EXPECT_EQ(expected_vad_activity, frame.vad_activity_);
henrik.lundin834a6ea2016-05-13 03:45:24 -0700349 EXPECT_FALSE(muted);
henrik.lundin7dc68892016-04-06 01:03:02 -0700350 }
351 }
352 }
353};
354
355#if defined(WEBRTC_ANDROID)
356#define MAYBE_VerifyAudioFramePCMU DISABLED_VerifyAudioFramePCMU
357#else
358#define MAYBE_VerifyAudioFramePCMU VerifyAudioFramePCMU
359#endif
360TEST_F(AcmReceiverTestFaxModeOldApi, MAYBE_VerifyAudioFramePCMU) {
361 RunVerifyAudioFrame(RentACodec::CodecId::kPCMU);
362}
363
364#if defined(WEBRTC_ANDROID)
365#define MAYBE_VerifyAudioFrameISAC DISABLED_VerifyAudioFrameISAC
366#else
367#define MAYBE_VerifyAudioFrameISAC VerifyAudioFrameISAC
368#endif
369TEST_F(AcmReceiverTestFaxModeOldApi, MAYBE_VerifyAudioFrameISAC) {
370 RunVerifyAudioFrame(RentACodec::CodecId::kISAC);
371}
372
373#if defined(WEBRTC_ANDROID)
374#define MAYBE_VerifyAudioFrameOpus DISABLED_VerifyAudioFrameOpus
375#else
376#define MAYBE_VerifyAudioFrameOpus VerifyAudioFrameOpus
377#endif
378TEST_F(AcmReceiverTestFaxModeOldApi, MAYBE_VerifyAudioFrameOpus) {
379 RunVerifyAudioFrame(RentACodec::CodecId::kOpus);
380}
381
Peter Boströme2976c82016-01-04 22:44:05 +0100382#if defined(WEBRTC_ANDROID)
383#define MAYBE_PostdecodingVad DISABLED_PostdecodingVad
384#else
385#define MAYBE_PostdecodingVad PostdecodingVad
386#endif
387TEST_F(AcmReceiverTestOldApi, MAYBE_PostdecodingVad) {
henrik.lundin500c04b2016-03-08 02:36:04 -0800388 EXPECT_TRUE(config_.neteq_config.enable_post_decode_vad);
kwibergfce4a942015-10-27 11:40:24 -0700389 const CodecIdInst codec(RentACodec::CodecId::kPCM16Bwb);
390 ASSERT_EQ(
391 0, receiver_->AddCodec(codec.id, codec.inst.pltype, codec.inst.channels,
henrik.lundin4cf61dd2015-12-09 06:20:58 -0800392 codec.inst.plfreq, nullptr, ""));
andresp@webrtc.org4f6f22f2014-09-23 11:37:57 +0000393 const int kNumPackets = 5;
kwibergfce4a942015-10-27 11:40:24 -0700394 const int num_10ms_frames = codec.inst.pacsize / (codec.inst.plfreq / 100);
andresp@webrtc.org4f6f22f2014-09-23 11:37:57 +0000395 AudioFrame frame;
396 for (int n = 0; n < kNumPackets; ++n) {
kwibergfce4a942015-10-27 11:40:24 -0700397 InsertOnePacketOfSilence(codec.id);
henrik.lundin834a6ea2016-05-13 03:45:24 -0700398 for (int k = 0; k < num_10ms_frames; ++k) {
399 bool muted;
400 ASSERT_EQ(0, receiver_->GetAudio(codec.inst.plfreq, &frame, &muted));
401 }
andresp@webrtc.org4f6f22f2014-09-23 11:37:57 +0000402 }
403 EXPECT_EQ(AudioFrame::kVadPassive, frame.vad_activity_);
henrik.lundin500c04b2016-03-08 02:36:04 -0800404}
andresp@webrtc.org4f6f22f2014-09-23 11:37:57 +0000405
henrik.lundin500c04b2016-03-08 02:36:04 -0800406class AcmReceiverTestPostDecodeVadPassiveOldApi : public AcmReceiverTestOldApi {
407 protected:
408 AcmReceiverTestPostDecodeVadPassiveOldApi() {
409 config_.neteq_config.enable_post_decode_vad = false;
410 }
411};
andresp@webrtc.org4f6f22f2014-09-23 11:37:57 +0000412
henrik.lundin500c04b2016-03-08 02:36:04 -0800413#if defined(WEBRTC_ANDROID)
414#define MAYBE_PostdecodingVad DISABLED_PostdecodingVad
415#else
416#define MAYBE_PostdecodingVad PostdecodingVad
417#endif
418TEST_F(AcmReceiverTestPostDecodeVadPassiveOldApi, MAYBE_PostdecodingVad) {
419 EXPECT_FALSE(config_.neteq_config.enable_post_decode_vad);
420 const CodecIdInst codec(RentACodec::CodecId::kPCM16Bwb);
421 ASSERT_EQ(
422 0, receiver_->AddCodec(codec.id, codec.inst.pltype, codec.inst.channels,
423 codec.inst.plfreq, nullptr, ""));
424 const int kNumPackets = 5;
425 const int num_10ms_frames = codec.inst.pacsize / (codec.inst.plfreq / 100);
426 AudioFrame frame;
andresp@webrtc.org4f6f22f2014-09-23 11:37:57 +0000427 for (int n = 0; n < kNumPackets; ++n) {
kwibergfce4a942015-10-27 11:40:24 -0700428 InsertOnePacketOfSilence(codec.id);
henrik.lundin834a6ea2016-05-13 03:45:24 -0700429 for (int k = 0; k < num_10ms_frames; ++k) {
430 bool muted;
431 ASSERT_EQ(0, receiver_->GetAudio(codec.inst.plfreq, &frame, &muted));
432 }
andresp@webrtc.org4f6f22f2014-09-23 11:37:57 +0000433 }
434 EXPECT_EQ(AudioFrame::kVadUnknown, frame.vad_activity_);
435}
436
Peter Boströme2976c82016-01-04 22:44:05 +0100437#if defined(WEBRTC_ANDROID)
438#define MAYBE_LastAudioCodec DISABLED_LastAudioCodec
kwiberg98ab3a42015-09-30 21:54:21 -0700439#else
Peter Boströme2976c82016-01-04 22:44:05 +0100440#define MAYBE_LastAudioCodec LastAudioCodec
kwiberg98ab3a42015-09-30 21:54:21 -0700441#endif
Peter Boströme2976c82016-01-04 22:44:05 +0100442#if defined(WEBRTC_CODEC_ISAC)
443TEST_F(AcmReceiverTestOldApi, MAYBE_LastAudioCodec) {
kwibergfce4a942015-10-27 11:40:24 -0700444 const RentACodec::CodecId kCodecId[] = {
445 RentACodec::CodecId::kISAC, RentACodec::CodecId::kPCMA,
446 RentACodec::CodecId::kISACSWB, RentACodec::CodecId::kPCM16Bswb32kHz};
andresp@webrtc.org4f6f22f2014-09-23 11:37:57 +0000447 AddSetOfCodecs(kCodecId);
448
kwibergfce4a942015-10-27 11:40:24 -0700449 const RentACodec::CodecId kCngId[] = {
450 // Not including full-band.
451 RentACodec::CodecId::kCNNB, RentACodec::CodecId::kCNWB,
452 RentACodec::CodecId::kCNSWB};
andresp@webrtc.org4f6f22f2014-09-23 11:37:57 +0000453 AddSetOfCodecs(kCngId);
454
455 // Register CNG at sender side.
kwibergfce4a942015-10-27 11:40:24 -0700456 for (auto id : kCngId)
457 ASSERT_EQ(0, acm_->RegisterSendCodec(CodecIdInst(id).inst));
andresp@webrtc.org4f6f22f2014-09-23 11:37:57 +0000458
459 CodecInst codec;
460 // No audio payload is received.
461 EXPECT_EQ(-1, receiver_->LastAudioCodec(&codec));
462
463 // Start with sending DTX.
464 ASSERT_EQ(0, acm_->SetVAD(true, true, VADVeryAggr));
465 packet_sent_ = false;
kwibergfce4a942015-10-27 11:40:24 -0700466 InsertOnePacketOfSilence(CodecIdInst(kCodecId[0]).id); // Enough to test
467 // with one codec.
andresp@webrtc.org4f6f22f2014-09-23 11:37:57 +0000468 ASSERT_TRUE(packet_sent_);
469 EXPECT_EQ(kAudioFrameCN, last_frame_type_);
470
471 // Has received, only, DTX. Last Audio codec is undefined.
472 EXPECT_EQ(-1, receiver_->LastAudioCodec(&codec));
henrik.lundin057fb892015-11-23 08:19:52 -0800473 EXPECT_FALSE(receiver_->last_packet_sample_rate_hz());
andresp@webrtc.org4f6f22f2014-09-23 11:37:57 +0000474
kwibergfce4a942015-10-27 11:40:24 -0700475 for (auto id : kCodecId) {
476 const CodecIdInst c(id);
477
andresp@webrtc.org4f6f22f2014-09-23 11:37:57 +0000478 // Set DTX off to send audio payload.
479 acm_->SetVAD(false, false, VADAggr);
480 packet_sent_ = false;
kwibergfce4a942015-10-27 11:40:24 -0700481 InsertOnePacketOfSilence(c.id);
andresp@webrtc.org4f6f22f2014-09-23 11:37:57 +0000482
483 // Sanity check if Actually an audio payload received, and it should be
484 // of type "speech."
485 ASSERT_TRUE(packet_sent_);
486 ASSERT_EQ(kAudioFrameSpeech, last_frame_type_);
Oskar Sundbom12ab00b2017-11-16 15:31:38 +0100487 EXPECT_EQ(c.inst.plfreq, receiver_->last_packet_sample_rate_hz());
andresp@webrtc.org4f6f22f2014-09-23 11:37:57 +0000488
489 // Set VAD on to send DTX. Then check if the "Last Audio codec" returns
490 // the expected codec.
491 acm_->SetVAD(true, true, VADAggr);
492
493 // Do as many encoding until a DTX is sent.
494 while (last_frame_type_ != kAudioFrameCN) {
495 packet_sent_ = false;
kwibergfce4a942015-10-27 11:40:24 -0700496 InsertOnePacketOfSilence(c.id);
andresp@webrtc.org4f6f22f2014-09-23 11:37:57 +0000497 ASSERT_TRUE(packet_sent_);
498 }
Oskar Sundbom12ab00b2017-11-16 15:31:38 +0100499 EXPECT_EQ(c.inst.plfreq, receiver_->last_packet_sample_rate_hz());
andresp@webrtc.org4f6f22f2014-09-23 11:37:57 +0000500 EXPECT_EQ(0, receiver_->LastAudioCodec(&codec));
kwibergfce4a942015-10-27 11:40:24 -0700501 EXPECT_TRUE(CodecsEqual(c.inst, codec));
andresp@webrtc.org4f6f22f2014-09-23 11:37:57 +0000502 }
503}
Peter Boströme2976c82016-01-04 22:44:05 +0100504#endif
andresp@webrtc.org4f6f22f2014-09-23 11:37:57 +0000505
506} // namespace acm2
507
508} // namespace webrtc