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