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