blob: 797178b7b880b546c587c81163f1e503bc29e0e9 [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
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020011#include "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
Karl Wiberg5817d3d2018-04-06 10:06:42 +020017#include "api/audio_codecs/builtin_audio_decoder_factory.h"
Mirko Bonadei71207422017-09-15 13:58:09 +020018#include "common_types.h" // NOLINT(build/include)
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020019#include "modules/audio_coding/codecs/audio_format_conversion.h"
20#include "modules/audio_coding/include/audio_coding_module_typedefs.h"
21#include "modules/audio_coding/test/utility.h"
Jonas Olsson366a50c2018-09-06 13:41:30 +020022#include "rtc_base/strings/string_builder.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020023#include "test/gtest.h"
24#include "test/testsupport/fileutils.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000025
tina.legrand@webrtc.org554ae1a2011-12-16 10:09:04 +000026namespace webrtc {
niklase@google.com470e71d2011-07-07 08:21:25 +000027
28// Class for simulating packet handling
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +000029TestPackStereo::TestPackStereo()
30 : receiver_acm_(NULL),
31 seq_no_(0),
32 timestamp_diff_(0),
33 last_in_timestamp_(0),
34 total_bytes_(0),
35 payload_size_(0),
36 codec_mode_(kNotSet),
Yves Gerey665174f2018-06-19 15:03:05 +020037 lost_packet_(false) {}
niklase@google.com470e71d2011-07-07 08:21:25 +000038
Yves Gerey665174f2018-06-19 15:03:05 +020039TestPackStereo::~TestPackStereo() {}
niklase@google.com470e71d2011-07-07 08:21:25 +000040
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +000041void TestPackStereo::RegisterReceiverACM(AudioCodingModule* acm) {
42 receiver_acm_ = acm;
43 return;
44}
niklase@google.com470e71d2011-07-07 08:21:25 +000045
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000046int32_t TestPackStereo::SendData(const FrameType frame_type,
47 const uint8_t payload_type,
48 const uint32_t timestamp,
49 const uint8_t* payload_data,
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +000050 const size_t payload_size,
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000051 const RTPFragmentationHeader* fragmentation) {
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +000052 WebRtcRTPHeader rtp_info;
pbos@webrtc.org0946a562013-04-09 00:28:06 +000053 int32_t status = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +000054
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +000055 rtp_info.header.markerBit = false;
56 rtp_info.header.ssrc = 0;
57 rtp_info.header.sequenceNumber = seq_no_++;
58 rtp_info.header.payloadType = payload_type;
59 rtp_info.header.timestamp = timestamp;
pbos22993e12015-10-19 02:39:06 -070060 if (frame_type == kEmptyFrame) {
tina.legrand@webrtc.org16b6b902012-04-12 11:02:38 +000061 // Skip this frame
62 return 0;
63 }
niklase@google.com470e71d2011-07-07 08:21:25 +000064
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +000065 if (lost_packet_ == false) {
Yves Gerey665174f2018-06-19 15:03:05 +020066 status =
67 receiver_acm_->IncomingPacket(payload_data, payload_size, rtp_info);
niklase@google.com470e71d2011-07-07 08:21:25 +000068
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +000069 if (frame_type != kAudioFrameCN) {
henrike@webrtc.org6ac22e62014-08-11 21:06:30 +000070 payload_size_ = static_cast<int>(payload_size);
niklase@google.com470e71d2011-07-07 08:21:25 +000071 } else {
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +000072 payload_size_ = -1;
niklase@google.com470e71d2011-07-07 08:21:25 +000073 }
tina.legrand@webrtc.org16b6b902012-04-12 11:02:38 +000074
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +000075 timestamp_diff_ = timestamp - last_in_timestamp_;
76 last_in_timestamp_ = timestamp;
77 total_bytes_ += payload_size;
tina.legrand@webrtc.org16b6b902012-04-12 11:02:38 +000078 }
79 return status;
niklase@google.com470e71d2011-07-07 08:21:25 +000080}
81
pbos@webrtc.org0946a562013-04-09 00:28:06 +000082uint16_t TestPackStereo::payload_size() {
henrike@webrtc.org6ac22e62014-08-11 21:06:30 +000083 return static_cast<uint16_t>(payload_size_);
niklase@google.com470e71d2011-07-07 08:21:25 +000084}
85
pbos@webrtc.org0946a562013-04-09 00:28:06 +000086uint32_t TestPackStereo::timestamp_diff() {
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +000087 return timestamp_diff_;
niklase@google.com470e71d2011-07-07 08:21:25 +000088}
89
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +000090void TestPackStereo::reset_payload_size() {
91 payload_size_ = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +000092}
93
tina.legrand@webrtc.org16b6b902012-04-12 11:02:38 +000094void TestPackStereo::set_codec_mode(enum StereoMonoMode mode) {
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +000095 codec_mode_ = mode;
tina.legrand@webrtc.org16b6b902012-04-12 11:02:38 +000096}
97
98void TestPackStereo::set_lost_packet(bool lost) {
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +000099 lost_packet_ = lost;
niklase@google.com470e71d2011-07-07 08:21:25 +0000100}
101
henrik.lundin@webrtc.orgadaf8092014-04-17 08:29:10 +0000102TestStereo::TestStereo(int test_mode)
Karl Wiberg5817d3d2018-04-06 10:06:42 +0200103 : acm_a_(AudioCodingModule::Create(
104 AudioCodingModule::Config(CreateBuiltinAudioDecoderFactory()))),
105 acm_b_(AudioCodingModule::Create(
106 AudioCodingModule::Config(CreateBuiltinAudioDecoderFactory()))),
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000107 channel_a2b_(NULL),
108 test_cntr_(0),
109 pack_size_samp_(0),
110 pack_size_bytes_(0),
Karl Wibergeb254b42017-11-01 15:08:12 +0100111 counter_(0),
112 g722_pltype_(0),
113 l16_8khz_pltype_(-1),
114 l16_16khz_pltype_(-1),
115 l16_32khz_pltype_(-1)
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +0000116#ifdef PCMA_AND_PCMU
Karl Wiberg5817d3d2018-04-06 10:06:42 +0200117 ,
118 pcma_pltype_(-1),
119 pcmu_pltype_(-1)
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +0000120#endif
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +0000121#ifdef WEBRTC_CODEC_OPUS
Karl Wiberg5817d3d2018-04-06 10:06:42 +0200122 ,
123 opus_pltype_(-1)
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +0000124#endif
Karl Wibergeb254b42017-11-01 15:08:12 +0100125{
tina.legrand@webrtc.org45175852012-06-01 09:27:35 +0000126 // test_mode = 0 for silent test (auto test)
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000127 test_mode_ = test_mode;
niklase@google.com470e71d2011-07-07 08:21:25 +0000128}
129
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000130TestStereo::~TestStereo() {
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000131 if (channel_a2b_ != NULL) {
132 delete channel_a2b_;
133 channel_a2b_ = NULL;
134 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000135}
136
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000137void TestStereo::Perform() {
pbos@webrtc.org0946a562013-04-09 00:28:06 +0000138 uint16_t frequency_hz;
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000139 int audio_channels;
140 int codec_channels;
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000141 bool dtx;
142 bool vad;
143 ACMVADMode vad_mode;
niklase@google.com470e71d2011-07-07 08:21:25 +0000144
tina.legrand@webrtc.org45175852012-06-01 09:27:35 +0000145 // Open both mono and stereo test files in 32 kHz.
Yves Gerey665174f2018-06-19 15:03:05 +0200146 const std::string file_name_stereo =
147 webrtc::test::ResourcePath("audio_coding/teststereo32kHz", "pcm");
148 const std::string file_name_mono =
149 webrtc::test::ResourcePath("audio_coding/testfile32kHz", "pcm");
tina.legrand@webrtc.org45175852012-06-01 09:27:35 +0000150 frequency_hz = 32000;
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000151 in_file_stereo_ = new PCMFile();
152 in_file_mono_ = new PCMFile();
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000153 in_file_stereo_->Open(file_name_stereo, frequency_hz, "rb");
154 in_file_stereo_->ReadStereo(true);
155 in_file_mono_->Open(file_name_mono, frequency_hz, "rb");
156 in_file_mono_->ReadStereo(false);
157
tina.legrand@webrtc.org45175852012-06-01 09:27:35 +0000158 // Create and initialize two ACMs, one for each side of a one-to-one call.
andrew@webrtc.org89df0922013-09-12 01:27:43 +0000159 ASSERT_TRUE((acm_a_.get() != NULL) && (acm_b_.get() != NULL));
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000160 EXPECT_EQ(0, acm_a_->InitializeReceiver());
161 EXPECT_EQ(0, acm_b_->InitializeReceiver());
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000162
tina.legrand@webrtc.org45175852012-06-01 09:27:35 +0000163 // Register all available codes as receiving codecs.
pbos@webrtc.org0946a562013-04-09 00:28:06 +0000164 uint8_t num_encoders = acm_a_->NumberOfCodecs();
tina.legrand@webrtc.org45175852012-06-01 09:27:35 +0000165 CodecInst my_codec_param;
pbos@webrtc.org0946a562013-04-09 00:28:06 +0000166 for (uint8_t n = 0; n < num_encoders; n++) {
tina.legrand@webrtc.org7a7a0082013-02-21 10:27:48 +0000167 EXPECT_EQ(0, acm_b_->Codec(n, &my_codec_param));
kwibergda2bf4e2016-10-24 13:47:09 -0700168 EXPECT_EQ(true, acm_b_->RegisterReceiveCodec(
169 my_codec_param.pltype, CodecInstToSdp(my_codec_param)));
tina.legrand@webrtc.org45175852012-06-01 09:27:35 +0000170 }
171
172 // Test that unregister all receive codecs works.
pbos@webrtc.org0946a562013-04-09 00:28:06 +0000173 for (uint8_t n = 0; n < num_encoders; n++) {
tina.legrand@webrtc.org7a7a0082013-02-21 10:27:48 +0000174 EXPECT_EQ(0, acm_b_->Codec(n, &my_codec_param));
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000175 EXPECT_EQ(0, acm_b_->UnregisterReceiveCodec(my_codec_param.pltype));
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000176 }
tina.legrand@webrtc.orgae1c4542012-03-12 08:41:30 +0000177
tina.legrand@webrtc.org45175852012-06-01 09:27:35 +0000178 // Register all available codes as receiving codecs once more.
pbos@webrtc.org0946a562013-04-09 00:28:06 +0000179 for (uint8_t n = 0; n < num_encoders; n++) {
tina.legrand@webrtc.org7a7a0082013-02-21 10:27:48 +0000180 EXPECT_EQ(0, acm_b_->Codec(n, &my_codec_param));
kwibergda2bf4e2016-10-24 13:47:09 -0700181 EXPECT_EQ(true, acm_b_->RegisterReceiveCodec(
182 my_codec_param.pltype, CodecInstToSdp(my_codec_param)));
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000183 }
tina.legrand@webrtc.orgae1c4542012-03-12 08:41:30 +0000184
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000185 // Create and connect the channel.
186 channel_a2b_ = new TestPackStereo;
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000187 EXPECT_EQ(0, acm_a_->RegisterTransportCallback(channel_a2b_));
andrew@webrtc.org89df0922013-09-12 01:27:43 +0000188 channel_a2b_->RegisterReceiverACM(acm_b_.get());
tina.legrand@webrtc.orgdf697752012-02-08 10:22:21 +0000189
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000190 // Start with setting VAD/DTX, before we know we will send stereo.
191 // Continue with setting a stereo codec as send codec and verify that
192 // VAD/DTX gets turned off.
193 EXPECT_EQ(0, acm_a_->SetVAD(true, true, VADNormal));
tina.legrand@webrtc.org7a7a0082013-02-21 10:27:48 +0000194 EXPECT_EQ(0, acm_a_->VAD(&dtx, &vad, &vad_mode));
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000195 EXPECT_TRUE(dtx);
196 EXPECT_TRUE(vad);
197 char codec_pcma_temp[] = "PCMA";
198 RegisterSendCodec('A', codec_pcma_temp, 8000, 64000, 80, 2, pcma_pltype_);
tina.legrand@webrtc.org7a7a0082013-02-21 10:27:48 +0000199 EXPECT_EQ(0, acm_a_->VAD(&dtx, &vad, &vad_mode));
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000200 EXPECT_FALSE(dtx);
201 EXPECT_FALSE(vad);
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000202 if (test_mode_ != 0) {
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000203 printf("\n");
204 }
205
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000206 //
207 // Test Stereo-To-Stereo for all codecs.
208 //
209 audio_channels = 2;
210 codec_channels = 2;
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000211
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000212 // All codecs are tested for all allowed sampling frequencies, rates and
213 // packet sizes.
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000214 if (test_mode_ != 0) {
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000215 printf("===========================================================\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000216 printf("Test number: %d\n", test_cntr_ + 1);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000217 printf("Test type: Stereo-to-stereo\n");
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000218 }
219 channel_a2b_->set_codec_mode(kStereo);
220 test_cntr_++;
221 OpenOutFile(test_cntr_);
222 char codec_g722[] = "G722";
223 RegisterSendCodec('A', codec_g722, 16000, 64000, 160, codec_channels,
Yves Gerey665174f2018-06-19 15:03:05 +0200224 g722_pltype_);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000225 Run(channel_a2b_, audio_channels, codec_channels);
226 RegisterSendCodec('A', codec_g722, 16000, 64000, 320, codec_channels,
Yves Gerey665174f2018-06-19 15:03:05 +0200227 g722_pltype_);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000228 Run(channel_a2b_, audio_channels, codec_channels);
229 RegisterSendCodec('A', codec_g722, 16000, 64000, 480, codec_channels,
Yves Gerey665174f2018-06-19 15:03:05 +0200230 g722_pltype_);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000231 Run(channel_a2b_, audio_channels, codec_channels);
232 RegisterSendCodec('A', codec_g722, 16000, 64000, 640, codec_channels,
Yves Gerey665174f2018-06-19 15:03:05 +0200233 g722_pltype_);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000234 Run(channel_a2b_, audio_channels, codec_channels);
235 RegisterSendCodec('A', codec_g722, 16000, 64000, 800, codec_channels,
Yves Gerey665174f2018-06-19 15:03:05 +0200236 g722_pltype_);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000237 Run(channel_a2b_, audio_channels, codec_channels);
238 RegisterSendCodec('A', codec_g722, 16000, 64000, 960, codec_channels,
Yves Gerey665174f2018-06-19 15:03:05 +0200239 g722_pltype_);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000240 Run(channel_a2b_, audio_channels, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000241 out_file_.Close();
Karl Wibergeb254b42017-11-01 15:08:12 +0100242
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000243 if (test_mode_ != 0) {
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000244 printf("===========================================================\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000245 printf("Test number: %d\n", test_cntr_ + 1);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000246 printf("Test type: Stereo-to-stereo\n");
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000247 }
248 channel_a2b_->set_codec_mode(kStereo);
249 test_cntr_++;
250 OpenOutFile(test_cntr_);
251 char codec_l16[] = "L16";
252 RegisterSendCodec('A', codec_l16, 8000, 128000, 80, codec_channels,
Yves Gerey665174f2018-06-19 15:03:05 +0200253 l16_8khz_pltype_);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000254 Run(channel_a2b_, audio_channels, codec_channels);
255 RegisterSendCodec('A', codec_l16, 8000, 128000, 160, codec_channels,
Yves Gerey665174f2018-06-19 15:03:05 +0200256 l16_8khz_pltype_);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000257 Run(channel_a2b_, audio_channels, codec_channels);
258 RegisterSendCodec('A', codec_l16, 8000, 128000, 240, codec_channels,
Yves Gerey665174f2018-06-19 15:03:05 +0200259 l16_8khz_pltype_);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000260 Run(channel_a2b_, audio_channels, codec_channels);
261 RegisterSendCodec('A', codec_l16, 8000, 128000, 320, codec_channels,
Yves Gerey665174f2018-06-19 15:03:05 +0200262 l16_8khz_pltype_);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000263 Run(channel_a2b_, audio_channels, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000264 out_file_.Close();
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000265
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000266 if (test_mode_ != 0) {
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000267 printf("===========================================================\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000268 printf("Test number: %d\n", test_cntr_ + 1);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000269 printf("Test type: Stereo-to-stereo\n");
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000270 }
271 test_cntr_++;
272 OpenOutFile(test_cntr_);
273 RegisterSendCodec('A', codec_l16, 16000, 256000, 160, codec_channels,
Yves Gerey665174f2018-06-19 15:03:05 +0200274 l16_16khz_pltype_);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000275 Run(channel_a2b_, audio_channels, codec_channels);
276 RegisterSendCodec('A', codec_l16, 16000, 256000, 320, codec_channels,
Yves Gerey665174f2018-06-19 15:03:05 +0200277 l16_16khz_pltype_);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000278 Run(channel_a2b_, audio_channels, codec_channels);
279 RegisterSendCodec('A', codec_l16, 16000, 256000, 480, codec_channels,
Yves Gerey665174f2018-06-19 15:03:05 +0200280 l16_16khz_pltype_);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000281 Run(channel_a2b_, audio_channels, codec_channels);
282 RegisterSendCodec('A', codec_l16, 16000, 256000, 640, codec_channels,
Yves Gerey665174f2018-06-19 15:03:05 +0200283 l16_16khz_pltype_);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000284 Run(channel_a2b_, audio_channels, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000285 out_file_.Close();
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000286
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000287 if (test_mode_ != 0) {
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000288 printf("===========================================================\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000289 printf("Test number: %d\n", test_cntr_ + 1);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000290 printf("Test type: Stereo-to-stereo\n");
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000291 }
292 test_cntr_++;
293 OpenOutFile(test_cntr_);
294 RegisterSendCodec('A', codec_l16, 32000, 512000, 320, codec_channels,
Yves Gerey665174f2018-06-19 15:03:05 +0200295 l16_32khz_pltype_);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000296 Run(channel_a2b_, audio_channels, codec_channels);
297 RegisterSendCodec('A', codec_l16, 32000, 512000, 640, codec_channels,
Yves Gerey665174f2018-06-19 15:03:05 +0200298 l16_32khz_pltype_);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000299 Run(channel_a2b_, audio_channels, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000300 out_file_.Close();
niklase@google.com470e71d2011-07-07 08:21:25 +0000301#ifdef PCMA_AND_PCMU
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000302 if (test_mode_ != 0) {
303 printf("===========================================================\n");
304 printf("Test number: %d\n", test_cntr_ + 1);
305 printf("Test type: Stereo-to-stereo\n");
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000306 }
307 channel_a2b_->set_codec_mode(kStereo);
308 audio_channels = 2;
309 codec_channels = 2;
310 test_cntr_++;
311 OpenOutFile(test_cntr_);
312 char codec_pcma[] = "PCMA";
313 RegisterSendCodec('A', codec_pcma, 8000, 64000, 80, codec_channels,
314 pcma_pltype_);
315 Run(channel_a2b_, audio_channels, codec_channels);
316 RegisterSendCodec('A', codec_pcma, 8000, 64000, 160, codec_channels,
317 pcma_pltype_);
318 Run(channel_a2b_, audio_channels, codec_channels);
319 RegisterSendCodec('A', codec_pcma, 8000, 64000, 240, codec_channels,
320 pcma_pltype_);
321 Run(channel_a2b_, audio_channels, codec_channels);
322 RegisterSendCodec('A', codec_pcma, 8000, 64000, 320, codec_channels,
323 pcma_pltype_);
324 Run(channel_a2b_, audio_channels, codec_channels);
325 RegisterSendCodec('A', codec_pcma, 8000, 64000, 400, codec_channels,
326 pcma_pltype_);
327 Run(channel_a2b_, audio_channels, codec_channels);
328 RegisterSendCodec('A', codec_pcma, 8000, 64000, 480, codec_channels,
329 pcma_pltype_);
330 Run(channel_a2b_, audio_channels, codec_channels);
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000331
332 // Test that VAD/DTX cannot be turned on while sending stereo.
333 EXPECT_EQ(-1, acm_a_->SetVAD(true, true, VADNormal));
tina.legrand@webrtc.org7a7a0082013-02-21 10:27:48 +0000334 EXPECT_EQ(0, acm_a_->VAD(&dtx, &vad, &vad_mode));
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000335 EXPECT_FALSE(dtx);
336 EXPECT_FALSE(vad);
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000337 EXPECT_EQ(0, acm_a_->SetVAD(false, false, VADNormal));
tina.legrand@webrtc.org7a7a0082013-02-21 10:27:48 +0000338 EXPECT_EQ(0, acm_a_->VAD(&dtx, &vad, &vad_mode));
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000339 EXPECT_FALSE(dtx);
340 EXPECT_FALSE(vad);
341
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000342 out_file_.Close();
343 if (test_mode_ != 0) {
344 printf("===========================================================\n");
345 printf("Test number: %d\n", test_cntr_ + 1);
346 printf("Test type: Stereo-to-stereo\n");
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000347 }
348 test_cntr_++;
349 OpenOutFile(test_cntr_);
350 char codec_pcmu[] = "PCMU";
351 RegisterSendCodec('A', codec_pcmu, 8000, 64000, 80, codec_channels,
352 pcmu_pltype_);
353 Run(channel_a2b_, audio_channels, codec_channels);
354 RegisterSendCodec('A', codec_pcmu, 8000, 64000, 160, codec_channels,
355 pcmu_pltype_);
356 Run(channel_a2b_, audio_channels, codec_channels);
357 RegisterSendCodec('A', codec_pcmu, 8000, 64000, 240, codec_channels,
358 pcmu_pltype_);
359 Run(channel_a2b_, audio_channels, codec_channels);
360 RegisterSendCodec('A', codec_pcmu, 8000, 64000, 320, codec_channels,
361 pcmu_pltype_);
362 Run(channel_a2b_, audio_channels, codec_channels);
363 RegisterSendCodec('A', codec_pcmu, 8000, 64000, 400, codec_channels,
364 pcmu_pltype_);
365 Run(channel_a2b_, audio_channels, codec_channels);
366 RegisterSendCodec('A', codec_pcmu, 8000, 64000, 480, codec_channels,
367 pcmu_pltype_);
368 Run(channel_a2b_, audio_channels, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000369 out_file_.Close();
niklase@google.com470e71d2011-07-07 08:21:25 +0000370#endif
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000371#ifdef WEBRTC_CODEC_OPUS
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000372 if (test_mode_ != 0) {
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000373 printf("===========================================================\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000374 printf("Test number: %d\n", test_cntr_ + 1);
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000375 printf("Test type: Stereo-to-stereo\n");
376 }
377 channel_a2b_->set_codec_mode(kStereo);
378 audio_channels = 2;
379 codec_channels = 2;
380 test_cntr_++;
381 OpenOutFile(test_cntr_);
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000382
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000383 char codec_opus[] = "opus";
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000384 // Run Opus with 10 ms frame size.
385 RegisterSendCodec('A', codec_opus, 48000, 64000, 480, codec_channels,
Yves Gerey665174f2018-06-19 15:03:05 +0200386 opus_pltype_);
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000387 Run(channel_a2b_, audio_channels, codec_channels);
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000388 // Run Opus with 20 ms frame size.
Yves Gerey665174f2018-06-19 15:03:05 +0200389 RegisterSendCodec('A', codec_opus, 48000, 64000, 480 * 2, codec_channels,
390 opus_pltype_);
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000391 Run(channel_a2b_, audio_channels, codec_channels);
392 // Run Opus with 40 ms frame size.
Yves Gerey665174f2018-06-19 15:03:05 +0200393 RegisterSendCodec('A', codec_opus, 48000, 64000, 480 * 4, codec_channels,
394 opus_pltype_);
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000395 Run(channel_a2b_, audio_channels, codec_channels);
396 // Run Opus with 60 ms frame size.
Yves Gerey665174f2018-06-19 15:03:05 +0200397 RegisterSendCodec('A', codec_opus, 48000, 64000, 480 * 6, codec_channels,
398 opus_pltype_);
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000399 Run(channel_a2b_, audio_channels, codec_channels);
400 // Run Opus with 20 ms frame size and different bitrates.
401 RegisterSendCodec('A', codec_opus, 48000, 40000, 960, codec_channels,
Yves Gerey665174f2018-06-19 15:03:05 +0200402 opus_pltype_);
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000403 Run(channel_a2b_, audio_channels, codec_channels);
404 RegisterSendCodec('A', codec_opus, 48000, 510000, 960, codec_channels,
Yves Gerey665174f2018-06-19 15:03:05 +0200405 opus_pltype_);
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000406 Run(channel_a2b_, audio_channels, codec_channels);
407 out_file_.Close();
408#endif
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000409 //
410 // Test Mono-To-Stereo for all codecs.
411 //
412 audio_channels = 1;
413 codec_channels = 2;
niklase@google.com470e71d2011-07-07 08:21:25 +0000414
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000415 if (test_mode_ != 0) {
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000416 printf("===============================================================\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000417 printf("Test number: %d\n", test_cntr_ + 1);
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000418 printf("Test type: Mono-to-stereo\n");
419 }
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000420 test_cntr_++;
421 channel_a2b_->set_codec_mode(kStereo);
422 OpenOutFile(test_cntr_);
423 RegisterSendCodec('A', codec_g722, 16000, 64000, 160, codec_channels,
Yves Gerey665174f2018-06-19 15:03:05 +0200424 g722_pltype_);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000425 Run(channel_a2b_, audio_channels, codec_channels);
426 out_file_.Close();
Karl Wibergeb254b42017-11-01 15:08:12 +0100427
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000428 if (test_mode_ != 0) {
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000429 printf("===============================================================\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000430 printf("Test number: %d\n", test_cntr_ + 1);
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000431 printf("Test type: Mono-to-stereo\n");
432 }
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000433 test_cntr_++;
434 channel_a2b_->set_codec_mode(kStereo);
435 OpenOutFile(test_cntr_);
436 RegisterSendCodec('A', codec_l16, 8000, 128000, 80, codec_channels,
Yves Gerey665174f2018-06-19 15:03:05 +0200437 l16_8khz_pltype_);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000438 Run(channel_a2b_, audio_channels, codec_channels);
439 out_file_.Close();
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000440 if (test_mode_ != 0) {
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000441 printf("===============================================================\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000442 printf("Test number: %d\n", test_cntr_ + 1);
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000443 printf("Test type: Mono-to-stereo\n");
444 }
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000445 test_cntr_++;
446 OpenOutFile(test_cntr_);
447 RegisterSendCodec('A', codec_l16, 16000, 256000, 160, codec_channels,
Yves Gerey665174f2018-06-19 15:03:05 +0200448 l16_16khz_pltype_);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000449 Run(channel_a2b_, audio_channels, codec_channels);
450 out_file_.Close();
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000451 if (test_mode_ != 0) {
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000452 printf("===============================================================\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000453 printf("Test number: %d\n", test_cntr_ + 1);
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000454 printf("Test type: Mono-to-stereo\n");
455 }
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000456 test_cntr_++;
457 OpenOutFile(test_cntr_);
458 RegisterSendCodec('A', codec_l16, 32000, 512000, 320, codec_channels,
Yves Gerey665174f2018-06-19 15:03:05 +0200459 l16_32khz_pltype_);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000460 Run(channel_a2b_, audio_channels, codec_channels);
461 out_file_.Close();
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000462#ifdef PCMA_AND_PCMU
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000463 if (test_mode_ != 0) {
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000464 printf("===============================================================\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000465 printf("Test number: %d\n", test_cntr_ + 1);
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000466 printf("Test type: Mono-to-stereo\n");
467 }
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000468 test_cntr_++;
469 channel_a2b_->set_codec_mode(kStereo);
470 OpenOutFile(test_cntr_);
471 RegisterSendCodec('A', codec_pcmu, 8000, 64000, 80, codec_channels,
tina.legrand@webrtc.orgae1c4542012-03-12 08:41:30 +0000472 pcmu_pltype_);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000473 Run(channel_a2b_, audio_channels, codec_channels);
474 RegisterSendCodec('A', codec_pcma, 8000, 64000, 80, codec_channels,
tina.legrand@webrtc.orgae1c4542012-03-12 08:41:30 +0000475 pcma_pltype_);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000476 Run(channel_a2b_, audio_channels, codec_channels);
477 out_file_.Close();
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000478#endif
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000479#ifdef WEBRTC_CODEC_OPUS
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000480 if (test_mode_ != 0) {
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000481 printf("===============================================================\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000482 printf("Test number: %d\n", test_cntr_ + 1);
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000483 printf("Test type: Mono-to-stereo\n");
484 }
tina.legrand@webrtc.orgc4590582012-11-28 12:23:29 +0000485
486 // Keep encode and decode in stereo.
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000487 test_cntr_++;
488 channel_a2b_->set_codec_mode(kStereo);
489 OpenOutFile(test_cntr_);
490 RegisterSendCodec('A', codec_opus, 48000, 64000, 960, codec_channels,
Yves Gerey665174f2018-06-19 15:03:05 +0200491 opus_pltype_);
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000492 Run(channel_a2b_, audio_channels, codec_channels);
tina.legrand@webrtc.orgc4590582012-11-28 12:23:29 +0000493
494 // Encode in mono, decode in stereo mode.
495 RegisterSendCodec('A', codec_opus, 48000, 64000, 960, 1, opus_pltype_);
496 Run(channel_a2b_, audio_channels, codec_channels);
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000497 out_file_.Close();
498#endif
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000499
500 //
501 // Test Stereo-To-Mono for all codecs.
502 //
503 audio_channels = 2;
504 codec_channels = 1;
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000505 channel_a2b_->set_codec_mode(kMono);
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000506
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000507 // Run stereo audio and mono codec.
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000508 if (test_mode_ != 0) {
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000509 printf("===============================================================\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000510 printf("Test number: %d\n", test_cntr_ + 1);
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000511 printf("Test type: Stereo-to-mono\n");
512 }
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000513 test_cntr_++;
514 OpenOutFile(test_cntr_);
515 RegisterSendCodec('A', codec_g722, 16000, 64000, 160, codec_channels,
Yves Gerey665174f2018-06-19 15:03:05 +0200516 g722_pltype_);
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000517
518 // Make sure it is possible to set VAD/CNG, now that we are sending mono
519 // again.
520 EXPECT_EQ(0, acm_a_->SetVAD(true, true, VADNormal));
tina.legrand@webrtc.org7a7a0082013-02-21 10:27:48 +0000521 EXPECT_EQ(0, acm_a_->VAD(&dtx, &vad, &vad_mode));
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000522 EXPECT_TRUE(dtx);
523 EXPECT_TRUE(vad);
524 EXPECT_EQ(0, acm_a_->SetVAD(false, false, VADNormal));
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000525 Run(channel_a2b_, audio_channels, codec_channels);
526 out_file_.Close();
Karl Wibergeb254b42017-11-01 15:08:12 +0100527
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000528 if (test_mode_ != 0) {
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000529 printf("===============================================================\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000530 printf("Test number: %d\n", test_cntr_ + 1);
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000531 printf("Test type: Stereo-to-mono\n");
532 }
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000533 test_cntr_++;
534 OpenOutFile(test_cntr_);
535 RegisterSendCodec('A', codec_l16, 8000, 128000, 80, codec_channels,
Yves Gerey665174f2018-06-19 15:03:05 +0200536 l16_8khz_pltype_);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000537 Run(channel_a2b_, audio_channels, codec_channels);
538 out_file_.Close();
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000539 if (test_mode_ != 0) {
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000540 printf("===============================================================\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000541 printf("Test number: %d\n", test_cntr_ + 1);
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000542 printf("Test type: Stereo-to-mono\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000543 }
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000544 test_cntr_++;
545 OpenOutFile(test_cntr_);
546 RegisterSendCodec('A', codec_l16, 16000, 256000, 160, codec_channels,
Yves Gerey665174f2018-06-19 15:03:05 +0200547 l16_16khz_pltype_);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000548 Run(channel_a2b_, audio_channels, codec_channels);
549 out_file_.Close();
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000550 if (test_mode_ != 0) {
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000551 printf("==============================================================\n");
552 printf("Test number: %d\n", test_cntr_ + 1);
553 printf("Test type: Stereo-to-mono\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000554 }
555 test_cntr_++;
556 OpenOutFile(test_cntr_);
557 RegisterSendCodec('A', codec_l16, 32000, 512000, 320, codec_channels,
Yves Gerey665174f2018-06-19 15:03:05 +0200558 l16_32khz_pltype_);
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000559 Run(channel_a2b_, audio_channels, codec_channels);
560 out_file_.Close();
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000561#ifdef PCMA_AND_PCMU
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000562 if (test_mode_ != 0) {
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000563 printf("===============================================================\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000564 printf("Test number: %d\n", test_cntr_ + 1);
tina.legrand@webrtc.orgdf697752012-02-08 10:22:21 +0000565 printf("Test type: Stereo-to-mono\n");
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000566 }
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000567 test_cntr_++;
568 OpenOutFile(test_cntr_);
569 RegisterSendCodec('A', codec_pcmu, 8000, 64000, 80, codec_channels,
tina.legrand@webrtc.orgae1c4542012-03-12 08:41:30 +0000570 pcmu_pltype_);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000571 Run(channel_a2b_, audio_channels, codec_channels);
572 RegisterSendCodec('A', codec_pcma, 8000, 64000, 80, codec_channels,
tina.legrand@webrtc.orgae1c4542012-03-12 08:41:30 +0000573 pcma_pltype_);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000574 Run(channel_a2b_, audio_channels, codec_channels);
575 out_file_.Close();
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000576#endif
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000577#ifdef WEBRTC_CODEC_OPUS
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000578 if (test_mode_ != 0) {
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000579 printf("===============================================================\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000580 printf("Test number: %d\n", test_cntr_ + 1);
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000581 printf("Test type: Stereo-to-mono\n");
582 }
583 test_cntr_++;
584 OpenOutFile(test_cntr_);
tina.legrand@webrtc.orgc4590582012-11-28 12:23:29 +0000585 // Encode and decode in mono.
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000586 RegisterSendCodec('A', codec_opus, 48000, 32000, 960, codec_channels,
Yves Gerey665174f2018-06-19 15:03:05 +0200587 opus_pltype_);
tina.legrand@webrtc.orgc4590582012-11-28 12:23:29 +0000588 CodecInst opus_codec_param;
pbos@webrtc.org0946a562013-04-09 00:28:06 +0000589 for (uint8_t n = 0; n < num_encoders; n++) {
tina.legrand@webrtc.org7a7a0082013-02-21 10:27:48 +0000590 EXPECT_EQ(0, acm_b_->Codec(n, &opus_codec_param));
tina.legrand@webrtc.orgc4590582012-11-28 12:23:29 +0000591 if (!strcmp(opus_codec_param.plname, "opus")) {
592 opus_codec_param.channels = 1;
kwibergda2bf4e2016-10-24 13:47:09 -0700593 EXPECT_EQ(true,
594 acm_b_->RegisterReceiveCodec(opus_codec_param.pltype,
595 CodecInstToSdp(opus_codec_param)));
tina.legrand@webrtc.orgc4590582012-11-28 12:23:29 +0000596 break;
597 }
598 }
599 Run(channel_a2b_, audio_channels, codec_channels);
600
601 // Encode in stereo, decode in mono.
602 RegisterSendCodec('A', codec_opus, 48000, 32000, 960, 2, opus_pltype_);
603 Run(channel_a2b_, audio_channels, codec_channels);
604
605 out_file_.Close();
606
607 // Test switching between decoding mono and stereo for Opus.
608
609 // Decode in mono.
610 test_cntr_++;
611 OpenOutFile(test_cntr_);
612 if (test_mode_ != 0) {
613 // Print out codec and settings
Yves Gerey665174f2018-06-19 15:03:05 +0200614 printf(
615 "Test number: %d\nCodec: Opus Freq: 48000 Rate :32000 PackSize: 960"
616 " Decode: mono\n",
617 test_cntr_);
tina.legrand@webrtc.orgc4590582012-11-28 12:23:29 +0000618 }
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000619 Run(channel_a2b_, audio_channels, codec_channels);
620 out_file_.Close();
tina.legrand@webrtc.orgc4590582012-11-28 12:23:29 +0000621 // Decode in stereo.
622 test_cntr_++;
623 OpenOutFile(test_cntr_);
624 if (test_mode_ != 0) {
625 // Print out codec and settings
Yves Gerey665174f2018-06-19 15:03:05 +0200626 printf(
627 "Test number: %d\nCodec: Opus Freq: 48000 Rate :32000 PackSize: 960"
628 " Decode: stereo\n",
629 test_cntr_);
tina.legrand@webrtc.orgc4590582012-11-28 12:23:29 +0000630 }
631 opus_codec_param.channels = 2;
kwibergda2bf4e2016-10-24 13:47:09 -0700632 EXPECT_EQ(true,
633 acm_b_->RegisterReceiveCodec(opus_codec_param.pltype,
634 CodecInstToSdp(opus_codec_param)));
tina.legrand@webrtc.orgc4590582012-11-28 12:23:29 +0000635 Run(channel_a2b_, audio_channels, 2);
636 out_file_.Close();
637 // Decode in mono.
638 test_cntr_++;
639 OpenOutFile(test_cntr_);
640 if (test_mode_ != 0) {
641 // Print out codec and settings
Yves Gerey665174f2018-06-19 15:03:05 +0200642 printf(
643 "Test number: %d\nCodec: Opus Freq: 48000 Rate :32000 PackSize: 960"
644 " Decode: mono\n",
645 test_cntr_);
tina.legrand@webrtc.orgc4590582012-11-28 12:23:29 +0000646 }
647 opus_codec_param.channels = 1;
kwibergda2bf4e2016-10-24 13:47:09 -0700648 EXPECT_EQ(true,
649 acm_b_->RegisterReceiveCodec(opus_codec_param.pltype,
650 CodecInstToSdp(opus_codec_param)));
tina.legrand@webrtc.orgc4590582012-11-28 12:23:29 +0000651 Run(channel_a2b_, audio_channels, codec_channels);
652 out_file_.Close();
653
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000654#endif
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000655
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000656 // Print out which codecs were tested, and which were not, in the run.
657 if (test_mode_ != 0) {
658 printf("\nThe following codecs was INCLUDED in the test:\n");
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000659 printf(" G.722\n");
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000660 printf(" PCM16\n");
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000661 printf(" G.711\n");
tina.legrand@webrtc.orgc4590582012-11-28 12:23:29 +0000662#ifdef WEBRTC_CODEC_OPUS
663 printf(" Opus\n");
664#endif
Yves Gerey665174f2018-06-19 15:03:05 +0200665 printf(
666 "\nTo complete the test, listen to the %d number of output "
667 "files.\n",
668 test_cntr_);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000669 }
670
671 // Delete the file pointers.
672 delete in_file_stereo_;
673 delete in_file_mono_;
niklase@google.com470e71d2011-07-07 08:21:25 +0000674}
675
676// Register Codec to use in the test
677//
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000678// Input: side - which ACM to use, 'A' or 'B'
679// codec_name - name to use when register the codec
680// sampling_freq_hz - sampling frequency in Herz
681// rate - bitrate in bytes
682// pack_size - packet size in samples
683// channels - number of channels; 1 for mono, 2 for stereo
684// payload_type - payload type for the codec
Yves Gerey665174f2018-06-19 15:03:05 +0200685void TestStereo::RegisterSendCodec(char side,
686 char* codec_name,
687 int32_t sampling_freq_hz,
688 int rate,
689 int pack_size,
690 int channels,
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000691 int payload_type) {
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000692 if (test_mode_ != 0) {
693 // Print out codec and settings
tina.legrand@webrtc.orgba468042012-08-17 10:38:28 +0000694 printf("Codec: %s Freq: %d Rate: %d PackSize: %d\n", codec_name,
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000695 sampling_freq_hz, rate, pack_size);
696 }
697
698 // Store packet size in samples, used to validate the received packet
699 pack_size_samp_ = pack_size;
700
701 // Store the expected packet size in bytes, used to validate the received
702 // packet. Add 0.875 to always round up to a whole byte.
pbos@webrtc.orgd8ca7232014-12-10 11:49:13 +0000703 pack_size_bytes_ = (uint16_t)(static_cast<float>(pack_size * rate) /
704 static_cast<float>(sampling_freq_hz * 8) +
705 0.875);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000706
707 // Set pointer to the ACM where to register the codec
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000708 AudioCodingModule* my_acm = NULL;
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000709 switch (side) {
710 case 'A': {
andrew@webrtc.org89df0922013-09-12 01:27:43 +0000711 my_acm = acm_a_.get();
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000712 break;
niklase@google.com470e71d2011-07-07 08:21:25 +0000713 }
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000714 case 'B': {
andrew@webrtc.org89df0922013-09-12 01:27:43 +0000715 my_acm = acm_b_.get();
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000716 break;
tina.legrand@webrtc.org16b6b902012-04-12 11:02:38 +0000717 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000718 default:
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000719 break;
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000720 }
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000721 ASSERT_TRUE(my_acm != NULL);
niklase@google.com470e71d2011-07-07 08:21:25 +0000722
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000723 CodecInst my_codec_param;
724 // Get all codec parameters before registering
tina.legrand@webrtc.orgee92b662013-08-27 07:33:51 +0000725 EXPECT_GT(AudioCodingModule::Codec(codec_name, &my_codec_param,
Yves Gerey665174f2018-06-19 15:03:05 +0200726 sampling_freq_hz, channels),
727 -1);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000728 my_codec_param.rate = rate;
729 my_codec_param.pacsize = pack_size;
tina.legrand@webrtc.orgee92b662013-08-27 07:33:51 +0000730 EXPECT_EQ(0, my_acm->RegisterSendCodec(my_codec_param));
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000731
732 send_codec_name_ = codec_name;
niklase@google.com470e71d2011-07-07 08:21:25 +0000733}
734
Yves Gerey665174f2018-06-19 15:03:05 +0200735void TestStereo::Run(TestPackStereo* channel,
736 int in_channels,
737 int out_channels,
tina.legrand@webrtc.org16b6b902012-04-12 11:02:38 +0000738 int percent_loss) {
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000739 AudioFrame audio_frame;
niklase@google.com470e71d2011-07-07 08:21:25 +0000740
pbos@webrtc.org0946a562013-04-09 00:28:06 +0000741 int32_t out_freq_hz_b = out_file_.SamplingFrequency();
742 uint16_t rec_size;
743 uint32_t time_stamp_diff;
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000744 channel->reset_payload_size();
745 int error_count = 0;
tina.legrand@webrtc.org65d61c32014-06-05 13:42:51 +0000746 int variable_bytes = 0;
747 int variable_packets = 0;
Henrik Lundin4d682082015-12-10 16:24:39 +0100748 // Set test length to 500 ms (50 blocks of 10 ms each).
749 in_file_mono_->SetNum10MsBlocksToRead(50);
750 in_file_stereo_->SetNum10MsBlocksToRead(50);
751 // Fast-forward 1 second (100 blocks) since the files start with silence.
752 in_file_stereo_->FastForward(100);
753 in_file_mono_->FastForward(100);
niklase@google.com470e71d2011-07-07 08:21:25 +0000754
andresp@webrtc.orgd0b436a2014-01-13 13:15:59 +0000755 while (1) {
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000756 // Simulate packet loss by setting |packet_loss_| to "true" in
757 // |percent_loss| percent of the loops.
758 if (percent_loss > 0) {
759 if (counter_ == floor((100 / percent_loss) + 0.5)) {
760 counter_ = 0;
761 channel->set_lost_packet(true);
762 } else {
763 channel->set_lost_packet(false);
764 }
765 counter_++;
niklase@google.com470e71d2011-07-07 08:21:25 +0000766 }
767
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000768 // Add 10 msec to ACM
769 if (in_channels == 1) {
770 if (in_file_mono_->EndOfFile()) {
771 break;
772 }
773 in_file_mono_->Read10MsData(audio_frame);
774 } else {
775 if (in_file_stereo_->EndOfFile()) {
776 break;
777 }
778 in_file_stereo_->Read10MsData(audio_frame);
779 }
henrik.lundin@webrtc.orgf56c1622015-03-02 12:29:30 +0000780 EXPECT_GE(acm_a_->Add10MsData(audio_frame), 0);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000781
tina.legrand@webrtc.org65d61c32014-06-05 13:42:51 +0000782 // Verify that the received packet size matches the settings.
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000783 rec_size = channel->payload_size();
784 if ((0 < rec_size) & (rec_size < 65535)) {
tina.legrand@webrtc.org65d61c32014-06-05 13:42:51 +0000785 if (strcmp(send_codec_name_, "opus") == 0) {
786 // Opus is a variable rate codec, hence calculate the average packet
787 // size, and later make sure the average is in the right range.
788 variable_bytes += rec_size;
789 variable_packets++;
790 } else {
791 // For fixed rate codecs, check that packet size is correct.
Yves Gerey665174f2018-06-19 15:03:05 +0200792 if ((rec_size != pack_size_bytes_ * out_channels) &&
793 (pack_size_bytes_ < 65535)) {
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000794 error_count++;
795 }
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000796 }
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000797 // Verify that the timestamp is updated with expected length
798 time_stamp_diff = channel->timestamp_diff();
799 if ((counter_ > 10) && (time_stamp_diff != pack_size_samp_)) {
800 error_count++;
801 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000802 }
803
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000804 // Run received side of ACM
henrik.lundind4ccb002016-05-17 12:21:55 -0700805 bool muted;
806 EXPECT_EQ(0, acm_b_->PlayoutData10Ms(out_freq_hz_b, &audio_frame, &muted));
807 ASSERT_FALSE(muted);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000808
809 // Write output speech to file
810 out_file_.Write10MsData(
yujo36b1a5f2017-06-12 12:45:32 -0700811 audio_frame.data(),
andrew@webrtc.org63a50982012-05-02 23:56:37 +0000812 audio_frame.samples_per_channel_ * audio_frame.num_channels_);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000813 }
814
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000815 EXPECT_EQ(0, error_count);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000816
tina.legrand@webrtc.org65d61c32014-06-05 13:42:51 +0000817 // Check that packet size is in the right range for variable rate codecs,
818 // such as Opus.
819 if (variable_packets > 0) {
820 variable_bytes /= variable_packets;
Henrik Lundin4d682082015-12-10 16:24:39 +0100821 EXPECT_NEAR(variable_bytes, pack_size_bytes_, 18);
tina.legrand@webrtc.org65d61c32014-06-05 13:42:51 +0000822 }
823
andresp@webrtc.orgd0b436a2014-01-13 13:15:59 +0000824 if (in_file_mono_->EndOfFile()) {
825 in_file_mono_->Rewind();
826 }
827 if (in_file_stereo_->EndOfFile()) {
828 in_file_stereo_->Rewind();
829 }
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000830 // Reset in case we ended with a lost packet
831 channel->set_lost_packet(false);
niklase@google.com470e71d2011-07-07 08:21:25 +0000832}
833
pbos@webrtc.org0946a562013-04-09 00:28:06 +0000834void TestStereo::OpenOutFile(int16_t test_number) {
tina.legrand@webrtc.orgba468042012-08-17 10:38:28 +0000835 std::string file_name;
Jonas Olsson366a50c2018-09-06 13:41:30 +0200836 rtc::StringBuilder file_stream;
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000837 file_stream << webrtc::test::OutputPath() << "teststereo_out_" << test_number
Yves Gerey665174f2018-06-19 15:03:05 +0200838 << ".pcm";
tina.legrand@webrtc.orgba468042012-08-17 10:38:28 +0000839 file_name = file_stream.str();
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000840 out_file_.Open(file_name, 32000, "wb");
niklase@google.com470e71d2011-07-07 08:21:25 +0000841}
842
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000843void TestStereo::DisplaySendReceiveCodec() {
kwiberg1fd4a4a2015-11-03 11:20:50 -0800844 auto send_codec = acm_a_->SendCodec();
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000845 if (test_mode_ != 0) {
kwiberg1fd4a4a2015-11-03 11:20:50 -0800846 ASSERT_TRUE(send_codec);
847 printf("%s -> ", send_codec->plname);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000848 }
kwiberg1fd4a4a2015-11-03 11:20:50 -0800849 CodecInst receive_codec;
850 acm_b_->ReceiveCodec(&receive_codec);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000851 if (test_mode_ != 0) {
kwiberg1fd4a4a2015-11-03 11:20:50 -0800852 printf("%s\n", receive_codec.plname);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000853 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000854}
855
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000856} // namespace webrtc