blob: ba86719fe82c3bef5e6ef8d2ed860474c131694c [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
Mirko Bonadei71207422017-09-15 13:58:09 +020017#include "common_types.h" // NOLINT(build/include)
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020018#include "modules/audio_coding/codecs/audio_format_conversion.h"
19#include "modules/audio_coding/include/audio_coding_module_typedefs.h"
20#include "modules/audio_coding/test/utility.h"
21#include "test/gtest.h"
22#include "test/testsupport/fileutils.h"
Mirko Bonadei71207422017-09-15 13:58:09 +020023#include "typedefs.h" // NOLINT(build/include)
niklase@google.com470e71d2011-07-07 08:21:25 +000024
tina.legrand@webrtc.org554ae1a2011-12-16 10:09:04 +000025namespace webrtc {
niklase@google.com470e71d2011-07-07 08:21:25 +000026
27// Class for simulating packet handling
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +000028TestPackStereo::TestPackStereo()
29 : receiver_acm_(NULL),
30 seq_no_(0),
31 timestamp_diff_(0),
32 last_in_timestamp_(0),
33 total_bytes_(0),
34 payload_size_(0),
35 codec_mode_(kNotSet),
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000036 lost_packet_(false) {
37}
niklase@google.com470e71d2011-07-07 08:21:25 +000038
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000039TestPackStereo::~TestPackStereo() {
40}
niklase@google.com470e71d2011-07-07 08:21:25 +000041
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +000042void TestPackStereo::RegisterReceiverACM(AudioCodingModule* acm) {
43 receiver_acm_ = acm;
44 return;
45}
niklase@google.com470e71d2011-07-07 08:21:25 +000046
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000047int32_t TestPackStereo::SendData(const FrameType frame_type,
48 const uint8_t payload_type,
49 const uint32_t timestamp,
50 const uint8_t* payload_data,
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +000051 const size_t payload_size,
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000052 const RTPFragmentationHeader* fragmentation) {
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +000053 WebRtcRTPHeader rtp_info;
pbos@webrtc.org0946a562013-04-09 00:28:06 +000054 int32_t status = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +000055
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +000056 rtp_info.header.markerBit = false;
57 rtp_info.header.ssrc = 0;
58 rtp_info.header.sequenceNumber = seq_no_++;
59 rtp_info.header.payloadType = payload_type;
60 rtp_info.header.timestamp = timestamp;
pbos22993e12015-10-19 02:39:06 -070061 if (frame_type == kEmptyFrame) {
tina.legrand@webrtc.org16b6b902012-04-12 11:02:38 +000062 // Skip this frame
63 return 0;
64 }
niklase@google.com470e71d2011-07-07 08:21:25 +000065
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +000066 if (lost_packet_ == false) {
67 if (frame_type != kAudioFrameCN) {
68 rtp_info.type.Audio.isCNG = false;
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +000069 rtp_info.type.Audio.channel = static_cast<int>(codec_mode_);
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +000070 } else {
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +000071 rtp_info.type.Audio.isCNG = true;
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +000072 rtp_info.type.Audio.channel = static_cast<int>(kMono);
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +000073 }
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +000074 status = receiver_acm_->IncomingPacket(payload_data, payload_size,
tina.legrand@webrtc.org45175852012-06-01 09:27:35 +000075 rtp_info);
niklase@google.com470e71d2011-07-07 08:21:25 +000076
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +000077 if (frame_type != kAudioFrameCN) {
henrike@webrtc.org6ac22e62014-08-11 21:06:30 +000078 payload_size_ = static_cast<int>(payload_size);
niklase@google.com470e71d2011-07-07 08:21:25 +000079 } else {
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +000080 payload_size_ = -1;
niklase@google.com470e71d2011-07-07 08:21:25 +000081 }
tina.legrand@webrtc.org16b6b902012-04-12 11:02:38 +000082
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +000083 timestamp_diff_ = timestamp - last_in_timestamp_;
84 last_in_timestamp_ = timestamp;
85 total_bytes_ += payload_size;
tina.legrand@webrtc.org16b6b902012-04-12 11:02:38 +000086 }
87 return status;
niklase@google.com470e71d2011-07-07 08:21:25 +000088}
89
pbos@webrtc.org0946a562013-04-09 00:28:06 +000090uint16_t TestPackStereo::payload_size() {
henrike@webrtc.org6ac22e62014-08-11 21:06:30 +000091 return static_cast<uint16_t>(payload_size_);
niklase@google.com470e71d2011-07-07 08:21:25 +000092}
93
pbos@webrtc.org0946a562013-04-09 00:28:06 +000094uint32_t TestPackStereo::timestamp_diff() {
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +000095 return timestamp_diff_;
niklase@google.com470e71d2011-07-07 08:21:25 +000096}
97
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +000098void TestPackStereo::reset_payload_size() {
99 payload_size_ = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000100}
101
tina.legrand@webrtc.org16b6b902012-04-12 11:02:38 +0000102void TestPackStereo::set_codec_mode(enum StereoMonoMode mode) {
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000103 codec_mode_ = mode;
tina.legrand@webrtc.org16b6b902012-04-12 11:02:38 +0000104}
105
106void TestPackStereo::set_lost_packet(bool lost) {
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000107 lost_packet_ = lost;
niklase@google.com470e71d2011-07-07 08:21:25 +0000108}
109
henrik.lundin@webrtc.orgadaf8092014-04-17 08:29:10 +0000110TestStereo::TestStereo(int test_mode)
solenbergc7b4a452017-09-28 07:37:11 -0700111 : acm_a_(AudioCodingModule::Create()),
112 acm_b_(AudioCodingModule::Create()),
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000113 channel_a2b_(NULL),
114 test_cntr_(0),
115 pack_size_samp_(0),
116 pack_size_bytes_(0),
Karl Wibergeb254b42017-11-01 15:08:12 +0100117 counter_(0),
118 g722_pltype_(0),
119 l16_8khz_pltype_(-1),
120 l16_16khz_pltype_(-1),
121 l16_32khz_pltype_(-1)
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +0000122#ifdef PCMA_AND_PCMU
123 , pcma_pltype_(-1)
124 , pcmu_pltype_(-1)
125#endif
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +0000126#ifdef WEBRTC_CODEC_OPUS
127 , opus_pltype_(-1)
128#endif
Karl Wibergeb254b42017-11-01 15:08:12 +0100129{
tina.legrand@webrtc.org45175852012-06-01 09:27:35 +0000130 // test_mode = 0 for silent test (auto test)
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000131 test_mode_ = test_mode;
niklase@google.com470e71d2011-07-07 08:21:25 +0000132}
133
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000134TestStereo::~TestStereo() {
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000135 if (channel_a2b_ != NULL) {
136 delete channel_a2b_;
137 channel_a2b_ = NULL;
138 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000139}
140
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000141void TestStereo::Perform() {
pbos@webrtc.org0946a562013-04-09 00:28:06 +0000142 uint16_t frequency_hz;
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000143 int audio_channels;
144 int codec_channels;
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000145 bool dtx;
146 bool vad;
147 ACMVADMode vad_mode;
niklase@google.com470e71d2011-07-07 08:21:25 +0000148
tina.legrand@webrtc.org45175852012-06-01 09:27:35 +0000149 // Open both mono and stereo test files in 32 kHz.
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000150 const std::string file_name_stereo = webrtc::test::ResourcePath(
151 "audio_coding/teststereo32kHz", "pcm");
152 const std::string file_name_mono = webrtc::test::ResourcePath(
153 "audio_coding/testfile32kHz", "pcm");
tina.legrand@webrtc.org45175852012-06-01 09:27:35 +0000154 frequency_hz = 32000;
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000155 in_file_stereo_ = new PCMFile();
156 in_file_mono_ = new PCMFile();
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000157 in_file_stereo_->Open(file_name_stereo, frequency_hz, "rb");
158 in_file_stereo_->ReadStereo(true);
159 in_file_mono_->Open(file_name_mono, frequency_hz, "rb");
160 in_file_mono_->ReadStereo(false);
161
tina.legrand@webrtc.org45175852012-06-01 09:27:35 +0000162 // Create and initialize two ACMs, one for each side of a one-to-one call.
andrew@webrtc.org89df0922013-09-12 01:27:43 +0000163 ASSERT_TRUE((acm_a_.get() != NULL) && (acm_b_.get() != NULL));
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000164 EXPECT_EQ(0, acm_a_->InitializeReceiver());
165 EXPECT_EQ(0, acm_b_->InitializeReceiver());
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000166
tina.legrand@webrtc.org45175852012-06-01 09:27:35 +0000167 // Register all available codes as receiving codecs.
pbos@webrtc.org0946a562013-04-09 00:28:06 +0000168 uint8_t num_encoders = acm_a_->NumberOfCodecs();
tina.legrand@webrtc.org45175852012-06-01 09:27:35 +0000169 CodecInst my_codec_param;
pbos@webrtc.org0946a562013-04-09 00:28:06 +0000170 for (uint8_t n = 0; n < num_encoders; n++) {
tina.legrand@webrtc.org7a7a0082013-02-21 10:27:48 +0000171 EXPECT_EQ(0, acm_b_->Codec(n, &my_codec_param));
kwibergda2bf4e2016-10-24 13:47:09 -0700172 EXPECT_EQ(true, acm_b_->RegisterReceiveCodec(
173 my_codec_param.pltype, CodecInstToSdp(my_codec_param)));
tina.legrand@webrtc.org45175852012-06-01 09:27:35 +0000174 }
175
176 // Test that unregister all receive codecs works.
pbos@webrtc.org0946a562013-04-09 00:28:06 +0000177 for (uint8_t n = 0; n < num_encoders; n++) {
tina.legrand@webrtc.org7a7a0082013-02-21 10:27:48 +0000178 EXPECT_EQ(0, acm_b_->Codec(n, &my_codec_param));
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000179 EXPECT_EQ(0, acm_b_->UnregisterReceiveCodec(my_codec_param.pltype));
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000180 }
tina.legrand@webrtc.orgae1c4542012-03-12 08:41:30 +0000181
tina.legrand@webrtc.org45175852012-06-01 09:27:35 +0000182 // Register all available codes as receiving codecs once more.
pbos@webrtc.org0946a562013-04-09 00:28:06 +0000183 for (uint8_t n = 0; n < num_encoders; n++) {
tina.legrand@webrtc.org7a7a0082013-02-21 10:27:48 +0000184 EXPECT_EQ(0, acm_b_->Codec(n, &my_codec_param));
kwibergda2bf4e2016-10-24 13:47:09 -0700185 EXPECT_EQ(true, acm_b_->RegisterReceiveCodec(
186 my_codec_param.pltype, CodecInstToSdp(my_codec_param)));
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000187 }
tina.legrand@webrtc.orgae1c4542012-03-12 08:41:30 +0000188
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000189 // Create and connect the channel.
190 channel_a2b_ = new TestPackStereo;
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000191 EXPECT_EQ(0, acm_a_->RegisterTransportCallback(channel_a2b_));
andrew@webrtc.org89df0922013-09-12 01:27:43 +0000192 channel_a2b_->RegisterReceiverACM(acm_b_.get());
tina.legrand@webrtc.orgdf697752012-02-08 10:22:21 +0000193
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000194 // Start with setting VAD/DTX, before we know we will send stereo.
195 // Continue with setting a stereo codec as send codec and verify that
196 // VAD/DTX gets turned off.
197 EXPECT_EQ(0, acm_a_->SetVAD(true, true, VADNormal));
tina.legrand@webrtc.org7a7a0082013-02-21 10:27:48 +0000198 EXPECT_EQ(0, acm_a_->VAD(&dtx, &vad, &vad_mode));
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000199 EXPECT_TRUE(dtx);
200 EXPECT_TRUE(vad);
201 char codec_pcma_temp[] = "PCMA";
202 RegisterSendCodec('A', codec_pcma_temp, 8000, 64000, 80, 2, pcma_pltype_);
tina.legrand@webrtc.org7a7a0082013-02-21 10:27:48 +0000203 EXPECT_EQ(0, acm_a_->VAD(&dtx, &vad, &vad_mode));
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000204 EXPECT_FALSE(dtx);
205 EXPECT_FALSE(vad);
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000206 if (test_mode_ != 0) {
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000207 printf("\n");
208 }
209
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000210 //
211 // Test Stereo-To-Stereo for all codecs.
212 //
213 audio_channels = 2;
214 codec_channels = 2;
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000215
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000216 // All codecs are tested for all allowed sampling frequencies, rates and
217 // packet sizes.
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000218 if (test_mode_ != 0) {
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000219 printf("===========================================================\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000220 printf("Test number: %d\n", test_cntr_ + 1);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000221 printf("Test type: Stereo-to-stereo\n");
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000222 }
223 channel_a2b_->set_codec_mode(kStereo);
224 test_cntr_++;
225 OpenOutFile(test_cntr_);
226 char codec_g722[] = "G722";
227 RegisterSendCodec('A', codec_g722, 16000, 64000, 160, codec_channels,
228 g722_pltype_);
229 Run(channel_a2b_, audio_channels, codec_channels);
230 RegisterSendCodec('A', codec_g722, 16000, 64000, 320, codec_channels,
231 g722_pltype_);
232 Run(channel_a2b_, audio_channels, codec_channels);
233 RegisterSendCodec('A', codec_g722, 16000, 64000, 480, codec_channels,
234 g722_pltype_);
235 Run(channel_a2b_, audio_channels, codec_channels);
236 RegisterSendCodec('A', codec_g722, 16000, 64000, 640, codec_channels,
237 g722_pltype_);
238 Run(channel_a2b_, audio_channels, codec_channels);
239 RegisterSendCodec('A', codec_g722, 16000, 64000, 800, codec_channels,
240 g722_pltype_);
241 Run(channel_a2b_, audio_channels, codec_channels);
242 RegisterSendCodec('A', codec_g722, 16000, 64000, 960, codec_channels,
243 g722_pltype_);
244 Run(channel_a2b_, audio_channels, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000245 out_file_.Close();
Karl Wibergeb254b42017-11-01 15:08:12 +0100246
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000247 if (test_mode_ != 0) {
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000248 printf("===========================================================\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000249 printf("Test number: %d\n", test_cntr_ + 1);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000250 printf("Test type: Stereo-to-stereo\n");
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000251 }
252 channel_a2b_->set_codec_mode(kStereo);
253 test_cntr_++;
254 OpenOutFile(test_cntr_);
255 char codec_l16[] = "L16";
256 RegisterSendCodec('A', codec_l16, 8000, 128000, 80, codec_channels,
257 l16_8khz_pltype_);
258 Run(channel_a2b_, audio_channels, codec_channels);
259 RegisterSendCodec('A', codec_l16, 8000, 128000, 160, codec_channels,
260 l16_8khz_pltype_);
261 Run(channel_a2b_, audio_channels, codec_channels);
262 RegisterSendCodec('A', codec_l16, 8000, 128000, 240, codec_channels,
263 l16_8khz_pltype_);
264 Run(channel_a2b_, audio_channels, codec_channels);
265 RegisterSendCodec('A', codec_l16, 8000, 128000, 320, codec_channels,
266 l16_8khz_pltype_);
267 Run(channel_a2b_, audio_channels, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000268 out_file_.Close();
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000269
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000270 if (test_mode_ != 0) {
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000271 printf("===========================================================\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000272 printf("Test number: %d\n", test_cntr_ + 1);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000273 printf("Test type: Stereo-to-stereo\n");
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000274 }
275 test_cntr_++;
276 OpenOutFile(test_cntr_);
277 RegisterSendCodec('A', codec_l16, 16000, 256000, 160, codec_channels,
278 l16_16khz_pltype_);
279 Run(channel_a2b_, audio_channels, codec_channels);
280 RegisterSendCodec('A', codec_l16, 16000, 256000, 320, codec_channels,
281 l16_16khz_pltype_);
282 Run(channel_a2b_, audio_channels, codec_channels);
283 RegisterSendCodec('A', codec_l16, 16000, 256000, 480, codec_channels,
284 l16_16khz_pltype_);
285 Run(channel_a2b_, audio_channels, codec_channels);
286 RegisterSendCodec('A', codec_l16, 16000, 256000, 640, codec_channels,
287 l16_16khz_pltype_);
288 Run(channel_a2b_, audio_channels, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000289 out_file_.Close();
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000290
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000291 if (test_mode_ != 0) {
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000292 printf("===========================================================\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000293 printf("Test number: %d\n", test_cntr_ + 1);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000294 printf("Test type: Stereo-to-stereo\n");
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000295 }
296 test_cntr_++;
297 OpenOutFile(test_cntr_);
298 RegisterSendCodec('A', codec_l16, 32000, 512000, 320, codec_channels,
299 l16_32khz_pltype_);
300 Run(channel_a2b_, audio_channels, codec_channels);
301 RegisterSendCodec('A', codec_l16, 32000, 512000, 640, codec_channels,
302 l16_32khz_pltype_);
303 Run(channel_a2b_, audio_channels, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000304 out_file_.Close();
niklase@google.com470e71d2011-07-07 08:21:25 +0000305#ifdef PCMA_AND_PCMU
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000306 if (test_mode_ != 0) {
307 printf("===========================================================\n");
308 printf("Test number: %d\n", test_cntr_ + 1);
309 printf("Test type: Stereo-to-stereo\n");
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000310 }
311 channel_a2b_->set_codec_mode(kStereo);
312 audio_channels = 2;
313 codec_channels = 2;
314 test_cntr_++;
315 OpenOutFile(test_cntr_);
316 char codec_pcma[] = "PCMA";
317 RegisterSendCodec('A', codec_pcma, 8000, 64000, 80, codec_channels,
318 pcma_pltype_);
319 Run(channel_a2b_, audio_channels, codec_channels);
320 RegisterSendCodec('A', codec_pcma, 8000, 64000, 160, codec_channels,
321 pcma_pltype_);
322 Run(channel_a2b_, audio_channels, codec_channels);
323 RegisterSendCodec('A', codec_pcma, 8000, 64000, 240, codec_channels,
324 pcma_pltype_);
325 Run(channel_a2b_, audio_channels, codec_channels);
326 RegisterSendCodec('A', codec_pcma, 8000, 64000, 320, codec_channels,
327 pcma_pltype_);
328 Run(channel_a2b_, audio_channels, codec_channels);
329 RegisterSendCodec('A', codec_pcma, 8000, 64000, 400, codec_channels,
330 pcma_pltype_);
331 Run(channel_a2b_, audio_channels, codec_channels);
332 RegisterSendCodec('A', codec_pcma, 8000, 64000, 480, codec_channels,
333 pcma_pltype_);
334 Run(channel_a2b_, audio_channels, codec_channels);
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000335
336 // Test that VAD/DTX cannot be turned on while sending stereo.
337 EXPECT_EQ(-1, acm_a_->SetVAD(true, true, VADNormal));
tina.legrand@webrtc.org7a7a0082013-02-21 10:27:48 +0000338 EXPECT_EQ(0, acm_a_->VAD(&dtx, &vad, &vad_mode));
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000339 EXPECT_FALSE(dtx);
340 EXPECT_FALSE(vad);
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000341 EXPECT_EQ(0, acm_a_->SetVAD(false, false, VADNormal));
tina.legrand@webrtc.org7a7a0082013-02-21 10:27:48 +0000342 EXPECT_EQ(0, acm_a_->VAD(&dtx, &vad, &vad_mode));
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000343 EXPECT_FALSE(dtx);
344 EXPECT_FALSE(vad);
345
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000346 out_file_.Close();
347 if (test_mode_ != 0) {
348 printf("===========================================================\n");
349 printf("Test number: %d\n", test_cntr_ + 1);
350 printf("Test type: Stereo-to-stereo\n");
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000351 }
352 test_cntr_++;
353 OpenOutFile(test_cntr_);
354 char codec_pcmu[] = "PCMU";
355 RegisterSendCodec('A', codec_pcmu, 8000, 64000, 80, codec_channels,
356 pcmu_pltype_);
357 Run(channel_a2b_, audio_channels, codec_channels);
358 RegisterSendCodec('A', codec_pcmu, 8000, 64000, 160, codec_channels,
359 pcmu_pltype_);
360 Run(channel_a2b_, audio_channels, codec_channels);
361 RegisterSendCodec('A', codec_pcmu, 8000, 64000, 240, codec_channels,
362 pcmu_pltype_);
363 Run(channel_a2b_, audio_channels, codec_channels);
364 RegisterSendCodec('A', codec_pcmu, 8000, 64000, 320, codec_channels,
365 pcmu_pltype_);
366 Run(channel_a2b_, audio_channels, codec_channels);
367 RegisterSendCodec('A', codec_pcmu, 8000, 64000, 400, codec_channels,
368 pcmu_pltype_);
369 Run(channel_a2b_, audio_channels, codec_channels);
370 RegisterSendCodec('A', codec_pcmu, 8000, 64000, 480, codec_channels,
371 pcmu_pltype_);
372 Run(channel_a2b_, audio_channels, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000373 out_file_.Close();
niklase@google.com470e71d2011-07-07 08:21:25 +0000374#endif
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000375#ifdef WEBRTC_CODEC_OPUS
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000376 if (test_mode_ != 0) {
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000377 printf("===========================================================\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000378 printf("Test number: %d\n", test_cntr_ + 1);
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000379 printf("Test type: Stereo-to-stereo\n");
380 }
381 channel_a2b_->set_codec_mode(kStereo);
382 audio_channels = 2;
383 codec_channels = 2;
384 test_cntr_++;
385 OpenOutFile(test_cntr_);
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000386
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000387 char codec_opus[] = "opus";
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000388 // Run Opus with 10 ms frame size.
389 RegisterSendCodec('A', codec_opus, 48000, 64000, 480, codec_channels,
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000390 opus_pltype_);
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000391 Run(channel_a2b_, audio_channels, codec_channels);
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000392 // Run Opus with 20 ms frame size.
393 RegisterSendCodec('A', codec_opus, 48000, 64000, 480*2, codec_channels,
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000394 opus_pltype_);
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000395 Run(channel_a2b_, audio_channels, codec_channels);
396 // Run Opus with 40 ms frame size.
397 RegisterSendCodec('A', codec_opus, 48000, 64000, 480*4, codec_channels,
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000398 opus_pltype_);
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000399 Run(channel_a2b_, audio_channels, codec_channels);
400 // Run Opus with 60 ms frame size.
401 RegisterSendCodec('A', codec_opus, 48000, 64000, 480*6, codec_channels,
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000402 opus_pltype_);
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000403 Run(channel_a2b_, audio_channels, codec_channels);
404 // Run Opus with 20 ms frame size and different bitrates.
405 RegisterSendCodec('A', codec_opus, 48000, 40000, 960, codec_channels,
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000406 opus_pltype_);
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000407 Run(channel_a2b_, audio_channels, codec_channels);
408 RegisterSendCodec('A', codec_opus, 48000, 510000, 960, codec_channels,
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000409 opus_pltype_);
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000410 Run(channel_a2b_, audio_channels, codec_channels);
411 out_file_.Close();
412#endif
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000413 //
414 // Test Mono-To-Stereo for all codecs.
415 //
416 audio_channels = 1;
417 codec_channels = 2;
niklase@google.com470e71d2011-07-07 08:21:25 +0000418
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000419 if (test_mode_ != 0) {
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000420 printf("===============================================================\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000421 printf("Test number: %d\n", test_cntr_ + 1);
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000422 printf("Test type: Mono-to-stereo\n");
423 }
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000424 test_cntr_++;
425 channel_a2b_->set_codec_mode(kStereo);
426 OpenOutFile(test_cntr_);
427 RegisterSendCodec('A', codec_g722, 16000, 64000, 160, codec_channels,
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000428 g722_pltype_);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000429 Run(channel_a2b_, audio_channels, codec_channels);
430 out_file_.Close();
Karl Wibergeb254b42017-11-01 15:08:12 +0100431
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000432 if (test_mode_ != 0) {
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000433 printf("===============================================================\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000434 printf("Test number: %d\n", test_cntr_ + 1);
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000435 printf("Test type: Mono-to-stereo\n");
436 }
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000437 test_cntr_++;
438 channel_a2b_->set_codec_mode(kStereo);
439 OpenOutFile(test_cntr_);
440 RegisterSendCodec('A', codec_l16, 8000, 128000, 80, codec_channels,
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000441 l16_8khz_pltype_);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000442 Run(channel_a2b_, audio_channels, codec_channels);
443 out_file_.Close();
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000444 if (test_mode_ != 0) {
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000445 printf("===============================================================\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000446 printf("Test number: %d\n", test_cntr_ + 1);
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000447 printf("Test type: Mono-to-stereo\n");
448 }
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000449 test_cntr_++;
450 OpenOutFile(test_cntr_);
451 RegisterSendCodec('A', codec_l16, 16000, 256000, 160, codec_channels,
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000452 l16_16khz_pltype_);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000453 Run(channel_a2b_, audio_channels, codec_channels);
454 out_file_.Close();
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000455 if (test_mode_ != 0) {
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000456 printf("===============================================================\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000457 printf("Test number: %d\n", test_cntr_ + 1);
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000458 printf("Test type: Mono-to-stereo\n");
459 }
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000460 test_cntr_++;
461 OpenOutFile(test_cntr_);
462 RegisterSendCodec('A', codec_l16, 32000, 512000, 320, codec_channels,
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000463 l16_32khz_pltype_);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000464 Run(channel_a2b_, audio_channels, codec_channels);
465 out_file_.Close();
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000466#ifdef PCMA_AND_PCMU
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000467 if (test_mode_ != 0) {
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000468 printf("===============================================================\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000469 printf("Test number: %d\n", test_cntr_ + 1);
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000470 printf("Test type: Mono-to-stereo\n");
471 }
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000472 test_cntr_++;
473 channel_a2b_->set_codec_mode(kStereo);
474 OpenOutFile(test_cntr_);
475 RegisterSendCodec('A', codec_pcmu, 8000, 64000, 80, codec_channels,
tina.legrand@webrtc.orgae1c4542012-03-12 08:41:30 +0000476 pcmu_pltype_);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000477 Run(channel_a2b_, audio_channels, codec_channels);
478 RegisterSendCodec('A', codec_pcma, 8000, 64000, 80, codec_channels,
tina.legrand@webrtc.orgae1c4542012-03-12 08:41:30 +0000479 pcma_pltype_);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000480 Run(channel_a2b_, audio_channels, codec_channels);
481 out_file_.Close();
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000482#endif
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000483#ifdef WEBRTC_CODEC_OPUS
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000484 if (test_mode_ != 0) {
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000485 printf("===============================================================\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000486 printf("Test number: %d\n", test_cntr_ + 1);
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000487 printf("Test type: Mono-to-stereo\n");
488 }
tina.legrand@webrtc.orgc4590582012-11-28 12:23:29 +0000489
490 // Keep encode and decode in stereo.
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000491 test_cntr_++;
492 channel_a2b_->set_codec_mode(kStereo);
493 OpenOutFile(test_cntr_);
494 RegisterSendCodec('A', codec_opus, 48000, 64000, 960, codec_channels,
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000495 opus_pltype_);
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000496 Run(channel_a2b_, audio_channels, codec_channels);
tina.legrand@webrtc.orgc4590582012-11-28 12:23:29 +0000497
498 // Encode in mono, decode in stereo mode.
499 RegisterSendCodec('A', codec_opus, 48000, 64000, 960, 1, opus_pltype_);
500 Run(channel_a2b_, audio_channels, codec_channels);
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000501 out_file_.Close();
502#endif
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000503
504 //
505 // Test Stereo-To-Mono for all codecs.
506 //
507 audio_channels = 2;
508 codec_channels = 1;
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000509 channel_a2b_->set_codec_mode(kMono);
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000510
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000511 // Run stereo audio and mono codec.
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000512 if (test_mode_ != 0) {
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000513 printf("===============================================================\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000514 printf("Test number: %d\n", test_cntr_ + 1);
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000515 printf("Test type: Stereo-to-mono\n");
516 }
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000517 test_cntr_++;
518 OpenOutFile(test_cntr_);
519 RegisterSendCodec('A', codec_g722, 16000, 64000, 160, codec_channels,
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000520 g722_pltype_);
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000521
522 // Make sure it is possible to set VAD/CNG, now that we are sending mono
523 // again.
524 EXPECT_EQ(0, acm_a_->SetVAD(true, true, VADNormal));
tina.legrand@webrtc.org7a7a0082013-02-21 10:27:48 +0000525 EXPECT_EQ(0, acm_a_->VAD(&dtx, &vad, &vad_mode));
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000526 EXPECT_TRUE(dtx);
527 EXPECT_TRUE(vad);
528 EXPECT_EQ(0, acm_a_->SetVAD(false, false, VADNormal));
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000529 Run(channel_a2b_, audio_channels, codec_channels);
530 out_file_.Close();
Karl Wibergeb254b42017-11-01 15:08:12 +0100531
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000532 if (test_mode_ != 0) {
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000533 printf("===============================================================\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000534 printf("Test number: %d\n", test_cntr_ + 1);
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000535 printf("Test type: Stereo-to-mono\n");
536 }
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000537 test_cntr_++;
538 OpenOutFile(test_cntr_);
539 RegisterSendCodec('A', codec_l16, 8000, 128000, 80, codec_channels,
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000540 l16_8khz_pltype_);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000541 Run(channel_a2b_, audio_channels, codec_channels);
542 out_file_.Close();
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000543 if (test_mode_ != 0) {
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000544 printf("===============================================================\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000545 printf("Test number: %d\n", test_cntr_ + 1);
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000546 printf("Test type: Stereo-to-mono\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000547 }
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000548 test_cntr_++;
549 OpenOutFile(test_cntr_);
550 RegisterSendCodec('A', codec_l16, 16000, 256000, 160, codec_channels,
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000551 l16_16khz_pltype_);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000552 Run(channel_a2b_, audio_channels, codec_channels);
553 out_file_.Close();
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000554 if (test_mode_ != 0) {
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000555 printf("==============================================================\n");
556 printf("Test number: %d\n", test_cntr_ + 1);
557 printf("Test type: Stereo-to-mono\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000558 }
559 test_cntr_++;
560 OpenOutFile(test_cntr_);
561 RegisterSendCodec('A', codec_l16, 32000, 512000, 320, codec_channels,
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000562 l16_32khz_pltype_);
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000563 Run(channel_a2b_, audio_channels, codec_channels);
564 out_file_.Close();
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000565#ifdef PCMA_AND_PCMU
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000566 if (test_mode_ != 0) {
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000567 printf("===============================================================\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000568 printf("Test number: %d\n", test_cntr_ + 1);
tina.legrand@webrtc.orgdf697752012-02-08 10:22:21 +0000569 printf("Test type: Stereo-to-mono\n");
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000570 }
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000571 test_cntr_++;
572 OpenOutFile(test_cntr_);
573 RegisterSendCodec('A', codec_pcmu, 8000, 64000, 80, codec_channels,
tina.legrand@webrtc.orgae1c4542012-03-12 08:41:30 +0000574 pcmu_pltype_);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000575 Run(channel_a2b_, audio_channels, codec_channels);
576 RegisterSendCodec('A', codec_pcma, 8000, 64000, 80, codec_channels,
tina.legrand@webrtc.orgae1c4542012-03-12 08:41:30 +0000577 pcma_pltype_);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000578 Run(channel_a2b_, audio_channels, codec_channels);
579 out_file_.Close();
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000580#endif
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000581#ifdef WEBRTC_CODEC_OPUS
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000582 if (test_mode_ != 0) {
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000583 printf("===============================================================\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000584 printf("Test number: %d\n", test_cntr_ + 1);
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000585 printf("Test type: Stereo-to-mono\n");
586 }
587 test_cntr_++;
588 OpenOutFile(test_cntr_);
tina.legrand@webrtc.orgc4590582012-11-28 12:23:29 +0000589 // Encode and decode in mono.
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000590 RegisterSendCodec('A', codec_opus, 48000, 32000, 960, codec_channels,
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000591 opus_pltype_);
tina.legrand@webrtc.orgc4590582012-11-28 12:23:29 +0000592 CodecInst opus_codec_param;
pbos@webrtc.org0946a562013-04-09 00:28:06 +0000593 for (uint8_t n = 0; n < num_encoders; n++) {
tina.legrand@webrtc.org7a7a0082013-02-21 10:27:48 +0000594 EXPECT_EQ(0, acm_b_->Codec(n, &opus_codec_param));
tina.legrand@webrtc.orgc4590582012-11-28 12:23:29 +0000595 if (!strcmp(opus_codec_param.plname, "opus")) {
596 opus_codec_param.channels = 1;
kwibergda2bf4e2016-10-24 13:47:09 -0700597 EXPECT_EQ(true,
598 acm_b_->RegisterReceiveCodec(opus_codec_param.pltype,
599 CodecInstToSdp(opus_codec_param)));
tina.legrand@webrtc.orgc4590582012-11-28 12:23:29 +0000600 break;
601 }
602 }
603 Run(channel_a2b_, audio_channels, codec_channels);
604
605 // Encode in stereo, decode in mono.
606 RegisterSendCodec('A', codec_opus, 48000, 32000, 960, 2, opus_pltype_);
607 Run(channel_a2b_, audio_channels, codec_channels);
608
609 out_file_.Close();
610
611 // Test switching between decoding mono and stereo for Opus.
612
613 // Decode in mono.
614 test_cntr_++;
615 OpenOutFile(test_cntr_);
616 if (test_mode_ != 0) {
617 // Print out codec and settings
618 printf("Test number: %d\nCodec: Opus Freq: 48000 Rate :32000 PackSize: 960"
619 " Decode: mono\n", test_cntr_);
620 }
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000621 Run(channel_a2b_, audio_channels, codec_channels);
622 out_file_.Close();
tina.legrand@webrtc.orgc4590582012-11-28 12:23:29 +0000623 // Decode in stereo.
624 test_cntr_++;
625 OpenOutFile(test_cntr_);
626 if (test_mode_ != 0) {
627 // Print out codec and settings
628 printf("Test number: %d\nCodec: Opus Freq: 48000 Rate :32000 PackSize: 960"
629 " Decode: stereo\n", test_cntr_);
630 }
631 opus_codec_param.channels = 2;
kwibergda2bf4e2016-10-24 13:47:09 -0700632 EXPECT_EQ(true,
633 acm_b_->RegisterReceiveCodec(opus_codec_param.pltype,
634 CodecInstToSdp(opus_codec_param)));
tina.legrand@webrtc.orgc4590582012-11-28 12:23:29 +0000635 Run(channel_a2b_, audio_channels, 2);
636 out_file_.Close();
637 // Decode in mono.
638 test_cntr_++;
639 OpenOutFile(test_cntr_);
640 if (test_mode_ != 0) {
641 // Print out codec and settings
642 printf("Test number: %d\nCodec: Opus Freq: 48000 Rate :32000 PackSize: 960"
643 " Decode: mono\n", test_cntr_);
644 }
645 opus_codec_param.channels = 1;
kwibergda2bf4e2016-10-24 13:47:09 -0700646 EXPECT_EQ(true,
647 acm_b_->RegisterReceiveCodec(opus_codec_param.pltype,
648 CodecInstToSdp(opus_codec_param)));
tina.legrand@webrtc.orgc4590582012-11-28 12:23:29 +0000649 Run(channel_a2b_, audio_channels, codec_channels);
650 out_file_.Close();
651
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000652#endif
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000653
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000654 // Print out which codecs were tested, and which were not, in the run.
655 if (test_mode_ != 0) {
656 printf("\nThe following codecs was INCLUDED in the test:\n");
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000657 printf(" G.722\n");
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000658 printf(" PCM16\n");
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000659 printf(" G.711\n");
tina.legrand@webrtc.orgc4590582012-11-28 12:23:29 +0000660#ifdef WEBRTC_CODEC_OPUS
661 printf(" Opus\n");
662#endif
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000663 printf("\nTo complete the test, listen to the %d number of output "
664 "files.\n",
665 test_cntr_);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000666 }
667
668 // Delete the file pointers.
669 delete in_file_stereo_;
670 delete in_file_mono_;
niklase@google.com470e71d2011-07-07 08:21:25 +0000671}
672
673// Register Codec to use in the test
674//
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000675// Input: side - which ACM to use, 'A' or 'B'
676// codec_name - name to use when register the codec
677// sampling_freq_hz - sampling frequency in Herz
678// rate - bitrate in bytes
679// pack_size - packet size in samples
680// channels - number of channels; 1 for mono, 2 for stereo
681// payload_type - payload type for the codec
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000682void TestStereo::RegisterSendCodec(char side, char* codec_name,
pbos@webrtc.org0946a562013-04-09 00:28:06 +0000683 int32_t sampling_freq_hz, int rate,
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000684 int pack_size, int channels,
685 int payload_type) {
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000686 if (test_mode_ != 0) {
687 // Print out codec and settings
tina.legrand@webrtc.orgba468042012-08-17 10:38:28 +0000688 printf("Codec: %s Freq: %d Rate: %d PackSize: %d\n", codec_name,
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000689 sampling_freq_hz, rate, pack_size);
690 }
691
692 // Store packet size in samples, used to validate the received packet
693 pack_size_samp_ = pack_size;
694
695 // Store the expected packet size in bytes, used to validate the received
696 // packet. Add 0.875 to always round up to a whole byte.
pbos@webrtc.orgd8ca7232014-12-10 11:49:13 +0000697 pack_size_bytes_ = (uint16_t)(static_cast<float>(pack_size * rate) /
698 static_cast<float>(sampling_freq_hz * 8) +
699 0.875);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000700
701 // Set pointer to the ACM where to register the codec
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000702 AudioCodingModule* my_acm = NULL;
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000703 switch (side) {
704 case 'A': {
andrew@webrtc.org89df0922013-09-12 01:27:43 +0000705 my_acm = acm_a_.get();
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000706 break;
niklase@google.com470e71d2011-07-07 08:21:25 +0000707 }
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000708 case 'B': {
andrew@webrtc.org89df0922013-09-12 01:27:43 +0000709 my_acm = acm_b_.get();
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000710 break;
tina.legrand@webrtc.org16b6b902012-04-12 11:02:38 +0000711 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000712 default:
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000713 break;
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000714 }
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000715 ASSERT_TRUE(my_acm != NULL);
niklase@google.com470e71d2011-07-07 08:21:25 +0000716
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000717 CodecInst my_codec_param;
718 // Get all codec parameters before registering
tina.legrand@webrtc.orgee92b662013-08-27 07:33:51 +0000719 EXPECT_GT(AudioCodingModule::Codec(codec_name, &my_codec_param,
720 sampling_freq_hz, channels), -1);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000721 my_codec_param.rate = rate;
722 my_codec_param.pacsize = pack_size;
tina.legrand@webrtc.orgee92b662013-08-27 07:33:51 +0000723 EXPECT_EQ(0, my_acm->RegisterSendCodec(my_codec_param));
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000724
725 send_codec_name_ = codec_name;
niklase@google.com470e71d2011-07-07 08:21:25 +0000726}
727
tina.legrand@webrtc.org16b6b902012-04-12 11:02:38 +0000728void TestStereo::Run(TestPackStereo* channel, int in_channels, int out_channels,
729 int percent_loss) {
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000730 AudioFrame audio_frame;
niklase@google.com470e71d2011-07-07 08:21:25 +0000731
pbos@webrtc.org0946a562013-04-09 00:28:06 +0000732 int32_t out_freq_hz_b = out_file_.SamplingFrequency();
733 uint16_t rec_size;
734 uint32_t time_stamp_diff;
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000735 channel->reset_payload_size();
736 int error_count = 0;
tina.legrand@webrtc.org65d61c32014-06-05 13:42:51 +0000737 int variable_bytes = 0;
738 int variable_packets = 0;
Henrik Lundin4d682082015-12-10 16:24:39 +0100739 // Set test length to 500 ms (50 blocks of 10 ms each).
740 in_file_mono_->SetNum10MsBlocksToRead(50);
741 in_file_stereo_->SetNum10MsBlocksToRead(50);
742 // Fast-forward 1 second (100 blocks) since the files start with silence.
743 in_file_stereo_->FastForward(100);
744 in_file_mono_->FastForward(100);
niklase@google.com470e71d2011-07-07 08:21:25 +0000745
andresp@webrtc.orgd0b436a2014-01-13 13:15:59 +0000746 while (1) {
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000747 // Simulate packet loss by setting |packet_loss_| to "true" in
748 // |percent_loss| percent of the loops.
749 if (percent_loss > 0) {
750 if (counter_ == floor((100 / percent_loss) + 0.5)) {
751 counter_ = 0;
752 channel->set_lost_packet(true);
753 } else {
754 channel->set_lost_packet(false);
755 }
756 counter_++;
niklase@google.com470e71d2011-07-07 08:21:25 +0000757 }
758
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000759 // Add 10 msec to ACM
760 if (in_channels == 1) {
761 if (in_file_mono_->EndOfFile()) {
762 break;
763 }
764 in_file_mono_->Read10MsData(audio_frame);
765 } else {
766 if (in_file_stereo_->EndOfFile()) {
767 break;
768 }
769 in_file_stereo_->Read10MsData(audio_frame);
770 }
henrik.lundin@webrtc.orgf56c1622015-03-02 12:29:30 +0000771 EXPECT_GE(acm_a_->Add10MsData(audio_frame), 0);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000772
tina.legrand@webrtc.org65d61c32014-06-05 13:42:51 +0000773 // Verify that the received packet size matches the settings.
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000774 rec_size = channel->payload_size();
775 if ((0 < rec_size) & (rec_size < 65535)) {
tina.legrand@webrtc.org65d61c32014-06-05 13:42:51 +0000776 if (strcmp(send_codec_name_, "opus") == 0) {
777 // Opus is a variable rate codec, hence calculate the average packet
778 // size, and later make sure the average is in the right range.
779 variable_bytes += rec_size;
780 variable_packets++;
781 } else {
782 // For fixed rate codecs, check that packet size is correct.
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000783 if ((rec_size != pack_size_bytes_ * out_channels)
784 && (pack_size_bytes_ < 65535)) {
785 error_count++;
786 }
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000787 }
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000788 // Verify that the timestamp is updated with expected length
789 time_stamp_diff = channel->timestamp_diff();
790 if ((counter_ > 10) && (time_stamp_diff != pack_size_samp_)) {
791 error_count++;
792 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000793 }
794
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000795 // Run received side of ACM
henrik.lundind4ccb002016-05-17 12:21:55 -0700796 bool muted;
797 EXPECT_EQ(0, acm_b_->PlayoutData10Ms(out_freq_hz_b, &audio_frame, &muted));
798 ASSERT_FALSE(muted);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000799
800 // Write output speech to file
801 out_file_.Write10MsData(
yujo36b1a5f2017-06-12 12:45:32 -0700802 audio_frame.data(),
andrew@webrtc.org63a50982012-05-02 23:56:37 +0000803 audio_frame.samples_per_channel_ * audio_frame.num_channels_);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000804 }
805
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000806 EXPECT_EQ(0, error_count);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000807
tina.legrand@webrtc.org65d61c32014-06-05 13:42:51 +0000808 // Check that packet size is in the right range for variable rate codecs,
809 // such as Opus.
810 if (variable_packets > 0) {
811 variable_bytes /= variable_packets;
Henrik Lundin4d682082015-12-10 16:24:39 +0100812 EXPECT_NEAR(variable_bytes, pack_size_bytes_, 18);
tina.legrand@webrtc.org65d61c32014-06-05 13:42:51 +0000813 }
814
andresp@webrtc.orgd0b436a2014-01-13 13:15:59 +0000815 if (in_file_mono_->EndOfFile()) {
816 in_file_mono_->Rewind();
817 }
818 if (in_file_stereo_->EndOfFile()) {
819 in_file_stereo_->Rewind();
820 }
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000821 // Reset in case we ended with a lost packet
822 channel->set_lost_packet(false);
niklase@google.com470e71d2011-07-07 08:21:25 +0000823}
824
pbos@webrtc.org0946a562013-04-09 00:28:06 +0000825void TestStereo::OpenOutFile(int16_t test_number) {
tina.legrand@webrtc.orgba468042012-08-17 10:38:28 +0000826 std::string file_name;
827 std::stringstream file_stream;
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000828 file_stream << webrtc::test::OutputPath() << "teststereo_out_" << test_number
829 << ".pcm";
tina.legrand@webrtc.orgba468042012-08-17 10:38:28 +0000830 file_name = file_stream.str();
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000831 out_file_.Open(file_name, 32000, "wb");
niklase@google.com470e71d2011-07-07 08:21:25 +0000832}
833
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000834void TestStereo::DisplaySendReceiveCodec() {
kwiberg1fd4a4a2015-11-03 11:20:50 -0800835 auto send_codec = acm_a_->SendCodec();
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000836 if (test_mode_ != 0) {
kwiberg1fd4a4a2015-11-03 11:20:50 -0800837 ASSERT_TRUE(send_codec);
838 printf("%s -> ", send_codec->plname);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000839 }
kwiberg1fd4a4a2015-11-03 11:20:50 -0800840 CodecInst receive_codec;
841 acm_b_->ReceiveCodec(&receive_codec);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000842 if (test_mode_ != 0) {
kwiberg1fd4a4a2015-11-03 11:20:50 -0800843 printf("%s\n", receive_codec.plname);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000844 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000845}
846
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000847} // namespace webrtc