blob: b9677e3734e81726ed7bc8d8c01547a4f07950e0 [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
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +000011#include "webrtc/modules/audio_coding/main/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.org3ddc9742012-06-27 09:25:50 +000017#include "gtest/gtest.h"
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +000018#include "webrtc/common_types.h"
19#include "webrtc/engine_configurations.h"
20#include "webrtc/modules/audio_coding/main/interface/audio_coding_module_typedefs.h"
21#include "webrtc/modules/audio_coding/main/test/utility.h"
22#include "webrtc/system_wrappers/interface/trace.h"
23#include "webrtc/test/testsupport/fileutils.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,
51 const uint16_t payload_size,
52 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;
61 if (frame_type == kFrameEmpty) {
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),
117 counter_(0),
118 g722_pltype_(0),
119 l16_8khz_pltype_(-1),
120 l16_16khz_pltype_(-1),
121 l16_32khz_pltype_(-1),
122 pcma_pltype_(-1),
123 pcmu_pltype_(-1),
124 celt_pltype_(-1),
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000125 opus_pltype_(-1),
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000126 cn_8khz_pltype_(-1),
127 cn_16khz_pltype_(-1),
128 cn_32khz_pltype_(-1) {
tina.legrand@webrtc.org45175852012-06-01 09:27:35 +0000129 // test_mode = 0 for silent test (auto test)
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000130 test_mode_ = test_mode;
niklase@google.com470e71d2011-07-07 08:21:25 +0000131}
132
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000133TestStereo::~TestStereo() {
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000134 if (channel_a2b_ != NULL) {
135 delete channel_a2b_;
136 channel_a2b_ = NULL;
137 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000138}
139
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000140void TestStereo::Perform() {
pbos@webrtc.org0946a562013-04-09 00:28:06 +0000141 uint16_t frequency_hz;
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000142 int audio_channels;
143 int codec_channels;
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000144 bool dtx;
145 bool vad;
146 ACMVADMode vad_mode;
niklase@google.com470e71d2011-07-07 08:21:25 +0000147
tina.legrand@webrtc.org45175852012-06-01 09:27:35 +0000148 // Open both mono and stereo test files in 32 kHz.
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000149 const std::string file_name_stereo = webrtc::test::ResourcePath(
150 "audio_coding/teststereo32kHz", "pcm");
151 const std::string file_name_mono = webrtc::test::ResourcePath(
152 "audio_coding/testfile32kHz", "pcm");
tina.legrand@webrtc.org45175852012-06-01 09:27:35 +0000153 frequency_hz = 32000;
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000154 in_file_stereo_ = new PCMFile();
155 in_file_mono_ = new PCMFile();
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000156 in_file_stereo_->Open(file_name_stereo, frequency_hz, "rb");
157 in_file_stereo_->ReadStereo(true);
158 in_file_mono_->Open(file_name_mono, frequency_hz, "rb");
159 in_file_mono_->ReadStereo(false);
160
tina.legrand@webrtc.org45175852012-06-01 09:27:35 +0000161 // Create and initialize two ACMs, one for each side of a one-to-one call.
andrew@webrtc.org89df0922013-09-12 01:27:43 +0000162 ASSERT_TRUE((acm_a_.get() != NULL) && (acm_b_.get() != NULL));
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000163 EXPECT_EQ(0, acm_a_->InitializeReceiver());
164 EXPECT_EQ(0, acm_b_->InitializeReceiver());
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000165
tina.legrand@webrtc.org45175852012-06-01 09:27:35 +0000166 // Register all available codes as receiving codecs.
pbos@webrtc.org0946a562013-04-09 00:28:06 +0000167 uint8_t num_encoders = acm_a_->NumberOfCodecs();
tina.legrand@webrtc.org45175852012-06-01 09:27:35 +0000168 CodecInst my_codec_param;
pbos@webrtc.org0946a562013-04-09 00:28:06 +0000169 for (uint8_t n = 0; n < num_encoders; n++) {
tina.legrand@webrtc.org7a7a0082013-02-21 10:27:48 +0000170 EXPECT_EQ(0, acm_b_->Codec(n, &my_codec_param));
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000171 EXPECT_EQ(0, acm_b_->RegisterReceiveCodec(my_codec_param));
tina.legrand@webrtc.org45175852012-06-01 09:27:35 +0000172 }
173
174 // Test that unregister all receive codecs works.
pbos@webrtc.org0946a562013-04-09 00:28:06 +0000175 for (uint8_t n = 0; n < num_encoders; n++) {
tina.legrand@webrtc.org7a7a0082013-02-21 10:27:48 +0000176 EXPECT_EQ(0, acm_b_->Codec(n, &my_codec_param));
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000177 EXPECT_EQ(0, acm_b_->UnregisterReceiveCodec(my_codec_param.pltype));
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000178 }
tina.legrand@webrtc.orgae1c4542012-03-12 08:41:30 +0000179
tina.legrand@webrtc.org45175852012-06-01 09:27:35 +0000180 // Register all available codes as receiving codecs once more.
pbos@webrtc.org0946a562013-04-09 00:28:06 +0000181 for (uint8_t n = 0; n < num_encoders; n++) {
tina.legrand@webrtc.org7a7a0082013-02-21 10:27:48 +0000182 EXPECT_EQ(0, acm_b_->Codec(n, &my_codec_param));
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000183 EXPECT_EQ(0, acm_b_->RegisterReceiveCodec(my_codec_param));
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000184 }
tina.legrand@webrtc.orgae1c4542012-03-12 08:41:30 +0000185
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000186 // Create and connect the channel.
187 channel_a2b_ = new TestPackStereo;
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000188 EXPECT_EQ(0, acm_a_->RegisterTransportCallback(channel_a2b_));
andrew@webrtc.org89df0922013-09-12 01:27:43 +0000189 channel_a2b_->RegisterReceiverACM(acm_b_.get());
tina.legrand@webrtc.orgdf697752012-02-08 10:22:21 +0000190
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000191 // Start with setting VAD/DTX, before we know we will send stereo.
192 // Continue with setting a stereo codec as send codec and verify that
193 // VAD/DTX gets turned off.
194 EXPECT_EQ(0, acm_a_->SetVAD(true, true, VADNormal));
tina.legrand@webrtc.org7a7a0082013-02-21 10:27:48 +0000195 EXPECT_EQ(0, acm_a_->VAD(&dtx, &vad, &vad_mode));
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000196 EXPECT_TRUE(dtx);
197 EXPECT_TRUE(vad);
198 char codec_pcma_temp[] = "PCMA";
199 RegisterSendCodec('A', codec_pcma_temp, 8000, 64000, 80, 2, pcma_pltype_);
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_FALSE(dtx);
202 EXPECT_FALSE(vad);
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000203 if (test_mode_ != 0) {
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000204 printf("\n");
205 }
206
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000207 //
208 // Test Stereo-To-Stereo for all codecs.
209 //
210 audio_channels = 2;
211 codec_channels = 2;
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000212
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000213 // All codecs are tested for all allowed sampling frequencies, rates and
214 // packet sizes.
niklase@google.com470e71d2011-07-07 08:21:25 +0000215#ifdef WEBRTC_CODEC_G722
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000216 if (test_mode_ != 0) {
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000217 printf("===========================================================\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000218 printf("Test number: %d\n", test_cntr_ + 1);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000219 printf("Test type: Stereo-to-stereo\n");
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000220 }
221 channel_a2b_->set_codec_mode(kStereo);
222 test_cntr_++;
223 OpenOutFile(test_cntr_);
224 char codec_g722[] = "G722";
225 RegisterSendCodec('A', codec_g722, 16000, 64000, 160, codec_channels,
226 g722_pltype_);
227 Run(channel_a2b_, audio_channels, codec_channels);
228 RegisterSendCodec('A', codec_g722, 16000, 64000, 320, codec_channels,
229 g722_pltype_);
230 Run(channel_a2b_, audio_channels, codec_channels);
231 RegisterSendCodec('A', codec_g722, 16000, 64000, 480, codec_channels,
232 g722_pltype_);
233 Run(channel_a2b_, audio_channels, codec_channels);
234 RegisterSendCodec('A', codec_g722, 16000, 64000, 640, codec_channels,
235 g722_pltype_);
236 Run(channel_a2b_, audio_channels, codec_channels);
237 RegisterSendCodec('A', codec_g722, 16000, 64000, 800, codec_channels,
238 g722_pltype_);
239 Run(channel_a2b_, audio_channels, codec_channels);
240 RegisterSendCodec('A', codec_g722, 16000, 64000, 960, codec_channels,
241 g722_pltype_);
242 Run(channel_a2b_, audio_channels, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000243 out_file_.Close();
niklase@google.com470e71d2011-07-07 08:21:25 +0000244#endif
245#ifdef WEBRTC_CODEC_PCM16
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000246 if (test_mode_ != 0) {
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000247 printf("===========================================================\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000248 printf("Test number: %d\n", test_cntr_ + 1);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000249 printf("Test type: Stereo-to-stereo\n");
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000250 }
251 channel_a2b_->set_codec_mode(kStereo);
252 test_cntr_++;
253 OpenOutFile(test_cntr_);
254 char codec_l16[] = "L16";
255 RegisterSendCodec('A', codec_l16, 8000, 128000, 80, codec_channels,
256 l16_8khz_pltype_);
257 Run(channel_a2b_, audio_channels, codec_channels);
258 RegisterSendCodec('A', codec_l16, 8000, 128000, 160, codec_channels,
259 l16_8khz_pltype_);
260 Run(channel_a2b_, audio_channels, codec_channels);
261 RegisterSendCodec('A', codec_l16, 8000, 128000, 240, codec_channels,
262 l16_8khz_pltype_);
263 Run(channel_a2b_, audio_channels, codec_channels);
264 RegisterSendCodec('A', codec_l16, 8000, 128000, 320, codec_channels,
265 l16_8khz_pltype_);
266 Run(channel_a2b_, audio_channels, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000267 out_file_.Close();
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000268
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000269 if (test_mode_ != 0) {
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000270 printf("===========================================================\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000271 printf("Test number: %d\n", test_cntr_ + 1);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000272 printf("Test type: Stereo-to-stereo\n");
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000273 }
274 test_cntr_++;
275 OpenOutFile(test_cntr_);
276 RegisterSendCodec('A', codec_l16, 16000, 256000, 160, codec_channels,
277 l16_16khz_pltype_);
278 Run(channel_a2b_, audio_channels, codec_channels);
279 RegisterSendCodec('A', codec_l16, 16000, 256000, 320, codec_channels,
280 l16_16khz_pltype_);
281 Run(channel_a2b_, audio_channels, codec_channels);
282 RegisterSendCodec('A', codec_l16, 16000, 256000, 480, codec_channels,
283 l16_16khz_pltype_);
284 Run(channel_a2b_, audio_channels, codec_channels);
285 RegisterSendCodec('A', codec_l16, 16000, 256000, 640, codec_channels,
286 l16_16khz_pltype_);
287 Run(channel_a2b_, audio_channels, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000288 out_file_.Close();
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000289
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000290 if (test_mode_ != 0) {
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000291 printf("===========================================================\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000292 printf("Test number: %d\n", test_cntr_ + 1);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000293 printf("Test type: Stereo-to-stereo\n");
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000294 }
295 test_cntr_++;
296 OpenOutFile(test_cntr_);
297 RegisterSendCodec('A', codec_l16, 32000, 512000, 320, codec_channels,
298 l16_32khz_pltype_);
299 Run(channel_a2b_, audio_channels, codec_channels);
300 RegisterSendCodec('A', codec_l16, 32000, 512000, 640, codec_channels,
301 l16_32khz_pltype_);
302 Run(channel_a2b_, audio_channels, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000303 out_file_.Close();
niklase@google.com470e71d2011-07-07 08:21:25 +0000304#endif
305#define PCMA_AND_PCMU
306#ifdef PCMA_AND_PCMU
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000307 if (test_mode_ != 0) {
308 printf("===========================================================\n");
309 printf("Test number: %d\n", test_cntr_ + 1);
310 printf("Test type: Stereo-to-stereo\n");
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000311 }
312 channel_a2b_->set_codec_mode(kStereo);
313 audio_channels = 2;
314 codec_channels = 2;
315 test_cntr_++;
316 OpenOutFile(test_cntr_);
317 char codec_pcma[] = "PCMA";
318 RegisterSendCodec('A', codec_pcma, 8000, 64000, 80, codec_channels,
319 pcma_pltype_);
320 Run(channel_a2b_, audio_channels, codec_channels);
321 RegisterSendCodec('A', codec_pcma, 8000, 64000, 160, codec_channels,
322 pcma_pltype_);
323 Run(channel_a2b_, audio_channels, codec_channels);
324 RegisterSendCodec('A', codec_pcma, 8000, 64000, 240, codec_channels,
325 pcma_pltype_);
326 Run(channel_a2b_, audio_channels, codec_channels);
327 RegisterSendCodec('A', codec_pcma, 8000, 64000, 320, codec_channels,
328 pcma_pltype_);
329 Run(channel_a2b_, audio_channels, codec_channels);
330 RegisterSendCodec('A', codec_pcma, 8000, 64000, 400, codec_channels,
331 pcma_pltype_);
332 Run(channel_a2b_, audio_channels, codec_channels);
333 RegisterSendCodec('A', codec_pcma, 8000, 64000, 480, codec_channels,
334 pcma_pltype_);
335 Run(channel_a2b_, audio_channels, codec_channels);
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000336
337 // Test that VAD/DTX cannot be turned on while sending stereo.
338 EXPECT_EQ(-1, acm_a_->SetVAD(true, true, VADNormal));
tina.legrand@webrtc.org7a7a0082013-02-21 10:27:48 +0000339 EXPECT_EQ(0, acm_a_->VAD(&dtx, &vad, &vad_mode));
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000340 EXPECT_FALSE(dtx);
341 EXPECT_FALSE(vad);
342 EXPECT_EQ(-1, acm_a_->SetVAD(true, false, VADNormal));
tina.legrand@webrtc.org7a7a0082013-02-21 10:27:48 +0000343 EXPECT_EQ(0, acm_a_->VAD(&dtx, &vad, &vad_mode));
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000344 EXPECT_FALSE(dtx);
345 EXPECT_FALSE(vad);
346 EXPECT_EQ(-1, acm_a_->SetVAD(false, true, VADNormal));
tina.legrand@webrtc.org7a7a0082013-02-21 10:27:48 +0000347 EXPECT_EQ(0, acm_a_->VAD(&dtx, &vad, &vad_mode));
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000348 EXPECT_FALSE(dtx);
349 EXPECT_FALSE(vad);
350 EXPECT_EQ(0, acm_a_->SetVAD(false, false, VADNormal));
tina.legrand@webrtc.org7a7a0082013-02-21 10:27:48 +0000351 EXPECT_EQ(0, acm_a_->VAD(&dtx, &vad, &vad_mode));
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000352 EXPECT_FALSE(dtx);
353 EXPECT_FALSE(vad);
354
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000355 out_file_.Close();
356 if (test_mode_ != 0) {
357 printf("===========================================================\n");
358 printf("Test number: %d\n", test_cntr_ + 1);
359 printf("Test type: Stereo-to-stereo\n");
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000360 }
361 test_cntr_++;
362 OpenOutFile(test_cntr_);
363 char codec_pcmu[] = "PCMU";
364 RegisterSendCodec('A', codec_pcmu, 8000, 64000, 80, codec_channels,
365 pcmu_pltype_);
366 Run(channel_a2b_, audio_channels, codec_channels);
367 RegisterSendCodec('A', codec_pcmu, 8000, 64000, 160, codec_channels,
368 pcmu_pltype_);
369 Run(channel_a2b_, audio_channels, codec_channels);
370 RegisterSendCodec('A', codec_pcmu, 8000, 64000, 240, codec_channels,
371 pcmu_pltype_);
372 Run(channel_a2b_, audio_channels, codec_channels);
373 RegisterSendCodec('A', codec_pcmu, 8000, 64000, 320, codec_channels,
374 pcmu_pltype_);
375 Run(channel_a2b_, audio_channels, codec_channels);
376 RegisterSendCodec('A', codec_pcmu, 8000, 64000, 400, codec_channels,
377 pcmu_pltype_);
378 Run(channel_a2b_, audio_channels, codec_channels);
379 RegisterSendCodec('A', codec_pcmu, 8000, 64000, 480, codec_channels,
380 pcmu_pltype_);
381 Run(channel_a2b_, audio_channels, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000382 out_file_.Close();
niklase@google.com470e71d2011-07-07 08:21:25 +0000383#endif
tina.legrand@webrtc.orgdf697752012-02-08 10:22:21 +0000384#ifdef WEBRTC_CODEC_CELT
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000385 if (test_mode_ != 0) {
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000386 printf("===========================================================\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000387 printf("Test number: %d\n", test_cntr_ + 1);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000388 printf("Test type: Stereo-to-stereo\n");
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000389 }
390 channel_a2b_->set_codec_mode(kStereo);
391 audio_channels = 2;
392 codec_channels = 2;
393 test_cntr_++;
394 OpenOutFile(test_cntr_);
395 char codec_celt[] = "CELT";
tina.legrand@webrtc.org90af7f82012-06-07 08:57:27 +0000396 RegisterSendCodec('A', codec_celt, 32000, 48000, 640, codec_channels,
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000397 celt_pltype_);
398 Run(channel_a2b_, audio_channels, codec_channels);
tina.legrand@webrtc.org90af7f82012-06-07 08:57:27 +0000399 RegisterSendCodec('A', codec_celt, 32000, 64000, 640, codec_channels,
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000400 celt_pltype_);
401 Run(channel_a2b_, audio_channels, codec_channels);
tina.legrand@webrtc.org90af7f82012-06-07 08:57:27 +0000402 RegisterSendCodec('A', codec_celt, 32000, 128000, 640, codec_channels,
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000403 celt_pltype_);
404 Run(channel_a2b_, audio_channels, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000405 out_file_.Close();
tina.legrand@webrtc.orgdf697752012-02-08 10:22:21 +0000406#endif
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000407#ifdef WEBRTC_CODEC_OPUS
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000408 if (test_mode_ != 0) {
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000409 printf("===========================================================\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000410 printf("Test number: %d\n", test_cntr_ + 1);
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000411 printf("Test type: Stereo-to-stereo\n");
412 }
413 channel_a2b_->set_codec_mode(kStereo);
414 audio_channels = 2;
415 codec_channels = 2;
416 test_cntr_++;
417 OpenOutFile(test_cntr_);
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000418
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000419 char codec_opus[] = "opus";
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000420 // Run Opus with 10 ms frame size.
421 RegisterSendCodec('A', codec_opus, 48000, 64000, 480, codec_channels,
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000422 opus_pltype_);
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000423 Run(channel_a2b_, audio_channels, codec_channels);
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000424 // Run Opus with 20 ms frame size.
425 RegisterSendCodec('A', codec_opus, 48000, 64000, 480*2, codec_channels,
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000426 opus_pltype_);
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000427 Run(channel_a2b_, audio_channels, codec_channels);
428 // Run Opus with 40 ms frame size.
429 RegisterSendCodec('A', codec_opus, 48000, 64000, 480*4, codec_channels,
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000430 opus_pltype_);
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000431 Run(channel_a2b_, audio_channels, codec_channels);
432 // Run Opus with 60 ms frame size.
433 RegisterSendCodec('A', codec_opus, 48000, 64000, 480*6, codec_channels,
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000434 opus_pltype_);
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000435 Run(channel_a2b_, audio_channels, codec_channels);
436 // Run Opus with 20 ms frame size and different bitrates.
437 RegisterSendCodec('A', codec_opus, 48000, 40000, 960, codec_channels,
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000438 opus_pltype_);
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000439 Run(channel_a2b_, audio_channels, codec_channels);
440 RegisterSendCodec('A', codec_opus, 48000, 510000, 960, codec_channels,
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000441 opus_pltype_);
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000442 Run(channel_a2b_, audio_channels, codec_channels);
443 out_file_.Close();
444#endif
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000445 //
446 // Test Mono-To-Stereo for all codecs.
447 //
448 audio_channels = 1;
449 codec_channels = 2;
niklase@google.com470e71d2011-07-07 08:21:25 +0000450
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000451#ifdef WEBRTC_CODEC_G722
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000452 if (test_mode_ != 0) {
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000453 printf("===============================================================\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000454 printf("Test number: %d\n", test_cntr_ + 1);
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000455 printf("Test type: Mono-to-stereo\n");
456 }
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000457 test_cntr_++;
458 channel_a2b_->set_codec_mode(kStereo);
459 OpenOutFile(test_cntr_);
460 RegisterSendCodec('A', codec_g722, 16000, 64000, 160, codec_channels,
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000461 g722_pltype_);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000462 Run(channel_a2b_, audio_channels, codec_channels);
463 out_file_.Close();
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000464#endif
465#ifdef WEBRTC_CODEC_PCM16
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000466 if (test_mode_ != 0) {
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000467 printf("===============================================================\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000468 printf("Test number: %d\n", test_cntr_ + 1);
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000469 printf("Test type: Mono-to-stereo\n");
470 }
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000471 test_cntr_++;
472 channel_a2b_->set_codec_mode(kStereo);
473 OpenOutFile(test_cntr_);
474 RegisterSendCodec('A', codec_l16, 8000, 128000, 80, codec_channels,
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000475 l16_8khz_pltype_);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000476 Run(channel_a2b_, audio_channels, codec_channels);
477 out_file_.Close();
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000478 if (test_mode_ != 0) {
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000479 printf("===============================================================\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000480 printf("Test number: %d\n", test_cntr_ + 1);
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000481 printf("Test type: Mono-to-stereo\n");
482 }
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000483 test_cntr_++;
484 OpenOutFile(test_cntr_);
485 RegisterSendCodec('A', codec_l16, 16000, 256000, 160, codec_channels,
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000486 l16_16khz_pltype_);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000487 Run(channel_a2b_, audio_channels, codec_channels);
488 out_file_.Close();
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000489 if (test_mode_ != 0) {
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000490 printf("===============================================================\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000491 printf("Test number: %d\n", test_cntr_ + 1);
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000492 printf("Test type: Mono-to-stereo\n");
493 }
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000494 test_cntr_++;
495 OpenOutFile(test_cntr_);
496 RegisterSendCodec('A', codec_l16, 32000, 512000, 320, codec_channels,
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000497 l16_32khz_pltype_);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000498 Run(channel_a2b_, audio_channels, codec_channels);
499 out_file_.Close();
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000500#endif
501#ifdef PCMA_AND_PCMU
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000502 if (test_mode_ != 0) {
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000503 printf("===============================================================\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000504 printf("Test number: %d\n", test_cntr_ + 1);
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000505 printf("Test type: Mono-to-stereo\n");
506 }
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000507 test_cntr_++;
508 channel_a2b_->set_codec_mode(kStereo);
509 OpenOutFile(test_cntr_);
510 RegisterSendCodec('A', codec_pcmu, 8000, 64000, 80, codec_channels,
tina.legrand@webrtc.orgae1c4542012-03-12 08:41:30 +0000511 pcmu_pltype_);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000512 Run(channel_a2b_, audio_channels, codec_channels);
513 RegisterSendCodec('A', codec_pcma, 8000, 64000, 80, codec_channels,
tina.legrand@webrtc.orgae1c4542012-03-12 08:41:30 +0000514 pcma_pltype_);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000515 Run(channel_a2b_, audio_channels, codec_channels);
516 out_file_.Close();
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000517#endif
tina.legrand@webrtc.orgdf697752012-02-08 10:22:21 +0000518#ifdef WEBRTC_CODEC_CELT
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000519 if (test_mode_ != 0) {
tina.legrand@webrtc.orgdf697752012-02-08 10:22:21 +0000520 printf("===============================================================\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000521 printf("Test number: %d\n", test_cntr_ + 1);
tina.legrand@webrtc.orgdf697752012-02-08 10:22:21 +0000522 printf("Test type: Mono-to-stereo\n");
523 }
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000524 test_cntr_++;
525 channel_a2b_->set_codec_mode(kStereo);
526 OpenOutFile(test_cntr_);
tina.legrand@webrtc.org90af7f82012-06-07 08:57:27 +0000527 RegisterSendCodec('A', codec_celt, 32000, 64000, 640, codec_channels,
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000528 celt_pltype_);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000529 Run(channel_a2b_, audio_channels, codec_channels);
530 out_file_.Close();
tina.legrand@webrtc.orgdf697752012-02-08 10:22:21 +0000531#endif
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000532#ifdef WEBRTC_CODEC_OPUS
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000533 if (test_mode_ != 0) {
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000534 printf("===============================================================\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000535 printf("Test number: %d\n", test_cntr_ + 1);
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000536 printf("Test type: Mono-to-stereo\n");
537 }
tina.legrand@webrtc.orgc4590582012-11-28 12:23:29 +0000538
539 // Keep encode and decode in stereo.
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000540 test_cntr_++;
541 channel_a2b_->set_codec_mode(kStereo);
542 OpenOutFile(test_cntr_);
543 RegisterSendCodec('A', codec_opus, 48000, 64000, 960, codec_channels,
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000544 opus_pltype_);
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000545 Run(channel_a2b_, audio_channels, codec_channels);
tina.legrand@webrtc.orgc4590582012-11-28 12:23:29 +0000546
547 // Encode in mono, decode in stereo mode.
548 RegisterSendCodec('A', codec_opus, 48000, 64000, 960, 1, opus_pltype_);
549 Run(channel_a2b_, audio_channels, codec_channels);
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000550 out_file_.Close();
551#endif
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000552
553 //
554 // Test Stereo-To-Mono for all codecs.
555 //
556 audio_channels = 2;
557 codec_channels = 1;
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000558 channel_a2b_->set_codec_mode(kMono);
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000559
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000560#ifdef WEBRTC_CODEC_G722
561 // Run stereo audio and mono codec.
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000562 if (test_mode_ != 0) {
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000563 printf("===============================================================\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000564 printf("Test number: %d\n", test_cntr_ + 1);
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000565 printf("Test type: Stereo-to-mono\n");
566 }
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000567 test_cntr_++;
568 OpenOutFile(test_cntr_);
569 RegisterSendCodec('A', codec_g722, 16000, 64000, 160, codec_channels,
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000570 g722_pltype_);
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000571
572 // Make sure it is possible to set VAD/CNG, now that we are sending mono
573 // again.
574 EXPECT_EQ(0, acm_a_->SetVAD(true, true, VADNormal));
tina.legrand@webrtc.org7a7a0082013-02-21 10:27:48 +0000575 EXPECT_EQ(0, acm_a_->VAD(&dtx, &vad, &vad_mode));
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000576 EXPECT_TRUE(dtx);
577 EXPECT_TRUE(vad);
578 EXPECT_EQ(0, acm_a_->SetVAD(false, false, VADNormal));
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000579 Run(channel_a2b_, audio_channels, codec_channels);
580 out_file_.Close();
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000581#endif
582#ifdef WEBRTC_CODEC_PCM16
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000583 if (test_mode_ != 0) {
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000584 printf("===============================================================\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000585 printf("Test number: %d\n", test_cntr_ + 1);
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000586 printf("Test type: Stereo-to-mono\n");
587 }
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000588 test_cntr_++;
589 OpenOutFile(test_cntr_);
590 RegisterSendCodec('A', codec_l16, 8000, 128000, 80, codec_channels,
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000591 l16_8khz_pltype_);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000592 Run(channel_a2b_, audio_channels, codec_channels);
593 out_file_.Close();
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000594 if (test_mode_ != 0) {
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000595 printf("===============================================================\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000596 printf("Test number: %d\n", test_cntr_ + 1);
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000597 printf("Test type: Stereo-to-mono\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000598 }
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000599 test_cntr_++;
600 OpenOutFile(test_cntr_);
601 RegisterSendCodec('A', codec_l16, 16000, 256000, 160, codec_channels,
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000602 l16_16khz_pltype_);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000603 Run(channel_a2b_, audio_channels, codec_channels);
604 out_file_.Close();
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000605 if (test_mode_ != 0) {
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000606 printf("==============================================================\n");
607 printf("Test number: %d\n", test_cntr_ + 1);
608 printf("Test type: Stereo-to-mono\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000609 }
610 test_cntr_++;
611 OpenOutFile(test_cntr_);
612 RegisterSendCodec('A', codec_l16, 32000, 512000, 320, codec_channels,
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000613 l16_32khz_pltype_);
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000614 Run(channel_a2b_, audio_channels, codec_channels);
615 out_file_.Close();
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000616#endif
617#ifdef PCMA_AND_PCMU
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000618 if (test_mode_ != 0) {
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000619 printf("===============================================================\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000620 printf("Test number: %d\n", test_cntr_ + 1);
tina.legrand@webrtc.orgdf697752012-02-08 10:22:21 +0000621 printf("Test type: Stereo-to-mono\n");
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000622 }
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000623 test_cntr_++;
624 OpenOutFile(test_cntr_);
625 RegisterSendCodec('A', codec_pcmu, 8000, 64000, 80, codec_channels,
tina.legrand@webrtc.orgae1c4542012-03-12 08:41:30 +0000626 pcmu_pltype_);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000627 Run(channel_a2b_, audio_channels, codec_channels);
628 RegisterSendCodec('A', codec_pcma, 8000, 64000, 80, codec_channels,
tina.legrand@webrtc.orgae1c4542012-03-12 08:41:30 +0000629 pcma_pltype_);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000630 Run(channel_a2b_, audio_channels, codec_channels);
631 out_file_.Close();
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000632#endif
tina.legrand@webrtc.orgdf697752012-02-08 10:22:21 +0000633#ifdef WEBRTC_CODEC_CELT
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000634 if (test_mode_ != 0) {
tina.legrand@webrtc.orgdf697752012-02-08 10:22:21 +0000635 printf("===============================================================\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000636 printf("Test number: %d\n", test_cntr_ + 1);
tina.legrand@webrtc.orgdf697752012-02-08 10:22:21 +0000637 printf("Test type: Stereo-to-mono\n");
638 }
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000639 test_cntr_++;
640 OpenOutFile(test_cntr_);
tina.legrand@webrtc.org90af7f82012-06-07 08:57:27 +0000641 RegisterSendCodec('A', codec_celt, 32000, 64000, 640, codec_channels,
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000642 celt_pltype_);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000643 Run(channel_a2b_, audio_channels, codec_channels);
644 out_file_.Close();
tina.legrand@webrtc.orgdf697752012-02-08 10:22:21 +0000645#endif
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000646#ifdef WEBRTC_CODEC_OPUS
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000647 if (test_mode_ != 0) {
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000648 printf("===============================================================\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000649 printf("Test number: %d\n", test_cntr_ + 1);
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000650 printf("Test type: Stereo-to-mono\n");
651 }
652 test_cntr_++;
653 OpenOutFile(test_cntr_);
tina.legrand@webrtc.orgc4590582012-11-28 12:23:29 +0000654 // Encode and decode in mono.
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000655 RegisterSendCodec('A', codec_opus, 48000, 32000, 960, codec_channels,
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000656 opus_pltype_);
tina.legrand@webrtc.orgc4590582012-11-28 12:23:29 +0000657 CodecInst opus_codec_param;
pbos@webrtc.org0946a562013-04-09 00:28:06 +0000658 for (uint8_t n = 0; n < num_encoders; n++) {
tina.legrand@webrtc.org7a7a0082013-02-21 10:27:48 +0000659 EXPECT_EQ(0, acm_b_->Codec(n, &opus_codec_param));
tina.legrand@webrtc.orgc4590582012-11-28 12:23:29 +0000660 if (!strcmp(opus_codec_param.plname, "opus")) {
661 opus_codec_param.channels = 1;
662 EXPECT_EQ(0, acm_b_->RegisterReceiveCodec(opus_codec_param));
663 break;
664 }
665 }
666 Run(channel_a2b_, audio_channels, codec_channels);
667
668 // Encode in stereo, decode in mono.
669 RegisterSendCodec('A', codec_opus, 48000, 32000, 960, 2, opus_pltype_);
670 Run(channel_a2b_, audio_channels, codec_channels);
671
672 out_file_.Close();
673
674 // Test switching between decoding mono and stereo for Opus.
675
676 // Decode in mono.
677 test_cntr_++;
678 OpenOutFile(test_cntr_);
679 if (test_mode_ != 0) {
680 // Print out codec and settings
681 printf("Test number: %d\nCodec: Opus Freq: 48000 Rate :32000 PackSize: 960"
682 " Decode: mono\n", test_cntr_);
683 }
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000684 Run(channel_a2b_, audio_channels, codec_channels);
685 out_file_.Close();
tina.legrand@webrtc.orgc4590582012-11-28 12:23:29 +0000686 // Decode in stereo.
687 test_cntr_++;
688 OpenOutFile(test_cntr_);
689 if (test_mode_ != 0) {
690 // Print out codec and settings
691 printf("Test number: %d\nCodec: Opus Freq: 48000 Rate :32000 PackSize: 960"
692 " Decode: stereo\n", test_cntr_);
693 }
694 opus_codec_param.channels = 2;
695 EXPECT_EQ(0, acm_b_->RegisterReceiveCodec(opus_codec_param));
696 Run(channel_a2b_, audio_channels, 2);
697 out_file_.Close();
698 // Decode in mono.
699 test_cntr_++;
700 OpenOutFile(test_cntr_);
701 if (test_mode_ != 0) {
702 // Print out codec and settings
703 printf("Test number: %d\nCodec: Opus Freq: 48000 Rate :32000 PackSize: 960"
704 " Decode: mono\n", test_cntr_);
705 }
706 opus_codec_param.channels = 1;
707 EXPECT_EQ(0, acm_b_->RegisterReceiveCodec(opus_codec_param));
708 Run(channel_a2b_, audio_channels, codec_channels);
709 out_file_.Close();
710
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000711#endif
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000712
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000713 // Print out which codecs were tested, and which were not, in the run.
714 if (test_mode_ != 0) {
715 printf("\nThe following codecs was INCLUDED in the test:\n");
niklase@google.com470e71d2011-07-07 08:21:25 +0000716#ifdef WEBRTC_CODEC_G722
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000717 printf(" G.722\n");
niklase@google.com470e71d2011-07-07 08:21:25 +0000718#endif
719#ifdef WEBRTC_CODEC_PCM16
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000720 printf(" PCM16\n");
niklase@google.com470e71d2011-07-07 08:21:25 +0000721#endif
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000722 printf(" G.711\n");
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000723#ifdef WEBRTC_CODEC_CELT
724 printf(" CELT\n");
725#endif
tina.legrand@webrtc.orgc4590582012-11-28 12:23:29 +0000726#ifdef WEBRTC_CODEC_OPUS
727 printf(" Opus\n");
728#endif
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000729 printf("\nTo complete the test, listen to the %d number of output "
730 "files.\n",
731 test_cntr_);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000732 }
733
734 // Delete the file pointers.
735 delete in_file_stereo_;
736 delete in_file_mono_;
niklase@google.com470e71d2011-07-07 08:21:25 +0000737}
738
739// Register Codec to use in the test
740//
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000741// Input: side - which ACM to use, 'A' or 'B'
742// codec_name - name to use when register the codec
743// sampling_freq_hz - sampling frequency in Herz
744// rate - bitrate in bytes
745// pack_size - packet size in samples
746// channels - number of channels; 1 for mono, 2 for stereo
747// payload_type - payload type for the codec
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000748void TestStereo::RegisterSendCodec(char side, char* codec_name,
pbos@webrtc.org0946a562013-04-09 00:28:06 +0000749 int32_t sampling_freq_hz, int rate,
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000750 int pack_size, int channels,
751 int payload_type) {
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000752 if (test_mode_ != 0) {
753 // Print out codec and settings
tina.legrand@webrtc.orgba468042012-08-17 10:38:28 +0000754 printf("Codec: %s Freq: %d Rate: %d PackSize: %d\n", codec_name,
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000755 sampling_freq_hz, rate, pack_size);
756 }
757
758 // Store packet size in samples, used to validate the received packet
759 pack_size_samp_ = pack_size;
760
761 // Store the expected packet size in bytes, used to validate the received
762 // packet. Add 0.875 to always round up to a whole byte.
763 // For Celt the packet size in bytes is already counting the stereo part.
764 if (!strcmp(codec_name, "CELT")) {
pbos@webrtc.org0946a562013-04-09 00:28:06 +0000765 pack_size_bytes_ = (uint16_t)(
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000766 static_cast<float>(pack_size * rate) /
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000767 static_cast<float>(sampling_freq_hz * 8) + 0.875) / channels;
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000768 } else {
pbos@webrtc.org0946a562013-04-09 00:28:06 +0000769 pack_size_bytes_ = (uint16_t)(
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000770 static_cast<float>(pack_size * rate) /
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000771 static_cast<float>(sampling_freq_hz * 8) + 0.875);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000772 }
773
774 // Set pointer to the ACM where to register the codec
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000775 AudioCodingModule* my_acm = NULL;
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000776 switch (side) {
777 case 'A': {
andrew@webrtc.org89df0922013-09-12 01:27:43 +0000778 my_acm = acm_a_.get();
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000779 break;
niklase@google.com470e71d2011-07-07 08:21:25 +0000780 }
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000781 case 'B': {
andrew@webrtc.org89df0922013-09-12 01:27:43 +0000782 my_acm = acm_b_.get();
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000783 break;
tina.legrand@webrtc.org16b6b902012-04-12 11:02:38 +0000784 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000785 default:
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000786 break;
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000787 }
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000788 ASSERT_TRUE(my_acm != NULL);
niklase@google.com470e71d2011-07-07 08:21:25 +0000789
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000790 CodecInst my_codec_param;
791 // Get all codec parameters before registering
tina.legrand@webrtc.orgee92b662013-08-27 07:33:51 +0000792 EXPECT_GT(AudioCodingModule::Codec(codec_name, &my_codec_param,
793 sampling_freq_hz, channels), -1);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000794 my_codec_param.rate = rate;
795 my_codec_param.pacsize = pack_size;
tina.legrand@webrtc.orgee92b662013-08-27 07:33:51 +0000796 EXPECT_EQ(0, my_acm->RegisterSendCodec(my_codec_param));
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000797
798 send_codec_name_ = codec_name;
niklase@google.com470e71d2011-07-07 08:21:25 +0000799}
800
tina.legrand@webrtc.org16b6b902012-04-12 11:02:38 +0000801void TestStereo::Run(TestPackStereo* channel, int in_channels, int out_channels,
802 int percent_loss) {
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000803 AudioFrame audio_frame;
niklase@google.com470e71d2011-07-07 08:21:25 +0000804
pbos@webrtc.org0946a562013-04-09 00:28:06 +0000805 int32_t out_freq_hz_b = out_file_.SamplingFrequency();
806 uint16_t rec_size;
807 uint32_t time_stamp_diff;
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000808 channel->reset_payload_size();
809 int error_count = 0;
tina.legrand@webrtc.org65d61c32014-06-05 13:42:51 +0000810 int variable_bytes = 0;
811 int variable_packets = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000812
andresp@webrtc.orgd0b436a2014-01-13 13:15:59 +0000813 while (1) {
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000814 // Simulate packet loss by setting |packet_loss_| to "true" in
815 // |percent_loss| percent of the loops.
816 if (percent_loss > 0) {
817 if (counter_ == floor((100 / percent_loss) + 0.5)) {
818 counter_ = 0;
819 channel->set_lost_packet(true);
820 } else {
821 channel->set_lost_packet(false);
822 }
823 counter_++;
niklase@google.com470e71d2011-07-07 08:21:25 +0000824 }
825
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000826 // Add 10 msec to ACM
827 if (in_channels == 1) {
828 if (in_file_mono_->EndOfFile()) {
829 break;
830 }
831 in_file_mono_->Read10MsData(audio_frame);
832 } else {
833 if (in_file_stereo_->EndOfFile()) {
834 break;
835 }
836 in_file_stereo_->Read10MsData(audio_frame);
837 }
tina.legrand@webrtc.orgee92b662013-08-27 07:33:51 +0000838 EXPECT_EQ(0, acm_a_->Add10MsData(audio_frame));
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000839
840 // Run sender side of ACM
tina.legrand@webrtc.orgee92b662013-08-27 07:33:51 +0000841 EXPECT_GT(acm_a_->Process(), -1);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000842
tina.legrand@webrtc.org65d61c32014-06-05 13:42:51 +0000843 // Verify that the received packet size matches the settings.
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000844 rec_size = channel->payload_size();
845 if ((0 < rec_size) & (rec_size < 65535)) {
tina.legrand@webrtc.org65d61c32014-06-05 13:42:51 +0000846 if (strcmp(send_codec_name_, "opus") == 0) {
847 // Opus is a variable rate codec, hence calculate the average packet
848 // size, and later make sure the average is in the right range.
849 variable_bytes += rec_size;
850 variable_packets++;
851 } else {
852 // For fixed rate codecs, check that packet size is correct.
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000853 if ((rec_size != pack_size_bytes_ * out_channels)
854 && (pack_size_bytes_ < 65535)) {
855 error_count++;
856 }
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000857 }
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000858 // Verify that the timestamp is updated with expected length
859 time_stamp_diff = channel->timestamp_diff();
860 if ((counter_ > 10) && (time_stamp_diff != pack_size_samp_)) {
861 error_count++;
862 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000863 }
864
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000865 // Run received side of ACM
tina.legrand@webrtc.orgee92b662013-08-27 07:33:51 +0000866 EXPECT_EQ(0, acm_b_->PlayoutData10Ms(out_freq_hz_b, &audio_frame));
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000867
868 // Write output speech to file
869 out_file_.Write10MsData(
andrew@webrtc.org63a50982012-05-02 23:56:37 +0000870 audio_frame.data_,
871 audio_frame.samples_per_channel_ * audio_frame.num_channels_);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000872 }
873
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000874 EXPECT_EQ(0, error_count);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000875
tina.legrand@webrtc.org65d61c32014-06-05 13:42:51 +0000876 // Check that packet size is in the right range for variable rate codecs,
877 // such as Opus.
878 if (variable_packets > 0) {
879 variable_bytes /= variable_packets;
880 EXPECT_NEAR(variable_bytes, pack_size_bytes_, 3);
881 }
882
andresp@webrtc.orgd0b436a2014-01-13 13:15:59 +0000883 if (in_file_mono_->EndOfFile()) {
884 in_file_mono_->Rewind();
885 }
886 if (in_file_stereo_->EndOfFile()) {
887 in_file_stereo_->Rewind();
888 }
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000889 // Reset in case we ended with a lost packet
890 channel->set_lost_packet(false);
niklase@google.com470e71d2011-07-07 08:21:25 +0000891}
892
pbos@webrtc.org0946a562013-04-09 00:28:06 +0000893void TestStereo::OpenOutFile(int16_t test_number) {
tina.legrand@webrtc.orgba468042012-08-17 10:38:28 +0000894 std::string file_name;
895 std::stringstream file_stream;
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000896 file_stream << webrtc::test::OutputPath() << "teststereo_out_" << test_number
897 << ".pcm";
tina.legrand@webrtc.orgba468042012-08-17 10:38:28 +0000898 file_name = file_stream.str();
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000899 out_file_.Open(file_name, 32000, "wb");
niklase@google.com470e71d2011-07-07 08:21:25 +0000900}
901
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000902void TestStereo::DisplaySendReceiveCodec() {
903 CodecInst my_codec_param;
tina.legrand@webrtc.org7a7a0082013-02-21 10:27:48 +0000904 acm_a_->SendCodec(&my_codec_param);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000905 if (test_mode_ != 0) {
906 printf("%s -> ", my_codec_param.plname);
907 }
tina.legrand@webrtc.org7a7a0082013-02-21 10:27:48 +0000908 acm_b_->ReceiveCodec(&my_codec_param);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000909 if (test_mode_ != 0) {
910 printf("%s\n", my_codec_param.plname);
911 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000912}
913
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000914} // namespace webrtc