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