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