blob: 4d43cd29d8db8ae8611104b0416e45ad76054e7c [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"
Fredrik Solenberg4b60c732015-05-07 14:07:48 +020040#include "talk/media/webrtc/fakewebrtccall.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000041#include "talk/media/webrtc/fakewebrtcvoiceengine.h"
42#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:
Fredrik Solenbergaaf8ff22015-05-07 16:05:53 +020089 int SetTraceFilter(const unsigned int filter) override {
wu@webrtc.org97077a32013-10-25 21:18:33 +000090 filter_ = filter;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000091 return 0;
92 }
Fredrik Solenbergaaf8ff22015-05-07 16:05:53 +020093 int SetTraceFile(const char* fileNameUTF8) override { return 0; }
94 int SetTraceCallback(webrtc::TraceCallback* callback) override { return 0; }
wu@webrtc.org97077a32013-10-25 21:18:33 +000095 unsigned int filter_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000096};
97
98class WebRtcVoiceEngineTestFake : public testing::Test {
99 public:
100 class ChannelErrorListener : public sigslot::has_slots<> {
101 public:
102 explicit ChannelErrorListener(cricket::VoiceMediaChannel* channel)
103 : ssrc_(0), error_(cricket::VoiceMediaChannel::ERROR_NONE) {
Fredrik Solenbergd3ddc1b2015-05-07 17:07:34 +0200104 DCHECK(channel != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000105 channel->SignalMediaError.connect(
106 this, &ChannelErrorListener::OnVoiceChannelError);
107 }
108 void OnVoiceChannelError(uint32 ssrc,
109 cricket::VoiceMediaChannel::Error error) {
110 ssrc_ = ssrc;
111 error_ = error;
112 }
113 void Reset() {
114 ssrc_ = 0;
115 error_ = cricket::VoiceMediaChannel::ERROR_NONE;
116 }
117 uint32 ssrc() const {
118 return ssrc_;
119 }
120 cricket::VoiceMediaChannel::Error error() const {
121 return error_;
122 }
123
124 private:
125 uint32 ssrc_;
126 cricket::VoiceMediaChannel::Error error_;
127 };
128
129 WebRtcVoiceEngineTestFake()
130 : voe_(kAudioCodecs, ARRAY_SIZE(kAudioCodecs)),
131 voe_sc_(kAudioCodecs, ARRAY_SIZE(kAudioCodecs)),
wu@webrtc.org97077a32013-10-25 21:18:33 +0000132 trace_wrapper_(new FakeVoETraceWrapper()),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000133 engine_(new FakeVoEWrapper(&voe_),
134 new FakeVoEWrapper(&voe_sc_),
wu@webrtc.org97077a32013-10-25 21:18:33 +0000135 trace_wrapper_),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000136 channel_(NULL), soundclip_(NULL) {
137 options_conference_.conference_mode.Set(true);
138 options_adjust_agc_.adjust_agc_delta.Set(-10);
139 }
buildbot@webrtc.org150835e2014-05-06 15:54:38 +0000140 bool SetupEngineWithoutStream() {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000141 if (!engine_.Init(rtc::Thread::Current())) {
buildbot@webrtc.org150835e2014-05-06 15:54:38 +0000142 return false;
143 }
144 channel_ = engine_.CreateChannel();
145 return (channel_ != NULL);
146 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000147 bool SetupEngine() {
buildbot@webrtc.org150835e2014-05-06 15:54:38 +0000148 if (!SetupEngineWithoutStream()) {
149 return false;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000150 }
buildbot@webrtc.org150835e2014-05-06 15:54:38 +0000151 return channel_->AddSendStream(
152 cricket::StreamParams::CreateLegacy(kSsrc1));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000153 }
wu@webrtc.org9dba5252013-08-05 20:36:57 +0000154 void SetupForMultiSendStream() {
155 EXPECT_TRUE(SetupEngine());
156 // Remove stream added in Setup, which is corresponding to default channel.
157 int default_channel_num = voe_.GetLastChannel();
henrike@webrtc.org7666db72013-08-22 14:45:42 +0000158 uint32 default_send_ssrc = 0u;
wu@webrtc.org9dba5252013-08-05 20:36:57 +0000159 EXPECT_EQ(0, voe_.GetLocalSSRC(default_channel_num, default_send_ssrc));
160 EXPECT_EQ(kSsrc1, default_send_ssrc);
161 EXPECT_TRUE(channel_->RemoveSendStream(default_send_ssrc));
162
163 // Verify the default channel still exists.
164 EXPECT_EQ(0, voe_.GetLocalSSRC(default_channel_num, default_send_ssrc));
165 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000166 void DeliverPacket(const void* data, int len) {
Karl Wiberg94784372015-04-20 14:03:07 +0200167 rtc::Buffer packet(reinterpret_cast<const uint8_t*>(data), len);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000168 channel_->OnPacketReceived(&packet, rtc::PacketTime());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000169 }
Fredrik Solenbergaaf8ff22015-05-07 16:05:53 +0200170 void TearDown() override {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000171 delete soundclip_;
172 delete channel_;
173 engine_.Terminate();
174 }
175
wu@webrtc.orgcadf9042013-08-30 21:24:16 +0000176 void TestInsertDtmf(uint32 ssrc, bool caller) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000177 EXPECT_TRUE(engine_.Init(rtc::Thread::Current()));
wu@webrtc.orgcadf9042013-08-30 21:24:16 +0000178 channel_ = engine_.CreateChannel();
179 EXPECT_TRUE(channel_ != NULL);
180 if (caller) {
181 // if this is a caller, local description will be applied and add the
182 // send stream.
183 EXPECT_TRUE(channel_->AddSendStream(
184 cricket::StreamParams::CreateLegacy(kSsrc1)));
185 }
186 int channel_id = voe_.GetLastChannel();
187
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000188 // Test we can only InsertDtmf when the other side supports telephone-event.
189 std::vector<cricket::AudioCodec> codecs;
190 codecs.push_back(kPcmuCodec);
191 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
192 EXPECT_TRUE(channel_->SetSend(cricket::SEND_MICROPHONE));
193 EXPECT_FALSE(channel_->CanInsertDtmf());
194 EXPECT_FALSE(channel_->InsertDtmf(ssrc, 1, 111, cricket::DF_SEND));
195 codecs.push_back(kTelephoneEventCodec);
196 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
197 EXPECT_TRUE(channel_->CanInsertDtmf());
wu@webrtc.orgcadf9042013-08-30 21:24:16 +0000198
199 if (!caller) {
200 // There's no active send channel yet.
201 EXPECT_FALSE(channel_->InsertDtmf(ssrc, 2, 123, cricket::DF_SEND));
202 EXPECT_TRUE(channel_->AddSendStream(
203 cricket::StreamParams::CreateLegacy(kSsrc1)));
204 }
205
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000206 // Check we fail if the ssrc is invalid.
207 EXPECT_FALSE(channel_->InsertDtmf(-1, 1, 111, cricket::DF_SEND));
208
209 // Test send
210 EXPECT_FALSE(voe_.WasSendTelephoneEventCalled(channel_id, 2, 123));
211 EXPECT_TRUE(channel_->InsertDtmf(ssrc, 2, 123, cricket::DF_SEND));
212 EXPECT_TRUE(voe_.WasSendTelephoneEventCalled(channel_id, 2, 123));
213
214 // Test play
215 EXPECT_FALSE(voe_.WasPlayDtmfToneCalled(3, 134));
216 EXPECT_TRUE(channel_->InsertDtmf(ssrc, 3, 134, cricket::DF_PLAY));
217 EXPECT_TRUE(voe_.WasPlayDtmfToneCalled(3, 134));
218
219 // Test send and play
220 EXPECT_FALSE(voe_.WasSendTelephoneEventCalled(channel_id, 4, 145));
221 EXPECT_FALSE(voe_.WasPlayDtmfToneCalled(4, 145));
222 EXPECT_TRUE(channel_->InsertDtmf(ssrc, 4, 145,
223 cricket::DF_PLAY | cricket::DF_SEND));
224 EXPECT_TRUE(voe_.WasSendTelephoneEventCalled(channel_id, 4, 145));
225 EXPECT_TRUE(voe_.WasPlayDtmfToneCalled(4, 145));
226 }
227
228 // Test that send bandwidth is set correctly.
229 // |codec| is the codec under test.
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000230 // |max_bitrate| is a parameter to set to SetMaxSendBandwidth().
231 // |expected_result| is the expected result from SetMaxSendBandwidth().
232 // |expected_bitrate| is the expected audio bitrate afterward.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000233 void TestSendBandwidth(const cricket::AudioCodec& codec,
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000234 int max_bitrate,
235 bool expected_result,
236 int expected_bitrate) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000237 int channel_num = voe_.GetLastChannel();
238 std::vector<cricket::AudioCodec> codecs;
239
240 codecs.push_back(codec);
241 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
242
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000243 bool result = channel_->SetMaxSendBandwidth(max_bitrate);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000244 EXPECT_EQ(expected_result, result);
245
wu@webrtc.org1d1ffc92013-10-16 18:12:02 +0000246 webrtc::CodecInst temp_codec;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000247 EXPECT_FALSE(voe_.GetSendCodec(channel_num, temp_codec));
248
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000249 EXPECT_EQ(expected_bitrate, temp_codec.rate);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000250 }
251
buildbot@webrtc.org150835e2014-05-06 15:54:38 +0000252 void TestSetSendRtpHeaderExtensions(const std::string& ext) {
253 EXPECT_TRUE(SetupEngineWithoutStream());
254 int channel_num = voe_.GetLastChannel();
wu@webrtc.org9dba5252013-08-05 20:36:57 +0000255
henrike@webrtc.org79047f92014-03-06 23:46:59 +0000256 // Ensure extensions are off by default.
buildbot@webrtc.org150835e2014-05-06 15:54:38 +0000257 EXPECT_EQ(-1, voe_.GetSendRtpExtensionId(channel_num, ext));
wu@webrtc.org9dba5252013-08-05 20:36:57 +0000258
buildbot@webrtc.org150835e2014-05-06 15:54:38 +0000259 std::vector<cricket::RtpHeaderExtension> extensions;
wu@webrtc.org9dba5252013-08-05 20:36:57 +0000260 // Ensure unknown extensions won't cause an error.
261 extensions.push_back(cricket::RtpHeaderExtension(
henrike@webrtc.org79047f92014-03-06 23:46:59 +0000262 "urn:ietf:params:unknownextention", 1));
wu@webrtc.org9dba5252013-08-05 20:36:57 +0000263 EXPECT_TRUE(channel_->SetSendRtpHeaderExtensions(extensions));
buildbot@webrtc.org150835e2014-05-06 15:54:38 +0000264 EXPECT_EQ(-1, voe_.GetSendRtpExtensionId(channel_num, ext));
wu@webrtc.org9dba5252013-08-05 20:36:57 +0000265
henrike@webrtc.org79047f92014-03-06 23:46:59 +0000266 // Ensure extensions stay off with an empty list of headers.
267 extensions.clear();
wu@webrtc.org9dba5252013-08-05 20:36:57 +0000268 EXPECT_TRUE(channel_->SetSendRtpHeaderExtensions(extensions));
buildbot@webrtc.org150835e2014-05-06 15:54:38 +0000269 EXPECT_EQ(-1, voe_.GetSendRtpExtensionId(channel_num, ext));
wu@webrtc.org9dba5252013-08-05 20:36:57 +0000270
buildbot@webrtc.org150835e2014-05-06 15:54:38 +0000271 // Ensure extension is set properly.
272 const int id = 1;
273 extensions.push_back(cricket::RtpHeaderExtension(ext, id));
wu@webrtc.org9dba5252013-08-05 20:36:57 +0000274 EXPECT_TRUE(channel_->SetSendRtpHeaderExtensions(extensions));
buildbot@webrtc.org150835e2014-05-06 15:54:38 +0000275 EXPECT_EQ(id, voe_.GetSendRtpExtensionId(channel_num, ext));
wu@webrtc.org9dba5252013-08-05 20:36:57 +0000276
buildbot@webrtc.org150835e2014-05-06 15:54:38 +0000277 // Ensure extension is set properly on new channel.
278 // The first stream to occupy the default channel.
279 EXPECT_TRUE(channel_->AddSendStream(
280 cricket::StreamParams::CreateLegacy(123)));
281 EXPECT_TRUE(channel_->AddSendStream(
282 cricket::StreamParams::CreateLegacy(234)));
283 int new_channel_num = voe_.GetLastChannel();
284 EXPECT_NE(channel_num, new_channel_num);
285 EXPECT_EQ(id, voe_.GetSendRtpExtensionId(new_channel_num, ext));
henrike@webrtc.org79047f92014-03-06 23:46:59 +0000286
287 // Ensure all extensions go back off with an empty list.
wu@webrtc.org9dba5252013-08-05 20:36:57 +0000288 extensions.clear();
289 EXPECT_TRUE(channel_->SetSendRtpHeaderExtensions(extensions));
buildbot@webrtc.org150835e2014-05-06 15:54:38 +0000290 EXPECT_EQ(-1, voe_.GetSendRtpExtensionId(channel_num, ext));
291 EXPECT_EQ(-1, voe_.GetSendRtpExtensionId(new_channel_num, ext));
henrike@webrtc.org79047f92014-03-06 23:46:59 +0000292 }
293
buildbot@webrtc.org150835e2014-05-06 15:54:38 +0000294 void TestSetRecvRtpHeaderExtensions(const std::string& ext) {
295 EXPECT_TRUE(SetupEngineWithoutStream());
296 int channel_num = voe_.GetLastChannel();
henrike@webrtc.org79047f92014-03-06 23:46:59 +0000297
henrike@webrtc.org79047f92014-03-06 23:46:59 +0000298 // Ensure extensions are off by default.
buildbot@webrtc.org150835e2014-05-06 15:54:38 +0000299 EXPECT_EQ(-1, voe_.GetReceiveRtpExtensionId(channel_num, ext));
henrike@webrtc.org79047f92014-03-06 23:46:59 +0000300
buildbot@webrtc.org150835e2014-05-06 15:54:38 +0000301 std::vector<cricket::RtpHeaderExtension> extensions;
henrike@webrtc.org79047f92014-03-06 23:46:59 +0000302 // Ensure unknown extensions won't cause an error.
303 extensions.push_back(cricket::RtpHeaderExtension(
304 "urn:ietf:params:unknownextention", 1));
305 EXPECT_TRUE(channel_->SetRecvRtpHeaderExtensions(extensions));
buildbot@webrtc.org150835e2014-05-06 15:54:38 +0000306 EXPECT_EQ(-1, voe_.GetReceiveRtpExtensionId(channel_num, ext));
henrike@webrtc.org79047f92014-03-06 23:46:59 +0000307
buildbot@webrtc.org150835e2014-05-06 15:54:38 +0000308 // Ensure extensions stay off with an empty list of headers.
henrike@webrtc.org79047f92014-03-06 23:46:59 +0000309 extensions.clear();
310 EXPECT_TRUE(channel_->SetRecvRtpHeaderExtensions(extensions));
buildbot@webrtc.org150835e2014-05-06 15:54:38 +0000311 EXPECT_EQ(-1, voe_.GetReceiveRtpExtensionId(channel_num, ext));
henrike@webrtc.org79047f92014-03-06 23:46:59 +0000312
buildbot@webrtc.org150835e2014-05-06 15:54:38 +0000313 // Ensure extension is set properly.
314 const int id = 2;
315 extensions.push_back(cricket::RtpHeaderExtension(ext, id));
henrike@webrtc.org79047f92014-03-06 23:46:59 +0000316 EXPECT_TRUE(channel_->SetRecvRtpHeaderExtensions(extensions));
buildbot@webrtc.org150835e2014-05-06 15:54:38 +0000317 EXPECT_EQ(id, voe_.GetReceiveRtpExtensionId(channel_num, ext));
henrike@webrtc.org79047f92014-03-06 23:46:59 +0000318
buildbot@webrtc.org150835e2014-05-06 15:54:38 +0000319 // Ensure extension is set properly on new channel.
320 // The first stream to occupy the default channel.
321 EXPECT_TRUE(channel_->AddRecvStream(
322 cricket::StreamParams::CreateLegacy(345)));
323 EXPECT_TRUE(channel_->AddRecvStream(
324 cricket::StreamParams::CreateLegacy(456)));
325 int new_channel_num = voe_.GetLastChannel();
326 EXPECT_NE(channel_num, new_channel_num);
327 EXPECT_EQ(id, voe_.GetReceiveRtpExtensionId(new_channel_num, ext));
328
329 // Ensure all extensions go back off with an empty list.
henrike@webrtc.org79047f92014-03-06 23:46:59 +0000330 extensions.clear();
331 EXPECT_TRUE(channel_->SetRecvRtpHeaderExtensions(extensions));
buildbot@webrtc.org150835e2014-05-06 15:54:38 +0000332 EXPECT_EQ(-1, voe_.GetReceiveRtpExtensionId(channel_num, ext));
333 EXPECT_EQ(-1, voe_.GetReceiveRtpExtensionId(new_channel_num, ext));
wu@webrtc.org9dba5252013-08-05 20:36:57 +0000334 }
335
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000336 protected:
337 cricket::FakeWebRtcVoiceEngine voe_;
338 cricket::FakeWebRtcVoiceEngine voe_sc_;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000339 FakeVoETraceWrapper* trace_wrapper_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000340 cricket::WebRtcVoiceEngine engine_;
341 cricket::VoiceMediaChannel* channel_;
342 cricket::SoundclipMedia* soundclip_;
343
344 cricket::AudioOptions options_conference_;
345 cricket::AudioOptions options_adjust_agc_;
346};
347
348// Tests that our stub library "works".
349TEST_F(WebRtcVoiceEngineTestFake, StartupShutdown) {
350 EXPECT_FALSE(voe_.IsInited());
351 EXPECT_FALSE(voe_sc_.IsInited());
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000352 EXPECT_TRUE(engine_.Init(rtc::Thread::Current()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000353 EXPECT_TRUE(voe_.IsInited());
wu@webrtc.org4551b792013-10-09 15:37:36 +0000354 // The soundclip engine is lazily initialized.
355 EXPECT_FALSE(voe_sc_.IsInited());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000356 engine_.Terminate();
357 EXPECT_FALSE(voe_.IsInited());
358 EXPECT_FALSE(voe_sc_.IsInited());
359}
360
361// Tests that we can create and destroy a channel.
362TEST_F(WebRtcVoiceEngineTestFake, CreateChannel) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000363 EXPECT_TRUE(engine_.Init(rtc::Thread::Current()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000364 channel_ = engine_.CreateChannel();
365 EXPECT_TRUE(channel_ != NULL);
366}
367
368// Tests that we properly handle failures in CreateChannel.
369TEST_F(WebRtcVoiceEngineTestFake, CreateChannelFail) {
370 voe_.set_fail_create_channel(true);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000371 EXPECT_TRUE(engine_.Init(rtc::Thread::Current()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000372 channel_ = engine_.CreateChannel();
373 EXPECT_TRUE(channel_ == NULL);
374}
375
376// Tests that the list of supported codecs is created properly and ordered
377// correctly
378TEST_F(WebRtcVoiceEngineTestFake, CodecPreference) {
379 const std::vector<cricket::AudioCodec>& codecs = engine_.codecs();
380 ASSERT_FALSE(codecs.empty());
381 EXPECT_STRCASEEQ("opus", codecs[0].name.c_str());
382 EXPECT_EQ(48000, codecs[0].clockrate);
383 EXPECT_EQ(2, codecs[0].channels);
384 EXPECT_EQ(64000, codecs[0].bitrate);
385 int pref = codecs[0].preference;
386 for (size_t i = 1; i < codecs.size(); ++i) {
387 EXPECT_GT(pref, codecs[i].preference);
388 pref = codecs[i].preference;
389 }
390}
391
392// Tests that we can find codecs by name or id, and that we interpret the
393// clockrate and bitrate fields properly.
394TEST_F(WebRtcVoiceEngineTestFake, FindCodec) {
395 cricket::AudioCodec codec;
396 webrtc::CodecInst codec_inst;
397 // Find PCMU with explicit clockrate and bitrate.
398 EXPECT_TRUE(engine_.FindWebRtcCodec(kPcmuCodec, &codec_inst));
399 // Find ISAC with explicit clockrate and 0 bitrate.
400 EXPECT_TRUE(engine_.FindWebRtcCodec(kIsacCodec, &codec_inst));
401 // Find telephone-event with explicit clockrate and 0 bitrate.
402 EXPECT_TRUE(engine_.FindWebRtcCodec(kTelephoneEventCodec, &codec_inst));
403 // Find ISAC with a different payload id.
404 codec = kIsacCodec;
405 codec.id = 127;
406 EXPECT_TRUE(engine_.FindWebRtcCodec(codec, &codec_inst));
407 EXPECT_EQ(codec.id, codec_inst.pltype);
408 // Find PCMU with a 0 clockrate.
409 codec = kPcmuCodec;
410 codec.clockrate = 0;
411 EXPECT_TRUE(engine_.FindWebRtcCodec(codec, &codec_inst));
412 EXPECT_EQ(codec.id, codec_inst.pltype);
413 EXPECT_EQ(8000, codec_inst.plfreq);
414 // Find PCMU with a 0 bitrate.
415 codec = kPcmuCodec;
416 codec.bitrate = 0;
417 EXPECT_TRUE(engine_.FindWebRtcCodec(codec, &codec_inst));
418 EXPECT_EQ(codec.id, codec_inst.pltype);
419 EXPECT_EQ(64000, codec_inst.rate);
420 // Find ISAC with an explicit bitrate.
421 codec = kIsacCodec;
422 codec.bitrate = 32000;
423 EXPECT_TRUE(engine_.FindWebRtcCodec(codec, &codec_inst));
424 EXPECT_EQ(codec.id, codec_inst.pltype);
425 EXPECT_EQ(32000, codec_inst.rate);
426}
427
428// Test that we set our inbound codecs properly, including changing PT.
429TEST_F(WebRtcVoiceEngineTestFake, SetRecvCodecs) {
430 EXPECT_TRUE(SetupEngine());
431 int channel_num = voe_.GetLastChannel();
432 std::vector<cricket::AudioCodec> codecs;
433 codecs.push_back(kIsacCodec);
434 codecs.push_back(kPcmuCodec);
435 codecs.push_back(kTelephoneEventCodec);
436 codecs[0].id = 106; // collide with existing telephone-event
437 codecs[2].id = 126;
438 EXPECT_TRUE(channel_->SetRecvCodecs(codecs));
439 webrtc::CodecInst gcodec;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000440 rtc::strcpyn(gcodec.plname, ARRAY_SIZE(gcodec.plname), "ISAC");
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000441 gcodec.plfreq = 16000;
442 gcodec.channels = 1;
443 EXPECT_EQ(0, voe_.GetRecPayloadType(channel_num, gcodec));
444 EXPECT_EQ(106, gcodec.pltype);
445 EXPECT_STREQ("ISAC", gcodec.plname);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000446 rtc::strcpyn(gcodec.plname, ARRAY_SIZE(gcodec.plname),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000447 "telephone-event");
448 gcodec.plfreq = 8000;
449 EXPECT_EQ(0, voe_.GetRecPayloadType(channel_num, gcodec));
450 EXPECT_EQ(126, gcodec.pltype);
451 EXPECT_STREQ("telephone-event", gcodec.plname);
452}
453
454// Test that we fail to set an unknown inbound codec.
455TEST_F(WebRtcVoiceEngineTestFake, SetRecvCodecsUnsupportedCodec) {
456 EXPECT_TRUE(SetupEngine());
457 std::vector<cricket::AudioCodec> codecs;
458 codecs.push_back(kIsacCodec);
459 codecs.push_back(cricket::AudioCodec(127, "XYZ", 32000, 0, 1, 0));
460 EXPECT_FALSE(channel_->SetRecvCodecs(codecs));
461}
462
463// Test that we fail if we have duplicate types in the inbound list.
464TEST_F(WebRtcVoiceEngineTestFake, SetRecvCodecsDuplicatePayloadType) {
465 EXPECT_TRUE(SetupEngine());
466 std::vector<cricket::AudioCodec> codecs;
467 codecs.push_back(kIsacCodec);
468 codecs.push_back(kCn16000Codec);
469 codecs[1].id = kIsacCodec.id;
470 EXPECT_FALSE(channel_->SetRecvCodecs(codecs));
471}
472
473// Test that we can decode OPUS without stereo parameters.
474TEST_F(WebRtcVoiceEngineTestFake, SetRecvCodecsWithOpusNoStereo) {
475 EXPECT_TRUE(SetupEngine());
476 EXPECT_TRUE(channel_->SetOptions(options_conference_));
477 std::vector<cricket::AudioCodec> codecs;
478 codecs.push_back(kIsacCodec);
479 codecs.push_back(kPcmuCodec);
480 codecs.push_back(kOpusCodec);
481 EXPECT_TRUE(channel_->SetRecvCodecs(codecs));
482 EXPECT_TRUE(channel_->AddRecvStream(
483 cricket::StreamParams::CreateLegacy(kSsrc1)));
484 int channel_num2 = voe_.GetLastChannel();
485 webrtc::CodecInst opus;
486 engine_.FindWebRtcCodec(kOpusCodec, &opus);
487 // Even without stereo parameters, recv codecs still specify channels = 2.
488 EXPECT_EQ(2, opus.channels);
489 EXPECT_EQ(111, opus.pltype);
490 EXPECT_STREQ("opus", opus.plname);
491 opus.pltype = 0;
492 EXPECT_EQ(0, voe_.GetRecPayloadType(channel_num2, opus));
493 EXPECT_EQ(111, opus.pltype);
494}
495
496// Test that we can decode OPUS with stereo = 0.
497TEST_F(WebRtcVoiceEngineTestFake, SetRecvCodecsWithOpus0Stereo) {
498 EXPECT_TRUE(SetupEngine());
499 EXPECT_TRUE(channel_->SetOptions(options_conference_));
500 std::vector<cricket::AudioCodec> codecs;
501 codecs.push_back(kIsacCodec);
502 codecs.push_back(kPcmuCodec);
503 codecs.push_back(kOpusCodec);
504 codecs[2].params["stereo"] = "0";
505 EXPECT_TRUE(channel_->SetRecvCodecs(codecs));
506 EXPECT_TRUE(channel_->AddRecvStream(
507 cricket::StreamParams::CreateLegacy(kSsrc1)));
508 int channel_num2 = voe_.GetLastChannel();
509 webrtc::CodecInst opus;
510 engine_.FindWebRtcCodec(kOpusCodec, &opus);
511 // Even when stereo is off, recv codecs still specify channels = 2.
512 EXPECT_EQ(2, opus.channels);
513 EXPECT_EQ(111, opus.pltype);
514 EXPECT_STREQ("opus", opus.plname);
515 opus.pltype = 0;
516 EXPECT_EQ(0, voe_.GetRecPayloadType(channel_num2, opus));
517 EXPECT_EQ(111, opus.pltype);
518}
519
520// Test that we can decode OPUS with stereo = 1.
521TEST_F(WebRtcVoiceEngineTestFake, SetRecvCodecsWithOpus1Stereo) {
522 EXPECT_TRUE(SetupEngine());
523 EXPECT_TRUE(channel_->SetOptions(options_conference_));
524 std::vector<cricket::AudioCodec> codecs;
525 codecs.push_back(kIsacCodec);
526 codecs.push_back(kPcmuCodec);
527 codecs.push_back(kOpusCodec);
528 codecs[2].params["stereo"] = "1";
529 EXPECT_TRUE(channel_->SetRecvCodecs(codecs));
530 EXPECT_TRUE(channel_->AddRecvStream(
531 cricket::StreamParams::CreateLegacy(kSsrc1)));
532 int channel_num2 = voe_.GetLastChannel();
533 webrtc::CodecInst opus;
534 engine_.FindWebRtcCodec(kOpusCodec, &opus);
535 EXPECT_EQ(2, opus.channels);
536 EXPECT_EQ(111, opus.pltype);
537 EXPECT_STREQ("opus", opus.plname);
538 opus.pltype = 0;
539 EXPECT_EQ(0, voe_.GetRecPayloadType(channel_num2, opus));
540 EXPECT_EQ(111, opus.pltype);
541}
542
543// Test that changes to recv codecs are applied to all streams.
544TEST_F(WebRtcVoiceEngineTestFake, SetRecvCodecsWithMultipleStreams) {
545 EXPECT_TRUE(SetupEngine());
546 EXPECT_TRUE(channel_->SetOptions(options_conference_));
547 std::vector<cricket::AudioCodec> codecs;
548 codecs.push_back(kIsacCodec);
549 codecs.push_back(kPcmuCodec);
550 codecs.push_back(kTelephoneEventCodec);
551 codecs[0].id = 106; // collide with existing telephone-event
552 codecs[2].id = 126;
553 EXPECT_TRUE(channel_->SetRecvCodecs(codecs));
554 EXPECT_TRUE(channel_->AddRecvStream(
555 cricket::StreamParams::CreateLegacy(kSsrc1)));
556 int channel_num2 = voe_.GetLastChannel();
557 webrtc::CodecInst gcodec;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000558 rtc::strcpyn(gcodec.plname, ARRAY_SIZE(gcodec.plname), "ISAC");
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000559 gcodec.plfreq = 16000;
560 gcodec.channels = 1;
561 EXPECT_EQ(0, voe_.GetRecPayloadType(channel_num2, gcodec));
562 EXPECT_EQ(106, gcodec.pltype);
563 EXPECT_STREQ("ISAC", gcodec.plname);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000564 rtc::strcpyn(gcodec.plname, ARRAY_SIZE(gcodec.plname),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000565 "telephone-event");
566 gcodec.plfreq = 8000;
567 gcodec.channels = 1;
568 EXPECT_EQ(0, voe_.GetRecPayloadType(channel_num2, gcodec));
569 EXPECT_EQ(126, gcodec.pltype);
570 EXPECT_STREQ("telephone-event", gcodec.plname);
571}
572
573TEST_F(WebRtcVoiceEngineTestFake, SetRecvCodecsAfterAddingStreams) {
574 EXPECT_TRUE(SetupEngine());
575 EXPECT_TRUE(channel_->SetOptions(options_conference_));
576 std::vector<cricket::AudioCodec> codecs;
577 codecs.push_back(kIsacCodec);
578 codecs[0].id = 106; // collide with existing telephone-event
579
580 EXPECT_TRUE(channel_->AddRecvStream(
581 cricket::StreamParams::CreateLegacy(kSsrc1)));
582 EXPECT_TRUE(channel_->SetRecvCodecs(codecs));
583
584 int channel_num2 = voe_.GetLastChannel();
585 webrtc::CodecInst gcodec;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000586 rtc::strcpyn(gcodec.plname, ARRAY_SIZE(gcodec.plname), "ISAC");
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000587 gcodec.plfreq = 16000;
588 gcodec.channels = 1;
589 EXPECT_EQ(0, voe_.GetRecPayloadType(channel_num2, gcodec));
590 EXPECT_EQ(106, gcodec.pltype);
591 EXPECT_STREQ("ISAC", gcodec.plname);
592}
593
594// Test that we can apply the same set of codecs again while playing.
595TEST_F(WebRtcVoiceEngineTestFake, SetRecvCodecsWhilePlaying) {
596 EXPECT_TRUE(SetupEngine());
597 int channel_num = voe_.GetLastChannel();
598 std::vector<cricket::AudioCodec> codecs;
599 codecs.push_back(kIsacCodec);
600 codecs.push_back(kCn16000Codec);
601 EXPECT_TRUE(channel_->SetRecvCodecs(codecs));
602 EXPECT_TRUE(channel_->SetPlayout(true));
603 EXPECT_TRUE(channel_->SetRecvCodecs(codecs));
604
605 // Changing the payload type of a codec should fail.
606 codecs[0].id = 127;
607 EXPECT_FALSE(channel_->SetRecvCodecs(codecs));
608 EXPECT_TRUE(voe_.GetPlayout(channel_num));
609}
610
611// Test that we can add a codec while playing.
612TEST_F(WebRtcVoiceEngineTestFake, AddRecvCodecsWhilePlaying) {
613 EXPECT_TRUE(SetupEngine());
614 int channel_num = voe_.GetLastChannel();
615 std::vector<cricket::AudioCodec> codecs;
616 codecs.push_back(kIsacCodec);
617 codecs.push_back(kCn16000Codec);
618 EXPECT_TRUE(channel_->SetRecvCodecs(codecs));
619 EXPECT_TRUE(channel_->SetPlayout(true));
620
621 codecs.push_back(kOpusCodec);
622 EXPECT_TRUE(channel_->SetRecvCodecs(codecs));
623 EXPECT_TRUE(voe_.GetPlayout(channel_num));
624 webrtc::CodecInst gcodec;
625 EXPECT_TRUE(engine_.FindWebRtcCodec(kOpusCodec, &gcodec));
626 EXPECT_EQ(kOpusCodec.id, gcodec.pltype);
627}
628
629TEST_F(WebRtcVoiceEngineTestFake, SetSendBandwidthAuto) {
630 EXPECT_TRUE(SetupEngine());
631 EXPECT_TRUE(channel_->SetSendCodecs(engine_.codecs()));
632
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000633 // Test that when autobw is enabled, bitrate is kept as the default
634 // value. autobw is enabled for the following tests because the target
635 // bitrate is <= 0.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000636
637 // ISAC, default bitrate == 32000.
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000638 TestSendBandwidth(kIsacCodec, 0, true, 32000);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000639
640 // PCMU, default bitrate == 64000.
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000641 TestSendBandwidth(kPcmuCodec, -1, true, 64000);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000642
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000643 // opus, default bitrate == 64000.
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000644 TestSendBandwidth(kOpusCodec, -1, true, 64000);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000645}
646
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000647TEST_F(WebRtcVoiceEngineTestFake, SetMaxSendBandwidthMultiRateAsCaller) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000648 EXPECT_TRUE(SetupEngine());
649 EXPECT_TRUE(channel_->SetSendCodecs(engine_.codecs()));
650
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000651 // Test that the bitrate of a multi-rate codec is always the maximum.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000652
653 // ISAC, default bitrate == 32000.
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000654 TestSendBandwidth(kIsacCodec, 128000, true, 128000);
655 TestSendBandwidth(kIsacCodec, 16000, true, 16000);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000656
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000657 // opus, default bitrate == 64000.
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000658 TestSendBandwidth(kOpusCodec, 96000, true, 96000);
659 TestSendBandwidth(kOpusCodec, 48000, true, 48000);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000660}
661
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000662TEST_F(WebRtcVoiceEngineTestFake, SetMaxSendBandwidthFixedRateAsCaller) {
663 EXPECT_TRUE(SetupEngine());
664 EXPECT_TRUE(channel_->SetSendCodecs(engine_.codecs()));
665
666 // Test that we can only set a maximum bitrate for a fixed-rate codec
667 // if it's bigger than the fixed rate.
668
669 // PCMU, fixed bitrate == 64000.
670 TestSendBandwidth(kPcmuCodec, 0, true, 64000);
671 TestSendBandwidth(kPcmuCodec, 1, false, 64000);
672 TestSendBandwidth(kPcmuCodec, 128000, true, 64000);
673 TestSendBandwidth(kPcmuCodec, 32000, false, 64000);
674 TestSendBandwidth(kPcmuCodec, 64000, true, 64000);
675 TestSendBandwidth(kPcmuCodec, 63999, false, 64000);
676 TestSendBandwidth(kPcmuCodec, 64001, true, 64000);
677}
678
679TEST_F(WebRtcVoiceEngineTestFake, SetMaxSendBandwidthMultiRateAsCallee) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000680 EXPECT_TRUE(engine_.Init(rtc::Thread::Current()));
wu@webrtc.org1d1ffc92013-10-16 18:12:02 +0000681 channel_ = engine_.CreateChannel();
682 EXPECT_TRUE(channel_ != NULL);
683 EXPECT_TRUE(channel_->SetSendCodecs(engine_.codecs()));
684
685 int desired_bitrate = 128000;
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000686 EXPECT_TRUE(channel_->SetMaxSendBandwidth(desired_bitrate));
wu@webrtc.org1d1ffc92013-10-16 18:12:02 +0000687
688 EXPECT_TRUE(channel_->AddSendStream(
689 cricket::StreamParams::CreateLegacy(kSsrc1)));
690
691 int channel_num = voe_.GetLastChannel();
692 webrtc::CodecInst codec;
693 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, codec));
694 EXPECT_EQ(desired_bitrate, codec.rate);
695}
696
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000697// Test that bitrate cannot be set for CBR codecs.
698// Bitrate is ignored if it is higher than the fixed bitrate.
699// Bitrate less then the fixed bitrate is an error.
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000700TEST_F(WebRtcVoiceEngineTestFake, SetMaxSendBandwidthCbr) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000701 EXPECT_TRUE(SetupEngine());
702 EXPECT_TRUE(channel_->SetSendCodecs(engine_.codecs()));
703
704 webrtc::CodecInst codec;
705 int channel_num = voe_.GetLastChannel();
706 std::vector<cricket::AudioCodec> codecs;
707
708 // PCMU, default bitrate == 64000.
709 codecs.push_back(kPcmuCodec);
710 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
711 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, codec));
712 EXPECT_EQ(64000, codec.rate);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000713 EXPECT_TRUE(channel_->SetMaxSendBandwidth(128000));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000714 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, codec));
715 EXPECT_EQ(64000, codec.rate);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000716 EXPECT_FALSE(channel_->SetMaxSendBandwidth(128));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000717 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, codec));
718 EXPECT_EQ(64000, codec.rate);
719}
720
721// Test that we apply codecs properly.
722TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecs) {
723 EXPECT_TRUE(SetupEngine());
724 int channel_num = voe_.GetLastChannel();
725 std::vector<cricket::AudioCodec> codecs;
726 codecs.push_back(kIsacCodec);
727 codecs.push_back(kPcmuCodec);
728 codecs.push_back(kRedCodec);
729 codecs[0].id = 96;
730 codecs[0].bitrate = 48000;
731 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
wu@webrtc.org05e7b442014-04-01 17:44:24 +0000732 EXPECT_EQ(1, voe_.GetNumSetSendCodecs());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000733 webrtc::CodecInst gcodec;
734 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
735 EXPECT_EQ(96, gcodec.pltype);
736 EXPECT_EQ(48000, gcodec.rate);
737 EXPECT_STREQ("ISAC", gcodec.plname);
738 EXPECT_FALSE(voe_.GetVAD(channel_num));
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +0000739 EXPECT_FALSE(voe_.GetRED(channel_num));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000740 EXPECT_EQ(13, voe_.GetSendCNPayloadType(channel_num, false));
741 EXPECT_EQ(105, voe_.GetSendCNPayloadType(channel_num, true));
742 EXPECT_EQ(106, voe_.GetSendTelephoneEventPayloadType(channel_num));
743}
744
wu@webrtc.org05e7b442014-04-01 17:44:24 +0000745// Test that VoE Channel doesn't call SetSendCodec again if same codec is tried
746// to apply.
747TEST_F(WebRtcVoiceEngineTestFake, DontResetSetSendCodec) {
748 EXPECT_TRUE(SetupEngine());
749 std::vector<cricket::AudioCodec> codecs;
750 codecs.push_back(kIsacCodec);
751 codecs.push_back(kPcmuCodec);
752 codecs.push_back(kRedCodec);
753 codecs[0].id = 96;
754 codecs[0].bitrate = 48000;
755 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
756 EXPECT_EQ(1, voe_.GetNumSetSendCodecs());
757 // Calling SetSendCodec again with same codec which is already set.
758 // In this case media channel shouldn't send codec to VoE.
759 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
760 EXPECT_EQ(1, voe_.GetNumSetSendCodecs());
761}
762
henrik.lundin@webrtc.orgf85dbce2014-11-07 12:25:00 +0000763// Verify that G722 is set with 16000 samples per second to WebRTC.
764TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecG722) {
765 EXPECT_TRUE(SetupEngine());
766 int channel_num = voe_.GetLastChannel();
767 std::vector<cricket::AudioCodec> codecs;
768 codecs.push_back(kG722CodecSdp);
769 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
770 webrtc::CodecInst gcodec;
771 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
772 EXPECT_STREQ("G722", gcodec.plname);
773 EXPECT_EQ(1, gcodec.channels);
774 EXPECT_EQ(16000, gcodec.plfreq);
775}
776
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000777// Test that if clockrate is not 48000 for opus, we fail.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000778TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecOpusBadClockrate) {
779 EXPECT_TRUE(SetupEngine());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000780 std::vector<cricket::AudioCodec> codecs;
781 codecs.push_back(kOpusCodec);
782 codecs[0].bitrate = 0;
783 codecs[0].clockrate = 50000;
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000784 EXPECT_FALSE(channel_->SetSendCodecs(codecs));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000785}
786
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000787// Test that if channels=0 for opus, we fail.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000788TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecOpusBad0ChannelsNoStereo) {
789 EXPECT_TRUE(SetupEngine());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000790 std::vector<cricket::AudioCodec> codecs;
791 codecs.push_back(kOpusCodec);
792 codecs[0].bitrate = 0;
793 codecs[0].channels = 0;
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000794 EXPECT_FALSE(channel_->SetSendCodecs(codecs));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000795}
796
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000797// Test that if channels=0 for opus, we fail.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000798TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecOpusBad0Channels1Stereo) {
799 EXPECT_TRUE(SetupEngine());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000800 std::vector<cricket::AudioCodec> codecs;
801 codecs.push_back(kOpusCodec);
802 codecs[0].bitrate = 0;
803 codecs[0].channels = 0;
804 codecs[0].params["stereo"] = "1";
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000805 EXPECT_FALSE(channel_->SetSendCodecs(codecs));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000806}
807
808// Test that if channel is 1 for opus and there's no stereo, we fail.
809TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecOpus1ChannelNoStereo) {
810 EXPECT_TRUE(SetupEngine());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000811 std::vector<cricket::AudioCodec> codecs;
812 codecs.push_back(kOpusCodec);
813 codecs[0].bitrate = 0;
814 codecs[0].channels = 1;
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000815 EXPECT_FALSE(channel_->SetSendCodecs(codecs));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000816}
817
818// Test that if channel is 1 for opus and stereo=0, we fail.
819TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecOpusBad1Channel0Stereo) {
820 EXPECT_TRUE(SetupEngine());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000821 std::vector<cricket::AudioCodec> codecs;
822 codecs.push_back(kOpusCodec);
823 codecs[0].bitrate = 0;
824 codecs[0].channels = 1;
825 codecs[0].params["stereo"] = "0";
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000826 EXPECT_FALSE(channel_->SetSendCodecs(codecs));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000827}
828
829// Test that if channel is 1 for opus and stereo=1, we fail.
830TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecOpusBad1Channel1Stereo) {
831 EXPECT_TRUE(SetupEngine());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000832 std::vector<cricket::AudioCodec> codecs;
833 codecs.push_back(kOpusCodec);
834 codecs[0].bitrate = 0;
835 codecs[0].channels = 1;
836 codecs[0].params["stereo"] = "1";
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000837 EXPECT_FALSE(channel_->SetSendCodecs(codecs));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000838}
839
840// Test that with bitrate=0 and no stereo,
841// channels and bitrate are 1 and 32000.
842TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecOpusGood0BitrateNoStereo) {
843 EXPECT_TRUE(SetupEngine());
844 int channel_num = voe_.GetLastChannel();
845 std::vector<cricket::AudioCodec> codecs;
846 codecs.push_back(kOpusCodec);
847 codecs[0].bitrate = 0;
848 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
849 webrtc::CodecInst gcodec;
850 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
851 EXPECT_STREQ("opus", gcodec.plname);
852 EXPECT_EQ(1, gcodec.channels);
853 EXPECT_EQ(32000, gcodec.rate);
854}
855
856// Test that with bitrate=0 and stereo=0,
857// channels and bitrate are 1 and 32000.
858TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecOpusGood0Bitrate0Stereo) {
859 EXPECT_TRUE(SetupEngine());
860 int channel_num = voe_.GetLastChannel();
861 std::vector<cricket::AudioCodec> codecs;
862 codecs.push_back(kOpusCodec);
863 codecs[0].bitrate = 0;
864 codecs[0].params["stereo"] = "0";
865 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
866 webrtc::CodecInst gcodec;
867 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
868 EXPECT_STREQ("opus", gcodec.plname);
869 EXPECT_EQ(1, gcodec.channels);
870 EXPECT_EQ(32000, gcodec.rate);
871}
872
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000873// Test that with bitrate=invalid and stereo=0,
874// channels and bitrate are 1 and 32000.
875TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecOpusGoodXBitrate0Stereo) {
876 EXPECT_TRUE(SetupEngine());
877 int channel_num = voe_.GetLastChannel();
878 std::vector<cricket::AudioCodec> codecs;
879 codecs.push_back(kOpusCodec);
880 codecs[0].params["stereo"] = "0";
881 webrtc::CodecInst gcodec;
882
buildbot@webrtc.org9d446f22014-10-23 12:22:06 +0000883 // bitrate that's out of the range between 6000 and 510000 will be clamped.
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000884 codecs[0].bitrate = 5999;
885 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
886 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
887 EXPECT_STREQ("opus", gcodec.plname);
888 EXPECT_EQ(1, gcodec.channels);
buildbot@webrtc.org9d446f22014-10-23 12:22:06 +0000889 EXPECT_EQ(6000, gcodec.rate);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000890
891 codecs[0].bitrate = 510001;
892 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
893 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
894 EXPECT_STREQ("opus", gcodec.plname);
895 EXPECT_EQ(1, gcodec.channels);
buildbot@webrtc.org9d446f22014-10-23 12:22:06 +0000896 EXPECT_EQ(510000, gcodec.rate);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000897}
898
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000899// Test that with bitrate=0 and stereo=1,
900// channels and bitrate are 2 and 64000.
901TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecOpusGood0Bitrate1Stereo) {
902 EXPECT_TRUE(SetupEngine());
903 int channel_num = voe_.GetLastChannel();
904 std::vector<cricket::AudioCodec> codecs;
905 codecs.push_back(kOpusCodec);
906 codecs[0].bitrate = 0;
907 codecs[0].params["stereo"] = "1";
908 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
909 webrtc::CodecInst gcodec;
910 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
911 EXPECT_STREQ("opus", gcodec.plname);
912 EXPECT_EQ(2, gcodec.channels);
913 EXPECT_EQ(64000, gcodec.rate);
914}
915
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000916// Test that with bitrate=invalid and stereo=1,
917// channels and bitrate are 2 and 64000.
918TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecOpusGoodXBitrate1Stereo) {
919 EXPECT_TRUE(SetupEngine());
920 int channel_num = voe_.GetLastChannel();
921 std::vector<cricket::AudioCodec> codecs;
922 codecs.push_back(kOpusCodec);
923 codecs[0].params["stereo"] = "1";
924 webrtc::CodecInst gcodec;
925
buildbot@webrtc.org9d446f22014-10-23 12:22:06 +0000926 // bitrate that's out of the range between 6000 and 510000 will be clamped.
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000927 codecs[0].bitrate = 5999;
928 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
929 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
930 EXPECT_STREQ("opus", gcodec.plname);
931 EXPECT_EQ(2, gcodec.channels);
buildbot@webrtc.org9d446f22014-10-23 12:22:06 +0000932 EXPECT_EQ(6000, gcodec.rate);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000933
934 codecs[0].bitrate = 510001;
935 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
936 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
937 EXPECT_STREQ("opus", gcodec.plname);
938 EXPECT_EQ(2, gcodec.channels);
buildbot@webrtc.org9d446f22014-10-23 12:22:06 +0000939 EXPECT_EQ(510000, gcodec.rate);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000940}
941
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000942// Test that with bitrate=N and stereo unset,
943// channels and bitrate are 1 and N.
944TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecOpusGoodNBitrateNoStereo) {
945 EXPECT_TRUE(SetupEngine());
946 int channel_num = voe_.GetLastChannel();
947 std::vector<cricket::AudioCodec> codecs;
948 codecs.push_back(kOpusCodec);
949 codecs[0].bitrate = 96000;
950 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
951 webrtc::CodecInst gcodec;
952 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
953 EXPECT_EQ(111, gcodec.pltype);
954 EXPECT_EQ(96000, gcodec.rate);
955 EXPECT_STREQ("opus", gcodec.plname);
956 EXPECT_EQ(1, gcodec.channels);
957 EXPECT_EQ(48000, gcodec.plfreq);
958}
959
960// Test that with bitrate=N and stereo=0,
961// channels and bitrate are 1 and N.
962TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecOpusGoodNBitrate0Stereo) {
963 EXPECT_TRUE(SetupEngine());
964 int channel_num = voe_.GetLastChannel();
965 std::vector<cricket::AudioCodec> codecs;
966 codecs.push_back(kOpusCodec);
967 codecs[0].bitrate = 30000;
968 codecs[0].params["stereo"] = "0";
969 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
970 webrtc::CodecInst gcodec;
971 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
972 EXPECT_EQ(1, gcodec.channels);
973 EXPECT_EQ(30000, gcodec.rate);
974 EXPECT_STREQ("opus", gcodec.plname);
975}
976
977// Test that with bitrate=N and without any parameters,
978// channels and bitrate are 1 and N.
979TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecOpusGoodNBitrateNoParameters) {
980 EXPECT_TRUE(SetupEngine());
981 int channel_num = voe_.GetLastChannel();
982 std::vector<cricket::AudioCodec> codecs;
983 codecs.push_back(kOpusCodec);
984 codecs[0].bitrate = 30000;
985 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
986 webrtc::CodecInst gcodec;
987 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
988 EXPECT_EQ(1, gcodec.channels);
989 EXPECT_EQ(30000, gcodec.rate);
990 EXPECT_STREQ("opus", gcodec.plname);
991}
992
993// Test that with bitrate=N and stereo=1,
994// channels and bitrate are 2 and N.
995TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecOpusGoodNBitrate1Stereo) {
996 EXPECT_TRUE(SetupEngine());
997 int channel_num = voe_.GetLastChannel();
998 std::vector<cricket::AudioCodec> codecs;
999 codecs.push_back(kOpusCodec);
1000 codecs[0].bitrate = 30000;
1001 codecs[0].params["stereo"] = "1";
1002 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1003 webrtc::CodecInst gcodec;
1004 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1005 EXPECT_EQ(2, gcodec.channels);
1006 EXPECT_EQ(30000, gcodec.rate);
1007 EXPECT_STREQ("opus", gcodec.plname);
1008}
1009
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00001010// Test that bitrate will be overridden by the "maxaveragebitrate" parameter.
1011// Also test that the "maxaveragebitrate" can't be set to values outside the
1012// range of 6000 and 510000
1013TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecOpusMaxAverageBitrate) {
1014 EXPECT_TRUE(SetupEngine());
1015 int channel_num = voe_.GetLastChannel();
1016 std::vector<cricket::AudioCodec> codecs;
1017 codecs.push_back(kOpusCodec);
1018 codecs[0].bitrate = 30000;
1019 webrtc::CodecInst gcodec;
1020
1021 // Ignore if less than 6000.
1022 codecs[0].params["maxaveragebitrate"] = "5999";
1023 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1024 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
buildbot@webrtc.org9d446f22014-10-23 12:22:06 +00001025 EXPECT_EQ(6000, gcodec.rate);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00001026
1027 // Ignore if larger than 510000.
1028 codecs[0].params["maxaveragebitrate"] = "510001";
1029 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1030 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
buildbot@webrtc.org9d446f22014-10-23 12:22:06 +00001031 EXPECT_EQ(510000, gcodec.rate);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00001032
1033 codecs[0].params["maxaveragebitrate"] = "200000";
1034 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1035 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1036 EXPECT_EQ(200000, gcodec.rate);
1037}
1038
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00001039// Test that we can enable NACK with opus as caller.
1040TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecEnableNackAsCaller) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001041 EXPECT_TRUE(SetupEngine());
1042 int channel_num = voe_.GetLastChannel();
1043 std::vector<cricket::AudioCodec> codecs;
1044 codecs.push_back(kOpusCodec);
1045 codecs[0].AddFeedbackParam(cricket::FeedbackParam(cricket::kRtcpFbParamNack,
1046 cricket::kParamValueEmpty));
1047 EXPECT_FALSE(voe_.GetNACK(channel_num));
1048 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1049 EXPECT_TRUE(voe_.GetNACK(channel_num));
1050}
1051
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00001052// Test that we can enable NACK with opus as callee.
1053TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecEnableNackAsCallee) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001054 EXPECT_TRUE(engine_.Init(rtc::Thread::Current()));
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00001055 channel_ = engine_.CreateChannel();
1056 EXPECT_TRUE(channel_ != NULL);
1057
1058 int channel_num = voe_.GetLastChannel();
1059 std::vector<cricket::AudioCodec> codecs;
1060 codecs.push_back(kOpusCodec);
1061 codecs[0].AddFeedbackParam(cricket::FeedbackParam(cricket::kRtcpFbParamNack,
1062 cricket::kParamValueEmpty));
1063 EXPECT_FALSE(voe_.GetNACK(channel_num));
1064 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1065 EXPECT_FALSE(voe_.GetNACK(channel_num));
1066
1067 EXPECT_TRUE(channel_->AddSendStream(
1068 cricket::StreamParams::CreateLegacy(kSsrc1)));
1069 EXPECT_TRUE(voe_.GetNACK(channel_num));
1070}
1071
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001072// Test that we can enable NACK on receive streams.
1073TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecEnableNackRecvStreams) {
1074 EXPECT_TRUE(SetupEngine());
1075 EXPECT_TRUE(channel_->SetOptions(options_conference_));
1076 int channel_num1 = voe_.GetLastChannel();
1077 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(2)));
1078 int channel_num2 = voe_.GetLastChannel();
1079 std::vector<cricket::AudioCodec> codecs;
1080 codecs.push_back(kOpusCodec);
1081 codecs[0].AddFeedbackParam(cricket::FeedbackParam(cricket::kRtcpFbParamNack,
1082 cricket::kParamValueEmpty));
1083 EXPECT_FALSE(voe_.GetNACK(channel_num1));
1084 EXPECT_FALSE(voe_.GetNACK(channel_num2));
1085 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1086 EXPECT_TRUE(voe_.GetNACK(channel_num1));
1087 EXPECT_TRUE(voe_.GetNACK(channel_num2));
1088}
1089
1090// Test that we can disable NACK.
1091TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecDisableNack) {
1092 EXPECT_TRUE(SetupEngine());
1093 int channel_num = voe_.GetLastChannel();
1094 std::vector<cricket::AudioCodec> codecs;
1095 codecs.push_back(kOpusCodec);
1096 codecs[0].AddFeedbackParam(cricket::FeedbackParam(cricket::kRtcpFbParamNack,
1097 cricket::kParamValueEmpty));
1098 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1099 EXPECT_TRUE(voe_.GetNACK(channel_num));
1100
1101 codecs.clear();
1102 codecs.push_back(kOpusCodec);
1103 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1104 EXPECT_FALSE(voe_.GetNACK(channel_num));
1105}
1106
1107// Test that we can disable NACK on receive streams.
1108TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecDisableNackRecvStreams) {
1109 EXPECT_TRUE(SetupEngine());
1110 EXPECT_TRUE(channel_->SetOptions(options_conference_));
1111 int channel_num1 = voe_.GetLastChannel();
1112 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(2)));
1113 int channel_num2 = voe_.GetLastChannel();
1114 std::vector<cricket::AudioCodec> codecs;
1115 codecs.push_back(kOpusCodec);
1116 codecs[0].AddFeedbackParam(cricket::FeedbackParam(cricket::kRtcpFbParamNack,
1117 cricket::kParamValueEmpty));
1118 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1119 EXPECT_TRUE(voe_.GetNACK(channel_num1));
1120 EXPECT_TRUE(voe_.GetNACK(channel_num2));
1121
1122 codecs.clear();
1123 codecs.push_back(kOpusCodec);
1124 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1125 EXPECT_FALSE(voe_.GetNACK(channel_num1));
1126 EXPECT_FALSE(voe_.GetNACK(channel_num2));
1127}
1128
1129// Test that NACK is enabled on a new receive stream.
1130TEST_F(WebRtcVoiceEngineTestFake, AddRecvStreamEnableNack) {
1131 EXPECT_TRUE(SetupEngine());
1132 EXPECT_TRUE(channel_->SetOptions(options_conference_));
1133 int channel_num = voe_.GetLastChannel();
1134 std::vector<cricket::AudioCodec> codecs;
1135 codecs.push_back(kIsacCodec);
1136 codecs[0].AddFeedbackParam(cricket::FeedbackParam(cricket::kRtcpFbParamNack,
1137 cricket::kParamValueEmpty));
1138 codecs.push_back(kCn16000Codec);
1139 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1140 EXPECT_TRUE(voe_.GetNACK(channel_num));
1141
1142 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(2)));
1143 channel_num = voe_.GetLastChannel();
1144 EXPECT_TRUE(voe_.GetNACK(channel_num));
1145 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(3)));
1146 channel_num = voe_.GetLastChannel();
1147 EXPECT_TRUE(voe_.GetNACK(channel_num));
1148}
1149
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +00001150// Test that without useinbandfec, Opus FEC is off.
buildbot@webrtc.orgd27d9ae2014-06-19 01:56:46 +00001151TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecNoOpusFec) {
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +00001152 EXPECT_TRUE(SetupEngine());
1153 int channel_num = voe_.GetLastChannel();
1154 std::vector<cricket::AudioCodec> codecs;
1155 codecs.push_back(kOpusCodec);
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +00001156 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1157 EXPECT_FALSE(voe_.GetCodecFEC(channel_num));
1158}
1159
1160// Test that with useinbandfec=0, Opus FEC is off.
buildbot@webrtc.orgd27d9ae2014-06-19 01:56:46 +00001161TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecOpusDisableFec) {
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +00001162 EXPECT_TRUE(SetupEngine());
1163 int channel_num = voe_.GetLastChannel();
1164 std::vector<cricket::AudioCodec> codecs;
1165 codecs.push_back(kOpusCodec);
1166 codecs[0].bitrate = 0;
1167 codecs[0].params["useinbandfec"] = "0";
1168 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1169 EXPECT_FALSE(voe_.GetCodecFEC(channel_num));
1170 webrtc::CodecInst gcodec;
1171 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1172 EXPECT_STREQ("opus", gcodec.plname);
1173 EXPECT_EQ(1, gcodec.channels);
1174 EXPECT_EQ(32000, gcodec.rate);
1175}
1176
1177// Test that with useinbandfec=1, Opus FEC is on.
buildbot@webrtc.orgd27d9ae2014-06-19 01:56:46 +00001178TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecOpusEnableFec) {
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +00001179 EXPECT_TRUE(SetupEngine());
1180 int channel_num = voe_.GetLastChannel();
1181 std::vector<cricket::AudioCodec> codecs;
1182 codecs.push_back(kOpusCodec);
1183 codecs[0].bitrate = 0;
1184 codecs[0].params["useinbandfec"] = "1";
1185 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1186 EXPECT_TRUE(voe_.GetCodecFEC(channel_num));
1187 webrtc::CodecInst gcodec;
1188 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1189 EXPECT_STREQ("opus", gcodec.plname);
1190 EXPECT_EQ(1, gcodec.channels);
1191 EXPECT_EQ(32000, gcodec.rate);
1192}
1193
1194// Test that with useinbandfec=1, stereo=1, Opus FEC is on.
buildbot@webrtc.orgd27d9ae2014-06-19 01:56:46 +00001195TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecOpusEnableFecStereo) {
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +00001196 EXPECT_TRUE(SetupEngine());
1197 int channel_num = voe_.GetLastChannel();
1198 std::vector<cricket::AudioCodec> codecs;
1199 codecs.push_back(kOpusCodec);
1200 codecs[0].bitrate = 0;
1201 codecs[0].params["stereo"] = "1";
1202 codecs[0].params["useinbandfec"] = "1";
1203 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1204 EXPECT_TRUE(voe_.GetCodecFEC(channel_num));
1205 webrtc::CodecInst gcodec;
1206 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1207 EXPECT_STREQ("opus", gcodec.plname);
1208 EXPECT_EQ(2, gcodec.channels);
1209 EXPECT_EQ(64000, gcodec.rate);
1210}
1211
1212// Test that with non-Opus, codec FEC is off.
buildbot@webrtc.orgd27d9ae2014-06-19 01:56:46 +00001213TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecIsacNoFec) {
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +00001214 EXPECT_TRUE(SetupEngine());
1215 int channel_num = voe_.GetLastChannel();
1216 std::vector<cricket::AudioCodec> codecs;
1217 codecs.push_back(kIsacCodec);
1218 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1219 EXPECT_FALSE(voe_.GetCodecFEC(channel_num));
1220}
buildbot@webrtc.org3ffa1f92014-07-02 19:51:26 +00001221
1222// Test the with non-Opus, even if useinbandfec=1, FEC is off.
1223TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecIsacWithParamNoFec) {
1224 EXPECT_TRUE(SetupEngine());
1225 int channel_num = voe_.GetLastChannel();
1226 std::vector<cricket::AudioCodec> codecs;
1227 codecs.push_back(kIsacCodec);
1228 codecs[0].params["useinbandfec"] = "1";
1229 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1230 EXPECT_FALSE(voe_.GetCodecFEC(channel_num));
1231}
buildbot@webrtc.org5d639b32014-09-10 07:57:12 +00001232
1233// Test that Opus FEC status can be changed.
1234TEST_F(WebRtcVoiceEngineTestFake, ChangeOpusFecStatus) {
1235 EXPECT_TRUE(SetupEngine());
1236 int channel_num = voe_.GetLastChannel();
1237 std::vector<cricket::AudioCodec> codecs;
1238 codecs.push_back(kOpusCodec);
1239 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1240 EXPECT_FALSE(voe_.GetCodecFEC(channel_num));
1241 codecs[0].params["useinbandfec"] = "1";
1242 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1243 EXPECT_TRUE(voe_.GetCodecFEC(channel_num));
1244}
1245
1246// Test maxplaybackrate <= 8000 triggers Opus narrow band mode.
1247TEST_F(WebRtcVoiceEngineTestFake, SetOpusMaxPlaybackRateNb) {
1248 EXPECT_TRUE(SetupEngine());
1249 int channel_num = voe_.GetLastChannel();
1250 std::vector<cricket::AudioCodec> codecs;
1251 codecs.push_back(kOpusCodec);
1252 codecs[0].bitrate = 0;
1253 codecs[0].SetParam(cricket::kCodecParamMaxPlaybackRate, 8000);
1254 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1255 EXPECT_EQ(cricket::kOpusBandwidthNb,
1256 voe_.GetMaxEncodingBandwidth(channel_num));
1257 webrtc::CodecInst gcodec;
1258 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1259 EXPECT_STREQ("opus", gcodec.plname);
minyue@webrtc.org2dc6f312014-10-31 05:33:10 +00001260
1261 EXPECT_EQ(12000, gcodec.rate);
1262 codecs[0].SetParam(cricket::kCodecParamStereo, "1");
1263 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1264 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1265 EXPECT_EQ(24000, gcodec.rate);
buildbot@webrtc.org5d639b32014-09-10 07:57:12 +00001266}
1267
1268// Test 8000 < maxplaybackrate <= 12000 triggers Opus medium band mode.
1269TEST_F(WebRtcVoiceEngineTestFake, SetOpusMaxPlaybackRateMb) {
1270 EXPECT_TRUE(SetupEngine());
1271 int channel_num = voe_.GetLastChannel();
1272 std::vector<cricket::AudioCodec> codecs;
1273 codecs.push_back(kOpusCodec);
1274 codecs[0].bitrate = 0;
1275 codecs[0].SetParam(cricket::kCodecParamMaxPlaybackRate, 8001);
1276 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1277 EXPECT_EQ(cricket::kOpusBandwidthMb,
1278 voe_.GetMaxEncodingBandwidth(channel_num));
1279 webrtc::CodecInst gcodec;
1280 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1281 EXPECT_STREQ("opus", gcodec.plname);
minyue@webrtc.org2dc6f312014-10-31 05:33:10 +00001282
1283 EXPECT_EQ(20000, gcodec.rate);
1284 codecs[0].SetParam(cricket::kCodecParamStereo, "1");
1285 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1286 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1287 EXPECT_EQ(40000, gcodec.rate);
buildbot@webrtc.org5d639b32014-09-10 07:57:12 +00001288}
1289
1290// Test 12000 < maxplaybackrate <= 16000 triggers Opus wide band mode.
1291TEST_F(WebRtcVoiceEngineTestFake, SetOpusMaxPlaybackRateWb) {
1292 EXPECT_TRUE(SetupEngine());
1293 int channel_num = voe_.GetLastChannel();
1294 std::vector<cricket::AudioCodec> codecs;
1295 codecs.push_back(kOpusCodec);
1296 codecs[0].bitrate = 0;
1297 codecs[0].SetParam(cricket::kCodecParamMaxPlaybackRate, 12001);
1298 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1299 EXPECT_EQ(cricket::kOpusBandwidthWb,
1300 voe_.GetMaxEncodingBandwidth(channel_num));
1301 webrtc::CodecInst gcodec;
1302 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1303 EXPECT_STREQ("opus", gcodec.plname);
minyue@webrtc.org2dc6f312014-10-31 05:33:10 +00001304
1305 EXPECT_EQ(20000, gcodec.rate);
1306 codecs[0].SetParam(cricket::kCodecParamStereo, "1");
1307 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1308 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1309 EXPECT_EQ(40000, gcodec.rate);
buildbot@webrtc.org5d639b32014-09-10 07:57:12 +00001310}
1311
1312// Test 16000 < maxplaybackrate <= 24000 triggers Opus super wide band mode.
1313TEST_F(WebRtcVoiceEngineTestFake, SetOpusMaxPlaybackRateSwb) {
1314 EXPECT_TRUE(SetupEngine());
1315 int channel_num = voe_.GetLastChannel();
1316 std::vector<cricket::AudioCodec> codecs;
1317 codecs.push_back(kOpusCodec);
1318 codecs[0].bitrate = 0;
1319 codecs[0].SetParam(cricket::kCodecParamMaxPlaybackRate, 16001);
1320 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1321 EXPECT_EQ(cricket::kOpusBandwidthSwb,
1322 voe_.GetMaxEncodingBandwidth(channel_num));
1323 webrtc::CodecInst gcodec;
1324 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1325 EXPECT_STREQ("opus", gcodec.plname);
minyue@webrtc.org2dc6f312014-10-31 05:33:10 +00001326
buildbot@webrtc.org5d639b32014-09-10 07:57:12 +00001327 EXPECT_EQ(32000, gcodec.rate);
minyue@webrtc.org2dc6f312014-10-31 05:33:10 +00001328 codecs[0].SetParam(cricket::kCodecParamStereo, "1");
1329 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1330 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1331 EXPECT_EQ(64000, gcodec.rate);
buildbot@webrtc.org5d639b32014-09-10 07:57:12 +00001332}
1333
1334// Test 24000 < maxplaybackrate triggers Opus full band mode.
1335TEST_F(WebRtcVoiceEngineTestFake, SetOpusMaxPlaybackRateFb) {
1336 EXPECT_TRUE(SetupEngine());
1337 int channel_num = voe_.GetLastChannel();
1338 std::vector<cricket::AudioCodec> codecs;
1339 codecs.push_back(kOpusCodec);
1340 codecs[0].bitrate = 0;
1341 codecs[0].SetParam(cricket::kCodecParamMaxPlaybackRate, 24001);
1342 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1343 EXPECT_EQ(cricket::kOpusBandwidthFb,
1344 voe_.GetMaxEncodingBandwidth(channel_num));
1345 webrtc::CodecInst gcodec;
1346 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1347 EXPECT_STREQ("opus", gcodec.plname);
minyue@webrtc.org2dc6f312014-10-31 05:33:10 +00001348
buildbot@webrtc.org5d639b32014-09-10 07:57:12 +00001349 EXPECT_EQ(32000, gcodec.rate);
minyue@webrtc.org2dc6f312014-10-31 05:33:10 +00001350 codecs[0].SetParam(cricket::kCodecParamStereo, "1");
1351 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1352 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1353 EXPECT_EQ(64000, gcodec.rate);
buildbot@webrtc.org5d639b32014-09-10 07:57:12 +00001354}
1355
1356// Test Opus that without maxplaybackrate, default playback rate is used.
1357TEST_F(WebRtcVoiceEngineTestFake, DefaultOpusMaxPlaybackRate) {
1358 EXPECT_TRUE(SetupEngine());
1359 int channel_num = voe_.GetLastChannel();
1360 std::vector<cricket::AudioCodec> codecs;
1361 codecs.push_back(kOpusCodec);
1362 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1363 EXPECT_EQ(cricket::kOpusBandwidthFb,
1364 voe_.GetMaxEncodingBandwidth(channel_num));
1365}
1366
1367// Test the with non-Opus, maxplaybackrate has no effect.
1368TEST_F(WebRtcVoiceEngineTestFake, SetNonOpusMaxPlaybackRate) {
1369 EXPECT_TRUE(SetupEngine());
1370 int channel_num = voe_.GetLastChannel();
1371 std::vector<cricket::AudioCodec> codecs;
1372 codecs.push_back(kIsacCodec);
1373 codecs[0].SetParam(cricket::kCodecParamMaxPlaybackRate, 32000);
1374 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1375 EXPECT_EQ(0, voe_.GetMaxEncodingBandwidth(channel_num));
1376}
1377
1378// Test maxplaybackrate can be set on two streams.
1379TEST_F(WebRtcVoiceEngineTestFake, SetOpusMaxPlaybackRateOnTwoStreams) {
1380 EXPECT_TRUE(SetupEngine());
1381 int channel_num = voe_.GetLastChannel();
1382 std::vector<cricket::AudioCodec> codecs;
1383 codecs.push_back(kOpusCodec);
1384 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1385 // Default bandwidth is 24000.
1386 EXPECT_EQ(cricket::kOpusBandwidthFb,
1387 voe_.GetMaxEncodingBandwidth(channel_num));
1388
1389 codecs[0].SetParam(cricket::kCodecParamMaxPlaybackRate, 8000);
1390
1391 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1392 EXPECT_EQ(cricket::kOpusBandwidthNb,
1393 voe_.GetMaxEncodingBandwidth(channel_num));
1394
1395 channel_->AddSendStream(cricket::StreamParams::CreateLegacy(kSsrc2));
1396 channel_num = voe_.GetLastChannel();
1397 EXPECT_EQ(cricket::kOpusBandwidthNb,
1398 voe_.GetMaxEncodingBandwidth(channel_num));
1399}
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +00001400
Minyue Li7100dcd2015-03-27 05:05:59 +01001401// Test that with usedtx=0, Opus DTX is off.
1402TEST_F(WebRtcVoiceEngineTestFake, DisableOpusDtxOnOpus) {
1403 EXPECT_TRUE(SetupEngine());
1404 int channel_num = voe_.GetLastChannel();
1405 std::vector<cricket::AudioCodec> codecs;
1406 codecs.push_back(kOpusCodec);
1407 codecs[0].params["usedtx"] = "0";
1408 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1409 EXPECT_FALSE(voe_.GetOpusDtx(channel_num));
1410}
1411
1412// Test that with usedtx=1, Opus DTX is on.
1413TEST_F(WebRtcVoiceEngineTestFake, EnableOpusDtxOnOpus) {
1414 EXPECT_TRUE(SetupEngine());
1415 int channel_num = voe_.GetLastChannel();
1416 std::vector<cricket::AudioCodec> codecs;
1417 codecs.push_back(kOpusCodec);
1418 codecs[0].params["usedtx"] = "1";
1419 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1420 EXPECT_TRUE(voe_.GetOpusDtx(channel_num));
1421 EXPECT_FALSE(voe_.GetVAD(channel_num)); // Opus DTX should not affect VAD.
1422}
1423
1424// Test that usedtx=1 works with stereo Opus.
1425TEST_F(WebRtcVoiceEngineTestFake, EnableOpusDtxOnOpusStereo) {
1426 EXPECT_TRUE(SetupEngine());
1427 int channel_num = voe_.GetLastChannel();
1428 std::vector<cricket::AudioCodec> codecs;
1429 codecs.push_back(kOpusCodec);
1430 codecs[0].params["usedtx"] = "1";
1431 codecs[0].params["stereo"] = "1";
1432 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1433 EXPECT_TRUE(voe_.GetOpusDtx(channel_num));
1434 EXPECT_FALSE(voe_.GetVAD(channel_num)); // Opus DTX should not affect VAD.
1435}
1436
1437// Test that usedtx=1 does not work with non Opus.
1438TEST_F(WebRtcVoiceEngineTestFake, CannotEnableOpusDtxOnNonOpus) {
1439 EXPECT_TRUE(SetupEngine());
1440 int channel_num = voe_.GetLastChannel();
1441 std::vector<cricket::AudioCodec> codecs;
1442 codecs.push_back(kIsacCodec);
1443 codecs[0].params["usedtx"] = "1";
1444 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1445 EXPECT_FALSE(voe_.GetOpusDtx(channel_num));
1446}
1447
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +00001448// Test that we can switch back and forth between Opus and ISAC with CN.
1449TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecsIsacOpusSwitching) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001450 EXPECT_TRUE(SetupEngine());
1451 int channel_num = voe_.GetLastChannel();
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +00001452 std::vector<cricket::AudioCodec> opus_codecs;
1453 opus_codecs.push_back(kOpusCodec);
1454 EXPECT_TRUE(channel_->SetSendCodecs(opus_codecs));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001455 webrtc::CodecInst gcodec;
1456 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +00001457 EXPECT_EQ(111, gcodec.pltype);
1458 EXPECT_STREQ("opus", gcodec.plname);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001459
1460 std::vector<cricket::AudioCodec> isac_codecs;
1461 isac_codecs.push_back(kIsacCodec);
1462 isac_codecs.push_back(kCn16000Codec);
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +00001463 isac_codecs.push_back(kOpusCodec);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001464 EXPECT_TRUE(channel_->SetSendCodecs(isac_codecs));
1465 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1466 EXPECT_EQ(103, gcodec.pltype);
1467 EXPECT_STREQ("ISAC", gcodec.plname);
1468
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +00001469 EXPECT_TRUE(channel_->SetSendCodecs(opus_codecs));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001470 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +00001471 EXPECT_EQ(111, gcodec.pltype);
1472 EXPECT_STREQ("opus", gcodec.plname);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001473}
1474
1475// Test that we handle various ways of specifying bitrate.
1476TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecsBitrate) {
1477 EXPECT_TRUE(SetupEngine());
1478 int channel_num = voe_.GetLastChannel();
1479 std::vector<cricket::AudioCodec> codecs;
1480 codecs.push_back(kIsacCodec); // bitrate == 32000
1481 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1482 webrtc::CodecInst gcodec;
1483 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1484 EXPECT_EQ(103, gcodec.pltype);
1485 EXPECT_STREQ("ISAC", gcodec.plname);
1486 EXPECT_EQ(32000, gcodec.rate);
1487
1488 codecs[0].bitrate = 0; // bitrate == default
1489 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1490 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1491 EXPECT_EQ(103, gcodec.pltype);
1492 EXPECT_STREQ("ISAC", gcodec.plname);
1493 EXPECT_EQ(-1, gcodec.rate);
1494
1495 codecs[0].bitrate = 28000; // bitrate == 28000
1496 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1497 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1498 EXPECT_EQ(103, gcodec.pltype);
1499 EXPECT_STREQ("ISAC", gcodec.plname);
1500 EXPECT_EQ(28000, gcodec.rate);
1501
1502 codecs[0] = kPcmuCodec; // bitrate == 64000
1503 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1504 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1505 EXPECT_EQ(0, gcodec.pltype);
1506 EXPECT_STREQ("PCMU", gcodec.plname);
1507 EXPECT_EQ(64000, gcodec.rate);
1508
1509 codecs[0].bitrate = 0; // bitrate == default
1510 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1511 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1512 EXPECT_EQ(0, gcodec.pltype);
1513 EXPECT_STREQ("PCMU", gcodec.plname);
1514 EXPECT_EQ(64000, gcodec.rate);
1515
1516 codecs[0] = kOpusCodec;
1517 codecs[0].bitrate = 0; // bitrate == default
1518 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1519 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1520 EXPECT_EQ(111, gcodec.pltype);
1521 EXPECT_STREQ("opus", gcodec.plname);
1522 EXPECT_EQ(32000, gcodec.rate);
1523}
1524
Brave Yao5225dd82015-03-26 07:39:19 +08001525// Test that we could set packet size specified in kCodecParamPTime.
1526TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecsPTimeAsPacketSize) {
1527 EXPECT_TRUE(SetupEngine());
1528 int channel_num = voe_.GetLastChannel();
1529 std::vector<cricket::AudioCodec> codecs;
1530 codecs.push_back(kOpusCodec);
1531 codecs[0].SetParam(cricket::kCodecParamPTime, 40); // Value within range.
1532 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1533 webrtc::CodecInst gcodec;
1534 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1535 EXPECT_EQ(1920, gcodec.pacsize); // Opus gets 40ms.
1536
1537 codecs[0].SetParam(cricket::kCodecParamPTime, 5); // Value below range.
1538 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1539 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1540 EXPECT_EQ(480, gcodec.pacsize); // Opus gets 10ms.
1541
1542 codecs[0].SetParam(cricket::kCodecParamPTime, 80); // Value beyond range.
1543 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1544 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1545 EXPECT_EQ(2880, gcodec.pacsize); // Opus gets 60ms.
1546
1547 codecs[0] = kIsacCodec; // Also try Isac, and with unsupported size.
1548 codecs[0].SetParam(cricket::kCodecParamPTime, 40); // Value within range.
1549 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1550 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1551 EXPECT_EQ(480, gcodec.pacsize); // Isac gets 30ms as the next smallest value.
1552
1553 codecs[0] = kG722CodecSdp; // Try G722 @8kHz as negotiated in SDP.
1554 codecs[0].SetParam(cricket::kCodecParamPTime, 40);
1555 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1556 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1557 EXPECT_EQ(640, gcodec.pacsize); // G722 gets 40ms @16kHz as defined in VoE.
1558}
1559
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00001560// Test that we fail if no codecs are specified.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001561TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecsNoCodecs) {
1562 EXPECT_TRUE(SetupEngine());
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00001563 std::vector<cricket::AudioCodec> codecs;
1564 EXPECT_FALSE(channel_->SetSendCodecs(codecs));
1565}
1566
1567// Test that we can set send codecs even with telephone-event codec as the first
1568// one on the list.
1569TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecsDTMFOnTop) {
1570 EXPECT_TRUE(SetupEngine());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001571 int channel_num = voe_.GetLastChannel();
1572 std::vector<cricket::AudioCodec> codecs;
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00001573 codecs.push_back(kTelephoneEventCodec);
1574 codecs.push_back(kIsacCodec);
1575 codecs.push_back(kPcmuCodec);
1576 codecs[0].id = 98; // DTMF
1577 codecs[1].id = 96;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001578 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1579 webrtc::CodecInst gcodec;
1580 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00001581 EXPECT_EQ(96, gcodec.pltype);
1582 EXPECT_STREQ("ISAC", gcodec.plname);
1583 EXPECT_EQ(98, voe_.GetSendTelephoneEventPayloadType(channel_num));
1584}
1585
1586// Test that we can set send codecs even with CN codec as the first
1587// one on the list.
1588TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecsCNOnTop) {
1589 EXPECT_TRUE(SetupEngine());
1590 int channel_num = voe_.GetLastChannel();
1591 std::vector<cricket::AudioCodec> codecs;
1592 codecs.push_back(kCn16000Codec);
1593 codecs.push_back(kIsacCodec);
1594 codecs.push_back(kPcmuCodec);
1595 codecs[0].id = 98; // wideband CN
1596 codecs[1].id = 96;
1597 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1598 webrtc::CodecInst gcodec;
1599 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1600 EXPECT_EQ(96, gcodec.pltype);
1601 EXPECT_STREQ("ISAC", gcodec.plname);
1602 EXPECT_EQ(98, voe_.GetSendCNPayloadType(channel_num, true));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001603}
1604
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00001605// Test that we set VAD and DTMF types correctly as caller.
1606TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecsCNandDTMFAsCaller) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001607 EXPECT_TRUE(SetupEngine());
1608 int channel_num = voe_.GetLastChannel();
1609 std::vector<cricket::AudioCodec> codecs;
1610 codecs.push_back(kIsacCodec);
1611 codecs.push_back(kPcmuCodec);
1612 // TODO(juberti): cn 32000
1613 codecs.push_back(kCn16000Codec);
1614 codecs.push_back(kCn8000Codec);
1615 codecs.push_back(kTelephoneEventCodec);
1616 codecs.push_back(kRedCodec);
1617 codecs[0].id = 96;
1618 codecs[2].id = 97; // wideband CN
1619 codecs[4].id = 98; // DTMF
1620 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1621 webrtc::CodecInst gcodec;
1622 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1623 EXPECT_EQ(96, gcodec.pltype);
1624 EXPECT_STREQ("ISAC", gcodec.plname);
1625 EXPECT_TRUE(voe_.GetVAD(channel_num));
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +00001626 EXPECT_FALSE(voe_.GetRED(channel_num));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001627 EXPECT_EQ(13, voe_.GetSendCNPayloadType(channel_num, false));
1628 EXPECT_EQ(97, voe_.GetSendCNPayloadType(channel_num, true));
1629 EXPECT_EQ(98, voe_.GetSendTelephoneEventPayloadType(channel_num));
1630}
1631
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00001632// Test that we set VAD and DTMF types correctly as callee.
1633TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecsCNandDTMFAsCallee) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001634 EXPECT_TRUE(engine_.Init(rtc::Thread::Current()));
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00001635 channel_ = engine_.CreateChannel();
1636 EXPECT_TRUE(channel_ != NULL);
1637
1638 int channel_num = voe_.GetLastChannel();
1639 std::vector<cricket::AudioCodec> codecs;
1640 codecs.push_back(kIsacCodec);
1641 codecs.push_back(kPcmuCodec);
1642 // TODO(juberti): cn 32000
1643 codecs.push_back(kCn16000Codec);
1644 codecs.push_back(kCn8000Codec);
1645 codecs.push_back(kTelephoneEventCodec);
1646 codecs.push_back(kRedCodec);
1647 codecs[0].id = 96;
1648 codecs[2].id = 97; // wideband CN
1649 codecs[4].id = 98; // DTMF
1650 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1651 EXPECT_TRUE(channel_->AddSendStream(
1652 cricket::StreamParams::CreateLegacy(kSsrc1)));
1653
1654 webrtc::CodecInst gcodec;
1655 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1656 EXPECT_EQ(96, gcodec.pltype);
1657 EXPECT_STREQ("ISAC", gcodec.plname);
1658 EXPECT_TRUE(voe_.GetVAD(channel_num));
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +00001659 EXPECT_FALSE(voe_.GetRED(channel_num));
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00001660 EXPECT_EQ(13, voe_.GetSendCNPayloadType(channel_num, false));
1661 EXPECT_EQ(97, voe_.GetSendCNPayloadType(channel_num, true));
1662 EXPECT_EQ(98, voe_.GetSendTelephoneEventPayloadType(channel_num));
1663}
1664
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001665// Test that we only apply VAD if we have a CN codec that matches the
1666// send codec clockrate.
1667TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecsCNNoMatch) {
1668 EXPECT_TRUE(SetupEngine());
1669 int channel_num = voe_.GetLastChannel();
1670 std::vector<cricket::AudioCodec> codecs;
1671 // Set ISAC(16K) and CN(16K). VAD should be activated.
1672 codecs.push_back(kIsacCodec);
1673 codecs.push_back(kCn16000Codec);
1674 codecs[1].id = 97;
1675 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1676 webrtc::CodecInst gcodec;
1677 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1678 EXPECT_STREQ("ISAC", gcodec.plname);
1679 EXPECT_TRUE(voe_.GetVAD(channel_num));
1680 EXPECT_EQ(97, voe_.GetSendCNPayloadType(channel_num, true));
1681 // Set PCMU(8K) and CN(16K). VAD should not be activated.
1682 codecs[0] = kPcmuCodec;
1683 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1684 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1685 EXPECT_STREQ("PCMU", gcodec.plname);
1686 EXPECT_FALSE(voe_.GetVAD(channel_num));
1687 // Set PCMU(8K) and CN(8K). VAD should be activated.
1688 codecs[1] = kCn8000Codec;
1689 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1690 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1691 EXPECT_STREQ("PCMU", gcodec.plname);
1692 EXPECT_TRUE(voe_.GetVAD(channel_num));
1693 EXPECT_EQ(13, voe_.GetSendCNPayloadType(channel_num, false));
Brave Yao5225dd82015-03-26 07:39:19 +08001694 // Set ISAC(16K) and CN(8K). VAD should not be activated.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001695 codecs[0] = kIsacCodec;
1696 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1697 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1698 EXPECT_STREQ("ISAC", gcodec.plname);
1699 EXPECT_FALSE(voe_.GetVAD(channel_num));
1700}
1701
1702// Test that we perform case-insensitive matching of codec names.
1703TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecsCaseInsensitive) {
1704 EXPECT_TRUE(SetupEngine());
1705 int channel_num = voe_.GetLastChannel();
1706 std::vector<cricket::AudioCodec> codecs;
1707 codecs.push_back(kIsacCodec);
1708 codecs.push_back(kPcmuCodec);
1709 codecs.push_back(kCn16000Codec);
1710 codecs.push_back(kCn8000Codec);
1711 codecs.push_back(kTelephoneEventCodec);
1712 codecs.push_back(kRedCodec);
1713 codecs[0].name = "iSaC";
1714 codecs[0].id = 96;
1715 codecs[2].id = 97; // wideband CN
1716 codecs[4].id = 98; // DTMF
1717 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1718 webrtc::CodecInst gcodec;
1719 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1720 EXPECT_EQ(96, gcodec.pltype);
1721 EXPECT_STREQ("ISAC", gcodec.plname);
1722 EXPECT_TRUE(voe_.GetVAD(channel_num));
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +00001723 EXPECT_FALSE(voe_.GetRED(channel_num));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001724 EXPECT_EQ(13, voe_.GetSendCNPayloadType(channel_num, false));
1725 EXPECT_EQ(97, voe_.GetSendCNPayloadType(channel_num, true));
1726 EXPECT_EQ(98, voe_.GetSendTelephoneEventPayloadType(channel_num));
1727}
1728
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +00001729// Test that we set up RED correctly as caller.
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00001730TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecsREDAsCaller) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001731 EXPECT_TRUE(SetupEngine());
1732 int channel_num = voe_.GetLastChannel();
1733 std::vector<cricket::AudioCodec> codecs;
1734 codecs.push_back(kRedCodec);
1735 codecs.push_back(kIsacCodec);
1736 codecs.push_back(kPcmuCodec);
1737 codecs[0].id = 127;
1738 codecs[0].params[""] = "96/96";
1739 codecs[1].id = 96;
1740 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1741 webrtc::CodecInst gcodec;
1742 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1743 EXPECT_EQ(96, gcodec.pltype);
1744 EXPECT_STREQ("ISAC", gcodec.plname);
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +00001745 EXPECT_TRUE(voe_.GetRED(channel_num));
1746 EXPECT_EQ(127, voe_.GetSendREDPayloadType(channel_num));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001747}
1748
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +00001749// Test that we set up RED correctly as callee.
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00001750TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecsREDAsCallee) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001751 EXPECT_TRUE(engine_.Init(rtc::Thread::Current()));
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00001752 channel_ = engine_.CreateChannel();
1753 EXPECT_TRUE(channel_ != NULL);
1754
1755 int channel_num = voe_.GetLastChannel();
1756 std::vector<cricket::AudioCodec> codecs;
1757 codecs.push_back(kRedCodec);
1758 codecs.push_back(kIsacCodec);
1759 codecs.push_back(kPcmuCodec);
1760 codecs[0].id = 127;
1761 codecs[0].params[""] = "96/96";
1762 codecs[1].id = 96;
1763 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1764 EXPECT_TRUE(channel_->AddSendStream(
1765 cricket::StreamParams::CreateLegacy(kSsrc1)));
1766 webrtc::CodecInst gcodec;
1767 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1768 EXPECT_EQ(96, gcodec.pltype);
1769 EXPECT_STREQ("ISAC", gcodec.plname);
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +00001770 EXPECT_TRUE(voe_.GetRED(channel_num));
1771 EXPECT_EQ(127, voe_.GetSendREDPayloadType(channel_num));
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00001772}
1773
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +00001774// Test that we set up RED correctly if params are omitted.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001775TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecsREDNoParams) {
1776 EXPECT_TRUE(SetupEngine());
1777 int channel_num = voe_.GetLastChannel();
1778 std::vector<cricket::AudioCodec> codecs;
1779 codecs.push_back(kRedCodec);
1780 codecs.push_back(kIsacCodec);
1781 codecs.push_back(kPcmuCodec);
1782 codecs[0].id = 127;
1783 codecs[1].id = 96;
1784 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1785 webrtc::CodecInst gcodec;
1786 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1787 EXPECT_EQ(96, gcodec.pltype);
1788 EXPECT_STREQ("ISAC", gcodec.plname);
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +00001789 EXPECT_TRUE(voe_.GetRED(channel_num));
1790 EXPECT_EQ(127, voe_.GetSendREDPayloadType(channel_num));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001791}
1792
1793// Test that we ignore RED if the parameters aren't named the way we expect.
1794TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecsBadRED1) {
1795 EXPECT_TRUE(SetupEngine());
1796 int channel_num = voe_.GetLastChannel();
1797 std::vector<cricket::AudioCodec> codecs;
1798 codecs.push_back(kRedCodec);
1799 codecs.push_back(kIsacCodec);
1800 codecs.push_back(kPcmuCodec);
1801 codecs[0].id = 127;
1802 codecs[0].params["ABC"] = "96/96";
1803 codecs[1].id = 96;
1804 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1805 webrtc::CodecInst gcodec;
1806 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1807 EXPECT_EQ(96, gcodec.pltype);
1808 EXPECT_STREQ("ISAC", gcodec.plname);
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +00001809 EXPECT_FALSE(voe_.GetRED(channel_num));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001810}
1811
1812// Test that we ignore RED if it uses different primary/secondary encoding.
1813TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecsBadRED2) {
1814 EXPECT_TRUE(SetupEngine());
1815 int channel_num = voe_.GetLastChannel();
1816 std::vector<cricket::AudioCodec> codecs;
1817 codecs.push_back(kRedCodec);
1818 codecs.push_back(kIsacCodec);
1819 codecs.push_back(kPcmuCodec);
1820 codecs[0].id = 127;
1821 codecs[0].params[""] = "96/0";
1822 codecs[1].id = 96;
1823 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1824 webrtc::CodecInst gcodec;
1825 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1826 EXPECT_EQ(96, gcodec.pltype);
1827 EXPECT_STREQ("ISAC", gcodec.plname);
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +00001828 EXPECT_FALSE(voe_.GetRED(channel_num));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001829}
1830
1831// Test that we ignore RED if it uses more than 2 encodings.
1832TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecsBadRED3) {
1833 EXPECT_TRUE(SetupEngine());
1834 int channel_num = voe_.GetLastChannel();
1835 std::vector<cricket::AudioCodec> codecs;
1836 codecs.push_back(kRedCodec);
1837 codecs.push_back(kIsacCodec);
1838 codecs.push_back(kPcmuCodec);
1839 codecs[0].id = 127;
1840 codecs[0].params[""] = "96/96/96";
1841 codecs[1].id = 96;
1842 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1843 webrtc::CodecInst gcodec;
1844 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1845 EXPECT_EQ(96, gcodec.pltype);
1846 EXPECT_STREQ("ISAC", gcodec.plname);
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +00001847 EXPECT_FALSE(voe_.GetRED(channel_num));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001848}
1849
1850// Test that we ignore RED if it has bogus codec ids.
1851TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecsBadRED4) {
1852 EXPECT_TRUE(SetupEngine());
1853 int channel_num = voe_.GetLastChannel();
1854 std::vector<cricket::AudioCodec> codecs;
1855 codecs.push_back(kRedCodec);
1856 codecs.push_back(kIsacCodec);
1857 codecs.push_back(kPcmuCodec);
1858 codecs[0].id = 127;
1859 codecs[0].params[""] = "ABC/ABC";
1860 codecs[1].id = 96;
1861 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1862 webrtc::CodecInst gcodec;
1863 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1864 EXPECT_EQ(96, gcodec.pltype);
1865 EXPECT_STREQ("ISAC", gcodec.plname);
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +00001866 EXPECT_FALSE(voe_.GetRED(channel_num));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001867}
1868
1869// Test that we ignore RED if it refers to a codec that is not present.
1870TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecsBadRED5) {
1871 EXPECT_TRUE(SetupEngine());
1872 int channel_num = voe_.GetLastChannel();
1873 std::vector<cricket::AudioCodec> codecs;
1874 codecs.push_back(kRedCodec);
1875 codecs.push_back(kIsacCodec);
1876 codecs.push_back(kPcmuCodec);
1877 codecs[0].id = 127;
1878 codecs[0].params[""] = "97/97";
1879 codecs[1].id = 96;
1880 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1881 webrtc::CodecInst gcodec;
1882 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1883 EXPECT_EQ(96, gcodec.pltype);
1884 EXPECT_STREQ("ISAC", gcodec.plname);
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +00001885 EXPECT_FALSE(voe_.GetRED(channel_num));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001886}
1887
buildbot@webrtc.org150835e2014-05-06 15:54:38 +00001888// Test support for audio level header extension.
1889TEST_F(WebRtcVoiceEngineTestFake, SendAudioLevelHeaderExtensions) {
1890 TestSetSendRtpHeaderExtensions(kRtpAudioLevelHeaderExtension);
henrike@webrtc.org79047f92014-03-06 23:46:59 +00001891}
buildbot@webrtc.org150835e2014-05-06 15:54:38 +00001892TEST_F(WebRtcVoiceEngineTestFake, RecvAudioLevelHeaderExtensions) {
1893 TestSetRecvRtpHeaderExtensions(kRtpAudioLevelHeaderExtension);
1894}
henrike@webrtc.org79047f92014-03-06 23:46:59 +00001895
buildbot@webrtc.org150835e2014-05-06 15:54:38 +00001896// Test support for absolute send time header extension.
1897TEST_F(WebRtcVoiceEngineTestFake, SendAbsoluteSendTimeHeaderExtensions) {
1898 TestSetSendRtpHeaderExtensions(kRtpAbsoluteSenderTimeHeaderExtension);
1899}
1900TEST_F(WebRtcVoiceEngineTestFake, RecvAbsoluteSendTimeHeaderExtensions) {
1901 TestSetRecvRtpHeaderExtensions(kRtpAbsoluteSenderTimeHeaderExtension);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001902}
1903
1904// Test that we can create a channel and start sending/playing out on it.
1905TEST_F(WebRtcVoiceEngineTestFake, SendAndPlayout) {
1906 EXPECT_TRUE(SetupEngine());
1907 int channel_num = voe_.GetLastChannel();
1908 std::vector<cricket::AudioCodec> codecs;
1909 codecs.push_back(kPcmuCodec);
1910 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1911 EXPECT_TRUE(channel_->SetSend(cricket::SEND_MICROPHONE));
1912 EXPECT_TRUE(voe_.GetSend(channel_num));
1913 EXPECT_TRUE(channel_->SetPlayout(true));
1914 EXPECT_TRUE(voe_.GetPlayout(channel_num));
1915 EXPECT_TRUE(channel_->SetSend(cricket::SEND_NOTHING));
1916 EXPECT_FALSE(voe_.GetSend(channel_num));
1917 EXPECT_TRUE(channel_->SetPlayout(false));
1918 EXPECT_FALSE(voe_.GetPlayout(channel_num));
1919}
1920
wu@webrtc.org9dba5252013-08-05 20:36:57 +00001921// Test that we can add and remove send streams.
1922TEST_F(WebRtcVoiceEngineTestFake, CreateAndDeleteMultipleSendStreams) {
1923 SetupForMultiSendStream();
1924
1925 static const uint32 kSsrcs4[] = {1, 2, 3, 4};
1926
1927 // Set the global state for sending.
1928 EXPECT_TRUE(channel_->SetSend(cricket::SEND_MICROPHONE));
1929
1930 for (unsigned int i = 0; i < ARRAY_SIZE(kSsrcs4); ++i) {
1931 EXPECT_TRUE(channel_->AddSendStream(
1932 cricket::StreamParams::CreateLegacy(kSsrcs4[i])));
1933
1934 // Verify that we are in a sending state for all the created streams.
1935 int channel_num = voe_.GetChannelFromLocalSsrc(kSsrcs4[i]);
1936 EXPECT_TRUE(voe_.GetSend(channel_num));
1937 }
1938
1939 // Remove the first send channel, which is the default channel. It will only
1940 // recycle the default channel but not delete it.
1941 EXPECT_TRUE(channel_->RemoveSendStream(kSsrcs4[0]));
1942 // Stream should already be Removed from the send stream list.
1943 EXPECT_FALSE(channel_->RemoveSendStream(kSsrcs4[0]));
1944 // But the default still exists.
1945 EXPECT_EQ(0, voe_.GetChannelFromLocalSsrc(kSsrcs4[0]));
1946
1947 // Delete the rest of send channel streams.
1948 for (unsigned int i = 1; i < ARRAY_SIZE(kSsrcs4); ++i) {
1949 EXPECT_TRUE(channel_->RemoveSendStream(kSsrcs4[i]));
1950 // Stream should already be deleted.
1951 EXPECT_FALSE(channel_->RemoveSendStream(kSsrcs4[i]));
1952 EXPECT_EQ(-1, voe_.GetChannelFromLocalSsrc(kSsrcs4[i]));
1953 }
1954}
1955
1956// Test SetSendCodecs correctly configure the codecs in all send streams.
1957TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecsWithMultipleSendStreams) {
1958 SetupForMultiSendStream();
1959
1960 static const uint32 kSsrcs4[] = {1, 2, 3, 4};
1961 // Create send streams.
1962 for (unsigned int i = 0; i < ARRAY_SIZE(kSsrcs4); ++i) {
1963 EXPECT_TRUE(channel_->AddSendStream(
1964 cricket::StreamParams::CreateLegacy(kSsrcs4[i])));
1965 }
1966
1967 std::vector<cricket::AudioCodec> codecs;
1968 // Set ISAC(16K) and CN(16K). VAD should be activated.
1969 codecs.push_back(kIsacCodec);
1970 codecs.push_back(kCn16000Codec);
1971 codecs[1].id = 97;
1972 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1973
1974 // Verify ISAC and VAD are corrected configured on all send channels.
1975 webrtc::CodecInst gcodec;
1976 for (unsigned int i = 0; i < ARRAY_SIZE(kSsrcs4); ++i) {
1977 int channel_num = voe_.GetChannelFromLocalSsrc(kSsrcs4[i]);
1978 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1979 EXPECT_STREQ("ISAC", gcodec.plname);
1980 EXPECT_TRUE(voe_.GetVAD(channel_num));
1981 EXPECT_EQ(97, voe_.GetSendCNPayloadType(channel_num, true));
1982 }
1983
1984 // Change to PCMU(8K) and CN(16K). VAD should not be activated.
1985 codecs[0] = kPcmuCodec;
1986 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1987 for (unsigned int i = 0; i < ARRAY_SIZE(kSsrcs4); ++i) {
1988 int channel_num = voe_.GetChannelFromLocalSsrc(kSsrcs4[i]);
1989 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1990 EXPECT_STREQ("PCMU", gcodec.plname);
1991 EXPECT_FALSE(voe_.GetVAD(channel_num));
1992 }
1993}
1994
1995// Test we can SetSend on all send streams correctly.
1996TEST_F(WebRtcVoiceEngineTestFake, SetSendWithMultipleSendStreams) {
1997 SetupForMultiSendStream();
1998
1999 static const uint32 kSsrcs4[] = {1, 2, 3, 4};
2000 // Create the send channels and they should be a SEND_NOTHING date.
2001 for (unsigned int i = 0; i < ARRAY_SIZE(kSsrcs4); ++i) {
2002 EXPECT_TRUE(channel_->AddSendStream(
2003 cricket::StreamParams::CreateLegacy(kSsrcs4[i])));
2004 int channel_num = voe_.GetLastChannel();
2005 EXPECT_FALSE(voe_.GetSend(channel_num));
2006 }
2007
2008 // Set the global state for starting sending.
2009 EXPECT_TRUE(channel_->SetSend(cricket::SEND_MICROPHONE));
2010 for (unsigned int i = 0; i < ARRAY_SIZE(kSsrcs4); ++i) {
2011 // Verify that we are in a sending state for all the send streams.
2012 int channel_num = voe_.GetChannelFromLocalSsrc(kSsrcs4[i]);
2013 EXPECT_TRUE(voe_.GetSend(channel_num));
2014 }
2015
2016 // Set the global state for stopping sending.
2017 EXPECT_TRUE(channel_->SetSend(cricket::SEND_NOTHING));
2018 for (unsigned int i = 1; i < ARRAY_SIZE(kSsrcs4); ++i) {
2019 // Verify that we are in a stop state for all the send streams.
2020 int channel_num = voe_.GetChannelFromLocalSsrc(kSsrcs4[i]);
2021 EXPECT_FALSE(voe_.GetSend(channel_num));
2022 }
2023}
2024
2025// Test we can set the correct statistics on all send streams.
2026TEST_F(WebRtcVoiceEngineTestFake, GetStatsWithMultipleSendStreams) {
2027 SetupForMultiSendStream();
2028
2029 static const uint32 kSsrcs4[] = {1, 2, 3, 4};
2030 // Create send streams.
2031 for (unsigned int i = 0; i < ARRAY_SIZE(kSsrcs4); ++i) {
2032 EXPECT_TRUE(channel_->AddSendStream(
2033 cricket::StreamParams::CreateLegacy(kSsrcs4[i])));
2034 }
buildbot@webrtc.org7e71b772014-06-13 01:14:01 +00002035 // Create a receive stream to check that none of the send streams end up in
2036 // the receive stream stats.
2037 EXPECT_TRUE(channel_->AddRecvStream(
2038 cricket::StreamParams::CreateLegacy(kSsrc2)));
wu@webrtc.org9dba5252013-08-05 20:36:57 +00002039 // We need send codec to be set to get all stats.
2040 std::vector<cricket::AudioCodec> codecs;
2041 codecs.push_back(kPcmuCodec);
2042 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
buildbot@webrtc.org7e71b772014-06-13 01:14:01 +00002043 EXPECT_TRUE(channel_->SetRecvCodecs(codecs));
wu@webrtc.org9dba5252013-08-05 20:36:57 +00002044
2045 cricket::VoiceMediaInfo info;
2046 EXPECT_EQ(true, channel_->GetStats(&info));
2047 EXPECT_EQ(static_cast<size_t>(ARRAY_SIZE(kSsrcs4)), info.senders.size());
2048
2049 // Verify the statistic information is correct.
2050 for (unsigned int i = 0; i < ARRAY_SIZE(kSsrcs4); ++i) {
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +00002051 EXPECT_EQ(kSsrcs4[i], info.senders[i].ssrc());
wu@webrtc.org9dba5252013-08-05 20:36:57 +00002052 EXPECT_EQ(kPcmuCodec.name, info.senders[i].codec_name);
2053 EXPECT_EQ(cricket::kIntStatValue, info.senders[i].bytes_sent);
2054 EXPECT_EQ(cricket::kIntStatValue, info.senders[i].packets_sent);
2055 EXPECT_EQ(cricket::kIntStatValue, info.senders[i].packets_lost);
2056 EXPECT_EQ(cricket::kFractionLostStatValue, info.senders[i].fraction_lost);
2057 EXPECT_EQ(cricket::kIntStatValue, info.senders[i].ext_seqnum);
2058 EXPECT_EQ(cricket::kIntStatValue, info.senders[i].rtt_ms);
2059 EXPECT_EQ(cricket::kIntStatValue, info.senders[i].jitter_ms);
buildbot@webrtc.org7e71b772014-06-13 01:14:01 +00002060 EXPECT_EQ(kPcmuCodec.name, info.senders[i].codec_name);
wu@webrtc.org9dba5252013-08-05 20:36:57 +00002061 }
2062
buildbot@webrtc.org7e71b772014-06-13 01:14:01 +00002063 EXPECT_EQ(0u, info.receivers.size());
2064 DeliverPacket(kPcmuFrame, sizeof(kPcmuFrame));
2065 EXPECT_EQ(true, channel_->GetStats(&info));
2066
wu@webrtc.org9dba5252013-08-05 20:36:57 +00002067 EXPECT_EQ(1u, info.receivers.size());
buildbot@webrtc.org7e71b772014-06-13 01:14:01 +00002068 EXPECT_EQ(cricket::kIntStatValue, info.receivers[0].bytes_rcvd);
2069 EXPECT_EQ(cricket::kIntStatValue, info.receivers[0].packets_rcvd);
2070 EXPECT_EQ(cricket::kIntStatValue, info.receivers[0].packets_lost);
2071 EXPECT_EQ(cricket::kIntStatValue, info.receivers[0].ext_seqnum);
2072 EXPECT_EQ(kPcmuCodec.name, info.receivers[0].codec_name);
minyue@webrtc.orgc0bd7be2015-02-18 15:24:13 +00002073 EXPECT_EQ(static_cast<float>(cricket::kNetStats.currentExpandRate) /
2074 (1 << 14), info.receivers[0].expand_rate);
2075 EXPECT_EQ(static_cast<float>(cricket::kNetStats.currentSpeechExpandRate) /
2076 (1 << 14), info.receivers[0].speech_expand_rate);
2077 EXPECT_EQ(static_cast<float>(cricket::kNetStats.currentSecondaryDecodedRate) /
2078 (1 << 14), info.receivers[0].secondary_decoded_rate);
wu@webrtc.org9dba5252013-08-05 20:36:57 +00002079}
2080
wu@webrtc.org9dba5252013-08-05 20:36:57 +00002081// Test that we can add and remove receive streams, and do proper send/playout.
2082// We can receive on multiple streams while sending one stream.
2083TEST_F(WebRtcVoiceEngineTestFake, PlayoutWithMultipleStreams) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002084 EXPECT_TRUE(SetupEngine());
2085 int channel_num1 = voe_.GetLastChannel();
2086
2087 // Start playout on the default channel.
2088 EXPECT_TRUE(channel_->SetOptions(options_conference_));
2089 EXPECT_TRUE(channel_->SetPlayout(true));
2090 EXPECT_TRUE(voe_.GetPlayout(channel_num1));
2091
2092 // Adding another stream should disable playout on the default channel.
2093 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(2)));
2094 int channel_num2 = voe_.GetLastChannel();
2095 std::vector<cricket::AudioCodec> codecs;
2096 codecs.push_back(kPcmuCodec);
2097 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
2098 EXPECT_TRUE(channel_->SetSend(cricket::SEND_MICROPHONE));
2099 EXPECT_TRUE(voe_.GetSend(channel_num1));
2100 EXPECT_FALSE(voe_.GetSend(channel_num2));
2101
2102 // Make sure only the new channel is played out.
2103 EXPECT_FALSE(voe_.GetPlayout(channel_num1));
2104 EXPECT_TRUE(voe_.GetPlayout(channel_num2));
2105
2106 // Adding yet another stream should have stream 2 and 3 enabled for playout.
2107 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(3)));
2108 int channel_num3 = voe_.GetLastChannel();
2109 EXPECT_FALSE(voe_.GetPlayout(channel_num1));
2110 EXPECT_TRUE(voe_.GetPlayout(channel_num2));
2111 EXPECT_TRUE(voe_.GetPlayout(channel_num3));
2112 EXPECT_FALSE(voe_.GetSend(channel_num3));
2113
2114 // Stop sending.
2115 EXPECT_TRUE(channel_->SetSend(cricket::SEND_NOTHING));
2116 EXPECT_FALSE(voe_.GetSend(channel_num1));
2117 EXPECT_FALSE(voe_.GetSend(channel_num2));
2118 EXPECT_FALSE(voe_.GetSend(channel_num3));
2119
2120 // Stop playout.
2121 EXPECT_TRUE(channel_->SetPlayout(false));
2122 EXPECT_FALSE(voe_.GetPlayout(channel_num1));
2123 EXPECT_FALSE(voe_.GetPlayout(channel_num2));
2124 EXPECT_FALSE(voe_.GetPlayout(channel_num3));
2125
2126 // Restart playout and make sure the default channel still is not played out.
2127 EXPECT_TRUE(channel_->SetPlayout(true));
2128 EXPECT_FALSE(voe_.GetPlayout(channel_num1));
2129 EXPECT_TRUE(voe_.GetPlayout(channel_num2));
2130 EXPECT_TRUE(voe_.GetPlayout(channel_num3));
2131
2132 // Now remove the new streams and verify that the default channel is
2133 // played out again.
2134 EXPECT_TRUE(channel_->RemoveRecvStream(3));
2135 EXPECT_TRUE(channel_->RemoveRecvStream(2));
2136
2137 EXPECT_TRUE(voe_.GetPlayout(channel_num1));
2138}
2139
2140// Test that we can set the devices to use.
2141TEST_F(WebRtcVoiceEngineTestFake, SetDevices) {
2142 EXPECT_TRUE(SetupEngine());
2143 int channel_num = voe_.GetLastChannel();
2144 std::vector<cricket::AudioCodec> codecs;
2145 codecs.push_back(kPcmuCodec);
2146 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
2147
2148 cricket::Device default_dev(cricket::kFakeDefaultDeviceName,
2149 cricket::kFakeDefaultDeviceId);
2150 cricket::Device dev(cricket::kFakeDeviceName,
2151 cricket::kFakeDeviceId);
2152
2153 // Test SetDevices() while not sending or playing.
2154 EXPECT_TRUE(engine_.SetDevices(&default_dev, &default_dev));
2155
2156 // Test SetDevices() while sending and playing.
2157 EXPECT_TRUE(engine_.SetLocalMonitor(true));
2158 EXPECT_TRUE(channel_->SetSend(cricket::SEND_MICROPHONE));
2159 EXPECT_TRUE(channel_->SetPlayout(true));
2160 EXPECT_TRUE(voe_.GetRecordingMicrophone());
2161 EXPECT_TRUE(voe_.GetSend(channel_num));
2162 EXPECT_TRUE(voe_.GetPlayout(channel_num));
2163
2164 EXPECT_TRUE(engine_.SetDevices(&dev, &dev));
2165
2166 EXPECT_TRUE(voe_.GetRecordingMicrophone());
2167 EXPECT_TRUE(voe_.GetSend(channel_num));
2168 EXPECT_TRUE(voe_.GetPlayout(channel_num));
2169
2170 // Test that failure to open newly selected devices does not prevent opening
2171 // ones after that.
2172 voe_.set_fail_start_recording_microphone(true);
2173 voe_.set_playout_fail_channel(channel_num);
2174 voe_.set_send_fail_channel(channel_num);
2175
2176 EXPECT_FALSE(engine_.SetDevices(&default_dev, &default_dev));
2177
2178 EXPECT_FALSE(voe_.GetRecordingMicrophone());
2179 EXPECT_FALSE(voe_.GetSend(channel_num));
2180 EXPECT_FALSE(voe_.GetPlayout(channel_num));
2181
2182 voe_.set_fail_start_recording_microphone(false);
2183 voe_.set_playout_fail_channel(-1);
2184 voe_.set_send_fail_channel(-1);
2185
2186 EXPECT_TRUE(engine_.SetDevices(&dev, &dev));
2187
2188 EXPECT_TRUE(voe_.GetRecordingMicrophone());
2189 EXPECT_TRUE(voe_.GetSend(channel_num));
2190 EXPECT_TRUE(voe_.GetPlayout(channel_num));
2191}
2192
2193// Test that we can set the devices to use even if we failed to
2194// open the initial ones.
2195TEST_F(WebRtcVoiceEngineTestFake, SetDevicesWithInitiallyBadDevices) {
2196 EXPECT_TRUE(SetupEngine());
2197 int channel_num = voe_.GetLastChannel();
2198 std::vector<cricket::AudioCodec> codecs;
2199 codecs.push_back(kPcmuCodec);
2200 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
2201
2202 cricket::Device default_dev(cricket::kFakeDefaultDeviceName,
2203 cricket::kFakeDefaultDeviceId);
2204 cricket::Device dev(cricket::kFakeDeviceName,
2205 cricket::kFakeDeviceId);
2206
2207 // Test that failure to open devices selected before starting
2208 // send/play does not prevent opening newly selected ones after that.
2209 voe_.set_fail_start_recording_microphone(true);
2210 voe_.set_playout_fail_channel(channel_num);
2211 voe_.set_send_fail_channel(channel_num);
2212
2213 EXPECT_TRUE(engine_.SetDevices(&default_dev, &default_dev));
2214
2215 EXPECT_FALSE(engine_.SetLocalMonitor(true));
2216 EXPECT_FALSE(channel_->SetSend(cricket::SEND_MICROPHONE));
2217 EXPECT_FALSE(channel_->SetPlayout(true));
2218 EXPECT_FALSE(voe_.GetRecordingMicrophone());
2219 EXPECT_FALSE(voe_.GetSend(channel_num));
2220 EXPECT_FALSE(voe_.GetPlayout(channel_num));
2221
2222 voe_.set_fail_start_recording_microphone(false);
2223 voe_.set_playout_fail_channel(-1);
2224 voe_.set_send_fail_channel(-1);
2225
2226 EXPECT_TRUE(engine_.SetDevices(&dev, &dev));
2227
2228 EXPECT_TRUE(voe_.GetRecordingMicrophone());
2229 EXPECT_TRUE(voe_.GetSend(channel_num));
2230 EXPECT_TRUE(voe_.GetPlayout(channel_num));
2231}
2232
2233// Test that we can create a channel configured for multi-point conferences,
2234// and start sending/playing out on it.
2235TEST_F(WebRtcVoiceEngineTestFake, ConferenceSendAndPlayout) {
2236 EXPECT_TRUE(SetupEngine());
2237 int channel_num = voe_.GetLastChannel();
2238 EXPECT_TRUE(channel_->SetOptions(options_conference_));
2239 std::vector<cricket::AudioCodec> codecs;
2240 codecs.push_back(kPcmuCodec);
2241 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
2242 EXPECT_TRUE(channel_->SetSend(cricket::SEND_MICROPHONE));
2243 EXPECT_TRUE(voe_.GetSend(channel_num));
2244}
2245
2246// Test that we can create a channel configured for Codian bridges,
2247// and start sending/playing out on it.
2248TEST_F(WebRtcVoiceEngineTestFake, CodianSendAndPlayout) {
2249 EXPECT_TRUE(SetupEngine());
2250 int channel_num = voe_.GetLastChannel();
2251 webrtc::AgcConfig agc_config;
2252 EXPECT_EQ(0, voe_.GetAgcConfig(agc_config));
2253 EXPECT_EQ(0, agc_config.targetLeveldBOv);
2254 EXPECT_TRUE(channel_->SetOptions(options_adjust_agc_));
2255 std::vector<cricket::AudioCodec> codecs;
2256 codecs.push_back(kPcmuCodec);
2257 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
2258 EXPECT_TRUE(channel_->SetSend(cricket::SEND_MICROPHONE));
2259 EXPECT_TRUE(voe_.GetSend(channel_num));
2260 EXPECT_EQ(0, voe_.GetAgcConfig(agc_config));
2261 EXPECT_EQ(agc_config.targetLeveldBOv, 10); // level was attenuated
2262 EXPECT_TRUE(channel_->SetPlayout(true));
2263 EXPECT_TRUE(voe_.GetPlayout(channel_num));
2264 EXPECT_TRUE(channel_->SetSend(cricket::SEND_NOTHING));
2265 EXPECT_FALSE(voe_.GetSend(channel_num));
2266 EXPECT_EQ(0, voe_.GetAgcConfig(agc_config));
2267 EXPECT_EQ(0, agc_config.targetLeveldBOv); // level was restored
2268 EXPECT_TRUE(channel_->SetPlayout(false));
2269 EXPECT_FALSE(voe_.GetPlayout(channel_num));
2270}
2271
wu@webrtc.org97077a32013-10-25 21:18:33 +00002272TEST_F(WebRtcVoiceEngineTestFake, TxAgcConfigViaOptions) {
2273 EXPECT_TRUE(SetupEngine());
2274 webrtc::AgcConfig agc_config;
2275 EXPECT_EQ(0, voe_.GetAgcConfig(agc_config));
2276 EXPECT_EQ(0, agc_config.targetLeveldBOv);
2277
2278 cricket::AudioOptions options;
2279 options.tx_agc_target_dbov.Set(3);
2280 options.tx_agc_digital_compression_gain.Set(9);
2281 options.tx_agc_limiter.Set(true);
2282 options.auto_gain_control.Set(true);
2283 EXPECT_TRUE(engine_.SetOptions(options));
2284
2285 EXPECT_EQ(0, voe_.GetAgcConfig(agc_config));
2286 EXPECT_EQ(3, agc_config.targetLeveldBOv);
2287 EXPECT_EQ(9, agc_config.digitalCompressionGaindB);
2288 EXPECT_TRUE(agc_config.limiterEnable);
2289
2290 // Check interaction with adjust_agc_delta. Both should be respected, for
2291 // backwards compatibility.
2292 options.adjust_agc_delta.Set(-10);
2293 EXPECT_TRUE(engine_.SetOptions(options));
2294
2295 EXPECT_EQ(0, voe_.GetAgcConfig(agc_config));
2296 EXPECT_EQ(13, agc_config.targetLeveldBOv);
2297}
2298
2299TEST_F(WebRtcVoiceEngineTestFake, RxAgcConfigViaOptions) {
2300 EXPECT_TRUE(SetupEngine());
2301 int channel_num = voe_.GetLastChannel();
2302 cricket::AudioOptions options;
2303 options.rx_agc_target_dbov.Set(6);
2304 options.rx_agc_digital_compression_gain.Set(0);
2305 options.rx_agc_limiter.Set(true);
2306 options.rx_auto_gain_control.Set(true);
2307 EXPECT_TRUE(channel_->SetOptions(options));
2308
2309 webrtc::AgcConfig agc_config;
2310 EXPECT_EQ(0, engine_.voe()->processing()->GetRxAgcConfig(
2311 channel_num, agc_config));
2312 EXPECT_EQ(6, agc_config.targetLeveldBOv);
2313 EXPECT_EQ(0, agc_config.digitalCompressionGaindB);
2314 EXPECT_TRUE(agc_config.limiterEnable);
2315}
2316
2317TEST_F(WebRtcVoiceEngineTestFake, SampleRatesViaOptions) {
2318 EXPECT_TRUE(SetupEngine());
2319 cricket::AudioOptions options;
2320 options.recording_sample_rate.Set(48000u);
2321 options.playout_sample_rate.Set(44100u);
2322 EXPECT_TRUE(engine_.SetOptions(options));
2323
2324 unsigned int recording_sample_rate, playout_sample_rate;
2325 EXPECT_EQ(0, voe_.RecordingSampleRate(&recording_sample_rate));
2326 EXPECT_EQ(0, voe_.PlayoutSampleRate(&playout_sample_rate));
2327 EXPECT_EQ(48000u, recording_sample_rate);
2328 EXPECT_EQ(44100u, playout_sample_rate);
2329}
2330
2331TEST_F(WebRtcVoiceEngineTestFake, TraceFilterViaTraceOptions) {
2332 EXPECT_TRUE(SetupEngine());
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002333 engine_.SetLogging(rtc::LS_INFO, "");
wu@webrtc.org97077a32013-10-25 21:18:33 +00002334 EXPECT_EQ(
2335 // Info:
2336 webrtc::kTraceStateInfo | webrtc::kTraceInfo |
2337 // Warning:
2338 webrtc::kTraceTerseInfo | webrtc::kTraceWarning |
2339 // Error:
2340 webrtc::kTraceError | webrtc::kTraceCritical,
2341 static_cast<int>(trace_wrapper_->filter_));
2342 // Now set it explicitly
2343 std::string filter =
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002344 "tracefilter " + rtc::ToString(webrtc::kTraceDefault);
2345 engine_.SetLogging(rtc::LS_VERBOSE, filter.c_str());
wu@webrtc.org97077a32013-10-25 21:18:33 +00002346 EXPECT_EQ(static_cast<unsigned int>(webrtc::kTraceDefault),
2347 trace_wrapper_->filter_);
2348}
2349
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002350// Test that we can set the outgoing SSRC properly.
2351// SSRC is set in SetupEngine by calling AddSendStream.
2352TEST_F(WebRtcVoiceEngineTestFake, SetSendSsrc) {
2353 EXPECT_TRUE(SetupEngine());
2354 int channel_num = voe_.GetLastChannel();
2355 unsigned int send_ssrc;
2356 EXPECT_EQ(0, voe_.GetLocalSSRC(channel_num, send_ssrc));
2357 EXPECT_NE(0U, send_ssrc);
2358 EXPECT_EQ(0, voe_.GetLocalSSRC(channel_num, send_ssrc));
2359 EXPECT_EQ(kSsrc1, send_ssrc);
2360}
2361
2362TEST_F(WebRtcVoiceEngineTestFake, GetStats) {
2363 // Setup. We need send codec to be set to get all stats.
2364 EXPECT_TRUE(SetupEngine());
buildbot@webrtc.org7e71b772014-06-13 01:14:01 +00002365 // SetupEngine adds a send stream with kSsrc1, so the receive stream has to
2366 // use a different SSRC.
2367 EXPECT_TRUE(channel_->AddRecvStream(
2368 cricket::StreamParams::CreateLegacy(kSsrc2)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002369 std::vector<cricket::AudioCodec> codecs;
2370 codecs.push_back(kPcmuCodec);
2371 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
buildbot@webrtc.org7e71b772014-06-13 01:14:01 +00002372 EXPECT_TRUE(channel_->SetRecvCodecs(codecs));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002373
2374 cricket::VoiceMediaInfo info;
2375 EXPECT_EQ(true, channel_->GetStats(&info));
2376 EXPECT_EQ(1u, info.senders.size());
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +00002377 EXPECT_EQ(kSsrc1, info.senders[0].ssrc());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002378 EXPECT_EQ(kPcmuCodec.name, info.senders[0].codec_name);
2379 EXPECT_EQ(cricket::kIntStatValue, info.senders[0].bytes_sent);
2380 EXPECT_EQ(cricket::kIntStatValue, info.senders[0].packets_sent);
2381 EXPECT_EQ(cricket::kIntStatValue, info.senders[0].packets_lost);
2382 EXPECT_EQ(cricket::kFractionLostStatValue, info.senders[0].fraction_lost);
2383 EXPECT_EQ(cricket::kIntStatValue, info.senders[0].ext_seqnum);
2384 EXPECT_EQ(cricket::kIntStatValue, info.senders[0].rtt_ms);
2385 EXPECT_EQ(cricket::kIntStatValue, info.senders[0].jitter_ms);
buildbot@webrtc.org7e71b772014-06-13 01:14:01 +00002386 EXPECT_EQ(kPcmuCodec.name, info.senders[0].codec_name);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002387 // TODO(sriniv): Add testing for more fields. These are not populated
2388 // in FakeWebrtcVoiceEngine yet.
2389 // EXPECT_EQ(cricket::kIntStatValue, info.senders[0].audio_level);
2390 // EXPECT_EQ(cricket::kIntStatValue, info.senders[0].echo_delay_median_ms);
2391 // EXPECT_EQ(cricket::kIntStatValue, info.senders[0].echo_delay_std_ms);
2392 // EXPECT_EQ(cricket::kIntStatValue, info.senders[0].echo_return_loss);
2393 // EXPECT_EQ(cricket::kIntStatValue,
2394 // info.senders[0].echo_return_loss_enhancement);
2395
buildbot@webrtc.org7e71b772014-06-13 01:14:01 +00002396 EXPECT_EQ(0u, info.receivers.size());
2397 DeliverPacket(kPcmuFrame, sizeof(kPcmuFrame));
2398 EXPECT_EQ(true, channel_->GetStats(&info));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002399 EXPECT_EQ(1u, info.receivers.size());
buildbot@webrtc.org7e71b772014-06-13 01:14:01 +00002400
2401 EXPECT_EQ(cricket::kIntStatValue, info.receivers[0].bytes_rcvd);
2402 EXPECT_EQ(cricket::kIntStatValue, info.receivers[0].packets_rcvd);
2403 EXPECT_EQ(cricket::kIntStatValue, info.receivers[0].packets_lost);
2404 EXPECT_EQ(cricket::kIntStatValue, info.receivers[0].ext_seqnum);
2405 EXPECT_EQ(kPcmuCodec.name, info.receivers[0].codec_name);
minyue@webrtc.orgc0bd7be2015-02-18 15:24:13 +00002406 EXPECT_EQ(static_cast<float>(cricket::kNetStats.currentExpandRate) /
2407 (1 << 14), info.receivers[0].expand_rate);
2408 EXPECT_EQ(static_cast<float>(cricket::kNetStats.currentSpeechExpandRate) /
2409 (1 << 14), info.receivers[0].speech_expand_rate);
2410 EXPECT_EQ(static_cast<float>(cricket::kNetStats.currentSecondaryDecodedRate) /
2411 (1 << 14), info.receivers[0].secondary_decoded_rate);
buildbot@webrtc.org7e71b772014-06-13 01:14:01 +00002412 // TODO(sriniv): Add testing for more receiver fields.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002413}
2414
2415// Test that we can set the outgoing SSRC properly with multiple streams.
2416// SSRC is set in SetupEngine by calling AddSendStream.
2417TEST_F(WebRtcVoiceEngineTestFake, SetSendSsrcWithMultipleStreams) {
2418 EXPECT_TRUE(SetupEngine());
2419 EXPECT_TRUE(channel_->SetOptions(options_conference_));
2420 int channel_num1 = voe_.GetLastChannel();
2421 unsigned int send_ssrc;
2422 EXPECT_EQ(0, voe_.GetLocalSSRC(channel_num1, send_ssrc));
2423 EXPECT_EQ(kSsrc1, send_ssrc);
2424
2425 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(2)));
2426 int channel_num2 = voe_.GetLastChannel();
2427 EXPECT_EQ(0, voe_.GetLocalSSRC(channel_num2, send_ssrc));
2428 EXPECT_EQ(kSsrc1, send_ssrc);
2429}
2430
2431// Test that the local SSRC is the same on sending and receiving channels if the
2432// receive channel is created before the send channel.
2433TEST_F(WebRtcVoiceEngineTestFake, SetSendSsrcAfterCreatingReceiveChannel) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002434 EXPECT_TRUE(engine_.Init(rtc::Thread::Current()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002435 channel_ = engine_.CreateChannel();
2436 EXPECT_TRUE(channel_->SetOptions(options_conference_));
2437
2438 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(1)));
2439 int receive_channel_num = voe_.GetLastChannel();
2440 EXPECT_TRUE(channel_->AddSendStream(
2441 cricket::StreamParams::CreateLegacy(1234)));
2442 int send_channel_num = voe_.GetLastChannel();
2443
2444 unsigned int ssrc = 0;
2445 EXPECT_EQ(0, voe_.GetLocalSSRC(send_channel_num, ssrc));
2446 EXPECT_EQ(1234U, ssrc);
2447 ssrc = 0;
2448 EXPECT_EQ(0, voe_.GetLocalSSRC(receive_channel_num, ssrc));
2449 EXPECT_EQ(1234U, ssrc);
2450}
2451
2452// Test that we can properly receive packets.
2453TEST_F(WebRtcVoiceEngineTestFake, Recv) {
2454 EXPECT_TRUE(SetupEngine());
2455 int channel_num = voe_.GetLastChannel();
2456 DeliverPacket(kPcmuFrame, sizeof(kPcmuFrame));
2457 EXPECT_TRUE(voe_.CheckPacket(channel_num, kPcmuFrame,
2458 sizeof(kPcmuFrame)));
2459}
2460
2461// Test that we can properly receive packets on multiple streams.
2462TEST_F(WebRtcVoiceEngineTestFake, RecvWithMultipleStreams) {
2463 EXPECT_TRUE(SetupEngine());
2464 EXPECT_TRUE(channel_->SetOptions(options_conference_));
2465 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(1)));
2466 int channel_num1 = voe_.GetLastChannel();
2467 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(2)));
2468 int channel_num2 = voe_.GetLastChannel();
2469 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(3)));
2470 int channel_num3 = voe_.GetLastChannel();
2471 // Create packets with the right SSRCs.
2472 char packets[4][sizeof(kPcmuFrame)];
2473 for (size_t i = 0; i < ARRAY_SIZE(packets); ++i) {
2474 memcpy(packets[i], kPcmuFrame, sizeof(kPcmuFrame));
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002475 rtc::SetBE32(packets[i] + 8, static_cast<uint32>(i));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002476 }
2477 EXPECT_TRUE(voe_.CheckNoPacket(channel_num1));
2478 EXPECT_TRUE(voe_.CheckNoPacket(channel_num2));
2479 EXPECT_TRUE(voe_.CheckNoPacket(channel_num3));
2480 DeliverPacket(packets[0], sizeof(packets[0]));
2481 EXPECT_TRUE(voe_.CheckNoPacket(channel_num1));
2482 EXPECT_TRUE(voe_.CheckNoPacket(channel_num2));
2483 EXPECT_TRUE(voe_.CheckNoPacket(channel_num3));
2484 DeliverPacket(packets[1], sizeof(packets[1]));
2485 EXPECT_TRUE(voe_.CheckPacket(channel_num1, packets[1],
2486 sizeof(packets[1])));
2487 EXPECT_TRUE(voe_.CheckNoPacket(channel_num2));
2488 EXPECT_TRUE(voe_.CheckNoPacket(channel_num3));
2489 DeliverPacket(packets[2], sizeof(packets[2]));
2490 EXPECT_TRUE(voe_.CheckNoPacket(channel_num1));
2491 EXPECT_TRUE(voe_.CheckPacket(channel_num2, packets[2],
2492 sizeof(packets[2])));
2493 EXPECT_TRUE(voe_.CheckNoPacket(channel_num3));
2494 DeliverPacket(packets[3], sizeof(packets[3]));
2495 EXPECT_TRUE(voe_.CheckNoPacket(channel_num1));
2496 EXPECT_TRUE(voe_.CheckNoPacket(channel_num2));
2497 EXPECT_TRUE(voe_.CheckPacket(channel_num3, packets[3],
2498 sizeof(packets[3])));
2499 EXPECT_TRUE(channel_->RemoveRecvStream(3));
2500 EXPECT_TRUE(channel_->RemoveRecvStream(2));
2501 EXPECT_TRUE(channel_->RemoveRecvStream(1));
2502}
2503
2504// Test that we properly handle failures to add a stream.
2505TEST_F(WebRtcVoiceEngineTestFake, AddStreamFail) {
2506 EXPECT_TRUE(SetupEngine());
2507 voe_.set_fail_create_channel(true);
2508 EXPECT_TRUE(channel_->SetOptions(options_conference_));
2509 EXPECT_FALSE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(2)));
2510
2511 // In 1:1 call, we should not try to create a new channel.
2512 cricket::AudioOptions options_no_conference_;
2513 options_no_conference_.conference_mode.Set(false);
2514 EXPECT_TRUE(channel_->SetOptions(options_no_conference_));
2515 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(2)));
2516}
2517
2518// Test that AddRecvStream doesn't create new channel for 1:1 call.
2519TEST_F(WebRtcVoiceEngineTestFake, AddRecvStream1On1) {
2520 EXPECT_TRUE(SetupEngine());
2521 int channel_num = voe_.GetLastChannel();
2522 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(1)));
2523 EXPECT_EQ(channel_num, voe_.GetLastChannel());
2524}
2525
2526// Test that after adding a recv stream, we do not decode more codecs than
2527// those previously passed into SetRecvCodecs.
2528TEST_F(WebRtcVoiceEngineTestFake, AddRecvStreamUnsupportedCodec) {
2529 EXPECT_TRUE(SetupEngine());
2530 EXPECT_TRUE(channel_->SetOptions(options_conference_));
2531 std::vector<cricket::AudioCodec> codecs;
2532 codecs.push_back(kIsacCodec);
2533 codecs.push_back(kPcmuCodec);
2534 EXPECT_TRUE(channel_->SetRecvCodecs(codecs));
2535 EXPECT_TRUE(channel_->AddRecvStream(
2536 cricket::StreamParams::CreateLegacy(kSsrc1)));
2537 int channel_num2 = voe_.GetLastChannel();
2538 webrtc::CodecInst gcodec;
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +00002539 rtc::strcpyn(gcodec.plname, ARRAY_SIZE(gcodec.plname), "opus");
2540 gcodec.plfreq = 48000;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002541 gcodec.channels = 2;
2542 EXPECT_EQ(-1, voe_.GetRecPayloadType(channel_num2, gcodec));
2543}
2544
2545// Test that we properly clean up any streams that were added, even if
2546// not explicitly removed.
2547TEST_F(WebRtcVoiceEngineTestFake, StreamCleanup) {
2548 EXPECT_TRUE(SetupEngine());
2549 EXPECT_TRUE(channel_->SetOptions(options_conference_));
2550 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(1)));
2551 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(2)));
2552 EXPECT_EQ(3, voe_.GetNumChannels()); // default channel + 2 added
2553 delete channel_;
2554 channel_ = NULL;
2555 EXPECT_EQ(0, voe_.GetNumChannels());
2556}
2557
wu@webrtc.org78187522013-10-07 23:32:02 +00002558TEST_F(WebRtcVoiceEngineTestFake, TestAddRecvStreamFailWithZeroSsrc) {
2559 EXPECT_TRUE(SetupEngine());
2560 EXPECT_FALSE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(0)));
2561}
2562
2563TEST_F(WebRtcVoiceEngineTestFake, TestNoLeakingWhenAddRecvStreamFail) {
2564 EXPECT_TRUE(SetupEngine());
2565 // Stream 1 reuses default channel.
2566 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(1)));
2567 // Manually delete default channel to simulate a failure.
2568 int default_channel = voe_.GetLastChannel();
2569 EXPECT_EQ(0, voe_.DeleteChannel(default_channel));
2570 // Add recv stream 2 should fail because default channel is gone.
2571 EXPECT_FALSE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(2)));
2572 int new_channel = voe_.GetLastChannel();
2573 EXPECT_NE(default_channel, new_channel);
2574 // The last created channel should have already been deleted.
2575 EXPECT_EQ(-1, voe_.DeleteChannel(new_channel));
2576}
2577
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002578// Test the InsertDtmf on default send stream as caller.
2579TEST_F(WebRtcVoiceEngineTestFake, InsertDtmfOnDefaultSendStreamAsCaller) {
2580 TestInsertDtmf(0, true);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002581}
2582
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002583// Test the InsertDtmf on default send stream as callee
2584TEST_F(WebRtcVoiceEngineTestFake, InsertDtmfOnDefaultSendStreamAsCallee) {
2585 TestInsertDtmf(0, false);
2586}
2587
2588// Test the InsertDtmf on specified send stream as caller.
2589TEST_F(WebRtcVoiceEngineTestFake, InsertDtmfOnSendStreamAsCaller) {
2590 TestInsertDtmf(kSsrc1, true);
2591}
2592
2593// Test the InsertDtmf on specified send stream as callee.
2594TEST_F(WebRtcVoiceEngineTestFake, InsertDtmfOnSendStreamAsCallee) {
2595 TestInsertDtmf(kSsrc1, false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002596}
2597
2598// Test that we can play a ringback tone properly in a single-stream call.
2599TEST_F(WebRtcVoiceEngineTestFake, PlayRingback) {
2600 EXPECT_TRUE(SetupEngine());
2601 int channel_num = voe_.GetLastChannel();
2602 EXPECT_EQ(0, voe_.IsPlayingFileLocally(channel_num));
2603 // Check we fail if no ringback tone specified.
2604 EXPECT_FALSE(channel_->PlayRingbackTone(0, true, true));
2605 EXPECT_EQ(0, voe_.IsPlayingFileLocally(channel_num));
2606 // Check we can set and play a ringback tone.
wu@webrtc.org9caf2762013-12-11 18:25:07 +00002607 EXPECT_TRUE(channel_->SetRingbackTone(
2608 kRingbackTone, static_cast<int>(strlen(kRingbackTone))));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002609 EXPECT_TRUE(channel_->PlayRingbackTone(0, true, true));
2610 EXPECT_EQ(1, voe_.IsPlayingFileLocally(channel_num));
2611 // Check we can stop the tone manually.
2612 EXPECT_TRUE(channel_->PlayRingbackTone(0, false, false));
2613 EXPECT_EQ(0, voe_.IsPlayingFileLocally(channel_num));
2614 // Check we stop the tone if a packet arrives.
2615 EXPECT_TRUE(channel_->PlayRingbackTone(0, true, true));
2616 EXPECT_EQ(1, voe_.IsPlayingFileLocally(channel_num));
2617 DeliverPacket(kPcmuFrame, sizeof(kPcmuFrame));
2618 EXPECT_EQ(0, voe_.IsPlayingFileLocally(channel_num));
2619}
2620
2621// Test that we can play a ringback tone properly in a multi-stream call.
2622TEST_F(WebRtcVoiceEngineTestFake, PlayRingbackWithMultipleStreams) {
2623 EXPECT_TRUE(SetupEngine());
2624 EXPECT_TRUE(channel_->SetOptions(options_conference_));
2625 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(1)));
2626 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(2)));
2627 int channel_num = voe_.GetLastChannel();
2628 EXPECT_EQ(0, voe_.IsPlayingFileLocally(channel_num));
2629 // Check we fail if no ringback tone specified.
2630 EXPECT_FALSE(channel_->PlayRingbackTone(2, true, true));
2631 EXPECT_EQ(0, voe_.IsPlayingFileLocally(channel_num));
2632 // Check we can set and play a ringback tone on the correct ssrc.
wu@webrtc.org9caf2762013-12-11 18:25:07 +00002633 EXPECT_TRUE(channel_->SetRingbackTone(
2634 kRingbackTone, static_cast<int>(strlen(kRingbackTone))));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002635 EXPECT_FALSE(channel_->PlayRingbackTone(77, true, true));
2636 EXPECT_TRUE(channel_->PlayRingbackTone(2, true, true));
2637 EXPECT_EQ(1, voe_.IsPlayingFileLocally(channel_num));
2638 // Check we can stop the tone manually.
2639 EXPECT_TRUE(channel_->PlayRingbackTone(2, false, false));
2640 EXPECT_EQ(0, voe_.IsPlayingFileLocally(channel_num));
2641 // Check we stop the tone if a packet arrives, but only with the right SSRC.
2642 EXPECT_TRUE(channel_->PlayRingbackTone(2, true, true));
2643 EXPECT_EQ(1, voe_.IsPlayingFileLocally(channel_num));
2644 // Send a packet with SSRC 1; the tone should not stop.
2645 DeliverPacket(kPcmuFrame, sizeof(kPcmuFrame));
2646 EXPECT_EQ(1, voe_.IsPlayingFileLocally(channel_num));
2647 // Send a packet with SSRC 2; the tone should stop.
2648 char packet[sizeof(kPcmuFrame)];
2649 memcpy(packet, kPcmuFrame, sizeof(kPcmuFrame));
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002650 rtc::SetBE32(packet + 8, 2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002651 DeliverPacket(packet, sizeof(packet));
2652 EXPECT_EQ(0, voe_.IsPlayingFileLocally(channel_num));
2653}
2654
2655// Tests creating soundclips, and make sure they come from the right engine.
2656TEST_F(WebRtcVoiceEngineTestFake, CreateSoundclip) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002657 EXPECT_TRUE(engine_.Init(rtc::Thread::Current()));
wu@webrtc.org4551b792013-10-09 15:37:36 +00002658 EXPECT_FALSE(voe_sc_.IsInited());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002659 soundclip_ = engine_.CreateSoundclip();
wu@webrtc.org4551b792013-10-09 15:37:36 +00002660 EXPECT_TRUE(voe_sc_.IsInited());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002661 ASSERT_TRUE(soundclip_ != NULL);
2662 EXPECT_EQ(0, voe_.GetNumChannels());
2663 EXPECT_EQ(1, voe_sc_.GetNumChannels());
2664 int channel_num = voe_sc_.GetLastChannel();
2665 EXPECT_TRUE(voe_sc_.GetPlayout(channel_num));
2666 delete soundclip_;
2667 soundclip_ = NULL;
2668 EXPECT_EQ(0, voe_sc_.GetNumChannels());
wu@webrtc.org4551b792013-10-09 15:37:36 +00002669 // Make sure the soundclip engine is uninitialized on shutdown, now that
2670 // we've initialized it by creating a soundclip.
2671 engine_.Terminate();
2672 EXPECT_FALSE(voe_sc_.IsInited());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002673}
2674
2675// Tests playing out a fake sound.
2676TEST_F(WebRtcVoiceEngineTestFake, PlaySoundclip) {
2677 static const char kZeroes[16000] = {};
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002678 EXPECT_TRUE(engine_.Init(rtc::Thread::Current()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002679 soundclip_ = engine_.CreateSoundclip();
2680 ASSERT_TRUE(soundclip_ != NULL);
2681 EXPECT_TRUE(soundclip_->PlaySound(kZeroes, sizeof(kZeroes), 0));
2682}
2683
2684TEST_F(WebRtcVoiceEngineTestFake, MediaEngineCallbackOnError) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002685 rtc::scoped_ptr<ChannelErrorListener> listener;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002686 cricket::WebRtcVoiceMediaChannel* media_channel;
2687 unsigned int ssrc = 0;
2688
2689 EXPECT_TRUE(SetupEngine());
2690 EXPECT_TRUE(channel_->SetOptions(options_conference_));
2691 EXPECT_TRUE(channel_->SetSend(cricket::SEND_MICROPHONE));
2692
2693 media_channel = static_cast<cricket::WebRtcVoiceMediaChannel*>(channel_);
2694 listener.reset(new ChannelErrorListener(channel_));
2695
2696 // Test on WebRtc VoE channel.
2697 voe_.TriggerCallbackOnError(media_channel->voe_channel(),
2698 VE_SATURATION_WARNING);
2699 EXPECT_EQ(cricket::VoiceMediaChannel::ERROR_REC_DEVICE_SATURATION,
2700 listener->error());
2701 EXPECT_NE(-1, voe_.GetLocalSSRC(voe_.GetLastChannel(), ssrc));
2702 EXPECT_EQ(ssrc, listener->ssrc());
2703
2704 listener->Reset();
2705 voe_.TriggerCallbackOnError(-1, VE_TYPING_NOISE_WARNING);
2706 EXPECT_EQ(cricket::VoiceMediaChannel::ERROR_REC_TYPING_NOISE_DETECTED,
2707 listener->error());
2708 EXPECT_EQ(0U, listener->ssrc());
2709
2710 // Add another stream and test on that.
2711 ++ssrc;
2712 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(
2713 ssrc)));
2714 listener->Reset();
2715 voe_.TriggerCallbackOnError(voe_.GetLastChannel(),
2716 VE_SATURATION_WARNING);
2717 EXPECT_EQ(cricket::VoiceMediaChannel::ERROR_REC_DEVICE_SATURATION,
2718 listener->error());
2719 EXPECT_EQ(ssrc, listener->ssrc());
2720
2721 // Testing a non-existing channel.
2722 listener->Reset();
2723 voe_.TriggerCallbackOnError(voe_.GetLastChannel() + 2,
2724 VE_SATURATION_WARNING);
2725 EXPECT_EQ(0, listener->error());
2726}
2727
2728TEST_F(WebRtcVoiceEngineTestFake, TestSetPlayoutError) {
2729 EXPECT_TRUE(SetupEngine());
2730 EXPECT_TRUE(channel_->SetOptions(options_conference_));
2731 std::vector<cricket::AudioCodec> codecs;
2732 codecs.push_back(kPcmuCodec);
2733 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
2734 EXPECT_TRUE(channel_->SetSend(cricket::SEND_MICROPHONE));
2735 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(2)));
2736 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(3)));
2737 EXPECT_TRUE(channel_->SetPlayout(true));
2738 voe_.set_playout_fail_channel(voe_.GetLastChannel() - 1);
2739 EXPECT_TRUE(channel_->SetPlayout(false));
2740 EXPECT_FALSE(channel_->SetPlayout(true));
2741}
2742
2743// Test that the Registering/Unregistering with the
2744// webrtcvoiceengine works as expected
2745TEST_F(WebRtcVoiceEngineTestFake, RegisterVoiceProcessor) {
2746 EXPECT_TRUE(SetupEngine());
2747 EXPECT_TRUE(channel_->SetOptions(options_conference_));
2748 EXPECT_TRUE(channel_->AddRecvStream(
2749 cricket::StreamParams::CreateLegacy(kSsrc2)));
2750 cricket::FakeMediaProcessor vp_1;
2751 cricket::FakeMediaProcessor vp_2;
2752
2753 EXPECT_FALSE(engine_.RegisterProcessor(kSsrc2, &vp_1, cricket::MPD_TX));
2754 EXPECT_TRUE(engine_.RegisterProcessor(kSsrc2, &vp_1, cricket::MPD_RX));
2755 EXPECT_TRUE(engine_.RegisterProcessor(kSsrc2, &vp_2, cricket::MPD_RX));
2756 voe_.TriggerProcessPacket(cricket::MPD_RX);
2757 voe_.TriggerProcessPacket(cricket::MPD_TX);
2758
2759 EXPECT_TRUE(voe_.IsExternalMediaProcessorRegistered());
2760 EXPECT_EQ(1, vp_1.voice_frame_count());
2761 EXPECT_EQ(1, vp_2.voice_frame_count());
2762
2763 EXPECT_TRUE(engine_.UnregisterProcessor(kSsrc2,
2764 &vp_2,
2765 cricket::MPD_RX));
2766 voe_.TriggerProcessPacket(cricket::MPD_RX);
2767 EXPECT_TRUE(voe_.IsExternalMediaProcessorRegistered());
2768 EXPECT_EQ(1, vp_2.voice_frame_count());
2769 EXPECT_EQ(2, vp_1.voice_frame_count());
2770
2771 EXPECT_TRUE(engine_.UnregisterProcessor(kSsrc2,
2772 &vp_1,
2773 cricket::MPD_RX));
2774 voe_.TriggerProcessPacket(cricket::MPD_RX);
2775 EXPECT_FALSE(voe_.IsExternalMediaProcessorRegistered());
2776 EXPECT_EQ(2, vp_1.voice_frame_count());
2777
2778 EXPECT_FALSE(engine_.RegisterProcessor(kSsrc1, &vp_1, cricket::MPD_RX));
2779 EXPECT_TRUE(engine_.RegisterProcessor(kSsrc1, &vp_1, cricket::MPD_TX));
2780 voe_.TriggerProcessPacket(cricket::MPD_RX);
2781 voe_.TriggerProcessPacket(cricket::MPD_TX);
2782 EXPECT_TRUE(voe_.IsExternalMediaProcessorRegistered());
2783 EXPECT_EQ(3, vp_1.voice_frame_count());
2784
2785 EXPECT_TRUE(engine_.UnregisterProcessor(kSsrc1,
2786 &vp_1,
2787 cricket::MPD_RX_AND_TX));
2788 voe_.TriggerProcessPacket(cricket::MPD_TX);
2789 EXPECT_FALSE(voe_.IsExternalMediaProcessorRegistered());
2790 EXPECT_EQ(3, vp_1.voice_frame_count());
2791 EXPECT_TRUE(channel_->RemoveRecvStream(kSsrc2));
2792 EXPECT_FALSE(engine_.RegisterProcessor(kSsrc2, &vp_1, cricket::MPD_RX));
2793 EXPECT_FALSE(voe_.IsExternalMediaProcessorRegistered());
2794
2795 // Test that we can register a processor on the receive channel on SSRC 0.
2796 // This tests the 1:1 case when the receive SSRC is unknown.
2797 EXPECT_TRUE(engine_.RegisterProcessor(0, &vp_1, cricket::MPD_RX));
2798 voe_.TriggerProcessPacket(cricket::MPD_RX);
2799 EXPECT_TRUE(voe_.IsExternalMediaProcessorRegistered());
2800 EXPECT_EQ(4, vp_1.voice_frame_count());
2801 EXPECT_TRUE(engine_.UnregisterProcessor(0,
2802 &vp_1,
2803 cricket::MPD_RX));
2804
2805 // The following tests test that FindChannelNumFromSsrc is doing
2806 // what we expect.
2807 // pick an invalid ssrc and make sure we can't register
2808 EXPECT_FALSE(engine_.RegisterProcessor(99,
2809 &vp_1,
2810 cricket::MPD_RX));
2811 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(1)));
2812 EXPECT_TRUE(engine_.RegisterProcessor(1,
2813 &vp_1,
2814 cricket::MPD_RX));
2815 EXPECT_TRUE(engine_.UnregisterProcessor(1,
2816 &vp_1,
2817 cricket::MPD_RX));
2818 EXPECT_FALSE(engine_.RegisterProcessor(1,
2819 &vp_1,
2820 cricket::MPD_TX));
2821 EXPECT_TRUE(channel_->RemoveRecvStream(1));
2822}
2823
2824TEST_F(WebRtcVoiceEngineTestFake, SetAudioOptions) {
2825 EXPECT_TRUE(SetupEngine());
2826
2827 bool ec_enabled;
2828 webrtc::EcModes ec_mode;
2829 bool ec_metrics_enabled;
2830 webrtc::AecmModes aecm_mode;
2831 bool cng_enabled;
2832 bool agc_enabled;
2833 webrtc::AgcModes agc_mode;
2834 webrtc::AgcConfig agc_config;
2835 bool ns_enabled;
2836 webrtc::NsModes ns_mode;
2837 bool highpass_filter_enabled;
2838 bool stereo_swapping_enabled;
2839 bool typing_detection_enabled;
2840 voe_.GetEcStatus(ec_enabled, ec_mode);
2841 voe_.GetEcMetricsStatus(ec_metrics_enabled);
2842 voe_.GetAecmMode(aecm_mode, cng_enabled);
2843 voe_.GetAgcStatus(agc_enabled, agc_mode);
2844 voe_.GetAgcConfig(agc_config);
2845 voe_.GetNsStatus(ns_enabled, ns_mode);
2846 highpass_filter_enabled = voe_.IsHighPassFilterEnabled();
2847 stereo_swapping_enabled = voe_.IsStereoChannelSwappingEnabled();
2848 voe_.GetTypingDetectionStatus(typing_detection_enabled);
2849 EXPECT_TRUE(ec_enabled);
2850 EXPECT_TRUE(ec_metrics_enabled);
2851 EXPECT_FALSE(cng_enabled);
2852 EXPECT_TRUE(agc_enabled);
2853 EXPECT_EQ(0, agc_config.targetLeveldBOv);
2854 EXPECT_TRUE(ns_enabled);
2855 EXPECT_TRUE(highpass_filter_enabled);
2856 EXPECT_FALSE(stereo_swapping_enabled);
2857 EXPECT_TRUE(typing_detection_enabled);
2858 EXPECT_EQ(ec_mode, webrtc::kEcConference);
2859 EXPECT_EQ(ns_mode, webrtc::kNsHighSuppression);
2860
2861 // Nothing set, so all ignored.
2862 cricket::AudioOptions options;
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00002863 ASSERT_TRUE(engine_.SetOptions(options));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002864 voe_.GetEcStatus(ec_enabled, ec_mode);
2865 voe_.GetEcMetricsStatus(ec_metrics_enabled);
2866 voe_.GetAecmMode(aecm_mode, cng_enabled);
2867 voe_.GetAgcStatus(agc_enabled, agc_mode);
2868 voe_.GetAgcConfig(agc_config);
2869 voe_.GetNsStatus(ns_enabled, ns_mode);
2870 highpass_filter_enabled = voe_.IsHighPassFilterEnabled();
2871 stereo_swapping_enabled = voe_.IsStereoChannelSwappingEnabled();
2872 voe_.GetTypingDetectionStatus(typing_detection_enabled);
2873 EXPECT_TRUE(ec_enabled);
2874 EXPECT_TRUE(ec_metrics_enabled);
2875 EXPECT_FALSE(cng_enabled);
2876 EXPECT_TRUE(agc_enabled);
2877 EXPECT_EQ(0, agc_config.targetLeveldBOv);
2878 EXPECT_TRUE(ns_enabled);
2879 EXPECT_TRUE(highpass_filter_enabled);
2880 EXPECT_FALSE(stereo_swapping_enabled);
2881 EXPECT_TRUE(typing_detection_enabled);
2882 EXPECT_EQ(ec_mode, webrtc::kEcConference);
2883 EXPECT_EQ(ns_mode, webrtc::kNsHighSuppression);
Henrik Lundin64dad832015-05-11 12:44:23 +02002884 EXPECT_EQ(50, voe_.GetNetEqCapacity()); // From GetDefaultEngineOptions().
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002885
2886 // Turn echo cancellation off
2887 options.echo_cancellation.Set(false);
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00002888 ASSERT_TRUE(engine_.SetOptions(options));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002889 voe_.GetEcStatus(ec_enabled, ec_mode);
2890 EXPECT_FALSE(ec_enabled);
2891
2892 // Turn echo cancellation back on, with settings, and make sure
2893 // nothing else changed.
2894 options.echo_cancellation.Set(true);
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00002895 ASSERT_TRUE(engine_.SetOptions(options));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002896 voe_.GetEcStatus(ec_enabled, ec_mode);
2897 voe_.GetEcMetricsStatus(ec_metrics_enabled);
2898 voe_.GetAecmMode(aecm_mode, cng_enabled);
2899 voe_.GetAgcStatus(agc_enabled, agc_mode);
2900 voe_.GetAgcConfig(agc_config);
2901 voe_.GetNsStatus(ns_enabled, ns_mode);
2902 highpass_filter_enabled = voe_.IsHighPassFilterEnabled();
2903 stereo_swapping_enabled = voe_.IsStereoChannelSwappingEnabled();
2904 voe_.GetTypingDetectionStatus(typing_detection_enabled);
2905 EXPECT_TRUE(ec_enabled);
2906 EXPECT_TRUE(ec_metrics_enabled);
2907 EXPECT_TRUE(agc_enabled);
2908 EXPECT_EQ(0, agc_config.targetLeveldBOv);
2909 EXPECT_TRUE(ns_enabled);
2910 EXPECT_TRUE(highpass_filter_enabled);
2911 EXPECT_FALSE(stereo_swapping_enabled);
2912 EXPECT_TRUE(typing_detection_enabled);
2913 EXPECT_EQ(ec_mode, webrtc::kEcConference);
2914 EXPECT_EQ(ns_mode, webrtc::kNsHighSuppression);
2915
Bjorn Volckerbf395c12015-03-25 22:45:56 +01002916 // Turn on delay agnostic aec and make sure nothing change w.r.t. echo
2917 // control.
2918 options.delay_agnostic_aec.Set(true);
2919 ASSERT_TRUE(engine_.SetOptions(options));
2920 voe_.GetEcStatus(ec_enabled, ec_mode);
2921 voe_.GetEcMetricsStatus(ec_metrics_enabled);
2922 voe_.GetAecmMode(aecm_mode, cng_enabled);
2923 EXPECT_TRUE(ec_enabled);
2924 EXPECT_TRUE(ec_metrics_enabled);
2925 EXPECT_EQ(ec_mode, webrtc::kEcConference);
2926
2927 // Turn off echo cancellation and delay agnostic aec.
2928 options.delay_agnostic_aec.Set(false);
2929 options.experimental_aec.Set(false);
2930 options.echo_cancellation.Set(false);
2931 ASSERT_TRUE(engine_.SetOptions(options));
2932 voe_.GetEcStatus(ec_enabled, ec_mode);
2933 EXPECT_FALSE(ec_enabled);
2934 // Turning delay agnostic aec back on should also turn on echo cancellation.
2935 options.delay_agnostic_aec.Set(true);
2936 ASSERT_TRUE(engine_.SetOptions(options));
2937 voe_.GetEcStatus(ec_enabled, ec_mode);
2938 voe_.GetEcMetricsStatus(ec_metrics_enabled);
2939 EXPECT_TRUE(ec_enabled);
2940 EXPECT_TRUE(ec_metrics_enabled);
2941 EXPECT_EQ(ec_mode, webrtc::kEcConference);
2942
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002943 // Turn off AGC
2944 options.auto_gain_control.Set(false);
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00002945 ASSERT_TRUE(engine_.SetOptions(options));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002946 voe_.GetAgcStatus(agc_enabled, agc_mode);
2947 EXPECT_FALSE(agc_enabled);
2948
2949 // Turn AGC back on
2950 options.auto_gain_control.Set(true);
2951 options.adjust_agc_delta.Clear();
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00002952 ASSERT_TRUE(engine_.SetOptions(options));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002953 voe_.GetAgcStatus(agc_enabled, agc_mode);
2954 EXPECT_TRUE(agc_enabled);
2955 voe_.GetAgcConfig(agc_config);
2956 EXPECT_EQ(0, agc_config.targetLeveldBOv);
2957
2958 // Turn off other options (and stereo swapping on).
2959 options.noise_suppression.Set(false);
2960 options.highpass_filter.Set(false);
2961 options.typing_detection.Set(false);
2962 options.stereo_swapping.Set(true);
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00002963 ASSERT_TRUE(engine_.SetOptions(options));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002964 voe_.GetNsStatus(ns_enabled, ns_mode);
2965 highpass_filter_enabled = voe_.IsHighPassFilterEnabled();
2966 stereo_swapping_enabled = voe_.IsStereoChannelSwappingEnabled();
2967 voe_.GetTypingDetectionStatus(typing_detection_enabled);
2968 EXPECT_FALSE(ns_enabled);
2969 EXPECT_FALSE(highpass_filter_enabled);
2970 EXPECT_FALSE(typing_detection_enabled);
2971 EXPECT_TRUE(stereo_swapping_enabled);
2972
2973 // Turn on "conference mode" to ensure it has no impact.
2974 options.conference_mode.Set(true);
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00002975 ASSERT_TRUE(engine_.SetOptions(options));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002976 voe_.GetEcStatus(ec_enabled, ec_mode);
2977 voe_.GetNsStatus(ns_enabled, ns_mode);
2978 EXPECT_TRUE(ec_enabled);
2979 EXPECT_EQ(webrtc::kEcConference, ec_mode);
2980 EXPECT_FALSE(ns_enabled);
2981 EXPECT_EQ(webrtc::kNsHighSuppression, ns_mode);
2982}
2983
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00002984TEST_F(WebRtcVoiceEngineTestFake, DefaultOptions) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002985 EXPECT_TRUE(SetupEngine());
2986
2987 bool ec_enabled;
2988 webrtc::EcModes ec_mode;
2989 bool ec_metrics_enabled;
2990 bool agc_enabled;
2991 webrtc::AgcModes agc_mode;
2992 bool ns_enabled;
2993 webrtc::NsModes ns_mode;
2994 bool highpass_filter_enabled;
2995 bool stereo_swapping_enabled;
2996 bool typing_detection_enabled;
2997
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002998 voe_.GetEcStatus(ec_enabled, ec_mode);
2999 voe_.GetEcMetricsStatus(ec_metrics_enabled);
3000 voe_.GetAgcStatus(agc_enabled, agc_mode);
3001 voe_.GetNsStatus(ns_enabled, ns_mode);
3002 highpass_filter_enabled = voe_.IsHighPassFilterEnabled();
3003 stereo_swapping_enabled = voe_.IsStereoChannelSwappingEnabled();
3004 voe_.GetTypingDetectionStatus(typing_detection_enabled);
3005 EXPECT_TRUE(ec_enabled);
3006 EXPECT_TRUE(agc_enabled);
3007 EXPECT_TRUE(ns_enabled);
3008 EXPECT_TRUE(highpass_filter_enabled);
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00003009 EXPECT_TRUE(typing_detection_enabled);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003010 EXPECT_FALSE(stereo_swapping_enabled);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003011}
3012
3013TEST_F(WebRtcVoiceEngineTestFake, InitDoesNotOverwriteDefaultAgcConfig) {
3014 webrtc::AgcConfig set_config = {0};
3015 set_config.targetLeveldBOv = 3;
3016 set_config.digitalCompressionGaindB = 9;
3017 set_config.limiterEnable = true;
3018 EXPECT_EQ(0, voe_.SetAgcConfig(set_config));
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003019 EXPECT_TRUE(engine_.Init(rtc::Thread::Current()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003020
3021 webrtc::AgcConfig config = {0};
3022 EXPECT_EQ(0, voe_.GetAgcConfig(config));
3023 EXPECT_EQ(set_config.targetLeveldBOv, config.targetLeveldBOv);
3024 EXPECT_EQ(set_config.digitalCompressionGaindB,
3025 config.digitalCompressionGaindB);
3026 EXPECT_EQ(set_config.limiterEnable, config.limiterEnable);
3027}
3028
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003029TEST_F(WebRtcVoiceEngineTestFake, SetOptionOverridesViaChannels) {
3030 EXPECT_TRUE(SetupEngine());
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003031 rtc::scoped_ptr<cricket::VoiceMediaChannel> channel1(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003032 engine_.CreateChannel());
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003033 rtc::scoped_ptr<cricket::VoiceMediaChannel> channel2(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003034 engine_.CreateChannel());
3035
3036 // Have to add a stream to make SetSend work.
3037 cricket::StreamParams stream1;
3038 stream1.ssrcs.push_back(1);
3039 channel1->AddSendStream(stream1);
3040 cricket::StreamParams stream2;
3041 stream2.ssrcs.push_back(2);
3042 channel2->AddSendStream(stream2);
3043
3044 // AEC and AGC and NS
3045 cricket::AudioOptions options_all;
3046 options_all.echo_cancellation.Set(true);
3047 options_all.auto_gain_control.Set(true);
3048 options_all.noise_suppression.Set(true);
3049
3050 ASSERT_TRUE(channel1->SetOptions(options_all));
3051 cricket::AudioOptions expected_options = options_all;
3052 cricket::AudioOptions actual_options;
3053 ASSERT_TRUE(channel1->GetOptions(&actual_options));
3054 EXPECT_EQ(expected_options, actual_options);
3055 ASSERT_TRUE(channel2->SetOptions(options_all));
3056 ASSERT_TRUE(channel2->GetOptions(&actual_options));
3057 EXPECT_EQ(expected_options, actual_options);
3058
3059 // unset NS
3060 cricket::AudioOptions options_no_ns;
3061 options_no_ns.noise_suppression.Set(false);
3062 ASSERT_TRUE(channel1->SetOptions(options_no_ns));
3063
3064 expected_options.echo_cancellation.Set(true);
3065 expected_options.auto_gain_control.Set(true);
3066 expected_options.noise_suppression.Set(false);
3067 ASSERT_TRUE(channel1->GetOptions(&actual_options));
3068 EXPECT_EQ(expected_options, actual_options);
3069
3070 // unset AGC
3071 cricket::AudioOptions options_no_agc;
3072 options_no_agc.auto_gain_control.Set(false);
3073 ASSERT_TRUE(channel2->SetOptions(options_no_agc));
3074
3075 expected_options.echo_cancellation.Set(true);
3076 expected_options.auto_gain_control.Set(false);
3077 expected_options.noise_suppression.Set(true);
3078 ASSERT_TRUE(channel2->GetOptions(&actual_options));
3079 EXPECT_EQ(expected_options, actual_options);
3080
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00003081 ASSERT_TRUE(engine_.SetOptions(options_all));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003082 bool ec_enabled;
3083 webrtc::EcModes ec_mode;
3084 bool agc_enabled;
3085 webrtc::AgcModes agc_mode;
3086 bool ns_enabled;
3087 webrtc::NsModes ns_mode;
3088 voe_.GetEcStatus(ec_enabled, ec_mode);
3089 voe_.GetAgcStatus(agc_enabled, agc_mode);
3090 voe_.GetNsStatus(ns_enabled, ns_mode);
3091 EXPECT_TRUE(ec_enabled);
3092 EXPECT_TRUE(agc_enabled);
3093 EXPECT_TRUE(ns_enabled);
3094
3095 channel1->SetSend(cricket::SEND_MICROPHONE);
3096 voe_.GetEcStatus(ec_enabled, ec_mode);
3097 voe_.GetAgcStatus(agc_enabled, agc_mode);
3098 voe_.GetNsStatus(ns_enabled, ns_mode);
3099 EXPECT_TRUE(ec_enabled);
3100 EXPECT_TRUE(agc_enabled);
3101 EXPECT_FALSE(ns_enabled);
3102
3103 channel1->SetSend(cricket::SEND_NOTHING);
3104 voe_.GetEcStatus(ec_enabled, ec_mode);
3105 voe_.GetAgcStatus(agc_enabled, agc_mode);
3106 voe_.GetNsStatus(ns_enabled, ns_mode);
3107 EXPECT_TRUE(ec_enabled);
3108 EXPECT_TRUE(agc_enabled);
3109 EXPECT_TRUE(ns_enabled);
3110
3111 channel2->SetSend(cricket::SEND_MICROPHONE);
3112 voe_.GetEcStatus(ec_enabled, ec_mode);
3113 voe_.GetAgcStatus(agc_enabled, agc_mode);
3114 voe_.GetNsStatus(ns_enabled, ns_mode);
3115 EXPECT_TRUE(ec_enabled);
3116 EXPECT_FALSE(agc_enabled);
3117 EXPECT_TRUE(ns_enabled);
3118
3119 channel2->SetSend(cricket::SEND_NOTHING);
3120 voe_.GetEcStatus(ec_enabled, ec_mode);
3121 voe_.GetAgcStatus(agc_enabled, agc_mode);
3122 voe_.GetNsStatus(ns_enabled, ns_mode);
3123 EXPECT_TRUE(ec_enabled);
3124 EXPECT_TRUE(agc_enabled);
3125 EXPECT_TRUE(ns_enabled);
3126
3127 // Make sure settings take effect while we are sending.
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00003128 ASSERT_TRUE(engine_.SetOptions(options_all));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003129 cricket::AudioOptions options_no_agc_nor_ns;
3130 options_no_agc_nor_ns.auto_gain_control.Set(false);
3131 options_no_agc_nor_ns.noise_suppression.Set(false);
3132 channel2->SetSend(cricket::SEND_MICROPHONE);
3133 channel2->SetOptions(options_no_agc_nor_ns);
3134
3135 expected_options.echo_cancellation.Set(true);
3136 expected_options.auto_gain_control.Set(false);
3137 expected_options.noise_suppression.Set(false);
3138 ASSERT_TRUE(channel2->GetOptions(&actual_options));
3139 EXPECT_EQ(expected_options, actual_options);
3140 voe_.GetEcStatus(ec_enabled, ec_mode);
3141 voe_.GetAgcStatus(agc_enabled, agc_mode);
3142 voe_.GetNsStatus(ns_enabled, ns_mode);
3143 EXPECT_TRUE(ec_enabled);
3144 EXPECT_FALSE(agc_enabled);
3145 EXPECT_FALSE(ns_enabled);
3146}
3147
wu@webrtc.orgde305012013-10-31 15:40:38 +00003148// This test verifies DSCP settings are properly applied on voice media channel.
3149TEST_F(WebRtcVoiceEngineTestFake, TestSetDscpOptions) {
3150 EXPECT_TRUE(SetupEngine());
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003151 rtc::scoped_ptr<cricket::VoiceMediaChannel> channel(
wu@webrtc.orgde305012013-10-31 15:40:38 +00003152 engine_.CreateChannel());
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003153 rtc::scoped_ptr<cricket::FakeNetworkInterface> network_interface(
wu@webrtc.orgde305012013-10-31 15:40:38 +00003154 new cricket::FakeNetworkInterface);
3155 channel->SetInterface(network_interface.get());
3156 cricket::AudioOptions options;
3157 options.dscp.Set(true);
3158 EXPECT_TRUE(channel->SetOptions(options));
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003159 EXPECT_EQ(rtc::DSCP_EF, network_interface->dscp());
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +00003160 // Verify previous value is not modified if dscp option is not set.
3161 cricket::AudioOptions options1;
3162 EXPECT_TRUE(channel->SetOptions(options1));
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003163 EXPECT_EQ(rtc::DSCP_EF, network_interface->dscp());
wu@webrtc.orgde305012013-10-31 15:40:38 +00003164 options.dscp.Set(false);
3165 EXPECT_TRUE(channel->SetOptions(options));
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003166 EXPECT_EQ(rtc::DSCP_DEFAULT, network_interface->dscp());
wu@webrtc.orgde305012013-10-31 15:40:38 +00003167}
3168
wu@webrtc.org1d1ffc92013-10-16 18:12:02 +00003169TEST(WebRtcVoiceEngineTest, TestDefaultOptionsBeforeInit) {
3170 cricket::WebRtcVoiceEngine engine;
3171 cricket::AudioOptions options = engine.GetOptions();
3172 // The default options should have at least a few things set. We purposefully
3173 // don't check the option values here, though.
3174 EXPECT_TRUE(options.echo_cancellation.IsSet());
3175 EXPECT_TRUE(options.auto_gain_control.IsSet());
3176 EXPECT_TRUE(options.noise_suppression.IsSet());
3177}
3178
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003179// Test that GetReceiveChannelNum returns the default channel for the first
3180// recv stream in 1-1 calls.
3181TEST_F(WebRtcVoiceEngineTestFake, TestGetReceiveChannelNumIn1To1Calls) {
3182 EXPECT_TRUE(SetupEngine());
3183 cricket::WebRtcVoiceMediaChannel* media_channel =
3184 static_cast<cricket::WebRtcVoiceMediaChannel*>(channel_);
3185 // Test that GetChannelNum returns the default channel if the SSRC is unknown.
3186 EXPECT_EQ(media_channel->voe_channel(),
3187 media_channel->GetReceiveChannelNum(0));
3188 cricket::StreamParams stream;
3189 stream.ssrcs.push_back(kSsrc2);
3190 EXPECT_TRUE(channel_->AddRecvStream(stream));
3191 EXPECT_EQ(media_channel->voe_channel(),
3192 media_channel->GetReceiveChannelNum(kSsrc2));
3193}
3194
3195// Test that GetReceiveChannelNum doesn't return the default channel for the
3196// first recv stream in conference calls.
3197TEST_F(WebRtcVoiceEngineTestFake, TestGetChannelNumInConferenceCalls) {
3198 EXPECT_TRUE(SetupEngine());
3199 EXPECT_TRUE(channel_->SetOptions(options_conference_));
3200 cricket::StreamParams stream;
3201 stream.ssrcs.push_back(kSsrc2);
3202 EXPECT_TRUE(channel_->AddRecvStream(stream));
3203 cricket::WebRtcVoiceMediaChannel* media_channel =
3204 static_cast<cricket::WebRtcVoiceMediaChannel*>(channel_);
3205 EXPECT_LT(media_channel->voe_channel(),
3206 media_channel->GetReceiveChannelNum(kSsrc2));
3207}
3208
3209TEST_F(WebRtcVoiceEngineTestFake, SetOutputScaling) {
3210 EXPECT_TRUE(SetupEngine());
3211 double left, right;
3212 EXPECT_TRUE(channel_->SetOutputScaling(0, 1, 2));
3213 EXPECT_TRUE(channel_->GetOutputScaling(0, &left, &right));
3214 EXPECT_DOUBLE_EQ(1, left);
3215 EXPECT_DOUBLE_EQ(2, right);
3216
3217 EXPECT_FALSE(channel_->SetOutputScaling(kSsrc2, 1, 2));
3218 cricket::StreamParams stream;
3219 stream.ssrcs.push_back(kSsrc2);
3220 EXPECT_TRUE(channel_->AddRecvStream(stream));
3221
3222 EXPECT_TRUE(channel_->SetOutputScaling(kSsrc2, 2, 1));
3223 EXPECT_TRUE(channel_->GetOutputScaling(kSsrc2, &left, &right));
3224 EXPECT_DOUBLE_EQ(2, left);
3225 EXPECT_DOUBLE_EQ(1, right);
3226}
3227
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003228// Tests for the actual WebRtc VoE library.
3229
3230// Tests that the library initializes and shuts down properly.
3231TEST(WebRtcVoiceEngineTest, StartupShutdown) {
3232 cricket::WebRtcVoiceEngine engine;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003233 EXPECT_TRUE(engine.Init(rtc::Thread::Current()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003234 cricket::VoiceMediaChannel* channel = engine.CreateChannel();
3235 EXPECT_TRUE(channel != NULL);
3236 delete channel;
3237 engine.Terminate();
3238
3239 // Reinit to catch regression where VoiceEngineObserver reference is lost
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003240 EXPECT_TRUE(engine.Init(rtc::Thread::Current()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003241 engine.Terminate();
3242}
3243
3244// Tests that the logging from the library is cleartext.
3245TEST(WebRtcVoiceEngineTest, DISABLED_HasUnencryptedLogging) {
3246 cricket::WebRtcVoiceEngine engine;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003247 rtc::scoped_ptr<rtc::MemoryStream> stream(
3248 new rtc::MemoryStream);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003249 size_t size = 0;
3250 bool cleartext = true;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003251 rtc::LogMessage::AddLogToStream(stream.get(), rtc::LS_VERBOSE);
3252 engine.SetLogging(rtc::LS_VERBOSE, "");
3253 EXPECT_TRUE(engine.Init(rtc::Thread::Current()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003254 EXPECT_TRUE(stream->GetSize(&size));
3255 EXPECT_GT(size, 0U);
3256 engine.Terminate();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003257 rtc::LogMessage::RemoveLogToStream(stream.get());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003258 const char* buf = stream->GetBuffer();
3259 for (size_t i = 0; i < size && cleartext; ++i) {
3260 int ch = static_cast<int>(buf[i]);
3261 ASSERT_GE(ch, 0) << "Out of bounds character in WebRtc VoE log: "
3262 << std::hex << ch;
3263 cleartext = (isprint(ch) || isspace(ch));
3264 }
3265 EXPECT_TRUE(cleartext);
3266}
3267
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003268// Tests that the library is configured with the codecs we want.
3269TEST(WebRtcVoiceEngineTest, HasCorrectCodecs) {
3270 cricket::WebRtcVoiceEngine engine;
3271 // Check codecs by name.
3272 EXPECT_TRUE(engine.FindCodec(
3273 cricket::AudioCodec(96, "OPUS", 48000, 0, 2, 0)));
3274 EXPECT_TRUE(engine.FindCodec(
3275 cricket::AudioCodec(96, "ISAC", 16000, 0, 1, 0)));
3276 EXPECT_TRUE(engine.FindCodec(
3277 cricket::AudioCodec(96, "ISAC", 32000, 0, 1, 0)));
3278 // Check that name matching is case-insensitive.
3279 EXPECT_TRUE(engine.FindCodec(
3280 cricket::AudioCodec(96, "ILBC", 8000, 0, 1, 0)));
3281 EXPECT_TRUE(engine.FindCodec(
3282 cricket::AudioCodec(96, "iLBC", 8000, 0, 1, 0)));
3283 EXPECT_TRUE(engine.FindCodec(
3284 cricket::AudioCodec(96, "PCMU", 8000, 0, 1, 0)));
3285 EXPECT_TRUE(engine.FindCodec(
3286 cricket::AudioCodec(96, "PCMA", 8000, 0, 1, 0)));
3287 EXPECT_TRUE(engine.FindCodec(
henrik.lundin@webrtc.orgf85dbce2014-11-07 12:25:00 +00003288 cricket::AudioCodec(96, "G722", 8000, 0, 1, 0)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003289 EXPECT_TRUE(engine.FindCodec(
3290 cricket::AudioCodec(96, "red", 8000, 0, 1, 0)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003291 EXPECT_TRUE(engine.FindCodec(
3292 cricket::AudioCodec(96, "CN", 32000, 0, 1, 0)));
3293 EXPECT_TRUE(engine.FindCodec(
3294 cricket::AudioCodec(96, "CN", 16000, 0, 1, 0)));
3295 EXPECT_TRUE(engine.FindCodec(
3296 cricket::AudioCodec(96, "CN", 8000, 0, 1, 0)));
3297 EXPECT_TRUE(engine.FindCodec(
3298 cricket::AudioCodec(96, "telephone-event", 8000, 0, 1, 0)));
3299 // Check codecs with an id by id.
3300 EXPECT_TRUE(engine.FindCodec(
3301 cricket::AudioCodec(0, "", 8000, 0, 1, 0))); // PCMU
3302 EXPECT_TRUE(engine.FindCodec(
3303 cricket::AudioCodec(8, "", 8000, 0, 1, 0))); // PCMA
3304 EXPECT_TRUE(engine.FindCodec(
henrik.lundin@webrtc.orgf85dbce2014-11-07 12:25:00 +00003305 cricket::AudioCodec(9, "", 8000, 0, 1, 0))); // G722
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003306 EXPECT_TRUE(engine.FindCodec(
3307 cricket::AudioCodec(13, "", 8000, 0, 1, 0))); // CN
3308 // Check sample/bitrate matching.
3309 EXPECT_TRUE(engine.FindCodec(
3310 cricket::AudioCodec(0, "PCMU", 8000, 64000, 1, 0)));
3311 // Check that bad codecs fail.
3312 EXPECT_FALSE(engine.FindCodec(cricket::AudioCodec(99, "ABCD", 0, 0, 1, 0)));
3313 EXPECT_FALSE(engine.FindCodec(cricket::AudioCodec(88, "", 0, 0, 1, 0)));
3314 EXPECT_FALSE(engine.FindCodec(cricket::AudioCodec(0, "", 0, 0, 2, 0)));
3315 EXPECT_FALSE(engine.FindCodec(cricket::AudioCodec(0, "", 5000, 0, 1, 0)));
3316 EXPECT_FALSE(engine.FindCodec(cricket::AudioCodec(0, "", 0, 5000, 1, 0)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003317 // Verify the payload id of common audio codecs, including CN, ISAC, and G722.
3318 for (std::vector<cricket::AudioCodec>::const_iterator it =
3319 engine.codecs().begin(); it != engine.codecs().end(); ++it) {
3320 if (it->name == "CN" && it->clockrate == 16000) {
3321 EXPECT_EQ(105, it->id);
3322 } else if (it->name == "CN" && it->clockrate == 32000) {
3323 EXPECT_EQ(106, it->id);
3324 } else if (it->name == "ISAC" && it->clockrate == 16000) {
3325 EXPECT_EQ(103, it->id);
3326 } else if (it->name == "ISAC" && it->clockrate == 32000) {
3327 EXPECT_EQ(104, it->id);
henrik.lundin@webrtc.orgf85dbce2014-11-07 12:25:00 +00003328 } else if (it->name == "G722" && it->clockrate == 8000) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003329 EXPECT_EQ(9, it->id);
3330 } else if (it->name == "telephone-event") {
3331 EXPECT_EQ(126, it->id);
3332 } else if (it->name == "red") {
3333 EXPECT_EQ(127, it->id);
3334 } else if (it->name == "opus") {
3335 EXPECT_EQ(111, it->id);
wu@webrtc.org9caf2762013-12-11 18:25:07 +00003336 ASSERT_TRUE(it->params.find("minptime") != it->params.end());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003337 EXPECT_EQ("10", it->params.find("minptime")->second);
wu@webrtc.org9caf2762013-12-11 18:25:07 +00003338 ASSERT_TRUE(it->params.find("maxptime") != it->params.end());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003339 EXPECT_EQ("60", it->params.find("maxptime")->second);
minyue@webrtc.org4ef22d12014-11-17 09:26:39 +00003340 ASSERT_TRUE(it->params.find("useinbandfec") != it->params.end());
3341 EXPECT_EQ("1", it->params.find("useinbandfec")->second);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003342 }
3343 }
3344
3345 engine.Terminate();
3346}
3347
3348// Tests that VoE supports at least 32 channels
3349TEST(WebRtcVoiceEngineTest, Has32Channels) {
3350 cricket::WebRtcVoiceEngine engine;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003351 EXPECT_TRUE(engine.Init(rtc::Thread::Current()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003352
3353 cricket::VoiceMediaChannel* channels[32];
3354 int num_channels = 0;
3355
3356 while (num_channels < ARRAY_SIZE(channels)) {
3357 cricket::VoiceMediaChannel* channel = engine.CreateChannel();
3358 if (!channel)
3359 break;
3360
3361 channels[num_channels++] = channel;
3362 }
3363
3364 int expected = ARRAY_SIZE(channels);
3365 EXPECT_EQ(expected, num_channels);
3366
3367 while (num_channels > 0) {
3368 delete channels[--num_channels];
3369 }
3370
3371 engine.Terminate();
3372}
3373
3374// Test that we set our preferred codecs properly.
3375TEST(WebRtcVoiceEngineTest, SetRecvCodecs) {
3376 cricket::WebRtcVoiceEngine engine;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003377 EXPECT_TRUE(engine.Init(rtc::Thread::Current()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003378 cricket::WebRtcVoiceMediaChannel channel(&engine);
3379 EXPECT_TRUE(channel.SetRecvCodecs(engine.codecs()));
3380}
3381
3382#ifdef WIN32
3383// Test our workarounds to WebRtc VoE' munging of the coinit count
3384TEST(WebRtcVoiceEngineTest, CoInitialize) {
3385 cricket::WebRtcVoiceEngine* engine = new cricket::WebRtcVoiceEngine();
3386
3387 // Initial refcount should be 0.
3388 EXPECT_EQ(S_OK, CoInitializeEx(NULL, COINIT_MULTITHREADED));
3389
3390 // Engine should start even with COM already inited.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003391 EXPECT_TRUE(engine->Init(rtc::Thread::Current()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003392 engine->Terminate();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003393 EXPECT_TRUE(engine->Init(rtc::Thread::Current()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003394 engine->Terminate();
3395
3396 // Refcount after terminate should be 1 (in reality 3); test if it is nonzero.
3397 EXPECT_EQ(S_FALSE, CoInitializeEx(NULL, COINIT_MULTITHREADED));
3398 // Decrement refcount to (hopefully) 0.
3399 CoUninitialize();
3400 CoUninitialize();
3401 delete engine;
3402
3403 // Ensure refcount is 0.
3404 EXPECT_EQ(S_OK, CoInitializeEx(NULL, COINIT_MULTITHREADED));
3405 CoUninitialize();
3406}
3407#endif
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +00003408
Fredrik Solenberg4b60c732015-05-07 14:07:48 +02003409TEST_F(WebRtcVoiceEngineTestFake, ChangeCombinedBweOption_Call) {
3410 // Test that changing the combined_audio_video_bwe option results in the
3411 // expected state changes on an associated Call.
3412 cricket::FakeCall call(webrtc::Call::Config(nullptr));
3413 const uint32 kAudioSsrc1 = 223;
3414 const uint32 kAudioSsrc2 = 224;
3415
3416 EXPECT_TRUE(SetupEngine());
3417 cricket::WebRtcVoiceMediaChannel* media_channel =
3418 static_cast<cricket::WebRtcVoiceMediaChannel*>(channel_);
3419 media_channel->SetCall(&call);
3420 EXPECT_TRUE(media_channel->AddRecvStream(
3421 cricket::StreamParams::CreateLegacy(kAudioSsrc1)));
3422 EXPECT_TRUE(media_channel->AddRecvStream(
3423 cricket::StreamParams::CreateLegacy(kAudioSsrc2)));
3424
3425 // Combined BWE should not be set up yet.
3426 EXPECT_EQ(0, call.GetAudioReceiveStreams().size());
3427
3428 // Enable combined BWE option - now it should be set up.
3429 cricket::AudioOptions options;
3430 options.combined_audio_video_bwe.Set(true);
3431 EXPECT_TRUE(media_channel->SetOptions(options));
3432 EXPECT_EQ(2, call.GetAudioReceiveStreams().size());
3433 EXPECT_NE(nullptr, call.GetAudioReceiveStream(kAudioSsrc1));
3434 EXPECT_NE(nullptr, call.GetAudioReceiveStream(kAudioSsrc2));
3435
3436 // Disable combined BWE option - should be disabled again.
3437 options.combined_audio_video_bwe.Set(false);
3438 EXPECT_TRUE(media_channel->SetOptions(options));
3439 EXPECT_EQ(0, call.GetAudioReceiveStreams().size());
3440
3441 media_channel->SetCall(nullptr);
3442}
3443
3444TEST_F(WebRtcVoiceEngineTestFake, ConfigureCombinedBwe_Call) {
3445 // Test that calling SetCall() on the voice media channel results in the
3446 // expected state changes in Call.
3447 cricket::FakeCall call(webrtc::Call::Config(nullptr));
3448 cricket::FakeCall call2(webrtc::Call::Config(nullptr));
3449 const uint32 kAudioSsrc1 = 223;
3450 const uint32 kAudioSsrc2 = 224;
3451
3452 EXPECT_TRUE(SetupEngine());
3453 cricket::WebRtcVoiceMediaChannel* media_channel =
3454 static_cast<cricket::WebRtcVoiceMediaChannel*>(channel_);
3455 cricket::AudioOptions options;
3456 options.combined_audio_video_bwe.Set(true);
3457 EXPECT_TRUE(media_channel->SetOptions(options));
3458 EXPECT_TRUE(media_channel->AddRecvStream(
3459 cricket::StreamParams::CreateLegacy(kAudioSsrc1)));
3460 EXPECT_TRUE(media_channel->AddRecvStream(
3461 cricket::StreamParams::CreateLegacy(kAudioSsrc2)));
3462
3463 // Combined BWE should not be set up yet.
3464 EXPECT_EQ(0, call.GetAudioReceiveStreams().size());
3465
3466 // Register - should be enabled.
3467 media_channel->SetCall(&call);
3468 EXPECT_EQ(2, call.GetAudioReceiveStreams().size());
3469 EXPECT_NE(nullptr, call.GetAudioReceiveStream(kAudioSsrc1));
3470 EXPECT_NE(nullptr, call.GetAudioReceiveStream(kAudioSsrc2));
3471
3472 // Re-register - should now be enabled on new call.
3473 media_channel->SetCall(&call2);
3474 EXPECT_EQ(0, call.GetAudioReceiveStreams().size());
3475 EXPECT_EQ(2, call2.GetAudioReceiveStreams().size());
3476 EXPECT_NE(nullptr, call2.GetAudioReceiveStream(kAudioSsrc1));
3477 EXPECT_NE(nullptr, call2.GetAudioReceiveStream(kAudioSsrc2));
3478
3479 // Unregister - should be disabled again.
3480 media_channel->SetCall(nullptr);
3481 EXPECT_EQ(0, call.GetAudioReceiveStreams().size());
3482}
3483
3484TEST_F(WebRtcVoiceEngineTestFake, ConfigureCombinedBweForNewRecvStreams_Call) {
3485 // Test that adding receive streams after enabling combined bandwidth
3486 // estimation will correctly configure each channel.
3487 cricket::FakeCall call(webrtc::Call::Config(nullptr));
3488
3489 EXPECT_TRUE(SetupEngine());
3490 cricket::WebRtcVoiceMediaChannel* media_channel =
3491 static_cast<cricket::WebRtcVoiceMediaChannel*>(channel_);
3492 media_channel->SetCall(&call);
3493 cricket::AudioOptions options;
3494 options.combined_audio_video_bwe.Set(true);
3495 EXPECT_TRUE(media_channel->SetOptions(options));
3496
3497 static const uint32 kSsrcs[] = {1, 2, 3, 4};
3498 for (unsigned int i = 0; i < ARRAY_SIZE(kSsrcs); ++i) {
3499 EXPECT_TRUE(media_channel->AddRecvStream(
3500 cricket::StreamParams::CreateLegacy(kSsrcs[i])));
3501 EXPECT_NE(nullptr, call.GetAudioReceiveStream(kSsrcs[i]));
3502 }
3503 EXPECT_EQ(ARRAY_SIZE(kSsrcs), call.GetAudioReceiveStreams().size());
3504
3505 media_channel->SetCall(nullptr);
3506 EXPECT_EQ(0, call.GetAudioReceiveStreams().size());
3507}
3508
3509TEST_F(WebRtcVoiceEngineTestFake, ConfigureCombinedBweExtensions_Call) {
3510 // Test that setting the header extensions results in the expected state
3511 // changes on an associated Call.
3512 cricket::FakeCall call(webrtc::Call::Config(nullptr));
3513 std::vector<uint32> ssrcs;
3514 ssrcs.push_back(223);
3515 ssrcs.push_back(224);
3516
3517 EXPECT_TRUE(SetupEngine());
3518 cricket::WebRtcVoiceMediaChannel* media_channel =
3519 static_cast<cricket::WebRtcVoiceMediaChannel*>(channel_);
3520 media_channel->SetCall(&call);
3521 cricket::AudioOptions options;
3522 options.combined_audio_video_bwe.Set(true);
3523 EXPECT_TRUE(media_channel->SetOptions(options));
3524 for (uint32 ssrc : ssrcs) {
3525 EXPECT_TRUE(media_channel->AddRecvStream(
3526 cricket::StreamParams::CreateLegacy(ssrc)));
3527 }
3528
3529 // Combined BWE should be set up, but with no configured extensions.
3530 EXPECT_EQ(2, call.GetAudioReceiveStreams().size());
3531 for (uint32 ssrc : ssrcs) {
3532 const auto* s = call.GetAudioReceiveStream(ssrc);
3533 EXPECT_NE(nullptr, s);
3534 EXPECT_EQ(0, s->GetConfig().rtp.extensions.size());
3535 }
3536
3537 // Set up receive extensions.
3538 const auto& e_exts = engine_.rtp_header_extensions();
3539 channel_->SetRecvRtpHeaderExtensions(e_exts);
3540 EXPECT_EQ(2, call.GetAudioReceiveStreams().size());
3541 for (uint32 ssrc : ssrcs) {
3542 const auto* s = call.GetAudioReceiveStream(ssrc);
3543 EXPECT_NE(nullptr, s);
3544 const auto& s_exts = s->GetConfig().rtp.extensions;
3545 EXPECT_EQ(e_exts.size(), s_exts.size());
3546 for (const auto& e_ext : e_exts) {
3547 for (const auto& s_ext : s_exts) {
3548 if (e_ext.id == s_ext.id) {
3549 EXPECT_EQ(e_ext.uri, s_ext.name);
3550 }
3551 }
3552 }
3553 }
3554
3555 // Disable receive extensions.
3556 std::vector<cricket::RtpHeaderExtension> extensions;
3557 channel_->SetRecvRtpHeaderExtensions(extensions);
3558 for (uint32 ssrc : ssrcs) {
3559 const auto* s = call.GetAudioReceiveStream(ssrc);
3560 EXPECT_NE(nullptr, s);
3561 EXPECT_EQ(0, s->GetConfig().rtp.extensions.size());
3562 }
3563
3564 media_channel->SetCall(nullptr);
3565}
3566
3567TEST_F(WebRtcVoiceEngineTestFake, DeliverAudioPacket_Call) {
3568 // Test that packets are forwarded to the Call when configured accordingly.
3569 cricket::FakeCall call(webrtc::Call::Config(nullptr));
3570 const uint32 kAudioSsrc = 1;
3571 rtc::Buffer kPcmuPacket(kPcmuFrame, sizeof(kPcmuFrame));
3572 static const unsigned char kRtcp[] = {
3573 0x80, 0xc9, 0x00, 0x01, 0x00, 0x00, 0x00, 0x02,
3574 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00,
3575 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
3576 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
3577 };
3578 rtc::Buffer kRtcpPacket(kRtcp, sizeof(kRtcp));
3579
3580 EXPECT_TRUE(SetupEngine());
3581 cricket::WebRtcVoiceMediaChannel* media_channel =
3582 static_cast<cricket::WebRtcVoiceMediaChannel*>(channel_);
3583 cricket::AudioOptions options;
3584 options.combined_audio_video_bwe.Set(true);
3585 EXPECT_TRUE(media_channel->SetOptions(options));
3586 EXPECT_TRUE(media_channel->AddRecvStream(
3587 cricket::StreamParams::CreateLegacy(kAudioSsrc)));
3588
3589 // Call not set on media channel, so no packets can be forwarded.
3590 EXPECT_EQ(0, call.GetAudioReceiveStreams().size());
3591 channel_->OnPacketReceived(&kPcmuPacket, rtc::PacketTime());
3592 channel_->OnRtcpReceived(&kRtcpPacket, rtc::PacketTime());
3593 EXPECT_EQ(0, call.GetAudioReceiveStreams().size());
3594
3595 // Set Call, now there should be a receive stream which is forwarded packets.
3596 media_channel->SetCall(&call);
3597 EXPECT_EQ(1, call.GetAudioReceiveStreams().size());
3598 const cricket::FakeAudioReceiveStream* s =
3599 call.GetAudioReceiveStream(kAudioSsrc);
3600 EXPECT_EQ(0, s->received_packets());
3601 channel_->OnPacketReceived(&kPcmuPacket, rtc::PacketTime());
3602 EXPECT_EQ(1, s->received_packets());
3603 channel_->OnRtcpReceived(&kRtcpPacket, rtc::PacketTime());
3604 EXPECT_EQ(2, s->received_packets());
3605
3606 media_channel->SetCall(nullptr);
3607}