blob: 42db62d518fd306445f6ef5e708a5c0bbecf4447 [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"
Karl Wibergd363db12018-09-24 14:45:24 +020018#include "api/audio_codecs/builtin_audio_encoder_factory.h"
Mirko Bonadei71207422017-09-15 13:58:09 +020019#include "common_types.h" // NOLINT(build/include)
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020020#include "modules/audio_coding/codecs/audio_format_conversion.h"
21#include "modules/audio_coding/include/audio_coding_module_typedefs.h"
22#include "modules/audio_coding/test/utility.h"
Jonas Olsson366a50c2018-09-06 13:41:30 +020023#include "rtc_base/strings/string_builder.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020024#include "test/gtest.h"
25#include "test/testsupport/fileutils.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000026
tina.legrand@webrtc.org554ae1a2011-12-16 10:09:04 +000027namespace webrtc {
niklase@google.com470e71d2011-07-07 08:21:25 +000028
29// Class for simulating packet handling
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +000030TestPackStereo::TestPackStereo()
31 : receiver_acm_(NULL),
32 seq_no_(0),
33 timestamp_diff_(0),
34 last_in_timestamp_(0),
35 total_bytes_(0),
36 payload_size_(0),
37 codec_mode_(kNotSet),
Yves Gerey665174f2018-06-19 15:03:05 +020038 lost_packet_(false) {}
niklase@google.com470e71d2011-07-07 08:21:25 +000039
Yves Gerey665174f2018-06-19 15:03:05 +020040TestPackStereo::~TestPackStereo() {}
niklase@google.com470e71d2011-07-07 08:21:25 +000041
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +000042void TestPackStereo::RegisterReceiverACM(AudioCodingModule* acm) {
43 receiver_acm_ = acm;
44 return;
45}
niklase@google.com470e71d2011-07-07 08:21:25 +000046
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000047int32_t TestPackStereo::SendData(const FrameType frame_type,
48 const uint8_t payload_type,
49 const uint32_t timestamp,
50 const uint8_t* payload_data,
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +000051 const size_t payload_size,
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000052 const RTPFragmentationHeader* fragmentation) {
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +000053 WebRtcRTPHeader rtp_info;
pbos@webrtc.org0946a562013-04-09 00:28:06 +000054 int32_t status = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +000055
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +000056 rtp_info.header.markerBit = false;
57 rtp_info.header.ssrc = 0;
58 rtp_info.header.sequenceNumber = seq_no_++;
59 rtp_info.header.payloadType = payload_type;
60 rtp_info.header.timestamp = timestamp;
pbos22993e12015-10-19 02:39:06 -070061 if (frame_type == kEmptyFrame) {
tina.legrand@webrtc.org16b6b902012-04-12 11:02:38 +000062 // Skip this frame
63 return 0;
64 }
niklase@google.com470e71d2011-07-07 08:21:25 +000065
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +000066 if (lost_packet_ == false) {
Yves Gerey665174f2018-06-19 15:03:05 +020067 status =
68 receiver_acm_->IncomingPacket(payload_data, payload_size, rtp_info);
niklase@google.com470e71d2011-07-07 08:21:25 +000069
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +000070 if (frame_type != kAudioFrameCN) {
henrike@webrtc.org6ac22e62014-08-11 21:06:30 +000071 payload_size_ = static_cast<int>(payload_size);
niklase@google.com470e71d2011-07-07 08:21:25 +000072 } else {
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +000073 payload_size_ = -1;
niklase@google.com470e71d2011-07-07 08:21:25 +000074 }
tina.legrand@webrtc.org16b6b902012-04-12 11:02:38 +000075
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +000076 timestamp_diff_ = timestamp - last_in_timestamp_;
77 last_in_timestamp_ = timestamp;
78 total_bytes_ += payload_size;
tina.legrand@webrtc.org16b6b902012-04-12 11:02:38 +000079 }
80 return status;
niklase@google.com470e71d2011-07-07 08:21:25 +000081}
82
pbos@webrtc.org0946a562013-04-09 00:28:06 +000083uint16_t TestPackStereo::payload_size() {
henrike@webrtc.org6ac22e62014-08-11 21:06:30 +000084 return static_cast<uint16_t>(payload_size_);
niklase@google.com470e71d2011-07-07 08:21:25 +000085}
86
pbos@webrtc.org0946a562013-04-09 00:28:06 +000087uint32_t TestPackStereo::timestamp_diff() {
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +000088 return timestamp_diff_;
niklase@google.com470e71d2011-07-07 08:21:25 +000089}
90
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +000091void TestPackStereo::reset_payload_size() {
92 payload_size_ = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +000093}
94
tina.legrand@webrtc.org16b6b902012-04-12 11:02:38 +000095void TestPackStereo::set_codec_mode(enum StereoMonoMode mode) {
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +000096 codec_mode_ = mode;
tina.legrand@webrtc.org16b6b902012-04-12 11:02:38 +000097}
98
99void TestPackStereo::set_lost_packet(bool lost) {
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000100 lost_packet_ = lost;
niklase@google.com470e71d2011-07-07 08:21:25 +0000101}
102
henrik.lundin@webrtc.orgadaf8092014-04-17 08:29:10 +0000103TestStereo::TestStereo(int test_mode)
Karl Wiberg5817d3d2018-04-06 10:06:42 +0200104 : acm_a_(AudioCodingModule::Create(
105 AudioCodingModule::Config(CreateBuiltinAudioDecoderFactory()))),
106 acm_b_(AudioCodingModule::Create(
107 AudioCodingModule::Config(CreateBuiltinAudioDecoderFactory()))),
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000108 channel_a2b_(NULL),
109 test_cntr_(0),
110 pack_size_samp_(0),
111 pack_size_bytes_(0),
Karl Wiberg36b37dc2018-09-24 10:52:32 +0200112 counter_(0) {
tina.legrand@webrtc.org45175852012-06-01 09:27:35 +0000113 // test_mode = 0 for silent test (auto test)
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000114 test_mode_ = test_mode;
niklase@google.com470e71d2011-07-07 08:21:25 +0000115}
116
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000117TestStereo::~TestStereo() {
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000118 if (channel_a2b_ != NULL) {
119 delete channel_a2b_;
120 channel_a2b_ = NULL;
121 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000122}
123
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000124void TestStereo::Perform() {
pbos@webrtc.org0946a562013-04-09 00:28:06 +0000125 uint16_t frequency_hz;
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000126 int audio_channels;
127 int codec_channels;
niklase@google.com470e71d2011-07-07 08:21:25 +0000128
tina.legrand@webrtc.org45175852012-06-01 09:27:35 +0000129 // Open both mono and stereo test files in 32 kHz.
Yves Gerey665174f2018-06-19 15:03:05 +0200130 const std::string file_name_stereo =
131 webrtc::test::ResourcePath("audio_coding/teststereo32kHz", "pcm");
132 const std::string file_name_mono =
133 webrtc::test::ResourcePath("audio_coding/testfile32kHz", "pcm");
tina.legrand@webrtc.org45175852012-06-01 09:27:35 +0000134 frequency_hz = 32000;
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000135 in_file_stereo_ = new PCMFile();
136 in_file_mono_ = new PCMFile();
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000137 in_file_stereo_->Open(file_name_stereo, frequency_hz, "rb");
138 in_file_stereo_->ReadStereo(true);
139 in_file_mono_->Open(file_name_mono, frequency_hz, "rb");
140 in_file_mono_->ReadStereo(false);
141
tina.legrand@webrtc.org45175852012-06-01 09:27:35 +0000142 // Create and initialize two ACMs, one for each side of a one-to-one call.
andrew@webrtc.org89df0922013-09-12 01:27:43 +0000143 ASSERT_TRUE((acm_a_.get() != NULL) && (acm_b_.get() != NULL));
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000144 EXPECT_EQ(0, acm_a_->InitializeReceiver());
145 EXPECT_EQ(0, acm_b_->InitializeReceiver());
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000146
tina.legrand@webrtc.org45175852012-06-01 09:27:35 +0000147 // Register all available codes as receiving codecs.
pbos@webrtc.org0946a562013-04-09 00:28:06 +0000148 uint8_t num_encoders = acm_a_->NumberOfCodecs();
tina.legrand@webrtc.org45175852012-06-01 09:27:35 +0000149 CodecInst my_codec_param;
pbos@webrtc.org0946a562013-04-09 00:28:06 +0000150 for (uint8_t n = 0; n < num_encoders; n++) {
tina.legrand@webrtc.org7a7a0082013-02-21 10:27:48 +0000151 EXPECT_EQ(0, acm_b_->Codec(n, &my_codec_param));
kwibergda2bf4e2016-10-24 13:47:09 -0700152 EXPECT_EQ(true, acm_b_->RegisterReceiveCodec(
153 my_codec_param.pltype, CodecInstToSdp(my_codec_param)));
tina.legrand@webrtc.org45175852012-06-01 09:27:35 +0000154 }
155
156 // Test that unregister all receive codecs works.
pbos@webrtc.org0946a562013-04-09 00:28:06 +0000157 for (uint8_t n = 0; n < num_encoders; n++) {
tina.legrand@webrtc.org7a7a0082013-02-21 10:27:48 +0000158 EXPECT_EQ(0, acm_b_->Codec(n, &my_codec_param));
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000159 EXPECT_EQ(0, acm_b_->UnregisterReceiveCodec(my_codec_param.pltype));
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000160 }
tina.legrand@webrtc.orgae1c4542012-03-12 08:41:30 +0000161
tina.legrand@webrtc.org45175852012-06-01 09:27:35 +0000162 // Register all available codes as receiving codecs once more.
pbos@webrtc.org0946a562013-04-09 00:28:06 +0000163 for (uint8_t n = 0; n < num_encoders; n++) {
tina.legrand@webrtc.org7a7a0082013-02-21 10:27:48 +0000164 EXPECT_EQ(0, acm_b_->Codec(n, &my_codec_param));
kwibergda2bf4e2016-10-24 13:47:09 -0700165 EXPECT_EQ(true, acm_b_->RegisterReceiveCodec(
166 my_codec_param.pltype, CodecInstToSdp(my_codec_param)));
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000167 }
tina.legrand@webrtc.orgae1c4542012-03-12 08:41:30 +0000168
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000169 // Create and connect the channel.
170 channel_a2b_ = new TestPackStereo;
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000171 EXPECT_EQ(0, acm_a_->RegisterTransportCallback(channel_a2b_));
andrew@webrtc.org89df0922013-09-12 01:27:43 +0000172 channel_a2b_->RegisterReceiverACM(acm_b_.get());
tina.legrand@webrtc.orgdf697752012-02-08 10:22:21 +0000173
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000174 char codec_pcma_temp[] = "PCMA";
Karl Wiberg36b37dc2018-09-24 10:52:32 +0200175 RegisterSendCodec('A', codec_pcma_temp, 8000, 64000, 80, 2);
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000176 if (test_mode_ != 0) {
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000177 printf("\n");
178 }
179
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000180 //
181 // Test Stereo-To-Stereo for all codecs.
182 //
183 audio_channels = 2;
184 codec_channels = 2;
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000185
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000186 // All codecs are tested for all allowed sampling frequencies, rates and
187 // packet sizes.
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000188 if (test_mode_ != 0) {
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000189 printf("===========================================================\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000190 printf("Test number: %d\n", test_cntr_ + 1);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000191 printf("Test type: Stereo-to-stereo\n");
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000192 }
193 channel_a2b_->set_codec_mode(kStereo);
194 test_cntr_++;
195 OpenOutFile(test_cntr_);
196 char codec_g722[] = "G722";
Karl Wiberg36b37dc2018-09-24 10:52:32 +0200197 RegisterSendCodec('A', codec_g722, 16000, 64000, 160, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000198 Run(channel_a2b_, audio_channels, codec_channels);
Karl Wiberg36b37dc2018-09-24 10:52:32 +0200199 RegisterSendCodec('A', codec_g722, 16000, 64000, 320, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000200 Run(channel_a2b_, audio_channels, codec_channels);
Karl Wiberg36b37dc2018-09-24 10:52:32 +0200201 RegisterSendCodec('A', codec_g722, 16000, 64000, 480, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000202 Run(channel_a2b_, audio_channels, codec_channels);
Karl Wiberg36b37dc2018-09-24 10:52:32 +0200203 RegisterSendCodec('A', codec_g722, 16000, 64000, 640, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000204 Run(channel_a2b_, audio_channels, codec_channels);
Karl Wiberg36b37dc2018-09-24 10:52:32 +0200205 RegisterSendCodec('A', codec_g722, 16000, 64000, 800, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000206 Run(channel_a2b_, audio_channels, codec_channels);
Karl Wiberg36b37dc2018-09-24 10:52:32 +0200207 RegisterSendCodec('A', codec_g722, 16000, 64000, 960, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000208 Run(channel_a2b_, audio_channels, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000209 out_file_.Close();
Karl Wibergeb254b42017-11-01 15:08:12 +0100210
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000211 if (test_mode_ != 0) {
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000212 printf("===========================================================\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000213 printf("Test number: %d\n", test_cntr_ + 1);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000214 printf("Test type: Stereo-to-stereo\n");
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000215 }
216 channel_a2b_->set_codec_mode(kStereo);
217 test_cntr_++;
218 OpenOutFile(test_cntr_);
219 char codec_l16[] = "L16";
Karl Wiberg36b37dc2018-09-24 10:52:32 +0200220 RegisterSendCodec('A', codec_l16, 8000, 128000, 80, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000221 Run(channel_a2b_, audio_channels, codec_channels);
Karl Wiberg36b37dc2018-09-24 10:52:32 +0200222 RegisterSendCodec('A', codec_l16, 8000, 128000, 160, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000223 Run(channel_a2b_, audio_channels, codec_channels);
Karl Wiberg36b37dc2018-09-24 10:52:32 +0200224 RegisterSendCodec('A', codec_l16, 8000, 128000, 240, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000225 Run(channel_a2b_, audio_channels, codec_channels);
Karl Wiberg36b37dc2018-09-24 10:52:32 +0200226 RegisterSendCodec('A', codec_l16, 8000, 128000, 320, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000227 Run(channel_a2b_, audio_channels, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000228 out_file_.Close();
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000229
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000230 if (test_mode_ != 0) {
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000231 printf("===========================================================\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000232 printf("Test number: %d\n", test_cntr_ + 1);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000233 printf("Test type: Stereo-to-stereo\n");
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000234 }
235 test_cntr_++;
236 OpenOutFile(test_cntr_);
Karl Wiberg36b37dc2018-09-24 10:52:32 +0200237 RegisterSendCodec('A', codec_l16, 16000, 256000, 160, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000238 Run(channel_a2b_, audio_channels, codec_channels);
Karl Wiberg36b37dc2018-09-24 10:52:32 +0200239 RegisterSendCodec('A', codec_l16, 16000, 256000, 320, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000240 Run(channel_a2b_, audio_channels, codec_channels);
Karl Wiberg36b37dc2018-09-24 10:52:32 +0200241 RegisterSendCodec('A', codec_l16, 16000, 256000, 480, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000242 Run(channel_a2b_, audio_channels, codec_channels);
Karl Wiberg36b37dc2018-09-24 10:52:32 +0200243 RegisterSendCodec('A', codec_l16, 16000, 256000, 640, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000244 Run(channel_a2b_, audio_channels, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000245 out_file_.Close();
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000246
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000247 if (test_mode_ != 0) {
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000248 printf("===========================================================\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000249 printf("Test number: %d\n", test_cntr_ + 1);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000250 printf("Test type: Stereo-to-stereo\n");
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000251 }
252 test_cntr_++;
253 OpenOutFile(test_cntr_);
Karl Wiberg36b37dc2018-09-24 10:52:32 +0200254 RegisterSendCodec('A', codec_l16, 32000, 512000, 320, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000255 Run(channel_a2b_, audio_channels, codec_channels);
Karl Wiberg36b37dc2018-09-24 10:52:32 +0200256 RegisterSendCodec('A', codec_l16, 32000, 512000, 640, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000257 Run(channel_a2b_, audio_channels, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000258 out_file_.Close();
niklase@google.com470e71d2011-07-07 08:21:25 +0000259#ifdef PCMA_AND_PCMU
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000260 if (test_mode_ != 0) {
261 printf("===========================================================\n");
262 printf("Test number: %d\n", test_cntr_ + 1);
263 printf("Test type: Stereo-to-stereo\n");
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000264 }
265 channel_a2b_->set_codec_mode(kStereo);
266 audio_channels = 2;
267 codec_channels = 2;
268 test_cntr_++;
269 OpenOutFile(test_cntr_);
270 char codec_pcma[] = "PCMA";
Karl Wiberg36b37dc2018-09-24 10:52:32 +0200271 RegisterSendCodec('A', codec_pcma, 8000, 64000, 80, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000272 Run(channel_a2b_, audio_channels, codec_channels);
Karl Wiberg36b37dc2018-09-24 10:52:32 +0200273 RegisterSendCodec('A', codec_pcma, 8000, 64000, 160, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000274 Run(channel_a2b_, audio_channels, codec_channels);
Karl Wiberg36b37dc2018-09-24 10:52:32 +0200275 RegisterSendCodec('A', codec_pcma, 8000, 64000, 240, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000276 Run(channel_a2b_, audio_channels, codec_channels);
Karl Wiberg36b37dc2018-09-24 10:52:32 +0200277 RegisterSendCodec('A', codec_pcma, 8000, 64000, 320, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000278 Run(channel_a2b_, audio_channels, codec_channels);
Karl Wiberg36b37dc2018-09-24 10:52:32 +0200279 RegisterSendCodec('A', codec_pcma, 8000, 64000, 400, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000280 Run(channel_a2b_, audio_channels, codec_channels);
Karl Wiberg36b37dc2018-09-24 10:52:32 +0200281 RegisterSendCodec('A', codec_pcma, 8000, 64000, 480, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000282 Run(channel_a2b_, audio_channels, codec_channels);
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000283
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000284 out_file_.Close();
285 if (test_mode_ != 0) {
286 printf("===========================================================\n");
287 printf("Test number: %d\n", test_cntr_ + 1);
288 printf("Test type: Stereo-to-stereo\n");
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000289 }
290 test_cntr_++;
291 OpenOutFile(test_cntr_);
292 char codec_pcmu[] = "PCMU";
Karl Wiberg36b37dc2018-09-24 10:52:32 +0200293 RegisterSendCodec('A', codec_pcmu, 8000, 64000, 80, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000294 Run(channel_a2b_, audio_channels, codec_channels);
Karl Wiberg36b37dc2018-09-24 10:52:32 +0200295 RegisterSendCodec('A', codec_pcmu, 8000, 64000, 160, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000296 Run(channel_a2b_, audio_channels, codec_channels);
Karl Wiberg36b37dc2018-09-24 10:52:32 +0200297 RegisterSendCodec('A', codec_pcmu, 8000, 64000, 240, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000298 Run(channel_a2b_, audio_channels, codec_channels);
Karl Wiberg36b37dc2018-09-24 10:52:32 +0200299 RegisterSendCodec('A', codec_pcmu, 8000, 64000, 320, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000300 Run(channel_a2b_, audio_channels, codec_channels);
Karl Wiberg36b37dc2018-09-24 10:52:32 +0200301 RegisterSendCodec('A', codec_pcmu, 8000, 64000, 400, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000302 Run(channel_a2b_, audio_channels, codec_channels);
Karl Wiberg36b37dc2018-09-24 10:52:32 +0200303 RegisterSendCodec('A', codec_pcmu, 8000, 64000, 480, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000304 Run(channel_a2b_, audio_channels, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000305 out_file_.Close();
niklase@google.com470e71d2011-07-07 08:21:25 +0000306#endif
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000307#ifdef WEBRTC_CODEC_OPUS
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000308 if (test_mode_ != 0) {
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000309 printf("===========================================================\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000310 printf("Test number: %d\n", test_cntr_ + 1);
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000311 printf("Test type: Stereo-to-stereo\n");
312 }
313 channel_a2b_->set_codec_mode(kStereo);
314 audio_channels = 2;
315 codec_channels = 2;
316 test_cntr_++;
317 OpenOutFile(test_cntr_);
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000318
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000319 char codec_opus[] = "opus";
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000320 // Run Opus with 10 ms frame size.
Karl Wiberg36b37dc2018-09-24 10:52:32 +0200321 RegisterSendCodec('A', codec_opus, 48000, 64000, 480, codec_channels);
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000322 Run(channel_a2b_, audio_channels, codec_channels);
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000323 // Run Opus with 20 ms frame size.
Karl Wiberg36b37dc2018-09-24 10:52:32 +0200324 RegisterSendCodec('A', codec_opus, 48000, 64000, 480 * 2, codec_channels);
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000325 Run(channel_a2b_, audio_channels, codec_channels);
326 // Run Opus with 40 ms frame size.
Karl Wiberg36b37dc2018-09-24 10:52:32 +0200327 RegisterSendCodec('A', codec_opus, 48000, 64000, 480 * 4, codec_channels);
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000328 Run(channel_a2b_, audio_channels, codec_channels);
329 // Run Opus with 60 ms frame size.
Karl Wiberg36b37dc2018-09-24 10:52:32 +0200330 RegisterSendCodec('A', codec_opus, 48000, 64000, 480 * 6, codec_channels);
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000331 Run(channel_a2b_, audio_channels, codec_channels);
332 // Run Opus with 20 ms frame size and different bitrates.
Karl Wiberg36b37dc2018-09-24 10:52:32 +0200333 RegisterSendCodec('A', codec_opus, 48000, 40000, 960, codec_channels);
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000334 Run(channel_a2b_, audio_channels, codec_channels);
Karl Wiberg36b37dc2018-09-24 10:52:32 +0200335 RegisterSendCodec('A', codec_opus, 48000, 510000, 960, codec_channels);
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000336 Run(channel_a2b_, audio_channels, codec_channels);
337 out_file_.Close();
338#endif
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000339 //
340 // Test Mono-To-Stereo for all codecs.
341 //
342 audio_channels = 1;
343 codec_channels = 2;
niklase@google.com470e71d2011-07-07 08:21:25 +0000344
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000345 if (test_mode_ != 0) {
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000346 printf("===============================================================\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000347 printf("Test number: %d\n", test_cntr_ + 1);
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000348 printf("Test type: Mono-to-stereo\n");
349 }
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000350 test_cntr_++;
351 channel_a2b_->set_codec_mode(kStereo);
352 OpenOutFile(test_cntr_);
Karl Wiberg36b37dc2018-09-24 10:52:32 +0200353 RegisterSendCodec('A', codec_g722, 16000, 64000, 160, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000354 Run(channel_a2b_, audio_channels, codec_channels);
355 out_file_.Close();
Karl Wibergeb254b42017-11-01 15:08:12 +0100356
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000357 if (test_mode_ != 0) {
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000358 printf("===============================================================\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000359 printf("Test number: %d\n", test_cntr_ + 1);
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000360 printf("Test type: Mono-to-stereo\n");
361 }
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000362 test_cntr_++;
363 channel_a2b_->set_codec_mode(kStereo);
364 OpenOutFile(test_cntr_);
Karl Wiberg36b37dc2018-09-24 10:52:32 +0200365 RegisterSendCodec('A', codec_l16, 8000, 128000, 80, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000366 Run(channel_a2b_, audio_channels, codec_channels);
367 out_file_.Close();
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000368 if (test_mode_ != 0) {
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000369 printf("===============================================================\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000370 printf("Test number: %d\n", test_cntr_ + 1);
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000371 printf("Test type: Mono-to-stereo\n");
372 }
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000373 test_cntr_++;
374 OpenOutFile(test_cntr_);
Karl Wiberg36b37dc2018-09-24 10:52:32 +0200375 RegisterSendCodec('A', codec_l16, 16000, 256000, 160, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000376 Run(channel_a2b_, audio_channels, codec_channels);
377 out_file_.Close();
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000378 if (test_mode_ != 0) {
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000379 printf("===============================================================\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000380 printf("Test number: %d\n", test_cntr_ + 1);
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000381 printf("Test type: Mono-to-stereo\n");
382 }
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000383 test_cntr_++;
384 OpenOutFile(test_cntr_);
Karl Wiberg36b37dc2018-09-24 10:52:32 +0200385 RegisterSendCodec('A', codec_l16, 32000, 512000, 320, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000386 Run(channel_a2b_, audio_channels, codec_channels);
387 out_file_.Close();
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000388#ifdef PCMA_AND_PCMU
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000389 if (test_mode_ != 0) {
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000390 printf("===============================================================\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000391 printf("Test number: %d\n", test_cntr_ + 1);
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000392 printf("Test type: Mono-to-stereo\n");
393 }
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000394 test_cntr_++;
395 channel_a2b_->set_codec_mode(kStereo);
396 OpenOutFile(test_cntr_);
Karl Wiberg36b37dc2018-09-24 10:52:32 +0200397 RegisterSendCodec('A', codec_pcmu, 8000, 64000, 80, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000398 Run(channel_a2b_, audio_channels, codec_channels);
Karl Wiberg36b37dc2018-09-24 10:52:32 +0200399 RegisterSendCodec('A', codec_pcma, 8000, 64000, 80, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000400 Run(channel_a2b_, audio_channels, codec_channels);
401 out_file_.Close();
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000402#endif
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000403#ifdef WEBRTC_CODEC_OPUS
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000404 if (test_mode_ != 0) {
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000405 printf("===============================================================\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000406 printf("Test number: %d\n", test_cntr_ + 1);
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000407 printf("Test type: Mono-to-stereo\n");
408 }
tina.legrand@webrtc.orgc4590582012-11-28 12:23:29 +0000409
410 // Keep encode and decode in stereo.
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000411 test_cntr_++;
412 channel_a2b_->set_codec_mode(kStereo);
413 OpenOutFile(test_cntr_);
Karl Wiberg36b37dc2018-09-24 10:52:32 +0200414 RegisterSendCodec('A', codec_opus, 48000, 64000, 960, codec_channels);
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000415 Run(channel_a2b_, audio_channels, codec_channels);
tina.legrand@webrtc.orgc4590582012-11-28 12:23:29 +0000416
417 // Encode in mono, decode in stereo mode.
Karl Wiberg36b37dc2018-09-24 10:52:32 +0200418 RegisterSendCodec('A', codec_opus, 48000, 64000, 960, 1);
tina.legrand@webrtc.orgc4590582012-11-28 12:23:29 +0000419 Run(channel_a2b_, audio_channels, codec_channels);
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000420 out_file_.Close();
421#endif
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000422
423 //
424 // Test Stereo-To-Mono for all codecs.
425 //
426 audio_channels = 2;
427 codec_channels = 1;
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000428 channel_a2b_->set_codec_mode(kMono);
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000429
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000430 // Run stereo audio and mono codec.
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000431 if (test_mode_ != 0) {
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000432 printf("===============================================================\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000433 printf("Test number: %d\n", test_cntr_ + 1);
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000434 printf("Test type: Stereo-to-mono\n");
435 }
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000436 test_cntr_++;
437 OpenOutFile(test_cntr_);
Karl Wiberg36b37dc2018-09-24 10:52:32 +0200438 RegisterSendCodec('A', codec_g722, 16000, 64000, 160, codec_channels);
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000439
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000440 Run(channel_a2b_, audio_channels, codec_channels);
441 out_file_.Close();
Karl Wibergeb254b42017-11-01 15:08:12 +0100442
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000443 if (test_mode_ != 0) {
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000444 printf("===============================================================\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000445 printf("Test number: %d\n", test_cntr_ + 1);
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000446 printf("Test type: Stereo-to-mono\n");
447 }
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000448 test_cntr_++;
449 OpenOutFile(test_cntr_);
Karl Wiberg36b37dc2018-09-24 10:52:32 +0200450 RegisterSendCodec('A', codec_l16, 8000, 128000, 80, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000451 Run(channel_a2b_, audio_channels, codec_channels);
452 out_file_.Close();
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");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000457 }
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_l16, 16000, 256000, 160, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000461 Run(channel_a2b_, audio_channels, codec_channels);
462 out_file_.Close();
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000463 if (test_mode_ != 0) {
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000464 printf("==============================================================\n");
465 printf("Test number: %d\n", test_cntr_ + 1);
466 printf("Test type: Stereo-to-mono\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000467 }
468 test_cntr_++;
469 OpenOutFile(test_cntr_);
Karl Wiberg36b37dc2018-09-24 10:52:32 +0200470 RegisterSendCodec('A', codec_l16, 32000, 512000, 320, codec_channels);
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000471 Run(channel_a2b_, audio_channels, codec_channels);
472 out_file_.Close();
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000473#ifdef PCMA_AND_PCMU
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000474 if (test_mode_ != 0) {
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000475 printf("===============================================================\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000476 printf("Test number: %d\n", test_cntr_ + 1);
tina.legrand@webrtc.orgdf697752012-02-08 10:22:21 +0000477 printf("Test type: Stereo-to-mono\n");
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000478 }
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000479 test_cntr_++;
480 OpenOutFile(test_cntr_);
Karl Wiberg36b37dc2018-09-24 10:52:32 +0200481 RegisterSendCodec('A', codec_pcmu, 8000, 64000, 80, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000482 Run(channel_a2b_, audio_channels, codec_channels);
Karl Wiberg36b37dc2018-09-24 10:52:32 +0200483 RegisterSendCodec('A', codec_pcma, 8000, 64000, 80, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000484 Run(channel_a2b_, audio_channels, codec_channels);
485 out_file_.Close();
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000486#endif
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000487#ifdef WEBRTC_CODEC_OPUS
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000488 if (test_mode_ != 0) {
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000489 printf("===============================================================\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000490 printf("Test number: %d\n", test_cntr_ + 1);
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000491 printf("Test type: Stereo-to-mono\n");
492 }
493 test_cntr_++;
494 OpenOutFile(test_cntr_);
tina.legrand@webrtc.orgc4590582012-11-28 12:23:29 +0000495 // Encode and decode in mono.
Karl Wiberg36b37dc2018-09-24 10:52:32 +0200496 RegisterSendCodec('A', codec_opus, 48000, 32000, 960, codec_channels);
tina.legrand@webrtc.orgc4590582012-11-28 12:23:29 +0000497 CodecInst opus_codec_param;
pbos@webrtc.org0946a562013-04-09 00:28:06 +0000498 for (uint8_t n = 0; n < num_encoders; n++) {
tina.legrand@webrtc.org7a7a0082013-02-21 10:27:48 +0000499 EXPECT_EQ(0, acm_b_->Codec(n, &opus_codec_param));
tina.legrand@webrtc.orgc4590582012-11-28 12:23:29 +0000500 if (!strcmp(opus_codec_param.plname, "opus")) {
501 opus_codec_param.channels = 1;
kwibergda2bf4e2016-10-24 13:47:09 -0700502 EXPECT_EQ(true,
503 acm_b_->RegisterReceiveCodec(opus_codec_param.pltype,
504 CodecInstToSdp(opus_codec_param)));
tina.legrand@webrtc.orgc4590582012-11-28 12:23:29 +0000505 break;
506 }
507 }
508 Run(channel_a2b_, audio_channels, codec_channels);
509
510 // Encode in stereo, decode in mono.
Karl Wiberg36b37dc2018-09-24 10:52:32 +0200511 RegisterSendCodec('A', codec_opus, 48000, 32000, 960, 2);
tina.legrand@webrtc.orgc4590582012-11-28 12:23:29 +0000512 Run(channel_a2b_, audio_channels, codec_channels);
513
514 out_file_.Close();
515
516 // Test switching between decoding mono and stereo for Opus.
517
518 // Decode in mono.
519 test_cntr_++;
520 OpenOutFile(test_cntr_);
521 if (test_mode_ != 0) {
522 // Print out codec and settings
Yves Gerey665174f2018-06-19 15:03:05 +0200523 printf(
524 "Test number: %d\nCodec: Opus Freq: 48000 Rate :32000 PackSize: 960"
525 " Decode: mono\n",
526 test_cntr_);
tina.legrand@webrtc.orgc4590582012-11-28 12:23:29 +0000527 }
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000528 Run(channel_a2b_, audio_channels, codec_channels);
529 out_file_.Close();
tina.legrand@webrtc.orgc4590582012-11-28 12:23:29 +0000530 // Decode in stereo.
531 test_cntr_++;
532 OpenOutFile(test_cntr_);
533 if (test_mode_ != 0) {
534 // Print out codec and settings
Yves Gerey665174f2018-06-19 15:03:05 +0200535 printf(
536 "Test number: %d\nCodec: Opus Freq: 48000 Rate :32000 PackSize: 960"
537 " Decode: stereo\n",
538 test_cntr_);
tina.legrand@webrtc.orgc4590582012-11-28 12:23:29 +0000539 }
540 opus_codec_param.channels = 2;
kwibergda2bf4e2016-10-24 13:47:09 -0700541 EXPECT_EQ(true,
542 acm_b_->RegisterReceiveCodec(opus_codec_param.pltype,
543 CodecInstToSdp(opus_codec_param)));
tina.legrand@webrtc.orgc4590582012-11-28 12:23:29 +0000544 Run(channel_a2b_, audio_channels, 2);
545 out_file_.Close();
546 // Decode in mono.
547 test_cntr_++;
548 OpenOutFile(test_cntr_);
549 if (test_mode_ != 0) {
550 // Print out codec and settings
Yves Gerey665174f2018-06-19 15:03:05 +0200551 printf(
552 "Test number: %d\nCodec: Opus Freq: 48000 Rate :32000 PackSize: 960"
553 " Decode: mono\n",
554 test_cntr_);
tina.legrand@webrtc.orgc4590582012-11-28 12:23:29 +0000555 }
556 opus_codec_param.channels = 1;
kwibergda2bf4e2016-10-24 13:47:09 -0700557 EXPECT_EQ(true,
558 acm_b_->RegisterReceiveCodec(opus_codec_param.pltype,
559 CodecInstToSdp(opus_codec_param)));
tina.legrand@webrtc.orgc4590582012-11-28 12:23:29 +0000560 Run(channel_a2b_, audio_channels, codec_channels);
561 out_file_.Close();
562
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000563#endif
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000564
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000565 // Print out which codecs were tested, and which were not, in the run.
566 if (test_mode_ != 0) {
567 printf("\nThe following codecs was INCLUDED in the test:\n");
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000568 printf(" G.722\n");
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000569 printf(" PCM16\n");
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000570 printf(" G.711\n");
tina.legrand@webrtc.orgc4590582012-11-28 12:23:29 +0000571#ifdef WEBRTC_CODEC_OPUS
572 printf(" Opus\n");
573#endif
Yves Gerey665174f2018-06-19 15:03:05 +0200574 printf(
575 "\nTo complete the test, listen to the %d number of output "
576 "files.\n",
577 test_cntr_);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000578 }
579
580 // Delete the file pointers.
581 delete in_file_stereo_;
582 delete in_file_mono_;
niklase@google.com470e71d2011-07-07 08:21:25 +0000583}
584
585// Register Codec to use in the test
586//
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000587// Input: side - which ACM to use, 'A' or 'B'
588// codec_name - name to use when register the codec
589// sampling_freq_hz - sampling frequency in Herz
590// rate - bitrate in bytes
591// pack_size - packet size in samples
592// channels - number of channels; 1 for mono, 2 for stereo
Yves Gerey665174f2018-06-19 15:03:05 +0200593void TestStereo::RegisterSendCodec(char side,
594 char* codec_name,
595 int32_t sampling_freq_hz,
596 int rate,
597 int pack_size,
Karl Wiberg36b37dc2018-09-24 10:52:32 +0200598 int channels) {
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000599 if (test_mode_ != 0) {
600 // Print out codec and settings
tina.legrand@webrtc.orgba468042012-08-17 10:38:28 +0000601 printf("Codec: %s Freq: %d Rate: %d PackSize: %d\n", codec_name,
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000602 sampling_freq_hz, rate, pack_size);
603 }
604
605 // Store packet size in samples, used to validate the received packet
606 pack_size_samp_ = pack_size;
607
608 // Store the expected packet size in bytes, used to validate the received
609 // packet. Add 0.875 to always round up to a whole byte.
pbos@webrtc.orgd8ca7232014-12-10 11:49:13 +0000610 pack_size_bytes_ = (uint16_t)(static_cast<float>(pack_size * rate) /
611 static_cast<float>(sampling_freq_hz * 8) +
612 0.875);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000613
614 // Set pointer to the ACM where to register the codec
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000615 AudioCodingModule* my_acm = NULL;
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000616 switch (side) {
617 case 'A': {
andrew@webrtc.org89df0922013-09-12 01:27:43 +0000618 my_acm = acm_a_.get();
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000619 break;
niklase@google.com470e71d2011-07-07 08:21:25 +0000620 }
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000621 case 'B': {
andrew@webrtc.org89df0922013-09-12 01:27:43 +0000622 my_acm = acm_b_.get();
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000623 break;
tina.legrand@webrtc.org16b6b902012-04-12 11:02:38 +0000624 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000625 default:
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000626 break;
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000627 }
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000628 ASSERT_TRUE(my_acm != NULL);
niklase@google.com470e71d2011-07-07 08:21:25 +0000629
Karl Wibergd363db12018-09-24 14:45:24 +0200630 auto encoder_factory = CreateBuiltinAudioEncoderFactory();
631 const int clockrate_hz = STR_CASE_CMP(codec_name, "g722") == 0
632 ? sampling_freq_hz / 2
633 : sampling_freq_hz;
634 const std::string ptime = rtc::ToString(rtc::CheckedDivExact(
635 pack_size, rtc::CheckedDivExact(sampling_freq_hz, 1000)));
636 SdpAudioFormat::Parameters params = {{"ptime", ptime}};
637 RTC_CHECK(channels == 1 || channels == 2);
638 if (STR_CASE_CMP(codec_name, "opus") == 0) {
639 if (channels == 2) {
640 params["stereo"] = "1";
641 }
642 channels = 2;
643 params["maxaveragebitrate"] = rtc::ToString(rate);
644 }
645 constexpr int payload_type = 17;
646 auto encoder = encoder_factory->MakeAudioEncoder(
647 payload_type, SdpAudioFormat(codec_name, clockrate_hz, channels, params),
648 absl::nullopt);
649 EXPECT_NE(nullptr, encoder);
650 my_acm->SetEncoder(std::move(encoder));
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000651
652 send_codec_name_ = codec_name;
niklase@google.com470e71d2011-07-07 08:21:25 +0000653}
654
Yves Gerey665174f2018-06-19 15:03:05 +0200655void TestStereo::Run(TestPackStereo* channel,
656 int in_channels,
657 int out_channels,
tina.legrand@webrtc.org16b6b902012-04-12 11:02:38 +0000658 int percent_loss) {
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000659 AudioFrame audio_frame;
niklase@google.com470e71d2011-07-07 08:21:25 +0000660
pbos@webrtc.org0946a562013-04-09 00:28:06 +0000661 int32_t out_freq_hz_b = out_file_.SamplingFrequency();
662 uint16_t rec_size;
663 uint32_t time_stamp_diff;
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000664 channel->reset_payload_size();
665 int error_count = 0;
tina.legrand@webrtc.org65d61c32014-06-05 13:42:51 +0000666 int variable_bytes = 0;
667 int variable_packets = 0;
Henrik Lundin4d682082015-12-10 16:24:39 +0100668 // Set test length to 500 ms (50 blocks of 10 ms each).
669 in_file_mono_->SetNum10MsBlocksToRead(50);
670 in_file_stereo_->SetNum10MsBlocksToRead(50);
671 // Fast-forward 1 second (100 blocks) since the files start with silence.
672 in_file_stereo_->FastForward(100);
673 in_file_mono_->FastForward(100);
niklase@google.com470e71d2011-07-07 08:21:25 +0000674
andresp@webrtc.orgd0b436a2014-01-13 13:15:59 +0000675 while (1) {
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000676 // Simulate packet loss by setting |packet_loss_| to "true" in
677 // |percent_loss| percent of the loops.
678 if (percent_loss > 0) {
679 if (counter_ == floor((100 / percent_loss) + 0.5)) {
680 counter_ = 0;
681 channel->set_lost_packet(true);
682 } else {
683 channel->set_lost_packet(false);
684 }
685 counter_++;
niklase@google.com470e71d2011-07-07 08:21:25 +0000686 }
687
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000688 // Add 10 msec to ACM
689 if (in_channels == 1) {
690 if (in_file_mono_->EndOfFile()) {
691 break;
692 }
693 in_file_mono_->Read10MsData(audio_frame);
694 } else {
695 if (in_file_stereo_->EndOfFile()) {
696 break;
697 }
698 in_file_stereo_->Read10MsData(audio_frame);
699 }
henrik.lundin@webrtc.orgf56c1622015-03-02 12:29:30 +0000700 EXPECT_GE(acm_a_->Add10MsData(audio_frame), 0);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000701
tina.legrand@webrtc.org65d61c32014-06-05 13:42:51 +0000702 // Verify that the received packet size matches the settings.
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000703 rec_size = channel->payload_size();
704 if ((0 < rec_size) & (rec_size < 65535)) {
tina.legrand@webrtc.org65d61c32014-06-05 13:42:51 +0000705 if (strcmp(send_codec_name_, "opus") == 0) {
706 // Opus is a variable rate codec, hence calculate the average packet
707 // size, and later make sure the average is in the right range.
708 variable_bytes += rec_size;
709 variable_packets++;
710 } else {
711 // For fixed rate codecs, check that packet size is correct.
Yves Gerey665174f2018-06-19 15:03:05 +0200712 if ((rec_size != pack_size_bytes_ * out_channels) &&
713 (pack_size_bytes_ < 65535)) {
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000714 error_count++;
715 }
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000716 }
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000717 // Verify that the timestamp is updated with expected length
718 time_stamp_diff = channel->timestamp_diff();
719 if ((counter_ > 10) && (time_stamp_diff != pack_size_samp_)) {
720 error_count++;
721 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000722 }
723
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000724 // Run received side of ACM
henrik.lundind4ccb002016-05-17 12:21:55 -0700725 bool muted;
726 EXPECT_EQ(0, acm_b_->PlayoutData10Ms(out_freq_hz_b, &audio_frame, &muted));
727 ASSERT_FALSE(muted);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000728
729 // Write output speech to file
730 out_file_.Write10MsData(
yujo36b1a5f2017-06-12 12:45:32 -0700731 audio_frame.data(),
andrew@webrtc.org63a50982012-05-02 23:56:37 +0000732 audio_frame.samples_per_channel_ * audio_frame.num_channels_);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000733 }
734
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000735 EXPECT_EQ(0, error_count);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000736
tina.legrand@webrtc.org65d61c32014-06-05 13:42:51 +0000737 // Check that packet size is in the right range for variable rate codecs,
738 // such as Opus.
739 if (variable_packets > 0) {
740 variable_bytes /= variable_packets;
Henrik Lundin4d682082015-12-10 16:24:39 +0100741 EXPECT_NEAR(variable_bytes, pack_size_bytes_, 18);
tina.legrand@webrtc.org65d61c32014-06-05 13:42:51 +0000742 }
743
andresp@webrtc.orgd0b436a2014-01-13 13:15:59 +0000744 if (in_file_mono_->EndOfFile()) {
745 in_file_mono_->Rewind();
746 }
747 if (in_file_stereo_->EndOfFile()) {
748 in_file_stereo_->Rewind();
749 }
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000750 // Reset in case we ended with a lost packet
751 channel->set_lost_packet(false);
niklase@google.com470e71d2011-07-07 08:21:25 +0000752}
753
pbos@webrtc.org0946a562013-04-09 00:28:06 +0000754void TestStereo::OpenOutFile(int16_t test_number) {
tina.legrand@webrtc.orgba468042012-08-17 10:38:28 +0000755 std::string file_name;
Jonas Olsson366a50c2018-09-06 13:41:30 +0200756 rtc::StringBuilder file_stream;
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000757 file_stream << webrtc::test::OutputPath() << "teststereo_out_" << test_number
Yves Gerey665174f2018-06-19 15:03:05 +0200758 << ".pcm";
tina.legrand@webrtc.orgba468042012-08-17 10:38:28 +0000759 file_name = file_stream.str();
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000760 out_file_.Open(file_name, 32000, "wb");
niklase@google.com470e71d2011-07-07 08:21:25 +0000761}
762
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000763void TestStereo::DisplaySendReceiveCodec() {
kwiberg1fd4a4a2015-11-03 11:20:50 -0800764 auto send_codec = acm_a_->SendCodec();
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000765 if (test_mode_ != 0) {
kwiberg1fd4a4a2015-11-03 11:20:50 -0800766 ASSERT_TRUE(send_codec);
767 printf("%s -> ", send_codec->plname);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000768 }
kwiberg1fd4a4a2015-11-03 11:20:50 -0800769 CodecInst receive_codec;
770 acm_b_->ReceiveCodec(&receive_codec);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000771 if (test_mode_ != 0) {
kwiberg1fd4a4a2015-11-03 11:20:50 -0800772 printf("%s\n", receive_codec.plname);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000773 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000774}
775
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000776} // namespace webrtc