blob: 57b7a54c8772c771364b7116d128cc2c64a3562b [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
kjellander3e6db232015-11-26 04:44:54 -080011#include "webrtc/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
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +000017#include "webrtc/common_types.h"
kwibergda2bf4e2016-10-24 13:47:09 -070018#include "webrtc/modules/audio_coding/codecs/audio_format_conversion.h"
kjellander3e6db232015-11-26 04:44:54 -080019#include "webrtc/modules/audio_coding/include/audio_coding_module_typedefs.h"
20#include "webrtc/modules/audio_coding/test/utility.h"
Henrik Kjellander98f53512015-10-28 18:17:40 +010021#include "webrtc/system_wrappers/include/trace.h"
kwibergac9f8762016-09-30 22:29:43 -070022#include "webrtc/test/gtest.h"
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +000023#include "webrtc/test/testsupport/fileutils.h"
mflodman7056be92016-10-07 07:07:28 +020024#include "webrtc/voice_engine_configurations.h"
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),
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000037 lost_packet_(false) {
38}
niklase@google.com470e71d2011-07-07 08:21:25 +000039
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000040TestPackStereo::~TestPackStereo() {
41}
niklase@google.com470e71d2011-07-07 08:21:25 +000042
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +000043void TestPackStereo::RegisterReceiverACM(AudioCodingModule* acm) {
44 receiver_acm_ = acm;
45 return;
46}
niklase@google.com470e71d2011-07-07 08:21:25 +000047
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000048int32_t TestPackStereo::SendData(const FrameType frame_type,
49 const uint8_t payload_type,
50 const uint32_t timestamp,
51 const uint8_t* payload_data,
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +000052 const size_t payload_size,
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000053 const RTPFragmentationHeader* fragmentation) {
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +000054 WebRtcRTPHeader rtp_info;
pbos@webrtc.org0946a562013-04-09 00:28:06 +000055 int32_t status = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +000056
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +000057 rtp_info.header.markerBit = false;
58 rtp_info.header.ssrc = 0;
59 rtp_info.header.sequenceNumber = seq_no_++;
60 rtp_info.header.payloadType = payload_type;
61 rtp_info.header.timestamp = timestamp;
pbos22993e12015-10-19 02:39:06 -070062 if (frame_type == kEmptyFrame) {
tina.legrand@webrtc.org16b6b902012-04-12 11:02:38 +000063 // Skip this frame
64 return 0;
65 }
niklase@google.com470e71d2011-07-07 08:21:25 +000066
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +000067 if (lost_packet_ == false) {
68 if (frame_type != kAudioFrameCN) {
69 rtp_info.type.Audio.isCNG = false;
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +000070 rtp_info.type.Audio.channel = static_cast<int>(codec_mode_);
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +000071 } else {
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +000072 rtp_info.type.Audio.isCNG = true;
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +000073 rtp_info.type.Audio.channel = static_cast<int>(kMono);
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +000074 }
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +000075 status = receiver_acm_->IncomingPacket(payload_data, payload_size,
tina.legrand@webrtc.org45175852012-06-01 09:27:35 +000076 rtp_info);
niklase@google.com470e71d2011-07-07 08:21:25 +000077
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +000078 if (frame_type != kAudioFrameCN) {
henrike@webrtc.org6ac22e62014-08-11 21:06:30 +000079 payload_size_ = static_cast<int>(payload_size);
niklase@google.com470e71d2011-07-07 08:21:25 +000080 } else {
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +000081 payload_size_ = -1;
niklase@google.com470e71d2011-07-07 08:21:25 +000082 }
tina.legrand@webrtc.org16b6b902012-04-12 11:02:38 +000083
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +000084 timestamp_diff_ = timestamp - last_in_timestamp_;
85 last_in_timestamp_ = timestamp;
86 total_bytes_ += payload_size;
tina.legrand@webrtc.org16b6b902012-04-12 11:02:38 +000087 }
88 return status;
niklase@google.com470e71d2011-07-07 08:21:25 +000089}
90
pbos@webrtc.org0946a562013-04-09 00:28:06 +000091uint16_t TestPackStereo::payload_size() {
henrike@webrtc.org6ac22e62014-08-11 21:06:30 +000092 return static_cast<uint16_t>(payload_size_);
niklase@google.com470e71d2011-07-07 08:21:25 +000093}
94
pbos@webrtc.org0946a562013-04-09 00:28:06 +000095uint32_t TestPackStereo::timestamp_diff() {
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +000096 return timestamp_diff_;
niklase@google.com470e71d2011-07-07 08:21:25 +000097}
98
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +000099void TestPackStereo::reset_payload_size() {
100 payload_size_ = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000101}
102
tina.legrand@webrtc.org16b6b902012-04-12 11:02:38 +0000103void TestPackStereo::set_codec_mode(enum StereoMonoMode mode) {
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000104 codec_mode_ = mode;
tina.legrand@webrtc.org16b6b902012-04-12 11:02:38 +0000105}
106
107void TestPackStereo::set_lost_packet(bool lost) {
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000108 lost_packet_ = lost;
niklase@google.com470e71d2011-07-07 08:21:25 +0000109}
110
henrik.lundin@webrtc.orgadaf8092014-04-17 08:29:10 +0000111TestStereo::TestStereo(int test_mode)
112 : acm_a_(AudioCodingModule::Create(0)),
113 acm_b_(AudioCodingModule::Create(1)),
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),
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +0000118 counter_(0)
119#ifdef WEBRTC_CODEC_G722
120 , g722_pltype_(0)
121#endif
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +0000122 , l16_8khz_pltype_(-1)
123 , l16_16khz_pltype_(-1)
124 , l16_32khz_pltype_(-1)
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +0000125#ifdef PCMA_AND_PCMU
126 , pcma_pltype_(-1)
127 , pcmu_pltype_(-1)
128#endif
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +0000129#ifdef WEBRTC_CODEC_OPUS
130 , opus_pltype_(-1)
131#endif
132 {
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.
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000153 const std::string file_name_stereo = webrtc::test::ResourcePath(
154 "audio_coding/teststereo32kHz", "pcm");
155 const std::string file_name_mono = webrtc::test::ResourcePath(
156 "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.
niklase@google.com470e71d2011-07-07 08:21:25 +0000221#ifdef WEBRTC_CODEC_G722
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000222 if (test_mode_ != 0) {
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000223 printf("===========================================================\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000224 printf("Test number: %d\n", test_cntr_ + 1);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000225 printf("Test type: Stereo-to-stereo\n");
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000226 }
227 channel_a2b_->set_codec_mode(kStereo);
228 test_cntr_++;
229 OpenOutFile(test_cntr_);
230 char codec_g722[] = "G722";
231 RegisterSendCodec('A', codec_g722, 16000, 64000, 160, codec_channels,
232 g722_pltype_);
233 Run(channel_a2b_, audio_channels, codec_channels);
234 RegisterSendCodec('A', codec_g722, 16000, 64000, 320, codec_channels,
235 g722_pltype_);
236 Run(channel_a2b_, audio_channels, codec_channels);
237 RegisterSendCodec('A', codec_g722, 16000, 64000, 480, codec_channels,
238 g722_pltype_);
239 Run(channel_a2b_, audio_channels, codec_channels);
240 RegisterSendCodec('A', codec_g722, 16000, 64000, 640, codec_channels,
241 g722_pltype_);
242 Run(channel_a2b_, audio_channels, codec_channels);
243 RegisterSendCodec('A', codec_g722, 16000, 64000, 800, codec_channels,
244 g722_pltype_);
245 Run(channel_a2b_, audio_channels, codec_channels);
246 RegisterSendCodec('A', codec_g722, 16000, 64000, 960, codec_channels,
247 g722_pltype_);
248 Run(channel_a2b_, audio_channels, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000249 out_file_.Close();
niklase@google.com470e71d2011-07-07 08:21:25 +0000250#endif
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000251 if (test_mode_ != 0) {
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000252 printf("===========================================================\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000253 printf("Test number: %d\n", test_cntr_ + 1);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000254 printf("Test type: Stereo-to-stereo\n");
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000255 }
256 channel_a2b_->set_codec_mode(kStereo);
257 test_cntr_++;
258 OpenOutFile(test_cntr_);
259 char codec_l16[] = "L16";
260 RegisterSendCodec('A', codec_l16, 8000, 128000, 80, codec_channels,
261 l16_8khz_pltype_);
262 Run(channel_a2b_, audio_channels, codec_channels);
263 RegisterSendCodec('A', codec_l16, 8000, 128000, 160, codec_channels,
264 l16_8khz_pltype_);
265 Run(channel_a2b_, audio_channels, codec_channels);
266 RegisterSendCodec('A', codec_l16, 8000, 128000, 240, codec_channels,
267 l16_8khz_pltype_);
268 Run(channel_a2b_, audio_channels, codec_channels);
269 RegisterSendCodec('A', codec_l16, 8000, 128000, 320, codec_channels,
270 l16_8khz_pltype_);
271 Run(channel_a2b_, audio_channels, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000272 out_file_.Close();
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000273
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000274 if (test_mode_ != 0) {
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000275 printf("===========================================================\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000276 printf("Test number: %d\n", test_cntr_ + 1);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000277 printf("Test type: Stereo-to-stereo\n");
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000278 }
279 test_cntr_++;
280 OpenOutFile(test_cntr_);
281 RegisterSendCodec('A', codec_l16, 16000, 256000, 160, codec_channels,
282 l16_16khz_pltype_);
283 Run(channel_a2b_, audio_channels, codec_channels);
284 RegisterSendCodec('A', codec_l16, 16000, 256000, 320, codec_channels,
285 l16_16khz_pltype_);
286 Run(channel_a2b_, audio_channels, codec_channels);
287 RegisterSendCodec('A', codec_l16, 16000, 256000, 480, codec_channels,
288 l16_16khz_pltype_);
289 Run(channel_a2b_, audio_channels, codec_channels);
290 RegisterSendCodec('A', codec_l16, 16000, 256000, 640, codec_channels,
291 l16_16khz_pltype_);
292 Run(channel_a2b_, audio_channels, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000293 out_file_.Close();
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000294
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000295 if (test_mode_ != 0) {
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000296 printf("===========================================================\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000297 printf("Test number: %d\n", test_cntr_ + 1);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000298 printf("Test type: Stereo-to-stereo\n");
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000299 }
300 test_cntr_++;
301 OpenOutFile(test_cntr_);
302 RegisterSendCodec('A', codec_l16, 32000, 512000, 320, codec_channels,
303 l16_32khz_pltype_);
304 Run(channel_a2b_, audio_channels, codec_channels);
305 RegisterSendCodec('A', codec_l16, 32000, 512000, 640, codec_channels,
306 l16_32khz_pltype_);
307 Run(channel_a2b_, audio_channels, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000308 out_file_.Close();
niklase@google.com470e71d2011-07-07 08:21:25 +0000309#ifdef PCMA_AND_PCMU
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000310 if (test_mode_ != 0) {
311 printf("===========================================================\n");
312 printf("Test number: %d\n", test_cntr_ + 1);
313 printf("Test type: Stereo-to-stereo\n");
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000314 }
315 channel_a2b_->set_codec_mode(kStereo);
316 audio_channels = 2;
317 codec_channels = 2;
318 test_cntr_++;
319 OpenOutFile(test_cntr_);
320 char codec_pcma[] = "PCMA";
321 RegisterSendCodec('A', codec_pcma, 8000, 64000, 80, codec_channels,
322 pcma_pltype_);
323 Run(channel_a2b_, audio_channels, codec_channels);
324 RegisterSendCodec('A', codec_pcma, 8000, 64000, 160, codec_channels,
325 pcma_pltype_);
326 Run(channel_a2b_, audio_channels, codec_channels);
327 RegisterSendCodec('A', codec_pcma, 8000, 64000, 240, codec_channels,
328 pcma_pltype_);
329 Run(channel_a2b_, audio_channels, codec_channels);
330 RegisterSendCodec('A', codec_pcma, 8000, 64000, 320, codec_channels,
331 pcma_pltype_);
332 Run(channel_a2b_, audio_channels, codec_channels);
333 RegisterSendCodec('A', codec_pcma, 8000, 64000, 400, codec_channels,
334 pcma_pltype_);
335 Run(channel_a2b_, audio_channels, codec_channels);
336 RegisterSendCodec('A', codec_pcma, 8000, 64000, 480, codec_channels,
337 pcma_pltype_);
338 Run(channel_a2b_, audio_channels, codec_channels);
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000339
340 // Test that VAD/DTX cannot be turned on while sending stereo.
341 EXPECT_EQ(-1, acm_a_->SetVAD(true, true, 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);
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000345 EXPECT_EQ(0, acm_a_->SetVAD(false, false, VADNormal));
tina.legrand@webrtc.org7a7a0082013-02-21 10:27:48 +0000346 EXPECT_EQ(0, acm_a_->VAD(&dtx, &vad, &vad_mode));
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000347 EXPECT_FALSE(dtx);
348 EXPECT_FALSE(vad);
349
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000350 out_file_.Close();
351 if (test_mode_ != 0) {
352 printf("===========================================================\n");
353 printf("Test number: %d\n", test_cntr_ + 1);
354 printf("Test type: Stereo-to-stereo\n");
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000355 }
356 test_cntr_++;
357 OpenOutFile(test_cntr_);
358 char codec_pcmu[] = "PCMU";
359 RegisterSendCodec('A', codec_pcmu, 8000, 64000, 80, codec_channels,
360 pcmu_pltype_);
361 Run(channel_a2b_, audio_channels, codec_channels);
362 RegisterSendCodec('A', codec_pcmu, 8000, 64000, 160, codec_channels,
363 pcmu_pltype_);
364 Run(channel_a2b_, audio_channels, codec_channels);
365 RegisterSendCodec('A', codec_pcmu, 8000, 64000, 240, codec_channels,
366 pcmu_pltype_);
367 Run(channel_a2b_, audio_channels, codec_channels);
368 RegisterSendCodec('A', codec_pcmu, 8000, 64000, 320, codec_channels,
369 pcmu_pltype_);
370 Run(channel_a2b_, audio_channels, codec_channels);
371 RegisterSendCodec('A', codec_pcmu, 8000, 64000, 400, codec_channels,
372 pcmu_pltype_);
373 Run(channel_a2b_, audio_channels, codec_channels);
374 RegisterSendCodec('A', codec_pcmu, 8000, 64000, 480, codec_channels,
375 pcmu_pltype_);
376 Run(channel_a2b_, audio_channels, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000377 out_file_.Close();
niklase@google.com470e71d2011-07-07 08:21:25 +0000378#endif
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000379#ifdef WEBRTC_CODEC_OPUS
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000380 if (test_mode_ != 0) {
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000381 printf("===========================================================\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000382 printf("Test number: %d\n", test_cntr_ + 1);
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000383 printf("Test type: Stereo-to-stereo\n");
384 }
385 channel_a2b_->set_codec_mode(kStereo);
386 audio_channels = 2;
387 codec_channels = 2;
388 test_cntr_++;
389 OpenOutFile(test_cntr_);
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000390
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000391 char codec_opus[] = "opus";
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000392 // Run Opus with 10 ms frame size.
393 RegisterSendCodec('A', codec_opus, 48000, 64000, 480, codec_channels,
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000394 opus_pltype_);
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000395 Run(channel_a2b_, audio_channels, codec_channels);
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000396 // Run Opus with 20 ms frame size.
397 RegisterSendCodec('A', codec_opus, 48000, 64000, 480*2, 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 40 ms frame size.
401 RegisterSendCodec('A', codec_opus, 48000, 64000, 480*4, 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 60 ms frame size.
405 RegisterSendCodec('A', codec_opus, 48000, 64000, 480*6, codec_channels,
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000406 opus_pltype_);
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000407 Run(channel_a2b_, audio_channels, codec_channels);
408 // Run Opus with 20 ms frame size and different bitrates.
409 RegisterSendCodec('A', codec_opus, 48000, 40000, 960, codec_channels,
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000410 opus_pltype_);
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000411 Run(channel_a2b_, audio_channels, codec_channels);
412 RegisterSendCodec('A', codec_opus, 48000, 510000, 960, codec_channels,
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000413 opus_pltype_);
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000414 Run(channel_a2b_, audio_channels, codec_channels);
415 out_file_.Close();
416#endif
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000417 //
418 // Test Mono-To-Stereo for all codecs.
419 //
420 audio_channels = 1;
421 codec_channels = 2;
niklase@google.com470e71d2011-07-07 08:21:25 +0000422
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000423#ifdef WEBRTC_CODEC_G722
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000424 if (test_mode_ != 0) {
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000425 printf("===============================================================\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000426 printf("Test number: %d\n", test_cntr_ + 1);
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000427 printf("Test type: Mono-to-stereo\n");
428 }
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000429 test_cntr_++;
430 channel_a2b_->set_codec_mode(kStereo);
431 OpenOutFile(test_cntr_);
432 RegisterSendCodec('A', codec_g722, 16000, 64000, 160, codec_channels,
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000433 g722_pltype_);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000434 Run(channel_a2b_, audio_channels, codec_channels);
435 out_file_.Close();
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000436#endif
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000437 if (test_mode_ != 0) {
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000438 printf("===============================================================\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000439 printf("Test number: %d\n", test_cntr_ + 1);
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000440 printf("Test type: Mono-to-stereo\n");
441 }
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000442 test_cntr_++;
443 channel_a2b_->set_codec_mode(kStereo);
444 OpenOutFile(test_cntr_);
445 RegisterSendCodec('A', codec_l16, 8000, 128000, 80, codec_channels,
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000446 l16_8khz_pltype_);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000447 Run(channel_a2b_, audio_channels, codec_channels);
448 out_file_.Close();
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000449 if (test_mode_ != 0) {
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000450 printf("===============================================================\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000451 printf("Test number: %d\n", test_cntr_ + 1);
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000452 printf("Test type: Mono-to-stereo\n");
453 }
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000454 test_cntr_++;
455 OpenOutFile(test_cntr_);
456 RegisterSendCodec('A', codec_l16, 16000, 256000, 160, codec_channels,
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000457 l16_16khz_pltype_);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000458 Run(channel_a2b_, audio_channels, codec_channels);
459 out_file_.Close();
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000460 if (test_mode_ != 0) {
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000461 printf("===============================================================\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000462 printf("Test number: %d\n", test_cntr_ + 1);
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000463 printf("Test type: Mono-to-stereo\n");
464 }
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000465 test_cntr_++;
466 OpenOutFile(test_cntr_);
467 RegisterSendCodec('A', codec_l16, 32000, 512000, 320, codec_channels,
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000468 l16_32khz_pltype_);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000469 Run(channel_a2b_, audio_channels, codec_channels);
470 out_file_.Close();
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000471#ifdef PCMA_AND_PCMU
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000472 if (test_mode_ != 0) {
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000473 printf("===============================================================\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000474 printf("Test number: %d\n", test_cntr_ + 1);
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000475 printf("Test type: Mono-to-stereo\n");
476 }
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000477 test_cntr_++;
478 channel_a2b_->set_codec_mode(kStereo);
479 OpenOutFile(test_cntr_);
480 RegisterSendCodec('A', codec_pcmu, 8000, 64000, 80, codec_channels,
tina.legrand@webrtc.orgae1c4542012-03-12 08:41:30 +0000481 pcmu_pltype_);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000482 Run(channel_a2b_, audio_channels, codec_channels);
483 RegisterSendCodec('A', codec_pcma, 8000, 64000, 80, codec_channels,
tina.legrand@webrtc.orgae1c4542012-03-12 08:41:30 +0000484 pcma_pltype_);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000485 Run(channel_a2b_, audio_channels, codec_channels);
486 out_file_.Close();
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000487#endif
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000488#ifdef WEBRTC_CODEC_OPUS
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000489 if (test_mode_ != 0) {
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000490 printf("===============================================================\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000491 printf("Test number: %d\n", test_cntr_ + 1);
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000492 printf("Test type: Mono-to-stereo\n");
493 }
tina.legrand@webrtc.orgc4590582012-11-28 12:23:29 +0000494
495 // Keep encode and decode in stereo.
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000496 test_cntr_++;
497 channel_a2b_->set_codec_mode(kStereo);
498 OpenOutFile(test_cntr_);
499 RegisterSendCodec('A', codec_opus, 48000, 64000, 960, codec_channels,
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000500 opus_pltype_);
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000501 Run(channel_a2b_, audio_channels, codec_channels);
tina.legrand@webrtc.orgc4590582012-11-28 12:23:29 +0000502
503 // Encode in mono, decode in stereo mode.
504 RegisterSendCodec('A', codec_opus, 48000, 64000, 960, 1, opus_pltype_);
505 Run(channel_a2b_, audio_channels, codec_channels);
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000506 out_file_.Close();
507#endif
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000508
509 //
510 // Test Stereo-To-Mono for all codecs.
511 //
512 audio_channels = 2;
513 codec_channels = 1;
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000514 channel_a2b_->set_codec_mode(kMono);
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000515
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000516#ifdef WEBRTC_CODEC_G722
517 // Run stereo audio and mono codec.
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000518 if (test_mode_ != 0) {
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000519 printf("===============================================================\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000520 printf("Test number: %d\n", test_cntr_ + 1);
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000521 printf("Test type: Stereo-to-mono\n");
522 }
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000523 test_cntr_++;
524 OpenOutFile(test_cntr_);
525 RegisterSendCodec('A', codec_g722, 16000, 64000, 160, codec_channels,
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000526 g722_pltype_);
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000527
528 // Make sure it is possible to set VAD/CNG, now that we are sending mono
529 // again.
530 EXPECT_EQ(0, acm_a_->SetVAD(true, true, VADNormal));
tina.legrand@webrtc.org7a7a0082013-02-21 10:27:48 +0000531 EXPECT_EQ(0, acm_a_->VAD(&dtx, &vad, &vad_mode));
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000532 EXPECT_TRUE(dtx);
533 EXPECT_TRUE(vad);
534 EXPECT_EQ(0, acm_a_->SetVAD(false, false, VADNormal));
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000535 Run(channel_a2b_, audio_channels, codec_channels);
536 out_file_.Close();
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000537#endif
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000538 if (test_mode_ != 0) {
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000539 printf("===============================================================\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000540 printf("Test number: %d\n", test_cntr_ + 1);
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000541 printf("Test type: Stereo-to-mono\n");
542 }
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000543 test_cntr_++;
544 OpenOutFile(test_cntr_);
545 RegisterSendCodec('A', codec_l16, 8000, 128000, 80, codec_channels,
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000546 l16_8khz_pltype_);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000547 Run(channel_a2b_, audio_channels, codec_channels);
548 out_file_.Close();
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000549 if (test_mode_ != 0) {
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000550 printf("===============================================================\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000551 printf("Test number: %d\n", test_cntr_ + 1);
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000552 printf("Test type: Stereo-to-mono\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000553 }
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000554 test_cntr_++;
555 OpenOutFile(test_cntr_);
556 RegisterSendCodec('A', codec_l16, 16000, 256000, 160, codec_channels,
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000557 l16_16khz_pltype_);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000558 Run(channel_a2b_, audio_channels, codec_channels);
559 out_file_.Close();
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000560 if (test_mode_ != 0) {
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000561 printf("==============================================================\n");
562 printf("Test number: %d\n", test_cntr_ + 1);
563 printf("Test type: Stereo-to-mono\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000564 }
565 test_cntr_++;
566 OpenOutFile(test_cntr_);
567 RegisterSendCodec('A', codec_l16, 32000, 512000, 320, codec_channels,
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000568 l16_32khz_pltype_);
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000569 Run(channel_a2b_, audio_channels, codec_channels);
570 out_file_.Close();
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000571#ifdef PCMA_AND_PCMU
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000572 if (test_mode_ != 0) {
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000573 printf("===============================================================\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000574 printf("Test number: %d\n", test_cntr_ + 1);
tina.legrand@webrtc.orgdf697752012-02-08 10:22:21 +0000575 printf("Test type: Stereo-to-mono\n");
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000576 }
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000577 test_cntr_++;
578 OpenOutFile(test_cntr_);
579 RegisterSendCodec('A', codec_pcmu, 8000, 64000, 80, codec_channels,
tina.legrand@webrtc.orgae1c4542012-03-12 08:41:30 +0000580 pcmu_pltype_);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000581 Run(channel_a2b_, audio_channels, codec_channels);
582 RegisterSendCodec('A', codec_pcma, 8000, 64000, 80, codec_channels,
tina.legrand@webrtc.orgae1c4542012-03-12 08:41:30 +0000583 pcma_pltype_);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000584 Run(channel_a2b_, audio_channels, codec_channels);
585 out_file_.Close();
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000586#endif
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000587#ifdef WEBRTC_CODEC_OPUS
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000588 if (test_mode_ != 0) {
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000589 printf("===============================================================\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000590 printf("Test number: %d\n", test_cntr_ + 1);
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000591 printf("Test type: Stereo-to-mono\n");
592 }
593 test_cntr_++;
594 OpenOutFile(test_cntr_);
tina.legrand@webrtc.orgc4590582012-11-28 12:23:29 +0000595 // Encode and decode in mono.
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000596 RegisterSendCodec('A', codec_opus, 48000, 32000, 960, codec_channels,
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000597 opus_pltype_);
tina.legrand@webrtc.orgc4590582012-11-28 12:23:29 +0000598 CodecInst opus_codec_param;
pbos@webrtc.org0946a562013-04-09 00:28:06 +0000599 for (uint8_t n = 0; n < num_encoders; n++) {
tina.legrand@webrtc.org7a7a0082013-02-21 10:27:48 +0000600 EXPECT_EQ(0, acm_b_->Codec(n, &opus_codec_param));
tina.legrand@webrtc.orgc4590582012-11-28 12:23:29 +0000601 if (!strcmp(opus_codec_param.plname, "opus")) {
602 opus_codec_param.channels = 1;
kwibergda2bf4e2016-10-24 13:47:09 -0700603 EXPECT_EQ(true,
604 acm_b_->RegisterReceiveCodec(opus_codec_param.pltype,
605 CodecInstToSdp(opus_codec_param)));
tina.legrand@webrtc.orgc4590582012-11-28 12:23:29 +0000606 break;
607 }
608 }
609 Run(channel_a2b_, audio_channels, codec_channels);
610
611 // Encode in stereo, decode in mono.
612 RegisterSendCodec('A', codec_opus, 48000, 32000, 960, 2, opus_pltype_);
613 Run(channel_a2b_, audio_channels, codec_channels);
614
615 out_file_.Close();
616
617 // Test switching between decoding mono and stereo for Opus.
618
619 // Decode in mono.
620 test_cntr_++;
621 OpenOutFile(test_cntr_);
622 if (test_mode_ != 0) {
623 // Print out codec and settings
624 printf("Test number: %d\nCodec: Opus Freq: 48000 Rate :32000 PackSize: 960"
625 " Decode: mono\n", test_cntr_);
626 }
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000627 Run(channel_a2b_, audio_channels, codec_channels);
628 out_file_.Close();
tina.legrand@webrtc.orgc4590582012-11-28 12:23:29 +0000629 // Decode in stereo.
630 test_cntr_++;
631 OpenOutFile(test_cntr_);
632 if (test_mode_ != 0) {
633 // Print out codec and settings
634 printf("Test number: %d\nCodec: Opus Freq: 48000 Rate :32000 PackSize: 960"
635 " Decode: stereo\n", test_cntr_);
636 }
637 opus_codec_param.channels = 2;
kwibergda2bf4e2016-10-24 13:47:09 -0700638 EXPECT_EQ(true,
639 acm_b_->RegisterReceiveCodec(opus_codec_param.pltype,
640 CodecInstToSdp(opus_codec_param)));
tina.legrand@webrtc.orgc4590582012-11-28 12:23:29 +0000641 Run(channel_a2b_, audio_channels, 2);
642 out_file_.Close();
643 // Decode in mono.
644 test_cntr_++;
645 OpenOutFile(test_cntr_);
646 if (test_mode_ != 0) {
647 // Print out codec and settings
648 printf("Test number: %d\nCodec: Opus Freq: 48000 Rate :32000 PackSize: 960"
649 " Decode: mono\n", test_cntr_);
650 }
651 opus_codec_param.channels = 1;
kwibergda2bf4e2016-10-24 13:47:09 -0700652 EXPECT_EQ(true,
653 acm_b_->RegisterReceiveCodec(opus_codec_param.pltype,
654 CodecInstToSdp(opus_codec_param)));
tina.legrand@webrtc.orgc4590582012-11-28 12:23:29 +0000655 Run(channel_a2b_, audio_channels, codec_channels);
656 out_file_.Close();
657
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000658#endif
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000659
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000660 // Print out which codecs were tested, and which were not, in the run.
661 if (test_mode_ != 0) {
662 printf("\nThe following codecs was INCLUDED in the test:\n");
niklase@google.com470e71d2011-07-07 08:21:25 +0000663#ifdef WEBRTC_CODEC_G722
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000664 printf(" G.722\n");
niklase@google.com470e71d2011-07-07 08:21:25 +0000665#endif
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000666 printf(" PCM16\n");
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000667 printf(" G.711\n");
tina.legrand@webrtc.orgc4590582012-11-28 12:23:29 +0000668#ifdef WEBRTC_CODEC_OPUS
669 printf(" Opus\n");
670#endif
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000671 printf("\nTo complete the test, listen to the %d number of output "
672 "files.\n",
673 test_cntr_);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000674 }
675
676 // Delete the file pointers.
677 delete in_file_stereo_;
678 delete in_file_mono_;
niklase@google.com470e71d2011-07-07 08:21:25 +0000679}
680
681// Register Codec to use in the test
682//
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000683// Input: side - which ACM to use, 'A' or 'B'
684// codec_name - name to use when register the codec
685// sampling_freq_hz - sampling frequency in Herz
686// rate - bitrate in bytes
687// pack_size - packet size in samples
688// channels - number of channels; 1 for mono, 2 for stereo
689// payload_type - payload type for the codec
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000690void TestStereo::RegisterSendCodec(char side, char* codec_name,
pbos@webrtc.org0946a562013-04-09 00:28:06 +0000691 int32_t sampling_freq_hz, int rate,
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000692 int pack_size, int channels,
693 int payload_type) {
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000694 if (test_mode_ != 0) {
695 // Print out codec and settings
tina.legrand@webrtc.orgba468042012-08-17 10:38:28 +0000696 printf("Codec: %s Freq: %d Rate: %d PackSize: %d\n", codec_name,
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000697 sampling_freq_hz, rate, pack_size);
698 }
699
700 // Store packet size in samples, used to validate the received packet
701 pack_size_samp_ = pack_size;
702
703 // Store the expected packet size in bytes, used to validate the received
704 // packet. Add 0.875 to always round up to a whole byte.
pbos@webrtc.orgd8ca7232014-12-10 11:49:13 +0000705 pack_size_bytes_ = (uint16_t)(static_cast<float>(pack_size * rate) /
706 static_cast<float>(sampling_freq_hz * 8) +
707 0.875);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000708
709 // Set pointer to the ACM where to register the codec
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000710 AudioCodingModule* my_acm = NULL;
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000711 switch (side) {
712 case 'A': {
andrew@webrtc.org89df0922013-09-12 01:27:43 +0000713 my_acm = acm_a_.get();
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000714 break;
niklase@google.com470e71d2011-07-07 08:21:25 +0000715 }
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000716 case 'B': {
andrew@webrtc.org89df0922013-09-12 01:27:43 +0000717 my_acm = acm_b_.get();
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000718 break;
tina.legrand@webrtc.org16b6b902012-04-12 11:02:38 +0000719 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000720 default:
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000721 break;
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000722 }
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000723 ASSERT_TRUE(my_acm != NULL);
niklase@google.com470e71d2011-07-07 08:21:25 +0000724
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000725 CodecInst my_codec_param;
726 // Get all codec parameters before registering
tina.legrand@webrtc.orgee92b662013-08-27 07:33:51 +0000727 EXPECT_GT(AudioCodingModule::Codec(codec_name, &my_codec_param,
728 sampling_freq_hz, channels), -1);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000729 my_codec_param.rate = rate;
730 my_codec_param.pacsize = pack_size;
tina.legrand@webrtc.orgee92b662013-08-27 07:33:51 +0000731 EXPECT_EQ(0, my_acm->RegisterSendCodec(my_codec_param));
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000732
733 send_codec_name_ = codec_name;
niklase@google.com470e71d2011-07-07 08:21:25 +0000734}
735
tina.legrand@webrtc.org16b6b902012-04-12 11:02:38 +0000736void TestStereo::Run(TestPackStereo* channel, int in_channels, int out_channels,
737 int percent_loss) {
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000738 AudioFrame audio_frame;
niklase@google.com470e71d2011-07-07 08:21:25 +0000739
pbos@webrtc.org0946a562013-04-09 00:28:06 +0000740 int32_t out_freq_hz_b = out_file_.SamplingFrequency();
741 uint16_t rec_size;
742 uint32_t time_stamp_diff;
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000743 channel->reset_payload_size();
744 int error_count = 0;
tina.legrand@webrtc.org65d61c32014-06-05 13:42:51 +0000745 int variable_bytes = 0;
746 int variable_packets = 0;
Henrik Lundin4d682082015-12-10 16:24:39 +0100747 // Set test length to 500 ms (50 blocks of 10 ms each).
748 in_file_mono_->SetNum10MsBlocksToRead(50);
749 in_file_stereo_->SetNum10MsBlocksToRead(50);
750 // Fast-forward 1 second (100 blocks) since the files start with silence.
751 in_file_stereo_->FastForward(100);
752 in_file_mono_->FastForward(100);
niklase@google.com470e71d2011-07-07 08:21:25 +0000753
andresp@webrtc.orgd0b436a2014-01-13 13:15:59 +0000754 while (1) {
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000755 // Simulate packet loss by setting |packet_loss_| to "true" in
756 // |percent_loss| percent of the loops.
757 if (percent_loss > 0) {
758 if (counter_ == floor((100 / percent_loss) + 0.5)) {
759 counter_ = 0;
760 channel->set_lost_packet(true);
761 } else {
762 channel->set_lost_packet(false);
763 }
764 counter_++;
niklase@google.com470e71d2011-07-07 08:21:25 +0000765 }
766
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000767 // Add 10 msec to ACM
768 if (in_channels == 1) {
769 if (in_file_mono_->EndOfFile()) {
770 break;
771 }
772 in_file_mono_->Read10MsData(audio_frame);
773 } else {
774 if (in_file_stereo_->EndOfFile()) {
775 break;
776 }
777 in_file_stereo_->Read10MsData(audio_frame);
778 }
henrik.lundin@webrtc.orgf56c1622015-03-02 12:29:30 +0000779 EXPECT_GE(acm_a_->Add10MsData(audio_frame), 0);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000780
tina.legrand@webrtc.org65d61c32014-06-05 13:42:51 +0000781 // Verify that the received packet size matches the settings.
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000782 rec_size = channel->payload_size();
783 if ((0 < rec_size) & (rec_size < 65535)) {
tina.legrand@webrtc.org65d61c32014-06-05 13:42:51 +0000784 if (strcmp(send_codec_name_, "opus") == 0) {
785 // Opus is a variable rate codec, hence calculate the average packet
786 // size, and later make sure the average is in the right range.
787 variable_bytes += rec_size;
788 variable_packets++;
789 } else {
790 // For fixed rate codecs, check that packet size is correct.
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000791 if ((rec_size != pack_size_bytes_ * out_channels)
792 && (pack_size_bytes_ < 65535)) {
793 error_count++;
794 }
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000795 }
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000796 // Verify that the timestamp is updated with expected length
797 time_stamp_diff = channel->timestamp_diff();
798 if ((counter_ > 10) && (time_stamp_diff != pack_size_samp_)) {
799 error_count++;
800 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000801 }
802
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000803 // Run received side of ACM
henrik.lundind4ccb002016-05-17 12:21:55 -0700804 bool muted;
805 EXPECT_EQ(0, acm_b_->PlayoutData10Ms(out_freq_hz_b, &audio_frame, &muted));
806 ASSERT_FALSE(muted);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000807
808 // Write output speech to file
809 out_file_.Write10MsData(
andrew@webrtc.org63a50982012-05-02 23:56:37 +0000810 audio_frame.data_,
811 audio_frame.samples_per_channel_ * audio_frame.num_channels_);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000812 }
813
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000814 EXPECT_EQ(0, error_count);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000815
tina.legrand@webrtc.org65d61c32014-06-05 13:42:51 +0000816 // Check that packet size is in the right range for variable rate codecs,
817 // such as Opus.
818 if (variable_packets > 0) {
819 variable_bytes /= variable_packets;
Henrik Lundin4d682082015-12-10 16:24:39 +0100820 EXPECT_NEAR(variable_bytes, pack_size_bytes_, 18);
tina.legrand@webrtc.org65d61c32014-06-05 13:42:51 +0000821 }
822
andresp@webrtc.orgd0b436a2014-01-13 13:15:59 +0000823 if (in_file_mono_->EndOfFile()) {
824 in_file_mono_->Rewind();
825 }
826 if (in_file_stereo_->EndOfFile()) {
827 in_file_stereo_->Rewind();
828 }
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000829 // Reset in case we ended with a lost packet
830 channel->set_lost_packet(false);
niklase@google.com470e71d2011-07-07 08:21:25 +0000831}
832
pbos@webrtc.org0946a562013-04-09 00:28:06 +0000833void TestStereo::OpenOutFile(int16_t test_number) {
tina.legrand@webrtc.orgba468042012-08-17 10:38:28 +0000834 std::string file_name;
835 std::stringstream file_stream;
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000836 file_stream << webrtc::test::OutputPath() << "teststereo_out_" << test_number
837 << ".pcm";
tina.legrand@webrtc.orgba468042012-08-17 10:38:28 +0000838 file_name = file_stream.str();
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000839 out_file_.Open(file_name, 32000, "wb");
niklase@google.com470e71d2011-07-07 08:21:25 +0000840}
841
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000842void TestStereo::DisplaySendReceiveCodec() {
kwiberg1fd4a4a2015-11-03 11:20:50 -0800843 auto send_codec = acm_a_->SendCodec();
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000844 if (test_mode_ != 0) {
kwiberg1fd4a4a2015-11-03 11:20:50 -0800845 ASSERT_TRUE(send_codec);
846 printf("%s -> ", send_codec->plname);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000847 }
kwiberg1fd4a4a2015-11-03 11:20:50 -0800848 CodecInst receive_codec;
849 acm_b_->ReceiveCodec(&receive_codec);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000850 if (test_mode_ != 0) {
kwiberg1fd4a4a2015-11-03 11:20:50 -0800851 printf("%s\n", receive_codec.plname);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000852 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000853}
854
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000855} // namespace webrtc