blob: 59388bc5118ac5428cd488716fa5aed9bfb67bc8 [file] [log] [blame]
henrike@webrtc.org79047f92014-03-06 23:46:59 +00001/*
2 * libjingle
3 * Copyright 2008 Google Inc.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright notice,
11 * this list of conditions and the following disclaimer in the documentation
12 * and/or other materials provided with the distribution.
13 * 3. The name of the author may not be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
19 * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
21 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
22 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
23 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
24 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
25 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
henrike@webrtc.org28e20752013-07-10 00:45:36 +000027
28#ifdef WIN32
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000029#include "webrtc/base/win32.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000030#include <objbase.h>
31#endif
32
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000033#include "webrtc/base/byteorder.h"
34#include "webrtc/base/gunit.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000035#include "talk/media/base/constants.h"
36#include "talk/media/base/fakemediaengine.h"
37#include "talk/media/base/fakemediaprocessor.h"
wu@webrtc.orgde305012013-10-31 15:40:38 +000038#include "talk/media/base/fakenetworkinterface.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000039#include "talk/media/base/fakertp.h"
40#include "talk/media/webrtc/fakewebrtcvoiceengine.h"
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +000041#include "talk/media/webrtc/webrtcvie.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000042#include "talk/media/webrtc/webrtcvoiceengine.h"
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +000043#include "webrtc/p2p/base/fakesession.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000044#include "talk/session/media/channel.h"
45
46// Tests for the WebRtcVoiceEngine/VoiceChannel code.
47
buildbot@webrtc.org150835e2014-05-06 15:54:38 +000048using cricket::kRtpAudioLevelHeaderExtension;
49using cricket::kRtpAbsoluteSenderTimeHeaderExtension;
50
henrike@webrtc.org28e20752013-07-10 00:45:36 +000051static const cricket::AudioCodec kPcmuCodec(0, "PCMU", 8000, 64000, 1, 0);
52static const cricket::AudioCodec kIsacCodec(103, "ISAC", 16000, 32000, 1, 0);
henrike@webrtc.org28e20752013-07-10 00:45:36 +000053static const cricket::AudioCodec kOpusCodec(111, "opus", 48000, 64000, 2, 0);
henrik.lundin@webrtc.orgf85dbce2014-11-07 12:25:00 +000054static const cricket::AudioCodec kG722CodecVoE(9, "G722", 16000, 64000, 1, 0);
55static const cricket::AudioCodec kG722CodecSdp(9, "G722", 8000, 64000, 1, 0);
henrike@webrtc.org28e20752013-07-10 00:45:36 +000056static const cricket::AudioCodec kRedCodec(117, "red", 8000, 0, 1, 0);
57static const cricket::AudioCodec kCn8000Codec(13, "CN", 8000, 0, 1, 0);
58static const cricket::AudioCodec kCn16000Codec(105, "CN", 16000, 0, 1, 0);
59static const cricket::AudioCodec
60 kTelephoneEventCodec(106, "telephone-event", 8000, 0, 1, 0);
61static const cricket::AudioCodec* const kAudioCodecs[] = {
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +000062 &kPcmuCodec, &kIsacCodec, &kOpusCodec, &kG722CodecVoE, &kRedCodec,
63 &kCn8000Codec, &kCn16000Codec, &kTelephoneEventCodec,
henrike@webrtc.org28e20752013-07-10 00:45:36 +000064};
65const char kRingbackTone[] = "RIFF____WAVE____ABCD1234";
66static uint32 kSsrc1 = 0x99;
67static uint32 kSsrc2 = 0x98;
68
69class FakeVoEWrapper : public cricket::VoEWrapper {
70 public:
71 explicit FakeVoEWrapper(cricket::FakeWebRtcVoiceEngine* engine)
72 : cricket::VoEWrapper(engine, // processing
73 engine, // base
74 engine, // codec
75 engine, // dtmf
76 engine, // file
77 engine, // hw
78 engine, // media
79 engine, // neteq
80 engine, // network
81 engine, // rtp
82 engine, // sync
83 engine) { // volume
84 }
85};
86
wu@webrtc.org97077a32013-10-25 21:18:33 +000087class FakeVoETraceWrapper : public cricket::VoETraceWrapper {
henrike@webrtc.org28e20752013-07-10 00:45:36 +000088 public:
89 virtual int SetTraceFilter(const unsigned int filter) {
wu@webrtc.org97077a32013-10-25 21:18:33 +000090 filter_ = filter;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000091 return 0;
92 }
93 virtual int SetTraceFile(const char* fileNameUTF8) {
94 return 0;
95 }
96 virtual int SetTraceCallback(webrtc::TraceCallback* callback) {
97 return 0;
98 }
wu@webrtc.org97077a32013-10-25 21:18:33 +000099 unsigned int filter_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000100};
101
102class WebRtcVoiceEngineTestFake : public testing::Test {
103 public:
104 class ChannelErrorListener : public sigslot::has_slots<> {
105 public:
106 explicit ChannelErrorListener(cricket::VoiceMediaChannel* channel)
107 : ssrc_(0), error_(cricket::VoiceMediaChannel::ERROR_NONE) {
108 ASSERT(channel != NULL);
109 channel->SignalMediaError.connect(
110 this, &ChannelErrorListener::OnVoiceChannelError);
111 }
112 void OnVoiceChannelError(uint32 ssrc,
113 cricket::VoiceMediaChannel::Error error) {
114 ssrc_ = ssrc;
115 error_ = error;
116 }
117 void Reset() {
118 ssrc_ = 0;
119 error_ = cricket::VoiceMediaChannel::ERROR_NONE;
120 }
121 uint32 ssrc() const {
122 return ssrc_;
123 }
124 cricket::VoiceMediaChannel::Error error() const {
125 return error_;
126 }
127
128 private:
129 uint32 ssrc_;
130 cricket::VoiceMediaChannel::Error error_;
131 };
132
133 WebRtcVoiceEngineTestFake()
134 : voe_(kAudioCodecs, ARRAY_SIZE(kAudioCodecs)),
135 voe_sc_(kAudioCodecs, ARRAY_SIZE(kAudioCodecs)),
wu@webrtc.org97077a32013-10-25 21:18:33 +0000136 trace_wrapper_(new FakeVoETraceWrapper()),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000137 engine_(new FakeVoEWrapper(&voe_),
138 new FakeVoEWrapper(&voe_sc_),
wu@webrtc.org97077a32013-10-25 21:18:33 +0000139 trace_wrapper_),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000140 channel_(NULL), soundclip_(NULL) {
141 options_conference_.conference_mode.Set(true);
142 options_adjust_agc_.adjust_agc_delta.Set(-10);
143 }
buildbot@webrtc.org150835e2014-05-06 15:54:38 +0000144 bool SetupEngineWithoutStream() {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000145 if (!engine_.Init(rtc::Thread::Current())) {
buildbot@webrtc.org150835e2014-05-06 15:54:38 +0000146 return false;
147 }
148 channel_ = engine_.CreateChannel();
149 return (channel_ != NULL);
150 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000151 bool SetupEngine() {
buildbot@webrtc.org150835e2014-05-06 15:54:38 +0000152 if (!SetupEngineWithoutStream()) {
153 return false;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000154 }
buildbot@webrtc.org150835e2014-05-06 15:54:38 +0000155 return channel_->AddSendStream(
156 cricket::StreamParams::CreateLegacy(kSsrc1));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000157 }
wu@webrtc.org9dba5252013-08-05 20:36:57 +0000158 void SetupForMultiSendStream() {
159 EXPECT_TRUE(SetupEngine());
160 // Remove stream added in Setup, which is corresponding to default channel.
161 int default_channel_num = voe_.GetLastChannel();
henrike@webrtc.org7666db72013-08-22 14:45:42 +0000162 uint32 default_send_ssrc = 0u;
wu@webrtc.org9dba5252013-08-05 20:36:57 +0000163 EXPECT_EQ(0, voe_.GetLocalSSRC(default_channel_num, default_send_ssrc));
164 EXPECT_EQ(kSsrc1, default_send_ssrc);
165 EXPECT_TRUE(channel_->RemoveSendStream(default_send_ssrc));
166
167 // Verify the default channel still exists.
168 EXPECT_EQ(0, voe_.GetLocalSSRC(default_channel_num, default_send_ssrc));
169 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000170 void DeliverPacket(const void* data, int len) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000171 rtc::Buffer packet(data, len);
172 channel_->OnPacketReceived(&packet, rtc::PacketTime());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000173 }
174 virtual void TearDown() {
175 delete soundclip_;
176 delete channel_;
177 engine_.Terminate();
178 }
179
wu@webrtc.orgcadf9042013-08-30 21:24:16 +0000180 void TestInsertDtmf(uint32 ssrc, bool caller) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000181 EXPECT_TRUE(engine_.Init(rtc::Thread::Current()));
wu@webrtc.orgcadf9042013-08-30 21:24:16 +0000182 channel_ = engine_.CreateChannel();
183 EXPECT_TRUE(channel_ != NULL);
184 if (caller) {
185 // if this is a caller, local description will be applied and add the
186 // send stream.
187 EXPECT_TRUE(channel_->AddSendStream(
188 cricket::StreamParams::CreateLegacy(kSsrc1)));
189 }
190 int channel_id = voe_.GetLastChannel();
191
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000192 // Test we can only InsertDtmf when the other side supports telephone-event.
193 std::vector<cricket::AudioCodec> codecs;
194 codecs.push_back(kPcmuCodec);
195 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
196 EXPECT_TRUE(channel_->SetSend(cricket::SEND_MICROPHONE));
197 EXPECT_FALSE(channel_->CanInsertDtmf());
198 EXPECT_FALSE(channel_->InsertDtmf(ssrc, 1, 111, cricket::DF_SEND));
199 codecs.push_back(kTelephoneEventCodec);
200 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
201 EXPECT_TRUE(channel_->CanInsertDtmf());
wu@webrtc.orgcadf9042013-08-30 21:24:16 +0000202
203 if (!caller) {
204 // There's no active send channel yet.
205 EXPECT_FALSE(channel_->InsertDtmf(ssrc, 2, 123, cricket::DF_SEND));
206 EXPECT_TRUE(channel_->AddSendStream(
207 cricket::StreamParams::CreateLegacy(kSsrc1)));
208 }
209
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000210 // Check we fail if the ssrc is invalid.
211 EXPECT_FALSE(channel_->InsertDtmf(-1, 1, 111, cricket::DF_SEND));
212
213 // Test send
214 EXPECT_FALSE(voe_.WasSendTelephoneEventCalled(channel_id, 2, 123));
215 EXPECT_TRUE(channel_->InsertDtmf(ssrc, 2, 123, cricket::DF_SEND));
216 EXPECT_TRUE(voe_.WasSendTelephoneEventCalled(channel_id, 2, 123));
217
218 // Test play
219 EXPECT_FALSE(voe_.WasPlayDtmfToneCalled(3, 134));
220 EXPECT_TRUE(channel_->InsertDtmf(ssrc, 3, 134, cricket::DF_PLAY));
221 EXPECT_TRUE(voe_.WasPlayDtmfToneCalled(3, 134));
222
223 // Test send and play
224 EXPECT_FALSE(voe_.WasSendTelephoneEventCalled(channel_id, 4, 145));
225 EXPECT_FALSE(voe_.WasPlayDtmfToneCalled(4, 145));
226 EXPECT_TRUE(channel_->InsertDtmf(ssrc, 4, 145,
227 cricket::DF_PLAY | cricket::DF_SEND));
228 EXPECT_TRUE(voe_.WasSendTelephoneEventCalled(channel_id, 4, 145));
229 EXPECT_TRUE(voe_.WasPlayDtmfToneCalled(4, 145));
230 }
231
232 // Test that send bandwidth is set correctly.
233 // |codec| is the codec under test.
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000234 // |max_bitrate| is a parameter to set to SetMaxSendBandwidth().
235 // |expected_result| is the expected result from SetMaxSendBandwidth().
236 // |expected_bitrate| is the expected audio bitrate afterward.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000237 void TestSendBandwidth(const cricket::AudioCodec& codec,
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000238 int max_bitrate,
239 bool expected_result,
240 int expected_bitrate) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000241 int channel_num = voe_.GetLastChannel();
242 std::vector<cricket::AudioCodec> codecs;
243
244 codecs.push_back(codec);
245 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
246
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000247 bool result = channel_->SetMaxSendBandwidth(max_bitrate);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000248 EXPECT_EQ(expected_result, result);
249
wu@webrtc.org1d1ffc92013-10-16 18:12:02 +0000250 webrtc::CodecInst temp_codec;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000251 EXPECT_FALSE(voe_.GetSendCodec(channel_num, temp_codec));
252
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000253 EXPECT_EQ(expected_bitrate, temp_codec.rate);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000254 }
255
buildbot@webrtc.org150835e2014-05-06 15:54:38 +0000256 void TestSetSendRtpHeaderExtensions(const std::string& ext) {
257 EXPECT_TRUE(SetupEngineWithoutStream());
258 int channel_num = voe_.GetLastChannel();
wu@webrtc.org9dba5252013-08-05 20:36:57 +0000259
henrike@webrtc.org79047f92014-03-06 23:46:59 +0000260 // Ensure extensions are off by default.
buildbot@webrtc.org150835e2014-05-06 15:54:38 +0000261 EXPECT_EQ(-1, voe_.GetSendRtpExtensionId(channel_num, ext));
wu@webrtc.org9dba5252013-08-05 20:36:57 +0000262
buildbot@webrtc.org150835e2014-05-06 15:54:38 +0000263 std::vector<cricket::RtpHeaderExtension> extensions;
wu@webrtc.org9dba5252013-08-05 20:36:57 +0000264 // Ensure unknown extensions won't cause an error.
265 extensions.push_back(cricket::RtpHeaderExtension(
henrike@webrtc.org79047f92014-03-06 23:46:59 +0000266 "urn:ietf:params:unknownextention", 1));
wu@webrtc.org9dba5252013-08-05 20:36:57 +0000267 EXPECT_TRUE(channel_->SetSendRtpHeaderExtensions(extensions));
buildbot@webrtc.org150835e2014-05-06 15:54:38 +0000268 EXPECT_EQ(-1, voe_.GetSendRtpExtensionId(channel_num, ext));
wu@webrtc.org9dba5252013-08-05 20:36:57 +0000269
henrike@webrtc.org79047f92014-03-06 23:46:59 +0000270 // Ensure extensions stay off with an empty list of headers.
271 extensions.clear();
wu@webrtc.org9dba5252013-08-05 20:36:57 +0000272 EXPECT_TRUE(channel_->SetSendRtpHeaderExtensions(extensions));
buildbot@webrtc.org150835e2014-05-06 15:54:38 +0000273 EXPECT_EQ(-1, voe_.GetSendRtpExtensionId(channel_num, ext));
wu@webrtc.org9dba5252013-08-05 20:36:57 +0000274
buildbot@webrtc.org150835e2014-05-06 15:54:38 +0000275 // Ensure extension is set properly.
276 const int id = 1;
277 extensions.push_back(cricket::RtpHeaderExtension(ext, id));
wu@webrtc.org9dba5252013-08-05 20:36:57 +0000278 EXPECT_TRUE(channel_->SetSendRtpHeaderExtensions(extensions));
buildbot@webrtc.org150835e2014-05-06 15:54:38 +0000279 EXPECT_EQ(id, voe_.GetSendRtpExtensionId(channel_num, ext));
wu@webrtc.org9dba5252013-08-05 20:36:57 +0000280
buildbot@webrtc.org150835e2014-05-06 15:54:38 +0000281 // Ensure extension is set properly on new channel.
282 // The first stream to occupy the default channel.
283 EXPECT_TRUE(channel_->AddSendStream(
284 cricket::StreamParams::CreateLegacy(123)));
285 EXPECT_TRUE(channel_->AddSendStream(
286 cricket::StreamParams::CreateLegacy(234)));
287 int new_channel_num = voe_.GetLastChannel();
288 EXPECT_NE(channel_num, new_channel_num);
289 EXPECT_EQ(id, voe_.GetSendRtpExtensionId(new_channel_num, ext));
henrike@webrtc.org79047f92014-03-06 23:46:59 +0000290
291 // Ensure all extensions go back off with an empty list.
wu@webrtc.org9dba5252013-08-05 20:36:57 +0000292 extensions.clear();
293 EXPECT_TRUE(channel_->SetSendRtpHeaderExtensions(extensions));
buildbot@webrtc.org150835e2014-05-06 15:54:38 +0000294 EXPECT_EQ(-1, voe_.GetSendRtpExtensionId(channel_num, ext));
295 EXPECT_EQ(-1, voe_.GetSendRtpExtensionId(new_channel_num, ext));
henrike@webrtc.org79047f92014-03-06 23:46:59 +0000296 }
297
buildbot@webrtc.org150835e2014-05-06 15:54:38 +0000298 void TestSetRecvRtpHeaderExtensions(const std::string& ext) {
299 EXPECT_TRUE(SetupEngineWithoutStream());
300 int channel_num = voe_.GetLastChannel();
henrike@webrtc.org79047f92014-03-06 23:46:59 +0000301
henrike@webrtc.org79047f92014-03-06 23:46:59 +0000302 // Ensure extensions are off by default.
buildbot@webrtc.org150835e2014-05-06 15:54:38 +0000303 EXPECT_EQ(-1, voe_.GetReceiveRtpExtensionId(channel_num, ext));
henrike@webrtc.org79047f92014-03-06 23:46:59 +0000304
buildbot@webrtc.org150835e2014-05-06 15:54:38 +0000305 std::vector<cricket::RtpHeaderExtension> extensions;
henrike@webrtc.org79047f92014-03-06 23:46:59 +0000306 // Ensure unknown extensions won't cause an error.
307 extensions.push_back(cricket::RtpHeaderExtension(
308 "urn:ietf:params:unknownextention", 1));
309 EXPECT_TRUE(channel_->SetRecvRtpHeaderExtensions(extensions));
buildbot@webrtc.org150835e2014-05-06 15:54:38 +0000310 EXPECT_EQ(-1, voe_.GetReceiveRtpExtensionId(channel_num, ext));
henrike@webrtc.org79047f92014-03-06 23:46:59 +0000311
buildbot@webrtc.org150835e2014-05-06 15:54:38 +0000312 // Ensure extensions stay off with an empty list of headers.
henrike@webrtc.org79047f92014-03-06 23:46:59 +0000313 extensions.clear();
314 EXPECT_TRUE(channel_->SetRecvRtpHeaderExtensions(extensions));
buildbot@webrtc.org150835e2014-05-06 15:54:38 +0000315 EXPECT_EQ(-1, voe_.GetReceiveRtpExtensionId(channel_num, ext));
henrike@webrtc.org79047f92014-03-06 23:46:59 +0000316
buildbot@webrtc.org150835e2014-05-06 15:54:38 +0000317 // Ensure extension is set properly.
318 const int id = 2;
319 extensions.push_back(cricket::RtpHeaderExtension(ext, id));
henrike@webrtc.org79047f92014-03-06 23:46:59 +0000320 EXPECT_TRUE(channel_->SetRecvRtpHeaderExtensions(extensions));
buildbot@webrtc.org150835e2014-05-06 15:54:38 +0000321 EXPECT_EQ(id, voe_.GetReceiveRtpExtensionId(channel_num, ext));
henrike@webrtc.org79047f92014-03-06 23:46:59 +0000322
buildbot@webrtc.org150835e2014-05-06 15:54:38 +0000323 // Ensure extension is set properly on new channel.
324 // The first stream to occupy the default channel.
325 EXPECT_TRUE(channel_->AddRecvStream(
326 cricket::StreamParams::CreateLegacy(345)));
327 EXPECT_TRUE(channel_->AddRecvStream(
328 cricket::StreamParams::CreateLegacy(456)));
329 int new_channel_num = voe_.GetLastChannel();
330 EXPECT_NE(channel_num, new_channel_num);
331 EXPECT_EQ(id, voe_.GetReceiveRtpExtensionId(new_channel_num, ext));
332
333 // Ensure all extensions go back off with an empty list.
henrike@webrtc.org79047f92014-03-06 23:46:59 +0000334 extensions.clear();
335 EXPECT_TRUE(channel_->SetRecvRtpHeaderExtensions(extensions));
buildbot@webrtc.org150835e2014-05-06 15:54:38 +0000336 EXPECT_EQ(-1, voe_.GetReceiveRtpExtensionId(channel_num, ext));
337 EXPECT_EQ(-1, voe_.GetReceiveRtpExtensionId(new_channel_num, ext));
wu@webrtc.org9dba5252013-08-05 20:36:57 +0000338 }
339
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000340 protected:
341 cricket::FakeWebRtcVoiceEngine voe_;
342 cricket::FakeWebRtcVoiceEngine voe_sc_;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000343 FakeVoETraceWrapper* trace_wrapper_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000344 cricket::WebRtcVoiceEngine engine_;
345 cricket::VoiceMediaChannel* channel_;
346 cricket::SoundclipMedia* soundclip_;
347
348 cricket::AudioOptions options_conference_;
349 cricket::AudioOptions options_adjust_agc_;
350};
351
352// Tests that our stub library "works".
353TEST_F(WebRtcVoiceEngineTestFake, StartupShutdown) {
354 EXPECT_FALSE(voe_.IsInited());
355 EXPECT_FALSE(voe_sc_.IsInited());
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000356 EXPECT_TRUE(engine_.Init(rtc::Thread::Current()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000357 EXPECT_TRUE(voe_.IsInited());
wu@webrtc.org4551b792013-10-09 15:37:36 +0000358 // The soundclip engine is lazily initialized.
359 EXPECT_FALSE(voe_sc_.IsInited());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000360 engine_.Terminate();
361 EXPECT_FALSE(voe_.IsInited());
362 EXPECT_FALSE(voe_sc_.IsInited());
363}
364
365// Tests that we can create and destroy a channel.
366TEST_F(WebRtcVoiceEngineTestFake, CreateChannel) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000367 EXPECT_TRUE(engine_.Init(rtc::Thread::Current()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000368 channel_ = engine_.CreateChannel();
369 EXPECT_TRUE(channel_ != NULL);
370}
371
372// Tests that we properly handle failures in CreateChannel.
373TEST_F(WebRtcVoiceEngineTestFake, CreateChannelFail) {
374 voe_.set_fail_create_channel(true);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000375 EXPECT_TRUE(engine_.Init(rtc::Thread::Current()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000376 channel_ = engine_.CreateChannel();
377 EXPECT_TRUE(channel_ == NULL);
378}
379
380// Tests that the list of supported codecs is created properly and ordered
381// correctly
382TEST_F(WebRtcVoiceEngineTestFake, CodecPreference) {
383 const std::vector<cricket::AudioCodec>& codecs = engine_.codecs();
384 ASSERT_FALSE(codecs.empty());
385 EXPECT_STRCASEEQ("opus", codecs[0].name.c_str());
386 EXPECT_EQ(48000, codecs[0].clockrate);
387 EXPECT_EQ(2, codecs[0].channels);
388 EXPECT_EQ(64000, codecs[0].bitrate);
389 int pref = codecs[0].preference;
390 for (size_t i = 1; i < codecs.size(); ++i) {
391 EXPECT_GT(pref, codecs[i].preference);
392 pref = codecs[i].preference;
393 }
394}
395
396// Tests that we can find codecs by name or id, and that we interpret the
397// clockrate and bitrate fields properly.
398TEST_F(WebRtcVoiceEngineTestFake, FindCodec) {
399 cricket::AudioCodec codec;
400 webrtc::CodecInst codec_inst;
401 // Find PCMU with explicit clockrate and bitrate.
402 EXPECT_TRUE(engine_.FindWebRtcCodec(kPcmuCodec, &codec_inst));
403 // Find ISAC with explicit clockrate and 0 bitrate.
404 EXPECT_TRUE(engine_.FindWebRtcCodec(kIsacCodec, &codec_inst));
405 // Find telephone-event with explicit clockrate and 0 bitrate.
406 EXPECT_TRUE(engine_.FindWebRtcCodec(kTelephoneEventCodec, &codec_inst));
407 // Find ISAC with a different payload id.
408 codec = kIsacCodec;
409 codec.id = 127;
410 EXPECT_TRUE(engine_.FindWebRtcCodec(codec, &codec_inst));
411 EXPECT_EQ(codec.id, codec_inst.pltype);
412 // Find PCMU with a 0 clockrate.
413 codec = kPcmuCodec;
414 codec.clockrate = 0;
415 EXPECT_TRUE(engine_.FindWebRtcCodec(codec, &codec_inst));
416 EXPECT_EQ(codec.id, codec_inst.pltype);
417 EXPECT_EQ(8000, codec_inst.plfreq);
418 // Find PCMU with a 0 bitrate.
419 codec = kPcmuCodec;
420 codec.bitrate = 0;
421 EXPECT_TRUE(engine_.FindWebRtcCodec(codec, &codec_inst));
422 EXPECT_EQ(codec.id, codec_inst.pltype);
423 EXPECT_EQ(64000, codec_inst.rate);
424 // Find ISAC with an explicit bitrate.
425 codec = kIsacCodec;
426 codec.bitrate = 32000;
427 EXPECT_TRUE(engine_.FindWebRtcCodec(codec, &codec_inst));
428 EXPECT_EQ(codec.id, codec_inst.pltype);
429 EXPECT_EQ(32000, codec_inst.rate);
430}
431
432// Test that we set our inbound codecs properly, including changing PT.
433TEST_F(WebRtcVoiceEngineTestFake, SetRecvCodecs) {
434 EXPECT_TRUE(SetupEngine());
435 int channel_num = voe_.GetLastChannel();
436 std::vector<cricket::AudioCodec> codecs;
437 codecs.push_back(kIsacCodec);
438 codecs.push_back(kPcmuCodec);
439 codecs.push_back(kTelephoneEventCodec);
440 codecs[0].id = 106; // collide with existing telephone-event
441 codecs[2].id = 126;
442 EXPECT_TRUE(channel_->SetRecvCodecs(codecs));
443 webrtc::CodecInst gcodec;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000444 rtc::strcpyn(gcodec.plname, ARRAY_SIZE(gcodec.plname), "ISAC");
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000445 gcodec.plfreq = 16000;
446 gcodec.channels = 1;
447 EXPECT_EQ(0, voe_.GetRecPayloadType(channel_num, gcodec));
448 EXPECT_EQ(106, gcodec.pltype);
449 EXPECT_STREQ("ISAC", gcodec.plname);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000450 rtc::strcpyn(gcodec.plname, ARRAY_SIZE(gcodec.plname),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000451 "telephone-event");
452 gcodec.plfreq = 8000;
453 EXPECT_EQ(0, voe_.GetRecPayloadType(channel_num, gcodec));
454 EXPECT_EQ(126, gcodec.pltype);
455 EXPECT_STREQ("telephone-event", gcodec.plname);
456}
457
458// Test that we fail to set an unknown inbound codec.
459TEST_F(WebRtcVoiceEngineTestFake, SetRecvCodecsUnsupportedCodec) {
460 EXPECT_TRUE(SetupEngine());
461 std::vector<cricket::AudioCodec> codecs;
462 codecs.push_back(kIsacCodec);
463 codecs.push_back(cricket::AudioCodec(127, "XYZ", 32000, 0, 1, 0));
464 EXPECT_FALSE(channel_->SetRecvCodecs(codecs));
465}
466
467// Test that we fail if we have duplicate types in the inbound list.
468TEST_F(WebRtcVoiceEngineTestFake, SetRecvCodecsDuplicatePayloadType) {
469 EXPECT_TRUE(SetupEngine());
470 std::vector<cricket::AudioCodec> codecs;
471 codecs.push_back(kIsacCodec);
472 codecs.push_back(kCn16000Codec);
473 codecs[1].id = kIsacCodec.id;
474 EXPECT_FALSE(channel_->SetRecvCodecs(codecs));
475}
476
477// Test that we can decode OPUS without stereo parameters.
478TEST_F(WebRtcVoiceEngineTestFake, SetRecvCodecsWithOpusNoStereo) {
479 EXPECT_TRUE(SetupEngine());
480 EXPECT_TRUE(channel_->SetOptions(options_conference_));
481 std::vector<cricket::AudioCodec> codecs;
482 codecs.push_back(kIsacCodec);
483 codecs.push_back(kPcmuCodec);
484 codecs.push_back(kOpusCodec);
485 EXPECT_TRUE(channel_->SetRecvCodecs(codecs));
486 EXPECT_TRUE(channel_->AddRecvStream(
487 cricket::StreamParams::CreateLegacy(kSsrc1)));
488 int channel_num2 = voe_.GetLastChannel();
489 webrtc::CodecInst opus;
490 engine_.FindWebRtcCodec(kOpusCodec, &opus);
491 // Even without stereo parameters, recv codecs still specify channels = 2.
492 EXPECT_EQ(2, opus.channels);
493 EXPECT_EQ(111, opus.pltype);
494 EXPECT_STREQ("opus", opus.plname);
495 opus.pltype = 0;
496 EXPECT_EQ(0, voe_.GetRecPayloadType(channel_num2, opus));
497 EXPECT_EQ(111, opus.pltype);
498}
499
500// Test that we can decode OPUS with stereo = 0.
501TEST_F(WebRtcVoiceEngineTestFake, SetRecvCodecsWithOpus0Stereo) {
502 EXPECT_TRUE(SetupEngine());
503 EXPECT_TRUE(channel_->SetOptions(options_conference_));
504 std::vector<cricket::AudioCodec> codecs;
505 codecs.push_back(kIsacCodec);
506 codecs.push_back(kPcmuCodec);
507 codecs.push_back(kOpusCodec);
508 codecs[2].params["stereo"] = "0";
509 EXPECT_TRUE(channel_->SetRecvCodecs(codecs));
510 EXPECT_TRUE(channel_->AddRecvStream(
511 cricket::StreamParams::CreateLegacy(kSsrc1)));
512 int channel_num2 = voe_.GetLastChannel();
513 webrtc::CodecInst opus;
514 engine_.FindWebRtcCodec(kOpusCodec, &opus);
515 // Even when stereo is off, recv codecs still specify channels = 2.
516 EXPECT_EQ(2, opus.channels);
517 EXPECT_EQ(111, opus.pltype);
518 EXPECT_STREQ("opus", opus.plname);
519 opus.pltype = 0;
520 EXPECT_EQ(0, voe_.GetRecPayloadType(channel_num2, opus));
521 EXPECT_EQ(111, opus.pltype);
522}
523
524// Test that we can decode OPUS with stereo = 1.
525TEST_F(WebRtcVoiceEngineTestFake, SetRecvCodecsWithOpus1Stereo) {
526 EXPECT_TRUE(SetupEngine());
527 EXPECT_TRUE(channel_->SetOptions(options_conference_));
528 std::vector<cricket::AudioCodec> codecs;
529 codecs.push_back(kIsacCodec);
530 codecs.push_back(kPcmuCodec);
531 codecs.push_back(kOpusCodec);
532 codecs[2].params["stereo"] = "1";
533 EXPECT_TRUE(channel_->SetRecvCodecs(codecs));
534 EXPECT_TRUE(channel_->AddRecvStream(
535 cricket::StreamParams::CreateLegacy(kSsrc1)));
536 int channel_num2 = voe_.GetLastChannel();
537 webrtc::CodecInst opus;
538 engine_.FindWebRtcCodec(kOpusCodec, &opus);
539 EXPECT_EQ(2, opus.channels);
540 EXPECT_EQ(111, opus.pltype);
541 EXPECT_STREQ("opus", opus.plname);
542 opus.pltype = 0;
543 EXPECT_EQ(0, voe_.GetRecPayloadType(channel_num2, opus));
544 EXPECT_EQ(111, opus.pltype);
545}
546
547// Test that changes to recv codecs are applied to all streams.
548TEST_F(WebRtcVoiceEngineTestFake, SetRecvCodecsWithMultipleStreams) {
549 EXPECT_TRUE(SetupEngine());
550 EXPECT_TRUE(channel_->SetOptions(options_conference_));
551 std::vector<cricket::AudioCodec> codecs;
552 codecs.push_back(kIsacCodec);
553 codecs.push_back(kPcmuCodec);
554 codecs.push_back(kTelephoneEventCodec);
555 codecs[0].id = 106; // collide with existing telephone-event
556 codecs[2].id = 126;
557 EXPECT_TRUE(channel_->SetRecvCodecs(codecs));
558 EXPECT_TRUE(channel_->AddRecvStream(
559 cricket::StreamParams::CreateLegacy(kSsrc1)));
560 int channel_num2 = voe_.GetLastChannel();
561 webrtc::CodecInst gcodec;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000562 rtc::strcpyn(gcodec.plname, ARRAY_SIZE(gcodec.plname), "ISAC");
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000563 gcodec.plfreq = 16000;
564 gcodec.channels = 1;
565 EXPECT_EQ(0, voe_.GetRecPayloadType(channel_num2, gcodec));
566 EXPECT_EQ(106, gcodec.pltype);
567 EXPECT_STREQ("ISAC", gcodec.plname);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000568 rtc::strcpyn(gcodec.plname, ARRAY_SIZE(gcodec.plname),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000569 "telephone-event");
570 gcodec.plfreq = 8000;
571 gcodec.channels = 1;
572 EXPECT_EQ(0, voe_.GetRecPayloadType(channel_num2, gcodec));
573 EXPECT_EQ(126, gcodec.pltype);
574 EXPECT_STREQ("telephone-event", gcodec.plname);
575}
576
577TEST_F(WebRtcVoiceEngineTestFake, SetRecvCodecsAfterAddingStreams) {
578 EXPECT_TRUE(SetupEngine());
579 EXPECT_TRUE(channel_->SetOptions(options_conference_));
580 std::vector<cricket::AudioCodec> codecs;
581 codecs.push_back(kIsacCodec);
582 codecs[0].id = 106; // collide with existing telephone-event
583
584 EXPECT_TRUE(channel_->AddRecvStream(
585 cricket::StreamParams::CreateLegacy(kSsrc1)));
586 EXPECT_TRUE(channel_->SetRecvCodecs(codecs));
587
588 int channel_num2 = voe_.GetLastChannel();
589 webrtc::CodecInst gcodec;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000590 rtc::strcpyn(gcodec.plname, ARRAY_SIZE(gcodec.plname), "ISAC");
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000591 gcodec.plfreq = 16000;
592 gcodec.channels = 1;
593 EXPECT_EQ(0, voe_.GetRecPayloadType(channel_num2, gcodec));
594 EXPECT_EQ(106, gcodec.pltype);
595 EXPECT_STREQ("ISAC", gcodec.plname);
596}
597
598// Test that we can apply the same set of codecs again while playing.
599TEST_F(WebRtcVoiceEngineTestFake, SetRecvCodecsWhilePlaying) {
600 EXPECT_TRUE(SetupEngine());
601 int channel_num = voe_.GetLastChannel();
602 std::vector<cricket::AudioCodec> codecs;
603 codecs.push_back(kIsacCodec);
604 codecs.push_back(kCn16000Codec);
605 EXPECT_TRUE(channel_->SetRecvCodecs(codecs));
606 EXPECT_TRUE(channel_->SetPlayout(true));
607 EXPECT_TRUE(channel_->SetRecvCodecs(codecs));
608
609 // Changing the payload type of a codec should fail.
610 codecs[0].id = 127;
611 EXPECT_FALSE(channel_->SetRecvCodecs(codecs));
612 EXPECT_TRUE(voe_.GetPlayout(channel_num));
613}
614
615// Test that we can add a codec while playing.
616TEST_F(WebRtcVoiceEngineTestFake, AddRecvCodecsWhilePlaying) {
617 EXPECT_TRUE(SetupEngine());
618 int channel_num = voe_.GetLastChannel();
619 std::vector<cricket::AudioCodec> codecs;
620 codecs.push_back(kIsacCodec);
621 codecs.push_back(kCn16000Codec);
622 EXPECT_TRUE(channel_->SetRecvCodecs(codecs));
623 EXPECT_TRUE(channel_->SetPlayout(true));
624
625 codecs.push_back(kOpusCodec);
626 EXPECT_TRUE(channel_->SetRecvCodecs(codecs));
627 EXPECT_TRUE(voe_.GetPlayout(channel_num));
628 webrtc::CodecInst gcodec;
629 EXPECT_TRUE(engine_.FindWebRtcCodec(kOpusCodec, &gcodec));
630 EXPECT_EQ(kOpusCodec.id, gcodec.pltype);
631}
632
633TEST_F(WebRtcVoiceEngineTestFake, SetSendBandwidthAuto) {
634 EXPECT_TRUE(SetupEngine());
635 EXPECT_TRUE(channel_->SetSendCodecs(engine_.codecs()));
636
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000637 // Test that when autobw is enabled, bitrate is kept as the default
638 // value. autobw is enabled for the following tests because the target
639 // bitrate is <= 0.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000640
641 // ISAC, default bitrate == 32000.
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000642 TestSendBandwidth(kIsacCodec, 0, true, 32000);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000643
644 // PCMU, default bitrate == 64000.
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000645 TestSendBandwidth(kPcmuCodec, -1, true, 64000);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000646
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000647 // opus, default bitrate == 64000.
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000648 TestSendBandwidth(kOpusCodec, -1, true, 64000);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000649}
650
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000651TEST_F(WebRtcVoiceEngineTestFake, SetMaxSendBandwidthMultiRateAsCaller) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000652 EXPECT_TRUE(SetupEngine());
653 EXPECT_TRUE(channel_->SetSendCodecs(engine_.codecs()));
654
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000655 // Test that the bitrate of a multi-rate codec is always the maximum.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000656
657 // ISAC, default bitrate == 32000.
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000658 TestSendBandwidth(kIsacCodec, 128000, true, 128000);
659 TestSendBandwidth(kIsacCodec, 16000, true, 16000);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000660
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000661 // opus, default bitrate == 64000.
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000662 TestSendBandwidth(kOpusCodec, 96000, true, 96000);
663 TestSendBandwidth(kOpusCodec, 48000, true, 48000);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000664}
665
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000666TEST_F(WebRtcVoiceEngineTestFake, SetMaxSendBandwidthFixedRateAsCaller) {
667 EXPECT_TRUE(SetupEngine());
668 EXPECT_TRUE(channel_->SetSendCodecs(engine_.codecs()));
669
670 // Test that we can only set a maximum bitrate for a fixed-rate codec
671 // if it's bigger than the fixed rate.
672
673 // PCMU, fixed bitrate == 64000.
674 TestSendBandwidth(kPcmuCodec, 0, true, 64000);
675 TestSendBandwidth(kPcmuCodec, 1, false, 64000);
676 TestSendBandwidth(kPcmuCodec, 128000, true, 64000);
677 TestSendBandwidth(kPcmuCodec, 32000, false, 64000);
678 TestSendBandwidth(kPcmuCodec, 64000, true, 64000);
679 TestSendBandwidth(kPcmuCodec, 63999, false, 64000);
680 TestSendBandwidth(kPcmuCodec, 64001, true, 64000);
681}
682
683TEST_F(WebRtcVoiceEngineTestFake, SetMaxSendBandwidthMultiRateAsCallee) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000684 EXPECT_TRUE(engine_.Init(rtc::Thread::Current()));
wu@webrtc.org1d1ffc92013-10-16 18:12:02 +0000685 channel_ = engine_.CreateChannel();
686 EXPECT_TRUE(channel_ != NULL);
687 EXPECT_TRUE(channel_->SetSendCodecs(engine_.codecs()));
688
689 int desired_bitrate = 128000;
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000690 EXPECT_TRUE(channel_->SetMaxSendBandwidth(desired_bitrate));
wu@webrtc.org1d1ffc92013-10-16 18:12:02 +0000691
692 EXPECT_TRUE(channel_->AddSendStream(
693 cricket::StreamParams::CreateLegacy(kSsrc1)));
694
695 int channel_num = voe_.GetLastChannel();
696 webrtc::CodecInst codec;
697 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, codec));
698 EXPECT_EQ(desired_bitrate, codec.rate);
699}
700
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000701// Test that bitrate cannot be set for CBR codecs.
702// Bitrate is ignored if it is higher than the fixed bitrate.
703// Bitrate less then the fixed bitrate is an error.
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000704TEST_F(WebRtcVoiceEngineTestFake, SetMaxSendBandwidthCbr) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000705 EXPECT_TRUE(SetupEngine());
706 EXPECT_TRUE(channel_->SetSendCodecs(engine_.codecs()));
707
708 webrtc::CodecInst codec;
709 int channel_num = voe_.GetLastChannel();
710 std::vector<cricket::AudioCodec> codecs;
711
712 // PCMU, default bitrate == 64000.
713 codecs.push_back(kPcmuCodec);
714 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
715 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, codec));
716 EXPECT_EQ(64000, codec.rate);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000717 EXPECT_TRUE(channel_->SetMaxSendBandwidth(128000));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000718 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, codec));
719 EXPECT_EQ(64000, codec.rate);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000720 EXPECT_FALSE(channel_->SetMaxSendBandwidth(128));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000721 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, codec));
722 EXPECT_EQ(64000, codec.rate);
723}
724
725// Test that we apply codecs properly.
726TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecs) {
727 EXPECT_TRUE(SetupEngine());
728 int channel_num = voe_.GetLastChannel();
729 std::vector<cricket::AudioCodec> codecs;
730 codecs.push_back(kIsacCodec);
731 codecs.push_back(kPcmuCodec);
732 codecs.push_back(kRedCodec);
733 codecs[0].id = 96;
734 codecs[0].bitrate = 48000;
735 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
wu@webrtc.org05e7b442014-04-01 17:44:24 +0000736 EXPECT_EQ(1, voe_.GetNumSetSendCodecs());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000737 webrtc::CodecInst gcodec;
738 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
739 EXPECT_EQ(96, gcodec.pltype);
740 EXPECT_EQ(48000, gcodec.rate);
741 EXPECT_STREQ("ISAC", gcodec.plname);
742 EXPECT_FALSE(voe_.GetVAD(channel_num));
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +0000743 EXPECT_FALSE(voe_.GetRED(channel_num));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000744 EXPECT_EQ(13, voe_.GetSendCNPayloadType(channel_num, false));
745 EXPECT_EQ(105, voe_.GetSendCNPayloadType(channel_num, true));
746 EXPECT_EQ(106, voe_.GetSendTelephoneEventPayloadType(channel_num));
747}
748
wu@webrtc.org05e7b442014-04-01 17:44:24 +0000749// Test that VoE Channel doesn't call SetSendCodec again if same codec is tried
750// to apply.
751TEST_F(WebRtcVoiceEngineTestFake, DontResetSetSendCodec) {
752 EXPECT_TRUE(SetupEngine());
753 std::vector<cricket::AudioCodec> codecs;
754 codecs.push_back(kIsacCodec);
755 codecs.push_back(kPcmuCodec);
756 codecs.push_back(kRedCodec);
757 codecs[0].id = 96;
758 codecs[0].bitrate = 48000;
759 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
760 EXPECT_EQ(1, voe_.GetNumSetSendCodecs());
761 // Calling SetSendCodec again with same codec which is already set.
762 // In this case media channel shouldn't send codec to VoE.
763 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
764 EXPECT_EQ(1, voe_.GetNumSetSendCodecs());
765}
766
henrik.lundin@webrtc.orgf85dbce2014-11-07 12:25:00 +0000767// Verify that G722 is set with 16000 samples per second to WebRTC.
768TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecG722) {
769 EXPECT_TRUE(SetupEngine());
770 int channel_num = voe_.GetLastChannel();
771 std::vector<cricket::AudioCodec> codecs;
772 codecs.push_back(kG722CodecSdp);
773 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
774 webrtc::CodecInst gcodec;
775 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
776 EXPECT_STREQ("G722", gcodec.plname);
777 EXPECT_EQ(1, gcodec.channels);
778 EXPECT_EQ(16000, gcodec.plfreq);
779}
780
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000781// Test that if clockrate is not 48000 for opus, we fail.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000782TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecOpusBadClockrate) {
783 EXPECT_TRUE(SetupEngine());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000784 std::vector<cricket::AudioCodec> codecs;
785 codecs.push_back(kOpusCodec);
786 codecs[0].bitrate = 0;
787 codecs[0].clockrate = 50000;
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000788 EXPECT_FALSE(channel_->SetSendCodecs(codecs));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000789}
790
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000791// Test that if channels=0 for opus, we fail.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000792TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecOpusBad0ChannelsNoStereo) {
793 EXPECT_TRUE(SetupEngine());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000794 std::vector<cricket::AudioCodec> codecs;
795 codecs.push_back(kOpusCodec);
796 codecs[0].bitrate = 0;
797 codecs[0].channels = 0;
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000798 EXPECT_FALSE(channel_->SetSendCodecs(codecs));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000799}
800
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000801// Test that if channels=0 for opus, we fail.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000802TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecOpusBad0Channels1Stereo) {
803 EXPECT_TRUE(SetupEngine());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000804 std::vector<cricket::AudioCodec> codecs;
805 codecs.push_back(kOpusCodec);
806 codecs[0].bitrate = 0;
807 codecs[0].channels = 0;
808 codecs[0].params["stereo"] = "1";
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000809 EXPECT_FALSE(channel_->SetSendCodecs(codecs));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000810}
811
812// Test that if channel is 1 for opus and there's no stereo, we fail.
813TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecOpus1ChannelNoStereo) {
814 EXPECT_TRUE(SetupEngine());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000815 std::vector<cricket::AudioCodec> codecs;
816 codecs.push_back(kOpusCodec);
817 codecs[0].bitrate = 0;
818 codecs[0].channels = 1;
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000819 EXPECT_FALSE(channel_->SetSendCodecs(codecs));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000820}
821
822// Test that if channel is 1 for opus and stereo=0, we fail.
823TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecOpusBad1Channel0Stereo) {
824 EXPECT_TRUE(SetupEngine());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000825 std::vector<cricket::AudioCodec> codecs;
826 codecs.push_back(kOpusCodec);
827 codecs[0].bitrate = 0;
828 codecs[0].channels = 1;
829 codecs[0].params["stereo"] = "0";
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000830 EXPECT_FALSE(channel_->SetSendCodecs(codecs));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000831}
832
833// Test that if channel is 1 for opus and stereo=1, we fail.
834TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecOpusBad1Channel1Stereo) {
835 EXPECT_TRUE(SetupEngine());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000836 std::vector<cricket::AudioCodec> codecs;
837 codecs.push_back(kOpusCodec);
838 codecs[0].bitrate = 0;
839 codecs[0].channels = 1;
840 codecs[0].params["stereo"] = "1";
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000841 EXPECT_FALSE(channel_->SetSendCodecs(codecs));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000842}
843
844// Test that with bitrate=0 and no stereo,
845// channels and bitrate are 1 and 32000.
846TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecOpusGood0BitrateNoStereo) {
847 EXPECT_TRUE(SetupEngine());
848 int channel_num = voe_.GetLastChannel();
849 std::vector<cricket::AudioCodec> codecs;
850 codecs.push_back(kOpusCodec);
851 codecs[0].bitrate = 0;
852 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
853 webrtc::CodecInst gcodec;
854 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
855 EXPECT_STREQ("opus", gcodec.plname);
856 EXPECT_EQ(1, gcodec.channels);
857 EXPECT_EQ(32000, gcodec.rate);
858}
859
860// Test that with bitrate=0 and stereo=0,
861// channels and bitrate are 1 and 32000.
862TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecOpusGood0Bitrate0Stereo) {
863 EXPECT_TRUE(SetupEngine());
864 int channel_num = voe_.GetLastChannel();
865 std::vector<cricket::AudioCodec> codecs;
866 codecs.push_back(kOpusCodec);
867 codecs[0].bitrate = 0;
868 codecs[0].params["stereo"] = "0";
869 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
870 webrtc::CodecInst gcodec;
871 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
872 EXPECT_STREQ("opus", gcodec.plname);
873 EXPECT_EQ(1, gcodec.channels);
874 EXPECT_EQ(32000, gcodec.rate);
875}
876
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000877// Test that with bitrate=invalid and stereo=0,
878// channels and bitrate are 1 and 32000.
879TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecOpusGoodXBitrate0Stereo) {
880 EXPECT_TRUE(SetupEngine());
881 int channel_num = voe_.GetLastChannel();
882 std::vector<cricket::AudioCodec> codecs;
883 codecs.push_back(kOpusCodec);
884 codecs[0].params["stereo"] = "0";
885 webrtc::CodecInst gcodec;
886
buildbot@webrtc.org9d446f22014-10-23 12:22:06 +0000887 // bitrate that's out of the range between 6000 and 510000 will be clamped.
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000888 codecs[0].bitrate = 5999;
889 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
890 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
891 EXPECT_STREQ("opus", gcodec.plname);
892 EXPECT_EQ(1, gcodec.channels);
buildbot@webrtc.org9d446f22014-10-23 12:22:06 +0000893 EXPECT_EQ(6000, gcodec.rate);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000894
895 codecs[0].bitrate = 510001;
896 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
897 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
898 EXPECT_STREQ("opus", gcodec.plname);
899 EXPECT_EQ(1, gcodec.channels);
buildbot@webrtc.org9d446f22014-10-23 12:22:06 +0000900 EXPECT_EQ(510000, gcodec.rate);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000901}
902
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000903// Test that with bitrate=0 and stereo=1,
904// channels and bitrate are 2 and 64000.
905TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecOpusGood0Bitrate1Stereo) {
906 EXPECT_TRUE(SetupEngine());
907 int channel_num = voe_.GetLastChannel();
908 std::vector<cricket::AudioCodec> codecs;
909 codecs.push_back(kOpusCodec);
910 codecs[0].bitrate = 0;
911 codecs[0].params["stereo"] = "1";
912 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
913 webrtc::CodecInst gcodec;
914 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
915 EXPECT_STREQ("opus", gcodec.plname);
916 EXPECT_EQ(2, gcodec.channels);
917 EXPECT_EQ(64000, gcodec.rate);
918}
919
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000920// Test that with bitrate=invalid and stereo=1,
921// channels and bitrate are 2 and 64000.
922TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecOpusGoodXBitrate1Stereo) {
923 EXPECT_TRUE(SetupEngine());
924 int channel_num = voe_.GetLastChannel();
925 std::vector<cricket::AudioCodec> codecs;
926 codecs.push_back(kOpusCodec);
927 codecs[0].params["stereo"] = "1";
928 webrtc::CodecInst gcodec;
929
buildbot@webrtc.org9d446f22014-10-23 12:22:06 +0000930 // bitrate that's out of the range between 6000 and 510000 will be clamped.
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000931 codecs[0].bitrate = 5999;
932 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
933 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
934 EXPECT_STREQ("opus", gcodec.plname);
935 EXPECT_EQ(2, gcodec.channels);
buildbot@webrtc.org9d446f22014-10-23 12:22:06 +0000936 EXPECT_EQ(6000, gcodec.rate);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000937
938 codecs[0].bitrate = 510001;
939 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
940 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
941 EXPECT_STREQ("opus", gcodec.plname);
942 EXPECT_EQ(2, gcodec.channels);
buildbot@webrtc.org9d446f22014-10-23 12:22:06 +0000943 EXPECT_EQ(510000, gcodec.rate);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000944}
945
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000946// Test that with bitrate=N and stereo unset,
947// channels and bitrate are 1 and N.
948TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecOpusGoodNBitrateNoStereo) {
949 EXPECT_TRUE(SetupEngine());
950 int channel_num = voe_.GetLastChannel();
951 std::vector<cricket::AudioCodec> codecs;
952 codecs.push_back(kOpusCodec);
953 codecs[0].bitrate = 96000;
954 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
955 webrtc::CodecInst gcodec;
956 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
957 EXPECT_EQ(111, gcodec.pltype);
958 EXPECT_EQ(96000, gcodec.rate);
959 EXPECT_STREQ("opus", gcodec.plname);
960 EXPECT_EQ(1, gcodec.channels);
961 EXPECT_EQ(48000, gcodec.plfreq);
962}
963
964// Test that with bitrate=N and stereo=0,
965// channels and bitrate are 1 and N.
966TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecOpusGoodNBitrate0Stereo) {
967 EXPECT_TRUE(SetupEngine());
968 int channel_num = voe_.GetLastChannel();
969 std::vector<cricket::AudioCodec> codecs;
970 codecs.push_back(kOpusCodec);
971 codecs[0].bitrate = 30000;
972 codecs[0].params["stereo"] = "0";
973 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
974 webrtc::CodecInst gcodec;
975 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
976 EXPECT_EQ(1, gcodec.channels);
977 EXPECT_EQ(30000, gcodec.rate);
978 EXPECT_STREQ("opus", gcodec.plname);
979}
980
981// Test that with bitrate=N and without any parameters,
982// channels and bitrate are 1 and N.
983TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecOpusGoodNBitrateNoParameters) {
984 EXPECT_TRUE(SetupEngine());
985 int channel_num = voe_.GetLastChannel();
986 std::vector<cricket::AudioCodec> codecs;
987 codecs.push_back(kOpusCodec);
988 codecs[0].bitrate = 30000;
989 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
990 webrtc::CodecInst gcodec;
991 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
992 EXPECT_EQ(1, gcodec.channels);
993 EXPECT_EQ(30000, gcodec.rate);
994 EXPECT_STREQ("opus", gcodec.plname);
995}
996
997// Test that with bitrate=N and stereo=1,
998// channels and bitrate are 2 and N.
999TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecOpusGoodNBitrate1Stereo) {
1000 EXPECT_TRUE(SetupEngine());
1001 int channel_num = voe_.GetLastChannel();
1002 std::vector<cricket::AudioCodec> codecs;
1003 codecs.push_back(kOpusCodec);
1004 codecs[0].bitrate = 30000;
1005 codecs[0].params["stereo"] = "1";
1006 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1007 webrtc::CodecInst gcodec;
1008 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1009 EXPECT_EQ(2, gcodec.channels);
1010 EXPECT_EQ(30000, gcodec.rate);
1011 EXPECT_STREQ("opus", gcodec.plname);
1012}
1013
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00001014// Test that bitrate will be overridden by the "maxaveragebitrate" parameter.
1015// Also test that the "maxaveragebitrate" can't be set to values outside the
1016// range of 6000 and 510000
1017TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecOpusMaxAverageBitrate) {
1018 EXPECT_TRUE(SetupEngine());
1019 int channel_num = voe_.GetLastChannel();
1020 std::vector<cricket::AudioCodec> codecs;
1021 codecs.push_back(kOpusCodec);
1022 codecs[0].bitrate = 30000;
1023 webrtc::CodecInst gcodec;
1024
1025 // Ignore if less than 6000.
1026 codecs[0].params["maxaveragebitrate"] = "5999";
1027 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1028 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
buildbot@webrtc.org9d446f22014-10-23 12:22:06 +00001029 EXPECT_EQ(6000, gcodec.rate);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00001030
1031 // Ignore if larger than 510000.
1032 codecs[0].params["maxaveragebitrate"] = "510001";
1033 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1034 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
buildbot@webrtc.org9d446f22014-10-23 12:22:06 +00001035 EXPECT_EQ(510000, gcodec.rate);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00001036
1037 codecs[0].params["maxaveragebitrate"] = "200000";
1038 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1039 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1040 EXPECT_EQ(200000, gcodec.rate);
1041}
1042
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00001043// Test that we can enable NACK with opus as caller.
1044TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecEnableNackAsCaller) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001045 EXPECT_TRUE(SetupEngine());
1046 int channel_num = voe_.GetLastChannel();
1047 std::vector<cricket::AudioCodec> codecs;
1048 codecs.push_back(kOpusCodec);
1049 codecs[0].AddFeedbackParam(cricket::FeedbackParam(cricket::kRtcpFbParamNack,
1050 cricket::kParamValueEmpty));
1051 EXPECT_FALSE(voe_.GetNACK(channel_num));
1052 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1053 EXPECT_TRUE(voe_.GetNACK(channel_num));
1054}
1055
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00001056// Test that we can enable NACK with opus as callee.
1057TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecEnableNackAsCallee) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001058 EXPECT_TRUE(engine_.Init(rtc::Thread::Current()));
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00001059 channel_ = engine_.CreateChannel();
1060 EXPECT_TRUE(channel_ != NULL);
1061
1062 int channel_num = voe_.GetLastChannel();
1063 std::vector<cricket::AudioCodec> codecs;
1064 codecs.push_back(kOpusCodec);
1065 codecs[0].AddFeedbackParam(cricket::FeedbackParam(cricket::kRtcpFbParamNack,
1066 cricket::kParamValueEmpty));
1067 EXPECT_FALSE(voe_.GetNACK(channel_num));
1068 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1069 EXPECT_FALSE(voe_.GetNACK(channel_num));
1070
1071 EXPECT_TRUE(channel_->AddSendStream(
1072 cricket::StreamParams::CreateLegacy(kSsrc1)));
1073 EXPECT_TRUE(voe_.GetNACK(channel_num));
1074}
1075
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001076// Test that we can enable NACK on receive streams.
1077TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecEnableNackRecvStreams) {
1078 EXPECT_TRUE(SetupEngine());
1079 EXPECT_TRUE(channel_->SetOptions(options_conference_));
1080 int channel_num1 = voe_.GetLastChannel();
1081 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(2)));
1082 int channel_num2 = voe_.GetLastChannel();
1083 std::vector<cricket::AudioCodec> codecs;
1084 codecs.push_back(kOpusCodec);
1085 codecs[0].AddFeedbackParam(cricket::FeedbackParam(cricket::kRtcpFbParamNack,
1086 cricket::kParamValueEmpty));
1087 EXPECT_FALSE(voe_.GetNACK(channel_num1));
1088 EXPECT_FALSE(voe_.GetNACK(channel_num2));
1089 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1090 EXPECT_TRUE(voe_.GetNACK(channel_num1));
1091 EXPECT_TRUE(voe_.GetNACK(channel_num2));
1092}
1093
1094// Test that we can disable NACK.
1095TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecDisableNack) {
1096 EXPECT_TRUE(SetupEngine());
1097 int channel_num = voe_.GetLastChannel();
1098 std::vector<cricket::AudioCodec> codecs;
1099 codecs.push_back(kOpusCodec);
1100 codecs[0].AddFeedbackParam(cricket::FeedbackParam(cricket::kRtcpFbParamNack,
1101 cricket::kParamValueEmpty));
1102 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1103 EXPECT_TRUE(voe_.GetNACK(channel_num));
1104
1105 codecs.clear();
1106 codecs.push_back(kOpusCodec);
1107 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1108 EXPECT_FALSE(voe_.GetNACK(channel_num));
1109}
1110
1111// Test that we can disable NACK on receive streams.
1112TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecDisableNackRecvStreams) {
1113 EXPECT_TRUE(SetupEngine());
1114 EXPECT_TRUE(channel_->SetOptions(options_conference_));
1115 int channel_num1 = voe_.GetLastChannel();
1116 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(2)));
1117 int channel_num2 = voe_.GetLastChannel();
1118 std::vector<cricket::AudioCodec> codecs;
1119 codecs.push_back(kOpusCodec);
1120 codecs[0].AddFeedbackParam(cricket::FeedbackParam(cricket::kRtcpFbParamNack,
1121 cricket::kParamValueEmpty));
1122 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1123 EXPECT_TRUE(voe_.GetNACK(channel_num1));
1124 EXPECT_TRUE(voe_.GetNACK(channel_num2));
1125
1126 codecs.clear();
1127 codecs.push_back(kOpusCodec);
1128 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1129 EXPECT_FALSE(voe_.GetNACK(channel_num1));
1130 EXPECT_FALSE(voe_.GetNACK(channel_num2));
1131}
1132
1133// Test that NACK is enabled on a new receive stream.
1134TEST_F(WebRtcVoiceEngineTestFake, AddRecvStreamEnableNack) {
1135 EXPECT_TRUE(SetupEngine());
1136 EXPECT_TRUE(channel_->SetOptions(options_conference_));
1137 int channel_num = voe_.GetLastChannel();
1138 std::vector<cricket::AudioCodec> codecs;
1139 codecs.push_back(kIsacCodec);
1140 codecs[0].AddFeedbackParam(cricket::FeedbackParam(cricket::kRtcpFbParamNack,
1141 cricket::kParamValueEmpty));
1142 codecs.push_back(kCn16000Codec);
1143 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1144 EXPECT_TRUE(voe_.GetNACK(channel_num));
1145
1146 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(2)));
1147 channel_num = voe_.GetLastChannel();
1148 EXPECT_TRUE(voe_.GetNACK(channel_num));
1149 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(3)));
1150 channel_num = voe_.GetLastChannel();
1151 EXPECT_TRUE(voe_.GetNACK(channel_num));
1152}
1153
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +00001154// Test that without useinbandfec, Opus FEC is off.
buildbot@webrtc.orgd27d9ae2014-06-19 01:56:46 +00001155TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecNoOpusFec) {
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +00001156 EXPECT_TRUE(SetupEngine());
1157 int channel_num = voe_.GetLastChannel();
1158 std::vector<cricket::AudioCodec> codecs;
1159 codecs.push_back(kOpusCodec);
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +00001160 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1161 EXPECT_FALSE(voe_.GetCodecFEC(channel_num));
1162}
1163
1164// Test that with useinbandfec=0, Opus FEC is off.
buildbot@webrtc.orgd27d9ae2014-06-19 01:56:46 +00001165TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecOpusDisableFec) {
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +00001166 EXPECT_TRUE(SetupEngine());
1167 int channel_num = voe_.GetLastChannel();
1168 std::vector<cricket::AudioCodec> codecs;
1169 codecs.push_back(kOpusCodec);
1170 codecs[0].bitrate = 0;
1171 codecs[0].params["useinbandfec"] = "0";
1172 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1173 EXPECT_FALSE(voe_.GetCodecFEC(channel_num));
1174 webrtc::CodecInst gcodec;
1175 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1176 EXPECT_STREQ("opus", gcodec.plname);
1177 EXPECT_EQ(1, gcodec.channels);
1178 EXPECT_EQ(32000, gcodec.rate);
1179}
1180
1181// Test that with useinbandfec=1, Opus FEC is on.
buildbot@webrtc.orgd27d9ae2014-06-19 01:56:46 +00001182TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecOpusEnableFec) {
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +00001183 EXPECT_TRUE(SetupEngine());
1184 int channel_num = voe_.GetLastChannel();
1185 std::vector<cricket::AudioCodec> codecs;
1186 codecs.push_back(kOpusCodec);
1187 codecs[0].bitrate = 0;
1188 codecs[0].params["useinbandfec"] = "1";
1189 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1190 EXPECT_TRUE(voe_.GetCodecFEC(channel_num));
1191 webrtc::CodecInst gcodec;
1192 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1193 EXPECT_STREQ("opus", gcodec.plname);
1194 EXPECT_EQ(1, gcodec.channels);
1195 EXPECT_EQ(32000, gcodec.rate);
1196}
1197
1198// Test that with useinbandfec=1, stereo=1, Opus FEC is on.
buildbot@webrtc.orgd27d9ae2014-06-19 01:56:46 +00001199TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecOpusEnableFecStereo) {
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +00001200 EXPECT_TRUE(SetupEngine());
1201 int channel_num = voe_.GetLastChannel();
1202 std::vector<cricket::AudioCodec> codecs;
1203 codecs.push_back(kOpusCodec);
1204 codecs[0].bitrate = 0;
1205 codecs[0].params["stereo"] = "1";
1206 codecs[0].params["useinbandfec"] = "1";
1207 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1208 EXPECT_TRUE(voe_.GetCodecFEC(channel_num));
1209 webrtc::CodecInst gcodec;
1210 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1211 EXPECT_STREQ("opus", gcodec.plname);
1212 EXPECT_EQ(2, gcodec.channels);
1213 EXPECT_EQ(64000, gcodec.rate);
1214}
1215
1216// Test that with non-Opus, codec FEC is off.
buildbot@webrtc.orgd27d9ae2014-06-19 01:56:46 +00001217TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecIsacNoFec) {
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +00001218 EXPECT_TRUE(SetupEngine());
1219 int channel_num = voe_.GetLastChannel();
1220 std::vector<cricket::AudioCodec> codecs;
1221 codecs.push_back(kIsacCodec);
1222 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1223 EXPECT_FALSE(voe_.GetCodecFEC(channel_num));
1224}
buildbot@webrtc.org3ffa1f92014-07-02 19:51:26 +00001225
1226// Test the with non-Opus, even if useinbandfec=1, FEC is off.
1227TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecIsacWithParamNoFec) {
1228 EXPECT_TRUE(SetupEngine());
1229 int channel_num = voe_.GetLastChannel();
1230 std::vector<cricket::AudioCodec> codecs;
1231 codecs.push_back(kIsacCodec);
1232 codecs[0].params["useinbandfec"] = "1";
1233 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1234 EXPECT_FALSE(voe_.GetCodecFEC(channel_num));
1235}
buildbot@webrtc.org5d639b32014-09-10 07:57:12 +00001236
1237// Test that Opus FEC status can be changed.
1238TEST_F(WebRtcVoiceEngineTestFake, ChangeOpusFecStatus) {
1239 EXPECT_TRUE(SetupEngine());
1240 int channel_num = voe_.GetLastChannel();
1241 std::vector<cricket::AudioCodec> codecs;
1242 codecs.push_back(kOpusCodec);
1243 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1244 EXPECT_FALSE(voe_.GetCodecFEC(channel_num));
1245 codecs[0].params["useinbandfec"] = "1";
1246 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1247 EXPECT_TRUE(voe_.GetCodecFEC(channel_num));
1248}
1249
1250// Test maxplaybackrate <= 8000 triggers Opus narrow band mode.
1251TEST_F(WebRtcVoiceEngineTestFake, SetOpusMaxPlaybackRateNb) {
1252 EXPECT_TRUE(SetupEngine());
1253 int channel_num = voe_.GetLastChannel();
1254 std::vector<cricket::AudioCodec> codecs;
1255 codecs.push_back(kOpusCodec);
1256 codecs[0].bitrate = 0;
1257 codecs[0].SetParam(cricket::kCodecParamMaxPlaybackRate, 8000);
1258 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1259 EXPECT_EQ(cricket::kOpusBandwidthNb,
1260 voe_.GetMaxEncodingBandwidth(channel_num));
1261 webrtc::CodecInst gcodec;
1262 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1263 EXPECT_STREQ("opus", gcodec.plname);
minyue@webrtc.org2dc6f312014-10-31 05:33:10 +00001264
1265 EXPECT_EQ(12000, gcodec.rate);
1266 codecs[0].SetParam(cricket::kCodecParamStereo, "1");
1267 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1268 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1269 EXPECT_EQ(24000, gcodec.rate);
buildbot@webrtc.org5d639b32014-09-10 07:57:12 +00001270}
1271
1272// Test 8000 < maxplaybackrate <= 12000 triggers Opus medium band mode.
1273TEST_F(WebRtcVoiceEngineTestFake, SetOpusMaxPlaybackRateMb) {
1274 EXPECT_TRUE(SetupEngine());
1275 int channel_num = voe_.GetLastChannel();
1276 std::vector<cricket::AudioCodec> codecs;
1277 codecs.push_back(kOpusCodec);
1278 codecs[0].bitrate = 0;
1279 codecs[0].SetParam(cricket::kCodecParamMaxPlaybackRate, 8001);
1280 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1281 EXPECT_EQ(cricket::kOpusBandwidthMb,
1282 voe_.GetMaxEncodingBandwidth(channel_num));
1283 webrtc::CodecInst gcodec;
1284 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1285 EXPECT_STREQ("opus", gcodec.plname);
minyue@webrtc.org2dc6f312014-10-31 05:33:10 +00001286
1287 EXPECT_EQ(20000, gcodec.rate);
1288 codecs[0].SetParam(cricket::kCodecParamStereo, "1");
1289 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1290 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1291 EXPECT_EQ(40000, gcodec.rate);
buildbot@webrtc.org5d639b32014-09-10 07:57:12 +00001292}
1293
1294// Test 12000 < maxplaybackrate <= 16000 triggers Opus wide band mode.
1295TEST_F(WebRtcVoiceEngineTestFake, SetOpusMaxPlaybackRateWb) {
1296 EXPECT_TRUE(SetupEngine());
1297 int channel_num = voe_.GetLastChannel();
1298 std::vector<cricket::AudioCodec> codecs;
1299 codecs.push_back(kOpusCodec);
1300 codecs[0].bitrate = 0;
1301 codecs[0].SetParam(cricket::kCodecParamMaxPlaybackRate, 12001);
1302 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1303 EXPECT_EQ(cricket::kOpusBandwidthWb,
1304 voe_.GetMaxEncodingBandwidth(channel_num));
1305 webrtc::CodecInst gcodec;
1306 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1307 EXPECT_STREQ("opus", gcodec.plname);
minyue@webrtc.org2dc6f312014-10-31 05:33:10 +00001308
1309 EXPECT_EQ(20000, gcodec.rate);
1310 codecs[0].SetParam(cricket::kCodecParamStereo, "1");
1311 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1312 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1313 EXPECT_EQ(40000, gcodec.rate);
buildbot@webrtc.org5d639b32014-09-10 07:57:12 +00001314}
1315
1316// Test 16000 < maxplaybackrate <= 24000 triggers Opus super wide band mode.
1317TEST_F(WebRtcVoiceEngineTestFake, SetOpusMaxPlaybackRateSwb) {
1318 EXPECT_TRUE(SetupEngine());
1319 int channel_num = voe_.GetLastChannel();
1320 std::vector<cricket::AudioCodec> codecs;
1321 codecs.push_back(kOpusCodec);
1322 codecs[0].bitrate = 0;
1323 codecs[0].SetParam(cricket::kCodecParamMaxPlaybackRate, 16001);
1324 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1325 EXPECT_EQ(cricket::kOpusBandwidthSwb,
1326 voe_.GetMaxEncodingBandwidth(channel_num));
1327 webrtc::CodecInst gcodec;
1328 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1329 EXPECT_STREQ("opus", gcodec.plname);
minyue@webrtc.org2dc6f312014-10-31 05:33:10 +00001330
buildbot@webrtc.org5d639b32014-09-10 07:57:12 +00001331 EXPECT_EQ(32000, gcodec.rate);
minyue@webrtc.org2dc6f312014-10-31 05:33:10 +00001332 codecs[0].SetParam(cricket::kCodecParamStereo, "1");
1333 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1334 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1335 EXPECT_EQ(64000, gcodec.rate);
buildbot@webrtc.org5d639b32014-09-10 07:57:12 +00001336}
1337
1338// Test 24000 < maxplaybackrate triggers Opus full band mode.
1339TEST_F(WebRtcVoiceEngineTestFake, SetOpusMaxPlaybackRateFb) {
1340 EXPECT_TRUE(SetupEngine());
1341 int channel_num = voe_.GetLastChannel();
1342 std::vector<cricket::AudioCodec> codecs;
1343 codecs.push_back(kOpusCodec);
1344 codecs[0].bitrate = 0;
1345 codecs[0].SetParam(cricket::kCodecParamMaxPlaybackRate, 24001);
1346 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1347 EXPECT_EQ(cricket::kOpusBandwidthFb,
1348 voe_.GetMaxEncodingBandwidth(channel_num));
1349 webrtc::CodecInst gcodec;
1350 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1351 EXPECT_STREQ("opus", gcodec.plname);
minyue@webrtc.org2dc6f312014-10-31 05:33:10 +00001352
buildbot@webrtc.org5d639b32014-09-10 07:57:12 +00001353 EXPECT_EQ(32000, gcodec.rate);
minyue@webrtc.org2dc6f312014-10-31 05:33:10 +00001354 codecs[0].SetParam(cricket::kCodecParamStereo, "1");
1355 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1356 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1357 EXPECT_EQ(64000, gcodec.rate);
buildbot@webrtc.org5d639b32014-09-10 07:57:12 +00001358}
1359
1360// Test Opus that without maxplaybackrate, default playback rate is used.
1361TEST_F(WebRtcVoiceEngineTestFake, DefaultOpusMaxPlaybackRate) {
1362 EXPECT_TRUE(SetupEngine());
1363 int channel_num = voe_.GetLastChannel();
1364 std::vector<cricket::AudioCodec> codecs;
1365 codecs.push_back(kOpusCodec);
1366 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1367 EXPECT_EQ(cricket::kOpusBandwidthFb,
1368 voe_.GetMaxEncodingBandwidth(channel_num));
1369}
1370
1371// Test the with non-Opus, maxplaybackrate has no effect.
1372TEST_F(WebRtcVoiceEngineTestFake, SetNonOpusMaxPlaybackRate) {
1373 EXPECT_TRUE(SetupEngine());
1374 int channel_num = voe_.GetLastChannel();
1375 std::vector<cricket::AudioCodec> codecs;
1376 codecs.push_back(kIsacCodec);
1377 codecs[0].SetParam(cricket::kCodecParamMaxPlaybackRate, 32000);
1378 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1379 EXPECT_EQ(0, voe_.GetMaxEncodingBandwidth(channel_num));
1380}
1381
1382// Test maxplaybackrate can be set on two streams.
1383TEST_F(WebRtcVoiceEngineTestFake, SetOpusMaxPlaybackRateOnTwoStreams) {
1384 EXPECT_TRUE(SetupEngine());
1385 int channel_num = voe_.GetLastChannel();
1386 std::vector<cricket::AudioCodec> codecs;
1387 codecs.push_back(kOpusCodec);
1388 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1389 // Default bandwidth is 24000.
1390 EXPECT_EQ(cricket::kOpusBandwidthFb,
1391 voe_.GetMaxEncodingBandwidth(channel_num));
1392
1393 codecs[0].SetParam(cricket::kCodecParamMaxPlaybackRate, 8000);
1394
1395 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1396 EXPECT_EQ(cricket::kOpusBandwidthNb,
1397 voe_.GetMaxEncodingBandwidth(channel_num));
1398
1399 channel_->AddSendStream(cricket::StreamParams::CreateLegacy(kSsrc2));
1400 channel_num = voe_.GetLastChannel();
1401 EXPECT_EQ(cricket::kOpusBandwidthNb,
1402 voe_.GetMaxEncodingBandwidth(channel_num));
1403}
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +00001404
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +00001405// Test that we can switch back and forth between Opus and ISAC with CN.
1406TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecsIsacOpusSwitching) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001407 EXPECT_TRUE(SetupEngine());
1408 int channel_num = voe_.GetLastChannel();
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +00001409 std::vector<cricket::AudioCodec> opus_codecs;
1410 opus_codecs.push_back(kOpusCodec);
1411 EXPECT_TRUE(channel_->SetSendCodecs(opus_codecs));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001412 webrtc::CodecInst gcodec;
1413 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +00001414 EXPECT_EQ(111, gcodec.pltype);
1415 EXPECT_STREQ("opus", gcodec.plname);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001416
1417 std::vector<cricket::AudioCodec> isac_codecs;
1418 isac_codecs.push_back(kIsacCodec);
1419 isac_codecs.push_back(kCn16000Codec);
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +00001420 isac_codecs.push_back(kOpusCodec);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001421 EXPECT_TRUE(channel_->SetSendCodecs(isac_codecs));
1422 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1423 EXPECT_EQ(103, gcodec.pltype);
1424 EXPECT_STREQ("ISAC", gcodec.plname);
1425
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +00001426 EXPECT_TRUE(channel_->SetSendCodecs(opus_codecs));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001427 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +00001428 EXPECT_EQ(111, gcodec.pltype);
1429 EXPECT_STREQ("opus", gcodec.plname);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001430}
1431
1432// Test that we handle various ways of specifying bitrate.
1433TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecsBitrate) {
1434 EXPECT_TRUE(SetupEngine());
1435 int channel_num = voe_.GetLastChannel();
1436 std::vector<cricket::AudioCodec> codecs;
1437 codecs.push_back(kIsacCodec); // bitrate == 32000
1438 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1439 webrtc::CodecInst gcodec;
1440 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1441 EXPECT_EQ(103, gcodec.pltype);
1442 EXPECT_STREQ("ISAC", gcodec.plname);
1443 EXPECT_EQ(32000, gcodec.rate);
1444
1445 codecs[0].bitrate = 0; // bitrate == default
1446 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1447 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1448 EXPECT_EQ(103, gcodec.pltype);
1449 EXPECT_STREQ("ISAC", gcodec.plname);
1450 EXPECT_EQ(-1, gcodec.rate);
1451
1452 codecs[0].bitrate = 28000; // bitrate == 28000
1453 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1454 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1455 EXPECT_EQ(103, gcodec.pltype);
1456 EXPECT_STREQ("ISAC", gcodec.plname);
1457 EXPECT_EQ(28000, gcodec.rate);
1458
1459 codecs[0] = kPcmuCodec; // bitrate == 64000
1460 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1461 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1462 EXPECT_EQ(0, gcodec.pltype);
1463 EXPECT_STREQ("PCMU", gcodec.plname);
1464 EXPECT_EQ(64000, gcodec.rate);
1465
1466 codecs[0].bitrate = 0; // bitrate == default
1467 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1468 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1469 EXPECT_EQ(0, gcodec.pltype);
1470 EXPECT_STREQ("PCMU", gcodec.plname);
1471 EXPECT_EQ(64000, gcodec.rate);
1472
1473 codecs[0] = kOpusCodec;
1474 codecs[0].bitrate = 0; // bitrate == default
1475 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1476 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1477 EXPECT_EQ(111, gcodec.pltype);
1478 EXPECT_STREQ("opus", gcodec.plname);
1479 EXPECT_EQ(32000, gcodec.rate);
1480}
1481
Brave Yao5225dd82015-03-26 07:39:19 +08001482// Test that we could set packet size specified in kCodecParamPTime.
1483TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecsPTimeAsPacketSize) {
1484 EXPECT_TRUE(SetupEngine());
1485 int channel_num = voe_.GetLastChannel();
1486 std::vector<cricket::AudioCodec> codecs;
1487 codecs.push_back(kOpusCodec);
1488 codecs[0].SetParam(cricket::kCodecParamPTime, 40); // Value within range.
1489 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1490 webrtc::CodecInst gcodec;
1491 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1492 EXPECT_EQ(1920, gcodec.pacsize); // Opus gets 40ms.
1493
1494 codecs[0].SetParam(cricket::kCodecParamPTime, 5); // Value below range.
1495 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1496 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1497 EXPECT_EQ(480, gcodec.pacsize); // Opus gets 10ms.
1498
1499 codecs[0].SetParam(cricket::kCodecParamPTime, 80); // Value beyond range.
1500 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1501 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1502 EXPECT_EQ(2880, gcodec.pacsize); // Opus gets 60ms.
1503
1504 codecs[0] = kIsacCodec; // Also try Isac, and with unsupported size.
1505 codecs[0].SetParam(cricket::kCodecParamPTime, 40); // Value within range.
1506 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1507 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1508 EXPECT_EQ(480, gcodec.pacsize); // Isac gets 30ms as the next smallest value.
1509
1510 codecs[0] = kG722CodecSdp; // Try G722 @8kHz as negotiated in SDP.
1511 codecs[0].SetParam(cricket::kCodecParamPTime, 40);
1512 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1513 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1514 EXPECT_EQ(640, gcodec.pacsize); // G722 gets 40ms @16kHz as defined in VoE.
1515}
1516
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00001517// Test that we fail if no codecs are specified.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001518TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecsNoCodecs) {
1519 EXPECT_TRUE(SetupEngine());
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00001520 std::vector<cricket::AudioCodec> codecs;
1521 EXPECT_FALSE(channel_->SetSendCodecs(codecs));
1522}
1523
1524// Test that we can set send codecs even with telephone-event codec as the first
1525// one on the list.
1526TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecsDTMFOnTop) {
1527 EXPECT_TRUE(SetupEngine());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001528 int channel_num = voe_.GetLastChannel();
1529 std::vector<cricket::AudioCodec> codecs;
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00001530 codecs.push_back(kTelephoneEventCodec);
1531 codecs.push_back(kIsacCodec);
1532 codecs.push_back(kPcmuCodec);
1533 codecs[0].id = 98; // DTMF
1534 codecs[1].id = 96;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001535 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1536 webrtc::CodecInst gcodec;
1537 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00001538 EXPECT_EQ(96, gcodec.pltype);
1539 EXPECT_STREQ("ISAC", gcodec.plname);
1540 EXPECT_EQ(98, voe_.GetSendTelephoneEventPayloadType(channel_num));
1541}
1542
1543// Test that we can set send codecs even with CN codec as the first
1544// one on the list.
1545TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecsCNOnTop) {
1546 EXPECT_TRUE(SetupEngine());
1547 int channel_num = voe_.GetLastChannel();
1548 std::vector<cricket::AudioCodec> codecs;
1549 codecs.push_back(kCn16000Codec);
1550 codecs.push_back(kIsacCodec);
1551 codecs.push_back(kPcmuCodec);
1552 codecs[0].id = 98; // wideband CN
1553 codecs[1].id = 96;
1554 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1555 webrtc::CodecInst gcodec;
1556 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1557 EXPECT_EQ(96, gcodec.pltype);
1558 EXPECT_STREQ("ISAC", gcodec.plname);
1559 EXPECT_EQ(98, voe_.GetSendCNPayloadType(channel_num, true));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001560}
1561
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00001562// Test that we set VAD and DTMF types correctly as caller.
1563TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecsCNandDTMFAsCaller) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001564 EXPECT_TRUE(SetupEngine());
1565 int channel_num = voe_.GetLastChannel();
1566 std::vector<cricket::AudioCodec> codecs;
1567 codecs.push_back(kIsacCodec);
1568 codecs.push_back(kPcmuCodec);
1569 // TODO(juberti): cn 32000
1570 codecs.push_back(kCn16000Codec);
1571 codecs.push_back(kCn8000Codec);
1572 codecs.push_back(kTelephoneEventCodec);
1573 codecs.push_back(kRedCodec);
1574 codecs[0].id = 96;
1575 codecs[2].id = 97; // wideband CN
1576 codecs[4].id = 98; // DTMF
1577 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1578 webrtc::CodecInst gcodec;
1579 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1580 EXPECT_EQ(96, gcodec.pltype);
1581 EXPECT_STREQ("ISAC", gcodec.plname);
1582 EXPECT_TRUE(voe_.GetVAD(channel_num));
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +00001583 EXPECT_FALSE(voe_.GetRED(channel_num));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001584 EXPECT_EQ(13, voe_.GetSendCNPayloadType(channel_num, false));
1585 EXPECT_EQ(97, voe_.GetSendCNPayloadType(channel_num, true));
1586 EXPECT_EQ(98, voe_.GetSendTelephoneEventPayloadType(channel_num));
1587}
1588
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00001589// Test that we set VAD and DTMF types correctly as callee.
1590TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecsCNandDTMFAsCallee) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001591 EXPECT_TRUE(engine_.Init(rtc::Thread::Current()));
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00001592 channel_ = engine_.CreateChannel();
1593 EXPECT_TRUE(channel_ != NULL);
1594
1595 int channel_num = voe_.GetLastChannel();
1596 std::vector<cricket::AudioCodec> codecs;
1597 codecs.push_back(kIsacCodec);
1598 codecs.push_back(kPcmuCodec);
1599 // TODO(juberti): cn 32000
1600 codecs.push_back(kCn16000Codec);
1601 codecs.push_back(kCn8000Codec);
1602 codecs.push_back(kTelephoneEventCodec);
1603 codecs.push_back(kRedCodec);
1604 codecs[0].id = 96;
1605 codecs[2].id = 97; // wideband CN
1606 codecs[4].id = 98; // DTMF
1607 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1608 EXPECT_TRUE(channel_->AddSendStream(
1609 cricket::StreamParams::CreateLegacy(kSsrc1)));
1610
1611 webrtc::CodecInst gcodec;
1612 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1613 EXPECT_EQ(96, gcodec.pltype);
1614 EXPECT_STREQ("ISAC", gcodec.plname);
1615 EXPECT_TRUE(voe_.GetVAD(channel_num));
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +00001616 EXPECT_FALSE(voe_.GetRED(channel_num));
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00001617 EXPECT_EQ(13, voe_.GetSendCNPayloadType(channel_num, false));
1618 EXPECT_EQ(97, voe_.GetSendCNPayloadType(channel_num, true));
1619 EXPECT_EQ(98, voe_.GetSendTelephoneEventPayloadType(channel_num));
1620}
1621
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001622// Test that we only apply VAD if we have a CN codec that matches the
1623// send codec clockrate.
1624TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecsCNNoMatch) {
1625 EXPECT_TRUE(SetupEngine());
1626 int channel_num = voe_.GetLastChannel();
1627 std::vector<cricket::AudioCodec> codecs;
1628 // Set ISAC(16K) and CN(16K). VAD should be activated.
1629 codecs.push_back(kIsacCodec);
1630 codecs.push_back(kCn16000Codec);
1631 codecs[1].id = 97;
1632 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1633 webrtc::CodecInst gcodec;
1634 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1635 EXPECT_STREQ("ISAC", gcodec.plname);
1636 EXPECT_TRUE(voe_.GetVAD(channel_num));
1637 EXPECT_EQ(97, voe_.GetSendCNPayloadType(channel_num, true));
1638 // Set PCMU(8K) and CN(16K). VAD should not be activated.
1639 codecs[0] = kPcmuCodec;
1640 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1641 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1642 EXPECT_STREQ("PCMU", gcodec.plname);
1643 EXPECT_FALSE(voe_.GetVAD(channel_num));
1644 // Set PCMU(8K) and CN(8K). VAD should be activated.
1645 codecs[1] = kCn8000Codec;
1646 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1647 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1648 EXPECT_STREQ("PCMU", gcodec.plname);
1649 EXPECT_TRUE(voe_.GetVAD(channel_num));
1650 EXPECT_EQ(13, voe_.GetSendCNPayloadType(channel_num, false));
Brave Yao5225dd82015-03-26 07:39:19 +08001651 // Set ISAC(16K) and CN(8K). VAD should not be activated.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001652 codecs[0] = kIsacCodec;
1653 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1654 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1655 EXPECT_STREQ("ISAC", gcodec.plname);
1656 EXPECT_FALSE(voe_.GetVAD(channel_num));
1657}
1658
1659// Test that we perform case-insensitive matching of codec names.
1660TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecsCaseInsensitive) {
1661 EXPECT_TRUE(SetupEngine());
1662 int channel_num = voe_.GetLastChannel();
1663 std::vector<cricket::AudioCodec> codecs;
1664 codecs.push_back(kIsacCodec);
1665 codecs.push_back(kPcmuCodec);
1666 codecs.push_back(kCn16000Codec);
1667 codecs.push_back(kCn8000Codec);
1668 codecs.push_back(kTelephoneEventCodec);
1669 codecs.push_back(kRedCodec);
1670 codecs[0].name = "iSaC";
1671 codecs[0].id = 96;
1672 codecs[2].id = 97; // wideband CN
1673 codecs[4].id = 98; // DTMF
1674 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1675 webrtc::CodecInst gcodec;
1676 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1677 EXPECT_EQ(96, gcodec.pltype);
1678 EXPECT_STREQ("ISAC", gcodec.plname);
1679 EXPECT_TRUE(voe_.GetVAD(channel_num));
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +00001680 EXPECT_FALSE(voe_.GetRED(channel_num));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001681 EXPECT_EQ(13, voe_.GetSendCNPayloadType(channel_num, false));
1682 EXPECT_EQ(97, voe_.GetSendCNPayloadType(channel_num, true));
1683 EXPECT_EQ(98, voe_.GetSendTelephoneEventPayloadType(channel_num));
1684}
1685
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +00001686// Test that we set up RED correctly as caller.
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00001687TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecsREDAsCaller) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001688 EXPECT_TRUE(SetupEngine());
1689 int channel_num = voe_.GetLastChannel();
1690 std::vector<cricket::AudioCodec> codecs;
1691 codecs.push_back(kRedCodec);
1692 codecs.push_back(kIsacCodec);
1693 codecs.push_back(kPcmuCodec);
1694 codecs[0].id = 127;
1695 codecs[0].params[""] = "96/96";
1696 codecs[1].id = 96;
1697 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1698 webrtc::CodecInst gcodec;
1699 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1700 EXPECT_EQ(96, gcodec.pltype);
1701 EXPECT_STREQ("ISAC", gcodec.plname);
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +00001702 EXPECT_TRUE(voe_.GetRED(channel_num));
1703 EXPECT_EQ(127, voe_.GetSendREDPayloadType(channel_num));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001704}
1705
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +00001706// Test that we set up RED correctly as callee.
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00001707TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecsREDAsCallee) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001708 EXPECT_TRUE(engine_.Init(rtc::Thread::Current()));
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00001709 channel_ = engine_.CreateChannel();
1710 EXPECT_TRUE(channel_ != NULL);
1711
1712 int channel_num = voe_.GetLastChannel();
1713 std::vector<cricket::AudioCodec> codecs;
1714 codecs.push_back(kRedCodec);
1715 codecs.push_back(kIsacCodec);
1716 codecs.push_back(kPcmuCodec);
1717 codecs[0].id = 127;
1718 codecs[0].params[""] = "96/96";
1719 codecs[1].id = 96;
1720 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1721 EXPECT_TRUE(channel_->AddSendStream(
1722 cricket::StreamParams::CreateLegacy(kSsrc1)));
1723 webrtc::CodecInst gcodec;
1724 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1725 EXPECT_EQ(96, gcodec.pltype);
1726 EXPECT_STREQ("ISAC", gcodec.plname);
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +00001727 EXPECT_TRUE(voe_.GetRED(channel_num));
1728 EXPECT_EQ(127, voe_.GetSendREDPayloadType(channel_num));
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00001729}
1730
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +00001731// Test that we set up RED correctly if params are omitted.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001732TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecsREDNoParams) {
1733 EXPECT_TRUE(SetupEngine());
1734 int channel_num = voe_.GetLastChannel();
1735 std::vector<cricket::AudioCodec> codecs;
1736 codecs.push_back(kRedCodec);
1737 codecs.push_back(kIsacCodec);
1738 codecs.push_back(kPcmuCodec);
1739 codecs[0].id = 127;
1740 codecs[1].id = 96;
1741 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1742 webrtc::CodecInst gcodec;
1743 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1744 EXPECT_EQ(96, gcodec.pltype);
1745 EXPECT_STREQ("ISAC", gcodec.plname);
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +00001746 EXPECT_TRUE(voe_.GetRED(channel_num));
1747 EXPECT_EQ(127, voe_.GetSendREDPayloadType(channel_num));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001748}
1749
1750// Test that we ignore RED if the parameters aren't named the way we expect.
1751TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecsBadRED1) {
1752 EXPECT_TRUE(SetupEngine());
1753 int channel_num = voe_.GetLastChannel();
1754 std::vector<cricket::AudioCodec> codecs;
1755 codecs.push_back(kRedCodec);
1756 codecs.push_back(kIsacCodec);
1757 codecs.push_back(kPcmuCodec);
1758 codecs[0].id = 127;
1759 codecs[0].params["ABC"] = "96/96";
1760 codecs[1].id = 96;
1761 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1762 webrtc::CodecInst gcodec;
1763 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1764 EXPECT_EQ(96, gcodec.pltype);
1765 EXPECT_STREQ("ISAC", gcodec.plname);
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +00001766 EXPECT_FALSE(voe_.GetRED(channel_num));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001767}
1768
1769// Test that we ignore RED if it uses different primary/secondary encoding.
1770TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecsBadRED2) {
1771 EXPECT_TRUE(SetupEngine());
1772 int channel_num = voe_.GetLastChannel();
1773 std::vector<cricket::AudioCodec> codecs;
1774 codecs.push_back(kRedCodec);
1775 codecs.push_back(kIsacCodec);
1776 codecs.push_back(kPcmuCodec);
1777 codecs[0].id = 127;
1778 codecs[0].params[""] = "96/0";
1779 codecs[1].id = 96;
1780 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1781 webrtc::CodecInst gcodec;
1782 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1783 EXPECT_EQ(96, gcodec.pltype);
1784 EXPECT_STREQ("ISAC", gcodec.plname);
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +00001785 EXPECT_FALSE(voe_.GetRED(channel_num));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001786}
1787
1788// Test that we ignore RED if it uses more than 2 encodings.
1789TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecsBadRED3) {
1790 EXPECT_TRUE(SetupEngine());
1791 int channel_num = voe_.GetLastChannel();
1792 std::vector<cricket::AudioCodec> codecs;
1793 codecs.push_back(kRedCodec);
1794 codecs.push_back(kIsacCodec);
1795 codecs.push_back(kPcmuCodec);
1796 codecs[0].id = 127;
1797 codecs[0].params[""] = "96/96/96";
1798 codecs[1].id = 96;
1799 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1800 webrtc::CodecInst gcodec;
1801 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1802 EXPECT_EQ(96, gcodec.pltype);
1803 EXPECT_STREQ("ISAC", gcodec.plname);
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +00001804 EXPECT_FALSE(voe_.GetRED(channel_num));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001805}
1806
1807// Test that we ignore RED if it has bogus codec ids.
1808TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecsBadRED4) {
1809 EXPECT_TRUE(SetupEngine());
1810 int channel_num = voe_.GetLastChannel();
1811 std::vector<cricket::AudioCodec> codecs;
1812 codecs.push_back(kRedCodec);
1813 codecs.push_back(kIsacCodec);
1814 codecs.push_back(kPcmuCodec);
1815 codecs[0].id = 127;
1816 codecs[0].params[""] = "ABC/ABC";
1817 codecs[1].id = 96;
1818 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1819 webrtc::CodecInst gcodec;
1820 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1821 EXPECT_EQ(96, gcodec.pltype);
1822 EXPECT_STREQ("ISAC", gcodec.plname);
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +00001823 EXPECT_FALSE(voe_.GetRED(channel_num));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001824}
1825
1826// Test that we ignore RED if it refers to a codec that is not present.
1827TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecsBadRED5) {
1828 EXPECT_TRUE(SetupEngine());
1829 int channel_num = voe_.GetLastChannel();
1830 std::vector<cricket::AudioCodec> codecs;
1831 codecs.push_back(kRedCodec);
1832 codecs.push_back(kIsacCodec);
1833 codecs.push_back(kPcmuCodec);
1834 codecs[0].id = 127;
1835 codecs[0].params[""] = "97/97";
1836 codecs[1].id = 96;
1837 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1838 webrtc::CodecInst gcodec;
1839 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1840 EXPECT_EQ(96, gcodec.pltype);
1841 EXPECT_STREQ("ISAC", gcodec.plname);
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +00001842 EXPECT_FALSE(voe_.GetRED(channel_num));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001843}
1844
buildbot@webrtc.org150835e2014-05-06 15:54:38 +00001845// Test support for audio level header extension.
1846TEST_F(WebRtcVoiceEngineTestFake, SendAudioLevelHeaderExtensions) {
1847 TestSetSendRtpHeaderExtensions(kRtpAudioLevelHeaderExtension);
henrike@webrtc.org79047f92014-03-06 23:46:59 +00001848}
buildbot@webrtc.org150835e2014-05-06 15:54:38 +00001849TEST_F(WebRtcVoiceEngineTestFake, RecvAudioLevelHeaderExtensions) {
1850 TestSetRecvRtpHeaderExtensions(kRtpAudioLevelHeaderExtension);
1851}
henrike@webrtc.org79047f92014-03-06 23:46:59 +00001852
buildbot@webrtc.org150835e2014-05-06 15:54:38 +00001853// Test support for absolute send time header extension.
1854TEST_F(WebRtcVoiceEngineTestFake, SendAbsoluteSendTimeHeaderExtensions) {
1855 TestSetSendRtpHeaderExtensions(kRtpAbsoluteSenderTimeHeaderExtension);
1856}
1857TEST_F(WebRtcVoiceEngineTestFake, RecvAbsoluteSendTimeHeaderExtensions) {
1858 TestSetRecvRtpHeaderExtensions(kRtpAbsoluteSenderTimeHeaderExtension);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001859}
1860
1861// Test that we can create a channel and start sending/playing out on it.
1862TEST_F(WebRtcVoiceEngineTestFake, SendAndPlayout) {
1863 EXPECT_TRUE(SetupEngine());
1864 int channel_num = voe_.GetLastChannel();
1865 std::vector<cricket::AudioCodec> codecs;
1866 codecs.push_back(kPcmuCodec);
1867 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1868 EXPECT_TRUE(channel_->SetSend(cricket::SEND_MICROPHONE));
1869 EXPECT_TRUE(voe_.GetSend(channel_num));
1870 EXPECT_TRUE(channel_->SetPlayout(true));
1871 EXPECT_TRUE(voe_.GetPlayout(channel_num));
1872 EXPECT_TRUE(channel_->SetSend(cricket::SEND_NOTHING));
1873 EXPECT_FALSE(voe_.GetSend(channel_num));
1874 EXPECT_TRUE(channel_->SetPlayout(false));
1875 EXPECT_FALSE(voe_.GetPlayout(channel_num));
1876}
1877
wu@webrtc.org9dba5252013-08-05 20:36:57 +00001878// Test that we can add and remove send streams.
1879TEST_F(WebRtcVoiceEngineTestFake, CreateAndDeleteMultipleSendStreams) {
1880 SetupForMultiSendStream();
1881
1882 static const uint32 kSsrcs4[] = {1, 2, 3, 4};
1883
1884 // Set the global state for sending.
1885 EXPECT_TRUE(channel_->SetSend(cricket::SEND_MICROPHONE));
1886
1887 for (unsigned int i = 0; i < ARRAY_SIZE(kSsrcs4); ++i) {
1888 EXPECT_TRUE(channel_->AddSendStream(
1889 cricket::StreamParams::CreateLegacy(kSsrcs4[i])));
1890
1891 // Verify that we are in a sending state for all the created streams.
1892 int channel_num = voe_.GetChannelFromLocalSsrc(kSsrcs4[i]);
1893 EXPECT_TRUE(voe_.GetSend(channel_num));
1894 }
1895
1896 // Remove the first send channel, which is the default channel. It will only
1897 // recycle the default channel but not delete it.
1898 EXPECT_TRUE(channel_->RemoveSendStream(kSsrcs4[0]));
1899 // Stream should already be Removed from the send stream list.
1900 EXPECT_FALSE(channel_->RemoveSendStream(kSsrcs4[0]));
1901 // But the default still exists.
1902 EXPECT_EQ(0, voe_.GetChannelFromLocalSsrc(kSsrcs4[0]));
1903
1904 // Delete the rest of send channel streams.
1905 for (unsigned int i = 1; i < ARRAY_SIZE(kSsrcs4); ++i) {
1906 EXPECT_TRUE(channel_->RemoveSendStream(kSsrcs4[i]));
1907 // Stream should already be deleted.
1908 EXPECT_FALSE(channel_->RemoveSendStream(kSsrcs4[i]));
1909 EXPECT_EQ(-1, voe_.GetChannelFromLocalSsrc(kSsrcs4[i]));
1910 }
1911}
1912
1913// Test SetSendCodecs correctly configure the codecs in all send streams.
1914TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecsWithMultipleSendStreams) {
1915 SetupForMultiSendStream();
1916
1917 static const uint32 kSsrcs4[] = {1, 2, 3, 4};
1918 // Create send streams.
1919 for (unsigned int i = 0; i < ARRAY_SIZE(kSsrcs4); ++i) {
1920 EXPECT_TRUE(channel_->AddSendStream(
1921 cricket::StreamParams::CreateLegacy(kSsrcs4[i])));
1922 }
1923
1924 std::vector<cricket::AudioCodec> codecs;
1925 // Set ISAC(16K) and CN(16K). VAD should be activated.
1926 codecs.push_back(kIsacCodec);
1927 codecs.push_back(kCn16000Codec);
1928 codecs[1].id = 97;
1929 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1930
1931 // Verify ISAC and VAD are corrected configured on all send channels.
1932 webrtc::CodecInst gcodec;
1933 for (unsigned int i = 0; i < ARRAY_SIZE(kSsrcs4); ++i) {
1934 int channel_num = voe_.GetChannelFromLocalSsrc(kSsrcs4[i]);
1935 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1936 EXPECT_STREQ("ISAC", gcodec.plname);
1937 EXPECT_TRUE(voe_.GetVAD(channel_num));
1938 EXPECT_EQ(97, voe_.GetSendCNPayloadType(channel_num, true));
1939 }
1940
1941 // Change to PCMU(8K) and CN(16K). VAD should not be activated.
1942 codecs[0] = kPcmuCodec;
1943 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1944 for (unsigned int i = 0; i < ARRAY_SIZE(kSsrcs4); ++i) {
1945 int channel_num = voe_.GetChannelFromLocalSsrc(kSsrcs4[i]);
1946 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1947 EXPECT_STREQ("PCMU", gcodec.plname);
1948 EXPECT_FALSE(voe_.GetVAD(channel_num));
1949 }
1950}
1951
1952// Test we can SetSend on all send streams correctly.
1953TEST_F(WebRtcVoiceEngineTestFake, SetSendWithMultipleSendStreams) {
1954 SetupForMultiSendStream();
1955
1956 static const uint32 kSsrcs4[] = {1, 2, 3, 4};
1957 // Create the send channels and they should be a SEND_NOTHING date.
1958 for (unsigned int i = 0; i < ARRAY_SIZE(kSsrcs4); ++i) {
1959 EXPECT_TRUE(channel_->AddSendStream(
1960 cricket::StreamParams::CreateLegacy(kSsrcs4[i])));
1961 int channel_num = voe_.GetLastChannel();
1962 EXPECT_FALSE(voe_.GetSend(channel_num));
1963 }
1964
1965 // Set the global state for starting sending.
1966 EXPECT_TRUE(channel_->SetSend(cricket::SEND_MICROPHONE));
1967 for (unsigned int i = 0; i < ARRAY_SIZE(kSsrcs4); ++i) {
1968 // Verify that we are in a sending state for all the send streams.
1969 int channel_num = voe_.GetChannelFromLocalSsrc(kSsrcs4[i]);
1970 EXPECT_TRUE(voe_.GetSend(channel_num));
1971 }
1972
1973 // Set the global state for stopping sending.
1974 EXPECT_TRUE(channel_->SetSend(cricket::SEND_NOTHING));
1975 for (unsigned int i = 1; i < ARRAY_SIZE(kSsrcs4); ++i) {
1976 // Verify that we are in a stop state for all the send streams.
1977 int channel_num = voe_.GetChannelFromLocalSsrc(kSsrcs4[i]);
1978 EXPECT_FALSE(voe_.GetSend(channel_num));
1979 }
1980}
1981
1982// Test we can set the correct statistics on all send streams.
1983TEST_F(WebRtcVoiceEngineTestFake, GetStatsWithMultipleSendStreams) {
1984 SetupForMultiSendStream();
1985
1986 static const uint32 kSsrcs4[] = {1, 2, 3, 4};
1987 // Create send streams.
1988 for (unsigned int i = 0; i < ARRAY_SIZE(kSsrcs4); ++i) {
1989 EXPECT_TRUE(channel_->AddSendStream(
1990 cricket::StreamParams::CreateLegacy(kSsrcs4[i])));
1991 }
buildbot@webrtc.org7e71b772014-06-13 01:14:01 +00001992 // Create a receive stream to check that none of the send streams end up in
1993 // the receive stream stats.
1994 EXPECT_TRUE(channel_->AddRecvStream(
1995 cricket::StreamParams::CreateLegacy(kSsrc2)));
wu@webrtc.org9dba5252013-08-05 20:36:57 +00001996 // We need send codec to be set to get all stats.
1997 std::vector<cricket::AudioCodec> codecs;
1998 codecs.push_back(kPcmuCodec);
1999 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
buildbot@webrtc.org7e71b772014-06-13 01:14:01 +00002000 EXPECT_TRUE(channel_->SetRecvCodecs(codecs));
wu@webrtc.org9dba5252013-08-05 20:36:57 +00002001
2002 cricket::VoiceMediaInfo info;
2003 EXPECT_EQ(true, channel_->GetStats(&info));
2004 EXPECT_EQ(static_cast<size_t>(ARRAY_SIZE(kSsrcs4)), info.senders.size());
2005
2006 // Verify the statistic information is correct.
2007 for (unsigned int i = 0; i < ARRAY_SIZE(kSsrcs4); ++i) {
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +00002008 EXPECT_EQ(kSsrcs4[i], info.senders[i].ssrc());
wu@webrtc.org9dba5252013-08-05 20:36:57 +00002009 EXPECT_EQ(kPcmuCodec.name, info.senders[i].codec_name);
2010 EXPECT_EQ(cricket::kIntStatValue, info.senders[i].bytes_sent);
2011 EXPECT_EQ(cricket::kIntStatValue, info.senders[i].packets_sent);
2012 EXPECT_EQ(cricket::kIntStatValue, info.senders[i].packets_lost);
2013 EXPECT_EQ(cricket::kFractionLostStatValue, info.senders[i].fraction_lost);
2014 EXPECT_EQ(cricket::kIntStatValue, info.senders[i].ext_seqnum);
2015 EXPECT_EQ(cricket::kIntStatValue, info.senders[i].rtt_ms);
2016 EXPECT_EQ(cricket::kIntStatValue, info.senders[i].jitter_ms);
buildbot@webrtc.org7e71b772014-06-13 01:14:01 +00002017 EXPECT_EQ(kPcmuCodec.name, info.senders[i].codec_name);
wu@webrtc.org9dba5252013-08-05 20:36:57 +00002018 }
2019
buildbot@webrtc.org7e71b772014-06-13 01:14:01 +00002020 EXPECT_EQ(0u, info.receivers.size());
2021 DeliverPacket(kPcmuFrame, sizeof(kPcmuFrame));
2022 EXPECT_EQ(true, channel_->GetStats(&info));
2023
wu@webrtc.org9dba5252013-08-05 20:36:57 +00002024 EXPECT_EQ(1u, info.receivers.size());
buildbot@webrtc.org7e71b772014-06-13 01:14:01 +00002025 EXPECT_EQ(cricket::kIntStatValue, info.receivers[0].bytes_rcvd);
2026 EXPECT_EQ(cricket::kIntStatValue, info.receivers[0].packets_rcvd);
2027 EXPECT_EQ(cricket::kIntStatValue, info.receivers[0].packets_lost);
2028 EXPECT_EQ(cricket::kIntStatValue, info.receivers[0].ext_seqnum);
2029 EXPECT_EQ(kPcmuCodec.name, info.receivers[0].codec_name);
minyue@webrtc.orgc0bd7be2015-02-18 15:24:13 +00002030 EXPECT_EQ(static_cast<float>(cricket::kNetStats.currentExpandRate) /
2031 (1 << 14), info.receivers[0].expand_rate);
2032 EXPECT_EQ(static_cast<float>(cricket::kNetStats.currentSpeechExpandRate) /
2033 (1 << 14), info.receivers[0].speech_expand_rate);
2034 EXPECT_EQ(static_cast<float>(cricket::kNetStats.currentSecondaryDecodedRate) /
2035 (1 << 14), info.receivers[0].secondary_decoded_rate);
wu@webrtc.org9dba5252013-08-05 20:36:57 +00002036}
2037
wu@webrtc.org9dba5252013-08-05 20:36:57 +00002038// Test that we can add and remove receive streams, and do proper send/playout.
2039// We can receive on multiple streams while sending one stream.
2040TEST_F(WebRtcVoiceEngineTestFake, PlayoutWithMultipleStreams) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002041 EXPECT_TRUE(SetupEngine());
2042 int channel_num1 = voe_.GetLastChannel();
2043
2044 // Start playout on the default channel.
2045 EXPECT_TRUE(channel_->SetOptions(options_conference_));
2046 EXPECT_TRUE(channel_->SetPlayout(true));
2047 EXPECT_TRUE(voe_.GetPlayout(channel_num1));
2048
2049 // Adding another stream should disable playout on the default channel.
2050 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(2)));
2051 int channel_num2 = voe_.GetLastChannel();
2052 std::vector<cricket::AudioCodec> codecs;
2053 codecs.push_back(kPcmuCodec);
2054 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
2055 EXPECT_TRUE(channel_->SetSend(cricket::SEND_MICROPHONE));
2056 EXPECT_TRUE(voe_.GetSend(channel_num1));
2057 EXPECT_FALSE(voe_.GetSend(channel_num2));
2058
2059 // Make sure only the new channel is played out.
2060 EXPECT_FALSE(voe_.GetPlayout(channel_num1));
2061 EXPECT_TRUE(voe_.GetPlayout(channel_num2));
2062
2063 // Adding yet another stream should have stream 2 and 3 enabled for playout.
2064 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(3)));
2065 int channel_num3 = voe_.GetLastChannel();
2066 EXPECT_FALSE(voe_.GetPlayout(channel_num1));
2067 EXPECT_TRUE(voe_.GetPlayout(channel_num2));
2068 EXPECT_TRUE(voe_.GetPlayout(channel_num3));
2069 EXPECT_FALSE(voe_.GetSend(channel_num3));
2070
2071 // Stop sending.
2072 EXPECT_TRUE(channel_->SetSend(cricket::SEND_NOTHING));
2073 EXPECT_FALSE(voe_.GetSend(channel_num1));
2074 EXPECT_FALSE(voe_.GetSend(channel_num2));
2075 EXPECT_FALSE(voe_.GetSend(channel_num3));
2076
2077 // Stop playout.
2078 EXPECT_TRUE(channel_->SetPlayout(false));
2079 EXPECT_FALSE(voe_.GetPlayout(channel_num1));
2080 EXPECT_FALSE(voe_.GetPlayout(channel_num2));
2081 EXPECT_FALSE(voe_.GetPlayout(channel_num3));
2082
2083 // Restart playout and make sure the default channel still is not played out.
2084 EXPECT_TRUE(channel_->SetPlayout(true));
2085 EXPECT_FALSE(voe_.GetPlayout(channel_num1));
2086 EXPECT_TRUE(voe_.GetPlayout(channel_num2));
2087 EXPECT_TRUE(voe_.GetPlayout(channel_num3));
2088
2089 // Now remove the new streams and verify that the default channel is
2090 // played out again.
2091 EXPECT_TRUE(channel_->RemoveRecvStream(3));
2092 EXPECT_TRUE(channel_->RemoveRecvStream(2));
2093
2094 EXPECT_TRUE(voe_.GetPlayout(channel_num1));
2095}
2096
2097// Test that we can set the devices to use.
2098TEST_F(WebRtcVoiceEngineTestFake, SetDevices) {
2099 EXPECT_TRUE(SetupEngine());
2100 int channel_num = voe_.GetLastChannel();
2101 std::vector<cricket::AudioCodec> codecs;
2102 codecs.push_back(kPcmuCodec);
2103 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
2104
2105 cricket::Device default_dev(cricket::kFakeDefaultDeviceName,
2106 cricket::kFakeDefaultDeviceId);
2107 cricket::Device dev(cricket::kFakeDeviceName,
2108 cricket::kFakeDeviceId);
2109
2110 // Test SetDevices() while not sending or playing.
2111 EXPECT_TRUE(engine_.SetDevices(&default_dev, &default_dev));
2112
2113 // Test SetDevices() while sending and playing.
2114 EXPECT_TRUE(engine_.SetLocalMonitor(true));
2115 EXPECT_TRUE(channel_->SetSend(cricket::SEND_MICROPHONE));
2116 EXPECT_TRUE(channel_->SetPlayout(true));
2117 EXPECT_TRUE(voe_.GetRecordingMicrophone());
2118 EXPECT_TRUE(voe_.GetSend(channel_num));
2119 EXPECT_TRUE(voe_.GetPlayout(channel_num));
2120
2121 EXPECT_TRUE(engine_.SetDevices(&dev, &dev));
2122
2123 EXPECT_TRUE(voe_.GetRecordingMicrophone());
2124 EXPECT_TRUE(voe_.GetSend(channel_num));
2125 EXPECT_TRUE(voe_.GetPlayout(channel_num));
2126
2127 // Test that failure to open newly selected devices does not prevent opening
2128 // ones after that.
2129 voe_.set_fail_start_recording_microphone(true);
2130 voe_.set_playout_fail_channel(channel_num);
2131 voe_.set_send_fail_channel(channel_num);
2132
2133 EXPECT_FALSE(engine_.SetDevices(&default_dev, &default_dev));
2134
2135 EXPECT_FALSE(voe_.GetRecordingMicrophone());
2136 EXPECT_FALSE(voe_.GetSend(channel_num));
2137 EXPECT_FALSE(voe_.GetPlayout(channel_num));
2138
2139 voe_.set_fail_start_recording_microphone(false);
2140 voe_.set_playout_fail_channel(-1);
2141 voe_.set_send_fail_channel(-1);
2142
2143 EXPECT_TRUE(engine_.SetDevices(&dev, &dev));
2144
2145 EXPECT_TRUE(voe_.GetRecordingMicrophone());
2146 EXPECT_TRUE(voe_.GetSend(channel_num));
2147 EXPECT_TRUE(voe_.GetPlayout(channel_num));
2148}
2149
2150// Test that we can set the devices to use even if we failed to
2151// open the initial ones.
2152TEST_F(WebRtcVoiceEngineTestFake, SetDevicesWithInitiallyBadDevices) {
2153 EXPECT_TRUE(SetupEngine());
2154 int channel_num = voe_.GetLastChannel();
2155 std::vector<cricket::AudioCodec> codecs;
2156 codecs.push_back(kPcmuCodec);
2157 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
2158
2159 cricket::Device default_dev(cricket::kFakeDefaultDeviceName,
2160 cricket::kFakeDefaultDeviceId);
2161 cricket::Device dev(cricket::kFakeDeviceName,
2162 cricket::kFakeDeviceId);
2163
2164 // Test that failure to open devices selected before starting
2165 // send/play does not prevent opening newly selected ones after that.
2166 voe_.set_fail_start_recording_microphone(true);
2167 voe_.set_playout_fail_channel(channel_num);
2168 voe_.set_send_fail_channel(channel_num);
2169
2170 EXPECT_TRUE(engine_.SetDevices(&default_dev, &default_dev));
2171
2172 EXPECT_FALSE(engine_.SetLocalMonitor(true));
2173 EXPECT_FALSE(channel_->SetSend(cricket::SEND_MICROPHONE));
2174 EXPECT_FALSE(channel_->SetPlayout(true));
2175 EXPECT_FALSE(voe_.GetRecordingMicrophone());
2176 EXPECT_FALSE(voe_.GetSend(channel_num));
2177 EXPECT_FALSE(voe_.GetPlayout(channel_num));
2178
2179 voe_.set_fail_start_recording_microphone(false);
2180 voe_.set_playout_fail_channel(-1);
2181 voe_.set_send_fail_channel(-1);
2182
2183 EXPECT_TRUE(engine_.SetDevices(&dev, &dev));
2184
2185 EXPECT_TRUE(voe_.GetRecordingMicrophone());
2186 EXPECT_TRUE(voe_.GetSend(channel_num));
2187 EXPECT_TRUE(voe_.GetPlayout(channel_num));
2188}
2189
2190// Test that we can create a channel configured for multi-point conferences,
2191// and start sending/playing out on it.
2192TEST_F(WebRtcVoiceEngineTestFake, ConferenceSendAndPlayout) {
2193 EXPECT_TRUE(SetupEngine());
2194 int channel_num = voe_.GetLastChannel();
2195 EXPECT_TRUE(channel_->SetOptions(options_conference_));
2196 std::vector<cricket::AudioCodec> codecs;
2197 codecs.push_back(kPcmuCodec);
2198 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
2199 EXPECT_TRUE(channel_->SetSend(cricket::SEND_MICROPHONE));
2200 EXPECT_TRUE(voe_.GetSend(channel_num));
2201}
2202
2203// Test that we can create a channel configured for Codian bridges,
2204// and start sending/playing out on it.
2205TEST_F(WebRtcVoiceEngineTestFake, CodianSendAndPlayout) {
2206 EXPECT_TRUE(SetupEngine());
2207 int channel_num = voe_.GetLastChannel();
2208 webrtc::AgcConfig agc_config;
2209 EXPECT_EQ(0, voe_.GetAgcConfig(agc_config));
2210 EXPECT_EQ(0, agc_config.targetLeveldBOv);
2211 EXPECT_TRUE(channel_->SetOptions(options_adjust_agc_));
2212 std::vector<cricket::AudioCodec> codecs;
2213 codecs.push_back(kPcmuCodec);
2214 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
2215 EXPECT_TRUE(channel_->SetSend(cricket::SEND_MICROPHONE));
2216 EXPECT_TRUE(voe_.GetSend(channel_num));
2217 EXPECT_EQ(0, voe_.GetAgcConfig(agc_config));
2218 EXPECT_EQ(agc_config.targetLeveldBOv, 10); // level was attenuated
2219 EXPECT_TRUE(channel_->SetPlayout(true));
2220 EXPECT_TRUE(voe_.GetPlayout(channel_num));
2221 EXPECT_TRUE(channel_->SetSend(cricket::SEND_NOTHING));
2222 EXPECT_FALSE(voe_.GetSend(channel_num));
2223 EXPECT_EQ(0, voe_.GetAgcConfig(agc_config));
2224 EXPECT_EQ(0, agc_config.targetLeveldBOv); // level was restored
2225 EXPECT_TRUE(channel_->SetPlayout(false));
2226 EXPECT_FALSE(voe_.GetPlayout(channel_num));
2227}
2228
wu@webrtc.org97077a32013-10-25 21:18:33 +00002229TEST_F(WebRtcVoiceEngineTestFake, TxAgcConfigViaOptions) {
2230 EXPECT_TRUE(SetupEngine());
2231 webrtc::AgcConfig agc_config;
2232 EXPECT_EQ(0, voe_.GetAgcConfig(agc_config));
2233 EXPECT_EQ(0, agc_config.targetLeveldBOv);
2234
2235 cricket::AudioOptions options;
2236 options.tx_agc_target_dbov.Set(3);
2237 options.tx_agc_digital_compression_gain.Set(9);
2238 options.tx_agc_limiter.Set(true);
2239 options.auto_gain_control.Set(true);
2240 EXPECT_TRUE(engine_.SetOptions(options));
2241
2242 EXPECT_EQ(0, voe_.GetAgcConfig(agc_config));
2243 EXPECT_EQ(3, agc_config.targetLeveldBOv);
2244 EXPECT_EQ(9, agc_config.digitalCompressionGaindB);
2245 EXPECT_TRUE(agc_config.limiterEnable);
2246
2247 // Check interaction with adjust_agc_delta. Both should be respected, for
2248 // backwards compatibility.
2249 options.adjust_agc_delta.Set(-10);
2250 EXPECT_TRUE(engine_.SetOptions(options));
2251
2252 EXPECT_EQ(0, voe_.GetAgcConfig(agc_config));
2253 EXPECT_EQ(13, agc_config.targetLeveldBOv);
2254}
2255
2256TEST_F(WebRtcVoiceEngineTestFake, RxAgcConfigViaOptions) {
2257 EXPECT_TRUE(SetupEngine());
2258 int channel_num = voe_.GetLastChannel();
2259 cricket::AudioOptions options;
2260 options.rx_agc_target_dbov.Set(6);
2261 options.rx_agc_digital_compression_gain.Set(0);
2262 options.rx_agc_limiter.Set(true);
2263 options.rx_auto_gain_control.Set(true);
2264 EXPECT_TRUE(channel_->SetOptions(options));
2265
2266 webrtc::AgcConfig agc_config;
2267 EXPECT_EQ(0, engine_.voe()->processing()->GetRxAgcConfig(
2268 channel_num, agc_config));
2269 EXPECT_EQ(6, agc_config.targetLeveldBOv);
2270 EXPECT_EQ(0, agc_config.digitalCompressionGaindB);
2271 EXPECT_TRUE(agc_config.limiterEnable);
2272}
2273
2274TEST_F(WebRtcVoiceEngineTestFake, SampleRatesViaOptions) {
2275 EXPECT_TRUE(SetupEngine());
2276 cricket::AudioOptions options;
2277 options.recording_sample_rate.Set(48000u);
2278 options.playout_sample_rate.Set(44100u);
2279 EXPECT_TRUE(engine_.SetOptions(options));
2280
2281 unsigned int recording_sample_rate, playout_sample_rate;
2282 EXPECT_EQ(0, voe_.RecordingSampleRate(&recording_sample_rate));
2283 EXPECT_EQ(0, voe_.PlayoutSampleRate(&playout_sample_rate));
2284 EXPECT_EQ(48000u, recording_sample_rate);
2285 EXPECT_EQ(44100u, playout_sample_rate);
2286}
2287
2288TEST_F(WebRtcVoiceEngineTestFake, TraceFilterViaTraceOptions) {
2289 EXPECT_TRUE(SetupEngine());
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002290 engine_.SetLogging(rtc::LS_INFO, "");
wu@webrtc.org97077a32013-10-25 21:18:33 +00002291 EXPECT_EQ(
2292 // Info:
2293 webrtc::kTraceStateInfo | webrtc::kTraceInfo |
2294 // Warning:
2295 webrtc::kTraceTerseInfo | webrtc::kTraceWarning |
2296 // Error:
2297 webrtc::kTraceError | webrtc::kTraceCritical,
2298 static_cast<int>(trace_wrapper_->filter_));
2299 // Now set it explicitly
2300 std::string filter =
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002301 "tracefilter " + rtc::ToString(webrtc::kTraceDefault);
2302 engine_.SetLogging(rtc::LS_VERBOSE, filter.c_str());
wu@webrtc.org97077a32013-10-25 21:18:33 +00002303 EXPECT_EQ(static_cast<unsigned int>(webrtc::kTraceDefault),
2304 trace_wrapper_->filter_);
2305}
2306
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002307// Test that we can set the outgoing SSRC properly.
2308// SSRC is set in SetupEngine by calling AddSendStream.
2309TEST_F(WebRtcVoiceEngineTestFake, SetSendSsrc) {
2310 EXPECT_TRUE(SetupEngine());
2311 int channel_num = voe_.GetLastChannel();
2312 unsigned int send_ssrc;
2313 EXPECT_EQ(0, voe_.GetLocalSSRC(channel_num, send_ssrc));
2314 EXPECT_NE(0U, send_ssrc);
2315 EXPECT_EQ(0, voe_.GetLocalSSRC(channel_num, send_ssrc));
2316 EXPECT_EQ(kSsrc1, send_ssrc);
2317}
2318
2319TEST_F(WebRtcVoiceEngineTestFake, GetStats) {
2320 // Setup. We need send codec to be set to get all stats.
2321 EXPECT_TRUE(SetupEngine());
buildbot@webrtc.org7e71b772014-06-13 01:14:01 +00002322 // SetupEngine adds a send stream with kSsrc1, so the receive stream has to
2323 // use a different SSRC.
2324 EXPECT_TRUE(channel_->AddRecvStream(
2325 cricket::StreamParams::CreateLegacy(kSsrc2)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002326 std::vector<cricket::AudioCodec> codecs;
2327 codecs.push_back(kPcmuCodec);
2328 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
buildbot@webrtc.org7e71b772014-06-13 01:14:01 +00002329 EXPECT_TRUE(channel_->SetRecvCodecs(codecs));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002330
2331 cricket::VoiceMediaInfo info;
2332 EXPECT_EQ(true, channel_->GetStats(&info));
2333 EXPECT_EQ(1u, info.senders.size());
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +00002334 EXPECT_EQ(kSsrc1, info.senders[0].ssrc());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002335 EXPECT_EQ(kPcmuCodec.name, info.senders[0].codec_name);
2336 EXPECT_EQ(cricket::kIntStatValue, info.senders[0].bytes_sent);
2337 EXPECT_EQ(cricket::kIntStatValue, info.senders[0].packets_sent);
2338 EXPECT_EQ(cricket::kIntStatValue, info.senders[0].packets_lost);
2339 EXPECT_EQ(cricket::kFractionLostStatValue, info.senders[0].fraction_lost);
2340 EXPECT_EQ(cricket::kIntStatValue, info.senders[0].ext_seqnum);
2341 EXPECT_EQ(cricket::kIntStatValue, info.senders[0].rtt_ms);
2342 EXPECT_EQ(cricket::kIntStatValue, info.senders[0].jitter_ms);
buildbot@webrtc.org7e71b772014-06-13 01:14:01 +00002343 EXPECT_EQ(kPcmuCodec.name, info.senders[0].codec_name);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002344 // TODO(sriniv): Add testing for more fields. These are not populated
2345 // in FakeWebrtcVoiceEngine yet.
2346 // EXPECT_EQ(cricket::kIntStatValue, info.senders[0].audio_level);
2347 // EXPECT_EQ(cricket::kIntStatValue, info.senders[0].echo_delay_median_ms);
2348 // EXPECT_EQ(cricket::kIntStatValue, info.senders[0].echo_delay_std_ms);
2349 // EXPECT_EQ(cricket::kIntStatValue, info.senders[0].echo_return_loss);
2350 // EXPECT_EQ(cricket::kIntStatValue,
2351 // info.senders[0].echo_return_loss_enhancement);
2352
buildbot@webrtc.org7e71b772014-06-13 01:14:01 +00002353 EXPECT_EQ(0u, info.receivers.size());
2354 DeliverPacket(kPcmuFrame, sizeof(kPcmuFrame));
2355 EXPECT_EQ(true, channel_->GetStats(&info));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002356 EXPECT_EQ(1u, info.receivers.size());
buildbot@webrtc.org7e71b772014-06-13 01:14:01 +00002357
2358 EXPECT_EQ(cricket::kIntStatValue, info.receivers[0].bytes_rcvd);
2359 EXPECT_EQ(cricket::kIntStatValue, info.receivers[0].packets_rcvd);
2360 EXPECT_EQ(cricket::kIntStatValue, info.receivers[0].packets_lost);
2361 EXPECT_EQ(cricket::kIntStatValue, info.receivers[0].ext_seqnum);
2362 EXPECT_EQ(kPcmuCodec.name, info.receivers[0].codec_name);
minyue@webrtc.orgc0bd7be2015-02-18 15:24:13 +00002363 EXPECT_EQ(static_cast<float>(cricket::kNetStats.currentExpandRate) /
2364 (1 << 14), info.receivers[0].expand_rate);
2365 EXPECT_EQ(static_cast<float>(cricket::kNetStats.currentSpeechExpandRate) /
2366 (1 << 14), info.receivers[0].speech_expand_rate);
2367 EXPECT_EQ(static_cast<float>(cricket::kNetStats.currentSecondaryDecodedRate) /
2368 (1 << 14), info.receivers[0].secondary_decoded_rate);
buildbot@webrtc.org7e71b772014-06-13 01:14:01 +00002369 // TODO(sriniv): Add testing for more receiver fields.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002370}
2371
2372// Test that we can set the outgoing SSRC properly with multiple streams.
2373// SSRC is set in SetupEngine by calling AddSendStream.
2374TEST_F(WebRtcVoiceEngineTestFake, SetSendSsrcWithMultipleStreams) {
2375 EXPECT_TRUE(SetupEngine());
2376 EXPECT_TRUE(channel_->SetOptions(options_conference_));
2377 int channel_num1 = voe_.GetLastChannel();
2378 unsigned int send_ssrc;
2379 EXPECT_EQ(0, voe_.GetLocalSSRC(channel_num1, send_ssrc));
2380 EXPECT_EQ(kSsrc1, send_ssrc);
2381
2382 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(2)));
2383 int channel_num2 = voe_.GetLastChannel();
2384 EXPECT_EQ(0, voe_.GetLocalSSRC(channel_num2, send_ssrc));
2385 EXPECT_EQ(kSsrc1, send_ssrc);
2386}
2387
2388// Test that the local SSRC is the same on sending and receiving channels if the
2389// receive channel is created before the send channel.
2390TEST_F(WebRtcVoiceEngineTestFake, SetSendSsrcAfterCreatingReceiveChannel) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002391 EXPECT_TRUE(engine_.Init(rtc::Thread::Current()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002392 channel_ = engine_.CreateChannel();
2393 EXPECT_TRUE(channel_->SetOptions(options_conference_));
2394
2395 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(1)));
2396 int receive_channel_num = voe_.GetLastChannel();
2397 EXPECT_TRUE(channel_->AddSendStream(
2398 cricket::StreamParams::CreateLegacy(1234)));
2399 int send_channel_num = voe_.GetLastChannel();
2400
2401 unsigned int ssrc = 0;
2402 EXPECT_EQ(0, voe_.GetLocalSSRC(send_channel_num, ssrc));
2403 EXPECT_EQ(1234U, ssrc);
2404 ssrc = 0;
2405 EXPECT_EQ(0, voe_.GetLocalSSRC(receive_channel_num, ssrc));
2406 EXPECT_EQ(1234U, ssrc);
2407}
2408
2409// Test that we can properly receive packets.
2410TEST_F(WebRtcVoiceEngineTestFake, Recv) {
2411 EXPECT_TRUE(SetupEngine());
2412 int channel_num = voe_.GetLastChannel();
2413 DeliverPacket(kPcmuFrame, sizeof(kPcmuFrame));
2414 EXPECT_TRUE(voe_.CheckPacket(channel_num, kPcmuFrame,
2415 sizeof(kPcmuFrame)));
2416}
2417
2418// Test that we can properly receive packets on multiple streams.
2419TEST_F(WebRtcVoiceEngineTestFake, RecvWithMultipleStreams) {
2420 EXPECT_TRUE(SetupEngine());
2421 EXPECT_TRUE(channel_->SetOptions(options_conference_));
2422 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(1)));
2423 int channel_num1 = voe_.GetLastChannel();
2424 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(2)));
2425 int channel_num2 = voe_.GetLastChannel();
2426 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(3)));
2427 int channel_num3 = voe_.GetLastChannel();
2428 // Create packets with the right SSRCs.
2429 char packets[4][sizeof(kPcmuFrame)];
2430 for (size_t i = 0; i < ARRAY_SIZE(packets); ++i) {
2431 memcpy(packets[i], kPcmuFrame, sizeof(kPcmuFrame));
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002432 rtc::SetBE32(packets[i] + 8, static_cast<uint32>(i));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002433 }
2434 EXPECT_TRUE(voe_.CheckNoPacket(channel_num1));
2435 EXPECT_TRUE(voe_.CheckNoPacket(channel_num2));
2436 EXPECT_TRUE(voe_.CheckNoPacket(channel_num3));
2437 DeliverPacket(packets[0], sizeof(packets[0]));
2438 EXPECT_TRUE(voe_.CheckNoPacket(channel_num1));
2439 EXPECT_TRUE(voe_.CheckNoPacket(channel_num2));
2440 EXPECT_TRUE(voe_.CheckNoPacket(channel_num3));
2441 DeliverPacket(packets[1], sizeof(packets[1]));
2442 EXPECT_TRUE(voe_.CheckPacket(channel_num1, packets[1],
2443 sizeof(packets[1])));
2444 EXPECT_TRUE(voe_.CheckNoPacket(channel_num2));
2445 EXPECT_TRUE(voe_.CheckNoPacket(channel_num3));
2446 DeliverPacket(packets[2], sizeof(packets[2]));
2447 EXPECT_TRUE(voe_.CheckNoPacket(channel_num1));
2448 EXPECT_TRUE(voe_.CheckPacket(channel_num2, packets[2],
2449 sizeof(packets[2])));
2450 EXPECT_TRUE(voe_.CheckNoPacket(channel_num3));
2451 DeliverPacket(packets[3], sizeof(packets[3]));
2452 EXPECT_TRUE(voe_.CheckNoPacket(channel_num1));
2453 EXPECT_TRUE(voe_.CheckNoPacket(channel_num2));
2454 EXPECT_TRUE(voe_.CheckPacket(channel_num3, packets[3],
2455 sizeof(packets[3])));
2456 EXPECT_TRUE(channel_->RemoveRecvStream(3));
2457 EXPECT_TRUE(channel_->RemoveRecvStream(2));
2458 EXPECT_TRUE(channel_->RemoveRecvStream(1));
2459}
2460
2461// Test that we properly handle failures to add a stream.
2462TEST_F(WebRtcVoiceEngineTestFake, AddStreamFail) {
2463 EXPECT_TRUE(SetupEngine());
2464 voe_.set_fail_create_channel(true);
2465 EXPECT_TRUE(channel_->SetOptions(options_conference_));
2466 EXPECT_FALSE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(2)));
2467
2468 // In 1:1 call, we should not try to create a new channel.
2469 cricket::AudioOptions options_no_conference_;
2470 options_no_conference_.conference_mode.Set(false);
2471 EXPECT_TRUE(channel_->SetOptions(options_no_conference_));
2472 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(2)));
2473}
2474
2475// Test that AddRecvStream doesn't create new channel for 1:1 call.
2476TEST_F(WebRtcVoiceEngineTestFake, AddRecvStream1On1) {
2477 EXPECT_TRUE(SetupEngine());
2478 int channel_num = voe_.GetLastChannel();
2479 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(1)));
2480 EXPECT_EQ(channel_num, voe_.GetLastChannel());
2481}
2482
2483// Test that after adding a recv stream, we do not decode more codecs than
2484// those previously passed into SetRecvCodecs.
2485TEST_F(WebRtcVoiceEngineTestFake, AddRecvStreamUnsupportedCodec) {
2486 EXPECT_TRUE(SetupEngine());
2487 EXPECT_TRUE(channel_->SetOptions(options_conference_));
2488 std::vector<cricket::AudioCodec> codecs;
2489 codecs.push_back(kIsacCodec);
2490 codecs.push_back(kPcmuCodec);
2491 EXPECT_TRUE(channel_->SetRecvCodecs(codecs));
2492 EXPECT_TRUE(channel_->AddRecvStream(
2493 cricket::StreamParams::CreateLegacy(kSsrc1)));
2494 int channel_num2 = voe_.GetLastChannel();
2495 webrtc::CodecInst gcodec;
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +00002496 rtc::strcpyn(gcodec.plname, ARRAY_SIZE(gcodec.plname), "opus");
2497 gcodec.plfreq = 48000;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002498 gcodec.channels = 2;
2499 EXPECT_EQ(-1, voe_.GetRecPayloadType(channel_num2, gcodec));
2500}
2501
2502// Test that we properly clean up any streams that were added, even if
2503// not explicitly removed.
2504TEST_F(WebRtcVoiceEngineTestFake, StreamCleanup) {
2505 EXPECT_TRUE(SetupEngine());
2506 EXPECT_TRUE(channel_->SetOptions(options_conference_));
2507 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(1)));
2508 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(2)));
2509 EXPECT_EQ(3, voe_.GetNumChannels()); // default channel + 2 added
2510 delete channel_;
2511 channel_ = NULL;
2512 EXPECT_EQ(0, voe_.GetNumChannels());
2513}
2514
wu@webrtc.org78187522013-10-07 23:32:02 +00002515TEST_F(WebRtcVoiceEngineTestFake, TestAddRecvStreamFailWithZeroSsrc) {
2516 EXPECT_TRUE(SetupEngine());
2517 EXPECT_FALSE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(0)));
2518}
2519
2520TEST_F(WebRtcVoiceEngineTestFake, TestNoLeakingWhenAddRecvStreamFail) {
2521 EXPECT_TRUE(SetupEngine());
2522 // Stream 1 reuses default channel.
2523 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(1)));
2524 // Manually delete default channel to simulate a failure.
2525 int default_channel = voe_.GetLastChannel();
2526 EXPECT_EQ(0, voe_.DeleteChannel(default_channel));
2527 // Add recv stream 2 should fail because default channel is gone.
2528 EXPECT_FALSE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(2)));
2529 int new_channel = voe_.GetLastChannel();
2530 EXPECT_NE(default_channel, new_channel);
2531 // The last created channel should have already been deleted.
2532 EXPECT_EQ(-1, voe_.DeleteChannel(new_channel));
2533}
2534
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002535// Test the InsertDtmf on default send stream as caller.
2536TEST_F(WebRtcVoiceEngineTestFake, InsertDtmfOnDefaultSendStreamAsCaller) {
2537 TestInsertDtmf(0, true);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002538}
2539
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002540// Test the InsertDtmf on default send stream as callee
2541TEST_F(WebRtcVoiceEngineTestFake, InsertDtmfOnDefaultSendStreamAsCallee) {
2542 TestInsertDtmf(0, false);
2543}
2544
2545// Test the InsertDtmf on specified send stream as caller.
2546TEST_F(WebRtcVoiceEngineTestFake, InsertDtmfOnSendStreamAsCaller) {
2547 TestInsertDtmf(kSsrc1, true);
2548}
2549
2550// Test the InsertDtmf on specified send stream as callee.
2551TEST_F(WebRtcVoiceEngineTestFake, InsertDtmfOnSendStreamAsCallee) {
2552 TestInsertDtmf(kSsrc1, false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002553}
2554
2555// Test that we can play a ringback tone properly in a single-stream call.
2556TEST_F(WebRtcVoiceEngineTestFake, PlayRingback) {
2557 EXPECT_TRUE(SetupEngine());
2558 int channel_num = voe_.GetLastChannel();
2559 EXPECT_EQ(0, voe_.IsPlayingFileLocally(channel_num));
2560 // Check we fail if no ringback tone specified.
2561 EXPECT_FALSE(channel_->PlayRingbackTone(0, true, true));
2562 EXPECT_EQ(0, voe_.IsPlayingFileLocally(channel_num));
2563 // Check we can set and play a ringback tone.
wu@webrtc.org9caf2762013-12-11 18:25:07 +00002564 EXPECT_TRUE(channel_->SetRingbackTone(
2565 kRingbackTone, static_cast<int>(strlen(kRingbackTone))));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002566 EXPECT_TRUE(channel_->PlayRingbackTone(0, true, true));
2567 EXPECT_EQ(1, voe_.IsPlayingFileLocally(channel_num));
2568 // Check we can stop the tone manually.
2569 EXPECT_TRUE(channel_->PlayRingbackTone(0, false, false));
2570 EXPECT_EQ(0, voe_.IsPlayingFileLocally(channel_num));
2571 // Check we stop the tone if a packet arrives.
2572 EXPECT_TRUE(channel_->PlayRingbackTone(0, true, true));
2573 EXPECT_EQ(1, voe_.IsPlayingFileLocally(channel_num));
2574 DeliverPacket(kPcmuFrame, sizeof(kPcmuFrame));
2575 EXPECT_EQ(0, voe_.IsPlayingFileLocally(channel_num));
2576}
2577
2578// Test that we can play a ringback tone properly in a multi-stream call.
2579TEST_F(WebRtcVoiceEngineTestFake, PlayRingbackWithMultipleStreams) {
2580 EXPECT_TRUE(SetupEngine());
2581 EXPECT_TRUE(channel_->SetOptions(options_conference_));
2582 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(1)));
2583 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(2)));
2584 int channel_num = voe_.GetLastChannel();
2585 EXPECT_EQ(0, voe_.IsPlayingFileLocally(channel_num));
2586 // Check we fail if no ringback tone specified.
2587 EXPECT_FALSE(channel_->PlayRingbackTone(2, true, true));
2588 EXPECT_EQ(0, voe_.IsPlayingFileLocally(channel_num));
2589 // Check we can set and play a ringback tone on the correct ssrc.
wu@webrtc.org9caf2762013-12-11 18:25:07 +00002590 EXPECT_TRUE(channel_->SetRingbackTone(
2591 kRingbackTone, static_cast<int>(strlen(kRingbackTone))));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002592 EXPECT_FALSE(channel_->PlayRingbackTone(77, true, true));
2593 EXPECT_TRUE(channel_->PlayRingbackTone(2, true, true));
2594 EXPECT_EQ(1, voe_.IsPlayingFileLocally(channel_num));
2595 // Check we can stop the tone manually.
2596 EXPECT_TRUE(channel_->PlayRingbackTone(2, false, false));
2597 EXPECT_EQ(0, voe_.IsPlayingFileLocally(channel_num));
2598 // Check we stop the tone if a packet arrives, but only with the right SSRC.
2599 EXPECT_TRUE(channel_->PlayRingbackTone(2, true, true));
2600 EXPECT_EQ(1, voe_.IsPlayingFileLocally(channel_num));
2601 // Send a packet with SSRC 1; the tone should not stop.
2602 DeliverPacket(kPcmuFrame, sizeof(kPcmuFrame));
2603 EXPECT_EQ(1, voe_.IsPlayingFileLocally(channel_num));
2604 // Send a packet with SSRC 2; the tone should stop.
2605 char packet[sizeof(kPcmuFrame)];
2606 memcpy(packet, kPcmuFrame, sizeof(kPcmuFrame));
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002607 rtc::SetBE32(packet + 8, 2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002608 DeliverPacket(packet, sizeof(packet));
2609 EXPECT_EQ(0, voe_.IsPlayingFileLocally(channel_num));
2610}
2611
2612// Tests creating soundclips, and make sure they come from the right engine.
2613TEST_F(WebRtcVoiceEngineTestFake, CreateSoundclip) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002614 EXPECT_TRUE(engine_.Init(rtc::Thread::Current()));
wu@webrtc.org4551b792013-10-09 15:37:36 +00002615 EXPECT_FALSE(voe_sc_.IsInited());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002616 soundclip_ = engine_.CreateSoundclip();
wu@webrtc.org4551b792013-10-09 15:37:36 +00002617 EXPECT_TRUE(voe_sc_.IsInited());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002618 ASSERT_TRUE(soundclip_ != NULL);
2619 EXPECT_EQ(0, voe_.GetNumChannels());
2620 EXPECT_EQ(1, voe_sc_.GetNumChannels());
2621 int channel_num = voe_sc_.GetLastChannel();
2622 EXPECT_TRUE(voe_sc_.GetPlayout(channel_num));
2623 delete soundclip_;
2624 soundclip_ = NULL;
2625 EXPECT_EQ(0, voe_sc_.GetNumChannels());
wu@webrtc.org4551b792013-10-09 15:37:36 +00002626 // Make sure the soundclip engine is uninitialized on shutdown, now that
2627 // we've initialized it by creating a soundclip.
2628 engine_.Terminate();
2629 EXPECT_FALSE(voe_sc_.IsInited());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002630}
2631
2632// Tests playing out a fake sound.
2633TEST_F(WebRtcVoiceEngineTestFake, PlaySoundclip) {
2634 static const char kZeroes[16000] = {};
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002635 EXPECT_TRUE(engine_.Init(rtc::Thread::Current()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002636 soundclip_ = engine_.CreateSoundclip();
2637 ASSERT_TRUE(soundclip_ != NULL);
2638 EXPECT_TRUE(soundclip_->PlaySound(kZeroes, sizeof(kZeroes), 0));
2639}
2640
2641TEST_F(WebRtcVoiceEngineTestFake, MediaEngineCallbackOnError) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002642 rtc::scoped_ptr<ChannelErrorListener> listener;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002643 cricket::WebRtcVoiceMediaChannel* media_channel;
2644 unsigned int ssrc = 0;
2645
2646 EXPECT_TRUE(SetupEngine());
2647 EXPECT_TRUE(channel_->SetOptions(options_conference_));
2648 EXPECT_TRUE(channel_->SetSend(cricket::SEND_MICROPHONE));
2649
2650 media_channel = static_cast<cricket::WebRtcVoiceMediaChannel*>(channel_);
2651 listener.reset(new ChannelErrorListener(channel_));
2652
2653 // Test on WebRtc VoE channel.
2654 voe_.TriggerCallbackOnError(media_channel->voe_channel(),
2655 VE_SATURATION_WARNING);
2656 EXPECT_EQ(cricket::VoiceMediaChannel::ERROR_REC_DEVICE_SATURATION,
2657 listener->error());
2658 EXPECT_NE(-1, voe_.GetLocalSSRC(voe_.GetLastChannel(), ssrc));
2659 EXPECT_EQ(ssrc, listener->ssrc());
2660
2661 listener->Reset();
2662 voe_.TriggerCallbackOnError(-1, VE_TYPING_NOISE_WARNING);
2663 EXPECT_EQ(cricket::VoiceMediaChannel::ERROR_REC_TYPING_NOISE_DETECTED,
2664 listener->error());
2665 EXPECT_EQ(0U, listener->ssrc());
2666
2667 // Add another stream and test on that.
2668 ++ssrc;
2669 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(
2670 ssrc)));
2671 listener->Reset();
2672 voe_.TriggerCallbackOnError(voe_.GetLastChannel(),
2673 VE_SATURATION_WARNING);
2674 EXPECT_EQ(cricket::VoiceMediaChannel::ERROR_REC_DEVICE_SATURATION,
2675 listener->error());
2676 EXPECT_EQ(ssrc, listener->ssrc());
2677
2678 // Testing a non-existing channel.
2679 listener->Reset();
2680 voe_.TriggerCallbackOnError(voe_.GetLastChannel() + 2,
2681 VE_SATURATION_WARNING);
2682 EXPECT_EQ(0, listener->error());
2683}
2684
2685TEST_F(WebRtcVoiceEngineTestFake, TestSetPlayoutError) {
2686 EXPECT_TRUE(SetupEngine());
2687 EXPECT_TRUE(channel_->SetOptions(options_conference_));
2688 std::vector<cricket::AudioCodec> codecs;
2689 codecs.push_back(kPcmuCodec);
2690 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
2691 EXPECT_TRUE(channel_->SetSend(cricket::SEND_MICROPHONE));
2692 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(2)));
2693 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(3)));
2694 EXPECT_TRUE(channel_->SetPlayout(true));
2695 voe_.set_playout_fail_channel(voe_.GetLastChannel() - 1);
2696 EXPECT_TRUE(channel_->SetPlayout(false));
2697 EXPECT_FALSE(channel_->SetPlayout(true));
2698}
2699
2700// Test that the Registering/Unregistering with the
2701// webrtcvoiceengine works as expected
2702TEST_F(WebRtcVoiceEngineTestFake, RegisterVoiceProcessor) {
2703 EXPECT_TRUE(SetupEngine());
2704 EXPECT_TRUE(channel_->SetOptions(options_conference_));
2705 EXPECT_TRUE(channel_->AddRecvStream(
2706 cricket::StreamParams::CreateLegacy(kSsrc2)));
2707 cricket::FakeMediaProcessor vp_1;
2708 cricket::FakeMediaProcessor vp_2;
2709
2710 EXPECT_FALSE(engine_.RegisterProcessor(kSsrc2, &vp_1, cricket::MPD_TX));
2711 EXPECT_TRUE(engine_.RegisterProcessor(kSsrc2, &vp_1, cricket::MPD_RX));
2712 EXPECT_TRUE(engine_.RegisterProcessor(kSsrc2, &vp_2, cricket::MPD_RX));
2713 voe_.TriggerProcessPacket(cricket::MPD_RX);
2714 voe_.TriggerProcessPacket(cricket::MPD_TX);
2715
2716 EXPECT_TRUE(voe_.IsExternalMediaProcessorRegistered());
2717 EXPECT_EQ(1, vp_1.voice_frame_count());
2718 EXPECT_EQ(1, vp_2.voice_frame_count());
2719
2720 EXPECT_TRUE(engine_.UnregisterProcessor(kSsrc2,
2721 &vp_2,
2722 cricket::MPD_RX));
2723 voe_.TriggerProcessPacket(cricket::MPD_RX);
2724 EXPECT_TRUE(voe_.IsExternalMediaProcessorRegistered());
2725 EXPECT_EQ(1, vp_2.voice_frame_count());
2726 EXPECT_EQ(2, vp_1.voice_frame_count());
2727
2728 EXPECT_TRUE(engine_.UnregisterProcessor(kSsrc2,
2729 &vp_1,
2730 cricket::MPD_RX));
2731 voe_.TriggerProcessPacket(cricket::MPD_RX);
2732 EXPECT_FALSE(voe_.IsExternalMediaProcessorRegistered());
2733 EXPECT_EQ(2, vp_1.voice_frame_count());
2734
2735 EXPECT_FALSE(engine_.RegisterProcessor(kSsrc1, &vp_1, cricket::MPD_RX));
2736 EXPECT_TRUE(engine_.RegisterProcessor(kSsrc1, &vp_1, cricket::MPD_TX));
2737 voe_.TriggerProcessPacket(cricket::MPD_RX);
2738 voe_.TriggerProcessPacket(cricket::MPD_TX);
2739 EXPECT_TRUE(voe_.IsExternalMediaProcessorRegistered());
2740 EXPECT_EQ(3, vp_1.voice_frame_count());
2741
2742 EXPECT_TRUE(engine_.UnregisterProcessor(kSsrc1,
2743 &vp_1,
2744 cricket::MPD_RX_AND_TX));
2745 voe_.TriggerProcessPacket(cricket::MPD_TX);
2746 EXPECT_FALSE(voe_.IsExternalMediaProcessorRegistered());
2747 EXPECT_EQ(3, vp_1.voice_frame_count());
2748 EXPECT_TRUE(channel_->RemoveRecvStream(kSsrc2));
2749 EXPECT_FALSE(engine_.RegisterProcessor(kSsrc2, &vp_1, cricket::MPD_RX));
2750 EXPECT_FALSE(voe_.IsExternalMediaProcessorRegistered());
2751
2752 // Test that we can register a processor on the receive channel on SSRC 0.
2753 // This tests the 1:1 case when the receive SSRC is unknown.
2754 EXPECT_TRUE(engine_.RegisterProcessor(0, &vp_1, cricket::MPD_RX));
2755 voe_.TriggerProcessPacket(cricket::MPD_RX);
2756 EXPECT_TRUE(voe_.IsExternalMediaProcessorRegistered());
2757 EXPECT_EQ(4, vp_1.voice_frame_count());
2758 EXPECT_TRUE(engine_.UnregisterProcessor(0,
2759 &vp_1,
2760 cricket::MPD_RX));
2761
2762 // The following tests test that FindChannelNumFromSsrc is doing
2763 // what we expect.
2764 // pick an invalid ssrc and make sure we can't register
2765 EXPECT_FALSE(engine_.RegisterProcessor(99,
2766 &vp_1,
2767 cricket::MPD_RX));
2768 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(1)));
2769 EXPECT_TRUE(engine_.RegisterProcessor(1,
2770 &vp_1,
2771 cricket::MPD_RX));
2772 EXPECT_TRUE(engine_.UnregisterProcessor(1,
2773 &vp_1,
2774 cricket::MPD_RX));
2775 EXPECT_FALSE(engine_.RegisterProcessor(1,
2776 &vp_1,
2777 cricket::MPD_TX));
2778 EXPECT_TRUE(channel_->RemoveRecvStream(1));
2779}
2780
2781TEST_F(WebRtcVoiceEngineTestFake, SetAudioOptions) {
2782 EXPECT_TRUE(SetupEngine());
2783
2784 bool ec_enabled;
2785 webrtc::EcModes ec_mode;
2786 bool ec_metrics_enabled;
2787 webrtc::AecmModes aecm_mode;
2788 bool cng_enabled;
2789 bool agc_enabled;
2790 webrtc::AgcModes agc_mode;
2791 webrtc::AgcConfig agc_config;
2792 bool ns_enabled;
2793 webrtc::NsModes ns_mode;
2794 bool highpass_filter_enabled;
2795 bool stereo_swapping_enabled;
2796 bool typing_detection_enabled;
2797 voe_.GetEcStatus(ec_enabled, ec_mode);
2798 voe_.GetEcMetricsStatus(ec_metrics_enabled);
2799 voe_.GetAecmMode(aecm_mode, cng_enabled);
2800 voe_.GetAgcStatus(agc_enabled, agc_mode);
2801 voe_.GetAgcConfig(agc_config);
2802 voe_.GetNsStatus(ns_enabled, ns_mode);
2803 highpass_filter_enabled = voe_.IsHighPassFilterEnabled();
2804 stereo_swapping_enabled = voe_.IsStereoChannelSwappingEnabled();
2805 voe_.GetTypingDetectionStatus(typing_detection_enabled);
2806 EXPECT_TRUE(ec_enabled);
2807 EXPECT_TRUE(ec_metrics_enabled);
2808 EXPECT_FALSE(cng_enabled);
2809 EXPECT_TRUE(agc_enabled);
2810 EXPECT_EQ(0, agc_config.targetLeveldBOv);
2811 EXPECT_TRUE(ns_enabled);
2812 EXPECT_TRUE(highpass_filter_enabled);
2813 EXPECT_FALSE(stereo_swapping_enabled);
2814 EXPECT_TRUE(typing_detection_enabled);
2815 EXPECT_EQ(ec_mode, webrtc::kEcConference);
2816 EXPECT_EQ(ns_mode, webrtc::kNsHighSuppression);
2817
2818 // Nothing set, so all ignored.
2819 cricket::AudioOptions options;
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00002820 ASSERT_TRUE(engine_.SetOptions(options));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002821 voe_.GetEcStatus(ec_enabled, ec_mode);
2822 voe_.GetEcMetricsStatus(ec_metrics_enabled);
2823 voe_.GetAecmMode(aecm_mode, cng_enabled);
2824 voe_.GetAgcStatus(agc_enabled, agc_mode);
2825 voe_.GetAgcConfig(agc_config);
2826 voe_.GetNsStatus(ns_enabled, ns_mode);
2827 highpass_filter_enabled = voe_.IsHighPassFilterEnabled();
2828 stereo_swapping_enabled = voe_.IsStereoChannelSwappingEnabled();
2829 voe_.GetTypingDetectionStatus(typing_detection_enabled);
2830 EXPECT_TRUE(ec_enabled);
2831 EXPECT_TRUE(ec_metrics_enabled);
2832 EXPECT_FALSE(cng_enabled);
2833 EXPECT_TRUE(agc_enabled);
2834 EXPECT_EQ(0, agc_config.targetLeveldBOv);
2835 EXPECT_TRUE(ns_enabled);
2836 EXPECT_TRUE(highpass_filter_enabled);
2837 EXPECT_FALSE(stereo_swapping_enabled);
2838 EXPECT_TRUE(typing_detection_enabled);
2839 EXPECT_EQ(ec_mode, webrtc::kEcConference);
2840 EXPECT_EQ(ns_mode, webrtc::kNsHighSuppression);
2841
2842 // Turn echo cancellation off
2843 options.echo_cancellation.Set(false);
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00002844 ASSERT_TRUE(engine_.SetOptions(options));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002845 voe_.GetEcStatus(ec_enabled, ec_mode);
2846 EXPECT_FALSE(ec_enabled);
2847
2848 // Turn echo cancellation back on, with settings, and make sure
2849 // nothing else changed.
2850 options.echo_cancellation.Set(true);
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00002851 ASSERT_TRUE(engine_.SetOptions(options));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002852 voe_.GetEcStatus(ec_enabled, ec_mode);
2853 voe_.GetEcMetricsStatus(ec_metrics_enabled);
2854 voe_.GetAecmMode(aecm_mode, cng_enabled);
2855 voe_.GetAgcStatus(agc_enabled, agc_mode);
2856 voe_.GetAgcConfig(agc_config);
2857 voe_.GetNsStatus(ns_enabled, ns_mode);
2858 highpass_filter_enabled = voe_.IsHighPassFilterEnabled();
2859 stereo_swapping_enabled = voe_.IsStereoChannelSwappingEnabled();
2860 voe_.GetTypingDetectionStatus(typing_detection_enabled);
2861 EXPECT_TRUE(ec_enabled);
2862 EXPECT_TRUE(ec_metrics_enabled);
2863 EXPECT_TRUE(agc_enabled);
2864 EXPECT_EQ(0, agc_config.targetLeveldBOv);
2865 EXPECT_TRUE(ns_enabled);
2866 EXPECT_TRUE(highpass_filter_enabled);
2867 EXPECT_FALSE(stereo_swapping_enabled);
2868 EXPECT_TRUE(typing_detection_enabled);
2869 EXPECT_EQ(ec_mode, webrtc::kEcConference);
2870 EXPECT_EQ(ns_mode, webrtc::kNsHighSuppression);
2871
Bjorn Volckerbf395c12015-03-25 22:45:56 +01002872 // Turn on delay agnostic aec and make sure nothing change w.r.t. echo
2873 // control.
2874 options.delay_agnostic_aec.Set(true);
2875 ASSERT_TRUE(engine_.SetOptions(options));
2876 voe_.GetEcStatus(ec_enabled, ec_mode);
2877 voe_.GetEcMetricsStatus(ec_metrics_enabled);
2878 voe_.GetAecmMode(aecm_mode, cng_enabled);
2879 EXPECT_TRUE(ec_enabled);
2880 EXPECT_TRUE(ec_metrics_enabled);
2881 EXPECT_EQ(ec_mode, webrtc::kEcConference);
2882
2883 // Turn off echo cancellation and delay agnostic aec.
2884 options.delay_agnostic_aec.Set(false);
2885 options.experimental_aec.Set(false);
2886 options.echo_cancellation.Set(false);
2887 ASSERT_TRUE(engine_.SetOptions(options));
2888 voe_.GetEcStatus(ec_enabled, ec_mode);
2889 EXPECT_FALSE(ec_enabled);
2890 // Turning delay agnostic aec back on should also turn on echo cancellation.
2891 options.delay_agnostic_aec.Set(true);
2892 ASSERT_TRUE(engine_.SetOptions(options));
2893 voe_.GetEcStatus(ec_enabled, ec_mode);
2894 voe_.GetEcMetricsStatus(ec_metrics_enabled);
2895 EXPECT_TRUE(ec_enabled);
2896 EXPECT_TRUE(ec_metrics_enabled);
2897 EXPECT_EQ(ec_mode, webrtc::kEcConference);
2898
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002899 // Turn off AGC
2900 options.auto_gain_control.Set(false);
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00002901 ASSERT_TRUE(engine_.SetOptions(options));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002902 voe_.GetAgcStatus(agc_enabled, agc_mode);
2903 EXPECT_FALSE(agc_enabled);
2904
2905 // Turn AGC back on
2906 options.auto_gain_control.Set(true);
2907 options.adjust_agc_delta.Clear();
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00002908 ASSERT_TRUE(engine_.SetOptions(options));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002909 voe_.GetAgcStatus(agc_enabled, agc_mode);
2910 EXPECT_TRUE(agc_enabled);
2911 voe_.GetAgcConfig(agc_config);
2912 EXPECT_EQ(0, agc_config.targetLeveldBOv);
2913
2914 // Turn off other options (and stereo swapping on).
2915 options.noise_suppression.Set(false);
2916 options.highpass_filter.Set(false);
2917 options.typing_detection.Set(false);
2918 options.stereo_swapping.Set(true);
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00002919 ASSERT_TRUE(engine_.SetOptions(options));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002920 voe_.GetNsStatus(ns_enabled, ns_mode);
2921 highpass_filter_enabled = voe_.IsHighPassFilterEnabled();
2922 stereo_swapping_enabled = voe_.IsStereoChannelSwappingEnabled();
2923 voe_.GetTypingDetectionStatus(typing_detection_enabled);
2924 EXPECT_FALSE(ns_enabled);
2925 EXPECT_FALSE(highpass_filter_enabled);
2926 EXPECT_FALSE(typing_detection_enabled);
2927 EXPECT_TRUE(stereo_swapping_enabled);
2928
2929 // Turn on "conference mode" to ensure it has no impact.
2930 options.conference_mode.Set(true);
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00002931 ASSERT_TRUE(engine_.SetOptions(options));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002932 voe_.GetEcStatus(ec_enabled, ec_mode);
2933 voe_.GetNsStatus(ns_enabled, ns_mode);
2934 EXPECT_TRUE(ec_enabled);
2935 EXPECT_EQ(webrtc::kEcConference, ec_mode);
2936 EXPECT_FALSE(ns_enabled);
2937 EXPECT_EQ(webrtc::kNsHighSuppression, ns_mode);
2938}
2939
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00002940TEST_F(WebRtcVoiceEngineTestFake, DefaultOptions) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002941 EXPECT_TRUE(SetupEngine());
2942
2943 bool ec_enabled;
2944 webrtc::EcModes ec_mode;
2945 bool ec_metrics_enabled;
2946 bool agc_enabled;
2947 webrtc::AgcModes agc_mode;
2948 bool ns_enabled;
2949 webrtc::NsModes ns_mode;
2950 bool highpass_filter_enabled;
2951 bool stereo_swapping_enabled;
2952 bool typing_detection_enabled;
2953
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002954 voe_.GetEcStatus(ec_enabled, ec_mode);
2955 voe_.GetEcMetricsStatus(ec_metrics_enabled);
2956 voe_.GetAgcStatus(agc_enabled, agc_mode);
2957 voe_.GetNsStatus(ns_enabled, ns_mode);
2958 highpass_filter_enabled = voe_.IsHighPassFilterEnabled();
2959 stereo_swapping_enabled = voe_.IsStereoChannelSwappingEnabled();
2960 voe_.GetTypingDetectionStatus(typing_detection_enabled);
2961 EXPECT_TRUE(ec_enabled);
2962 EXPECT_TRUE(agc_enabled);
2963 EXPECT_TRUE(ns_enabled);
2964 EXPECT_TRUE(highpass_filter_enabled);
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00002965 EXPECT_TRUE(typing_detection_enabled);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002966 EXPECT_FALSE(stereo_swapping_enabled);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002967}
2968
2969TEST_F(WebRtcVoiceEngineTestFake, InitDoesNotOverwriteDefaultAgcConfig) {
2970 webrtc::AgcConfig set_config = {0};
2971 set_config.targetLeveldBOv = 3;
2972 set_config.digitalCompressionGaindB = 9;
2973 set_config.limiterEnable = true;
2974 EXPECT_EQ(0, voe_.SetAgcConfig(set_config));
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002975 EXPECT_TRUE(engine_.Init(rtc::Thread::Current()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002976
2977 webrtc::AgcConfig config = {0};
2978 EXPECT_EQ(0, voe_.GetAgcConfig(config));
2979 EXPECT_EQ(set_config.targetLeveldBOv, config.targetLeveldBOv);
2980 EXPECT_EQ(set_config.digitalCompressionGaindB,
2981 config.digitalCompressionGaindB);
2982 EXPECT_EQ(set_config.limiterEnable, config.limiterEnable);
2983}
2984
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002985TEST_F(WebRtcVoiceEngineTestFake, SetOptionOverridesViaChannels) {
2986 EXPECT_TRUE(SetupEngine());
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002987 rtc::scoped_ptr<cricket::VoiceMediaChannel> channel1(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002988 engine_.CreateChannel());
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002989 rtc::scoped_ptr<cricket::VoiceMediaChannel> channel2(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002990 engine_.CreateChannel());
2991
2992 // Have to add a stream to make SetSend work.
2993 cricket::StreamParams stream1;
2994 stream1.ssrcs.push_back(1);
2995 channel1->AddSendStream(stream1);
2996 cricket::StreamParams stream2;
2997 stream2.ssrcs.push_back(2);
2998 channel2->AddSendStream(stream2);
2999
3000 // AEC and AGC and NS
3001 cricket::AudioOptions options_all;
3002 options_all.echo_cancellation.Set(true);
3003 options_all.auto_gain_control.Set(true);
3004 options_all.noise_suppression.Set(true);
3005
3006 ASSERT_TRUE(channel1->SetOptions(options_all));
3007 cricket::AudioOptions expected_options = options_all;
3008 cricket::AudioOptions actual_options;
3009 ASSERT_TRUE(channel1->GetOptions(&actual_options));
3010 EXPECT_EQ(expected_options, actual_options);
3011 ASSERT_TRUE(channel2->SetOptions(options_all));
3012 ASSERT_TRUE(channel2->GetOptions(&actual_options));
3013 EXPECT_EQ(expected_options, actual_options);
3014
3015 // unset NS
3016 cricket::AudioOptions options_no_ns;
3017 options_no_ns.noise_suppression.Set(false);
3018 ASSERT_TRUE(channel1->SetOptions(options_no_ns));
3019
3020 expected_options.echo_cancellation.Set(true);
3021 expected_options.auto_gain_control.Set(true);
3022 expected_options.noise_suppression.Set(false);
3023 ASSERT_TRUE(channel1->GetOptions(&actual_options));
3024 EXPECT_EQ(expected_options, actual_options);
3025
3026 // unset AGC
3027 cricket::AudioOptions options_no_agc;
3028 options_no_agc.auto_gain_control.Set(false);
3029 ASSERT_TRUE(channel2->SetOptions(options_no_agc));
3030
3031 expected_options.echo_cancellation.Set(true);
3032 expected_options.auto_gain_control.Set(false);
3033 expected_options.noise_suppression.Set(true);
3034 ASSERT_TRUE(channel2->GetOptions(&actual_options));
3035 EXPECT_EQ(expected_options, actual_options);
3036
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00003037 ASSERT_TRUE(engine_.SetOptions(options_all));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003038 bool ec_enabled;
3039 webrtc::EcModes ec_mode;
3040 bool agc_enabled;
3041 webrtc::AgcModes agc_mode;
3042 bool ns_enabled;
3043 webrtc::NsModes ns_mode;
3044 voe_.GetEcStatus(ec_enabled, ec_mode);
3045 voe_.GetAgcStatus(agc_enabled, agc_mode);
3046 voe_.GetNsStatus(ns_enabled, ns_mode);
3047 EXPECT_TRUE(ec_enabled);
3048 EXPECT_TRUE(agc_enabled);
3049 EXPECT_TRUE(ns_enabled);
3050
3051 channel1->SetSend(cricket::SEND_MICROPHONE);
3052 voe_.GetEcStatus(ec_enabled, ec_mode);
3053 voe_.GetAgcStatus(agc_enabled, agc_mode);
3054 voe_.GetNsStatus(ns_enabled, ns_mode);
3055 EXPECT_TRUE(ec_enabled);
3056 EXPECT_TRUE(agc_enabled);
3057 EXPECT_FALSE(ns_enabled);
3058
3059 channel1->SetSend(cricket::SEND_NOTHING);
3060 voe_.GetEcStatus(ec_enabled, ec_mode);
3061 voe_.GetAgcStatus(agc_enabled, agc_mode);
3062 voe_.GetNsStatus(ns_enabled, ns_mode);
3063 EXPECT_TRUE(ec_enabled);
3064 EXPECT_TRUE(agc_enabled);
3065 EXPECT_TRUE(ns_enabled);
3066
3067 channel2->SetSend(cricket::SEND_MICROPHONE);
3068 voe_.GetEcStatus(ec_enabled, ec_mode);
3069 voe_.GetAgcStatus(agc_enabled, agc_mode);
3070 voe_.GetNsStatus(ns_enabled, ns_mode);
3071 EXPECT_TRUE(ec_enabled);
3072 EXPECT_FALSE(agc_enabled);
3073 EXPECT_TRUE(ns_enabled);
3074
3075 channel2->SetSend(cricket::SEND_NOTHING);
3076 voe_.GetEcStatus(ec_enabled, ec_mode);
3077 voe_.GetAgcStatus(agc_enabled, agc_mode);
3078 voe_.GetNsStatus(ns_enabled, ns_mode);
3079 EXPECT_TRUE(ec_enabled);
3080 EXPECT_TRUE(agc_enabled);
3081 EXPECT_TRUE(ns_enabled);
3082
3083 // Make sure settings take effect while we are sending.
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00003084 ASSERT_TRUE(engine_.SetOptions(options_all));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003085 cricket::AudioOptions options_no_agc_nor_ns;
3086 options_no_agc_nor_ns.auto_gain_control.Set(false);
3087 options_no_agc_nor_ns.noise_suppression.Set(false);
3088 channel2->SetSend(cricket::SEND_MICROPHONE);
3089 channel2->SetOptions(options_no_agc_nor_ns);
3090
3091 expected_options.echo_cancellation.Set(true);
3092 expected_options.auto_gain_control.Set(false);
3093 expected_options.noise_suppression.Set(false);
3094 ASSERT_TRUE(channel2->GetOptions(&actual_options));
3095 EXPECT_EQ(expected_options, actual_options);
3096 voe_.GetEcStatus(ec_enabled, ec_mode);
3097 voe_.GetAgcStatus(agc_enabled, agc_mode);
3098 voe_.GetNsStatus(ns_enabled, ns_mode);
3099 EXPECT_TRUE(ec_enabled);
3100 EXPECT_FALSE(agc_enabled);
3101 EXPECT_FALSE(ns_enabled);
3102}
3103
wu@webrtc.orgde305012013-10-31 15:40:38 +00003104// This test verifies DSCP settings are properly applied on voice media channel.
3105TEST_F(WebRtcVoiceEngineTestFake, TestSetDscpOptions) {
3106 EXPECT_TRUE(SetupEngine());
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003107 rtc::scoped_ptr<cricket::VoiceMediaChannel> channel(
wu@webrtc.orgde305012013-10-31 15:40:38 +00003108 engine_.CreateChannel());
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003109 rtc::scoped_ptr<cricket::FakeNetworkInterface> network_interface(
wu@webrtc.orgde305012013-10-31 15:40:38 +00003110 new cricket::FakeNetworkInterface);
3111 channel->SetInterface(network_interface.get());
3112 cricket::AudioOptions options;
3113 options.dscp.Set(true);
3114 EXPECT_TRUE(channel->SetOptions(options));
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003115 EXPECT_EQ(rtc::DSCP_EF, network_interface->dscp());
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +00003116 // Verify previous value is not modified if dscp option is not set.
3117 cricket::AudioOptions options1;
3118 EXPECT_TRUE(channel->SetOptions(options1));
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003119 EXPECT_EQ(rtc::DSCP_EF, network_interface->dscp());
wu@webrtc.orgde305012013-10-31 15:40:38 +00003120 options.dscp.Set(false);
3121 EXPECT_TRUE(channel->SetOptions(options));
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003122 EXPECT_EQ(rtc::DSCP_DEFAULT, network_interface->dscp());
wu@webrtc.orgde305012013-10-31 15:40:38 +00003123}
3124
wu@webrtc.org1d1ffc92013-10-16 18:12:02 +00003125TEST(WebRtcVoiceEngineTest, TestDefaultOptionsBeforeInit) {
3126 cricket::WebRtcVoiceEngine engine;
3127 cricket::AudioOptions options = engine.GetOptions();
3128 // The default options should have at least a few things set. We purposefully
3129 // don't check the option values here, though.
3130 EXPECT_TRUE(options.echo_cancellation.IsSet());
3131 EXPECT_TRUE(options.auto_gain_control.IsSet());
3132 EXPECT_TRUE(options.noise_suppression.IsSet());
3133}
3134
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003135// Test that GetReceiveChannelNum returns the default channel for the first
3136// recv stream in 1-1 calls.
3137TEST_F(WebRtcVoiceEngineTestFake, TestGetReceiveChannelNumIn1To1Calls) {
3138 EXPECT_TRUE(SetupEngine());
3139 cricket::WebRtcVoiceMediaChannel* media_channel =
3140 static_cast<cricket::WebRtcVoiceMediaChannel*>(channel_);
3141 // Test that GetChannelNum returns the default channel if the SSRC is unknown.
3142 EXPECT_EQ(media_channel->voe_channel(),
3143 media_channel->GetReceiveChannelNum(0));
3144 cricket::StreamParams stream;
3145 stream.ssrcs.push_back(kSsrc2);
3146 EXPECT_TRUE(channel_->AddRecvStream(stream));
3147 EXPECT_EQ(media_channel->voe_channel(),
3148 media_channel->GetReceiveChannelNum(kSsrc2));
3149}
3150
3151// Test that GetReceiveChannelNum doesn't return the default channel for the
3152// first recv stream in conference calls.
3153TEST_F(WebRtcVoiceEngineTestFake, TestGetChannelNumInConferenceCalls) {
3154 EXPECT_TRUE(SetupEngine());
3155 EXPECT_TRUE(channel_->SetOptions(options_conference_));
3156 cricket::StreamParams stream;
3157 stream.ssrcs.push_back(kSsrc2);
3158 EXPECT_TRUE(channel_->AddRecvStream(stream));
3159 cricket::WebRtcVoiceMediaChannel* media_channel =
3160 static_cast<cricket::WebRtcVoiceMediaChannel*>(channel_);
3161 EXPECT_LT(media_channel->voe_channel(),
3162 media_channel->GetReceiveChannelNum(kSsrc2));
3163}
3164
3165TEST_F(WebRtcVoiceEngineTestFake, SetOutputScaling) {
3166 EXPECT_TRUE(SetupEngine());
3167 double left, right;
3168 EXPECT_TRUE(channel_->SetOutputScaling(0, 1, 2));
3169 EXPECT_TRUE(channel_->GetOutputScaling(0, &left, &right));
3170 EXPECT_DOUBLE_EQ(1, left);
3171 EXPECT_DOUBLE_EQ(2, right);
3172
3173 EXPECT_FALSE(channel_->SetOutputScaling(kSsrc2, 1, 2));
3174 cricket::StreamParams stream;
3175 stream.ssrcs.push_back(kSsrc2);
3176 EXPECT_TRUE(channel_->AddRecvStream(stream));
3177
3178 EXPECT_TRUE(channel_->SetOutputScaling(kSsrc2, 2, 1));
3179 EXPECT_TRUE(channel_->GetOutputScaling(kSsrc2, &left, &right));
3180 EXPECT_DOUBLE_EQ(2, left);
3181 EXPECT_DOUBLE_EQ(1, right);
3182}
3183
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003184// Tests for the actual WebRtc VoE library.
3185
3186// Tests that the library initializes and shuts down properly.
3187TEST(WebRtcVoiceEngineTest, StartupShutdown) {
3188 cricket::WebRtcVoiceEngine engine;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003189 EXPECT_TRUE(engine.Init(rtc::Thread::Current()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003190 cricket::VoiceMediaChannel* channel = engine.CreateChannel();
3191 EXPECT_TRUE(channel != NULL);
3192 delete channel;
3193 engine.Terminate();
3194
3195 // Reinit to catch regression where VoiceEngineObserver reference is lost
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003196 EXPECT_TRUE(engine.Init(rtc::Thread::Current()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003197 engine.Terminate();
3198}
3199
3200// Tests that the logging from the library is cleartext.
3201TEST(WebRtcVoiceEngineTest, DISABLED_HasUnencryptedLogging) {
3202 cricket::WebRtcVoiceEngine engine;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003203 rtc::scoped_ptr<rtc::MemoryStream> stream(
3204 new rtc::MemoryStream);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003205 size_t size = 0;
3206 bool cleartext = true;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003207 rtc::LogMessage::AddLogToStream(stream.get(), rtc::LS_VERBOSE);
3208 engine.SetLogging(rtc::LS_VERBOSE, "");
3209 EXPECT_TRUE(engine.Init(rtc::Thread::Current()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003210 EXPECT_TRUE(stream->GetSize(&size));
3211 EXPECT_GT(size, 0U);
3212 engine.Terminate();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003213 rtc::LogMessage::RemoveLogToStream(stream.get());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003214 const char* buf = stream->GetBuffer();
3215 for (size_t i = 0; i < size && cleartext; ++i) {
3216 int ch = static_cast<int>(buf[i]);
3217 ASSERT_GE(ch, 0) << "Out of bounds character in WebRtc VoE log: "
3218 << std::hex << ch;
3219 cleartext = (isprint(ch) || isspace(ch));
3220 }
3221 EXPECT_TRUE(cleartext);
3222}
3223
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003224// Tests that the library is configured with the codecs we want.
3225TEST(WebRtcVoiceEngineTest, HasCorrectCodecs) {
3226 cricket::WebRtcVoiceEngine engine;
3227 // Check codecs by name.
3228 EXPECT_TRUE(engine.FindCodec(
3229 cricket::AudioCodec(96, "OPUS", 48000, 0, 2, 0)));
3230 EXPECT_TRUE(engine.FindCodec(
3231 cricket::AudioCodec(96, "ISAC", 16000, 0, 1, 0)));
3232 EXPECT_TRUE(engine.FindCodec(
3233 cricket::AudioCodec(96, "ISAC", 32000, 0, 1, 0)));
3234 // Check that name matching is case-insensitive.
3235 EXPECT_TRUE(engine.FindCodec(
3236 cricket::AudioCodec(96, "ILBC", 8000, 0, 1, 0)));
3237 EXPECT_TRUE(engine.FindCodec(
3238 cricket::AudioCodec(96, "iLBC", 8000, 0, 1, 0)));
3239 EXPECT_TRUE(engine.FindCodec(
3240 cricket::AudioCodec(96, "PCMU", 8000, 0, 1, 0)));
3241 EXPECT_TRUE(engine.FindCodec(
3242 cricket::AudioCodec(96, "PCMA", 8000, 0, 1, 0)));
3243 EXPECT_TRUE(engine.FindCodec(
henrik.lundin@webrtc.orgf85dbce2014-11-07 12:25:00 +00003244 cricket::AudioCodec(96, "G722", 8000, 0, 1, 0)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003245 EXPECT_TRUE(engine.FindCodec(
3246 cricket::AudioCodec(96, "red", 8000, 0, 1, 0)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003247 EXPECT_TRUE(engine.FindCodec(
3248 cricket::AudioCodec(96, "CN", 32000, 0, 1, 0)));
3249 EXPECT_TRUE(engine.FindCodec(
3250 cricket::AudioCodec(96, "CN", 16000, 0, 1, 0)));
3251 EXPECT_TRUE(engine.FindCodec(
3252 cricket::AudioCodec(96, "CN", 8000, 0, 1, 0)));
3253 EXPECT_TRUE(engine.FindCodec(
3254 cricket::AudioCodec(96, "telephone-event", 8000, 0, 1, 0)));
3255 // Check codecs with an id by id.
3256 EXPECT_TRUE(engine.FindCodec(
3257 cricket::AudioCodec(0, "", 8000, 0, 1, 0))); // PCMU
3258 EXPECT_TRUE(engine.FindCodec(
3259 cricket::AudioCodec(8, "", 8000, 0, 1, 0))); // PCMA
3260 EXPECT_TRUE(engine.FindCodec(
henrik.lundin@webrtc.orgf85dbce2014-11-07 12:25:00 +00003261 cricket::AudioCodec(9, "", 8000, 0, 1, 0))); // G722
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003262 EXPECT_TRUE(engine.FindCodec(
3263 cricket::AudioCodec(13, "", 8000, 0, 1, 0))); // CN
3264 // Check sample/bitrate matching.
3265 EXPECT_TRUE(engine.FindCodec(
3266 cricket::AudioCodec(0, "PCMU", 8000, 64000, 1, 0)));
3267 // Check that bad codecs fail.
3268 EXPECT_FALSE(engine.FindCodec(cricket::AudioCodec(99, "ABCD", 0, 0, 1, 0)));
3269 EXPECT_FALSE(engine.FindCodec(cricket::AudioCodec(88, "", 0, 0, 1, 0)));
3270 EXPECT_FALSE(engine.FindCodec(cricket::AudioCodec(0, "", 0, 0, 2, 0)));
3271 EXPECT_FALSE(engine.FindCodec(cricket::AudioCodec(0, "", 5000, 0, 1, 0)));
3272 EXPECT_FALSE(engine.FindCodec(cricket::AudioCodec(0, "", 0, 5000, 1, 0)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003273 // Verify the payload id of common audio codecs, including CN, ISAC, and G722.
3274 for (std::vector<cricket::AudioCodec>::const_iterator it =
3275 engine.codecs().begin(); it != engine.codecs().end(); ++it) {
3276 if (it->name == "CN" && it->clockrate == 16000) {
3277 EXPECT_EQ(105, it->id);
3278 } else if (it->name == "CN" && it->clockrate == 32000) {
3279 EXPECT_EQ(106, it->id);
3280 } else if (it->name == "ISAC" && it->clockrate == 16000) {
3281 EXPECT_EQ(103, it->id);
3282 } else if (it->name == "ISAC" && it->clockrate == 32000) {
3283 EXPECT_EQ(104, it->id);
henrik.lundin@webrtc.orgf85dbce2014-11-07 12:25:00 +00003284 } else if (it->name == "G722" && it->clockrate == 8000) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003285 EXPECT_EQ(9, it->id);
3286 } else if (it->name == "telephone-event") {
3287 EXPECT_EQ(126, it->id);
3288 } else if (it->name == "red") {
3289 EXPECT_EQ(127, it->id);
3290 } else if (it->name == "opus") {
3291 EXPECT_EQ(111, it->id);
wu@webrtc.org9caf2762013-12-11 18:25:07 +00003292 ASSERT_TRUE(it->params.find("minptime") != it->params.end());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003293 EXPECT_EQ("10", it->params.find("minptime")->second);
wu@webrtc.org9caf2762013-12-11 18:25:07 +00003294 ASSERT_TRUE(it->params.find("maxptime") != it->params.end());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003295 EXPECT_EQ("60", it->params.find("maxptime")->second);
minyue@webrtc.org4ef22d12014-11-17 09:26:39 +00003296 ASSERT_TRUE(it->params.find("useinbandfec") != it->params.end());
3297 EXPECT_EQ("1", it->params.find("useinbandfec")->second);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003298 }
3299 }
3300
3301 engine.Terminate();
3302}
3303
3304// Tests that VoE supports at least 32 channels
3305TEST(WebRtcVoiceEngineTest, Has32Channels) {
3306 cricket::WebRtcVoiceEngine engine;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003307 EXPECT_TRUE(engine.Init(rtc::Thread::Current()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003308
3309 cricket::VoiceMediaChannel* channels[32];
3310 int num_channels = 0;
3311
3312 while (num_channels < ARRAY_SIZE(channels)) {
3313 cricket::VoiceMediaChannel* channel = engine.CreateChannel();
3314 if (!channel)
3315 break;
3316
3317 channels[num_channels++] = channel;
3318 }
3319
3320 int expected = ARRAY_SIZE(channels);
3321 EXPECT_EQ(expected, num_channels);
3322
3323 while (num_channels > 0) {
3324 delete channels[--num_channels];
3325 }
3326
3327 engine.Terminate();
3328}
3329
3330// Test that we set our preferred codecs properly.
3331TEST(WebRtcVoiceEngineTest, SetRecvCodecs) {
3332 cricket::WebRtcVoiceEngine engine;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003333 EXPECT_TRUE(engine.Init(rtc::Thread::Current()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003334 cricket::WebRtcVoiceMediaChannel channel(&engine);
3335 EXPECT_TRUE(channel.SetRecvCodecs(engine.codecs()));
3336}
3337
3338#ifdef WIN32
3339// Test our workarounds to WebRtc VoE' munging of the coinit count
3340TEST(WebRtcVoiceEngineTest, CoInitialize) {
3341 cricket::WebRtcVoiceEngine* engine = new cricket::WebRtcVoiceEngine();
3342
3343 // Initial refcount should be 0.
3344 EXPECT_EQ(S_OK, CoInitializeEx(NULL, COINIT_MULTITHREADED));
3345
3346 // Engine should start even with COM already inited.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003347 EXPECT_TRUE(engine->Init(rtc::Thread::Current()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003348 engine->Terminate();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003349 EXPECT_TRUE(engine->Init(rtc::Thread::Current()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003350 engine->Terminate();
3351
3352 // Refcount after terminate should be 1 (in reality 3); test if it is nonzero.
3353 EXPECT_EQ(S_FALSE, CoInitializeEx(NULL, COINIT_MULTITHREADED));
3354 // Decrement refcount to (hopefully) 0.
3355 CoUninitialize();
3356 CoUninitialize();
3357 delete engine;
3358
3359 // Ensure refcount is 0.
3360 EXPECT_EQ(S_OK, CoInitializeEx(NULL, COINIT_MULTITHREADED));
3361 CoUninitialize();
3362}
3363#endif
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +00003364
3365TEST_F(WebRtcVoiceEngineTestFake, ChangeCombinedAudioVideoBweOption) {
3366 // Test that changing the combined_audio_video_bwe option results in the
3367 // expected state changes in VoiceEngine.
3368 cricket::ViEWrapper vie;
3369 const int kVieCh = 667;
3370
3371 EXPECT_TRUE(SetupEngine());
3372 cricket::WebRtcVoiceMediaChannel* media_channel =
3373 static_cast<cricket::WebRtcVoiceMediaChannel*>(channel_);
3374 EXPECT_TRUE(media_channel->SetupSharedBandwidthEstimation(vie.engine(),
3375 kVieCh));
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 // Enable combined BWE option - now it should be set up.
3385 cricket::AudioOptions options;
3386 options.combined_audio_video_bwe.Set(true);
3387 EXPECT_TRUE(media_channel->SetOptions(options));
3388 EXPECT_EQ(vie.network(), voe_.GetViENetwork(recv_ch));
3389 EXPECT_EQ(kVieCh, voe_.GetVideoChannel(recv_ch));
3390
3391 // Disable combined BWE option - should be disabled again.
3392 options.combined_audio_video_bwe.Set(false);
3393 EXPECT_TRUE(media_channel->SetOptions(options));
3394 EXPECT_EQ(NULL, voe_.GetViENetwork(recv_ch));
3395 EXPECT_EQ(-1, voe_.GetVideoChannel(recv_ch));
3396
3397 EXPECT_TRUE(media_channel->SetupSharedBandwidthEstimation(NULL, -1));
3398}
3399
3400TEST_F(WebRtcVoiceEngineTestFake, SetupSharedBandwidthEstimation) {
3401 // Test that calling SetupSharedBandwidthEstimation() on the voice media
3402 // channel results in the expected state changes in VoiceEngine.
3403 cricket::ViEWrapper vie1;
3404 cricket::ViEWrapper vie2;
3405 const int kVieCh1 = 667;
3406 const int kVieCh2 = 70;
3407
3408 EXPECT_TRUE(SetupEngine());
3409 cricket::WebRtcVoiceMediaChannel* media_channel =
3410 static_cast<cricket::WebRtcVoiceMediaChannel*>(channel_);
3411 cricket::AudioOptions options;
3412 options.combined_audio_video_bwe.Set(true);
3413 EXPECT_TRUE(media_channel->SetOptions(options));
3414 EXPECT_TRUE(media_channel->AddRecvStream(
3415 cricket::StreamParams::CreateLegacy(2)));
3416 int recv_ch = voe_.GetLastChannel();
3417
3418 // Combined BWE should not be set up yet.
3419 EXPECT_EQ(NULL, voe_.GetViENetwork(recv_ch));
3420 EXPECT_EQ(-1, voe_.GetVideoChannel(recv_ch));
3421
3422 // Register - should be enabled.
3423 EXPECT_TRUE(media_channel->SetupSharedBandwidthEstimation(vie1.engine(),
3424 kVieCh1));
3425 EXPECT_EQ(vie1.network(), voe_.GetViENetwork(recv_ch));
3426 EXPECT_EQ(kVieCh1, voe_.GetVideoChannel(recv_ch));
3427
3428 // Re-register - should still be enabled.
3429 EXPECT_TRUE(media_channel->SetupSharedBandwidthEstimation(vie2.engine(),
3430 kVieCh2));
3431 EXPECT_EQ(vie2.network(), voe_.GetViENetwork(recv_ch));
3432 EXPECT_EQ(kVieCh2, voe_.GetVideoChannel(recv_ch));
3433
3434 // Unregister - should be disabled again.
3435 EXPECT_TRUE(media_channel->SetupSharedBandwidthEstimation(NULL, -1));
3436 EXPECT_EQ(NULL, voe_.GetViENetwork(recv_ch));
3437 EXPECT_EQ(-1, voe_.GetVideoChannel(recv_ch));
3438}
3439
3440TEST_F(WebRtcVoiceEngineTestFake, ConfigureCombinedBweForNewRecvStreams) {
3441 // Test that adding receive streams after enabling combined bandwidth
3442 // estimation will correctly configure each channel.
3443 cricket::ViEWrapper vie;
3444 const int kVieCh = 667;
3445
3446 EXPECT_TRUE(SetupEngine());
3447 cricket::WebRtcVoiceMediaChannel* media_channel =
3448 static_cast<cricket::WebRtcVoiceMediaChannel*>(channel_);
3449 EXPECT_TRUE(media_channel->SetupSharedBandwidthEstimation(vie.engine(),
3450 kVieCh));
3451 cricket::AudioOptions options;
3452 options.combined_audio_video_bwe.Set(true);
3453 EXPECT_TRUE(media_channel->SetOptions(options));
3454
3455 static const uint32 kSsrcs[] = {1, 2, 3, 4};
3456 int voe_channels[ARRAY_SIZE(kSsrcs)] = {0};
3457 for (unsigned int i = 0; i < ARRAY_SIZE(kSsrcs); ++i) {
3458 EXPECT_TRUE(media_channel->AddRecvStream(
3459 cricket::StreamParams::CreateLegacy(kSsrcs[i])));
3460 int recv_ch = media_channel->GetReceiveChannelNum(kSsrcs[i]);
3461 EXPECT_NE(-1, recv_ch);
3462 voe_channels[i] = recv_ch;
3463 EXPECT_EQ(vie.network(), voe_.GetViENetwork(recv_ch));
3464 EXPECT_EQ(kVieCh, voe_.GetVideoChannel(recv_ch));
3465 }
3466
3467 EXPECT_TRUE(media_channel->SetupSharedBandwidthEstimation(NULL, -1));
3468
3469 for (unsigned int i = 0; i < ARRAY_SIZE(voe_channels); ++i) {
3470 EXPECT_EQ(NULL, voe_.GetViENetwork(voe_channels[i]));
3471 EXPECT_EQ(-1, voe_.GetVideoChannel(voe_channels[i]));
3472 }
3473}