blob: b013e023d542bca67a15dcc9131e1499086970f2 [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// Test that without useinbandfec, Opus FEC is off.
buildbot@webrtc.orgd27d9ae2014-06-19 01:56:46 +00001163TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecNoOpusFec) {
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +00001164 EXPECT_TRUE(SetupEngine());
1165 int channel_num = voe_.GetLastChannel();
1166 std::vector<cricket::AudioCodec> codecs;
1167 codecs.push_back(kOpusCodec);
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +00001168 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1169 EXPECT_FALSE(voe_.GetCodecFEC(channel_num));
1170}
1171
1172// Test that with useinbandfec=0, Opus FEC is off.
buildbot@webrtc.orgd27d9ae2014-06-19 01:56:46 +00001173TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecOpusDisableFec) {
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +00001174 EXPECT_TRUE(SetupEngine());
1175 int channel_num = voe_.GetLastChannel();
1176 std::vector<cricket::AudioCodec> codecs;
1177 codecs.push_back(kOpusCodec);
1178 codecs[0].bitrate = 0;
1179 codecs[0].params["useinbandfec"] = "0";
1180 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1181 EXPECT_FALSE(voe_.GetCodecFEC(channel_num));
1182 webrtc::CodecInst gcodec;
1183 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1184 EXPECT_STREQ("opus", gcodec.plname);
1185 EXPECT_EQ(1, gcodec.channels);
1186 EXPECT_EQ(32000, gcodec.rate);
1187}
1188
1189// Test that with useinbandfec=1, Opus FEC is on.
buildbot@webrtc.orgd27d9ae2014-06-19 01:56:46 +00001190TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecOpusEnableFec) {
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +00001191 EXPECT_TRUE(SetupEngine());
1192 int channel_num = voe_.GetLastChannel();
1193 std::vector<cricket::AudioCodec> codecs;
1194 codecs.push_back(kOpusCodec);
1195 codecs[0].bitrate = 0;
1196 codecs[0].params["useinbandfec"] = "1";
1197 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1198 EXPECT_TRUE(voe_.GetCodecFEC(channel_num));
1199 webrtc::CodecInst gcodec;
1200 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1201 EXPECT_STREQ("opus", gcodec.plname);
1202 EXPECT_EQ(1, gcodec.channels);
1203 EXPECT_EQ(32000, gcodec.rate);
1204}
1205
1206// Test that with useinbandfec=1, stereo=1, Opus FEC is on.
buildbot@webrtc.orgd27d9ae2014-06-19 01:56:46 +00001207TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecOpusEnableFecStereo) {
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +00001208 EXPECT_TRUE(SetupEngine());
1209 int channel_num = voe_.GetLastChannel();
1210 std::vector<cricket::AudioCodec> codecs;
1211 codecs.push_back(kOpusCodec);
1212 codecs[0].bitrate = 0;
1213 codecs[0].params["stereo"] = "1";
1214 codecs[0].params["useinbandfec"] = "1";
1215 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1216 EXPECT_TRUE(voe_.GetCodecFEC(channel_num));
1217 webrtc::CodecInst gcodec;
1218 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1219 EXPECT_STREQ("opus", gcodec.plname);
1220 EXPECT_EQ(2, gcodec.channels);
1221 EXPECT_EQ(64000, gcodec.rate);
1222}
1223
1224// Test that with non-Opus, codec FEC is off.
buildbot@webrtc.orgd27d9ae2014-06-19 01:56:46 +00001225TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecIsacNoFec) {
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +00001226 EXPECT_TRUE(SetupEngine());
1227 int channel_num = voe_.GetLastChannel();
1228 std::vector<cricket::AudioCodec> codecs;
1229 codecs.push_back(kIsacCodec);
1230 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1231 EXPECT_FALSE(voe_.GetCodecFEC(channel_num));
1232}
buildbot@webrtc.org3ffa1f92014-07-02 19:51:26 +00001233
1234// Test the with non-Opus, even if useinbandfec=1, FEC is off.
1235TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecIsacWithParamNoFec) {
1236 EXPECT_TRUE(SetupEngine());
1237 int channel_num = voe_.GetLastChannel();
1238 std::vector<cricket::AudioCodec> codecs;
1239 codecs.push_back(kIsacCodec);
1240 codecs[0].params["useinbandfec"] = "1";
1241 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1242 EXPECT_FALSE(voe_.GetCodecFEC(channel_num));
1243}
buildbot@webrtc.org5d639b32014-09-10 07:57:12 +00001244
1245// Test that Opus FEC status can be changed.
1246TEST_F(WebRtcVoiceEngineTestFake, ChangeOpusFecStatus) {
1247 EXPECT_TRUE(SetupEngine());
1248 int channel_num = voe_.GetLastChannel();
1249 std::vector<cricket::AudioCodec> codecs;
1250 codecs.push_back(kOpusCodec);
1251 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1252 EXPECT_FALSE(voe_.GetCodecFEC(channel_num));
1253 codecs[0].params["useinbandfec"] = "1";
1254 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1255 EXPECT_TRUE(voe_.GetCodecFEC(channel_num));
1256}
1257
1258// Test maxplaybackrate <= 8000 triggers Opus narrow band mode.
1259TEST_F(WebRtcVoiceEngineTestFake, SetOpusMaxPlaybackRateNb) {
1260 EXPECT_TRUE(SetupEngine());
1261 int channel_num = voe_.GetLastChannel();
1262 std::vector<cricket::AudioCodec> codecs;
1263 codecs.push_back(kOpusCodec);
1264 codecs[0].bitrate = 0;
1265 codecs[0].SetParam(cricket::kCodecParamMaxPlaybackRate, 8000);
1266 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1267 EXPECT_EQ(cricket::kOpusBandwidthNb,
1268 voe_.GetMaxEncodingBandwidth(channel_num));
1269 webrtc::CodecInst gcodec;
1270 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1271 EXPECT_STREQ("opus", gcodec.plname);
minyue@webrtc.org2dc6f312014-10-31 05:33:10 +00001272
1273 EXPECT_EQ(12000, gcodec.rate);
1274 codecs[0].SetParam(cricket::kCodecParamStereo, "1");
1275 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1276 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1277 EXPECT_EQ(24000, gcodec.rate);
buildbot@webrtc.org5d639b32014-09-10 07:57:12 +00001278}
1279
1280// Test 8000 < maxplaybackrate <= 12000 triggers Opus medium band mode.
1281TEST_F(WebRtcVoiceEngineTestFake, SetOpusMaxPlaybackRateMb) {
1282 EXPECT_TRUE(SetupEngine());
1283 int channel_num = voe_.GetLastChannel();
1284 std::vector<cricket::AudioCodec> codecs;
1285 codecs.push_back(kOpusCodec);
1286 codecs[0].bitrate = 0;
1287 codecs[0].SetParam(cricket::kCodecParamMaxPlaybackRate, 8001);
1288 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1289 EXPECT_EQ(cricket::kOpusBandwidthMb,
1290 voe_.GetMaxEncodingBandwidth(channel_num));
1291 webrtc::CodecInst gcodec;
1292 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1293 EXPECT_STREQ("opus", gcodec.plname);
minyue@webrtc.org2dc6f312014-10-31 05:33:10 +00001294
1295 EXPECT_EQ(20000, gcodec.rate);
1296 codecs[0].SetParam(cricket::kCodecParamStereo, "1");
1297 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1298 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1299 EXPECT_EQ(40000, gcodec.rate);
buildbot@webrtc.org5d639b32014-09-10 07:57:12 +00001300}
1301
1302// Test 12000 < maxplaybackrate <= 16000 triggers Opus wide band mode.
1303TEST_F(WebRtcVoiceEngineTestFake, SetOpusMaxPlaybackRateWb) {
1304 EXPECT_TRUE(SetupEngine());
1305 int channel_num = voe_.GetLastChannel();
1306 std::vector<cricket::AudioCodec> codecs;
1307 codecs.push_back(kOpusCodec);
1308 codecs[0].bitrate = 0;
1309 codecs[0].SetParam(cricket::kCodecParamMaxPlaybackRate, 12001);
1310 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1311 EXPECT_EQ(cricket::kOpusBandwidthWb,
1312 voe_.GetMaxEncodingBandwidth(channel_num));
1313 webrtc::CodecInst gcodec;
1314 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1315 EXPECT_STREQ("opus", gcodec.plname);
minyue@webrtc.org2dc6f312014-10-31 05:33:10 +00001316
1317 EXPECT_EQ(20000, gcodec.rate);
1318 codecs[0].SetParam(cricket::kCodecParamStereo, "1");
1319 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1320 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1321 EXPECT_EQ(40000, gcodec.rate);
buildbot@webrtc.org5d639b32014-09-10 07:57:12 +00001322}
1323
1324// Test 16000 < maxplaybackrate <= 24000 triggers Opus super wide band mode.
1325TEST_F(WebRtcVoiceEngineTestFake, SetOpusMaxPlaybackRateSwb) {
1326 EXPECT_TRUE(SetupEngine());
1327 int channel_num = voe_.GetLastChannel();
1328 std::vector<cricket::AudioCodec> codecs;
1329 codecs.push_back(kOpusCodec);
1330 codecs[0].bitrate = 0;
1331 codecs[0].SetParam(cricket::kCodecParamMaxPlaybackRate, 16001);
1332 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1333 EXPECT_EQ(cricket::kOpusBandwidthSwb,
1334 voe_.GetMaxEncodingBandwidth(channel_num));
1335 webrtc::CodecInst gcodec;
1336 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1337 EXPECT_STREQ("opus", gcodec.plname);
minyue@webrtc.org2dc6f312014-10-31 05:33:10 +00001338
buildbot@webrtc.org5d639b32014-09-10 07:57:12 +00001339 EXPECT_EQ(32000, gcodec.rate);
minyue@webrtc.org2dc6f312014-10-31 05:33:10 +00001340 codecs[0].SetParam(cricket::kCodecParamStereo, "1");
1341 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1342 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1343 EXPECT_EQ(64000, gcodec.rate);
buildbot@webrtc.org5d639b32014-09-10 07:57:12 +00001344}
1345
1346// Test 24000 < maxplaybackrate triggers Opus full band mode.
1347TEST_F(WebRtcVoiceEngineTestFake, SetOpusMaxPlaybackRateFb) {
1348 EXPECT_TRUE(SetupEngine());
1349 int channel_num = voe_.GetLastChannel();
1350 std::vector<cricket::AudioCodec> codecs;
1351 codecs.push_back(kOpusCodec);
1352 codecs[0].bitrate = 0;
1353 codecs[0].SetParam(cricket::kCodecParamMaxPlaybackRate, 24001);
1354 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1355 EXPECT_EQ(cricket::kOpusBandwidthFb,
1356 voe_.GetMaxEncodingBandwidth(channel_num));
1357 webrtc::CodecInst gcodec;
1358 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1359 EXPECT_STREQ("opus", gcodec.plname);
minyue@webrtc.org2dc6f312014-10-31 05:33:10 +00001360
buildbot@webrtc.org5d639b32014-09-10 07:57:12 +00001361 EXPECT_EQ(32000, gcodec.rate);
minyue@webrtc.org2dc6f312014-10-31 05:33:10 +00001362 codecs[0].SetParam(cricket::kCodecParamStereo, "1");
1363 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1364 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1365 EXPECT_EQ(64000, gcodec.rate);
buildbot@webrtc.org5d639b32014-09-10 07:57:12 +00001366}
1367
1368// Test Opus that without maxplaybackrate, default playback rate is used.
1369TEST_F(WebRtcVoiceEngineTestFake, DefaultOpusMaxPlaybackRate) {
1370 EXPECT_TRUE(SetupEngine());
1371 int channel_num = voe_.GetLastChannel();
1372 std::vector<cricket::AudioCodec> codecs;
1373 codecs.push_back(kOpusCodec);
1374 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1375 EXPECT_EQ(cricket::kOpusBandwidthFb,
1376 voe_.GetMaxEncodingBandwidth(channel_num));
1377}
1378
1379// Test the with non-Opus, maxplaybackrate has no effect.
1380TEST_F(WebRtcVoiceEngineTestFake, SetNonOpusMaxPlaybackRate) {
1381 EXPECT_TRUE(SetupEngine());
1382 int channel_num = voe_.GetLastChannel();
1383 std::vector<cricket::AudioCodec> codecs;
1384 codecs.push_back(kIsacCodec);
1385 codecs[0].SetParam(cricket::kCodecParamMaxPlaybackRate, 32000);
1386 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1387 EXPECT_EQ(0, voe_.GetMaxEncodingBandwidth(channel_num));
1388}
1389
1390// Test maxplaybackrate can be set on two streams.
1391TEST_F(WebRtcVoiceEngineTestFake, SetOpusMaxPlaybackRateOnTwoStreams) {
1392 EXPECT_TRUE(SetupEngine());
1393 int channel_num = voe_.GetLastChannel();
1394 std::vector<cricket::AudioCodec> codecs;
1395 codecs.push_back(kOpusCodec);
1396 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1397 // Default bandwidth is 24000.
1398 EXPECT_EQ(cricket::kOpusBandwidthFb,
1399 voe_.GetMaxEncodingBandwidth(channel_num));
1400
1401 codecs[0].SetParam(cricket::kCodecParamMaxPlaybackRate, 8000);
1402
1403 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1404 EXPECT_EQ(cricket::kOpusBandwidthNb,
1405 voe_.GetMaxEncodingBandwidth(channel_num));
1406
1407 channel_->AddSendStream(cricket::StreamParams::CreateLegacy(kSsrc2));
1408 channel_num = voe_.GetLastChannel();
1409 EXPECT_EQ(cricket::kOpusBandwidthNb,
1410 voe_.GetMaxEncodingBandwidth(channel_num));
1411}
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +00001412
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001413// Test that we can apply CELT with stereo mode but fail with mono mode.
1414TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecsCelt) {
1415 EXPECT_TRUE(SetupEngine());
1416 int channel_num = voe_.GetLastChannel();
1417 std::vector<cricket::AudioCodec> codecs;
1418 codecs.push_back(kCeltCodec);
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00001419 codecs.push_back(kIsacCodec);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001420 codecs[0].id = 96;
1421 codecs[0].channels = 2;
1422 codecs[0].bitrate = 96000;
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00001423 codecs[1].bitrate = 64000;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001424 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1425 webrtc::CodecInst gcodec;
1426 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1427 EXPECT_EQ(96, gcodec.pltype);
1428 EXPECT_EQ(96000, gcodec.rate);
1429 EXPECT_EQ(2, gcodec.channels);
1430 EXPECT_STREQ("CELT", gcodec.plname);
1431 // Doesn't support mono, expect it to fall back to the next codec in the list.
1432 codecs[0].channels = 1;
1433 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1434 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00001435 EXPECT_EQ(103, gcodec.pltype);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001436 EXPECT_EQ(1, gcodec.channels);
1437 EXPECT_EQ(64000, gcodec.rate);
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00001438 EXPECT_STREQ("ISAC", gcodec.plname);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001439}
1440
1441// Test that we can switch back and forth between CELT and ISAC with CN.
1442TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecsIsacCeltSwitching) {
1443 EXPECT_TRUE(SetupEngine());
1444 int channel_num = voe_.GetLastChannel();
1445 std::vector<cricket::AudioCodec> celt_codecs;
1446 celt_codecs.push_back(kCeltCodec);
1447 EXPECT_TRUE(channel_->SetSendCodecs(celt_codecs));
1448 webrtc::CodecInst gcodec;
1449 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1450 EXPECT_EQ(110, gcodec.pltype);
1451 EXPECT_STREQ("CELT", gcodec.plname);
1452
1453 std::vector<cricket::AudioCodec> isac_codecs;
1454 isac_codecs.push_back(kIsacCodec);
1455 isac_codecs.push_back(kCn16000Codec);
1456 isac_codecs.push_back(kCeltCodec);
1457 EXPECT_TRUE(channel_->SetSendCodecs(isac_codecs));
1458 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1459 EXPECT_EQ(103, gcodec.pltype);
1460 EXPECT_STREQ("ISAC", gcodec.plname);
1461
1462 EXPECT_TRUE(channel_->SetSendCodecs(celt_codecs));
1463 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1464 EXPECT_EQ(110, gcodec.pltype);
1465 EXPECT_STREQ("CELT", gcodec.plname);
1466}
1467
1468// Test that we handle various ways of specifying bitrate.
1469TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecsBitrate) {
1470 EXPECT_TRUE(SetupEngine());
1471 int channel_num = voe_.GetLastChannel();
1472 std::vector<cricket::AudioCodec> codecs;
1473 codecs.push_back(kIsacCodec); // bitrate == 32000
1474 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1475 webrtc::CodecInst gcodec;
1476 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1477 EXPECT_EQ(103, gcodec.pltype);
1478 EXPECT_STREQ("ISAC", gcodec.plname);
1479 EXPECT_EQ(32000, gcodec.rate);
1480
1481 codecs[0].bitrate = 0; // bitrate == default
1482 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1483 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1484 EXPECT_EQ(103, gcodec.pltype);
1485 EXPECT_STREQ("ISAC", gcodec.plname);
1486 EXPECT_EQ(-1, gcodec.rate);
1487
1488 codecs[0].bitrate = 28000; // bitrate == 28000
1489 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1490 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1491 EXPECT_EQ(103, gcodec.pltype);
1492 EXPECT_STREQ("ISAC", gcodec.plname);
1493 EXPECT_EQ(28000, gcodec.rate);
1494
1495 codecs[0] = kPcmuCodec; // bitrate == 64000
1496 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1497 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1498 EXPECT_EQ(0, gcodec.pltype);
1499 EXPECT_STREQ("PCMU", gcodec.plname);
1500 EXPECT_EQ(64000, gcodec.rate);
1501
1502 codecs[0].bitrate = 0; // bitrate == default
1503 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1504 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1505 EXPECT_EQ(0, gcodec.pltype);
1506 EXPECT_STREQ("PCMU", gcodec.plname);
1507 EXPECT_EQ(64000, gcodec.rate);
1508
1509 codecs[0] = kOpusCodec;
1510 codecs[0].bitrate = 0; // bitrate == default
1511 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1512 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1513 EXPECT_EQ(111, gcodec.pltype);
1514 EXPECT_STREQ("opus", gcodec.plname);
1515 EXPECT_EQ(32000, gcodec.rate);
1516}
1517
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00001518// Test that we fail if no codecs are specified.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001519TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecsNoCodecs) {
1520 EXPECT_TRUE(SetupEngine());
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00001521 std::vector<cricket::AudioCodec> codecs;
1522 EXPECT_FALSE(channel_->SetSendCodecs(codecs));
1523}
1524
1525// Test that we can set send codecs even with telephone-event codec as the first
1526// one on the list.
1527TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecsDTMFOnTop) {
1528 EXPECT_TRUE(SetupEngine());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001529 int channel_num = voe_.GetLastChannel();
1530 std::vector<cricket::AudioCodec> codecs;
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00001531 codecs.push_back(kTelephoneEventCodec);
1532 codecs.push_back(kIsacCodec);
1533 codecs.push_back(kPcmuCodec);
1534 codecs[0].id = 98; // DTMF
1535 codecs[1].id = 96;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001536 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1537 webrtc::CodecInst gcodec;
1538 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00001539 EXPECT_EQ(96, gcodec.pltype);
1540 EXPECT_STREQ("ISAC", gcodec.plname);
1541 EXPECT_EQ(98, voe_.GetSendTelephoneEventPayloadType(channel_num));
1542}
1543
1544// Test that we can set send codecs even with CN codec as the first
1545// one on the list.
1546TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecsCNOnTop) {
1547 EXPECT_TRUE(SetupEngine());
1548 int channel_num = voe_.GetLastChannel();
1549 std::vector<cricket::AudioCodec> codecs;
1550 codecs.push_back(kCn16000Codec);
1551 codecs.push_back(kIsacCodec);
1552 codecs.push_back(kPcmuCodec);
1553 codecs[0].id = 98; // wideband CN
1554 codecs[1].id = 96;
1555 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1556 webrtc::CodecInst gcodec;
1557 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1558 EXPECT_EQ(96, gcodec.pltype);
1559 EXPECT_STREQ("ISAC", gcodec.plname);
1560 EXPECT_EQ(98, voe_.GetSendCNPayloadType(channel_num, true));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001561}
1562
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00001563// Test that we set VAD and DTMF types correctly as caller.
1564TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecsCNandDTMFAsCaller) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001565 EXPECT_TRUE(SetupEngine());
1566 int channel_num = voe_.GetLastChannel();
1567 std::vector<cricket::AudioCodec> codecs;
1568 codecs.push_back(kIsacCodec);
1569 codecs.push_back(kPcmuCodec);
1570 // TODO(juberti): cn 32000
1571 codecs.push_back(kCn16000Codec);
1572 codecs.push_back(kCn8000Codec);
1573 codecs.push_back(kTelephoneEventCodec);
1574 codecs.push_back(kRedCodec);
1575 codecs[0].id = 96;
1576 codecs[2].id = 97; // wideband CN
1577 codecs[4].id = 98; // DTMF
1578 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1579 webrtc::CodecInst gcodec;
1580 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1581 EXPECT_EQ(96, gcodec.pltype);
1582 EXPECT_STREQ("ISAC", gcodec.plname);
1583 EXPECT_TRUE(voe_.GetVAD(channel_num));
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +00001584 EXPECT_FALSE(voe_.GetRED(channel_num));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001585 EXPECT_EQ(13, voe_.GetSendCNPayloadType(channel_num, false));
1586 EXPECT_EQ(97, voe_.GetSendCNPayloadType(channel_num, true));
1587 EXPECT_EQ(98, voe_.GetSendTelephoneEventPayloadType(channel_num));
1588}
1589
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00001590// Test that we set VAD and DTMF types correctly as callee.
1591TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecsCNandDTMFAsCallee) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001592 EXPECT_TRUE(engine_.Init(rtc::Thread::Current()));
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00001593 channel_ = engine_.CreateChannel();
1594 EXPECT_TRUE(channel_ != NULL);
1595
1596 int channel_num = voe_.GetLastChannel();
1597 std::vector<cricket::AudioCodec> codecs;
1598 codecs.push_back(kIsacCodec);
1599 codecs.push_back(kPcmuCodec);
1600 // TODO(juberti): cn 32000
1601 codecs.push_back(kCn16000Codec);
1602 codecs.push_back(kCn8000Codec);
1603 codecs.push_back(kTelephoneEventCodec);
1604 codecs.push_back(kRedCodec);
1605 codecs[0].id = 96;
1606 codecs[2].id = 97; // wideband CN
1607 codecs[4].id = 98; // DTMF
1608 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1609 EXPECT_TRUE(channel_->AddSendStream(
1610 cricket::StreamParams::CreateLegacy(kSsrc1)));
1611
1612 webrtc::CodecInst gcodec;
1613 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1614 EXPECT_EQ(96, gcodec.pltype);
1615 EXPECT_STREQ("ISAC", gcodec.plname);
1616 EXPECT_TRUE(voe_.GetVAD(channel_num));
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +00001617 EXPECT_FALSE(voe_.GetRED(channel_num));
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00001618 EXPECT_EQ(13, voe_.GetSendCNPayloadType(channel_num, false));
1619 EXPECT_EQ(97, voe_.GetSendCNPayloadType(channel_num, true));
1620 EXPECT_EQ(98, voe_.GetSendTelephoneEventPayloadType(channel_num));
1621}
1622
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001623// Test that we only apply VAD if we have a CN codec that matches the
1624// send codec clockrate.
1625TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecsCNNoMatch) {
1626 EXPECT_TRUE(SetupEngine());
1627 int channel_num = voe_.GetLastChannel();
1628 std::vector<cricket::AudioCodec> codecs;
1629 // Set ISAC(16K) and CN(16K). VAD should be activated.
1630 codecs.push_back(kIsacCodec);
1631 codecs.push_back(kCn16000Codec);
1632 codecs[1].id = 97;
1633 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1634 webrtc::CodecInst gcodec;
1635 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1636 EXPECT_STREQ("ISAC", gcodec.plname);
1637 EXPECT_TRUE(voe_.GetVAD(channel_num));
1638 EXPECT_EQ(97, voe_.GetSendCNPayloadType(channel_num, true));
1639 // Set PCMU(8K) and CN(16K). VAD should not be activated.
1640 codecs[0] = kPcmuCodec;
1641 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1642 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1643 EXPECT_STREQ("PCMU", gcodec.plname);
1644 EXPECT_FALSE(voe_.GetVAD(channel_num));
1645 // Set PCMU(8K) and CN(8K). VAD should be activated.
1646 codecs[1] = kCn8000Codec;
1647 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1648 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1649 EXPECT_STREQ("PCMU", gcodec.plname);
1650 EXPECT_TRUE(voe_.GetVAD(channel_num));
1651 EXPECT_EQ(13, voe_.GetSendCNPayloadType(channel_num, false));
1652 // Set ISAC(16K) and CN(8K). VAD should not be activated.
1653 codecs[0] = kIsacCodec;
1654 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1655 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1656 EXPECT_STREQ("ISAC", gcodec.plname);
1657 EXPECT_FALSE(voe_.GetVAD(channel_num));
1658}
1659
1660// Test that we perform case-insensitive matching of codec names.
1661TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecsCaseInsensitive) {
1662 EXPECT_TRUE(SetupEngine());
1663 int channel_num = voe_.GetLastChannel();
1664 std::vector<cricket::AudioCodec> codecs;
1665 codecs.push_back(kIsacCodec);
1666 codecs.push_back(kPcmuCodec);
1667 codecs.push_back(kCn16000Codec);
1668 codecs.push_back(kCn8000Codec);
1669 codecs.push_back(kTelephoneEventCodec);
1670 codecs.push_back(kRedCodec);
1671 codecs[0].name = "iSaC";
1672 codecs[0].id = 96;
1673 codecs[2].id = 97; // wideband CN
1674 codecs[4].id = 98; // DTMF
1675 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1676 webrtc::CodecInst gcodec;
1677 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1678 EXPECT_EQ(96, gcodec.pltype);
1679 EXPECT_STREQ("ISAC", gcodec.plname);
1680 EXPECT_TRUE(voe_.GetVAD(channel_num));
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +00001681 EXPECT_FALSE(voe_.GetRED(channel_num));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001682 EXPECT_EQ(13, voe_.GetSendCNPayloadType(channel_num, false));
1683 EXPECT_EQ(97, voe_.GetSendCNPayloadType(channel_num, true));
1684 EXPECT_EQ(98, voe_.GetSendTelephoneEventPayloadType(channel_num));
1685}
1686
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +00001687// Test that we set up RED correctly as caller.
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00001688TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecsREDAsCaller) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001689 EXPECT_TRUE(SetupEngine());
1690 int channel_num = voe_.GetLastChannel();
1691 std::vector<cricket::AudioCodec> codecs;
1692 codecs.push_back(kRedCodec);
1693 codecs.push_back(kIsacCodec);
1694 codecs.push_back(kPcmuCodec);
1695 codecs[0].id = 127;
1696 codecs[0].params[""] = "96/96";
1697 codecs[1].id = 96;
1698 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1699 webrtc::CodecInst gcodec;
1700 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1701 EXPECT_EQ(96, gcodec.pltype);
1702 EXPECT_STREQ("ISAC", gcodec.plname);
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +00001703 EXPECT_TRUE(voe_.GetRED(channel_num));
1704 EXPECT_EQ(127, voe_.GetSendREDPayloadType(channel_num));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001705}
1706
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +00001707// Test that we set up RED correctly as callee.
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00001708TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecsREDAsCallee) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001709 EXPECT_TRUE(engine_.Init(rtc::Thread::Current()));
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00001710 channel_ = engine_.CreateChannel();
1711 EXPECT_TRUE(channel_ != NULL);
1712
1713 int channel_num = voe_.GetLastChannel();
1714 std::vector<cricket::AudioCodec> codecs;
1715 codecs.push_back(kRedCodec);
1716 codecs.push_back(kIsacCodec);
1717 codecs.push_back(kPcmuCodec);
1718 codecs[0].id = 127;
1719 codecs[0].params[""] = "96/96";
1720 codecs[1].id = 96;
1721 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1722 EXPECT_TRUE(channel_->AddSendStream(
1723 cricket::StreamParams::CreateLegacy(kSsrc1)));
1724 webrtc::CodecInst gcodec;
1725 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1726 EXPECT_EQ(96, gcodec.pltype);
1727 EXPECT_STREQ("ISAC", gcodec.plname);
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +00001728 EXPECT_TRUE(voe_.GetRED(channel_num));
1729 EXPECT_EQ(127, voe_.GetSendREDPayloadType(channel_num));
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00001730}
1731
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +00001732// Test that we set up RED correctly if params are omitted.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001733TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecsREDNoParams) {
1734 EXPECT_TRUE(SetupEngine());
1735 int channel_num = voe_.GetLastChannel();
1736 std::vector<cricket::AudioCodec> codecs;
1737 codecs.push_back(kRedCodec);
1738 codecs.push_back(kIsacCodec);
1739 codecs.push_back(kPcmuCodec);
1740 codecs[0].id = 127;
1741 codecs[1].id = 96;
1742 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1743 webrtc::CodecInst gcodec;
1744 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1745 EXPECT_EQ(96, gcodec.pltype);
1746 EXPECT_STREQ("ISAC", gcodec.plname);
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +00001747 EXPECT_TRUE(voe_.GetRED(channel_num));
1748 EXPECT_EQ(127, voe_.GetSendREDPayloadType(channel_num));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001749}
1750
1751// Test that we ignore RED if the parameters aren't named the way we expect.
1752TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecsBadRED1) {
1753 EXPECT_TRUE(SetupEngine());
1754 int channel_num = voe_.GetLastChannel();
1755 std::vector<cricket::AudioCodec> codecs;
1756 codecs.push_back(kRedCodec);
1757 codecs.push_back(kIsacCodec);
1758 codecs.push_back(kPcmuCodec);
1759 codecs[0].id = 127;
1760 codecs[0].params["ABC"] = "96/96";
1761 codecs[1].id = 96;
1762 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1763 webrtc::CodecInst gcodec;
1764 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1765 EXPECT_EQ(96, gcodec.pltype);
1766 EXPECT_STREQ("ISAC", gcodec.plname);
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +00001767 EXPECT_FALSE(voe_.GetRED(channel_num));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001768}
1769
1770// Test that we ignore RED if it uses different primary/secondary encoding.
1771TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecsBadRED2) {
1772 EXPECT_TRUE(SetupEngine());
1773 int channel_num = voe_.GetLastChannel();
1774 std::vector<cricket::AudioCodec> codecs;
1775 codecs.push_back(kRedCodec);
1776 codecs.push_back(kIsacCodec);
1777 codecs.push_back(kPcmuCodec);
1778 codecs[0].id = 127;
1779 codecs[0].params[""] = "96/0";
1780 codecs[1].id = 96;
1781 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1782 webrtc::CodecInst gcodec;
1783 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1784 EXPECT_EQ(96, gcodec.pltype);
1785 EXPECT_STREQ("ISAC", gcodec.plname);
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +00001786 EXPECT_FALSE(voe_.GetRED(channel_num));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001787}
1788
1789// Test that we ignore RED if it uses more than 2 encodings.
1790TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecsBadRED3) {
1791 EXPECT_TRUE(SetupEngine());
1792 int channel_num = voe_.GetLastChannel();
1793 std::vector<cricket::AudioCodec> codecs;
1794 codecs.push_back(kRedCodec);
1795 codecs.push_back(kIsacCodec);
1796 codecs.push_back(kPcmuCodec);
1797 codecs[0].id = 127;
1798 codecs[0].params[""] = "96/96/96";
1799 codecs[1].id = 96;
1800 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1801 webrtc::CodecInst gcodec;
1802 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1803 EXPECT_EQ(96, gcodec.pltype);
1804 EXPECT_STREQ("ISAC", gcodec.plname);
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +00001805 EXPECT_FALSE(voe_.GetRED(channel_num));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001806}
1807
1808// Test that we ignore RED if it has bogus codec ids.
1809TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecsBadRED4) {
1810 EXPECT_TRUE(SetupEngine());
1811 int channel_num = voe_.GetLastChannel();
1812 std::vector<cricket::AudioCodec> codecs;
1813 codecs.push_back(kRedCodec);
1814 codecs.push_back(kIsacCodec);
1815 codecs.push_back(kPcmuCodec);
1816 codecs[0].id = 127;
1817 codecs[0].params[""] = "ABC/ABC";
1818 codecs[1].id = 96;
1819 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1820 webrtc::CodecInst gcodec;
1821 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1822 EXPECT_EQ(96, gcodec.pltype);
1823 EXPECT_STREQ("ISAC", gcodec.plname);
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +00001824 EXPECT_FALSE(voe_.GetRED(channel_num));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001825}
1826
1827// Test that we ignore RED if it refers to a codec that is not present.
1828TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecsBadRED5) {
1829 EXPECT_TRUE(SetupEngine());
1830 int channel_num = voe_.GetLastChannel();
1831 std::vector<cricket::AudioCodec> codecs;
1832 codecs.push_back(kRedCodec);
1833 codecs.push_back(kIsacCodec);
1834 codecs.push_back(kPcmuCodec);
1835 codecs[0].id = 127;
1836 codecs[0].params[""] = "97/97";
1837 codecs[1].id = 96;
1838 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1839 webrtc::CodecInst gcodec;
1840 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1841 EXPECT_EQ(96, gcodec.pltype);
1842 EXPECT_STREQ("ISAC", gcodec.plname);
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +00001843 EXPECT_FALSE(voe_.GetRED(channel_num));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001844}
1845
buildbot@webrtc.org150835e2014-05-06 15:54:38 +00001846// Test support for audio level header extension.
1847TEST_F(WebRtcVoiceEngineTestFake, SendAudioLevelHeaderExtensions) {
1848 TestSetSendRtpHeaderExtensions(kRtpAudioLevelHeaderExtension);
henrike@webrtc.org79047f92014-03-06 23:46:59 +00001849}
buildbot@webrtc.org150835e2014-05-06 15:54:38 +00001850TEST_F(WebRtcVoiceEngineTestFake, RecvAudioLevelHeaderExtensions) {
1851 TestSetRecvRtpHeaderExtensions(kRtpAudioLevelHeaderExtension);
1852}
henrike@webrtc.org79047f92014-03-06 23:46:59 +00001853
buildbot@webrtc.org150835e2014-05-06 15:54:38 +00001854// Test support for absolute send time header extension.
1855TEST_F(WebRtcVoiceEngineTestFake, SendAbsoluteSendTimeHeaderExtensions) {
1856 TestSetSendRtpHeaderExtensions(kRtpAbsoluteSenderTimeHeaderExtension);
1857}
1858TEST_F(WebRtcVoiceEngineTestFake, RecvAbsoluteSendTimeHeaderExtensions) {
1859 TestSetRecvRtpHeaderExtensions(kRtpAbsoluteSenderTimeHeaderExtension);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001860}
1861
1862// Test that we can create a channel and start sending/playing out on it.
1863TEST_F(WebRtcVoiceEngineTestFake, SendAndPlayout) {
1864 EXPECT_TRUE(SetupEngine());
1865 int channel_num = voe_.GetLastChannel();
1866 std::vector<cricket::AudioCodec> codecs;
1867 codecs.push_back(kPcmuCodec);
1868 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1869 EXPECT_TRUE(channel_->SetSend(cricket::SEND_MICROPHONE));
1870 EXPECT_TRUE(voe_.GetSend(channel_num));
1871 EXPECT_TRUE(channel_->SetPlayout(true));
1872 EXPECT_TRUE(voe_.GetPlayout(channel_num));
1873 EXPECT_TRUE(channel_->SetSend(cricket::SEND_NOTHING));
1874 EXPECT_FALSE(voe_.GetSend(channel_num));
1875 EXPECT_TRUE(channel_->SetPlayout(false));
1876 EXPECT_FALSE(voe_.GetPlayout(channel_num));
1877}
1878
wu@webrtc.org9dba5252013-08-05 20:36:57 +00001879// Test that we can add and remove send streams.
1880TEST_F(WebRtcVoiceEngineTestFake, CreateAndDeleteMultipleSendStreams) {
1881 SetupForMultiSendStream();
1882
1883 static const uint32 kSsrcs4[] = {1, 2, 3, 4};
1884
1885 // Set the global state for sending.
1886 EXPECT_TRUE(channel_->SetSend(cricket::SEND_MICROPHONE));
1887
1888 for (unsigned int i = 0; i < ARRAY_SIZE(kSsrcs4); ++i) {
1889 EXPECT_TRUE(channel_->AddSendStream(
1890 cricket::StreamParams::CreateLegacy(kSsrcs4[i])));
1891
1892 // Verify that we are in a sending state for all the created streams.
1893 int channel_num = voe_.GetChannelFromLocalSsrc(kSsrcs4[i]);
1894 EXPECT_TRUE(voe_.GetSend(channel_num));
1895 }
1896
1897 // Remove the first send channel, which is the default channel. It will only
1898 // recycle the default channel but not delete it.
1899 EXPECT_TRUE(channel_->RemoveSendStream(kSsrcs4[0]));
1900 // Stream should already be Removed from the send stream list.
1901 EXPECT_FALSE(channel_->RemoveSendStream(kSsrcs4[0]));
1902 // But the default still exists.
1903 EXPECT_EQ(0, voe_.GetChannelFromLocalSsrc(kSsrcs4[0]));
1904
1905 // Delete the rest of send channel streams.
1906 for (unsigned int i = 1; i < ARRAY_SIZE(kSsrcs4); ++i) {
1907 EXPECT_TRUE(channel_->RemoveSendStream(kSsrcs4[i]));
1908 // Stream should already be deleted.
1909 EXPECT_FALSE(channel_->RemoveSendStream(kSsrcs4[i]));
1910 EXPECT_EQ(-1, voe_.GetChannelFromLocalSsrc(kSsrcs4[i]));
1911 }
1912}
1913
1914// Test SetSendCodecs correctly configure the codecs in all send streams.
1915TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecsWithMultipleSendStreams) {
1916 SetupForMultiSendStream();
1917
1918 static const uint32 kSsrcs4[] = {1, 2, 3, 4};
1919 // Create send streams.
1920 for (unsigned int i = 0; i < ARRAY_SIZE(kSsrcs4); ++i) {
1921 EXPECT_TRUE(channel_->AddSendStream(
1922 cricket::StreamParams::CreateLegacy(kSsrcs4[i])));
1923 }
1924
1925 std::vector<cricket::AudioCodec> codecs;
1926 // Set ISAC(16K) and CN(16K). VAD should be activated.
1927 codecs.push_back(kIsacCodec);
1928 codecs.push_back(kCn16000Codec);
1929 codecs[1].id = 97;
1930 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1931
1932 // Verify ISAC and VAD are corrected configured on all send channels.
1933 webrtc::CodecInst gcodec;
1934 for (unsigned int i = 0; i < ARRAY_SIZE(kSsrcs4); ++i) {
1935 int channel_num = voe_.GetChannelFromLocalSsrc(kSsrcs4[i]);
1936 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1937 EXPECT_STREQ("ISAC", gcodec.plname);
1938 EXPECT_TRUE(voe_.GetVAD(channel_num));
1939 EXPECT_EQ(97, voe_.GetSendCNPayloadType(channel_num, true));
1940 }
1941
1942 // Change to PCMU(8K) and CN(16K). VAD should not be activated.
1943 codecs[0] = kPcmuCodec;
1944 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1945 for (unsigned int i = 0; i < ARRAY_SIZE(kSsrcs4); ++i) {
1946 int channel_num = voe_.GetChannelFromLocalSsrc(kSsrcs4[i]);
1947 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1948 EXPECT_STREQ("PCMU", gcodec.plname);
1949 EXPECT_FALSE(voe_.GetVAD(channel_num));
1950 }
1951}
1952
1953// Test we can SetSend on all send streams correctly.
1954TEST_F(WebRtcVoiceEngineTestFake, SetSendWithMultipleSendStreams) {
1955 SetupForMultiSendStream();
1956
1957 static const uint32 kSsrcs4[] = {1, 2, 3, 4};
1958 // Create the send channels and they should be a SEND_NOTHING date.
1959 for (unsigned int i = 0; i < ARRAY_SIZE(kSsrcs4); ++i) {
1960 EXPECT_TRUE(channel_->AddSendStream(
1961 cricket::StreamParams::CreateLegacy(kSsrcs4[i])));
1962 int channel_num = voe_.GetLastChannel();
1963 EXPECT_FALSE(voe_.GetSend(channel_num));
1964 }
1965
1966 // Set the global state for starting sending.
1967 EXPECT_TRUE(channel_->SetSend(cricket::SEND_MICROPHONE));
1968 for (unsigned int i = 0; i < ARRAY_SIZE(kSsrcs4); ++i) {
1969 // Verify that we are in a sending state for all the send streams.
1970 int channel_num = voe_.GetChannelFromLocalSsrc(kSsrcs4[i]);
1971 EXPECT_TRUE(voe_.GetSend(channel_num));
1972 }
1973
1974 // Set the global state for stopping sending.
1975 EXPECT_TRUE(channel_->SetSend(cricket::SEND_NOTHING));
1976 for (unsigned int i = 1; i < ARRAY_SIZE(kSsrcs4); ++i) {
1977 // Verify that we are in a stop state for all the send streams.
1978 int channel_num = voe_.GetChannelFromLocalSsrc(kSsrcs4[i]);
1979 EXPECT_FALSE(voe_.GetSend(channel_num));
1980 }
1981}
1982
1983// Test we can set the correct statistics on all send streams.
1984TEST_F(WebRtcVoiceEngineTestFake, GetStatsWithMultipleSendStreams) {
1985 SetupForMultiSendStream();
1986
1987 static const uint32 kSsrcs4[] = {1, 2, 3, 4};
1988 // Create send streams.
1989 for (unsigned int i = 0; i < ARRAY_SIZE(kSsrcs4); ++i) {
1990 EXPECT_TRUE(channel_->AddSendStream(
1991 cricket::StreamParams::CreateLegacy(kSsrcs4[i])));
1992 }
buildbot@webrtc.org7e71b772014-06-13 01:14:01 +00001993 // Create a receive stream to check that none of the send streams end up in
1994 // the receive stream stats.
1995 EXPECT_TRUE(channel_->AddRecvStream(
1996 cricket::StreamParams::CreateLegacy(kSsrc2)));
wu@webrtc.org9dba5252013-08-05 20:36:57 +00001997 // We need send codec to be set to get all stats.
1998 std::vector<cricket::AudioCodec> codecs;
1999 codecs.push_back(kPcmuCodec);
2000 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
buildbot@webrtc.org7e71b772014-06-13 01:14:01 +00002001 EXPECT_TRUE(channel_->SetRecvCodecs(codecs));
wu@webrtc.org9dba5252013-08-05 20:36:57 +00002002
2003 cricket::VoiceMediaInfo info;
2004 EXPECT_EQ(true, channel_->GetStats(&info));
2005 EXPECT_EQ(static_cast<size_t>(ARRAY_SIZE(kSsrcs4)), info.senders.size());
2006
2007 // Verify the statistic information is correct.
2008 for (unsigned int i = 0; i < ARRAY_SIZE(kSsrcs4); ++i) {
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +00002009 EXPECT_EQ(kSsrcs4[i], info.senders[i].ssrc());
wu@webrtc.org9dba5252013-08-05 20:36:57 +00002010 EXPECT_EQ(kPcmuCodec.name, info.senders[i].codec_name);
2011 EXPECT_EQ(cricket::kIntStatValue, info.senders[i].bytes_sent);
2012 EXPECT_EQ(cricket::kIntStatValue, info.senders[i].packets_sent);
2013 EXPECT_EQ(cricket::kIntStatValue, info.senders[i].packets_lost);
2014 EXPECT_EQ(cricket::kFractionLostStatValue, info.senders[i].fraction_lost);
2015 EXPECT_EQ(cricket::kIntStatValue, info.senders[i].ext_seqnum);
2016 EXPECT_EQ(cricket::kIntStatValue, info.senders[i].rtt_ms);
2017 EXPECT_EQ(cricket::kIntStatValue, info.senders[i].jitter_ms);
buildbot@webrtc.org7e71b772014-06-13 01:14:01 +00002018 EXPECT_EQ(kPcmuCodec.name, info.senders[i].codec_name);
wu@webrtc.org9dba5252013-08-05 20:36:57 +00002019 }
2020
buildbot@webrtc.org7e71b772014-06-13 01:14:01 +00002021 EXPECT_EQ(0u, info.receivers.size());
2022 DeliverPacket(kPcmuFrame, sizeof(kPcmuFrame));
2023 EXPECT_EQ(true, channel_->GetStats(&info));
2024
wu@webrtc.org9dba5252013-08-05 20:36:57 +00002025 EXPECT_EQ(1u, info.receivers.size());
buildbot@webrtc.org7e71b772014-06-13 01:14:01 +00002026 EXPECT_EQ(cricket::kIntStatValue, info.receivers[0].bytes_rcvd);
2027 EXPECT_EQ(cricket::kIntStatValue, info.receivers[0].packets_rcvd);
2028 EXPECT_EQ(cricket::kIntStatValue, info.receivers[0].packets_lost);
2029 EXPECT_EQ(cricket::kIntStatValue, info.receivers[0].ext_seqnum);
2030 EXPECT_EQ(kPcmuCodec.name, info.receivers[0].codec_name);
wu@webrtc.org9dba5252013-08-05 20:36:57 +00002031}
2032
wu@webrtc.org9dba5252013-08-05 20:36:57 +00002033// Test that we can add and remove receive streams, and do proper send/playout.
2034// We can receive on multiple streams while sending one stream.
2035TEST_F(WebRtcVoiceEngineTestFake, PlayoutWithMultipleStreams) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002036 EXPECT_TRUE(SetupEngine());
2037 int channel_num1 = voe_.GetLastChannel();
2038
2039 // Start playout on the default channel.
2040 EXPECT_TRUE(channel_->SetOptions(options_conference_));
2041 EXPECT_TRUE(channel_->SetPlayout(true));
2042 EXPECT_TRUE(voe_.GetPlayout(channel_num1));
2043
2044 // Adding another stream should disable playout on the default channel.
2045 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(2)));
2046 int channel_num2 = voe_.GetLastChannel();
2047 std::vector<cricket::AudioCodec> codecs;
2048 codecs.push_back(kPcmuCodec);
2049 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
2050 EXPECT_TRUE(channel_->SetSend(cricket::SEND_MICROPHONE));
2051 EXPECT_TRUE(voe_.GetSend(channel_num1));
2052 EXPECT_FALSE(voe_.GetSend(channel_num2));
2053
2054 // Make sure only the new channel is played out.
2055 EXPECT_FALSE(voe_.GetPlayout(channel_num1));
2056 EXPECT_TRUE(voe_.GetPlayout(channel_num2));
2057
2058 // Adding yet another stream should have stream 2 and 3 enabled for playout.
2059 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(3)));
2060 int channel_num3 = voe_.GetLastChannel();
2061 EXPECT_FALSE(voe_.GetPlayout(channel_num1));
2062 EXPECT_TRUE(voe_.GetPlayout(channel_num2));
2063 EXPECT_TRUE(voe_.GetPlayout(channel_num3));
2064 EXPECT_FALSE(voe_.GetSend(channel_num3));
2065
2066 // Stop sending.
2067 EXPECT_TRUE(channel_->SetSend(cricket::SEND_NOTHING));
2068 EXPECT_FALSE(voe_.GetSend(channel_num1));
2069 EXPECT_FALSE(voe_.GetSend(channel_num2));
2070 EXPECT_FALSE(voe_.GetSend(channel_num3));
2071
2072 // Stop playout.
2073 EXPECT_TRUE(channel_->SetPlayout(false));
2074 EXPECT_FALSE(voe_.GetPlayout(channel_num1));
2075 EXPECT_FALSE(voe_.GetPlayout(channel_num2));
2076 EXPECT_FALSE(voe_.GetPlayout(channel_num3));
2077
2078 // Restart playout and make sure the default channel still is not played out.
2079 EXPECT_TRUE(channel_->SetPlayout(true));
2080 EXPECT_FALSE(voe_.GetPlayout(channel_num1));
2081 EXPECT_TRUE(voe_.GetPlayout(channel_num2));
2082 EXPECT_TRUE(voe_.GetPlayout(channel_num3));
2083
2084 // Now remove the new streams and verify that the default channel is
2085 // played out again.
2086 EXPECT_TRUE(channel_->RemoveRecvStream(3));
2087 EXPECT_TRUE(channel_->RemoveRecvStream(2));
2088
2089 EXPECT_TRUE(voe_.GetPlayout(channel_num1));
2090}
2091
2092// Test that we can set the devices to use.
2093TEST_F(WebRtcVoiceEngineTestFake, SetDevices) {
2094 EXPECT_TRUE(SetupEngine());
2095 int channel_num = voe_.GetLastChannel();
2096 std::vector<cricket::AudioCodec> codecs;
2097 codecs.push_back(kPcmuCodec);
2098 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
2099
2100 cricket::Device default_dev(cricket::kFakeDefaultDeviceName,
2101 cricket::kFakeDefaultDeviceId);
2102 cricket::Device dev(cricket::kFakeDeviceName,
2103 cricket::kFakeDeviceId);
2104
2105 // Test SetDevices() while not sending or playing.
2106 EXPECT_TRUE(engine_.SetDevices(&default_dev, &default_dev));
2107
2108 // Test SetDevices() while sending and playing.
2109 EXPECT_TRUE(engine_.SetLocalMonitor(true));
2110 EXPECT_TRUE(channel_->SetSend(cricket::SEND_MICROPHONE));
2111 EXPECT_TRUE(channel_->SetPlayout(true));
2112 EXPECT_TRUE(voe_.GetRecordingMicrophone());
2113 EXPECT_TRUE(voe_.GetSend(channel_num));
2114 EXPECT_TRUE(voe_.GetPlayout(channel_num));
2115
2116 EXPECT_TRUE(engine_.SetDevices(&dev, &dev));
2117
2118 EXPECT_TRUE(voe_.GetRecordingMicrophone());
2119 EXPECT_TRUE(voe_.GetSend(channel_num));
2120 EXPECT_TRUE(voe_.GetPlayout(channel_num));
2121
2122 // Test that failure to open newly selected devices does not prevent opening
2123 // ones after that.
2124 voe_.set_fail_start_recording_microphone(true);
2125 voe_.set_playout_fail_channel(channel_num);
2126 voe_.set_send_fail_channel(channel_num);
2127
2128 EXPECT_FALSE(engine_.SetDevices(&default_dev, &default_dev));
2129
2130 EXPECT_FALSE(voe_.GetRecordingMicrophone());
2131 EXPECT_FALSE(voe_.GetSend(channel_num));
2132 EXPECT_FALSE(voe_.GetPlayout(channel_num));
2133
2134 voe_.set_fail_start_recording_microphone(false);
2135 voe_.set_playout_fail_channel(-1);
2136 voe_.set_send_fail_channel(-1);
2137
2138 EXPECT_TRUE(engine_.SetDevices(&dev, &dev));
2139
2140 EXPECT_TRUE(voe_.GetRecordingMicrophone());
2141 EXPECT_TRUE(voe_.GetSend(channel_num));
2142 EXPECT_TRUE(voe_.GetPlayout(channel_num));
2143}
2144
2145// Test that we can set the devices to use even if we failed to
2146// open the initial ones.
2147TEST_F(WebRtcVoiceEngineTestFake, SetDevicesWithInitiallyBadDevices) {
2148 EXPECT_TRUE(SetupEngine());
2149 int channel_num = voe_.GetLastChannel();
2150 std::vector<cricket::AudioCodec> codecs;
2151 codecs.push_back(kPcmuCodec);
2152 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
2153
2154 cricket::Device default_dev(cricket::kFakeDefaultDeviceName,
2155 cricket::kFakeDefaultDeviceId);
2156 cricket::Device dev(cricket::kFakeDeviceName,
2157 cricket::kFakeDeviceId);
2158
2159 // Test that failure to open devices selected before starting
2160 // send/play does not prevent opening newly selected ones after that.
2161 voe_.set_fail_start_recording_microphone(true);
2162 voe_.set_playout_fail_channel(channel_num);
2163 voe_.set_send_fail_channel(channel_num);
2164
2165 EXPECT_TRUE(engine_.SetDevices(&default_dev, &default_dev));
2166
2167 EXPECT_FALSE(engine_.SetLocalMonitor(true));
2168 EXPECT_FALSE(channel_->SetSend(cricket::SEND_MICROPHONE));
2169 EXPECT_FALSE(channel_->SetPlayout(true));
2170 EXPECT_FALSE(voe_.GetRecordingMicrophone());
2171 EXPECT_FALSE(voe_.GetSend(channel_num));
2172 EXPECT_FALSE(voe_.GetPlayout(channel_num));
2173
2174 voe_.set_fail_start_recording_microphone(false);
2175 voe_.set_playout_fail_channel(-1);
2176 voe_.set_send_fail_channel(-1);
2177
2178 EXPECT_TRUE(engine_.SetDevices(&dev, &dev));
2179
2180 EXPECT_TRUE(voe_.GetRecordingMicrophone());
2181 EXPECT_TRUE(voe_.GetSend(channel_num));
2182 EXPECT_TRUE(voe_.GetPlayout(channel_num));
2183}
2184
2185// Test that we can create a channel configured for multi-point conferences,
2186// and start sending/playing out on it.
2187TEST_F(WebRtcVoiceEngineTestFake, ConferenceSendAndPlayout) {
2188 EXPECT_TRUE(SetupEngine());
2189 int channel_num = voe_.GetLastChannel();
2190 EXPECT_TRUE(channel_->SetOptions(options_conference_));
2191 std::vector<cricket::AudioCodec> codecs;
2192 codecs.push_back(kPcmuCodec);
2193 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
2194 EXPECT_TRUE(channel_->SetSend(cricket::SEND_MICROPHONE));
2195 EXPECT_TRUE(voe_.GetSend(channel_num));
2196}
2197
2198// Test that we can create a channel configured for Codian bridges,
2199// and start sending/playing out on it.
2200TEST_F(WebRtcVoiceEngineTestFake, CodianSendAndPlayout) {
2201 EXPECT_TRUE(SetupEngine());
2202 int channel_num = voe_.GetLastChannel();
2203 webrtc::AgcConfig agc_config;
2204 EXPECT_EQ(0, voe_.GetAgcConfig(agc_config));
2205 EXPECT_EQ(0, agc_config.targetLeveldBOv);
2206 EXPECT_TRUE(channel_->SetOptions(options_adjust_agc_));
2207 std::vector<cricket::AudioCodec> codecs;
2208 codecs.push_back(kPcmuCodec);
2209 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
2210 EXPECT_TRUE(channel_->SetSend(cricket::SEND_MICROPHONE));
2211 EXPECT_TRUE(voe_.GetSend(channel_num));
2212 EXPECT_EQ(0, voe_.GetAgcConfig(agc_config));
2213 EXPECT_EQ(agc_config.targetLeveldBOv, 10); // level was attenuated
2214 EXPECT_TRUE(channel_->SetPlayout(true));
2215 EXPECT_TRUE(voe_.GetPlayout(channel_num));
2216 EXPECT_TRUE(channel_->SetSend(cricket::SEND_NOTHING));
2217 EXPECT_FALSE(voe_.GetSend(channel_num));
2218 EXPECT_EQ(0, voe_.GetAgcConfig(agc_config));
2219 EXPECT_EQ(0, agc_config.targetLeveldBOv); // level was restored
2220 EXPECT_TRUE(channel_->SetPlayout(false));
2221 EXPECT_FALSE(voe_.GetPlayout(channel_num));
2222}
2223
wu@webrtc.org97077a32013-10-25 21:18:33 +00002224TEST_F(WebRtcVoiceEngineTestFake, TxAgcConfigViaOptions) {
2225 EXPECT_TRUE(SetupEngine());
2226 webrtc::AgcConfig agc_config;
2227 EXPECT_EQ(0, voe_.GetAgcConfig(agc_config));
2228 EXPECT_EQ(0, agc_config.targetLeveldBOv);
2229
2230 cricket::AudioOptions options;
2231 options.tx_agc_target_dbov.Set(3);
2232 options.tx_agc_digital_compression_gain.Set(9);
2233 options.tx_agc_limiter.Set(true);
2234 options.auto_gain_control.Set(true);
2235 EXPECT_TRUE(engine_.SetOptions(options));
2236
2237 EXPECT_EQ(0, voe_.GetAgcConfig(agc_config));
2238 EXPECT_EQ(3, agc_config.targetLeveldBOv);
2239 EXPECT_EQ(9, agc_config.digitalCompressionGaindB);
2240 EXPECT_TRUE(agc_config.limiterEnable);
2241
2242 // Check interaction with adjust_agc_delta. Both should be respected, for
2243 // backwards compatibility.
2244 options.adjust_agc_delta.Set(-10);
2245 EXPECT_TRUE(engine_.SetOptions(options));
2246
2247 EXPECT_EQ(0, voe_.GetAgcConfig(agc_config));
2248 EXPECT_EQ(13, agc_config.targetLeveldBOv);
2249}
2250
2251TEST_F(WebRtcVoiceEngineTestFake, RxAgcConfigViaOptions) {
2252 EXPECT_TRUE(SetupEngine());
2253 int channel_num = voe_.GetLastChannel();
2254 cricket::AudioOptions options;
2255 options.rx_agc_target_dbov.Set(6);
2256 options.rx_agc_digital_compression_gain.Set(0);
2257 options.rx_agc_limiter.Set(true);
2258 options.rx_auto_gain_control.Set(true);
2259 EXPECT_TRUE(channel_->SetOptions(options));
2260
2261 webrtc::AgcConfig agc_config;
2262 EXPECT_EQ(0, engine_.voe()->processing()->GetRxAgcConfig(
2263 channel_num, agc_config));
2264 EXPECT_EQ(6, agc_config.targetLeveldBOv);
2265 EXPECT_EQ(0, agc_config.digitalCompressionGaindB);
2266 EXPECT_TRUE(agc_config.limiterEnable);
2267}
2268
2269TEST_F(WebRtcVoiceEngineTestFake, SampleRatesViaOptions) {
2270 EXPECT_TRUE(SetupEngine());
2271 cricket::AudioOptions options;
2272 options.recording_sample_rate.Set(48000u);
2273 options.playout_sample_rate.Set(44100u);
2274 EXPECT_TRUE(engine_.SetOptions(options));
2275
2276 unsigned int recording_sample_rate, playout_sample_rate;
2277 EXPECT_EQ(0, voe_.RecordingSampleRate(&recording_sample_rate));
2278 EXPECT_EQ(0, voe_.PlayoutSampleRate(&playout_sample_rate));
2279 EXPECT_EQ(48000u, recording_sample_rate);
2280 EXPECT_EQ(44100u, playout_sample_rate);
2281}
2282
2283TEST_F(WebRtcVoiceEngineTestFake, TraceFilterViaTraceOptions) {
2284 EXPECT_TRUE(SetupEngine());
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002285 engine_.SetLogging(rtc::LS_INFO, "");
wu@webrtc.org97077a32013-10-25 21:18:33 +00002286 EXPECT_EQ(
2287 // Info:
2288 webrtc::kTraceStateInfo | webrtc::kTraceInfo |
2289 // Warning:
2290 webrtc::kTraceTerseInfo | webrtc::kTraceWarning |
2291 // Error:
2292 webrtc::kTraceError | webrtc::kTraceCritical,
2293 static_cast<int>(trace_wrapper_->filter_));
2294 // Now set it explicitly
2295 std::string filter =
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002296 "tracefilter " + rtc::ToString(webrtc::kTraceDefault);
2297 engine_.SetLogging(rtc::LS_VERBOSE, filter.c_str());
wu@webrtc.org97077a32013-10-25 21:18:33 +00002298 EXPECT_EQ(static_cast<unsigned int>(webrtc::kTraceDefault),
2299 trace_wrapper_->filter_);
2300}
2301
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002302// Test that we can set the outgoing SSRC properly.
2303// SSRC is set in SetupEngine by calling AddSendStream.
2304TEST_F(WebRtcVoiceEngineTestFake, SetSendSsrc) {
2305 EXPECT_TRUE(SetupEngine());
2306 int channel_num = voe_.GetLastChannel();
2307 unsigned int send_ssrc;
2308 EXPECT_EQ(0, voe_.GetLocalSSRC(channel_num, send_ssrc));
2309 EXPECT_NE(0U, send_ssrc);
2310 EXPECT_EQ(0, voe_.GetLocalSSRC(channel_num, send_ssrc));
2311 EXPECT_EQ(kSsrc1, send_ssrc);
2312}
2313
2314TEST_F(WebRtcVoiceEngineTestFake, GetStats) {
2315 // Setup. We need send codec to be set to get all stats.
2316 EXPECT_TRUE(SetupEngine());
buildbot@webrtc.org7e71b772014-06-13 01:14:01 +00002317 // SetupEngine adds a send stream with kSsrc1, so the receive stream has to
2318 // use a different SSRC.
2319 EXPECT_TRUE(channel_->AddRecvStream(
2320 cricket::StreamParams::CreateLegacy(kSsrc2)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002321 std::vector<cricket::AudioCodec> codecs;
2322 codecs.push_back(kPcmuCodec);
2323 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
buildbot@webrtc.org7e71b772014-06-13 01:14:01 +00002324 EXPECT_TRUE(channel_->SetRecvCodecs(codecs));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002325
2326 cricket::VoiceMediaInfo info;
2327 EXPECT_EQ(true, channel_->GetStats(&info));
2328 EXPECT_EQ(1u, info.senders.size());
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +00002329 EXPECT_EQ(kSsrc1, info.senders[0].ssrc());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002330 EXPECT_EQ(kPcmuCodec.name, info.senders[0].codec_name);
2331 EXPECT_EQ(cricket::kIntStatValue, info.senders[0].bytes_sent);
2332 EXPECT_EQ(cricket::kIntStatValue, info.senders[0].packets_sent);
2333 EXPECT_EQ(cricket::kIntStatValue, info.senders[0].packets_lost);
2334 EXPECT_EQ(cricket::kFractionLostStatValue, info.senders[0].fraction_lost);
2335 EXPECT_EQ(cricket::kIntStatValue, info.senders[0].ext_seqnum);
2336 EXPECT_EQ(cricket::kIntStatValue, info.senders[0].rtt_ms);
2337 EXPECT_EQ(cricket::kIntStatValue, info.senders[0].jitter_ms);
buildbot@webrtc.org7e71b772014-06-13 01:14:01 +00002338 EXPECT_EQ(kPcmuCodec.name, info.senders[0].codec_name);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002339 // TODO(sriniv): Add testing for more fields. These are not populated
2340 // in FakeWebrtcVoiceEngine yet.
2341 // EXPECT_EQ(cricket::kIntStatValue, info.senders[0].audio_level);
2342 // EXPECT_EQ(cricket::kIntStatValue, info.senders[0].echo_delay_median_ms);
2343 // EXPECT_EQ(cricket::kIntStatValue, info.senders[0].echo_delay_std_ms);
2344 // EXPECT_EQ(cricket::kIntStatValue, info.senders[0].echo_return_loss);
2345 // EXPECT_EQ(cricket::kIntStatValue,
2346 // info.senders[0].echo_return_loss_enhancement);
2347
buildbot@webrtc.org7e71b772014-06-13 01:14:01 +00002348 EXPECT_EQ(0u, info.receivers.size());
2349 DeliverPacket(kPcmuFrame, sizeof(kPcmuFrame));
2350 EXPECT_EQ(true, channel_->GetStats(&info));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002351 EXPECT_EQ(1u, info.receivers.size());
buildbot@webrtc.org7e71b772014-06-13 01:14:01 +00002352
2353 EXPECT_EQ(cricket::kIntStatValue, info.receivers[0].bytes_rcvd);
2354 EXPECT_EQ(cricket::kIntStatValue, info.receivers[0].packets_rcvd);
2355 EXPECT_EQ(cricket::kIntStatValue, info.receivers[0].packets_lost);
2356 EXPECT_EQ(cricket::kIntStatValue, info.receivers[0].ext_seqnum);
2357 EXPECT_EQ(kPcmuCodec.name, info.receivers[0].codec_name);
2358 // TODO(sriniv): Add testing for more receiver fields.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002359}
2360
2361// Test that we can set the outgoing SSRC properly with multiple streams.
2362// SSRC is set in SetupEngine by calling AddSendStream.
2363TEST_F(WebRtcVoiceEngineTestFake, SetSendSsrcWithMultipleStreams) {
2364 EXPECT_TRUE(SetupEngine());
2365 EXPECT_TRUE(channel_->SetOptions(options_conference_));
2366 int channel_num1 = voe_.GetLastChannel();
2367 unsigned int send_ssrc;
2368 EXPECT_EQ(0, voe_.GetLocalSSRC(channel_num1, send_ssrc));
2369 EXPECT_EQ(kSsrc1, send_ssrc);
2370
2371 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(2)));
2372 int channel_num2 = voe_.GetLastChannel();
2373 EXPECT_EQ(0, voe_.GetLocalSSRC(channel_num2, send_ssrc));
2374 EXPECT_EQ(kSsrc1, send_ssrc);
2375}
2376
2377// Test that the local SSRC is the same on sending and receiving channels if the
2378// receive channel is created before the send channel.
2379TEST_F(WebRtcVoiceEngineTestFake, SetSendSsrcAfterCreatingReceiveChannel) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002380 EXPECT_TRUE(engine_.Init(rtc::Thread::Current()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002381 channel_ = engine_.CreateChannel();
2382 EXPECT_TRUE(channel_->SetOptions(options_conference_));
2383
2384 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(1)));
2385 int receive_channel_num = voe_.GetLastChannel();
2386 EXPECT_TRUE(channel_->AddSendStream(
2387 cricket::StreamParams::CreateLegacy(1234)));
2388 int send_channel_num = voe_.GetLastChannel();
2389
2390 unsigned int ssrc = 0;
2391 EXPECT_EQ(0, voe_.GetLocalSSRC(send_channel_num, ssrc));
2392 EXPECT_EQ(1234U, ssrc);
2393 ssrc = 0;
2394 EXPECT_EQ(0, voe_.GetLocalSSRC(receive_channel_num, ssrc));
2395 EXPECT_EQ(1234U, ssrc);
2396}
2397
2398// Test that we can properly receive packets.
2399TEST_F(WebRtcVoiceEngineTestFake, Recv) {
2400 EXPECT_TRUE(SetupEngine());
2401 int channel_num = voe_.GetLastChannel();
2402 DeliverPacket(kPcmuFrame, sizeof(kPcmuFrame));
2403 EXPECT_TRUE(voe_.CheckPacket(channel_num, kPcmuFrame,
2404 sizeof(kPcmuFrame)));
2405}
2406
2407// Test that we can properly receive packets on multiple streams.
2408TEST_F(WebRtcVoiceEngineTestFake, RecvWithMultipleStreams) {
2409 EXPECT_TRUE(SetupEngine());
2410 EXPECT_TRUE(channel_->SetOptions(options_conference_));
2411 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(1)));
2412 int channel_num1 = voe_.GetLastChannel();
2413 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(2)));
2414 int channel_num2 = voe_.GetLastChannel();
2415 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(3)));
2416 int channel_num3 = voe_.GetLastChannel();
2417 // Create packets with the right SSRCs.
2418 char packets[4][sizeof(kPcmuFrame)];
2419 for (size_t i = 0; i < ARRAY_SIZE(packets); ++i) {
2420 memcpy(packets[i], kPcmuFrame, sizeof(kPcmuFrame));
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002421 rtc::SetBE32(packets[i] + 8, static_cast<uint32>(i));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002422 }
2423 EXPECT_TRUE(voe_.CheckNoPacket(channel_num1));
2424 EXPECT_TRUE(voe_.CheckNoPacket(channel_num2));
2425 EXPECT_TRUE(voe_.CheckNoPacket(channel_num3));
2426 DeliverPacket(packets[0], sizeof(packets[0]));
2427 EXPECT_TRUE(voe_.CheckNoPacket(channel_num1));
2428 EXPECT_TRUE(voe_.CheckNoPacket(channel_num2));
2429 EXPECT_TRUE(voe_.CheckNoPacket(channel_num3));
2430 DeliverPacket(packets[1], sizeof(packets[1]));
2431 EXPECT_TRUE(voe_.CheckPacket(channel_num1, packets[1],
2432 sizeof(packets[1])));
2433 EXPECT_TRUE(voe_.CheckNoPacket(channel_num2));
2434 EXPECT_TRUE(voe_.CheckNoPacket(channel_num3));
2435 DeliverPacket(packets[2], sizeof(packets[2]));
2436 EXPECT_TRUE(voe_.CheckNoPacket(channel_num1));
2437 EXPECT_TRUE(voe_.CheckPacket(channel_num2, packets[2],
2438 sizeof(packets[2])));
2439 EXPECT_TRUE(voe_.CheckNoPacket(channel_num3));
2440 DeliverPacket(packets[3], sizeof(packets[3]));
2441 EXPECT_TRUE(voe_.CheckNoPacket(channel_num1));
2442 EXPECT_TRUE(voe_.CheckNoPacket(channel_num2));
2443 EXPECT_TRUE(voe_.CheckPacket(channel_num3, packets[3],
2444 sizeof(packets[3])));
2445 EXPECT_TRUE(channel_->RemoveRecvStream(3));
2446 EXPECT_TRUE(channel_->RemoveRecvStream(2));
2447 EXPECT_TRUE(channel_->RemoveRecvStream(1));
2448}
2449
2450// Test that we properly handle failures to add a stream.
2451TEST_F(WebRtcVoiceEngineTestFake, AddStreamFail) {
2452 EXPECT_TRUE(SetupEngine());
2453 voe_.set_fail_create_channel(true);
2454 EXPECT_TRUE(channel_->SetOptions(options_conference_));
2455 EXPECT_FALSE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(2)));
2456
2457 // In 1:1 call, we should not try to create a new channel.
2458 cricket::AudioOptions options_no_conference_;
2459 options_no_conference_.conference_mode.Set(false);
2460 EXPECT_TRUE(channel_->SetOptions(options_no_conference_));
2461 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(2)));
2462}
2463
2464// Test that AddRecvStream doesn't create new channel for 1:1 call.
2465TEST_F(WebRtcVoiceEngineTestFake, AddRecvStream1On1) {
2466 EXPECT_TRUE(SetupEngine());
2467 int channel_num = voe_.GetLastChannel();
2468 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(1)));
2469 EXPECT_EQ(channel_num, voe_.GetLastChannel());
2470}
2471
2472// Test that after adding a recv stream, we do not decode more codecs than
2473// those previously passed into SetRecvCodecs.
2474TEST_F(WebRtcVoiceEngineTestFake, AddRecvStreamUnsupportedCodec) {
2475 EXPECT_TRUE(SetupEngine());
2476 EXPECT_TRUE(channel_->SetOptions(options_conference_));
2477 std::vector<cricket::AudioCodec> codecs;
2478 codecs.push_back(kIsacCodec);
2479 codecs.push_back(kPcmuCodec);
2480 EXPECT_TRUE(channel_->SetRecvCodecs(codecs));
2481 EXPECT_TRUE(channel_->AddRecvStream(
2482 cricket::StreamParams::CreateLegacy(kSsrc1)));
2483 int channel_num2 = voe_.GetLastChannel();
2484 webrtc::CodecInst gcodec;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002485 rtc::strcpyn(gcodec.plname, ARRAY_SIZE(gcodec.plname), "CELT");
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002486 gcodec.plfreq = 32000;
2487 gcodec.channels = 2;
2488 EXPECT_EQ(-1, voe_.GetRecPayloadType(channel_num2, gcodec));
2489}
2490
2491// Test that we properly clean up any streams that were added, even if
2492// not explicitly removed.
2493TEST_F(WebRtcVoiceEngineTestFake, StreamCleanup) {
2494 EXPECT_TRUE(SetupEngine());
2495 EXPECT_TRUE(channel_->SetOptions(options_conference_));
2496 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(1)));
2497 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(2)));
2498 EXPECT_EQ(3, voe_.GetNumChannels()); // default channel + 2 added
2499 delete channel_;
2500 channel_ = NULL;
2501 EXPECT_EQ(0, voe_.GetNumChannels());
2502}
2503
wu@webrtc.org78187522013-10-07 23:32:02 +00002504TEST_F(WebRtcVoiceEngineTestFake, TestAddRecvStreamFailWithZeroSsrc) {
2505 EXPECT_TRUE(SetupEngine());
2506 EXPECT_FALSE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(0)));
2507}
2508
2509TEST_F(WebRtcVoiceEngineTestFake, TestNoLeakingWhenAddRecvStreamFail) {
2510 EXPECT_TRUE(SetupEngine());
2511 // Stream 1 reuses default channel.
2512 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(1)));
2513 // Manually delete default channel to simulate a failure.
2514 int default_channel = voe_.GetLastChannel();
2515 EXPECT_EQ(0, voe_.DeleteChannel(default_channel));
2516 // Add recv stream 2 should fail because default channel is gone.
2517 EXPECT_FALSE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(2)));
2518 int new_channel = voe_.GetLastChannel();
2519 EXPECT_NE(default_channel, new_channel);
2520 // The last created channel should have already been deleted.
2521 EXPECT_EQ(-1, voe_.DeleteChannel(new_channel));
2522}
2523
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002524// Test the InsertDtmf on default send stream as caller.
2525TEST_F(WebRtcVoiceEngineTestFake, InsertDtmfOnDefaultSendStreamAsCaller) {
2526 TestInsertDtmf(0, true);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002527}
2528
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002529// Test the InsertDtmf on default send stream as callee
2530TEST_F(WebRtcVoiceEngineTestFake, InsertDtmfOnDefaultSendStreamAsCallee) {
2531 TestInsertDtmf(0, false);
2532}
2533
2534// Test the InsertDtmf on specified send stream as caller.
2535TEST_F(WebRtcVoiceEngineTestFake, InsertDtmfOnSendStreamAsCaller) {
2536 TestInsertDtmf(kSsrc1, true);
2537}
2538
2539// Test the InsertDtmf on specified send stream as callee.
2540TEST_F(WebRtcVoiceEngineTestFake, InsertDtmfOnSendStreamAsCallee) {
2541 TestInsertDtmf(kSsrc1, false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002542}
2543
2544// Test that we can play a ringback tone properly in a single-stream call.
2545TEST_F(WebRtcVoiceEngineTestFake, PlayRingback) {
2546 EXPECT_TRUE(SetupEngine());
2547 int channel_num = voe_.GetLastChannel();
2548 EXPECT_EQ(0, voe_.IsPlayingFileLocally(channel_num));
2549 // Check we fail if no ringback tone specified.
2550 EXPECT_FALSE(channel_->PlayRingbackTone(0, true, true));
2551 EXPECT_EQ(0, voe_.IsPlayingFileLocally(channel_num));
2552 // Check we can set and play a ringback tone.
wu@webrtc.org9caf2762013-12-11 18:25:07 +00002553 EXPECT_TRUE(channel_->SetRingbackTone(
2554 kRingbackTone, static_cast<int>(strlen(kRingbackTone))));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002555 EXPECT_TRUE(channel_->PlayRingbackTone(0, true, true));
2556 EXPECT_EQ(1, voe_.IsPlayingFileLocally(channel_num));
2557 // Check we can stop the tone manually.
2558 EXPECT_TRUE(channel_->PlayRingbackTone(0, false, false));
2559 EXPECT_EQ(0, voe_.IsPlayingFileLocally(channel_num));
2560 // Check we stop the tone if a packet arrives.
2561 EXPECT_TRUE(channel_->PlayRingbackTone(0, true, true));
2562 EXPECT_EQ(1, voe_.IsPlayingFileLocally(channel_num));
2563 DeliverPacket(kPcmuFrame, sizeof(kPcmuFrame));
2564 EXPECT_EQ(0, voe_.IsPlayingFileLocally(channel_num));
2565}
2566
2567// Test that we can play a ringback tone properly in a multi-stream call.
2568TEST_F(WebRtcVoiceEngineTestFake, PlayRingbackWithMultipleStreams) {
2569 EXPECT_TRUE(SetupEngine());
2570 EXPECT_TRUE(channel_->SetOptions(options_conference_));
2571 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(1)));
2572 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(2)));
2573 int channel_num = voe_.GetLastChannel();
2574 EXPECT_EQ(0, voe_.IsPlayingFileLocally(channel_num));
2575 // Check we fail if no ringback tone specified.
2576 EXPECT_FALSE(channel_->PlayRingbackTone(2, true, true));
2577 EXPECT_EQ(0, voe_.IsPlayingFileLocally(channel_num));
2578 // Check we can set and play a ringback tone on the correct ssrc.
wu@webrtc.org9caf2762013-12-11 18:25:07 +00002579 EXPECT_TRUE(channel_->SetRingbackTone(
2580 kRingbackTone, static_cast<int>(strlen(kRingbackTone))));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002581 EXPECT_FALSE(channel_->PlayRingbackTone(77, true, true));
2582 EXPECT_TRUE(channel_->PlayRingbackTone(2, true, true));
2583 EXPECT_EQ(1, voe_.IsPlayingFileLocally(channel_num));
2584 // Check we can stop the tone manually.
2585 EXPECT_TRUE(channel_->PlayRingbackTone(2, false, false));
2586 EXPECT_EQ(0, voe_.IsPlayingFileLocally(channel_num));
2587 // Check we stop the tone if a packet arrives, but only with the right SSRC.
2588 EXPECT_TRUE(channel_->PlayRingbackTone(2, true, true));
2589 EXPECT_EQ(1, voe_.IsPlayingFileLocally(channel_num));
2590 // Send a packet with SSRC 1; the tone should not stop.
2591 DeliverPacket(kPcmuFrame, sizeof(kPcmuFrame));
2592 EXPECT_EQ(1, voe_.IsPlayingFileLocally(channel_num));
2593 // Send a packet with SSRC 2; the tone should stop.
2594 char packet[sizeof(kPcmuFrame)];
2595 memcpy(packet, kPcmuFrame, sizeof(kPcmuFrame));
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002596 rtc::SetBE32(packet + 8, 2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002597 DeliverPacket(packet, sizeof(packet));
2598 EXPECT_EQ(0, voe_.IsPlayingFileLocally(channel_num));
2599}
2600
2601// Tests creating soundclips, and make sure they come from the right engine.
2602TEST_F(WebRtcVoiceEngineTestFake, CreateSoundclip) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002603 EXPECT_TRUE(engine_.Init(rtc::Thread::Current()));
wu@webrtc.org4551b792013-10-09 15:37:36 +00002604 EXPECT_FALSE(voe_sc_.IsInited());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002605 soundclip_ = engine_.CreateSoundclip();
wu@webrtc.org4551b792013-10-09 15:37:36 +00002606 EXPECT_TRUE(voe_sc_.IsInited());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002607 ASSERT_TRUE(soundclip_ != NULL);
2608 EXPECT_EQ(0, voe_.GetNumChannels());
2609 EXPECT_EQ(1, voe_sc_.GetNumChannels());
2610 int channel_num = voe_sc_.GetLastChannel();
2611 EXPECT_TRUE(voe_sc_.GetPlayout(channel_num));
2612 delete soundclip_;
2613 soundclip_ = NULL;
2614 EXPECT_EQ(0, voe_sc_.GetNumChannels());
wu@webrtc.org4551b792013-10-09 15:37:36 +00002615 // Make sure the soundclip engine is uninitialized on shutdown, now that
2616 // we've initialized it by creating a soundclip.
2617 engine_.Terminate();
2618 EXPECT_FALSE(voe_sc_.IsInited());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002619}
2620
2621// Tests playing out a fake sound.
2622TEST_F(WebRtcVoiceEngineTestFake, PlaySoundclip) {
2623 static const char kZeroes[16000] = {};
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002624 EXPECT_TRUE(engine_.Init(rtc::Thread::Current()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002625 soundclip_ = engine_.CreateSoundclip();
2626 ASSERT_TRUE(soundclip_ != NULL);
2627 EXPECT_TRUE(soundclip_->PlaySound(kZeroes, sizeof(kZeroes), 0));
2628}
2629
2630TEST_F(WebRtcVoiceEngineTestFake, MediaEngineCallbackOnError) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002631 rtc::scoped_ptr<ChannelErrorListener> listener;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002632 cricket::WebRtcVoiceMediaChannel* media_channel;
2633 unsigned int ssrc = 0;
2634
2635 EXPECT_TRUE(SetupEngine());
2636 EXPECT_TRUE(channel_->SetOptions(options_conference_));
2637 EXPECT_TRUE(channel_->SetSend(cricket::SEND_MICROPHONE));
2638
2639 media_channel = static_cast<cricket::WebRtcVoiceMediaChannel*>(channel_);
2640 listener.reset(new ChannelErrorListener(channel_));
2641
2642 // Test on WebRtc VoE channel.
2643 voe_.TriggerCallbackOnError(media_channel->voe_channel(),
2644 VE_SATURATION_WARNING);
2645 EXPECT_EQ(cricket::VoiceMediaChannel::ERROR_REC_DEVICE_SATURATION,
2646 listener->error());
2647 EXPECT_NE(-1, voe_.GetLocalSSRC(voe_.GetLastChannel(), ssrc));
2648 EXPECT_EQ(ssrc, listener->ssrc());
2649
2650 listener->Reset();
2651 voe_.TriggerCallbackOnError(-1, VE_TYPING_NOISE_WARNING);
2652 EXPECT_EQ(cricket::VoiceMediaChannel::ERROR_REC_TYPING_NOISE_DETECTED,
2653 listener->error());
2654 EXPECT_EQ(0U, listener->ssrc());
2655
2656 // Add another stream and test on that.
2657 ++ssrc;
2658 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(
2659 ssrc)));
2660 listener->Reset();
2661 voe_.TriggerCallbackOnError(voe_.GetLastChannel(),
2662 VE_SATURATION_WARNING);
2663 EXPECT_EQ(cricket::VoiceMediaChannel::ERROR_REC_DEVICE_SATURATION,
2664 listener->error());
2665 EXPECT_EQ(ssrc, listener->ssrc());
2666
2667 // Testing a non-existing channel.
2668 listener->Reset();
2669 voe_.TriggerCallbackOnError(voe_.GetLastChannel() + 2,
2670 VE_SATURATION_WARNING);
2671 EXPECT_EQ(0, listener->error());
2672}
2673
2674TEST_F(WebRtcVoiceEngineTestFake, TestSetPlayoutError) {
2675 EXPECT_TRUE(SetupEngine());
2676 EXPECT_TRUE(channel_->SetOptions(options_conference_));
2677 std::vector<cricket::AudioCodec> codecs;
2678 codecs.push_back(kPcmuCodec);
2679 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
2680 EXPECT_TRUE(channel_->SetSend(cricket::SEND_MICROPHONE));
2681 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(2)));
2682 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(3)));
2683 EXPECT_TRUE(channel_->SetPlayout(true));
2684 voe_.set_playout_fail_channel(voe_.GetLastChannel() - 1);
2685 EXPECT_TRUE(channel_->SetPlayout(false));
2686 EXPECT_FALSE(channel_->SetPlayout(true));
2687}
2688
2689// Test that the Registering/Unregistering with the
2690// webrtcvoiceengine works as expected
2691TEST_F(WebRtcVoiceEngineTestFake, RegisterVoiceProcessor) {
2692 EXPECT_TRUE(SetupEngine());
2693 EXPECT_TRUE(channel_->SetOptions(options_conference_));
2694 EXPECT_TRUE(channel_->AddRecvStream(
2695 cricket::StreamParams::CreateLegacy(kSsrc2)));
2696 cricket::FakeMediaProcessor vp_1;
2697 cricket::FakeMediaProcessor vp_2;
2698
2699 EXPECT_FALSE(engine_.RegisterProcessor(kSsrc2, &vp_1, cricket::MPD_TX));
2700 EXPECT_TRUE(engine_.RegisterProcessor(kSsrc2, &vp_1, cricket::MPD_RX));
2701 EXPECT_TRUE(engine_.RegisterProcessor(kSsrc2, &vp_2, cricket::MPD_RX));
2702 voe_.TriggerProcessPacket(cricket::MPD_RX);
2703 voe_.TriggerProcessPacket(cricket::MPD_TX);
2704
2705 EXPECT_TRUE(voe_.IsExternalMediaProcessorRegistered());
2706 EXPECT_EQ(1, vp_1.voice_frame_count());
2707 EXPECT_EQ(1, vp_2.voice_frame_count());
2708
2709 EXPECT_TRUE(engine_.UnregisterProcessor(kSsrc2,
2710 &vp_2,
2711 cricket::MPD_RX));
2712 voe_.TriggerProcessPacket(cricket::MPD_RX);
2713 EXPECT_TRUE(voe_.IsExternalMediaProcessorRegistered());
2714 EXPECT_EQ(1, vp_2.voice_frame_count());
2715 EXPECT_EQ(2, vp_1.voice_frame_count());
2716
2717 EXPECT_TRUE(engine_.UnregisterProcessor(kSsrc2,
2718 &vp_1,
2719 cricket::MPD_RX));
2720 voe_.TriggerProcessPacket(cricket::MPD_RX);
2721 EXPECT_FALSE(voe_.IsExternalMediaProcessorRegistered());
2722 EXPECT_EQ(2, vp_1.voice_frame_count());
2723
2724 EXPECT_FALSE(engine_.RegisterProcessor(kSsrc1, &vp_1, cricket::MPD_RX));
2725 EXPECT_TRUE(engine_.RegisterProcessor(kSsrc1, &vp_1, cricket::MPD_TX));
2726 voe_.TriggerProcessPacket(cricket::MPD_RX);
2727 voe_.TriggerProcessPacket(cricket::MPD_TX);
2728 EXPECT_TRUE(voe_.IsExternalMediaProcessorRegistered());
2729 EXPECT_EQ(3, vp_1.voice_frame_count());
2730
2731 EXPECT_TRUE(engine_.UnregisterProcessor(kSsrc1,
2732 &vp_1,
2733 cricket::MPD_RX_AND_TX));
2734 voe_.TriggerProcessPacket(cricket::MPD_TX);
2735 EXPECT_FALSE(voe_.IsExternalMediaProcessorRegistered());
2736 EXPECT_EQ(3, vp_1.voice_frame_count());
2737 EXPECT_TRUE(channel_->RemoveRecvStream(kSsrc2));
2738 EXPECT_FALSE(engine_.RegisterProcessor(kSsrc2, &vp_1, cricket::MPD_RX));
2739 EXPECT_FALSE(voe_.IsExternalMediaProcessorRegistered());
2740
2741 // Test that we can register a processor on the receive channel on SSRC 0.
2742 // This tests the 1:1 case when the receive SSRC is unknown.
2743 EXPECT_TRUE(engine_.RegisterProcessor(0, &vp_1, cricket::MPD_RX));
2744 voe_.TriggerProcessPacket(cricket::MPD_RX);
2745 EXPECT_TRUE(voe_.IsExternalMediaProcessorRegistered());
2746 EXPECT_EQ(4, vp_1.voice_frame_count());
2747 EXPECT_TRUE(engine_.UnregisterProcessor(0,
2748 &vp_1,
2749 cricket::MPD_RX));
2750
2751 // The following tests test that FindChannelNumFromSsrc is doing
2752 // what we expect.
2753 // pick an invalid ssrc and make sure we can't register
2754 EXPECT_FALSE(engine_.RegisterProcessor(99,
2755 &vp_1,
2756 cricket::MPD_RX));
2757 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(1)));
2758 EXPECT_TRUE(engine_.RegisterProcessor(1,
2759 &vp_1,
2760 cricket::MPD_RX));
2761 EXPECT_TRUE(engine_.UnregisterProcessor(1,
2762 &vp_1,
2763 cricket::MPD_RX));
2764 EXPECT_FALSE(engine_.RegisterProcessor(1,
2765 &vp_1,
2766 cricket::MPD_TX));
2767 EXPECT_TRUE(channel_->RemoveRecvStream(1));
2768}
2769
2770TEST_F(WebRtcVoiceEngineTestFake, SetAudioOptions) {
2771 EXPECT_TRUE(SetupEngine());
2772
2773 bool ec_enabled;
2774 webrtc::EcModes ec_mode;
2775 bool ec_metrics_enabled;
2776 webrtc::AecmModes aecm_mode;
2777 bool cng_enabled;
2778 bool agc_enabled;
2779 webrtc::AgcModes agc_mode;
2780 webrtc::AgcConfig agc_config;
2781 bool ns_enabled;
2782 webrtc::NsModes ns_mode;
2783 bool highpass_filter_enabled;
2784 bool stereo_swapping_enabled;
2785 bool typing_detection_enabled;
2786 voe_.GetEcStatus(ec_enabled, ec_mode);
2787 voe_.GetEcMetricsStatus(ec_metrics_enabled);
2788 voe_.GetAecmMode(aecm_mode, cng_enabled);
2789 voe_.GetAgcStatus(agc_enabled, agc_mode);
2790 voe_.GetAgcConfig(agc_config);
2791 voe_.GetNsStatus(ns_enabled, ns_mode);
2792 highpass_filter_enabled = voe_.IsHighPassFilterEnabled();
2793 stereo_swapping_enabled = voe_.IsStereoChannelSwappingEnabled();
2794 voe_.GetTypingDetectionStatus(typing_detection_enabled);
2795 EXPECT_TRUE(ec_enabled);
2796 EXPECT_TRUE(ec_metrics_enabled);
2797 EXPECT_FALSE(cng_enabled);
2798 EXPECT_TRUE(agc_enabled);
2799 EXPECT_EQ(0, agc_config.targetLeveldBOv);
2800 EXPECT_TRUE(ns_enabled);
2801 EXPECT_TRUE(highpass_filter_enabled);
2802 EXPECT_FALSE(stereo_swapping_enabled);
2803 EXPECT_TRUE(typing_detection_enabled);
2804 EXPECT_EQ(ec_mode, webrtc::kEcConference);
2805 EXPECT_EQ(ns_mode, webrtc::kNsHighSuppression);
2806
2807 // Nothing set, so all ignored.
2808 cricket::AudioOptions options;
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00002809 ASSERT_TRUE(engine_.SetOptions(options));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002810 voe_.GetEcStatus(ec_enabled, ec_mode);
2811 voe_.GetEcMetricsStatus(ec_metrics_enabled);
2812 voe_.GetAecmMode(aecm_mode, cng_enabled);
2813 voe_.GetAgcStatus(agc_enabled, agc_mode);
2814 voe_.GetAgcConfig(agc_config);
2815 voe_.GetNsStatus(ns_enabled, ns_mode);
2816 highpass_filter_enabled = voe_.IsHighPassFilterEnabled();
2817 stereo_swapping_enabled = voe_.IsStereoChannelSwappingEnabled();
2818 voe_.GetTypingDetectionStatus(typing_detection_enabled);
2819 EXPECT_TRUE(ec_enabled);
2820 EXPECT_TRUE(ec_metrics_enabled);
2821 EXPECT_FALSE(cng_enabled);
2822 EXPECT_TRUE(agc_enabled);
2823 EXPECT_EQ(0, agc_config.targetLeveldBOv);
2824 EXPECT_TRUE(ns_enabled);
2825 EXPECT_TRUE(highpass_filter_enabled);
2826 EXPECT_FALSE(stereo_swapping_enabled);
2827 EXPECT_TRUE(typing_detection_enabled);
2828 EXPECT_EQ(ec_mode, webrtc::kEcConference);
2829 EXPECT_EQ(ns_mode, webrtc::kNsHighSuppression);
2830
2831 // Turn echo cancellation off
2832 options.echo_cancellation.Set(false);
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00002833 ASSERT_TRUE(engine_.SetOptions(options));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002834 voe_.GetEcStatus(ec_enabled, ec_mode);
2835 EXPECT_FALSE(ec_enabled);
2836
2837 // Turn echo cancellation back on, with settings, and make sure
2838 // nothing else changed.
2839 options.echo_cancellation.Set(true);
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00002840 ASSERT_TRUE(engine_.SetOptions(options));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002841 voe_.GetEcStatus(ec_enabled, ec_mode);
2842 voe_.GetEcMetricsStatus(ec_metrics_enabled);
2843 voe_.GetAecmMode(aecm_mode, cng_enabled);
2844 voe_.GetAgcStatus(agc_enabled, agc_mode);
2845 voe_.GetAgcConfig(agc_config);
2846 voe_.GetNsStatus(ns_enabled, ns_mode);
2847 highpass_filter_enabled = voe_.IsHighPassFilterEnabled();
2848 stereo_swapping_enabled = voe_.IsStereoChannelSwappingEnabled();
2849 voe_.GetTypingDetectionStatus(typing_detection_enabled);
2850 EXPECT_TRUE(ec_enabled);
2851 EXPECT_TRUE(ec_metrics_enabled);
2852 EXPECT_TRUE(agc_enabled);
2853 EXPECT_EQ(0, agc_config.targetLeveldBOv);
2854 EXPECT_TRUE(ns_enabled);
2855 EXPECT_TRUE(highpass_filter_enabled);
2856 EXPECT_FALSE(stereo_swapping_enabled);
2857 EXPECT_TRUE(typing_detection_enabled);
2858 EXPECT_EQ(ec_mode, webrtc::kEcConference);
2859 EXPECT_EQ(ns_mode, webrtc::kNsHighSuppression);
2860
2861 // Turn off AGC
2862 options.auto_gain_control.Set(false);
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00002863 ASSERT_TRUE(engine_.SetOptions(options));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002864 voe_.GetAgcStatus(agc_enabled, agc_mode);
2865 EXPECT_FALSE(agc_enabled);
2866
2867 // Turn AGC back on
2868 options.auto_gain_control.Set(true);
2869 options.adjust_agc_delta.Clear();
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00002870 ASSERT_TRUE(engine_.SetOptions(options));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002871 voe_.GetAgcStatus(agc_enabled, agc_mode);
2872 EXPECT_TRUE(agc_enabled);
2873 voe_.GetAgcConfig(agc_config);
2874 EXPECT_EQ(0, agc_config.targetLeveldBOv);
2875
2876 // Turn off other options (and stereo swapping on).
2877 options.noise_suppression.Set(false);
2878 options.highpass_filter.Set(false);
2879 options.typing_detection.Set(false);
2880 options.stereo_swapping.Set(true);
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00002881 ASSERT_TRUE(engine_.SetOptions(options));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002882 voe_.GetNsStatus(ns_enabled, ns_mode);
2883 highpass_filter_enabled = voe_.IsHighPassFilterEnabled();
2884 stereo_swapping_enabled = voe_.IsStereoChannelSwappingEnabled();
2885 voe_.GetTypingDetectionStatus(typing_detection_enabled);
2886 EXPECT_FALSE(ns_enabled);
2887 EXPECT_FALSE(highpass_filter_enabled);
2888 EXPECT_FALSE(typing_detection_enabled);
2889 EXPECT_TRUE(stereo_swapping_enabled);
2890
2891 // Turn on "conference mode" to ensure it has no impact.
2892 options.conference_mode.Set(true);
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00002893 ASSERT_TRUE(engine_.SetOptions(options));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002894 voe_.GetEcStatus(ec_enabled, ec_mode);
2895 voe_.GetNsStatus(ns_enabled, ns_mode);
2896 EXPECT_TRUE(ec_enabled);
2897 EXPECT_EQ(webrtc::kEcConference, ec_mode);
2898 EXPECT_FALSE(ns_enabled);
2899 EXPECT_EQ(webrtc::kNsHighSuppression, ns_mode);
2900}
2901
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00002902TEST_F(WebRtcVoiceEngineTestFake, DefaultOptions) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002903 EXPECT_TRUE(SetupEngine());
2904
2905 bool ec_enabled;
2906 webrtc::EcModes ec_mode;
2907 bool ec_metrics_enabled;
2908 bool agc_enabled;
2909 webrtc::AgcModes agc_mode;
2910 bool ns_enabled;
2911 webrtc::NsModes ns_mode;
2912 bool highpass_filter_enabled;
2913 bool stereo_swapping_enabled;
2914 bool typing_detection_enabled;
2915
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002916 voe_.GetEcStatus(ec_enabled, ec_mode);
2917 voe_.GetEcMetricsStatus(ec_metrics_enabled);
2918 voe_.GetAgcStatus(agc_enabled, agc_mode);
2919 voe_.GetNsStatus(ns_enabled, ns_mode);
2920 highpass_filter_enabled = voe_.IsHighPassFilterEnabled();
2921 stereo_swapping_enabled = voe_.IsStereoChannelSwappingEnabled();
2922 voe_.GetTypingDetectionStatus(typing_detection_enabled);
2923 EXPECT_TRUE(ec_enabled);
2924 EXPECT_TRUE(agc_enabled);
2925 EXPECT_TRUE(ns_enabled);
2926 EXPECT_TRUE(highpass_filter_enabled);
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00002927 EXPECT_TRUE(typing_detection_enabled);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002928 EXPECT_FALSE(stereo_swapping_enabled);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002929}
2930
2931TEST_F(WebRtcVoiceEngineTestFake, InitDoesNotOverwriteDefaultAgcConfig) {
2932 webrtc::AgcConfig set_config = {0};
2933 set_config.targetLeveldBOv = 3;
2934 set_config.digitalCompressionGaindB = 9;
2935 set_config.limiterEnable = true;
2936 EXPECT_EQ(0, voe_.SetAgcConfig(set_config));
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002937 EXPECT_TRUE(engine_.Init(rtc::Thread::Current()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002938
2939 webrtc::AgcConfig config = {0};
2940 EXPECT_EQ(0, voe_.GetAgcConfig(config));
2941 EXPECT_EQ(set_config.targetLeveldBOv, config.targetLeveldBOv);
2942 EXPECT_EQ(set_config.digitalCompressionGaindB,
2943 config.digitalCompressionGaindB);
2944 EXPECT_EQ(set_config.limiterEnable, config.limiterEnable);
2945}
2946
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002947TEST_F(WebRtcVoiceEngineTestFake, SetOptionOverridesViaChannels) {
2948 EXPECT_TRUE(SetupEngine());
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002949 rtc::scoped_ptr<cricket::VoiceMediaChannel> channel1(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002950 engine_.CreateChannel());
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002951 rtc::scoped_ptr<cricket::VoiceMediaChannel> channel2(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002952 engine_.CreateChannel());
2953
2954 // Have to add a stream to make SetSend work.
2955 cricket::StreamParams stream1;
2956 stream1.ssrcs.push_back(1);
2957 channel1->AddSendStream(stream1);
2958 cricket::StreamParams stream2;
2959 stream2.ssrcs.push_back(2);
2960 channel2->AddSendStream(stream2);
2961
2962 // AEC and AGC and NS
2963 cricket::AudioOptions options_all;
2964 options_all.echo_cancellation.Set(true);
2965 options_all.auto_gain_control.Set(true);
2966 options_all.noise_suppression.Set(true);
2967
2968 ASSERT_TRUE(channel1->SetOptions(options_all));
2969 cricket::AudioOptions expected_options = options_all;
2970 cricket::AudioOptions actual_options;
2971 ASSERT_TRUE(channel1->GetOptions(&actual_options));
2972 EXPECT_EQ(expected_options, actual_options);
2973 ASSERT_TRUE(channel2->SetOptions(options_all));
2974 ASSERT_TRUE(channel2->GetOptions(&actual_options));
2975 EXPECT_EQ(expected_options, actual_options);
2976
2977 // unset NS
2978 cricket::AudioOptions options_no_ns;
2979 options_no_ns.noise_suppression.Set(false);
2980 ASSERT_TRUE(channel1->SetOptions(options_no_ns));
2981
2982 expected_options.echo_cancellation.Set(true);
2983 expected_options.auto_gain_control.Set(true);
2984 expected_options.noise_suppression.Set(false);
2985 ASSERT_TRUE(channel1->GetOptions(&actual_options));
2986 EXPECT_EQ(expected_options, actual_options);
2987
2988 // unset AGC
2989 cricket::AudioOptions options_no_agc;
2990 options_no_agc.auto_gain_control.Set(false);
2991 ASSERT_TRUE(channel2->SetOptions(options_no_agc));
2992
2993 expected_options.echo_cancellation.Set(true);
2994 expected_options.auto_gain_control.Set(false);
2995 expected_options.noise_suppression.Set(true);
2996 ASSERT_TRUE(channel2->GetOptions(&actual_options));
2997 EXPECT_EQ(expected_options, actual_options);
2998
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00002999 ASSERT_TRUE(engine_.SetOptions(options_all));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003000 bool ec_enabled;
3001 webrtc::EcModes ec_mode;
3002 bool agc_enabled;
3003 webrtc::AgcModes agc_mode;
3004 bool ns_enabled;
3005 webrtc::NsModes ns_mode;
3006 voe_.GetEcStatus(ec_enabled, ec_mode);
3007 voe_.GetAgcStatus(agc_enabled, agc_mode);
3008 voe_.GetNsStatus(ns_enabled, ns_mode);
3009 EXPECT_TRUE(ec_enabled);
3010 EXPECT_TRUE(agc_enabled);
3011 EXPECT_TRUE(ns_enabled);
3012
3013 channel1->SetSend(cricket::SEND_MICROPHONE);
3014 voe_.GetEcStatus(ec_enabled, ec_mode);
3015 voe_.GetAgcStatus(agc_enabled, agc_mode);
3016 voe_.GetNsStatus(ns_enabled, ns_mode);
3017 EXPECT_TRUE(ec_enabled);
3018 EXPECT_TRUE(agc_enabled);
3019 EXPECT_FALSE(ns_enabled);
3020
3021 channel1->SetSend(cricket::SEND_NOTHING);
3022 voe_.GetEcStatus(ec_enabled, ec_mode);
3023 voe_.GetAgcStatus(agc_enabled, agc_mode);
3024 voe_.GetNsStatus(ns_enabled, ns_mode);
3025 EXPECT_TRUE(ec_enabled);
3026 EXPECT_TRUE(agc_enabled);
3027 EXPECT_TRUE(ns_enabled);
3028
3029 channel2->SetSend(cricket::SEND_MICROPHONE);
3030 voe_.GetEcStatus(ec_enabled, ec_mode);
3031 voe_.GetAgcStatus(agc_enabled, agc_mode);
3032 voe_.GetNsStatus(ns_enabled, ns_mode);
3033 EXPECT_TRUE(ec_enabled);
3034 EXPECT_FALSE(agc_enabled);
3035 EXPECT_TRUE(ns_enabled);
3036
3037 channel2->SetSend(cricket::SEND_NOTHING);
3038 voe_.GetEcStatus(ec_enabled, ec_mode);
3039 voe_.GetAgcStatus(agc_enabled, agc_mode);
3040 voe_.GetNsStatus(ns_enabled, ns_mode);
3041 EXPECT_TRUE(ec_enabled);
3042 EXPECT_TRUE(agc_enabled);
3043 EXPECT_TRUE(ns_enabled);
3044
3045 // Make sure settings take effect while we are sending.
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00003046 ASSERT_TRUE(engine_.SetOptions(options_all));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003047 cricket::AudioOptions options_no_agc_nor_ns;
3048 options_no_agc_nor_ns.auto_gain_control.Set(false);
3049 options_no_agc_nor_ns.noise_suppression.Set(false);
3050 channel2->SetSend(cricket::SEND_MICROPHONE);
3051 channel2->SetOptions(options_no_agc_nor_ns);
3052
3053 expected_options.echo_cancellation.Set(true);
3054 expected_options.auto_gain_control.Set(false);
3055 expected_options.noise_suppression.Set(false);
3056 ASSERT_TRUE(channel2->GetOptions(&actual_options));
3057 EXPECT_EQ(expected_options, actual_options);
3058 voe_.GetEcStatus(ec_enabled, ec_mode);
3059 voe_.GetAgcStatus(agc_enabled, agc_mode);
3060 voe_.GetNsStatus(ns_enabled, ns_mode);
3061 EXPECT_TRUE(ec_enabled);
3062 EXPECT_FALSE(agc_enabled);
3063 EXPECT_FALSE(ns_enabled);
3064}
3065
wu@webrtc.orgde305012013-10-31 15:40:38 +00003066// This test verifies DSCP settings are properly applied on voice media channel.
3067TEST_F(WebRtcVoiceEngineTestFake, TestSetDscpOptions) {
3068 EXPECT_TRUE(SetupEngine());
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003069 rtc::scoped_ptr<cricket::VoiceMediaChannel> channel(
wu@webrtc.orgde305012013-10-31 15:40:38 +00003070 engine_.CreateChannel());
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003071 rtc::scoped_ptr<cricket::FakeNetworkInterface> network_interface(
wu@webrtc.orgde305012013-10-31 15:40:38 +00003072 new cricket::FakeNetworkInterface);
3073 channel->SetInterface(network_interface.get());
3074 cricket::AudioOptions options;
3075 options.dscp.Set(true);
3076 EXPECT_TRUE(channel->SetOptions(options));
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003077 EXPECT_EQ(rtc::DSCP_EF, network_interface->dscp());
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +00003078 // Verify previous value is not modified if dscp option is not set.
3079 cricket::AudioOptions options1;
3080 EXPECT_TRUE(channel->SetOptions(options1));
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003081 EXPECT_EQ(rtc::DSCP_EF, network_interface->dscp());
wu@webrtc.orgde305012013-10-31 15:40:38 +00003082 options.dscp.Set(false);
3083 EXPECT_TRUE(channel->SetOptions(options));
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003084 EXPECT_EQ(rtc::DSCP_DEFAULT, network_interface->dscp());
wu@webrtc.orgde305012013-10-31 15:40:38 +00003085}
3086
wu@webrtc.org1d1ffc92013-10-16 18:12:02 +00003087TEST(WebRtcVoiceEngineTest, TestDefaultOptionsBeforeInit) {
3088 cricket::WebRtcVoiceEngine engine;
3089 cricket::AudioOptions options = engine.GetOptions();
3090 // The default options should have at least a few things set. We purposefully
3091 // don't check the option values here, though.
3092 EXPECT_TRUE(options.echo_cancellation.IsSet());
3093 EXPECT_TRUE(options.auto_gain_control.IsSet());
3094 EXPECT_TRUE(options.noise_suppression.IsSet());
3095}
3096
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003097// Test that GetReceiveChannelNum returns the default channel for the first
3098// recv stream in 1-1 calls.
3099TEST_F(WebRtcVoiceEngineTestFake, TestGetReceiveChannelNumIn1To1Calls) {
3100 EXPECT_TRUE(SetupEngine());
3101 cricket::WebRtcVoiceMediaChannel* media_channel =
3102 static_cast<cricket::WebRtcVoiceMediaChannel*>(channel_);
3103 // Test that GetChannelNum returns the default channel if the SSRC is unknown.
3104 EXPECT_EQ(media_channel->voe_channel(),
3105 media_channel->GetReceiveChannelNum(0));
3106 cricket::StreamParams stream;
3107 stream.ssrcs.push_back(kSsrc2);
3108 EXPECT_TRUE(channel_->AddRecvStream(stream));
3109 EXPECT_EQ(media_channel->voe_channel(),
3110 media_channel->GetReceiveChannelNum(kSsrc2));
3111}
3112
3113// Test that GetReceiveChannelNum doesn't return the default channel for the
3114// first recv stream in conference calls.
3115TEST_F(WebRtcVoiceEngineTestFake, TestGetChannelNumInConferenceCalls) {
3116 EXPECT_TRUE(SetupEngine());
3117 EXPECT_TRUE(channel_->SetOptions(options_conference_));
3118 cricket::StreamParams stream;
3119 stream.ssrcs.push_back(kSsrc2);
3120 EXPECT_TRUE(channel_->AddRecvStream(stream));
3121 cricket::WebRtcVoiceMediaChannel* media_channel =
3122 static_cast<cricket::WebRtcVoiceMediaChannel*>(channel_);
3123 EXPECT_LT(media_channel->voe_channel(),
3124 media_channel->GetReceiveChannelNum(kSsrc2));
3125}
3126
3127TEST_F(WebRtcVoiceEngineTestFake, SetOutputScaling) {
3128 EXPECT_TRUE(SetupEngine());
3129 double left, right;
3130 EXPECT_TRUE(channel_->SetOutputScaling(0, 1, 2));
3131 EXPECT_TRUE(channel_->GetOutputScaling(0, &left, &right));
3132 EXPECT_DOUBLE_EQ(1, left);
3133 EXPECT_DOUBLE_EQ(2, right);
3134
3135 EXPECT_FALSE(channel_->SetOutputScaling(kSsrc2, 1, 2));
3136 cricket::StreamParams stream;
3137 stream.ssrcs.push_back(kSsrc2);
3138 EXPECT_TRUE(channel_->AddRecvStream(stream));
3139
3140 EXPECT_TRUE(channel_->SetOutputScaling(kSsrc2, 2, 1));
3141 EXPECT_TRUE(channel_->GetOutputScaling(kSsrc2, &left, &right));
3142 EXPECT_DOUBLE_EQ(2, left);
3143 EXPECT_DOUBLE_EQ(1, right);
3144}
3145
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003146// Tests for the actual WebRtc VoE library.
3147
3148// Tests that the library initializes and shuts down properly.
3149TEST(WebRtcVoiceEngineTest, StartupShutdown) {
3150 cricket::WebRtcVoiceEngine engine;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003151 EXPECT_TRUE(engine.Init(rtc::Thread::Current()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003152 cricket::VoiceMediaChannel* channel = engine.CreateChannel();
3153 EXPECT_TRUE(channel != NULL);
3154 delete channel;
3155 engine.Terminate();
3156
3157 // Reinit to catch regression where VoiceEngineObserver reference is lost
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003158 EXPECT_TRUE(engine.Init(rtc::Thread::Current()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003159 engine.Terminate();
3160}
3161
3162// Tests that the logging from the library is cleartext.
3163TEST(WebRtcVoiceEngineTest, DISABLED_HasUnencryptedLogging) {
3164 cricket::WebRtcVoiceEngine engine;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003165 rtc::scoped_ptr<rtc::MemoryStream> stream(
3166 new rtc::MemoryStream);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003167 size_t size = 0;
3168 bool cleartext = true;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003169 rtc::LogMessage::AddLogToStream(stream.get(), rtc::LS_VERBOSE);
3170 engine.SetLogging(rtc::LS_VERBOSE, "");
3171 EXPECT_TRUE(engine.Init(rtc::Thread::Current()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003172 EXPECT_TRUE(stream->GetSize(&size));
3173 EXPECT_GT(size, 0U);
3174 engine.Terminate();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003175 rtc::LogMessage::RemoveLogToStream(stream.get());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003176 const char* buf = stream->GetBuffer();
3177 for (size_t i = 0; i < size && cleartext; ++i) {
3178 int ch = static_cast<int>(buf[i]);
3179 ASSERT_GE(ch, 0) << "Out of bounds character in WebRtc VoE log: "
3180 << std::hex << ch;
3181 cleartext = (isprint(ch) || isspace(ch));
3182 }
3183 EXPECT_TRUE(cleartext);
3184}
3185
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003186// Tests that the library is configured with the codecs we want.
3187TEST(WebRtcVoiceEngineTest, HasCorrectCodecs) {
3188 cricket::WebRtcVoiceEngine engine;
3189 // Check codecs by name.
3190 EXPECT_TRUE(engine.FindCodec(
3191 cricket::AudioCodec(96, "OPUS", 48000, 0, 2, 0)));
3192 EXPECT_TRUE(engine.FindCodec(
3193 cricket::AudioCodec(96, "ISAC", 16000, 0, 1, 0)));
3194 EXPECT_TRUE(engine.FindCodec(
3195 cricket::AudioCodec(96, "ISAC", 32000, 0, 1, 0)));
3196 // Check that name matching is case-insensitive.
3197 EXPECT_TRUE(engine.FindCodec(
3198 cricket::AudioCodec(96, "ILBC", 8000, 0, 1, 0)));
3199 EXPECT_TRUE(engine.FindCodec(
3200 cricket::AudioCodec(96, "iLBC", 8000, 0, 1, 0)));
3201 EXPECT_TRUE(engine.FindCodec(
3202 cricket::AudioCodec(96, "PCMU", 8000, 0, 1, 0)));
3203 EXPECT_TRUE(engine.FindCodec(
3204 cricket::AudioCodec(96, "PCMA", 8000, 0, 1, 0)));
3205 EXPECT_TRUE(engine.FindCodec(
henrik.lundin@webrtc.orgf85dbce2014-11-07 12:25:00 +00003206 cricket::AudioCodec(96, "G722", 8000, 0, 1, 0)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003207 EXPECT_TRUE(engine.FindCodec(
3208 cricket::AudioCodec(96, "red", 8000, 0, 1, 0)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003209 EXPECT_TRUE(engine.FindCodec(
3210 cricket::AudioCodec(96, "CN", 32000, 0, 1, 0)));
3211 EXPECT_TRUE(engine.FindCodec(
3212 cricket::AudioCodec(96, "CN", 16000, 0, 1, 0)));
3213 EXPECT_TRUE(engine.FindCodec(
3214 cricket::AudioCodec(96, "CN", 8000, 0, 1, 0)));
3215 EXPECT_TRUE(engine.FindCodec(
3216 cricket::AudioCodec(96, "telephone-event", 8000, 0, 1, 0)));
3217 // Check codecs with an id by id.
3218 EXPECT_TRUE(engine.FindCodec(
3219 cricket::AudioCodec(0, "", 8000, 0, 1, 0))); // PCMU
3220 EXPECT_TRUE(engine.FindCodec(
3221 cricket::AudioCodec(8, "", 8000, 0, 1, 0))); // PCMA
3222 EXPECT_TRUE(engine.FindCodec(
henrik.lundin@webrtc.orgf85dbce2014-11-07 12:25:00 +00003223 cricket::AudioCodec(9, "", 8000, 0, 1, 0))); // G722
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003224 EXPECT_TRUE(engine.FindCodec(
3225 cricket::AudioCodec(13, "", 8000, 0, 1, 0))); // CN
3226 // Check sample/bitrate matching.
3227 EXPECT_TRUE(engine.FindCodec(
3228 cricket::AudioCodec(0, "PCMU", 8000, 64000, 1, 0)));
3229 // Check that bad codecs fail.
3230 EXPECT_FALSE(engine.FindCodec(cricket::AudioCodec(99, "ABCD", 0, 0, 1, 0)));
3231 EXPECT_FALSE(engine.FindCodec(cricket::AudioCodec(88, "", 0, 0, 1, 0)));
3232 EXPECT_FALSE(engine.FindCodec(cricket::AudioCodec(0, "", 0, 0, 2, 0)));
3233 EXPECT_FALSE(engine.FindCodec(cricket::AudioCodec(0, "", 5000, 0, 1, 0)));
3234 EXPECT_FALSE(engine.FindCodec(cricket::AudioCodec(0, "", 0, 5000, 1, 0)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003235 // Verify the payload id of common audio codecs, including CN, ISAC, and G722.
3236 for (std::vector<cricket::AudioCodec>::const_iterator it =
3237 engine.codecs().begin(); it != engine.codecs().end(); ++it) {
3238 if (it->name == "CN" && it->clockrate == 16000) {
3239 EXPECT_EQ(105, it->id);
3240 } else if (it->name == "CN" && it->clockrate == 32000) {
3241 EXPECT_EQ(106, it->id);
3242 } else if (it->name == "ISAC" && it->clockrate == 16000) {
3243 EXPECT_EQ(103, it->id);
3244 } else if (it->name == "ISAC" && it->clockrate == 32000) {
3245 EXPECT_EQ(104, it->id);
henrik.lundin@webrtc.orgf85dbce2014-11-07 12:25:00 +00003246 } else if (it->name == "G722" && it->clockrate == 8000) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003247 EXPECT_EQ(9, it->id);
3248 } else if (it->name == "telephone-event") {
3249 EXPECT_EQ(126, it->id);
3250 } else if (it->name == "red") {
3251 EXPECT_EQ(127, it->id);
3252 } else if (it->name == "opus") {
3253 EXPECT_EQ(111, it->id);
wu@webrtc.org9caf2762013-12-11 18:25:07 +00003254 ASSERT_TRUE(it->params.find("minptime") != it->params.end());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003255 EXPECT_EQ("10", it->params.find("minptime")->second);
wu@webrtc.org9caf2762013-12-11 18:25:07 +00003256 ASSERT_TRUE(it->params.find("maxptime") != it->params.end());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003257 EXPECT_EQ("60", it->params.find("maxptime")->second);
minyue@webrtc.org4ef22d12014-11-17 09:26:39 +00003258 ASSERT_TRUE(it->params.find("useinbandfec") != it->params.end());
3259 EXPECT_EQ("1", it->params.find("useinbandfec")->second);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003260 }
3261 }
3262
3263 engine.Terminate();
3264}
3265
3266// Tests that VoE supports at least 32 channels
3267TEST(WebRtcVoiceEngineTest, Has32Channels) {
3268 cricket::WebRtcVoiceEngine engine;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003269 EXPECT_TRUE(engine.Init(rtc::Thread::Current()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003270
3271 cricket::VoiceMediaChannel* channels[32];
3272 int num_channels = 0;
3273
3274 while (num_channels < ARRAY_SIZE(channels)) {
3275 cricket::VoiceMediaChannel* channel = engine.CreateChannel();
3276 if (!channel)
3277 break;
3278
3279 channels[num_channels++] = channel;
3280 }
3281
3282 int expected = ARRAY_SIZE(channels);
3283 EXPECT_EQ(expected, num_channels);
3284
3285 while (num_channels > 0) {
3286 delete channels[--num_channels];
3287 }
3288
3289 engine.Terminate();
3290}
3291
3292// Test that we set our preferred codecs properly.
3293TEST(WebRtcVoiceEngineTest, SetRecvCodecs) {
3294 cricket::WebRtcVoiceEngine engine;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003295 EXPECT_TRUE(engine.Init(rtc::Thread::Current()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003296 cricket::WebRtcVoiceMediaChannel channel(&engine);
3297 EXPECT_TRUE(channel.SetRecvCodecs(engine.codecs()));
3298}
3299
3300#ifdef WIN32
3301// Test our workarounds to WebRtc VoE' munging of the coinit count
3302TEST(WebRtcVoiceEngineTest, CoInitialize) {
3303 cricket::WebRtcVoiceEngine* engine = new cricket::WebRtcVoiceEngine();
3304
3305 // Initial refcount should be 0.
3306 EXPECT_EQ(S_OK, CoInitializeEx(NULL, COINIT_MULTITHREADED));
3307
3308 // Engine should start even with COM already inited.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003309 EXPECT_TRUE(engine->Init(rtc::Thread::Current()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003310 engine->Terminate();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003311 EXPECT_TRUE(engine->Init(rtc::Thread::Current()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003312 engine->Terminate();
3313
3314 // Refcount after terminate should be 1 (in reality 3); test if it is nonzero.
3315 EXPECT_EQ(S_FALSE, CoInitializeEx(NULL, COINIT_MULTITHREADED));
3316 // Decrement refcount to (hopefully) 0.
3317 CoUninitialize();
3318 CoUninitialize();
3319 delete engine;
3320
3321 // Ensure refcount is 0.
3322 EXPECT_EQ(S_OK, CoInitializeEx(NULL, COINIT_MULTITHREADED));
3323 CoUninitialize();
3324}
3325#endif
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +00003326
3327TEST_F(WebRtcVoiceEngineTestFake, ChangeCombinedAudioVideoBweOption) {
3328 // Test that changing the combined_audio_video_bwe option results in the
3329 // expected state changes in VoiceEngine.
3330 cricket::ViEWrapper vie;
3331 const int kVieCh = 667;
3332
3333 EXPECT_TRUE(SetupEngine());
3334 cricket::WebRtcVoiceMediaChannel* media_channel =
3335 static_cast<cricket::WebRtcVoiceMediaChannel*>(channel_);
3336 EXPECT_TRUE(media_channel->SetupSharedBandwidthEstimation(vie.engine(),
3337 kVieCh));
3338 EXPECT_TRUE(media_channel->AddRecvStream(
3339 cricket::StreamParams::CreateLegacy(2)));
3340 int recv_ch = voe_.GetLastChannel();
3341
3342 // Combined BWE should not be set up yet.
3343 EXPECT_EQ(NULL, voe_.GetViENetwork(recv_ch));
3344 EXPECT_EQ(-1, voe_.GetVideoChannel(recv_ch));
3345
3346 // Enable combined BWE option - now it should be set up.
3347 cricket::AudioOptions options;
3348 options.combined_audio_video_bwe.Set(true);
3349 EXPECT_TRUE(media_channel->SetOptions(options));
3350 EXPECT_EQ(vie.network(), voe_.GetViENetwork(recv_ch));
3351 EXPECT_EQ(kVieCh, voe_.GetVideoChannel(recv_ch));
3352
3353 // Disable combined BWE option - should be disabled again.
3354 options.combined_audio_video_bwe.Set(false);
3355 EXPECT_TRUE(media_channel->SetOptions(options));
3356 EXPECT_EQ(NULL, voe_.GetViENetwork(recv_ch));
3357 EXPECT_EQ(-1, voe_.GetVideoChannel(recv_ch));
3358
3359 EXPECT_TRUE(media_channel->SetupSharedBandwidthEstimation(NULL, -1));
3360}
3361
3362TEST_F(WebRtcVoiceEngineTestFake, SetupSharedBandwidthEstimation) {
3363 // Test that calling SetupSharedBandwidthEstimation() on the voice media
3364 // channel results in the expected state changes in VoiceEngine.
3365 cricket::ViEWrapper vie1;
3366 cricket::ViEWrapper vie2;
3367 const int kVieCh1 = 667;
3368 const int kVieCh2 = 70;
3369
3370 EXPECT_TRUE(SetupEngine());
3371 cricket::WebRtcVoiceMediaChannel* media_channel =
3372 static_cast<cricket::WebRtcVoiceMediaChannel*>(channel_);
3373 cricket::AudioOptions options;
3374 options.combined_audio_video_bwe.Set(true);
3375 EXPECT_TRUE(media_channel->SetOptions(options));
3376 EXPECT_TRUE(media_channel->AddRecvStream(
3377 cricket::StreamParams::CreateLegacy(2)));
3378 int recv_ch = voe_.GetLastChannel();
3379
3380 // Combined BWE should not be set up yet.
3381 EXPECT_EQ(NULL, voe_.GetViENetwork(recv_ch));
3382 EXPECT_EQ(-1, voe_.GetVideoChannel(recv_ch));
3383
3384 // Register - should be enabled.
3385 EXPECT_TRUE(media_channel->SetupSharedBandwidthEstimation(vie1.engine(),
3386 kVieCh1));
3387 EXPECT_EQ(vie1.network(), voe_.GetViENetwork(recv_ch));
3388 EXPECT_EQ(kVieCh1, voe_.GetVideoChannel(recv_ch));
3389
3390 // Re-register - should still be enabled.
3391 EXPECT_TRUE(media_channel->SetupSharedBandwidthEstimation(vie2.engine(),
3392 kVieCh2));
3393 EXPECT_EQ(vie2.network(), voe_.GetViENetwork(recv_ch));
3394 EXPECT_EQ(kVieCh2, voe_.GetVideoChannel(recv_ch));
3395
3396 // Unregister - should be disabled again.
3397 EXPECT_TRUE(media_channel->SetupSharedBandwidthEstimation(NULL, -1));
3398 EXPECT_EQ(NULL, voe_.GetViENetwork(recv_ch));
3399 EXPECT_EQ(-1, voe_.GetVideoChannel(recv_ch));
3400}
3401
3402TEST_F(WebRtcVoiceEngineTestFake, ConfigureCombinedBweForNewRecvStreams) {
3403 // Test that adding receive streams after enabling combined bandwidth
3404 // estimation will correctly configure each channel.
3405 cricket::ViEWrapper vie;
3406 const int kVieCh = 667;
3407
3408 EXPECT_TRUE(SetupEngine());
3409 cricket::WebRtcVoiceMediaChannel* media_channel =
3410 static_cast<cricket::WebRtcVoiceMediaChannel*>(channel_);
3411 EXPECT_TRUE(media_channel->SetupSharedBandwidthEstimation(vie.engine(),
3412 kVieCh));
3413 cricket::AudioOptions options;
3414 options.combined_audio_video_bwe.Set(true);
3415 EXPECT_TRUE(media_channel->SetOptions(options));
3416
3417 static const uint32 kSsrcs[] = {1, 2, 3, 4};
3418 int voe_channels[ARRAY_SIZE(kSsrcs)] = {0};
3419 for (unsigned int i = 0; i < ARRAY_SIZE(kSsrcs); ++i) {
3420 EXPECT_TRUE(media_channel->AddRecvStream(
3421 cricket::StreamParams::CreateLegacy(kSsrcs[i])));
3422 int recv_ch = media_channel->GetReceiveChannelNum(kSsrcs[i]);
3423 EXPECT_NE(-1, recv_ch);
3424 voe_channels[i] = recv_ch;
3425 EXPECT_EQ(vie.network(), voe_.GetViENetwork(recv_ch));
3426 EXPECT_EQ(kVieCh, voe_.GetVideoChannel(recv_ch));
3427 }
3428
3429 EXPECT_TRUE(media_channel->SetupSharedBandwidthEstimation(NULL, -1));
3430
3431 for (unsigned int i = 0; i < ARRAY_SIZE(voe_channels); ++i) {
3432 EXPECT_EQ(NULL, voe_.GetViENetwork(voe_channels[i]));
3433 EXPECT_EQ(-1, voe_.GetVideoChannel(voe_channels[i]));
3434 }
3435}