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 | |
tina.legrand@webrtc.org | a092cbf | 2013-02-14 09:28:10 +0000 | [diff] [blame] | 11 | #include "webrtc/modules/audio_coding/main/test/TestStereo.h" |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 12 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 13 | #include <cassert> |
tina.legrand@webrtc.org | a092cbf | 2013-02-14 09:28:10 +0000 | [diff] [blame] | 14 | #include <string> |
kjellander@webrtc.org | 5490c71 | 2011-12-21 13:34:18 +0000 | [diff] [blame] | 15 | |
tina.legrand@webrtc.org | 3ddc974 | 2012-06-27 09:25:50 +0000 | [diff] [blame] | 16 | #include "gtest/gtest.h" |
| 17 | |
tina.legrand@webrtc.org | a092cbf | 2013-02-14 09:28:10 +0000 | [diff] [blame] | 18 | #include "webrtc/common_types.h" |
| 19 | #include "webrtc/engine_configurations.h" |
| 20 | #include "webrtc/modules/audio_coding/main/interface/audio_coding_module_typedefs.h" |
| 21 | #include "webrtc/modules/audio_coding/main/test/utility.h" |
| 22 | #include "webrtc/system_wrappers/interface/trace.h" |
| 23 | #include "webrtc/test/testsupport/fileutils.h" |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 24 | |
tina.legrand@webrtc.org | 554ae1a | 2011-12-16 10:09:04 +0000 | [diff] [blame] | 25 | namespace webrtc { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 26 | |
| 27 | // Class for simulating packet handling |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 28 | TestPackStereo::TestPackStereo() |
| 29 | : receiver_acm_(NULL), |
| 30 | seq_no_(0), |
| 31 | timestamp_diff_(0), |
| 32 | last_in_timestamp_(0), |
| 33 | total_bytes_(0), |
| 34 | payload_size_(0), |
| 35 | codec_mode_(kNotSet), |
| 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 | |
pbos@webrtc.org | 0946a56 | 2013-04-09 00:28:06 +0000 | [diff] [blame] | 45 | int32_t TestPackStereo::SendData( |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 46 | const FrameType frame_type, |
pbos@webrtc.org | 0946a56 | 2013-04-09 00:28:06 +0000 | [diff] [blame] | 47 | const uint8_t payload_type, |
| 48 | const uint32_t timestamp, |
| 49 | const uint8_t* payload_data, |
| 50 | const uint16_t 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; |
pbos@webrtc.org | 0946a56 | 2013-04-09 00:28:06 +0000 | [diff] [blame] | 53 | int32_t status = 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 54 | |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 55 | rtp_info.header.markerBit = false; |
| 56 | rtp_info.header.ssrc = 0; |
| 57 | rtp_info.header.sequenceNumber = seq_no_++; |
| 58 | rtp_info.header.payloadType = payload_type; |
| 59 | rtp_info.header.timestamp = timestamp; |
| 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; |
tina.legrand@webrtc.org | a092cbf | 2013-02-14 09:28:10 +0000 | [diff] [blame] | 68 | rtp_info.type.Audio.channel = static_cast<int>(codec_mode_); |
tina.legrand@webrtc.org | 6b6ff55 | 2012-01-11 10:12:54 +0000 | [diff] [blame] | 69 | } else { |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 70 | rtp_info.type.Audio.isCNG = true; |
tina.legrand@webrtc.org | a092cbf | 2013-02-14 09:28:10 +0000 | [diff] [blame] | 71 | rtp_info.type.Audio.channel = static_cast<int>(kMono); |
tina.legrand@webrtc.org | 6b6ff55 | 2012-01-11 10:12:54 +0000 | [diff] [blame] | 72 | } |
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 | |
pbos@webrtc.org | 0946a56 | 2013-04-09 00:28:06 +0000 | [diff] [blame] | 89 | uint16_t TestPackStereo::payload_size() { |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 90 | return payload_size_; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 91 | } |
| 92 | |
pbos@webrtc.org | 0946a56 | 2013-04-09 00:28:06 +0000 | [diff] [blame] | 93 | uint32_t TestPackStereo::timestamp_diff() { |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 94 | return timestamp_diff_; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 95 | } |
| 96 | |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 97 | void TestPackStereo::reset_payload_size() { |
| 98 | payload_size_ = 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 99 | } |
| 100 | |
tina.legrand@webrtc.org | 16b6b90 | 2012-04-12 11:02:38 +0000 | [diff] [blame] | 101 | void TestPackStereo::set_codec_mode(enum StereoMonoMode mode) { |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 102 | codec_mode_ = mode; |
tina.legrand@webrtc.org | 16b6b90 | 2012-04-12 11:02:38 +0000 | [diff] [blame] | 103 | } |
| 104 | |
| 105 | void TestPackStereo::set_lost_packet(bool lost) { |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 106 | lost_packet_ = lost; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 107 | } |
| 108 | |
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() { |
pbos@webrtc.org | 0946a56 | 2013-04-09 00:28:06 +0000 | [diff] [blame] | 148 | uint16_t frequency_hz; |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 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. |
pbos@webrtc.org | 0946a56 | 2013-04-09 00:28:06 +0000 | [diff] [blame] | 182 | uint8_t num_encoders = acm_a_->NumberOfCodecs(); |
tina.legrand@webrtc.org | 4517585 | 2012-06-01 09:27:35 +0000 | [diff] [blame] | 183 | CodecInst my_codec_param; |
pbos@webrtc.org | 0946a56 | 2013-04-09 00:28:06 +0000 | [diff] [blame] | 184 | for (uint8_t n = 0; n < num_encoders; n++) { |
tina.legrand@webrtc.org | 7a7a008 | 2013-02-21 10:27:48 +0000 | [diff] [blame] | 185 | EXPECT_EQ(0, acm_b_->Codec(n, &my_codec_param)); |
tina.legrand@webrtc.org | 3ddc974 | 2012-06-27 09:25:50 +0000 | [diff] [blame] | 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. |
pbos@webrtc.org | 0946a56 | 2013-04-09 00:28:06 +0000 | [diff] [blame] | 190 | for (uint8_t n = 0; n < num_encoders; n++) { |
tina.legrand@webrtc.org | 7a7a008 | 2013-02-21 10:27:48 +0000 | [diff] [blame] | 191 | EXPECT_EQ(0, acm_b_->Codec(n, &my_codec_param)); |
tina.legrand@webrtc.org | 3ddc974 | 2012-06-27 09:25:50 +0000 | [diff] [blame] | 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. |
pbos@webrtc.org | 0946a56 | 2013-04-09 00:28:06 +0000 | [diff] [blame] | 196 | for (uint8_t n = 0; n < num_encoders; n++) { |
tina.legrand@webrtc.org | 7a7a008 | 2013-02-21 10:27:48 +0000 | [diff] [blame] | 197 | EXPECT_EQ(0, acm_b_->Codec(n, &my_codec_param)); |
tina.legrand@webrtc.org | 3ddc974 | 2012-06-27 09:25:50 +0000 | [diff] [blame] | 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)); |
tina.legrand@webrtc.org | 7a7a008 | 2013-02-21 10:27:48 +0000 | [diff] [blame] | 225 | EXPECT_EQ(0, acm_a_->VAD(&dtx, &vad, &vad_mode)); |
tina.legrand@webrtc.org | 3ddc974 | 2012-06-27 09:25:50 +0000 | [diff] [blame] | 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_); |
tina.legrand@webrtc.org | 7a7a008 | 2013-02-21 10:27:48 +0000 | [diff] [blame] | 230 | EXPECT_EQ(0, acm_a_->VAD(&dtx, &vad, &vad_mode)); |
tina.legrand@webrtc.org | 3ddc974 | 2012-06-27 09:25:50 +0000 | [diff] [blame] | 231 | EXPECT_FALSE(dtx); |
| 232 | EXPECT_FALSE(vad); |
tina.legrand@webrtc.org | 46d90dc | 2013-02-01 14:20:06 +0000 | [diff] [blame] | 233 | if (test_mode_ != 0) { |
tina.legrand@webrtc.org | 3ddc974 | 2012-06-27 09:25:50 +0000 | [diff] [blame] | 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 | 46d90dc | 2013-02-01 14:20:06 +0000 | [diff] [blame] | 246 | if (test_mode_ != 0) { |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 247 | printf("===========================================================\n"); |
tina.legrand@webrtc.org | a092cbf | 2013-02-14 09:28:10 +0000 | [diff] [blame] | 248 | printf("Test number: %d\n", test_cntr_ + 1); |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 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 | 46d90dc | 2013-02-01 14:20:06 +0000 | [diff] [blame] | 276 | if (test_mode_ != 0) { |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 277 | printf("===========================================================\n"); |
tina.legrand@webrtc.org | a092cbf | 2013-02-14 09:28:10 +0000 | [diff] [blame] | 278 | printf("Test number: %d\n", test_cntr_ + 1); |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 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 | 46d90dc | 2013-02-01 14:20:06 +0000 | [diff] [blame] | 299 | if (test_mode_ != 0) { |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 300 | printf("===========================================================\n"); |
tina.legrand@webrtc.org | a092cbf | 2013-02-14 09:28:10 +0000 | [diff] [blame] | 301 | printf("Test number: %d\n", test_cntr_ + 1); |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 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 | 46d90dc | 2013-02-01 14:20:06 +0000 | [diff] [blame] | 320 | if (test_mode_ != 0) { |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 321 | printf("===========================================================\n"); |
tina.legrand@webrtc.org | a092cbf | 2013-02-14 09:28:10 +0000 | [diff] [blame] | 322 | printf("Test number: %d\n", test_cntr_ + 1); |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 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)); |
tina.legrand@webrtc.org | 7a7a008 | 2013-02-21 10:27:48 +0000 | [diff] [blame] | 369 | EXPECT_EQ(0, acm_a_->VAD(&dtx, &vad, &vad_mode)); |
tina.legrand@webrtc.org | 3ddc974 | 2012-06-27 09:25:50 +0000 | [diff] [blame] | 370 | EXPECT_FALSE(dtx); |
| 371 | EXPECT_FALSE(vad); |
| 372 | EXPECT_EQ(-1, acm_a_->SetVAD(true, false, VADNormal)); |
tina.legrand@webrtc.org | 7a7a008 | 2013-02-21 10:27:48 +0000 | [diff] [blame] | 373 | EXPECT_EQ(0, acm_a_->VAD(&dtx, &vad, &vad_mode)); |
tina.legrand@webrtc.org | 3ddc974 | 2012-06-27 09:25:50 +0000 | [diff] [blame] | 374 | EXPECT_FALSE(dtx); |
| 375 | EXPECT_FALSE(vad); |
| 376 | EXPECT_EQ(-1, acm_a_->SetVAD(false, true, VADNormal)); |
tina.legrand@webrtc.org | 7a7a008 | 2013-02-21 10:27:48 +0000 | [diff] [blame] | 377 | EXPECT_EQ(0, acm_a_->VAD(&dtx, &vad, &vad_mode)); |
tina.legrand@webrtc.org | 3ddc974 | 2012-06-27 09:25:50 +0000 | [diff] [blame] | 378 | EXPECT_FALSE(dtx); |
| 379 | EXPECT_FALSE(vad); |
| 380 | EXPECT_EQ(0, acm_a_->SetVAD(false, false, VADNormal)); |
tina.legrand@webrtc.org | 7a7a008 | 2013-02-21 10:27:48 +0000 | [diff] [blame] | 381 | EXPECT_EQ(0, acm_a_->VAD(&dtx, &vad, &vad_mode)); |
tina.legrand@webrtc.org | 3ddc974 | 2012-06-27 09:25:50 +0000 | [diff] [blame] | 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 | 46d90dc | 2013-02-01 14:20:06 +0000 | [diff] [blame] | 415 | if (test_mode_ != 0) { |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 416 | printf("===========================================================\n"); |
tina.legrand@webrtc.org | a092cbf | 2013-02-14 09:28:10 +0000 | [diff] [blame] | 417 | printf("Test number: %d\n", test_cntr_ + 1); |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 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 |
tina.legrand@webrtc.org | 46d90dc | 2013-02-01 14:20:06 +0000 | [diff] [blame] | 438 | if (test_mode_ != 0) { |
tina.legrand@webrtc.org | 0ad3c1a | 2012-11-07 08:07:29 +0000 | [diff] [blame] | 439 | printf("===========================================================\n"); |
tina.legrand@webrtc.org | a092cbf | 2013-02-14 09:28:10 +0000 | [diff] [blame] | 440 | printf("Test number: %d\n", test_cntr_ + 1); |
tina.legrand@webrtc.org | 0ad3c1a | 2012-11-07 08:07:29 +0000 | [diff] [blame] | 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_); |
tina.legrand@webrtc.org | 46d90dc | 2013-02-01 14:20:06 +0000 | [diff] [blame] | 448 | |
tina.legrand@webrtc.org | 0ad3c1a | 2012-11-07 08:07:29 +0000 | [diff] [blame] | 449 | char codec_opus[] = "opus"; |
tina.legrand@webrtc.org | 46d90dc | 2013-02-01 14:20:06 +0000 | [diff] [blame] | 450 | // Run Opus with 10 ms frame size. |
| 451 | RegisterSendCodec('A', codec_opus, 48000, 64000, 480, codec_channels, |
tina.legrand@webrtc.org | 0ad3c1a | 2012-11-07 08:07:29 +0000 | [diff] [blame] | 452 | opus_pltype_); |
| 453 | Run(channel_a2b_, audio_channels, codec_channels); |
tina.legrand@webrtc.org | 46d90dc | 2013-02-01 14:20:06 +0000 | [diff] [blame] | 454 | // Run Opus with 20 ms frame size. |
| 455 | RegisterSendCodec('A', codec_opus, 48000, 64000, 480*2, codec_channels, |
| 456 | opus_pltype_); |
| 457 | Run(channel_a2b_, audio_channels, codec_channels); |
| 458 | // Run Opus with 40 ms frame size. |
| 459 | RegisterSendCodec('A', codec_opus, 48000, 64000, 480*4, codec_channels, |
| 460 | opus_pltype_); |
| 461 | Run(channel_a2b_, audio_channels, codec_channels); |
| 462 | // Run Opus with 60 ms frame size. |
| 463 | RegisterSendCodec('A', codec_opus, 48000, 64000, 480*6, codec_channels, |
| 464 | opus_pltype_); |
| 465 | Run(channel_a2b_, audio_channels, codec_channels); |
| 466 | // Run Opus with 20 ms frame size and different bitrates. |
| 467 | RegisterSendCodec('A', codec_opus, 48000, 40000, 960, codec_channels, |
tina.legrand@webrtc.org | 0ad3c1a | 2012-11-07 08:07:29 +0000 | [diff] [blame] | 468 | opus_pltype_); |
| 469 | Run(channel_a2b_, audio_channels, codec_channels); |
| 470 | RegisterSendCodec('A', codec_opus, 48000, 510000, 960, codec_channels, |
| 471 | opus_pltype_); |
| 472 | Run(channel_a2b_, audio_channels, codec_channels); |
| 473 | out_file_.Close(); |
| 474 | #endif |
tina.legrand@webrtc.org | 6b6ff55 | 2012-01-11 10:12:54 +0000 | [diff] [blame] | 475 | // |
| 476 | // Test Mono-To-Stereo for all codecs. |
| 477 | // |
| 478 | audio_channels = 1; |
| 479 | codec_channels = 2; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 480 | |
tina.legrand@webrtc.org | 6b6ff55 | 2012-01-11 10:12:54 +0000 | [diff] [blame] | 481 | #ifdef WEBRTC_CODEC_G722 |
tina.legrand@webrtc.org | 46d90dc | 2013-02-01 14:20:06 +0000 | [diff] [blame] | 482 | if (test_mode_ != 0) { |
tina.legrand@webrtc.org | 6b6ff55 | 2012-01-11 10:12:54 +0000 | [diff] [blame] | 483 | printf("===============================================================\n"); |
tina.legrand@webrtc.org | a092cbf | 2013-02-14 09:28:10 +0000 | [diff] [blame] | 484 | printf("Test number: %d\n", test_cntr_ + 1); |
tina.legrand@webrtc.org | 6b6ff55 | 2012-01-11 10:12:54 +0000 | [diff] [blame] | 485 | printf("Test type: Mono-to-stereo\n"); |
| 486 | } |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 487 | test_cntr_++; |
| 488 | channel_a2b_->set_codec_mode(kStereo); |
| 489 | OpenOutFile(test_cntr_); |
| 490 | RegisterSendCodec('A', codec_g722, 16000, 64000, 160, codec_channels, |
tina.legrand@webrtc.org | ae1c454 | 2012-03-12 08:41:30 +0000 | [diff] [blame] | 491 | g722_pltype_); |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 492 | Run(channel_a2b_, audio_channels, codec_channels); |
| 493 | out_file_.Close(); |
tina.legrand@webrtc.org | 6b6ff55 | 2012-01-11 10:12:54 +0000 | [diff] [blame] | 494 | #endif |
| 495 | #ifdef WEBRTC_CODEC_PCM16 |
tina.legrand@webrtc.org | 46d90dc | 2013-02-01 14:20:06 +0000 | [diff] [blame] | 496 | if (test_mode_ != 0) { |
tina.legrand@webrtc.org | 6b6ff55 | 2012-01-11 10:12:54 +0000 | [diff] [blame] | 497 | printf("===============================================================\n"); |
tina.legrand@webrtc.org | a092cbf | 2013-02-14 09:28:10 +0000 | [diff] [blame] | 498 | printf("Test number: %d\n", test_cntr_ + 1); |
tina.legrand@webrtc.org | 6b6ff55 | 2012-01-11 10:12:54 +0000 | [diff] [blame] | 499 | printf("Test type: Mono-to-stereo\n"); |
| 500 | } |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 501 | test_cntr_++; |
| 502 | channel_a2b_->set_codec_mode(kStereo); |
| 503 | OpenOutFile(test_cntr_); |
| 504 | RegisterSendCodec('A', codec_l16, 8000, 128000, 80, codec_channels, |
tina.legrand@webrtc.org | ae1c454 | 2012-03-12 08:41:30 +0000 | [diff] [blame] | 505 | l16_8khz_pltype_); |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 506 | Run(channel_a2b_, audio_channels, codec_channels); |
| 507 | out_file_.Close(); |
tina.legrand@webrtc.org | 46d90dc | 2013-02-01 14:20:06 +0000 | [diff] [blame] | 508 | if (test_mode_ != 0) { |
tina.legrand@webrtc.org | 6b6ff55 | 2012-01-11 10:12:54 +0000 | [diff] [blame] | 509 | printf("===============================================================\n"); |
tina.legrand@webrtc.org | a092cbf | 2013-02-14 09:28:10 +0000 | [diff] [blame] | 510 | printf("Test number: %d\n", test_cntr_ + 1); |
tina.legrand@webrtc.org | 6b6ff55 | 2012-01-11 10:12:54 +0000 | [diff] [blame] | 511 | printf("Test type: Mono-to-stereo\n"); |
| 512 | } |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 513 | test_cntr_++; |
| 514 | OpenOutFile(test_cntr_); |
| 515 | RegisterSendCodec('A', codec_l16, 16000, 256000, 160, codec_channels, |
tina.legrand@webrtc.org | ae1c454 | 2012-03-12 08:41:30 +0000 | [diff] [blame] | 516 | l16_16khz_pltype_); |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 517 | Run(channel_a2b_, audio_channels, codec_channels); |
| 518 | out_file_.Close(); |
tina.legrand@webrtc.org | 46d90dc | 2013-02-01 14:20:06 +0000 | [diff] [blame] | 519 | if (test_mode_ != 0) { |
tina.legrand@webrtc.org | 6b6ff55 | 2012-01-11 10:12:54 +0000 | [diff] [blame] | 520 | printf("===============================================================\n"); |
tina.legrand@webrtc.org | a092cbf | 2013-02-14 09:28:10 +0000 | [diff] [blame] | 521 | printf("Test number: %d\n", test_cntr_ + 1); |
tina.legrand@webrtc.org | 6b6ff55 | 2012-01-11 10:12:54 +0000 | [diff] [blame] | 522 | printf("Test type: Mono-to-stereo\n"); |
| 523 | } |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 524 | test_cntr_++; |
| 525 | OpenOutFile(test_cntr_); |
| 526 | RegisterSendCodec('A', codec_l16, 32000, 512000, 320, codec_channels, |
tina.legrand@webrtc.org | ae1c454 | 2012-03-12 08:41:30 +0000 | [diff] [blame] | 527 | l16_32khz_pltype_); |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 528 | Run(channel_a2b_, audio_channels, codec_channels); |
| 529 | out_file_.Close(); |
tina.legrand@webrtc.org | 6b6ff55 | 2012-01-11 10:12:54 +0000 | [diff] [blame] | 530 | #endif |
| 531 | #ifdef PCMA_AND_PCMU |
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: Mono-to-stereo\n"); |
| 536 | } |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 537 | test_cntr_++; |
| 538 | channel_a2b_->set_codec_mode(kStereo); |
| 539 | OpenOutFile(test_cntr_); |
| 540 | RegisterSendCodec('A', codec_pcmu, 8000, 64000, 80, codec_channels, |
tina.legrand@webrtc.org | ae1c454 | 2012-03-12 08:41:30 +0000 | [diff] [blame] | 541 | pcmu_pltype_); |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 542 | Run(channel_a2b_, audio_channels, codec_channels); |
| 543 | RegisterSendCodec('A', codec_pcma, 8000, 64000, 80, codec_channels, |
tina.legrand@webrtc.org | ae1c454 | 2012-03-12 08:41:30 +0000 | [diff] [blame] | 544 | pcma_pltype_); |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 545 | Run(channel_a2b_, audio_channels, codec_channels); |
| 546 | out_file_.Close(); |
tina.legrand@webrtc.org | 6b6ff55 | 2012-01-11 10:12:54 +0000 | [diff] [blame] | 547 | #endif |
tina.legrand@webrtc.org | df69775 | 2012-02-08 10:22:21 +0000 | [diff] [blame] | 548 | #ifdef WEBRTC_CODEC_CELT |
tina.legrand@webrtc.org | 46d90dc | 2013-02-01 14:20:06 +0000 | [diff] [blame] | 549 | if (test_mode_ != 0) { |
tina.legrand@webrtc.org | df69775 | 2012-02-08 10:22:21 +0000 | [diff] [blame] | 550 | printf("===============================================================\n"); |
tina.legrand@webrtc.org | a092cbf | 2013-02-14 09:28:10 +0000 | [diff] [blame] | 551 | printf("Test number: %d\n", test_cntr_ + 1); |
tina.legrand@webrtc.org | df69775 | 2012-02-08 10:22:21 +0000 | [diff] [blame] | 552 | printf("Test type: Mono-to-stereo\n"); |
| 553 | } |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 554 | test_cntr_++; |
| 555 | channel_a2b_->set_codec_mode(kStereo); |
| 556 | OpenOutFile(test_cntr_); |
tina.legrand@webrtc.org | 90af7f8 | 2012-06-07 08:57:27 +0000 | [diff] [blame] | 557 | RegisterSendCodec('A', codec_celt, 32000, 64000, 640, codec_channels, |
tina.legrand@webrtc.org | ae1c454 | 2012-03-12 08:41:30 +0000 | [diff] [blame] | 558 | celt_pltype_); |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 559 | Run(channel_a2b_, audio_channels, codec_channels); |
| 560 | out_file_.Close(); |
tina.legrand@webrtc.org | df69775 | 2012-02-08 10:22:21 +0000 | [diff] [blame] | 561 | #endif |
tina.legrand@webrtc.org | 0ad3c1a | 2012-11-07 08:07:29 +0000 | [diff] [blame] | 562 | #ifdef WEBRTC_CODEC_OPUS |
tina.legrand@webrtc.org | 46d90dc | 2013-02-01 14:20:06 +0000 | [diff] [blame] | 563 | if (test_mode_ != 0) { |
tina.legrand@webrtc.org | 0ad3c1a | 2012-11-07 08:07:29 +0000 | [diff] [blame] | 564 | printf("===============================================================\n"); |
tina.legrand@webrtc.org | a092cbf | 2013-02-14 09:28:10 +0000 | [diff] [blame] | 565 | printf("Test number: %d\n", test_cntr_ + 1); |
tina.legrand@webrtc.org | 0ad3c1a | 2012-11-07 08:07:29 +0000 | [diff] [blame] | 566 | printf("Test type: Mono-to-stereo\n"); |
| 567 | } |
tina.legrand@webrtc.org | c459058 | 2012-11-28 12:23:29 +0000 | [diff] [blame] | 568 | |
| 569 | // Keep encode and decode in stereo. |
tina.legrand@webrtc.org | 0ad3c1a | 2012-11-07 08:07:29 +0000 | [diff] [blame] | 570 | test_cntr_++; |
| 571 | channel_a2b_->set_codec_mode(kStereo); |
| 572 | OpenOutFile(test_cntr_); |
| 573 | RegisterSendCodec('A', codec_opus, 48000, 64000, 960, codec_channels, |
| 574 | opus_pltype_); |
| 575 | Run(channel_a2b_, audio_channels, codec_channels); |
tina.legrand@webrtc.org | c459058 | 2012-11-28 12:23:29 +0000 | [diff] [blame] | 576 | |
| 577 | // Encode in mono, decode in stereo mode. |
| 578 | RegisterSendCodec('A', codec_opus, 48000, 64000, 960, 1, opus_pltype_); |
| 579 | Run(channel_a2b_, audio_channels, codec_channels); |
tina.legrand@webrtc.org | 0ad3c1a | 2012-11-07 08:07:29 +0000 | [diff] [blame] | 580 | out_file_.Close(); |
| 581 | #endif |
tina.legrand@webrtc.org | 6b6ff55 | 2012-01-11 10:12:54 +0000 | [diff] [blame] | 582 | |
| 583 | // |
| 584 | // Test Stereo-To-Mono for all codecs. |
| 585 | // |
| 586 | audio_channels = 2; |
| 587 | codec_channels = 1; |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 588 | channel_a2b_->set_codec_mode(kMono); |
tina.legrand@webrtc.org | 6b6ff55 | 2012-01-11 10:12:54 +0000 | [diff] [blame] | 589 | |
tina.legrand@webrtc.org | 6b6ff55 | 2012-01-11 10:12:54 +0000 | [diff] [blame] | 590 | #ifdef WEBRTC_CODEC_G722 |
| 591 | // Run stereo audio and mono codec. |
tina.legrand@webrtc.org | 46d90dc | 2013-02-01 14:20:06 +0000 | [diff] [blame] | 592 | if (test_mode_ != 0) { |
tina.legrand@webrtc.org | 6b6ff55 | 2012-01-11 10:12:54 +0000 | [diff] [blame] | 593 | printf("===============================================================\n"); |
tina.legrand@webrtc.org | a092cbf | 2013-02-14 09:28:10 +0000 | [diff] [blame] | 594 | printf("Test number: %d\n", test_cntr_ + 1); |
tina.legrand@webrtc.org | 6b6ff55 | 2012-01-11 10:12:54 +0000 | [diff] [blame] | 595 | printf("Test type: Stereo-to-mono\n"); |
| 596 | } |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 597 | test_cntr_++; |
| 598 | OpenOutFile(test_cntr_); |
| 599 | RegisterSendCodec('A', codec_g722, 16000, 64000, 160, codec_channels, |
tina.legrand@webrtc.org | ae1c454 | 2012-03-12 08:41:30 +0000 | [diff] [blame] | 600 | g722_pltype_); |
tina.legrand@webrtc.org | 3ddc974 | 2012-06-27 09:25:50 +0000 | [diff] [blame] | 601 | |
| 602 | |
| 603 | // Make sure it is possible to set VAD/CNG, now that we are sending mono |
| 604 | // again. |
| 605 | EXPECT_EQ(0, acm_a_->SetVAD(true, true, VADNormal)); |
tina.legrand@webrtc.org | 7a7a008 | 2013-02-21 10:27:48 +0000 | [diff] [blame] | 606 | EXPECT_EQ(0, acm_a_->VAD(&dtx, &vad, &vad_mode)); |
tina.legrand@webrtc.org | 3ddc974 | 2012-06-27 09:25:50 +0000 | [diff] [blame] | 607 | EXPECT_TRUE(dtx); |
| 608 | EXPECT_TRUE(vad); |
| 609 | EXPECT_EQ(0, acm_a_->SetVAD(false, false, VADNormal)); |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 610 | Run(channel_a2b_, audio_channels, codec_channels); |
| 611 | out_file_.Close(); |
tina.legrand@webrtc.org | 6b6ff55 | 2012-01-11 10:12:54 +0000 | [diff] [blame] | 612 | #endif |
| 613 | #ifdef WEBRTC_CODEC_PCM16 |
tina.legrand@webrtc.org | 46d90dc | 2013-02-01 14:20:06 +0000 | [diff] [blame] | 614 | if (test_mode_ != 0) { |
tina.legrand@webrtc.org | 6b6ff55 | 2012-01-11 10:12:54 +0000 | [diff] [blame] | 615 | printf("===============================================================\n"); |
tina.legrand@webrtc.org | a092cbf | 2013-02-14 09:28:10 +0000 | [diff] [blame] | 616 | printf("Test number: %d\n", test_cntr_ + 1); |
tina.legrand@webrtc.org | 6b6ff55 | 2012-01-11 10:12:54 +0000 | [diff] [blame] | 617 | printf("Test type: Stereo-to-mono\n"); |
| 618 | } |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 619 | test_cntr_++; |
| 620 | OpenOutFile(test_cntr_); |
| 621 | RegisterSendCodec('A', codec_l16, 8000, 128000, 80, codec_channels, |
tina.legrand@webrtc.org | ae1c454 | 2012-03-12 08:41:30 +0000 | [diff] [blame] | 622 | l16_8khz_pltype_); |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 623 | Run(channel_a2b_, audio_channels, codec_channels); |
| 624 | out_file_.Close(); |
tina.legrand@webrtc.org | 46d90dc | 2013-02-01 14:20:06 +0000 | [diff] [blame] | 625 | if (test_mode_ != 0) { |
tina.legrand@webrtc.org | 6b6ff55 | 2012-01-11 10:12:54 +0000 | [diff] [blame] | 626 | printf("===============================================================\n"); |
tina.legrand@webrtc.org | a092cbf | 2013-02-14 09:28:10 +0000 | [diff] [blame] | 627 | printf("Test number: %d\n", test_cntr_ + 1); |
tina.legrand@webrtc.org | 6b6ff55 | 2012-01-11 10:12:54 +0000 | [diff] [blame] | 628 | printf("Test type: Stereo-to-mono\n"); |
tina.legrand@webrtc.org | a092cbf | 2013-02-14 09:28:10 +0000 | [diff] [blame] | 629 | } |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 630 | test_cntr_++; |
| 631 | OpenOutFile(test_cntr_); |
| 632 | RegisterSendCodec('A', codec_l16, 16000, 256000, 160, codec_channels, |
tina.legrand@webrtc.org | ae1c454 | 2012-03-12 08:41:30 +0000 | [diff] [blame] | 633 | l16_16khz_pltype_); |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 634 | Run(channel_a2b_, audio_channels, codec_channels); |
| 635 | out_file_.Close(); |
tina.legrand@webrtc.org | 46d90dc | 2013-02-01 14:20:06 +0000 | [diff] [blame] | 636 | if (test_mode_ != 0) { |
tina.legrand@webrtc.org | 16b6b90 | 2012-04-12 11:02:38 +0000 | [diff] [blame] | 637 | printf("==============================================================\n"); |
tina.legrand@webrtc.org | a092cbf | 2013-02-14 09:28:10 +0000 | [diff] [blame] | 638 | printf("Test number: %d\n", test_cntr_ + 1); |
tina.legrand@webrtc.org | df69775 | 2012-02-08 10:22:21 +0000 | [diff] [blame] | 639 | printf("Test type: Stereo-to-mono\n"); |
tina.legrand@webrtc.org | a092cbf | 2013-02-14 09:28:10 +0000 | [diff] [blame] | 640 | } |
| 641 | test_cntr_++; |
| 642 | OpenOutFile(test_cntr_); |
| 643 | RegisterSendCodec('A', codec_l16, 32000, 512000, 320, codec_channels, |
| 644 | l16_32khz_pltype_); |
| 645 | Run(channel_a2b_, audio_channels, codec_channels); |
| 646 | out_file_.Close(); |
tina.legrand@webrtc.org | 6b6ff55 | 2012-01-11 10:12:54 +0000 | [diff] [blame] | 647 | #endif |
| 648 | #ifdef PCMA_AND_PCMU |
tina.legrand@webrtc.org | 46d90dc | 2013-02-01 14:20:06 +0000 | [diff] [blame] | 649 | if (test_mode_ != 0) { |
tina.legrand@webrtc.org | 6b6ff55 | 2012-01-11 10:12:54 +0000 | [diff] [blame] | 650 | printf("===============================================================\n"); |
tina.legrand@webrtc.org | a092cbf | 2013-02-14 09:28:10 +0000 | [diff] [blame] | 651 | printf("Test number: %d\n", test_cntr_ + 1); |
tina.legrand@webrtc.org | df69775 | 2012-02-08 10:22:21 +0000 | [diff] [blame] | 652 | printf("Test type: Stereo-to-mono\n"); |
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 | test_cntr_++; |
| 655 | OpenOutFile(test_cntr_); |
| 656 | RegisterSendCodec('A', codec_pcmu, 8000, 64000, 80, codec_channels, |
tina.legrand@webrtc.org | ae1c454 | 2012-03-12 08:41:30 +0000 | [diff] [blame] | 657 | pcmu_pltype_); |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 658 | Run(channel_a2b_, audio_channels, codec_channels); |
| 659 | RegisterSendCodec('A', codec_pcma, 8000, 64000, 80, codec_channels, |
tina.legrand@webrtc.org | ae1c454 | 2012-03-12 08:41:30 +0000 | [diff] [blame] | 660 | pcma_pltype_); |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 661 | Run(channel_a2b_, audio_channels, codec_channels); |
| 662 | out_file_.Close(); |
tina.legrand@webrtc.org | 6b6ff55 | 2012-01-11 10:12:54 +0000 | [diff] [blame] | 663 | #endif |
tina.legrand@webrtc.org | df69775 | 2012-02-08 10:22:21 +0000 | [diff] [blame] | 664 | #ifdef WEBRTC_CODEC_CELT |
tina.legrand@webrtc.org | 46d90dc | 2013-02-01 14:20:06 +0000 | [diff] [blame] | 665 | if (test_mode_ != 0) { |
tina.legrand@webrtc.org | df69775 | 2012-02-08 10:22:21 +0000 | [diff] [blame] | 666 | printf("===============================================================\n"); |
tina.legrand@webrtc.org | a092cbf | 2013-02-14 09:28:10 +0000 | [diff] [blame] | 667 | printf("Test number: %d\n", test_cntr_ + 1); |
tina.legrand@webrtc.org | df69775 | 2012-02-08 10:22:21 +0000 | [diff] [blame] | 668 | printf("Test type: Stereo-to-mono\n"); |
| 669 | } |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 670 | test_cntr_++; |
| 671 | OpenOutFile(test_cntr_); |
tina.legrand@webrtc.org | 90af7f8 | 2012-06-07 08:57:27 +0000 | [diff] [blame] | 672 | RegisterSendCodec('A', codec_celt, 32000, 64000, 640, codec_channels, |
tina.legrand@webrtc.org | ae1c454 | 2012-03-12 08:41:30 +0000 | [diff] [blame] | 673 | celt_pltype_); |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 674 | Run(channel_a2b_, audio_channels, codec_channels); |
| 675 | out_file_.Close(); |
tina.legrand@webrtc.org | df69775 | 2012-02-08 10:22:21 +0000 | [diff] [blame] | 676 | #endif |
tina.legrand@webrtc.org | 0ad3c1a | 2012-11-07 08:07:29 +0000 | [diff] [blame] | 677 | #ifdef WEBRTC_CODEC_OPUS |
tina.legrand@webrtc.org | 46d90dc | 2013-02-01 14:20:06 +0000 | [diff] [blame] | 678 | if (test_mode_ != 0) { |
tina.legrand@webrtc.org | 0ad3c1a | 2012-11-07 08:07:29 +0000 | [diff] [blame] | 679 | printf("===============================================================\n"); |
tina.legrand@webrtc.org | a092cbf | 2013-02-14 09:28:10 +0000 | [diff] [blame] | 680 | printf("Test number: %d\n", test_cntr_ + 1); |
tina.legrand@webrtc.org | 0ad3c1a | 2012-11-07 08:07:29 +0000 | [diff] [blame] | 681 | printf("Test type: Stereo-to-mono\n"); |
| 682 | } |
| 683 | test_cntr_++; |
| 684 | OpenOutFile(test_cntr_); |
tina.legrand@webrtc.org | c459058 | 2012-11-28 12:23:29 +0000 | [diff] [blame] | 685 | // Encode and decode in mono. |
tina.legrand@webrtc.org | 0ad3c1a | 2012-11-07 08:07:29 +0000 | [diff] [blame] | 686 | RegisterSendCodec('A', codec_opus, 48000, 32000, 960, codec_channels, |
| 687 | opus_pltype_); |
tina.legrand@webrtc.org | c459058 | 2012-11-28 12:23:29 +0000 | [diff] [blame] | 688 | CodecInst opus_codec_param; |
pbos@webrtc.org | 0946a56 | 2013-04-09 00:28:06 +0000 | [diff] [blame] | 689 | for (uint8_t n = 0; n < num_encoders; n++) { |
tina.legrand@webrtc.org | 7a7a008 | 2013-02-21 10:27:48 +0000 | [diff] [blame] | 690 | EXPECT_EQ(0, acm_b_->Codec(n, &opus_codec_param)); |
tina.legrand@webrtc.org | c459058 | 2012-11-28 12:23:29 +0000 | [diff] [blame] | 691 | if (!strcmp(opus_codec_param.plname, "opus")) { |
| 692 | opus_codec_param.channels = 1; |
| 693 | EXPECT_EQ(0, acm_b_->RegisterReceiveCodec(opus_codec_param)); |
| 694 | break; |
| 695 | } |
| 696 | } |
| 697 | Run(channel_a2b_, audio_channels, codec_channels); |
| 698 | |
| 699 | // Encode in stereo, decode in mono. |
| 700 | RegisterSendCodec('A', codec_opus, 48000, 32000, 960, 2, opus_pltype_); |
| 701 | Run(channel_a2b_, audio_channels, codec_channels); |
| 702 | |
| 703 | out_file_.Close(); |
| 704 | |
| 705 | // Test switching between decoding mono and stereo for Opus. |
| 706 | |
| 707 | // Decode in mono. |
| 708 | test_cntr_++; |
| 709 | OpenOutFile(test_cntr_); |
| 710 | if (test_mode_ != 0) { |
| 711 | // Print out codec and settings |
| 712 | printf("Test number: %d\nCodec: Opus Freq: 48000 Rate :32000 PackSize: 960" |
| 713 | " Decode: mono\n", test_cntr_); |
| 714 | } |
tina.legrand@webrtc.org | 0ad3c1a | 2012-11-07 08:07:29 +0000 | [diff] [blame] | 715 | Run(channel_a2b_, audio_channels, codec_channels); |
| 716 | out_file_.Close(); |
tina.legrand@webrtc.org | c459058 | 2012-11-28 12:23:29 +0000 | [diff] [blame] | 717 | // Decode in stereo. |
| 718 | test_cntr_++; |
| 719 | OpenOutFile(test_cntr_); |
| 720 | if (test_mode_ != 0) { |
| 721 | // Print out codec and settings |
| 722 | printf("Test number: %d\nCodec: Opus Freq: 48000 Rate :32000 PackSize: 960" |
| 723 | " Decode: stereo\n", test_cntr_); |
| 724 | } |
| 725 | opus_codec_param.channels = 2; |
| 726 | EXPECT_EQ(0, acm_b_->RegisterReceiveCodec(opus_codec_param)); |
| 727 | Run(channel_a2b_, audio_channels, 2); |
| 728 | out_file_.Close(); |
| 729 | // Decode in mono. |
| 730 | test_cntr_++; |
| 731 | OpenOutFile(test_cntr_); |
| 732 | if (test_mode_ != 0) { |
| 733 | // Print out codec and settings |
| 734 | printf("Test number: %d\nCodec: Opus Freq: 48000 Rate :32000 PackSize: 960" |
| 735 | " Decode: mono\n", test_cntr_); |
| 736 | } |
| 737 | opus_codec_param.channels = 1; |
| 738 | EXPECT_EQ(0, acm_b_->RegisterReceiveCodec(opus_codec_param)); |
| 739 | Run(channel_a2b_, audio_channels, codec_channels); |
| 740 | out_file_.Close(); |
| 741 | |
tina.legrand@webrtc.org | 0ad3c1a | 2012-11-07 08:07:29 +0000 | [diff] [blame] | 742 | #endif |
tina.legrand@webrtc.org | 6b6ff55 | 2012-01-11 10:12:54 +0000 | [diff] [blame] | 743 | |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 744 | // Print out which codecs were tested, and which were not, in the run. |
| 745 | if (test_mode_ != 0) { |
| 746 | printf("\nThe following codecs was INCLUDED in the test:\n"); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 747 | #ifdef WEBRTC_CODEC_G722 |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 748 | printf(" G.722\n"); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 749 | #endif |
| 750 | #ifdef WEBRTC_CODEC_PCM16 |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 751 | printf(" PCM16\n"); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 752 | #endif |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 753 | printf(" G.711\n"); |
tina.legrand@webrtc.org | 3ddc974 | 2012-06-27 09:25:50 +0000 | [diff] [blame] | 754 | #ifdef WEBRTC_CODEC_CELT |
| 755 | printf(" CELT\n"); |
| 756 | #endif |
tina.legrand@webrtc.org | c459058 | 2012-11-28 12:23:29 +0000 | [diff] [blame] | 757 | #ifdef WEBRTC_CODEC_OPUS |
| 758 | printf(" Opus\n"); |
| 759 | #endif |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 760 | printf("\nTo complete the test, listen to the %d number of output " |
| 761 | "files.\n", |
| 762 | test_cntr_); |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 763 | } |
| 764 | |
| 765 | // Delete the file pointers. |
| 766 | delete in_file_stereo_; |
| 767 | delete in_file_mono_; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 768 | } |
| 769 | |
| 770 | // Register Codec to use in the test |
| 771 | // |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 772 | // Input: side - which ACM to use, 'A' or 'B' |
| 773 | // codec_name - name to use when register the codec |
| 774 | // sampling_freq_hz - sampling frequency in Herz |
| 775 | // rate - bitrate in bytes |
| 776 | // pack_size - packet size in samples |
| 777 | // channels - number of channels; 1 for mono, 2 for stereo |
| 778 | // payload_type - payload type for the codec |
tina.legrand@webrtc.org | 3ddc974 | 2012-06-27 09:25:50 +0000 | [diff] [blame] | 779 | void TestStereo::RegisterSendCodec(char side, char* codec_name, |
pbos@webrtc.org | 0946a56 | 2013-04-09 00:28:06 +0000 | [diff] [blame] | 780 | int32_t sampling_freq_hz, int rate, |
tina.legrand@webrtc.org | 3ddc974 | 2012-06-27 09:25:50 +0000 | [diff] [blame] | 781 | int pack_size, int channels, |
| 782 | int payload_type) { |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 783 | if (test_mode_ != 0) { |
| 784 | // Print out codec and settings |
tina.legrand@webrtc.org | ba46804 | 2012-08-17 10:38:28 +0000 | [diff] [blame] | 785 | 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] | 786 | sampling_freq_hz, rate, pack_size); |
| 787 | } |
| 788 | |
| 789 | // Store packet size in samples, used to validate the received packet |
| 790 | pack_size_samp_ = pack_size; |
| 791 | |
| 792 | // Store the expected packet size in bytes, used to validate the received |
| 793 | // packet. Add 0.875 to always round up to a whole byte. |
| 794 | // For Celt the packet size in bytes is already counting the stereo part. |
| 795 | if (!strcmp(codec_name, "CELT")) { |
pbos@webrtc.org | 0946a56 | 2013-04-09 00:28:06 +0000 | [diff] [blame] | 796 | pack_size_bytes_ = (uint16_t)( |
tina.legrand@webrtc.org | a092cbf | 2013-02-14 09:28:10 +0000 | [diff] [blame] | 797 | static_cast<float>(pack_size * rate) / |
| 798 | static_cast<float>(sampling_freq_hz * 8) + 0.875) |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 799 | / channels; |
| 800 | } else { |
pbos@webrtc.org | 0946a56 | 2013-04-09 00:28:06 +0000 | [diff] [blame] | 801 | pack_size_bytes_ = (uint16_t)( |
tina.legrand@webrtc.org | a092cbf | 2013-02-14 09:28:10 +0000 | [diff] [blame] | 802 | static_cast<float>(pack_size * rate) / |
| 803 | static_cast<float>(sampling_freq_hz * 8) + 0.875); |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 804 | } |
| 805 | |
| 806 | // Set pointer to the ACM where to register the codec |
tina.legrand@webrtc.org | 3ddc974 | 2012-06-27 09:25:50 +0000 | [diff] [blame] | 807 | AudioCodingModule* my_acm = NULL; |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 808 | switch (side) { |
| 809 | case 'A': { |
| 810 | my_acm = acm_a_; |
| 811 | break; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 812 | } |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 813 | case 'B': { |
| 814 | my_acm = acm_b_; |
| 815 | break; |
tina.legrand@webrtc.org | 16b6b90 | 2012-04-12 11:02:38 +0000 | [diff] [blame] | 816 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 817 | default: |
tina.legrand@webrtc.org | 3ddc974 | 2012-06-27 09:25:50 +0000 | [diff] [blame] | 818 | break; |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 819 | } |
tina.legrand@webrtc.org | 3ddc974 | 2012-06-27 09:25:50 +0000 | [diff] [blame] | 820 | ASSERT_TRUE(my_acm != NULL); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 821 | |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 822 | CodecInst my_codec_param; |
| 823 | // Get all codec parameters before registering |
tina.legrand@webrtc.org | 7a7a008 | 2013-02-21 10:27:48 +0000 | [diff] [blame] | 824 | CHECK_ERROR(AudioCodingModule::Codec(codec_name, &my_codec_param, |
tina.legrand@webrtc.org | 4517585 | 2012-06-01 09:27:35 +0000 | [diff] [blame] | 825 | sampling_freq_hz, channels)); |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 826 | my_codec_param.rate = rate; |
| 827 | my_codec_param.pacsize = pack_size; |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 828 | CHECK_ERROR(my_acm->RegisterSendCodec(my_codec_param)); |
tina.legrand@webrtc.org | 0ad3c1a | 2012-11-07 08:07:29 +0000 | [diff] [blame] | 829 | |
| 830 | send_codec_name_ = codec_name; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 831 | } |
| 832 | |
tina.legrand@webrtc.org | 16b6b90 | 2012-04-12 11:02:38 +0000 | [diff] [blame] | 833 | void TestStereo::Run(TestPackStereo* channel, int in_channels, int out_channels, |
| 834 | int percent_loss) { |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 835 | AudioFrame audio_frame; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 836 | |
pbos@webrtc.org | 0946a56 | 2013-04-09 00:28:06 +0000 | [diff] [blame] | 837 | int32_t out_freq_hz_b = out_file_.SamplingFrequency(); |
| 838 | uint16_t rec_size; |
| 839 | uint32_t time_stamp_diff; |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 840 | channel->reset_payload_size(); |
| 841 | int error_count = 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 842 | |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 843 | while (1) { |
| 844 | // Simulate packet loss by setting |packet_loss_| to "true" in |
| 845 | // |percent_loss| percent of the loops. |
| 846 | if (percent_loss > 0) { |
| 847 | if (counter_ == floor((100 / percent_loss) + 0.5)) { |
| 848 | counter_ = 0; |
| 849 | channel->set_lost_packet(true); |
| 850 | } else { |
| 851 | channel->set_lost_packet(false); |
| 852 | } |
| 853 | counter_++; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 854 | } |
| 855 | |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 856 | // Add 10 msec to ACM |
| 857 | if (in_channels == 1) { |
| 858 | if (in_file_mono_->EndOfFile()) { |
| 859 | break; |
| 860 | } |
| 861 | in_file_mono_->Read10MsData(audio_frame); |
| 862 | } else { |
| 863 | if (in_file_stereo_->EndOfFile()) { |
| 864 | break; |
| 865 | } |
| 866 | in_file_stereo_->Read10MsData(audio_frame); |
| 867 | } |
| 868 | CHECK_ERROR(acm_a_->Add10MsData(audio_frame)); |
| 869 | |
| 870 | // Run sender side of ACM |
| 871 | CHECK_ERROR(acm_a_->Process()); |
| 872 | |
| 873 | // Verify that the received packet size matches the settings |
| 874 | rec_size = channel->payload_size(); |
| 875 | if ((0 < rec_size) & (rec_size < 65535)) { |
tina.legrand@webrtc.org | 0ad3c1a | 2012-11-07 08:07:29 +0000 | [diff] [blame] | 876 | // Opus is variable rate, skip this test. |
| 877 | if (strcmp(send_codec_name_, "opus")) { |
| 878 | if ((rec_size != pack_size_bytes_ * out_channels) |
| 879 | && (pack_size_bytes_ < 65535)) { |
| 880 | error_count++; |
| 881 | } |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 882 | } |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 883 | // Verify that the timestamp is updated with expected length |
| 884 | time_stamp_diff = channel->timestamp_diff(); |
| 885 | if ((counter_ > 10) && (time_stamp_diff != pack_size_samp_)) { |
| 886 | error_count++; |
| 887 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 888 | } |
| 889 | |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 890 | // Run received side of ACM |
tina.legrand@webrtc.org | 7a7a008 | 2013-02-21 10:27:48 +0000 | [diff] [blame] | 891 | CHECK_ERROR(acm_b_->PlayoutData10Ms(out_freq_hz_b, &audio_frame)); |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 892 | |
| 893 | // Write output speech to file |
| 894 | out_file_.Write10MsData( |
andrew@webrtc.org | 63a5098 | 2012-05-02 23:56:37 +0000 | [diff] [blame] | 895 | audio_frame.data_, |
| 896 | audio_frame.samples_per_channel_ * audio_frame.num_channels_); |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 897 | } |
| 898 | |
tina.legrand@webrtc.org | 3ddc974 | 2012-06-27 09:25:50 +0000 | [diff] [blame] | 899 | EXPECT_EQ(0, error_count); |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 900 | |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 901 | if (in_file_mono_->EndOfFile()) { |
| 902 | in_file_mono_->Rewind(); |
| 903 | } |
| 904 | if (in_file_stereo_->EndOfFile()) { |
| 905 | in_file_stereo_->Rewind(); |
| 906 | } |
| 907 | // Reset in case we ended with a lost packet |
| 908 | channel->set_lost_packet(false); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 909 | } |
| 910 | |
pbos@webrtc.org | 0946a56 | 2013-04-09 00:28:06 +0000 | [diff] [blame] | 911 | void TestStereo::OpenOutFile(int16_t test_number) { |
tina.legrand@webrtc.org | ba46804 | 2012-08-17 10:38:28 +0000 | [diff] [blame] | 912 | std::string file_name; |
| 913 | std::stringstream file_stream; |
| 914 | file_stream << webrtc::test::OutputPath() << "teststereo_out_" |
| 915 | << test_number << ".pcm"; |
| 916 | file_name = file_stream.str(); |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 917 | out_file_.Open(file_name, 32000, "wb"); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 918 | } |
| 919 | |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 920 | void TestStereo::DisplaySendReceiveCodec() { |
| 921 | CodecInst my_codec_param; |
tina.legrand@webrtc.org | 7a7a008 | 2013-02-21 10:27:48 +0000 | [diff] [blame] | 922 | acm_a_->SendCodec(&my_codec_param); |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 923 | if (test_mode_ != 0) { |
| 924 | printf("%s -> ", my_codec_param.plname); |
| 925 | } |
tina.legrand@webrtc.org | 7a7a008 | 2013-02-21 10:27:48 +0000 | [diff] [blame] | 926 | acm_b_->ReceiveCodec(&my_codec_param); |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 927 | if (test_mode_ != 0) { |
| 928 | printf("%s\n", my_codec_param.plname); |
| 929 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 930 | } |
| 931 | |
tina.legrand@webrtc.org | a6ecd1e | 2012-04-26 07:54:30 +0000 | [diff] [blame] | 932 | } // namespace webrtc |