blob: 29f2a45669b3d99f21edc0402d16c1fed0be1f11 [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"
Karl Wiberg377a2312018-09-24 14:52:51 +020017#include "api/audio_codecs/builtin_audio_encoder_factory.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020018#include "modules/audio_coding/acm2/rent_a_codec.h"
Karl Wiberg377a2312018-09-24 14:52:51 +020019#include "modules/audio_coding/codecs/cng/audio_encoder_cng.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020020#include "modules/audio_coding/include/audio_coding_module.h"
21#include "modules/audio_coding/neteq/tools/rtp_generator.h"
Fredrik Solenbergbbf21a32018-04-12 22:44:09 +020022#include "modules/include/module_common_types.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020023#include "rtc_base/checks.h"
Karl Wiberge40468b2017-11-22 10:42:26 +010024#include "rtc_base/numerics/safe_conversions.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020025#include "system_wrappers/include/clock.h"
26#include "test/gtest.h"
27#include "test/testsupport/fileutils.h"
andresp@webrtc.org4f6f22f2014-09-23 11:37:57 +000028
29namespace webrtc {
30
31namespace acm2 {
andresp@webrtc.org4f6f22f2014-09-23 11:37:57 +000032
33class AcmReceiverTestOldApi : public AudioPacketizationCallback,
34 public ::testing::Test {
35 protected:
36 AcmReceiverTestOldApi()
37 : timestamp_(0),
38 packet_sent_(false),
39 last_packet_send_timestamp_(timestamp_),
pbos22993e12015-10-19 02:39:06 -070040 last_frame_type_(kEmptyFrame) {
Karl Wiberg377a2312018-09-24 14:52:51 +020041 config_.decoder_factory = decoder_factory_;
andresp@webrtc.org4f6f22f2014-09-23 11:37:57 +000042 }
43
44 ~AcmReceiverTestOldApi() {}
45
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +000046 void SetUp() override {
kwibergc13ded52016-06-17 06:00:45 -070047 acm_.reset(AudioCodingModule::Create(config_));
henrik.lundin500c04b2016-03-08 02:36:04 -080048 receiver_.reset(new AcmReceiver(config_));
andresp@webrtc.org4f6f22f2014-09-23 11:37:57 +000049 ASSERT_TRUE(receiver_.get() != NULL);
50 ASSERT_TRUE(acm_.get() != NULL);
andresp@webrtc.org4f6f22f2014-09-23 11:37:57 +000051 acm_->InitializeReceiver();
andresp@webrtc.org4f6f22f2014-09-23 11:37:57 +000052 acm_->RegisterTransportCallback(this);
53
54 rtp_header_.header.sequenceNumber = 0;
55 rtp_header_.header.timestamp = 0;
56 rtp_header_.header.markerBit = false;
57 rtp_header_.header.ssrc = 0x12345678; // Arbitrary.
58 rtp_header_.header.numCSRCs = 0;
59 rtp_header_.header.payloadType = 0;
60 rtp_header_.frameType = kAudioFrameSpeech;
andresp@webrtc.org4f6f22f2014-09-23 11:37:57 +000061 }
62
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +000063 void TearDown() override {}
andresp@webrtc.org4f6f22f2014-09-23 11:37:57 +000064
Karl Wiberg377a2312018-09-24 14:52:51 +020065 AudioCodecInfo SetEncoder(int payload_type,
66 const SdpAudioFormat& format,
67 const std::map<int, int> cng_payload_types = {}) {
68 // Create the speech encoder.
69 AudioCodecInfo info = encoder_factory_->QueryAudioEncoder(format).value();
70 std::unique_ptr<AudioEncoder> enc =
71 encoder_factory_->MakeAudioEncoder(payload_type, format, absl::nullopt);
72
73 // If we have a compatible CN specification, stack a CNG on top.
74 auto it = cng_payload_types.find(info.sample_rate_hz);
75 if (it != cng_payload_types.end()) {
76 AudioEncoderCng::Config config;
77 config.speech_encoder = std::move(enc);
78 config.num_channels = 1;
79 config.payload_type = it->second;
80 config.vad_mode = Vad::kVadNormal;
81 enc = absl::make_unique<AudioEncoderCng>(std::move(config));
andresp@webrtc.org4f6f22f2014-09-23 11:37:57 +000082 }
Karl Wiberg377a2312018-09-24 14:52:51 +020083
84 // Actually start using the new encoder.
85 acm_->SetEncoder(std::move(enc));
86 return info;
87 }
88
89 int InsertOnePacketOfSilence(const AudioCodecInfo& info) {
andresp@webrtc.org4f6f22f2014-09-23 11:37:57 +000090 // Frame setup according to the codec.
Karl Wiberg377a2312018-09-24 14:52:51 +020091 AudioFrame frame;
92 frame.sample_rate_hz_ = info.sample_rate_hz;
93 frame.samples_per_channel_ = info.sample_rate_hz / 100; // 10 ms.
94 frame.num_channels_ = info.num_channels;
yujo36b1a5f2017-06-12 12:45:32 -070095 frame.Mute();
andresp@webrtc.org4f6f22f2014-09-23 11:37:57 +000096 packet_sent_ = false;
97 last_packet_send_timestamp_ = timestamp_;
Karl Wiberg377a2312018-09-24 14:52:51 +020098 int num_10ms_frames = 0;
henrik.lundin@webrtc.orgf56c1622015-03-02 12:29:30 +000099 while (!packet_sent_) {
andresp@webrtc.org4f6f22f2014-09-23 11:37:57 +0000100 frame.timestamp_ = timestamp_;
Mirko Bonadei737e0732017-10-19 09:00:17 +0200101 timestamp_ += rtc::checked_cast<uint32_t>(frame.samples_per_channel_);
Karl Wiberg377a2312018-09-24 14:52:51 +0200102 EXPECT_GE(acm_->Add10MsData(frame), 0);
103 ++num_10ms_frames;
andresp@webrtc.org4f6f22f2014-09-23 11:37:57 +0000104 }
Karl Wiberg377a2312018-09-24 14:52:51 +0200105 return num_10ms_frames;
andresp@webrtc.org4f6f22f2014-09-23 11:37:57 +0000106 }
107
kwibergfce4a942015-10-27 11:40:24 -0700108 template <size_t N>
Karl Wiberg377a2312018-09-24 14:52:51 +0200109 void AddSetOfCodecs(rtc::ArrayView<SdpAudioFormat> formats) {
110 static int payload_type = 0;
111 for (const auto& format : formats) {
112 EXPECT_TRUE(receiver_->AddCodec(payload_type++, format));
andresp@webrtc.org4f6f22f2014-09-23 11:37:57 +0000113 }
114 }
115
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000116 int SendData(FrameType frame_type,
117 uint8_t payload_type,
118 uint32_t timestamp,
119 const uint8_t* payload_data,
120 size_t payload_len_bytes,
121 const RTPFragmentationHeader* fragmentation) override {
pbos22993e12015-10-19 02:39:06 -0700122 if (frame_type == kEmptyFrame)
andresp@webrtc.org4f6f22f2014-09-23 11:37:57 +0000123 return 0;
124
125 rtp_header_.header.payloadType = payload_type;
126 rtp_header_.frameType = frame_type;
andresp@webrtc.org4f6f22f2014-09-23 11:37:57 +0000127 rtp_header_.header.timestamp = timestamp;
128
kwibergee2bac22015-11-11 10:34:00 -0800129 int ret_val = receiver_->InsertPacket(
130 rtp_header_,
131 rtc::ArrayView<const uint8_t>(payload_data, payload_len_bytes));
andresp@webrtc.org4f6f22f2014-09-23 11:37:57 +0000132 if (ret_val < 0) {
133 assert(false);
134 return -1;
135 }
136 rtp_header_.header.sequenceNumber++;
137 packet_sent_ = true;
138 last_frame_type_ = frame_type;
139 return 0;
140 }
141
Karl Wiberg377a2312018-09-24 14:52:51 +0200142 const rtc::scoped_refptr<AudioEncoderFactory> encoder_factory_ =
143 CreateBuiltinAudioEncoderFactory();
144 const rtc::scoped_refptr<AudioDecoderFactory> decoder_factory_ =
145 CreateBuiltinAudioDecoderFactory();
henrik.lundin500c04b2016-03-08 02:36:04 -0800146 AudioCodingModule::Config config_;
kwiberg16c5a962016-02-15 02:27:22 -0800147 std::unique_ptr<AcmReceiver> receiver_;
kwiberg16c5a962016-02-15 02:27:22 -0800148 std::unique_ptr<AudioCodingModule> acm_;
andresp@webrtc.org4f6f22f2014-09-23 11:37:57 +0000149 WebRtcRTPHeader rtp_header_;
150 uint32_t timestamp_;
151 bool packet_sent_; // Set when SendData is called reset when inserting audio.
152 uint32_t last_packet_send_timestamp_;
153 FrameType last_frame_type_;
154};
155
Peter Boströme2976c82016-01-04 22:44:05 +0100156#if defined(WEBRTC_ANDROID)
157#define MAYBE_AddCodecGetCodec DISABLED_AddCodecGetCodec
158#else
159#define MAYBE_AddCodecGetCodec AddCodecGetCodec
160#endif
161TEST_F(AcmReceiverTestOldApi, MAYBE_AddCodecGetCodec) {
Karl Wiberg377a2312018-09-24 14:52:51 +0200162 const std::vector<AudioCodecSpec> codecs =
163 decoder_factory_->GetSupportedDecoders();
164
andresp@webrtc.org4f6f22f2014-09-23 11:37:57 +0000165 // Add codec.
Karl Wiberg377a2312018-09-24 14:52:51 +0200166 for (size_t n = 0; n < codecs.size(); ++n) {
kwibergd1201922016-09-20 15:18:21 -0700167 if (n & 0x1) { // Just add codecs with odd index.
Karl Wiberg377a2312018-09-24 14:52:51 +0200168 const int payload_type = rtc::checked_cast<int>(n);
169 EXPECT_TRUE(receiver_->AddCodec(payload_type, codecs[n].format));
kwibergd1201922016-09-20 15:18:21 -0700170 }
andresp@webrtc.org4f6f22f2014-09-23 11:37:57 +0000171 }
172 // Get codec and compare.
Karl Wiberg377a2312018-09-24 14:52:51 +0200173 for (size_t n = 0; n < codecs.size(); ++n) {
174 const int payload_type = rtc::checked_cast<int>(n);
andresp@webrtc.org4f6f22f2014-09-23 11:37:57 +0000175 if (n & 0x1) {
176 // Codecs with odd index should match the reference.
Karl Wiberg377a2312018-09-24 14:52:51 +0200177 EXPECT_EQ(absl::make_optional(codecs[n].format),
178 receiver_->DecoderByPayloadType(payload_type));
andresp@webrtc.org4f6f22f2014-09-23 11:37:57 +0000179 } else {
180 // Codecs with even index are not registered.
Karl Wiberg377a2312018-09-24 14:52:51 +0200181 EXPECT_EQ(absl::nullopt, receiver_->DecoderByPayloadType(payload_type));
andresp@webrtc.org4f6f22f2014-09-23 11:37:57 +0000182 }
183 }
184}
185
Peter Boströme2976c82016-01-04 22:44:05 +0100186#if defined(WEBRTC_ANDROID)
187#define MAYBE_AddCodecChangePayloadType DISABLED_AddCodecChangePayloadType
188#else
189#define MAYBE_AddCodecChangePayloadType AddCodecChangePayloadType
190#endif
191TEST_F(AcmReceiverTestOldApi, MAYBE_AddCodecChangePayloadType) {
Karl Wiberg377a2312018-09-24 14:52:51 +0200192 const SdpAudioFormat format("giraffe", 8000, 1);
andresp@webrtc.org4f6f22f2014-09-23 11:37:57 +0000193
Jelena Marusica9907842015-03-26 14:01:30 +0100194 // Register the same codec with different payloads.
Karl Wiberg377a2312018-09-24 14:52:51 +0200195 EXPECT_EQ(true, receiver_->AddCodec(17, format));
196 EXPECT_EQ(true, receiver_->AddCodec(18, format));
andresp@webrtc.org4f6f22f2014-09-23 11:37:57 +0000197
Jelena Marusica9907842015-03-26 14:01:30 +0100198 // Both payload types should exist.
Karl Wiberg377a2312018-09-24 14:52:51 +0200199 EXPECT_EQ(absl::make_optional(format), receiver_->DecoderByPayloadType(17));
200 EXPECT_EQ(absl::make_optional(format), receiver_->DecoderByPayloadType(18));
Jelena Marusica9907842015-03-26 14:01:30 +0100201}
andresp@webrtc.org4f6f22f2014-09-23 11:37:57 +0000202
Peter Boströme2976c82016-01-04 22:44:05 +0100203#if defined(WEBRTC_ANDROID)
204#define MAYBE_AddCodecChangeCodecId DISABLED_AddCodecChangeCodecId
205#else
206#define MAYBE_AddCodecChangeCodecId AddCodecChangeCodecId
207#endif
208TEST_F(AcmReceiverTestOldApi, AddCodecChangeCodecId) {
Karl Wiberg377a2312018-09-24 14:52:51 +0200209 const SdpAudioFormat format1("giraffe", 8000, 1);
210 const SdpAudioFormat format2("gnu", 16000, 1);
Jelena Marusica9907842015-03-26 14:01:30 +0100211
212 // Register the same payload type with different codec ID.
Karl Wiberg377a2312018-09-24 14:52:51 +0200213 EXPECT_EQ(true, receiver_->AddCodec(17, format1));
214 EXPECT_EQ(true, receiver_->AddCodec(17, format2));
Jelena Marusica9907842015-03-26 14:01:30 +0100215
216 // Make sure that the last codec is used.
Karl Wiberg377a2312018-09-24 14:52:51 +0200217 EXPECT_EQ(absl::make_optional(format2), receiver_->DecoderByPayloadType(17));
andresp@webrtc.org4f6f22f2014-09-23 11:37:57 +0000218}
219
Peter Boströme2976c82016-01-04 22:44:05 +0100220#if defined(WEBRTC_ANDROID)
221#define MAYBE_AddCodecRemoveCodec DISABLED_AddCodecRemoveCodec
222#else
223#define MAYBE_AddCodecRemoveCodec AddCodecRemoveCodec
224#endif
225TEST_F(AcmReceiverTestOldApi, MAYBE_AddCodecRemoveCodec) {
Karl Wiberg377a2312018-09-24 14:52:51 +0200226 EXPECT_EQ(true, receiver_->AddCodec(17, SdpAudioFormat("giraffe", 8000, 1)));
andresp@webrtc.org4f6f22f2014-09-23 11:37:57 +0000227
228 // Remove non-existing codec should not fail. ACM1 legacy.
Karl Wiberg377a2312018-09-24 14:52:51 +0200229 EXPECT_EQ(0, receiver_->RemoveCodec(18));
andresp@webrtc.org4f6f22f2014-09-23 11:37:57 +0000230
231 // Remove an existing codec.
Karl Wiberg377a2312018-09-24 14:52:51 +0200232 EXPECT_EQ(0, receiver_->RemoveCodec(17));
andresp@webrtc.org4f6f22f2014-09-23 11:37:57 +0000233
234 // Ask for the removed codec, must fail.
Karl Wiberg377a2312018-09-24 14:52:51 +0200235 EXPECT_EQ(absl::nullopt, receiver_->DecoderByPayloadType(17));
andresp@webrtc.org4f6f22f2014-09-23 11:37:57 +0000236}
237
Peter Boströme2976c82016-01-04 22:44:05 +0100238#if defined(WEBRTC_ANDROID)
239#define MAYBE_SampleRate DISABLED_SampleRate
240#else
241#define MAYBE_SampleRate SampleRate
242#endif
243TEST_F(AcmReceiverTestOldApi, MAYBE_SampleRate) {
Karl Wiberg377a2312018-09-24 14:52:51 +0200244 const std::vector<SdpAudioFormat> codecs = {{"ISAC", 16000, 1},
245 {"ISAC", 32000, 1}};
246 for (size_t i = 0; i < codecs.size(); ++i) {
247 const int payload_type = rtc::checked_cast<int>(i);
248 EXPECT_EQ(true, receiver_->AddCodec(payload_type, codecs[i]));
249 }
andresp@webrtc.org4f6f22f2014-09-23 11:37:57 +0000250
Karl Wiberg377a2312018-09-24 14:52:51 +0200251 constexpr int kOutSampleRateHz = 8000; // Different than codec sample rate.
252 for (size_t i = 0; i < codecs.size(); ++i) {
253 const int payload_type = rtc::checked_cast<int>(i);
254 const int num_10ms_frames =
255 InsertOnePacketOfSilence(SetEncoder(payload_type, codecs[i]));
andresp@webrtc.org4f6f22f2014-09-23 11:37:57 +0000256 for (int k = 0; k < num_10ms_frames; ++k) {
Karl Wiberg377a2312018-09-24 14:52:51 +0200257 AudioFrame frame;
henrik.lundin834a6ea2016-05-13 03:45:24 -0700258 bool muted;
259 EXPECT_EQ(0, receiver_->GetAudio(kOutSampleRateHz, &frame, &muted));
andresp@webrtc.org4f6f22f2014-09-23 11:37:57 +0000260 }
Karl Wiberg377a2312018-09-24 14:52:51 +0200261 EXPECT_EQ(encoder_factory_->QueryAudioEncoder(codecs[i])->sample_rate_hz,
262 receiver_->last_output_sample_rate_hz());
andresp@webrtc.org4f6f22f2014-09-23 11:37:57 +0000263 }
264}
265
henrik.lundin7dc68892016-04-06 01:03:02 -0700266class AcmReceiverTestFaxModeOldApi : public AcmReceiverTestOldApi {
267 protected:
268 AcmReceiverTestFaxModeOldApi() {
Henrik Lundin7687ad52018-07-02 10:14:46 +0200269 config_.neteq_config.for_test_no_time_stretching = true;
henrik.lundin7dc68892016-04-06 01:03:02 -0700270 }
271
Karl Wiberg377a2312018-09-24 14:52:51 +0200272 void RunVerifyAudioFrame(const SdpAudioFormat& codec) {
henrik.lundin7dc68892016-04-06 01:03:02 -0700273 // Make sure "fax mode" is enabled. This will avoid delay changes unless the
274 // packet-loss concealment is made. We do this in order to make the
275 // timestamp increments predictable; in normal mode, NetEq may decide to do
276 // accelerate or pre-emptive expand operations after some time, offsetting
277 // the timestamp.
Henrik Lundin7687ad52018-07-02 10:14:46 +0200278 EXPECT_TRUE(config_.neteq_config.for_test_no_time_stretching);
henrik.lundin7dc68892016-04-06 01:03:02 -0700279
Karl Wiberg377a2312018-09-24 14:52:51 +0200280 constexpr int payload_type = 17;
281 EXPECT_TRUE(receiver_->AddCodec(payload_type, codec));
henrik.lundin7dc68892016-04-06 01:03:02 -0700282
Karl Wiberg377a2312018-09-24 14:52:51 +0200283 const AudioCodecInfo info = SetEncoder(payload_type, codec);
284 const int output_sample_rate_hz = info.sample_rate_hz;
285 const size_t output_channels = info.num_channels;
henrik.lundin7dc68892016-04-06 01:03:02 -0700286 const size_t samples_per_ms = rtc::checked_cast<size_t>(
287 rtc::CheckedDivExact(output_sample_rate_hz, 1000));
henrik.lundin7dc68892016-04-06 01:03:02 -0700288 const AudioFrame::VADActivity expected_vad_activity =
289 output_sample_rate_hz > 16000 ? AudioFrame::kVadActive
290 : AudioFrame::kVadPassive;
291
292 // Expect the first output timestamp to be 5*fs/8000 samples before the
293 // first inserted timestamp (because of NetEq's look-ahead). (This value is
294 // defined in Expand::overlap_length_.)
Yves Gerey665174f2018-06-19 15:03:05 +0200295 uint32_t expected_output_ts =
296 last_packet_send_timestamp_ -
henrik.lundin7dc68892016-04-06 01:03:02 -0700297 rtc::CheckedDivExact(5 * output_sample_rate_hz, 8000);
298
299 AudioFrame frame;
henrik.lundin834a6ea2016-05-13 03:45:24 -0700300 bool muted;
301 EXPECT_EQ(0, receiver_->GetAudio(output_sample_rate_hz, &frame, &muted));
henrik.lundin15c51e32016-04-06 08:38:56 -0700302 // Expect timestamp = 0 before first packet is inserted.
303 EXPECT_EQ(0u, frame.timestamp_);
henrik.lundin7dc68892016-04-06 01:03:02 -0700304 for (int i = 0; i < 5; ++i) {
Karl Wiberg377a2312018-09-24 14:52:51 +0200305 const int num_10ms_frames = InsertOnePacketOfSilence(info);
henrik.lundin7dc68892016-04-06 01:03:02 -0700306 for (int k = 0; k < num_10ms_frames; ++k) {
henrik.lundin834a6ea2016-05-13 03:45:24 -0700307 EXPECT_EQ(0,
308 receiver_->GetAudio(output_sample_rate_hz, &frame, &muted));
henrik.lundin7dc68892016-04-06 01:03:02 -0700309 EXPECT_EQ(expected_output_ts, frame.timestamp_);
Mirko Bonadei737e0732017-10-19 09:00:17 +0200310 expected_output_ts += rtc::checked_cast<uint32_t>(10 * samples_per_ms);
henrik.lundin7dc68892016-04-06 01:03:02 -0700311 EXPECT_EQ(10 * samples_per_ms, frame.samples_per_channel_);
312 EXPECT_EQ(output_sample_rate_hz, frame.sample_rate_hz_);
313 EXPECT_EQ(output_channels, frame.num_channels_);
314 EXPECT_EQ(AudioFrame::kNormalSpeech, frame.speech_type_);
315 EXPECT_EQ(expected_vad_activity, frame.vad_activity_);
henrik.lundin834a6ea2016-05-13 03:45:24 -0700316 EXPECT_FALSE(muted);
henrik.lundin7dc68892016-04-06 01:03:02 -0700317 }
318 }
319 }
320};
321
322#if defined(WEBRTC_ANDROID)
323#define MAYBE_VerifyAudioFramePCMU DISABLED_VerifyAudioFramePCMU
324#else
325#define MAYBE_VerifyAudioFramePCMU VerifyAudioFramePCMU
326#endif
327TEST_F(AcmReceiverTestFaxModeOldApi, MAYBE_VerifyAudioFramePCMU) {
Karl Wiberg377a2312018-09-24 14:52:51 +0200328 RunVerifyAudioFrame({"PCMU", 8000, 1});
henrik.lundin7dc68892016-04-06 01:03:02 -0700329}
330
331#if defined(WEBRTC_ANDROID)
332#define MAYBE_VerifyAudioFrameISAC DISABLED_VerifyAudioFrameISAC
333#else
334#define MAYBE_VerifyAudioFrameISAC VerifyAudioFrameISAC
335#endif
336TEST_F(AcmReceiverTestFaxModeOldApi, MAYBE_VerifyAudioFrameISAC) {
Karl Wiberg377a2312018-09-24 14:52:51 +0200337 RunVerifyAudioFrame({"ISAC", 16000, 1});
henrik.lundin7dc68892016-04-06 01:03:02 -0700338}
339
340#if defined(WEBRTC_ANDROID)
341#define MAYBE_VerifyAudioFrameOpus DISABLED_VerifyAudioFrameOpus
342#else
343#define MAYBE_VerifyAudioFrameOpus VerifyAudioFrameOpus
344#endif
345TEST_F(AcmReceiverTestFaxModeOldApi, MAYBE_VerifyAudioFrameOpus) {
Karl Wiberg377a2312018-09-24 14:52:51 +0200346 RunVerifyAudioFrame({"opus", 48000, 2});
henrik.lundin7dc68892016-04-06 01:03:02 -0700347}
348
Peter Boströme2976c82016-01-04 22:44:05 +0100349#if defined(WEBRTC_ANDROID)
350#define MAYBE_PostdecodingVad DISABLED_PostdecodingVad
351#else
352#define MAYBE_PostdecodingVad PostdecodingVad
353#endif
354TEST_F(AcmReceiverTestOldApi, MAYBE_PostdecodingVad) {
henrik.lundin500c04b2016-03-08 02:36:04 -0800355 EXPECT_TRUE(config_.neteq_config.enable_post_decode_vad);
Karl Wiberg377a2312018-09-24 14:52:51 +0200356 constexpr int payload_type = 34;
357 const SdpAudioFormat codec = {"L16", 16000, 1};
358 const AudioCodecInfo info = SetEncoder(payload_type, codec);
359 EXPECT_TRUE(receiver_->AddCodec(payload_type, codec));
360 constexpr int kNumPackets = 5;
andresp@webrtc.org4f6f22f2014-09-23 11:37:57 +0000361 AudioFrame frame;
362 for (int n = 0; n < kNumPackets; ++n) {
Karl Wiberg377a2312018-09-24 14:52:51 +0200363 const int num_10ms_frames = InsertOnePacketOfSilence(info);
henrik.lundin834a6ea2016-05-13 03:45:24 -0700364 for (int k = 0; k < num_10ms_frames; ++k) {
365 bool muted;
Karl Wiberg377a2312018-09-24 14:52:51 +0200366 ASSERT_EQ(0, receiver_->GetAudio(info.sample_rate_hz, &frame, &muted));
henrik.lundin834a6ea2016-05-13 03:45:24 -0700367 }
andresp@webrtc.org4f6f22f2014-09-23 11:37:57 +0000368 }
369 EXPECT_EQ(AudioFrame::kVadPassive, frame.vad_activity_);
henrik.lundin500c04b2016-03-08 02:36:04 -0800370}
andresp@webrtc.org4f6f22f2014-09-23 11:37:57 +0000371
henrik.lundin500c04b2016-03-08 02:36:04 -0800372class AcmReceiverTestPostDecodeVadPassiveOldApi : public AcmReceiverTestOldApi {
373 protected:
374 AcmReceiverTestPostDecodeVadPassiveOldApi() {
375 config_.neteq_config.enable_post_decode_vad = false;
376 }
377};
andresp@webrtc.org4f6f22f2014-09-23 11:37:57 +0000378
henrik.lundin500c04b2016-03-08 02:36:04 -0800379#if defined(WEBRTC_ANDROID)
380#define MAYBE_PostdecodingVad DISABLED_PostdecodingVad
381#else
382#define MAYBE_PostdecodingVad PostdecodingVad
383#endif
384TEST_F(AcmReceiverTestPostDecodeVadPassiveOldApi, MAYBE_PostdecodingVad) {
385 EXPECT_FALSE(config_.neteq_config.enable_post_decode_vad);
Karl Wiberg377a2312018-09-24 14:52:51 +0200386 constexpr int payload_type = 34;
387 const SdpAudioFormat codec = {"L16", 16000, 1};
388 const AudioCodecInfo info = SetEncoder(payload_type, codec);
389 encoder_factory_->QueryAudioEncoder(codec).value();
390 EXPECT_TRUE(receiver_->AddCodec(payload_type, codec));
henrik.lundin500c04b2016-03-08 02:36:04 -0800391 const int kNumPackets = 5;
henrik.lundin500c04b2016-03-08 02:36:04 -0800392 AudioFrame frame;
andresp@webrtc.org4f6f22f2014-09-23 11:37:57 +0000393 for (int n = 0; n < kNumPackets; ++n) {
Karl Wiberg377a2312018-09-24 14:52:51 +0200394 const int num_10ms_frames = InsertOnePacketOfSilence(info);
henrik.lundin834a6ea2016-05-13 03:45:24 -0700395 for (int k = 0; k < num_10ms_frames; ++k) {
396 bool muted;
Karl Wiberg377a2312018-09-24 14:52:51 +0200397 ASSERT_EQ(0, receiver_->GetAudio(info.sample_rate_hz, &frame, &muted));
henrik.lundin834a6ea2016-05-13 03:45:24 -0700398 }
andresp@webrtc.org4f6f22f2014-09-23 11:37:57 +0000399 }
400 EXPECT_EQ(AudioFrame::kVadUnknown, frame.vad_activity_);
401}
402
Peter Boströme2976c82016-01-04 22:44:05 +0100403#if defined(WEBRTC_ANDROID)
404#define MAYBE_LastAudioCodec DISABLED_LastAudioCodec
kwiberg98ab3a42015-09-30 21:54:21 -0700405#else
Peter Boströme2976c82016-01-04 22:44:05 +0100406#define MAYBE_LastAudioCodec LastAudioCodec
kwiberg98ab3a42015-09-30 21:54:21 -0700407#endif
Peter Boströme2976c82016-01-04 22:44:05 +0100408#if defined(WEBRTC_CODEC_ISAC)
409TEST_F(AcmReceiverTestOldApi, MAYBE_LastAudioCodec) {
Karl Wiberg377a2312018-09-24 14:52:51 +0200410 const std::vector<SdpAudioFormat> codecs = {{"ISAC", 16000, 1},
411 {"PCMA", 8000, 1},
412 {"ISAC", 32000, 1},
413 {"L16", 32000, 1}};
414 for (size_t i = 0; i < codecs.size(); ++i) {
415 const int payload_type = rtc::checked_cast<int>(i);
416 EXPECT_TRUE(receiver_->AddCodec(payload_type, codecs[i]));
417 }
andresp@webrtc.org4f6f22f2014-09-23 11:37:57 +0000418
Karl Wiberg377a2312018-09-24 14:52:51 +0200419 const std::map<int, int> cng_payload_types = {
420 {8000, 100}, {16000, 101}, {32000, 102}};
421 for (const auto& x : cng_payload_types) {
422 const int sample_rate_hz = x.first;
423 const int payload_type = x.second;
424 EXPECT_TRUE(receiver_->AddCodec(payload_type, {"CN", sample_rate_hz, 1}));
425 }
andresp@webrtc.org4f6f22f2014-09-23 11:37:57 +0000426
andresp@webrtc.org4f6f22f2014-09-23 11:37:57 +0000427 // No audio payload is received.
Karl Wiberg377a2312018-09-24 14:52:51 +0200428 EXPECT_EQ(absl::nullopt, receiver_->LastAudioFormat());
andresp@webrtc.org4f6f22f2014-09-23 11:37:57 +0000429
430 // Start with sending DTX.
andresp@webrtc.org4f6f22f2014-09-23 11:37:57 +0000431 packet_sent_ = false;
Karl Wiberg377a2312018-09-24 14:52:51 +0200432 InsertOnePacketOfSilence(
433 SetEncoder(0, codecs[0], cng_payload_types)); // Enough to test
434 // with one codec.
andresp@webrtc.org4f6f22f2014-09-23 11:37:57 +0000435 ASSERT_TRUE(packet_sent_);
436 EXPECT_EQ(kAudioFrameCN, last_frame_type_);
437
438 // Has received, only, DTX. Last Audio codec is undefined.
Karl Wiberg377a2312018-09-24 14:52:51 +0200439 EXPECT_EQ(absl::nullopt, receiver_->LastAudioFormat());
henrik.lundin057fb892015-11-23 08:19:52 -0800440 EXPECT_FALSE(receiver_->last_packet_sample_rate_hz());
andresp@webrtc.org4f6f22f2014-09-23 11:37:57 +0000441
Karl Wiberg377a2312018-09-24 14:52:51 +0200442 for (size_t i = 0; i < codecs.size(); ++i) {
andresp@webrtc.org4f6f22f2014-09-23 11:37:57 +0000443 // Set DTX off to send audio payload.
andresp@webrtc.org4f6f22f2014-09-23 11:37:57 +0000444 packet_sent_ = false;
Karl Wiberg377a2312018-09-24 14:52:51 +0200445 const int payload_type = rtc::checked_cast<int>(i);
446 const AudioCodecInfo info_without_cng = SetEncoder(payload_type, codecs[i]);
447 InsertOnePacketOfSilence(info_without_cng);
andresp@webrtc.org4f6f22f2014-09-23 11:37:57 +0000448
449 // Sanity check if Actually an audio payload received, and it should be
450 // of type "speech."
451 ASSERT_TRUE(packet_sent_);
452 ASSERT_EQ(kAudioFrameSpeech, last_frame_type_);
Karl Wiberg377a2312018-09-24 14:52:51 +0200453 EXPECT_EQ(info_without_cng.sample_rate_hz,
454 receiver_->last_packet_sample_rate_hz());
andresp@webrtc.org4f6f22f2014-09-23 11:37:57 +0000455
456 // Set VAD on to send DTX. Then check if the "Last Audio codec" returns
Karl Wiberg377a2312018-09-24 14:52:51 +0200457 // the expected codec. Encode repeatedly until a DTX is sent.
458 const AudioCodecInfo info_with_cng =
459 SetEncoder(payload_type, codecs[i], cng_payload_types);
andresp@webrtc.org4f6f22f2014-09-23 11:37:57 +0000460 while (last_frame_type_ != kAudioFrameCN) {
461 packet_sent_ = false;
Karl Wiberg377a2312018-09-24 14:52:51 +0200462 InsertOnePacketOfSilence(info_with_cng);
andresp@webrtc.org4f6f22f2014-09-23 11:37:57 +0000463 ASSERT_TRUE(packet_sent_);
464 }
Karl Wiberg377a2312018-09-24 14:52:51 +0200465 EXPECT_EQ(info_with_cng.sample_rate_hz,
466 receiver_->last_packet_sample_rate_hz());
467 EXPECT_EQ(codecs[i], receiver_->LastAudioFormat());
andresp@webrtc.org4f6f22f2014-09-23 11:37:57 +0000468 }
469}
Peter Boströme2976c82016-01-04 22:44:05 +0100470#endif
andresp@webrtc.org4f6f22f2014-09-23 11:37:57 +0000471
472} // namespace acm2
473
474} // namespace webrtc