blob: 89d4c4d43ab10ad0858fae64359de573ccde14f2 [file] [log] [blame]
henrike@webrtc.org79047f92014-03-06 23:46:59 +00001/*
2 * libjingle
3 * Copyright 2008 Google Inc.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright notice,
11 * this list of conditions and the following disclaimer in the documentation
12 * and/or other materials provided with the distribution.
13 * 3. The name of the author may not be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
19 * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
21 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
22 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
23 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
24 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
25 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
henrike@webrtc.org28e20752013-07-10 00:45:36 +000027
28#ifdef WIN32
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000029#include "webrtc/base/win32.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000030#include <objbase.h>
31#endif
32
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000033#include "webrtc/base/byteorder.h"
34#include "webrtc/base/gunit.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000035#include "talk/media/base/constants.h"
36#include "talk/media/base/fakemediaengine.h"
37#include "talk/media/base/fakemediaprocessor.h"
wu@webrtc.orgde305012013-10-31 15:40:38 +000038#include "talk/media/base/fakenetworkinterface.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000039#include "talk/media/base/fakertp.h"
40#include "talk/media/webrtc/fakewebrtcvoiceengine.h"
41#include "talk/media/webrtc/webrtcvoiceengine.h"
42#include "talk/p2p/base/fakesession.h"
43#include "talk/session/media/channel.h"
44
45// Tests for the WebRtcVoiceEngine/VoiceChannel code.
46
buildbot@webrtc.org150835e2014-05-06 15:54:38 +000047using cricket::kRtpAudioLevelHeaderExtension;
48using cricket::kRtpAbsoluteSenderTimeHeaderExtension;
49
henrike@webrtc.org28e20752013-07-10 00:45:36 +000050static const cricket::AudioCodec kPcmuCodec(0, "PCMU", 8000, 64000, 1, 0);
51static const cricket::AudioCodec kIsacCodec(103, "ISAC", 16000, 32000, 1, 0);
52static const cricket::AudioCodec kCeltCodec(110, "CELT", 32000, 64000, 2, 0);
53static const cricket::AudioCodec kOpusCodec(111, "opus", 48000, 64000, 2, 0);
54static const cricket::AudioCodec kRedCodec(117, "red", 8000, 0, 1, 0);
55static const cricket::AudioCodec kCn8000Codec(13, "CN", 8000, 0, 1, 0);
56static const cricket::AudioCodec kCn16000Codec(105, "CN", 16000, 0, 1, 0);
57static const cricket::AudioCodec
58 kTelephoneEventCodec(106, "telephone-event", 8000, 0, 1, 0);
59static const cricket::AudioCodec* const kAudioCodecs[] = {
60 &kPcmuCodec, &kIsacCodec, &kCeltCodec, &kOpusCodec, &kRedCodec,
61 &kCn8000Codec, &kCn16000Codec, &kTelephoneEventCodec,
62};
63const char kRingbackTone[] = "RIFF____WAVE____ABCD1234";
64static uint32 kSsrc1 = 0x99;
65static uint32 kSsrc2 = 0x98;
66
67class FakeVoEWrapper : public cricket::VoEWrapper {
68 public:
69 explicit FakeVoEWrapper(cricket::FakeWebRtcVoiceEngine* engine)
70 : cricket::VoEWrapper(engine, // processing
71 engine, // base
72 engine, // codec
73 engine, // dtmf
74 engine, // file
75 engine, // hw
76 engine, // media
77 engine, // neteq
78 engine, // network
79 engine, // rtp
80 engine, // sync
81 engine) { // volume
82 }
83};
84
wu@webrtc.org97077a32013-10-25 21:18:33 +000085class FakeVoETraceWrapper : public cricket::VoETraceWrapper {
henrike@webrtc.org28e20752013-07-10 00:45:36 +000086 public:
87 virtual int SetTraceFilter(const unsigned int filter) {
wu@webrtc.org97077a32013-10-25 21:18:33 +000088 filter_ = filter;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000089 return 0;
90 }
91 virtual int SetTraceFile(const char* fileNameUTF8) {
92 return 0;
93 }
94 virtual int SetTraceCallback(webrtc::TraceCallback* callback) {
95 return 0;
96 }
wu@webrtc.org97077a32013-10-25 21:18:33 +000097 unsigned int filter_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000098};
99
100class WebRtcVoiceEngineTestFake : public testing::Test {
101 public:
102 class ChannelErrorListener : public sigslot::has_slots<> {
103 public:
104 explicit ChannelErrorListener(cricket::VoiceMediaChannel* channel)
105 : ssrc_(0), error_(cricket::VoiceMediaChannel::ERROR_NONE) {
106 ASSERT(channel != NULL);
107 channel->SignalMediaError.connect(
108 this, &ChannelErrorListener::OnVoiceChannelError);
109 }
110 void OnVoiceChannelError(uint32 ssrc,
111 cricket::VoiceMediaChannel::Error error) {
112 ssrc_ = ssrc;
113 error_ = error;
114 }
115 void Reset() {
116 ssrc_ = 0;
117 error_ = cricket::VoiceMediaChannel::ERROR_NONE;
118 }
119 uint32 ssrc() const {
120 return ssrc_;
121 }
122 cricket::VoiceMediaChannel::Error error() const {
123 return error_;
124 }
125
126 private:
127 uint32 ssrc_;
128 cricket::VoiceMediaChannel::Error error_;
129 };
130
131 WebRtcVoiceEngineTestFake()
132 : voe_(kAudioCodecs, ARRAY_SIZE(kAudioCodecs)),
133 voe_sc_(kAudioCodecs, ARRAY_SIZE(kAudioCodecs)),
wu@webrtc.org97077a32013-10-25 21:18:33 +0000134 trace_wrapper_(new FakeVoETraceWrapper()),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000135 engine_(new FakeVoEWrapper(&voe_),
136 new FakeVoEWrapper(&voe_sc_),
wu@webrtc.org97077a32013-10-25 21:18:33 +0000137 trace_wrapper_),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000138 channel_(NULL), soundclip_(NULL) {
139 options_conference_.conference_mode.Set(true);
140 options_adjust_agc_.adjust_agc_delta.Set(-10);
141 }
buildbot@webrtc.org150835e2014-05-06 15:54:38 +0000142 bool SetupEngineWithoutStream() {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000143 if (!engine_.Init(rtc::Thread::Current())) {
buildbot@webrtc.org150835e2014-05-06 15:54:38 +0000144 return false;
145 }
146 channel_ = engine_.CreateChannel();
147 return (channel_ != NULL);
148 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000149 bool SetupEngine() {
buildbot@webrtc.org150835e2014-05-06 15:54:38 +0000150 if (!SetupEngineWithoutStream()) {
151 return false;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000152 }
buildbot@webrtc.org150835e2014-05-06 15:54:38 +0000153 return channel_->AddSendStream(
154 cricket::StreamParams::CreateLegacy(kSsrc1));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000155 }
wu@webrtc.org9dba5252013-08-05 20:36:57 +0000156 void SetupForMultiSendStream() {
157 EXPECT_TRUE(SetupEngine());
158 // Remove stream added in Setup, which is corresponding to default channel.
159 int default_channel_num = voe_.GetLastChannel();
henrike@webrtc.org7666db72013-08-22 14:45:42 +0000160 uint32 default_send_ssrc = 0u;
wu@webrtc.org9dba5252013-08-05 20:36:57 +0000161 EXPECT_EQ(0, voe_.GetLocalSSRC(default_channel_num, default_send_ssrc));
162 EXPECT_EQ(kSsrc1, default_send_ssrc);
163 EXPECT_TRUE(channel_->RemoveSendStream(default_send_ssrc));
164
165 // Verify the default channel still exists.
166 EXPECT_EQ(0, voe_.GetLocalSSRC(default_channel_num, default_send_ssrc));
167 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000168 void DeliverPacket(const void* data, int len) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000169 rtc::Buffer packet(data, len);
170 channel_->OnPacketReceived(&packet, rtc::PacketTime());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000171 }
172 virtual void TearDown() {
173 delete soundclip_;
174 delete channel_;
175 engine_.Terminate();
176 }
177
wu@webrtc.orgcadf9042013-08-30 21:24:16 +0000178 void TestInsertDtmf(uint32 ssrc, bool caller) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000179 EXPECT_TRUE(engine_.Init(rtc::Thread::Current()));
wu@webrtc.orgcadf9042013-08-30 21:24:16 +0000180 channel_ = engine_.CreateChannel();
181 EXPECT_TRUE(channel_ != NULL);
182 if (caller) {
183 // if this is a caller, local description will be applied and add the
184 // send stream.
185 EXPECT_TRUE(channel_->AddSendStream(
186 cricket::StreamParams::CreateLegacy(kSsrc1)));
187 }
188 int channel_id = voe_.GetLastChannel();
189
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000190 // Test we can only InsertDtmf when the other side supports telephone-event.
191 std::vector<cricket::AudioCodec> codecs;
192 codecs.push_back(kPcmuCodec);
193 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
194 EXPECT_TRUE(channel_->SetSend(cricket::SEND_MICROPHONE));
195 EXPECT_FALSE(channel_->CanInsertDtmf());
196 EXPECT_FALSE(channel_->InsertDtmf(ssrc, 1, 111, cricket::DF_SEND));
197 codecs.push_back(kTelephoneEventCodec);
198 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
199 EXPECT_TRUE(channel_->CanInsertDtmf());
wu@webrtc.orgcadf9042013-08-30 21:24:16 +0000200
201 if (!caller) {
202 // There's no active send channel yet.
203 EXPECT_FALSE(channel_->InsertDtmf(ssrc, 2, 123, cricket::DF_SEND));
204 EXPECT_TRUE(channel_->AddSendStream(
205 cricket::StreamParams::CreateLegacy(kSsrc1)));
206 }
207
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000208 // Check we fail if the ssrc is invalid.
209 EXPECT_FALSE(channel_->InsertDtmf(-1, 1, 111, cricket::DF_SEND));
210
211 // Test send
212 EXPECT_FALSE(voe_.WasSendTelephoneEventCalled(channel_id, 2, 123));
213 EXPECT_TRUE(channel_->InsertDtmf(ssrc, 2, 123, cricket::DF_SEND));
214 EXPECT_TRUE(voe_.WasSendTelephoneEventCalled(channel_id, 2, 123));
215
216 // Test play
217 EXPECT_FALSE(voe_.WasPlayDtmfToneCalled(3, 134));
218 EXPECT_TRUE(channel_->InsertDtmf(ssrc, 3, 134, cricket::DF_PLAY));
219 EXPECT_TRUE(voe_.WasPlayDtmfToneCalled(3, 134));
220
221 // Test send and play
222 EXPECT_FALSE(voe_.WasSendTelephoneEventCalled(channel_id, 4, 145));
223 EXPECT_FALSE(voe_.WasPlayDtmfToneCalled(4, 145));
224 EXPECT_TRUE(channel_->InsertDtmf(ssrc, 4, 145,
225 cricket::DF_PLAY | cricket::DF_SEND));
226 EXPECT_TRUE(voe_.WasSendTelephoneEventCalled(channel_id, 4, 145));
227 EXPECT_TRUE(voe_.WasPlayDtmfToneCalled(4, 145));
228 }
229
230 // Test that send bandwidth is set correctly.
231 // |codec| is the codec under test.
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000232 // |max_bitrate| is a parameter to set to SetMaxSendBandwidth().
233 // |expected_result| is the expected result from SetMaxSendBandwidth().
234 // |expected_bitrate| is the expected audio bitrate afterward.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000235 void TestSendBandwidth(const cricket::AudioCodec& codec,
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000236 int max_bitrate,
237 bool expected_result,
238 int expected_bitrate) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000239 int channel_num = voe_.GetLastChannel();
240 std::vector<cricket::AudioCodec> codecs;
241
242 codecs.push_back(codec);
243 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
244
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000245 bool result = channel_->SetMaxSendBandwidth(max_bitrate);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000246 EXPECT_EQ(expected_result, result);
247
wu@webrtc.org1d1ffc92013-10-16 18:12:02 +0000248 webrtc::CodecInst temp_codec;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000249 EXPECT_FALSE(voe_.GetSendCodec(channel_num, temp_codec));
250
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000251 EXPECT_EQ(expected_bitrate, temp_codec.rate);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000252 }
253
buildbot@webrtc.org150835e2014-05-06 15:54:38 +0000254 void TestSetSendRtpHeaderExtensions(const std::string& ext) {
255 EXPECT_TRUE(SetupEngineWithoutStream());
256 int channel_num = voe_.GetLastChannel();
wu@webrtc.org9dba5252013-08-05 20:36:57 +0000257
henrike@webrtc.org79047f92014-03-06 23:46:59 +0000258 // Ensure extensions are off by default.
buildbot@webrtc.org150835e2014-05-06 15:54:38 +0000259 EXPECT_EQ(-1, voe_.GetSendRtpExtensionId(channel_num, ext));
wu@webrtc.org9dba5252013-08-05 20:36:57 +0000260
buildbot@webrtc.org150835e2014-05-06 15:54:38 +0000261 std::vector<cricket::RtpHeaderExtension> extensions;
wu@webrtc.org9dba5252013-08-05 20:36:57 +0000262 // Ensure unknown extensions won't cause an error.
263 extensions.push_back(cricket::RtpHeaderExtension(
henrike@webrtc.org79047f92014-03-06 23:46:59 +0000264 "urn:ietf:params:unknownextention", 1));
wu@webrtc.org9dba5252013-08-05 20:36:57 +0000265 EXPECT_TRUE(channel_->SetSendRtpHeaderExtensions(extensions));
buildbot@webrtc.org150835e2014-05-06 15:54:38 +0000266 EXPECT_EQ(-1, voe_.GetSendRtpExtensionId(channel_num, ext));
wu@webrtc.org9dba5252013-08-05 20:36:57 +0000267
henrike@webrtc.org79047f92014-03-06 23:46:59 +0000268 // Ensure extensions stay off with an empty list of headers.
269 extensions.clear();
wu@webrtc.org9dba5252013-08-05 20:36:57 +0000270 EXPECT_TRUE(channel_->SetSendRtpHeaderExtensions(extensions));
buildbot@webrtc.org150835e2014-05-06 15:54:38 +0000271 EXPECT_EQ(-1, voe_.GetSendRtpExtensionId(channel_num, ext));
wu@webrtc.org9dba5252013-08-05 20:36:57 +0000272
buildbot@webrtc.org150835e2014-05-06 15:54:38 +0000273 // Ensure extension is set properly.
274 const int id = 1;
275 extensions.push_back(cricket::RtpHeaderExtension(ext, id));
wu@webrtc.org9dba5252013-08-05 20:36:57 +0000276 EXPECT_TRUE(channel_->SetSendRtpHeaderExtensions(extensions));
buildbot@webrtc.org150835e2014-05-06 15:54:38 +0000277 EXPECT_EQ(id, voe_.GetSendRtpExtensionId(channel_num, ext));
wu@webrtc.org9dba5252013-08-05 20:36:57 +0000278
buildbot@webrtc.org150835e2014-05-06 15:54:38 +0000279 // Ensure extension is set properly on new channel.
280 // The first stream to occupy the default channel.
281 EXPECT_TRUE(channel_->AddSendStream(
282 cricket::StreamParams::CreateLegacy(123)));
283 EXPECT_TRUE(channel_->AddSendStream(
284 cricket::StreamParams::CreateLegacy(234)));
285 int new_channel_num = voe_.GetLastChannel();
286 EXPECT_NE(channel_num, new_channel_num);
287 EXPECT_EQ(id, voe_.GetSendRtpExtensionId(new_channel_num, ext));
henrike@webrtc.org79047f92014-03-06 23:46:59 +0000288
289 // Ensure all extensions go back off with an empty list.
wu@webrtc.org9dba5252013-08-05 20:36:57 +0000290 extensions.clear();
291 EXPECT_TRUE(channel_->SetSendRtpHeaderExtensions(extensions));
buildbot@webrtc.org150835e2014-05-06 15:54:38 +0000292 EXPECT_EQ(-1, voe_.GetSendRtpExtensionId(channel_num, ext));
293 EXPECT_EQ(-1, voe_.GetSendRtpExtensionId(new_channel_num, ext));
henrike@webrtc.org79047f92014-03-06 23:46:59 +0000294 }
295
buildbot@webrtc.org150835e2014-05-06 15:54:38 +0000296 void TestSetRecvRtpHeaderExtensions(const std::string& ext) {
297 EXPECT_TRUE(SetupEngineWithoutStream());
298 int channel_num = voe_.GetLastChannel();
henrike@webrtc.org79047f92014-03-06 23:46:59 +0000299
henrike@webrtc.org79047f92014-03-06 23:46:59 +0000300 // Ensure extensions are off by default.
buildbot@webrtc.org150835e2014-05-06 15:54:38 +0000301 EXPECT_EQ(-1, voe_.GetReceiveRtpExtensionId(channel_num, ext));
henrike@webrtc.org79047f92014-03-06 23:46:59 +0000302
buildbot@webrtc.org150835e2014-05-06 15:54:38 +0000303 std::vector<cricket::RtpHeaderExtension> extensions;
henrike@webrtc.org79047f92014-03-06 23:46:59 +0000304 // Ensure unknown extensions won't cause an error.
305 extensions.push_back(cricket::RtpHeaderExtension(
306 "urn:ietf:params:unknownextention", 1));
307 EXPECT_TRUE(channel_->SetRecvRtpHeaderExtensions(extensions));
buildbot@webrtc.org150835e2014-05-06 15:54:38 +0000308 EXPECT_EQ(-1, voe_.GetReceiveRtpExtensionId(channel_num, ext));
henrike@webrtc.org79047f92014-03-06 23:46:59 +0000309
buildbot@webrtc.org150835e2014-05-06 15:54:38 +0000310 // Ensure extensions stay off with an empty list of headers.
henrike@webrtc.org79047f92014-03-06 23:46:59 +0000311 extensions.clear();
312 EXPECT_TRUE(channel_->SetRecvRtpHeaderExtensions(extensions));
buildbot@webrtc.org150835e2014-05-06 15:54:38 +0000313 EXPECT_EQ(-1, voe_.GetReceiveRtpExtensionId(channel_num, ext));
henrike@webrtc.org79047f92014-03-06 23:46:59 +0000314
buildbot@webrtc.org150835e2014-05-06 15:54:38 +0000315 // Ensure extension is set properly.
316 const int id = 2;
317 extensions.push_back(cricket::RtpHeaderExtension(ext, id));
henrike@webrtc.org79047f92014-03-06 23:46:59 +0000318 EXPECT_TRUE(channel_->SetRecvRtpHeaderExtensions(extensions));
buildbot@webrtc.org150835e2014-05-06 15:54:38 +0000319 EXPECT_EQ(id, voe_.GetReceiveRtpExtensionId(channel_num, ext));
henrike@webrtc.org79047f92014-03-06 23:46:59 +0000320
buildbot@webrtc.org150835e2014-05-06 15:54:38 +0000321 // Ensure extension is set properly on new channel.
322 // The first stream to occupy the default channel.
323 EXPECT_TRUE(channel_->AddRecvStream(
324 cricket::StreamParams::CreateLegacy(345)));
325 EXPECT_TRUE(channel_->AddRecvStream(
326 cricket::StreamParams::CreateLegacy(456)));
327 int new_channel_num = voe_.GetLastChannel();
328 EXPECT_NE(channel_num, new_channel_num);
329 EXPECT_EQ(id, voe_.GetReceiveRtpExtensionId(new_channel_num, ext));
330
331 // Ensure all extensions go back off with an empty list.
henrike@webrtc.org79047f92014-03-06 23:46:59 +0000332 extensions.clear();
333 EXPECT_TRUE(channel_->SetRecvRtpHeaderExtensions(extensions));
buildbot@webrtc.org150835e2014-05-06 15:54:38 +0000334 EXPECT_EQ(-1, voe_.GetReceiveRtpExtensionId(channel_num, ext));
335 EXPECT_EQ(-1, voe_.GetReceiveRtpExtensionId(new_channel_num, ext));
wu@webrtc.org9dba5252013-08-05 20:36:57 +0000336 }
337
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000338 protected:
339 cricket::FakeWebRtcVoiceEngine voe_;
340 cricket::FakeWebRtcVoiceEngine voe_sc_;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000341 FakeVoETraceWrapper* trace_wrapper_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000342 cricket::WebRtcVoiceEngine engine_;
343 cricket::VoiceMediaChannel* channel_;
344 cricket::SoundclipMedia* soundclip_;
345
346 cricket::AudioOptions options_conference_;
347 cricket::AudioOptions options_adjust_agc_;
348};
349
350// Tests that our stub library "works".
351TEST_F(WebRtcVoiceEngineTestFake, StartupShutdown) {
352 EXPECT_FALSE(voe_.IsInited());
353 EXPECT_FALSE(voe_sc_.IsInited());
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000354 EXPECT_TRUE(engine_.Init(rtc::Thread::Current()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000355 EXPECT_TRUE(voe_.IsInited());
wu@webrtc.org4551b792013-10-09 15:37:36 +0000356 // The soundclip engine is lazily initialized.
357 EXPECT_FALSE(voe_sc_.IsInited());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000358 engine_.Terminate();
359 EXPECT_FALSE(voe_.IsInited());
360 EXPECT_FALSE(voe_sc_.IsInited());
361}
362
363// Tests that we can create and destroy a channel.
364TEST_F(WebRtcVoiceEngineTestFake, CreateChannel) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000365 EXPECT_TRUE(engine_.Init(rtc::Thread::Current()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000366 channel_ = engine_.CreateChannel();
367 EXPECT_TRUE(channel_ != NULL);
368}
369
370// Tests that we properly handle failures in CreateChannel.
371TEST_F(WebRtcVoiceEngineTestFake, CreateChannelFail) {
372 voe_.set_fail_create_channel(true);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000373 EXPECT_TRUE(engine_.Init(rtc::Thread::Current()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000374 channel_ = engine_.CreateChannel();
375 EXPECT_TRUE(channel_ == NULL);
376}
377
378// Tests that the list of supported codecs is created properly and ordered
379// correctly
380TEST_F(WebRtcVoiceEngineTestFake, CodecPreference) {
381 const std::vector<cricket::AudioCodec>& codecs = engine_.codecs();
382 ASSERT_FALSE(codecs.empty());
383 EXPECT_STRCASEEQ("opus", codecs[0].name.c_str());
384 EXPECT_EQ(48000, codecs[0].clockrate);
385 EXPECT_EQ(2, codecs[0].channels);
386 EXPECT_EQ(64000, codecs[0].bitrate);
387 int pref = codecs[0].preference;
388 for (size_t i = 1; i < codecs.size(); ++i) {
389 EXPECT_GT(pref, codecs[i].preference);
390 pref = codecs[i].preference;
391 }
392}
393
394// Tests that we can find codecs by name or id, and that we interpret the
395// clockrate and bitrate fields properly.
396TEST_F(WebRtcVoiceEngineTestFake, FindCodec) {
397 cricket::AudioCodec codec;
398 webrtc::CodecInst codec_inst;
399 // Find PCMU with explicit clockrate and bitrate.
400 EXPECT_TRUE(engine_.FindWebRtcCodec(kPcmuCodec, &codec_inst));
401 // Find ISAC with explicit clockrate and 0 bitrate.
402 EXPECT_TRUE(engine_.FindWebRtcCodec(kIsacCodec, &codec_inst));
403 // Find telephone-event with explicit clockrate and 0 bitrate.
404 EXPECT_TRUE(engine_.FindWebRtcCodec(kTelephoneEventCodec, &codec_inst));
405 // Find ISAC with a different payload id.
406 codec = kIsacCodec;
407 codec.id = 127;
408 EXPECT_TRUE(engine_.FindWebRtcCodec(codec, &codec_inst));
409 EXPECT_EQ(codec.id, codec_inst.pltype);
410 // Find PCMU with a 0 clockrate.
411 codec = kPcmuCodec;
412 codec.clockrate = 0;
413 EXPECT_TRUE(engine_.FindWebRtcCodec(codec, &codec_inst));
414 EXPECT_EQ(codec.id, codec_inst.pltype);
415 EXPECT_EQ(8000, codec_inst.plfreq);
416 // Find PCMU with a 0 bitrate.
417 codec = kPcmuCodec;
418 codec.bitrate = 0;
419 EXPECT_TRUE(engine_.FindWebRtcCodec(codec, &codec_inst));
420 EXPECT_EQ(codec.id, codec_inst.pltype);
421 EXPECT_EQ(64000, codec_inst.rate);
422 // Find ISAC with an explicit bitrate.
423 codec = kIsacCodec;
424 codec.bitrate = 32000;
425 EXPECT_TRUE(engine_.FindWebRtcCodec(codec, &codec_inst));
426 EXPECT_EQ(codec.id, codec_inst.pltype);
427 EXPECT_EQ(32000, codec_inst.rate);
428}
429
430// Test that we set our inbound codecs properly, including changing PT.
431TEST_F(WebRtcVoiceEngineTestFake, SetRecvCodecs) {
432 EXPECT_TRUE(SetupEngine());
433 int channel_num = voe_.GetLastChannel();
434 std::vector<cricket::AudioCodec> codecs;
435 codecs.push_back(kIsacCodec);
436 codecs.push_back(kPcmuCodec);
437 codecs.push_back(kTelephoneEventCodec);
438 codecs[0].id = 106; // collide with existing telephone-event
439 codecs[2].id = 126;
440 EXPECT_TRUE(channel_->SetRecvCodecs(codecs));
441 webrtc::CodecInst gcodec;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000442 rtc::strcpyn(gcodec.plname, ARRAY_SIZE(gcodec.plname), "ISAC");
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000443 gcodec.plfreq = 16000;
444 gcodec.channels = 1;
445 EXPECT_EQ(0, voe_.GetRecPayloadType(channel_num, gcodec));
446 EXPECT_EQ(106, gcodec.pltype);
447 EXPECT_STREQ("ISAC", gcodec.plname);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000448 rtc::strcpyn(gcodec.plname, ARRAY_SIZE(gcodec.plname),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000449 "telephone-event");
450 gcodec.plfreq = 8000;
451 EXPECT_EQ(0, voe_.GetRecPayloadType(channel_num, gcodec));
452 EXPECT_EQ(126, gcodec.pltype);
453 EXPECT_STREQ("telephone-event", gcodec.plname);
454}
455
456// Test that we fail to set an unknown inbound codec.
457TEST_F(WebRtcVoiceEngineTestFake, SetRecvCodecsUnsupportedCodec) {
458 EXPECT_TRUE(SetupEngine());
459 std::vector<cricket::AudioCodec> codecs;
460 codecs.push_back(kIsacCodec);
461 codecs.push_back(cricket::AudioCodec(127, "XYZ", 32000, 0, 1, 0));
462 EXPECT_FALSE(channel_->SetRecvCodecs(codecs));
463}
464
465// Test that we fail if we have duplicate types in the inbound list.
466TEST_F(WebRtcVoiceEngineTestFake, SetRecvCodecsDuplicatePayloadType) {
467 EXPECT_TRUE(SetupEngine());
468 std::vector<cricket::AudioCodec> codecs;
469 codecs.push_back(kIsacCodec);
470 codecs.push_back(kCn16000Codec);
471 codecs[1].id = kIsacCodec.id;
472 EXPECT_FALSE(channel_->SetRecvCodecs(codecs));
473}
474
475// Test that we can decode OPUS without stereo parameters.
476TEST_F(WebRtcVoiceEngineTestFake, SetRecvCodecsWithOpusNoStereo) {
477 EXPECT_TRUE(SetupEngine());
478 EXPECT_TRUE(channel_->SetOptions(options_conference_));
479 std::vector<cricket::AudioCodec> codecs;
480 codecs.push_back(kIsacCodec);
481 codecs.push_back(kPcmuCodec);
482 codecs.push_back(kOpusCodec);
483 EXPECT_TRUE(channel_->SetRecvCodecs(codecs));
484 EXPECT_TRUE(channel_->AddRecvStream(
485 cricket::StreamParams::CreateLegacy(kSsrc1)));
486 int channel_num2 = voe_.GetLastChannel();
487 webrtc::CodecInst opus;
488 engine_.FindWebRtcCodec(kOpusCodec, &opus);
489 // Even without stereo parameters, recv codecs still specify channels = 2.
490 EXPECT_EQ(2, opus.channels);
491 EXPECT_EQ(111, opus.pltype);
492 EXPECT_STREQ("opus", opus.plname);
493 opus.pltype = 0;
494 EXPECT_EQ(0, voe_.GetRecPayloadType(channel_num2, opus));
495 EXPECT_EQ(111, opus.pltype);
496}
497
498// Test that we can decode OPUS with stereo = 0.
499TEST_F(WebRtcVoiceEngineTestFake, SetRecvCodecsWithOpus0Stereo) {
500 EXPECT_TRUE(SetupEngine());
501 EXPECT_TRUE(channel_->SetOptions(options_conference_));
502 std::vector<cricket::AudioCodec> codecs;
503 codecs.push_back(kIsacCodec);
504 codecs.push_back(kPcmuCodec);
505 codecs.push_back(kOpusCodec);
506 codecs[2].params["stereo"] = "0";
507 EXPECT_TRUE(channel_->SetRecvCodecs(codecs));
508 EXPECT_TRUE(channel_->AddRecvStream(
509 cricket::StreamParams::CreateLegacy(kSsrc1)));
510 int channel_num2 = voe_.GetLastChannel();
511 webrtc::CodecInst opus;
512 engine_.FindWebRtcCodec(kOpusCodec, &opus);
513 // Even when stereo is off, recv codecs still specify channels = 2.
514 EXPECT_EQ(2, opus.channels);
515 EXPECT_EQ(111, opus.pltype);
516 EXPECT_STREQ("opus", opus.plname);
517 opus.pltype = 0;
518 EXPECT_EQ(0, voe_.GetRecPayloadType(channel_num2, opus));
519 EXPECT_EQ(111, opus.pltype);
520}
521
522// Test that we can decode OPUS with stereo = 1.
523TEST_F(WebRtcVoiceEngineTestFake, SetRecvCodecsWithOpus1Stereo) {
524 EXPECT_TRUE(SetupEngine());
525 EXPECT_TRUE(channel_->SetOptions(options_conference_));
526 std::vector<cricket::AudioCodec> codecs;
527 codecs.push_back(kIsacCodec);
528 codecs.push_back(kPcmuCodec);
529 codecs.push_back(kOpusCodec);
530 codecs[2].params["stereo"] = "1";
531 EXPECT_TRUE(channel_->SetRecvCodecs(codecs));
532 EXPECT_TRUE(channel_->AddRecvStream(
533 cricket::StreamParams::CreateLegacy(kSsrc1)));
534 int channel_num2 = voe_.GetLastChannel();
535 webrtc::CodecInst opus;
536 engine_.FindWebRtcCodec(kOpusCodec, &opus);
537 EXPECT_EQ(2, opus.channels);
538 EXPECT_EQ(111, opus.pltype);
539 EXPECT_STREQ("opus", opus.plname);
540 opus.pltype = 0;
541 EXPECT_EQ(0, voe_.GetRecPayloadType(channel_num2, opus));
542 EXPECT_EQ(111, opus.pltype);
543}
544
545// Test that changes to recv codecs are applied to all streams.
546TEST_F(WebRtcVoiceEngineTestFake, SetRecvCodecsWithMultipleStreams) {
547 EXPECT_TRUE(SetupEngine());
548 EXPECT_TRUE(channel_->SetOptions(options_conference_));
549 std::vector<cricket::AudioCodec> codecs;
550 codecs.push_back(kIsacCodec);
551 codecs.push_back(kPcmuCodec);
552 codecs.push_back(kTelephoneEventCodec);
553 codecs[0].id = 106; // collide with existing telephone-event
554 codecs[2].id = 126;
555 EXPECT_TRUE(channel_->SetRecvCodecs(codecs));
556 EXPECT_TRUE(channel_->AddRecvStream(
557 cricket::StreamParams::CreateLegacy(kSsrc1)));
558 int channel_num2 = voe_.GetLastChannel();
559 webrtc::CodecInst gcodec;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000560 rtc::strcpyn(gcodec.plname, ARRAY_SIZE(gcodec.plname), "ISAC");
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000561 gcodec.plfreq = 16000;
562 gcodec.channels = 1;
563 EXPECT_EQ(0, voe_.GetRecPayloadType(channel_num2, gcodec));
564 EXPECT_EQ(106, gcodec.pltype);
565 EXPECT_STREQ("ISAC", gcodec.plname);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000566 rtc::strcpyn(gcodec.plname, ARRAY_SIZE(gcodec.plname),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000567 "telephone-event");
568 gcodec.plfreq = 8000;
569 gcodec.channels = 1;
570 EXPECT_EQ(0, voe_.GetRecPayloadType(channel_num2, gcodec));
571 EXPECT_EQ(126, gcodec.pltype);
572 EXPECT_STREQ("telephone-event", gcodec.plname);
573}
574
575TEST_F(WebRtcVoiceEngineTestFake, SetRecvCodecsAfterAddingStreams) {
576 EXPECT_TRUE(SetupEngine());
577 EXPECT_TRUE(channel_->SetOptions(options_conference_));
578 std::vector<cricket::AudioCodec> codecs;
579 codecs.push_back(kIsacCodec);
580 codecs[0].id = 106; // collide with existing telephone-event
581
582 EXPECT_TRUE(channel_->AddRecvStream(
583 cricket::StreamParams::CreateLegacy(kSsrc1)));
584 EXPECT_TRUE(channel_->SetRecvCodecs(codecs));
585
586 int channel_num2 = voe_.GetLastChannel();
587 webrtc::CodecInst gcodec;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000588 rtc::strcpyn(gcodec.plname, ARRAY_SIZE(gcodec.plname), "ISAC");
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000589 gcodec.plfreq = 16000;
590 gcodec.channels = 1;
591 EXPECT_EQ(0, voe_.GetRecPayloadType(channel_num2, gcodec));
592 EXPECT_EQ(106, gcodec.pltype);
593 EXPECT_STREQ("ISAC", gcodec.plname);
594}
595
596// Test that we can apply the same set of codecs again while playing.
597TEST_F(WebRtcVoiceEngineTestFake, SetRecvCodecsWhilePlaying) {
598 EXPECT_TRUE(SetupEngine());
599 int channel_num = voe_.GetLastChannel();
600 std::vector<cricket::AudioCodec> codecs;
601 codecs.push_back(kIsacCodec);
602 codecs.push_back(kCn16000Codec);
603 EXPECT_TRUE(channel_->SetRecvCodecs(codecs));
604 EXPECT_TRUE(channel_->SetPlayout(true));
605 EXPECT_TRUE(channel_->SetRecvCodecs(codecs));
606
607 // Changing the payload type of a codec should fail.
608 codecs[0].id = 127;
609 EXPECT_FALSE(channel_->SetRecvCodecs(codecs));
610 EXPECT_TRUE(voe_.GetPlayout(channel_num));
611}
612
613// Test that we can add a codec while playing.
614TEST_F(WebRtcVoiceEngineTestFake, AddRecvCodecsWhilePlaying) {
615 EXPECT_TRUE(SetupEngine());
616 int channel_num = voe_.GetLastChannel();
617 std::vector<cricket::AudioCodec> codecs;
618 codecs.push_back(kIsacCodec);
619 codecs.push_back(kCn16000Codec);
620 EXPECT_TRUE(channel_->SetRecvCodecs(codecs));
621 EXPECT_TRUE(channel_->SetPlayout(true));
622
623 codecs.push_back(kOpusCodec);
624 EXPECT_TRUE(channel_->SetRecvCodecs(codecs));
625 EXPECT_TRUE(voe_.GetPlayout(channel_num));
626 webrtc::CodecInst gcodec;
627 EXPECT_TRUE(engine_.FindWebRtcCodec(kOpusCodec, &gcodec));
628 EXPECT_EQ(kOpusCodec.id, gcodec.pltype);
629}
630
631TEST_F(WebRtcVoiceEngineTestFake, SetSendBandwidthAuto) {
632 EXPECT_TRUE(SetupEngine());
633 EXPECT_TRUE(channel_->SetSendCodecs(engine_.codecs()));
634
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000635 // Test that when autobw is enabled, bitrate is kept as the default
636 // value. autobw is enabled for the following tests because the target
637 // bitrate is <= 0.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000638
639 // ISAC, default bitrate == 32000.
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000640 TestSendBandwidth(kIsacCodec, 0, true, 32000);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000641
642 // PCMU, default bitrate == 64000.
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000643 TestSendBandwidth(kPcmuCodec, -1, true, 64000);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000644
645 // CELT, default bitrate == 64000.
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000646 TestSendBandwidth(kCeltCodec, 0, true, 64000);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000647
648 // opus, default bitrate == 64000.
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000649 TestSendBandwidth(kOpusCodec, -1, true, 64000);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000650}
651
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000652TEST_F(WebRtcVoiceEngineTestFake, SetMaxSendBandwidthMultiRateAsCaller) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000653 EXPECT_TRUE(SetupEngine());
654 EXPECT_TRUE(channel_->SetSendCodecs(engine_.codecs()));
655
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000656 // Test that the bitrate of a multi-rate codec is always the maximum.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000657
658 // ISAC, default bitrate == 32000.
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000659 TestSendBandwidth(kIsacCodec, 128000, true, 128000);
660 TestSendBandwidth(kIsacCodec, 16000, true, 16000);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000661
662 // CELT, default bitrate == 64000.
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000663 TestSendBandwidth(kCeltCodec, 96000, true, 96000);
664 TestSendBandwidth(kCeltCodec, 32000, true, 32000);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000665
666 // opus, default bitrate == 64000.
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000667 TestSendBandwidth(kOpusCodec, 96000, true, 96000);
668 TestSendBandwidth(kOpusCodec, 48000, true, 48000);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000669}
670
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000671TEST_F(WebRtcVoiceEngineTestFake, SetMaxSendBandwidthFixedRateAsCaller) {
672 EXPECT_TRUE(SetupEngine());
673 EXPECT_TRUE(channel_->SetSendCodecs(engine_.codecs()));
674
675 // Test that we can only set a maximum bitrate for a fixed-rate codec
676 // if it's bigger than the fixed rate.
677
678 // PCMU, fixed bitrate == 64000.
679 TestSendBandwidth(kPcmuCodec, 0, true, 64000);
680 TestSendBandwidth(kPcmuCodec, 1, false, 64000);
681 TestSendBandwidth(kPcmuCodec, 128000, true, 64000);
682 TestSendBandwidth(kPcmuCodec, 32000, false, 64000);
683 TestSendBandwidth(kPcmuCodec, 64000, true, 64000);
684 TestSendBandwidth(kPcmuCodec, 63999, false, 64000);
685 TestSendBandwidth(kPcmuCodec, 64001, true, 64000);
686}
687
688TEST_F(WebRtcVoiceEngineTestFake, SetMaxSendBandwidthMultiRateAsCallee) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000689 EXPECT_TRUE(engine_.Init(rtc::Thread::Current()));
wu@webrtc.org1d1ffc92013-10-16 18:12:02 +0000690 channel_ = engine_.CreateChannel();
691 EXPECT_TRUE(channel_ != NULL);
692 EXPECT_TRUE(channel_->SetSendCodecs(engine_.codecs()));
693
694 int desired_bitrate = 128000;
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000695 EXPECT_TRUE(channel_->SetMaxSendBandwidth(desired_bitrate));
wu@webrtc.org1d1ffc92013-10-16 18:12:02 +0000696
697 EXPECT_TRUE(channel_->AddSendStream(
698 cricket::StreamParams::CreateLegacy(kSsrc1)));
699
700 int channel_num = voe_.GetLastChannel();
701 webrtc::CodecInst codec;
702 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, codec));
703 EXPECT_EQ(desired_bitrate, codec.rate);
704}
705
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000706// Test that bitrate cannot be set for CBR codecs.
707// Bitrate is ignored if it is higher than the fixed bitrate.
708// Bitrate less then the fixed bitrate is an error.
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000709TEST_F(WebRtcVoiceEngineTestFake, SetMaxSendBandwidthCbr) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000710 EXPECT_TRUE(SetupEngine());
711 EXPECT_TRUE(channel_->SetSendCodecs(engine_.codecs()));
712
713 webrtc::CodecInst codec;
714 int channel_num = voe_.GetLastChannel();
715 std::vector<cricket::AudioCodec> codecs;
716
717 // PCMU, default bitrate == 64000.
718 codecs.push_back(kPcmuCodec);
719 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
720 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, codec));
721 EXPECT_EQ(64000, codec.rate);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000722 EXPECT_TRUE(channel_->SetMaxSendBandwidth(128000));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000723 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, codec));
724 EXPECT_EQ(64000, codec.rate);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000725 EXPECT_FALSE(channel_->SetMaxSendBandwidth(128));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000726 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, codec));
727 EXPECT_EQ(64000, codec.rate);
728}
729
730// Test that we apply codecs properly.
731TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecs) {
732 EXPECT_TRUE(SetupEngine());
733 int channel_num = voe_.GetLastChannel();
734 std::vector<cricket::AudioCodec> codecs;
735 codecs.push_back(kIsacCodec);
736 codecs.push_back(kPcmuCodec);
737 codecs.push_back(kRedCodec);
738 codecs[0].id = 96;
739 codecs[0].bitrate = 48000;
740 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
wu@webrtc.org05e7b442014-04-01 17:44:24 +0000741 EXPECT_EQ(1, voe_.GetNumSetSendCodecs());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000742 webrtc::CodecInst gcodec;
743 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
744 EXPECT_EQ(96, gcodec.pltype);
745 EXPECT_EQ(48000, gcodec.rate);
746 EXPECT_STREQ("ISAC", gcodec.plname);
747 EXPECT_FALSE(voe_.GetVAD(channel_num));
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +0000748 EXPECT_FALSE(voe_.GetRED(channel_num));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000749 EXPECT_EQ(13, voe_.GetSendCNPayloadType(channel_num, false));
750 EXPECT_EQ(105, voe_.GetSendCNPayloadType(channel_num, true));
751 EXPECT_EQ(106, voe_.GetSendTelephoneEventPayloadType(channel_num));
752}
753
wu@webrtc.org05e7b442014-04-01 17:44:24 +0000754// Test that VoE Channel doesn't call SetSendCodec again if same codec is tried
755// to apply.
756TEST_F(WebRtcVoiceEngineTestFake, DontResetSetSendCodec) {
757 EXPECT_TRUE(SetupEngine());
758 std::vector<cricket::AudioCodec> codecs;
759 codecs.push_back(kIsacCodec);
760 codecs.push_back(kPcmuCodec);
761 codecs.push_back(kRedCodec);
762 codecs[0].id = 96;
763 codecs[0].bitrate = 48000;
764 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
765 EXPECT_EQ(1, voe_.GetNumSetSendCodecs());
766 // Calling SetSendCodec again with same codec which is already set.
767 // In this case media channel shouldn't send codec to VoE.
768 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
769 EXPECT_EQ(1, voe_.GetNumSetSendCodecs());
770}
771
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000772// Test that if clockrate is not 48000 for opus, we fail.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000773TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecOpusBadClockrate) {
774 EXPECT_TRUE(SetupEngine());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000775 std::vector<cricket::AudioCodec> codecs;
776 codecs.push_back(kOpusCodec);
777 codecs[0].bitrate = 0;
778 codecs[0].clockrate = 50000;
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000779 EXPECT_FALSE(channel_->SetSendCodecs(codecs));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000780}
781
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000782// Test that if channels=0 for opus, we fail.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000783TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecOpusBad0ChannelsNoStereo) {
784 EXPECT_TRUE(SetupEngine());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000785 std::vector<cricket::AudioCodec> codecs;
786 codecs.push_back(kOpusCodec);
787 codecs[0].bitrate = 0;
788 codecs[0].channels = 0;
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000789 EXPECT_FALSE(channel_->SetSendCodecs(codecs));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000790}
791
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000792// Test that if channels=0 for opus, we fail.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000793TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecOpusBad0Channels1Stereo) {
794 EXPECT_TRUE(SetupEngine());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000795 std::vector<cricket::AudioCodec> codecs;
796 codecs.push_back(kOpusCodec);
797 codecs[0].bitrate = 0;
798 codecs[0].channels = 0;
799 codecs[0].params["stereo"] = "1";
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000800 EXPECT_FALSE(channel_->SetSendCodecs(codecs));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000801}
802
803// Test that if channel is 1 for opus and there's no stereo, we fail.
804TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecOpus1ChannelNoStereo) {
805 EXPECT_TRUE(SetupEngine());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000806 std::vector<cricket::AudioCodec> codecs;
807 codecs.push_back(kOpusCodec);
808 codecs[0].bitrate = 0;
809 codecs[0].channels = 1;
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000810 EXPECT_FALSE(channel_->SetSendCodecs(codecs));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000811}
812
813// Test that if channel is 1 for opus and stereo=0, we fail.
814TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecOpusBad1Channel0Stereo) {
815 EXPECT_TRUE(SetupEngine());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000816 std::vector<cricket::AudioCodec> codecs;
817 codecs.push_back(kOpusCodec);
818 codecs[0].bitrate = 0;
819 codecs[0].channels = 1;
820 codecs[0].params["stereo"] = "0";
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000821 EXPECT_FALSE(channel_->SetSendCodecs(codecs));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000822}
823
824// Test that if channel is 1 for opus and stereo=1, we fail.
825TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecOpusBad1Channel1Stereo) {
826 EXPECT_TRUE(SetupEngine());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000827 std::vector<cricket::AudioCodec> codecs;
828 codecs.push_back(kOpusCodec);
829 codecs[0].bitrate = 0;
830 codecs[0].channels = 1;
831 codecs[0].params["stereo"] = "1";
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000832 EXPECT_FALSE(channel_->SetSendCodecs(codecs));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000833}
834
835// Test that with bitrate=0 and no stereo,
836// channels and bitrate are 1 and 32000.
837TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecOpusGood0BitrateNoStereo) {
838 EXPECT_TRUE(SetupEngine());
839 int channel_num = voe_.GetLastChannel();
840 std::vector<cricket::AudioCodec> codecs;
841 codecs.push_back(kOpusCodec);
842 codecs[0].bitrate = 0;
843 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
844 webrtc::CodecInst gcodec;
845 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
846 EXPECT_STREQ("opus", gcodec.plname);
847 EXPECT_EQ(1, gcodec.channels);
848 EXPECT_EQ(32000, gcodec.rate);
849}
850
851// Test that with bitrate=0 and stereo=0,
852// channels and bitrate are 1 and 32000.
853TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecOpusGood0Bitrate0Stereo) {
854 EXPECT_TRUE(SetupEngine());
855 int channel_num = voe_.GetLastChannel();
856 std::vector<cricket::AudioCodec> codecs;
857 codecs.push_back(kOpusCodec);
858 codecs[0].bitrate = 0;
859 codecs[0].params["stereo"] = "0";
860 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
861 webrtc::CodecInst gcodec;
862 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
863 EXPECT_STREQ("opus", gcodec.plname);
864 EXPECT_EQ(1, gcodec.channels);
865 EXPECT_EQ(32000, gcodec.rate);
866}
867
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000868// Test that with bitrate=invalid and stereo=0,
869// channels and bitrate are 1 and 32000.
870TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecOpusGoodXBitrate0Stereo) {
871 EXPECT_TRUE(SetupEngine());
872 int channel_num = voe_.GetLastChannel();
873 std::vector<cricket::AudioCodec> codecs;
874 codecs.push_back(kOpusCodec);
875 codecs[0].params["stereo"] = "0";
876 webrtc::CodecInst gcodec;
877
878 // bitrate that's out of the range between 6000 and 510000 will be considered
879 // as invalid and ignored.
880 codecs[0].bitrate = 5999;
881 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
882 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
883 EXPECT_STREQ("opus", gcodec.plname);
884 EXPECT_EQ(1, gcodec.channels);
885 EXPECT_EQ(32000, gcodec.rate);
886
887 codecs[0].bitrate = 510001;
888 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
889 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
890 EXPECT_STREQ("opus", gcodec.plname);
891 EXPECT_EQ(1, gcodec.channels);
892 EXPECT_EQ(32000, gcodec.rate);
893}
894
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000895// Test that with bitrate=0 and stereo=1,
896// channels and bitrate are 2 and 64000.
897TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecOpusGood0Bitrate1Stereo) {
898 EXPECT_TRUE(SetupEngine());
899 int channel_num = voe_.GetLastChannel();
900 std::vector<cricket::AudioCodec> codecs;
901 codecs.push_back(kOpusCodec);
902 codecs[0].bitrate = 0;
903 codecs[0].params["stereo"] = "1";
904 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
905 webrtc::CodecInst gcodec;
906 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
907 EXPECT_STREQ("opus", gcodec.plname);
908 EXPECT_EQ(2, gcodec.channels);
909 EXPECT_EQ(64000, gcodec.rate);
910}
911
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000912// Test that with bitrate=invalid and stereo=1,
913// channels and bitrate are 2 and 64000.
914TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecOpusGoodXBitrate1Stereo) {
915 EXPECT_TRUE(SetupEngine());
916 int channel_num = voe_.GetLastChannel();
917 std::vector<cricket::AudioCodec> codecs;
918 codecs.push_back(kOpusCodec);
919 codecs[0].params["stereo"] = "1";
920 webrtc::CodecInst gcodec;
921
922 // bitrate that's out of the range between 6000 and 510000 will be considered
923 // as invalid and ignored.
924 codecs[0].bitrate = 5999;
925 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
926 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
927 EXPECT_STREQ("opus", gcodec.plname);
928 EXPECT_EQ(2, gcodec.channels);
929 EXPECT_EQ(64000, gcodec.rate);
930
931 codecs[0].bitrate = 510001;
932 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
933 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
934 EXPECT_STREQ("opus", gcodec.plname);
935 EXPECT_EQ(2, gcodec.channels);
936 EXPECT_EQ(64000, gcodec.rate);
937}
938
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000939// Test that with bitrate=N and stereo unset,
940// channels and bitrate are 1 and N.
941TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecOpusGoodNBitrateNoStereo) {
942 EXPECT_TRUE(SetupEngine());
943 int channel_num = voe_.GetLastChannel();
944 std::vector<cricket::AudioCodec> codecs;
945 codecs.push_back(kOpusCodec);
946 codecs[0].bitrate = 96000;
947 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
948 webrtc::CodecInst gcodec;
949 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
950 EXPECT_EQ(111, gcodec.pltype);
951 EXPECT_EQ(96000, gcodec.rate);
952 EXPECT_STREQ("opus", gcodec.plname);
953 EXPECT_EQ(1, gcodec.channels);
954 EXPECT_EQ(48000, gcodec.plfreq);
955}
956
957// Test that with bitrate=N and stereo=0,
958// channels and bitrate are 1 and N.
959TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecOpusGoodNBitrate0Stereo) {
960 EXPECT_TRUE(SetupEngine());
961 int channel_num = voe_.GetLastChannel();
962 std::vector<cricket::AudioCodec> codecs;
963 codecs.push_back(kOpusCodec);
964 codecs[0].bitrate = 30000;
965 codecs[0].params["stereo"] = "0";
966 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
967 webrtc::CodecInst gcodec;
968 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
969 EXPECT_EQ(1, gcodec.channels);
970 EXPECT_EQ(30000, gcodec.rate);
971 EXPECT_STREQ("opus", gcodec.plname);
972}
973
974// Test that with bitrate=N and without any parameters,
975// channels and bitrate are 1 and N.
976TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecOpusGoodNBitrateNoParameters) {
977 EXPECT_TRUE(SetupEngine());
978 int channel_num = voe_.GetLastChannel();
979 std::vector<cricket::AudioCodec> codecs;
980 codecs.push_back(kOpusCodec);
981 codecs[0].bitrate = 30000;
982 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
983 webrtc::CodecInst gcodec;
984 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
985 EXPECT_EQ(1, gcodec.channels);
986 EXPECT_EQ(30000, gcodec.rate);
987 EXPECT_STREQ("opus", gcodec.plname);
988}
989
990// Test that with bitrate=N and stereo=1,
991// channels and bitrate are 2 and N.
992TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecOpusGoodNBitrate1Stereo) {
993 EXPECT_TRUE(SetupEngine());
994 int channel_num = voe_.GetLastChannel();
995 std::vector<cricket::AudioCodec> codecs;
996 codecs.push_back(kOpusCodec);
997 codecs[0].bitrate = 30000;
998 codecs[0].params["stereo"] = "1";
999 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1000 webrtc::CodecInst gcodec;
1001 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1002 EXPECT_EQ(2, gcodec.channels);
1003 EXPECT_EQ(30000, gcodec.rate);
1004 EXPECT_STREQ("opus", gcodec.plname);
1005}
1006
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00001007// Test that bitrate will be overridden by the "maxaveragebitrate" parameter.
1008// Also test that the "maxaveragebitrate" can't be set to values outside the
1009// range of 6000 and 510000
1010TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecOpusMaxAverageBitrate) {
1011 EXPECT_TRUE(SetupEngine());
1012 int channel_num = voe_.GetLastChannel();
1013 std::vector<cricket::AudioCodec> codecs;
1014 codecs.push_back(kOpusCodec);
1015 codecs[0].bitrate = 30000;
1016 webrtc::CodecInst gcodec;
1017
1018 // Ignore if less than 6000.
1019 codecs[0].params["maxaveragebitrate"] = "5999";
1020 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1021 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1022 EXPECT_EQ(30000, gcodec.rate);
1023
1024 // Ignore if larger than 510000.
1025 codecs[0].params["maxaveragebitrate"] = "510001";
1026 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1027 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1028 EXPECT_EQ(30000, gcodec.rate);
1029
1030 codecs[0].params["maxaveragebitrate"] = "200000";
1031 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1032 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1033 EXPECT_EQ(200000, gcodec.rate);
1034}
1035
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00001036// Test that we can enable NACK with opus as caller.
1037TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecEnableNackAsCaller) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001038 EXPECT_TRUE(SetupEngine());
1039 int channel_num = voe_.GetLastChannel();
1040 std::vector<cricket::AudioCodec> codecs;
1041 codecs.push_back(kOpusCodec);
1042 codecs[0].AddFeedbackParam(cricket::FeedbackParam(cricket::kRtcpFbParamNack,
1043 cricket::kParamValueEmpty));
1044 EXPECT_FALSE(voe_.GetNACK(channel_num));
1045 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1046 EXPECT_TRUE(voe_.GetNACK(channel_num));
1047}
1048
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00001049// Test that we can enable NACK with opus as callee.
1050TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecEnableNackAsCallee) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001051 EXPECT_TRUE(engine_.Init(rtc::Thread::Current()));
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00001052 channel_ = engine_.CreateChannel();
1053 EXPECT_TRUE(channel_ != NULL);
1054
1055 int channel_num = voe_.GetLastChannel();
1056 std::vector<cricket::AudioCodec> codecs;
1057 codecs.push_back(kOpusCodec);
1058 codecs[0].AddFeedbackParam(cricket::FeedbackParam(cricket::kRtcpFbParamNack,
1059 cricket::kParamValueEmpty));
1060 EXPECT_FALSE(voe_.GetNACK(channel_num));
1061 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1062 EXPECT_FALSE(voe_.GetNACK(channel_num));
1063
1064 EXPECT_TRUE(channel_->AddSendStream(
1065 cricket::StreamParams::CreateLegacy(kSsrc1)));
1066 EXPECT_TRUE(voe_.GetNACK(channel_num));
1067}
1068
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001069// Test that we can enable NACK on receive streams.
1070TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecEnableNackRecvStreams) {
1071 EXPECT_TRUE(SetupEngine());
1072 EXPECT_TRUE(channel_->SetOptions(options_conference_));
1073 int channel_num1 = voe_.GetLastChannel();
1074 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(2)));
1075 int channel_num2 = voe_.GetLastChannel();
1076 std::vector<cricket::AudioCodec> codecs;
1077 codecs.push_back(kOpusCodec);
1078 codecs[0].AddFeedbackParam(cricket::FeedbackParam(cricket::kRtcpFbParamNack,
1079 cricket::kParamValueEmpty));
1080 EXPECT_FALSE(voe_.GetNACK(channel_num1));
1081 EXPECT_FALSE(voe_.GetNACK(channel_num2));
1082 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1083 EXPECT_TRUE(voe_.GetNACK(channel_num1));
1084 EXPECT_TRUE(voe_.GetNACK(channel_num2));
1085}
1086
1087// Test that we can disable NACK.
1088TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecDisableNack) {
1089 EXPECT_TRUE(SetupEngine());
1090 int channel_num = voe_.GetLastChannel();
1091 std::vector<cricket::AudioCodec> codecs;
1092 codecs.push_back(kOpusCodec);
1093 codecs[0].AddFeedbackParam(cricket::FeedbackParam(cricket::kRtcpFbParamNack,
1094 cricket::kParamValueEmpty));
1095 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1096 EXPECT_TRUE(voe_.GetNACK(channel_num));
1097
1098 codecs.clear();
1099 codecs.push_back(kOpusCodec);
1100 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1101 EXPECT_FALSE(voe_.GetNACK(channel_num));
1102}
1103
1104// Test that we can disable NACK on receive streams.
1105TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecDisableNackRecvStreams) {
1106 EXPECT_TRUE(SetupEngine());
1107 EXPECT_TRUE(channel_->SetOptions(options_conference_));
1108 int channel_num1 = voe_.GetLastChannel();
1109 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(2)));
1110 int channel_num2 = voe_.GetLastChannel();
1111 std::vector<cricket::AudioCodec> codecs;
1112 codecs.push_back(kOpusCodec);
1113 codecs[0].AddFeedbackParam(cricket::FeedbackParam(cricket::kRtcpFbParamNack,
1114 cricket::kParamValueEmpty));
1115 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1116 EXPECT_TRUE(voe_.GetNACK(channel_num1));
1117 EXPECT_TRUE(voe_.GetNACK(channel_num2));
1118
1119 codecs.clear();
1120 codecs.push_back(kOpusCodec);
1121 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1122 EXPECT_FALSE(voe_.GetNACK(channel_num1));
1123 EXPECT_FALSE(voe_.GetNACK(channel_num2));
1124}
1125
1126// Test that NACK is enabled on a new receive stream.
1127TEST_F(WebRtcVoiceEngineTestFake, AddRecvStreamEnableNack) {
1128 EXPECT_TRUE(SetupEngine());
1129 EXPECT_TRUE(channel_->SetOptions(options_conference_));
1130 int channel_num = voe_.GetLastChannel();
1131 std::vector<cricket::AudioCodec> codecs;
1132 codecs.push_back(kIsacCodec);
1133 codecs[0].AddFeedbackParam(cricket::FeedbackParam(cricket::kRtcpFbParamNack,
1134 cricket::kParamValueEmpty));
1135 codecs.push_back(kCn16000Codec);
1136 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1137 EXPECT_TRUE(voe_.GetNACK(channel_num));
1138
1139 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(2)));
1140 channel_num = voe_.GetLastChannel();
1141 EXPECT_TRUE(voe_.GetNACK(channel_num));
1142 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(3)));
1143 channel_num = voe_.GetLastChannel();
1144 EXPECT_TRUE(voe_.GetNACK(channel_num));
1145}
1146
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +00001147#ifdef USE_WEBRTC_DEV_BRANCH
1148// Test that without useinbandfec, Opus FEC is off.
buildbot@webrtc.orgd27d9ae2014-06-19 01:56:46 +00001149TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecNoOpusFec) {
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +00001150 EXPECT_TRUE(SetupEngine());
1151 int channel_num = voe_.GetLastChannel();
1152 std::vector<cricket::AudioCodec> codecs;
1153 codecs.push_back(kOpusCodec);
1154 codecs[0].bitrate = 0;
1155 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1156 EXPECT_FALSE(voe_.GetCodecFEC(channel_num));
1157}
1158
1159// Test that with useinbandfec=0, Opus FEC is off.
buildbot@webrtc.orgd27d9ae2014-06-19 01:56:46 +00001160TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecOpusDisableFec) {
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +00001161 EXPECT_TRUE(SetupEngine());
1162 int channel_num = voe_.GetLastChannel();
1163 std::vector<cricket::AudioCodec> codecs;
1164 codecs.push_back(kOpusCodec);
1165 codecs[0].bitrate = 0;
1166 codecs[0].params["useinbandfec"] = "0";
1167 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1168 EXPECT_FALSE(voe_.GetCodecFEC(channel_num));
1169 webrtc::CodecInst gcodec;
1170 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1171 EXPECT_STREQ("opus", gcodec.plname);
1172 EXPECT_EQ(1, gcodec.channels);
1173 EXPECT_EQ(32000, gcodec.rate);
1174}
1175
1176// Test that with useinbandfec=1, Opus FEC is on.
buildbot@webrtc.orgd27d9ae2014-06-19 01:56:46 +00001177TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecOpusEnableFec) {
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +00001178 EXPECT_TRUE(SetupEngine());
1179 int channel_num = voe_.GetLastChannel();
1180 std::vector<cricket::AudioCodec> codecs;
1181 codecs.push_back(kOpusCodec);
1182 codecs[0].bitrate = 0;
1183 codecs[0].params["useinbandfec"] = "1";
1184 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1185 EXPECT_TRUE(voe_.GetCodecFEC(channel_num));
1186 webrtc::CodecInst gcodec;
1187 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1188 EXPECT_STREQ("opus", gcodec.plname);
1189 EXPECT_EQ(1, gcodec.channels);
1190 EXPECT_EQ(32000, gcodec.rate);
1191}
1192
1193// Test that with useinbandfec=1, stereo=1, Opus FEC is on.
buildbot@webrtc.orgd27d9ae2014-06-19 01:56:46 +00001194TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecOpusEnableFecStereo) {
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +00001195 EXPECT_TRUE(SetupEngine());
1196 int channel_num = voe_.GetLastChannel();
1197 std::vector<cricket::AudioCodec> codecs;
1198 codecs.push_back(kOpusCodec);
1199 codecs[0].bitrate = 0;
1200 codecs[0].params["stereo"] = "1";
1201 codecs[0].params["useinbandfec"] = "1";
1202 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1203 EXPECT_TRUE(voe_.GetCodecFEC(channel_num));
1204 webrtc::CodecInst gcodec;
1205 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1206 EXPECT_STREQ("opus", gcodec.plname);
1207 EXPECT_EQ(2, gcodec.channels);
1208 EXPECT_EQ(64000, gcodec.rate);
1209}
1210
1211// Test that with non-Opus, codec FEC is off.
buildbot@webrtc.orgd27d9ae2014-06-19 01:56:46 +00001212TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecIsacNoFec) {
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +00001213 EXPECT_TRUE(SetupEngine());
1214 int channel_num = voe_.GetLastChannel();
1215 std::vector<cricket::AudioCodec> codecs;
1216 codecs.push_back(kIsacCodec);
1217 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1218 EXPECT_FALSE(voe_.GetCodecFEC(channel_num));
1219}
buildbot@webrtc.org3ffa1f92014-07-02 19:51:26 +00001220
1221// Test the with non-Opus, even if useinbandfec=1, FEC is off.
1222TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecIsacWithParamNoFec) {
1223 EXPECT_TRUE(SetupEngine());
1224 int channel_num = voe_.GetLastChannel();
1225 std::vector<cricket::AudioCodec> codecs;
1226 codecs.push_back(kIsacCodec);
1227 codecs[0].params["useinbandfec"] = "1";
1228 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1229 EXPECT_FALSE(voe_.GetCodecFEC(channel_num));
1230}
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +00001231#endif // USE_WEBRTC_DEV_BRANCH
1232
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001233// Test that we can apply CELT with stereo mode but fail with mono mode.
1234TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecsCelt) {
1235 EXPECT_TRUE(SetupEngine());
1236 int channel_num = voe_.GetLastChannel();
1237 std::vector<cricket::AudioCodec> codecs;
1238 codecs.push_back(kCeltCodec);
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00001239 codecs.push_back(kIsacCodec);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001240 codecs[0].id = 96;
1241 codecs[0].channels = 2;
1242 codecs[0].bitrate = 96000;
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00001243 codecs[1].bitrate = 64000;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001244 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1245 webrtc::CodecInst gcodec;
1246 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1247 EXPECT_EQ(96, gcodec.pltype);
1248 EXPECT_EQ(96000, gcodec.rate);
1249 EXPECT_EQ(2, gcodec.channels);
1250 EXPECT_STREQ("CELT", gcodec.plname);
1251 // Doesn't support mono, expect it to fall back to the next codec in the list.
1252 codecs[0].channels = 1;
1253 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1254 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00001255 EXPECT_EQ(103, gcodec.pltype);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001256 EXPECT_EQ(1, gcodec.channels);
1257 EXPECT_EQ(64000, gcodec.rate);
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00001258 EXPECT_STREQ("ISAC", gcodec.plname);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001259}
1260
1261// Test that we can switch back and forth between CELT and ISAC with CN.
1262TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecsIsacCeltSwitching) {
1263 EXPECT_TRUE(SetupEngine());
1264 int channel_num = voe_.GetLastChannel();
1265 std::vector<cricket::AudioCodec> celt_codecs;
1266 celt_codecs.push_back(kCeltCodec);
1267 EXPECT_TRUE(channel_->SetSendCodecs(celt_codecs));
1268 webrtc::CodecInst gcodec;
1269 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1270 EXPECT_EQ(110, gcodec.pltype);
1271 EXPECT_STREQ("CELT", gcodec.plname);
1272
1273 std::vector<cricket::AudioCodec> isac_codecs;
1274 isac_codecs.push_back(kIsacCodec);
1275 isac_codecs.push_back(kCn16000Codec);
1276 isac_codecs.push_back(kCeltCodec);
1277 EXPECT_TRUE(channel_->SetSendCodecs(isac_codecs));
1278 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1279 EXPECT_EQ(103, gcodec.pltype);
1280 EXPECT_STREQ("ISAC", gcodec.plname);
1281
1282 EXPECT_TRUE(channel_->SetSendCodecs(celt_codecs));
1283 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1284 EXPECT_EQ(110, gcodec.pltype);
1285 EXPECT_STREQ("CELT", gcodec.plname);
1286}
1287
1288// Test that we handle various ways of specifying bitrate.
1289TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecsBitrate) {
1290 EXPECT_TRUE(SetupEngine());
1291 int channel_num = voe_.GetLastChannel();
1292 std::vector<cricket::AudioCodec> codecs;
1293 codecs.push_back(kIsacCodec); // bitrate == 32000
1294 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1295 webrtc::CodecInst gcodec;
1296 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1297 EXPECT_EQ(103, gcodec.pltype);
1298 EXPECT_STREQ("ISAC", gcodec.plname);
1299 EXPECT_EQ(32000, gcodec.rate);
1300
1301 codecs[0].bitrate = 0; // bitrate == default
1302 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1303 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1304 EXPECT_EQ(103, gcodec.pltype);
1305 EXPECT_STREQ("ISAC", gcodec.plname);
1306 EXPECT_EQ(-1, gcodec.rate);
1307
1308 codecs[0].bitrate = 28000; // bitrate == 28000
1309 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1310 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1311 EXPECT_EQ(103, gcodec.pltype);
1312 EXPECT_STREQ("ISAC", gcodec.plname);
1313 EXPECT_EQ(28000, gcodec.rate);
1314
1315 codecs[0] = kPcmuCodec; // bitrate == 64000
1316 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1317 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1318 EXPECT_EQ(0, gcodec.pltype);
1319 EXPECT_STREQ("PCMU", gcodec.plname);
1320 EXPECT_EQ(64000, gcodec.rate);
1321
1322 codecs[0].bitrate = 0; // bitrate == default
1323 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1324 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1325 EXPECT_EQ(0, gcodec.pltype);
1326 EXPECT_STREQ("PCMU", gcodec.plname);
1327 EXPECT_EQ(64000, gcodec.rate);
1328
1329 codecs[0] = kOpusCodec;
1330 codecs[0].bitrate = 0; // bitrate == default
1331 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1332 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1333 EXPECT_EQ(111, gcodec.pltype);
1334 EXPECT_STREQ("opus", gcodec.plname);
1335 EXPECT_EQ(32000, gcodec.rate);
1336}
1337
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00001338// Test that we fail if no codecs are specified.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001339TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecsNoCodecs) {
1340 EXPECT_TRUE(SetupEngine());
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00001341 std::vector<cricket::AudioCodec> codecs;
1342 EXPECT_FALSE(channel_->SetSendCodecs(codecs));
1343}
1344
1345// Test that we can set send codecs even with telephone-event codec as the first
1346// one on the list.
1347TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecsDTMFOnTop) {
1348 EXPECT_TRUE(SetupEngine());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001349 int channel_num = voe_.GetLastChannel();
1350 std::vector<cricket::AudioCodec> codecs;
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00001351 codecs.push_back(kTelephoneEventCodec);
1352 codecs.push_back(kIsacCodec);
1353 codecs.push_back(kPcmuCodec);
1354 codecs[0].id = 98; // DTMF
1355 codecs[1].id = 96;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001356 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1357 webrtc::CodecInst gcodec;
1358 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00001359 EXPECT_EQ(96, gcodec.pltype);
1360 EXPECT_STREQ("ISAC", gcodec.plname);
1361 EXPECT_EQ(98, voe_.GetSendTelephoneEventPayloadType(channel_num));
1362}
1363
1364// Test that we can set send codecs even with CN codec as the first
1365// one on the list.
1366TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecsCNOnTop) {
1367 EXPECT_TRUE(SetupEngine());
1368 int channel_num = voe_.GetLastChannel();
1369 std::vector<cricket::AudioCodec> codecs;
1370 codecs.push_back(kCn16000Codec);
1371 codecs.push_back(kIsacCodec);
1372 codecs.push_back(kPcmuCodec);
1373 codecs[0].id = 98; // wideband CN
1374 codecs[1].id = 96;
1375 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1376 webrtc::CodecInst gcodec;
1377 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1378 EXPECT_EQ(96, gcodec.pltype);
1379 EXPECT_STREQ("ISAC", gcodec.plname);
1380 EXPECT_EQ(98, voe_.GetSendCNPayloadType(channel_num, true));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001381}
1382
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00001383// Test that we set VAD and DTMF types correctly as caller.
1384TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecsCNandDTMFAsCaller) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001385 EXPECT_TRUE(SetupEngine());
1386 int channel_num = voe_.GetLastChannel();
1387 std::vector<cricket::AudioCodec> codecs;
1388 codecs.push_back(kIsacCodec);
1389 codecs.push_back(kPcmuCodec);
1390 // TODO(juberti): cn 32000
1391 codecs.push_back(kCn16000Codec);
1392 codecs.push_back(kCn8000Codec);
1393 codecs.push_back(kTelephoneEventCodec);
1394 codecs.push_back(kRedCodec);
1395 codecs[0].id = 96;
1396 codecs[2].id = 97; // wideband CN
1397 codecs[4].id = 98; // DTMF
1398 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1399 webrtc::CodecInst gcodec;
1400 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1401 EXPECT_EQ(96, gcodec.pltype);
1402 EXPECT_STREQ("ISAC", gcodec.plname);
1403 EXPECT_TRUE(voe_.GetVAD(channel_num));
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +00001404 EXPECT_FALSE(voe_.GetRED(channel_num));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001405 EXPECT_EQ(13, voe_.GetSendCNPayloadType(channel_num, false));
1406 EXPECT_EQ(97, voe_.GetSendCNPayloadType(channel_num, true));
1407 EXPECT_EQ(98, voe_.GetSendTelephoneEventPayloadType(channel_num));
1408}
1409
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00001410// Test that we set VAD and DTMF types correctly as callee.
1411TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecsCNandDTMFAsCallee) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001412 EXPECT_TRUE(engine_.Init(rtc::Thread::Current()));
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00001413 channel_ = engine_.CreateChannel();
1414 EXPECT_TRUE(channel_ != NULL);
1415
1416 int channel_num = voe_.GetLastChannel();
1417 std::vector<cricket::AudioCodec> codecs;
1418 codecs.push_back(kIsacCodec);
1419 codecs.push_back(kPcmuCodec);
1420 // TODO(juberti): cn 32000
1421 codecs.push_back(kCn16000Codec);
1422 codecs.push_back(kCn8000Codec);
1423 codecs.push_back(kTelephoneEventCodec);
1424 codecs.push_back(kRedCodec);
1425 codecs[0].id = 96;
1426 codecs[2].id = 97; // wideband CN
1427 codecs[4].id = 98; // DTMF
1428 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1429 EXPECT_TRUE(channel_->AddSendStream(
1430 cricket::StreamParams::CreateLegacy(kSsrc1)));
1431
1432 webrtc::CodecInst gcodec;
1433 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1434 EXPECT_EQ(96, gcodec.pltype);
1435 EXPECT_STREQ("ISAC", gcodec.plname);
1436 EXPECT_TRUE(voe_.GetVAD(channel_num));
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +00001437 EXPECT_FALSE(voe_.GetRED(channel_num));
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00001438 EXPECT_EQ(13, voe_.GetSendCNPayloadType(channel_num, false));
1439 EXPECT_EQ(97, voe_.GetSendCNPayloadType(channel_num, true));
1440 EXPECT_EQ(98, voe_.GetSendTelephoneEventPayloadType(channel_num));
1441}
1442
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001443// Test that we only apply VAD if we have a CN codec that matches the
1444// send codec clockrate.
1445TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecsCNNoMatch) {
1446 EXPECT_TRUE(SetupEngine());
1447 int channel_num = voe_.GetLastChannel();
1448 std::vector<cricket::AudioCodec> codecs;
1449 // Set ISAC(16K) and CN(16K). VAD should be activated.
1450 codecs.push_back(kIsacCodec);
1451 codecs.push_back(kCn16000Codec);
1452 codecs[1].id = 97;
1453 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1454 webrtc::CodecInst gcodec;
1455 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1456 EXPECT_STREQ("ISAC", gcodec.plname);
1457 EXPECT_TRUE(voe_.GetVAD(channel_num));
1458 EXPECT_EQ(97, voe_.GetSendCNPayloadType(channel_num, true));
1459 // Set PCMU(8K) and CN(16K). VAD should not be activated.
1460 codecs[0] = kPcmuCodec;
1461 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1462 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1463 EXPECT_STREQ("PCMU", gcodec.plname);
1464 EXPECT_FALSE(voe_.GetVAD(channel_num));
1465 // Set PCMU(8K) and CN(8K). VAD should be activated.
1466 codecs[1] = kCn8000Codec;
1467 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1468 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1469 EXPECT_STREQ("PCMU", gcodec.plname);
1470 EXPECT_TRUE(voe_.GetVAD(channel_num));
1471 EXPECT_EQ(13, voe_.GetSendCNPayloadType(channel_num, false));
1472 // Set ISAC(16K) and CN(8K). VAD should not be activated.
1473 codecs[0] = kIsacCodec;
1474 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1475 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1476 EXPECT_STREQ("ISAC", gcodec.plname);
1477 EXPECT_FALSE(voe_.GetVAD(channel_num));
1478}
1479
1480// Test that we perform case-insensitive matching of codec names.
1481TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecsCaseInsensitive) {
1482 EXPECT_TRUE(SetupEngine());
1483 int channel_num = voe_.GetLastChannel();
1484 std::vector<cricket::AudioCodec> codecs;
1485 codecs.push_back(kIsacCodec);
1486 codecs.push_back(kPcmuCodec);
1487 codecs.push_back(kCn16000Codec);
1488 codecs.push_back(kCn8000Codec);
1489 codecs.push_back(kTelephoneEventCodec);
1490 codecs.push_back(kRedCodec);
1491 codecs[0].name = "iSaC";
1492 codecs[0].id = 96;
1493 codecs[2].id = 97; // wideband CN
1494 codecs[4].id = 98; // DTMF
1495 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1496 webrtc::CodecInst gcodec;
1497 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1498 EXPECT_EQ(96, gcodec.pltype);
1499 EXPECT_STREQ("ISAC", gcodec.plname);
1500 EXPECT_TRUE(voe_.GetVAD(channel_num));
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +00001501 EXPECT_FALSE(voe_.GetRED(channel_num));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001502 EXPECT_EQ(13, voe_.GetSendCNPayloadType(channel_num, false));
1503 EXPECT_EQ(97, voe_.GetSendCNPayloadType(channel_num, true));
1504 EXPECT_EQ(98, voe_.GetSendTelephoneEventPayloadType(channel_num));
1505}
1506
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +00001507// Test that we set up RED correctly as caller.
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00001508TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecsREDAsCaller) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001509 EXPECT_TRUE(SetupEngine());
1510 int channel_num = voe_.GetLastChannel();
1511 std::vector<cricket::AudioCodec> codecs;
1512 codecs.push_back(kRedCodec);
1513 codecs.push_back(kIsacCodec);
1514 codecs.push_back(kPcmuCodec);
1515 codecs[0].id = 127;
1516 codecs[0].params[""] = "96/96";
1517 codecs[1].id = 96;
1518 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1519 webrtc::CodecInst gcodec;
1520 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1521 EXPECT_EQ(96, gcodec.pltype);
1522 EXPECT_STREQ("ISAC", gcodec.plname);
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +00001523 EXPECT_TRUE(voe_.GetRED(channel_num));
1524 EXPECT_EQ(127, voe_.GetSendREDPayloadType(channel_num));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001525}
1526
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +00001527// Test that we set up RED correctly as callee.
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00001528TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecsREDAsCallee) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001529 EXPECT_TRUE(engine_.Init(rtc::Thread::Current()));
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00001530 channel_ = engine_.CreateChannel();
1531 EXPECT_TRUE(channel_ != NULL);
1532
1533 int channel_num = voe_.GetLastChannel();
1534 std::vector<cricket::AudioCodec> codecs;
1535 codecs.push_back(kRedCodec);
1536 codecs.push_back(kIsacCodec);
1537 codecs.push_back(kPcmuCodec);
1538 codecs[0].id = 127;
1539 codecs[0].params[""] = "96/96";
1540 codecs[1].id = 96;
1541 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1542 EXPECT_TRUE(channel_->AddSendStream(
1543 cricket::StreamParams::CreateLegacy(kSsrc1)));
1544 webrtc::CodecInst gcodec;
1545 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1546 EXPECT_EQ(96, gcodec.pltype);
1547 EXPECT_STREQ("ISAC", gcodec.plname);
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +00001548 EXPECT_TRUE(voe_.GetRED(channel_num));
1549 EXPECT_EQ(127, voe_.GetSendREDPayloadType(channel_num));
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00001550}
1551
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +00001552// Test that we set up RED correctly if params are omitted.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001553TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecsREDNoParams) {
1554 EXPECT_TRUE(SetupEngine());
1555 int channel_num = voe_.GetLastChannel();
1556 std::vector<cricket::AudioCodec> codecs;
1557 codecs.push_back(kRedCodec);
1558 codecs.push_back(kIsacCodec);
1559 codecs.push_back(kPcmuCodec);
1560 codecs[0].id = 127;
1561 codecs[1].id = 96;
1562 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1563 webrtc::CodecInst gcodec;
1564 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1565 EXPECT_EQ(96, gcodec.pltype);
1566 EXPECT_STREQ("ISAC", gcodec.plname);
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +00001567 EXPECT_TRUE(voe_.GetRED(channel_num));
1568 EXPECT_EQ(127, voe_.GetSendREDPayloadType(channel_num));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001569}
1570
1571// Test that we ignore RED if the parameters aren't named the way we expect.
1572TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecsBadRED1) {
1573 EXPECT_TRUE(SetupEngine());
1574 int channel_num = voe_.GetLastChannel();
1575 std::vector<cricket::AudioCodec> codecs;
1576 codecs.push_back(kRedCodec);
1577 codecs.push_back(kIsacCodec);
1578 codecs.push_back(kPcmuCodec);
1579 codecs[0].id = 127;
1580 codecs[0].params["ABC"] = "96/96";
1581 codecs[1].id = 96;
1582 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1583 webrtc::CodecInst gcodec;
1584 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1585 EXPECT_EQ(96, gcodec.pltype);
1586 EXPECT_STREQ("ISAC", gcodec.plname);
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +00001587 EXPECT_FALSE(voe_.GetRED(channel_num));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001588}
1589
1590// Test that we ignore RED if it uses different primary/secondary encoding.
1591TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecsBadRED2) {
1592 EXPECT_TRUE(SetupEngine());
1593 int channel_num = voe_.GetLastChannel();
1594 std::vector<cricket::AudioCodec> codecs;
1595 codecs.push_back(kRedCodec);
1596 codecs.push_back(kIsacCodec);
1597 codecs.push_back(kPcmuCodec);
1598 codecs[0].id = 127;
1599 codecs[0].params[""] = "96/0";
1600 codecs[1].id = 96;
1601 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1602 webrtc::CodecInst gcodec;
1603 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1604 EXPECT_EQ(96, gcodec.pltype);
1605 EXPECT_STREQ("ISAC", gcodec.plname);
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +00001606 EXPECT_FALSE(voe_.GetRED(channel_num));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001607}
1608
1609// Test that we ignore RED if it uses more than 2 encodings.
1610TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecsBadRED3) {
1611 EXPECT_TRUE(SetupEngine());
1612 int channel_num = voe_.GetLastChannel();
1613 std::vector<cricket::AudioCodec> codecs;
1614 codecs.push_back(kRedCodec);
1615 codecs.push_back(kIsacCodec);
1616 codecs.push_back(kPcmuCodec);
1617 codecs[0].id = 127;
1618 codecs[0].params[""] = "96/96/96";
1619 codecs[1].id = 96;
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);
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +00001625 EXPECT_FALSE(voe_.GetRED(channel_num));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001626}
1627
1628// Test that we ignore RED if it has bogus codec ids.
1629TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecsBadRED4) {
1630 EXPECT_TRUE(SetupEngine());
1631 int channel_num = voe_.GetLastChannel();
1632 std::vector<cricket::AudioCodec> codecs;
1633 codecs.push_back(kRedCodec);
1634 codecs.push_back(kIsacCodec);
1635 codecs.push_back(kPcmuCodec);
1636 codecs[0].id = 127;
1637 codecs[0].params[""] = "ABC/ABC";
1638 codecs[1].id = 96;
1639 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1640 webrtc::CodecInst gcodec;
1641 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1642 EXPECT_EQ(96, gcodec.pltype);
1643 EXPECT_STREQ("ISAC", gcodec.plname);
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +00001644 EXPECT_FALSE(voe_.GetRED(channel_num));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001645}
1646
1647// Test that we ignore RED if it refers to a codec that is not present.
1648TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecsBadRED5) {
1649 EXPECT_TRUE(SetupEngine());
1650 int channel_num = voe_.GetLastChannel();
1651 std::vector<cricket::AudioCodec> codecs;
1652 codecs.push_back(kRedCodec);
1653 codecs.push_back(kIsacCodec);
1654 codecs.push_back(kPcmuCodec);
1655 codecs[0].id = 127;
1656 codecs[0].params[""] = "97/97";
1657 codecs[1].id = 96;
1658 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1659 webrtc::CodecInst gcodec;
1660 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1661 EXPECT_EQ(96, gcodec.pltype);
1662 EXPECT_STREQ("ISAC", gcodec.plname);
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +00001663 EXPECT_FALSE(voe_.GetRED(channel_num));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001664}
1665
buildbot@webrtc.org150835e2014-05-06 15:54:38 +00001666// Test support for audio level header extension.
1667TEST_F(WebRtcVoiceEngineTestFake, SendAudioLevelHeaderExtensions) {
1668 TestSetSendRtpHeaderExtensions(kRtpAudioLevelHeaderExtension);
henrike@webrtc.org79047f92014-03-06 23:46:59 +00001669}
buildbot@webrtc.org150835e2014-05-06 15:54:38 +00001670TEST_F(WebRtcVoiceEngineTestFake, RecvAudioLevelHeaderExtensions) {
1671 TestSetRecvRtpHeaderExtensions(kRtpAudioLevelHeaderExtension);
1672}
henrike@webrtc.org79047f92014-03-06 23:46:59 +00001673
buildbot@webrtc.org150835e2014-05-06 15:54:38 +00001674// Test support for absolute send time header extension.
1675TEST_F(WebRtcVoiceEngineTestFake, SendAbsoluteSendTimeHeaderExtensions) {
1676 TestSetSendRtpHeaderExtensions(kRtpAbsoluteSenderTimeHeaderExtension);
1677}
1678TEST_F(WebRtcVoiceEngineTestFake, RecvAbsoluteSendTimeHeaderExtensions) {
1679 TestSetRecvRtpHeaderExtensions(kRtpAbsoluteSenderTimeHeaderExtension);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001680}
1681
1682// Test that we can create a channel and start sending/playing out on it.
1683TEST_F(WebRtcVoiceEngineTestFake, SendAndPlayout) {
1684 EXPECT_TRUE(SetupEngine());
1685 int channel_num = voe_.GetLastChannel();
1686 std::vector<cricket::AudioCodec> codecs;
1687 codecs.push_back(kPcmuCodec);
1688 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1689 EXPECT_TRUE(channel_->SetSend(cricket::SEND_MICROPHONE));
1690 EXPECT_TRUE(voe_.GetSend(channel_num));
1691 EXPECT_TRUE(channel_->SetPlayout(true));
1692 EXPECT_TRUE(voe_.GetPlayout(channel_num));
1693 EXPECT_TRUE(channel_->SetSend(cricket::SEND_NOTHING));
1694 EXPECT_FALSE(voe_.GetSend(channel_num));
1695 EXPECT_TRUE(channel_->SetPlayout(false));
1696 EXPECT_FALSE(voe_.GetPlayout(channel_num));
1697}
1698
wu@webrtc.org9dba5252013-08-05 20:36:57 +00001699// Test that we can add and remove send streams.
1700TEST_F(WebRtcVoiceEngineTestFake, CreateAndDeleteMultipleSendStreams) {
1701 SetupForMultiSendStream();
1702
1703 static const uint32 kSsrcs4[] = {1, 2, 3, 4};
1704
1705 // Set the global state for sending.
1706 EXPECT_TRUE(channel_->SetSend(cricket::SEND_MICROPHONE));
1707
1708 for (unsigned int i = 0; i < ARRAY_SIZE(kSsrcs4); ++i) {
1709 EXPECT_TRUE(channel_->AddSendStream(
1710 cricket::StreamParams::CreateLegacy(kSsrcs4[i])));
1711
1712 // Verify that we are in a sending state for all the created streams.
1713 int channel_num = voe_.GetChannelFromLocalSsrc(kSsrcs4[i]);
1714 EXPECT_TRUE(voe_.GetSend(channel_num));
1715 }
1716
1717 // Remove the first send channel, which is the default channel. It will only
1718 // recycle the default channel but not delete it.
1719 EXPECT_TRUE(channel_->RemoveSendStream(kSsrcs4[0]));
1720 // Stream should already be Removed from the send stream list.
1721 EXPECT_FALSE(channel_->RemoveSendStream(kSsrcs4[0]));
1722 // But the default still exists.
1723 EXPECT_EQ(0, voe_.GetChannelFromLocalSsrc(kSsrcs4[0]));
1724
1725 // Delete the rest of send channel streams.
1726 for (unsigned int i = 1; i < ARRAY_SIZE(kSsrcs4); ++i) {
1727 EXPECT_TRUE(channel_->RemoveSendStream(kSsrcs4[i]));
1728 // Stream should already be deleted.
1729 EXPECT_FALSE(channel_->RemoveSendStream(kSsrcs4[i]));
1730 EXPECT_EQ(-1, voe_.GetChannelFromLocalSsrc(kSsrcs4[i]));
1731 }
1732}
1733
1734// Test SetSendCodecs correctly configure the codecs in all send streams.
1735TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecsWithMultipleSendStreams) {
1736 SetupForMultiSendStream();
1737
1738 static const uint32 kSsrcs4[] = {1, 2, 3, 4};
1739 // Create send streams.
1740 for (unsigned int i = 0; i < ARRAY_SIZE(kSsrcs4); ++i) {
1741 EXPECT_TRUE(channel_->AddSendStream(
1742 cricket::StreamParams::CreateLegacy(kSsrcs4[i])));
1743 }
1744
1745 std::vector<cricket::AudioCodec> codecs;
1746 // Set ISAC(16K) and CN(16K). VAD should be activated.
1747 codecs.push_back(kIsacCodec);
1748 codecs.push_back(kCn16000Codec);
1749 codecs[1].id = 97;
1750 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1751
1752 // Verify ISAC and VAD are corrected configured on all send channels.
1753 webrtc::CodecInst gcodec;
1754 for (unsigned int i = 0; i < ARRAY_SIZE(kSsrcs4); ++i) {
1755 int channel_num = voe_.GetChannelFromLocalSsrc(kSsrcs4[i]);
1756 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1757 EXPECT_STREQ("ISAC", gcodec.plname);
1758 EXPECT_TRUE(voe_.GetVAD(channel_num));
1759 EXPECT_EQ(97, voe_.GetSendCNPayloadType(channel_num, true));
1760 }
1761
1762 // Change to PCMU(8K) and CN(16K). VAD should not be activated.
1763 codecs[0] = kPcmuCodec;
1764 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1765 for (unsigned int i = 0; i < ARRAY_SIZE(kSsrcs4); ++i) {
1766 int channel_num = voe_.GetChannelFromLocalSsrc(kSsrcs4[i]);
1767 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1768 EXPECT_STREQ("PCMU", gcodec.plname);
1769 EXPECT_FALSE(voe_.GetVAD(channel_num));
1770 }
1771}
1772
1773// Test we can SetSend on all send streams correctly.
1774TEST_F(WebRtcVoiceEngineTestFake, SetSendWithMultipleSendStreams) {
1775 SetupForMultiSendStream();
1776
1777 static const uint32 kSsrcs4[] = {1, 2, 3, 4};
1778 // Create the send channels and they should be a SEND_NOTHING date.
1779 for (unsigned int i = 0; i < ARRAY_SIZE(kSsrcs4); ++i) {
1780 EXPECT_TRUE(channel_->AddSendStream(
1781 cricket::StreamParams::CreateLegacy(kSsrcs4[i])));
1782 int channel_num = voe_.GetLastChannel();
1783 EXPECT_FALSE(voe_.GetSend(channel_num));
1784 }
1785
1786 // Set the global state for starting sending.
1787 EXPECT_TRUE(channel_->SetSend(cricket::SEND_MICROPHONE));
1788 for (unsigned int i = 0; i < ARRAY_SIZE(kSsrcs4); ++i) {
1789 // Verify that we are in a sending state for all the send streams.
1790 int channel_num = voe_.GetChannelFromLocalSsrc(kSsrcs4[i]);
1791 EXPECT_TRUE(voe_.GetSend(channel_num));
1792 }
1793
1794 // Set the global state for stopping sending.
1795 EXPECT_TRUE(channel_->SetSend(cricket::SEND_NOTHING));
1796 for (unsigned int i = 1; i < ARRAY_SIZE(kSsrcs4); ++i) {
1797 // Verify that we are in a stop state for all the send streams.
1798 int channel_num = voe_.GetChannelFromLocalSsrc(kSsrcs4[i]);
1799 EXPECT_FALSE(voe_.GetSend(channel_num));
1800 }
1801}
1802
1803// Test we can set the correct statistics on all send streams.
1804TEST_F(WebRtcVoiceEngineTestFake, GetStatsWithMultipleSendStreams) {
1805 SetupForMultiSendStream();
1806
1807 static const uint32 kSsrcs4[] = {1, 2, 3, 4};
1808 // Create send streams.
1809 for (unsigned int i = 0; i < ARRAY_SIZE(kSsrcs4); ++i) {
1810 EXPECT_TRUE(channel_->AddSendStream(
1811 cricket::StreamParams::CreateLegacy(kSsrcs4[i])));
1812 }
buildbot@webrtc.org7e71b772014-06-13 01:14:01 +00001813 // Create a receive stream to check that none of the send streams end up in
1814 // the receive stream stats.
1815 EXPECT_TRUE(channel_->AddRecvStream(
1816 cricket::StreamParams::CreateLegacy(kSsrc2)));
wu@webrtc.org9dba5252013-08-05 20:36:57 +00001817 // We need send codec to be set to get all stats.
1818 std::vector<cricket::AudioCodec> codecs;
1819 codecs.push_back(kPcmuCodec);
1820 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
buildbot@webrtc.org7e71b772014-06-13 01:14:01 +00001821 EXPECT_TRUE(channel_->SetRecvCodecs(codecs));
wu@webrtc.org9dba5252013-08-05 20:36:57 +00001822
1823 cricket::VoiceMediaInfo info;
1824 EXPECT_EQ(true, channel_->GetStats(&info));
1825 EXPECT_EQ(static_cast<size_t>(ARRAY_SIZE(kSsrcs4)), info.senders.size());
1826
1827 // Verify the statistic information is correct.
1828 for (unsigned int i = 0; i < ARRAY_SIZE(kSsrcs4); ++i) {
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +00001829 EXPECT_EQ(kSsrcs4[i], info.senders[i].ssrc());
wu@webrtc.org9dba5252013-08-05 20:36:57 +00001830 EXPECT_EQ(kPcmuCodec.name, info.senders[i].codec_name);
1831 EXPECT_EQ(cricket::kIntStatValue, info.senders[i].bytes_sent);
1832 EXPECT_EQ(cricket::kIntStatValue, info.senders[i].packets_sent);
1833 EXPECT_EQ(cricket::kIntStatValue, info.senders[i].packets_lost);
1834 EXPECT_EQ(cricket::kFractionLostStatValue, info.senders[i].fraction_lost);
1835 EXPECT_EQ(cricket::kIntStatValue, info.senders[i].ext_seqnum);
1836 EXPECT_EQ(cricket::kIntStatValue, info.senders[i].rtt_ms);
1837 EXPECT_EQ(cricket::kIntStatValue, info.senders[i].jitter_ms);
buildbot@webrtc.org7e71b772014-06-13 01:14:01 +00001838 EXPECT_EQ(kPcmuCodec.name, info.senders[i].codec_name);
wu@webrtc.org9dba5252013-08-05 20:36:57 +00001839 }
1840
buildbot@webrtc.org7e71b772014-06-13 01:14:01 +00001841 EXPECT_EQ(0u, info.receivers.size());
1842 DeliverPacket(kPcmuFrame, sizeof(kPcmuFrame));
1843 EXPECT_EQ(true, channel_->GetStats(&info));
1844
wu@webrtc.org9dba5252013-08-05 20:36:57 +00001845 EXPECT_EQ(1u, info.receivers.size());
buildbot@webrtc.org7e71b772014-06-13 01:14:01 +00001846 EXPECT_EQ(cricket::kIntStatValue, info.receivers[0].bytes_rcvd);
1847 EXPECT_EQ(cricket::kIntStatValue, info.receivers[0].packets_rcvd);
1848 EXPECT_EQ(cricket::kIntStatValue, info.receivers[0].packets_lost);
1849 EXPECT_EQ(cricket::kIntStatValue, info.receivers[0].ext_seqnum);
1850 EXPECT_EQ(kPcmuCodec.name, info.receivers[0].codec_name);
wu@webrtc.org9dba5252013-08-05 20:36:57 +00001851}
1852
wu@webrtc.org9dba5252013-08-05 20:36:57 +00001853// Test that we can add and remove receive streams, and do proper send/playout.
1854// We can receive on multiple streams while sending one stream.
1855TEST_F(WebRtcVoiceEngineTestFake, PlayoutWithMultipleStreams) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001856 EXPECT_TRUE(SetupEngine());
1857 int channel_num1 = voe_.GetLastChannel();
1858
1859 // Start playout on the default channel.
1860 EXPECT_TRUE(channel_->SetOptions(options_conference_));
1861 EXPECT_TRUE(channel_->SetPlayout(true));
1862 EXPECT_TRUE(voe_.GetPlayout(channel_num1));
1863
1864 // Adding another stream should disable playout on the default channel.
1865 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(2)));
1866 int channel_num2 = voe_.GetLastChannel();
1867 std::vector<cricket::AudioCodec> codecs;
1868 codecs.push_back(kPcmuCodec);
1869 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1870 EXPECT_TRUE(channel_->SetSend(cricket::SEND_MICROPHONE));
1871 EXPECT_TRUE(voe_.GetSend(channel_num1));
1872 EXPECT_FALSE(voe_.GetSend(channel_num2));
1873
1874 // Make sure only the new channel is played out.
1875 EXPECT_FALSE(voe_.GetPlayout(channel_num1));
1876 EXPECT_TRUE(voe_.GetPlayout(channel_num2));
1877
1878 // Adding yet another stream should have stream 2 and 3 enabled for playout.
1879 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(3)));
1880 int channel_num3 = voe_.GetLastChannel();
1881 EXPECT_FALSE(voe_.GetPlayout(channel_num1));
1882 EXPECT_TRUE(voe_.GetPlayout(channel_num2));
1883 EXPECT_TRUE(voe_.GetPlayout(channel_num3));
1884 EXPECT_FALSE(voe_.GetSend(channel_num3));
1885
1886 // Stop sending.
1887 EXPECT_TRUE(channel_->SetSend(cricket::SEND_NOTHING));
1888 EXPECT_FALSE(voe_.GetSend(channel_num1));
1889 EXPECT_FALSE(voe_.GetSend(channel_num2));
1890 EXPECT_FALSE(voe_.GetSend(channel_num3));
1891
1892 // Stop playout.
1893 EXPECT_TRUE(channel_->SetPlayout(false));
1894 EXPECT_FALSE(voe_.GetPlayout(channel_num1));
1895 EXPECT_FALSE(voe_.GetPlayout(channel_num2));
1896 EXPECT_FALSE(voe_.GetPlayout(channel_num3));
1897
1898 // Restart playout and make sure the default channel still is not played out.
1899 EXPECT_TRUE(channel_->SetPlayout(true));
1900 EXPECT_FALSE(voe_.GetPlayout(channel_num1));
1901 EXPECT_TRUE(voe_.GetPlayout(channel_num2));
1902 EXPECT_TRUE(voe_.GetPlayout(channel_num3));
1903
1904 // Now remove the new streams and verify that the default channel is
1905 // played out again.
1906 EXPECT_TRUE(channel_->RemoveRecvStream(3));
1907 EXPECT_TRUE(channel_->RemoveRecvStream(2));
1908
1909 EXPECT_TRUE(voe_.GetPlayout(channel_num1));
1910}
1911
1912// Test that we can set the devices to use.
1913TEST_F(WebRtcVoiceEngineTestFake, SetDevices) {
1914 EXPECT_TRUE(SetupEngine());
1915 int channel_num = voe_.GetLastChannel();
1916 std::vector<cricket::AudioCodec> codecs;
1917 codecs.push_back(kPcmuCodec);
1918 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1919
1920 cricket::Device default_dev(cricket::kFakeDefaultDeviceName,
1921 cricket::kFakeDefaultDeviceId);
1922 cricket::Device dev(cricket::kFakeDeviceName,
1923 cricket::kFakeDeviceId);
1924
1925 // Test SetDevices() while not sending or playing.
1926 EXPECT_TRUE(engine_.SetDevices(&default_dev, &default_dev));
1927
1928 // Test SetDevices() while sending and playing.
1929 EXPECT_TRUE(engine_.SetLocalMonitor(true));
1930 EXPECT_TRUE(channel_->SetSend(cricket::SEND_MICROPHONE));
1931 EXPECT_TRUE(channel_->SetPlayout(true));
1932 EXPECT_TRUE(voe_.GetRecordingMicrophone());
1933 EXPECT_TRUE(voe_.GetSend(channel_num));
1934 EXPECT_TRUE(voe_.GetPlayout(channel_num));
1935
1936 EXPECT_TRUE(engine_.SetDevices(&dev, &dev));
1937
1938 EXPECT_TRUE(voe_.GetRecordingMicrophone());
1939 EXPECT_TRUE(voe_.GetSend(channel_num));
1940 EXPECT_TRUE(voe_.GetPlayout(channel_num));
1941
1942 // Test that failure to open newly selected devices does not prevent opening
1943 // ones after that.
1944 voe_.set_fail_start_recording_microphone(true);
1945 voe_.set_playout_fail_channel(channel_num);
1946 voe_.set_send_fail_channel(channel_num);
1947
1948 EXPECT_FALSE(engine_.SetDevices(&default_dev, &default_dev));
1949
1950 EXPECT_FALSE(voe_.GetRecordingMicrophone());
1951 EXPECT_FALSE(voe_.GetSend(channel_num));
1952 EXPECT_FALSE(voe_.GetPlayout(channel_num));
1953
1954 voe_.set_fail_start_recording_microphone(false);
1955 voe_.set_playout_fail_channel(-1);
1956 voe_.set_send_fail_channel(-1);
1957
1958 EXPECT_TRUE(engine_.SetDevices(&dev, &dev));
1959
1960 EXPECT_TRUE(voe_.GetRecordingMicrophone());
1961 EXPECT_TRUE(voe_.GetSend(channel_num));
1962 EXPECT_TRUE(voe_.GetPlayout(channel_num));
1963}
1964
1965// Test that we can set the devices to use even if we failed to
1966// open the initial ones.
1967TEST_F(WebRtcVoiceEngineTestFake, SetDevicesWithInitiallyBadDevices) {
1968 EXPECT_TRUE(SetupEngine());
1969 int channel_num = voe_.GetLastChannel();
1970 std::vector<cricket::AudioCodec> codecs;
1971 codecs.push_back(kPcmuCodec);
1972 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1973
1974 cricket::Device default_dev(cricket::kFakeDefaultDeviceName,
1975 cricket::kFakeDefaultDeviceId);
1976 cricket::Device dev(cricket::kFakeDeviceName,
1977 cricket::kFakeDeviceId);
1978
1979 // Test that failure to open devices selected before starting
1980 // send/play does not prevent opening newly selected ones after that.
1981 voe_.set_fail_start_recording_microphone(true);
1982 voe_.set_playout_fail_channel(channel_num);
1983 voe_.set_send_fail_channel(channel_num);
1984
1985 EXPECT_TRUE(engine_.SetDevices(&default_dev, &default_dev));
1986
1987 EXPECT_FALSE(engine_.SetLocalMonitor(true));
1988 EXPECT_FALSE(channel_->SetSend(cricket::SEND_MICROPHONE));
1989 EXPECT_FALSE(channel_->SetPlayout(true));
1990 EXPECT_FALSE(voe_.GetRecordingMicrophone());
1991 EXPECT_FALSE(voe_.GetSend(channel_num));
1992 EXPECT_FALSE(voe_.GetPlayout(channel_num));
1993
1994 voe_.set_fail_start_recording_microphone(false);
1995 voe_.set_playout_fail_channel(-1);
1996 voe_.set_send_fail_channel(-1);
1997
1998 EXPECT_TRUE(engine_.SetDevices(&dev, &dev));
1999
2000 EXPECT_TRUE(voe_.GetRecordingMicrophone());
2001 EXPECT_TRUE(voe_.GetSend(channel_num));
2002 EXPECT_TRUE(voe_.GetPlayout(channel_num));
2003}
2004
2005// Test that we can create a channel configured for multi-point conferences,
2006// and start sending/playing out on it.
2007TEST_F(WebRtcVoiceEngineTestFake, ConferenceSendAndPlayout) {
2008 EXPECT_TRUE(SetupEngine());
2009 int channel_num = voe_.GetLastChannel();
2010 EXPECT_TRUE(channel_->SetOptions(options_conference_));
2011 std::vector<cricket::AudioCodec> codecs;
2012 codecs.push_back(kPcmuCodec);
2013 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
2014 EXPECT_TRUE(channel_->SetSend(cricket::SEND_MICROPHONE));
2015 EXPECT_TRUE(voe_.GetSend(channel_num));
2016}
2017
2018// Test that we can create a channel configured for Codian bridges,
2019// and start sending/playing out on it.
2020TEST_F(WebRtcVoiceEngineTestFake, CodianSendAndPlayout) {
2021 EXPECT_TRUE(SetupEngine());
2022 int channel_num = voe_.GetLastChannel();
2023 webrtc::AgcConfig agc_config;
2024 EXPECT_EQ(0, voe_.GetAgcConfig(agc_config));
2025 EXPECT_EQ(0, agc_config.targetLeveldBOv);
2026 EXPECT_TRUE(channel_->SetOptions(options_adjust_agc_));
2027 std::vector<cricket::AudioCodec> codecs;
2028 codecs.push_back(kPcmuCodec);
2029 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
2030 EXPECT_TRUE(channel_->SetSend(cricket::SEND_MICROPHONE));
2031 EXPECT_TRUE(voe_.GetSend(channel_num));
2032 EXPECT_EQ(0, voe_.GetAgcConfig(agc_config));
2033 EXPECT_EQ(agc_config.targetLeveldBOv, 10); // level was attenuated
2034 EXPECT_TRUE(channel_->SetPlayout(true));
2035 EXPECT_TRUE(voe_.GetPlayout(channel_num));
2036 EXPECT_TRUE(channel_->SetSend(cricket::SEND_NOTHING));
2037 EXPECT_FALSE(voe_.GetSend(channel_num));
2038 EXPECT_EQ(0, voe_.GetAgcConfig(agc_config));
2039 EXPECT_EQ(0, agc_config.targetLeveldBOv); // level was restored
2040 EXPECT_TRUE(channel_->SetPlayout(false));
2041 EXPECT_FALSE(voe_.GetPlayout(channel_num));
2042}
2043
wu@webrtc.org97077a32013-10-25 21:18:33 +00002044TEST_F(WebRtcVoiceEngineTestFake, TxAgcConfigViaOptions) {
2045 EXPECT_TRUE(SetupEngine());
2046 webrtc::AgcConfig agc_config;
2047 EXPECT_EQ(0, voe_.GetAgcConfig(agc_config));
2048 EXPECT_EQ(0, agc_config.targetLeveldBOv);
2049
2050 cricket::AudioOptions options;
2051 options.tx_agc_target_dbov.Set(3);
2052 options.tx_agc_digital_compression_gain.Set(9);
2053 options.tx_agc_limiter.Set(true);
2054 options.auto_gain_control.Set(true);
2055 EXPECT_TRUE(engine_.SetOptions(options));
2056
2057 EXPECT_EQ(0, voe_.GetAgcConfig(agc_config));
2058 EXPECT_EQ(3, agc_config.targetLeveldBOv);
2059 EXPECT_EQ(9, agc_config.digitalCompressionGaindB);
2060 EXPECT_TRUE(agc_config.limiterEnable);
2061
2062 // Check interaction with adjust_agc_delta. Both should be respected, for
2063 // backwards compatibility.
2064 options.adjust_agc_delta.Set(-10);
2065 EXPECT_TRUE(engine_.SetOptions(options));
2066
2067 EXPECT_EQ(0, voe_.GetAgcConfig(agc_config));
2068 EXPECT_EQ(13, agc_config.targetLeveldBOv);
2069}
2070
2071TEST_F(WebRtcVoiceEngineTestFake, RxAgcConfigViaOptions) {
2072 EXPECT_TRUE(SetupEngine());
2073 int channel_num = voe_.GetLastChannel();
2074 cricket::AudioOptions options;
2075 options.rx_agc_target_dbov.Set(6);
2076 options.rx_agc_digital_compression_gain.Set(0);
2077 options.rx_agc_limiter.Set(true);
2078 options.rx_auto_gain_control.Set(true);
2079 EXPECT_TRUE(channel_->SetOptions(options));
2080
2081 webrtc::AgcConfig agc_config;
2082 EXPECT_EQ(0, engine_.voe()->processing()->GetRxAgcConfig(
2083 channel_num, agc_config));
2084 EXPECT_EQ(6, agc_config.targetLeveldBOv);
2085 EXPECT_EQ(0, agc_config.digitalCompressionGaindB);
2086 EXPECT_TRUE(agc_config.limiterEnable);
2087}
2088
2089TEST_F(WebRtcVoiceEngineTestFake, SampleRatesViaOptions) {
2090 EXPECT_TRUE(SetupEngine());
2091 cricket::AudioOptions options;
2092 options.recording_sample_rate.Set(48000u);
2093 options.playout_sample_rate.Set(44100u);
2094 EXPECT_TRUE(engine_.SetOptions(options));
2095
2096 unsigned int recording_sample_rate, playout_sample_rate;
2097 EXPECT_EQ(0, voe_.RecordingSampleRate(&recording_sample_rate));
2098 EXPECT_EQ(0, voe_.PlayoutSampleRate(&playout_sample_rate));
2099 EXPECT_EQ(48000u, recording_sample_rate);
2100 EXPECT_EQ(44100u, playout_sample_rate);
2101}
2102
2103TEST_F(WebRtcVoiceEngineTestFake, TraceFilterViaTraceOptions) {
2104 EXPECT_TRUE(SetupEngine());
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002105 engine_.SetLogging(rtc::LS_INFO, "");
wu@webrtc.org97077a32013-10-25 21:18:33 +00002106 EXPECT_EQ(
2107 // Info:
2108 webrtc::kTraceStateInfo | webrtc::kTraceInfo |
2109 // Warning:
2110 webrtc::kTraceTerseInfo | webrtc::kTraceWarning |
2111 // Error:
2112 webrtc::kTraceError | webrtc::kTraceCritical,
2113 static_cast<int>(trace_wrapper_->filter_));
2114 // Now set it explicitly
2115 std::string filter =
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002116 "tracefilter " + rtc::ToString(webrtc::kTraceDefault);
2117 engine_.SetLogging(rtc::LS_VERBOSE, filter.c_str());
wu@webrtc.org97077a32013-10-25 21:18:33 +00002118 EXPECT_EQ(static_cast<unsigned int>(webrtc::kTraceDefault),
2119 trace_wrapper_->filter_);
2120}
2121
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002122// Test that we can set the outgoing SSRC properly.
2123// SSRC is set in SetupEngine by calling AddSendStream.
2124TEST_F(WebRtcVoiceEngineTestFake, SetSendSsrc) {
2125 EXPECT_TRUE(SetupEngine());
2126 int channel_num = voe_.GetLastChannel();
2127 unsigned int send_ssrc;
2128 EXPECT_EQ(0, voe_.GetLocalSSRC(channel_num, send_ssrc));
2129 EXPECT_NE(0U, send_ssrc);
2130 EXPECT_EQ(0, voe_.GetLocalSSRC(channel_num, send_ssrc));
2131 EXPECT_EQ(kSsrc1, send_ssrc);
2132}
2133
2134TEST_F(WebRtcVoiceEngineTestFake, GetStats) {
2135 // Setup. We need send codec to be set to get all stats.
2136 EXPECT_TRUE(SetupEngine());
buildbot@webrtc.org7e71b772014-06-13 01:14:01 +00002137 // SetupEngine adds a send stream with kSsrc1, so the receive stream has to
2138 // use a different SSRC.
2139 EXPECT_TRUE(channel_->AddRecvStream(
2140 cricket::StreamParams::CreateLegacy(kSsrc2)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002141 std::vector<cricket::AudioCodec> codecs;
2142 codecs.push_back(kPcmuCodec);
2143 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
buildbot@webrtc.org7e71b772014-06-13 01:14:01 +00002144 EXPECT_TRUE(channel_->SetRecvCodecs(codecs));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002145
2146 cricket::VoiceMediaInfo info;
2147 EXPECT_EQ(true, channel_->GetStats(&info));
2148 EXPECT_EQ(1u, info.senders.size());
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +00002149 EXPECT_EQ(kSsrc1, info.senders[0].ssrc());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002150 EXPECT_EQ(kPcmuCodec.name, info.senders[0].codec_name);
2151 EXPECT_EQ(cricket::kIntStatValue, info.senders[0].bytes_sent);
2152 EXPECT_EQ(cricket::kIntStatValue, info.senders[0].packets_sent);
2153 EXPECT_EQ(cricket::kIntStatValue, info.senders[0].packets_lost);
2154 EXPECT_EQ(cricket::kFractionLostStatValue, info.senders[0].fraction_lost);
2155 EXPECT_EQ(cricket::kIntStatValue, info.senders[0].ext_seqnum);
2156 EXPECT_EQ(cricket::kIntStatValue, info.senders[0].rtt_ms);
2157 EXPECT_EQ(cricket::kIntStatValue, info.senders[0].jitter_ms);
buildbot@webrtc.org7e71b772014-06-13 01:14:01 +00002158 EXPECT_EQ(kPcmuCodec.name, info.senders[0].codec_name);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002159 // TODO(sriniv): Add testing for more fields. These are not populated
2160 // in FakeWebrtcVoiceEngine yet.
2161 // EXPECT_EQ(cricket::kIntStatValue, info.senders[0].audio_level);
2162 // EXPECT_EQ(cricket::kIntStatValue, info.senders[0].echo_delay_median_ms);
2163 // EXPECT_EQ(cricket::kIntStatValue, info.senders[0].echo_delay_std_ms);
2164 // EXPECT_EQ(cricket::kIntStatValue, info.senders[0].echo_return_loss);
2165 // EXPECT_EQ(cricket::kIntStatValue,
2166 // info.senders[0].echo_return_loss_enhancement);
2167
buildbot@webrtc.org7e71b772014-06-13 01:14:01 +00002168 EXPECT_EQ(0u, info.receivers.size());
2169 DeliverPacket(kPcmuFrame, sizeof(kPcmuFrame));
2170 EXPECT_EQ(true, channel_->GetStats(&info));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002171 EXPECT_EQ(1u, info.receivers.size());
buildbot@webrtc.org7e71b772014-06-13 01:14:01 +00002172
2173 EXPECT_EQ(cricket::kIntStatValue, info.receivers[0].bytes_rcvd);
2174 EXPECT_EQ(cricket::kIntStatValue, info.receivers[0].packets_rcvd);
2175 EXPECT_EQ(cricket::kIntStatValue, info.receivers[0].packets_lost);
2176 EXPECT_EQ(cricket::kIntStatValue, info.receivers[0].ext_seqnum);
2177 EXPECT_EQ(kPcmuCodec.name, info.receivers[0].codec_name);
2178 // TODO(sriniv): Add testing for more receiver fields.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002179}
2180
2181// Test that we can set the outgoing SSRC properly with multiple streams.
2182// SSRC is set in SetupEngine by calling AddSendStream.
2183TEST_F(WebRtcVoiceEngineTestFake, SetSendSsrcWithMultipleStreams) {
2184 EXPECT_TRUE(SetupEngine());
2185 EXPECT_TRUE(channel_->SetOptions(options_conference_));
2186 int channel_num1 = voe_.GetLastChannel();
2187 unsigned int send_ssrc;
2188 EXPECT_EQ(0, voe_.GetLocalSSRC(channel_num1, send_ssrc));
2189 EXPECT_EQ(kSsrc1, send_ssrc);
2190
2191 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(2)));
2192 int channel_num2 = voe_.GetLastChannel();
2193 EXPECT_EQ(0, voe_.GetLocalSSRC(channel_num2, send_ssrc));
2194 EXPECT_EQ(kSsrc1, send_ssrc);
2195}
2196
2197// Test that the local SSRC is the same on sending and receiving channels if the
2198// receive channel is created before the send channel.
2199TEST_F(WebRtcVoiceEngineTestFake, SetSendSsrcAfterCreatingReceiveChannel) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002200 EXPECT_TRUE(engine_.Init(rtc::Thread::Current()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002201 channel_ = engine_.CreateChannel();
2202 EXPECT_TRUE(channel_->SetOptions(options_conference_));
2203
2204 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(1)));
2205 int receive_channel_num = voe_.GetLastChannel();
2206 EXPECT_TRUE(channel_->AddSendStream(
2207 cricket::StreamParams::CreateLegacy(1234)));
2208 int send_channel_num = voe_.GetLastChannel();
2209
2210 unsigned int ssrc = 0;
2211 EXPECT_EQ(0, voe_.GetLocalSSRC(send_channel_num, ssrc));
2212 EXPECT_EQ(1234U, ssrc);
2213 ssrc = 0;
2214 EXPECT_EQ(0, voe_.GetLocalSSRC(receive_channel_num, ssrc));
2215 EXPECT_EQ(1234U, ssrc);
2216}
2217
2218// Test that we can properly receive packets.
2219TEST_F(WebRtcVoiceEngineTestFake, Recv) {
2220 EXPECT_TRUE(SetupEngine());
2221 int channel_num = voe_.GetLastChannel();
2222 DeliverPacket(kPcmuFrame, sizeof(kPcmuFrame));
2223 EXPECT_TRUE(voe_.CheckPacket(channel_num, kPcmuFrame,
2224 sizeof(kPcmuFrame)));
2225}
2226
2227// Test that we can properly receive packets on multiple streams.
2228TEST_F(WebRtcVoiceEngineTestFake, RecvWithMultipleStreams) {
2229 EXPECT_TRUE(SetupEngine());
2230 EXPECT_TRUE(channel_->SetOptions(options_conference_));
2231 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(1)));
2232 int channel_num1 = voe_.GetLastChannel();
2233 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(2)));
2234 int channel_num2 = voe_.GetLastChannel();
2235 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(3)));
2236 int channel_num3 = voe_.GetLastChannel();
2237 // Create packets with the right SSRCs.
2238 char packets[4][sizeof(kPcmuFrame)];
2239 for (size_t i = 0; i < ARRAY_SIZE(packets); ++i) {
2240 memcpy(packets[i], kPcmuFrame, sizeof(kPcmuFrame));
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002241 rtc::SetBE32(packets[i] + 8, static_cast<uint32>(i));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002242 }
2243 EXPECT_TRUE(voe_.CheckNoPacket(channel_num1));
2244 EXPECT_TRUE(voe_.CheckNoPacket(channel_num2));
2245 EXPECT_TRUE(voe_.CheckNoPacket(channel_num3));
2246 DeliverPacket(packets[0], sizeof(packets[0]));
2247 EXPECT_TRUE(voe_.CheckNoPacket(channel_num1));
2248 EXPECT_TRUE(voe_.CheckNoPacket(channel_num2));
2249 EXPECT_TRUE(voe_.CheckNoPacket(channel_num3));
2250 DeliverPacket(packets[1], sizeof(packets[1]));
2251 EXPECT_TRUE(voe_.CheckPacket(channel_num1, packets[1],
2252 sizeof(packets[1])));
2253 EXPECT_TRUE(voe_.CheckNoPacket(channel_num2));
2254 EXPECT_TRUE(voe_.CheckNoPacket(channel_num3));
2255 DeliverPacket(packets[2], sizeof(packets[2]));
2256 EXPECT_TRUE(voe_.CheckNoPacket(channel_num1));
2257 EXPECT_TRUE(voe_.CheckPacket(channel_num2, packets[2],
2258 sizeof(packets[2])));
2259 EXPECT_TRUE(voe_.CheckNoPacket(channel_num3));
2260 DeliverPacket(packets[3], sizeof(packets[3]));
2261 EXPECT_TRUE(voe_.CheckNoPacket(channel_num1));
2262 EXPECT_TRUE(voe_.CheckNoPacket(channel_num2));
2263 EXPECT_TRUE(voe_.CheckPacket(channel_num3, packets[3],
2264 sizeof(packets[3])));
2265 EXPECT_TRUE(channel_->RemoveRecvStream(3));
2266 EXPECT_TRUE(channel_->RemoveRecvStream(2));
2267 EXPECT_TRUE(channel_->RemoveRecvStream(1));
2268}
2269
2270// Test that we properly handle failures to add a stream.
2271TEST_F(WebRtcVoiceEngineTestFake, AddStreamFail) {
2272 EXPECT_TRUE(SetupEngine());
2273 voe_.set_fail_create_channel(true);
2274 EXPECT_TRUE(channel_->SetOptions(options_conference_));
2275 EXPECT_FALSE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(2)));
2276
2277 // In 1:1 call, we should not try to create a new channel.
2278 cricket::AudioOptions options_no_conference_;
2279 options_no_conference_.conference_mode.Set(false);
2280 EXPECT_TRUE(channel_->SetOptions(options_no_conference_));
2281 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(2)));
2282}
2283
2284// Test that AddRecvStream doesn't create new channel for 1:1 call.
2285TEST_F(WebRtcVoiceEngineTestFake, AddRecvStream1On1) {
2286 EXPECT_TRUE(SetupEngine());
2287 int channel_num = voe_.GetLastChannel();
2288 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(1)));
2289 EXPECT_EQ(channel_num, voe_.GetLastChannel());
2290}
2291
2292// Test that after adding a recv stream, we do not decode more codecs than
2293// those previously passed into SetRecvCodecs.
2294TEST_F(WebRtcVoiceEngineTestFake, AddRecvStreamUnsupportedCodec) {
2295 EXPECT_TRUE(SetupEngine());
2296 EXPECT_TRUE(channel_->SetOptions(options_conference_));
2297 std::vector<cricket::AudioCodec> codecs;
2298 codecs.push_back(kIsacCodec);
2299 codecs.push_back(kPcmuCodec);
2300 EXPECT_TRUE(channel_->SetRecvCodecs(codecs));
2301 EXPECT_TRUE(channel_->AddRecvStream(
2302 cricket::StreamParams::CreateLegacy(kSsrc1)));
2303 int channel_num2 = voe_.GetLastChannel();
2304 webrtc::CodecInst gcodec;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002305 rtc::strcpyn(gcodec.plname, ARRAY_SIZE(gcodec.plname), "CELT");
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002306 gcodec.plfreq = 32000;
2307 gcodec.channels = 2;
2308 EXPECT_EQ(-1, voe_.GetRecPayloadType(channel_num2, gcodec));
2309}
2310
2311// Test that we properly clean up any streams that were added, even if
2312// not explicitly removed.
2313TEST_F(WebRtcVoiceEngineTestFake, StreamCleanup) {
2314 EXPECT_TRUE(SetupEngine());
2315 EXPECT_TRUE(channel_->SetOptions(options_conference_));
2316 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(1)));
2317 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(2)));
2318 EXPECT_EQ(3, voe_.GetNumChannels()); // default channel + 2 added
2319 delete channel_;
2320 channel_ = NULL;
2321 EXPECT_EQ(0, voe_.GetNumChannels());
2322}
2323
wu@webrtc.org78187522013-10-07 23:32:02 +00002324TEST_F(WebRtcVoiceEngineTestFake, TestAddRecvStreamFailWithZeroSsrc) {
2325 EXPECT_TRUE(SetupEngine());
2326 EXPECT_FALSE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(0)));
2327}
2328
2329TEST_F(WebRtcVoiceEngineTestFake, TestNoLeakingWhenAddRecvStreamFail) {
2330 EXPECT_TRUE(SetupEngine());
2331 // Stream 1 reuses default channel.
2332 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(1)));
2333 // Manually delete default channel to simulate a failure.
2334 int default_channel = voe_.GetLastChannel();
2335 EXPECT_EQ(0, voe_.DeleteChannel(default_channel));
2336 // Add recv stream 2 should fail because default channel is gone.
2337 EXPECT_FALSE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(2)));
2338 int new_channel = voe_.GetLastChannel();
2339 EXPECT_NE(default_channel, new_channel);
2340 // The last created channel should have already been deleted.
2341 EXPECT_EQ(-1, voe_.DeleteChannel(new_channel));
2342}
2343
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002344// Test the InsertDtmf on default send stream as caller.
2345TEST_F(WebRtcVoiceEngineTestFake, InsertDtmfOnDefaultSendStreamAsCaller) {
2346 TestInsertDtmf(0, true);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002347}
2348
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002349// Test the InsertDtmf on default send stream as callee
2350TEST_F(WebRtcVoiceEngineTestFake, InsertDtmfOnDefaultSendStreamAsCallee) {
2351 TestInsertDtmf(0, false);
2352}
2353
2354// Test the InsertDtmf on specified send stream as caller.
2355TEST_F(WebRtcVoiceEngineTestFake, InsertDtmfOnSendStreamAsCaller) {
2356 TestInsertDtmf(kSsrc1, true);
2357}
2358
2359// Test the InsertDtmf on specified send stream as callee.
2360TEST_F(WebRtcVoiceEngineTestFake, InsertDtmfOnSendStreamAsCallee) {
2361 TestInsertDtmf(kSsrc1, false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002362}
2363
2364// Test that we can play a ringback tone properly in a single-stream call.
2365TEST_F(WebRtcVoiceEngineTestFake, PlayRingback) {
2366 EXPECT_TRUE(SetupEngine());
2367 int channel_num = voe_.GetLastChannel();
2368 EXPECT_EQ(0, voe_.IsPlayingFileLocally(channel_num));
2369 // Check we fail if no ringback tone specified.
2370 EXPECT_FALSE(channel_->PlayRingbackTone(0, true, true));
2371 EXPECT_EQ(0, voe_.IsPlayingFileLocally(channel_num));
2372 // Check we can set and play a ringback tone.
wu@webrtc.org9caf2762013-12-11 18:25:07 +00002373 EXPECT_TRUE(channel_->SetRingbackTone(
2374 kRingbackTone, static_cast<int>(strlen(kRingbackTone))));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002375 EXPECT_TRUE(channel_->PlayRingbackTone(0, true, true));
2376 EXPECT_EQ(1, voe_.IsPlayingFileLocally(channel_num));
2377 // Check we can stop the tone manually.
2378 EXPECT_TRUE(channel_->PlayRingbackTone(0, false, false));
2379 EXPECT_EQ(0, voe_.IsPlayingFileLocally(channel_num));
2380 // Check we stop the tone if a packet arrives.
2381 EXPECT_TRUE(channel_->PlayRingbackTone(0, true, true));
2382 EXPECT_EQ(1, voe_.IsPlayingFileLocally(channel_num));
2383 DeliverPacket(kPcmuFrame, sizeof(kPcmuFrame));
2384 EXPECT_EQ(0, voe_.IsPlayingFileLocally(channel_num));
2385}
2386
2387// Test that we can play a ringback tone properly in a multi-stream call.
2388TEST_F(WebRtcVoiceEngineTestFake, PlayRingbackWithMultipleStreams) {
2389 EXPECT_TRUE(SetupEngine());
2390 EXPECT_TRUE(channel_->SetOptions(options_conference_));
2391 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(1)));
2392 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(2)));
2393 int channel_num = voe_.GetLastChannel();
2394 EXPECT_EQ(0, voe_.IsPlayingFileLocally(channel_num));
2395 // Check we fail if no ringback tone specified.
2396 EXPECT_FALSE(channel_->PlayRingbackTone(2, true, true));
2397 EXPECT_EQ(0, voe_.IsPlayingFileLocally(channel_num));
2398 // Check we can set and play a ringback tone on the correct ssrc.
wu@webrtc.org9caf2762013-12-11 18:25:07 +00002399 EXPECT_TRUE(channel_->SetRingbackTone(
2400 kRingbackTone, static_cast<int>(strlen(kRingbackTone))));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002401 EXPECT_FALSE(channel_->PlayRingbackTone(77, true, true));
2402 EXPECT_TRUE(channel_->PlayRingbackTone(2, true, true));
2403 EXPECT_EQ(1, voe_.IsPlayingFileLocally(channel_num));
2404 // Check we can stop the tone manually.
2405 EXPECT_TRUE(channel_->PlayRingbackTone(2, false, false));
2406 EXPECT_EQ(0, voe_.IsPlayingFileLocally(channel_num));
2407 // Check we stop the tone if a packet arrives, but only with the right SSRC.
2408 EXPECT_TRUE(channel_->PlayRingbackTone(2, true, true));
2409 EXPECT_EQ(1, voe_.IsPlayingFileLocally(channel_num));
2410 // Send a packet with SSRC 1; the tone should not stop.
2411 DeliverPacket(kPcmuFrame, sizeof(kPcmuFrame));
2412 EXPECT_EQ(1, voe_.IsPlayingFileLocally(channel_num));
2413 // Send a packet with SSRC 2; the tone should stop.
2414 char packet[sizeof(kPcmuFrame)];
2415 memcpy(packet, kPcmuFrame, sizeof(kPcmuFrame));
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002416 rtc::SetBE32(packet + 8, 2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002417 DeliverPacket(packet, sizeof(packet));
2418 EXPECT_EQ(0, voe_.IsPlayingFileLocally(channel_num));
2419}
2420
2421// Tests creating soundclips, and make sure they come from the right engine.
2422TEST_F(WebRtcVoiceEngineTestFake, CreateSoundclip) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002423 EXPECT_TRUE(engine_.Init(rtc::Thread::Current()));
wu@webrtc.org4551b792013-10-09 15:37:36 +00002424 EXPECT_FALSE(voe_sc_.IsInited());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002425 soundclip_ = engine_.CreateSoundclip();
wu@webrtc.org4551b792013-10-09 15:37:36 +00002426 EXPECT_TRUE(voe_sc_.IsInited());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002427 ASSERT_TRUE(soundclip_ != NULL);
2428 EXPECT_EQ(0, voe_.GetNumChannels());
2429 EXPECT_EQ(1, voe_sc_.GetNumChannels());
2430 int channel_num = voe_sc_.GetLastChannel();
2431 EXPECT_TRUE(voe_sc_.GetPlayout(channel_num));
2432 delete soundclip_;
2433 soundclip_ = NULL;
2434 EXPECT_EQ(0, voe_sc_.GetNumChannels());
wu@webrtc.org4551b792013-10-09 15:37:36 +00002435 // Make sure the soundclip engine is uninitialized on shutdown, now that
2436 // we've initialized it by creating a soundclip.
2437 engine_.Terminate();
2438 EXPECT_FALSE(voe_sc_.IsInited());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002439}
2440
2441// Tests playing out a fake sound.
2442TEST_F(WebRtcVoiceEngineTestFake, PlaySoundclip) {
2443 static const char kZeroes[16000] = {};
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002444 EXPECT_TRUE(engine_.Init(rtc::Thread::Current()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002445 soundclip_ = engine_.CreateSoundclip();
2446 ASSERT_TRUE(soundclip_ != NULL);
2447 EXPECT_TRUE(soundclip_->PlaySound(kZeroes, sizeof(kZeroes), 0));
2448}
2449
2450TEST_F(WebRtcVoiceEngineTestFake, MediaEngineCallbackOnError) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002451 rtc::scoped_ptr<ChannelErrorListener> listener;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002452 cricket::WebRtcVoiceMediaChannel* media_channel;
2453 unsigned int ssrc = 0;
2454
2455 EXPECT_TRUE(SetupEngine());
2456 EXPECT_TRUE(channel_->SetOptions(options_conference_));
2457 EXPECT_TRUE(channel_->SetSend(cricket::SEND_MICROPHONE));
2458
2459 media_channel = static_cast<cricket::WebRtcVoiceMediaChannel*>(channel_);
2460 listener.reset(new ChannelErrorListener(channel_));
2461
2462 // Test on WebRtc VoE channel.
2463 voe_.TriggerCallbackOnError(media_channel->voe_channel(),
2464 VE_SATURATION_WARNING);
2465 EXPECT_EQ(cricket::VoiceMediaChannel::ERROR_REC_DEVICE_SATURATION,
2466 listener->error());
2467 EXPECT_NE(-1, voe_.GetLocalSSRC(voe_.GetLastChannel(), ssrc));
2468 EXPECT_EQ(ssrc, listener->ssrc());
2469
2470 listener->Reset();
2471 voe_.TriggerCallbackOnError(-1, VE_TYPING_NOISE_WARNING);
2472 EXPECT_EQ(cricket::VoiceMediaChannel::ERROR_REC_TYPING_NOISE_DETECTED,
2473 listener->error());
2474 EXPECT_EQ(0U, listener->ssrc());
2475
2476 // Add another stream and test on that.
2477 ++ssrc;
2478 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(
2479 ssrc)));
2480 listener->Reset();
2481 voe_.TriggerCallbackOnError(voe_.GetLastChannel(),
2482 VE_SATURATION_WARNING);
2483 EXPECT_EQ(cricket::VoiceMediaChannel::ERROR_REC_DEVICE_SATURATION,
2484 listener->error());
2485 EXPECT_EQ(ssrc, listener->ssrc());
2486
2487 // Testing a non-existing channel.
2488 listener->Reset();
2489 voe_.TriggerCallbackOnError(voe_.GetLastChannel() + 2,
2490 VE_SATURATION_WARNING);
2491 EXPECT_EQ(0, listener->error());
2492}
2493
2494TEST_F(WebRtcVoiceEngineTestFake, TestSetPlayoutError) {
2495 EXPECT_TRUE(SetupEngine());
2496 EXPECT_TRUE(channel_->SetOptions(options_conference_));
2497 std::vector<cricket::AudioCodec> codecs;
2498 codecs.push_back(kPcmuCodec);
2499 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
2500 EXPECT_TRUE(channel_->SetSend(cricket::SEND_MICROPHONE));
2501 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(2)));
2502 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(3)));
2503 EXPECT_TRUE(channel_->SetPlayout(true));
2504 voe_.set_playout_fail_channel(voe_.GetLastChannel() - 1);
2505 EXPECT_TRUE(channel_->SetPlayout(false));
2506 EXPECT_FALSE(channel_->SetPlayout(true));
2507}
2508
2509// Test that the Registering/Unregistering with the
2510// webrtcvoiceengine works as expected
2511TEST_F(WebRtcVoiceEngineTestFake, RegisterVoiceProcessor) {
2512 EXPECT_TRUE(SetupEngine());
2513 EXPECT_TRUE(channel_->SetOptions(options_conference_));
2514 EXPECT_TRUE(channel_->AddRecvStream(
2515 cricket::StreamParams::CreateLegacy(kSsrc2)));
2516 cricket::FakeMediaProcessor vp_1;
2517 cricket::FakeMediaProcessor vp_2;
2518
2519 EXPECT_FALSE(engine_.RegisterProcessor(kSsrc2, &vp_1, cricket::MPD_TX));
2520 EXPECT_TRUE(engine_.RegisterProcessor(kSsrc2, &vp_1, cricket::MPD_RX));
2521 EXPECT_TRUE(engine_.RegisterProcessor(kSsrc2, &vp_2, cricket::MPD_RX));
2522 voe_.TriggerProcessPacket(cricket::MPD_RX);
2523 voe_.TriggerProcessPacket(cricket::MPD_TX);
2524
2525 EXPECT_TRUE(voe_.IsExternalMediaProcessorRegistered());
2526 EXPECT_EQ(1, vp_1.voice_frame_count());
2527 EXPECT_EQ(1, vp_2.voice_frame_count());
2528
2529 EXPECT_TRUE(engine_.UnregisterProcessor(kSsrc2,
2530 &vp_2,
2531 cricket::MPD_RX));
2532 voe_.TriggerProcessPacket(cricket::MPD_RX);
2533 EXPECT_TRUE(voe_.IsExternalMediaProcessorRegistered());
2534 EXPECT_EQ(1, vp_2.voice_frame_count());
2535 EXPECT_EQ(2, vp_1.voice_frame_count());
2536
2537 EXPECT_TRUE(engine_.UnregisterProcessor(kSsrc2,
2538 &vp_1,
2539 cricket::MPD_RX));
2540 voe_.TriggerProcessPacket(cricket::MPD_RX);
2541 EXPECT_FALSE(voe_.IsExternalMediaProcessorRegistered());
2542 EXPECT_EQ(2, vp_1.voice_frame_count());
2543
2544 EXPECT_FALSE(engine_.RegisterProcessor(kSsrc1, &vp_1, cricket::MPD_RX));
2545 EXPECT_TRUE(engine_.RegisterProcessor(kSsrc1, &vp_1, cricket::MPD_TX));
2546 voe_.TriggerProcessPacket(cricket::MPD_RX);
2547 voe_.TriggerProcessPacket(cricket::MPD_TX);
2548 EXPECT_TRUE(voe_.IsExternalMediaProcessorRegistered());
2549 EXPECT_EQ(3, vp_1.voice_frame_count());
2550
2551 EXPECT_TRUE(engine_.UnregisterProcessor(kSsrc1,
2552 &vp_1,
2553 cricket::MPD_RX_AND_TX));
2554 voe_.TriggerProcessPacket(cricket::MPD_TX);
2555 EXPECT_FALSE(voe_.IsExternalMediaProcessorRegistered());
2556 EXPECT_EQ(3, vp_1.voice_frame_count());
2557 EXPECT_TRUE(channel_->RemoveRecvStream(kSsrc2));
2558 EXPECT_FALSE(engine_.RegisterProcessor(kSsrc2, &vp_1, cricket::MPD_RX));
2559 EXPECT_FALSE(voe_.IsExternalMediaProcessorRegistered());
2560
2561 // Test that we can register a processor on the receive channel on SSRC 0.
2562 // This tests the 1:1 case when the receive SSRC is unknown.
2563 EXPECT_TRUE(engine_.RegisterProcessor(0, &vp_1, cricket::MPD_RX));
2564 voe_.TriggerProcessPacket(cricket::MPD_RX);
2565 EXPECT_TRUE(voe_.IsExternalMediaProcessorRegistered());
2566 EXPECT_EQ(4, vp_1.voice_frame_count());
2567 EXPECT_TRUE(engine_.UnregisterProcessor(0,
2568 &vp_1,
2569 cricket::MPD_RX));
2570
2571 // The following tests test that FindChannelNumFromSsrc is doing
2572 // what we expect.
2573 // pick an invalid ssrc and make sure we can't register
2574 EXPECT_FALSE(engine_.RegisterProcessor(99,
2575 &vp_1,
2576 cricket::MPD_RX));
2577 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(1)));
2578 EXPECT_TRUE(engine_.RegisterProcessor(1,
2579 &vp_1,
2580 cricket::MPD_RX));
2581 EXPECT_TRUE(engine_.UnregisterProcessor(1,
2582 &vp_1,
2583 cricket::MPD_RX));
2584 EXPECT_FALSE(engine_.RegisterProcessor(1,
2585 &vp_1,
2586 cricket::MPD_TX));
2587 EXPECT_TRUE(channel_->RemoveRecvStream(1));
2588}
2589
2590TEST_F(WebRtcVoiceEngineTestFake, SetAudioOptions) {
2591 EXPECT_TRUE(SetupEngine());
2592
2593 bool ec_enabled;
2594 webrtc::EcModes ec_mode;
2595 bool ec_metrics_enabled;
2596 webrtc::AecmModes aecm_mode;
2597 bool cng_enabled;
2598 bool agc_enabled;
2599 webrtc::AgcModes agc_mode;
2600 webrtc::AgcConfig agc_config;
2601 bool ns_enabled;
2602 webrtc::NsModes ns_mode;
2603 bool highpass_filter_enabled;
2604 bool stereo_swapping_enabled;
2605 bool typing_detection_enabled;
2606 voe_.GetEcStatus(ec_enabled, ec_mode);
2607 voe_.GetEcMetricsStatus(ec_metrics_enabled);
2608 voe_.GetAecmMode(aecm_mode, cng_enabled);
2609 voe_.GetAgcStatus(agc_enabled, agc_mode);
2610 voe_.GetAgcConfig(agc_config);
2611 voe_.GetNsStatus(ns_enabled, ns_mode);
2612 highpass_filter_enabled = voe_.IsHighPassFilterEnabled();
2613 stereo_swapping_enabled = voe_.IsStereoChannelSwappingEnabled();
2614 voe_.GetTypingDetectionStatus(typing_detection_enabled);
2615 EXPECT_TRUE(ec_enabled);
2616 EXPECT_TRUE(ec_metrics_enabled);
2617 EXPECT_FALSE(cng_enabled);
2618 EXPECT_TRUE(agc_enabled);
2619 EXPECT_EQ(0, agc_config.targetLeveldBOv);
2620 EXPECT_TRUE(ns_enabled);
2621 EXPECT_TRUE(highpass_filter_enabled);
2622 EXPECT_FALSE(stereo_swapping_enabled);
2623 EXPECT_TRUE(typing_detection_enabled);
2624 EXPECT_EQ(ec_mode, webrtc::kEcConference);
2625 EXPECT_EQ(ns_mode, webrtc::kNsHighSuppression);
2626
2627 // Nothing set, so all ignored.
2628 cricket::AudioOptions options;
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00002629 ASSERT_TRUE(engine_.SetOptions(options));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002630 voe_.GetEcStatus(ec_enabled, ec_mode);
2631 voe_.GetEcMetricsStatus(ec_metrics_enabled);
2632 voe_.GetAecmMode(aecm_mode, cng_enabled);
2633 voe_.GetAgcStatus(agc_enabled, agc_mode);
2634 voe_.GetAgcConfig(agc_config);
2635 voe_.GetNsStatus(ns_enabled, ns_mode);
2636 highpass_filter_enabled = voe_.IsHighPassFilterEnabled();
2637 stereo_swapping_enabled = voe_.IsStereoChannelSwappingEnabled();
2638 voe_.GetTypingDetectionStatus(typing_detection_enabled);
2639 EXPECT_TRUE(ec_enabled);
2640 EXPECT_TRUE(ec_metrics_enabled);
2641 EXPECT_FALSE(cng_enabled);
2642 EXPECT_TRUE(agc_enabled);
2643 EXPECT_EQ(0, agc_config.targetLeveldBOv);
2644 EXPECT_TRUE(ns_enabled);
2645 EXPECT_TRUE(highpass_filter_enabled);
2646 EXPECT_FALSE(stereo_swapping_enabled);
2647 EXPECT_TRUE(typing_detection_enabled);
2648 EXPECT_EQ(ec_mode, webrtc::kEcConference);
2649 EXPECT_EQ(ns_mode, webrtc::kNsHighSuppression);
2650
2651 // Turn echo cancellation off
2652 options.echo_cancellation.Set(false);
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00002653 ASSERT_TRUE(engine_.SetOptions(options));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002654 voe_.GetEcStatus(ec_enabled, ec_mode);
2655 EXPECT_FALSE(ec_enabled);
2656
2657 // Turn echo cancellation back on, with settings, and make sure
2658 // nothing else changed.
2659 options.echo_cancellation.Set(true);
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00002660 ASSERT_TRUE(engine_.SetOptions(options));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002661 voe_.GetEcStatus(ec_enabled, ec_mode);
2662 voe_.GetEcMetricsStatus(ec_metrics_enabled);
2663 voe_.GetAecmMode(aecm_mode, cng_enabled);
2664 voe_.GetAgcStatus(agc_enabled, agc_mode);
2665 voe_.GetAgcConfig(agc_config);
2666 voe_.GetNsStatus(ns_enabled, ns_mode);
2667 highpass_filter_enabled = voe_.IsHighPassFilterEnabled();
2668 stereo_swapping_enabled = voe_.IsStereoChannelSwappingEnabled();
2669 voe_.GetTypingDetectionStatus(typing_detection_enabled);
2670 EXPECT_TRUE(ec_enabled);
2671 EXPECT_TRUE(ec_metrics_enabled);
2672 EXPECT_TRUE(agc_enabled);
2673 EXPECT_EQ(0, agc_config.targetLeveldBOv);
2674 EXPECT_TRUE(ns_enabled);
2675 EXPECT_TRUE(highpass_filter_enabled);
2676 EXPECT_FALSE(stereo_swapping_enabled);
2677 EXPECT_TRUE(typing_detection_enabled);
2678 EXPECT_EQ(ec_mode, webrtc::kEcConference);
2679 EXPECT_EQ(ns_mode, webrtc::kNsHighSuppression);
2680
2681 // Turn off AGC
2682 options.auto_gain_control.Set(false);
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00002683 ASSERT_TRUE(engine_.SetOptions(options));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002684 voe_.GetAgcStatus(agc_enabled, agc_mode);
2685 EXPECT_FALSE(agc_enabled);
2686
2687 // Turn AGC back on
2688 options.auto_gain_control.Set(true);
2689 options.adjust_agc_delta.Clear();
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00002690 ASSERT_TRUE(engine_.SetOptions(options));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002691 voe_.GetAgcStatus(agc_enabled, agc_mode);
2692 EXPECT_TRUE(agc_enabled);
2693 voe_.GetAgcConfig(agc_config);
2694 EXPECT_EQ(0, agc_config.targetLeveldBOv);
2695
2696 // Turn off other options (and stereo swapping on).
2697 options.noise_suppression.Set(false);
2698 options.highpass_filter.Set(false);
2699 options.typing_detection.Set(false);
2700 options.stereo_swapping.Set(true);
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00002701 ASSERT_TRUE(engine_.SetOptions(options));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002702 voe_.GetNsStatus(ns_enabled, ns_mode);
2703 highpass_filter_enabled = voe_.IsHighPassFilterEnabled();
2704 stereo_swapping_enabled = voe_.IsStereoChannelSwappingEnabled();
2705 voe_.GetTypingDetectionStatus(typing_detection_enabled);
2706 EXPECT_FALSE(ns_enabled);
2707 EXPECT_FALSE(highpass_filter_enabled);
2708 EXPECT_FALSE(typing_detection_enabled);
2709 EXPECT_TRUE(stereo_swapping_enabled);
2710
2711 // Turn on "conference mode" to ensure it has no impact.
2712 options.conference_mode.Set(true);
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00002713 ASSERT_TRUE(engine_.SetOptions(options));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002714 voe_.GetEcStatus(ec_enabled, ec_mode);
2715 voe_.GetNsStatus(ns_enabled, ns_mode);
2716 EXPECT_TRUE(ec_enabled);
2717 EXPECT_EQ(webrtc::kEcConference, ec_mode);
2718 EXPECT_FALSE(ns_enabled);
2719 EXPECT_EQ(webrtc::kNsHighSuppression, ns_mode);
2720}
2721
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00002722TEST_F(WebRtcVoiceEngineTestFake, DefaultOptions) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002723 EXPECT_TRUE(SetupEngine());
2724
2725 bool ec_enabled;
2726 webrtc::EcModes ec_mode;
2727 bool ec_metrics_enabled;
2728 bool agc_enabled;
2729 webrtc::AgcModes agc_mode;
2730 bool ns_enabled;
2731 webrtc::NsModes ns_mode;
2732 bool highpass_filter_enabled;
2733 bool stereo_swapping_enabled;
2734 bool typing_detection_enabled;
2735
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002736 voe_.GetEcStatus(ec_enabled, ec_mode);
2737 voe_.GetEcMetricsStatus(ec_metrics_enabled);
2738 voe_.GetAgcStatus(agc_enabled, agc_mode);
2739 voe_.GetNsStatus(ns_enabled, ns_mode);
2740 highpass_filter_enabled = voe_.IsHighPassFilterEnabled();
2741 stereo_swapping_enabled = voe_.IsStereoChannelSwappingEnabled();
2742 voe_.GetTypingDetectionStatus(typing_detection_enabled);
2743 EXPECT_TRUE(ec_enabled);
2744 EXPECT_TRUE(agc_enabled);
2745 EXPECT_TRUE(ns_enabled);
2746 EXPECT_TRUE(highpass_filter_enabled);
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00002747 EXPECT_TRUE(typing_detection_enabled);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002748 EXPECT_FALSE(stereo_swapping_enabled);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002749}
2750
2751TEST_F(WebRtcVoiceEngineTestFake, InitDoesNotOverwriteDefaultAgcConfig) {
2752 webrtc::AgcConfig set_config = {0};
2753 set_config.targetLeveldBOv = 3;
2754 set_config.digitalCompressionGaindB = 9;
2755 set_config.limiterEnable = true;
2756 EXPECT_EQ(0, voe_.SetAgcConfig(set_config));
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002757 EXPECT_TRUE(engine_.Init(rtc::Thread::Current()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002758
2759 webrtc::AgcConfig config = {0};
2760 EXPECT_EQ(0, voe_.GetAgcConfig(config));
2761 EXPECT_EQ(set_config.targetLeveldBOv, config.targetLeveldBOv);
2762 EXPECT_EQ(set_config.digitalCompressionGaindB,
2763 config.digitalCompressionGaindB);
2764 EXPECT_EQ(set_config.limiterEnable, config.limiterEnable);
2765}
2766
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002767TEST_F(WebRtcVoiceEngineTestFake, SetOptionOverridesViaChannels) {
2768 EXPECT_TRUE(SetupEngine());
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002769 rtc::scoped_ptr<cricket::VoiceMediaChannel> channel1(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002770 engine_.CreateChannel());
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002771 rtc::scoped_ptr<cricket::VoiceMediaChannel> channel2(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002772 engine_.CreateChannel());
2773
2774 // Have to add a stream to make SetSend work.
2775 cricket::StreamParams stream1;
2776 stream1.ssrcs.push_back(1);
2777 channel1->AddSendStream(stream1);
2778 cricket::StreamParams stream2;
2779 stream2.ssrcs.push_back(2);
2780 channel2->AddSendStream(stream2);
2781
2782 // AEC and AGC and NS
2783 cricket::AudioOptions options_all;
2784 options_all.echo_cancellation.Set(true);
2785 options_all.auto_gain_control.Set(true);
2786 options_all.noise_suppression.Set(true);
2787
2788 ASSERT_TRUE(channel1->SetOptions(options_all));
2789 cricket::AudioOptions expected_options = options_all;
2790 cricket::AudioOptions actual_options;
2791 ASSERT_TRUE(channel1->GetOptions(&actual_options));
2792 EXPECT_EQ(expected_options, actual_options);
2793 ASSERT_TRUE(channel2->SetOptions(options_all));
2794 ASSERT_TRUE(channel2->GetOptions(&actual_options));
2795 EXPECT_EQ(expected_options, actual_options);
2796
2797 // unset NS
2798 cricket::AudioOptions options_no_ns;
2799 options_no_ns.noise_suppression.Set(false);
2800 ASSERT_TRUE(channel1->SetOptions(options_no_ns));
2801
2802 expected_options.echo_cancellation.Set(true);
2803 expected_options.auto_gain_control.Set(true);
2804 expected_options.noise_suppression.Set(false);
2805 ASSERT_TRUE(channel1->GetOptions(&actual_options));
2806 EXPECT_EQ(expected_options, actual_options);
2807
2808 // unset AGC
2809 cricket::AudioOptions options_no_agc;
2810 options_no_agc.auto_gain_control.Set(false);
2811 ASSERT_TRUE(channel2->SetOptions(options_no_agc));
2812
2813 expected_options.echo_cancellation.Set(true);
2814 expected_options.auto_gain_control.Set(false);
2815 expected_options.noise_suppression.Set(true);
2816 ASSERT_TRUE(channel2->GetOptions(&actual_options));
2817 EXPECT_EQ(expected_options, actual_options);
2818
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00002819 ASSERT_TRUE(engine_.SetOptions(options_all));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002820 bool ec_enabled;
2821 webrtc::EcModes ec_mode;
2822 bool agc_enabled;
2823 webrtc::AgcModes agc_mode;
2824 bool ns_enabled;
2825 webrtc::NsModes ns_mode;
2826 voe_.GetEcStatus(ec_enabled, ec_mode);
2827 voe_.GetAgcStatus(agc_enabled, agc_mode);
2828 voe_.GetNsStatus(ns_enabled, ns_mode);
2829 EXPECT_TRUE(ec_enabled);
2830 EXPECT_TRUE(agc_enabled);
2831 EXPECT_TRUE(ns_enabled);
2832
2833 channel1->SetSend(cricket::SEND_MICROPHONE);
2834 voe_.GetEcStatus(ec_enabled, ec_mode);
2835 voe_.GetAgcStatus(agc_enabled, agc_mode);
2836 voe_.GetNsStatus(ns_enabled, ns_mode);
2837 EXPECT_TRUE(ec_enabled);
2838 EXPECT_TRUE(agc_enabled);
2839 EXPECT_FALSE(ns_enabled);
2840
2841 channel1->SetSend(cricket::SEND_NOTHING);
2842 voe_.GetEcStatus(ec_enabled, ec_mode);
2843 voe_.GetAgcStatus(agc_enabled, agc_mode);
2844 voe_.GetNsStatus(ns_enabled, ns_mode);
2845 EXPECT_TRUE(ec_enabled);
2846 EXPECT_TRUE(agc_enabled);
2847 EXPECT_TRUE(ns_enabled);
2848
2849 channel2->SetSend(cricket::SEND_MICROPHONE);
2850 voe_.GetEcStatus(ec_enabled, ec_mode);
2851 voe_.GetAgcStatus(agc_enabled, agc_mode);
2852 voe_.GetNsStatus(ns_enabled, ns_mode);
2853 EXPECT_TRUE(ec_enabled);
2854 EXPECT_FALSE(agc_enabled);
2855 EXPECT_TRUE(ns_enabled);
2856
2857 channel2->SetSend(cricket::SEND_NOTHING);
2858 voe_.GetEcStatus(ec_enabled, ec_mode);
2859 voe_.GetAgcStatus(agc_enabled, agc_mode);
2860 voe_.GetNsStatus(ns_enabled, ns_mode);
2861 EXPECT_TRUE(ec_enabled);
2862 EXPECT_TRUE(agc_enabled);
2863 EXPECT_TRUE(ns_enabled);
2864
2865 // Make sure settings take effect while we are sending.
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00002866 ASSERT_TRUE(engine_.SetOptions(options_all));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002867 cricket::AudioOptions options_no_agc_nor_ns;
2868 options_no_agc_nor_ns.auto_gain_control.Set(false);
2869 options_no_agc_nor_ns.noise_suppression.Set(false);
2870 channel2->SetSend(cricket::SEND_MICROPHONE);
2871 channel2->SetOptions(options_no_agc_nor_ns);
2872
2873 expected_options.echo_cancellation.Set(true);
2874 expected_options.auto_gain_control.Set(false);
2875 expected_options.noise_suppression.Set(false);
2876 ASSERT_TRUE(channel2->GetOptions(&actual_options));
2877 EXPECT_EQ(expected_options, actual_options);
2878 voe_.GetEcStatus(ec_enabled, ec_mode);
2879 voe_.GetAgcStatus(agc_enabled, agc_mode);
2880 voe_.GetNsStatus(ns_enabled, ns_mode);
2881 EXPECT_TRUE(ec_enabled);
2882 EXPECT_FALSE(agc_enabled);
2883 EXPECT_FALSE(ns_enabled);
2884}
2885
wu@webrtc.orgde305012013-10-31 15:40:38 +00002886// This test verifies DSCP settings are properly applied on voice media channel.
2887TEST_F(WebRtcVoiceEngineTestFake, TestSetDscpOptions) {
2888 EXPECT_TRUE(SetupEngine());
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002889 rtc::scoped_ptr<cricket::VoiceMediaChannel> channel(
wu@webrtc.orgde305012013-10-31 15:40:38 +00002890 engine_.CreateChannel());
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002891 rtc::scoped_ptr<cricket::FakeNetworkInterface> network_interface(
wu@webrtc.orgde305012013-10-31 15:40:38 +00002892 new cricket::FakeNetworkInterface);
2893 channel->SetInterface(network_interface.get());
2894 cricket::AudioOptions options;
2895 options.dscp.Set(true);
2896 EXPECT_TRUE(channel->SetOptions(options));
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002897 EXPECT_EQ(rtc::DSCP_EF, network_interface->dscp());
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +00002898 // Verify previous value is not modified if dscp option is not set.
2899 cricket::AudioOptions options1;
2900 EXPECT_TRUE(channel->SetOptions(options1));
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002901 EXPECT_EQ(rtc::DSCP_EF, network_interface->dscp());
wu@webrtc.orgde305012013-10-31 15:40:38 +00002902 options.dscp.Set(false);
2903 EXPECT_TRUE(channel->SetOptions(options));
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002904 EXPECT_EQ(rtc::DSCP_DEFAULT, network_interface->dscp());
wu@webrtc.orgde305012013-10-31 15:40:38 +00002905}
2906
wu@webrtc.org1d1ffc92013-10-16 18:12:02 +00002907TEST(WebRtcVoiceEngineTest, TestDefaultOptionsBeforeInit) {
2908 cricket::WebRtcVoiceEngine engine;
2909 cricket::AudioOptions options = engine.GetOptions();
2910 // The default options should have at least a few things set. We purposefully
2911 // don't check the option values here, though.
2912 EXPECT_TRUE(options.echo_cancellation.IsSet());
2913 EXPECT_TRUE(options.auto_gain_control.IsSet());
2914 EXPECT_TRUE(options.noise_suppression.IsSet());
2915}
2916
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002917// Test that GetReceiveChannelNum returns the default channel for the first
2918// recv stream in 1-1 calls.
2919TEST_F(WebRtcVoiceEngineTestFake, TestGetReceiveChannelNumIn1To1Calls) {
2920 EXPECT_TRUE(SetupEngine());
2921 cricket::WebRtcVoiceMediaChannel* media_channel =
2922 static_cast<cricket::WebRtcVoiceMediaChannel*>(channel_);
2923 // Test that GetChannelNum returns the default channel if the SSRC is unknown.
2924 EXPECT_EQ(media_channel->voe_channel(),
2925 media_channel->GetReceiveChannelNum(0));
2926 cricket::StreamParams stream;
2927 stream.ssrcs.push_back(kSsrc2);
2928 EXPECT_TRUE(channel_->AddRecvStream(stream));
2929 EXPECT_EQ(media_channel->voe_channel(),
2930 media_channel->GetReceiveChannelNum(kSsrc2));
2931}
2932
2933// Test that GetReceiveChannelNum doesn't return the default channel for the
2934// first recv stream in conference calls.
2935TEST_F(WebRtcVoiceEngineTestFake, TestGetChannelNumInConferenceCalls) {
2936 EXPECT_TRUE(SetupEngine());
2937 EXPECT_TRUE(channel_->SetOptions(options_conference_));
2938 cricket::StreamParams stream;
2939 stream.ssrcs.push_back(kSsrc2);
2940 EXPECT_TRUE(channel_->AddRecvStream(stream));
2941 cricket::WebRtcVoiceMediaChannel* media_channel =
2942 static_cast<cricket::WebRtcVoiceMediaChannel*>(channel_);
2943 EXPECT_LT(media_channel->voe_channel(),
2944 media_channel->GetReceiveChannelNum(kSsrc2));
2945}
2946
2947TEST_F(WebRtcVoiceEngineTestFake, SetOutputScaling) {
2948 EXPECT_TRUE(SetupEngine());
2949 double left, right;
2950 EXPECT_TRUE(channel_->SetOutputScaling(0, 1, 2));
2951 EXPECT_TRUE(channel_->GetOutputScaling(0, &left, &right));
2952 EXPECT_DOUBLE_EQ(1, left);
2953 EXPECT_DOUBLE_EQ(2, right);
2954
2955 EXPECT_FALSE(channel_->SetOutputScaling(kSsrc2, 1, 2));
2956 cricket::StreamParams stream;
2957 stream.ssrcs.push_back(kSsrc2);
2958 EXPECT_TRUE(channel_->AddRecvStream(stream));
2959
2960 EXPECT_TRUE(channel_->SetOutputScaling(kSsrc2, 2, 1));
2961 EXPECT_TRUE(channel_->GetOutputScaling(kSsrc2, &left, &right));
2962 EXPECT_DOUBLE_EQ(2, left);
2963 EXPECT_DOUBLE_EQ(1, right);
2964}
2965
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002966// Tests for the actual WebRtc VoE library.
2967
2968// Tests that the library initializes and shuts down properly.
2969TEST(WebRtcVoiceEngineTest, StartupShutdown) {
2970 cricket::WebRtcVoiceEngine engine;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002971 EXPECT_TRUE(engine.Init(rtc::Thread::Current()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002972 cricket::VoiceMediaChannel* channel = engine.CreateChannel();
2973 EXPECT_TRUE(channel != NULL);
2974 delete channel;
2975 engine.Terminate();
2976
2977 // Reinit to catch regression where VoiceEngineObserver reference is lost
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002978 EXPECT_TRUE(engine.Init(rtc::Thread::Current()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002979 engine.Terminate();
2980}
2981
2982// Tests that the logging from the library is cleartext.
2983TEST(WebRtcVoiceEngineTest, DISABLED_HasUnencryptedLogging) {
2984 cricket::WebRtcVoiceEngine engine;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002985 rtc::scoped_ptr<rtc::MemoryStream> stream(
2986 new rtc::MemoryStream);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002987 size_t size = 0;
2988 bool cleartext = true;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002989 rtc::LogMessage::AddLogToStream(stream.get(), rtc::LS_VERBOSE);
2990 engine.SetLogging(rtc::LS_VERBOSE, "");
2991 EXPECT_TRUE(engine.Init(rtc::Thread::Current()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002992 EXPECT_TRUE(stream->GetSize(&size));
2993 EXPECT_GT(size, 0U);
2994 engine.Terminate();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002995 rtc::LogMessage::RemoveLogToStream(stream.get());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002996 const char* buf = stream->GetBuffer();
2997 for (size_t i = 0; i < size && cleartext; ++i) {
2998 int ch = static_cast<int>(buf[i]);
2999 ASSERT_GE(ch, 0) << "Out of bounds character in WebRtc VoE log: "
3000 << std::hex << ch;
3001 cleartext = (isprint(ch) || isspace(ch));
3002 }
3003 EXPECT_TRUE(cleartext);
3004}
3005
3006// Tests we do not see any references to a monitor thread being spun up
3007// when initiating the engine.
3008TEST(WebRtcVoiceEngineTest, HasNoMonitorThread) {
3009 cricket::WebRtcVoiceEngine engine;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003010 rtc::scoped_ptr<rtc::MemoryStream> stream(
3011 new rtc::MemoryStream);
3012 rtc::LogMessage::AddLogToStream(stream.get(), rtc::LS_VERBOSE);
3013 engine.SetLogging(rtc::LS_VERBOSE, "");
3014 EXPECT_TRUE(engine.Init(rtc::Thread::Current()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003015 engine.Terminate();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003016 rtc::LogMessage::RemoveLogToStream(stream.get());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003017
3018 size_t size = 0;
3019 EXPECT_TRUE(stream->GetSize(&size));
3020 EXPECT_GT(size, 0U);
wu@webrtc.org9caf2762013-12-11 18:25:07 +00003021 const std::string logs(stream->GetBuffer(), size);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003022 EXPECT_NE(std::string::npos, logs.find("ProcessThread"));
3023}
3024
3025// Tests that the library is configured with the codecs we want.
3026TEST(WebRtcVoiceEngineTest, HasCorrectCodecs) {
3027 cricket::WebRtcVoiceEngine engine;
3028 // Check codecs by name.
3029 EXPECT_TRUE(engine.FindCodec(
3030 cricket::AudioCodec(96, "OPUS", 48000, 0, 2, 0)));
3031 EXPECT_TRUE(engine.FindCodec(
3032 cricket::AudioCodec(96, "ISAC", 16000, 0, 1, 0)));
3033 EXPECT_TRUE(engine.FindCodec(
3034 cricket::AudioCodec(96, "ISAC", 32000, 0, 1, 0)));
3035 // Check that name matching is case-insensitive.
3036 EXPECT_TRUE(engine.FindCodec(
3037 cricket::AudioCodec(96, "ILBC", 8000, 0, 1, 0)));
3038 EXPECT_TRUE(engine.FindCodec(
3039 cricket::AudioCodec(96, "iLBC", 8000, 0, 1, 0)));
3040 EXPECT_TRUE(engine.FindCodec(
3041 cricket::AudioCodec(96, "PCMU", 8000, 0, 1, 0)));
3042 EXPECT_TRUE(engine.FindCodec(
3043 cricket::AudioCodec(96, "PCMA", 8000, 0, 1, 0)));
3044 EXPECT_TRUE(engine.FindCodec(
3045 cricket::AudioCodec(96, "G722", 16000, 0, 1, 0)));
3046 EXPECT_TRUE(engine.FindCodec(
3047 cricket::AudioCodec(96, "red", 8000, 0, 1, 0)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003048 EXPECT_TRUE(engine.FindCodec(
3049 cricket::AudioCodec(96, "CN", 32000, 0, 1, 0)));
3050 EXPECT_TRUE(engine.FindCodec(
3051 cricket::AudioCodec(96, "CN", 16000, 0, 1, 0)));
3052 EXPECT_TRUE(engine.FindCodec(
3053 cricket::AudioCodec(96, "CN", 8000, 0, 1, 0)));
3054 EXPECT_TRUE(engine.FindCodec(
3055 cricket::AudioCodec(96, "telephone-event", 8000, 0, 1, 0)));
3056 // Check codecs with an id by id.
3057 EXPECT_TRUE(engine.FindCodec(
3058 cricket::AudioCodec(0, "", 8000, 0, 1, 0))); // PCMU
3059 EXPECT_TRUE(engine.FindCodec(
3060 cricket::AudioCodec(8, "", 8000, 0, 1, 0))); // PCMA
3061 EXPECT_TRUE(engine.FindCodec(
3062 cricket::AudioCodec(9, "", 16000, 0, 1, 0))); // G722
3063 EXPECT_TRUE(engine.FindCodec(
3064 cricket::AudioCodec(13, "", 8000, 0, 1, 0))); // CN
3065 // Check sample/bitrate matching.
3066 EXPECT_TRUE(engine.FindCodec(
3067 cricket::AudioCodec(0, "PCMU", 8000, 64000, 1, 0)));
3068 // Check that bad codecs fail.
3069 EXPECT_FALSE(engine.FindCodec(cricket::AudioCodec(99, "ABCD", 0, 0, 1, 0)));
3070 EXPECT_FALSE(engine.FindCodec(cricket::AudioCodec(88, "", 0, 0, 1, 0)));
3071 EXPECT_FALSE(engine.FindCodec(cricket::AudioCodec(0, "", 0, 0, 2, 0)));
3072 EXPECT_FALSE(engine.FindCodec(cricket::AudioCodec(0, "", 5000, 0, 1, 0)));
3073 EXPECT_FALSE(engine.FindCodec(cricket::AudioCodec(0, "", 0, 5000, 1, 0)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003074 // Verify the payload id of common audio codecs, including CN, ISAC, and G722.
3075 for (std::vector<cricket::AudioCodec>::const_iterator it =
3076 engine.codecs().begin(); it != engine.codecs().end(); ++it) {
3077 if (it->name == "CN" && it->clockrate == 16000) {
3078 EXPECT_EQ(105, it->id);
3079 } else if (it->name == "CN" && it->clockrate == 32000) {
3080 EXPECT_EQ(106, it->id);
3081 } else if (it->name == "ISAC" && it->clockrate == 16000) {
3082 EXPECT_EQ(103, it->id);
3083 } else if (it->name == "ISAC" && it->clockrate == 32000) {
3084 EXPECT_EQ(104, it->id);
3085 } else if (it->name == "G722" && it->clockrate == 16000) {
3086 EXPECT_EQ(9, it->id);
3087 } else if (it->name == "telephone-event") {
3088 EXPECT_EQ(126, it->id);
3089 } else if (it->name == "red") {
3090 EXPECT_EQ(127, it->id);
3091 } else if (it->name == "opus") {
3092 EXPECT_EQ(111, it->id);
wu@webrtc.org9caf2762013-12-11 18:25:07 +00003093 ASSERT_TRUE(it->params.find("minptime") != it->params.end());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003094 EXPECT_EQ("10", it->params.find("minptime")->second);
wu@webrtc.org9caf2762013-12-11 18:25:07 +00003095 ASSERT_TRUE(it->params.find("maxptime") != it->params.end());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003096 EXPECT_EQ("60", it->params.find("maxptime")->second);
3097 }
3098 }
3099
3100 engine.Terminate();
3101}
3102
3103// Tests that VoE supports at least 32 channels
3104TEST(WebRtcVoiceEngineTest, Has32Channels) {
3105 cricket::WebRtcVoiceEngine engine;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003106 EXPECT_TRUE(engine.Init(rtc::Thread::Current()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003107
3108 cricket::VoiceMediaChannel* channels[32];
3109 int num_channels = 0;
3110
3111 while (num_channels < ARRAY_SIZE(channels)) {
3112 cricket::VoiceMediaChannel* channel = engine.CreateChannel();
3113 if (!channel)
3114 break;
3115
3116 channels[num_channels++] = channel;
3117 }
3118
3119 int expected = ARRAY_SIZE(channels);
3120 EXPECT_EQ(expected, num_channels);
3121
3122 while (num_channels > 0) {
3123 delete channels[--num_channels];
3124 }
3125
3126 engine.Terminate();
3127}
3128
3129// Test that we set our preferred codecs properly.
3130TEST(WebRtcVoiceEngineTest, SetRecvCodecs) {
3131 cricket::WebRtcVoiceEngine engine;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003132 EXPECT_TRUE(engine.Init(rtc::Thread::Current()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003133 cricket::WebRtcVoiceMediaChannel channel(&engine);
3134 EXPECT_TRUE(channel.SetRecvCodecs(engine.codecs()));
3135}
3136
3137#ifdef WIN32
3138// Test our workarounds to WebRtc VoE' munging of the coinit count
3139TEST(WebRtcVoiceEngineTest, CoInitialize) {
3140 cricket::WebRtcVoiceEngine* engine = new cricket::WebRtcVoiceEngine();
3141
3142 // Initial refcount should be 0.
3143 EXPECT_EQ(S_OK, CoInitializeEx(NULL, COINIT_MULTITHREADED));
3144
3145 // Engine should start even with COM already inited.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003146 EXPECT_TRUE(engine->Init(rtc::Thread::Current()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003147 engine->Terminate();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003148 EXPECT_TRUE(engine->Init(rtc::Thread::Current()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003149 engine->Terminate();
3150
3151 // Refcount after terminate should be 1 (in reality 3); test if it is nonzero.
3152 EXPECT_EQ(S_FALSE, CoInitializeEx(NULL, COINIT_MULTITHREADED));
3153 // Decrement refcount to (hopefully) 0.
3154 CoUninitialize();
3155 CoUninitialize();
3156 delete engine;
3157
3158 // Ensure refcount is 0.
3159 EXPECT_EQ(S_OK, CoInitializeEx(NULL, COINIT_MULTITHREADED));
3160 CoUninitialize();
3161}
3162#endif