blob: ea8735b66d27beb09a920a94c39d2bb3e42e626d [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),
Karl Wiberg36b37dc2018-09-24 10:52:32 +0200107 counter_(0) {
niklase@google.com470e71d2011-07-07 08:21:25 +0000108}
109
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000110TestStereo::~TestStereo() {
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000111 if (channel_a2b_ != NULL) {
112 delete channel_a2b_;
113 channel_a2b_ = NULL;
114 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000115}
116
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000117void TestStereo::Perform() {
pbos@webrtc.org0946a562013-04-09 00:28:06 +0000118 uint16_t frequency_hz;
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000119 int audio_channels;
120 int codec_channels;
niklase@google.com470e71d2011-07-07 08:21:25 +0000121
tina.legrand@webrtc.org45175852012-06-01 09:27:35 +0000122 // Open both mono and stereo test files in 32 kHz.
Yves Gerey665174f2018-06-19 15:03:05 +0200123 const std::string file_name_stereo =
124 webrtc::test::ResourcePath("audio_coding/teststereo32kHz", "pcm");
125 const std::string file_name_mono =
126 webrtc::test::ResourcePath("audio_coding/testfile32kHz", "pcm");
tina.legrand@webrtc.org45175852012-06-01 09:27:35 +0000127 frequency_hz = 32000;
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000128 in_file_stereo_ = new PCMFile();
129 in_file_mono_ = new PCMFile();
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000130 in_file_stereo_->Open(file_name_stereo, frequency_hz, "rb");
131 in_file_stereo_->ReadStereo(true);
132 in_file_mono_->Open(file_name_mono, frequency_hz, "rb");
133 in_file_mono_->ReadStereo(false);
134
tina.legrand@webrtc.org45175852012-06-01 09:27:35 +0000135 // Create and initialize two ACMs, one for each side of a one-to-one call.
andrew@webrtc.org89df0922013-09-12 01:27:43 +0000136 ASSERT_TRUE((acm_a_.get() != NULL) && (acm_b_.get() != NULL));
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000137 EXPECT_EQ(0, acm_a_->InitializeReceiver());
138 EXPECT_EQ(0, acm_b_->InitializeReceiver());
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000139
Fredrik Solenberg657b2962018-12-05 10:30:25 +0100140 acm_b_->SetReceiveCodecs({{103, {"ISAC", 16000, 1}},
141 {104, {"ISAC", 32000, 1}},
142 {107, {"L16", 8000, 1}},
143 {108, {"L16", 16000, 1}},
144 {109, {"L16", 32000, 1}},
145 {111, {"L16", 8000, 2}},
146 {112, {"L16", 16000, 2}},
147 {113, {"L16", 32000, 2}},
148 {0, {"PCMU", 8000, 1}},
149 {110, {"PCMU", 8000, 2}},
150 {8, {"PCMA", 8000, 1}},
151 {118, {"PCMA", 8000, 2}},
152 {102, {"ILBC", 8000, 1}},
153 {9, {"G722", 8000, 1}},
154 {119, {"G722", 8000, 2}},
155 {120, {"OPUS", 48000, 2, {{"stereo", "1"}}}},
156 {13, {"CN", 8000, 1}},
157 {98, {"CN", 16000, 1}},
158 {99, {"CN", 32000, 1}}});
tina.legrand@webrtc.orgae1c4542012-03-12 08:41:30 +0000159
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000160 // Create and connect the channel.
161 channel_a2b_ = new TestPackStereo;
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000162 EXPECT_EQ(0, acm_a_->RegisterTransportCallback(channel_a2b_));
andrew@webrtc.org89df0922013-09-12 01:27:43 +0000163 channel_a2b_->RegisterReceiverACM(acm_b_.get());
tina.legrand@webrtc.orgdf697752012-02-08 10:22:21 +0000164
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000165 char codec_pcma_temp[] = "PCMA";
Karl Wiberg36b37dc2018-09-24 10:52:32 +0200166 RegisterSendCodec('A', codec_pcma_temp, 8000, 64000, 80, 2);
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000167
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000168 //
169 // Test Stereo-To-Stereo for all codecs.
170 //
171 audio_channels = 2;
172 codec_channels = 2;
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000173
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000174 // All codecs are tested for all allowed sampling frequencies, rates and
175 // packet sizes.
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000176 channel_a2b_->set_codec_mode(kStereo);
177 test_cntr_++;
178 OpenOutFile(test_cntr_);
179 char codec_g722[] = "G722";
Karl Wiberg36b37dc2018-09-24 10:52:32 +0200180 RegisterSendCodec('A', codec_g722, 16000, 64000, 160, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000181 Run(channel_a2b_, audio_channels, codec_channels);
Karl Wiberg36b37dc2018-09-24 10:52:32 +0200182 RegisterSendCodec('A', codec_g722, 16000, 64000, 320, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000183 Run(channel_a2b_, audio_channels, codec_channels);
Karl Wiberg36b37dc2018-09-24 10:52:32 +0200184 RegisterSendCodec('A', codec_g722, 16000, 64000, 480, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000185 Run(channel_a2b_, audio_channels, codec_channels);
Karl Wiberg36b37dc2018-09-24 10:52:32 +0200186 RegisterSendCodec('A', codec_g722, 16000, 64000, 640, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000187 Run(channel_a2b_, audio_channels, codec_channels);
Karl Wiberg36b37dc2018-09-24 10:52:32 +0200188 RegisterSendCodec('A', codec_g722, 16000, 64000, 800, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000189 Run(channel_a2b_, audio_channels, codec_channels);
Karl Wiberg36b37dc2018-09-24 10:52:32 +0200190 RegisterSendCodec('A', codec_g722, 16000, 64000, 960, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000191 Run(channel_a2b_, audio_channels, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000192 out_file_.Close();
Karl Wibergeb254b42017-11-01 15:08:12 +0100193
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000194 channel_a2b_->set_codec_mode(kStereo);
195 test_cntr_++;
196 OpenOutFile(test_cntr_);
197 char codec_l16[] = "L16";
Karl Wiberg36b37dc2018-09-24 10:52:32 +0200198 RegisterSendCodec('A', codec_l16, 8000, 128000, 80, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000199 Run(channel_a2b_, audio_channels, codec_channels);
Karl Wiberg36b37dc2018-09-24 10:52:32 +0200200 RegisterSendCodec('A', codec_l16, 8000, 128000, 160, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000201 Run(channel_a2b_, audio_channels, codec_channels);
Karl Wiberg36b37dc2018-09-24 10:52:32 +0200202 RegisterSendCodec('A', codec_l16, 8000, 128000, 240, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000203 Run(channel_a2b_, audio_channels, codec_channels);
Karl Wiberg36b37dc2018-09-24 10:52:32 +0200204 RegisterSendCodec('A', codec_l16, 8000, 128000, 320, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000205 Run(channel_a2b_, audio_channels, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000206 out_file_.Close();
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000207
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000208 test_cntr_++;
209 OpenOutFile(test_cntr_);
Karl Wiberg36b37dc2018-09-24 10:52:32 +0200210 RegisterSendCodec('A', codec_l16, 16000, 256000, 160, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000211 Run(channel_a2b_, audio_channels, codec_channels);
Karl Wiberg36b37dc2018-09-24 10:52:32 +0200212 RegisterSendCodec('A', codec_l16, 16000, 256000, 320, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000213 Run(channel_a2b_, audio_channels, codec_channels);
Karl Wiberg36b37dc2018-09-24 10:52:32 +0200214 RegisterSendCodec('A', codec_l16, 16000, 256000, 480, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000215 Run(channel_a2b_, audio_channels, codec_channels);
Karl Wiberg36b37dc2018-09-24 10:52:32 +0200216 RegisterSendCodec('A', codec_l16, 16000, 256000, 640, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000217 Run(channel_a2b_, audio_channels, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000218 out_file_.Close();
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000219
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000220 test_cntr_++;
221 OpenOutFile(test_cntr_);
Karl Wiberg36b37dc2018-09-24 10:52:32 +0200222 RegisterSendCodec('A', codec_l16, 32000, 512000, 320, 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, 32000, 512000, 640, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000225 Run(channel_a2b_, audio_channels, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000226 out_file_.Close();
niklase@google.com470e71d2011-07-07 08:21:25 +0000227#ifdef PCMA_AND_PCMU
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000228 channel_a2b_->set_codec_mode(kStereo);
229 audio_channels = 2;
230 codec_channels = 2;
231 test_cntr_++;
232 OpenOutFile(test_cntr_);
233 char codec_pcma[] = "PCMA";
Karl Wiberg36b37dc2018-09-24 10:52:32 +0200234 RegisterSendCodec('A', codec_pcma, 8000, 64000, 80, 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_pcma, 8000, 64000, 160, 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_pcma, 8000, 64000, 240, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000239 Run(channel_a2b_, audio_channels, codec_channels);
Karl Wiberg36b37dc2018-09-24 10:52:32 +0200240 RegisterSendCodec('A', codec_pcma, 8000, 64000, 320, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000241 Run(channel_a2b_, audio_channels, codec_channels);
Karl Wiberg36b37dc2018-09-24 10:52:32 +0200242 RegisterSendCodec('A', codec_pcma, 8000, 64000, 400, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000243 Run(channel_a2b_, audio_channels, codec_channels);
Karl Wiberg36b37dc2018-09-24 10:52:32 +0200244 RegisterSendCodec('A', codec_pcma, 8000, 64000, 480, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000245 Run(channel_a2b_, audio_channels, codec_channels);
Fredrik Solenbergec0f45b2018-12-03 15:50:44 +0000246 out_file_.Close();
Fredrik Solenberg657b2962018-12-05 10:30:25 +0100247
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000248 test_cntr_++;
249 OpenOutFile(test_cntr_);
250 char codec_pcmu[] = "PCMU";
Karl Wiberg36b37dc2018-09-24 10:52:32 +0200251 RegisterSendCodec('A', codec_pcmu, 8000, 64000, 80, 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_pcmu, 8000, 64000, 160, 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_pcmu, 8000, 64000, 240, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000256 Run(channel_a2b_, audio_channels, codec_channels);
Karl Wiberg36b37dc2018-09-24 10:52:32 +0200257 RegisterSendCodec('A', codec_pcmu, 8000, 64000, 320, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000258 Run(channel_a2b_, audio_channels, codec_channels);
Karl Wiberg36b37dc2018-09-24 10:52:32 +0200259 RegisterSendCodec('A', codec_pcmu, 8000, 64000, 400, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000260 Run(channel_a2b_, audio_channels, codec_channels);
Karl Wiberg36b37dc2018-09-24 10:52:32 +0200261 RegisterSendCodec('A', codec_pcmu, 8000, 64000, 480, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000262 Run(channel_a2b_, audio_channels, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000263 out_file_.Close();
niklase@google.com470e71d2011-07-07 08:21:25 +0000264#endif
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000265#ifdef WEBRTC_CODEC_OPUS
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000266 channel_a2b_->set_codec_mode(kStereo);
267 audio_channels = 2;
268 codec_channels = 2;
269 test_cntr_++;
270 OpenOutFile(test_cntr_);
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000271
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000272 char codec_opus[] = "opus";
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000273 // Run Opus with 10 ms frame size.
Karl Wiberg36b37dc2018-09-24 10:52:32 +0200274 RegisterSendCodec('A', codec_opus, 48000, 64000, 480, codec_channels);
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000275 Run(channel_a2b_, audio_channels, codec_channels);
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000276 // Run Opus with 20 ms frame size.
Karl Wiberg36b37dc2018-09-24 10:52:32 +0200277 RegisterSendCodec('A', codec_opus, 48000, 64000, 480 * 2, codec_channels);
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000278 Run(channel_a2b_, audio_channels, codec_channels);
279 // Run Opus with 40 ms frame size.
Karl Wiberg36b37dc2018-09-24 10:52:32 +0200280 RegisterSendCodec('A', codec_opus, 48000, 64000, 480 * 4, codec_channels);
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000281 Run(channel_a2b_, audio_channels, codec_channels);
282 // Run Opus with 60 ms frame size.
Karl Wiberg36b37dc2018-09-24 10:52:32 +0200283 RegisterSendCodec('A', codec_opus, 48000, 64000, 480 * 6, codec_channels);
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000284 Run(channel_a2b_, audio_channels, codec_channels);
285 // Run Opus with 20 ms frame size and different bitrates.
Karl Wiberg36b37dc2018-09-24 10:52:32 +0200286 RegisterSendCodec('A', codec_opus, 48000, 40000, 960, codec_channels);
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000287 Run(channel_a2b_, audio_channels, codec_channels);
Karl Wiberg36b37dc2018-09-24 10:52:32 +0200288 RegisterSendCodec('A', codec_opus, 48000, 510000, 960, codec_channels);
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000289 Run(channel_a2b_, audio_channels, codec_channels);
290 out_file_.Close();
291#endif
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000292 //
293 // Test Mono-To-Stereo for all codecs.
294 //
295 audio_channels = 1;
296 codec_channels = 2;
niklase@google.com470e71d2011-07-07 08:21:25 +0000297
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000298 test_cntr_++;
299 channel_a2b_->set_codec_mode(kStereo);
300 OpenOutFile(test_cntr_);
Karl Wiberg36b37dc2018-09-24 10:52:32 +0200301 RegisterSendCodec('A', codec_g722, 16000, 64000, 160, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000302 Run(channel_a2b_, audio_channels, codec_channels);
303 out_file_.Close();
Karl Wibergeb254b42017-11-01 15:08:12 +0100304
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000305 test_cntr_++;
306 channel_a2b_->set_codec_mode(kStereo);
307 OpenOutFile(test_cntr_);
Karl Wiberg36b37dc2018-09-24 10:52:32 +0200308 RegisterSendCodec('A', codec_l16, 8000, 128000, 80, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000309 Run(channel_a2b_, audio_channels, codec_channels);
310 out_file_.Close();
Fredrik Solenberg657b2962018-12-05 10:30:25 +0100311
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000312 test_cntr_++;
313 OpenOutFile(test_cntr_);
Karl Wiberg36b37dc2018-09-24 10:52:32 +0200314 RegisterSendCodec('A', codec_l16, 16000, 256000, 160, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000315 Run(channel_a2b_, audio_channels, codec_channels);
316 out_file_.Close();
Fredrik Solenberg657b2962018-12-05 10:30:25 +0100317
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000318 test_cntr_++;
319 OpenOutFile(test_cntr_);
Karl Wiberg36b37dc2018-09-24 10:52:32 +0200320 RegisterSendCodec('A', codec_l16, 32000, 512000, 320, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000321 Run(channel_a2b_, audio_channels, codec_channels);
322 out_file_.Close();
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000323#ifdef PCMA_AND_PCMU
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000324 test_cntr_++;
325 channel_a2b_->set_codec_mode(kStereo);
326 OpenOutFile(test_cntr_);
Karl Wiberg36b37dc2018-09-24 10:52:32 +0200327 RegisterSendCodec('A', codec_pcmu, 8000, 64000, 80, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000328 Run(channel_a2b_, audio_channels, codec_channels);
Karl Wiberg36b37dc2018-09-24 10:52:32 +0200329 RegisterSendCodec('A', codec_pcma, 8000, 64000, 80, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000330 Run(channel_a2b_, audio_channels, codec_channels);
331 out_file_.Close();
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000332#endif
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000333#ifdef WEBRTC_CODEC_OPUS
tina.legrand@webrtc.orgc4590582012-11-28 12:23:29 +0000334 // Keep encode and decode in stereo.
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000335 test_cntr_++;
336 channel_a2b_->set_codec_mode(kStereo);
337 OpenOutFile(test_cntr_);
Karl Wiberg36b37dc2018-09-24 10:52:32 +0200338 RegisterSendCodec('A', codec_opus, 48000, 64000, 960, codec_channels);
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000339 Run(channel_a2b_, audio_channels, codec_channels);
tina.legrand@webrtc.orgc4590582012-11-28 12:23:29 +0000340
341 // Encode in mono, decode in stereo mode.
Karl Wiberg36b37dc2018-09-24 10:52:32 +0200342 RegisterSendCodec('A', codec_opus, 48000, 64000, 960, 1);
tina.legrand@webrtc.orgc4590582012-11-28 12:23:29 +0000343 Run(channel_a2b_, audio_channels, codec_channels);
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000344 out_file_.Close();
345#endif
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000346
347 //
348 // Test Stereo-To-Mono for all codecs.
349 //
350 audio_channels = 2;
351 codec_channels = 1;
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000352 channel_a2b_->set_codec_mode(kMono);
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000353
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000354 // Run stereo audio and mono codec.
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000355 test_cntr_++;
356 OpenOutFile(test_cntr_);
Karl Wiberg36b37dc2018-09-24 10:52:32 +0200357 RegisterSendCodec('A', codec_g722, 16000, 64000, 160, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000358 Run(channel_a2b_, audio_channels, codec_channels);
359 out_file_.Close();
Karl Wibergeb254b42017-11-01 15:08:12 +0100360
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000361 test_cntr_++;
362 OpenOutFile(test_cntr_);
Karl Wiberg36b37dc2018-09-24 10:52:32 +0200363 RegisterSendCodec('A', codec_l16, 8000, 128000, 80, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000364 Run(channel_a2b_, audio_channels, codec_channels);
365 out_file_.Close();
Fredrik Solenberg657b2962018-12-05 10:30:25 +0100366
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000367 test_cntr_++;
368 OpenOutFile(test_cntr_);
Karl Wiberg36b37dc2018-09-24 10:52:32 +0200369 RegisterSendCodec('A', codec_l16, 16000, 256000, 160, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000370 Run(channel_a2b_, audio_channels, codec_channels);
371 out_file_.Close();
Fredrik Solenberg657b2962018-12-05 10:30:25 +0100372
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000373 test_cntr_++;
374 OpenOutFile(test_cntr_);
Karl Wiberg36b37dc2018-09-24 10:52:32 +0200375 RegisterSendCodec('A', codec_l16, 32000, 512000, 320, codec_channels);
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000376 Run(channel_a2b_, audio_channels, codec_channels);
377 out_file_.Close();
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000378#ifdef PCMA_AND_PCMU
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000379 test_cntr_++;
380 OpenOutFile(test_cntr_);
Karl Wiberg36b37dc2018-09-24 10:52:32 +0200381 RegisterSendCodec('A', codec_pcmu, 8000, 64000, 80, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000382 Run(channel_a2b_, audio_channels, codec_channels);
Karl Wiberg36b37dc2018-09-24 10:52:32 +0200383 RegisterSendCodec('A', codec_pcma, 8000, 64000, 80, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000384 Run(channel_a2b_, audio_channels, codec_channels);
385 out_file_.Close();
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000386#endif
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000387#ifdef WEBRTC_CODEC_OPUS
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000388 test_cntr_++;
389 OpenOutFile(test_cntr_);
tina.legrand@webrtc.orgc4590582012-11-28 12:23:29 +0000390 // Encode and decode in mono.
Karl Wiberg36b37dc2018-09-24 10:52:32 +0200391 RegisterSendCodec('A', codec_opus, 48000, 32000, 960, codec_channels);
Fredrik Solenberg657b2962018-12-05 10:30:25 +0100392 acm_b_->SetReceiveCodecs({{120, {"OPUS", 48000, 2}}});
tina.legrand@webrtc.orgc4590582012-11-28 12:23:29 +0000393 Run(channel_a2b_, audio_channels, codec_channels);
394
395 // Encode in stereo, decode in mono.
Karl Wiberg36b37dc2018-09-24 10:52:32 +0200396 RegisterSendCodec('A', codec_opus, 48000, 32000, 960, 2);
tina.legrand@webrtc.orgc4590582012-11-28 12:23:29 +0000397 Run(channel_a2b_, audio_channels, codec_channels);
398
399 out_file_.Close();
400
401 // Test switching between decoding mono and stereo for Opus.
402
403 // Decode in mono.
404 test_cntr_++;
405 OpenOutFile(test_cntr_);
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000406 Run(channel_a2b_, audio_channels, codec_channels);
407 out_file_.Close();
tina.legrand@webrtc.orgc4590582012-11-28 12:23:29 +0000408 // Decode in stereo.
409 test_cntr_++;
410 OpenOutFile(test_cntr_);
Fredrik Solenberg657b2962018-12-05 10:30:25 +0100411 acm_b_->SetReceiveCodecs({{120, {"OPUS", 48000, 2, {{"stereo", "1"}}}}});
tina.legrand@webrtc.orgc4590582012-11-28 12:23:29 +0000412 Run(channel_a2b_, audio_channels, 2);
413 out_file_.Close();
414 // Decode in mono.
415 test_cntr_++;
416 OpenOutFile(test_cntr_);
Fredrik Solenberg657b2962018-12-05 10:30:25 +0100417 acm_b_->SetReceiveCodecs({{120, {"OPUS", 48000, 2}}});
tina.legrand@webrtc.orgc4590582012-11-28 12:23:29 +0000418 Run(channel_a2b_, audio_channels, codec_channels);
419 out_file_.Close();
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000420#endif
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000421
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000422 // Delete the file pointers.
423 delete in_file_stereo_;
424 delete in_file_mono_;
niklase@google.com470e71d2011-07-07 08:21:25 +0000425}
426
427// Register Codec to use in the test
428//
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000429// Input: side - which ACM to use, 'A' or 'B'
430// codec_name - name to use when register the codec
431// sampling_freq_hz - sampling frequency in Herz
432// rate - bitrate in bytes
433// pack_size - packet size in samples
434// channels - number of channels; 1 for mono, 2 for stereo
Yves Gerey665174f2018-06-19 15:03:05 +0200435void TestStereo::RegisterSendCodec(char side,
436 char* codec_name,
437 int32_t sampling_freq_hz,
438 int rate,
439 int pack_size,
Karl Wiberg36b37dc2018-09-24 10:52:32 +0200440 int channels) {
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000441 // Store packet size in samples, used to validate the received packet
442 pack_size_samp_ = pack_size;
443
444 // Store the expected packet size in bytes, used to validate the received
445 // packet. Add 0.875 to always round up to a whole byte.
pbos@webrtc.orgd8ca7232014-12-10 11:49:13 +0000446 pack_size_bytes_ = (uint16_t)(static_cast<float>(pack_size * rate) /
447 static_cast<float>(sampling_freq_hz * 8) +
448 0.875);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000449
450 // Set pointer to the ACM where to register the codec
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000451 AudioCodingModule* my_acm = NULL;
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000452 switch (side) {
453 case 'A': {
andrew@webrtc.org89df0922013-09-12 01:27:43 +0000454 my_acm = acm_a_.get();
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000455 break;
niklase@google.com470e71d2011-07-07 08:21:25 +0000456 }
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000457 case 'B': {
andrew@webrtc.org89df0922013-09-12 01:27:43 +0000458 my_acm = acm_b_.get();
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000459 break;
tina.legrand@webrtc.org16b6b902012-04-12 11:02:38 +0000460 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000461 default:
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000462 break;
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000463 }
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000464 ASSERT_TRUE(my_acm != NULL);
niklase@google.com470e71d2011-07-07 08:21:25 +0000465
Karl Wibergd363db12018-09-24 14:45:24 +0200466 auto encoder_factory = CreateBuiltinAudioEncoderFactory();
Niels Möller2edab4c2018-10-22 09:48:08 +0200467 const int clockrate_hz = absl::EqualsIgnoreCase(codec_name, "g722")
Karl Wibergd363db12018-09-24 14:45:24 +0200468 ? sampling_freq_hz / 2
469 : sampling_freq_hz;
470 const std::string ptime = rtc::ToString(rtc::CheckedDivExact(
471 pack_size, rtc::CheckedDivExact(sampling_freq_hz, 1000)));
472 SdpAudioFormat::Parameters params = {{"ptime", ptime}};
473 RTC_CHECK(channels == 1 || channels == 2);
Niels Möller2edab4c2018-10-22 09:48:08 +0200474 if (absl::EqualsIgnoreCase(codec_name, "opus")) {
Karl Wibergd363db12018-09-24 14:45:24 +0200475 if (channels == 2) {
476 params["stereo"] = "1";
477 }
478 channels = 2;
479 params["maxaveragebitrate"] = rtc::ToString(rate);
480 }
481 constexpr int payload_type = 17;
482 auto encoder = encoder_factory->MakeAudioEncoder(
483 payload_type, SdpAudioFormat(codec_name, clockrate_hz, channels, params),
484 absl::nullopt);
485 EXPECT_NE(nullptr, encoder);
486 my_acm->SetEncoder(std::move(encoder));
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000487
488 send_codec_name_ = codec_name;
niklase@google.com470e71d2011-07-07 08:21:25 +0000489}
490
Yves Gerey665174f2018-06-19 15:03:05 +0200491void TestStereo::Run(TestPackStereo* channel,
492 int in_channels,
493 int out_channels,
tina.legrand@webrtc.org16b6b902012-04-12 11:02:38 +0000494 int percent_loss) {
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000495 AudioFrame audio_frame;
niklase@google.com470e71d2011-07-07 08:21:25 +0000496
pbos@webrtc.org0946a562013-04-09 00:28:06 +0000497 int32_t out_freq_hz_b = out_file_.SamplingFrequency();
498 uint16_t rec_size;
499 uint32_t time_stamp_diff;
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000500 channel->reset_payload_size();
501 int error_count = 0;
tina.legrand@webrtc.org65d61c32014-06-05 13:42:51 +0000502 int variable_bytes = 0;
503 int variable_packets = 0;
Henrik Lundin4d682082015-12-10 16:24:39 +0100504 // Set test length to 500 ms (50 blocks of 10 ms each).
505 in_file_mono_->SetNum10MsBlocksToRead(50);
506 in_file_stereo_->SetNum10MsBlocksToRead(50);
507 // Fast-forward 1 second (100 blocks) since the files start with silence.
508 in_file_stereo_->FastForward(100);
509 in_file_mono_->FastForward(100);
niklase@google.com470e71d2011-07-07 08:21:25 +0000510
andresp@webrtc.orgd0b436a2014-01-13 13:15:59 +0000511 while (1) {
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000512 // Simulate packet loss by setting |packet_loss_| to "true" in
513 // |percent_loss| percent of the loops.
514 if (percent_loss > 0) {
515 if (counter_ == floor((100 / percent_loss) + 0.5)) {
516 counter_ = 0;
517 channel->set_lost_packet(true);
518 } else {
519 channel->set_lost_packet(false);
520 }
521 counter_++;
niklase@google.com470e71d2011-07-07 08:21:25 +0000522 }
523
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000524 // Add 10 msec to ACM
525 if (in_channels == 1) {
526 if (in_file_mono_->EndOfFile()) {
527 break;
528 }
529 in_file_mono_->Read10MsData(audio_frame);
530 } else {
531 if (in_file_stereo_->EndOfFile()) {
532 break;
533 }
534 in_file_stereo_->Read10MsData(audio_frame);
535 }
henrik.lundin@webrtc.orgf56c1622015-03-02 12:29:30 +0000536 EXPECT_GE(acm_a_->Add10MsData(audio_frame), 0);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000537
tina.legrand@webrtc.org65d61c32014-06-05 13:42:51 +0000538 // Verify that the received packet size matches the settings.
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000539 rec_size = channel->payload_size();
540 if ((0 < rec_size) & (rec_size < 65535)) {
tina.legrand@webrtc.org65d61c32014-06-05 13:42:51 +0000541 if (strcmp(send_codec_name_, "opus") == 0) {
542 // Opus is a variable rate codec, hence calculate the average packet
543 // size, and later make sure the average is in the right range.
544 variable_bytes += rec_size;
545 variable_packets++;
546 } else {
547 // For fixed rate codecs, check that packet size is correct.
Yves Gerey665174f2018-06-19 15:03:05 +0200548 if ((rec_size != pack_size_bytes_ * out_channels) &&
549 (pack_size_bytes_ < 65535)) {
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000550 error_count++;
551 }
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000552 }
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000553 // Verify that the timestamp is updated with expected length
554 time_stamp_diff = channel->timestamp_diff();
555 if ((counter_ > 10) && (time_stamp_diff != pack_size_samp_)) {
556 error_count++;
557 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000558 }
559
Fredrik Solenberg657b2962018-12-05 10:30:25 +0100560 // Run receive side of ACM
henrik.lundind4ccb002016-05-17 12:21:55 -0700561 bool muted;
562 EXPECT_EQ(0, acm_b_->PlayoutData10Ms(out_freq_hz_b, &audio_frame, &muted));
563 ASSERT_FALSE(muted);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000564
565 // Write output speech to file
566 out_file_.Write10MsData(
yujo36b1a5f2017-06-12 12:45:32 -0700567 audio_frame.data(),
andrew@webrtc.org63a50982012-05-02 23:56:37 +0000568 audio_frame.samples_per_channel_ * audio_frame.num_channels_);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000569 }
570
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000571 EXPECT_EQ(0, error_count);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000572
tina.legrand@webrtc.org65d61c32014-06-05 13:42:51 +0000573 // Check that packet size is in the right range for variable rate codecs,
574 // such as Opus.
575 if (variable_packets > 0) {
576 variable_bytes /= variable_packets;
Henrik Lundin4d682082015-12-10 16:24:39 +0100577 EXPECT_NEAR(variable_bytes, pack_size_bytes_, 18);
tina.legrand@webrtc.org65d61c32014-06-05 13:42:51 +0000578 }
579
andresp@webrtc.orgd0b436a2014-01-13 13:15:59 +0000580 if (in_file_mono_->EndOfFile()) {
581 in_file_mono_->Rewind();
582 }
583 if (in_file_stereo_->EndOfFile()) {
584 in_file_stereo_->Rewind();
585 }
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000586 // Reset in case we ended with a lost packet
587 channel->set_lost_packet(false);
niklase@google.com470e71d2011-07-07 08:21:25 +0000588}
589
pbos@webrtc.org0946a562013-04-09 00:28:06 +0000590void TestStereo::OpenOutFile(int16_t test_number) {
tina.legrand@webrtc.orgba468042012-08-17 10:38:28 +0000591 std::string file_name;
Jonas Olsson366a50c2018-09-06 13:41:30 +0200592 rtc::StringBuilder file_stream;
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000593 file_stream << webrtc::test::OutputPath() << "teststereo_out_" << test_number
Yves Gerey665174f2018-06-19 15:03:05 +0200594 << ".pcm";
tina.legrand@webrtc.orgba468042012-08-17 10:38:28 +0000595 file_name = file_stream.str();
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000596 out_file_.Open(file_name, 32000, "wb");
niklase@google.com470e71d2011-07-07 08:21:25 +0000597}
598
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000599} // namespace webrtc