blob: 94a15760260486103113fc5d0cde4bdc3dc6fec8 [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
Henrik Lundin84f75692023-02-01 12:07:10 +000038void TestPackStereo::RegisterReceiverACM(acm2::AcmReceiver* acm_receiver) {
39 receiver_acm_ = acm_receiver;
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +000040 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,
Minyue Liff0e4db2020-01-23 13:45:50 +010047 const size_t payload_size,
48 int64_t absolute_capture_timestamp_ms) {
Niels Möllerafb5dbb2019-02-15 15:21:47 +010049 RTPHeader rtp_header;
pbos@webrtc.org0946a562013-04-09 00:28:06 +000050 int32_t status = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +000051
Niels Möllerafb5dbb2019-02-15 15:21:47 +010052 rtp_header.markerBit = false;
53 rtp_header.ssrc = 0;
54 rtp_header.sequenceNumber = seq_no_++;
55 rtp_header.payloadType = payload_type;
56 rtp_header.timestamp = timestamp;
Niels Möllerc936cb62019-03-19 14:10:16 +010057 if (frame_type == AudioFrameType::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) {
Henrik Lundin84f75692023-02-01 12:07:10 +000063 status = receiver_acm_->InsertPacket(
64 rtp_header, rtc::ArrayView<const uint8_t>(payload_data, payload_size));
niklase@google.com470e71d2011-07-07 08:21:25 +000065
Niels Möllerc936cb62019-03-19 14:10:16 +010066 if (frame_type != AudioFrameType::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 Solenberg657b2962018-12-05 10:30:25 +010099TestStereo::TestStereo()
Henrik Lundin84f75692023-02-01 12:07:10 +0000100 : acm_a_(AudioCodingModule::Create()),
101 acm_b_(std::make_unique<acm2::AcmReceiver>(
102 acm2::AcmReceiver::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));
Henrik Lundin84f75692023-02-01 12:07:10 +0000136 acm_b_->FlushBuffers();
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000137
Henrik Lundin84f75692023-02-01 12:07:10 +0000138 acm_b_->SetCodecs({{103, {"ISAC", 16000, 1}},
139 {104, {"ISAC", 32000, 1}},
140 {107, {"L16", 8000, 1}},
141 {108, {"L16", 16000, 1}},
142 {109, {"L16", 32000, 1}},
143 {111, {"L16", 8000, 2}},
144 {112, {"L16", 16000, 2}},
145 {113, {"L16", 32000, 2}},
146 {0, {"PCMU", 8000, 1}},
147 {110, {"PCMU", 8000, 2}},
148 {8, {"PCMA", 8000, 1}},
149 {118, {"PCMA", 8000, 2}},
150 {102, {"ILBC", 8000, 1}},
151 {9, {"G722", 8000, 1}},
152 {119, {"G722", 8000, 2}},
153 {120, {"OPUS", 48000, 2, {{"stereo", "1"}}}},
154 {13, {"CN", 8000, 1}},
155 {98, {"CN", 16000, 1}},
156 {99, {"CN", 32000, 1}}});
tina.legrand@webrtc.orgae1c4542012-03-12 08:41:30 +0000157
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000158 // Create and connect the channel.
159 channel_a2b_ = new TestPackStereo;
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000160 EXPECT_EQ(0, acm_a_->RegisterTransportCallback(channel_a2b_));
andrew@webrtc.org89df0922013-09-12 01:27:43 +0000161 channel_a2b_->RegisterReceiverACM(acm_b_.get());
tina.legrand@webrtc.orgdf697752012-02-08 10:22:21 +0000162
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000163 char codec_pcma_temp[] = "PCMA";
Karl Wiberg36b37dc2018-09-24 10:52:32 +0200164 RegisterSendCodec('A', codec_pcma_temp, 8000, 64000, 80, 2);
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000165
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000166 //
167 // Test Stereo-To-Stereo for all codecs.
168 //
169 audio_channels = 2;
170 codec_channels = 2;
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000171
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000172 // All codecs are tested for all allowed sampling frequencies, rates and
173 // packet sizes.
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000174 channel_a2b_->set_codec_mode(kStereo);
175 test_cntr_++;
176 OpenOutFile(test_cntr_);
177 char codec_g722[] = "G722";
Karl Wiberg36b37dc2018-09-24 10:52:32 +0200178 RegisterSendCodec('A', codec_g722, 16000, 64000, 160, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000179 Run(channel_a2b_, audio_channels, codec_channels);
Karl Wiberg36b37dc2018-09-24 10:52:32 +0200180 RegisterSendCodec('A', codec_g722, 16000, 64000, 320, 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, 480, 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, 640, 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, 800, 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, 960, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000189 Run(channel_a2b_, audio_channels, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000190 out_file_.Close();
Karl Wibergeb254b42017-11-01 15:08:12 +0100191
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000192 channel_a2b_->set_codec_mode(kStereo);
193 test_cntr_++;
194 OpenOutFile(test_cntr_);
195 char codec_l16[] = "L16";
Karl Wiberg36b37dc2018-09-24 10:52:32 +0200196 RegisterSendCodec('A', codec_l16, 8000, 128000, 80, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000197 Run(channel_a2b_, audio_channels, codec_channels);
Karl Wiberg36b37dc2018-09-24 10:52:32 +0200198 RegisterSendCodec('A', codec_l16, 8000, 128000, 160, 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, 240, 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, 320, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000203 Run(channel_a2b_, audio_channels, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000204 out_file_.Close();
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000205
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000206 test_cntr_++;
207 OpenOutFile(test_cntr_);
Karl Wiberg36b37dc2018-09-24 10:52:32 +0200208 RegisterSendCodec('A', codec_l16, 16000, 256000, 160, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000209 Run(channel_a2b_, audio_channels, codec_channels);
Karl Wiberg36b37dc2018-09-24 10:52:32 +0200210 RegisterSendCodec('A', codec_l16, 16000, 256000, 320, 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, 480, 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, 640, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000215 Run(channel_a2b_, audio_channels, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000216 out_file_.Close();
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000217
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000218 test_cntr_++;
219 OpenOutFile(test_cntr_);
Karl Wiberg36b37dc2018-09-24 10:52:32 +0200220 RegisterSendCodec('A', codec_l16, 32000, 512000, 320, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000221 Run(channel_a2b_, audio_channels, codec_channels);
Karl Wiberg36b37dc2018-09-24 10:52:32 +0200222 RegisterSendCodec('A', codec_l16, 32000, 512000, 640, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000223 Run(channel_a2b_, audio_channels, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000224 out_file_.Close();
niklase@google.com470e71d2011-07-07 08:21:25 +0000225#ifdef PCMA_AND_PCMU
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000226 channel_a2b_->set_codec_mode(kStereo);
227 audio_channels = 2;
228 codec_channels = 2;
229 test_cntr_++;
230 OpenOutFile(test_cntr_);
231 char codec_pcma[] = "PCMA";
Karl Wiberg36b37dc2018-09-24 10:52:32 +0200232 RegisterSendCodec('A', codec_pcma, 8000, 64000, 80, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000233 Run(channel_a2b_, audio_channels, codec_channels);
Karl Wiberg36b37dc2018-09-24 10:52:32 +0200234 RegisterSendCodec('A', codec_pcma, 8000, 64000, 160, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000235 Run(channel_a2b_, audio_channels, codec_channels);
Karl Wiberg36b37dc2018-09-24 10:52:32 +0200236 RegisterSendCodec('A', codec_pcma, 8000, 64000, 240, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000237 Run(channel_a2b_, audio_channels, codec_channels);
Karl Wiberg36b37dc2018-09-24 10:52:32 +0200238 RegisterSendCodec('A', codec_pcma, 8000, 64000, 320, 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, 400, 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, 480, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000243 Run(channel_a2b_, audio_channels, codec_channels);
Fredrik Solenbergec0f45b2018-12-03 15:50:44 +0000244 out_file_.Close();
Fredrik Solenberg657b2962018-12-05 10:30:25 +0100245
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000246 test_cntr_++;
247 OpenOutFile(test_cntr_);
248 char codec_pcmu[] = "PCMU";
Karl Wiberg36b37dc2018-09-24 10:52:32 +0200249 RegisterSendCodec('A', codec_pcmu, 8000, 64000, 80, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000250 Run(channel_a2b_, audio_channels, codec_channels);
Karl Wiberg36b37dc2018-09-24 10:52:32 +0200251 RegisterSendCodec('A', codec_pcmu, 8000, 64000, 160, 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, 240, 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, 320, 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, 400, 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, 480, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000260 Run(channel_a2b_, audio_channels, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000261 out_file_.Close();
niklase@google.com470e71d2011-07-07 08:21:25 +0000262#endif
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000263#ifdef WEBRTC_CODEC_OPUS
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000264 channel_a2b_->set_codec_mode(kStereo);
265 audio_channels = 2;
266 codec_channels = 2;
267 test_cntr_++;
268 OpenOutFile(test_cntr_);
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000269
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000270 char codec_opus[] = "opus";
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000271 // Run Opus with 10 ms frame size.
Karl Wiberg36b37dc2018-09-24 10:52:32 +0200272 RegisterSendCodec('A', codec_opus, 48000, 64000, 480, codec_channels);
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000273 Run(channel_a2b_, audio_channels, codec_channels);
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000274 // Run Opus with 20 ms frame size.
Karl Wiberg36b37dc2018-09-24 10:52:32 +0200275 RegisterSendCodec('A', codec_opus, 48000, 64000, 480 * 2, codec_channels);
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000276 Run(channel_a2b_, audio_channels, codec_channels);
277 // Run Opus with 40 ms frame size.
Karl Wiberg36b37dc2018-09-24 10:52:32 +0200278 RegisterSendCodec('A', codec_opus, 48000, 64000, 480 * 4, codec_channels);
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000279 Run(channel_a2b_, audio_channels, codec_channels);
280 // Run Opus with 60 ms frame size.
Karl Wiberg36b37dc2018-09-24 10:52:32 +0200281 RegisterSendCodec('A', codec_opus, 48000, 64000, 480 * 6, codec_channels);
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000282 Run(channel_a2b_, audio_channels, codec_channels);
283 // Run Opus with 20 ms frame size and different bitrates.
Karl Wiberg36b37dc2018-09-24 10:52:32 +0200284 RegisterSendCodec('A', codec_opus, 48000, 40000, 960, codec_channels);
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000285 Run(channel_a2b_, audio_channels, codec_channels);
Karl Wiberg36b37dc2018-09-24 10:52:32 +0200286 RegisterSendCodec('A', codec_opus, 48000, 510000, 960, codec_channels);
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000287 Run(channel_a2b_, audio_channels, codec_channels);
288 out_file_.Close();
289#endif
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000290 //
291 // Test Mono-To-Stereo for all codecs.
292 //
293 audio_channels = 1;
294 codec_channels = 2;
niklase@google.com470e71d2011-07-07 08:21:25 +0000295
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000296 test_cntr_++;
297 channel_a2b_->set_codec_mode(kStereo);
298 OpenOutFile(test_cntr_);
Karl Wiberg36b37dc2018-09-24 10:52:32 +0200299 RegisterSendCodec('A', codec_g722, 16000, 64000, 160, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000300 Run(channel_a2b_, audio_channels, codec_channels);
301 out_file_.Close();
Karl Wibergeb254b42017-11-01 15:08:12 +0100302
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000303 test_cntr_++;
304 channel_a2b_->set_codec_mode(kStereo);
305 OpenOutFile(test_cntr_);
Karl Wiberg36b37dc2018-09-24 10:52:32 +0200306 RegisterSendCodec('A', codec_l16, 8000, 128000, 80, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000307 Run(channel_a2b_, audio_channels, codec_channels);
308 out_file_.Close();
Fredrik Solenberg657b2962018-12-05 10:30:25 +0100309
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000310 test_cntr_++;
311 OpenOutFile(test_cntr_);
Karl Wiberg36b37dc2018-09-24 10:52:32 +0200312 RegisterSendCodec('A', codec_l16, 16000, 256000, 160, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000313 Run(channel_a2b_, audio_channels, codec_channels);
314 out_file_.Close();
Fredrik Solenberg657b2962018-12-05 10:30:25 +0100315
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000316 test_cntr_++;
317 OpenOutFile(test_cntr_);
Karl Wiberg36b37dc2018-09-24 10:52:32 +0200318 RegisterSendCodec('A', codec_l16, 32000, 512000, 320, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000319 Run(channel_a2b_, audio_channels, codec_channels);
320 out_file_.Close();
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000321#ifdef PCMA_AND_PCMU
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000322 test_cntr_++;
323 channel_a2b_->set_codec_mode(kStereo);
324 OpenOutFile(test_cntr_);
Karl Wiberg36b37dc2018-09-24 10:52:32 +0200325 RegisterSendCodec('A', codec_pcmu, 8000, 64000, 80, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000326 Run(channel_a2b_, audio_channels, codec_channels);
Karl Wiberg36b37dc2018-09-24 10:52:32 +0200327 RegisterSendCodec('A', codec_pcma, 8000, 64000, 80, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000328 Run(channel_a2b_, audio_channels, codec_channels);
329 out_file_.Close();
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000330#endif
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000331#ifdef WEBRTC_CODEC_OPUS
tina.legrand@webrtc.orgc4590582012-11-28 12:23:29 +0000332 // Keep encode and decode in stereo.
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000333 test_cntr_++;
334 channel_a2b_->set_codec_mode(kStereo);
335 OpenOutFile(test_cntr_);
Karl Wiberg36b37dc2018-09-24 10:52:32 +0200336 RegisterSendCodec('A', codec_opus, 48000, 64000, 960, codec_channels);
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000337 Run(channel_a2b_, audio_channels, codec_channels);
tina.legrand@webrtc.orgc4590582012-11-28 12:23:29 +0000338
339 // Encode in mono, decode in stereo mode.
Karl Wiberg36b37dc2018-09-24 10:52:32 +0200340 RegisterSendCodec('A', codec_opus, 48000, 64000, 960, 1);
tina.legrand@webrtc.orgc4590582012-11-28 12:23:29 +0000341 Run(channel_a2b_, audio_channels, codec_channels);
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000342 out_file_.Close();
343#endif
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000344
345 //
346 // Test Stereo-To-Mono for all codecs.
347 //
348 audio_channels = 2;
349 codec_channels = 1;
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000350 channel_a2b_->set_codec_mode(kMono);
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000351
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000352 // Run stereo audio and mono codec.
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000353 test_cntr_++;
354 OpenOutFile(test_cntr_);
Karl Wiberg36b37dc2018-09-24 10:52:32 +0200355 RegisterSendCodec('A', codec_g722, 16000, 64000, 160, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000356 Run(channel_a2b_, audio_channels, codec_channels);
357 out_file_.Close();
Karl Wibergeb254b42017-11-01 15:08:12 +0100358
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000359 test_cntr_++;
360 OpenOutFile(test_cntr_);
Karl Wiberg36b37dc2018-09-24 10:52:32 +0200361 RegisterSendCodec('A', codec_l16, 8000, 128000, 80, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000362 Run(channel_a2b_, audio_channels, codec_channels);
363 out_file_.Close();
Fredrik Solenberg657b2962018-12-05 10:30:25 +0100364
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000365 test_cntr_++;
366 OpenOutFile(test_cntr_);
Karl Wiberg36b37dc2018-09-24 10:52:32 +0200367 RegisterSendCodec('A', codec_l16, 16000, 256000, 160, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000368 Run(channel_a2b_, audio_channels, codec_channels);
369 out_file_.Close();
Fredrik Solenberg657b2962018-12-05 10:30:25 +0100370
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000371 test_cntr_++;
372 OpenOutFile(test_cntr_);
Karl Wiberg36b37dc2018-09-24 10:52:32 +0200373 RegisterSendCodec('A', codec_l16, 32000, 512000, 320, codec_channels);
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000374 Run(channel_a2b_, audio_channels, codec_channels);
375 out_file_.Close();
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000376#ifdef PCMA_AND_PCMU
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000377 test_cntr_++;
378 OpenOutFile(test_cntr_);
Karl Wiberg36b37dc2018-09-24 10:52:32 +0200379 RegisterSendCodec('A', codec_pcmu, 8000, 64000, 80, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000380 Run(channel_a2b_, audio_channels, codec_channels);
Karl Wiberg36b37dc2018-09-24 10:52:32 +0200381 RegisterSendCodec('A', codec_pcma, 8000, 64000, 80, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000382 Run(channel_a2b_, audio_channels, codec_channels);
383 out_file_.Close();
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000384#endif
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000385#ifdef WEBRTC_CODEC_OPUS
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000386 test_cntr_++;
387 OpenOutFile(test_cntr_);
tina.legrand@webrtc.orgc4590582012-11-28 12:23:29 +0000388 // Encode and decode in mono.
Karl Wiberg36b37dc2018-09-24 10:52:32 +0200389 RegisterSendCodec('A', codec_opus, 48000, 32000, 960, codec_channels);
Henrik Lundin84f75692023-02-01 12:07:10 +0000390 acm_b_->SetCodecs({{120, {"OPUS", 48000, 2}}});
tina.legrand@webrtc.orgc4590582012-11-28 12:23:29 +0000391 Run(channel_a2b_, audio_channels, codec_channels);
392
393 // Encode in stereo, decode in mono.
Karl Wiberg36b37dc2018-09-24 10:52:32 +0200394 RegisterSendCodec('A', codec_opus, 48000, 32000, 960, 2);
tina.legrand@webrtc.orgc4590582012-11-28 12:23:29 +0000395 Run(channel_a2b_, audio_channels, codec_channels);
396
397 out_file_.Close();
398
399 // Test switching between decoding mono and stereo for Opus.
400
401 // Decode in mono.
402 test_cntr_++;
403 OpenOutFile(test_cntr_);
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000404 Run(channel_a2b_, audio_channels, codec_channels);
405 out_file_.Close();
tina.legrand@webrtc.orgc4590582012-11-28 12:23:29 +0000406 // Decode in stereo.
407 test_cntr_++;
408 OpenOutFile(test_cntr_);
Henrik Lundin84f75692023-02-01 12:07:10 +0000409 acm_b_->SetCodecs({{120, {"OPUS", 48000, 2, {{"stereo", "1"}}}}});
tina.legrand@webrtc.orgc4590582012-11-28 12:23:29 +0000410 Run(channel_a2b_, audio_channels, 2);
411 out_file_.Close();
412 // Decode in mono.
413 test_cntr_++;
414 OpenOutFile(test_cntr_);
Henrik Lundin84f75692023-02-01 12:07:10 +0000415 acm_b_->SetCodecs({{120, {"OPUS", 48000, 2}}});
tina.legrand@webrtc.orgc4590582012-11-28 12:23:29 +0000416 Run(channel_a2b_, audio_channels, codec_channels);
417 out_file_.Close();
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000418#endif
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000419
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000420 // Delete the file pointers.
421 delete in_file_stereo_;
422 delete in_file_mono_;
niklase@google.com470e71d2011-07-07 08:21:25 +0000423}
424
425// Register Codec to use in the test
426//
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000427// Input: side - which ACM to use, 'A' or 'B'
428// codec_name - name to use when register the codec
429// sampling_freq_hz - sampling frequency in Herz
430// rate - bitrate in bytes
431// pack_size - packet size in samples
432// channels - number of channels; 1 for mono, 2 for stereo
Yves Gerey665174f2018-06-19 15:03:05 +0200433void TestStereo::RegisterSendCodec(char side,
434 char* codec_name,
435 int32_t sampling_freq_hz,
436 int rate,
437 int pack_size,
Karl Wiberg36b37dc2018-09-24 10:52:32 +0200438 int channels) {
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000439 // Store packet size in samples, used to validate the received packet
440 pack_size_samp_ = pack_size;
441
442 // Store the expected packet size in bytes, used to validate the received
443 // packet. Add 0.875 to always round up to a whole byte.
pbos@webrtc.orgd8ca7232014-12-10 11:49:13 +0000444 pack_size_bytes_ = (uint16_t)(static_cast<float>(pack_size * rate) /
445 static_cast<float>(sampling_freq_hz * 8) +
446 0.875);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000447
448 // Set pointer to the ACM where to register the codec
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000449 AudioCodingModule* my_acm = NULL;
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000450 switch (side) {
451 case 'A': {
andrew@webrtc.org89df0922013-09-12 01:27:43 +0000452 my_acm = acm_a_.get();
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000453 break;
niklase@google.com470e71d2011-07-07 08:21:25 +0000454 }
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000455 case 'B': {
Henrik Lundin84f75692023-02-01 12:07:10 +0000456 // We no longer use this case. Refactor code to avoid the switch.
457 ASSERT_TRUE(false);
458 // 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
Anton Bikineev7abf45f2022-01-23 22:22:59 +0100511 while (true) {
Artem Titovd00ce742021-07-28 20:00:17 +0200512 // Simulate packet loss by setting `packet_loss_` to "true" in
513 // `percent_loss` percent of the loops.
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000514 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;
Henrik Lundin84f75692023-02-01 12:07:10 +0000562 EXPECT_EQ(0, acm_b_->GetAudio(out_freq_hz_b, &audio_frame, &muted));
henrik.lundind4ccb002016-05-17 12:21:55 -0700563 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