niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1 | /* |
tina.legrand@webrtc.org | df69775 | 2012-02-08 10:22:21 +0000 | [diff] [blame] | 2 | * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 3 | * |
| 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 Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 11 | #include "modules/audio_coding/test/TestAllCodecs.h" |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 12 | |
pkasting@chromium.org | 4591fbd | 2014-11-20 22:28:14 +0000 | [diff] [blame] | 13 | #include <cstdio> |
| 14 | #include <limits> |
tina.legrand@webrtc.org | 5e7ca60 | 2012-06-12 07:16:24 +0000 | [diff] [blame] | 15 | #include <string> |
kjellander@webrtc.org | 5490c71 | 2011-12-21 13:34:18 +0000 | [diff] [blame] | 16 | |
Karl Wiberg | 5817d3d | 2018-04-06 10:06:42 +0200 | [diff] [blame] | 17 | #include "api/audio_codecs/builtin_audio_decoder_factory.h" |
Karl Wiberg | 133cff0 | 2018-07-06 15:40:14 +0200 | [diff] [blame] | 18 | #include "api/audio_codecs/builtin_audio_encoder_factory.h" |
Mirko Bonadei | 7120742 | 2017-09-15 13:58:09 +0200 | [diff] [blame] | 19 | #include "common_types.h" // NOLINT(build/include) |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 20 | #include "modules/audio_coding/codecs/audio_format_conversion.h" |
| 21 | #include "modules/audio_coding/include/audio_coding_module.h" |
| 22 | #include "modules/audio_coding/include/audio_coding_module_typedefs.h" |
| 23 | #include "modules/audio_coding/test/utility.h" |
| 24 | #include "rtc_base/logging.h" |
Karl Wiberg | 133cff0 | 2018-07-06 15:40:14 +0200 | [diff] [blame] | 25 | #include "rtc_base/stringencode.h" |
Jonas Olsson | 366a50c | 2018-09-06 13:41:30 +0200 | [diff] [blame^] | 26 | #include "rtc_base/strings/string_builder.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 27 | #include "test/gtest.h" |
| 28 | #include "test/testsupport/fileutils.h" |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 29 | |
tina.legrand@webrtc.org | 50d5ca5 | 2012-06-18 13:35:52 +0000 | [diff] [blame] | 30 | // Description of the test: |
| 31 | // In this test we set up a one-way communication channel from a participant |
| 32 | // called "a" to a participant called "b". |
| 33 | // a -> channel_a_to_b -> b |
| 34 | // |
| 35 | // The test loops through all available mono codecs, encode at "a" sends over |
| 36 | // the channel, and decodes at "b". |
| 37 | |
pkasting@chromium.org | 4591fbd | 2014-11-20 22:28:14 +0000 | [diff] [blame] | 38 | namespace { |
| 39 | const size_t kVariableSize = std::numeric_limits<size_t>::max(); |
| 40 | } |
| 41 | |
tina.legrand@webrtc.org | 554ae1a | 2011-12-16 10:09:04 +0000 | [diff] [blame] | 42 | namespace webrtc { |
| 43 | |
tina.legrand@webrtc.org | 50d5ca5 | 2012-06-18 13:35:52 +0000 | [diff] [blame] | 44 | // Class for simulating packet handling. |
| 45 | TestPack::TestPack() |
| 46 | : receiver_acm_(NULL), |
| 47 | sequence_number_(0), |
| 48 | timestamp_diff_(0), |
| 49 | last_in_timestamp_(0), |
| 50 | total_bytes_(0), |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 51 | payload_size_(0) {} |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 52 | |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 53 | TestPack::~TestPack() {} |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 54 | |
tina.legrand@webrtc.org | 50d5ca5 | 2012-06-18 13:35:52 +0000 | [diff] [blame] | 55 | void TestPack::RegisterReceiverACM(AudioCodingModule* acm) { |
| 56 | receiver_acm_ = acm; |
| 57 | return; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 58 | } |
| 59 | |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 60 | int32_t TestPack::SendData(FrameType frame_type, |
| 61 | uint8_t payload_type, |
| 62 | uint32_t timestamp, |
| 63 | const uint8_t* payload_data, |
pkasting@chromium.org | 4591fbd | 2014-11-20 22:28:14 +0000 | [diff] [blame] | 64 | size_t payload_size, |
tina.legrand@webrtc.org | 50d5ca5 | 2012-06-18 13:35:52 +0000 | [diff] [blame] | 65 | const RTPFragmentationHeader* fragmentation) { |
| 66 | WebRtcRTPHeader rtp_info; |
| 67 | int32_t status; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 68 | |
tina.legrand@webrtc.org | 50d5ca5 | 2012-06-18 13:35:52 +0000 | [diff] [blame] | 69 | rtp_info.header.markerBit = false; |
| 70 | rtp_info.header.ssrc = 0; |
| 71 | rtp_info.header.sequenceNumber = sequence_number_++; |
| 72 | rtp_info.header.payloadType = payload_type; |
| 73 | rtp_info.header.timestamp = timestamp; |
philipel | 0a5fe77 | 2018-06-19 16:18:31 +0200 | [diff] [blame] | 74 | |
pbos | 22993e1 | 2015-10-19 02:39:06 -0700 | [diff] [blame] | 75 | if (frame_type == kEmptyFrame) { |
tina.legrand@webrtc.org | 50d5ca5 | 2012-06-18 13:35:52 +0000 | [diff] [blame] | 76 | // Skip this frame. |
| 77 | return 0; |
| 78 | } |
| 79 | |
| 80 | // Only run mono for all test cases. |
tina.legrand@webrtc.org | 50d5ca5 | 2012-06-18 13:35:52 +0000 | [diff] [blame] | 81 | memcpy(payload_data_, payload_data, payload_size); |
| 82 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 83 | status = receiver_acm_->IncomingPacket(payload_data_, payload_size, rtp_info); |
tina.legrand@webrtc.org | 50d5ca5 | 2012-06-18 13:35:52 +0000 | [diff] [blame] | 84 | |
| 85 | payload_size_ = payload_size; |
| 86 | timestamp_diff_ = timestamp - last_in_timestamp_; |
| 87 | last_in_timestamp_ = timestamp; |
| 88 | total_bytes_ += payload_size; |
| 89 | return status; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 90 | } |
| 91 | |
pkasting@chromium.org | 4591fbd | 2014-11-20 22:28:14 +0000 | [diff] [blame] | 92 | size_t TestPack::payload_size() { |
tina.legrand@webrtc.org | 50d5ca5 | 2012-06-18 13:35:52 +0000 | [diff] [blame] | 93 | return payload_size_; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 94 | } |
| 95 | |
tina.legrand@webrtc.org | 50d5ca5 | 2012-06-18 13:35:52 +0000 | [diff] [blame] | 96 | uint32_t TestPack::timestamp_diff() { |
| 97 | return timestamp_diff_; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 98 | } |
| 99 | |
tina.legrand@webrtc.org | 50d5ca5 | 2012-06-18 13:35:52 +0000 | [diff] [blame] | 100 | void TestPack::reset_payload_size() { |
| 101 | payload_size_ = 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 102 | } |
| 103 | |
henrik.lundin@webrtc.org | adaf809 | 2014-04-17 08:29:10 +0000 | [diff] [blame] | 104 | TestAllCodecs::TestAllCodecs(int test_mode) |
Karl Wiberg | 5817d3d | 2018-04-06 10:06:42 +0200 | [diff] [blame] | 105 | : acm_a_(AudioCodingModule::Create( |
| 106 | AudioCodingModule::Config(CreateBuiltinAudioDecoderFactory()))), |
| 107 | acm_b_(AudioCodingModule::Create( |
| 108 | AudioCodingModule::Config(CreateBuiltinAudioDecoderFactory()))), |
tina.legrand@webrtc.org | 50d5ca5 | 2012-06-18 13:35:52 +0000 | [diff] [blame] | 109 | channel_a_to_b_(NULL), |
| 110 | test_count_(0), |
| 111 | packet_size_samples_(0), |
| 112 | packet_size_bytes_(0) { |
| 113 | // test_mode = 0 for silent test (auto test) |
| 114 | test_mode_ = test_mode; |
| 115 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 116 | |
tina.legrand@webrtc.org | 50d5ca5 | 2012-06-18 13:35:52 +0000 | [diff] [blame] | 117 | TestAllCodecs::~TestAllCodecs() { |
tina.legrand@webrtc.org | 50d5ca5 | 2012-06-18 13:35:52 +0000 | [diff] [blame] | 118 | if (channel_a_to_b_ != NULL) { |
| 119 | delete channel_a_to_b_; |
| 120 | channel_a_to_b_ = NULL; |
| 121 | } |
| 122 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 123 | |
tina.legrand@webrtc.org | 50d5ca5 | 2012-06-18 13:35:52 +0000 | [diff] [blame] | 124 | void TestAllCodecs::Perform() { |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 125 | const std::string file_name = |
| 126 | webrtc::test::ResourcePath("audio_coding/testfile32kHz", "pcm"); |
tina.legrand@webrtc.org | ba46804 | 2012-08-17 10:38:28 +0000 | [diff] [blame] | 127 | infile_a_.Open(file_name, 32000, "rb"); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 128 | |
tina.legrand@webrtc.org | 50d5ca5 | 2012-06-18 13:35:52 +0000 | [diff] [blame] | 129 | if (test_mode_ == 0) { |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 130 | RTC_LOG(LS_INFO) << "---------- TestAllCodecs ----------"; |
tina.legrand@webrtc.org | 50d5ca5 | 2012-06-18 13:35:52 +0000 | [diff] [blame] | 131 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 132 | |
tina.legrand@webrtc.org | 50d5ca5 | 2012-06-18 13:35:52 +0000 | [diff] [blame] | 133 | acm_a_->InitializeReceiver(); |
| 134 | acm_b_->InitializeReceiver(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 135 | |
tina.legrand@webrtc.org | 50d5ca5 | 2012-06-18 13:35:52 +0000 | [diff] [blame] | 136 | uint8_t num_encoders = acm_a_->NumberOfCodecs(); |
| 137 | CodecInst my_codec_param; |
| 138 | for (uint8_t n = 0; n < num_encoders; n++) { |
tina.legrand@webrtc.org | 7a7a008 | 2013-02-21 10:27:48 +0000 | [diff] [blame] | 139 | acm_b_->Codec(n, &my_codec_param); |
tina.legrand@webrtc.org | c459058 | 2012-11-28 12:23:29 +0000 | [diff] [blame] | 140 | if (!strcmp(my_codec_param.plname, "opus")) { |
| 141 | my_codec_param.channels = 1; |
| 142 | } |
kwiberg | da2bf4e | 2016-10-24 13:47:09 -0700 | [diff] [blame] | 143 | acm_b_->RegisterReceiveCodec(my_codec_param.pltype, |
| 144 | CodecInstToSdp(my_codec_param)); |
tina.legrand@webrtc.org | 50d5ca5 | 2012-06-18 13:35:52 +0000 | [diff] [blame] | 145 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 146 | |
tina.legrand@webrtc.org | 50d5ca5 | 2012-06-18 13:35:52 +0000 | [diff] [blame] | 147 | // Create and connect the channel |
| 148 | channel_a_to_b_ = new TestPack; |
| 149 | acm_a_->RegisterTransportCallback(channel_a_to_b_); |
andrew@webrtc.org | 89df092 | 2013-09-12 01:27:43 +0000 | [diff] [blame] | 150 | channel_a_to_b_->RegisterReceiverACM(acm_b_.get()); |
tina.legrand@webrtc.org | 50d5ca5 | 2012-06-18 13:35:52 +0000 | [diff] [blame] | 151 | |
| 152 | // All codecs are tested for all allowed sampling frequencies, rates and |
| 153 | // packet sizes. |
tina.legrand@webrtc.org | 50d5ca5 | 2012-06-18 13:35:52 +0000 | [diff] [blame] | 154 | if (test_mode_ != 0) { |
| 155 | printf("===============================================================\n"); |
| 156 | } |
| 157 | test_count_++; |
| 158 | OpenOutFile(test_count_); |
| 159 | char codec_g722[] = "G722"; |
| 160 | RegisterSendCodec('A', codec_g722, 16000, 64000, 160, 0); |
| 161 | Run(channel_a_to_b_); |
| 162 | RegisterSendCodec('A', codec_g722, 16000, 64000, 320, 0); |
| 163 | Run(channel_a_to_b_); |
| 164 | RegisterSendCodec('A', codec_g722, 16000, 64000, 480, 0); |
| 165 | Run(channel_a_to_b_); |
| 166 | RegisterSendCodec('A', codec_g722, 16000, 64000, 640, 0); |
| 167 | Run(channel_a_to_b_); |
| 168 | RegisterSendCodec('A', codec_g722, 16000, 64000, 800, 0); |
| 169 | Run(channel_a_to_b_); |
| 170 | RegisterSendCodec('A', codec_g722, 16000, 64000, 960, 0); |
| 171 | Run(channel_a_to_b_); |
| 172 | outfile_b_.Close(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 173 | #ifdef WEBRTC_CODEC_ILBC |
tina.legrand@webrtc.org | 50d5ca5 | 2012-06-18 13:35:52 +0000 | [diff] [blame] | 174 | if (test_mode_ != 0) { |
| 175 | printf("===============================================================\n"); |
| 176 | } |
| 177 | test_count_++; |
| 178 | OpenOutFile(test_count_); |
| 179 | char codec_ilbc[] = "ILBC"; |
| 180 | RegisterSendCodec('A', codec_ilbc, 8000, 13300, 240, 0); |
| 181 | Run(channel_a_to_b_); |
| 182 | RegisterSendCodec('A', codec_ilbc, 8000, 13300, 480, 0); |
| 183 | Run(channel_a_to_b_); |
| 184 | RegisterSendCodec('A', codec_ilbc, 8000, 15200, 160, 0); |
| 185 | Run(channel_a_to_b_); |
| 186 | RegisterSendCodec('A', codec_ilbc, 8000, 15200, 320, 0); |
| 187 | Run(channel_a_to_b_); |
| 188 | outfile_b_.Close(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 189 | #endif |
| 190 | #if (defined(WEBRTC_CODEC_ISAC) || defined(WEBRTC_CODEC_ISACFX)) |
tina.legrand@webrtc.org | 50d5ca5 | 2012-06-18 13:35:52 +0000 | [diff] [blame] | 191 | if (test_mode_ != 0) { |
| 192 | printf("===============================================================\n"); |
| 193 | } |
| 194 | test_count_++; |
| 195 | OpenOutFile(test_count_); |
| 196 | char codec_isac[] = "ISAC"; |
pkasting@chromium.org | 4591fbd | 2014-11-20 22:28:14 +0000 | [diff] [blame] | 197 | RegisterSendCodec('A', codec_isac, 16000, -1, 480, kVariableSize); |
tina.legrand@webrtc.org | 50d5ca5 | 2012-06-18 13:35:52 +0000 | [diff] [blame] | 198 | Run(channel_a_to_b_); |
pkasting@chromium.org | 4591fbd | 2014-11-20 22:28:14 +0000 | [diff] [blame] | 199 | RegisterSendCodec('A', codec_isac, 16000, -1, 960, kVariableSize); |
tina.legrand@webrtc.org | 50d5ca5 | 2012-06-18 13:35:52 +0000 | [diff] [blame] | 200 | Run(channel_a_to_b_); |
pkasting@chromium.org | 4591fbd | 2014-11-20 22:28:14 +0000 | [diff] [blame] | 201 | RegisterSendCodec('A', codec_isac, 16000, 15000, 480, kVariableSize); |
tina.legrand@webrtc.org | 50d5ca5 | 2012-06-18 13:35:52 +0000 | [diff] [blame] | 202 | Run(channel_a_to_b_); |
pkasting@chromium.org | 4591fbd | 2014-11-20 22:28:14 +0000 | [diff] [blame] | 203 | RegisterSendCodec('A', codec_isac, 16000, 32000, 960, kVariableSize); |
tina.legrand@webrtc.org | 50d5ca5 | 2012-06-18 13:35:52 +0000 | [diff] [blame] | 204 | Run(channel_a_to_b_); |
| 205 | outfile_b_.Close(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 206 | #endif |
| 207 | #ifdef WEBRTC_CODEC_ISAC |
tina.legrand@webrtc.org | 50d5ca5 | 2012-06-18 13:35:52 +0000 | [diff] [blame] | 208 | if (test_mode_ != 0) { |
| 209 | printf("===============================================================\n"); |
| 210 | } |
| 211 | test_count_++; |
| 212 | OpenOutFile(test_count_); |
pkasting@chromium.org | 4591fbd | 2014-11-20 22:28:14 +0000 | [diff] [blame] | 213 | RegisterSendCodec('A', codec_isac, 32000, -1, 960, kVariableSize); |
tina.legrand@webrtc.org | 50d5ca5 | 2012-06-18 13:35:52 +0000 | [diff] [blame] | 214 | Run(channel_a_to_b_); |
pkasting@chromium.org | 4591fbd | 2014-11-20 22:28:14 +0000 | [diff] [blame] | 215 | RegisterSendCodec('A', codec_isac, 32000, 56000, 960, kVariableSize); |
tina.legrand@webrtc.org | 50d5ca5 | 2012-06-18 13:35:52 +0000 | [diff] [blame] | 216 | Run(channel_a_to_b_); |
pkasting@chromium.org | 4591fbd | 2014-11-20 22:28:14 +0000 | [diff] [blame] | 217 | RegisterSendCodec('A', codec_isac, 32000, 37000, 960, kVariableSize); |
tina.legrand@webrtc.org | 50d5ca5 | 2012-06-18 13:35:52 +0000 | [diff] [blame] | 218 | Run(channel_a_to_b_); |
pkasting@chromium.org | 4591fbd | 2014-11-20 22:28:14 +0000 | [diff] [blame] | 219 | RegisterSendCodec('A', codec_isac, 32000, 32000, 960, kVariableSize); |
tina.legrand@webrtc.org | 50d5ca5 | 2012-06-18 13:35:52 +0000 | [diff] [blame] | 220 | Run(channel_a_to_b_); |
| 221 | outfile_b_.Close(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 222 | #endif |
tina.legrand@webrtc.org | 50d5ca5 | 2012-06-18 13:35:52 +0000 | [diff] [blame] | 223 | if (test_mode_ != 0) { |
| 224 | printf("===============================================================\n"); |
| 225 | } |
| 226 | test_count_++; |
| 227 | OpenOutFile(test_count_); |
| 228 | char codec_l16[] = "L16"; |
| 229 | RegisterSendCodec('A', codec_l16, 8000, 128000, 80, 0); |
| 230 | Run(channel_a_to_b_); |
| 231 | RegisterSendCodec('A', codec_l16, 8000, 128000, 160, 0); |
| 232 | Run(channel_a_to_b_); |
| 233 | RegisterSendCodec('A', codec_l16, 8000, 128000, 240, 0); |
| 234 | Run(channel_a_to_b_); |
| 235 | RegisterSendCodec('A', codec_l16, 8000, 128000, 320, 0); |
| 236 | Run(channel_a_to_b_); |
| 237 | outfile_b_.Close(); |
| 238 | if (test_mode_ != 0) { |
| 239 | printf("===============================================================\n"); |
| 240 | } |
| 241 | test_count_++; |
| 242 | OpenOutFile(test_count_); |
| 243 | RegisterSendCodec('A', codec_l16, 16000, 256000, 160, 0); |
| 244 | Run(channel_a_to_b_); |
| 245 | RegisterSendCodec('A', codec_l16, 16000, 256000, 320, 0); |
| 246 | Run(channel_a_to_b_); |
| 247 | RegisterSendCodec('A', codec_l16, 16000, 256000, 480, 0); |
| 248 | Run(channel_a_to_b_); |
| 249 | RegisterSendCodec('A', codec_l16, 16000, 256000, 640, 0); |
| 250 | Run(channel_a_to_b_); |
| 251 | outfile_b_.Close(); |
| 252 | if (test_mode_ != 0) { |
| 253 | printf("===============================================================\n"); |
| 254 | } |
| 255 | test_count_++; |
| 256 | OpenOutFile(test_count_); |
| 257 | RegisterSendCodec('A', codec_l16, 32000, 512000, 320, 0); |
| 258 | Run(channel_a_to_b_); |
| 259 | RegisterSendCodec('A', codec_l16, 32000, 512000, 640, 0); |
| 260 | Run(channel_a_to_b_); |
| 261 | outfile_b_.Close(); |
tina.legrand@webrtc.org | 50d5ca5 | 2012-06-18 13:35:52 +0000 | [diff] [blame] | 262 | if (test_mode_ != 0) { |
| 263 | printf("===============================================================\n"); |
| 264 | } |
| 265 | test_count_++; |
| 266 | OpenOutFile(test_count_); |
| 267 | char codec_pcma[] = "PCMA"; |
| 268 | RegisterSendCodec('A', codec_pcma, 8000, 64000, 80, 0); |
| 269 | Run(channel_a_to_b_); |
| 270 | RegisterSendCodec('A', codec_pcma, 8000, 64000, 160, 0); |
| 271 | Run(channel_a_to_b_); |
| 272 | RegisterSendCodec('A', codec_pcma, 8000, 64000, 240, 0); |
| 273 | Run(channel_a_to_b_); |
| 274 | RegisterSendCodec('A', codec_pcma, 8000, 64000, 320, 0); |
| 275 | Run(channel_a_to_b_); |
| 276 | RegisterSendCodec('A', codec_pcma, 8000, 64000, 400, 0); |
| 277 | Run(channel_a_to_b_); |
| 278 | RegisterSendCodec('A', codec_pcma, 8000, 64000, 480, 0); |
| 279 | Run(channel_a_to_b_); |
| 280 | if (test_mode_ != 0) { |
| 281 | printf("===============================================================\n"); |
| 282 | } |
| 283 | char codec_pcmu[] = "PCMU"; |
| 284 | RegisterSendCodec('A', codec_pcmu, 8000, 64000, 80, 0); |
| 285 | Run(channel_a_to_b_); |
| 286 | RegisterSendCodec('A', codec_pcmu, 8000, 64000, 160, 0); |
| 287 | Run(channel_a_to_b_); |
| 288 | RegisterSendCodec('A', codec_pcmu, 8000, 64000, 240, 0); |
| 289 | Run(channel_a_to_b_); |
| 290 | RegisterSendCodec('A', codec_pcmu, 8000, 64000, 320, 0); |
| 291 | Run(channel_a_to_b_); |
| 292 | RegisterSendCodec('A', codec_pcmu, 8000, 64000, 400, 0); |
| 293 | Run(channel_a_to_b_); |
| 294 | RegisterSendCodec('A', codec_pcmu, 8000, 64000, 480, 0); |
| 295 | Run(channel_a_to_b_); |
| 296 | outfile_b_.Close(); |
tina.legrand@webrtc.org | a7d8387 | 2012-10-18 10:00:52 +0000 | [diff] [blame] | 297 | #ifdef WEBRTC_CODEC_OPUS |
| 298 | if (test_mode_ != 0) { |
| 299 | printf("===============================================================\n"); |
| 300 | } |
| 301 | test_count_++; |
| 302 | OpenOutFile(test_count_); |
| 303 | char codec_opus[] = "OPUS"; |
pkasting@chromium.org | 4591fbd | 2014-11-20 22:28:14 +0000 | [diff] [blame] | 304 | RegisterSendCodec('A', codec_opus, 48000, 6000, 480, kVariableSize); |
tina.legrand@webrtc.org | a7d8387 | 2012-10-18 10:00:52 +0000 | [diff] [blame] | 305 | Run(channel_a_to_b_); |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 306 | RegisterSendCodec('A', codec_opus, 48000, 20000, 480 * 2, kVariableSize); |
tina.legrand@webrtc.org | a7d8387 | 2012-10-18 10:00:52 +0000 | [diff] [blame] | 307 | Run(channel_a_to_b_); |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 308 | RegisterSendCodec('A', codec_opus, 48000, 32000, 480 * 4, kVariableSize); |
tina.legrand@webrtc.org | a7d8387 | 2012-10-18 10:00:52 +0000 | [diff] [blame] | 309 | Run(channel_a_to_b_); |
pkasting@chromium.org | 4591fbd | 2014-11-20 22:28:14 +0000 | [diff] [blame] | 310 | RegisterSendCodec('A', codec_opus, 48000, 48000, 480, kVariableSize); |
tina.legrand@webrtc.org | a7d8387 | 2012-10-18 10:00:52 +0000 | [diff] [blame] | 311 | Run(channel_a_to_b_); |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 312 | RegisterSendCodec('A', codec_opus, 48000, 64000, 480 * 4, kVariableSize); |
tina.legrand@webrtc.org | a7d8387 | 2012-10-18 10:00:52 +0000 | [diff] [blame] | 313 | Run(channel_a_to_b_); |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 314 | RegisterSendCodec('A', codec_opus, 48000, 96000, 480 * 6, kVariableSize); |
tina.legrand@webrtc.org | a7d8387 | 2012-10-18 10:00:52 +0000 | [diff] [blame] | 315 | Run(channel_a_to_b_); |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 316 | RegisterSendCodec('A', codec_opus, 48000, 500000, 480 * 2, kVariableSize); |
tina.legrand@webrtc.org | a7d8387 | 2012-10-18 10:00:52 +0000 | [diff] [blame] | 317 | Run(channel_a_to_b_); |
tina.legrand@webrtc.org | c459058 | 2012-11-28 12:23:29 +0000 | [diff] [blame] | 318 | outfile_b_.Close(); |
tina.legrand@webrtc.org | a7d8387 | 2012-10-18 10:00:52 +0000 | [diff] [blame] | 319 | #endif |
tina.legrand@webrtc.org | 50d5ca5 | 2012-06-18 13:35:52 +0000 | [diff] [blame] | 320 | if (test_mode_ != 0) { |
| 321 | printf("===============================================================\n"); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 322 | |
| 323 | /* Print out all codecs that were not tested in the run */ |
tina.legrand@webrtc.org | 50d5ca5 | 2012-06-18 13:35:52 +0000 | [diff] [blame] | 324 | printf("The following codecs was not included in the test:\n"); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 325 | #ifndef WEBRTC_CODEC_ILBC |
tina.legrand@webrtc.org | 50d5ca5 | 2012-06-18 13:35:52 +0000 | [diff] [blame] | 326 | printf(" iLBC\n"); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 327 | #endif |
| 328 | #ifndef WEBRTC_CODEC_ISAC |
tina.legrand@webrtc.org | 50d5ca5 | 2012-06-18 13:35:52 +0000 | [diff] [blame] | 329 | printf(" ISAC float\n"); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 330 | #endif |
| 331 | #ifndef WEBRTC_CODEC_ISACFX |
tina.legrand@webrtc.org | 50d5ca5 | 2012-06-18 13:35:52 +0000 | [diff] [blame] | 332 | printf(" ISAC fix\n"); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 333 | #endif |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 334 | |
tina.legrand@webrtc.org | 50d5ca5 | 2012-06-18 13:35:52 +0000 | [diff] [blame] | 335 | printf("\nTo complete the test, listen to the %d number of output files.\n", |
| 336 | test_count_); |
| 337 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 338 | } |
| 339 | |
| 340 | // Register Codec to use in the test |
| 341 | // |
tina.legrand@webrtc.org | 50d5ca5 | 2012-06-18 13:35:52 +0000 | [diff] [blame] | 342 | // Input: side - which ACM to use, 'A' or 'B' |
| 343 | // codec_name - name to use when register the codec |
| 344 | // sampling_freq_hz - sampling frequency in Herz |
| 345 | // rate - bitrate in bytes |
| 346 | // packet_size - packet size in samples |
| 347 | // extra_byte - if extra bytes needed compared to the bitrate |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 348 | // used when registering, can be an internal header |
pkasting@chromium.org | 4591fbd | 2014-11-20 22:28:14 +0000 | [diff] [blame] | 349 | // set to kVariableSize if the codec is a variable |
| 350 | // rate codec |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 351 | void TestAllCodecs::RegisterSendCodec(char side, |
| 352 | char* codec_name, |
| 353 | int32_t sampling_freq_hz, |
| 354 | int rate, |
| 355 | int packet_size, |
| 356 | size_t extra_byte) { |
tina.legrand@webrtc.org | 50d5ca5 | 2012-06-18 13:35:52 +0000 | [diff] [blame] | 357 | if (test_mode_ != 0) { |
| 358 | // Print out codec and settings. |
| 359 | printf("codec: %s Freq: %d Rate: %d PackSize: %d\n", codec_name, |
| 360 | sampling_freq_hz, rate, packet_size); |
| 361 | } |
| 362 | |
| 363 | // Store packet-size in samples, used to validate the received packet. |
| 364 | // If G.722, store half the size to compensate for the timestamp bug in the |
| 365 | // RFC for G.722. |
| 366 | // If iSAC runs in adaptive mode, packet size in samples can change on the |
| 367 | // fly, so we exclude this test by setting |packet_size_samples_| to -1. |
| 368 | if (!strcmp(codec_name, "G722")) { |
| 369 | packet_size_samples_ = packet_size / 2; |
| 370 | } else if (!strcmp(codec_name, "ISAC") && (rate == -1)) { |
| 371 | packet_size_samples_ = -1; |
| 372 | } else { |
| 373 | packet_size_samples_ = packet_size; |
| 374 | } |
| 375 | |
| 376 | // Store the expected packet size in bytes, used to validate the received |
henrike@webrtc.org | 6ac22e6 | 2014-08-11 21:06:30 +0000 | [diff] [blame] | 377 | // packet. If variable rate codec (extra_byte == -1), set to -1. |
pkasting@chromium.org | 4591fbd | 2014-11-20 22:28:14 +0000 | [diff] [blame] | 378 | if (extra_byte != kVariableSize) { |
tina.legrand@webrtc.org | 50d5ca5 | 2012-06-18 13:35:52 +0000 | [diff] [blame] | 379 | // Add 0.875 to always round up to a whole byte |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 380 | packet_size_bytes_ = |
| 381 | static_cast<size_t>(static_cast<float>(packet_size * rate) / |
| 382 | static_cast<float>(sampling_freq_hz * 8) + |
| 383 | 0.875) + |
| 384 | extra_byte; |
tina.legrand@webrtc.org | 50d5ca5 | 2012-06-18 13:35:52 +0000 | [diff] [blame] | 385 | } else { |
| 386 | // Packets will have a variable size. |
pkasting@chromium.org | 4591fbd | 2014-11-20 22:28:14 +0000 | [diff] [blame] | 387 | packet_size_bytes_ = kVariableSize; |
tina.legrand@webrtc.org | 50d5ca5 | 2012-06-18 13:35:52 +0000 | [diff] [blame] | 388 | } |
| 389 | |
| 390 | // Set pointer to the ACM where to register the codec. |
| 391 | AudioCodingModule* my_acm = NULL; |
| 392 | switch (side) { |
| 393 | case 'A': { |
andrew@webrtc.org | 89df092 | 2013-09-12 01:27:43 +0000 | [diff] [blame] | 394 | my_acm = acm_a_.get(); |
tina.legrand@webrtc.org | 50d5ca5 | 2012-06-18 13:35:52 +0000 | [diff] [blame] | 395 | break; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 396 | } |
tina.legrand@webrtc.org | 50d5ca5 | 2012-06-18 13:35:52 +0000 | [diff] [blame] | 397 | case 'B': { |
andrew@webrtc.org | 89df092 | 2013-09-12 01:27:43 +0000 | [diff] [blame] | 398 | my_acm = acm_b_.get(); |
tina.legrand@webrtc.org | 50d5ca5 | 2012-06-18 13:35:52 +0000 | [diff] [blame] | 399 | break; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 400 | } |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 401 | default: { break; } |
tina.legrand@webrtc.org | 50d5ca5 | 2012-06-18 13:35:52 +0000 | [diff] [blame] | 402 | } |
| 403 | ASSERT_TRUE(my_acm != NULL); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 404 | |
tina.legrand@webrtc.org | 50d5ca5 | 2012-06-18 13:35:52 +0000 | [diff] [blame] | 405 | // Get all codec parameters before registering |
| 406 | CodecInst my_codec_param; |
tina.legrand@webrtc.org | 7a7a008 | 2013-02-21 10:27:48 +0000 | [diff] [blame] | 407 | CHECK_ERROR(AudioCodingModule::Codec(codec_name, &my_codec_param, |
tina.legrand@webrtc.org | 50d5ca5 | 2012-06-18 13:35:52 +0000 | [diff] [blame] | 408 | sampling_freq_hz, 1)); |
| 409 | my_codec_param.rate = rate; |
| 410 | my_codec_param.pacsize = packet_size; |
Karl Wiberg | 133cff0 | 2018-07-06 15:40:14 +0200 | [diff] [blame] | 411 | |
| 412 | auto factory = CreateBuiltinAudioEncoderFactory(); |
| 413 | constexpr int payload_type = 17; |
| 414 | SdpAudioFormat format = CodecInstToSdp(my_codec_param); |
| 415 | format.parameters["ptime"] = rtc::ToString(rtc::CheckedDivExact( |
| 416 | packet_size, rtc::CheckedDivExact(sampling_freq_hz, 1000))); |
| 417 | my_acm->SetEncoder( |
| 418 | factory->MakeAudioEncoder(payload_type, format, absl::nullopt)); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 419 | } |
| 420 | |
tina.legrand@webrtc.org | 50d5ca5 | 2012-06-18 13:35:52 +0000 | [diff] [blame] | 421 | void TestAllCodecs::Run(TestPack* channel) { |
| 422 | AudioFrame audio_frame; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 423 | |
tina.legrand@webrtc.org | 50d5ca5 | 2012-06-18 13:35:52 +0000 | [diff] [blame] | 424 | int32_t out_freq_hz = outfile_b_.SamplingFrequency(); |
pkasting@chromium.org | 4591fbd | 2014-11-20 22:28:14 +0000 | [diff] [blame] | 425 | size_t receive_size; |
tina.legrand@webrtc.org | 50d5ca5 | 2012-06-18 13:35:52 +0000 | [diff] [blame] | 426 | uint32_t timestamp_diff; |
| 427 | channel->reset_payload_size(); |
| 428 | int error_count = 0; |
tina.legrand@webrtc.org | 50d5ca5 | 2012-06-18 13:35:52 +0000 | [diff] [blame] | 429 | int counter = 0; |
Henrik Lundin | 4d68208 | 2015-12-10 16:24:39 +0100 | [diff] [blame] | 430 | // Set test length to 500 ms (50 blocks of 10 ms each). |
| 431 | infile_a_.SetNum10MsBlocksToRead(50); |
| 432 | // Fast-forward 1 second (100 blocks) since the file starts with silence. |
| 433 | infile_a_.FastForward(100); |
| 434 | |
tina.legrand@webrtc.org | 50d5ca5 | 2012-06-18 13:35:52 +0000 | [diff] [blame] | 435 | while (!infile_a_.EndOfFile()) { |
| 436 | // Add 10 msec to ACM. |
| 437 | infile_a_.Read10MsData(audio_frame); |
| 438 | CHECK_ERROR(acm_a_->Add10MsData(audio_frame)); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 439 | |
tina.legrand@webrtc.org | 50d5ca5 | 2012-06-18 13:35:52 +0000 | [diff] [blame] | 440 | // Verify that the received packet size matches the settings. |
| 441 | receive_size = channel->payload_size(); |
| 442 | if (receive_size) { |
pkasting@chromium.org | 4591fbd | 2014-11-20 22:28:14 +0000 | [diff] [blame] | 443 | if ((receive_size != packet_size_bytes_) && |
| 444 | (packet_size_bytes_ != kVariableSize)) { |
tina.legrand@webrtc.org | 50d5ca5 | 2012-06-18 13:35:52 +0000 | [diff] [blame] | 445 | error_count++; |
| 446 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 447 | |
tina.legrand@webrtc.org | 50d5ca5 | 2012-06-18 13:35:52 +0000 | [diff] [blame] | 448 | // Verify that the timestamp is updated with expected length. The counter |
| 449 | // is used to avoid problems when switching codec or frame size in the |
| 450 | // test. |
| 451 | timestamp_diff = channel->timestamp_diff(); |
henrike@webrtc.org | 6ac22e6 | 2014-08-11 21:06:30 +0000 | [diff] [blame] | 452 | if ((counter > 10) && |
| 453 | (static_cast<int>(timestamp_diff) != packet_size_samples_) && |
| 454 | (packet_size_samples_ > -1)) |
tina.legrand@webrtc.org | 50d5ca5 | 2012-06-18 13:35:52 +0000 | [diff] [blame] | 455 | error_count++; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 456 | } |
| 457 | |
tina.legrand@webrtc.org | 50d5ca5 | 2012-06-18 13:35:52 +0000 | [diff] [blame] | 458 | // Run received side of ACM. |
henrik.lundin | d4ccb00 | 2016-05-17 12:21:55 -0700 | [diff] [blame] | 459 | bool muted; |
| 460 | CHECK_ERROR(acm_b_->PlayoutData10Ms(out_freq_hz, &audio_frame, &muted)); |
| 461 | ASSERT_FALSE(muted); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 462 | |
tina.legrand@webrtc.org | 50d5ca5 | 2012-06-18 13:35:52 +0000 | [diff] [blame] | 463 | // Write output speech to file. |
yujo | 36b1a5f | 2017-06-12 12:45:32 -0700 | [diff] [blame] | 464 | outfile_b_.Write10MsData(audio_frame.data(), |
tina.legrand@webrtc.org | 50d5ca5 | 2012-06-18 13:35:52 +0000 | [diff] [blame] | 465 | audio_frame.samples_per_channel_); |
| 466 | |
| 467 | // Update loop counter |
| 468 | counter++; |
| 469 | } |
| 470 | |
| 471 | EXPECT_EQ(0, error_count); |
| 472 | |
| 473 | if (infile_a_.EndOfFile()) { |
| 474 | infile_a_.Rewind(); |
| 475 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 476 | } |
| 477 | |
tina.legrand@webrtc.org | 50d5ca5 | 2012-06-18 13:35:52 +0000 | [diff] [blame] | 478 | void TestAllCodecs::OpenOutFile(int test_number) { |
| 479 | std::string filename = webrtc::test::OutputPath(); |
Jonas Olsson | 366a50c | 2018-09-06 13:41:30 +0200 | [diff] [blame^] | 480 | rtc::StringBuilder test_number_str; |
tina.legrand@webrtc.org | 50d5ca5 | 2012-06-18 13:35:52 +0000 | [diff] [blame] | 481 | test_number_str << test_number; |
| 482 | filename += "testallcodecs_out_"; |
| 483 | filename += test_number_str.str(); |
| 484 | filename += ".pcm"; |
tina.legrand@webrtc.org | ba46804 | 2012-08-17 10:38:28 +0000 | [diff] [blame] | 485 | outfile_b_.Open(filename, 32000, "wb"); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 486 | } |
| 487 | |
tina.legrand@webrtc.org | 50d5ca5 | 2012-06-18 13:35:52 +0000 | [diff] [blame] | 488 | void TestAllCodecs::DisplaySendReceiveCodec() { |
| 489 | CodecInst my_codec_param; |
kwiberg | 1fd4a4a | 2015-11-03 11:20:50 -0800 | [diff] [blame] | 490 | printf("%s -> ", acm_a_->SendCodec()->plname); |
tina.legrand@webrtc.org | 7a7a008 | 2013-02-21 10:27:48 +0000 | [diff] [blame] | 491 | acm_b_->ReceiveCodec(&my_codec_param); |
tina.legrand@webrtc.org | 50d5ca5 | 2012-06-18 13:35:52 +0000 | [diff] [blame] | 492 | printf("%s\n", my_codec_param.plname); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 493 | } |
| 494 | |
tina.legrand@webrtc.org | 50d5ca5 | 2012-06-18 13:35:52 +0000 | [diff] [blame] | 495 | } // namespace webrtc |