blob: f0e450328a54cd1b971d3509e245eff2fa8fba81 [file] [log] [blame]
henrike@webrtc.org79047f92014-03-06 23:46:59 +00001/*
2 * libjingle
3 * Copyright 2008 Google Inc.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright notice,
11 * this list of conditions and the following disclaimer in the documentation
12 * and/or other materials provided with the distribution.
13 * 3. The name of the author may not be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
19 * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
21 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
22 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
23 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
24 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
25 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
henrike@webrtc.org28e20752013-07-10 00:45:36 +000027
28#ifdef WIN32
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000029#include "webrtc/base/win32.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000030#include <objbase.h>
31#endif
32
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000033#include "webrtc/base/byteorder.h"
34#include "webrtc/base/gunit.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000035#include "talk/media/base/constants.h"
36#include "talk/media/base/fakemediaengine.h"
37#include "talk/media/base/fakemediaprocessor.h"
wu@webrtc.orgde305012013-10-31 15:40:38 +000038#include "talk/media/base/fakenetworkinterface.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000039#include "talk/media/base/fakertp.h"
40#include "talk/media/webrtc/fakewebrtcvoiceengine.h"
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +000041#include "talk/media/webrtc/webrtcvie.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000042#include "talk/media/webrtc/webrtcvoiceengine.h"
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +000043#include "webrtc/p2p/base/fakesession.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000044#include "talk/session/media/channel.h"
45
46// Tests for the WebRtcVoiceEngine/VoiceChannel code.
47
buildbot@webrtc.org150835e2014-05-06 15:54:38 +000048using cricket::kRtpAudioLevelHeaderExtension;
49using cricket::kRtpAbsoluteSenderTimeHeaderExtension;
50
henrike@webrtc.org28e20752013-07-10 00:45:36 +000051static const cricket::AudioCodec kPcmuCodec(0, "PCMU", 8000, 64000, 1, 0);
52static const cricket::AudioCodec kIsacCodec(103, "ISAC", 16000, 32000, 1, 0);
henrike@webrtc.org28e20752013-07-10 00:45:36 +000053static const cricket::AudioCodec kOpusCodec(111, "opus", 48000, 64000, 2, 0);
henrik.lundin@webrtc.orgf85dbce2014-11-07 12:25:00 +000054static const cricket::AudioCodec kG722CodecVoE(9, "G722", 16000, 64000, 1, 0);
55static const cricket::AudioCodec kG722CodecSdp(9, "G722", 8000, 64000, 1, 0);
henrike@webrtc.org28e20752013-07-10 00:45:36 +000056static const cricket::AudioCodec kRedCodec(117, "red", 8000, 0, 1, 0);
57static const cricket::AudioCodec kCn8000Codec(13, "CN", 8000, 0, 1, 0);
58static const cricket::AudioCodec kCn16000Codec(105, "CN", 16000, 0, 1, 0);
59static const cricket::AudioCodec
60 kTelephoneEventCodec(106, "telephone-event", 8000, 0, 1, 0);
61static const cricket::AudioCodec* const kAudioCodecs[] = {
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +000062 &kPcmuCodec, &kIsacCodec, &kOpusCodec, &kG722CodecVoE, &kRedCodec,
63 &kCn8000Codec, &kCn16000Codec, &kTelephoneEventCodec,
henrike@webrtc.org28e20752013-07-10 00:45:36 +000064};
65const char kRingbackTone[] = "RIFF____WAVE____ABCD1234";
66static uint32 kSsrc1 = 0x99;
67static uint32 kSsrc2 = 0x98;
68
69class FakeVoEWrapper : public cricket::VoEWrapper {
70 public:
71 explicit FakeVoEWrapper(cricket::FakeWebRtcVoiceEngine* engine)
72 : cricket::VoEWrapper(engine, // processing
73 engine, // base
74 engine, // codec
75 engine, // dtmf
76 engine, // file
77 engine, // hw
78 engine, // media
79 engine, // neteq
80 engine, // network
81 engine, // rtp
82 engine, // sync
83 engine) { // volume
84 }
85};
86
wu@webrtc.org97077a32013-10-25 21:18:33 +000087class FakeVoETraceWrapper : public cricket::VoETraceWrapper {
henrike@webrtc.org28e20752013-07-10 00:45:36 +000088 public:
89 virtual int SetTraceFilter(const unsigned int filter) {
wu@webrtc.org97077a32013-10-25 21:18:33 +000090 filter_ = filter;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000091 return 0;
92 }
93 virtual int SetTraceFile(const char* fileNameUTF8) {
94 return 0;
95 }
96 virtual int SetTraceCallback(webrtc::TraceCallback* callback) {
97 return 0;
98 }
wu@webrtc.org97077a32013-10-25 21:18:33 +000099 unsigned int filter_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000100};
101
102class WebRtcVoiceEngineTestFake : public testing::Test {
103 public:
104 class ChannelErrorListener : public sigslot::has_slots<> {
105 public:
106 explicit ChannelErrorListener(cricket::VoiceMediaChannel* channel)
107 : ssrc_(0), error_(cricket::VoiceMediaChannel::ERROR_NONE) {
108 ASSERT(channel != NULL);
109 channel->SignalMediaError.connect(
110 this, &ChannelErrorListener::OnVoiceChannelError);
111 }
112 void OnVoiceChannelError(uint32 ssrc,
113 cricket::VoiceMediaChannel::Error error) {
114 ssrc_ = ssrc;
115 error_ = error;
116 }
117 void Reset() {
118 ssrc_ = 0;
119 error_ = cricket::VoiceMediaChannel::ERROR_NONE;
120 }
121 uint32 ssrc() const {
122 return ssrc_;
123 }
124 cricket::VoiceMediaChannel::Error error() const {
125 return error_;
126 }
127
128 private:
129 uint32 ssrc_;
130 cricket::VoiceMediaChannel::Error error_;
131 };
132
133 WebRtcVoiceEngineTestFake()
134 : voe_(kAudioCodecs, ARRAY_SIZE(kAudioCodecs)),
135 voe_sc_(kAudioCodecs, ARRAY_SIZE(kAudioCodecs)),
wu@webrtc.org97077a32013-10-25 21:18:33 +0000136 trace_wrapper_(new FakeVoETraceWrapper()),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000137 engine_(new FakeVoEWrapper(&voe_),
138 new FakeVoEWrapper(&voe_sc_),
wu@webrtc.org97077a32013-10-25 21:18:33 +0000139 trace_wrapper_),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000140 channel_(NULL), soundclip_(NULL) {
141 options_conference_.conference_mode.Set(true);
142 options_adjust_agc_.adjust_agc_delta.Set(-10);
143 }
buildbot@webrtc.org150835e2014-05-06 15:54:38 +0000144 bool SetupEngineWithoutStream() {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000145 if (!engine_.Init(rtc::Thread::Current())) {
buildbot@webrtc.org150835e2014-05-06 15:54:38 +0000146 return false;
147 }
148 channel_ = engine_.CreateChannel();
149 return (channel_ != NULL);
150 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000151 bool SetupEngine() {
buildbot@webrtc.org150835e2014-05-06 15:54:38 +0000152 if (!SetupEngineWithoutStream()) {
153 return false;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000154 }
buildbot@webrtc.org150835e2014-05-06 15:54:38 +0000155 return channel_->AddSendStream(
156 cricket::StreamParams::CreateLegacy(kSsrc1));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000157 }
wu@webrtc.org9dba5252013-08-05 20:36:57 +0000158 void SetupForMultiSendStream() {
159 EXPECT_TRUE(SetupEngine());
160 // Remove stream added in Setup, which is corresponding to default channel.
161 int default_channel_num = voe_.GetLastChannel();
henrike@webrtc.org7666db72013-08-22 14:45:42 +0000162 uint32 default_send_ssrc = 0u;
wu@webrtc.org9dba5252013-08-05 20:36:57 +0000163 EXPECT_EQ(0, voe_.GetLocalSSRC(default_channel_num, default_send_ssrc));
164 EXPECT_EQ(kSsrc1, default_send_ssrc);
165 EXPECT_TRUE(channel_->RemoveSendStream(default_send_ssrc));
166
167 // Verify the default channel still exists.
168 EXPECT_EQ(0, voe_.GetLocalSSRC(default_channel_num, default_send_ssrc));
169 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000170 void DeliverPacket(const void* data, int len) {
Karl Wiberg94784372015-04-20 14:03:07 +0200171 rtc::Buffer packet(reinterpret_cast<const uint8_t*>(data), len);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000172 channel_->OnPacketReceived(&packet, rtc::PacketTime());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000173 }
174 virtual void TearDown() {
175 delete soundclip_;
176 delete channel_;
177 engine_.Terminate();
178 }
179
wu@webrtc.orgcadf9042013-08-30 21:24:16 +0000180 void TestInsertDtmf(uint32 ssrc, bool caller) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000181 EXPECT_TRUE(engine_.Init(rtc::Thread::Current()));
wu@webrtc.orgcadf9042013-08-30 21:24:16 +0000182 channel_ = engine_.CreateChannel();
183 EXPECT_TRUE(channel_ != NULL);
184 if (caller) {
185 // if this is a caller, local description will be applied and add the
186 // send stream.
187 EXPECT_TRUE(channel_->AddSendStream(
188 cricket::StreamParams::CreateLegacy(kSsrc1)));
189 }
190 int channel_id = voe_.GetLastChannel();
191
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000192 // Test we can only InsertDtmf when the other side supports telephone-event.
193 std::vector<cricket::AudioCodec> codecs;
194 codecs.push_back(kPcmuCodec);
195 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
196 EXPECT_TRUE(channel_->SetSend(cricket::SEND_MICROPHONE));
197 EXPECT_FALSE(channel_->CanInsertDtmf());
198 EXPECT_FALSE(channel_->InsertDtmf(ssrc, 1, 111, cricket::DF_SEND));
199 codecs.push_back(kTelephoneEventCodec);
200 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
201 EXPECT_TRUE(channel_->CanInsertDtmf());
wu@webrtc.orgcadf9042013-08-30 21:24:16 +0000202
203 if (!caller) {
204 // There's no active send channel yet.
205 EXPECT_FALSE(channel_->InsertDtmf(ssrc, 2, 123, cricket::DF_SEND));
206 EXPECT_TRUE(channel_->AddSendStream(
207 cricket::StreamParams::CreateLegacy(kSsrc1)));
208 }
209
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000210 // Check we fail if the ssrc is invalid.
211 EXPECT_FALSE(channel_->InsertDtmf(-1, 1, 111, cricket::DF_SEND));
212
213 // Test send
214 EXPECT_FALSE(voe_.WasSendTelephoneEventCalled(channel_id, 2, 123));
215 EXPECT_TRUE(channel_->InsertDtmf(ssrc, 2, 123, cricket::DF_SEND));
216 EXPECT_TRUE(voe_.WasSendTelephoneEventCalled(channel_id, 2, 123));
217
218 // Test play
219 EXPECT_FALSE(voe_.WasPlayDtmfToneCalled(3, 134));
220 EXPECT_TRUE(channel_->InsertDtmf(ssrc, 3, 134, cricket::DF_PLAY));
221 EXPECT_TRUE(voe_.WasPlayDtmfToneCalled(3, 134));
222
223 // Test send and play
224 EXPECT_FALSE(voe_.WasSendTelephoneEventCalled(channel_id, 4, 145));
225 EXPECT_FALSE(voe_.WasPlayDtmfToneCalled(4, 145));
226 EXPECT_TRUE(channel_->InsertDtmf(ssrc, 4, 145,
227 cricket::DF_PLAY | cricket::DF_SEND));
228 EXPECT_TRUE(voe_.WasSendTelephoneEventCalled(channel_id, 4, 145));
229 EXPECT_TRUE(voe_.WasPlayDtmfToneCalled(4, 145));
230 }
231
232 // Test that send bandwidth is set correctly.
233 // |codec| is the codec under test.
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000234 // |max_bitrate| is a parameter to set to SetMaxSendBandwidth().
235 // |expected_result| is the expected result from SetMaxSendBandwidth().
236 // |expected_bitrate| is the expected audio bitrate afterward.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000237 void TestSendBandwidth(const cricket::AudioCodec& codec,
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000238 int max_bitrate,
239 bool expected_result,
240 int expected_bitrate) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000241 int channel_num = voe_.GetLastChannel();
242 std::vector<cricket::AudioCodec> codecs;
243
244 codecs.push_back(codec);
245 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
246
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000247 bool result = channel_->SetMaxSendBandwidth(max_bitrate);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000248 EXPECT_EQ(expected_result, result);
249
wu@webrtc.org1d1ffc92013-10-16 18:12:02 +0000250 webrtc::CodecInst temp_codec;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000251 EXPECT_FALSE(voe_.GetSendCodec(channel_num, temp_codec));
252
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000253 EXPECT_EQ(expected_bitrate, temp_codec.rate);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000254 }
255
buildbot@webrtc.org150835e2014-05-06 15:54:38 +0000256 void TestSetSendRtpHeaderExtensions(const std::string& ext) {
257 EXPECT_TRUE(SetupEngineWithoutStream());
258 int channel_num = voe_.GetLastChannel();
wu@webrtc.org9dba5252013-08-05 20:36:57 +0000259
henrike@webrtc.org79047f92014-03-06 23:46:59 +0000260 // Ensure extensions are off by default.
buildbot@webrtc.org150835e2014-05-06 15:54:38 +0000261 EXPECT_EQ(-1, voe_.GetSendRtpExtensionId(channel_num, ext));
wu@webrtc.org9dba5252013-08-05 20:36:57 +0000262
buildbot@webrtc.org150835e2014-05-06 15:54:38 +0000263 std::vector<cricket::RtpHeaderExtension> extensions;
wu@webrtc.org9dba5252013-08-05 20:36:57 +0000264 // Ensure unknown extensions won't cause an error.
265 extensions.push_back(cricket::RtpHeaderExtension(
henrike@webrtc.org79047f92014-03-06 23:46:59 +0000266 "urn:ietf:params:unknownextention", 1));
wu@webrtc.org9dba5252013-08-05 20:36:57 +0000267 EXPECT_TRUE(channel_->SetSendRtpHeaderExtensions(extensions));
buildbot@webrtc.org150835e2014-05-06 15:54:38 +0000268 EXPECT_EQ(-1, voe_.GetSendRtpExtensionId(channel_num, ext));
wu@webrtc.org9dba5252013-08-05 20:36:57 +0000269
henrike@webrtc.org79047f92014-03-06 23:46:59 +0000270 // Ensure extensions stay off with an empty list of headers.
271 extensions.clear();
wu@webrtc.org9dba5252013-08-05 20:36:57 +0000272 EXPECT_TRUE(channel_->SetSendRtpHeaderExtensions(extensions));
buildbot@webrtc.org150835e2014-05-06 15:54:38 +0000273 EXPECT_EQ(-1, voe_.GetSendRtpExtensionId(channel_num, ext));
wu@webrtc.org9dba5252013-08-05 20:36:57 +0000274
buildbot@webrtc.org150835e2014-05-06 15:54:38 +0000275 // Ensure extension is set properly.
276 const int id = 1;
277 extensions.push_back(cricket::RtpHeaderExtension(ext, id));
wu@webrtc.org9dba5252013-08-05 20:36:57 +0000278 EXPECT_TRUE(channel_->SetSendRtpHeaderExtensions(extensions));
buildbot@webrtc.org150835e2014-05-06 15:54:38 +0000279 EXPECT_EQ(id, voe_.GetSendRtpExtensionId(channel_num, ext));
wu@webrtc.org9dba5252013-08-05 20:36:57 +0000280
buildbot@webrtc.org150835e2014-05-06 15:54:38 +0000281 // Ensure extension is set properly on new channel.
282 // The first stream to occupy the default channel.
283 EXPECT_TRUE(channel_->AddSendStream(
284 cricket::StreamParams::CreateLegacy(123)));
285 EXPECT_TRUE(channel_->AddSendStream(
286 cricket::StreamParams::CreateLegacy(234)));
287 int new_channel_num = voe_.GetLastChannel();
288 EXPECT_NE(channel_num, new_channel_num);
289 EXPECT_EQ(id, voe_.GetSendRtpExtensionId(new_channel_num, ext));
henrike@webrtc.org79047f92014-03-06 23:46:59 +0000290
291 // Ensure all extensions go back off with an empty list.
wu@webrtc.org9dba5252013-08-05 20:36:57 +0000292 extensions.clear();
293 EXPECT_TRUE(channel_->SetSendRtpHeaderExtensions(extensions));
buildbot@webrtc.org150835e2014-05-06 15:54:38 +0000294 EXPECT_EQ(-1, voe_.GetSendRtpExtensionId(channel_num, ext));
295 EXPECT_EQ(-1, voe_.GetSendRtpExtensionId(new_channel_num, ext));
henrike@webrtc.org79047f92014-03-06 23:46:59 +0000296 }
297
buildbot@webrtc.org150835e2014-05-06 15:54:38 +0000298 void TestSetRecvRtpHeaderExtensions(const std::string& ext) {
299 EXPECT_TRUE(SetupEngineWithoutStream());
300 int channel_num = voe_.GetLastChannel();
henrike@webrtc.org79047f92014-03-06 23:46:59 +0000301
henrike@webrtc.org79047f92014-03-06 23:46:59 +0000302 // Ensure extensions are off by default.
buildbot@webrtc.org150835e2014-05-06 15:54:38 +0000303 EXPECT_EQ(-1, voe_.GetReceiveRtpExtensionId(channel_num, ext));
henrike@webrtc.org79047f92014-03-06 23:46:59 +0000304
buildbot@webrtc.org150835e2014-05-06 15:54:38 +0000305 std::vector<cricket::RtpHeaderExtension> extensions;
henrike@webrtc.org79047f92014-03-06 23:46:59 +0000306 // Ensure unknown extensions won't cause an error.
307 extensions.push_back(cricket::RtpHeaderExtension(
308 "urn:ietf:params:unknownextention", 1));
309 EXPECT_TRUE(channel_->SetRecvRtpHeaderExtensions(extensions));
buildbot@webrtc.org150835e2014-05-06 15:54:38 +0000310 EXPECT_EQ(-1, voe_.GetReceiveRtpExtensionId(channel_num, ext));
henrike@webrtc.org79047f92014-03-06 23:46:59 +0000311
buildbot@webrtc.org150835e2014-05-06 15:54:38 +0000312 // Ensure extensions stay off with an empty list of headers.
henrike@webrtc.org79047f92014-03-06 23:46:59 +0000313 extensions.clear();
314 EXPECT_TRUE(channel_->SetRecvRtpHeaderExtensions(extensions));
buildbot@webrtc.org150835e2014-05-06 15:54:38 +0000315 EXPECT_EQ(-1, voe_.GetReceiveRtpExtensionId(channel_num, ext));
henrike@webrtc.org79047f92014-03-06 23:46:59 +0000316
buildbot@webrtc.org150835e2014-05-06 15:54:38 +0000317 // Ensure extension is set properly.
318 const int id = 2;
319 extensions.push_back(cricket::RtpHeaderExtension(ext, id));
henrike@webrtc.org79047f92014-03-06 23:46:59 +0000320 EXPECT_TRUE(channel_->SetRecvRtpHeaderExtensions(extensions));
buildbot@webrtc.org150835e2014-05-06 15:54:38 +0000321 EXPECT_EQ(id, voe_.GetReceiveRtpExtensionId(channel_num, ext));
henrike@webrtc.org79047f92014-03-06 23:46:59 +0000322
buildbot@webrtc.org150835e2014-05-06 15:54:38 +0000323 // Ensure extension is set properly on new channel.
324 // The first stream to occupy the default channel.
325 EXPECT_TRUE(channel_->AddRecvStream(
326 cricket::StreamParams::CreateLegacy(345)));
327 EXPECT_TRUE(channel_->AddRecvStream(
328 cricket::StreamParams::CreateLegacy(456)));
329 int new_channel_num = voe_.GetLastChannel();
330 EXPECT_NE(channel_num, new_channel_num);
331 EXPECT_EQ(id, voe_.GetReceiveRtpExtensionId(new_channel_num, ext));
332
333 // Ensure all extensions go back off with an empty list.
henrike@webrtc.org79047f92014-03-06 23:46:59 +0000334 extensions.clear();
335 EXPECT_TRUE(channel_->SetRecvRtpHeaderExtensions(extensions));
buildbot@webrtc.org150835e2014-05-06 15:54:38 +0000336 EXPECT_EQ(-1, voe_.GetReceiveRtpExtensionId(channel_num, ext));
337 EXPECT_EQ(-1, voe_.GetReceiveRtpExtensionId(new_channel_num, ext));
wu@webrtc.org9dba5252013-08-05 20:36:57 +0000338 }
339
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000340 protected:
341 cricket::FakeWebRtcVoiceEngine voe_;
342 cricket::FakeWebRtcVoiceEngine voe_sc_;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000343 FakeVoETraceWrapper* trace_wrapper_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000344 cricket::WebRtcVoiceEngine engine_;
345 cricket::VoiceMediaChannel* channel_;
346 cricket::SoundclipMedia* soundclip_;
347
348 cricket::AudioOptions options_conference_;
349 cricket::AudioOptions options_adjust_agc_;
350};
351
352// Tests that our stub library "works".
353TEST_F(WebRtcVoiceEngineTestFake, StartupShutdown) {
354 EXPECT_FALSE(voe_.IsInited());
355 EXPECT_FALSE(voe_sc_.IsInited());
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000356 EXPECT_TRUE(engine_.Init(rtc::Thread::Current()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000357 EXPECT_TRUE(voe_.IsInited());
wu@webrtc.org4551b792013-10-09 15:37:36 +0000358 // The soundclip engine is lazily initialized.
359 EXPECT_FALSE(voe_sc_.IsInited());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000360 engine_.Terminate();
361 EXPECT_FALSE(voe_.IsInited());
362 EXPECT_FALSE(voe_sc_.IsInited());
363}
364
365// Tests that we can create and destroy a channel.
366TEST_F(WebRtcVoiceEngineTestFake, CreateChannel) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000367 EXPECT_TRUE(engine_.Init(rtc::Thread::Current()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000368 channel_ = engine_.CreateChannel();
369 EXPECT_TRUE(channel_ != NULL);
370}
371
372// Tests that we properly handle failures in CreateChannel.
373TEST_F(WebRtcVoiceEngineTestFake, CreateChannelFail) {
374 voe_.set_fail_create_channel(true);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000375 EXPECT_TRUE(engine_.Init(rtc::Thread::Current()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000376 channel_ = engine_.CreateChannel();
377 EXPECT_TRUE(channel_ == NULL);
378}
379
380// Tests that the list of supported codecs is created properly and ordered
381// correctly
382TEST_F(WebRtcVoiceEngineTestFake, CodecPreference) {
383 const std::vector<cricket::AudioCodec>& codecs = engine_.codecs();
384 ASSERT_FALSE(codecs.empty());
385 EXPECT_STRCASEEQ("opus", codecs[0].name.c_str());
386 EXPECT_EQ(48000, codecs[0].clockrate);
387 EXPECT_EQ(2, codecs[0].channels);
388 EXPECT_EQ(64000, codecs[0].bitrate);
389 int pref = codecs[0].preference;
390 for (size_t i = 1; i < codecs.size(); ++i) {
391 EXPECT_GT(pref, codecs[i].preference);
392 pref = codecs[i].preference;
393 }
394}
395
396// Tests that we can find codecs by name or id, and that we interpret the
397// clockrate and bitrate fields properly.
398TEST_F(WebRtcVoiceEngineTestFake, FindCodec) {
399 cricket::AudioCodec codec;
400 webrtc::CodecInst codec_inst;
401 // Find PCMU with explicit clockrate and bitrate.
402 EXPECT_TRUE(engine_.FindWebRtcCodec(kPcmuCodec, &codec_inst));
403 // Find ISAC with explicit clockrate and 0 bitrate.
404 EXPECT_TRUE(engine_.FindWebRtcCodec(kIsacCodec, &codec_inst));
405 // Find telephone-event with explicit clockrate and 0 bitrate.
406 EXPECT_TRUE(engine_.FindWebRtcCodec(kTelephoneEventCodec, &codec_inst));
407 // Find ISAC with a different payload id.
408 codec = kIsacCodec;
409 codec.id = 127;
410 EXPECT_TRUE(engine_.FindWebRtcCodec(codec, &codec_inst));
411 EXPECT_EQ(codec.id, codec_inst.pltype);
412 // Find PCMU with a 0 clockrate.
413 codec = kPcmuCodec;
414 codec.clockrate = 0;
415 EXPECT_TRUE(engine_.FindWebRtcCodec(codec, &codec_inst));
416 EXPECT_EQ(codec.id, codec_inst.pltype);
417 EXPECT_EQ(8000, codec_inst.plfreq);
418 // Find PCMU with a 0 bitrate.
419 codec = kPcmuCodec;
420 codec.bitrate = 0;
421 EXPECT_TRUE(engine_.FindWebRtcCodec(codec, &codec_inst));
422 EXPECT_EQ(codec.id, codec_inst.pltype);
423 EXPECT_EQ(64000, codec_inst.rate);
424 // Find ISAC with an explicit bitrate.
425 codec = kIsacCodec;
426 codec.bitrate = 32000;
427 EXPECT_TRUE(engine_.FindWebRtcCodec(codec, &codec_inst));
428 EXPECT_EQ(codec.id, codec_inst.pltype);
429 EXPECT_EQ(32000, codec_inst.rate);
430}
431
432// Test that we set our inbound codecs properly, including changing PT.
433TEST_F(WebRtcVoiceEngineTestFake, SetRecvCodecs) {
434 EXPECT_TRUE(SetupEngine());
435 int channel_num = voe_.GetLastChannel();
436 std::vector<cricket::AudioCodec> codecs;
437 codecs.push_back(kIsacCodec);
438 codecs.push_back(kPcmuCodec);
439 codecs.push_back(kTelephoneEventCodec);
440 codecs[0].id = 106; // collide with existing telephone-event
441 codecs[2].id = 126;
442 EXPECT_TRUE(channel_->SetRecvCodecs(codecs));
443 webrtc::CodecInst gcodec;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000444 rtc::strcpyn(gcodec.plname, ARRAY_SIZE(gcodec.plname), "ISAC");
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000445 gcodec.plfreq = 16000;
446 gcodec.channels = 1;
447 EXPECT_EQ(0, voe_.GetRecPayloadType(channel_num, gcodec));
448 EXPECT_EQ(106, gcodec.pltype);
449 EXPECT_STREQ("ISAC", gcodec.plname);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000450 rtc::strcpyn(gcodec.plname, ARRAY_SIZE(gcodec.plname),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000451 "telephone-event");
452 gcodec.plfreq = 8000;
453 EXPECT_EQ(0, voe_.GetRecPayloadType(channel_num, gcodec));
454 EXPECT_EQ(126, gcodec.pltype);
455 EXPECT_STREQ("telephone-event", gcodec.plname);
456}
457
458// Test that we fail to set an unknown inbound codec.
459TEST_F(WebRtcVoiceEngineTestFake, SetRecvCodecsUnsupportedCodec) {
460 EXPECT_TRUE(SetupEngine());
461 std::vector<cricket::AudioCodec> codecs;
462 codecs.push_back(kIsacCodec);
463 codecs.push_back(cricket::AudioCodec(127, "XYZ", 32000, 0, 1, 0));
464 EXPECT_FALSE(channel_->SetRecvCodecs(codecs));
465}
466
467// Test that we fail if we have duplicate types in the inbound list.
468TEST_F(WebRtcVoiceEngineTestFake, SetRecvCodecsDuplicatePayloadType) {
469 EXPECT_TRUE(SetupEngine());
470 std::vector<cricket::AudioCodec> codecs;
471 codecs.push_back(kIsacCodec);
472 codecs.push_back(kCn16000Codec);
473 codecs[1].id = kIsacCodec.id;
474 EXPECT_FALSE(channel_->SetRecvCodecs(codecs));
475}
476
477// Test that we can decode OPUS without stereo parameters.
478TEST_F(WebRtcVoiceEngineTestFake, SetRecvCodecsWithOpusNoStereo) {
479 EXPECT_TRUE(SetupEngine());
480 EXPECT_TRUE(channel_->SetOptions(options_conference_));
481 std::vector<cricket::AudioCodec> codecs;
482 codecs.push_back(kIsacCodec);
483 codecs.push_back(kPcmuCodec);
484 codecs.push_back(kOpusCodec);
485 EXPECT_TRUE(channel_->SetRecvCodecs(codecs));
486 EXPECT_TRUE(channel_->AddRecvStream(
487 cricket::StreamParams::CreateLegacy(kSsrc1)));
488 int channel_num2 = voe_.GetLastChannel();
489 webrtc::CodecInst opus;
490 engine_.FindWebRtcCodec(kOpusCodec, &opus);
491 // Even without stereo parameters, recv codecs still specify channels = 2.
492 EXPECT_EQ(2, opus.channels);
493 EXPECT_EQ(111, opus.pltype);
494 EXPECT_STREQ("opus", opus.plname);
495 opus.pltype = 0;
496 EXPECT_EQ(0, voe_.GetRecPayloadType(channel_num2, opus));
497 EXPECT_EQ(111, opus.pltype);
498}
499
500// Test that we can decode OPUS with stereo = 0.
501TEST_F(WebRtcVoiceEngineTestFake, SetRecvCodecsWithOpus0Stereo) {
502 EXPECT_TRUE(SetupEngine());
503 EXPECT_TRUE(channel_->SetOptions(options_conference_));
504 std::vector<cricket::AudioCodec> codecs;
505 codecs.push_back(kIsacCodec);
506 codecs.push_back(kPcmuCodec);
507 codecs.push_back(kOpusCodec);
508 codecs[2].params["stereo"] = "0";
509 EXPECT_TRUE(channel_->SetRecvCodecs(codecs));
510 EXPECT_TRUE(channel_->AddRecvStream(
511 cricket::StreamParams::CreateLegacy(kSsrc1)));
512 int channel_num2 = voe_.GetLastChannel();
513 webrtc::CodecInst opus;
514 engine_.FindWebRtcCodec(kOpusCodec, &opus);
515 // Even when stereo is off, recv codecs still specify channels = 2.
516 EXPECT_EQ(2, opus.channels);
517 EXPECT_EQ(111, opus.pltype);
518 EXPECT_STREQ("opus", opus.plname);
519 opus.pltype = 0;
520 EXPECT_EQ(0, voe_.GetRecPayloadType(channel_num2, opus));
521 EXPECT_EQ(111, opus.pltype);
522}
523
524// Test that we can decode OPUS with stereo = 1.
525TEST_F(WebRtcVoiceEngineTestFake, SetRecvCodecsWithOpus1Stereo) {
526 EXPECT_TRUE(SetupEngine());
527 EXPECT_TRUE(channel_->SetOptions(options_conference_));
528 std::vector<cricket::AudioCodec> codecs;
529 codecs.push_back(kIsacCodec);
530 codecs.push_back(kPcmuCodec);
531 codecs.push_back(kOpusCodec);
532 codecs[2].params["stereo"] = "1";
533 EXPECT_TRUE(channel_->SetRecvCodecs(codecs));
534 EXPECT_TRUE(channel_->AddRecvStream(
535 cricket::StreamParams::CreateLegacy(kSsrc1)));
536 int channel_num2 = voe_.GetLastChannel();
537 webrtc::CodecInst opus;
538 engine_.FindWebRtcCodec(kOpusCodec, &opus);
539 EXPECT_EQ(2, opus.channels);
540 EXPECT_EQ(111, opus.pltype);
541 EXPECT_STREQ("opus", opus.plname);
542 opus.pltype = 0;
543 EXPECT_EQ(0, voe_.GetRecPayloadType(channel_num2, opus));
544 EXPECT_EQ(111, opus.pltype);
545}
546
547// Test that changes to recv codecs are applied to all streams.
548TEST_F(WebRtcVoiceEngineTestFake, SetRecvCodecsWithMultipleStreams) {
549 EXPECT_TRUE(SetupEngine());
550 EXPECT_TRUE(channel_->SetOptions(options_conference_));
551 std::vector<cricket::AudioCodec> codecs;
552 codecs.push_back(kIsacCodec);
553 codecs.push_back(kPcmuCodec);
554 codecs.push_back(kTelephoneEventCodec);
555 codecs[0].id = 106; // collide with existing telephone-event
556 codecs[2].id = 126;
557 EXPECT_TRUE(channel_->SetRecvCodecs(codecs));
558 EXPECT_TRUE(channel_->AddRecvStream(
559 cricket::StreamParams::CreateLegacy(kSsrc1)));
560 int channel_num2 = voe_.GetLastChannel();
561 webrtc::CodecInst gcodec;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000562 rtc::strcpyn(gcodec.plname, ARRAY_SIZE(gcodec.plname), "ISAC");
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000563 gcodec.plfreq = 16000;
564 gcodec.channels = 1;
565 EXPECT_EQ(0, voe_.GetRecPayloadType(channel_num2, gcodec));
566 EXPECT_EQ(106, gcodec.pltype);
567 EXPECT_STREQ("ISAC", gcodec.plname);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000568 rtc::strcpyn(gcodec.plname, ARRAY_SIZE(gcodec.plname),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000569 "telephone-event");
570 gcodec.plfreq = 8000;
571 gcodec.channels = 1;
572 EXPECT_EQ(0, voe_.GetRecPayloadType(channel_num2, gcodec));
573 EXPECT_EQ(126, gcodec.pltype);
574 EXPECT_STREQ("telephone-event", gcodec.plname);
575}
576
577TEST_F(WebRtcVoiceEngineTestFake, SetRecvCodecsAfterAddingStreams) {
578 EXPECT_TRUE(SetupEngine());
579 EXPECT_TRUE(channel_->SetOptions(options_conference_));
580 std::vector<cricket::AudioCodec> codecs;
581 codecs.push_back(kIsacCodec);
582 codecs[0].id = 106; // collide with existing telephone-event
583
584 EXPECT_TRUE(channel_->AddRecvStream(
585 cricket::StreamParams::CreateLegacy(kSsrc1)));
586 EXPECT_TRUE(channel_->SetRecvCodecs(codecs));
587
588 int channel_num2 = voe_.GetLastChannel();
589 webrtc::CodecInst gcodec;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000590 rtc::strcpyn(gcodec.plname, ARRAY_SIZE(gcodec.plname), "ISAC");
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000591 gcodec.plfreq = 16000;
592 gcodec.channels = 1;
593 EXPECT_EQ(0, voe_.GetRecPayloadType(channel_num2, gcodec));
594 EXPECT_EQ(106, gcodec.pltype);
595 EXPECT_STREQ("ISAC", gcodec.plname);
596}
597
598// Test that we can apply the same set of codecs again while playing.
599TEST_F(WebRtcVoiceEngineTestFake, SetRecvCodecsWhilePlaying) {
600 EXPECT_TRUE(SetupEngine());
601 int channel_num = voe_.GetLastChannel();
602 std::vector<cricket::AudioCodec> codecs;
603 codecs.push_back(kIsacCodec);
604 codecs.push_back(kCn16000Codec);
605 EXPECT_TRUE(channel_->SetRecvCodecs(codecs));
606 EXPECT_TRUE(channel_->SetPlayout(true));
607 EXPECT_TRUE(channel_->SetRecvCodecs(codecs));
608
609 // Changing the payload type of a codec should fail.
610 codecs[0].id = 127;
611 EXPECT_FALSE(channel_->SetRecvCodecs(codecs));
612 EXPECT_TRUE(voe_.GetPlayout(channel_num));
613}
614
615// Test that we can add a codec while playing.
616TEST_F(WebRtcVoiceEngineTestFake, AddRecvCodecsWhilePlaying) {
617 EXPECT_TRUE(SetupEngine());
618 int channel_num = voe_.GetLastChannel();
619 std::vector<cricket::AudioCodec> codecs;
620 codecs.push_back(kIsacCodec);
621 codecs.push_back(kCn16000Codec);
622 EXPECT_TRUE(channel_->SetRecvCodecs(codecs));
623 EXPECT_TRUE(channel_->SetPlayout(true));
624
625 codecs.push_back(kOpusCodec);
626 EXPECT_TRUE(channel_->SetRecvCodecs(codecs));
627 EXPECT_TRUE(voe_.GetPlayout(channel_num));
628 webrtc::CodecInst gcodec;
629 EXPECT_TRUE(engine_.FindWebRtcCodec(kOpusCodec, &gcodec));
630 EXPECT_EQ(kOpusCodec.id, gcodec.pltype);
631}
632
633TEST_F(WebRtcVoiceEngineTestFake, SetSendBandwidthAuto) {
634 EXPECT_TRUE(SetupEngine());
635 EXPECT_TRUE(channel_->SetSendCodecs(engine_.codecs()));
636
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000637 // Test that when autobw is enabled, bitrate is kept as the default
638 // value. autobw is enabled for the following tests because the target
639 // bitrate is <= 0.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000640
641 // ISAC, default bitrate == 32000.
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000642 TestSendBandwidth(kIsacCodec, 0, true, 32000);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000643
644 // PCMU, default bitrate == 64000.
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000645 TestSendBandwidth(kPcmuCodec, -1, true, 64000);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000646
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000647 // opus, default bitrate == 64000.
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000648 TestSendBandwidth(kOpusCodec, -1, true, 64000);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000649}
650
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000651TEST_F(WebRtcVoiceEngineTestFake, SetMaxSendBandwidthMultiRateAsCaller) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000652 EXPECT_TRUE(SetupEngine());
653 EXPECT_TRUE(channel_->SetSendCodecs(engine_.codecs()));
654
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000655 // Test that the bitrate of a multi-rate codec is always the maximum.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000656
657 // ISAC, default bitrate == 32000.
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000658 TestSendBandwidth(kIsacCodec, 128000, true, 128000);
659 TestSendBandwidth(kIsacCodec, 16000, true, 16000);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000660
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000661 // opus, default bitrate == 64000.
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000662 TestSendBandwidth(kOpusCodec, 96000, true, 96000);
663 TestSendBandwidth(kOpusCodec, 48000, true, 48000);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000664}
665
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000666TEST_F(WebRtcVoiceEngineTestFake, SetMaxSendBandwidthFixedRateAsCaller) {
667 EXPECT_TRUE(SetupEngine());
668 EXPECT_TRUE(channel_->SetSendCodecs(engine_.codecs()));
669
670 // Test that we can only set a maximum bitrate for a fixed-rate codec
671 // if it's bigger than the fixed rate.
672
673 // PCMU, fixed bitrate == 64000.
674 TestSendBandwidth(kPcmuCodec, 0, true, 64000);
675 TestSendBandwidth(kPcmuCodec, 1, false, 64000);
676 TestSendBandwidth(kPcmuCodec, 128000, true, 64000);
677 TestSendBandwidth(kPcmuCodec, 32000, false, 64000);
678 TestSendBandwidth(kPcmuCodec, 64000, true, 64000);
679 TestSendBandwidth(kPcmuCodec, 63999, false, 64000);
680 TestSendBandwidth(kPcmuCodec, 64001, true, 64000);
681}
682
683TEST_F(WebRtcVoiceEngineTestFake, SetMaxSendBandwidthMultiRateAsCallee) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000684 EXPECT_TRUE(engine_.Init(rtc::Thread::Current()));
wu@webrtc.org1d1ffc92013-10-16 18:12:02 +0000685 channel_ = engine_.CreateChannel();
686 EXPECT_TRUE(channel_ != NULL);
687 EXPECT_TRUE(channel_->SetSendCodecs(engine_.codecs()));
688
689 int desired_bitrate = 128000;
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000690 EXPECT_TRUE(channel_->SetMaxSendBandwidth(desired_bitrate));
wu@webrtc.org1d1ffc92013-10-16 18:12:02 +0000691
692 EXPECT_TRUE(channel_->AddSendStream(
693 cricket::StreamParams::CreateLegacy(kSsrc1)));
694
695 int channel_num = voe_.GetLastChannel();
696 webrtc::CodecInst codec;
697 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, codec));
698 EXPECT_EQ(desired_bitrate, codec.rate);
699}
700
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000701// Test that bitrate cannot be set for CBR codecs.
702// Bitrate is ignored if it is higher than the fixed bitrate.
703// Bitrate less then the fixed bitrate is an error.
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000704TEST_F(WebRtcVoiceEngineTestFake, SetMaxSendBandwidthCbr) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000705 EXPECT_TRUE(SetupEngine());
706 EXPECT_TRUE(channel_->SetSendCodecs(engine_.codecs()));
707
708 webrtc::CodecInst codec;
709 int channel_num = voe_.GetLastChannel();
710 std::vector<cricket::AudioCodec> codecs;
711
712 // PCMU, default bitrate == 64000.
713 codecs.push_back(kPcmuCodec);
714 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
715 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, codec));
716 EXPECT_EQ(64000, codec.rate);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000717 EXPECT_TRUE(channel_->SetMaxSendBandwidth(128000));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000718 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, codec));
719 EXPECT_EQ(64000, codec.rate);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000720 EXPECT_FALSE(channel_->SetMaxSendBandwidth(128));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000721 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, codec));
722 EXPECT_EQ(64000, codec.rate);
723}
724
725// Test that we apply codecs properly.
726TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecs) {
727 EXPECT_TRUE(SetupEngine());
728 int channel_num = voe_.GetLastChannel();
729 std::vector<cricket::AudioCodec> codecs;
730 codecs.push_back(kIsacCodec);
731 codecs.push_back(kPcmuCodec);
732 codecs.push_back(kRedCodec);
733 codecs[0].id = 96;
734 codecs[0].bitrate = 48000;
735 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
wu@webrtc.org05e7b442014-04-01 17:44:24 +0000736 EXPECT_EQ(1, voe_.GetNumSetSendCodecs());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000737 webrtc::CodecInst gcodec;
738 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
739 EXPECT_EQ(96, gcodec.pltype);
740 EXPECT_EQ(48000, gcodec.rate);
741 EXPECT_STREQ("ISAC", gcodec.plname);
742 EXPECT_FALSE(voe_.GetVAD(channel_num));
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +0000743 EXPECT_FALSE(voe_.GetRED(channel_num));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000744 EXPECT_EQ(13, voe_.GetSendCNPayloadType(channel_num, false));
745 EXPECT_EQ(105, voe_.GetSendCNPayloadType(channel_num, true));
746 EXPECT_EQ(106, voe_.GetSendTelephoneEventPayloadType(channel_num));
747}
748
wu@webrtc.org05e7b442014-04-01 17:44:24 +0000749// Test that VoE Channel doesn't call SetSendCodec again if same codec is tried
750// to apply.
751TEST_F(WebRtcVoiceEngineTestFake, DontResetSetSendCodec) {
752 EXPECT_TRUE(SetupEngine());
753 std::vector<cricket::AudioCodec> codecs;
754 codecs.push_back(kIsacCodec);
755 codecs.push_back(kPcmuCodec);
756 codecs.push_back(kRedCodec);
757 codecs[0].id = 96;
758 codecs[0].bitrate = 48000;
759 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
760 EXPECT_EQ(1, voe_.GetNumSetSendCodecs());
761 // Calling SetSendCodec again with same codec which is already set.
762 // In this case media channel shouldn't send codec to VoE.
763 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
764 EXPECT_EQ(1, voe_.GetNumSetSendCodecs());
765}
766
henrik.lundin@webrtc.orgf85dbce2014-11-07 12:25:00 +0000767// Verify that G722 is set with 16000 samples per second to WebRTC.
768TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecG722) {
769 EXPECT_TRUE(SetupEngine());
770 int channel_num = voe_.GetLastChannel();
771 std::vector<cricket::AudioCodec> codecs;
772 codecs.push_back(kG722CodecSdp);
773 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
774 webrtc::CodecInst gcodec;
775 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
776 EXPECT_STREQ("G722", gcodec.plname);
777 EXPECT_EQ(1, gcodec.channels);
778 EXPECT_EQ(16000, gcodec.plfreq);
779}
780
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000781// Test that if clockrate is not 48000 for opus, we fail.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000782TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecOpusBadClockrate) {
783 EXPECT_TRUE(SetupEngine());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000784 std::vector<cricket::AudioCodec> codecs;
785 codecs.push_back(kOpusCodec);
786 codecs[0].bitrate = 0;
787 codecs[0].clockrate = 50000;
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000788 EXPECT_FALSE(channel_->SetSendCodecs(codecs));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000789}
790
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000791// Test that if channels=0 for opus, we fail.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000792TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecOpusBad0ChannelsNoStereo) {
793 EXPECT_TRUE(SetupEngine());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000794 std::vector<cricket::AudioCodec> codecs;
795 codecs.push_back(kOpusCodec);
796 codecs[0].bitrate = 0;
797 codecs[0].channels = 0;
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000798 EXPECT_FALSE(channel_->SetSendCodecs(codecs));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000799}
800
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000801// Test that if channels=0 for opus, we fail.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000802TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecOpusBad0Channels1Stereo) {
803 EXPECT_TRUE(SetupEngine());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000804 std::vector<cricket::AudioCodec> codecs;
805 codecs.push_back(kOpusCodec);
806 codecs[0].bitrate = 0;
807 codecs[0].channels = 0;
808 codecs[0].params["stereo"] = "1";
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000809 EXPECT_FALSE(channel_->SetSendCodecs(codecs));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000810}
811
812// Test that if channel is 1 for opus and there's no stereo, we fail.
813TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecOpus1ChannelNoStereo) {
814 EXPECT_TRUE(SetupEngine());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000815 std::vector<cricket::AudioCodec> codecs;
816 codecs.push_back(kOpusCodec);
817 codecs[0].bitrate = 0;
818 codecs[0].channels = 1;
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000819 EXPECT_FALSE(channel_->SetSendCodecs(codecs));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000820}
821
822// Test that if channel is 1 for opus and stereo=0, we fail.
823TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecOpusBad1Channel0Stereo) {
824 EXPECT_TRUE(SetupEngine());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000825 std::vector<cricket::AudioCodec> codecs;
826 codecs.push_back(kOpusCodec);
827 codecs[0].bitrate = 0;
828 codecs[0].channels = 1;
829 codecs[0].params["stereo"] = "0";
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000830 EXPECT_FALSE(channel_->SetSendCodecs(codecs));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000831}
832
833// Test that if channel is 1 for opus and stereo=1, we fail.
834TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecOpusBad1Channel1Stereo) {
835 EXPECT_TRUE(SetupEngine());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000836 std::vector<cricket::AudioCodec> codecs;
837 codecs.push_back(kOpusCodec);
838 codecs[0].bitrate = 0;
839 codecs[0].channels = 1;
840 codecs[0].params["stereo"] = "1";
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000841 EXPECT_FALSE(channel_->SetSendCodecs(codecs));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000842}
843
844// Test that with bitrate=0 and no stereo,
845// channels and bitrate are 1 and 32000.
846TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecOpusGood0BitrateNoStereo) {
847 EXPECT_TRUE(SetupEngine());
848 int channel_num = voe_.GetLastChannel();
849 std::vector<cricket::AudioCodec> codecs;
850 codecs.push_back(kOpusCodec);
851 codecs[0].bitrate = 0;
852 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
853 webrtc::CodecInst gcodec;
854 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
855 EXPECT_STREQ("opus", gcodec.plname);
856 EXPECT_EQ(1, gcodec.channels);
857 EXPECT_EQ(32000, gcodec.rate);
858}
859
860// Test that with bitrate=0 and stereo=0,
861// channels and bitrate are 1 and 32000.
862TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecOpusGood0Bitrate0Stereo) {
863 EXPECT_TRUE(SetupEngine());
864 int channel_num = voe_.GetLastChannel();
865 std::vector<cricket::AudioCodec> codecs;
866 codecs.push_back(kOpusCodec);
867 codecs[0].bitrate = 0;
868 codecs[0].params["stereo"] = "0";
869 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
870 webrtc::CodecInst gcodec;
871 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
872 EXPECT_STREQ("opus", gcodec.plname);
873 EXPECT_EQ(1, gcodec.channels);
874 EXPECT_EQ(32000, gcodec.rate);
875}
876
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000877// Test that with bitrate=invalid and stereo=0,
878// channels and bitrate are 1 and 32000.
879TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecOpusGoodXBitrate0Stereo) {
880 EXPECT_TRUE(SetupEngine());
881 int channel_num = voe_.GetLastChannel();
882 std::vector<cricket::AudioCodec> codecs;
883 codecs.push_back(kOpusCodec);
884 codecs[0].params["stereo"] = "0";
885 webrtc::CodecInst gcodec;
886
buildbot@webrtc.org9d446f22014-10-23 12:22:06 +0000887 // bitrate that's out of the range between 6000 and 510000 will be clamped.
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000888 codecs[0].bitrate = 5999;
889 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
890 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
891 EXPECT_STREQ("opus", gcodec.plname);
892 EXPECT_EQ(1, gcodec.channels);
buildbot@webrtc.org9d446f22014-10-23 12:22:06 +0000893 EXPECT_EQ(6000, gcodec.rate);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000894
895 codecs[0].bitrate = 510001;
896 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
897 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
898 EXPECT_STREQ("opus", gcodec.plname);
899 EXPECT_EQ(1, gcodec.channels);
buildbot@webrtc.org9d446f22014-10-23 12:22:06 +0000900 EXPECT_EQ(510000, gcodec.rate);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000901}
902
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000903// Test that with bitrate=0 and stereo=1,
904// channels and bitrate are 2 and 64000.
905TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecOpusGood0Bitrate1Stereo) {
906 EXPECT_TRUE(SetupEngine());
907 int channel_num = voe_.GetLastChannel();
908 std::vector<cricket::AudioCodec> codecs;
909 codecs.push_back(kOpusCodec);
910 codecs[0].bitrate = 0;
911 codecs[0].params["stereo"] = "1";
912 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
913 webrtc::CodecInst gcodec;
914 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
915 EXPECT_STREQ("opus", gcodec.plname);
916 EXPECT_EQ(2, gcodec.channels);
917 EXPECT_EQ(64000, gcodec.rate);
918}
919
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000920// Test that with bitrate=invalid and stereo=1,
921// channels and bitrate are 2 and 64000.
922TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecOpusGoodXBitrate1Stereo) {
923 EXPECT_TRUE(SetupEngine());
924 int channel_num = voe_.GetLastChannel();
925 std::vector<cricket::AudioCodec> codecs;
926 codecs.push_back(kOpusCodec);
927 codecs[0].params["stereo"] = "1";
928 webrtc::CodecInst gcodec;
929
buildbot@webrtc.org9d446f22014-10-23 12:22:06 +0000930 // bitrate that's out of the range between 6000 and 510000 will be clamped.
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000931 codecs[0].bitrate = 5999;
932 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
933 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
934 EXPECT_STREQ("opus", gcodec.plname);
935 EXPECT_EQ(2, gcodec.channels);
buildbot@webrtc.org9d446f22014-10-23 12:22:06 +0000936 EXPECT_EQ(6000, gcodec.rate);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000937
938 codecs[0].bitrate = 510001;
939 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
940 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
941 EXPECT_STREQ("opus", gcodec.plname);
942 EXPECT_EQ(2, gcodec.channels);
buildbot@webrtc.org9d446f22014-10-23 12:22:06 +0000943 EXPECT_EQ(510000, gcodec.rate);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000944}
945
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000946// Test that with bitrate=N and stereo unset,
947// channels and bitrate are 1 and N.
948TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecOpusGoodNBitrateNoStereo) {
949 EXPECT_TRUE(SetupEngine());
950 int channel_num = voe_.GetLastChannel();
951 std::vector<cricket::AudioCodec> codecs;
952 codecs.push_back(kOpusCodec);
953 codecs[0].bitrate = 96000;
954 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
955 webrtc::CodecInst gcodec;
956 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
957 EXPECT_EQ(111, gcodec.pltype);
958 EXPECT_EQ(96000, gcodec.rate);
959 EXPECT_STREQ("opus", gcodec.plname);
960 EXPECT_EQ(1, gcodec.channels);
961 EXPECT_EQ(48000, gcodec.plfreq);
962}
963
964// Test that with bitrate=N and stereo=0,
965// channels and bitrate are 1 and N.
966TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecOpusGoodNBitrate0Stereo) {
967 EXPECT_TRUE(SetupEngine());
968 int channel_num = voe_.GetLastChannel();
969 std::vector<cricket::AudioCodec> codecs;
970 codecs.push_back(kOpusCodec);
971 codecs[0].bitrate = 30000;
972 codecs[0].params["stereo"] = "0";
973 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
974 webrtc::CodecInst gcodec;
975 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
976 EXPECT_EQ(1, gcodec.channels);
977 EXPECT_EQ(30000, gcodec.rate);
978 EXPECT_STREQ("opus", gcodec.plname);
979}
980
981// Test that with bitrate=N and without any parameters,
982// channels and bitrate are 1 and N.
983TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecOpusGoodNBitrateNoParameters) {
984 EXPECT_TRUE(SetupEngine());
985 int channel_num = voe_.GetLastChannel();
986 std::vector<cricket::AudioCodec> codecs;
987 codecs.push_back(kOpusCodec);
988 codecs[0].bitrate = 30000;
989 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
990 webrtc::CodecInst gcodec;
991 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
992 EXPECT_EQ(1, gcodec.channels);
993 EXPECT_EQ(30000, gcodec.rate);
994 EXPECT_STREQ("opus", gcodec.plname);
995}
996
997// Test that with bitrate=N and stereo=1,
998// channels and bitrate are 2 and N.
999TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecOpusGoodNBitrate1Stereo) {
1000 EXPECT_TRUE(SetupEngine());
1001 int channel_num = voe_.GetLastChannel();
1002 std::vector<cricket::AudioCodec> codecs;
1003 codecs.push_back(kOpusCodec);
1004 codecs[0].bitrate = 30000;
1005 codecs[0].params["stereo"] = "1";
1006 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1007 webrtc::CodecInst gcodec;
1008 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1009 EXPECT_EQ(2, gcodec.channels);
1010 EXPECT_EQ(30000, gcodec.rate);
1011 EXPECT_STREQ("opus", gcodec.plname);
1012}
1013
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00001014// Test that bitrate will be overridden by the "maxaveragebitrate" parameter.
1015// Also test that the "maxaveragebitrate" can't be set to values outside the
1016// range of 6000 and 510000
1017TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecOpusMaxAverageBitrate) {
1018 EXPECT_TRUE(SetupEngine());
1019 int channel_num = voe_.GetLastChannel();
1020 std::vector<cricket::AudioCodec> codecs;
1021 codecs.push_back(kOpusCodec);
1022 codecs[0].bitrate = 30000;
1023 webrtc::CodecInst gcodec;
1024
1025 // Ignore if less than 6000.
1026 codecs[0].params["maxaveragebitrate"] = "5999";
1027 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1028 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
buildbot@webrtc.org9d446f22014-10-23 12:22:06 +00001029 EXPECT_EQ(6000, gcodec.rate);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00001030
1031 // Ignore if larger than 510000.
1032 codecs[0].params["maxaveragebitrate"] = "510001";
1033 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1034 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
buildbot@webrtc.org9d446f22014-10-23 12:22:06 +00001035 EXPECT_EQ(510000, gcodec.rate);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00001036
1037 codecs[0].params["maxaveragebitrate"] = "200000";
1038 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1039 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1040 EXPECT_EQ(200000, gcodec.rate);
1041}
1042
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00001043// Test that we can enable NACK with opus as caller.
1044TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecEnableNackAsCaller) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001045 EXPECT_TRUE(SetupEngine());
1046 int channel_num = voe_.GetLastChannel();
1047 std::vector<cricket::AudioCodec> codecs;
1048 codecs.push_back(kOpusCodec);
1049 codecs[0].AddFeedbackParam(cricket::FeedbackParam(cricket::kRtcpFbParamNack,
1050 cricket::kParamValueEmpty));
1051 EXPECT_FALSE(voe_.GetNACK(channel_num));
1052 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1053 EXPECT_TRUE(voe_.GetNACK(channel_num));
1054}
1055
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00001056// Test that we can enable NACK with opus as callee.
1057TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecEnableNackAsCallee) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001058 EXPECT_TRUE(engine_.Init(rtc::Thread::Current()));
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00001059 channel_ = engine_.CreateChannel();
1060 EXPECT_TRUE(channel_ != NULL);
1061
1062 int channel_num = voe_.GetLastChannel();
1063 std::vector<cricket::AudioCodec> codecs;
1064 codecs.push_back(kOpusCodec);
1065 codecs[0].AddFeedbackParam(cricket::FeedbackParam(cricket::kRtcpFbParamNack,
1066 cricket::kParamValueEmpty));
1067 EXPECT_FALSE(voe_.GetNACK(channel_num));
1068 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1069 EXPECT_FALSE(voe_.GetNACK(channel_num));
1070
1071 EXPECT_TRUE(channel_->AddSendStream(
1072 cricket::StreamParams::CreateLegacy(kSsrc1)));
1073 EXPECT_TRUE(voe_.GetNACK(channel_num));
1074}
1075
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001076// Test that we can enable NACK on receive streams.
1077TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecEnableNackRecvStreams) {
1078 EXPECT_TRUE(SetupEngine());
1079 EXPECT_TRUE(channel_->SetOptions(options_conference_));
1080 int channel_num1 = voe_.GetLastChannel();
1081 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(2)));
1082 int channel_num2 = voe_.GetLastChannel();
1083 std::vector<cricket::AudioCodec> codecs;
1084 codecs.push_back(kOpusCodec);
1085 codecs[0].AddFeedbackParam(cricket::FeedbackParam(cricket::kRtcpFbParamNack,
1086 cricket::kParamValueEmpty));
1087 EXPECT_FALSE(voe_.GetNACK(channel_num1));
1088 EXPECT_FALSE(voe_.GetNACK(channel_num2));
1089 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1090 EXPECT_TRUE(voe_.GetNACK(channel_num1));
1091 EXPECT_TRUE(voe_.GetNACK(channel_num2));
1092}
1093
1094// Test that we can disable NACK.
1095TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecDisableNack) {
1096 EXPECT_TRUE(SetupEngine());
1097 int channel_num = voe_.GetLastChannel();
1098 std::vector<cricket::AudioCodec> codecs;
1099 codecs.push_back(kOpusCodec);
1100 codecs[0].AddFeedbackParam(cricket::FeedbackParam(cricket::kRtcpFbParamNack,
1101 cricket::kParamValueEmpty));
1102 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1103 EXPECT_TRUE(voe_.GetNACK(channel_num));
1104
1105 codecs.clear();
1106 codecs.push_back(kOpusCodec);
1107 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1108 EXPECT_FALSE(voe_.GetNACK(channel_num));
1109}
1110
1111// Test that we can disable NACK on receive streams.
1112TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecDisableNackRecvStreams) {
1113 EXPECT_TRUE(SetupEngine());
1114 EXPECT_TRUE(channel_->SetOptions(options_conference_));
1115 int channel_num1 = voe_.GetLastChannel();
1116 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(2)));
1117 int channel_num2 = voe_.GetLastChannel();
1118 std::vector<cricket::AudioCodec> codecs;
1119 codecs.push_back(kOpusCodec);
1120 codecs[0].AddFeedbackParam(cricket::FeedbackParam(cricket::kRtcpFbParamNack,
1121 cricket::kParamValueEmpty));
1122 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1123 EXPECT_TRUE(voe_.GetNACK(channel_num1));
1124 EXPECT_TRUE(voe_.GetNACK(channel_num2));
1125
1126 codecs.clear();
1127 codecs.push_back(kOpusCodec);
1128 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1129 EXPECT_FALSE(voe_.GetNACK(channel_num1));
1130 EXPECT_FALSE(voe_.GetNACK(channel_num2));
1131}
1132
1133// Test that NACK is enabled on a new receive stream.
1134TEST_F(WebRtcVoiceEngineTestFake, AddRecvStreamEnableNack) {
1135 EXPECT_TRUE(SetupEngine());
1136 EXPECT_TRUE(channel_->SetOptions(options_conference_));
1137 int channel_num = voe_.GetLastChannel();
1138 std::vector<cricket::AudioCodec> codecs;
1139 codecs.push_back(kIsacCodec);
1140 codecs[0].AddFeedbackParam(cricket::FeedbackParam(cricket::kRtcpFbParamNack,
1141 cricket::kParamValueEmpty));
1142 codecs.push_back(kCn16000Codec);
1143 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1144 EXPECT_TRUE(voe_.GetNACK(channel_num));
1145
1146 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(2)));
1147 channel_num = voe_.GetLastChannel();
1148 EXPECT_TRUE(voe_.GetNACK(channel_num));
1149 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(3)));
1150 channel_num = voe_.GetLastChannel();
1151 EXPECT_TRUE(voe_.GetNACK(channel_num));
1152}
1153
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +00001154// Test that without useinbandfec, Opus FEC is off.
buildbot@webrtc.orgd27d9ae2014-06-19 01:56:46 +00001155TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecNoOpusFec) {
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +00001156 EXPECT_TRUE(SetupEngine());
1157 int channel_num = voe_.GetLastChannel();
1158 std::vector<cricket::AudioCodec> codecs;
1159 codecs.push_back(kOpusCodec);
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +00001160 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1161 EXPECT_FALSE(voe_.GetCodecFEC(channel_num));
1162}
1163
1164// Test that with useinbandfec=0, Opus FEC is off.
buildbot@webrtc.orgd27d9ae2014-06-19 01:56:46 +00001165TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecOpusDisableFec) {
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +00001166 EXPECT_TRUE(SetupEngine());
1167 int channel_num = voe_.GetLastChannel();
1168 std::vector<cricket::AudioCodec> codecs;
1169 codecs.push_back(kOpusCodec);
1170 codecs[0].bitrate = 0;
1171 codecs[0].params["useinbandfec"] = "0";
1172 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1173 EXPECT_FALSE(voe_.GetCodecFEC(channel_num));
1174 webrtc::CodecInst gcodec;
1175 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1176 EXPECT_STREQ("opus", gcodec.plname);
1177 EXPECT_EQ(1, gcodec.channels);
1178 EXPECT_EQ(32000, gcodec.rate);
1179}
1180
1181// Test that with useinbandfec=1, Opus FEC is on.
buildbot@webrtc.orgd27d9ae2014-06-19 01:56:46 +00001182TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecOpusEnableFec) {
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +00001183 EXPECT_TRUE(SetupEngine());
1184 int channel_num = voe_.GetLastChannel();
1185 std::vector<cricket::AudioCodec> codecs;
1186 codecs.push_back(kOpusCodec);
1187 codecs[0].bitrate = 0;
1188 codecs[0].params["useinbandfec"] = "1";
1189 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1190 EXPECT_TRUE(voe_.GetCodecFEC(channel_num));
1191 webrtc::CodecInst gcodec;
1192 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1193 EXPECT_STREQ("opus", gcodec.plname);
1194 EXPECT_EQ(1, gcodec.channels);
1195 EXPECT_EQ(32000, gcodec.rate);
1196}
1197
1198// Test that with useinbandfec=1, stereo=1, Opus FEC is on.
buildbot@webrtc.orgd27d9ae2014-06-19 01:56:46 +00001199TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecOpusEnableFecStereo) {
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +00001200 EXPECT_TRUE(SetupEngine());
1201 int channel_num = voe_.GetLastChannel();
1202 std::vector<cricket::AudioCodec> codecs;
1203 codecs.push_back(kOpusCodec);
1204 codecs[0].bitrate = 0;
1205 codecs[0].params["stereo"] = "1";
1206 codecs[0].params["useinbandfec"] = "1";
1207 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1208 EXPECT_TRUE(voe_.GetCodecFEC(channel_num));
1209 webrtc::CodecInst gcodec;
1210 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1211 EXPECT_STREQ("opus", gcodec.plname);
1212 EXPECT_EQ(2, gcodec.channels);
1213 EXPECT_EQ(64000, gcodec.rate);
1214}
1215
1216// Test that with non-Opus, codec FEC is off.
buildbot@webrtc.orgd27d9ae2014-06-19 01:56:46 +00001217TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecIsacNoFec) {
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +00001218 EXPECT_TRUE(SetupEngine());
1219 int channel_num = voe_.GetLastChannel();
1220 std::vector<cricket::AudioCodec> codecs;
1221 codecs.push_back(kIsacCodec);
1222 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1223 EXPECT_FALSE(voe_.GetCodecFEC(channel_num));
1224}
buildbot@webrtc.org3ffa1f92014-07-02 19:51:26 +00001225
1226// Test the with non-Opus, even if useinbandfec=1, FEC is off.
1227TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecIsacWithParamNoFec) {
1228 EXPECT_TRUE(SetupEngine());
1229 int channel_num = voe_.GetLastChannel();
1230 std::vector<cricket::AudioCodec> codecs;
1231 codecs.push_back(kIsacCodec);
1232 codecs[0].params["useinbandfec"] = "1";
1233 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1234 EXPECT_FALSE(voe_.GetCodecFEC(channel_num));
1235}
buildbot@webrtc.org5d639b32014-09-10 07:57:12 +00001236
1237// Test that Opus FEC status can be changed.
1238TEST_F(WebRtcVoiceEngineTestFake, ChangeOpusFecStatus) {
1239 EXPECT_TRUE(SetupEngine());
1240 int channel_num = voe_.GetLastChannel();
1241 std::vector<cricket::AudioCodec> codecs;
1242 codecs.push_back(kOpusCodec);
1243 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1244 EXPECT_FALSE(voe_.GetCodecFEC(channel_num));
1245 codecs[0].params["useinbandfec"] = "1";
1246 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1247 EXPECT_TRUE(voe_.GetCodecFEC(channel_num));
1248}
1249
1250// Test maxplaybackrate <= 8000 triggers Opus narrow band mode.
1251TEST_F(WebRtcVoiceEngineTestFake, SetOpusMaxPlaybackRateNb) {
1252 EXPECT_TRUE(SetupEngine());
1253 int channel_num = voe_.GetLastChannel();
1254 std::vector<cricket::AudioCodec> codecs;
1255 codecs.push_back(kOpusCodec);
1256 codecs[0].bitrate = 0;
1257 codecs[0].SetParam(cricket::kCodecParamMaxPlaybackRate, 8000);
1258 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1259 EXPECT_EQ(cricket::kOpusBandwidthNb,
1260 voe_.GetMaxEncodingBandwidth(channel_num));
1261 webrtc::CodecInst gcodec;
1262 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1263 EXPECT_STREQ("opus", gcodec.plname);
minyue@webrtc.org2dc6f312014-10-31 05:33:10 +00001264
1265 EXPECT_EQ(12000, gcodec.rate);
1266 codecs[0].SetParam(cricket::kCodecParamStereo, "1");
1267 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1268 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1269 EXPECT_EQ(24000, gcodec.rate);
buildbot@webrtc.org5d639b32014-09-10 07:57:12 +00001270}
1271
1272// Test 8000 < maxplaybackrate <= 12000 triggers Opus medium band mode.
1273TEST_F(WebRtcVoiceEngineTestFake, SetOpusMaxPlaybackRateMb) {
1274 EXPECT_TRUE(SetupEngine());
1275 int channel_num = voe_.GetLastChannel();
1276 std::vector<cricket::AudioCodec> codecs;
1277 codecs.push_back(kOpusCodec);
1278 codecs[0].bitrate = 0;
1279 codecs[0].SetParam(cricket::kCodecParamMaxPlaybackRate, 8001);
1280 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1281 EXPECT_EQ(cricket::kOpusBandwidthMb,
1282 voe_.GetMaxEncodingBandwidth(channel_num));
1283 webrtc::CodecInst gcodec;
1284 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1285 EXPECT_STREQ("opus", gcodec.plname);
minyue@webrtc.org2dc6f312014-10-31 05:33:10 +00001286
1287 EXPECT_EQ(20000, gcodec.rate);
1288 codecs[0].SetParam(cricket::kCodecParamStereo, "1");
1289 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1290 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1291 EXPECT_EQ(40000, gcodec.rate);
buildbot@webrtc.org5d639b32014-09-10 07:57:12 +00001292}
1293
1294// Test 12000 < maxplaybackrate <= 16000 triggers Opus wide band mode.
1295TEST_F(WebRtcVoiceEngineTestFake, SetOpusMaxPlaybackRateWb) {
1296 EXPECT_TRUE(SetupEngine());
1297 int channel_num = voe_.GetLastChannel();
1298 std::vector<cricket::AudioCodec> codecs;
1299 codecs.push_back(kOpusCodec);
1300 codecs[0].bitrate = 0;
1301 codecs[0].SetParam(cricket::kCodecParamMaxPlaybackRate, 12001);
1302 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1303 EXPECT_EQ(cricket::kOpusBandwidthWb,
1304 voe_.GetMaxEncodingBandwidth(channel_num));
1305 webrtc::CodecInst gcodec;
1306 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1307 EXPECT_STREQ("opus", gcodec.plname);
minyue@webrtc.org2dc6f312014-10-31 05:33:10 +00001308
1309 EXPECT_EQ(20000, gcodec.rate);
1310 codecs[0].SetParam(cricket::kCodecParamStereo, "1");
1311 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1312 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1313 EXPECT_EQ(40000, gcodec.rate);
buildbot@webrtc.org5d639b32014-09-10 07:57:12 +00001314}
1315
1316// Test 16000 < maxplaybackrate <= 24000 triggers Opus super wide band mode.
1317TEST_F(WebRtcVoiceEngineTestFake, SetOpusMaxPlaybackRateSwb) {
1318 EXPECT_TRUE(SetupEngine());
1319 int channel_num = voe_.GetLastChannel();
1320 std::vector<cricket::AudioCodec> codecs;
1321 codecs.push_back(kOpusCodec);
1322 codecs[0].bitrate = 0;
1323 codecs[0].SetParam(cricket::kCodecParamMaxPlaybackRate, 16001);
1324 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1325 EXPECT_EQ(cricket::kOpusBandwidthSwb,
1326 voe_.GetMaxEncodingBandwidth(channel_num));
1327 webrtc::CodecInst gcodec;
1328 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1329 EXPECT_STREQ("opus", gcodec.plname);
minyue@webrtc.org2dc6f312014-10-31 05:33:10 +00001330
buildbot@webrtc.org5d639b32014-09-10 07:57:12 +00001331 EXPECT_EQ(32000, gcodec.rate);
minyue@webrtc.org2dc6f312014-10-31 05:33:10 +00001332 codecs[0].SetParam(cricket::kCodecParamStereo, "1");
1333 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1334 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1335 EXPECT_EQ(64000, gcodec.rate);
buildbot@webrtc.org5d639b32014-09-10 07:57:12 +00001336}
1337
1338// Test 24000 < maxplaybackrate triggers Opus full band mode.
1339TEST_F(WebRtcVoiceEngineTestFake, SetOpusMaxPlaybackRateFb) {
1340 EXPECT_TRUE(SetupEngine());
1341 int channel_num = voe_.GetLastChannel();
1342 std::vector<cricket::AudioCodec> codecs;
1343 codecs.push_back(kOpusCodec);
1344 codecs[0].bitrate = 0;
1345 codecs[0].SetParam(cricket::kCodecParamMaxPlaybackRate, 24001);
1346 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1347 EXPECT_EQ(cricket::kOpusBandwidthFb,
1348 voe_.GetMaxEncodingBandwidth(channel_num));
1349 webrtc::CodecInst gcodec;
1350 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1351 EXPECT_STREQ("opus", gcodec.plname);
minyue@webrtc.org2dc6f312014-10-31 05:33:10 +00001352
buildbot@webrtc.org5d639b32014-09-10 07:57:12 +00001353 EXPECT_EQ(32000, gcodec.rate);
minyue@webrtc.org2dc6f312014-10-31 05:33:10 +00001354 codecs[0].SetParam(cricket::kCodecParamStereo, "1");
1355 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1356 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1357 EXPECT_EQ(64000, gcodec.rate);
buildbot@webrtc.org5d639b32014-09-10 07:57:12 +00001358}
1359
1360// Test Opus that without maxplaybackrate, default playback rate is used.
1361TEST_F(WebRtcVoiceEngineTestFake, DefaultOpusMaxPlaybackRate) {
1362 EXPECT_TRUE(SetupEngine());
1363 int channel_num = voe_.GetLastChannel();
1364 std::vector<cricket::AudioCodec> codecs;
1365 codecs.push_back(kOpusCodec);
1366 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1367 EXPECT_EQ(cricket::kOpusBandwidthFb,
1368 voe_.GetMaxEncodingBandwidth(channel_num));
1369}
1370
1371// Test the with non-Opus, maxplaybackrate has no effect.
1372TEST_F(WebRtcVoiceEngineTestFake, SetNonOpusMaxPlaybackRate) {
1373 EXPECT_TRUE(SetupEngine());
1374 int channel_num = voe_.GetLastChannel();
1375 std::vector<cricket::AudioCodec> codecs;
1376 codecs.push_back(kIsacCodec);
1377 codecs[0].SetParam(cricket::kCodecParamMaxPlaybackRate, 32000);
1378 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1379 EXPECT_EQ(0, voe_.GetMaxEncodingBandwidth(channel_num));
1380}
1381
1382// Test maxplaybackrate can be set on two streams.
1383TEST_F(WebRtcVoiceEngineTestFake, SetOpusMaxPlaybackRateOnTwoStreams) {
1384 EXPECT_TRUE(SetupEngine());
1385 int channel_num = voe_.GetLastChannel();
1386 std::vector<cricket::AudioCodec> codecs;
1387 codecs.push_back(kOpusCodec);
1388 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1389 // Default bandwidth is 24000.
1390 EXPECT_EQ(cricket::kOpusBandwidthFb,
1391 voe_.GetMaxEncodingBandwidth(channel_num));
1392
1393 codecs[0].SetParam(cricket::kCodecParamMaxPlaybackRate, 8000);
1394
1395 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1396 EXPECT_EQ(cricket::kOpusBandwidthNb,
1397 voe_.GetMaxEncodingBandwidth(channel_num));
1398
1399 channel_->AddSendStream(cricket::StreamParams::CreateLegacy(kSsrc2));
1400 channel_num = voe_.GetLastChannel();
1401 EXPECT_EQ(cricket::kOpusBandwidthNb,
1402 voe_.GetMaxEncodingBandwidth(channel_num));
1403}
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +00001404
Minyue Li7100dcd2015-03-27 05:05:59 +01001405// Test that with usedtx=0, Opus DTX is off.
1406TEST_F(WebRtcVoiceEngineTestFake, DisableOpusDtxOnOpus) {
1407 EXPECT_TRUE(SetupEngine());
1408 int channel_num = voe_.GetLastChannel();
1409 std::vector<cricket::AudioCodec> codecs;
1410 codecs.push_back(kOpusCodec);
1411 codecs[0].params["usedtx"] = "0";
1412 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1413 EXPECT_FALSE(voe_.GetOpusDtx(channel_num));
1414}
1415
1416// Test that with usedtx=1, Opus DTX is on.
1417TEST_F(WebRtcVoiceEngineTestFake, EnableOpusDtxOnOpus) {
1418 EXPECT_TRUE(SetupEngine());
1419 int channel_num = voe_.GetLastChannel();
1420 std::vector<cricket::AudioCodec> codecs;
1421 codecs.push_back(kOpusCodec);
1422 codecs[0].params["usedtx"] = "1";
1423 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1424 EXPECT_TRUE(voe_.GetOpusDtx(channel_num));
1425 EXPECT_FALSE(voe_.GetVAD(channel_num)); // Opus DTX should not affect VAD.
1426}
1427
1428// Test that usedtx=1 works with stereo Opus.
1429TEST_F(WebRtcVoiceEngineTestFake, EnableOpusDtxOnOpusStereo) {
1430 EXPECT_TRUE(SetupEngine());
1431 int channel_num = voe_.GetLastChannel();
1432 std::vector<cricket::AudioCodec> codecs;
1433 codecs.push_back(kOpusCodec);
1434 codecs[0].params["usedtx"] = "1";
1435 codecs[0].params["stereo"] = "1";
1436 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1437 EXPECT_TRUE(voe_.GetOpusDtx(channel_num));
1438 EXPECT_FALSE(voe_.GetVAD(channel_num)); // Opus DTX should not affect VAD.
1439}
1440
1441// Test that usedtx=1 does not work with non Opus.
1442TEST_F(WebRtcVoiceEngineTestFake, CannotEnableOpusDtxOnNonOpus) {
1443 EXPECT_TRUE(SetupEngine());
1444 int channel_num = voe_.GetLastChannel();
1445 std::vector<cricket::AudioCodec> codecs;
1446 codecs.push_back(kIsacCodec);
1447 codecs[0].params["usedtx"] = "1";
1448 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1449 EXPECT_FALSE(voe_.GetOpusDtx(channel_num));
1450}
1451
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +00001452// Test that we can switch back and forth between Opus and ISAC with CN.
1453TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecsIsacOpusSwitching) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001454 EXPECT_TRUE(SetupEngine());
1455 int channel_num = voe_.GetLastChannel();
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +00001456 std::vector<cricket::AudioCodec> opus_codecs;
1457 opus_codecs.push_back(kOpusCodec);
1458 EXPECT_TRUE(channel_->SetSendCodecs(opus_codecs));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001459 webrtc::CodecInst gcodec;
1460 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +00001461 EXPECT_EQ(111, gcodec.pltype);
1462 EXPECT_STREQ("opus", gcodec.plname);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001463
1464 std::vector<cricket::AudioCodec> isac_codecs;
1465 isac_codecs.push_back(kIsacCodec);
1466 isac_codecs.push_back(kCn16000Codec);
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +00001467 isac_codecs.push_back(kOpusCodec);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001468 EXPECT_TRUE(channel_->SetSendCodecs(isac_codecs));
1469 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1470 EXPECT_EQ(103, gcodec.pltype);
1471 EXPECT_STREQ("ISAC", gcodec.plname);
1472
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +00001473 EXPECT_TRUE(channel_->SetSendCodecs(opus_codecs));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001474 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +00001475 EXPECT_EQ(111, gcodec.pltype);
1476 EXPECT_STREQ("opus", gcodec.plname);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001477}
1478
1479// Test that we handle various ways of specifying bitrate.
1480TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecsBitrate) {
1481 EXPECT_TRUE(SetupEngine());
1482 int channel_num = voe_.GetLastChannel();
1483 std::vector<cricket::AudioCodec> codecs;
1484 codecs.push_back(kIsacCodec); // bitrate == 32000
1485 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1486 webrtc::CodecInst gcodec;
1487 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1488 EXPECT_EQ(103, gcodec.pltype);
1489 EXPECT_STREQ("ISAC", gcodec.plname);
1490 EXPECT_EQ(32000, gcodec.rate);
1491
1492 codecs[0].bitrate = 0; // bitrate == default
1493 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1494 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1495 EXPECT_EQ(103, gcodec.pltype);
1496 EXPECT_STREQ("ISAC", gcodec.plname);
1497 EXPECT_EQ(-1, gcodec.rate);
1498
1499 codecs[0].bitrate = 28000; // bitrate == 28000
1500 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1501 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1502 EXPECT_EQ(103, gcodec.pltype);
1503 EXPECT_STREQ("ISAC", gcodec.plname);
1504 EXPECT_EQ(28000, gcodec.rate);
1505
1506 codecs[0] = kPcmuCodec; // bitrate == 64000
1507 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1508 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1509 EXPECT_EQ(0, gcodec.pltype);
1510 EXPECT_STREQ("PCMU", gcodec.plname);
1511 EXPECT_EQ(64000, gcodec.rate);
1512
1513 codecs[0].bitrate = 0; // bitrate == default
1514 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1515 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1516 EXPECT_EQ(0, gcodec.pltype);
1517 EXPECT_STREQ("PCMU", gcodec.plname);
1518 EXPECT_EQ(64000, gcodec.rate);
1519
1520 codecs[0] = kOpusCodec;
1521 codecs[0].bitrate = 0; // bitrate == default
1522 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1523 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1524 EXPECT_EQ(111, gcodec.pltype);
1525 EXPECT_STREQ("opus", gcodec.plname);
1526 EXPECT_EQ(32000, gcodec.rate);
1527}
1528
Brave Yao5225dd82015-03-26 07:39:19 +08001529// Test that we could set packet size specified in kCodecParamPTime.
1530TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecsPTimeAsPacketSize) {
1531 EXPECT_TRUE(SetupEngine());
1532 int channel_num = voe_.GetLastChannel();
1533 std::vector<cricket::AudioCodec> codecs;
1534 codecs.push_back(kOpusCodec);
1535 codecs[0].SetParam(cricket::kCodecParamPTime, 40); // Value within range.
1536 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1537 webrtc::CodecInst gcodec;
1538 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1539 EXPECT_EQ(1920, gcodec.pacsize); // Opus gets 40ms.
1540
1541 codecs[0].SetParam(cricket::kCodecParamPTime, 5); // Value below range.
1542 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1543 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1544 EXPECT_EQ(480, gcodec.pacsize); // Opus gets 10ms.
1545
1546 codecs[0].SetParam(cricket::kCodecParamPTime, 80); // Value beyond range.
1547 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1548 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1549 EXPECT_EQ(2880, gcodec.pacsize); // Opus gets 60ms.
1550
1551 codecs[0] = kIsacCodec; // Also try Isac, and with unsupported size.
1552 codecs[0].SetParam(cricket::kCodecParamPTime, 40); // Value within range.
1553 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1554 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1555 EXPECT_EQ(480, gcodec.pacsize); // Isac gets 30ms as the next smallest value.
1556
1557 codecs[0] = kG722CodecSdp; // Try G722 @8kHz as negotiated in SDP.
1558 codecs[0].SetParam(cricket::kCodecParamPTime, 40);
1559 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1560 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1561 EXPECT_EQ(640, gcodec.pacsize); // G722 gets 40ms @16kHz as defined in VoE.
1562}
1563
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00001564// Test that we fail if no codecs are specified.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001565TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecsNoCodecs) {
1566 EXPECT_TRUE(SetupEngine());
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00001567 std::vector<cricket::AudioCodec> codecs;
1568 EXPECT_FALSE(channel_->SetSendCodecs(codecs));
1569}
1570
1571// Test that we can set send codecs even with telephone-event codec as the first
1572// one on the list.
1573TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecsDTMFOnTop) {
1574 EXPECT_TRUE(SetupEngine());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001575 int channel_num = voe_.GetLastChannel();
1576 std::vector<cricket::AudioCodec> codecs;
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00001577 codecs.push_back(kTelephoneEventCodec);
1578 codecs.push_back(kIsacCodec);
1579 codecs.push_back(kPcmuCodec);
1580 codecs[0].id = 98; // DTMF
1581 codecs[1].id = 96;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001582 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1583 webrtc::CodecInst gcodec;
1584 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00001585 EXPECT_EQ(96, gcodec.pltype);
1586 EXPECT_STREQ("ISAC", gcodec.plname);
1587 EXPECT_EQ(98, voe_.GetSendTelephoneEventPayloadType(channel_num));
1588}
1589
1590// Test that we can set send codecs even with CN codec as the first
1591// one on the list.
1592TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecsCNOnTop) {
1593 EXPECT_TRUE(SetupEngine());
1594 int channel_num = voe_.GetLastChannel();
1595 std::vector<cricket::AudioCodec> codecs;
1596 codecs.push_back(kCn16000Codec);
1597 codecs.push_back(kIsacCodec);
1598 codecs.push_back(kPcmuCodec);
1599 codecs[0].id = 98; // wideband CN
1600 codecs[1].id = 96;
1601 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1602 webrtc::CodecInst gcodec;
1603 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1604 EXPECT_EQ(96, gcodec.pltype);
1605 EXPECT_STREQ("ISAC", gcodec.plname);
1606 EXPECT_EQ(98, voe_.GetSendCNPayloadType(channel_num, true));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001607}
1608
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00001609// Test that we set VAD and DTMF types correctly as caller.
1610TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecsCNandDTMFAsCaller) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001611 EXPECT_TRUE(SetupEngine());
1612 int channel_num = voe_.GetLastChannel();
1613 std::vector<cricket::AudioCodec> codecs;
1614 codecs.push_back(kIsacCodec);
1615 codecs.push_back(kPcmuCodec);
1616 // TODO(juberti): cn 32000
1617 codecs.push_back(kCn16000Codec);
1618 codecs.push_back(kCn8000Codec);
1619 codecs.push_back(kTelephoneEventCodec);
1620 codecs.push_back(kRedCodec);
1621 codecs[0].id = 96;
1622 codecs[2].id = 97; // wideband CN
1623 codecs[4].id = 98; // DTMF
1624 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1625 webrtc::CodecInst gcodec;
1626 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1627 EXPECT_EQ(96, gcodec.pltype);
1628 EXPECT_STREQ("ISAC", gcodec.plname);
1629 EXPECT_TRUE(voe_.GetVAD(channel_num));
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +00001630 EXPECT_FALSE(voe_.GetRED(channel_num));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001631 EXPECT_EQ(13, voe_.GetSendCNPayloadType(channel_num, false));
1632 EXPECT_EQ(97, voe_.GetSendCNPayloadType(channel_num, true));
1633 EXPECT_EQ(98, voe_.GetSendTelephoneEventPayloadType(channel_num));
1634}
1635
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00001636// Test that we set VAD and DTMF types correctly as callee.
1637TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecsCNandDTMFAsCallee) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001638 EXPECT_TRUE(engine_.Init(rtc::Thread::Current()));
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00001639 channel_ = engine_.CreateChannel();
1640 EXPECT_TRUE(channel_ != NULL);
1641
1642 int channel_num = voe_.GetLastChannel();
1643 std::vector<cricket::AudioCodec> codecs;
1644 codecs.push_back(kIsacCodec);
1645 codecs.push_back(kPcmuCodec);
1646 // TODO(juberti): cn 32000
1647 codecs.push_back(kCn16000Codec);
1648 codecs.push_back(kCn8000Codec);
1649 codecs.push_back(kTelephoneEventCodec);
1650 codecs.push_back(kRedCodec);
1651 codecs[0].id = 96;
1652 codecs[2].id = 97; // wideband CN
1653 codecs[4].id = 98; // DTMF
1654 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1655 EXPECT_TRUE(channel_->AddSendStream(
1656 cricket::StreamParams::CreateLegacy(kSsrc1)));
1657
1658 webrtc::CodecInst gcodec;
1659 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1660 EXPECT_EQ(96, gcodec.pltype);
1661 EXPECT_STREQ("ISAC", gcodec.plname);
1662 EXPECT_TRUE(voe_.GetVAD(channel_num));
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +00001663 EXPECT_FALSE(voe_.GetRED(channel_num));
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00001664 EXPECT_EQ(13, voe_.GetSendCNPayloadType(channel_num, false));
1665 EXPECT_EQ(97, voe_.GetSendCNPayloadType(channel_num, true));
1666 EXPECT_EQ(98, voe_.GetSendTelephoneEventPayloadType(channel_num));
1667}
1668
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001669// Test that we only apply VAD if we have a CN codec that matches the
1670// send codec clockrate.
1671TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecsCNNoMatch) {
1672 EXPECT_TRUE(SetupEngine());
1673 int channel_num = voe_.GetLastChannel();
1674 std::vector<cricket::AudioCodec> codecs;
1675 // Set ISAC(16K) and CN(16K). VAD should be activated.
1676 codecs.push_back(kIsacCodec);
1677 codecs.push_back(kCn16000Codec);
1678 codecs[1].id = 97;
1679 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1680 webrtc::CodecInst gcodec;
1681 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1682 EXPECT_STREQ("ISAC", gcodec.plname);
1683 EXPECT_TRUE(voe_.GetVAD(channel_num));
1684 EXPECT_EQ(97, voe_.GetSendCNPayloadType(channel_num, true));
1685 // Set PCMU(8K) and CN(16K). VAD should not be activated.
1686 codecs[0] = kPcmuCodec;
1687 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1688 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1689 EXPECT_STREQ("PCMU", gcodec.plname);
1690 EXPECT_FALSE(voe_.GetVAD(channel_num));
1691 // Set PCMU(8K) and CN(8K). VAD should be activated.
1692 codecs[1] = kCn8000Codec;
1693 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1694 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1695 EXPECT_STREQ("PCMU", gcodec.plname);
1696 EXPECT_TRUE(voe_.GetVAD(channel_num));
1697 EXPECT_EQ(13, voe_.GetSendCNPayloadType(channel_num, false));
Brave Yao5225dd82015-03-26 07:39:19 +08001698 // Set ISAC(16K) and CN(8K). VAD should not be activated.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001699 codecs[0] = kIsacCodec;
1700 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1701 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1702 EXPECT_STREQ("ISAC", gcodec.plname);
1703 EXPECT_FALSE(voe_.GetVAD(channel_num));
1704}
1705
1706// Test that we perform case-insensitive matching of codec names.
1707TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecsCaseInsensitive) {
1708 EXPECT_TRUE(SetupEngine());
1709 int channel_num = voe_.GetLastChannel();
1710 std::vector<cricket::AudioCodec> codecs;
1711 codecs.push_back(kIsacCodec);
1712 codecs.push_back(kPcmuCodec);
1713 codecs.push_back(kCn16000Codec);
1714 codecs.push_back(kCn8000Codec);
1715 codecs.push_back(kTelephoneEventCodec);
1716 codecs.push_back(kRedCodec);
1717 codecs[0].name = "iSaC";
1718 codecs[0].id = 96;
1719 codecs[2].id = 97; // wideband CN
1720 codecs[4].id = 98; // DTMF
1721 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1722 webrtc::CodecInst gcodec;
1723 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1724 EXPECT_EQ(96, gcodec.pltype);
1725 EXPECT_STREQ("ISAC", gcodec.plname);
1726 EXPECT_TRUE(voe_.GetVAD(channel_num));
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +00001727 EXPECT_FALSE(voe_.GetRED(channel_num));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001728 EXPECT_EQ(13, voe_.GetSendCNPayloadType(channel_num, false));
1729 EXPECT_EQ(97, voe_.GetSendCNPayloadType(channel_num, true));
1730 EXPECT_EQ(98, voe_.GetSendTelephoneEventPayloadType(channel_num));
1731}
1732
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +00001733// Test that we set up RED correctly as caller.
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00001734TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecsREDAsCaller) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001735 EXPECT_TRUE(SetupEngine());
1736 int channel_num = voe_.GetLastChannel();
1737 std::vector<cricket::AudioCodec> codecs;
1738 codecs.push_back(kRedCodec);
1739 codecs.push_back(kIsacCodec);
1740 codecs.push_back(kPcmuCodec);
1741 codecs[0].id = 127;
1742 codecs[0].params[""] = "96/96";
1743 codecs[1].id = 96;
1744 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1745 webrtc::CodecInst gcodec;
1746 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1747 EXPECT_EQ(96, gcodec.pltype);
1748 EXPECT_STREQ("ISAC", gcodec.plname);
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +00001749 EXPECT_TRUE(voe_.GetRED(channel_num));
1750 EXPECT_EQ(127, voe_.GetSendREDPayloadType(channel_num));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001751}
1752
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +00001753// Test that we set up RED correctly as callee.
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00001754TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecsREDAsCallee) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001755 EXPECT_TRUE(engine_.Init(rtc::Thread::Current()));
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00001756 channel_ = engine_.CreateChannel();
1757 EXPECT_TRUE(channel_ != NULL);
1758
1759 int channel_num = voe_.GetLastChannel();
1760 std::vector<cricket::AudioCodec> codecs;
1761 codecs.push_back(kRedCodec);
1762 codecs.push_back(kIsacCodec);
1763 codecs.push_back(kPcmuCodec);
1764 codecs[0].id = 127;
1765 codecs[0].params[""] = "96/96";
1766 codecs[1].id = 96;
1767 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1768 EXPECT_TRUE(channel_->AddSendStream(
1769 cricket::StreamParams::CreateLegacy(kSsrc1)));
1770 webrtc::CodecInst gcodec;
1771 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1772 EXPECT_EQ(96, gcodec.pltype);
1773 EXPECT_STREQ("ISAC", gcodec.plname);
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +00001774 EXPECT_TRUE(voe_.GetRED(channel_num));
1775 EXPECT_EQ(127, voe_.GetSendREDPayloadType(channel_num));
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00001776}
1777
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +00001778// Test that we set up RED correctly if params are omitted.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001779TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecsREDNoParams) {
1780 EXPECT_TRUE(SetupEngine());
1781 int channel_num = voe_.GetLastChannel();
1782 std::vector<cricket::AudioCodec> codecs;
1783 codecs.push_back(kRedCodec);
1784 codecs.push_back(kIsacCodec);
1785 codecs.push_back(kPcmuCodec);
1786 codecs[0].id = 127;
1787 codecs[1].id = 96;
1788 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1789 webrtc::CodecInst gcodec;
1790 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1791 EXPECT_EQ(96, gcodec.pltype);
1792 EXPECT_STREQ("ISAC", gcodec.plname);
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +00001793 EXPECT_TRUE(voe_.GetRED(channel_num));
1794 EXPECT_EQ(127, voe_.GetSendREDPayloadType(channel_num));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001795}
1796
1797// Test that we ignore RED if the parameters aren't named the way we expect.
1798TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecsBadRED1) {
1799 EXPECT_TRUE(SetupEngine());
1800 int channel_num = voe_.GetLastChannel();
1801 std::vector<cricket::AudioCodec> codecs;
1802 codecs.push_back(kRedCodec);
1803 codecs.push_back(kIsacCodec);
1804 codecs.push_back(kPcmuCodec);
1805 codecs[0].id = 127;
1806 codecs[0].params["ABC"] = "96/96";
1807 codecs[1].id = 96;
1808 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1809 webrtc::CodecInst gcodec;
1810 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1811 EXPECT_EQ(96, gcodec.pltype);
1812 EXPECT_STREQ("ISAC", gcodec.plname);
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +00001813 EXPECT_FALSE(voe_.GetRED(channel_num));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001814}
1815
1816// Test that we ignore RED if it uses different primary/secondary encoding.
1817TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecsBadRED2) {
1818 EXPECT_TRUE(SetupEngine());
1819 int channel_num = voe_.GetLastChannel();
1820 std::vector<cricket::AudioCodec> codecs;
1821 codecs.push_back(kRedCodec);
1822 codecs.push_back(kIsacCodec);
1823 codecs.push_back(kPcmuCodec);
1824 codecs[0].id = 127;
1825 codecs[0].params[""] = "96/0";
1826 codecs[1].id = 96;
1827 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1828 webrtc::CodecInst gcodec;
1829 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1830 EXPECT_EQ(96, gcodec.pltype);
1831 EXPECT_STREQ("ISAC", gcodec.plname);
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +00001832 EXPECT_FALSE(voe_.GetRED(channel_num));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001833}
1834
1835// Test that we ignore RED if it uses more than 2 encodings.
1836TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecsBadRED3) {
1837 EXPECT_TRUE(SetupEngine());
1838 int channel_num = voe_.GetLastChannel();
1839 std::vector<cricket::AudioCodec> codecs;
1840 codecs.push_back(kRedCodec);
1841 codecs.push_back(kIsacCodec);
1842 codecs.push_back(kPcmuCodec);
1843 codecs[0].id = 127;
1844 codecs[0].params[""] = "96/96/96";
1845 codecs[1].id = 96;
1846 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1847 webrtc::CodecInst gcodec;
1848 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1849 EXPECT_EQ(96, gcodec.pltype);
1850 EXPECT_STREQ("ISAC", gcodec.plname);
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +00001851 EXPECT_FALSE(voe_.GetRED(channel_num));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001852}
1853
1854// Test that we ignore RED if it has bogus codec ids.
1855TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecsBadRED4) {
1856 EXPECT_TRUE(SetupEngine());
1857 int channel_num = voe_.GetLastChannel();
1858 std::vector<cricket::AudioCodec> codecs;
1859 codecs.push_back(kRedCodec);
1860 codecs.push_back(kIsacCodec);
1861 codecs.push_back(kPcmuCodec);
1862 codecs[0].id = 127;
1863 codecs[0].params[""] = "ABC/ABC";
1864 codecs[1].id = 96;
1865 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1866 webrtc::CodecInst gcodec;
1867 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1868 EXPECT_EQ(96, gcodec.pltype);
1869 EXPECT_STREQ("ISAC", gcodec.plname);
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +00001870 EXPECT_FALSE(voe_.GetRED(channel_num));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001871}
1872
1873// Test that we ignore RED if it refers to a codec that is not present.
1874TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecsBadRED5) {
1875 EXPECT_TRUE(SetupEngine());
1876 int channel_num = voe_.GetLastChannel();
1877 std::vector<cricket::AudioCodec> codecs;
1878 codecs.push_back(kRedCodec);
1879 codecs.push_back(kIsacCodec);
1880 codecs.push_back(kPcmuCodec);
1881 codecs[0].id = 127;
1882 codecs[0].params[""] = "97/97";
1883 codecs[1].id = 96;
1884 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1885 webrtc::CodecInst gcodec;
1886 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1887 EXPECT_EQ(96, gcodec.pltype);
1888 EXPECT_STREQ("ISAC", gcodec.plname);
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +00001889 EXPECT_FALSE(voe_.GetRED(channel_num));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001890}
1891
buildbot@webrtc.org150835e2014-05-06 15:54:38 +00001892// Test support for audio level header extension.
1893TEST_F(WebRtcVoiceEngineTestFake, SendAudioLevelHeaderExtensions) {
1894 TestSetSendRtpHeaderExtensions(kRtpAudioLevelHeaderExtension);
henrike@webrtc.org79047f92014-03-06 23:46:59 +00001895}
buildbot@webrtc.org150835e2014-05-06 15:54:38 +00001896TEST_F(WebRtcVoiceEngineTestFake, RecvAudioLevelHeaderExtensions) {
1897 TestSetRecvRtpHeaderExtensions(kRtpAudioLevelHeaderExtension);
1898}
henrike@webrtc.org79047f92014-03-06 23:46:59 +00001899
buildbot@webrtc.org150835e2014-05-06 15:54:38 +00001900// Test support for absolute send time header extension.
1901TEST_F(WebRtcVoiceEngineTestFake, SendAbsoluteSendTimeHeaderExtensions) {
1902 TestSetSendRtpHeaderExtensions(kRtpAbsoluteSenderTimeHeaderExtension);
1903}
1904TEST_F(WebRtcVoiceEngineTestFake, RecvAbsoluteSendTimeHeaderExtensions) {
1905 TestSetRecvRtpHeaderExtensions(kRtpAbsoluteSenderTimeHeaderExtension);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001906}
1907
1908// Test that we can create a channel and start sending/playing out on it.
1909TEST_F(WebRtcVoiceEngineTestFake, SendAndPlayout) {
1910 EXPECT_TRUE(SetupEngine());
1911 int channel_num = voe_.GetLastChannel();
1912 std::vector<cricket::AudioCodec> codecs;
1913 codecs.push_back(kPcmuCodec);
1914 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1915 EXPECT_TRUE(channel_->SetSend(cricket::SEND_MICROPHONE));
1916 EXPECT_TRUE(voe_.GetSend(channel_num));
1917 EXPECT_TRUE(channel_->SetPlayout(true));
1918 EXPECT_TRUE(voe_.GetPlayout(channel_num));
1919 EXPECT_TRUE(channel_->SetSend(cricket::SEND_NOTHING));
1920 EXPECT_FALSE(voe_.GetSend(channel_num));
1921 EXPECT_TRUE(channel_->SetPlayout(false));
1922 EXPECT_FALSE(voe_.GetPlayout(channel_num));
1923}
1924
wu@webrtc.org9dba5252013-08-05 20:36:57 +00001925// Test that we can add and remove send streams.
1926TEST_F(WebRtcVoiceEngineTestFake, CreateAndDeleteMultipleSendStreams) {
1927 SetupForMultiSendStream();
1928
1929 static const uint32 kSsrcs4[] = {1, 2, 3, 4};
1930
1931 // Set the global state for sending.
1932 EXPECT_TRUE(channel_->SetSend(cricket::SEND_MICROPHONE));
1933
1934 for (unsigned int i = 0; i < ARRAY_SIZE(kSsrcs4); ++i) {
1935 EXPECT_TRUE(channel_->AddSendStream(
1936 cricket::StreamParams::CreateLegacy(kSsrcs4[i])));
1937
1938 // Verify that we are in a sending state for all the created streams.
1939 int channel_num = voe_.GetChannelFromLocalSsrc(kSsrcs4[i]);
1940 EXPECT_TRUE(voe_.GetSend(channel_num));
1941 }
1942
1943 // Remove the first send channel, which is the default channel. It will only
1944 // recycle the default channel but not delete it.
1945 EXPECT_TRUE(channel_->RemoveSendStream(kSsrcs4[0]));
1946 // Stream should already be Removed from the send stream list.
1947 EXPECT_FALSE(channel_->RemoveSendStream(kSsrcs4[0]));
1948 // But the default still exists.
1949 EXPECT_EQ(0, voe_.GetChannelFromLocalSsrc(kSsrcs4[0]));
1950
1951 // Delete the rest of send channel streams.
1952 for (unsigned int i = 1; i < ARRAY_SIZE(kSsrcs4); ++i) {
1953 EXPECT_TRUE(channel_->RemoveSendStream(kSsrcs4[i]));
1954 // Stream should already be deleted.
1955 EXPECT_FALSE(channel_->RemoveSendStream(kSsrcs4[i]));
1956 EXPECT_EQ(-1, voe_.GetChannelFromLocalSsrc(kSsrcs4[i]));
1957 }
1958}
1959
1960// Test SetSendCodecs correctly configure the codecs in all send streams.
1961TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecsWithMultipleSendStreams) {
1962 SetupForMultiSendStream();
1963
1964 static const uint32 kSsrcs4[] = {1, 2, 3, 4};
1965 // Create send streams.
1966 for (unsigned int i = 0; i < ARRAY_SIZE(kSsrcs4); ++i) {
1967 EXPECT_TRUE(channel_->AddSendStream(
1968 cricket::StreamParams::CreateLegacy(kSsrcs4[i])));
1969 }
1970
1971 std::vector<cricket::AudioCodec> codecs;
1972 // Set ISAC(16K) and CN(16K). VAD should be activated.
1973 codecs.push_back(kIsacCodec);
1974 codecs.push_back(kCn16000Codec);
1975 codecs[1].id = 97;
1976 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1977
1978 // Verify ISAC and VAD are corrected configured on all send channels.
1979 webrtc::CodecInst gcodec;
1980 for (unsigned int i = 0; i < ARRAY_SIZE(kSsrcs4); ++i) {
1981 int channel_num = voe_.GetChannelFromLocalSsrc(kSsrcs4[i]);
1982 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1983 EXPECT_STREQ("ISAC", gcodec.plname);
1984 EXPECT_TRUE(voe_.GetVAD(channel_num));
1985 EXPECT_EQ(97, voe_.GetSendCNPayloadType(channel_num, true));
1986 }
1987
1988 // Change to PCMU(8K) and CN(16K). VAD should not be activated.
1989 codecs[0] = kPcmuCodec;
1990 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1991 for (unsigned int i = 0; i < ARRAY_SIZE(kSsrcs4); ++i) {
1992 int channel_num = voe_.GetChannelFromLocalSsrc(kSsrcs4[i]);
1993 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1994 EXPECT_STREQ("PCMU", gcodec.plname);
1995 EXPECT_FALSE(voe_.GetVAD(channel_num));
1996 }
1997}
1998
1999// Test we can SetSend on all send streams correctly.
2000TEST_F(WebRtcVoiceEngineTestFake, SetSendWithMultipleSendStreams) {
2001 SetupForMultiSendStream();
2002
2003 static const uint32 kSsrcs4[] = {1, 2, 3, 4};
2004 // Create the send channels and they should be a SEND_NOTHING date.
2005 for (unsigned int i = 0; i < ARRAY_SIZE(kSsrcs4); ++i) {
2006 EXPECT_TRUE(channel_->AddSendStream(
2007 cricket::StreamParams::CreateLegacy(kSsrcs4[i])));
2008 int channel_num = voe_.GetLastChannel();
2009 EXPECT_FALSE(voe_.GetSend(channel_num));
2010 }
2011
2012 // Set the global state for starting sending.
2013 EXPECT_TRUE(channel_->SetSend(cricket::SEND_MICROPHONE));
2014 for (unsigned int i = 0; i < ARRAY_SIZE(kSsrcs4); ++i) {
2015 // Verify that we are in a sending state for all the send streams.
2016 int channel_num = voe_.GetChannelFromLocalSsrc(kSsrcs4[i]);
2017 EXPECT_TRUE(voe_.GetSend(channel_num));
2018 }
2019
2020 // Set the global state for stopping sending.
2021 EXPECT_TRUE(channel_->SetSend(cricket::SEND_NOTHING));
2022 for (unsigned int i = 1; i < ARRAY_SIZE(kSsrcs4); ++i) {
2023 // Verify that we are in a stop state for all the send streams.
2024 int channel_num = voe_.GetChannelFromLocalSsrc(kSsrcs4[i]);
2025 EXPECT_FALSE(voe_.GetSend(channel_num));
2026 }
2027}
2028
2029// Test we can set the correct statistics on all send streams.
2030TEST_F(WebRtcVoiceEngineTestFake, GetStatsWithMultipleSendStreams) {
2031 SetupForMultiSendStream();
2032
2033 static const uint32 kSsrcs4[] = {1, 2, 3, 4};
2034 // Create send streams.
2035 for (unsigned int i = 0; i < ARRAY_SIZE(kSsrcs4); ++i) {
2036 EXPECT_TRUE(channel_->AddSendStream(
2037 cricket::StreamParams::CreateLegacy(kSsrcs4[i])));
2038 }
buildbot@webrtc.org7e71b772014-06-13 01:14:01 +00002039 // Create a receive stream to check that none of the send streams end up in
2040 // the receive stream stats.
2041 EXPECT_TRUE(channel_->AddRecvStream(
2042 cricket::StreamParams::CreateLegacy(kSsrc2)));
wu@webrtc.org9dba5252013-08-05 20:36:57 +00002043 // We need send codec to be set to get all stats.
2044 std::vector<cricket::AudioCodec> codecs;
2045 codecs.push_back(kPcmuCodec);
2046 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
buildbot@webrtc.org7e71b772014-06-13 01:14:01 +00002047 EXPECT_TRUE(channel_->SetRecvCodecs(codecs));
wu@webrtc.org9dba5252013-08-05 20:36:57 +00002048
2049 cricket::VoiceMediaInfo info;
2050 EXPECT_EQ(true, channel_->GetStats(&info));
2051 EXPECT_EQ(static_cast<size_t>(ARRAY_SIZE(kSsrcs4)), info.senders.size());
2052
2053 // Verify the statistic information is correct.
2054 for (unsigned int i = 0; i < ARRAY_SIZE(kSsrcs4); ++i) {
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +00002055 EXPECT_EQ(kSsrcs4[i], info.senders[i].ssrc());
wu@webrtc.org9dba5252013-08-05 20:36:57 +00002056 EXPECT_EQ(kPcmuCodec.name, info.senders[i].codec_name);
2057 EXPECT_EQ(cricket::kIntStatValue, info.senders[i].bytes_sent);
2058 EXPECT_EQ(cricket::kIntStatValue, info.senders[i].packets_sent);
2059 EXPECT_EQ(cricket::kIntStatValue, info.senders[i].packets_lost);
2060 EXPECT_EQ(cricket::kFractionLostStatValue, info.senders[i].fraction_lost);
2061 EXPECT_EQ(cricket::kIntStatValue, info.senders[i].ext_seqnum);
2062 EXPECT_EQ(cricket::kIntStatValue, info.senders[i].rtt_ms);
2063 EXPECT_EQ(cricket::kIntStatValue, info.senders[i].jitter_ms);
buildbot@webrtc.org7e71b772014-06-13 01:14:01 +00002064 EXPECT_EQ(kPcmuCodec.name, info.senders[i].codec_name);
wu@webrtc.org9dba5252013-08-05 20:36:57 +00002065 }
2066
buildbot@webrtc.org7e71b772014-06-13 01:14:01 +00002067 EXPECT_EQ(0u, info.receivers.size());
2068 DeliverPacket(kPcmuFrame, sizeof(kPcmuFrame));
2069 EXPECT_EQ(true, channel_->GetStats(&info));
2070
wu@webrtc.org9dba5252013-08-05 20:36:57 +00002071 EXPECT_EQ(1u, info.receivers.size());
buildbot@webrtc.org7e71b772014-06-13 01:14:01 +00002072 EXPECT_EQ(cricket::kIntStatValue, info.receivers[0].bytes_rcvd);
2073 EXPECT_EQ(cricket::kIntStatValue, info.receivers[0].packets_rcvd);
2074 EXPECT_EQ(cricket::kIntStatValue, info.receivers[0].packets_lost);
2075 EXPECT_EQ(cricket::kIntStatValue, info.receivers[0].ext_seqnum);
2076 EXPECT_EQ(kPcmuCodec.name, info.receivers[0].codec_name);
minyue@webrtc.orgc0bd7be2015-02-18 15:24:13 +00002077 EXPECT_EQ(static_cast<float>(cricket::kNetStats.currentExpandRate) /
2078 (1 << 14), info.receivers[0].expand_rate);
2079 EXPECT_EQ(static_cast<float>(cricket::kNetStats.currentSpeechExpandRate) /
2080 (1 << 14), info.receivers[0].speech_expand_rate);
2081 EXPECT_EQ(static_cast<float>(cricket::kNetStats.currentSecondaryDecodedRate) /
2082 (1 << 14), info.receivers[0].secondary_decoded_rate);
wu@webrtc.org9dba5252013-08-05 20:36:57 +00002083}
2084
wu@webrtc.org9dba5252013-08-05 20:36:57 +00002085// Test that we can add and remove receive streams, and do proper send/playout.
2086// We can receive on multiple streams while sending one stream.
2087TEST_F(WebRtcVoiceEngineTestFake, PlayoutWithMultipleStreams) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002088 EXPECT_TRUE(SetupEngine());
2089 int channel_num1 = voe_.GetLastChannel();
2090
2091 // Start playout on the default channel.
2092 EXPECT_TRUE(channel_->SetOptions(options_conference_));
2093 EXPECT_TRUE(channel_->SetPlayout(true));
2094 EXPECT_TRUE(voe_.GetPlayout(channel_num1));
2095
2096 // Adding another stream should disable playout on the default channel.
2097 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(2)));
2098 int channel_num2 = voe_.GetLastChannel();
2099 std::vector<cricket::AudioCodec> codecs;
2100 codecs.push_back(kPcmuCodec);
2101 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
2102 EXPECT_TRUE(channel_->SetSend(cricket::SEND_MICROPHONE));
2103 EXPECT_TRUE(voe_.GetSend(channel_num1));
2104 EXPECT_FALSE(voe_.GetSend(channel_num2));
2105
2106 // Make sure only the new channel is played out.
2107 EXPECT_FALSE(voe_.GetPlayout(channel_num1));
2108 EXPECT_TRUE(voe_.GetPlayout(channel_num2));
2109
2110 // Adding yet another stream should have stream 2 and 3 enabled for playout.
2111 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(3)));
2112 int channel_num3 = voe_.GetLastChannel();
2113 EXPECT_FALSE(voe_.GetPlayout(channel_num1));
2114 EXPECT_TRUE(voe_.GetPlayout(channel_num2));
2115 EXPECT_TRUE(voe_.GetPlayout(channel_num3));
2116 EXPECT_FALSE(voe_.GetSend(channel_num3));
2117
2118 // Stop sending.
2119 EXPECT_TRUE(channel_->SetSend(cricket::SEND_NOTHING));
2120 EXPECT_FALSE(voe_.GetSend(channel_num1));
2121 EXPECT_FALSE(voe_.GetSend(channel_num2));
2122 EXPECT_FALSE(voe_.GetSend(channel_num3));
2123
2124 // Stop playout.
2125 EXPECT_TRUE(channel_->SetPlayout(false));
2126 EXPECT_FALSE(voe_.GetPlayout(channel_num1));
2127 EXPECT_FALSE(voe_.GetPlayout(channel_num2));
2128 EXPECT_FALSE(voe_.GetPlayout(channel_num3));
2129
2130 // Restart playout and make sure the default channel still is not played out.
2131 EXPECT_TRUE(channel_->SetPlayout(true));
2132 EXPECT_FALSE(voe_.GetPlayout(channel_num1));
2133 EXPECT_TRUE(voe_.GetPlayout(channel_num2));
2134 EXPECT_TRUE(voe_.GetPlayout(channel_num3));
2135
2136 // Now remove the new streams and verify that the default channel is
2137 // played out again.
2138 EXPECT_TRUE(channel_->RemoveRecvStream(3));
2139 EXPECT_TRUE(channel_->RemoveRecvStream(2));
2140
2141 EXPECT_TRUE(voe_.GetPlayout(channel_num1));
2142}
2143
2144// Test that we can set the devices to use.
2145TEST_F(WebRtcVoiceEngineTestFake, SetDevices) {
2146 EXPECT_TRUE(SetupEngine());
2147 int channel_num = voe_.GetLastChannel();
2148 std::vector<cricket::AudioCodec> codecs;
2149 codecs.push_back(kPcmuCodec);
2150 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
2151
2152 cricket::Device default_dev(cricket::kFakeDefaultDeviceName,
2153 cricket::kFakeDefaultDeviceId);
2154 cricket::Device dev(cricket::kFakeDeviceName,
2155 cricket::kFakeDeviceId);
2156
2157 // Test SetDevices() while not sending or playing.
2158 EXPECT_TRUE(engine_.SetDevices(&default_dev, &default_dev));
2159
2160 // Test SetDevices() while sending and playing.
2161 EXPECT_TRUE(engine_.SetLocalMonitor(true));
2162 EXPECT_TRUE(channel_->SetSend(cricket::SEND_MICROPHONE));
2163 EXPECT_TRUE(channel_->SetPlayout(true));
2164 EXPECT_TRUE(voe_.GetRecordingMicrophone());
2165 EXPECT_TRUE(voe_.GetSend(channel_num));
2166 EXPECT_TRUE(voe_.GetPlayout(channel_num));
2167
2168 EXPECT_TRUE(engine_.SetDevices(&dev, &dev));
2169
2170 EXPECT_TRUE(voe_.GetRecordingMicrophone());
2171 EXPECT_TRUE(voe_.GetSend(channel_num));
2172 EXPECT_TRUE(voe_.GetPlayout(channel_num));
2173
2174 // Test that failure to open newly selected devices does not prevent opening
2175 // ones after that.
2176 voe_.set_fail_start_recording_microphone(true);
2177 voe_.set_playout_fail_channel(channel_num);
2178 voe_.set_send_fail_channel(channel_num);
2179
2180 EXPECT_FALSE(engine_.SetDevices(&default_dev, &default_dev));
2181
2182 EXPECT_FALSE(voe_.GetRecordingMicrophone());
2183 EXPECT_FALSE(voe_.GetSend(channel_num));
2184 EXPECT_FALSE(voe_.GetPlayout(channel_num));
2185
2186 voe_.set_fail_start_recording_microphone(false);
2187 voe_.set_playout_fail_channel(-1);
2188 voe_.set_send_fail_channel(-1);
2189
2190 EXPECT_TRUE(engine_.SetDevices(&dev, &dev));
2191
2192 EXPECT_TRUE(voe_.GetRecordingMicrophone());
2193 EXPECT_TRUE(voe_.GetSend(channel_num));
2194 EXPECT_TRUE(voe_.GetPlayout(channel_num));
2195}
2196
2197// Test that we can set the devices to use even if we failed to
2198// open the initial ones.
2199TEST_F(WebRtcVoiceEngineTestFake, SetDevicesWithInitiallyBadDevices) {
2200 EXPECT_TRUE(SetupEngine());
2201 int channel_num = voe_.GetLastChannel();
2202 std::vector<cricket::AudioCodec> codecs;
2203 codecs.push_back(kPcmuCodec);
2204 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
2205
2206 cricket::Device default_dev(cricket::kFakeDefaultDeviceName,
2207 cricket::kFakeDefaultDeviceId);
2208 cricket::Device dev(cricket::kFakeDeviceName,
2209 cricket::kFakeDeviceId);
2210
2211 // Test that failure to open devices selected before starting
2212 // send/play does not prevent opening newly selected ones after that.
2213 voe_.set_fail_start_recording_microphone(true);
2214 voe_.set_playout_fail_channel(channel_num);
2215 voe_.set_send_fail_channel(channel_num);
2216
2217 EXPECT_TRUE(engine_.SetDevices(&default_dev, &default_dev));
2218
2219 EXPECT_FALSE(engine_.SetLocalMonitor(true));
2220 EXPECT_FALSE(channel_->SetSend(cricket::SEND_MICROPHONE));
2221 EXPECT_FALSE(channel_->SetPlayout(true));
2222 EXPECT_FALSE(voe_.GetRecordingMicrophone());
2223 EXPECT_FALSE(voe_.GetSend(channel_num));
2224 EXPECT_FALSE(voe_.GetPlayout(channel_num));
2225
2226 voe_.set_fail_start_recording_microphone(false);
2227 voe_.set_playout_fail_channel(-1);
2228 voe_.set_send_fail_channel(-1);
2229
2230 EXPECT_TRUE(engine_.SetDevices(&dev, &dev));
2231
2232 EXPECT_TRUE(voe_.GetRecordingMicrophone());
2233 EXPECT_TRUE(voe_.GetSend(channel_num));
2234 EXPECT_TRUE(voe_.GetPlayout(channel_num));
2235}
2236
2237// Test that we can create a channel configured for multi-point conferences,
2238// and start sending/playing out on it.
2239TEST_F(WebRtcVoiceEngineTestFake, ConferenceSendAndPlayout) {
2240 EXPECT_TRUE(SetupEngine());
2241 int channel_num = voe_.GetLastChannel();
2242 EXPECT_TRUE(channel_->SetOptions(options_conference_));
2243 std::vector<cricket::AudioCodec> codecs;
2244 codecs.push_back(kPcmuCodec);
2245 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
2246 EXPECT_TRUE(channel_->SetSend(cricket::SEND_MICROPHONE));
2247 EXPECT_TRUE(voe_.GetSend(channel_num));
2248}
2249
2250// Test that we can create a channel configured for Codian bridges,
2251// and start sending/playing out on it.
2252TEST_F(WebRtcVoiceEngineTestFake, CodianSendAndPlayout) {
2253 EXPECT_TRUE(SetupEngine());
2254 int channel_num = voe_.GetLastChannel();
2255 webrtc::AgcConfig agc_config;
2256 EXPECT_EQ(0, voe_.GetAgcConfig(agc_config));
2257 EXPECT_EQ(0, agc_config.targetLeveldBOv);
2258 EXPECT_TRUE(channel_->SetOptions(options_adjust_agc_));
2259 std::vector<cricket::AudioCodec> codecs;
2260 codecs.push_back(kPcmuCodec);
2261 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
2262 EXPECT_TRUE(channel_->SetSend(cricket::SEND_MICROPHONE));
2263 EXPECT_TRUE(voe_.GetSend(channel_num));
2264 EXPECT_EQ(0, voe_.GetAgcConfig(agc_config));
2265 EXPECT_EQ(agc_config.targetLeveldBOv, 10); // level was attenuated
2266 EXPECT_TRUE(channel_->SetPlayout(true));
2267 EXPECT_TRUE(voe_.GetPlayout(channel_num));
2268 EXPECT_TRUE(channel_->SetSend(cricket::SEND_NOTHING));
2269 EXPECT_FALSE(voe_.GetSend(channel_num));
2270 EXPECT_EQ(0, voe_.GetAgcConfig(agc_config));
2271 EXPECT_EQ(0, agc_config.targetLeveldBOv); // level was restored
2272 EXPECT_TRUE(channel_->SetPlayout(false));
2273 EXPECT_FALSE(voe_.GetPlayout(channel_num));
2274}
2275
wu@webrtc.org97077a32013-10-25 21:18:33 +00002276TEST_F(WebRtcVoiceEngineTestFake, TxAgcConfigViaOptions) {
2277 EXPECT_TRUE(SetupEngine());
2278 webrtc::AgcConfig agc_config;
2279 EXPECT_EQ(0, voe_.GetAgcConfig(agc_config));
2280 EXPECT_EQ(0, agc_config.targetLeveldBOv);
2281
2282 cricket::AudioOptions options;
2283 options.tx_agc_target_dbov.Set(3);
2284 options.tx_agc_digital_compression_gain.Set(9);
2285 options.tx_agc_limiter.Set(true);
2286 options.auto_gain_control.Set(true);
2287 EXPECT_TRUE(engine_.SetOptions(options));
2288
2289 EXPECT_EQ(0, voe_.GetAgcConfig(agc_config));
2290 EXPECT_EQ(3, agc_config.targetLeveldBOv);
2291 EXPECT_EQ(9, agc_config.digitalCompressionGaindB);
2292 EXPECT_TRUE(agc_config.limiterEnable);
2293
2294 // Check interaction with adjust_agc_delta. Both should be respected, for
2295 // backwards compatibility.
2296 options.adjust_agc_delta.Set(-10);
2297 EXPECT_TRUE(engine_.SetOptions(options));
2298
2299 EXPECT_EQ(0, voe_.GetAgcConfig(agc_config));
2300 EXPECT_EQ(13, agc_config.targetLeveldBOv);
2301}
2302
2303TEST_F(WebRtcVoiceEngineTestFake, RxAgcConfigViaOptions) {
2304 EXPECT_TRUE(SetupEngine());
2305 int channel_num = voe_.GetLastChannel();
2306 cricket::AudioOptions options;
2307 options.rx_agc_target_dbov.Set(6);
2308 options.rx_agc_digital_compression_gain.Set(0);
2309 options.rx_agc_limiter.Set(true);
2310 options.rx_auto_gain_control.Set(true);
2311 EXPECT_TRUE(channel_->SetOptions(options));
2312
2313 webrtc::AgcConfig agc_config;
2314 EXPECT_EQ(0, engine_.voe()->processing()->GetRxAgcConfig(
2315 channel_num, agc_config));
2316 EXPECT_EQ(6, agc_config.targetLeveldBOv);
2317 EXPECT_EQ(0, agc_config.digitalCompressionGaindB);
2318 EXPECT_TRUE(agc_config.limiterEnable);
2319}
2320
2321TEST_F(WebRtcVoiceEngineTestFake, SampleRatesViaOptions) {
2322 EXPECT_TRUE(SetupEngine());
2323 cricket::AudioOptions options;
2324 options.recording_sample_rate.Set(48000u);
2325 options.playout_sample_rate.Set(44100u);
2326 EXPECT_TRUE(engine_.SetOptions(options));
2327
2328 unsigned int recording_sample_rate, playout_sample_rate;
2329 EXPECT_EQ(0, voe_.RecordingSampleRate(&recording_sample_rate));
2330 EXPECT_EQ(0, voe_.PlayoutSampleRate(&playout_sample_rate));
2331 EXPECT_EQ(48000u, recording_sample_rate);
2332 EXPECT_EQ(44100u, playout_sample_rate);
2333}
2334
2335TEST_F(WebRtcVoiceEngineTestFake, TraceFilterViaTraceOptions) {
2336 EXPECT_TRUE(SetupEngine());
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002337 engine_.SetLogging(rtc::LS_INFO, "");
wu@webrtc.org97077a32013-10-25 21:18:33 +00002338 EXPECT_EQ(
2339 // Info:
2340 webrtc::kTraceStateInfo | webrtc::kTraceInfo |
2341 // Warning:
2342 webrtc::kTraceTerseInfo | webrtc::kTraceWarning |
2343 // Error:
2344 webrtc::kTraceError | webrtc::kTraceCritical,
2345 static_cast<int>(trace_wrapper_->filter_));
2346 // Now set it explicitly
2347 std::string filter =
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002348 "tracefilter " + rtc::ToString(webrtc::kTraceDefault);
2349 engine_.SetLogging(rtc::LS_VERBOSE, filter.c_str());
wu@webrtc.org97077a32013-10-25 21:18:33 +00002350 EXPECT_EQ(static_cast<unsigned int>(webrtc::kTraceDefault),
2351 trace_wrapper_->filter_);
2352}
2353
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002354// Test that we can set the outgoing SSRC properly.
2355// SSRC is set in SetupEngine by calling AddSendStream.
2356TEST_F(WebRtcVoiceEngineTestFake, SetSendSsrc) {
2357 EXPECT_TRUE(SetupEngine());
2358 int channel_num = voe_.GetLastChannel();
2359 unsigned int send_ssrc;
2360 EXPECT_EQ(0, voe_.GetLocalSSRC(channel_num, send_ssrc));
2361 EXPECT_NE(0U, send_ssrc);
2362 EXPECT_EQ(0, voe_.GetLocalSSRC(channel_num, send_ssrc));
2363 EXPECT_EQ(kSsrc1, send_ssrc);
2364}
2365
2366TEST_F(WebRtcVoiceEngineTestFake, GetStats) {
2367 // Setup. We need send codec to be set to get all stats.
2368 EXPECT_TRUE(SetupEngine());
buildbot@webrtc.org7e71b772014-06-13 01:14:01 +00002369 // SetupEngine adds a send stream with kSsrc1, so the receive stream has to
2370 // use a different SSRC.
2371 EXPECT_TRUE(channel_->AddRecvStream(
2372 cricket::StreamParams::CreateLegacy(kSsrc2)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002373 std::vector<cricket::AudioCodec> codecs;
2374 codecs.push_back(kPcmuCodec);
2375 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
buildbot@webrtc.org7e71b772014-06-13 01:14:01 +00002376 EXPECT_TRUE(channel_->SetRecvCodecs(codecs));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002377
2378 cricket::VoiceMediaInfo info;
2379 EXPECT_EQ(true, channel_->GetStats(&info));
2380 EXPECT_EQ(1u, info.senders.size());
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +00002381 EXPECT_EQ(kSsrc1, info.senders[0].ssrc());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002382 EXPECT_EQ(kPcmuCodec.name, info.senders[0].codec_name);
2383 EXPECT_EQ(cricket::kIntStatValue, info.senders[0].bytes_sent);
2384 EXPECT_EQ(cricket::kIntStatValue, info.senders[0].packets_sent);
2385 EXPECT_EQ(cricket::kIntStatValue, info.senders[0].packets_lost);
2386 EXPECT_EQ(cricket::kFractionLostStatValue, info.senders[0].fraction_lost);
2387 EXPECT_EQ(cricket::kIntStatValue, info.senders[0].ext_seqnum);
2388 EXPECT_EQ(cricket::kIntStatValue, info.senders[0].rtt_ms);
2389 EXPECT_EQ(cricket::kIntStatValue, info.senders[0].jitter_ms);
buildbot@webrtc.org7e71b772014-06-13 01:14:01 +00002390 EXPECT_EQ(kPcmuCodec.name, info.senders[0].codec_name);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002391 // TODO(sriniv): Add testing for more fields. These are not populated
2392 // in FakeWebrtcVoiceEngine yet.
2393 // EXPECT_EQ(cricket::kIntStatValue, info.senders[0].audio_level);
2394 // EXPECT_EQ(cricket::kIntStatValue, info.senders[0].echo_delay_median_ms);
2395 // EXPECT_EQ(cricket::kIntStatValue, info.senders[0].echo_delay_std_ms);
2396 // EXPECT_EQ(cricket::kIntStatValue, info.senders[0].echo_return_loss);
2397 // EXPECT_EQ(cricket::kIntStatValue,
2398 // info.senders[0].echo_return_loss_enhancement);
2399
buildbot@webrtc.org7e71b772014-06-13 01:14:01 +00002400 EXPECT_EQ(0u, info.receivers.size());
2401 DeliverPacket(kPcmuFrame, sizeof(kPcmuFrame));
2402 EXPECT_EQ(true, channel_->GetStats(&info));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002403 EXPECT_EQ(1u, info.receivers.size());
buildbot@webrtc.org7e71b772014-06-13 01:14:01 +00002404
2405 EXPECT_EQ(cricket::kIntStatValue, info.receivers[0].bytes_rcvd);
2406 EXPECT_EQ(cricket::kIntStatValue, info.receivers[0].packets_rcvd);
2407 EXPECT_EQ(cricket::kIntStatValue, info.receivers[0].packets_lost);
2408 EXPECT_EQ(cricket::kIntStatValue, info.receivers[0].ext_seqnum);
2409 EXPECT_EQ(kPcmuCodec.name, info.receivers[0].codec_name);
minyue@webrtc.orgc0bd7be2015-02-18 15:24:13 +00002410 EXPECT_EQ(static_cast<float>(cricket::kNetStats.currentExpandRate) /
2411 (1 << 14), info.receivers[0].expand_rate);
2412 EXPECT_EQ(static_cast<float>(cricket::kNetStats.currentSpeechExpandRate) /
2413 (1 << 14), info.receivers[0].speech_expand_rate);
2414 EXPECT_EQ(static_cast<float>(cricket::kNetStats.currentSecondaryDecodedRate) /
2415 (1 << 14), info.receivers[0].secondary_decoded_rate);
buildbot@webrtc.org7e71b772014-06-13 01:14:01 +00002416 // TODO(sriniv): Add testing for more receiver fields.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002417}
2418
2419// Test that we can set the outgoing SSRC properly with multiple streams.
2420// SSRC is set in SetupEngine by calling AddSendStream.
2421TEST_F(WebRtcVoiceEngineTestFake, SetSendSsrcWithMultipleStreams) {
2422 EXPECT_TRUE(SetupEngine());
2423 EXPECT_TRUE(channel_->SetOptions(options_conference_));
2424 int channel_num1 = voe_.GetLastChannel();
2425 unsigned int send_ssrc;
2426 EXPECT_EQ(0, voe_.GetLocalSSRC(channel_num1, send_ssrc));
2427 EXPECT_EQ(kSsrc1, send_ssrc);
2428
2429 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(2)));
2430 int channel_num2 = voe_.GetLastChannel();
2431 EXPECT_EQ(0, voe_.GetLocalSSRC(channel_num2, send_ssrc));
2432 EXPECT_EQ(kSsrc1, send_ssrc);
2433}
2434
2435// Test that the local SSRC is the same on sending and receiving channels if the
2436// receive channel is created before the send channel.
2437TEST_F(WebRtcVoiceEngineTestFake, SetSendSsrcAfterCreatingReceiveChannel) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002438 EXPECT_TRUE(engine_.Init(rtc::Thread::Current()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002439 channel_ = engine_.CreateChannel();
2440 EXPECT_TRUE(channel_->SetOptions(options_conference_));
2441
2442 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(1)));
2443 int receive_channel_num = voe_.GetLastChannel();
2444 EXPECT_TRUE(channel_->AddSendStream(
2445 cricket::StreamParams::CreateLegacy(1234)));
2446 int send_channel_num = voe_.GetLastChannel();
2447
2448 unsigned int ssrc = 0;
2449 EXPECT_EQ(0, voe_.GetLocalSSRC(send_channel_num, ssrc));
2450 EXPECT_EQ(1234U, ssrc);
2451 ssrc = 0;
2452 EXPECT_EQ(0, voe_.GetLocalSSRC(receive_channel_num, ssrc));
2453 EXPECT_EQ(1234U, ssrc);
2454}
2455
2456// Test that we can properly receive packets.
2457TEST_F(WebRtcVoiceEngineTestFake, Recv) {
2458 EXPECT_TRUE(SetupEngine());
2459 int channel_num = voe_.GetLastChannel();
2460 DeliverPacket(kPcmuFrame, sizeof(kPcmuFrame));
2461 EXPECT_TRUE(voe_.CheckPacket(channel_num, kPcmuFrame,
2462 sizeof(kPcmuFrame)));
2463}
2464
2465// Test that we can properly receive packets on multiple streams.
2466TEST_F(WebRtcVoiceEngineTestFake, RecvWithMultipleStreams) {
2467 EXPECT_TRUE(SetupEngine());
2468 EXPECT_TRUE(channel_->SetOptions(options_conference_));
2469 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(1)));
2470 int channel_num1 = voe_.GetLastChannel();
2471 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(2)));
2472 int channel_num2 = voe_.GetLastChannel();
2473 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(3)));
2474 int channel_num3 = voe_.GetLastChannel();
2475 // Create packets with the right SSRCs.
2476 char packets[4][sizeof(kPcmuFrame)];
2477 for (size_t i = 0; i < ARRAY_SIZE(packets); ++i) {
2478 memcpy(packets[i], kPcmuFrame, sizeof(kPcmuFrame));
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002479 rtc::SetBE32(packets[i] + 8, static_cast<uint32>(i));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002480 }
2481 EXPECT_TRUE(voe_.CheckNoPacket(channel_num1));
2482 EXPECT_TRUE(voe_.CheckNoPacket(channel_num2));
2483 EXPECT_TRUE(voe_.CheckNoPacket(channel_num3));
2484 DeliverPacket(packets[0], sizeof(packets[0]));
2485 EXPECT_TRUE(voe_.CheckNoPacket(channel_num1));
2486 EXPECT_TRUE(voe_.CheckNoPacket(channel_num2));
2487 EXPECT_TRUE(voe_.CheckNoPacket(channel_num3));
2488 DeliverPacket(packets[1], sizeof(packets[1]));
2489 EXPECT_TRUE(voe_.CheckPacket(channel_num1, packets[1],
2490 sizeof(packets[1])));
2491 EXPECT_TRUE(voe_.CheckNoPacket(channel_num2));
2492 EXPECT_TRUE(voe_.CheckNoPacket(channel_num3));
2493 DeliverPacket(packets[2], sizeof(packets[2]));
2494 EXPECT_TRUE(voe_.CheckNoPacket(channel_num1));
2495 EXPECT_TRUE(voe_.CheckPacket(channel_num2, packets[2],
2496 sizeof(packets[2])));
2497 EXPECT_TRUE(voe_.CheckNoPacket(channel_num3));
2498 DeliverPacket(packets[3], sizeof(packets[3]));
2499 EXPECT_TRUE(voe_.CheckNoPacket(channel_num1));
2500 EXPECT_TRUE(voe_.CheckNoPacket(channel_num2));
2501 EXPECT_TRUE(voe_.CheckPacket(channel_num3, packets[3],
2502 sizeof(packets[3])));
2503 EXPECT_TRUE(channel_->RemoveRecvStream(3));
2504 EXPECT_TRUE(channel_->RemoveRecvStream(2));
2505 EXPECT_TRUE(channel_->RemoveRecvStream(1));
2506}
2507
2508// Test that we properly handle failures to add a stream.
2509TEST_F(WebRtcVoiceEngineTestFake, AddStreamFail) {
2510 EXPECT_TRUE(SetupEngine());
2511 voe_.set_fail_create_channel(true);
2512 EXPECT_TRUE(channel_->SetOptions(options_conference_));
2513 EXPECT_FALSE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(2)));
2514
2515 // In 1:1 call, we should not try to create a new channel.
2516 cricket::AudioOptions options_no_conference_;
2517 options_no_conference_.conference_mode.Set(false);
2518 EXPECT_TRUE(channel_->SetOptions(options_no_conference_));
2519 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(2)));
2520}
2521
2522// Test that AddRecvStream doesn't create new channel for 1:1 call.
2523TEST_F(WebRtcVoiceEngineTestFake, AddRecvStream1On1) {
2524 EXPECT_TRUE(SetupEngine());
2525 int channel_num = voe_.GetLastChannel();
2526 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(1)));
2527 EXPECT_EQ(channel_num, voe_.GetLastChannel());
2528}
2529
2530// Test that after adding a recv stream, we do not decode more codecs than
2531// those previously passed into SetRecvCodecs.
2532TEST_F(WebRtcVoiceEngineTestFake, AddRecvStreamUnsupportedCodec) {
2533 EXPECT_TRUE(SetupEngine());
2534 EXPECT_TRUE(channel_->SetOptions(options_conference_));
2535 std::vector<cricket::AudioCodec> codecs;
2536 codecs.push_back(kIsacCodec);
2537 codecs.push_back(kPcmuCodec);
2538 EXPECT_TRUE(channel_->SetRecvCodecs(codecs));
2539 EXPECT_TRUE(channel_->AddRecvStream(
2540 cricket::StreamParams::CreateLegacy(kSsrc1)));
2541 int channel_num2 = voe_.GetLastChannel();
2542 webrtc::CodecInst gcodec;
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +00002543 rtc::strcpyn(gcodec.plname, ARRAY_SIZE(gcodec.plname), "opus");
2544 gcodec.plfreq = 48000;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002545 gcodec.channels = 2;
2546 EXPECT_EQ(-1, voe_.GetRecPayloadType(channel_num2, gcodec));
2547}
2548
2549// Test that we properly clean up any streams that were added, even if
2550// not explicitly removed.
2551TEST_F(WebRtcVoiceEngineTestFake, StreamCleanup) {
2552 EXPECT_TRUE(SetupEngine());
2553 EXPECT_TRUE(channel_->SetOptions(options_conference_));
2554 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(1)));
2555 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(2)));
2556 EXPECT_EQ(3, voe_.GetNumChannels()); // default channel + 2 added
2557 delete channel_;
2558 channel_ = NULL;
2559 EXPECT_EQ(0, voe_.GetNumChannels());
2560}
2561
wu@webrtc.org78187522013-10-07 23:32:02 +00002562TEST_F(WebRtcVoiceEngineTestFake, TestAddRecvStreamFailWithZeroSsrc) {
2563 EXPECT_TRUE(SetupEngine());
2564 EXPECT_FALSE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(0)));
2565}
2566
2567TEST_F(WebRtcVoiceEngineTestFake, TestNoLeakingWhenAddRecvStreamFail) {
2568 EXPECT_TRUE(SetupEngine());
2569 // Stream 1 reuses default channel.
2570 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(1)));
2571 // Manually delete default channel to simulate a failure.
2572 int default_channel = voe_.GetLastChannel();
2573 EXPECT_EQ(0, voe_.DeleteChannel(default_channel));
2574 // Add recv stream 2 should fail because default channel is gone.
2575 EXPECT_FALSE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(2)));
2576 int new_channel = voe_.GetLastChannel();
2577 EXPECT_NE(default_channel, new_channel);
2578 // The last created channel should have already been deleted.
2579 EXPECT_EQ(-1, voe_.DeleteChannel(new_channel));
2580}
2581
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002582// Test the InsertDtmf on default send stream as caller.
2583TEST_F(WebRtcVoiceEngineTestFake, InsertDtmfOnDefaultSendStreamAsCaller) {
2584 TestInsertDtmf(0, true);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002585}
2586
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002587// Test the InsertDtmf on default send stream as callee
2588TEST_F(WebRtcVoiceEngineTestFake, InsertDtmfOnDefaultSendStreamAsCallee) {
2589 TestInsertDtmf(0, false);
2590}
2591
2592// Test the InsertDtmf on specified send stream as caller.
2593TEST_F(WebRtcVoiceEngineTestFake, InsertDtmfOnSendStreamAsCaller) {
2594 TestInsertDtmf(kSsrc1, true);
2595}
2596
2597// Test the InsertDtmf on specified send stream as callee.
2598TEST_F(WebRtcVoiceEngineTestFake, InsertDtmfOnSendStreamAsCallee) {
2599 TestInsertDtmf(kSsrc1, false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002600}
2601
2602// Test that we can play a ringback tone properly in a single-stream call.
2603TEST_F(WebRtcVoiceEngineTestFake, PlayRingback) {
2604 EXPECT_TRUE(SetupEngine());
2605 int channel_num = voe_.GetLastChannel();
2606 EXPECT_EQ(0, voe_.IsPlayingFileLocally(channel_num));
2607 // Check we fail if no ringback tone specified.
2608 EXPECT_FALSE(channel_->PlayRingbackTone(0, true, true));
2609 EXPECT_EQ(0, voe_.IsPlayingFileLocally(channel_num));
2610 // Check we can set and play a ringback tone.
wu@webrtc.org9caf2762013-12-11 18:25:07 +00002611 EXPECT_TRUE(channel_->SetRingbackTone(
2612 kRingbackTone, static_cast<int>(strlen(kRingbackTone))));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002613 EXPECT_TRUE(channel_->PlayRingbackTone(0, true, true));
2614 EXPECT_EQ(1, voe_.IsPlayingFileLocally(channel_num));
2615 // Check we can stop the tone manually.
2616 EXPECT_TRUE(channel_->PlayRingbackTone(0, false, false));
2617 EXPECT_EQ(0, voe_.IsPlayingFileLocally(channel_num));
2618 // Check we stop the tone if a packet arrives.
2619 EXPECT_TRUE(channel_->PlayRingbackTone(0, true, true));
2620 EXPECT_EQ(1, voe_.IsPlayingFileLocally(channel_num));
2621 DeliverPacket(kPcmuFrame, sizeof(kPcmuFrame));
2622 EXPECT_EQ(0, voe_.IsPlayingFileLocally(channel_num));
2623}
2624
2625// Test that we can play a ringback tone properly in a multi-stream call.
2626TEST_F(WebRtcVoiceEngineTestFake, PlayRingbackWithMultipleStreams) {
2627 EXPECT_TRUE(SetupEngine());
2628 EXPECT_TRUE(channel_->SetOptions(options_conference_));
2629 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(1)));
2630 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(2)));
2631 int channel_num = voe_.GetLastChannel();
2632 EXPECT_EQ(0, voe_.IsPlayingFileLocally(channel_num));
2633 // Check we fail if no ringback tone specified.
2634 EXPECT_FALSE(channel_->PlayRingbackTone(2, true, true));
2635 EXPECT_EQ(0, voe_.IsPlayingFileLocally(channel_num));
2636 // Check we can set and play a ringback tone on the correct ssrc.
wu@webrtc.org9caf2762013-12-11 18:25:07 +00002637 EXPECT_TRUE(channel_->SetRingbackTone(
2638 kRingbackTone, static_cast<int>(strlen(kRingbackTone))));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002639 EXPECT_FALSE(channel_->PlayRingbackTone(77, true, true));
2640 EXPECT_TRUE(channel_->PlayRingbackTone(2, true, true));
2641 EXPECT_EQ(1, voe_.IsPlayingFileLocally(channel_num));
2642 // Check we can stop the tone manually.
2643 EXPECT_TRUE(channel_->PlayRingbackTone(2, false, false));
2644 EXPECT_EQ(0, voe_.IsPlayingFileLocally(channel_num));
2645 // Check we stop the tone if a packet arrives, but only with the right SSRC.
2646 EXPECT_TRUE(channel_->PlayRingbackTone(2, true, true));
2647 EXPECT_EQ(1, voe_.IsPlayingFileLocally(channel_num));
2648 // Send a packet with SSRC 1; the tone should not stop.
2649 DeliverPacket(kPcmuFrame, sizeof(kPcmuFrame));
2650 EXPECT_EQ(1, voe_.IsPlayingFileLocally(channel_num));
2651 // Send a packet with SSRC 2; the tone should stop.
2652 char packet[sizeof(kPcmuFrame)];
2653 memcpy(packet, kPcmuFrame, sizeof(kPcmuFrame));
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002654 rtc::SetBE32(packet + 8, 2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002655 DeliverPacket(packet, sizeof(packet));
2656 EXPECT_EQ(0, voe_.IsPlayingFileLocally(channel_num));
2657}
2658
2659// Tests creating soundclips, and make sure they come from the right engine.
2660TEST_F(WebRtcVoiceEngineTestFake, CreateSoundclip) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002661 EXPECT_TRUE(engine_.Init(rtc::Thread::Current()));
wu@webrtc.org4551b792013-10-09 15:37:36 +00002662 EXPECT_FALSE(voe_sc_.IsInited());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002663 soundclip_ = engine_.CreateSoundclip();
wu@webrtc.org4551b792013-10-09 15:37:36 +00002664 EXPECT_TRUE(voe_sc_.IsInited());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002665 ASSERT_TRUE(soundclip_ != NULL);
2666 EXPECT_EQ(0, voe_.GetNumChannels());
2667 EXPECT_EQ(1, voe_sc_.GetNumChannels());
2668 int channel_num = voe_sc_.GetLastChannel();
2669 EXPECT_TRUE(voe_sc_.GetPlayout(channel_num));
2670 delete soundclip_;
2671 soundclip_ = NULL;
2672 EXPECT_EQ(0, voe_sc_.GetNumChannels());
wu@webrtc.org4551b792013-10-09 15:37:36 +00002673 // Make sure the soundclip engine is uninitialized on shutdown, now that
2674 // we've initialized it by creating a soundclip.
2675 engine_.Terminate();
2676 EXPECT_FALSE(voe_sc_.IsInited());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002677}
2678
2679// Tests playing out a fake sound.
2680TEST_F(WebRtcVoiceEngineTestFake, PlaySoundclip) {
2681 static const char kZeroes[16000] = {};
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002682 EXPECT_TRUE(engine_.Init(rtc::Thread::Current()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002683 soundclip_ = engine_.CreateSoundclip();
2684 ASSERT_TRUE(soundclip_ != NULL);
2685 EXPECT_TRUE(soundclip_->PlaySound(kZeroes, sizeof(kZeroes), 0));
2686}
2687
2688TEST_F(WebRtcVoiceEngineTestFake, MediaEngineCallbackOnError) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002689 rtc::scoped_ptr<ChannelErrorListener> listener;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002690 cricket::WebRtcVoiceMediaChannel* media_channel;
2691 unsigned int ssrc = 0;
2692
2693 EXPECT_TRUE(SetupEngine());
2694 EXPECT_TRUE(channel_->SetOptions(options_conference_));
2695 EXPECT_TRUE(channel_->SetSend(cricket::SEND_MICROPHONE));
2696
2697 media_channel = static_cast<cricket::WebRtcVoiceMediaChannel*>(channel_);
2698 listener.reset(new ChannelErrorListener(channel_));
2699
2700 // Test on WebRtc VoE channel.
2701 voe_.TriggerCallbackOnError(media_channel->voe_channel(),
2702 VE_SATURATION_WARNING);
2703 EXPECT_EQ(cricket::VoiceMediaChannel::ERROR_REC_DEVICE_SATURATION,
2704 listener->error());
2705 EXPECT_NE(-1, voe_.GetLocalSSRC(voe_.GetLastChannel(), ssrc));
2706 EXPECT_EQ(ssrc, listener->ssrc());
2707
2708 listener->Reset();
2709 voe_.TriggerCallbackOnError(-1, VE_TYPING_NOISE_WARNING);
2710 EXPECT_EQ(cricket::VoiceMediaChannel::ERROR_REC_TYPING_NOISE_DETECTED,
2711 listener->error());
2712 EXPECT_EQ(0U, listener->ssrc());
2713
2714 // Add another stream and test on that.
2715 ++ssrc;
2716 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(
2717 ssrc)));
2718 listener->Reset();
2719 voe_.TriggerCallbackOnError(voe_.GetLastChannel(),
2720 VE_SATURATION_WARNING);
2721 EXPECT_EQ(cricket::VoiceMediaChannel::ERROR_REC_DEVICE_SATURATION,
2722 listener->error());
2723 EXPECT_EQ(ssrc, listener->ssrc());
2724
2725 // Testing a non-existing channel.
2726 listener->Reset();
2727 voe_.TriggerCallbackOnError(voe_.GetLastChannel() + 2,
2728 VE_SATURATION_WARNING);
2729 EXPECT_EQ(0, listener->error());
2730}
2731
2732TEST_F(WebRtcVoiceEngineTestFake, TestSetPlayoutError) {
2733 EXPECT_TRUE(SetupEngine());
2734 EXPECT_TRUE(channel_->SetOptions(options_conference_));
2735 std::vector<cricket::AudioCodec> codecs;
2736 codecs.push_back(kPcmuCodec);
2737 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
2738 EXPECT_TRUE(channel_->SetSend(cricket::SEND_MICROPHONE));
2739 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(2)));
2740 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(3)));
2741 EXPECT_TRUE(channel_->SetPlayout(true));
2742 voe_.set_playout_fail_channel(voe_.GetLastChannel() - 1);
2743 EXPECT_TRUE(channel_->SetPlayout(false));
2744 EXPECT_FALSE(channel_->SetPlayout(true));
2745}
2746
2747// Test that the Registering/Unregistering with the
2748// webrtcvoiceengine works as expected
2749TEST_F(WebRtcVoiceEngineTestFake, RegisterVoiceProcessor) {
2750 EXPECT_TRUE(SetupEngine());
2751 EXPECT_TRUE(channel_->SetOptions(options_conference_));
2752 EXPECT_TRUE(channel_->AddRecvStream(
2753 cricket::StreamParams::CreateLegacy(kSsrc2)));
2754 cricket::FakeMediaProcessor vp_1;
2755 cricket::FakeMediaProcessor vp_2;
2756
2757 EXPECT_FALSE(engine_.RegisterProcessor(kSsrc2, &vp_1, cricket::MPD_TX));
2758 EXPECT_TRUE(engine_.RegisterProcessor(kSsrc2, &vp_1, cricket::MPD_RX));
2759 EXPECT_TRUE(engine_.RegisterProcessor(kSsrc2, &vp_2, cricket::MPD_RX));
2760 voe_.TriggerProcessPacket(cricket::MPD_RX);
2761 voe_.TriggerProcessPacket(cricket::MPD_TX);
2762
2763 EXPECT_TRUE(voe_.IsExternalMediaProcessorRegistered());
2764 EXPECT_EQ(1, vp_1.voice_frame_count());
2765 EXPECT_EQ(1, vp_2.voice_frame_count());
2766
2767 EXPECT_TRUE(engine_.UnregisterProcessor(kSsrc2,
2768 &vp_2,
2769 cricket::MPD_RX));
2770 voe_.TriggerProcessPacket(cricket::MPD_RX);
2771 EXPECT_TRUE(voe_.IsExternalMediaProcessorRegistered());
2772 EXPECT_EQ(1, vp_2.voice_frame_count());
2773 EXPECT_EQ(2, vp_1.voice_frame_count());
2774
2775 EXPECT_TRUE(engine_.UnregisterProcessor(kSsrc2,
2776 &vp_1,
2777 cricket::MPD_RX));
2778 voe_.TriggerProcessPacket(cricket::MPD_RX);
2779 EXPECT_FALSE(voe_.IsExternalMediaProcessorRegistered());
2780 EXPECT_EQ(2, vp_1.voice_frame_count());
2781
2782 EXPECT_FALSE(engine_.RegisterProcessor(kSsrc1, &vp_1, cricket::MPD_RX));
2783 EXPECT_TRUE(engine_.RegisterProcessor(kSsrc1, &vp_1, cricket::MPD_TX));
2784 voe_.TriggerProcessPacket(cricket::MPD_RX);
2785 voe_.TriggerProcessPacket(cricket::MPD_TX);
2786 EXPECT_TRUE(voe_.IsExternalMediaProcessorRegistered());
2787 EXPECT_EQ(3, vp_1.voice_frame_count());
2788
2789 EXPECT_TRUE(engine_.UnregisterProcessor(kSsrc1,
2790 &vp_1,
2791 cricket::MPD_RX_AND_TX));
2792 voe_.TriggerProcessPacket(cricket::MPD_TX);
2793 EXPECT_FALSE(voe_.IsExternalMediaProcessorRegistered());
2794 EXPECT_EQ(3, vp_1.voice_frame_count());
2795 EXPECT_TRUE(channel_->RemoveRecvStream(kSsrc2));
2796 EXPECT_FALSE(engine_.RegisterProcessor(kSsrc2, &vp_1, cricket::MPD_RX));
2797 EXPECT_FALSE(voe_.IsExternalMediaProcessorRegistered());
2798
2799 // Test that we can register a processor on the receive channel on SSRC 0.
2800 // This tests the 1:1 case when the receive SSRC is unknown.
2801 EXPECT_TRUE(engine_.RegisterProcessor(0, &vp_1, cricket::MPD_RX));
2802 voe_.TriggerProcessPacket(cricket::MPD_RX);
2803 EXPECT_TRUE(voe_.IsExternalMediaProcessorRegistered());
2804 EXPECT_EQ(4, vp_1.voice_frame_count());
2805 EXPECT_TRUE(engine_.UnregisterProcessor(0,
2806 &vp_1,
2807 cricket::MPD_RX));
2808
2809 // The following tests test that FindChannelNumFromSsrc is doing
2810 // what we expect.
2811 // pick an invalid ssrc and make sure we can't register
2812 EXPECT_FALSE(engine_.RegisterProcessor(99,
2813 &vp_1,
2814 cricket::MPD_RX));
2815 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(1)));
2816 EXPECT_TRUE(engine_.RegisterProcessor(1,
2817 &vp_1,
2818 cricket::MPD_RX));
2819 EXPECT_TRUE(engine_.UnregisterProcessor(1,
2820 &vp_1,
2821 cricket::MPD_RX));
2822 EXPECT_FALSE(engine_.RegisterProcessor(1,
2823 &vp_1,
2824 cricket::MPD_TX));
2825 EXPECT_TRUE(channel_->RemoveRecvStream(1));
2826}
2827
2828TEST_F(WebRtcVoiceEngineTestFake, SetAudioOptions) {
2829 EXPECT_TRUE(SetupEngine());
2830
2831 bool ec_enabled;
2832 webrtc::EcModes ec_mode;
2833 bool ec_metrics_enabled;
2834 webrtc::AecmModes aecm_mode;
2835 bool cng_enabled;
2836 bool agc_enabled;
2837 webrtc::AgcModes agc_mode;
2838 webrtc::AgcConfig agc_config;
2839 bool ns_enabled;
2840 webrtc::NsModes ns_mode;
2841 bool highpass_filter_enabled;
2842 bool stereo_swapping_enabled;
2843 bool typing_detection_enabled;
2844 voe_.GetEcStatus(ec_enabled, ec_mode);
2845 voe_.GetEcMetricsStatus(ec_metrics_enabled);
2846 voe_.GetAecmMode(aecm_mode, cng_enabled);
2847 voe_.GetAgcStatus(agc_enabled, agc_mode);
2848 voe_.GetAgcConfig(agc_config);
2849 voe_.GetNsStatus(ns_enabled, ns_mode);
2850 highpass_filter_enabled = voe_.IsHighPassFilterEnabled();
2851 stereo_swapping_enabled = voe_.IsStereoChannelSwappingEnabled();
2852 voe_.GetTypingDetectionStatus(typing_detection_enabled);
2853 EXPECT_TRUE(ec_enabled);
2854 EXPECT_TRUE(ec_metrics_enabled);
2855 EXPECT_FALSE(cng_enabled);
2856 EXPECT_TRUE(agc_enabled);
2857 EXPECT_EQ(0, agc_config.targetLeveldBOv);
2858 EXPECT_TRUE(ns_enabled);
2859 EXPECT_TRUE(highpass_filter_enabled);
2860 EXPECT_FALSE(stereo_swapping_enabled);
2861 EXPECT_TRUE(typing_detection_enabled);
2862 EXPECT_EQ(ec_mode, webrtc::kEcConference);
2863 EXPECT_EQ(ns_mode, webrtc::kNsHighSuppression);
2864
2865 // Nothing set, so all ignored.
2866 cricket::AudioOptions options;
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00002867 ASSERT_TRUE(engine_.SetOptions(options));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002868 voe_.GetEcStatus(ec_enabled, ec_mode);
2869 voe_.GetEcMetricsStatus(ec_metrics_enabled);
2870 voe_.GetAecmMode(aecm_mode, cng_enabled);
2871 voe_.GetAgcStatus(agc_enabled, agc_mode);
2872 voe_.GetAgcConfig(agc_config);
2873 voe_.GetNsStatus(ns_enabled, ns_mode);
2874 highpass_filter_enabled = voe_.IsHighPassFilterEnabled();
2875 stereo_swapping_enabled = voe_.IsStereoChannelSwappingEnabled();
2876 voe_.GetTypingDetectionStatus(typing_detection_enabled);
2877 EXPECT_TRUE(ec_enabled);
2878 EXPECT_TRUE(ec_metrics_enabled);
2879 EXPECT_FALSE(cng_enabled);
2880 EXPECT_TRUE(agc_enabled);
2881 EXPECT_EQ(0, agc_config.targetLeveldBOv);
2882 EXPECT_TRUE(ns_enabled);
2883 EXPECT_TRUE(highpass_filter_enabled);
2884 EXPECT_FALSE(stereo_swapping_enabled);
2885 EXPECT_TRUE(typing_detection_enabled);
2886 EXPECT_EQ(ec_mode, webrtc::kEcConference);
2887 EXPECT_EQ(ns_mode, webrtc::kNsHighSuppression);
2888
2889 // Turn echo cancellation off
2890 options.echo_cancellation.Set(false);
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00002891 ASSERT_TRUE(engine_.SetOptions(options));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002892 voe_.GetEcStatus(ec_enabled, ec_mode);
2893 EXPECT_FALSE(ec_enabled);
2894
2895 // Turn echo cancellation back on, with settings, and make sure
2896 // nothing else changed.
2897 options.echo_cancellation.Set(true);
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00002898 ASSERT_TRUE(engine_.SetOptions(options));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002899 voe_.GetEcStatus(ec_enabled, ec_mode);
2900 voe_.GetEcMetricsStatus(ec_metrics_enabled);
2901 voe_.GetAecmMode(aecm_mode, cng_enabled);
2902 voe_.GetAgcStatus(agc_enabled, agc_mode);
2903 voe_.GetAgcConfig(agc_config);
2904 voe_.GetNsStatus(ns_enabled, ns_mode);
2905 highpass_filter_enabled = voe_.IsHighPassFilterEnabled();
2906 stereo_swapping_enabled = voe_.IsStereoChannelSwappingEnabled();
2907 voe_.GetTypingDetectionStatus(typing_detection_enabled);
2908 EXPECT_TRUE(ec_enabled);
2909 EXPECT_TRUE(ec_metrics_enabled);
2910 EXPECT_TRUE(agc_enabled);
2911 EXPECT_EQ(0, agc_config.targetLeveldBOv);
2912 EXPECT_TRUE(ns_enabled);
2913 EXPECT_TRUE(highpass_filter_enabled);
2914 EXPECT_FALSE(stereo_swapping_enabled);
2915 EXPECT_TRUE(typing_detection_enabled);
2916 EXPECT_EQ(ec_mode, webrtc::kEcConference);
2917 EXPECT_EQ(ns_mode, webrtc::kNsHighSuppression);
2918
Bjorn Volckerbf395c12015-03-25 22:45:56 +01002919 // Turn on delay agnostic aec and make sure nothing change w.r.t. echo
2920 // control.
2921 options.delay_agnostic_aec.Set(true);
2922 ASSERT_TRUE(engine_.SetOptions(options));
2923 voe_.GetEcStatus(ec_enabled, ec_mode);
2924 voe_.GetEcMetricsStatus(ec_metrics_enabled);
2925 voe_.GetAecmMode(aecm_mode, cng_enabled);
2926 EXPECT_TRUE(ec_enabled);
2927 EXPECT_TRUE(ec_metrics_enabled);
2928 EXPECT_EQ(ec_mode, webrtc::kEcConference);
2929
2930 // Turn off echo cancellation and delay agnostic aec.
2931 options.delay_agnostic_aec.Set(false);
2932 options.experimental_aec.Set(false);
2933 options.echo_cancellation.Set(false);
2934 ASSERT_TRUE(engine_.SetOptions(options));
2935 voe_.GetEcStatus(ec_enabled, ec_mode);
2936 EXPECT_FALSE(ec_enabled);
2937 // Turning delay agnostic aec back on should also turn on echo cancellation.
2938 options.delay_agnostic_aec.Set(true);
2939 ASSERT_TRUE(engine_.SetOptions(options));
2940 voe_.GetEcStatus(ec_enabled, ec_mode);
2941 voe_.GetEcMetricsStatus(ec_metrics_enabled);
2942 EXPECT_TRUE(ec_enabled);
2943 EXPECT_TRUE(ec_metrics_enabled);
2944 EXPECT_EQ(ec_mode, webrtc::kEcConference);
2945
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002946 // Turn off AGC
2947 options.auto_gain_control.Set(false);
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00002948 ASSERT_TRUE(engine_.SetOptions(options));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002949 voe_.GetAgcStatus(agc_enabled, agc_mode);
2950 EXPECT_FALSE(agc_enabled);
2951
2952 // Turn AGC back on
2953 options.auto_gain_control.Set(true);
2954 options.adjust_agc_delta.Clear();
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00002955 ASSERT_TRUE(engine_.SetOptions(options));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002956 voe_.GetAgcStatus(agc_enabled, agc_mode);
2957 EXPECT_TRUE(agc_enabled);
2958 voe_.GetAgcConfig(agc_config);
2959 EXPECT_EQ(0, agc_config.targetLeveldBOv);
2960
2961 // Turn off other options (and stereo swapping on).
2962 options.noise_suppression.Set(false);
2963 options.highpass_filter.Set(false);
2964 options.typing_detection.Set(false);
2965 options.stereo_swapping.Set(true);
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00002966 ASSERT_TRUE(engine_.SetOptions(options));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002967 voe_.GetNsStatus(ns_enabled, ns_mode);
2968 highpass_filter_enabled = voe_.IsHighPassFilterEnabled();
2969 stereo_swapping_enabled = voe_.IsStereoChannelSwappingEnabled();
2970 voe_.GetTypingDetectionStatus(typing_detection_enabled);
2971 EXPECT_FALSE(ns_enabled);
2972 EXPECT_FALSE(highpass_filter_enabled);
2973 EXPECT_FALSE(typing_detection_enabled);
2974 EXPECT_TRUE(stereo_swapping_enabled);
2975
2976 // Turn on "conference mode" to ensure it has no impact.
2977 options.conference_mode.Set(true);
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00002978 ASSERT_TRUE(engine_.SetOptions(options));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002979 voe_.GetEcStatus(ec_enabled, ec_mode);
2980 voe_.GetNsStatus(ns_enabled, ns_mode);
2981 EXPECT_TRUE(ec_enabled);
2982 EXPECT_EQ(webrtc::kEcConference, ec_mode);
2983 EXPECT_FALSE(ns_enabled);
2984 EXPECT_EQ(webrtc::kNsHighSuppression, ns_mode);
2985}
2986
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00002987TEST_F(WebRtcVoiceEngineTestFake, DefaultOptions) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002988 EXPECT_TRUE(SetupEngine());
2989
2990 bool ec_enabled;
2991 webrtc::EcModes ec_mode;
2992 bool ec_metrics_enabled;
2993 bool agc_enabled;
2994 webrtc::AgcModes agc_mode;
2995 bool ns_enabled;
2996 webrtc::NsModes ns_mode;
2997 bool highpass_filter_enabled;
2998 bool stereo_swapping_enabled;
2999 bool typing_detection_enabled;
3000
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003001 voe_.GetEcStatus(ec_enabled, ec_mode);
3002 voe_.GetEcMetricsStatus(ec_metrics_enabled);
3003 voe_.GetAgcStatus(agc_enabled, agc_mode);
3004 voe_.GetNsStatus(ns_enabled, ns_mode);
3005 highpass_filter_enabled = voe_.IsHighPassFilterEnabled();
3006 stereo_swapping_enabled = voe_.IsStereoChannelSwappingEnabled();
3007 voe_.GetTypingDetectionStatus(typing_detection_enabled);
3008 EXPECT_TRUE(ec_enabled);
3009 EXPECT_TRUE(agc_enabled);
3010 EXPECT_TRUE(ns_enabled);
3011 EXPECT_TRUE(highpass_filter_enabled);
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00003012 EXPECT_TRUE(typing_detection_enabled);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003013 EXPECT_FALSE(stereo_swapping_enabled);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003014}
3015
3016TEST_F(WebRtcVoiceEngineTestFake, InitDoesNotOverwriteDefaultAgcConfig) {
3017 webrtc::AgcConfig set_config = {0};
3018 set_config.targetLeveldBOv = 3;
3019 set_config.digitalCompressionGaindB = 9;
3020 set_config.limiterEnable = true;
3021 EXPECT_EQ(0, voe_.SetAgcConfig(set_config));
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003022 EXPECT_TRUE(engine_.Init(rtc::Thread::Current()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003023
3024 webrtc::AgcConfig config = {0};
3025 EXPECT_EQ(0, voe_.GetAgcConfig(config));
3026 EXPECT_EQ(set_config.targetLeveldBOv, config.targetLeveldBOv);
3027 EXPECT_EQ(set_config.digitalCompressionGaindB,
3028 config.digitalCompressionGaindB);
3029 EXPECT_EQ(set_config.limiterEnable, config.limiterEnable);
3030}
3031
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003032TEST_F(WebRtcVoiceEngineTestFake, SetOptionOverridesViaChannels) {
3033 EXPECT_TRUE(SetupEngine());
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003034 rtc::scoped_ptr<cricket::VoiceMediaChannel> channel1(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003035 engine_.CreateChannel());
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003036 rtc::scoped_ptr<cricket::VoiceMediaChannel> channel2(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003037 engine_.CreateChannel());
3038
3039 // Have to add a stream to make SetSend work.
3040 cricket::StreamParams stream1;
3041 stream1.ssrcs.push_back(1);
3042 channel1->AddSendStream(stream1);
3043 cricket::StreamParams stream2;
3044 stream2.ssrcs.push_back(2);
3045 channel2->AddSendStream(stream2);
3046
3047 // AEC and AGC and NS
3048 cricket::AudioOptions options_all;
3049 options_all.echo_cancellation.Set(true);
3050 options_all.auto_gain_control.Set(true);
3051 options_all.noise_suppression.Set(true);
3052
3053 ASSERT_TRUE(channel1->SetOptions(options_all));
3054 cricket::AudioOptions expected_options = options_all;
3055 cricket::AudioOptions actual_options;
3056 ASSERT_TRUE(channel1->GetOptions(&actual_options));
3057 EXPECT_EQ(expected_options, actual_options);
3058 ASSERT_TRUE(channel2->SetOptions(options_all));
3059 ASSERT_TRUE(channel2->GetOptions(&actual_options));
3060 EXPECT_EQ(expected_options, actual_options);
3061
3062 // unset NS
3063 cricket::AudioOptions options_no_ns;
3064 options_no_ns.noise_suppression.Set(false);
3065 ASSERT_TRUE(channel1->SetOptions(options_no_ns));
3066
3067 expected_options.echo_cancellation.Set(true);
3068 expected_options.auto_gain_control.Set(true);
3069 expected_options.noise_suppression.Set(false);
3070 ASSERT_TRUE(channel1->GetOptions(&actual_options));
3071 EXPECT_EQ(expected_options, actual_options);
3072
3073 // unset AGC
3074 cricket::AudioOptions options_no_agc;
3075 options_no_agc.auto_gain_control.Set(false);
3076 ASSERT_TRUE(channel2->SetOptions(options_no_agc));
3077
3078 expected_options.echo_cancellation.Set(true);
3079 expected_options.auto_gain_control.Set(false);
3080 expected_options.noise_suppression.Set(true);
3081 ASSERT_TRUE(channel2->GetOptions(&actual_options));
3082 EXPECT_EQ(expected_options, actual_options);
3083
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00003084 ASSERT_TRUE(engine_.SetOptions(options_all));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003085 bool ec_enabled;
3086 webrtc::EcModes ec_mode;
3087 bool agc_enabled;
3088 webrtc::AgcModes agc_mode;
3089 bool ns_enabled;
3090 webrtc::NsModes ns_mode;
3091 voe_.GetEcStatus(ec_enabled, ec_mode);
3092 voe_.GetAgcStatus(agc_enabled, agc_mode);
3093 voe_.GetNsStatus(ns_enabled, ns_mode);
3094 EXPECT_TRUE(ec_enabled);
3095 EXPECT_TRUE(agc_enabled);
3096 EXPECT_TRUE(ns_enabled);
3097
3098 channel1->SetSend(cricket::SEND_MICROPHONE);
3099 voe_.GetEcStatus(ec_enabled, ec_mode);
3100 voe_.GetAgcStatus(agc_enabled, agc_mode);
3101 voe_.GetNsStatus(ns_enabled, ns_mode);
3102 EXPECT_TRUE(ec_enabled);
3103 EXPECT_TRUE(agc_enabled);
3104 EXPECT_FALSE(ns_enabled);
3105
3106 channel1->SetSend(cricket::SEND_NOTHING);
3107 voe_.GetEcStatus(ec_enabled, ec_mode);
3108 voe_.GetAgcStatus(agc_enabled, agc_mode);
3109 voe_.GetNsStatus(ns_enabled, ns_mode);
3110 EXPECT_TRUE(ec_enabled);
3111 EXPECT_TRUE(agc_enabled);
3112 EXPECT_TRUE(ns_enabled);
3113
3114 channel2->SetSend(cricket::SEND_MICROPHONE);
3115 voe_.GetEcStatus(ec_enabled, ec_mode);
3116 voe_.GetAgcStatus(agc_enabled, agc_mode);
3117 voe_.GetNsStatus(ns_enabled, ns_mode);
3118 EXPECT_TRUE(ec_enabled);
3119 EXPECT_FALSE(agc_enabled);
3120 EXPECT_TRUE(ns_enabled);
3121
3122 channel2->SetSend(cricket::SEND_NOTHING);
3123 voe_.GetEcStatus(ec_enabled, ec_mode);
3124 voe_.GetAgcStatus(agc_enabled, agc_mode);
3125 voe_.GetNsStatus(ns_enabled, ns_mode);
3126 EXPECT_TRUE(ec_enabled);
3127 EXPECT_TRUE(agc_enabled);
3128 EXPECT_TRUE(ns_enabled);
3129
3130 // Make sure settings take effect while we are sending.
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00003131 ASSERT_TRUE(engine_.SetOptions(options_all));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003132 cricket::AudioOptions options_no_agc_nor_ns;
3133 options_no_agc_nor_ns.auto_gain_control.Set(false);
3134 options_no_agc_nor_ns.noise_suppression.Set(false);
3135 channel2->SetSend(cricket::SEND_MICROPHONE);
3136 channel2->SetOptions(options_no_agc_nor_ns);
3137
3138 expected_options.echo_cancellation.Set(true);
3139 expected_options.auto_gain_control.Set(false);
3140 expected_options.noise_suppression.Set(false);
3141 ASSERT_TRUE(channel2->GetOptions(&actual_options));
3142 EXPECT_EQ(expected_options, actual_options);
3143 voe_.GetEcStatus(ec_enabled, ec_mode);
3144 voe_.GetAgcStatus(agc_enabled, agc_mode);
3145 voe_.GetNsStatus(ns_enabled, ns_mode);
3146 EXPECT_TRUE(ec_enabled);
3147 EXPECT_FALSE(agc_enabled);
3148 EXPECT_FALSE(ns_enabled);
3149}
3150
wu@webrtc.orgde305012013-10-31 15:40:38 +00003151// This test verifies DSCP settings are properly applied on voice media channel.
3152TEST_F(WebRtcVoiceEngineTestFake, TestSetDscpOptions) {
3153 EXPECT_TRUE(SetupEngine());
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003154 rtc::scoped_ptr<cricket::VoiceMediaChannel> channel(
wu@webrtc.orgde305012013-10-31 15:40:38 +00003155 engine_.CreateChannel());
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003156 rtc::scoped_ptr<cricket::FakeNetworkInterface> network_interface(
wu@webrtc.orgde305012013-10-31 15:40:38 +00003157 new cricket::FakeNetworkInterface);
3158 channel->SetInterface(network_interface.get());
3159 cricket::AudioOptions options;
3160 options.dscp.Set(true);
3161 EXPECT_TRUE(channel->SetOptions(options));
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003162 EXPECT_EQ(rtc::DSCP_EF, network_interface->dscp());
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +00003163 // Verify previous value is not modified if dscp option is not set.
3164 cricket::AudioOptions options1;
3165 EXPECT_TRUE(channel->SetOptions(options1));
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003166 EXPECT_EQ(rtc::DSCP_EF, network_interface->dscp());
wu@webrtc.orgde305012013-10-31 15:40:38 +00003167 options.dscp.Set(false);
3168 EXPECT_TRUE(channel->SetOptions(options));
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003169 EXPECT_EQ(rtc::DSCP_DEFAULT, network_interface->dscp());
wu@webrtc.orgde305012013-10-31 15:40:38 +00003170}
3171
wu@webrtc.org1d1ffc92013-10-16 18:12:02 +00003172TEST(WebRtcVoiceEngineTest, TestDefaultOptionsBeforeInit) {
3173 cricket::WebRtcVoiceEngine engine;
3174 cricket::AudioOptions options = engine.GetOptions();
3175 // The default options should have at least a few things set. We purposefully
3176 // don't check the option values here, though.
3177 EXPECT_TRUE(options.echo_cancellation.IsSet());
3178 EXPECT_TRUE(options.auto_gain_control.IsSet());
3179 EXPECT_TRUE(options.noise_suppression.IsSet());
3180}
3181
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003182// Test that GetReceiveChannelNum returns the default channel for the first
3183// recv stream in 1-1 calls.
3184TEST_F(WebRtcVoiceEngineTestFake, TestGetReceiveChannelNumIn1To1Calls) {
3185 EXPECT_TRUE(SetupEngine());
3186 cricket::WebRtcVoiceMediaChannel* media_channel =
3187 static_cast<cricket::WebRtcVoiceMediaChannel*>(channel_);
3188 // Test that GetChannelNum returns the default channel if the SSRC is unknown.
3189 EXPECT_EQ(media_channel->voe_channel(),
3190 media_channel->GetReceiveChannelNum(0));
3191 cricket::StreamParams stream;
3192 stream.ssrcs.push_back(kSsrc2);
3193 EXPECT_TRUE(channel_->AddRecvStream(stream));
3194 EXPECT_EQ(media_channel->voe_channel(),
3195 media_channel->GetReceiveChannelNum(kSsrc2));
3196}
3197
3198// Test that GetReceiveChannelNum doesn't return the default channel for the
3199// first recv stream in conference calls.
3200TEST_F(WebRtcVoiceEngineTestFake, TestGetChannelNumInConferenceCalls) {
3201 EXPECT_TRUE(SetupEngine());
3202 EXPECT_TRUE(channel_->SetOptions(options_conference_));
3203 cricket::StreamParams stream;
3204 stream.ssrcs.push_back(kSsrc2);
3205 EXPECT_TRUE(channel_->AddRecvStream(stream));
3206 cricket::WebRtcVoiceMediaChannel* media_channel =
3207 static_cast<cricket::WebRtcVoiceMediaChannel*>(channel_);
3208 EXPECT_LT(media_channel->voe_channel(),
3209 media_channel->GetReceiveChannelNum(kSsrc2));
3210}
3211
3212TEST_F(WebRtcVoiceEngineTestFake, SetOutputScaling) {
3213 EXPECT_TRUE(SetupEngine());
3214 double left, right;
3215 EXPECT_TRUE(channel_->SetOutputScaling(0, 1, 2));
3216 EXPECT_TRUE(channel_->GetOutputScaling(0, &left, &right));
3217 EXPECT_DOUBLE_EQ(1, left);
3218 EXPECT_DOUBLE_EQ(2, right);
3219
3220 EXPECT_FALSE(channel_->SetOutputScaling(kSsrc2, 1, 2));
3221 cricket::StreamParams stream;
3222 stream.ssrcs.push_back(kSsrc2);
3223 EXPECT_TRUE(channel_->AddRecvStream(stream));
3224
3225 EXPECT_TRUE(channel_->SetOutputScaling(kSsrc2, 2, 1));
3226 EXPECT_TRUE(channel_->GetOutputScaling(kSsrc2, &left, &right));
3227 EXPECT_DOUBLE_EQ(2, left);
3228 EXPECT_DOUBLE_EQ(1, right);
3229}
3230
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003231// Tests for the actual WebRtc VoE library.
3232
3233// Tests that the library initializes and shuts down properly.
3234TEST(WebRtcVoiceEngineTest, StartupShutdown) {
3235 cricket::WebRtcVoiceEngine engine;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003236 EXPECT_TRUE(engine.Init(rtc::Thread::Current()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003237 cricket::VoiceMediaChannel* channel = engine.CreateChannel();
3238 EXPECT_TRUE(channel != NULL);
3239 delete channel;
3240 engine.Terminate();
3241
3242 // Reinit to catch regression where VoiceEngineObserver reference is lost
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003243 EXPECT_TRUE(engine.Init(rtc::Thread::Current()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003244 engine.Terminate();
3245}
3246
3247// Tests that the logging from the library is cleartext.
3248TEST(WebRtcVoiceEngineTest, DISABLED_HasUnencryptedLogging) {
3249 cricket::WebRtcVoiceEngine engine;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003250 rtc::scoped_ptr<rtc::MemoryStream> stream(
3251 new rtc::MemoryStream);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003252 size_t size = 0;
3253 bool cleartext = true;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003254 rtc::LogMessage::AddLogToStream(stream.get(), rtc::LS_VERBOSE);
3255 engine.SetLogging(rtc::LS_VERBOSE, "");
3256 EXPECT_TRUE(engine.Init(rtc::Thread::Current()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003257 EXPECT_TRUE(stream->GetSize(&size));
3258 EXPECT_GT(size, 0U);
3259 engine.Terminate();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003260 rtc::LogMessage::RemoveLogToStream(stream.get());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003261 const char* buf = stream->GetBuffer();
3262 for (size_t i = 0; i < size && cleartext; ++i) {
3263 int ch = static_cast<int>(buf[i]);
3264 ASSERT_GE(ch, 0) << "Out of bounds character in WebRtc VoE log: "
3265 << std::hex << ch;
3266 cleartext = (isprint(ch) || isspace(ch));
3267 }
3268 EXPECT_TRUE(cleartext);
3269}
3270
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003271// Tests that the library is configured with the codecs we want.
3272TEST(WebRtcVoiceEngineTest, HasCorrectCodecs) {
3273 cricket::WebRtcVoiceEngine engine;
3274 // Check codecs by name.
3275 EXPECT_TRUE(engine.FindCodec(
3276 cricket::AudioCodec(96, "OPUS", 48000, 0, 2, 0)));
3277 EXPECT_TRUE(engine.FindCodec(
3278 cricket::AudioCodec(96, "ISAC", 16000, 0, 1, 0)));
3279 EXPECT_TRUE(engine.FindCodec(
3280 cricket::AudioCodec(96, "ISAC", 32000, 0, 1, 0)));
3281 // Check that name matching is case-insensitive.
3282 EXPECT_TRUE(engine.FindCodec(
3283 cricket::AudioCodec(96, "ILBC", 8000, 0, 1, 0)));
3284 EXPECT_TRUE(engine.FindCodec(
3285 cricket::AudioCodec(96, "iLBC", 8000, 0, 1, 0)));
3286 EXPECT_TRUE(engine.FindCodec(
3287 cricket::AudioCodec(96, "PCMU", 8000, 0, 1, 0)));
3288 EXPECT_TRUE(engine.FindCodec(
3289 cricket::AudioCodec(96, "PCMA", 8000, 0, 1, 0)));
3290 EXPECT_TRUE(engine.FindCodec(
henrik.lundin@webrtc.orgf85dbce2014-11-07 12:25:00 +00003291 cricket::AudioCodec(96, "G722", 8000, 0, 1, 0)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003292 EXPECT_TRUE(engine.FindCodec(
3293 cricket::AudioCodec(96, "red", 8000, 0, 1, 0)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003294 EXPECT_TRUE(engine.FindCodec(
3295 cricket::AudioCodec(96, "CN", 32000, 0, 1, 0)));
3296 EXPECT_TRUE(engine.FindCodec(
3297 cricket::AudioCodec(96, "CN", 16000, 0, 1, 0)));
3298 EXPECT_TRUE(engine.FindCodec(
3299 cricket::AudioCodec(96, "CN", 8000, 0, 1, 0)));
3300 EXPECT_TRUE(engine.FindCodec(
3301 cricket::AudioCodec(96, "telephone-event", 8000, 0, 1, 0)));
3302 // Check codecs with an id by id.
3303 EXPECT_TRUE(engine.FindCodec(
3304 cricket::AudioCodec(0, "", 8000, 0, 1, 0))); // PCMU
3305 EXPECT_TRUE(engine.FindCodec(
3306 cricket::AudioCodec(8, "", 8000, 0, 1, 0))); // PCMA
3307 EXPECT_TRUE(engine.FindCodec(
henrik.lundin@webrtc.orgf85dbce2014-11-07 12:25:00 +00003308 cricket::AudioCodec(9, "", 8000, 0, 1, 0))); // G722
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003309 EXPECT_TRUE(engine.FindCodec(
3310 cricket::AudioCodec(13, "", 8000, 0, 1, 0))); // CN
3311 // Check sample/bitrate matching.
3312 EXPECT_TRUE(engine.FindCodec(
3313 cricket::AudioCodec(0, "PCMU", 8000, 64000, 1, 0)));
3314 // Check that bad codecs fail.
3315 EXPECT_FALSE(engine.FindCodec(cricket::AudioCodec(99, "ABCD", 0, 0, 1, 0)));
3316 EXPECT_FALSE(engine.FindCodec(cricket::AudioCodec(88, "", 0, 0, 1, 0)));
3317 EXPECT_FALSE(engine.FindCodec(cricket::AudioCodec(0, "", 0, 0, 2, 0)));
3318 EXPECT_FALSE(engine.FindCodec(cricket::AudioCodec(0, "", 5000, 0, 1, 0)));
3319 EXPECT_FALSE(engine.FindCodec(cricket::AudioCodec(0, "", 0, 5000, 1, 0)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003320 // Verify the payload id of common audio codecs, including CN, ISAC, and G722.
3321 for (std::vector<cricket::AudioCodec>::const_iterator it =
3322 engine.codecs().begin(); it != engine.codecs().end(); ++it) {
3323 if (it->name == "CN" && it->clockrate == 16000) {
3324 EXPECT_EQ(105, it->id);
3325 } else if (it->name == "CN" && it->clockrate == 32000) {
3326 EXPECT_EQ(106, it->id);
3327 } else if (it->name == "ISAC" && it->clockrate == 16000) {
3328 EXPECT_EQ(103, it->id);
3329 } else if (it->name == "ISAC" && it->clockrate == 32000) {
3330 EXPECT_EQ(104, it->id);
henrik.lundin@webrtc.orgf85dbce2014-11-07 12:25:00 +00003331 } else if (it->name == "G722" && it->clockrate == 8000) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003332 EXPECT_EQ(9, it->id);
3333 } else if (it->name == "telephone-event") {
3334 EXPECT_EQ(126, it->id);
3335 } else if (it->name == "red") {
3336 EXPECT_EQ(127, it->id);
3337 } else if (it->name == "opus") {
3338 EXPECT_EQ(111, it->id);
wu@webrtc.org9caf2762013-12-11 18:25:07 +00003339 ASSERT_TRUE(it->params.find("minptime") != it->params.end());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003340 EXPECT_EQ("10", it->params.find("minptime")->second);
wu@webrtc.org9caf2762013-12-11 18:25:07 +00003341 ASSERT_TRUE(it->params.find("maxptime") != it->params.end());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003342 EXPECT_EQ("60", it->params.find("maxptime")->second);
minyue@webrtc.org4ef22d12014-11-17 09:26:39 +00003343 ASSERT_TRUE(it->params.find("useinbandfec") != it->params.end());
3344 EXPECT_EQ("1", it->params.find("useinbandfec")->second);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003345 }
3346 }
3347
3348 engine.Terminate();
3349}
3350
3351// Tests that VoE supports at least 32 channels
3352TEST(WebRtcVoiceEngineTest, Has32Channels) {
3353 cricket::WebRtcVoiceEngine engine;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003354 EXPECT_TRUE(engine.Init(rtc::Thread::Current()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003355
3356 cricket::VoiceMediaChannel* channels[32];
3357 int num_channels = 0;
3358
3359 while (num_channels < ARRAY_SIZE(channels)) {
3360 cricket::VoiceMediaChannel* channel = engine.CreateChannel();
3361 if (!channel)
3362 break;
3363
3364 channels[num_channels++] = channel;
3365 }
3366
3367 int expected = ARRAY_SIZE(channels);
3368 EXPECT_EQ(expected, num_channels);
3369
3370 while (num_channels > 0) {
3371 delete channels[--num_channels];
3372 }
3373
3374 engine.Terminate();
3375}
3376
3377// Test that we set our preferred codecs properly.
3378TEST(WebRtcVoiceEngineTest, SetRecvCodecs) {
3379 cricket::WebRtcVoiceEngine engine;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003380 EXPECT_TRUE(engine.Init(rtc::Thread::Current()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003381 cricket::WebRtcVoiceMediaChannel channel(&engine);
3382 EXPECT_TRUE(channel.SetRecvCodecs(engine.codecs()));
3383}
3384
3385#ifdef WIN32
3386// Test our workarounds to WebRtc VoE' munging of the coinit count
3387TEST(WebRtcVoiceEngineTest, CoInitialize) {
3388 cricket::WebRtcVoiceEngine* engine = new cricket::WebRtcVoiceEngine();
3389
3390 // Initial refcount should be 0.
3391 EXPECT_EQ(S_OK, CoInitializeEx(NULL, COINIT_MULTITHREADED));
3392
3393 // Engine should start even with COM already inited.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003394 EXPECT_TRUE(engine->Init(rtc::Thread::Current()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003395 engine->Terminate();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003396 EXPECT_TRUE(engine->Init(rtc::Thread::Current()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003397 engine->Terminate();
3398
3399 // Refcount after terminate should be 1 (in reality 3); test if it is nonzero.
3400 EXPECT_EQ(S_FALSE, CoInitializeEx(NULL, COINIT_MULTITHREADED));
3401 // Decrement refcount to (hopefully) 0.
3402 CoUninitialize();
3403 CoUninitialize();
3404 delete engine;
3405
3406 // Ensure refcount is 0.
3407 EXPECT_EQ(S_OK, CoInitializeEx(NULL, COINIT_MULTITHREADED));
3408 CoUninitialize();
3409}
3410#endif
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +00003411
3412TEST_F(WebRtcVoiceEngineTestFake, ChangeCombinedAudioVideoBweOption) {
3413 // Test that changing the combined_audio_video_bwe option results in the
3414 // expected state changes in VoiceEngine.
3415 cricket::ViEWrapper vie;
3416 const int kVieCh = 667;
3417
3418 EXPECT_TRUE(SetupEngine());
3419 cricket::WebRtcVoiceMediaChannel* media_channel =
3420 static_cast<cricket::WebRtcVoiceMediaChannel*>(channel_);
3421 EXPECT_TRUE(media_channel->SetupSharedBandwidthEstimation(vie.engine(),
3422 kVieCh));
3423 EXPECT_TRUE(media_channel->AddRecvStream(
3424 cricket::StreamParams::CreateLegacy(2)));
3425 int recv_ch = voe_.GetLastChannel();
3426
3427 // Combined BWE should not be set up yet.
3428 EXPECT_EQ(NULL, voe_.GetViENetwork(recv_ch));
3429 EXPECT_EQ(-1, voe_.GetVideoChannel(recv_ch));
3430
3431 // Enable combined BWE option - now it should be set up.
3432 cricket::AudioOptions options;
3433 options.combined_audio_video_bwe.Set(true);
3434 EXPECT_TRUE(media_channel->SetOptions(options));
3435 EXPECT_EQ(vie.network(), voe_.GetViENetwork(recv_ch));
3436 EXPECT_EQ(kVieCh, voe_.GetVideoChannel(recv_ch));
3437
3438 // Disable combined BWE option - should be disabled again.
3439 options.combined_audio_video_bwe.Set(false);
3440 EXPECT_TRUE(media_channel->SetOptions(options));
3441 EXPECT_EQ(NULL, voe_.GetViENetwork(recv_ch));
3442 EXPECT_EQ(-1, voe_.GetVideoChannel(recv_ch));
3443
3444 EXPECT_TRUE(media_channel->SetupSharedBandwidthEstimation(NULL, -1));
3445}
3446
3447TEST_F(WebRtcVoiceEngineTestFake, SetupSharedBandwidthEstimation) {
3448 // Test that calling SetupSharedBandwidthEstimation() on the voice media
3449 // channel results in the expected state changes in VoiceEngine.
3450 cricket::ViEWrapper vie1;
3451 cricket::ViEWrapper vie2;
3452 const int kVieCh1 = 667;
3453 const int kVieCh2 = 70;
3454
3455 EXPECT_TRUE(SetupEngine());
3456 cricket::WebRtcVoiceMediaChannel* media_channel =
3457 static_cast<cricket::WebRtcVoiceMediaChannel*>(channel_);
3458 cricket::AudioOptions options;
3459 options.combined_audio_video_bwe.Set(true);
3460 EXPECT_TRUE(media_channel->SetOptions(options));
3461 EXPECT_TRUE(media_channel->AddRecvStream(
3462 cricket::StreamParams::CreateLegacy(2)));
3463 int recv_ch = voe_.GetLastChannel();
3464
3465 // Combined BWE should not be set up yet.
3466 EXPECT_EQ(NULL, voe_.GetViENetwork(recv_ch));
3467 EXPECT_EQ(-1, voe_.GetVideoChannel(recv_ch));
3468
3469 // Register - should be enabled.
3470 EXPECT_TRUE(media_channel->SetupSharedBandwidthEstimation(vie1.engine(),
3471 kVieCh1));
3472 EXPECT_EQ(vie1.network(), voe_.GetViENetwork(recv_ch));
3473 EXPECT_EQ(kVieCh1, voe_.GetVideoChannel(recv_ch));
3474
3475 // Re-register - should still be enabled.
3476 EXPECT_TRUE(media_channel->SetupSharedBandwidthEstimation(vie2.engine(),
3477 kVieCh2));
3478 EXPECT_EQ(vie2.network(), voe_.GetViENetwork(recv_ch));
3479 EXPECT_EQ(kVieCh2, voe_.GetVideoChannel(recv_ch));
3480
3481 // Unregister - should be disabled again.
3482 EXPECT_TRUE(media_channel->SetupSharedBandwidthEstimation(NULL, -1));
3483 EXPECT_EQ(NULL, voe_.GetViENetwork(recv_ch));
3484 EXPECT_EQ(-1, voe_.GetVideoChannel(recv_ch));
3485}
3486
3487TEST_F(WebRtcVoiceEngineTestFake, ConfigureCombinedBweForNewRecvStreams) {
3488 // Test that adding receive streams after enabling combined bandwidth
3489 // estimation will correctly configure each channel.
3490 cricket::ViEWrapper vie;
3491 const int kVieCh = 667;
3492
3493 EXPECT_TRUE(SetupEngine());
3494 cricket::WebRtcVoiceMediaChannel* media_channel =
3495 static_cast<cricket::WebRtcVoiceMediaChannel*>(channel_);
3496 EXPECT_TRUE(media_channel->SetupSharedBandwidthEstimation(vie.engine(),
3497 kVieCh));
3498 cricket::AudioOptions options;
3499 options.combined_audio_video_bwe.Set(true);
3500 EXPECT_TRUE(media_channel->SetOptions(options));
3501
3502 static const uint32 kSsrcs[] = {1, 2, 3, 4};
3503 int voe_channels[ARRAY_SIZE(kSsrcs)] = {0};
3504 for (unsigned int i = 0; i < ARRAY_SIZE(kSsrcs); ++i) {
3505 EXPECT_TRUE(media_channel->AddRecvStream(
3506 cricket::StreamParams::CreateLegacy(kSsrcs[i])));
3507 int recv_ch = media_channel->GetReceiveChannelNum(kSsrcs[i]);
3508 EXPECT_NE(-1, recv_ch);
3509 voe_channels[i] = recv_ch;
3510 EXPECT_EQ(vie.network(), voe_.GetViENetwork(recv_ch));
3511 EXPECT_EQ(kVieCh, voe_.GetVideoChannel(recv_ch));
3512 }
3513
3514 EXPECT_TRUE(media_channel->SetupSharedBandwidthEstimation(NULL, -1));
3515
3516 for (unsigned int i = 0; i < ARRAY_SIZE(voe_channels); ++i) {
3517 EXPECT_EQ(NULL, voe_.GetViENetwork(voe_channels[i]));
3518 EXPECT_EQ(-1, voe_.GetVideoChannel(voe_channels[i]));
3519 }
3520}