blob: 741f00b946135e4c924933f8352658959f1e31f2 [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"
18
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +000019#include "webrtc/common_types.h"
20#include "webrtc/engine_configurations.h"
21#include "webrtc/modules/audio_coding/main/interface/audio_coding_module_typedefs.h"
22#include "webrtc/modules/audio_coding/main/test/utility.h"
23#include "webrtc/system_wrappers/interface/trace.h"
24#include "webrtc/test/testsupport/fileutils.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000025
tina.legrand@webrtc.org554ae1a2011-12-16 10:09:04 +000026namespace webrtc {
niklase@google.com470e71d2011-07-07 08:21:25 +000027
28// Class for simulating packet handling
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +000029TestPackStereo::TestPackStereo()
30 : receiver_acm_(NULL),
31 seq_no_(0),
32 timestamp_diff_(0),
33 last_in_timestamp_(0),
34 total_bytes_(0),
35 payload_size_(0),
36 codec_mode_(kNotSet),
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000037 lost_packet_(false) {
38}
niklase@google.com470e71d2011-07-07 08:21:25 +000039
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000040TestPackStereo::~TestPackStereo() {
41}
niklase@google.com470e71d2011-07-07 08:21:25 +000042
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +000043void TestPackStereo::RegisterReceiverACM(AudioCodingModule* acm) {
44 receiver_acm_ = acm;
45 return;
46}
niklase@google.com470e71d2011-07-07 08:21:25 +000047
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000048int32_t TestPackStereo::SendData(const FrameType frame_type,
49 const uint8_t payload_type,
50 const uint32_t timestamp,
51 const uint8_t* payload_data,
52 const uint16_t payload_size,
53 const RTPFragmentationHeader* fragmentation) {
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +000054 WebRtcRTPHeader rtp_info;
pbos@webrtc.org0946a562013-04-09 00:28:06 +000055 int32_t status = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +000056
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +000057 rtp_info.header.markerBit = false;
58 rtp_info.header.ssrc = 0;
59 rtp_info.header.sequenceNumber = seq_no_++;
60 rtp_info.header.payloadType = payload_type;
61 rtp_info.header.timestamp = timestamp;
62 if (frame_type == kFrameEmpty) {
tina.legrand@webrtc.org16b6b902012-04-12 11:02:38 +000063 // Skip this frame
64 return 0;
65 }
niklase@google.com470e71d2011-07-07 08:21:25 +000066
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +000067 if (lost_packet_ == false) {
68 if (frame_type != kAudioFrameCN) {
69 rtp_info.type.Audio.isCNG = false;
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +000070 rtp_info.type.Audio.channel = static_cast<int>(codec_mode_);
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +000071 } else {
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +000072 rtp_info.type.Audio.isCNG = true;
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +000073 rtp_info.type.Audio.channel = static_cast<int>(kMono);
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +000074 }
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +000075 status = receiver_acm_->IncomingPacket(payload_data, payload_size,
tina.legrand@webrtc.org45175852012-06-01 09:27:35 +000076 rtp_info);
niklase@google.com470e71d2011-07-07 08:21:25 +000077
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +000078 if (frame_type != kAudioFrameCN) {
79 payload_size_ = payload_size;
niklase@google.com470e71d2011-07-07 08:21:25 +000080 } else {
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +000081 payload_size_ = -1;
niklase@google.com470e71d2011-07-07 08:21:25 +000082 }
tina.legrand@webrtc.org16b6b902012-04-12 11:02:38 +000083
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +000084 timestamp_diff_ = timestamp - last_in_timestamp_;
85 last_in_timestamp_ = timestamp;
86 total_bytes_ += payload_size;
tina.legrand@webrtc.org16b6b902012-04-12 11:02:38 +000087 }
88 return status;
niklase@google.com470e71d2011-07-07 08:21:25 +000089}
90
pbos@webrtc.org0946a562013-04-09 00:28:06 +000091uint16_t TestPackStereo::payload_size() {
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +000092 return payload_size_;
niklase@google.com470e71d2011-07-07 08:21:25 +000093}
94
pbos@webrtc.org0946a562013-04-09 00:28:06 +000095uint32_t TestPackStereo::timestamp_diff() {
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +000096 return timestamp_diff_;
niklase@google.com470e71d2011-07-07 08:21:25 +000097}
98
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +000099void TestPackStereo::reset_payload_size() {
100 payload_size_ = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000101}
102
tina.legrand@webrtc.org16b6b902012-04-12 11:02:38 +0000103void TestPackStereo::set_codec_mode(enum StereoMonoMode mode) {
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000104 codec_mode_ = mode;
tina.legrand@webrtc.org16b6b902012-04-12 11:02:38 +0000105}
106
107void TestPackStereo::set_lost_packet(bool lost) {
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000108 lost_packet_ = lost;
niklase@google.com470e71d2011-07-07 08:21:25 +0000109}
110
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000111TestStereo::TestStereo(int test_mode)
112 : acm_a_(NULL),
113 acm_b_(NULL),
114 channel_a2b_(NULL),
115 test_cntr_(0),
116 pack_size_samp_(0),
117 pack_size_bytes_(0),
118 counter_(0),
119 g722_pltype_(0),
120 l16_8khz_pltype_(-1),
121 l16_16khz_pltype_(-1),
122 l16_32khz_pltype_(-1),
123 pcma_pltype_(-1),
124 pcmu_pltype_(-1),
125 celt_pltype_(-1),
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000126 opus_pltype_(-1),
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000127 cn_8khz_pltype_(-1),
128 cn_16khz_pltype_(-1),
129 cn_32khz_pltype_(-1) {
tina.legrand@webrtc.org45175852012-06-01 09:27:35 +0000130 // test_mode = 0 for silent test (auto test)
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000131 test_mode_ = test_mode;
niklase@google.com470e71d2011-07-07 08:21:25 +0000132}
133
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000134TestStereo::~TestStereo() {
135 if (acm_a_ != NULL) {
136 AudioCodingModule::Destroy(acm_a_);
137 acm_a_ = NULL;
138 }
139 if (acm_b_ != NULL) {
140 AudioCodingModule::Destroy(acm_b_);
141 acm_b_ = NULL;
142 }
143 if (channel_a2b_ != NULL) {
144 delete channel_a2b_;
145 channel_a2b_ = NULL;
146 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000147}
148
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000149void TestStereo::Perform() {
pbos@webrtc.org0946a562013-04-09 00:28:06 +0000150 uint16_t frequency_hz;
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000151 int audio_channels;
152 int codec_channels;
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000153 bool dtx;
154 bool vad;
155 ACMVADMode vad_mode;
niklase@google.com470e71d2011-07-07 08:21:25 +0000156
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000157 if (test_mode_ == 0) {
158 printf("Running Stereo Test");
159 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioCoding, -1,
160 "---------- TestStereo ----------");
161 }
162
tina.legrand@webrtc.org45175852012-06-01 09:27:35 +0000163 // Open both mono and stereo test files in 32 kHz.
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000164 const std::string file_name_stereo = webrtc::test::ResourcePath(
165 "audio_coding/teststereo32kHz", "pcm");
166 const std::string file_name_mono = webrtc::test::ResourcePath(
167 "audio_coding/testfile32kHz", "pcm");
tina.legrand@webrtc.org45175852012-06-01 09:27:35 +0000168 frequency_hz = 32000;
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000169 in_file_stereo_ = new PCMFile();
170 in_file_mono_ = new PCMFile();
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000171 in_file_stereo_->Open(file_name_stereo, frequency_hz, "rb");
172 in_file_stereo_->ReadStereo(true);
173 in_file_mono_->Open(file_name_mono, frequency_hz, "rb");
174 in_file_mono_->ReadStereo(false);
175
tina.legrand@webrtc.org45175852012-06-01 09:27:35 +0000176 // Create and initialize two ACMs, one for each side of a one-to-one call.
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000177 acm_a_ = AudioCodingModule::Create(0);
178 acm_b_ = AudioCodingModule::Create(1);
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000179 ASSERT_TRUE((acm_a_ != NULL) && (acm_b_ != NULL));
180 EXPECT_EQ(0, acm_a_->InitializeReceiver());
181 EXPECT_EQ(0, acm_b_->InitializeReceiver());
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000182
tina.legrand@webrtc.org45175852012-06-01 09:27:35 +0000183 // Register all available codes as receiving codecs.
pbos@webrtc.org0946a562013-04-09 00:28:06 +0000184 uint8_t num_encoders = acm_a_->NumberOfCodecs();
tina.legrand@webrtc.org45175852012-06-01 09:27:35 +0000185 CodecInst my_codec_param;
pbos@webrtc.org0946a562013-04-09 00:28:06 +0000186 for (uint8_t n = 0; n < num_encoders; n++) {
tina.legrand@webrtc.org7a7a0082013-02-21 10:27:48 +0000187 EXPECT_EQ(0, acm_b_->Codec(n, &my_codec_param));
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000188 EXPECT_EQ(0, acm_b_->RegisterReceiveCodec(my_codec_param));
tina.legrand@webrtc.org45175852012-06-01 09:27:35 +0000189 }
190
191 // Test that unregister all receive codecs works.
pbos@webrtc.org0946a562013-04-09 00:28:06 +0000192 for (uint8_t n = 0; n < num_encoders; n++) {
tina.legrand@webrtc.org7a7a0082013-02-21 10:27:48 +0000193 EXPECT_EQ(0, acm_b_->Codec(n, &my_codec_param));
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000194 EXPECT_EQ(0, acm_b_->UnregisterReceiveCodec(my_codec_param.pltype));
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000195 }
tina.legrand@webrtc.orgae1c4542012-03-12 08:41:30 +0000196
tina.legrand@webrtc.org45175852012-06-01 09:27:35 +0000197 // Register all available codes as receiving codecs once more.
pbos@webrtc.org0946a562013-04-09 00:28:06 +0000198 for (uint8_t n = 0; n < num_encoders; n++) {
tina.legrand@webrtc.org7a7a0082013-02-21 10:27:48 +0000199 EXPECT_EQ(0, acm_b_->Codec(n, &my_codec_param));
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000200 EXPECT_EQ(0, acm_b_->RegisterReceiveCodec(my_codec_param));
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000201 }
tina.legrand@webrtc.orgae1c4542012-03-12 08:41:30 +0000202
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000203 // TODO(tlegrand): Take care of return values of all function calls.
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000204
tina.legrand@webrtc.org45175852012-06-01 09:27:35 +0000205 // TODO(tlegrand): Re-register all stereo codecs needed in the test,
206 // with new payload numbers.
207 // g722_pltype_ = 117;
208 // l16_8khz_pltype_ = 120;
209 // l16_16khz_pltype_ = 121;
210 // l16_32khz_pltype_ = 122;
211 // pcma_pltype_ = 110;
212 // pcmu_pltype_ = 118;
213 // celt_pltype_ = 119;
214 // cn_8khz_pltype_ = 123;
215 // cn_16khz_pltype_ = 124;
216 // cn_32khz_pltype_ = 125;
tina.legrand@webrtc.orgae1c4542012-03-12 08:41:30 +0000217
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000218 // Create and connect the channel.
219 channel_a2b_ = new TestPackStereo;
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000220 EXPECT_EQ(0, acm_a_->RegisterTransportCallback(channel_a2b_));
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000221 channel_a2b_->RegisterReceiverACM(acm_b_);
tina.legrand@webrtc.orgdf697752012-02-08 10:22:21 +0000222
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000223 // Start with setting VAD/DTX, before we know we will send stereo.
224 // Continue with setting a stereo codec as send codec and verify that
225 // VAD/DTX gets turned off.
226 EXPECT_EQ(0, acm_a_->SetVAD(true, true, VADNormal));
tina.legrand@webrtc.org7a7a0082013-02-21 10:27:48 +0000227 EXPECT_EQ(0, acm_a_->VAD(&dtx, &vad, &vad_mode));
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000228 EXPECT_TRUE(dtx);
229 EXPECT_TRUE(vad);
230 char codec_pcma_temp[] = "PCMA";
231 RegisterSendCodec('A', codec_pcma_temp, 8000, 64000, 80, 2, pcma_pltype_);
tina.legrand@webrtc.org7a7a0082013-02-21 10:27:48 +0000232 EXPECT_EQ(0, acm_a_->VAD(&dtx, &vad, &vad_mode));
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000233 EXPECT_FALSE(dtx);
234 EXPECT_FALSE(vad);
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000235 if (test_mode_ != 0) {
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000236 printf("\n");
237 }
238
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000239 //
240 // Test Stereo-To-Stereo for all codecs.
241 //
242 audio_channels = 2;
243 codec_channels = 2;
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000244
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000245 // All codecs are tested for all allowed sampling frequencies, rates and
246 // packet sizes.
niklase@google.com470e71d2011-07-07 08:21:25 +0000247#ifdef WEBRTC_CODEC_G722
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000248 if (test_mode_ != 0) {
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000249 printf("===========================================================\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000250 printf("Test number: %d\n", test_cntr_ + 1);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000251 printf("Test type: Stereo-to-stereo\n");
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000252 }
253 channel_a2b_->set_codec_mode(kStereo);
254 test_cntr_++;
255 OpenOutFile(test_cntr_);
256 char codec_g722[] = "G722";
257 RegisterSendCodec('A', codec_g722, 16000, 64000, 160, codec_channels,
258 g722_pltype_);
259 Run(channel_a2b_, audio_channels, codec_channels);
260 RegisterSendCodec('A', codec_g722, 16000, 64000, 320, codec_channels,
261 g722_pltype_);
262 Run(channel_a2b_, audio_channels, codec_channels);
263 RegisterSendCodec('A', codec_g722, 16000, 64000, 480, codec_channels,
264 g722_pltype_);
265 Run(channel_a2b_, audio_channels, codec_channels);
266 RegisterSendCodec('A', codec_g722, 16000, 64000, 640, codec_channels,
267 g722_pltype_);
268 Run(channel_a2b_, audio_channels, codec_channels);
269 RegisterSendCodec('A', codec_g722, 16000, 64000, 800, codec_channels,
270 g722_pltype_);
271 Run(channel_a2b_, audio_channels, codec_channels);
272 RegisterSendCodec('A', codec_g722, 16000, 64000, 960, codec_channels,
273 g722_pltype_);
274 Run(channel_a2b_, audio_channels, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000275 out_file_.Close();
niklase@google.com470e71d2011-07-07 08:21:25 +0000276#endif
277#ifdef WEBRTC_CODEC_PCM16
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000278 if (test_mode_ != 0) {
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000279 printf("===========================================================\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000280 printf("Test number: %d\n", test_cntr_ + 1);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000281 printf("Test type: Stereo-to-stereo\n");
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000282 }
283 channel_a2b_->set_codec_mode(kStereo);
284 test_cntr_++;
285 OpenOutFile(test_cntr_);
286 char codec_l16[] = "L16";
287 RegisterSendCodec('A', codec_l16, 8000, 128000, 80, codec_channels,
288 l16_8khz_pltype_);
289 Run(channel_a2b_, audio_channels, codec_channels);
290 RegisterSendCodec('A', codec_l16, 8000, 128000, 160, codec_channels,
291 l16_8khz_pltype_);
292 Run(channel_a2b_, audio_channels, codec_channels);
293 RegisterSendCodec('A', codec_l16, 8000, 128000, 240, codec_channels,
294 l16_8khz_pltype_);
295 Run(channel_a2b_, audio_channels, codec_channels);
296 RegisterSendCodec('A', codec_l16, 8000, 128000, 320, codec_channels,
297 l16_8khz_pltype_);
298 Run(channel_a2b_, audio_channels, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000299 out_file_.Close();
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000300
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000301 if (test_mode_ != 0) {
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000302 printf("===========================================================\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000303 printf("Test number: %d\n", test_cntr_ + 1);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000304 printf("Test type: Stereo-to-stereo\n");
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000305 }
306 test_cntr_++;
307 OpenOutFile(test_cntr_);
308 RegisterSendCodec('A', codec_l16, 16000, 256000, 160, codec_channels,
309 l16_16khz_pltype_);
310 Run(channel_a2b_, audio_channels, codec_channels);
311 RegisterSendCodec('A', codec_l16, 16000, 256000, 320, codec_channels,
312 l16_16khz_pltype_);
313 Run(channel_a2b_, audio_channels, codec_channels);
314 RegisterSendCodec('A', codec_l16, 16000, 256000, 480, codec_channels,
315 l16_16khz_pltype_);
316 Run(channel_a2b_, audio_channels, codec_channels);
317 RegisterSendCodec('A', codec_l16, 16000, 256000, 640, codec_channels,
318 l16_16khz_pltype_);
319 Run(channel_a2b_, audio_channels, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000320 out_file_.Close();
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000321
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000322 if (test_mode_ != 0) {
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000323 printf("===========================================================\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000324 printf("Test number: %d\n", test_cntr_ + 1);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000325 printf("Test type: Stereo-to-stereo\n");
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000326 }
327 test_cntr_++;
328 OpenOutFile(test_cntr_);
329 RegisterSendCodec('A', codec_l16, 32000, 512000, 320, codec_channels,
330 l16_32khz_pltype_);
331 Run(channel_a2b_, audio_channels, codec_channels);
332 RegisterSendCodec('A', codec_l16, 32000, 512000, 640, codec_channels,
333 l16_32khz_pltype_);
334 Run(channel_a2b_, audio_channels, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000335 out_file_.Close();
niklase@google.com470e71d2011-07-07 08:21:25 +0000336#endif
337#define PCMA_AND_PCMU
338#ifdef PCMA_AND_PCMU
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000339 if (test_mode_ != 0) {
340 printf("===========================================================\n");
341 printf("Test number: %d\n", test_cntr_ + 1);
342 printf("Test type: Stereo-to-stereo\n");
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000343 }
344 channel_a2b_->set_codec_mode(kStereo);
345 audio_channels = 2;
346 codec_channels = 2;
347 test_cntr_++;
348 OpenOutFile(test_cntr_);
349 char codec_pcma[] = "PCMA";
350 RegisterSendCodec('A', codec_pcma, 8000, 64000, 80, codec_channels,
351 pcma_pltype_);
352 Run(channel_a2b_, audio_channels, codec_channels);
353 RegisterSendCodec('A', codec_pcma, 8000, 64000, 160, codec_channels,
354 pcma_pltype_);
355 Run(channel_a2b_, audio_channels, codec_channels);
356 RegisterSendCodec('A', codec_pcma, 8000, 64000, 240, codec_channels,
357 pcma_pltype_);
358 Run(channel_a2b_, audio_channels, codec_channels);
359 RegisterSendCodec('A', codec_pcma, 8000, 64000, 320, codec_channels,
360 pcma_pltype_);
361 Run(channel_a2b_, audio_channels, codec_channels);
362 RegisterSendCodec('A', codec_pcma, 8000, 64000, 400, codec_channels,
363 pcma_pltype_);
364 Run(channel_a2b_, audio_channels, codec_channels);
365 RegisterSendCodec('A', codec_pcma, 8000, 64000, 480, codec_channels,
366 pcma_pltype_);
367 Run(channel_a2b_, audio_channels, codec_channels);
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000368
369 // Test that VAD/DTX cannot be turned on while sending stereo.
370 EXPECT_EQ(-1, acm_a_->SetVAD(true, true, VADNormal));
tina.legrand@webrtc.org7a7a0082013-02-21 10:27:48 +0000371 EXPECT_EQ(0, acm_a_->VAD(&dtx, &vad, &vad_mode));
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000372 EXPECT_FALSE(dtx);
373 EXPECT_FALSE(vad);
374 EXPECT_EQ(-1, acm_a_->SetVAD(true, false, VADNormal));
tina.legrand@webrtc.org7a7a0082013-02-21 10:27:48 +0000375 EXPECT_EQ(0, acm_a_->VAD(&dtx, &vad, &vad_mode));
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000376 EXPECT_FALSE(dtx);
377 EXPECT_FALSE(vad);
378 EXPECT_EQ(-1, acm_a_->SetVAD(false, true, VADNormal));
tina.legrand@webrtc.org7a7a0082013-02-21 10:27:48 +0000379 EXPECT_EQ(0, acm_a_->VAD(&dtx, &vad, &vad_mode));
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000380 EXPECT_FALSE(dtx);
381 EXPECT_FALSE(vad);
382 EXPECT_EQ(0, acm_a_->SetVAD(false, false, VADNormal));
tina.legrand@webrtc.org7a7a0082013-02-21 10:27:48 +0000383 EXPECT_EQ(0, acm_a_->VAD(&dtx, &vad, &vad_mode));
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000384 EXPECT_FALSE(dtx);
385 EXPECT_FALSE(vad);
386
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000387 out_file_.Close();
388 if (test_mode_ != 0) {
389 printf("===========================================================\n");
390 printf("Test number: %d\n", test_cntr_ + 1);
391 printf("Test type: Stereo-to-stereo\n");
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000392 }
393 test_cntr_++;
394 OpenOutFile(test_cntr_);
395 char codec_pcmu[] = "PCMU";
396 RegisterSendCodec('A', codec_pcmu, 8000, 64000, 80, codec_channels,
397 pcmu_pltype_);
398 Run(channel_a2b_, audio_channels, codec_channels);
399 RegisterSendCodec('A', codec_pcmu, 8000, 64000, 160, codec_channels,
400 pcmu_pltype_);
401 Run(channel_a2b_, audio_channels, codec_channels);
402 RegisterSendCodec('A', codec_pcmu, 8000, 64000, 240, codec_channels,
403 pcmu_pltype_);
404 Run(channel_a2b_, audio_channels, codec_channels);
405 RegisterSendCodec('A', codec_pcmu, 8000, 64000, 320, codec_channels,
406 pcmu_pltype_);
407 Run(channel_a2b_, audio_channels, codec_channels);
408 RegisterSendCodec('A', codec_pcmu, 8000, 64000, 400, codec_channels,
409 pcmu_pltype_);
410 Run(channel_a2b_, audio_channels, codec_channels);
411 RegisterSendCodec('A', codec_pcmu, 8000, 64000, 480, codec_channels,
412 pcmu_pltype_);
413 Run(channel_a2b_, audio_channels, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000414 out_file_.Close();
niklase@google.com470e71d2011-07-07 08:21:25 +0000415#endif
tina.legrand@webrtc.orgdf697752012-02-08 10:22:21 +0000416#ifdef WEBRTC_CODEC_CELT
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000417 if (test_mode_ != 0) {
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000418 printf("===========================================================\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000419 printf("Test number: %d\n", test_cntr_ + 1);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000420 printf("Test type: Stereo-to-stereo\n");
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000421 }
422 channel_a2b_->set_codec_mode(kStereo);
423 audio_channels = 2;
424 codec_channels = 2;
425 test_cntr_++;
426 OpenOutFile(test_cntr_);
427 char codec_celt[] = "CELT";
tina.legrand@webrtc.org90af7f82012-06-07 08:57:27 +0000428 RegisterSendCodec('A', codec_celt, 32000, 48000, 640, codec_channels,
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000429 celt_pltype_);
430 Run(channel_a2b_, audio_channels, codec_channels);
tina.legrand@webrtc.org90af7f82012-06-07 08:57:27 +0000431 RegisterSendCodec('A', codec_celt, 32000, 64000, 640, codec_channels,
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000432 celt_pltype_);
433 Run(channel_a2b_, audio_channels, codec_channels);
tina.legrand@webrtc.org90af7f82012-06-07 08:57:27 +0000434 RegisterSendCodec('A', codec_celt, 32000, 128000, 640, codec_channels,
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000435 celt_pltype_);
436 Run(channel_a2b_, audio_channels, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000437 out_file_.Close();
tina.legrand@webrtc.orgdf697752012-02-08 10:22:21 +0000438#endif
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000439#ifdef WEBRTC_CODEC_OPUS
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000440 if (test_mode_ != 0) {
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000441 printf("===========================================================\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000442 printf("Test number: %d\n", test_cntr_ + 1);
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000443 printf("Test type: Stereo-to-stereo\n");
444 }
445 channel_a2b_->set_codec_mode(kStereo);
446 audio_channels = 2;
447 codec_channels = 2;
448 test_cntr_++;
449 OpenOutFile(test_cntr_);
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000450
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000451 char codec_opus[] = "opus";
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000452 // Run Opus with 10 ms frame size.
453 RegisterSendCodec('A', codec_opus, 48000, 64000, 480, codec_channels,
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000454 opus_pltype_);
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000455 Run(channel_a2b_, audio_channels, codec_channels);
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000456 // Run Opus with 20 ms frame size.
457 RegisterSendCodec('A', codec_opus, 48000, 64000, 480*2, codec_channels,
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000458 opus_pltype_);
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000459 Run(channel_a2b_, audio_channels, codec_channels);
460 // Run Opus with 40 ms frame size.
461 RegisterSendCodec('A', codec_opus, 48000, 64000, 480*4, codec_channels,
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000462 opus_pltype_);
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000463 Run(channel_a2b_, audio_channels, codec_channels);
464 // Run Opus with 60 ms frame size.
465 RegisterSendCodec('A', codec_opus, 48000, 64000, 480*6, codec_channels,
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000466 opus_pltype_);
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000467 Run(channel_a2b_, audio_channels, codec_channels);
468 // Run Opus with 20 ms frame size and different bitrates.
469 RegisterSendCodec('A', codec_opus, 48000, 40000, 960, codec_channels,
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000470 opus_pltype_);
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000471 Run(channel_a2b_, audio_channels, codec_channels);
472 RegisterSendCodec('A', codec_opus, 48000, 510000, 960, codec_channels,
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000473 opus_pltype_);
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000474 Run(channel_a2b_, audio_channels, codec_channels);
475 out_file_.Close();
476#endif
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000477 //
478 // Test Mono-To-Stereo for all codecs.
479 //
480 audio_channels = 1;
481 codec_channels = 2;
niklase@google.com470e71d2011-07-07 08:21:25 +0000482
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000483#ifdef WEBRTC_CODEC_G722
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000484 if (test_mode_ != 0) {
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000485 printf("===============================================================\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000486 printf("Test number: %d\n", test_cntr_ + 1);
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000487 printf("Test type: Mono-to-stereo\n");
488 }
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000489 test_cntr_++;
490 channel_a2b_->set_codec_mode(kStereo);
491 OpenOutFile(test_cntr_);
492 RegisterSendCodec('A', codec_g722, 16000, 64000, 160, codec_channels,
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000493 g722_pltype_);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000494 Run(channel_a2b_, audio_channels, codec_channels);
495 out_file_.Close();
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000496#endif
497#ifdef WEBRTC_CODEC_PCM16
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000498 if (test_mode_ != 0) {
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000499 printf("===============================================================\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000500 printf("Test number: %d\n", test_cntr_ + 1);
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000501 printf("Test type: Mono-to-stereo\n");
502 }
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000503 test_cntr_++;
504 channel_a2b_->set_codec_mode(kStereo);
505 OpenOutFile(test_cntr_);
506 RegisterSendCodec('A', codec_l16, 8000, 128000, 80, codec_channels,
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000507 l16_8khz_pltype_);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000508 Run(channel_a2b_, audio_channels, codec_channels);
509 out_file_.Close();
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000510 if (test_mode_ != 0) {
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000511 printf("===============================================================\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000512 printf("Test number: %d\n", test_cntr_ + 1);
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000513 printf("Test type: Mono-to-stereo\n");
514 }
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000515 test_cntr_++;
516 OpenOutFile(test_cntr_);
517 RegisterSendCodec('A', codec_l16, 16000, 256000, 160, codec_channels,
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000518 l16_16khz_pltype_);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000519 Run(channel_a2b_, audio_channels, codec_channels);
520 out_file_.Close();
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000521 if (test_mode_ != 0) {
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000522 printf("===============================================================\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000523 printf("Test number: %d\n", test_cntr_ + 1);
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000524 printf("Test type: Mono-to-stereo\n");
525 }
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000526 test_cntr_++;
527 OpenOutFile(test_cntr_);
528 RegisterSendCodec('A', codec_l16, 32000, 512000, 320, codec_channels,
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000529 l16_32khz_pltype_);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000530 Run(channel_a2b_, audio_channels, codec_channels);
531 out_file_.Close();
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000532#endif
533#ifdef PCMA_AND_PCMU
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000534 if (test_mode_ != 0) {
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000535 printf("===============================================================\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000536 printf("Test number: %d\n", test_cntr_ + 1);
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000537 printf("Test type: Mono-to-stereo\n");
538 }
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000539 test_cntr_++;
540 channel_a2b_->set_codec_mode(kStereo);
541 OpenOutFile(test_cntr_);
542 RegisterSendCodec('A', codec_pcmu, 8000, 64000, 80, codec_channels,
tina.legrand@webrtc.orgae1c4542012-03-12 08:41:30 +0000543 pcmu_pltype_);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000544 Run(channel_a2b_, audio_channels, codec_channels);
545 RegisterSendCodec('A', codec_pcma, 8000, 64000, 80, codec_channels,
tina.legrand@webrtc.orgae1c4542012-03-12 08:41:30 +0000546 pcma_pltype_);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000547 Run(channel_a2b_, audio_channels, codec_channels);
548 out_file_.Close();
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000549#endif
tina.legrand@webrtc.orgdf697752012-02-08 10:22:21 +0000550#ifdef WEBRTC_CODEC_CELT
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000551 if (test_mode_ != 0) {
tina.legrand@webrtc.orgdf697752012-02-08 10:22:21 +0000552 printf("===============================================================\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000553 printf("Test number: %d\n", test_cntr_ + 1);
tina.legrand@webrtc.orgdf697752012-02-08 10:22:21 +0000554 printf("Test type: Mono-to-stereo\n");
555 }
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000556 test_cntr_++;
557 channel_a2b_->set_codec_mode(kStereo);
558 OpenOutFile(test_cntr_);
tina.legrand@webrtc.org90af7f82012-06-07 08:57:27 +0000559 RegisterSendCodec('A', codec_celt, 32000, 64000, 640, codec_channels,
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000560 celt_pltype_);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000561 Run(channel_a2b_, audio_channels, codec_channels);
562 out_file_.Close();
tina.legrand@webrtc.orgdf697752012-02-08 10:22:21 +0000563#endif
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000564#ifdef WEBRTC_CODEC_OPUS
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000565 if (test_mode_ != 0) {
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000566 printf("===============================================================\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000567 printf("Test number: %d\n", test_cntr_ + 1);
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000568 printf("Test type: Mono-to-stereo\n");
569 }
tina.legrand@webrtc.orgc4590582012-11-28 12:23:29 +0000570
571 // Keep encode and decode in stereo.
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000572 test_cntr_++;
573 channel_a2b_->set_codec_mode(kStereo);
574 OpenOutFile(test_cntr_);
575 RegisterSendCodec('A', codec_opus, 48000, 64000, 960, codec_channels,
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000576 opus_pltype_);
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000577 Run(channel_a2b_, audio_channels, codec_channels);
tina.legrand@webrtc.orgc4590582012-11-28 12:23:29 +0000578
579 // Encode in mono, decode in stereo mode.
580 RegisterSendCodec('A', codec_opus, 48000, 64000, 960, 1, opus_pltype_);
581 Run(channel_a2b_, audio_channels, codec_channels);
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000582 out_file_.Close();
583#endif
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000584
585 //
586 // Test Stereo-To-Mono for all codecs.
587 //
588 audio_channels = 2;
589 codec_channels = 1;
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000590 channel_a2b_->set_codec_mode(kMono);
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000591
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000592#ifdef WEBRTC_CODEC_G722
593 // Run stereo audio and mono codec.
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");
598 }
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000599 test_cntr_++;
600 OpenOutFile(test_cntr_);
601 RegisterSendCodec('A', codec_g722, 16000, 64000, 160, codec_channels,
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000602 g722_pltype_);
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000603
604 // Make sure it is possible to set VAD/CNG, now that we are sending mono
605 // again.
606 EXPECT_EQ(0, acm_a_->SetVAD(true, true, VADNormal));
tina.legrand@webrtc.org7a7a0082013-02-21 10:27:48 +0000607 EXPECT_EQ(0, acm_a_->VAD(&dtx, &vad, &vad_mode));
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000608 EXPECT_TRUE(dtx);
609 EXPECT_TRUE(vad);
610 EXPECT_EQ(0, acm_a_->SetVAD(false, false, VADNormal));
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000611 Run(channel_a2b_, audio_channels, codec_channels);
612 out_file_.Close();
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000613#endif
614#ifdef WEBRTC_CODEC_PCM16
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000615 if (test_mode_ != 0) {
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000616 printf("===============================================================\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000617 printf("Test number: %d\n", test_cntr_ + 1);
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000618 printf("Test type: Stereo-to-mono\n");
619 }
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000620 test_cntr_++;
621 OpenOutFile(test_cntr_);
622 RegisterSendCodec('A', codec_l16, 8000, 128000, 80, codec_channels,
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000623 l16_8khz_pltype_);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000624 Run(channel_a2b_, audio_channels, codec_channels);
625 out_file_.Close();
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000626 if (test_mode_ != 0) {
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000627 printf("===============================================================\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000628 printf("Test number: %d\n", test_cntr_ + 1);
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000629 printf("Test type: Stereo-to-mono\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000630 }
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000631 test_cntr_++;
632 OpenOutFile(test_cntr_);
633 RegisterSendCodec('A', codec_l16, 16000, 256000, 160, codec_channels,
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000634 l16_16khz_pltype_);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000635 Run(channel_a2b_, audio_channels, codec_channels);
636 out_file_.Close();
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000637 if (test_mode_ != 0) {
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000638 printf("==============================================================\n");
639 printf("Test number: %d\n", test_cntr_ + 1);
640 printf("Test type: Stereo-to-mono\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000641 }
642 test_cntr_++;
643 OpenOutFile(test_cntr_);
644 RegisterSendCodec('A', codec_l16, 32000, 512000, 320, codec_channels,
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000645 l16_32khz_pltype_);
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000646 Run(channel_a2b_, audio_channels, codec_channels);
647 out_file_.Close();
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000648#endif
649#ifdef PCMA_AND_PCMU
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000650 if (test_mode_ != 0) {
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000651 printf("===============================================================\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000652 printf("Test number: %d\n", test_cntr_ + 1);
tina.legrand@webrtc.orgdf697752012-02-08 10:22:21 +0000653 printf("Test type: Stereo-to-mono\n");
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000654 }
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000655 test_cntr_++;
656 OpenOutFile(test_cntr_);
657 RegisterSendCodec('A', codec_pcmu, 8000, 64000, 80, codec_channels,
tina.legrand@webrtc.orgae1c4542012-03-12 08:41:30 +0000658 pcmu_pltype_);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000659 Run(channel_a2b_, audio_channels, codec_channels);
660 RegisterSendCodec('A', codec_pcma, 8000, 64000, 80, codec_channels,
tina.legrand@webrtc.orgae1c4542012-03-12 08:41:30 +0000661 pcma_pltype_);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000662 Run(channel_a2b_, audio_channels, codec_channels);
663 out_file_.Close();
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000664#endif
tina.legrand@webrtc.orgdf697752012-02-08 10:22:21 +0000665#ifdef WEBRTC_CODEC_CELT
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000666 if (test_mode_ != 0) {
tina.legrand@webrtc.orgdf697752012-02-08 10:22:21 +0000667 printf("===============================================================\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000668 printf("Test number: %d\n", test_cntr_ + 1);
tina.legrand@webrtc.orgdf697752012-02-08 10:22:21 +0000669 printf("Test type: Stereo-to-mono\n");
670 }
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000671 test_cntr_++;
672 OpenOutFile(test_cntr_);
tina.legrand@webrtc.org90af7f82012-06-07 08:57:27 +0000673 RegisterSendCodec('A', codec_celt, 32000, 64000, 640, codec_channels,
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000674 celt_pltype_);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000675 Run(channel_a2b_, audio_channels, codec_channels);
676 out_file_.Close();
tina.legrand@webrtc.orgdf697752012-02-08 10:22:21 +0000677#endif
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000678#ifdef WEBRTC_CODEC_OPUS
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000679 if (test_mode_ != 0) {
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000680 printf("===============================================================\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000681 printf("Test number: %d\n", test_cntr_ + 1);
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000682 printf("Test type: Stereo-to-mono\n");
683 }
684 test_cntr_++;
685 OpenOutFile(test_cntr_);
tina.legrand@webrtc.orgc4590582012-11-28 12:23:29 +0000686 // Encode and decode in mono.
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000687 RegisterSendCodec('A', codec_opus, 48000, 32000, 960, codec_channels,
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000688 opus_pltype_);
tina.legrand@webrtc.orgc4590582012-11-28 12:23:29 +0000689 CodecInst opus_codec_param;
pbos@webrtc.org0946a562013-04-09 00:28:06 +0000690 for (uint8_t n = 0; n < num_encoders; n++) {
tina.legrand@webrtc.org7a7a0082013-02-21 10:27:48 +0000691 EXPECT_EQ(0, acm_b_->Codec(n, &opus_codec_param));
tina.legrand@webrtc.orgc4590582012-11-28 12:23:29 +0000692 if (!strcmp(opus_codec_param.plname, "opus")) {
693 opus_codec_param.channels = 1;
694 EXPECT_EQ(0, acm_b_->RegisterReceiveCodec(opus_codec_param));
695 break;
696 }
697 }
698 Run(channel_a2b_, audio_channels, codec_channels);
699
700 // Encode in stereo, decode in mono.
701 RegisterSendCodec('A', codec_opus, 48000, 32000, 960, 2, opus_pltype_);
702 Run(channel_a2b_, audio_channels, codec_channels);
703
704 out_file_.Close();
705
706 // Test switching between decoding mono and stereo for Opus.
707
708 // Decode in mono.
709 test_cntr_++;
710 OpenOutFile(test_cntr_);
711 if (test_mode_ != 0) {
712 // Print out codec and settings
713 printf("Test number: %d\nCodec: Opus Freq: 48000 Rate :32000 PackSize: 960"
714 " Decode: mono\n", test_cntr_);
715 }
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000716 Run(channel_a2b_, audio_channels, codec_channels);
717 out_file_.Close();
tina.legrand@webrtc.orgc4590582012-11-28 12:23:29 +0000718 // Decode in stereo.
719 test_cntr_++;
720 OpenOutFile(test_cntr_);
721 if (test_mode_ != 0) {
722 // Print out codec and settings
723 printf("Test number: %d\nCodec: Opus Freq: 48000 Rate :32000 PackSize: 960"
724 " Decode: stereo\n", test_cntr_);
725 }
726 opus_codec_param.channels = 2;
727 EXPECT_EQ(0, acm_b_->RegisterReceiveCodec(opus_codec_param));
728 Run(channel_a2b_, audio_channels, 2);
729 out_file_.Close();
730 // Decode in mono.
731 test_cntr_++;
732 OpenOutFile(test_cntr_);
733 if (test_mode_ != 0) {
734 // Print out codec and settings
735 printf("Test number: %d\nCodec: Opus Freq: 48000 Rate :32000 PackSize: 960"
736 " Decode: mono\n", test_cntr_);
737 }
738 opus_codec_param.channels = 1;
739 EXPECT_EQ(0, acm_b_->RegisterReceiveCodec(opus_codec_param));
740 Run(channel_a2b_, audio_channels, codec_channels);
741 out_file_.Close();
742
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000743#endif
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000744
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000745 // Print out which codecs were tested, and which were not, in the run.
746 if (test_mode_ != 0) {
747 printf("\nThe following codecs was INCLUDED in the test:\n");
niklase@google.com470e71d2011-07-07 08:21:25 +0000748#ifdef WEBRTC_CODEC_G722
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000749 printf(" G.722\n");
niklase@google.com470e71d2011-07-07 08:21:25 +0000750#endif
751#ifdef WEBRTC_CODEC_PCM16
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000752 printf(" PCM16\n");
niklase@google.com470e71d2011-07-07 08:21:25 +0000753#endif
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000754 printf(" G.711\n");
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000755#ifdef WEBRTC_CODEC_CELT
756 printf(" CELT\n");
757#endif
tina.legrand@webrtc.orgc4590582012-11-28 12:23:29 +0000758#ifdef WEBRTC_CODEC_OPUS
759 printf(" Opus\n");
760#endif
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000761 printf("\nTo complete the test, listen to the %d number of output "
762 "files.\n",
763 test_cntr_);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000764 }
765
766 // Delete the file pointers.
767 delete in_file_stereo_;
768 delete in_file_mono_;
niklase@google.com470e71d2011-07-07 08:21:25 +0000769}
770
771// Register Codec to use in the test
772//
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000773// Input: side - which ACM to use, 'A' or 'B'
774// codec_name - name to use when register the codec
775// sampling_freq_hz - sampling frequency in Herz
776// rate - bitrate in bytes
777// pack_size - packet size in samples
778// channels - number of channels; 1 for mono, 2 for stereo
779// payload_type - payload type for the codec
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000780void TestStereo::RegisterSendCodec(char side, char* codec_name,
pbos@webrtc.org0946a562013-04-09 00:28:06 +0000781 int32_t sampling_freq_hz, int rate,
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000782 int pack_size, int channels,
783 int payload_type) {
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000784 if (test_mode_ != 0) {
785 // Print out codec and settings
tina.legrand@webrtc.orgba468042012-08-17 10:38:28 +0000786 printf("Codec: %s Freq: %d Rate: %d PackSize: %d\n", codec_name,
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000787 sampling_freq_hz, rate, pack_size);
788 }
789
790 // Store packet size in samples, used to validate the received packet
791 pack_size_samp_ = pack_size;
792
793 // Store the expected packet size in bytes, used to validate the received
794 // packet. Add 0.875 to always round up to a whole byte.
795 // For Celt the packet size in bytes is already counting the stereo part.
796 if (!strcmp(codec_name, "CELT")) {
pbos@webrtc.org0946a562013-04-09 00:28:06 +0000797 pack_size_bytes_ = (uint16_t)(
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000798 static_cast<float>(pack_size * rate) /
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000799 static_cast<float>(sampling_freq_hz * 8) + 0.875) / channels;
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000800 } else {
pbos@webrtc.org0946a562013-04-09 00:28:06 +0000801 pack_size_bytes_ = (uint16_t)(
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000802 static_cast<float>(pack_size * rate) /
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000803 static_cast<float>(sampling_freq_hz * 8) + 0.875);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000804 }
805
806 // Set pointer to the ACM where to register the codec
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000807 AudioCodingModule* my_acm = NULL;
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000808 switch (side) {
809 case 'A': {
810 my_acm = acm_a_;
811 break;
niklase@google.com470e71d2011-07-07 08:21:25 +0000812 }
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000813 case 'B': {
814 my_acm = acm_b_;
815 break;
tina.legrand@webrtc.org16b6b902012-04-12 11:02:38 +0000816 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000817 default:
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000818 break;
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000819 }
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000820 ASSERT_TRUE(my_acm != NULL);
niklase@google.com470e71d2011-07-07 08:21:25 +0000821
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000822 CodecInst my_codec_param;
823 // Get all codec parameters before registering
tina.legrand@webrtc.org7a7a0082013-02-21 10:27:48 +0000824 CHECK_ERROR(AudioCodingModule::Codec(codec_name, &my_codec_param,
tina.legrand@webrtc.org45175852012-06-01 09:27:35 +0000825 sampling_freq_hz, channels));
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000826 my_codec_param.rate = rate;
827 my_codec_param.pacsize = pack_size;
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000828 CHECK_ERROR(my_acm->RegisterSendCodec(my_codec_param));
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000829
830 send_codec_name_ = codec_name;
niklase@google.com470e71d2011-07-07 08:21:25 +0000831}
832
tina.legrand@webrtc.org16b6b902012-04-12 11:02:38 +0000833void TestStereo::Run(TestPackStereo* channel, int in_channels, int out_channels,
834 int percent_loss) {
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000835 AudioFrame audio_frame;
niklase@google.com470e71d2011-07-07 08:21:25 +0000836
pbos@webrtc.org0946a562013-04-09 00:28:06 +0000837 int32_t out_freq_hz_b = out_file_.SamplingFrequency();
838 uint16_t rec_size;
839 uint32_t time_stamp_diff;
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000840 channel->reset_payload_size();
841 int error_count = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000842
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000843 while (1) {
844 // Simulate packet loss by setting |packet_loss_| to "true" in
845 // |percent_loss| percent of the loops.
846 if (percent_loss > 0) {
847 if (counter_ == floor((100 / percent_loss) + 0.5)) {
848 counter_ = 0;
849 channel->set_lost_packet(true);
850 } else {
851 channel->set_lost_packet(false);
852 }
853 counter_++;
niklase@google.com470e71d2011-07-07 08:21:25 +0000854 }
855
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000856 // Add 10 msec to ACM
857 if (in_channels == 1) {
858 if (in_file_mono_->EndOfFile()) {
859 break;
860 }
861 in_file_mono_->Read10MsData(audio_frame);
862 } else {
863 if (in_file_stereo_->EndOfFile()) {
864 break;
865 }
866 in_file_stereo_->Read10MsData(audio_frame);
867 }
868 CHECK_ERROR(acm_a_->Add10MsData(audio_frame));
869
870 // Run sender side of ACM
871 CHECK_ERROR(acm_a_->Process());
872
873 // Verify that the received packet size matches the settings
874 rec_size = channel->payload_size();
875 if ((0 < rec_size) & (rec_size < 65535)) {
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000876 // Opus is variable rate, skip this test.
877 if (strcmp(send_codec_name_, "opus")) {
878 if ((rec_size != pack_size_bytes_ * out_channels)
879 && (pack_size_bytes_ < 65535)) {
880 error_count++;
881 }
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000882 }
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000883 // Verify that the timestamp is updated with expected length
884 time_stamp_diff = channel->timestamp_diff();
885 if ((counter_ > 10) && (time_stamp_diff != pack_size_samp_)) {
886 error_count++;
887 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000888 }
889
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000890 // Run received side of ACM
tina.legrand@webrtc.org7a7a0082013-02-21 10:27:48 +0000891 CHECK_ERROR(acm_b_->PlayoutData10Ms(out_freq_hz_b, &audio_frame));
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000892
893 // Write output speech to file
894 out_file_.Write10MsData(
andrew@webrtc.org63a50982012-05-02 23:56:37 +0000895 audio_frame.data_,
896 audio_frame.samples_per_channel_ * audio_frame.num_channels_);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000897 }
898
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000899 EXPECT_EQ(0, error_count);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000900
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000901 if (in_file_mono_->EndOfFile()) {
902 in_file_mono_->Rewind();
903 }
904 if (in_file_stereo_->EndOfFile()) {
905 in_file_stereo_->Rewind();
906 }
907 // Reset in case we ended with a lost packet
908 channel->set_lost_packet(false);
niklase@google.com470e71d2011-07-07 08:21:25 +0000909}
910
pbos@webrtc.org0946a562013-04-09 00:28:06 +0000911void TestStereo::OpenOutFile(int16_t test_number) {
tina.legrand@webrtc.orgba468042012-08-17 10:38:28 +0000912 std::string file_name;
913 std::stringstream file_stream;
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000914 file_stream << webrtc::test::OutputPath() << "teststereo_out_" << test_number
915 << ".pcm";
tina.legrand@webrtc.orgba468042012-08-17 10:38:28 +0000916 file_name = file_stream.str();
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000917 out_file_.Open(file_name, 32000, "wb");
niklase@google.com470e71d2011-07-07 08:21:25 +0000918}
919
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000920void TestStereo::DisplaySendReceiveCodec() {
921 CodecInst my_codec_param;
tina.legrand@webrtc.org7a7a0082013-02-21 10:27:48 +0000922 acm_a_->SendCodec(&my_codec_param);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000923 if (test_mode_ != 0) {
924 printf("%s -> ", my_codec_param.plname);
925 }
tina.legrand@webrtc.org7a7a0082013-02-21 10:27:48 +0000926 acm_b_->ReceiveCodec(&my_codec_param);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000927 if (test_mode_ != 0) {
928 printf("%s\n", my_codec_param.plname);
929 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000930}
931
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000932} // namespace webrtc