blob: c5b8f4019eaffafe43ef2286490672fbd1c32c90 [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),
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000036 lost_packet_(false) {
37}
niklase@google.com470e71d2011-07-07 08:21:25 +000038
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000039TestPackStereo::~TestPackStereo() {
40}
niklase@google.com470e71d2011-07-07 08:21:25 +000041
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +000042void TestPackStereo::RegisterReceiverACM(AudioCodingModule* acm) {
43 receiver_acm_ = acm;
44 return;
45}
niklase@google.com470e71d2011-07-07 08:21:25 +000046
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000047int32_t TestPackStereo::SendData(const FrameType frame_type,
48 const uint8_t payload_type,
49 const uint32_t timestamp,
50 const uint8_t* payload_data,
51 const uint16_t payload_size,
52 const RTPFragmentationHeader* fragmentation) {
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +000053 WebRtcRTPHeader rtp_info;
pbos@webrtc.org0946a562013-04-09 00:28:06 +000054 int32_t status = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +000055
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +000056 rtp_info.header.markerBit = false;
57 rtp_info.header.ssrc = 0;
58 rtp_info.header.sequenceNumber = seq_no_++;
59 rtp_info.header.payloadType = payload_type;
60 rtp_info.header.timestamp = timestamp;
61 if (frame_type == kFrameEmpty) {
tina.legrand@webrtc.org16b6b902012-04-12 11:02:38 +000062 // Skip this frame
63 return 0;
64 }
niklase@google.com470e71d2011-07-07 08:21:25 +000065
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +000066 if (lost_packet_ == false) {
67 if (frame_type != kAudioFrameCN) {
68 rtp_info.type.Audio.isCNG = false;
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +000069 rtp_info.type.Audio.channel = static_cast<int>(codec_mode_);
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +000070 } else {
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +000071 rtp_info.type.Audio.isCNG = true;
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +000072 rtp_info.type.Audio.channel = static_cast<int>(kMono);
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +000073 }
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +000074 status = receiver_acm_->IncomingPacket(payload_data, payload_size,
tina.legrand@webrtc.org45175852012-06-01 09:27:35 +000075 rtp_info);
niklase@google.com470e71d2011-07-07 08:21:25 +000076
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +000077 if (frame_type != kAudioFrameCN) {
78 payload_size_ = payload_size;
niklase@google.com470e71d2011-07-07 08:21:25 +000079 } else {
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +000080 payload_size_ = -1;
niklase@google.com470e71d2011-07-07 08:21:25 +000081 }
tina.legrand@webrtc.org16b6b902012-04-12 11:02:38 +000082
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +000083 timestamp_diff_ = timestamp - last_in_timestamp_;
84 last_in_timestamp_ = timestamp;
85 total_bytes_ += payload_size;
tina.legrand@webrtc.org16b6b902012-04-12 11:02:38 +000086 }
87 return status;
niklase@google.com470e71d2011-07-07 08:21:25 +000088}
89
pbos@webrtc.org0946a562013-04-09 00:28:06 +000090uint16_t TestPackStereo::payload_size() {
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +000091 return payload_size_;
niklase@google.com470e71d2011-07-07 08:21:25 +000092}
93
pbos@webrtc.org0946a562013-04-09 00:28:06 +000094uint32_t TestPackStereo::timestamp_diff() {
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +000095 return timestamp_diff_;
niklase@google.com470e71d2011-07-07 08:21:25 +000096}
97
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +000098void TestPackStereo::reset_payload_size() {
99 payload_size_ = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000100}
101
tina.legrand@webrtc.org16b6b902012-04-12 11:02:38 +0000102void TestPackStereo::set_codec_mode(enum StereoMonoMode mode) {
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000103 codec_mode_ = mode;
tina.legrand@webrtc.org16b6b902012-04-12 11:02:38 +0000104}
105
106void TestPackStereo::set_lost_packet(bool lost) {
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000107 lost_packet_ = lost;
niklase@google.com470e71d2011-07-07 08:21:25 +0000108}
109
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000110TestStereo::TestStereo(int test_mode)
111 : acm_a_(NULL),
112 acm_b_(NULL),
113 channel_a2b_(NULL),
114 test_cntr_(0),
115 pack_size_samp_(0),
116 pack_size_bytes_(0),
117 counter_(0),
118 g722_pltype_(0),
119 l16_8khz_pltype_(-1),
120 l16_16khz_pltype_(-1),
121 l16_32khz_pltype_(-1),
122 pcma_pltype_(-1),
123 pcmu_pltype_(-1),
124 celt_pltype_(-1),
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000125 opus_pltype_(-1),
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000126 cn_8khz_pltype_(-1),
127 cn_16khz_pltype_(-1),
128 cn_32khz_pltype_(-1) {
tina.legrand@webrtc.org45175852012-06-01 09:27:35 +0000129 // test_mode = 0 for silent test (auto test)
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000130 test_mode_ = test_mode;
niklase@google.com470e71d2011-07-07 08:21:25 +0000131}
132
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000133TestStereo::~TestStereo() {
134 if (acm_a_ != NULL) {
135 AudioCodingModule::Destroy(acm_a_);
136 acm_a_ = NULL;
137 }
138 if (acm_b_ != NULL) {
139 AudioCodingModule::Destroy(acm_b_);
140 acm_b_ = NULL;
141 }
142 if (channel_a2b_ != NULL) {
143 delete channel_a2b_;
144 channel_a2b_ = NULL;
145 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000146}
147
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000148void TestStereo::Perform() {
pbos@webrtc.org0946a562013-04-09 00:28:06 +0000149 uint16_t frequency_hz;
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000150 int audio_channels;
151 int codec_channels;
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000152 bool dtx;
153 bool vad;
154 ACMVADMode vad_mode;
niklase@google.com470e71d2011-07-07 08:21:25 +0000155
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000156 if (test_mode_ == 0) {
157 printf("Running Stereo Test");
158 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioCoding, -1,
159 "---------- TestStereo ----------");
160 }
161
tina.legrand@webrtc.org45175852012-06-01 09:27:35 +0000162 // Open both mono and stereo test files in 32 kHz.
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000163 const std::string file_name_stereo = webrtc::test::ResourcePath(
164 "audio_coding/teststereo32kHz", "pcm");
165 const std::string file_name_mono = webrtc::test::ResourcePath(
166 "audio_coding/testfile32kHz", "pcm");
tina.legrand@webrtc.org45175852012-06-01 09:27:35 +0000167 frequency_hz = 32000;
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000168 in_file_stereo_ = new PCMFile();
169 in_file_mono_ = new PCMFile();
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000170 in_file_stereo_->Open(file_name_stereo, frequency_hz, "rb");
171 in_file_stereo_->ReadStereo(true);
172 in_file_mono_->Open(file_name_mono, frequency_hz, "rb");
173 in_file_mono_->ReadStereo(false);
174
tina.legrand@webrtc.org45175852012-06-01 09:27:35 +0000175 // Create and initialize two ACMs, one for each side of a one-to-one call.
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000176 acm_a_ = AudioCodingModule::Create(0);
177 acm_b_ = AudioCodingModule::Create(1);
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000178 ASSERT_TRUE((acm_a_ != NULL) && (acm_b_ != NULL));
179 EXPECT_EQ(0, acm_a_->InitializeReceiver());
180 EXPECT_EQ(0, acm_b_->InitializeReceiver());
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000181
tina.legrand@webrtc.org45175852012-06-01 09:27:35 +0000182 // Register all available codes as receiving codecs.
pbos@webrtc.org0946a562013-04-09 00:28:06 +0000183 uint8_t num_encoders = acm_a_->NumberOfCodecs();
tina.legrand@webrtc.org45175852012-06-01 09:27:35 +0000184 CodecInst my_codec_param;
pbos@webrtc.org0946a562013-04-09 00:28:06 +0000185 for (uint8_t n = 0; n < num_encoders; n++) {
tina.legrand@webrtc.org7a7a0082013-02-21 10:27:48 +0000186 EXPECT_EQ(0, acm_b_->Codec(n, &my_codec_param));
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000187 EXPECT_EQ(0, acm_b_->RegisterReceiveCodec(my_codec_param));
tina.legrand@webrtc.org45175852012-06-01 09:27:35 +0000188 }
189
190 // Test that unregister all receive codecs works.
pbos@webrtc.org0946a562013-04-09 00:28:06 +0000191 for (uint8_t n = 0; n < num_encoders; n++) {
tina.legrand@webrtc.org7a7a0082013-02-21 10:27:48 +0000192 EXPECT_EQ(0, acm_b_->Codec(n, &my_codec_param));
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000193 EXPECT_EQ(0, acm_b_->UnregisterReceiveCodec(my_codec_param.pltype));
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000194 }
tina.legrand@webrtc.orgae1c4542012-03-12 08:41:30 +0000195
tina.legrand@webrtc.org45175852012-06-01 09:27:35 +0000196 // Register all available codes as receiving codecs once more.
pbos@webrtc.org0946a562013-04-09 00:28:06 +0000197 for (uint8_t n = 0; n < num_encoders; n++) {
tina.legrand@webrtc.org7a7a0082013-02-21 10:27:48 +0000198 EXPECT_EQ(0, acm_b_->Codec(n, &my_codec_param));
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000199 EXPECT_EQ(0, acm_b_->RegisterReceiveCodec(my_codec_param));
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000200 }
tina.legrand@webrtc.orgae1c4542012-03-12 08:41:30 +0000201
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000202 // TODO(tlegrand): Take care of return values of all function calls.
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000203
tina.legrand@webrtc.org45175852012-06-01 09:27:35 +0000204 // TODO(tlegrand): Re-register all stereo codecs needed in the test,
205 // with new payload numbers.
206 // g722_pltype_ = 117;
207 // l16_8khz_pltype_ = 120;
208 // l16_16khz_pltype_ = 121;
209 // l16_32khz_pltype_ = 122;
210 // pcma_pltype_ = 110;
211 // pcmu_pltype_ = 118;
212 // celt_pltype_ = 119;
213 // cn_8khz_pltype_ = 123;
214 // cn_16khz_pltype_ = 124;
215 // cn_32khz_pltype_ = 125;
tina.legrand@webrtc.orgae1c4542012-03-12 08:41:30 +0000216
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000217 // Create and connect the channel.
218 channel_a2b_ = new TestPackStereo;
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000219 EXPECT_EQ(0, acm_a_->RegisterTransportCallback(channel_a2b_));
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000220 channel_a2b_->RegisterReceiverACM(acm_b_);
tina.legrand@webrtc.orgdf697752012-02-08 10:22:21 +0000221
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000222 // Start with setting VAD/DTX, before we know we will send stereo.
223 // Continue with setting a stereo codec as send codec and verify that
224 // VAD/DTX gets turned off.
225 EXPECT_EQ(0, acm_a_->SetVAD(true, true, VADNormal));
tina.legrand@webrtc.org7a7a0082013-02-21 10:27:48 +0000226 EXPECT_EQ(0, acm_a_->VAD(&dtx, &vad, &vad_mode));
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000227 EXPECT_TRUE(dtx);
228 EXPECT_TRUE(vad);
229 char codec_pcma_temp[] = "PCMA";
230 RegisterSendCodec('A', codec_pcma_temp, 8000, 64000, 80, 2, pcma_pltype_);
tina.legrand@webrtc.org7a7a0082013-02-21 10:27:48 +0000231 EXPECT_EQ(0, acm_a_->VAD(&dtx, &vad, &vad_mode));
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000232 EXPECT_FALSE(dtx);
233 EXPECT_FALSE(vad);
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000234 if (test_mode_ != 0) {
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000235 printf("\n");
236 }
237
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000238 //
239 // Test Stereo-To-Stereo for all codecs.
240 //
241 audio_channels = 2;
242 codec_channels = 2;
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000243
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000244 // All codecs are tested for all allowed sampling frequencies, rates and
245 // packet sizes.
niklase@google.com470e71d2011-07-07 08:21:25 +0000246#ifdef WEBRTC_CODEC_G722
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000247 if (test_mode_ != 0) {
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000248 printf("===========================================================\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000249 printf("Test number: %d\n", test_cntr_ + 1);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000250 printf("Test type: Stereo-to-stereo\n");
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000251 }
252 channel_a2b_->set_codec_mode(kStereo);
253 test_cntr_++;
254 OpenOutFile(test_cntr_);
255 char codec_g722[] = "G722";
256 RegisterSendCodec('A', codec_g722, 16000, 64000, 160, codec_channels,
257 g722_pltype_);
258 Run(channel_a2b_, audio_channels, codec_channels);
259 RegisterSendCodec('A', codec_g722, 16000, 64000, 320, codec_channels,
260 g722_pltype_);
261 Run(channel_a2b_, audio_channels, codec_channels);
262 RegisterSendCodec('A', codec_g722, 16000, 64000, 480, codec_channels,
263 g722_pltype_);
264 Run(channel_a2b_, audio_channels, codec_channels);
265 RegisterSendCodec('A', codec_g722, 16000, 64000, 640, codec_channels,
266 g722_pltype_);
267 Run(channel_a2b_, audio_channels, codec_channels);
268 RegisterSendCodec('A', codec_g722, 16000, 64000, 800, codec_channels,
269 g722_pltype_);
270 Run(channel_a2b_, audio_channels, codec_channels);
271 RegisterSendCodec('A', codec_g722, 16000, 64000, 960, codec_channels,
272 g722_pltype_);
273 Run(channel_a2b_, audio_channels, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000274 out_file_.Close();
niklase@google.com470e71d2011-07-07 08:21:25 +0000275#endif
276#ifdef WEBRTC_CODEC_PCM16
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000277 if (test_mode_ != 0) {
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000278 printf("===========================================================\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000279 printf("Test number: %d\n", test_cntr_ + 1);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000280 printf("Test type: Stereo-to-stereo\n");
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000281 }
282 channel_a2b_->set_codec_mode(kStereo);
283 test_cntr_++;
284 OpenOutFile(test_cntr_);
285 char codec_l16[] = "L16";
286 RegisterSendCodec('A', codec_l16, 8000, 128000, 80, codec_channels,
287 l16_8khz_pltype_);
288 Run(channel_a2b_, audio_channels, codec_channels);
289 RegisterSendCodec('A', codec_l16, 8000, 128000, 160, codec_channels,
290 l16_8khz_pltype_);
291 Run(channel_a2b_, audio_channels, codec_channels);
292 RegisterSendCodec('A', codec_l16, 8000, 128000, 240, codec_channels,
293 l16_8khz_pltype_);
294 Run(channel_a2b_, audio_channels, codec_channels);
295 RegisterSendCodec('A', codec_l16, 8000, 128000, 320, codec_channels,
296 l16_8khz_pltype_);
297 Run(channel_a2b_, audio_channels, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000298 out_file_.Close();
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000299
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000300 if (test_mode_ != 0) {
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000301 printf("===========================================================\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000302 printf("Test number: %d\n", test_cntr_ + 1);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000303 printf("Test type: Stereo-to-stereo\n");
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000304 }
305 test_cntr_++;
306 OpenOutFile(test_cntr_);
307 RegisterSendCodec('A', codec_l16, 16000, 256000, 160, codec_channels,
308 l16_16khz_pltype_);
309 Run(channel_a2b_, audio_channels, codec_channels);
310 RegisterSendCodec('A', codec_l16, 16000, 256000, 320, codec_channels,
311 l16_16khz_pltype_);
312 Run(channel_a2b_, audio_channels, codec_channels);
313 RegisterSendCodec('A', codec_l16, 16000, 256000, 480, codec_channels,
314 l16_16khz_pltype_);
315 Run(channel_a2b_, audio_channels, codec_channels);
316 RegisterSendCodec('A', codec_l16, 16000, 256000, 640, codec_channels,
317 l16_16khz_pltype_);
318 Run(channel_a2b_, audio_channels, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000319 out_file_.Close();
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000320
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000321 if (test_mode_ != 0) {
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000322 printf("===========================================================\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000323 printf("Test number: %d\n", test_cntr_ + 1);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000324 printf("Test type: Stereo-to-stereo\n");
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000325 }
326 test_cntr_++;
327 OpenOutFile(test_cntr_);
328 RegisterSendCodec('A', codec_l16, 32000, 512000, 320, codec_channels,
329 l16_32khz_pltype_);
330 Run(channel_a2b_, audio_channels, codec_channels);
331 RegisterSendCodec('A', codec_l16, 32000, 512000, 640, codec_channels,
332 l16_32khz_pltype_);
333 Run(channel_a2b_, audio_channels, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000334 out_file_.Close();
niklase@google.com470e71d2011-07-07 08:21:25 +0000335#endif
336#define PCMA_AND_PCMU
337#ifdef PCMA_AND_PCMU
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000338 if (test_mode_ != 0) {
339 printf("===========================================================\n");
340 printf("Test number: %d\n", test_cntr_ + 1);
341 printf("Test type: Stereo-to-stereo\n");
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000342 }
343 channel_a2b_->set_codec_mode(kStereo);
344 audio_channels = 2;
345 codec_channels = 2;
346 test_cntr_++;
347 OpenOutFile(test_cntr_);
348 char codec_pcma[] = "PCMA";
349 RegisterSendCodec('A', codec_pcma, 8000, 64000, 80, codec_channels,
350 pcma_pltype_);
351 Run(channel_a2b_, audio_channels, codec_channels);
352 RegisterSendCodec('A', codec_pcma, 8000, 64000, 160, codec_channels,
353 pcma_pltype_);
354 Run(channel_a2b_, audio_channels, codec_channels);
355 RegisterSendCodec('A', codec_pcma, 8000, 64000, 240, codec_channels,
356 pcma_pltype_);
357 Run(channel_a2b_, audio_channels, codec_channels);
358 RegisterSendCodec('A', codec_pcma, 8000, 64000, 320, codec_channels,
359 pcma_pltype_);
360 Run(channel_a2b_, audio_channels, codec_channels);
361 RegisterSendCodec('A', codec_pcma, 8000, 64000, 400, codec_channels,
362 pcma_pltype_);
363 Run(channel_a2b_, audio_channels, codec_channels);
364 RegisterSendCodec('A', codec_pcma, 8000, 64000, 480, codec_channels,
365 pcma_pltype_);
366 Run(channel_a2b_, audio_channels, codec_channels);
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000367
368 // Test that VAD/DTX cannot be turned on while sending stereo.
369 EXPECT_EQ(-1, acm_a_->SetVAD(true, true, VADNormal));
tina.legrand@webrtc.org7a7a0082013-02-21 10:27:48 +0000370 EXPECT_EQ(0, acm_a_->VAD(&dtx, &vad, &vad_mode));
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000371 EXPECT_FALSE(dtx);
372 EXPECT_FALSE(vad);
373 EXPECT_EQ(-1, acm_a_->SetVAD(true, false, VADNormal));
tina.legrand@webrtc.org7a7a0082013-02-21 10:27:48 +0000374 EXPECT_EQ(0, acm_a_->VAD(&dtx, &vad, &vad_mode));
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000375 EXPECT_FALSE(dtx);
376 EXPECT_FALSE(vad);
377 EXPECT_EQ(-1, acm_a_->SetVAD(false, true, VADNormal));
tina.legrand@webrtc.org7a7a0082013-02-21 10:27:48 +0000378 EXPECT_EQ(0, acm_a_->VAD(&dtx, &vad, &vad_mode));
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000379 EXPECT_FALSE(dtx);
380 EXPECT_FALSE(vad);
381 EXPECT_EQ(0, acm_a_->SetVAD(false, false, VADNormal));
tina.legrand@webrtc.org7a7a0082013-02-21 10:27:48 +0000382 EXPECT_EQ(0, acm_a_->VAD(&dtx, &vad, &vad_mode));
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000383 EXPECT_FALSE(dtx);
384 EXPECT_FALSE(vad);
385
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000386 out_file_.Close();
387 if (test_mode_ != 0) {
388 printf("===========================================================\n");
389 printf("Test number: %d\n", test_cntr_ + 1);
390 printf("Test type: Stereo-to-stereo\n");
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000391 }
392 test_cntr_++;
393 OpenOutFile(test_cntr_);
394 char codec_pcmu[] = "PCMU";
395 RegisterSendCodec('A', codec_pcmu, 8000, 64000, 80, codec_channels,
396 pcmu_pltype_);
397 Run(channel_a2b_, audio_channels, codec_channels);
398 RegisterSendCodec('A', codec_pcmu, 8000, 64000, 160, codec_channels,
399 pcmu_pltype_);
400 Run(channel_a2b_, audio_channels, codec_channels);
401 RegisterSendCodec('A', codec_pcmu, 8000, 64000, 240, codec_channels,
402 pcmu_pltype_);
403 Run(channel_a2b_, audio_channels, codec_channels);
404 RegisterSendCodec('A', codec_pcmu, 8000, 64000, 320, codec_channels,
405 pcmu_pltype_);
406 Run(channel_a2b_, audio_channels, codec_channels);
407 RegisterSendCodec('A', codec_pcmu, 8000, 64000, 400, codec_channels,
408 pcmu_pltype_);
409 Run(channel_a2b_, audio_channels, codec_channels);
410 RegisterSendCodec('A', codec_pcmu, 8000, 64000, 480, codec_channels,
411 pcmu_pltype_);
412 Run(channel_a2b_, audio_channels, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000413 out_file_.Close();
niklase@google.com470e71d2011-07-07 08:21:25 +0000414#endif
tina.legrand@webrtc.orgdf697752012-02-08 10:22:21 +0000415#ifdef WEBRTC_CODEC_CELT
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000416 if (test_mode_ != 0) {
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000417 printf("===========================================================\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000418 printf("Test number: %d\n", test_cntr_ + 1);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000419 printf("Test type: Stereo-to-stereo\n");
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000420 }
421 channel_a2b_->set_codec_mode(kStereo);
422 audio_channels = 2;
423 codec_channels = 2;
424 test_cntr_++;
425 OpenOutFile(test_cntr_);
426 char codec_celt[] = "CELT";
tina.legrand@webrtc.org90af7f82012-06-07 08:57:27 +0000427 RegisterSendCodec('A', codec_celt, 32000, 48000, 640, codec_channels,
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000428 celt_pltype_);
429 Run(channel_a2b_, audio_channels, codec_channels);
tina.legrand@webrtc.org90af7f82012-06-07 08:57:27 +0000430 RegisterSendCodec('A', codec_celt, 32000, 64000, 640, codec_channels,
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000431 celt_pltype_);
432 Run(channel_a2b_, audio_channels, codec_channels);
tina.legrand@webrtc.org90af7f82012-06-07 08:57:27 +0000433 RegisterSendCodec('A', codec_celt, 32000, 128000, 640, codec_channels,
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000434 celt_pltype_);
435 Run(channel_a2b_, audio_channels, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000436 out_file_.Close();
tina.legrand@webrtc.orgdf697752012-02-08 10:22:21 +0000437#endif
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000438#ifdef WEBRTC_CODEC_OPUS
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000439 if (test_mode_ != 0) {
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000440 printf("===========================================================\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000441 printf("Test number: %d\n", test_cntr_ + 1);
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000442 printf("Test type: Stereo-to-stereo\n");
443 }
444 channel_a2b_->set_codec_mode(kStereo);
445 audio_channels = 2;
446 codec_channels = 2;
447 test_cntr_++;
448 OpenOutFile(test_cntr_);
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000449
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000450 char codec_opus[] = "opus";
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000451 // Run Opus with 10 ms frame size.
452 RegisterSendCodec('A', codec_opus, 48000, 64000, 480, codec_channels,
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000453 opus_pltype_);
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000454 Run(channel_a2b_, audio_channels, codec_channels);
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000455 // Run Opus with 20 ms frame size.
456 RegisterSendCodec('A', codec_opus, 48000, 64000, 480*2, codec_channels,
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000457 opus_pltype_);
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000458 Run(channel_a2b_, audio_channels, codec_channels);
459 // Run Opus with 40 ms frame size.
460 RegisterSendCodec('A', codec_opus, 48000, 64000, 480*4, codec_channels,
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000461 opus_pltype_);
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000462 Run(channel_a2b_, audio_channels, codec_channels);
463 // Run Opus with 60 ms frame size.
464 RegisterSendCodec('A', codec_opus, 48000, 64000, 480*6, codec_channels,
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000465 opus_pltype_);
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000466 Run(channel_a2b_, audio_channels, codec_channels);
467 // Run Opus with 20 ms frame size and different bitrates.
468 RegisterSendCodec('A', codec_opus, 48000, 40000, 960, codec_channels,
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000469 opus_pltype_);
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000470 Run(channel_a2b_, audio_channels, codec_channels);
471 RegisterSendCodec('A', codec_opus, 48000, 510000, 960, codec_channels,
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000472 opus_pltype_);
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000473 Run(channel_a2b_, audio_channels, codec_channels);
474 out_file_.Close();
475#endif
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000476 //
477 // Test Mono-To-Stereo for all codecs.
478 //
479 audio_channels = 1;
480 codec_channels = 2;
niklase@google.com470e71d2011-07-07 08:21:25 +0000481
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000482#ifdef WEBRTC_CODEC_G722
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000483 if (test_mode_ != 0) {
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000484 printf("===============================================================\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000485 printf("Test number: %d\n", test_cntr_ + 1);
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000486 printf("Test type: Mono-to-stereo\n");
487 }
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000488 test_cntr_++;
489 channel_a2b_->set_codec_mode(kStereo);
490 OpenOutFile(test_cntr_);
491 RegisterSendCodec('A', codec_g722, 16000, 64000, 160, codec_channels,
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000492 g722_pltype_);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000493 Run(channel_a2b_, audio_channels, codec_channels);
494 out_file_.Close();
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000495#endif
496#ifdef WEBRTC_CODEC_PCM16
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000497 if (test_mode_ != 0) {
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000498 printf("===============================================================\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000499 printf("Test number: %d\n", test_cntr_ + 1);
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000500 printf("Test type: Mono-to-stereo\n");
501 }
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000502 test_cntr_++;
503 channel_a2b_->set_codec_mode(kStereo);
504 OpenOutFile(test_cntr_);
505 RegisterSendCodec('A', codec_l16, 8000, 128000, 80, codec_channels,
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000506 l16_8khz_pltype_);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000507 Run(channel_a2b_, audio_channels, codec_channels);
508 out_file_.Close();
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000509 if (test_mode_ != 0) {
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000510 printf("===============================================================\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000511 printf("Test number: %d\n", test_cntr_ + 1);
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000512 printf("Test type: Mono-to-stereo\n");
513 }
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000514 test_cntr_++;
515 OpenOutFile(test_cntr_);
516 RegisterSendCodec('A', codec_l16, 16000, 256000, 160, codec_channels,
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000517 l16_16khz_pltype_);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000518 Run(channel_a2b_, audio_channels, codec_channels);
519 out_file_.Close();
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000520 if (test_mode_ != 0) {
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000521 printf("===============================================================\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000522 printf("Test number: %d\n", test_cntr_ + 1);
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000523 printf("Test type: Mono-to-stereo\n");
524 }
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000525 test_cntr_++;
526 OpenOutFile(test_cntr_);
527 RegisterSendCodec('A', codec_l16, 32000, 512000, 320, codec_channels,
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000528 l16_32khz_pltype_);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000529 Run(channel_a2b_, audio_channels, codec_channels);
530 out_file_.Close();
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000531#endif
532#ifdef PCMA_AND_PCMU
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000533 if (test_mode_ != 0) {
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000534 printf("===============================================================\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000535 printf("Test number: %d\n", test_cntr_ + 1);
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000536 printf("Test type: Mono-to-stereo\n");
537 }
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000538 test_cntr_++;
539 channel_a2b_->set_codec_mode(kStereo);
540 OpenOutFile(test_cntr_);
541 RegisterSendCodec('A', codec_pcmu, 8000, 64000, 80, codec_channels,
tina.legrand@webrtc.orgae1c4542012-03-12 08:41:30 +0000542 pcmu_pltype_);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000543 Run(channel_a2b_, audio_channels, codec_channels);
544 RegisterSendCodec('A', codec_pcma, 8000, 64000, 80, codec_channels,
tina.legrand@webrtc.orgae1c4542012-03-12 08:41:30 +0000545 pcma_pltype_);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000546 Run(channel_a2b_, audio_channels, codec_channels);
547 out_file_.Close();
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000548#endif
tina.legrand@webrtc.orgdf697752012-02-08 10:22:21 +0000549#ifdef WEBRTC_CODEC_CELT
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000550 if (test_mode_ != 0) {
tina.legrand@webrtc.orgdf697752012-02-08 10:22:21 +0000551 printf("===============================================================\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000552 printf("Test number: %d\n", test_cntr_ + 1);
tina.legrand@webrtc.orgdf697752012-02-08 10:22:21 +0000553 printf("Test type: Mono-to-stereo\n");
554 }
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000555 test_cntr_++;
556 channel_a2b_->set_codec_mode(kStereo);
557 OpenOutFile(test_cntr_);
tina.legrand@webrtc.org90af7f82012-06-07 08:57:27 +0000558 RegisterSendCodec('A', codec_celt, 32000, 64000, 640, codec_channels,
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000559 celt_pltype_);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000560 Run(channel_a2b_, audio_channels, codec_channels);
561 out_file_.Close();
tina.legrand@webrtc.orgdf697752012-02-08 10:22:21 +0000562#endif
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000563#ifdef WEBRTC_CODEC_OPUS
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000564 if (test_mode_ != 0) {
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000565 printf("===============================================================\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000566 printf("Test number: %d\n", test_cntr_ + 1);
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000567 printf("Test type: Mono-to-stereo\n");
568 }
tina.legrand@webrtc.orgc4590582012-11-28 12:23:29 +0000569
570 // Keep encode and decode in stereo.
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000571 test_cntr_++;
572 channel_a2b_->set_codec_mode(kStereo);
573 OpenOutFile(test_cntr_);
574 RegisterSendCodec('A', codec_opus, 48000, 64000, 960, codec_channels,
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000575 opus_pltype_);
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000576 Run(channel_a2b_, audio_channels, codec_channels);
tina.legrand@webrtc.orgc4590582012-11-28 12:23:29 +0000577
578 // Encode in mono, decode in stereo mode.
579 RegisterSendCodec('A', codec_opus, 48000, 64000, 960, 1, opus_pltype_);
580 Run(channel_a2b_, audio_channels, codec_channels);
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000581 out_file_.Close();
582#endif
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000583
584 //
585 // Test Stereo-To-Mono for all codecs.
586 //
587 audio_channels = 2;
588 codec_channels = 1;
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000589 channel_a2b_->set_codec_mode(kMono);
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000590
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000591#ifdef WEBRTC_CODEC_G722
592 // Run stereo audio and mono codec.
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000593 if (test_mode_ != 0) {
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000594 printf("===============================================================\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000595 printf("Test number: %d\n", test_cntr_ + 1);
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000596 printf("Test type: Stereo-to-mono\n");
597 }
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000598 test_cntr_++;
599 OpenOutFile(test_cntr_);
600 RegisterSendCodec('A', codec_g722, 16000, 64000, 160, codec_channels,
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000601 g722_pltype_);
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000602
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.org7a7a0082013-02-21 10:27:48 +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.orgd5726a12013-05-03 07:34:12 +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.orgd5726a12013-05-03 07:34:12 +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.orgd5726a12013-05-03 07:34:12 +0000637 printf("==============================================================\n");
638 printf("Test number: %d\n", test_cntr_ + 1);
639 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,
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000644 l16_32khz_pltype_);
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000645 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.orgd5726a12013-05-03 07:34:12 +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,
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000687 opus_pltype_);
tina.legrand@webrtc.orgc4590582012-11-28 12:23:29 +0000688 CodecInst opus_codec_param;
pbos@webrtc.org0946a562013-04-09 00:28:06 +0000689 for (uint8_t n = 0; n < num_encoders; n++) {
tina.legrand@webrtc.org7a7a0082013-02-21 10:27:48 +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,
pbos@webrtc.org0946a562013-04-09 00:28:06 +0000780 int32_t sampling_freq_hz, int rate,
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000781 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")) {
pbos@webrtc.org0946a562013-04-09 00:28:06 +0000796 pack_size_bytes_ = (uint16_t)(
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000797 static_cast<float>(pack_size * rate) /
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000798 static_cast<float>(sampling_freq_hz * 8) + 0.875) / channels;
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000799 } else {
pbos@webrtc.org0946a562013-04-09 00:28:06 +0000800 pack_size_bytes_ = (uint16_t)(
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000801 static_cast<float>(pack_size * rate) /
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000802 static_cast<float>(sampling_freq_hz * 8) + 0.875);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000803 }
804
805 // Set pointer to the ACM where to register the codec
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000806 AudioCodingModule* my_acm = NULL;
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000807 switch (side) {
808 case 'A': {
809 my_acm = acm_a_;
810 break;
niklase@google.com470e71d2011-07-07 08:21:25 +0000811 }
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000812 case 'B': {
813 my_acm = acm_b_;
814 break;
tina.legrand@webrtc.org16b6b902012-04-12 11:02:38 +0000815 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000816 default:
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000817 break;
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000818 }
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000819 ASSERT_TRUE(my_acm != NULL);
niklase@google.com470e71d2011-07-07 08:21:25 +0000820
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000821 CodecInst my_codec_param;
822 // Get all codec parameters before registering
tina.legrand@webrtc.org7a7a0082013-02-21 10:27:48 +0000823 CHECK_ERROR(AudioCodingModule::Codec(codec_name, &my_codec_param,
tina.legrand@webrtc.org45175852012-06-01 09:27:35 +0000824 sampling_freq_hz, channels));
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000825 my_codec_param.rate = rate;
826 my_codec_param.pacsize = pack_size;
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000827 CHECK_ERROR(my_acm->RegisterSendCodec(my_codec_param));
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000828
829 send_codec_name_ = codec_name;
niklase@google.com470e71d2011-07-07 08:21:25 +0000830}
831
tina.legrand@webrtc.org16b6b902012-04-12 11:02:38 +0000832void TestStereo::Run(TestPackStereo* channel, int in_channels, int out_channels,
833 int percent_loss) {
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000834 AudioFrame audio_frame;
niklase@google.com470e71d2011-07-07 08:21:25 +0000835
pbos@webrtc.org0946a562013-04-09 00:28:06 +0000836 int32_t out_freq_hz_b = out_file_.SamplingFrequency();
837 uint16_t rec_size;
838 uint32_t time_stamp_diff;
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000839 channel->reset_payload_size();
840 int error_count = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000841
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000842 while (1) {
843 // Simulate packet loss by setting |packet_loss_| to "true" in
844 // |percent_loss| percent of the loops.
845 if (percent_loss > 0) {
846 if (counter_ == floor((100 / percent_loss) + 0.5)) {
847 counter_ = 0;
848 channel->set_lost_packet(true);
849 } else {
850 channel->set_lost_packet(false);
851 }
852 counter_++;
niklase@google.com470e71d2011-07-07 08:21:25 +0000853 }
854
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000855 // Add 10 msec to ACM
856 if (in_channels == 1) {
857 if (in_file_mono_->EndOfFile()) {
858 break;
859 }
860 in_file_mono_->Read10MsData(audio_frame);
861 } else {
862 if (in_file_stereo_->EndOfFile()) {
863 break;
864 }
865 in_file_stereo_->Read10MsData(audio_frame);
866 }
867 CHECK_ERROR(acm_a_->Add10MsData(audio_frame));
868
869 // Run sender side of ACM
870 CHECK_ERROR(acm_a_->Process());
871
872 // Verify that the received packet size matches the settings
873 rec_size = channel->payload_size();
874 if ((0 < rec_size) & (rec_size < 65535)) {
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000875 // Opus is variable rate, skip this test.
876 if (strcmp(send_codec_name_, "opus")) {
877 if ((rec_size != pack_size_bytes_ * out_channels)
878 && (pack_size_bytes_ < 65535)) {
879 error_count++;
880 }
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000881 }
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000882 // Verify that the timestamp is updated with expected length
883 time_stamp_diff = channel->timestamp_diff();
884 if ((counter_ > 10) && (time_stamp_diff != pack_size_samp_)) {
885 error_count++;
886 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000887 }
888
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000889 // Run received side of ACM
tina.legrand@webrtc.org7a7a0082013-02-21 10:27:48 +0000890 CHECK_ERROR(acm_b_->PlayoutData10Ms(out_freq_hz_b, &audio_frame));
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000891
892 // Write output speech to file
893 out_file_.Write10MsData(
andrew@webrtc.org63a50982012-05-02 23:56:37 +0000894 audio_frame.data_,
895 audio_frame.samples_per_channel_ * audio_frame.num_channels_);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000896 }
897
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000898 EXPECT_EQ(0, error_count);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000899
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000900 if (in_file_mono_->EndOfFile()) {
901 in_file_mono_->Rewind();
902 }
903 if (in_file_stereo_->EndOfFile()) {
904 in_file_stereo_->Rewind();
905 }
906 // Reset in case we ended with a lost packet
907 channel->set_lost_packet(false);
niklase@google.com470e71d2011-07-07 08:21:25 +0000908}
909
pbos@webrtc.org0946a562013-04-09 00:28:06 +0000910void TestStereo::OpenOutFile(int16_t test_number) {
tina.legrand@webrtc.orgba468042012-08-17 10:38:28 +0000911 std::string file_name;
912 std::stringstream file_stream;
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000913 file_stream << webrtc::test::OutputPath() << "teststereo_out_" << test_number
914 << ".pcm";
tina.legrand@webrtc.orgba468042012-08-17 10:38:28 +0000915 file_name = file_stream.str();
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000916 out_file_.Open(file_name, 32000, "wb");
niklase@google.com470e71d2011-07-07 08:21:25 +0000917}
918
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000919void TestStereo::DisplaySendReceiveCodec() {
920 CodecInst my_codec_param;
tina.legrand@webrtc.org7a7a0082013-02-21 10:27:48 +0000921 acm_a_->SendCodec(&my_codec_param);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000922 if (test_mode_ != 0) {
923 printf("%s -> ", my_codec_param.plname);
924 }
tina.legrand@webrtc.org7a7a0082013-02-21 10:27:48 +0000925 acm_b_->ReceiveCodec(&my_codec_param);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000926 if (test_mode_ != 0) {
927 printf("%s\n", my_codec_param.plname);
928 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000929}
930
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000931} // namespace webrtc