blob: 5faec6c06ab0b9d8796c05fcb81c518a927ecd16 [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) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000171 rtc::Buffer packet(data, len);
172 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@webrtc.orgf9b5c1b2015-02-17 12:36:41 +00001405// Test that we can switch back and forth between Opus and ISAC with CN.
1406TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecsIsacOpusSwitching) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001407 EXPECT_TRUE(SetupEngine());
1408 int channel_num = voe_.GetLastChannel();
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +00001409 std::vector<cricket::AudioCodec> opus_codecs;
1410 opus_codecs.push_back(kOpusCodec);
1411 EXPECT_TRUE(channel_->SetSendCodecs(opus_codecs));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001412 webrtc::CodecInst gcodec;
1413 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +00001414 EXPECT_EQ(111, gcodec.pltype);
1415 EXPECT_STREQ("opus", gcodec.plname);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001416
1417 std::vector<cricket::AudioCodec> isac_codecs;
1418 isac_codecs.push_back(kIsacCodec);
1419 isac_codecs.push_back(kCn16000Codec);
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +00001420 isac_codecs.push_back(kOpusCodec);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001421 EXPECT_TRUE(channel_->SetSendCodecs(isac_codecs));
1422 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1423 EXPECT_EQ(103, gcodec.pltype);
1424 EXPECT_STREQ("ISAC", gcodec.plname);
1425
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +00001426 EXPECT_TRUE(channel_->SetSendCodecs(opus_codecs));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001427 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +00001428 EXPECT_EQ(111, gcodec.pltype);
1429 EXPECT_STREQ("opus", gcodec.plname);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001430}
1431
1432// Test that we handle various ways of specifying bitrate.
1433TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecsBitrate) {
1434 EXPECT_TRUE(SetupEngine());
1435 int channel_num = voe_.GetLastChannel();
1436 std::vector<cricket::AudioCodec> codecs;
1437 codecs.push_back(kIsacCodec); // bitrate == 32000
1438 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1439 webrtc::CodecInst gcodec;
1440 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1441 EXPECT_EQ(103, gcodec.pltype);
1442 EXPECT_STREQ("ISAC", gcodec.plname);
1443 EXPECT_EQ(32000, gcodec.rate);
1444
1445 codecs[0].bitrate = 0; // bitrate == default
1446 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1447 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1448 EXPECT_EQ(103, gcodec.pltype);
1449 EXPECT_STREQ("ISAC", gcodec.plname);
1450 EXPECT_EQ(-1, gcodec.rate);
1451
1452 codecs[0].bitrate = 28000; // bitrate == 28000
1453 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1454 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1455 EXPECT_EQ(103, gcodec.pltype);
1456 EXPECT_STREQ("ISAC", gcodec.plname);
1457 EXPECT_EQ(28000, gcodec.rate);
1458
1459 codecs[0] = kPcmuCodec; // bitrate == 64000
1460 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1461 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1462 EXPECT_EQ(0, gcodec.pltype);
1463 EXPECT_STREQ("PCMU", gcodec.plname);
1464 EXPECT_EQ(64000, gcodec.rate);
1465
1466 codecs[0].bitrate = 0; // bitrate == default
1467 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1468 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1469 EXPECT_EQ(0, gcodec.pltype);
1470 EXPECT_STREQ("PCMU", gcodec.plname);
1471 EXPECT_EQ(64000, gcodec.rate);
1472
1473 codecs[0] = kOpusCodec;
1474 codecs[0].bitrate = 0; // bitrate == default
1475 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1476 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1477 EXPECT_EQ(111, gcodec.pltype);
1478 EXPECT_STREQ("opus", gcodec.plname);
1479 EXPECT_EQ(32000, gcodec.rate);
1480}
1481
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00001482// Test that we fail if no codecs are specified.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001483TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecsNoCodecs) {
1484 EXPECT_TRUE(SetupEngine());
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00001485 std::vector<cricket::AudioCodec> codecs;
1486 EXPECT_FALSE(channel_->SetSendCodecs(codecs));
1487}
1488
1489// Test that we can set send codecs even with telephone-event codec as the first
1490// one on the list.
1491TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecsDTMFOnTop) {
1492 EXPECT_TRUE(SetupEngine());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001493 int channel_num = voe_.GetLastChannel();
1494 std::vector<cricket::AudioCodec> codecs;
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00001495 codecs.push_back(kTelephoneEventCodec);
1496 codecs.push_back(kIsacCodec);
1497 codecs.push_back(kPcmuCodec);
1498 codecs[0].id = 98; // DTMF
1499 codecs[1].id = 96;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001500 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1501 webrtc::CodecInst gcodec;
1502 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00001503 EXPECT_EQ(96, gcodec.pltype);
1504 EXPECT_STREQ("ISAC", gcodec.plname);
1505 EXPECT_EQ(98, voe_.GetSendTelephoneEventPayloadType(channel_num));
1506}
1507
1508// Test that we can set send codecs even with CN codec as the first
1509// one on the list.
1510TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecsCNOnTop) {
1511 EXPECT_TRUE(SetupEngine());
1512 int channel_num = voe_.GetLastChannel();
1513 std::vector<cricket::AudioCodec> codecs;
1514 codecs.push_back(kCn16000Codec);
1515 codecs.push_back(kIsacCodec);
1516 codecs.push_back(kPcmuCodec);
1517 codecs[0].id = 98; // wideband CN
1518 codecs[1].id = 96;
1519 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1520 webrtc::CodecInst gcodec;
1521 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1522 EXPECT_EQ(96, gcodec.pltype);
1523 EXPECT_STREQ("ISAC", gcodec.plname);
1524 EXPECT_EQ(98, voe_.GetSendCNPayloadType(channel_num, true));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001525}
1526
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00001527// Test that we set VAD and DTMF types correctly as caller.
1528TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecsCNandDTMFAsCaller) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001529 EXPECT_TRUE(SetupEngine());
1530 int channel_num = voe_.GetLastChannel();
1531 std::vector<cricket::AudioCodec> codecs;
1532 codecs.push_back(kIsacCodec);
1533 codecs.push_back(kPcmuCodec);
1534 // TODO(juberti): cn 32000
1535 codecs.push_back(kCn16000Codec);
1536 codecs.push_back(kCn8000Codec);
1537 codecs.push_back(kTelephoneEventCodec);
1538 codecs.push_back(kRedCodec);
1539 codecs[0].id = 96;
1540 codecs[2].id = 97; // wideband CN
1541 codecs[4].id = 98; // DTMF
1542 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1543 webrtc::CodecInst gcodec;
1544 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1545 EXPECT_EQ(96, gcodec.pltype);
1546 EXPECT_STREQ("ISAC", gcodec.plname);
1547 EXPECT_TRUE(voe_.GetVAD(channel_num));
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +00001548 EXPECT_FALSE(voe_.GetRED(channel_num));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001549 EXPECT_EQ(13, voe_.GetSendCNPayloadType(channel_num, false));
1550 EXPECT_EQ(97, voe_.GetSendCNPayloadType(channel_num, true));
1551 EXPECT_EQ(98, voe_.GetSendTelephoneEventPayloadType(channel_num));
1552}
1553
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00001554// Test that we set VAD and DTMF types correctly as callee.
1555TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecsCNandDTMFAsCallee) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001556 EXPECT_TRUE(engine_.Init(rtc::Thread::Current()));
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00001557 channel_ = engine_.CreateChannel();
1558 EXPECT_TRUE(channel_ != NULL);
1559
1560 int channel_num = voe_.GetLastChannel();
1561 std::vector<cricket::AudioCodec> codecs;
1562 codecs.push_back(kIsacCodec);
1563 codecs.push_back(kPcmuCodec);
1564 // TODO(juberti): cn 32000
1565 codecs.push_back(kCn16000Codec);
1566 codecs.push_back(kCn8000Codec);
1567 codecs.push_back(kTelephoneEventCodec);
1568 codecs.push_back(kRedCodec);
1569 codecs[0].id = 96;
1570 codecs[2].id = 97; // wideband CN
1571 codecs[4].id = 98; // DTMF
1572 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1573 EXPECT_TRUE(channel_->AddSendStream(
1574 cricket::StreamParams::CreateLegacy(kSsrc1)));
1575
1576 webrtc::CodecInst gcodec;
1577 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1578 EXPECT_EQ(96, gcodec.pltype);
1579 EXPECT_STREQ("ISAC", gcodec.plname);
1580 EXPECT_TRUE(voe_.GetVAD(channel_num));
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +00001581 EXPECT_FALSE(voe_.GetRED(channel_num));
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00001582 EXPECT_EQ(13, voe_.GetSendCNPayloadType(channel_num, false));
1583 EXPECT_EQ(97, voe_.GetSendCNPayloadType(channel_num, true));
1584 EXPECT_EQ(98, voe_.GetSendTelephoneEventPayloadType(channel_num));
1585}
1586
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001587// Test that we only apply VAD if we have a CN codec that matches the
1588// send codec clockrate.
1589TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecsCNNoMatch) {
1590 EXPECT_TRUE(SetupEngine());
1591 int channel_num = voe_.GetLastChannel();
1592 std::vector<cricket::AudioCodec> codecs;
1593 // Set ISAC(16K) and CN(16K). VAD should be activated.
1594 codecs.push_back(kIsacCodec);
1595 codecs.push_back(kCn16000Codec);
1596 codecs[1].id = 97;
1597 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1598 webrtc::CodecInst gcodec;
1599 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1600 EXPECT_STREQ("ISAC", gcodec.plname);
1601 EXPECT_TRUE(voe_.GetVAD(channel_num));
1602 EXPECT_EQ(97, voe_.GetSendCNPayloadType(channel_num, true));
1603 // Set PCMU(8K) and CN(16K). VAD should not be activated.
1604 codecs[0] = kPcmuCodec;
1605 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1606 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1607 EXPECT_STREQ("PCMU", gcodec.plname);
1608 EXPECT_FALSE(voe_.GetVAD(channel_num));
1609 // Set PCMU(8K) and CN(8K). VAD should be activated.
1610 codecs[1] = kCn8000Codec;
1611 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1612 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1613 EXPECT_STREQ("PCMU", gcodec.plname);
1614 EXPECT_TRUE(voe_.GetVAD(channel_num));
1615 EXPECT_EQ(13, voe_.GetSendCNPayloadType(channel_num, false));
1616 // Set ISAC(16K) and CN(8K). VAD should not be activated.
1617 codecs[0] = kIsacCodec;
1618 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1619 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1620 EXPECT_STREQ("ISAC", gcodec.plname);
1621 EXPECT_FALSE(voe_.GetVAD(channel_num));
1622}
1623
1624// Test that we perform case-insensitive matching of codec names.
1625TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecsCaseInsensitive) {
1626 EXPECT_TRUE(SetupEngine());
1627 int channel_num = voe_.GetLastChannel();
1628 std::vector<cricket::AudioCodec> codecs;
1629 codecs.push_back(kIsacCodec);
1630 codecs.push_back(kPcmuCodec);
1631 codecs.push_back(kCn16000Codec);
1632 codecs.push_back(kCn8000Codec);
1633 codecs.push_back(kTelephoneEventCodec);
1634 codecs.push_back(kRedCodec);
1635 codecs[0].name = "iSaC";
1636 codecs[0].id = 96;
1637 codecs[2].id = 97; // wideband CN
1638 codecs[4].id = 98; // DTMF
1639 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1640 webrtc::CodecInst gcodec;
1641 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1642 EXPECT_EQ(96, gcodec.pltype);
1643 EXPECT_STREQ("ISAC", gcodec.plname);
1644 EXPECT_TRUE(voe_.GetVAD(channel_num));
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +00001645 EXPECT_FALSE(voe_.GetRED(channel_num));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001646 EXPECT_EQ(13, voe_.GetSendCNPayloadType(channel_num, false));
1647 EXPECT_EQ(97, voe_.GetSendCNPayloadType(channel_num, true));
1648 EXPECT_EQ(98, voe_.GetSendTelephoneEventPayloadType(channel_num));
1649}
1650
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +00001651// Test that we set up RED correctly as caller.
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00001652TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecsREDAsCaller) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001653 EXPECT_TRUE(SetupEngine());
1654 int channel_num = voe_.GetLastChannel();
1655 std::vector<cricket::AudioCodec> codecs;
1656 codecs.push_back(kRedCodec);
1657 codecs.push_back(kIsacCodec);
1658 codecs.push_back(kPcmuCodec);
1659 codecs[0].id = 127;
1660 codecs[0].params[""] = "96/96";
1661 codecs[1].id = 96;
1662 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1663 webrtc::CodecInst gcodec;
1664 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1665 EXPECT_EQ(96, gcodec.pltype);
1666 EXPECT_STREQ("ISAC", gcodec.plname);
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +00001667 EXPECT_TRUE(voe_.GetRED(channel_num));
1668 EXPECT_EQ(127, voe_.GetSendREDPayloadType(channel_num));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001669}
1670
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +00001671// Test that we set up RED correctly as callee.
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00001672TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecsREDAsCallee) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001673 EXPECT_TRUE(engine_.Init(rtc::Thread::Current()));
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00001674 channel_ = engine_.CreateChannel();
1675 EXPECT_TRUE(channel_ != NULL);
1676
1677 int channel_num = voe_.GetLastChannel();
1678 std::vector<cricket::AudioCodec> codecs;
1679 codecs.push_back(kRedCodec);
1680 codecs.push_back(kIsacCodec);
1681 codecs.push_back(kPcmuCodec);
1682 codecs[0].id = 127;
1683 codecs[0].params[""] = "96/96";
1684 codecs[1].id = 96;
1685 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1686 EXPECT_TRUE(channel_->AddSendStream(
1687 cricket::StreamParams::CreateLegacy(kSsrc1)));
1688 webrtc::CodecInst gcodec;
1689 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1690 EXPECT_EQ(96, gcodec.pltype);
1691 EXPECT_STREQ("ISAC", gcodec.plname);
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +00001692 EXPECT_TRUE(voe_.GetRED(channel_num));
1693 EXPECT_EQ(127, voe_.GetSendREDPayloadType(channel_num));
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00001694}
1695
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +00001696// Test that we set up RED correctly if params are omitted.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001697TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecsREDNoParams) {
1698 EXPECT_TRUE(SetupEngine());
1699 int channel_num = voe_.GetLastChannel();
1700 std::vector<cricket::AudioCodec> codecs;
1701 codecs.push_back(kRedCodec);
1702 codecs.push_back(kIsacCodec);
1703 codecs.push_back(kPcmuCodec);
1704 codecs[0].id = 127;
1705 codecs[1].id = 96;
1706 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1707 webrtc::CodecInst gcodec;
1708 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1709 EXPECT_EQ(96, gcodec.pltype);
1710 EXPECT_STREQ("ISAC", gcodec.plname);
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +00001711 EXPECT_TRUE(voe_.GetRED(channel_num));
1712 EXPECT_EQ(127, voe_.GetSendREDPayloadType(channel_num));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001713}
1714
1715// Test that we ignore RED if the parameters aren't named the way we expect.
1716TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecsBadRED1) {
1717 EXPECT_TRUE(SetupEngine());
1718 int channel_num = voe_.GetLastChannel();
1719 std::vector<cricket::AudioCodec> codecs;
1720 codecs.push_back(kRedCodec);
1721 codecs.push_back(kIsacCodec);
1722 codecs.push_back(kPcmuCodec);
1723 codecs[0].id = 127;
1724 codecs[0].params["ABC"] = "96/96";
1725 codecs[1].id = 96;
1726 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1727 webrtc::CodecInst gcodec;
1728 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1729 EXPECT_EQ(96, gcodec.pltype);
1730 EXPECT_STREQ("ISAC", gcodec.plname);
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +00001731 EXPECT_FALSE(voe_.GetRED(channel_num));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001732}
1733
1734// Test that we ignore RED if it uses different primary/secondary encoding.
1735TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecsBadRED2) {
1736 EXPECT_TRUE(SetupEngine());
1737 int channel_num = voe_.GetLastChannel();
1738 std::vector<cricket::AudioCodec> codecs;
1739 codecs.push_back(kRedCodec);
1740 codecs.push_back(kIsacCodec);
1741 codecs.push_back(kPcmuCodec);
1742 codecs[0].id = 127;
1743 codecs[0].params[""] = "96/0";
1744 codecs[1].id = 96;
1745 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1746 webrtc::CodecInst gcodec;
1747 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1748 EXPECT_EQ(96, gcodec.pltype);
1749 EXPECT_STREQ("ISAC", gcodec.plname);
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +00001750 EXPECT_FALSE(voe_.GetRED(channel_num));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001751}
1752
1753// Test that we ignore RED if it uses more than 2 encodings.
1754TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecsBadRED3) {
1755 EXPECT_TRUE(SetupEngine());
1756 int channel_num = voe_.GetLastChannel();
1757 std::vector<cricket::AudioCodec> codecs;
1758 codecs.push_back(kRedCodec);
1759 codecs.push_back(kIsacCodec);
1760 codecs.push_back(kPcmuCodec);
1761 codecs[0].id = 127;
1762 codecs[0].params[""] = "96/96/96";
1763 codecs[1].id = 96;
1764 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1765 webrtc::CodecInst gcodec;
1766 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1767 EXPECT_EQ(96, gcodec.pltype);
1768 EXPECT_STREQ("ISAC", gcodec.plname);
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +00001769 EXPECT_FALSE(voe_.GetRED(channel_num));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001770}
1771
1772// Test that we ignore RED if it has bogus codec ids.
1773TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecsBadRED4) {
1774 EXPECT_TRUE(SetupEngine());
1775 int channel_num = voe_.GetLastChannel();
1776 std::vector<cricket::AudioCodec> codecs;
1777 codecs.push_back(kRedCodec);
1778 codecs.push_back(kIsacCodec);
1779 codecs.push_back(kPcmuCodec);
1780 codecs[0].id = 127;
1781 codecs[0].params[""] = "ABC/ABC";
1782 codecs[1].id = 96;
1783 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1784 webrtc::CodecInst gcodec;
1785 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1786 EXPECT_EQ(96, gcodec.pltype);
1787 EXPECT_STREQ("ISAC", gcodec.plname);
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +00001788 EXPECT_FALSE(voe_.GetRED(channel_num));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001789}
1790
1791// Test that we ignore RED if it refers to a codec that is not present.
1792TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecsBadRED5) {
1793 EXPECT_TRUE(SetupEngine());
1794 int channel_num = voe_.GetLastChannel();
1795 std::vector<cricket::AudioCodec> codecs;
1796 codecs.push_back(kRedCodec);
1797 codecs.push_back(kIsacCodec);
1798 codecs.push_back(kPcmuCodec);
1799 codecs[0].id = 127;
1800 codecs[0].params[""] = "97/97";
1801 codecs[1].id = 96;
1802 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1803 webrtc::CodecInst gcodec;
1804 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1805 EXPECT_EQ(96, gcodec.pltype);
1806 EXPECT_STREQ("ISAC", gcodec.plname);
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +00001807 EXPECT_FALSE(voe_.GetRED(channel_num));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001808}
1809
buildbot@webrtc.org150835e2014-05-06 15:54:38 +00001810// Test support for audio level header extension.
1811TEST_F(WebRtcVoiceEngineTestFake, SendAudioLevelHeaderExtensions) {
1812 TestSetSendRtpHeaderExtensions(kRtpAudioLevelHeaderExtension);
henrike@webrtc.org79047f92014-03-06 23:46:59 +00001813}
buildbot@webrtc.org150835e2014-05-06 15:54:38 +00001814TEST_F(WebRtcVoiceEngineTestFake, RecvAudioLevelHeaderExtensions) {
1815 TestSetRecvRtpHeaderExtensions(kRtpAudioLevelHeaderExtension);
1816}
henrike@webrtc.org79047f92014-03-06 23:46:59 +00001817
buildbot@webrtc.org150835e2014-05-06 15:54:38 +00001818// Test support for absolute send time header extension.
1819TEST_F(WebRtcVoiceEngineTestFake, SendAbsoluteSendTimeHeaderExtensions) {
1820 TestSetSendRtpHeaderExtensions(kRtpAbsoluteSenderTimeHeaderExtension);
1821}
1822TEST_F(WebRtcVoiceEngineTestFake, RecvAbsoluteSendTimeHeaderExtensions) {
1823 TestSetRecvRtpHeaderExtensions(kRtpAbsoluteSenderTimeHeaderExtension);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001824}
1825
1826// Test that we can create a channel and start sending/playing out on it.
1827TEST_F(WebRtcVoiceEngineTestFake, SendAndPlayout) {
1828 EXPECT_TRUE(SetupEngine());
1829 int channel_num = voe_.GetLastChannel();
1830 std::vector<cricket::AudioCodec> codecs;
1831 codecs.push_back(kPcmuCodec);
1832 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1833 EXPECT_TRUE(channel_->SetSend(cricket::SEND_MICROPHONE));
1834 EXPECT_TRUE(voe_.GetSend(channel_num));
1835 EXPECT_TRUE(channel_->SetPlayout(true));
1836 EXPECT_TRUE(voe_.GetPlayout(channel_num));
1837 EXPECT_TRUE(channel_->SetSend(cricket::SEND_NOTHING));
1838 EXPECT_FALSE(voe_.GetSend(channel_num));
1839 EXPECT_TRUE(channel_->SetPlayout(false));
1840 EXPECT_FALSE(voe_.GetPlayout(channel_num));
1841}
1842
wu@webrtc.org9dba5252013-08-05 20:36:57 +00001843// Test that we can add and remove send streams.
1844TEST_F(WebRtcVoiceEngineTestFake, CreateAndDeleteMultipleSendStreams) {
1845 SetupForMultiSendStream();
1846
1847 static const uint32 kSsrcs4[] = {1, 2, 3, 4};
1848
1849 // Set the global state for sending.
1850 EXPECT_TRUE(channel_->SetSend(cricket::SEND_MICROPHONE));
1851
1852 for (unsigned int i = 0; i < ARRAY_SIZE(kSsrcs4); ++i) {
1853 EXPECT_TRUE(channel_->AddSendStream(
1854 cricket::StreamParams::CreateLegacy(kSsrcs4[i])));
1855
1856 // Verify that we are in a sending state for all the created streams.
1857 int channel_num = voe_.GetChannelFromLocalSsrc(kSsrcs4[i]);
1858 EXPECT_TRUE(voe_.GetSend(channel_num));
1859 }
1860
1861 // Remove the first send channel, which is the default channel. It will only
1862 // recycle the default channel but not delete it.
1863 EXPECT_TRUE(channel_->RemoveSendStream(kSsrcs4[0]));
1864 // Stream should already be Removed from the send stream list.
1865 EXPECT_FALSE(channel_->RemoveSendStream(kSsrcs4[0]));
1866 // But the default still exists.
1867 EXPECT_EQ(0, voe_.GetChannelFromLocalSsrc(kSsrcs4[0]));
1868
1869 // Delete the rest of send channel streams.
1870 for (unsigned int i = 1; i < ARRAY_SIZE(kSsrcs4); ++i) {
1871 EXPECT_TRUE(channel_->RemoveSendStream(kSsrcs4[i]));
1872 // Stream should already be deleted.
1873 EXPECT_FALSE(channel_->RemoveSendStream(kSsrcs4[i]));
1874 EXPECT_EQ(-1, voe_.GetChannelFromLocalSsrc(kSsrcs4[i]));
1875 }
1876}
1877
1878// Test SetSendCodecs correctly configure the codecs in all send streams.
1879TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecsWithMultipleSendStreams) {
1880 SetupForMultiSendStream();
1881
1882 static const uint32 kSsrcs4[] = {1, 2, 3, 4};
1883 // Create send streams.
1884 for (unsigned int i = 0; i < ARRAY_SIZE(kSsrcs4); ++i) {
1885 EXPECT_TRUE(channel_->AddSendStream(
1886 cricket::StreamParams::CreateLegacy(kSsrcs4[i])));
1887 }
1888
1889 std::vector<cricket::AudioCodec> codecs;
1890 // Set ISAC(16K) and CN(16K). VAD should be activated.
1891 codecs.push_back(kIsacCodec);
1892 codecs.push_back(kCn16000Codec);
1893 codecs[1].id = 97;
1894 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1895
1896 // Verify ISAC and VAD are corrected configured on all send channels.
1897 webrtc::CodecInst gcodec;
1898 for (unsigned int i = 0; i < ARRAY_SIZE(kSsrcs4); ++i) {
1899 int channel_num = voe_.GetChannelFromLocalSsrc(kSsrcs4[i]);
1900 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1901 EXPECT_STREQ("ISAC", gcodec.plname);
1902 EXPECT_TRUE(voe_.GetVAD(channel_num));
1903 EXPECT_EQ(97, voe_.GetSendCNPayloadType(channel_num, true));
1904 }
1905
1906 // Change to PCMU(8K) and CN(16K). VAD should not be activated.
1907 codecs[0] = kPcmuCodec;
1908 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1909 for (unsigned int i = 0; i < ARRAY_SIZE(kSsrcs4); ++i) {
1910 int channel_num = voe_.GetChannelFromLocalSsrc(kSsrcs4[i]);
1911 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1912 EXPECT_STREQ("PCMU", gcodec.plname);
1913 EXPECT_FALSE(voe_.GetVAD(channel_num));
1914 }
1915}
1916
1917// Test we can SetSend on all send streams correctly.
1918TEST_F(WebRtcVoiceEngineTestFake, SetSendWithMultipleSendStreams) {
1919 SetupForMultiSendStream();
1920
1921 static const uint32 kSsrcs4[] = {1, 2, 3, 4};
1922 // Create the send channels and they should be a SEND_NOTHING date.
1923 for (unsigned int i = 0; i < ARRAY_SIZE(kSsrcs4); ++i) {
1924 EXPECT_TRUE(channel_->AddSendStream(
1925 cricket::StreamParams::CreateLegacy(kSsrcs4[i])));
1926 int channel_num = voe_.GetLastChannel();
1927 EXPECT_FALSE(voe_.GetSend(channel_num));
1928 }
1929
1930 // Set the global state for starting sending.
1931 EXPECT_TRUE(channel_->SetSend(cricket::SEND_MICROPHONE));
1932 for (unsigned int i = 0; i < ARRAY_SIZE(kSsrcs4); ++i) {
1933 // Verify that we are in a sending state for all the send streams.
1934 int channel_num = voe_.GetChannelFromLocalSsrc(kSsrcs4[i]);
1935 EXPECT_TRUE(voe_.GetSend(channel_num));
1936 }
1937
1938 // Set the global state for stopping sending.
1939 EXPECT_TRUE(channel_->SetSend(cricket::SEND_NOTHING));
1940 for (unsigned int i = 1; i < ARRAY_SIZE(kSsrcs4); ++i) {
1941 // Verify that we are in a stop state for all the send streams.
1942 int channel_num = voe_.GetChannelFromLocalSsrc(kSsrcs4[i]);
1943 EXPECT_FALSE(voe_.GetSend(channel_num));
1944 }
1945}
1946
1947// Test we can set the correct statistics on all send streams.
1948TEST_F(WebRtcVoiceEngineTestFake, GetStatsWithMultipleSendStreams) {
1949 SetupForMultiSendStream();
1950
1951 static const uint32 kSsrcs4[] = {1, 2, 3, 4};
1952 // Create send streams.
1953 for (unsigned int i = 0; i < ARRAY_SIZE(kSsrcs4); ++i) {
1954 EXPECT_TRUE(channel_->AddSendStream(
1955 cricket::StreamParams::CreateLegacy(kSsrcs4[i])));
1956 }
buildbot@webrtc.org7e71b772014-06-13 01:14:01 +00001957 // Create a receive stream to check that none of the send streams end up in
1958 // the receive stream stats.
1959 EXPECT_TRUE(channel_->AddRecvStream(
1960 cricket::StreamParams::CreateLegacy(kSsrc2)));
wu@webrtc.org9dba5252013-08-05 20:36:57 +00001961 // We need send codec to be set to get all stats.
1962 std::vector<cricket::AudioCodec> codecs;
1963 codecs.push_back(kPcmuCodec);
1964 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
buildbot@webrtc.org7e71b772014-06-13 01:14:01 +00001965 EXPECT_TRUE(channel_->SetRecvCodecs(codecs));
wu@webrtc.org9dba5252013-08-05 20:36:57 +00001966
1967 cricket::VoiceMediaInfo info;
1968 EXPECT_EQ(true, channel_->GetStats(&info));
1969 EXPECT_EQ(static_cast<size_t>(ARRAY_SIZE(kSsrcs4)), info.senders.size());
1970
1971 // Verify the statistic information is correct.
1972 for (unsigned int i = 0; i < ARRAY_SIZE(kSsrcs4); ++i) {
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +00001973 EXPECT_EQ(kSsrcs4[i], info.senders[i].ssrc());
wu@webrtc.org9dba5252013-08-05 20:36:57 +00001974 EXPECT_EQ(kPcmuCodec.name, info.senders[i].codec_name);
1975 EXPECT_EQ(cricket::kIntStatValue, info.senders[i].bytes_sent);
1976 EXPECT_EQ(cricket::kIntStatValue, info.senders[i].packets_sent);
1977 EXPECT_EQ(cricket::kIntStatValue, info.senders[i].packets_lost);
1978 EXPECT_EQ(cricket::kFractionLostStatValue, info.senders[i].fraction_lost);
1979 EXPECT_EQ(cricket::kIntStatValue, info.senders[i].ext_seqnum);
1980 EXPECT_EQ(cricket::kIntStatValue, info.senders[i].rtt_ms);
1981 EXPECT_EQ(cricket::kIntStatValue, info.senders[i].jitter_ms);
buildbot@webrtc.org7e71b772014-06-13 01:14:01 +00001982 EXPECT_EQ(kPcmuCodec.name, info.senders[i].codec_name);
wu@webrtc.org9dba5252013-08-05 20:36:57 +00001983 }
1984
buildbot@webrtc.org7e71b772014-06-13 01:14:01 +00001985 EXPECT_EQ(0u, info.receivers.size());
1986 DeliverPacket(kPcmuFrame, sizeof(kPcmuFrame));
1987 EXPECT_EQ(true, channel_->GetStats(&info));
1988
wu@webrtc.org9dba5252013-08-05 20:36:57 +00001989 EXPECT_EQ(1u, info.receivers.size());
buildbot@webrtc.org7e71b772014-06-13 01:14:01 +00001990 EXPECT_EQ(cricket::kIntStatValue, info.receivers[0].bytes_rcvd);
1991 EXPECT_EQ(cricket::kIntStatValue, info.receivers[0].packets_rcvd);
1992 EXPECT_EQ(cricket::kIntStatValue, info.receivers[0].packets_lost);
1993 EXPECT_EQ(cricket::kIntStatValue, info.receivers[0].ext_seqnum);
1994 EXPECT_EQ(kPcmuCodec.name, info.receivers[0].codec_name);
wu@webrtc.org9dba5252013-08-05 20:36:57 +00001995}
1996
wu@webrtc.org9dba5252013-08-05 20:36:57 +00001997// Test that we can add and remove receive streams, and do proper send/playout.
1998// We can receive on multiple streams while sending one stream.
1999TEST_F(WebRtcVoiceEngineTestFake, PlayoutWithMultipleStreams) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002000 EXPECT_TRUE(SetupEngine());
2001 int channel_num1 = voe_.GetLastChannel();
2002
2003 // Start playout on the default channel.
2004 EXPECT_TRUE(channel_->SetOptions(options_conference_));
2005 EXPECT_TRUE(channel_->SetPlayout(true));
2006 EXPECT_TRUE(voe_.GetPlayout(channel_num1));
2007
2008 // Adding another stream should disable playout on the default channel.
2009 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(2)));
2010 int channel_num2 = voe_.GetLastChannel();
2011 std::vector<cricket::AudioCodec> codecs;
2012 codecs.push_back(kPcmuCodec);
2013 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
2014 EXPECT_TRUE(channel_->SetSend(cricket::SEND_MICROPHONE));
2015 EXPECT_TRUE(voe_.GetSend(channel_num1));
2016 EXPECT_FALSE(voe_.GetSend(channel_num2));
2017
2018 // Make sure only the new channel is played out.
2019 EXPECT_FALSE(voe_.GetPlayout(channel_num1));
2020 EXPECT_TRUE(voe_.GetPlayout(channel_num2));
2021
2022 // Adding yet another stream should have stream 2 and 3 enabled for playout.
2023 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(3)));
2024 int channel_num3 = voe_.GetLastChannel();
2025 EXPECT_FALSE(voe_.GetPlayout(channel_num1));
2026 EXPECT_TRUE(voe_.GetPlayout(channel_num2));
2027 EXPECT_TRUE(voe_.GetPlayout(channel_num3));
2028 EXPECT_FALSE(voe_.GetSend(channel_num3));
2029
2030 // Stop sending.
2031 EXPECT_TRUE(channel_->SetSend(cricket::SEND_NOTHING));
2032 EXPECT_FALSE(voe_.GetSend(channel_num1));
2033 EXPECT_FALSE(voe_.GetSend(channel_num2));
2034 EXPECT_FALSE(voe_.GetSend(channel_num3));
2035
2036 // Stop playout.
2037 EXPECT_TRUE(channel_->SetPlayout(false));
2038 EXPECT_FALSE(voe_.GetPlayout(channel_num1));
2039 EXPECT_FALSE(voe_.GetPlayout(channel_num2));
2040 EXPECT_FALSE(voe_.GetPlayout(channel_num3));
2041
2042 // Restart playout and make sure the default channel still is not played out.
2043 EXPECT_TRUE(channel_->SetPlayout(true));
2044 EXPECT_FALSE(voe_.GetPlayout(channel_num1));
2045 EXPECT_TRUE(voe_.GetPlayout(channel_num2));
2046 EXPECT_TRUE(voe_.GetPlayout(channel_num3));
2047
2048 // Now remove the new streams and verify that the default channel is
2049 // played out again.
2050 EXPECT_TRUE(channel_->RemoveRecvStream(3));
2051 EXPECT_TRUE(channel_->RemoveRecvStream(2));
2052
2053 EXPECT_TRUE(voe_.GetPlayout(channel_num1));
2054}
2055
2056// Test that we can set the devices to use.
2057TEST_F(WebRtcVoiceEngineTestFake, SetDevices) {
2058 EXPECT_TRUE(SetupEngine());
2059 int channel_num = voe_.GetLastChannel();
2060 std::vector<cricket::AudioCodec> codecs;
2061 codecs.push_back(kPcmuCodec);
2062 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
2063
2064 cricket::Device default_dev(cricket::kFakeDefaultDeviceName,
2065 cricket::kFakeDefaultDeviceId);
2066 cricket::Device dev(cricket::kFakeDeviceName,
2067 cricket::kFakeDeviceId);
2068
2069 // Test SetDevices() while not sending or playing.
2070 EXPECT_TRUE(engine_.SetDevices(&default_dev, &default_dev));
2071
2072 // Test SetDevices() while sending and playing.
2073 EXPECT_TRUE(engine_.SetLocalMonitor(true));
2074 EXPECT_TRUE(channel_->SetSend(cricket::SEND_MICROPHONE));
2075 EXPECT_TRUE(channel_->SetPlayout(true));
2076 EXPECT_TRUE(voe_.GetRecordingMicrophone());
2077 EXPECT_TRUE(voe_.GetSend(channel_num));
2078 EXPECT_TRUE(voe_.GetPlayout(channel_num));
2079
2080 EXPECT_TRUE(engine_.SetDevices(&dev, &dev));
2081
2082 EXPECT_TRUE(voe_.GetRecordingMicrophone());
2083 EXPECT_TRUE(voe_.GetSend(channel_num));
2084 EXPECT_TRUE(voe_.GetPlayout(channel_num));
2085
2086 // Test that failure to open newly selected devices does not prevent opening
2087 // ones after that.
2088 voe_.set_fail_start_recording_microphone(true);
2089 voe_.set_playout_fail_channel(channel_num);
2090 voe_.set_send_fail_channel(channel_num);
2091
2092 EXPECT_FALSE(engine_.SetDevices(&default_dev, &default_dev));
2093
2094 EXPECT_FALSE(voe_.GetRecordingMicrophone());
2095 EXPECT_FALSE(voe_.GetSend(channel_num));
2096 EXPECT_FALSE(voe_.GetPlayout(channel_num));
2097
2098 voe_.set_fail_start_recording_microphone(false);
2099 voe_.set_playout_fail_channel(-1);
2100 voe_.set_send_fail_channel(-1);
2101
2102 EXPECT_TRUE(engine_.SetDevices(&dev, &dev));
2103
2104 EXPECT_TRUE(voe_.GetRecordingMicrophone());
2105 EXPECT_TRUE(voe_.GetSend(channel_num));
2106 EXPECT_TRUE(voe_.GetPlayout(channel_num));
2107}
2108
2109// Test that we can set the devices to use even if we failed to
2110// open the initial ones.
2111TEST_F(WebRtcVoiceEngineTestFake, SetDevicesWithInitiallyBadDevices) {
2112 EXPECT_TRUE(SetupEngine());
2113 int channel_num = voe_.GetLastChannel();
2114 std::vector<cricket::AudioCodec> codecs;
2115 codecs.push_back(kPcmuCodec);
2116 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
2117
2118 cricket::Device default_dev(cricket::kFakeDefaultDeviceName,
2119 cricket::kFakeDefaultDeviceId);
2120 cricket::Device dev(cricket::kFakeDeviceName,
2121 cricket::kFakeDeviceId);
2122
2123 // Test that failure to open devices selected before starting
2124 // send/play does not prevent opening newly selected ones after that.
2125 voe_.set_fail_start_recording_microphone(true);
2126 voe_.set_playout_fail_channel(channel_num);
2127 voe_.set_send_fail_channel(channel_num);
2128
2129 EXPECT_TRUE(engine_.SetDevices(&default_dev, &default_dev));
2130
2131 EXPECT_FALSE(engine_.SetLocalMonitor(true));
2132 EXPECT_FALSE(channel_->SetSend(cricket::SEND_MICROPHONE));
2133 EXPECT_FALSE(channel_->SetPlayout(true));
2134 EXPECT_FALSE(voe_.GetRecordingMicrophone());
2135 EXPECT_FALSE(voe_.GetSend(channel_num));
2136 EXPECT_FALSE(voe_.GetPlayout(channel_num));
2137
2138 voe_.set_fail_start_recording_microphone(false);
2139 voe_.set_playout_fail_channel(-1);
2140 voe_.set_send_fail_channel(-1);
2141
2142 EXPECT_TRUE(engine_.SetDevices(&dev, &dev));
2143
2144 EXPECT_TRUE(voe_.GetRecordingMicrophone());
2145 EXPECT_TRUE(voe_.GetSend(channel_num));
2146 EXPECT_TRUE(voe_.GetPlayout(channel_num));
2147}
2148
2149// Test that we can create a channel configured for multi-point conferences,
2150// and start sending/playing out on it.
2151TEST_F(WebRtcVoiceEngineTestFake, ConferenceSendAndPlayout) {
2152 EXPECT_TRUE(SetupEngine());
2153 int channel_num = voe_.GetLastChannel();
2154 EXPECT_TRUE(channel_->SetOptions(options_conference_));
2155 std::vector<cricket::AudioCodec> codecs;
2156 codecs.push_back(kPcmuCodec);
2157 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
2158 EXPECT_TRUE(channel_->SetSend(cricket::SEND_MICROPHONE));
2159 EXPECT_TRUE(voe_.GetSend(channel_num));
2160}
2161
2162// Test that we can create a channel configured for Codian bridges,
2163// and start sending/playing out on it.
2164TEST_F(WebRtcVoiceEngineTestFake, CodianSendAndPlayout) {
2165 EXPECT_TRUE(SetupEngine());
2166 int channel_num = voe_.GetLastChannel();
2167 webrtc::AgcConfig agc_config;
2168 EXPECT_EQ(0, voe_.GetAgcConfig(agc_config));
2169 EXPECT_EQ(0, agc_config.targetLeveldBOv);
2170 EXPECT_TRUE(channel_->SetOptions(options_adjust_agc_));
2171 std::vector<cricket::AudioCodec> codecs;
2172 codecs.push_back(kPcmuCodec);
2173 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
2174 EXPECT_TRUE(channel_->SetSend(cricket::SEND_MICROPHONE));
2175 EXPECT_TRUE(voe_.GetSend(channel_num));
2176 EXPECT_EQ(0, voe_.GetAgcConfig(agc_config));
2177 EXPECT_EQ(agc_config.targetLeveldBOv, 10); // level was attenuated
2178 EXPECT_TRUE(channel_->SetPlayout(true));
2179 EXPECT_TRUE(voe_.GetPlayout(channel_num));
2180 EXPECT_TRUE(channel_->SetSend(cricket::SEND_NOTHING));
2181 EXPECT_FALSE(voe_.GetSend(channel_num));
2182 EXPECT_EQ(0, voe_.GetAgcConfig(agc_config));
2183 EXPECT_EQ(0, agc_config.targetLeveldBOv); // level was restored
2184 EXPECT_TRUE(channel_->SetPlayout(false));
2185 EXPECT_FALSE(voe_.GetPlayout(channel_num));
2186}
2187
wu@webrtc.org97077a32013-10-25 21:18:33 +00002188TEST_F(WebRtcVoiceEngineTestFake, TxAgcConfigViaOptions) {
2189 EXPECT_TRUE(SetupEngine());
2190 webrtc::AgcConfig agc_config;
2191 EXPECT_EQ(0, voe_.GetAgcConfig(agc_config));
2192 EXPECT_EQ(0, agc_config.targetLeveldBOv);
2193
2194 cricket::AudioOptions options;
2195 options.tx_agc_target_dbov.Set(3);
2196 options.tx_agc_digital_compression_gain.Set(9);
2197 options.tx_agc_limiter.Set(true);
2198 options.auto_gain_control.Set(true);
2199 EXPECT_TRUE(engine_.SetOptions(options));
2200
2201 EXPECT_EQ(0, voe_.GetAgcConfig(agc_config));
2202 EXPECT_EQ(3, agc_config.targetLeveldBOv);
2203 EXPECT_EQ(9, agc_config.digitalCompressionGaindB);
2204 EXPECT_TRUE(agc_config.limiterEnable);
2205
2206 // Check interaction with adjust_agc_delta. Both should be respected, for
2207 // backwards compatibility.
2208 options.adjust_agc_delta.Set(-10);
2209 EXPECT_TRUE(engine_.SetOptions(options));
2210
2211 EXPECT_EQ(0, voe_.GetAgcConfig(agc_config));
2212 EXPECT_EQ(13, agc_config.targetLeveldBOv);
2213}
2214
2215TEST_F(WebRtcVoiceEngineTestFake, RxAgcConfigViaOptions) {
2216 EXPECT_TRUE(SetupEngine());
2217 int channel_num = voe_.GetLastChannel();
2218 cricket::AudioOptions options;
2219 options.rx_agc_target_dbov.Set(6);
2220 options.rx_agc_digital_compression_gain.Set(0);
2221 options.rx_agc_limiter.Set(true);
2222 options.rx_auto_gain_control.Set(true);
2223 EXPECT_TRUE(channel_->SetOptions(options));
2224
2225 webrtc::AgcConfig agc_config;
2226 EXPECT_EQ(0, engine_.voe()->processing()->GetRxAgcConfig(
2227 channel_num, agc_config));
2228 EXPECT_EQ(6, agc_config.targetLeveldBOv);
2229 EXPECT_EQ(0, agc_config.digitalCompressionGaindB);
2230 EXPECT_TRUE(agc_config.limiterEnable);
2231}
2232
2233TEST_F(WebRtcVoiceEngineTestFake, SampleRatesViaOptions) {
2234 EXPECT_TRUE(SetupEngine());
2235 cricket::AudioOptions options;
2236 options.recording_sample_rate.Set(48000u);
2237 options.playout_sample_rate.Set(44100u);
2238 EXPECT_TRUE(engine_.SetOptions(options));
2239
2240 unsigned int recording_sample_rate, playout_sample_rate;
2241 EXPECT_EQ(0, voe_.RecordingSampleRate(&recording_sample_rate));
2242 EXPECT_EQ(0, voe_.PlayoutSampleRate(&playout_sample_rate));
2243 EXPECT_EQ(48000u, recording_sample_rate);
2244 EXPECT_EQ(44100u, playout_sample_rate);
2245}
2246
2247TEST_F(WebRtcVoiceEngineTestFake, TraceFilterViaTraceOptions) {
2248 EXPECT_TRUE(SetupEngine());
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002249 engine_.SetLogging(rtc::LS_INFO, "");
wu@webrtc.org97077a32013-10-25 21:18:33 +00002250 EXPECT_EQ(
2251 // Info:
2252 webrtc::kTraceStateInfo | webrtc::kTraceInfo |
2253 // Warning:
2254 webrtc::kTraceTerseInfo | webrtc::kTraceWarning |
2255 // Error:
2256 webrtc::kTraceError | webrtc::kTraceCritical,
2257 static_cast<int>(trace_wrapper_->filter_));
2258 // Now set it explicitly
2259 std::string filter =
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002260 "tracefilter " + rtc::ToString(webrtc::kTraceDefault);
2261 engine_.SetLogging(rtc::LS_VERBOSE, filter.c_str());
wu@webrtc.org97077a32013-10-25 21:18:33 +00002262 EXPECT_EQ(static_cast<unsigned int>(webrtc::kTraceDefault),
2263 trace_wrapper_->filter_);
2264}
2265
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002266// Test that we can set the outgoing SSRC properly.
2267// SSRC is set in SetupEngine by calling AddSendStream.
2268TEST_F(WebRtcVoiceEngineTestFake, SetSendSsrc) {
2269 EXPECT_TRUE(SetupEngine());
2270 int channel_num = voe_.GetLastChannel();
2271 unsigned int send_ssrc;
2272 EXPECT_EQ(0, voe_.GetLocalSSRC(channel_num, send_ssrc));
2273 EXPECT_NE(0U, send_ssrc);
2274 EXPECT_EQ(0, voe_.GetLocalSSRC(channel_num, send_ssrc));
2275 EXPECT_EQ(kSsrc1, send_ssrc);
2276}
2277
2278TEST_F(WebRtcVoiceEngineTestFake, GetStats) {
2279 // Setup. We need send codec to be set to get all stats.
2280 EXPECT_TRUE(SetupEngine());
buildbot@webrtc.org7e71b772014-06-13 01:14:01 +00002281 // SetupEngine adds a send stream with kSsrc1, so the receive stream has to
2282 // use a different SSRC.
2283 EXPECT_TRUE(channel_->AddRecvStream(
2284 cricket::StreamParams::CreateLegacy(kSsrc2)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002285 std::vector<cricket::AudioCodec> codecs;
2286 codecs.push_back(kPcmuCodec);
2287 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
buildbot@webrtc.org7e71b772014-06-13 01:14:01 +00002288 EXPECT_TRUE(channel_->SetRecvCodecs(codecs));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002289
2290 cricket::VoiceMediaInfo info;
2291 EXPECT_EQ(true, channel_->GetStats(&info));
2292 EXPECT_EQ(1u, info.senders.size());
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +00002293 EXPECT_EQ(kSsrc1, info.senders[0].ssrc());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002294 EXPECT_EQ(kPcmuCodec.name, info.senders[0].codec_name);
2295 EXPECT_EQ(cricket::kIntStatValue, info.senders[0].bytes_sent);
2296 EXPECT_EQ(cricket::kIntStatValue, info.senders[0].packets_sent);
2297 EXPECT_EQ(cricket::kIntStatValue, info.senders[0].packets_lost);
2298 EXPECT_EQ(cricket::kFractionLostStatValue, info.senders[0].fraction_lost);
2299 EXPECT_EQ(cricket::kIntStatValue, info.senders[0].ext_seqnum);
2300 EXPECT_EQ(cricket::kIntStatValue, info.senders[0].rtt_ms);
2301 EXPECT_EQ(cricket::kIntStatValue, info.senders[0].jitter_ms);
buildbot@webrtc.org7e71b772014-06-13 01:14:01 +00002302 EXPECT_EQ(kPcmuCodec.name, info.senders[0].codec_name);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002303 // TODO(sriniv): Add testing for more fields. These are not populated
2304 // in FakeWebrtcVoiceEngine yet.
2305 // EXPECT_EQ(cricket::kIntStatValue, info.senders[0].audio_level);
2306 // EXPECT_EQ(cricket::kIntStatValue, info.senders[0].echo_delay_median_ms);
2307 // EXPECT_EQ(cricket::kIntStatValue, info.senders[0].echo_delay_std_ms);
2308 // EXPECT_EQ(cricket::kIntStatValue, info.senders[0].echo_return_loss);
2309 // EXPECT_EQ(cricket::kIntStatValue,
2310 // info.senders[0].echo_return_loss_enhancement);
2311
buildbot@webrtc.org7e71b772014-06-13 01:14:01 +00002312 EXPECT_EQ(0u, info.receivers.size());
2313 DeliverPacket(kPcmuFrame, sizeof(kPcmuFrame));
2314 EXPECT_EQ(true, channel_->GetStats(&info));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002315 EXPECT_EQ(1u, info.receivers.size());
buildbot@webrtc.org7e71b772014-06-13 01:14:01 +00002316
2317 EXPECT_EQ(cricket::kIntStatValue, info.receivers[0].bytes_rcvd);
2318 EXPECT_EQ(cricket::kIntStatValue, info.receivers[0].packets_rcvd);
2319 EXPECT_EQ(cricket::kIntStatValue, info.receivers[0].packets_lost);
2320 EXPECT_EQ(cricket::kIntStatValue, info.receivers[0].ext_seqnum);
2321 EXPECT_EQ(kPcmuCodec.name, info.receivers[0].codec_name);
2322 // TODO(sriniv): Add testing for more receiver fields.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002323}
2324
2325// Test that we can set the outgoing SSRC properly with multiple streams.
2326// SSRC is set in SetupEngine by calling AddSendStream.
2327TEST_F(WebRtcVoiceEngineTestFake, SetSendSsrcWithMultipleStreams) {
2328 EXPECT_TRUE(SetupEngine());
2329 EXPECT_TRUE(channel_->SetOptions(options_conference_));
2330 int channel_num1 = voe_.GetLastChannel();
2331 unsigned int send_ssrc;
2332 EXPECT_EQ(0, voe_.GetLocalSSRC(channel_num1, send_ssrc));
2333 EXPECT_EQ(kSsrc1, send_ssrc);
2334
2335 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(2)));
2336 int channel_num2 = voe_.GetLastChannel();
2337 EXPECT_EQ(0, voe_.GetLocalSSRC(channel_num2, send_ssrc));
2338 EXPECT_EQ(kSsrc1, send_ssrc);
2339}
2340
2341// Test that the local SSRC is the same on sending and receiving channels if the
2342// receive channel is created before the send channel.
2343TEST_F(WebRtcVoiceEngineTestFake, SetSendSsrcAfterCreatingReceiveChannel) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002344 EXPECT_TRUE(engine_.Init(rtc::Thread::Current()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002345 channel_ = engine_.CreateChannel();
2346 EXPECT_TRUE(channel_->SetOptions(options_conference_));
2347
2348 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(1)));
2349 int receive_channel_num = voe_.GetLastChannel();
2350 EXPECT_TRUE(channel_->AddSendStream(
2351 cricket::StreamParams::CreateLegacy(1234)));
2352 int send_channel_num = voe_.GetLastChannel();
2353
2354 unsigned int ssrc = 0;
2355 EXPECT_EQ(0, voe_.GetLocalSSRC(send_channel_num, ssrc));
2356 EXPECT_EQ(1234U, ssrc);
2357 ssrc = 0;
2358 EXPECT_EQ(0, voe_.GetLocalSSRC(receive_channel_num, ssrc));
2359 EXPECT_EQ(1234U, ssrc);
2360}
2361
2362// Test that we can properly receive packets.
2363TEST_F(WebRtcVoiceEngineTestFake, Recv) {
2364 EXPECT_TRUE(SetupEngine());
2365 int channel_num = voe_.GetLastChannel();
2366 DeliverPacket(kPcmuFrame, sizeof(kPcmuFrame));
2367 EXPECT_TRUE(voe_.CheckPacket(channel_num, kPcmuFrame,
2368 sizeof(kPcmuFrame)));
2369}
2370
2371// Test that we can properly receive packets on multiple streams.
2372TEST_F(WebRtcVoiceEngineTestFake, RecvWithMultipleStreams) {
2373 EXPECT_TRUE(SetupEngine());
2374 EXPECT_TRUE(channel_->SetOptions(options_conference_));
2375 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(1)));
2376 int channel_num1 = voe_.GetLastChannel();
2377 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(2)));
2378 int channel_num2 = voe_.GetLastChannel();
2379 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(3)));
2380 int channel_num3 = voe_.GetLastChannel();
2381 // Create packets with the right SSRCs.
2382 char packets[4][sizeof(kPcmuFrame)];
2383 for (size_t i = 0; i < ARRAY_SIZE(packets); ++i) {
2384 memcpy(packets[i], kPcmuFrame, sizeof(kPcmuFrame));
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002385 rtc::SetBE32(packets[i] + 8, static_cast<uint32>(i));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002386 }
2387 EXPECT_TRUE(voe_.CheckNoPacket(channel_num1));
2388 EXPECT_TRUE(voe_.CheckNoPacket(channel_num2));
2389 EXPECT_TRUE(voe_.CheckNoPacket(channel_num3));
2390 DeliverPacket(packets[0], sizeof(packets[0]));
2391 EXPECT_TRUE(voe_.CheckNoPacket(channel_num1));
2392 EXPECT_TRUE(voe_.CheckNoPacket(channel_num2));
2393 EXPECT_TRUE(voe_.CheckNoPacket(channel_num3));
2394 DeliverPacket(packets[1], sizeof(packets[1]));
2395 EXPECT_TRUE(voe_.CheckPacket(channel_num1, packets[1],
2396 sizeof(packets[1])));
2397 EXPECT_TRUE(voe_.CheckNoPacket(channel_num2));
2398 EXPECT_TRUE(voe_.CheckNoPacket(channel_num3));
2399 DeliverPacket(packets[2], sizeof(packets[2]));
2400 EXPECT_TRUE(voe_.CheckNoPacket(channel_num1));
2401 EXPECT_TRUE(voe_.CheckPacket(channel_num2, packets[2],
2402 sizeof(packets[2])));
2403 EXPECT_TRUE(voe_.CheckNoPacket(channel_num3));
2404 DeliverPacket(packets[3], sizeof(packets[3]));
2405 EXPECT_TRUE(voe_.CheckNoPacket(channel_num1));
2406 EXPECT_TRUE(voe_.CheckNoPacket(channel_num2));
2407 EXPECT_TRUE(voe_.CheckPacket(channel_num3, packets[3],
2408 sizeof(packets[3])));
2409 EXPECT_TRUE(channel_->RemoveRecvStream(3));
2410 EXPECT_TRUE(channel_->RemoveRecvStream(2));
2411 EXPECT_TRUE(channel_->RemoveRecvStream(1));
2412}
2413
2414// Test that we properly handle failures to add a stream.
2415TEST_F(WebRtcVoiceEngineTestFake, AddStreamFail) {
2416 EXPECT_TRUE(SetupEngine());
2417 voe_.set_fail_create_channel(true);
2418 EXPECT_TRUE(channel_->SetOptions(options_conference_));
2419 EXPECT_FALSE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(2)));
2420
2421 // In 1:1 call, we should not try to create a new channel.
2422 cricket::AudioOptions options_no_conference_;
2423 options_no_conference_.conference_mode.Set(false);
2424 EXPECT_TRUE(channel_->SetOptions(options_no_conference_));
2425 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(2)));
2426}
2427
2428// Test that AddRecvStream doesn't create new channel for 1:1 call.
2429TEST_F(WebRtcVoiceEngineTestFake, AddRecvStream1On1) {
2430 EXPECT_TRUE(SetupEngine());
2431 int channel_num = voe_.GetLastChannel();
2432 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(1)));
2433 EXPECT_EQ(channel_num, voe_.GetLastChannel());
2434}
2435
2436// Test that after adding a recv stream, we do not decode more codecs than
2437// those previously passed into SetRecvCodecs.
2438TEST_F(WebRtcVoiceEngineTestFake, AddRecvStreamUnsupportedCodec) {
2439 EXPECT_TRUE(SetupEngine());
2440 EXPECT_TRUE(channel_->SetOptions(options_conference_));
2441 std::vector<cricket::AudioCodec> codecs;
2442 codecs.push_back(kIsacCodec);
2443 codecs.push_back(kPcmuCodec);
2444 EXPECT_TRUE(channel_->SetRecvCodecs(codecs));
2445 EXPECT_TRUE(channel_->AddRecvStream(
2446 cricket::StreamParams::CreateLegacy(kSsrc1)));
2447 int channel_num2 = voe_.GetLastChannel();
2448 webrtc::CodecInst gcodec;
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +00002449 rtc::strcpyn(gcodec.plname, ARRAY_SIZE(gcodec.plname), "opus");
2450 gcodec.plfreq = 48000;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002451 gcodec.channels = 2;
2452 EXPECT_EQ(-1, voe_.GetRecPayloadType(channel_num2, gcodec));
2453}
2454
2455// Test that we properly clean up any streams that were added, even if
2456// not explicitly removed.
2457TEST_F(WebRtcVoiceEngineTestFake, StreamCleanup) {
2458 EXPECT_TRUE(SetupEngine());
2459 EXPECT_TRUE(channel_->SetOptions(options_conference_));
2460 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(1)));
2461 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(2)));
2462 EXPECT_EQ(3, voe_.GetNumChannels()); // default channel + 2 added
2463 delete channel_;
2464 channel_ = NULL;
2465 EXPECT_EQ(0, voe_.GetNumChannels());
2466}
2467
wu@webrtc.org78187522013-10-07 23:32:02 +00002468TEST_F(WebRtcVoiceEngineTestFake, TestAddRecvStreamFailWithZeroSsrc) {
2469 EXPECT_TRUE(SetupEngine());
2470 EXPECT_FALSE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(0)));
2471}
2472
2473TEST_F(WebRtcVoiceEngineTestFake, TestNoLeakingWhenAddRecvStreamFail) {
2474 EXPECT_TRUE(SetupEngine());
2475 // Stream 1 reuses default channel.
2476 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(1)));
2477 // Manually delete default channel to simulate a failure.
2478 int default_channel = voe_.GetLastChannel();
2479 EXPECT_EQ(0, voe_.DeleteChannel(default_channel));
2480 // Add recv stream 2 should fail because default channel is gone.
2481 EXPECT_FALSE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(2)));
2482 int new_channel = voe_.GetLastChannel();
2483 EXPECT_NE(default_channel, new_channel);
2484 // The last created channel should have already been deleted.
2485 EXPECT_EQ(-1, voe_.DeleteChannel(new_channel));
2486}
2487
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002488// Test the InsertDtmf on default send stream as caller.
2489TEST_F(WebRtcVoiceEngineTestFake, InsertDtmfOnDefaultSendStreamAsCaller) {
2490 TestInsertDtmf(0, true);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002491}
2492
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002493// Test the InsertDtmf on default send stream as callee
2494TEST_F(WebRtcVoiceEngineTestFake, InsertDtmfOnDefaultSendStreamAsCallee) {
2495 TestInsertDtmf(0, false);
2496}
2497
2498// Test the InsertDtmf on specified send stream as caller.
2499TEST_F(WebRtcVoiceEngineTestFake, InsertDtmfOnSendStreamAsCaller) {
2500 TestInsertDtmf(kSsrc1, true);
2501}
2502
2503// Test the InsertDtmf on specified send stream as callee.
2504TEST_F(WebRtcVoiceEngineTestFake, InsertDtmfOnSendStreamAsCallee) {
2505 TestInsertDtmf(kSsrc1, false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002506}
2507
2508// Test that we can play a ringback tone properly in a single-stream call.
2509TEST_F(WebRtcVoiceEngineTestFake, PlayRingback) {
2510 EXPECT_TRUE(SetupEngine());
2511 int channel_num = voe_.GetLastChannel();
2512 EXPECT_EQ(0, voe_.IsPlayingFileLocally(channel_num));
2513 // Check we fail if no ringback tone specified.
2514 EXPECT_FALSE(channel_->PlayRingbackTone(0, true, true));
2515 EXPECT_EQ(0, voe_.IsPlayingFileLocally(channel_num));
2516 // Check we can set and play a ringback tone.
wu@webrtc.org9caf2762013-12-11 18:25:07 +00002517 EXPECT_TRUE(channel_->SetRingbackTone(
2518 kRingbackTone, static_cast<int>(strlen(kRingbackTone))));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002519 EXPECT_TRUE(channel_->PlayRingbackTone(0, true, true));
2520 EXPECT_EQ(1, voe_.IsPlayingFileLocally(channel_num));
2521 // Check we can stop the tone manually.
2522 EXPECT_TRUE(channel_->PlayRingbackTone(0, false, false));
2523 EXPECT_EQ(0, voe_.IsPlayingFileLocally(channel_num));
2524 // Check we stop the tone if a packet arrives.
2525 EXPECT_TRUE(channel_->PlayRingbackTone(0, true, true));
2526 EXPECT_EQ(1, voe_.IsPlayingFileLocally(channel_num));
2527 DeliverPacket(kPcmuFrame, sizeof(kPcmuFrame));
2528 EXPECT_EQ(0, voe_.IsPlayingFileLocally(channel_num));
2529}
2530
2531// Test that we can play a ringback tone properly in a multi-stream call.
2532TEST_F(WebRtcVoiceEngineTestFake, PlayRingbackWithMultipleStreams) {
2533 EXPECT_TRUE(SetupEngine());
2534 EXPECT_TRUE(channel_->SetOptions(options_conference_));
2535 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(1)));
2536 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(2)));
2537 int channel_num = voe_.GetLastChannel();
2538 EXPECT_EQ(0, voe_.IsPlayingFileLocally(channel_num));
2539 // Check we fail if no ringback tone specified.
2540 EXPECT_FALSE(channel_->PlayRingbackTone(2, true, true));
2541 EXPECT_EQ(0, voe_.IsPlayingFileLocally(channel_num));
2542 // Check we can set and play a ringback tone on the correct ssrc.
wu@webrtc.org9caf2762013-12-11 18:25:07 +00002543 EXPECT_TRUE(channel_->SetRingbackTone(
2544 kRingbackTone, static_cast<int>(strlen(kRingbackTone))));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002545 EXPECT_FALSE(channel_->PlayRingbackTone(77, true, true));
2546 EXPECT_TRUE(channel_->PlayRingbackTone(2, true, true));
2547 EXPECT_EQ(1, voe_.IsPlayingFileLocally(channel_num));
2548 // Check we can stop the tone manually.
2549 EXPECT_TRUE(channel_->PlayRingbackTone(2, false, false));
2550 EXPECT_EQ(0, voe_.IsPlayingFileLocally(channel_num));
2551 // Check we stop the tone if a packet arrives, but only with the right SSRC.
2552 EXPECT_TRUE(channel_->PlayRingbackTone(2, true, true));
2553 EXPECT_EQ(1, voe_.IsPlayingFileLocally(channel_num));
2554 // Send a packet with SSRC 1; the tone should not stop.
2555 DeliverPacket(kPcmuFrame, sizeof(kPcmuFrame));
2556 EXPECT_EQ(1, voe_.IsPlayingFileLocally(channel_num));
2557 // Send a packet with SSRC 2; the tone should stop.
2558 char packet[sizeof(kPcmuFrame)];
2559 memcpy(packet, kPcmuFrame, sizeof(kPcmuFrame));
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002560 rtc::SetBE32(packet + 8, 2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002561 DeliverPacket(packet, sizeof(packet));
2562 EXPECT_EQ(0, voe_.IsPlayingFileLocally(channel_num));
2563}
2564
2565// Tests creating soundclips, and make sure they come from the right engine.
2566TEST_F(WebRtcVoiceEngineTestFake, CreateSoundclip) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002567 EXPECT_TRUE(engine_.Init(rtc::Thread::Current()));
wu@webrtc.org4551b792013-10-09 15:37:36 +00002568 EXPECT_FALSE(voe_sc_.IsInited());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002569 soundclip_ = engine_.CreateSoundclip();
wu@webrtc.org4551b792013-10-09 15:37:36 +00002570 EXPECT_TRUE(voe_sc_.IsInited());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002571 ASSERT_TRUE(soundclip_ != NULL);
2572 EXPECT_EQ(0, voe_.GetNumChannels());
2573 EXPECT_EQ(1, voe_sc_.GetNumChannels());
2574 int channel_num = voe_sc_.GetLastChannel();
2575 EXPECT_TRUE(voe_sc_.GetPlayout(channel_num));
2576 delete soundclip_;
2577 soundclip_ = NULL;
2578 EXPECT_EQ(0, voe_sc_.GetNumChannels());
wu@webrtc.org4551b792013-10-09 15:37:36 +00002579 // Make sure the soundclip engine is uninitialized on shutdown, now that
2580 // we've initialized it by creating a soundclip.
2581 engine_.Terminate();
2582 EXPECT_FALSE(voe_sc_.IsInited());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002583}
2584
2585// Tests playing out a fake sound.
2586TEST_F(WebRtcVoiceEngineTestFake, PlaySoundclip) {
2587 static const char kZeroes[16000] = {};
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002588 EXPECT_TRUE(engine_.Init(rtc::Thread::Current()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002589 soundclip_ = engine_.CreateSoundclip();
2590 ASSERT_TRUE(soundclip_ != NULL);
2591 EXPECT_TRUE(soundclip_->PlaySound(kZeroes, sizeof(kZeroes), 0));
2592}
2593
2594TEST_F(WebRtcVoiceEngineTestFake, MediaEngineCallbackOnError) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002595 rtc::scoped_ptr<ChannelErrorListener> listener;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002596 cricket::WebRtcVoiceMediaChannel* media_channel;
2597 unsigned int ssrc = 0;
2598
2599 EXPECT_TRUE(SetupEngine());
2600 EXPECT_TRUE(channel_->SetOptions(options_conference_));
2601 EXPECT_TRUE(channel_->SetSend(cricket::SEND_MICROPHONE));
2602
2603 media_channel = static_cast<cricket::WebRtcVoiceMediaChannel*>(channel_);
2604 listener.reset(new ChannelErrorListener(channel_));
2605
2606 // Test on WebRtc VoE channel.
2607 voe_.TriggerCallbackOnError(media_channel->voe_channel(),
2608 VE_SATURATION_WARNING);
2609 EXPECT_EQ(cricket::VoiceMediaChannel::ERROR_REC_DEVICE_SATURATION,
2610 listener->error());
2611 EXPECT_NE(-1, voe_.GetLocalSSRC(voe_.GetLastChannel(), ssrc));
2612 EXPECT_EQ(ssrc, listener->ssrc());
2613
2614 listener->Reset();
2615 voe_.TriggerCallbackOnError(-1, VE_TYPING_NOISE_WARNING);
2616 EXPECT_EQ(cricket::VoiceMediaChannel::ERROR_REC_TYPING_NOISE_DETECTED,
2617 listener->error());
2618 EXPECT_EQ(0U, listener->ssrc());
2619
2620 // Add another stream and test on that.
2621 ++ssrc;
2622 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(
2623 ssrc)));
2624 listener->Reset();
2625 voe_.TriggerCallbackOnError(voe_.GetLastChannel(),
2626 VE_SATURATION_WARNING);
2627 EXPECT_EQ(cricket::VoiceMediaChannel::ERROR_REC_DEVICE_SATURATION,
2628 listener->error());
2629 EXPECT_EQ(ssrc, listener->ssrc());
2630
2631 // Testing a non-existing channel.
2632 listener->Reset();
2633 voe_.TriggerCallbackOnError(voe_.GetLastChannel() + 2,
2634 VE_SATURATION_WARNING);
2635 EXPECT_EQ(0, listener->error());
2636}
2637
2638TEST_F(WebRtcVoiceEngineTestFake, TestSetPlayoutError) {
2639 EXPECT_TRUE(SetupEngine());
2640 EXPECT_TRUE(channel_->SetOptions(options_conference_));
2641 std::vector<cricket::AudioCodec> codecs;
2642 codecs.push_back(kPcmuCodec);
2643 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
2644 EXPECT_TRUE(channel_->SetSend(cricket::SEND_MICROPHONE));
2645 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(2)));
2646 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(3)));
2647 EXPECT_TRUE(channel_->SetPlayout(true));
2648 voe_.set_playout_fail_channel(voe_.GetLastChannel() - 1);
2649 EXPECT_TRUE(channel_->SetPlayout(false));
2650 EXPECT_FALSE(channel_->SetPlayout(true));
2651}
2652
2653// Test that the Registering/Unregistering with the
2654// webrtcvoiceengine works as expected
2655TEST_F(WebRtcVoiceEngineTestFake, RegisterVoiceProcessor) {
2656 EXPECT_TRUE(SetupEngine());
2657 EXPECT_TRUE(channel_->SetOptions(options_conference_));
2658 EXPECT_TRUE(channel_->AddRecvStream(
2659 cricket::StreamParams::CreateLegacy(kSsrc2)));
2660 cricket::FakeMediaProcessor vp_1;
2661 cricket::FakeMediaProcessor vp_2;
2662
2663 EXPECT_FALSE(engine_.RegisterProcessor(kSsrc2, &vp_1, cricket::MPD_TX));
2664 EXPECT_TRUE(engine_.RegisterProcessor(kSsrc2, &vp_1, cricket::MPD_RX));
2665 EXPECT_TRUE(engine_.RegisterProcessor(kSsrc2, &vp_2, cricket::MPD_RX));
2666 voe_.TriggerProcessPacket(cricket::MPD_RX);
2667 voe_.TriggerProcessPacket(cricket::MPD_TX);
2668
2669 EXPECT_TRUE(voe_.IsExternalMediaProcessorRegistered());
2670 EXPECT_EQ(1, vp_1.voice_frame_count());
2671 EXPECT_EQ(1, vp_2.voice_frame_count());
2672
2673 EXPECT_TRUE(engine_.UnregisterProcessor(kSsrc2,
2674 &vp_2,
2675 cricket::MPD_RX));
2676 voe_.TriggerProcessPacket(cricket::MPD_RX);
2677 EXPECT_TRUE(voe_.IsExternalMediaProcessorRegistered());
2678 EXPECT_EQ(1, vp_2.voice_frame_count());
2679 EXPECT_EQ(2, vp_1.voice_frame_count());
2680
2681 EXPECT_TRUE(engine_.UnregisterProcessor(kSsrc2,
2682 &vp_1,
2683 cricket::MPD_RX));
2684 voe_.TriggerProcessPacket(cricket::MPD_RX);
2685 EXPECT_FALSE(voe_.IsExternalMediaProcessorRegistered());
2686 EXPECT_EQ(2, vp_1.voice_frame_count());
2687
2688 EXPECT_FALSE(engine_.RegisterProcessor(kSsrc1, &vp_1, cricket::MPD_RX));
2689 EXPECT_TRUE(engine_.RegisterProcessor(kSsrc1, &vp_1, cricket::MPD_TX));
2690 voe_.TriggerProcessPacket(cricket::MPD_RX);
2691 voe_.TriggerProcessPacket(cricket::MPD_TX);
2692 EXPECT_TRUE(voe_.IsExternalMediaProcessorRegistered());
2693 EXPECT_EQ(3, vp_1.voice_frame_count());
2694
2695 EXPECT_TRUE(engine_.UnregisterProcessor(kSsrc1,
2696 &vp_1,
2697 cricket::MPD_RX_AND_TX));
2698 voe_.TriggerProcessPacket(cricket::MPD_TX);
2699 EXPECT_FALSE(voe_.IsExternalMediaProcessorRegistered());
2700 EXPECT_EQ(3, vp_1.voice_frame_count());
2701 EXPECT_TRUE(channel_->RemoveRecvStream(kSsrc2));
2702 EXPECT_FALSE(engine_.RegisterProcessor(kSsrc2, &vp_1, cricket::MPD_RX));
2703 EXPECT_FALSE(voe_.IsExternalMediaProcessorRegistered());
2704
2705 // Test that we can register a processor on the receive channel on SSRC 0.
2706 // This tests the 1:1 case when the receive SSRC is unknown.
2707 EXPECT_TRUE(engine_.RegisterProcessor(0, &vp_1, cricket::MPD_RX));
2708 voe_.TriggerProcessPacket(cricket::MPD_RX);
2709 EXPECT_TRUE(voe_.IsExternalMediaProcessorRegistered());
2710 EXPECT_EQ(4, vp_1.voice_frame_count());
2711 EXPECT_TRUE(engine_.UnregisterProcessor(0,
2712 &vp_1,
2713 cricket::MPD_RX));
2714
2715 // The following tests test that FindChannelNumFromSsrc is doing
2716 // what we expect.
2717 // pick an invalid ssrc and make sure we can't register
2718 EXPECT_FALSE(engine_.RegisterProcessor(99,
2719 &vp_1,
2720 cricket::MPD_RX));
2721 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(1)));
2722 EXPECT_TRUE(engine_.RegisterProcessor(1,
2723 &vp_1,
2724 cricket::MPD_RX));
2725 EXPECT_TRUE(engine_.UnregisterProcessor(1,
2726 &vp_1,
2727 cricket::MPD_RX));
2728 EXPECT_FALSE(engine_.RegisterProcessor(1,
2729 &vp_1,
2730 cricket::MPD_TX));
2731 EXPECT_TRUE(channel_->RemoveRecvStream(1));
2732}
2733
2734TEST_F(WebRtcVoiceEngineTestFake, SetAudioOptions) {
2735 EXPECT_TRUE(SetupEngine());
2736
2737 bool ec_enabled;
2738 webrtc::EcModes ec_mode;
2739 bool ec_metrics_enabled;
2740 webrtc::AecmModes aecm_mode;
2741 bool cng_enabled;
2742 bool agc_enabled;
2743 webrtc::AgcModes agc_mode;
2744 webrtc::AgcConfig agc_config;
2745 bool ns_enabled;
2746 webrtc::NsModes ns_mode;
2747 bool highpass_filter_enabled;
2748 bool stereo_swapping_enabled;
2749 bool typing_detection_enabled;
2750 voe_.GetEcStatus(ec_enabled, ec_mode);
2751 voe_.GetEcMetricsStatus(ec_metrics_enabled);
2752 voe_.GetAecmMode(aecm_mode, cng_enabled);
2753 voe_.GetAgcStatus(agc_enabled, agc_mode);
2754 voe_.GetAgcConfig(agc_config);
2755 voe_.GetNsStatus(ns_enabled, ns_mode);
2756 highpass_filter_enabled = voe_.IsHighPassFilterEnabled();
2757 stereo_swapping_enabled = voe_.IsStereoChannelSwappingEnabled();
2758 voe_.GetTypingDetectionStatus(typing_detection_enabled);
2759 EXPECT_TRUE(ec_enabled);
2760 EXPECT_TRUE(ec_metrics_enabled);
2761 EXPECT_FALSE(cng_enabled);
2762 EXPECT_TRUE(agc_enabled);
2763 EXPECT_EQ(0, agc_config.targetLeveldBOv);
2764 EXPECT_TRUE(ns_enabled);
2765 EXPECT_TRUE(highpass_filter_enabled);
2766 EXPECT_FALSE(stereo_swapping_enabled);
2767 EXPECT_TRUE(typing_detection_enabled);
2768 EXPECT_EQ(ec_mode, webrtc::kEcConference);
2769 EXPECT_EQ(ns_mode, webrtc::kNsHighSuppression);
2770
2771 // Nothing set, so all ignored.
2772 cricket::AudioOptions options;
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00002773 ASSERT_TRUE(engine_.SetOptions(options));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002774 voe_.GetEcStatus(ec_enabled, ec_mode);
2775 voe_.GetEcMetricsStatus(ec_metrics_enabled);
2776 voe_.GetAecmMode(aecm_mode, cng_enabled);
2777 voe_.GetAgcStatus(agc_enabled, agc_mode);
2778 voe_.GetAgcConfig(agc_config);
2779 voe_.GetNsStatus(ns_enabled, ns_mode);
2780 highpass_filter_enabled = voe_.IsHighPassFilterEnabled();
2781 stereo_swapping_enabled = voe_.IsStereoChannelSwappingEnabled();
2782 voe_.GetTypingDetectionStatus(typing_detection_enabled);
2783 EXPECT_TRUE(ec_enabled);
2784 EXPECT_TRUE(ec_metrics_enabled);
2785 EXPECT_FALSE(cng_enabled);
2786 EXPECT_TRUE(agc_enabled);
2787 EXPECT_EQ(0, agc_config.targetLeveldBOv);
2788 EXPECT_TRUE(ns_enabled);
2789 EXPECT_TRUE(highpass_filter_enabled);
2790 EXPECT_FALSE(stereo_swapping_enabled);
2791 EXPECT_TRUE(typing_detection_enabled);
2792 EXPECT_EQ(ec_mode, webrtc::kEcConference);
2793 EXPECT_EQ(ns_mode, webrtc::kNsHighSuppression);
2794
2795 // Turn echo cancellation off
2796 options.echo_cancellation.Set(false);
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00002797 ASSERT_TRUE(engine_.SetOptions(options));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002798 voe_.GetEcStatus(ec_enabled, ec_mode);
2799 EXPECT_FALSE(ec_enabled);
2800
2801 // Turn echo cancellation back on, with settings, and make sure
2802 // nothing else changed.
2803 options.echo_cancellation.Set(true);
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00002804 ASSERT_TRUE(engine_.SetOptions(options));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002805 voe_.GetEcStatus(ec_enabled, ec_mode);
2806 voe_.GetEcMetricsStatus(ec_metrics_enabled);
2807 voe_.GetAecmMode(aecm_mode, cng_enabled);
2808 voe_.GetAgcStatus(agc_enabled, agc_mode);
2809 voe_.GetAgcConfig(agc_config);
2810 voe_.GetNsStatus(ns_enabled, ns_mode);
2811 highpass_filter_enabled = voe_.IsHighPassFilterEnabled();
2812 stereo_swapping_enabled = voe_.IsStereoChannelSwappingEnabled();
2813 voe_.GetTypingDetectionStatus(typing_detection_enabled);
2814 EXPECT_TRUE(ec_enabled);
2815 EXPECT_TRUE(ec_metrics_enabled);
2816 EXPECT_TRUE(agc_enabled);
2817 EXPECT_EQ(0, agc_config.targetLeveldBOv);
2818 EXPECT_TRUE(ns_enabled);
2819 EXPECT_TRUE(highpass_filter_enabled);
2820 EXPECT_FALSE(stereo_swapping_enabled);
2821 EXPECT_TRUE(typing_detection_enabled);
2822 EXPECT_EQ(ec_mode, webrtc::kEcConference);
2823 EXPECT_EQ(ns_mode, webrtc::kNsHighSuppression);
2824
2825 // Turn off AGC
2826 options.auto_gain_control.Set(false);
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00002827 ASSERT_TRUE(engine_.SetOptions(options));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002828 voe_.GetAgcStatus(agc_enabled, agc_mode);
2829 EXPECT_FALSE(agc_enabled);
2830
2831 // Turn AGC back on
2832 options.auto_gain_control.Set(true);
2833 options.adjust_agc_delta.Clear();
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00002834 ASSERT_TRUE(engine_.SetOptions(options));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002835 voe_.GetAgcStatus(agc_enabled, agc_mode);
2836 EXPECT_TRUE(agc_enabled);
2837 voe_.GetAgcConfig(agc_config);
2838 EXPECT_EQ(0, agc_config.targetLeveldBOv);
2839
2840 // Turn off other options (and stereo swapping on).
2841 options.noise_suppression.Set(false);
2842 options.highpass_filter.Set(false);
2843 options.typing_detection.Set(false);
2844 options.stereo_swapping.Set(true);
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00002845 ASSERT_TRUE(engine_.SetOptions(options));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002846 voe_.GetNsStatus(ns_enabled, ns_mode);
2847 highpass_filter_enabled = voe_.IsHighPassFilterEnabled();
2848 stereo_swapping_enabled = voe_.IsStereoChannelSwappingEnabled();
2849 voe_.GetTypingDetectionStatus(typing_detection_enabled);
2850 EXPECT_FALSE(ns_enabled);
2851 EXPECT_FALSE(highpass_filter_enabled);
2852 EXPECT_FALSE(typing_detection_enabled);
2853 EXPECT_TRUE(stereo_swapping_enabled);
2854
2855 // Turn on "conference mode" to ensure it has no impact.
2856 options.conference_mode.Set(true);
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00002857 ASSERT_TRUE(engine_.SetOptions(options));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002858 voe_.GetEcStatus(ec_enabled, ec_mode);
2859 voe_.GetNsStatus(ns_enabled, ns_mode);
2860 EXPECT_TRUE(ec_enabled);
2861 EXPECT_EQ(webrtc::kEcConference, ec_mode);
2862 EXPECT_FALSE(ns_enabled);
2863 EXPECT_EQ(webrtc::kNsHighSuppression, ns_mode);
2864}
2865
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00002866TEST_F(WebRtcVoiceEngineTestFake, DefaultOptions) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002867 EXPECT_TRUE(SetupEngine());
2868
2869 bool ec_enabled;
2870 webrtc::EcModes ec_mode;
2871 bool ec_metrics_enabled;
2872 bool agc_enabled;
2873 webrtc::AgcModes agc_mode;
2874 bool ns_enabled;
2875 webrtc::NsModes ns_mode;
2876 bool highpass_filter_enabled;
2877 bool stereo_swapping_enabled;
2878 bool typing_detection_enabled;
2879
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002880 voe_.GetEcStatus(ec_enabled, ec_mode);
2881 voe_.GetEcMetricsStatus(ec_metrics_enabled);
2882 voe_.GetAgcStatus(agc_enabled, agc_mode);
2883 voe_.GetNsStatus(ns_enabled, ns_mode);
2884 highpass_filter_enabled = voe_.IsHighPassFilterEnabled();
2885 stereo_swapping_enabled = voe_.IsStereoChannelSwappingEnabled();
2886 voe_.GetTypingDetectionStatus(typing_detection_enabled);
2887 EXPECT_TRUE(ec_enabled);
2888 EXPECT_TRUE(agc_enabled);
2889 EXPECT_TRUE(ns_enabled);
2890 EXPECT_TRUE(highpass_filter_enabled);
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00002891 EXPECT_TRUE(typing_detection_enabled);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002892 EXPECT_FALSE(stereo_swapping_enabled);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002893}
2894
2895TEST_F(WebRtcVoiceEngineTestFake, InitDoesNotOverwriteDefaultAgcConfig) {
2896 webrtc::AgcConfig set_config = {0};
2897 set_config.targetLeveldBOv = 3;
2898 set_config.digitalCompressionGaindB = 9;
2899 set_config.limiterEnable = true;
2900 EXPECT_EQ(0, voe_.SetAgcConfig(set_config));
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002901 EXPECT_TRUE(engine_.Init(rtc::Thread::Current()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002902
2903 webrtc::AgcConfig config = {0};
2904 EXPECT_EQ(0, voe_.GetAgcConfig(config));
2905 EXPECT_EQ(set_config.targetLeveldBOv, config.targetLeveldBOv);
2906 EXPECT_EQ(set_config.digitalCompressionGaindB,
2907 config.digitalCompressionGaindB);
2908 EXPECT_EQ(set_config.limiterEnable, config.limiterEnable);
2909}
2910
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002911TEST_F(WebRtcVoiceEngineTestFake, SetOptionOverridesViaChannels) {
2912 EXPECT_TRUE(SetupEngine());
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002913 rtc::scoped_ptr<cricket::VoiceMediaChannel> channel1(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002914 engine_.CreateChannel());
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002915 rtc::scoped_ptr<cricket::VoiceMediaChannel> channel2(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002916 engine_.CreateChannel());
2917
2918 // Have to add a stream to make SetSend work.
2919 cricket::StreamParams stream1;
2920 stream1.ssrcs.push_back(1);
2921 channel1->AddSendStream(stream1);
2922 cricket::StreamParams stream2;
2923 stream2.ssrcs.push_back(2);
2924 channel2->AddSendStream(stream2);
2925
2926 // AEC and AGC and NS
2927 cricket::AudioOptions options_all;
2928 options_all.echo_cancellation.Set(true);
2929 options_all.auto_gain_control.Set(true);
2930 options_all.noise_suppression.Set(true);
2931
2932 ASSERT_TRUE(channel1->SetOptions(options_all));
2933 cricket::AudioOptions expected_options = options_all;
2934 cricket::AudioOptions actual_options;
2935 ASSERT_TRUE(channel1->GetOptions(&actual_options));
2936 EXPECT_EQ(expected_options, actual_options);
2937 ASSERT_TRUE(channel2->SetOptions(options_all));
2938 ASSERT_TRUE(channel2->GetOptions(&actual_options));
2939 EXPECT_EQ(expected_options, actual_options);
2940
2941 // unset NS
2942 cricket::AudioOptions options_no_ns;
2943 options_no_ns.noise_suppression.Set(false);
2944 ASSERT_TRUE(channel1->SetOptions(options_no_ns));
2945
2946 expected_options.echo_cancellation.Set(true);
2947 expected_options.auto_gain_control.Set(true);
2948 expected_options.noise_suppression.Set(false);
2949 ASSERT_TRUE(channel1->GetOptions(&actual_options));
2950 EXPECT_EQ(expected_options, actual_options);
2951
2952 // unset AGC
2953 cricket::AudioOptions options_no_agc;
2954 options_no_agc.auto_gain_control.Set(false);
2955 ASSERT_TRUE(channel2->SetOptions(options_no_agc));
2956
2957 expected_options.echo_cancellation.Set(true);
2958 expected_options.auto_gain_control.Set(false);
2959 expected_options.noise_suppression.Set(true);
2960 ASSERT_TRUE(channel2->GetOptions(&actual_options));
2961 EXPECT_EQ(expected_options, actual_options);
2962
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00002963 ASSERT_TRUE(engine_.SetOptions(options_all));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002964 bool ec_enabled;
2965 webrtc::EcModes ec_mode;
2966 bool agc_enabled;
2967 webrtc::AgcModes agc_mode;
2968 bool ns_enabled;
2969 webrtc::NsModes ns_mode;
2970 voe_.GetEcStatus(ec_enabled, ec_mode);
2971 voe_.GetAgcStatus(agc_enabled, agc_mode);
2972 voe_.GetNsStatus(ns_enabled, ns_mode);
2973 EXPECT_TRUE(ec_enabled);
2974 EXPECT_TRUE(agc_enabled);
2975 EXPECT_TRUE(ns_enabled);
2976
2977 channel1->SetSend(cricket::SEND_MICROPHONE);
2978 voe_.GetEcStatus(ec_enabled, ec_mode);
2979 voe_.GetAgcStatus(agc_enabled, agc_mode);
2980 voe_.GetNsStatus(ns_enabled, ns_mode);
2981 EXPECT_TRUE(ec_enabled);
2982 EXPECT_TRUE(agc_enabled);
2983 EXPECT_FALSE(ns_enabled);
2984
2985 channel1->SetSend(cricket::SEND_NOTHING);
2986 voe_.GetEcStatus(ec_enabled, ec_mode);
2987 voe_.GetAgcStatus(agc_enabled, agc_mode);
2988 voe_.GetNsStatus(ns_enabled, ns_mode);
2989 EXPECT_TRUE(ec_enabled);
2990 EXPECT_TRUE(agc_enabled);
2991 EXPECT_TRUE(ns_enabled);
2992
2993 channel2->SetSend(cricket::SEND_MICROPHONE);
2994 voe_.GetEcStatus(ec_enabled, ec_mode);
2995 voe_.GetAgcStatus(agc_enabled, agc_mode);
2996 voe_.GetNsStatus(ns_enabled, ns_mode);
2997 EXPECT_TRUE(ec_enabled);
2998 EXPECT_FALSE(agc_enabled);
2999 EXPECT_TRUE(ns_enabled);
3000
3001 channel2->SetSend(cricket::SEND_NOTHING);
3002 voe_.GetEcStatus(ec_enabled, ec_mode);
3003 voe_.GetAgcStatus(agc_enabled, agc_mode);
3004 voe_.GetNsStatus(ns_enabled, ns_mode);
3005 EXPECT_TRUE(ec_enabled);
3006 EXPECT_TRUE(agc_enabled);
3007 EXPECT_TRUE(ns_enabled);
3008
3009 // Make sure settings take effect while we are sending.
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00003010 ASSERT_TRUE(engine_.SetOptions(options_all));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003011 cricket::AudioOptions options_no_agc_nor_ns;
3012 options_no_agc_nor_ns.auto_gain_control.Set(false);
3013 options_no_agc_nor_ns.noise_suppression.Set(false);
3014 channel2->SetSend(cricket::SEND_MICROPHONE);
3015 channel2->SetOptions(options_no_agc_nor_ns);
3016
3017 expected_options.echo_cancellation.Set(true);
3018 expected_options.auto_gain_control.Set(false);
3019 expected_options.noise_suppression.Set(false);
3020 ASSERT_TRUE(channel2->GetOptions(&actual_options));
3021 EXPECT_EQ(expected_options, actual_options);
3022 voe_.GetEcStatus(ec_enabled, ec_mode);
3023 voe_.GetAgcStatus(agc_enabled, agc_mode);
3024 voe_.GetNsStatus(ns_enabled, ns_mode);
3025 EXPECT_TRUE(ec_enabled);
3026 EXPECT_FALSE(agc_enabled);
3027 EXPECT_FALSE(ns_enabled);
3028}
3029
wu@webrtc.orgde305012013-10-31 15:40:38 +00003030// This test verifies DSCP settings are properly applied on voice media channel.
3031TEST_F(WebRtcVoiceEngineTestFake, TestSetDscpOptions) {
3032 EXPECT_TRUE(SetupEngine());
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003033 rtc::scoped_ptr<cricket::VoiceMediaChannel> channel(
wu@webrtc.orgde305012013-10-31 15:40:38 +00003034 engine_.CreateChannel());
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003035 rtc::scoped_ptr<cricket::FakeNetworkInterface> network_interface(
wu@webrtc.orgde305012013-10-31 15:40:38 +00003036 new cricket::FakeNetworkInterface);
3037 channel->SetInterface(network_interface.get());
3038 cricket::AudioOptions options;
3039 options.dscp.Set(true);
3040 EXPECT_TRUE(channel->SetOptions(options));
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003041 EXPECT_EQ(rtc::DSCP_EF, network_interface->dscp());
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +00003042 // Verify previous value is not modified if dscp option is not set.
3043 cricket::AudioOptions options1;
3044 EXPECT_TRUE(channel->SetOptions(options1));
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003045 EXPECT_EQ(rtc::DSCP_EF, network_interface->dscp());
wu@webrtc.orgde305012013-10-31 15:40:38 +00003046 options.dscp.Set(false);
3047 EXPECT_TRUE(channel->SetOptions(options));
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003048 EXPECT_EQ(rtc::DSCP_DEFAULT, network_interface->dscp());
wu@webrtc.orgde305012013-10-31 15:40:38 +00003049}
3050
wu@webrtc.org1d1ffc92013-10-16 18:12:02 +00003051TEST(WebRtcVoiceEngineTest, TestDefaultOptionsBeforeInit) {
3052 cricket::WebRtcVoiceEngine engine;
3053 cricket::AudioOptions options = engine.GetOptions();
3054 // The default options should have at least a few things set. We purposefully
3055 // don't check the option values here, though.
3056 EXPECT_TRUE(options.echo_cancellation.IsSet());
3057 EXPECT_TRUE(options.auto_gain_control.IsSet());
3058 EXPECT_TRUE(options.noise_suppression.IsSet());
3059}
3060
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003061// Test that GetReceiveChannelNum returns the default channel for the first
3062// recv stream in 1-1 calls.
3063TEST_F(WebRtcVoiceEngineTestFake, TestGetReceiveChannelNumIn1To1Calls) {
3064 EXPECT_TRUE(SetupEngine());
3065 cricket::WebRtcVoiceMediaChannel* media_channel =
3066 static_cast<cricket::WebRtcVoiceMediaChannel*>(channel_);
3067 // Test that GetChannelNum returns the default channel if the SSRC is unknown.
3068 EXPECT_EQ(media_channel->voe_channel(),
3069 media_channel->GetReceiveChannelNum(0));
3070 cricket::StreamParams stream;
3071 stream.ssrcs.push_back(kSsrc2);
3072 EXPECT_TRUE(channel_->AddRecvStream(stream));
3073 EXPECT_EQ(media_channel->voe_channel(),
3074 media_channel->GetReceiveChannelNum(kSsrc2));
3075}
3076
3077// Test that GetReceiveChannelNum doesn't return the default channel for the
3078// first recv stream in conference calls.
3079TEST_F(WebRtcVoiceEngineTestFake, TestGetChannelNumInConferenceCalls) {
3080 EXPECT_TRUE(SetupEngine());
3081 EXPECT_TRUE(channel_->SetOptions(options_conference_));
3082 cricket::StreamParams stream;
3083 stream.ssrcs.push_back(kSsrc2);
3084 EXPECT_TRUE(channel_->AddRecvStream(stream));
3085 cricket::WebRtcVoiceMediaChannel* media_channel =
3086 static_cast<cricket::WebRtcVoiceMediaChannel*>(channel_);
3087 EXPECT_LT(media_channel->voe_channel(),
3088 media_channel->GetReceiveChannelNum(kSsrc2));
3089}
3090
3091TEST_F(WebRtcVoiceEngineTestFake, SetOutputScaling) {
3092 EXPECT_TRUE(SetupEngine());
3093 double left, right;
3094 EXPECT_TRUE(channel_->SetOutputScaling(0, 1, 2));
3095 EXPECT_TRUE(channel_->GetOutputScaling(0, &left, &right));
3096 EXPECT_DOUBLE_EQ(1, left);
3097 EXPECT_DOUBLE_EQ(2, right);
3098
3099 EXPECT_FALSE(channel_->SetOutputScaling(kSsrc2, 1, 2));
3100 cricket::StreamParams stream;
3101 stream.ssrcs.push_back(kSsrc2);
3102 EXPECT_TRUE(channel_->AddRecvStream(stream));
3103
3104 EXPECT_TRUE(channel_->SetOutputScaling(kSsrc2, 2, 1));
3105 EXPECT_TRUE(channel_->GetOutputScaling(kSsrc2, &left, &right));
3106 EXPECT_DOUBLE_EQ(2, left);
3107 EXPECT_DOUBLE_EQ(1, right);
3108}
3109
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003110// Tests for the actual WebRtc VoE library.
3111
3112// Tests that the library initializes and shuts down properly.
3113TEST(WebRtcVoiceEngineTest, StartupShutdown) {
3114 cricket::WebRtcVoiceEngine engine;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003115 EXPECT_TRUE(engine.Init(rtc::Thread::Current()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003116 cricket::VoiceMediaChannel* channel = engine.CreateChannel();
3117 EXPECT_TRUE(channel != NULL);
3118 delete channel;
3119 engine.Terminate();
3120
3121 // Reinit to catch regression where VoiceEngineObserver reference is lost
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003122 EXPECT_TRUE(engine.Init(rtc::Thread::Current()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003123 engine.Terminate();
3124}
3125
3126// Tests that the logging from the library is cleartext.
3127TEST(WebRtcVoiceEngineTest, DISABLED_HasUnencryptedLogging) {
3128 cricket::WebRtcVoiceEngine engine;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003129 rtc::scoped_ptr<rtc::MemoryStream> stream(
3130 new rtc::MemoryStream);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003131 size_t size = 0;
3132 bool cleartext = true;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003133 rtc::LogMessage::AddLogToStream(stream.get(), rtc::LS_VERBOSE);
3134 engine.SetLogging(rtc::LS_VERBOSE, "");
3135 EXPECT_TRUE(engine.Init(rtc::Thread::Current()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003136 EXPECT_TRUE(stream->GetSize(&size));
3137 EXPECT_GT(size, 0U);
3138 engine.Terminate();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003139 rtc::LogMessage::RemoveLogToStream(stream.get());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003140 const char* buf = stream->GetBuffer();
3141 for (size_t i = 0; i < size && cleartext; ++i) {
3142 int ch = static_cast<int>(buf[i]);
3143 ASSERT_GE(ch, 0) << "Out of bounds character in WebRtc VoE log: "
3144 << std::hex << ch;
3145 cleartext = (isprint(ch) || isspace(ch));
3146 }
3147 EXPECT_TRUE(cleartext);
3148}
3149
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003150// Tests that the library is configured with the codecs we want.
3151TEST(WebRtcVoiceEngineTest, HasCorrectCodecs) {
3152 cricket::WebRtcVoiceEngine engine;
3153 // Check codecs by name.
3154 EXPECT_TRUE(engine.FindCodec(
3155 cricket::AudioCodec(96, "OPUS", 48000, 0, 2, 0)));
3156 EXPECT_TRUE(engine.FindCodec(
3157 cricket::AudioCodec(96, "ISAC", 16000, 0, 1, 0)));
3158 EXPECT_TRUE(engine.FindCodec(
3159 cricket::AudioCodec(96, "ISAC", 32000, 0, 1, 0)));
3160 // Check that name matching is case-insensitive.
3161 EXPECT_TRUE(engine.FindCodec(
3162 cricket::AudioCodec(96, "ILBC", 8000, 0, 1, 0)));
3163 EXPECT_TRUE(engine.FindCodec(
3164 cricket::AudioCodec(96, "iLBC", 8000, 0, 1, 0)));
3165 EXPECT_TRUE(engine.FindCodec(
3166 cricket::AudioCodec(96, "PCMU", 8000, 0, 1, 0)));
3167 EXPECT_TRUE(engine.FindCodec(
3168 cricket::AudioCodec(96, "PCMA", 8000, 0, 1, 0)));
3169 EXPECT_TRUE(engine.FindCodec(
henrik.lundin@webrtc.orgf85dbce2014-11-07 12:25:00 +00003170 cricket::AudioCodec(96, "G722", 8000, 0, 1, 0)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003171 EXPECT_TRUE(engine.FindCodec(
3172 cricket::AudioCodec(96, "red", 8000, 0, 1, 0)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003173 EXPECT_TRUE(engine.FindCodec(
3174 cricket::AudioCodec(96, "CN", 32000, 0, 1, 0)));
3175 EXPECT_TRUE(engine.FindCodec(
3176 cricket::AudioCodec(96, "CN", 16000, 0, 1, 0)));
3177 EXPECT_TRUE(engine.FindCodec(
3178 cricket::AudioCodec(96, "CN", 8000, 0, 1, 0)));
3179 EXPECT_TRUE(engine.FindCodec(
3180 cricket::AudioCodec(96, "telephone-event", 8000, 0, 1, 0)));
3181 // Check codecs with an id by id.
3182 EXPECT_TRUE(engine.FindCodec(
3183 cricket::AudioCodec(0, "", 8000, 0, 1, 0))); // PCMU
3184 EXPECT_TRUE(engine.FindCodec(
3185 cricket::AudioCodec(8, "", 8000, 0, 1, 0))); // PCMA
3186 EXPECT_TRUE(engine.FindCodec(
henrik.lundin@webrtc.orgf85dbce2014-11-07 12:25:00 +00003187 cricket::AudioCodec(9, "", 8000, 0, 1, 0))); // G722
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003188 EXPECT_TRUE(engine.FindCodec(
3189 cricket::AudioCodec(13, "", 8000, 0, 1, 0))); // CN
3190 // Check sample/bitrate matching.
3191 EXPECT_TRUE(engine.FindCodec(
3192 cricket::AudioCodec(0, "PCMU", 8000, 64000, 1, 0)));
3193 // Check that bad codecs fail.
3194 EXPECT_FALSE(engine.FindCodec(cricket::AudioCodec(99, "ABCD", 0, 0, 1, 0)));
3195 EXPECT_FALSE(engine.FindCodec(cricket::AudioCodec(88, "", 0, 0, 1, 0)));
3196 EXPECT_FALSE(engine.FindCodec(cricket::AudioCodec(0, "", 0, 0, 2, 0)));
3197 EXPECT_FALSE(engine.FindCodec(cricket::AudioCodec(0, "", 5000, 0, 1, 0)));
3198 EXPECT_FALSE(engine.FindCodec(cricket::AudioCodec(0, "", 0, 5000, 1, 0)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003199 // Verify the payload id of common audio codecs, including CN, ISAC, and G722.
3200 for (std::vector<cricket::AudioCodec>::const_iterator it =
3201 engine.codecs().begin(); it != engine.codecs().end(); ++it) {
3202 if (it->name == "CN" && it->clockrate == 16000) {
3203 EXPECT_EQ(105, it->id);
3204 } else if (it->name == "CN" && it->clockrate == 32000) {
3205 EXPECT_EQ(106, it->id);
3206 } else if (it->name == "ISAC" && it->clockrate == 16000) {
3207 EXPECT_EQ(103, it->id);
3208 } else if (it->name == "ISAC" && it->clockrate == 32000) {
3209 EXPECT_EQ(104, it->id);
henrik.lundin@webrtc.orgf85dbce2014-11-07 12:25:00 +00003210 } else if (it->name == "G722" && it->clockrate == 8000) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003211 EXPECT_EQ(9, it->id);
3212 } else if (it->name == "telephone-event") {
3213 EXPECT_EQ(126, it->id);
3214 } else if (it->name == "red") {
3215 EXPECT_EQ(127, it->id);
3216 } else if (it->name == "opus") {
3217 EXPECT_EQ(111, it->id);
wu@webrtc.org9caf2762013-12-11 18:25:07 +00003218 ASSERT_TRUE(it->params.find("minptime") != it->params.end());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003219 EXPECT_EQ("10", it->params.find("minptime")->second);
wu@webrtc.org9caf2762013-12-11 18:25:07 +00003220 ASSERT_TRUE(it->params.find("maxptime") != it->params.end());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003221 EXPECT_EQ("60", it->params.find("maxptime")->second);
minyue@webrtc.org4ef22d12014-11-17 09:26:39 +00003222 ASSERT_TRUE(it->params.find("useinbandfec") != it->params.end());
3223 EXPECT_EQ("1", it->params.find("useinbandfec")->second);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003224 }
3225 }
3226
3227 engine.Terminate();
3228}
3229
3230// Tests that VoE supports at least 32 channels
3231TEST(WebRtcVoiceEngineTest, Has32Channels) {
3232 cricket::WebRtcVoiceEngine engine;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003233 EXPECT_TRUE(engine.Init(rtc::Thread::Current()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003234
3235 cricket::VoiceMediaChannel* channels[32];
3236 int num_channels = 0;
3237
3238 while (num_channels < ARRAY_SIZE(channels)) {
3239 cricket::VoiceMediaChannel* channel = engine.CreateChannel();
3240 if (!channel)
3241 break;
3242
3243 channels[num_channels++] = channel;
3244 }
3245
3246 int expected = ARRAY_SIZE(channels);
3247 EXPECT_EQ(expected, num_channels);
3248
3249 while (num_channels > 0) {
3250 delete channels[--num_channels];
3251 }
3252
3253 engine.Terminate();
3254}
3255
3256// Test that we set our preferred codecs properly.
3257TEST(WebRtcVoiceEngineTest, SetRecvCodecs) {
3258 cricket::WebRtcVoiceEngine engine;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003259 EXPECT_TRUE(engine.Init(rtc::Thread::Current()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003260 cricket::WebRtcVoiceMediaChannel channel(&engine);
3261 EXPECT_TRUE(channel.SetRecvCodecs(engine.codecs()));
3262}
3263
3264#ifdef WIN32
3265// Test our workarounds to WebRtc VoE' munging of the coinit count
3266TEST(WebRtcVoiceEngineTest, CoInitialize) {
3267 cricket::WebRtcVoiceEngine* engine = new cricket::WebRtcVoiceEngine();
3268
3269 // Initial refcount should be 0.
3270 EXPECT_EQ(S_OK, CoInitializeEx(NULL, COINIT_MULTITHREADED));
3271
3272 // Engine should start even with COM already inited.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003273 EXPECT_TRUE(engine->Init(rtc::Thread::Current()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003274 engine->Terminate();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003275 EXPECT_TRUE(engine->Init(rtc::Thread::Current()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003276 engine->Terminate();
3277
3278 // Refcount after terminate should be 1 (in reality 3); test if it is nonzero.
3279 EXPECT_EQ(S_FALSE, CoInitializeEx(NULL, COINIT_MULTITHREADED));
3280 // Decrement refcount to (hopefully) 0.
3281 CoUninitialize();
3282 CoUninitialize();
3283 delete engine;
3284
3285 // Ensure refcount is 0.
3286 EXPECT_EQ(S_OK, CoInitializeEx(NULL, COINIT_MULTITHREADED));
3287 CoUninitialize();
3288}
3289#endif
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +00003290
3291TEST_F(WebRtcVoiceEngineTestFake, ChangeCombinedAudioVideoBweOption) {
3292 // Test that changing the combined_audio_video_bwe option results in the
3293 // expected state changes in VoiceEngine.
3294 cricket::ViEWrapper vie;
3295 const int kVieCh = 667;
3296
3297 EXPECT_TRUE(SetupEngine());
3298 cricket::WebRtcVoiceMediaChannel* media_channel =
3299 static_cast<cricket::WebRtcVoiceMediaChannel*>(channel_);
3300 EXPECT_TRUE(media_channel->SetupSharedBandwidthEstimation(vie.engine(),
3301 kVieCh));
3302 EXPECT_TRUE(media_channel->AddRecvStream(
3303 cricket::StreamParams::CreateLegacy(2)));
3304 int recv_ch = voe_.GetLastChannel();
3305
3306 // Combined BWE should not be set up yet.
3307 EXPECT_EQ(NULL, voe_.GetViENetwork(recv_ch));
3308 EXPECT_EQ(-1, voe_.GetVideoChannel(recv_ch));
3309
3310 // Enable combined BWE option - now it should be set up.
3311 cricket::AudioOptions options;
3312 options.combined_audio_video_bwe.Set(true);
3313 EXPECT_TRUE(media_channel->SetOptions(options));
3314 EXPECT_EQ(vie.network(), voe_.GetViENetwork(recv_ch));
3315 EXPECT_EQ(kVieCh, voe_.GetVideoChannel(recv_ch));
3316
3317 // Disable combined BWE option - should be disabled again.
3318 options.combined_audio_video_bwe.Set(false);
3319 EXPECT_TRUE(media_channel->SetOptions(options));
3320 EXPECT_EQ(NULL, voe_.GetViENetwork(recv_ch));
3321 EXPECT_EQ(-1, voe_.GetVideoChannel(recv_ch));
3322
3323 EXPECT_TRUE(media_channel->SetupSharedBandwidthEstimation(NULL, -1));
3324}
3325
3326TEST_F(WebRtcVoiceEngineTestFake, SetupSharedBandwidthEstimation) {
3327 // Test that calling SetupSharedBandwidthEstimation() on the voice media
3328 // channel results in the expected state changes in VoiceEngine.
3329 cricket::ViEWrapper vie1;
3330 cricket::ViEWrapper vie2;
3331 const int kVieCh1 = 667;
3332 const int kVieCh2 = 70;
3333
3334 EXPECT_TRUE(SetupEngine());
3335 cricket::WebRtcVoiceMediaChannel* media_channel =
3336 static_cast<cricket::WebRtcVoiceMediaChannel*>(channel_);
3337 cricket::AudioOptions options;
3338 options.combined_audio_video_bwe.Set(true);
3339 EXPECT_TRUE(media_channel->SetOptions(options));
3340 EXPECT_TRUE(media_channel->AddRecvStream(
3341 cricket::StreamParams::CreateLegacy(2)));
3342 int recv_ch = voe_.GetLastChannel();
3343
3344 // Combined BWE should not be set up yet.
3345 EXPECT_EQ(NULL, voe_.GetViENetwork(recv_ch));
3346 EXPECT_EQ(-1, voe_.GetVideoChannel(recv_ch));
3347
3348 // Register - should be enabled.
3349 EXPECT_TRUE(media_channel->SetupSharedBandwidthEstimation(vie1.engine(),
3350 kVieCh1));
3351 EXPECT_EQ(vie1.network(), voe_.GetViENetwork(recv_ch));
3352 EXPECT_EQ(kVieCh1, voe_.GetVideoChannel(recv_ch));
3353
3354 // Re-register - should still be enabled.
3355 EXPECT_TRUE(media_channel->SetupSharedBandwidthEstimation(vie2.engine(),
3356 kVieCh2));
3357 EXPECT_EQ(vie2.network(), voe_.GetViENetwork(recv_ch));
3358 EXPECT_EQ(kVieCh2, voe_.GetVideoChannel(recv_ch));
3359
3360 // Unregister - should be disabled again.
3361 EXPECT_TRUE(media_channel->SetupSharedBandwidthEstimation(NULL, -1));
3362 EXPECT_EQ(NULL, voe_.GetViENetwork(recv_ch));
3363 EXPECT_EQ(-1, voe_.GetVideoChannel(recv_ch));
3364}
3365
3366TEST_F(WebRtcVoiceEngineTestFake, ConfigureCombinedBweForNewRecvStreams) {
3367 // Test that adding receive streams after enabling combined bandwidth
3368 // estimation will correctly configure each channel.
3369 cricket::ViEWrapper vie;
3370 const int kVieCh = 667;
3371
3372 EXPECT_TRUE(SetupEngine());
3373 cricket::WebRtcVoiceMediaChannel* media_channel =
3374 static_cast<cricket::WebRtcVoiceMediaChannel*>(channel_);
3375 EXPECT_TRUE(media_channel->SetupSharedBandwidthEstimation(vie.engine(),
3376 kVieCh));
3377 cricket::AudioOptions options;
3378 options.combined_audio_video_bwe.Set(true);
3379 EXPECT_TRUE(media_channel->SetOptions(options));
3380
3381 static const uint32 kSsrcs[] = {1, 2, 3, 4};
3382 int voe_channels[ARRAY_SIZE(kSsrcs)] = {0};
3383 for (unsigned int i = 0; i < ARRAY_SIZE(kSsrcs); ++i) {
3384 EXPECT_TRUE(media_channel->AddRecvStream(
3385 cricket::StreamParams::CreateLegacy(kSsrcs[i])));
3386 int recv_ch = media_channel->GetReceiveChannelNum(kSsrcs[i]);
3387 EXPECT_NE(-1, recv_ch);
3388 voe_channels[i] = recv_ch;
3389 EXPECT_EQ(vie.network(), voe_.GetViENetwork(recv_ch));
3390 EXPECT_EQ(kVieCh, voe_.GetVideoChannel(recv_ch));
3391 }
3392
3393 EXPECT_TRUE(media_channel->SetupSharedBandwidthEstimation(NULL, -1));
3394
3395 for (unsigned int i = 0; i < ARRAY_SIZE(voe_channels); ++i) {
3396 EXPECT_EQ(NULL, voe_.GetViENetwork(voe_channels[i]));
3397 EXPECT_EQ(-1, voe_.GetVideoChannel(voe_channels[i]));
3398 }
3399}