blob: 9c1090fa46d6d26f23559ad59364eba32a4bc880 [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);
minyue@webrtc.orgc0bd7be2015-02-18 15:24:13 +00001995 EXPECT_EQ(static_cast<float>(cricket::kNetStats.currentExpandRate) /
1996 (1 << 14), info.receivers[0].expand_rate);
1997 EXPECT_EQ(static_cast<float>(cricket::kNetStats.currentSpeechExpandRate) /
1998 (1 << 14), info.receivers[0].speech_expand_rate);
1999 EXPECT_EQ(static_cast<float>(cricket::kNetStats.currentSecondaryDecodedRate) /
2000 (1 << 14), info.receivers[0].secondary_decoded_rate);
wu@webrtc.org9dba5252013-08-05 20:36:57 +00002001}
2002
wu@webrtc.org9dba5252013-08-05 20:36:57 +00002003// Test that we can add and remove receive streams, and do proper send/playout.
2004// We can receive on multiple streams while sending one stream.
2005TEST_F(WebRtcVoiceEngineTestFake, PlayoutWithMultipleStreams) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002006 EXPECT_TRUE(SetupEngine());
2007 int channel_num1 = voe_.GetLastChannel();
2008
2009 // Start playout on the default channel.
2010 EXPECT_TRUE(channel_->SetOptions(options_conference_));
2011 EXPECT_TRUE(channel_->SetPlayout(true));
2012 EXPECT_TRUE(voe_.GetPlayout(channel_num1));
2013
2014 // Adding another stream should disable playout on the default channel.
2015 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(2)));
2016 int channel_num2 = voe_.GetLastChannel();
2017 std::vector<cricket::AudioCodec> codecs;
2018 codecs.push_back(kPcmuCodec);
2019 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
2020 EXPECT_TRUE(channel_->SetSend(cricket::SEND_MICROPHONE));
2021 EXPECT_TRUE(voe_.GetSend(channel_num1));
2022 EXPECT_FALSE(voe_.GetSend(channel_num2));
2023
2024 // Make sure only the new channel is played out.
2025 EXPECT_FALSE(voe_.GetPlayout(channel_num1));
2026 EXPECT_TRUE(voe_.GetPlayout(channel_num2));
2027
2028 // Adding yet another stream should have stream 2 and 3 enabled for playout.
2029 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(3)));
2030 int channel_num3 = voe_.GetLastChannel();
2031 EXPECT_FALSE(voe_.GetPlayout(channel_num1));
2032 EXPECT_TRUE(voe_.GetPlayout(channel_num2));
2033 EXPECT_TRUE(voe_.GetPlayout(channel_num3));
2034 EXPECT_FALSE(voe_.GetSend(channel_num3));
2035
2036 // Stop sending.
2037 EXPECT_TRUE(channel_->SetSend(cricket::SEND_NOTHING));
2038 EXPECT_FALSE(voe_.GetSend(channel_num1));
2039 EXPECT_FALSE(voe_.GetSend(channel_num2));
2040 EXPECT_FALSE(voe_.GetSend(channel_num3));
2041
2042 // Stop playout.
2043 EXPECT_TRUE(channel_->SetPlayout(false));
2044 EXPECT_FALSE(voe_.GetPlayout(channel_num1));
2045 EXPECT_FALSE(voe_.GetPlayout(channel_num2));
2046 EXPECT_FALSE(voe_.GetPlayout(channel_num3));
2047
2048 // Restart playout and make sure the default channel still is not played out.
2049 EXPECT_TRUE(channel_->SetPlayout(true));
2050 EXPECT_FALSE(voe_.GetPlayout(channel_num1));
2051 EXPECT_TRUE(voe_.GetPlayout(channel_num2));
2052 EXPECT_TRUE(voe_.GetPlayout(channel_num3));
2053
2054 // Now remove the new streams and verify that the default channel is
2055 // played out again.
2056 EXPECT_TRUE(channel_->RemoveRecvStream(3));
2057 EXPECT_TRUE(channel_->RemoveRecvStream(2));
2058
2059 EXPECT_TRUE(voe_.GetPlayout(channel_num1));
2060}
2061
2062// Test that we can set the devices to use.
2063TEST_F(WebRtcVoiceEngineTestFake, SetDevices) {
2064 EXPECT_TRUE(SetupEngine());
2065 int channel_num = voe_.GetLastChannel();
2066 std::vector<cricket::AudioCodec> codecs;
2067 codecs.push_back(kPcmuCodec);
2068 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
2069
2070 cricket::Device default_dev(cricket::kFakeDefaultDeviceName,
2071 cricket::kFakeDefaultDeviceId);
2072 cricket::Device dev(cricket::kFakeDeviceName,
2073 cricket::kFakeDeviceId);
2074
2075 // Test SetDevices() while not sending or playing.
2076 EXPECT_TRUE(engine_.SetDevices(&default_dev, &default_dev));
2077
2078 // Test SetDevices() while sending and playing.
2079 EXPECT_TRUE(engine_.SetLocalMonitor(true));
2080 EXPECT_TRUE(channel_->SetSend(cricket::SEND_MICROPHONE));
2081 EXPECT_TRUE(channel_->SetPlayout(true));
2082 EXPECT_TRUE(voe_.GetRecordingMicrophone());
2083 EXPECT_TRUE(voe_.GetSend(channel_num));
2084 EXPECT_TRUE(voe_.GetPlayout(channel_num));
2085
2086 EXPECT_TRUE(engine_.SetDevices(&dev, &dev));
2087
2088 EXPECT_TRUE(voe_.GetRecordingMicrophone());
2089 EXPECT_TRUE(voe_.GetSend(channel_num));
2090 EXPECT_TRUE(voe_.GetPlayout(channel_num));
2091
2092 // Test that failure to open newly selected devices does not prevent opening
2093 // ones after that.
2094 voe_.set_fail_start_recording_microphone(true);
2095 voe_.set_playout_fail_channel(channel_num);
2096 voe_.set_send_fail_channel(channel_num);
2097
2098 EXPECT_FALSE(engine_.SetDevices(&default_dev, &default_dev));
2099
2100 EXPECT_FALSE(voe_.GetRecordingMicrophone());
2101 EXPECT_FALSE(voe_.GetSend(channel_num));
2102 EXPECT_FALSE(voe_.GetPlayout(channel_num));
2103
2104 voe_.set_fail_start_recording_microphone(false);
2105 voe_.set_playout_fail_channel(-1);
2106 voe_.set_send_fail_channel(-1);
2107
2108 EXPECT_TRUE(engine_.SetDevices(&dev, &dev));
2109
2110 EXPECT_TRUE(voe_.GetRecordingMicrophone());
2111 EXPECT_TRUE(voe_.GetSend(channel_num));
2112 EXPECT_TRUE(voe_.GetPlayout(channel_num));
2113}
2114
2115// Test that we can set the devices to use even if we failed to
2116// open the initial ones.
2117TEST_F(WebRtcVoiceEngineTestFake, SetDevicesWithInitiallyBadDevices) {
2118 EXPECT_TRUE(SetupEngine());
2119 int channel_num = voe_.GetLastChannel();
2120 std::vector<cricket::AudioCodec> codecs;
2121 codecs.push_back(kPcmuCodec);
2122 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
2123
2124 cricket::Device default_dev(cricket::kFakeDefaultDeviceName,
2125 cricket::kFakeDefaultDeviceId);
2126 cricket::Device dev(cricket::kFakeDeviceName,
2127 cricket::kFakeDeviceId);
2128
2129 // Test that failure to open devices selected before starting
2130 // send/play does not prevent opening newly selected ones after that.
2131 voe_.set_fail_start_recording_microphone(true);
2132 voe_.set_playout_fail_channel(channel_num);
2133 voe_.set_send_fail_channel(channel_num);
2134
2135 EXPECT_TRUE(engine_.SetDevices(&default_dev, &default_dev));
2136
2137 EXPECT_FALSE(engine_.SetLocalMonitor(true));
2138 EXPECT_FALSE(channel_->SetSend(cricket::SEND_MICROPHONE));
2139 EXPECT_FALSE(channel_->SetPlayout(true));
2140 EXPECT_FALSE(voe_.GetRecordingMicrophone());
2141 EXPECT_FALSE(voe_.GetSend(channel_num));
2142 EXPECT_FALSE(voe_.GetPlayout(channel_num));
2143
2144 voe_.set_fail_start_recording_microphone(false);
2145 voe_.set_playout_fail_channel(-1);
2146 voe_.set_send_fail_channel(-1);
2147
2148 EXPECT_TRUE(engine_.SetDevices(&dev, &dev));
2149
2150 EXPECT_TRUE(voe_.GetRecordingMicrophone());
2151 EXPECT_TRUE(voe_.GetSend(channel_num));
2152 EXPECT_TRUE(voe_.GetPlayout(channel_num));
2153}
2154
2155// Test that we can create a channel configured for multi-point conferences,
2156// and start sending/playing out on it.
2157TEST_F(WebRtcVoiceEngineTestFake, ConferenceSendAndPlayout) {
2158 EXPECT_TRUE(SetupEngine());
2159 int channel_num = voe_.GetLastChannel();
2160 EXPECT_TRUE(channel_->SetOptions(options_conference_));
2161 std::vector<cricket::AudioCodec> codecs;
2162 codecs.push_back(kPcmuCodec);
2163 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
2164 EXPECT_TRUE(channel_->SetSend(cricket::SEND_MICROPHONE));
2165 EXPECT_TRUE(voe_.GetSend(channel_num));
2166}
2167
2168// Test that we can create a channel configured for Codian bridges,
2169// and start sending/playing out on it.
2170TEST_F(WebRtcVoiceEngineTestFake, CodianSendAndPlayout) {
2171 EXPECT_TRUE(SetupEngine());
2172 int channel_num = voe_.GetLastChannel();
2173 webrtc::AgcConfig agc_config;
2174 EXPECT_EQ(0, voe_.GetAgcConfig(agc_config));
2175 EXPECT_EQ(0, agc_config.targetLeveldBOv);
2176 EXPECT_TRUE(channel_->SetOptions(options_adjust_agc_));
2177 std::vector<cricket::AudioCodec> codecs;
2178 codecs.push_back(kPcmuCodec);
2179 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
2180 EXPECT_TRUE(channel_->SetSend(cricket::SEND_MICROPHONE));
2181 EXPECT_TRUE(voe_.GetSend(channel_num));
2182 EXPECT_EQ(0, voe_.GetAgcConfig(agc_config));
2183 EXPECT_EQ(agc_config.targetLeveldBOv, 10); // level was attenuated
2184 EXPECT_TRUE(channel_->SetPlayout(true));
2185 EXPECT_TRUE(voe_.GetPlayout(channel_num));
2186 EXPECT_TRUE(channel_->SetSend(cricket::SEND_NOTHING));
2187 EXPECT_FALSE(voe_.GetSend(channel_num));
2188 EXPECT_EQ(0, voe_.GetAgcConfig(agc_config));
2189 EXPECT_EQ(0, agc_config.targetLeveldBOv); // level was restored
2190 EXPECT_TRUE(channel_->SetPlayout(false));
2191 EXPECT_FALSE(voe_.GetPlayout(channel_num));
2192}
2193
wu@webrtc.org97077a32013-10-25 21:18:33 +00002194TEST_F(WebRtcVoiceEngineTestFake, TxAgcConfigViaOptions) {
2195 EXPECT_TRUE(SetupEngine());
2196 webrtc::AgcConfig agc_config;
2197 EXPECT_EQ(0, voe_.GetAgcConfig(agc_config));
2198 EXPECT_EQ(0, agc_config.targetLeveldBOv);
2199
2200 cricket::AudioOptions options;
2201 options.tx_agc_target_dbov.Set(3);
2202 options.tx_agc_digital_compression_gain.Set(9);
2203 options.tx_agc_limiter.Set(true);
2204 options.auto_gain_control.Set(true);
2205 EXPECT_TRUE(engine_.SetOptions(options));
2206
2207 EXPECT_EQ(0, voe_.GetAgcConfig(agc_config));
2208 EXPECT_EQ(3, agc_config.targetLeveldBOv);
2209 EXPECT_EQ(9, agc_config.digitalCompressionGaindB);
2210 EXPECT_TRUE(agc_config.limiterEnable);
2211
2212 // Check interaction with adjust_agc_delta. Both should be respected, for
2213 // backwards compatibility.
2214 options.adjust_agc_delta.Set(-10);
2215 EXPECT_TRUE(engine_.SetOptions(options));
2216
2217 EXPECT_EQ(0, voe_.GetAgcConfig(agc_config));
2218 EXPECT_EQ(13, agc_config.targetLeveldBOv);
2219}
2220
2221TEST_F(WebRtcVoiceEngineTestFake, RxAgcConfigViaOptions) {
2222 EXPECT_TRUE(SetupEngine());
2223 int channel_num = voe_.GetLastChannel();
2224 cricket::AudioOptions options;
2225 options.rx_agc_target_dbov.Set(6);
2226 options.rx_agc_digital_compression_gain.Set(0);
2227 options.rx_agc_limiter.Set(true);
2228 options.rx_auto_gain_control.Set(true);
2229 EXPECT_TRUE(channel_->SetOptions(options));
2230
2231 webrtc::AgcConfig agc_config;
2232 EXPECT_EQ(0, engine_.voe()->processing()->GetRxAgcConfig(
2233 channel_num, agc_config));
2234 EXPECT_EQ(6, agc_config.targetLeveldBOv);
2235 EXPECT_EQ(0, agc_config.digitalCompressionGaindB);
2236 EXPECT_TRUE(agc_config.limiterEnable);
2237}
2238
2239TEST_F(WebRtcVoiceEngineTestFake, SampleRatesViaOptions) {
2240 EXPECT_TRUE(SetupEngine());
2241 cricket::AudioOptions options;
2242 options.recording_sample_rate.Set(48000u);
2243 options.playout_sample_rate.Set(44100u);
2244 EXPECT_TRUE(engine_.SetOptions(options));
2245
2246 unsigned int recording_sample_rate, playout_sample_rate;
2247 EXPECT_EQ(0, voe_.RecordingSampleRate(&recording_sample_rate));
2248 EXPECT_EQ(0, voe_.PlayoutSampleRate(&playout_sample_rate));
2249 EXPECT_EQ(48000u, recording_sample_rate);
2250 EXPECT_EQ(44100u, playout_sample_rate);
2251}
2252
2253TEST_F(WebRtcVoiceEngineTestFake, TraceFilterViaTraceOptions) {
2254 EXPECT_TRUE(SetupEngine());
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002255 engine_.SetLogging(rtc::LS_INFO, "");
wu@webrtc.org97077a32013-10-25 21:18:33 +00002256 EXPECT_EQ(
2257 // Info:
2258 webrtc::kTraceStateInfo | webrtc::kTraceInfo |
2259 // Warning:
2260 webrtc::kTraceTerseInfo | webrtc::kTraceWarning |
2261 // Error:
2262 webrtc::kTraceError | webrtc::kTraceCritical,
2263 static_cast<int>(trace_wrapper_->filter_));
2264 // Now set it explicitly
2265 std::string filter =
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002266 "tracefilter " + rtc::ToString(webrtc::kTraceDefault);
2267 engine_.SetLogging(rtc::LS_VERBOSE, filter.c_str());
wu@webrtc.org97077a32013-10-25 21:18:33 +00002268 EXPECT_EQ(static_cast<unsigned int>(webrtc::kTraceDefault),
2269 trace_wrapper_->filter_);
2270}
2271
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002272// Test that we can set the outgoing SSRC properly.
2273// SSRC is set in SetupEngine by calling AddSendStream.
2274TEST_F(WebRtcVoiceEngineTestFake, SetSendSsrc) {
2275 EXPECT_TRUE(SetupEngine());
2276 int channel_num = voe_.GetLastChannel();
2277 unsigned int send_ssrc;
2278 EXPECT_EQ(0, voe_.GetLocalSSRC(channel_num, send_ssrc));
2279 EXPECT_NE(0U, send_ssrc);
2280 EXPECT_EQ(0, voe_.GetLocalSSRC(channel_num, send_ssrc));
2281 EXPECT_EQ(kSsrc1, send_ssrc);
2282}
2283
2284TEST_F(WebRtcVoiceEngineTestFake, GetStats) {
2285 // Setup. We need send codec to be set to get all stats.
2286 EXPECT_TRUE(SetupEngine());
buildbot@webrtc.org7e71b772014-06-13 01:14:01 +00002287 // SetupEngine adds a send stream with kSsrc1, so the receive stream has to
2288 // use a different SSRC.
2289 EXPECT_TRUE(channel_->AddRecvStream(
2290 cricket::StreamParams::CreateLegacy(kSsrc2)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002291 std::vector<cricket::AudioCodec> codecs;
2292 codecs.push_back(kPcmuCodec);
2293 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
buildbot@webrtc.org7e71b772014-06-13 01:14:01 +00002294 EXPECT_TRUE(channel_->SetRecvCodecs(codecs));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002295
2296 cricket::VoiceMediaInfo info;
2297 EXPECT_EQ(true, channel_->GetStats(&info));
2298 EXPECT_EQ(1u, info.senders.size());
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +00002299 EXPECT_EQ(kSsrc1, info.senders[0].ssrc());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002300 EXPECT_EQ(kPcmuCodec.name, info.senders[0].codec_name);
2301 EXPECT_EQ(cricket::kIntStatValue, info.senders[0].bytes_sent);
2302 EXPECT_EQ(cricket::kIntStatValue, info.senders[0].packets_sent);
2303 EXPECT_EQ(cricket::kIntStatValue, info.senders[0].packets_lost);
2304 EXPECT_EQ(cricket::kFractionLostStatValue, info.senders[0].fraction_lost);
2305 EXPECT_EQ(cricket::kIntStatValue, info.senders[0].ext_seqnum);
2306 EXPECT_EQ(cricket::kIntStatValue, info.senders[0].rtt_ms);
2307 EXPECT_EQ(cricket::kIntStatValue, info.senders[0].jitter_ms);
buildbot@webrtc.org7e71b772014-06-13 01:14:01 +00002308 EXPECT_EQ(kPcmuCodec.name, info.senders[0].codec_name);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002309 // TODO(sriniv): Add testing for more fields. These are not populated
2310 // in FakeWebrtcVoiceEngine yet.
2311 // EXPECT_EQ(cricket::kIntStatValue, info.senders[0].audio_level);
2312 // EXPECT_EQ(cricket::kIntStatValue, info.senders[0].echo_delay_median_ms);
2313 // EXPECT_EQ(cricket::kIntStatValue, info.senders[0].echo_delay_std_ms);
2314 // EXPECT_EQ(cricket::kIntStatValue, info.senders[0].echo_return_loss);
2315 // EXPECT_EQ(cricket::kIntStatValue,
2316 // info.senders[0].echo_return_loss_enhancement);
2317
buildbot@webrtc.org7e71b772014-06-13 01:14:01 +00002318 EXPECT_EQ(0u, info.receivers.size());
2319 DeliverPacket(kPcmuFrame, sizeof(kPcmuFrame));
2320 EXPECT_EQ(true, channel_->GetStats(&info));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002321 EXPECT_EQ(1u, info.receivers.size());
buildbot@webrtc.org7e71b772014-06-13 01:14:01 +00002322
2323 EXPECT_EQ(cricket::kIntStatValue, info.receivers[0].bytes_rcvd);
2324 EXPECT_EQ(cricket::kIntStatValue, info.receivers[0].packets_rcvd);
2325 EXPECT_EQ(cricket::kIntStatValue, info.receivers[0].packets_lost);
2326 EXPECT_EQ(cricket::kIntStatValue, info.receivers[0].ext_seqnum);
2327 EXPECT_EQ(kPcmuCodec.name, info.receivers[0].codec_name);
minyue@webrtc.orgc0bd7be2015-02-18 15:24:13 +00002328 EXPECT_EQ(static_cast<float>(cricket::kNetStats.currentExpandRate) /
2329 (1 << 14), info.receivers[0].expand_rate);
2330 EXPECT_EQ(static_cast<float>(cricket::kNetStats.currentSpeechExpandRate) /
2331 (1 << 14), info.receivers[0].speech_expand_rate);
2332 EXPECT_EQ(static_cast<float>(cricket::kNetStats.currentSecondaryDecodedRate) /
2333 (1 << 14), info.receivers[0].secondary_decoded_rate);
buildbot@webrtc.org7e71b772014-06-13 01:14:01 +00002334 // TODO(sriniv): Add testing for more receiver fields.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002335}
2336
2337// Test that we can set the outgoing SSRC properly with multiple streams.
2338// SSRC is set in SetupEngine by calling AddSendStream.
2339TEST_F(WebRtcVoiceEngineTestFake, SetSendSsrcWithMultipleStreams) {
2340 EXPECT_TRUE(SetupEngine());
2341 EXPECT_TRUE(channel_->SetOptions(options_conference_));
2342 int channel_num1 = voe_.GetLastChannel();
2343 unsigned int send_ssrc;
2344 EXPECT_EQ(0, voe_.GetLocalSSRC(channel_num1, send_ssrc));
2345 EXPECT_EQ(kSsrc1, send_ssrc);
2346
2347 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(2)));
2348 int channel_num2 = voe_.GetLastChannel();
2349 EXPECT_EQ(0, voe_.GetLocalSSRC(channel_num2, send_ssrc));
2350 EXPECT_EQ(kSsrc1, send_ssrc);
2351}
2352
2353// Test that the local SSRC is the same on sending and receiving channels if the
2354// receive channel is created before the send channel.
2355TEST_F(WebRtcVoiceEngineTestFake, SetSendSsrcAfterCreatingReceiveChannel) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002356 EXPECT_TRUE(engine_.Init(rtc::Thread::Current()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002357 channel_ = engine_.CreateChannel();
2358 EXPECT_TRUE(channel_->SetOptions(options_conference_));
2359
2360 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(1)));
2361 int receive_channel_num = voe_.GetLastChannel();
2362 EXPECT_TRUE(channel_->AddSendStream(
2363 cricket::StreamParams::CreateLegacy(1234)));
2364 int send_channel_num = voe_.GetLastChannel();
2365
2366 unsigned int ssrc = 0;
2367 EXPECT_EQ(0, voe_.GetLocalSSRC(send_channel_num, ssrc));
2368 EXPECT_EQ(1234U, ssrc);
2369 ssrc = 0;
2370 EXPECT_EQ(0, voe_.GetLocalSSRC(receive_channel_num, ssrc));
2371 EXPECT_EQ(1234U, ssrc);
2372}
2373
2374// Test that we can properly receive packets.
2375TEST_F(WebRtcVoiceEngineTestFake, Recv) {
2376 EXPECT_TRUE(SetupEngine());
2377 int channel_num = voe_.GetLastChannel();
2378 DeliverPacket(kPcmuFrame, sizeof(kPcmuFrame));
2379 EXPECT_TRUE(voe_.CheckPacket(channel_num, kPcmuFrame,
2380 sizeof(kPcmuFrame)));
2381}
2382
2383// Test that we can properly receive packets on multiple streams.
2384TEST_F(WebRtcVoiceEngineTestFake, RecvWithMultipleStreams) {
2385 EXPECT_TRUE(SetupEngine());
2386 EXPECT_TRUE(channel_->SetOptions(options_conference_));
2387 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(1)));
2388 int channel_num1 = voe_.GetLastChannel();
2389 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(2)));
2390 int channel_num2 = voe_.GetLastChannel();
2391 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(3)));
2392 int channel_num3 = voe_.GetLastChannel();
2393 // Create packets with the right SSRCs.
2394 char packets[4][sizeof(kPcmuFrame)];
2395 for (size_t i = 0; i < ARRAY_SIZE(packets); ++i) {
2396 memcpy(packets[i], kPcmuFrame, sizeof(kPcmuFrame));
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002397 rtc::SetBE32(packets[i] + 8, static_cast<uint32>(i));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002398 }
2399 EXPECT_TRUE(voe_.CheckNoPacket(channel_num1));
2400 EXPECT_TRUE(voe_.CheckNoPacket(channel_num2));
2401 EXPECT_TRUE(voe_.CheckNoPacket(channel_num3));
2402 DeliverPacket(packets[0], sizeof(packets[0]));
2403 EXPECT_TRUE(voe_.CheckNoPacket(channel_num1));
2404 EXPECT_TRUE(voe_.CheckNoPacket(channel_num2));
2405 EXPECT_TRUE(voe_.CheckNoPacket(channel_num3));
2406 DeliverPacket(packets[1], sizeof(packets[1]));
2407 EXPECT_TRUE(voe_.CheckPacket(channel_num1, packets[1],
2408 sizeof(packets[1])));
2409 EXPECT_TRUE(voe_.CheckNoPacket(channel_num2));
2410 EXPECT_TRUE(voe_.CheckNoPacket(channel_num3));
2411 DeliverPacket(packets[2], sizeof(packets[2]));
2412 EXPECT_TRUE(voe_.CheckNoPacket(channel_num1));
2413 EXPECT_TRUE(voe_.CheckPacket(channel_num2, packets[2],
2414 sizeof(packets[2])));
2415 EXPECT_TRUE(voe_.CheckNoPacket(channel_num3));
2416 DeliverPacket(packets[3], sizeof(packets[3]));
2417 EXPECT_TRUE(voe_.CheckNoPacket(channel_num1));
2418 EXPECT_TRUE(voe_.CheckNoPacket(channel_num2));
2419 EXPECT_TRUE(voe_.CheckPacket(channel_num3, packets[3],
2420 sizeof(packets[3])));
2421 EXPECT_TRUE(channel_->RemoveRecvStream(3));
2422 EXPECT_TRUE(channel_->RemoveRecvStream(2));
2423 EXPECT_TRUE(channel_->RemoveRecvStream(1));
2424}
2425
2426// Test that we properly handle failures to add a stream.
2427TEST_F(WebRtcVoiceEngineTestFake, AddStreamFail) {
2428 EXPECT_TRUE(SetupEngine());
2429 voe_.set_fail_create_channel(true);
2430 EXPECT_TRUE(channel_->SetOptions(options_conference_));
2431 EXPECT_FALSE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(2)));
2432
2433 // In 1:1 call, we should not try to create a new channel.
2434 cricket::AudioOptions options_no_conference_;
2435 options_no_conference_.conference_mode.Set(false);
2436 EXPECT_TRUE(channel_->SetOptions(options_no_conference_));
2437 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(2)));
2438}
2439
2440// Test that AddRecvStream doesn't create new channel for 1:1 call.
2441TEST_F(WebRtcVoiceEngineTestFake, AddRecvStream1On1) {
2442 EXPECT_TRUE(SetupEngine());
2443 int channel_num = voe_.GetLastChannel();
2444 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(1)));
2445 EXPECT_EQ(channel_num, voe_.GetLastChannel());
2446}
2447
2448// Test that after adding a recv stream, we do not decode more codecs than
2449// those previously passed into SetRecvCodecs.
2450TEST_F(WebRtcVoiceEngineTestFake, AddRecvStreamUnsupportedCodec) {
2451 EXPECT_TRUE(SetupEngine());
2452 EXPECT_TRUE(channel_->SetOptions(options_conference_));
2453 std::vector<cricket::AudioCodec> codecs;
2454 codecs.push_back(kIsacCodec);
2455 codecs.push_back(kPcmuCodec);
2456 EXPECT_TRUE(channel_->SetRecvCodecs(codecs));
2457 EXPECT_TRUE(channel_->AddRecvStream(
2458 cricket::StreamParams::CreateLegacy(kSsrc1)));
2459 int channel_num2 = voe_.GetLastChannel();
2460 webrtc::CodecInst gcodec;
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +00002461 rtc::strcpyn(gcodec.plname, ARRAY_SIZE(gcodec.plname), "opus");
2462 gcodec.plfreq = 48000;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002463 gcodec.channels = 2;
2464 EXPECT_EQ(-1, voe_.GetRecPayloadType(channel_num2, gcodec));
2465}
2466
2467// Test that we properly clean up any streams that were added, even if
2468// not explicitly removed.
2469TEST_F(WebRtcVoiceEngineTestFake, StreamCleanup) {
2470 EXPECT_TRUE(SetupEngine());
2471 EXPECT_TRUE(channel_->SetOptions(options_conference_));
2472 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(1)));
2473 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(2)));
2474 EXPECT_EQ(3, voe_.GetNumChannels()); // default channel + 2 added
2475 delete channel_;
2476 channel_ = NULL;
2477 EXPECT_EQ(0, voe_.GetNumChannels());
2478}
2479
wu@webrtc.org78187522013-10-07 23:32:02 +00002480TEST_F(WebRtcVoiceEngineTestFake, TestAddRecvStreamFailWithZeroSsrc) {
2481 EXPECT_TRUE(SetupEngine());
2482 EXPECT_FALSE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(0)));
2483}
2484
2485TEST_F(WebRtcVoiceEngineTestFake, TestNoLeakingWhenAddRecvStreamFail) {
2486 EXPECT_TRUE(SetupEngine());
2487 // Stream 1 reuses default channel.
2488 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(1)));
2489 // Manually delete default channel to simulate a failure.
2490 int default_channel = voe_.GetLastChannel();
2491 EXPECT_EQ(0, voe_.DeleteChannel(default_channel));
2492 // Add recv stream 2 should fail because default channel is gone.
2493 EXPECT_FALSE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(2)));
2494 int new_channel = voe_.GetLastChannel();
2495 EXPECT_NE(default_channel, new_channel);
2496 // The last created channel should have already been deleted.
2497 EXPECT_EQ(-1, voe_.DeleteChannel(new_channel));
2498}
2499
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002500// Test the InsertDtmf on default send stream as caller.
2501TEST_F(WebRtcVoiceEngineTestFake, InsertDtmfOnDefaultSendStreamAsCaller) {
2502 TestInsertDtmf(0, true);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002503}
2504
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002505// Test the InsertDtmf on default send stream as callee
2506TEST_F(WebRtcVoiceEngineTestFake, InsertDtmfOnDefaultSendStreamAsCallee) {
2507 TestInsertDtmf(0, false);
2508}
2509
2510// Test the InsertDtmf on specified send stream as caller.
2511TEST_F(WebRtcVoiceEngineTestFake, InsertDtmfOnSendStreamAsCaller) {
2512 TestInsertDtmf(kSsrc1, true);
2513}
2514
2515// Test the InsertDtmf on specified send stream as callee.
2516TEST_F(WebRtcVoiceEngineTestFake, InsertDtmfOnSendStreamAsCallee) {
2517 TestInsertDtmf(kSsrc1, false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002518}
2519
2520// Test that we can play a ringback tone properly in a single-stream call.
2521TEST_F(WebRtcVoiceEngineTestFake, PlayRingback) {
2522 EXPECT_TRUE(SetupEngine());
2523 int channel_num = voe_.GetLastChannel();
2524 EXPECT_EQ(0, voe_.IsPlayingFileLocally(channel_num));
2525 // Check we fail if no ringback tone specified.
2526 EXPECT_FALSE(channel_->PlayRingbackTone(0, true, true));
2527 EXPECT_EQ(0, voe_.IsPlayingFileLocally(channel_num));
2528 // Check we can set and play a ringback tone.
wu@webrtc.org9caf2762013-12-11 18:25:07 +00002529 EXPECT_TRUE(channel_->SetRingbackTone(
2530 kRingbackTone, static_cast<int>(strlen(kRingbackTone))));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002531 EXPECT_TRUE(channel_->PlayRingbackTone(0, true, true));
2532 EXPECT_EQ(1, voe_.IsPlayingFileLocally(channel_num));
2533 // Check we can stop the tone manually.
2534 EXPECT_TRUE(channel_->PlayRingbackTone(0, false, false));
2535 EXPECT_EQ(0, voe_.IsPlayingFileLocally(channel_num));
2536 // Check we stop the tone if a packet arrives.
2537 EXPECT_TRUE(channel_->PlayRingbackTone(0, true, true));
2538 EXPECT_EQ(1, voe_.IsPlayingFileLocally(channel_num));
2539 DeliverPacket(kPcmuFrame, sizeof(kPcmuFrame));
2540 EXPECT_EQ(0, voe_.IsPlayingFileLocally(channel_num));
2541}
2542
2543// Test that we can play a ringback tone properly in a multi-stream call.
2544TEST_F(WebRtcVoiceEngineTestFake, PlayRingbackWithMultipleStreams) {
2545 EXPECT_TRUE(SetupEngine());
2546 EXPECT_TRUE(channel_->SetOptions(options_conference_));
2547 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(1)));
2548 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(2)));
2549 int channel_num = voe_.GetLastChannel();
2550 EXPECT_EQ(0, voe_.IsPlayingFileLocally(channel_num));
2551 // Check we fail if no ringback tone specified.
2552 EXPECT_FALSE(channel_->PlayRingbackTone(2, true, true));
2553 EXPECT_EQ(0, voe_.IsPlayingFileLocally(channel_num));
2554 // Check we can set and play a ringback tone on the correct ssrc.
wu@webrtc.org9caf2762013-12-11 18:25:07 +00002555 EXPECT_TRUE(channel_->SetRingbackTone(
2556 kRingbackTone, static_cast<int>(strlen(kRingbackTone))));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002557 EXPECT_FALSE(channel_->PlayRingbackTone(77, true, true));
2558 EXPECT_TRUE(channel_->PlayRingbackTone(2, true, true));
2559 EXPECT_EQ(1, voe_.IsPlayingFileLocally(channel_num));
2560 // Check we can stop the tone manually.
2561 EXPECT_TRUE(channel_->PlayRingbackTone(2, false, false));
2562 EXPECT_EQ(0, voe_.IsPlayingFileLocally(channel_num));
2563 // Check we stop the tone if a packet arrives, but only with the right SSRC.
2564 EXPECT_TRUE(channel_->PlayRingbackTone(2, true, true));
2565 EXPECT_EQ(1, voe_.IsPlayingFileLocally(channel_num));
2566 // Send a packet with SSRC 1; the tone should not stop.
2567 DeliverPacket(kPcmuFrame, sizeof(kPcmuFrame));
2568 EXPECT_EQ(1, voe_.IsPlayingFileLocally(channel_num));
2569 // Send a packet with SSRC 2; the tone should stop.
2570 char packet[sizeof(kPcmuFrame)];
2571 memcpy(packet, kPcmuFrame, sizeof(kPcmuFrame));
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002572 rtc::SetBE32(packet + 8, 2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002573 DeliverPacket(packet, sizeof(packet));
2574 EXPECT_EQ(0, voe_.IsPlayingFileLocally(channel_num));
2575}
2576
2577// Tests creating soundclips, and make sure they come from the right engine.
2578TEST_F(WebRtcVoiceEngineTestFake, CreateSoundclip) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002579 EXPECT_TRUE(engine_.Init(rtc::Thread::Current()));
wu@webrtc.org4551b792013-10-09 15:37:36 +00002580 EXPECT_FALSE(voe_sc_.IsInited());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002581 soundclip_ = engine_.CreateSoundclip();
wu@webrtc.org4551b792013-10-09 15:37:36 +00002582 EXPECT_TRUE(voe_sc_.IsInited());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002583 ASSERT_TRUE(soundclip_ != NULL);
2584 EXPECT_EQ(0, voe_.GetNumChannels());
2585 EXPECT_EQ(1, voe_sc_.GetNumChannels());
2586 int channel_num = voe_sc_.GetLastChannel();
2587 EXPECT_TRUE(voe_sc_.GetPlayout(channel_num));
2588 delete soundclip_;
2589 soundclip_ = NULL;
2590 EXPECT_EQ(0, voe_sc_.GetNumChannels());
wu@webrtc.org4551b792013-10-09 15:37:36 +00002591 // Make sure the soundclip engine is uninitialized on shutdown, now that
2592 // we've initialized it by creating a soundclip.
2593 engine_.Terminate();
2594 EXPECT_FALSE(voe_sc_.IsInited());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002595}
2596
2597// Tests playing out a fake sound.
2598TEST_F(WebRtcVoiceEngineTestFake, PlaySoundclip) {
2599 static const char kZeroes[16000] = {};
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002600 EXPECT_TRUE(engine_.Init(rtc::Thread::Current()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002601 soundclip_ = engine_.CreateSoundclip();
2602 ASSERT_TRUE(soundclip_ != NULL);
2603 EXPECT_TRUE(soundclip_->PlaySound(kZeroes, sizeof(kZeroes), 0));
2604}
2605
2606TEST_F(WebRtcVoiceEngineTestFake, MediaEngineCallbackOnError) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002607 rtc::scoped_ptr<ChannelErrorListener> listener;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002608 cricket::WebRtcVoiceMediaChannel* media_channel;
2609 unsigned int ssrc = 0;
2610
2611 EXPECT_TRUE(SetupEngine());
2612 EXPECT_TRUE(channel_->SetOptions(options_conference_));
2613 EXPECT_TRUE(channel_->SetSend(cricket::SEND_MICROPHONE));
2614
2615 media_channel = static_cast<cricket::WebRtcVoiceMediaChannel*>(channel_);
2616 listener.reset(new ChannelErrorListener(channel_));
2617
2618 // Test on WebRtc VoE channel.
2619 voe_.TriggerCallbackOnError(media_channel->voe_channel(),
2620 VE_SATURATION_WARNING);
2621 EXPECT_EQ(cricket::VoiceMediaChannel::ERROR_REC_DEVICE_SATURATION,
2622 listener->error());
2623 EXPECT_NE(-1, voe_.GetLocalSSRC(voe_.GetLastChannel(), ssrc));
2624 EXPECT_EQ(ssrc, listener->ssrc());
2625
2626 listener->Reset();
2627 voe_.TriggerCallbackOnError(-1, VE_TYPING_NOISE_WARNING);
2628 EXPECT_EQ(cricket::VoiceMediaChannel::ERROR_REC_TYPING_NOISE_DETECTED,
2629 listener->error());
2630 EXPECT_EQ(0U, listener->ssrc());
2631
2632 // Add another stream and test on that.
2633 ++ssrc;
2634 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(
2635 ssrc)));
2636 listener->Reset();
2637 voe_.TriggerCallbackOnError(voe_.GetLastChannel(),
2638 VE_SATURATION_WARNING);
2639 EXPECT_EQ(cricket::VoiceMediaChannel::ERROR_REC_DEVICE_SATURATION,
2640 listener->error());
2641 EXPECT_EQ(ssrc, listener->ssrc());
2642
2643 // Testing a non-existing channel.
2644 listener->Reset();
2645 voe_.TriggerCallbackOnError(voe_.GetLastChannel() + 2,
2646 VE_SATURATION_WARNING);
2647 EXPECT_EQ(0, listener->error());
2648}
2649
2650TEST_F(WebRtcVoiceEngineTestFake, TestSetPlayoutError) {
2651 EXPECT_TRUE(SetupEngine());
2652 EXPECT_TRUE(channel_->SetOptions(options_conference_));
2653 std::vector<cricket::AudioCodec> codecs;
2654 codecs.push_back(kPcmuCodec);
2655 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
2656 EXPECT_TRUE(channel_->SetSend(cricket::SEND_MICROPHONE));
2657 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(2)));
2658 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(3)));
2659 EXPECT_TRUE(channel_->SetPlayout(true));
2660 voe_.set_playout_fail_channel(voe_.GetLastChannel() - 1);
2661 EXPECT_TRUE(channel_->SetPlayout(false));
2662 EXPECT_FALSE(channel_->SetPlayout(true));
2663}
2664
2665// Test that the Registering/Unregistering with the
2666// webrtcvoiceengine works as expected
2667TEST_F(WebRtcVoiceEngineTestFake, RegisterVoiceProcessor) {
2668 EXPECT_TRUE(SetupEngine());
2669 EXPECT_TRUE(channel_->SetOptions(options_conference_));
2670 EXPECT_TRUE(channel_->AddRecvStream(
2671 cricket::StreamParams::CreateLegacy(kSsrc2)));
2672 cricket::FakeMediaProcessor vp_1;
2673 cricket::FakeMediaProcessor vp_2;
2674
2675 EXPECT_FALSE(engine_.RegisterProcessor(kSsrc2, &vp_1, cricket::MPD_TX));
2676 EXPECT_TRUE(engine_.RegisterProcessor(kSsrc2, &vp_1, cricket::MPD_RX));
2677 EXPECT_TRUE(engine_.RegisterProcessor(kSsrc2, &vp_2, cricket::MPD_RX));
2678 voe_.TriggerProcessPacket(cricket::MPD_RX);
2679 voe_.TriggerProcessPacket(cricket::MPD_TX);
2680
2681 EXPECT_TRUE(voe_.IsExternalMediaProcessorRegistered());
2682 EXPECT_EQ(1, vp_1.voice_frame_count());
2683 EXPECT_EQ(1, vp_2.voice_frame_count());
2684
2685 EXPECT_TRUE(engine_.UnregisterProcessor(kSsrc2,
2686 &vp_2,
2687 cricket::MPD_RX));
2688 voe_.TriggerProcessPacket(cricket::MPD_RX);
2689 EXPECT_TRUE(voe_.IsExternalMediaProcessorRegistered());
2690 EXPECT_EQ(1, vp_2.voice_frame_count());
2691 EXPECT_EQ(2, vp_1.voice_frame_count());
2692
2693 EXPECT_TRUE(engine_.UnregisterProcessor(kSsrc2,
2694 &vp_1,
2695 cricket::MPD_RX));
2696 voe_.TriggerProcessPacket(cricket::MPD_RX);
2697 EXPECT_FALSE(voe_.IsExternalMediaProcessorRegistered());
2698 EXPECT_EQ(2, vp_1.voice_frame_count());
2699
2700 EXPECT_FALSE(engine_.RegisterProcessor(kSsrc1, &vp_1, cricket::MPD_RX));
2701 EXPECT_TRUE(engine_.RegisterProcessor(kSsrc1, &vp_1, cricket::MPD_TX));
2702 voe_.TriggerProcessPacket(cricket::MPD_RX);
2703 voe_.TriggerProcessPacket(cricket::MPD_TX);
2704 EXPECT_TRUE(voe_.IsExternalMediaProcessorRegistered());
2705 EXPECT_EQ(3, vp_1.voice_frame_count());
2706
2707 EXPECT_TRUE(engine_.UnregisterProcessor(kSsrc1,
2708 &vp_1,
2709 cricket::MPD_RX_AND_TX));
2710 voe_.TriggerProcessPacket(cricket::MPD_TX);
2711 EXPECT_FALSE(voe_.IsExternalMediaProcessorRegistered());
2712 EXPECT_EQ(3, vp_1.voice_frame_count());
2713 EXPECT_TRUE(channel_->RemoveRecvStream(kSsrc2));
2714 EXPECT_FALSE(engine_.RegisterProcessor(kSsrc2, &vp_1, cricket::MPD_RX));
2715 EXPECT_FALSE(voe_.IsExternalMediaProcessorRegistered());
2716
2717 // Test that we can register a processor on the receive channel on SSRC 0.
2718 // This tests the 1:1 case when the receive SSRC is unknown.
2719 EXPECT_TRUE(engine_.RegisterProcessor(0, &vp_1, cricket::MPD_RX));
2720 voe_.TriggerProcessPacket(cricket::MPD_RX);
2721 EXPECT_TRUE(voe_.IsExternalMediaProcessorRegistered());
2722 EXPECT_EQ(4, vp_1.voice_frame_count());
2723 EXPECT_TRUE(engine_.UnregisterProcessor(0,
2724 &vp_1,
2725 cricket::MPD_RX));
2726
2727 // The following tests test that FindChannelNumFromSsrc is doing
2728 // what we expect.
2729 // pick an invalid ssrc and make sure we can't register
2730 EXPECT_FALSE(engine_.RegisterProcessor(99,
2731 &vp_1,
2732 cricket::MPD_RX));
2733 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(1)));
2734 EXPECT_TRUE(engine_.RegisterProcessor(1,
2735 &vp_1,
2736 cricket::MPD_RX));
2737 EXPECT_TRUE(engine_.UnregisterProcessor(1,
2738 &vp_1,
2739 cricket::MPD_RX));
2740 EXPECT_FALSE(engine_.RegisterProcessor(1,
2741 &vp_1,
2742 cricket::MPD_TX));
2743 EXPECT_TRUE(channel_->RemoveRecvStream(1));
2744}
2745
2746TEST_F(WebRtcVoiceEngineTestFake, SetAudioOptions) {
2747 EXPECT_TRUE(SetupEngine());
2748
2749 bool ec_enabled;
2750 webrtc::EcModes ec_mode;
2751 bool ec_metrics_enabled;
2752 webrtc::AecmModes aecm_mode;
2753 bool cng_enabled;
2754 bool agc_enabled;
2755 webrtc::AgcModes agc_mode;
2756 webrtc::AgcConfig agc_config;
2757 bool ns_enabled;
2758 webrtc::NsModes ns_mode;
2759 bool highpass_filter_enabled;
2760 bool stereo_swapping_enabled;
2761 bool typing_detection_enabled;
2762 voe_.GetEcStatus(ec_enabled, ec_mode);
2763 voe_.GetEcMetricsStatus(ec_metrics_enabled);
2764 voe_.GetAecmMode(aecm_mode, cng_enabled);
2765 voe_.GetAgcStatus(agc_enabled, agc_mode);
2766 voe_.GetAgcConfig(agc_config);
2767 voe_.GetNsStatus(ns_enabled, ns_mode);
2768 highpass_filter_enabled = voe_.IsHighPassFilterEnabled();
2769 stereo_swapping_enabled = voe_.IsStereoChannelSwappingEnabled();
2770 voe_.GetTypingDetectionStatus(typing_detection_enabled);
2771 EXPECT_TRUE(ec_enabled);
2772 EXPECT_TRUE(ec_metrics_enabled);
2773 EXPECT_FALSE(cng_enabled);
2774 EXPECT_TRUE(agc_enabled);
2775 EXPECT_EQ(0, agc_config.targetLeveldBOv);
2776 EXPECT_TRUE(ns_enabled);
2777 EXPECT_TRUE(highpass_filter_enabled);
2778 EXPECT_FALSE(stereo_swapping_enabled);
2779 EXPECT_TRUE(typing_detection_enabled);
2780 EXPECT_EQ(ec_mode, webrtc::kEcConference);
2781 EXPECT_EQ(ns_mode, webrtc::kNsHighSuppression);
2782
2783 // Nothing set, so all ignored.
2784 cricket::AudioOptions options;
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00002785 ASSERT_TRUE(engine_.SetOptions(options));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002786 voe_.GetEcStatus(ec_enabled, ec_mode);
2787 voe_.GetEcMetricsStatus(ec_metrics_enabled);
2788 voe_.GetAecmMode(aecm_mode, cng_enabled);
2789 voe_.GetAgcStatus(agc_enabled, agc_mode);
2790 voe_.GetAgcConfig(agc_config);
2791 voe_.GetNsStatus(ns_enabled, ns_mode);
2792 highpass_filter_enabled = voe_.IsHighPassFilterEnabled();
2793 stereo_swapping_enabled = voe_.IsStereoChannelSwappingEnabled();
2794 voe_.GetTypingDetectionStatus(typing_detection_enabled);
2795 EXPECT_TRUE(ec_enabled);
2796 EXPECT_TRUE(ec_metrics_enabled);
2797 EXPECT_FALSE(cng_enabled);
2798 EXPECT_TRUE(agc_enabled);
2799 EXPECT_EQ(0, agc_config.targetLeveldBOv);
2800 EXPECT_TRUE(ns_enabled);
2801 EXPECT_TRUE(highpass_filter_enabled);
2802 EXPECT_FALSE(stereo_swapping_enabled);
2803 EXPECT_TRUE(typing_detection_enabled);
2804 EXPECT_EQ(ec_mode, webrtc::kEcConference);
2805 EXPECT_EQ(ns_mode, webrtc::kNsHighSuppression);
2806
2807 // Turn echo cancellation off
2808 options.echo_cancellation.Set(false);
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00002809 ASSERT_TRUE(engine_.SetOptions(options));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002810 voe_.GetEcStatus(ec_enabled, ec_mode);
2811 EXPECT_FALSE(ec_enabled);
2812
2813 // Turn echo cancellation back on, with settings, and make sure
2814 // nothing else changed.
2815 options.echo_cancellation.Set(true);
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00002816 ASSERT_TRUE(engine_.SetOptions(options));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002817 voe_.GetEcStatus(ec_enabled, ec_mode);
2818 voe_.GetEcMetricsStatus(ec_metrics_enabled);
2819 voe_.GetAecmMode(aecm_mode, cng_enabled);
2820 voe_.GetAgcStatus(agc_enabled, agc_mode);
2821 voe_.GetAgcConfig(agc_config);
2822 voe_.GetNsStatus(ns_enabled, ns_mode);
2823 highpass_filter_enabled = voe_.IsHighPassFilterEnabled();
2824 stereo_swapping_enabled = voe_.IsStereoChannelSwappingEnabled();
2825 voe_.GetTypingDetectionStatus(typing_detection_enabled);
2826 EXPECT_TRUE(ec_enabled);
2827 EXPECT_TRUE(ec_metrics_enabled);
2828 EXPECT_TRUE(agc_enabled);
2829 EXPECT_EQ(0, agc_config.targetLeveldBOv);
2830 EXPECT_TRUE(ns_enabled);
2831 EXPECT_TRUE(highpass_filter_enabled);
2832 EXPECT_FALSE(stereo_swapping_enabled);
2833 EXPECT_TRUE(typing_detection_enabled);
2834 EXPECT_EQ(ec_mode, webrtc::kEcConference);
2835 EXPECT_EQ(ns_mode, webrtc::kNsHighSuppression);
2836
Bjorn Volckerbf395c12015-03-25 22:45:56 +01002837 // Turn on delay agnostic aec and make sure nothing change w.r.t. echo
2838 // control.
2839 options.delay_agnostic_aec.Set(true);
2840 ASSERT_TRUE(engine_.SetOptions(options));
2841 voe_.GetEcStatus(ec_enabled, ec_mode);
2842 voe_.GetEcMetricsStatus(ec_metrics_enabled);
2843 voe_.GetAecmMode(aecm_mode, cng_enabled);
2844 EXPECT_TRUE(ec_enabled);
2845 EXPECT_TRUE(ec_metrics_enabled);
2846 EXPECT_EQ(ec_mode, webrtc::kEcConference);
2847
2848 // Turn off echo cancellation and delay agnostic aec.
2849 options.delay_agnostic_aec.Set(false);
2850 options.experimental_aec.Set(false);
2851 options.echo_cancellation.Set(false);
2852 ASSERT_TRUE(engine_.SetOptions(options));
2853 voe_.GetEcStatus(ec_enabled, ec_mode);
2854 EXPECT_FALSE(ec_enabled);
2855 // Turning delay agnostic aec back on should also turn on echo cancellation.
2856 options.delay_agnostic_aec.Set(true);
2857 ASSERT_TRUE(engine_.SetOptions(options));
2858 voe_.GetEcStatus(ec_enabled, ec_mode);
2859 voe_.GetEcMetricsStatus(ec_metrics_enabled);
2860 EXPECT_TRUE(ec_enabled);
2861 EXPECT_TRUE(ec_metrics_enabled);
2862 EXPECT_EQ(ec_mode, webrtc::kEcConference);
2863
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002864 // Turn off AGC
2865 options.auto_gain_control.Set(false);
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00002866 ASSERT_TRUE(engine_.SetOptions(options));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002867 voe_.GetAgcStatus(agc_enabled, agc_mode);
2868 EXPECT_FALSE(agc_enabled);
2869
2870 // Turn AGC back on
2871 options.auto_gain_control.Set(true);
2872 options.adjust_agc_delta.Clear();
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00002873 ASSERT_TRUE(engine_.SetOptions(options));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002874 voe_.GetAgcStatus(agc_enabled, agc_mode);
2875 EXPECT_TRUE(agc_enabled);
2876 voe_.GetAgcConfig(agc_config);
2877 EXPECT_EQ(0, agc_config.targetLeveldBOv);
2878
2879 // Turn off other options (and stereo swapping on).
2880 options.noise_suppression.Set(false);
2881 options.highpass_filter.Set(false);
2882 options.typing_detection.Set(false);
2883 options.stereo_swapping.Set(true);
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00002884 ASSERT_TRUE(engine_.SetOptions(options));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002885 voe_.GetNsStatus(ns_enabled, ns_mode);
2886 highpass_filter_enabled = voe_.IsHighPassFilterEnabled();
2887 stereo_swapping_enabled = voe_.IsStereoChannelSwappingEnabled();
2888 voe_.GetTypingDetectionStatus(typing_detection_enabled);
2889 EXPECT_FALSE(ns_enabled);
2890 EXPECT_FALSE(highpass_filter_enabled);
2891 EXPECT_FALSE(typing_detection_enabled);
2892 EXPECT_TRUE(stereo_swapping_enabled);
2893
2894 // Turn on "conference mode" to ensure it has no impact.
2895 options.conference_mode.Set(true);
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00002896 ASSERT_TRUE(engine_.SetOptions(options));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002897 voe_.GetEcStatus(ec_enabled, ec_mode);
2898 voe_.GetNsStatus(ns_enabled, ns_mode);
2899 EXPECT_TRUE(ec_enabled);
2900 EXPECT_EQ(webrtc::kEcConference, ec_mode);
2901 EXPECT_FALSE(ns_enabled);
2902 EXPECT_EQ(webrtc::kNsHighSuppression, ns_mode);
2903}
2904
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00002905TEST_F(WebRtcVoiceEngineTestFake, DefaultOptions) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002906 EXPECT_TRUE(SetupEngine());
2907
2908 bool ec_enabled;
2909 webrtc::EcModes ec_mode;
2910 bool ec_metrics_enabled;
2911 bool agc_enabled;
2912 webrtc::AgcModes agc_mode;
2913 bool ns_enabled;
2914 webrtc::NsModes ns_mode;
2915 bool highpass_filter_enabled;
2916 bool stereo_swapping_enabled;
2917 bool typing_detection_enabled;
2918
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002919 voe_.GetEcStatus(ec_enabled, ec_mode);
2920 voe_.GetEcMetricsStatus(ec_metrics_enabled);
2921 voe_.GetAgcStatus(agc_enabled, agc_mode);
2922 voe_.GetNsStatus(ns_enabled, ns_mode);
2923 highpass_filter_enabled = voe_.IsHighPassFilterEnabled();
2924 stereo_swapping_enabled = voe_.IsStereoChannelSwappingEnabled();
2925 voe_.GetTypingDetectionStatus(typing_detection_enabled);
2926 EXPECT_TRUE(ec_enabled);
2927 EXPECT_TRUE(agc_enabled);
2928 EXPECT_TRUE(ns_enabled);
2929 EXPECT_TRUE(highpass_filter_enabled);
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00002930 EXPECT_TRUE(typing_detection_enabled);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002931 EXPECT_FALSE(stereo_swapping_enabled);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002932}
2933
2934TEST_F(WebRtcVoiceEngineTestFake, InitDoesNotOverwriteDefaultAgcConfig) {
2935 webrtc::AgcConfig set_config = {0};
2936 set_config.targetLeveldBOv = 3;
2937 set_config.digitalCompressionGaindB = 9;
2938 set_config.limiterEnable = true;
2939 EXPECT_EQ(0, voe_.SetAgcConfig(set_config));
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002940 EXPECT_TRUE(engine_.Init(rtc::Thread::Current()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002941
2942 webrtc::AgcConfig config = {0};
2943 EXPECT_EQ(0, voe_.GetAgcConfig(config));
2944 EXPECT_EQ(set_config.targetLeveldBOv, config.targetLeveldBOv);
2945 EXPECT_EQ(set_config.digitalCompressionGaindB,
2946 config.digitalCompressionGaindB);
2947 EXPECT_EQ(set_config.limiterEnable, config.limiterEnable);
2948}
2949
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002950TEST_F(WebRtcVoiceEngineTestFake, SetOptionOverridesViaChannels) {
2951 EXPECT_TRUE(SetupEngine());
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002952 rtc::scoped_ptr<cricket::VoiceMediaChannel> channel1(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002953 engine_.CreateChannel());
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002954 rtc::scoped_ptr<cricket::VoiceMediaChannel> channel2(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002955 engine_.CreateChannel());
2956
2957 // Have to add a stream to make SetSend work.
2958 cricket::StreamParams stream1;
2959 stream1.ssrcs.push_back(1);
2960 channel1->AddSendStream(stream1);
2961 cricket::StreamParams stream2;
2962 stream2.ssrcs.push_back(2);
2963 channel2->AddSendStream(stream2);
2964
2965 // AEC and AGC and NS
2966 cricket::AudioOptions options_all;
2967 options_all.echo_cancellation.Set(true);
2968 options_all.auto_gain_control.Set(true);
2969 options_all.noise_suppression.Set(true);
2970
2971 ASSERT_TRUE(channel1->SetOptions(options_all));
2972 cricket::AudioOptions expected_options = options_all;
2973 cricket::AudioOptions actual_options;
2974 ASSERT_TRUE(channel1->GetOptions(&actual_options));
2975 EXPECT_EQ(expected_options, actual_options);
2976 ASSERT_TRUE(channel2->SetOptions(options_all));
2977 ASSERT_TRUE(channel2->GetOptions(&actual_options));
2978 EXPECT_EQ(expected_options, actual_options);
2979
2980 // unset NS
2981 cricket::AudioOptions options_no_ns;
2982 options_no_ns.noise_suppression.Set(false);
2983 ASSERT_TRUE(channel1->SetOptions(options_no_ns));
2984
2985 expected_options.echo_cancellation.Set(true);
2986 expected_options.auto_gain_control.Set(true);
2987 expected_options.noise_suppression.Set(false);
2988 ASSERT_TRUE(channel1->GetOptions(&actual_options));
2989 EXPECT_EQ(expected_options, actual_options);
2990
2991 // unset AGC
2992 cricket::AudioOptions options_no_agc;
2993 options_no_agc.auto_gain_control.Set(false);
2994 ASSERT_TRUE(channel2->SetOptions(options_no_agc));
2995
2996 expected_options.echo_cancellation.Set(true);
2997 expected_options.auto_gain_control.Set(false);
2998 expected_options.noise_suppression.Set(true);
2999 ASSERT_TRUE(channel2->GetOptions(&actual_options));
3000 EXPECT_EQ(expected_options, actual_options);
3001
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00003002 ASSERT_TRUE(engine_.SetOptions(options_all));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003003 bool ec_enabled;
3004 webrtc::EcModes ec_mode;
3005 bool agc_enabled;
3006 webrtc::AgcModes agc_mode;
3007 bool ns_enabled;
3008 webrtc::NsModes ns_mode;
3009 voe_.GetEcStatus(ec_enabled, ec_mode);
3010 voe_.GetAgcStatus(agc_enabled, agc_mode);
3011 voe_.GetNsStatus(ns_enabled, ns_mode);
3012 EXPECT_TRUE(ec_enabled);
3013 EXPECT_TRUE(agc_enabled);
3014 EXPECT_TRUE(ns_enabled);
3015
3016 channel1->SetSend(cricket::SEND_MICROPHONE);
3017 voe_.GetEcStatus(ec_enabled, ec_mode);
3018 voe_.GetAgcStatus(agc_enabled, agc_mode);
3019 voe_.GetNsStatus(ns_enabled, ns_mode);
3020 EXPECT_TRUE(ec_enabled);
3021 EXPECT_TRUE(agc_enabled);
3022 EXPECT_FALSE(ns_enabled);
3023
3024 channel1->SetSend(cricket::SEND_NOTHING);
3025 voe_.GetEcStatus(ec_enabled, ec_mode);
3026 voe_.GetAgcStatus(agc_enabled, agc_mode);
3027 voe_.GetNsStatus(ns_enabled, ns_mode);
3028 EXPECT_TRUE(ec_enabled);
3029 EXPECT_TRUE(agc_enabled);
3030 EXPECT_TRUE(ns_enabled);
3031
3032 channel2->SetSend(cricket::SEND_MICROPHONE);
3033 voe_.GetEcStatus(ec_enabled, ec_mode);
3034 voe_.GetAgcStatus(agc_enabled, agc_mode);
3035 voe_.GetNsStatus(ns_enabled, ns_mode);
3036 EXPECT_TRUE(ec_enabled);
3037 EXPECT_FALSE(agc_enabled);
3038 EXPECT_TRUE(ns_enabled);
3039
3040 channel2->SetSend(cricket::SEND_NOTHING);
3041 voe_.GetEcStatus(ec_enabled, ec_mode);
3042 voe_.GetAgcStatus(agc_enabled, agc_mode);
3043 voe_.GetNsStatus(ns_enabled, ns_mode);
3044 EXPECT_TRUE(ec_enabled);
3045 EXPECT_TRUE(agc_enabled);
3046 EXPECT_TRUE(ns_enabled);
3047
3048 // Make sure settings take effect while we are sending.
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00003049 ASSERT_TRUE(engine_.SetOptions(options_all));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003050 cricket::AudioOptions options_no_agc_nor_ns;
3051 options_no_agc_nor_ns.auto_gain_control.Set(false);
3052 options_no_agc_nor_ns.noise_suppression.Set(false);
3053 channel2->SetSend(cricket::SEND_MICROPHONE);
3054 channel2->SetOptions(options_no_agc_nor_ns);
3055
3056 expected_options.echo_cancellation.Set(true);
3057 expected_options.auto_gain_control.Set(false);
3058 expected_options.noise_suppression.Set(false);
3059 ASSERT_TRUE(channel2->GetOptions(&actual_options));
3060 EXPECT_EQ(expected_options, actual_options);
3061 voe_.GetEcStatus(ec_enabled, ec_mode);
3062 voe_.GetAgcStatus(agc_enabled, agc_mode);
3063 voe_.GetNsStatus(ns_enabled, ns_mode);
3064 EXPECT_TRUE(ec_enabled);
3065 EXPECT_FALSE(agc_enabled);
3066 EXPECT_FALSE(ns_enabled);
3067}
3068
wu@webrtc.orgde305012013-10-31 15:40:38 +00003069// This test verifies DSCP settings are properly applied on voice media channel.
3070TEST_F(WebRtcVoiceEngineTestFake, TestSetDscpOptions) {
3071 EXPECT_TRUE(SetupEngine());
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003072 rtc::scoped_ptr<cricket::VoiceMediaChannel> channel(
wu@webrtc.orgde305012013-10-31 15:40:38 +00003073 engine_.CreateChannel());
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003074 rtc::scoped_ptr<cricket::FakeNetworkInterface> network_interface(
wu@webrtc.orgde305012013-10-31 15:40:38 +00003075 new cricket::FakeNetworkInterface);
3076 channel->SetInterface(network_interface.get());
3077 cricket::AudioOptions options;
3078 options.dscp.Set(true);
3079 EXPECT_TRUE(channel->SetOptions(options));
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003080 EXPECT_EQ(rtc::DSCP_EF, network_interface->dscp());
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +00003081 // Verify previous value is not modified if dscp option is not set.
3082 cricket::AudioOptions options1;
3083 EXPECT_TRUE(channel->SetOptions(options1));
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003084 EXPECT_EQ(rtc::DSCP_EF, network_interface->dscp());
wu@webrtc.orgde305012013-10-31 15:40:38 +00003085 options.dscp.Set(false);
3086 EXPECT_TRUE(channel->SetOptions(options));
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003087 EXPECT_EQ(rtc::DSCP_DEFAULT, network_interface->dscp());
wu@webrtc.orgde305012013-10-31 15:40:38 +00003088}
3089
wu@webrtc.org1d1ffc92013-10-16 18:12:02 +00003090TEST(WebRtcVoiceEngineTest, TestDefaultOptionsBeforeInit) {
3091 cricket::WebRtcVoiceEngine engine;
3092 cricket::AudioOptions options = engine.GetOptions();
3093 // The default options should have at least a few things set. We purposefully
3094 // don't check the option values here, though.
3095 EXPECT_TRUE(options.echo_cancellation.IsSet());
3096 EXPECT_TRUE(options.auto_gain_control.IsSet());
3097 EXPECT_TRUE(options.noise_suppression.IsSet());
3098}
3099
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003100// Test that GetReceiveChannelNum returns the default channel for the first
3101// recv stream in 1-1 calls.
3102TEST_F(WebRtcVoiceEngineTestFake, TestGetReceiveChannelNumIn1To1Calls) {
3103 EXPECT_TRUE(SetupEngine());
3104 cricket::WebRtcVoiceMediaChannel* media_channel =
3105 static_cast<cricket::WebRtcVoiceMediaChannel*>(channel_);
3106 // Test that GetChannelNum returns the default channel if the SSRC is unknown.
3107 EXPECT_EQ(media_channel->voe_channel(),
3108 media_channel->GetReceiveChannelNum(0));
3109 cricket::StreamParams stream;
3110 stream.ssrcs.push_back(kSsrc2);
3111 EXPECT_TRUE(channel_->AddRecvStream(stream));
3112 EXPECT_EQ(media_channel->voe_channel(),
3113 media_channel->GetReceiveChannelNum(kSsrc2));
3114}
3115
3116// Test that GetReceiveChannelNum doesn't return the default channel for the
3117// first recv stream in conference calls.
3118TEST_F(WebRtcVoiceEngineTestFake, TestGetChannelNumInConferenceCalls) {
3119 EXPECT_TRUE(SetupEngine());
3120 EXPECT_TRUE(channel_->SetOptions(options_conference_));
3121 cricket::StreamParams stream;
3122 stream.ssrcs.push_back(kSsrc2);
3123 EXPECT_TRUE(channel_->AddRecvStream(stream));
3124 cricket::WebRtcVoiceMediaChannel* media_channel =
3125 static_cast<cricket::WebRtcVoiceMediaChannel*>(channel_);
3126 EXPECT_LT(media_channel->voe_channel(),
3127 media_channel->GetReceiveChannelNum(kSsrc2));
3128}
3129
3130TEST_F(WebRtcVoiceEngineTestFake, SetOutputScaling) {
3131 EXPECT_TRUE(SetupEngine());
3132 double left, right;
3133 EXPECT_TRUE(channel_->SetOutputScaling(0, 1, 2));
3134 EXPECT_TRUE(channel_->GetOutputScaling(0, &left, &right));
3135 EXPECT_DOUBLE_EQ(1, left);
3136 EXPECT_DOUBLE_EQ(2, right);
3137
3138 EXPECT_FALSE(channel_->SetOutputScaling(kSsrc2, 1, 2));
3139 cricket::StreamParams stream;
3140 stream.ssrcs.push_back(kSsrc2);
3141 EXPECT_TRUE(channel_->AddRecvStream(stream));
3142
3143 EXPECT_TRUE(channel_->SetOutputScaling(kSsrc2, 2, 1));
3144 EXPECT_TRUE(channel_->GetOutputScaling(kSsrc2, &left, &right));
3145 EXPECT_DOUBLE_EQ(2, left);
3146 EXPECT_DOUBLE_EQ(1, right);
3147}
3148
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003149// Tests for the actual WebRtc VoE library.
3150
3151// Tests that the library initializes and shuts down properly.
3152TEST(WebRtcVoiceEngineTest, StartupShutdown) {
3153 cricket::WebRtcVoiceEngine engine;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003154 EXPECT_TRUE(engine.Init(rtc::Thread::Current()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003155 cricket::VoiceMediaChannel* channel = engine.CreateChannel();
3156 EXPECT_TRUE(channel != NULL);
3157 delete channel;
3158 engine.Terminate();
3159
3160 // Reinit to catch regression where VoiceEngineObserver reference is lost
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003161 EXPECT_TRUE(engine.Init(rtc::Thread::Current()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003162 engine.Terminate();
3163}
3164
3165// Tests that the logging from the library is cleartext.
3166TEST(WebRtcVoiceEngineTest, DISABLED_HasUnencryptedLogging) {
3167 cricket::WebRtcVoiceEngine engine;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003168 rtc::scoped_ptr<rtc::MemoryStream> stream(
3169 new rtc::MemoryStream);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003170 size_t size = 0;
3171 bool cleartext = true;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003172 rtc::LogMessage::AddLogToStream(stream.get(), rtc::LS_VERBOSE);
3173 engine.SetLogging(rtc::LS_VERBOSE, "");
3174 EXPECT_TRUE(engine.Init(rtc::Thread::Current()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003175 EXPECT_TRUE(stream->GetSize(&size));
3176 EXPECT_GT(size, 0U);
3177 engine.Terminate();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003178 rtc::LogMessage::RemoveLogToStream(stream.get());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003179 const char* buf = stream->GetBuffer();
3180 for (size_t i = 0; i < size && cleartext; ++i) {
3181 int ch = static_cast<int>(buf[i]);
3182 ASSERT_GE(ch, 0) << "Out of bounds character in WebRtc VoE log: "
3183 << std::hex << ch;
3184 cleartext = (isprint(ch) || isspace(ch));
3185 }
3186 EXPECT_TRUE(cleartext);
3187}
3188
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003189// Tests that the library is configured with the codecs we want.
3190TEST(WebRtcVoiceEngineTest, HasCorrectCodecs) {
3191 cricket::WebRtcVoiceEngine engine;
3192 // Check codecs by name.
3193 EXPECT_TRUE(engine.FindCodec(
3194 cricket::AudioCodec(96, "OPUS", 48000, 0, 2, 0)));
3195 EXPECT_TRUE(engine.FindCodec(
3196 cricket::AudioCodec(96, "ISAC", 16000, 0, 1, 0)));
3197 EXPECT_TRUE(engine.FindCodec(
3198 cricket::AudioCodec(96, "ISAC", 32000, 0, 1, 0)));
3199 // Check that name matching is case-insensitive.
3200 EXPECT_TRUE(engine.FindCodec(
3201 cricket::AudioCodec(96, "ILBC", 8000, 0, 1, 0)));
3202 EXPECT_TRUE(engine.FindCodec(
3203 cricket::AudioCodec(96, "iLBC", 8000, 0, 1, 0)));
3204 EXPECT_TRUE(engine.FindCodec(
3205 cricket::AudioCodec(96, "PCMU", 8000, 0, 1, 0)));
3206 EXPECT_TRUE(engine.FindCodec(
3207 cricket::AudioCodec(96, "PCMA", 8000, 0, 1, 0)));
3208 EXPECT_TRUE(engine.FindCodec(
henrik.lundin@webrtc.orgf85dbce2014-11-07 12:25:00 +00003209 cricket::AudioCodec(96, "G722", 8000, 0, 1, 0)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003210 EXPECT_TRUE(engine.FindCodec(
3211 cricket::AudioCodec(96, "red", 8000, 0, 1, 0)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003212 EXPECT_TRUE(engine.FindCodec(
3213 cricket::AudioCodec(96, "CN", 32000, 0, 1, 0)));
3214 EXPECT_TRUE(engine.FindCodec(
3215 cricket::AudioCodec(96, "CN", 16000, 0, 1, 0)));
3216 EXPECT_TRUE(engine.FindCodec(
3217 cricket::AudioCodec(96, "CN", 8000, 0, 1, 0)));
3218 EXPECT_TRUE(engine.FindCodec(
3219 cricket::AudioCodec(96, "telephone-event", 8000, 0, 1, 0)));
3220 // Check codecs with an id by id.
3221 EXPECT_TRUE(engine.FindCodec(
3222 cricket::AudioCodec(0, "", 8000, 0, 1, 0))); // PCMU
3223 EXPECT_TRUE(engine.FindCodec(
3224 cricket::AudioCodec(8, "", 8000, 0, 1, 0))); // PCMA
3225 EXPECT_TRUE(engine.FindCodec(
henrik.lundin@webrtc.orgf85dbce2014-11-07 12:25:00 +00003226 cricket::AudioCodec(9, "", 8000, 0, 1, 0))); // G722
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003227 EXPECT_TRUE(engine.FindCodec(
3228 cricket::AudioCodec(13, "", 8000, 0, 1, 0))); // CN
3229 // Check sample/bitrate matching.
3230 EXPECT_TRUE(engine.FindCodec(
3231 cricket::AudioCodec(0, "PCMU", 8000, 64000, 1, 0)));
3232 // Check that bad codecs fail.
3233 EXPECT_FALSE(engine.FindCodec(cricket::AudioCodec(99, "ABCD", 0, 0, 1, 0)));
3234 EXPECT_FALSE(engine.FindCodec(cricket::AudioCodec(88, "", 0, 0, 1, 0)));
3235 EXPECT_FALSE(engine.FindCodec(cricket::AudioCodec(0, "", 0, 0, 2, 0)));
3236 EXPECT_FALSE(engine.FindCodec(cricket::AudioCodec(0, "", 5000, 0, 1, 0)));
3237 EXPECT_FALSE(engine.FindCodec(cricket::AudioCodec(0, "", 0, 5000, 1, 0)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003238 // Verify the payload id of common audio codecs, including CN, ISAC, and G722.
3239 for (std::vector<cricket::AudioCodec>::const_iterator it =
3240 engine.codecs().begin(); it != engine.codecs().end(); ++it) {
3241 if (it->name == "CN" && it->clockrate == 16000) {
3242 EXPECT_EQ(105, it->id);
3243 } else if (it->name == "CN" && it->clockrate == 32000) {
3244 EXPECT_EQ(106, it->id);
3245 } else if (it->name == "ISAC" && it->clockrate == 16000) {
3246 EXPECT_EQ(103, it->id);
3247 } else if (it->name == "ISAC" && it->clockrate == 32000) {
3248 EXPECT_EQ(104, it->id);
henrik.lundin@webrtc.orgf85dbce2014-11-07 12:25:00 +00003249 } else if (it->name == "G722" && it->clockrate == 8000) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003250 EXPECT_EQ(9, it->id);
3251 } else if (it->name == "telephone-event") {
3252 EXPECT_EQ(126, it->id);
3253 } else if (it->name == "red") {
3254 EXPECT_EQ(127, it->id);
3255 } else if (it->name == "opus") {
3256 EXPECT_EQ(111, it->id);
wu@webrtc.org9caf2762013-12-11 18:25:07 +00003257 ASSERT_TRUE(it->params.find("minptime") != it->params.end());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003258 EXPECT_EQ("10", it->params.find("minptime")->second);
wu@webrtc.org9caf2762013-12-11 18:25:07 +00003259 ASSERT_TRUE(it->params.find("maxptime") != it->params.end());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003260 EXPECT_EQ("60", it->params.find("maxptime")->second);
minyue@webrtc.org4ef22d12014-11-17 09:26:39 +00003261 ASSERT_TRUE(it->params.find("useinbandfec") != it->params.end());
3262 EXPECT_EQ("1", it->params.find("useinbandfec")->second);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003263 }
3264 }
3265
3266 engine.Terminate();
3267}
3268
3269// Tests that VoE supports at least 32 channels
3270TEST(WebRtcVoiceEngineTest, Has32Channels) {
3271 cricket::WebRtcVoiceEngine engine;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003272 EXPECT_TRUE(engine.Init(rtc::Thread::Current()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003273
3274 cricket::VoiceMediaChannel* channels[32];
3275 int num_channels = 0;
3276
3277 while (num_channels < ARRAY_SIZE(channels)) {
3278 cricket::VoiceMediaChannel* channel = engine.CreateChannel();
3279 if (!channel)
3280 break;
3281
3282 channels[num_channels++] = channel;
3283 }
3284
3285 int expected = ARRAY_SIZE(channels);
3286 EXPECT_EQ(expected, num_channels);
3287
3288 while (num_channels > 0) {
3289 delete channels[--num_channels];
3290 }
3291
3292 engine.Terminate();
3293}
3294
3295// Test that we set our preferred codecs properly.
3296TEST(WebRtcVoiceEngineTest, SetRecvCodecs) {
3297 cricket::WebRtcVoiceEngine engine;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003298 EXPECT_TRUE(engine.Init(rtc::Thread::Current()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003299 cricket::WebRtcVoiceMediaChannel channel(&engine);
3300 EXPECT_TRUE(channel.SetRecvCodecs(engine.codecs()));
3301}
3302
3303#ifdef WIN32
3304// Test our workarounds to WebRtc VoE' munging of the coinit count
3305TEST(WebRtcVoiceEngineTest, CoInitialize) {
3306 cricket::WebRtcVoiceEngine* engine = new cricket::WebRtcVoiceEngine();
3307
3308 // Initial refcount should be 0.
3309 EXPECT_EQ(S_OK, CoInitializeEx(NULL, COINIT_MULTITHREADED));
3310
3311 // Engine should start even with COM already inited.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003312 EXPECT_TRUE(engine->Init(rtc::Thread::Current()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003313 engine->Terminate();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003314 EXPECT_TRUE(engine->Init(rtc::Thread::Current()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003315 engine->Terminate();
3316
3317 // Refcount after terminate should be 1 (in reality 3); test if it is nonzero.
3318 EXPECT_EQ(S_FALSE, CoInitializeEx(NULL, COINIT_MULTITHREADED));
3319 // Decrement refcount to (hopefully) 0.
3320 CoUninitialize();
3321 CoUninitialize();
3322 delete engine;
3323
3324 // Ensure refcount is 0.
3325 EXPECT_EQ(S_OK, CoInitializeEx(NULL, COINIT_MULTITHREADED));
3326 CoUninitialize();
3327}
3328#endif
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +00003329
3330TEST_F(WebRtcVoiceEngineTestFake, ChangeCombinedAudioVideoBweOption) {
3331 // Test that changing the combined_audio_video_bwe option results in the
3332 // expected state changes in VoiceEngine.
3333 cricket::ViEWrapper vie;
3334 const int kVieCh = 667;
3335
3336 EXPECT_TRUE(SetupEngine());
3337 cricket::WebRtcVoiceMediaChannel* media_channel =
3338 static_cast<cricket::WebRtcVoiceMediaChannel*>(channel_);
3339 EXPECT_TRUE(media_channel->SetupSharedBandwidthEstimation(vie.engine(),
3340 kVieCh));
3341 EXPECT_TRUE(media_channel->AddRecvStream(
3342 cricket::StreamParams::CreateLegacy(2)));
3343 int recv_ch = voe_.GetLastChannel();
3344
3345 // Combined BWE should not be set up yet.
3346 EXPECT_EQ(NULL, voe_.GetViENetwork(recv_ch));
3347 EXPECT_EQ(-1, voe_.GetVideoChannel(recv_ch));
3348
3349 // Enable combined BWE option - now it should be set up.
3350 cricket::AudioOptions options;
3351 options.combined_audio_video_bwe.Set(true);
3352 EXPECT_TRUE(media_channel->SetOptions(options));
3353 EXPECT_EQ(vie.network(), voe_.GetViENetwork(recv_ch));
3354 EXPECT_EQ(kVieCh, voe_.GetVideoChannel(recv_ch));
3355
3356 // Disable combined BWE option - should be disabled again.
3357 options.combined_audio_video_bwe.Set(false);
3358 EXPECT_TRUE(media_channel->SetOptions(options));
3359 EXPECT_EQ(NULL, voe_.GetViENetwork(recv_ch));
3360 EXPECT_EQ(-1, voe_.GetVideoChannel(recv_ch));
3361
3362 EXPECT_TRUE(media_channel->SetupSharedBandwidthEstimation(NULL, -1));
3363}
3364
3365TEST_F(WebRtcVoiceEngineTestFake, SetupSharedBandwidthEstimation) {
3366 // Test that calling SetupSharedBandwidthEstimation() on the voice media
3367 // channel results in the expected state changes in VoiceEngine.
3368 cricket::ViEWrapper vie1;
3369 cricket::ViEWrapper vie2;
3370 const int kVieCh1 = 667;
3371 const int kVieCh2 = 70;
3372
3373 EXPECT_TRUE(SetupEngine());
3374 cricket::WebRtcVoiceMediaChannel* media_channel =
3375 static_cast<cricket::WebRtcVoiceMediaChannel*>(channel_);
3376 cricket::AudioOptions options;
3377 options.combined_audio_video_bwe.Set(true);
3378 EXPECT_TRUE(media_channel->SetOptions(options));
3379 EXPECT_TRUE(media_channel->AddRecvStream(
3380 cricket::StreamParams::CreateLegacy(2)));
3381 int recv_ch = voe_.GetLastChannel();
3382
3383 // Combined BWE should not be set up yet.
3384 EXPECT_EQ(NULL, voe_.GetViENetwork(recv_ch));
3385 EXPECT_EQ(-1, voe_.GetVideoChannel(recv_ch));
3386
3387 // Register - should be enabled.
3388 EXPECT_TRUE(media_channel->SetupSharedBandwidthEstimation(vie1.engine(),
3389 kVieCh1));
3390 EXPECT_EQ(vie1.network(), voe_.GetViENetwork(recv_ch));
3391 EXPECT_EQ(kVieCh1, voe_.GetVideoChannel(recv_ch));
3392
3393 // Re-register - should still be enabled.
3394 EXPECT_TRUE(media_channel->SetupSharedBandwidthEstimation(vie2.engine(),
3395 kVieCh2));
3396 EXPECT_EQ(vie2.network(), voe_.GetViENetwork(recv_ch));
3397 EXPECT_EQ(kVieCh2, voe_.GetVideoChannel(recv_ch));
3398
3399 // Unregister - should be disabled again.
3400 EXPECT_TRUE(media_channel->SetupSharedBandwidthEstimation(NULL, -1));
3401 EXPECT_EQ(NULL, voe_.GetViENetwork(recv_ch));
3402 EXPECT_EQ(-1, voe_.GetVideoChannel(recv_ch));
3403}
3404
3405TEST_F(WebRtcVoiceEngineTestFake, ConfigureCombinedBweForNewRecvStreams) {
3406 // Test that adding receive streams after enabling combined bandwidth
3407 // estimation will correctly configure each channel.
3408 cricket::ViEWrapper vie;
3409 const int kVieCh = 667;
3410
3411 EXPECT_TRUE(SetupEngine());
3412 cricket::WebRtcVoiceMediaChannel* media_channel =
3413 static_cast<cricket::WebRtcVoiceMediaChannel*>(channel_);
3414 EXPECT_TRUE(media_channel->SetupSharedBandwidthEstimation(vie.engine(),
3415 kVieCh));
3416 cricket::AudioOptions options;
3417 options.combined_audio_video_bwe.Set(true);
3418 EXPECT_TRUE(media_channel->SetOptions(options));
3419
3420 static const uint32 kSsrcs[] = {1, 2, 3, 4};
3421 int voe_channels[ARRAY_SIZE(kSsrcs)] = {0};
3422 for (unsigned int i = 0; i < ARRAY_SIZE(kSsrcs); ++i) {
3423 EXPECT_TRUE(media_channel->AddRecvStream(
3424 cricket::StreamParams::CreateLegacy(kSsrcs[i])));
3425 int recv_ch = media_channel->GetReceiveChannelNum(kSsrcs[i]);
3426 EXPECT_NE(-1, recv_ch);
3427 voe_channels[i] = recv_ch;
3428 EXPECT_EQ(vie.network(), voe_.GetViENetwork(recv_ch));
3429 EXPECT_EQ(kVieCh, voe_.GetVideoChannel(recv_ch));
3430 }
3431
3432 EXPECT_TRUE(media_channel->SetupSharedBandwidthEstimation(NULL, -1));
3433
3434 for (unsigned int i = 0; i < ARRAY_SIZE(voe_channels); ++i) {
3435 EXPECT_EQ(NULL, voe_.GetViENetwork(voe_channels[i]));
3436 EXPECT_EQ(-1, voe_.GetVideoChannel(voe_channels[i]));
3437 }
3438}