blob: 72ae25ea18e58e342d3b65774f3bc018b4efef46 [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
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +000011#include "webrtc/modules/audio_coding/main/test/TestStereo.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000012
pbos@webrtc.org12dc1a32013-08-05 16:22:53 +000013#include <assert.h>
14
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +000015#include <string>
kjellander@webrtc.org5490c712011-12-21 13:34:18 +000016
kjellander@webrtc.org3c0aae12014-09-04 09:55:40 +000017#include "testing/gtest/include/gtest/gtest.h"
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +000018#include "webrtc/common_types.h"
19#include "webrtc/engine_configurations.h"
20#include "webrtc/modules/audio_coding/main/interface/audio_coding_module_typedefs.h"
21#include "webrtc/modules/audio_coding/main/test/utility.h"
22#include "webrtc/system_wrappers/interface/trace.h"
23#include "webrtc/test/testsupport/fileutils.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000024
tina.legrand@webrtc.org554ae1a2011-12-16 10:09:04 +000025namespace webrtc {
niklase@google.com470e71d2011-07-07 08:21:25 +000026
27// Class for simulating packet handling
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +000028TestPackStereo::TestPackStereo()
29 : receiver_acm_(NULL),
30 seq_no_(0),
31 timestamp_diff_(0),
32 last_in_timestamp_(0),
33 total_bytes_(0),
34 payload_size_(0),
35 codec_mode_(kNotSet),
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000036 lost_packet_(false) {
37}
niklase@google.com470e71d2011-07-07 08:21:25 +000038
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000039TestPackStereo::~TestPackStereo() {
40}
niklase@google.com470e71d2011-07-07 08:21:25 +000041
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +000042void TestPackStereo::RegisterReceiverACM(AudioCodingModule* acm) {
43 receiver_acm_ = acm;
44 return;
45}
niklase@google.com470e71d2011-07-07 08:21:25 +000046
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000047int32_t TestPackStereo::SendData(const FrameType frame_type,
48 const uint8_t payload_type,
49 const uint32_t timestamp,
50 const uint8_t* payload_data,
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +000051 const size_t payload_size,
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000052 const RTPFragmentationHeader* fragmentation) {
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +000053 WebRtcRTPHeader rtp_info;
pbos@webrtc.org0946a562013-04-09 00:28:06 +000054 int32_t status = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +000055
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +000056 rtp_info.header.markerBit = false;
57 rtp_info.header.ssrc = 0;
58 rtp_info.header.sequenceNumber = seq_no_++;
59 rtp_info.header.payloadType = payload_type;
60 rtp_info.header.timestamp = timestamp;
61 if (frame_type == kFrameEmpty) {
tina.legrand@webrtc.org16b6b902012-04-12 11:02:38 +000062 // Skip this frame
63 return 0;
64 }
niklase@google.com470e71d2011-07-07 08:21:25 +000065
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +000066 if (lost_packet_ == false) {
67 if (frame_type != kAudioFrameCN) {
68 rtp_info.type.Audio.isCNG = false;
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +000069 rtp_info.type.Audio.channel = static_cast<int>(codec_mode_);
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +000070 } else {
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +000071 rtp_info.type.Audio.isCNG = true;
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +000072 rtp_info.type.Audio.channel = static_cast<int>(kMono);
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +000073 }
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +000074 status = receiver_acm_->IncomingPacket(payload_data, payload_size,
tina.legrand@webrtc.org45175852012-06-01 09:27:35 +000075 rtp_info);
niklase@google.com470e71d2011-07-07 08:21:25 +000076
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +000077 if (frame_type != kAudioFrameCN) {
henrike@webrtc.org6ac22e62014-08-11 21:06:30 +000078 payload_size_ = static_cast<int>(payload_size);
niklase@google.com470e71d2011-07-07 08:21:25 +000079 } else {
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +000080 payload_size_ = -1;
niklase@google.com470e71d2011-07-07 08:21:25 +000081 }
tina.legrand@webrtc.org16b6b902012-04-12 11:02:38 +000082
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +000083 timestamp_diff_ = timestamp - last_in_timestamp_;
84 last_in_timestamp_ = timestamp;
85 total_bytes_ += payload_size;
tina.legrand@webrtc.org16b6b902012-04-12 11:02:38 +000086 }
87 return status;
niklase@google.com470e71d2011-07-07 08:21:25 +000088}
89
pbos@webrtc.org0946a562013-04-09 00:28:06 +000090uint16_t TestPackStereo::payload_size() {
henrike@webrtc.org6ac22e62014-08-11 21:06:30 +000091 return static_cast<uint16_t>(payload_size_);
niklase@google.com470e71d2011-07-07 08:21:25 +000092}
93
pbos@webrtc.org0946a562013-04-09 00:28:06 +000094uint32_t TestPackStereo::timestamp_diff() {
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +000095 return timestamp_diff_;
niklase@google.com470e71d2011-07-07 08:21:25 +000096}
97
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +000098void TestPackStereo::reset_payload_size() {
99 payload_size_ = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000100}
101
tina.legrand@webrtc.org16b6b902012-04-12 11:02:38 +0000102void TestPackStereo::set_codec_mode(enum StereoMonoMode mode) {
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000103 codec_mode_ = mode;
tina.legrand@webrtc.org16b6b902012-04-12 11:02:38 +0000104}
105
106void TestPackStereo::set_lost_packet(bool lost) {
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000107 lost_packet_ = lost;
niklase@google.com470e71d2011-07-07 08:21:25 +0000108}
109
henrik.lundin@webrtc.orgadaf8092014-04-17 08:29:10 +0000110TestStereo::TestStereo(int test_mode)
111 : acm_a_(AudioCodingModule::Create(0)),
112 acm_b_(AudioCodingModule::Create(1)),
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000113 channel_a2b_(NULL),
114 test_cntr_(0),
115 pack_size_samp_(0),
116 pack_size_bytes_(0),
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +0000117 counter_(0)
118#ifdef WEBRTC_CODEC_G722
119 , g722_pltype_(0)
120#endif
121#ifdef WEBRTC_CODEC_PCM16
122 , l16_8khz_pltype_(-1)
123 , l16_16khz_pltype_(-1)
124 , l16_32khz_pltype_(-1)
125#endif
126#ifdef PCMA_AND_PCMU
127 , pcma_pltype_(-1)
128 , pcmu_pltype_(-1)
129#endif
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +0000130#ifdef WEBRTC_CODEC_OPUS
131 , opus_pltype_(-1)
132#endif
133 {
tina.legrand@webrtc.org45175852012-06-01 09:27:35 +0000134 // test_mode = 0 for silent test (auto test)
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000135 test_mode_ = test_mode;
niklase@google.com470e71d2011-07-07 08:21:25 +0000136}
137
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000138TestStereo::~TestStereo() {
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000139 if (channel_a2b_ != NULL) {
140 delete channel_a2b_;
141 channel_a2b_ = NULL;
142 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000143}
144
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000145void TestStereo::Perform() {
pbos@webrtc.org0946a562013-04-09 00:28:06 +0000146 uint16_t frequency_hz;
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000147 int audio_channels;
148 int codec_channels;
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000149 bool dtx;
150 bool vad;
151 ACMVADMode vad_mode;
niklase@google.com470e71d2011-07-07 08:21:25 +0000152
tina.legrand@webrtc.org45175852012-06-01 09:27:35 +0000153 // Open both mono and stereo test files in 32 kHz.
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000154 const std::string file_name_stereo = webrtc::test::ResourcePath(
155 "audio_coding/teststereo32kHz", "pcm");
156 const std::string file_name_mono = webrtc::test::ResourcePath(
157 "audio_coding/testfile32kHz", "pcm");
tina.legrand@webrtc.org45175852012-06-01 09:27:35 +0000158 frequency_hz = 32000;
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000159 in_file_stereo_ = new PCMFile();
160 in_file_mono_ = new PCMFile();
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000161 in_file_stereo_->Open(file_name_stereo, frequency_hz, "rb");
162 in_file_stereo_->ReadStereo(true);
163 in_file_mono_->Open(file_name_mono, frequency_hz, "rb");
164 in_file_mono_->ReadStereo(false);
165
tina.legrand@webrtc.org45175852012-06-01 09:27:35 +0000166 // Create and initialize two ACMs, one for each side of a one-to-one call.
andrew@webrtc.org89df0922013-09-12 01:27:43 +0000167 ASSERT_TRUE((acm_a_.get() != NULL) && (acm_b_.get() != NULL));
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000168 EXPECT_EQ(0, acm_a_->InitializeReceiver());
169 EXPECT_EQ(0, acm_b_->InitializeReceiver());
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000170
tina.legrand@webrtc.org45175852012-06-01 09:27:35 +0000171 // Register all available codes as receiving codecs.
pbos@webrtc.org0946a562013-04-09 00:28:06 +0000172 uint8_t num_encoders = acm_a_->NumberOfCodecs();
tina.legrand@webrtc.org45175852012-06-01 09:27:35 +0000173 CodecInst my_codec_param;
pbos@webrtc.org0946a562013-04-09 00:28:06 +0000174 for (uint8_t n = 0; n < num_encoders; n++) {
tina.legrand@webrtc.org7a7a0082013-02-21 10:27:48 +0000175 EXPECT_EQ(0, acm_b_->Codec(n, &my_codec_param));
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000176 EXPECT_EQ(0, acm_b_->RegisterReceiveCodec(my_codec_param));
tina.legrand@webrtc.org45175852012-06-01 09:27:35 +0000177 }
178
179 // Test that unregister all receive codecs works.
pbos@webrtc.org0946a562013-04-09 00:28:06 +0000180 for (uint8_t n = 0; n < num_encoders; n++) {
tina.legrand@webrtc.org7a7a0082013-02-21 10:27:48 +0000181 EXPECT_EQ(0, acm_b_->Codec(n, &my_codec_param));
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000182 EXPECT_EQ(0, acm_b_->UnregisterReceiveCodec(my_codec_param.pltype));
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000183 }
tina.legrand@webrtc.orgae1c4542012-03-12 08:41:30 +0000184
tina.legrand@webrtc.org45175852012-06-01 09:27:35 +0000185 // Register all available codes as receiving codecs once more.
pbos@webrtc.org0946a562013-04-09 00:28:06 +0000186 for (uint8_t n = 0; n < num_encoders; n++) {
tina.legrand@webrtc.org7a7a0082013-02-21 10:27:48 +0000187 EXPECT_EQ(0, acm_b_->Codec(n, &my_codec_param));
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000188 EXPECT_EQ(0, acm_b_->RegisterReceiveCodec(my_codec_param));
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000189 }
tina.legrand@webrtc.orgae1c4542012-03-12 08:41:30 +0000190
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000191 // Create and connect the channel.
192 channel_a2b_ = new TestPackStereo;
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000193 EXPECT_EQ(0, acm_a_->RegisterTransportCallback(channel_a2b_));
andrew@webrtc.org89df0922013-09-12 01:27:43 +0000194 channel_a2b_->RegisterReceiverACM(acm_b_.get());
tina.legrand@webrtc.orgdf697752012-02-08 10:22:21 +0000195
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000196 // Start with setting VAD/DTX, before we know we will send stereo.
197 // Continue with setting a stereo codec as send codec and verify that
198 // VAD/DTX gets turned off.
199 EXPECT_EQ(0, acm_a_->SetVAD(true, true, VADNormal));
tina.legrand@webrtc.org7a7a0082013-02-21 10:27:48 +0000200 EXPECT_EQ(0, acm_a_->VAD(&dtx, &vad, &vad_mode));
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000201 EXPECT_TRUE(dtx);
202 EXPECT_TRUE(vad);
203 char codec_pcma_temp[] = "PCMA";
204 RegisterSendCodec('A', codec_pcma_temp, 8000, 64000, 80, 2, pcma_pltype_);
tina.legrand@webrtc.org7a7a0082013-02-21 10:27:48 +0000205 EXPECT_EQ(0, acm_a_->VAD(&dtx, &vad, &vad_mode));
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000206 EXPECT_FALSE(dtx);
207 EXPECT_FALSE(vad);
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000208 if (test_mode_ != 0) {
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000209 printf("\n");
210 }
211
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000212 //
213 // Test Stereo-To-Stereo for all codecs.
214 //
215 audio_channels = 2;
216 codec_channels = 2;
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000217
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000218 // All codecs are tested for all allowed sampling frequencies, rates and
219 // packet sizes.
niklase@google.com470e71d2011-07-07 08:21:25 +0000220#ifdef WEBRTC_CODEC_G722
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000221 if (test_mode_ != 0) {
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000222 printf("===========================================================\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000223 printf("Test number: %d\n", test_cntr_ + 1);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000224 printf("Test type: Stereo-to-stereo\n");
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000225 }
226 channel_a2b_->set_codec_mode(kStereo);
227 test_cntr_++;
228 OpenOutFile(test_cntr_);
229 char codec_g722[] = "G722";
230 RegisterSendCodec('A', codec_g722, 16000, 64000, 160, codec_channels,
231 g722_pltype_);
232 Run(channel_a2b_, audio_channels, codec_channels);
233 RegisterSendCodec('A', codec_g722, 16000, 64000, 320, codec_channels,
234 g722_pltype_);
235 Run(channel_a2b_, audio_channels, codec_channels);
236 RegisterSendCodec('A', codec_g722, 16000, 64000, 480, codec_channels,
237 g722_pltype_);
238 Run(channel_a2b_, audio_channels, codec_channels);
239 RegisterSendCodec('A', codec_g722, 16000, 64000, 640, codec_channels,
240 g722_pltype_);
241 Run(channel_a2b_, audio_channels, codec_channels);
242 RegisterSendCodec('A', codec_g722, 16000, 64000, 800, codec_channels,
243 g722_pltype_);
244 Run(channel_a2b_, audio_channels, codec_channels);
245 RegisterSendCodec('A', codec_g722, 16000, 64000, 960, codec_channels,
246 g722_pltype_);
247 Run(channel_a2b_, audio_channels, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000248 out_file_.Close();
niklase@google.com470e71d2011-07-07 08:21:25 +0000249#endif
250#ifdef WEBRTC_CODEC_PCM16
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000251 if (test_mode_ != 0) {
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000252 printf("===========================================================\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000253 printf("Test number: %d\n", test_cntr_ + 1);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000254 printf("Test type: Stereo-to-stereo\n");
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000255 }
256 channel_a2b_->set_codec_mode(kStereo);
257 test_cntr_++;
258 OpenOutFile(test_cntr_);
259 char codec_l16[] = "L16";
260 RegisterSendCodec('A', codec_l16, 8000, 128000, 80, codec_channels,
261 l16_8khz_pltype_);
262 Run(channel_a2b_, audio_channels, codec_channels);
263 RegisterSendCodec('A', codec_l16, 8000, 128000, 160, codec_channels,
264 l16_8khz_pltype_);
265 Run(channel_a2b_, audio_channels, codec_channels);
266 RegisterSendCodec('A', codec_l16, 8000, 128000, 240, codec_channels,
267 l16_8khz_pltype_);
268 Run(channel_a2b_, audio_channels, codec_channels);
269 RegisterSendCodec('A', codec_l16, 8000, 128000, 320, codec_channels,
270 l16_8khz_pltype_);
271 Run(channel_a2b_, audio_channels, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000272 out_file_.Close();
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000273
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000274 if (test_mode_ != 0) {
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000275 printf("===========================================================\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000276 printf("Test number: %d\n", test_cntr_ + 1);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000277 printf("Test type: Stereo-to-stereo\n");
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000278 }
279 test_cntr_++;
280 OpenOutFile(test_cntr_);
281 RegisterSendCodec('A', codec_l16, 16000, 256000, 160, codec_channels,
282 l16_16khz_pltype_);
283 Run(channel_a2b_, audio_channels, codec_channels);
284 RegisterSendCodec('A', codec_l16, 16000, 256000, 320, codec_channels,
285 l16_16khz_pltype_);
286 Run(channel_a2b_, audio_channels, codec_channels);
287 RegisterSendCodec('A', codec_l16, 16000, 256000, 480, codec_channels,
288 l16_16khz_pltype_);
289 Run(channel_a2b_, audio_channels, codec_channels);
290 RegisterSendCodec('A', codec_l16, 16000, 256000, 640, codec_channels,
291 l16_16khz_pltype_);
292 Run(channel_a2b_, audio_channels, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000293 out_file_.Close();
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000294
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000295 if (test_mode_ != 0) {
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000296 printf("===========================================================\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000297 printf("Test number: %d\n", test_cntr_ + 1);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000298 printf("Test type: Stereo-to-stereo\n");
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000299 }
300 test_cntr_++;
301 OpenOutFile(test_cntr_);
302 RegisterSendCodec('A', codec_l16, 32000, 512000, 320, codec_channels,
303 l16_32khz_pltype_);
304 Run(channel_a2b_, audio_channels, codec_channels);
305 RegisterSendCodec('A', codec_l16, 32000, 512000, 640, codec_channels,
306 l16_32khz_pltype_);
307 Run(channel_a2b_, audio_channels, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000308 out_file_.Close();
niklase@google.com470e71d2011-07-07 08:21:25 +0000309#endif
niklase@google.com470e71d2011-07-07 08:21:25 +0000310#ifdef PCMA_AND_PCMU
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000311 if (test_mode_ != 0) {
312 printf("===========================================================\n");
313 printf("Test number: %d\n", test_cntr_ + 1);
314 printf("Test type: Stereo-to-stereo\n");
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000315 }
316 channel_a2b_->set_codec_mode(kStereo);
317 audio_channels = 2;
318 codec_channels = 2;
319 test_cntr_++;
320 OpenOutFile(test_cntr_);
321 char codec_pcma[] = "PCMA";
322 RegisterSendCodec('A', codec_pcma, 8000, 64000, 80, codec_channels,
323 pcma_pltype_);
324 Run(channel_a2b_, audio_channels, codec_channels);
325 RegisterSendCodec('A', codec_pcma, 8000, 64000, 160, codec_channels,
326 pcma_pltype_);
327 Run(channel_a2b_, audio_channels, codec_channels);
328 RegisterSendCodec('A', codec_pcma, 8000, 64000, 240, codec_channels,
329 pcma_pltype_);
330 Run(channel_a2b_, audio_channels, codec_channels);
331 RegisterSendCodec('A', codec_pcma, 8000, 64000, 320, codec_channels,
332 pcma_pltype_);
333 Run(channel_a2b_, audio_channels, codec_channels);
334 RegisterSendCodec('A', codec_pcma, 8000, 64000, 400, codec_channels,
335 pcma_pltype_);
336 Run(channel_a2b_, audio_channels, codec_channels);
337 RegisterSendCodec('A', codec_pcma, 8000, 64000, 480, codec_channels,
338 pcma_pltype_);
339 Run(channel_a2b_, audio_channels, codec_channels);
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000340
341 // Test that VAD/DTX cannot be turned on while sending stereo.
342 EXPECT_EQ(-1, acm_a_->SetVAD(true, true, VADNormal));
tina.legrand@webrtc.org7a7a0082013-02-21 10:27:48 +0000343 EXPECT_EQ(0, acm_a_->VAD(&dtx, &vad, &vad_mode));
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000344 EXPECT_FALSE(dtx);
345 EXPECT_FALSE(vad);
346 EXPECT_EQ(-1, acm_a_->SetVAD(true, false, VADNormal));
tina.legrand@webrtc.org7a7a0082013-02-21 10:27:48 +0000347 EXPECT_EQ(0, acm_a_->VAD(&dtx, &vad, &vad_mode));
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000348 EXPECT_FALSE(dtx);
349 EXPECT_FALSE(vad);
350 EXPECT_EQ(-1, acm_a_->SetVAD(false, true, VADNormal));
tina.legrand@webrtc.org7a7a0082013-02-21 10:27:48 +0000351 EXPECT_EQ(0, acm_a_->VAD(&dtx, &vad, &vad_mode));
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000352 EXPECT_FALSE(dtx);
353 EXPECT_FALSE(vad);
354 EXPECT_EQ(0, acm_a_->SetVAD(false, false, VADNormal));
tina.legrand@webrtc.org7a7a0082013-02-21 10:27:48 +0000355 EXPECT_EQ(0, acm_a_->VAD(&dtx, &vad, &vad_mode));
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000356 EXPECT_FALSE(dtx);
357 EXPECT_FALSE(vad);
358
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000359 out_file_.Close();
360 if (test_mode_ != 0) {
361 printf("===========================================================\n");
362 printf("Test number: %d\n", test_cntr_ + 1);
363 printf("Test type: Stereo-to-stereo\n");
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000364 }
365 test_cntr_++;
366 OpenOutFile(test_cntr_);
367 char codec_pcmu[] = "PCMU";
368 RegisterSendCodec('A', codec_pcmu, 8000, 64000, 80, codec_channels,
369 pcmu_pltype_);
370 Run(channel_a2b_, audio_channels, codec_channels);
371 RegisterSendCodec('A', codec_pcmu, 8000, 64000, 160, codec_channels,
372 pcmu_pltype_);
373 Run(channel_a2b_, audio_channels, codec_channels);
374 RegisterSendCodec('A', codec_pcmu, 8000, 64000, 240, codec_channels,
375 pcmu_pltype_);
376 Run(channel_a2b_, audio_channels, codec_channels);
377 RegisterSendCodec('A', codec_pcmu, 8000, 64000, 320, codec_channels,
378 pcmu_pltype_);
379 Run(channel_a2b_, audio_channels, codec_channels);
380 RegisterSendCodec('A', codec_pcmu, 8000, 64000, 400, codec_channels,
381 pcmu_pltype_);
382 Run(channel_a2b_, audio_channels, codec_channels);
383 RegisterSendCodec('A', codec_pcmu, 8000, 64000, 480, codec_channels,
384 pcmu_pltype_);
385 Run(channel_a2b_, audio_channels, codec_channels);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000386 out_file_.Close();
niklase@google.com470e71d2011-07-07 08:21:25 +0000387#endif
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000388#ifdef WEBRTC_CODEC_OPUS
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000389 if (test_mode_ != 0) {
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000390 printf("===========================================================\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000391 printf("Test number: %d\n", test_cntr_ + 1);
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000392 printf("Test type: Stereo-to-stereo\n");
393 }
394 channel_a2b_->set_codec_mode(kStereo);
395 audio_channels = 2;
396 codec_channels = 2;
397 test_cntr_++;
398 OpenOutFile(test_cntr_);
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000399
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000400 char codec_opus[] = "opus";
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000401 // Run Opus with 10 ms frame size.
402 RegisterSendCodec('A', codec_opus, 48000, 64000, 480, codec_channels,
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000403 opus_pltype_);
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000404 Run(channel_a2b_, audio_channels, codec_channels);
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000405 // Run Opus with 20 ms frame size.
406 RegisterSendCodec('A', codec_opus, 48000, 64000, 480*2, codec_channels,
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000407 opus_pltype_);
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000408 Run(channel_a2b_, audio_channels, codec_channels);
409 // Run Opus with 40 ms frame size.
410 RegisterSendCodec('A', codec_opus, 48000, 64000, 480*4, codec_channels,
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000411 opus_pltype_);
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000412 Run(channel_a2b_, audio_channels, codec_channels);
413 // Run Opus with 60 ms frame size.
414 RegisterSendCodec('A', codec_opus, 48000, 64000, 480*6, codec_channels,
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000415 opus_pltype_);
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000416 Run(channel_a2b_, audio_channels, codec_channels);
417 // Run Opus with 20 ms frame size and different bitrates.
418 RegisterSendCodec('A', codec_opus, 48000, 40000, 960, codec_channels,
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000419 opus_pltype_);
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000420 Run(channel_a2b_, audio_channels, codec_channels);
421 RegisterSendCodec('A', codec_opus, 48000, 510000, 960, codec_channels,
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000422 opus_pltype_);
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000423 Run(channel_a2b_, audio_channels, codec_channels);
424 out_file_.Close();
425#endif
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000426 //
427 // Test Mono-To-Stereo for all codecs.
428 //
429 audio_channels = 1;
430 codec_channels = 2;
niklase@google.com470e71d2011-07-07 08:21:25 +0000431
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000432#ifdef WEBRTC_CODEC_G722
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000433 if (test_mode_ != 0) {
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000434 printf("===============================================================\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000435 printf("Test number: %d\n", test_cntr_ + 1);
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000436 printf("Test type: Mono-to-stereo\n");
437 }
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000438 test_cntr_++;
439 channel_a2b_->set_codec_mode(kStereo);
440 OpenOutFile(test_cntr_);
441 RegisterSendCodec('A', codec_g722, 16000, 64000, 160, codec_channels,
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000442 g722_pltype_);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000443 Run(channel_a2b_, audio_channels, codec_channels);
444 out_file_.Close();
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000445#endif
446#ifdef WEBRTC_CODEC_PCM16
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000447 if (test_mode_ != 0) {
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000448 printf("===============================================================\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000449 printf("Test number: %d\n", test_cntr_ + 1);
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000450 printf("Test type: Mono-to-stereo\n");
451 }
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000452 test_cntr_++;
453 channel_a2b_->set_codec_mode(kStereo);
454 OpenOutFile(test_cntr_);
455 RegisterSendCodec('A', codec_l16, 8000, 128000, 80, codec_channels,
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000456 l16_8khz_pltype_);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000457 Run(channel_a2b_, audio_channels, codec_channels);
458 out_file_.Close();
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000459 if (test_mode_ != 0) {
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000460 printf("===============================================================\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000461 printf("Test number: %d\n", test_cntr_ + 1);
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000462 printf("Test type: Mono-to-stereo\n");
463 }
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000464 test_cntr_++;
465 OpenOutFile(test_cntr_);
466 RegisterSendCodec('A', codec_l16, 16000, 256000, 160, codec_channels,
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000467 l16_16khz_pltype_);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000468 Run(channel_a2b_, audio_channels, codec_channels);
469 out_file_.Close();
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000470 if (test_mode_ != 0) {
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000471 printf("===============================================================\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000472 printf("Test number: %d\n", test_cntr_ + 1);
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000473 printf("Test type: Mono-to-stereo\n");
474 }
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000475 test_cntr_++;
476 OpenOutFile(test_cntr_);
477 RegisterSendCodec('A', codec_l16, 32000, 512000, 320, codec_channels,
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000478 l16_32khz_pltype_);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000479 Run(channel_a2b_, audio_channels, codec_channels);
480 out_file_.Close();
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000481#endif
482#ifdef PCMA_AND_PCMU
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000483 if (test_mode_ != 0) {
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000484 printf("===============================================================\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000485 printf("Test number: %d\n", test_cntr_ + 1);
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000486 printf("Test type: Mono-to-stereo\n");
487 }
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000488 test_cntr_++;
489 channel_a2b_->set_codec_mode(kStereo);
490 OpenOutFile(test_cntr_);
491 RegisterSendCodec('A', codec_pcmu, 8000, 64000, 80, codec_channels,
tina.legrand@webrtc.orgae1c4542012-03-12 08:41:30 +0000492 pcmu_pltype_);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000493 Run(channel_a2b_, audio_channels, codec_channels);
494 RegisterSendCodec('A', codec_pcma, 8000, 64000, 80, codec_channels,
tina.legrand@webrtc.orgae1c4542012-03-12 08:41:30 +0000495 pcma_pltype_);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000496 Run(channel_a2b_, audio_channels, codec_channels);
497 out_file_.Close();
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000498#endif
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000499#ifdef WEBRTC_CODEC_OPUS
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000500 if (test_mode_ != 0) {
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000501 printf("===============================================================\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000502 printf("Test number: %d\n", test_cntr_ + 1);
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000503 printf("Test type: Mono-to-stereo\n");
504 }
tina.legrand@webrtc.orgc4590582012-11-28 12:23:29 +0000505
506 // Keep encode and decode in stereo.
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000507 test_cntr_++;
508 channel_a2b_->set_codec_mode(kStereo);
509 OpenOutFile(test_cntr_);
510 RegisterSendCodec('A', codec_opus, 48000, 64000, 960, codec_channels,
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000511 opus_pltype_);
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000512 Run(channel_a2b_, audio_channels, codec_channels);
tina.legrand@webrtc.orgc4590582012-11-28 12:23:29 +0000513
514 // Encode in mono, decode in stereo mode.
515 RegisterSendCodec('A', codec_opus, 48000, 64000, 960, 1, opus_pltype_);
516 Run(channel_a2b_, audio_channels, codec_channels);
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000517 out_file_.Close();
518#endif
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000519
520 //
521 // Test Stereo-To-Mono for all codecs.
522 //
523 audio_channels = 2;
524 codec_channels = 1;
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000525 channel_a2b_->set_codec_mode(kMono);
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000526
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000527#ifdef WEBRTC_CODEC_G722
528 // Run stereo audio and mono codec.
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000529 if (test_mode_ != 0) {
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000530 printf("===============================================================\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000531 printf("Test number: %d\n", test_cntr_ + 1);
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000532 printf("Test type: Stereo-to-mono\n");
533 }
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000534 test_cntr_++;
535 OpenOutFile(test_cntr_);
536 RegisterSendCodec('A', codec_g722, 16000, 64000, 160, codec_channels,
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000537 g722_pltype_);
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000538
539 // Make sure it is possible to set VAD/CNG, now that we are sending mono
540 // again.
541 EXPECT_EQ(0, acm_a_->SetVAD(true, true, VADNormal));
tina.legrand@webrtc.org7a7a0082013-02-21 10:27:48 +0000542 EXPECT_EQ(0, acm_a_->VAD(&dtx, &vad, &vad_mode));
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000543 EXPECT_TRUE(dtx);
544 EXPECT_TRUE(vad);
545 EXPECT_EQ(0, acm_a_->SetVAD(false, false, VADNormal));
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000546 Run(channel_a2b_, audio_channels, codec_channels);
547 out_file_.Close();
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000548#endif
549#ifdef WEBRTC_CODEC_PCM16
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000550 if (test_mode_ != 0) {
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000551 printf("===============================================================\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000552 printf("Test number: %d\n", test_cntr_ + 1);
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000553 printf("Test type: Stereo-to-mono\n");
554 }
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000555 test_cntr_++;
556 OpenOutFile(test_cntr_);
557 RegisterSendCodec('A', codec_l16, 8000, 128000, 80, codec_channels,
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000558 l16_8khz_pltype_);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000559 Run(channel_a2b_, audio_channels, codec_channels);
560 out_file_.Close();
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000561 if (test_mode_ != 0) {
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000562 printf("===============================================================\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000563 printf("Test number: %d\n", test_cntr_ + 1);
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000564 printf("Test type: Stereo-to-mono\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000565 }
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000566 test_cntr_++;
567 OpenOutFile(test_cntr_);
568 RegisterSendCodec('A', codec_l16, 16000, 256000, 160, codec_channels,
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000569 l16_16khz_pltype_);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000570 Run(channel_a2b_, audio_channels, codec_channels);
571 out_file_.Close();
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000572 if (test_mode_ != 0) {
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000573 printf("==============================================================\n");
574 printf("Test number: %d\n", test_cntr_ + 1);
575 printf("Test type: Stereo-to-mono\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000576 }
577 test_cntr_++;
578 OpenOutFile(test_cntr_);
579 RegisterSendCodec('A', codec_l16, 32000, 512000, 320, codec_channels,
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000580 l16_32khz_pltype_);
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000581 Run(channel_a2b_, audio_channels, codec_channels);
582 out_file_.Close();
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000583#endif
584#ifdef PCMA_AND_PCMU
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000585 if (test_mode_ != 0) {
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000586 printf("===============================================================\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000587 printf("Test number: %d\n", test_cntr_ + 1);
tina.legrand@webrtc.orgdf697752012-02-08 10:22:21 +0000588 printf("Test type: Stereo-to-mono\n");
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000589 }
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000590 test_cntr_++;
591 OpenOutFile(test_cntr_);
592 RegisterSendCodec('A', codec_pcmu, 8000, 64000, 80, codec_channels,
tina.legrand@webrtc.orgae1c4542012-03-12 08:41:30 +0000593 pcmu_pltype_);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000594 Run(channel_a2b_, audio_channels, codec_channels);
595 RegisterSendCodec('A', codec_pcma, 8000, 64000, 80, codec_channels,
tina.legrand@webrtc.orgae1c4542012-03-12 08:41:30 +0000596 pcma_pltype_);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000597 Run(channel_a2b_, audio_channels, codec_channels);
598 out_file_.Close();
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000599#endif
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000600#ifdef WEBRTC_CODEC_OPUS
tina.legrand@webrtc.org46d90dc2013-02-01 14:20:06 +0000601 if (test_mode_ != 0) {
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000602 printf("===============================================================\n");
tina.legrand@webrtc.orga092cbf2013-02-14 09:28:10 +0000603 printf("Test number: %d\n", test_cntr_ + 1);
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000604 printf("Test type: Stereo-to-mono\n");
605 }
606 test_cntr_++;
607 OpenOutFile(test_cntr_);
tina.legrand@webrtc.orgc4590582012-11-28 12:23:29 +0000608 // Encode and decode in mono.
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000609 RegisterSendCodec('A', codec_opus, 48000, 32000, 960, codec_channels,
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000610 opus_pltype_);
tina.legrand@webrtc.orgc4590582012-11-28 12:23:29 +0000611 CodecInst opus_codec_param;
pbos@webrtc.org0946a562013-04-09 00:28:06 +0000612 for (uint8_t n = 0; n < num_encoders; n++) {
tina.legrand@webrtc.org7a7a0082013-02-21 10:27:48 +0000613 EXPECT_EQ(0, acm_b_->Codec(n, &opus_codec_param));
tina.legrand@webrtc.orgc4590582012-11-28 12:23:29 +0000614 if (!strcmp(opus_codec_param.plname, "opus")) {
615 opus_codec_param.channels = 1;
616 EXPECT_EQ(0, acm_b_->RegisterReceiveCodec(opus_codec_param));
617 break;
618 }
619 }
620 Run(channel_a2b_, audio_channels, codec_channels);
621
622 // Encode in stereo, decode in mono.
623 RegisterSendCodec('A', codec_opus, 48000, 32000, 960, 2, opus_pltype_);
624 Run(channel_a2b_, audio_channels, codec_channels);
625
626 out_file_.Close();
627
628 // Test switching between decoding mono and stereo for Opus.
629
630 // Decode in mono.
631 test_cntr_++;
632 OpenOutFile(test_cntr_);
633 if (test_mode_ != 0) {
634 // Print out codec and settings
635 printf("Test number: %d\nCodec: Opus Freq: 48000 Rate :32000 PackSize: 960"
636 " Decode: mono\n", test_cntr_);
637 }
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000638 Run(channel_a2b_, audio_channels, codec_channels);
639 out_file_.Close();
tina.legrand@webrtc.orgc4590582012-11-28 12:23:29 +0000640 // Decode in stereo.
641 test_cntr_++;
642 OpenOutFile(test_cntr_);
643 if (test_mode_ != 0) {
644 // Print out codec and settings
645 printf("Test number: %d\nCodec: Opus Freq: 48000 Rate :32000 PackSize: 960"
646 " Decode: stereo\n", test_cntr_);
647 }
648 opus_codec_param.channels = 2;
649 EXPECT_EQ(0, acm_b_->RegisterReceiveCodec(opus_codec_param));
650 Run(channel_a2b_, audio_channels, 2);
651 out_file_.Close();
652 // Decode in mono.
653 test_cntr_++;
654 OpenOutFile(test_cntr_);
655 if (test_mode_ != 0) {
656 // Print out codec and settings
657 printf("Test number: %d\nCodec: Opus Freq: 48000 Rate :32000 PackSize: 960"
658 " Decode: mono\n", test_cntr_);
659 }
660 opus_codec_param.channels = 1;
661 EXPECT_EQ(0, acm_b_->RegisterReceiveCodec(opus_codec_param));
662 Run(channel_a2b_, audio_channels, codec_channels);
663 out_file_.Close();
664
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000665#endif
tina.legrand@webrtc.org6b6ff552012-01-11 10:12:54 +0000666
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000667 // Print out which codecs were tested, and which were not, in the run.
668 if (test_mode_ != 0) {
669 printf("\nThe following codecs was INCLUDED in the test:\n");
niklase@google.com470e71d2011-07-07 08:21:25 +0000670#ifdef WEBRTC_CODEC_G722
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000671 printf(" G.722\n");
niklase@google.com470e71d2011-07-07 08:21:25 +0000672#endif
673#ifdef WEBRTC_CODEC_PCM16
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000674 printf(" PCM16\n");
niklase@google.com470e71d2011-07-07 08:21:25 +0000675#endif
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000676 printf(" G.711\n");
tina.legrand@webrtc.orgc4590582012-11-28 12:23:29 +0000677#ifdef WEBRTC_CODEC_OPUS
678 printf(" Opus\n");
679#endif
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000680 printf("\nTo complete the test, listen to the %d number of output "
681 "files.\n",
682 test_cntr_);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000683 }
684
685 // Delete the file pointers.
686 delete in_file_stereo_;
687 delete in_file_mono_;
niklase@google.com470e71d2011-07-07 08:21:25 +0000688}
689
690// Register Codec to use in the test
691//
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000692// Input: side - which ACM to use, 'A' or 'B'
693// codec_name - name to use when register the codec
694// sampling_freq_hz - sampling frequency in Herz
695// rate - bitrate in bytes
696// pack_size - packet size in samples
697// channels - number of channels; 1 for mono, 2 for stereo
698// payload_type - payload type for the codec
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000699void TestStereo::RegisterSendCodec(char side, char* codec_name,
pbos@webrtc.org0946a562013-04-09 00:28:06 +0000700 int32_t sampling_freq_hz, int rate,
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000701 int pack_size, int channels,
702 int payload_type) {
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000703 if (test_mode_ != 0) {
704 // Print out codec and settings
tina.legrand@webrtc.orgba468042012-08-17 10:38:28 +0000705 printf("Codec: %s Freq: %d Rate: %d PackSize: %d\n", codec_name,
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000706 sampling_freq_hz, rate, pack_size);
707 }
708
709 // Store packet size in samples, used to validate the received packet
710 pack_size_samp_ = pack_size;
711
712 // Store the expected packet size in bytes, used to validate the received
713 // packet. Add 0.875 to always round up to a whole byte.
pbos@webrtc.orgd8ca7232014-12-10 11:49:13 +0000714 pack_size_bytes_ = (uint16_t)(static_cast<float>(pack_size * rate) /
715 static_cast<float>(sampling_freq_hz * 8) +
716 0.875);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000717
718 // Set pointer to the ACM where to register the codec
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000719 AudioCodingModule* my_acm = NULL;
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000720 switch (side) {
721 case 'A': {
andrew@webrtc.org89df0922013-09-12 01:27:43 +0000722 my_acm = acm_a_.get();
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000723 break;
niklase@google.com470e71d2011-07-07 08:21:25 +0000724 }
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000725 case 'B': {
andrew@webrtc.org89df0922013-09-12 01:27:43 +0000726 my_acm = acm_b_.get();
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000727 break;
tina.legrand@webrtc.org16b6b902012-04-12 11:02:38 +0000728 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000729 default:
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000730 break;
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000731 }
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000732 ASSERT_TRUE(my_acm != NULL);
niklase@google.com470e71d2011-07-07 08:21:25 +0000733
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000734 CodecInst my_codec_param;
735 // Get all codec parameters before registering
tina.legrand@webrtc.orgee92b662013-08-27 07:33:51 +0000736 EXPECT_GT(AudioCodingModule::Codec(codec_name, &my_codec_param,
737 sampling_freq_hz, channels), -1);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000738 my_codec_param.rate = rate;
739 my_codec_param.pacsize = pack_size;
tina.legrand@webrtc.orgee92b662013-08-27 07:33:51 +0000740 EXPECT_EQ(0, my_acm->RegisterSendCodec(my_codec_param));
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000741
742 send_codec_name_ = codec_name;
niklase@google.com470e71d2011-07-07 08:21:25 +0000743}
744
tina.legrand@webrtc.org16b6b902012-04-12 11:02:38 +0000745void TestStereo::Run(TestPackStereo* channel, int in_channels, int out_channels,
746 int percent_loss) {
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000747 AudioFrame audio_frame;
niklase@google.com470e71d2011-07-07 08:21:25 +0000748
pbos@webrtc.org0946a562013-04-09 00:28:06 +0000749 int32_t out_freq_hz_b = out_file_.SamplingFrequency();
750 uint16_t rec_size;
751 uint32_t time_stamp_diff;
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000752 channel->reset_payload_size();
753 int error_count = 0;
tina.legrand@webrtc.org65d61c32014-06-05 13:42:51 +0000754 int variable_bytes = 0;
755 int variable_packets = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000756
andresp@webrtc.orgd0b436a2014-01-13 13:15:59 +0000757 while (1) {
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000758 // Simulate packet loss by setting |packet_loss_| to "true" in
759 // |percent_loss| percent of the loops.
760 if (percent_loss > 0) {
761 if (counter_ == floor((100 / percent_loss) + 0.5)) {
762 counter_ = 0;
763 channel->set_lost_packet(true);
764 } else {
765 channel->set_lost_packet(false);
766 }
767 counter_++;
niklase@google.com470e71d2011-07-07 08:21:25 +0000768 }
769
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000770 // Add 10 msec to ACM
771 if (in_channels == 1) {
772 if (in_file_mono_->EndOfFile()) {
773 break;
774 }
775 in_file_mono_->Read10MsData(audio_frame);
776 } else {
777 if (in_file_stereo_->EndOfFile()) {
778 break;
779 }
780 in_file_stereo_->Read10MsData(audio_frame);
781 }
henrik.lundin@webrtc.orgf56c1622015-03-02 12:29:30 +0000782 EXPECT_GE(acm_a_->Add10MsData(audio_frame), 0);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000783
tina.legrand@webrtc.org65d61c32014-06-05 13:42:51 +0000784 // Verify that the received packet size matches the settings.
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000785 rec_size = channel->payload_size();
786 if ((0 < rec_size) & (rec_size < 65535)) {
tina.legrand@webrtc.org65d61c32014-06-05 13:42:51 +0000787 if (strcmp(send_codec_name_, "opus") == 0) {
788 // Opus is a variable rate codec, hence calculate the average packet
789 // size, and later make sure the average is in the right range.
790 variable_bytes += rec_size;
791 variable_packets++;
792 } else {
793 // For fixed rate codecs, check that packet size is correct.
tina.legrand@webrtc.org0ad3c1a2012-11-07 08:07:29 +0000794 if ((rec_size != pack_size_bytes_ * out_channels)
795 && (pack_size_bytes_ < 65535)) {
796 error_count++;
797 }
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000798 }
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000799 // Verify that the timestamp is updated with expected length
800 time_stamp_diff = channel->timestamp_diff();
801 if ((counter_ > 10) && (time_stamp_diff != pack_size_samp_)) {
802 error_count++;
803 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000804 }
805
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000806 // Run received side of ACM
tina.legrand@webrtc.orgee92b662013-08-27 07:33:51 +0000807 EXPECT_EQ(0, acm_b_->PlayoutData10Ms(out_freq_hz_b, &audio_frame));
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000808
809 // Write output speech to file
810 out_file_.Write10MsData(
andrew@webrtc.org63a50982012-05-02 23:56:37 +0000811 audio_frame.data_,
812 audio_frame.samples_per_channel_ * audio_frame.num_channels_);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000813 }
814
tina.legrand@webrtc.org3ddc9742012-06-27 09:25:50 +0000815 EXPECT_EQ(0, error_count);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000816
tina.legrand@webrtc.org65d61c32014-06-05 13:42:51 +0000817 // Check that packet size is in the right range for variable rate codecs,
818 // such as Opus.
819 if (variable_packets > 0) {
820 variable_bytes /= variable_packets;
821 EXPECT_NEAR(variable_bytes, pack_size_bytes_, 3);
822 }
823
andresp@webrtc.orgd0b436a2014-01-13 13:15:59 +0000824 if (in_file_mono_->EndOfFile()) {
825 in_file_mono_->Rewind();
826 }
827 if (in_file_stereo_->EndOfFile()) {
828 in_file_stereo_->Rewind();
829 }
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000830 // Reset in case we ended with a lost packet
831 channel->set_lost_packet(false);
niklase@google.com470e71d2011-07-07 08:21:25 +0000832}
833
pbos@webrtc.org0946a562013-04-09 00:28:06 +0000834void TestStereo::OpenOutFile(int16_t test_number) {
tina.legrand@webrtc.orgba468042012-08-17 10:38:28 +0000835 std::string file_name;
836 std::stringstream file_stream;
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000837 file_stream << webrtc::test::OutputPath() << "teststereo_out_" << test_number
838 << ".pcm";
tina.legrand@webrtc.orgba468042012-08-17 10:38:28 +0000839 file_name = file_stream.str();
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000840 out_file_.Open(file_name, 32000, "wb");
niklase@google.com470e71d2011-07-07 08:21:25 +0000841}
842
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000843void TestStereo::DisplaySendReceiveCodec() {
844 CodecInst my_codec_param;
tina.legrand@webrtc.org7a7a0082013-02-21 10:27:48 +0000845 acm_a_->SendCodec(&my_codec_param);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000846 if (test_mode_ != 0) {
847 printf("%s -> ", my_codec_param.plname);
848 }
tina.legrand@webrtc.org7a7a0082013-02-21 10:27:48 +0000849 acm_b_->ReceiveCodec(&my_codec_param);
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000850 if (test_mode_ != 0) {
851 printf("%s\n", my_codec_param.plname);
852 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000853}
854
tina.legrand@webrtc.orga6ecd1e2012-04-26 07:54:30 +0000855} // namespace webrtc