blob: 42bdbd8d3dacef1a4c558bf6dcbc66ab9bb88965 [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
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +000013#include <string>
kjellander@webrtc.org5490c712011-12-21 13:34:18 +000014
Niels Möller2edab4c2018-10-22 09:48:08 +020015#include "absl/strings/match.h"
Karl Wiberg5817d3d2018-04-06 10:06:42 +020016#include "api/audio_codecs/builtin_audio_decoder_factory.h"
Karl Wibergd363db12018-09-24 14:45:24 +020017#include "api/audio_codecs/builtin_audio_encoder_factory.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020018#include "modules/audio_coding/include/audio_coding_module_typedefs.h"
Fredrik Solenberg657b2962018-12-05 10:30:25 +010019#include "modules/include/module_common_types.h"
Jonas Olsson366a50c2018-09-06 13:41:30 +020020#include "rtc_base/strings/string_builder.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020021#include "test/gtest.h"
Steve Anton10542f22019-01-11 09:11:00 -080022#include "test/testsupport/file_utils.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000023
tina.legrand@webrtc.org554ae1a2011-12-16 10:09:04 +000024namespace webrtc {
niklase@google.com470e71d2011-07-07 08:21:25 +000025
26// Class for simulating packet handling
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +000027TestPackStereo::TestPackStereo()
28 : receiver_acm_(NULL),
29 seq_no_(0),
30 timestamp_diff_(0),
31 last_in_timestamp_(0),
32 total_bytes_(0),
33 payload_size_(0),
Yves Gerey665174f2018-06-19 15:03:05 +020034 lost_packet_(false) {}
niklase@google.com470e71d2011-07-07 08:21:25 +000035
Yves Gerey665174f2018-06-19 15:03:05 +020036TestPackStereo::~TestPackStereo() {}
niklase@google.com470e71d2011-07-07 08:21:25 +000037
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +000038void TestPackStereo::RegisterReceiverACM(AudioCodingModule* acm) {
39 receiver_acm_ = acm;
40 return;
41}
niklase@google.com470e71d2011-07-07 08:21:25 +000042
Niels Möller87e2d782019-03-07 10:18:23 +010043int32_t TestPackStereo::SendData(const AudioFrameType frame_type,
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000044 const uint8_t payload_type,
45 const uint32_t timestamp,
46 const uint8_t* payload_data,
Niels Möllerc35b6e62019-04-25 16:31:18 +020047 const size_t payload_size) {
Niels Möllerafb5dbb2019-02-15 15:21:47 +010048 RTPHeader rtp_header;
pbos@webrtc.org0946a562013-04-09 00:28:06 +000049 int32_t status = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +000050
Niels Möllerafb5dbb2019-02-15 15:21:47 +010051 rtp_header.markerBit = false;
52 rtp_header.ssrc = 0;
53 rtp_header.sequenceNumber = seq_no_++;
54 rtp_header.payloadType = payload_type;
55 rtp_header.timestamp = timestamp;
Niels Möllerc936cb62019-03-19 14:10:16 +010056 if (frame_type == AudioFrameType::kEmptyFrame) {
tina.legrand@webrtc.org16b6b902012-04-12 11:02:38 +000057 // Skip this frame
58 return 0;
59 }
niklase@google.com470e71d2011-07-07 08:21:25 +000060
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +000061 if (lost_packet_ == false) {
Yves Gerey665174f2018-06-19 15:03:05 +020062 status =
Niels Möllerafb5dbb2019-02-15 15:21:47 +010063 receiver_acm_->IncomingPacket(payload_data, payload_size, rtp_header);
niklase@google.com470e71d2011-07-07 08:21:25 +000064
Niels Möllerc936cb62019-03-19 14:10:16 +010065 if (frame_type != AudioFrameType::kAudioFrameCN) {
henrike@webrtc.org6ac22e62014-08-11 21:06:30 +000066 payload_size_ = static_cast<int>(payload_size);
niklase@google.com470e71d2011-07-07 08:21:25 +000067 } else {
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +000068 payload_size_ = -1;
niklase@google.com470e71d2011-07-07 08:21:25 +000069 }
tina.legrand@webrtc.org16b6b902012-04-12 11:02:38 +000070
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +000071 timestamp_diff_ = timestamp - last_in_timestamp_;
72 last_in_timestamp_ = timestamp;
73 total_bytes_ += payload_size;
tina.legrand@webrtc.org16b6b902012-04-12 11:02:38 +000074 }
75 return status;
niklase@google.com470e71d2011-07-07 08:21:25 +000076}
77
pbos@webrtc.org0946a562013-04-09 00:28:06 +000078uint16_t TestPackStereo::payload_size() {
henrike@webrtc.org6ac22e62014-08-11 21:06:30 +000079 return static_cast<uint16_t>(payload_size_);
niklase@google.com470e71d2011-07-07 08:21:25 +000080}
81
pbos@webrtc.org0946a562013-04-09 00:28:06 +000082uint32_t TestPackStereo::timestamp_diff() {
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +000083 return timestamp_diff_;
niklase@google.com470e71d2011-07-07 08:21:25 +000084}
85
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +000086void TestPackStereo::reset_payload_size() {
87 payload_size_ = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +000088}
89
tina.legrand@webrtc.org16b6b902012-04-12 11:02:38 +000090void TestPackStereo::set_codec_mode(enum StereoMonoMode mode) {
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +000091 codec_mode_ = mode;
tina.legrand@webrtc.org16b6b902012-04-12 11:02:38 +000092}
93
94void TestPackStereo::set_lost_packet(bool lost) {
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +000095 lost_packet_ = lost;
niklase@google.com470e71d2011-07-07 08:21:25 +000096}
97
Fredrik Solenberg657b2962018-12-05 10:30:25 +010098TestStereo::TestStereo()
Karl Wiberg5817d3d2018-04-06 10:06:42 +020099 : acm_a_(AudioCodingModule::Create(
100 AudioCodingModule::Config(CreateBuiltinAudioDecoderFactory()))),
101 acm_b_(AudioCodingModule::Create(
102 AudioCodingModule::Config(CreateBuiltinAudioDecoderFactory()))),
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000103 channel_a2b_(NULL),
104 test_cntr_(0),
105 pack_size_samp_(0),
106 pack_size_bytes_(0),
Jonas Olssona4d87372019-07-05 19:08:33 +0200107 counter_(0) {}
niklase@google.com470e71d2011-07-07 08:21:25 +0000108
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000109TestStereo::~TestStereo() {
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000110 if (channel_a2b_ != NULL) {
111 delete channel_a2b_;
112 channel_a2b_ = NULL;
113 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000114}
115
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000116void TestStereo::Perform() {
pbos@webrtc.org0946a562013-04-09 00:28:06 +0000117 uint16_t frequency_hz;
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000118 int audio_channels;
119 int codec_channels;
niklase@google.com470e71d2011-07-07 08:21:25 +0000120
tina.legrand@webrtc.org45175852012-06-01 09:27:35 +0000121 // Open both mono and stereo test files in 32 kHz.
Yves Gerey665174f2018-06-19 15:03:05 +0200122 const std::string file_name_stereo =
123 webrtc::test::ResourcePath("audio_coding/teststereo32kHz", "pcm");
124 const std::string file_name_mono =
125 webrtc::test::ResourcePath("audio_coding/testfile32kHz", "pcm");
tina.legrand@webrtc.org45175852012-06-01 09:27:35 +0000126 frequency_hz = 32000;
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000127 in_file_stereo_ = new PCMFile();
128 in_file_mono_ = new PCMFile();
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000129 in_file_stereo_->Open(file_name_stereo, frequency_hz, "rb");
130 in_file_stereo_->ReadStereo(true);
131 in_file_mono_->Open(file_name_mono, frequency_hz, "rb");
132 in_file_mono_->ReadStereo(false);
133
tina.legrand@webrtc.org45175852012-06-01 09:27:35 +0000134 // Create and initialize two ACMs, one for each side of a one-to-one call.
andrew@webrtc.org89df0922013-09-12 01:27:43 +0000135 ASSERT_TRUE((acm_a_.get() != NULL) && (acm_b_.get() != NULL));
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000136 EXPECT_EQ(0, acm_a_->InitializeReceiver());
137 EXPECT_EQ(0, acm_b_->InitializeReceiver());
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000138
Fredrik Solenberg657b2962018-12-05 10:30:25 +0100139 acm_b_->SetReceiveCodecs({{103, {"ISAC", 16000, 1}},
140 {104, {"ISAC", 32000, 1}},
141 {107, {"L16", 8000, 1}},
142 {108, {"L16", 16000, 1}},
143 {109, {"L16", 32000, 1}},
144 {111, {"L16", 8000, 2}},
145 {112, {"L16", 16000, 2}},
146 {113, {"L16", 32000, 2}},
147 {0, {"PCMU", 8000, 1}},
148 {110, {"PCMU", 8000, 2}},
149 {8, {"PCMA", 8000, 1}},
150 {118, {"PCMA", 8000, 2}},
151 {102, {"ILBC", 8000, 1}},
152 {9, {"G722", 8000, 1}},
153 {119, {"G722", 8000, 2}},
154 {120, {"OPUS", 48000, 2, {{"stereo", "1"}}}},
155 {13, {"CN", 8000, 1}},
156 {98, {"CN", 16000, 1}},
157 {99, {"CN", 32000, 1}}});
tina.legrand@webrtc.orgae1c4542012-03-12 08:41:30 +0000158
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000159 // Create and connect the channel.
160 channel_a2b_ = new TestPackStereo;
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000161 EXPECT_EQ(0, acm_a_->RegisterTransportCallback(channel_a2b_));
andrew@webrtc.org89df0922013-09-12 01:27:43 +0000162 channel_a2b_->RegisterReceiverACM(acm_b_.get());
tina.legrand@webrtc.orgdf697752012-02-08 10:22:21 +0000163
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000164 char codec_pcma_temp[] = "PCMA";
Karl Wiberg36b37dc2018-09-24 10:52:32 +0200165 RegisterSendCodec('A', codec_pcma_temp, 8000, 64000, 80, 2);
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000166
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000167 //
168 // Test Stereo-To-Stereo for all codecs.
169 //
170 audio_channels = 2;
171 codec_channels = 2;
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000172
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000173 // All codecs are tested for all allowed sampling frequencies, rates and
174 // packet sizes.
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000175 channel_a2b_->set_codec_mode(kStereo);
176 test_cntr_++;
177 OpenOutFile(test_cntr_);
178 char codec_g722[] = "G722";
Karl Wiberg36b37dc2018-09-24 10:52:32 +0200179 RegisterSendCodec('A', codec_g722, 16000, 64000, 160, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000180 Run(channel_a2b_, audio_channels, codec_channels);
Karl Wiberg36b37dc2018-09-24 10:52:32 +0200181 RegisterSendCodec('A', codec_g722, 16000, 64000, 320, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000182 Run(channel_a2b_, audio_channels, codec_channels);
Karl Wiberg36b37dc2018-09-24 10:52:32 +0200183 RegisterSendCodec('A', codec_g722, 16000, 64000, 480, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000184 Run(channel_a2b_, audio_channels, codec_channels);
Karl Wiberg36b37dc2018-09-24 10:52:32 +0200185 RegisterSendCodec('A', codec_g722, 16000, 64000, 640, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000186 Run(channel_a2b_, audio_channels, codec_channels);
Karl Wiberg36b37dc2018-09-24 10:52:32 +0200187 RegisterSendCodec('A', codec_g722, 16000, 64000, 800, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000188 Run(channel_a2b_, audio_channels, codec_channels);
Karl Wiberg36b37dc2018-09-24 10:52:32 +0200189 RegisterSendCodec('A', codec_g722, 16000, 64000, 960, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000190 Run(channel_a2b_, audio_channels, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000191 out_file_.Close();
Karl Wibergeb254b42017-11-01 15:08:12 +0100192
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000193 channel_a2b_->set_codec_mode(kStereo);
194 test_cntr_++;
195 OpenOutFile(test_cntr_);
196 char codec_l16[] = "L16";
Karl Wiberg36b37dc2018-09-24 10:52:32 +0200197 RegisterSendCodec('A', codec_l16, 8000, 128000, 80, 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_l16, 8000, 128000, 160, 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_l16, 8000, 128000, 240, 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_l16, 8000, 128000, 320, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000204 Run(channel_a2b_, audio_channels, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000205 out_file_.Close();
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000206
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000207 test_cntr_++;
208 OpenOutFile(test_cntr_);
Karl Wiberg36b37dc2018-09-24 10:52:32 +0200209 RegisterSendCodec('A', codec_l16, 16000, 256000, 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_l16, 16000, 256000, 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_l16, 16000, 256000, 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_l16, 16000, 256000, 640, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000216 Run(channel_a2b_, audio_channels, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000217 out_file_.Close();
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000218
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000219 test_cntr_++;
220 OpenOutFile(test_cntr_);
Karl Wiberg36b37dc2018-09-24 10:52:32 +0200221 RegisterSendCodec('A', codec_l16, 32000, 512000, 320, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000222 Run(channel_a2b_, audio_channels, codec_channels);
Karl Wiberg36b37dc2018-09-24 10:52:32 +0200223 RegisterSendCodec('A', codec_l16, 32000, 512000, 640, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000224 Run(channel_a2b_, audio_channels, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000225 out_file_.Close();
niklase@google.com470e71d2011-07-07 08:21:25 +0000226#ifdef PCMA_AND_PCMU
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000227 channel_a2b_->set_codec_mode(kStereo);
228 audio_channels = 2;
229 codec_channels = 2;
230 test_cntr_++;
231 OpenOutFile(test_cntr_);
232 char codec_pcma[] = "PCMA";
Karl Wiberg36b37dc2018-09-24 10:52:32 +0200233 RegisterSendCodec('A', codec_pcma, 8000, 64000, 80, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000234 Run(channel_a2b_, audio_channels, codec_channels);
Karl Wiberg36b37dc2018-09-24 10:52:32 +0200235 RegisterSendCodec('A', codec_pcma, 8000, 64000, 160, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000236 Run(channel_a2b_, audio_channels, codec_channels);
Karl Wiberg36b37dc2018-09-24 10:52:32 +0200237 RegisterSendCodec('A', codec_pcma, 8000, 64000, 240, 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_pcma, 8000, 64000, 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_pcma, 8000, 64000, 400, 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_pcma, 8000, 64000, 480, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000244 Run(channel_a2b_, audio_channels, codec_channels);
Fredrik Solenbergec0f45b2018-12-03 15:50:44 +0000245 out_file_.Close();
Fredrik Solenberg657b2962018-12-05 10:30:25 +0100246
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000247 test_cntr_++;
248 OpenOutFile(test_cntr_);
249 char codec_pcmu[] = "PCMU";
Karl Wiberg36b37dc2018-09-24 10:52:32 +0200250 RegisterSendCodec('A', codec_pcmu, 8000, 64000, 80, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000251 Run(channel_a2b_, audio_channels, codec_channels);
Karl Wiberg36b37dc2018-09-24 10:52:32 +0200252 RegisterSendCodec('A', codec_pcmu, 8000, 64000, 160, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000253 Run(channel_a2b_, audio_channels, codec_channels);
Karl Wiberg36b37dc2018-09-24 10:52:32 +0200254 RegisterSendCodec('A', codec_pcmu, 8000, 64000, 240, 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_pcmu, 8000, 64000, 320, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000257 Run(channel_a2b_, audio_channels, codec_channels);
Karl Wiberg36b37dc2018-09-24 10:52:32 +0200258 RegisterSendCodec('A', codec_pcmu, 8000, 64000, 400, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000259 Run(channel_a2b_, audio_channels, codec_channels);
Karl Wiberg36b37dc2018-09-24 10:52:32 +0200260 RegisterSendCodec('A', codec_pcmu, 8000, 64000, 480, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000261 Run(channel_a2b_, audio_channels, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000262 out_file_.Close();
niklase@google.com470e71d2011-07-07 08:21:25 +0000263#endif
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000264#ifdef WEBRTC_CODEC_OPUS
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000265 channel_a2b_->set_codec_mode(kStereo);
266 audio_channels = 2;
267 codec_channels = 2;
268 test_cntr_++;
269 OpenOutFile(test_cntr_);
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000270
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000271 char codec_opus[] = "opus";
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000272 // Run Opus with 10 ms frame size.
Karl Wiberg36b37dc2018-09-24 10:52:32 +0200273 RegisterSendCodec('A', codec_opus, 48000, 64000, 480, codec_channels);
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000274 Run(channel_a2b_, audio_channels, codec_channels);
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000275 // Run Opus with 20 ms frame size.
Karl Wiberg36b37dc2018-09-24 10:52:32 +0200276 RegisterSendCodec('A', codec_opus, 48000, 64000, 480 * 2, codec_channels);
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000277 Run(channel_a2b_, audio_channels, codec_channels);
278 // Run Opus with 40 ms frame size.
Karl Wiberg36b37dc2018-09-24 10:52:32 +0200279 RegisterSendCodec('A', codec_opus, 48000, 64000, 480 * 4, codec_channels);
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000280 Run(channel_a2b_, audio_channels, codec_channels);
281 // Run Opus with 60 ms frame size.
Karl Wiberg36b37dc2018-09-24 10:52:32 +0200282 RegisterSendCodec('A', codec_opus, 48000, 64000, 480 * 6, codec_channels);
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000283 Run(channel_a2b_, audio_channels, codec_channels);
284 // Run Opus with 20 ms frame size and different bitrates.
Karl Wiberg36b37dc2018-09-24 10:52:32 +0200285 RegisterSendCodec('A', codec_opus, 48000, 40000, 960, codec_channels);
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000286 Run(channel_a2b_, audio_channels, codec_channels);
Karl Wiberg36b37dc2018-09-24 10:52:32 +0200287 RegisterSendCodec('A', codec_opus, 48000, 510000, 960, codec_channels);
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000288 Run(channel_a2b_, audio_channels, codec_channels);
289 out_file_.Close();
290#endif
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000291 //
292 // Test Mono-To-Stereo for all codecs.
293 //
294 audio_channels = 1;
295 codec_channels = 2;
niklase@google.com470e71d2011-07-07 08:21:25 +0000296
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000297 test_cntr_++;
298 channel_a2b_->set_codec_mode(kStereo);
299 OpenOutFile(test_cntr_);
Karl Wiberg36b37dc2018-09-24 10:52:32 +0200300 RegisterSendCodec('A', codec_g722, 16000, 64000, 160, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000301 Run(channel_a2b_, audio_channels, codec_channels);
302 out_file_.Close();
Karl Wibergeb254b42017-11-01 15:08:12 +0100303
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000304 test_cntr_++;
305 channel_a2b_->set_codec_mode(kStereo);
306 OpenOutFile(test_cntr_);
Karl Wiberg36b37dc2018-09-24 10:52:32 +0200307 RegisterSendCodec('A', codec_l16, 8000, 128000, 80, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000308 Run(channel_a2b_, audio_channels, codec_channels);
309 out_file_.Close();
Fredrik Solenberg657b2962018-12-05 10:30:25 +0100310
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000311 test_cntr_++;
312 OpenOutFile(test_cntr_);
Karl Wiberg36b37dc2018-09-24 10:52:32 +0200313 RegisterSendCodec('A', codec_l16, 16000, 256000, 160, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000314 Run(channel_a2b_, audio_channels, codec_channels);
315 out_file_.Close();
Fredrik Solenberg657b2962018-12-05 10:30:25 +0100316
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000317 test_cntr_++;
318 OpenOutFile(test_cntr_);
Karl Wiberg36b37dc2018-09-24 10:52:32 +0200319 RegisterSendCodec('A', codec_l16, 32000, 512000, 320, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000320 Run(channel_a2b_, audio_channels, codec_channels);
321 out_file_.Close();
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000322#ifdef PCMA_AND_PCMU
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000323 test_cntr_++;
324 channel_a2b_->set_codec_mode(kStereo);
325 OpenOutFile(test_cntr_);
Karl Wiberg36b37dc2018-09-24 10:52:32 +0200326 RegisterSendCodec('A', codec_pcmu, 8000, 64000, 80, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000327 Run(channel_a2b_, audio_channels, codec_channels);
Karl Wiberg36b37dc2018-09-24 10:52:32 +0200328 RegisterSendCodec('A', codec_pcma, 8000, 64000, 80, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000329 Run(channel_a2b_, audio_channels, codec_channels);
330 out_file_.Close();
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000331#endif
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000332#ifdef WEBRTC_CODEC_OPUS
tina.legrand@webrtc.orgc4590582012-11-28 12:23:29 +0000333 // Keep encode and decode in stereo.
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000334 test_cntr_++;
335 channel_a2b_->set_codec_mode(kStereo);
336 OpenOutFile(test_cntr_);
Karl Wiberg36b37dc2018-09-24 10:52:32 +0200337 RegisterSendCodec('A', codec_opus, 48000, 64000, 960, codec_channels);
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000338 Run(channel_a2b_, audio_channels, codec_channels);
tina.legrand@webrtc.orgc4590582012-11-28 12:23:29 +0000339
340 // Encode in mono, decode in stereo mode.
Karl Wiberg36b37dc2018-09-24 10:52:32 +0200341 RegisterSendCodec('A', codec_opus, 48000, 64000, 960, 1);
tina.legrand@webrtc.orgc4590582012-11-28 12:23:29 +0000342 Run(channel_a2b_, audio_channels, codec_channels);
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000343 out_file_.Close();
344#endif
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000345
346 //
347 // Test Stereo-To-Mono for all codecs.
348 //
349 audio_channels = 2;
350 codec_channels = 1;
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000351 channel_a2b_->set_codec_mode(kMono);
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000352
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000353 // Run stereo audio and mono codec.
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000354 test_cntr_++;
355 OpenOutFile(test_cntr_);
Karl Wiberg36b37dc2018-09-24 10:52:32 +0200356 RegisterSendCodec('A', codec_g722, 16000, 64000, 160, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000357 Run(channel_a2b_, audio_channels, codec_channels);
358 out_file_.Close();
Karl Wibergeb254b42017-11-01 15:08:12 +0100359
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000360 test_cntr_++;
361 OpenOutFile(test_cntr_);
Karl Wiberg36b37dc2018-09-24 10:52:32 +0200362 RegisterSendCodec('A', codec_l16, 8000, 128000, 80, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000363 Run(channel_a2b_, audio_channels, codec_channels);
364 out_file_.Close();
Fredrik Solenberg657b2962018-12-05 10:30:25 +0100365
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000366 test_cntr_++;
367 OpenOutFile(test_cntr_);
Karl Wiberg36b37dc2018-09-24 10:52:32 +0200368 RegisterSendCodec('A', codec_l16, 16000, 256000, 160, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000369 Run(channel_a2b_, audio_channels, codec_channels);
370 out_file_.Close();
Fredrik Solenberg657b2962018-12-05 10:30:25 +0100371
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000372 test_cntr_++;
373 OpenOutFile(test_cntr_);
Karl Wiberg36b37dc2018-09-24 10:52:32 +0200374 RegisterSendCodec('A', codec_l16, 32000, 512000, 320, codec_channels);
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000375 Run(channel_a2b_, audio_channels, codec_channels);
376 out_file_.Close();
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000377#ifdef PCMA_AND_PCMU
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000378 test_cntr_++;
379 OpenOutFile(test_cntr_);
Karl Wiberg36b37dc2018-09-24 10:52:32 +0200380 RegisterSendCodec('A', codec_pcmu, 8000, 64000, 80, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000381 Run(channel_a2b_, audio_channels, codec_channels);
Karl Wiberg36b37dc2018-09-24 10:52:32 +0200382 RegisterSendCodec('A', codec_pcma, 8000, 64000, 80, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000383 Run(channel_a2b_, audio_channels, codec_channels);
384 out_file_.Close();
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000385#endif
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000386#ifdef WEBRTC_CODEC_OPUS
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000387 test_cntr_++;
388 OpenOutFile(test_cntr_);
tina.legrand@webrtc.orgc4590582012-11-28 12:23:29 +0000389 // Encode and decode in mono.
Karl Wiberg36b37dc2018-09-24 10:52:32 +0200390 RegisterSendCodec('A', codec_opus, 48000, 32000, 960, codec_channels);
Fredrik Solenberg657b2962018-12-05 10:30:25 +0100391 acm_b_->SetReceiveCodecs({{120, {"OPUS", 48000, 2}}});
tina.legrand@webrtc.orgc4590582012-11-28 12:23:29 +0000392 Run(channel_a2b_, audio_channels, codec_channels);
393
394 // Encode in stereo, decode in mono.
Karl Wiberg36b37dc2018-09-24 10:52:32 +0200395 RegisterSendCodec('A', codec_opus, 48000, 32000, 960, 2);
tina.legrand@webrtc.orgc4590582012-11-28 12:23:29 +0000396 Run(channel_a2b_, audio_channels, codec_channels);
397
398 out_file_.Close();
399
400 // Test switching between decoding mono and stereo for Opus.
401
402 // Decode in mono.
403 test_cntr_++;
404 OpenOutFile(test_cntr_);
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000405 Run(channel_a2b_, audio_channels, codec_channels);
406 out_file_.Close();
tina.legrand@webrtc.orgc4590582012-11-28 12:23:29 +0000407 // Decode in stereo.
408 test_cntr_++;
409 OpenOutFile(test_cntr_);
Fredrik Solenberg657b2962018-12-05 10:30:25 +0100410 acm_b_->SetReceiveCodecs({{120, {"OPUS", 48000, 2, {{"stereo", "1"}}}}});
tina.legrand@webrtc.orgc4590582012-11-28 12:23:29 +0000411 Run(channel_a2b_, audio_channels, 2);
412 out_file_.Close();
413 // Decode in mono.
414 test_cntr_++;
415 OpenOutFile(test_cntr_);
Fredrik Solenberg657b2962018-12-05 10:30:25 +0100416 acm_b_->SetReceiveCodecs({{120, {"OPUS", 48000, 2}}});
tina.legrand@webrtc.orgc4590582012-11-28 12:23:29 +0000417 Run(channel_a2b_, audio_channels, codec_channels);
418 out_file_.Close();
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000419#endif
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000420
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000421 // Delete the file pointers.
422 delete in_file_stereo_;
423 delete in_file_mono_;
niklase@google.com470e71d2011-07-07 08:21:25 +0000424}
425
426// Register Codec to use in the test
427//
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000428// Input: side - which ACM to use, 'A' or 'B'
429// codec_name - name to use when register the codec
430// sampling_freq_hz - sampling frequency in Herz
431// rate - bitrate in bytes
432// pack_size - packet size in samples
433// channels - number of channels; 1 for mono, 2 for stereo
Yves Gerey665174f2018-06-19 15:03:05 +0200434void TestStereo::RegisterSendCodec(char side,
435 char* codec_name,
436 int32_t sampling_freq_hz,
437 int rate,
438 int pack_size,
Karl Wiberg36b37dc2018-09-24 10:52:32 +0200439 int channels) {
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000440 // Store packet size in samples, used to validate the received packet
441 pack_size_samp_ = pack_size;
442
443 // Store the expected packet size in bytes, used to validate the received
444 // packet. Add 0.875 to always round up to a whole byte.
pbos@webrtc.orgd8ca7232014-12-10 11:49:13 +0000445 pack_size_bytes_ = (uint16_t)(static_cast<float>(pack_size * rate) /
446 static_cast<float>(sampling_freq_hz * 8) +
447 0.875);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000448
449 // Set pointer to the ACM where to register the codec
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000450 AudioCodingModule* my_acm = NULL;
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000451 switch (side) {
452 case 'A': {
andrew@webrtc.org89df0922013-09-12 01:27:43 +0000453 my_acm = acm_a_.get();
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000454 break;
niklase@google.com470e71d2011-07-07 08:21:25 +0000455 }
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000456 case 'B': {
andrew@webrtc.org89df0922013-09-12 01:27:43 +0000457 my_acm = acm_b_.get();
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000458 break;
tina.legrand@webrtc.org16b6b902012-04-12 11:02:38 +0000459 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000460 default:
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000461 break;
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000462 }
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000463 ASSERT_TRUE(my_acm != NULL);
niklase@google.com470e71d2011-07-07 08:21:25 +0000464
Karl Wibergd363db12018-09-24 14:45:24 +0200465 auto encoder_factory = CreateBuiltinAudioEncoderFactory();
Niels Möller2edab4c2018-10-22 09:48:08 +0200466 const int clockrate_hz = absl::EqualsIgnoreCase(codec_name, "g722")
Karl Wibergd363db12018-09-24 14:45:24 +0200467 ? sampling_freq_hz / 2
468 : sampling_freq_hz;
469 const std::string ptime = rtc::ToString(rtc::CheckedDivExact(
470 pack_size, rtc::CheckedDivExact(sampling_freq_hz, 1000)));
471 SdpAudioFormat::Parameters params = {{"ptime", ptime}};
472 RTC_CHECK(channels == 1 || channels == 2);
Niels Möller2edab4c2018-10-22 09:48:08 +0200473 if (absl::EqualsIgnoreCase(codec_name, "opus")) {
Karl Wibergd363db12018-09-24 14:45:24 +0200474 if (channels == 2) {
475 params["stereo"] = "1";
476 }
477 channels = 2;
478 params["maxaveragebitrate"] = rtc::ToString(rate);
479 }
480 constexpr int payload_type = 17;
481 auto encoder = encoder_factory->MakeAudioEncoder(
482 payload_type, SdpAudioFormat(codec_name, clockrate_hz, channels, params),
483 absl::nullopt);
484 EXPECT_NE(nullptr, encoder);
485 my_acm->SetEncoder(std::move(encoder));
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000486
487 send_codec_name_ = codec_name;
niklase@google.com470e71d2011-07-07 08:21:25 +0000488}
489
Yves Gerey665174f2018-06-19 15:03:05 +0200490void TestStereo::Run(TestPackStereo* channel,
491 int in_channels,
492 int out_channels,
tina.legrand@webrtc.org16b6b902012-04-12 11:02:38 +0000493 int percent_loss) {
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000494 AudioFrame audio_frame;
niklase@google.com470e71d2011-07-07 08:21:25 +0000495
pbos@webrtc.org0946a562013-04-09 00:28:06 +0000496 int32_t out_freq_hz_b = out_file_.SamplingFrequency();
497 uint16_t rec_size;
498 uint32_t time_stamp_diff;
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000499 channel->reset_payload_size();
500 int error_count = 0;
tina.legrand@webrtc.org65d61c32014-06-05 13:42:51 +0000501 int variable_bytes = 0;
502 int variable_packets = 0;
Henrik Lundin4d682082015-12-10 16:24:39 +0100503 // Set test length to 500 ms (50 blocks of 10 ms each).
504 in_file_mono_->SetNum10MsBlocksToRead(50);
505 in_file_stereo_->SetNum10MsBlocksToRead(50);
506 // Fast-forward 1 second (100 blocks) since the files start with silence.
507 in_file_stereo_->FastForward(100);
508 in_file_mono_->FastForward(100);
niklase@google.com470e71d2011-07-07 08:21:25 +0000509
andresp@webrtc.orgd0b436a2014-01-13 13:15:59 +0000510 while (1) {
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000511 // Simulate packet loss by setting |packet_loss_| to "true" in
512 // |percent_loss| percent of the loops.
513 if (percent_loss > 0) {
514 if (counter_ == floor((100 / percent_loss) + 0.5)) {
515 counter_ = 0;
516 channel->set_lost_packet(true);
517 } else {
518 channel->set_lost_packet(false);
519 }
520 counter_++;
niklase@google.com470e71d2011-07-07 08:21:25 +0000521 }
522
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000523 // Add 10 msec to ACM
524 if (in_channels == 1) {
525 if (in_file_mono_->EndOfFile()) {
526 break;
527 }
528 in_file_mono_->Read10MsData(audio_frame);
529 } else {
530 if (in_file_stereo_->EndOfFile()) {
531 break;
532 }
533 in_file_stereo_->Read10MsData(audio_frame);
534 }
henrik.lundin@webrtc.orgf56c1622015-03-02 12:29:30 +0000535 EXPECT_GE(acm_a_->Add10MsData(audio_frame), 0);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000536
tina.legrand@webrtc.org65d61c32014-06-05 13:42:51 +0000537 // Verify that the received packet size matches the settings.
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000538 rec_size = channel->payload_size();
539 if ((0 < rec_size) & (rec_size < 65535)) {
tina.legrand@webrtc.org65d61c32014-06-05 13:42:51 +0000540 if (strcmp(send_codec_name_, "opus") == 0) {
541 // Opus is a variable rate codec, hence calculate the average packet
542 // size, and later make sure the average is in the right range.
543 variable_bytes += rec_size;
544 variable_packets++;
545 } else {
546 // For fixed rate codecs, check that packet size is correct.
Yves Gerey665174f2018-06-19 15:03:05 +0200547 if ((rec_size != pack_size_bytes_ * out_channels) &&
548 (pack_size_bytes_ < 65535)) {
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000549 error_count++;
550 }
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000551 }
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000552 // Verify that the timestamp is updated with expected length
553 time_stamp_diff = channel->timestamp_diff();
554 if ((counter_ > 10) && (time_stamp_diff != pack_size_samp_)) {
555 error_count++;
556 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000557 }
558
Fredrik Solenberg657b2962018-12-05 10:30:25 +0100559 // Run receive side of ACM
henrik.lundind4ccb002016-05-17 12:21:55 -0700560 bool muted;
561 EXPECT_EQ(0, acm_b_->PlayoutData10Ms(out_freq_hz_b, &audio_frame, &muted));
562 ASSERT_FALSE(muted);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000563
564 // Write output speech to file
565 out_file_.Write10MsData(
yujo36b1a5f2017-06-12 12:45:32 -0700566 audio_frame.data(),
andrew@webrtc.org63a50982012-05-02 23:56:37 +0000567 audio_frame.samples_per_channel_ * audio_frame.num_channels_);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000568 }
569
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000570 EXPECT_EQ(0, error_count);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000571
tina.legrand@webrtc.org65d61c32014-06-05 13:42:51 +0000572 // Check that packet size is in the right range for variable rate codecs,
573 // such as Opus.
574 if (variable_packets > 0) {
575 variable_bytes /= variable_packets;
Henrik Lundin4d682082015-12-10 16:24:39 +0100576 EXPECT_NEAR(variable_bytes, pack_size_bytes_, 18);
tina.legrand@webrtc.org65d61c32014-06-05 13:42:51 +0000577 }
578
andresp@webrtc.orgd0b436a2014-01-13 13:15:59 +0000579 if (in_file_mono_->EndOfFile()) {
580 in_file_mono_->Rewind();
581 }
582 if (in_file_stereo_->EndOfFile()) {
583 in_file_stereo_->Rewind();
584 }
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000585 // Reset in case we ended with a lost packet
586 channel->set_lost_packet(false);
niklase@google.com470e71d2011-07-07 08:21:25 +0000587}
588
pbos@webrtc.org0946a562013-04-09 00:28:06 +0000589void TestStereo::OpenOutFile(int16_t test_number) {
tina.legrand@webrtc.orgba468042012-08-17 10:38:28 +0000590 std::string file_name;
Jonas Olsson366a50c2018-09-06 13:41:30 +0200591 rtc::StringBuilder file_stream;
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000592 file_stream << webrtc::test::OutputPath() << "teststereo_out_" << test_number
Yves Gerey665174f2018-06-19 15:03:05 +0200593 << ".pcm";
tina.legrand@webrtc.orgba468042012-08-17 10:38:28 +0000594 file_name = file_stream.str();
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000595 out_file_.Open(file_name, 32000, "wb");
niklase@google.com470e71d2011-07-07 08:21:25 +0000596}
597
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000598} // namespace webrtc