| OLD | NEW |
| (Empty) |
| 1 /* | |
| 2 * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved. | |
| 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 <stdio.h> | |
| 12 #include <string> | |
| 13 | |
| 14 #include "test/testsupport/fileutils.h" | |
| 15 #include "voice_engine/test/auto_test/fixtures/after_streaming_fixture.h" | |
| 16 #include "voice_engine/voice_engine_defines.h" | |
| 17 | |
| 18 class CodecTest : public AfterStreamingFixture { | |
| 19 protected: | |
| 20 void SetUp() { | |
| 21 memset(&codec_instance_, 0, sizeof(codec_instance_)); | |
| 22 apm_ = webrtc::AudioProcessing::Create(); | |
| 23 voe_base_->Init(nullptr, apm_.get(), nullptr); | |
| 24 } | |
| 25 | |
| 26 void SetArbitrarySendCodec() { | |
| 27 // Just grab the first codec. | |
| 28 EXPECT_EQ(0, voe_codec_->GetCodec(0, codec_instance_)); | |
| 29 EXPECT_EQ(0, voe_codec_->SetSendCodec(channel_, codec_instance_)); | |
| 30 } | |
| 31 | |
| 32 rtc::scoped_refptr<webrtc::AudioProcessing> apm_; | |
| 33 webrtc::CodecInst codec_instance_; | |
| 34 }; | |
| 35 | |
| 36 static void SetRateIfILBC(webrtc::CodecInst* codec_instance, int packet_size) { | |
| 37 if (!STR_CASE_CMP(codec_instance->plname, "ilbc")) { | |
| 38 if (packet_size == 160 || packet_size == 320) { | |
| 39 codec_instance->rate = 15200; | |
| 40 } else { | |
| 41 codec_instance->rate = 13300; | |
| 42 } | |
| 43 } | |
| 44 } | |
| 45 | |
| 46 static bool IsNotViableSendCodec(const char* codec_name) { | |
| 47 return !STR_CASE_CMP(codec_name, "CN") || | |
| 48 !STR_CASE_CMP(codec_name, "telephone-event") || | |
| 49 !STR_CASE_CMP(codec_name, "red"); | |
| 50 } | |
| 51 | |
| 52 TEST_F(CodecTest, PcmuIsDefaultCodecAndHasTheRightValues) { | |
| 53 EXPECT_EQ(0, voe_codec_->GetSendCodec(channel_, codec_instance_)); | |
| 54 EXPECT_EQ(1u, codec_instance_.channels); | |
| 55 EXPECT_EQ(160, codec_instance_.pacsize); | |
| 56 EXPECT_EQ(8000, codec_instance_.plfreq); | |
| 57 EXPECT_EQ(0, codec_instance_.pltype); | |
| 58 EXPECT_EQ(64000, codec_instance_.rate); | |
| 59 EXPECT_STRCASEEQ("PCMU", codec_instance_.plname); | |
| 60 } | |
| 61 | |
| 62 TEST_F(CodecTest, VoiceActivityDetectionIsOffByDefault) { | |
| 63 bool vad_enabled = false; | |
| 64 bool dtx_disabled = false; | |
| 65 webrtc::VadModes vad_mode = webrtc::kVadAggressiveMid; | |
| 66 | |
| 67 voe_codec_->GetVADStatus(channel_, vad_enabled, vad_mode, dtx_disabled); | |
| 68 | |
| 69 EXPECT_FALSE(vad_enabled); | |
| 70 EXPECT_TRUE(dtx_disabled); | |
| 71 EXPECT_EQ(webrtc::kVadConventional, vad_mode); | |
| 72 } | |
| 73 | |
| 74 TEST_F(CodecTest, VoiceActivityDetectionCanBeEnabled) { | |
| 75 EXPECT_EQ(0, voe_codec_->SetVADStatus(channel_, true)); | |
| 76 | |
| 77 bool vad_enabled = false; | |
| 78 bool dtx_disabled = false; | |
| 79 webrtc::VadModes vad_mode = webrtc::kVadAggressiveMid; | |
| 80 | |
| 81 voe_codec_->GetVADStatus(channel_, vad_enabled, vad_mode, dtx_disabled); | |
| 82 | |
| 83 EXPECT_TRUE(vad_enabled); | |
| 84 EXPECT_EQ(webrtc::kVadConventional, vad_mode); | |
| 85 EXPECT_FALSE(dtx_disabled); | |
| 86 } | |
| 87 | |
| 88 TEST_F(CodecTest, VoiceActivityDetectionTypeSettingsCanBeChanged) { | |
| 89 bool vad_enabled = false; | |
| 90 bool dtx_disabled = false; | |
| 91 webrtc::VadModes vad_mode = webrtc::kVadAggressiveMid; | |
| 92 | |
| 93 EXPECT_EQ(0, voe_codec_->SetVADStatus( | |
| 94 channel_, true, webrtc::kVadAggressiveLow, false)); | |
| 95 EXPECT_EQ(0, voe_codec_->GetVADStatus( | |
| 96 channel_, vad_enabled, vad_mode, dtx_disabled)); | |
| 97 EXPECT_EQ(vad_mode, webrtc::kVadAggressiveLow); | |
| 98 EXPECT_FALSE(dtx_disabled); | |
| 99 | |
| 100 EXPECT_EQ(0, voe_codec_->SetVADStatus( | |
| 101 channel_, true, webrtc::kVadAggressiveMid, false)); | |
| 102 EXPECT_EQ(0, voe_codec_->GetVADStatus( | |
| 103 channel_, vad_enabled, vad_mode, dtx_disabled)); | |
| 104 EXPECT_EQ(vad_mode, webrtc::kVadAggressiveMid); | |
| 105 EXPECT_FALSE(dtx_disabled); | |
| 106 | |
| 107 // The fourth argument is the DTX disable flag, which is always supposed to | |
| 108 // be false. | |
| 109 EXPECT_EQ(0, voe_codec_->SetVADStatus(channel_, true, | |
| 110 webrtc::kVadAggressiveHigh, false)); | |
| 111 EXPECT_EQ(0, voe_codec_->GetVADStatus( | |
| 112 channel_, vad_enabled, vad_mode, dtx_disabled)); | |
| 113 EXPECT_EQ(vad_mode, webrtc::kVadAggressiveHigh); | |
| 114 EXPECT_FALSE(dtx_disabled); | |
| 115 | |
| 116 EXPECT_EQ(0, voe_codec_->SetVADStatus(channel_, true, | |
| 117 webrtc::kVadConventional, false)); | |
| 118 EXPECT_EQ(0, voe_codec_->GetVADStatus( | |
| 119 channel_, vad_enabled, vad_mode, dtx_disabled)); | |
| 120 EXPECT_EQ(vad_mode, webrtc::kVadConventional); | |
| 121 } | |
| 122 | |
| 123 TEST_F(CodecTest, VoiceActivityDetectionCanBeTurnedOff) { | |
| 124 EXPECT_EQ(0, voe_codec_->SetVADStatus(channel_, true)); | |
| 125 | |
| 126 // VAD is always on when DTX is on, so we need to turn off DTX too. | |
| 127 EXPECT_EQ(0, voe_codec_->SetVADStatus( | |
| 128 channel_, false, webrtc::kVadConventional, true)); | |
| 129 | |
| 130 bool vad_enabled = false; | |
| 131 bool dtx_disabled = false; | |
| 132 webrtc::VadModes vad_mode = webrtc::kVadAggressiveMid; | |
| 133 | |
| 134 voe_codec_->GetVADStatus(channel_, vad_enabled, vad_mode, dtx_disabled); | |
| 135 | |
| 136 EXPECT_FALSE(vad_enabled); | |
| 137 EXPECT_TRUE(dtx_disabled); | |
| 138 EXPECT_EQ(webrtc::kVadConventional, vad_mode); | |
| 139 } | |
| 140 | |
| 141 TEST_F(CodecTest, OpusMaxPlaybackRateCanBeSet) { | |
| 142 for (int i = 0; i < voe_codec_->NumOfCodecs(); ++i) { | |
| 143 voe_codec_->GetCodec(i, codec_instance_); | |
| 144 if (STR_CASE_CMP("opus", codec_instance_.plname)) { | |
| 145 continue; | |
| 146 } | |
| 147 voe_codec_->SetSendCodec(channel_, codec_instance_); | |
| 148 // SetOpusMaxPlaybackRate can handle any integer as the bandwidth. Following | |
| 149 // tests some most commonly used numbers. | |
| 150 EXPECT_EQ(0, voe_codec_->SetOpusMaxPlaybackRate(channel_, 48000)); | |
| 151 EXPECT_EQ(0, voe_codec_->SetOpusMaxPlaybackRate(channel_, 32000)); | |
| 152 EXPECT_EQ(0, voe_codec_->SetOpusMaxPlaybackRate(channel_, 16000)); | |
| 153 EXPECT_EQ(0, voe_codec_->SetOpusMaxPlaybackRate(channel_, 8000)); | |
| 154 } | |
| 155 } | |
| 156 | |
| 157 TEST_F(CodecTest, OpusDtxCanBeSetForOpus) { | |
| 158 for (int i = 0; i < voe_codec_->NumOfCodecs(); ++i) { | |
| 159 voe_codec_->GetCodec(i, codec_instance_); | |
| 160 if (STR_CASE_CMP("opus", codec_instance_.plname)) { | |
| 161 continue; | |
| 162 } | |
| 163 voe_codec_->SetSendCodec(channel_, codec_instance_); | |
| 164 EXPECT_EQ(0, voe_codec_->SetOpusDtx(channel_, false)); | |
| 165 EXPECT_EQ(0, voe_codec_->SetOpusDtx(channel_, true)); | |
| 166 } | |
| 167 } | |
| 168 | |
| 169 TEST_F(CodecTest, OpusDtxCannotBeSetForNonOpus) { | |
| 170 for (int i = 0; i < voe_codec_->NumOfCodecs(); ++i) { | |
| 171 voe_codec_->GetCodec(i, codec_instance_); | |
| 172 if (!STR_CASE_CMP("opus", codec_instance_.plname)) { | |
| 173 continue; | |
| 174 } | |
| 175 voe_codec_->SetSendCodec(channel_, codec_instance_); | |
| 176 EXPECT_EQ(-1, voe_codec_->SetOpusDtx(channel_, true)); | |
| 177 } | |
| 178 } | |
| 179 | |
| 180 // TODO(xians, phoglund): Re-enable when issue 372 is resolved. | |
| 181 TEST_F(CodecTest, DISABLED_ManualVerifySendCodecsForAllPacketSizes) { | |
| 182 for (int i = 0; i < voe_codec_->NumOfCodecs(); ++i) { | |
| 183 voe_codec_->GetCodec(i, codec_instance_); | |
| 184 if (IsNotViableSendCodec(codec_instance_.plname)) { | |
| 185 TEST_LOG("Skipping %s.\n", codec_instance_.plname); | |
| 186 continue; | |
| 187 } | |
| 188 EXPECT_NE(-1, codec_instance_.pltype) << | |
| 189 "The codec database should suggest a payload type."; | |
| 190 | |
| 191 // Test with default packet size: | |
| 192 TEST_LOG("%s (pt=%d): default packet size(%d), accepts sizes ", | |
| 193 codec_instance_.plname, codec_instance_.pltype, | |
| 194 codec_instance_.pacsize); | |
| 195 voe_codec_->SetSendCodec(channel_, codec_instance_); | |
| 196 Sleep(CODEC_TEST_TIME); | |
| 197 | |
| 198 // Now test other reasonable packet sizes: | |
| 199 bool at_least_one_succeeded = false; | |
| 200 for (int packet_size = 80; packet_size < 1000; packet_size += 80) { | |
| 201 SetRateIfILBC(&codec_instance_, packet_size); | |
| 202 codec_instance_.pacsize = packet_size; | |
| 203 | |
| 204 if (voe_codec_->SetSendCodec(channel_, codec_instance_) != -1) { | |
| 205 // Note that it's fine for SetSendCodec to fail - what packet sizes | |
| 206 // it accepts depends on the codec. It should accept one at minimum. | |
| 207 TEST_LOG("%d ", packet_size); | |
| 208 TEST_LOG_FLUSH; | |
| 209 at_least_one_succeeded = true; | |
| 210 Sleep(CODEC_TEST_TIME); | |
| 211 } | |
| 212 } | |
| 213 TEST_LOG("\n"); | |
| 214 EXPECT_TRUE(at_least_one_succeeded); | |
| 215 } | |
| 216 } | |
| OLD | NEW |