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