blob: d1cff235c2147cc9440ca685f6539e45849c1303 [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;
andresp@webrtc.org4f6f22f2014-09-23 11:37:57 +000085 }
86
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +000087 void TearDown() override {}
andresp@webrtc.org4f6f22f2014-09-23 11:37:57 +000088
89 void InsertOnePacketOfSilence(int codec_id) {
kwibergd6c0f8c2015-11-06 14:28:00 -080090 CodecInst codec =
91 *RentACodec::CodecInstById(*RentACodec::CodecIdFromIndex(codec_id));
andresp@webrtc.org4f6f22f2014-09-23 11:37:57 +000092 if (timestamp_ == 0) { // This is the first time inserting audio.
93 ASSERT_EQ(0, acm_->RegisterSendCodec(codec));
94 } else {
kwiberg1fd4a4a2015-11-03 11:20:50 -080095 auto current_codec = acm_->SendCodec();
96 ASSERT_TRUE(current_codec);
97 if (!CodecsEqual(codec, *current_codec))
andresp@webrtc.org4f6f22f2014-09-23 11:37:57 +000098 ASSERT_EQ(0, acm_->RegisterSendCodec(codec));
99 }
100 AudioFrame frame;
101 // Frame setup according to the codec.
102 frame.sample_rate_hz_ = codec.plfreq;
103 frame.samples_per_channel_ = codec.plfreq / 100; // 10 ms.
104 frame.num_channels_ = codec.channels;
yujo36b1a5f2017-06-12 12:45:32 -0700105 frame.Mute();
andresp@webrtc.org4f6f22f2014-09-23 11:37:57 +0000106 packet_sent_ = false;
107 last_packet_send_timestamp_ = timestamp_;
henrik.lundin@webrtc.orgf56c1622015-03-02 12:29:30 +0000108 while (!packet_sent_) {
andresp@webrtc.org4f6f22f2014-09-23 11:37:57 +0000109 frame.timestamp_ = timestamp_;
Mirko Bonadei737e0732017-10-19 09:00:17 +0200110 timestamp_ += rtc::checked_cast<uint32_t>(frame.samples_per_channel_);
henrik.lundin@webrtc.orgf56c1622015-03-02 12:29:30 +0000111 ASSERT_GE(acm_->Add10MsData(frame), 0);
andresp@webrtc.org4f6f22f2014-09-23 11:37:57 +0000112 }
andresp@webrtc.org4f6f22f2014-09-23 11:37:57 +0000113 }
114
kwibergfce4a942015-10-27 11:40:24 -0700115 template <size_t N>
Yves Gerey665174f2018-06-19 15:03:05 +0200116 void AddSetOfCodecs(const RentACodec::CodecId (&ids)[N]) {
kwibergfce4a942015-10-27 11:40:24 -0700117 for (auto id : ids) {
118 const auto i = RentACodec::CodecIndexFromId(id);
119 ASSERT_TRUE(i);
kwiberg6f0f6162016-09-20 03:07:46 -0700120 ASSERT_EQ(0, receiver_->AddCodec(*i, codecs_[*i].pltype,
121 codecs_[*i].channels, codecs_[*i].plfreq,
122 nullptr, codecs_[*i].plname));
andresp@webrtc.org4f6f22f2014-09-23 11:37:57 +0000123 }
124 }
125
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000126 int SendData(FrameType frame_type,
127 uint8_t payload_type,
128 uint32_t timestamp,
129 const uint8_t* payload_data,
130 size_t payload_len_bytes,
131 const RTPFragmentationHeader* fragmentation) override {
pbos22993e12015-10-19 02:39:06 -0700132 if (frame_type == kEmptyFrame)
andresp@webrtc.org4f6f22f2014-09-23 11:37:57 +0000133 return 0;
134
135 rtp_header_.header.payloadType = payload_type;
136 rtp_header_.frameType = frame_type;
andresp@webrtc.org4f6f22f2014-09-23 11:37:57 +0000137 rtp_header_.header.timestamp = timestamp;
138
kwibergee2bac22015-11-11 10:34:00 -0800139 int ret_val = receiver_->InsertPacket(
140 rtp_header_,
141 rtc::ArrayView<const uint8_t>(payload_data, payload_len_bytes));
andresp@webrtc.org4f6f22f2014-09-23 11:37:57 +0000142 if (ret_val < 0) {
143 assert(false);
144 return -1;
145 }
146 rtp_header_.header.sequenceNumber++;
147 packet_sent_ = true;
148 last_frame_type_ = frame_type;
149 return 0;
150 }
151
henrik.lundin500c04b2016-03-08 02:36:04 -0800152 AudioCodingModule::Config config_;
kwiberg16c5a962016-02-15 02:27:22 -0800153 std::unique_ptr<AcmReceiver> receiver_;
kwibergfce4a942015-10-27 11:40:24 -0700154 rtc::ArrayView<const CodecInst> codecs_;
kwiberg16c5a962016-02-15 02:27:22 -0800155 std::unique_ptr<AudioCodingModule> acm_;
andresp@webrtc.org4f6f22f2014-09-23 11:37:57 +0000156 WebRtcRTPHeader rtp_header_;
157 uint32_t timestamp_;
158 bool packet_sent_; // Set when SendData is called reset when inserting audio.
159 uint32_t last_packet_send_timestamp_;
160 FrameType last_frame_type_;
161};
162
Peter Boströme2976c82016-01-04 22:44:05 +0100163#if defined(WEBRTC_ANDROID)
164#define MAYBE_AddCodecGetCodec DISABLED_AddCodecGetCodec
165#else
166#define MAYBE_AddCodecGetCodec AddCodecGetCodec
167#endif
168TEST_F(AcmReceiverTestOldApi, MAYBE_AddCodecGetCodec) {
andresp@webrtc.org4f6f22f2014-09-23 11:37:57 +0000169 // Add codec.
kwibergfce4a942015-10-27 11:40:24 -0700170 for (size_t n = 0; n < codecs_.size(); ++n) {
kwibergd1201922016-09-20 15:18:21 -0700171 if (n & 0x1) { // Just add codecs with odd index.
172 EXPECT_EQ(
Mirko Bonadei737e0732017-10-19 09:00:17 +0200173 0, receiver_->AddCodec(rtc::checked_cast<int>(n), codecs_[n].pltype,
174 codecs_[n].channels, codecs_[n].plfreq, NULL,
175 codecs_[n].plname));
kwibergd1201922016-09-20 15:18:21 -0700176 }
andresp@webrtc.org4f6f22f2014-09-23 11:37:57 +0000177 }
178 // Get codec and compare.
kwibergfce4a942015-10-27 11:40:24 -0700179 for (size_t n = 0; n < codecs_.size(); ++n) {
andresp@webrtc.org4f6f22f2014-09-23 11:37:57 +0000180 CodecInst my_codec;
181 if (n & 0x1) {
182 // Codecs with odd index should match the reference.
Yves Gerey665174f2018-06-19 15:03:05 +0200183 EXPECT_EQ(0,
184 receiver_->DecoderByPayloadType(codecs_[n].pltype, &my_codec));
andresp@webrtc.org4f6f22f2014-09-23 11:37:57 +0000185 EXPECT_TRUE(CodecsEqual(codecs_[n], my_codec));
186 } else {
187 // Codecs with even index are not registered.
Yves Gerey665174f2018-06-19 15:03:05 +0200188 EXPECT_EQ(-1,
189 receiver_->DecoderByPayloadType(codecs_[n].pltype, &my_codec));
andresp@webrtc.org4f6f22f2014-09-23 11:37:57 +0000190 }
191 }
192}
193
Peter Boströme2976c82016-01-04 22:44:05 +0100194#if defined(WEBRTC_ANDROID)
195#define MAYBE_AddCodecChangePayloadType DISABLED_AddCodecChangePayloadType
196#else
197#define MAYBE_AddCodecChangePayloadType AddCodecChangePayloadType
198#endif
199TEST_F(AcmReceiverTestOldApi, MAYBE_AddCodecChangePayloadType) {
kwibergfce4a942015-10-27 11:40:24 -0700200 const CodecIdInst codec1(RentACodec::CodecId::kPCMA);
201 CodecInst codec2 = codec1.inst;
202 ++codec2.pltype;
andresp@webrtc.org4f6f22f2014-09-23 11:37:57 +0000203 CodecInst test_codec;
andresp@webrtc.org4f6f22f2014-09-23 11:37:57 +0000204
Jelena Marusica9907842015-03-26 14:01:30 +0100205 // Register the same codec with different payloads.
kwibergfce4a942015-10-27 11:40:24 -0700206 EXPECT_EQ(0, receiver_->AddCodec(codec1.id, codec1.inst.pltype,
207 codec1.inst.channels, codec1.inst.plfreq,
kwibergd1201922016-09-20 15:18:21 -0700208 nullptr, codec1.inst.plname));
kwibergfce4a942015-10-27 11:40:24 -0700209 EXPECT_EQ(0, receiver_->AddCodec(codec1.id, codec2.pltype, codec2.channels,
kwibergd1201922016-09-20 15:18:21 -0700210 codec2.plfreq, NULL, codec2.plname));
andresp@webrtc.org4f6f22f2014-09-23 11:37:57 +0000211
Jelena Marusica9907842015-03-26 14:01:30 +0100212 // Both payload types should exist.
kwibergfce4a942015-10-27 11:40:24 -0700213 EXPECT_EQ(0,
214 receiver_->DecoderByPayloadType(codec1.inst.pltype, &test_codec));
215 EXPECT_EQ(true, CodecsEqual(codec1.inst, test_codec));
216 EXPECT_EQ(0, receiver_->DecoderByPayloadType(codec2.pltype, &test_codec));
217 EXPECT_EQ(true, CodecsEqual(codec2, test_codec));
Jelena Marusica9907842015-03-26 14:01:30 +0100218}
andresp@webrtc.org4f6f22f2014-09-23 11:37:57 +0000219
Peter Boströme2976c82016-01-04 22:44:05 +0100220#if defined(WEBRTC_ANDROID)
221#define MAYBE_AddCodecChangeCodecId DISABLED_AddCodecChangeCodecId
222#else
223#define MAYBE_AddCodecChangeCodecId AddCodecChangeCodecId
224#endif
225TEST_F(AcmReceiverTestOldApi, AddCodecChangeCodecId) {
kwibergfce4a942015-10-27 11:40:24 -0700226 const CodecIdInst codec1(RentACodec::CodecId::kPCMU);
227 CodecIdInst codec2(RentACodec::CodecId::kPCMA);
228 codec2.inst.pltype = codec1.inst.pltype;
Jelena Marusica9907842015-03-26 14:01:30 +0100229 CodecInst test_codec;
230
231 // Register the same payload type with different codec ID.
kwibergfce4a942015-10-27 11:40:24 -0700232 EXPECT_EQ(0, receiver_->AddCodec(codec1.id, codec1.inst.pltype,
233 codec1.inst.channels, codec1.inst.plfreq,
kwibergd1201922016-09-20 15:18:21 -0700234 nullptr, codec1.inst.plname));
kwibergfce4a942015-10-27 11:40:24 -0700235 EXPECT_EQ(0, receiver_->AddCodec(codec2.id, codec2.inst.pltype,
236 codec2.inst.channels, codec2.inst.plfreq,
kwibergd1201922016-09-20 15:18:21 -0700237 nullptr, codec2.inst.plname));
Jelena Marusica9907842015-03-26 14:01:30 +0100238
239 // Make sure that the last codec is used.
kwibergfce4a942015-10-27 11:40:24 -0700240 EXPECT_EQ(0,
241 receiver_->DecoderByPayloadType(codec2.inst.pltype, &test_codec));
242 EXPECT_EQ(true, CodecsEqual(codec2.inst, test_codec));
andresp@webrtc.org4f6f22f2014-09-23 11:37:57 +0000243}
244
Peter Boströme2976c82016-01-04 22:44:05 +0100245#if defined(WEBRTC_ANDROID)
246#define MAYBE_AddCodecRemoveCodec DISABLED_AddCodecRemoveCodec
247#else
248#define MAYBE_AddCodecRemoveCodec AddCodecRemoveCodec
249#endif
250TEST_F(AcmReceiverTestOldApi, MAYBE_AddCodecRemoveCodec) {
kwibergfce4a942015-10-27 11:40:24 -0700251 const CodecIdInst codec(RentACodec::CodecId::kPCMA);
252 const int payload_type = codec.inst.pltype;
253 EXPECT_EQ(
254 0, receiver_->AddCodec(codec.id, codec.inst.pltype, codec.inst.channels,
kwibergd1201922016-09-20 15:18:21 -0700255 codec.inst.plfreq, nullptr, codec.inst.plname));
andresp@webrtc.org4f6f22f2014-09-23 11:37:57 +0000256
257 // Remove non-existing codec should not fail. ACM1 legacy.
258 EXPECT_EQ(0, receiver_->RemoveCodec(payload_type + 1));
259
260 // Remove an existing codec.
261 EXPECT_EQ(0, receiver_->RemoveCodec(payload_type));
262
263 // Ask for the removed codec, must fail.
kwibergfce4a942015-10-27 11:40:24 -0700264 CodecInst ci;
265 EXPECT_EQ(-1, receiver_->DecoderByPayloadType(payload_type, &ci));
andresp@webrtc.org4f6f22f2014-09-23 11:37:57 +0000266}
267
Peter Boströme2976c82016-01-04 22:44:05 +0100268#if defined(WEBRTC_ANDROID)
269#define MAYBE_SampleRate DISABLED_SampleRate
270#else
271#define MAYBE_SampleRate SampleRate
272#endif
273TEST_F(AcmReceiverTestOldApi, MAYBE_SampleRate) {
kwibergfce4a942015-10-27 11:40:24 -0700274 const RentACodec::CodecId kCodecId[] = {RentACodec::CodecId::kISAC,
275 RentACodec::CodecId::kISACSWB};
andresp@webrtc.org4f6f22f2014-09-23 11:37:57 +0000276 AddSetOfCodecs(kCodecId);
277
278 AudioFrame frame;
279 const int kOutSampleRateHz = 8000; // Different than codec sample rate.
kwibergfce4a942015-10-27 11:40:24 -0700280 for (const auto codec_id : kCodecId) {
281 const CodecIdInst codec(codec_id);
282 const int num_10ms_frames = codec.inst.pacsize / (codec.inst.plfreq / 100);
283 InsertOnePacketOfSilence(codec.id);
andresp@webrtc.org4f6f22f2014-09-23 11:37:57 +0000284 for (int k = 0; k < num_10ms_frames; ++k) {
henrik.lundin834a6ea2016-05-13 03:45:24 -0700285 bool muted;
286 EXPECT_EQ(0, receiver_->GetAudio(kOutSampleRateHz, &frame, &muted));
andresp@webrtc.org4f6f22f2014-09-23 11:37:57 +0000287 }
henrik.lundind89814b2015-11-23 06:49:25 -0800288 EXPECT_EQ(codec.inst.plfreq, receiver_->last_output_sample_rate_hz());
andresp@webrtc.org4f6f22f2014-09-23 11:37:57 +0000289 }
290}
291
henrik.lundin7dc68892016-04-06 01:03:02 -0700292class AcmReceiverTestFaxModeOldApi : public AcmReceiverTestOldApi {
293 protected:
294 AcmReceiverTestFaxModeOldApi() {
Henrik Lundin1ff41eb2018-06-21 12:36:28 +0000295 config_.neteq_config.playout_mode = kPlayoutFax;
henrik.lundin7dc68892016-04-06 01:03:02 -0700296 }
297
298 void RunVerifyAudioFrame(RentACodec::CodecId codec_id) {
299 // Make sure "fax mode" is enabled. This will avoid delay changes unless the
300 // packet-loss concealment is made. We do this in order to make the
301 // timestamp increments predictable; in normal mode, NetEq may decide to do
302 // accelerate or pre-emptive expand operations after some time, offsetting
303 // the timestamp.
Henrik Lundin1ff41eb2018-06-21 12:36:28 +0000304 EXPECT_EQ(kPlayoutFax, config_.neteq_config.playout_mode);
henrik.lundin7dc68892016-04-06 01:03:02 -0700305
306 const RentACodec::CodecId kCodecId[] = {codec_id};
307 AddSetOfCodecs(kCodecId);
308
309 const CodecIdInst codec(codec_id);
310 const int output_sample_rate_hz = codec.inst.plfreq;
311 const size_t output_channels = codec.inst.channels;
312 const size_t samples_per_ms = rtc::checked_cast<size_t>(
313 rtc::CheckedDivExact(output_sample_rate_hz, 1000));
314 const int num_10ms_frames = rtc::CheckedDivExact(
315 codec.inst.pacsize, rtc::checked_cast<int>(10 * samples_per_ms));
316 const AudioFrame::VADActivity expected_vad_activity =
317 output_sample_rate_hz > 16000 ? AudioFrame::kVadActive
318 : AudioFrame::kVadPassive;
319
320 // Expect the first output timestamp to be 5*fs/8000 samples before the
321 // first inserted timestamp (because of NetEq's look-ahead). (This value is
322 // defined in Expand::overlap_length_.)
Yves Gerey665174f2018-06-19 15:03:05 +0200323 uint32_t expected_output_ts =
324 last_packet_send_timestamp_ -
henrik.lundin7dc68892016-04-06 01:03:02 -0700325 rtc::CheckedDivExact(5 * output_sample_rate_hz, 8000);
326
327 AudioFrame frame;
henrik.lundin834a6ea2016-05-13 03:45:24 -0700328 bool muted;
329 EXPECT_EQ(0, receiver_->GetAudio(output_sample_rate_hz, &frame, &muted));
henrik.lundin15c51e32016-04-06 08:38:56 -0700330 // Expect timestamp = 0 before first packet is inserted.
331 EXPECT_EQ(0u, frame.timestamp_);
henrik.lundin7dc68892016-04-06 01:03:02 -0700332 for (int i = 0; i < 5; ++i) {
333 InsertOnePacketOfSilence(codec.id);
334 for (int k = 0; k < num_10ms_frames; ++k) {
henrik.lundin834a6ea2016-05-13 03:45:24 -0700335 EXPECT_EQ(0,
336 receiver_->GetAudio(output_sample_rate_hz, &frame, &muted));
henrik.lundin7dc68892016-04-06 01:03:02 -0700337 EXPECT_EQ(expected_output_ts, frame.timestamp_);
Mirko Bonadei737e0732017-10-19 09:00:17 +0200338 expected_output_ts += rtc::checked_cast<uint32_t>(10 * samples_per_ms);
henrik.lundin7dc68892016-04-06 01:03:02 -0700339 EXPECT_EQ(10 * samples_per_ms, frame.samples_per_channel_);
340 EXPECT_EQ(output_sample_rate_hz, frame.sample_rate_hz_);
341 EXPECT_EQ(output_channels, frame.num_channels_);
342 EXPECT_EQ(AudioFrame::kNormalSpeech, frame.speech_type_);
343 EXPECT_EQ(expected_vad_activity, frame.vad_activity_);
henrik.lundin834a6ea2016-05-13 03:45:24 -0700344 EXPECT_FALSE(muted);
henrik.lundin7dc68892016-04-06 01:03:02 -0700345 }
346 }
347 }
348};
349
350#if defined(WEBRTC_ANDROID)
351#define MAYBE_VerifyAudioFramePCMU DISABLED_VerifyAudioFramePCMU
352#else
353#define MAYBE_VerifyAudioFramePCMU VerifyAudioFramePCMU
354#endif
355TEST_F(AcmReceiverTestFaxModeOldApi, MAYBE_VerifyAudioFramePCMU) {
356 RunVerifyAudioFrame(RentACodec::CodecId::kPCMU);
357}
358
359#if defined(WEBRTC_ANDROID)
360#define MAYBE_VerifyAudioFrameISAC DISABLED_VerifyAudioFrameISAC
361#else
362#define MAYBE_VerifyAudioFrameISAC VerifyAudioFrameISAC
363#endif
364TEST_F(AcmReceiverTestFaxModeOldApi, MAYBE_VerifyAudioFrameISAC) {
365 RunVerifyAudioFrame(RentACodec::CodecId::kISAC);
366}
367
368#if defined(WEBRTC_ANDROID)
369#define MAYBE_VerifyAudioFrameOpus DISABLED_VerifyAudioFrameOpus
370#else
371#define MAYBE_VerifyAudioFrameOpus VerifyAudioFrameOpus
372#endif
373TEST_F(AcmReceiverTestFaxModeOldApi, MAYBE_VerifyAudioFrameOpus) {
374 RunVerifyAudioFrame(RentACodec::CodecId::kOpus);
375}
376
Peter Boströme2976c82016-01-04 22:44:05 +0100377#if defined(WEBRTC_ANDROID)
378#define MAYBE_PostdecodingVad DISABLED_PostdecodingVad
379#else
380#define MAYBE_PostdecodingVad PostdecodingVad
381#endif
382TEST_F(AcmReceiverTestOldApi, MAYBE_PostdecodingVad) {
henrik.lundin500c04b2016-03-08 02:36:04 -0800383 EXPECT_TRUE(config_.neteq_config.enable_post_decode_vad);
kwibergfce4a942015-10-27 11:40:24 -0700384 const CodecIdInst codec(RentACodec::CodecId::kPCM16Bwb);
385 ASSERT_EQ(
386 0, receiver_->AddCodec(codec.id, codec.inst.pltype, codec.inst.channels,
henrik.lundin4cf61dd2015-12-09 06:20:58 -0800387 codec.inst.plfreq, nullptr, ""));
andresp@webrtc.org4f6f22f2014-09-23 11:37:57 +0000388 const int kNumPackets = 5;
kwibergfce4a942015-10-27 11:40:24 -0700389 const int num_10ms_frames = codec.inst.pacsize / (codec.inst.plfreq / 100);
andresp@webrtc.org4f6f22f2014-09-23 11:37:57 +0000390 AudioFrame frame;
391 for (int n = 0; n < kNumPackets; ++n) {
kwibergfce4a942015-10-27 11:40:24 -0700392 InsertOnePacketOfSilence(codec.id);
henrik.lundin834a6ea2016-05-13 03:45:24 -0700393 for (int k = 0; k < num_10ms_frames; ++k) {
394 bool muted;
395 ASSERT_EQ(0, receiver_->GetAudio(codec.inst.plfreq, &frame, &muted));
396 }
andresp@webrtc.org4f6f22f2014-09-23 11:37:57 +0000397 }
398 EXPECT_EQ(AudioFrame::kVadPassive, frame.vad_activity_);
henrik.lundin500c04b2016-03-08 02:36:04 -0800399}
andresp@webrtc.org4f6f22f2014-09-23 11:37:57 +0000400
henrik.lundin500c04b2016-03-08 02:36:04 -0800401class AcmReceiverTestPostDecodeVadPassiveOldApi : public AcmReceiverTestOldApi {
402 protected:
403 AcmReceiverTestPostDecodeVadPassiveOldApi() {
404 config_.neteq_config.enable_post_decode_vad = false;
405 }
406};
andresp@webrtc.org4f6f22f2014-09-23 11:37:57 +0000407
henrik.lundin500c04b2016-03-08 02:36:04 -0800408#if defined(WEBRTC_ANDROID)
409#define MAYBE_PostdecodingVad DISABLED_PostdecodingVad
410#else
411#define MAYBE_PostdecodingVad PostdecodingVad
412#endif
413TEST_F(AcmReceiverTestPostDecodeVadPassiveOldApi, MAYBE_PostdecodingVad) {
414 EXPECT_FALSE(config_.neteq_config.enable_post_decode_vad);
415 const CodecIdInst codec(RentACodec::CodecId::kPCM16Bwb);
416 ASSERT_EQ(
417 0, receiver_->AddCodec(codec.id, codec.inst.pltype, codec.inst.channels,
418 codec.inst.plfreq, nullptr, ""));
419 const int kNumPackets = 5;
420 const int num_10ms_frames = codec.inst.pacsize / (codec.inst.plfreq / 100);
421 AudioFrame frame;
andresp@webrtc.org4f6f22f2014-09-23 11:37:57 +0000422 for (int n = 0; n < kNumPackets; ++n) {
kwibergfce4a942015-10-27 11:40:24 -0700423 InsertOnePacketOfSilence(codec.id);
henrik.lundin834a6ea2016-05-13 03:45:24 -0700424 for (int k = 0; k < num_10ms_frames; ++k) {
425 bool muted;
426 ASSERT_EQ(0, receiver_->GetAudio(codec.inst.plfreq, &frame, &muted));
427 }
andresp@webrtc.org4f6f22f2014-09-23 11:37:57 +0000428 }
429 EXPECT_EQ(AudioFrame::kVadUnknown, frame.vad_activity_);
430}
431
Peter Boströme2976c82016-01-04 22:44:05 +0100432#if defined(WEBRTC_ANDROID)
433#define MAYBE_LastAudioCodec DISABLED_LastAudioCodec
kwiberg98ab3a42015-09-30 21:54:21 -0700434#else
Peter Boströme2976c82016-01-04 22:44:05 +0100435#define MAYBE_LastAudioCodec LastAudioCodec
kwiberg98ab3a42015-09-30 21:54:21 -0700436#endif
Peter Boströme2976c82016-01-04 22:44:05 +0100437#if defined(WEBRTC_CODEC_ISAC)
438TEST_F(AcmReceiverTestOldApi, MAYBE_LastAudioCodec) {
kwibergfce4a942015-10-27 11:40:24 -0700439 const RentACodec::CodecId kCodecId[] = {
440 RentACodec::CodecId::kISAC, RentACodec::CodecId::kPCMA,
441 RentACodec::CodecId::kISACSWB, RentACodec::CodecId::kPCM16Bswb32kHz};
andresp@webrtc.org4f6f22f2014-09-23 11:37:57 +0000442 AddSetOfCodecs(kCodecId);
443
kwibergfce4a942015-10-27 11:40:24 -0700444 const RentACodec::CodecId kCngId[] = {
445 // Not including full-band.
446 RentACodec::CodecId::kCNNB, RentACodec::CodecId::kCNWB,
447 RentACodec::CodecId::kCNSWB};
andresp@webrtc.org4f6f22f2014-09-23 11:37:57 +0000448 AddSetOfCodecs(kCngId);
449
450 // Register CNG at sender side.
kwibergfce4a942015-10-27 11:40:24 -0700451 for (auto id : kCngId)
452 ASSERT_EQ(0, acm_->RegisterSendCodec(CodecIdInst(id).inst));
andresp@webrtc.org4f6f22f2014-09-23 11:37:57 +0000453
454 CodecInst codec;
455 // No audio payload is received.
456 EXPECT_EQ(-1, receiver_->LastAudioCodec(&codec));
457
458 // Start with sending DTX.
459 ASSERT_EQ(0, acm_->SetVAD(true, true, VADVeryAggr));
460 packet_sent_ = false;
kwibergfce4a942015-10-27 11:40:24 -0700461 InsertOnePacketOfSilence(CodecIdInst(kCodecId[0]).id); // Enough to test
462 // with one codec.
andresp@webrtc.org4f6f22f2014-09-23 11:37:57 +0000463 ASSERT_TRUE(packet_sent_);
464 EXPECT_EQ(kAudioFrameCN, last_frame_type_);
465
466 // Has received, only, DTX. Last Audio codec is undefined.
467 EXPECT_EQ(-1, receiver_->LastAudioCodec(&codec));
henrik.lundin057fb892015-11-23 08:19:52 -0800468 EXPECT_FALSE(receiver_->last_packet_sample_rate_hz());
andresp@webrtc.org4f6f22f2014-09-23 11:37:57 +0000469
kwibergfce4a942015-10-27 11:40:24 -0700470 for (auto id : kCodecId) {
471 const CodecIdInst c(id);
472
andresp@webrtc.org4f6f22f2014-09-23 11:37:57 +0000473 // Set DTX off to send audio payload.
474 acm_->SetVAD(false, false, VADAggr);
475 packet_sent_ = false;
kwibergfce4a942015-10-27 11:40:24 -0700476 InsertOnePacketOfSilence(c.id);
andresp@webrtc.org4f6f22f2014-09-23 11:37:57 +0000477
478 // Sanity check if Actually an audio payload received, and it should be
479 // of type "speech."
480 ASSERT_TRUE(packet_sent_);
481 ASSERT_EQ(kAudioFrameSpeech, last_frame_type_);
Oskar Sundbom12ab00b2017-11-16 15:31:38 +0100482 EXPECT_EQ(c.inst.plfreq, receiver_->last_packet_sample_rate_hz());
andresp@webrtc.org4f6f22f2014-09-23 11:37:57 +0000483
484 // Set VAD on to send DTX. Then check if the "Last Audio codec" returns
485 // the expected codec.
486 acm_->SetVAD(true, true, VADAggr);
487
488 // Do as many encoding until a DTX is sent.
489 while (last_frame_type_ != kAudioFrameCN) {
490 packet_sent_ = false;
kwibergfce4a942015-10-27 11:40:24 -0700491 InsertOnePacketOfSilence(c.id);
andresp@webrtc.org4f6f22f2014-09-23 11:37:57 +0000492 ASSERT_TRUE(packet_sent_);
493 }
Oskar Sundbom12ab00b2017-11-16 15:31:38 +0100494 EXPECT_EQ(c.inst.plfreq, receiver_->last_packet_sample_rate_hz());
andresp@webrtc.org4f6f22f2014-09-23 11:37:57 +0000495 EXPECT_EQ(0, receiver_->LastAudioCodec(&codec));
kwibergfce4a942015-10-27 11:40:24 -0700496 EXPECT_TRUE(CodecsEqual(c.inst, codec));
andresp@webrtc.org4f6f22f2014-09-23 11:37:57 +0000497 }
498}
Peter Boströme2976c82016-01-04 22:44:05 +0100499#endif
andresp@webrtc.org4f6f22f2014-09-23 11:37:57 +0000500
501} // namespace acm2
502
503} // namespace webrtc