blob: 85a2ae283b217f8abbb9e66efc115f4ea26640f0 [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
kjellander3e6db232015-11-26 04:44:54 -080011#include "webrtc/modules/audio_coding/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"
kjellander3e6db232015-11-26 04:44:54 -080020#include "webrtc/modules/audio_coding/include/audio_coding_module_typedefs.h"
21#include "webrtc/modules/audio_coding/test/utility.h"
Henrik Kjellander98f53512015-10-28 18:17:40 +010022#include "webrtc/system_wrappers/include/trace.h"
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +000023#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;
pbos22993e12015-10-19 02:39:06 -070061 if (frame_type == kEmptyFrame) {
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
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +0000121 , l16_8khz_pltype_(-1)
122 , l16_16khz_pltype_(-1)
123 , l16_32khz_pltype_(-1)
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +0000124#ifdef PCMA_AND_PCMU
125 , pcma_pltype_(-1)
126 , pcmu_pltype_(-1)
127#endif
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +0000128#ifdef WEBRTC_CODEC_OPUS
129 , opus_pltype_(-1)
130#endif
131 {
tina.legrand@webrtc.org45175852012-06-01 09:27:35 +0000132 // test_mode = 0 for silent test (auto test)
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000133 test_mode_ = test_mode;
niklase@google.com470e71d2011-07-07 08:21:25 +0000134}
135
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000136TestStereo::~TestStereo() {
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000137 if (channel_a2b_ != NULL) {
138 delete channel_a2b_;
139 channel_a2b_ = NULL;
140 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000141}
142
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000143void TestStereo::Perform() {
pbos@webrtc.org0946a562013-04-09 00:28:06 +0000144 uint16_t frequency_hz;
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000145 int audio_channels;
146 int codec_channels;
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000147 bool dtx;
148 bool vad;
149 ACMVADMode vad_mode;
niklase@google.com470e71d2011-07-07 08:21:25 +0000150
tina.legrand@webrtc.org45175852012-06-01 09:27:35 +0000151 // Open both mono and stereo test files in 32 kHz.
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000152 const std::string file_name_stereo = webrtc::test::ResourcePath(
153 "audio_coding/teststereo32kHz", "pcm");
154 const std::string file_name_mono = webrtc::test::ResourcePath(
155 "audio_coding/testfile32kHz", "pcm");
tina.legrand@webrtc.org45175852012-06-01 09:27:35 +0000156 frequency_hz = 32000;
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000157 in_file_stereo_ = new PCMFile();
158 in_file_mono_ = new PCMFile();
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000159 in_file_stereo_->Open(file_name_stereo, frequency_hz, "rb");
160 in_file_stereo_->ReadStereo(true);
161 in_file_mono_->Open(file_name_mono, frequency_hz, "rb");
162 in_file_mono_->ReadStereo(false);
163
tina.legrand@webrtc.org45175852012-06-01 09:27:35 +0000164 // Create and initialize two ACMs, one for each side of a one-to-one call.
andrew@webrtc.org89df0922013-09-12 01:27:43 +0000165 ASSERT_TRUE((acm_a_.get() != NULL) && (acm_b_.get() != NULL));
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000166 EXPECT_EQ(0, acm_a_->InitializeReceiver());
167 EXPECT_EQ(0, acm_b_->InitializeReceiver());
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000168
tina.legrand@webrtc.org45175852012-06-01 09:27:35 +0000169 // Register all available codes as receiving codecs.
pbos@webrtc.org0946a562013-04-09 00:28:06 +0000170 uint8_t num_encoders = acm_a_->NumberOfCodecs();
tina.legrand@webrtc.org45175852012-06-01 09:27:35 +0000171 CodecInst my_codec_param;
pbos@webrtc.org0946a562013-04-09 00:28:06 +0000172 for (uint8_t n = 0; n < num_encoders; n++) {
tina.legrand@webrtc.org7a7a0082013-02-21 10:27:48 +0000173 EXPECT_EQ(0, acm_b_->Codec(n, &my_codec_param));
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000174 EXPECT_EQ(0, acm_b_->RegisterReceiveCodec(my_codec_param));
tina.legrand@webrtc.org45175852012-06-01 09:27:35 +0000175 }
176
177 // Test that unregister all receive codecs works.
pbos@webrtc.org0946a562013-04-09 00:28:06 +0000178 for (uint8_t n = 0; n < num_encoders; n++) {
tina.legrand@webrtc.org7a7a0082013-02-21 10:27:48 +0000179 EXPECT_EQ(0, acm_b_->Codec(n, &my_codec_param));
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000180 EXPECT_EQ(0, acm_b_->UnregisterReceiveCodec(my_codec_param.pltype));
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000181 }
tina.legrand@webrtc.orgae1c4542012-03-12 08:41:30 +0000182
tina.legrand@webrtc.org45175852012-06-01 09:27:35 +0000183 // Register all available codes as receiving codecs once more.
pbos@webrtc.org0946a562013-04-09 00:28:06 +0000184 for (uint8_t n = 0; n < num_encoders; n++) {
tina.legrand@webrtc.org7a7a0082013-02-21 10:27:48 +0000185 EXPECT_EQ(0, acm_b_->Codec(n, &my_codec_param));
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000186 EXPECT_EQ(0, acm_b_->RegisterReceiveCodec(my_codec_param));
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000187 }
tina.legrand@webrtc.orgae1c4542012-03-12 08:41:30 +0000188
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000189 // Create and connect the channel.
190 channel_a2b_ = new TestPackStereo;
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000191 EXPECT_EQ(0, acm_a_->RegisterTransportCallback(channel_a2b_));
andrew@webrtc.org89df0922013-09-12 01:27:43 +0000192 channel_a2b_->RegisterReceiverACM(acm_b_.get());
tina.legrand@webrtc.orgdf697752012-02-08 10:22:21 +0000193
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000194 // Start with setting VAD/DTX, before we know we will send stereo.
195 // Continue with setting a stereo codec as send codec and verify that
196 // VAD/DTX gets turned off.
197 EXPECT_EQ(0, acm_a_->SetVAD(true, true, VADNormal));
tina.legrand@webrtc.org7a7a0082013-02-21 10:27:48 +0000198 EXPECT_EQ(0, acm_a_->VAD(&dtx, &vad, &vad_mode));
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000199 EXPECT_TRUE(dtx);
200 EXPECT_TRUE(vad);
201 char codec_pcma_temp[] = "PCMA";
202 RegisterSendCodec('A', codec_pcma_temp, 8000, 64000, 80, 2, pcma_pltype_);
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_FALSE(dtx);
205 EXPECT_FALSE(vad);
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000206 if (test_mode_ != 0) {
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000207 printf("\n");
208 }
209
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000210 //
211 // Test Stereo-To-Stereo for all codecs.
212 //
213 audio_channels = 2;
214 codec_channels = 2;
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000215
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000216 // All codecs are tested for all allowed sampling frequencies, rates and
217 // packet sizes.
niklase@google.com470e71d2011-07-07 08:21:25 +0000218#ifdef WEBRTC_CODEC_G722
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000219 if (test_mode_ != 0) {
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000220 printf("===========================================================\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000221 printf("Test number: %d\n", test_cntr_ + 1);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000222 printf("Test type: Stereo-to-stereo\n");
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000223 }
224 channel_a2b_->set_codec_mode(kStereo);
225 test_cntr_++;
226 OpenOutFile(test_cntr_);
227 char codec_g722[] = "G722";
228 RegisterSendCodec('A', codec_g722, 16000, 64000, 160, codec_channels,
229 g722_pltype_);
230 Run(channel_a2b_, audio_channels, codec_channels);
231 RegisterSendCodec('A', codec_g722, 16000, 64000, 320, codec_channels,
232 g722_pltype_);
233 Run(channel_a2b_, audio_channels, codec_channels);
234 RegisterSendCodec('A', codec_g722, 16000, 64000, 480, codec_channels,
235 g722_pltype_);
236 Run(channel_a2b_, audio_channels, codec_channels);
237 RegisterSendCodec('A', codec_g722, 16000, 64000, 640, codec_channels,
238 g722_pltype_);
239 Run(channel_a2b_, audio_channels, codec_channels);
240 RegisterSendCodec('A', codec_g722, 16000, 64000, 800, codec_channels,
241 g722_pltype_);
242 Run(channel_a2b_, audio_channels, codec_channels);
243 RegisterSendCodec('A', codec_g722, 16000, 64000, 960, codec_channels,
244 g722_pltype_);
245 Run(channel_a2b_, audio_channels, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000246 out_file_.Close();
niklase@google.com470e71d2011-07-07 08:21:25 +0000247#endif
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000248 if (test_mode_ != 0) {
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000249 printf("===========================================================\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000250 printf("Test number: %d\n", test_cntr_ + 1);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000251 printf("Test type: Stereo-to-stereo\n");
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000252 }
253 channel_a2b_->set_codec_mode(kStereo);
254 test_cntr_++;
255 OpenOutFile(test_cntr_);
256 char codec_l16[] = "L16";
257 RegisterSendCodec('A', codec_l16, 8000, 128000, 80, codec_channels,
258 l16_8khz_pltype_);
259 Run(channel_a2b_, audio_channels, codec_channels);
260 RegisterSendCodec('A', codec_l16, 8000, 128000, 160, codec_channels,
261 l16_8khz_pltype_);
262 Run(channel_a2b_, audio_channels, codec_channels);
263 RegisterSendCodec('A', codec_l16, 8000, 128000, 240, codec_channels,
264 l16_8khz_pltype_);
265 Run(channel_a2b_, audio_channels, codec_channels);
266 RegisterSendCodec('A', codec_l16, 8000, 128000, 320, codec_channels,
267 l16_8khz_pltype_);
268 Run(channel_a2b_, audio_channels, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000269 out_file_.Close();
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000270
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000271 if (test_mode_ != 0) {
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000272 printf("===========================================================\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000273 printf("Test number: %d\n", test_cntr_ + 1);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000274 printf("Test type: Stereo-to-stereo\n");
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000275 }
276 test_cntr_++;
277 OpenOutFile(test_cntr_);
278 RegisterSendCodec('A', codec_l16, 16000, 256000, 160, codec_channels,
279 l16_16khz_pltype_);
280 Run(channel_a2b_, audio_channels, codec_channels);
281 RegisterSendCodec('A', codec_l16, 16000, 256000, 320, codec_channels,
282 l16_16khz_pltype_);
283 Run(channel_a2b_, audio_channels, codec_channels);
284 RegisterSendCodec('A', codec_l16, 16000, 256000, 480, codec_channels,
285 l16_16khz_pltype_);
286 Run(channel_a2b_, audio_channels, codec_channels);
287 RegisterSendCodec('A', codec_l16, 16000, 256000, 640, codec_channels,
288 l16_16khz_pltype_);
289 Run(channel_a2b_, audio_channels, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000290 out_file_.Close();
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000291
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000292 if (test_mode_ != 0) {
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000293 printf("===========================================================\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000294 printf("Test number: %d\n", test_cntr_ + 1);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000295 printf("Test type: Stereo-to-stereo\n");
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000296 }
297 test_cntr_++;
298 OpenOutFile(test_cntr_);
299 RegisterSendCodec('A', codec_l16, 32000, 512000, 320, codec_channels,
300 l16_32khz_pltype_);
301 Run(channel_a2b_, audio_channels, codec_channels);
302 RegisterSendCodec('A', codec_l16, 32000, 512000, 640, codec_channels,
303 l16_32khz_pltype_);
304 Run(channel_a2b_, audio_channels, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000305 out_file_.Close();
niklase@google.com470e71d2011-07-07 08:21:25 +0000306#ifdef PCMA_AND_PCMU
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000307 if (test_mode_ != 0) {
308 printf("===========================================================\n");
309 printf("Test number: %d\n", test_cntr_ + 1);
310 printf("Test type: Stereo-to-stereo\n");
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000311 }
312 channel_a2b_->set_codec_mode(kStereo);
313 audio_channels = 2;
314 codec_channels = 2;
315 test_cntr_++;
316 OpenOutFile(test_cntr_);
317 char codec_pcma[] = "PCMA";
318 RegisterSendCodec('A', codec_pcma, 8000, 64000, 80, codec_channels,
319 pcma_pltype_);
320 Run(channel_a2b_, audio_channels, codec_channels);
321 RegisterSendCodec('A', codec_pcma, 8000, 64000, 160, codec_channels,
322 pcma_pltype_);
323 Run(channel_a2b_, audio_channels, codec_channels);
324 RegisterSendCodec('A', codec_pcma, 8000, 64000, 240, codec_channels,
325 pcma_pltype_);
326 Run(channel_a2b_, audio_channels, codec_channels);
327 RegisterSendCodec('A', codec_pcma, 8000, 64000, 320, codec_channels,
328 pcma_pltype_);
329 Run(channel_a2b_, audio_channels, codec_channels);
330 RegisterSendCodec('A', codec_pcma, 8000, 64000, 400, codec_channels,
331 pcma_pltype_);
332 Run(channel_a2b_, audio_channels, codec_channels);
333 RegisterSendCodec('A', codec_pcma, 8000, 64000, 480, codec_channels,
334 pcma_pltype_);
335 Run(channel_a2b_, audio_channels, codec_channels);
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000336
337 // Test that VAD/DTX cannot be turned on while sending stereo.
338 EXPECT_EQ(-1, acm_a_->SetVAD(true, true, VADNormal));
tina.legrand@webrtc.org7a7a0082013-02-21 10:27:48 +0000339 EXPECT_EQ(0, acm_a_->VAD(&dtx, &vad, &vad_mode));
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000340 EXPECT_FALSE(dtx);
341 EXPECT_FALSE(vad);
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000342 EXPECT_EQ(0, acm_a_->SetVAD(false, false, VADNormal));
tina.legrand@webrtc.org7a7a0082013-02-21 10:27:48 +0000343 EXPECT_EQ(0, acm_a_->VAD(&dtx, &vad, &vad_mode));
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000344 EXPECT_FALSE(dtx);
345 EXPECT_FALSE(vad);
346
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000347 out_file_.Close();
348 if (test_mode_ != 0) {
349 printf("===========================================================\n");
350 printf("Test number: %d\n", test_cntr_ + 1);
351 printf("Test type: Stereo-to-stereo\n");
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000352 }
353 test_cntr_++;
354 OpenOutFile(test_cntr_);
355 char codec_pcmu[] = "PCMU";
356 RegisterSendCodec('A', codec_pcmu, 8000, 64000, 80, codec_channels,
357 pcmu_pltype_);
358 Run(channel_a2b_, audio_channels, codec_channels);
359 RegisterSendCodec('A', codec_pcmu, 8000, 64000, 160, codec_channels,
360 pcmu_pltype_);
361 Run(channel_a2b_, audio_channels, codec_channels);
362 RegisterSendCodec('A', codec_pcmu, 8000, 64000, 240, codec_channels,
363 pcmu_pltype_);
364 Run(channel_a2b_, audio_channels, codec_channels);
365 RegisterSendCodec('A', codec_pcmu, 8000, 64000, 320, codec_channels,
366 pcmu_pltype_);
367 Run(channel_a2b_, audio_channels, codec_channels);
368 RegisterSendCodec('A', codec_pcmu, 8000, 64000, 400, codec_channels,
369 pcmu_pltype_);
370 Run(channel_a2b_, audio_channels, codec_channels);
371 RegisterSendCodec('A', codec_pcmu, 8000, 64000, 480, codec_channels,
372 pcmu_pltype_);
373 Run(channel_a2b_, audio_channels, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000374 out_file_.Close();
niklase@google.com470e71d2011-07-07 08:21:25 +0000375#endif
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000376#ifdef WEBRTC_CODEC_OPUS
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000377 if (test_mode_ != 0) {
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000378 printf("===========================================================\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000379 printf("Test number: %d\n", test_cntr_ + 1);
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000380 printf("Test type: Stereo-to-stereo\n");
381 }
382 channel_a2b_->set_codec_mode(kStereo);
383 audio_channels = 2;
384 codec_channels = 2;
385 test_cntr_++;
386 OpenOutFile(test_cntr_);
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000387
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000388 char codec_opus[] = "opus";
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000389 // Run Opus with 10 ms frame size.
390 RegisterSendCodec('A', codec_opus, 48000, 64000, 480, codec_channels,
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000391 opus_pltype_);
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000392 Run(channel_a2b_, audio_channels, codec_channels);
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000393 // Run Opus with 20 ms frame size.
394 RegisterSendCodec('A', codec_opus, 48000, 64000, 480*2, codec_channels,
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000395 opus_pltype_);
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000396 Run(channel_a2b_, audio_channels, codec_channels);
397 // Run Opus with 40 ms frame size.
398 RegisterSendCodec('A', codec_opus, 48000, 64000, 480*4, codec_channels,
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000399 opus_pltype_);
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000400 Run(channel_a2b_, audio_channels, codec_channels);
401 // Run Opus with 60 ms frame size.
402 RegisterSendCodec('A', codec_opus, 48000, 64000, 480*6, codec_channels,
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000403 opus_pltype_);
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000404 Run(channel_a2b_, audio_channels, codec_channels);
405 // Run Opus with 20 ms frame size and different bitrates.
406 RegisterSendCodec('A', codec_opus, 48000, 40000, 960, codec_channels,
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000407 opus_pltype_);
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000408 Run(channel_a2b_, audio_channels, codec_channels);
409 RegisterSendCodec('A', codec_opus, 48000, 510000, 960, codec_channels,
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000410 opus_pltype_);
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000411 Run(channel_a2b_, audio_channels, codec_channels);
412 out_file_.Close();
413#endif
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000414 //
415 // Test Mono-To-Stereo for all codecs.
416 //
417 audio_channels = 1;
418 codec_channels = 2;
niklase@google.com470e71d2011-07-07 08:21:25 +0000419
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000420#ifdef WEBRTC_CODEC_G722
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000421 if (test_mode_ != 0) {
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000422 printf("===============================================================\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000423 printf("Test number: %d\n", test_cntr_ + 1);
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000424 printf("Test type: Mono-to-stereo\n");
425 }
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000426 test_cntr_++;
427 channel_a2b_->set_codec_mode(kStereo);
428 OpenOutFile(test_cntr_);
429 RegisterSendCodec('A', codec_g722, 16000, 64000, 160, codec_channels,
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000430 g722_pltype_);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000431 Run(channel_a2b_, audio_channels, codec_channels);
432 out_file_.Close();
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000433#endif
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000434 if (test_mode_ != 0) {
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000435 printf("===============================================================\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000436 printf("Test number: %d\n", test_cntr_ + 1);
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000437 printf("Test type: Mono-to-stereo\n");
438 }
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000439 test_cntr_++;
440 channel_a2b_->set_codec_mode(kStereo);
441 OpenOutFile(test_cntr_);
442 RegisterSendCodec('A', codec_l16, 8000, 128000, 80, codec_channels,
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000443 l16_8khz_pltype_);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000444 Run(channel_a2b_, audio_channels, codec_channels);
445 out_file_.Close();
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000446 if (test_mode_ != 0) {
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000447 printf("===============================================================\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000448 printf("Test number: %d\n", test_cntr_ + 1);
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000449 printf("Test type: Mono-to-stereo\n");
450 }
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000451 test_cntr_++;
452 OpenOutFile(test_cntr_);
453 RegisterSendCodec('A', codec_l16, 16000, 256000, 160, codec_channels,
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000454 l16_16khz_pltype_);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000455 Run(channel_a2b_, audio_channels, codec_channels);
456 out_file_.Close();
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000457 if (test_mode_ != 0) {
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000458 printf("===============================================================\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000459 printf("Test number: %d\n", test_cntr_ + 1);
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000460 printf("Test type: Mono-to-stereo\n");
461 }
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000462 test_cntr_++;
463 OpenOutFile(test_cntr_);
464 RegisterSendCodec('A', codec_l16, 32000, 512000, 320, codec_channels,
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000465 l16_32khz_pltype_);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000466 Run(channel_a2b_, audio_channels, codec_channels);
467 out_file_.Close();
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000468#ifdef PCMA_AND_PCMU
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000469 if (test_mode_ != 0) {
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000470 printf("===============================================================\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000471 printf("Test number: %d\n", test_cntr_ + 1);
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000472 printf("Test type: Mono-to-stereo\n");
473 }
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000474 test_cntr_++;
475 channel_a2b_->set_codec_mode(kStereo);
476 OpenOutFile(test_cntr_);
477 RegisterSendCodec('A', codec_pcmu, 8000, 64000, 80, codec_channels,
tina.legrand@webrtc.orgae1c4542012-03-12 08:41:30 +0000478 pcmu_pltype_);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000479 Run(channel_a2b_, audio_channels, codec_channels);
480 RegisterSendCodec('A', codec_pcma, 8000, 64000, 80, codec_channels,
tina.legrand@webrtc.orgae1c4542012-03-12 08:41:30 +0000481 pcma_pltype_);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000482 Run(channel_a2b_, audio_channels, codec_channels);
483 out_file_.Close();
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000484#endif
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000485#ifdef WEBRTC_CODEC_OPUS
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000486 if (test_mode_ != 0) {
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000487 printf("===============================================================\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000488 printf("Test number: %d\n", test_cntr_ + 1);
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000489 printf("Test type: Mono-to-stereo\n");
490 }
tina.legrand@webrtc.orgc4590582012-11-28 12:23:29 +0000491
492 // Keep encode and decode in stereo.
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000493 test_cntr_++;
494 channel_a2b_->set_codec_mode(kStereo);
495 OpenOutFile(test_cntr_);
496 RegisterSendCodec('A', codec_opus, 48000, 64000, 960, codec_channels,
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000497 opus_pltype_);
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000498 Run(channel_a2b_, audio_channels, codec_channels);
tina.legrand@webrtc.orgc4590582012-11-28 12:23:29 +0000499
500 // Encode in mono, decode in stereo mode.
501 RegisterSendCodec('A', codec_opus, 48000, 64000, 960, 1, opus_pltype_);
502 Run(channel_a2b_, audio_channels, codec_channels);
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000503 out_file_.Close();
504#endif
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000505
506 //
507 // Test Stereo-To-Mono for all codecs.
508 //
509 audio_channels = 2;
510 codec_channels = 1;
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000511 channel_a2b_->set_codec_mode(kMono);
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000512
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000513#ifdef WEBRTC_CODEC_G722
514 // Run stereo audio and mono codec.
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000515 if (test_mode_ != 0) {
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000516 printf("===============================================================\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000517 printf("Test number: %d\n", test_cntr_ + 1);
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000518 printf("Test type: Stereo-to-mono\n");
519 }
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000520 test_cntr_++;
521 OpenOutFile(test_cntr_);
522 RegisterSendCodec('A', codec_g722, 16000, 64000, 160, codec_channels,
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000523 g722_pltype_);
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000524
525 // Make sure it is possible to set VAD/CNG, now that we are sending mono
526 // again.
527 EXPECT_EQ(0, acm_a_->SetVAD(true, true, VADNormal));
tina.legrand@webrtc.org7a7a0082013-02-21 10:27:48 +0000528 EXPECT_EQ(0, acm_a_->VAD(&dtx, &vad, &vad_mode));
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000529 EXPECT_TRUE(dtx);
530 EXPECT_TRUE(vad);
531 EXPECT_EQ(0, acm_a_->SetVAD(false, false, VADNormal));
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000532 Run(channel_a2b_, audio_channels, codec_channels);
533 out_file_.Close();
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000534#endif
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000535 if (test_mode_ != 0) {
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000536 printf("===============================================================\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000537 printf("Test number: %d\n", test_cntr_ + 1);
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000538 printf("Test type: Stereo-to-mono\n");
539 }
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000540 test_cntr_++;
541 OpenOutFile(test_cntr_);
542 RegisterSendCodec('A', codec_l16, 8000, 128000, 80, codec_channels,
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000543 l16_8khz_pltype_);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000544 Run(channel_a2b_, audio_channels, codec_channels);
545 out_file_.Close();
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000546 if (test_mode_ != 0) {
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000547 printf("===============================================================\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000548 printf("Test number: %d\n", test_cntr_ + 1);
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000549 printf("Test type: Stereo-to-mono\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000550 }
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000551 test_cntr_++;
552 OpenOutFile(test_cntr_);
553 RegisterSendCodec('A', codec_l16, 16000, 256000, 160, codec_channels,
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000554 l16_16khz_pltype_);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000555 Run(channel_a2b_, audio_channels, codec_channels);
556 out_file_.Close();
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000557 if (test_mode_ != 0) {
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000558 printf("==============================================================\n");
559 printf("Test number: %d\n", test_cntr_ + 1);
560 printf("Test type: Stereo-to-mono\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000561 }
562 test_cntr_++;
563 OpenOutFile(test_cntr_);
564 RegisterSendCodec('A', codec_l16, 32000, 512000, 320, codec_channels,
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000565 l16_32khz_pltype_);
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000566 Run(channel_a2b_, audio_channels, codec_channels);
567 out_file_.Close();
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000568#ifdef PCMA_AND_PCMU
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.orgdf697752012-02-08 10:22:21 +0000572 printf("Test type: Stereo-to-mono\n");
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000573 }
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000574 test_cntr_++;
575 OpenOutFile(test_cntr_);
576 RegisterSendCodec('A', codec_pcmu, 8000, 64000, 80, codec_channels,
tina.legrand@webrtc.orgae1c4542012-03-12 08:41:30 +0000577 pcmu_pltype_);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000578 Run(channel_a2b_, audio_channels, codec_channels);
579 RegisterSendCodec('A', codec_pcma, 8000, 64000, 80, codec_channels,
tina.legrand@webrtc.orgae1c4542012-03-12 08:41:30 +0000580 pcma_pltype_);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000581 Run(channel_a2b_, audio_channels, codec_channels);
582 out_file_.Close();
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000583#endif
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000584#ifdef WEBRTC_CODEC_OPUS
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000585 if (test_mode_ != 0) {
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000586 printf("===============================================================\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000587 printf("Test number: %d\n", test_cntr_ + 1);
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000588 printf("Test type: Stereo-to-mono\n");
589 }
590 test_cntr_++;
591 OpenOutFile(test_cntr_);
tina.legrand@webrtc.orgc4590582012-11-28 12:23:29 +0000592 // Encode and decode in mono.
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000593 RegisterSendCodec('A', codec_opus, 48000, 32000, 960, codec_channels,
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000594 opus_pltype_);
tina.legrand@webrtc.orgc4590582012-11-28 12:23:29 +0000595 CodecInst opus_codec_param;
pbos@webrtc.org0946a562013-04-09 00:28:06 +0000596 for (uint8_t n = 0; n < num_encoders; n++) {
tina.legrand@webrtc.org7a7a0082013-02-21 10:27:48 +0000597 EXPECT_EQ(0, acm_b_->Codec(n, &opus_codec_param));
tina.legrand@webrtc.orgc4590582012-11-28 12:23:29 +0000598 if (!strcmp(opus_codec_param.plname, "opus")) {
599 opus_codec_param.channels = 1;
600 EXPECT_EQ(0, acm_b_->RegisterReceiveCodec(opus_codec_param));
601 break;
602 }
603 }
604 Run(channel_a2b_, audio_channels, codec_channels);
605
606 // Encode in stereo, decode in mono.
607 RegisterSendCodec('A', codec_opus, 48000, 32000, 960, 2, opus_pltype_);
608 Run(channel_a2b_, audio_channels, codec_channels);
609
610 out_file_.Close();
611
612 // Test switching between decoding mono and stereo for Opus.
613
614 // Decode in mono.
615 test_cntr_++;
616 OpenOutFile(test_cntr_);
617 if (test_mode_ != 0) {
618 // Print out codec and settings
619 printf("Test number: %d\nCodec: Opus Freq: 48000 Rate :32000 PackSize: 960"
620 " Decode: mono\n", test_cntr_);
621 }
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000622 Run(channel_a2b_, audio_channels, codec_channels);
623 out_file_.Close();
tina.legrand@webrtc.orgc4590582012-11-28 12:23:29 +0000624 // Decode in stereo.
625 test_cntr_++;
626 OpenOutFile(test_cntr_);
627 if (test_mode_ != 0) {
628 // Print out codec and settings
629 printf("Test number: %d\nCodec: Opus Freq: 48000 Rate :32000 PackSize: 960"
630 " Decode: stereo\n", test_cntr_);
631 }
632 opus_codec_param.channels = 2;
633 EXPECT_EQ(0, acm_b_->RegisterReceiveCodec(opus_codec_param));
634 Run(channel_a2b_, audio_channels, 2);
635 out_file_.Close();
636 // Decode in mono.
637 test_cntr_++;
638 OpenOutFile(test_cntr_);
639 if (test_mode_ != 0) {
640 // Print out codec and settings
641 printf("Test number: %d\nCodec: Opus Freq: 48000 Rate :32000 PackSize: 960"
642 " Decode: mono\n", test_cntr_);
643 }
644 opus_codec_param.channels = 1;
645 EXPECT_EQ(0, acm_b_->RegisterReceiveCodec(opus_codec_param));
646 Run(channel_a2b_, audio_channels, codec_channels);
647 out_file_.Close();
648
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000649#endif
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000650
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000651 // Print out which codecs were tested, and which were not, in the run.
652 if (test_mode_ != 0) {
653 printf("\nThe following codecs was INCLUDED in the test:\n");
niklase@google.com470e71d2011-07-07 08:21:25 +0000654#ifdef WEBRTC_CODEC_G722
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000655 printf(" G.722\n");
niklase@google.com470e71d2011-07-07 08:21:25 +0000656#endif
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000657 printf(" PCM16\n");
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000658 printf(" G.711\n");
tina.legrand@webrtc.orgc4590582012-11-28 12:23:29 +0000659#ifdef WEBRTC_CODEC_OPUS
660 printf(" Opus\n");
661#endif
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000662 printf("\nTo complete the test, listen to the %d number of output "
663 "files.\n",
664 test_cntr_);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000665 }
666
667 // Delete the file pointers.
668 delete in_file_stereo_;
669 delete in_file_mono_;
niklase@google.com470e71d2011-07-07 08:21:25 +0000670}
671
672// Register Codec to use in the test
673//
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000674// Input: side - which ACM to use, 'A' or 'B'
675// codec_name - name to use when register the codec
676// sampling_freq_hz - sampling frequency in Herz
677// rate - bitrate in bytes
678// pack_size - packet size in samples
679// channels - number of channels; 1 for mono, 2 for stereo
680// payload_type - payload type for the codec
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000681void TestStereo::RegisterSendCodec(char side, char* codec_name,
pbos@webrtc.org0946a562013-04-09 00:28:06 +0000682 int32_t sampling_freq_hz, int rate,
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000683 int pack_size, int channels,
684 int payload_type) {
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000685 if (test_mode_ != 0) {
686 // Print out codec and settings
tina.legrand@webrtc.orgba468042012-08-17 10:38:28 +0000687 printf("Codec: %s Freq: %d Rate: %d PackSize: %d\n", codec_name,
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000688 sampling_freq_hz, rate, pack_size);
689 }
690
691 // Store packet size in samples, used to validate the received packet
692 pack_size_samp_ = pack_size;
693
694 // Store the expected packet size in bytes, used to validate the received
695 // packet. Add 0.875 to always round up to a whole byte.
pbos@webrtc.orgd8ca7232014-12-10 11:49:13 +0000696 pack_size_bytes_ = (uint16_t)(static_cast<float>(pack_size * rate) /
697 static_cast<float>(sampling_freq_hz * 8) +
698 0.875);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000699
700 // Set pointer to the ACM where to register the codec
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000701 AudioCodingModule* my_acm = NULL;
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000702 switch (side) {
703 case 'A': {
andrew@webrtc.org89df0922013-09-12 01:27:43 +0000704 my_acm = acm_a_.get();
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000705 break;
niklase@google.com470e71d2011-07-07 08:21:25 +0000706 }
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000707 case 'B': {
andrew@webrtc.org89df0922013-09-12 01:27:43 +0000708 my_acm = acm_b_.get();
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000709 break;
tina.legrand@webrtc.org16b6b902012-04-12 11:02:38 +0000710 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000711 default:
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000712 break;
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000713 }
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000714 ASSERT_TRUE(my_acm != NULL);
niklase@google.com470e71d2011-07-07 08:21:25 +0000715
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000716 CodecInst my_codec_param;
717 // Get all codec parameters before registering
tina.legrand@webrtc.orgee92b662013-08-27 07:33:51 +0000718 EXPECT_GT(AudioCodingModule::Codec(codec_name, &my_codec_param,
719 sampling_freq_hz, channels), -1);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000720 my_codec_param.rate = rate;
721 my_codec_param.pacsize = pack_size;
tina.legrand@webrtc.orgee92b662013-08-27 07:33:51 +0000722 EXPECT_EQ(0, my_acm->RegisterSendCodec(my_codec_param));
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000723
724 send_codec_name_ = codec_name;
niklase@google.com470e71d2011-07-07 08:21:25 +0000725}
726
tina.legrand@webrtc.org16b6b902012-04-12 11:02:38 +0000727void TestStereo::Run(TestPackStereo* channel, int in_channels, int out_channels,
728 int percent_loss) {
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000729 AudioFrame audio_frame;
niklase@google.com470e71d2011-07-07 08:21:25 +0000730
pbos@webrtc.org0946a562013-04-09 00:28:06 +0000731 int32_t out_freq_hz_b = out_file_.SamplingFrequency();
732 uint16_t rec_size;
733 uint32_t time_stamp_diff;
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000734 channel->reset_payload_size();
735 int error_count = 0;
tina.legrand@webrtc.org65d61c32014-06-05 13:42:51 +0000736 int variable_bytes = 0;
737 int variable_packets = 0;
Henrik Lundin4d682082015-12-10 16:24:39 +0100738 // Set test length to 500 ms (50 blocks of 10 ms each).
739 in_file_mono_->SetNum10MsBlocksToRead(50);
740 in_file_stereo_->SetNum10MsBlocksToRead(50);
741 // Fast-forward 1 second (100 blocks) since the files start with silence.
742 in_file_stereo_->FastForward(100);
743 in_file_mono_->FastForward(100);
niklase@google.com470e71d2011-07-07 08:21:25 +0000744
andresp@webrtc.orgd0b436a2014-01-13 13:15:59 +0000745 while (1) {
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000746 // Simulate packet loss by setting |packet_loss_| to "true" in
747 // |percent_loss| percent of the loops.
748 if (percent_loss > 0) {
749 if (counter_ == floor((100 / percent_loss) + 0.5)) {
750 counter_ = 0;
751 channel->set_lost_packet(true);
752 } else {
753 channel->set_lost_packet(false);
754 }
755 counter_++;
niklase@google.com470e71d2011-07-07 08:21:25 +0000756 }
757
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000758 // Add 10 msec to ACM
759 if (in_channels == 1) {
760 if (in_file_mono_->EndOfFile()) {
761 break;
762 }
763 in_file_mono_->Read10MsData(audio_frame);
764 } else {
765 if (in_file_stereo_->EndOfFile()) {
766 break;
767 }
768 in_file_stereo_->Read10MsData(audio_frame);
769 }
henrik.lundin@webrtc.orgf56c1622015-03-02 12:29:30 +0000770 EXPECT_GE(acm_a_->Add10MsData(audio_frame), 0);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000771
tina.legrand@webrtc.org65d61c32014-06-05 13:42:51 +0000772 // Verify that the received packet size matches the settings.
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000773 rec_size = channel->payload_size();
774 if ((0 < rec_size) & (rec_size < 65535)) {
tina.legrand@webrtc.org65d61c32014-06-05 13:42:51 +0000775 if (strcmp(send_codec_name_, "opus") == 0) {
776 // Opus is a variable rate codec, hence calculate the average packet
777 // size, and later make sure the average is in the right range.
778 variable_bytes += rec_size;
779 variable_packets++;
780 } else {
781 // For fixed rate codecs, check that packet size is correct.
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000782 if ((rec_size != pack_size_bytes_ * out_channels)
783 && (pack_size_bytes_ < 65535)) {
784 error_count++;
785 }
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000786 }
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000787 // Verify that the timestamp is updated with expected length
788 time_stamp_diff = channel->timestamp_diff();
789 if ((counter_ > 10) && (time_stamp_diff != pack_size_samp_)) {
790 error_count++;
791 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000792 }
793
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000794 // Run received side of ACM
henrik.lundind4ccb002016-05-17 12:21:55 -0700795 bool muted;
796 EXPECT_EQ(0, acm_b_->PlayoutData10Ms(out_freq_hz_b, &audio_frame, &muted));
797 ASSERT_FALSE(muted);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000798
799 // Write output speech to file
800 out_file_.Write10MsData(
andrew@webrtc.org63a50982012-05-02 23:56:37 +0000801 audio_frame.data_,
802 audio_frame.samples_per_channel_ * audio_frame.num_channels_);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000803 }
804
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000805 EXPECT_EQ(0, error_count);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000806
tina.legrand@webrtc.org65d61c32014-06-05 13:42:51 +0000807 // Check that packet size is in the right range for variable rate codecs,
808 // such as Opus.
809 if (variable_packets > 0) {
810 variable_bytes /= variable_packets;
Henrik Lundin4d682082015-12-10 16:24:39 +0100811 EXPECT_NEAR(variable_bytes, pack_size_bytes_, 18);
tina.legrand@webrtc.org65d61c32014-06-05 13:42:51 +0000812 }
813
andresp@webrtc.orgd0b436a2014-01-13 13:15:59 +0000814 if (in_file_mono_->EndOfFile()) {
815 in_file_mono_->Rewind();
816 }
817 if (in_file_stereo_->EndOfFile()) {
818 in_file_stereo_->Rewind();
819 }
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000820 // Reset in case we ended with a lost packet
821 channel->set_lost_packet(false);
niklase@google.com470e71d2011-07-07 08:21:25 +0000822}
823
pbos@webrtc.org0946a562013-04-09 00:28:06 +0000824void TestStereo::OpenOutFile(int16_t test_number) {
tina.legrand@webrtc.orgba468042012-08-17 10:38:28 +0000825 std::string file_name;
826 std::stringstream file_stream;
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000827 file_stream << webrtc::test::OutputPath() << "teststereo_out_" << test_number
828 << ".pcm";
tina.legrand@webrtc.orgba468042012-08-17 10:38:28 +0000829 file_name = file_stream.str();
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000830 out_file_.Open(file_name, 32000, "wb");
niklase@google.com470e71d2011-07-07 08:21:25 +0000831}
832
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000833void TestStereo::DisplaySendReceiveCodec() {
kwiberg1fd4a4a2015-11-03 11:20:50 -0800834 auto send_codec = acm_a_->SendCodec();
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000835 if (test_mode_ != 0) {
kwiberg1fd4a4a2015-11-03 11:20:50 -0800836 ASSERT_TRUE(send_codec);
837 printf("%s -> ", send_codec->plname);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000838 }
kwiberg1fd4a4a2015-11-03 11:20:50 -0800839 CodecInst receive_codec;
840 acm_b_->ReceiveCodec(&receive_codec);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000841 if (test_mode_ != 0) {
kwiberg1fd4a4a2015-11-03 11:20:50 -0800842 printf("%s\n", receive_codec.plname);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000843 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000844}
845
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000846} // namespace webrtc