blob: 02bc141ae724ab1bd8ae782d80cd3de092b14cd2 [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"
kwibergac9f8762016-09-30 22:29:43 -070021#include "webrtc/test/gtest.h"
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +000022#include "webrtc/test/testsupport/fileutils.h"
henrik.lundina9a6d4b2016-12-12 05:03:02 -080023#include "webrtc/typedefs.h"
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)
111 : acm_a_(AudioCodingModule::Create(0)),
112 acm_b_(AudioCodingModule::Create(1)),
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),
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +0000117 counter_(0)
118#ifdef WEBRTC_CODEC_G722
119 , g722_pltype_(0)
120#endif
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +0000121 , l16_8khz_pltype_(-1)
122 , l16_16khz_pltype_(-1)
123 , l16_32khz_pltype_(-1)
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +0000124#ifdef PCMA_AND_PCMU
125 , pcma_pltype_(-1)
126 , pcmu_pltype_(-1)
127#endif
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +0000128#ifdef WEBRTC_CODEC_OPUS
129 , opus_pltype_(-1)
130#endif
131 {
tina.legrand@webrtc.org45175852012-06-01 09:27:35 +0000132 // test_mode = 0 for silent test (auto test)
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000133 test_mode_ = test_mode;
niklase@google.com470e71d2011-07-07 08:21:25 +0000134}
135
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000136TestStereo::~TestStereo() {
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000137 if (channel_a2b_ != NULL) {
138 delete channel_a2b_;
139 channel_a2b_ = NULL;
140 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000141}
142
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000143void TestStereo::Perform() {
pbos@webrtc.org0946a562013-04-09 00:28:06 +0000144 uint16_t frequency_hz;
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000145 int audio_channels;
146 int codec_channels;
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000147 bool dtx;
148 bool vad;
149 ACMVADMode vad_mode;
niklase@google.com470e71d2011-07-07 08:21:25 +0000150
tina.legrand@webrtc.org45175852012-06-01 09:27:35 +0000151 // Open both mono and stereo test files in 32 kHz.
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000152 const std::string file_name_stereo = webrtc::test::ResourcePath(
153 "audio_coding/teststereo32kHz", "pcm");
154 const std::string file_name_mono = webrtc::test::ResourcePath(
155 "audio_coding/testfile32kHz", "pcm");
tina.legrand@webrtc.org45175852012-06-01 09:27:35 +0000156 frequency_hz = 32000;
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000157 in_file_stereo_ = new PCMFile();
158 in_file_mono_ = new PCMFile();
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000159 in_file_stereo_->Open(file_name_stereo, frequency_hz, "rb");
160 in_file_stereo_->ReadStereo(true);
161 in_file_mono_->Open(file_name_mono, frequency_hz, "rb");
162 in_file_mono_->ReadStereo(false);
163
tina.legrand@webrtc.org45175852012-06-01 09:27:35 +0000164 // Create and initialize two ACMs, one for each side of a one-to-one call.
andrew@webrtc.org89df0922013-09-12 01:27:43 +0000165 ASSERT_TRUE((acm_a_.get() != NULL) && (acm_b_.get() != NULL));
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000166 EXPECT_EQ(0, acm_a_->InitializeReceiver());
167 EXPECT_EQ(0, acm_b_->InitializeReceiver());
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000168
tina.legrand@webrtc.org45175852012-06-01 09:27:35 +0000169 // Register all available codes as receiving codecs.
pbos@webrtc.org0946a562013-04-09 00:28:06 +0000170 uint8_t num_encoders = acm_a_->NumberOfCodecs();
tina.legrand@webrtc.org45175852012-06-01 09:27:35 +0000171 CodecInst my_codec_param;
pbos@webrtc.org0946a562013-04-09 00:28:06 +0000172 for (uint8_t n = 0; n < num_encoders; n++) {
tina.legrand@webrtc.org7a7a0082013-02-21 10:27:48 +0000173 EXPECT_EQ(0, acm_b_->Codec(n, &my_codec_param));
kwibergda2bf4e2016-10-24 13:47:09 -0700174 EXPECT_EQ(true, acm_b_->RegisterReceiveCodec(
175 my_codec_param.pltype, CodecInstToSdp(my_codec_param)));
tina.legrand@webrtc.org45175852012-06-01 09:27:35 +0000176 }
177
178 // Test that unregister all receive codecs works.
pbos@webrtc.org0946a562013-04-09 00:28:06 +0000179 for (uint8_t n = 0; n < num_encoders; n++) {
tina.legrand@webrtc.org7a7a0082013-02-21 10:27:48 +0000180 EXPECT_EQ(0, acm_b_->Codec(n, &my_codec_param));
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000181 EXPECT_EQ(0, acm_b_->UnregisterReceiveCodec(my_codec_param.pltype));
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000182 }
tina.legrand@webrtc.orgae1c4542012-03-12 08:41:30 +0000183
tina.legrand@webrtc.org45175852012-06-01 09:27:35 +0000184 // Register all available codes as receiving codecs once more.
pbos@webrtc.org0946a562013-04-09 00:28:06 +0000185 for (uint8_t n = 0; n < num_encoders; n++) {
tina.legrand@webrtc.org7a7a0082013-02-21 10:27:48 +0000186 EXPECT_EQ(0, acm_b_->Codec(n, &my_codec_param));
kwibergda2bf4e2016-10-24 13:47:09 -0700187 EXPECT_EQ(true, acm_b_->RegisterReceiveCodec(
188 my_codec_param.pltype, CodecInstToSdp(my_codec_param)));
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000189 }
tina.legrand@webrtc.orgae1c4542012-03-12 08:41:30 +0000190
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000191 // Create and connect the channel.
192 channel_a2b_ = new TestPackStereo;
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000193 EXPECT_EQ(0, acm_a_->RegisterTransportCallback(channel_a2b_));
andrew@webrtc.org89df0922013-09-12 01:27:43 +0000194 channel_a2b_->RegisterReceiverACM(acm_b_.get());
tina.legrand@webrtc.orgdf697752012-02-08 10:22:21 +0000195
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000196 // Start with setting VAD/DTX, before we know we will send stereo.
197 // Continue with setting a stereo codec as send codec and verify that
198 // VAD/DTX gets turned off.
199 EXPECT_EQ(0, acm_a_->SetVAD(true, true, VADNormal));
tina.legrand@webrtc.org7a7a0082013-02-21 10:27:48 +0000200 EXPECT_EQ(0, acm_a_->VAD(&dtx, &vad, &vad_mode));
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000201 EXPECT_TRUE(dtx);
202 EXPECT_TRUE(vad);
203 char codec_pcma_temp[] = "PCMA";
204 RegisterSendCodec('A', codec_pcma_temp, 8000, 64000, 80, 2, pcma_pltype_);
tina.legrand@webrtc.org7a7a0082013-02-21 10:27:48 +0000205 EXPECT_EQ(0, acm_a_->VAD(&dtx, &vad, &vad_mode));
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000206 EXPECT_FALSE(dtx);
207 EXPECT_FALSE(vad);
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000208 if (test_mode_ != 0) {
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000209 printf("\n");
210 }
211
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000212 //
213 // Test Stereo-To-Stereo for all codecs.
214 //
215 audio_channels = 2;
216 codec_channels = 2;
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000217
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000218 // All codecs are tested for all allowed sampling frequencies, rates and
219 // packet sizes.
niklase@google.com470e71d2011-07-07 08:21:25 +0000220#ifdef WEBRTC_CODEC_G722
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000221 if (test_mode_ != 0) {
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000222 printf("===========================================================\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000223 printf("Test number: %d\n", test_cntr_ + 1);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000224 printf("Test type: Stereo-to-stereo\n");
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000225 }
226 channel_a2b_->set_codec_mode(kStereo);
227 test_cntr_++;
228 OpenOutFile(test_cntr_);
229 char codec_g722[] = "G722";
230 RegisterSendCodec('A', codec_g722, 16000, 64000, 160, codec_channels,
231 g722_pltype_);
232 Run(channel_a2b_, audio_channels, codec_channels);
233 RegisterSendCodec('A', codec_g722, 16000, 64000, 320, codec_channels,
234 g722_pltype_);
235 Run(channel_a2b_, audio_channels, codec_channels);
236 RegisterSendCodec('A', codec_g722, 16000, 64000, 480, codec_channels,
237 g722_pltype_);
238 Run(channel_a2b_, audio_channels, codec_channels);
239 RegisterSendCodec('A', codec_g722, 16000, 64000, 640, codec_channels,
240 g722_pltype_);
241 Run(channel_a2b_, audio_channels, codec_channels);
242 RegisterSendCodec('A', codec_g722, 16000, 64000, 800, codec_channels,
243 g722_pltype_);
244 Run(channel_a2b_, audio_channels, codec_channels);
245 RegisterSendCodec('A', codec_g722, 16000, 64000, 960, codec_channels,
246 g722_pltype_);
247 Run(channel_a2b_, audio_channels, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000248 out_file_.Close();
niklase@google.com470e71d2011-07-07 08:21:25 +0000249#endif
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000250 if (test_mode_ != 0) {
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000251 printf("===========================================================\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000252 printf("Test number: %d\n", test_cntr_ + 1);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000253 printf("Test type: Stereo-to-stereo\n");
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000254 }
255 channel_a2b_->set_codec_mode(kStereo);
256 test_cntr_++;
257 OpenOutFile(test_cntr_);
258 char codec_l16[] = "L16";
259 RegisterSendCodec('A', codec_l16, 8000, 128000, 80, codec_channels,
260 l16_8khz_pltype_);
261 Run(channel_a2b_, audio_channels, codec_channels);
262 RegisterSendCodec('A', codec_l16, 8000, 128000, 160, codec_channels,
263 l16_8khz_pltype_);
264 Run(channel_a2b_, audio_channels, codec_channels);
265 RegisterSendCodec('A', codec_l16, 8000, 128000, 240, codec_channels,
266 l16_8khz_pltype_);
267 Run(channel_a2b_, audio_channels, codec_channels);
268 RegisterSendCodec('A', codec_l16, 8000, 128000, 320, codec_channels,
269 l16_8khz_pltype_);
270 Run(channel_a2b_, audio_channels, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000271 out_file_.Close();
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000272
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000273 if (test_mode_ != 0) {
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000274 printf("===========================================================\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000275 printf("Test number: %d\n", test_cntr_ + 1);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000276 printf("Test type: Stereo-to-stereo\n");
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000277 }
278 test_cntr_++;
279 OpenOutFile(test_cntr_);
280 RegisterSendCodec('A', codec_l16, 16000, 256000, 160, codec_channels,
281 l16_16khz_pltype_);
282 Run(channel_a2b_, audio_channels, codec_channels);
283 RegisterSendCodec('A', codec_l16, 16000, 256000, 320, codec_channels,
284 l16_16khz_pltype_);
285 Run(channel_a2b_, audio_channels, codec_channels);
286 RegisterSendCodec('A', codec_l16, 16000, 256000, 480, codec_channels,
287 l16_16khz_pltype_);
288 Run(channel_a2b_, audio_channels, codec_channels);
289 RegisterSendCodec('A', codec_l16, 16000, 256000, 640, codec_channels,
290 l16_16khz_pltype_);
291 Run(channel_a2b_, audio_channels, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000292 out_file_.Close();
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000293
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000294 if (test_mode_ != 0) {
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000295 printf("===========================================================\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000296 printf("Test number: %d\n", test_cntr_ + 1);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000297 printf("Test type: Stereo-to-stereo\n");
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000298 }
299 test_cntr_++;
300 OpenOutFile(test_cntr_);
301 RegisterSendCodec('A', codec_l16, 32000, 512000, 320, codec_channels,
302 l16_32khz_pltype_);
303 Run(channel_a2b_, audio_channels, codec_channels);
304 RegisterSendCodec('A', codec_l16, 32000, 512000, 640, codec_channels,
305 l16_32khz_pltype_);
306 Run(channel_a2b_, audio_channels, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000307 out_file_.Close();
niklase@google.com470e71d2011-07-07 08:21:25 +0000308#ifdef PCMA_AND_PCMU
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000309 if (test_mode_ != 0) {
310 printf("===========================================================\n");
311 printf("Test number: %d\n", test_cntr_ + 1);
312 printf("Test type: Stereo-to-stereo\n");
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000313 }
314 channel_a2b_->set_codec_mode(kStereo);
315 audio_channels = 2;
316 codec_channels = 2;
317 test_cntr_++;
318 OpenOutFile(test_cntr_);
319 char codec_pcma[] = "PCMA";
320 RegisterSendCodec('A', codec_pcma, 8000, 64000, 80, codec_channels,
321 pcma_pltype_);
322 Run(channel_a2b_, audio_channels, codec_channels);
323 RegisterSendCodec('A', codec_pcma, 8000, 64000, 160, codec_channels,
324 pcma_pltype_);
325 Run(channel_a2b_, audio_channels, codec_channels);
326 RegisterSendCodec('A', codec_pcma, 8000, 64000, 240, codec_channels,
327 pcma_pltype_);
328 Run(channel_a2b_, audio_channels, codec_channels);
329 RegisterSendCodec('A', codec_pcma, 8000, 64000, 320, codec_channels,
330 pcma_pltype_);
331 Run(channel_a2b_, audio_channels, codec_channels);
332 RegisterSendCodec('A', codec_pcma, 8000, 64000, 400, codec_channels,
333 pcma_pltype_);
334 Run(channel_a2b_, audio_channels, codec_channels);
335 RegisterSendCodec('A', codec_pcma, 8000, 64000, 480, codec_channels,
336 pcma_pltype_);
337 Run(channel_a2b_, audio_channels, codec_channels);
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000338
339 // Test that VAD/DTX cannot be turned on while sending stereo.
340 EXPECT_EQ(-1, acm_a_->SetVAD(true, true, VADNormal));
tina.legrand@webrtc.org7a7a0082013-02-21 10:27:48 +0000341 EXPECT_EQ(0, acm_a_->VAD(&dtx, &vad, &vad_mode));
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000342 EXPECT_FALSE(dtx);
343 EXPECT_FALSE(vad);
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000344 EXPECT_EQ(0, acm_a_->SetVAD(false, false, VADNormal));
tina.legrand@webrtc.org7a7a0082013-02-21 10:27:48 +0000345 EXPECT_EQ(0, acm_a_->VAD(&dtx, &vad, &vad_mode));
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000346 EXPECT_FALSE(dtx);
347 EXPECT_FALSE(vad);
348
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000349 out_file_.Close();
350 if (test_mode_ != 0) {
351 printf("===========================================================\n");
352 printf("Test number: %d\n", test_cntr_ + 1);
353 printf("Test type: Stereo-to-stereo\n");
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000354 }
355 test_cntr_++;
356 OpenOutFile(test_cntr_);
357 char codec_pcmu[] = "PCMU";
358 RegisterSendCodec('A', codec_pcmu, 8000, 64000, 80, codec_channels,
359 pcmu_pltype_);
360 Run(channel_a2b_, audio_channels, codec_channels);
361 RegisterSendCodec('A', codec_pcmu, 8000, 64000, 160, codec_channels,
362 pcmu_pltype_);
363 Run(channel_a2b_, audio_channels, codec_channels);
364 RegisterSendCodec('A', codec_pcmu, 8000, 64000, 240, codec_channels,
365 pcmu_pltype_);
366 Run(channel_a2b_, audio_channels, codec_channels);
367 RegisterSendCodec('A', codec_pcmu, 8000, 64000, 320, codec_channels,
368 pcmu_pltype_);
369 Run(channel_a2b_, audio_channels, codec_channels);
370 RegisterSendCodec('A', codec_pcmu, 8000, 64000, 400, codec_channels,
371 pcmu_pltype_);
372 Run(channel_a2b_, audio_channels, codec_channels);
373 RegisterSendCodec('A', codec_pcmu, 8000, 64000, 480, codec_channels,
374 pcmu_pltype_);
375 Run(channel_a2b_, audio_channels, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000376 out_file_.Close();
niklase@google.com470e71d2011-07-07 08:21:25 +0000377#endif
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000378#ifdef WEBRTC_CODEC_OPUS
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000379 if (test_mode_ != 0) {
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000380 printf("===========================================================\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000381 printf("Test number: %d\n", test_cntr_ + 1);
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000382 printf("Test type: Stereo-to-stereo\n");
383 }
384 channel_a2b_->set_codec_mode(kStereo);
385 audio_channels = 2;
386 codec_channels = 2;
387 test_cntr_++;
388 OpenOutFile(test_cntr_);
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000389
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000390 char codec_opus[] = "opus";
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000391 // Run Opus with 10 ms frame size.
392 RegisterSendCodec('A', codec_opus, 48000, 64000, 480, codec_channels,
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000393 opus_pltype_);
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000394 Run(channel_a2b_, audio_channels, codec_channels);
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000395 // Run Opus with 20 ms frame size.
396 RegisterSendCodec('A', codec_opus, 48000, 64000, 480*2, codec_channels,
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000397 opus_pltype_);
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000398 Run(channel_a2b_, audio_channels, codec_channels);
399 // Run Opus with 40 ms frame size.
400 RegisterSendCodec('A', codec_opus, 48000, 64000, 480*4, codec_channels,
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000401 opus_pltype_);
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000402 Run(channel_a2b_, audio_channels, codec_channels);
403 // Run Opus with 60 ms frame size.
404 RegisterSendCodec('A', codec_opus, 48000, 64000, 480*6, codec_channels,
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000405 opus_pltype_);
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000406 Run(channel_a2b_, audio_channels, codec_channels);
407 // Run Opus with 20 ms frame size and different bitrates.
408 RegisterSendCodec('A', codec_opus, 48000, 40000, 960, codec_channels,
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 RegisterSendCodec('A', codec_opus, 48000, 510000, 960, codec_channels,
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000412 opus_pltype_);
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000413 Run(channel_a2b_, audio_channels, codec_channels);
414 out_file_.Close();
415#endif
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000416 //
417 // Test Mono-To-Stereo for all codecs.
418 //
419 audio_channels = 1;
420 codec_channels = 2;
niklase@google.com470e71d2011-07-07 08:21:25 +0000421
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000422#ifdef WEBRTC_CODEC_G722
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000423 if (test_mode_ != 0) {
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000424 printf("===============================================================\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000425 printf("Test number: %d\n", test_cntr_ + 1);
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000426 printf("Test type: Mono-to-stereo\n");
427 }
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000428 test_cntr_++;
429 channel_a2b_->set_codec_mode(kStereo);
430 OpenOutFile(test_cntr_);
431 RegisterSendCodec('A', codec_g722, 16000, 64000, 160, codec_channels,
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000432 g722_pltype_);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000433 Run(channel_a2b_, audio_channels, codec_channels);
434 out_file_.Close();
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000435#endif
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000436 if (test_mode_ != 0) {
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000437 printf("===============================================================\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000438 printf("Test number: %d\n", test_cntr_ + 1);
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000439 printf("Test type: Mono-to-stereo\n");
440 }
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000441 test_cntr_++;
442 channel_a2b_->set_codec_mode(kStereo);
443 OpenOutFile(test_cntr_);
444 RegisterSendCodec('A', codec_l16, 8000, 128000, 80, codec_channels,
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000445 l16_8khz_pltype_);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000446 Run(channel_a2b_, audio_channels, codec_channels);
447 out_file_.Close();
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000448 if (test_mode_ != 0) {
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000449 printf("===============================================================\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000450 printf("Test number: %d\n", test_cntr_ + 1);
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000451 printf("Test type: Mono-to-stereo\n");
452 }
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000453 test_cntr_++;
454 OpenOutFile(test_cntr_);
455 RegisterSendCodec('A', codec_l16, 16000, 256000, 160, codec_channels,
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000456 l16_16khz_pltype_);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000457 Run(channel_a2b_, audio_channels, codec_channels);
458 out_file_.Close();
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000459 if (test_mode_ != 0) {
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000460 printf("===============================================================\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000461 printf("Test number: %d\n", test_cntr_ + 1);
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000462 printf("Test type: Mono-to-stereo\n");
463 }
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000464 test_cntr_++;
465 OpenOutFile(test_cntr_);
466 RegisterSendCodec('A', codec_l16, 32000, 512000, 320, codec_channels,
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000467 l16_32khz_pltype_);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000468 Run(channel_a2b_, audio_channels, codec_channels);
469 out_file_.Close();
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000470#ifdef PCMA_AND_PCMU
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000471 if (test_mode_ != 0) {
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000472 printf("===============================================================\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000473 printf("Test number: %d\n", test_cntr_ + 1);
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000474 printf("Test type: Mono-to-stereo\n");
475 }
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000476 test_cntr_++;
477 channel_a2b_->set_codec_mode(kStereo);
478 OpenOutFile(test_cntr_);
479 RegisterSendCodec('A', codec_pcmu, 8000, 64000, 80, codec_channels,
tina.legrand@webrtc.orgae1c4542012-03-12 08:41:30 +0000480 pcmu_pltype_);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000481 Run(channel_a2b_, audio_channels, codec_channels);
482 RegisterSendCodec('A', codec_pcma, 8000, 64000, 80, codec_channels,
tina.legrand@webrtc.orgae1c4542012-03-12 08:41:30 +0000483 pcma_pltype_);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000484 Run(channel_a2b_, audio_channels, codec_channels);
485 out_file_.Close();
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000486#endif
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000487#ifdef WEBRTC_CODEC_OPUS
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000488 if (test_mode_ != 0) {
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000489 printf("===============================================================\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000490 printf("Test number: %d\n", test_cntr_ + 1);
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000491 printf("Test type: Mono-to-stereo\n");
492 }
tina.legrand@webrtc.orgc4590582012-11-28 12:23:29 +0000493
494 // Keep encode and decode in stereo.
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000495 test_cntr_++;
496 channel_a2b_->set_codec_mode(kStereo);
497 OpenOutFile(test_cntr_);
498 RegisterSendCodec('A', codec_opus, 48000, 64000, 960, codec_channels,
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000499 opus_pltype_);
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000500 Run(channel_a2b_, audio_channels, codec_channels);
tina.legrand@webrtc.orgc4590582012-11-28 12:23:29 +0000501
502 // Encode in mono, decode in stereo mode.
503 RegisterSendCodec('A', codec_opus, 48000, 64000, 960, 1, opus_pltype_);
504 Run(channel_a2b_, audio_channels, codec_channels);
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000505 out_file_.Close();
506#endif
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000507
508 //
509 // Test Stereo-To-Mono for all codecs.
510 //
511 audio_channels = 2;
512 codec_channels = 1;
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000513 channel_a2b_->set_codec_mode(kMono);
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000514
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000515#ifdef WEBRTC_CODEC_G722
516 // Run stereo audio and mono codec.
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000517 if (test_mode_ != 0) {
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000518 printf("===============================================================\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000519 printf("Test number: %d\n", test_cntr_ + 1);
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000520 printf("Test type: Stereo-to-mono\n");
521 }
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000522 test_cntr_++;
523 OpenOutFile(test_cntr_);
524 RegisterSendCodec('A', codec_g722, 16000, 64000, 160, codec_channels,
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000525 g722_pltype_);
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000526
527 // Make sure it is possible to set VAD/CNG, now that we are sending mono
528 // again.
529 EXPECT_EQ(0, acm_a_->SetVAD(true, true, VADNormal));
tina.legrand@webrtc.org7a7a0082013-02-21 10:27:48 +0000530 EXPECT_EQ(0, acm_a_->VAD(&dtx, &vad, &vad_mode));
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000531 EXPECT_TRUE(dtx);
532 EXPECT_TRUE(vad);
533 EXPECT_EQ(0, acm_a_->SetVAD(false, false, VADNormal));
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000534 Run(channel_a2b_, audio_channels, codec_channels);
535 out_file_.Close();
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000536#endif
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000537 if (test_mode_ != 0) {
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000538 printf("===============================================================\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000539 printf("Test number: %d\n", test_cntr_ + 1);
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000540 printf("Test type: Stereo-to-mono\n");
541 }
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000542 test_cntr_++;
543 OpenOutFile(test_cntr_);
544 RegisterSendCodec('A', codec_l16, 8000, 128000, 80, codec_channels,
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000545 l16_8khz_pltype_);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000546 Run(channel_a2b_, audio_channels, codec_channels);
547 out_file_.Close();
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000548 if (test_mode_ != 0) {
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000549 printf("===============================================================\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000550 printf("Test number: %d\n", test_cntr_ + 1);
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000551 printf("Test type: Stereo-to-mono\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000552 }
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000553 test_cntr_++;
554 OpenOutFile(test_cntr_);
555 RegisterSendCodec('A', codec_l16, 16000, 256000, 160, codec_channels,
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000556 l16_16khz_pltype_);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000557 Run(channel_a2b_, audio_channels, codec_channels);
558 out_file_.Close();
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000559 if (test_mode_ != 0) {
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000560 printf("==============================================================\n");
561 printf("Test number: %d\n", test_cntr_ + 1);
562 printf("Test type: Stereo-to-mono\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000563 }
564 test_cntr_++;
565 OpenOutFile(test_cntr_);
566 RegisterSendCodec('A', codec_l16, 32000, 512000, 320, codec_channels,
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000567 l16_32khz_pltype_);
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000568 Run(channel_a2b_, audio_channels, codec_channels);
569 out_file_.Close();
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000570#ifdef PCMA_AND_PCMU
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000571 if (test_mode_ != 0) {
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000572 printf("===============================================================\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000573 printf("Test number: %d\n", test_cntr_ + 1);
tina.legrand@webrtc.orgdf697752012-02-08 10:22:21 +0000574 printf("Test type: Stereo-to-mono\n");
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000575 }
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000576 test_cntr_++;
577 OpenOutFile(test_cntr_);
578 RegisterSendCodec('A', codec_pcmu, 8000, 64000, 80, codec_channels,
tina.legrand@webrtc.orgae1c4542012-03-12 08:41:30 +0000579 pcmu_pltype_);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000580 Run(channel_a2b_, audio_channels, codec_channels);
581 RegisterSendCodec('A', codec_pcma, 8000, 64000, 80, codec_channels,
tina.legrand@webrtc.orgae1c4542012-03-12 08:41:30 +0000582 pcma_pltype_);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000583 Run(channel_a2b_, audio_channels, codec_channels);
584 out_file_.Close();
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000585#endif
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000586#ifdef WEBRTC_CODEC_OPUS
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000587 if (test_mode_ != 0) {
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000588 printf("===============================================================\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000589 printf("Test number: %d\n", test_cntr_ + 1);
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000590 printf("Test type: Stereo-to-mono\n");
591 }
592 test_cntr_++;
593 OpenOutFile(test_cntr_);
tina.legrand@webrtc.orgc4590582012-11-28 12:23:29 +0000594 // Encode and decode in mono.
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000595 RegisterSendCodec('A', codec_opus, 48000, 32000, 960, codec_channels,
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000596 opus_pltype_);
tina.legrand@webrtc.orgc4590582012-11-28 12:23:29 +0000597 CodecInst opus_codec_param;
pbos@webrtc.org0946a562013-04-09 00:28:06 +0000598 for (uint8_t n = 0; n < num_encoders; n++) {
tina.legrand@webrtc.org7a7a0082013-02-21 10:27:48 +0000599 EXPECT_EQ(0, acm_b_->Codec(n, &opus_codec_param));
tina.legrand@webrtc.orgc4590582012-11-28 12:23:29 +0000600 if (!strcmp(opus_codec_param.plname, "opus")) {
601 opus_codec_param.channels = 1;
kwibergda2bf4e2016-10-24 13:47:09 -0700602 EXPECT_EQ(true,
603 acm_b_->RegisterReceiveCodec(opus_codec_param.pltype,
604 CodecInstToSdp(opus_codec_param)));
tina.legrand@webrtc.orgc4590582012-11-28 12:23:29 +0000605 break;
606 }
607 }
608 Run(channel_a2b_, audio_channels, codec_channels);
609
610 // Encode in stereo, decode in mono.
611 RegisterSendCodec('A', codec_opus, 48000, 32000, 960, 2, opus_pltype_);
612 Run(channel_a2b_, audio_channels, codec_channels);
613
614 out_file_.Close();
615
616 // Test switching between decoding mono and stereo for Opus.
617
618 // Decode in mono.
619 test_cntr_++;
620 OpenOutFile(test_cntr_);
621 if (test_mode_ != 0) {
622 // Print out codec and settings
623 printf("Test number: %d\nCodec: Opus Freq: 48000 Rate :32000 PackSize: 960"
624 " Decode: mono\n", test_cntr_);
625 }
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000626 Run(channel_a2b_, audio_channels, codec_channels);
627 out_file_.Close();
tina.legrand@webrtc.orgc4590582012-11-28 12:23:29 +0000628 // Decode in stereo.
629 test_cntr_++;
630 OpenOutFile(test_cntr_);
631 if (test_mode_ != 0) {
632 // Print out codec and settings
633 printf("Test number: %d\nCodec: Opus Freq: 48000 Rate :32000 PackSize: 960"
634 " Decode: stereo\n", test_cntr_);
635 }
636 opus_codec_param.channels = 2;
kwibergda2bf4e2016-10-24 13:47:09 -0700637 EXPECT_EQ(true,
638 acm_b_->RegisterReceiveCodec(opus_codec_param.pltype,
639 CodecInstToSdp(opus_codec_param)));
tina.legrand@webrtc.orgc4590582012-11-28 12:23:29 +0000640 Run(channel_a2b_, audio_channels, 2);
641 out_file_.Close();
642 // Decode in mono.
643 test_cntr_++;
644 OpenOutFile(test_cntr_);
645 if (test_mode_ != 0) {
646 // Print out codec and settings
647 printf("Test number: %d\nCodec: Opus Freq: 48000 Rate :32000 PackSize: 960"
648 " Decode: mono\n", test_cntr_);
649 }
650 opus_codec_param.channels = 1;
kwibergda2bf4e2016-10-24 13:47:09 -0700651 EXPECT_EQ(true,
652 acm_b_->RegisterReceiveCodec(opus_codec_param.pltype,
653 CodecInstToSdp(opus_codec_param)));
tina.legrand@webrtc.orgc4590582012-11-28 12:23:29 +0000654 Run(channel_a2b_, audio_channels, codec_channels);
655 out_file_.Close();
656
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000657#endif
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000658
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000659 // Print out which codecs were tested, and which were not, in the run.
660 if (test_mode_ != 0) {
661 printf("\nThe following codecs was INCLUDED in the test:\n");
niklase@google.com470e71d2011-07-07 08:21:25 +0000662#ifdef WEBRTC_CODEC_G722
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000663 printf(" G.722\n");
niklase@google.com470e71d2011-07-07 08:21:25 +0000664#endif
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000665 printf(" PCM16\n");
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000666 printf(" G.711\n");
tina.legrand@webrtc.orgc4590582012-11-28 12:23:29 +0000667#ifdef WEBRTC_CODEC_OPUS
668 printf(" Opus\n");
669#endif
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000670 printf("\nTo complete the test, listen to the %d number of output "
671 "files.\n",
672 test_cntr_);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000673 }
674
675 // Delete the file pointers.
676 delete in_file_stereo_;
677 delete in_file_mono_;
niklase@google.com470e71d2011-07-07 08:21:25 +0000678}
679
680// Register Codec to use in the test
681//
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000682// Input: side - which ACM to use, 'A' or 'B'
683// codec_name - name to use when register the codec
684// sampling_freq_hz - sampling frequency in Herz
685// rate - bitrate in bytes
686// pack_size - packet size in samples
687// channels - number of channels; 1 for mono, 2 for stereo
688// payload_type - payload type for the codec
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000689void TestStereo::RegisterSendCodec(char side, char* codec_name,
pbos@webrtc.org0946a562013-04-09 00:28:06 +0000690 int32_t sampling_freq_hz, int rate,
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000691 int pack_size, int channels,
692 int payload_type) {
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000693 if (test_mode_ != 0) {
694 // Print out codec and settings
tina.legrand@webrtc.orgba468042012-08-17 10:38:28 +0000695 printf("Codec: %s Freq: %d Rate: %d PackSize: %d\n", codec_name,
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000696 sampling_freq_hz, rate, pack_size);
697 }
698
699 // Store packet size in samples, used to validate the received packet
700 pack_size_samp_ = pack_size;
701
702 // Store the expected packet size in bytes, used to validate the received
703 // packet. Add 0.875 to always round up to a whole byte.
pbos@webrtc.orgd8ca7232014-12-10 11:49:13 +0000704 pack_size_bytes_ = (uint16_t)(static_cast<float>(pack_size * rate) /
705 static_cast<float>(sampling_freq_hz * 8) +
706 0.875);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000707
708 // Set pointer to the ACM where to register the codec
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000709 AudioCodingModule* my_acm = NULL;
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000710 switch (side) {
711 case 'A': {
andrew@webrtc.org89df0922013-09-12 01:27:43 +0000712 my_acm = acm_a_.get();
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000713 break;
niklase@google.com470e71d2011-07-07 08:21:25 +0000714 }
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000715 case 'B': {
andrew@webrtc.org89df0922013-09-12 01:27:43 +0000716 my_acm = acm_b_.get();
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000717 break;
tina.legrand@webrtc.org16b6b902012-04-12 11:02:38 +0000718 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000719 default:
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000720 break;
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000721 }
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000722 ASSERT_TRUE(my_acm != NULL);
niklase@google.com470e71d2011-07-07 08:21:25 +0000723
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000724 CodecInst my_codec_param;
725 // Get all codec parameters before registering
tina.legrand@webrtc.orgee92b662013-08-27 07:33:51 +0000726 EXPECT_GT(AudioCodingModule::Codec(codec_name, &my_codec_param,
727 sampling_freq_hz, channels), -1);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000728 my_codec_param.rate = rate;
729 my_codec_param.pacsize = pack_size;
tina.legrand@webrtc.orgee92b662013-08-27 07:33:51 +0000730 EXPECT_EQ(0, my_acm->RegisterSendCodec(my_codec_param));
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000731
732 send_codec_name_ = codec_name;
niklase@google.com470e71d2011-07-07 08:21:25 +0000733}
734
tina.legrand@webrtc.org16b6b902012-04-12 11:02:38 +0000735void TestStereo::Run(TestPackStereo* channel, int in_channels, int out_channels,
736 int percent_loss) {
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000737 AudioFrame audio_frame;
niklase@google.com470e71d2011-07-07 08:21:25 +0000738
pbos@webrtc.org0946a562013-04-09 00:28:06 +0000739 int32_t out_freq_hz_b = out_file_.SamplingFrequency();
740 uint16_t rec_size;
741 uint32_t time_stamp_diff;
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000742 channel->reset_payload_size();
743 int error_count = 0;
tina.legrand@webrtc.org65d61c32014-06-05 13:42:51 +0000744 int variable_bytes = 0;
745 int variable_packets = 0;
Henrik Lundin4d682082015-12-10 16:24:39 +0100746 // Set test length to 500 ms (50 blocks of 10 ms each).
747 in_file_mono_->SetNum10MsBlocksToRead(50);
748 in_file_stereo_->SetNum10MsBlocksToRead(50);
749 // Fast-forward 1 second (100 blocks) since the files start with silence.
750 in_file_stereo_->FastForward(100);
751 in_file_mono_->FastForward(100);
niklase@google.com470e71d2011-07-07 08:21:25 +0000752
andresp@webrtc.orgd0b436a2014-01-13 13:15:59 +0000753 while (1) {
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000754 // Simulate packet loss by setting |packet_loss_| to "true" in
755 // |percent_loss| percent of the loops.
756 if (percent_loss > 0) {
757 if (counter_ == floor((100 / percent_loss) + 0.5)) {
758 counter_ = 0;
759 channel->set_lost_packet(true);
760 } else {
761 channel->set_lost_packet(false);
762 }
763 counter_++;
niklase@google.com470e71d2011-07-07 08:21:25 +0000764 }
765
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000766 // Add 10 msec to ACM
767 if (in_channels == 1) {
768 if (in_file_mono_->EndOfFile()) {
769 break;
770 }
771 in_file_mono_->Read10MsData(audio_frame);
772 } else {
773 if (in_file_stereo_->EndOfFile()) {
774 break;
775 }
776 in_file_stereo_->Read10MsData(audio_frame);
777 }
henrik.lundin@webrtc.orgf56c1622015-03-02 12:29:30 +0000778 EXPECT_GE(acm_a_->Add10MsData(audio_frame), 0);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000779
tina.legrand@webrtc.org65d61c32014-06-05 13:42:51 +0000780 // Verify that the received packet size matches the settings.
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000781 rec_size = channel->payload_size();
782 if ((0 < rec_size) & (rec_size < 65535)) {
tina.legrand@webrtc.org65d61c32014-06-05 13:42:51 +0000783 if (strcmp(send_codec_name_, "opus") == 0) {
784 // Opus is a variable rate codec, hence calculate the average packet
785 // size, and later make sure the average is in the right range.
786 variable_bytes += rec_size;
787 variable_packets++;
788 } else {
789 // For fixed rate codecs, check that packet size is correct.
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000790 if ((rec_size != pack_size_bytes_ * out_channels)
791 && (pack_size_bytes_ < 65535)) {
792 error_count++;
793 }
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000794 }
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000795 // Verify that the timestamp is updated with expected length
796 time_stamp_diff = channel->timestamp_diff();
797 if ((counter_ > 10) && (time_stamp_diff != pack_size_samp_)) {
798 error_count++;
799 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000800 }
801
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000802 // Run received side of ACM
henrik.lundind4ccb002016-05-17 12:21:55 -0700803 bool muted;
804 EXPECT_EQ(0, acm_b_->PlayoutData10Ms(out_freq_hz_b, &audio_frame, &muted));
805 ASSERT_FALSE(muted);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000806
807 // Write output speech to file
808 out_file_.Write10MsData(
yujo36b1a5f2017-06-12 12:45:32 -0700809 audio_frame.data(),
andrew@webrtc.org63a50982012-05-02 23:56:37 +0000810 audio_frame.samples_per_channel_ * audio_frame.num_channels_);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000811 }
812
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000813 EXPECT_EQ(0, error_count);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000814
tina.legrand@webrtc.org65d61c32014-06-05 13:42:51 +0000815 // Check that packet size is in the right range for variable rate codecs,
816 // such as Opus.
817 if (variable_packets > 0) {
818 variable_bytes /= variable_packets;
Henrik Lundin4d682082015-12-10 16:24:39 +0100819 EXPECT_NEAR(variable_bytes, pack_size_bytes_, 18);
tina.legrand@webrtc.org65d61c32014-06-05 13:42:51 +0000820 }
821
andresp@webrtc.orgd0b436a2014-01-13 13:15:59 +0000822 if (in_file_mono_->EndOfFile()) {
823 in_file_mono_->Rewind();
824 }
825 if (in_file_stereo_->EndOfFile()) {
826 in_file_stereo_->Rewind();
827 }
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000828 // Reset in case we ended with a lost packet
829 channel->set_lost_packet(false);
niklase@google.com470e71d2011-07-07 08:21:25 +0000830}
831
pbos@webrtc.org0946a562013-04-09 00:28:06 +0000832void TestStereo::OpenOutFile(int16_t test_number) {
tina.legrand@webrtc.orgba468042012-08-17 10:38:28 +0000833 std::string file_name;
834 std::stringstream file_stream;
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000835 file_stream << webrtc::test::OutputPath() << "teststereo_out_" << test_number
836 << ".pcm";
tina.legrand@webrtc.orgba468042012-08-17 10:38:28 +0000837 file_name = file_stream.str();
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000838 out_file_.Open(file_name, 32000, "wb");
niklase@google.com470e71d2011-07-07 08:21:25 +0000839}
840
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000841void TestStereo::DisplaySendReceiveCodec() {
kwiberg1fd4a4a2015-11-03 11:20:50 -0800842 auto send_codec = acm_a_->SendCodec();
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000843 if (test_mode_ != 0) {
kwiberg1fd4a4a2015-11-03 11:20:50 -0800844 ASSERT_TRUE(send_codec);
845 printf("%s -> ", send_codec->plname);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000846 }
kwiberg1fd4a4a2015-11-03 11:20:50 -0800847 CodecInst receive_codec;
848 acm_b_->ReceiveCodec(&receive_codec);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000849 if (test_mode_ != 0) {
kwiberg1fd4a4a2015-11-03 11:20:50 -0800850 printf("%s\n", receive_codec.plname);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000851 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000852}
853
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000854} // namespace webrtc