blob: 9a0bf9e7910a7d8a3ba92ec964f65767e6ea422d [file] [log] [blame]
niklase@google.com470e71d2011-07-07 08:21:25 +00001/*
tina.legrand@webrtc.orgdf697752012-02-08 10:22:21 +00002 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
niklase@google.com470e71d2011-07-07 08:21:25 +00003 *
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +000011#include "webrtc/modules/audio_coding/main/test/TestStereo.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000012
pbos@webrtc.org12dc1a32013-08-05 16:22:53 +000013#include <assert.h>
14
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +000015#include <string>
kjellander@webrtc.org5490c712011-12-21 13:34:18 +000016
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +000017#include "gtest/gtest.h"
18
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +000019#include "webrtc/common_types.h"
20#include "webrtc/engine_configurations.h"
21#include "webrtc/modules/audio_coding/main/interface/audio_coding_module_typedefs.h"
22#include "webrtc/modules/audio_coding/main/test/utility.h"
23#include "webrtc/system_wrappers/interface/trace.h"
24#include "webrtc/test/testsupport/fileutils.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000025
tina.legrand@webrtc.org554ae1a2011-12-16 10:09:04 +000026namespace webrtc {
niklase@google.com470e71d2011-07-07 08:21:25 +000027
28// Class for simulating packet handling
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +000029TestPackStereo::TestPackStereo()
30 : receiver_acm_(NULL),
31 seq_no_(0),
32 timestamp_diff_(0),
33 last_in_timestamp_(0),
34 total_bytes_(0),
35 payload_size_(0),
36 codec_mode_(kNotSet),
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000037 lost_packet_(false) {
38}
niklase@google.com470e71d2011-07-07 08:21:25 +000039
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000040TestPackStereo::~TestPackStereo() {
41}
niklase@google.com470e71d2011-07-07 08:21:25 +000042
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +000043void TestPackStereo::RegisterReceiverACM(AudioCodingModule* acm) {
44 receiver_acm_ = acm;
45 return;
46}
niklase@google.com470e71d2011-07-07 08:21:25 +000047
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000048int32_t TestPackStereo::SendData(const FrameType frame_type,
49 const uint8_t payload_type,
50 const uint32_t timestamp,
51 const uint8_t* payload_data,
52 const uint16_t payload_size,
53 const RTPFragmentationHeader* fragmentation) {
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +000054 WebRtcRTPHeader rtp_info;
pbos@webrtc.org0946a562013-04-09 00:28:06 +000055 int32_t status = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +000056
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +000057 rtp_info.header.markerBit = false;
58 rtp_info.header.ssrc = 0;
59 rtp_info.header.sequenceNumber = seq_no_++;
60 rtp_info.header.payloadType = payload_type;
61 rtp_info.header.timestamp = timestamp;
62 if (frame_type == kFrameEmpty) {
tina.legrand@webrtc.org16b6b902012-04-12 11:02:38 +000063 // Skip this frame
64 return 0;
65 }
niklase@google.com470e71d2011-07-07 08:21:25 +000066
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +000067 if (lost_packet_ == false) {
68 if (frame_type != kAudioFrameCN) {
69 rtp_info.type.Audio.isCNG = false;
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +000070 rtp_info.type.Audio.channel = static_cast<int>(codec_mode_);
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +000071 } else {
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +000072 rtp_info.type.Audio.isCNG = true;
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +000073 rtp_info.type.Audio.channel = static_cast<int>(kMono);
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +000074 }
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +000075 status = receiver_acm_->IncomingPacket(payload_data, payload_size,
tina.legrand@webrtc.org45175852012-06-01 09:27:35 +000076 rtp_info);
niklase@google.com470e71d2011-07-07 08:21:25 +000077
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +000078 if (frame_type != kAudioFrameCN) {
79 payload_size_ = payload_size;
niklase@google.com470e71d2011-07-07 08:21:25 +000080 } else {
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +000081 payload_size_ = -1;
niklase@google.com470e71d2011-07-07 08:21:25 +000082 }
tina.legrand@webrtc.org16b6b902012-04-12 11:02:38 +000083
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +000084 timestamp_diff_ = timestamp - last_in_timestamp_;
85 last_in_timestamp_ = timestamp;
86 total_bytes_ += payload_size;
tina.legrand@webrtc.org16b6b902012-04-12 11:02:38 +000087 }
88 return status;
niklase@google.com470e71d2011-07-07 08:21:25 +000089}
90
pbos@webrtc.org0946a562013-04-09 00:28:06 +000091uint16_t TestPackStereo::payload_size() {
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +000092 return payload_size_;
niklase@google.com470e71d2011-07-07 08:21:25 +000093}
94
pbos@webrtc.org0946a562013-04-09 00:28:06 +000095uint32_t TestPackStereo::timestamp_diff() {
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +000096 return timestamp_diff_;
niklase@google.com470e71d2011-07-07 08:21:25 +000097}
98
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +000099void TestPackStereo::reset_payload_size() {
100 payload_size_ = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000101}
102
tina.legrand@webrtc.org16b6b902012-04-12 11:02:38 +0000103void TestPackStereo::set_codec_mode(enum StereoMonoMode mode) {
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000104 codec_mode_ = mode;
tina.legrand@webrtc.org16b6b902012-04-12 11:02:38 +0000105}
106
107void TestPackStereo::set_lost_packet(bool lost) {
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000108 lost_packet_ = lost;
niklase@google.com470e71d2011-07-07 08:21:25 +0000109}
110
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000111TestStereo::TestStereo(int test_mode)
112 : acm_a_(NULL),
113 acm_b_(NULL),
114 channel_a2b_(NULL),
115 test_cntr_(0),
116 pack_size_samp_(0),
117 pack_size_bytes_(0),
118 counter_(0),
119 g722_pltype_(0),
120 l16_8khz_pltype_(-1),
121 l16_16khz_pltype_(-1),
122 l16_32khz_pltype_(-1),
123 pcma_pltype_(-1),
124 pcmu_pltype_(-1),
125 celt_pltype_(-1),
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000126 opus_pltype_(-1),
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000127 cn_8khz_pltype_(-1),
128 cn_16khz_pltype_(-1),
129 cn_32khz_pltype_(-1) {
tina.legrand@webrtc.org45175852012-06-01 09:27:35 +0000130 // test_mode = 0 for silent test (auto test)
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000131 test_mode_ = test_mode;
niklase@google.com470e71d2011-07-07 08:21:25 +0000132}
133
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000134TestStereo::~TestStereo() {
135 if (acm_a_ != NULL) {
136 AudioCodingModule::Destroy(acm_a_);
137 acm_a_ = NULL;
138 }
139 if (acm_b_ != NULL) {
140 AudioCodingModule::Destroy(acm_b_);
141 acm_b_ = NULL;
142 }
143 if (channel_a2b_ != NULL) {
144 delete channel_a2b_;
145 channel_a2b_ = NULL;
146 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000147}
148
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000149void TestStereo::Perform() {
pbos@webrtc.org0946a562013-04-09 00:28:06 +0000150 uint16_t frequency_hz;
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000151 int audio_channels;
152 int codec_channels;
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000153 bool dtx;
154 bool vad;
155 ACMVADMode vad_mode;
niklase@google.com470e71d2011-07-07 08:21:25 +0000156
tina.legrand@webrtc.org45175852012-06-01 09:27:35 +0000157 // Open both mono and stereo test files in 32 kHz.
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000158 const std::string file_name_stereo = webrtc::test::ResourcePath(
159 "audio_coding/teststereo32kHz", "pcm");
160 const std::string file_name_mono = webrtc::test::ResourcePath(
161 "audio_coding/testfile32kHz", "pcm");
tina.legrand@webrtc.org45175852012-06-01 09:27:35 +0000162 frequency_hz = 32000;
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000163 in_file_stereo_ = new PCMFile();
164 in_file_mono_ = new PCMFile();
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000165 in_file_stereo_->Open(file_name_stereo, frequency_hz, "rb");
166 in_file_stereo_->ReadStereo(true);
167 in_file_mono_->Open(file_name_mono, frequency_hz, "rb");
168 in_file_mono_->ReadStereo(false);
169
tina.legrand@webrtc.org45175852012-06-01 09:27:35 +0000170 // Create and initialize two ACMs, one for each side of a one-to-one call.
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000171 acm_a_ = AudioCodingModule::Create(0);
172 acm_b_ = AudioCodingModule::Create(1);
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000173 ASSERT_TRUE((acm_a_ != NULL) && (acm_b_ != NULL));
174 EXPECT_EQ(0, acm_a_->InitializeReceiver());
175 EXPECT_EQ(0, acm_b_->InitializeReceiver());
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000176
tina.legrand@webrtc.org45175852012-06-01 09:27:35 +0000177 // Register all available codes as receiving codecs.
pbos@webrtc.org0946a562013-04-09 00:28:06 +0000178 uint8_t num_encoders = acm_a_->NumberOfCodecs();
tina.legrand@webrtc.org45175852012-06-01 09:27:35 +0000179 CodecInst my_codec_param;
pbos@webrtc.org0946a562013-04-09 00:28:06 +0000180 for (uint8_t n = 0; n < num_encoders; n++) {
tina.legrand@webrtc.org7a7a0082013-02-21 10:27:48 +0000181 EXPECT_EQ(0, acm_b_->Codec(n, &my_codec_param));
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000182 EXPECT_EQ(0, acm_b_->RegisterReceiveCodec(my_codec_param));
tina.legrand@webrtc.org45175852012-06-01 09:27:35 +0000183 }
184
185 // Test that unregister all receive codecs works.
pbos@webrtc.org0946a562013-04-09 00:28:06 +0000186 for (uint8_t n = 0; n < num_encoders; n++) {
tina.legrand@webrtc.org7a7a0082013-02-21 10:27:48 +0000187 EXPECT_EQ(0, acm_b_->Codec(n, &my_codec_param));
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000188 EXPECT_EQ(0, acm_b_->UnregisterReceiveCodec(my_codec_param.pltype));
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000189 }
tina.legrand@webrtc.orgae1c4542012-03-12 08:41:30 +0000190
tina.legrand@webrtc.org45175852012-06-01 09:27:35 +0000191 // Register all available codes as receiving codecs once more.
pbos@webrtc.org0946a562013-04-09 00:28:06 +0000192 for (uint8_t n = 0; n < num_encoders; n++) {
tina.legrand@webrtc.org7a7a0082013-02-21 10:27:48 +0000193 EXPECT_EQ(0, acm_b_->Codec(n, &my_codec_param));
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000194 EXPECT_EQ(0, acm_b_->RegisterReceiveCodec(my_codec_param));
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000195 }
tina.legrand@webrtc.orgae1c4542012-03-12 08:41:30 +0000196
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000197 // Create and connect the channel.
198 channel_a2b_ = new TestPackStereo;
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000199 EXPECT_EQ(0, acm_a_->RegisterTransportCallback(channel_a2b_));
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000200 channel_a2b_->RegisterReceiverACM(acm_b_);
tina.legrand@webrtc.orgdf697752012-02-08 10:22:21 +0000201
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000202 // Start with setting VAD/DTX, before we know we will send stereo.
203 // Continue with setting a stereo codec as send codec and verify that
204 // VAD/DTX gets turned off.
205 EXPECT_EQ(0, acm_a_->SetVAD(true, true, VADNormal));
tina.legrand@webrtc.org7a7a0082013-02-21 10:27:48 +0000206 EXPECT_EQ(0, acm_a_->VAD(&dtx, &vad, &vad_mode));
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000207 EXPECT_TRUE(dtx);
208 EXPECT_TRUE(vad);
209 char codec_pcma_temp[] = "PCMA";
210 RegisterSendCodec('A', codec_pcma_temp, 8000, 64000, 80, 2, pcma_pltype_);
tina.legrand@webrtc.org7a7a0082013-02-21 10:27:48 +0000211 EXPECT_EQ(0, acm_a_->VAD(&dtx, &vad, &vad_mode));
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000212 EXPECT_FALSE(dtx);
213 EXPECT_FALSE(vad);
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000214 if (test_mode_ != 0) {
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000215 printf("\n");
216 }
217
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000218 //
219 // Test Stereo-To-Stereo for all codecs.
220 //
221 audio_channels = 2;
222 codec_channels = 2;
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000223
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000224 // All codecs are tested for all allowed sampling frequencies, rates and
225 // packet sizes.
niklase@google.com470e71d2011-07-07 08:21:25 +0000226#ifdef WEBRTC_CODEC_G722
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000227 if (test_mode_ != 0) {
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000228 printf("===========================================================\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000229 printf("Test number: %d\n", test_cntr_ + 1);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000230 printf("Test type: Stereo-to-stereo\n");
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000231 }
232 channel_a2b_->set_codec_mode(kStereo);
233 test_cntr_++;
234 OpenOutFile(test_cntr_);
235 char codec_g722[] = "G722";
236 RegisterSendCodec('A', codec_g722, 16000, 64000, 160, codec_channels,
237 g722_pltype_);
238 Run(channel_a2b_, audio_channels, codec_channels);
239 RegisterSendCodec('A', codec_g722, 16000, 64000, 320, codec_channels,
240 g722_pltype_);
241 Run(channel_a2b_, audio_channels, codec_channels);
242 RegisterSendCodec('A', codec_g722, 16000, 64000, 480, codec_channels,
243 g722_pltype_);
244 Run(channel_a2b_, audio_channels, codec_channels);
245 RegisterSendCodec('A', codec_g722, 16000, 64000, 640, codec_channels,
246 g722_pltype_);
247 Run(channel_a2b_, audio_channels, codec_channels);
248 RegisterSendCodec('A', codec_g722, 16000, 64000, 800, codec_channels,
249 g722_pltype_);
250 Run(channel_a2b_, audio_channels, codec_channels);
251 RegisterSendCodec('A', codec_g722, 16000, 64000, 960, codec_channels,
252 g722_pltype_);
253 Run(channel_a2b_, audio_channels, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000254 out_file_.Close();
niklase@google.com470e71d2011-07-07 08:21:25 +0000255#endif
256#ifdef WEBRTC_CODEC_PCM16
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000257 if (test_mode_ != 0) {
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000258 printf("===========================================================\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000259 printf("Test number: %d\n", test_cntr_ + 1);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000260 printf("Test type: Stereo-to-stereo\n");
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000261 }
262 channel_a2b_->set_codec_mode(kStereo);
263 test_cntr_++;
264 OpenOutFile(test_cntr_);
265 char codec_l16[] = "L16";
266 RegisterSendCodec('A', codec_l16, 8000, 128000, 80, codec_channels,
267 l16_8khz_pltype_);
268 Run(channel_a2b_, audio_channels, codec_channels);
269 RegisterSendCodec('A', codec_l16, 8000, 128000, 160, codec_channels,
270 l16_8khz_pltype_);
271 Run(channel_a2b_, audio_channels, codec_channels);
272 RegisterSendCodec('A', codec_l16, 8000, 128000, 240, codec_channels,
273 l16_8khz_pltype_);
274 Run(channel_a2b_, audio_channels, codec_channels);
275 RegisterSendCodec('A', codec_l16, 8000, 128000, 320, codec_channels,
276 l16_8khz_pltype_);
277 Run(channel_a2b_, audio_channels, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000278 out_file_.Close();
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000279
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000280 if (test_mode_ != 0) {
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000281 printf("===========================================================\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000282 printf("Test number: %d\n", test_cntr_ + 1);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000283 printf("Test type: Stereo-to-stereo\n");
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000284 }
285 test_cntr_++;
286 OpenOutFile(test_cntr_);
287 RegisterSendCodec('A', codec_l16, 16000, 256000, 160, codec_channels,
288 l16_16khz_pltype_);
289 Run(channel_a2b_, audio_channels, codec_channels);
290 RegisterSendCodec('A', codec_l16, 16000, 256000, 320, codec_channels,
291 l16_16khz_pltype_);
292 Run(channel_a2b_, audio_channels, codec_channels);
293 RegisterSendCodec('A', codec_l16, 16000, 256000, 480, codec_channels,
294 l16_16khz_pltype_);
295 Run(channel_a2b_, audio_channels, codec_channels);
296 RegisterSendCodec('A', codec_l16, 16000, 256000, 640, codec_channels,
297 l16_16khz_pltype_);
298 Run(channel_a2b_, audio_channels, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000299 out_file_.Close();
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000300
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000301 if (test_mode_ != 0) {
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000302 printf("===========================================================\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000303 printf("Test number: %d\n", test_cntr_ + 1);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000304 printf("Test type: Stereo-to-stereo\n");
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000305 }
306 test_cntr_++;
307 OpenOutFile(test_cntr_);
308 RegisterSendCodec('A', codec_l16, 32000, 512000, 320, codec_channels,
309 l16_32khz_pltype_);
310 Run(channel_a2b_, audio_channels, codec_channels);
311 RegisterSendCodec('A', codec_l16, 32000, 512000, 640, codec_channels,
312 l16_32khz_pltype_);
313 Run(channel_a2b_, audio_channels, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000314 out_file_.Close();
niklase@google.com470e71d2011-07-07 08:21:25 +0000315#endif
316#define PCMA_AND_PCMU
317#ifdef PCMA_AND_PCMU
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000318 if (test_mode_ != 0) {
319 printf("===========================================================\n");
320 printf("Test number: %d\n", test_cntr_ + 1);
321 printf("Test type: Stereo-to-stereo\n");
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000322 }
323 channel_a2b_->set_codec_mode(kStereo);
324 audio_channels = 2;
325 codec_channels = 2;
326 test_cntr_++;
327 OpenOutFile(test_cntr_);
328 char codec_pcma[] = "PCMA";
329 RegisterSendCodec('A', codec_pcma, 8000, 64000, 80, codec_channels,
330 pcma_pltype_);
331 Run(channel_a2b_, audio_channels, codec_channels);
332 RegisterSendCodec('A', codec_pcma, 8000, 64000, 160, codec_channels,
333 pcma_pltype_);
334 Run(channel_a2b_, audio_channels, codec_channels);
335 RegisterSendCodec('A', codec_pcma, 8000, 64000, 240, codec_channels,
336 pcma_pltype_);
337 Run(channel_a2b_, audio_channels, codec_channels);
338 RegisterSendCodec('A', codec_pcma, 8000, 64000, 320, codec_channels,
339 pcma_pltype_);
340 Run(channel_a2b_, audio_channels, codec_channels);
341 RegisterSendCodec('A', codec_pcma, 8000, 64000, 400, codec_channels,
342 pcma_pltype_);
343 Run(channel_a2b_, audio_channels, codec_channels);
344 RegisterSendCodec('A', codec_pcma, 8000, 64000, 480, codec_channels,
345 pcma_pltype_);
346 Run(channel_a2b_, audio_channels, codec_channels);
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000347
348 // Test that VAD/DTX cannot be turned on while sending stereo.
349 EXPECT_EQ(-1, acm_a_->SetVAD(true, true, VADNormal));
tina.legrand@webrtc.org7a7a0082013-02-21 10:27:48 +0000350 EXPECT_EQ(0, acm_a_->VAD(&dtx, &vad, &vad_mode));
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000351 EXPECT_FALSE(dtx);
352 EXPECT_FALSE(vad);
353 EXPECT_EQ(-1, acm_a_->SetVAD(true, false, VADNormal));
tina.legrand@webrtc.org7a7a0082013-02-21 10:27:48 +0000354 EXPECT_EQ(0, acm_a_->VAD(&dtx, &vad, &vad_mode));
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000355 EXPECT_FALSE(dtx);
356 EXPECT_FALSE(vad);
357 EXPECT_EQ(-1, acm_a_->SetVAD(false, true, VADNormal));
tina.legrand@webrtc.org7a7a0082013-02-21 10:27:48 +0000358 EXPECT_EQ(0, acm_a_->VAD(&dtx, &vad, &vad_mode));
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000359 EXPECT_FALSE(dtx);
360 EXPECT_FALSE(vad);
361 EXPECT_EQ(0, acm_a_->SetVAD(false, false, VADNormal));
tina.legrand@webrtc.org7a7a0082013-02-21 10:27:48 +0000362 EXPECT_EQ(0, acm_a_->VAD(&dtx, &vad, &vad_mode));
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000363 EXPECT_FALSE(dtx);
364 EXPECT_FALSE(vad);
365
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000366 out_file_.Close();
367 if (test_mode_ != 0) {
368 printf("===========================================================\n");
369 printf("Test number: %d\n", test_cntr_ + 1);
370 printf("Test type: Stereo-to-stereo\n");
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000371 }
372 test_cntr_++;
373 OpenOutFile(test_cntr_);
374 char codec_pcmu[] = "PCMU";
375 RegisterSendCodec('A', codec_pcmu, 8000, 64000, 80, codec_channels,
376 pcmu_pltype_);
377 Run(channel_a2b_, audio_channels, codec_channels);
378 RegisterSendCodec('A', codec_pcmu, 8000, 64000, 160, codec_channels,
379 pcmu_pltype_);
380 Run(channel_a2b_, audio_channels, codec_channels);
381 RegisterSendCodec('A', codec_pcmu, 8000, 64000, 240, codec_channels,
382 pcmu_pltype_);
383 Run(channel_a2b_, audio_channels, codec_channels);
384 RegisterSendCodec('A', codec_pcmu, 8000, 64000, 320, codec_channels,
385 pcmu_pltype_);
386 Run(channel_a2b_, audio_channels, codec_channels);
387 RegisterSendCodec('A', codec_pcmu, 8000, 64000, 400, codec_channels,
388 pcmu_pltype_);
389 Run(channel_a2b_, audio_channels, codec_channels);
390 RegisterSendCodec('A', codec_pcmu, 8000, 64000, 480, codec_channels,
391 pcmu_pltype_);
392 Run(channel_a2b_, audio_channels, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000393 out_file_.Close();
niklase@google.com470e71d2011-07-07 08:21:25 +0000394#endif
tina.legrand@webrtc.orgdf697752012-02-08 10:22:21 +0000395#ifdef WEBRTC_CODEC_CELT
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000396 if (test_mode_ != 0) {
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000397 printf("===========================================================\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000398 printf("Test number: %d\n", test_cntr_ + 1);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000399 printf("Test type: Stereo-to-stereo\n");
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000400 }
401 channel_a2b_->set_codec_mode(kStereo);
402 audio_channels = 2;
403 codec_channels = 2;
404 test_cntr_++;
405 OpenOutFile(test_cntr_);
406 char codec_celt[] = "CELT";
tina.legrand@webrtc.org90af7f82012-06-07 08:57:27 +0000407 RegisterSendCodec('A', codec_celt, 32000, 48000, 640, codec_channels,
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000408 celt_pltype_);
409 Run(channel_a2b_, audio_channels, codec_channels);
tina.legrand@webrtc.org90af7f82012-06-07 08:57:27 +0000410 RegisterSendCodec('A', codec_celt, 32000, 64000, 640, codec_channels,
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000411 celt_pltype_);
412 Run(channel_a2b_, audio_channels, codec_channels);
tina.legrand@webrtc.org90af7f82012-06-07 08:57:27 +0000413 RegisterSendCodec('A', codec_celt, 32000, 128000, 640, codec_channels,
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000414 celt_pltype_);
415 Run(channel_a2b_, audio_channels, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000416 out_file_.Close();
tina.legrand@webrtc.orgdf697752012-02-08 10:22:21 +0000417#endif
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000418#ifdef WEBRTC_CODEC_OPUS
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000419 if (test_mode_ != 0) {
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000420 printf("===========================================================\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000421 printf("Test number: %d\n", test_cntr_ + 1);
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000422 printf("Test type: Stereo-to-stereo\n");
423 }
424 channel_a2b_->set_codec_mode(kStereo);
425 audio_channels = 2;
426 codec_channels = 2;
427 test_cntr_++;
428 OpenOutFile(test_cntr_);
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000429
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000430 char codec_opus[] = "opus";
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000431 // Run Opus with 10 ms frame size.
432 RegisterSendCodec('A', codec_opus, 48000, 64000, 480, codec_channels,
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000433 opus_pltype_);
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000434 Run(channel_a2b_, audio_channels, codec_channels);
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000435 // Run Opus with 20 ms frame size.
436 RegisterSendCodec('A', codec_opus, 48000, 64000, 480*2, codec_channels,
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000437 opus_pltype_);
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000438 Run(channel_a2b_, audio_channels, codec_channels);
439 // Run Opus with 40 ms frame size.
440 RegisterSendCodec('A', codec_opus, 48000, 64000, 480*4, codec_channels,
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000441 opus_pltype_);
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000442 Run(channel_a2b_, audio_channels, codec_channels);
443 // Run Opus with 60 ms frame size.
444 RegisterSendCodec('A', codec_opus, 48000, 64000, 480*6, codec_channels,
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000445 opus_pltype_);
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000446 Run(channel_a2b_, audio_channels, codec_channels);
447 // Run Opus with 20 ms frame size and different bitrates.
448 RegisterSendCodec('A', codec_opus, 48000, 40000, 960, codec_channels,
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000449 opus_pltype_);
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000450 Run(channel_a2b_, audio_channels, codec_channels);
451 RegisterSendCodec('A', codec_opus, 48000, 510000, 960, codec_channels,
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000452 opus_pltype_);
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000453 Run(channel_a2b_, audio_channels, codec_channels);
454 out_file_.Close();
455#endif
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000456 //
457 // Test Mono-To-Stereo for all codecs.
458 //
459 audio_channels = 1;
460 codec_channels = 2;
niklase@google.com470e71d2011-07-07 08:21:25 +0000461
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000462#ifdef WEBRTC_CODEC_G722
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000463 if (test_mode_ != 0) {
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000464 printf("===============================================================\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000465 printf("Test number: %d\n", test_cntr_ + 1);
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000466 printf("Test type: Mono-to-stereo\n");
467 }
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000468 test_cntr_++;
469 channel_a2b_->set_codec_mode(kStereo);
470 OpenOutFile(test_cntr_);
471 RegisterSendCodec('A', codec_g722, 16000, 64000, 160, codec_channels,
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000472 g722_pltype_);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000473 Run(channel_a2b_, audio_channels, codec_channels);
474 out_file_.Close();
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000475#endif
476#ifdef WEBRTC_CODEC_PCM16
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000477 if (test_mode_ != 0) {
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000478 printf("===============================================================\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000479 printf("Test number: %d\n", test_cntr_ + 1);
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000480 printf("Test type: Mono-to-stereo\n");
481 }
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000482 test_cntr_++;
483 channel_a2b_->set_codec_mode(kStereo);
484 OpenOutFile(test_cntr_);
485 RegisterSendCodec('A', codec_l16, 8000, 128000, 80, codec_channels,
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000486 l16_8khz_pltype_);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000487 Run(channel_a2b_, audio_channels, codec_channels);
488 out_file_.Close();
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000489 if (test_mode_ != 0) {
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000490 printf("===============================================================\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000491 printf("Test number: %d\n", test_cntr_ + 1);
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000492 printf("Test type: Mono-to-stereo\n");
493 }
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000494 test_cntr_++;
495 OpenOutFile(test_cntr_);
496 RegisterSendCodec('A', codec_l16, 16000, 256000, 160, codec_channels,
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000497 l16_16khz_pltype_);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000498 Run(channel_a2b_, audio_channels, codec_channels);
499 out_file_.Close();
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000500 if (test_mode_ != 0) {
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000501 printf("===============================================================\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000502 printf("Test number: %d\n", test_cntr_ + 1);
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000503 printf("Test type: Mono-to-stereo\n");
504 }
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000505 test_cntr_++;
506 OpenOutFile(test_cntr_);
507 RegisterSendCodec('A', codec_l16, 32000, 512000, 320, codec_channels,
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000508 l16_32khz_pltype_);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000509 Run(channel_a2b_, audio_channels, codec_channels);
510 out_file_.Close();
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000511#endif
512#ifdef PCMA_AND_PCMU
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000513 if (test_mode_ != 0) {
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000514 printf("===============================================================\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000515 printf("Test number: %d\n", test_cntr_ + 1);
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000516 printf("Test type: Mono-to-stereo\n");
517 }
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000518 test_cntr_++;
519 channel_a2b_->set_codec_mode(kStereo);
520 OpenOutFile(test_cntr_);
521 RegisterSendCodec('A', codec_pcmu, 8000, 64000, 80, codec_channels,
tina.legrand@webrtc.orgae1c4542012-03-12 08:41:30 +0000522 pcmu_pltype_);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000523 Run(channel_a2b_, audio_channels, codec_channels);
524 RegisterSendCodec('A', codec_pcma, 8000, 64000, 80, codec_channels,
tina.legrand@webrtc.orgae1c4542012-03-12 08:41:30 +0000525 pcma_pltype_);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000526 Run(channel_a2b_, audio_channels, codec_channels);
527 out_file_.Close();
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000528#endif
tina.legrand@webrtc.orgdf697752012-02-08 10:22:21 +0000529#ifdef WEBRTC_CODEC_CELT
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000530 if (test_mode_ != 0) {
tina.legrand@webrtc.orgdf697752012-02-08 10:22:21 +0000531 printf("===============================================================\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000532 printf("Test number: %d\n", test_cntr_ + 1);
tina.legrand@webrtc.orgdf697752012-02-08 10:22:21 +0000533 printf("Test type: Mono-to-stereo\n");
534 }
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000535 test_cntr_++;
536 channel_a2b_->set_codec_mode(kStereo);
537 OpenOutFile(test_cntr_);
tina.legrand@webrtc.org90af7f82012-06-07 08:57:27 +0000538 RegisterSendCodec('A', codec_celt, 32000, 64000, 640, codec_channels,
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000539 celt_pltype_);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000540 Run(channel_a2b_, audio_channels, codec_channels);
541 out_file_.Close();
tina.legrand@webrtc.orgdf697752012-02-08 10:22:21 +0000542#endif
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000543#ifdef WEBRTC_CODEC_OPUS
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000544 if (test_mode_ != 0) {
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000545 printf("===============================================================\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000546 printf("Test number: %d\n", test_cntr_ + 1);
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000547 printf("Test type: Mono-to-stereo\n");
548 }
tina.legrand@webrtc.orgc4590582012-11-28 12:23:29 +0000549
550 // Keep encode and decode in stereo.
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000551 test_cntr_++;
552 channel_a2b_->set_codec_mode(kStereo);
553 OpenOutFile(test_cntr_);
554 RegisterSendCodec('A', codec_opus, 48000, 64000, 960, codec_channels,
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000555 opus_pltype_);
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000556 Run(channel_a2b_, audio_channels, codec_channels);
tina.legrand@webrtc.orgc4590582012-11-28 12:23:29 +0000557
558 // Encode in mono, decode in stereo mode.
559 RegisterSendCodec('A', codec_opus, 48000, 64000, 960, 1, opus_pltype_);
560 Run(channel_a2b_, audio_channels, codec_channels);
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000561 out_file_.Close();
562#endif
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000563
564 //
565 // Test Stereo-To-Mono for all codecs.
566 //
567 audio_channels = 2;
568 codec_channels = 1;
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000569 channel_a2b_->set_codec_mode(kMono);
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000570
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000571#ifdef WEBRTC_CODEC_G722
572 // Run stereo audio and mono codec.
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000573 if (test_mode_ != 0) {
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000574 printf("===============================================================\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000575 printf("Test number: %d\n", test_cntr_ + 1);
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000576 printf("Test type: Stereo-to-mono\n");
577 }
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000578 test_cntr_++;
579 OpenOutFile(test_cntr_);
580 RegisterSendCodec('A', codec_g722, 16000, 64000, 160, codec_channels,
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000581 g722_pltype_);
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000582
583 // Make sure it is possible to set VAD/CNG, now that we are sending mono
584 // again.
585 EXPECT_EQ(0, acm_a_->SetVAD(true, true, VADNormal));
tina.legrand@webrtc.org7a7a0082013-02-21 10:27:48 +0000586 EXPECT_EQ(0, acm_a_->VAD(&dtx, &vad, &vad_mode));
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000587 EXPECT_TRUE(dtx);
588 EXPECT_TRUE(vad);
589 EXPECT_EQ(0, acm_a_->SetVAD(false, false, VADNormal));
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000590 Run(channel_a2b_, audio_channels, codec_channels);
591 out_file_.Close();
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000592#endif
593#ifdef WEBRTC_CODEC_PCM16
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000594 if (test_mode_ != 0) {
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000595 printf("===============================================================\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000596 printf("Test number: %d\n", test_cntr_ + 1);
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000597 printf("Test type: Stereo-to-mono\n");
598 }
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000599 test_cntr_++;
600 OpenOutFile(test_cntr_);
601 RegisterSendCodec('A', codec_l16, 8000, 128000, 80, codec_channels,
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000602 l16_8khz_pltype_);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000603 Run(channel_a2b_, audio_channels, codec_channels);
604 out_file_.Close();
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000605 if (test_mode_ != 0) {
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000606 printf("===============================================================\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000607 printf("Test number: %d\n", test_cntr_ + 1);
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000608 printf("Test type: Stereo-to-mono\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000609 }
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000610 test_cntr_++;
611 OpenOutFile(test_cntr_);
612 RegisterSendCodec('A', codec_l16, 16000, 256000, 160, codec_channels,
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000613 l16_16khz_pltype_);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000614 Run(channel_a2b_, audio_channels, codec_channels);
615 out_file_.Close();
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000616 if (test_mode_ != 0) {
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000617 printf("==============================================================\n");
618 printf("Test number: %d\n", test_cntr_ + 1);
619 printf("Test type: Stereo-to-mono\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000620 }
621 test_cntr_++;
622 OpenOutFile(test_cntr_);
623 RegisterSendCodec('A', codec_l16, 32000, 512000, 320, codec_channels,
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000624 l16_32khz_pltype_);
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000625 Run(channel_a2b_, audio_channels, codec_channels);
626 out_file_.Close();
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000627#endif
628#ifdef PCMA_AND_PCMU
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000629 if (test_mode_ != 0) {
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000630 printf("===============================================================\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000631 printf("Test number: %d\n", test_cntr_ + 1);
tina.legrand@webrtc.orgdf697752012-02-08 10:22:21 +0000632 printf("Test type: Stereo-to-mono\n");
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000633 }
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000634 test_cntr_++;
635 OpenOutFile(test_cntr_);
636 RegisterSendCodec('A', codec_pcmu, 8000, 64000, 80, codec_channels,
tina.legrand@webrtc.orgae1c4542012-03-12 08:41:30 +0000637 pcmu_pltype_);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000638 Run(channel_a2b_, audio_channels, codec_channels);
639 RegisterSendCodec('A', codec_pcma, 8000, 64000, 80, codec_channels,
tina.legrand@webrtc.orgae1c4542012-03-12 08:41:30 +0000640 pcma_pltype_);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000641 Run(channel_a2b_, audio_channels, codec_channels);
642 out_file_.Close();
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000643#endif
tina.legrand@webrtc.orgdf697752012-02-08 10:22:21 +0000644#ifdef WEBRTC_CODEC_CELT
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000645 if (test_mode_ != 0) {
tina.legrand@webrtc.orgdf697752012-02-08 10:22:21 +0000646 printf("===============================================================\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000647 printf("Test number: %d\n", test_cntr_ + 1);
tina.legrand@webrtc.orgdf697752012-02-08 10:22:21 +0000648 printf("Test type: Stereo-to-mono\n");
649 }
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000650 test_cntr_++;
651 OpenOutFile(test_cntr_);
tina.legrand@webrtc.org90af7f82012-06-07 08:57:27 +0000652 RegisterSendCodec('A', codec_celt, 32000, 64000, 640, codec_channels,
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000653 celt_pltype_);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000654 Run(channel_a2b_, audio_channels, codec_channels);
655 out_file_.Close();
tina.legrand@webrtc.orgdf697752012-02-08 10:22:21 +0000656#endif
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000657#ifdef WEBRTC_CODEC_OPUS
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000658 if (test_mode_ != 0) {
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000659 printf("===============================================================\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000660 printf("Test number: %d\n", test_cntr_ + 1);
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000661 printf("Test type: Stereo-to-mono\n");
662 }
663 test_cntr_++;
664 OpenOutFile(test_cntr_);
tina.legrand@webrtc.orgc4590582012-11-28 12:23:29 +0000665 // Encode and decode in mono.
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000666 RegisterSendCodec('A', codec_opus, 48000, 32000, 960, codec_channels,
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000667 opus_pltype_);
tina.legrand@webrtc.orgc4590582012-11-28 12:23:29 +0000668 CodecInst opus_codec_param;
pbos@webrtc.org0946a562013-04-09 00:28:06 +0000669 for (uint8_t n = 0; n < num_encoders; n++) {
tina.legrand@webrtc.org7a7a0082013-02-21 10:27:48 +0000670 EXPECT_EQ(0, acm_b_->Codec(n, &opus_codec_param));
tina.legrand@webrtc.orgc4590582012-11-28 12:23:29 +0000671 if (!strcmp(opus_codec_param.plname, "opus")) {
672 opus_codec_param.channels = 1;
673 EXPECT_EQ(0, acm_b_->RegisterReceiveCodec(opus_codec_param));
674 break;
675 }
676 }
677 Run(channel_a2b_, audio_channels, codec_channels);
678
679 // Encode in stereo, decode in mono.
680 RegisterSendCodec('A', codec_opus, 48000, 32000, 960, 2, opus_pltype_);
681 Run(channel_a2b_, audio_channels, codec_channels);
682
683 out_file_.Close();
684
685 // Test switching between decoding mono and stereo for Opus.
686
687 // Decode in mono.
688 test_cntr_++;
689 OpenOutFile(test_cntr_);
690 if (test_mode_ != 0) {
691 // Print out codec and settings
692 printf("Test number: %d\nCodec: Opus Freq: 48000 Rate :32000 PackSize: 960"
693 " Decode: mono\n", test_cntr_);
694 }
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000695 Run(channel_a2b_, audio_channels, codec_channels);
696 out_file_.Close();
tina.legrand@webrtc.orgc4590582012-11-28 12:23:29 +0000697 // Decode in stereo.
698 test_cntr_++;
699 OpenOutFile(test_cntr_);
700 if (test_mode_ != 0) {
701 // Print out codec and settings
702 printf("Test number: %d\nCodec: Opus Freq: 48000 Rate :32000 PackSize: 960"
703 " Decode: stereo\n", test_cntr_);
704 }
705 opus_codec_param.channels = 2;
706 EXPECT_EQ(0, acm_b_->RegisterReceiveCodec(opus_codec_param));
707 Run(channel_a2b_, audio_channels, 2);
708 out_file_.Close();
709 // Decode in mono.
710 test_cntr_++;
711 OpenOutFile(test_cntr_);
712 if (test_mode_ != 0) {
713 // Print out codec and settings
714 printf("Test number: %d\nCodec: Opus Freq: 48000 Rate :32000 PackSize: 960"
715 " Decode: mono\n", test_cntr_);
716 }
717 opus_codec_param.channels = 1;
718 EXPECT_EQ(0, acm_b_->RegisterReceiveCodec(opus_codec_param));
719 Run(channel_a2b_, audio_channels, codec_channels);
720 out_file_.Close();
721
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000722#endif
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000723
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000724 // Print out which codecs were tested, and which were not, in the run.
725 if (test_mode_ != 0) {
726 printf("\nThe following codecs was INCLUDED in the test:\n");
niklase@google.com470e71d2011-07-07 08:21:25 +0000727#ifdef WEBRTC_CODEC_G722
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000728 printf(" G.722\n");
niklase@google.com470e71d2011-07-07 08:21:25 +0000729#endif
730#ifdef WEBRTC_CODEC_PCM16
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000731 printf(" PCM16\n");
niklase@google.com470e71d2011-07-07 08:21:25 +0000732#endif
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000733 printf(" G.711\n");
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000734#ifdef WEBRTC_CODEC_CELT
735 printf(" CELT\n");
736#endif
tina.legrand@webrtc.orgc4590582012-11-28 12:23:29 +0000737#ifdef WEBRTC_CODEC_OPUS
738 printf(" Opus\n");
739#endif
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000740 printf("\nTo complete the test, listen to the %d number of output "
741 "files.\n",
742 test_cntr_);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000743 }
744
745 // Delete the file pointers.
746 delete in_file_stereo_;
747 delete in_file_mono_;
niklase@google.com470e71d2011-07-07 08:21:25 +0000748}
749
750// Register Codec to use in the test
751//
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000752// Input: side - which ACM to use, 'A' or 'B'
753// codec_name - name to use when register the codec
754// sampling_freq_hz - sampling frequency in Herz
755// rate - bitrate in bytes
756// pack_size - packet size in samples
757// channels - number of channels; 1 for mono, 2 for stereo
758// payload_type - payload type for the codec
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000759void TestStereo::RegisterSendCodec(char side, char* codec_name,
pbos@webrtc.org0946a562013-04-09 00:28:06 +0000760 int32_t sampling_freq_hz, int rate,
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000761 int pack_size, int channels,
762 int payload_type) {
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000763 if (test_mode_ != 0) {
764 // Print out codec and settings
tina.legrand@webrtc.orgba468042012-08-17 10:38:28 +0000765 printf("Codec: %s Freq: %d Rate: %d PackSize: %d\n", codec_name,
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000766 sampling_freq_hz, rate, pack_size);
767 }
768
769 // Store packet size in samples, used to validate the received packet
770 pack_size_samp_ = pack_size;
771
772 // Store the expected packet size in bytes, used to validate the received
773 // packet. Add 0.875 to always round up to a whole byte.
774 // For Celt the packet size in bytes is already counting the stereo part.
775 if (!strcmp(codec_name, "CELT")) {
pbos@webrtc.org0946a562013-04-09 00:28:06 +0000776 pack_size_bytes_ = (uint16_t)(
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000777 static_cast<float>(pack_size * rate) /
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000778 static_cast<float>(sampling_freq_hz * 8) + 0.875) / channels;
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000779 } else {
pbos@webrtc.org0946a562013-04-09 00:28:06 +0000780 pack_size_bytes_ = (uint16_t)(
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000781 static_cast<float>(pack_size * rate) /
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000782 static_cast<float>(sampling_freq_hz * 8) + 0.875);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000783 }
784
785 // Set pointer to the ACM where to register the codec
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000786 AudioCodingModule* my_acm = NULL;
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000787 switch (side) {
788 case 'A': {
789 my_acm = acm_a_;
790 break;
niklase@google.com470e71d2011-07-07 08:21:25 +0000791 }
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000792 case 'B': {
793 my_acm = acm_b_;
794 break;
tina.legrand@webrtc.org16b6b902012-04-12 11:02:38 +0000795 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000796 default:
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000797 break;
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000798 }
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000799 ASSERT_TRUE(my_acm != NULL);
niklase@google.com470e71d2011-07-07 08:21:25 +0000800
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000801 CodecInst my_codec_param;
802 // Get all codec parameters before registering
tina.legrand@webrtc.orgee92b662013-08-27 07:33:51 +0000803 EXPECT_GT(AudioCodingModule::Codec(codec_name, &my_codec_param,
804 sampling_freq_hz, channels), -1);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000805 my_codec_param.rate = rate;
806 my_codec_param.pacsize = pack_size;
tina.legrand@webrtc.orgee92b662013-08-27 07:33:51 +0000807 EXPECT_EQ(0, my_acm->RegisterSendCodec(my_codec_param));
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000808
809 send_codec_name_ = codec_name;
niklase@google.com470e71d2011-07-07 08:21:25 +0000810}
811
tina.legrand@webrtc.org16b6b902012-04-12 11:02:38 +0000812void TestStereo::Run(TestPackStereo* channel, int in_channels, int out_channels,
813 int percent_loss) {
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000814 AudioFrame audio_frame;
niklase@google.com470e71d2011-07-07 08:21:25 +0000815
pbos@webrtc.org0946a562013-04-09 00:28:06 +0000816 int32_t out_freq_hz_b = out_file_.SamplingFrequency();
817 uint16_t rec_size;
818 uint32_t time_stamp_diff;
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000819 channel->reset_payload_size();
820 int error_count = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000821
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000822 while (1) {
823 // Simulate packet loss by setting |packet_loss_| to "true" in
824 // |percent_loss| percent of the loops.
825 if (percent_loss > 0) {
826 if (counter_ == floor((100 / percent_loss) + 0.5)) {
827 counter_ = 0;
828 channel->set_lost_packet(true);
829 } else {
830 channel->set_lost_packet(false);
831 }
832 counter_++;
niklase@google.com470e71d2011-07-07 08:21:25 +0000833 }
834
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000835 // Add 10 msec to ACM
836 if (in_channels == 1) {
837 if (in_file_mono_->EndOfFile()) {
838 break;
839 }
840 in_file_mono_->Read10MsData(audio_frame);
841 } else {
842 if (in_file_stereo_->EndOfFile()) {
843 break;
844 }
845 in_file_stereo_->Read10MsData(audio_frame);
846 }
tina.legrand@webrtc.orgee92b662013-08-27 07:33:51 +0000847 EXPECT_EQ(0, acm_a_->Add10MsData(audio_frame));
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000848
849 // Run sender side of ACM
tina.legrand@webrtc.orgee92b662013-08-27 07:33:51 +0000850 EXPECT_GT(acm_a_->Process(), -1);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000851
852 // Verify that the received packet size matches the settings
853 rec_size = channel->payload_size();
854 if ((0 < rec_size) & (rec_size < 65535)) {
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000855 // Opus is variable rate, skip this test.
856 if (strcmp(send_codec_name_, "opus")) {
857 if ((rec_size != pack_size_bytes_ * out_channels)
858 && (pack_size_bytes_ < 65535)) {
859 error_count++;
860 }
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000861 }
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000862 // Verify that the timestamp is updated with expected length
863 time_stamp_diff = channel->timestamp_diff();
864 if ((counter_ > 10) && (time_stamp_diff != pack_size_samp_)) {
865 error_count++;
866 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000867 }
868
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000869 // Run received side of ACM
tina.legrand@webrtc.orgee92b662013-08-27 07:33:51 +0000870 EXPECT_EQ(0, acm_b_->PlayoutData10Ms(out_freq_hz_b, &audio_frame));
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000871
872 // Write output speech to file
873 out_file_.Write10MsData(
andrew@webrtc.org63a50982012-05-02 23:56:37 +0000874 audio_frame.data_,
875 audio_frame.samples_per_channel_ * audio_frame.num_channels_);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000876 }
877
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000878 EXPECT_EQ(0, error_count);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000879
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000880 if (in_file_mono_->EndOfFile()) {
881 in_file_mono_->Rewind();
882 }
883 if (in_file_stereo_->EndOfFile()) {
884 in_file_stereo_->Rewind();
885 }
886 // Reset in case we ended with a lost packet
887 channel->set_lost_packet(false);
niklase@google.com470e71d2011-07-07 08:21:25 +0000888}
889
pbos@webrtc.org0946a562013-04-09 00:28:06 +0000890void TestStereo::OpenOutFile(int16_t test_number) {
tina.legrand@webrtc.orgba468042012-08-17 10:38:28 +0000891 std::string file_name;
892 std::stringstream file_stream;
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000893 file_stream << webrtc::test::OutputPath() << "teststereo_out_" << test_number
894 << ".pcm";
tina.legrand@webrtc.orgba468042012-08-17 10:38:28 +0000895 file_name = file_stream.str();
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000896 out_file_.Open(file_name, 32000, "wb");
niklase@google.com470e71d2011-07-07 08:21:25 +0000897}
898
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000899void TestStereo::DisplaySendReceiveCodec() {
900 CodecInst my_codec_param;
tina.legrand@webrtc.org7a7a0082013-02-21 10:27:48 +0000901 acm_a_->SendCodec(&my_codec_param);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000902 if (test_mode_ != 0) {
903 printf("%s -> ", my_codec_param.plname);
904 }
tina.legrand@webrtc.org7a7a0082013-02-21 10:27:48 +0000905 acm_b_->ReceiveCodec(&my_codec_param);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000906 if (test_mode_ != 0) {
907 printf("%s\n", my_codec_param.plname);
908 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000909}
910
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000911} // namespace webrtc