blob: 5eb6e2448472779e363d8d0623ec5a970af3ee59 [file] [log] [blame]
henrike@webrtc.org79047f92014-03-06 23:46:59 +00001/*
2 * libjingle
3 * Copyright 2008 Google Inc.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright notice,
11 * this list of conditions and the following disclaimer in the documentation
12 * and/or other materials provided with the distribution.
13 * 3. The name of the author may not be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
19 * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
21 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
22 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
23 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
24 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
25 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
henrike@webrtc.org28e20752013-07-10 00:45:36 +000027
28#ifdef WIN32
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000029#include "webrtc/base/win32.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000030#include <objbase.h>
31#endif
32
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000033#include "webrtc/base/byteorder.h"
34#include "webrtc/base/gunit.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000035#include "talk/media/base/constants.h"
36#include "talk/media/base/fakemediaengine.h"
37#include "talk/media/base/fakemediaprocessor.h"
wu@webrtc.orgde305012013-10-31 15:40:38 +000038#include "talk/media/base/fakenetworkinterface.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000039#include "talk/media/base/fakertp.h"
40#include "talk/media/webrtc/fakewebrtcvoiceengine.h"
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +000041#include "talk/media/webrtc/webrtcvie.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000042#include "talk/media/webrtc/webrtcvoiceengine.h"
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +000043#include "webrtc/p2p/base/fakesession.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000044#include "talk/session/media/channel.h"
45
46// Tests for the WebRtcVoiceEngine/VoiceChannel code.
47
buildbot@webrtc.org150835e2014-05-06 15:54:38 +000048using cricket::kRtpAudioLevelHeaderExtension;
49using cricket::kRtpAbsoluteSenderTimeHeaderExtension;
50
henrike@webrtc.org28e20752013-07-10 00:45:36 +000051static const cricket::AudioCodec kPcmuCodec(0, "PCMU", 8000, 64000, 1, 0);
52static const cricket::AudioCodec kIsacCodec(103, "ISAC", 16000, 32000, 1, 0);
53static const cricket::AudioCodec kCeltCodec(110, "CELT", 32000, 64000, 2, 0);
54static const cricket::AudioCodec kOpusCodec(111, "opus", 48000, 64000, 2, 0);
henrik.lundin@webrtc.orgf85dbce2014-11-07 12:25:00 +000055static const cricket::AudioCodec kG722CodecVoE(9, "G722", 16000, 64000, 1, 0);
56static const cricket::AudioCodec kG722CodecSdp(9, "G722", 8000, 64000, 1, 0);
henrike@webrtc.org28e20752013-07-10 00:45:36 +000057static const cricket::AudioCodec kRedCodec(117, "red", 8000, 0, 1, 0);
58static const cricket::AudioCodec kCn8000Codec(13, "CN", 8000, 0, 1, 0);
59static const cricket::AudioCodec kCn16000Codec(105, "CN", 16000, 0, 1, 0);
60static const cricket::AudioCodec
61 kTelephoneEventCodec(106, "telephone-event", 8000, 0, 1, 0);
62static const cricket::AudioCodec* const kAudioCodecs[] = {
henrik.lundin@webrtc.orgf85dbce2014-11-07 12:25:00 +000063 &kPcmuCodec, &kIsacCodec, &kCeltCodec, &kOpusCodec, &kG722CodecVoE,
64 &kRedCodec, &kCn8000Codec, &kCn16000Codec, &kTelephoneEventCodec,
henrike@webrtc.org28e20752013-07-10 00:45:36 +000065};
66const char kRingbackTone[] = "RIFF____WAVE____ABCD1234";
67static uint32 kSsrc1 = 0x99;
68static uint32 kSsrc2 = 0x98;
69
70class FakeVoEWrapper : public cricket::VoEWrapper {
71 public:
72 explicit FakeVoEWrapper(cricket::FakeWebRtcVoiceEngine* engine)
73 : cricket::VoEWrapper(engine, // processing
74 engine, // base
75 engine, // codec
76 engine, // dtmf
77 engine, // file
78 engine, // hw
79 engine, // media
80 engine, // neteq
81 engine, // network
82 engine, // rtp
83 engine, // sync
84 engine) { // volume
85 }
86};
87
wu@webrtc.org97077a32013-10-25 21:18:33 +000088class FakeVoETraceWrapper : public cricket::VoETraceWrapper {
henrike@webrtc.org28e20752013-07-10 00:45:36 +000089 public:
90 virtual int SetTraceFilter(const unsigned int filter) {
wu@webrtc.org97077a32013-10-25 21:18:33 +000091 filter_ = filter;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000092 return 0;
93 }
94 virtual int SetTraceFile(const char* fileNameUTF8) {
95 return 0;
96 }
97 virtual int SetTraceCallback(webrtc::TraceCallback* callback) {
98 return 0;
99 }
wu@webrtc.org97077a32013-10-25 21:18:33 +0000100 unsigned int filter_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000101};
102
103class WebRtcVoiceEngineTestFake : public testing::Test {
104 public:
105 class ChannelErrorListener : public sigslot::has_slots<> {
106 public:
107 explicit ChannelErrorListener(cricket::VoiceMediaChannel* channel)
108 : ssrc_(0), error_(cricket::VoiceMediaChannel::ERROR_NONE) {
109 ASSERT(channel != NULL);
110 channel->SignalMediaError.connect(
111 this, &ChannelErrorListener::OnVoiceChannelError);
112 }
113 void OnVoiceChannelError(uint32 ssrc,
114 cricket::VoiceMediaChannel::Error error) {
115 ssrc_ = ssrc;
116 error_ = error;
117 }
118 void Reset() {
119 ssrc_ = 0;
120 error_ = cricket::VoiceMediaChannel::ERROR_NONE;
121 }
122 uint32 ssrc() const {
123 return ssrc_;
124 }
125 cricket::VoiceMediaChannel::Error error() const {
126 return error_;
127 }
128
129 private:
130 uint32 ssrc_;
131 cricket::VoiceMediaChannel::Error error_;
132 };
133
134 WebRtcVoiceEngineTestFake()
135 : voe_(kAudioCodecs, ARRAY_SIZE(kAudioCodecs)),
136 voe_sc_(kAudioCodecs, ARRAY_SIZE(kAudioCodecs)),
wu@webrtc.org97077a32013-10-25 21:18:33 +0000137 trace_wrapper_(new FakeVoETraceWrapper()),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000138 engine_(new FakeVoEWrapper(&voe_),
139 new FakeVoEWrapper(&voe_sc_),
wu@webrtc.org97077a32013-10-25 21:18:33 +0000140 trace_wrapper_),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000141 channel_(NULL), soundclip_(NULL) {
142 options_conference_.conference_mode.Set(true);
143 options_adjust_agc_.adjust_agc_delta.Set(-10);
144 }
buildbot@webrtc.org150835e2014-05-06 15:54:38 +0000145 bool SetupEngineWithoutStream() {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000146 if (!engine_.Init(rtc::Thread::Current())) {
buildbot@webrtc.org150835e2014-05-06 15:54:38 +0000147 return false;
148 }
149 channel_ = engine_.CreateChannel();
150 return (channel_ != NULL);
151 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000152 bool SetupEngine() {
buildbot@webrtc.org150835e2014-05-06 15:54:38 +0000153 if (!SetupEngineWithoutStream()) {
154 return false;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000155 }
buildbot@webrtc.org150835e2014-05-06 15:54:38 +0000156 return channel_->AddSendStream(
157 cricket::StreamParams::CreateLegacy(kSsrc1));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000158 }
wu@webrtc.org9dba5252013-08-05 20:36:57 +0000159 void SetupForMultiSendStream() {
160 EXPECT_TRUE(SetupEngine());
161 // Remove stream added in Setup, which is corresponding to default channel.
162 int default_channel_num = voe_.GetLastChannel();
henrike@webrtc.org7666db72013-08-22 14:45:42 +0000163 uint32 default_send_ssrc = 0u;
wu@webrtc.org9dba5252013-08-05 20:36:57 +0000164 EXPECT_EQ(0, voe_.GetLocalSSRC(default_channel_num, default_send_ssrc));
165 EXPECT_EQ(kSsrc1, default_send_ssrc);
166 EXPECT_TRUE(channel_->RemoveSendStream(default_send_ssrc));
167
168 // Verify the default channel still exists.
169 EXPECT_EQ(0, voe_.GetLocalSSRC(default_channel_num, default_send_ssrc));
170 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000171 void DeliverPacket(const void* data, int len) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000172 rtc::Buffer packet(data, len);
173 channel_->OnPacketReceived(&packet, rtc::PacketTime());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000174 }
175 virtual void TearDown() {
176 delete soundclip_;
177 delete channel_;
178 engine_.Terminate();
179 }
180
wu@webrtc.orgcadf9042013-08-30 21:24:16 +0000181 void TestInsertDtmf(uint32 ssrc, bool caller) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000182 EXPECT_TRUE(engine_.Init(rtc::Thread::Current()));
wu@webrtc.orgcadf9042013-08-30 21:24:16 +0000183 channel_ = engine_.CreateChannel();
184 EXPECT_TRUE(channel_ != NULL);
185 if (caller) {
186 // if this is a caller, local description will be applied and add the
187 // send stream.
188 EXPECT_TRUE(channel_->AddSendStream(
189 cricket::StreamParams::CreateLegacy(kSsrc1)));
190 }
191 int channel_id = voe_.GetLastChannel();
192
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000193 // Test we can only InsertDtmf when the other side supports telephone-event.
194 std::vector<cricket::AudioCodec> codecs;
195 codecs.push_back(kPcmuCodec);
196 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
197 EXPECT_TRUE(channel_->SetSend(cricket::SEND_MICROPHONE));
198 EXPECT_FALSE(channel_->CanInsertDtmf());
199 EXPECT_FALSE(channel_->InsertDtmf(ssrc, 1, 111, cricket::DF_SEND));
200 codecs.push_back(kTelephoneEventCodec);
201 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
202 EXPECT_TRUE(channel_->CanInsertDtmf());
wu@webrtc.orgcadf9042013-08-30 21:24:16 +0000203
204 if (!caller) {
205 // There's no active send channel yet.
206 EXPECT_FALSE(channel_->InsertDtmf(ssrc, 2, 123, cricket::DF_SEND));
207 EXPECT_TRUE(channel_->AddSendStream(
208 cricket::StreamParams::CreateLegacy(kSsrc1)));
209 }
210
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000211 // Check we fail if the ssrc is invalid.
212 EXPECT_FALSE(channel_->InsertDtmf(-1, 1, 111, cricket::DF_SEND));
213
214 // Test send
215 EXPECT_FALSE(voe_.WasSendTelephoneEventCalled(channel_id, 2, 123));
216 EXPECT_TRUE(channel_->InsertDtmf(ssrc, 2, 123, cricket::DF_SEND));
217 EXPECT_TRUE(voe_.WasSendTelephoneEventCalled(channel_id, 2, 123));
218
219 // Test play
220 EXPECT_FALSE(voe_.WasPlayDtmfToneCalled(3, 134));
221 EXPECT_TRUE(channel_->InsertDtmf(ssrc, 3, 134, cricket::DF_PLAY));
222 EXPECT_TRUE(voe_.WasPlayDtmfToneCalled(3, 134));
223
224 // Test send and play
225 EXPECT_FALSE(voe_.WasSendTelephoneEventCalled(channel_id, 4, 145));
226 EXPECT_FALSE(voe_.WasPlayDtmfToneCalled(4, 145));
227 EXPECT_TRUE(channel_->InsertDtmf(ssrc, 4, 145,
228 cricket::DF_PLAY | cricket::DF_SEND));
229 EXPECT_TRUE(voe_.WasSendTelephoneEventCalled(channel_id, 4, 145));
230 EXPECT_TRUE(voe_.WasPlayDtmfToneCalled(4, 145));
231 }
232
233 // Test that send bandwidth is set correctly.
234 // |codec| is the codec under test.
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000235 // |max_bitrate| is a parameter to set to SetMaxSendBandwidth().
236 // |expected_result| is the expected result from SetMaxSendBandwidth().
237 // |expected_bitrate| is the expected audio bitrate afterward.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000238 void TestSendBandwidth(const cricket::AudioCodec& codec,
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000239 int max_bitrate,
240 bool expected_result,
241 int expected_bitrate) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000242 int channel_num = voe_.GetLastChannel();
243 std::vector<cricket::AudioCodec> codecs;
244
245 codecs.push_back(codec);
246 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
247
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000248 bool result = channel_->SetMaxSendBandwidth(max_bitrate);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000249 EXPECT_EQ(expected_result, result);
250
wu@webrtc.org1d1ffc92013-10-16 18:12:02 +0000251 webrtc::CodecInst temp_codec;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000252 EXPECT_FALSE(voe_.GetSendCodec(channel_num, temp_codec));
253
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000254 EXPECT_EQ(expected_bitrate, temp_codec.rate);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000255 }
256
buildbot@webrtc.org150835e2014-05-06 15:54:38 +0000257 void TestSetSendRtpHeaderExtensions(const std::string& ext) {
258 EXPECT_TRUE(SetupEngineWithoutStream());
259 int channel_num = voe_.GetLastChannel();
wu@webrtc.org9dba5252013-08-05 20:36:57 +0000260
henrike@webrtc.org79047f92014-03-06 23:46:59 +0000261 // Ensure extensions are off by default.
buildbot@webrtc.org150835e2014-05-06 15:54:38 +0000262 EXPECT_EQ(-1, voe_.GetSendRtpExtensionId(channel_num, ext));
wu@webrtc.org9dba5252013-08-05 20:36:57 +0000263
buildbot@webrtc.org150835e2014-05-06 15:54:38 +0000264 std::vector<cricket::RtpHeaderExtension> extensions;
wu@webrtc.org9dba5252013-08-05 20:36:57 +0000265 // Ensure unknown extensions won't cause an error.
266 extensions.push_back(cricket::RtpHeaderExtension(
henrike@webrtc.org79047f92014-03-06 23:46:59 +0000267 "urn:ietf:params:unknownextention", 1));
wu@webrtc.org9dba5252013-08-05 20:36:57 +0000268 EXPECT_TRUE(channel_->SetSendRtpHeaderExtensions(extensions));
buildbot@webrtc.org150835e2014-05-06 15:54:38 +0000269 EXPECT_EQ(-1, voe_.GetSendRtpExtensionId(channel_num, ext));
wu@webrtc.org9dba5252013-08-05 20:36:57 +0000270
henrike@webrtc.org79047f92014-03-06 23:46:59 +0000271 // Ensure extensions stay off with an empty list of headers.
272 extensions.clear();
wu@webrtc.org9dba5252013-08-05 20:36:57 +0000273 EXPECT_TRUE(channel_->SetSendRtpHeaderExtensions(extensions));
buildbot@webrtc.org150835e2014-05-06 15:54:38 +0000274 EXPECT_EQ(-1, voe_.GetSendRtpExtensionId(channel_num, ext));
wu@webrtc.org9dba5252013-08-05 20:36:57 +0000275
buildbot@webrtc.org150835e2014-05-06 15:54:38 +0000276 // Ensure extension is set properly.
277 const int id = 1;
278 extensions.push_back(cricket::RtpHeaderExtension(ext, id));
wu@webrtc.org9dba5252013-08-05 20:36:57 +0000279 EXPECT_TRUE(channel_->SetSendRtpHeaderExtensions(extensions));
buildbot@webrtc.org150835e2014-05-06 15:54:38 +0000280 EXPECT_EQ(id, voe_.GetSendRtpExtensionId(channel_num, ext));
wu@webrtc.org9dba5252013-08-05 20:36:57 +0000281
buildbot@webrtc.org150835e2014-05-06 15:54:38 +0000282 // Ensure extension is set properly on new channel.
283 // The first stream to occupy the default channel.
284 EXPECT_TRUE(channel_->AddSendStream(
285 cricket::StreamParams::CreateLegacy(123)));
286 EXPECT_TRUE(channel_->AddSendStream(
287 cricket::StreamParams::CreateLegacy(234)));
288 int new_channel_num = voe_.GetLastChannel();
289 EXPECT_NE(channel_num, new_channel_num);
290 EXPECT_EQ(id, voe_.GetSendRtpExtensionId(new_channel_num, ext));
henrike@webrtc.org79047f92014-03-06 23:46:59 +0000291
292 // Ensure all extensions go back off with an empty list.
wu@webrtc.org9dba5252013-08-05 20:36:57 +0000293 extensions.clear();
294 EXPECT_TRUE(channel_->SetSendRtpHeaderExtensions(extensions));
buildbot@webrtc.org150835e2014-05-06 15:54:38 +0000295 EXPECT_EQ(-1, voe_.GetSendRtpExtensionId(channel_num, ext));
296 EXPECT_EQ(-1, voe_.GetSendRtpExtensionId(new_channel_num, ext));
henrike@webrtc.org79047f92014-03-06 23:46:59 +0000297 }
298
buildbot@webrtc.org150835e2014-05-06 15:54:38 +0000299 void TestSetRecvRtpHeaderExtensions(const std::string& ext) {
300 EXPECT_TRUE(SetupEngineWithoutStream());
301 int channel_num = voe_.GetLastChannel();
henrike@webrtc.org79047f92014-03-06 23:46:59 +0000302
henrike@webrtc.org79047f92014-03-06 23:46:59 +0000303 // Ensure extensions are off by default.
buildbot@webrtc.org150835e2014-05-06 15:54:38 +0000304 EXPECT_EQ(-1, voe_.GetReceiveRtpExtensionId(channel_num, ext));
henrike@webrtc.org79047f92014-03-06 23:46:59 +0000305
buildbot@webrtc.org150835e2014-05-06 15:54:38 +0000306 std::vector<cricket::RtpHeaderExtension> extensions;
henrike@webrtc.org79047f92014-03-06 23:46:59 +0000307 // Ensure unknown extensions won't cause an error.
308 extensions.push_back(cricket::RtpHeaderExtension(
309 "urn:ietf:params:unknownextention", 1));
310 EXPECT_TRUE(channel_->SetRecvRtpHeaderExtensions(extensions));
buildbot@webrtc.org150835e2014-05-06 15:54:38 +0000311 EXPECT_EQ(-1, voe_.GetReceiveRtpExtensionId(channel_num, ext));
henrike@webrtc.org79047f92014-03-06 23:46:59 +0000312
buildbot@webrtc.org150835e2014-05-06 15:54:38 +0000313 // Ensure extensions stay off with an empty list of headers.
henrike@webrtc.org79047f92014-03-06 23:46:59 +0000314 extensions.clear();
315 EXPECT_TRUE(channel_->SetRecvRtpHeaderExtensions(extensions));
buildbot@webrtc.org150835e2014-05-06 15:54:38 +0000316 EXPECT_EQ(-1, voe_.GetReceiveRtpExtensionId(channel_num, ext));
henrike@webrtc.org79047f92014-03-06 23:46:59 +0000317
buildbot@webrtc.org150835e2014-05-06 15:54:38 +0000318 // Ensure extension is set properly.
319 const int id = 2;
320 extensions.push_back(cricket::RtpHeaderExtension(ext, id));
henrike@webrtc.org79047f92014-03-06 23:46:59 +0000321 EXPECT_TRUE(channel_->SetRecvRtpHeaderExtensions(extensions));
buildbot@webrtc.org150835e2014-05-06 15:54:38 +0000322 EXPECT_EQ(id, voe_.GetReceiveRtpExtensionId(channel_num, ext));
henrike@webrtc.org79047f92014-03-06 23:46:59 +0000323
buildbot@webrtc.org150835e2014-05-06 15:54:38 +0000324 // Ensure extension is set properly on new channel.
325 // The first stream to occupy the default channel.
326 EXPECT_TRUE(channel_->AddRecvStream(
327 cricket::StreamParams::CreateLegacy(345)));
328 EXPECT_TRUE(channel_->AddRecvStream(
329 cricket::StreamParams::CreateLegacy(456)));
330 int new_channel_num = voe_.GetLastChannel();
331 EXPECT_NE(channel_num, new_channel_num);
332 EXPECT_EQ(id, voe_.GetReceiveRtpExtensionId(new_channel_num, ext));
333
334 // Ensure all extensions go back off with an empty list.
henrike@webrtc.org79047f92014-03-06 23:46:59 +0000335 extensions.clear();
336 EXPECT_TRUE(channel_->SetRecvRtpHeaderExtensions(extensions));
buildbot@webrtc.org150835e2014-05-06 15:54:38 +0000337 EXPECT_EQ(-1, voe_.GetReceiveRtpExtensionId(channel_num, ext));
338 EXPECT_EQ(-1, voe_.GetReceiveRtpExtensionId(new_channel_num, ext));
wu@webrtc.org9dba5252013-08-05 20:36:57 +0000339 }
340
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000341 protected:
342 cricket::FakeWebRtcVoiceEngine voe_;
343 cricket::FakeWebRtcVoiceEngine voe_sc_;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000344 FakeVoETraceWrapper* trace_wrapper_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000345 cricket::WebRtcVoiceEngine engine_;
346 cricket::VoiceMediaChannel* channel_;
347 cricket::SoundclipMedia* soundclip_;
348
349 cricket::AudioOptions options_conference_;
350 cricket::AudioOptions options_adjust_agc_;
351};
352
353// Tests that our stub library "works".
354TEST_F(WebRtcVoiceEngineTestFake, StartupShutdown) {
355 EXPECT_FALSE(voe_.IsInited());
356 EXPECT_FALSE(voe_sc_.IsInited());
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000357 EXPECT_TRUE(engine_.Init(rtc::Thread::Current()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000358 EXPECT_TRUE(voe_.IsInited());
wu@webrtc.org4551b792013-10-09 15:37:36 +0000359 // The soundclip engine is lazily initialized.
360 EXPECT_FALSE(voe_sc_.IsInited());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000361 engine_.Terminate();
362 EXPECT_FALSE(voe_.IsInited());
363 EXPECT_FALSE(voe_sc_.IsInited());
364}
365
366// Tests that we can create and destroy a channel.
367TEST_F(WebRtcVoiceEngineTestFake, CreateChannel) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000368 EXPECT_TRUE(engine_.Init(rtc::Thread::Current()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000369 channel_ = engine_.CreateChannel();
370 EXPECT_TRUE(channel_ != NULL);
371}
372
373// Tests that we properly handle failures in CreateChannel.
374TEST_F(WebRtcVoiceEngineTestFake, CreateChannelFail) {
375 voe_.set_fail_create_channel(true);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000376 EXPECT_TRUE(engine_.Init(rtc::Thread::Current()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000377 channel_ = engine_.CreateChannel();
378 EXPECT_TRUE(channel_ == NULL);
379}
380
381// Tests that the list of supported codecs is created properly and ordered
382// correctly
383TEST_F(WebRtcVoiceEngineTestFake, CodecPreference) {
384 const std::vector<cricket::AudioCodec>& codecs = engine_.codecs();
385 ASSERT_FALSE(codecs.empty());
386 EXPECT_STRCASEEQ("opus", codecs[0].name.c_str());
387 EXPECT_EQ(48000, codecs[0].clockrate);
388 EXPECT_EQ(2, codecs[0].channels);
389 EXPECT_EQ(64000, codecs[0].bitrate);
390 int pref = codecs[0].preference;
391 for (size_t i = 1; i < codecs.size(); ++i) {
392 EXPECT_GT(pref, codecs[i].preference);
393 pref = codecs[i].preference;
394 }
395}
396
397// Tests that we can find codecs by name or id, and that we interpret the
398// clockrate and bitrate fields properly.
399TEST_F(WebRtcVoiceEngineTestFake, FindCodec) {
400 cricket::AudioCodec codec;
401 webrtc::CodecInst codec_inst;
402 // Find PCMU with explicit clockrate and bitrate.
403 EXPECT_TRUE(engine_.FindWebRtcCodec(kPcmuCodec, &codec_inst));
404 // Find ISAC with explicit clockrate and 0 bitrate.
405 EXPECT_TRUE(engine_.FindWebRtcCodec(kIsacCodec, &codec_inst));
406 // Find telephone-event with explicit clockrate and 0 bitrate.
407 EXPECT_TRUE(engine_.FindWebRtcCodec(kTelephoneEventCodec, &codec_inst));
408 // Find ISAC with a different payload id.
409 codec = kIsacCodec;
410 codec.id = 127;
411 EXPECT_TRUE(engine_.FindWebRtcCodec(codec, &codec_inst));
412 EXPECT_EQ(codec.id, codec_inst.pltype);
413 // Find PCMU with a 0 clockrate.
414 codec = kPcmuCodec;
415 codec.clockrate = 0;
416 EXPECT_TRUE(engine_.FindWebRtcCodec(codec, &codec_inst));
417 EXPECT_EQ(codec.id, codec_inst.pltype);
418 EXPECT_EQ(8000, codec_inst.plfreq);
419 // Find PCMU with a 0 bitrate.
420 codec = kPcmuCodec;
421 codec.bitrate = 0;
422 EXPECT_TRUE(engine_.FindWebRtcCodec(codec, &codec_inst));
423 EXPECT_EQ(codec.id, codec_inst.pltype);
424 EXPECT_EQ(64000, codec_inst.rate);
425 // Find ISAC with an explicit bitrate.
426 codec = kIsacCodec;
427 codec.bitrate = 32000;
428 EXPECT_TRUE(engine_.FindWebRtcCodec(codec, &codec_inst));
429 EXPECT_EQ(codec.id, codec_inst.pltype);
430 EXPECT_EQ(32000, codec_inst.rate);
431}
432
433// Test that we set our inbound codecs properly, including changing PT.
434TEST_F(WebRtcVoiceEngineTestFake, SetRecvCodecs) {
435 EXPECT_TRUE(SetupEngine());
436 int channel_num = voe_.GetLastChannel();
437 std::vector<cricket::AudioCodec> codecs;
438 codecs.push_back(kIsacCodec);
439 codecs.push_back(kPcmuCodec);
440 codecs.push_back(kTelephoneEventCodec);
441 codecs[0].id = 106; // collide with existing telephone-event
442 codecs[2].id = 126;
443 EXPECT_TRUE(channel_->SetRecvCodecs(codecs));
444 webrtc::CodecInst gcodec;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000445 rtc::strcpyn(gcodec.plname, ARRAY_SIZE(gcodec.plname), "ISAC");
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000446 gcodec.plfreq = 16000;
447 gcodec.channels = 1;
448 EXPECT_EQ(0, voe_.GetRecPayloadType(channel_num, gcodec));
449 EXPECT_EQ(106, gcodec.pltype);
450 EXPECT_STREQ("ISAC", gcodec.plname);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000451 rtc::strcpyn(gcodec.plname, ARRAY_SIZE(gcodec.plname),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000452 "telephone-event");
453 gcodec.plfreq = 8000;
454 EXPECT_EQ(0, voe_.GetRecPayloadType(channel_num, gcodec));
455 EXPECT_EQ(126, gcodec.pltype);
456 EXPECT_STREQ("telephone-event", gcodec.plname);
457}
458
459// Test that we fail to set an unknown inbound codec.
460TEST_F(WebRtcVoiceEngineTestFake, SetRecvCodecsUnsupportedCodec) {
461 EXPECT_TRUE(SetupEngine());
462 std::vector<cricket::AudioCodec> codecs;
463 codecs.push_back(kIsacCodec);
464 codecs.push_back(cricket::AudioCodec(127, "XYZ", 32000, 0, 1, 0));
465 EXPECT_FALSE(channel_->SetRecvCodecs(codecs));
466}
467
468// Test that we fail if we have duplicate types in the inbound list.
469TEST_F(WebRtcVoiceEngineTestFake, SetRecvCodecsDuplicatePayloadType) {
470 EXPECT_TRUE(SetupEngine());
471 std::vector<cricket::AudioCodec> codecs;
472 codecs.push_back(kIsacCodec);
473 codecs.push_back(kCn16000Codec);
474 codecs[1].id = kIsacCodec.id;
475 EXPECT_FALSE(channel_->SetRecvCodecs(codecs));
476}
477
478// Test that we can decode OPUS without stereo parameters.
479TEST_F(WebRtcVoiceEngineTestFake, SetRecvCodecsWithOpusNoStereo) {
480 EXPECT_TRUE(SetupEngine());
481 EXPECT_TRUE(channel_->SetOptions(options_conference_));
482 std::vector<cricket::AudioCodec> codecs;
483 codecs.push_back(kIsacCodec);
484 codecs.push_back(kPcmuCodec);
485 codecs.push_back(kOpusCodec);
486 EXPECT_TRUE(channel_->SetRecvCodecs(codecs));
487 EXPECT_TRUE(channel_->AddRecvStream(
488 cricket::StreamParams::CreateLegacy(kSsrc1)));
489 int channel_num2 = voe_.GetLastChannel();
490 webrtc::CodecInst opus;
491 engine_.FindWebRtcCodec(kOpusCodec, &opus);
492 // Even without stereo parameters, recv codecs still specify channels = 2.
493 EXPECT_EQ(2, opus.channels);
494 EXPECT_EQ(111, opus.pltype);
495 EXPECT_STREQ("opus", opus.plname);
496 opus.pltype = 0;
497 EXPECT_EQ(0, voe_.GetRecPayloadType(channel_num2, opus));
498 EXPECT_EQ(111, opus.pltype);
499}
500
501// Test that we can decode OPUS with stereo = 0.
502TEST_F(WebRtcVoiceEngineTestFake, SetRecvCodecsWithOpus0Stereo) {
503 EXPECT_TRUE(SetupEngine());
504 EXPECT_TRUE(channel_->SetOptions(options_conference_));
505 std::vector<cricket::AudioCodec> codecs;
506 codecs.push_back(kIsacCodec);
507 codecs.push_back(kPcmuCodec);
508 codecs.push_back(kOpusCodec);
509 codecs[2].params["stereo"] = "0";
510 EXPECT_TRUE(channel_->SetRecvCodecs(codecs));
511 EXPECT_TRUE(channel_->AddRecvStream(
512 cricket::StreamParams::CreateLegacy(kSsrc1)));
513 int channel_num2 = voe_.GetLastChannel();
514 webrtc::CodecInst opus;
515 engine_.FindWebRtcCodec(kOpusCodec, &opus);
516 // Even when stereo is off, recv codecs still specify channels = 2.
517 EXPECT_EQ(2, opus.channels);
518 EXPECT_EQ(111, opus.pltype);
519 EXPECT_STREQ("opus", opus.plname);
520 opus.pltype = 0;
521 EXPECT_EQ(0, voe_.GetRecPayloadType(channel_num2, opus));
522 EXPECT_EQ(111, opus.pltype);
523}
524
525// Test that we can decode OPUS with stereo = 1.
526TEST_F(WebRtcVoiceEngineTestFake, SetRecvCodecsWithOpus1Stereo) {
527 EXPECT_TRUE(SetupEngine());
528 EXPECT_TRUE(channel_->SetOptions(options_conference_));
529 std::vector<cricket::AudioCodec> codecs;
530 codecs.push_back(kIsacCodec);
531 codecs.push_back(kPcmuCodec);
532 codecs.push_back(kOpusCodec);
533 codecs[2].params["stereo"] = "1";
534 EXPECT_TRUE(channel_->SetRecvCodecs(codecs));
535 EXPECT_TRUE(channel_->AddRecvStream(
536 cricket::StreamParams::CreateLegacy(kSsrc1)));
537 int channel_num2 = voe_.GetLastChannel();
538 webrtc::CodecInst opus;
539 engine_.FindWebRtcCodec(kOpusCodec, &opus);
540 EXPECT_EQ(2, opus.channels);
541 EXPECT_EQ(111, opus.pltype);
542 EXPECT_STREQ("opus", opus.plname);
543 opus.pltype = 0;
544 EXPECT_EQ(0, voe_.GetRecPayloadType(channel_num2, opus));
545 EXPECT_EQ(111, opus.pltype);
546}
547
548// Test that changes to recv codecs are applied to all streams.
549TEST_F(WebRtcVoiceEngineTestFake, SetRecvCodecsWithMultipleStreams) {
550 EXPECT_TRUE(SetupEngine());
551 EXPECT_TRUE(channel_->SetOptions(options_conference_));
552 std::vector<cricket::AudioCodec> codecs;
553 codecs.push_back(kIsacCodec);
554 codecs.push_back(kPcmuCodec);
555 codecs.push_back(kTelephoneEventCodec);
556 codecs[0].id = 106; // collide with existing telephone-event
557 codecs[2].id = 126;
558 EXPECT_TRUE(channel_->SetRecvCodecs(codecs));
559 EXPECT_TRUE(channel_->AddRecvStream(
560 cricket::StreamParams::CreateLegacy(kSsrc1)));
561 int channel_num2 = voe_.GetLastChannel();
562 webrtc::CodecInst gcodec;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000563 rtc::strcpyn(gcodec.plname, ARRAY_SIZE(gcodec.plname), "ISAC");
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000564 gcodec.plfreq = 16000;
565 gcodec.channels = 1;
566 EXPECT_EQ(0, voe_.GetRecPayloadType(channel_num2, gcodec));
567 EXPECT_EQ(106, gcodec.pltype);
568 EXPECT_STREQ("ISAC", gcodec.plname);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000569 rtc::strcpyn(gcodec.plname, ARRAY_SIZE(gcodec.plname),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000570 "telephone-event");
571 gcodec.plfreq = 8000;
572 gcodec.channels = 1;
573 EXPECT_EQ(0, voe_.GetRecPayloadType(channel_num2, gcodec));
574 EXPECT_EQ(126, gcodec.pltype);
575 EXPECT_STREQ("telephone-event", gcodec.plname);
576}
577
578TEST_F(WebRtcVoiceEngineTestFake, SetRecvCodecsAfterAddingStreams) {
579 EXPECT_TRUE(SetupEngine());
580 EXPECT_TRUE(channel_->SetOptions(options_conference_));
581 std::vector<cricket::AudioCodec> codecs;
582 codecs.push_back(kIsacCodec);
583 codecs[0].id = 106; // collide with existing telephone-event
584
585 EXPECT_TRUE(channel_->AddRecvStream(
586 cricket::StreamParams::CreateLegacy(kSsrc1)));
587 EXPECT_TRUE(channel_->SetRecvCodecs(codecs));
588
589 int channel_num2 = voe_.GetLastChannel();
590 webrtc::CodecInst gcodec;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000591 rtc::strcpyn(gcodec.plname, ARRAY_SIZE(gcodec.plname), "ISAC");
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000592 gcodec.plfreq = 16000;
593 gcodec.channels = 1;
594 EXPECT_EQ(0, voe_.GetRecPayloadType(channel_num2, gcodec));
595 EXPECT_EQ(106, gcodec.pltype);
596 EXPECT_STREQ("ISAC", gcodec.plname);
597}
598
599// Test that we can apply the same set of codecs again while playing.
600TEST_F(WebRtcVoiceEngineTestFake, SetRecvCodecsWhilePlaying) {
601 EXPECT_TRUE(SetupEngine());
602 int channel_num = voe_.GetLastChannel();
603 std::vector<cricket::AudioCodec> codecs;
604 codecs.push_back(kIsacCodec);
605 codecs.push_back(kCn16000Codec);
606 EXPECT_TRUE(channel_->SetRecvCodecs(codecs));
607 EXPECT_TRUE(channel_->SetPlayout(true));
608 EXPECT_TRUE(channel_->SetRecvCodecs(codecs));
609
610 // Changing the payload type of a codec should fail.
611 codecs[0].id = 127;
612 EXPECT_FALSE(channel_->SetRecvCodecs(codecs));
613 EXPECT_TRUE(voe_.GetPlayout(channel_num));
614}
615
616// Test that we can add a codec while playing.
617TEST_F(WebRtcVoiceEngineTestFake, AddRecvCodecsWhilePlaying) {
618 EXPECT_TRUE(SetupEngine());
619 int channel_num = voe_.GetLastChannel();
620 std::vector<cricket::AudioCodec> codecs;
621 codecs.push_back(kIsacCodec);
622 codecs.push_back(kCn16000Codec);
623 EXPECT_TRUE(channel_->SetRecvCodecs(codecs));
624 EXPECT_TRUE(channel_->SetPlayout(true));
625
626 codecs.push_back(kOpusCodec);
627 EXPECT_TRUE(channel_->SetRecvCodecs(codecs));
628 EXPECT_TRUE(voe_.GetPlayout(channel_num));
629 webrtc::CodecInst gcodec;
630 EXPECT_TRUE(engine_.FindWebRtcCodec(kOpusCodec, &gcodec));
631 EXPECT_EQ(kOpusCodec.id, gcodec.pltype);
632}
633
634TEST_F(WebRtcVoiceEngineTestFake, SetSendBandwidthAuto) {
635 EXPECT_TRUE(SetupEngine());
636 EXPECT_TRUE(channel_->SetSendCodecs(engine_.codecs()));
637
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000638 // Test that when autobw is enabled, bitrate is kept as the default
639 // value. autobw is enabled for the following tests because the target
640 // bitrate is <= 0.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000641
642 // ISAC, default bitrate == 32000.
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000643 TestSendBandwidth(kIsacCodec, 0, true, 32000);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000644
645 // PCMU, default bitrate == 64000.
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000646 TestSendBandwidth(kPcmuCodec, -1, true, 64000);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000647
648 // CELT, default bitrate == 64000.
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000649 TestSendBandwidth(kCeltCodec, 0, true, 64000);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000650
651 // opus, default bitrate == 64000.
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000652 TestSendBandwidth(kOpusCodec, -1, true, 64000);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000653}
654
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000655TEST_F(WebRtcVoiceEngineTestFake, SetMaxSendBandwidthMultiRateAsCaller) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000656 EXPECT_TRUE(SetupEngine());
657 EXPECT_TRUE(channel_->SetSendCodecs(engine_.codecs()));
658
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000659 // Test that the bitrate of a multi-rate codec is always the maximum.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000660
661 // ISAC, default bitrate == 32000.
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000662 TestSendBandwidth(kIsacCodec, 128000, true, 128000);
663 TestSendBandwidth(kIsacCodec, 16000, true, 16000);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000664
665 // CELT, default bitrate == 64000.
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000666 TestSendBandwidth(kCeltCodec, 96000, true, 96000);
667 TestSendBandwidth(kCeltCodec, 32000, true, 32000);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000668
669 // opus, default bitrate == 64000.
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000670 TestSendBandwidth(kOpusCodec, 96000, true, 96000);
671 TestSendBandwidth(kOpusCodec, 48000, true, 48000);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000672}
673
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000674TEST_F(WebRtcVoiceEngineTestFake, SetMaxSendBandwidthFixedRateAsCaller) {
675 EXPECT_TRUE(SetupEngine());
676 EXPECT_TRUE(channel_->SetSendCodecs(engine_.codecs()));
677
678 // Test that we can only set a maximum bitrate for a fixed-rate codec
679 // if it's bigger than the fixed rate.
680
681 // PCMU, fixed bitrate == 64000.
682 TestSendBandwidth(kPcmuCodec, 0, true, 64000);
683 TestSendBandwidth(kPcmuCodec, 1, false, 64000);
684 TestSendBandwidth(kPcmuCodec, 128000, true, 64000);
685 TestSendBandwidth(kPcmuCodec, 32000, false, 64000);
686 TestSendBandwidth(kPcmuCodec, 64000, true, 64000);
687 TestSendBandwidth(kPcmuCodec, 63999, false, 64000);
688 TestSendBandwidth(kPcmuCodec, 64001, true, 64000);
689}
690
691TEST_F(WebRtcVoiceEngineTestFake, SetMaxSendBandwidthMultiRateAsCallee) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000692 EXPECT_TRUE(engine_.Init(rtc::Thread::Current()));
wu@webrtc.org1d1ffc92013-10-16 18:12:02 +0000693 channel_ = engine_.CreateChannel();
694 EXPECT_TRUE(channel_ != NULL);
695 EXPECT_TRUE(channel_->SetSendCodecs(engine_.codecs()));
696
697 int desired_bitrate = 128000;
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000698 EXPECT_TRUE(channel_->SetMaxSendBandwidth(desired_bitrate));
wu@webrtc.org1d1ffc92013-10-16 18:12:02 +0000699
700 EXPECT_TRUE(channel_->AddSendStream(
701 cricket::StreamParams::CreateLegacy(kSsrc1)));
702
703 int channel_num = voe_.GetLastChannel();
704 webrtc::CodecInst codec;
705 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, codec));
706 EXPECT_EQ(desired_bitrate, codec.rate);
707}
708
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000709// Test that bitrate cannot be set for CBR codecs.
710// Bitrate is ignored if it is higher than the fixed bitrate.
711// Bitrate less then the fixed bitrate is an error.
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000712TEST_F(WebRtcVoiceEngineTestFake, SetMaxSendBandwidthCbr) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000713 EXPECT_TRUE(SetupEngine());
714 EXPECT_TRUE(channel_->SetSendCodecs(engine_.codecs()));
715
716 webrtc::CodecInst codec;
717 int channel_num = voe_.GetLastChannel();
718 std::vector<cricket::AudioCodec> codecs;
719
720 // PCMU, default bitrate == 64000.
721 codecs.push_back(kPcmuCodec);
722 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
723 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, codec));
724 EXPECT_EQ(64000, codec.rate);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000725 EXPECT_TRUE(channel_->SetMaxSendBandwidth(128000));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000726 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, codec));
727 EXPECT_EQ(64000, codec.rate);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000728 EXPECT_FALSE(channel_->SetMaxSendBandwidth(128));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000729 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, codec));
730 EXPECT_EQ(64000, codec.rate);
731}
732
733// Test that we apply codecs properly.
734TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecs) {
735 EXPECT_TRUE(SetupEngine());
736 int channel_num = voe_.GetLastChannel();
737 std::vector<cricket::AudioCodec> codecs;
738 codecs.push_back(kIsacCodec);
739 codecs.push_back(kPcmuCodec);
740 codecs.push_back(kRedCodec);
741 codecs[0].id = 96;
742 codecs[0].bitrate = 48000;
743 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
wu@webrtc.org05e7b442014-04-01 17:44:24 +0000744 EXPECT_EQ(1, voe_.GetNumSetSendCodecs());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000745 webrtc::CodecInst gcodec;
746 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
747 EXPECT_EQ(96, gcodec.pltype);
748 EXPECT_EQ(48000, gcodec.rate);
749 EXPECT_STREQ("ISAC", gcodec.plname);
750 EXPECT_FALSE(voe_.GetVAD(channel_num));
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +0000751 EXPECT_FALSE(voe_.GetRED(channel_num));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000752 EXPECT_EQ(13, voe_.GetSendCNPayloadType(channel_num, false));
753 EXPECT_EQ(105, voe_.GetSendCNPayloadType(channel_num, true));
754 EXPECT_EQ(106, voe_.GetSendTelephoneEventPayloadType(channel_num));
755}
756
wu@webrtc.org05e7b442014-04-01 17:44:24 +0000757// Test that VoE Channel doesn't call SetSendCodec again if same codec is tried
758// to apply.
759TEST_F(WebRtcVoiceEngineTestFake, DontResetSetSendCodec) {
760 EXPECT_TRUE(SetupEngine());
761 std::vector<cricket::AudioCodec> codecs;
762 codecs.push_back(kIsacCodec);
763 codecs.push_back(kPcmuCodec);
764 codecs.push_back(kRedCodec);
765 codecs[0].id = 96;
766 codecs[0].bitrate = 48000;
767 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
768 EXPECT_EQ(1, voe_.GetNumSetSendCodecs());
769 // Calling SetSendCodec again with same codec which is already set.
770 // In this case media channel shouldn't send codec to VoE.
771 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
772 EXPECT_EQ(1, voe_.GetNumSetSendCodecs());
773}
774
henrik.lundin@webrtc.orgf85dbce2014-11-07 12:25:00 +0000775// Verify that G722 is set with 16000 samples per second to WebRTC.
776TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecG722) {
777 EXPECT_TRUE(SetupEngine());
778 int channel_num = voe_.GetLastChannel();
779 std::vector<cricket::AudioCodec> codecs;
780 codecs.push_back(kG722CodecSdp);
781 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
782 webrtc::CodecInst gcodec;
783 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
784 EXPECT_STREQ("G722", gcodec.plname);
785 EXPECT_EQ(1, gcodec.channels);
786 EXPECT_EQ(16000, gcodec.plfreq);
787}
788
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000789// Test that if clockrate is not 48000 for opus, we fail.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000790TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecOpusBadClockrate) {
791 EXPECT_TRUE(SetupEngine());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000792 std::vector<cricket::AudioCodec> codecs;
793 codecs.push_back(kOpusCodec);
794 codecs[0].bitrate = 0;
795 codecs[0].clockrate = 50000;
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000796 EXPECT_FALSE(channel_->SetSendCodecs(codecs));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000797}
798
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000799// Test that if channels=0 for opus, we fail.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000800TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecOpusBad0ChannelsNoStereo) {
801 EXPECT_TRUE(SetupEngine());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000802 std::vector<cricket::AudioCodec> codecs;
803 codecs.push_back(kOpusCodec);
804 codecs[0].bitrate = 0;
805 codecs[0].channels = 0;
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000806 EXPECT_FALSE(channel_->SetSendCodecs(codecs));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000807}
808
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000809// Test that if channels=0 for opus, we fail.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000810TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecOpusBad0Channels1Stereo) {
811 EXPECT_TRUE(SetupEngine());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000812 std::vector<cricket::AudioCodec> codecs;
813 codecs.push_back(kOpusCodec);
814 codecs[0].bitrate = 0;
815 codecs[0].channels = 0;
816 codecs[0].params["stereo"] = "1";
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000817 EXPECT_FALSE(channel_->SetSendCodecs(codecs));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000818}
819
820// Test that if channel is 1 for opus and there's no stereo, we fail.
821TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecOpus1ChannelNoStereo) {
822 EXPECT_TRUE(SetupEngine());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000823 std::vector<cricket::AudioCodec> codecs;
824 codecs.push_back(kOpusCodec);
825 codecs[0].bitrate = 0;
826 codecs[0].channels = 1;
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000827 EXPECT_FALSE(channel_->SetSendCodecs(codecs));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000828}
829
830// Test that if channel is 1 for opus and stereo=0, we fail.
831TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecOpusBad1Channel0Stereo) {
832 EXPECT_TRUE(SetupEngine());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000833 std::vector<cricket::AudioCodec> codecs;
834 codecs.push_back(kOpusCodec);
835 codecs[0].bitrate = 0;
836 codecs[0].channels = 1;
837 codecs[0].params["stereo"] = "0";
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000838 EXPECT_FALSE(channel_->SetSendCodecs(codecs));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000839}
840
841// Test that if channel is 1 for opus and stereo=1, we fail.
842TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecOpusBad1Channel1Stereo) {
843 EXPECT_TRUE(SetupEngine());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000844 std::vector<cricket::AudioCodec> codecs;
845 codecs.push_back(kOpusCodec);
846 codecs[0].bitrate = 0;
847 codecs[0].channels = 1;
848 codecs[0].params["stereo"] = "1";
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000849 EXPECT_FALSE(channel_->SetSendCodecs(codecs));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000850}
851
852// Test that with bitrate=0 and no stereo,
853// channels and bitrate are 1 and 32000.
854TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecOpusGood0BitrateNoStereo) {
855 EXPECT_TRUE(SetupEngine());
856 int channel_num = voe_.GetLastChannel();
857 std::vector<cricket::AudioCodec> codecs;
858 codecs.push_back(kOpusCodec);
859 codecs[0].bitrate = 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
868// Test that with bitrate=0 and stereo=0,
869// channels and bitrate are 1 and 32000.
870TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecOpusGood0Bitrate0Stereo) {
871 EXPECT_TRUE(SetupEngine());
872 int channel_num = voe_.GetLastChannel();
873 std::vector<cricket::AudioCodec> codecs;
874 codecs.push_back(kOpusCodec);
875 codecs[0].bitrate = 0;
876 codecs[0].params["stereo"] = "0";
877 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
878 webrtc::CodecInst gcodec;
879 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
880 EXPECT_STREQ("opus", gcodec.plname);
881 EXPECT_EQ(1, gcodec.channels);
882 EXPECT_EQ(32000, gcodec.rate);
883}
884
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000885// Test that with bitrate=invalid and stereo=0,
886// channels and bitrate are 1 and 32000.
887TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecOpusGoodXBitrate0Stereo) {
888 EXPECT_TRUE(SetupEngine());
889 int channel_num = voe_.GetLastChannel();
890 std::vector<cricket::AudioCodec> codecs;
891 codecs.push_back(kOpusCodec);
892 codecs[0].params["stereo"] = "0";
893 webrtc::CodecInst gcodec;
894
buildbot@webrtc.org9d446f22014-10-23 12:22:06 +0000895 // bitrate that's out of the range between 6000 and 510000 will be clamped.
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000896 codecs[0].bitrate = 5999;
897 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
898 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
899 EXPECT_STREQ("opus", gcodec.plname);
900 EXPECT_EQ(1, gcodec.channels);
buildbot@webrtc.org9d446f22014-10-23 12:22:06 +0000901 EXPECT_EQ(6000, gcodec.rate);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000902
903 codecs[0].bitrate = 510001;
904 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
905 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
906 EXPECT_STREQ("opus", gcodec.plname);
907 EXPECT_EQ(1, gcodec.channels);
buildbot@webrtc.org9d446f22014-10-23 12:22:06 +0000908 EXPECT_EQ(510000, gcodec.rate);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000909}
910
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000911// Test that with bitrate=0 and stereo=1,
912// channels and bitrate are 2 and 64000.
913TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecOpusGood0Bitrate1Stereo) {
914 EXPECT_TRUE(SetupEngine());
915 int channel_num = voe_.GetLastChannel();
916 std::vector<cricket::AudioCodec> codecs;
917 codecs.push_back(kOpusCodec);
918 codecs[0].bitrate = 0;
919 codecs[0].params["stereo"] = "1";
920 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
921 webrtc::CodecInst gcodec;
922 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
923 EXPECT_STREQ("opus", gcodec.plname);
924 EXPECT_EQ(2, gcodec.channels);
925 EXPECT_EQ(64000, gcodec.rate);
926}
927
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000928// Test that with bitrate=invalid and stereo=1,
929// channels and bitrate are 2 and 64000.
930TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecOpusGoodXBitrate1Stereo) {
931 EXPECT_TRUE(SetupEngine());
932 int channel_num = voe_.GetLastChannel();
933 std::vector<cricket::AudioCodec> codecs;
934 codecs.push_back(kOpusCodec);
935 codecs[0].params["stereo"] = "1";
936 webrtc::CodecInst gcodec;
937
buildbot@webrtc.org9d446f22014-10-23 12:22:06 +0000938 // bitrate that's out of the range between 6000 and 510000 will be clamped.
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000939 codecs[0].bitrate = 5999;
940 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
941 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
942 EXPECT_STREQ("opus", gcodec.plname);
943 EXPECT_EQ(2, gcodec.channels);
buildbot@webrtc.org9d446f22014-10-23 12:22:06 +0000944 EXPECT_EQ(6000, gcodec.rate);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000945
946 codecs[0].bitrate = 510001;
947 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
948 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
949 EXPECT_STREQ("opus", gcodec.plname);
950 EXPECT_EQ(2, gcodec.channels);
buildbot@webrtc.org9d446f22014-10-23 12:22:06 +0000951 EXPECT_EQ(510000, gcodec.rate);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000952}
953
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000954// Test that with bitrate=N and stereo unset,
955// channels and bitrate are 1 and N.
956TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecOpusGoodNBitrateNoStereo) {
957 EXPECT_TRUE(SetupEngine());
958 int channel_num = voe_.GetLastChannel();
959 std::vector<cricket::AudioCodec> codecs;
960 codecs.push_back(kOpusCodec);
961 codecs[0].bitrate = 96000;
962 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
963 webrtc::CodecInst gcodec;
964 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
965 EXPECT_EQ(111, gcodec.pltype);
966 EXPECT_EQ(96000, gcodec.rate);
967 EXPECT_STREQ("opus", gcodec.plname);
968 EXPECT_EQ(1, gcodec.channels);
969 EXPECT_EQ(48000, gcodec.plfreq);
970}
971
972// Test that with bitrate=N and stereo=0,
973// channels and bitrate are 1 and N.
974TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecOpusGoodNBitrate0Stereo) {
975 EXPECT_TRUE(SetupEngine());
976 int channel_num = voe_.GetLastChannel();
977 std::vector<cricket::AudioCodec> codecs;
978 codecs.push_back(kOpusCodec);
979 codecs[0].bitrate = 30000;
980 codecs[0].params["stereo"] = "0";
981 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
982 webrtc::CodecInst gcodec;
983 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
984 EXPECT_EQ(1, gcodec.channels);
985 EXPECT_EQ(30000, gcodec.rate);
986 EXPECT_STREQ("opus", gcodec.plname);
987}
988
989// Test that with bitrate=N and without any parameters,
990// channels and bitrate are 1 and N.
991TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecOpusGoodNBitrateNoParameters) {
992 EXPECT_TRUE(SetupEngine());
993 int channel_num = voe_.GetLastChannel();
994 std::vector<cricket::AudioCodec> codecs;
995 codecs.push_back(kOpusCodec);
996 codecs[0].bitrate = 30000;
997 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
998 webrtc::CodecInst gcodec;
999 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1000 EXPECT_EQ(1, gcodec.channels);
1001 EXPECT_EQ(30000, gcodec.rate);
1002 EXPECT_STREQ("opus", gcodec.plname);
1003}
1004
1005// Test that with bitrate=N and stereo=1,
1006// channels and bitrate are 2 and N.
1007TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecOpusGoodNBitrate1Stereo) {
1008 EXPECT_TRUE(SetupEngine());
1009 int channel_num = voe_.GetLastChannel();
1010 std::vector<cricket::AudioCodec> codecs;
1011 codecs.push_back(kOpusCodec);
1012 codecs[0].bitrate = 30000;
1013 codecs[0].params["stereo"] = "1";
1014 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1015 webrtc::CodecInst gcodec;
1016 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1017 EXPECT_EQ(2, gcodec.channels);
1018 EXPECT_EQ(30000, gcodec.rate);
1019 EXPECT_STREQ("opus", gcodec.plname);
1020}
1021
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00001022// Test that bitrate will be overridden by the "maxaveragebitrate" parameter.
1023// Also test that the "maxaveragebitrate" can't be set to values outside the
1024// range of 6000 and 510000
1025TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecOpusMaxAverageBitrate) {
1026 EXPECT_TRUE(SetupEngine());
1027 int channel_num = voe_.GetLastChannel();
1028 std::vector<cricket::AudioCodec> codecs;
1029 codecs.push_back(kOpusCodec);
1030 codecs[0].bitrate = 30000;
1031 webrtc::CodecInst gcodec;
1032
1033 // Ignore if less than 6000.
1034 codecs[0].params["maxaveragebitrate"] = "5999";
1035 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1036 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
buildbot@webrtc.org9d446f22014-10-23 12:22:06 +00001037 EXPECT_EQ(6000, gcodec.rate);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00001038
1039 // Ignore if larger than 510000.
1040 codecs[0].params["maxaveragebitrate"] = "510001";
1041 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1042 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
buildbot@webrtc.org9d446f22014-10-23 12:22:06 +00001043 EXPECT_EQ(510000, gcodec.rate);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00001044
1045 codecs[0].params["maxaveragebitrate"] = "200000";
1046 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1047 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1048 EXPECT_EQ(200000, gcodec.rate);
1049}
1050
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00001051// Test that we can enable NACK with opus as caller.
1052TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecEnableNackAsCaller) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001053 EXPECT_TRUE(SetupEngine());
1054 int channel_num = voe_.GetLastChannel();
1055 std::vector<cricket::AudioCodec> codecs;
1056 codecs.push_back(kOpusCodec);
1057 codecs[0].AddFeedbackParam(cricket::FeedbackParam(cricket::kRtcpFbParamNack,
1058 cricket::kParamValueEmpty));
1059 EXPECT_FALSE(voe_.GetNACK(channel_num));
1060 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1061 EXPECT_TRUE(voe_.GetNACK(channel_num));
1062}
1063
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00001064// Test that we can enable NACK with opus as callee.
1065TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecEnableNackAsCallee) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001066 EXPECT_TRUE(engine_.Init(rtc::Thread::Current()));
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00001067 channel_ = engine_.CreateChannel();
1068 EXPECT_TRUE(channel_ != NULL);
1069
1070 int channel_num = voe_.GetLastChannel();
1071 std::vector<cricket::AudioCodec> codecs;
1072 codecs.push_back(kOpusCodec);
1073 codecs[0].AddFeedbackParam(cricket::FeedbackParam(cricket::kRtcpFbParamNack,
1074 cricket::kParamValueEmpty));
1075 EXPECT_FALSE(voe_.GetNACK(channel_num));
1076 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1077 EXPECT_FALSE(voe_.GetNACK(channel_num));
1078
1079 EXPECT_TRUE(channel_->AddSendStream(
1080 cricket::StreamParams::CreateLegacy(kSsrc1)));
1081 EXPECT_TRUE(voe_.GetNACK(channel_num));
1082}
1083
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001084// Test that we can enable NACK on receive streams.
1085TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecEnableNackRecvStreams) {
1086 EXPECT_TRUE(SetupEngine());
1087 EXPECT_TRUE(channel_->SetOptions(options_conference_));
1088 int channel_num1 = voe_.GetLastChannel();
1089 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(2)));
1090 int channel_num2 = 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_FALSE(voe_.GetNACK(channel_num1));
1096 EXPECT_FALSE(voe_.GetNACK(channel_num2));
1097 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1098 EXPECT_TRUE(voe_.GetNACK(channel_num1));
1099 EXPECT_TRUE(voe_.GetNACK(channel_num2));
1100}
1101
1102// Test that we can disable NACK.
1103TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecDisableNack) {
1104 EXPECT_TRUE(SetupEngine());
1105 int channel_num = voe_.GetLastChannel();
1106 std::vector<cricket::AudioCodec> codecs;
1107 codecs.push_back(kOpusCodec);
1108 codecs[0].AddFeedbackParam(cricket::FeedbackParam(cricket::kRtcpFbParamNack,
1109 cricket::kParamValueEmpty));
1110 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1111 EXPECT_TRUE(voe_.GetNACK(channel_num));
1112
1113 codecs.clear();
1114 codecs.push_back(kOpusCodec);
1115 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1116 EXPECT_FALSE(voe_.GetNACK(channel_num));
1117}
1118
1119// Test that we can disable NACK on receive streams.
1120TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecDisableNackRecvStreams) {
1121 EXPECT_TRUE(SetupEngine());
1122 EXPECT_TRUE(channel_->SetOptions(options_conference_));
1123 int channel_num1 = voe_.GetLastChannel();
1124 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(2)));
1125 int channel_num2 = voe_.GetLastChannel();
1126 std::vector<cricket::AudioCodec> codecs;
1127 codecs.push_back(kOpusCodec);
1128 codecs[0].AddFeedbackParam(cricket::FeedbackParam(cricket::kRtcpFbParamNack,
1129 cricket::kParamValueEmpty));
1130 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1131 EXPECT_TRUE(voe_.GetNACK(channel_num1));
1132 EXPECT_TRUE(voe_.GetNACK(channel_num2));
1133
1134 codecs.clear();
1135 codecs.push_back(kOpusCodec);
1136 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1137 EXPECT_FALSE(voe_.GetNACK(channel_num1));
1138 EXPECT_FALSE(voe_.GetNACK(channel_num2));
1139}
1140
1141// Test that NACK is enabled on a new receive stream.
1142TEST_F(WebRtcVoiceEngineTestFake, AddRecvStreamEnableNack) {
1143 EXPECT_TRUE(SetupEngine());
1144 EXPECT_TRUE(channel_->SetOptions(options_conference_));
1145 int channel_num = voe_.GetLastChannel();
1146 std::vector<cricket::AudioCodec> codecs;
1147 codecs.push_back(kIsacCodec);
1148 codecs[0].AddFeedbackParam(cricket::FeedbackParam(cricket::kRtcpFbParamNack,
1149 cricket::kParamValueEmpty));
1150 codecs.push_back(kCn16000Codec);
1151 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1152 EXPECT_TRUE(voe_.GetNACK(channel_num));
1153
1154 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(2)));
1155 channel_num = voe_.GetLastChannel();
1156 EXPECT_TRUE(voe_.GetNACK(channel_num));
1157 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(3)));
1158 channel_num = voe_.GetLastChannel();
1159 EXPECT_TRUE(voe_.GetNACK(channel_num));
1160}
1161
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +00001162#ifdef USE_WEBRTC_DEV_BRANCH
1163// Test that without useinbandfec, Opus FEC is off.
buildbot@webrtc.orgd27d9ae2014-06-19 01:56:46 +00001164TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecNoOpusFec) {
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +00001165 EXPECT_TRUE(SetupEngine());
1166 int channel_num = voe_.GetLastChannel();
1167 std::vector<cricket::AudioCodec> codecs;
1168 codecs.push_back(kOpusCodec);
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +00001169 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1170 EXPECT_FALSE(voe_.GetCodecFEC(channel_num));
1171}
1172
1173// Test that with useinbandfec=0, Opus FEC is off.
buildbot@webrtc.orgd27d9ae2014-06-19 01:56:46 +00001174TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecOpusDisableFec) {
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +00001175 EXPECT_TRUE(SetupEngine());
1176 int channel_num = voe_.GetLastChannel();
1177 std::vector<cricket::AudioCodec> codecs;
1178 codecs.push_back(kOpusCodec);
1179 codecs[0].bitrate = 0;
1180 codecs[0].params["useinbandfec"] = "0";
1181 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1182 EXPECT_FALSE(voe_.GetCodecFEC(channel_num));
1183 webrtc::CodecInst gcodec;
1184 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1185 EXPECT_STREQ("opus", gcodec.plname);
1186 EXPECT_EQ(1, gcodec.channels);
1187 EXPECT_EQ(32000, gcodec.rate);
1188}
1189
1190// Test that with useinbandfec=1, Opus FEC is on.
buildbot@webrtc.orgd27d9ae2014-06-19 01:56:46 +00001191TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecOpusEnableFec) {
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +00001192 EXPECT_TRUE(SetupEngine());
1193 int channel_num = voe_.GetLastChannel();
1194 std::vector<cricket::AudioCodec> codecs;
1195 codecs.push_back(kOpusCodec);
1196 codecs[0].bitrate = 0;
1197 codecs[0].params["useinbandfec"] = "1";
1198 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1199 EXPECT_TRUE(voe_.GetCodecFEC(channel_num));
1200 webrtc::CodecInst gcodec;
1201 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1202 EXPECT_STREQ("opus", gcodec.plname);
1203 EXPECT_EQ(1, gcodec.channels);
1204 EXPECT_EQ(32000, gcodec.rate);
1205}
1206
1207// Test that with useinbandfec=1, stereo=1, Opus FEC is on.
buildbot@webrtc.orgd27d9ae2014-06-19 01:56:46 +00001208TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecOpusEnableFecStereo) {
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +00001209 EXPECT_TRUE(SetupEngine());
1210 int channel_num = voe_.GetLastChannel();
1211 std::vector<cricket::AudioCodec> codecs;
1212 codecs.push_back(kOpusCodec);
1213 codecs[0].bitrate = 0;
1214 codecs[0].params["stereo"] = "1";
1215 codecs[0].params["useinbandfec"] = "1";
1216 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1217 EXPECT_TRUE(voe_.GetCodecFEC(channel_num));
1218 webrtc::CodecInst gcodec;
1219 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1220 EXPECT_STREQ("opus", gcodec.plname);
1221 EXPECT_EQ(2, gcodec.channels);
1222 EXPECT_EQ(64000, gcodec.rate);
1223}
1224
1225// Test that with non-Opus, codec FEC is off.
buildbot@webrtc.orgd27d9ae2014-06-19 01:56:46 +00001226TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecIsacNoFec) {
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +00001227 EXPECT_TRUE(SetupEngine());
1228 int channel_num = voe_.GetLastChannel();
1229 std::vector<cricket::AudioCodec> codecs;
1230 codecs.push_back(kIsacCodec);
1231 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1232 EXPECT_FALSE(voe_.GetCodecFEC(channel_num));
1233}
buildbot@webrtc.org3ffa1f92014-07-02 19:51:26 +00001234
1235// Test the with non-Opus, even if useinbandfec=1, FEC is off.
1236TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecIsacWithParamNoFec) {
1237 EXPECT_TRUE(SetupEngine());
1238 int channel_num = voe_.GetLastChannel();
1239 std::vector<cricket::AudioCodec> codecs;
1240 codecs.push_back(kIsacCodec);
1241 codecs[0].params["useinbandfec"] = "1";
1242 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1243 EXPECT_FALSE(voe_.GetCodecFEC(channel_num));
1244}
buildbot@webrtc.org5d639b32014-09-10 07:57:12 +00001245
1246// Test that Opus FEC status can be changed.
1247TEST_F(WebRtcVoiceEngineTestFake, ChangeOpusFecStatus) {
1248 EXPECT_TRUE(SetupEngine());
1249 int channel_num = voe_.GetLastChannel();
1250 std::vector<cricket::AudioCodec> codecs;
1251 codecs.push_back(kOpusCodec);
1252 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1253 EXPECT_FALSE(voe_.GetCodecFEC(channel_num));
1254 codecs[0].params["useinbandfec"] = "1";
1255 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1256 EXPECT_TRUE(voe_.GetCodecFEC(channel_num));
1257}
1258
1259// Test maxplaybackrate <= 8000 triggers Opus narrow band mode.
1260TEST_F(WebRtcVoiceEngineTestFake, SetOpusMaxPlaybackRateNb) {
1261 EXPECT_TRUE(SetupEngine());
1262 int channel_num = voe_.GetLastChannel();
1263 std::vector<cricket::AudioCodec> codecs;
1264 codecs.push_back(kOpusCodec);
1265 codecs[0].bitrate = 0;
1266 codecs[0].SetParam(cricket::kCodecParamMaxPlaybackRate, 8000);
1267 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1268 EXPECT_EQ(cricket::kOpusBandwidthNb,
1269 voe_.GetMaxEncodingBandwidth(channel_num));
1270 webrtc::CodecInst gcodec;
1271 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1272 EXPECT_STREQ("opus", gcodec.plname);
minyue@webrtc.org2dc6f312014-10-31 05:33:10 +00001273
1274 EXPECT_EQ(12000, gcodec.rate);
1275 codecs[0].SetParam(cricket::kCodecParamStereo, "1");
1276 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1277 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1278 EXPECT_EQ(24000, gcodec.rate);
buildbot@webrtc.org5d639b32014-09-10 07:57:12 +00001279}
1280
1281// Test 8000 < maxplaybackrate <= 12000 triggers Opus medium band mode.
1282TEST_F(WebRtcVoiceEngineTestFake, SetOpusMaxPlaybackRateMb) {
1283 EXPECT_TRUE(SetupEngine());
1284 int channel_num = voe_.GetLastChannel();
1285 std::vector<cricket::AudioCodec> codecs;
1286 codecs.push_back(kOpusCodec);
1287 codecs[0].bitrate = 0;
1288 codecs[0].SetParam(cricket::kCodecParamMaxPlaybackRate, 8001);
1289 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1290 EXPECT_EQ(cricket::kOpusBandwidthMb,
1291 voe_.GetMaxEncodingBandwidth(channel_num));
1292 webrtc::CodecInst gcodec;
1293 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1294 EXPECT_STREQ("opus", gcodec.plname);
minyue@webrtc.org2dc6f312014-10-31 05:33:10 +00001295
1296 EXPECT_EQ(20000, gcodec.rate);
1297 codecs[0].SetParam(cricket::kCodecParamStereo, "1");
1298 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1299 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1300 EXPECT_EQ(40000, gcodec.rate);
buildbot@webrtc.org5d639b32014-09-10 07:57:12 +00001301}
1302
1303// Test 12000 < maxplaybackrate <= 16000 triggers Opus wide band mode.
1304TEST_F(WebRtcVoiceEngineTestFake, SetOpusMaxPlaybackRateWb) {
1305 EXPECT_TRUE(SetupEngine());
1306 int channel_num = voe_.GetLastChannel();
1307 std::vector<cricket::AudioCodec> codecs;
1308 codecs.push_back(kOpusCodec);
1309 codecs[0].bitrate = 0;
1310 codecs[0].SetParam(cricket::kCodecParamMaxPlaybackRate, 12001);
1311 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1312 EXPECT_EQ(cricket::kOpusBandwidthWb,
1313 voe_.GetMaxEncodingBandwidth(channel_num));
1314 webrtc::CodecInst gcodec;
1315 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1316 EXPECT_STREQ("opus", gcodec.plname);
minyue@webrtc.org2dc6f312014-10-31 05:33:10 +00001317
1318 EXPECT_EQ(20000, gcodec.rate);
1319 codecs[0].SetParam(cricket::kCodecParamStereo, "1");
1320 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1321 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1322 EXPECT_EQ(40000, gcodec.rate);
buildbot@webrtc.org5d639b32014-09-10 07:57:12 +00001323}
1324
1325// Test 16000 < maxplaybackrate <= 24000 triggers Opus super wide band mode.
1326TEST_F(WebRtcVoiceEngineTestFake, SetOpusMaxPlaybackRateSwb) {
1327 EXPECT_TRUE(SetupEngine());
1328 int channel_num = voe_.GetLastChannel();
1329 std::vector<cricket::AudioCodec> codecs;
1330 codecs.push_back(kOpusCodec);
1331 codecs[0].bitrate = 0;
1332 codecs[0].SetParam(cricket::kCodecParamMaxPlaybackRate, 16001);
1333 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1334 EXPECT_EQ(cricket::kOpusBandwidthSwb,
1335 voe_.GetMaxEncodingBandwidth(channel_num));
1336 webrtc::CodecInst gcodec;
1337 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1338 EXPECT_STREQ("opus", gcodec.plname);
minyue@webrtc.org2dc6f312014-10-31 05:33:10 +00001339
buildbot@webrtc.org5d639b32014-09-10 07:57:12 +00001340 EXPECT_EQ(32000, gcodec.rate);
minyue@webrtc.org2dc6f312014-10-31 05:33:10 +00001341 codecs[0].SetParam(cricket::kCodecParamStereo, "1");
1342 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1343 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1344 EXPECT_EQ(64000, gcodec.rate);
buildbot@webrtc.org5d639b32014-09-10 07:57:12 +00001345}
1346
1347// Test 24000 < maxplaybackrate triggers Opus full band mode.
1348TEST_F(WebRtcVoiceEngineTestFake, SetOpusMaxPlaybackRateFb) {
1349 EXPECT_TRUE(SetupEngine());
1350 int channel_num = voe_.GetLastChannel();
1351 std::vector<cricket::AudioCodec> codecs;
1352 codecs.push_back(kOpusCodec);
1353 codecs[0].bitrate = 0;
1354 codecs[0].SetParam(cricket::kCodecParamMaxPlaybackRate, 24001);
1355 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1356 EXPECT_EQ(cricket::kOpusBandwidthFb,
1357 voe_.GetMaxEncodingBandwidth(channel_num));
1358 webrtc::CodecInst gcodec;
1359 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1360 EXPECT_STREQ("opus", gcodec.plname);
minyue@webrtc.org2dc6f312014-10-31 05:33:10 +00001361
buildbot@webrtc.org5d639b32014-09-10 07:57:12 +00001362 EXPECT_EQ(32000, gcodec.rate);
minyue@webrtc.org2dc6f312014-10-31 05:33:10 +00001363 codecs[0].SetParam(cricket::kCodecParamStereo, "1");
1364 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1365 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1366 EXPECT_EQ(64000, gcodec.rate);
buildbot@webrtc.org5d639b32014-09-10 07:57:12 +00001367}
1368
1369// Test Opus that without maxplaybackrate, default playback rate is used.
1370TEST_F(WebRtcVoiceEngineTestFake, DefaultOpusMaxPlaybackRate) {
1371 EXPECT_TRUE(SetupEngine());
1372 int channel_num = voe_.GetLastChannel();
1373 std::vector<cricket::AudioCodec> codecs;
1374 codecs.push_back(kOpusCodec);
1375 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1376 EXPECT_EQ(cricket::kOpusBandwidthFb,
1377 voe_.GetMaxEncodingBandwidth(channel_num));
1378}
1379
1380// Test the with non-Opus, maxplaybackrate has no effect.
1381TEST_F(WebRtcVoiceEngineTestFake, SetNonOpusMaxPlaybackRate) {
1382 EXPECT_TRUE(SetupEngine());
1383 int channel_num = voe_.GetLastChannel();
1384 std::vector<cricket::AudioCodec> codecs;
1385 codecs.push_back(kIsacCodec);
1386 codecs[0].SetParam(cricket::kCodecParamMaxPlaybackRate, 32000);
1387 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1388 EXPECT_EQ(0, voe_.GetMaxEncodingBandwidth(channel_num));
1389}
1390
1391// Test maxplaybackrate can be set on two streams.
1392TEST_F(WebRtcVoiceEngineTestFake, SetOpusMaxPlaybackRateOnTwoStreams) {
1393 EXPECT_TRUE(SetupEngine());
1394 int channel_num = voe_.GetLastChannel();
1395 std::vector<cricket::AudioCodec> codecs;
1396 codecs.push_back(kOpusCodec);
1397 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1398 // Default bandwidth is 24000.
1399 EXPECT_EQ(cricket::kOpusBandwidthFb,
1400 voe_.GetMaxEncodingBandwidth(channel_num));
1401
1402 codecs[0].SetParam(cricket::kCodecParamMaxPlaybackRate, 8000);
1403
1404 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1405 EXPECT_EQ(cricket::kOpusBandwidthNb,
1406 voe_.GetMaxEncodingBandwidth(channel_num));
1407
1408 channel_->AddSendStream(cricket::StreamParams::CreateLegacy(kSsrc2));
1409 channel_num = voe_.GetLastChannel();
1410 EXPECT_EQ(cricket::kOpusBandwidthNb,
1411 voe_.GetMaxEncodingBandwidth(channel_num));
1412}
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +00001413#endif // USE_WEBRTC_DEV_BRANCH
1414
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001415// Test that we can apply CELT with stereo mode but fail with mono mode.
1416TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecsCelt) {
1417 EXPECT_TRUE(SetupEngine());
1418 int channel_num = voe_.GetLastChannel();
1419 std::vector<cricket::AudioCodec> codecs;
1420 codecs.push_back(kCeltCodec);
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00001421 codecs.push_back(kIsacCodec);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001422 codecs[0].id = 96;
1423 codecs[0].channels = 2;
1424 codecs[0].bitrate = 96000;
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00001425 codecs[1].bitrate = 64000;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001426 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1427 webrtc::CodecInst gcodec;
1428 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1429 EXPECT_EQ(96, gcodec.pltype);
1430 EXPECT_EQ(96000, gcodec.rate);
1431 EXPECT_EQ(2, gcodec.channels);
1432 EXPECT_STREQ("CELT", gcodec.plname);
1433 // Doesn't support mono, expect it to fall back to the next codec in the list.
1434 codecs[0].channels = 1;
1435 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1436 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00001437 EXPECT_EQ(103, gcodec.pltype);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001438 EXPECT_EQ(1, gcodec.channels);
1439 EXPECT_EQ(64000, gcodec.rate);
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00001440 EXPECT_STREQ("ISAC", gcodec.plname);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001441}
1442
1443// Test that we can switch back and forth between CELT and ISAC with CN.
1444TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecsIsacCeltSwitching) {
1445 EXPECT_TRUE(SetupEngine());
1446 int channel_num = voe_.GetLastChannel();
1447 std::vector<cricket::AudioCodec> celt_codecs;
1448 celt_codecs.push_back(kCeltCodec);
1449 EXPECT_TRUE(channel_->SetSendCodecs(celt_codecs));
1450 webrtc::CodecInst gcodec;
1451 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1452 EXPECT_EQ(110, gcodec.pltype);
1453 EXPECT_STREQ("CELT", gcodec.plname);
1454
1455 std::vector<cricket::AudioCodec> isac_codecs;
1456 isac_codecs.push_back(kIsacCodec);
1457 isac_codecs.push_back(kCn16000Codec);
1458 isac_codecs.push_back(kCeltCodec);
1459 EXPECT_TRUE(channel_->SetSendCodecs(isac_codecs));
1460 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1461 EXPECT_EQ(103, gcodec.pltype);
1462 EXPECT_STREQ("ISAC", gcodec.plname);
1463
1464 EXPECT_TRUE(channel_->SetSendCodecs(celt_codecs));
1465 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1466 EXPECT_EQ(110, gcodec.pltype);
1467 EXPECT_STREQ("CELT", gcodec.plname);
1468}
1469
1470// Test that we handle various ways of specifying bitrate.
1471TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecsBitrate) {
1472 EXPECT_TRUE(SetupEngine());
1473 int channel_num = voe_.GetLastChannel();
1474 std::vector<cricket::AudioCodec> codecs;
1475 codecs.push_back(kIsacCodec); // bitrate == 32000
1476 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1477 webrtc::CodecInst gcodec;
1478 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1479 EXPECT_EQ(103, gcodec.pltype);
1480 EXPECT_STREQ("ISAC", gcodec.plname);
1481 EXPECT_EQ(32000, gcodec.rate);
1482
1483 codecs[0].bitrate = 0; // bitrate == default
1484 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1485 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1486 EXPECT_EQ(103, gcodec.pltype);
1487 EXPECT_STREQ("ISAC", gcodec.plname);
1488 EXPECT_EQ(-1, gcodec.rate);
1489
1490 codecs[0].bitrate = 28000; // bitrate == 28000
1491 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1492 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1493 EXPECT_EQ(103, gcodec.pltype);
1494 EXPECT_STREQ("ISAC", gcodec.plname);
1495 EXPECT_EQ(28000, gcodec.rate);
1496
1497 codecs[0] = kPcmuCodec; // bitrate == 64000
1498 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1499 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1500 EXPECT_EQ(0, gcodec.pltype);
1501 EXPECT_STREQ("PCMU", gcodec.plname);
1502 EXPECT_EQ(64000, gcodec.rate);
1503
1504 codecs[0].bitrate = 0; // bitrate == default
1505 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1506 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1507 EXPECT_EQ(0, gcodec.pltype);
1508 EXPECT_STREQ("PCMU", gcodec.plname);
1509 EXPECT_EQ(64000, gcodec.rate);
1510
1511 codecs[0] = kOpusCodec;
1512 codecs[0].bitrate = 0; // bitrate == default
1513 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1514 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1515 EXPECT_EQ(111, gcodec.pltype);
1516 EXPECT_STREQ("opus", gcodec.plname);
1517 EXPECT_EQ(32000, gcodec.rate);
1518}
1519
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00001520// Test that we fail if no codecs are specified.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001521TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecsNoCodecs) {
1522 EXPECT_TRUE(SetupEngine());
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00001523 std::vector<cricket::AudioCodec> codecs;
1524 EXPECT_FALSE(channel_->SetSendCodecs(codecs));
1525}
1526
1527// Test that we can set send codecs even with telephone-event codec as the first
1528// one on the list.
1529TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecsDTMFOnTop) {
1530 EXPECT_TRUE(SetupEngine());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001531 int channel_num = voe_.GetLastChannel();
1532 std::vector<cricket::AudioCodec> codecs;
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00001533 codecs.push_back(kTelephoneEventCodec);
1534 codecs.push_back(kIsacCodec);
1535 codecs.push_back(kPcmuCodec);
1536 codecs[0].id = 98; // DTMF
1537 codecs[1].id = 96;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001538 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1539 webrtc::CodecInst gcodec;
1540 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00001541 EXPECT_EQ(96, gcodec.pltype);
1542 EXPECT_STREQ("ISAC", gcodec.plname);
1543 EXPECT_EQ(98, voe_.GetSendTelephoneEventPayloadType(channel_num));
1544}
1545
1546// Test that we can set send codecs even with CN codec as the first
1547// one on the list.
1548TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecsCNOnTop) {
1549 EXPECT_TRUE(SetupEngine());
1550 int channel_num = voe_.GetLastChannel();
1551 std::vector<cricket::AudioCodec> codecs;
1552 codecs.push_back(kCn16000Codec);
1553 codecs.push_back(kIsacCodec);
1554 codecs.push_back(kPcmuCodec);
1555 codecs[0].id = 98; // wideband CN
1556 codecs[1].id = 96;
1557 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1558 webrtc::CodecInst gcodec;
1559 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1560 EXPECT_EQ(96, gcodec.pltype);
1561 EXPECT_STREQ("ISAC", gcodec.plname);
1562 EXPECT_EQ(98, voe_.GetSendCNPayloadType(channel_num, true));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001563}
1564
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00001565// Test that we set VAD and DTMF types correctly as caller.
1566TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecsCNandDTMFAsCaller) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001567 EXPECT_TRUE(SetupEngine());
1568 int channel_num = voe_.GetLastChannel();
1569 std::vector<cricket::AudioCodec> codecs;
1570 codecs.push_back(kIsacCodec);
1571 codecs.push_back(kPcmuCodec);
1572 // TODO(juberti): cn 32000
1573 codecs.push_back(kCn16000Codec);
1574 codecs.push_back(kCn8000Codec);
1575 codecs.push_back(kTelephoneEventCodec);
1576 codecs.push_back(kRedCodec);
1577 codecs[0].id = 96;
1578 codecs[2].id = 97; // wideband CN
1579 codecs[4].id = 98; // DTMF
1580 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1581 webrtc::CodecInst gcodec;
1582 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1583 EXPECT_EQ(96, gcodec.pltype);
1584 EXPECT_STREQ("ISAC", gcodec.plname);
1585 EXPECT_TRUE(voe_.GetVAD(channel_num));
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +00001586 EXPECT_FALSE(voe_.GetRED(channel_num));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001587 EXPECT_EQ(13, voe_.GetSendCNPayloadType(channel_num, false));
1588 EXPECT_EQ(97, voe_.GetSendCNPayloadType(channel_num, true));
1589 EXPECT_EQ(98, voe_.GetSendTelephoneEventPayloadType(channel_num));
1590}
1591
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00001592// Test that we set VAD and DTMF types correctly as callee.
1593TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecsCNandDTMFAsCallee) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001594 EXPECT_TRUE(engine_.Init(rtc::Thread::Current()));
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00001595 channel_ = engine_.CreateChannel();
1596 EXPECT_TRUE(channel_ != NULL);
1597
1598 int channel_num = voe_.GetLastChannel();
1599 std::vector<cricket::AudioCodec> codecs;
1600 codecs.push_back(kIsacCodec);
1601 codecs.push_back(kPcmuCodec);
1602 // TODO(juberti): cn 32000
1603 codecs.push_back(kCn16000Codec);
1604 codecs.push_back(kCn8000Codec);
1605 codecs.push_back(kTelephoneEventCodec);
1606 codecs.push_back(kRedCodec);
1607 codecs[0].id = 96;
1608 codecs[2].id = 97; // wideband CN
1609 codecs[4].id = 98; // DTMF
1610 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1611 EXPECT_TRUE(channel_->AddSendStream(
1612 cricket::StreamParams::CreateLegacy(kSsrc1)));
1613
1614 webrtc::CodecInst gcodec;
1615 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1616 EXPECT_EQ(96, gcodec.pltype);
1617 EXPECT_STREQ("ISAC", gcodec.plname);
1618 EXPECT_TRUE(voe_.GetVAD(channel_num));
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +00001619 EXPECT_FALSE(voe_.GetRED(channel_num));
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00001620 EXPECT_EQ(13, voe_.GetSendCNPayloadType(channel_num, false));
1621 EXPECT_EQ(97, voe_.GetSendCNPayloadType(channel_num, true));
1622 EXPECT_EQ(98, voe_.GetSendTelephoneEventPayloadType(channel_num));
1623}
1624
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001625// Test that we only apply VAD if we have a CN codec that matches the
1626// send codec clockrate.
1627TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecsCNNoMatch) {
1628 EXPECT_TRUE(SetupEngine());
1629 int channel_num = voe_.GetLastChannel();
1630 std::vector<cricket::AudioCodec> codecs;
1631 // Set ISAC(16K) and CN(16K). VAD should be activated.
1632 codecs.push_back(kIsacCodec);
1633 codecs.push_back(kCn16000Codec);
1634 codecs[1].id = 97;
1635 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1636 webrtc::CodecInst gcodec;
1637 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1638 EXPECT_STREQ("ISAC", gcodec.plname);
1639 EXPECT_TRUE(voe_.GetVAD(channel_num));
1640 EXPECT_EQ(97, voe_.GetSendCNPayloadType(channel_num, true));
1641 // Set PCMU(8K) and CN(16K). VAD should not be activated.
1642 codecs[0] = kPcmuCodec;
1643 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1644 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1645 EXPECT_STREQ("PCMU", gcodec.plname);
1646 EXPECT_FALSE(voe_.GetVAD(channel_num));
1647 // Set PCMU(8K) and CN(8K). VAD should be activated.
1648 codecs[1] = kCn8000Codec;
1649 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1650 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1651 EXPECT_STREQ("PCMU", gcodec.plname);
1652 EXPECT_TRUE(voe_.GetVAD(channel_num));
1653 EXPECT_EQ(13, voe_.GetSendCNPayloadType(channel_num, false));
1654 // Set ISAC(16K) and CN(8K). VAD should not be activated.
1655 codecs[0] = kIsacCodec;
1656 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1657 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1658 EXPECT_STREQ("ISAC", gcodec.plname);
1659 EXPECT_FALSE(voe_.GetVAD(channel_num));
1660}
1661
1662// Test that we perform case-insensitive matching of codec names.
1663TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecsCaseInsensitive) {
1664 EXPECT_TRUE(SetupEngine());
1665 int channel_num = voe_.GetLastChannel();
1666 std::vector<cricket::AudioCodec> codecs;
1667 codecs.push_back(kIsacCodec);
1668 codecs.push_back(kPcmuCodec);
1669 codecs.push_back(kCn16000Codec);
1670 codecs.push_back(kCn8000Codec);
1671 codecs.push_back(kTelephoneEventCodec);
1672 codecs.push_back(kRedCodec);
1673 codecs[0].name = "iSaC";
1674 codecs[0].id = 96;
1675 codecs[2].id = 97; // wideband CN
1676 codecs[4].id = 98; // DTMF
1677 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1678 webrtc::CodecInst gcodec;
1679 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1680 EXPECT_EQ(96, gcodec.pltype);
1681 EXPECT_STREQ("ISAC", gcodec.plname);
1682 EXPECT_TRUE(voe_.GetVAD(channel_num));
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +00001683 EXPECT_FALSE(voe_.GetRED(channel_num));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001684 EXPECT_EQ(13, voe_.GetSendCNPayloadType(channel_num, false));
1685 EXPECT_EQ(97, voe_.GetSendCNPayloadType(channel_num, true));
1686 EXPECT_EQ(98, voe_.GetSendTelephoneEventPayloadType(channel_num));
1687}
1688
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +00001689// Test that we set up RED correctly as caller.
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00001690TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecsREDAsCaller) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001691 EXPECT_TRUE(SetupEngine());
1692 int channel_num = voe_.GetLastChannel();
1693 std::vector<cricket::AudioCodec> codecs;
1694 codecs.push_back(kRedCodec);
1695 codecs.push_back(kIsacCodec);
1696 codecs.push_back(kPcmuCodec);
1697 codecs[0].id = 127;
1698 codecs[0].params[""] = "96/96";
1699 codecs[1].id = 96;
1700 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1701 webrtc::CodecInst gcodec;
1702 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1703 EXPECT_EQ(96, gcodec.pltype);
1704 EXPECT_STREQ("ISAC", gcodec.plname);
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +00001705 EXPECT_TRUE(voe_.GetRED(channel_num));
1706 EXPECT_EQ(127, voe_.GetSendREDPayloadType(channel_num));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001707}
1708
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +00001709// Test that we set up RED correctly as callee.
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00001710TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecsREDAsCallee) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001711 EXPECT_TRUE(engine_.Init(rtc::Thread::Current()));
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00001712 channel_ = engine_.CreateChannel();
1713 EXPECT_TRUE(channel_ != NULL);
1714
1715 int channel_num = voe_.GetLastChannel();
1716 std::vector<cricket::AudioCodec> codecs;
1717 codecs.push_back(kRedCodec);
1718 codecs.push_back(kIsacCodec);
1719 codecs.push_back(kPcmuCodec);
1720 codecs[0].id = 127;
1721 codecs[0].params[""] = "96/96";
1722 codecs[1].id = 96;
1723 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1724 EXPECT_TRUE(channel_->AddSendStream(
1725 cricket::StreamParams::CreateLegacy(kSsrc1)));
1726 webrtc::CodecInst gcodec;
1727 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1728 EXPECT_EQ(96, gcodec.pltype);
1729 EXPECT_STREQ("ISAC", gcodec.plname);
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +00001730 EXPECT_TRUE(voe_.GetRED(channel_num));
1731 EXPECT_EQ(127, voe_.GetSendREDPayloadType(channel_num));
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00001732}
1733
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +00001734// Test that we set up RED correctly if params are omitted.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001735TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecsREDNoParams) {
1736 EXPECT_TRUE(SetupEngine());
1737 int channel_num = voe_.GetLastChannel();
1738 std::vector<cricket::AudioCodec> codecs;
1739 codecs.push_back(kRedCodec);
1740 codecs.push_back(kIsacCodec);
1741 codecs.push_back(kPcmuCodec);
1742 codecs[0].id = 127;
1743 codecs[1].id = 96;
1744 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1745 webrtc::CodecInst gcodec;
1746 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1747 EXPECT_EQ(96, gcodec.pltype);
1748 EXPECT_STREQ("ISAC", gcodec.plname);
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +00001749 EXPECT_TRUE(voe_.GetRED(channel_num));
1750 EXPECT_EQ(127, voe_.GetSendREDPayloadType(channel_num));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001751}
1752
1753// Test that we ignore RED if the parameters aren't named the way we expect.
1754TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecsBadRED1) {
1755 EXPECT_TRUE(SetupEngine());
1756 int channel_num = voe_.GetLastChannel();
1757 std::vector<cricket::AudioCodec> codecs;
1758 codecs.push_back(kRedCodec);
1759 codecs.push_back(kIsacCodec);
1760 codecs.push_back(kPcmuCodec);
1761 codecs[0].id = 127;
1762 codecs[0].params["ABC"] = "96/96";
1763 codecs[1].id = 96;
1764 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1765 webrtc::CodecInst gcodec;
1766 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1767 EXPECT_EQ(96, gcodec.pltype);
1768 EXPECT_STREQ("ISAC", gcodec.plname);
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +00001769 EXPECT_FALSE(voe_.GetRED(channel_num));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001770}
1771
1772// Test that we ignore RED if it uses different primary/secondary encoding.
1773TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecsBadRED2) {
1774 EXPECT_TRUE(SetupEngine());
1775 int channel_num = voe_.GetLastChannel();
1776 std::vector<cricket::AudioCodec> codecs;
1777 codecs.push_back(kRedCodec);
1778 codecs.push_back(kIsacCodec);
1779 codecs.push_back(kPcmuCodec);
1780 codecs[0].id = 127;
1781 codecs[0].params[""] = "96/0";
1782 codecs[1].id = 96;
1783 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1784 webrtc::CodecInst gcodec;
1785 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1786 EXPECT_EQ(96, gcodec.pltype);
1787 EXPECT_STREQ("ISAC", gcodec.plname);
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +00001788 EXPECT_FALSE(voe_.GetRED(channel_num));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001789}
1790
1791// Test that we ignore RED if it uses more than 2 encodings.
1792TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecsBadRED3) {
1793 EXPECT_TRUE(SetupEngine());
1794 int channel_num = voe_.GetLastChannel();
1795 std::vector<cricket::AudioCodec> codecs;
1796 codecs.push_back(kRedCodec);
1797 codecs.push_back(kIsacCodec);
1798 codecs.push_back(kPcmuCodec);
1799 codecs[0].id = 127;
1800 codecs[0].params[""] = "96/96/96";
1801 codecs[1].id = 96;
1802 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1803 webrtc::CodecInst gcodec;
1804 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1805 EXPECT_EQ(96, gcodec.pltype);
1806 EXPECT_STREQ("ISAC", gcodec.plname);
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +00001807 EXPECT_FALSE(voe_.GetRED(channel_num));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001808}
1809
1810// Test that we ignore RED if it has bogus codec ids.
1811TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecsBadRED4) {
1812 EXPECT_TRUE(SetupEngine());
1813 int channel_num = voe_.GetLastChannel();
1814 std::vector<cricket::AudioCodec> codecs;
1815 codecs.push_back(kRedCodec);
1816 codecs.push_back(kIsacCodec);
1817 codecs.push_back(kPcmuCodec);
1818 codecs[0].id = 127;
1819 codecs[0].params[""] = "ABC/ABC";
1820 codecs[1].id = 96;
1821 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1822 webrtc::CodecInst gcodec;
1823 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1824 EXPECT_EQ(96, gcodec.pltype);
1825 EXPECT_STREQ("ISAC", gcodec.plname);
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +00001826 EXPECT_FALSE(voe_.GetRED(channel_num));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001827}
1828
1829// Test that we ignore RED if it refers to a codec that is not present.
1830TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecsBadRED5) {
1831 EXPECT_TRUE(SetupEngine());
1832 int channel_num = voe_.GetLastChannel();
1833 std::vector<cricket::AudioCodec> codecs;
1834 codecs.push_back(kRedCodec);
1835 codecs.push_back(kIsacCodec);
1836 codecs.push_back(kPcmuCodec);
1837 codecs[0].id = 127;
1838 codecs[0].params[""] = "97/97";
1839 codecs[1].id = 96;
1840 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1841 webrtc::CodecInst gcodec;
1842 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1843 EXPECT_EQ(96, gcodec.pltype);
1844 EXPECT_STREQ("ISAC", gcodec.plname);
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +00001845 EXPECT_FALSE(voe_.GetRED(channel_num));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001846}
1847
buildbot@webrtc.org150835e2014-05-06 15:54:38 +00001848// Test support for audio level header extension.
1849TEST_F(WebRtcVoiceEngineTestFake, SendAudioLevelHeaderExtensions) {
1850 TestSetSendRtpHeaderExtensions(kRtpAudioLevelHeaderExtension);
henrike@webrtc.org79047f92014-03-06 23:46:59 +00001851}
buildbot@webrtc.org150835e2014-05-06 15:54:38 +00001852TEST_F(WebRtcVoiceEngineTestFake, RecvAudioLevelHeaderExtensions) {
1853 TestSetRecvRtpHeaderExtensions(kRtpAudioLevelHeaderExtension);
1854}
henrike@webrtc.org79047f92014-03-06 23:46:59 +00001855
buildbot@webrtc.org150835e2014-05-06 15:54:38 +00001856// Test support for absolute send time header extension.
1857TEST_F(WebRtcVoiceEngineTestFake, SendAbsoluteSendTimeHeaderExtensions) {
1858 TestSetSendRtpHeaderExtensions(kRtpAbsoluteSenderTimeHeaderExtension);
1859}
1860TEST_F(WebRtcVoiceEngineTestFake, RecvAbsoluteSendTimeHeaderExtensions) {
1861 TestSetRecvRtpHeaderExtensions(kRtpAbsoluteSenderTimeHeaderExtension);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001862}
1863
1864// Test that we can create a channel and start sending/playing out on it.
1865TEST_F(WebRtcVoiceEngineTestFake, SendAndPlayout) {
1866 EXPECT_TRUE(SetupEngine());
1867 int channel_num = voe_.GetLastChannel();
1868 std::vector<cricket::AudioCodec> codecs;
1869 codecs.push_back(kPcmuCodec);
1870 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1871 EXPECT_TRUE(channel_->SetSend(cricket::SEND_MICROPHONE));
1872 EXPECT_TRUE(voe_.GetSend(channel_num));
1873 EXPECT_TRUE(channel_->SetPlayout(true));
1874 EXPECT_TRUE(voe_.GetPlayout(channel_num));
1875 EXPECT_TRUE(channel_->SetSend(cricket::SEND_NOTHING));
1876 EXPECT_FALSE(voe_.GetSend(channel_num));
1877 EXPECT_TRUE(channel_->SetPlayout(false));
1878 EXPECT_FALSE(voe_.GetPlayout(channel_num));
1879}
1880
wu@webrtc.org9dba5252013-08-05 20:36:57 +00001881// Test that we can add and remove send streams.
1882TEST_F(WebRtcVoiceEngineTestFake, CreateAndDeleteMultipleSendStreams) {
1883 SetupForMultiSendStream();
1884
1885 static const uint32 kSsrcs4[] = {1, 2, 3, 4};
1886
1887 // Set the global state for sending.
1888 EXPECT_TRUE(channel_->SetSend(cricket::SEND_MICROPHONE));
1889
1890 for (unsigned int i = 0; i < ARRAY_SIZE(kSsrcs4); ++i) {
1891 EXPECT_TRUE(channel_->AddSendStream(
1892 cricket::StreamParams::CreateLegacy(kSsrcs4[i])));
1893
1894 // Verify that we are in a sending state for all the created streams.
1895 int channel_num = voe_.GetChannelFromLocalSsrc(kSsrcs4[i]);
1896 EXPECT_TRUE(voe_.GetSend(channel_num));
1897 }
1898
1899 // Remove the first send channel, which is the default channel. It will only
1900 // recycle the default channel but not delete it.
1901 EXPECT_TRUE(channel_->RemoveSendStream(kSsrcs4[0]));
1902 // Stream should already be Removed from the send stream list.
1903 EXPECT_FALSE(channel_->RemoveSendStream(kSsrcs4[0]));
1904 // But the default still exists.
1905 EXPECT_EQ(0, voe_.GetChannelFromLocalSsrc(kSsrcs4[0]));
1906
1907 // Delete the rest of send channel streams.
1908 for (unsigned int i = 1; i < ARRAY_SIZE(kSsrcs4); ++i) {
1909 EXPECT_TRUE(channel_->RemoveSendStream(kSsrcs4[i]));
1910 // Stream should already be deleted.
1911 EXPECT_FALSE(channel_->RemoveSendStream(kSsrcs4[i]));
1912 EXPECT_EQ(-1, voe_.GetChannelFromLocalSsrc(kSsrcs4[i]));
1913 }
1914}
1915
1916// Test SetSendCodecs correctly configure the codecs in all send streams.
1917TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecsWithMultipleSendStreams) {
1918 SetupForMultiSendStream();
1919
1920 static const uint32 kSsrcs4[] = {1, 2, 3, 4};
1921 // Create send streams.
1922 for (unsigned int i = 0; i < ARRAY_SIZE(kSsrcs4); ++i) {
1923 EXPECT_TRUE(channel_->AddSendStream(
1924 cricket::StreamParams::CreateLegacy(kSsrcs4[i])));
1925 }
1926
1927 std::vector<cricket::AudioCodec> codecs;
1928 // Set ISAC(16K) and CN(16K). VAD should be activated.
1929 codecs.push_back(kIsacCodec);
1930 codecs.push_back(kCn16000Codec);
1931 codecs[1].id = 97;
1932 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1933
1934 // Verify ISAC and VAD are corrected configured on all send channels.
1935 webrtc::CodecInst gcodec;
1936 for (unsigned int i = 0; i < ARRAY_SIZE(kSsrcs4); ++i) {
1937 int channel_num = voe_.GetChannelFromLocalSsrc(kSsrcs4[i]);
1938 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1939 EXPECT_STREQ("ISAC", gcodec.plname);
1940 EXPECT_TRUE(voe_.GetVAD(channel_num));
1941 EXPECT_EQ(97, voe_.GetSendCNPayloadType(channel_num, true));
1942 }
1943
1944 // Change to PCMU(8K) and CN(16K). VAD should not be activated.
1945 codecs[0] = kPcmuCodec;
1946 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1947 for (unsigned int i = 0; i < ARRAY_SIZE(kSsrcs4); ++i) {
1948 int channel_num = voe_.GetChannelFromLocalSsrc(kSsrcs4[i]);
1949 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1950 EXPECT_STREQ("PCMU", gcodec.plname);
1951 EXPECT_FALSE(voe_.GetVAD(channel_num));
1952 }
1953}
1954
1955// Test we can SetSend on all send streams correctly.
1956TEST_F(WebRtcVoiceEngineTestFake, SetSendWithMultipleSendStreams) {
1957 SetupForMultiSendStream();
1958
1959 static const uint32 kSsrcs4[] = {1, 2, 3, 4};
1960 // Create the send channels and they should be a SEND_NOTHING date.
1961 for (unsigned int i = 0; i < ARRAY_SIZE(kSsrcs4); ++i) {
1962 EXPECT_TRUE(channel_->AddSendStream(
1963 cricket::StreamParams::CreateLegacy(kSsrcs4[i])));
1964 int channel_num = voe_.GetLastChannel();
1965 EXPECT_FALSE(voe_.GetSend(channel_num));
1966 }
1967
1968 // Set the global state for starting sending.
1969 EXPECT_TRUE(channel_->SetSend(cricket::SEND_MICROPHONE));
1970 for (unsigned int i = 0; i < ARRAY_SIZE(kSsrcs4); ++i) {
1971 // Verify that we are in a sending state for all the send streams.
1972 int channel_num = voe_.GetChannelFromLocalSsrc(kSsrcs4[i]);
1973 EXPECT_TRUE(voe_.GetSend(channel_num));
1974 }
1975
1976 // Set the global state for stopping sending.
1977 EXPECT_TRUE(channel_->SetSend(cricket::SEND_NOTHING));
1978 for (unsigned int i = 1; i < ARRAY_SIZE(kSsrcs4); ++i) {
1979 // Verify that we are in a stop state for all the send streams.
1980 int channel_num = voe_.GetChannelFromLocalSsrc(kSsrcs4[i]);
1981 EXPECT_FALSE(voe_.GetSend(channel_num));
1982 }
1983}
1984
1985// Test we can set the correct statistics on all send streams.
1986TEST_F(WebRtcVoiceEngineTestFake, GetStatsWithMultipleSendStreams) {
1987 SetupForMultiSendStream();
1988
1989 static const uint32 kSsrcs4[] = {1, 2, 3, 4};
1990 // Create send streams.
1991 for (unsigned int i = 0; i < ARRAY_SIZE(kSsrcs4); ++i) {
1992 EXPECT_TRUE(channel_->AddSendStream(
1993 cricket::StreamParams::CreateLegacy(kSsrcs4[i])));
1994 }
buildbot@webrtc.org7e71b772014-06-13 01:14:01 +00001995 // Create a receive stream to check that none of the send streams end up in
1996 // the receive stream stats.
1997 EXPECT_TRUE(channel_->AddRecvStream(
1998 cricket::StreamParams::CreateLegacy(kSsrc2)));
wu@webrtc.org9dba5252013-08-05 20:36:57 +00001999 // We need send codec to be set to get all stats.
2000 std::vector<cricket::AudioCodec> codecs;
2001 codecs.push_back(kPcmuCodec);
2002 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
buildbot@webrtc.org7e71b772014-06-13 01:14:01 +00002003 EXPECT_TRUE(channel_->SetRecvCodecs(codecs));
wu@webrtc.org9dba5252013-08-05 20:36:57 +00002004
2005 cricket::VoiceMediaInfo info;
2006 EXPECT_EQ(true, channel_->GetStats(&info));
2007 EXPECT_EQ(static_cast<size_t>(ARRAY_SIZE(kSsrcs4)), info.senders.size());
2008
2009 // Verify the statistic information is correct.
2010 for (unsigned int i = 0; i < ARRAY_SIZE(kSsrcs4); ++i) {
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +00002011 EXPECT_EQ(kSsrcs4[i], info.senders[i].ssrc());
wu@webrtc.org9dba5252013-08-05 20:36:57 +00002012 EXPECT_EQ(kPcmuCodec.name, info.senders[i].codec_name);
2013 EXPECT_EQ(cricket::kIntStatValue, info.senders[i].bytes_sent);
2014 EXPECT_EQ(cricket::kIntStatValue, info.senders[i].packets_sent);
2015 EXPECT_EQ(cricket::kIntStatValue, info.senders[i].packets_lost);
2016 EXPECT_EQ(cricket::kFractionLostStatValue, info.senders[i].fraction_lost);
2017 EXPECT_EQ(cricket::kIntStatValue, info.senders[i].ext_seqnum);
2018 EXPECT_EQ(cricket::kIntStatValue, info.senders[i].rtt_ms);
2019 EXPECT_EQ(cricket::kIntStatValue, info.senders[i].jitter_ms);
buildbot@webrtc.org7e71b772014-06-13 01:14:01 +00002020 EXPECT_EQ(kPcmuCodec.name, info.senders[i].codec_name);
wu@webrtc.org9dba5252013-08-05 20:36:57 +00002021 }
2022
buildbot@webrtc.org7e71b772014-06-13 01:14:01 +00002023 EXPECT_EQ(0u, info.receivers.size());
2024 DeliverPacket(kPcmuFrame, sizeof(kPcmuFrame));
2025 EXPECT_EQ(true, channel_->GetStats(&info));
2026
wu@webrtc.org9dba5252013-08-05 20:36:57 +00002027 EXPECT_EQ(1u, info.receivers.size());
buildbot@webrtc.org7e71b772014-06-13 01:14:01 +00002028 EXPECT_EQ(cricket::kIntStatValue, info.receivers[0].bytes_rcvd);
2029 EXPECT_EQ(cricket::kIntStatValue, info.receivers[0].packets_rcvd);
2030 EXPECT_EQ(cricket::kIntStatValue, info.receivers[0].packets_lost);
2031 EXPECT_EQ(cricket::kIntStatValue, info.receivers[0].ext_seqnum);
2032 EXPECT_EQ(kPcmuCodec.name, info.receivers[0].codec_name);
wu@webrtc.org9dba5252013-08-05 20:36:57 +00002033}
2034
wu@webrtc.org9dba5252013-08-05 20:36:57 +00002035// Test that we can add and remove receive streams, and do proper send/playout.
2036// We can receive on multiple streams while sending one stream.
2037TEST_F(WebRtcVoiceEngineTestFake, PlayoutWithMultipleStreams) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002038 EXPECT_TRUE(SetupEngine());
2039 int channel_num1 = voe_.GetLastChannel();
2040
2041 // Start playout on the default channel.
2042 EXPECT_TRUE(channel_->SetOptions(options_conference_));
2043 EXPECT_TRUE(channel_->SetPlayout(true));
2044 EXPECT_TRUE(voe_.GetPlayout(channel_num1));
2045
2046 // Adding another stream should disable playout on the default channel.
2047 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(2)));
2048 int channel_num2 = voe_.GetLastChannel();
2049 std::vector<cricket::AudioCodec> codecs;
2050 codecs.push_back(kPcmuCodec);
2051 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
2052 EXPECT_TRUE(channel_->SetSend(cricket::SEND_MICROPHONE));
2053 EXPECT_TRUE(voe_.GetSend(channel_num1));
2054 EXPECT_FALSE(voe_.GetSend(channel_num2));
2055
2056 // Make sure only the new channel is played out.
2057 EXPECT_FALSE(voe_.GetPlayout(channel_num1));
2058 EXPECT_TRUE(voe_.GetPlayout(channel_num2));
2059
2060 // Adding yet another stream should have stream 2 and 3 enabled for playout.
2061 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(3)));
2062 int channel_num3 = voe_.GetLastChannel();
2063 EXPECT_FALSE(voe_.GetPlayout(channel_num1));
2064 EXPECT_TRUE(voe_.GetPlayout(channel_num2));
2065 EXPECT_TRUE(voe_.GetPlayout(channel_num3));
2066 EXPECT_FALSE(voe_.GetSend(channel_num3));
2067
2068 // Stop sending.
2069 EXPECT_TRUE(channel_->SetSend(cricket::SEND_NOTHING));
2070 EXPECT_FALSE(voe_.GetSend(channel_num1));
2071 EXPECT_FALSE(voe_.GetSend(channel_num2));
2072 EXPECT_FALSE(voe_.GetSend(channel_num3));
2073
2074 // Stop playout.
2075 EXPECT_TRUE(channel_->SetPlayout(false));
2076 EXPECT_FALSE(voe_.GetPlayout(channel_num1));
2077 EXPECT_FALSE(voe_.GetPlayout(channel_num2));
2078 EXPECT_FALSE(voe_.GetPlayout(channel_num3));
2079
2080 // Restart playout and make sure the default channel still is not played out.
2081 EXPECT_TRUE(channel_->SetPlayout(true));
2082 EXPECT_FALSE(voe_.GetPlayout(channel_num1));
2083 EXPECT_TRUE(voe_.GetPlayout(channel_num2));
2084 EXPECT_TRUE(voe_.GetPlayout(channel_num3));
2085
2086 // Now remove the new streams and verify that the default channel is
2087 // played out again.
2088 EXPECT_TRUE(channel_->RemoveRecvStream(3));
2089 EXPECT_TRUE(channel_->RemoveRecvStream(2));
2090
2091 EXPECT_TRUE(voe_.GetPlayout(channel_num1));
2092}
2093
2094// Test that we can set the devices to use.
2095TEST_F(WebRtcVoiceEngineTestFake, SetDevices) {
2096 EXPECT_TRUE(SetupEngine());
2097 int channel_num = voe_.GetLastChannel();
2098 std::vector<cricket::AudioCodec> codecs;
2099 codecs.push_back(kPcmuCodec);
2100 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
2101
2102 cricket::Device default_dev(cricket::kFakeDefaultDeviceName,
2103 cricket::kFakeDefaultDeviceId);
2104 cricket::Device dev(cricket::kFakeDeviceName,
2105 cricket::kFakeDeviceId);
2106
2107 // Test SetDevices() while not sending or playing.
2108 EXPECT_TRUE(engine_.SetDevices(&default_dev, &default_dev));
2109
2110 // Test SetDevices() while sending and playing.
2111 EXPECT_TRUE(engine_.SetLocalMonitor(true));
2112 EXPECT_TRUE(channel_->SetSend(cricket::SEND_MICROPHONE));
2113 EXPECT_TRUE(channel_->SetPlayout(true));
2114 EXPECT_TRUE(voe_.GetRecordingMicrophone());
2115 EXPECT_TRUE(voe_.GetSend(channel_num));
2116 EXPECT_TRUE(voe_.GetPlayout(channel_num));
2117
2118 EXPECT_TRUE(engine_.SetDevices(&dev, &dev));
2119
2120 EXPECT_TRUE(voe_.GetRecordingMicrophone());
2121 EXPECT_TRUE(voe_.GetSend(channel_num));
2122 EXPECT_TRUE(voe_.GetPlayout(channel_num));
2123
2124 // Test that failure to open newly selected devices does not prevent opening
2125 // ones after that.
2126 voe_.set_fail_start_recording_microphone(true);
2127 voe_.set_playout_fail_channel(channel_num);
2128 voe_.set_send_fail_channel(channel_num);
2129
2130 EXPECT_FALSE(engine_.SetDevices(&default_dev, &default_dev));
2131
2132 EXPECT_FALSE(voe_.GetRecordingMicrophone());
2133 EXPECT_FALSE(voe_.GetSend(channel_num));
2134 EXPECT_FALSE(voe_.GetPlayout(channel_num));
2135
2136 voe_.set_fail_start_recording_microphone(false);
2137 voe_.set_playout_fail_channel(-1);
2138 voe_.set_send_fail_channel(-1);
2139
2140 EXPECT_TRUE(engine_.SetDevices(&dev, &dev));
2141
2142 EXPECT_TRUE(voe_.GetRecordingMicrophone());
2143 EXPECT_TRUE(voe_.GetSend(channel_num));
2144 EXPECT_TRUE(voe_.GetPlayout(channel_num));
2145}
2146
2147// Test that we can set the devices to use even if we failed to
2148// open the initial ones.
2149TEST_F(WebRtcVoiceEngineTestFake, SetDevicesWithInitiallyBadDevices) {
2150 EXPECT_TRUE(SetupEngine());
2151 int channel_num = voe_.GetLastChannel();
2152 std::vector<cricket::AudioCodec> codecs;
2153 codecs.push_back(kPcmuCodec);
2154 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
2155
2156 cricket::Device default_dev(cricket::kFakeDefaultDeviceName,
2157 cricket::kFakeDefaultDeviceId);
2158 cricket::Device dev(cricket::kFakeDeviceName,
2159 cricket::kFakeDeviceId);
2160
2161 // Test that failure to open devices selected before starting
2162 // send/play does not prevent opening newly selected ones after that.
2163 voe_.set_fail_start_recording_microphone(true);
2164 voe_.set_playout_fail_channel(channel_num);
2165 voe_.set_send_fail_channel(channel_num);
2166
2167 EXPECT_TRUE(engine_.SetDevices(&default_dev, &default_dev));
2168
2169 EXPECT_FALSE(engine_.SetLocalMonitor(true));
2170 EXPECT_FALSE(channel_->SetSend(cricket::SEND_MICROPHONE));
2171 EXPECT_FALSE(channel_->SetPlayout(true));
2172 EXPECT_FALSE(voe_.GetRecordingMicrophone());
2173 EXPECT_FALSE(voe_.GetSend(channel_num));
2174 EXPECT_FALSE(voe_.GetPlayout(channel_num));
2175
2176 voe_.set_fail_start_recording_microphone(false);
2177 voe_.set_playout_fail_channel(-1);
2178 voe_.set_send_fail_channel(-1);
2179
2180 EXPECT_TRUE(engine_.SetDevices(&dev, &dev));
2181
2182 EXPECT_TRUE(voe_.GetRecordingMicrophone());
2183 EXPECT_TRUE(voe_.GetSend(channel_num));
2184 EXPECT_TRUE(voe_.GetPlayout(channel_num));
2185}
2186
2187// Test that we can create a channel configured for multi-point conferences,
2188// and start sending/playing out on it.
2189TEST_F(WebRtcVoiceEngineTestFake, ConferenceSendAndPlayout) {
2190 EXPECT_TRUE(SetupEngine());
2191 int channel_num = voe_.GetLastChannel();
2192 EXPECT_TRUE(channel_->SetOptions(options_conference_));
2193 std::vector<cricket::AudioCodec> codecs;
2194 codecs.push_back(kPcmuCodec);
2195 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
2196 EXPECT_TRUE(channel_->SetSend(cricket::SEND_MICROPHONE));
2197 EXPECT_TRUE(voe_.GetSend(channel_num));
2198}
2199
2200// Test that we can create a channel configured for Codian bridges,
2201// and start sending/playing out on it.
2202TEST_F(WebRtcVoiceEngineTestFake, CodianSendAndPlayout) {
2203 EXPECT_TRUE(SetupEngine());
2204 int channel_num = voe_.GetLastChannel();
2205 webrtc::AgcConfig agc_config;
2206 EXPECT_EQ(0, voe_.GetAgcConfig(agc_config));
2207 EXPECT_EQ(0, agc_config.targetLeveldBOv);
2208 EXPECT_TRUE(channel_->SetOptions(options_adjust_agc_));
2209 std::vector<cricket::AudioCodec> codecs;
2210 codecs.push_back(kPcmuCodec);
2211 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
2212 EXPECT_TRUE(channel_->SetSend(cricket::SEND_MICROPHONE));
2213 EXPECT_TRUE(voe_.GetSend(channel_num));
2214 EXPECT_EQ(0, voe_.GetAgcConfig(agc_config));
2215 EXPECT_EQ(agc_config.targetLeveldBOv, 10); // level was attenuated
2216 EXPECT_TRUE(channel_->SetPlayout(true));
2217 EXPECT_TRUE(voe_.GetPlayout(channel_num));
2218 EXPECT_TRUE(channel_->SetSend(cricket::SEND_NOTHING));
2219 EXPECT_FALSE(voe_.GetSend(channel_num));
2220 EXPECT_EQ(0, voe_.GetAgcConfig(agc_config));
2221 EXPECT_EQ(0, agc_config.targetLeveldBOv); // level was restored
2222 EXPECT_TRUE(channel_->SetPlayout(false));
2223 EXPECT_FALSE(voe_.GetPlayout(channel_num));
2224}
2225
wu@webrtc.org97077a32013-10-25 21:18:33 +00002226TEST_F(WebRtcVoiceEngineTestFake, TxAgcConfigViaOptions) {
2227 EXPECT_TRUE(SetupEngine());
2228 webrtc::AgcConfig agc_config;
2229 EXPECT_EQ(0, voe_.GetAgcConfig(agc_config));
2230 EXPECT_EQ(0, agc_config.targetLeveldBOv);
2231
2232 cricket::AudioOptions options;
2233 options.tx_agc_target_dbov.Set(3);
2234 options.tx_agc_digital_compression_gain.Set(9);
2235 options.tx_agc_limiter.Set(true);
2236 options.auto_gain_control.Set(true);
2237 EXPECT_TRUE(engine_.SetOptions(options));
2238
2239 EXPECT_EQ(0, voe_.GetAgcConfig(agc_config));
2240 EXPECT_EQ(3, agc_config.targetLeveldBOv);
2241 EXPECT_EQ(9, agc_config.digitalCompressionGaindB);
2242 EXPECT_TRUE(agc_config.limiterEnable);
2243
2244 // Check interaction with adjust_agc_delta. Both should be respected, for
2245 // backwards compatibility.
2246 options.adjust_agc_delta.Set(-10);
2247 EXPECT_TRUE(engine_.SetOptions(options));
2248
2249 EXPECT_EQ(0, voe_.GetAgcConfig(agc_config));
2250 EXPECT_EQ(13, agc_config.targetLeveldBOv);
2251}
2252
2253TEST_F(WebRtcVoiceEngineTestFake, RxAgcConfigViaOptions) {
2254 EXPECT_TRUE(SetupEngine());
2255 int channel_num = voe_.GetLastChannel();
2256 cricket::AudioOptions options;
2257 options.rx_agc_target_dbov.Set(6);
2258 options.rx_agc_digital_compression_gain.Set(0);
2259 options.rx_agc_limiter.Set(true);
2260 options.rx_auto_gain_control.Set(true);
2261 EXPECT_TRUE(channel_->SetOptions(options));
2262
2263 webrtc::AgcConfig agc_config;
2264 EXPECT_EQ(0, engine_.voe()->processing()->GetRxAgcConfig(
2265 channel_num, agc_config));
2266 EXPECT_EQ(6, agc_config.targetLeveldBOv);
2267 EXPECT_EQ(0, agc_config.digitalCompressionGaindB);
2268 EXPECT_TRUE(agc_config.limiterEnable);
2269}
2270
2271TEST_F(WebRtcVoiceEngineTestFake, SampleRatesViaOptions) {
2272 EXPECT_TRUE(SetupEngine());
2273 cricket::AudioOptions options;
2274 options.recording_sample_rate.Set(48000u);
2275 options.playout_sample_rate.Set(44100u);
2276 EXPECT_TRUE(engine_.SetOptions(options));
2277
2278 unsigned int recording_sample_rate, playout_sample_rate;
2279 EXPECT_EQ(0, voe_.RecordingSampleRate(&recording_sample_rate));
2280 EXPECT_EQ(0, voe_.PlayoutSampleRate(&playout_sample_rate));
2281 EXPECT_EQ(48000u, recording_sample_rate);
2282 EXPECT_EQ(44100u, playout_sample_rate);
2283}
2284
2285TEST_F(WebRtcVoiceEngineTestFake, TraceFilterViaTraceOptions) {
2286 EXPECT_TRUE(SetupEngine());
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002287 engine_.SetLogging(rtc::LS_INFO, "");
wu@webrtc.org97077a32013-10-25 21:18:33 +00002288 EXPECT_EQ(
2289 // Info:
2290 webrtc::kTraceStateInfo | webrtc::kTraceInfo |
2291 // Warning:
2292 webrtc::kTraceTerseInfo | webrtc::kTraceWarning |
2293 // Error:
2294 webrtc::kTraceError | webrtc::kTraceCritical,
2295 static_cast<int>(trace_wrapper_->filter_));
2296 // Now set it explicitly
2297 std::string filter =
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002298 "tracefilter " + rtc::ToString(webrtc::kTraceDefault);
2299 engine_.SetLogging(rtc::LS_VERBOSE, filter.c_str());
wu@webrtc.org97077a32013-10-25 21:18:33 +00002300 EXPECT_EQ(static_cast<unsigned int>(webrtc::kTraceDefault),
2301 trace_wrapper_->filter_);
2302}
2303
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002304// Test that we can set the outgoing SSRC properly.
2305// SSRC is set in SetupEngine by calling AddSendStream.
2306TEST_F(WebRtcVoiceEngineTestFake, SetSendSsrc) {
2307 EXPECT_TRUE(SetupEngine());
2308 int channel_num = voe_.GetLastChannel();
2309 unsigned int send_ssrc;
2310 EXPECT_EQ(0, voe_.GetLocalSSRC(channel_num, send_ssrc));
2311 EXPECT_NE(0U, send_ssrc);
2312 EXPECT_EQ(0, voe_.GetLocalSSRC(channel_num, send_ssrc));
2313 EXPECT_EQ(kSsrc1, send_ssrc);
2314}
2315
2316TEST_F(WebRtcVoiceEngineTestFake, GetStats) {
2317 // Setup. We need send codec to be set to get all stats.
2318 EXPECT_TRUE(SetupEngine());
buildbot@webrtc.org7e71b772014-06-13 01:14:01 +00002319 // SetupEngine adds a send stream with kSsrc1, so the receive stream has to
2320 // use a different SSRC.
2321 EXPECT_TRUE(channel_->AddRecvStream(
2322 cricket::StreamParams::CreateLegacy(kSsrc2)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002323 std::vector<cricket::AudioCodec> codecs;
2324 codecs.push_back(kPcmuCodec);
2325 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
buildbot@webrtc.org7e71b772014-06-13 01:14:01 +00002326 EXPECT_TRUE(channel_->SetRecvCodecs(codecs));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002327
2328 cricket::VoiceMediaInfo info;
2329 EXPECT_EQ(true, channel_->GetStats(&info));
2330 EXPECT_EQ(1u, info.senders.size());
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +00002331 EXPECT_EQ(kSsrc1, info.senders[0].ssrc());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002332 EXPECT_EQ(kPcmuCodec.name, info.senders[0].codec_name);
2333 EXPECT_EQ(cricket::kIntStatValue, info.senders[0].bytes_sent);
2334 EXPECT_EQ(cricket::kIntStatValue, info.senders[0].packets_sent);
2335 EXPECT_EQ(cricket::kIntStatValue, info.senders[0].packets_lost);
2336 EXPECT_EQ(cricket::kFractionLostStatValue, info.senders[0].fraction_lost);
2337 EXPECT_EQ(cricket::kIntStatValue, info.senders[0].ext_seqnum);
2338 EXPECT_EQ(cricket::kIntStatValue, info.senders[0].rtt_ms);
2339 EXPECT_EQ(cricket::kIntStatValue, info.senders[0].jitter_ms);
buildbot@webrtc.org7e71b772014-06-13 01:14:01 +00002340 EXPECT_EQ(kPcmuCodec.name, info.senders[0].codec_name);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002341 // TODO(sriniv): Add testing for more fields. These are not populated
2342 // in FakeWebrtcVoiceEngine yet.
2343 // EXPECT_EQ(cricket::kIntStatValue, info.senders[0].audio_level);
2344 // EXPECT_EQ(cricket::kIntStatValue, info.senders[0].echo_delay_median_ms);
2345 // EXPECT_EQ(cricket::kIntStatValue, info.senders[0].echo_delay_std_ms);
2346 // EXPECT_EQ(cricket::kIntStatValue, info.senders[0].echo_return_loss);
2347 // EXPECT_EQ(cricket::kIntStatValue,
2348 // info.senders[0].echo_return_loss_enhancement);
2349
buildbot@webrtc.org7e71b772014-06-13 01:14:01 +00002350 EXPECT_EQ(0u, info.receivers.size());
2351 DeliverPacket(kPcmuFrame, sizeof(kPcmuFrame));
2352 EXPECT_EQ(true, channel_->GetStats(&info));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002353 EXPECT_EQ(1u, info.receivers.size());
buildbot@webrtc.org7e71b772014-06-13 01:14:01 +00002354
2355 EXPECT_EQ(cricket::kIntStatValue, info.receivers[0].bytes_rcvd);
2356 EXPECT_EQ(cricket::kIntStatValue, info.receivers[0].packets_rcvd);
2357 EXPECT_EQ(cricket::kIntStatValue, info.receivers[0].packets_lost);
2358 EXPECT_EQ(cricket::kIntStatValue, info.receivers[0].ext_seqnum);
2359 EXPECT_EQ(kPcmuCodec.name, info.receivers[0].codec_name);
2360 // TODO(sriniv): Add testing for more receiver fields.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002361}
2362
2363// Test that we can set the outgoing SSRC properly with multiple streams.
2364// SSRC is set in SetupEngine by calling AddSendStream.
2365TEST_F(WebRtcVoiceEngineTestFake, SetSendSsrcWithMultipleStreams) {
2366 EXPECT_TRUE(SetupEngine());
2367 EXPECT_TRUE(channel_->SetOptions(options_conference_));
2368 int channel_num1 = voe_.GetLastChannel();
2369 unsigned int send_ssrc;
2370 EXPECT_EQ(0, voe_.GetLocalSSRC(channel_num1, send_ssrc));
2371 EXPECT_EQ(kSsrc1, send_ssrc);
2372
2373 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(2)));
2374 int channel_num2 = voe_.GetLastChannel();
2375 EXPECT_EQ(0, voe_.GetLocalSSRC(channel_num2, send_ssrc));
2376 EXPECT_EQ(kSsrc1, send_ssrc);
2377}
2378
2379// Test that the local SSRC is the same on sending and receiving channels if the
2380// receive channel is created before the send channel.
2381TEST_F(WebRtcVoiceEngineTestFake, SetSendSsrcAfterCreatingReceiveChannel) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002382 EXPECT_TRUE(engine_.Init(rtc::Thread::Current()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002383 channel_ = engine_.CreateChannel();
2384 EXPECT_TRUE(channel_->SetOptions(options_conference_));
2385
2386 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(1)));
2387 int receive_channel_num = voe_.GetLastChannel();
2388 EXPECT_TRUE(channel_->AddSendStream(
2389 cricket::StreamParams::CreateLegacy(1234)));
2390 int send_channel_num = voe_.GetLastChannel();
2391
2392 unsigned int ssrc = 0;
2393 EXPECT_EQ(0, voe_.GetLocalSSRC(send_channel_num, ssrc));
2394 EXPECT_EQ(1234U, ssrc);
2395 ssrc = 0;
2396 EXPECT_EQ(0, voe_.GetLocalSSRC(receive_channel_num, ssrc));
2397 EXPECT_EQ(1234U, ssrc);
2398}
2399
2400// Test that we can properly receive packets.
2401TEST_F(WebRtcVoiceEngineTestFake, Recv) {
2402 EXPECT_TRUE(SetupEngine());
2403 int channel_num = voe_.GetLastChannel();
2404 DeliverPacket(kPcmuFrame, sizeof(kPcmuFrame));
2405 EXPECT_TRUE(voe_.CheckPacket(channel_num, kPcmuFrame,
2406 sizeof(kPcmuFrame)));
2407}
2408
2409// Test that we can properly receive packets on multiple streams.
2410TEST_F(WebRtcVoiceEngineTestFake, RecvWithMultipleStreams) {
2411 EXPECT_TRUE(SetupEngine());
2412 EXPECT_TRUE(channel_->SetOptions(options_conference_));
2413 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(1)));
2414 int channel_num1 = voe_.GetLastChannel();
2415 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(2)));
2416 int channel_num2 = voe_.GetLastChannel();
2417 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(3)));
2418 int channel_num3 = voe_.GetLastChannel();
2419 // Create packets with the right SSRCs.
2420 char packets[4][sizeof(kPcmuFrame)];
2421 for (size_t i = 0; i < ARRAY_SIZE(packets); ++i) {
2422 memcpy(packets[i], kPcmuFrame, sizeof(kPcmuFrame));
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002423 rtc::SetBE32(packets[i] + 8, static_cast<uint32>(i));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002424 }
2425 EXPECT_TRUE(voe_.CheckNoPacket(channel_num1));
2426 EXPECT_TRUE(voe_.CheckNoPacket(channel_num2));
2427 EXPECT_TRUE(voe_.CheckNoPacket(channel_num3));
2428 DeliverPacket(packets[0], sizeof(packets[0]));
2429 EXPECT_TRUE(voe_.CheckNoPacket(channel_num1));
2430 EXPECT_TRUE(voe_.CheckNoPacket(channel_num2));
2431 EXPECT_TRUE(voe_.CheckNoPacket(channel_num3));
2432 DeliverPacket(packets[1], sizeof(packets[1]));
2433 EXPECT_TRUE(voe_.CheckPacket(channel_num1, packets[1],
2434 sizeof(packets[1])));
2435 EXPECT_TRUE(voe_.CheckNoPacket(channel_num2));
2436 EXPECT_TRUE(voe_.CheckNoPacket(channel_num3));
2437 DeliverPacket(packets[2], sizeof(packets[2]));
2438 EXPECT_TRUE(voe_.CheckNoPacket(channel_num1));
2439 EXPECT_TRUE(voe_.CheckPacket(channel_num2, packets[2],
2440 sizeof(packets[2])));
2441 EXPECT_TRUE(voe_.CheckNoPacket(channel_num3));
2442 DeliverPacket(packets[3], sizeof(packets[3]));
2443 EXPECT_TRUE(voe_.CheckNoPacket(channel_num1));
2444 EXPECT_TRUE(voe_.CheckNoPacket(channel_num2));
2445 EXPECT_TRUE(voe_.CheckPacket(channel_num3, packets[3],
2446 sizeof(packets[3])));
2447 EXPECT_TRUE(channel_->RemoveRecvStream(3));
2448 EXPECT_TRUE(channel_->RemoveRecvStream(2));
2449 EXPECT_TRUE(channel_->RemoveRecvStream(1));
2450}
2451
2452// Test that we properly handle failures to add a stream.
2453TEST_F(WebRtcVoiceEngineTestFake, AddStreamFail) {
2454 EXPECT_TRUE(SetupEngine());
2455 voe_.set_fail_create_channel(true);
2456 EXPECT_TRUE(channel_->SetOptions(options_conference_));
2457 EXPECT_FALSE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(2)));
2458
2459 // In 1:1 call, we should not try to create a new channel.
2460 cricket::AudioOptions options_no_conference_;
2461 options_no_conference_.conference_mode.Set(false);
2462 EXPECT_TRUE(channel_->SetOptions(options_no_conference_));
2463 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(2)));
2464}
2465
2466// Test that AddRecvStream doesn't create new channel for 1:1 call.
2467TEST_F(WebRtcVoiceEngineTestFake, AddRecvStream1On1) {
2468 EXPECT_TRUE(SetupEngine());
2469 int channel_num = voe_.GetLastChannel();
2470 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(1)));
2471 EXPECT_EQ(channel_num, voe_.GetLastChannel());
2472}
2473
2474// Test that after adding a recv stream, we do not decode more codecs than
2475// those previously passed into SetRecvCodecs.
2476TEST_F(WebRtcVoiceEngineTestFake, AddRecvStreamUnsupportedCodec) {
2477 EXPECT_TRUE(SetupEngine());
2478 EXPECT_TRUE(channel_->SetOptions(options_conference_));
2479 std::vector<cricket::AudioCodec> codecs;
2480 codecs.push_back(kIsacCodec);
2481 codecs.push_back(kPcmuCodec);
2482 EXPECT_TRUE(channel_->SetRecvCodecs(codecs));
2483 EXPECT_TRUE(channel_->AddRecvStream(
2484 cricket::StreamParams::CreateLegacy(kSsrc1)));
2485 int channel_num2 = voe_.GetLastChannel();
2486 webrtc::CodecInst gcodec;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002487 rtc::strcpyn(gcodec.plname, ARRAY_SIZE(gcodec.plname), "CELT");
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002488 gcodec.plfreq = 32000;
2489 gcodec.channels = 2;
2490 EXPECT_EQ(-1, voe_.GetRecPayloadType(channel_num2, gcodec));
2491}
2492
2493// Test that we properly clean up any streams that were added, even if
2494// not explicitly removed.
2495TEST_F(WebRtcVoiceEngineTestFake, StreamCleanup) {
2496 EXPECT_TRUE(SetupEngine());
2497 EXPECT_TRUE(channel_->SetOptions(options_conference_));
2498 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(1)));
2499 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(2)));
2500 EXPECT_EQ(3, voe_.GetNumChannels()); // default channel + 2 added
2501 delete channel_;
2502 channel_ = NULL;
2503 EXPECT_EQ(0, voe_.GetNumChannels());
2504}
2505
wu@webrtc.org78187522013-10-07 23:32:02 +00002506TEST_F(WebRtcVoiceEngineTestFake, TestAddRecvStreamFailWithZeroSsrc) {
2507 EXPECT_TRUE(SetupEngine());
2508 EXPECT_FALSE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(0)));
2509}
2510
2511TEST_F(WebRtcVoiceEngineTestFake, TestNoLeakingWhenAddRecvStreamFail) {
2512 EXPECT_TRUE(SetupEngine());
2513 // Stream 1 reuses default channel.
2514 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(1)));
2515 // Manually delete default channel to simulate a failure.
2516 int default_channel = voe_.GetLastChannel();
2517 EXPECT_EQ(0, voe_.DeleteChannel(default_channel));
2518 // Add recv stream 2 should fail because default channel is gone.
2519 EXPECT_FALSE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(2)));
2520 int new_channel = voe_.GetLastChannel();
2521 EXPECT_NE(default_channel, new_channel);
2522 // The last created channel should have already been deleted.
2523 EXPECT_EQ(-1, voe_.DeleteChannel(new_channel));
2524}
2525
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002526// Test the InsertDtmf on default send stream as caller.
2527TEST_F(WebRtcVoiceEngineTestFake, InsertDtmfOnDefaultSendStreamAsCaller) {
2528 TestInsertDtmf(0, true);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002529}
2530
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002531// Test the InsertDtmf on default send stream as callee
2532TEST_F(WebRtcVoiceEngineTestFake, InsertDtmfOnDefaultSendStreamAsCallee) {
2533 TestInsertDtmf(0, false);
2534}
2535
2536// Test the InsertDtmf on specified send stream as caller.
2537TEST_F(WebRtcVoiceEngineTestFake, InsertDtmfOnSendStreamAsCaller) {
2538 TestInsertDtmf(kSsrc1, true);
2539}
2540
2541// Test the InsertDtmf on specified send stream as callee.
2542TEST_F(WebRtcVoiceEngineTestFake, InsertDtmfOnSendStreamAsCallee) {
2543 TestInsertDtmf(kSsrc1, false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002544}
2545
2546// Test that we can play a ringback tone properly in a single-stream call.
2547TEST_F(WebRtcVoiceEngineTestFake, PlayRingback) {
2548 EXPECT_TRUE(SetupEngine());
2549 int channel_num = voe_.GetLastChannel();
2550 EXPECT_EQ(0, voe_.IsPlayingFileLocally(channel_num));
2551 // Check we fail if no ringback tone specified.
2552 EXPECT_FALSE(channel_->PlayRingbackTone(0, true, true));
2553 EXPECT_EQ(0, voe_.IsPlayingFileLocally(channel_num));
2554 // Check we can set and play a ringback tone.
wu@webrtc.org9caf2762013-12-11 18:25:07 +00002555 EXPECT_TRUE(channel_->SetRingbackTone(
2556 kRingbackTone, static_cast<int>(strlen(kRingbackTone))));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002557 EXPECT_TRUE(channel_->PlayRingbackTone(0, true, true));
2558 EXPECT_EQ(1, voe_.IsPlayingFileLocally(channel_num));
2559 // Check we can stop the tone manually.
2560 EXPECT_TRUE(channel_->PlayRingbackTone(0, false, false));
2561 EXPECT_EQ(0, voe_.IsPlayingFileLocally(channel_num));
2562 // Check we stop the tone if a packet arrives.
2563 EXPECT_TRUE(channel_->PlayRingbackTone(0, true, true));
2564 EXPECT_EQ(1, voe_.IsPlayingFileLocally(channel_num));
2565 DeliverPacket(kPcmuFrame, sizeof(kPcmuFrame));
2566 EXPECT_EQ(0, voe_.IsPlayingFileLocally(channel_num));
2567}
2568
2569// Test that we can play a ringback tone properly in a multi-stream call.
2570TEST_F(WebRtcVoiceEngineTestFake, PlayRingbackWithMultipleStreams) {
2571 EXPECT_TRUE(SetupEngine());
2572 EXPECT_TRUE(channel_->SetOptions(options_conference_));
2573 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(1)));
2574 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(2)));
2575 int channel_num = voe_.GetLastChannel();
2576 EXPECT_EQ(0, voe_.IsPlayingFileLocally(channel_num));
2577 // Check we fail if no ringback tone specified.
2578 EXPECT_FALSE(channel_->PlayRingbackTone(2, true, true));
2579 EXPECT_EQ(0, voe_.IsPlayingFileLocally(channel_num));
2580 // Check we can set and play a ringback tone on the correct ssrc.
wu@webrtc.org9caf2762013-12-11 18:25:07 +00002581 EXPECT_TRUE(channel_->SetRingbackTone(
2582 kRingbackTone, static_cast<int>(strlen(kRingbackTone))));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002583 EXPECT_FALSE(channel_->PlayRingbackTone(77, true, true));
2584 EXPECT_TRUE(channel_->PlayRingbackTone(2, true, true));
2585 EXPECT_EQ(1, voe_.IsPlayingFileLocally(channel_num));
2586 // Check we can stop the tone manually.
2587 EXPECT_TRUE(channel_->PlayRingbackTone(2, false, false));
2588 EXPECT_EQ(0, voe_.IsPlayingFileLocally(channel_num));
2589 // Check we stop the tone if a packet arrives, but only with the right SSRC.
2590 EXPECT_TRUE(channel_->PlayRingbackTone(2, true, true));
2591 EXPECT_EQ(1, voe_.IsPlayingFileLocally(channel_num));
2592 // Send a packet with SSRC 1; the tone should not stop.
2593 DeliverPacket(kPcmuFrame, sizeof(kPcmuFrame));
2594 EXPECT_EQ(1, voe_.IsPlayingFileLocally(channel_num));
2595 // Send a packet with SSRC 2; the tone should stop.
2596 char packet[sizeof(kPcmuFrame)];
2597 memcpy(packet, kPcmuFrame, sizeof(kPcmuFrame));
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002598 rtc::SetBE32(packet + 8, 2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002599 DeliverPacket(packet, sizeof(packet));
2600 EXPECT_EQ(0, voe_.IsPlayingFileLocally(channel_num));
2601}
2602
2603// Tests creating soundclips, and make sure they come from the right engine.
2604TEST_F(WebRtcVoiceEngineTestFake, CreateSoundclip) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002605 EXPECT_TRUE(engine_.Init(rtc::Thread::Current()));
wu@webrtc.org4551b792013-10-09 15:37:36 +00002606 EXPECT_FALSE(voe_sc_.IsInited());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002607 soundclip_ = engine_.CreateSoundclip();
wu@webrtc.org4551b792013-10-09 15:37:36 +00002608 EXPECT_TRUE(voe_sc_.IsInited());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002609 ASSERT_TRUE(soundclip_ != NULL);
2610 EXPECT_EQ(0, voe_.GetNumChannels());
2611 EXPECT_EQ(1, voe_sc_.GetNumChannels());
2612 int channel_num = voe_sc_.GetLastChannel();
2613 EXPECT_TRUE(voe_sc_.GetPlayout(channel_num));
2614 delete soundclip_;
2615 soundclip_ = NULL;
2616 EXPECT_EQ(0, voe_sc_.GetNumChannels());
wu@webrtc.org4551b792013-10-09 15:37:36 +00002617 // Make sure the soundclip engine is uninitialized on shutdown, now that
2618 // we've initialized it by creating a soundclip.
2619 engine_.Terminate();
2620 EXPECT_FALSE(voe_sc_.IsInited());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002621}
2622
2623// Tests playing out a fake sound.
2624TEST_F(WebRtcVoiceEngineTestFake, PlaySoundclip) {
2625 static const char kZeroes[16000] = {};
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002626 EXPECT_TRUE(engine_.Init(rtc::Thread::Current()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002627 soundclip_ = engine_.CreateSoundclip();
2628 ASSERT_TRUE(soundclip_ != NULL);
2629 EXPECT_TRUE(soundclip_->PlaySound(kZeroes, sizeof(kZeroes), 0));
2630}
2631
2632TEST_F(WebRtcVoiceEngineTestFake, MediaEngineCallbackOnError) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002633 rtc::scoped_ptr<ChannelErrorListener> listener;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002634 cricket::WebRtcVoiceMediaChannel* media_channel;
2635 unsigned int ssrc = 0;
2636
2637 EXPECT_TRUE(SetupEngine());
2638 EXPECT_TRUE(channel_->SetOptions(options_conference_));
2639 EXPECT_TRUE(channel_->SetSend(cricket::SEND_MICROPHONE));
2640
2641 media_channel = static_cast<cricket::WebRtcVoiceMediaChannel*>(channel_);
2642 listener.reset(new ChannelErrorListener(channel_));
2643
2644 // Test on WebRtc VoE channel.
2645 voe_.TriggerCallbackOnError(media_channel->voe_channel(),
2646 VE_SATURATION_WARNING);
2647 EXPECT_EQ(cricket::VoiceMediaChannel::ERROR_REC_DEVICE_SATURATION,
2648 listener->error());
2649 EXPECT_NE(-1, voe_.GetLocalSSRC(voe_.GetLastChannel(), ssrc));
2650 EXPECT_EQ(ssrc, listener->ssrc());
2651
2652 listener->Reset();
2653 voe_.TriggerCallbackOnError(-1, VE_TYPING_NOISE_WARNING);
2654 EXPECT_EQ(cricket::VoiceMediaChannel::ERROR_REC_TYPING_NOISE_DETECTED,
2655 listener->error());
2656 EXPECT_EQ(0U, listener->ssrc());
2657
2658 // Add another stream and test on that.
2659 ++ssrc;
2660 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(
2661 ssrc)));
2662 listener->Reset();
2663 voe_.TriggerCallbackOnError(voe_.GetLastChannel(),
2664 VE_SATURATION_WARNING);
2665 EXPECT_EQ(cricket::VoiceMediaChannel::ERROR_REC_DEVICE_SATURATION,
2666 listener->error());
2667 EXPECT_EQ(ssrc, listener->ssrc());
2668
2669 // Testing a non-existing channel.
2670 listener->Reset();
2671 voe_.TriggerCallbackOnError(voe_.GetLastChannel() + 2,
2672 VE_SATURATION_WARNING);
2673 EXPECT_EQ(0, listener->error());
2674}
2675
2676TEST_F(WebRtcVoiceEngineTestFake, TestSetPlayoutError) {
2677 EXPECT_TRUE(SetupEngine());
2678 EXPECT_TRUE(channel_->SetOptions(options_conference_));
2679 std::vector<cricket::AudioCodec> codecs;
2680 codecs.push_back(kPcmuCodec);
2681 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
2682 EXPECT_TRUE(channel_->SetSend(cricket::SEND_MICROPHONE));
2683 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(2)));
2684 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(3)));
2685 EXPECT_TRUE(channel_->SetPlayout(true));
2686 voe_.set_playout_fail_channel(voe_.GetLastChannel() - 1);
2687 EXPECT_TRUE(channel_->SetPlayout(false));
2688 EXPECT_FALSE(channel_->SetPlayout(true));
2689}
2690
2691// Test that the Registering/Unregistering with the
2692// webrtcvoiceengine works as expected
2693TEST_F(WebRtcVoiceEngineTestFake, RegisterVoiceProcessor) {
2694 EXPECT_TRUE(SetupEngine());
2695 EXPECT_TRUE(channel_->SetOptions(options_conference_));
2696 EXPECT_TRUE(channel_->AddRecvStream(
2697 cricket::StreamParams::CreateLegacy(kSsrc2)));
2698 cricket::FakeMediaProcessor vp_1;
2699 cricket::FakeMediaProcessor vp_2;
2700
2701 EXPECT_FALSE(engine_.RegisterProcessor(kSsrc2, &vp_1, cricket::MPD_TX));
2702 EXPECT_TRUE(engine_.RegisterProcessor(kSsrc2, &vp_1, cricket::MPD_RX));
2703 EXPECT_TRUE(engine_.RegisterProcessor(kSsrc2, &vp_2, cricket::MPD_RX));
2704 voe_.TriggerProcessPacket(cricket::MPD_RX);
2705 voe_.TriggerProcessPacket(cricket::MPD_TX);
2706
2707 EXPECT_TRUE(voe_.IsExternalMediaProcessorRegistered());
2708 EXPECT_EQ(1, vp_1.voice_frame_count());
2709 EXPECT_EQ(1, vp_2.voice_frame_count());
2710
2711 EXPECT_TRUE(engine_.UnregisterProcessor(kSsrc2,
2712 &vp_2,
2713 cricket::MPD_RX));
2714 voe_.TriggerProcessPacket(cricket::MPD_RX);
2715 EXPECT_TRUE(voe_.IsExternalMediaProcessorRegistered());
2716 EXPECT_EQ(1, vp_2.voice_frame_count());
2717 EXPECT_EQ(2, vp_1.voice_frame_count());
2718
2719 EXPECT_TRUE(engine_.UnregisterProcessor(kSsrc2,
2720 &vp_1,
2721 cricket::MPD_RX));
2722 voe_.TriggerProcessPacket(cricket::MPD_RX);
2723 EXPECT_FALSE(voe_.IsExternalMediaProcessorRegistered());
2724 EXPECT_EQ(2, vp_1.voice_frame_count());
2725
2726 EXPECT_FALSE(engine_.RegisterProcessor(kSsrc1, &vp_1, cricket::MPD_RX));
2727 EXPECT_TRUE(engine_.RegisterProcessor(kSsrc1, &vp_1, cricket::MPD_TX));
2728 voe_.TriggerProcessPacket(cricket::MPD_RX);
2729 voe_.TriggerProcessPacket(cricket::MPD_TX);
2730 EXPECT_TRUE(voe_.IsExternalMediaProcessorRegistered());
2731 EXPECT_EQ(3, vp_1.voice_frame_count());
2732
2733 EXPECT_TRUE(engine_.UnregisterProcessor(kSsrc1,
2734 &vp_1,
2735 cricket::MPD_RX_AND_TX));
2736 voe_.TriggerProcessPacket(cricket::MPD_TX);
2737 EXPECT_FALSE(voe_.IsExternalMediaProcessorRegistered());
2738 EXPECT_EQ(3, vp_1.voice_frame_count());
2739 EXPECT_TRUE(channel_->RemoveRecvStream(kSsrc2));
2740 EXPECT_FALSE(engine_.RegisterProcessor(kSsrc2, &vp_1, cricket::MPD_RX));
2741 EXPECT_FALSE(voe_.IsExternalMediaProcessorRegistered());
2742
2743 // Test that we can register a processor on the receive channel on SSRC 0.
2744 // This tests the 1:1 case when the receive SSRC is unknown.
2745 EXPECT_TRUE(engine_.RegisterProcessor(0, &vp_1, cricket::MPD_RX));
2746 voe_.TriggerProcessPacket(cricket::MPD_RX);
2747 EXPECT_TRUE(voe_.IsExternalMediaProcessorRegistered());
2748 EXPECT_EQ(4, vp_1.voice_frame_count());
2749 EXPECT_TRUE(engine_.UnregisterProcessor(0,
2750 &vp_1,
2751 cricket::MPD_RX));
2752
2753 // The following tests test that FindChannelNumFromSsrc is doing
2754 // what we expect.
2755 // pick an invalid ssrc and make sure we can't register
2756 EXPECT_FALSE(engine_.RegisterProcessor(99,
2757 &vp_1,
2758 cricket::MPD_RX));
2759 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(1)));
2760 EXPECT_TRUE(engine_.RegisterProcessor(1,
2761 &vp_1,
2762 cricket::MPD_RX));
2763 EXPECT_TRUE(engine_.UnregisterProcessor(1,
2764 &vp_1,
2765 cricket::MPD_RX));
2766 EXPECT_FALSE(engine_.RegisterProcessor(1,
2767 &vp_1,
2768 cricket::MPD_TX));
2769 EXPECT_TRUE(channel_->RemoveRecvStream(1));
2770}
2771
2772TEST_F(WebRtcVoiceEngineTestFake, SetAudioOptions) {
2773 EXPECT_TRUE(SetupEngine());
2774
2775 bool ec_enabled;
2776 webrtc::EcModes ec_mode;
2777 bool ec_metrics_enabled;
2778 webrtc::AecmModes aecm_mode;
2779 bool cng_enabled;
2780 bool agc_enabled;
2781 webrtc::AgcModes agc_mode;
2782 webrtc::AgcConfig agc_config;
2783 bool ns_enabled;
2784 webrtc::NsModes ns_mode;
2785 bool highpass_filter_enabled;
2786 bool stereo_swapping_enabled;
2787 bool typing_detection_enabled;
2788 voe_.GetEcStatus(ec_enabled, ec_mode);
2789 voe_.GetEcMetricsStatus(ec_metrics_enabled);
2790 voe_.GetAecmMode(aecm_mode, cng_enabled);
2791 voe_.GetAgcStatus(agc_enabled, agc_mode);
2792 voe_.GetAgcConfig(agc_config);
2793 voe_.GetNsStatus(ns_enabled, ns_mode);
2794 highpass_filter_enabled = voe_.IsHighPassFilterEnabled();
2795 stereo_swapping_enabled = voe_.IsStereoChannelSwappingEnabled();
2796 voe_.GetTypingDetectionStatus(typing_detection_enabled);
2797 EXPECT_TRUE(ec_enabled);
2798 EXPECT_TRUE(ec_metrics_enabled);
2799 EXPECT_FALSE(cng_enabled);
2800 EXPECT_TRUE(agc_enabled);
2801 EXPECT_EQ(0, agc_config.targetLeveldBOv);
2802 EXPECT_TRUE(ns_enabled);
2803 EXPECT_TRUE(highpass_filter_enabled);
2804 EXPECT_FALSE(stereo_swapping_enabled);
2805 EXPECT_TRUE(typing_detection_enabled);
2806 EXPECT_EQ(ec_mode, webrtc::kEcConference);
2807 EXPECT_EQ(ns_mode, webrtc::kNsHighSuppression);
2808
2809 // Nothing set, so all ignored.
2810 cricket::AudioOptions options;
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00002811 ASSERT_TRUE(engine_.SetOptions(options));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002812 voe_.GetEcStatus(ec_enabled, ec_mode);
2813 voe_.GetEcMetricsStatus(ec_metrics_enabled);
2814 voe_.GetAecmMode(aecm_mode, cng_enabled);
2815 voe_.GetAgcStatus(agc_enabled, agc_mode);
2816 voe_.GetAgcConfig(agc_config);
2817 voe_.GetNsStatus(ns_enabled, ns_mode);
2818 highpass_filter_enabled = voe_.IsHighPassFilterEnabled();
2819 stereo_swapping_enabled = voe_.IsStereoChannelSwappingEnabled();
2820 voe_.GetTypingDetectionStatus(typing_detection_enabled);
2821 EXPECT_TRUE(ec_enabled);
2822 EXPECT_TRUE(ec_metrics_enabled);
2823 EXPECT_FALSE(cng_enabled);
2824 EXPECT_TRUE(agc_enabled);
2825 EXPECT_EQ(0, agc_config.targetLeveldBOv);
2826 EXPECT_TRUE(ns_enabled);
2827 EXPECT_TRUE(highpass_filter_enabled);
2828 EXPECT_FALSE(stereo_swapping_enabled);
2829 EXPECT_TRUE(typing_detection_enabled);
2830 EXPECT_EQ(ec_mode, webrtc::kEcConference);
2831 EXPECT_EQ(ns_mode, webrtc::kNsHighSuppression);
2832
2833 // Turn echo cancellation off
2834 options.echo_cancellation.Set(false);
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00002835 ASSERT_TRUE(engine_.SetOptions(options));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002836 voe_.GetEcStatus(ec_enabled, ec_mode);
2837 EXPECT_FALSE(ec_enabled);
2838
2839 // Turn echo cancellation back on, with settings, and make sure
2840 // nothing else changed.
2841 options.echo_cancellation.Set(true);
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00002842 ASSERT_TRUE(engine_.SetOptions(options));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002843 voe_.GetEcStatus(ec_enabled, ec_mode);
2844 voe_.GetEcMetricsStatus(ec_metrics_enabled);
2845 voe_.GetAecmMode(aecm_mode, cng_enabled);
2846 voe_.GetAgcStatus(agc_enabled, agc_mode);
2847 voe_.GetAgcConfig(agc_config);
2848 voe_.GetNsStatus(ns_enabled, ns_mode);
2849 highpass_filter_enabled = voe_.IsHighPassFilterEnabled();
2850 stereo_swapping_enabled = voe_.IsStereoChannelSwappingEnabled();
2851 voe_.GetTypingDetectionStatus(typing_detection_enabled);
2852 EXPECT_TRUE(ec_enabled);
2853 EXPECT_TRUE(ec_metrics_enabled);
2854 EXPECT_TRUE(agc_enabled);
2855 EXPECT_EQ(0, agc_config.targetLeveldBOv);
2856 EXPECT_TRUE(ns_enabled);
2857 EXPECT_TRUE(highpass_filter_enabled);
2858 EXPECT_FALSE(stereo_swapping_enabled);
2859 EXPECT_TRUE(typing_detection_enabled);
2860 EXPECT_EQ(ec_mode, webrtc::kEcConference);
2861 EXPECT_EQ(ns_mode, webrtc::kNsHighSuppression);
2862
2863 // Turn off AGC
2864 options.auto_gain_control.Set(false);
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00002865 ASSERT_TRUE(engine_.SetOptions(options));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002866 voe_.GetAgcStatus(agc_enabled, agc_mode);
2867 EXPECT_FALSE(agc_enabled);
2868
2869 // Turn AGC back on
2870 options.auto_gain_control.Set(true);
2871 options.adjust_agc_delta.Clear();
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00002872 ASSERT_TRUE(engine_.SetOptions(options));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002873 voe_.GetAgcStatus(agc_enabled, agc_mode);
2874 EXPECT_TRUE(agc_enabled);
2875 voe_.GetAgcConfig(agc_config);
2876 EXPECT_EQ(0, agc_config.targetLeveldBOv);
2877
2878 // Turn off other options (and stereo swapping on).
2879 options.noise_suppression.Set(false);
2880 options.highpass_filter.Set(false);
2881 options.typing_detection.Set(false);
2882 options.stereo_swapping.Set(true);
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00002883 ASSERT_TRUE(engine_.SetOptions(options));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002884 voe_.GetNsStatus(ns_enabled, ns_mode);
2885 highpass_filter_enabled = voe_.IsHighPassFilterEnabled();
2886 stereo_swapping_enabled = voe_.IsStereoChannelSwappingEnabled();
2887 voe_.GetTypingDetectionStatus(typing_detection_enabled);
2888 EXPECT_FALSE(ns_enabled);
2889 EXPECT_FALSE(highpass_filter_enabled);
2890 EXPECT_FALSE(typing_detection_enabled);
2891 EXPECT_TRUE(stereo_swapping_enabled);
2892
2893 // Turn on "conference mode" to ensure it has no impact.
2894 options.conference_mode.Set(true);
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00002895 ASSERT_TRUE(engine_.SetOptions(options));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002896 voe_.GetEcStatus(ec_enabled, ec_mode);
2897 voe_.GetNsStatus(ns_enabled, ns_mode);
2898 EXPECT_TRUE(ec_enabled);
2899 EXPECT_EQ(webrtc::kEcConference, ec_mode);
2900 EXPECT_FALSE(ns_enabled);
2901 EXPECT_EQ(webrtc::kNsHighSuppression, ns_mode);
2902}
2903
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00002904TEST_F(WebRtcVoiceEngineTestFake, DefaultOptions) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002905 EXPECT_TRUE(SetupEngine());
2906
2907 bool ec_enabled;
2908 webrtc::EcModes ec_mode;
2909 bool ec_metrics_enabled;
2910 bool agc_enabled;
2911 webrtc::AgcModes agc_mode;
2912 bool ns_enabled;
2913 webrtc::NsModes ns_mode;
2914 bool highpass_filter_enabled;
2915 bool stereo_swapping_enabled;
2916 bool typing_detection_enabled;
2917
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002918 voe_.GetEcStatus(ec_enabled, ec_mode);
2919 voe_.GetEcMetricsStatus(ec_metrics_enabled);
2920 voe_.GetAgcStatus(agc_enabled, agc_mode);
2921 voe_.GetNsStatus(ns_enabled, ns_mode);
2922 highpass_filter_enabled = voe_.IsHighPassFilterEnabled();
2923 stereo_swapping_enabled = voe_.IsStereoChannelSwappingEnabled();
2924 voe_.GetTypingDetectionStatus(typing_detection_enabled);
2925 EXPECT_TRUE(ec_enabled);
2926 EXPECT_TRUE(agc_enabled);
2927 EXPECT_TRUE(ns_enabled);
2928 EXPECT_TRUE(highpass_filter_enabled);
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00002929 EXPECT_TRUE(typing_detection_enabled);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002930 EXPECT_FALSE(stereo_swapping_enabled);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002931}
2932
2933TEST_F(WebRtcVoiceEngineTestFake, InitDoesNotOverwriteDefaultAgcConfig) {
2934 webrtc::AgcConfig set_config = {0};
2935 set_config.targetLeveldBOv = 3;
2936 set_config.digitalCompressionGaindB = 9;
2937 set_config.limiterEnable = true;
2938 EXPECT_EQ(0, voe_.SetAgcConfig(set_config));
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002939 EXPECT_TRUE(engine_.Init(rtc::Thread::Current()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002940
2941 webrtc::AgcConfig config = {0};
2942 EXPECT_EQ(0, voe_.GetAgcConfig(config));
2943 EXPECT_EQ(set_config.targetLeveldBOv, config.targetLeveldBOv);
2944 EXPECT_EQ(set_config.digitalCompressionGaindB,
2945 config.digitalCompressionGaindB);
2946 EXPECT_EQ(set_config.limiterEnable, config.limiterEnable);
2947}
2948
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002949TEST_F(WebRtcVoiceEngineTestFake, SetOptionOverridesViaChannels) {
2950 EXPECT_TRUE(SetupEngine());
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002951 rtc::scoped_ptr<cricket::VoiceMediaChannel> channel1(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002952 engine_.CreateChannel());
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002953 rtc::scoped_ptr<cricket::VoiceMediaChannel> channel2(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002954 engine_.CreateChannel());
2955
2956 // Have to add a stream to make SetSend work.
2957 cricket::StreamParams stream1;
2958 stream1.ssrcs.push_back(1);
2959 channel1->AddSendStream(stream1);
2960 cricket::StreamParams stream2;
2961 stream2.ssrcs.push_back(2);
2962 channel2->AddSendStream(stream2);
2963
2964 // AEC and AGC and NS
2965 cricket::AudioOptions options_all;
2966 options_all.echo_cancellation.Set(true);
2967 options_all.auto_gain_control.Set(true);
2968 options_all.noise_suppression.Set(true);
2969
2970 ASSERT_TRUE(channel1->SetOptions(options_all));
2971 cricket::AudioOptions expected_options = options_all;
2972 cricket::AudioOptions actual_options;
2973 ASSERT_TRUE(channel1->GetOptions(&actual_options));
2974 EXPECT_EQ(expected_options, actual_options);
2975 ASSERT_TRUE(channel2->SetOptions(options_all));
2976 ASSERT_TRUE(channel2->GetOptions(&actual_options));
2977 EXPECT_EQ(expected_options, actual_options);
2978
2979 // unset NS
2980 cricket::AudioOptions options_no_ns;
2981 options_no_ns.noise_suppression.Set(false);
2982 ASSERT_TRUE(channel1->SetOptions(options_no_ns));
2983
2984 expected_options.echo_cancellation.Set(true);
2985 expected_options.auto_gain_control.Set(true);
2986 expected_options.noise_suppression.Set(false);
2987 ASSERT_TRUE(channel1->GetOptions(&actual_options));
2988 EXPECT_EQ(expected_options, actual_options);
2989
2990 // unset AGC
2991 cricket::AudioOptions options_no_agc;
2992 options_no_agc.auto_gain_control.Set(false);
2993 ASSERT_TRUE(channel2->SetOptions(options_no_agc));
2994
2995 expected_options.echo_cancellation.Set(true);
2996 expected_options.auto_gain_control.Set(false);
2997 expected_options.noise_suppression.Set(true);
2998 ASSERT_TRUE(channel2->GetOptions(&actual_options));
2999 EXPECT_EQ(expected_options, actual_options);
3000
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00003001 ASSERT_TRUE(engine_.SetOptions(options_all));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003002 bool ec_enabled;
3003 webrtc::EcModes ec_mode;
3004 bool agc_enabled;
3005 webrtc::AgcModes agc_mode;
3006 bool ns_enabled;
3007 webrtc::NsModes ns_mode;
3008 voe_.GetEcStatus(ec_enabled, ec_mode);
3009 voe_.GetAgcStatus(agc_enabled, agc_mode);
3010 voe_.GetNsStatus(ns_enabled, ns_mode);
3011 EXPECT_TRUE(ec_enabled);
3012 EXPECT_TRUE(agc_enabled);
3013 EXPECT_TRUE(ns_enabled);
3014
3015 channel1->SetSend(cricket::SEND_MICROPHONE);
3016 voe_.GetEcStatus(ec_enabled, ec_mode);
3017 voe_.GetAgcStatus(agc_enabled, agc_mode);
3018 voe_.GetNsStatus(ns_enabled, ns_mode);
3019 EXPECT_TRUE(ec_enabled);
3020 EXPECT_TRUE(agc_enabled);
3021 EXPECT_FALSE(ns_enabled);
3022
3023 channel1->SetSend(cricket::SEND_NOTHING);
3024 voe_.GetEcStatus(ec_enabled, ec_mode);
3025 voe_.GetAgcStatus(agc_enabled, agc_mode);
3026 voe_.GetNsStatus(ns_enabled, ns_mode);
3027 EXPECT_TRUE(ec_enabled);
3028 EXPECT_TRUE(agc_enabled);
3029 EXPECT_TRUE(ns_enabled);
3030
3031 channel2->SetSend(cricket::SEND_MICROPHONE);
3032 voe_.GetEcStatus(ec_enabled, ec_mode);
3033 voe_.GetAgcStatus(agc_enabled, agc_mode);
3034 voe_.GetNsStatus(ns_enabled, ns_mode);
3035 EXPECT_TRUE(ec_enabled);
3036 EXPECT_FALSE(agc_enabled);
3037 EXPECT_TRUE(ns_enabled);
3038
3039 channel2->SetSend(cricket::SEND_NOTHING);
3040 voe_.GetEcStatus(ec_enabled, ec_mode);
3041 voe_.GetAgcStatus(agc_enabled, agc_mode);
3042 voe_.GetNsStatus(ns_enabled, ns_mode);
3043 EXPECT_TRUE(ec_enabled);
3044 EXPECT_TRUE(agc_enabled);
3045 EXPECT_TRUE(ns_enabled);
3046
3047 // Make sure settings take effect while we are sending.
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00003048 ASSERT_TRUE(engine_.SetOptions(options_all));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003049 cricket::AudioOptions options_no_agc_nor_ns;
3050 options_no_agc_nor_ns.auto_gain_control.Set(false);
3051 options_no_agc_nor_ns.noise_suppression.Set(false);
3052 channel2->SetSend(cricket::SEND_MICROPHONE);
3053 channel2->SetOptions(options_no_agc_nor_ns);
3054
3055 expected_options.echo_cancellation.Set(true);
3056 expected_options.auto_gain_control.Set(false);
3057 expected_options.noise_suppression.Set(false);
3058 ASSERT_TRUE(channel2->GetOptions(&actual_options));
3059 EXPECT_EQ(expected_options, actual_options);
3060 voe_.GetEcStatus(ec_enabled, ec_mode);
3061 voe_.GetAgcStatus(agc_enabled, agc_mode);
3062 voe_.GetNsStatus(ns_enabled, ns_mode);
3063 EXPECT_TRUE(ec_enabled);
3064 EXPECT_FALSE(agc_enabled);
3065 EXPECT_FALSE(ns_enabled);
3066}
3067
wu@webrtc.orgde305012013-10-31 15:40:38 +00003068// This test verifies DSCP settings are properly applied on voice media channel.
3069TEST_F(WebRtcVoiceEngineTestFake, TestSetDscpOptions) {
3070 EXPECT_TRUE(SetupEngine());
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003071 rtc::scoped_ptr<cricket::VoiceMediaChannel> channel(
wu@webrtc.orgde305012013-10-31 15:40:38 +00003072 engine_.CreateChannel());
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003073 rtc::scoped_ptr<cricket::FakeNetworkInterface> network_interface(
wu@webrtc.orgde305012013-10-31 15:40:38 +00003074 new cricket::FakeNetworkInterface);
3075 channel->SetInterface(network_interface.get());
3076 cricket::AudioOptions options;
3077 options.dscp.Set(true);
3078 EXPECT_TRUE(channel->SetOptions(options));
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003079 EXPECT_EQ(rtc::DSCP_EF, network_interface->dscp());
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +00003080 // Verify previous value is not modified if dscp option is not set.
3081 cricket::AudioOptions options1;
3082 EXPECT_TRUE(channel->SetOptions(options1));
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003083 EXPECT_EQ(rtc::DSCP_EF, network_interface->dscp());
wu@webrtc.orgde305012013-10-31 15:40:38 +00003084 options.dscp.Set(false);
3085 EXPECT_TRUE(channel->SetOptions(options));
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003086 EXPECT_EQ(rtc::DSCP_DEFAULT, network_interface->dscp());
wu@webrtc.orgde305012013-10-31 15:40:38 +00003087}
3088
wu@webrtc.org1d1ffc92013-10-16 18:12:02 +00003089TEST(WebRtcVoiceEngineTest, TestDefaultOptionsBeforeInit) {
3090 cricket::WebRtcVoiceEngine engine;
3091 cricket::AudioOptions options = engine.GetOptions();
3092 // The default options should have at least a few things set. We purposefully
3093 // don't check the option values here, though.
3094 EXPECT_TRUE(options.echo_cancellation.IsSet());
3095 EXPECT_TRUE(options.auto_gain_control.IsSet());
3096 EXPECT_TRUE(options.noise_suppression.IsSet());
3097}
3098
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003099// Test that GetReceiveChannelNum returns the default channel for the first
3100// recv stream in 1-1 calls.
3101TEST_F(WebRtcVoiceEngineTestFake, TestGetReceiveChannelNumIn1To1Calls) {
3102 EXPECT_TRUE(SetupEngine());
3103 cricket::WebRtcVoiceMediaChannel* media_channel =
3104 static_cast<cricket::WebRtcVoiceMediaChannel*>(channel_);
3105 // Test that GetChannelNum returns the default channel if the SSRC is unknown.
3106 EXPECT_EQ(media_channel->voe_channel(),
3107 media_channel->GetReceiveChannelNum(0));
3108 cricket::StreamParams stream;
3109 stream.ssrcs.push_back(kSsrc2);
3110 EXPECT_TRUE(channel_->AddRecvStream(stream));
3111 EXPECT_EQ(media_channel->voe_channel(),
3112 media_channel->GetReceiveChannelNum(kSsrc2));
3113}
3114
3115// Test that GetReceiveChannelNum doesn't return the default channel for the
3116// first recv stream in conference calls.
3117TEST_F(WebRtcVoiceEngineTestFake, TestGetChannelNumInConferenceCalls) {
3118 EXPECT_TRUE(SetupEngine());
3119 EXPECT_TRUE(channel_->SetOptions(options_conference_));
3120 cricket::StreamParams stream;
3121 stream.ssrcs.push_back(kSsrc2);
3122 EXPECT_TRUE(channel_->AddRecvStream(stream));
3123 cricket::WebRtcVoiceMediaChannel* media_channel =
3124 static_cast<cricket::WebRtcVoiceMediaChannel*>(channel_);
3125 EXPECT_LT(media_channel->voe_channel(),
3126 media_channel->GetReceiveChannelNum(kSsrc2));
3127}
3128
3129TEST_F(WebRtcVoiceEngineTestFake, SetOutputScaling) {
3130 EXPECT_TRUE(SetupEngine());
3131 double left, right;
3132 EXPECT_TRUE(channel_->SetOutputScaling(0, 1, 2));
3133 EXPECT_TRUE(channel_->GetOutputScaling(0, &left, &right));
3134 EXPECT_DOUBLE_EQ(1, left);
3135 EXPECT_DOUBLE_EQ(2, right);
3136
3137 EXPECT_FALSE(channel_->SetOutputScaling(kSsrc2, 1, 2));
3138 cricket::StreamParams stream;
3139 stream.ssrcs.push_back(kSsrc2);
3140 EXPECT_TRUE(channel_->AddRecvStream(stream));
3141
3142 EXPECT_TRUE(channel_->SetOutputScaling(kSsrc2, 2, 1));
3143 EXPECT_TRUE(channel_->GetOutputScaling(kSsrc2, &left, &right));
3144 EXPECT_DOUBLE_EQ(2, left);
3145 EXPECT_DOUBLE_EQ(1, right);
3146}
3147
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003148// Tests for the actual WebRtc VoE library.
3149
3150// Tests that the library initializes and shuts down properly.
3151TEST(WebRtcVoiceEngineTest, StartupShutdown) {
3152 cricket::WebRtcVoiceEngine engine;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003153 EXPECT_TRUE(engine.Init(rtc::Thread::Current()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003154 cricket::VoiceMediaChannel* channel = engine.CreateChannel();
3155 EXPECT_TRUE(channel != NULL);
3156 delete channel;
3157 engine.Terminate();
3158
3159 // Reinit to catch regression where VoiceEngineObserver reference is lost
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003160 EXPECT_TRUE(engine.Init(rtc::Thread::Current()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003161 engine.Terminate();
3162}
3163
3164// Tests that the logging from the library is cleartext.
3165TEST(WebRtcVoiceEngineTest, DISABLED_HasUnencryptedLogging) {
3166 cricket::WebRtcVoiceEngine engine;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003167 rtc::scoped_ptr<rtc::MemoryStream> stream(
3168 new rtc::MemoryStream);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003169 size_t size = 0;
3170 bool cleartext = true;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003171 rtc::LogMessage::AddLogToStream(stream.get(), rtc::LS_VERBOSE);
3172 engine.SetLogging(rtc::LS_VERBOSE, "");
3173 EXPECT_TRUE(engine.Init(rtc::Thread::Current()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003174 EXPECT_TRUE(stream->GetSize(&size));
3175 EXPECT_GT(size, 0U);
3176 engine.Terminate();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003177 rtc::LogMessage::RemoveLogToStream(stream.get());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003178 const char* buf = stream->GetBuffer();
3179 for (size_t i = 0; i < size && cleartext; ++i) {
3180 int ch = static_cast<int>(buf[i]);
3181 ASSERT_GE(ch, 0) << "Out of bounds character in WebRtc VoE log: "
3182 << std::hex << ch;
3183 cleartext = (isprint(ch) || isspace(ch));
3184 }
3185 EXPECT_TRUE(cleartext);
3186}
3187
3188// Tests we do not see any references to a monitor thread being spun up
3189// when initiating the engine.
3190TEST(WebRtcVoiceEngineTest, HasNoMonitorThread) {
3191 cricket::WebRtcVoiceEngine engine;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003192 rtc::scoped_ptr<rtc::MemoryStream> stream(
3193 new rtc::MemoryStream);
3194 rtc::LogMessage::AddLogToStream(stream.get(), rtc::LS_VERBOSE);
3195 engine.SetLogging(rtc::LS_VERBOSE, "");
3196 EXPECT_TRUE(engine.Init(rtc::Thread::Current()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003197 engine.Terminate();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003198 rtc::LogMessage::RemoveLogToStream(stream.get());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003199
3200 size_t size = 0;
3201 EXPECT_TRUE(stream->GetSize(&size));
3202 EXPECT_GT(size, 0U);
wu@webrtc.org9caf2762013-12-11 18:25:07 +00003203 const std::string logs(stream->GetBuffer(), size);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003204 EXPECT_NE(std::string::npos, logs.find("ProcessThread"));
3205}
3206
3207// Tests that the library is configured with the codecs we want.
3208TEST(WebRtcVoiceEngineTest, HasCorrectCodecs) {
3209 cricket::WebRtcVoiceEngine engine;
3210 // Check codecs by name.
3211 EXPECT_TRUE(engine.FindCodec(
3212 cricket::AudioCodec(96, "OPUS", 48000, 0, 2, 0)));
3213 EXPECT_TRUE(engine.FindCodec(
3214 cricket::AudioCodec(96, "ISAC", 16000, 0, 1, 0)));
3215 EXPECT_TRUE(engine.FindCodec(
3216 cricket::AudioCodec(96, "ISAC", 32000, 0, 1, 0)));
3217 // Check that name matching is case-insensitive.
3218 EXPECT_TRUE(engine.FindCodec(
3219 cricket::AudioCodec(96, "ILBC", 8000, 0, 1, 0)));
3220 EXPECT_TRUE(engine.FindCodec(
3221 cricket::AudioCodec(96, "iLBC", 8000, 0, 1, 0)));
3222 EXPECT_TRUE(engine.FindCodec(
3223 cricket::AudioCodec(96, "PCMU", 8000, 0, 1, 0)));
3224 EXPECT_TRUE(engine.FindCodec(
3225 cricket::AudioCodec(96, "PCMA", 8000, 0, 1, 0)));
3226 EXPECT_TRUE(engine.FindCodec(
henrik.lundin@webrtc.orgf85dbce2014-11-07 12:25:00 +00003227 cricket::AudioCodec(96, "G722", 8000, 0, 1, 0)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003228 EXPECT_TRUE(engine.FindCodec(
3229 cricket::AudioCodec(96, "red", 8000, 0, 1, 0)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003230 EXPECT_TRUE(engine.FindCodec(
3231 cricket::AudioCodec(96, "CN", 32000, 0, 1, 0)));
3232 EXPECT_TRUE(engine.FindCodec(
3233 cricket::AudioCodec(96, "CN", 16000, 0, 1, 0)));
3234 EXPECT_TRUE(engine.FindCodec(
3235 cricket::AudioCodec(96, "CN", 8000, 0, 1, 0)));
3236 EXPECT_TRUE(engine.FindCodec(
3237 cricket::AudioCodec(96, "telephone-event", 8000, 0, 1, 0)));
3238 // Check codecs with an id by id.
3239 EXPECT_TRUE(engine.FindCodec(
3240 cricket::AudioCodec(0, "", 8000, 0, 1, 0))); // PCMU
3241 EXPECT_TRUE(engine.FindCodec(
3242 cricket::AudioCodec(8, "", 8000, 0, 1, 0))); // PCMA
3243 EXPECT_TRUE(engine.FindCodec(
henrik.lundin@webrtc.orgf85dbce2014-11-07 12:25:00 +00003244 cricket::AudioCodec(9, "", 8000, 0, 1, 0))); // G722
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003245 EXPECT_TRUE(engine.FindCodec(
3246 cricket::AudioCodec(13, "", 8000, 0, 1, 0))); // CN
3247 // Check sample/bitrate matching.
3248 EXPECT_TRUE(engine.FindCodec(
3249 cricket::AudioCodec(0, "PCMU", 8000, 64000, 1, 0)));
3250 // Check that bad codecs fail.
3251 EXPECT_FALSE(engine.FindCodec(cricket::AudioCodec(99, "ABCD", 0, 0, 1, 0)));
3252 EXPECT_FALSE(engine.FindCodec(cricket::AudioCodec(88, "", 0, 0, 1, 0)));
3253 EXPECT_FALSE(engine.FindCodec(cricket::AudioCodec(0, "", 0, 0, 2, 0)));
3254 EXPECT_FALSE(engine.FindCodec(cricket::AudioCodec(0, "", 5000, 0, 1, 0)));
3255 EXPECT_FALSE(engine.FindCodec(cricket::AudioCodec(0, "", 0, 5000, 1, 0)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003256 // Verify the payload id of common audio codecs, including CN, ISAC, and G722.
3257 for (std::vector<cricket::AudioCodec>::const_iterator it =
3258 engine.codecs().begin(); it != engine.codecs().end(); ++it) {
3259 if (it->name == "CN" && it->clockrate == 16000) {
3260 EXPECT_EQ(105, it->id);
3261 } else if (it->name == "CN" && it->clockrate == 32000) {
3262 EXPECT_EQ(106, it->id);
3263 } else if (it->name == "ISAC" && it->clockrate == 16000) {
3264 EXPECT_EQ(103, it->id);
3265 } else if (it->name == "ISAC" && it->clockrate == 32000) {
3266 EXPECT_EQ(104, it->id);
henrik.lundin@webrtc.orgf85dbce2014-11-07 12:25:00 +00003267 } else if (it->name == "G722" && it->clockrate == 8000) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003268 EXPECT_EQ(9, it->id);
3269 } else if (it->name == "telephone-event") {
3270 EXPECT_EQ(126, it->id);
3271 } else if (it->name == "red") {
3272 EXPECT_EQ(127, it->id);
3273 } else if (it->name == "opus") {
3274 EXPECT_EQ(111, it->id);
wu@webrtc.org9caf2762013-12-11 18:25:07 +00003275 ASSERT_TRUE(it->params.find("minptime") != it->params.end());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003276 EXPECT_EQ("10", it->params.find("minptime")->second);
wu@webrtc.org9caf2762013-12-11 18:25:07 +00003277 ASSERT_TRUE(it->params.find("maxptime") != it->params.end());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003278 EXPECT_EQ("60", it->params.find("maxptime")->second);
3279 }
3280 }
3281
3282 engine.Terminate();
3283}
3284
3285// Tests that VoE supports at least 32 channels
3286TEST(WebRtcVoiceEngineTest, Has32Channels) {
3287 cricket::WebRtcVoiceEngine engine;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003288 EXPECT_TRUE(engine.Init(rtc::Thread::Current()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003289
3290 cricket::VoiceMediaChannel* channels[32];
3291 int num_channels = 0;
3292
3293 while (num_channels < ARRAY_SIZE(channels)) {
3294 cricket::VoiceMediaChannel* channel = engine.CreateChannel();
3295 if (!channel)
3296 break;
3297
3298 channels[num_channels++] = channel;
3299 }
3300
3301 int expected = ARRAY_SIZE(channels);
3302 EXPECT_EQ(expected, num_channels);
3303
3304 while (num_channels > 0) {
3305 delete channels[--num_channels];
3306 }
3307
3308 engine.Terminate();
3309}
3310
3311// Test that we set our preferred codecs properly.
3312TEST(WebRtcVoiceEngineTest, SetRecvCodecs) {
3313 cricket::WebRtcVoiceEngine engine;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003314 EXPECT_TRUE(engine.Init(rtc::Thread::Current()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003315 cricket::WebRtcVoiceMediaChannel channel(&engine);
3316 EXPECT_TRUE(channel.SetRecvCodecs(engine.codecs()));
3317}
3318
3319#ifdef WIN32
3320// Test our workarounds to WebRtc VoE' munging of the coinit count
3321TEST(WebRtcVoiceEngineTest, CoInitialize) {
3322 cricket::WebRtcVoiceEngine* engine = new cricket::WebRtcVoiceEngine();
3323
3324 // Initial refcount should be 0.
3325 EXPECT_EQ(S_OK, CoInitializeEx(NULL, COINIT_MULTITHREADED));
3326
3327 // Engine should start even with COM already inited.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003328 EXPECT_TRUE(engine->Init(rtc::Thread::Current()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003329 engine->Terminate();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003330 EXPECT_TRUE(engine->Init(rtc::Thread::Current()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003331 engine->Terminate();
3332
3333 // Refcount after terminate should be 1 (in reality 3); test if it is nonzero.
3334 EXPECT_EQ(S_FALSE, CoInitializeEx(NULL, COINIT_MULTITHREADED));
3335 // Decrement refcount to (hopefully) 0.
3336 CoUninitialize();
3337 CoUninitialize();
3338 delete engine;
3339
3340 // Ensure refcount is 0.
3341 EXPECT_EQ(S_OK, CoInitializeEx(NULL, COINIT_MULTITHREADED));
3342 CoUninitialize();
3343}
3344#endif
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +00003345
3346TEST_F(WebRtcVoiceEngineTestFake, ChangeCombinedAudioVideoBweOption) {
3347 // Test that changing the combined_audio_video_bwe option results in the
3348 // expected state changes in VoiceEngine.
3349 cricket::ViEWrapper vie;
3350 const int kVieCh = 667;
3351
3352 EXPECT_TRUE(SetupEngine());
3353 cricket::WebRtcVoiceMediaChannel* media_channel =
3354 static_cast<cricket::WebRtcVoiceMediaChannel*>(channel_);
3355 EXPECT_TRUE(media_channel->SetupSharedBandwidthEstimation(vie.engine(),
3356 kVieCh));
3357 EXPECT_TRUE(media_channel->AddRecvStream(
3358 cricket::StreamParams::CreateLegacy(2)));
3359 int recv_ch = voe_.GetLastChannel();
3360
3361 // Combined BWE should not be set up yet.
3362 EXPECT_EQ(NULL, voe_.GetViENetwork(recv_ch));
3363 EXPECT_EQ(-1, voe_.GetVideoChannel(recv_ch));
3364
3365 // Enable combined BWE option - now it should be set up.
3366 cricket::AudioOptions options;
3367 options.combined_audio_video_bwe.Set(true);
3368 EXPECT_TRUE(media_channel->SetOptions(options));
3369 EXPECT_EQ(vie.network(), voe_.GetViENetwork(recv_ch));
3370 EXPECT_EQ(kVieCh, voe_.GetVideoChannel(recv_ch));
3371
3372 // Disable combined BWE option - should be disabled again.
3373 options.combined_audio_video_bwe.Set(false);
3374 EXPECT_TRUE(media_channel->SetOptions(options));
3375 EXPECT_EQ(NULL, voe_.GetViENetwork(recv_ch));
3376 EXPECT_EQ(-1, voe_.GetVideoChannel(recv_ch));
3377
3378 EXPECT_TRUE(media_channel->SetupSharedBandwidthEstimation(NULL, -1));
3379}
3380
3381TEST_F(WebRtcVoiceEngineTestFake, SetupSharedBandwidthEstimation) {
3382 // Test that calling SetupSharedBandwidthEstimation() on the voice media
3383 // channel results in the expected state changes in VoiceEngine.
3384 cricket::ViEWrapper vie1;
3385 cricket::ViEWrapper vie2;
3386 const int kVieCh1 = 667;
3387 const int kVieCh2 = 70;
3388
3389 EXPECT_TRUE(SetupEngine());
3390 cricket::WebRtcVoiceMediaChannel* media_channel =
3391 static_cast<cricket::WebRtcVoiceMediaChannel*>(channel_);
3392 cricket::AudioOptions options;
3393 options.combined_audio_video_bwe.Set(true);
3394 EXPECT_TRUE(media_channel->SetOptions(options));
3395 EXPECT_TRUE(media_channel->AddRecvStream(
3396 cricket::StreamParams::CreateLegacy(2)));
3397 int recv_ch = voe_.GetLastChannel();
3398
3399 // Combined BWE should not be set up yet.
3400 EXPECT_EQ(NULL, voe_.GetViENetwork(recv_ch));
3401 EXPECT_EQ(-1, voe_.GetVideoChannel(recv_ch));
3402
3403 // Register - should be enabled.
3404 EXPECT_TRUE(media_channel->SetupSharedBandwidthEstimation(vie1.engine(),
3405 kVieCh1));
3406 EXPECT_EQ(vie1.network(), voe_.GetViENetwork(recv_ch));
3407 EXPECT_EQ(kVieCh1, voe_.GetVideoChannel(recv_ch));
3408
3409 // Re-register - should still be enabled.
3410 EXPECT_TRUE(media_channel->SetupSharedBandwidthEstimation(vie2.engine(),
3411 kVieCh2));
3412 EXPECT_EQ(vie2.network(), voe_.GetViENetwork(recv_ch));
3413 EXPECT_EQ(kVieCh2, voe_.GetVideoChannel(recv_ch));
3414
3415 // Unregister - should be disabled again.
3416 EXPECT_TRUE(media_channel->SetupSharedBandwidthEstimation(NULL, -1));
3417 EXPECT_EQ(NULL, voe_.GetViENetwork(recv_ch));
3418 EXPECT_EQ(-1, voe_.GetVideoChannel(recv_ch));
3419}
3420
3421TEST_F(WebRtcVoiceEngineTestFake, ConfigureCombinedBweForNewRecvStreams) {
3422 // Test that adding receive streams after enabling combined bandwidth
3423 // estimation will correctly configure each channel.
3424 cricket::ViEWrapper vie;
3425 const int kVieCh = 667;
3426
3427 EXPECT_TRUE(SetupEngine());
3428 cricket::WebRtcVoiceMediaChannel* media_channel =
3429 static_cast<cricket::WebRtcVoiceMediaChannel*>(channel_);
3430 EXPECT_TRUE(media_channel->SetupSharedBandwidthEstimation(vie.engine(),
3431 kVieCh));
3432 cricket::AudioOptions options;
3433 options.combined_audio_video_bwe.Set(true);
3434 EXPECT_TRUE(media_channel->SetOptions(options));
3435
3436 static const uint32 kSsrcs[] = {1, 2, 3, 4};
3437 int voe_channels[ARRAY_SIZE(kSsrcs)] = {0};
3438 for (unsigned int i = 0; i < ARRAY_SIZE(kSsrcs); ++i) {
3439 EXPECT_TRUE(media_channel->AddRecvStream(
3440 cricket::StreamParams::CreateLegacy(kSsrcs[i])));
3441 int recv_ch = media_channel->GetReceiveChannelNum(kSsrcs[i]);
3442 EXPECT_NE(-1, recv_ch);
3443 voe_channels[i] = recv_ch;
3444 EXPECT_EQ(vie.network(), voe_.GetViENetwork(recv_ch));
3445 EXPECT_EQ(kVieCh, voe_.GetVideoChannel(recv_ch));
3446 }
3447
3448 EXPECT_TRUE(media_channel->SetupSharedBandwidthEstimation(NULL, -1));
3449
3450 for (unsigned int i = 0; i < ARRAY_SIZE(voe_channels); ++i) {
3451 EXPECT_EQ(NULL, voe_.GetViENetwork(voe_channels[i]));
3452 EXPECT_EQ(-1, voe_.GetVideoChannel(voe_channels[i]));
3453 }
3454}