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 | |
pbos@webrtc.org | 12dc1a3 | 2013-08-05 16:22:53 +0000 | [diff] [blame] | 13 | #include <assert.h> |
| 14 | |
tina.legrand@webrtc.org | a092cbf | 2013-02-14 09:28:10 +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_typedefs.h" |
| 21 | #include "modules/audio_coding/test/utility.h" |
| 22 | #include "test/gtest.h" |
| 23 | #include "test/testsupport/fileutils.h" |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 24 | |
tina.legrand@webrtc.org | 554ae1a | 2011-12-16 10:09:04 +0000 | [diff] [blame] | 25 | namespace webrtc { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 26 | |
| 27 | // Class for simulating packet handling |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 28 | TestPackStereo::TestPackStereo() |
| 29 | : receiver_acm_(NULL), |
| 30 | seq_no_(0), |
| 31 | timestamp_diff_(0), |
| 32 | last_in_timestamp_(0), |
| 33 | total_bytes_(0), |
| 34 | payload_size_(0), |
| 35 | codec_mode_(kNotSet), |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 36 | lost_packet_(false) {} |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 37 | |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 38 | TestPackStereo::~TestPackStereo() {} |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 39 | |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 40 | void TestPackStereo::RegisterReceiverACM(AudioCodingModule* acm) { |
| 41 | receiver_acm_ = acm; |
| 42 | return; |
| 43 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 44 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 45 | int32_t TestPackStereo::SendData(const FrameType frame_type, |
| 46 | const uint8_t payload_type, |
| 47 | const uint32_t timestamp, |
| 48 | const uint8_t* payload_data, |
pkasting@chromium.org | 4591fbd | 2014-11-20 22:28:14 +0000 | [diff] [blame] | 49 | const size_t payload_size, |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 50 | const RTPFragmentationHeader* fragmentation) { |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 51 | WebRtcRTPHeader rtp_info; |
pbos@webrtc.org | 0946a56 | 2013-04-09 00:28:06 +0000 | [diff] [blame] | 52 | int32_t status = 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 53 | |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 54 | rtp_info.header.markerBit = false; |
| 55 | rtp_info.header.ssrc = 0; |
| 56 | rtp_info.header.sequenceNumber = seq_no_++; |
| 57 | rtp_info.header.payloadType = payload_type; |
| 58 | rtp_info.header.timestamp = timestamp; |
pbos | 22993e1 | 2015-10-19 02:39:06 -0700 | [diff] [blame] | 59 | if (frame_type == kEmptyFrame) { |
tina.legrand@webrtc.org | 16b6b90 | 2012-04-12 11:02:38 +0000 | [diff] [blame] | 60 | // Skip this frame |
| 61 | return 0; |
| 62 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 63 | |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 64 | if (lost_packet_ == false) { |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 65 | status = |
| 66 | receiver_acm_->IncomingPacket(payload_data, payload_size, rtp_info); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 67 | |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 68 | if (frame_type != kAudioFrameCN) { |
henrike@webrtc.org | 6ac22e6 | 2014-08-11 21:06:30 +0000 | [diff] [blame] | 69 | payload_size_ = static_cast<int>(payload_size); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 70 | } else { |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 71 | payload_size_ = -1; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 72 | } |
tina.legrand@webrtc.org | 16b6b90 | 2012-04-12 11:02:38 +0000 | [diff] [blame] | 73 | |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 74 | timestamp_diff_ = timestamp - last_in_timestamp_; |
| 75 | last_in_timestamp_ = timestamp; |
| 76 | total_bytes_ += payload_size; |
tina.legrand@webrtc.org | 16b6b90 | 2012-04-12 11:02:38 +0000 | [diff] [blame] | 77 | } |
| 78 | return status; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 79 | } |
| 80 | |
pbos@webrtc.org | 0946a56 | 2013-04-09 00:28:06 +0000 | [diff] [blame] | 81 | uint16_t TestPackStereo::payload_size() { |
henrike@webrtc.org | 6ac22e6 | 2014-08-11 21:06:30 +0000 | [diff] [blame] | 82 | return static_cast<uint16_t>(payload_size_); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 83 | } |
| 84 | |
pbos@webrtc.org | 0946a56 | 2013-04-09 00:28:06 +0000 | [diff] [blame] | 85 | uint32_t TestPackStereo::timestamp_diff() { |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 86 | return timestamp_diff_; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 87 | } |
| 88 | |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 89 | void TestPackStereo::reset_payload_size() { |
| 90 | payload_size_ = 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 91 | } |
| 92 | |
tina.legrand@webrtc.org | 16b6b90 | 2012-04-12 11:02:38 +0000 | [diff] [blame] | 93 | void TestPackStereo::set_codec_mode(enum StereoMonoMode mode) { |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 94 | codec_mode_ = mode; |
tina.legrand@webrtc.org | 16b6b90 | 2012-04-12 11:02:38 +0000 | [diff] [blame] | 95 | } |
| 96 | |
| 97 | void TestPackStereo::set_lost_packet(bool lost) { |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 98 | lost_packet_ = lost; |
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 | TestStereo::TestStereo(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 | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 106 | channel_a2b_(NULL), |
| 107 | test_cntr_(0), |
| 108 | pack_size_samp_(0), |
| 109 | pack_size_bytes_(0), |
Karl Wiberg | eb254b4 | 2017-11-01 15:08:12 +0100 | [diff] [blame] | 110 | counter_(0), |
| 111 | g722_pltype_(0), |
| 112 | l16_8khz_pltype_(-1), |
| 113 | l16_16khz_pltype_(-1), |
| 114 | l16_32khz_pltype_(-1) |
pkasting@chromium.org | 4591fbd | 2014-11-20 22:28:14 +0000 | [diff] [blame] | 115 | #ifdef PCMA_AND_PCMU |
Karl Wiberg | 5817d3d | 2018-04-06 10:06:42 +0200 | [diff] [blame] | 116 | , |
| 117 | pcma_pltype_(-1), |
| 118 | pcmu_pltype_(-1) |
pkasting@chromium.org | 4591fbd | 2014-11-20 22:28:14 +0000 | [diff] [blame] | 119 | #endif |
pkasting@chromium.org | 4591fbd | 2014-11-20 22:28:14 +0000 | [diff] [blame] | 120 | #ifdef WEBRTC_CODEC_OPUS |
Karl Wiberg | 5817d3d | 2018-04-06 10:06:42 +0200 | [diff] [blame] | 121 | , |
| 122 | opus_pltype_(-1) |
pkasting@chromium.org | 4591fbd | 2014-11-20 22:28:14 +0000 | [diff] [blame] | 123 | #endif |
Karl Wiberg | eb254b4 | 2017-11-01 15:08:12 +0100 | [diff] [blame] | 124 | { |
tina.legrand@webrtc.org | 4517585 | 2012-06-01 09:27:35 +0000 | [diff] [blame] | 125 | // test_mode = 0 for silent test (auto test) |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 126 | test_mode_ = test_mode; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 127 | } |
| 128 | |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 129 | TestStereo::~TestStereo() { |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 130 | if (channel_a2b_ != NULL) { |
| 131 | delete channel_a2b_; |
| 132 | channel_a2b_ = NULL; |
| 133 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 134 | } |
| 135 | |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 136 | void TestStereo::Perform() { |
pbos@webrtc.org | 0946a56 | 2013-04-09 00:28:06 +0000 | [diff] [blame] | 137 | uint16_t frequency_hz; |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 138 | int audio_channels; |
| 139 | int codec_channels; |
tina.legrand@webrtc.org | 3ddc974 | 2012-06-27 09:25:50 +0000 | [diff] [blame] | 140 | bool dtx; |
| 141 | bool vad; |
| 142 | ACMVADMode vad_mode; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 143 | |
tina.legrand@webrtc.org | 4517585 | 2012-06-01 09:27:35 +0000 | [diff] [blame] | 144 | // Open both mono and stereo test files in 32 kHz. |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 145 | const std::string file_name_stereo = |
| 146 | webrtc::test::ResourcePath("audio_coding/teststereo32kHz", "pcm"); |
| 147 | const std::string file_name_mono = |
| 148 | webrtc::test::ResourcePath("audio_coding/testfile32kHz", "pcm"); |
tina.legrand@webrtc.org | 4517585 | 2012-06-01 09:27:35 +0000 | [diff] [blame] | 149 | frequency_hz = 32000; |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 150 | in_file_stereo_ = new PCMFile(); |
| 151 | in_file_mono_ = new PCMFile(); |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 152 | in_file_stereo_->Open(file_name_stereo, frequency_hz, "rb"); |
| 153 | in_file_stereo_->ReadStereo(true); |
| 154 | in_file_mono_->Open(file_name_mono, frequency_hz, "rb"); |
| 155 | in_file_mono_->ReadStereo(false); |
| 156 | |
tina.legrand@webrtc.org | 4517585 | 2012-06-01 09:27:35 +0000 | [diff] [blame] | 157 | // 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] | 158 | ASSERT_TRUE((acm_a_.get() != NULL) && (acm_b_.get() != NULL)); |
tina.legrand@webrtc.org | 3ddc974 | 2012-06-27 09:25:50 +0000 | [diff] [blame] | 159 | EXPECT_EQ(0, acm_a_->InitializeReceiver()); |
| 160 | EXPECT_EQ(0, acm_b_->InitializeReceiver()); |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 161 | |
tina.legrand@webrtc.org | 4517585 | 2012-06-01 09:27:35 +0000 | [diff] [blame] | 162 | // Register all available codes as receiving codecs. |
pbos@webrtc.org | 0946a56 | 2013-04-09 00:28:06 +0000 | [diff] [blame] | 163 | uint8_t num_encoders = acm_a_->NumberOfCodecs(); |
tina.legrand@webrtc.org | 4517585 | 2012-06-01 09:27:35 +0000 | [diff] [blame] | 164 | CodecInst my_codec_param; |
pbos@webrtc.org | 0946a56 | 2013-04-09 00:28:06 +0000 | [diff] [blame] | 165 | for (uint8_t n = 0; n < num_encoders; n++) { |
tina.legrand@webrtc.org | 7a7a008 | 2013-02-21 10:27:48 +0000 | [diff] [blame] | 166 | EXPECT_EQ(0, acm_b_->Codec(n, &my_codec_param)); |
kwiberg | da2bf4e | 2016-10-24 13:47:09 -0700 | [diff] [blame] | 167 | EXPECT_EQ(true, acm_b_->RegisterReceiveCodec( |
| 168 | my_codec_param.pltype, CodecInstToSdp(my_codec_param))); |
tina.legrand@webrtc.org | 4517585 | 2012-06-01 09:27:35 +0000 | [diff] [blame] | 169 | } |
| 170 | |
| 171 | // Test that unregister all receive codecs works. |
pbos@webrtc.org | 0946a56 | 2013-04-09 00:28:06 +0000 | [diff] [blame] | 172 | for (uint8_t n = 0; n < num_encoders; n++) { |
tina.legrand@webrtc.org | 7a7a008 | 2013-02-21 10:27:48 +0000 | [diff] [blame] | 173 | EXPECT_EQ(0, acm_b_->Codec(n, &my_codec_param)); |
tina.legrand@webrtc.org | 3ddc974 | 2012-06-27 09:25:50 +0000 | [diff] [blame] | 174 | EXPECT_EQ(0, acm_b_->UnregisterReceiveCodec(my_codec_param.pltype)); |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 175 | } |
tina.legrand@webrtc.org | ae1c454 | 2012-03-12 08:41:30 +0000 | [diff] [blame] | 176 | |
tina.legrand@webrtc.org | 4517585 | 2012-06-01 09:27:35 +0000 | [diff] [blame] | 177 | // Register all available codes as receiving codecs once more. |
pbos@webrtc.org | 0946a56 | 2013-04-09 00:28:06 +0000 | [diff] [blame] | 178 | for (uint8_t n = 0; n < num_encoders; n++) { |
tina.legrand@webrtc.org | 7a7a008 | 2013-02-21 10:27:48 +0000 | [diff] [blame] | 179 | EXPECT_EQ(0, acm_b_->Codec(n, &my_codec_param)); |
kwiberg | da2bf4e | 2016-10-24 13:47:09 -0700 | [diff] [blame] | 180 | EXPECT_EQ(true, acm_b_->RegisterReceiveCodec( |
| 181 | my_codec_param.pltype, CodecInstToSdp(my_codec_param))); |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 182 | } |
tina.legrand@webrtc.org | ae1c454 | 2012-03-12 08:41:30 +0000 | [diff] [blame] | 183 | |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 184 | // Create and connect the channel. |
| 185 | channel_a2b_ = new TestPackStereo; |
tina.legrand@webrtc.org | 3ddc974 | 2012-06-27 09:25:50 +0000 | [diff] [blame] | 186 | EXPECT_EQ(0, acm_a_->RegisterTransportCallback(channel_a2b_)); |
andrew@webrtc.org | 89df092 | 2013-09-12 01:27:43 +0000 | [diff] [blame] | 187 | channel_a2b_->RegisterReceiverACM(acm_b_.get()); |
tina.legrand@webrtc.org | df69775 | 2012-02-08 10:22:21 +0000 | [diff] [blame] | 188 | |
tina.legrand@webrtc.org | 3ddc974 | 2012-06-27 09:25:50 +0000 | [diff] [blame] | 189 | // Start with setting VAD/DTX, before we know we will send stereo. |
| 190 | // Continue with setting a stereo codec as send codec and verify that |
| 191 | // VAD/DTX gets turned off. |
| 192 | EXPECT_EQ(0, acm_a_->SetVAD(true, true, VADNormal)); |
tina.legrand@webrtc.org | 7a7a008 | 2013-02-21 10:27:48 +0000 | [diff] [blame] | 193 | EXPECT_EQ(0, acm_a_->VAD(&dtx, &vad, &vad_mode)); |
tina.legrand@webrtc.org | 3ddc974 | 2012-06-27 09:25:50 +0000 | [diff] [blame] | 194 | EXPECT_TRUE(dtx); |
| 195 | EXPECT_TRUE(vad); |
| 196 | char codec_pcma_temp[] = "PCMA"; |
| 197 | RegisterSendCodec('A', codec_pcma_temp, 8000, 64000, 80, 2, pcma_pltype_); |
tina.legrand@webrtc.org | 7a7a008 | 2013-02-21 10:27:48 +0000 | [diff] [blame] | 198 | EXPECT_EQ(0, acm_a_->VAD(&dtx, &vad, &vad_mode)); |
tina.legrand@webrtc.org | 3ddc974 | 2012-06-27 09:25:50 +0000 | [diff] [blame] | 199 | EXPECT_FALSE(dtx); |
| 200 | EXPECT_FALSE(vad); |
tina.legrand@webrtc.org | 46d90dc | 2013-02-01 14:20:06 +0000 | [diff] [blame] | 201 | if (test_mode_ != 0) { |
tina.legrand@webrtc.org | 3ddc974 | 2012-06-27 09:25:50 +0000 | [diff] [blame] | 202 | printf("\n"); |
| 203 | } |
| 204 | |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 205 | // |
| 206 | // Test Stereo-To-Stereo for all codecs. |
| 207 | // |
| 208 | audio_channels = 2; |
| 209 | codec_channels = 2; |
tina.legrand@webrtc.org | 6b6ff55 | 2012-01-11 10:12:54 +0000 | [diff] [blame] | 210 | |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 211 | // All codecs are tested for all allowed sampling frequencies, rates and |
| 212 | // packet sizes. |
tina.legrand@webrtc.org | 46d90dc | 2013-02-01 14:20:06 +0000 | [diff] [blame] | 213 | if (test_mode_ != 0) { |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 214 | printf("===========================================================\n"); |
tina.legrand@webrtc.org | a092cbf | 2013-02-14 09:28:10 +0000 | [diff] [blame] | 215 | printf("Test number: %d\n", test_cntr_ + 1); |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 216 | printf("Test type: Stereo-to-stereo\n"); |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 217 | } |
| 218 | channel_a2b_->set_codec_mode(kStereo); |
| 219 | test_cntr_++; |
| 220 | OpenOutFile(test_cntr_); |
| 221 | char codec_g722[] = "G722"; |
| 222 | RegisterSendCodec('A', codec_g722, 16000, 64000, 160, codec_channels, |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 223 | g722_pltype_); |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 224 | Run(channel_a2b_, audio_channels, codec_channels); |
| 225 | RegisterSendCodec('A', codec_g722, 16000, 64000, 320, codec_channels, |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 226 | g722_pltype_); |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 227 | Run(channel_a2b_, audio_channels, codec_channels); |
| 228 | RegisterSendCodec('A', codec_g722, 16000, 64000, 480, codec_channels, |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 229 | g722_pltype_); |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 230 | Run(channel_a2b_, audio_channels, codec_channels); |
| 231 | RegisterSendCodec('A', codec_g722, 16000, 64000, 640, codec_channels, |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 232 | g722_pltype_); |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 233 | Run(channel_a2b_, audio_channels, codec_channels); |
| 234 | RegisterSendCodec('A', codec_g722, 16000, 64000, 800, codec_channels, |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 235 | g722_pltype_); |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 236 | Run(channel_a2b_, audio_channels, codec_channels); |
| 237 | RegisterSendCodec('A', codec_g722, 16000, 64000, 960, codec_channels, |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 238 | g722_pltype_); |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 239 | Run(channel_a2b_, audio_channels, codec_channels); |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 240 | out_file_.Close(); |
Karl Wiberg | eb254b4 | 2017-11-01 15:08:12 +0100 | [diff] [blame] | 241 | |
tina.legrand@webrtc.org | 46d90dc | 2013-02-01 14:20:06 +0000 | [diff] [blame] | 242 | if (test_mode_ != 0) { |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 243 | printf("===========================================================\n"); |
tina.legrand@webrtc.org | a092cbf | 2013-02-14 09:28:10 +0000 | [diff] [blame] | 244 | printf("Test number: %d\n", test_cntr_ + 1); |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 245 | printf("Test type: Stereo-to-stereo\n"); |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 246 | } |
| 247 | channel_a2b_->set_codec_mode(kStereo); |
| 248 | test_cntr_++; |
| 249 | OpenOutFile(test_cntr_); |
| 250 | char codec_l16[] = "L16"; |
| 251 | RegisterSendCodec('A', codec_l16, 8000, 128000, 80, codec_channels, |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 252 | l16_8khz_pltype_); |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 253 | Run(channel_a2b_, audio_channels, codec_channels); |
| 254 | RegisterSendCodec('A', codec_l16, 8000, 128000, 160, codec_channels, |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 255 | l16_8khz_pltype_); |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 256 | Run(channel_a2b_, audio_channels, codec_channels); |
| 257 | RegisterSendCodec('A', codec_l16, 8000, 128000, 240, codec_channels, |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 258 | l16_8khz_pltype_); |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 259 | Run(channel_a2b_, audio_channels, codec_channels); |
| 260 | RegisterSendCodec('A', codec_l16, 8000, 128000, 320, codec_channels, |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 261 | l16_8khz_pltype_); |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 262 | Run(channel_a2b_, audio_channels, codec_channels); |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 263 | out_file_.Close(); |
tina.legrand@webrtc.org | 6b6ff55 | 2012-01-11 10:12:54 +0000 | [diff] [blame] | 264 | |
tina.legrand@webrtc.org | 46d90dc | 2013-02-01 14:20:06 +0000 | [diff] [blame] | 265 | if (test_mode_ != 0) { |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 266 | printf("===========================================================\n"); |
tina.legrand@webrtc.org | a092cbf | 2013-02-14 09:28:10 +0000 | [diff] [blame] | 267 | printf("Test number: %d\n", test_cntr_ + 1); |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 268 | printf("Test type: Stereo-to-stereo\n"); |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 269 | } |
| 270 | test_cntr_++; |
| 271 | OpenOutFile(test_cntr_); |
| 272 | RegisterSendCodec('A', codec_l16, 16000, 256000, 160, codec_channels, |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 273 | l16_16khz_pltype_); |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 274 | Run(channel_a2b_, audio_channels, codec_channels); |
| 275 | RegisterSendCodec('A', codec_l16, 16000, 256000, 320, codec_channels, |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 276 | l16_16khz_pltype_); |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 277 | Run(channel_a2b_, audio_channels, codec_channels); |
| 278 | RegisterSendCodec('A', codec_l16, 16000, 256000, 480, codec_channels, |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 279 | l16_16khz_pltype_); |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 280 | Run(channel_a2b_, audio_channels, codec_channels); |
| 281 | RegisterSendCodec('A', codec_l16, 16000, 256000, 640, codec_channels, |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 282 | l16_16khz_pltype_); |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 283 | Run(channel_a2b_, audio_channels, codec_channels); |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 284 | out_file_.Close(); |
tina.legrand@webrtc.org | 6b6ff55 | 2012-01-11 10:12:54 +0000 | [diff] [blame] | 285 | |
tina.legrand@webrtc.org | 46d90dc | 2013-02-01 14:20:06 +0000 | [diff] [blame] | 286 | if (test_mode_ != 0) { |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 287 | printf("===========================================================\n"); |
tina.legrand@webrtc.org | a092cbf | 2013-02-14 09:28:10 +0000 | [diff] [blame] | 288 | printf("Test number: %d\n", test_cntr_ + 1); |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 289 | printf("Test type: Stereo-to-stereo\n"); |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 290 | } |
| 291 | test_cntr_++; |
| 292 | OpenOutFile(test_cntr_); |
| 293 | RegisterSendCodec('A', codec_l16, 32000, 512000, 320, codec_channels, |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 294 | l16_32khz_pltype_); |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 295 | Run(channel_a2b_, audio_channels, codec_channels); |
| 296 | RegisterSendCodec('A', codec_l16, 32000, 512000, 640, codec_channels, |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 297 | l16_32khz_pltype_); |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 298 | Run(channel_a2b_, audio_channels, codec_channels); |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 299 | out_file_.Close(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 300 | #ifdef PCMA_AND_PCMU |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 301 | if (test_mode_ != 0) { |
| 302 | printf("===========================================================\n"); |
| 303 | printf("Test number: %d\n", test_cntr_ + 1); |
| 304 | printf("Test type: Stereo-to-stereo\n"); |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 305 | } |
| 306 | channel_a2b_->set_codec_mode(kStereo); |
| 307 | audio_channels = 2; |
| 308 | codec_channels = 2; |
| 309 | test_cntr_++; |
| 310 | OpenOutFile(test_cntr_); |
| 311 | char codec_pcma[] = "PCMA"; |
| 312 | RegisterSendCodec('A', codec_pcma, 8000, 64000, 80, codec_channels, |
| 313 | pcma_pltype_); |
| 314 | Run(channel_a2b_, audio_channels, codec_channels); |
| 315 | RegisterSendCodec('A', codec_pcma, 8000, 64000, 160, codec_channels, |
| 316 | pcma_pltype_); |
| 317 | Run(channel_a2b_, audio_channels, codec_channels); |
| 318 | RegisterSendCodec('A', codec_pcma, 8000, 64000, 240, codec_channels, |
| 319 | pcma_pltype_); |
| 320 | Run(channel_a2b_, audio_channels, codec_channels); |
| 321 | RegisterSendCodec('A', codec_pcma, 8000, 64000, 320, codec_channels, |
| 322 | pcma_pltype_); |
| 323 | Run(channel_a2b_, audio_channels, codec_channels); |
| 324 | RegisterSendCodec('A', codec_pcma, 8000, 64000, 400, codec_channels, |
| 325 | pcma_pltype_); |
| 326 | Run(channel_a2b_, audio_channels, codec_channels); |
| 327 | RegisterSendCodec('A', codec_pcma, 8000, 64000, 480, codec_channels, |
| 328 | pcma_pltype_); |
| 329 | Run(channel_a2b_, audio_channels, codec_channels); |
tina.legrand@webrtc.org | 3ddc974 | 2012-06-27 09:25:50 +0000 | [diff] [blame] | 330 | |
| 331 | // Test that VAD/DTX cannot be turned on while sending stereo. |
| 332 | EXPECT_EQ(-1, acm_a_->SetVAD(true, true, VADNormal)); |
tina.legrand@webrtc.org | 7a7a008 | 2013-02-21 10:27:48 +0000 | [diff] [blame] | 333 | EXPECT_EQ(0, acm_a_->VAD(&dtx, &vad, &vad_mode)); |
tina.legrand@webrtc.org | 3ddc974 | 2012-06-27 09:25:50 +0000 | [diff] [blame] | 334 | EXPECT_FALSE(dtx); |
| 335 | EXPECT_FALSE(vad); |
tina.legrand@webrtc.org | 3ddc974 | 2012-06-27 09:25:50 +0000 | [diff] [blame] | 336 | EXPECT_EQ(0, acm_a_->SetVAD(false, false, VADNormal)); |
tina.legrand@webrtc.org | 7a7a008 | 2013-02-21 10:27:48 +0000 | [diff] [blame] | 337 | EXPECT_EQ(0, acm_a_->VAD(&dtx, &vad, &vad_mode)); |
tina.legrand@webrtc.org | 3ddc974 | 2012-06-27 09:25:50 +0000 | [diff] [blame] | 338 | EXPECT_FALSE(dtx); |
| 339 | EXPECT_FALSE(vad); |
| 340 | |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 341 | out_file_.Close(); |
| 342 | if (test_mode_ != 0) { |
| 343 | printf("===========================================================\n"); |
| 344 | printf("Test number: %d\n", test_cntr_ + 1); |
| 345 | printf("Test type: Stereo-to-stereo\n"); |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 346 | } |
| 347 | test_cntr_++; |
| 348 | OpenOutFile(test_cntr_); |
| 349 | char codec_pcmu[] = "PCMU"; |
| 350 | RegisterSendCodec('A', codec_pcmu, 8000, 64000, 80, codec_channels, |
| 351 | pcmu_pltype_); |
| 352 | Run(channel_a2b_, audio_channels, codec_channels); |
| 353 | RegisterSendCodec('A', codec_pcmu, 8000, 64000, 160, codec_channels, |
| 354 | pcmu_pltype_); |
| 355 | Run(channel_a2b_, audio_channels, codec_channels); |
| 356 | RegisterSendCodec('A', codec_pcmu, 8000, 64000, 240, codec_channels, |
| 357 | pcmu_pltype_); |
| 358 | Run(channel_a2b_, audio_channels, codec_channels); |
| 359 | RegisterSendCodec('A', codec_pcmu, 8000, 64000, 320, codec_channels, |
| 360 | pcmu_pltype_); |
| 361 | Run(channel_a2b_, audio_channels, codec_channels); |
| 362 | RegisterSendCodec('A', codec_pcmu, 8000, 64000, 400, codec_channels, |
| 363 | pcmu_pltype_); |
| 364 | Run(channel_a2b_, audio_channels, codec_channels); |
| 365 | RegisterSendCodec('A', codec_pcmu, 8000, 64000, 480, codec_channels, |
| 366 | pcmu_pltype_); |
| 367 | Run(channel_a2b_, audio_channels, codec_channels); |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 368 | out_file_.Close(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 369 | #endif |
tina.legrand@webrtc.org | 0ad3c1a | 2012-11-07 08:07:29 +0000 | [diff] [blame] | 370 | #ifdef WEBRTC_CODEC_OPUS |
tina.legrand@webrtc.org | 46d90dc | 2013-02-01 14:20:06 +0000 | [diff] [blame] | 371 | if (test_mode_ != 0) { |
tina.legrand@webrtc.org | 0ad3c1a | 2012-11-07 08:07:29 +0000 | [diff] [blame] | 372 | printf("===========================================================\n"); |
tina.legrand@webrtc.org | a092cbf | 2013-02-14 09:28:10 +0000 | [diff] [blame] | 373 | printf("Test number: %d\n", test_cntr_ + 1); |
tina.legrand@webrtc.org | 0ad3c1a | 2012-11-07 08:07:29 +0000 | [diff] [blame] | 374 | printf("Test type: Stereo-to-stereo\n"); |
| 375 | } |
| 376 | channel_a2b_->set_codec_mode(kStereo); |
| 377 | audio_channels = 2; |
| 378 | codec_channels = 2; |
| 379 | test_cntr_++; |
| 380 | OpenOutFile(test_cntr_); |
tina.legrand@webrtc.org | 46d90dc | 2013-02-01 14:20:06 +0000 | [diff] [blame] | 381 | |
tina.legrand@webrtc.org | 0ad3c1a | 2012-11-07 08:07:29 +0000 | [diff] [blame] | 382 | char codec_opus[] = "opus"; |
tina.legrand@webrtc.org | 46d90dc | 2013-02-01 14:20:06 +0000 | [diff] [blame] | 383 | // Run Opus with 10 ms frame size. |
| 384 | RegisterSendCodec('A', codec_opus, 48000, 64000, 480, codec_channels, |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 385 | opus_pltype_); |
tina.legrand@webrtc.org | 0ad3c1a | 2012-11-07 08:07:29 +0000 | [diff] [blame] | 386 | Run(channel_a2b_, audio_channels, codec_channels); |
tina.legrand@webrtc.org | 46d90dc | 2013-02-01 14:20:06 +0000 | [diff] [blame] | 387 | // Run Opus with 20 ms frame size. |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 388 | RegisterSendCodec('A', codec_opus, 48000, 64000, 480 * 2, codec_channels, |
| 389 | opus_pltype_); |
tina.legrand@webrtc.org | 46d90dc | 2013-02-01 14:20:06 +0000 | [diff] [blame] | 390 | Run(channel_a2b_, audio_channels, codec_channels); |
| 391 | // Run Opus with 40 ms frame size. |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 392 | RegisterSendCodec('A', codec_opus, 48000, 64000, 480 * 4, codec_channels, |
| 393 | opus_pltype_); |
tina.legrand@webrtc.org | 46d90dc | 2013-02-01 14:20:06 +0000 | [diff] [blame] | 394 | Run(channel_a2b_, audio_channels, codec_channels); |
| 395 | // Run Opus with 60 ms frame size. |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 396 | RegisterSendCodec('A', codec_opus, 48000, 64000, 480 * 6, codec_channels, |
| 397 | opus_pltype_); |
tina.legrand@webrtc.org | 46d90dc | 2013-02-01 14:20:06 +0000 | [diff] [blame] | 398 | Run(channel_a2b_, audio_channels, codec_channels); |
| 399 | // Run Opus with 20 ms frame size and different bitrates. |
| 400 | RegisterSendCodec('A', codec_opus, 48000, 40000, 960, codec_channels, |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 401 | opus_pltype_); |
tina.legrand@webrtc.org | 0ad3c1a | 2012-11-07 08:07:29 +0000 | [diff] [blame] | 402 | Run(channel_a2b_, audio_channels, codec_channels); |
| 403 | RegisterSendCodec('A', codec_opus, 48000, 510000, 960, codec_channels, |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 404 | opus_pltype_); |
tina.legrand@webrtc.org | 0ad3c1a | 2012-11-07 08:07:29 +0000 | [diff] [blame] | 405 | Run(channel_a2b_, audio_channels, codec_channels); |
| 406 | out_file_.Close(); |
| 407 | #endif |
tina.legrand@webrtc.org | 6b6ff55 | 2012-01-11 10:12:54 +0000 | [diff] [blame] | 408 | // |
| 409 | // Test Mono-To-Stereo for all codecs. |
| 410 | // |
| 411 | audio_channels = 1; |
| 412 | codec_channels = 2; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 413 | |
tina.legrand@webrtc.org | 46d90dc | 2013-02-01 14:20:06 +0000 | [diff] [blame] | 414 | if (test_mode_ != 0) { |
tina.legrand@webrtc.org | 6b6ff55 | 2012-01-11 10:12:54 +0000 | [diff] [blame] | 415 | printf("===============================================================\n"); |
tina.legrand@webrtc.org | a092cbf | 2013-02-14 09:28:10 +0000 | [diff] [blame] | 416 | printf("Test number: %d\n", test_cntr_ + 1); |
tina.legrand@webrtc.org | 6b6ff55 | 2012-01-11 10:12:54 +0000 | [diff] [blame] | 417 | printf("Test type: Mono-to-stereo\n"); |
| 418 | } |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 419 | test_cntr_++; |
| 420 | channel_a2b_->set_codec_mode(kStereo); |
| 421 | OpenOutFile(test_cntr_); |
| 422 | RegisterSendCodec('A', codec_g722, 16000, 64000, 160, codec_channels, |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 423 | g722_pltype_); |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 424 | Run(channel_a2b_, audio_channels, codec_channels); |
| 425 | out_file_.Close(); |
Karl Wiberg | eb254b4 | 2017-11-01 15:08:12 +0100 | [diff] [blame] | 426 | |
tina.legrand@webrtc.org | 46d90dc | 2013-02-01 14:20:06 +0000 | [diff] [blame] | 427 | if (test_mode_ != 0) { |
tina.legrand@webrtc.org | 6b6ff55 | 2012-01-11 10:12:54 +0000 | [diff] [blame] | 428 | printf("===============================================================\n"); |
tina.legrand@webrtc.org | a092cbf | 2013-02-14 09:28:10 +0000 | [diff] [blame] | 429 | printf("Test number: %d\n", test_cntr_ + 1); |
tina.legrand@webrtc.org | 6b6ff55 | 2012-01-11 10:12:54 +0000 | [diff] [blame] | 430 | printf("Test type: Mono-to-stereo\n"); |
| 431 | } |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 432 | test_cntr_++; |
| 433 | channel_a2b_->set_codec_mode(kStereo); |
| 434 | OpenOutFile(test_cntr_); |
| 435 | RegisterSendCodec('A', codec_l16, 8000, 128000, 80, codec_channels, |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 436 | l16_8khz_pltype_); |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 437 | Run(channel_a2b_, audio_channels, codec_channels); |
| 438 | out_file_.Close(); |
tina.legrand@webrtc.org | 46d90dc | 2013-02-01 14:20:06 +0000 | [diff] [blame] | 439 | if (test_mode_ != 0) { |
tina.legrand@webrtc.org | 6b6ff55 | 2012-01-11 10:12:54 +0000 | [diff] [blame] | 440 | printf("===============================================================\n"); |
tina.legrand@webrtc.org | a092cbf | 2013-02-14 09:28:10 +0000 | [diff] [blame] | 441 | printf("Test number: %d\n", test_cntr_ + 1); |
tina.legrand@webrtc.org | 6b6ff55 | 2012-01-11 10:12:54 +0000 | [diff] [blame] | 442 | printf("Test type: Mono-to-stereo\n"); |
| 443 | } |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 444 | test_cntr_++; |
| 445 | OpenOutFile(test_cntr_); |
| 446 | RegisterSendCodec('A', codec_l16, 16000, 256000, 160, codec_channels, |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 447 | l16_16khz_pltype_); |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 448 | Run(channel_a2b_, audio_channels, codec_channels); |
| 449 | out_file_.Close(); |
tina.legrand@webrtc.org | 46d90dc | 2013-02-01 14:20:06 +0000 | [diff] [blame] | 450 | if (test_mode_ != 0) { |
tina.legrand@webrtc.org | 6b6ff55 | 2012-01-11 10:12:54 +0000 | [diff] [blame] | 451 | printf("===============================================================\n"); |
tina.legrand@webrtc.org | a092cbf | 2013-02-14 09:28:10 +0000 | [diff] [blame] | 452 | printf("Test number: %d\n", test_cntr_ + 1); |
tina.legrand@webrtc.org | 6b6ff55 | 2012-01-11 10:12:54 +0000 | [diff] [blame] | 453 | printf("Test type: Mono-to-stereo\n"); |
| 454 | } |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 455 | test_cntr_++; |
| 456 | OpenOutFile(test_cntr_); |
| 457 | RegisterSendCodec('A', codec_l16, 32000, 512000, 320, codec_channels, |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 458 | l16_32khz_pltype_); |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 459 | Run(channel_a2b_, audio_channels, codec_channels); |
| 460 | out_file_.Close(); |
tina.legrand@webrtc.org | 6b6ff55 | 2012-01-11 10:12:54 +0000 | [diff] [blame] | 461 | #ifdef PCMA_AND_PCMU |
tina.legrand@webrtc.org | 46d90dc | 2013-02-01 14:20:06 +0000 | [diff] [blame] | 462 | if (test_mode_ != 0) { |
tina.legrand@webrtc.org | 6b6ff55 | 2012-01-11 10:12:54 +0000 | [diff] [blame] | 463 | printf("===============================================================\n"); |
tina.legrand@webrtc.org | a092cbf | 2013-02-14 09:28:10 +0000 | [diff] [blame] | 464 | printf("Test number: %d\n", test_cntr_ + 1); |
tina.legrand@webrtc.org | 6b6ff55 | 2012-01-11 10:12:54 +0000 | [diff] [blame] | 465 | printf("Test type: Mono-to-stereo\n"); |
| 466 | } |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 467 | test_cntr_++; |
| 468 | channel_a2b_->set_codec_mode(kStereo); |
| 469 | OpenOutFile(test_cntr_); |
| 470 | RegisterSendCodec('A', codec_pcmu, 8000, 64000, 80, codec_channels, |
tina.legrand@webrtc.org | ae1c454 | 2012-03-12 08:41:30 +0000 | [diff] [blame] | 471 | pcmu_pltype_); |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 472 | Run(channel_a2b_, audio_channels, codec_channels); |
| 473 | RegisterSendCodec('A', codec_pcma, 8000, 64000, 80, codec_channels, |
tina.legrand@webrtc.org | ae1c454 | 2012-03-12 08:41:30 +0000 | [diff] [blame] | 474 | pcma_pltype_); |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 475 | Run(channel_a2b_, audio_channels, codec_channels); |
| 476 | out_file_.Close(); |
tina.legrand@webrtc.org | 6b6ff55 | 2012-01-11 10:12:54 +0000 | [diff] [blame] | 477 | #endif |
tina.legrand@webrtc.org | 0ad3c1a | 2012-11-07 08:07:29 +0000 | [diff] [blame] | 478 | #ifdef WEBRTC_CODEC_OPUS |
tina.legrand@webrtc.org | 46d90dc | 2013-02-01 14:20:06 +0000 | [diff] [blame] | 479 | if (test_mode_ != 0) { |
tina.legrand@webrtc.org | 0ad3c1a | 2012-11-07 08:07:29 +0000 | [diff] [blame] | 480 | printf("===============================================================\n"); |
tina.legrand@webrtc.org | a092cbf | 2013-02-14 09:28:10 +0000 | [diff] [blame] | 481 | printf("Test number: %d\n", test_cntr_ + 1); |
tina.legrand@webrtc.org | 0ad3c1a | 2012-11-07 08:07:29 +0000 | [diff] [blame] | 482 | printf("Test type: Mono-to-stereo\n"); |
| 483 | } |
tina.legrand@webrtc.org | c459058 | 2012-11-28 12:23:29 +0000 | [diff] [blame] | 484 | |
| 485 | // Keep encode and decode in stereo. |
tina.legrand@webrtc.org | 0ad3c1a | 2012-11-07 08:07:29 +0000 | [diff] [blame] | 486 | test_cntr_++; |
| 487 | channel_a2b_->set_codec_mode(kStereo); |
| 488 | OpenOutFile(test_cntr_); |
| 489 | RegisterSendCodec('A', codec_opus, 48000, 64000, 960, codec_channels, |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 490 | opus_pltype_); |
tina.legrand@webrtc.org | 0ad3c1a | 2012-11-07 08:07:29 +0000 | [diff] [blame] | 491 | Run(channel_a2b_, audio_channels, codec_channels); |
tina.legrand@webrtc.org | c459058 | 2012-11-28 12:23:29 +0000 | [diff] [blame] | 492 | |
| 493 | // Encode in mono, decode in stereo mode. |
| 494 | RegisterSendCodec('A', codec_opus, 48000, 64000, 960, 1, opus_pltype_); |
| 495 | Run(channel_a2b_, audio_channels, codec_channels); |
tina.legrand@webrtc.org | 0ad3c1a | 2012-11-07 08:07:29 +0000 | [diff] [blame] | 496 | out_file_.Close(); |
| 497 | #endif |
tina.legrand@webrtc.org | 6b6ff55 | 2012-01-11 10:12:54 +0000 | [diff] [blame] | 498 | |
| 499 | // |
| 500 | // Test Stereo-To-Mono for all codecs. |
| 501 | // |
| 502 | audio_channels = 2; |
| 503 | codec_channels = 1; |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 504 | channel_a2b_->set_codec_mode(kMono); |
tina.legrand@webrtc.org | 6b6ff55 | 2012-01-11 10:12:54 +0000 | [diff] [blame] | 505 | |
tina.legrand@webrtc.org | 6b6ff55 | 2012-01-11 10:12:54 +0000 | [diff] [blame] | 506 | // Run stereo audio and mono codec. |
tina.legrand@webrtc.org | 46d90dc | 2013-02-01 14:20:06 +0000 | [diff] [blame] | 507 | if (test_mode_ != 0) { |
tina.legrand@webrtc.org | 6b6ff55 | 2012-01-11 10:12:54 +0000 | [diff] [blame] | 508 | printf("===============================================================\n"); |
tina.legrand@webrtc.org | a092cbf | 2013-02-14 09:28:10 +0000 | [diff] [blame] | 509 | printf("Test number: %d\n", test_cntr_ + 1); |
tina.legrand@webrtc.org | 6b6ff55 | 2012-01-11 10:12:54 +0000 | [diff] [blame] | 510 | printf("Test type: Stereo-to-mono\n"); |
| 511 | } |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 512 | test_cntr_++; |
| 513 | OpenOutFile(test_cntr_); |
| 514 | RegisterSendCodec('A', codec_g722, 16000, 64000, 160, codec_channels, |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 515 | g722_pltype_); |
tina.legrand@webrtc.org | 3ddc974 | 2012-06-27 09:25:50 +0000 | [diff] [blame] | 516 | |
| 517 | // Make sure it is possible to set VAD/CNG, now that we are sending mono |
| 518 | // again. |
| 519 | EXPECT_EQ(0, acm_a_->SetVAD(true, true, VADNormal)); |
tina.legrand@webrtc.org | 7a7a008 | 2013-02-21 10:27:48 +0000 | [diff] [blame] | 520 | EXPECT_EQ(0, acm_a_->VAD(&dtx, &vad, &vad_mode)); |
tina.legrand@webrtc.org | 3ddc974 | 2012-06-27 09:25:50 +0000 | [diff] [blame] | 521 | EXPECT_TRUE(dtx); |
| 522 | EXPECT_TRUE(vad); |
| 523 | EXPECT_EQ(0, acm_a_->SetVAD(false, false, VADNormal)); |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 524 | Run(channel_a2b_, audio_channels, codec_channels); |
| 525 | out_file_.Close(); |
Karl Wiberg | eb254b4 | 2017-11-01 15:08:12 +0100 | [diff] [blame] | 526 | |
tina.legrand@webrtc.org | 46d90dc | 2013-02-01 14:20:06 +0000 | [diff] [blame] | 527 | if (test_mode_ != 0) { |
tina.legrand@webrtc.org | 6b6ff55 | 2012-01-11 10:12:54 +0000 | [diff] [blame] | 528 | printf("===============================================================\n"); |
tina.legrand@webrtc.org | a092cbf | 2013-02-14 09:28:10 +0000 | [diff] [blame] | 529 | printf("Test number: %d\n", test_cntr_ + 1); |
tina.legrand@webrtc.org | 6b6ff55 | 2012-01-11 10:12:54 +0000 | [diff] [blame] | 530 | printf("Test type: Stereo-to-mono\n"); |
| 531 | } |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 532 | test_cntr_++; |
| 533 | OpenOutFile(test_cntr_); |
| 534 | RegisterSendCodec('A', codec_l16, 8000, 128000, 80, codec_channels, |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 535 | l16_8khz_pltype_); |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 536 | Run(channel_a2b_, audio_channels, codec_channels); |
| 537 | out_file_.Close(); |
tina.legrand@webrtc.org | 46d90dc | 2013-02-01 14:20:06 +0000 | [diff] [blame] | 538 | if (test_mode_ != 0) { |
tina.legrand@webrtc.org | 6b6ff55 | 2012-01-11 10:12:54 +0000 | [diff] [blame] | 539 | printf("===============================================================\n"); |
tina.legrand@webrtc.org | a092cbf | 2013-02-14 09:28:10 +0000 | [diff] [blame] | 540 | printf("Test number: %d\n", test_cntr_ + 1); |
tina.legrand@webrtc.org | 6b6ff55 | 2012-01-11 10:12:54 +0000 | [diff] [blame] | 541 | printf("Test type: Stereo-to-mono\n"); |
tina.legrand@webrtc.org | a092cbf | 2013-02-14 09:28:10 +0000 | [diff] [blame] | 542 | } |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 543 | test_cntr_++; |
| 544 | OpenOutFile(test_cntr_); |
| 545 | RegisterSendCodec('A', codec_l16, 16000, 256000, 160, codec_channels, |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 546 | l16_16khz_pltype_); |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 547 | Run(channel_a2b_, audio_channels, codec_channels); |
| 548 | out_file_.Close(); |
tina.legrand@webrtc.org | 46d90dc | 2013-02-01 14:20:06 +0000 | [diff] [blame] | 549 | if (test_mode_ != 0) { |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 550 | printf("==============================================================\n"); |
| 551 | printf("Test number: %d\n", test_cntr_ + 1); |
| 552 | printf("Test type: Stereo-to-mono\n"); |
tina.legrand@webrtc.org | a092cbf | 2013-02-14 09:28:10 +0000 | [diff] [blame] | 553 | } |
| 554 | test_cntr_++; |
| 555 | OpenOutFile(test_cntr_); |
| 556 | RegisterSendCodec('A', codec_l16, 32000, 512000, 320, codec_channels, |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 557 | l16_32khz_pltype_); |
tina.legrand@webrtc.org | a092cbf | 2013-02-14 09:28:10 +0000 | [diff] [blame] | 558 | Run(channel_a2b_, audio_channels, codec_channels); |
| 559 | out_file_.Close(); |
tina.legrand@webrtc.org | 6b6ff55 | 2012-01-11 10:12:54 +0000 | [diff] [blame] | 560 | #ifdef PCMA_AND_PCMU |
tina.legrand@webrtc.org | 46d90dc | 2013-02-01 14:20:06 +0000 | [diff] [blame] | 561 | if (test_mode_ != 0) { |
tina.legrand@webrtc.org | 6b6ff55 | 2012-01-11 10:12:54 +0000 | [diff] [blame] | 562 | printf("===============================================================\n"); |
tina.legrand@webrtc.org | a092cbf | 2013-02-14 09:28:10 +0000 | [diff] [blame] | 563 | printf("Test number: %d\n", test_cntr_ + 1); |
tina.legrand@webrtc.org | df69775 | 2012-02-08 10:22:21 +0000 | [diff] [blame] | 564 | printf("Test type: Stereo-to-mono\n"); |
tina.legrand@webrtc.org | 6b6ff55 | 2012-01-11 10:12:54 +0000 | [diff] [blame] | 565 | } |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 566 | test_cntr_++; |
| 567 | OpenOutFile(test_cntr_); |
| 568 | RegisterSendCodec('A', codec_pcmu, 8000, 64000, 80, codec_channels, |
tina.legrand@webrtc.org | ae1c454 | 2012-03-12 08:41:30 +0000 | [diff] [blame] | 569 | pcmu_pltype_); |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 570 | Run(channel_a2b_, audio_channels, codec_channels); |
| 571 | RegisterSendCodec('A', codec_pcma, 8000, 64000, 80, codec_channels, |
tina.legrand@webrtc.org | ae1c454 | 2012-03-12 08:41:30 +0000 | [diff] [blame] | 572 | pcma_pltype_); |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 573 | Run(channel_a2b_, audio_channels, codec_channels); |
| 574 | out_file_.Close(); |
tina.legrand@webrtc.org | 6b6ff55 | 2012-01-11 10:12:54 +0000 | [diff] [blame] | 575 | #endif |
tina.legrand@webrtc.org | 0ad3c1a | 2012-11-07 08:07:29 +0000 | [diff] [blame] | 576 | #ifdef WEBRTC_CODEC_OPUS |
tina.legrand@webrtc.org | 46d90dc | 2013-02-01 14:20:06 +0000 | [diff] [blame] | 577 | if (test_mode_ != 0) { |
tina.legrand@webrtc.org | 0ad3c1a | 2012-11-07 08:07:29 +0000 | [diff] [blame] | 578 | printf("===============================================================\n"); |
tina.legrand@webrtc.org | a092cbf | 2013-02-14 09:28:10 +0000 | [diff] [blame] | 579 | printf("Test number: %d\n", test_cntr_ + 1); |
tina.legrand@webrtc.org | 0ad3c1a | 2012-11-07 08:07:29 +0000 | [diff] [blame] | 580 | printf("Test type: Stereo-to-mono\n"); |
| 581 | } |
| 582 | test_cntr_++; |
| 583 | OpenOutFile(test_cntr_); |
tina.legrand@webrtc.org | c459058 | 2012-11-28 12:23:29 +0000 | [diff] [blame] | 584 | // Encode and decode in mono. |
tina.legrand@webrtc.org | 0ad3c1a | 2012-11-07 08:07:29 +0000 | [diff] [blame] | 585 | RegisterSendCodec('A', codec_opus, 48000, 32000, 960, codec_channels, |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 586 | opus_pltype_); |
tina.legrand@webrtc.org | c459058 | 2012-11-28 12:23:29 +0000 | [diff] [blame] | 587 | CodecInst opus_codec_param; |
pbos@webrtc.org | 0946a56 | 2013-04-09 00:28:06 +0000 | [diff] [blame] | 588 | for (uint8_t n = 0; n < num_encoders; n++) { |
tina.legrand@webrtc.org | 7a7a008 | 2013-02-21 10:27:48 +0000 | [diff] [blame] | 589 | EXPECT_EQ(0, acm_b_->Codec(n, &opus_codec_param)); |
tina.legrand@webrtc.org | c459058 | 2012-11-28 12:23:29 +0000 | [diff] [blame] | 590 | if (!strcmp(opus_codec_param.plname, "opus")) { |
| 591 | opus_codec_param.channels = 1; |
kwiberg | da2bf4e | 2016-10-24 13:47:09 -0700 | [diff] [blame] | 592 | EXPECT_EQ(true, |
| 593 | acm_b_->RegisterReceiveCodec(opus_codec_param.pltype, |
| 594 | CodecInstToSdp(opus_codec_param))); |
tina.legrand@webrtc.org | c459058 | 2012-11-28 12:23:29 +0000 | [diff] [blame] | 595 | break; |
| 596 | } |
| 597 | } |
| 598 | Run(channel_a2b_, audio_channels, codec_channels); |
| 599 | |
| 600 | // Encode in stereo, decode in mono. |
| 601 | RegisterSendCodec('A', codec_opus, 48000, 32000, 960, 2, opus_pltype_); |
| 602 | Run(channel_a2b_, audio_channels, codec_channels); |
| 603 | |
| 604 | out_file_.Close(); |
| 605 | |
| 606 | // Test switching between decoding mono and stereo for Opus. |
| 607 | |
| 608 | // Decode in mono. |
| 609 | test_cntr_++; |
| 610 | OpenOutFile(test_cntr_); |
| 611 | if (test_mode_ != 0) { |
| 612 | // Print out codec and settings |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 613 | printf( |
| 614 | "Test number: %d\nCodec: Opus Freq: 48000 Rate :32000 PackSize: 960" |
| 615 | " Decode: mono\n", |
| 616 | test_cntr_); |
tina.legrand@webrtc.org | c459058 | 2012-11-28 12:23:29 +0000 | [diff] [blame] | 617 | } |
tina.legrand@webrtc.org | 0ad3c1a | 2012-11-07 08:07:29 +0000 | [diff] [blame] | 618 | Run(channel_a2b_, audio_channels, codec_channels); |
| 619 | out_file_.Close(); |
tina.legrand@webrtc.org | c459058 | 2012-11-28 12:23:29 +0000 | [diff] [blame] | 620 | // Decode in stereo. |
| 621 | test_cntr_++; |
| 622 | OpenOutFile(test_cntr_); |
| 623 | if (test_mode_ != 0) { |
| 624 | // Print out codec and settings |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 625 | printf( |
| 626 | "Test number: %d\nCodec: Opus Freq: 48000 Rate :32000 PackSize: 960" |
| 627 | " Decode: stereo\n", |
| 628 | test_cntr_); |
tina.legrand@webrtc.org | c459058 | 2012-11-28 12:23:29 +0000 | [diff] [blame] | 629 | } |
| 630 | opus_codec_param.channels = 2; |
kwiberg | da2bf4e | 2016-10-24 13:47:09 -0700 | [diff] [blame] | 631 | EXPECT_EQ(true, |
| 632 | acm_b_->RegisterReceiveCodec(opus_codec_param.pltype, |
| 633 | CodecInstToSdp(opus_codec_param))); |
tina.legrand@webrtc.org | c459058 | 2012-11-28 12:23:29 +0000 | [diff] [blame] | 634 | Run(channel_a2b_, audio_channels, 2); |
| 635 | out_file_.Close(); |
| 636 | // Decode in mono. |
| 637 | test_cntr_++; |
| 638 | OpenOutFile(test_cntr_); |
| 639 | if (test_mode_ != 0) { |
| 640 | // Print out codec and settings |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 641 | printf( |
| 642 | "Test number: %d\nCodec: Opus Freq: 48000 Rate :32000 PackSize: 960" |
| 643 | " Decode: mono\n", |
| 644 | test_cntr_); |
tina.legrand@webrtc.org | c459058 | 2012-11-28 12:23:29 +0000 | [diff] [blame] | 645 | } |
| 646 | opus_codec_param.channels = 1; |
kwiberg | da2bf4e | 2016-10-24 13:47:09 -0700 | [diff] [blame] | 647 | EXPECT_EQ(true, |
| 648 | acm_b_->RegisterReceiveCodec(opus_codec_param.pltype, |
| 649 | CodecInstToSdp(opus_codec_param))); |
tina.legrand@webrtc.org | c459058 | 2012-11-28 12:23:29 +0000 | [diff] [blame] | 650 | Run(channel_a2b_, audio_channels, codec_channels); |
| 651 | out_file_.Close(); |
| 652 | |
tina.legrand@webrtc.org | 0ad3c1a | 2012-11-07 08:07:29 +0000 | [diff] [blame] | 653 | #endif |
tina.legrand@webrtc.org | 6b6ff55 | 2012-01-11 10:12:54 +0000 | [diff] [blame] | 654 | |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 655 | // Print out which codecs were tested, and which were not, in the run. |
| 656 | if (test_mode_ != 0) { |
| 657 | printf("\nThe following codecs was INCLUDED in the test:\n"); |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 658 | printf(" G.722\n"); |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 659 | printf(" PCM16\n"); |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 660 | printf(" G.711\n"); |
tina.legrand@webrtc.org | c459058 | 2012-11-28 12:23:29 +0000 | [diff] [blame] | 661 | #ifdef WEBRTC_CODEC_OPUS |
| 662 | printf(" Opus\n"); |
| 663 | #endif |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 664 | printf( |
| 665 | "\nTo complete the test, listen to the %d number of output " |
| 666 | "files.\n", |
| 667 | test_cntr_); |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 668 | } |
| 669 | |
| 670 | // Delete the file pointers. |
| 671 | delete in_file_stereo_; |
| 672 | delete in_file_mono_; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 673 | } |
| 674 | |
| 675 | // Register Codec to use in the test |
| 676 | // |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 677 | // Input: side - which ACM to use, 'A' or 'B' |
| 678 | // codec_name - name to use when register the codec |
| 679 | // sampling_freq_hz - sampling frequency in Herz |
| 680 | // rate - bitrate in bytes |
| 681 | // pack_size - packet size in samples |
| 682 | // channels - number of channels; 1 for mono, 2 for stereo |
| 683 | // payload_type - payload type for the codec |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 684 | void TestStereo::RegisterSendCodec(char side, |
| 685 | char* codec_name, |
| 686 | int32_t sampling_freq_hz, |
| 687 | int rate, |
| 688 | int pack_size, |
| 689 | int channels, |
tina.legrand@webrtc.org | 3ddc974 | 2012-06-27 09:25:50 +0000 | [diff] [blame] | 690 | int payload_type) { |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 691 | if (test_mode_ != 0) { |
| 692 | // Print out codec and settings |
tina.legrand@webrtc.org | ba46804 | 2012-08-17 10:38:28 +0000 | [diff] [blame] | 693 | printf("Codec: %s Freq: %d Rate: %d PackSize: %d\n", codec_name, |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 694 | sampling_freq_hz, rate, pack_size); |
| 695 | } |
| 696 | |
| 697 | // Store packet size in samples, used to validate the received packet |
| 698 | pack_size_samp_ = pack_size; |
| 699 | |
| 700 | // Store the expected packet size in bytes, used to validate the received |
| 701 | // 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] | 702 | pack_size_bytes_ = (uint16_t)(static_cast<float>(pack_size * rate) / |
| 703 | static_cast<float>(sampling_freq_hz * 8) + |
| 704 | 0.875); |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 705 | |
| 706 | // Set pointer to the ACM where to register the codec |
tina.legrand@webrtc.org | 3ddc974 | 2012-06-27 09:25:50 +0000 | [diff] [blame] | 707 | AudioCodingModule* my_acm = NULL; |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 708 | switch (side) { |
| 709 | case 'A': { |
andrew@webrtc.org | 89df092 | 2013-09-12 01:27:43 +0000 | [diff] [blame] | 710 | my_acm = acm_a_.get(); |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 711 | break; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 712 | } |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 713 | case 'B': { |
andrew@webrtc.org | 89df092 | 2013-09-12 01:27:43 +0000 | [diff] [blame] | 714 | my_acm = acm_b_.get(); |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 715 | break; |
tina.legrand@webrtc.org | 16b6b90 | 2012-04-12 11:02:38 +0000 | [diff] [blame] | 716 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 717 | default: |
tina.legrand@webrtc.org | 3ddc974 | 2012-06-27 09:25:50 +0000 | [diff] [blame] | 718 | break; |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 719 | } |
tina.legrand@webrtc.org | 3ddc974 | 2012-06-27 09:25:50 +0000 | [diff] [blame] | 720 | ASSERT_TRUE(my_acm != NULL); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 721 | |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 722 | CodecInst my_codec_param; |
| 723 | // Get all codec parameters before registering |
tina.legrand@webrtc.org | ee92b66 | 2013-08-27 07:33:51 +0000 | [diff] [blame] | 724 | EXPECT_GT(AudioCodingModule::Codec(codec_name, &my_codec_param, |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 725 | sampling_freq_hz, channels), |
| 726 | -1); |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 727 | my_codec_param.rate = rate; |
| 728 | my_codec_param.pacsize = pack_size; |
tina.legrand@webrtc.org | ee92b66 | 2013-08-27 07:33:51 +0000 | [diff] [blame] | 729 | EXPECT_EQ(0, my_acm->RegisterSendCodec(my_codec_param)); |
tina.legrand@webrtc.org | 0ad3c1a | 2012-11-07 08:07:29 +0000 | [diff] [blame] | 730 | |
| 731 | send_codec_name_ = codec_name; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 732 | } |
| 733 | |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 734 | void TestStereo::Run(TestPackStereo* channel, |
| 735 | int in_channels, |
| 736 | int out_channels, |
tina.legrand@webrtc.org | 16b6b90 | 2012-04-12 11:02:38 +0000 | [diff] [blame] | 737 | int percent_loss) { |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 738 | AudioFrame audio_frame; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 739 | |
pbos@webrtc.org | 0946a56 | 2013-04-09 00:28:06 +0000 | [diff] [blame] | 740 | int32_t out_freq_hz_b = out_file_.SamplingFrequency(); |
| 741 | uint16_t rec_size; |
| 742 | uint32_t time_stamp_diff; |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 743 | channel->reset_payload_size(); |
| 744 | int error_count = 0; |
tina.legrand@webrtc.org | 65d61c3 | 2014-06-05 13:42:51 +0000 | [diff] [blame] | 745 | int variable_bytes = 0; |
| 746 | int variable_packets = 0; |
Henrik Lundin | 4d68208 | 2015-12-10 16:24:39 +0100 | [diff] [blame] | 747 | // Set test length to 500 ms (50 blocks of 10 ms each). |
| 748 | in_file_mono_->SetNum10MsBlocksToRead(50); |
| 749 | in_file_stereo_->SetNum10MsBlocksToRead(50); |
| 750 | // Fast-forward 1 second (100 blocks) since the files start with silence. |
| 751 | in_file_stereo_->FastForward(100); |
| 752 | in_file_mono_->FastForward(100); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 753 | |
andresp@webrtc.org | d0b436a | 2014-01-13 13:15:59 +0000 | [diff] [blame] | 754 | while (1) { |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 755 | // Simulate packet loss by setting |packet_loss_| to "true" in |
| 756 | // |percent_loss| percent of the loops. |
| 757 | if (percent_loss > 0) { |
| 758 | if (counter_ == floor((100 / percent_loss) + 0.5)) { |
| 759 | counter_ = 0; |
| 760 | channel->set_lost_packet(true); |
| 761 | } else { |
| 762 | channel->set_lost_packet(false); |
| 763 | } |
| 764 | counter_++; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 765 | } |
| 766 | |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 767 | // Add 10 msec to ACM |
| 768 | if (in_channels == 1) { |
| 769 | if (in_file_mono_->EndOfFile()) { |
| 770 | break; |
| 771 | } |
| 772 | in_file_mono_->Read10MsData(audio_frame); |
| 773 | } else { |
| 774 | if (in_file_stereo_->EndOfFile()) { |
| 775 | break; |
| 776 | } |
| 777 | in_file_stereo_->Read10MsData(audio_frame); |
| 778 | } |
henrik.lundin@webrtc.org | f56c162 | 2015-03-02 12:29:30 +0000 | [diff] [blame] | 779 | EXPECT_GE(acm_a_->Add10MsData(audio_frame), 0); |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 780 | |
tina.legrand@webrtc.org | 65d61c3 | 2014-06-05 13:42:51 +0000 | [diff] [blame] | 781 | // Verify that the received packet size matches the settings. |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 782 | rec_size = channel->payload_size(); |
| 783 | if ((0 < rec_size) & (rec_size < 65535)) { |
tina.legrand@webrtc.org | 65d61c3 | 2014-06-05 13:42:51 +0000 | [diff] [blame] | 784 | if (strcmp(send_codec_name_, "opus") == 0) { |
| 785 | // Opus is a variable rate codec, hence calculate the average packet |
| 786 | // size, and later make sure the average is in the right range. |
| 787 | variable_bytes += rec_size; |
| 788 | variable_packets++; |
| 789 | } else { |
| 790 | // For fixed rate codecs, check that packet size is correct. |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 791 | if ((rec_size != pack_size_bytes_ * out_channels) && |
| 792 | (pack_size_bytes_ < 65535)) { |
tina.legrand@webrtc.org | 0ad3c1a | 2012-11-07 08:07:29 +0000 | [diff] [blame] | 793 | error_count++; |
| 794 | } |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 795 | } |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 796 | // Verify that the timestamp is updated with expected length |
| 797 | time_stamp_diff = channel->timestamp_diff(); |
| 798 | if ((counter_ > 10) && (time_stamp_diff != pack_size_samp_)) { |
| 799 | error_count++; |
| 800 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 801 | } |
| 802 | |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 803 | // Run received side of ACM |
henrik.lundin | d4ccb00 | 2016-05-17 12:21:55 -0700 | [diff] [blame] | 804 | bool muted; |
| 805 | EXPECT_EQ(0, acm_b_->PlayoutData10Ms(out_freq_hz_b, &audio_frame, &muted)); |
| 806 | ASSERT_FALSE(muted); |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 807 | |
| 808 | // Write output speech to file |
| 809 | out_file_.Write10MsData( |
yujo | 36b1a5f | 2017-06-12 12:45:32 -0700 | [diff] [blame] | 810 | audio_frame.data(), |
andrew@webrtc.org | 63a5098 | 2012-05-02 23:56:37 +0000 | [diff] [blame] | 811 | audio_frame.samples_per_channel_ * audio_frame.num_channels_); |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 812 | } |
| 813 | |
tina.legrand@webrtc.org | 3ddc974 | 2012-06-27 09:25:50 +0000 | [diff] [blame] | 814 | EXPECT_EQ(0, error_count); |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 815 | |
tina.legrand@webrtc.org | 65d61c3 | 2014-06-05 13:42:51 +0000 | [diff] [blame] | 816 | // Check that packet size is in the right range for variable rate codecs, |
| 817 | // such as Opus. |
| 818 | if (variable_packets > 0) { |
| 819 | variable_bytes /= variable_packets; |
Henrik Lundin | 4d68208 | 2015-12-10 16:24:39 +0100 | [diff] [blame] | 820 | EXPECT_NEAR(variable_bytes, pack_size_bytes_, 18); |
tina.legrand@webrtc.org | 65d61c3 | 2014-06-05 13:42:51 +0000 | [diff] [blame] | 821 | } |
| 822 | |
andresp@webrtc.org | d0b436a | 2014-01-13 13:15:59 +0000 | [diff] [blame] | 823 | if (in_file_mono_->EndOfFile()) { |
| 824 | in_file_mono_->Rewind(); |
| 825 | } |
| 826 | if (in_file_stereo_->EndOfFile()) { |
| 827 | in_file_stereo_->Rewind(); |
| 828 | } |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 829 | // Reset in case we ended with a lost packet |
| 830 | channel->set_lost_packet(false); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 831 | } |
| 832 | |
pbos@webrtc.org | 0946a56 | 2013-04-09 00:28:06 +0000 | [diff] [blame] | 833 | void TestStereo::OpenOutFile(int16_t test_number) { |
tina.legrand@webrtc.org | ba46804 | 2012-08-17 10:38:28 +0000 | [diff] [blame] | 834 | std::string file_name; |
| 835 | std::stringstream file_stream; |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 836 | file_stream << webrtc::test::OutputPath() << "teststereo_out_" << test_number |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 837 | << ".pcm"; |
tina.legrand@webrtc.org | ba46804 | 2012-08-17 10:38:28 +0000 | [diff] [blame] | 838 | file_name = file_stream.str(); |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 839 | out_file_.Open(file_name, 32000, "wb"); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 840 | } |
| 841 | |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 842 | void TestStereo::DisplaySendReceiveCodec() { |
kwiberg | 1fd4a4a | 2015-11-03 11:20:50 -0800 | [diff] [blame] | 843 | auto send_codec = acm_a_->SendCodec(); |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 844 | if (test_mode_ != 0) { |
kwiberg | 1fd4a4a | 2015-11-03 11:20:50 -0800 | [diff] [blame] | 845 | ASSERT_TRUE(send_codec); |
| 846 | printf("%s -> ", send_codec->plname); |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 847 | } |
kwiberg | 1fd4a4a | 2015-11-03 11:20:50 -0800 | [diff] [blame] | 848 | CodecInst receive_codec; |
| 849 | acm_b_->ReceiveCodec(&receive_codec); |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 850 | if (test_mode_ != 0) { |
kwiberg | 1fd4a4a | 2015-11-03 11:20:50 -0800 | [diff] [blame] | 851 | printf("%s\n", receive_codec.plname); |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 852 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 853 | } |
| 854 | |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 855 | } // namespace webrtc |