blob: 89a9829a811cef63268bdfd30a68829803b081cc [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
11#include "TestAllCodecs.h"
12
tina.legrand@webrtc.org5e7ca602012-06-12 07:16:24 +000013#include <stdio.h>
tina.legrand@webrtc.org5e7ca602012-06-12 07:16:24 +000014#include <string>
kjellander@webrtc.org5490c712011-12-21 13:34:18 +000015
tina.legrand@webrtc.org50d5ca52012-06-18 13:35:52 +000016#include "gtest/gtest.h"
17
18#include "audio_coding_module.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000019#include "audio_coding_module_typedefs.h"
20#include "common_types.h"
21#include "engine_configurations.h"
kjellander@webrtc.org5490c712011-12-21 13:34:18 +000022#include "testsupport/fileutils.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000023#include "trace.h"
tina.legrand@webrtc.org50d5ca52012-06-18 13:35:52 +000024#include "typedefs.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000025#include "utility.h"
26
tina.legrand@webrtc.org50d5ca52012-06-18 13:35:52 +000027// Description of the test:
28// In this test we set up a one-way communication channel from a participant
29// called "a" to a participant called "b".
30// a -> channel_a_to_b -> b
31//
32// The test loops through all available mono codecs, encode at "a" sends over
33// the channel, and decodes at "b".
34
tina.legrand@webrtc.org554ae1a2011-12-16 10:09:04 +000035namespace webrtc {
36
tina.legrand@webrtc.org50d5ca52012-06-18 13:35:52 +000037// Class for simulating packet handling.
38TestPack::TestPack()
39 : receiver_acm_(NULL),
40 sequence_number_(0),
41 timestamp_diff_(0),
42 last_in_timestamp_(0),
43 total_bytes_(0),
44 payload_size_(0) {
niklase@google.com470e71d2011-07-07 08:21:25 +000045}
46
tina.legrand@webrtc.org50d5ca52012-06-18 13:35:52 +000047TestPack::~TestPack() {
niklase@google.com470e71d2011-07-07 08:21:25 +000048}
49
tina.legrand@webrtc.org50d5ca52012-06-18 13:35:52 +000050void TestPack::RegisterReceiverACM(AudioCodingModule* acm) {
51 receiver_acm_ = acm;
52 return;
niklase@google.com470e71d2011-07-07 08:21:25 +000053}
54
tina.legrand@webrtc.org50d5ca52012-06-18 13:35:52 +000055int32_t TestPack::SendData(FrameType frame_type, uint8_t payload_type,
56 uint32_t timestamp, const uint8_t* payload_data,
57 uint16_t payload_size,
58 const RTPFragmentationHeader* fragmentation) {
59 WebRtcRTPHeader rtp_info;
60 int32_t status;
niklase@google.com470e71d2011-07-07 08:21:25 +000061
tina.legrand@webrtc.org50d5ca52012-06-18 13:35:52 +000062 rtp_info.header.markerBit = false;
63 rtp_info.header.ssrc = 0;
64 rtp_info.header.sequenceNumber = sequence_number_++;
65 rtp_info.header.payloadType = payload_type;
66 rtp_info.header.timestamp = timestamp;
67 if (frame_type == kAudioFrameCN) {
68 rtp_info.type.Audio.isCNG = true;
69 } else {
70 rtp_info.type.Audio.isCNG = false;
71 }
72 if (frame_type == kFrameEmpty) {
73 // Skip this frame.
74 return 0;
75 }
76
77 // Only run mono for all test cases.
78 rtp_info.type.Audio.channel = 1;
79 memcpy(payload_data_, payload_data, payload_size);
80
81 status = receiver_acm_->IncomingPacket(payload_data_, payload_size,
82 rtp_info);
83
84 payload_size_ = payload_size;
85 timestamp_diff_ = timestamp - last_in_timestamp_;
86 last_in_timestamp_ = timestamp;
87 total_bytes_ += payload_size;
88 return status;
niklase@google.com470e71d2011-07-07 08:21:25 +000089}
90
tina.legrand@webrtc.org50d5ca52012-06-18 13:35:52 +000091uint16_t TestPack::payload_size() {
92 return payload_size_;
niklase@google.com470e71d2011-07-07 08:21:25 +000093}
94
tina.legrand@webrtc.org50d5ca52012-06-18 13:35:52 +000095uint32_t TestPack::timestamp_diff() {
96 return timestamp_diff_;
niklase@google.com470e71d2011-07-07 08:21:25 +000097}
98
tina.legrand@webrtc.org50d5ca52012-06-18 13:35:52 +000099void TestPack::reset_payload_size() {
100 payload_size_ = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000101}
102
tina.legrand@webrtc.org50d5ca52012-06-18 13:35:52 +0000103TestAllCodecs::TestAllCodecs(int test_mode)
104 : acm_a_(NULL),
105 acm_b_(NULL),
106 channel_a_to_b_(NULL),
107 test_count_(0),
108 packet_size_samples_(0),
109 packet_size_bytes_(0) {
110 // test_mode = 0 for silent test (auto test)
111 test_mode_ = test_mode;
112}
niklase@google.com470e71d2011-07-07 08:21:25 +0000113
tina.legrand@webrtc.org50d5ca52012-06-18 13:35:52 +0000114TestAllCodecs::~TestAllCodecs() {
115 if (acm_a_ != NULL) {
116 AudioCodingModule::Destroy(acm_a_);
117 acm_a_ = NULL;
118 }
119 if (acm_b_ != NULL) {
120 AudioCodingModule::Destroy(acm_b_);
121 acm_b_ = NULL;
122 }
123 if (channel_a_to_b_ != NULL) {
124 delete channel_a_to_b_;
125 channel_a_to_b_ = NULL;
126 }
127}
niklase@google.com470e71d2011-07-07 08:21:25 +0000128
tina.legrand@webrtc.org50d5ca52012-06-18 13:35:52 +0000129void TestAllCodecs::Perform() {
tina.legrand@webrtc.orgba468042012-08-17 10:38:28 +0000130
131 const std::string file_name =
132 webrtc::test::ResourcePath("audio_coding/testfile32kHz", "pcm");
133 infile_a_.Open(file_name, 32000, "rb");
niklase@google.com470e71d2011-07-07 08:21:25 +0000134
tina.legrand@webrtc.org50d5ca52012-06-18 13:35:52 +0000135 if (test_mode_ == 0) {
136 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioCoding, -1,
137 "---------- TestAllCodecs ----------");
138 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000139
tina.legrand@webrtc.org50d5ca52012-06-18 13:35:52 +0000140 acm_a_ = AudioCodingModule::Create(0);
141 acm_b_ = AudioCodingModule::Create(1);
niklase@google.com470e71d2011-07-07 08:21:25 +0000142
tina.legrand@webrtc.org50d5ca52012-06-18 13:35:52 +0000143 acm_a_->InitializeReceiver();
144 acm_b_->InitializeReceiver();
niklase@google.com470e71d2011-07-07 08:21:25 +0000145
tina.legrand@webrtc.org50d5ca52012-06-18 13:35:52 +0000146 uint8_t num_encoders = acm_a_->NumberOfCodecs();
147 CodecInst my_codec_param;
148 for (uint8_t n = 0; n < num_encoders; n++) {
149 acm_b_->Codec(n, my_codec_param);
150 acm_b_->RegisterReceiveCodec(my_codec_param);
151 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000152
tina.legrand@webrtc.org50d5ca52012-06-18 13:35:52 +0000153 // Create and connect the channel
154 channel_a_to_b_ = new TestPack;
155 acm_a_->RegisterTransportCallback(channel_a_to_b_);
156 channel_a_to_b_->RegisterReceiverACM(acm_b_);
157
158 // All codecs are tested for all allowed sampling frequencies, rates and
159 // packet sizes.
160#ifdef WEBRTC_CODEC_AMR
161 if (test_mode_ != 0) {
162 printf("===============================================================\n");
163 }
164 test_count_++;
165 OpenOutFile(test_count_);
166 char codec_amr[] = "AMR";
167 RegisterSendCodec('A', codec_amr, 8000, 4750, 160, 2);
168 Run(channel_a_to_b_);
169 RegisterSendCodec('A', codec_amr, 8000, 4750, 320, 2);
170 Run(channel_a_to_b_);
171 RegisterSendCodec('A', codec_amr, 8000, 4750, 480, 3);
172 Run(channel_a_to_b_);
173 RegisterSendCodec('A', codec_amr, 8000, 5150, 160, 2);
174 Run(channel_a_to_b_);
175 RegisterSendCodec('A', codec_amr, 8000, 5150, 320, 2);
176 Run(channel_a_to_b_);
177 RegisterSendCodec('A', codec_amr, 8000, 5150, 480, 3);
178 Run(channel_a_to_b_);
179 RegisterSendCodec('A', codec_amr, 8000, 5900, 160, 1);
180 Run(channel_a_to_b_);
181 RegisterSendCodec('A', codec_amr, 8000, 5900, 320, 2);
182 Run(channel_a_to_b_);
183 RegisterSendCodec('A', codec_amr, 8000, 5900, 480, 2);
184 Run(channel_a_to_b_);
185 RegisterSendCodec('A', codec_amr, 8000, 6700, 160, 1);
186 Run(channel_a_to_b_);
187 RegisterSendCodec('A', codec_amr, 8000, 6700, 320, 2);
188 Run(channel_a_to_b_);
189 RegisterSendCodec('A', codec_amr, 8000, 6700, 480, 2);
190 Run(channel_a_to_b_);
191 RegisterSendCodec('A', codec_amr, 8000, 7400, 160, 1);
192 Run(channel_a_to_b_);
193 RegisterSendCodec('A', codec_amr, 8000, 7400, 320, 2);
194 Run(channel_a_to_b_);
195 RegisterSendCodec('A', codec_amr, 8000, 7400, 480, 3);
196 Run(channel_a_to_b_);
197 RegisterSendCodec('A', codec_amr, 8000, 7950, 160, 2);
198 Run(channel_a_to_b_);
199 RegisterSendCodec('A', codec_amr, 8000, 7950, 320, 2);
200 Run(channel_a_to_b_);
201 RegisterSendCodec('A', codec_amr, 8000, 7950, 480, 3);
202 Run(channel_a_to_b_);
203 RegisterSendCodec('A', codec_amr, 8000, 10200, 160, 1);
204 Run(channel_a_to_b_);
205 RegisterSendCodec('A', codec_amr, 8000, 10200, 320, 2);
206 Run(channel_a_to_b_);
207 RegisterSendCodec('A', codec_amr, 8000, 10200, 480, 3);
208 Run(channel_a_to_b_);
209 RegisterSendCodec('A', codec_amr, 8000, 12200, 160, 1);
210 Run(channel_a_to_b_);
211 RegisterSendCodec('A', codec_amr, 8000, 12200, 320, 2);
212 Run(channel_a_to_b_);
213 RegisterSendCodec('A', codec_amr, 8000, 12200, 480, 3);
214 Run(channel_a_to_b_);
215 outfile_b_.Close();
niklase@google.com470e71d2011-07-07 08:21:25 +0000216#endif
tina.legrand@webrtc.org50d5ca52012-06-18 13:35:52 +0000217#ifdef WEBRTC_CODEC_AMRWB
218 if (test_mode_ != 0) {
219 printf("===============================================================\n");
220 }
221 test_count_++;
222 char codec_amrwb[] = "AMR-WB";
223 OpenOutFile(test_count_);
224 RegisterSendCodec('A', codec_amrwb, 16000, 7000, 320, 0);
225 Run(channel_a_to_b_);
226 RegisterSendCodec('A', codec_amrwb, 16000, 7000, 640, 0);
227 Run(channel_a_to_b_);
228 RegisterSendCodec('A', codec_amrwb, 16000, 7000, 960, 0);
229 Run(channel_a_to_b_);
230 RegisterSendCodec('A', codec_amrwb, 16000, 9000, 320, 1);
231 Run(channel_a_to_b_);
232 RegisterSendCodec('A', codec_amrwb, 16000, 9000, 640, 2);
233 Run(channel_a_to_b_);
234 RegisterSendCodec('A', codec_amrwb, 16000, 9000, 960, 2);
235 Run(channel_a_to_b_);
236 RegisterSendCodec('A', codec_amrwb, 16000, 12000, 320, 3);
237 Run(channel_a_to_b_);
238 RegisterSendCodec('A', codec_amrwb, 16000, 12000, 640, 6);
239 Run(channel_a_to_b_);
240 RegisterSendCodec('A', codec_amrwb, 16000, 12000, 960, 8);
241 Run(channel_a_to_b_);
242 RegisterSendCodec('A', codec_amrwb, 16000, 14000, 320, 2);
243 Run(channel_a_to_b_);
244 RegisterSendCodec('A', codec_amrwb, 16000, 14000, 640, 4);
245 Run(channel_a_to_b_);
246 RegisterSendCodec('A', codec_amrwb, 16000, 14000, 960, 5);
247 Run(channel_a_to_b_);
248 RegisterSendCodec('A', codec_amrwb, 16000, 16000, 320, 1);
249 Run(channel_a_to_b_);
250 RegisterSendCodec('A', codec_amrwb, 16000, 16000, 640, 2);
251 Run(channel_a_to_b_);
252 RegisterSendCodec('A', codec_amrwb, 16000, 16000, 960, 2);
253 Run(channel_a_to_b_);
254 RegisterSendCodec('A', codec_amrwb, 16000, 18000, 320, 2);
255 Run(channel_a_to_b_);
256 RegisterSendCodec('A', codec_amrwb, 16000, 18000, 640, 4);
257 Run(channel_a_to_b_);
258 RegisterSendCodec('A', codec_amrwb, 16000, 18000, 960, 5);
259 Run(channel_a_to_b_);
260 RegisterSendCodec('A', codec_amrwb, 16000, 20000, 320, 1);
261 Run(channel_a_to_b_);
262 RegisterSendCodec('A', codec_amrwb, 16000, 20000, 640, 2);
263 Run(channel_a_to_b_);
264 RegisterSendCodec('A', codec_amrwb, 16000, 20000, 960, 2);
265 Run(channel_a_to_b_);
266 RegisterSendCodec('A', codec_amrwb, 16000, 23000, 320, 1);
267 Run(channel_a_to_b_);
268 RegisterSendCodec('A', codec_amrwb, 16000, 23000, 640, 3);
269 Run(channel_a_to_b_);
270 RegisterSendCodec('A', codec_amrwb, 16000, 23000, 960, 3);
271 Run(channel_a_to_b_);
272 RegisterSendCodec('A', codec_amrwb, 16000, 24000, 320, 1);
273 Run(channel_a_to_b_);
274 RegisterSendCodec('A', codec_amrwb, 16000, 24000, 640, 2);
275 Run(channel_a_to_b_);
276 RegisterSendCodec('A', codec_amrwb, 16000, 24000, 960, 2);
277 Run(channel_a_to_b_);
278 outfile_b_.Close();
niklase@google.com470e71d2011-07-07 08:21:25 +0000279#endif
280#ifdef WEBRTC_CODEC_G722
tina.legrand@webrtc.org50d5ca52012-06-18 13:35:52 +0000281 if (test_mode_ != 0) {
282 printf("===============================================================\n");
283 }
284 test_count_++;
285 OpenOutFile(test_count_);
286 char codec_g722[] = "G722";
287 RegisterSendCodec('A', codec_g722, 16000, 64000, 160, 0);
288 Run(channel_a_to_b_);
289 RegisterSendCodec('A', codec_g722, 16000, 64000, 320, 0);
290 Run(channel_a_to_b_);
291 RegisterSendCodec('A', codec_g722, 16000, 64000, 480, 0);
292 Run(channel_a_to_b_);
293 RegisterSendCodec('A', codec_g722, 16000, 64000, 640, 0);
294 Run(channel_a_to_b_);
295 RegisterSendCodec('A', codec_g722, 16000, 64000, 800, 0);
296 Run(channel_a_to_b_);
297 RegisterSendCodec('A', codec_g722, 16000, 64000, 960, 0);
298 Run(channel_a_to_b_);
299 outfile_b_.Close();
niklase@google.com470e71d2011-07-07 08:21:25 +0000300#endif
301#ifdef WEBRTC_CODEC_G722_1
tina.legrand@webrtc.org50d5ca52012-06-18 13:35:52 +0000302 if (test_mode_ != 0) {
303 printf("===============================================================\n");
304 }
305 test_count_++;
306 OpenOutFile(test_count_);
307 char codec_g722_1[] = "G7221";
308 RegisterSendCodec('A', codec_g722_1, 16000, 32000, 320, 0);
309 Run(channel_a_to_b_);
310 RegisterSendCodec('A', codec_g722_1, 16000, 24000, 320, 0);
311 Run(channel_a_to_b_);
312 RegisterSendCodec('A', codec_g722_1, 16000, 16000, 320, 0);
313 Run(channel_a_to_b_);
314 outfile_b_.Close();
niklase@google.com470e71d2011-07-07 08:21:25 +0000315#endif
316#ifdef WEBRTC_CODEC_G722_1C
tina.legrand@webrtc.org50d5ca52012-06-18 13:35:52 +0000317 if (test_mode_ != 0) {
318 printf("===============================================================\n");
319 }
320 test_count_++;
321 OpenOutFile(test_count_);
322 char codec_g722_1c[] = "G7221";
323 RegisterSendCodec('A', codec_g722_1c, 32000, 48000, 640, 0);
324 Run(channel_a_to_b_);
325 RegisterSendCodec('A', codec_g722_1c, 32000, 32000, 640, 0);
326 Run(channel_a_to_b_);
327 RegisterSendCodec('A', codec_g722_1c, 32000, 24000, 640, 0);
328 Run(channel_a_to_b_);
329 outfile_b_.Close();
niklase@google.com470e71d2011-07-07 08:21:25 +0000330#endif
331#ifdef WEBRTC_CODEC_G729
tina.legrand@webrtc.org50d5ca52012-06-18 13:35:52 +0000332 if (test_mode_ != 0) {
333 printf("===============================================================\n");
334 }
335 test_count_++;
336 OpenOutFile(test_count_);
337 char codec_g729[] = "G729";
338 RegisterSendCodec('A', codec_g729, 8000, 8000, 80, 0);
339 Run(channel_a_to_b_);
340 RegisterSendCodec('A', codec_g729, 8000, 8000, 160, 0);
341 Run(channel_a_to_b_);
342 RegisterSendCodec('A', codec_g729, 8000, 8000, 240, 0);
343 Run(channel_a_to_b_);
344 RegisterSendCodec('A', codec_g729, 8000, 8000, 320, 0);
345 Run(channel_a_to_b_);
346 RegisterSendCodec('A', codec_g729, 8000, 8000, 400, 0);
347 Run(channel_a_to_b_);
348 RegisterSendCodec('A', codec_g729, 8000, 8000, 480, 0);
349 Run(channel_a_to_b_);
350 outfile_b_.Close();
niklase@google.com470e71d2011-07-07 08:21:25 +0000351#endif
352#ifdef WEBRTC_CODEC_G729_1
tina.legrand@webrtc.org50d5ca52012-06-18 13:35:52 +0000353 if (test_mode_ != 0) {
354 printf("===============================================================\n");
355 }
356 test_count_++;
357 OpenOutFile(test_count_);
358 char codec_g729_1[] = "G7291";
359 RegisterSendCodec('A', codec_g729_1, 16000, 8000, 320, 1);
360 Run(channel_a_to_b_);
361 RegisterSendCodec('A', codec_g729_1, 16000, 8000, 640, 1);
362 Run(channel_a_to_b_);
363 RegisterSendCodec('A', codec_g729_1, 16000, 8000, 960, 1);
364 Run(channel_a_to_b_);
365 RegisterSendCodec('A', codec_g729_1, 16000, 12000, 320, 1);
366 Run(channel_a_to_b_);
367 RegisterSendCodec('A', codec_g729_1, 16000, 12000, 640, 1);
368 Run(channel_a_to_b_);
369 RegisterSendCodec('A', codec_g729_1, 16000, 12000, 960, 1);
370 Run(channel_a_to_b_);
371 RegisterSendCodec('A', codec_g729_1, 16000, 14000, 320, 1);
372 Run(channel_a_to_b_);
373 RegisterSendCodec('A', codec_g729_1, 16000, 14000, 640, 1);
374 Run(channel_a_to_b_);
375 RegisterSendCodec('A', codec_g729_1, 16000, 14000, 960, 1);
376 Run(channel_a_to_b_);
377 RegisterSendCodec('A', codec_g729_1, 16000, 16000, 320, 1);
378 Run(channel_a_to_b_);
379 RegisterSendCodec('A', codec_g729_1, 16000, 16000, 640, 1);
380 Run(channel_a_to_b_);
381 RegisterSendCodec('A', codec_g729_1, 16000, 16000, 960, 1);
382 Run(channel_a_to_b_);
383 RegisterSendCodec('A', codec_g729_1, 16000, 18000, 320, 1);
384 Run(channel_a_to_b_);
385 RegisterSendCodec('A', codec_g729_1, 16000, 18000, 640, 1);
386 Run(channel_a_to_b_);
387 RegisterSendCodec('A', codec_g729_1, 16000, 18000, 960, 1);
388 Run(channel_a_to_b_);
389 RegisterSendCodec('A', codec_g729_1, 16000, 20000, 320, 1);
390 Run(channel_a_to_b_);
391 RegisterSendCodec('A', codec_g729_1, 16000, 20000, 640, 1);
392 Run(channel_a_to_b_);
393 RegisterSendCodec('A', codec_g729_1, 16000, 20000, 960, 1);
394 Run(channel_a_to_b_);
395 RegisterSendCodec('A', codec_g729_1, 16000, 22000, 320, 1);
396 Run(channel_a_to_b_);
397 RegisterSendCodec('A', codec_g729_1, 16000, 22000, 640, 1);
398 Run(channel_a_to_b_);
399 RegisterSendCodec('A', codec_g729_1, 16000, 22000, 960, 1);
400 Run(channel_a_to_b_);
401 RegisterSendCodec('A', codec_g729_1, 16000, 24000, 320, 1);
402 Run(channel_a_to_b_);
403 RegisterSendCodec('A', codec_g729_1, 16000, 24000, 640, 1);
404 Run(channel_a_to_b_);
405 RegisterSendCodec('A', codec_g729_1, 16000, 24000, 960, 1);
406 Run(channel_a_to_b_);
407 RegisterSendCodec('A', codec_g729_1, 16000, 26000, 320, 1);
408 Run(channel_a_to_b_);
409 RegisterSendCodec('A', codec_g729_1, 16000, 26000, 640, 1);
410 Run(channel_a_to_b_);
411 RegisterSendCodec('A', codec_g729_1, 16000, 26000, 960, 1);
412 Run(channel_a_to_b_);
413 RegisterSendCodec('A', codec_g729_1, 16000, 28000, 320, 1);
414 Run(channel_a_to_b_);
415 RegisterSendCodec('A', codec_g729_1, 16000, 28000, 640, 1);
416 Run(channel_a_to_b_);
417 RegisterSendCodec('A', codec_g729_1, 16000, 28000, 960, 1);
418 Run(channel_a_to_b_);
419 RegisterSendCodec('A', codec_g729_1, 16000, 30000, 320, 1);
420 Run(channel_a_to_b_);
421 RegisterSendCodec('A', codec_g729_1, 16000, 30000, 640, 1);
422 Run(channel_a_to_b_);
423 RegisterSendCodec('A', codec_g729_1, 16000, 30000, 960, 1);
424 Run(channel_a_to_b_);
425 RegisterSendCodec('A', codec_g729_1, 16000, 32000, 320, 1);
426 Run(channel_a_to_b_);
427 RegisterSendCodec('A', codec_g729_1, 16000, 32000, 640, 1);
428 Run(channel_a_to_b_);
429 RegisterSendCodec('A', codec_g729_1, 16000, 32000, 960, 1);
430 Run(channel_a_to_b_);
431 outfile_b_.Close();
niklase@google.com470e71d2011-07-07 08:21:25 +0000432#endif
433#ifdef WEBRTC_CODEC_GSMFR
tina.legrand@webrtc.org50d5ca52012-06-18 13:35:52 +0000434 if (test_mode_ != 0) {
435 printf("===============================================================\n");
436 }
437 test_count_++;
438 OpenOutFile(test_count_);
439 char codec_gsmfr[] = "GSM";
440 RegisterSendCodec('A', codec_gsmfr, 8000, 13200, 160, 0);
441 Run(channel_a_to_b_);
442 RegisterSendCodec('A', codec_gsmfr, 8000, 13200, 320, 0);
443 Run(channel_a_to_b_);
444 RegisterSendCodec('A', codec_gsmfr, 8000, 13200, 480, 0);
445 Run(channel_a_to_b_);
446 outfile_b_.Close();
niklase@google.com470e71d2011-07-07 08:21:25 +0000447#endif
448#ifdef WEBRTC_CODEC_ILBC
tina.legrand@webrtc.org50d5ca52012-06-18 13:35:52 +0000449 if (test_mode_ != 0) {
450 printf("===============================================================\n");
451 }
452 test_count_++;
453 OpenOutFile(test_count_);
454 char codec_ilbc[] = "ILBC";
455 RegisterSendCodec('A', codec_ilbc, 8000, 13300, 240, 0);
456 Run(channel_a_to_b_);
457 RegisterSendCodec('A', codec_ilbc, 8000, 13300, 480, 0);
458 Run(channel_a_to_b_);
459 RegisterSendCodec('A', codec_ilbc, 8000, 15200, 160, 0);
460 Run(channel_a_to_b_);
461 RegisterSendCodec('A', codec_ilbc, 8000, 15200, 320, 0);
462 Run(channel_a_to_b_);
463 outfile_b_.Close();
niklase@google.com470e71d2011-07-07 08:21:25 +0000464#endif
465#if (defined(WEBRTC_CODEC_ISAC) || defined(WEBRTC_CODEC_ISACFX))
tina.legrand@webrtc.org50d5ca52012-06-18 13:35:52 +0000466 if (test_mode_ != 0) {
467 printf("===============================================================\n");
468 }
469 test_count_++;
470 OpenOutFile(test_count_);
471 char codec_isac[] = "ISAC";
472 RegisterSendCodec('A', codec_isac, 16000, -1, 480, -1);
473 Run(channel_a_to_b_);
474 RegisterSendCodec('A', codec_isac, 16000, -1, 960, -1);
475 Run(channel_a_to_b_);
476 RegisterSendCodec('A', codec_isac, 16000, 15000, 480, -1);
477 Run(channel_a_to_b_);
478 RegisterSendCodec('A', codec_isac, 16000, 32000, 960, -1);
479 Run(channel_a_to_b_);
480 outfile_b_.Close();
niklase@google.com470e71d2011-07-07 08:21:25 +0000481#endif
482#ifdef WEBRTC_CODEC_ISAC
tina.legrand@webrtc.org50d5ca52012-06-18 13:35:52 +0000483 if (test_mode_ != 0) {
484 printf("===============================================================\n");
485 }
486 test_count_++;
487 OpenOutFile(test_count_);
488 RegisterSendCodec('A', codec_isac, 32000, -1, 960, -1);
489 Run(channel_a_to_b_);
490 RegisterSendCodec('A', codec_isac, 32000, 56000, 960, -1);
491 Run(channel_a_to_b_);
492 RegisterSendCodec('A', codec_isac, 32000, 37000, 960, -1);
493 Run(channel_a_to_b_);
494 RegisterSendCodec('A', codec_isac, 32000, 32000, 960, -1);
495 Run(channel_a_to_b_);
496 outfile_b_.Close();
niklase@google.com470e71d2011-07-07 08:21:25 +0000497#endif
498#ifdef WEBRTC_CODEC_PCM16
tina.legrand@webrtc.org50d5ca52012-06-18 13:35:52 +0000499 if (test_mode_ != 0) {
500 printf("===============================================================\n");
501 }
502 test_count_++;
503 OpenOutFile(test_count_);
504 char codec_l16[] = "L16";
505 RegisterSendCodec('A', codec_l16, 8000, 128000, 80, 0);
506 Run(channel_a_to_b_);
507 RegisterSendCodec('A', codec_l16, 8000, 128000, 160, 0);
508 Run(channel_a_to_b_);
509 RegisterSendCodec('A', codec_l16, 8000, 128000, 240, 0);
510 Run(channel_a_to_b_);
511 RegisterSendCodec('A', codec_l16, 8000, 128000, 320, 0);
512 Run(channel_a_to_b_);
513 outfile_b_.Close();
514 if (test_mode_ != 0) {
515 printf("===============================================================\n");
516 }
517 test_count_++;
518 OpenOutFile(test_count_);
519 RegisterSendCodec('A', codec_l16, 16000, 256000, 160, 0);
520 Run(channel_a_to_b_);
521 RegisterSendCodec('A', codec_l16, 16000, 256000, 320, 0);
522 Run(channel_a_to_b_);
523 RegisterSendCodec('A', codec_l16, 16000, 256000, 480, 0);
524 Run(channel_a_to_b_);
525 RegisterSendCodec('A', codec_l16, 16000, 256000, 640, 0);
526 Run(channel_a_to_b_);
527 outfile_b_.Close();
528 if (test_mode_ != 0) {
529 printf("===============================================================\n");
530 }
531 test_count_++;
532 OpenOutFile(test_count_);
533 RegisterSendCodec('A', codec_l16, 32000, 512000, 320, 0);
534 Run(channel_a_to_b_);
535 RegisterSendCodec('A', codec_l16, 32000, 512000, 640, 0);
536 Run(channel_a_to_b_);
537 outfile_b_.Close();
niklase@google.com470e71d2011-07-07 08:21:25 +0000538#endif
tina.legrand@webrtc.org50d5ca52012-06-18 13:35:52 +0000539 if (test_mode_ != 0) {
540 printf("===============================================================\n");
541 }
542 test_count_++;
543 OpenOutFile(test_count_);
544 char codec_pcma[] = "PCMA";
545 RegisterSendCodec('A', codec_pcma, 8000, 64000, 80, 0);
546 Run(channel_a_to_b_);
547 RegisterSendCodec('A', codec_pcma, 8000, 64000, 160, 0);
548 Run(channel_a_to_b_);
549 RegisterSendCodec('A', codec_pcma, 8000, 64000, 240, 0);
550 Run(channel_a_to_b_);
551 RegisterSendCodec('A', codec_pcma, 8000, 64000, 320, 0);
552 Run(channel_a_to_b_);
553 RegisterSendCodec('A', codec_pcma, 8000, 64000, 400, 0);
554 Run(channel_a_to_b_);
555 RegisterSendCodec('A', codec_pcma, 8000, 64000, 480, 0);
556 Run(channel_a_to_b_);
557 if (test_mode_ != 0) {
558 printf("===============================================================\n");
559 }
560 char codec_pcmu[] = "PCMU";
561 RegisterSendCodec('A', codec_pcmu, 8000, 64000, 80, 0);
562 Run(channel_a_to_b_);
563 RegisterSendCodec('A', codec_pcmu, 8000, 64000, 160, 0);
564 Run(channel_a_to_b_);
565 RegisterSendCodec('A', codec_pcmu, 8000, 64000, 240, 0);
566 Run(channel_a_to_b_);
567 RegisterSendCodec('A', codec_pcmu, 8000, 64000, 320, 0);
568 Run(channel_a_to_b_);
569 RegisterSendCodec('A', codec_pcmu, 8000, 64000, 400, 0);
570 Run(channel_a_to_b_);
571 RegisterSendCodec('A', codec_pcmu, 8000, 64000, 480, 0);
572 Run(channel_a_to_b_);
573 outfile_b_.Close();
niklase@google.com470e71d2011-07-07 08:21:25 +0000574#ifdef WEBRTC_CODEC_SPEEX
tina.legrand@webrtc.org50d5ca52012-06-18 13:35:52 +0000575 if (test_mode_ != 0) {
576 printf("===============================================================\n");
577 }
578 test_count_++;
579 OpenOutFile(test_count_);
580 char codec_speex[] = "SPEEX";
581 RegisterSendCodec('A', codec_speex, 8000, 2400, 160, 0);
582 Run(channel_a_to_b_);
583 RegisterSendCodec('A', codec_speex, 8000, 8000, 320, 0);
584 Run(channel_a_to_b_);
585 RegisterSendCodec('A', codec_speex, 8000, 18200, 480, 0);
586 Run(channel_a_to_b_);
587 outfile_b_.Close();
niklase@google.com470e71d2011-07-07 08:21:25 +0000588
tina.legrand@webrtc.org50d5ca52012-06-18 13:35:52 +0000589 if (test_mode_ != 0) {
590 printf("===============================================================\n");
591 }
592 test_count_++;
593 OpenOutFile(test_count_);
594 RegisterSendCodec('A', codec_speex, 16000, 4000, 320, 0);
595 Run(channel_a_to_b_);
596 RegisterSendCodec('A', codec_speex, 16000, 12800, 640, 0);
597 Run(channel_a_to_b_);
598 RegisterSendCodec('A', codec_speex, 16000, 34200, 960, 0);
599 Run(channel_a_to_b_);
600 outfile_b_.Close();
niklase@google.com470e71d2011-07-07 08:21:25 +0000601#endif
tina.legrand@webrtc.orgdf697752012-02-08 10:22:21 +0000602#ifdef WEBRTC_CODEC_CELT
tina.legrand@webrtc.org50d5ca52012-06-18 13:35:52 +0000603 if (test_mode_ != 0) {
604 printf("===============================================================\n");
605 }
606 test_count_++;
607 OpenOutFile(test_count_);
608 char codec_celt[] = "CELT";
609 RegisterSendCodec('A', codec_celt, 32000, 48000, 640, 0);
610 Run(channel_a_to_b_);
611 RegisterSendCodec('A', codec_celt, 32000, 64000, 640, 0);
612 Run(channel_a_to_b_);
613 RegisterSendCodec('A', codec_celt, 32000, 128000, 640, 0);
614 Run(channel_a_to_b_);
615 outfile_b_.Close();
tina.legrand@webrtc.orgdf697752012-02-08 10:22:21 +0000616#endif
tina.legrand@webrtc.orga7d83872012-10-18 10:00:52 +0000617#ifdef WEBRTC_CODEC_OPUS
618 if (test_mode_ != 0) {
619 printf("===============================================================\n");
620 }
621 test_count_++;
622 OpenOutFile(test_count_);
623 char codec_opus[] = "OPUS";
624 RegisterSendCodec('A', codec_opus, 48000, 6000, 960, -1);
625 Run(channel_a_to_b_);
626 RegisterSendCodec('A', codec_opus, 48000, 20000, 960, -1);
627 Run(channel_a_to_b_);
628 RegisterSendCodec('A', codec_opus, 48000, 32000, 960, -1);
629 Run(channel_a_to_b_);
630 RegisterSendCodec('A', codec_opus, 48000, 48000, 960, -1);
631 Run(channel_a_to_b_);
632 RegisterSendCodec('A', codec_opus, 48000, 64000, 960, -1);
633 Run(channel_a_to_b_);
634 RegisterSendCodec('A', codec_opus, 48000, 96000, 960, -1);
635 Run(channel_a_to_b_);
636 RegisterSendCodec('A', codec_opus, 48000, 500000, 960, -1);
637 Run(channel_a_to_b_);
638#endif
tina.legrand@webrtc.org50d5ca52012-06-18 13:35:52 +0000639 if (test_mode_ != 0) {
640 printf("===============================================================\n");
niklase@google.com470e71d2011-07-07 08:21:25 +0000641
642 /* Print out all codecs that were not tested in the run */
tina.legrand@webrtc.org50d5ca52012-06-18 13:35:52 +0000643 printf("The following codecs was not included in the test:\n");
644#ifndef WEBRTC_CODEC_AMR
645 printf(" GSMAMR\n");
niklase@google.com470e71d2011-07-07 08:21:25 +0000646#endif
tina.legrand@webrtc.org50d5ca52012-06-18 13:35:52 +0000647#ifndef WEBRTC_CODEC_AMRWB
648 printf(" GSMAMR-wb\n");
niklase@google.com470e71d2011-07-07 08:21:25 +0000649#endif
650#ifndef WEBRTC_CODEC_G722
tina.legrand@webrtc.org50d5ca52012-06-18 13:35:52 +0000651 printf(" G.722\n");
niklase@google.com470e71d2011-07-07 08:21:25 +0000652#endif
653#ifndef WEBRTC_CODEC_G722_1
tina.legrand@webrtc.org50d5ca52012-06-18 13:35:52 +0000654 printf(" G.722.1\n");
niklase@google.com470e71d2011-07-07 08:21:25 +0000655#endif
656#ifndef WEBRTC_CODEC_G722_1C
tina.legrand@webrtc.org50d5ca52012-06-18 13:35:52 +0000657 printf(" G.722.1C\n");
niklase@google.com470e71d2011-07-07 08:21:25 +0000658#endif
659#ifndef WEBRTC_CODEC_G729
tina.legrand@webrtc.org50d5ca52012-06-18 13:35:52 +0000660 printf(" G.729\n");
niklase@google.com470e71d2011-07-07 08:21:25 +0000661#endif
662#ifndef WEBRTC_CODEC_G729_1
tina.legrand@webrtc.org50d5ca52012-06-18 13:35:52 +0000663 printf(" G.729.1\n");
niklase@google.com470e71d2011-07-07 08:21:25 +0000664#endif
665#ifndef WEBRTC_CODEC_GSMFR
tina.legrand@webrtc.org50d5ca52012-06-18 13:35:52 +0000666 printf(" GSMFR\n");
niklase@google.com470e71d2011-07-07 08:21:25 +0000667#endif
668#ifndef WEBRTC_CODEC_ILBC
tina.legrand@webrtc.org50d5ca52012-06-18 13:35:52 +0000669 printf(" iLBC\n");
niklase@google.com470e71d2011-07-07 08:21:25 +0000670#endif
671#ifndef WEBRTC_CODEC_ISAC
tina.legrand@webrtc.org50d5ca52012-06-18 13:35:52 +0000672 printf(" ISAC float\n");
niklase@google.com470e71d2011-07-07 08:21:25 +0000673#endif
674#ifndef WEBRTC_CODEC_ISACFX
tina.legrand@webrtc.org50d5ca52012-06-18 13:35:52 +0000675 printf(" ISAC fix\n");
niklase@google.com470e71d2011-07-07 08:21:25 +0000676#endif
677#ifndef WEBRTC_CODEC_PCM16
tina.legrand@webrtc.org50d5ca52012-06-18 13:35:52 +0000678 printf(" PCM16\n");
niklase@google.com470e71d2011-07-07 08:21:25 +0000679#endif
680#ifndef WEBRTC_CODEC_SPEEX
tina.legrand@webrtc.org50d5ca52012-06-18 13:35:52 +0000681 printf(" Speex\n");
niklase@google.com470e71d2011-07-07 08:21:25 +0000682#endif
683
tina.legrand@webrtc.org50d5ca52012-06-18 13:35:52 +0000684 printf("\nTo complete the test, listen to the %d number of output files.\n",
685 test_count_);
686 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000687}
688
689// Register Codec to use in the test
690//
tina.legrand@webrtc.org50d5ca52012-06-18 13:35:52 +0000691// Input: side - which ACM to use, 'A' or 'B'
692// codec_name - name to use when register the codec
693// sampling_freq_hz - sampling frequency in Herz
694// rate - bitrate in bytes
695// packet_size - packet size in samples
696// extra_byte - if extra bytes needed compared to the bitrate
niklase@google.com470e71d2011-07-07 08:21:25 +0000697// used when registering, can be an internal header
698// set to -1 if the codec is a variable rate codec
tina.legrand@webrtc.org50d5ca52012-06-18 13:35:52 +0000699void TestAllCodecs::RegisterSendCodec(char side, char* codec_name,
700 int32_t sampling_freq_hz, int rate,
701 int packet_size, int extra_byte) {
702 if (test_mode_ != 0) {
703 // Print out codec and settings.
704 printf("codec: %s Freq: %d Rate: %d PackSize: %d\n", codec_name,
705 sampling_freq_hz, rate, packet_size);
706 }
707
708 // Store packet-size in samples, used to validate the received packet.
709 // If G.722, store half the size to compensate for the timestamp bug in the
710 // RFC for G.722.
711 // If iSAC runs in adaptive mode, packet size in samples can change on the
712 // fly, so we exclude this test by setting |packet_size_samples_| to -1.
713 if (!strcmp(codec_name, "G722")) {
714 packet_size_samples_ = packet_size / 2;
715 } else if (!strcmp(codec_name, "ISAC") && (rate == -1)) {
716 packet_size_samples_ = -1;
717 } else {
718 packet_size_samples_ = packet_size;
719 }
720
721 // Store the expected packet size in bytes, used to validate the received
722 // packet. If variable rate codec (extra_byte == -1), set to -1 (65535).
723 if (extra_byte != -1) {
724 // Add 0.875 to always round up to a whole byte
725 packet_size_bytes_ =
726 static_cast<uint16_t>(static_cast<float>(packet_size * rate) /
727 static_cast<float>(sampling_freq_hz * 8) + 0.875) + extra_byte;
728 } else {
729 // Packets will have a variable size.
730 packet_size_bytes_ = -1;
731 }
732
733 // Set pointer to the ACM where to register the codec.
734 AudioCodingModule* my_acm = NULL;
735 switch (side) {
736 case 'A': {
737 my_acm = acm_a_;
738 break;
niklase@google.com470e71d2011-07-07 08:21:25 +0000739 }
tina.legrand@webrtc.org50d5ca52012-06-18 13:35:52 +0000740 case 'B': {
741 my_acm = acm_b_;
742 break;
niklase@google.com470e71d2011-07-07 08:21:25 +0000743 }
tina.legrand@webrtc.org50d5ca52012-06-18 13:35:52 +0000744 default: {
745 break;
niklase@google.com470e71d2011-07-07 08:21:25 +0000746 }
tina.legrand@webrtc.org50d5ca52012-06-18 13:35:52 +0000747 }
748 ASSERT_TRUE(my_acm != NULL);
niklase@google.com470e71d2011-07-07 08:21:25 +0000749
tina.legrand@webrtc.org50d5ca52012-06-18 13:35:52 +0000750 // Get all codec parameters before registering
751 CodecInst my_codec_param;
752 CHECK_ERROR(AudioCodingModule::Codec(codec_name, my_codec_param,
753 sampling_freq_hz, 1));
754 my_codec_param.rate = rate;
755 my_codec_param.pacsize = packet_size;
756 CHECK_ERROR(my_acm->RegisterSendCodec(my_codec_param));
niklase@google.com470e71d2011-07-07 08:21:25 +0000757}
758
tina.legrand@webrtc.org50d5ca52012-06-18 13:35:52 +0000759void TestAllCodecs::Run(TestPack* channel) {
760 AudioFrame audio_frame;
niklase@google.com470e71d2011-07-07 08:21:25 +0000761
tina.legrand@webrtc.org50d5ca52012-06-18 13:35:52 +0000762 int32_t out_freq_hz = outfile_b_.SamplingFrequency();
763 uint16_t receive_size;
764 uint32_t timestamp_diff;
765 channel->reset_payload_size();
766 int error_count = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000767
tina.legrand@webrtc.org50d5ca52012-06-18 13:35:52 +0000768 int counter = 0;
769 while (!infile_a_.EndOfFile()) {
770 // Add 10 msec to ACM.
771 infile_a_.Read10MsData(audio_frame);
772 CHECK_ERROR(acm_a_->Add10MsData(audio_frame));
niklase@google.com470e71d2011-07-07 08:21:25 +0000773
tina.legrand@webrtc.org50d5ca52012-06-18 13:35:52 +0000774 // Run sender side of ACM.
775 CHECK_ERROR(acm_a_->Process());
niklase@google.com470e71d2011-07-07 08:21:25 +0000776
tina.legrand@webrtc.org50d5ca52012-06-18 13:35:52 +0000777 // Verify that the received packet size matches the settings.
778 receive_size = channel->payload_size();
779 if (receive_size) {
780 if ((receive_size != packet_size_bytes_) &&
781 (packet_size_bytes_ < 65535)) {
782 error_count++;
783 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000784
tina.legrand@webrtc.org50d5ca52012-06-18 13:35:52 +0000785 // Verify that the timestamp is updated with expected length. The counter
786 // is used to avoid problems when switching codec or frame size in the
787 // test.
788 timestamp_diff = channel->timestamp_diff();
789 if ((counter > 10) && (timestamp_diff != packet_size_samples_) &&
790 (packet_size_samples_ < 65535))
791 error_count++;
niklase@google.com470e71d2011-07-07 08:21:25 +0000792 }
793
tina.legrand@webrtc.org50d5ca52012-06-18 13:35:52 +0000794 // Run received side of ACM.
795 CHECK_ERROR(acm_b_->PlayoutData10Ms(out_freq_hz, audio_frame));
niklase@google.com470e71d2011-07-07 08:21:25 +0000796
tina.legrand@webrtc.org50d5ca52012-06-18 13:35:52 +0000797 // Write output speech to file.
798 outfile_b_.Write10MsData(audio_frame.data_,
799 audio_frame.samples_per_channel_);
800
801 // Update loop counter
802 counter++;
803 }
804
805 EXPECT_EQ(0, error_count);
806
807 if (infile_a_.EndOfFile()) {
808 infile_a_.Rewind();
809 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000810}
811
tina.legrand@webrtc.org50d5ca52012-06-18 13:35:52 +0000812void TestAllCodecs::OpenOutFile(int test_number) {
813 std::string filename = webrtc::test::OutputPath();
814 std::ostringstream test_number_str;
815 test_number_str << test_number;
816 filename += "testallcodecs_out_";
817 filename += test_number_str.str();
818 filename += ".pcm";
tina.legrand@webrtc.orgba468042012-08-17 10:38:28 +0000819 outfile_b_.Open(filename, 32000, "wb");
niklase@google.com470e71d2011-07-07 08:21:25 +0000820}
821
tina.legrand@webrtc.org50d5ca52012-06-18 13:35:52 +0000822void TestAllCodecs::DisplaySendReceiveCodec() {
823 CodecInst my_codec_param;
824 acm_a_->SendCodec(my_codec_param);
825 printf("%s -> ", my_codec_param.plname);
826 acm_b_->ReceiveCodec(my_codec_param);
827 printf("%s\n", my_codec_param.plname);
niklase@google.com470e71d2011-07-07 08:21:25 +0000828}
829
tina.legrand@webrtc.org50d5ca52012-06-18 13:35:52 +0000830} // namespace webrtc
tina.legrand@webrtc.org554ae1a2011-12-16 10:09:04 +0000831