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/TestStereo.h" |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 12 | |
tina.legrand@webrtc.org | a092cbf | 2013-02-14 09:28:10 +0000 | [diff] [blame] | 13 | #include <string> |
kjellander@webrtc.org | 5490c71 | 2011-12-21 13:34:18 +0000 | [diff] [blame] | 14 | |
Niels Möller | 2edab4c | 2018-10-22 09:48:08 +0200 | [diff] [blame] | 15 | #include "absl/strings/match.h" |
Karl Wiberg | 5817d3d | 2018-04-06 10:06:42 +0200 | [diff] [blame] | 16 | #include "api/audio_codecs/builtin_audio_decoder_factory.h" |
Karl Wiberg | d363db1 | 2018-09-24 14:45:24 +0200 | [diff] [blame] | 17 | #include "api/audio_codecs/builtin_audio_encoder_factory.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 18 | #include "modules/audio_coding/include/audio_coding_module_typedefs.h" |
Fredrik Solenberg | 657b296 | 2018-12-05 10:30:25 +0100 | [diff] [blame] | 19 | #include "modules/include/module_common_types.h" |
Jonas Olsson | 366a50c | 2018-09-06 13:41:30 +0200 | [diff] [blame] | 20 | #include "rtc_base/strings/string_builder.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 21 | #include "test/gtest.h" |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 22 | #include "test/testsupport/file_utils.h" |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 23 | |
tina.legrand@webrtc.org | 554ae1a | 2011-12-16 10:09:04 +0000 | [diff] [blame] | 24 | namespace webrtc { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 25 | |
| 26 | // Class for simulating packet handling |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 27 | TestPackStereo::TestPackStereo() |
| 28 | : receiver_acm_(NULL), |
| 29 | seq_no_(0), |
| 30 | timestamp_diff_(0), |
| 31 | last_in_timestamp_(0), |
| 32 | total_bytes_(0), |
| 33 | payload_size_(0), |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 34 | lost_packet_(false) {} |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 35 | |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 36 | TestPackStereo::~TestPackStereo() {} |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 37 | |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 38 | void TestPackStereo::RegisterReceiverACM(AudioCodingModule* acm) { |
| 39 | receiver_acm_ = acm; |
| 40 | return; |
| 41 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 42 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 43 | int32_t TestPackStereo::SendData(const FrameType frame_type, |
| 44 | const uint8_t payload_type, |
| 45 | const uint32_t timestamp, |
| 46 | const uint8_t* payload_data, |
pkasting@chromium.org | 4591fbd | 2014-11-20 22:28:14 +0000 | [diff] [blame] | 47 | const size_t payload_size, |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 48 | const RTPFragmentationHeader* fragmentation) { |
Niels Möller | afb5dbb | 2019-02-15 15:21:47 +0100 | [diff] [blame] | 49 | RTPHeader rtp_header; |
pbos@webrtc.org | 0946a56 | 2013-04-09 00:28:06 +0000 | [diff] [blame] | 50 | int32_t status = 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 51 | |
Niels Möller | afb5dbb | 2019-02-15 15:21:47 +0100 | [diff] [blame] | 52 | rtp_header.markerBit = false; |
| 53 | rtp_header.ssrc = 0; |
| 54 | rtp_header.sequenceNumber = seq_no_++; |
| 55 | rtp_header.payloadType = payload_type; |
| 56 | rtp_header.timestamp = timestamp; |
pbos | 22993e1 | 2015-10-19 02:39:06 -0700 | [diff] [blame] | 57 | if (frame_type == kEmptyFrame) { |
tina.legrand@webrtc.org | 16b6b90 | 2012-04-12 11:02:38 +0000 | [diff] [blame] | 58 | // Skip this frame |
| 59 | return 0; |
| 60 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 61 | |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 62 | if (lost_packet_ == false) { |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 63 | status = |
Niels Möller | afb5dbb | 2019-02-15 15:21:47 +0100 | [diff] [blame] | 64 | receiver_acm_->IncomingPacket(payload_data, payload_size, rtp_header); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 65 | |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 66 | if (frame_type != kAudioFrameCN) { |
henrike@webrtc.org | 6ac22e6 | 2014-08-11 21:06:30 +0000 | [diff] [blame] | 67 | payload_size_ = static_cast<int>(payload_size); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 68 | } else { |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 69 | payload_size_ = -1; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 70 | } |
tina.legrand@webrtc.org | 16b6b90 | 2012-04-12 11:02:38 +0000 | [diff] [blame] | 71 | |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 72 | timestamp_diff_ = timestamp - last_in_timestamp_; |
| 73 | last_in_timestamp_ = timestamp; |
| 74 | total_bytes_ += payload_size; |
tina.legrand@webrtc.org | 16b6b90 | 2012-04-12 11:02:38 +0000 | [diff] [blame] | 75 | } |
| 76 | return status; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 77 | } |
| 78 | |
pbos@webrtc.org | 0946a56 | 2013-04-09 00:28:06 +0000 | [diff] [blame] | 79 | uint16_t TestPackStereo::payload_size() { |
henrike@webrtc.org | 6ac22e6 | 2014-08-11 21:06:30 +0000 | [diff] [blame] | 80 | return static_cast<uint16_t>(payload_size_); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 81 | } |
| 82 | |
pbos@webrtc.org | 0946a56 | 2013-04-09 00:28:06 +0000 | [diff] [blame] | 83 | uint32_t TestPackStereo::timestamp_diff() { |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 84 | return timestamp_diff_; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 85 | } |
| 86 | |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 87 | void TestPackStereo::reset_payload_size() { |
| 88 | payload_size_ = 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 89 | } |
| 90 | |
tina.legrand@webrtc.org | 16b6b90 | 2012-04-12 11:02:38 +0000 | [diff] [blame] | 91 | void TestPackStereo::set_codec_mode(enum StereoMonoMode mode) { |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 92 | codec_mode_ = mode; |
tina.legrand@webrtc.org | 16b6b90 | 2012-04-12 11:02:38 +0000 | [diff] [blame] | 93 | } |
| 94 | |
| 95 | void TestPackStereo::set_lost_packet(bool lost) { |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 96 | lost_packet_ = lost; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 97 | } |
| 98 | |
Fredrik Solenberg | 657b296 | 2018-12-05 10:30:25 +0100 | [diff] [blame] | 99 | TestStereo::TestStereo() |
Karl Wiberg | 5817d3d | 2018-04-06 10:06:42 +0200 | [diff] [blame] | 100 | : acm_a_(AudioCodingModule::Create( |
| 101 | AudioCodingModule::Config(CreateBuiltinAudioDecoderFactory()))), |
| 102 | acm_b_(AudioCodingModule::Create( |
| 103 | AudioCodingModule::Config(CreateBuiltinAudioDecoderFactory()))), |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 104 | channel_a2b_(NULL), |
| 105 | test_cntr_(0), |
| 106 | pack_size_samp_(0), |
| 107 | pack_size_bytes_(0), |
Karl Wiberg | 36b37dc | 2018-09-24 10:52:32 +0200 | [diff] [blame] | 108 | counter_(0) { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 109 | } |
| 110 | |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 111 | TestStereo::~TestStereo() { |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 112 | if (channel_a2b_ != NULL) { |
| 113 | delete channel_a2b_; |
| 114 | channel_a2b_ = NULL; |
| 115 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 116 | } |
| 117 | |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 118 | void TestStereo::Perform() { |
pbos@webrtc.org | 0946a56 | 2013-04-09 00:28:06 +0000 | [diff] [blame] | 119 | uint16_t frequency_hz; |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 120 | int audio_channels; |
| 121 | int codec_channels; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 122 | |
tina.legrand@webrtc.org | 4517585 | 2012-06-01 09:27:35 +0000 | [diff] [blame] | 123 | // Open both mono and stereo test files in 32 kHz. |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 124 | const std::string file_name_stereo = |
| 125 | webrtc::test::ResourcePath("audio_coding/teststereo32kHz", "pcm"); |
| 126 | const std::string file_name_mono = |
| 127 | webrtc::test::ResourcePath("audio_coding/testfile32kHz", "pcm"); |
tina.legrand@webrtc.org | 4517585 | 2012-06-01 09:27:35 +0000 | [diff] [blame] | 128 | frequency_hz = 32000; |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 129 | in_file_stereo_ = new PCMFile(); |
| 130 | in_file_mono_ = new PCMFile(); |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 131 | in_file_stereo_->Open(file_name_stereo, frequency_hz, "rb"); |
| 132 | in_file_stereo_->ReadStereo(true); |
| 133 | in_file_mono_->Open(file_name_mono, frequency_hz, "rb"); |
| 134 | in_file_mono_->ReadStereo(false); |
| 135 | |
tina.legrand@webrtc.org | 4517585 | 2012-06-01 09:27:35 +0000 | [diff] [blame] | 136 | // Create and initialize two ACMs, one for each side of a one-to-one call. |
andrew@webrtc.org | 89df092 | 2013-09-12 01:27:43 +0000 | [diff] [blame] | 137 | ASSERT_TRUE((acm_a_.get() != NULL) && (acm_b_.get() != NULL)); |
tina.legrand@webrtc.org | 3ddc974 | 2012-06-27 09:25:50 +0000 | [diff] [blame] | 138 | EXPECT_EQ(0, acm_a_->InitializeReceiver()); |
| 139 | EXPECT_EQ(0, acm_b_->InitializeReceiver()); |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 140 | |
Fredrik Solenberg | 657b296 | 2018-12-05 10:30:25 +0100 | [diff] [blame] | 141 | acm_b_->SetReceiveCodecs({{103, {"ISAC", 16000, 1}}, |
| 142 | {104, {"ISAC", 32000, 1}}, |
| 143 | {107, {"L16", 8000, 1}}, |
| 144 | {108, {"L16", 16000, 1}}, |
| 145 | {109, {"L16", 32000, 1}}, |
| 146 | {111, {"L16", 8000, 2}}, |
| 147 | {112, {"L16", 16000, 2}}, |
| 148 | {113, {"L16", 32000, 2}}, |
| 149 | {0, {"PCMU", 8000, 1}}, |
| 150 | {110, {"PCMU", 8000, 2}}, |
| 151 | {8, {"PCMA", 8000, 1}}, |
| 152 | {118, {"PCMA", 8000, 2}}, |
| 153 | {102, {"ILBC", 8000, 1}}, |
| 154 | {9, {"G722", 8000, 1}}, |
| 155 | {119, {"G722", 8000, 2}}, |
| 156 | {120, {"OPUS", 48000, 2, {{"stereo", "1"}}}}, |
| 157 | {13, {"CN", 8000, 1}}, |
| 158 | {98, {"CN", 16000, 1}}, |
| 159 | {99, {"CN", 32000, 1}}}); |
tina.legrand@webrtc.org | ae1c454 | 2012-03-12 08:41:30 +0000 | [diff] [blame] | 160 | |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 161 | // Create and connect the channel. |
| 162 | channel_a2b_ = new TestPackStereo; |
tina.legrand@webrtc.org | 3ddc974 | 2012-06-27 09:25:50 +0000 | [diff] [blame] | 163 | EXPECT_EQ(0, acm_a_->RegisterTransportCallback(channel_a2b_)); |
andrew@webrtc.org | 89df092 | 2013-09-12 01:27:43 +0000 | [diff] [blame] | 164 | channel_a2b_->RegisterReceiverACM(acm_b_.get()); |
tina.legrand@webrtc.org | df69775 | 2012-02-08 10:22:21 +0000 | [diff] [blame] | 165 | |
tina.legrand@webrtc.org | 3ddc974 | 2012-06-27 09:25:50 +0000 | [diff] [blame] | 166 | char codec_pcma_temp[] = "PCMA"; |
Karl Wiberg | 36b37dc | 2018-09-24 10:52:32 +0200 | [diff] [blame] | 167 | RegisterSendCodec('A', codec_pcma_temp, 8000, 64000, 80, 2); |
tina.legrand@webrtc.org | 3ddc974 | 2012-06-27 09:25:50 +0000 | [diff] [blame] | 168 | |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 169 | // |
| 170 | // Test Stereo-To-Stereo for all codecs. |
| 171 | // |
| 172 | audio_channels = 2; |
| 173 | codec_channels = 2; |
tina.legrand@webrtc.org | 6b6ff55 | 2012-01-11 10:12:54 +0000 | [diff] [blame] | 174 | |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 175 | // All codecs are tested for all allowed sampling frequencies, rates and |
| 176 | // packet sizes. |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 177 | channel_a2b_->set_codec_mode(kStereo); |
| 178 | test_cntr_++; |
| 179 | OpenOutFile(test_cntr_); |
| 180 | char codec_g722[] = "G722"; |
Karl Wiberg | 36b37dc | 2018-09-24 10:52:32 +0200 | [diff] [blame] | 181 | RegisterSendCodec('A', codec_g722, 16000, 64000, 160, codec_channels); |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 182 | Run(channel_a2b_, audio_channels, codec_channels); |
Karl Wiberg | 36b37dc | 2018-09-24 10:52:32 +0200 | [diff] [blame] | 183 | RegisterSendCodec('A', codec_g722, 16000, 64000, 320, codec_channels); |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 184 | Run(channel_a2b_, audio_channels, codec_channels); |
Karl Wiberg | 36b37dc | 2018-09-24 10:52:32 +0200 | [diff] [blame] | 185 | RegisterSendCodec('A', codec_g722, 16000, 64000, 480, codec_channels); |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 186 | Run(channel_a2b_, audio_channels, codec_channels); |
Karl Wiberg | 36b37dc | 2018-09-24 10:52:32 +0200 | [diff] [blame] | 187 | RegisterSendCodec('A', codec_g722, 16000, 64000, 640, codec_channels); |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 188 | Run(channel_a2b_, audio_channels, codec_channels); |
Karl Wiberg | 36b37dc | 2018-09-24 10:52:32 +0200 | [diff] [blame] | 189 | RegisterSendCodec('A', codec_g722, 16000, 64000, 800, codec_channels); |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 190 | Run(channel_a2b_, audio_channels, codec_channels); |
Karl Wiberg | 36b37dc | 2018-09-24 10:52:32 +0200 | [diff] [blame] | 191 | RegisterSendCodec('A', codec_g722, 16000, 64000, 960, codec_channels); |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 192 | Run(channel_a2b_, audio_channels, codec_channels); |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 193 | out_file_.Close(); |
Karl Wiberg | eb254b4 | 2017-11-01 15:08:12 +0100 | [diff] [blame] | 194 | |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 195 | channel_a2b_->set_codec_mode(kStereo); |
| 196 | test_cntr_++; |
| 197 | OpenOutFile(test_cntr_); |
| 198 | char codec_l16[] = "L16"; |
Karl Wiberg | 36b37dc | 2018-09-24 10:52:32 +0200 | [diff] [blame] | 199 | RegisterSendCodec('A', codec_l16, 8000, 128000, 80, codec_channels); |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 200 | Run(channel_a2b_, audio_channels, codec_channels); |
Karl Wiberg | 36b37dc | 2018-09-24 10:52:32 +0200 | [diff] [blame] | 201 | RegisterSendCodec('A', codec_l16, 8000, 128000, 160, codec_channels); |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 202 | Run(channel_a2b_, audio_channels, codec_channels); |
Karl Wiberg | 36b37dc | 2018-09-24 10:52:32 +0200 | [diff] [blame] | 203 | RegisterSendCodec('A', codec_l16, 8000, 128000, 240, codec_channels); |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 204 | Run(channel_a2b_, audio_channels, codec_channels); |
Karl Wiberg | 36b37dc | 2018-09-24 10:52:32 +0200 | [diff] [blame] | 205 | RegisterSendCodec('A', codec_l16, 8000, 128000, 320, codec_channels); |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 206 | Run(channel_a2b_, audio_channels, codec_channels); |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 207 | out_file_.Close(); |
tina.legrand@webrtc.org | 6b6ff55 | 2012-01-11 10:12:54 +0000 | [diff] [blame] | 208 | |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 209 | test_cntr_++; |
| 210 | OpenOutFile(test_cntr_); |
Karl Wiberg | 36b37dc | 2018-09-24 10:52:32 +0200 | [diff] [blame] | 211 | RegisterSendCodec('A', codec_l16, 16000, 256000, 160, codec_channels); |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 212 | Run(channel_a2b_, audio_channels, codec_channels); |
Karl Wiberg | 36b37dc | 2018-09-24 10:52:32 +0200 | [diff] [blame] | 213 | RegisterSendCodec('A', codec_l16, 16000, 256000, 320, codec_channels); |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 214 | Run(channel_a2b_, audio_channels, codec_channels); |
Karl Wiberg | 36b37dc | 2018-09-24 10:52:32 +0200 | [diff] [blame] | 215 | RegisterSendCodec('A', codec_l16, 16000, 256000, 480, codec_channels); |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 216 | Run(channel_a2b_, audio_channels, codec_channels); |
Karl Wiberg | 36b37dc | 2018-09-24 10:52:32 +0200 | [diff] [blame] | 217 | RegisterSendCodec('A', codec_l16, 16000, 256000, 640, codec_channels); |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 218 | Run(channel_a2b_, audio_channels, codec_channels); |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 219 | out_file_.Close(); |
tina.legrand@webrtc.org | 6b6ff55 | 2012-01-11 10:12:54 +0000 | [diff] [blame] | 220 | |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 221 | test_cntr_++; |
| 222 | OpenOutFile(test_cntr_); |
Karl Wiberg | 36b37dc | 2018-09-24 10:52:32 +0200 | [diff] [blame] | 223 | RegisterSendCodec('A', codec_l16, 32000, 512000, 320, codec_channels); |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 224 | Run(channel_a2b_, audio_channels, codec_channels); |
Karl Wiberg | 36b37dc | 2018-09-24 10:52:32 +0200 | [diff] [blame] | 225 | RegisterSendCodec('A', codec_l16, 32000, 512000, 640, codec_channels); |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 226 | Run(channel_a2b_, audio_channels, codec_channels); |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 227 | out_file_.Close(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 228 | #ifdef PCMA_AND_PCMU |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 229 | channel_a2b_->set_codec_mode(kStereo); |
| 230 | audio_channels = 2; |
| 231 | codec_channels = 2; |
| 232 | test_cntr_++; |
| 233 | OpenOutFile(test_cntr_); |
| 234 | char codec_pcma[] = "PCMA"; |
Karl Wiberg | 36b37dc | 2018-09-24 10:52:32 +0200 | [diff] [blame] | 235 | RegisterSendCodec('A', codec_pcma, 8000, 64000, 80, codec_channels); |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 236 | Run(channel_a2b_, audio_channels, codec_channels); |
Karl Wiberg | 36b37dc | 2018-09-24 10:52:32 +0200 | [diff] [blame] | 237 | RegisterSendCodec('A', codec_pcma, 8000, 64000, 160, codec_channels); |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 238 | Run(channel_a2b_, audio_channels, codec_channels); |
Karl Wiberg | 36b37dc | 2018-09-24 10:52:32 +0200 | [diff] [blame] | 239 | RegisterSendCodec('A', codec_pcma, 8000, 64000, 240, codec_channels); |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 240 | Run(channel_a2b_, audio_channels, codec_channels); |
Karl Wiberg | 36b37dc | 2018-09-24 10:52:32 +0200 | [diff] [blame] | 241 | RegisterSendCodec('A', codec_pcma, 8000, 64000, 320, codec_channels); |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 242 | Run(channel_a2b_, audio_channels, codec_channels); |
Karl Wiberg | 36b37dc | 2018-09-24 10:52:32 +0200 | [diff] [blame] | 243 | RegisterSendCodec('A', codec_pcma, 8000, 64000, 400, codec_channels); |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 244 | Run(channel_a2b_, audio_channels, codec_channels); |
Karl Wiberg | 36b37dc | 2018-09-24 10:52:32 +0200 | [diff] [blame] | 245 | RegisterSendCodec('A', codec_pcma, 8000, 64000, 480, codec_channels); |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 246 | Run(channel_a2b_, audio_channels, codec_channels); |
Fredrik Solenberg | ec0f45b | 2018-12-03 15:50:44 +0000 | [diff] [blame] | 247 | out_file_.Close(); |
Fredrik Solenberg | 657b296 | 2018-12-05 10:30:25 +0100 | [diff] [blame] | 248 | |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 249 | test_cntr_++; |
| 250 | OpenOutFile(test_cntr_); |
| 251 | char codec_pcmu[] = "PCMU"; |
Karl Wiberg | 36b37dc | 2018-09-24 10:52:32 +0200 | [diff] [blame] | 252 | RegisterSendCodec('A', codec_pcmu, 8000, 64000, 80, codec_channels); |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 253 | Run(channel_a2b_, audio_channels, codec_channels); |
Karl Wiberg | 36b37dc | 2018-09-24 10:52:32 +0200 | [diff] [blame] | 254 | RegisterSendCodec('A', codec_pcmu, 8000, 64000, 160, codec_channels); |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 255 | Run(channel_a2b_, audio_channels, codec_channels); |
Karl Wiberg | 36b37dc | 2018-09-24 10:52:32 +0200 | [diff] [blame] | 256 | RegisterSendCodec('A', codec_pcmu, 8000, 64000, 240, codec_channels); |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 257 | Run(channel_a2b_, audio_channels, codec_channels); |
Karl Wiberg | 36b37dc | 2018-09-24 10:52:32 +0200 | [diff] [blame] | 258 | RegisterSendCodec('A', codec_pcmu, 8000, 64000, 320, codec_channels); |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 259 | Run(channel_a2b_, audio_channels, codec_channels); |
Karl Wiberg | 36b37dc | 2018-09-24 10:52:32 +0200 | [diff] [blame] | 260 | RegisterSendCodec('A', codec_pcmu, 8000, 64000, 400, codec_channels); |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 261 | Run(channel_a2b_, audio_channels, codec_channels); |
Karl Wiberg | 36b37dc | 2018-09-24 10:52:32 +0200 | [diff] [blame] | 262 | RegisterSendCodec('A', codec_pcmu, 8000, 64000, 480, codec_channels); |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 263 | Run(channel_a2b_, audio_channels, codec_channels); |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 264 | out_file_.Close(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 265 | #endif |
tina.legrand@webrtc.org | 0ad3c1a | 2012-11-07 08:07:29 +0000 | [diff] [blame] | 266 | #ifdef WEBRTC_CODEC_OPUS |
tina.legrand@webrtc.org | 0ad3c1a | 2012-11-07 08:07:29 +0000 | [diff] [blame] | 267 | channel_a2b_->set_codec_mode(kStereo); |
| 268 | audio_channels = 2; |
| 269 | codec_channels = 2; |
| 270 | test_cntr_++; |
| 271 | OpenOutFile(test_cntr_); |
tina.legrand@webrtc.org | 46d90dc | 2013-02-01 14:20:06 +0000 | [diff] [blame] | 272 | |
tina.legrand@webrtc.org | 0ad3c1a | 2012-11-07 08:07:29 +0000 | [diff] [blame] | 273 | char codec_opus[] = "opus"; |
tina.legrand@webrtc.org | 46d90dc | 2013-02-01 14:20:06 +0000 | [diff] [blame] | 274 | // Run Opus with 10 ms frame size. |
Karl Wiberg | 36b37dc | 2018-09-24 10:52:32 +0200 | [diff] [blame] | 275 | RegisterSendCodec('A', codec_opus, 48000, 64000, 480, codec_channels); |
tina.legrand@webrtc.org | 0ad3c1a | 2012-11-07 08:07:29 +0000 | [diff] [blame] | 276 | Run(channel_a2b_, audio_channels, codec_channels); |
tina.legrand@webrtc.org | 46d90dc | 2013-02-01 14:20:06 +0000 | [diff] [blame] | 277 | // Run Opus with 20 ms frame size. |
Karl Wiberg | 36b37dc | 2018-09-24 10:52:32 +0200 | [diff] [blame] | 278 | RegisterSendCodec('A', codec_opus, 48000, 64000, 480 * 2, codec_channels); |
tina.legrand@webrtc.org | 46d90dc | 2013-02-01 14:20:06 +0000 | [diff] [blame] | 279 | Run(channel_a2b_, audio_channels, codec_channels); |
| 280 | // Run Opus with 40 ms frame size. |
Karl Wiberg | 36b37dc | 2018-09-24 10:52:32 +0200 | [diff] [blame] | 281 | RegisterSendCodec('A', codec_opus, 48000, 64000, 480 * 4, codec_channels); |
tina.legrand@webrtc.org | 46d90dc | 2013-02-01 14:20:06 +0000 | [diff] [blame] | 282 | Run(channel_a2b_, audio_channels, codec_channels); |
| 283 | // Run Opus with 60 ms frame size. |
Karl Wiberg | 36b37dc | 2018-09-24 10:52:32 +0200 | [diff] [blame] | 284 | RegisterSendCodec('A', codec_opus, 48000, 64000, 480 * 6, codec_channels); |
tina.legrand@webrtc.org | 46d90dc | 2013-02-01 14:20:06 +0000 | [diff] [blame] | 285 | Run(channel_a2b_, audio_channels, codec_channels); |
| 286 | // Run Opus with 20 ms frame size and different bitrates. |
Karl Wiberg | 36b37dc | 2018-09-24 10:52:32 +0200 | [diff] [blame] | 287 | RegisterSendCodec('A', codec_opus, 48000, 40000, 960, codec_channels); |
tina.legrand@webrtc.org | 0ad3c1a | 2012-11-07 08:07:29 +0000 | [diff] [blame] | 288 | Run(channel_a2b_, audio_channels, codec_channels); |
Karl Wiberg | 36b37dc | 2018-09-24 10:52:32 +0200 | [diff] [blame] | 289 | RegisterSendCodec('A', codec_opus, 48000, 510000, 960, codec_channels); |
tina.legrand@webrtc.org | 0ad3c1a | 2012-11-07 08:07:29 +0000 | [diff] [blame] | 290 | Run(channel_a2b_, audio_channels, codec_channels); |
| 291 | out_file_.Close(); |
| 292 | #endif |
tina.legrand@webrtc.org | 6b6ff55 | 2012-01-11 10:12:54 +0000 | [diff] [blame] | 293 | // |
| 294 | // Test Mono-To-Stereo for all codecs. |
| 295 | // |
| 296 | audio_channels = 1; |
| 297 | codec_channels = 2; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 298 | |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 299 | test_cntr_++; |
| 300 | channel_a2b_->set_codec_mode(kStereo); |
| 301 | OpenOutFile(test_cntr_); |
Karl Wiberg | 36b37dc | 2018-09-24 10:52:32 +0200 | [diff] [blame] | 302 | RegisterSendCodec('A', codec_g722, 16000, 64000, 160, codec_channels); |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 303 | Run(channel_a2b_, audio_channels, codec_channels); |
| 304 | out_file_.Close(); |
Karl Wiberg | eb254b4 | 2017-11-01 15:08:12 +0100 | [diff] [blame] | 305 | |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 306 | test_cntr_++; |
| 307 | channel_a2b_->set_codec_mode(kStereo); |
| 308 | OpenOutFile(test_cntr_); |
Karl Wiberg | 36b37dc | 2018-09-24 10:52:32 +0200 | [diff] [blame] | 309 | RegisterSendCodec('A', codec_l16, 8000, 128000, 80, codec_channels); |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 310 | Run(channel_a2b_, audio_channels, codec_channels); |
| 311 | out_file_.Close(); |
Fredrik Solenberg | 657b296 | 2018-12-05 10:30:25 +0100 | [diff] [blame] | 312 | |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 313 | test_cntr_++; |
| 314 | OpenOutFile(test_cntr_); |
Karl Wiberg | 36b37dc | 2018-09-24 10:52:32 +0200 | [diff] [blame] | 315 | RegisterSendCodec('A', codec_l16, 16000, 256000, 160, codec_channels); |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 316 | Run(channel_a2b_, audio_channels, codec_channels); |
| 317 | out_file_.Close(); |
Fredrik Solenberg | 657b296 | 2018-12-05 10:30:25 +0100 | [diff] [blame] | 318 | |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 319 | test_cntr_++; |
| 320 | OpenOutFile(test_cntr_); |
Karl Wiberg | 36b37dc | 2018-09-24 10:52:32 +0200 | [diff] [blame] | 321 | RegisterSendCodec('A', codec_l16, 32000, 512000, 320, codec_channels); |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 322 | Run(channel_a2b_, audio_channels, codec_channels); |
| 323 | out_file_.Close(); |
tina.legrand@webrtc.org | 6b6ff55 | 2012-01-11 10:12:54 +0000 | [diff] [blame] | 324 | #ifdef PCMA_AND_PCMU |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 325 | test_cntr_++; |
| 326 | channel_a2b_->set_codec_mode(kStereo); |
| 327 | OpenOutFile(test_cntr_); |
Karl Wiberg | 36b37dc | 2018-09-24 10:52:32 +0200 | [diff] [blame] | 328 | RegisterSendCodec('A', codec_pcmu, 8000, 64000, 80, codec_channels); |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 329 | Run(channel_a2b_, audio_channels, codec_channels); |
Karl Wiberg | 36b37dc | 2018-09-24 10:52:32 +0200 | [diff] [blame] | 330 | RegisterSendCodec('A', codec_pcma, 8000, 64000, 80, codec_channels); |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 331 | Run(channel_a2b_, audio_channels, codec_channels); |
| 332 | out_file_.Close(); |
tina.legrand@webrtc.org | 6b6ff55 | 2012-01-11 10:12:54 +0000 | [diff] [blame] | 333 | #endif |
tina.legrand@webrtc.org | 0ad3c1a | 2012-11-07 08:07:29 +0000 | [diff] [blame] | 334 | #ifdef WEBRTC_CODEC_OPUS |
tina.legrand@webrtc.org | c459058 | 2012-11-28 12:23:29 +0000 | [diff] [blame] | 335 | // Keep encode and decode in stereo. |
tina.legrand@webrtc.org | 0ad3c1a | 2012-11-07 08:07:29 +0000 | [diff] [blame] | 336 | test_cntr_++; |
| 337 | channel_a2b_->set_codec_mode(kStereo); |
| 338 | OpenOutFile(test_cntr_); |
Karl Wiberg | 36b37dc | 2018-09-24 10:52:32 +0200 | [diff] [blame] | 339 | RegisterSendCodec('A', codec_opus, 48000, 64000, 960, codec_channels); |
tina.legrand@webrtc.org | 0ad3c1a | 2012-11-07 08:07:29 +0000 | [diff] [blame] | 340 | Run(channel_a2b_, audio_channels, codec_channels); |
tina.legrand@webrtc.org | c459058 | 2012-11-28 12:23:29 +0000 | [diff] [blame] | 341 | |
| 342 | // Encode in mono, decode in stereo mode. |
Karl Wiberg | 36b37dc | 2018-09-24 10:52:32 +0200 | [diff] [blame] | 343 | RegisterSendCodec('A', codec_opus, 48000, 64000, 960, 1); |
tina.legrand@webrtc.org | c459058 | 2012-11-28 12:23:29 +0000 | [diff] [blame] | 344 | Run(channel_a2b_, audio_channels, codec_channels); |
tina.legrand@webrtc.org | 0ad3c1a | 2012-11-07 08:07:29 +0000 | [diff] [blame] | 345 | out_file_.Close(); |
| 346 | #endif |
tina.legrand@webrtc.org | 6b6ff55 | 2012-01-11 10:12:54 +0000 | [diff] [blame] | 347 | |
| 348 | // |
| 349 | // Test Stereo-To-Mono for all codecs. |
| 350 | // |
| 351 | audio_channels = 2; |
| 352 | codec_channels = 1; |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 353 | channel_a2b_->set_codec_mode(kMono); |
tina.legrand@webrtc.org | 6b6ff55 | 2012-01-11 10:12:54 +0000 | [diff] [blame] | 354 | |
tina.legrand@webrtc.org | 6b6ff55 | 2012-01-11 10:12:54 +0000 | [diff] [blame] | 355 | // Run stereo audio and mono codec. |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 356 | test_cntr_++; |
| 357 | OpenOutFile(test_cntr_); |
Karl Wiberg | 36b37dc | 2018-09-24 10:52:32 +0200 | [diff] [blame] | 358 | RegisterSendCodec('A', codec_g722, 16000, 64000, 160, codec_channels); |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 359 | Run(channel_a2b_, audio_channels, codec_channels); |
| 360 | out_file_.Close(); |
Karl Wiberg | eb254b4 | 2017-11-01 15:08:12 +0100 | [diff] [blame] | 361 | |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 362 | test_cntr_++; |
| 363 | OpenOutFile(test_cntr_); |
Karl Wiberg | 36b37dc | 2018-09-24 10:52:32 +0200 | [diff] [blame] | 364 | RegisterSendCodec('A', codec_l16, 8000, 128000, 80, codec_channels); |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 365 | Run(channel_a2b_, audio_channels, codec_channels); |
| 366 | out_file_.Close(); |
Fredrik Solenberg | 657b296 | 2018-12-05 10:30:25 +0100 | [diff] [blame] | 367 | |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 368 | test_cntr_++; |
| 369 | OpenOutFile(test_cntr_); |
Karl Wiberg | 36b37dc | 2018-09-24 10:52:32 +0200 | [diff] [blame] | 370 | RegisterSendCodec('A', codec_l16, 16000, 256000, 160, codec_channels); |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 371 | Run(channel_a2b_, audio_channels, codec_channels); |
| 372 | out_file_.Close(); |
Fredrik Solenberg | 657b296 | 2018-12-05 10:30:25 +0100 | [diff] [blame] | 373 | |
tina.legrand@webrtc.org | a092cbf | 2013-02-14 09:28:10 +0000 | [diff] [blame] | 374 | test_cntr_++; |
| 375 | OpenOutFile(test_cntr_); |
Karl Wiberg | 36b37dc | 2018-09-24 10:52:32 +0200 | [diff] [blame] | 376 | RegisterSendCodec('A', codec_l16, 32000, 512000, 320, codec_channels); |
tina.legrand@webrtc.org | a092cbf | 2013-02-14 09:28:10 +0000 | [diff] [blame] | 377 | Run(channel_a2b_, audio_channels, codec_channels); |
| 378 | out_file_.Close(); |
tina.legrand@webrtc.org | 6b6ff55 | 2012-01-11 10:12:54 +0000 | [diff] [blame] | 379 | #ifdef PCMA_AND_PCMU |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 380 | test_cntr_++; |
| 381 | OpenOutFile(test_cntr_); |
Karl Wiberg | 36b37dc | 2018-09-24 10:52:32 +0200 | [diff] [blame] | 382 | RegisterSendCodec('A', codec_pcmu, 8000, 64000, 80, codec_channels); |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 383 | Run(channel_a2b_, audio_channels, codec_channels); |
Karl Wiberg | 36b37dc | 2018-09-24 10:52:32 +0200 | [diff] [blame] | 384 | RegisterSendCodec('A', codec_pcma, 8000, 64000, 80, codec_channels); |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 385 | Run(channel_a2b_, audio_channels, codec_channels); |
| 386 | out_file_.Close(); |
tina.legrand@webrtc.org | 6b6ff55 | 2012-01-11 10:12:54 +0000 | [diff] [blame] | 387 | #endif |
tina.legrand@webrtc.org | 0ad3c1a | 2012-11-07 08:07:29 +0000 | [diff] [blame] | 388 | #ifdef WEBRTC_CODEC_OPUS |
tina.legrand@webrtc.org | 0ad3c1a | 2012-11-07 08:07:29 +0000 | [diff] [blame] | 389 | test_cntr_++; |
| 390 | OpenOutFile(test_cntr_); |
tina.legrand@webrtc.org | c459058 | 2012-11-28 12:23:29 +0000 | [diff] [blame] | 391 | // Encode and decode in mono. |
Karl Wiberg | 36b37dc | 2018-09-24 10:52:32 +0200 | [diff] [blame] | 392 | RegisterSendCodec('A', codec_opus, 48000, 32000, 960, codec_channels); |
Fredrik Solenberg | 657b296 | 2018-12-05 10:30:25 +0100 | [diff] [blame] | 393 | acm_b_->SetReceiveCodecs({{120, {"OPUS", 48000, 2}}}); |
tina.legrand@webrtc.org | c459058 | 2012-11-28 12:23:29 +0000 | [diff] [blame] | 394 | Run(channel_a2b_, audio_channels, codec_channels); |
| 395 | |
| 396 | // Encode in stereo, decode in mono. |
Karl Wiberg | 36b37dc | 2018-09-24 10:52:32 +0200 | [diff] [blame] | 397 | RegisterSendCodec('A', codec_opus, 48000, 32000, 960, 2); |
tina.legrand@webrtc.org | c459058 | 2012-11-28 12:23:29 +0000 | [diff] [blame] | 398 | Run(channel_a2b_, audio_channels, codec_channels); |
| 399 | |
| 400 | out_file_.Close(); |
| 401 | |
| 402 | // Test switching between decoding mono and stereo for Opus. |
| 403 | |
| 404 | // Decode in mono. |
| 405 | test_cntr_++; |
| 406 | OpenOutFile(test_cntr_); |
tina.legrand@webrtc.org | 0ad3c1a | 2012-11-07 08:07:29 +0000 | [diff] [blame] | 407 | Run(channel_a2b_, audio_channels, codec_channels); |
| 408 | out_file_.Close(); |
tina.legrand@webrtc.org | c459058 | 2012-11-28 12:23:29 +0000 | [diff] [blame] | 409 | // Decode in stereo. |
| 410 | test_cntr_++; |
| 411 | OpenOutFile(test_cntr_); |
Fredrik Solenberg | 657b296 | 2018-12-05 10:30:25 +0100 | [diff] [blame] | 412 | acm_b_->SetReceiveCodecs({{120, {"OPUS", 48000, 2, {{"stereo", "1"}}}}}); |
tina.legrand@webrtc.org | c459058 | 2012-11-28 12:23:29 +0000 | [diff] [blame] | 413 | Run(channel_a2b_, audio_channels, 2); |
| 414 | out_file_.Close(); |
| 415 | // Decode in mono. |
| 416 | test_cntr_++; |
| 417 | OpenOutFile(test_cntr_); |
Fredrik Solenberg | 657b296 | 2018-12-05 10:30:25 +0100 | [diff] [blame] | 418 | acm_b_->SetReceiveCodecs({{120, {"OPUS", 48000, 2}}}); |
tina.legrand@webrtc.org | c459058 | 2012-11-28 12:23:29 +0000 | [diff] [blame] | 419 | Run(channel_a2b_, audio_channels, codec_channels); |
| 420 | out_file_.Close(); |
tina.legrand@webrtc.org | 0ad3c1a | 2012-11-07 08:07:29 +0000 | [diff] [blame] | 421 | #endif |
tina.legrand@webrtc.org | 6b6ff55 | 2012-01-11 10:12:54 +0000 | [diff] [blame] | 422 | |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 423 | // Delete the file pointers. |
| 424 | delete in_file_stereo_; |
| 425 | delete in_file_mono_; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 426 | } |
| 427 | |
| 428 | // Register Codec to use in the test |
| 429 | // |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 430 | // Input: side - which ACM to use, 'A' or 'B' |
| 431 | // codec_name - name to use when register the codec |
| 432 | // sampling_freq_hz - sampling frequency in Herz |
| 433 | // rate - bitrate in bytes |
| 434 | // pack_size - packet size in samples |
| 435 | // channels - number of channels; 1 for mono, 2 for stereo |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 436 | void TestStereo::RegisterSendCodec(char side, |
| 437 | char* codec_name, |
| 438 | int32_t sampling_freq_hz, |
| 439 | int rate, |
| 440 | int pack_size, |
Karl Wiberg | 36b37dc | 2018-09-24 10:52:32 +0200 | [diff] [blame] | 441 | int channels) { |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 442 | // Store packet size in samples, used to validate the received packet |
| 443 | pack_size_samp_ = pack_size; |
| 444 | |
| 445 | // Store the expected packet size in bytes, used to validate the received |
| 446 | // packet. Add 0.875 to always round up to a whole byte. |
pbos@webrtc.org | d8ca723 | 2014-12-10 11:49:13 +0000 | [diff] [blame] | 447 | pack_size_bytes_ = (uint16_t)(static_cast<float>(pack_size * rate) / |
| 448 | static_cast<float>(sampling_freq_hz * 8) + |
| 449 | 0.875); |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 450 | |
| 451 | // Set pointer to the ACM where to register the codec |
tina.legrand@webrtc.org | 3ddc974 | 2012-06-27 09:25:50 +0000 | [diff] [blame] | 452 | AudioCodingModule* my_acm = NULL; |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 453 | switch (side) { |
| 454 | case 'A': { |
andrew@webrtc.org | 89df092 | 2013-09-12 01:27:43 +0000 | [diff] [blame] | 455 | my_acm = acm_a_.get(); |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 456 | break; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 457 | } |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 458 | case 'B': { |
andrew@webrtc.org | 89df092 | 2013-09-12 01:27:43 +0000 | [diff] [blame] | 459 | my_acm = acm_b_.get(); |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 460 | break; |
tina.legrand@webrtc.org | 16b6b90 | 2012-04-12 11:02:38 +0000 | [diff] [blame] | 461 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 462 | default: |
tina.legrand@webrtc.org | 3ddc974 | 2012-06-27 09:25:50 +0000 | [diff] [blame] | 463 | break; |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 464 | } |
tina.legrand@webrtc.org | 3ddc974 | 2012-06-27 09:25:50 +0000 | [diff] [blame] | 465 | ASSERT_TRUE(my_acm != NULL); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 466 | |
Karl Wiberg | d363db1 | 2018-09-24 14:45:24 +0200 | [diff] [blame] | 467 | auto encoder_factory = CreateBuiltinAudioEncoderFactory(); |
Niels Möller | 2edab4c | 2018-10-22 09:48:08 +0200 | [diff] [blame] | 468 | const int clockrate_hz = absl::EqualsIgnoreCase(codec_name, "g722") |
Karl Wiberg | d363db1 | 2018-09-24 14:45:24 +0200 | [diff] [blame] | 469 | ? sampling_freq_hz / 2 |
| 470 | : sampling_freq_hz; |
| 471 | const std::string ptime = rtc::ToString(rtc::CheckedDivExact( |
| 472 | pack_size, rtc::CheckedDivExact(sampling_freq_hz, 1000))); |
| 473 | SdpAudioFormat::Parameters params = {{"ptime", ptime}}; |
| 474 | RTC_CHECK(channels == 1 || channels == 2); |
Niels Möller | 2edab4c | 2018-10-22 09:48:08 +0200 | [diff] [blame] | 475 | if (absl::EqualsIgnoreCase(codec_name, "opus")) { |
Karl Wiberg | d363db1 | 2018-09-24 14:45:24 +0200 | [diff] [blame] | 476 | if (channels == 2) { |
| 477 | params["stereo"] = "1"; |
| 478 | } |
| 479 | channels = 2; |
| 480 | params["maxaveragebitrate"] = rtc::ToString(rate); |
| 481 | } |
| 482 | constexpr int payload_type = 17; |
| 483 | auto encoder = encoder_factory->MakeAudioEncoder( |
| 484 | payload_type, SdpAudioFormat(codec_name, clockrate_hz, channels, params), |
| 485 | absl::nullopt); |
| 486 | EXPECT_NE(nullptr, encoder); |
| 487 | my_acm->SetEncoder(std::move(encoder)); |
tina.legrand@webrtc.org | 0ad3c1a | 2012-11-07 08:07:29 +0000 | [diff] [blame] | 488 | |
| 489 | send_codec_name_ = codec_name; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 490 | } |
| 491 | |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 492 | void TestStereo::Run(TestPackStereo* channel, |
| 493 | int in_channels, |
| 494 | int out_channels, |
tina.legrand@webrtc.org | 16b6b90 | 2012-04-12 11:02:38 +0000 | [diff] [blame] | 495 | int percent_loss) { |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 496 | AudioFrame audio_frame; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 497 | |
pbos@webrtc.org | 0946a56 | 2013-04-09 00:28:06 +0000 | [diff] [blame] | 498 | int32_t out_freq_hz_b = out_file_.SamplingFrequency(); |
| 499 | uint16_t rec_size; |
| 500 | uint32_t time_stamp_diff; |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 501 | channel->reset_payload_size(); |
| 502 | int error_count = 0; |
tina.legrand@webrtc.org | 65d61c3 | 2014-06-05 13:42:51 +0000 | [diff] [blame] | 503 | int variable_bytes = 0; |
| 504 | int variable_packets = 0; |
Henrik Lundin | 4d68208 | 2015-12-10 16:24:39 +0100 | [diff] [blame] | 505 | // Set test length to 500 ms (50 blocks of 10 ms each). |
| 506 | in_file_mono_->SetNum10MsBlocksToRead(50); |
| 507 | in_file_stereo_->SetNum10MsBlocksToRead(50); |
| 508 | // Fast-forward 1 second (100 blocks) since the files start with silence. |
| 509 | in_file_stereo_->FastForward(100); |
| 510 | in_file_mono_->FastForward(100); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 511 | |
andresp@webrtc.org | d0b436a | 2014-01-13 13:15:59 +0000 | [diff] [blame] | 512 | while (1) { |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 513 | // Simulate packet loss by setting |packet_loss_| to "true" in |
| 514 | // |percent_loss| percent of the loops. |
| 515 | if (percent_loss > 0) { |
| 516 | if (counter_ == floor((100 / percent_loss) + 0.5)) { |
| 517 | counter_ = 0; |
| 518 | channel->set_lost_packet(true); |
| 519 | } else { |
| 520 | channel->set_lost_packet(false); |
| 521 | } |
| 522 | counter_++; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 523 | } |
| 524 | |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 525 | // Add 10 msec to ACM |
| 526 | if (in_channels == 1) { |
| 527 | if (in_file_mono_->EndOfFile()) { |
| 528 | break; |
| 529 | } |
| 530 | in_file_mono_->Read10MsData(audio_frame); |
| 531 | } else { |
| 532 | if (in_file_stereo_->EndOfFile()) { |
| 533 | break; |
| 534 | } |
| 535 | in_file_stereo_->Read10MsData(audio_frame); |
| 536 | } |
henrik.lundin@webrtc.org | f56c162 | 2015-03-02 12:29:30 +0000 | [diff] [blame] | 537 | EXPECT_GE(acm_a_->Add10MsData(audio_frame), 0); |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 538 | |
tina.legrand@webrtc.org | 65d61c3 | 2014-06-05 13:42:51 +0000 | [diff] [blame] | 539 | // Verify that the received packet size matches the settings. |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 540 | rec_size = channel->payload_size(); |
| 541 | if ((0 < rec_size) & (rec_size < 65535)) { |
tina.legrand@webrtc.org | 65d61c3 | 2014-06-05 13:42:51 +0000 | [diff] [blame] | 542 | if (strcmp(send_codec_name_, "opus") == 0) { |
| 543 | // Opus is a variable rate codec, hence calculate the average packet |
| 544 | // size, and later make sure the average is in the right range. |
| 545 | variable_bytes += rec_size; |
| 546 | variable_packets++; |
| 547 | } else { |
| 548 | // For fixed rate codecs, check that packet size is correct. |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 549 | if ((rec_size != pack_size_bytes_ * out_channels) && |
| 550 | (pack_size_bytes_ < 65535)) { |
tina.legrand@webrtc.org | 0ad3c1a | 2012-11-07 08:07:29 +0000 | [diff] [blame] | 551 | error_count++; |
| 552 | } |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 553 | } |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 554 | // Verify that the timestamp is updated with expected length |
| 555 | time_stamp_diff = channel->timestamp_diff(); |
| 556 | if ((counter_ > 10) && (time_stamp_diff != pack_size_samp_)) { |
| 557 | error_count++; |
| 558 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 559 | } |
| 560 | |
Fredrik Solenberg | 657b296 | 2018-12-05 10:30:25 +0100 | [diff] [blame] | 561 | // Run receive side of ACM |
henrik.lundin | d4ccb00 | 2016-05-17 12:21:55 -0700 | [diff] [blame] | 562 | bool muted; |
| 563 | EXPECT_EQ(0, acm_b_->PlayoutData10Ms(out_freq_hz_b, &audio_frame, &muted)); |
| 564 | ASSERT_FALSE(muted); |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 565 | |
| 566 | // Write output speech to file |
| 567 | out_file_.Write10MsData( |
yujo | 36b1a5f | 2017-06-12 12:45:32 -0700 | [diff] [blame] | 568 | audio_frame.data(), |
andrew@webrtc.org | 63a5098 | 2012-05-02 23:56:37 +0000 | [diff] [blame] | 569 | audio_frame.samples_per_channel_ * audio_frame.num_channels_); |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 570 | } |
| 571 | |
tina.legrand@webrtc.org | 3ddc974 | 2012-06-27 09:25:50 +0000 | [diff] [blame] | 572 | EXPECT_EQ(0, error_count); |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 573 | |
tina.legrand@webrtc.org | 65d61c3 | 2014-06-05 13:42:51 +0000 | [diff] [blame] | 574 | // Check that packet size is in the right range for variable rate codecs, |
| 575 | // such as Opus. |
| 576 | if (variable_packets > 0) { |
| 577 | variable_bytes /= variable_packets; |
Henrik Lundin | 4d68208 | 2015-12-10 16:24:39 +0100 | [diff] [blame] | 578 | EXPECT_NEAR(variable_bytes, pack_size_bytes_, 18); |
tina.legrand@webrtc.org | 65d61c3 | 2014-06-05 13:42:51 +0000 | [diff] [blame] | 579 | } |
| 580 | |
andresp@webrtc.org | d0b436a | 2014-01-13 13:15:59 +0000 | [diff] [blame] | 581 | if (in_file_mono_->EndOfFile()) { |
| 582 | in_file_mono_->Rewind(); |
| 583 | } |
| 584 | if (in_file_stereo_->EndOfFile()) { |
| 585 | in_file_stereo_->Rewind(); |
| 586 | } |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 587 | // Reset in case we ended with a lost packet |
| 588 | channel->set_lost_packet(false); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 589 | } |
| 590 | |
pbos@webrtc.org | 0946a56 | 2013-04-09 00:28:06 +0000 | [diff] [blame] | 591 | void TestStereo::OpenOutFile(int16_t test_number) { |
tina.legrand@webrtc.org | ba46804 | 2012-08-17 10:38:28 +0000 | [diff] [blame] | 592 | std::string file_name; |
Jonas Olsson | 366a50c | 2018-09-06 13:41:30 +0200 | [diff] [blame] | 593 | rtc::StringBuilder file_stream; |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 594 | file_stream << webrtc::test::OutputPath() << "teststereo_out_" << test_number |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 595 | << ".pcm"; |
tina.legrand@webrtc.org | ba46804 | 2012-08-17 10:38:28 +0000 | [diff] [blame] | 596 | file_name = file_stream.str(); |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 597 | out_file_.Open(file_name, 32000, "wb"); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 598 | } |
| 599 | |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 600 | } // namespace webrtc |