blob: 86a75e5b6af98ca495fe7d7028e87c419b926049 [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
kjellander@webrtc.org3c0aae12014-09-04 09:55:40 +000017#include "testing/gtest/include/gtest/gtest.h"
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +000018#include "webrtc/common_types.h"
19#include "webrtc/engine_configurations.h"
20#include "webrtc/modules/audio_coding/main/interface/audio_coding_module_typedefs.h"
21#include "webrtc/modules/audio_coding/main/test/utility.h"
22#include "webrtc/system_wrappers/interface/trace.h"
23#include "webrtc/test/testsupport/fileutils.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000024
tina.legrand@webrtc.org554ae1a2011-12-16 10:09:04 +000025namespace webrtc {
niklase@google.com470e71d2011-07-07 08:21:25 +000026
27// Class for simulating packet handling
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +000028TestPackStereo::TestPackStereo()
29 : receiver_acm_(NULL),
30 seq_no_(0),
31 timestamp_diff_(0),
32 last_in_timestamp_(0),
33 total_bytes_(0),
34 payload_size_(0),
35 codec_mode_(kNotSet),
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000036 lost_packet_(false) {
37}
niklase@google.com470e71d2011-07-07 08:21:25 +000038
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000039TestPackStereo::~TestPackStereo() {
40}
niklase@google.com470e71d2011-07-07 08:21:25 +000041
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +000042void TestPackStereo::RegisterReceiverACM(AudioCodingModule* acm) {
43 receiver_acm_ = acm;
44 return;
45}
niklase@google.com470e71d2011-07-07 08:21:25 +000046
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000047int32_t TestPackStereo::SendData(const FrameType frame_type,
48 const uint8_t payload_type,
49 const uint32_t timestamp,
50 const uint8_t* payload_data,
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +000051 const size_t payload_size,
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000052 const RTPFragmentationHeader* fragmentation) {
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +000053 WebRtcRTPHeader rtp_info;
pbos@webrtc.org0946a562013-04-09 00:28:06 +000054 int32_t status = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +000055
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +000056 rtp_info.header.markerBit = false;
57 rtp_info.header.ssrc = 0;
58 rtp_info.header.sequenceNumber = seq_no_++;
59 rtp_info.header.payloadType = payload_type;
60 rtp_info.header.timestamp = timestamp;
61 if (frame_type == kFrameEmpty) {
tina.legrand@webrtc.org16b6b902012-04-12 11:02:38 +000062 // Skip this frame
63 return 0;
64 }
niklase@google.com470e71d2011-07-07 08:21:25 +000065
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +000066 if (lost_packet_ == false) {
67 if (frame_type != kAudioFrameCN) {
68 rtp_info.type.Audio.isCNG = false;
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +000069 rtp_info.type.Audio.channel = static_cast<int>(codec_mode_);
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +000070 } else {
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +000071 rtp_info.type.Audio.isCNG = true;
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +000072 rtp_info.type.Audio.channel = static_cast<int>(kMono);
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +000073 }
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +000074 status = receiver_acm_->IncomingPacket(payload_data, payload_size,
tina.legrand@webrtc.org45175852012-06-01 09:27:35 +000075 rtp_info);
niklase@google.com470e71d2011-07-07 08:21:25 +000076
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +000077 if (frame_type != kAudioFrameCN) {
henrike@webrtc.org6ac22e62014-08-11 21:06:30 +000078 payload_size_ = static_cast<int>(payload_size);
niklase@google.com470e71d2011-07-07 08:21:25 +000079 } else {
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +000080 payload_size_ = -1;
niklase@google.com470e71d2011-07-07 08:21:25 +000081 }
tina.legrand@webrtc.org16b6b902012-04-12 11:02:38 +000082
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +000083 timestamp_diff_ = timestamp - last_in_timestamp_;
84 last_in_timestamp_ = timestamp;
85 total_bytes_ += payload_size;
tina.legrand@webrtc.org16b6b902012-04-12 11:02:38 +000086 }
87 return status;
niklase@google.com470e71d2011-07-07 08:21:25 +000088}
89
pbos@webrtc.org0946a562013-04-09 00:28:06 +000090uint16_t TestPackStereo::payload_size() {
henrike@webrtc.org6ac22e62014-08-11 21:06:30 +000091 return static_cast<uint16_t>(payload_size_);
niklase@google.com470e71d2011-07-07 08:21:25 +000092}
93
pbos@webrtc.org0946a562013-04-09 00:28:06 +000094uint32_t TestPackStereo::timestamp_diff() {
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +000095 return timestamp_diff_;
niklase@google.com470e71d2011-07-07 08:21:25 +000096}
97
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +000098void TestPackStereo::reset_payload_size() {
99 payload_size_ = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000100}
101
tina.legrand@webrtc.org16b6b902012-04-12 11:02:38 +0000102void TestPackStereo::set_codec_mode(enum StereoMonoMode mode) {
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000103 codec_mode_ = mode;
tina.legrand@webrtc.org16b6b902012-04-12 11:02:38 +0000104}
105
106void TestPackStereo::set_lost_packet(bool lost) {
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000107 lost_packet_ = lost;
niklase@google.com470e71d2011-07-07 08:21:25 +0000108}
109
henrik.lundin@webrtc.orgadaf8092014-04-17 08:29:10 +0000110TestStereo::TestStereo(int test_mode)
111 : acm_a_(AudioCodingModule::Create(0)),
112 acm_b_(AudioCodingModule::Create(1)),
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000113 channel_a2b_(NULL),
114 test_cntr_(0),
115 pack_size_samp_(0),
116 pack_size_bytes_(0),
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +0000117 counter_(0)
118#ifdef WEBRTC_CODEC_G722
119 , g722_pltype_(0)
120#endif
121#ifdef WEBRTC_CODEC_PCM16
122 , l16_8khz_pltype_(-1)
123 , l16_16khz_pltype_(-1)
124 , l16_32khz_pltype_(-1)
125#endif
126#ifdef PCMA_AND_PCMU
127 , pcma_pltype_(-1)
128 , pcmu_pltype_(-1)
129#endif
130#ifdef WEBRTC_CODEC_CELT
131 , celt_pltype_(-1)
132#endif
133#ifdef WEBRTC_CODEC_OPUS
134 , opus_pltype_(-1)
135#endif
136 {
tina.legrand@webrtc.org45175852012-06-01 09:27:35 +0000137 // test_mode = 0 for silent test (auto test)
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000138 test_mode_ = test_mode;
niklase@google.com470e71d2011-07-07 08:21:25 +0000139}
140
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000141TestStereo::~TestStereo() {
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000142 if (channel_a2b_ != NULL) {
143 delete channel_a2b_;
144 channel_a2b_ = NULL;
145 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000146}
147
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000148void TestStereo::Perform() {
pbos@webrtc.org0946a562013-04-09 00:28:06 +0000149 uint16_t frequency_hz;
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000150 int audio_channels;
151 int codec_channels;
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000152 bool dtx;
153 bool vad;
154 ACMVADMode vad_mode;
niklase@google.com470e71d2011-07-07 08:21:25 +0000155
tina.legrand@webrtc.org45175852012-06-01 09:27:35 +0000156 // Open both mono and stereo test files in 32 kHz.
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000157 const std::string file_name_stereo = webrtc::test::ResourcePath(
158 "audio_coding/teststereo32kHz", "pcm");
159 const std::string file_name_mono = webrtc::test::ResourcePath(
160 "audio_coding/testfile32kHz", "pcm");
tina.legrand@webrtc.org45175852012-06-01 09:27:35 +0000161 frequency_hz = 32000;
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000162 in_file_stereo_ = new PCMFile();
163 in_file_mono_ = new PCMFile();
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000164 in_file_stereo_->Open(file_name_stereo, frequency_hz, "rb");
165 in_file_stereo_->ReadStereo(true);
166 in_file_mono_->Open(file_name_mono, frequency_hz, "rb");
167 in_file_mono_->ReadStereo(false);
168
tina.legrand@webrtc.org45175852012-06-01 09:27:35 +0000169 // Create and initialize two ACMs, one for each side of a one-to-one call.
andrew@webrtc.org89df0922013-09-12 01:27:43 +0000170 ASSERT_TRUE((acm_a_.get() != NULL) && (acm_b_.get() != NULL));
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000171 EXPECT_EQ(0, acm_a_->InitializeReceiver());
172 EXPECT_EQ(0, acm_b_->InitializeReceiver());
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000173
tina.legrand@webrtc.org45175852012-06-01 09:27:35 +0000174 // Register all available codes as receiving codecs.
pbos@webrtc.org0946a562013-04-09 00:28:06 +0000175 uint8_t num_encoders = acm_a_->NumberOfCodecs();
tina.legrand@webrtc.org45175852012-06-01 09:27:35 +0000176 CodecInst my_codec_param;
pbos@webrtc.org0946a562013-04-09 00:28:06 +0000177 for (uint8_t n = 0; n < num_encoders; n++) {
tina.legrand@webrtc.org7a7a0082013-02-21 10:27:48 +0000178 EXPECT_EQ(0, acm_b_->Codec(n, &my_codec_param));
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000179 EXPECT_EQ(0, acm_b_->RegisterReceiveCodec(my_codec_param));
tina.legrand@webrtc.org45175852012-06-01 09:27:35 +0000180 }
181
182 // Test that unregister all receive codecs works.
pbos@webrtc.org0946a562013-04-09 00:28:06 +0000183 for (uint8_t n = 0; n < num_encoders; n++) {
tina.legrand@webrtc.org7a7a0082013-02-21 10:27:48 +0000184 EXPECT_EQ(0, acm_b_->Codec(n, &my_codec_param));
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000185 EXPECT_EQ(0, acm_b_->UnregisterReceiveCodec(my_codec_param.pltype));
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000186 }
tina.legrand@webrtc.orgae1c4542012-03-12 08:41:30 +0000187
tina.legrand@webrtc.org45175852012-06-01 09:27:35 +0000188 // Register all available codes as receiving codecs once more.
pbos@webrtc.org0946a562013-04-09 00:28:06 +0000189 for (uint8_t n = 0; n < num_encoders; n++) {
tina.legrand@webrtc.org7a7a0082013-02-21 10:27:48 +0000190 EXPECT_EQ(0, acm_b_->Codec(n, &my_codec_param));
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000191 EXPECT_EQ(0, acm_b_->RegisterReceiveCodec(my_codec_param));
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000192 }
tina.legrand@webrtc.orgae1c4542012-03-12 08:41:30 +0000193
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000194 // Create and connect the channel.
195 channel_a2b_ = new TestPackStereo;
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000196 EXPECT_EQ(0, acm_a_->RegisterTransportCallback(channel_a2b_));
andrew@webrtc.org89df0922013-09-12 01:27:43 +0000197 channel_a2b_->RegisterReceiverACM(acm_b_.get());
tina.legrand@webrtc.orgdf697752012-02-08 10:22:21 +0000198
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000199 // Start with setting VAD/DTX, before we know we will send stereo.
200 // Continue with setting a stereo codec as send codec and verify that
201 // VAD/DTX gets turned off.
202 EXPECT_EQ(0, acm_a_->SetVAD(true, true, VADNormal));
tina.legrand@webrtc.org7a7a0082013-02-21 10:27:48 +0000203 EXPECT_EQ(0, acm_a_->VAD(&dtx, &vad, &vad_mode));
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000204 EXPECT_TRUE(dtx);
205 EXPECT_TRUE(vad);
206 char codec_pcma_temp[] = "PCMA";
207 RegisterSendCodec('A', codec_pcma_temp, 8000, 64000, 80, 2, pcma_pltype_);
tina.legrand@webrtc.org7a7a0082013-02-21 10:27:48 +0000208 EXPECT_EQ(0, acm_a_->VAD(&dtx, &vad, &vad_mode));
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000209 EXPECT_FALSE(dtx);
210 EXPECT_FALSE(vad);
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000211 if (test_mode_ != 0) {
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000212 printf("\n");
213 }
214
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000215 //
216 // Test Stereo-To-Stereo for all codecs.
217 //
218 audio_channels = 2;
219 codec_channels = 2;
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000220
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000221 // All codecs are tested for all allowed sampling frequencies, rates and
222 // packet sizes.
niklase@google.com470e71d2011-07-07 08:21:25 +0000223#ifdef WEBRTC_CODEC_G722
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000224 if (test_mode_ != 0) {
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000225 printf("===========================================================\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000226 printf("Test number: %d\n", test_cntr_ + 1);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000227 printf("Test type: Stereo-to-stereo\n");
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000228 }
229 channel_a2b_->set_codec_mode(kStereo);
230 test_cntr_++;
231 OpenOutFile(test_cntr_);
232 char codec_g722[] = "G722";
233 RegisterSendCodec('A', codec_g722, 16000, 64000, 160, codec_channels,
234 g722_pltype_);
235 Run(channel_a2b_, audio_channels, codec_channels);
236 RegisterSendCodec('A', codec_g722, 16000, 64000, 320, codec_channels,
237 g722_pltype_);
238 Run(channel_a2b_, audio_channels, codec_channels);
239 RegisterSendCodec('A', codec_g722, 16000, 64000, 480, codec_channels,
240 g722_pltype_);
241 Run(channel_a2b_, audio_channels, codec_channels);
242 RegisterSendCodec('A', codec_g722, 16000, 64000, 640, codec_channels,
243 g722_pltype_);
244 Run(channel_a2b_, audio_channels, codec_channels);
245 RegisterSendCodec('A', codec_g722, 16000, 64000, 800, codec_channels,
246 g722_pltype_);
247 Run(channel_a2b_, audio_channels, codec_channels);
248 RegisterSendCodec('A', codec_g722, 16000, 64000, 960, codec_channels,
249 g722_pltype_);
250 Run(channel_a2b_, audio_channels, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000251 out_file_.Close();
niklase@google.com470e71d2011-07-07 08:21:25 +0000252#endif
253#ifdef WEBRTC_CODEC_PCM16
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000254 if (test_mode_ != 0) {
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000255 printf("===========================================================\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000256 printf("Test number: %d\n", test_cntr_ + 1);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000257 printf("Test type: Stereo-to-stereo\n");
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000258 }
259 channel_a2b_->set_codec_mode(kStereo);
260 test_cntr_++;
261 OpenOutFile(test_cntr_);
262 char codec_l16[] = "L16";
263 RegisterSendCodec('A', codec_l16, 8000, 128000, 80, codec_channels,
264 l16_8khz_pltype_);
265 Run(channel_a2b_, audio_channels, codec_channels);
266 RegisterSendCodec('A', codec_l16, 8000, 128000, 160, codec_channels,
267 l16_8khz_pltype_);
268 Run(channel_a2b_, audio_channels, codec_channels);
269 RegisterSendCodec('A', codec_l16, 8000, 128000, 240, codec_channels,
270 l16_8khz_pltype_);
271 Run(channel_a2b_, audio_channels, codec_channels);
272 RegisterSendCodec('A', codec_l16, 8000, 128000, 320, codec_channels,
273 l16_8khz_pltype_);
274 Run(channel_a2b_, audio_channels, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000275 out_file_.Close();
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000276
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000277 if (test_mode_ != 0) {
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000278 printf("===========================================================\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000279 printf("Test number: %d\n", test_cntr_ + 1);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000280 printf("Test type: Stereo-to-stereo\n");
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000281 }
282 test_cntr_++;
283 OpenOutFile(test_cntr_);
284 RegisterSendCodec('A', codec_l16, 16000, 256000, 160, codec_channels,
285 l16_16khz_pltype_);
286 Run(channel_a2b_, audio_channels, codec_channels);
287 RegisterSendCodec('A', codec_l16, 16000, 256000, 320, codec_channels,
288 l16_16khz_pltype_);
289 Run(channel_a2b_, audio_channels, codec_channels);
290 RegisterSendCodec('A', codec_l16, 16000, 256000, 480, codec_channels,
291 l16_16khz_pltype_);
292 Run(channel_a2b_, audio_channels, codec_channels);
293 RegisterSendCodec('A', codec_l16, 16000, 256000, 640, codec_channels,
294 l16_16khz_pltype_);
295 Run(channel_a2b_, audio_channels, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000296 out_file_.Close();
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000297
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000298 if (test_mode_ != 0) {
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000299 printf("===========================================================\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000300 printf("Test number: %d\n", test_cntr_ + 1);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000301 printf("Test type: Stereo-to-stereo\n");
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000302 }
303 test_cntr_++;
304 OpenOutFile(test_cntr_);
305 RegisterSendCodec('A', codec_l16, 32000, 512000, 320, codec_channels,
306 l16_32khz_pltype_);
307 Run(channel_a2b_, audio_channels, codec_channels);
308 RegisterSendCodec('A', codec_l16, 32000, 512000, 640, codec_channels,
309 l16_32khz_pltype_);
310 Run(channel_a2b_, audio_channels, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000311 out_file_.Close();
niklase@google.com470e71d2011-07-07 08:21:25 +0000312#endif
niklase@google.com470e71d2011-07-07 08:21:25 +0000313#ifdef PCMA_AND_PCMU
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000314 if (test_mode_ != 0) {
315 printf("===========================================================\n");
316 printf("Test number: %d\n", test_cntr_ + 1);
317 printf("Test type: Stereo-to-stereo\n");
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000318 }
319 channel_a2b_->set_codec_mode(kStereo);
320 audio_channels = 2;
321 codec_channels = 2;
322 test_cntr_++;
323 OpenOutFile(test_cntr_);
324 char codec_pcma[] = "PCMA";
325 RegisterSendCodec('A', codec_pcma, 8000, 64000, 80, codec_channels,
326 pcma_pltype_);
327 Run(channel_a2b_, audio_channels, codec_channels);
328 RegisterSendCodec('A', codec_pcma, 8000, 64000, 160, codec_channels,
329 pcma_pltype_);
330 Run(channel_a2b_, audio_channels, codec_channels);
331 RegisterSendCodec('A', codec_pcma, 8000, 64000, 240, codec_channels,
332 pcma_pltype_);
333 Run(channel_a2b_, audio_channels, codec_channels);
334 RegisterSendCodec('A', codec_pcma, 8000, 64000, 320, codec_channels,
335 pcma_pltype_);
336 Run(channel_a2b_, audio_channels, codec_channels);
337 RegisterSendCodec('A', codec_pcma, 8000, 64000, 400, codec_channels,
338 pcma_pltype_);
339 Run(channel_a2b_, audio_channels, codec_channels);
340 RegisterSendCodec('A', codec_pcma, 8000, 64000, 480, codec_channels,
341 pcma_pltype_);
342 Run(channel_a2b_, audio_channels, codec_channels);
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000343
344 // Test that VAD/DTX cannot be turned on while sending stereo.
345 EXPECT_EQ(-1, acm_a_->SetVAD(true, true, VADNormal));
tina.legrand@webrtc.org7a7a0082013-02-21 10:27:48 +0000346 EXPECT_EQ(0, acm_a_->VAD(&dtx, &vad, &vad_mode));
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000347 EXPECT_FALSE(dtx);
348 EXPECT_FALSE(vad);
349 EXPECT_EQ(-1, acm_a_->SetVAD(true, false, 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(false, true, 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(0, acm_a_->SetVAD(false, false, 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
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000362 out_file_.Close();
363 if (test_mode_ != 0) {
364 printf("===========================================================\n");
365 printf("Test number: %d\n", test_cntr_ + 1);
366 printf("Test type: Stereo-to-stereo\n");
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000367 }
368 test_cntr_++;
369 OpenOutFile(test_cntr_);
370 char codec_pcmu[] = "PCMU";
371 RegisterSendCodec('A', codec_pcmu, 8000, 64000, 80, codec_channels,
372 pcmu_pltype_);
373 Run(channel_a2b_, audio_channels, codec_channels);
374 RegisterSendCodec('A', codec_pcmu, 8000, 64000, 160, codec_channels,
375 pcmu_pltype_);
376 Run(channel_a2b_, audio_channels, codec_channels);
377 RegisterSendCodec('A', codec_pcmu, 8000, 64000, 240, codec_channels,
378 pcmu_pltype_);
379 Run(channel_a2b_, audio_channels, codec_channels);
380 RegisterSendCodec('A', codec_pcmu, 8000, 64000, 320, codec_channels,
381 pcmu_pltype_);
382 Run(channel_a2b_, audio_channels, codec_channels);
383 RegisterSendCodec('A', codec_pcmu, 8000, 64000, 400, codec_channels,
384 pcmu_pltype_);
385 Run(channel_a2b_, audio_channels, codec_channels);
386 RegisterSendCodec('A', codec_pcmu, 8000, 64000, 480, codec_channels,
387 pcmu_pltype_);
388 Run(channel_a2b_, audio_channels, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000389 out_file_.Close();
niklase@google.com470e71d2011-07-07 08:21:25 +0000390#endif
tina.legrand@webrtc.orgdf697752012-02-08 10:22:21 +0000391#ifdef WEBRTC_CODEC_CELT
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000392 if (test_mode_ != 0) {
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000393 printf("===========================================================\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000394 printf("Test number: %d\n", test_cntr_ + 1);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000395 printf("Test type: Stereo-to-stereo\n");
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000396 }
397 channel_a2b_->set_codec_mode(kStereo);
398 audio_channels = 2;
399 codec_channels = 2;
400 test_cntr_++;
401 OpenOutFile(test_cntr_);
402 char codec_celt[] = "CELT";
tina.legrand@webrtc.org90af7f82012-06-07 08:57:27 +0000403 RegisterSendCodec('A', codec_celt, 32000, 48000, 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.org90af7f82012-06-07 08:57:27 +0000406 RegisterSendCodec('A', codec_celt, 32000, 64000, 640, codec_channels,
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000407 celt_pltype_);
408 Run(channel_a2b_, audio_channels, codec_channels);
tina.legrand@webrtc.org90af7f82012-06-07 08:57:27 +0000409 RegisterSendCodec('A', codec_celt, 32000, 128000, 640, codec_channels,
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000410 celt_pltype_);
411 Run(channel_a2b_, audio_channels, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000412 out_file_.Close();
tina.legrand@webrtc.orgdf697752012-02-08 10:22:21 +0000413#endif
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000414#ifdef WEBRTC_CODEC_OPUS
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000415 if (test_mode_ != 0) {
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000416 printf("===========================================================\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000417 printf("Test number: %d\n", test_cntr_ + 1);
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000418 printf("Test type: Stereo-to-stereo\n");
419 }
420 channel_a2b_->set_codec_mode(kStereo);
421 audio_channels = 2;
422 codec_channels = 2;
423 test_cntr_++;
424 OpenOutFile(test_cntr_);
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000425
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000426 char codec_opus[] = "opus";
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000427 // Run Opus with 10 ms frame size.
428 RegisterSendCodec('A', codec_opus, 48000, 64000, 480, codec_channels,
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000429 opus_pltype_);
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000430 Run(channel_a2b_, audio_channels, codec_channels);
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000431 // Run Opus with 20 ms frame size.
432 RegisterSendCodec('A', codec_opus, 48000, 64000, 480*2, codec_channels,
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000433 opus_pltype_);
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000434 Run(channel_a2b_, audio_channels, codec_channels);
435 // Run Opus with 40 ms frame size.
436 RegisterSendCodec('A', codec_opus, 48000, 64000, 480*4, 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 60 ms frame size.
440 RegisterSendCodec('A', codec_opus, 48000, 64000, 480*6, 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 20 ms frame size and different bitrates.
444 RegisterSendCodec('A', codec_opus, 48000, 40000, 960, codec_channels,
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000445 opus_pltype_);
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000446 Run(channel_a2b_, audio_channels, codec_channels);
447 RegisterSendCodec('A', codec_opus, 48000, 510000, 960, codec_channels,
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000448 opus_pltype_);
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000449 Run(channel_a2b_, audio_channels, codec_channels);
450 out_file_.Close();
451#endif
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000452 //
453 // Test Mono-To-Stereo for all codecs.
454 //
455 audio_channels = 1;
456 codec_channels = 2;
niklase@google.com470e71d2011-07-07 08:21:25 +0000457
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000458#ifdef WEBRTC_CODEC_G722
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000459 if (test_mode_ != 0) {
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000460 printf("===============================================================\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000461 printf("Test number: %d\n", test_cntr_ + 1);
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000462 printf("Test type: Mono-to-stereo\n");
463 }
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000464 test_cntr_++;
465 channel_a2b_->set_codec_mode(kStereo);
466 OpenOutFile(test_cntr_);
467 RegisterSendCodec('A', codec_g722, 16000, 64000, 160, codec_channels,
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000468 g722_pltype_);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000469 Run(channel_a2b_, audio_channels, codec_channels);
470 out_file_.Close();
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000471#endif
472#ifdef WEBRTC_CODEC_PCM16
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000473 if (test_mode_ != 0) {
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000474 printf("===============================================================\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000475 printf("Test number: %d\n", test_cntr_ + 1);
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000476 printf("Test type: Mono-to-stereo\n");
477 }
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000478 test_cntr_++;
479 channel_a2b_->set_codec_mode(kStereo);
480 OpenOutFile(test_cntr_);
481 RegisterSendCodec('A', codec_l16, 8000, 128000, 80, codec_channels,
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000482 l16_8khz_pltype_);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000483 Run(channel_a2b_, audio_channels, codec_channels);
484 out_file_.Close();
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000485 if (test_mode_ != 0) {
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000486 printf("===============================================================\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000487 printf("Test number: %d\n", test_cntr_ + 1);
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000488 printf("Test type: Mono-to-stereo\n");
489 }
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000490 test_cntr_++;
491 OpenOutFile(test_cntr_);
492 RegisterSendCodec('A', codec_l16, 16000, 256000, 160, codec_channels,
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000493 l16_16khz_pltype_);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000494 Run(channel_a2b_, audio_channels, codec_channels);
495 out_file_.Close();
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000496 if (test_mode_ != 0) {
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000497 printf("===============================================================\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000498 printf("Test number: %d\n", test_cntr_ + 1);
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000499 printf("Test type: Mono-to-stereo\n");
500 }
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000501 test_cntr_++;
502 OpenOutFile(test_cntr_);
503 RegisterSendCodec('A', codec_l16, 32000, 512000, 320, codec_channels,
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000504 l16_32khz_pltype_);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000505 Run(channel_a2b_, audio_channels, codec_channels);
506 out_file_.Close();
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000507#endif
508#ifdef PCMA_AND_PCMU
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000509 if (test_mode_ != 0) {
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000510 printf("===============================================================\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000511 printf("Test number: %d\n", test_cntr_ + 1);
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000512 printf("Test type: Mono-to-stereo\n");
513 }
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000514 test_cntr_++;
515 channel_a2b_->set_codec_mode(kStereo);
516 OpenOutFile(test_cntr_);
517 RegisterSendCodec('A', codec_pcmu, 8000, 64000, 80, codec_channels,
tina.legrand@webrtc.orgae1c4542012-03-12 08:41:30 +0000518 pcmu_pltype_);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000519 Run(channel_a2b_, audio_channels, codec_channels);
520 RegisterSendCodec('A', codec_pcma, 8000, 64000, 80, codec_channels,
tina.legrand@webrtc.orgae1c4542012-03-12 08:41:30 +0000521 pcma_pltype_);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000522 Run(channel_a2b_, audio_channels, codec_channels);
523 out_file_.Close();
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000524#endif
tina.legrand@webrtc.orgdf697752012-02-08 10:22:21 +0000525#ifdef WEBRTC_CODEC_CELT
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000526 if (test_mode_ != 0) {
tina.legrand@webrtc.orgdf697752012-02-08 10:22:21 +0000527 printf("===============================================================\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000528 printf("Test number: %d\n", test_cntr_ + 1);
tina.legrand@webrtc.orgdf697752012-02-08 10:22:21 +0000529 printf("Test type: Mono-to-stereo\n");
530 }
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000531 test_cntr_++;
532 channel_a2b_->set_codec_mode(kStereo);
533 OpenOutFile(test_cntr_);
tina.legrand@webrtc.org90af7f82012-06-07 08:57:27 +0000534 RegisterSendCodec('A', codec_celt, 32000, 64000, 640, codec_channels,
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000535 celt_pltype_);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000536 Run(channel_a2b_, audio_channels, codec_channels);
537 out_file_.Close();
tina.legrand@webrtc.orgdf697752012-02-08 10:22:21 +0000538#endif
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000539#ifdef WEBRTC_CODEC_OPUS
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000540 if (test_mode_ != 0) {
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000541 printf("===============================================================\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000542 printf("Test number: %d\n", test_cntr_ + 1);
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000543 printf("Test type: Mono-to-stereo\n");
544 }
tina.legrand@webrtc.orgc4590582012-11-28 12:23:29 +0000545
546 // Keep encode and decode in stereo.
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000547 test_cntr_++;
548 channel_a2b_->set_codec_mode(kStereo);
549 OpenOutFile(test_cntr_);
550 RegisterSendCodec('A', codec_opus, 48000, 64000, 960, codec_channels,
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000551 opus_pltype_);
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000552 Run(channel_a2b_, audio_channels, codec_channels);
tina.legrand@webrtc.orgc4590582012-11-28 12:23:29 +0000553
554 // Encode in mono, decode in stereo mode.
555 RegisterSendCodec('A', codec_opus, 48000, 64000, 960, 1, opus_pltype_);
556 Run(channel_a2b_, audio_channels, codec_channels);
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000557 out_file_.Close();
558#endif
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000559
560 //
561 // Test Stereo-To-Mono for all codecs.
562 //
563 audio_channels = 2;
564 codec_channels = 1;
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000565 channel_a2b_->set_codec_mode(kMono);
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000566
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000567#ifdef WEBRTC_CODEC_G722
568 // Run stereo audio and mono codec.
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000569 if (test_mode_ != 0) {
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000570 printf("===============================================================\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000571 printf("Test number: %d\n", test_cntr_ + 1);
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000572 printf("Test type: Stereo-to-mono\n");
573 }
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000574 test_cntr_++;
575 OpenOutFile(test_cntr_);
576 RegisterSendCodec('A', codec_g722, 16000, 64000, 160, codec_channels,
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000577 g722_pltype_);
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000578
579 // Make sure it is possible to set VAD/CNG, now that we are sending mono
580 // again.
581 EXPECT_EQ(0, acm_a_->SetVAD(true, true, VADNormal));
tina.legrand@webrtc.org7a7a0082013-02-21 10:27:48 +0000582 EXPECT_EQ(0, acm_a_->VAD(&dtx, &vad, &vad_mode));
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000583 EXPECT_TRUE(dtx);
584 EXPECT_TRUE(vad);
585 EXPECT_EQ(0, acm_a_->SetVAD(false, false, VADNormal));
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000586 Run(channel_a2b_, audio_channels, codec_channels);
587 out_file_.Close();
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000588#endif
589#ifdef WEBRTC_CODEC_PCM16
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000590 if (test_mode_ != 0) {
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000591 printf("===============================================================\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000592 printf("Test number: %d\n", test_cntr_ + 1);
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000593 printf("Test type: Stereo-to-mono\n");
594 }
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000595 test_cntr_++;
596 OpenOutFile(test_cntr_);
597 RegisterSendCodec('A', codec_l16, 8000, 128000, 80, codec_channels,
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000598 l16_8khz_pltype_);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000599 Run(channel_a2b_, audio_channels, codec_channels);
600 out_file_.Close();
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000601 if (test_mode_ != 0) {
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000602 printf("===============================================================\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000603 printf("Test number: %d\n", test_cntr_ + 1);
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000604 printf("Test type: Stereo-to-mono\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000605 }
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000606 test_cntr_++;
607 OpenOutFile(test_cntr_);
608 RegisterSendCodec('A', codec_l16, 16000, 256000, 160, codec_channels,
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000609 l16_16khz_pltype_);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000610 Run(channel_a2b_, audio_channels, codec_channels);
611 out_file_.Close();
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000612 if (test_mode_ != 0) {
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000613 printf("==============================================================\n");
614 printf("Test number: %d\n", test_cntr_ + 1);
615 printf("Test type: Stereo-to-mono\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000616 }
617 test_cntr_++;
618 OpenOutFile(test_cntr_);
619 RegisterSendCodec('A', codec_l16, 32000, 512000, 320, codec_channels,
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000620 l16_32khz_pltype_);
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000621 Run(channel_a2b_, audio_channels, codec_channels);
622 out_file_.Close();
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000623#endif
624#ifdef PCMA_AND_PCMU
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000625 if (test_mode_ != 0) {
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000626 printf("===============================================================\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000627 printf("Test number: %d\n", test_cntr_ + 1);
tina.legrand@webrtc.orgdf697752012-02-08 10:22:21 +0000628 printf("Test type: Stereo-to-mono\n");
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000629 }
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000630 test_cntr_++;
631 OpenOutFile(test_cntr_);
632 RegisterSendCodec('A', codec_pcmu, 8000, 64000, 80, codec_channels,
tina.legrand@webrtc.orgae1c4542012-03-12 08:41:30 +0000633 pcmu_pltype_);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000634 Run(channel_a2b_, audio_channels, codec_channels);
635 RegisterSendCodec('A', codec_pcma, 8000, 64000, 80, codec_channels,
tina.legrand@webrtc.orgae1c4542012-03-12 08:41:30 +0000636 pcma_pltype_);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000637 Run(channel_a2b_, audio_channels, codec_channels);
638 out_file_.Close();
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000639#endif
tina.legrand@webrtc.orgdf697752012-02-08 10:22:21 +0000640#ifdef WEBRTC_CODEC_CELT
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000641 if (test_mode_ != 0) {
tina.legrand@webrtc.orgdf697752012-02-08 10:22:21 +0000642 printf("===============================================================\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000643 printf("Test number: %d\n", test_cntr_ + 1);
tina.legrand@webrtc.orgdf697752012-02-08 10:22:21 +0000644 printf("Test type: Stereo-to-mono\n");
645 }
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000646 test_cntr_++;
647 OpenOutFile(test_cntr_);
tina.legrand@webrtc.org90af7f82012-06-07 08:57:27 +0000648 RegisterSendCodec('A', codec_celt, 32000, 64000, 640, codec_channels,
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000649 celt_pltype_);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000650 Run(channel_a2b_, audio_channels, codec_channels);
651 out_file_.Close();
tina.legrand@webrtc.orgdf697752012-02-08 10:22:21 +0000652#endif
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000653#ifdef WEBRTC_CODEC_OPUS
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000654 if (test_mode_ != 0) {
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000655 printf("===============================================================\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000656 printf("Test number: %d\n", test_cntr_ + 1);
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000657 printf("Test type: Stereo-to-mono\n");
658 }
659 test_cntr_++;
660 OpenOutFile(test_cntr_);
tina.legrand@webrtc.orgc4590582012-11-28 12:23:29 +0000661 // Encode and decode in mono.
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000662 RegisterSendCodec('A', codec_opus, 48000, 32000, 960, codec_channels,
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000663 opus_pltype_);
tina.legrand@webrtc.orgc4590582012-11-28 12:23:29 +0000664 CodecInst opus_codec_param;
pbos@webrtc.org0946a562013-04-09 00:28:06 +0000665 for (uint8_t n = 0; n < num_encoders; n++) {
tina.legrand@webrtc.org7a7a0082013-02-21 10:27:48 +0000666 EXPECT_EQ(0, acm_b_->Codec(n, &opus_codec_param));
tina.legrand@webrtc.orgc4590582012-11-28 12:23:29 +0000667 if (!strcmp(opus_codec_param.plname, "opus")) {
668 opus_codec_param.channels = 1;
669 EXPECT_EQ(0, acm_b_->RegisterReceiveCodec(opus_codec_param));
670 break;
671 }
672 }
673 Run(channel_a2b_, audio_channels, codec_channels);
674
675 // Encode in stereo, decode in mono.
676 RegisterSendCodec('A', codec_opus, 48000, 32000, 960, 2, opus_pltype_);
677 Run(channel_a2b_, audio_channels, codec_channels);
678
679 out_file_.Close();
680
681 // Test switching between decoding mono and stereo for Opus.
682
683 // Decode in mono.
684 test_cntr_++;
685 OpenOutFile(test_cntr_);
686 if (test_mode_ != 0) {
687 // Print out codec and settings
688 printf("Test number: %d\nCodec: Opus Freq: 48000 Rate :32000 PackSize: 960"
689 " Decode: mono\n", test_cntr_);
690 }
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000691 Run(channel_a2b_, audio_channels, codec_channels);
692 out_file_.Close();
tina.legrand@webrtc.orgc4590582012-11-28 12:23:29 +0000693 // Decode in stereo.
694 test_cntr_++;
695 OpenOutFile(test_cntr_);
696 if (test_mode_ != 0) {
697 // Print out codec and settings
698 printf("Test number: %d\nCodec: Opus Freq: 48000 Rate :32000 PackSize: 960"
699 " Decode: stereo\n", test_cntr_);
700 }
701 opus_codec_param.channels = 2;
702 EXPECT_EQ(0, acm_b_->RegisterReceiveCodec(opus_codec_param));
703 Run(channel_a2b_, audio_channels, 2);
704 out_file_.Close();
705 // Decode in mono.
706 test_cntr_++;
707 OpenOutFile(test_cntr_);
708 if (test_mode_ != 0) {
709 // Print out codec and settings
710 printf("Test number: %d\nCodec: Opus Freq: 48000 Rate :32000 PackSize: 960"
711 " Decode: mono\n", test_cntr_);
712 }
713 opus_codec_param.channels = 1;
714 EXPECT_EQ(0, acm_b_->RegisterReceiveCodec(opus_codec_param));
715 Run(channel_a2b_, audio_channels, codec_channels);
716 out_file_.Close();
717
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000718#endif
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000719
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000720 // Print out which codecs were tested, and which were not, in the run.
721 if (test_mode_ != 0) {
722 printf("\nThe following codecs was INCLUDED in the test:\n");
niklase@google.com470e71d2011-07-07 08:21:25 +0000723#ifdef WEBRTC_CODEC_G722
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000724 printf(" G.722\n");
niklase@google.com470e71d2011-07-07 08:21:25 +0000725#endif
726#ifdef WEBRTC_CODEC_PCM16
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000727 printf(" PCM16\n");
niklase@google.com470e71d2011-07-07 08:21:25 +0000728#endif
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000729 printf(" G.711\n");
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000730#ifdef WEBRTC_CODEC_CELT
731 printf(" CELT\n");
732#endif
tina.legrand@webrtc.orgc4590582012-11-28 12:23:29 +0000733#ifdef WEBRTC_CODEC_OPUS
734 printf(" Opus\n");
735#endif
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000736 printf("\nTo complete the test, listen to the %d number of output "
737 "files.\n",
738 test_cntr_);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000739 }
740
741 // Delete the file pointers.
742 delete in_file_stereo_;
743 delete in_file_mono_;
niklase@google.com470e71d2011-07-07 08:21:25 +0000744}
745
746// Register Codec to use in the test
747//
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000748// Input: side - which ACM to use, 'A' or 'B'
749// codec_name - name to use when register the codec
750// sampling_freq_hz - sampling frequency in Herz
751// rate - bitrate in bytes
752// pack_size - packet size in samples
753// channels - number of channels; 1 for mono, 2 for stereo
754// payload_type - payload type for the codec
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000755void TestStereo::RegisterSendCodec(char side, char* codec_name,
pbos@webrtc.org0946a562013-04-09 00:28:06 +0000756 int32_t sampling_freq_hz, int rate,
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000757 int pack_size, int channels,
758 int payload_type) {
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000759 if (test_mode_ != 0) {
760 // Print out codec and settings
tina.legrand@webrtc.orgba468042012-08-17 10:38:28 +0000761 printf("Codec: %s Freq: %d Rate: %d PackSize: %d\n", codec_name,
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000762 sampling_freq_hz, rate, pack_size);
763 }
764
765 // Store packet size in samples, used to validate the received packet
766 pack_size_samp_ = pack_size;
767
768 // Store the expected packet size in bytes, used to validate the received
769 // packet. Add 0.875 to always round up to a whole byte.
770 // For Celt the packet size in bytes is already counting the stereo part.
771 if (!strcmp(codec_name, "CELT")) {
pbos@webrtc.org0946a562013-04-09 00:28:06 +0000772 pack_size_bytes_ = (uint16_t)(
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000773 static_cast<float>(pack_size * rate) /
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000774 static_cast<float>(sampling_freq_hz * 8) + 0.875) / channels;
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000775 } else {
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);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000779 }
780
781 // Set pointer to the ACM where to register the codec
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000782 AudioCodingModule* my_acm = NULL;
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000783 switch (side) {
784 case 'A': {
andrew@webrtc.org89df0922013-09-12 01:27:43 +0000785 my_acm = acm_a_.get();
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000786 break;
niklase@google.com470e71d2011-07-07 08:21:25 +0000787 }
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000788 case 'B': {
andrew@webrtc.org89df0922013-09-12 01:27:43 +0000789 my_acm = acm_b_.get();
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000790 break;
tina.legrand@webrtc.org16b6b902012-04-12 11:02:38 +0000791 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000792 default:
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000793 break;
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000794 }
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000795 ASSERT_TRUE(my_acm != NULL);
niklase@google.com470e71d2011-07-07 08:21:25 +0000796
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000797 CodecInst my_codec_param;
798 // Get all codec parameters before registering
tina.legrand@webrtc.orgee92b662013-08-27 07:33:51 +0000799 EXPECT_GT(AudioCodingModule::Codec(codec_name, &my_codec_param,
800 sampling_freq_hz, channels), -1);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000801 my_codec_param.rate = rate;
802 my_codec_param.pacsize = pack_size;
tina.legrand@webrtc.orgee92b662013-08-27 07:33:51 +0000803 EXPECT_EQ(0, my_acm->RegisterSendCodec(my_codec_param));
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000804
805 send_codec_name_ = codec_name;
niklase@google.com470e71d2011-07-07 08:21:25 +0000806}
807
tina.legrand@webrtc.org16b6b902012-04-12 11:02:38 +0000808void TestStereo::Run(TestPackStereo* channel, int in_channels, int out_channels,
809 int percent_loss) {
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000810 AudioFrame audio_frame;
niklase@google.com470e71d2011-07-07 08:21:25 +0000811
pbos@webrtc.org0946a562013-04-09 00:28:06 +0000812 int32_t out_freq_hz_b = out_file_.SamplingFrequency();
813 uint16_t rec_size;
814 uint32_t time_stamp_diff;
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000815 channel->reset_payload_size();
816 int error_count = 0;
tina.legrand@webrtc.org65d61c32014-06-05 13:42:51 +0000817 int variable_bytes = 0;
818 int variable_packets = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000819
andresp@webrtc.orgd0b436a2014-01-13 13:15:59 +0000820 while (1) {
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000821 // Simulate packet loss by setting |packet_loss_| to "true" in
822 // |percent_loss| percent of the loops.
823 if (percent_loss > 0) {
824 if (counter_ == floor((100 / percent_loss) + 0.5)) {
825 counter_ = 0;
826 channel->set_lost_packet(true);
827 } else {
828 channel->set_lost_packet(false);
829 }
830 counter_++;
niklase@google.com470e71d2011-07-07 08:21:25 +0000831 }
832
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000833 // Add 10 msec to ACM
834 if (in_channels == 1) {
835 if (in_file_mono_->EndOfFile()) {
836 break;
837 }
838 in_file_mono_->Read10MsData(audio_frame);
839 } else {
840 if (in_file_stereo_->EndOfFile()) {
841 break;
842 }
843 in_file_stereo_->Read10MsData(audio_frame);
844 }
tina.legrand@webrtc.orgee92b662013-08-27 07:33:51 +0000845 EXPECT_EQ(0, acm_a_->Add10MsData(audio_frame));
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000846
847 // Run sender side of ACM
tina.legrand@webrtc.orgee92b662013-08-27 07:33:51 +0000848 EXPECT_GT(acm_a_->Process(), -1);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000849
tina.legrand@webrtc.org65d61c32014-06-05 13:42:51 +0000850 // Verify that the received packet size matches the settings.
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000851 rec_size = channel->payload_size();
852 if ((0 < rec_size) & (rec_size < 65535)) {
tina.legrand@webrtc.org65d61c32014-06-05 13:42:51 +0000853 if (strcmp(send_codec_name_, "opus") == 0) {
854 // Opus is a variable rate codec, hence calculate the average packet
855 // size, and later make sure the average is in the right range.
856 variable_bytes += rec_size;
857 variable_packets++;
858 } else {
859 // For fixed rate codecs, check that packet size is correct.
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000860 if ((rec_size != pack_size_bytes_ * out_channels)
861 && (pack_size_bytes_ < 65535)) {
862 error_count++;
863 }
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000864 }
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000865 // Verify that the timestamp is updated with expected length
866 time_stamp_diff = channel->timestamp_diff();
867 if ((counter_ > 10) && (time_stamp_diff != pack_size_samp_)) {
868 error_count++;
869 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000870 }
871
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000872 // Run received side of ACM
tina.legrand@webrtc.orgee92b662013-08-27 07:33:51 +0000873 EXPECT_EQ(0, acm_b_->PlayoutData10Ms(out_freq_hz_b, &audio_frame));
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000874
875 // Write output speech to file
876 out_file_.Write10MsData(
andrew@webrtc.org63a50982012-05-02 23:56:37 +0000877 audio_frame.data_,
878 audio_frame.samples_per_channel_ * audio_frame.num_channels_);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000879 }
880
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000881 EXPECT_EQ(0, error_count);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000882
tina.legrand@webrtc.org65d61c32014-06-05 13:42:51 +0000883 // Check that packet size is in the right range for variable rate codecs,
884 // such as Opus.
885 if (variable_packets > 0) {
886 variable_bytes /= variable_packets;
887 EXPECT_NEAR(variable_bytes, pack_size_bytes_, 3);
888 }
889
andresp@webrtc.orgd0b436a2014-01-13 13:15:59 +0000890 if (in_file_mono_->EndOfFile()) {
891 in_file_mono_->Rewind();
892 }
893 if (in_file_stereo_->EndOfFile()) {
894 in_file_stereo_->Rewind();
895 }
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000896 // Reset in case we ended with a lost packet
897 channel->set_lost_packet(false);
niklase@google.com470e71d2011-07-07 08:21:25 +0000898}
899
pbos@webrtc.org0946a562013-04-09 00:28:06 +0000900void TestStereo::OpenOutFile(int16_t test_number) {
tina.legrand@webrtc.orgba468042012-08-17 10:38:28 +0000901 std::string file_name;
902 std::stringstream file_stream;
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000903 file_stream << webrtc::test::OutputPath() << "teststereo_out_" << test_number
904 << ".pcm";
tina.legrand@webrtc.orgba468042012-08-17 10:38:28 +0000905 file_name = file_stream.str();
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000906 out_file_.Open(file_name, 32000, "wb");
niklase@google.com470e71d2011-07-07 08:21:25 +0000907}
908
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000909void TestStereo::DisplaySendReceiveCodec() {
910 CodecInst my_codec_param;
tina.legrand@webrtc.org7a7a0082013-02-21 10:27:48 +0000911 acm_a_->SendCodec(&my_codec_param);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000912 if (test_mode_ != 0) {
913 printf("%s -> ", my_codec_param.plname);
914 }
tina.legrand@webrtc.org7a7a0082013-02-21 10:27:48 +0000915 acm_b_->ReceiveCodec(&my_codec_param);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000916 if (test_mode_ != 0) {
917 printf("%s\n", my_codec_param.plname);
918 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000919}
920
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000921} // namespace webrtc