blob: dd4be6a5245f4aebd93a59c7bedcb4105e54f2ed [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 Solenberg056f9732018-12-03 15:22:16 +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"
22#include "test/testsupport/fileutils.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
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000043int32_t TestPackStereo::SendData(const FrameType frame_type,
44 const uint8_t payload_type,
45 const uint32_t timestamp,
46 const uint8_t* payload_data,
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +000047 const size_t payload_size,
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000048 const RTPFragmentationHeader* fragmentation) {
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +000049 WebRtcRTPHeader rtp_info;
pbos@webrtc.org0946a562013-04-09 00:28:06 +000050 int32_t status = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +000051
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +000052 rtp_info.header.markerBit = false;
53 rtp_info.header.ssrc = 0;
54 rtp_info.header.sequenceNumber = seq_no_++;
55 rtp_info.header.payloadType = payload_type;
56 rtp_info.header.timestamp = timestamp;
pbos22993e12015-10-19 02:39:06 -070057 if (frame_type == kEmptyFrame) {
tina.legrand@webrtc.org16b6b902012-04-12 11:02:38 +000058 // Skip this frame
59 return 0;
60 }
niklase@google.com470e71d2011-07-07 08:21:25 +000061
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +000062 if (lost_packet_ == false) {
Yves Gerey665174f2018-06-19 15:03:05 +020063 status =
64 receiver_acm_->IncomingPacket(payload_data, payload_size, rtp_info);
niklase@google.com470e71d2011-07-07 08:21:25 +000065
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +000066 if (frame_type != kAudioFrameCN) {
henrike@webrtc.org6ac22e62014-08-11 21:06:30 +000067 payload_size_ = static_cast<int>(payload_size);
niklase@google.com470e71d2011-07-07 08:21:25 +000068 } else {
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +000069 payload_size_ = -1;
niklase@google.com470e71d2011-07-07 08:21:25 +000070 }
tina.legrand@webrtc.org16b6b902012-04-12 11:02:38 +000071
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +000072 timestamp_diff_ = timestamp - last_in_timestamp_;
73 last_in_timestamp_ = timestamp;
74 total_bytes_ += payload_size;
tina.legrand@webrtc.org16b6b902012-04-12 11:02:38 +000075 }
76 return status;
niklase@google.com470e71d2011-07-07 08:21:25 +000077}
78
pbos@webrtc.org0946a562013-04-09 00:28:06 +000079uint16_t TestPackStereo::payload_size() {
henrike@webrtc.org6ac22e62014-08-11 21:06:30 +000080 return static_cast<uint16_t>(payload_size_);
niklase@google.com470e71d2011-07-07 08:21:25 +000081}
82
pbos@webrtc.org0946a562013-04-09 00:28:06 +000083uint32_t TestPackStereo::timestamp_diff() {
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +000084 return timestamp_diff_;
niklase@google.com470e71d2011-07-07 08:21:25 +000085}
86
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +000087void TestPackStereo::reset_payload_size() {
88 payload_size_ = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +000089}
90
tina.legrand@webrtc.org16b6b902012-04-12 11:02:38 +000091void TestPackStereo::set_codec_mode(enum StereoMonoMode mode) {
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +000092 codec_mode_ = mode;
tina.legrand@webrtc.org16b6b902012-04-12 11:02:38 +000093}
94
95void TestPackStereo::set_lost_packet(bool lost) {
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +000096 lost_packet_ = lost;
niklase@google.com470e71d2011-07-07 08:21:25 +000097}
98
Fredrik Solenberg056f9732018-12-03 15:22:16 +010099TestStereo::TestStereo()
Karl Wiberg5817d3d2018-04-06 10:06:42 +0200100 : acm_a_(AudioCodingModule::Create(
101 AudioCodingModule::Config(CreateBuiltinAudioDecoderFactory()))),
102 acm_b_(AudioCodingModule::Create(
103 AudioCodingModule::Config(CreateBuiltinAudioDecoderFactory()))),
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000104 channel_a2b_(NULL),
105 test_cntr_(0),
106 pack_size_samp_(0),
107 pack_size_bytes_(0),
Karl Wiberg36b37dc2018-09-24 10:52:32 +0200108 counter_(0) {
niklase@google.com470e71d2011-07-07 08:21:25 +0000109}
110
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000111TestStereo::~TestStereo() {
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000112 if (channel_a2b_ != NULL) {
113 delete channel_a2b_;
114 channel_a2b_ = NULL;
115 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000116}
117
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000118void TestStereo::Perform() {
pbos@webrtc.org0946a562013-04-09 00:28:06 +0000119 uint16_t frequency_hz;
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000120 int audio_channels;
121 int codec_channels;
niklase@google.com470e71d2011-07-07 08:21:25 +0000122
tina.legrand@webrtc.org45175852012-06-01 09:27:35 +0000123 // Open both mono and stereo test files in 32 kHz.
Yves Gerey665174f2018-06-19 15:03:05 +0200124 const std::string file_name_stereo =
125 webrtc::test::ResourcePath("audio_coding/teststereo32kHz", "pcm");
126 const std::string file_name_mono =
127 webrtc::test::ResourcePath("audio_coding/testfile32kHz", "pcm");
tina.legrand@webrtc.org45175852012-06-01 09:27:35 +0000128 frequency_hz = 32000;
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000129 in_file_stereo_ = new PCMFile();
130 in_file_mono_ = new PCMFile();
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000131 in_file_stereo_->Open(file_name_stereo, frequency_hz, "rb");
132 in_file_stereo_->ReadStereo(true);
133 in_file_mono_->Open(file_name_mono, frequency_hz, "rb");
134 in_file_mono_->ReadStereo(false);
135
tina.legrand@webrtc.org45175852012-06-01 09:27:35 +0000136 // Create and initialize two ACMs, one for each side of a one-to-one call.
andrew@webrtc.org89df0922013-09-12 01:27:43 +0000137 ASSERT_TRUE((acm_a_.get() != NULL) && (acm_b_.get() != NULL));
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000138 EXPECT_EQ(0, acm_a_->InitializeReceiver());
139 EXPECT_EQ(0, acm_b_->InitializeReceiver());
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000140
Fredrik Solenberg056f9732018-12-03 15:22:16 +0100141 acm_b_->SetReceiveCodecs({{103, {"ISAC", 16000, 1}},
142 {104, {"ISAC", 32000, 1}},
143 {107, {"L16", 8000, 1}},
144 {108, {"L16", 16000, 1}},
145 {109, {"L16", 32000, 1}},
146 {111, {"L16", 8000, 2}},
147 {112, {"L16", 16000, 2}},
148 {113, {"L16", 32000, 2}},
149 {0, {"PCMU", 8000, 1}},
150 {110, {"PCMU", 8000, 2}},
151 {8, {"PCMA", 8000, 1}},
152 {118, {"PCMA", 8000, 2}},
153 {102, {"ILBC", 8000, 1}},
154 {9, {"G722", 8000, 1}},
155 {119, {"G722", 8000, 2}},
156 {120, {"OPUS", 48000, 2, {{"stereo", "1"}}}},
157 {13, {"CN", 8000, 1}},
158 {98, {"CN", 16000, 1}},
159 {99, {"CN", 32000, 1}}});
tina.legrand@webrtc.orgae1c4542012-03-12 08:41:30 +0000160
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000161 // Create and connect the channel.
162 channel_a2b_ = new TestPackStereo;
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000163 EXPECT_EQ(0, acm_a_->RegisterTransportCallback(channel_a2b_));
andrew@webrtc.org89df0922013-09-12 01:27:43 +0000164 channel_a2b_->RegisterReceiverACM(acm_b_.get());
tina.legrand@webrtc.orgdf697752012-02-08 10:22:21 +0000165
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000166 char codec_pcma_temp[] = "PCMA";
Karl Wiberg36b37dc2018-09-24 10:52:32 +0200167 RegisterSendCodec('A', codec_pcma_temp, 8000, 64000, 80, 2);
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000168
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000169 //
170 // Test Stereo-To-Stereo for all codecs.
171 //
172 audio_channels = 2;
173 codec_channels = 2;
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000174
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000175 // All codecs are tested for all allowed sampling frequencies, rates and
176 // packet sizes.
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000177 channel_a2b_->set_codec_mode(kStereo);
178 test_cntr_++;
179 OpenOutFile(test_cntr_);
180 char codec_g722[] = "G722";
Karl Wiberg36b37dc2018-09-24 10:52:32 +0200181 RegisterSendCodec('A', codec_g722, 16000, 64000, 160, 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, 320, 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, 480, 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, 640, 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, 800, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000190 Run(channel_a2b_, audio_channels, codec_channels);
Karl Wiberg36b37dc2018-09-24 10:52:32 +0200191 RegisterSendCodec('A', codec_g722, 16000, 64000, 960, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000192 Run(channel_a2b_, audio_channels, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000193 out_file_.Close();
Karl Wibergeb254b42017-11-01 15:08:12 +0100194
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000195 channel_a2b_->set_codec_mode(kStereo);
196 test_cntr_++;
197 OpenOutFile(test_cntr_);
198 char codec_l16[] = "L16";
Karl Wiberg36b37dc2018-09-24 10:52:32 +0200199 RegisterSendCodec('A', codec_l16, 8000, 128000, 80, 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, 160, 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, 240, 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_l16, 8000, 128000, 320, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000206 Run(channel_a2b_, audio_channels, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000207 out_file_.Close();
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000208
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000209 test_cntr_++;
210 OpenOutFile(test_cntr_);
Karl Wiberg36b37dc2018-09-24 10:52:32 +0200211 RegisterSendCodec('A', codec_l16, 16000, 256000, 160, 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, 320, 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, 480, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000216 Run(channel_a2b_, audio_channels, codec_channels);
Karl Wiberg36b37dc2018-09-24 10:52:32 +0200217 RegisterSendCodec('A', codec_l16, 16000, 256000, 640, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000218 Run(channel_a2b_, audio_channels, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000219 out_file_.Close();
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000220
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000221 test_cntr_++;
222 OpenOutFile(test_cntr_);
Karl Wiberg36b37dc2018-09-24 10:52:32 +0200223 RegisterSendCodec('A', codec_l16, 32000, 512000, 320, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000224 Run(channel_a2b_, audio_channels, codec_channels);
Karl Wiberg36b37dc2018-09-24 10:52:32 +0200225 RegisterSendCodec('A', codec_l16, 32000, 512000, 640, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000226 Run(channel_a2b_, audio_channels, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000227 out_file_.Close();
niklase@google.com470e71d2011-07-07 08:21:25 +0000228#ifdef PCMA_AND_PCMU
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000229 channel_a2b_->set_codec_mode(kStereo);
230 audio_channels = 2;
231 codec_channels = 2;
232 test_cntr_++;
233 OpenOutFile(test_cntr_);
234 char codec_pcma[] = "PCMA";
Karl Wiberg36b37dc2018-09-24 10:52:32 +0200235 RegisterSendCodec('A', codec_pcma, 8000, 64000, 80, 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, 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_pcma, 8000, 64000, 240, 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, 320, 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, 400, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000244 Run(channel_a2b_, audio_channels, codec_channels);
Karl Wiberg36b37dc2018-09-24 10:52:32 +0200245 RegisterSendCodec('A', codec_pcma, 8000, 64000, 480, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000246 Run(channel_a2b_, audio_channels, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000247 out_file_.Close();
Fredrik Solenberg056f9732018-12-03 15:22:16 +0100248
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000249 test_cntr_++;
250 OpenOutFile(test_cntr_);
251 char codec_pcmu[] = "PCMU";
Karl Wiberg36b37dc2018-09-24 10:52:32 +0200252 RegisterSendCodec('A', codec_pcmu, 8000, 64000, 80, 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, 160, 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, 240, 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, 320, 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, 400, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000261 Run(channel_a2b_, audio_channels, codec_channels);
Karl Wiberg36b37dc2018-09-24 10:52:32 +0200262 RegisterSendCodec('A', codec_pcmu, 8000, 64000, 480, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000263 Run(channel_a2b_, audio_channels, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000264 out_file_.Close();
niklase@google.com470e71d2011-07-07 08:21:25 +0000265#endif
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000266#ifdef WEBRTC_CODEC_OPUS
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000267 channel_a2b_->set_codec_mode(kStereo);
268 audio_channels = 2;
269 codec_channels = 2;
270 test_cntr_++;
271 OpenOutFile(test_cntr_);
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000272
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000273 char codec_opus[] = "opus";
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000274 // Run Opus with 10 ms frame size.
Karl Wiberg36b37dc2018-09-24 10:52:32 +0200275 RegisterSendCodec('A', codec_opus, 48000, 64000, 480, codec_channels);
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000276 Run(channel_a2b_, audio_channels, codec_channels);
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000277 // Run Opus with 20 ms frame size.
Karl Wiberg36b37dc2018-09-24 10:52:32 +0200278 RegisterSendCodec('A', codec_opus, 48000, 64000, 480 * 2, codec_channels);
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000279 Run(channel_a2b_, audio_channels, codec_channels);
280 // Run Opus with 40 ms frame size.
Karl Wiberg36b37dc2018-09-24 10:52:32 +0200281 RegisterSendCodec('A', codec_opus, 48000, 64000, 480 * 4, codec_channels);
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000282 Run(channel_a2b_, audio_channels, codec_channels);
283 // Run Opus with 60 ms frame size.
Karl Wiberg36b37dc2018-09-24 10:52:32 +0200284 RegisterSendCodec('A', codec_opus, 48000, 64000, 480 * 6, codec_channels);
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000285 Run(channel_a2b_, audio_channels, codec_channels);
286 // Run Opus with 20 ms frame size and different bitrates.
Karl Wiberg36b37dc2018-09-24 10:52:32 +0200287 RegisterSendCodec('A', codec_opus, 48000, 40000, 960, codec_channels);
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000288 Run(channel_a2b_, audio_channels, codec_channels);
Karl Wiberg36b37dc2018-09-24 10:52:32 +0200289 RegisterSendCodec('A', codec_opus, 48000, 510000, 960, codec_channels);
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000290 Run(channel_a2b_, audio_channels, codec_channels);
291 out_file_.Close();
292#endif
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000293 //
294 // Test Mono-To-Stereo for all codecs.
295 //
296 audio_channels = 1;
297 codec_channels = 2;
niklase@google.com470e71d2011-07-07 08:21:25 +0000298
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000299 test_cntr_++;
300 channel_a2b_->set_codec_mode(kStereo);
301 OpenOutFile(test_cntr_);
Karl Wiberg36b37dc2018-09-24 10:52:32 +0200302 RegisterSendCodec('A', codec_g722, 16000, 64000, 160, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000303 Run(channel_a2b_, audio_channels, codec_channels);
304 out_file_.Close();
Karl Wibergeb254b42017-11-01 15:08:12 +0100305
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000306 test_cntr_++;
307 channel_a2b_->set_codec_mode(kStereo);
308 OpenOutFile(test_cntr_);
Karl Wiberg36b37dc2018-09-24 10:52:32 +0200309 RegisterSendCodec('A', codec_l16, 8000, 128000, 80, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000310 Run(channel_a2b_, audio_channels, codec_channels);
311 out_file_.Close();
Fredrik Solenberg056f9732018-12-03 15:22:16 +0100312
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000313 test_cntr_++;
314 OpenOutFile(test_cntr_);
Karl Wiberg36b37dc2018-09-24 10:52:32 +0200315 RegisterSendCodec('A', codec_l16, 16000, 256000, 160, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000316 Run(channel_a2b_, audio_channels, codec_channels);
317 out_file_.Close();
Fredrik Solenberg056f9732018-12-03 15:22:16 +0100318
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000319 test_cntr_++;
320 OpenOutFile(test_cntr_);
Karl Wiberg36b37dc2018-09-24 10:52:32 +0200321 RegisterSendCodec('A', codec_l16, 32000, 512000, 320, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000322 Run(channel_a2b_, audio_channels, codec_channels);
323 out_file_.Close();
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000324#ifdef PCMA_AND_PCMU
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000325 test_cntr_++;
326 channel_a2b_->set_codec_mode(kStereo);
327 OpenOutFile(test_cntr_);
Karl Wiberg36b37dc2018-09-24 10:52:32 +0200328 RegisterSendCodec('A', codec_pcmu, 8000, 64000, 80, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000329 Run(channel_a2b_, audio_channels, codec_channels);
Karl Wiberg36b37dc2018-09-24 10:52:32 +0200330 RegisterSendCodec('A', codec_pcma, 8000, 64000, 80, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000331 Run(channel_a2b_, audio_channels, codec_channels);
332 out_file_.Close();
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000333#endif
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000334#ifdef WEBRTC_CODEC_OPUS
tina.legrand@webrtc.orgc4590582012-11-28 12:23:29 +0000335 // Keep encode and decode in stereo.
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000336 test_cntr_++;
337 channel_a2b_->set_codec_mode(kStereo);
338 OpenOutFile(test_cntr_);
Karl Wiberg36b37dc2018-09-24 10:52:32 +0200339 RegisterSendCodec('A', codec_opus, 48000, 64000, 960, codec_channels);
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000340 Run(channel_a2b_, audio_channels, codec_channels);
tina.legrand@webrtc.orgc4590582012-11-28 12:23:29 +0000341
342 // Encode in mono, decode in stereo mode.
Karl Wiberg36b37dc2018-09-24 10:52:32 +0200343 RegisterSendCodec('A', codec_opus, 48000, 64000, 960, 1);
tina.legrand@webrtc.orgc4590582012-11-28 12:23:29 +0000344 Run(channel_a2b_, audio_channels, codec_channels);
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000345 out_file_.Close();
346#endif
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000347
348 //
349 // Test Stereo-To-Mono for all codecs.
350 //
351 audio_channels = 2;
352 codec_channels = 1;
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000353 channel_a2b_->set_codec_mode(kMono);
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000354
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000355 // Run stereo audio and mono codec.
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000356 test_cntr_++;
357 OpenOutFile(test_cntr_);
Karl Wiberg36b37dc2018-09-24 10:52:32 +0200358 RegisterSendCodec('A', codec_g722, 16000, 64000, 160, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000359 Run(channel_a2b_, audio_channels, codec_channels);
360 out_file_.Close();
Karl Wibergeb254b42017-11-01 15:08:12 +0100361
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000362 test_cntr_++;
363 OpenOutFile(test_cntr_);
Karl Wiberg36b37dc2018-09-24 10:52:32 +0200364 RegisterSendCodec('A', codec_l16, 8000, 128000, 80, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000365 Run(channel_a2b_, audio_channels, codec_channels);
366 out_file_.Close();
Fredrik Solenberg056f9732018-12-03 15:22:16 +0100367
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000368 test_cntr_++;
369 OpenOutFile(test_cntr_);
Karl Wiberg36b37dc2018-09-24 10:52:32 +0200370 RegisterSendCodec('A', codec_l16, 16000, 256000, 160, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000371 Run(channel_a2b_, audio_channels, codec_channels);
372 out_file_.Close();
Fredrik Solenberg056f9732018-12-03 15:22:16 +0100373
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000374 test_cntr_++;
375 OpenOutFile(test_cntr_);
Karl Wiberg36b37dc2018-09-24 10:52:32 +0200376 RegisterSendCodec('A', codec_l16, 32000, 512000, 320, codec_channels);
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000377 Run(channel_a2b_, audio_channels, codec_channels);
378 out_file_.Close();
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000379#ifdef PCMA_AND_PCMU
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000380 test_cntr_++;
381 OpenOutFile(test_cntr_);
Karl Wiberg36b37dc2018-09-24 10:52:32 +0200382 RegisterSendCodec('A', codec_pcmu, 8000, 64000, 80, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000383 Run(channel_a2b_, audio_channels, codec_channels);
Karl Wiberg36b37dc2018-09-24 10:52:32 +0200384 RegisterSendCodec('A', codec_pcma, 8000, 64000, 80, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000385 Run(channel_a2b_, audio_channels, codec_channels);
386 out_file_.Close();
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000387#endif
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000388#ifdef WEBRTC_CODEC_OPUS
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000389 test_cntr_++;
390 OpenOutFile(test_cntr_);
tina.legrand@webrtc.orgc4590582012-11-28 12:23:29 +0000391 // Encode and decode in mono.
Karl Wiberg36b37dc2018-09-24 10:52:32 +0200392 RegisterSendCodec('A', codec_opus, 48000, 32000, 960, codec_channels);
Fredrik Solenberg056f9732018-12-03 15:22:16 +0100393 acm_b_->SetReceiveCodecs({{120, {"OPUS", 48000, 2}}});
tina.legrand@webrtc.orgc4590582012-11-28 12:23:29 +0000394 Run(channel_a2b_, audio_channels, codec_channels);
395
396 // Encode in stereo, decode in mono.
Karl Wiberg36b37dc2018-09-24 10:52:32 +0200397 RegisterSendCodec('A', codec_opus, 48000, 32000, 960, 2);
tina.legrand@webrtc.orgc4590582012-11-28 12:23:29 +0000398 Run(channel_a2b_, audio_channels, codec_channels);
399
400 out_file_.Close();
401
402 // Test switching between decoding mono and stereo for Opus.
403
404 // Decode in mono.
405 test_cntr_++;
406 OpenOutFile(test_cntr_);
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000407 Run(channel_a2b_, audio_channels, codec_channels);
408 out_file_.Close();
tina.legrand@webrtc.orgc4590582012-11-28 12:23:29 +0000409 // Decode in stereo.
410 test_cntr_++;
411 OpenOutFile(test_cntr_);
Fredrik Solenberg056f9732018-12-03 15:22:16 +0100412 acm_b_->SetReceiveCodecs({{120, {"OPUS", 48000, 2, {{"stereo", "1"}}}}});
tina.legrand@webrtc.orgc4590582012-11-28 12:23:29 +0000413 Run(channel_a2b_, audio_channels, 2);
414 out_file_.Close();
415 // Decode in mono.
416 test_cntr_++;
417 OpenOutFile(test_cntr_);
Fredrik Solenberg056f9732018-12-03 15:22:16 +0100418 acm_b_->SetReceiveCodecs({{120, {"OPUS", 48000, 2}}});
tina.legrand@webrtc.orgc4590582012-11-28 12:23:29 +0000419 Run(channel_a2b_, audio_channels, codec_channels);
420 out_file_.Close();
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000421#endif
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000422
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000423 // Delete the file pointers.
424 delete in_file_stereo_;
425 delete in_file_mono_;
niklase@google.com470e71d2011-07-07 08:21:25 +0000426}
427
428// Register Codec to use in the test
429//
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000430// Input: side - which ACM to use, 'A' or 'B'
431// codec_name - name to use when register the codec
432// sampling_freq_hz - sampling frequency in Herz
433// rate - bitrate in bytes
434// pack_size - packet size in samples
435// channels - number of channels; 1 for mono, 2 for stereo
Yves Gerey665174f2018-06-19 15:03:05 +0200436void TestStereo::RegisterSendCodec(char side,
437 char* codec_name,
438 int32_t sampling_freq_hz,
439 int rate,
440 int pack_size,
Karl Wiberg36b37dc2018-09-24 10:52:32 +0200441 int channels) {
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000442 // Store packet size in samples, used to validate the received packet
443 pack_size_samp_ = pack_size;
444
445 // Store the expected packet size in bytes, used to validate the received
446 // packet. Add 0.875 to always round up to a whole byte.
pbos@webrtc.orgd8ca7232014-12-10 11:49:13 +0000447 pack_size_bytes_ = (uint16_t)(static_cast<float>(pack_size * rate) /
448 static_cast<float>(sampling_freq_hz * 8) +
449 0.875);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000450
451 // Set pointer to the ACM where to register the codec
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000452 AudioCodingModule* my_acm = NULL;
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000453 switch (side) {
454 case 'A': {
andrew@webrtc.org89df0922013-09-12 01:27:43 +0000455 my_acm = acm_a_.get();
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000456 break;
niklase@google.com470e71d2011-07-07 08:21:25 +0000457 }
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000458 case 'B': {
andrew@webrtc.org89df0922013-09-12 01:27:43 +0000459 my_acm = acm_b_.get();
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000460 break;
tina.legrand@webrtc.org16b6b902012-04-12 11:02:38 +0000461 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000462 default:
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000463 break;
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000464 }
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000465 ASSERT_TRUE(my_acm != NULL);
niklase@google.com470e71d2011-07-07 08:21:25 +0000466
Karl Wibergd363db12018-09-24 14:45:24 +0200467 auto encoder_factory = CreateBuiltinAudioEncoderFactory();
Niels Möller2edab4c2018-10-22 09:48:08 +0200468 const int clockrate_hz = absl::EqualsIgnoreCase(codec_name, "g722")
Karl Wibergd363db12018-09-24 14:45:24 +0200469 ? sampling_freq_hz / 2
470 : sampling_freq_hz;
471 const std::string ptime = rtc::ToString(rtc::CheckedDivExact(
472 pack_size, rtc::CheckedDivExact(sampling_freq_hz, 1000)));
473 SdpAudioFormat::Parameters params = {{"ptime", ptime}};
474 RTC_CHECK(channels == 1 || channels == 2);
Niels Möller2edab4c2018-10-22 09:48:08 +0200475 if (absl::EqualsIgnoreCase(codec_name, "opus")) {
Karl Wibergd363db12018-09-24 14:45:24 +0200476 if (channels == 2) {
477 params["stereo"] = "1";
478 }
479 channels = 2;
480 params["maxaveragebitrate"] = rtc::ToString(rate);
481 }
482 constexpr int payload_type = 17;
483 auto encoder = encoder_factory->MakeAudioEncoder(
484 payload_type, SdpAudioFormat(codec_name, clockrate_hz, channels, params),
485 absl::nullopt);
486 EXPECT_NE(nullptr, encoder);
487 my_acm->SetEncoder(std::move(encoder));
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000488
489 send_codec_name_ = codec_name;
niklase@google.com470e71d2011-07-07 08:21:25 +0000490}
491
Yves Gerey665174f2018-06-19 15:03:05 +0200492void TestStereo::Run(TestPackStereo* channel,
493 int in_channels,
494 int out_channels,
tina.legrand@webrtc.org16b6b902012-04-12 11:02:38 +0000495 int percent_loss) {
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000496 AudioFrame audio_frame;
niklase@google.com470e71d2011-07-07 08:21:25 +0000497
pbos@webrtc.org0946a562013-04-09 00:28:06 +0000498 int32_t out_freq_hz_b = out_file_.SamplingFrequency();
499 uint16_t rec_size;
500 uint32_t time_stamp_diff;
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000501 channel->reset_payload_size();
502 int error_count = 0;
tina.legrand@webrtc.org65d61c32014-06-05 13:42:51 +0000503 int variable_bytes = 0;
504 int variable_packets = 0;
Henrik Lundin4d682082015-12-10 16:24:39 +0100505 // Set test length to 500 ms (50 blocks of 10 ms each).
506 in_file_mono_->SetNum10MsBlocksToRead(50);
507 in_file_stereo_->SetNum10MsBlocksToRead(50);
508 // Fast-forward 1 second (100 blocks) since the files start with silence.
509 in_file_stereo_->FastForward(100);
510 in_file_mono_->FastForward(100);
niklase@google.com470e71d2011-07-07 08:21:25 +0000511
andresp@webrtc.orgd0b436a2014-01-13 13:15:59 +0000512 while (1) {
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000513 // Simulate packet loss by setting |packet_loss_| to "true" in
514 // |percent_loss| percent of the loops.
515 if (percent_loss > 0) {
516 if (counter_ == floor((100 / percent_loss) + 0.5)) {
517 counter_ = 0;
518 channel->set_lost_packet(true);
519 } else {
520 channel->set_lost_packet(false);
521 }
522 counter_++;
niklase@google.com470e71d2011-07-07 08:21:25 +0000523 }
524
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000525 // Add 10 msec to ACM
526 if (in_channels == 1) {
527 if (in_file_mono_->EndOfFile()) {
528 break;
529 }
530 in_file_mono_->Read10MsData(audio_frame);
531 } else {
532 if (in_file_stereo_->EndOfFile()) {
533 break;
534 }
535 in_file_stereo_->Read10MsData(audio_frame);
536 }
henrik.lundin@webrtc.orgf56c1622015-03-02 12:29:30 +0000537 EXPECT_GE(acm_a_->Add10MsData(audio_frame), 0);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000538
tina.legrand@webrtc.org65d61c32014-06-05 13:42:51 +0000539 // Verify that the received packet size matches the settings.
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000540 rec_size = channel->payload_size();
541 if ((0 < rec_size) & (rec_size < 65535)) {
tina.legrand@webrtc.org65d61c32014-06-05 13:42:51 +0000542 if (strcmp(send_codec_name_, "opus") == 0) {
543 // Opus is a variable rate codec, hence calculate the average packet
544 // size, and later make sure the average is in the right range.
545 variable_bytes += rec_size;
546 variable_packets++;
547 } else {
548 // For fixed rate codecs, check that packet size is correct.
Yves Gerey665174f2018-06-19 15:03:05 +0200549 if ((rec_size != pack_size_bytes_ * out_channels) &&
550 (pack_size_bytes_ < 65535)) {
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000551 error_count++;
552 }
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000553 }
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000554 // Verify that the timestamp is updated with expected length
555 time_stamp_diff = channel->timestamp_diff();
556 if ((counter_ > 10) && (time_stamp_diff != pack_size_samp_)) {
557 error_count++;
558 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000559 }
560
Fredrik Solenberg056f9732018-12-03 15:22:16 +0100561 // Run receive side of ACM
henrik.lundind4ccb002016-05-17 12:21:55 -0700562 bool muted;
563 EXPECT_EQ(0, acm_b_->PlayoutData10Ms(out_freq_hz_b, &audio_frame, &muted));
564 ASSERT_FALSE(muted);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000565
566 // Write output speech to file
567 out_file_.Write10MsData(
yujo36b1a5f2017-06-12 12:45:32 -0700568 audio_frame.data(),
andrew@webrtc.org63a50982012-05-02 23:56:37 +0000569 audio_frame.samples_per_channel_ * audio_frame.num_channels_);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000570 }
571
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000572 EXPECT_EQ(0, error_count);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000573
tina.legrand@webrtc.org65d61c32014-06-05 13:42:51 +0000574 // Check that packet size is in the right range for variable rate codecs,
575 // such as Opus.
576 if (variable_packets > 0) {
577 variable_bytes /= variable_packets;
Henrik Lundin4d682082015-12-10 16:24:39 +0100578 EXPECT_NEAR(variable_bytes, pack_size_bytes_, 18);
tina.legrand@webrtc.org65d61c32014-06-05 13:42:51 +0000579 }
580
andresp@webrtc.orgd0b436a2014-01-13 13:15:59 +0000581 if (in_file_mono_->EndOfFile()) {
582 in_file_mono_->Rewind();
583 }
584 if (in_file_stereo_->EndOfFile()) {
585 in_file_stereo_->Rewind();
586 }
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000587 // Reset in case we ended with a lost packet
588 channel->set_lost_packet(false);
niklase@google.com470e71d2011-07-07 08:21:25 +0000589}
590
pbos@webrtc.org0946a562013-04-09 00:28:06 +0000591void TestStereo::OpenOutFile(int16_t test_number) {
tina.legrand@webrtc.orgba468042012-08-17 10:38:28 +0000592 std::string file_name;
Jonas Olsson366a50c2018-09-06 13:41:30 +0200593 rtc::StringBuilder file_stream;
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000594 file_stream << webrtc::test::OutputPath() << "teststereo_out_" << test_number
Yves Gerey665174f2018-06-19 15:03:05 +0200595 << ".pcm";
tina.legrand@webrtc.orgba468042012-08-17 10:38:28 +0000596 file_name = file_stream.str();
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000597 out_file_.Open(file_name, 32000, "wb");
niklase@google.com470e71d2011-07-07 08:21:25 +0000598}
599
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000600} // namespace webrtc