blob: 9910ead997d76ecf17d3756b472ddc93de85b573 [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),
124 cn_8khz_pltype_(-1),
125 cn_16khz_pltype_(-1),
126 cn_32khz_pltype_(-1) {
tina.legrand@webrtc.org45175852012-06-01 09:27:35 +0000127 // test_mode = 0 for silent test (auto test)
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000128 test_mode_ = test_mode;
niklase@google.com470e71d2011-07-07 08:21:25 +0000129}
130
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000131TestStereo::~TestStereo() {
132 if (acm_a_ != NULL) {
133 AudioCodingModule::Destroy(acm_a_);
134 acm_a_ = NULL;
135 }
136 if (acm_b_ != NULL) {
137 AudioCodingModule::Destroy(acm_b_);
138 acm_b_ = NULL;
139 }
140 if (channel_a2b_ != NULL) {
141 delete channel_a2b_;
142 channel_a2b_ = NULL;
143 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000144}
145
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000146void TestStereo::Perform() {
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000147 WebRtc_UWord16 frequency_hz;
148 int audio_channels;
149 int codec_channels;
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000150 bool dtx;
151 bool vad;
152 ACMVADMode vad_mode;
niklase@google.com470e71d2011-07-07 08:21:25 +0000153
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000154 if (test_mode_ == 0) {
155 printf("Running Stereo Test");
156 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioCoding, -1,
157 "---------- TestStereo ----------");
158 }
159
tina.legrand@webrtc.org45175852012-06-01 09:27:35 +0000160 // Open both mono and stereo test files in 32 kHz.
tina.legrand@webrtc.orgba468042012-08-17 10:38:28 +0000161 const std::string file_name_stereo =
162 webrtc::test::ResourcePath("audio_coding/teststereo32kHz", "pcm");
163 const std::string file_name_mono =
164 webrtc::test::ResourcePath("audio_coding/testfile32kHz", "pcm");
tina.legrand@webrtc.org45175852012-06-01 09:27:35 +0000165 frequency_hz = 32000;
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000166 in_file_stereo_ = new PCMFile();
167 in_file_mono_ = new PCMFile();
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000168 in_file_stereo_->Open(file_name_stereo, frequency_hz, "rb");
169 in_file_stereo_->ReadStereo(true);
170 in_file_mono_->Open(file_name_mono, frequency_hz, "rb");
171 in_file_mono_->ReadStereo(false);
172
tina.legrand@webrtc.org45175852012-06-01 09:27:35 +0000173 // Create and initialize two ACMs, one for each side of a one-to-one call.
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000174 acm_a_ = AudioCodingModule::Create(0);
175 acm_b_ = AudioCodingModule::Create(1);
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000176 ASSERT_TRUE((acm_a_ != NULL) && (acm_b_ != NULL));
177 EXPECT_EQ(0, acm_a_->InitializeReceiver());
178 EXPECT_EQ(0, acm_b_->InitializeReceiver());
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000179
tina.legrand@webrtc.org45175852012-06-01 09:27:35 +0000180 // Register all available codes as receiving codecs.
181 WebRtc_UWord8 num_encoders = acm_a_->NumberOfCodecs();
182 CodecInst my_codec_param;
183 for (WebRtc_UWord8 n = 0; n < num_encoders; n++) {
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000184 EXPECT_EQ(0, acm_b_->Codec(n, my_codec_param));
185 EXPECT_EQ(0, acm_b_->RegisterReceiveCodec(my_codec_param));
tina.legrand@webrtc.org45175852012-06-01 09:27:35 +0000186 }
187
188 // Test that unregister all receive codecs works.
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000189 for (WebRtc_UWord8 n = 0; n < num_encoders; n++) {
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000190 EXPECT_EQ(0, acm_b_->Codec(n, my_codec_param));
191 EXPECT_EQ(0, acm_b_->UnregisterReceiveCodec(my_codec_param.pltype));
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000192 }
tina.legrand@webrtc.orgae1c4542012-03-12 08:41:30 +0000193
tina.legrand@webrtc.org45175852012-06-01 09:27:35 +0000194 // Register all available codes as receiving codecs once more.
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000195 for (WebRtc_UWord8 n = 0; n < num_encoders; n++) {
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000196 EXPECT_EQ(0, acm_b_->Codec(n, my_codec_param));
197 EXPECT_EQ(0, acm_b_->RegisterReceiveCodec(my_codec_param));
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000198 }
tina.legrand@webrtc.orgae1c4542012-03-12 08:41:30 +0000199
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000200 // TODO(tlegrand): Take care of return values of all function calls.
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000201
tina.legrand@webrtc.org45175852012-06-01 09:27:35 +0000202 // TODO(tlegrand): Re-register all stereo codecs needed in the test,
203 // with new payload numbers.
204 // g722_pltype_ = 117;
205 // l16_8khz_pltype_ = 120;
206 // l16_16khz_pltype_ = 121;
207 // l16_32khz_pltype_ = 122;
208 // pcma_pltype_ = 110;
209 // pcmu_pltype_ = 118;
210 // celt_pltype_ = 119;
211 // cn_8khz_pltype_ = 123;
212 // cn_16khz_pltype_ = 124;
213 // cn_32khz_pltype_ = 125;
tina.legrand@webrtc.orgae1c4542012-03-12 08:41:30 +0000214
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000215 // Create and connect the channel.
216 channel_a2b_ = new TestPackStereo;
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000217 EXPECT_EQ(0, acm_a_->RegisterTransportCallback(channel_a2b_));
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000218 channel_a2b_->RegisterReceiverACM(acm_b_);
tina.legrand@webrtc.orgdf697752012-02-08 10:22:21 +0000219
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000220 // Start with setting VAD/DTX, before we know we will send stereo.
221 // Continue with setting a stereo codec as send codec and verify that
222 // VAD/DTX gets turned off.
223 EXPECT_EQ(0, acm_a_->SetVAD(true, true, VADNormal));
224 EXPECT_EQ(0, acm_a_->VAD(dtx, vad, vad_mode));
225 EXPECT_TRUE(dtx);
226 EXPECT_TRUE(vad);
227 char codec_pcma_temp[] = "PCMA";
228 RegisterSendCodec('A', codec_pcma_temp, 8000, 64000, 80, 2, pcma_pltype_);
229 EXPECT_EQ(0, acm_a_->VAD(dtx, vad, vad_mode));
230 EXPECT_FALSE(dtx);
231 EXPECT_FALSE(vad);
232 if(test_mode_ != 0) {
233 printf("\n");
234 }
235
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000236 //
237 // Test Stereo-To-Stereo for all codecs.
238 //
239 audio_channels = 2;
240 codec_channels = 2;
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000241
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000242 // All codecs are tested for all allowed sampling frequencies, rates and
243 // packet sizes.
niklase@google.com470e71d2011-07-07 08:21:25 +0000244#ifdef WEBRTC_CODEC_G722
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000245 if(test_mode_ != 0) {
246 printf("===========================================================\n");
247 printf("Test number: %d\n",test_cntr_ + 1);
248 printf("Test type: Stereo-to-stereo\n");
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000249 }
250 channel_a2b_->set_codec_mode(kStereo);
251 test_cntr_++;
252 OpenOutFile(test_cntr_);
253 char codec_g722[] = "G722";
254 RegisterSendCodec('A', codec_g722, 16000, 64000, 160, codec_channels,
255 g722_pltype_);
256 Run(channel_a2b_, audio_channels, codec_channels);
257 RegisterSendCodec('A', codec_g722, 16000, 64000, 320, codec_channels,
258 g722_pltype_);
259 Run(channel_a2b_, audio_channels, codec_channels);
260 RegisterSendCodec('A', codec_g722, 16000, 64000, 480, codec_channels,
261 g722_pltype_);
262 Run(channel_a2b_, audio_channels, codec_channels);
263 RegisterSendCodec('A', codec_g722, 16000, 64000, 640, codec_channels,
264 g722_pltype_);
265 Run(channel_a2b_, audio_channels, codec_channels);
266 RegisterSendCodec('A', codec_g722, 16000, 64000, 800, codec_channels,
267 g722_pltype_);
268 Run(channel_a2b_, audio_channels, codec_channels);
269 RegisterSendCodec('A', codec_g722, 16000, 64000, 960, codec_channels,
270 g722_pltype_);
271 Run(channel_a2b_, audio_channels, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000272 out_file_.Close();
niklase@google.com470e71d2011-07-07 08:21:25 +0000273#endif
274#ifdef WEBRTC_CODEC_PCM16
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000275 if(test_mode_ != 0) {
276 printf("===========================================================\n");
277 printf("Test number: %d\n",test_cntr_ + 1);
278 printf("Test type: Stereo-to-stereo\n");
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000279 }
280 channel_a2b_->set_codec_mode(kStereo);
281 test_cntr_++;
282 OpenOutFile(test_cntr_);
283 char codec_l16[] = "L16";
284 RegisterSendCodec('A', codec_l16, 8000, 128000, 80, codec_channels,
285 l16_8khz_pltype_);
286 Run(channel_a2b_, audio_channels, codec_channels);
287 RegisterSendCodec('A', codec_l16, 8000, 128000, 160, codec_channels,
288 l16_8khz_pltype_);
289 Run(channel_a2b_, audio_channels, codec_channels);
290 RegisterSendCodec('A', codec_l16, 8000, 128000, 240, codec_channels,
291 l16_8khz_pltype_);
292 Run(channel_a2b_, audio_channels, codec_channels);
293 RegisterSendCodec('A', codec_l16, 8000, 128000, 320, codec_channels,
294 l16_8khz_pltype_);
295 Run(channel_a2b_, audio_channels, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000296 out_file_.Close();
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000297
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000298 if(test_mode_ != 0) {
299 printf("===========================================================\n");
300 printf("Test number: %d\n",test_cntr_ + 1);
301 printf("Test type: Stereo-to-stereo\n");
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000302 }
303 test_cntr_++;
304 OpenOutFile(test_cntr_);
305 RegisterSendCodec('A', codec_l16, 16000, 256000, 160, codec_channels,
306 l16_16khz_pltype_);
307 Run(channel_a2b_, audio_channels, codec_channels);
308 RegisterSendCodec('A', codec_l16, 16000, 256000, 320, codec_channels,
309 l16_16khz_pltype_);
310 Run(channel_a2b_, audio_channels, codec_channels);
311 RegisterSendCodec('A', codec_l16, 16000, 256000, 480, codec_channels,
312 l16_16khz_pltype_);
313 Run(channel_a2b_, audio_channels, codec_channels);
314 RegisterSendCodec('A', codec_l16, 16000, 256000, 640, codec_channels,
315 l16_16khz_pltype_);
316 Run(channel_a2b_, audio_channels, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000317 out_file_.Close();
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000318
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000319 if(test_mode_ != 0) {
320 printf("===========================================================\n");
321 printf("Test number: %d\n",test_cntr_ + 1);
322 printf("Test type: Stereo-to-stereo\n");
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000323 }
324 test_cntr_++;
325 OpenOutFile(test_cntr_);
326 RegisterSendCodec('A', codec_l16, 32000, 512000, 320, codec_channels,
327 l16_32khz_pltype_);
328 Run(channel_a2b_, audio_channels, codec_channels);
329 RegisterSendCodec('A', codec_l16, 32000, 512000, 640, codec_channels,
330 l16_32khz_pltype_);
331 Run(channel_a2b_, audio_channels, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000332 out_file_.Close();
niklase@google.com470e71d2011-07-07 08:21:25 +0000333#endif
334#define PCMA_AND_PCMU
335#ifdef PCMA_AND_PCMU
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000336 if (test_mode_ != 0) {
337 printf("===========================================================\n");
338 printf("Test number: %d\n", test_cntr_ + 1);
339 printf("Test type: Stereo-to-stereo\n");
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000340 }
341 channel_a2b_->set_codec_mode(kStereo);
342 audio_channels = 2;
343 codec_channels = 2;
344 test_cntr_++;
345 OpenOutFile(test_cntr_);
346 char codec_pcma[] = "PCMA";
347 RegisterSendCodec('A', codec_pcma, 8000, 64000, 80, codec_channels,
348 pcma_pltype_);
349 Run(channel_a2b_, audio_channels, codec_channels);
350 RegisterSendCodec('A', codec_pcma, 8000, 64000, 160, codec_channels,
351 pcma_pltype_);
352 Run(channel_a2b_, audio_channels, codec_channels);
353 RegisterSendCodec('A', codec_pcma, 8000, 64000, 240, codec_channels,
354 pcma_pltype_);
355 Run(channel_a2b_, audio_channels, codec_channels);
356 RegisterSendCodec('A', codec_pcma, 8000, 64000, 320, codec_channels,
357 pcma_pltype_);
358 Run(channel_a2b_, audio_channels, codec_channels);
359 RegisterSendCodec('A', codec_pcma, 8000, 64000, 400, codec_channels,
360 pcma_pltype_);
361 Run(channel_a2b_, audio_channels, codec_channels);
362 RegisterSendCodec('A', codec_pcma, 8000, 64000, 480, codec_channels,
363 pcma_pltype_);
364 Run(channel_a2b_, audio_channels, codec_channels);
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000365
366 // Test that VAD/DTX cannot be turned on while sending stereo.
367 EXPECT_EQ(-1, acm_a_->SetVAD(true, true, VADNormal));
368 EXPECT_EQ(0, acm_a_->VAD(dtx, vad, vad_mode));
369 EXPECT_FALSE(dtx);
370 EXPECT_FALSE(vad);
371 EXPECT_EQ(-1, acm_a_->SetVAD(true, false, VADNormal));
372 EXPECT_EQ(0, acm_a_->VAD(dtx, vad, vad_mode));
373 EXPECT_FALSE(dtx);
374 EXPECT_FALSE(vad);
375 EXPECT_EQ(-1, acm_a_->SetVAD(false, true, VADNormal));
376 EXPECT_EQ(0, acm_a_->VAD(dtx, vad, vad_mode));
377 EXPECT_FALSE(dtx);
378 EXPECT_FALSE(vad);
379 EXPECT_EQ(0, acm_a_->SetVAD(false, false, VADNormal));
380 EXPECT_EQ(0, acm_a_->VAD(dtx, vad, vad_mode));
381 EXPECT_FALSE(dtx);
382 EXPECT_FALSE(vad);
383
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000384 out_file_.Close();
385 if (test_mode_ != 0) {
386 printf("===========================================================\n");
387 printf("Test number: %d\n", test_cntr_ + 1);
388 printf("Test type: Stereo-to-stereo\n");
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000389 }
390 test_cntr_++;
391 OpenOutFile(test_cntr_);
392 char codec_pcmu[] = "PCMU";
393 RegisterSendCodec('A', codec_pcmu, 8000, 64000, 80, codec_channels,
394 pcmu_pltype_);
395 Run(channel_a2b_, audio_channels, codec_channels);
396 RegisterSendCodec('A', codec_pcmu, 8000, 64000, 160, codec_channels,
397 pcmu_pltype_);
398 Run(channel_a2b_, audio_channels, codec_channels);
399 RegisterSendCodec('A', codec_pcmu, 8000, 64000, 240, codec_channels,
400 pcmu_pltype_);
401 Run(channel_a2b_, audio_channels, codec_channels);
402 RegisterSendCodec('A', codec_pcmu, 8000, 64000, 320, codec_channels,
403 pcmu_pltype_);
404 Run(channel_a2b_, audio_channels, codec_channels);
405 RegisterSendCodec('A', codec_pcmu, 8000, 64000, 400, codec_channels,
406 pcmu_pltype_);
407 Run(channel_a2b_, audio_channels, codec_channels);
408 RegisterSendCodec('A', codec_pcmu, 8000, 64000, 480, codec_channels,
409 pcmu_pltype_);
410 Run(channel_a2b_, audio_channels, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000411 out_file_.Close();
niklase@google.com470e71d2011-07-07 08:21:25 +0000412#endif
tina.legrand@webrtc.orgdf697752012-02-08 10:22:21 +0000413#ifdef WEBRTC_CODEC_CELT
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000414 if(test_mode_ != 0) {
415 printf("===========================================================\n");
416 printf("Test number: %d\n",test_cntr_ + 1);
417 printf("Test type: Stereo-to-stereo\n");
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000418 }
419 channel_a2b_->set_codec_mode(kStereo);
420 audio_channels = 2;
421 codec_channels = 2;
422 test_cntr_++;
423 OpenOutFile(test_cntr_);
424 char codec_celt[] = "CELT";
tina.legrand@webrtc.org90af7f82012-06-07 08:57:27 +0000425 RegisterSendCodec('A', codec_celt, 32000, 48000, 640, codec_channels,
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000426 celt_pltype_);
427 Run(channel_a2b_, audio_channels, codec_channels);
tina.legrand@webrtc.org90af7f82012-06-07 08:57:27 +0000428 RegisterSendCodec('A', codec_celt, 32000, 64000, 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, 128000, 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.orga6ecd1e2012-04-26 07:54:30 +0000434 out_file_.Close();
tina.legrand@webrtc.orgdf697752012-02-08 10:22:21 +0000435#endif
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000436 //
437 // Test Mono-To-Stereo for all codecs.
438 //
439 audio_channels = 1;
440 codec_channels = 2;
niklase@google.com470e71d2011-07-07 08:21:25 +0000441
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000442#ifdef WEBRTC_CODEC_G722
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000443 if(test_mode_ != 0) {
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000444 printf("===============================================================\n");
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000445 printf("Test number: %d\n",test_cntr_ + 1);
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000446 printf("Test type: Mono-to-stereo\n");
447 }
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000448 test_cntr_++;
449 channel_a2b_->set_codec_mode(kStereo);
450 OpenOutFile(test_cntr_);
451 RegisterSendCodec('A', codec_g722, 16000, 64000, 160, codec_channels,
tina.legrand@webrtc.orgae1c4542012-03-12 08:41:30 +0000452 g722_pltype_);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000453 Run(channel_a2b_, audio_channels, codec_channels);
454 out_file_.Close();
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000455#endif
456#ifdef WEBRTC_CODEC_PCM16
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000457 if(test_mode_ != 0) {
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000458 printf("===============================================================\n");
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000459 printf("Test number: %d\n",test_cntr_ + 1);
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000460 printf("Test type: Mono-to-stereo\n");
461 }
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000462 test_cntr_++;
463 channel_a2b_->set_codec_mode(kStereo);
464 OpenOutFile(test_cntr_);
465 RegisterSendCodec('A', codec_l16, 8000, 128000, 80, codec_channels,
tina.legrand@webrtc.orgae1c4542012-03-12 08:41:30 +0000466 l16_8khz_pltype_);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000467 Run(channel_a2b_, audio_channels, codec_channels);
468 out_file_.Close();
469 if(test_mode_ != 0) {
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000470 printf("===============================================================\n");
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000471 printf("Test number: %d\n",test_cntr_ + 1);
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000472 printf("Test type: Mono-to-stereo\n");
473 }
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000474 test_cntr_++;
475 OpenOutFile(test_cntr_);
476 RegisterSendCodec('A', codec_l16, 16000, 256000, 160, codec_channels,
tina.legrand@webrtc.orgae1c4542012-03-12 08:41:30 +0000477 l16_16khz_pltype_);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000478 Run(channel_a2b_, audio_channels, codec_channels);
479 out_file_.Close();
480 if(test_mode_ != 0) {
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000481 printf("===============================================================\n");
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000482 printf("Test number: %d\n",test_cntr_ + 1);
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000483 printf("Test type: Mono-to-stereo\n");
484 }
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000485 test_cntr_++;
486 OpenOutFile(test_cntr_);
487 RegisterSendCodec('A', codec_l16, 32000, 512000, 320, codec_channels,
tina.legrand@webrtc.orgae1c4542012-03-12 08:41:30 +0000488 l16_32khz_pltype_);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000489 Run(channel_a2b_, audio_channels, codec_channels);
490 out_file_.Close();
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000491#endif
492#ifdef PCMA_AND_PCMU
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000493 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 channel_a2b_->set_codec_mode(kStereo);
500 OpenOutFile(test_cntr_);
501 RegisterSendCodec('A', codec_pcmu, 8000, 64000, 80, codec_channels,
tina.legrand@webrtc.orgae1c4542012-03-12 08:41:30 +0000502 pcmu_pltype_);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000503 Run(channel_a2b_, audio_channels, codec_channels);
504 RegisterSendCodec('A', codec_pcma, 8000, 64000, 80, codec_channels,
tina.legrand@webrtc.orgae1c4542012-03-12 08:41:30 +0000505 pcma_pltype_);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000506 Run(channel_a2b_, audio_channels, codec_channels);
507 out_file_.Close();
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000508#endif
tina.legrand@webrtc.orgdf697752012-02-08 10:22:21 +0000509#ifdef WEBRTC_CODEC_CELT
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000510 if(test_mode_ != 0) {
tina.legrand@webrtc.orgdf697752012-02-08 10:22:21 +0000511 printf("===============================================================\n");
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000512 printf("Test number: %d\n",test_cntr_ + 1);
tina.legrand@webrtc.orgdf697752012-02-08 10:22:21 +0000513 printf("Test type: Mono-to-stereo\n");
514 }
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000515 test_cntr_++;
516 channel_a2b_->set_codec_mode(kStereo);
517 OpenOutFile(test_cntr_);
tina.legrand@webrtc.org90af7f82012-06-07 08:57:27 +0000518 RegisterSendCodec('A', codec_celt, 32000, 64000, 640, codec_channels,
tina.legrand@webrtc.orgae1c4542012-03-12 08:41:30 +0000519 celt_pltype_);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000520 Run(channel_a2b_, audio_channels, codec_channels);
521 out_file_.Close();
tina.legrand@webrtc.orgdf697752012-02-08 10:22:21 +0000522#endif
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000523
524 //
525 // Test Stereo-To-Mono for all codecs.
526 //
527 audio_channels = 2;
528 codec_channels = 1;
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000529 channel_a2b_->set_codec_mode(kMono);
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000530
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000531#ifdef WEBRTC_CODEC_G722
532 // Run stereo audio and mono codec.
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000533 if(test_mode_ != 0) {
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000534 printf("===============================================================\n");
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000535 printf("Test number: %d\n",test_cntr_ + 1);
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000536 printf("Test type: Stereo-to-mono\n");
537 }
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000538 test_cntr_++;
539 OpenOutFile(test_cntr_);
540 RegisterSendCodec('A', codec_g722, 16000, 64000, 160, codec_channels,
tina.legrand@webrtc.orgae1c4542012-03-12 08:41:30 +0000541 g722_pltype_);
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000542
543
544 // Make sure it is possible to set VAD/CNG, now that we are sending mono
545 // again.
546 EXPECT_EQ(0, acm_a_->SetVAD(true, true, VADNormal));
547 EXPECT_EQ(0, acm_a_->VAD(dtx, vad, vad_mode));
548 EXPECT_TRUE(dtx);
549 EXPECT_TRUE(vad);
550 EXPECT_EQ(0, acm_a_->SetVAD(false, false, VADNormal));
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000551 Run(channel_a2b_, audio_channels, codec_channels);
552 out_file_.Close();
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000553#endif
554#ifdef WEBRTC_CODEC_PCM16
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000555 if(test_mode_ != 0) {
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000556 printf("===============================================================\n");
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000557 printf("Test number: %d\n",test_cntr_ + 1);
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000558 printf("Test type: Stereo-to-mono\n");
559 }
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000560 test_cntr_++;
561 OpenOutFile(test_cntr_);
562 RegisterSendCodec('A', codec_l16, 8000, 128000, 80, codec_channels,
tina.legrand@webrtc.orgae1c4542012-03-12 08:41:30 +0000563 l16_8khz_pltype_);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000564 Run(channel_a2b_, audio_channels, codec_channels);
565 out_file_.Close();
566 if(test_mode_ != 0) {
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000567 printf("===============================================================\n");
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000568 printf("Test number: %d\n",test_cntr_ + 1);
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000569 printf("Test type: Stereo-to-mono\n");
570 }
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000571 test_cntr_++;
572 OpenOutFile(test_cntr_);
573 RegisterSendCodec('A', codec_l16, 16000, 256000, 160, codec_channels,
tina.legrand@webrtc.orgae1c4542012-03-12 08:41:30 +0000574 l16_16khz_pltype_);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000575 Run(channel_a2b_, audio_channels, codec_channels);
576 out_file_.Close();
577 if(test_mode_ != 0) {
tina.legrand@webrtc.org16b6b902012-04-12 11:02:38 +0000578 printf("==============================================================\n");
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000579 printf("Test number: %d\n",test_cntr_ + 1);
tina.legrand@webrtc.orgdf697752012-02-08 10:22:21 +0000580 printf("Test type: Stereo-to-mono\n");
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000581 }
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000582 test_cntr_++;
583 OpenOutFile(test_cntr_);
584 RegisterSendCodec('A', codec_l16, 32000, 512000, 320, codec_channels,
tina.legrand@webrtc.orgae1c4542012-03-12 08:41:30 +0000585 l16_32khz_pltype_);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000586 Run(channel_a2b_, audio_channels, codec_channels);
587 out_file_.Close();
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000588#endif
589#ifdef PCMA_AND_PCMU
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000590 if(test_mode_ != 0) {
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000591 printf("===============================================================\n");
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000592 printf("Test number: %d\n",test_cntr_ + 1);
tina.legrand@webrtc.orgdf697752012-02-08 10:22:21 +0000593 printf("Test type: Stereo-to-mono\n");
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000594 }
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000595 test_cntr_++;
596 OpenOutFile(test_cntr_);
597 RegisterSendCodec('A', codec_pcmu, 8000, 64000, 80, codec_channels,
tina.legrand@webrtc.orgae1c4542012-03-12 08:41:30 +0000598 pcmu_pltype_);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000599 Run(channel_a2b_, audio_channels, codec_channels);
600 RegisterSendCodec('A', codec_pcma, 8000, 64000, 80, codec_channels,
tina.legrand@webrtc.orgae1c4542012-03-12 08:41:30 +0000601 pcma_pltype_);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000602 Run(channel_a2b_, audio_channels, codec_channels);
603 out_file_.Close();
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000604#endif
tina.legrand@webrtc.orgdf697752012-02-08 10:22:21 +0000605#ifdef WEBRTC_CODEC_CELT
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000606 if(test_mode_ != 0) {
tina.legrand@webrtc.orgdf697752012-02-08 10:22:21 +0000607 printf("===============================================================\n");
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000608 printf("Test number: %d\n",test_cntr_ + 1);
tina.legrand@webrtc.orgdf697752012-02-08 10:22:21 +0000609 printf("Test type: Stereo-to-mono\n");
610 }
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000611 test_cntr_++;
612 OpenOutFile(test_cntr_);
tina.legrand@webrtc.org90af7f82012-06-07 08:57:27 +0000613 RegisterSendCodec('A', codec_celt, 32000, 64000, 640, codec_channels,
tina.legrand@webrtc.orgae1c4542012-03-12 08:41:30 +0000614 celt_pltype_);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000615 Run(channel_a2b_, audio_channels, codec_channels);
616 out_file_.Close();
tina.legrand@webrtc.orgdf697752012-02-08 10:22:21 +0000617#endif
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000618
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000619 // Print out which codecs were tested, and which were not, in the run.
620 if (test_mode_ != 0) {
621 printf("\nThe following codecs was INCLUDED in the test:\n");
niklase@google.com470e71d2011-07-07 08:21:25 +0000622#ifdef WEBRTC_CODEC_G722
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000623 printf(" G.722\n");
niklase@google.com470e71d2011-07-07 08:21:25 +0000624#endif
625#ifdef WEBRTC_CODEC_PCM16
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000626 printf(" PCM16\n");
niklase@google.com470e71d2011-07-07 08:21:25 +0000627#endif
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000628 printf(" G.711\n");
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000629#ifdef WEBRTC_CODEC_CELT
630 printf(" CELT\n");
631#endif
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000632 printf("\nTo complete the test, listen to the %d number of output "
633 "files.\n",
634 test_cntr_);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000635 }
636
637 // Delete the file pointers.
638 delete in_file_stereo_;
639 delete in_file_mono_;
niklase@google.com470e71d2011-07-07 08:21:25 +0000640}
641
642// Register Codec to use in the test
643//
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000644// Input: side - which ACM to use, 'A' or 'B'
645// codec_name - name to use when register the codec
646// sampling_freq_hz - sampling frequency in Herz
647// rate - bitrate in bytes
648// pack_size - packet size in samples
649// channels - number of channels; 1 for mono, 2 for stereo
650// payload_type - payload type for the codec
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000651void TestStereo::RegisterSendCodec(char side, char* codec_name,
652 WebRtc_Word32 sampling_freq_hz, int rate,
653 int pack_size, int channels,
654 int payload_type) {
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000655 if (test_mode_ != 0) {
656 // Print out codec and settings
tina.legrand@webrtc.orgba468042012-08-17 10:38:28 +0000657 printf("Codec: %s Freq: %d Rate: %d PackSize: %d\n", codec_name,
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000658 sampling_freq_hz, rate, pack_size);
659 }
660
661 // Store packet size in samples, used to validate the received packet
662 pack_size_samp_ = pack_size;
663
664 // Store the expected packet size in bytes, used to validate the received
665 // packet. Add 0.875 to always round up to a whole byte.
666 // For Celt the packet size in bytes is already counting the stereo part.
667 if (!strcmp(codec_name, "CELT")) {
668 pack_size_bytes_ = (WebRtc_UWord16)(
669 (float) (pack_size * rate) / (float) (sampling_freq_hz * 8) + 0.875)
670 / channels;
671 } else {
672 pack_size_bytes_ = (WebRtc_UWord16)(
673 (float) (pack_size * rate) / (float) (sampling_freq_hz * 8) + 0.875);
674 }
675
676 // Set pointer to the ACM where to register the codec
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000677 AudioCodingModule* my_acm = NULL;
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000678 switch (side) {
679 case 'A': {
680 my_acm = acm_a_;
681 break;
niklase@google.com470e71d2011-07-07 08:21:25 +0000682 }
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000683 case 'B': {
684 my_acm = acm_b_;
685 break;
tina.legrand@webrtc.org16b6b902012-04-12 11:02:38 +0000686 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000687 default:
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000688 break;
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000689 }
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000690 ASSERT_TRUE(my_acm != NULL);
niklase@google.com470e71d2011-07-07 08:21:25 +0000691
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000692 CodecInst my_codec_param;
693 // Get all codec parameters before registering
694 CHECK_ERROR(AudioCodingModule::Codec(codec_name, my_codec_param,
tina.legrand@webrtc.org45175852012-06-01 09:27:35 +0000695 sampling_freq_hz, channels));
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000696 my_codec_param.rate = rate;
697 my_codec_param.pacsize = pack_size;
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000698 CHECK_ERROR(my_acm->RegisterSendCodec(my_codec_param));
niklase@google.com470e71d2011-07-07 08:21:25 +0000699}
700
tina.legrand@webrtc.org16b6b902012-04-12 11:02:38 +0000701void TestStereo::Run(TestPackStereo* channel, int in_channels, int out_channels,
702 int percent_loss) {
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000703 AudioFrame audio_frame;
niklase@google.com470e71d2011-07-07 08:21:25 +0000704
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000705 WebRtc_Word32 out_freq_hz_b = out_file_.SamplingFrequency();
706 WebRtc_UWord16 rec_size;
707 WebRtc_UWord32 time_stamp_diff;
708 channel->reset_payload_size();
709 int error_count = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000710
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000711 while (1) {
712 // Simulate packet loss by setting |packet_loss_| to "true" in
713 // |percent_loss| percent of the loops.
714 if (percent_loss > 0) {
715 if (counter_ == floor((100 / percent_loss) + 0.5)) {
716 counter_ = 0;
717 channel->set_lost_packet(true);
718 } else {
719 channel->set_lost_packet(false);
720 }
721 counter_++;
niklase@google.com470e71d2011-07-07 08:21:25 +0000722 }
723
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000724 // Add 10 msec to ACM
725 if (in_channels == 1) {
726 if (in_file_mono_->EndOfFile()) {
727 break;
728 }
729 in_file_mono_->Read10MsData(audio_frame);
730 } else {
731 if (in_file_stereo_->EndOfFile()) {
732 break;
733 }
734 in_file_stereo_->Read10MsData(audio_frame);
735 }
736 CHECK_ERROR(acm_a_->Add10MsData(audio_frame));
737
738 // Run sender side of ACM
739 CHECK_ERROR(acm_a_->Process());
740
741 // Verify that the received packet size matches the settings
742 rec_size = channel->payload_size();
743 if ((0 < rec_size) & (rec_size < 65535)) {
744 if ((rec_size != pack_size_bytes_ * out_channels)
745 && (pack_size_bytes_ < 65535)) {
746 error_count++;
747 }
748
749 // Verify that the timestamp is updated with expected length
750 time_stamp_diff = channel->timestamp_diff();
751 if ((counter_ > 10) && (time_stamp_diff != pack_size_samp_)) {
752 error_count++;
753 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000754 }
755
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000756 // Run received side of ACM
757 CHECK_ERROR(acm_b_->PlayoutData10Ms(out_freq_hz_b, audio_frame));
758
759 // Write output speech to file
760 out_file_.Write10MsData(
andrew@webrtc.org63a50982012-05-02 23:56:37 +0000761 audio_frame.data_,
762 audio_frame.samples_per_channel_ * audio_frame.num_channels_);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000763 }
764
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000765 EXPECT_EQ(0, error_count);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000766
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000767 if (in_file_mono_->EndOfFile()) {
768 in_file_mono_->Rewind();
769 }
770 if (in_file_stereo_->EndOfFile()) {
771 in_file_stereo_->Rewind();
772 }
773 // Reset in case we ended with a lost packet
774 channel->set_lost_packet(false);
niklase@google.com470e71d2011-07-07 08:21:25 +0000775}
776
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000777void TestStereo::OpenOutFile(WebRtc_Word16 test_number) {
tina.legrand@webrtc.orgba468042012-08-17 10:38:28 +0000778 std::string file_name;
779 std::stringstream file_stream;
780 file_stream << webrtc::test::OutputPath() << "teststereo_out_"
781 << test_number << ".pcm";
782 file_name = file_stream.str();
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000783 out_file_.Open(file_name, 32000, "wb");
niklase@google.com470e71d2011-07-07 08:21:25 +0000784}
785
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000786void TestStereo::DisplaySendReceiveCodec() {
787 CodecInst my_codec_param;
788 acm_a_->SendCodec(my_codec_param);
789 if (test_mode_ != 0) {
790 printf("%s -> ", my_codec_param.plname);
791 }
792 acm_b_->ReceiveCodec(my_codec_param);
793 if (test_mode_ != 0) {
794 printf("%s\n", my_codec_param.plname);
795 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000796}
797
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000798} // namespace webrtc