blob: 804b70f019f09d9b24f3b55d4cf7dd62e34f7737 [file] [log] [blame]
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001/*
2 * libjingle
3 * Copyright 2004 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 */
27
28#include "talk/base/fakecpumonitor.h"
29#include "talk/base/gunit.h"
30#include "talk/base/logging.h"
31#include "talk/base/scoped_ptr.h"
32#include "talk/base/stream.h"
33#include "talk/media/base/constants.h"
34#include "talk/media/base/fakemediaprocessor.h"
35#include "talk/media/base/fakenetworkinterface.h"
36#include "talk/media/base/fakevideorenderer.h"
37#include "talk/media/base/mediachannel.h"
38#include "talk/media/base/testutils.h"
mallinath@webrtc.org67ee6b92014-02-03 16:57:16 +000039#include "talk/media/base/videoadapter.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000040#include "talk/media/base/videoengine_unittest.h"
41#include "talk/media/webrtc/fakewebrtcvideocapturemodule.h"
42#include "talk/media/webrtc/fakewebrtcvideoengine.h"
43#include "talk/media/webrtc/fakewebrtcvoiceengine.h"
44#include "talk/media/webrtc/webrtcvideocapturer.h"
45#include "talk/media/webrtc/webrtcvideoengine.h"
46#include "talk/media/webrtc/webrtcvideoframe.h"
47#include "talk/media/webrtc/webrtcvoiceengine.h"
48#include "talk/session/media/mediasession.h"
49#include "webrtc/system_wrappers/interface/trace.h"
50
51// Tests for the WebRtcVideoEngine/VideoChannel code.
52
buildbot@webrtc.org150835e2014-05-06 15:54:38 +000053using cricket::kRtpTimestampOffsetHeaderExtension;
54using cricket::kRtpAbsoluteSenderTimeHeaderExtension;
55
henrike@webrtc.org28e20752013-07-10 00:45:36 +000056static const cricket::VideoCodec kVP8Codec720p(100, "VP8", 1280, 720, 30, 0);
57static const cricket::VideoCodec kVP8Codec360p(100, "VP8", 640, 360, 30, 0);
58static const cricket::VideoCodec kVP8Codec270p(100, "VP8", 480, 270, 30, 0);
59static const cricket::VideoCodec kVP8Codec180p(100, "VP8", 320, 180, 30, 0);
60
61static const cricket::VideoCodec kVP8Codec(100, "VP8", 640, 400, 30, 0);
62static const cricket::VideoCodec kRedCodec(101, "red", 0, 0, 0, 0);
63static const cricket::VideoCodec kUlpFecCodec(102, "ulpfec", 0, 0, 0, 0);
64static const cricket::VideoCodec* const kVideoCodecs[] = {
65 &kVP8Codec,
66 &kRedCodec,
67 &kUlpFecCodec
68};
69
henrike@webrtc.org28e20752013-07-10 00:45:36 +000070static const unsigned int kStartBandwidthKbps = 300;
wu@webrtc.org1e6cb2c2014-03-24 17:01:50 +000071static const unsigned int kMinBandwidthKbps = 50;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000072static const unsigned int kMaxBandwidthKbps = 2000;
73
wu@webrtc.org9caf2762013-12-11 18:25:07 +000074static const uint32 kSsrcs1[] = {1};
75static const uint32 kSsrcs2[] = {1, 2};
76static const uint32 kSsrcs3[] = {1, 2, 3};
77static const uint32 kRtxSsrc1[] = {4};
78static const uint32 kRtxSsrcs3[] = {4, 5, 6};
79
henrike@webrtc.org28e20752013-07-10 00:45:36 +000080
81class FakeViEWrapper : public cricket::ViEWrapper {
82 public:
83 explicit FakeViEWrapper(cricket::FakeWebRtcVideoEngine* engine)
84 : cricket::ViEWrapper(engine, // base
85 engine, // codec
86 engine, // capture
87 engine, // network
88 engine, // render
89 engine, // rtp
90 engine, // image
91 engine) { // external decoder
92 }
93};
94
95// Test fixture to test WebRtcVideoEngine with a fake webrtc::VideoEngine.
96// Useful for testing failure paths.
wu@webrtc.orgcadf9042013-08-30 21:24:16 +000097class WebRtcVideoEngineTestFake : public testing::Test,
wu@webrtc.orgd64719d2013-08-01 00:00:07 +000098 public sigslot::has_slots<> {
henrike@webrtc.org28e20752013-07-10 00:45:36 +000099 public:
100 WebRtcVideoEngineTestFake()
101 : vie_(kVideoCodecs, ARRAY_SIZE(kVideoCodecs)),
102 cpu_monitor_(new talk_base::FakeCpuMonitor(
103 talk_base::Thread::Current())),
104 engine_(NULL, // cricket::WebRtcVoiceEngine
105 new FakeViEWrapper(&vie_), cpu_monitor_),
106 channel_(NULL),
wu@webrtc.orgd64719d2013-08-01 00:00:07 +0000107 voice_channel_(NULL),
108 last_error_(cricket::VideoMediaChannel::ERROR_NONE) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000109 }
110 bool SetupEngine() {
111 bool result = engine_.Init(talk_base::Thread::Current());
112 if (result) {
113 channel_ = engine_.CreateChannel(voice_channel_);
wu@webrtc.orgd64719d2013-08-01 00:00:07 +0000114 channel_->SignalMediaError.connect(this,
115 &WebRtcVideoEngineTestFake::OnMediaError);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000116 result = (channel_ != NULL);
117 }
118 return result;
119 }
wu@webrtc.orgd64719d2013-08-01 00:00:07 +0000120 void OnMediaError(uint32 ssrc, cricket::VideoMediaChannel::Error error) {
121 last_error_ = error;
122 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000123 bool SendI420Frame(int width, int height) {
124 if (NULL == channel_) {
125 return false;
126 }
127 cricket::WebRtcVideoFrame frame;
wu@webrtc.org9caf2762013-12-11 18:25:07 +0000128 if (!frame.InitToBlack(width, height, 1, 1, 0, 0)) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000129 return false;
130 }
131 cricket::FakeVideoCapturer capturer;
wu@webrtc.orgf7d501d2014-03-27 23:48:25 +0000132 channel_->SendFrame(&capturer, &frame);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000133 return true;
134 }
135 bool SendI420ScreencastFrame(int width, int height) {
136 return SendI420ScreencastFrameWithTimestamp(width, height, 0);
137 }
138 bool SendI420ScreencastFrameWithTimestamp(
139 int width, int height, int64 timestamp) {
140 if (NULL == channel_) {
141 return false;
142 }
143 cricket::WebRtcVideoFrame frame;
wu@webrtc.org9caf2762013-12-11 18:25:07 +0000144 if (!frame.InitToBlack(width, height, 1, 1, 0, 0)) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000145 return false;
146 }
147 cricket::FakeVideoCapturer capturer;
148 capturer.SetScreencast(true);
wu@webrtc.orgf7d501d2014-03-27 23:48:25 +0000149 channel_->SendFrame(&capturer, &frame);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000150 return true;
151 }
buildbot@webrtc.org150835e2014-05-06 15:54:38 +0000152 void TestSetSendRtpHeaderExtensions(const std::string& ext) {
153 EXPECT_TRUE(SetupEngine());
154 int channel_num = vie_.GetLastChannel();
155
156 // Verify extensions are off by default.
157 EXPECT_EQ(-1, vie_.GetSendRtpExtensionId(channel_num, ext));
158
159 // Enable extension.
160 const int id = 1;
161 std::vector<cricket::RtpHeaderExtension> extensions;
162 extensions.push_back(cricket::RtpHeaderExtension(ext, id));
163
164 // Verify the send extension id.
165 EXPECT_TRUE(channel_->SetSendRtpHeaderExtensions(extensions));
166 EXPECT_EQ(id, vie_.GetSendRtpExtensionId(channel_num, ext));
167 // Verify call with same set of extensions returns true.
168 EXPECT_TRUE(channel_->SetSendRtpHeaderExtensions(extensions));
169 EXPECT_EQ(id, vie_.GetSendRtpExtensionId(channel_num, ext));
170
171 // Add a new send stream and verify the extension is set.
172 // The first send stream to occupy the default channel.
173 EXPECT_TRUE(
174 channel_->AddSendStream(cricket::StreamParams::CreateLegacy(123)));
175 EXPECT_TRUE(
176 channel_->AddSendStream(cricket::StreamParams::CreateLegacy(234)));
177 int new_send_channel_num = vie_.GetLastChannel();
178 EXPECT_NE(channel_num, new_send_channel_num);
179 EXPECT_EQ(id, vie_.GetSendRtpExtensionId(new_send_channel_num, ext));
180
181 // Remove the extension id.
182 std::vector<cricket::RtpHeaderExtension> empty_extensions;
183 EXPECT_TRUE(channel_->SetSendRtpHeaderExtensions(empty_extensions));
184 EXPECT_EQ(-1, vie_.GetSendRtpExtensionId(channel_num, ext));
185 EXPECT_EQ(-1, vie_.GetSendRtpExtensionId(new_send_channel_num, ext));
186 }
187 void TestSetRecvRtpHeaderExtensions(const std::string& ext) {
188 EXPECT_TRUE(SetupEngine());
189 int channel_num = vie_.GetLastChannel();
190
191 // Verify extensions are off by default.
192 EXPECT_EQ(-1, vie_.GetReceiveRtpExtensionId(channel_num, ext));
193
194 // Enable extension.
195 const int id = 2;
196 std::vector<cricket::RtpHeaderExtension> extensions;
197 extensions.push_back(cricket::RtpHeaderExtension(ext, id));
198
199 // Verify receive extension id.
200 EXPECT_TRUE(channel_->SetRecvRtpHeaderExtensions(extensions));
201 EXPECT_EQ(id, vie_.GetReceiveRtpExtensionId(channel_num, ext));
202 // Verify call with same set of extensions returns true.
203 EXPECT_TRUE(channel_->SetRecvRtpHeaderExtensions(extensions));
204 EXPECT_EQ(id, vie_.GetReceiveRtpExtensionId(channel_num, ext));
205
206 // Add a new receive stream and verify the extension is set.
207 // The first send stream to occupy the default channel.
208 EXPECT_TRUE(
209 channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(345)));
210 EXPECT_TRUE(
211 channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(456)));
212 int new_recv_channel_num = vie_.GetLastChannel();
213 EXPECT_NE(channel_num, new_recv_channel_num);
214 EXPECT_EQ(id, vie_.GetReceiveRtpExtensionId(new_recv_channel_num, ext));
215
216 // Remove the extension id.
217 std::vector<cricket::RtpHeaderExtension> empty_extensions;
218 EXPECT_TRUE(channel_->SetRecvRtpHeaderExtensions(empty_extensions));
219 EXPECT_EQ(-1, vie_.GetReceiveRtpExtensionId(channel_num, ext));
220 EXPECT_EQ(-1, vie_.GetReceiveRtpExtensionId(new_recv_channel_num, ext));
221 }
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +0000222 void VerifyCodecFeedbackParams(const cricket::VideoCodec& codec) {
223 EXPECT_TRUE(codec.HasFeedbackParam(
224 cricket::FeedbackParam(cricket::kRtcpFbParamNack,
225 cricket::kParamValueEmpty)));
226 EXPECT_TRUE(codec.HasFeedbackParam(
227 cricket::FeedbackParam(cricket::kRtcpFbParamNack,
228 cricket::kRtcpFbNackParamPli)));
229 EXPECT_TRUE(codec.HasFeedbackParam(
230 cricket::FeedbackParam(cricket::kRtcpFbParamRemb,
231 cricket::kParamValueEmpty)));
232 EXPECT_TRUE(codec.HasFeedbackParam(
233 cricket::FeedbackParam(cricket::kRtcpFbParamCcm,
234 cricket::kRtcpFbCcmParamFir)));
235 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000236 void VerifyVP8SendCodec(int channel_num,
237 unsigned int width,
238 unsigned int height,
239 unsigned int layers = 0,
240 unsigned int max_bitrate = kMaxBandwidthKbps,
241 unsigned int min_bitrate = kMinBandwidthKbps,
242 unsigned int start_bitrate = kStartBandwidthKbps,
243 unsigned int fps = 30,
244 unsigned int max_quantization = 0
245 ) {
246 webrtc::VideoCodec gcodec;
247 EXPECT_EQ(0, vie_.GetSendCodec(channel_num, gcodec));
248
249 // Video codec properties.
250 EXPECT_EQ(webrtc::kVideoCodecVP8, gcodec.codecType);
251 EXPECT_STREQ("VP8", gcodec.plName);
252 EXPECT_EQ(100, gcodec.plType);
253 EXPECT_EQ(width, gcodec.width);
254 EXPECT_EQ(height, gcodec.height);
255 EXPECT_EQ(talk_base::_min(start_bitrate, max_bitrate), gcodec.startBitrate);
256 EXPECT_EQ(max_bitrate, gcodec.maxBitrate);
257 EXPECT_EQ(min_bitrate, gcodec.minBitrate);
258 EXPECT_EQ(fps, gcodec.maxFramerate);
259 // VP8 specific.
260 EXPECT_FALSE(gcodec.codecSpecific.VP8.pictureLossIndicationOn);
261 EXPECT_FALSE(gcodec.codecSpecific.VP8.feedbackModeOn);
262 EXPECT_EQ(webrtc::kComplexityNormal, gcodec.codecSpecific.VP8.complexity);
263 EXPECT_EQ(webrtc::kResilienceOff, gcodec.codecSpecific.VP8.resilience);
264 EXPECT_EQ(max_quantization, gcodec.qpMax);
265 }
266 virtual void TearDown() {
267 delete channel_;
268 engine_.Terminate();
269 }
270
271 protected:
272 cricket::FakeWebRtcVideoEngine vie_;
273 cricket::FakeWebRtcVideoDecoderFactory decoder_factory_;
274 cricket::FakeWebRtcVideoEncoderFactory encoder_factory_;
275 talk_base::FakeCpuMonitor* cpu_monitor_;
276 cricket::WebRtcVideoEngine engine_;
277 cricket::WebRtcVideoMediaChannel* channel_;
278 cricket::WebRtcVoiceMediaChannel* voice_channel_;
wu@webrtc.orgd64719d2013-08-01 00:00:07 +0000279 cricket::VideoMediaChannel::Error last_error_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000280};
281
282// Test fixtures to test WebRtcVideoEngine with a real webrtc::VideoEngine.
283class WebRtcVideoEngineTest
284 : public VideoEngineTest<cricket::WebRtcVideoEngine> {
285 protected:
286 typedef VideoEngineTest<cricket::WebRtcVideoEngine> Base;
287};
288class WebRtcVideoMediaChannelTest
289 : public VideoMediaChannelTest<
290 cricket::WebRtcVideoEngine, cricket::WebRtcVideoMediaChannel> {
291 protected:
292 typedef VideoMediaChannelTest<cricket::WebRtcVideoEngine,
293 cricket::WebRtcVideoMediaChannel> Base;
294 virtual cricket::VideoCodec DefaultCodec() { return kVP8Codec; }
295 virtual void SetUp() {
296 Base::SetUp();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000297 }
298 virtual void TearDown() {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000299 Base::TearDown();
300 }
301};
302
303/////////////////////////
304// Tests with fake ViE //
305/////////////////////////
306
307// Tests that our stub library "works".
308TEST_F(WebRtcVideoEngineTestFake, StartupShutdown) {
309 EXPECT_FALSE(vie_.IsInited());
310 EXPECT_TRUE(engine_.Init(talk_base::Thread::Current()));
311 EXPECT_TRUE(vie_.IsInited());
312 engine_.Terminate();
313}
314
315// Tests that webrtc logs are logged when they should be.
316TEST_F(WebRtcVideoEngineTest, WebRtcShouldLog) {
317 const char webrtc_log[] = "WebRtcVideoEngineTest.WebRtcShouldLog";
318 EXPECT_TRUE(engine_.Init(talk_base::Thread::Current()));
319 engine_.SetLogging(talk_base::LS_INFO, "");
320 std::string str;
321 talk_base::StringStream stream(str);
322 talk_base::LogMessage::AddLogToStream(&stream, talk_base::LS_INFO);
323 EXPECT_EQ(talk_base::LS_INFO, talk_base::LogMessage::GetLogToStream(&stream));
324 webrtc::Trace::Add(webrtc::kTraceStateInfo, webrtc::kTraceUndefined, 0,
325 webrtc_log);
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +0000326 talk_base::Thread::Current()->ProcessMessages(100);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000327 talk_base::LogMessage::RemoveLogToStream(&stream);
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +0000328 // Access |str| after LogMessage is done with it to avoid data racing.
329 EXPECT_NE(std::string::npos, str.find(webrtc_log));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000330}
331
332// Tests that webrtc logs are not logged when they should't be.
333TEST_F(WebRtcVideoEngineTest, WebRtcShouldNotLog) {
334 const char webrtc_log[] = "WebRtcVideoEngineTest.WebRtcShouldNotLog";
335 EXPECT_TRUE(engine_.Init(talk_base::Thread::Current()));
336 // WebRTC should never be logged lower than LS_INFO.
337 engine_.SetLogging(talk_base::LS_WARNING, "");
338 std::string str;
339 talk_base::StringStream stream(str);
340 // Make sure that WebRTC is not logged, even at lowest severity
341 talk_base::LogMessage::AddLogToStream(&stream, talk_base::LS_SENSITIVE);
342 EXPECT_EQ(talk_base::LS_SENSITIVE,
343 talk_base::LogMessage::GetLogToStream(&stream));
344 webrtc::Trace::Add(webrtc::kTraceStateInfo, webrtc::kTraceUndefined, 0,
345 webrtc_log);
346 talk_base::Thread::Current()->ProcessMessages(10);
347 EXPECT_EQ(std::string::npos, str.find(webrtc_log));
348 talk_base::LogMessage::RemoveLogToStream(&stream);
349}
350
351// Tests that we can create and destroy a channel.
352TEST_F(WebRtcVideoEngineTestFake, CreateChannel) {
353 EXPECT_TRUE(engine_.Init(talk_base::Thread::Current()));
354 channel_ = engine_.CreateChannel(voice_channel_);
355 EXPECT_TRUE(channel_ != NULL);
356 EXPECT_EQ(1, engine_.GetNumOfChannels());
357 delete channel_;
358 channel_ = NULL;
359 EXPECT_EQ(0, engine_.GetNumOfChannels());
360}
361
362// Tests that we properly handle failures in CreateChannel.
363TEST_F(WebRtcVideoEngineTestFake, CreateChannelFail) {
364 vie_.set_fail_create_channel(true);
365 EXPECT_TRUE(engine_.Init(talk_base::Thread::Current()));
366 channel_ = engine_.CreateChannel(voice_channel_);
367 EXPECT_TRUE(channel_ == NULL);
368}
369
370// Tests that we properly handle failures in AllocateExternalCaptureDevice.
371TEST_F(WebRtcVideoEngineTestFake, AllocateExternalCaptureDeviceFail) {
372 vie_.set_fail_alloc_capturer(true);
373 EXPECT_TRUE(engine_.Init(talk_base::Thread::Current()));
374 channel_ = engine_.CreateChannel(voice_channel_);
375 EXPECT_TRUE(channel_ == NULL);
376}
377
378// Test that we apply our default codecs properly.
379TEST_F(WebRtcVideoEngineTestFake, SetSendCodecs) {
380 EXPECT_TRUE(SetupEngine());
381 int channel_num = vie_.GetLastChannel();
382 std::vector<cricket::VideoCodec> codecs(engine_.codecs());
383 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
384 VerifyVP8SendCodec(channel_num, kVP8Codec.width, kVP8Codec.height);
385 EXPECT_TRUE(vie_.GetHybridNackFecStatus(channel_num));
386 EXPECT_FALSE(vie_.GetNackStatus(channel_num));
wu@webrtc.org05e7b442014-04-01 17:44:24 +0000387 EXPECT_EQ(1, vie_.GetNumSetSendCodecs());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000388 // TODO(juberti): Check RTCP, PLI, TMMBR.
389}
390
wu@webrtc.org05e7b442014-04-01 17:44:24 +0000391// Test that ViE Channel doesn't call SetSendCodec again if same codec is tried
392// to apply.
393TEST_F(WebRtcVideoEngineTestFake, DontResetSetSendCodec) {
394 EXPECT_TRUE(SetupEngine());
395 int channel_num = vie_.GetLastChannel();
396 std::vector<cricket::VideoCodec> codecs(engine_.codecs());
397 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
398 VerifyVP8SendCodec(channel_num, kVP8Codec.width, kVP8Codec.height);
399 EXPECT_TRUE(vie_.GetHybridNackFecStatus(channel_num));
400 EXPECT_FALSE(vie_.GetNackStatus(channel_num));
401 EXPECT_EQ(1, vie_.GetNumSetSendCodecs());
402 // Try setting same code again.
403 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
404 // Since it's exact same codec which is already set, media channel shouldn't
405 // send the codec to ViE.
406 EXPECT_EQ(1, vie_.GetNumSetSendCodecs());
407}
408
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000409TEST_F(WebRtcVideoEngineTestFake, SetSendCodecsWithMinMaxBitrate) {
410 EXPECT_TRUE(SetupEngine());
411 int channel_num = vie_.GetLastChannel();
412 std::vector<cricket::VideoCodec> codecs(engine_.codecs());
413 codecs[0].params[cricket::kCodecParamMinBitrate] = "10";
414 codecs[0].params[cricket::kCodecParamMaxBitrate] = "20";
415 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
416
417 VerifyVP8SendCodec(
418 channel_num, kVP8Codec.width, kVP8Codec.height, 0, 20, 10, 20);
419
420 cricket::VideoCodec codec;
421 EXPECT_TRUE(channel_->GetSendCodec(&codec));
422 EXPECT_EQ("10", codec.params[cricket::kCodecParamMinBitrate]);
423 EXPECT_EQ("20", codec.params[cricket::kCodecParamMaxBitrate]);
424}
425
buildbot@webrtc.orged97bb02014-05-07 11:15:20 +0000426TEST_F(WebRtcVideoEngineTestFake, SetSendCodecsWithStartBitrate) {
427 EXPECT_TRUE(SetupEngine());
428 int channel_num = vie_.GetLastChannel();
429 std::vector<cricket::VideoCodec> codecs(engine_.codecs());
430 codecs[0].params[cricket::kCodecParamStartBitrate] = "450";
431 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
432
433 VerifyVP8SendCodec(
434 channel_num, kVP8Codec.width, kVP8Codec.height, 0, 2000, 50, 450);
435
436 cricket::VideoCodec codec;
437 EXPECT_TRUE(channel_->GetSendCodec(&codec));
438 EXPECT_EQ("450", codec.params[cricket::kCodecParamStartBitrate]);
439}
440
441TEST_F(WebRtcVideoEngineTestFake, SetSendCodecsWithMinMaxStartBitrate) {
442 EXPECT_TRUE(SetupEngine());
443 int channel_num = vie_.GetLastChannel();
444 std::vector<cricket::VideoCodec> codecs(engine_.codecs());
445 codecs[0].params[cricket::kCodecParamMinBitrate] = "10";
446 codecs[0].params[cricket::kCodecParamMaxBitrate] = "20";
447 codecs[0].params[cricket::kCodecParamStartBitrate] = "14";
448 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
449
450 VerifyVP8SendCodec(
451 channel_num, kVP8Codec.width, kVP8Codec.height, 0, 20, 10, 14);
452
453 cricket::VideoCodec codec;
454 EXPECT_TRUE(channel_->GetSendCodec(&codec));
455 EXPECT_EQ("10", codec.params[cricket::kCodecParamMinBitrate]);
456 EXPECT_EQ("20", codec.params[cricket::kCodecParamMaxBitrate]);
457 EXPECT_EQ("14", codec.params[cricket::kCodecParamStartBitrate]);
458}
459
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000460TEST_F(WebRtcVideoEngineTestFake, SetSendCodecsWithMinMaxBitrateInvalid) {
461 EXPECT_TRUE(SetupEngine());
462 std::vector<cricket::VideoCodec> codecs(engine_.codecs());
463 codecs[0].params[cricket::kCodecParamMinBitrate] = "30";
464 codecs[0].params[cricket::kCodecParamMaxBitrate] = "20";
465 EXPECT_FALSE(channel_->SetSendCodecs(codecs));
466}
467
468TEST_F(WebRtcVideoEngineTestFake, SetSendCodecsWithLargeMinMaxBitrate) {
469 EXPECT_TRUE(SetupEngine());
470 int channel_num = vie_.GetLastChannel();
471 std::vector<cricket::VideoCodec> codecs(engine_.codecs());
472 codecs[0].params[cricket::kCodecParamMinBitrate] = "1000";
473 codecs[0].params[cricket::kCodecParamMaxBitrate] = "2000";
474 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
475
476 VerifyVP8SendCodec(
477 channel_num, kVP8Codec.width, kVP8Codec.height, 0, 2000, 1000,
478 1000);
479}
480
481TEST_F(WebRtcVideoEngineTestFake, SetSendCodecsWithMaxQuantization) {
482 EXPECT_TRUE(SetupEngine());
483 int channel_num = vie_.GetLastChannel();
484 std::vector<cricket::VideoCodec> codecs(engine_.codecs());
485 codecs[0].params[cricket::kCodecParamMaxQuantization] = "21";
486 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
487
488 VerifyVP8SendCodec(
489 channel_num, kVP8Codec.width, kVP8Codec.height, 0, 2000, 50, 300,
490 30, 21);
491
492 cricket::VideoCodec codec;
493 EXPECT_TRUE(channel_->GetSendCodec(&codec));
494 EXPECT_EQ("21", codec.params[cricket::kCodecParamMaxQuantization]);
495}
496
497TEST_F(WebRtcVideoEngineTestFake, SetOptionsWithMaxBitrate) {
498 EXPECT_TRUE(SetupEngine());
499 int channel_num = vie_.GetLastChannel();
500 std::vector<cricket::VideoCodec> codecs(engine_.codecs());
501 codecs[0].params[cricket::kCodecParamMinBitrate] = "10";
502 codecs[0].params[cricket::kCodecParamMaxBitrate] = "20";
503 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
504
505 VerifyVP8SendCodec(
506 channel_num, kVP8Codec.width, kVP8Codec.height, 0, 20, 10, 20);
507
508 // Verify that max bitrate doesn't change after SetOptions().
509 cricket::VideoOptions options;
510 options.video_noise_reduction.Set(true);
511 EXPECT_TRUE(channel_->SetOptions(options));
512 VerifyVP8SendCodec(
513 channel_num, kVP8Codec.width, kVP8Codec.height, 0, 20, 10, 20);
514
515 options.video_noise_reduction.Set(false);
516 options.conference_mode.Set(false);
517 EXPECT_TRUE(channel_->SetOptions(options));
518 VerifyVP8SendCodec(
519 channel_num, kVP8Codec.width, kVP8Codec.height, 0, 20, 10, 20);
520}
521
wu@webrtc.orgcecfd182013-10-30 05:18:12 +0000522TEST_F(WebRtcVideoEngineTestFake, SetOptionsWithLoweredBitrate) {
523 EXPECT_TRUE(SetupEngine());
524 int channel_num = vie_.GetLastChannel();
525 std::vector<cricket::VideoCodec> codecs(engine_.codecs());
526 codecs[0].params[cricket::kCodecParamMinBitrate] = "50";
527 codecs[0].params[cricket::kCodecParamMaxBitrate] = "100";
528 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
529
530 VerifyVP8SendCodec(
531 channel_num, kVP8Codec.width, kVP8Codec.height, 0, 100, 50, 100);
532
533 // Verify that min bitrate changes after SetOptions().
534 cricket::VideoOptions options;
535 options.lower_min_bitrate.Set(true);
536 EXPECT_TRUE(channel_->SetOptions(options));
537 VerifyVP8SendCodec(
538 channel_num, kVP8Codec.width, kVP8Codec.height, 0, 100, 30, 100);
539}
540
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000541TEST_F(WebRtcVideoEngineTestFake, MaxBitrateResetWithConferenceMode) {
542 EXPECT_TRUE(SetupEngine());
543 int channel_num = vie_.GetLastChannel();
544 std::vector<cricket::VideoCodec> codecs(engine_.codecs());
545 codecs[0].params[cricket::kCodecParamMinBitrate] = "10";
546 codecs[0].params[cricket::kCodecParamMaxBitrate] = "20";
547 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
548
549 VerifyVP8SendCodec(
550 channel_num, kVP8Codec.width, kVP8Codec.height, 0, 20, 10, 20);
551
552 cricket::VideoOptions options;
553 options.conference_mode.Set(true);
554 EXPECT_TRUE(channel_->SetOptions(options));
555 options.conference_mode.Set(false);
556 EXPECT_TRUE(channel_->SetOptions(options));
557 VerifyVP8SendCodec(
558 channel_num, kVP8Codec.width, kVP8Codec.height, 0,
buildbot@webrtc.orgd1ae89f2014-05-08 19:19:26 +0000559 kMaxBandwidthKbps, 10, kStartBandwidthKbps);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000560}
561
562// Verify the current send bitrate is used as start bitrate when reconfiguring
563// the send codec.
564TEST_F(WebRtcVideoEngineTestFake, StartSendBitrate) {
565 EXPECT_TRUE(SetupEngine());
566 EXPECT_TRUE(channel_->AddSendStream(
567 cricket::StreamParams::CreateLegacy(1)));
568 int send_channel = vie_.GetLastChannel();
569 cricket::VideoCodec codec(kVP8Codec);
570 std::vector<cricket::VideoCodec> codec_list;
571 codec_list.push_back(codec);
572 EXPECT_TRUE(channel_->SetSendCodecs(codec_list));
573 const unsigned int kVideoMaxSendBitrateKbps = 2000;
574 const unsigned int kVideoMinSendBitrateKbps = 50;
575 const unsigned int kVideoDefaultStartSendBitrateKbps = 300;
576 VerifyVP8SendCodec(send_channel, kVP8Codec.width, kVP8Codec.height, 0,
577 kVideoMaxSendBitrateKbps, kVideoMinSendBitrateKbps,
578 kVideoDefaultStartSendBitrateKbps);
579 EXPECT_EQ(0, vie_.StartSend(send_channel));
580
581 // Increase the send bitrate and verify it is used as start bitrate.
582 const unsigned int kVideoSendBitrateBps = 768000;
583 vie_.SetSendBitrates(send_channel, kVideoSendBitrateBps, 0, 0);
584 EXPECT_TRUE(channel_->SetSendCodecs(codec_list));
585 VerifyVP8SendCodec(send_channel, kVP8Codec.width, kVP8Codec.height, 0,
586 kVideoMaxSendBitrateKbps, kVideoMinSendBitrateKbps,
587 kVideoSendBitrateBps / 1000);
588
589 // Never set a start bitrate higher than the max bitrate.
590 vie_.SetSendBitrates(send_channel, kVideoMaxSendBitrateKbps + 500, 0, 0);
591 EXPECT_TRUE(channel_->SetSendCodecs(codec_list));
592 VerifyVP8SendCodec(send_channel, kVP8Codec.width, kVP8Codec.height, 0,
593 kVideoMaxSendBitrateKbps, kVideoMinSendBitrateKbps,
594 kVideoDefaultStartSendBitrateKbps);
595
596 // Use the default start bitrate if the send bitrate is lower.
597 vie_.SetSendBitrates(send_channel, kVideoDefaultStartSendBitrateKbps - 50, 0,
598 0);
599 EXPECT_TRUE(channel_->SetSendCodecs(codec_list));
600 VerifyVP8SendCodec(send_channel, kVP8Codec.width, kVP8Codec.height, 0,
601 kVideoMaxSendBitrateKbps, kVideoMinSendBitrateKbps,
602 kVideoDefaultStartSendBitrateKbps);
603}
604
605
606// Test that we constrain send codecs properly.
607TEST_F(WebRtcVideoEngineTestFake, ConstrainSendCodecs) {
608 EXPECT_TRUE(SetupEngine());
609 int channel_num = vie_.GetLastChannel();
610
611 // Set max settings of 640x400x30.
612 EXPECT_TRUE(engine_.SetDefaultEncoderConfig(
613 cricket::VideoEncoderConfig(kVP8Codec)));
614
615 // Send codec format bigger than max setting.
616 cricket::VideoCodec codec(kVP8Codec);
617 codec.width = 1280;
618 codec.height = 800;
619 codec.framerate = 60;
620 std::vector<cricket::VideoCodec> codec_list;
621 codec_list.push_back(codec);
622
623 // Set send codec and verify codec has been constrained.
624 EXPECT_TRUE(channel_->SetSendCodecs(codec_list));
625 VerifyVP8SendCodec(channel_num, kVP8Codec.width, kVP8Codec.height);
626}
627
628// Test that SetSendCodecs rejects bad format.
629TEST_F(WebRtcVideoEngineTestFake, SetSendCodecsRejectBadFormat) {
630 EXPECT_TRUE(SetupEngine());
631 int channel_num = vie_.GetLastChannel();
632
633 // Set w = 0.
634 cricket::VideoCodec codec(kVP8Codec);
635 codec.width = 0;
636 std::vector<cricket::VideoCodec> codec_list;
637 codec_list.push_back(codec);
638
639 // Verify SetSendCodecs failed and send codec is not changed on engine.
640 EXPECT_FALSE(channel_->SetSendCodecs(codec_list));
641 webrtc::VideoCodec gcodec;
642 // Set plType to something other than the value to test against ensuring
643 // that failure will happen if it is not changed.
644 gcodec.plType = 1;
645 EXPECT_EQ(0, vie_.GetSendCodec(channel_num, gcodec));
646 EXPECT_EQ(0, gcodec.plType);
647
648 // Set h = 0.
649 codec_list[0].width = 640;
650 codec_list[0].height = 0;
651
652 // Verify SetSendCodecs failed and send codec is not changed on engine.
653 EXPECT_FALSE(channel_->SetSendCodecs(codec_list));
654 // Set plType to something other than the value to test against ensuring
655 // that failure will happen if it is not changed.
656 gcodec.plType = 1;
657 EXPECT_EQ(0, vie_.GetSendCodec(channel_num, gcodec));
658 EXPECT_EQ(0, gcodec.plType);
659}
660
661// Test that SetSendCodecs rejects bad codec.
662TEST_F(WebRtcVideoEngineTestFake, SetSendCodecsRejectBadCodec) {
663 EXPECT_TRUE(SetupEngine());
664 int channel_num = vie_.GetLastChannel();
665
666 // Set bad codec name.
667 cricket::VideoCodec codec(kVP8Codec);
668 codec.name = "bad";
669 std::vector<cricket::VideoCodec> codec_list;
670 codec_list.push_back(codec);
671
672 // Verify SetSendCodecs failed and send codec is not changed on engine.
673 EXPECT_FALSE(channel_->SetSendCodecs(codec_list));
674 webrtc::VideoCodec gcodec;
675 // Set plType to something other than the value to test against ensuring
676 // that failure will happen if it is not changed.
677 gcodec.plType = 1;
678 EXPECT_EQ(0, vie_.GetSendCodec(channel_num, gcodec));
679 EXPECT_EQ(0, gcodec.plType);
680}
681
682// Test that vie send codec is reset on new video frame size.
683TEST_F(WebRtcVideoEngineTestFake, ResetVieSendCodecOnNewFrameSize) {
684 EXPECT_TRUE(SetupEngine());
685 int channel_num = vie_.GetLastChannel();
686
687 // Set send codec.
688 std::vector<cricket::VideoCodec> codec_list;
689 codec_list.push_back(kVP8Codec);
690 EXPECT_TRUE(channel_->SetSendCodecs(codec_list));
691 EXPECT_TRUE(channel_->AddSendStream(
692 cricket::StreamParams::CreateLegacy(123)));
693 EXPECT_TRUE(channel_->SetSend(true));
694
695 // Capture a smaller frame and verify vie send codec has been reset to
696 // the new size.
697 SendI420Frame(kVP8Codec.width / 2, kVP8Codec.height / 2);
698 VerifyVP8SendCodec(channel_num, kVP8Codec.width / 2, kVP8Codec.height / 2);
699
700 // Capture a frame bigger than send_codec_ and verify vie send codec has been
701 // reset (and clipped) to send_codec_.
702 SendI420Frame(kVP8Codec.width * 2, kVP8Codec.height * 2);
703 VerifyVP8SendCodec(channel_num, kVP8Codec.width, kVP8Codec.height);
704}
705
706// Test that we set our inbound codecs properly.
707TEST_F(WebRtcVideoEngineTestFake, SetRecvCodecs) {
708 EXPECT_TRUE(SetupEngine());
709 int channel_num = vie_.GetLastChannel();
710
711 std::vector<cricket::VideoCodec> codecs;
712 codecs.push_back(kVP8Codec);
713 EXPECT_TRUE(channel_->SetRecvCodecs(codecs));
714
715 webrtc::VideoCodec wcodec;
716 EXPECT_TRUE(engine_.ConvertFromCricketVideoCodec(kVP8Codec, &wcodec));
717 EXPECT_TRUE(vie_.ReceiveCodecRegistered(channel_num, wcodec));
718}
719
buildbot@webrtc.orgdd4742a2014-05-07 14:50:35 +0000720// Test that we set our inbound RTX codecs properly.
721TEST_F(WebRtcVideoEngineTestFake, SetRecvCodecsWithRtx) {
722 EXPECT_TRUE(SetupEngine());
723 int channel_num = vie_.GetLastChannel();
724
725 std::vector<cricket::VideoCodec> codecs;
726 cricket::VideoCodec rtx_codec(96, "rtx", 0, 0, 0, 0);
727 codecs.push_back(rtx_codec);
728 // Should fail since there's no associated payload type set.
729 EXPECT_FALSE(channel_->SetRecvCodecs(codecs));
730
731 codecs[0].SetParam("apt", 97);
732 // Should still fail since the we don't support RTX on this APT.
733 EXPECT_FALSE(channel_->SetRecvCodecs(codecs));
734
735 codecs[0].SetParam("apt", kVP8Codec.id);
736 // Should still fail since the associated payload type is unknown.
737 EXPECT_FALSE(channel_->SetRecvCodecs(codecs));
738
739 codecs.push_back(kVP8Codec);
740 EXPECT_TRUE(channel_->SetRecvCodecs(codecs));
741
742 webrtc::VideoCodec wcodec;
743 // Should not have been registered as a WebRTC codec.
744 EXPECT_TRUE(engine_.ConvertFromCricketVideoCodec(rtx_codec, &wcodec));
745 EXPECT_STREQ("rtx", wcodec.plName);
746 EXPECT_FALSE(vie_.ReceiveCodecRegistered(channel_num, wcodec));
747
748 // The RTX payload type should have been set.
749 EXPECT_EQ(rtx_codec.id, vie_.GetRtxRecvPayloadType(channel_num));
750}
751
752// Test that RTX packets are routed to the correct video channel.
753TEST_F(WebRtcVideoEngineTestFake, TestReceiveRtx) {
754 EXPECT_TRUE(SetupEngine());
755
756 // Setup three channels with associated RTX streams.
757 int channel_num[ARRAY_SIZE(kSsrcs3)];
758 for (size_t i = 0; i < ARRAY_SIZE(kSsrcs3); ++i) {
759 cricket::StreamParams params =
760 cricket::StreamParams::CreateLegacy(kSsrcs3[i]);
761 params.AddFidSsrc(kSsrcs3[i], kRtxSsrcs3[i]);
762 EXPECT_TRUE(channel_->AddRecvStream(params));
763 channel_num[i] = vie_.GetLastChannel();
764 }
765
766 // Register codecs.
767 std::vector<cricket::VideoCodec> codec_list;
768 codec_list.push_back(kVP8Codec720p);
769 cricket::VideoCodec rtx_codec(96, "rtx", 0, 0, 0, 0);
770 rtx_codec.SetParam("apt", kVP8Codec.id);
771 codec_list.push_back(rtx_codec);
772 EXPECT_TRUE(channel_->SetRecvCodecs(codec_list));
773
774 // Construct a fake RTX packet and verify that it is passed to the
775 // right WebRTC channel.
776 const size_t kDataLength = 12;
777 uint8_t data[kDataLength];
778 memset(data, 0, sizeof(data));
779 data[0] = 0x80;
780 data[1] = rtx_codec.id;
781 talk_base::SetBE32(&data[8], kRtxSsrcs3[1]);
782 talk_base::Buffer packet(data, kDataLength);
783 talk_base::PacketTime packet_time;
784 channel_->OnPacketReceived(&packet, packet_time);
785 EXPECT_NE(rtx_codec.id, vie_.GetLastRecvdPayloadType(channel_num[0]));
786 EXPECT_EQ(rtx_codec.id, vie_.GetLastRecvdPayloadType(channel_num[1]));
787 EXPECT_NE(rtx_codec.id, vie_.GetLastRecvdPayloadType(channel_num[2]));
788}
789
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000790// Test that channel connects and disconnects external capturer correctly.
791TEST_F(WebRtcVideoEngineTestFake, HasExternalCapturer) {
792 EXPECT_TRUE(SetupEngine());
793 int channel_num = vie_.GetLastChannel();
794
795 EXPECT_EQ(1, vie_.GetNumCapturers());
796 int capture_id = vie_.GetCaptureId(channel_num);
797 EXPECT_EQ(channel_num, vie_.GetCaptureChannelId(capture_id));
798
799 // Delete the channel should disconnect the capturer.
800 delete channel_;
801 channel_ = NULL;
802 EXPECT_EQ(0, vie_.GetNumCapturers());
803}
804
805// Test that channel adds and removes renderer correctly.
806TEST_F(WebRtcVideoEngineTestFake, HasRenderer) {
807 EXPECT_TRUE(SetupEngine());
808 int channel_num = vie_.GetLastChannel();
809
810 EXPECT_TRUE(vie_.GetHasRenderer(channel_num));
811 EXPECT_FALSE(vie_.GetRenderStarted(channel_num));
812}
813
814// Test that rtcp is enabled on the channel.
815TEST_F(WebRtcVideoEngineTestFake, RtcpEnabled) {
816 EXPECT_TRUE(SetupEngine());
817 int channel_num = vie_.GetLastChannel();
818 EXPECT_EQ(webrtc::kRtcpCompound_RFC4585, vie_.GetRtcpStatus(channel_num));
819}
820
821// Test that key frame request method is set on the channel.
822TEST_F(WebRtcVideoEngineTestFake, KeyFrameRequestEnabled) {
823 EXPECT_TRUE(SetupEngine());
824 int channel_num = vie_.GetLastChannel();
825 EXPECT_EQ(webrtc::kViEKeyFrameRequestPliRtcp,
826 vie_.GetKeyFrameRequestMethod(channel_num));
827}
828
829// Test that remb receive and send is enabled for the default channel in a 1:1
830// call.
831TEST_F(WebRtcVideoEngineTestFake, RembEnabled) {
832 EXPECT_TRUE(SetupEngine());
833 int channel_num = vie_.GetLastChannel();
834 EXPECT_TRUE(channel_->AddSendStream(
835 cricket::StreamParams::CreateLegacy(1)));
836 EXPECT_TRUE(channel_->SetSendCodecs(engine_.codecs()));
837 EXPECT_TRUE(vie_.GetRembStatusBwPartition(channel_num));
838 EXPECT_TRUE(channel_->SetSend(true));
839 EXPECT_TRUE(vie_.GetRembStatusBwPartition(channel_num));
840 EXPECT_TRUE(vie_.GetRembStatusContribute(channel_num));
841}
842
843// When in conference mode, test that remb is enabled on a receive channel but
844// not for the default channel and that it uses the default channel for sending
845// remb packets.
846TEST_F(WebRtcVideoEngineTestFake, RembEnabledOnReceiveChannels) {
847 EXPECT_TRUE(SetupEngine());
848 int default_channel = vie_.GetLastChannel();
849 cricket::VideoOptions options;
850 options.conference_mode.Set(true);
851 EXPECT_TRUE(channel_->SetOptions(options));
852 EXPECT_TRUE(channel_->AddSendStream(
853 cricket::StreamParams::CreateLegacy(1)));
854 EXPECT_TRUE(channel_->SetSendCodecs(engine_.codecs()));
855 EXPECT_TRUE(vie_.GetRembStatusBwPartition(default_channel));
856 EXPECT_TRUE(vie_.GetRembStatusContribute(default_channel));
857 EXPECT_TRUE(channel_->SetSend(true));
858 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(1)));
859 int new_channel_num = vie_.GetLastChannel();
860 EXPECT_NE(default_channel, new_channel_num);
861
862 EXPECT_TRUE(vie_.GetRembStatusBwPartition(default_channel));
863 EXPECT_TRUE(vie_.GetRembStatusContribute(default_channel));
864 EXPECT_FALSE(vie_.GetRembStatusBwPartition(new_channel_num));
865 EXPECT_TRUE(vie_.GetRembStatusContribute(new_channel_num));
866}
867
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000868TEST_F(WebRtcVideoEngineTestFake, RecvStreamWithRtx) {
869 EXPECT_TRUE(SetupEngine());
870 int default_channel = vie_.GetLastChannel();
871 cricket::VideoOptions options;
872 options.conference_mode.Set(true);
873 EXPECT_TRUE(channel_->SetOptions(options));
874 EXPECT_TRUE(channel_->AddSendStream(
875 cricket::CreateSimWithRtxStreamParams("cname",
876 MAKE_VECTOR(kSsrcs3),
877 MAKE_VECTOR(kRtxSsrcs3))));
878 EXPECT_TRUE(channel_->SetSendCodecs(engine_.codecs()));
879 EXPECT_TRUE(channel_->SetSend(true));
880 EXPECT_TRUE(channel_->AddRecvStream(
881 cricket::CreateSimWithRtxStreamParams("cname",
882 MAKE_VECTOR(kSsrcs1),
883 MAKE_VECTOR(kRtxSsrc1))));
884 int new_channel_num = vie_.GetLastChannel();
885 EXPECT_NE(default_channel, new_channel_num);
886 EXPECT_EQ(4, vie_.GetRemoteRtxSsrc(new_channel_num));
887}
888
889TEST_F(WebRtcVideoEngineTestFake, RecvStreamNoRtx) {
890 EXPECT_TRUE(SetupEngine());
891 int default_channel = vie_.GetLastChannel();
892 cricket::VideoOptions options;
893 options.conference_mode.Set(true);
894 EXPECT_TRUE(channel_->SetOptions(options));
895 EXPECT_TRUE(channel_->AddSendStream(
896 cricket::CreateSimWithRtxStreamParams("cname",
897 MAKE_VECTOR(kSsrcs3),
898 MAKE_VECTOR(kRtxSsrcs3))));
899 EXPECT_TRUE(channel_->SetSendCodecs(engine_.codecs()));
900 EXPECT_TRUE(channel_->SetSend(true));
901 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(1)));
902 int new_channel_num = vie_.GetLastChannel();
903 EXPECT_NE(default_channel, new_channel_num);
904 EXPECT_EQ(-1, vie_.GetRemoteRtxSsrc(new_channel_num));
905}
906
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000907// Test support for RTP timestamp offset header extension.
buildbot@webrtc.org150835e2014-05-06 15:54:38 +0000908TEST_F(WebRtcVideoEngineTestFake, SendRtpTimestampOffsetHeaderExtensions) {
909 TestSetSendRtpHeaderExtensions(kRtpTimestampOffsetHeaderExtension);
910}
911TEST_F(WebRtcVideoEngineTestFake, RecvRtpTimestampOffsetHeaderExtensions) {
912 TestSetRecvRtpHeaderExtensions(kRtpTimestampOffsetHeaderExtension);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000913}
914
915// Test support for absolute send time header extension.
buildbot@webrtc.org150835e2014-05-06 15:54:38 +0000916TEST_F(WebRtcVideoEngineTestFake, SendAbsoluteSendTimeHeaderExtensions) {
917 TestSetSendRtpHeaderExtensions(kRtpAbsoluteSenderTimeHeaderExtension);
918}
919TEST_F(WebRtcVideoEngineTestFake, RecvAbsoluteSendTimeHeaderExtensions) {
920 TestSetRecvRtpHeaderExtensions(kRtpAbsoluteSenderTimeHeaderExtension);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000921}
922
923TEST_F(WebRtcVideoEngineTestFake, LeakyBucketTest) {
924 EXPECT_TRUE(SetupEngine());
925
926 // Verify this is off by default.
927 EXPECT_TRUE(channel_->AddSendStream(cricket::StreamParams::CreateLegacy(1)));
928 int first_send_channel = vie_.GetLastChannel();
929 EXPECT_FALSE(vie_.GetTransmissionSmoothingStatus(first_send_channel));
930
931 // Enable the experiment and verify.
932 cricket::VideoOptions options;
933 options.conference_mode.Set(true);
934 options.video_leaky_bucket.Set(true);
935 EXPECT_TRUE(channel_->SetOptions(options));
936 EXPECT_TRUE(vie_.GetTransmissionSmoothingStatus(first_send_channel));
937
938 // Add a receive channel and verify leaky bucket isn't enabled.
939 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(2)));
940 int recv_channel_num = vie_.GetLastChannel();
941 EXPECT_NE(first_send_channel, recv_channel_num);
942 EXPECT_FALSE(vie_.GetTransmissionSmoothingStatus(recv_channel_num));
943
944 // Add a new send stream and verify leaky bucket is enabled from start.
945 EXPECT_TRUE(channel_->AddSendStream(cricket::StreamParams::CreateLegacy(3)));
946 int second_send_channel = vie_.GetLastChannel();
947 EXPECT_NE(first_send_channel, second_send_channel);
948 EXPECT_TRUE(vie_.GetTransmissionSmoothingStatus(second_send_channel));
949}
950
henrike@webrtc.org6e3dbc22014-03-25 17:09:47 +0000951// Verify that SuspendBelowMinBitrate is enabled if it is set in the options.
952TEST_F(WebRtcVideoEngineTestFake, SuspendBelowMinBitrateTest) {
953 EXPECT_TRUE(SetupEngine());
954
955 // Verify this is off by default.
956 EXPECT_TRUE(channel_->AddSendStream(cricket::StreamParams::CreateLegacy(1)));
957 int first_send_channel = vie_.GetLastChannel();
958 EXPECT_FALSE(vie_.GetSuspendBelowMinBitrateStatus(first_send_channel));
959
960 // Enable the experiment and verify.
961 cricket::VideoOptions options;
962 options.suspend_below_min_bitrate.Set(true);
963 EXPECT_TRUE(channel_->SetOptions(options));
964 EXPECT_TRUE(vie_.GetSuspendBelowMinBitrateStatus(first_send_channel));
965
966 // Add a new send stream and verify suspend_below_min_bitrate is enabled.
967 EXPECT_TRUE(channel_->AddSendStream(cricket::StreamParams::CreateLegacy(2)));
968 int second_send_channel = vie_.GetLastChannel();
969 EXPECT_NE(first_send_channel, second_send_channel);
970 EXPECT_TRUE(vie_.GetSuspendBelowMinBitrateStatus(second_send_channel));
971}
972
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000973TEST_F(WebRtcVideoEngineTestFake, BufferedModeLatency) {
974 EXPECT_TRUE(SetupEngine());
975
976 // Verify this is off by default.
977 EXPECT_TRUE(channel_->AddSendStream(cricket::StreamParams::CreateLegacy(1)));
978 int first_send_channel = vie_.GetLastChannel();
979 EXPECT_EQ(0, vie_.GetSenderTargetDelay(first_send_channel));
980 EXPECT_EQ(0, vie_.GetReceiverTargetDelay(first_send_channel));
981
982 // Enable the experiment and verify. The default channel will have both
983 // sender and receiver buffered mode enabled.
984 cricket::VideoOptions options;
985 options.conference_mode.Set(true);
986 options.buffered_mode_latency.Set(100);
987 EXPECT_TRUE(channel_->SetOptions(options));
988 EXPECT_EQ(100, vie_.GetSenderTargetDelay(first_send_channel));
989 EXPECT_EQ(100, vie_.GetReceiverTargetDelay(first_send_channel));
990
991 // Add a receive channel and verify sender buffered mode isn't enabled.
992 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(2)));
993 int recv_channel_num = vie_.GetLastChannel();
994 EXPECT_NE(first_send_channel, recv_channel_num);
995 EXPECT_EQ(0, vie_.GetSenderTargetDelay(recv_channel_num));
996 EXPECT_EQ(100, vie_.GetReceiverTargetDelay(recv_channel_num));
997
998 // Add a new send stream and verify sender buffered mode is enabled.
999 EXPECT_TRUE(channel_->AddSendStream(cricket::StreamParams::CreateLegacy(3)));
1000 int second_send_channel = vie_.GetLastChannel();
1001 EXPECT_NE(first_send_channel, second_send_channel);
1002 EXPECT_EQ(100, vie_.GetSenderTargetDelay(second_send_channel));
1003 EXPECT_EQ(0, vie_.GetReceiverTargetDelay(second_send_channel));
1004
1005 // Disable sender buffered mode and verify.
1006 options.buffered_mode_latency.Set(cricket::kBufferedModeDisabled);
1007 EXPECT_TRUE(channel_->SetOptions(options));
1008 EXPECT_EQ(0, vie_.GetSenderTargetDelay(first_send_channel));
1009 EXPECT_EQ(0, vie_.GetReceiverTargetDelay(first_send_channel));
1010 EXPECT_EQ(0, vie_.GetSenderTargetDelay(second_send_channel));
1011 EXPECT_EQ(0, vie_.GetReceiverTargetDelay(second_send_channel));
1012 EXPECT_EQ(0, vie_.GetSenderTargetDelay(recv_channel_num));
1013 EXPECT_EQ(0, vie_.GetReceiverTargetDelay(recv_channel_num));
1014}
1015
1016TEST_F(WebRtcVideoEngineTestFake, AdditiveVideoOptions) {
1017 EXPECT_TRUE(SetupEngine());
1018
1019 EXPECT_TRUE(channel_->AddSendStream(cricket::StreamParams::CreateLegacy(1)));
1020 int first_send_channel = vie_.GetLastChannel();
1021 EXPECT_EQ(0, vie_.GetSenderTargetDelay(first_send_channel));
1022 EXPECT_EQ(0, vie_.GetReceiverTargetDelay(first_send_channel));
1023
1024 cricket::VideoOptions options1;
1025 options1.buffered_mode_latency.Set(100);
1026 EXPECT_TRUE(channel_->SetOptions(options1));
1027 EXPECT_EQ(100, vie_.GetSenderTargetDelay(first_send_channel));
1028 EXPECT_EQ(100, vie_.GetReceiverTargetDelay(first_send_channel));
1029 EXPECT_FALSE(vie_.GetTransmissionSmoothingStatus(first_send_channel));
1030
1031 cricket::VideoOptions options2;
1032 options2.video_leaky_bucket.Set(true);
1033 EXPECT_TRUE(channel_->SetOptions(options2));
1034 EXPECT_TRUE(vie_.GetTransmissionSmoothingStatus(first_send_channel));
1035 // The buffered_mode_latency still takes effect.
1036 EXPECT_EQ(100, vie_.GetSenderTargetDelay(first_send_channel));
1037 EXPECT_EQ(100, vie_.GetReceiverTargetDelay(first_send_channel));
1038
1039 options1.buffered_mode_latency.Set(50);
1040 EXPECT_TRUE(channel_->SetOptions(options1));
1041 EXPECT_EQ(50, vie_.GetSenderTargetDelay(first_send_channel));
1042 EXPECT_EQ(50, vie_.GetReceiverTargetDelay(first_send_channel));
1043 // The video_leaky_bucket still takes effect.
1044 EXPECT_TRUE(vie_.GetTransmissionSmoothingStatus(first_send_channel));
1045}
1046
henrike@webrtc.orgb0ecc1c2014-03-26 22:44:28 +00001047TEST_F(WebRtcVideoEngineTestFake, SetCpuOveruseOptionsWithCaptureJitterMethod) {
1048 EXPECT_TRUE(SetupEngine());
1049
1050 // Verify this is off by default.
1051 EXPECT_TRUE(channel_->AddSendStream(cricket::StreamParams::CreateLegacy(1)));
1052 int first_send_channel = vie_.GetLastChannel();
1053 webrtc::CpuOveruseOptions cpu_option =
1054 vie_.GetCpuOveruseOptions(first_send_channel);
1055 EXPECT_EQ(0, cpu_option.low_capture_jitter_threshold_ms);
1056 EXPECT_EQ(0, cpu_option.high_capture_jitter_threshold_ms);
1057 EXPECT_FALSE(cpu_option.enable_capture_jitter_method);
1058 EXPECT_FALSE(cpu_option.enable_encode_usage_method);
1059
1060 // Set low and high threshold and verify that cpu options are set.
1061 cricket::VideoOptions options;
1062 options.conference_mode.Set(true);
1063 options.cpu_underuse_threshold.Set(10);
1064 options.cpu_overuse_threshold.Set(20);
1065 EXPECT_TRUE(channel_->SetOptions(options));
1066 cpu_option = vie_.GetCpuOveruseOptions(first_send_channel);
1067 EXPECT_EQ(10, cpu_option.low_capture_jitter_threshold_ms);
1068 EXPECT_EQ(20, cpu_option.high_capture_jitter_threshold_ms);
1069 EXPECT_TRUE(cpu_option.enable_capture_jitter_method);
1070 EXPECT_FALSE(cpu_option.enable_encode_usage_method);
1071
1072 // Add a receive channel and verify that cpu options are not set.
1073 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(2)));
1074 int recv_channel_num = vie_.GetLastChannel();
1075 EXPECT_NE(first_send_channel, recv_channel_num);
1076 cpu_option = vie_.GetCpuOveruseOptions(recv_channel_num);
1077 EXPECT_EQ(0, cpu_option.low_capture_jitter_threshold_ms);
1078 EXPECT_EQ(0, cpu_option.high_capture_jitter_threshold_ms);
1079 EXPECT_FALSE(cpu_option.enable_capture_jitter_method);
1080 EXPECT_FALSE(cpu_option.enable_encode_usage_method);
1081
1082 // Add a new send stream and verify that cpu options are set from start.
1083 EXPECT_TRUE(channel_->AddSendStream(cricket::StreamParams::CreateLegacy(3)));
1084 int second_send_channel = vie_.GetLastChannel();
1085 EXPECT_NE(first_send_channel, second_send_channel);
1086 cpu_option = vie_.GetCpuOveruseOptions(second_send_channel);
1087 EXPECT_EQ(10, cpu_option.low_capture_jitter_threshold_ms);
1088 EXPECT_EQ(20, cpu_option.high_capture_jitter_threshold_ms);
1089 EXPECT_TRUE(cpu_option.enable_capture_jitter_method);
1090 EXPECT_FALSE(cpu_option.enable_encode_usage_method);
1091}
1092
1093TEST_F(WebRtcVideoEngineTestFake, SetInvalidCpuOveruseThresholds) {
1094 EXPECT_TRUE(SetupEngine());
1095 EXPECT_TRUE(channel_->AddSendStream(cricket::StreamParams::CreateLegacy(1)));
1096 int channel_num = vie_.GetLastChannel();
1097
1098 // Only low threshold set. Verify that cpu options are not set.
1099 cricket::VideoOptions options;
1100 options.conference_mode.Set(true);
1101 options.cpu_underuse_threshold.Set(10);
1102 EXPECT_TRUE(channel_->SetOptions(options));
1103 webrtc::CpuOveruseOptions cpu_option = vie_.GetCpuOveruseOptions(channel_num);
1104 EXPECT_EQ(0, cpu_option.low_capture_jitter_threshold_ms);
1105 EXPECT_EQ(0, cpu_option.high_capture_jitter_threshold_ms);
1106 EXPECT_FALSE(cpu_option.enable_capture_jitter_method);
1107 EXPECT_FALSE(cpu_option.enable_encode_usage_method);
1108
1109 // Set high threshold to a negative value. Verify that options are not set.
1110 options.cpu_overuse_threshold.Set(-1);
1111 EXPECT_TRUE(channel_->SetOptions(options));
1112 cpu_option = vie_.GetCpuOveruseOptions(channel_num);
1113 EXPECT_EQ(0, cpu_option.low_capture_jitter_threshold_ms);
1114 EXPECT_EQ(0, cpu_option.high_capture_jitter_threshold_ms);
1115 EXPECT_FALSE(cpu_option.enable_capture_jitter_method);
1116 EXPECT_FALSE(cpu_option.enable_encode_usage_method);
1117
1118 // Low and high threshold valid. Verify that cpu options are set.
1119 options.cpu_overuse_threshold.Set(20);
1120 EXPECT_TRUE(channel_->SetOptions(options));
1121 cpu_option = vie_.GetCpuOveruseOptions(channel_num);
1122 EXPECT_EQ(10, cpu_option.low_capture_jitter_threshold_ms);
1123 EXPECT_EQ(20, cpu_option.high_capture_jitter_threshold_ms);
1124 EXPECT_TRUE(cpu_option.enable_capture_jitter_method);
1125 EXPECT_FALSE(cpu_option.enable_encode_usage_method);
1126}
1127
1128TEST_F(WebRtcVideoEngineTestFake, SetCpuOveruseOptionsWithEncodeUsageMethod) {
1129 EXPECT_TRUE(SetupEngine());
1130 EXPECT_TRUE(channel_->AddSendStream(cricket::StreamParams::CreateLegacy(1)));
1131 int first_send_channel = vie_.GetLastChannel();
1132
1133 // Set low and high threshold and enable encode usage method.
1134 // Verify that cpu options are set.
1135 cricket::VideoOptions options;
1136 options.conference_mode.Set(true);
1137 options.cpu_underuse_threshold.Set(10);
1138 options.cpu_overuse_threshold.Set(20);
1139 options.cpu_overuse_encode_usage.Set(true);
1140 EXPECT_TRUE(channel_->SetOptions(options));
1141 webrtc::CpuOveruseOptions cpu_option =
1142 vie_.GetCpuOveruseOptions(first_send_channel);
1143 EXPECT_EQ(10, cpu_option.low_encode_usage_threshold_percent);
1144 EXPECT_EQ(20, cpu_option.high_encode_usage_threshold_percent);
1145 EXPECT_FALSE(cpu_option.enable_capture_jitter_method);
1146 EXPECT_TRUE(cpu_option.enable_encode_usage_method);
1147
1148 // Add a new send stream and verify that cpu options are set from start.
1149 EXPECT_TRUE(channel_->AddSendStream(cricket::StreamParams::CreateLegacy(3)));
1150 int second_send_channel = vie_.GetLastChannel();
1151 EXPECT_NE(first_send_channel, second_send_channel);
1152 cpu_option = vie_.GetCpuOveruseOptions(second_send_channel);
1153 EXPECT_EQ(10, cpu_option.low_encode_usage_threshold_percent);
1154 EXPECT_EQ(20, cpu_option.high_encode_usage_threshold_percent);
1155 EXPECT_FALSE(cpu_option.enable_capture_jitter_method);
1156 EXPECT_TRUE(cpu_option.enable_encode_usage_method);
1157}
henrike@webrtc.orgb0ecc1c2014-03-26 22:44:28 +00001158
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001159// Test that AddRecvStream doesn't create new channel for 1:1 call.
1160TEST_F(WebRtcVideoEngineTestFake, AddRecvStream1On1) {
1161 EXPECT_TRUE(SetupEngine());
1162 int channel_num = vie_.GetLastChannel();
1163 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(1)));
1164 EXPECT_EQ(channel_num, vie_.GetLastChannel());
1165}
1166
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +00001167// Test that NACK, PLI and REMB are enabled for internal codec.
1168TEST_F(WebRtcVideoEngineTestFake, InternalCodecFeedbackParams) {
1169 EXPECT_TRUE(SetupEngine());
1170
1171 std::vector<cricket::VideoCodec> codecs(engine_.codecs());
1172 // Vp8 will appear at the beginning.
1173 size_t pos = 0;
1174 EXPECT_EQ("VP8", codecs[pos].name);
1175 VerifyCodecFeedbackParams(codecs[pos]);
1176}
1177
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001178// Test that AddRecvStream doesn't change remb for 1:1 call.
1179TEST_F(WebRtcVideoEngineTestFake, NoRembChangeAfterAddRecvStream) {
1180 EXPECT_TRUE(SetupEngine());
1181 int channel_num = vie_.GetLastChannel();
1182 EXPECT_TRUE(channel_->AddSendStream(
1183 cricket::StreamParams::CreateLegacy(1)));
1184 EXPECT_TRUE(channel_->SetSendCodecs(engine_.codecs()));
1185 EXPECT_TRUE(vie_.GetRembStatusBwPartition(channel_num));
1186 EXPECT_TRUE(vie_.GetRembStatusContribute(channel_num));
1187 EXPECT_TRUE(channel_->SetSend(true));
1188 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(1)));
1189 EXPECT_TRUE(vie_.GetRembStatusBwPartition(channel_num));
1190 EXPECT_TRUE(vie_.GetRembStatusContribute(channel_num));
1191}
1192
1193// Verify default REMB setting and that it can be turned on and off.
1194TEST_F(WebRtcVideoEngineTestFake, RembOnOff) {
1195 EXPECT_TRUE(SetupEngine());
1196 int channel_num = vie_.GetLastChannel();
1197 // Verify REMB sending is always off by default.
1198 EXPECT_FALSE(vie_.GetRembStatusBwPartition(channel_num));
1199
1200 // Verify that REMB is turned on when setting default codecs since the
1201 // default codecs have REMB enabled.
1202 EXPECT_TRUE(channel_->SetSendCodecs(engine_.codecs()));
1203 EXPECT_TRUE(vie_.GetRembStatusBwPartition(channel_num));
1204
1205 // Verify that REMB is turned off when codecs without REMB are set.
1206 std::vector<cricket::VideoCodec> codecs = engine_.codecs();
1207 // Clearing the codecs' FeedbackParams and setting send codecs should disable
1208 // REMB.
1209 for (std::vector<cricket::VideoCodec>::iterator iter = codecs.begin();
1210 iter != codecs.end(); ++iter) {
1211 // Intersecting with empty will clear the FeedbackParams.
1212 cricket::FeedbackParams empty_params;
1213 iter->feedback_params.Intersect(empty_params);
1214 EXPECT_TRUE(iter->feedback_params.params().empty());
1215 }
1216 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1217 EXPECT_FALSE(vie_.GetRembStatusBwPartition(channel_num));
1218}
1219
1220// Test that nack is enabled on the channel if we don't offer red/fec.
1221TEST_F(WebRtcVideoEngineTestFake, NackEnabled) {
1222 EXPECT_TRUE(SetupEngine());
1223 int channel_num = vie_.GetLastChannel();
1224 std::vector<cricket::VideoCodec> codecs(engine_.codecs());
1225 codecs.resize(1); // toss out red and ulpfec
1226 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1227 EXPECT_TRUE(vie_.GetNackStatus(channel_num));
1228}
1229
1230// Test that we enable hybrid NACK FEC mode.
1231TEST_F(WebRtcVideoEngineTestFake, HybridNackFec) {
1232 EXPECT_TRUE(SetupEngine());
1233 int channel_num = vie_.GetLastChannel();
1234 EXPECT_TRUE(channel_->SetRecvCodecs(engine_.codecs()));
1235 EXPECT_TRUE(channel_->SetSendCodecs(engine_.codecs()));
1236 EXPECT_TRUE(vie_.GetHybridNackFecStatus(channel_num));
1237 EXPECT_FALSE(vie_.GetNackStatus(channel_num));
1238}
1239
1240// Test that we enable hybrid NACK FEC mode when calling SetSendCodecs and
1241// SetReceiveCodecs in reversed order.
1242TEST_F(WebRtcVideoEngineTestFake, HybridNackFecReversedOrder) {
1243 EXPECT_TRUE(SetupEngine());
1244 int channel_num = vie_.GetLastChannel();
1245 EXPECT_TRUE(channel_->SetSendCodecs(engine_.codecs()));
1246 EXPECT_TRUE(channel_->SetRecvCodecs(engine_.codecs()));
1247 EXPECT_TRUE(vie_.GetHybridNackFecStatus(channel_num));
1248 EXPECT_FALSE(vie_.GetNackStatus(channel_num));
1249}
1250
1251// Test NACK vs Hybrid NACK/FEC interop call setup, i.e. only use NACK even if
1252// red/fec is offered as receive codec.
1253TEST_F(WebRtcVideoEngineTestFake, VideoProtectionInterop) {
1254 EXPECT_TRUE(SetupEngine());
1255 int channel_num = vie_.GetLastChannel();
1256 std::vector<cricket::VideoCodec> recv_codecs(engine_.codecs());
1257 std::vector<cricket::VideoCodec> send_codecs(engine_.codecs());
1258 // Only add VP8 as send codec.
1259 send_codecs.resize(1);
1260 EXPECT_TRUE(channel_->SetRecvCodecs(recv_codecs));
1261 EXPECT_TRUE(channel_->SetSendCodecs(send_codecs));
1262 EXPECT_FALSE(vie_.GetHybridNackFecStatus(channel_num));
1263 EXPECT_TRUE(vie_.GetNackStatus(channel_num));
1264}
1265
1266// Test NACK vs Hybrid NACK/FEC interop call setup, i.e. only use NACK even if
1267// red/fec is offered as receive codec. Call order reversed compared to
1268// VideoProtectionInterop.
1269TEST_F(WebRtcVideoEngineTestFake, VideoProtectionInteropReversed) {
1270 EXPECT_TRUE(SetupEngine());
1271 int channel_num = vie_.GetLastChannel();
1272 std::vector<cricket::VideoCodec> recv_codecs(engine_.codecs());
1273 std::vector<cricket::VideoCodec> send_codecs(engine_.codecs());
1274 // Only add VP8 as send codec.
1275 send_codecs.resize(1);
1276 EXPECT_TRUE(channel_->SetSendCodecs(send_codecs));
1277 EXPECT_TRUE(channel_->SetRecvCodecs(recv_codecs));
1278 EXPECT_FALSE(vie_.GetHybridNackFecStatus(channel_num));
1279 EXPECT_TRUE(vie_.GetNackStatus(channel_num));
1280}
1281
1282// Test that NACK, not hybrid mode, is enabled in conference mode.
1283TEST_F(WebRtcVideoEngineTestFake, HybridNackFecConference) {
1284 EXPECT_TRUE(SetupEngine());
1285 // Setup the send channel.
1286 int send_channel_num = vie_.GetLastChannel();
1287 cricket::VideoOptions options;
1288 options.conference_mode.Set(true);
1289 EXPECT_TRUE(channel_->SetOptions(options));
1290 EXPECT_TRUE(channel_->SetRecvCodecs(engine_.codecs()));
1291 EXPECT_TRUE(channel_->SetSendCodecs(engine_.codecs()));
1292 EXPECT_FALSE(vie_.GetHybridNackFecStatus(send_channel_num));
1293 EXPECT_TRUE(vie_.GetNackStatus(send_channel_num));
1294 // Add a receive stream.
1295 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(1)));
1296 int receive_channel_num = vie_.GetLastChannel();
1297 EXPECT_FALSE(vie_.GetHybridNackFecStatus(receive_channel_num));
1298 EXPECT_TRUE(vie_.GetNackStatus(receive_channel_num));
1299}
1300
1301// Test that when AddRecvStream in conference mode, a new channel is created
1302// for receiving. And the new channel's "original channel" is the send channel.
1303TEST_F(WebRtcVideoEngineTestFake, AddRemoveRecvStreamConference) {
1304 EXPECT_TRUE(SetupEngine());
1305 // Setup the send channel.
1306 int send_channel_num = vie_.GetLastChannel();
1307 cricket::VideoOptions options;
1308 options.conference_mode.Set(true);
1309 EXPECT_TRUE(channel_->SetOptions(options));
1310 // Add a receive stream.
1311 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(1)));
1312 int receive_channel_num = vie_.GetLastChannel();
1313 EXPECT_EQ(send_channel_num, vie_.GetOriginalChannelId(receive_channel_num));
1314 EXPECT_TRUE(channel_->RemoveRecvStream(1));
1315 EXPECT_FALSE(vie_.IsChannel(receive_channel_num));
1316}
1317
henrike@webrtc.org6e3dbc22014-03-25 17:09:47 +00001318// Test that adding/removing stream with 0 ssrc should fail (and not crash).
1319// For crbug/351699 and 350988.
1320TEST_F(WebRtcVideoEngineTestFake, AddRemoveRecvStreamWith0Ssrc) {
1321 EXPECT_TRUE(SetupEngine());
1322 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(1)));
1323 EXPECT_FALSE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(0)));
1324 EXPECT_FALSE(channel_->RemoveRecvStream(0));
1325 EXPECT_TRUE(channel_->RemoveRecvStream(1));
1326}
1327
1328TEST_F(WebRtcVideoEngineTestFake, AddRemoveSendStreamWith0Ssrc) {
1329 EXPECT_TRUE(SetupEngine());
1330 EXPECT_TRUE(channel_->AddSendStream(cricket::StreamParams::CreateLegacy(1)));
1331 EXPECT_FALSE(channel_->AddSendStream(cricket::StreamParams::CreateLegacy(0)));
1332 EXPECT_FALSE(channel_->RemoveSendStream(0));
1333 EXPECT_TRUE(channel_->RemoveSendStream(1));
1334}
1335
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001336// Test that we can create a channel and start/stop rendering out on it.
1337TEST_F(WebRtcVideoEngineTestFake, SetRender) {
1338 EXPECT_TRUE(SetupEngine());
1339 int channel_num = vie_.GetLastChannel();
1340
1341 // Verify we can start/stop/start/stop rendering.
1342 EXPECT_TRUE(channel_->SetRender(true));
1343 EXPECT_TRUE(vie_.GetRenderStarted(channel_num));
1344 EXPECT_TRUE(channel_->SetRender(false));
1345 EXPECT_FALSE(vie_.GetRenderStarted(channel_num));
1346 EXPECT_TRUE(channel_->SetRender(true));
1347 EXPECT_TRUE(vie_.GetRenderStarted(channel_num));
1348 EXPECT_TRUE(channel_->SetRender(false));
1349 EXPECT_FALSE(vie_.GetRenderStarted(channel_num));
1350}
1351
1352// Test that we can create a channel and start/stop sending out on it.
1353TEST_F(WebRtcVideoEngineTestFake, SetSend) {
1354 EXPECT_TRUE(SetupEngine());
1355 int channel_num = vie_.GetLastChannel();
wu@webrtc.orgb9a088b2014-02-13 23:18:49 +00001356 // Verify receiving is also started.
1357 EXPECT_TRUE(vie_.GetReceive(channel_num));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001358
1359 // Set send codecs on the channel.
1360 std::vector<cricket::VideoCodec> codecs;
1361 codecs.push_back(kVP8Codec);
1362 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1363 EXPECT_TRUE(channel_->AddSendStream(
1364 cricket::StreamParams::CreateLegacy(123)));
1365
1366 // Verify we can start/stop/start/stop sending.
1367 EXPECT_TRUE(channel_->SetSend(true));
1368 EXPECT_TRUE(vie_.GetSend(channel_num));
1369 EXPECT_TRUE(channel_->SetSend(false));
1370 EXPECT_FALSE(vie_.GetSend(channel_num));
1371 EXPECT_TRUE(channel_->SetSend(true));
1372 EXPECT_TRUE(vie_.GetSend(channel_num));
1373 EXPECT_TRUE(channel_->SetSend(false));
1374 EXPECT_FALSE(vie_.GetSend(channel_num));
1375}
1376
1377// Test that we set bandwidth properly when using full auto bandwidth mode.
1378TEST_F(WebRtcVideoEngineTestFake, SetBandwidthAuto) {
1379 EXPECT_TRUE(SetupEngine());
1380 int channel_num = vie_.GetLastChannel();
1381 EXPECT_TRUE(channel_->SetSendCodecs(engine_.codecs()));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001382 EXPECT_TRUE(channel_->SetMaxSendBandwidth(cricket::kAutoBandwidth));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001383 VerifyVP8SendCodec(channel_num, kVP8Codec.width, kVP8Codec.height);
1384}
1385
1386// Test that we set bandwidth properly when using auto with upper bound.
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001387TEST_F(WebRtcVideoEngineTestFake, SetBandwidthCapped) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001388 EXPECT_TRUE(SetupEngine());
1389 int channel_num = vie_.GetLastChannel();
1390 EXPECT_TRUE(channel_->SetSendCodecs(engine_.codecs()));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001391 EXPECT_TRUE(channel_->SetMaxSendBandwidth(768000));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001392 VerifyVP8SendCodec(channel_num, kVP8Codec.width, kVP8Codec.height, 0, 768U);
1393}
1394
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001395// Test that we reduce the start bandwidth when the requested max is less than
1396// the default start bandwidth.
1397TEST_F(WebRtcVideoEngineTestFake, SetMaxBandwidthBelowDefaultStart) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001398 EXPECT_TRUE(SetupEngine());
1399 int channel_num = vie_.GetLastChannel();
1400 EXPECT_TRUE(channel_->SetSendCodecs(engine_.codecs()));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001401 int max_bandwidth_kbps = (kMinBandwidthKbps + kStartBandwidthKbps) / 2;
1402 EXPECT_TRUE(channel_->SetMaxSendBandwidth(max_bandwidth_kbps * 1000));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001403 VerifyVP8SendCodec(channel_num, kVP8Codec.width, kVP8Codec.height, 0,
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001404 max_bandwidth_kbps, kMinBandwidthKbps, max_bandwidth_kbps);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001405}
1406
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001407// Test that we reduce the min bandwidth when the requested max is less than
1408// the min bandwidth.
1409TEST_F(WebRtcVideoEngineTestFake, SetMaxBandwidthBelowMin) {
1410 EXPECT_TRUE(SetupEngine());
1411 int channel_num = vie_.GetLastChannel();
1412 EXPECT_TRUE(channel_->SetSendCodecs(engine_.codecs()));
1413 int max_bandwidth_kbps = kMinBandwidthKbps / 2;
1414 EXPECT_TRUE(channel_->SetMaxSendBandwidth(max_bandwidth_kbps * 1000));
1415 VerifyVP8SendCodec(channel_num, kVP8Codec.width, kVP8Codec.height, 0,
1416 max_bandwidth_kbps, max_bandwidth_kbps, max_bandwidth_kbps);
1417}
1418
1419// Test that the start bandwidth can be controlled separately from the max
1420// bandwidth.
1421TEST_F(WebRtcVideoEngineTestFake, SetStartBandwidth) {
1422 EXPECT_TRUE(SetupEngine());
1423 int channel_num = vie_.GetLastChannel();
1424 EXPECT_TRUE(channel_->SetSendCodecs(engine_.codecs()));
1425 int start_bandwidth_kbps = kStartBandwidthKbps + 1;
1426 EXPECT_TRUE(channel_->SetStartSendBandwidth(start_bandwidth_kbps * 1000));
1427 VerifyVP8SendCodec(channel_num, kVP8Codec.width, kVP8Codec.height, 0,
1428 kMaxBandwidthKbps, kMinBandwidthKbps, start_bandwidth_kbps);
1429
1430 // Check that SetMaxSendBandwidth doesn't overwrite the start bandwidth.
1431 int max_bandwidth_kbps = kMaxBandwidthKbps + 1;
1432 EXPECT_TRUE(channel_->SetMaxSendBandwidth(max_bandwidth_kbps * 1000));
1433 VerifyVP8SendCodec(channel_num, kVP8Codec.width, kVP8Codec.height, 0,
1434 max_bandwidth_kbps, kMinBandwidthKbps, start_bandwidth_kbps);
1435}
1436
wu@webrtc.org1e6cb2c2014-03-24 17:01:50 +00001437// Test that the start bandwidth can be controlled by experiment.
1438TEST_F(WebRtcVideoEngineTestFake, SetStartBandwidthOption) {
1439 EXPECT_TRUE(SetupEngine());
1440 int channel_num = vie_.GetLastChannel();
1441 EXPECT_TRUE(channel_->SetSendCodecs(engine_.codecs()));
1442 int start_bandwidth_kbps = kStartBandwidthKbps;
1443 EXPECT_TRUE(channel_->SetStartSendBandwidth(start_bandwidth_kbps * 1000));
1444 VerifyVP8SendCodec(channel_num, kVP8Codec.width, kVP8Codec.height, 0,
1445 kMaxBandwidthKbps, kMinBandwidthKbps, start_bandwidth_kbps);
1446
1447 // Set the start bitrate option.
1448 start_bandwidth_kbps = 1000;
1449 cricket::VideoOptions options;
1450 options.video_start_bitrate.Set(
1451 start_bandwidth_kbps);
1452 EXPECT_TRUE(channel_->SetOptions(options));
1453
1454 // Check that start bitrate has changed to the new value.
1455 VerifyVP8SendCodec(channel_num, kVP8Codec.width, kVP8Codec.height, 0,
1456 kMaxBandwidthKbps, kMinBandwidthKbps, start_bandwidth_kbps);
1457}
1458
buildbot@webrtc.orgd1ae89f2014-05-08 19:19:26 +00001459// Test that SetMaxSendBandwidth works as expected in conference mode.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001460TEST_F(WebRtcVideoEngineTestFake, SetBandwidthInConference) {
1461 EXPECT_TRUE(SetupEngine());
1462 int channel_num = vie_.GetLastChannel();
1463 cricket::VideoOptions options;
1464 options.conference_mode.Set(true);
1465 EXPECT_TRUE(channel_->SetOptions(options));
1466 EXPECT_TRUE(channel_->SetSendCodecs(engine_.codecs()));
1467 VerifyVP8SendCodec(channel_num, kVP8Codec.width, kVP8Codec.height);
1468
1469 // Set send bandwidth.
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001470 EXPECT_TRUE(channel_->SetMaxSendBandwidth(768000));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001471
buildbot@webrtc.orgd1ae89f2014-05-08 19:19:26 +00001472 // Verify that the max bitrate has changed.
1473 VerifyVP8SendCodec(channel_num, kVP8Codec.width, kVP8Codec.height, 0,
1474 768, kMinBandwidthKbps, kStartBandwidthKbps);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001475}
1476
buildbot@webrtc.orgd1ae89f2014-05-08 19:19:26 +00001477
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001478// Test that sending screencast frames doesn't change bitrate.
1479TEST_F(WebRtcVideoEngineTestFake, SetBandwidthScreencast) {
1480 EXPECT_TRUE(SetupEngine());
1481 int channel_num = vie_.GetLastChannel();
1482
1483 // Set send codec.
1484 cricket::VideoCodec codec(kVP8Codec);
1485 std::vector<cricket::VideoCodec> codec_list;
1486 codec_list.push_back(codec);
1487 EXPECT_TRUE(channel_->AddSendStream(
1488 cricket::StreamParams::CreateLegacy(123)));
1489 EXPECT_TRUE(channel_->SetSendCodecs(codec_list));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001490 EXPECT_TRUE(channel_->SetMaxSendBandwidth(111000));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001491 EXPECT_TRUE(channel_->SetSend(true));
1492
1493 SendI420ScreencastFrame(kVP8Codec.width, kVP8Codec.height);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001494 VerifyVP8SendCodec(channel_num, kVP8Codec.width, kVP8Codec.height, 0, 111);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001495}
1496
1497
1498// Test SetSendSsrc.
1499TEST_F(WebRtcVideoEngineTestFake, SetSendSsrcAndCname) {
1500 EXPECT_TRUE(SetupEngine());
1501 int channel_num = vie_.GetLastChannel();
1502
1503 cricket::StreamParams stream;
1504 stream.ssrcs.push_back(1234);
1505 stream.cname = "cname";
1506 channel_->AddSendStream(stream);
1507
1508 unsigned int ssrc = 0;
1509 EXPECT_EQ(0, vie_.GetLocalSSRC(channel_num, ssrc));
1510 EXPECT_EQ(1234U, ssrc);
1511 EXPECT_EQ(1, vie_.GetNumSsrcs(channel_num));
1512
1513 char rtcp_cname[256];
1514 EXPECT_EQ(0, vie_.GetRTCPCName(channel_num, rtcp_cname));
1515 EXPECT_STREQ("cname", rtcp_cname);
1516}
1517
1518
1519// Test that the local SSRC is the same on sending and receiving channels if the
1520// receive channel is created before the send channel.
1521TEST_F(WebRtcVideoEngineTestFake, SetSendSsrcAfterCreatingReceiveChannel) {
1522 EXPECT_TRUE(SetupEngine());
1523
1524 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(1)));
1525 int receive_channel_num = vie_.GetLastChannel();
1526 cricket::StreamParams stream = cricket::StreamParams::CreateLegacy(1234);
1527 EXPECT_TRUE(channel_->AddSendStream(stream));
1528 int send_channel_num = vie_.GetLastChannel();
1529 unsigned int ssrc = 0;
1530 EXPECT_EQ(0, vie_.GetLocalSSRC(send_channel_num, ssrc));
1531 EXPECT_EQ(1234U, ssrc);
1532 EXPECT_EQ(1, vie_.GetNumSsrcs(send_channel_num));
1533 ssrc = 0;
1534 EXPECT_EQ(0, vie_.GetLocalSSRC(receive_channel_num, ssrc));
1535 EXPECT_EQ(1234U, ssrc);
1536 EXPECT_EQ(1, vie_.GetNumSsrcs(receive_channel_num));
1537}
1538
1539
1540// Test SetOptions with denoising flag.
1541TEST_F(WebRtcVideoEngineTestFake, SetOptionsWithDenoising) {
1542 EXPECT_TRUE(SetupEngine());
1543 EXPECT_EQ(1, vie_.GetNumCapturers());
1544 int channel_num = vie_.GetLastChannel();
1545 int capture_id = vie_.GetCaptureId(channel_num);
1546 // Set send codecs on the channel.
1547 std::vector<cricket::VideoCodec> codecs;
1548 codecs.push_back(kVP8Codec);
1549 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1550
1551 // Set options with OPT_VIDEO_NOISE_REDUCTION flag.
1552 cricket::VideoOptions options;
1553 options.video_noise_reduction.Set(true);
1554 EXPECT_TRUE(channel_->SetOptions(options));
1555
1556 // Verify capture has denoising turned on.
1557 webrtc::VideoCodec send_codec;
1558 memset(&send_codec, 0, sizeof(send_codec)); // avoid uninitialized warning
1559 EXPECT_EQ(0, vie_.GetSendCodec(channel_num, send_codec));
1560 EXPECT_TRUE(send_codec.codecSpecific.VP8.denoisingOn);
1561 EXPECT_FALSE(vie_.GetCaptureDenoising(capture_id));
1562
1563 // Set options back to zero.
1564 options.video_noise_reduction.Set(false);
1565 EXPECT_TRUE(channel_->SetOptions(options));
1566
1567 // Verify capture has denoising turned off.
1568 EXPECT_EQ(0, vie_.GetSendCodec(channel_num, send_codec));
1569 EXPECT_FALSE(send_codec.codecSpecific.VP8.denoisingOn);
1570 EXPECT_FALSE(vie_.GetCaptureDenoising(capture_id));
1571}
1572
wu@webrtc.orga8910d22014-01-23 22:12:45 +00001573TEST_F(WebRtcVideoEngineTestFake, MultipleSendStreamsWithOneCapturer) {
wu@webrtc.org24301a62013-12-13 19:17:43 +00001574 EXPECT_TRUE(SetupEngine());
1575
1576 // Start the capturer
1577 cricket::FakeVideoCapturer capturer;
1578 cricket::VideoFormat capture_format_vga = cricket::VideoFormat(640, 480,
1579 cricket::VideoFormat::FpsToInterval(30), cricket::FOURCC_I420);
1580 EXPECT_EQ(cricket::CS_RUNNING, capturer.Start(capture_format_vga));
1581
1582 // Add send streams and connect the capturer
1583 for (unsigned int i = 0; i < sizeof(kSsrcs2)/sizeof(kSsrcs2[0]); ++i) {
1584 EXPECT_TRUE(channel_->AddSendStream(
1585 cricket::StreamParams::CreateLegacy(kSsrcs2[i])));
1586 // Register the capturer to the ssrc.
1587 EXPECT_TRUE(channel_->SetCapturer(kSsrcs2[i], &capturer));
1588 }
1589
1590 const int channel0 = vie_.GetChannelFromLocalSsrc(kSsrcs2[0]);
1591 ASSERT_NE(-1, channel0);
1592 const int channel1 = vie_.GetChannelFromLocalSsrc(kSsrcs2[1]);
1593 ASSERT_NE(-1, channel1);
1594 ASSERT_NE(channel0, channel1);
1595
wu@webrtc.orgb9a088b2014-02-13 23:18:49 +00001596 // Both channels should have started receiving after created.
1597 EXPECT_TRUE(vie_.GetReceive(channel0));
1598 EXPECT_TRUE(vie_.GetReceive(channel1));
1599
wu@webrtc.org24301a62013-12-13 19:17:43 +00001600 // Set send codec.
1601 std::vector<cricket::VideoCodec> codecs;
1602 cricket::VideoCodec send_codec(100, "VP8", 640, 480, 30, 0);
1603 codecs.push_back(send_codec);
1604 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1605
wu@webrtc.orgb9a088b2014-02-13 23:18:49 +00001606 EXPECT_TRUE(channel_->SetSend(true));
1607 EXPECT_TRUE(vie_.GetSend(channel0));
1608 EXPECT_TRUE(vie_.GetSend(channel1));
1609
wu@webrtc.org24301a62013-12-13 19:17:43 +00001610 EXPECT_TRUE(capturer.CaptureFrame());
1611 EXPECT_EQ(1, vie_.GetIncomingFrameNum(channel0));
1612 EXPECT_EQ(1, vie_.GetIncomingFrameNum(channel1));
1613
1614 EXPECT_TRUE(channel_->RemoveSendStream(kSsrcs2[0]));
1615 EXPECT_TRUE(capturer.CaptureFrame());
1616 // channel0 is the default channel, so it won't be deleted.
1617 // But it should be disconnected from the capturer.
1618 EXPECT_EQ(1, vie_.GetIncomingFrameNum(channel0));
1619 EXPECT_EQ(2, vie_.GetIncomingFrameNum(channel1));
1620
1621 EXPECT_TRUE(channel_->RemoveSendStream(kSsrcs2[1]));
1622 EXPECT_TRUE(capturer.CaptureFrame());
1623 EXPECT_EQ(1, vie_.GetIncomingFrameNum(channel0));
1624 // channel1 has already been deleted.
1625 EXPECT_EQ(-1, vie_.GetIncomingFrameNum(channel1));
1626}
1627
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001628
buildbot@webrtc.orga18b4c92014-05-06 17:48:14 +00001629TEST_F(WebRtcVideoEngineTestFake, SendReceiveBitratesStats) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001630 EXPECT_TRUE(SetupEngine());
1631 cricket::VideoOptions options;
1632 options.conference_mode.Set(true);
1633 EXPECT_TRUE(channel_->SetOptions(options));
1634 EXPECT_TRUE(channel_->AddSendStream(
1635 cricket::StreamParams::CreateLegacy(1)));
buildbot@webrtc.orga18b4c92014-05-06 17:48:14 +00001636 int first_send_channel = vie_.GetLastChannel();
1637 EXPECT_TRUE(channel_->AddSendStream(
1638 cricket::StreamParams::CreateLegacy(2)));
1639 int second_send_channel = vie_.GetLastChannel();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001640 cricket::VideoCodec codec(kVP8Codec720p);
1641 std::vector<cricket::VideoCodec> codec_list;
1642 codec_list.push_back(codec);
1643 EXPECT_TRUE(channel_->SetSendCodecs(codec_list));
1644
1645 EXPECT_TRUE(channel_->AddRecvStream(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001646 cricket::StreamParams::CreateLegacy(3)));
buildbot@webrtc.orga18b4c92014-05-06 17:48:14 +00001647 int first_receive_channel = vie_.GetLastChannel();
1648 EXPECT_NE(first_send_channel, first_receive_channel);
1649 EXPECT_TRUE(channel_->AddRecvStream(
1650 cricket::StreamParams::CreateLegacy(4)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001651 int second_receive_channel = vie_.GetLastChannel();
1652 EXPECT_NE(first_receive_channel, second_receive_channel);
1653
1654 cricket::VideoMediaInfo info;
wu@webrtc.orgb9a088b2014-02-13 23:18:49 +00001655 EXPECT_TRUE(channel_->GetStats(cricket::StatsOptions(), &info));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001656 ASSERT_EQ(1U, info.bw_estimations.size());
1657 ASSERT_EQ(0, info.bw_estimations[0].actual_enc_bitrate);
1658 ASSERT_EQ(0, info.bw_estimations[0].transmit_bitrate);
1659 ASSERT_EQ(0, info.bw_estimations[0].retransmit_bitrate);
1660 ASSERT_EQ(0, info.bw_estimations[0].available_send_bandwidth);
1661 ASSERT_EQ(0, info.bw_estimations[0].available_recv_bandwidth);
1662 ASSERT_EQ(0, info.bw_estimations[0].target_enc_bitrate);
1663
1664 // Start sending and receiving on one of the channels and verify bitrates.
buildbot@webrtc.orga18b4c92014-05-06 17:48:14 +00001665 EXPECT_EQ(0, vie_.StartSend(first_send_channel));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001666 int send_video_bitrate = 800;
1667 int send_fec_bitrate = 100;
1668 int send_nack_bitrate = 20;
1669 int send_total_bitrate = send_video_bitrate + send_fec_bitrate +
1670 send_nack_bitrate;
buildbot@webrtc.orga18b4c92014-05-06 17:48:14 +00001671 int send_bandwidth = 1900;
1672 vie_.SetSendBitrates(first_send_channel, send_video_bitrate, send_fec_bitrate,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001673 send_nack_bitrate);
buildbot@webrtc.orga18b4c92014-05-06 17:48:14 +00001674 vie_.SetSendBandwidthEstimate(first_send_channel, send_bandwidth);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001675
1676 EXPECT_EQ(0, vie_.StartReceive(first_receive_channel));
buildbot@webrtc.orga18b4c92014-05-06 17:48:14 +00001677 int receive_bandwidth = 600;
1678 vie_.SetReceiveBandwidthEstimate(first_receive_channel, receive_bandwidth);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001679
1680 info.Clear();
wu@webrtc.orgb9a088b2014-02-13 23:18:49 +00001681 EXPECT_TRUE(channel_->GetStats(cricket::StatsOptions(), &info));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001682 ASSERT_EQ(1U, info.bw_estimations.size());
1683 ASSERT_EQ(send_video_bitrate, info.bw_estimations[0].actual_enc_bitrate);
1684 ASSERT_EQ(send_total_bitrate, info.bw_estimations[0].transmit_bitrate);
1685 ASSERT_EQ(send_nack_bitrate, info.bw_estimations[0].retransmit_bitrate);
1686 ASSERT_EQ(send_bandwidth, info.bw_estimations[0].available_send_bandwidth);
buildbot@webrtc.orga18b4c92014-05-06 17:48:14 +00001687 ASSERT_EQ(receive_bandwidth, info.bw_estimations[0].available_recv_bandwidth);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001688 ASSERT_EQ(send_video_bitrate, info.bw_estimations[0].target_enc_bitrate);
1689
1690 // Start receiving on the second channel and verify received rate.
buildbot@webrtc.orga18b4c92014-05-06 17:48:14 +00001691 EXPECT_EQ(0, vie_.StartSend(second_send_channel));
1692 vie_.SetSendBitrates(second_send_channel,
1693 send_video_bitrate,
1694 send_fec_bitrate,
1695 send_nack_bitrate);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001696 EXPECT_EQ(0, vie_.StartReceive(second_receive_channel));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001697
1698 info.Clear();
wu@webrtc.orgb9a088b2014-02-13 23:18:49 +00001699 EXPECT_TRUE(channel_->GetStats(cricket::StatsOptions(), &info));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001700 ASSERT_EQ(1U, info.bw_estimations.size());
buildbot@webrtc.orga18b4c92014-05-06 17:48:14 +00001701 ASSERT_EQ(2 * send_video_bitrate, info.bw_estimations[0].actual_enc_bitrate);
1702 ASSERT_EQ(2 * send_total_bitrate, info.bw_estimations[0].transmit_bitrate);
1703 ASSERT_EQ(2 * send_nack_bitrate, info.bw_estimations[0].retransmit_bitrate);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001704 ASSERT_EQ(send_bandwidth, info.bw_estimations[0].available_send_bandwidth);
buildbot@webrtc.orga18b4c92014-05-06 17:48:14 +00001705 ASSERT_EQ(receive_bandwidth, info.bw_estimations[0].available_recv_bandwidth);
1706 ASSERT_EQ(2 * send_video_bitrate, info.bw_estimations[0].target_enc_bitrate);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001707}
1708
1709TEST_F(WebRtcVideoEngineTestFake, TestSetAdaptInputToCpuUsage) {
1710 EXPECT_TRUE(SetupEngine());
1711 cricket::VideoOptions options_in, options_out;
1712 bool cpu_adapt = false;
1713 channel_->SetOptions(options_in);
1714 EXPECT_TRUE(channel_->GetOptions(&options_out));
1715 EXPECT_FALSE(options_out.adapt_input_to_cpu_usage.Get(&cpu_adapt));
1716 // Set adapt input CPU usage option.
1717 options_in.adapt_input_to_cpu_usage.Set(true);
1718 EXPECT_TRUE(channel_->SetOptions(options_in));
1719 EXPECT_TRUE(channel_->GetOptions(&options_out));
1720 EXPECT_TRUE(options_out.adapt_input_to_cpu_usage.Get(&cpu_adapt));
1721 EXPECT_TRUE(cpu_adapt);
1722}
1723
1724TEST_F(WebRtcVideoEngineTestFake, TestSetCpuThreshold) {
1725 EXPECT_TRUE(SetupEngine());
1726 float low, high;
1727 cricket::VideoOptions options_in, options_out;
1728 // Verify that initial values are set.
1729 EXPECT_TRUE(channel_->GetOptions(&options_out));
1730 EXPECT_TRUE(options_out.system_low_adaptation_threshhold.Get(&low));
1731 EXPECT_EQ(low, 0.65f);
1732 EXPECT_TRUE(options_out.system_high_adaptation_threshhold.Get(&high));
1733 EXPECT_EQ(high, 0.85f);
1734 // Set new CPU threshold values.
1735 options_in.system_low_adaptation_threshhold.Set(0.45f);
1736 options_in.system_high_adaptation_threshhold.Set(0.95f);
1737 EXPECT_TRUE(channel_->SetOptions(options_in));
1738 EXPECT_TRUE(channel_->GetOptions(&options_out));
1739 EXPECT_TRUE(options_out.system_low_adaptation_threshhold.Get(&low));
1740 EXPECT_EQ(low, 0.45f);
1741 EXPECT_TRUE(options_out.system_high_adaptation_threshhold.Get(&high));
1742 EXPECT_EQ(high, 0.95f);
1743}
1744
1745TEST_F(WebRtcVideoEngineTestFake, TestSetInvalidCpuThreshold) {
1746 EXPECT_TRUE(SetupEngine());
1747 float low, high;
1748 cricket::VideoOptions options_in, options_out;
1749 // Valid range is [0, 1].
1750 options_in.system_low_adaptation_threshhold.Set(-1.5f);
1751 options_in.system_high_adaptation_threshhold.Set(1.5f);
1752 EXPECT_TRUE(channel_->SetOptions(options_in));
1753 EXPECT_TRUE(channel_->GetOptions(&options_out));
1754 EXPECT_TRUE(options_out.system_low_adaptation_threshhold.Get(&low));
1755 EXPECT_EQ(low, 0.0f);
1756 EXPECT_TRUE(options_out.system_high_adaptation_threshhold.Get(&high));
1757 EXPECT_EQ(high, 1.0f);
1758}
1759
1760
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +00001761TEST_F(WebRtcVideoEngineTestFake, ResetCodecOnScreencast) {
1762 EXPECT_TRUE(SetupEngine());
1763 cricket::VideoOptions options;
1764 options.video_noise_reduction.Set(true);
1765 EXPECT_TRUE(channel_->SetOptions(options));
1766
1767 // Set send codec.
1768 cricket::VideoCodec codec(kVP8Codec);
1769 std::vector<cricket::VideoCodec> codec_list;
1770 codec_list.push_back(codec);
1771 EXPECT_TRUE(channel_->AddSendStream(
1772 cricket::StreamParams::CreateLegacy(123)));
1773 EXPECT_TRUE(channel_->SetSendCodecs(codec_list));
1774 EXPECT_TRUE(channel_->SetSend(true));
wu@webrtc.org05e7b442014-04-01 17:44:24 +00001775 EXPECT_EQ(1, vie_.GetNumSetSendCodecs());
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +00001776
1777 webrtc::VideoCodec gcodec;
1778 memset(&gcodec, 0, sizeof(gcodec));
1779 int channel_num = vie_.GetLastChannel();
1780 EXPECT_EQ(0, vie_.GetSendCodec(channel_num, gcodec));
1781 EXPECT_TRUE(gcodec.codecSpecific.VP8.denoisingOn);
1782
1783 // Send a screencast frame with the same size.
1784 // Verify that denoising is turned off.
1785 SendI420ScreencastFrame(kVP8Codec.width, kVP8Codec.height);
wu@webrtc.org05e7b442014-04-01 17:44:24 +00001786 EXPECT_EQ(2, vie_.GetNumSetSendCodecs());
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +00001787 EXPECT_EQ(0, vie_.GetSendCodec(channel_num, gcodec));
1788 EXPECT_FALSE(gcodec.codecSpecific.VP8.denoisingOn);
1789}
1790
1791
1792TEST_F(WebRtcVideoEngineTestFake, DontRegisterDecoderIfFactoryIsNotGiven) {
1793 engine_.SetExternalDecoderFactory(NULL);
1794 EXPECT_TRUE(SetupEngine());
1795 int channel_num = vie_.GetLastChannel();
1796
1797 std::vector<cricket::VideoCodec> codecs;
1798 codecs.push_back(kVP8Codec);
1799 EXPECT_TRUE(channel_->SetRecvCodecs(codecs));
1800
1801 EXPECT_EQ(0, vie_.GetNumExternalDecoderRegistered(channel_num));
1802}
1803
1804TEST_F(WebRtcVideoEngineTestFake, RegisterDecoderIfFactoryIsGiven) {
1805 decoder_factory_.AddSupportedVideoCodecType(webrtc::kVideoCodecVP8);
1806 engine_.SetExternalDecoderFactory(&decoder_factory_);
1807 EXPECT_TRUE(SetupEngine());
1808 int channel_num = vie_.GetLastChannel();
1809
1810 std::vector<cricket::VideoCodec> codecs;
1811 codecs.push_back(kVP8Codec);
1812 EXPECT_TRUE(channel_->SetRecvCodecs(codecs));
1813
1814 EXPECT_TRUE(vie_.ExternalDecoderRegistered(channel_num, 100));
1815 EXPECT_EQ(1, vie_.GetNumExternalDecoderRegistered(channel_num));
1816}
1817
1818TEST_F(WebRtcVideoEngineTestFake, DontRegisterDecoderMultipleTimes) {
1819 decoder_factory_.AddSupportedVideoCodecType(webrtc::kVideoCodecVP8);
1820 engine_.SetExternalDecoderFactory(&decoder_factory_);
1821 EXPECT_TRUE(SetupEngine());
1822 int channel_num = vie_.GetLastChannel();
1823
1824 std::vector<cricket::VideoCodec> codecs;
1825 codecs.push_back(kVP8Codec);
1826 EXPECT_TRUE(channel_->SetRecvCodecs(codecs));
1827
1828 EXPECT_TRUE(vie_.ExternalDecoderRegistered(channel_num, 100));
1829 EXPECT_EQ(1, vie_.GetNumExternalDecoderRegistered(channel_num));
1830 EXPECT_EQ(1, decoder_factory_.GetNumCreatedDecoders());
1831
1832 EXPECT_TRUE(channel_->SetRecvCodecs(codecs));
1833 EXPECT_EQ(1, vie_.GetNumExternalDecoderRegistered(channel_num));
1834 EXPECT_EQ(1, decoder_factory_.GetNumCreatedDecoders());
1835}
1836
1837TEST_F(WebRtcVideoEngineTestFake, DontRegisterDecoderForNonVP8) {
1838 decoder_factory_.AddSupportedVideoCodecType(webrtc::kVideoCodecVP8);
1839 engine_.SetExternalDecoderFactory(&decoder_factory_);
1840 EXPECT_TRUE(SetupEngine());
1841 int channel_num = vie_.GetLastChannel();
1842
1843 std::vector<cricket::VideoCodec> codecs;
1844 codecs.push_back(kRedCodec);
1845 EXPECT_TRUE(channel_->SetRecvCodecs(codecs));
1846
1847 EXPECT_EQ(0, vie_.GetNumExternalDecoderRegistered(channel_num));
1848}
1849
1850TEST_F(WebRtcVideoEngineTestFake, DontRegisterEncoderIfFactoryIsNotGiven) {
1851 engine_.SetExternalEncoderFactory(NULL);
1852 EXPECT_TRUE(SetupEngine());
1853 int channel_num = vie_.GetLastChannel();
1854
1855 std::vector<cricket::VideoCodec> codecs;
1856 codecs.push_back(kVP8Codec);
1857 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1858
1859 EXPECT_EQ(0, vie_.GetNumExternalEncoderRegistered(channel_num));
1860}
1861
1862TEST_F(WebRtcVideoEngineTestFake, RegisterEncoderIfFactoryIsGiven) {
1863 encoder_factory_.AddSupportedVideoCodecType(webrtc::kVideoCodecVP8, "VP8");
1864 engine_.SetExternalEncoderFactory(&encoder_factory_);
1865 EXPECT_TRUE(SetupEngine());
1866 int channel_num = vie_.GetLastChannel();
1867
1868 std::vector<cricket::VideoCodec> codecs;
1869 codecs.push_back(kVP8Codec);
1870 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1871
1872 EXPECT_TRUE(channel_->AddSendStream(
1873 cricket::StreamParams::CreateLegacy(kSsrc)));
1874
1875 EXPECT_TRUE(vie_.ExternalEncoderRegistered(channel_num, 100));
1876 EXPECT_EQ(1, vie_.GetNumExternalEncoderRegistered(channel_num));
1877
1878 // Remove stream previously added to free the external encoder instance.
1879 EXPECT_TRUE(channel_->RemoveSendStream(kSsrc));
1880}
1881
1882TEST_F(WebRtcVideoEngineTestFake, DontRegisterEncoderMultipleTimes) {
1883 encoder_factory_.AddSupportedVideoCodecType(webrtc::kVideoCodecVP8, "VP8");
1884 engine_.SetExternalEncoderFactory(&encoder_factory_);
1885 EXPECT_TRUE(SetupEngine());
1886 int channel_num = vie_.GetLastChannel();
1887
1888 std::vector<cricket::VideoCodec> codecs;
1889 codecs.push_back(kVP8Codec);
1890 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1891
1892 EXPECT_TRUE(channel_->AddSendStream(
1893 cricket::StreamParams::CreateLegacy(kSsrc)));
1894
1895 EXPECT_TRUE(vie_.ExternalEncoderRegistered(channel_num, 100));
1896 EXPECT_EQ(1, vie_.GetNumExternalEncoderRegistered(channel_num));
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +00001897
1898 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1899 EXPECT_EQ(1, vie_.GetNumExternalEncoderRegistered(channel_num));
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +00001900
1901 // Remove stream previously added to free the external encoder instance.
1902 EXPECT_TRUE(channel_->RemoveSendStream(kSsrc));
1903}
1904
1905TEST_F(WebRtcVideoEngineTestFake, RegisterEncoderWithMultipleSendStreams) {
1906 encoder_factory_.AddSupportedVideoCodecType(webrtc::kVideoCodecVP8, "VP8");
1907 engine_.SetExternalEncoderFactory(&encoder_factory_);
1908 EXPECT_TRUE(SetupEngine());
1909
1910 std::vector<cricket::VideoCodec> codecs;
1911 codecs.push_back(kVP8Codec);
1912 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1913 EXPECT_EQ(1, vie_.GetTotalNumExternalEncoderRegistered());
1914
1915 // When we add the first stream (1234), it reuses the default send channel,
1916 // so it doesn't increase the registration count of external encoders.
1917 EXPECT_TRUE(channel_->AddSendStream(
1918 cricket::StreamParams::CreateLegacy(1234)));
1919 EXPECT_EQ(1, vie_.GetTotalNumExternalEncoderRegistered());
1920
1921 // When we add the second stream (2345), it creates a new channel and
1922 // increments the registration count.
1923 EXPECT_TRUE(channel_->AddSendStream(
1924 cricket::StreamParams::CreateLegacy(2345)));
1925 EXPECT_EQ(2, vie_.GetTotalNumExternalEncoderRegistered());
1926
1927 // At this moment the total registration count is two, but only one encoder
1928 // is registered per channel.
1929 int channel_num = vie_.GetLastChannel();
1930 EXPECT_EQ(1, vie_.GetNumExternalEncoderRegistered(channel_num));
1931
1932 // Removing send streams decrements the registration count.
1933 EXPECT_TRUE(channel_->RemoveSendStream(1234));
1934 EXPECT_EQ(1, vie_.GetTotalNumExternalEncoderRegistered());
1935
1936 // When we remove the last send stream, it also destroys the last send
1937 // channel and causes the registration count to drop to zero. It is a little
1938 // weird, but not a bug.
1939 EXPECT_TRUE(channel_->RemoveSendStream(2345));
1940 EXPECT_EQ(0, vie_.GetTotalNumExternalEncoderRegistered());
1941}
1942
1943TEST_F(WebRtcVideoEngineTestFake, DontRegisterEncoderForNonVP8) {
1944 encoder_factory_.AddSupportedVideoCodecType(webrtc::kVideoCodecGeneric,
1945 "GENERIC");
1946 engine_.SetExternalEncoderFactory(&encoder_factory_);
1947 EXPECT_TRUE(SetupEngine());
1948 int channel_num = vie_.GetLastChannel();
1949
1950 // Note: unlike the SetRecvCodecs, we must set a valid video codec for
1951 // channel_->SetSendCodecs() to succeed.
1952 std::vector<cricket::VideoCodec> codecs;
1953 codecs.push_back(kVP8Codec);
1954 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1955
1956 EXPECT_EQ(0, vie_.GetNumExternalEncoderRegistered(channel_num));
1957}
1958
1959// Test that NACK, PLI and REMB are enabled for external codec.
1960TEST_F(WebRtcVideoEngineTestFake, ExternalCodecFeedbackParams) {
1961 encoder_factory_.AddSupportedVideoCodecType(webrtc::kVideoCodecGeneric,
1962 "GENERIC");
1963 engine_.SetExternalEncoderFactory(&encoder_factory_);
1964 encoder_factory_.NotifyCodecsAvailable();
1965 EXPECT_TRUE(SetupEngine());
1966
1967 std::vector<cricket::VideoCodec> codecs(engine_.codecs());
1968 // The external codec will appear at last.
1969 size_t pos = codecs.size() - 1;
1970 EXPECT_EQ("GENERIC", codecs[pos].name);
1971 VerifyCodecFeedbackParams(codecs[pos]);
1972}
1973
1974// Test external codec with be added to the end of the supported codec list.
1975TEST_F(WebRtcVideoEngineTestFake, ExternalCodecAddedToTheEnd) {
1976 EXPECT_TRUE(SetupEngine());
1977
1978 std::vector<cricket::VideoCodec> codecs(engine_.codecs());
1979 EXPECT_EQ("VP8", codecs[0].name);
1980
1981 encoder_factory_.AddSupportedVideoCodecType(webrtc::kVideoCodecGeneric,
1982 "GENERIC");
1983 engine_.SetExternalEncoderFactory(&encoder_factory_);
1984 encoder_factory_.NotifyCodecsAvailable();
1985
1986 codecs = engine_.codecs();
1987 cricket::VideoCodec internal_codec = codecs[0];
1988 cricket::VideoCodec external_codec = codecs[codecs.size() - 1];
1989 // The external codec will appear at last.
1990 EXPECT_EQ("GENERIC", external_codec.name);
1991 // The internal codec is preferred.
1992 EXPECT_GE(internal_codec.preference, external_codec.preference);
1993}
1994
1995// Test that external codec with be ignored if it has the same name as one of
1996// the internal codecs.
1997TEST_F(WebRtcVideoEngineTestFake, ExternalCodecIgnored) {
1998 EXPECT_TRUE(SetupEngine());
1999
2000 std::vector<cricket::VideoCodec> internal_codecs(engine_.codecs());
2001 EXPECT_EQ("VP8", internal_codecs[0].name);
2002
2003 encoder_factory_.AddSupportedVideoCodecType(webrtc::kVideoCodecVP8, "VP8");
2004 engine_.SetExternalEncoderFactory(&encoder_factory_);
2005 encoder_factory_.NotifyCodecsAvailable();
2006
2007 std::vector<cricket::VideoCodec> codecs = engine_.codecs();
2008 EXPECT_EQ("VP8", codecs[0].name);
2009 EXPECT_EQ(internal_codecs[0].height, codecs[0].height);
2010 EXPECT_EQ(internal_codecs[0].width, codecs[0].width);
2011 // Verify the last codec is not the external codec.
2012 EXPECT_NE("VP8", codecs[codecs.size() - 1].name);
2013}
2014
2015TEST_F(WebRtcVideoEngineTestFake, UpdateEncoderCodecsAfterSetFactory) {
2016 engine_.SetExternalEncoderFactory(&encoder_factory_);
2017 EXPECT_TRUE(SetupEngine());
2018 int channel_num = vie_.GetLastChannel();
2019
2020 encoder_factory_.AddSupportedVideoCodecType(webrtc::kVideoCodecVP8, "VP8");
2021 encoder_factory_.NotifyCodecsAvailable();
2022 std::vector<cricket::VideoCodec> codecs;
2023 codecs.push_back(kVP8Codec);
2024 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
2025
2026 EXPECT_TRUE(channel_->AddSendStream(
2027 cricket::StreamParams::CreateLegacy(kSsrc)));
2028
2029 EXPECT_TRUE(vie_.ExternalEncoderRegistered(channel_num, 100));
2030 EXPECT_EQ(1, vie_.GetNumExternalEncoderRegistered(channel_num));
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +00002031
2032 // Remove stream previously added to free the external encoder instance.
2033 EXPECT_TRUE(channel_->RemoveSendStream(kSsrc));
2034}
2035
2036// Tests that OnReadyToSend will be propagated into ViE.
2037TEST_F(WebRtcVideoEngineTestFake, OnReadyToSend) {
2038 EXPECT_TRUE(SetupEngine());
2039 int channel_num = vie_.GetLastChannel();
2040 EXPECT_TRUE(vie_.GetIsTransmitting(channel_num));
2041
2042 channel_->OnReadyToSend(false);
2043 EXPECT_FALSE(vie_.GetIsTransmitting(channel_num));
2044
2045 channel_->OnReadyToSend(true);
2046 EXPECT_TRUE(vie_.GetIsTransmitting(channel_num));
2047}
2048
2049#if 0
2050TEST_F(WebRtcVideoEngineTestFake, CaptureFrameTimestampToNtpTimestamp) {
2051 EXPECT_TRUE(SetupEngine());
2052 int capture_id = vie_.GetCaptureId(vie_.GetLastChannel());
2053
2054 // Set send codec.
2055 cricket::VideoCodec codec(kVP8Codec);
2056 std::vector<cricket::VideoCodec> codec_list;
2057 codec_list.push_back(codec);
2058 EXPECT_TRUE(channel_->AddSendStream(
2059 cricket::StreamParams::CreateLegacy(123)));
2060 EXPECT_TRUE(channel_->SetSendCodecs(codec_list));
2061 EXPECT_TRUE(channel_->SetSend(true));
2062
2063 int64 timestamp = time(NULL) * talk_base::kNumNanosecsPerSec;
2064 SendI420ScreencastFrameWithTimestamp(
2065 kVP8Codec.width, kVP8Codec.height, timestamp);
2066 EXPECT_EQ(talk_base::UnixTimestampNanosecsToNtpMillisecs(timestamp),
2067 vie_.GetCaptureLastTimestamp(capture_id));
2068
2069 SendI420ScreencastFrameWithTimestamp(kVP8Codec.width, kVP8Codec.height, 0);
2070 EXPECT_EQ(0, vie_.GetCaptureLastTimestamp(capture_id));
2071}
2072#endif
2073
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002074/////////////////////////
2075// Tests with real ViE //
2076/////////////////////////
2077
2078// Tests that we can find codecs by name or id.
2079TEST_F(WebRtcVideoEngineTest, FindCodec) {
2080 // We should not need to init engine in order to get codecs.
2081 const std::vector<cricket::VideoCodec>& c = engine_.codecs();
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +00002082 EXPECT_EQ(4U, c.size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002083
2084 cricket::VideoCodec vp8(104, "VP8", 320, 200, 30, 0);
2085 EXPECT_TRUE(engine_.FindCodec(vp8));
2086
2087 cricket::VideoCodec vp8_ci(104, "vp8", 320, 200, 30, 0);
2088 EXPECT_TRUE(engine_.FindCodec(vp8));
2089
2090 cricket::VideoCodec vp8_diff_fr_diff_pref(104, "VP8", 320, 200, 50, 50);
2091 EXPECT_TRUE(engine_.FindCodec(vp8_diff_fr_diff_pref));
2092
2093 cricket::VideoCodec vp8_diff_id(95, "VP8", 320, 200, 30, 0);
2094 EXPECT_FALSE(engine_.FindCodec(vp8_diff_id));
2095 vp8_diff_id.id = 97;
2096 EXPECT_TRUE(engine_.FindCodec(vp8_diff_id));
2097
2098 cricket::VideoCodec vp8_diff_res(104, "VP8", 320, 111, 30, 0);
2099 EXPECT_FALSE(engine_.FindCodec(vp8_diff_res));
2100
2101 // PeerConnection doesn't negotiate the resolution at this point.
2102 // Test that FindCodec can handle the case when width/height is 0.
2103 cricket::VideoCodec vp8_zero_res(104, "VP8", 0, 0, 30, 0);
2104 EXPECT_TRUE(engine_.FindCodec(vp8_zero_res));
2105
2106 cricket::VideoCodec red(101, "RED", 0, 0, 30, 0);
2107 EXPECT_TRUE(engine_.FindCodec(red));
2108
2109 cricket::VideoCodec red_ci(101, "red", 0, 0, 30, 0);
2110 EXPECT_TRUE(engine_.FindCodec(red));
2111
2112 cricket::VideoCodec fec(102, "ULPFEC", 0, 0, 30, 0);
2113 EXPECT_TRUE(engine_.FindCodec(fec));
2114
2115 cricket::VideoCodec fec_ci(102, "ulpfec", 0, 0, 30, 0);
2116 EXPECT_TRUE(engine_.FindCodec(fec));
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +00002117
2118 cricket::VideoCodec rtx(96, "rtx", 0, 0, 30, 0);
buildbot@webrtc.orgdd4742a2014-05-07 14:50:35 +00002119 rtx.SetParam("apt", kVP8Codec.id);
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +00002120 EXPECT_TRUE(engine_.FindCodec(rtx));
2121}
2122
2123TEST_F(WebRtcVideoEngineTest, RtxCodecHasAptSet) {
2124 std::vector<cricket::VideoCodec>::const_iterator it;
2125 bool apt_checked = false;
2126 for (it = engine_.codecs().begin(); it != engine_.codecs().end(); ++it) {
2127 if (_stricmp(cricket::kRtxCodecName, it->name.c_str()) && it->id != 96) {
2128 continue;
2129 }
2130 int apt;
2131 EXPECT_TRUE(it->GetParam("apt", &apt));
2132 EXPECT_EQ(100, apt);
2133 apt_checked = true;
2134 }
2135 EXPECT_TRUE(apt_checked);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002136}
2137
2138TEST_F(WebRtcVideoEngineTest, StartupShutdown) {
2139 EXPECT_TRUE(engine_.Init(talk_base::Thread::Current()));
2140 engine_.Terminate();
2141}
2142
2143TEST_PRE_VIDEOENGINE_INIT(WebRtcVideoEngineTest, ConstrainNewCodec)
2144TEST_POST_VIDEOENGINE_INIT(WebRtcVideoEngineTest, ConstrainNewCodec)
2145
2146TEST_PRE_VIDEOENGINE_INIT(WebRtcVideoEngineTest, ConstrainRunningCodec)
2147TEST_POST_VIDEOENGINE_INIT(WebRtcVideoEngineTest, ConstrainRunningCodec)
2148
2149// TODO(juberti): Figure out why ViE is munging the COM refcount.
2150#ifdef WIN32
2151TEST_F(WebRtcVideoEngineTest, DISABLED_CheckCoInitialize) {
2152 Base::CheckCoInitialize();
2153}
2154#endif
2155
2156TEST_F(WebRtcVideoEngineTest, CreateChannel) {
2157 EXPECT_TRUE(engine_.Init(talk_base::Thread::Current()));
2158 cricket::VideoMediaChannel* channel = engine_.CreateChannel(NULL);
2159 EXPECT_TRUE(channel != NULL);
2160 delete channel;
2161}
2162
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002163TEST_F(WebRtcVideoMediaChannelTest, SetRecvCodecs) {
2164 std::vector<cricket::VideoCodec> codecs;
2165 codecs.push_back(kVP8Codec);
2166 EXPECT_TRUE(channel_->SetRecvCodecs(codecs));
2167}
2168TEST_F(WebRtcVideoMediaChannelTest, SetRecvCodecsWrongPayloadType) {
2169 std::vector<cricket::VideoCodec> codecs;
2170 codecs.push_back(kVP8Codec);
2171 codecs[0].id = 99;
2172 EXPECT_TRUE(channel_->SetRecvCodecs(codecs));
2173}
2174TEST_F(WebRtcVideoMediaChannelTest, SetRecvCodecsUnsupportedCodec) {
2175 std::vector<cricket::VideoCodec> codecs;
2176 codecs.push_back(kVP8Codec);
2177 codecs.push_back(cricket::VideoCodec(101, "VP1", 640, 400, 30, 0));
2178 EXPECT_FALSE(channel_->SetRecvCodecs(codecs));
2179}
2180
mallinath@webrtc.org92fdfeb2014-02-17 18:49:41 +00002181TEST_F(WebRtcVideoMediaChannelTest, GetRtpSendTimeExtension) {
2182 // Enable RTP timestamp extension.
2183 const int id = 12;
2184 std::vector<cricket::RtpHeaderExtension> extensions;
2185 extensions.push_back(cricket::RtpHeaderExtension(
2186 "http://www.webrtc.org/experiments/rtp-hdrext/abs-send-time", id));
2187
2188 // Verify the send extension id.
2189 EXPECT_TRUE(channel_->SetSendRtpHeaderExtensions(extensions));
2190 EXPECT_EQ(id, channel_->GetRtpSendTimeExtnId());
2191}
2192
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002193TEST_F(WebRtcVideoMediaChannelTest, SetSend) {
2194 Base::SetSend();
2195}
2196TEST_F(WebRtcVideoMediaChannelTest, SetSendWithoutCodecs) {
2197 Base::SetSendWithoutCodecs();
2198}
2199TEST_F(WebRtcVideoMediaChannelTest, SetSendSetsTransportBufferSizes) {
2200 Base::SetSendSetsTransportBufferSizes();
2201}
2202
2203TEST_F(WebRtcVideoMediaChannelTest, SendAndReceiveVp8Vga) {
2204 SendAndReceive(cricket::VideoCodec(100, "VP8", 640, 400, 30, 0));
2205}
2206TEST_F(WebRtcVideoMediaChannelTest, SendAndReceiveVp8Qvga) {
2207 SendAndReceive(cricket::VideoCodec(100, "VP8", 320, 200, 30, 0));
2208}
2209TEST_F(WebRtcVideoMediaChannelTest, SendAndReceiveH264SvcQqvga) {
2210 SendAndReceive(cricket::VideoCodec(100, "VP8", 160, 100, 30, 0));
2211}
2212TEST_F(WebRtcVideoMediaChannelTest, SendManyResizeOnce) {
2213 SendManyResizeOnce();
2214}
2215
buildbot@webrtc.orgce4201d2014-05-21 16:22:51 +00002216TEST_F(WebRtcVideoMediaChannelTest, DISABLED_SendVp8HdAndReceiveAdaptedVp8Vga) {
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00002217 EXPECT_TRUE(channel_->SetCapturer(kSsrc, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002218 channel_->UpdateAspectRatio(1280, 720);
2219 video_capturer_.reset(new cricket::FakeVideoCapturer);
2220 const std::vector<cricket::VideoFormat>* formats =
2221 video_capturer_->GetSupportedFormats();
2222 cricket::VideoFormat capture_format_hd = (*formats)[0];
2223 EXPECT_EQ(cricket::CS_RUNNING, video_capturer_->Start(capture_format_hd));
2224 EXPECT_TRUE(channel_->SetCapturer(kSsrc, video_capturer_.get()));
2225
2226 // Capture format HD -> adapt (OnOutputFormatRequest VGA) -> VGA.
2227 cricket::VideoCodec codec(100, "VP8", 1280, 720, 30, 0);
2228 EXPECT_TRUE(SetOneCodec(codec));
2229 codec.width /= 2;
2230 codec.height /= 2;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002231 EXPECT_TRUE(SetSend(true));
2232 EXPECT_TRUE(channel_->SetRender(true));
2233 EXPECT_EQ(0, renderer_.num_rendered_frames());
2234 EXPECT_TRUE(SendFrame());
2235 EXPECT_FRAME_WAIT(1, codec.width, codec.height, kTimeout);
2236}
2237
2238// TODO(juberti): Fix this test to tolerate missing stats.
2239TEST_F(WebRtcVideoMediaChannelTest, DISABLED_GetStats) {
2240 Base::GetStats();
2241}
2242
2243// TODO(juberti): Fix this test to tolerate missing stats.
2244TEST_F(WebRtcVideoMediaChannelTest, DISABLED_GetStatsMultipleRecvStreams) {
2245 Base::GetStatsMultipleRecvStreams();
2246}
2247
2248TEST_F(WebRtcVideoMediaChannelTest, GetStatsMultipleSendStreams) {
2249 Base::GetStatsMultipleSendStreams();
2250}
2251
2252TEST_F(WebRtcVideoMediaChannelTest, SetSendBandwidth) {
2253 Base::SetSendBandwidth();
2254}
2255TEST_F(WebRtcVideoMediaChannelTest, SetSendSsrc) {
2256 Base::SetSendSsrc();
2257}
2258TEST_F(WebRtcVideoMediaChannelTest, SetSendSsrcAfterSetCodecs) {
2259 Base::SetSendSsrcAfterSetCodecs();
2260}
2261
2262TEST_F(WebRtcVideoMediaChannelTest, SetRenderer) {
2263 Base::SetRenderer();
2264}
2265
2266TEST_F(WebRtcVideoMediaChannelTest, AddRemoveRecvStreams) {
2267 Base::AddRemoveRecvStreams();
2268}
2269
2270TEST_F(WebRtcVideoMediaChannelTest, AddRemoveRecvStreamAndRender) {
2271 Base::AddRemoveRecvStreamAndRender();
2272}
2273
2274TEST_F(WebRtcVideoMediaChannelTest, AddRemoveRecvStreamsNoConference) {
2275 Base::AddRemoveRecvStreamsNoConference();
2276}
2277
2278TEST_F(WebRtcVideoMediaChannelTest, AddRemoveSendStreams) {
2279 Base::AddRemoveSendStreams();
2280}
2281
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002282TEST_F(WebRtcVideoMediaChannelTest, SimulateConference) {
2283 Base::SimulateConference();
2284}
2285
2286TEST_F(WebRtcVideoMediaChannelTest, AddRemoveCapturer) {
2287 Base::AddRemoveCapturer();
2288}
2289
2290TEST_F(WebRtcVideoMediaChannelTest, RemoveCapturerWithoutAdd) {
2291 Base::RemoveCapturerWithoutAdd();
2292}
2293
2294TEST_F(WebRtcVideoMediaChannelTest, AddRemoveCapturerMultipleSources) {
2295 Base::AddRemoveCapturerMultipleSources();
2296}
2297
wu@webrtc.orgde305012013-10-31 15:40:38 +00002298// This test verifies DSCP settings are properly applied on video media channel.
2299TEST_F(WebRtcVideoMediaChannelTest, TestSetDscpOptions) {
2300 talk_base::scoped_ptr<cricket::FakeNetworkInterface> network_interface(
2301 new cricket::FakeNetworkInterface);
2302 channel_->SetInterface(network_interface.get());
2303 cricket::VideoOptions options;
2304 options.dscp.Set(true);
2305 EXPECT_TRUE(channel_->SetOptions(options));
2306 EXPECT_EQ(talk_base::DSCP_AF41, network_interface->dscp());
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +00002307 // Verify previous value is not modified if dscp option is not set.
2308 cricket::VideoOptions options1;
2309 EXPECT_TRUE(channel_->SetOptions(options1));
2310 EXPECT_EQ(talk_base::DSCP_AF41, network_interface->dscp());
wu@webrtc.orgde305012013-10-31 15:40:38 +00002311 options.dscp.Set(false);
2312 EXPECT_TRUE(channel_->SetOptions(options));
2313 EXPECT_EQ(talk_base::DSCP_DEFAULT, network_interface->dscp());
2314 channel_->SetInterface(NULL);
2315}
2316
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002317
2318TEST_F(WebRtcVideoMediaChannelTest, SetOptionsSucceedsWhenSending) {
2319 cricket::VideoOptions options;
2320 options.conference_mode.Set(true);
2321 EXPECT_TRUE(channel_->SetOptions(options));
2322
2323 // Verify SetOptions returns true on a different options.
2324 cricket::VideoOptions options2;
2325 options2.adapt_input_to_cpu_usage.Set(true);
2326 EXPECT_TRUE(channel_->SetOptions(options2));
2327
2328 // Set send codecs on the channel and start sending.
2329 std::vector<cricket::VideoCodec> codecs;
2330 codecs.push_back(kVP8Codec);
2331 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
2332 EXPECT_TRUE(channel_->SetSend(true));
2333
2334 // Verify SetOptions returns true if channel is already sending.
2335 cricket::VideoOptions options3;
2336 options3.conference_mode.Set(true);
2337 EXPECT_TRUE(channel_->SetOptions(options3));
2338}
2339
2340// Tests empty StreamParams is rejected.
2341TEST_F(WebRtcVideoMediaChannelTest, RejectEmptyStreamParams) {
2342 Base::RejectEmptyStreamParams();
2343}
2344
2345
2346TEST_F(WebRtcVideoMediaChannelTest, AdaptResolution16x10) {
2347 Base::AdaptResolution16x10();
2348}
2349
2350TEST_F(WebRtcVideoMediaChannelTest, AdaptResolution4x3) {
2351 Base::AdaptResolution4x3();
2352}
2353
2354TEST_F(WebRtcVideoMediaChannelTest, MuteStream) {
2355 Base::MuteStream();
2356}
2357
2358TEST_F(WebRtcVideoMediaChannelTest, MultipleSendStreams) {
2359 Base::MultipleSendStreams();
2360}
2361
2362// TODO(juberti): Restore this test once we support sending 0 fps.
2363TEST_F(WebRtcVideoMediaChannelTest, DISABLED_AdaptDropAllFrames) {
2364 Base::AdaptDropAllFrames();
2365}
2366// TODO(juberti): Understand why we get decode errors on this test.
2367TEST_F(WebRtcVideoMediaChannelTest, DISABLED_AdaptFramerate) {
2368 Base::AdaptFramerate();
2369}
2370
2371TEST_F(WebRtcVideoMediaChannelTest, SetSendStreamFormat0x0) {
2372 Base::SetSendStreamFormat0x0();
2373}
2374
2375// TODO(zhurunz): Fix the flakey test.
2376TEST_F(WebRtcVideoMediaChannelTest, DISABLED_SetSendStreamFormat) {
2377 Base::SetSendStreamFormat();
2378}
2379
2380TEST_F(WebRtcVideoMediaChannelTest, TwoStreamsSendAndReceive) {
2381 Base::TwoStreamsSendAndReceive(cricket::VideoCodec(100, "VP8", 640, 400, 30,
2382 0));
2383}
2384
2385TEST_F(WebRtcVideoMediaChannelTest, TwoStreamsReUseFirstStream) {
2386 Base::TwoStreamsReUseFirstStream(cricket::VideoCodec(100, "VP8", 640, 400, 30,
2387 0));
2388}
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00002389
buildbot@webrtc.org0b3c6c32014-04-17 10:03:57 +00002390TEST_F(WebRtcVideoMediaChannelTest, DISABLED_TwoStreamsSendAndUnsignalledRecv) {
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00002391 Base::TwoStreamsSendAndUnsignalledRecv(cricket::VideoCodec(100, "VP8", 640,
2392 400, 30, 0));
2393}
2394
henrike@webrtc.org806768a2014-02-27 21:03:09 +00002395TEST_F(WebRtcVideoMediaChannelTest,
henrike@webrtc.org18e59112014-03-14 17:19:38 +00002396 TwoStreamsSendAndFailUnsignalledRecv) {
henrike@webrtc.org806768a2014-02-27 21:03:09 +00002397 webrtc::Trace::set_level_filter(webrtc::kTraceAll);
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00002398 Base::TwoStreamsSendAndFailUnsignalledRecv(
2399 cricket::VideoCodec(100, "VP8", 640, 400, 30, 0));
2400}
2401
2402TEST_F(WebRtcVideoMediaChannelTest,
henrike@webrtc.org18e59112014-03-14 17:19:38 +00002403 TwoStreamsSendAndFailUnsignalledRecvInOneToOne) {
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00002404 Base::TwoStreamsSendAndFailUnsignalledRecvInOneToOne(
2405 cricket::VideoCodec(100, "VP8", 640, 400, 30, 0));
2406}
2407
2408TEST_F(WebRtcVideoMediaChannelTest,
henrike@webrtc.org18e59112014-03-14 17:19:38 +00002409 TwoStreamsAddAndRemoveUnsignalledRecv) {
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00002410 Base::TwoStreamsAddAndRemoveUnsignalledRecv(cricket::VideoCodec(100, "VP8",
2411 640, 400, 30,
2412 0));
2413}