blob: e1186ba2bb90d21411f5d25c8d9b0485b8999dd5 [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
niklase@google.com470e71d2011-07-07 08:21:25 +000013#include <cassert>
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +000014#include <string>
kjellander@webrtc.org5490c712011-12-21 13:34:18 +000015
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +000016#include "gtest/gtest.h"
17
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +000018#include "webrtc/common_types.h"
19#include "webrtc/engine_configurations.h"
20#include "webrtc/modules/audio_coding/main/interface/audio_coding_module_typedefs.h"
21#include "webrtc/modules/audio_coding/main/test/utility.h"
22#include "webrtc/system_wrappers/interface/trace.h"
23#include "webrtc/test/testsupport/fileutils.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000024
tina.legrand@webrtc.org554ae1a2011-12-16 10:09:04 +000025namespace webrtc {
niklase@google.com470e71d2011-07-07 08:21:25 +000026
27// Class for simulating packet handling
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +000028TestPackStereo::TestPackStereo()
29 : receiver_acm_(NULL),
30 seq_no_(0),
31 timestamp_diff_(0),
32 last_in_timestamp_(0),
33 total_bytes_(0),
34 payload_size_(0),
35 codec_mode_(kNotSet),
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;
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +000068 rtp_info.type.Audio.channel = static_cast<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;
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +000071 rtp_info.type.Audio.channel = static_cast<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.org374aa492013-02-20 15:22:23 +0000185 EXPECT_EQ(0, acm_b_->Codec(n, &my_codec_param));
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000186 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.org374aa492013-02-20 15:22:23 +0000191 EXPECT_EQ(0, acm_b_->Codec(n, &my_codec_param));
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000192 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.org374aa492013-02-20 15:22:23 +0000197 EXPECT_EQ(0, acm_b_->Codec(n, &my_codec_param));
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000198 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));
tina.legrand@webrtc.org374aa492013-02-20 15:22:23 +0000225 EXPECT_EQ(0, acm_a_->VAD(&dtx, &vad, &vad_mode));
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000226 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_);
tina.legrand@webrtc.org374aa492013-02-20 15:22:23 +0000230 EXPECT_EQ(0, acm_a_->VAD(&dtx, &vad, &vad_mode));
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000231 EXPECT_FALSE(dtx);
232 EXPECT_FALSE(vad);
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000233 if (test_mode_ != 0) {
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000234 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.org46d90dc2013-02-01 14:20:06 +0000246 if (test_mode_ != 0) {
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000247 printf("===========================================================\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000248 printf("Test number: %d\n", test_cntr_ + 1);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000249 printf("Test type: Stereo-to-stereo\n");
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000250 }
251 channel_a2b_->set_codec_mode(kStereo);
252 test_cntr_++;
253 OpenOutFile(test_cntr_);
254 char codec_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.org46d90dc2013-02-01 14:20:06 +0000276 if (test_mode_ != 0) {
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000277 printf("===========================================================\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000278 printf("Test number: %d\n", test_cntr_ + 1);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000279 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.org46d90dc2013-02-01 14:20:06 +0000299 if (test_mode_ != 0) {
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000300 printf("===========================================================\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000301 printf("Test number: %d\n", test_cntr_ + 1);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000302 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.org46d90dc2013-02-01 14:20:06 +0000320 if (test_mode_ != 0) {
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000321 printf("===========================================================\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000322 printf("Test number: %d\n", test_cntr_ + 1);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000323 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));
tina.legrand@webrtc.org374aa492013-02-20 15:22:23 +0000369 EXPECT_EQ(0, acm_a_->VAD(&dtx, &vad, &vad_mode));
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000370 EXPECT_FALSE(dtx);
371 EXPECT_FALSE(vad);
372 EXPECT_EQ(-1, acm_a_->SetVAD(true, false, VADNormal));
tina.legrand@webrtc.org374aa492013-02-20 15:22:23 +0000373 EXPECT_EQ(0, acm_a_->VAD(&dtx, &vad, &vad_mode));
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000374 EXPECT_FALSE(dtx);
375 EXPECT_FALSE(vad);
376 EXPECT_EQ(-1, acm_a_->SetVAD(false, true, VADNormal));
tina.legrand@webrtc.org374aa492013-02-20 15:22:23 +0000377 EXPECT_EQ(0, acm_a_->VAD(&dtx, &vad, &vad_mode));
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000378 EXPECT_FALSE(dtx);
379 EXPECT_FALSE(vad);
380 EXPECT_EQ(0, acm_a_->SetVAD(false, false, VADNormal));
tina.legrand@webrtc.org374aa492013-02-20 15:22:23 +0000381 EXPECT_EQ(0, acm_a_->VAD(&dtx, &vad, &vad_mode));
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000382 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.org46d90dc2013-02-01 14:20:06 +0000415 if (test_mode_ != 0) {
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000416 printf("===========================================================\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000417 printf("Test number: %d\n", test_cntr_ + 1);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000418 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
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000438 if (test_mode_ != 0) {
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000439 printf("===========================================================\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000440 printf("Test number: %d\n", test_cntr_ + 1);
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000441 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_);
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000448
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000449 char codec_opus[] = "opus";
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000450 // Run Opus with 10 ms frame size.
451 RegisterSendCodec('A', codec_opus, 48000, 64000, 480, codec_channels,
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000452 opus_pltype_);
453 Run(channel_a2b_, audio_channels, codec_channels);
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000454 // Run Opus with 20 ms frame size.
455 RegisterSendCodec('A', codec_opus, 48000, 64000, 480*2, codec_channels,
456 opus_pltype_);
457 Run(channel_a2b_, audio_channels, codec_channels);
458 // Run Opus with 40 ms frame size.
459 RegisterSendCodec('A', codec_opus, 48000, 64000, 480*4, codec_channels,
460 opus_pltype_);
461 Run(channel_a2b_, audio_channels, codec_channels);
462 // Run Opus with 60 ms frame size.
463 RegisterSendCodec('A', codec_opus, 48000, 64000, 480*6, codec_channels,
464 opus_pltype_);
465 Run(channel_a2b_, audio_channels, codec_channels);
466 // Run Opus with 20 ms frame size and different bitrates.
467 RegisterSendCodec('A', codec_opus, 48000, 40000, 960, codec_channels,
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000468 opus_pltype_);
469 Run(channel_a2b_, audio_channels, codec_channels);
470 RegisterSendCodec('A', codec_opus, 48000, 510000, 960, codec_channels,
471 opus_pltype_);
472 Run(channel_a2b_, audio_channels, codec_channels);
473 out_file_.Close();
474#endif
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000475 //
476 // Test Mono-To-Stereo for all codecs.
477 //
478 audio_channels = 1;
479 codec_channels = 2;
niklase@google.com470e71d2011-07-07 08:21:25 +0000480
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000481#ifdef WEBRTC_CODEC_G722
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000482 if (test_mode_ != 0) {
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000483 printf("===============================================================\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000484 printf("Test number: %d\n", test_cntr_ + 1);
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000485 printf("Test type: Mono-to-stereo\n");
486 }
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000487 test_cntr_++;
488 channel_a2b_->set_codec_mode(kStereo);
489 OpenOutFile(test_cntr_);
490 RegisterSendCodec('A', codec_g722, 16000, 64000, 160, codec_channels,
tina.legrand@webrtc.orgae1c4542012-03-12 08:41:30 +0000491 g722_pltype_);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000492 Run(channel_a2b_, audio_channels, codec_channels);
493 out_file_.Close();
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000494#endif
495#ifdef WEBRTC_CODEC_PCM16
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000496 if (test_mode_ != 0) {
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000497 printf("===============================================================\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000498 printf("Test number: %d\n", test_cntr_ + 1);
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000499 printf("Test type: Mono-to-stereo\n");
500 }
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000501 test_cntr_++;
502 channel_a2b_->set_codec_mode(kStereo);
503 OpenOutFile(test_cntr_);
504 RegisterSendCodec('A', codec_l16, 8000, 128000, 80, codec_channels,
tina.legrand@webrtc.orgae1c4542012-03-12 08:41:30 +0000505 l16_8khz_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.org46d90dc2013-02-01 14:20:06 +0000508 if (test_mode_ != 0) {
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000509 printf("===============================================================\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000510 printf("Test number: %d\n", test_cntr_ + 1);
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000511 printf("Test type: Mono-to-stereo\n");
512 }
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000513 test_cntr_++;
514 OpenOutFile(test_cntr_);
515 RegisterSendCodec('A', codec_l16, 16000, 256000, 160, codec_channels,
tina.legrand@webrtc.orgae1c4542012-03-12 08:41:30 +0000516 l16_16khz_pltype_);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000517 Run(channel_a2b_, audio_channels, codec_channels);
518 out_file_.Close();
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000519 if (test_mode_ != 0) {
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000520 printf("===============================================================\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000521 printf("Test number: %d\n", test_cntr_ + 1);
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000522 printf("Test type: Mono-to-stereo\n");
523 }
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000524 test_cntr_++;
525 OpenOutFile(test_cntr_);
526 RegisterSendCodec('A', codec_l16, 32000, 512000, 320, codec_channels,
tina.legrand@webrtc.orgae1c4542012-03-12 08:41:30 +0000527 l16_32khz_pltype_);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000528 Run(channel_a2b_, audio_channels, codec_channels);
529 out_file_.Close();
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000530#endif
531#ifdef PCMA_AND_PCMU
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000532 if (test_mode_ != 0) {
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000533 printf("===============================================================\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000534 printf("Test number: %d\n", test_cntr_ + 1);
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000535 printf("Test type: Mono-to-stereo\n");
536 }
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000537 test_cntr_++;
538 channel_a2b_->set_codec_mode(kStereo);
539 OpenOutFile(test_cntr_);
540 RegisterSendCodec('A', codec_pcmu, 8000, 64000, 80, codec_channels,
tina.legrand@webrtc.orgae1c4542012-03-12 08:41:30 +0000541 pcmu_pltype_);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000542 Run(channel_a2b_, audio_channels, codec_channels);
543 RegisterSendCodec('A', codec_pcma, 8000, 64000, 80, codec_channels,
tina.legrand@webrtc.orgae1c4542012-03-12 08:41:30 +0000544 pcma_pltype_);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000545 Run(channel_a2b_, audio_channels, codec_channels);
546 out_file_.Close();
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000547#endif
tina.legrand@webrtc.orgdf697752012-02-08 10:22:21 +0000548#ifdef WEBRTC_CODEC_CELT
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000549 if (test_mode_ != 0) {
tina.legrand@webrtc.orgdf697752012-02-08 10:22:21 +0000550 printf("===============================================================\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000551 printf("Test number: %d\n", test_cntr_ + 1);
tina.legrand@webrtc.orgdf697752012-02-08 10:22:21 +0000552 printf("Test type: Mono-to-stereo\n");
553 }
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000554 test_cntr_++;
555 channel_a2b_->set_codec_mode(kStereo);
556 OpenOutFile(test_cntr_);
tina.legrand@webrtc.org90af7f82012-06-07 08:57:27 +0000557 RegisterSendCodec('A', codec_celt, 32000, 64000, 640, codec_channels,
tina.legrand@webrtc.orgae1c4542012-03-12 08:41:30 +0000558 celt_pltype_);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000559 Run(channel_a2b_, audio_channels, codec_channels);
560 out_file_.Close();
tina.legrand@webrtc.orgdf697752012-02-08 10:22:21 +0000561#endif
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000562#ifdef WEBRTC_CODEC_OPUS
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000563 if (test_mode_ != 0) {
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000564 printf("===============================================================\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000565 printf("Test number: %d\n", test_cntr_ + 1);
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000566 printf("Test type: Mono-to-stereo\n");
567 }
tina.legrand@webrtc.orgc4590582012-11-28 12:23:29 +0000568
569 // Keep encode and decode in stereo.
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000570 test_cntr_++;
571 channel_a2b_->set_codec_mode(kStereo);
572 OpenOutFile(test_cntr_);
573 RegisterSendCodec('A', codec_opus, 48000, 64000, 960, codec_channels,
574 opus_pltype_);
575 Run(channel_a2b_, audio_channels, codec_channels);
tina.legrand@webrtc.orgc4590582012-11-28 12:23:29 +0000576
577 // Encode in mono, decode in stereo mode.
578 RegisterSendCodec('A', codec_opus, 48000, 64000, 960, 1, opus_pltype_);
579 Run(channel_a2b_, audio_channels, codec_channels);
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000580 out_file_.Close();
581#endif
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000582
583 //
584 // Test Stereo-To-Mono for all codecs.
585 //
586 audio_channels = 2;
587 codec_channels = 1;
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000588 channel_a2b_->set_codec_mode(kMono);
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000589
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000590#ifdef WEBRTC_CODEC_G722
591 // Run stereo audio and mono codec.
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000592 if (test_mode_ != 0) {
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000593 printf("===============================================================\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000594 printf("Test number: %d\n", test_cntr_ + 1);
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000595 printf("Test type: Stereo-to-mono\n");
596 }
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000597 test_cntr_++;
598 OpenOutFile(test_cntr_);
599 RegisterSendCodec('A', codec_g722, 16000, 64000, 160, codec_channels,
tina.legrand@webrtc.orgae1c4542012-03-12 08:41:30 +0000600 g722_pltype_);
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000601
602
603 // Make sure it is possible to set VAD/CNG, now that we are sending mono
604 // again.
605 EXPECT_EQ(0, acm_a_->SetVAD(true, true, VADNormal));
tina.legrand@webrtc.org374aa492013-02-20 15:22:23 +0000606 EXPECT_EQ(0, acm_a_->VAD(&dtx, &vad, &vad_mode));
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000607 EXPECT_TRUE(dtx);
608 EXPECT_TRUE(vad);
609 EXPECT_EQ(0, acm_a_->SetVAD(false, false, VADNormal));
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000610 Run(channel_a2b_, audio_channels, codec_channels);
611 out_file_.Close();
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000612#endif
613#ifdef WEBRTC_CODEC_PCM16
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000614 if (test_mode_ != 0) {
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000615 printf("===============================================================\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000616 printf("Test number: %d\n", test_cntr_ + 1);
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000617 printf("Test type: Stereo-to-mono\n");
618 }
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000619 test_cntr_++;
620 OpenOutFile(test_cntr_);
621 RegisterSendCodec('A', codec_l16, 8000, 128000, 80, codec_channels,
tina.legrand@webrtc.orgae1c4542012-03-12 08:41:30 +0000622 l16_8khz_pltype_);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000623 Run(channel_a2b_, audio_channels, codec_channels);
624 out_file_.Close();
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000625 if (test_mode_ != 0) {
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000626 printf("===============================================================\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000627 printf("Test number: %d\n", test_cntr_ + 1);
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000628 printf("Test type: Stereo-to-mono\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000629 }
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000630 test_cntr_++;
631 OpenOutFile(test_cntr_);
632 RegisterSendCodec('A', codec_l16, 16000, 256000, 160, codec_channels,
tina.legrand@webrtc.orgae1c4542012-03-12 08:41:30 +0000633 l16_16khz_pltype_);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000634 Run(channel_a2b_, audio_channels, codec_channels);
635 out_file_.Close();
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000636 if (test_mode_ != 0) {
tina.legrand@webrtc.org16b6b902012-04-12 11:02:38 +0000637 printf("==============================================================\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000638 printf("Test number: %d\n", test_cntr_ + 1);
tina.legrand@webrtc.orgdf697752012-02-08 10:22:21 +0000639 printf("Test type: Stereo-to-mono\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000640 }
641 test_cntr_++;
642 OpenOutFile(test_cntr_);
643 RegisterSendCodec('A', codec_l16, 32000, 512000, 320, codec_channels,
644 l16_32khz_pltype_);
645 Run(channel_a2b_, audio_channels, codec_channels);
646 out_file_.Close();
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000647#endif
648#ifdef PCMA_AND_PCMU
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000649 if (test_mode_ != 0) {
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000650 printf("===============================================================\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000651 printf("Test number: %d\n", test_cntr_ + 1);
tina.legrand@webrtc.orgdf697752012-02-08 10:22:21 +0000652 printf("Test type: Stereo-to-mono\n");
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000653 }
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000654 test_cntr_++;
655 OpenOutFile(test_cntr_);
656 RegisterSendCodec('A', codec_pcmu, 8000, 64000, 80, codec_channels,
tina.legrand@webrtc.orgae1c4542012-03-12 08:41:30 +0000657 pcmu_pltype_);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000658 Run(channel_a2b_, audio_channels, codec_channels);
659 RegisterSendCodec('A', codec_pcma, 8000, 64000, 80, codec_channels,
tina.legrand@webrtc.orgae1c4542012-03-12 08:41:30 +0000660 pcma_pltype_);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000661 Run(channel_a2b_, audio_channels, codec_channels);
662 out_file_.Close();
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000663#endif
tina.legrand@webrtc.orgdf697752012-02-08 10:22:21 +0000664#ifdef WEBRTC_CODEC_CELT
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000665 if (test_mode_ != 0) {
tina.legrand@webrtc.orgdf697752012-02-08 10:22:21 +0000666 printf("===============================================================\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000667 printf("Test number: %d\n", test_cntr_ + 1);
tina.legrand@webrtc.orgdf697752012-02-08 10:22:21 +0000668 printf("Test type: Stereo-to-mono\n");
669 }
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000670 test_cntr_++;
671 OpenOutFile(test_cntr_);
tina.legrand@webrtc.org90af7f82012-06-07 08:57:27 +0000672 RegisterSendCodec('A', codec_celt, 32000, 64000, 640, codec_channels,
tina.legrand@webrtc.orgae1c4542012-03-12 08:41:30 +0000673 celt_pltype_);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000674 Run(channel_a2b_, audio_channels, codec_channels);
675 out_file_.Close();
tina.legrand@webrtc.orgdf697752012-02-08 10:22:21 +0000676#endif
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000677#ifdef WEBRTC_CODEC_OPUS
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000678 if (test_mode_ != 0) {
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000679 printf("===============================================================\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000680 printf("Test number: %d\n", test_cntr_ + 1);
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000681 printf("Test type: Stereo-to-mono\n");
682 }
683 test_cntr_++;
684 OpenOutFile(test_cntr_);
tina.legrand@webrtc.orgc4590582012-11-28 12:23:29 +0000685 // Encode and decode in mono.
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000686 RegisterSendCodec('A', codec_opus, 48000, 32000, 960, codec_channels,
687 opus_pltype_);
tina.legrand@webrtc.orgc4590582012-11-28 12:23:29 +0000688 CodecInst opus_codec_param;
689 for (WebRtc_UWord8 n = 0; n < num_encoders; n++) {
tina.legrand@webrtc.org374aa492013-02-20 15:22:23 +0000690 EXPECT_EQ(0, acm_b_->Codec(n, &opus_codec_param));
tina.legrand@webrtc.orgc4590582012-11-28 12:23:29 +0000691 if (!strcmp(opus_codec_param.plname, "opus")) {
692 opus_codec_param.channels = 1;
693 EXPECT_EQ(0, acm_b_->RegisterReceiveCodec(opus_codec_param));
694 break;
695 }
696 }
697 Run(channel_a2b_, audio_channels, codec_channels);
698
699 // Encode in stereo, decode in mono.
700 RegisterSendCodec('A', codec_opus, 48000, 32000, 960, 2, opus_pltype_);
701 Run(channel_a2b_, audio_channels, codec_channels);
702
703 out_file_.Close();
704
705 // Test switching between decoding mono and stereo for Opus.
706
707 // Decode in mono.
708 test_cntr_++;
709 OpenOutFile(test_cntr_);
710 if (test_mode_ != 0) {
711 // Print out codec and settings
712 printf("Test number: %d\nCodec: Opus Freq: 48000 Rate :32000 PackSize: 960"
713 " Decode: mono\n", test_cntr_);
714 }
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000715 Run(channel_a2b_, audio_channels, codec_channels);
716 out_file_.Close();
tina.legrand@webrtc.orgc4590582012-11-28 12:23:29 +0000717 // Decode in stereo.
718 test_cntr_++;
719 OpenOutFile(test_cntr_);
720 if (test_mode_ != 0) {
721 // Print out codec and settings
722 printf("Test number: %d\nCodec: Opus Freq: 48000 Rate :32000 PackSize: 960"
723 " Decode: stereo\n", test_cntr_);
724 }
725 opus_codec_param.channels = 2;
726 EXPECT_EQ(0, acm_b_->RegisterReceiveCodec(opus_codec_param));
727 Run(channel_a2b_, audio_channels, 2);
728 out_file_.Close();
729 // Decode in mono.
730 test_cntr_++;
731 OpenOutFile(test_cntr_);
732 if (test_mode_ != 0) {
733 // Print out codec and settings
734 printf("Test number: %d\nCodec: Opus Freq: 48000 Rate :32000 PackSize: 960"
735 " Decode: mono\n", test_cntr_);
736 }
737 opus_codec_param.channels = 1;
738 EXPECT_EQ(0, acm_b_->RegisterReceiveCodec(opus_codec_param));
739 Run(channel_a2b_, audio_channels, codec_channels);
740 out_file_.Close();
741
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000742#endif
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000743
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000744 // Print out which codecs were tested, and which were not, in the run.
745 if (test_mode_ != 0) {
746 printf("\nThe following codecs was INCLUDED in the test:\n");
niklase@google.com470e71d2011-07-07 08:21:25 +0000747#ifdef WEBRTC_CODEC_G722
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000748 printf(" G.722\n");
niklase@google.com470e71d2011-07-07 08:21:25 +0000749#endif
750#ifdef WEBRTC_CODEC_PCM16
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000751 printf(" PCM16\n");
niklase@google.com470e71d2011-07-07 08:21:25 +0000752#endif
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000753 printf(" G.711\n");
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000754#ifdef WEBRTC_CODEC_CELT
755 printf(" CELT\n");
756#endif
tina.legrand@webrtc.orgc4590582012-11-28 12:23:29 +0000757#ifdef WEBRTC_CODEC_OPUS
758 printf(" Opus\n");
759#endif
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000760 printf("\nTo complete the test, listen to the %d number of output "
761 "files.\n",
762 test_cntr_);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000763 }
764
765 // Delete the file pointers.
766 delete in_file_stereo_;
767 delete in_file_mono_;
niklase@google.com470e71d2011-07-07 08:21:25 +0000768}
769
770// Register Codec to use in the test
771//
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000772// Input: side - which ACM to use, 'A' or 'B'
773// codec_name - name to use when register the codec
774// sampling_freq_hz - sampling frequency in Herz
775// rate - bitrate in bytes
776// pack_size - packet size in samples
777// channels - number of channels; 1 for mono, 2 for stereo
778// payload_type - payload type for the codec
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000779void TestStereo::RegisterSendCodec(char side, char* codec_name,
780 WebRtc_Word32 sampling_freq_hz, int rate,
781 int pack_size, int channels,
782 int payload_type) {
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000783 if (test_mode_ != 0) {
784 // Print out codec and settings
tina.legrand@webrtc.orgba468042012-08-17 10:38:28 +0000785 printf("Codec: %s Freq: %d Rate: %d PackSize: %d\n", codec_name,
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000786 sampling_freq_hz, rate, pack_size);
787 }
788
789 // Store packet size in samples, used to validate the received packet
790 pack_size_samp_ = pack_size;
791
792 // Store the expected packet size in bytes, used to validate the received
793 // packet. Add 0.875 to always round up to a whole byte.
794 // For Celt the packet size in bytes is already counting the stereo part.
795 if (!strcmp(codec_name, "CELT")) {
796 pack_size_bytes_ = (WebRtc_UWord16)(
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000797 static_cast<float>(pack_size * rate) /
798 static_cast<float>(sampling_freq_hz * 8) + 0.875)
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000799 / channels;
800 } else {
801 pack_size_bytes_ = (WebRtc_UWord16)(
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000802 static_cast<float>(pack_size * rate) /
803 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.org374aa492013-02-20 15:22:23 +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
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000837 WebRtc_Word32 out_freq_hz_b = out_file_.SamplingFrequency();
838 WebRtc_UWord16 rec_size;
839 WebRtc_UWord32 time_stamp_diff;
840 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.org374aa492013-02-20 15:22:23 +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
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000911void TestStereo::OpenOutFile(WebRtc_Word16 test_number) {
tina.legrand@webrtc.orgba468042012-08-17 10:38:28 +0000912 std::string file_name;
913 std::stringstream file_stream;
914 file_stream << webrtc::test::OutputPath() << "teststereo_out_"
915 << test_number << ".pcm";
916 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.org374aa492013-02-20 15:22:23 +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.org374aa492013-02-20 15:22:23 +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