blob: 2704d3d892d00075d171f513ecbeb5b6a6114f53 [file] [log] [blame]
niklase@google.com470e71d2011-07-07 08:21:25 +00001/*
tina.legrand@webrtc.orgdf697752012-02-08 10:22:21 +00002 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
niklase@google.com470e71d2011-07-07 08:21:25 +00003 *
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/test/TestStereo.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000012
pbos@webrtc.org12dc1a32013-08-05 16:22:53 +000013#include <assert.h>
14
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +000015#include <string>
kjellander@webrtc.org5490c712011-12-21 13:34:18 +000016
Karl Wiberg5817d3d2018-04-06 10:06:42 +020017#include "api/audio_codecs/builtin_audio_decoder_factory.h"
Mirko Bonadei71207422017-09-15 13:58:09 +020018#include "common_types.h" // NOLINT(build/include)
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020019#include "modules/audio_coding/codecs/audio_format_conversion.h"
20#include "modules/audio_coding/include/audio_coding_module_typedefs.h"
21#include "modules/audio_coding/test/utility.h"
22#include "test/gtest.h"
23#include "test/testsupport/fileutils.h"
Mirko Bonadei71207422017-09-15 13:58:09 +020024#include "typedefs.h" // NOLINT(build/include)
niklase@google.com470e71d2011-07-07 08:21:25 +000025
tina.legrand@webrtc.org554ae1a2011-12-16 10:09:04 +000026namespace webrtc {
niklase@google.com470e71d2011-07-07 08:21:25 +000027
28// Class for simulating packet handling
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +000029TestPackStereo::TestPackStereo()
30 : receiver_acm_(NULL),
31 seq_no_(0),
32 timestamp_diff_(0),
33 last_in_timestamp_(0),
34 total_bytes_(0),
35 payload_size_(0),
36 codec_mode_(kNotSet),
Yves Gerey665174f2018-06-19 15:03:05 +020037 lost_packet_(false) {}
niklase@google.com470e71d2011-07-07 08:21:25 +000038
Yves Gerey665174f2018-06-19 15:03:05 +020039TestPackStereo::~TestPackStereo() {}
niklase@google.com470e71d2011-07-07 08:21:25 +000040
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +000041void TestPackStereo::RegisterReceiverACM(AudioCodingModule* acm) {
42 receiver_acm_ = acm;
43 return;
44}
niklase@google.com470e71d2011-07-07 08:21:25 +000045
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000046int32_t TestPackStereo::SendData(const FrameType frame_type,
47 const uint8_t payload_type,
48 const uint32_t timestamp,
49 const uint8_t* payload_data,
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +000050 const size_t payload_size,
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000051 const RTPFragmentationHeader* fragmentation) {
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +000052 WebRtcRTPHeader rtp_info;
pbos@webrtc.org0946a562013-04-09 00:28:06 +000053 int32_t status = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +000054
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +000055 rtp_info.header.markerBit = false;
56 rtp_info.header.ssrc = 0;
57 rtp_info.header.sequenceNumber = seq_no_++;
58 rtp_info.header.payloadType = payload_type;
59 rtp_info.header.timestamp = timestamp;
pbos22993e12015-10-19 02:39:06 -070060 if (frame_type == kEmptyFrame) {
tina.legrand@webrtc.org16b6b902012-04-12 11:02:38 +000061 // Skip this frame
62 return 0;
63 }
niklase@google.com470e71d2011-07-07 08:21:25 +000064
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +000065 if (lost_packet_ == false) {
66 if (frame_type != kAudioFrameCN) {
67 rtp_info.type.Audio.isCNG = false;
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +000068 rtp_info.type.Audio.channel = static_cast<int>(codec_mode_);
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +000069 } else {
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +000070 rtp_info.type.Audio.isCNG = true;
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +000071 rtp_info.type.Audio.channel = static_cast<int>(kMono);
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +000072 }
Yves Gerey665174f2018-06-19 15:03:05 +020073 status =
74 receiver_acm_->IncomingPacket(payload_data, payload_size, rtp_info);
niklase@google.com470e71d2011-07-07 08:21:25 +000075
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +000076 if (frame_type != kAudioFrameCN) {
henrike@webrtc.org6ac22e62014-08-11 21:06:30 +000077 payload_size_ = static_cast<int>(payload_size);
niklase@google.com470e71d2011-07-07 08:21:25 +000078 } else {
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +000079 payload_size_ = -1;
niklase@google.com470e71d2011-07-07 08:21:25 +000080 }
tina.legrand@webrtc.org16b6b902012-04-12 11:02:38 +000081
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +000082 timestamp_diff_ = timestamp - last_in_timestamp_;
83 last_in_timestamp_ = timestamp;
84 total_bytes_ += payload_size;
tina.legrand@webrtc.org16b6b902012-04-12 11:02:38 +000085 }
86 return status;
niklase@google.com470e71d2011-07-07 08:21:25 +000087}
88
pbos@webrtc.org0946a562013-04-09 00:28:06 +000089uint16_t TestPackStereo::payload_size() {
henrike@webrtc.org6ac22e62014-08-11 21:06:30 +000090 return static_cast<uint16_t>(payload_size_);
niklase@google.com470e71d2011-07-07 08:21:25 +000091}
92
pbos@webrtc.org0946a562013-04-09 00:28:06 +000093uint32_t TestPackStereo::timestamp_diff() {
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +000094 return timestamp_diff_;
niklase@google.com470e71d2011-07-07 08:21:25 +000095}
96
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +000097void TestPackStereo::reset_payload_size() {
98 payload_size_ = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +000099}
100
tina.legrand@webrtc.org16b6b902012-04-12 11:02:38 +0000101void TestPackStereo::set_codec_mode(enum StereoMonoMode mode) {
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000102 codec_mode_ = mode;
tina.legrand@webrtc.org16b6b902012-04-12 11:02:38 +0000103}
104
105void TestPackStereo::set_lost_packet(bool lost) {
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000106 lost_packet_ = lost;
niklase@google.com470e71d2011-07-07 08:21:25 +0000107}
108
henrik.lundin@webrtc.orgadaf8092014-04-17 08:29:10 +0000109TestStereo::TestStereo(int test_mode)
Karl Wiberg5817d3d2018-04-06 10:06:42 +0200110 : acm_a_(AudioCodingModule::Create(
111 AudioCodingModule::Config(CreateBuiltinAudioDecoderFactory()))),
112 acm_b_(AudioCodingModule::Create(
113 AudioCodingModule::Config(CreateBuiltinAudioDecoderFactory()))),
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000114 channel_a2b_(NULL),
115 test_cntr_(0),
116 pack_size_samp_(0),
117 pack_size_bytes_(0),
Karl Wibergeb254b42017-11-01 15:08:12 +0100118 counter_(0),
119 g722_pltype_(0),
120 l16_8khz_pltype_(-1),
121 l16_16khz_pltype_(-1),
122 l16_32khz_pltype_(-1)
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +0000123#ifdef PCMA_AND_PCMU
Karl Wiberg5817d3d2018-04-06 10:06:42 +0200124 ,
125 pcma_pltype_(-1),
126 pcmu_pltype_(-1)
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +0000127#endif
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +0000128#ifdef WEBRTC_CODEC_OPUS
Karl Wiberg5817d3d2018-04-06 10:06:42 +0200129 ,
130 opus_pltype_(-1)
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +0000131#endif
Karl Wibergeb254b42017-11-01 15:08:12 +0100132{
tina.legrand@webrtc.org45175852012-06-01 09:27:35 +0000133 // test_mode = 0 for silent test (auto test)
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000134 test_mode_ = test_mode;
niklase@google.com470e71d2011-07-07 08:21:25 +0000135}
136
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000137TestStereo::~TestStereo() {
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000138 if (channel_a2b_ != NULL) {
139 delete channel_a2b_;
140 channel_a2b_ = NULL;
141 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000142}
143
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000144void TestStereo::Perform() {
pbos@webrtc.org0946a562013-04-09 00:28:06 +0000145 uint16_t frequency_hz;
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000146 int audio_channels;
147 int codec_channels;
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000148 bool dtx;
149 bool vad;
150 ACMVADMode vad_mode;
niklase@google.com470e71d2011-07-07 08:21:25 +0000151
tina.legrand@webrtc.org45175852012-06-01 09:27:35 +0000152 // Open both mono and stereo test files in 32 kHz.
Yves Gerey665174f2018-06-19 15:03:05 +0200153 const std::string file_name_stereo =
154 webrtc::test::ResourcePath("audio_coding/teststereo32kHz", "pcm");
155 const std::string file_name_mono =
156 webrtc::test::ResourcePath("audio_coding/testfile32kHz", "pcm");
tina.legrand@webrtc.org45175852012-06-01 09:27:35 +0000157 frequency_hz = 32000;
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000158 in_file_stereo_ = new PCMFile();
159 in_file_mono_ = new PCMFile();
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000160 in_file_stereo_->Open(file_name_stereo, frequency_hz, "rb");
161 in_file_stereo_->ReadStereo(true);
162 in_file_mono_->Open(file_name_mono, frequency_hz, "rb");
163 in_file_mono_->ReadStereo(false);
164
tina.legrand@webrtc.org45175852012-06-01 09:27:35 +0000165 // Create and initialize two ACMs, one for each side of a one-to-one call.
andrew@webrtc.org89df0922013-09-12 01:27:43 +0000166 ASSERT_TRUE((acm_a_.get() != NULL) && (acm_b_.get() != NULL));
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000167 EXPECT_EQ(0, acm_a_->InitializeReceiver());
168 EXPECT_EQ(0, acm_b_->InitializeReceiver());
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000169
tina.legrand@webrtc.org45175852012-06-01 09:27:35 +0000170 // Register all available codes as receiving codecs.
pbos@webrtc.org0946a562013-04-09 00:28:06 +0000171 uint8_t num_encoders = acm_a_->NumberOfCodecs();
tina.legrand@webrtc.org45175852012-06-01 09:27:35 +0000172 CodecInst my_codec_param;
pbos@webrtc.org0946a562013-04-09 00:28:06 +0000173 for (uint8_t n = 0; n < num_encoders; n++) {
tina.legrand@webrtc.org7a7a0082013-02-21 10:27:48 +0000174 EXPECT_EQ(0, acm_b_->Codec(n, &my_codec_param));
kwibergda2bf4e2016-10-24 13:47:09 -0700175 EXPECT_EQ(true, acm_b_->RegisterReceiveCodec(
176 my_codec_param.pltype, CodecInstToSdp(my_codec_param)));
tina.legrand@webrtc.org45175852012-06-01 09:27:35 +0000177 }
178
179 // Test that unregister all receive codecs works.
pbos@webrtc.org0946a562013-04-09 00:28:06 +0000180 for (uint8_t n = 0; n < num_encoders; n++) {
tina.legrand@webrtc.org7a7a0082013-02-21 10:27:48 +0000181 EXPECT_EQ(0, acm_b_->Codec(n, &my_codec_param));
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000182 EXPECT_EQ(0, acm_b_->UnregisterReceiveCodec(my_codec_param.pltype));
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000183 }
tina.legrand@webrtc.orgae1c4542012-03-12 08:41:30 +0000184
tina.legrand@webrtc.org45175852012-06-01 09:27:35 +0000185 // Register all available codes as receiving codecs once more.
pbos@webrtc.org0946a562013-04-09 00:28:06 +0000186 for (uint8_t n = 0; n < num_encoders; n++) {
tina.legrand@webrtc.org7a7a0082013-02-21 10:27:48 +0000187 EXPECT_EQ(0, acm_b_->Codec(n, &my_codec_param));
kwibergda2bf4e2016-10-24 13:47:09 -0700188 EXPECT_EQ(true, acm_b_->RegisterReceiveCodec(
189 my_codec_param.pltype, CodecInstToSdp(my_codec_param)));
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000190 }
tina.legrand@webrtc.orgae1c4542012-03-12 08:41:30 +0000191
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000192 // Create and connect the channel.
193 channel_a2b_ = new TestPackStereo;
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000194 EXPECT_EQ(0, acm_a_->RegisterTransportCallback(channel_a2b_));
andrew@webrtc.org89df0922013-09-12 01:27:43 +0000195 channel_a2b_->RegisterReceiverACM(acm_b_.get());
tina.legrand@webrtc.orgdf697752012-02-08 10:22:21 +0000196
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000197 // Start with setting VAD/DTX, before we know we will send stereo.
198 // Continue with setting a stereo codec as send codec and verify that
199 // VAD/DTX gets turned off.
200 EXPECT_EQ(0, acm_a_->SetVAD(true, true, VADNormal));
tina.legrand@webrtc.org7a7a0082013-02-21 10:27:48 +0000201 EXPECT_EQ(0, acm_a_->VAD(&dtx, &vad, &vad_mode));
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000202 EXPECT_TRUE(dtx);
203 EXPECT_TRUE(vad);
204 char codec_pcma_temp[] = "PCMA";
205 RegisterSendCodec('A', codec_pcma_temp, 8000, 64000, 80, 2, pcma_pltype_);
tina.legrand@webrtc.org7a7a0082013-02-21 10:27:48 +0000206 EXPECT_EQ(0, acm_a_->VAD(&dtx, &vad, &vad_mode));
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000207 EXPECT_FALSE(dtx);
208 EXPECT_FALSE(vad);
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000209 if (test_mode_ != 0) {
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000210 printf("\n");
211 }
212
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000213 //
214 // Test Stereo-To-Stereo for all codecs.
215 //
216 audio_channels = 2;
217 codec_channels = 2;
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000218
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000219 // All codecs are tested for all allowed sampling frequencies, rates and
220 // packet sizes.
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000221 if (test_mode_ != 0) {
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000222 printf("===========================================================\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000223 printf("Test number: %d\n", test_cntr_ + 1);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000224 printf("Test type: Stereo-to-stereo\n");
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000225 }
226 channel_a2b_->set_codec_mode(kStereo);
227 test_cntr_++;
228 OpenOutFile(test_cntr_);
229 char codec_g722[] = "G722";
230 RegisterSendCodec('A', codec_g722, 16000, 64000, 160, codec_channels,
Yves Gerey665174f2018-06-19 15:03:05 +0200231 g722_pltype_);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000232 Run(channel_a2b_, audio_channels, codec_channels);
233 RegisterSendCodec('A', codec_g722, 16000, 64000, 320, codec_channels,
Yves Gerey665174f2018-06-19 15:03:05 +0200234 g722_pltype_);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000235 Run(channel_a2b_, audio_channels, codec_channels);
236 RegisterSendCodec('A', codec_g722, 16000, 64000, 480, codec_channels,
Yves Gerey665174f2018-06-19 15:03:05 +0200237 g722_pltype_);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000238 Run(channel_a2b_, audio_channels, codec_channels);
239 RegisterSendCodec('A', codec_g722, 16000, 64000, 640, codec_channels,
Yves Gerey665174f2018-06-19 15:03:05 +0200240 g722_pltype_);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000241 Run(channel_a2b_, audio_channels, codec_channels);
242 RegisterSendCodec('A', codec_g722, 16000, 64000, 800, codec_channels,
Yves Gerey665174f2018-06-19 15:03:05 +0200243 g722_pltype_);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000244 Run(channel_a2b_, audio_channels, codec_channels);
245 RegisterSendCodec('A', codec_g722, 16000, 64000, 960, codec_channels,
Yves Gerey665174f2018-06-19 15:03:05 +0200246 g722_pltype_);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000247 Run(channel_a2b_, audio_channels, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000248 out_file_.Close();
Karl Wibergeb254b42017-11-01 15:08:12 +0100249
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000250 if (test_mode_ != 0) {
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000251 printf("===========================================================\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000252 printf("Test number: %d\n", test_cntr_ + 1);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000253 printf("Test type: Stereo-to-stereo\n");
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000254 }
255 channel_a2b_->set_codec_mode(kStereo);
256 test_cntr_++;
257 OpenOutFile(test_cntr_);
258 char codec_l16[] = "L16";
259 RegisterSendCodec('A', codec_l16, 8000, 128000, 80, codec_channels,
Yves Gerey665174f2018-06-19 15:03:05 +0200260 l16_8khz_pltype_);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000261 Run(channel_a2b_, audio_channels, codec_channels);
262 RegisterSendCodec('A', codec_l16, 8000, 128000, 160, codec_channels,
Yves Gerey665174f2018-06-19 15:03:05 +0200263 l16_8khz_pltype_);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000264 Run(channel_a2b_, audio_channels, codec_channels);
265 RegisterSendCodec('A', codec_l16, 8000, 128000, 240, codec_channels,
Yves Gerey665174f2018-06-19 15:03:05 +0200266 l16_8khz_pltype_);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000267 Run(channel_a2b_, audio_channels, codec_channels);
268 RegisterSendCodec('A', codec_l16, 8000, 128000, 320, codec_channels,
Yves Gerey665174f2018-06-19 15:03:05 +0200269 l16_8khz_pltype_);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000270 Run(channel_a2b_, audio_channels, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000271 out_file_.Close();
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000272
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000273 if (test_mode_ != 0) {
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000274 printf("===========================================================\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000275 printf("Test number: %d\n", test_cntr_ + 1);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000276 printf("Test type: Stereo-to-stereo\n");
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000277 }
278 test_cntr_++;
279 OpenOutFile(test_cntr_);
280 RegisterSendCodec('A', codec_l16, 16000, 256000, 160, codec_channels,
Yves Gerey665174f2018-06-19 15:03:05 +0200281 l16_16khz_pltype_);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000282 Run(channel_a2b_, audio_channels, codec_channels);
283 RegisterSendCodec('A', codec_l16, 16000, 256000, 320, codec_channels,
Yves Gerey665174f2018-06-19 15:03:05 +0200284 l16_16khz_pltype_);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000285 Run(channel_a2b_, audio_channels, codec_channels);
286 RegisterSendCodec('A', codec_l16, 16000, 256000, 480, codec_channels,
Yves Gerey665174f2018-06-19 15:03:05 +0200287 l16_16khz_pltype_);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000288 Run(channel_a2b_, audio_channels, codec_channels);
289 RegisterSendCodec('A', codec_l16, 16000, 256000, 640, codec_channels,
Yves Gerey665174f2018-06-19 15:03:05 +0200290 l16_16khz_pltype_);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000291 Run(channel_a2b_, audio_channels, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000292 out_file_.Close();
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000293
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000294 if (test_mode_ != 0) {
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000295 printf("===========================================================\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000296 printf("Test number: %d\n", test_cntr_ + 1);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000297 printf("Test type: Stereo-to-stereo\n");
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000298 }
299 test_cntr_++;
300 OpenOutFile(test_cntr_);
301 RegisterSendCodec('A', codec_l16, 32000, 512000, 320, codec_channels,
Yves Gerey665174f2018-06-19 15:03:05 +0200302 l16_32khz_pltype_);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000303 Run(channel_a2b_, audio_channels, codec_channels);
304 RegisterSendCodec('A', codec_l16, 32000, 512000, 640, codec_channels,
Yves Gerey665174f2018-06-19 15:03:05 +0200305 l16_32khz_pltype_);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000306 Run(channel_a2b_, audio_channels, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000307 out_file_.Close();
niklase@google.com470e71d2011-07-07 08:21:25 +0000308#ifdef PCMA_AND_PCMU
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000309 if (test_mode_ != 0) {
310 printf("===========================================================\n");
311 printf("Test number: %d\n", test_cntr_ + 1);
312 printf("Test type: Stereo-to-stereo\n");
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000313 }
314 channel_a2b_->set_codec_mode(kStereo);
315 audio_channels = 2;
316 codec_channels = 2;
317 test_cntr_++;
318 OpenOutFile(test_cntr_);
319 char codec_pcma[] = "PCMA";
320 RegisterSendCodec('A', codec_pcma, 8000, 64000, 80, codec_channels,
321 pcma_pltype_);
322 Run(channel_a2b_, audio_channels, codec_channels);
323 RegisterSendCodec('A', codec_pcma, 8000, 64000, 160, codec_channels,
324 pcma_pltype_);
325 Run(channel_a2b_, audio_channels, codec_channels);
326 RegisterSendCodec('A', codec_pcma, 8000, 64000, 240, codec_channels,
327 pcma_pltype_);
328 Run(channel_a2b_, audio_channels, codec_channels);
329 RegisterSendCodec('A', codec_pcma, 8000, 64000, 320, codec_channels,
330 pcma_pltype_);
331 Run(channel_a2b_, audio_channels, codec_channels);
332 RegisterSendCodec('A', codec_pcma, 8000, 64000, 400, codec_channels,
333 pcma_pltype_);
334 Run(channel_a2b_, audio_channels, codec_channels);
335 RegisterSendCodec('A', codec_pcma, 8000, 64000, 480, codec_channels,
336 pcma_pltype_);
337 Run(channel_a2b_, audio_channels, codec_channels);
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000338
339 // Test that VAD/DTX cannot be turned on while sending stereo.
340 EXPECT_EQ(-1, acm_a_->SetVAD(true, true, VADNormal));
tina.legrand@webrtc.org7a7a0082013-02-21 10:27:48 +0000341 EXPECT_EQ(0, acm_a_->VAD(&dtx, &vad, &vad_mode));
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000342 EXPECT_FALSE(dtx);
343 EXPECT_FALSE(vad);
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000344 EXPECT_EQ(0, acm_a_->SetVAD(false, false, VADNormal));
tina.legrand@webrtc.org7a7a0082013-02-21 10:27:48 +0000345 EXPECT_EQ(0, acm_a_->VAD(&dtx, &vad, &vad_mode));
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000346 EXPECT_FALSE(dtx);
347 EXPECT_FALSE(vad);
348
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000349 out_file_.Close();
350 if (test_mode_ != 0) {
351 printf("===========================================================\n");
352 printf("Test number: %d\n", test_cntr_ + 1);
353 printf("Test type: Stereo-to-stereo\n");
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000354 }
355 test_cntr_++;
356 OpenOutFile(test_cntr_);
357 char codec_pcmu[] = "PCMU";
358 RegisterSendCodec('A', codec_pcmu, 8000, 64000, 80, codec_channels,
359 pcmu_pltype_);
360 Run(channel_a2b_, audio_channels, codec_channels);
361 RegisterSendCodec('A', codec_pcmu, 8000, 64000, 160, codec_channels,
362 pcmu_pltype_);
363 Run(channel_a2b_, audio_channels, codec_channels);
364 RegisterSendCodec('A', codec_pcmu, 8000, 64000, 240, codec_channels,
365 pcmu_pltype_);
366 Run(channel_a2b_, audio_channels, codec_channels);
367 RegisterSendCodec('A', codec_pcmu, 8000, 64000, 320, codec_channels,
368 pcmu_pltype_);
369 Run(channel_a2b_, audio_channels, codec_channels);
370 RegisterSendCodec('A', codec_pcmu, 8000, 64000, 400, codec_channels,
371 pcmu_pltype_);
372 Run(channel_a2b_, audio_channels, codec_channels);
373 RegisterSendCodec('A', codec_pcmu, 8000, 64000, 480, codec_channels,
374 pcmu_pltype_);
375 Run(channel_a2b_, audio_channels, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000376 out_file_.Close();
niklase@google.com470e71d2011-07-07 08:21:25 +0000377#endif
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000378#ifdef WEBRTC_CODEC_OPUS
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000379 if (test_mode_ != 0) {
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000380 printf("===========================================================\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000381 printf("Test number: %d\n", test_cntr_ + 1);
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000382 printf("Test type: Stereo-to-stereo\n");
383 }
384 channel_a2b_->set_codec_mode(kStereo);
385 audio_channels = 2;
386 codec_channels = 2;
387 test_cntr_++;
388 OpenOutFile(test_cntr_);
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000389
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000390 char codec_opus[] = "opus";
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000391 // Run Opus with 10 ms frame size.
392 RegisterSendCodec('A', codec_opus, 48000, 64000, 480, codec_channels,
Yves Gerey665174f2018-06-19 15:03:05 +0200393 opus_pltype_);
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000394 Run(channel_a2b_, audio_channels, codec_channels);
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000395 // Run Opus with 20 ms frame size.
Yves Gerey665174f2018-06-19 15:03:05 +0200396 RegisterSendCodec('A', codec_opus, 48000, 64000, 480 * 2, codec_channels,
397 opus_pltype_);
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000398 Run(channel_a2b_, audio_channels, codec_channels);
399 // Run Opus with 40 ms frame size.
Yves Gerey665174f2018-06-19 15:03:05 +0200400 RegisterSendCodec('A', codec_opus, 48000, 64000, 480 * 4, codec_channels,
401 opus_pltype_);
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000402 Run(channel_a2b_, audio_channels, codec_channels);
403 // Run Opus with 60 ms frame size.
Yves Gerey665174f2018-06-19 15:03:05 +0200404 RegisterSendCodec('A', codec_opus, 48000, 64000, 480 * 6, codec_channels,
405 opus_pltype_);
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000406 Run(channel_a2b_, audio_channels, codec_channels);
407 // Run Opus with 20 ms frame size and different bitrates.
408 RegisterSendCodec('A', codec_opus, 48000, 40000, 960, codec_channels,
Yves Gerey665174f2018-06-19 15:03:05 +0200409 opus_pltype_);
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000410 Run(channel_a2b_, audio_channels, codec_channels);
411 RegisterSendCodec('A', codec_opus, 48000, 510000, 960, codec_channels,
Yves Gerey665174f2018-06-19 15:03:05 +0200412 opus_pltype_);
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000413 Run(channel_a2b_, audio_channels, codec_channels);
414 out_file_.Close();
415#endif
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000416 //
417 // Test Mono-To-Stereo for all codecs.
418 //
419 audio_channels = 1;
420 codec_channels = 2;
niklase@google.com470e71d2011-07-07 08:21:25 +0000421
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000422 if (test_mode_ != 0) {
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000423 printf("===============================================================\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000424 printf("Test number: %d\n", test_cntr_ + 1);
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000425 printf("Test type: Mono-to-stereo\n");
426 }
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000427 test_cntr_++;
428 channel_a2b_->set_codec_mode(kStereo);
429 OpenOutFile(test_cntr_);
430 RegisterSendCodec('A', codec_g722, 16000, 64000, 160, codec_channels,
Yves Gerey665174f2018-06-19 15:03:05 +0200431 g722_pltype_);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000432 Run(channel_a2b_, audio_channels, codec_channels);
433 out_file_.Close();
Karl Wibergeb254b42017-11-01 15:08:12 +0100434
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000435 if (test_mode_ != 0) {
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000436 printf("===============================================================\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000437 printf("Test number: %d\n", test_cntr_ + 1);
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000438 printf("Test type: Mono-to-stereo\n");
439 }
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000440 test_cntr_++;
441 channel_a2b_->set_codec_mode(kStereo);
442 OpenOutFile(test_cntr_);
443 RegisterSendCodec('A', codec_l16, 8000, 128000, 80, codec_channels,
Yves Gerey665174f2018-06-19 15:03:05 +0200444 l16_8khz_pltype_);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000445 Run(channel_a2b_, audio_channels, codec_channels);
446 out_file_.Close();
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000447 if (test_mode_ != 0) {
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000448 printf("===============================================================\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000449 printf("Test number: %d\n", test_cntr_ + 1);
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000450 printf("Test type: Mono-to-stereo\n");
451 }
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000452 test_cntr_++;
453 OpenOutFile(test_cntr_);
454 RegisterSendCodec('A', codec_l16, 16000, 256000, 160, codec_channels,
Yves Gerey665174f2018-06-19 15:03:05 +0200455 l16_16khz_pltype_);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000456 Run(channel_a2b_, audio_channels, codec_channels);
457 out_file_.Close();
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000458 if (test_mode_ != 0) {
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000459 printf("===============================================================\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000460 printf("Test number: %d\n", test_cntr_ + 1);
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000461 printf("Test type: Mono-to-stereo\n");
462 }
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000463 test_cntr_++;
464 OpenOutFile(test_cntr_);
465 RegisterSendCodec('A', codec_l16, 32000, 512000, 320, codec_channels,
Yves Gerey665174f2018-06-19 15:03:05 +0200466 l16_32khz_pltype_);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000467 Run(channel_a2b_, audio_channels, codec_channels);
468 out_file_.Close();
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000469#ifdef PCMA_AND_PCMU
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000470 if (test_mode_ != 0) {
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000471 printf("===============================================================\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000472 printf("Test number: %d\n", test_cntr_ + 1);
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000473 printf("Test type: Mono-to-stereo\n");
474 }
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000475 test_cntr_++;
476 channel_a2b_->set_codec_mode(kStereo);
477 OpenOutFile(test_cntr_);
478 RegisterSendCodec('A', codec_pcmu, 8000, 64000, 80, codec_channels,
tina.legrand@webrtc.orgae1c4542012-03-12 08:41:30 +0000479 pcmu_pltype_);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000480 Run(channel_a2b_, audio_channels, codec_channels);
481 RegisterSendCodec('A', codec_pcma, 8000, 64000, 80, codec_channels,
tina.legrand@webrtc.orgae1c4542012-03-12 08:41:30 +0000482 pcma_pltype_);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000483 Run(channel_a2b_, audio_channels, codec_channels);
484 out_file_.Close();
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000485#endif
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000486#ifdef WEBRTC_CODEC_OPUS
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000487 if (test_mode_ != 0) {
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000488 printf("===============================================================\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000489 printf("Test number: %d\n", test_cntr_ + 1);
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000490 printf("Test type: Mono-to-stereo\n");
491 }
tina.legrand@webrtc.orgc4590582012-11-28 12:23:29 +0000492
493 // Keep encode and decode in stereo.
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000494 test_cntr_++;
495 channel_a2b_->set_codec_mode(kStereo);
496 OpenOutFile(test_cntr_);
497 RegisterSendCodec('A', codec_opus, 48000, 64000, 960, codec_channels,
Yves Gerey665174f2018-06-19 15:03:05 +0200498 opus_pltype_);
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000499 Run(channel_a2b_, audio_channels, codec_channels);
tina.legrand@webrtc.orgc4590582012-11-28 12:23:29 +0000500
501 // Encode in mono, decode in stereo mode.
502 RegisterSendCodec('A', codec_opus, 48000, 64000, 960, 1, opus_pltype_);
503 Run(channel_a2b_, audio_channels, codec_channels);
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000504 out_file_.Close();
505#endif
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000506
507 //
508 // Test Stereo-To-Mono for all codecs.
509 //
510 audio_channels = 2;
511 codec_channels = 1;
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000512 channel_a2b_->set_codec_mode(kMono);
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000513
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000514 // Run stereo audio and mono codec.
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000515 if (test_mode_ != 0) {
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000516 printf("===============================================================\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000517 printf("Test number: %d\n", test_cntr_ + 1);
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000518 printf("Test type: Stereo-to-mono\n");
519 }
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000520 test_cntr_++;
521 OpenOutFile(test_cntr_);
522 RegisterSendCodec('A', codec_g722, 16000, 64000, 160, codec_channels,
Yves Gerey665174f2018-06-19 15:03:05 +0200523 g722_pltype_);
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000524
525 // Make sure it is possible to set VAD/CNG, now that we are sending mono
526 // again.
527 EXPECT_EQ(0, acm_a_->SetVAD(true, true, VADNormal));
tina.legrand@webrtc.org7a7a0082013-02-21 10:27:48 +0000528 EXPECT_EQ(0, acm_a_->VAD(&dtx, &vad, &vad_mode));
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000529 EXPECT_TRUE(dtx);
530 EXPECT_TRUE(vad);
531 EXPECT_EQ(0, acm_a_->SetVAD(false, false, VADNormal));
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000532 Run(channel_a2b_, audio_channels, codec_channels);
533 out_file_.Close();
Karl Wibergeb254b42017-11-01 15:08:12 +0100534
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000535 if (test_mode_ != 0) {
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000536 printf("===============================================================\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000537 printf("Test number: %d\n", test_cntr_ + 1);
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000538 printf("Test type: Stereo-to-mono\n");
539 }
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000540 test_cntr_++;
541 OpenOutFile(test_cntr_);
542 RegisterSendCodec('A', codec_l16, 8000, 128000, 80, codec_channels,
Yves Gerey665174f2018-06-19 15:03:05 +0200543 l16_8khz_pltype_);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000544 Run(channel_a2b_, audio_channels, codec_channels);
545 out_file_.Close();
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000546 if (test_mode_ != 0) {
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000547 printf("===============================================================\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000548 printf("Test number: %d\n", test_cntr_ + 1);
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000549 printf("Test type: Stereo-to-mono\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000550 }
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000551 test_cntr_++;
552 OpenOutFile(test_cntr_);
553 RegisterSendCodec('A', codec_l16, 16000, 256000, 160, codec_channels,
Yves Gerey665174f2018-06-19 15:03:05 +0200554 l16_16khz_pltype_);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000555 Run(channel_a2b_, audio_channels, codec_channels);
556 out_file_.Close();
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000557 if (test_mode_ != 0) {
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000558 printf("==============================================================\n");
559 printf("Test number: %d\n", test_cntr_ + 1);
560 printf("Test type: Stereo-to-mono\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000561 }
562 test_cntr_++;
563 OpenOutFile(test_cntr_);
564 RegisterSendCodec('A', codec_l16, 32000, 512000, 320, codec_channels,
Yves Gerey665174f2018-06-19 15:03:05 +0200565 l16_32khz_pltype_);
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000566 Run(channel_a2b_, audio_channels, codec_channels);
567 out_file_.Close();
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000568#ifdef PCMA_AND_PCMU
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000569 if (test_mode_ != 0) {
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000570 printf("===============================================================\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000571 printf("Test number: %d\n", test_cntr_ + 1);
tina.legrand@webrtc.orgdf697752012-02-08 10:22:21 +0000572 printf("Test type: Stereo-to-mono\n");
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000573 }
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000574 test_cntr_++;
575 OpenOutFile(test_cntr_);
576 RegisterSendCodec('A', codec_pcmu, 8000, 64000, 80, codec_channels,
tina.legrand@webrtc.orgae1c4542012-03-12 08:41:30 +0000577 pcmu_pltype_);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000578 Run(channel_a2b_, audio_channels, codec_channels);
579 RegisterSendCodec('A', codec_pcma, 8000, 64000, 80, codec_channels,
tina.legrand@webrtc.orgae1c4542012-03-12 08:41:30 +0000580 pcma_pltype_);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000581 Run(channel_a2b_, audio_channels, codec_channels);
582 out_file_.Close();
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000583#endif
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000584#ifdef WEBRTC_CODEC_OPUS
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000585 if (test_mode_ != 0) {
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000586 printf("===============================================================\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000587 printf("Test number: %d\n", test_cntr_ + 1);
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000588 printf("Test type: Stereo-to-mono\n");
589 }
590 test_cntr_++;
591 OpenOutFile(test_cntr_);
tina.legrand@webrtc.orgc4590582012-11-28 12:23:29 +0000592 // Encode and decode in mono.
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000593 RegisterSendCodec('A', codec_opus, 48000, 32000, 960, codec_channels,
Yves Gerey665174f2018-06-19 15:03:05 +0200594 opus_pltype_);
tina.legrand@webrtc.orgc4590582012-11-28 12:23:29 +0000595 CodecInst opus_codec_param;
pbos@webrtc.org0946a562013-04-09 00:28:06 +0000596 for (uint8_t n = 0; n < num_encoders; n++) {
tina.legrand@webrtc.org7a7a0082013-02-21 10:27:48 +0000597 EXPECT_EQ(0, acm_b_->Codec(n, &opus_codec_param));
tina.legrand@webrtc.orgc4590582012-11-28 12:23:29 +0000598 if (!strcmp(opus_codec_param.plname, "opus")) {
599 opus_codec_param.channels = 1;
kwibergda2bf4e2016-10-24 13:47:09 -0700600 EXPECT_EQ(true,
601 acm_b_->RegisterReceiveCodec(opus_codec_param.pltype,
602 CodecInstToSdp(opus_codec_param)));
tina.legrand@webrtc.orgc4590582012-11-28 12:23:29 +0000603 break;
604 }
605 }
606 Run(channel_a2b_, audio_channels, codec_channels);
607
608 // Encode in stereo, decode in mono.
609 RegisterSendCodec('A', codec_opus, 48000, 32000, 960, 2, opus_pltype_);
610 Run(channel_a2b_, audio_channels, codec_channels);
611
612 out_file_.Close();
613
614 // Test switching between decoding mono and stereo for Opus.
615
616 // Decode in mono.
617 test_cntr_++;
618 OpenOutFile(test_cntr_);
619 if (test_mode_ != 0) {
620 // Print out codec and settings
Yves Gerey665174f2018-06-19 15:03:05 +0200621 printf(
622 "Test number: %d\nCodec: Opus Freq: 48000 Rate :32000 PackSize: 960"
623 " Decode: mono\n",
624 test_cntr_);
tina.legrand@webrtc.orgc4590582012-11-28 12:23:29 +0000625 }
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000626 Run(channel_a2b_, audio_channels, codec_channels);
627 out_file_.Close();
tina.legrand@webrtc.orgc4590582012-11-28 12:23:29 +0000628 // Decode in stereo.
629 test_cntr_++;
630 OpenOutFile(test_cntr_);
631 if (test_mode_ != 0) {
632 // Print out codec and settings
Yves Gerey665174f2018-06-19 15:03:05 +0200633 printf(
634 "Test number: %d\nCodec: Opus Freq: 48000 Rate :32000 PackSize: 960"
635 " Decode: stereo\n",
636 test_cntr_);
tina.legrand@webrtc.orgc4590582012-11-28 12:23:29 +0000637 }
638 opus_codec_param.channels = 2;
kwibergda2bf4e2016-10-24 13:47:09 -0700639 EXPECT_EQ(true,
640 acm_b_->RegisterReceiveCodec(opus_codec_param.pltype,
641 CodecInstToSdp(opus_codec_param)));
tina.legrand@webrtc.orgc4590582012-11-28 12:23:29 +0000642 Run(channel_a2b_, audio_channels, 2);
643 out_file_.Close();
644 // Decode in mono.
645 test_cntr_++;
646 OpenOutFile(test_cntr_);
647 if (test_mode_ != 0) {
648 // Print out codec and settings
Yves Gerey665174f2018-06-19 15:03:05 +0200649 printf(
650 "Test number: %d\nCodec: Opus Freq: 48000 Rate :32000 PackSize: 960"
651 " Decode: mono\n",
652 test_cntr_);
tina.legrand@webrtc.orgc4590582012-11-28 12:23:29 +0000653 }
654 opus_codec_param.channels = 1;
kwibergda2bf4e2016-10-24 13:47:09 -0700655 EXPECT_EQ(true,
656 acm_b_->RegisterReceiveCodec(opus_codec_param.pltype,
657 CodecInstToSdp(opus_codec_param)));
tina.legrand@webrtc.orgc4590582012-11-28 12:23:29 +0000658 Run(channel_a2b_, audio_channels, codec_channels);
659 out_file_.Close();
660
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000661#endif
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000662
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000663 // Print out which codecs were tested, and which were not, in the run.
664 if (test_mode_ != 0) {
665 printf("\nThe following codecs was INCLUDED in the test:\n");
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000666 printf(" G.722\n");
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000667 printf(" PCM16\n");
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000668 printf(" G.711\n");
tina.legrand@webrtc.orgc4590582012-11-28 12:23:29 +0000669#ifdef WEBRTC_CODEC_OPUS
670 printf(" Opus\n");
671#endif
Yves Gerey665174f2018-06-19 15:03:05 +0200672 printf(
673 "\nTo complete the test, listen to the %d number of output "
674 "files.\n",
675 test_cntr_);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000676 }
677
678 // Delete the file pointers.
679 delete in_file_stereo_;
680 delete in_file_mono_;
niklase@google.com470e71d2011-07-07 08:21:25 +0000681}
682
683// Register Codec to use in the test
684//
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000685// Input: side - which ACM to use, 'A' or 'B'
686// codec_name - name to use when register the codec
687// sampling_freq_hz - sampling frequency in Herz
688// rate - bitrate in bytes
689// pack_size - packet size in samples
690// channels - number of channels; 1 for mono, 2 for stereo
691// payload_type - payload type for the codec
Yves Gerey665174f2018-06-19 15:03:05 +0200692void TestStereo::RegisterSendCodec(char side,
693 char* codec_name,
694 int32_t sampling_freq_hz,
695 int rate,
696 int pack_size,
697 int channels,
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000698 int payload_type) {
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000699 if (test_mode_ != 0) {
700 // Print out codec and settings
tina.legrand@webrtc.orgba468042012-08-17 10:38:28 +0000701 printf("Codec: %s Freq: %d Rate: %d PackSize: %d\n", codec_name,
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000702 sampling_freq_hz, rate, pack_size);
703 }
704
705 // Store packet size in samples, used to validate the received packet
706 pack_size_samp_ = pack_size;
707
708 // Store the expected packet size in bytes, used to validate the received
709 // packet. Add 0.875 to always round up to a whole byte.
pbos@webrtc.orgd8ca7232014-12-10 11:49:13 +0000710 pack_size_bytes_ = (uint16_t)(static_cast<float>(pack_size * rate) /
711 static_cast<float>(sampling_freq_hz * 8) +
712 0.875);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000713
714 // Set pointer to the ACM where to register the codec
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000715 AudioCodingModule* my_acm = NULL;
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000716 switch (side) {
717 case 'A': {
andrew@webrtc.org89df0922013-09-12 01:27:43 +0000718 my_acm = acm_a_.get();
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000719 break;
niklase@google.com470e71d2011-07-07 08:21:25 +0000720 }
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000721 case 'B': {
andrew@webrtc.org89df0922013-09-12 01:27:43 +0000722 my_acm = acm_b_.get();
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000723 break;
tina.legrand@webrtc.org16b6b902012-04-12 11:02:38 +0000724 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000725 default:
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000726 break;
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000727 }
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000728 ASSERT_TRUE(my_acm != NULL);
niklase@google.com470e71d2011-07-07 08:21:25 +0000729
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000730 CodecInst my_codec_param;
731 // Get all codec parameters before registering
tina.legrand@webrtc.orgee92b662013-08-27 07:33:51 +0000732 EXPECT_GT(AudioCodingModule::Codec(codec_name, &my_codec_param,
Yves Gerey665174f2018-06-19 15:03:05 +0200733 sampling_freq_hz, channels),
734 -1);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000735 my_codec_param.rate = rate;
736 my_codec_param.pacsize = pack_size;
tina.legrand@webrtc.orgee92b662013-08-27 07:33:51 +0000737 EXPECT_EQ(0, my_acm->RegisterSendCodec(my_codec_param));
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000738
739 send_codec_name_ = codec_name;
niklase@google.com470e71d2011-07-07 08:21:25 +0000740}
741
Yves Gerey665174f2018-06-19 15:03:05 +0200742void TestStereo::Run(TestPackStereo* channel,
743 int in_channels,
744 int out_channels,
tina.legrand@webrtc.org16b6b902012-04-12 11:02:38 +0000745 int percent_loss) {
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000746 AudioFrame audio_frame;
niklase@google.com470e71d2011-07-07 08:21:25 +0000747
pbos@webrtc.org0946a562013-04-09 00:28:06 +0000748 int32_t out_freq_hz_b = out_file_.SamplingFrequency();
749 uint16_t rec_size;
750 uint32_t time_stamp_diff;
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000751 channel->reset_payload_size();
752 int error_count = 0;
tina.legrand@webrtc.org65d61c32014-06-05 13:42:51 +0000753 int variable_bytes = 0;
754 int variable_packets = 0;
Henrik Lundin4d682082015-12-10 16:24:39 +0100755 // Set test length to 500 ms (50 blocks of 10 ms each).
756 in_file_mono_->SetNum10MsBlocksToRead(50);
757 in_file_stereo_->SetNum10MsBlocksToRead(50);
758 // Fast-forward 1 second (100 blocks) since the files start with silence.
759 in_file_stereo_->FastForward(100);
760 in_file_mono_->FastForward(100);
niklase@google.com470e71d2011-07-07 08:21:25 +0000761
andresp@webrtc.orgd0b436a2014-01-13 13:15:59 +0000762 while (1) {
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000763 // Simulate packet loss by setting |packet_loss_| to "true" in
764 // |percent_loss| percent of the loops.
765 if (percent_loss > 0) {
766 if (counter_ == floor((100 / percent_loss) + 0.5)) {
767 counter_ = 0;
768 channel->set_lost_packet(true);
769 } else {
770 channel->set_lost_packet(false);
771 }
772 counter_++;
niklase@google.com470e71d2011-07-07 08:21:25 +0000773 }
774
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000775 // Add 10 msec to ACM
776 if (in_channels == 1) {
777 if (in_file_mono_->EndOfFile()) {
778 break;
779 }
780 in_file_mono_->Read10MsData(audio_frame);
781 } else {
782 if (in_file_stereo_->EndOfFile()) {
783 break;
784 }
785 in_file_stereo_->Read10MsData(audio_frame);
786 }
henrik.lundin@webrtc.orgf56c1622015-03-02 12:29:30 +0000787 EXPECT_GE(acm_a_->Add10MsData(audio_frame), 0);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000788
tina.legrand@webrtc.org65d61c32014-06-05 13:42:51 +0000789 // Verify that the received packet size matches the settings.
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000790 rec_size = channel->payload_size();
791 if ((0 < rec_size) & (rec_size < 65535)) {
tina.legrand@webrtc.org65d61c32014-06-05 13:42:51 +0000792 if (strcmp(send_codec_name_, "opus") == 0) {
793 // Opus is a variable rate codec, hence calculate the average packet
794 // size, and later make sure the average is in the right range.
795 variable_bytes += rec_size;
796 variable_packets++;
797 } else {
798 // For fixed rate codecs, check that packet size is correct.
Yves Gerey665174f2018-06-19 15:03:05 +0200799 if ((rec_size != pack_size_bytes_ * out_channels) &&
800 (pack_size_bytes_ < 65535)) {
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000801 error_count++;
802 }
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000803 }
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000804 // Verify that the timestamp is updated with expected length
805 time_stamp_diff = channel->timestamp_diff();
806 if ((counter_ > 10) && (time_stamp_diff != pack_size_samp_)) {
807 error_count++;
808 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000809 }
810
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000811 // Run received side of ACM
henrik.lundind4ccb002016-05-17 12:21:55 -0700812 bool muted;
813 EXPECT_EQ(0, acm_b_->PlayoutData10Ms(out_freq_hz_b, &audio_frame, &muted));
814 ASSERT_FALSE(muted);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000815
816 // Write output speech to file
817 out_file_.Write10MsData(
yujo36b1a5f2017-06-12 12:45:32 -0700818 audio_frame.data(),
andrew@webrtc.org63a50982012-05-02 23:56:37 +0000819 audio_frame.samples_per_channel_ * audio_frame.num_channels_);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000820 }
821
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000822 EXPECT_EQ(0, error_count);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000823
tina.legrand@webrtc.org65d61c32014-06-05 13:42:51 +0000824 // Check that packet size is in the right range for variable rate codecs,
825 // such as Opus.
826 if (variable_packets > 0) {
827 variable_bytes /= variable_packets;
Henrik Lundin4d682082015-12-10 16:24:39 +0100828 EXPECT_NEAR(variable_bytes, pack_size_bytes_, 18);
tina.legrand@webrtc.org65d61c32014-06-05 13:42:51 +0000829 }
830
andresp@webrtc.orgd0b436a2014-01-13 13:15:59 +0000831 if (in_file_mono_->EndOfFile()) {
832 in_file_mono_->Rewind();
833 }
834 if (in_file_stereo_->EndOfFile()) {
835 in_file_stereo_->Rewind();
836 }
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000837 // Reset in case we ended with a lost packet
838 channel->set_lost_packet(false);
niklase@google.com470e71d2011-07-07 08:21:25 +0000839}
840
pbos@webrtc.org0946a562013-04-09 00:28:06 +0000841void TestStereo::OpenOutFile(int16_t test_number) {
tina.legrand@webrtc.orgba468042012-08-17 10:38:28 +0000842 std::string file_name;
843 std::stringstream file_stream;
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000844 file_stream << webrtc::test::OutputPath() << "teststereo_out_" << test_number
Yves Gerey665174f2018-06-19 15:03:05 +0200845 << ".pcm";
tina.legrand@webrtc.orgba468042012-08-17 10:38:28 +0000846 file_name = file_stream.str();
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000847 out_file_.Open(file_name, 32000, "wb");
niklase@google.com470e71d2011-07-07 08:21:25 +0000848}
849
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000850void TestStereo::DisplaySendReceiveCodec() {
kwiberg1fd4a4a2015-11-03 11:20:50 -0800851 auto send_codec = acm_a_->SendCodec();
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000852 if (test_mode_ != 0) {
kwiberg1fd4a4a2015-11-03 11:20:50 -0800853 ASSERT_TRUE(send_codec);
854 printf("%s -> ", send_codec->plname);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000855 }
kwiberg1fd4a4a2015-11-03 11:20:50 -0800856 CodecInst receive_codec;
857 acm_b_->ReceiveCodec(&receive_codec);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000858 if (test_mode_ != 0) {
kwiberg1fd4a4a2015-11-03 11:20:50 -0800859 printf("%s\n", receive_codec.plname);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000860 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000861}
862
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000863} // namespace webrtc