blob: 3b56bae54c412912ea3d5e95033420f984fa3648 [file] [log] [blame]
andrew@webrtc.orgb015cbe2012-10-22 18:19:231/*
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
pbos@webrtc.org471ae722013-05-21 13:52:3211#include "webrtc/voice_engine/test/auto_test/fixtures/after_streaming_fixture.h"
12#include "webrtc/voice_engine/voice_engine_defines.h"
andrew@webrtc.orgb015cbe2012-10-22 18:19:2313
14class CodecTest : public AfterStreamingFixture {
15 protected:
16 void SetUp() {
17 memset(&codec_instance_, 0, sizeof(codec_instance_));
18 }
19
20 void SetArbitrarySendCodec() {
21 // Just grab the first codec.
22 EXPECT_EQ(0, voe_codec_->GetCodec(0, codec_instance_));
23 EXPECT_EQ(0, voe_codec_->SetSendCodec(channel_, codec_instance_));
24 }
25
26 webrtc::CodecInst codec_instance_;
27};
28
29static void SetRateIfILBC(webrtc::CodecInst* codec_instance, int packet_size) {
30 if (!_stricmp(codec_instance->plname, "ilbc")) {
31 if (packet_size == 160 || packet_size == 320) {
32 codec_instance->rate = 15200;
33 } else {
34 codec_instance->rate = 13300;
35 }
36 }
37}
38
39static bool IsNotViableSendCodec(const char* codec_name) {
40 return !_stricmp(codec_name, "CN") ||
41 !_stricmp(codec_name, "telephone-event") ||
42 !_stricmp(codec_name, "red");
43}
44
45TEST_F(CodecTest, PcmuIsDefaultCodecAndHasTheRightValues) {
46 EXPECT_EQ(0, voe_codec_->GetSendCodec(channel_, codec_instance_));
47 EXPECT_EQ(1, codec_instance_.channels);
48 EXPECT_EQ(160, codec_instance_.pacsize);
49 EXPECT_EQ(8000, codec_instance_.plfreq);
50 EXPECT_EQ(0, codec_instance_.pltype);
51 EXPECT_EQ(64000, codec_instance_.rate);
52 EXPECT_STRCASEEQ("PCMU", codec_instance_.plname);
53}
54
55TEST_F(CodecTest, VoiceActivityDetectionIsOffByDefault) {
56 bool vad_enabled = false;
57 bool dtx_disabled = false;
58 webrtc::VadModes vad_mode = webrtc::kVadAggressiveMid;
59
60 voe_codec_->GetVADStatus(channel_, vad_enabled, vad_mode, dtx_disabled);
61
62 EXPECT_FALSE(vad_enabled);
63 EXPECT_TRUE(dtx_disabled);
64 EXPECT_EQ(webrtc::kVadConventional, vad_mode);
65}
66
67TEST_F(CodecTest, VoiceActivityDetectionCanBeEnabled) {
68 EXPECT_EQ(0, voe_codec_->SetVADStatus(channel_, true));
69
70 bool vad_enabled = false;
71 bool dtx_disabled = false;
72 webrtc::VadModes vad_mode = webrtc::kVadAggressiveMid;
73
74 voe_codec_->GetVADStatus(channel_, vad_enabled, vad_mode, dtx_disabled);
75
76 EXPECT_TRUE(vad_enabled);
77 EXPECT_EQ(webrtc::kVadConventional, vad_mode);
78 EXPECT_FALSE(dtx_disabled);
79}
80
81TEST_F(CodecTest, VoiceActivityDetectionTypeSettingsCanBeChanged) {
82 bool vad_enabled = false;
83 bool dtx_disabled = false;
84 webrtc::VadModes vad_mode = webrtc::kVadAggressiveMid;
85
86 EXPECT_EQ(0, voe_codec_->SetVADStatus(
87 channel_, true, webrtc::kVadAggressiveLow, false));
88 EXPECT_EQ(0, voe_codec_->GetVADStatus(
89 channel_, vad_enabled, vad_mode, dtx_disabled));
90 EXPECT_EQ(vad_mode, webrtc::kVadAggressiveLow);
91 EXPECT_FALSE(dtx_disabled);
92
93 EXPECT_EQ(0, voe_codec_->SetVADStatus(
94 channel_, true, webrtc::kVadAggressiveMid, false));
95 EXPECT_EQ(0, voe_codec_->GetVADStatus(
96 channel_, vad_enabled, vad_mode, dtx_disabled));
97 EXPECT_EQ(vad_mode, webrtc::kVadAggressiveMid);
98 EXPECT_FALSE(dtx_disabled);
99
100 // The fourth argument is the DTX disable flag.
101 EXPECT_EQ(0, voe_codec_->SetVADStatus(
102 channel_, true, webrtc::kVadAggressiveHigh, true));
103 EXPECT_EQ(0, voe_codec_->GetVADStatus(
104 channel_, vad_enabled, vad_mode, dtx_disabled));
105 EXPECT_EQ(vad_mode, webrtc::kVadAggressiveHigh);
106 EXPECT_TRUE(dtx_disabled);
107
108 EXPECT_EQ(0, voe_codec_->SetVADStatus(
109 channel_, true, webrtc::kVadConventional, true));
110 EXPECT_EQ(0, voe_codec_->GetVADStatus(
111 channel_, vad_enabled, vad_mode, dtx_disabled));
112 EXPECT_EQ(vad_mode, webrtc::kVadConventional);
113}
114
115TEST_F(CodecTest, VoiceActivityDetectionCanBeTurnedOff) {
116 EXPECT_EQ(0, voe_codec_->SetVADStatus(channel_, true));
117
118 // VAD is always on when DTX is on, so we need to turn off DTX too.
119 EXPECT_EQ(0, voe_codec_->SetVADStatus(
120 channel_, false, webrtc::kVadConventional, true));
121
122 bool vad_enabled = false;
123 bool dtx_disabled = false;
124 webrtc::VadModes vad_mode = webrtc::kVadAggressiveMid;
125
126 voe_codec_->GetVADStatus(channel_, vad_enabled, vad_mode, dtx_disabled);
127
128 EXPECT_FALSE(vad_enabled);
129 EXPECT_TRUE(dtx_disabled);
130 EXPECT_EQ(webrtc::kVadConventional, vad_mode);
131}
132
minyue@webrtc.orgb0aac712014-09-03 12:28:06133TEST_F(CodecTest, OpusMaxPlaybackRateCanBeSet) {
minyue@webrtc.org1bfd5402014-08-12 08:13:33134 for (int i = 0; i < voe_codec_->NumOfCodecs(); ++i) {
135 voe_codec_->GetCodec(i, codec_instance_);
136 if (_stricmp("opus", codec_instance_.plname)) {
137 continue;
138 }
139 voe_codec_->SetSendCodec(channel_, codec_instance_);
minyue@webrtc.orgb0aac712014-09-03 12:28:06140 // SetOpusMaxPlaybackRate can handle any integer as the bandwidth. Following
minyue@webrtc.org1bfd5402014-08-12 08:13:33141 // tests some most commonly used numbers.
minyue@webrtc.orgb0aac712014-09-03 12:28:06142 EXPECT_EQ(0, voe_codec_->SetOpusMaxPlaybackRate(channel_, 48000));
143 EXPECT_EQ(0, voe_codec_->SetOpusMaxPlaybackRate(channel_, 32000));
144 EXPECT_EQ(0, voe_codec_->SetOpusMaxPlaybackRate(channel_, 16000));
145 EXPECT_EQ(0, voe_codec_->SetOpusMaxPlaybackRate(channel_, 8000));
minyue@webrtc.org1bfd5402014-08-12 08:13:33146 }
147}
148
minyue@webrtc.orgb0aac712014-09-03 12:28:06149TEST_F(CodecTest, OpusMaxPlaybackRateCannotBeSetForNonOpus) {
minyue@webrtc.org1bfd5402014-08-12 08:13:33150 for (int i = 0; i < voe_codec_->NumOfCodecs(); ++i) {
151 voe_codec_->GetCodec(i, codec_instance_);
152 if (!_stricmp("opus", codec_instance_.plname)) {
153 continue;
154 }
155 voe_codec_->SetSendCodec(channel_, codec_instance_);
minyue@webrtc.orgb0aac712014-09-03 12:28:06156 EXPECT_EQ(-1, voe_codec_->SetOpusMaxPlaybackRate(channel_, 16000));
minyue@webrtc.org1bfd5402014-08-12 08:13:33157 }
158}
159
andrew@webrtc.orgb015cbe2012-10-22 18:19:23160// TODO(xians, phoglund): Re-enable when issue 372 is resolved.
161TEST_F(CodecTest, DISABLED_ManualVerifySendCodecsForAllPacketSizes) {
162 for (int i = 0; i < voe_codec_->NumOfCodecs(); ++i) {
163 voe_codec_->GetCodec(i, codec_instance_);
164 if (IsNotViableSendCodec(codec_instance_.plname)) {
165 TEST_LOG("Skipping %s.\n", codec_instance_.plname);
166 continue;
167 }
168 EXPECT_NE(-1, codec_instance_.pltype) <<
169 "The codec database should suggest a payload type.";
170
171 // Test with default packet size:
172 TEST_LOG("%s (pt=%d): default packet size(%d), accepts sizes ",
173 codec_instance_.plname, codec_instance_.pltype,
174 codec_instance_.pacsize);
175 voe_codec_->SetSendCodec(channel_, codec_instance_);
176 Sleep(CODEC_TEST_TIME);
177
178 // Now test other reasonable packet sizes:
179 bool at_least_one_succeeded = false;
180 for (int packet_size = 80; packet_size < 1000; packet_size += 80) {
181 SetRateIfILBC(&codec_instance_, packet_size);
182 codec_instance_.pacsize = packet_size;
183
184 if (voe_codec_->SetSendCodec(channel_, codec_instance_) != -1) {
185 // Note that it's fine for SetSendCodec to fail - what packet sizes
186 // it accepts depends on the codec. It should accept one at minimum.
187 TEST_LOG("%d ", packet_size);
188 TEST_LOG_FLUSH;
189 at_least_one_succeeded = true;
190 Sleep(CODEC_TEST_TIME);
191 }
192 }
193 TEST_LOG("\n");
194 EXPECT_TRUE(at_least_one_succeeded);
195 }
196}