blob: 8b65fbf50d6f4b2fb697fb54b3114fcf42d5650c [file] [log] [blame]
henrike@webrtc.org79047f92014-03-06 23:46:59 +00001/*
2 * libjingle
3 * Copyright 2008 Google Inc.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright notice,
11 * this list of conditions and the following disclaimer in the documentation
12 * and/or other materials provided with the distribution.
13 * 3. The name of the author may not be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
19 * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
21 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
22 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
23 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
24 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
25 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
henrike@webrtc.org28e20752013-07-10 00:45:36 +000027
28#ifdef WIN32
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000029#include "webrtc/base/win32.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000030#include <objbase.h>
31#endif
32
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000033#include "webrtc/base/byteorder.h"
34#include "webrtc/base/gunit.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000035#include "talk/media/base/constants.h"
36#include "talk/media/base/fakemediaengine.h"
37#include "talk/media/base/fakemediaprocessor.h"
wu@webrtc.orgde305012013-10-31 15:40:38 +000038#include "talk/media/base/fakenetworkinterface.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000039#include "talk/media/base/fakertp.h"
Fredrik Solenberg4b60c732015-05-07 14:07:48 +020040#include "talk/media/webrtc/fakewebrtccall.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000041#include "talk/media/webrtc/fakewebrtcvoiceengine.h"
42#include "talk/media/webrtc/webrtcvoiceengine.h"
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +000043#include "webrtc/p2p/base/fakesession.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000044#include "talk/session/media/channel.h"
45
46// Tests for the WebRtcVoiceEngine/VoiceChannel code.
47
buildbot@webrtc.org150835e2014-05-06 15:54:38 +000048using cricket::kRtpAudioLevelHeaderExtension;
49using cricket::kRtpAbsoluteSenderTimeHeaderExtension;
50
henrike@webrtc.org28e20752013-07-10 00:45:36 +000051static const cricket::AudioCodec kPcmuCodec(0, "PCMU", 8000, 64000, 1, 0);
52static const cricket::AudioCodec kIsacCodec(103, "ISAC", 16000, 32000, 1, 0);
henrike@webrtc.org28e20752013-07-10 00:45:36 +000053static const cricket::AudioCodec kOpusCodec(111, "opus", 48000, 64000, 2, 0);
henrik.lundin@webrtc.orgf85dbce2014-11-07 12:25:00 +000054static const cricket::AudioCodec kG722CodecVoE(9, "G722", 16000, 64000, 1, 0);
55static const cricket::AudioCodec kG722CodecSdp(9, "G722", 8000, 64000, 1, 0);
henrike@webrtc.org28e20752013-07-10 00:45:36 +000056static const cricket::AudioCodec kRedCodec(117, "red", 8000, 0, 1, 0);
57static const cricket::AudioCodec kCn8000Codec(13, "CN", 8000, 0, 1, 0);
58static const cricket::AudioCodec kCn16000Codec(105, "CN", 16000, 0, 1, 0);
59static const cricket::AudioCodec
60 kTelephoneEventCodec(106, "telephone-event", 8000, 0, 1, 0);
61static const cricket::AudioCodec* const kAudioCodecs[] = {
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +000062 &kPcmuCodec, &kIsacCodec, &kOpusCodec, &kG722CodecVoE, &kRedCodec,
63 &kCn8000Codec, &kCn16000Codec, &kTelephoneEventCodec,
henrike@webrtc.org28e20752013-07-10 00:45:36 +000064};
65const char kRingbackTone[] = "RIFF____WAVE____ABCD1234";
66static uint32 kSsrc1 = 0x99;
67static uint32 kSsrc2 = 0x98;
68
69class FakeVoEWrapper : public cricket::VoEWrapper {
70 public:
71 explicit FakeVoEWrapper(cricket::FakeWebRtcVoiceEngine* engine)
72 : cricket::VoEWrapper(engine, // processing
73 engine, // base
74 engine, // codec
75 engine, // dtmf
76 engine, // file
77 engine, // hw
78 engine, // media
79 engine, // neteq
80 engine, // network
81 engine, // rtp
82 engine, // sync
83 engine) { // volume
84 }
85};
86
wu@webrtc.org97077a32013-10-25 21:18:33 +000087class FakeVoETraceWrapper : public cricket::VoETraceWrapper {
henrike@webrtc.org28e20752013-07-10 00:45:36 +000088 public:
Fredrik Solenbergaaf8ff22015-05-07 16:05:53 +020089 int SetTraceFilter(const unsigned int filter) override {
wu@webrtc.org97077a32013-10-25 21:18:33 +000090 filter_ = filter;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000091 return 0;
92 }
Fredrik Solenbergaaf8ff22015-05-07 16:05:53 +020093 int SetTraceFile(const char* fileNameUTF8) override { return 0; }
94 int SetTraceCallback(webrtc::TraceCallback* callback) override { return 0; }
wu@webrtc.org97077a32013-10-25 21:18:33 +000095 unsigned int filter_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000096};
97
98class WebRtcVoiceEngineTestFake : public testing::Test {
99 public:
100 class ChannelErrorListener : public sigslot::has_slots<> {
101 public:
102 explicit ChannelErrorListener(cricket::VoiceMediaChannel* channel)
103 : ssrc_(0), error_(cricket::VoiceMediaChannel::ERROR_NONE) {
Fredrik Solenbergd3ddc1b2015-05-07 17:07:34 +0200104 DCHECK(channel != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000105 channel->SignalMediaError.connect(
106 this, &ChannelErrorListener::OnVoiceChannelError);
107 }
108 void OnVoiceChannelError(uint32 ssrc,
109 cricket::VoiceMediaChannel::Error error) {
110 ssrc_ = ssrc;
111 error_ = error;
112 }
113 void Reset() {
114 ssrc_ = 0;
115 error_ = cricket::VoiceMediaChannel::ERROR_NONE;
116 }
117 uint32 ssrc() const {
118 return ssrc_;
119 }
120 cricket::VoiceMediaChannel::Error error() const {
121 return error_;
122 }
123
124 private:
125 uint32 ssrc_;
126 cricket::VoiceMediaChannel::Error error_;
127 };
128
129 WebRtcVoiceEngineTestFake()
130 : voe_(kAudioCodecs, ARRAY_SIZE(kAudioCodecs)),
wu@webrtc.org97077a32013-10-25 21:18:33 +0000131 trace_wrapper_(new FakeVoETraceWrapper()),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000132 engine_(new FakeVoEWrapper(&voe_),
wu@webrtc.org97077a32013-10-25 21:18:33 +0000133 trace_wrapper_),
Fredrik Solenbergccb49e72015-05-19 11:37:56 +0200134 channel_(NULL) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000135 options_conference_.conference_mode.Set(true);
136 options_adjust_agc_.adjust_agc_delta.Set(-10);
137 }
buildbot@webrtc.org150835e2014-05-06 15:54:38 +0000138 bool SetupEngineWithoutStream() {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000139 if (!engine_.Init(rtc::Thread::Current())) {
buildbot@webrtc.org150835e2014-05-06 15:54:38 +0000140 return false;
141 }
142 channel_ = engine_.CreateChannel();
143 return (channel_ != NULL);
144 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000145 bool SetupEngine() {
buildbot@webrtc.org150835e2014-05-06 15:54:38 +0000146 if (!SetupEngineWithoutStream()) {
147 return false;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000148 }
buildbot@webrtc.org150835e2014-05-06 15:54:38 +0000149 return channel_->AddSendStream(
150 cricket::StreamParams::CreateLegacy(kSsrc1));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000151 }
wu@webrtc.org9dba5252013-08-05 20:36:57 +0000152 void SetupForMultiSendStream() {
153 EXPECT_TRUE(SetupEngine());
154 // Remove stream added in Setup, which is corresponding to default channel.
155 int default_channel_num = voe_.GetLastChannel();
henrike@webrtc.org7666db72013-08-22 14:45:42 +0000156 uint32 default_send_ssrc = 0u;
wu@webrtc.org9dba5252013-08-05 20:36:57 +0000157 EXPECT_EQ(0, voe_.GetLocalSSRC(default_channel_num, default_send_ssrc));
158 EXPECT_EQ(kSsrc1, default_send_ssrc);
159 EXPECT_TRUE(channel_->RemoveSendStream(default_send_ssrc));
160
161 // Verify the default channel still exists.
162 EXPECT_EQ(0, voe_.GetLocalSSRC(default_channel_num, default_send_ssrc));
163 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000164 void DeliverPacket(const void* data, int len) {
Karl Wiberg94784372015-04-20 14:03:07 +0200165 rtc::Buffer packet(reinterpret_cast<const uint8_t*>(data), len);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000166 channel_->OnPacketReceived(&packet, rtc::PacketTime());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000167 }
Fredrik Solenbergaaf8ff22015-05-07 16:05:53 +0200168 void TearDown() override {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000169 delete channel_;
170 engine_.Terminate();
171 }
172
wu@webrtc.orgcadf9042013-08-30 21:24:16 +0000173 void TestInsertDtmf(uint32 ssrc, bool caller) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000174 EXPECT_TRUE(engine_.Init(rtc::Thread::Current()));
wu@webrtc.orgcadf9042013-08-30 21:24:16 +0000175 channel_ = engine_.CreateChannel();
176 EXPECT_TRUE(channel_ != NULL);
177 if (caller) {
178 // if this is a caller, local description will be applied and add the
179 // send stream.
180 EXPECT_TRUE(channel_->AddSendStream(
181 cricket::StreamParams::CreateLegacy(kSsrc1)));
182 }
183 int channel_id = voe_.GetLastChannel();
184
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000185 // Test we can only InsertDtmf when the other side supports telephone-event.
186 std::vector<cricket::AudioCodec> codecs;
187 codecs.push_back(kPcmuCodec);
188 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
189 EXPECT_TRUE(channel_->SetSend(cricket::SEND_MICROPHONE));
190 EXPECT_FALSE(channel_->CanInsertDtmf());
191 EXPECT_FALSE(channel_->InsertDtmf(ssrc, 1, 111, cricket::DF_SEND));
192 codecs.push_back(kTelephoneEventCodec);
193 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
194 EXPECT_TRUE(channel_->CanInsertDtmf());
wu@webrtc.orgcadf9042013-08-30 21:24:16 +0000195
196 if (!caller) {
197 // There's no active send channel yet.
198 EXPECT_FALSE(channel_->InsertDtmf(ssrc, 2, 123, cricket::DF_SEND));
199 EXPECT_TRUE(channel_->AddSendStream(
200 cricket::StreamParams::CreateLegacy(kSsrc1)));
201 }
202
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000203 // Check we fail if the ssrc is invalid.
204 EXPECT_FALSE(channel_->InsertDtmf(-1, 1, 111, cricket::DF_SEND));
205
206 // Test send
207 EXPECT_FALSE(voe_.WasSendTelephoneEventCalled(channel_id, 2, 123));
208 EXPECT_TRUE(channel_->InsertDtmf(ssrc, 2, 123, cricket::DF_SEND));
209 EXPECT_TRUE(voe_.WasSendTelephoneEventCalled(channel_id, 2, 123));
210
211 // Test play
212 EXPECT_FALSE(voe_.WasPlayDtmfToneCalled(3, 134));
213 EXPECT_TRUE(channel_->InsertDtmf(ssrc, 3, 134, cricket::DF_PLAY));
214 EXPECT_TRUE(voe_.WasPlayDtmfToneCalled(3, 134));
215
216 // Test send and play
217 EXPECT_FALSE(voe_.WasSendTelephoneEventCalled(channel_id, 4, 145));
218 EXPECT_FALSE(voe_.WasPlayDtmfToneCalled(4, 145));
219 EXPECT_TRUE(channel_->InsertDtmf(ssrc, 4, 145,
220 cricket::DF_PLAY | cricket::DF_SEND));
221 EXPECT_TRUE(voe_.WasSendTelephoneEventCalled(channel_id, 4, 145));
222 EXPECT_TRUE(voe_.WasPlayDtmfToneCalled(4, 145));
223 }
224
225 // Test that send bandwidth is set correctly.
226 // |codec| is the codec under test.
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000227 // |max_bitrate| is a parameter to set to SetMaxSendBandwidth().
228 // |expected_result| is the expected result from SetMaxSendBandwidth().
229 // |expected_bitrate| is the expected audio bitrate afterward.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000230 void TestSendBandwidth(const cricket::AudioCodec& codec,
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000231 int max_bitrate,
232 bool expected_result,
233 int expected_bitrate) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000234 int channel_num = voe_.GetLastChannel();
235 std::vector<cricket::AudioCodec> codecs;
236
237 codecs.push_back(codec);
238 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
239
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000240 bool result = channel_->SetMaxSendBandwidth(max_bitrate);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000241 EXPECT_EQ(expected_result, result);
242
wu@webrtc.org1d1ffc92013-10-16 18:12:02 +0000243 webrtc::CodecInst temp_codec;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000244 EXPECT_FALSE(voe_.GetSendCodec(channel_num, temp_codec));
245
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000246 EXPECT_EQ(expected_bitrate, temp_codec.rate);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000247 }
248
buildbot@webrtc.org150835e2014-05-06 15:54:38 +0000249 void TestSetSendRtpHeaderExtensions(const std::string& ext) {
250 EXPECT_TRUE(SetupEngineWithoutStream());
251 int channel_num = voe_.GetLastChannel();
wu@webrtc.org9dba5252013-08-05 20:36:57 +0000252
henrike@webrtc.org79047f92014-03-06 23:46:59 +0000253 // Ensure extensions are off by default.
buildbot@webrtc.org150835e2014-05-06 15:54:38 +0000254 EXPECT_EQ(-1, voe_.GetSendRtpExtensionId(channel_num, ext));
wu@webrtc.org9dba5252013-08-05 20:36:57 +0000255
buildbot@webrtc.org150835e2014-05-06 15:54:38 +0000256 std::vector<cricket::RtpHeaderExtension> extensions;
wu@webrtc.org9dba5252013-08-05 20:36:57 +0000257 // Ensure unknown extensions won't cause an error.
258 extensions.push_back(cricket::RtpHeaderExtension(
henrike@webrtc.org79047f92014-03-06 23:46:59 +0000259 "urn:ietf:params:unknownextention", 1));
wu@webrtc.org9dba5252013-08-05 20:36:57 +0000260 EXPECT_TRUE(channel_->SetSendRtpHeaderExtensions(extensions));
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
henrike@webrtc.org79047f92014-03-06 23:46:59 +0000263 // Ensure extensions stay off with an empty list of headers.
264 extensions.clear();
wu@webrtc.org9dba5252013-08-05 20:36:57 +0000265 EXPECT_TRUE(channel_->SetSendRtpHeaderExtensions(extensions));
buildbot@webrtc.org150835e2014-05-06 15:54:38 +0000266 EXPECT_EQ(-1, voe_.GetSendRtpExtensionId(channel_num, ext));
wu@webrtc.org9dba5252013-08-05 20:36:57 +0000267
buildbot@webrtc.org150835e2014-05-06 15:54:38 +0000268 // Ensure extension is set properly.
269 const int id = 1;
270 extensions.push_back(cricket::RtpHeaderExtension(ext, id));
wu@webrtc.org9dba5252013-08-05 20:36:57 +0000271 EXPECT_TRUE(channel_->SetSendRtpHeaderExtensions(extensions));
buildbot@webrtc.org150835e2014-05-06 15:54:38 +0000272 EXPECT_EQ(id, voe_.GetSendRtpExtensionId(channel_num, ext));
wu@webrtc.org9dba5252013-08-05 20:36:57 +0000273
buildbot@webrtc.org150835e2014-05-06 15:54:38 +0000274 // Ensure extension is set properly on new channel.
275 // The first stream to occupy the default channel.
276 EXPECT_TRUE(channel_->AddSendStream(
277 cricket::StreamParams::CreateLegacy(123)));
278 EXPECT_TRUE(channel_->AddSendStream(
279 cricket::StreamParams::CreateLegacy(234)));
280 int new_channel_num = voe_.GetLastChannel();
281 EXPECT_NE(channel_num, new_channel_num);
282 EXPECT_EQ(id, voe_.GetSendRtpExtensionId(new_channel_num, ext));
henrike@webrtc.org79047f92014-03-06 23:46:59 +0000283
284 // Ensure all extensions go back off with an empty list.
wu@webrtc.org9dba5252013-08-05 20:36:57 +0000285 extensions.clear();
286 EXPECT_TRUE(channel_->SetSendRtpHeaderExtensions(extensions));
buildbot@webrtc.org150835e2014-05-06 15:54:38 +0000287 EXPECT_EQ(-1, voe_.GetSendRtpExtensionId(channel_num, ext));
288 EXPECT_EQ(-1, voe_.GetSendRtpExtensionId(new_channel_num, ext));
henrike@webrtc.org79047f92014-03-06 23:46:59 +0000289 }
290
buildbot@webrtc.org150835e2014-05-06 15:54:38 +0000291 void TestSetRecvRtpHeaderExtensions(const std::string& ext) {
292 EXPECT_TRUE(SetupEngineWithoutStream());
293 int channel_num = voe_.GetLastChannel();
henrike@webrtc.org79047f92014-03-06 23:46:59 +0000294
henrike@webrtc.org79047f92014-03-06 23:46:59 +0000295 // Ensure extensions are off by default.
buildbot@webrtc.org150835e2014-05-06 15:54:38 +0000296 EXPECT_EQ(-1, voe_.GetReceiveRtpExtensionId(channel_num, ext));
henrike@webrtc.org79047f92014-03-06 23:46:59 +0000297
buildbot@webrtc.org150835e2014-05-06 15:54:38 +0000298 std::vector<cricket::RtpHeaderExtension> extensions;
henrike@webrtc.org79047f92014-03-06 23:46:59 +0000299 // Ensure unknown extensions won't cause an error.
300 extensions.push_back(cricket::RtpHeaderExtension(
301 "urn:ietf:params:unknownextention", 1));
302 EXPECT_TRUE(channel_->SetRecvRtpHeaderExtensions(extensions));
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 // Ensure extensions stay off with an empty list of headers.
henrike@webrtc.org79047f92014-03-06 23:46:59 +0000306 extensions.clear();
307 EXPECT_TRUE(channel_->SetRecvRtpHeaderExtensions(extensions));
buildbot@webrtc.org150835e2014-05-06 15:54:38 +0000308 EXPECT_EQ(-1, voe_.GetReceiveRtpExtensionId(channel_num, ext));
henrike@webrtc.org79047f92014-03-06 23:46:59 +0000309
buildbot@webrtc.org150835e2014-05-06 15:54:38 +0000310 // Ensure extension is set properly.
311 const int id = 2;
312 extensions.push_back(cricket::RtpHeaderExtension(ext, id));
henrike@webrtc.org79047f92014-03-06 23:46:59 +0000313 EXPECT_TRUE(channel_->SetRecvRtpHeaderExtensions(extensions));
buildbot@webrtc.org150835e2014-05-06 15:54:38 +0000314 EXPECT_EQ(id, voe_.GetReceiveRtpExtensionId(channel_num, ext));
henrike@webrtc.org79047f92014-03-06 23:46:59 +0000315
buildbot@webrtc.org150835e2014-05-06 15:54:38 +0000316 // Ensure extension is set properly on new channel.
317 // The first stream to occupy the default channel.
318 EXPECT_TRUE(channel_->AddRecvStream(
319 cricket::StreamParams::CreateLegacy(345)));
320 EXPECT_TRUE(channel_->AddRecvStream(
321 cricket::StreamParams::CreateLegacy(456)));
322 int new_channel_num = voe_.GetLastChannel();
323 EXPECT_NE(channel_num, new_channel_num);
324 EXPECT_EQ(id, voe_.GetReceiveRtpExtensionId(new_channel_num, ext));
325
326 // Ensure all extensions go back off with an empty list.
henrike@webrtc.org79047f92014-03-06 23:46:59 +0000327 extensions.clear();
328 EXPECT_TRUE(channel_->SetRecvRtpHeaderExtensions(extensions));
buildbot@webrtc.org150835e2014-05-06 15:54:38 +0000329 EXPECT_EQ(-1, voe_.GetReceiveRtpExtensionId(channel_num, ext));
330 EXPECT_EQ(-1, voe_.GetReceiveRtpExtensionId(new_channel_num, ext));
wu@webrtc.org9dba5252013-08-05 20:36:57 +0000331 }
332
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000333 protected:
334 cricket::FakeWebRtcVoiceEngine voe_;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000335 FakeVoETraceWrapper* trace_wrapper_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000336 cricket::WebRtcVoiceEngine engine_;
337 cricket::VoiceMediaChannel* channel_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000338
339 cricket::AudioOptions options_conference_;
340 cricket::AudioOptions options_adjust_agc_;
341};
342
343// Tests that our stub library "works".
344TEST_F(WebRtcVoiceEngineTestFake, StartupShutdown) {
345 EXPECT_FALSE(voe_.IsInited());
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000346 EXPECT_TRUE(engine_.Init(rtc::Thread::Current()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000347 EXPECT_TRUE(voe_.IsInited());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000348 engine_.Terminate();
349 EXPECT_FALSE(voe_.IsInited());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000350}
351
352// Tests that we can create and destroy a channel.
353TEST_F(WebRtcVoiceEngineTestFake, CreateChannel) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000354 EXPECT_TRUE(engine_.Init(rtc::Thread::Current()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000355 channel_ = engine_.CreateChannel();
356 EXPECT_TRUE(channel_ != NULL);
357}
358
359// Tests that we properly handle failures in CreateChannel.
360TEST_F(WebRtcVoiceEngineTestFake, CreateChannelFail) {
361 voe_.set_fail_create_channel(true);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000362 EXPECT_TRUE(engine_.Init(rtc::Thread::Current()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000363 channel_ = engine_.CreateChannel();
364 EXPECT_TRUE(channel_ == NULL);
365}
366
367// Tests that the list of supported codecs is created properly and ordered
368// correctly
369TEST_F(WebRtcVoiceEngineTestFake, CodecPreference) {
370 const std::vector<cricket::AudioCodec>& codecs = engine_.codecs();
371 ASSERT_FALSE(codecs.empty());
372 EXPECT_STRCASEEQ("opus", codecs[0].name.c_str());
373 EXPECT_EQ(48000, codecs[0].clockrate);
374 EXPECT_EQ(2, codecs[0].channels);
375 EXPECT_EQ(64000, codecs[0].bitrate);
376 int pref = codecs[0].preference;
377 for (size_t i = 1; i < codecs.size(); ++i) {
378 EXPECT_GT(pref, codecs[i].preference);
379 pref = codecs[i].preference;
380 }
381}
382
383// Tests that we can find codecs by name or id, and that we interpret the
384// clockrate and bitrate fields properly.
385TEST_F(WebRtcVoiceEngineTestFake, FindCodec) {
386 cricket::AudioCodec codec;
387 webrtc::CodecInst codec_inst;
388 // Find PCMU with explicit clockrate and bitrate.
389 EXPECT_TRUE(engine_.FindWebRtcCodec(kPcmuCodec, &codec_inst));
390 // Find ISAC with explicit clockrate and 0 bitrate.
391 EXPECT_TRUE(engine_.FindWebRtcCodec(kIsacCodec, &codec_inst));
392 // Find telephone-event with explicit clockrate and 0 bitrate.
393 EXPECT_TRUE(engine_.FindWebRtcCodec(kTelephoneEventCodec, &codec_inst));
394 // Find ISAC with a different payload id.
395 codec = kIsacCodec;
396 codec.id = 127;
397 EXPECT_TRUE(engine_.FindWebRtcCodec(codec, &codec_inst));
398 EXPECT_EQ(codec.id, codec_inst.pltype);
399 // Find PCMU with a 0 clockrate.
400 codec = kPcmuCodec;
401 codec.clockrate = 0;
402 EXPECT_TRUE(engine_.FindWebRtcCodec(codec, &codec_inst));
403 EXPECT_EQ(codec.id, codec_inst.pltype);
404 EXPECT_EQ(8000, codec_inst.plfreq);
405 // Find PCMU with a 0 bitrate.
406 codec = kPcmuCodec;
407 codec.bitrate = 0;
408 EXPECT_TRUE(engine_.FindWebRtcCodec(codec, &codec_inst));
409 EXPECT_EQ(codec.id, codec_inst.pltype);
410 EXPECT_EQ(64000, codec_inst.rate);
411 // Find ISAC with an explicit bitrate.
412 codec = kIsacCodec;
413 codec.bitrate = 32000;
414 EXPECT_TRUE(engine_.FindWebRtcCodec(codec, &codec_inst));
415 EXPECT_EQ(codec.id, codec_inst.pltype);
416 EXPECT_EQ(32000, codec_inst.rate);
417}
418
419// Test that we set our inbound codecs properly, including changing PT.
420TEST_F(WebRtcVoiceEngineTestFake, SetRecvCodecs) {
421 EXPECT_TRUE(SetupEngine());
422 int channel_num = voe_.GetLastChannel();
423 std::vector<cricket::AudioCodec> codecs;
424 codecs.push_back(kIsacCodec);
425 codecs.push_back(kPcmuCodec);
426 codecs.push_back(kTelephoneEventCodec);
427 codecs[0].id = 106; // collide with existing telephone-event
428 codecs[2].id = 126;
429 EXPECT_TRUE(channel_->SetRecvCodecs(codecs));
430 webrtc::CodecInst gcodec;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000431 rtc::strcpyn(gcodec.plname, ARRAY_SIZE(gcodec.plname), "ISAC");
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000432 gcodec.plfreq = 16000;
433 gcodec.channels = 1;
434 EXPECT_EQ(0, voe_.GetRecPayloadType(channel_num, gcodec));
435 EXPECT_EQ(106, gcodec.pltype);
436 EXPECT_STREQ("ISAC", gcodec.plname);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000437 rtc::strcpyn(gcodec.plname, ARRAY_SIZE(gcodec.plname),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000438 "telephone-event");
439 gcodec.plfreq = 8000;
440 EXPECT_EQ(0, voe_.GetRecPayloadType(channel_num, gcodec));
441 EXPECT_EQ(126, gcodec.pltype);
442 EXPECT_STREQ("telephone-event", gcodec.plname);
443}
444
445// Test that we fail to set an unknown inbound codec.
446TEST_F(WebRtcVoiceEngineTestFake, SetRecvCodecsUnsupportedCodec) {
447 EXPECT_TRUE(SetupEngine());
448 std::vector<cricket::AudioCodec> codecs;
449 codecs.push_back(kIsacCodec);
450 codecs.push_back(cricket::AudioCodec(127, "XYZ", 32000, 0, 1, 0));
451 EXPECT_FALSE(channel_->SetRecvCodecs(codecs));
452}
453
454// Test that we fail if we have duplicate types in the inbound list.
455TEST_F(WebRtcVoiceEngineTestFake, SetRecvCodecsDuplicatePayloadType) {
456 EXPECT_TRUE(SetupEngine());
457 std::vector<cricket::AudioCodec> codecs;
458 codecs.push_back(kIsacCodec);
459 codecs.push_back(kCn16000Codec);
460 codecs[1].id = kIsacCodec.id;
461 EXPECT_FALSE(channel_->SetRecvCodecs(codecs));
462}
463
464// Test that we can decode OPUS without stereo parameters.
465TEST_F(WebRtcVoiceEngineTestFake, SetRecvCodecsWithOpusNoStereo) {
466 EXPECT_TRUE(SetupEngine());
467 EXPECT_TRUE(channel_->SetOptions(options_conference_));
468 std::vector<cricket::AudioCodec> codecs;
469 codecs.push_back(kIsacCodec);
470 codecs.push_back(kPcmuCodec);
471 codecs.push_back(kOpusCodec);
472 EXPECT_TRUE(channel_->SetRecvCodecs(codecs));
473 EXPECT_TRUE(channel_->AddRecvStream(
474 cricket::StreamParams::CreateLegacy(kSsrc1)));
475 int channel_num2 = voe_.GetLastChannel();
476 webrtc::CodecInst opus;
477 engine_.FindWebRtcCodec(kOpusCodec, &opus);
478 // Even without stereo parameters, recv codecs still specify channels = 2.
479 EXPECT_EQ(2, opus.channels);
480 EXPECT_EQ(111, opus.pltype);
481 EXPECT_STREQ("opus", opus.plname);
482 opus.pltype = 0;
483 EXPECT_EQ(0, voe_.GetRecPayloadType(channel_num2, opus));
484 EXPECT_EQ(111, opus.pltype);
485}
486
487// Test that we can decode OPUS with stereo = 0.
488TEST_F(WebRtcVoiceEngineTestFake, SetRecvCodecsWithOpus0Stereo) {
489 EXPECT_TRUE(SetupEngine());
490 EXPECT_TRUE(channel_->SetOptions(options_conference_));
491 std::vector<cricket::AudioCodec> codecs;
492 codecs.push_back(kIsacCodec);
493 codecs.push_back(kPcmuCodec);
494 codecs.push_back(kOpusCodec);
495 codecs[2].params["stereo"] = "0";
496 EXPECT_TRUE(channel_->SetRecvCodecs(codecs));
497 EXPECT_TRUE(channel_->AddRecvStream(
498 cricket::StreamParams::CreateLegacy(kSsrc1)));
499 int channel_num2 = voe_.GetLastChannel();
500 webrtc::CodecInst opus;
501 engine_.FindWebRtcCodec(kOpusCodec, &opus);
502 // Even when stereo is off, recv codecs still specify channels = 2.
503 EXPECT_EQ(2, opus.channels);
504 EXPECT_EQ(111, opus.pltype);
505 EXPECT_STREQ("opus", opus.plname);
506 opus.pltype = 0;
507 EXPECT_EQ(0, voe_.GetRecPayloadType(channel_num2, opus));
508 EXPECT_EQ(111, opus.pltype);
509}
510
511// Test that we can decode OPUS with stereo = 1.
512TEST_F(WebRtcVoiceEngineTestFake, SetRecvCodecsWithOpus1Stereo) {
513 EXPECT_TRUE(SetupEngine());
514 EXPECT_TRUE(channel_->SetOptions(options_conference_));
515 std::vector<cricket::AudioCodec> codecs;
516 codecs.push_back(kIsacCodec);
517 codecs.push_back(kPcmuCodec);
518 codecs.push_back(kOpusCodec);
519 codecs[2].params["stereo"] = "1";
520 EXPECT_TRUE(channel_->SetRecvCodecs(codecs));
521 EXPECT_TRUE(channel_->AddRecvStream(
522 cricket::StreamParams::CreateLegacy(kSsrc1)));
523 int channel_num2 = voe_.GetLastChannel();
524 webrtc::CodecInst opus;
525 engine_.FindWebRtcCodec(kOpusCodec, &opus);
526 EXPECT_EQ(2, opus.channels);
527 EXPECT_EQ(111, opus.pltype);
528 EXPECT_STREQ("opus", opus.plname);
529 opus.pltype = 0;
530 EXPECT_EQ(0, voe_.GetRecPayloadType(channel_num2, opus));
531 EXPECT_EQ(111, opus.pltype);
532}
533
534// Test that changes to recv codecs are applied to all streams.
535TEST_F(WebRtcVoiceEngineTestFake, SetRecvCodecsWithMultipleStreams) {
536 EXPECT_TRUE(SetupEngine());
537 EXPECT_TRUE(channel_->SetOptions(options_conference_));
538 std::vector<cricket::AudioCodec> codecs;
539 codecs.push_back(kIsacCodec);
540 codecs.push_back(kPcmuCodec);
541 codecs.push_back(kTelephoneEventCodec);
542 codecs[0].id = 106; // collide with existing telephone-event
543 codecs[2].id = 126;
544 EXPECT_TRUE(channel_->SetRecvCodecs(codecs));
545 EXPECT_TRUE(channel_->AddRecvStream(
546 cricket::StreamParams::CreateLegacy(kSsrc1)));
547 int channel_num2 = voe_.GetLastChannel();
548 webrtc::CodecInst gcodec;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000549 rtc::strcpyn(gcodec.plname, ARRAY_SIZE(gcodec.plname), "ISAC");
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000550 gcodec.plfreq = 16000;
551 gcodec.channels = 1;
552 EXPECT_EQ(0, voe_.GetRecPayloadType(channel_num2, gcodec));
553 EXPECT_EQ(106, gcodec.pltype);
554 EXPECT_STREQ("ISAC", gcodec.plname);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000555 rtc::strcpyn(gcodec.plname, ARRAY_SIZE(gcodec.plname),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000556 "telephone-event");
557 gcodec.plfreq = 8000;
558 gcodec.channels = 1;
559 EXPECT_EQ(0, voe_.GetRecPayloadType(channel_num2, gcodec));
560 EXPECT_EQ(126, gcodec.pltype);
561 EXPECT_STREQ("telephone-event", gcodec.plname);
562}
563
564TEST_F(WebRtcVoiceEngineTestFake, SetRecvCodecsAfterAddingStreams) {
565 EXPECT_TRUE(SetupEngine());
566 EXPECT_TRUE(channel_->SetOptions(options_conference_));
567 std::vector<cricket::AudioCodec> codecs;
568 codecs.push_back(kIsacCodec);
569 codecs[0].id = 106; // collide with existing telephone-event
570
571 EXPECT_TRUE(channel_->AddRecvStream(
572 cricket::StreamParams::CreateLegacy(kSsrc1)));
573 EXPECT_TRUE(channel_->SetRecvCodecs(codecs));
574
575 int channel_num2 = voe_.GetLastChannel();
576 webrtc::CodecInst gcodec;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000577 rtc::strcpyn(gcodec.plname, ARRAY_SIZE(gcodec.plname), "ISAC");
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000578 gcodec.plfreq = 16000;
579 gcodec.channels = 1;
580 EXPECT_EQ(0, voe_.GetRecPayloadType(channel_num2, gcodec));
581 EXPECT_EQ(106, gcodec.pltype);
582 EXPECT_STREQ("ISAC", gcodec.plname);
583}
584
585// Test that we can apply the same set of codecs again while playing.
586TEST_F(WebRtcVoiceEngineTestFake, SetRecvCodecsWhilePlaying) {
587 EXPECT_TRUE(SetupEngine());
588 int channel_num = voe_.GetLastChannel();
589 std::vector<cricket::AudioCodec> codecs;
590 codecs.push_back(kIsacCodec);
591 codecs.push_back(kCn16000Codec);
592 EXPECT_TRUE(channel_->SetRecvCodecs(codecs));
593 EXPECT_TRUE(channel_->SetPlayout(true));
594 EXPECT_TRUE(channel_->SetRecvCodecs(codecs));
595
596 // Changing the payload type of a codec should fail.
597 codecs[0].id = 127;
598 EXPECT_FALSE(channel_->SetRecvCodecs(codecs));
599 EXPECT_TRUE(voe_.GetPlayout(channel_num));
600}
601
602// Test that we can add a codec while playing.
603TEST_F(WebRtcVoiceEngineTestFake, AddRecvCodecsWhilePlaying) {
604 EXPECT_TRUE(SetupEngine());
605 int channel_num = voe_.GetLastChannel();
606 std::vector<cricket::AudioCodec> codecs;
607 codecs.push_back(kIsacCodec);
608 codecs.push_back(kCn16000Codec);
609 EXPECT_TRUE(channel_->SetRecvCodecs(codecs));
610 EXPECT_TRUE(channel_->SetPlayout(true));
611
612 codecs.push_back(kOpusCodec);
613 EXPECT_TRUE(channel_->SetRecvCodecs(codecs));
614 EXPECT_TRUE(voe_.GetPlayout(channel_num));
615 webrtc::CodecInst gcodec;
616 EXPECT_TRUE(engine_.FindWebRtcCodec(kOpusCodec, &gcodec));
617 EXPECT_EQ(kOpusCodec.id, gcodec.pltype);
618}
619
620TEST_F(WebRtcVoiceEngineTestFake, SetSendBandwidthAuto) {
621 EXPECT_TRUE(SetupEngine());
622 EXPECT_TRUE(channel_->SetSendCodecs(engine_.codecs()));
623
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000624 // Test that when autobw is enabled, bitrate is kept as the default
625 // value. autobw is enabled for the following tests because the target
626 // bitrate is <= 0.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000627
628 // ISAC, default bitrate == 32000.
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000629 TestSendBandwidth(kIsacCodec, 0, true, 32000);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000630
631 // PCMU, default bitrate == 64000.
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000632 TestSendBandwidth(kPcmuCodec, -1, true, 64000);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000633
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000634 // opus, default bitrate == 64000.
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000635 TestSendBandwidth(kOpusCodec, -1, true, 64000);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000636}
637
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000638TEST_F(WebRtcVoiceEngineTestFake, SetMaxSendBandwidthMultiRateAsCaller) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000639 EXPECT_TRUE(SetupEngine());
640 EXPECT_TRUE(channel_->SetSendCodecs(engine_.codecs()));
641
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000642 // Test that the bitrate of a multi-rate codec is always the maximum.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000643
644 // ISAC, default bitrate == 32000.
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000645 TestSendBandwidth(kIsacCodec, 128000, true, 128000);
646 TestSendBandwidth(kIsacCodec, 16000, true, 16000);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000647
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000648 // opus, default bitrate == 64000.
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000649 TestSendBandwidth(kOpusCodec, 96000, true, 96000);
650 TestSendBandwidth(kOpusCodec, 48000, true, 48000);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000651}
652
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000653TEST_F(WebRtcVoiceEngineTestFake, SetMaxSendBandwidthFixedRateAsCaller) {
654 EXPECT_TRUE(SetupEngine());
655 EXPECT_TRUE(channel_->SetSendCodecs(engine_.codecs()));
656
657 // Test that we can only set a maximum bitrate for a fixed-rate codec
658 // if it's bigger than the fixed rate.
659
660 // PCMU, fixed bitrate == 64000.
661 TestSendBandwidth(kPcmuCodec, 0, true, 64000);
662 TestSendBandwidth(kPcmuCodec, 1, false, 64000);
663 TestSendBandwidth(kPcmuCodec, 128000, true, 64000);
664 TestSendBandwidth(kPcmuCodec, 32000, false, 64000);
665 TestSendBandwidth(kPcmuCodec, 64000, true, 64000);
666 TestSendBandwidth(kPcmuCodec, 63999, false, 64000);
667 TestSendBandwidth(kPcmuCodec, 64001, true, 64000);
668}
669
670TEST_F(WebRtcVoiceEngineTestFake, SetMaxSendBandwidthMultiRateAsCallee) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000671 EXPECT_TRUE(engine_.Init(rtc::Thread::Current()));
wu@webrtc.org1d1ffc92013-10-16 18:12:02 +0000672 channel_ = engine_.CreateChannel();
673 EXPECT_TRUE(channel_ != NULL);
674 EXPECT_TRUE(channel_->SetSendCodecs(engine_.codecs()));
675
676 int desired_bitrate = 128000;
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000677 EXPECT_TRUE(channel_->SetMaxSendBandwidth(desired_bitrate));
wu@webrtc.org1d1ffc92013-10-16 18:12:02 +0000678
679 EXPECT_TRUE(channel_->AddSendStream(
680 cricket::StreamParams::CreateLegacy(kSsrc1)));
681
682 int channel_num = voe_.GetLastChannel();
683 webrtc::CodecInst codec;
684 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, codec));
685 EXPECT_EQ(desired_bitrate, codec.rate);
686}
687
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000688// Test that bitrate cannot be set for CBR codecs.
689// Bitrate is ignored if it is higher than the fixed bitrate.
690// Bitrate less then the fixed bitrate is an error.
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000691TEST_F(WebRtcVoiceEngineTestFake, SetMaxSendBandwidthCbr) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000692 EXPECT_TRUE(SetupEngine());
693 EXPECT_TRUE(channel_->SetSendCodecs(engine_.codecs()));
694
695 webrtc::CodecInst codec;
696 int channel_num = voe_.GetLastChannel();
697 std::vector<cricket::AudioCodec> codecs;
698
699 // PCMU, default bitrate == 64000.
700 codecs.push_back(kPcmuCodec);
701 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
702 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, codec));
703 EXPECT_EQ(64000, codec.rate);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000704 EXPECT_TRUE(channel_->SetMaxSendBandwidth(128000));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000705 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, codec));
706 EXPECT_EQ(64000, codec.rate);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000707 EXPECT_FALSE(channel_->SetMaxSendBandwidth(128));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000708 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, codec));
709 EXPECT_EQ(64000, codec.rate);
710}
711
712// Test that we apply codecs properly.
713TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecs) {
714 EXPECT_TRUE(SetupEngine());
715 int channel_num = voe_.GetLastChannel();
716 std::vector<cricket::AudioCodec> codecs;
717 codecs.push_back(kIsacCodec);
718 codecs.push_back(kPcmuCodec);
719 codecs.push_back(kRedCodec);
720 codecs[0].id = 96;
721 codecs[0].bitrate = 48000;
722 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
wu@webrtc.org05e7b442014-04-01 17:44:24 +0000723 EXPECT_EQ(1, voe_.GetNumSetSendCodecs());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000724 webrtc::CodecInst gcodec;
725 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
726 EXPECT_EQ(96, gcodec.pltype);
727 EXPECT_EQ(48000, gcodec.rate);
728 EXPECT_STREQ("ISAC", gcodec.plname);
729 EXPECT_FALSE(voe_.GetVAD(channel_num));
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +0000730 EXPECT_FALSE(voe_.GetRED(channel_num));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000731 EXPECT_EQ(13, voe_.GetSendCNPayloadType(channel_num, false));
732 EXPECT_EQ(105, voe_.GetSendCNPayloadType(channel_num, true));
733 EXPECT_EQ(106, voe_.GetSendTelephoneEventPayloadType(channel_num));
734}
735
wu@webrtc.org05e7b442014-04-01 17:44:24 +0000736// Test that VoE Channel doesn't call SetSendCodec again if same codec is tried
737// to apply.
738TEST_F(WebRtcVoiceEngineTestFake, DontResetSetSendCodec) {
739 EXPECT_TRUE(SetupEngine());
740 std::vector<cricket::AudioCodec> codecs;
741 codecs.push_back(kIsacCodec);
742 codecs.push_back(kPcmuCodec);
743 codecs.push_back(kRedCodec);
744 codecs[0].id = 96;
745 codecs[0].bitrate = 48000;
746 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
747 EXPECT_EQ(1, voe_.GetNumSetSendCodecs());
748 // Calling SetSendCodec again with same codec which is already set.
749 // In this case media channel shouldn't send codec to VoE.
750 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
751 EXPECT_EQ(1, voe_.GetNumSetSendCodecs());
752}
753
henrik.lundin@webrtc.orgf85dbce2014-11-07 12:25:00 +0000754// Verify that G722 is set with 16000 samples per second to WebRTC.
755TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecG722) {
756 EXPECT_TRUE(SetupEngine());
757 int channel_num = voe_.GetLastChannel();
758 std::vector<cricket::AudioCodec> codecs;
759 codecs.push_back(kG722CodecSdp);
760 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
761 webrtc::CodecInst gcodec;
762 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
763 EXPECT_STREQ("G722", gcodec.plname);
764 EXPECT_EQ(1, gcodec.channels);
765 EXPECT_EQ(16000, gcodec.plfreq);
766}
767
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000768// Test that if clockrate is not 48000 for opus, we fail.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000769TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecOpusBadClockrate) {
770 EXPECT_TRUE(SetupEngine());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000771 std::vector<cricket::AudioCodec> codecs;
772 codecs.push_back(kOpusCodec);
773 codecs[0].bitrate = 0;
774 codecs[0].clockrate = 50000;
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000775 EXPECT_FALSE(channel_->SetSendCodecs(codecs));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000776}
777
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000778// Test that if channels=0 for opus, we fail.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000779TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecOpusBad0ChannelsNoStereo) {
780 EXPECT_TRUE(SetupEngine());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000781 std::vector<cricket::AudioCodec> codecs;
782 codecs.push_back(kOpusCodec);
783 codecs[0].bitrate = 0;
784 codecs[0].channels = 0;
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000785 EXPECT_FALSE(channel_->SetSendCodecs(codecs));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000786}
787
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000788// Test that if channels=0 for opus, we fail.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000789TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecOpusBad0Channels1Stereo) {
790 EXPECT_TRUE(SetupEngine());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000791 std::vector<cricket::AudioCodec> codecs;
792 codecs.push_back(kOpusCodec);
793 codecs[0].bitrate = 0;
794 codecs[0].channels = 0;
795 codecs[0].params["stereo"] = "1";
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000796 EXPECT_FALSE(channel_->SetSendCodecs(codecs));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000797}
798
799// Test that if channel is 1 for opus and there's no stereo, we fail.
800TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecOpus1ChannelNoStereo) {
801 EXPECT_TRUE(SetupEngine());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000802 std::vector<cricket::AudioCodec> codecs;
803 codecs.push_back(kOpusCodec);
804 codecs[0].bitrate = 0;
805 codecs[0].channels = 1;
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000806 EXPECT_FALSE(channel_->SetSendCodecs(codecs));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000807}
808
809// Test that if channel is 1 for opus and stereo=0, we fail.
810TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecOpusBad1Channel0Stereo) {
811 EXPECT_TRUE(SetupEngine());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000812 std::vector<cricket::AudioCodec> codecs;
813 codecs.push_back(kOpusCodec);
814 codecs[0].bitrate = 0;
815 codecs[0].channels = 1;
816 codecs[0].params["stereo"] = "0";
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000817 EXPECT_FALSE(channel_->SetSendCodecs(codecs));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000818}
819
820// Test that if channel is 1 for opus and stereo=1, we fail.
821TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecOpusBad1Channel1Stereo) {
822 EXPECT_TRUE(SetupEngine());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000823 std::vector<cricket::AudioCodec> codecs;
824 codecs.push_back(kOpusCodec);
825 codecs[0].bitrate = 0;
826 codecs[0].channels = 1;
827 codecs[0].params["stereo"] = "1";
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000828 EXPECT_FALSE(channel_->SetSendCodecs(codecs));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000829}
830
831// Test that with bitrate=0 and no stereo,
832// channels and bitrate are 1 and 32000.
833TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecOpusGood0BitrateNoStereo) {
834 EXPECT_TRUE(SetupEngine());
835 int channel_num = voe_.GetLastChannel();
836 std::vector<cricket::AudioCodec> codecs;
837 codecs.push_back(kOpusCodec);
838 codecs[0].bitrate = 0;
839 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
840 webrtc::CodecInst gcodec;
841 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
842 EXPECT_STREQ("opus", gcodec.plname);
843 EXPECT_EQ(1, gcodec.channels);
844 EXPECT_EQ(32000, gcodec.rate);
845}
846
847// Test that with bitrate=0 and stereo=0,
848// channels and bitrate are 1 and 32000.
849TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecOpusGood0Bitrate0Stereo) {
850 EXPECT_TRUE(SetupEngine());
851 int channel_num = voe_.GetLastChannel();
852 std::vector<cricket::AudioCodec> codecs;
853 codecs.push_back(kOpusCodec);
854 codecs[0].bitrate = 0;
855 codecs[0].params["stereo"] = "0";
856 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
857 webrtc::CodecInst gcodec;
858 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
859 EXPECT_STREQ("opus", gcodec.plname);
860 EXPECT_EQ(1, gcodec.channels);
861 EXPECT_EQ(32000, gcodec.rate);
862}
863
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000864// Test that with bitrate=invalid and stereo=0,
865// channels and bitrate are 1 and 32000.
866TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecOpusGoodXBitrate0Stereo) {
867 EXPECT_TRUE(SetupEngine());
868 int channel_num = voe_.GetLastChannel();
869 std::vector<cricket::AudioCodec> codecs;
870 codecs.push_back(kOpusCodec);
871 codecs[0].params["stereo"] = "0";
872 webrtc::CodecInst gcodec;
873
buildbot@webrtc.org9d446f22014-10-23 12:22:06 +0000874 // bitrate that's out of the range between 6000 and 510000 will be clamped.
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000875 codecs[0].bitrate = 5999;
876 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
877 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
878 EXPECT_STREQ("opus", gcodec.plname);
879 EXPECT_EQ(1, gcodec.channels);
buildbot@webrtc.org9d446f22014-10-23 12:22:06 +0000880 EXPECT_EQ(6000, gcodec.rate);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000881
882 codecs[0].bitrate = 510001;
883 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
884 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
885 EXPECT_STREQ("opus", gcodec.plname);
886 EXPECT_EQ(1, gcodec.channels);
buildbot@webrtc.org9d446f22014-10-23 12:22:06 +0000887 EXPECT_EQ(510000, gcodec.rate);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000888}
889
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000890// Test that with bitrate=0 and stereo=1,
891// channels and bitrate are 2 and 64000.
892TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecOpusGood0Bitrate1Stereo) {
893 EXPECT_TRUE(SetupEngine());
894 int channel_num = voe_.GetLastChannel();
895 std::vector<cricket::AudioCodec> codecs;
896 codecs.push_back(kOpusCodec);
897 codecs[0].bitrate = 0;
898 codecs[0].params["stereo"] = "1";
899 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
900 webrtc::CodecInst gcodec;
901 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
902 EXPECT_STREQ("opus", gcodec.plname);
903 EXPECT_EQ(2, gcodec.channels);
904 EXPECT_EQ(64000, gcodec.rate);
905}
906
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000907// Test that with bitrate=invalid and stereo=1,
908// channels and bitrate are 2 and 64000.
909TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecOpusGoodXBitrate1Stereo) {
910 EXPECT_TRUE(SetupEngine());
911 int channel_num = voe_.GetLastChannel();
912 std::vector<cricket::AudioCodec> codecs;
913 codecs.push_back(kOpusCodec);
914 codecs[0].params["stereo"] = "1";
915 webrtc::CodecInst gcodec;
916
buildbot@webrtc.org9d446f22014-10-23 12:22:06 +0000917 // bitrate that's out of the range between 6000 and 510000 will be clamped.
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000918 codecs[0].bitrate = 5999;
919 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
920 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
921 EXPECT_STREQ("opus", gcodec.plname);
922 EXPECT_EQ(2, gcodec.channels);
buildbot@webrtc.org9d446f22014-10-23 12:22:06 +0000923 EXPECT_EQ(6000, gcodec.rate);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000924
925 codecs[0].bitrate = 510001;
926 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
927 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
928 EXPECT_STREQ("opus", gcodec.plname);
929 EXPECT_EQ(2, gcodec.channels);
buildbot@webrtc.org9d446f22014-10-23 12:22:06 +0000930 EXPECT_EQ(510000, gcodec.rate);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000931}
932
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000933// Test that with bitrate=N and stereo unset,
934// channels and bitrate are 1 and N.
935TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecOpusGoodNBitrateNoStereo) {
936 EXPECT_TRUE(SetupEngine());
937 int channel_num = voe_.GetLastChannel();
938 std::vector<cricket::AudioCodec> codecs;
939 codecs.push_back(kOpusCodec);
940 codecs[0].bitrate = 96000;
941 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
942 webrtc::CodecInst gcodec;
943 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
944 EXPECT_EQ(111, gcodec.pltype);
945 EXPECT_EQ(96000, gcodec.rate);
946 EXPECT_STREQ("opus", gcodec.plname);
947 EXPECT_EQ(1, gcodec.channels);
948 EXPECT_EQ(48000, gcodec.plfreq);
949}
950
951// Test that with bitrate=N and stereo=0,
952// channels and bitrate are 1 and N.
953TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecOpusGoodNBitrate0Stereo) {
954 EXPECT_TRUE(SetupEngine());
955 int channel_num = voe_.GetLastChannel();
956 std::vector<cricket::AudioCodec> codecs;
957 codecs.push_back(kOpusCodec);
958 codecs[0].bitrate = 30000;
959 codecs[0].params["stereo"] = "0";
960 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
961 webrtc::CodecInst gcodec;
962 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
963 EXPECT_EQ(1, gcodec.channels);
964 EXPECT_EQ(30000, gcodec.rate);
965 EXPECT_STREQ("opus", gcodec.plname);
966}
967
968// Test that with bitrate=N and without any parameters,
969// channels and bitrate are 1 and N.
970TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecOpusGoodNBitrateNoParameters) {
971 EXPECT_TRUE(SetupEngine());
972 int channel_num = voe_.GetLastChannel();
973 std::vector<cricket::AudioCodec> codecs;
974 codecs.push_back(kOpusCodec);
975 codecs[0].bitrate = 30000;
976 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
977 webrtc::CodecInst gcodec;
978 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
979 EXPECT_EQ(1, gcodec.channels);
980 EXPECT_EQ(30000, gcodec.rate);
981 EXPECT_STREQ("opus", gcodec.plname);
982}
983
984// Test that with bitrate=N and stereo=1,
985// channels and bitrate are 2 and N.
986TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecOpusGoodNBitrate1Stereo) {
987 EXPECT_TRUE(SetupEngine());
988 int channel_num = voe_.GetLastChannel();
989 std::vector<cricket::AudioCodec> codecs;
990 codecs.push_back(kOpusCodec);
991 codecs[0].bitrate = 30000;
992 codecs[0].params["stereo"] = "1";
993 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
994 webrtc::CodecInst gcodec;
995 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
996 EXPECT_EQ(2, gcodec.channels);
997 EXPECT_EQ(30000, gcodec.rate);
998 EXPECT_STREQ("opus", gcodec.plname);
999}
1000
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00001001// Test that bitrate will be overridden by the "maxaveragebitrate" parameter.
1002// Also test that the "maxaveragebitrate" can't be set to values outside the
1003// range of 6000 and 510000
1004TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecOpusMaxAverageBitrate) {
1005 EXPECT_TRUE(SetupEngine());
1006 int channel_num = voe_.GetLastChannel();
1007 std::vector<cricket::AudioCodec> codecs;
1008 codecs.push_back(kOpusCodec);
1009 codecs[0].bitrate = 30000;
1010 webrtc::CodecInst gcodec;
1011
1012 // Ignore if less than 6000.
1013 codecs[0].params["maxaveragebitrate"] = "5999";
1014 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1015 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
buildbot@webrtc.org9d446f22014-10-23 12:22:06 +00001016 EXPECT_EQ(6000, gcodec.rate);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00001017
1018 // Ignore if larger than 510000.
1019 codecs[0].params["maxaveragebitrate"] = "510001";
1020 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1021 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
buildbot@webrtc.org9d446f22014-10-23 12:22:06 +00001022 EXPECT_EQ(510000, gcodec.rate);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00001023
1024 codecs[0].params["maxaveragebitrate"] = "200000";
1025 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1026 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1027 EXPECT_EQ(200000, gcodec.rate);
1028}
1029
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00001030// Test that we can enable NACK with opus as caller.
1031TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecEnableNackAsCaller) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001032 EXPECT_TRUE(SetupEngine());
1033 int channel_num = voe_.GetLastChannel();
1034 std::vector<cricket::AudioCodec> codecs;
1035 codecs.push_back(kOpusCodec);
1036 codecs[0].AddFeedbackParam(cricket::FeedbackParam(cricket::kRtcpFbParamNack,
1037 cricket::kParamValueEmpty));
1038 EXPECT_FALSE(voe_.GetNACK(channel_num));
1039 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1040 EXPECT_TRUE(voe_.GetNACK(channel_num));
1041}
1042
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00001043// Test that we can enable NACK with opus as callee.
1044TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecEnableNackAsCallee) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001045 EXPECT_TRUE(engine_.Init(rtc::Thread::Current()));
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00001046 channel_ = engine_.CreateChannel();
1047 EXPECT_TRUE(channel_ != NULL);
1048
1049 int channel_num = voe_.GetLastChannel();
1050 std::vector<cricket::AudioCodec> codecs;
1051 codecs.push_back(kOpusCodec);
1052 codecs[0].AddFeedbackParam(cricket::FeedbackParam(cricket::kRtcpFbParamNack,
1053 cricket::kParamValueEmpty));
1054 EXPECT_FALSE(voe_.GetNACK(channel_num));
1055 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1056 EXPECT_FALSE(voe_.GetNACK(channel_num));
1057
1058 EXPECT_TRUE(channel_->AddSendStream(
1059 cricket::StreamParams::CreateLegacy(kSsrc1)));
1060 EXPECT_TRUE(voe_.GetNACK(channel_num));
1061}
1062
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001063// Test that we can enable NACK on receive streams.
1064TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecEnableNackRecvStreams) {
1065 EXPECT_TRUE(SetupEngine());
1066 EXPECT_TRUE(channel_->SetOptions(options_conference_));
1067 int channel_num1 = voe_.GetLastChannel();
1068 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(2)));
1069 int channel_num2 = voe_.GetLastChannel();
1070 std::vector<cricket::AudioCodec> codecs;
1071 codecs.push_back(kOpusCodec);
1072 codecs[0].AddFeedbackParam(cricket::FeedbackParam(cricket::kRtcpFbParamNack,
1073 cricket::kParamValueEmpty));
1074 EXPECT_FALSE(voe_.GetNACK(channel_num1));
1075 EXPECT_FALSE(voe_.GetNACK(channel_num2));
1076 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1077 EXPECT_TRUE(voe_.GetNACK(channel_num1));
1078 EXPECT_TRUE(voe_.GetNACK(channel_num2));
1079}
1080
1081// Test that we can disable NACK.
1082TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecDisableNack) {
1083 EXPECT_TRUE(SetupEngine());
1084 int channel_num = voe_.GetLastChannel();
1085 std::vector<cricket::AudioCodec> codecs;
1086 codecs.push_back(kOpusCodec);
1087 codecs[0].AddFeedbackParam(cricket::FeedbackParam(cricket::kRtcpFbParamNack,
1088 cricket::kParamValueEmpty));
1089 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1090 EXPECT_TRUE(voe_.GetNACK(channel_num));
1091
1092 codecs.clear();
1093 codecs.push_back(kOpusCodec);
1094 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1095 EXPECT_FALSE(voe_.GetNACK(channel_num));
1096}
1097
1098// Test that we can disable NACK on receive streams.
1099TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecDisableNackRecvStreams) {
1100 EXPECT_TRUE(SetupEngine());
1101 EXPECT_TRUE(channel_->SetOptions(options_conference_));
1102 int channel_num1 = voe_.GetLastChannel();
1103 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(2)));
1104 int channel_num2 = voe_.GetLastChannel();
1105 std::vector<cricket::AudioCodec> codecs;
1106 codecs.push_back(kOpusCodec);
1107 codecs[0].AddFeedbackParam(cricket::FeedbackParam(cricket::kRtcpFbParamNack,
1108 cricket::kParamValueEmpty));
1109 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1110 EXPECT_TRUE(voe_.GetNACK(channel_num1));
1111 EXPECT_TRUE(voe_.GetNACK(channel_num2));
1112
1113 codecs.clear();
1114 codecs.push_back(kOpusCodec);
1115 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1116 EXPECT_FALSE(voe_.GetNACK(channel_num1));
1117 EXPECT_FALSE(voe_.GetNACK(channel_num2));
1118}
1119
1120// Test that NACK is enabled on a new receive stream.
1121TEST_F(WebRtcVoiceEngineTestFake, AddRecvStreamEnableNack) {
1122 EXPECT_TRUE(SetupEngine());
1123 EXPECT_TRUE(channel_->SetOptions(options_conference_));
1124 int channel_num = voe_.GetLastChannel();
1125 std::vector<cricket::AudioCodec> codecs;
1126 codecs.push_back(kIsacCodec);
1127 codecs[0].AddFeedbackParam(cricket::FeedbackParam(cricket::kRtcpFbParamNack,
1128 cricket::kParamValueEmpty));
1129 codecs.push_back(kCn16000Codec);
1130 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1131 EXPECT_TRUE(voe_.GetNACK(channel_num));
1132
1133 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(2)));
1134 channel_num = voe_.GetLastChannel();
1135 EXPECT_TRUE(voe_.GetNACK(channel_num));
1136 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(3)));
1137 channel_num = voe_.GetLastChannel();
1138 EXPECT_TRUE(voe_.GetNACK(channel_num));
1139}
1140
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +00001141// Test that without useinbandfec, Opus FEC is off.
buildbot@webrtc.orgd27d9ae2014-06-19 01:56:46 +00001142TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecNoOpusFec) {
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +00001143 EXPECT_TRUE(SetupEngine());
1144 int channel_num = voe_.GetLastChannel();
1145 std::vector<cricket::AudioCodec> codecs;
1146 codecs.push_back(kOpusCodec);
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +00001147 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1148 EXPECT_FALSE(voe_.GetCodecFEC(channel_num));
1149}
1150
1151// Test that with useinbandfec=0, Opus FEC is off.
buildbot@webrtc.orgd27d9ae2014-06-19 01:56:46 +00001152TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecOpusDisableFec) {
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +00001153 EXPECT_TRUE(SetupEngine());
1154 int channel_num = voe_.GetLastChannel();
1155 std::vector<cricket::AudioCodec> codecs;
1156 codecs.push_back(kOpusCodec);
1157 codecs[0].bitrate = 0;
1158 codecs[0].params["useinbandfec"] = "0";
1159 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1160 EXPECT_FALSE(voe_.GetCodecFEC(channel_num));
1161 webrtc::CodecInst gcodec;
1162 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1163 EXPECT_STREQ("opus", gcodec.plname);
1164 EXPECT_EQ(1, gcodec.channels);
1165 EXPECT_EQ(32000, gcodec.rate);
1166}
1167
1168// Test that with useinbandfec=1, Opus FEC is on.
buildbot@webrtc.orgd27d9ae2014-06-19 01:56:46 +00001169TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecOpusEnableFec) {
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +00001170 EXPECT_TRUE(SetupEngine());
1171 int channel_num = voe_.GetLastChannel();
1172 std::vector<cricket::AudioCodec> codecs;
1173 codecs.push_back(kOpusCodec);
1174 codecs[0].bitrate = 0;
1175 codecs[0].params["useinbandfec"] = "1";
1176 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1177 EXPECT_TRUE(voe_.GetCodecFEC(channel_num));
1178 webrtc::CodecInst gcodec;
1179 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1180 EXPECT_STREQ("opus", gcodec.plname);
1181 EXPECT_EQ(1, gcodec.channels);
1182 EXPECT_EQ(32000, gcodec.rate);
1183}
1184
1185// Test that with useinbandfec=1, stereo=1, Opus FEC is on.
buildbot@webrtc.orgd27d9ae2014-06-19 01:56:46 +00001186TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecOpusEnableFecStereo) {
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +00001187 EXPECT_TRUE(SetupEngine());
1188 int channel_num = voe_.GetLastChannel();
1189 std::vector<cricket::AudioCodec> codecs;
1190 codecs.push_back(kOpusCodec);
1191 codecs[0].bitrate = 0;
1192 codecs[0].params["stereo"] = "1";
1193 codecs[0].params["useinbandfec"] = "1";
1194 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1195 EXPECT_TRUE(voe_.GetCodecFEC(channel_num));
1196 webrtc::CodecInst gcodec;
1197 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1198 EXPECT_STREQ("opus", gcodec.plname);
1199 EXPECT_EQ(2, gcodec.channels);
1200 EXPECT_EQ(64000, gcodec.rate);
1201}
1202
1203// Test that with non-Opus, codec FEC is off.
buildbot@webrtc.orgd27d9ae2014-06-19 01:56:46 +00001204TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecIsacNoFec) {
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +00001205 EXPECT_TRUE(SetupEngine());
1206 int channel_num = voe_.GetLastChannel();
1207 std::vector<cricket::AudioCodec> codecs;
1208 codecs.push_back(kIsacCodec);
1209 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1210 EXPECT_FALSE(voe_.GetCodecFEC(channel_num));
1211}
buildbot@webrtc.org3ffa1f92014-07-02 19:51:26 +00001212
1213// Test the with non-Opus, even if useinbandfec=1, FEC is off.
1214TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecIsacWithParamNoFec) {
1215 EXPECT_TRUE(SetupEngine());
1216 int channel_num = voe_.GetLastChannel();
1217 std::vector<cricket::AudioCodec> codecs;
1218 codecs.push_back(kIsacCodec);
1219 codecs[0].params["useinbandfec"] = "1";
1220 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1221 EXPECT_FALSE(voe_.GetCodecFEC(channel_num));
1222}
buildbot@webrtc.org5d639b32014-09-10 07:57:12 +00001223
1224// Test that Opus FEC status can be changed.
1225TEST_F(WebRtcVoiceEngineTestFake, ChangeOpusFecStatus) {
1226 EXPECT_TRUE(SetupEngine());
1227 int channel_num = voe_.GetLastChannel();
1228 std::vector<cricket::AudioCodec> codecs;
1229 codecs.push_back(kOpusCodec);
1230 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1231 EXPECT_FALSE(voe_.GetCodecFEC(channel_num));
1232 codecs[0].params["useinbandfec"] = "1";
1233 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1234 EXPECT_TRUE(voe_.GetCodecFEC(channel_num));
1235}
1236
1237// Test maxplaybackrate <= 8000 triggers Opus narrow band mode.
1238TEST_F(WebRtcVoiceEngineTestFake, SetOpusMaxPlaybackRateNb) {
1239 EXPECT_TRUE(SetupEngine());
1240 int channel_num = voe_.GetLastChannel();
1241 std::vector<cricket::AudioCodec> codecs;
1242 codecs.push_back(kOpusCodec);
1243 codecs[0].bitrate = 0;
1244 codecs[0].SetParam(cricket::kCodecParamMaxPlaybackRate, 8000);
1245 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1246 EXPECT_EQ(cricket::kOpusBandwidthNb,
1247 voe_.GetMaxEncodingBandwidth(channel_num));
1248 webrtc::CodecInst gcodec;
1249 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1250 EXPECT_STREQ("opus", gcodec.plname);
minyue@webrtc.org2dc6f312014-10-31 05:33:10 +00001251
1252 EXPECT_EQ(12000, gcodec.rate);
1253 codecs[0].SetParam(cricket::kCodecParamStereo, "1");
1254 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1255 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1256 EXPECT_EQ(24000, gcodec.rate);
buildbot@webrtc.org5d639b32014-09-10 07:57:12 +00001257}
1258
1259// Test 8000 < maxplaybackrate <= 12000 triggers Opus medium band mode.
1260TEST_F(WebRtcVoiceEngineTestFake, SetOpusMaxPlaybackRateMb) {
1261 EXPECT_TRUE(SetupEngine());
1262 int channel_num = voe_.GetLastChannel();
1263 std::vector<cricket::AudioCodec> codecs;
1264 codecs.push_back(kOpusCodec);
1265 codecs[0].bitrate = 0;
1266 codecs[0].SetParam(cricket::kCodecParamMaxPlaybackRate, 8001);
1267 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1268 EXPECT_EQ(cricket::kOpusBandwidthMb,
1269 voe_.GetMaxEncodingBandwidth(channel_num));
1270 webrtc::CodecInst gcodec;
1271 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1272 EXPECT_STREQ("opus", gcodec.plname);
minyue@webrtc.org2dc6f312014-10-31 05:33:10 +00001273
1274 EXPECT_EQ(20000, gcodec.rate);
1275 codecs[0].SetParam(cricket::kCodecParamStereo, "1");
1276 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1277 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1278 EXPECT_EQ(40000, gcodec.rate);
buildbot@webrtc.org5d639b32014-09-10 07:57:12 +00001279}
1280
1281// Test 12000 < maxplaybackrate <= 16000 triggers Opus wide band mode.
1282TEST_F(WebRtcVoiceEngineTestFake, SetOpusMaxPlaybackRateWb) {
1283 EXPECT_TRUE(SetupEngine());
1284 int channel_num = voe_.GetLastChannel();
1285 std::vector<cricket::AudioCodec> codecs;
1286 codecs.push_back(kOpusCodec);
1287 codecs[0].bitrate = 0;
1288 codecs[0].SetParam(cricket::kCodecParamMaxPlaybackRate, 12001);
1289 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1290 EXPECT_EQ(cricket::kOpusBandwidthWb,
1291 voe_.GetMaxEncodingBandwidth(channel_num));
1292 webrtc::CodecInst gcodec;
1293 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1294 EXPECT_STREQ("opus", gcodec.plname);
minyue@webrtc.org2dc6f312014-10-31 05:33:10 +00001295
1296 EXPECT_EQ(20000, gcodec.rate);
1297 codecs[0].SetParam(cricket::kCodecParamStereo, "1");
1298 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1299 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1300 EXPECT_EQ(40000, gcodec.rate);
buildbot@webrtc.org5d639b32014-09-10 07:57:12 +00001301}
1302
1303// Test 16000 < maxplaybackrate <= 24000 triggers Opus super wide band mode.
1304TEST_F(WebRtcVoiceEngineTestFake, SetOpusMaxPlaybackRateSwb) {
1305 EXPECT_TRUE(SetupEngine());
1306 int channel_num = voe_.GetLastChannel();
1307 std::vector<cricket::AudioCodec> codecs;
1308 codecs.push_back(kOpusCodec);
1309 codecs[0].bitrate = 0;
1310 codecs[0].SetParam(cricket::kCodecParamMaxPlaybackRate, 16001);
1311 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1312 EXPECT_EQ(cricket::kOpusBandwidthSwb,
1313 voe_.GetMaxEncodingBandwidth(channel_num));
1314 webrtc::CodecInst gcodec;
1315 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1316 EXPECT_STREQ("opus", gcodec.plname);
minyue@webrtc.org2dc6f312014-10-31 05:33:10 +00001317
buildbot@webrtc.org5d639b32014-09-10 07:57:12 +00001318 EXPECT_EQ(32000, gcodec.rate);
minyue@webrtc.org2dc6f312014-10-31 05:33:10 +00001319 codecs[0].SetParam(cricket::kCodecParamStereo, "1");
1320 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1321 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1322 EXPECT_EQ(64000, gcodec.rate);
buildbot@webrtc.org5d639b32014-09-10 07:57:12 +00001323}
1324
1325// Test 24000 < maxplaybackrate triggers Opus full band mode.
1326TEST_F(WebRtcVoiceEngineTestFake, SetOpusMaxPlaybackRateFb) {
1327 EXPECT_TRUE(SetupEngine());
1328 int channel_num = voe_.GetLastChannel();
1329 std::vector<cricket::AudioCodec> codecs;
1330 codecs.push_back(kOpusCodec);
1331 codecs[0].bitrate = 0;
1332 codecs[0].SetParam(cricket::kCodecParamMaxPlaybackRate, 24001);
1333 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1334 EXPECT_EQ(cricket::kOpusBandwidthFb,
1335 voe_.GetMaxEncodingBandwidth(channel_num));
1336 webrtc::CodecInst gcodec;
1337 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1338 EXPECT_STREQ("opus", gcodec.plname);
minyue@webrtc.org2dc6f312014-10-31 05:33:10 +00001339
buildbot@webrtc.org5d639b32014-09-10 07:57:12 +00001340 EXPECT_EQ(32000, gcodec.rate);
minyue@webrtc.org2dc6f312014-10-31 05:33:10 +00001341 codecs[0].SetParam(cricket::kCodecParamStereo, "1");
1342 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1343 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1344 EXPECT_EQ(64000, gcodec.rate);
buildbot@webrtc.org5d639b32014-09-10 07:57:12 +00001345}
1346
1347// Test Opus that without maxplaybackrate, default playback rate is used.
1348TEST_F(WebRtcVoiceEngineTestFake, DefaultOpusMaxPlaybackRate) {
1349 EXPECT_TRUE(SetupEngine());
1350 int channel_num = voe_.GetLastChannel();
1351 std::vector<cricket::AudioCodec> codecs;
1352 codecs.push_back(kOpusCodec);
1353 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1354 EXPECT_EQ(cricket::kOpusBandwidthFb,
1355 voe_.GetMaxEncodingBandwidth(channel_num));
1356}
1357
1358// Test the with non-Opus, maxplaybackrate has no effect.
1359TEST_F(WebRtcVoiceEngineTestFake, SetNonOpusMaxPlaybackRate) {
1360 EXPECT_TRUE(SetupEngine());
1361 int channel_num = voe_.GetLastChannel();
1362 std::vector<cricket::AudioCodec> codecs;
1363 codecs.push_back(kIsacCodec);
1364 codecs[0].SetParam(cricket::kCodecParamMaxPlaybackRate, 32000);
1365 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1366 EXPECT_EQ(0, voe_.GetMaxEncodingBandwidth(channel_num));
1367}
1368
1369// Test maxplaybackrate can be set on two streams.
1370TEST_F(WebRtcVoiceEngineTestFake, SetOpusMaxPlaybackRateOnTwoStreams) {
1371 EXPECT_TRUE(SetupEngine());
1372 int channel_num = voe_.GetLastChannel();
1373 std::vector<cricket::AudioCodec> codecs;
1374 codecs.push_back(kOpusCodec);
1375 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1376 // Default bandwidth is 24000.
1377 EXPECT_EQ(cricket::kOpusBandwidthFb,
1378 voe_.GetMaxEncodingBandwidth(channel_num));
1379
1380 codecs[0].SetParam(cricket::kCodecParamMaxPlaybackRate, 8000);
1381
1382 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1383 EXPECT_EQ(cricket::kOpusBandwidthNb,
1384 voe_.GetMaxEncodingBandwidth(channel_num));
1385
1386 channel_->AddSendStream(cricket::StreamParams::CreateLegacy(kSsrc2));
1387 channel_num = voe_.GetLastChannel();
1388 EXPECT_EQ(cricket::kOpusBandwidthNb,
1389 voe_.GetMaxEncodingBandwidth(channel_num));
1390}
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +00001391
Minyue Li7100dcd2015-03-27 05:05:59 +01001392// Test that with usedtx=0, Opus DTX is off.
1393TEST_F(WebRtcVoiceEngineTestFake, DisableOpusDtxOnOpus) {
1394 EXPECT_TRUE(SetupEngine());
1395 int channel_num = voe_.GetLastChannel();
1396 std::vector<cricket::AudioCodec> codecs;
1397 codecs.push_back(kOpusCodec);
1398 codecs[0].params["usedtx"] = "0";
1399 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1400 EXPECT_FALSE(voe_.GetOpusDtx(channel_num));
1401}
1402
1403// Test that with usedtx=1, Opus DTX is on.
1404TEST_F(WebRtcVoiceEngineTestFake, EnableOpusDtxOnOpus) {
1405 EXPECT_TRUE(SetupEngine());
1406 int channel_num = voe_.GetLastChannel();
1407 std::vector<cricket::AudioCodec> codecs;
1408 codecs.push_back(kOpusCodec);
1409 codecs[0].params["usedtx"] = "1";
1410 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1411 EXPECT_TRUE(voe_.GetOpusDtx(channel_num));
1412 EXPECT_FALSE(voe_.GetVAD(channel_num)); // Opus DTX should not affect VAD.
1413}
1414
1415// Test that usedtx=1 works with stereo Opus.
1416TEST_F(WebRtcVoiceEngineTestFake, EnableOpusDtxOnOpusStereo) {
1417 EXPECT_TRUE(SetupEngine());
1418 int channel_num = voe_.GetLastChannel();
1419 std::vector<cricket::AudioCodec> codecs;
1420 codecs.push_back(kOpusCodec);
1421 codecs[0].params["usedtx"] = "1";
1422 codecs[0].params["stereo"] = "1";
1423 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1424 EXPECT_TRUE(voe_.GetOpusDtx(channel_num));
1425 EXPECT_FALSE(voe_.GetVAD(channel_num)); // Opus DTX should not affect VAD.
1426}
1427
1428// Test that usedtx=1 does not work with non Opus.
1429TEST_F(WebRtcVoiceEngineTestFake, CannotEnableOpusDtxOnNonOpus) {
1430 EXPECT_TRUE(SetupEngine());
1431 int channel_num = voe_.GetLastChannel();
1432 std::vector<cricket::AudioCodec> codecs;
1433 codecs.push_back(kIsacCodec);
1434 codecs[0].params["usedtx"] = "1";
1435 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1436 EXPECT_FALSE(voe_.GetOpusDtx(channel_num));
1437}
1438
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +00001439// Test that we can switch back and forth between Opus and ISAC with CN.
1440TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecsIsacOpusSwitching) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001441 EXPECT_TRUE(SetupEngine());
1442 int channel_num = voe_.GetLastChannel();
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +00001443 std::vector<cricket::AudioCodec> opus_codecs;
1444 opus_codecs.push_back(kOpusCodec);
1445 EXPECT_TRUE(channel_->SetSendCodecs(opus_codecs));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001446 webrtc::CodecInst gcodec;
1447 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +00001448 EXPECT_EQ(111, gcodec.pltype);
1449 EXPECT_STREQ("opus", gcodec.plname);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001450
1451 std::vector<cricket::AudioCodec> isac_codecs;
1452 isac_codecs.push_back(kIsacCodec);
1453 isac_codecs.push_back(kCn16000Codec);
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +00001454 isac_codecs.push_back(kOpusCodec);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001455 EXPECT_TRUE(channel_->SetSendCodecs(isac_codecs));
1456 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1457 EXPECT_EQ(103, gcodec.pltype);
1458 EXPECT_STREQ("ISAC", gcodec.plname);
1459
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +00001460 EXPECT_TRUE(channel_->SetSendCodecs(opus_codecs));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001461 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +00001462 EXPECT_EQ(111, gcodec.pltype);
1463 EXPECT_STREQ("opus", gcodec.plname);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001464}
1465
1466// Test that we handle various ways of specifying bitrate.
1467TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecsBitrate) {
1468 EXPECT_TRUE(SetupEngine());
1469 int channel_num = voe_.GetLastChannel();
1470 std::vector<cricket::AudioCodec> codecs;
1471 codecs.push_back(kIsacCodec); // bitrate == 32000
1472 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1473 webrtc::CodecInst gcodec;
1474 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1475 EXPECT_EQ(103, gcodec.pltype);
1476 EXPECT_STREQ("ISAC", gcodec.plname);
1477 EXPECT_EQ(32000, gcodec.rate);
1478
1479 codecs[0].bitrate = 0; // bitrate == default
1480 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1481 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1482 EXPECT_EQ(103, gcodec.pltype);
1483 EXPECT_STREQ("ISAC", gcodec.plname);
1484 EXPECT_EQ(-1, gcodec.rate);
1485
1486 codecs[0].bitrate = 28000; // bitrate == 28000
1487 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1488 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1489 EXPECT_EQ(103, gcodec.pltype);
1490 EXPECT_STREQ("ISAC", gcodec.plname);
1491 EXPECT_EQ(28000, gcodec.rate);
1492
1493 codecs[0] = kPcmuCodec; // bitrate == 64000
1494 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1495 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1496 EXPECT_EQ(0, gcodec.pltype);
1497 EXPECT_STREQ("PCMU", gcodec.plname);
1498 EXPECT_EQ(64000, gcodec.rate);
1499
1500 codecs[0].bitrate = 0; // bitrate == default
1501 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1502 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1503 EXPECT_EQ(0, gcodec.pltype);
1504 EXPECT_STREQ("PCMU", gcodec.plname);
1505 EXPECT_EQ(64000, gcodec.rate);
1506
1507 codecs[0] = kOpusCodec;
1508 codecs[0].bitrate = 0; // bitrate == default
1509 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1510 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1511 EXPECT_EQ(111, gcodec.pltype);
1512 EXPECT_STREQ("opus", gcodec.plname);
1513 EXPECT_EQ(32000, gcodec.rate);
1514}
1515
Brave Yao5225dd82015-03-26 07:39:19 +08001516// Test that we could set packet size specified in kCodecParamPTime.
1517TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecsPTimeAsPacketSize) {
1518 EXPECT_TRUE(SetupEngine());
1519 int channel_num = voe_.GetLastChannel();
1520 std::vector<cricket::AudioCodec> codecs;
1521 codecs.push_back(kOpusCodec);
1522 codecs[0].SetParam(cricket::kCodecParamPTime, 40); // Value within range.
1523 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1524 webrtc::CodecInst gcodec;
1525 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1526 EXPECT_EQ(1920, gcodec.pacsize); // Opus gets 40ms.
1527
1528 codecs[0].SetParam(cricket::kCodecParamPTime, 5); // Value below range.
1529 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1530 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1531 EXPECT_EQ(480, gcodec.pacsize); // Opus gets 10ms.
1532
1533 codecs[0].SetParam(cricket::kCodecParamPTime, 80); // Value beyond range.
1534 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1535 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1536 EXPECT_EQ(2880, gcodec.pacsize); // Opus gets 60ms.
1537
1538 codecs[0] = kIsacCodec; // Also try Isac, and with unsupported size.
1539 codecs[0].SetParam(cricket::kCodecParamPTime, 40); // Value within range.
1540 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1541 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1542 EXPECT_EQ(480, gcodec.pacsize); // Isac gets 30ms as the next smallest value.
1543
1544 codecs[0] = kG722CodecSdp; // Try G722 @8kHz as negotiated in SDP.
1545 codecs[0].SetParam(cricket::kCodecParamPTime, 40);
1546 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1547 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1548 EXPECT_EQ(640, gcodec.pacsize); // G722 gets 40ms @16kHz as defined in VoE.
1549}
1550
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00001551// Test that we fail if no codecs are specified.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001552TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecsNoCodecs) {
1553 EXPECT_TRUE(SetupEngine());
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00001554 std::vector<cricket::AudioCodec> codecs;
1555 EXPECT_FALSE(channel_->SetSendCodecs(codecs));
1556}
1557
1558// Test that we can set send codecs even with telephone-event codec as the first
1559// one on the list.
1560TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecsDTMFOnTop) {
1561 EXPECT_TRUE(SetupEngine());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001562 int channel_num = voe_.GetLastChannel();
1563 std::vector<cricket::AudioCodec> codecs;
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00001564 codecs.push_back(kTelephoneEventCodec);
1565 codecs.push_back(kIsacCodec);
1566 codecs.push_back(kPcmuCodec);
1567 codecs[0].id = 98; // DTMF
1568 codecs[1].id = 96;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001569 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1570 webrtc::CodecInst gcodec;
1571 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00001572 EXPECT_EQ(96, gcodec.pltype);
1573 EXPECT_STREQ("ISAC", gcodec.plname);
1574 EXPECT_EQ(98, voe_.GetSendTelephoneEventPayloadType(channel_num));
1575}
1576
1577// Test that we can set send codecs even with CN codec as the first
1578// one on the list.
1579TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecsCNOnTop) {
1580 EXPECT_TRUE(SetupEngine());
1581 int channel_num = voe_.GetLastChannel();
1582 std::vector<cricket::AudioCodec> codecs;
1583 codecs.push_back(kCn16000Codec);
1584 codecs.push_back(kIsacCodec);
1585 codecs.push_back(kPcmuCodec);
1586 codecs[0].id = 98; // wideband CN
1587 codecs[1].id = 96;
1588 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1589 webrtc::CodecInst gcodec;
1590 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1591 EXPECT_EQ(96, gcodec.pltype);
1592 EXPECT_STREQ("ISAC", gcodec.plname);
1593 EXPECT_EQ(98, voe_.GetSendCNPayloadType(channel_num, true));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001594}
1595
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00001596// Test that we set VAD and DTMF types correctly as caller.
1597TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecsCNandDTMFAsCaller) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001598 EXPECT_TRUE(SetupEngine());
1599 int channel_num = voe_.GetLastChannel();
1600 std::vector<cricket::AudioCodec> codecs;
1601 codecs.push_back(kIsacCodec);
1602 codecs.push_back(kPcmuCodec);
1603 // TODO(juberti): cn 32000
1604 codecs.push_back(kCn16000Codec);
1605 codecs.push_back(kCn8000Codec);
1606 codecs.push_back(kTelephoneEventCodec);
1607 codecs.push_back(kRedCodec);
1608 codecs[0].id = 96;
1609 codecs[2].id = 97; // wideband CN
1610 codecs[4].id = 98; // DTMF
1611 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1612 webrtc::CodecInst gcodec;
1613 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1614 EXPECT_EQ(96, gcodec.pltype);
1615 EXPECT_STREQ("ISAC", gcodec.plname);
1616 EXPECT_TRUE(voe_.GetVAD(channel_num));
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +00001617 EXPECT_FALSE(voe_.GetRED(channel_num));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001618 EXPECT_EQ(13, voe_.GetSendCNPayloadType(channel_num, false));
1619 EXPECT_EQ(97, voe_.GetSendCNPayloadType(channel_num, true));
1620 EXPECT_EQ(98, voe_.GetSendTelephoneEventPayloadType(channel_num));
1621}
1622
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00001623// Test that we set VAD and DTMF types correctly as callee.
1624TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecsCNandDTMFAsCallee) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001625 EXPECT_TRUE(engine_.Init(rtc::Thread::Current()));
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00001626 channel_ = engine_.CreateChannel();
1627 EXPECT_TRUE(channel_ != NULL);
1628
1629 int channel_num = voe_.GetLastChannel();
1630 std::vector<cricket::AudioCodec> codecs;
1631 codecs.push_back(kIsacCodec);
1632 codecs.push_back(kPcmuCodec);
1633 // TODO(juberti): cn 32000
1634 codecs.push_back(kCn16000Codec);
1635 codecs.push_back(kCn8000Codec);
1636 codecs.push_back(kTelephoneEventCodec);
1637 codecs.push_back(kRedCodec);
1638 codecs[0].id = 96;
1639 codecs[2].id = 97; // wideband CN
1640 codecs[4].id = 98; // DTMF
1641 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1642 EXPECT_TRUE(channel_->AddSendStream(
1643 cricket::StreamParams::CreateLegacy(kSsrc1)));
1644
1645 webrtc::CodecInst gcodec;
1646 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1647 EXPECT_EQ(96, gcodec.pltype);
1648 EXPECT_STREQ("ISAC", gcodec.plname);
1649 EXPECT_TRUE(voe_.GetVAD(channel_num));
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +00001650 EXPECT_FALSE(voe_.GetRED(channel_num));
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00001651 EXPECT_EQ(13, voe_.GetSendCNPayloadType(channel_num, false));
1652 EXPECT_EQ(97, voe_.GetSendCNPayloadType(channel_num, true));
1653 EXPECT_EQ(98, voe_.GetSendTelephoneEventPayloadType(channel_num));
1654}
1655
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001656// Test that we only apply VAD if we have a CN codec that matches the
1657// send codec clockrate.
1658TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecsCNNoMatch) {
1659 EXPECT_TRUE(SetupEngine());
1660 int channel_num = voe_.GetLastChannel();
1661 std::vector<cricket::AudioCodec> codecs;
1662 // Set ISAC(16K) and CN(16K). VAD should be activated.
1663 codecs.push_back(kIsacCodec);
1664 codecs.push_back(kCn16000Codec);
1665 codecs[1].id = 97;
1666 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1667 webrtc::CodecInst gcodec;
1668 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1669 EXPECT_STREQ("ISAC", gcodec.plname);
1670 EXPECT_TRUE(voe_.GetVAD(channel_num));
1671 EXPECT_EQ(97, voe_.GetSendCNPayloadType(channel_num, true));
1672 // Set PCMU(8K) and CN(16K). VAD should not be activated.
1673 codecs[0] = kPcmuCodec;
1674 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1675 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1676 EXPECT_STREQ("PCMU", gcodec.plname);
1677 EXPECT_FALSE(voe_.GetVAD(channel_num));
1678 // Set PCMU(8K) and CN(8K). VAD should be activated.
1679 codecs[1] = kCn8000Codec;
1680 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1681 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1682 EXPECT_STREQ("PCMU", gcodec.plname);
1683 EXPECT_TRUE(voe_.GetVAD(channel_num));
1684 EXPECT_EQ(13, voe_.GetSendCNPayloadType(channel_num, false));
Brave Yao5225dd82015-03-26 07:39:19 +08001685 // Set ISAC(16K) and CN(8K). VAD should not be activated.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001686 codecs[0] = kIsacCodec;
1687 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1688 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1689 EXPECT_STREQ("ISAC", gcodec.plname);
1690 EXPECT_FALSE(voe_.GetVAD(channel_num));
1691}
1692
1693// Test that we perform case-insensitive matching of codec names.
1694TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecsCaseInsensitive) {
1695 EXPECT_TRUE(SetupEngine());
1696 int channel_num = voe_.GetLastChannel();
1697 std::vector<cricket::AudioCodec> codecs;
1698 codecs.push_back(kIsacCodec);
1699 codecs.push_back(kPcmuCodec);
1700 codecs.push_back(kCn16000Codec);
1701 codecs.push_back(kCn8000Codec);
1702 codecs.push_back(kTelephoneEventCodec);
1703 codecs.push_back(kRedCodec);
1704 codecs[0].name = "iSaC";
1705 codecs[0].id = 96;
1706 codecs[2].id = 97; // wideband CN
1707 codecs[4].id = 98; // DTMF
1708 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1709 webrtc::CodecInst gcodec;
1710 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1711 EXPECT_EQ(96, gcodec.pltype);
1712 EXPECT_STREQ("ISAC", gcodec.plname);
1713 EXPECT_TRUE(voe_.GetVAD(channel_num));
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +00001714 EXPECT_FALSE(voe_.GetRED(channel_num));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001715 EXPECT_EQ(13, voe_.GetSendCNPayloadType(channel_num, false));
1716 EXPECT_EQ(97, voe_.GetSendCNPayloadType(channel_num, true));
1717 EXPECT_EQ(98, voe_.GetSendTelephoneEventPayloadType(channel_num));
1718}
1719
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +00001720// Test that we set up RED correctly as caller.
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00001721TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecsREDAsCaller) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001722 EXPECT_TRUE(SetupEngine());
1723 int channel_num = voe_.GetLastChannel();
1724 std::vector<cricket::AudioCodec> codecs;
1725 codecs.push_back(kRedCodec);
1726 codecs.push_back(kIsacCodec);
1727 codecs.push_back(kPcmuCodec);
1728 codecs[0].id = 127;
1729 codecs[0].params[""] = "96/96";
1730 codecs[1].id = 96;
1731 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1732 webrtc::CodecInst gcodec;
1733 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1734 EXPECT_EQ(96, gcodec.pltype);
1735 EXPECT_STREQ("ISAC", gcodec.plname);
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +00001736 EXPECT_TRUE(voe_.GetRED(channel_num));
1737 EXPECT_EQ(127, voe_.GetSendREDPayloadType(channel_num));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001738}
1739
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +00001740// Test that we set up RED correctly as callee.
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00001741TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecsREDAsCallee) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001742 EXPECT_TRUE(engine_.Init(rtc::Thread::Current()));
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00001743 channel_ = engine_.CreateChannel();
1744 EXPECT_TRUE(channel_ != NULL);
1745
1746 int channel_num = voe_.GetLastChannel();
1747 std::vector<cricket::AudioCodec> codecs;
1748 codecs.push_back(kRedCodec);
1749 codecs.push_back(kIsacCodec);
1750 codecs.push_back(kPcmuCodec);
1751 codecs[0].id = 127;
1752 codecs[0].params[""] = "96/96";
1753 codecs[1].id = 96;
1754 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1755 EXPECT_TRUE(channel_->AddSendStream(
1756 cricket::StreamParams::CreateLegacy(kSsrc1)));
1757 webrtc::CodecInst gcodec;
1758 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1759 EXPECT_EQ(96, gcodec.pltype);
1760 EXPECT_STREQ("ISAC", gcodec.plname);
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +00001761 EXPECT_TRUE(voe_.GetRED(channel_num));
1762 EXPECT_EQ(127, voe_.GetSendREDPayloadType(channel_num));
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00001763}
1764
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +00001765// Test that we set up RED correctly if params are omitted.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001766TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecsREDNoParams) {
1767 EXPECT_TRUE(SetupEngine());
1768 int channel_num = voe_.GetLastChannel();
1769 std::vector<cricket::AudioCodec> codecs;
1770 codecs.push_back(kRedCodec);
1771 codecs.push_back(kIsacCodec);
1772 codecs.push_back(kPcmuCodec);
1773 codecs[0].id = 127;
1774 codecs[1].id = 96;
1775 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1776 webrtc::CodecInst gcodec;
1777 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1778 EXPECT_EQ(96, gcodec.pltype);
1779 EXPECT_STREQ("ISAC", gcodec.plname);
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +00001780 EXPECT_TRUE(voe_.GetRED(channel_num));
1781 EXPECT_EQ(127, voe_.GetSendREDPayloadType(channel_num));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001782}
1783
1784// Test that we ignore RED if the parameters aren't named the way we expect.
1785TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecsBadRED1) {
1786 EXPECT_TRUE(SetupEngine());
1787 int channel_num = voe_.GetLastChannel();
1788 std::vector<cricket::AudioCodec> codecs;
1789 codecs.push_back(kRedCodec);
1790 codecs.push_back(kIsacCodec);
1791 codecs.push_back(kPcmuCodec);
1792 codecs[0].id = 127;
1793 codecs[0].params["ABC"] = "96/96";
1794 codecs[1].id = 96;
1795 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1796 webrtc::CodecInst gcodec;
1797 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1798 EXPECT_EQ(96, gcodec.pltype);
1799 EXPECT_STREQ("ISAC", gcodec.plname);
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +00001800 EXPECT_FALSE(voe_.GetRED(channel_num));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001801}
1802
1803// Test that we ignore RED if it uses different primary/secondary encoding.
1804TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecsBadRED2) {
1805 EXPECT_TRUE(SetupEngine());
1806 int channel_num = voe_.GetLastChannel();
1807 std::vector<cricket::AudioCodec> codecs;
1808 codecs.push_back(kRedCodec);
1809 codecs.push_back(kIsacCodec);
1810 codecs.push_back(kPcmuCodec);
1811 codecs[0].id = 127;
1812 codecs[0].params[""] = "96/0";
1813 codecs[1].id = 96;
1814 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1815 webrtc::CodecInst gcodec;
1816 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1817 EXPECT_EQ(96, gcodec.pltype);
1818 EXPECT_STREQ("ISAC", gcodec.plname);
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +00001819 EXPECT_FALSE(voe_.GetRED(channel_num));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001820}
1821
1822// Test that we ignore RED if it uses more than 2 encodings.
1823TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecsBadRED3) {
1824 EXPECT_TRUE(SetupEngine());
1825 int channel_num = voe_.GetLastChannel();
1826 std::vector<cricket::AudioCodec> codecs;
1827 codecs.push_back(kRedCodec);
1828 codecs.push_back(kIsacCodec);
1829 codecs.push_back(kPcmuCodec);
1830 codecs[0].id = 127;
1831 codecs[0].params[""] = "96/96/96";
1832 codecs[1].id = 96;
1833 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1834 webrtc::CodecInst gcodec;
1835 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1836 EXPECT_EQ(96, gcodec.pltype);
1837 EXPECT_STREQ("ISAC", gcodec.plname);
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +00001838 EXPECT_FALSE(voe_.GetRED(channel_num));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001839}
1840
1841// Test that we ignore RED if it has bogus codec ids.
1842TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecsBadRED4) {
1843 EXPECT_TRUE(SetupEngine());
1844 int channel_num = voe_.GetLastChannel();
1845 std::vector<cricket::AudioCodec> codecs;
1846 codecs.push_back(kRedCodec);
1847 codecs.push_back(kIsacCodec);
1848 codecs.push_back(kPcmuCodec);
1849 codecs[0].id = 127;
1850 codecs[0].params[""] = "ABC/ABC";
1851 codecs[1].id = 96;
1852 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1853 webrtc::CodecInst gcodec;
1854 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1855 EXPECT_EQ(96, gcodec.pltype);
1856 EXPECT_STREQ("ISAC", gcodec.plname);
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +00001857 EXPECT_FALSE(voe_.GetRED(channel_num));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001858}
1859
1860// Test that we ignore RED if it refers to a codec that is not present.
1861TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecsBadRED5) {
1862 EXPECT_TRUE(SetupEngine());
1863 int channel_num = voe_.GetLastChannel();
1864 std::vector<cricket::AudioCodec> codecs;
1865 codecs.push_back(kRedCodec);
1866 codecs.push_back(kIsacCodec);
1867 codecs.push_back(kPcmuCodec);
1868 codecs[0].id = 127;
1869 codecs[0].params[""] = "97/97";
1870 codecs[1].id = 96;
1871 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1872 webrtc::CodecInst gcodec;
1873 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1874 EXPECT_EQ(96, gcodec.pltype);
1875 EXPECT_STREQ("ISAC", gcodec.plname);
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +00001876 EXPECT_FALSE(voe_.GetRED(channel_num));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001877}
1878
buildbot@webrtc.org150835e2014-05-06 15:54:38 +00001879// Test support for audio level header extension.
1880TEST_F(WebRtcVoiceEngineTestFake, SendAudioLevelHeaderExtensions) {
1881 TestSetSendRtpHeaderExtensions(kRtpAudioLevelHeaderExtension);
henrike@webrtc.org79047f92014-03-06 23:46:59 +00001882}
buildbot@webrtc.org150835e2014-05-06 15:54:38 +00001883TEST_F(WebRtcVoiceEngineTestFake, RecvAudioLevelHeaderExtensions) {
1884 TestSetRecvRtpHeaderExtensions(kRtpAudioLevelHeaderExtension);
1885}
henrike@webrtc.org79047f92014-03-06 23:46:59 +00001886
buildbot@webrtc.org150835e2014-05-06 15:54:38 +00001887// Test support for absolute send time header extension.
1888TEST_F(WebRtcVoiceEngineTestFake, SendAbsoluteSendTimeHeaderExtensions) {
1889 TestSetSendRtpHeaderExtensions(kRtpAbsoluteSenderTimeHeaderExtension);
1890}
1891TEST_F(WebRtcVoiceEngineTestFake, RecvAbsoluteSendTimeHeaderExtensions) {
1892 TestSetRecvRtpHeaderExtensions(kRtpAbsoluteSenderTimeHeaderExtension);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001893}
1894
1895// Test that we can create a channel and start sending/playing out on it.
1896TEST_F(WebRtcVoiceEngineTestFake, SendAndPlayout) {
1897 EXPECT_TRUE(SetupEngine());
1898 int channel_num = voe_.GetLastChannel();
1899 std::vector<cricket::AudioCodec> codecs;
1900 codecs.push_back(kPcmuCodec);
1901 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1902 EXPECT_TRUE(channel_->SetSend(cricket::SEND_MICROPHONE));
1903 EXPECT_TRUE(voe_.GetSend(channel_num));
1904 EXPECT_TRUE(channel_->SetPlayout(true));
1905 EXPECT_TRUE(voe_.GetPlayout(channel_num));
1906 EXPECT_TRUE(channel_->SetSend(cricket::SEND_NOTHING));
1907 EXPECT_FALSE(voe_.GetSend(channel_num));
1908 EXPECT_TRUE(channel_->SetPlayout(false));
1909 EXPECT_FALSE(voe_.GetPlayout(channel_num));
1910}
1911
wu@webrtc.org9dba5252013-08-05 20:36:57 +00001912// Test that we can add and remove send streams.
1913TEST_F(WebRtcVoiceEngineTestFake, CreateAndDeleteMultipleSendStreams) {
1914 SetupForMultiSendStream();
1915
1916 static const uint32 kSsrcs4[] = {1, 2, 3, 4};
1917
1918 // Set the global state for sending.
1919 EXPECT_TRUE(channel_->SetSend(cricket::SEND_MICROPHONE));
1920
1921 for (unsigned int i = 0; i < ARRAY_SIZE(kSsrcs4); ++i) {
1922 EXPECT_TRUE(channel_->AddSendStream(
1923 cricket::StreamParams::CreateLegacy(kSsrcs4[i])));
1924
1925 // Verify that we are in a sending state for all the created streams.
1926 int channel_num = voe_.GetChannelFromLocalSsrc(kSsrcs4[i]);
1927 EXPECT_TRUE(voe_.GetSend(channel_num));
1928 }
1929
1930 // Remove the first send channel, which is the default channel. It will only
1931 // recycle the default channel but not delete it.
1932 EXPECT_TRUE(channel_->RemoveSendStream(kSsrcs4[0]));
1933 // Stream should already be Removed from the send stream list.
1934 EXPECT_FALSE(channel_->RemoveSendStream(kSsrcs4[0]));
1935 // But the default still exists.
1936 EXPECT_EQ(0, voe_.GetChannelFromLocalSsrc(kSsrcs4[0]));
1937
1938 // Delete the rest of send channel streams.
1939 for (unsigned int i = 1; i < ARRAY_SIZE(kSsrcs4); ++i) {
1940 EXPECT_TRUE(channel_->RemoveSendStream(kSsrcs4[i]));
1941 // Stream should already be deleted.
1942 EXPECT_FALSE(channel_->RemoveSendStream(kSsrcs4[i]));
1943 EXPECT_EQ(-1, voe_.GetChannelFromLocalSsrc(kSsrcs4[i]));
1944 }
1945}
1946
1947// Test SetSendCodecs correctly configure the codecs in all send streams.
1948TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecsWithMultipleSendStreams) {
1949 SetupForMultiSendStream();
1950
1951 static const uint32 kSsrcs4[] = {1, 2, 3, 4};
1952 // Create send streams.
1953 for (unsigned int i = 0; i < ARRAY_SIZE(kSsrcs4); ++i) {
1954 EXPECT_TRUE(channel_->AddSendStream(
1955 cricket::StreamParams::CreateLegacy(kSsrcs4[i])));
1956 }
1957
1958 std::vector<cricket::AudioCodec> codecs;
1959 // Set ISAC(16K) and CN(16K). VAD should be activated.
1960 codecs.push_back(kIsacCodec);
1961 codecs.push_back(kCn16000Codec);
1962 codecs[1].id = 97;
1963 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1964
1965 // Verify ISAC and VAD are corrected configured on all send channels.
1966 webrtc::CodecInst gcodec;
1967 for (unsigned int i = 0; i < ARRAY_SIZE(kSsrcs4); ++i) {
1968 int channel_num = voe_.GetChannelFromLocalSsrc(kSsrcs4[i]);
1969 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1970 EXPECT_STREQ("ISAC", gcodec.plname);
1971 EXPECT_TRUE(voe_.GetVAD(channel_num));
1972 EXPECT_EQ(97, voe_.GetSendCNPayloadType(channel_num, true));
1973 }
1974
1975 // Change to PCMU(8K) and CN(16K). VAD should not be activated.
1976 codecs[0] = kPcmuCodec;
1977 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1978 for (unsigned int i = 0; i < ARRAY_SIZE(kSsrcs4); ++i) {
1979 int channel_num = voe_.GetChannelFromLocalSsrc(kSsrcs4[i]);
1980 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1981 EXPECT_STREQ("PCMU", gcodec.plname);
1982 EXPECT_FALSE(voe_.GetVAD(channel_num));
1983 }
1984}
1985
1986// Test we can SetSend on all send streams correctly.
1987TEST_F(WebRtcVoiceEngineTestFake, SetSendWithMultipleSendStreams) {
1988 SetupForMultiSendStream();
1989
1990 static const uint32 kSsrcs4[] = {1, 2, 3, 4};
1991 // Create the send channels and they should be a SEND_NOTHING date.
1992 for (unsigned int i = 0; i < ARRAY_SIZE(kSsrcs4); ++i) {
1993 EXPECT_TRUE(channel_->AddSendStream(
1994 cricket::StreamParams::CreateLegacy(kSsrcs4[i])));
1995 int channel_num = voe_.GetLastChannel();
1996 EXPECT_FALSE(voe_.GetSend(channel_num));
1997 }
1998
1999 // Set the global state for starting sending.
2000 EXPECT_TRUE(channel_->SetSend(cricket::SEND_MICROPHONE));
2001 for (unsigned int i = 0; i < ARRAY_SIZE(kSsrcs4); ++i) {
2002 // Verify that we are in a sending state for all the send streams.
2003 int channel_num = voe_.GetChannelFromLocalSsrc(kSsrcs4[i]);
2004 EXPECT_TRUE(voe_.GetSend(channel_num));
2005 }
2006
2007 // Set the global state for stopping sending.
2008 EXPECT_TRUE(channel_->SetSend(cricket::SEND_NOTHING));
2009 for (unsigned int i = 1; i < ARRAY_SIZE(kSsrcs4); ++i) {
2010 // Verify that we are in a stop state for all the send streams.
2011 int channel_num = voe_.GetChannelFromLocalSsrc(kSsrcs4[i]);
2012 EXPECT_FALSE(voe_.GetSend(channel_num));
2013 }
2014}
2015
2016// Test we can set the correct statistics on all send streams.
2017TEST_F(WebRtcVoiceEngineTestFake, GetStatsWithMultipleSendStreams) {
2018 SetupForMultiSendStream();
2019
2020 static const uint32 kSsrcs4[] = {1, 2, 3, 4};
2021 // Create send streams.
2022 for (unsigned int i = 0; i < ARRAY_SIZE(kSsrcs4); ++i) {
2023 EXPECT_TRUE(channel_->AddSendStream(
2024 cricket::StreamParams::CreateLegacy(kSsrcs4[i])));
2025 }
buildbot@webrtc.org7e71b772014-06-13 01:14:01 +00002026 // Create a receive stream to check that none of the send streams end up in
2027 // the receive stream stats.
2028 EXPECT_TRUE(channel_->AddRecvStream(
2029 cricket::StreamParams::CreateLegacy(kSsrc2)));
wu@webrtc.org9dba5252013-08-05 20:36:57 +00002030 // We need send codec to be set to get all stats.
2031 std::vector<cricket::AudioCodec> codecs;
2032 codecs.push_back(kPcmuCodec);
2033 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
buildbot@webrtc.org7e71b772014-06-13 01:14:01 +00002034 EXPECT_TRUE(channel_->SetRecvCodecs(codecs));
wu@webrtc.org9dba5252013-08-05 20:36:57 +00002035
2036 cricket::VoiceMediaInfo info;
2037 EXPECT_EQ(true, channel_->GetStats(&info));
2038 EXPECT_EQ(static_cast<size_t>(ARRAY_SIZE(kSsrcs4)), info.senders.size());
2039
2040 // Verify the statistic information is correct.
2041 for (unsigned int i = 0; i < ARRAY_SIZE(kSsrcs4); ++i) {
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +00002042 EXPECT_EQ(kSsrcs4[i], info.senders[i].ssrc());
wu@webrtc.org9dba5252013-08-05 20:36:57 +00002043 EXPECT_EQ(kPcmuCodec.name, info.senders[i].codec_name);
2044 EXPECT_EQ(cricket::kIntStatValue, info.senders[i].bytes_sent);
2045 EXPECT_EQ(cricket::kIntStatValue, info.senders[i].packets_sent);
2046 EXPECT_EQ(cricket::kIntStatValue, info.senders[i].packets_lost);
2047 EXPECT_EQ(cricket::kFractionLostStatValue, info.senders[i].fraction_lost);
2048 EXPECT_EQ(cricket::kIntStatValue, info.senders[i].ext_seqnum);
2049 EXPECT_EQ(cricket::kIntStatValue, info.senders[i].rtt_ms);
2050 EXPECT_EQ(cricket::kIntStatValue, info.senders[i].jitter_ms);
buildbot@webrtc.org7e71b772014-06-13 01:14:01 +00002051 EXPECT_EQ(kPcmuCodec.name, info.senders[i].codec_name);
wu@webrtc.org9dba5252013-08-05 20:36:57 +00002052 }
2053
buildbot@webrtc.org7e71b772014-06-13 01:14:01 +00002054 EXPECT_EQ(0u, info.receivers.size());
2055 DeliverPacket(kPcmuFrame, sizeof(kPcmuFrame));
2056 EXPECT_EQ(true, channel_->GetStats(&info));
2057
wu@webrtc.org9dba5252013-08-05 20:36:57 +00002058 EXPECT_EQ(1u, info.receivers.size());
buildbot@webrtc.org7e71b772014-06-13 01:14:01 +00002059 EXPECT_EQ(cricket::kIntStatValue, info.receivers[0].bytes_rcvd);
2060 EXPECT_EQ(cricket::kIntStatValue, info.receivers[0].packets_rcvd);
2061 EXPECT_EQ(cricket::kIntStatValue, info.receivers[0].packets_lost);
2062 EXPECT_EQ(cricket::kIntStatValue, info.receivers[0].ext_seqnum);
2063 EXPECT_EQ(kPcmuCodec.name, info.receivers[0].codec_name);
minyue@webrtc.orgc0bd7be2015-02-18 15:24:13 +00002064 EXPECT_EQ(static_cast<float>(cricket::kNetStats.currentExpandRate) /
2065 (1 << 14), info.receivers[0].expand_rate);
2066 EXPECT_EQ(static_cast<float>(cricket::kNetStats.currentSpeechExpandRate) /
2067 (1 << 14), info.receivers[0].speech_expand_rate);
2068 EXPECT_EQ(static_cast<float>(cricket::kNetStats.currentSecondaryDecodedRate) /
2069 (1 << 14), info.receivers[0].secondary_decoded_rate);
wu@webrtc.org9dba5252013-08-05 20:36:57 +00002070}
2071
wu@webrtc.org9dba5252013-08-05 20:36:57 +00002072// Test that we can add and remove receive streams, and do proper send/playout.
2073// We can receive on multiple streams while sending one stream.
2074TEST_F(WebRtcVoiceEngineTestFake, PlayoutWithMultipleStreams) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002075 EXPECT_TRUE(SetupEngine());
2076 int channel_num1 = voe_.GetLastChannel();
2077
2078 // Start playout on the default channel.
2079 EXPECT_TRUE(channel_->SetOptions(options_conference_));
2080 EXPECT_TRUE(channel_->SetPlayout(true));
2081 EXPECT_TRUE(voe_.GetPlayout(channel_num1));
2082
2083 // Adding another stream should disable playout on the default channel.
2084 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(2)));
2085 int channel_num2 = voe_.GetLastChannel();
2086 std::vector<cricket::AudioCodec> codecs;
2087 codecs.push_back(kPcmuCodec);
2088 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
2089 EXPECT_TRUE(channel_->SetSend(cricket::SEND_MICROPHONE));
2090 EXPECT_TRUE(voe_.GetSend(channel_num1));
2091 EXPECT_FALSE(voe_.GetSend(channel_num2));
2092
2093 // Make sure only the new channel is played out.
2094 EXPECT_FALSE(voe_.GetPlayout(channel_num1));
2095 EXPECT_TRUE(voe_.GetPlayout(channel_num2));
2096
2097 // Adding yet another stream should have stream 2 and 3 enabled for playout.
2098 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(3)));
2099 int channel_num3 = voe_.GetLastChannel();
2100 EXPECT_FALSE(voe_.GetPlayout(channel_num1));
2101 EXPECT_TRUE(voe_.GetPlayout(channel_num2));
2102 EXPECT_TRUE(voe_.GetPlayout(channel_num3));
2103 EXPECT_FALSE(voe_.GetSend(channel_num3));
2104
2105 // Stop sending.
2106 EXPECT_TRUE(channel_->SetSend(cricket::SEND_NOTHING));
2107 EXPECT_FALSE(voe_.GetSend(channel_num1));
2108 EXPECT_FALSE(voe_.GetSend(channel_num2));
2109 EXPECT_FALSE(voe_.GetSend(channel_num3));
2110
2111 // Stop playout.
2112 EXPECT_TRUE(channel_->SetPlayout(false));
2113 EXPECT_FALSE(voe_.GetPlayout(channel_num1));
2114 EXPECT_FALSE(voe_.GetPlayout(channel_num2));
2115 EXPECT_FALSE(voe_.GetPlayout(channel_num3));
2116
2117 // Restart playout and make sure the default channel still is not played out.
2118 EXPECT_TRUE(channel_->SetPlayout(true));
2119 EXPECT_FALSE(voe_.GetPlayout(channel_num1));
2120 EXPECT_TRUE(voe_.GetPlayout(channel_num2));
2121 EXPECT_TRUE(voe_.GetPlayout(channel_num3));
2122
2123 // Now remove the new streams and verify that the default channel is
2124 // played out again.
2125 EXPECT_TRUE(channel_->RemoveRecvStream(3));
2126 EXPECT_TRUE(channel_->RemoveRecvStream(2));
2127
2128 EXPECT_TRUE(voe_.GetPlayout(channel_num1));
2129}
2130
2131// Test that we can set the devices to use.
2132TEST_F(WebRtcVoiceEngineTestFake, SetDevices) {
2133 EXPECT_TRUE(SetupEngine());
2134 int channel_num = voe_.GetLastChannel();
2135 std::vector<cricket::AudioCodec> codecs;
2136 codecs.push_back(kPcmuCodec);
2137 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
2138
2139 cricket::Device default_dev(cricket::kFakeDefaultDeviceName,
2140 cricket::kFakeDefaultDeviceId);
2141 cricket::Device dev(cricket::kFakeDeviceName,
2142 cricket::kFakeDeviceId);
2143
2144 // Test SetDevices() while not sending or playing.
2145 EXPECT_TRUE(engine_.SetDevices(&default_dev, &default_dev));
2146
2147 // Test SetDevices() while sending and playing.
2148 EXPECT_TRUE(engine_.SetLocalMonitor(true));
2149 EXPECT_TRUE(channel_->SetSend(cricket::SEND_MICROPHONE));
2150 EXPECT_TRUE(channel_->SetPlayout(true));
2151 EXPECT_TRUE(voe_.GetRecordingMicrophone());
2152 EXPECT_TRUE(voe_.GetSend(channel_num));
2153 EXPECT_TRUE(voe_.GetPlayout(channel_num));
2154
2155 EXPECT_TRUE(engine_.SetDevices(&dev, &dev));
2156
2157 EXPECT_TRUE(voe_.GetRecordingMicrophone());
2158 EXPECT_TRUE(voe_.GetSend(channel_num));
2159 EXPECT_TRUE(voe_.GetPlayout(channel_num));
2160
2161 // Test that failure to open newly selected devices does not prevent opening
2162 // ones after that.
2163 voe_.set_fail_start_recording_microphone(true);
2164 voe_.set_playout_fail_channel(channel_num);
2165 voe_.set_send_fail_channel(channel_num);
2166
2167 EXPECT_FALSE(engine_.SetDevices(&default_dev, &default_dev));
2168
2169 EXPECT_FALSE(voe_.GetRecordingMicrophone());
2170 EXPECT_FALSE(voe_.GetSend(channel_num));
2171 EXPECT_FALSE(voe_.GetPlayout(channel_num));
2172
2173 voe_.set_fail_start_recording_microphone(false);
2174 voe_.set_playout_fail_channel(-1);
2175 voe_.set_send_fail_channel(-1);
2176
2177 EXPECT_TRUE(engine_.SetDevices(&dev, &dev));
2178
2179 EXPECT_TRUE(voe_.GetRecordingMicrophone());
2180 EXPECT_TRUE(voe_.GetSend(channel_num));
2181 EXPECT_TRUE(voe_.GetPlayout(channel_num));
2182}
2183
2184// Test that we can set the devices to use even if we failed to
2185// open the initial ones.
2186TEST_F(WebRtcVoiceEngineTestFake, SetDevicesWithInitiallyBadDevices) {
2187 EXPECT_TRUE(SetupEngine());
2188 int channel_num = voe_.GetLastChannel();
2189 std::vector<cricket::AudioCodec> codecs;
2190 codecs.push_back(kPcmuCodec);
2191 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
2192
2193 cricket::Device default_dev(cricket::kFakeDefaultDeviceName,
2194 cricket::kFakeDefaultDeviceId);
2195 cricket::Device dev(cricket::kFakeDeviceName,
2196 cricket::kFakeDeviceId);
2197
2198 // Test that failure to open devices selected before starting
2199 // send/play does not prevent opening newly selected ones after that.
2200 voe_.set_fail_start_recording_microphone(true);
2201 voe_.set_playout_fail_channel(channel_num);
2202 voe_.set_send_fail_channel(channel_num);
2203
2204 EXPECT_TRUE(engine_.SetDevices(&default_dev, &default_dev));
2205
2206 EXPECT_FALSE(engine_.SetLocalMonitor(true));
2207 EXPECT_FALSE(channel_->SetSend(cricket::SEND_MICROPHONE));
2208 EXPECT_FALSE(channel_->SetPlayout(true));
2209 EXPECT_FALSE(voe_.GetRecordingMicrophone());
2210 EXPECT_FALSE(voe_.GetSend(channel_num));
2211 EXPECT_FALSE(voe_.GetPlayout(channel_num));
2212
2213 voe_.set_fail_start_recording_microphone(false);
2214 voe_.set_playout_fail_channel(-1);
2215 voe_.set_send_fail_channel(-1);
2216
2217 EXPECT_TRUE(engine_.SetDevices(&dev, &dev));
2218
2219 EXPECT_TRUE(voe_.GetRecordingMicrophone());
2220 EXPECT_TRUE(voe_.GetSend(channel_num));
2221 EXPECT_TRUE(voe_.GetPlayout(channel_num));
2222}
2223
2224// Test that we can create a channel configured for multi-point conferences,
2225// and start sending/playing out on it.
2226TEST_F(WebRtcVoiceEngineTestFake, ConferenceSendAndPlayout) {
2227 EXPECT_TRUE(SetupEngine());
2228 int channel_num = voe_.GetLastChannel();
2229 EXPECT_TRUE(channel_->SetOptions(options_conference_));
2230 std::vector<cricket::AudioCodec> codecs;
2231 codecs.push_back(kPcmuCodec);
2232 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
2233 EXPECT_TRUE(channel_->SetSend(cricket::SEND_MICROPHONE));
2234 EXPECT_TRUE(voe_.GetSend(channel_num));
2235}
2236
2237// Test that we can create a channel configured for Codian bridges,
2238// and start sending/playing out on it.
2239TEST_F(WebRtcVoiceEngineTestFake, CodianSendAndPlayout) {
2240 EXPECT_TRUE(SetupEngine());
2241 int channel_num = voe_.GetLastChannel();
2242 webrtc::AgcConfig agc_config;
2243 EXPECT_EQ(0, voe_.GetAgcConfig(agc_config));
2244 EXPECT_EQ(0, agc_config.targetLeveldBOv);
2245 EXPECT_TRUE(channel_->SetOptions(options_adjust_agc_));
2246 std::vector<cricket::AudioCodec> codecs;
2247 codecs.push_back(kPcmuCodec);
2248 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
2249 EXPECT_TRUE(channel_->SetSend(cricket::SEND_MICROPHONE));
2250 EXPECT_TRUE(voe_.GetSend(channel_num));
2251 EXPECT_EQ(0, voe_.GetAgcConfig(agc_config));
2252 EXPECT_EQ(agc_config.targetLeveldBOv, 10); // level was attenuated
2253 EXPECT_TRUE(channel_->SetPlayout(true));
2254 EXPECT_TRUE(voe_.GetPlayout(channel_num));
2255 EXPECT_TRUE(channel_->SetSend(cricket::SEND_NOTHING));
2256 EXPECT_FALSE(voe_.GetSend(channel_num));
2257 EXPECT_EQ(0, voe_.GetAgcConfig(agc_config));
2258 EXPECT_EQ(0, agc_config.targetLeveldBOv); // level was restored
2259 EXPECT_TRUE(channel_->SetPlayout(false));
2260 EXPECT_FALSE(voe_.GetPlayout(channel_num));
2261}
2262
wu@webrtc.org97077a32013-10-25 21:18:33 +00002263TEST_F(WebRtcVoiceEngineTestFake, TxAgcConfigViaOptions) {
2264 EXPECT_TRUE(SetupEngine());
2265 webrtc::AgcConfig agc_config;
2266 EXPECT_EQ(0, voe_.GetAgcConfig(agc_config));
2267 EXPECT_EQ(0, agc_config.targetLeveldBOv);
2268
2269 cricket::AudioOptions options;
2270 options.tx_agc_target_dbov.Set(3);
2271 options.tx_agc_digital_compression_gain.Set(9);
2272 options.tx_agc_limiter.Set(true);
2273 options.auto_gain_control.Set(true);
2274 EXPECT_TRUE(engine_.SetOptions(options));
2275
2276 EXPECT_EQ(0, voe_.GetAgcConfig(agc_config));
2277 EXPECT_EQ(3, agc_config.targetLeveldBOv);
2278 EXPECT_EQ(9, agc_config.digitalCompressionGaindB);
2279 EXPECT_TRUE(agc_config.limiterEnable);
2280
2281 // Check interaction with adjust_agc_delta. Both should be respected, for
2282 // backwards compatibility.
2283 options.adjust_agc_delta.Set(-10);
2284 EXPECT_TRUE(engine_.SetOptions(options));
2285
2286 EXPECT_EQ(0, voe_.GetAgcConfig(agc_config));
2287 EXPECT_EQ(13, agc_config.targetLeveldBOv);
2288}
2289
2290TEST_F(WebRtcVoiceEngineTestFake, RxAgcConfigViaOptions) {
2291 EXPECT_TRUE(SetupEngine());
2292 int channel_num = voe_.GetLastChannel();
2293 cricket::AudioOptions options;
2294 options.rx_agc_target_dbov.Set(6);
2295 options.rx_agc_digital_compression_gain.Set(0);
2296 options.rx_agc_limiter.Set(true);
2297 options.rx_auto_gain_control.Set(true);
2298 EXPECT_TRUE(channel_->SetOptions(options));
2299
2300 webrtc::AgcConfig agc_config;
2301 EXPECT_EQ(0, engine_.voe()->processing()->GetRxAgcConfig(
2302 channel_num, agc_config));
2303 EXPECT_EQ(6, agc_config.targetLeveldBOv);
2304 EXPECT_EQ(0, agc_config.digitalCompressionGaindB);
2305 EXPECT_TRUE(agc_config.limiterEnable);
2306}
2307
2308TEST_F(WebRtcVoiceEngineTestFake, SampleRatesViaOptions) {
2309 EXPECT_TRUE(SetupEngine());
2310 cricket::AudioOptions options;
2311 options.recording_sample_rate.Set(48000u);
2312 options.playout_sample_rate.Set(44100u);
2313 EXPECT_TRUE(engine_.SetOptions(options));
2314
2315 unsigned int recording_sample_rate, playout_sample_rate;
2316 EXPECT_EQ(0, voe_.RecordingSampleRate(&recording_sample_rate));
2317 EXPECT_EQ(0, voe_.PlayoutSampleRate(&playout_sample_rate));
2318 EXPECT_EQ(48000u, recording_sample_rate);
2319 EXPECT_EQ(44100u, playout_sample_rate);
2320}
2321
2322TEST_F(WebRtcVoiceEngineTestFake, TraceFilterViaTraceOptions) {
2323 EXPECT_TRUE(SetupEngine());
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002324 engine_.SetLogging(rtc::LS_INFO, "");
wu@webrtc.org97077a32013-10-25 21:18:33 +00002325 EXPECT_EQ(
2326 // Info:
2327 webrtc::kTraceStateInfo | webrtc::kTraceInfo |
2328 // Warning:
2329 webrtc::kTraceTerseInfo | webrtc::kTraceWarning |
2330 // Error:
2331 webrtc::kTraceError | webrtc::kTraceCritical,
2332 static_cast<int>(trace_wrapper_->filter_));
2333 // Now set it explicitly
2334 std::string filter =
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002335 "tracefilter " + rtc::ToString(webrtc::kTraceDefault);
2336 engine_.SetLogging(rtc::LS_VERBOSE, filter.c_str());
wu@webrtc.org97077a32013-10-25 21:18:33 +00002337 EXPECT_EQ(static_cast<unsigned int>(webrtc::kTraceDefault),
2338 trace_wrapper_->filter_);
2339}
2340
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002341// Test that we can set the outgoing SSRC properly.
2342// SSRC is set in SetupEngine by calling AddSendStream.
2343TEST_F(WebRtcVoiceEngineTestFake, SetSendSsrc) {
2344 EXPECT_TRUE(SetupEngine());
2345 int channel_num = voe_.GetLastChannel();
2346 unsigned int send_ssrc;
2347 EXPECT_EQ(0, voe_.GetLocalSSRC(channel_num, send_ssrc));
2348 EXPECT_NE(0U, send_ssrc);
2349 EXPECT_EQ(0, voe_.GetLocalSSRC(channel_num, send_ssrc));
2350 EXPECT_EQ(kSsrc1, send_ssrc);
2351}
2352
2353TEST_F(WebRtcVoiceEngineTestFake, GetStats) {
2354 // Setup. We need send codec to be set to get all stats.
2355 EXPECT_TRUE(SetupEngine());
buildbot@webrtc.org7e71b772014-06-13 01:14:01 +00002356 // SetupEngine adds a send stream with kSsrc1, so the receive stream has to
2357 // use a different SSRC.
2358 EXPECT_TRUE(channel_->AddRecvStream(
2359 cricket::StreamParams::CreateLegacy(kSsrc2)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002360 std::vector<cricket::AudioCodec> codecs;
2361 codecs.push_back(kPcmuCodec);
2362 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
buildbot@webrtc.org7e71b772014-06-13 01:14:01 +00002363 EXPECT_TRUE(channel_->SetRecvCodecs(codecs));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002364
2365 cricket::VoiceMediaInfo info;
2366 EXPECT_EQ(true, channel_->GetStats(&info));
2367 EXPECT_EQ(1u, info.senders.size());
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +00002368 EXPECT_EQ(kSsrc1, info.senders[0].ssrc());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002369 EXPECT_EQ(kPcmuCodec.name, info.senders[0].codec_name);
2370 EXPECT_EQ(cricket::kIntStatValue, info.senders[0].bytes_sent);
2371 EXPECT_EQ(cricket::kIntStatValue, info.senders[0].packets_sent);
2372 EXPECT_EQ(cricket::kIntStatValue, info.senders[0].packets_lost);
2373 EXPECT_EQ(cricket::kFractionLostStatValue, info.senders[0].fraction_lost);
2374 EXPECT_EQ(cricket::kIntStatValue, info.senders[0].ext_seqnum);
2375 EXPECT_EQ(cricket::kIntStatValue, info.senders[0].rtt_ms);
2376 EXPECT_EQ(cricket::kIntStatValue, info.senders[0].jitter_ms);
buildbot@webrtc.org7e71b772014-06-13 01:14:01 +00002377 EXPECT_EQ(kPcmuCodec.name, info.senders[0].codec_name);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002378 // TODO(sriniv): Add testing for more fields. These are not populated
2379 // in FakeWebrtcVoiceEngine yet.
2380 // EXPECT_EQ(cricket::kIntStatValue, info.senders[0].audio_level);
2381 // EXPECT_EQ(cricket::kIntStatValue, info.senders[0].echo_delay_median_ms);
2382 // EXPECT_EQ(cricket::kIntStatValue, info.senders[0].echo_delay_std_ms);
2383 // EXPECT_EQ(cricket::kIntStatValue, info.senders[0].echo_return_loss);
2384 // EXPECT_EQ(cricket::kIntStatValue,
2385 // info.senders[0].echo_return_loss_enhancement);
2386
buildbot@webrtc.org7e71b772014-06-13 01:14:01 +00002387 EXPECT_EQ(0u, info.receivers.size());
2388 DeliverPacket(kPcmuFrame, sizeof(kPcmuFrame));
2389 EXPECT_EQ(true, channel_->GetStats(&info));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002390 EXPECT_EQ(1u, info.receivers.size());
buildbot@webrtc.org7e71b772014-06-13 01:14:01 +00002391
2392 EXPECT_EQ(cricket::kIntStatValue, info.receivers[0].bytes_rcvd);
2393 EXPECT_EQ(cricket::kIntStatValue, info.receivers[0].packets_rcvd);
2394 EXPECT_EQ(cricket::kIntStatValue, info.receivers[0].packets_lost);
2395 EXPECT_EQ(cricket::kIntStatValue, info.receivers[0].ext_seqnum);
2396 EXPECT_EQ(kPcmuCodec.name, info.receivers[0].codec_name);
minyue@webrtc.orgc0bd7be2015-02-18 15:24:13 +00002397 EXPECT_EQ(static_cast<float>(cricket::kNetStats.currentExpandRate) /
2398 (1 << 14), info.receivers[0].expand_rate);
2399 EXPECT_EQ(static_cast<float>(cricket::kNetStats.currentSpeechExpandRate) /
2400 (1 << 14), info.receivers[0].speech_expand_rate);
2401 EXPECT_EQ(static_cast<float>(cricket::kNetStats.currentSecondaryDecodedRate) /
2402 (1 << 14), info.receivers[0].secondary_decoded_rate);
buildbot@webrtc.org7e71b772014-06-13 01:14:01 +00002403 // TODO(sriniv): Add testing for more receiver fields.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002404}
2405
2406// Test that we can set the outgoing SSRC properly with multiple streams.
2407// SSRC is set in SetupEngine by calling AddSendStream.
2408TEST_F(WebRtcVoiceEngineTestFake, SetSendSsrcWithMultipleStreams) {
2409 EXPECT_TRUE(SetupEngine());
2410 EXPECT_TRUE(channel_->SetOptions(options_conference_));
2411 int channel_num1 = voe_.GetLastChannel();
2412 unsigned int send_ssrc;
2413 EXPECT_EQ(0, voe_.GetLocalSSRC(channel_num1, send_ssrc));
2414 EXPECT_EQ(kSsrc1, send_ssrc);
2415
2416 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(2)));
2417 int channel_num2 = voe_.GetLastChannel();
2418 EXPECT_EQ(0, voe_.GetLocalSSRC(channel_num2, send_ssrc));
2419 EXPECT_EQ(kSsrc1, send_ssrc);
2420}
2421
2422// Test that the local SSRC is the same on sending and receiving channels if the
2423// receive channel is created before the send channel.
2424TEST_F(WebRtcVoiceEngineTestFake, SetSendSsrcAfterCreatingReceiveChannel) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002425 EXPECT_TRUE(engine_.Init(rtc::Thread::Current()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002426 channel_ = engine_.CreateChannel();
2427 EXPECT_TRUE(channel_->SetOptions(options_conference_));
2428
2429 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(1)));
2430 int receive_channel_num = voe_.GetLastChannel();
2431 EXPECT_TRUE(channel_->AddSendStream(
2432 cricket::StreamParams::CreateLegacy(1234)));
2433 int send_channel_num = voe_.GetLastChannel();
2434
2435 unsigned int ssrc = 0;
2436 EXPECT_EQ(0, voe_.GetLocalSSRC(send_channel_num, ssrc));
2437 EXPECT_EQ(1234U, ssrc);
2438 ssrc = 0;
2439 EXPECT_EQ(0, voe_.GetLocalSSRC(receive_channel_num, ssrc));
2440 EXPECT_EQ(1234U, ssrc);
2441}
2442
2443// Test that we can properly receive packets.
2444TEST_F(WebRtcVoiceEngineTestFake, Recv) {
2445 EXPECT_TRUE(SetupEngine());
2446 int channel_num = voe_.GetLastChannel();
2447 DeliverPacket(kPcmuFrame, sizeof(kPcmuFrame));
2448 EXPECT_TRUE(voe_.CheckPacket(channel_num, kPcmuFrame,
2449 sizeof(kPcmuFrame)));
2450}
2451
2452// Test that we can properly receive packets on multiple streams.
2453TEST_F(WebRtcVoiceEngineTestFake, RecvWithMultipleStreams) {
2454 EXPECT_TRUE(SetupEngine());
2455 EXPECT_TRUE(channel_->SetOptions(options_conference_));
2456 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(1)));
2457 int channel_num1 = voe_.GetLastChannel();
2458 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(2)));
2459 int channel_num2 = voe_.GetLastChannel();
2460 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(3)));
2461 int channel_num3 = voe_.GetLastChannel();
2462 // Create packets with the right SSRCs.
2463 char packets[4][sizeof(kPcmuFrame)];
2464 for (size_t i = 0; i < ARRAY_SIZE(packets); ++i) {
2465 memcpy(packets[i], kPcmuFrame, sizeof(kPcmuFrame));
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002466 rtc::SetBE32(packets[i] + 8, static_cast<uint32>(i));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002467 }
2468 EXPECT_TRUE(voe_.CheckNoPacket(channel_num1));
2469 EXPECT_TRUE(voe_.CheckNoPacket(channel_num2));
2470 EXPECT_TRUE(voe_.CheckNoPacket(channel_num3));
2471 DeliverPacket(packets[0], sizeof(packets[0]));
2472 EXPECT_TRUE(voe_.CheckNoPacket(channel_num1));
2473 EXPECT_TRUE(voe_.CheckNoPacket(channel_num2));
2474 EXPECT_TRUE(voe_.CheckNoPacket(channel_num3));
2475 DeliverPacket(packets[1], sizeof(packets[1]));
2476 EXPECT_TRUE(voe_.CheckPacket(channel_num1, packets[1],
2477 sizeof(packets[1])));
2478 EXPECT_TRUE(voe_.CheckNoPacket(channel_num2));
2479 EXPECT_TRUE(voe_.CheckNoPacket(channel_num3));
2480 DeliverPacket(packets[2], sizeof(packets[2]));
2481 EXPECT_TRUE(voe_.CheckNoPacket(channel_num1));
2482 EXPECT_TRUE(voe_.CheckPacket(channel_num2, packets[2],
2483 sizeof(packets[2])));
2484 EXPECT_TRUE(voe_.CheckNoPacket(channel_num3));
2485 DeliverPacket(packets[3], sizeof(packets[3]));
2486 EXPECT_TRUE(voe_.CheckNoPacket(channel_num1));
2487 EXPECT_TRUE(voe_.CheckNoPacket(channel_num2));
2488 EXPECT_TRUE(voe_.CheckPacket(channel_num3, packets[3],
2489 sizeof(packets[3])));
2490 EXPECT_TRUE(channel_->RemoveRecvStream(3));
2491 EXPECT_TRUE(channel_->RemoveRecvStream(2));
2492 EXPECT_TRUE(channel_->RemoveRecvStream(1));
2493}
2494
2495// Test that we properly handle failures to add a stream.
2496TEST_F(WebRtcVoiceEngineTestFake, AddStreamFail) {
2497 EXPECT_TRUE(SetupEngine());
2498 voe_.set_fail_create_channel(true);
2499 EXPECT_TRUE(channel_->SetOptions(options_conference_));
2500 EXPECT_FALSE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(2)));
2501
2502 // In 1:1 call, we should not try to create a new channel.
2503 cricket::AudioOptions options_no_conference_;
2504 options_no_conference_.conference_mode.Set(false);
2505 EXPECT_TRUE(channel_->SetOptions(options_no_conference_));
2506 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(2)));
2507}
2508
2509// Test that AddRecvStream doesn't create new channel for 1:1 call.
2510TEST_F(WebRtcVoiceEngineTestFake, AddRecvStream1On1) {
2511 EXPECT_TRUE(SetupEngine());
2512 int channel_num = voe_.GetLastChannel();
2513 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(1)));
2514 EXPECT_EQ(channel_num, voe_.GetLastChannel());
2515}
2516
2517// Test that after adding a recv stream, we do not decode more codecs than
2518// those previously passed into SetRecvCodecs.
2519TEST_F(WebRtcVoiceEngineTestFake, AddRecvStreamUnsupportedCodec) {
2520 EXPECT_TRUE(SetupEngine());
2521 EXPECT_TRUE(channel_->SetOptions(options_conference_));
2522 std::vector<cricket::AudioCodec> codecs;
2523 codecs.push_back(kIsacCodec);
2524 codecs.push_back(kPcmuCodec);
2525 EXPECT_TRUE(channel_->SetRecvCodecs(codecs));
2526 EXPECT_TRUE(channel_->AddRecvStream(
2527 cricket::StreamParams::CreateLegacy(kSsrc1)));
2528 int channel_num2 = voe_.GetLastChannel();
2529 webrtc::CodecInst gcodec;
minyue@webrtc.orgf9b5c1b2015-02-17 12:36:41 +00002530 rtc::strcpyn(gcodec.plname, ARRAY_SIZE(gcodec.plname), "opus");
2531 gcodec.plfreq = 48000;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002532 gcodec.channels = 2;
2533 EXPECT_EQ(-1, voe_.GetRecPayloadType(channel_num2, gcodec));
2534}
2535
2536// Test that we properly clean up any streams that were added, even if
2537// not explicitly removed.
2538TEST_F(WebRtcVoiceEngineTestFake, StreamCleanup) {
2539 EXPECT_TRUE(SetupEngine());
2540 EXPECT_TRUE(channel_->SetOptions(options_conference_));
2541 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(1)));
2542 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(2)));
2543 EXPECT_EQ(3, voe_.GetNumChannels()); // default channel + 2 added
2544 delete channel_;
2545 channel_ = NULL;
2546 EXPECT_EQ(0, voe_.GetNumChannels());
2547}
2548
wu@webrtc.org78187522013-10-07 23:32:02 +00002549TEST_F(WebRtcVoiceEngineTestFake, TestAddRecvStreamFailWithZeroSsrc) {
2550 EXPECT_TRUE(SetupEngine());
2551 EXPECT_FALSE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(0)));
2552}
2553
2554TEST_F(WebRtcVoiceEngineTestFake, TestNoLeakingWhenAddRecvStreamFail) {
2555 EXPECT_TRUE(SetupEngine());
2556 // Stream 1 reuses default channel.
2557 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(1)));
2558 // Manually delete default channel to simulate a failure.
2559 int default_channel = voe_.GetLastChannel();
2560 EXPECT_EQ(0, voe_.DeleteChannel(default_channel));
2561 // Add recv stream 2 should fail because default channel is gone.
2562 EXPECT_FALSE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(2)));
2563 int new_channel = voe_.GetLastChannel();
2564 EXPECT_NE(default_channel, new_channel);
2565 // The last created channel should have already been deleted.
2566 EXPECT_EQ(-1, voe_.DeleteChannel(new_channel));
2567}
2568
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002569// Test the InsertDtmf on default send stream as caller.
2570TEST_F(WebRtcVoiceEngineTestFake, InsertDtmfOnDefaultSendStreamAsCaller) {
2571 TestInsertDtmf(0, true);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002572}
2573
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00002574// Test the InsertDtmf on default send stream as callee
2575TEST_F(WebRtcVoiceEngineTestFake, InsertDtmfOnDefaultSendStreamAsCallee) {
2576 TestInsertDtmf(0, false);
2577}
2578
2579// Test the InsertDtmf on specified send stream as caller.
2580TEST_F(WebRtcVoiceEngineTestFake, InsertDtmfOnSendStreamAsCaller) {
2581 TestInsertDtmf(kSsrc1, true);
2582}
2583
2584// Test the InsertDtmf on specified send stream as callee.
2585TEST_F(WebRtcVoiceEngineTestFake, InsertDtmfOnSendStreamAsCallee) {
2586 TestInsertDtmf(kSsrc1, false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002587}
2588
2589// Test that we can play a ringback tone properly in a single-stream call.
2590TEST_F(WebRtcVoiceEngineTestFake, PlayRingback) {
2591 EXPECT_TRUE(SetupEngine());
2592 int channel_num = voe_.GetLastChannel();
2593 EXPECT_EQ(0, voe_.IsPlayingFileLocally(channel_num));
2594 // Check we fail if no ringback tone specified.
2595 EXPECT_FALSE(channel_->PlayRingbackTone(0, true, true));
2596 EXPECT_EQ(0, voe_.IsPlayingFileLocally(channel_num));
2597 // Check we can set and play a ringback tone.
wu@webrtc.org9caf2762013-12-11 18:25:07 +00002598 EXPECT_TRUE(channel_->SetRingbackTone(
2599 kRingbackTone, static_cast<int>(strlen(kRingbackTone))));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002600 EXPECT_TRUE(channel_->PlayRingbackTone(0, true, true));
2601 EXPECT_EQ(1, voe_.IsPlayingFileLocally(channel_num));
2602 // Check we can stop the tone manually.
2603 EXPECT_TRUE(channel_->PlayRingbackTone(0, false, false));
2604 EXPECT_EQ(0, voe_.IsPlayingFileLocally(channel_num));
2605 // Check we stop the tone if a packet arrives.
2606 EXPECT_TRUE(channel_->PlayRingbackTone(0, true, true));
2607 EXPECT_EQ(1, voe_.IsPlayingFileLocally(channel_num));
2608 DeliverPacket(kPcmuFrame, sizeof(kPcmuFrame));
2609 EXPECT_EQ(0, voe_.IsPlayingFileLocally(channel_num));
2610}
2611
2612// Test that we can play a ringback tone properly in a multi-stream call.
2613TEST_F(WebRtcVoiceEngineTestFake, PlayRingbackWithMultipleStreams) {
2614 EXPECT_TRUE(SetupEngine());
2615 EXPECT_TRUE(channel_->SetOptions(options_conference_));
2616 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(1)));
2617 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(2)));
2618 int channel_num = voe_.GetLastChannel();
2619 EXPECT_EQ(0, voe_.IsPlayingFileLocally(channel_num));
2620 // Check we fail if no ringback tone specified.
2621 EXPECT_FALSE(channel_->PlayRingbackTone(2, true, true));
2622 EXPECT_EQ(0, voe_.IsPlayingFileLocally(channel_num));
2623 // Check we can set and play a ringback tone on the correct ssrc.
wu@webrtc.org9caf2762013-12-11 18:25:07 +00002624 EXPECT_TRUE(channel_->SetRingbackTone(
2625 kRingbackTone, static_cast<int>(strlen(kRingbackTone))));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002626 EXPECT_FALSE(channel_->PlayRingbackTone(77, true, true));
2627 EXPECT_TRUE(channel_->PlayRingbackTone(2, true, true));
2628 EXPECT_EQ(1, voe_.IsPlayingFileLocally(channel_num));
2629 // Check we can stop the tone manually.
2630 EXPECT_TRUE(channel_->PlayRingbackTone(2, false, false));
2631 EXPECT_EQ(0, voe_.IsPlayingFileLocally(channel_num));
2632 // Check we stop the tone if a packet arrives, but only with the right SSRC.
2633 EXPECT_TRUE(channel_->PlayRingbackTone(2, true, true));
2634 EXPECT_EQ(1, voe_.IsPlayingFileLocally(channel_num));
2635 // Send a packet with SSRC 1; the tone should not stop.
2636 DeliverPacket(kPcmuFrame, sizeof(kPcmuFrame));
2637 EXPECT_EQ(1, voe_.IsPlayingFileLocally(channel_num));
2638 // Send a packet with SSRC 2; the tone should stop.
2639 char packet[sizeof(kPcmuFrame)];
2640 memcpy(packet, kPcmuFrame, sizeof(kPcmuFrame));
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002641 rtc::SetBE32(packet + 8, 2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002642 DeliverPacket(packet, sizeof(packet));
2643 EXPECT_EQ(0, voe_.IsPlayingFileLocally(channel_num));
2644}
2645
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002646TEST_F(WebRtcVoiceEngineTestFake, MediaEngineCallbackOnError) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002647 rtc::scoped_ptr<ChannelErrorListener> listener;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002648 cricket::WebRtcVoiceMediaChannel* media_channel;
2649 unsigned int ssrc = 0;
2650
2651 EXPECT_TRUE(SetupEngine());
2652 EXPECT_TRUE(channel_->SetOptions(options_conference_));
2653 EXPECT_TRUE(channel_->SetSend(cricket::SEND_MICROPHONE));
2654
2655 media_channel = static_cast<cricket::WebRtcVoiceMediaChannel*>(channel_);
2656 listener.reset(new ChannelErrorListener(channel_));
2657
2658 // Test on WebRtc VoE channel.
2659 voe_.TriggerCallbackOnError(media_channel->voe_channel(),
2660 VE_SATURATION_WARNING);
2661 EXPECT_EQ(cricket::VoiceMediaChannel::ERROR_REC_DEVICE_SATURATION,
2662 listener->error());
2663 EXPECT_NE(-1, voe_.GetLocalSSRC(voe_.GetLastChannel(), ssrc));
2664 EXPECT_EQ(ssrc, listener->ssrc());
2665
2666 listener->Reset();
2667 voe_.TriggerCallbackOnError(-1, VE_TYPING_NOISE_WARNING);
2668 EXPECT_EQ(cricket::VoiceMediaChannel::ERROR_REC_TYPING_NOISE_DETECTED,
2669 listener->error());
2670 EXPECT_EQ(0U, listener->ssrc());
2671
2672 // Add another stream and test on that.
2673 ++ssrc;
2674 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(
2675 ssrc)));
2676 listener->Reset();
2677 voe_.TriggerCallbackOnError(voe_.GetLastChannel(),
2678 VE_SATURATION_WARNING);
2679 EXPECT_EQ(cricket::VoiceMediaChannel::ERROR_REC_DEVICE_SATURATION,
2680 listener->error());
2681 EXPECT_EQ(ssrc, listener->ssrc());
2682
2683 // Testing a non-existing channel.
2684 listener->Reset();
2685 voe_.TriggerCallbackOnError(voe_.GetLastChannel() + 2,
2686 VE_SATURATION_WARNING);
2687 EXPECT_EQ(0, listener->error());
2688}
2689
2690TEST_F(WebRtcVoiceEngineTestFake, TestSetPlayoutError) {
2691 EXPECT_TRUE(SetupEngine());
2692 EXPECT_TRUE(channel_->SetOptions(options_conference_));
2693 std::vector<cricket::AudioCodec> codecs;
2694 codecs.push_back(kPcmuCodec);
2695 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
2696 EXPECT_TRUE(channel_->SetSend(cricket::SEND_MICROPHONE));
2697 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(2)));
2698 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(3)));
2699 EXPECT_TRUE(channel_->SetPlayout(true));
2700 voe_.set_playout_fail_channel(voe_.GetLastChannel() - 1);
2701 EXPECT_TRUE(channel_->SetPlayout(false));
2702 EXPECT_FALSE(channel_->SetPlayout(true));
2703}
2704
2705// Test that the Registering/Unregistering with the
2706// webrtcvoiceengine works as expected
2707TEST_F(WebRtcVoiceEngineTestFake, RegisterVoiceProcessor) {
2708 EXPECT_TRUE(SetupEngine());
2709 EXPECT_TRUE(channel_->SetOptions(options_conference_));
2710 EXPECT_TRUE(channel_->AddRecvStream(
2711 cricket::StreamParams::CreateLegacy(kSsrc2)));
2712 cricket::FakeMediaProcessor vp_1;
2713 cricket::FakeMediaProcessor vp_2;
2714
2715 EXPECT_FALSE(engine_.RegisterProcessor(kSsrc2, &vp_1, cricket::MPD_TX));
2716 EXPECT_TRUE(engine_.RegisterProcessor(kSsrc2, &vp_1, cricket::MPD_RX));
2717 EXPECT_TRUE(engine_.RegisterProcessor(kSsrc2, &vp_2, cricket::MPD_RX));
2718 voe_.TriggerProcessPacket(cricket::MPD_RX);
2719 voe_.TriggerProcessPacket(cricket::MPD_TX);
2720
2721 EXPECT_TRUE(voe_.IsExternalMediaProcessorRegistered());
2722 EXPECT_EQ(1, vp_1.voice_frame_count());
2723 EXPECT_EQ(1, vp_2.voice_frame_count());
2724
2725 EXPECT_TRUE(engine_.UnregisterProcessor(kSsrc2,
2726 &vp_2,
2727 cricket::MPD_RX));
2728 voe_.TriggerProcessPacket(cricket::MPD_RX);
2729 EXPECT_TRUE(voe_.IsExternalMediaProcessorRegistered());
2730 EXPECT_EQ(1, vp_2.voice_frame_count());
2731 EXPECT_EQ(2, vp_1.voice_frame_count());
2732
2733 EXPECT_TRUE(engine_.UnregisterProcessor(kSsrc2,
2734 &vp_1,
2735 cricket::MPD_RX));
2736 voe_.TriggerProcessPacket(cricket::MPD_RX);
2737 EXPECT_FALSE(voe_.IsExternalMediaProcessorRegistered());
2738 EXPECT_EQ(2, vp_1.voice_frame_count());
2739
2740 EXPECT_FALSE(engine_.RegisterProcessor(kSsrc1, &vp_1, cricket::MPD_RX));
2741 EXPECT_TRUE(engine_.RegisterProcessor(kSsrc1, &vp_1, cricket::MPD_TX));
2742 voe_.TriggerProcessPacket(cricket::MPD_RX);
2743 voe_.TriggerProcessPacket(cricket::MPD_TX);
2744 EXPECT_TRUE(voe_.IsExternalMediaProcessorRegistered());
2745 EXPECT_EQ(3, vp_1.voice_frame_count());
2746
2747 EXPECT_TRUE(engine_.UnregisterProcessor(kSsrc1,
2748 &vp_1,
2749 cricket::MPD_RX_AND_TX));
2750 voe_.TriggerProcessPacket(cricket::MPD_TX);
2751 EXPECT_FALSE(voe_.IsExternalMediaProcessorRegistered());
2752 EXPECT_EQ(3, vp_1.voice_frame_count());
2753 EXPECT_TRUE(channel_->RemoveRecvStream(kSsrc2));
2754 EXPECT_FALSE(engine_.RegisterProcessor(kSsrc2, &vp_1, cricket::MPD_RX));
2755 EXPECT_FALSE(voe_.IsExternalMediaProcessorRegistered());
2756
2757 // Test that we can register a processor on the receive channel on SSRC 0.
2758 // This tests the 1:1 case when the receive SSRC is unknown.
2759 EXPECT_TRUE(engine_.RegisterProcessor(0, &vp_1, cricket::MPD_RX));
2760 voe_.TriggerProcessPacket(cricket::MPD_RX);
2761 EXPECT_TRUE(voe_.IsExternalMediaProcessorRegistered());
2762 EXPECT_EQ(4, vp_1.voice_frame_count());
2763 EXPECT_TRUE(engine_.UnregisterProcessor(0,
2764 &vp_1,
2765 cricket::MPD_RX));
2766
2767 // The following tests test that FindChannelNumFromSsrc is doing
2768 // what we expect.
2769 // pick an invalid ssrc and make sure we can't register
2770 EXPECT_FALSE(engine_.RegisterProcessor(99,
2771 &vp_1,
2772 cricket::MPD_RX));
2773 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(1)));
2774 EXPECT_TRUE(engine_.RegisterProcessor(1,
2775 &vp_1,
2776 cricket::MPD_RX));
2777 EXPECT_TRUE(engine_.UnregisterProcessor(1,
2778 &vp_1,
2779 cricket::MPD_RX));
2780 EXPECT_FALSE(engine_.RegisterProcessor(1,
2781 &vp_1,
2782 cricket::MPD_TX));
2783 EXPECT_TRUE(channel_->RemoveRecvStream(1));
2784}
2785
2786TEST_F(WebRtcVoiceEngineTestFake, SetAudioOptions) {
2787 EXPECT_TRUE(SetupEngine());
2788
2789 bool ec_enabled;
2790 webrtc::EcModes ec_mode;
2791 bool ec_metrics_enabled;
2792 webrtc::AecmModes aecm_mode;
2793 bool cng_enabled;
2794 bool agc_enabled;
2795 webrtc::AgcModes agc_mode;
2796 webrtc::AgcConfig agc_config;
2797 bool ns_enabled;
2798 webrtc::NsModes ns_mode;
2799 bool highpass_filter_enabled;
2800 bool stereo_swapping_enabled;
2801 bool typing_detection_enabled;
2802 voe_.GetEcStatus(ec_enabled, ec_mode);
2803 voe_.GetEcMetricsStatus(ec_metrics_enabled);
2804 voe_.GetAecmMode(aecm_mode, cng_enabled);
2805 voe_.GetAgcStatus(agc_enabled, agc_mode);
2806 voe_.GetAgcConfig(agc_config);
2807 voe_.GetNsStatus(ns_enabled, ns_mode);
2808 highpass_filter_enabled = voe_.IsHighPassFilterEnabled();
2809 stereo_swapping_enabled = voe_.IsStereoChannelSwappingEnabled();
2810 voe_.GetTypingDetectionStatus(typing_detection_enabled);
2811 EXPECT_TRUE(ec_enabled);
2812 EXPECT_TRUE(ec_metrics_enabled);
2813 EXPECT_FALSE(cng_enabled);
2814 EXPECT_TRUE(agc_enabled);
2815 EXPECT_EQ(0, agc_config.targetLeveldBOv);
2816 EXPECT_TRUE(ns_enabled);
2817 EXPECT_TRUE(highpass_filter_enabled);
2818 EXPECT_FALSE(stereo_swapping_enabled);
2819 EXPECT_TRUE(typing_detection_enabled);
2820 EXPECT_EQ(ec_mode, webrtc::kEcConference);
2821 EXPECT_EQ(ns_mode, webrtc::kNsHighSuppression);
2822
2823 // Nothing set, so all ignored.
2824 cricket::AudioOptions options;
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00002825 ASSERT_TRUE(engine_.SetOptions(options));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002826 voe_.GetEcStatus(ec_enabled, ec_mode);
2827 voe_.GetEcMetricsStatus(ec_metrics_enabled);
2828 voe_.GetAecmMode(aecm_mode, cng_enabled);
2829 voe_.GetAgcStatus(agc_enabled, agc_mode);
2830 voe_.GetAgcConfig(agc_config);
2831 voe_.GetNsStatus(ns_enabled, ns_mode);
2832 highpass_filter_enabled = voe_.IsHighPassFilterEnabled();
2833 stereo_swapping_enabled = voe_.IsStereoChannelSwappingEnabled();
2834 voe_.GetTypingDetectionStatus(typing_detection_enabled);
2835 EXPECT_TRUE(ec_enabled);
2836 EXPECT_TRUE(ec_metrics_enabled);
2837 EXPECT_FALSE(cng_enabled);
2838 EXPECT_TRUE(agc_enabled);
2839 EXPECT_EQ(0, agc_config.targetLeveldBOv);
2840 EXPECT_TRUE(ns_enabled);
2841 EXPECT_TRUE(highpass_filter_enabled);
2842 EXPECT_FALSE(stereo_swapping_enabled);
2843 EXPECT_TRUE(typing_detection_enabled);
2844 EXPECT_EQ(ec_mode, webrtc::kEcConference);
2845 EXPECT_EQ(ns_mode, webrtc::kNsHighSuppression);
Henrik Lundin64dad832015-05-11 12:44:23 +02002846 EXPECT_EQ(50, voe_.GetNetEqCapacity()); // From GetDefaultEngineOptions().
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002847
2848 // Turn echo cancellation off
2849 options.echo_cancellation.Set(false);
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00002850 ASSERT_TRUE(engine_.SetOptions(options));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002851 voe_.GetEcStatus(ec_enabled, ec_mode);
2852 EXPECT_FALSE(ec_enabled);
2853
2854 // Turn echo cancellation back on, with settings, and make sure
2855 // nothing else changed.
2856 options.echo_cancellation.Set(true);
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00002857 ASSERT_TRUE(engine_.SetOptions(options));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002858 voe_.GetEcStatus(ec_enabled, ec_mode);
2859 voe_.GetEcMetricsStatus(ec_metrics_enabled);
2860 voe_.GetAecmMode(aecm_mode, cng_enabled);
2861 voe_.GetAgcStatus(agc_enabled, agc_mode);
2862 voe_.GetAgcConfig(agc_config);
2863 voe_.GetNsStatus(ns_enabled, ns_mode);
2864 highpass_filter_enabled = voe_.IsHighPassFilterEnabled();
2865 stereo_swapping_enabled = voe_.IsStereoChannelSwappingEnabled();
2866 voe_.GetTypingDetectionStatus(typing_detection_enabled);
2867 EXPECT_TRUE(ec_enabled);
2868 EXPECT_TRUE(ec_metrics_enabled);
2869 EXPECT_TRUE(agc_enabled);
2870 EXPECT_EQ(0, agc_config.targetLeveldBOv);
2871 EXPECT_TRUE(ns_enabled);
2872 EXPECT_TRUE(highpass_filter_enabled);
2873 EXPECT_FALSE(stereo_swapping_enabled);
2874 EXPECT_TRUE(typing_detection_enabled);
2875 EXPECT_EQ(ec_mode, webrtc::kEcConference);
2876 EXPECT_EQ(ns_mode, webrtc::kNsHighSuppression);
2877
Bjorn Volckerbf395c12015-03-25 22:45:56 +01002878 // Turn on delay agnostic aec and make sure nothing change w.r.t. echo
2879 // control.
2880 options.delay_agnostic_aec.Set(true);
2881 ASSERT_TRUE(engine_.SetOptions(options));
2882 voe_.GetEcStatus(ec_enabled, ec_mode);
2883 voe_.GetEcMetricsStatus(ec_metrics_enabled);
2884 voe_.GetAecmMode(aecm_mode, cng_enabled);
2885 EXPECT_TRUE(ec_enabled);
2886 EXPECT_TRUE(ec_metrics_enabled);
2887 EXPECT_EQ(ec_mode, webrtc::kEcConference);
2888
2889 // Turn off echo cancellation and delay agnostic aec.
2890 options.delay_agnostic_aec.Set(false);
2891 options.experimental_aec.Set(false);
2892 options.echo_cancellation.Set(false);
2893 ASSERT_TRUE(engine_.SetOptions(options));
2894 voe_.GetEcStatus(ec_enabled, ec_mode);
2895 EXPECT_FALSE(ec_enabled);
2896 // Turning delay agnostic aec back on should also turn on echo cancellation.
2897 options.delay_agnostic_aec.Set(true);
2898 ASSERT_TRUE(engine_.SetOptions(options));
2899 voe_.GetEcStatus(ec_enabled, ec_mode);
2900 voe_.GetEcMetricsStatus(ec_metrics_enabled);
2901 EXPECT_TRUE(ec_enabled);
2902 EXPECT_TRUE(ec_metrics_enabled);
2903 EXPECT_EQ(ec_mode, webrtc::kEcConference);
2904
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002905 // Turn off AGC
2906 options.auto_gain_control.Set(false);
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00002907 ASSERT_TRUE(engine_.SetOptions(options));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002908 voe_.GetAgcStatus(agc_enabled, agc_mode);
2909 EXPECT_FALSE(agc_enabled);
2910
2911 // Turn AGC back on
2912 options.auto_gain_control.Set(true);
2913 options.adjust_agc_delta.Clear();
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00002914 ASSERT_TRUE(engine_.SetOptions(options));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002915 voe_.GetAgcStatus(agc_enabled, agc_mode);
2916 EXPECT_TRUE(agc_enabled);
2917 voe_.GetAgcConfig(agc_config);
2918 EXPECT_EQ(0, agc_config.targetLeveldBOv);
2919
2920 // Turn off other options (and stereo swapping on).
2921 options.noise_suppression.Set(false);
2922 options.highpass_filter.Set(false);
2923 options.typing_detection.Set(false);
2924 options.stereo_swapping.Set(true);
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00002925 ASSERT_TRUE(engine_.SetOptions(options));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002926 voe_.GetNsStatus(ns_enabled, ns_mode);
2927 highpass_filter_enabled = voe_.IsHighPassFilterEnabled();
2928 stereo_swapping_enabled = voe_.IsStereoChannelSwappingEnabled();
2929 voe_.GetTypingDetectionStatus(typing_detection_enabled);
2930 EXPECT_FALSE(ns_enabled);
2931 EXPECT_FALSE(highpass_filter_enabled);
2932 EXPECT_FALSE(typing_detection_enabled);
2933 EXPECT_TRUE(stereo_swapping_enabled);
2934
2935 // Turn on "conference mode" to ensure it has no impact.
2936 options.conference_mode.Set(true);
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00002937 ASSERT_TRUE(engine_.SetOptions(options));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002938 voe_.GetEcStatus(ec_enabled, ec_mode);
2939 voe_.GetNsStatus(ns_enabled, ns_mode);
2940 EXPECT_TRUE(ec_enabled);
2941 EXPECT_EQ(webrtc::kEcConference, ec_mode);
2942 EXPECT_FALSE(ns_enabled);
2943 EXPECT_EQ(webrtc::kNsHighSuppression, ns_mode);
2944}
2945
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00002946TEST_F(WebRtcVoiceEngineTestFake, DefaultOptions) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002947 EXPECT_TRUE(SetupEngine());
2948
2949 bool ec_enabled;
2950 webrtc::EcModes ec_mode;
2951 bool ec_metrics_enabled;
2952 bool agc_enabled;
2953 webrtc::AgcModes agc_mode;
2954 bool ns_enabled;
2955 webrtc::NsModes ns_mode;
2956 bool highpass_filter_enabled;
2957 bool stereo_swapping_enabled;
2958 bool typing_detection_enabled;
2959
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002960 voe_.GetEcStatus(ec_enabled, ec_mode);
2961 voe_.GetEcMetricsStatus(ec_metrics_enabled);
2962 voe_.GetAgcStatus(agc_enabled, agc_mode);
2963 voe_.GetNsStatus(ns_enabled, ns_mode);
2964 highpass_filter_enabled = voe_.IsHighPassFilterEnabled();
2965 stereo_swapping_enabled = voe_.IsStereoChannelSwappingEnabled();
2966 voe_.GetTypingDetectionStatus(typing_detection_enabled);
2967 EXPECT_TRUE(ec_enabled);
2968 EXPECT_TRUE(agc_enabled);
2969 EXPECT_TRUE(ns_enabled);
2970 EXPECT_TRUE(highpass_filter_enabled);
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00002971 EXPECT_TRUE(typing_detection_enabled);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002972 EXPECT_FALSE(stereo_swapping_enabled);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002973}
2974
2975TEST_F(WebRtcVoiceEngineTestFake, InitDoesNotOverwriteDefaultAgcConfig) {
2976 webrtc::AgcConfig set_config = {0};
2977 set_config.targetLeveldBOv = 3;
2978 set_config.digitalCompressionGaindB = 9;
2979 set_config.limiterEnable = true;
2980 EXPECT_EQ(0, voe_.SetAgcConfig(set_config));
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002981 EXPECT_TRUE(engine_.Init(rtc::Thread::Current()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002982
2983 webrtc::AgcConfig config = {0};
2984 EXPECT_EQ(0, voe_.GetAgcConfig(config));
2985 EXPECT_EQ(set_config.targetLeveldBOv, config.targetLeveldBOv);
2986 EXPECT_EQ(set_config.digitalCompressionGaindB,
2987 config.digitalCompressionGaindB);
2988 EXPECT_EQ(set_config.limiterEnable, config.limiterEnable);
2989}
2990
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002991TEST_F(WebRtcVoiceEngineTestFake, SetOptionOverridesViaChannels) {
2992 EXPECT_TRUE(SetupEngine());
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002993 rtc::scoped_ptr<cricket::VoiceMediaChannel> channel1(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002994 engine_.CreateChannel());
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002995 rtc::scoped_ptr<cricket::VoiceMediaChannel> channel2(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002996 engine_.CreateChannel());
2997
2998 // Have to add a stream to make SetSend work.
2999 cricket::StreamParams stream1;
3000 stream1.ssrcs.push_back(1);
3001 channel1->AddSendStream(stream1);
3002 cricket::StreamParams stream2;
3003 stream2.ssrcs.push_back(2);
3004 channel2->AddSendStream(stream2);
3005
3006 // AEC and AGC and NS
3007 cricket::AudioOptions options_all;
3008 options_all.echo_cancellation.Set(true);
3009 options_all.auto_gain_control.Set(true);
3010 options_all.noise_suppression.Set(true);
3011
3012 ASSERT_TRUE(channel1->SetOptions(options_all));
3013 cricket::AudioOptions expected_options = options_all;
3014 cricket::AudioOptions actual_options;
3015 ASSERT_TRUE(channel1->GetOptions(&actual_options));
3016 EXPECT_EQ(expected_options, actual_options);
3017 ASSERT_TRUE(channel2->SetOptions(options_all));
3018 ASSERT_TRUE(channel2->GetOptions(&actual_options));
3019 EXPECT_EQ(expected_options, actual_options);
3020
3021 // unset NS
3022 cricket::AudioOptions options_no_ns;
3023 options_no_ns.noise_suppression.Set(false);
3024 ASSERT_TRUE(channel1->SetOptions(options_no_ns));
3025
3026 expected_options.echo_cancellation.Set(true);
3027 expected_options.auto_gain_control.Set(true);
3028 expected_options.noise_suppression.Set(false);
3029 ASSERT_TRUE(channel1->GetOptions(&actual_options));
3030 EXPECT_EQ(expected_options, actual_options);
3031
3032 // unset AGC
3033 cricket::AudioOptions options_no_agc;
3034 options_no_agc.auto_gain_control.Set(false);
3035 ASSERT_TRUE(channel2->SetOptions(options_no_agc));
3036
3037 expected_options.echo_cancellation.Set(true);
3038 expected_options.auto_gain_control.Set(false);
3039 expected_options.noise_suppression.Set(true);
3040 ASSERT_TRUE(channel2->GetOptions(&actual_options));
3041 EXPECT_EQ(expected_options, actual_options);
3042
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00003043 ASSERT_TRUE(engine_.SetOptions(options_all));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003044 bool ec_enabled;
3045 webrtc::EcModes ec_mode;
3046 bool agc_enabled;
3047 webrtc::AgcModes agc_mode;
3048 bool ns_enabled;
3049 webrtc::NsModes ns_mode;
3050 voe_.GetEcStatus(ec_enabled, ec_mode);
3051 voe_.GetAgcStatus(agc_enabled, agc_mode);
3052 voe_.GetNsStatus(ns_enabled, ns_mode);
3053 EXPECT_TRUE(ec_enabled);
3054 EXPECT_TRUE(agc_enabled);
3055 EXPECT_TRUE(ns_enabled);
3056
3057 channel1->SetSend(cricket::SEND_MICROPHONE);
3058 voe_.GetEcStatus(ec_enabled, ec_mode);
3059 voe_.GetAgcStatus(agc_enabled, agc_mode);
3060 voe_.GetNsStatus(ns_enabled, ns_mode);
3061 EXPECT_TRUE(ec_enabled);
3062 EXPECT_TRUE(agc_enabled);
3063 EXPECT_FALSE(ns_enabled);
3064
3065 channel1->SetSend(cricket::SEND_NOTHING);
3066 voe_.GetEcStatus(ec_enabled, ec_mode);
3067 voe_.GetAgcStatus(agc_enabled, agc_mode);
3068 voe_.GetNsStatus(ns_enabled, ns_mode);
3069 EXPECT_TRUE(ec_enabled);
3070 EXPECT_TRUE(agc_enabled);
3071 EXPECT_TRUE(ns_enabled);
3072
3073 channel2->SetSend(cricket::SEND_MICROPHONE);
3074 voe_.GetEcStatus(ec_enabled, ec_mode);
3075 voe_.GetAgcStatus(agc_enabled, agc_mode);
3076 voe_.GetNsStatus(ns_enabled, ns_mode);
3077 EXPECT_TRUE(ec_enabled);
3078 EXPECT_FALSE(agc_enabled);
3079 EXPECT_TRUE(ns_enabled);
3080
3081 channel2->SetSend(cricket::SEND_NOTHING);
3082 voe_.GetEcStatus(ec_enabled, ec_mode);
3083 voe_.GetAgcStatus(agc_enabled, agc_mode);
3084 voe_.GetNsStatus(ns_enabled, ns_mode);
3085 EXPECT_TRUE(ec_enabled);
3086 EXPECT_TRUE(agc_enabled);
3087 EXPECT_TRUE(ns_enabled);
3088
3089 // Make sure settings take effect while we are sending.
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00003090 ASSERT_TRUE(engine_.SetOptions(options_all));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003091 cricket::AudioOptions options_no_agc_nor_ns;
3092 options_no_agc_nor_ns.auto_gain_control.Set(false);
3093 options_no_agc_nor_ns.noise_suppression.Set(false);
3094 channel2->SetSend(cricket::SEND_MICROPHONE);
3095 channel2->SetOptions(options_no_agc_nor_ns);
3096
3097 expected_options.echo_cancellation.Set(true);
3098 expected_options.auto_gain_control.Set(false);
3099 expected_options.noise_suppression.Set(false);
3100 ASSERT_TRUE(channel2->GetOptions(&actual_options));
3101 EXPECT_EQ(expected_options, actual_options);
3102 voe_.GetEcStatus(ec_enabled, ec_mode);
3103 voe_.GetAgcStatus(agc_enabled, agc_mode);
3104 voe_.GetNsStatus(ns_enabled, ns_mode);
3105 EXPECT_TRUE(ec_enabled);
3106 EXPECT_FALSE(agc_enabled);
3107 EXPECT_FALSE(ns_enabled);
3108}
3109
wu@webrtc.orgde305012013-10-31 15:40:38 +00003110// This test verifies DSCP settings are properly applied on voice media channel.
3111TEST_F(WebRtcVoiceEngineTestFake, TestSetDscpOptions) {
3112 EXPECT_TRUE(SetupEngine());
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003113 rtc::scoped_ptr<cricket::VoiceMediaChannel> channel(
wu@webrtc.orgde305012013-10-31 15:40:38 +00003114 engine_.CreateChannel());
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003115 rtc::scoped_ptr<cricket::FakeNetworkInterface> network_interface(
wu@webrtc.orgde305012013-10-31 15:40:38 +00003116 new cricket::FakeNetworkInterface);
3117 channel->SetInterface(network_interface.get());
3118 cricket::AudioOptions options;
3119 options.dscp.Set(true);
3120 EXPECT_TRUE(channel->SetOptions(options));
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003121 EXPECT_EQ(rtc::DSCP_EF, network_interface->dscp());
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +00003122 // Verify previous value is not modified if dscp option is not set.
3123 cricket::AudioOptions options1;
3124 EXPECT_TRUE(channel->SetOptions(options1));
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003125 EXPECT_EQ(rtc::DSCP_EF, network_interface->dscp());
wu@webrtc.orgde305012013-10-31 15:40:38 +00003126 options.dscp.Set(false);
3127 EXPECT_TRUE(channel->SetOptions(options));
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003128 EXPECT_EQ(rtc::DSCP_DEFAULT, network_interface->dscp());
wu@webrtc.orgde305012013-10-31 15:40:38 +00003129}
3130
wu@webrtc.org1d1ffc92013-10-16 18:12:02 +00003131TEST(WebRtcVoiceEngineTest, TestDefaultOptionsBeforeInit) {
3132 cricket::WebRtcVoiceEngine engine;
3133 cricket::AudioOptions options = engine.GetOptions();
3134 // The default options should have at least a few things set. We purposefully
3135 // don't check the option values here, though.
3136 EXPECT_TRUE(options.echo_cancellation.IsSet());
3137 EXPECT_TRUE(options.auto_gain_control.IsSet());
3138 EXPECT_TRUE(options.noise_suppression.IsSet());
3139}
3140
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003141// Test that GetReceiveChannelNum returns the default channel for the first
3142// recv stream in 1-1 calls.
3143TEST_F(WebRtcVoiceEngineTestFake, TestGetReceiveChannelNumIn1To1Calls) {
3144 EXPECT_TRUE(SetupEngine());
3145 cricket::WebRtcVoiceMediaChannel* media_channel =
3146 static_cast<cricket::WebRtcVoiceMediaChannel*>(channel_);
3147 // Test that GetChannelNum returns the default channel if the SSRC is unknown.
3148 EXPECT_EQ(media_channel->voe_channel(),
3149 media_channel->GetReceiveChannelNum(0));
3150 cricket::StreamParams stream;
3151 stream.ssrcs.push_back(kSsrc2);
3152 EXPECT_TRUE(channel_->AddRecvStream(stream));
3153 EXPECT_EQ(media_channel->voe_channel(),
3154 media_channel->GetReceiveChannelNum(kSsrc2));
3155}
3156
3157// Test that GetReceiveChannelNum doesn't return the default channel for the
3158// first recv stream in conference calls.
3159TEST_F(WebRtcVoiceEngineTestFake, TestGetChannelNumInConferenceCalls) {
3160 EXPECT_TRUE(SetupEngine());
3161 EXPECT_TRUE(channel_->SetOptions(options_conference_));
3162 cricket::StreamParams stream;
3163 stream.ssrcs.push_back(kSsrc2);
3164 EXPECT_TRUE(channel_->AddRecvStream(stream));
3165 cricket::WebRtcVoiceMediaChannel* media_channel =
3166 static_cast<cricket::WebRtcVoiceMediaChannel*>(channel_);
3167 EXPECT_LT(media_channel->voe_channel(),
3168 media_channel->GetReceiveChannelNum(kSsrc2));
3169}
3170
3171TEST_F(WebRtcVoiceEngineTestFake, SetOutputScaling) {
3172 EXPECT_TRUE(SetupEngine());
3173 double left, right;
3174 EXPECT_TRUE(channel_->SetOutputScaling(0, 1, 2));
3175 EXPECT_TRUE(channel_->GetOutputScaling(0, &left, &right));
3176 EXPECT_DOUBLE_EQ(1, left);
3177 EXPECT_DOUBLE_EQ(2, right);
3178
3179 EXPECT_FALSE(channel_->SetOutputScaling(kSsrc2, 1, 2));
3180 cricket::StreamParams stream;
3181 stream.ssrcs.push_back(kSsrc2);
3182 EXPECT_TRUE(channel_->AddRecvStream(stream));
3183
3184 EXPECT_TRUE(channel_->SetOutputScaling(kSsrc2, 2, 1));
3185 EXPECT_TRUE(channel_->GetOutputScaling(kSsrc2, &left, &right));
3186 EXPECT_DOUBLE_EQ(2, left);
3187 EXPECT_DOUBLE_EQ(1, right);
3188}
3189
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003190// Tests for the actual WebRtc VoE library.
3191
3192// Tests that the library initializes and shuts down properly.
3193TEST(WebRtcVoiceEngineTest, StartupShutdown) {
3194 cricket::WebRtcVoiceEngine engine;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003195 EXPECT_TRUE(engine.Init(rtc::Thread::Current()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003196 cricket::VoiceMediaChannel* channel = engine.CreateChannel();
3197 EXPECT_TRUE(channel != NULL);
3198 delete channel;
3199 engine.Terminate();
3200
3201 // Reinit to catch regression where VoiceEngineObserver reference is lost
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003202 EXPECT_TRUE(engine.Init(rtc::Thread::Current()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003203 engine.Terminate();
3204}
3205
3206// Tests that the logging from the library is cleartext.
3207TEST(WebRtcVoiceEngineTest, DISABLED_HasUnencryptedLogging) {
3208 cricket::WebRtcVoiceEngine engine;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003209 rtc::scoped_ptr<rtc::MemoryStream> stream(
3210 new rtc::MemoryStream);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003211 size_t size = 0;
3212 bool cleartext = true;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003213 rtc::LogMessage::AddLogToStream(stream.get(), rtc::LS_VERBOSE);
3214 engine.SetLogging(rtc::LS_VERBOSE, "");
3215 EXPECT_TRUE(engine.Init(rtc::Thread::Current()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003216 EXPECT_TRUE(stream->GetSize(&size));
3217 EXPECT_GT(size, 0U);
3218 engine.Terminate();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003219 rtc::LogMessage::RemoveLogToStream(stream.get());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003220 const char* buf = stream->GetBuffer();
3221 for (size_t i = 0; i < size && cleartext; ++i) {
3222 int ch = static_cast<int>(buf[i]);
3223 ASSERT_GE(ch, 0) << "Out of bounds character in WebRtc VoE log: "
3224 << std::hex << ch;
3225 cleartext = (isprint(ch) || isspace(ch));
3226 }
3227 EXPECT_TRUE(cleartext);
3228}
3229
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003230// Tests that the library is configured with the codecs we want.
3231TEST(WebRtcVoiceEngineTest, HasCorrectCodecs) {
3232 cricket::WebRtcVoiceEngine engine;
3233 // Check codecs by name.
3234 EXPECT_TRUE(engine.FindCodec(
3235 cricket::AudioCodec(96, "OPUS", 48000, 0, 2, 0)));
3236 EXPECT_TRUE(engine.FindCodec(
3237 cricket::AudioCodec(96, "ISAC", 16000, 0, 1, 0)));
3238 EXPECT_TRUE(engine.FindCodec(
3239 cricket::AudioCodec(96, "ISAC", 32000, 0, 1, 0)));
3240 // Check that name matching is case-insensitive.
3241 EXPECT_TRUE(engine.FindCodec(
3242 cricket::AudioCodec(96, "ILBC", 8000, 0, 1, 0)));
3243 EXPECT_TRUE(engine.FindCodec(
3244 cricket::AudioCodec(96, "iLBC", 8000, 0, 1, 0)));
3245 EXPECT_TRUE(engine.FindCodec(
3246 cricket::AudioCodec(96, "PCMU", 8000, 0, 1, 0)));
3247 EXPECT_TRUE(engine.FindCodec(
3248 cricket::AudioCodec(96, "PCMA", 8000, 0, 1, 0)));
3249 EXPECT_TRUE(engine.FindCodec(
henrik.lundin@webrtc.orgf85dbce2014-11-07 12:25:00 +00003250 cricket::AudioCodec(96, "G722", 8000, 0, 1, 0)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003251 EXPECT_TRUE(engine.FindCodec(
3252 cricket::AudioCodec(96, "red", 8000, 0, 1, 0)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003253 EXPECT_TRUE(engine.FindCodec(
3254 cricket::AudioCodec(96, "CN", 32000, 0, 1, 0)));
3255 EXPECT_TRUE(engine.FindCodec(
3256 cricket::AudioCodec(96, "CN", 16000, 0, 1, 0)));
3257 EXPECT_TRUE(engine.FindCodec(
3258 cricket::AudioCodec(96, "CN", 8000, 0, 1, 0)));
3259 EXPECT_TRUE(engine.FindCodec(
3260 cricket::AudioCodec(96, "telephone-event", 8000, 0, 1, 0)));
3261 // Check codecs with an id by id.
3262 EXPECT_TRUE(engine.FindCodec(
3263 cricket::AudioCodec(0, "", 8000, 0, 1, 0))); // PCMU
3264 EXPECT_TRUE(engine.FindCodec(
3265 cricket::AudioCodec(8, "", 8000, 0, 1, 0))); // PCMA
3266 EXPECT_TRUE(engine.FindCodec(
henrik.lundin@webrtc.orgf85dbce2014-11-07 12:25:00 +00003267 cricket::AudioCodec(9, "", 8000, 0, 1, 0))); // G722
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003268 EXPECT_TRUE(engine.FindCodec(
3269 cricket::AudioCodec(13, "", 8000, 0, 1, 0))); // CN
3270 // Check sample/bitrate matching.
3271 EXPECT_TRUE(engine.FindCodec(
3272 cricket::AudioCodec(0, "PCMU", 8000, 64000, 1, 0)));
3273 // Check that bad codecs fail.
3274 EXPECT_FALSE(engine.FindCodec(cricket::AudioCodec(99, "ABCD", 0, 0, 1, 0)));
3275 EXPECT_FALSE(engine.FindCodec(cricket::AudioCodec(88, "", 0, 0, 1, 0)));
3276 EXPECT_FALSE(engine.FindCodec(cricket::AudioCodec(0, "", 0, 0, 2, 0)));
3277 EXPECT_FALSE(engine.FindCodec(cricket::AudioCodec(0, "", 5000, 0, 1, 0)));
3278 EXPECT_FALSE(engine.FindCodec(cricket::AudioCodec(0, "", 0, 5000, 1, 0)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003279 // Verify the payload id of common audio codecs, including CN, ISAC, and G722.
3280 for (std::vector<cricket::AudioCodec>::const_iterator it =
3281 engine.codecs().begin(); it != engine.codecs().end(); ++it) {
3282 if (it->name == "CN" && it->clockrate == 16000) {
3283 EXPECT_EQ(105, it->id);
3284 } else if (it->name == "CN" && it->clockrate == 32000) {
3285 EXPECT_EQ(106, it->id);
3286 } else if (it->name == "ISAC" && it->clockrate == 16000) {
3287 EXPECT_EQ(103, it->id);
3288 } else if (it->name == "ISAC" && it->clockrate == 32000) {
3289 EXPECT_EQ(104, it->id);
henrik.lundin@webrtc.orgf85dbce2014-11-07 12:25:00 +00003290 } else if (it->name == "G722" && it->clockrate == 8000) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003291 EXPECT_EQ(9, it->id);
3292 } else if (it->name == "telephone-event") {
3293 EXPECT_EQ(126, it->id);
3294 } else if (it->name == "red") {
3295 EXPECT_EQ(127, it->id);
3296 } else if (it->name == "opus") {
3297 EXPECT_EQ(111, it->id);
wu@webrtc.org9caf2762013-12-11 18:25:07 +00003298 ASSERT_TRUE(it->params.find("minptime") != it->params.end());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003299 EXPECT_EQ("10", it->params.find("minptime")->second);
wu@webrtc.org9caf2762013-12-11 18:25:07 +00003300 ASSERT_TRUE(it->params.find("maxptime") != it->params.end());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003301 EXPECT_EQ("60", it->params.find("maxptime")->second);
minyue@webrtc.org4ef22d12014-11-17 09:26:39 +00003302 ASSERT_TRUE(it->params.find("useinbandfec") != it->params.end());
3303 EXPECT_EQ("1", it->params.find("useinbandfec")->second);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003304 }
3305 }
3306
3307 engine.Terminate();
3308}
3309
3310// Tests that VoE supports at least 32 channels
3311TEST(WebRtcVoiceEngineTest, Has32Channels) {
3312 cricket::WebRtcVoiceEngine engine;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003313 EXPECT_TRUE(engine.Init(rtc::Thread::Current()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003314
3315 cricket::VoiceMediaChannel* channels[32];
3316 int num_channels = 0;
3317
3318 while (num_channels < ARRAY_SIZE(channels)) {
3319 cricket::VoiceMediaChannel* channel = engine.CreateChannel();
3320 if (!channel)
3321 break;
3322
3323 channels[num_channels++] = channel;
3324 }
3325
3326 int expected = ARRAY_SIZE(channels);
3327 EXPECT_EQ(expected, num_channels);
3328
3329 while (num_channels > 0) {
3330 delete channels[--num_channels];
3331 }
3332
3333 engine.Terminate();
3334}
3335
3336// Test that we set our preferred codecs properly.
3337TEST(WebRtcVoiceEngineTest, SetRecvCodecs) {
3338 cricket::WebRtcVoiceEngine engine;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003339 EXPECT_TRUE(engine.Init(rtc::Thread::Current()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003340 cricket::WebRtcVoiceMediaChannel channel(&engine);
3341 EXPECT_TRUE(channel.SetRecvCodecs(engine.codecs()));
3342}
3343
3344#ifdef WIN32
3345// Test our workarounds to WebRtc VoE' munging of the coinit count
3346TEST(WebRtcVoiceEngineTest, CoInitialize) {
3347 cricket::WebRtcVoiceEngine* engine = new cricket::WebRtcVoiceEngine();
3348
3349 // Initial refcount should be 0.
3350 EXPECT_EQ(S_OK, CoInitializeEx(NULL, COINIT_MULTITHREADED));
3351
3352 // Engine should start even with COM already inited.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003353 EXPECT_TRUE(engine->Init(rtc::Thread::Current()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003354 engine->Terminate();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003355 EXPECT_TRUE(engine->Init(rtc::Thread::Current()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003356 engine->Terminate();
3357
3358 // Refcount after terminate should be 1 (in reality 3); test if it is nonzero.
3359 EXPECT_EQ(S_FALSE, CoInitializeEx(NULL, COINIT_MULTITHREADED));
3360 // Decrement refcount to (hopefully) 0.
3361 CoUninitialize();
3362 CoUninitialize();
3363 delete engine;
3364
3365 // Ensure refcount is 0.
3366 EXPECT_EQ(S_OK, CoInitializeEx(NULL, COINIT_MULTITHREADED));
3367 CoUninitialize();
3368}
3369#endif
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +00003370
Fredrik Solenberg4b60c732015-05-07 14:07:48 +02003371TEST_F(WebRtcVoiceEngineTestFake, ChangeCombinedBweOption_Call) {
3372 // Test that changing the combined_audio_video_bwe option results in the
3373 // expected state changes on an associated Call.
3374 cricket::FakeCall call(webrtc::Call::Config(nullptr));
3375 const uint32 kAudioSsrc1 = 223;
3376 const uint32 kAudioSsrc2 = 224;
3377
3378 EXPECT_TRUE(SetupEngine());
3379 cricket::WebRtcVoiceMediaChannel* media_channel =
3380 static_cast<cricket::WebRtcVoiceMediaChannel*>(channel_);
3381 media_channel->SetCall(&call);
3382 EXPECT_TRUE(media_channel->AddRecvStream(
3383 cricket::StreamParams::CreateLegacy(kAudioSsrc1)));
3384 EXPECT_TRUE(media_channel->AddRecvStream(
3385 cricket::StreamParams::CreateLegacy(kAudioSsrc2)));
3386
3387 // Combined BWE should not be set up yet.
3388 EXPECT_EQ(0, call.GetAudioReceiveStreams().size());
3389
3390 // Enable combined BWE option - now it should be set up.
3391 cricket::AudioOptions options;
3392 options.combined_audio_video_bwe.Set(true);
3393 EXPECT_TRUE(media_channel->SetOptions(options));
3394 EXPECT_EQ(2, call.GetAudioReceiveStreams().size());
3395 EXPECT_NE(nullptr, call.GetAudioReceiveStream(kAudioSsrc1));
3396 EXPECT_NE(nullptr, call.GetAudioReceiveStream(kAudioSsrc2));
3397
3398 // Disable combined BWE option - should be disabled again.
3399 options.combined_audio_video_bwe.Set(false);
3400 EXPECT_TRUE(media_channel->SetOptions(options));
3401 EXPECT_EQ(0, call.GetAudioReceiveStreams().size());
3402
3403 media_channel->SetCall(nullptr);
3404}
3405
3406TEST_F(WebRtcVoiceEngineTestFake, ConfigureCombinedBwe_Call) {
3407 // Test that calling SetCall() on the voice media channel results in the
3408 // expected state changes in Call.
3409 cricket::FakeCall call(webrtc::Call::Config(nullptr));
3410 cricket::FakeCall call2(webrtc::Call::Config(nullptr));
3411 const uint32 kAudioSsrc1 = 223;
3412 const uint32 kAudioSsrc2 = 224;
3413
3414 EXPECT_TRUE(SetupEngine());
3415 cricket::WebRtcVoiceMediaChannel* media_channel =
3416 static_cast<cricket::WebRtcVoiceMediaChannel*>(channel_);
3417 cricket::AudioOptions options;
3418 options.combined_audio_video_bwe.Set(true);
3419 EXPECT_TRUE(media_channel->SetOptions(options));
3420 EXPECT_TRUE(media_channel->AddRecvStream(
3421 cricket::StreamParams::CreateLegacy(kAudioSsrc1)));
3422 EXPECT_TRUE(media_channel->AddRecvStream(
3423 cricket::StreamParams::CreateLegacy(kAudioSsrc2)));
3424
3425 // Combined BWE should not be set up yet.
3426 EXPECT_EQ(0, call.GetAudioReceiveStreams().size());
3427
3428 // Register - should be enabled.
3429 media_channel->SetCall(&call);
3430 EXPECT_EQ(2, call.GetAudioReceiveStreams().size());
3431 EXPECT_NE(nullptr, call.GetAudioReceiveStream(kAudioSsrc1));
3432 EXPECT_NE(nullptr, call.GetAudioReceiveStream(kAudioSsrc2));
3433
3434 // Re-register - should now be enabled on new call.
3435 media_channel->SetCall(&call2);
3436 EXPECT_EQ(0, call.GetAudioReceiveStreams().size());
3437 EXPECT_EQ(2, call2.GetAudioReceiveStreams().size());
3438 EXPECT_NE(nullptr, call2.GetAudioReceiveStream(kAudioSsrc1));
3439 EXPECT_NE(nullptr, call2.GetAudioReceiveStream(kAudioSsrc2));
3440
3441 // Unregister - should be disabled again.
3442 media_channel->SetCall(nullptr);
3443 EXPECT_EQ(0, call.GetAudioReceiveStreams().size());
3444}
3445
3446TEST_F(WebRtcVoiceEngineTestFake, ConfigureCombinedBweForNewRecvStreams_Call) {
3447 // Test that adding receive streams after enabling combined bandwidth
3448 // estimation will correctly configure each channel.
3449 cricket::FakeCall call(webrtc::Call::Config(nullptr));
3450
3451 EXPECT_TRUE(SetupEngine());
3452 cricket::WebRtcVoiceMediaChannel* media_channel =
3453 static_cast<cricket::WebRtcVoiceMediaChannel*>(channel_);
3454 media_channel->SetCall(&call);
3455 cricket::AudioOptions options;
3456 options.combined_audio_video_bwe.Set(true);
3457 EXPECT_TRUE(media_channel->SetOptions(options));
3458
3459 static const uint32 kSsrcs[] = {1, 2, 3, 4};
3460 for (unsigned int i = 0; i < ARRAY_SIZE(kSsrcs); ++i) {
3461 EXPECT_TRUE(media_channel->AddRecvStream(
3462 cricket::StreamParams::CreateLegacy(kSsrcs[i])));
3463 EXPECT_NE(nullptr, call.GetAudioReceiveStream(kSsrcs[i]));
3464 }
3465 EXPECT_EQ(ARRAY_SIZE(kSsrcs), call.GetAudioReceiveStreams().size());
3466
3467 media_channel->SetCall(nullptr);
3468 EXPECT_EQ(0, call.GetAudioReceiveStreams().size());
3469}
3470
3471TEST_F(WebRtcVoiceEngineTestFake, ConfigureCombinedBweExtensions_Call) {
3472 // Test that setting the header extensions results in the expected state
3473 // changes on an associated Call.
3474 cricket::FakeCall call(webrtc::Call::Config(nullptr));
3475 std::vector<uint32> ssrcs;
3476 ssrcs.push_back(223);
3477 ssrcs.push_back(224);
3478
3479 EXPECT_TRUE(SetupEngine());
3480 cricket::WebRtcVoiceMediaChannel* media_channel =
3481 static_cast<cricket::WebRtcVoiceMediaChannel*>(channel_);
3482 media_channel->SetCall(&call);
3483 cricket::AudioOptions options;
3484 options.combined_audio_video_bwe.Set(true);
3485 EXPECT_TRUE(media_channel->SetOptions(options));
3486 for (uint32 ssrc : ssrcs) {
3487 EXPECT_TRUE(media_channel->AddRecvStream(
3488 cricket::StreamParams::CreateLegacy(ssrc)));
3489 }
3490
3491 // Combined BWE should be set up, but with no configured extensions.
3492 EXPECT_EQ(2, call.GetAudioReceiveStreams().size());
3493 for (uint32 ssrc : ssrcs) {
3494 const auto* s = call.GetAudioReceiveStream(ssrc);
3495 EXPECT_NE(nullptr, s);
3496 EXPECT_EQ(0, s->GetConfig().rtp.extensions.size());
3497 }
3498
3499 // Set up receive extensions.
3500 const auto& e_exts = engine_.rtp_header_extensions();
3501 channel_->SetRecvRtpHeaderExtensions(e_exts);
3502 EXPECT_EQ(2, call.GetAudioReceiveStreams().size());
3503 for (uint32 ssrc : ssrcs) {
3504 const auto* s = call.GetAudioReceiveStream(ssrc);
3505 EXPECT_NE(nullptr, s);
3506 const auto& s_exts = s->GetConfig().rtp.extensions;
3507 EXPECT_EQ(e_exts.size(), s_exts.size());
3508 for (const auto& e_ext : e_exts) {
3509 for (const auto& s_ext : s_exts) {
3510 if (e_ext.id == s_ext.id) {
3511 EXPECT_EQ(e_ext.uri, s_ext.name);
3512 }
3513 }
3514 }
3515 }
3516
3517 // Disable receive extensions.
3518 std::vector<cricket::RtpHeaderExtension> extensions;
3519 channel_->SetRecvRtpHeaderExtensions(extensions);
3520 for (uint32 ssrc : ssrcs) {
3521 const auto* s = call.GetAudioReceiveStream(ssrc);
3522 EXPECT_NE(nullptr, s);
3523 EXPECT_EQ(0, s->GetConfig().rtp.extensions.size());
3524 }
3525
3526 media_channel->SetCall(nullptr);
3527}
3528
3529TEST_F(WebRtcVoiceEngineTestFake, DeliverAudioPacket_Call) {
3530 // Test that packets are forwarded to the Call when configured accordingly.
3531 cricket::FakeCall call(webrtc::Call::Config(nullptr));
3532 const uint32 kAudioSsrc = 1;
3533 rtc::Buffer kPcmuPacket(kPcmuFrame, sizeof(kPcmuFrame));
3534 static const unsigned char kRtcp[] = {
3535 0x80, 0xc9, 0x00, 0x01, 0x00, 0x00, 0x00, 0x02,
3536 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00,
3537 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
3538 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
3539 };
3540 rtc::Buffer kRtcpPacket(kRtcp, sizeof(kRtcp));
3541
3542 EXPECT_TRUE(SetupEngine());
3543 cricket::WebRtcVoiceMediaChannel* media_channel =
3544 static_cast<cricket::WebRtcVoiceMediaChannel*>(channel_);
3545 cricket::AudioOptions options;
3546 options.combined_audio_video_bwe.Set(true);
3547 EXPECT_TRUE(media_channel->SetOptions(options));
3548 EXPECT_TRUE(media_channel->AddRecvStream(
3549 cricket::StreamParams::CreateLegacy(kAudioSsrc)));
3550
3551 // Call not set on media channel, so no packets can be forwarded.
3552 EXPECT_EQ(0, call.GetAudioReceiveStreams().size());
3553 channel_->OnPacketReceived(&kPcmuPacket, rtc::PacketTime());
3554 channel_->OnRtcpReceived(&kRtcpPacket, rtc::PacketTime());
3555 EXPECT_EQ(0, call.GetAudioReceiveStreams().size());
3556
3557 // Set Call, now there should be a receive stream which is forwarded packets.
3558 media_channel->SetCall(&call);
3559 EXPECT_EQ(1, call.GetAudioReceiveStreams().size());
3560 const cricket::FakeAudioReceiveStream* s =
3561 call.GetAudioReceiveStream(kAudioSsrc);
3562 EXPECT_EQ(0, s->received_packets());
3563 channel_->OnPacketReceived(&kPcmuPacket, rtc::PacketTime());
3564 EXPECT_EQ(1, s->received_packets());
3565 channel_->OnRtcpReceived(&kRtcpPacket, rtc::PacketTime());
3566 EXPECT_EQ(2, s->received_packets());
3567
3568 media_channel->SetCall(nullptr);
3569}
Minyue2013aec2015-05-13 14:14:42 +02003570
3571// Associate channel should not set on 1:1 call, since the receive channel also
3572// sends RTCP SR.
3573TEST_F(WebRtcVoiceEngineTestFake, AssociateChannelUnset1On1) {
3574 EXPECT_TRUE(SetupEngine());
3575 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(1)));
3576 int recv_ch = voe_.GetLastChannel();
3577 EXPECT_EQ(voe_.GetAssociateSendChannel(recv_ch), -1);
3578}
3579
3580// This test is an extension of AssociateChannelUnset1On1. We create two receive
3581// channels. The second should be associated with the default channel, since it
3582// does not send RTCP SR.
3583TEST_F(WebRtcVoiceEngineTestFake, AssociateDefaultChannelOnSecondRecvChannel) {
3584 EXPECT_TRUE(SetupEngine());
3585 cricket::WebRtcVoiceMediaChannel* media_channel =
3586 static_cast<cricket::WebRtcVoiceMediaChannel*>(channel_);
3587 int default_channel = media_channel->voe_channel();
3588 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(1)));
3589 int recv_ch_1 = voe_.GetLastChannel();
3590 EXPECT_EQ(recv_ch_1, default_channel);
3591 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(2)));
3592 int recv_ch_2 = voe_.GetLastChannel();
3593 EXPECT_EQ(voe_.GetAssociateSendChannel(recv_ch_1), -1);
3594 EXPECT_EQ(voe_.GetAssociateSendChannel(recv_ch_2), default_channel);
3595 // Add send stream, the association remains.
3596 EXPECT_TRUE(channel_->AddSendStream(cricket::StreamParams::CreateLegacy(3)));
3597 EXPECT_EQ(voe_.GetAssociateSendChannel(recv_ch_1), -1);
3598 EXPECT_EQ(voe_.GetAssociateSendChannel(recv_ch_2), default_channel);
3599}
3600
3601// In conference mode, all receive channels should be associated with the
3602// default channel, since they do not send RTCP SR.
3603TEST_F(WebRtcVoiceEngineTestFake, AssociateDefaultChannelOnConference) {
3604 EXPECT_TRUE(SetupEngine());
3605 EXPECT_TRUE(channel_->SetOptions(options_conference_));
3606 cricket::WebRtcVoiceMediaChannel* media_channel =
3607 static_cast<cricket::WebRtcVoiceMediaChannel*>(channel_);
3608 int default_channel = media_channel->voe_channel();
3609 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(1)));
3610 int recv_ch = voe_.GetLastChannel();
3611 EXPECT_NE(recv_ch, default_channel);
3612 EXPECT_EQ(voe_.GetAssociateSendChannel(recv_ch), default_channel);
3613 EXPECT_TRUE(channel_->AddSendStream(cricket::StreamParams::CreateLegacy(2)));
3614 EXPECT_EQ(voe_.GetAssociateSendChannel(recv_ch), default_channel);
3615}
3616
3617TEST_F(WebRtcVoiceEngineTestFake, AssociateChannelResetUponDeleteChannnel) {
3618 EXPECT_TRUE(SetupEngine());
3619 EXPECT_TRUE(channel_->SetOptions(options_conference_));
3620
3621 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(1)));
3622 int recv_ch = voe_.GetLastChannel();
3623
3624 EXPECT_TRUE(channel_->AddSendStream(cricket::StreamParams::CreateLegacy(2)));
3625 int send_ch = voe_.GetLastChannel();
3626
3627 // Manually associate |recv_ch| to |send_ch|. This test is to verify a
3628 // deleting logic, i.e., deleting |send_ch| will reset the associate send
3629 // channel of |recv_ch|.This is not a common case, since, normally, only the
3630 // default channel can be associated. However, the default is not deletable.
3631 // So we force the |recv_ch| to associate with a non-default channel.
3632 EXPECT_EQ(0, voe_.AssociateSendChannel(recv_ch, send_ch));
3633 EXPECT_EQ(voe_.GetAssociateSendChannel(recv_ch), send_ch);
3634
3635 EXPECT_TRUE(channel_->RemoveSendStream(2));
3636 EXPECT_EQ(voe_.GetAssociateSendChannel(recv_ch), -1);
3637}
3638