blob: e01f7229967f787fd9b196b7cdff24d525a1eb4b [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 Wiberg36b37dc2018-09-24 10:52:32 +0200111 counter_(0) {
tina.legrand@webrtc.org45175852012-06-01 09:27:35 +0000112 // test_mode = 0 for silent test (auto test)
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000113 test_mode_ = test_mode;
niklase@google.com470e71d2011-07-07 08:21:25 +0000114}
115
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000116TestStereo::~TestStereo() {
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000117 if (channel_a2b_ != NULL) {
118 delete channel_a2b_;
119 channel_a2b_ = NULL;
120 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000121}
122
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000123void TestStereo::Perform() {
pbos@webrtc.org0946a562013-04-09 00:28:06 +0000124 uint16_t frequency_hz;
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000125 int audio_channels;
126 int codec_channels;
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000127 bool dtx;
128 bool vad;
129 ACMVADMode vad_mode;
niklase@google.com470e71d2011-07-07 08:21:25 +0000130
tina.legrand@webrtc.org45175852012-06-01 09:27:35 +0000131 // Open both mono and stereo test files in 32 kHz.
Yves Gerey665174f2018-06-19 15:03:05 +0200132 const std::string file_name_stereo =
133 webrtc::test::ResourcePath("audio_coding/teststereo32kHz", "pcm");
134 const std::string file_name_mono =
135 webrtc::test::ResourcePath("audio_coding/testfile32kHz", "pcm");
tina.legrand@webrtc.org45175852012-06-01 09:27:35 +0000136 frequency_hz = 32000;
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000137 in_file_stereo_ = new PCMFile();
138 in_file_mono_ = new PCMFile();
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000139 in_file_stereo_->Open(file_name_stereo, frequency_hz, "rb");
140 in_file_stereo_->ReadStereo(true);
141 in_file_mono_->Open(file_name_mono, frequency_hz, "rb");
142 in_file_mono_->ReadStereo(false);
143
tina.legrand@webrtc.org45175852012-06-01 09:27:35 +0000144 // Create and initialize two ACMs, one for each side of a one-to-one call.
andrew@webrtc.org89df0922013-09-12 01:27:43 +0000145 ASSERT_TRUE((acm_a_.get() != NULL) && (acm_b_.get() != NULL));
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000146 EXPECT_EQ(0, acm_a_->InitializeReceiver());
147 EXPECT_EQ(0, acm_b_->InitializeReceiver());
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000148
tina.legrand@webrtc.org45175852012-06-01 09:27:35 +0000149 // Register all available codes as receiving codecs.
pbos@webrtc.org0946a562013-04-09 00:28:06 +0000150 uint8_t num_encoders = acm_a_->NumberOfCodecs();
tina.legrand@webrtc.org45175852012-06-01 09:27:35 +0000151 CodecInst my_codec_param;
pbos@webrtc.org0946a562013-04-09 00:28:06 +0000152 for (uint8_t n = 0; n < num_encoders; n++) {
tina.legrand@webrtc.org7a7a0082013-02-21 10:27:48 +0000153 EXPECT_EQ(0, acm_b_->Codec(n, &my_codec_param));
kwibergda2bf4e2016-10-24 13:47:09 -0700154 EXPECT_EQ(true, acm_b_->RegisterReceiveCodec(
155 my_codec_param.pltype, CodecInstToSdp(my_codec_param)));
tina.legrand@webrtc.org45175852012-06-01 09:27:35 +0000156 }
157
158 // Test that unregister all receive codecs works.
pbos@webrtc.org0946a562013-04-09 00:28:06 +0000159 for (uint8_t n = 0; n < num_encoders; n++) {
tina.legrand@webrtc.org7a7a0082013-02-21 10:27:48 +0000160 EXPECT_EQ(0, acm_b_->Codec(n, &my_codec_param));
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000161 EXPECT_EQ(0, acm_b_->UnregisterReceiveCodec(my_codec_param.pltype));
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000162 }
tina.legrand@webrtc.orgae1c4542012-03-12 08:41:30 +0000163
tina.legrand@webrtc.org45175852012-06-01 09:27:35 +0000164 // Register all available codes as receiving codecs once more.
pbos@webrtc.org0946a562013-04-09 00:28:06 +0000165 for (uint8_t n = 0; n < num_encoders; n++) {
tina.legrand@webrtc.org7a7a0082013-02-21 10:27:48 +0000166 EXPECT_EQ(0, acm_b_->Codec(n, &my_codec_param));
kwibergda2bf4e2016-10-24 13:47:09 -0700167 EXPECT_EQ(true, acm_b_->RegisterReceiveCodec(
168 my_codec_param.pltype, CodecInstToSdp(my_codec_param)));
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000169 }
tina.legrand@webrtc.orgae1c4542012-03-12 08:41:30 +0000170
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000171 // Create and connect the channel.
172 channel_a2b_ = new TestPackStereo;
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000173 EXPECT_EQ(0, acm_a_->RegisterTransportCallback(channel_a2b_));
andrew@webrtc.org89df0922013-09-12 01:27:43 +0000174 channel_a2b_->RegisterReceiverACM(acm_b_.get());
tina.legrand@webrtc.orgdf697752012-02-08 10:22:21 +0000175
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000176 // Start with setting VAD/DTX, before we know we will send stereo.
177 // Continue with setting a stereo codec as send codec and verify that
178 // VAD/DTX gets turned off.
179 EXPECT_EQ(0, acm_a_->SetVAD(true, true, VADNormal));
tina.legrand@webrtc.org7a7a0082013-02-21 10:27:48 +0000180 EXPECT_EQ(0, acm_a_->VAD(&dtx, &vad, &vad_mode));
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000181 EXPECT_TRUE(dtx);
182 EXPECT_TRUE(vad);
183 char codec_pcma_temp[] = "PCMA";
Karl Wiberg36b37dc2018-09-24 10:52:32 +0200184 RegisterSendCodec('A', codec_pcma_temp, 8000, 64000, 80, 2);
tina.legrand@webrtc.org7a7a0082013-02-21 10:27:48 +0000185 EXPECT_EQ(0, acm_a_->VAD(&dtx, &vad, &vad_mode));
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000186 EXPECT_FALSE(dtx);
187 EXPECT_FALSE(vad);
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000188 if (test_mode_ != 0) {
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000189 printf("\n");
190 }
191
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000192 //
193 // Test Stereo-To-Stereo for all codecs.
194 //
195 audio_channels = 2;
196 codec_channels = 2;
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000197
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000198 // All codecs are tested for all allowed sampling frequencies, rates and
199 // packet sizes.
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000200 if (test_mode_ != 0) {
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000201 printf("===========================================================\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000202 printf("Test number: %d\n", test_cntr_ + 1);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000203 printf("Test type: Stereo-to-stereo\n");
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000204 }
205 channel_a2b_->set_codec_mode(kStereo);
206 test_cntr_++;
207 OpenOutFile(test_cntr_);
208 char codec_g722[] = "G722";
Karl Wiberg36b37dc2018-09-24 10:52:32 +0200209 RegisterSendCodec('A', codec_g722, 16000, 64000, 160, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000210 Run(channel_a2b_, audio_channels, codec_channels);
Karl Wiberg36b37dc2018-09-24 10:52:32 +0200211 RegisterSendCodec('A', codec_g722, 16000, 64000, 320, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000212 Run(channel_a2b_, audio_channels, codec_channels);
Karl Wiberg36b37dc2018-09-24 10:52:32 +0200213 RegisterSendCodec('A', codec_g722, 16000, 64000, 480, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000214 Run(channel_a2b_, audio_channels, codec_channels);
Karl Wiberg36b37dc2018-09-24 10:52:32 +0200215 RegisterSendCodec('A', codec_g722, 16000, 64000, 640, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000216 Run(channel_a2b_, audio_channels, codec_channels);
Karl Wiberg36b37dc2018-09-24 10:52:32 +0200217 RegisterSendCodec('A', codec_g722, 16000, 64000, 800, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000218 Run(channel_a2b_, audio_channels, codec_channels);
Karl Wiberg36b37dc2018-09-24 10:52:32 +0200219 RegisterSendCodec('A', codec_g722, 16000, 64000, 960, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000220 Run(channel_a2b_, audio_channels, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000221 out_file_.Close();
Karl Wibergeb254b42017-11-01 15:08:12 +0100222
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000223 if (test_mode_ != 0) {
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000224 printf("===========================================================\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000225 printf("Test number: %d\n", test_cntr_ + 1);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000226 printf("Test type: Stereo-to-stereo\n");
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000227 }
228 channel_a2b_->set_codec_mode(kStereo);
229 test_cntr_++;
230 OpenOutFile(test_cntr_);
231 char codec_l16[] = "L16";
Karl Wiberg36b37dc2018-09-24 10:52:32 +0200232 RegisterSendCodec('A', codec_l16, 8000, 128000, 80, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000233 Run(channel_a2b_, audio_channels, codec_channels);
Karl Wiberg36b37dc2018-09-24 10:52:32 +0200234 RegisterSendCodec('A', codec_l16, 8000, 128000, 160, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000235 Run(channel_a2b_, audio_channels, codec_channels);
Karl Wiberg36b37dc2018-09-24 10:52:32 +0200236 RegisterSendCodec('A', codec_l16, 8000, 128000, 240, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000237 Run(channel_a2b_, audio_channels, codec_channels);
Karl Wiberg36b37dc2018-09-24 10:52:32 +0200238 RegisterSendCodec('A', codec_l16, 8000, 128000, 320, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000239 Run(channel_a2b_, audio_channels, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000240 out_file_.Close();
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000241
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000242 if (test_mode_ != 0) {
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000243 printf("===========================================================\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000244 printf("Test number: %d\n", test_cntr_ + 1);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000245 printf("Test type: Stereo-to-stereo\n");
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000246 }
247 test_cntr_++;
248 OpenOutFile(test_cntr_);
Karl Wiberg36b37dc2018-09-24 10:52:32 +0200249 RegisterSendCodec('A', codec_l16, 16000, 256000, 160, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000250 Run(channel_a2b_, audio_channels, codec_channels);
Karl Wiberg36b37dc2018-09-24 10:52:32 +0200251 RegisterSendCodec('A', codec_l16, 16000, 256000, 320, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000252 Run(channel_a2b_, audio_channels, codec_channels);
Karl Wiberg36b37dc2018-09-24 10:52:32 +0200253 RegisterSendCodec('A', codec_l16, 16000, 256000, 480, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000254 Run(channel_a2b_, audio_channels, codec_channels);
Karl Wiberg36b37dc2018-09-24 10:52:32 +0200255 RegisterSendCodec('A', codec_l16, 16000, 256000, 640, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000256 Run(channel_a2b_, audio_channels, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000257 out_file_.Close();
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000258
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000259 if (test_mode_ != 0) {
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000260 printf("===========================================================\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000261 printf("Test number: %d\n", test_cntr_ + 1);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000262 printf("Test type: Stereo-to-stereo\n");
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000263 }
264 test_cntr_++;
265 OpenOutFile(test_cntr_);
Karl Wiberg36b37dc2018-09-24 10:52:32 +0200266 RegisterSendCodec('A', codec_l16, 32000, 512000, 320, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000267 Run(channel_a2b_, audio_channels, codec_channels);
Karl Wiberg36b37dc2018-09-24 10:52:32 +0200268 RegisterSendCodec('A', codec_l16, 32000, 512000, 640, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000269 Run(channel_a2b_, audio_channels, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000270 out_file_.Close();
niklase@google.com470e71d2011-07-07 08:21:25 +0000271#ifdef PCMA_AND_PCMU
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000272 if (test_mode_ != 0) {
273 printf("===========================================================\n");
274 printf("Test number: %d\n", test_cntr_ + 1);
275 printf("Test type: Stereo-to-stereo\n");
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000276 }
277 channel_a2b_->set_codec_mode(kStereo);
278 audio_channels = 2;
279 codec_channels = 2;
280 test_cntr_++;
281 OpenOutFile(test_cntr_);
282 char codec_pcma[] = "PCMA";
Karl Wiberg36b37dc2018-09-24 10:52:32 +0200283 RegisterSendCodec('A', codec_pcma, 8000, 64000, 80, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000284 Run(channel_a2b_, audio_channels, codec_channels);
Karl Wiberg36b37dc2018-09-24 10:52:32 +0200285 RegisterSendCodec('A', codec_pcma, 8000, 64000, 160, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000286 Run(channel_a2b_, audio_channels, codec_channels);
Karl Wiberg36b37dc2018-09-24 10:52:32 +0200287 RegisterSendCodec('A', codec_pcma, 8000, 64000, 240, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000288 Run(channel_a2b_, audio_channels, codec_channels);
Karl Wiberg36b37dc2018-09-24 10:52:32 +0200289 RegisterSendCodec('A', codec_pcma, 8000, 64000, 320, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000290 Run(channel_a2b_, audio_channels, codec_channels);
Karl Wiberg36b37dc2018-09-24 10:52:32 +0200291 RegisterSendCodec('A', codec_pcma, 8000, 64000, 400, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000292 Run(channel_a2b_, audio_channels, codec_channels);
Karl Wiberg36b37dc2018-09-24 10:52:32 +0200293 RegisterSendCodec('A', codec_pcma, 8000, 64000, 480, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000294 Run(channel_a2b_, audio_channels, codec_channels);
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000295
296 // Test that VAD/DTX cannot be turned on while sending stereo.
297 EXPECT_EQ(-1, acm_a_->SetVAD(true, true, VADNormal));
tina.legrand@webrtc.org7a7a0082013-02-21 10:27:48 +0000298 EXPECT_EQ(0, acm_a_->VAD(&dtx, &vad, &vad_mode));
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000299 EXPECT_FALSE(dtx);
300 EXPECT_FALSE(vad);
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000301 EXPECT_EQ(0, acm_a_->SetVAD(false, false, VADNormal));
tina.legrand@webrtc.org7a7a0082013-02-21 10:27:48 +0000302 EXPECT_EQ(0, acm_a_->VAD(&dtx, &vad, &vad_mode));
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000303 EXPECT_FALSE(dtx);
304 EXPECT_FALSE(vad);
305
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000306 out_file_.Close();
307 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 test_cntr_++;
313 OpenOutFile(test_cntr_);
314 char codec_pcmu[] = "PCMU";
Karl Wiberg36b37dc2018-09-24 10:52:32 +0200315 RegisterSendCodec('A', codec_pcmu, 8000, 64000, 80, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000316 Run(channel_a2b_, audio_channels, codec_channels);
Karl Wiberg36b37dc2018-09-24 10:52:32 +0200317 RegisterSendCodec('A', codec_pcmu, 8000, 64000, 160, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000318 Run(channel_a2b_, audio_channels, codec_channels);
Karl Wiberg36b37dc2018-09-24 10:52:32 +0200319 RegisterSendCodec('A', codec_pcmu, 8000, 64000, 240, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000320 Run(channel_a2b_, audio_channels, codec_channels);
Karl Wiberg36b37dc2018-09-24 10:52:32 +0200321 RegisterSendCodec('A', codec_pcmu, 8000, 64000, 320, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000322 Run(channel_a2b_, audio_channels, codec_channels);
Karl Wiberg36b37dc2018-09-24 10:52:32 +0200323 RegisterSendCodec('A', codec_pcmu, 8000, 64000, 400, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000324 Run(channel_a2b_, audio_channels, codec_channels);
Karl Wiberg36b37dc2018-09-24 10:52:32 +0200325 RegisterSendCodec('A', codec_pcmu, 8000, 64000, 480, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000326 Run(channel_a2b_, audio_channels, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000327 out_file_.Close();
niklase@google.com470e71d2011-07-07 08:21:25 +0000328#endif
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000329#ifdef WEBRTC_CODEC_OPUS
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000330 if (test_mode_ != 0) {
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000331 printf("===========================================================\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000332 printf("Test number: %d\n", test_cntr_ + 1);
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000333 printf("Test type: Stereo-to-stereo\n");
334 }
335 channel_a2b_->set_codec_mode(kStereo);
336 audio_channels = 2;
337 codec_channels = 2;
338 test_cntr_++;
339 OpenOutFile(test_cntr_);
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000340
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000341 char codec_opus[] = "opus";
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000342 // Run Opus with 10 ms frame size.
Karl Wiberg36b37dc2018-09-24 10:52:32 +0200343 RegisterSendCodec('A', codec_opus, 48000, 64000, 480, codec_channels);
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000344 Run(channel_a2b_, audio_channels, codec_channels);
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000345 // Run Opus with 20 ms frame size.
Karl Wiberg36b37dc2018-09-24 10:52:32 +0200346 RegisterSendCodec('A', codec_opus, 48000, 64000, 480 * 2, codec_channels);
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000347 Run(channel_a2b_, audio_channels, codec_channels);
348 // Run Opus with 40 ms frame size.
Karl Wiberg36b37dc2018-09-24 10:52:32 +0200349 RegisterSendCodec('A', codec_opus, 48000, 64000, 480 * 4, codec_channels);
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000350 Run(channel_a2b_, audio_channels, codec_channels);
351 // Run Opus with 60 ms frame size.
Karl Wiberg36b37dc2018-09-24 10:52:32 +0200352 RegisterSendCodec('A', codec_opus, 48000, 64000, 480 * 6, codec_channels);
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000353 Run(channel_a2b_, audio_channels, codec_channels);
354 // Run Opus with 20 ms frame size and different bitrates.
Karl Wiberg36b37dc2018-09-24 10:52:32 +0200355 RegisterSendCodec('A', codec_opus, 48000, 40000, 960, codec_channels);
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000356 Run(channel_a2b_, audio_channels, codec_channels);
Karl Wiberg36b37dc2018-09-24 10:52:32 +0200357 RegisterSendCodec('A', codec_opus, 48000, 510000, 960, codec_channels);
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000358 Run(channel_a2b_, audio_channels, codec_channels);
359 out_file_.Close();
360#endif
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000361 //
362 // Test Mono-To-Stereo for all codecs.
363 //
364 audio_channels = 1;
365 codec_channels = 2;
niklase@google.com470e71d2011-07-07 08:21:25 +0000366
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000367 if (test_mode_ != 0) {
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000368 printf("===============================================================\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000369 printf("Test number: %d\n", test_cntr_ + 1);
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000370 printf("Test type: Mono-to-stereo\n");
371 }
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000372 test_cntr_++;
373 channel_a2b_->set_codec_mode(kStereo);
374 OpenOutFile(test_cntr_);
Karl Wiberg36b37dc2018-09-24 10:52:32 +0200375 RegisterSendCodec('A', codec_g722, 16000, 64000, 160, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000376 Run(channel_a2b_, audio_channels, codec_channels);
377 out_file_.Close();
Karl Wibergeb254b42017-11-01 15:08:12 +0100378
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000379 if (test_mode_ != 0) {
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000380 printf("===============================================================\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000381 printf("Test number: %d\n", test_cntr_ + 1);
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000382 printf("Test type: Mono-to-stereo\n");
383 }
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000384 test_cntr_++;
385 channel_a2b_->set_codec_mode(kStereo);
386 OpenOutFile(test_cntr_);
Karl Wiberg36b37dc2018-09-24 10:52:32 +0200387 RegisterSendCodec('A', codec_l16, 8000, 128000, 80, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000388 Run(channel_a2b_, audio_channels, codec_channels);
389 out_file_.Close();
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000390 if (test_mode_ != 0) {
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000391 printf("===============================================================\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000392 printf("Test number: %d\n", test_cntr_ + 1);
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000393 printf("Test type: Mono-to-stereo\n");
394 }
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000395 test_cntr_++;
396 OpenOutFile(test_cntr_);
Karl Wiberg36b37dc2018-09-24 10:52:32 +0200397 RegisterSendCodec('A', codec_l16, 16000, 256000, 160, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000398 Run(channel_a2b_, audio_channels, codec_channels);
399 out_file_.Close();
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000400 if (test_mode_ != 0) {
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000401 printf("===============================================================\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000402 printf("Test number: %d\n", test_cntr_ + 1);
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000403 printf("Test type: Mono-to-stereo\n");
404 }
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000405 test_cntr_++;
406 OpenOutFile(test_cntr_);
Karl Wiberg36b37dc2018-09-24 10:52:32 +0200407 RegisterSendCodec('A', codec_l16, 32000, 512000, 320, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000408 Run(channel_a2b_, audio_channels, codec_channels);
409 out_file_.Close();
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000410#ifdef PCMA_AND_PCMU
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000411 if (test_mode_ != 0) {
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000412 printf("===============================================================\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000413 printf("Test number: %d\n", test_cntr_ + 1);
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000414 printf("Test type: Mono-to-stereo\n");
415 }
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000416 test_cntr_++;
417 channel_a2b_->set_codec_mode(kStereo);
418 OpenOutFile(test_cntr_);
Karl Wiberg36b37dc2018-09-24 10:52:32 +0200419 RegisterSendCodec('A', codec_pcmu, 8000, 64000, 80, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000420 Run(channel_a2b_, audio_channels, codec_channels);
Karl Wiberg36b37dc2018-09-24 10:52:32 +0200421 RegisterSendCodec('A', codec_pcma, 8000, 64000, 80, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000422 Run(channel_a2b_, audio_channels, codec_channels);
423 out_file_.Close();
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000424#endif
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000425#ifdef WEBRTC_CODEC_OPUS
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000426 if (test_mode_ != 0) {
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000427 printf("===============================================================\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000428 printf("Test number: %d\n", test_cntr_ + 1);
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000429 printf("Test type: Mono-to-stereo\n");
430 }
tina.legrand@webrtc.orgc4590582012-11-28 12:23:29 +0000431
432 // Keep encode and decode in stereo.
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000433 test_cntr_++;
434 channel_a2b_->set_codec_mode(kStereo);
435 OpenOutFile(test_cntr_);
Karl Wiberg36b37dc2018-09-24 10:52:32 +0200436 RegisterSendCodec('A', codec_opus, 48000, 64000, 960, codec_channels);
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000437 Run(channel_a2b_, audio_channels, codec_channels);
tina.legrand@webrtc.orgc4590582012-11-28 12:23:29 +0000438
439 // Encode in mono, decode in stereo mode.
Karl Wiberg36b37dc2018-09-24 10:52:32 +0200440 RegisterSendCodec('A', codec_opus, 48000, 64000, 960, 1);
tina.legrand@webrtc.orgc4590582012-11-28 12:23:29 +0000441 Run(channel_a2b_, audio_channels, codec_channels);
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000442 out_file_.Close();
443#endif
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000444
445 //
446 // Test Stereo-To-Mono for all codecs.
447 //
448 audio_channels = 2;
449 codec_channels = 1;
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000450 channel_a2b_->set_codec_mode(kMono);
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000451
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000452 // Run stereo audio and mono codec.
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000453 if (test_mode_ != 0) {
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000454 printf("===============================================================\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000455 printf("Test number: %d\n", test_cntr_ + 1);
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000456 printf("Test type: Stereo-to-mono\n");
457 }
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000458 test_cntr_++;
459 OpenOutFile(test_cntr_);
Karl Wiberg36b37dc2018-09-24 10:52:32 +0200460 RegisterSendCodec('A', codec_g722, 16000, 64000, 160, codec_channels);
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000461
462 // Make sure it is possible to set VAD/CNG, now that we are sending mono
463 // again.
464 EXPECT_EQ(0, acm_a_->SetVAD(true, true, VADNormal));
tina.legrand@webrtc.org7a7a0082013-02-21 10:27:48 +0000465 EXPECT_EQ(0, acm_a_->VAD(&dtx, &vad, &vad_mode));
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000466 EXPECT_TRUE(dtx);
467 EXPECT_TRUE(vad);
468 EXPECT_EQ(0, acm_a_->SetVAD(false, false, VADNormal));
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000469 Run(channel_a2b_, audio_channels, codec_channels);
470 out_file_.Close();
Karl Wibergeb254b42017-11-01 15:08:12 +0100471
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000472 if (test_mode_ != 0) {
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000473 printf("===============================================================\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000474 printf("Test number: %d\n", test_cntr_ + 1);
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000475 printf("Test type: Stereo-to-mono\n");
476 }
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000477 test_cntr_++;
478 OpenOutFile(test_cntr_);
Karl Wiberg36b37dc2018-09-24 10:52:32 +0200479 RegisterSendCodec('A', codec_l16, 8000, 128000, 80, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000480 Run(channel_a2b_, audio_channels, codec_channels);
481 out_file_.Close();
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000482 if (test_mode_ != 0) {
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000483 printf("===============================================================\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000484 printf("Test number: %d\n", test_cntr_ + 1);
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000485 printf("Test type: Stereo-to-mono\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000486 }
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000487 test_cntr_++;
488 OpenOutFile(test_cntr_);
Karl Wiberg36b37dc2018-09-24 10:52:32 +0200489 RegisterSendCodec('A', codec_l16, 16000, 256000, 160, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000490 Run(channel_a2b_, audio_channels, codec_channels);
491 out_file_.Close();
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000492 if (test_mode_ != 0) {
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000493 printf("==============================================================\n");
494 printf("Test number: %d\n", test_cntr_ + 1);
495 printf("Test type: Stereo-to-mono\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000496 }
497 test_cntr_++;
498 OpenOutFile(test_cntr_);
Karl Wiberg36b37dc2018-09-24 10:52:32 +0200499 RegisterSendCodec('A', codec_l16, 32000, 512000, 320, codec_channels);
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000500 Run(channel_a2b_, audio_channels, codec_channels);
501 out_file_.Close();
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000502#ifdef PCMA_AND_PCMU
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000503 if (test_mode_ != 0) {
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000504 printf("===============================================================\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000505 printf("Test number: %d\n", test_cntr_ + 1);
tina.legrand@webrtc.orgdf697752012-02-08 10:22:21 +0000506 printf("Test type: Stereo-to-mono\n");
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000507 }
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000508 test_cntr_++;
509 OpenOutFile(test_cntr_);
Karl Wiberg36b37dc2018-09-24 10:52:32 +0200510 RegisterSendCodec('A', codec_pcmu, 8000, 64000, 80, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000511 Run(channel_a2b_, audio_channels, codec_channels);
Karl Wiberg36b37dc2018-09-24 10:52:32 +0200512 RegisterSendCodec('A', codec_pcma, 8000, 64000, 80, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000513 Run(channel_a2b_, audio_channels, codec_channels);
514 out_file_.Close();
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000515#endif
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000516#ifdef WEBRTC_CODEC_OPUS
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000517 if (test_mode_ != 0) {
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000518 printf("===============================================================\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000519 printf("Test number: %d\n", test_cntr_ + 1);
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000520 printf("Test type: Stereo-to-mono\n");
521 }
522 test_cntr_++;
523 OpenOutFile(test_cntr_);
tina.legrand@webrtc.orgc4590582012-11-28 12:23:29 +0000524 // Encode and decode in mono.
Karl Wiberg36b37dc2018-09-24 10:52:32 +0200525 RegisterSendCodec('A', codec_opus, 48000, 32000, 960, codec_channels);
tina.legrand@webrtc.orgc4590582012-11-28 12:23:29 +0000526 CodecInst opus_codec_param;
pbos@webrtc.org0946a562013-04-09 00:28:06 +0000527 for (uint8_t n = 0; n < num_encoders; n++) {
tina.legrand@webrtc.org7a7a0082013-02-21 10:27:48 +0000528 EXPECT_EQ(0, acm_b_->Codec(n, &opus_codec_param));
tina.legrand@webrtc.orgc4590582012-11-28 12:23:29 +0000529 if (!strcmp(opus_codec_param.plname, "opus")) {
530 opus_codec_param.channels = 1;
kwibergda2bf4e2016-10-24 13:47:09 -0700531 EXPECT_EQ(true,
532 acm_b_->RegisterReceiveCodec(opus_codec_param.pltype,
533 CodecInstToSdp(opus_codec_param)));
tina.legrand@webrtc.orgc4590582012-11-28 12:23:29 +0000534 break;
535 }
536 }
537 Run(channel_a2b_, audio_channels, codec_channels);
538
539 // Encode in stereo, decode in mono.
Karl Wiberg36b37dc2018-09-24 10:52:32 +0200540 RegisterSendCodec('A', codec_opus, 48000, 32000, 960, 2);
tina.legrand@webrtc.orgc4590582012-11-28 12:23:29 +0000541 Run(channel_a2b_, audio_channels, codec_channels);
542
543 out_file_.Close();
544
545 // Test switching between decoding mono and stereo for Opus.
546
547 // Decode in mono.
548 test_cntr_++;
549 OpenOutFile(test_cntr_);
550 if (test_mode_ != 0) {
551 // Print out codec and settings
Yves Gerey665174f2018-06-19 15:03:05 +0200552 printf(
553 "Test number: %d\nCodec: Opus Freq: 48000 Rate :32000 PackSize: 960"
554 " Decode: mono\n",
555 test_cntr_);
tina.legrand@webrtc.orgc4590582012-11-28 12:23:29 +0000556 }
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000557 Run(channel_a2b_, audio_channels, codec_channels);
558 out_file_.Close();
tina.legrand@webrtc.orgc4590582012-11-28 12:23:29 +0000559 // Decode in stereo.
560 test_cntr_++;
561 OpenOutFile(test_cntr_);
562 if (test_mode_ != 0) {
563 // Print out codec and settings
Yves Gerey665174f2018-06-19 15:03:05 +0200564 printf(
565 "Test number: %d\nCodec: Opus Freq: 48000 Rate :32000 PackSize: 960"
566 " Decode: stereo\n",
567 test_cntr_);
tina.legrand@webrtc.orgc4590582012-11-28 12:23:29 +0000568 }
569 opus_codec_param.channels = 2;
kwibergda2bf4e2016-10-24 13:47:09 -0700570 EXPECT_EQ(true,
571 acm_b_->RegisterReceiveCodec(opus_codec_param.pltype,
572 CodecInstToSdp(opus_codec_param)));
tina.legrand@webrtc.orgc4590582012-11-28 12:23:29 +0000573 Run(channel_a2b_, audio_channels, 2);
574 out_file_.Close();
575 // Decode in mono.
576 test_cntr_++;
577 OpenOutFile(test_cntr_);
578 if (test_mode_ != 0) {
579 // Print out codec and settings
Yves Gerey665174f2018-06-19 15:03:05 +0200580 printf(
581 "Test number: %d\nCodec: Opus Freq: 48000 Rate :32000 PackSize: 960"
582 " Decode: mono\n",
583 test_cntr_);
tina.legrand@webrtc.orgc4590582012-11-28 12:23:29 +0000584 }
585 opus_codec_param.channels = 1;
kwibergda2bf4e2016-10-24 13:47:09 -0700586 EXPECT_EQ(true,
587 acm_b_->RegisterReceiveCodec(opus_codec_param.pltype,
588 CodecInstToSdp(opus_codec_param)));
tina.legrand@webrtc.orgc4590582012-11-28 12:23:29 +0000589 Run(channel_a2b_, audio_channels, codec_channels);
590 out_file_.Close();
591
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000592#endif
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000593
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000594 // Print out which codecs were tested, and which were not, in the run.
595 if (test_mode_ != 0) {
596 printf("\nThe following codecs was INCLUDED in the test:\n");
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000597 printf(" G.722\n");
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000598 printf(" PCM16\n");
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000599 printf(" G.711\n");
tina.legrand@webrtc.orgc4590582012-11-28 12:23:29 +0000600#ifdef WEBRTC_CODEC_OPUS
601 printf(" Opus\n");
602#endif
Yves Gerey665174f2018-06-19 15:03:05 +0200603 printf(
604 "\nTo complete the test, listen to the %d number of output "
605 "files.\n",
606 test_cntr_);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000607 }
608
609 // Delete the file pointers.
610 delete in_file_stereo_;
611 delete in_file_mono_;
niklase@google.com470e71d2011-07-07 08:21:25 +0000612}
613
614// Register Codec to use in the test
615//
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000616// Input: side - which ACM to use, 'A' or 'B'
617// codec_name - name to use when register the codec
618// sampling_freq_hz - sampling frequency in Herz
619// rate - bitrate in bytes
620// pack_size - packet size in samples
621// channels - number of channels; 1 for mono, 2 for stereo
Yves Gerey665174f2018-06-19 15:03:05 +0200622void TestStereo::RegisterSendCodec(char side,
623 char* codec_name,
624 int32_t sampling_freq_hz,
625 int rate,
626 int pack_size,
Karl Wiberg36b37dc2018-09-24 10:52:32 +0200627 int channels) {
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000628 if (test_mode_ != 0) {
629 // Print out codec and settings
tina.legrand@webrtc.orgba468042012-08-17 10:38:28 +0000630 printf("Codec: %s Freq: %d Rate: %d PackSize: %d\n", codec_name,
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000631 sampling_freq_hz, rate, pack_size);
632 }
633
634 // Store packet size in samples, used to validate the received packet
635 pack_size_samp_ = pack_size;
636
637 // Store the expected packet size in bytes, used to validate the received
638 // packet. Add 0.875 to always round up to a whole byte.
pbos@webrtc.orgd8ca7232014-12-10 11:49:13 +0000639 pack_size_bytes_ = (uint16_t)(static_cast<float>(pack_size * rate) /
640 static_cast<float>(sampling_freq_hz * 8) +
641 0.875);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000642
643 // Set pointer to the ACM where to register the codec
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000644 AudioCodingModule* my_acm = NULL;
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000645 switch (side) {
646 case 'A': {
andrew@webrtc.org89df0922013-09-12 01:27:43 +0000647 my_acm = acm_a_.get();
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000648 break;
niklase@google.com470e71d2011-07-07 08:21:25 +0000649 }
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000650 case 'B': {
andrew@webrtc.org89df0922013-09-12 01:27:43 +0000651 my_acm = acm_b_.get();
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000652 break;
tina.legrand@webrtc.org16b6b902012-04-12 11:02:38 +0000653 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000654 default:
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000655 break;
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000656 }
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000657 ASSERT_TRUE(my_acm != NULL);
niklase@google.com470e71d2011-07-07 08:21:25 +0000658
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000659 CodecInst my_codec_param;
660 // Get all codec parameters before registering
tina.legrand@webrtc.orgee92b662013-08-27 07:33:51 +0000661 EXPECT_GT(AudioCodingModule::Codec(codec_name, &my_codec_param,
Yves Gerey665174f2018-06-19 15:03:05 +0200662 sampling_freq_hz, channels),
663 -1);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000664 my_codec_param.rate = rate;
665 my_codec_param.pacsize = pack_size;
tina.legrand@webrtc.orgee92b662013-08-27 07:33:51 +0000666 EXPECT_EQ(0, my_acm->RegisterSendCodec(my_codec_param));
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000667
668 send_codec_name_ = codec_name;
niklase@google.com470e71d2011-07-07 08:21:25 +0000669}
670
Yves Gerey665174f2018-06-19 15:03:05 +0200671void TestStereo::Run(TestPackStereo* channel,
672 int in_channels,
673 int out_channels,
tina.legrand@webrtc.org16b6b902012-04-12 11:02:38 +0000674 int percent_loss) {
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000675 AudioFrame audio_frame;
niklase@google.com470e71d2011-07-07 08:21:25 +0000676
pbos@webrtc.org0946a562013-04-09 00:28:06 +0000677 int32_t out_freq_hz_b = out_file_.SamplingFrequency();
678 uint16_t rec_size;
679 uint32_t time_stamp_diff;
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000680 channel->reset_payload_size();
681 int error_count = 0;
tina.legrand@webrtc.org65d61c32014-06-05 13:42:51 +0000682 int variable_bytes = 0;
683 int variable_packets = 0;
Henrik Lundin4d682082015-12-10 16:24:39 +0100684 // Set test length to 500 ms (50 blocks of 10 ms each).
685 in_file_mono_->SetNum10MsBlocksToRead(50);
686 in_file_stereo_->SetNum10MsBlocksToRead(50);
687 // Fast-forward 1 second (100 blocks) since the files start with silence.
688 in_file_stereo_->FastForward(100);
689 in_file_mono_->FastForward(100);
niklase@google.com470e71d2011-07-07 08:21:25 +0000690
andresp@webrtc.orgd0b436a2014-01-13 13:15:59 +0000691 while (1) {
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000692 // Simulate packet loss by setting |packet_loss_| to "true" in
693 // |percent_loss| percent of the loops.
694 if (percent_loss > 0) {
695 if (counter_ == floor((100 / percent_loss) + 0.5)) {
696 counter_ = 0;
697 channel->set_lost_packet(true);
698 } else {
699 channel->set_lost_packet(false);
700 }
701 counter_++;
niklase@google.com470e71d2011-07-07 08:21:25 +0000702 }
703
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000704 // Add 10 msec to ACM
705 if (in_channels == 1) {
706 if (in_file_mono_->EndOfFile()) {
707 break;
708 }
709 in_file_mono_->Read10MsData(audio_frame);
710 } else {
711 if (in_file_stereo_->EndOfFile()) {
712 break;
713 }
714 in_file_stereo_->Read10MsData(audio_frame);
715 }
henrik.lundin@webrtc.orgf56c1622015-03-02 12:29:30 +0000716 EXPECT_GE(acm_a_->Add10MsData(audio_frame), 0);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000717
tina.legrand@webrtc.org65d61c32014-06-05 13:42:51 +0000718 // Verify that the received packet size matches the settings.
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000719 rec_size = channel->payload_size();
720 if ((0 < rec_size) & (rec_size < 65535)) {
tina.legrand@webrtc.org65d61c32014-06-05 13:42:51 +0000721 if (strcmp(send_codec_name_, "opus") == 0) {
722 // Opus is a variable rate codec, hence calculate the average packet
723 // size, and later make sure the average is in the right range.
724 variable_bytes += rec_size;
725 variable_packets++;
726 } else {
727 // For fixed rate codecs, check that packet size is correct.
Yves Gerey665174f2018-06-19 15:03:05 +0200728 if ((rec_size != pack_size_bytes_ * out_channels) &&
729 (pack_size_bytes_ < 65535)) {
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000730 error_count++;
731 }
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000732 }
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000733 // Verify that the timestamp is updated with expected length
734 time_stamp_diff = channel->timestamp_diff();
735 if ((counter_ > 10) && (time_stamp_diff != pack_size_samp_)) {
736 error_count++;
737 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000738 }
739
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000740 // Run received side of ACM
henrik.lundind4ccb002016-05-17 12:21:55 -0700741 bool muted;
742 EXPECT_EQ(0, acm_b_->PlayoutData10Ms(out_freq_hz_b, &audio_frame, &muted));
743 ASSERT_FALSE(muted);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000744
745 // Write output speech to file
746 out_file_.Write10MsData(
yujo36b1a5f2017-06-12 12:45:32 -0700747 audio_frame.data(),
andrew@webrtc.org63a50982012-05-02 23:56:37 +0000748 audio_frame.samples_per_channel_ * audio_frame.num_channels_);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000749 }
750
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000751 EXPECT_EQ(0, error_count);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000752
tina.legrand@webrtc.org65d61c32014-06-05 13:42:51 +0000753 // Check that packet size is in the right range for variable rate codecs,
754 // such as Opus.
755 if (variable_packets > 0) {
756 variable_bytes /= variable_packets;
Henrik Lundin4d682082015-12-10 16:24:39 +0100757 EXPECT_NEAR(variable_bytes, pack_size_bytes_, 18);
tina.legrand@webrtc.org65d61c32014-06-05 13:42:51 +0000758 }
759
andresp@webrtc.orgd0b436a2014-01-13 13:15:59 +0000760 if (in_file_mono_->EndOfFile()) {
761 in_file_mono_->Rewind();
762 }
763 if (in_file_stereo_->EndOfFile()) {
764 in_file_stereo_->Rewind();
765 }
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000766 // Reset in case we ended with a lost packet
767 channel->set_lost_packet(false);
niklase@google.com470e71d2011-07-07 08:21:25 +0000768}
769
pbos@webrtc.org0946a562013-04-09 00:28:06 +0000770void TestStereo::OpenOutFile(int16_t test_number) {
tina.legrand@webrtc.orgba468042012-08-17 10:38:28 +0000771 std::string file_name;
Jonas Olsson366a50c2018-09-06 13:41:30 +0200772 rtc::StringBuilder file_stream;
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000773 file_stream << webrtc::test::OutputPath() << "teststereo_out_" << test_number
Yves Gerey665174f2018-06-19 15:03:05 +0200774 << ".pcm";
tina.legrand@webrtc.orgba468042012-08-17 10:38:28 +0000775 file_name = file_stream.str();
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000776 out_file_.Open(file_name, 32000, "wb");
niklase@google.com470e71d2011-07-07 08:21:25 +0000777}
778
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000779void TestStereo::DisplaySendReceiveCodec() {
kwiberg1fd4a4a2015-11-03 11:20:50 -0800780 auto send_codec = acm_a_->SendCodec();
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000781 if (test_mode_ != 0) {
kwiberg1fd4a4a2015-11-03 11:20:50 -0800782 ASSERT_TRUE(send_codec);
783 printf("%s -> ", send_codec->plname);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000784 }
kwiberg1fd4a4a2015-11-03 11:20:50 -0800785 CodecInst receive_codec;
786 acm_b_->ReceiveCodec(&receive_codec);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000787 if (test_mode_ != 0) {
kwiberg1fd4a4a2015-11-03 11:20:50 -0800788 printf("%s\n", receive_codec.plname);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000789 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000790}
791
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000792} // namespace webrtc