blob: b26334c3298380b25f45e68e8a31f6736ed2e83b [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"
turaj@webrtc.org6ea3d1c2013-10-02 21:44:33 +000018#include "webrtc/common.h"
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
turaj@webrtc.org6ea3d1c2013-10-02 21:44:33 +0000111TestStereo::TestStereo(int test_mode, const Config& config)
112 : acm_a_(config.Get<AudioCodingModuleFactory>().Create(0)),
113 acm_b_(config.Get<AudioCodingModuleFactory>().Create(1)),
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000114 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() {
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000135 if (channel_a2b_ != NULL) {
136 delete channel_a2b_;
137 channel_a2b_ = NULL;
138 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000139}
140
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000141void TestStereo::Perform() {
pbos@webrtc.org0946a562013-04-09 00:28:06 +0000142 uint16_t frequency_hz;
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000143 int audio_channels;
144 int codec_channels;
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000145 bool dtx;
146 bool vad;
147 ACMVADMode vad_mode;
niklase@google.com470e71d2011-07-07 08:21:25 +0000148
tina.legrand@webrtc.org45175852012-06-01 09:27:35 +0000149 // Open both mono and stereo test files in 32 kHz.
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000150 const std::string file_name_stereo = webrtc::test::ResourcePath(
151 "audio_coding/teststereo32kHz", "pcm");
152 const std::string file_name_mono = webrtc::test::ResourcePath(
153 "audio_coding/testfile32kHz", "pcm");
tina.legrand@webrtc.org45175852012-06-01 09:27:35 +0000154 frequency_hz = 32000;
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000155 in_file_stereo_ = new PCMFile();
156 in_file_mono_ = new PCMFile();
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000157 in_file_stereo_->Open(file_name_stereo, frequency_hz, "rb");
158 in_file_stereo_->ReadStereo(true);
159 in_file_mono_->Open(file_name_mono, frequency_hz, "rb");
160 in_file_mono_->ReadStereo(false);
161
tina.legrand@webrtc.org45175852012-06-01 09:27:35 +0000162 // Create and initialize two ACMs, one for each side of a one-to-one call.
andrew@webrtc.org89df0922013-09-12 01:27:43 +0000163 ASSERT_TRUE((acm_a_.get() != NULL) && (acm_b_.get() != NULL));
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000164 EXPECT_EQ(0, acm_a_->InitializeReceiver());
165 EXPECT_EQ(0, acm_b_->InitializeReceiver());
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000166
tina.legrand@webrtc.org45175852012-06-01 09:27:35 +0000167 // Register all available codes as receiving codecs.
pbos@webrtc.org0946a562013-04-09 00:28:06 +0000168 uint8_t num_encoders = acm_a_->NumberOfCodecs();
tina.legrand@webrtc.org45175852012-06-01 09:27:35 +0000169 CodecInst my_codec_param;
pbos@webrtc.org0946a562013-04-09 00:28:06 +0000170 for (uint8_t n = 0; n < num_encoders; n++) {
tina.legrand@webrtc.org7a7a0082013-02-21 10:27:48 +0000171 EXPECT_EQ(0, acm_b_->Codec(n, &my_codec_param));
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000172 EXPECT_EQ(0, acm_b_->RegisterReceiveCodec(my_codec_param));
tina.legrand@webrtc.org45175852012-06-01 09:27:35 +0000173 }
174
175 // Test that unregister all receive codecs works.
pbos@webrtc.org0946a562013-04-09 00:28:06 +0000176 for (uint8_t n = 0; n < num_encoders; n++) {
tina.legrand@webrtc.org7a7a0082013-02-21 10:27:48 +0000177 EXPECT_EQ(0, acm_b_->Codec(n, &my_codec_param));
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000178 EXPECT_EQ(0, acm_b_->UnregisterReceiveCodec(my_codec_param.pltype));
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000179 }
tina.legrand@webrtc.orgae1c4542012-03-12 08:41:30 +0000180
tina.legrand@webrtc.org45175852012-06-01 09:27:35 +0000181 // Register all available codes as receiving codecs once more.
pbos@webrtc.org0946a562013-04-09 00:28:06 +0000182 for (uint8_t n = 0; n < num_encoders; n++) {
tina.legrand@webrtc.org7a7a0082013-02-21 10:27:48 +0000183 EXPECT_EQ(0, acm_b_->Codec(n, &my_codec_param));
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000184 EXPECT_EQ(0, acm_b_->RegisterReceiveCodec(my_codec_param));
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000185 }
tina.legrand@webrtc.orgae1c4542012-03-12 08:41:30 +0000186
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000187 // Create and connect the channel.
188 channel_a2b_ = new TestPackStereo;
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000189 EXPECT_EQ(0, acm_a_->RegisterTransportCallback(channel_a2b_));
andrew@webrtc.org89df0922013-09-12 01:27:43 +0000190 channel_a2b_->RegisterReceiverACM(acm_b_.get());
tina.legrand@webrtc.orgdf697752012-02-08 10:22:21 +0000191
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000192 // Start with setting VAD/DTX, before we know we will send stereo.
193 // Continue with setting a stereo codec as send codec and verify that
194 // VAD/DTX gets turned off.
195 EXPECT_EQ(0, acm_a_->SetVAD(true, true, VADNormal));
tina.legrand@webrtc.org7a7a0082013-02-21 10:27:48 +0000196 EXPECT_EQ(0, acm_a_->VAD(&dtx, &vad, &vad_mode));
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000197 EXPECT_TRUE(dtx);
198 EXPECT_TRUE(vad);
199 char codec_pcma_temp[] = "PCMA";
200 RegisterSendCodec('A', codec_pcma_temp, 8000, 64000, 80, 2, pcma_pltype_);
tina.legrand@webrtc.org7a7a0082013-02-21 10:27:48 +0000201 EXPECT_EQ(0, acm_a_->VAD(&dtx, &vad, &vad_mode));
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000202 EXPECT_FALSE(dtx);
203 EXPECT_FALSE(vad);
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000204 if (test_mode_ != 0) {
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000205 printf("\n");
206 }
207
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000208 //
209 // Test Stereo-To-Stereo for all codecs.
210 //
211 audio_channels = 2;
212 codec_channels = 2;
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000213
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000214 // All codecs are tested for all allowed sampling frequencies, rates and
215 // packet sizes.
niklase@google.com470e71d2011-07-07 08:21:25 +0000216#ifdef WEBRTC_CODEC_G722
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000217 if (test_mode_ != 0) {
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000218 printf("===========================================================\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000219 printf("Test number: %d\n", test_cntr_ + 1);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000220 printf("Test type: Stereo-to-stereo\n");
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000221 }
222 channel_a2b_->set_codec_mode(kStereo);
223 test_cntr_++;
224 OpenOutFile(test_cntr_);
225 char codec_g722[] = "G722";
226 RegisterSendCodec('A', codec_g722, 16000, 64000, 160, codec_channels,
227 g722_pltype_);
228 Run(channel_a2b_, audio_channels, codec_channels);
229 RegisterSendCodec('A', codec_g722, 16000, 64000, 320, codec_channels,
230 g722_pltype_);
231 Run(channel_a2b_, audio_channels, codec_channels);
232 RegisterSendCodec('A', codec_g722, 16000, 64000, 480, codec_channels,
233 g722_pltype_);
234 Run(channel_a2b_, audio_channels, codec_channels);
235 RegisterSendCodec('A', codec_g722, 16000, 64000, 640, codec_channels,
236 g722_pltype_);
237 Run(channel_a2b_, audio_channels, codec_channels);
238 RegisterSendCodec('A', codec_g722, 16000, 64000, 800, codec_channels,
239 g722_pltype_);
240 Run(channel_a2b_, audio_channels, codec_channels);
241 RegisterSendCodec('A', codec_g722, 16000, 64000, 960, codec_channels,
242 g722_pltype_);
243 Run(channel_a2b_, audio_channels, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000244 out_file_.Close();
niklase@google.com470e71d2011-07-07 08:21:25 +0000245#endif
246#ifdef WEBRTC_CODEC_PCM16
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_l16[] = "L16";
256 RegisterSendCodec('A', codec_l16, 8000, 128000, 80, codec_channels,
257 l16_8khz_pltype_);
258 Run(channel_a2b_, audio_channels, codec_channels);
259 RegisterSendCodec('A', codec_l16, 8000, 128000, 160, codec_channels,
260 l16_8khz_pltype_);
261 Run(channel_a2b_, audio_channels, codec_channels);
262 RegisterSendCodec('A', codec_l16, 8000, 128000, 240, codec_channels,
263 l16_8khz_pltype_);
264 Run(channel_a2b_, audio_channels, codec_channels);
265 RegisterSendCodec('A', codec_l16, 8000, 128000, 320, codec_channels,
266 l16_8khz_pltype_);
267 Run(channel_a2b_, audio_channels, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000268 out_file_.Close();
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000269
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000270 if (test_mode_ != 0) {
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000271 printf("===========================================================\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000272 printf("Test number: %d\n", test_cntr_ + 1);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000273 printf("Test type: Stereo-to-stereo\n");
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000274 }
275 test_cntr_++;
276 OpenOutFile(test_cntr_);
277 RegisterSendCodec('A', codec_l16, 16000, 256000, 160, codec_channels,
278 l16_16khz_pltype_);
279 Run(channel_a2b_, audio_channels, codec_channels);
280 RegisterSendCodec('A', codec_l16, 16000, 256000, 320, codec_channels,
281 l16_16khz_pltype_);
282 Run(channel_a2b_, audio_channels, codec_channels);
283 RegisterSendCodec('A', codec_l16, 16000, 256000, 480, codec_channels,
284 l16_16khz_pltype_);
285 Run(channel_a2b_, audio_channels, codec_channels);
286 RegisterSendCodec('A', codec_l16, 16000, 256000, 640, codec_channels,
287 l16_16khz_pltype_);
288 Run(channel_a2b_, audio_channels, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000289 out_file_.Close();
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000290
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000291 if (test_mode_ != 0) {
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000292 printf("===========================================================\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000293 printf("Test number: %d\n", test_cntr_ + 1);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000294 printf("Test type: Stereo-to-stereo\n");
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000295 }
296 test_cntr_++;
297 OpenOutFile(test_cntr_);
298 RegisterSendCodec('A', codec_l16, 32000, 512000, 320, codec_channels,
299 l16_32khz_pltype_);
300 Run(channel_a2b_, audio_channels, codec_channels);
301 RegisterSendCodec('A', codec_l16, 32000, 512000, 640, codec_channels,
302 l16_32khz_pltype_);
303 Run(channel_a2b_, audio_channels, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000304 out_file_.Close();
niklase@google.com470e71d2011-07-07 08:21:25 +0000305#endif
306#define PCMA_AND_PCMU
307#ifdef PCMA_AND_PCMU
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000308 if (test_mode_ != 0) {
309 printf("===========================================================\n");
310 printf("Test number: %d\n", test_cntr_ + 1);
311 printf("Test type: Stereo-to-stereo\n");
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000312 }
313 channel_a2b_->set_codec_mode(kStereo);
314 audio_channels = 2;
315 codec_channels = 2;
316 test_cntr_++;
317 OpenOutFile(test_cntr_);
318 char codec_pcma[] = "PCMA";
319 RegisterSendCodec('A', codec_pcma, 8000, 64000, 80, codec_channels,
320 pcma_pltype_);
321 Run(channel_a2b_, audio_channels, codec_channels);
322 RegisterSendCodec('A', codec_pcma, 8000, 64000, 160, codec_channels,
323 pcma_pltype_);
324 Run(channel_a2b_, audio_channels, codec_channels);
325 RegisterSendCodec('A', codec_pcma, 8000, 64000, 240, codec_channels,
326 pcma_pltype_);
327 Run(channel_a2b_, audio_channels, codec_channels);
328 RegisterSendCodec('A', codec_pcma, 8000, 64000, 320, codec_channels,
329 pcma_pltype_);
330 Run(channel_a2b_, audio_channels, codec_channels);
331 RegisterSendCodec('A', codec_pcma, 8000, 64000, 400, codec_channels,
332 pcma_pltype_);
333 Run(channel_a2b_, audio_channels, codec_channels);
334 RegisterSendCodec('A', codec_pcma, 8000, 64000, 480, codec_channels,
335 pcma_pltype_);
336 Run(channel_a2b_, audio_channels, codec_channels);
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000337
338 // Test that VAD/DTX cannot be turned on while sending stereo.
339 EXPECT_EQ(-1, acm_a_->SetVAD(true, true, VADNormal));
tina.legrand@webrtc.org7a7a0082013-02-21 10:27:48 +0000340 EXPECT_EQ(0, acm_a_->VAD(&dtx, &vad, &vad_mode));
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000341 EXPECT_FALSE(dtx);
342 EXPECT_FALSE(vad);
343 EXPECT_EQ(-1, acm_a_->SetVAD(true, false, VADNormal));
tina.legrand@webrtc.org7a7a0082013-02-21 10:27:48 +0000344 EXPECT_EQ(0, acm_a_->VAD(&dtx, &vad, &vad_mode));
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000345 EXPECT_FALSE(dtx);
346 EXPECT_FALSE(vad);
347 EXPECT_EQ(-1, acm_a_->SetVAD(false, true, VADNormal));
tina.legrand@webrtc.org7a7a0082013-02-21 10:27:48 +0000348 EXPECT_EQ(0, acm_a_->VAD(&dtx, &vad, &vad_mode));
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000349 EXPECT_FALSE(dtx);
350 EXPECT_FALSE(vad);
351 EXPECT_EQ(0, acm_a_->SetVAD(false, false, VADNormal));
tina.legrand@webrtc.org7a7a0082013-02-21 10:27:48 +0000352 EXPECT_EQ(0, acm_a_->VAD(&dtx, &vad, &vad_mode));
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000353 EXPECT_FALSE(dtx);
354 EXPECT_FALSE(vad);
355
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000356 out_file_.Close();
357 if (test_mode_ != 0) {
358 printf("===========================================================\n");
359 printf("Test number: %d\n", test_cntr_ + 1);
360 printf("Test type: Stereo-to-stereo\n");
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000361 }
362 test_cntr_++;
363 OpenOutFile(test_cntr_);
364 char codec_pcmu[] = "PCMU";
365 RegisterSendCodec('A', codec_pcmu, 8000, 64000, 80, codec_channels,
366 pcmu_pltype_);
367 Run(channel_a2b_, audio_channels, codec_channels);
368 RegisterSendCodec('A', codec_pcmu, 8000, 64000, 160, codec_channels,
369 pcmu_pltype_);
370 Run(channel_a2b_, audio_channels, codec_channels);
371 RegisterSendCodec('A', codec_pcmu, 8000, 64000, 240, codec_channels,
372 pcmu_pltype_);
373 Run(channel_a2b_, audio_channels, codec_channels);
374 RegisterSendCodec('A', codec_pcmu, 8000, 64000, 320, codec_channels,
375 pcmu_pltype_);
376 Run(channel_a2b_, audio_channels, codec_channels);
377 RegisterSendCodec('A', codec_pcmu, 8000, 64000, 400, codec_channels,
378 pcmu_pltype_);
379 Run(channel_a2b_, audio_channels, codec_channels);
380 RegisterSendCodec('A', codec_pcmu, 8000, 64000, 480, codec_channels,
381 pcmu_pltype_);
382 Run(channel_a2b_, audio_channels, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000383 out_file_.Close();
niklase@google.com470e71d2011-07-07 08:21:25 +0000384#endif
tina.legrand@webrtc.orgdf697752012-02-08 10:22:21 +0000385#ifdef WEBRTC_CODEC_CELT
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000386 if (test_mode_ != 0) {
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000387 printf("===========================================================\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000388 printf("Test number: %d\n", test_cntr_ + 1);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000389 printf("Test type: Stereo-to-stereo\n");
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000390 }
391 channel_a2b_->set_codec_mode(kStereo);
392 audio_channels = 2;
393 codec_channels = 2;
394 test_cntr_++;
395 OpenOutFile(test_cntr_);
396 char codec_celt[] = "CELT";
tina.legrand@webrtc.org90af7f82012-06-07 08:57:27 +0000397 RegisterSendCodec('A', codec_celt, 32000, 48000, 640, codec_channels,
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000398 celt_pltype_);
399 Run(channel_a2b_, audio_channels, codec_channels);
tina.legrand@webrtc.org90af7f82012-06-07 08:57:27 +0000400 RegisterSendCodec('A', codec_celt, 32000, 64000, 640, codec_channels,
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000401 celt_pltype_);
402 Run(channel_a2b_, audio_channels, codec_channels);
tina.legrand@webrtc.org90af7f82012-06-07 08:57:27 +0000403 RegisterSendCodec('A', codec_celt, 32000, 128000, 640, codec_channels,
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000404 celt_pltype_);
405 Run(channel_a2b_, audio_channels, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000406 out_file_.Close();
tina.legrand@webrtc.orgdf697752012-02-08 10:22:21 +0000407#endif
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000408#ifdef WEBRTC_CODEC_OPUS
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000409 if (test_mode_ != 0) {
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000410 printf("===========================================================\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000411 printf("Test number: %d\n", test_cntr_ + 1);
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000412 printf("Test type: Stereo-to-stereo\n");
413 }
414 channel_a2b_->set_codec_mode(kStereo);
415 audio_channels = 2;
416 codec_channels = 2;
417 test_cntr_++;
418 OpenOutFile(test_cntr_);
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000419
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000420 char codec_opus[] = "opus";
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000421 // Run Opus with 10 ms frame size.
422 RegisterSendCodec('A', codec_opus, 48000, 64000, 480, codec_channels,
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000423 opus_pltype_);
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000424 Run(channel_a2b_, audio_channels, codec_channels);
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000425 // Run Opus with 20 ms frame size.
426 RegisterSendCodec('A', codec_opus, 48000, 64000, 480*2, codec_channels,
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000427 opus_pltype_);
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000428 Run(channel_a2b_, audio_channels, codec_channels);
429 // Run Opus with 40 ms frame size.
430 RegisterSendCodec('A', codec_opus, 48000, 64000, 480*4, codec_channels,
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000431 opus_pltype_);
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000432 Run(channel_a2b_, audio_channels, codec_channels);
433 // Run Opus with 60 ms frame size.
434 RegisterSendCodec('A', codec_opus, 48000, 64000, 480*6, codec_channels,
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000435 opus_pltype_);
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000436 Run(channel_a2b_, audio_channels, codec_channels);
437 // Run Opus with 20 ms frame size and different bitrates.
438 RegisterSendCodec('A', codec_opus, 48000, 40000, 960, codec_channels,
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000439 opus_pltype_);
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000440 Run(channel_a2b_, audio_channels, codec_channels);
441 RegisterSendCodec('A', codec_opus, 48000, 510000, 960, codec_channels,
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000442 opus_pltype_);
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000443 Run(channel_a2b_, audio_channels, codec_channels);
444 out_file_.Close();
445#endif
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000446 //
447 // Test Mono-To-Stereo for all codecs.
448 //
449 audio_channels = 1;
450 codec_channels = 2;
niklase@google.com470e71d2011-07-07 08:21:25 +0000451
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000452#ifdef WEBRTC_CODEC_G722
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000453 if (test_mode_ != 0) {
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000454 printf("===============================================================\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000455 printf("Test number: %d\n", test_cntr_ + 1);
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000456 printf("Test type: Mono-to-stereo\n");
457 }
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000458 test_cntr_++;
459 channel_a2b_->set_codec_mode(kStereo);
460 OpenOutFile(test_cntr_);
461 RegisterSendCodec('A', codec_g722, 16000, 64000, 160, codec_channels,
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000462 g722_pltype_);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000463 Run(channel_a2b_, audio_channels, codec_channels);
464 out_file_.Close();
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000465#endif
466#ifdef WEBRTC_CODEC_PCM16
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000467 if (test_mode_ != 0) {
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000468 printf("===============================================================\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000469 printf("Test number: %d\n", test_cntr_ + 1);
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000470 printf("Test type: Mono-to-stereo\n");
471 }
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000472 test_cntr_++;
473 channel_a2b_->set_codec_mode(kStereo);
474 OpenOutFile(test_cntr_);
475 RegisterSendCodec('A', codec_l16, 8000, 128000, 80, codec_channels,
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000476 l16_8khz_pltype_);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000477 Run(channel_a2b_, audio_channels, codec_channels);
478 out_file_.Close();
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000479 if (test_mode_ != 0) {
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000480 printf("===============================================================\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000481 printf("Test number: %d\n", test_cntr_ + 1);
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000482 printf("Test type: Mono-to-stereo\n");
483 }
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000484 test_cntr_++;
485 OpenOutFile(test_cntr_);
486 RegisterSendCodec('A', codec_l16, 16000, 256000, 160, codec_channels,
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000487 l16_16khz_pltype_);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000488 Run(channel_a2b_, audio_channels, codec_channels);
489 out_file_.Close();
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000490 if (test_mode_ != 0) {
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000491 printf("===============================================================\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000492 printf("Test number: %d\n", test_cntr_ + 1);
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000493 printf("Test type: Mono-to-stereo\n");
494 }
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000495 test_cntr_++;
496 OpenOutFile(test_cntr_);
497 RegisterSendCodec('A', codec_l16, 32000, 512000, 320, codec_channels,
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000498 l16_32khz_pltype_);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000499 Run(channel_a2b_, audio_channels, codec_channels);
500 out_file_.Close();
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000501#endif
502#ifdef PCMA_AND_PCMU
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000503 if (test_mode_ != 0) {
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000504 printf("===============================================================\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000505 printf("Test number: %d\n", test_cntr_ + 1);
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000506 printf("Test type: Mono-to-stereo\n");
507 }
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000508 test_cntr_++;
509 channel_a2b_->set_codec_mode(kStereo);
510 OpenOutFile(test_cntr_);
511 RegisterSendCodec('A', codec_pcmu, 8000, 64000, 80, codec_channels,
tina.legrand@webrtc.orgae1c4542012-03-12 08:41:30 +0000512 pcmu_pltype_);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000513 Run(channel_a2b_, audio_channels, codec_channels);
514 RegisterSendCodec('A', codec_pcma, 8000, 64000, 80, codec_channels,
tina.legrand@webrtc.orgae1c4542012-03-12 08:41:30 +0000515 pcma_pltype_);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000516 Run(channel_a2b_, audio_channels, codec_channels);
517 out_file_.Close();
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000518#endif
tina.legrand@webrtc.orgdf697752012-02-08 10:22:21 +0000519#ifdef WEBRTC_CODEC_CELT
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000520 if (test_mode_ != 0) {
tina.legrand@webrtc.orgdf697752012-02-08 10:22:21 +0000521 printf("===============================================================\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000522 printf("Test number: %d\n", test_cntr_ + 1);
tina.legrand@webrtc.orgdf697752012-02-08 10:22:21 +0000523 printf("Test type: Mono-to-stereo\n");
524 }
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000525 test_cntr_++;
526 channel_a2b_->set_codec_mode(kStereo);
527 OpenOutFile(test_cntr_);
tina.legrand@webrtc.org90af7f82012-06-07 08:57:27 +0000528 RegisterSendCodec('A', codec_celt, 32000, 64000, 640, codec_channels,
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000529 celt_pltype_);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000530 Run(channel_a2b_, audio_channels, codec_channels);
531 out_file_.Close();
tina.legrand@webrtc.orgdf697752012-02-08 10:22:21 +0000532#endif
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000533#ifdef WEBRTC_CODEC_OPUS
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000534 if (test_mode_ != 0) {
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000535 printf("===============================================================\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000536 printf("Test number: %d\n", test_cntr_ + 1);
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000537 printf("Test type: Mono-to-stereo\n");
538 }
tina.legrand@webrtc.orgc4590582012-11-28 12:23:29 +0000539
540 // Keep encode and decode in stereo.
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000541 test_cntr_++;
542 channel_a2b_->set_codec_mode(kStereo);
543 OpenOutFile(test_cntr_);
544 RegisterSendCodec('A', codec_opus, 48000, 64000, 960, codec_channels,
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000545 opus_pltype_);
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000546 Run(channel_a2b_, audio_channels, codec_channels);
tina.legrand@webrtc.orgc4590582012-11-28 12:23:29 +0000547
548 // Encode in mono, decode in stereo mode.
549 RegisterSendCodec('A', codec_opus, 48000, 64000, 960, 1, opus_pltype_);
550 Run(channel_a2b_, audio_channels, codec_channels);
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000551 out_file_.Close();
552#endif
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000553
554 //
555 // Test Stereo-To-Mono for all codecs.
556 //
557 audio_channels = 2;
558 codec_channels = 1;
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000559 channel_a2b_->set_codec_mode(kMono);
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000560
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000561#ifdef WEBRTC_CODEC_G722
562 // Run stereo audio and mono codec.
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000563 if (test_mode_ != 0) {
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000564 printf("===============================================================\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000565 printf("Test number: %d\n", test_cntr_ + 1);
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000566 printf("Test type: Stereo-to-mono\n");
567 }
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000568 test_cntr_++;
569 OpenOutFile(test_cntr_);
570 RegisterSendCodec('A', codec_g722, 16000, 64000, 160, codec_channels,
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000571 g722_pltype_);
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000572
573 // Make sure it is possible to set VAD/CNG, now that we are sending mono
574 // again.
575 EXPECT_EQ(0, acm_a_->SetVAD(true, true, VADNormal));
tina.legrand@webrtc.org7a7a0082013-02-21 10:27:48 +0000576 EXPECT_EQ(0, acm_a_->VAD(&dtx, &vad, &vad_mode));
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000577 EXPECT_TRUE(dtx);
578 EXPECT_TRUE(vad);
579 EXPECT_EQ(0, acm_a_->SetVAD(false, false, VADNormal));
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000580 Run(channel_a2b_, audio_channels, codec_channels);
581 out_file_.Close();
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000582#endif
583#ifdef WEBRTC_CODEC_PCM16
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000584 if (test_mode_ != 0) {
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000585 printf("===============================================================\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000586 printf("Test number: %d\n", test_cntr_ + 1);
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000587 printf("Test type: Stereo-to-mono\n");
588 }
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000589 test_cntr_++;
590 OpenOutFile(test_cntr_);
591 RegisterSendCodec('A', codec_l16, 8000, 128000, 80, codec_channels,
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000592 l16_8khz_pltype_);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000593 Run(channel_a2b_, audio_channels, codec_channels);
594 out_file_.Close();
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000595 if (test_mode_ != 0) {
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000596 printf("===============================================================\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000597 printf("Test number: %d\n", test_cntr_ + 1);
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000598 printf("Test type: Stereo-to-mono\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000599 }
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000600 test_cntr_++;
601 OpenOutFile(test_cntr_);
602 RegisterSendCodec('A', codec_l16, 16000, 256000, 160, codec_channels,
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000603 l16_16khz_pltype_);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000604 Run(channel_a2b_, audio_channels, codec_channels);
605 out_file_.Close();
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000606 if (test_mode_ != 0) {
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000607 printf("==============================================================\n");
608 printf("Test number: %d\n", test_cntr_ + 1);
609 printf("Test type: Stereo-to-mono\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000610 }
611 test_cntr_++;
612 OpenOutFile(test_cntr_);
613 RegisterSendCodec('A', codec_l16, 32000, 512000, 320, codec_channels,
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000614 l16_32khz_pltype_);
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000615 Run(channel_a2b_, audio_channels, codec_channels);
616 out_file_.Close();
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000617#endif
618#ifdef PCMA_AND_PCMU
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000619 if (test_mode_ != 0) {
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000620 printf("===============================================================\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000621 printf("Test number: %d\n", test_cntr_ + 1);
tina.legrand@webrtc.orgdf697752012-02-08 10:22:21 +0000622 printf("Test type: Stereo-to-mono\n");
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000623 }
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000624 test_cntr_++;
625 OpenOutFile(test_cntr_);
626 RegisterSendCodec('A', codec_pcmu, 8000, 64000, 80, codec_channels,
tina.legrand@webrtc.orgae1c4542012-03-12 08:41:30 +0000627 pcmu_pltype_);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000628 Run(channel_a2b_, audio_channels, codec_channels);
629 RegisterSendCodec('A', codec_pcma, 8000, 64000, 80, codec_channels,
tina.legrand@webrtc.orgae1c4542012-03-12 08:41:30 +0000630 pcma_pltype_);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000631 Run(channel_a2b_, audio_channels, codec_channels);
632 out_file_.Close();
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000633#endif
tina.legrand@webrtc.orgdf697752012-02-08 10:22:21 +0000634#ifdef WEBRTC_CODEC_CELT
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000635 if (test_mode_ != 0) {
tina.legrand@webrtc.orgdf697752012-02-08 10:22:21 +0000636 printf("===============================================================\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000637 printf("Test number: %d\n", test_cntr_ + 1);
tina.legrand@webrtc.orgdf697752012-02-08 10:22:21 +0000638 printf("Test type: Stereo-to-mono\n");
639 }
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000640 test_cntr_++;
641 OpenOutFile(test_cntr_);
tina.legrand@webrtc.org90af7f82012-06-07 08:57:27 +0000642 RegisterSendCodec('A', codec_celt, 32000, 64000, 640, codec_channels,
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000643 celt_pltype_);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000644 Run(channel_a2b_, audio_channels, codec_channels);
645 out_file_.Close();
tina.legrand@webrtc.orgdf697752012-02-08 10:22:21 +0000646#endif
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000647#ifdef WEBRTC_CODEC_OPUS
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000648 if (test_mode_ != 0) {
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000649 printf("===============================================================\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000650 printf("Test number: %d\n", test_cntr_ + 1);
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000651 printf("Test type: Stereo-to-mono\n");
652 }
653 test_cntr_++;
654 OpenOutFile(test_cntr_);
tina.legrand@webrtc.orgc4590582012-11-28 12:23:29 +0000655 // Encode and decode in mono.
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000656 RegisterSendCodec('A', codec_opus, 48000, 32000, 960, codec_channels,
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000657 opus_pltype_);
tina.legrand@webrtc.orgc4590582012-11-28 12:23:29 +0000658 CodecInst opus_codec_param;
pbos@webrtc.org0946a562013-04-09 00:28:06 +0000659 for (uint8_t n = 0; n < num_encoders; n++) {
tina.legrand@webrtc.org7a7a0082013-02-21 10:27:48 +0000660 EXPECT_EQ(0, acm_b_->Codec(n, &opus_codec_param));
tina.legrand@webrtc.orgc4590582012-11-28 12:23:29 +0000661 if (!strcmp(opus_codec_param.plname, "opus")) {
662 opus_codec_param.channels = 1;
663 EXPECT_EQ(0, acm_b_->RegisterReceiveCodec(opus_codec_param));
664 break;
665 }
666 }
667 Run(channel_a2b_, audio_channels, codec_channels);
668
669 // Encode in stereo, decode in mono.
670 RegisterSendCodec('A', codec_opus, 48000, 32000, 960, 2, opus_pltype_);
671 Run(channel_a2b_, audio_channels, codec_channels);
672
673 out_file_.Close();
674
675 // Test switching between decoding mono and stereo for Opus.
676
677 // Decode in mono.
678 test_cntr_++;
679 OpenOutFile(test_cntr_);
680 if (test_mode_ != 0) {
681 // Print out codec and settings
682 printf("Test number: %d\nCodec: Opus Freq: 48000 Rate :32000 PackSize: 960"
683 " Decode: mono\n", test_cntr_);
684 }
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000685 Run(channel_a2b_, audio_channels, codec_channels);
686 out_file_.Close();
tina.legrand@webrtc.orgc4590582012-11-28 12:23:29 +0000687 // Decode in stereo.
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: stereo\n", test_cntr_);
694 }
695 opus_codec_param.channels = 2;
696 EXPECT_EQ(0, acm_b_->RegisterReceiveCodec(opus_codec_param));
697 Run(channel_a2b_, audio_channels, 2);
698 out_file_.Close();
699 // Decode in mono.
700 test_cntr_++;
701 OpenOutFile(test_cntr_);
702 if (test_mode_ != 0) {
703 // Print out codec and settings
704 printf("Test number: %d\nCodec: Opus Freq: 48000 Rate :32000 PackSize: 960"
705 " Decode: mono\n", test_cntr_);
706 }
707 opus_codec_param.channels = 1;
708 EXPECT_EQ(0, acm_b_->RegisterReceiveCodec(opus_codec_param));
709 Run(channel_a2b_, audio_channels, codec_channels);
710 out_file_.Close();
711
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000712#endif
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000713
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000714 // Print out which codecs were tested, and which were not, in the run.
715 if (test_mode_ != 0) {
716 printf("\nThe following codecs was INCLUDED in the test:\n");
niklase@google.com470e71d2011-07-07 08:21:25 +0000717#ifdef WEBRTC_CODEC_G722
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000718 printf(" G.722\n");
niklase@google.com470e71d2011-07-07 08:21:25 +0000719#endif
720#ifdef WEBRTC_CODEC_PCM16
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000721 printf(" PCM16\n");
niklase@google.com470e71d2011-07-07 08:21:25 +0000722#endif
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000723 printf(" G.711\n");
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000724#ifdef WEBRTC_CODEC_CELT
725 printf(" CELT\n");
726#endif
tina.legrand@webrtc.orgc4590582012-11-28 12:23:29 +0000727#ifdef WEBRTC_CODEC_OPUS
728 printf(" Opus\n");
729#endif
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000730 printf("\nTo complete the test, listen to the %d number of output "
731 "files.\n",
732 test_cntr_);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000733 }
734
735 // Delete the file pointers.
736 delete in_file_stereo_;
737 delete in_file_mono_;
niklase@google.com470e71d2011-07-07 08:21:25 +0000738}
739
740// Register Codec to use in the test
741//
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000742// Input: side - which ACM to use, 'A' or 'B'
743// codec_name - name to use when register the codec
744// sampling_freq_hz - sampling frequency in Herz
745// rate - bitrate in bytes
746// pack_size - packet size in samples
747// channels - number of channels; 1 for mono, 2 for stereo
748// payload_type - payload type for the codec
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000749void TestStereo::RegisterSendCodec(char side, char* codec_name,
pbos@webrtc.org0946a562013-04-09 00:28:06 +0000750 int32_t sampling_freq_hz, int rate,
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000751 int pack_size, int channels,
752 int payload_type) {
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000753 if (test_mode_ != 0) {
754 // Print out codec and settings
tina.legrand@webrtc.orgba468042012-08-17 10:38:28 +0000755 printf("Codec: %s Freq: %d Rate: %d PackSize: %d\n", codec_name,
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000756 sampling_freq_hz, rate, pack_size);
757 }
758
759 // Store packet size in samples, used to validate the received packet
760 pack_size_samp_ = pack_size;
761
762 // Store the expected packet size in bytes, used to validate the received
763 // packet. Add 0.875 to always round up to a whole byte.
764 // For Celt the packet size in bytes is already counting the stereo part.
765 if (!strcmp(codec_name, "CELT")) {
pbos@webrtc.org0946a562013-04-09 00:28:06 +0000766 pack_size_bytes_ = (uint16_t)(
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000767 static_cast<float>(pack_size * rate) /
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000768 static_cast<float>(sampling_freq_hz * 8) + 0.875) / channels;
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000769 } else {
pbos@webrtc.org0946a562013-04-09 00:28:06 +0000770 pack_size_bytes_ = (uint16_t)(
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000771 static_cast<float>(pack_size * rate) /
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000772 static_cast<float>(sampling_freq_hz * 8) + 0.875);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000773 }
774
775 // Set pointer to the ACM where to register the codec
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000776 AudioCodingModule* my_acm = NULL;
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000777 switch (side) {
778 case 'A': {
andrew@webrtc.org89df0922013-09-12 01:27:43 +0000779 my_acm = acm_a_.get();
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000780 break;
niklase@google.com470e71d2011-07-07 08:21:25 +0000781 }
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000782 case 'B': {
andrew@webrtc.org89df0922013-09-12 01:27:43 +0000783 my_acm = acm_b_.get();
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000784 break;
tina.legrand@webrtc.org16b6b902012-04-12 11:02:38 +0000785 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000786 default:
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000787 break;
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000788 }
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000789 ASSERT_TRUE(my_acm != NULL);
niklase@google.com470e71d2011-07-07 08:21:25 +0000790
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000791 CodecInst my_codec_param;
792 // Get all codec parameters before registering
tina.legrand@webrtc.orgee92b662013-08-27 07:33:51 +0000793 EXPECT_GT(AudioCodingModule::Codec(codec_name, &my_codec_param,
794 sampling_freq_hz, channels), -1);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000795 my_codec_param.rate = rate;
796 my_codec_param.pacsize = pack_size;
tina.legrand@webrtc.orgee92b662013-08-27 07:33:51 +0000797 EXPECT_EQ(0, my_acm->RegisterSendCodec(my_codec_param));
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000798
799 send_codec_name_ = codec_name;
niklase@google.com470e71d2011-07-07 08:21:25 +0000800}
801
tina.legrand@webrtc.org16b6b902012-04-12 11:02:38 +0000802void TestStereo::Run(TestPackStereo* channel, int in_channels, int out_channels,
803 int percent_loss) {
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000804 AudioFrame audio_frame;
niklase@google.com470e71d2011-07-07 08:21:25 +0000805
pbos@webrtc.org0946a562013-04-09 00:28:06 +0000806 int32_t out_freq_hz_b = out_file_.SamplingFrequency();
807 uint16_t rec_size;
808 uint32_t time_stamp_diff;
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000809 channel->reset_payload_size();
810 int error_count = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000811
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000812 while (1) {
813 // Simulate packet loss by setting |packet_loss_| to "true" in
814 // |percent_loss| percent of the loops.
815 if (percent_loss > 0) {
816 if (counter_ == floor((100 / percent_loss) + 0.5)) {
817 counter_ = 0;
818 channel->set_lost_packet(true);
819 } else {
820 channel->set_lost_packet(false);
821 }
822 counter_++;
niklase@google.com470e71d2011-07-07 08:21:25 +0000823 }
824
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000825 // Add 10 msec to ACM
826 if (in_channels == 1) {
827 if (in_file_mono_->EndOfFile()) {
828 break;
829 }
830 in_file_mono_->Read10MsData(audio_frame);
831 } else {
832 if (in_file_stereo_->EndOfFile()) {
833 break;
834 }
835 in_file_stereo_->Read10MsData(audio_frame);
836 }
tina.legrand@webrtc.orgee92b662013-08-27 07:33:51 +0000837 EXPECT_EQ(0, acm_a_->Add10MsData(audio_frame));
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000838
839 // Run sender side of ACM
tina.legrand@webrtc.orgee92b662013-08-27 07:33:51 +0000840 EXPECT_GT(acm_a_->Process(), -1);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000841
842 // Verify that the received packet size matches the settings
843 rec_size = channel->payload_size();
844 if ((0 < rec_size) & (rec_size < 65535)) {
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000845 // Opus is variable rate, skip this test.
846 if (strcmp(send_codec_name_, "opus")) {
847 if ((rec_size != pack_size_bytes_ * out_channels)
848 && (pack_size_bytes_ < 65535)) {
849 error_count++;
850 }
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000851 }
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000852 // Verify that the timestamp is updated with expected length
853 time_stamp_diff = channel->timestamp_diff();
854 if ((counter_ > 10) && (time_stamp_diff != pack_size_samp_)) {
855 error_count++;
856 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000857 }
858
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000859 // Run received side of ACM
tina.legrand@webrtc.orgee92b662013-08-27 07:33:51 +0000860 EXPECT_EQ(0, acm_b_->PlayoutData10Ms(out_freq_hz_b, &audio_frame));
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000861
862 // Write output speech to file
863 out_file_.Write10MsData(
andrew@webrtc.org63a50982012-05-02 23:56:37 +0000864 audio_frame.data_,
865 audio_frame.samples_per_channel_ * audio_frame.num_channels_);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000866 }
867
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000868 EXPECT_EQ(0, error_count);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000869
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000870 if (in_file_mono_->EndOfFile()) {
871 in_file_mono_->Rewind();
872 }
873 if (in_file_stereo_->EndOfFile()) {
874 in_file_stereo_->Rewind();
875 }
876 // Reset in case we ended with a lost packet
877 channel->set_lost_packet(false);
niklase@google.com470e71d2011-07-07 08:21:25 +0000878}
879
pbos@webrtc.org0946a562013-04-09 00:28:06 +0000880void TestStereo::OpenOutFile(int16_t test_number) {
tina.legrand@webrtc.orgba468042012-08-17 10:38:28 +0000881 std::string file_name;
882 std::stringstream file_stream;
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000883 file_stream << webrtc::test::OutputPath() << "teststereo_out_" << test_number
884 << ".pcm";
tina.legrand@webrtc.orgba468042012-08-17 10:38:28 +0000885 file_name = file_stream.str();
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000886 out_file_.Open(file_name, 32000, "wb");
niklase@google.com470e71d2011-07-07 08:21:25 +0000887}
888
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000889void TestStereo::DisplaySendReceiveCodec() {
890 CodecInst my_codec_param;
tina.legrand@webrtc.org7a7a0082013-02-21 10:27:48 +0000891 acm_a_->SendCodec(&my_codec_param);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000892 if (test_mode_ != 0) {
893 printf("%s -> ", my_codec_param.plname);
894 }
tina.legrand@webrtc.org7a7a0082013-02-21 10:27:48 +0000895 acm_b_->ReceiveCodec(&my_codec_param);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000896 if (test_mode_ != 0) {
897 printf("%s\n", my_codec_param.plname);
898 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000899}
900
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000901} // namespace webrtc