blob: 97d6c2ebdc14611f38260b525d0902d54b10ecad [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
11#include "TestStereo.h"
12
niklase@google.com470e71d2011-07-07 08:21:25 +000013#include <cassert>
kjellander@webrtc.org5490c712011-12-21 13:34:18 +000014#include <iostream>
15
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +000016#include "gtest/gtest.h"
17
kjellander@webrtc.org5490c712011-12-21 13:34:18 +000018#include "audio_coding_module_typedefs.h"
19#include "common_types.h"
20#include "engine_configurations.h"
21#include "testsupport/fileutils.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000022#include "trace.h"
kjellander@webrtc.org5490c712011-12-21 13:34:18 +000023#include "utility.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),
36 lost_packet_(false) {}
niklase@google.com470e71d2011-07-07 08:21:25 +000037
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +000038TestPackStereo::~TestPackStereo() {}
niklase@google.com470e71d2011-07-07 08:21:25 +000039
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +000040void TestPackStereo::RegisterReceiverACM(AudioCodingModule* acm) {
41 receiver_acm_ = acm;
42 return;
43}
niklase@google.com470e71d2011-07-07 08:21:25 +000044
tina.legrand@webrtc.org16b6b902012-04-12 11:02:38 +000045WebRtc_Word32 TestPackStereo::SendData(
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +000046 const FrameType frame_type,
47 const WebRtc_UWord8 payload_type,
48 const WebRtc_UWord32 timestamp,
49 const WebRtc_UWord8* payload_data,
50 const WebRtc_UWord16 payload_size,
tina.legrand@webrtc.org16b6b902012-04-12 11:02:38 +000051 const RTPFragmentationHeader* fragmentation) {
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +000052 WebRtcRTPHeader rtp_info;
tina.legrand@webrtc.org16b6b902012-04-12 11:02:38 +000053 WebRtc_Word32 status = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +000054
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +000055 rtp_info.header.markerBit = false;
56 rtp_info.header.ssrc = 0;
57 rtp_info.header.sequenceNumber = seq_no_++;
58 rtp_info.header.payloadType = payload_type;
59 rtp_info.header.timestamp = timestamp;
60 if (frame_type == kFrameEmpty) {
tina.legrand@webrtc.org16b6b902012-04-12 11:02:38 +000061 // Skip this frame
62 return 0;
63 }
niklase@google.com470e71d2011-07-07 08:21:25 +000064
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +000065 if (lost_packet_ == false) {
66 if (frame_type != kAudioFrameCN) {
67 rtp_info.type.Audio.isCNG = false;
68 rtp_info.type.Audio.channel = (int) codec_mode_;
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +000069 } else {
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +000070 rtp_info.type.Audio.isCNG = true;
71 rtp_info.type.Audio.channel = (int) kMono;
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +000072 }
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +000073 status = receiver_acm_->IncomingPacket(payload_data, payload_size,
tina.legrand@webrtc.org45175852012-06-01 09:27:35 +000074 rtp_info);
niklase@google.com470e71d2011-07-07 08:21:25 +000075
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +000076 if (frame_type != kAudioFrameCN) {
77 payload_size_ = payload_size;
niklase@google.com470e71d2011-07-07 08:21:25 +000078 } else {
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +000079 payload_size_ = -1;
niklase@google.com470e71d2011-07-07 08:21:25 +000080 }
tina.legrand@webrtc.org16b6b902012-04-12 11:02:38 +000081
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +000082 timestamp_diff_ = timestamp - last_in_timestamp_;
83 last_in_timestamp_ = timestamp;
84 total_bytes_ += payload_size;
tina.legrand@webrtc.org16b6b902012-04-12 11:02:38 +000085 }
86 return status;
niklase@google.com470e71d2011-07-07 08:21:25 +000087}
88
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +000089WebRtc_UWord16 TestPackStereo::payload_size() {
90 return payload_size_;
niklase@google.com470e71d2011-07-07 08:21:25 +000091}
92
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +000093WebRtc_UWord32 TestPackStereo::timestamp_diff() {
94 return timestamp_diff_;
niklase@google.com470e71d2011-07-07 08:21:25 +000095}
96
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +000097void TestPackStereo::reset_payload_size() {
98 payload_size_ = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +000099}
100
tina.legrand@webrtc.org16b6b902012-04-12 11:02:38 +0000101void TestPackStereo::set_codec_mode(enum StereoMonoMode mode) {
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000102 codec_mode_ = mode;
tina.legrand@webrtc.org16b6b902012-04-12 11:02:38 +0000103}
104
105void TestPackStereo::set_lost_packet(bool lost) {
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000106 lost_packet_ = lost;
niklase@google.com470e71d2011-07-07 08:21:25 +0000107}
108
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000109TestStereo::TestStereo(int test_mode)
110 : acm_a_(NULL),
111 acm_b_(NULL),
112 channel_a2b_(NULL),
113 test_cntr_(0),
114 pack_size_samp_(0),
115 pack_size_bytes_(0),
116 counter_(0),
117 g722_pltype_(0),
118 l16_8khz_pltype_(-1),
119 l16_16khz_pltype_(-1),
120 l16_32khz_pltype_(-1),
121 pcma_pltype_(-1),
122 pcmu_pltype_(-1),
123 celt_pltype_(-1),
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000124 opus_pltype_(-1),
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000125 cn_8khz_pltype_(-1),
126 cn_16khz_pltype_(-1),
127 cn_32khz_pltype_(-1) {
tina.legrand@webrtc.org45175852012-06-01 09:27:35 +0000128 // test_mode = 0 for silent test (auto test)
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000129 test_mode_ = test_mode;
niklase@google.com470e71d2011-07-07 08:21:25 +0000130}
131
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000132TestStereo::~TestStereo() {
133 if (acm_a_ != NULL) {
134 AudioCodingModule::Destroy(acm_a_);
135 acm_a_ = NULL;
136 }
137 if (acm_b_ != NULL) {
138 AudioCodingModule::Destroy(acm_b_);
139 acm_b_ = NULL;
140 }
141 if (channel_a2b_ != NULL) {
142 delete channel_a2b_;
143 channel_a2b_ = NULL;
144 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000145}
146
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000147void TestStereo::Perform() {
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000148 WebRtc_UWord16 frequency_hz;
149 int audio_channels;
150 int codec_channels;
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000151 bool dtx;
152 bool vad;
153 ACMVADMode vad_mode;
niklase@google.com470e71d2011-07-07 08:21:25 +0000154
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000155 if (test_mode_ == 0) {
156 printf("Running Stereo Test");
157 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioCoding, -1,
158 "---------- TestStereo ----------");
159 }
160
tina.legrand@webrtc.org45175852012-06-01 09:27:35 +0000161 // Open both mono and stereo test files in 32 kHz.
tina.legrand@webrtc.orgba468042012-08-17 10:38:28 +0000162 const std::string file_name_stereo =
163 webrtc::test::ResourcePath("audio_coding/teststereo32kHz", "pcm");
164 const std::string file_name_mono =
165 webrtc::test::ResourcePath("audio_coding/testfile32kHz", "pcm");
tina.legrand@webrtc.org45175852012-06-01 09:27:35 +0000166 frequency_hz = 32000;
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000167 in_file_stereo_ = new PCMFile();
168 in_file_mono_ = new PCMFile();
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000169 in_file_stereo_->Open(file_name_stereo, frequency_hz, "rb");
170 in_file_stereo_->ReadStereo(true);
171 in_file_mono_->Open(file_name_mono, frequency_hz, "rb");
172 in_file_mono_->ReadStereo(false);
173
tina.legrand@webrtc.org45175852012-06-01 09:27:35 +0000174 // Create and initialize two ACMs, one for each side of a one-to-one call.
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000175 acm_a_ = AudioCodingModule::Create(0);
176 acm_b_ = AudioCodingModule::Create(1);
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000177 ASSERT_TRUE((acm_a_ != NULL) && (acm_b_ != NULL));
178 EXPECT_EQ(0, acm_a_->InitializeReceiver());
179 EXPECT_EQ(0, acm_b_->InitializeReceiver());
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000180
tina.legrand@webrtc.org45175852012-06-01 09:27:35 +0000181 // Register all available codes as receiving codecs.
182 WebRtc_UWord8 num_encoders = acm_a_->NumberOfCodecs();
183 CodecInst my_codec_param;
184 for (WebRtc_UWord8 n = 0; n < num_encoders; n++) {
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000185 EXPECT_EQ(0, acm_b_->Codec(n, my_codec_param));
186 EXPECT_EQ(0, acm_b_->RegisterReceiveCodec(my_codec_param));
tina.legrand@webrtc.org45175852012-06-01 09:27:35 +0000187 }
188
189 // Test that unregister all receive codecs works.
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000190 for (WebRtc_UWord8 n = 0; n < num_encoders; n++) {
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000191 EXPECT_EQ(0, acm_b_->Codec(n, my_codec_param));
192 EXPECT_EQ(0, acm_b_->UnregisterReceiveCodec(my_codec_param.pltype));
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000193 }
tina.legrand@webrtc.orgae1c4542012-03-12 08:41:30 +0000194
tina.legrand@webrtc.org45175852012-06-01 09:27:35 +0000195 // Register all available codes as receiving codecs once more.
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000196 for (WebRtc_UWord8 n = 0; n < num_encoders; n++) {
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000197 EXPECT_EQ(0, acm_b_->Codec(n, my_codec_param));
198 EXPECT_EQ(0, acm_b_->RegisterReceiveCodec(my_codec_param));
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000199 }
tina.legrand@webrtc.orgae1c4542012-03-12 08:41:30 +0000200
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000201 // TODO(tlegrand): Take care of return values of all function calls.
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000202
tina.legrand@webrtc.org45175852012-06-01 09:27:35 +0000203 // TODO(tlegrand): Re-register all stereo codecs needed in the test,
204 // with new payload numbers.
205 // g722_pltype_ = 117;
206 // l16_8khz_pltype_ = 120;
207 // l16_16khz_pltype_ = 121;
208 // l16_32khz_pltype_ = 122;
209 // pcma_pltype_ = 110;
210 // pcmu_pltype_ = 118;
211 // celt_pltype_ = 119;
212 // cn_8khz_pltype_ = 123;
213 // cn_16khz_pltype_ = 124;
214 // cn_32khz_pltype_ = 125;
tina.legrand@webrtc.orgae1c4542012-03-12 08:41:30 +0000215
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000216 // Create and connect the channel.
217 channel_a2b_ = new TestPackStereo;
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000218 EXPECT_EQ(0, acm_a_->RegisterTransportCallback(channel_a2b_));
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000219 channel_a2b_->RegisterReceiverACM(acm_b_);
tina.legrand@webrtc.orgdf697752012-02-08 10:22:21 +0000220
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000221 // Start with setting VAD/DTX, before we know we will send stereo.
222 // Continue with setting a stereo codec as send codec and verify that
223 // VAD/DTX gets turned off.
224 EXPECT_EQ(0, acm_a_->SetVAD(true, true, VADNormal));
225 EXPECT_EQ(0, acm_a_->VAD(dtx, vad, vad_mode));
226 EXPECT_TRUE(dtx);
227 EXPECT_TRUE(vad);
228 char codec_pcma_temp[] = "PCMA";
229 RegisterSendCodec('A', codec_pcma_temp, 8000, 64000, 80, 2, pcma_pltype_);
230 EXPECT_EQ(0, acm_a_->VAD(dtx, vad, vad_mode));
231 EXPECT_FALSE(dtx);
232 EXPECT_FALSE(vad);
233 if(test_mode_ != 0) {
234 printf("\n");
235 }
236
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000237 //
238 // Test Stereo-To-Stereo for all codecs.
239 //
240 audio_channels = 2;
241 codec_channels = 2;
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000242
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000243 // All codecs are tested for all allowed sampling frequencies, rates and
244 // packet sizes.
niklase@google.com470e71d2011-07-07 08:21:25 +0000245#ifdef WEBRTC_CODEC_G722
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000246 if(test_mode_ != 0) {
247 printf("===========================================================\n");
248 printf("Test number: %d\n",test_cntr_ + 1);
249 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_g722[] = "G722";
255 RegisterSendCodec('A', codec_g722, 16000, 64000, 160, codec_channels,
256 g722_pltype_);
257 Run(channel_a2b_, audio_channels, codec_channels);
258 RegisterSendCodec('A', codec_g722, 16000, 64000, 320, codec_channels,
259 g722_pltype_);
260 Run(channel_a2b_, audio_channels, codec_channels);
261 RegisterSendCodec('A', codec_g722, 16000, 64000, 480, codec_channels,
262 g722_pltype_);
263 Run(channel_a2b_, audio_channels, codec_channels);
264 RegisterSendCodec('A', codec_g722, 16000, 64000, 640, codec_channels,
265 g722_pltype_);
266 Run(channel_a2b_, audio_channels, codec_channels);
267 RegisterSendCodec('A', codec_g722, 16000, 64000, 800, codec_channels,
268 g722_pltype_);
269 Run(channel_a2b_, audio_channels, codec_channels);
270 RegisterSendCodec('A', codec_g722, 16000, 64000, 960, codec_channels,
271 g722_pltype_);
272 Run(channel_a2b_, audio_channels, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000273 out_file_.Close();
niklase@google.com470e71d2011-07-07 08:21:25 +0000274#endif
275#ifdef WEBRTC_CODEC_PCM16
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000276 if(test_mode_ != 0) {
277 printf("===========================================================\n");
278 printf("Test number: %d\n",test_cntr_ + 1);
279 printf("Test type: Stereo-to-stereo\n");
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000280 }
281 channel_a2b_->set_codec_mode(kStereo);
282 test_cntr_++;
283 OpenOutFile(test_cntr_);
284 char codec_l16[] = "L16";
285 RegisterSendCodec('A', codec_l16, 8000, 128000, 80, codec_channels,
286 l16_8khz_pltype_);
287 Run(channel_a2b_, audio_channels, codec_channels);
288 RegisterSendCodec('A', codec_l16, 8000, 128000, 160, codec_channels,
289 l16_8khz_pltype_);
290 Run(channel_a2b_, audio_channels, codec_channels);
291 RegisterSendCodec('A', codec_l16, 8000, 128000, 240, codec_channels,
292 l16_8khz_pltype_);
293 Run(channel_a2b_, audio_channels, codec_channels);
294 RegisterSendCodec('A', codec_l16, 8000, 128000, 320, codec_channels,
295 l16_8khz_pltype_);
296 Run(channel_a2b_, audio_channels, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000297 out_file_.Close();
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000298
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000299 if(test_mode_ != 0) {
300 printf("===========================================================\n");
301 printf("Test number: %d\n",test_cntr_ + 1);
302 printf("Test type: Stereo-to-stereo\n");
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000303 }
304 test_cntr_++;
305 OpenOutFile(test_cntr_);
306 RegisterSendCodec('A', codec_l16, 16000, 256000, 160, codec_channels,
307 l16_16khz_pltype_);
308 Run(channel_a2b_, audio_channels, codec_channels);
309 RegisterSendCodec('A', codec_l16, 16000, 256000, 320, codec_channels,
310 l16_16khz_pltype_);
311 Run(channel_a2b_, audio_channels, codec_channels);
312 RegisterSendCodec('A', codec_l16, 16000, 256000, 480, codec_channels,
313 l16_16khz_pltype_);
314 Run(channel_a2b_, audio_channels, codec_channels);
315 RegisterSendCodec('A', codec_l16, 16000, 256000, 640, codec_channels,
316 l16_16khz_pltype_);
317 Run(channel_a2b_, audio_channels, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000318 out_file_.Close();
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000319
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000320 if(test_mode_ != 0) {
321 printf("===========================================================\n");
322 printf("Test number: %d\n",test_cntr_ + 1);
323 printf("Test type: Stereo-to-stereo\n");
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000324 }
325 test_cntr_++;
326 OpenOutFile(test_cntr_);
327 RegisterSendCodec('A', codec_l16, 32000, 512000, 320, codec_channels,
328 l16_32khz_pltype_);
329 Run(channel_a2b_, audio_channels, codec_channels);
330 RegisterSendCodec('A', codec_l16, 32000, 512000, 640, codec_channels,
331 l16_32khz_pltype_);
332 Run(channel_a2b_, audio_channels, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000333 out_file_.Close();
niklase@google.com470e71d2011-07-07 08:21:25 +0000334#endif
335#define PCMA_AND_PCMU
336#ifdef PCMA_AND_PCMU
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000337 if (test_mode_ != 0) {
338 printf("===========================================================\n");
339 printf("Test number: %d\n", test_cntr_ + 1);
340 printf("Test type: Stereo-to-stereo\n");
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000341 }
342 channel_a2b_->set_codec_mode(kStereo);
343 audio_channels = 2;
344 codec_channels = 2;
345 test_cntr_++;
346 OpenOutFile(test_cntr_);
347 char codec_pcma[] = "PCMA";
348 RegisterSendCodec('A', codec_pcma, 8000, 64000, 80, codec_channels,
349 pcma_pltype_);
350 Run(channel_a2b_, audio_channels, codec_channels);
351 RegisterSendCodec('A', codec_pcma, 8000, 64000, 160, codec_channels,
352 pcma_pltype_);
353 Run(channel_a2b_, audio_channels, codec_channels);
354 RegisterSendCodec('A', codec_pcma, 8000, 64000, 240, codec_channels,
355 pcma_pltype_);
356 Run(channel_a2b_, audio_channels, codec_channels);
357 RegisterSendCodec('A', codec_pcma, 8000, 64000, 320, codec_channels,
358 pcma_pltype_);
359 Run(channel_a2b_, audio_channels, codec_channels);
360 RegisterSendCodec('A', codec_pcma, 8000, 64000, 400, codec_channels,
361 pcma_pltype_);
362 Run(channel_a2b_, audio_channels, codec_channels);
363 RegisterSendCodec('A', codec_pcma, 8000, 64000, 480, codec_channels,
364 pcma_pltype_);
365 Run(channel_a2b_, audio_channels, codec_channels);
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000366
367 // Test that VAD/DTX cannot be turned on while sending stereo.
368 EXPECT_EQ(-1, acm_a_->SetVAD(true, true, VADNormal));
369 EXPECT_EQ(0, acm_a_->VAD(dtx, vad, vad_mode));
370 EXPECT_FALSE(dtx);
371 EXPECT_FALSE(vad);
372 EXPECT_EQ(-1, acm_a_->SetVAD(true, false, VADNormal));
373 EXPECT_EQ(0, acm_a_->VAD(dtx, vad, vad_mode));
374 EXPECT_FALSE(dtx);
375 EXPECT_FALSE(vad);
376 EXPECT_EQ(-1, acm_a_->SetVAD(false, true, VADNormal));
377 EXPECT_EQ(0, acm_a_->VAD(dtx, vad, vad_mode));
378 EXPECT_FALSE(dtx);
379 EXPECT_FALSE(vad);
380 EXPECT_EQ(0, acm_a_->SetVAD(false, false, VADNormal));
381 EXPECT_EQ(0, acm_a_->VAD(dtx, vad, vad_mode));
382 EXPECT_FALSE(dtx);
383 EXPECT_FALSE(vad);
384
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000385 out_file_.Close();
386 if (test_mode_ != 0) {
387 printf("===========================================================\n");
388 printf("Test number: %d\n", test_cntr_ + 1);
389 printf("Test type: Stereo-to-stereo\n");
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000390 }
391 test_cntr_++;
392 OpenOutFile(test_cntr_);
393 char codec_pcmu[] = "PCMU";
394 RegisterSendCodec('A', codec_pcmu, 8000, 64000, 80, codec_channels,
395 pcmu_pltype_);
396 Run(channel_a2b_, audio_channels, codec_channels);
397 RegisterSendCodec('A', codec_pcmu, 8000, 64000, 160, codec_channels,
398 pcmu_pltype_);
399 Run(channel_a2b_, audio_channels, codec_channels);
400 RegisterSendCodec('A', codec_pcmu, 8000, 64000, 240, codec_channels,
401 pcmu_pltype_);
402 Run(channel_a2b_, audio_channels, codec_channels);
403 RegisterSendCodec('A', codec_pcmu, 8000, 64000, 320, codec_channels,
404 pcmu_pltype_);
405 Run(channel_a2b_, audio_channels, codec_channels);
406 RegisterSendCodec('A', codec_pcmu, 8000, 64000, 400, codec_channels,
407 pcmu_pltype_);
408 Run(channel_a2b_, audio_channels, codec_channels);
409 RegisterSendCodec('A', codec_pcmu, 8000, 64000, 480, codec_channels,
410 pcmu_pltype_);
411 Run(channel_a2b_, audio_channels, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000412 out_file_.Close();
niklase@google.com470e71d2011-07-07 08:21:25 +0000413#endif
tina.legrand@webrtc.orgdf697752012-02-08 10:22:21 +0000414#ifdef WEBRTC_CODEC_CELT
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000415 if(test_mode_ != 0) {
416 printf("===========================================================\n");
417 printf("Test number: %d\n",test_cntr_ + 1);
418 printf("Test type: Stereo-to-stereo\n");
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000419 }
420 channel_a2b_->set_codec_mode(kStereo);
421 audio_channels = 2;
422 codec_channels = 2;
423 test_cntr_++;
424 OpenOutFile(test_cntr_);
425 char codec_celt[] = "CELT";
tina.legrand@webrtc.org90af7f82012-06-07 08:57:27 +0000426 RegisterSendCodec('A', codec_celt, 32000, 48000, 640, codec_channels,
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000427 celt_pltype_);
428 Run(channel_a2b_, audio_channels, codec_channels);
tina.legrand@webrtc.org90af7f82012-06-07 08:57:27 +0000429 RegisterSendCodec('A', codec_celt, 32000, 64000, 640, codec_channels,
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000430 celt_pltype_);
431 Run(channel_a2b_, audio_channels, codec_channels);
tina.legrand@webrtc.org90af7f82012-06-07 08:57:27 +0000432 RegisterSendCodec('A', codec_celt, 32000, 128000, 640, codec_channels,
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000433 celt_pltype_);
434 Run(channel_a2b_, audio_channels, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000435 out_file_.Close();
tina.legrand@webrtc.orgdf697752012-02-08 10:22:21 +0000436#endif
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000437#ifdef WEBRTC_CODEC_OPUS
438 if(test_mode_ != 0) {
439 printf("===========================================================\n");
440 printf("Test number: %d\n",test_cntr_ + 1);
441 printf("Test type: Stereo-to-stereo\n");
442 }
443 channel_a2b_->set_codec_mode(kStereo);
444 audio_channels = 2;
445 codec_channels = 2;
446 test_cntr_++;
447 OpenOutFile(test_cntr_);
448 char codec_opus[] = "opus";
449 RegisterSendCodec('A', codec_opus, 48000, 40000, 960, codec_channels,
450 opus_pltype_);
451 Run(channel_a2b_, audio_channels, codec_channels);
452 RegisterSendCodec('A', codec_opus, 48000, 64000, 960, codec_channels,
453 opus_pltype_);
454 Run(channel_a2b_, audio_channels, codec_channels);
455 RegisterSendCodec('A', codec_opus, 48000, 510000, 960, codec_channels,
456 opus_pltype_);
457 Run(channel_a2b_, audio_channels, codec_channels);
458 out_file_.Close();
459#endif
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000460 //
461 // Test Mono-To-Stereo for all codecs.
462 //
463 audio_channels = 1;
464 codec_channels = 2;
niklase@google.com470e71d2011-07-07 08:21:25 +0000465
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000466#ifdef WEBRTC_CODEC_G722
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000467 if(test_mode_ != 0) {
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000468 printf("===============================================================\n");
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000469 printf("Test number: %d\n",test_cntr_ + 1);
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000470 printf("Test type: Mono-to-stereo\n");
471 }
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000472 test_cntr_++;
473 channel_a2b_->set_codec_mode(kStereo);
474 OpenOutFile(test_cntr_);
475 RegisterSendCodec('A', codec_g722, 16000, 64000, 160, codec_channels,
tina.legrand@webrtc.orgae1c4542012-03-12 08:41:30 +0000476 g722_pltype_);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000477 Run(channel_a2b_, audio_channels, codec_channels);
478 out_file_.Close();
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000479#endif
480#ifdef WEBRTC_CODEC_PCM16
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000481 if(test_mode_ != 0) {
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000482 printf("===============================================================\n");
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000483 printf("Test number: %d\n",test_cntr_ + 1);
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000484 printf("Test type: Mono-to-stereo\n");
485 }
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000486 test_cntr_++;
487 channel_a2b_->set_codec_mode(kStereo);
488 OpenOutFile(test_cntr_);
489 RegisterSendCodec('A', codec_l16, 8000, 128000, 80, codec_channels,
tina.legrand@webrtc.orgae1c4542012-03-12 08:41:30 +0000490 l16_8khz_pltype_);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000491 Run(channel_a2b_, audio_channels, codec_channels);
492 out_file_.Close();
493 if(test_mode_ != 0) {
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000494 printf("===============================================================\n");
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000495 printf("Test number: %d\n",test_cntr_ + 1);
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000496 printf("Test type: Mono-to-stereo\n");
497 }
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000498 test_cntr_++;
499 OpenOutFile(test_cntr_);
500 RegisterSendCodec('A', codec_l16, 16000, 256000, 160, codec_channels,
tina.legrand@webrtc.orgae1c4542012-03-12 08:41:30 +0000501 l16_16khz_pltype_);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000502 Run(channel_a2b_, audio_channels, codec_channels);
503 out_file_.Close();
504 if(test_mode_ != 0) {
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000505 printf("===============================================================\n");
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000506 printf("Test number: %d\n",test_cntr_ + 1);
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000507 printf("Test type: Mono-to-stereo\n");
508 }
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000509 test_cntr_++;
510 OpenOutFile(test_cntr_);
511 RegisterSendCodec('A', codec_l16, 32000, 512000, 320, codec_channels,
tina.legrand@webrtc.orgae1c4542012-03-12 08:41:30 +0000512 l16_32khz_pltype_);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000513 Run(channel_a2b_, audio_channels, codec_channels);
514 out_file_.Close();
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000515#endif
516#ifdef PCMA_AND_PCMU
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000517 if(test_mode_ != 0) {
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000518 printf("===============================================================\n");
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000519 printf("Test number: %d\n",test_cntr_ + 1);
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000520 printf("Test type: Mono-to-stereo\n");
521 }
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000522 test_cntr_++;
523 channel_a2b_->set_codec_mode(kStereo);
524 OpenOutFile(test_cntr_);
525 RegisterSendCodec('A', codec_pcmu, 8000, 64000, 80, codec_channels,
tina.legrand@webrtc.orgae1c4542012-03-12 08:41:30 +0000526 pcmu_pltype_);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000527 Run(channel_a2b_, audio_channels, codec_channels);
528 RegisterSendCodec('A', codec_pcma, 8000, 64000, 80, codec_channels,
tina.legrand@webrtc.orgae1c4542012-03-12 08:41:30 +0000529 pcma_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
tina.legrand@webrtc.orgdf697752012-02-08 10:22:21 +0000533#ifdef WEBRTC_CODEC_CELT
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000534 if(test_mode_ != 0) {
tina.legrand@webrtc.orgdf697752012-02-08 10:22:21 +0000535 printf("===============================================================\n");
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000536 printf("Test number: %d\n",test_cntr_ + 1);
tina.legrand@webrtc.orgdf697752012-02-08 10:22:21 +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_);
tina.legrand@webrtc.org90af7f82012-06-07 08:57:27 +0000542 RegisterSendCodec('A', codec_celt, 32000, 64000, 640, codec_channels,
tina.legrand@webrtc.orgae1c4542012-03-12 08:41:30 +0000543 celt_pltype_);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000544 Run(channel_a2b_, audio_channels, codec_channels);
545 out_file_.Close();
tina.legrand@webrtc.orgdf697752012-02-08 10:22:21 +0000546#endif
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000547#ifdef WEBRTC_CODEC_OPUS
548 if(test_mode_ != 0) {
549 printf("===============================================================\n");
550 printf("Test number: %d\n",test_cntr_ + 1);
551 printf("Test type: Mono-to-stereo\n");
552 }
553 test_cntr_++;
554 channel_a2b_->set_codec_mode(kStereo);
555 OpenOutFile(test_cntr_);
556 RegisterSendCodec('A', codec_opus, 48000, 64000, 960, codec_channels,
557 opus_pltype_);
558 Run(channel_a2b_, audio_channels, codec_channels);
559 out_file_.Close();
560#endif
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000561
562 //
563 // Test Stereo-To-Mono for all codecs.
564 //
565 audio_channels = 2;
566 codec_channels = 1;
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000567 channel_a2b_->set_codec_mode(kMono);
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000568
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000569#ifdef WEBRTC_CODEC_G722
570 // Run stereo audio and mono codec.
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000571 if(test_mode_ != 0) {
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000572 printf("===============================================================\n");
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000573 printf("Test number: %d\n",test_cntr_ + 1);
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000574 printf("Test type: Stereo-to-mono\n");
575 }
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000576 test_cntr_++;
577 OpenOutFile(test_cntr_);
578 RegisterSendCodec('A', codec_g722, 16000, 64000, 160, codec_channels,
tina.legrand@webrtc.orgae1c4542012-03-12 08:41:30 +0000579 g722_pltype_);
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000580
581
582 // Make sure it is possible to set VAD/CNG, now that we are sending mono
583 // again.
584 EXPECT_EQ(0, acm_a_->SetVAD(true, true, VADNormal));
585 EXPECT_EQ(0, acm_a_->VAD(dtx, vad, vad_mode));
586 EXPECT_TRUE(dtx);
587 EXPECT_TRUE(vad);
588 EXPECT_EQ(0, acm_a_->SetVAD(false, false, VADNormal));
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000589 Run(channel_a2b_, audio_channels, codec_channels);
590 out_file_.Close();
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000591#endif
592#ifdef WEBRTC_CODEC_PCM16
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000593 if(test_mode_ != 0) {
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000594 printf("===============================================================\n");
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000595 printf("Test number: %d\n",test_cntr_ + 1);
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000596 printf("Test type: Stereo-to-mono\n");
597 }
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000598 test_cntr_++;
599 OpenOutFile(test_cntr_);
600 RegisterSendCodec('A', codec_l16, 8000, 128000, 80, codec_channels,
tina.legrand@webrtc.orgae1c4542012-03-12 08:41:30 +0000601 l16_8khz_pltype_);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000602 Run(channel_a2b_, audio_channels, codec_channels);
603 out_file_.Close();
604 if(test_mode_ != 0) {
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000605 printf("===============================================================\n");
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000606 printf("Test number: %d\n",test_cntr_ + 1);
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000607 printf("Test type: Stereo-to-mono\n");
608 }
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000609 test_cntr_++;
610 OpenOutFile(test_cntr_);
611 RegisterSendCodec('A', codec_l16, 16000, 256000, 160, codec_channels,
tina.legrand@webrtc.orgae1c4542012-03-12 08:41:30 +0000612 l16_16khz_pltype_);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000613 Run(channel_a2b_, audio_channels, codec_channels);
614 out_file_.Close();
615 if(test_mode_ != 0) {
tina.legrand@webrtc.org16b6b902012-04-12 11:02:38 +0000616 printf("==============================================================\n");
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000617 printf("Test number: %d\n",test_cntr_ + 1);
tina.legrand@webrtc.orgdf697752012-02-08 10:22:21 +0000618 printf("Test type: Stereo-to-mono\n");
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000619 }
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000620 test_cntr_++;
621 OpenOutFile(test_cntr_);
622 RegisterSendCodec('A', codec_l16, 32000, 512000, 320, codec_channels,
tina.legrand@webrtc.orgae1c4542012-03-12 08:41:30 +0000623 l16_32khz_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.org6b6ff552012-01-11 10:12:54 +0000626#endif
627#ifdef PCMA_AND_PCMU
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000628 if(test_mode_ != 0) {
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000629 printf("===============================================================\n");
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000630 printf("Test number: %d\n",test_cntr_ + 1);
tina.legrand@webrtc.orgdf697752012-02-08 10:22:21 +0000631 printf("Test type: Stereo-to-mono\n");
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000632 }
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000633 test_cntr_++;
634 OpenOutFile(test_cntr_);
635 RegisterSendCodec('A', codec_pcmu, 8000, 64000, 80, codec_channels,
tina.legrand@webrtc.orgae1c4542012-03-12 08:41:30 +0000636 pcmu_pltype_);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000637 Run(channel_a2b_, audio_channels, codec_channels);
638 RegisterSendCodec('A', codec_pcma, 8000, 64000, 80, codec_channels,
tina.legrand@webrtc.orgae1c4542012-03-12 08:41:30 +0000639 pcma_pltype_);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000640 Run(channel_a2b_, audio_channels, codec_channels);
641 out_file_.Close();
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000642#endif
tina.legrand@webrtc.orgdf697752012-02-08 10:22:21 +0000643#ifdef WEBRTC_CODEC_CELT
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000644 if(test_mode_ != 0) {
tina.legrand@webrtc.orgdf697752012-02-08 10:22:21 +0000645 printf("===============================================================\n");
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000646 printf("Test number: %d\n",test_cntr_ + 1);
tina.legrand@webrtc.orgdf697752012-02-08 10:22:21 +0000647 printf("Test type: Stereo-to-mono\n");
648 }
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000649 test_cntr_++;
650 OpenOutFile(test_cntr_);
tina.legrand@webrtc.org90af7f82012-06-07 08:57:27 +0000651 RegisterSendCodec('A', codec_celt, 32000, 64000, 640, codec_channels,
tina.legrand@webrtc.orgae1c4542012-03-12 08:41:30 +0000652 celt_pltype_);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000653 Run(channel_a2b_, audio_channels, codec_channels);
654 out_file_.Close();
tina.legrand@webrtc.orgdf697752012-02-08 10:22:21 +0000655#endif
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000656#ifdef WEBRTC_CODEC_OPUS
657 if(test_mode_ != 0) {
658 printf("===============================================================\n");
659 printf("Test number: %d\n",test_cntr_ + 1);
660 printf("Test type: Stereo-to-mono\n");
661 }
662 test_cntr_++;
663 OpenOutFile(test_cntr_);
664 RegisterSendCodec('A', codec_opus, 48000, 32000, 960, codec_channels,
665 opus_pltype_);
666 Run(channel_a2b_, audio_channels, codec_channels);
667 out_file_.Close();
668#endif
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000669
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000670 // Print out which codecs were tested, and which were not, in the run.
671 if (test_mode_ != 0) {
672 printf("\nThe following codecs was INCLUDED in the test:\n");
niklase@google.com470e71d2011-07-07 08:21:25 +0000673#ifdef WEBRTC_CODEC_G722
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000674 printf(" G.722\n");
niklase@google.com470e71d2011-07-07 08:21:25 +0000675#endif
676#ifdef WEBRTC_CODEC_PCM16
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000677 printf(" PCM16\n");
niklase@google.com470e71d2011-07-07 08:21:25 +0000678#endif
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000679 printf(" G.711\n");
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000680#ifdef WEBRTC_CODEC_CELT
681 printf(" CELT\n");
682#endif
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000683 printf("\nTo complete the test, listen to the %d number of output "
684 "files.\n",
685 test_cntr_);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000686 }
687
688 // Delete the file pointers.
689 delete in_file_stereo_;
690 delete in_file_mono_;
niklase@google.com470e71d2011-07-07 08:21:25 +0000691}
692
693// Register Codec to use in the test
694//
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000695// Input: side - which ACM to use, 'A' or 'B'
696// codec_name - name to use when register the codec
697// sampling_freq_hz - sampling frequency in Herz
698// rate - bitrate in bytes
699// pack_size - packet size in samples
700// channels - number of channels; 1 for mono, 2 for stereo
701// payload_type - payload type for the codec
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000702void TestStereo::RegisterSendCodec(char side, char* codec_name,
703 WebRtc_Word32 sampling_freq_hz, int rate,
704 int pack_size, int channels,
705 int payload_type) {
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000706 if (test_mode_ != 0) {
707 // Print out codec and settings
tina.legrand@webrtc.orgba468042012-08-17 10:38:28 +0000708 printf("Codec: %s Freq: %d Rate: %d PackSize: %d\n", codec_name,
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000709 sampling_freq_hz, rate, pack_size);
710 }
711
712 // Store packet size in samples, used to validate the received packet
713 pack_size_samp_ = pack_size;
714
715 // Store the expected packet size in bytes, used to validate the received
716 // packet. Add 0.875 to always round up to a whole byte.
717 // For Celt the packet size in bytes is already counting the stereo part.
718 if (!strcmp(codec_name, "CELT")) {
719 pack_size_bytes_ = (WebRtc_UWord16)(
720 (float) (pack_size * rate) / (float) (sampling_freq_hz * 8) + 0.875)
721 / channels;
722 } else {
723 pack_size_bytes_ = (WebRtc_UWord16)(
724 (float) (pack_size * rate) / (float) (sampling_freq_hz * 8) + 0.875);
725 }
726
727 // Set pointer to the ACM where to register the codec
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000728 AudioCodingModule* my_acm = NULL;
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000729 switch (side) {
730 case 'A': {
731 my_acm = acm_a_;
732 break;
niklase@google.com470e71d2011-07-07 08:21:25 +0000733 }
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000734 case 'B': {
735 my_acm = acm_b_;
736 break;
tina.legrand@webrtc.org16b6b902012-04-12 11:02:38 +0000737 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000738 default:
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000739 break;
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000740 }
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000741 ASSERT_TRUE(my_acm != NULL);
niklase@google.com470e71d2011-07-07 08:21:25 +0000742
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000743 CodecInst my_codec_param;
744 // Get all codec parameters before registering
745 CHECK_ERROR(AudioCodingModule::Codec(codec_name, my_codec_param,
tina.legrand@webrtc.org45175852012-06-01 09:27:35 +0000746 sampling_freq_hz, channels));
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000747 my_codec_param.rate = rate;
748 my_codec_param.pacsize = pack_size;
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000749 CHECK_ERROR(my_acm->RegisterSendCodec(my_codec_param));
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000750
751 send_codec_name_ = codec_name;
niklase@google.com470e71d2011-07-07 08:21:25 +0000752}
753
tina.legrand@webrtc.org16b6b902012-04-12 11:02:38 +0000754void TestStereo::Run(TestPackStereo* channel, int in_channels, int out_channels,
755 int percent_loss) {
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000756 AudioFrame audio_frame;
niklase@google.com470e71d2011-07-07 08:21:25 +0000757
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000758 WebRtc_Word32 out_freq_hz_b = out_file_.SamplingFrequency();
759 WebRtc_UWord16 rec_size;
760 WebRtc_UWord32 time_stamp_diff;
761 channel->reset_payload_size();
762 int error_count = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000763
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000764 while (1) {
765 // Simulate packet loss by setting |packet_loss_| to "true" in
766 // |percent_loss| percent of the loops.
767 if (percent_loss > 0) {
768 if (counter_ == floor((100 / percent_loss) + 0.5)) {
769 counter_ = 0;
770 channel->set_lost_packet(true);
771 } else {
772 channel->set_lost_packet(false);
773 }
774 counter_++;
niklase@google.com470e71d2011-07-07 08:21:25 +0000775 }
776
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000777 // Add 10 msec to ACM
778 if (in_channels == 1) {
779 if (in_file_mono_->EndOfFile()) {
780 break;
781 }
782 in_file_mono_->Read10MsData(audio_frame);
783 } else {
784 if (in_file_stereo_->EndOfFile()) {
785 break;
786 }
787 in_file_stereo_->Read10MsData(audio_frame);
788 }
789 CHECK_ERROR(acm_a_->Add10MsData(audio_frame));
790
791 // Run sender side of ACM
792 CHECK_ERROR(acm_a_->Process());
793
794 // Verify that the received packet size matches the settings
795 rec_size = channel->payload_size();
796 if ((0 < rec_size) & (rec_size < 65535)) {
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000797 // Opus is variable rate, skip this test.
798 if (strcmp(send_codec_name_, "opus")) {
799 if ((rec_size != pack_size_bytes_ * out_channels)
800 && (pack_size_bytes_ < 65535)) {
801 error_count++;
802 }
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000803 }
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000804 // Verify that the timestamp is updated with expected length
805 time_stamp_diff = channel->timestamp_diff();
806 if ((counter_ > 10) && (time_stamp_diff != pack_size_samp_)) {
807 error_count++;
808 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000809 }
810
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000811 // Run received side of ACM
812 CHECK_ERROR(acm_b_->PlayoutData10Ms(out_freq_hz_b, audio_frame));
813
814 // Write output speech to file
815 out_file_.Write10MsData(
andrew@webrtc.org63a50982012-05-02 23:56:37 +0000816 audio_frame.data_,
817 audio_frame.samples_per_channel_ * audio_frame.num_channels_);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000818 }
819
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000820 EXPECT_EQ(0, error_count);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000821
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000822 if (in_file_mono_->EndOfFile()) {
823 in_file_mono_->Rewind();
824 }
825 if (in_file_stereo_->EndOfFile()) {
826 in_file_stereo_->Rewind();
827 }
828 // Reset in case we ended with a lost packet
829 channel->set_lost_packet(false);
niklase@google.com470e71d2011-07-07 08:21:25 +0000830}
831
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000832void TestStereo::OpenOutFile(WebRtc_Word16 test_number) {
tina.legrand@webrtc.orgba468042012-08-17 10:38:28 +0000833 std::string file_name;
834 std::stringstream file_stream;
835 file_stream << webrtc::test::OutputPath() << "teststereo_out_"
836 << test_number << ".pcm";
837 file_name = file_stream.str();
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000838 out_file_.Open(file_name, 32000, "wb");
niklase@google.com470e71d2011-07-07 08:21:25 +0000839}
840
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000841void TestStereo::DisplaySendReceiveCodec() {
842 CodecInst my_codec_param;
843 acm_a_->SendCodec(my_codec_param);
844 if (test_mode_ != 0) {
845 printf("%s -> ", my_codec_param.plname);
846 }
847 acm_b_->ReceiveCodec(my_codec_param);
848 if (test_mode_ != 0) {
849 printf("%s\n", my_codec_param.plname);
850 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000851}
852
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000853} // namespace webrtc