blob: 24eae469449a7c801b4e9bd612e6ca94335e8b5e [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"
39#include "talk/media/base/videoengine_unittest.h"
40#include "talk/media/webrtc/fakewebrtcvideocapturemodule.h"
41#include "talk/media/webrtc/fakewebrtcvideoengine.h"
42#include "talk/media/webrtc/fakewebrtcvoiceengine.h"
43#include "talk/media/webrtc/webrtcvideocapturer.h"
44#include "talk/media/webrtc/webrtcvideoengine.h"
45#include "talk/media/webrtc/webrtcvideoframe.h"
46#include "talk/media/webrtc/webrtcvoiceengine.h"
47#include "talk/session/media/mediasession.h"
48#include "webrtc/system_wrappers/interface/trace.h"
49
50// Tests for the WebRtcVideoEngine/VideoChannel code.
51
52static const cricket::VideoCodec kVP8Codec720p(100, "VP8", 1280, 720, 30, 0);
53static const cricket::VideoCodec kVP8Codec360p(100, "VP8", 640, 360, 30, 0);
54static const cricket::VideoCodec kVP8Codec270p(100, "VP8", 480, 270, 30, 0);
55static const cricket::VideoCodec kVP8Codec180p(100, "VP8", 320, 180, 30, 0);
56
57static const cricket::VideoCodec kVP8Codec(100, "VP8", 640, 400, 30, 0);
58static const cricket::VideoCodec kRedCodec(101, "red", 0, 0, 0, 0);
59static const cricket::VideoCodec kUlpFecCodec(102, "ulpfec", 0, 0, 0, 0);
60static const cricket::VideoCodec* const kVideoCodecs[] = {
61 &kVP8Codec,
62 &kRedCodec,
63 &kUlpFecCodec
64};
65
66static const unsigned int kMinBandwidthKbps = 50;
67static const unsigned int kStartBandwidthKbps = 300;
68static const unsigned int kMaxBandwidthKbps = 2000;
69
70static const unsigned int kNumberOfTemporalLayers = 1;
71
wu@webrtc.org9caf2762013-12-11 18:25:07 +000072static const uint32 kSsrcs1[] = {1};
73static const uint32 kSsrcs2[] = {1, 2};
74static const uint32 kSsrcs3[] = {1, 2, 3};
75static const uint32 kRtxSsrc1[] = {4};
76static const uint32 kRtxSsrcs3[] = {4, 5, 6};
77
henrike@webrtc.org28e20752013-07-10 00:45:36 +000078
79class FakeViEWrapper : public cricket::ViEWrapper {
80 public:
81 explicit FakeViEWrapper(cricket::FakeWebRtcVideoEngine* engine)
82 : cricket::ViEWrapper(engine, // base
83 engine, // codec
84 engine, // capture
85 engine, // network
86 engine, // render
87 engine, // rtp
88 engine, // image
89 engine) { // external decoder
90 }
91};
92
93// Test fixture to test WebRtcVideoEngine with a fake webrtc::VideoEngine.
94// Useful for testing failure paths.
wu@webrtc.orgcadf9042013-08-30 21:24:16 +000095class WebRtcVideoEngineTestFake : public testing::Test,
wu@webrtc.orgd64719d2013-08-01 00:00:07 +000096 public sigslot::has_slots<> {
henrike@webrtc.org28e20752013-07-10 00:45:36 +000097 public:
98 WebRtcVideoEngineTestFake()
99 : vie_(kVideoCodecs, ARRAY_SIZE(kVideoCodecs)),
100 cpu_monitor_(new talk_base::FakeCpuMonitor(
101 talk_base::Thread::Current())),
102 engine_(NULL, // cricket::WebRtcVoiceEngine
103 new FakeViEWrapper(&vie_), cpu_monitor_),
104 channel_(NULL),
wu@webrtc.orgd64719d2013-08-01 00:00:07 +0000105 voice_channel_(NULL),
106 last_error_(cricket::VideoMediaChannel::ERROR_NONE) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000107 }
108 bool SetupEngine() {
109 bool result = engine_.Init(talk_base::Thread::Current());
110 if (result) {
111 channel_ = engine_.CreateChannel(voice_channel_);
wu@webrtc.orgd64719d2013-08-01 00:00:07 +0000112 channel_->SignalMediaError.connect(this,
113 &WebRtcVideoEngineTestFake::OnMediaError);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000114 result = (channel_ != NULL);
115 }
116 return result;
117 }
wu@webrtc.orgd64719d2013-08-01 00:00:07 +0000118 void OnMediaError(uint32 ssrc, cricket::VideoMediaChannel::Error error) {
119 last_error_ = error;
120 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000121 bool SendI420Frame(int width, int height) {
122 if (NULL == channel_) {
123 return false;
124 }
125 cricket::WebRtcVideoFrame frame;
wu@webrtc.org9caf2762013-12-11 18:25:07 +0000126 if (!frame.InitToBlack(width, height, 1, 1, 0, 0)) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000127 return false;
128 }
129 cricket::FakeVideoCapturer capturer;
130 channel_->SendFrame(&capturer, &frame);
131 return true;
132 }
133 bool SendI420ScreencastFrame(int width, int height) {
134 return SendI420ScreencastFrameWithTimestamp(width, height, 0);
135 }
136 bool SendI420ScreencastFrameWithTimestamp(
137 int width, int height, int64 timestamp) {
138 if (NULL == channel_) {
139 return false;
140 }
141 cricket::WebRtcVideoFrame frame;
wu@webrtc.org9caf2762013-12-11 18:25:07 +0000142 if (!frame.InitToBlack(width, height, 1, 1, 0, 0)) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000143 return false;
144 }
145 cricket::FakeVideoCapturer capturer;
146 capturer.SetScreencast(true);
147 channel_->SendFrame(&capturer, &frame);
148 return true;
149 }
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +0000150 void VerifyCodecFeedbackParams(const cricket::VideoCodec& codec) {
151 EXPECT_TRUE(codec.HasFeedbackParam(
152 cricket::FeedbackParam(cricket::kRtcpFbParamNack,
153 cricket::kParamValueEmpty)));
154 EXPECT_TRUE(codec.HasFeedbackParam(
155 cricket::FeedbackParam(cricket::kRtcpFbParamNack,
156 cricket::kRtcpFbNackParamPli)));
157 EXPECT_TRUE(codec.HasFeedbackParam(
158 cricket::FeedbackParam(cricket::kRtcpFbParamRemb,
159 cricket::kParamValueEmpty)));
160 EXPECT_TRUE(codec.HasFeedbackParam(
161 cricket::FeedbackParam(cricket::kRtcpFbParamCcm,
162 cricket::kRtcpFbCcmParamFir)));
163 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000164 void VerifyVP8SendCodec(int channel_num,
165 unsigned int width,
166 unsigned int height,
167 unsigned int layers = 0,
168 unsigned int max_bitrate = kMaxBandwidthKbps,
169 unsigned int min_bitrate = kMinBandwidthKbps,
170 unsigned int start_bitrate = kStartBandwidthKbps,
171 unsigned int fps = 30,
172 unsigned int max_quantization = 0
173 ) {
174 webrtc::VideoCodec gcodec;
175 EXPECT_EQ(0, vie_.GetSendCodec(channel_num, gcodec));
176
177 // Video codec properties.
178 EXPECT_EQ(webrtc::kVideoCodecVP8, gcodec.codecType);
179 EXPECT_STREQ("VP8", gcodec.plName);
180 EXPECT_EQ(100, gcodec.plType);
181 EXPECT_EQ(width, gcodec.width);
182 EXPECT_EQ(height, gcodec.height);
183 EXPECT_EQ(talk_base::_min(start_bitrate, max_bitrate), gcodec.startBitrate);
184 EXPECT_EQ(max_bitrate, gcodec.maxBitrate);
185 EXPECT_EQ(min_bitrate, gcodec.minBitrate);
186 EXPECT_EQ(fps, gcodec.maxFramerate);
187 // VP8 specific.
188 EXPECT_FALSE(gcodec.codecSpecific.VP8.pictureLossIndicationOn);
189 EXPECT_FALSE(gcodec.codecSpecific.VP8.feedbackModeOn);
190 EXPECT_EQ(webrtc::kComplexityNormal, gcodec.codecSpecific.VP8.complexity);
191 EXPECT_EQ(webrtc::kResilienceOff, gcodec.codecSpecific.VP8.resilience);
192 EXPECT_EQ(max_quantization, gcodec.qpMax);
193 }
194 virtual void TearDown() {
195 delete channel_;
196 engine_.Terminate();
197 }
198
199 protected:
200 cricket::FakeWebRtcVideoEngine vie_;
201 cricket::FakeWebRtcVideoDecoderFactory decoder_factory_;
202 cricket::FakeWebRtcVideoEncoderFactory encoder_factory_;
203 talk_base::FakeCpuMonitor* cpu_monitor_;
204 cricket::WebRtcVideoEngine engine_;
205 cricket::WebRtcVideoMediaChannel* channel_;
206 cricket::WebRtcVoiceMediaChannel* voice_channel_;
wu@webrtc.orgd64719d2013-08-01 00:00:07 +0000207 cricket::VideoMediaChannel::Error last_error_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000208};
209
210// Test fixtures to test WebRtcVideoEngine with a real webrtc::VideoEngine.
211class WebRtcVideoEngineTest
212 : public VideoEngineTest<cricket::WebRtcVideoEngine> {
213 protected:
214 typedef VideoEngineTest<cricket::WebRtcVideoEngine> Base;
215};
216class WebRtcVideoMediaChannelTest
217 : public VideoMediaChannelTest<
218 cricket::WebRtcVideoEngine, cricket::WebRtcVideoMediaChannel> {
219 protected:
220 typedef VideoMediaChannelTest<cricket::WebRtcVideoEngine,
221 cricket::WebRtcVideoMediaChannel> Base;
222 virtual cricket::VideoCodec DefaultCodec() { return kVP8Codec; }
223 virtual void SetUp() {
224 Base::SetUp();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000225 }
226 virtual void TearDown() {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000227 Base::TearDown();
228 }
229};
230
231/////////////////////////
232// Tests with fake ViE //
233/////////////////////////
234
235// Tests that our stub library "works".
236TEST_F(WebRtcVideoEngineTestFake, StartupShutdown) {
237 EXPECT_FALSE(vie_.IsInited());
238 EXPECT_TRUE(engine_.Init(talk_base::Thread::Current()));
239 EXPECT_TRUE(vie_.IsInited());
240 engine_.Terminate();
241}
242
243// Tests that webrtc logs are logged when they should be.
244TEST_F(WebRtcVideoEngineTest, WebRtcShouldLog) {
245 const char webrtc_log[] = "WebRtcVideoEngineTest.WebRtcShouldLog";
246 EXPECT_TRUE(engine_.Init(talk_base::Thread::Current()));
247 engine_.SetLogging(talk_base::LS_INFO, "");
248 std::string str;
249 talk_base::StringStream stream(str);
250 talk_base::LogMessage::AddLogToStream(&stream, talk_base::LS_INFO);
251 EXPECT_EQ(talk_base::LS_INFO, talk_base::LogMessage::GetLogToStream(&stream));
252 webrtc::Trace::Add(webrtc::kTraceStateInfo, webrtc::kTraceUndefined, 0,
253 webrtc_log);
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +0000254 talk_base::Thread::Current()->ProcessMessages(100);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000255 talk_base::LogMessage::RemoveLogToStream(&stream);
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +0000256 // Access |str| after LogMessage is done with it to avoid data racing.
257 EXPECT_NE(std::string::npos, str.find(webrtc_log));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000258}
259
260// Tests that webrtc logs are not logged when they should't be.
261TEST_F(WebRtcVideoEngineTest, WebRtcShouldNotLog) {
262 const char webrtc_log[] = "WebRtcVideoEngineTest.WebRtcShouldNotLog";
263 EXPECT_TRUE(engine_.Init(talk_base::Thread::Current()));
264 // WebRTC should never be logged lower than LS_INFO.
265 engine_.SetLogging(talk_base::LS_WARNING, "");
266 std::string str;
267 talk_base::StringStream stream(str);
268 // Make sure that WebRTC is not logged, even at lowest severity
269 talk_base::LogMessage::AddLogToStream(&stream, talk_base::LS_SENSITIVE);
270 EXPECT_EQ(talk_base::LS_SENSITIVE,
271 talk_base::LogMessage::GetLogToStream(&stream));
272 webrtc::Trace::Add(webrtc::kTraceStateInfo, webrtc::kTraceUndefined, 0,
273 webrtc_log);
274 talk_base::Thread::Current()->ProcessMessages(10);
275 EXPECT_EQ(std::string::npos, str.find(webrtc_log));
276 talk_base::LogMessage::RemoveLogToStream(&stream);
277}
278
279// Tests that we can create and destroy a channel.
280TEST_F(WebRtcVideoEngineTestFake, CreateChannel) {
281 EXPECT_TRUE(engine_.Init(talk_base::Thread::Current()));
282 channel_ = engine_.CreateChannel(voice_channel_);
283 EXPECT_TRUE(channel_ != NULL);
284 EXPECT_EQ(1, engine_.GetNumOfChannels());
285 delete channel_;
286 channel_ = NULL;
287 EXPECT_EQ(0, engine_.GetNumOfChannels());
288}
289
290// Tests that we properly handle failures in CreateChannel.
291TEST_F(WebRtcVideoEngineTestFake, CreateChannelFail) {
292 vie_.set_fail_create_channel(true);
293 EXPECT_TRUE(engine_.Init(talk_base::Thread::Current()));
294 channel_ = engine_.CreateChannel(voice_channel_);
295 EXPECT_TRUE(channel_ == NULL);
296}
297
298// Tests that we properly handle failures in AllocateExternalCaptureDevice.
299TEST_F(WebRtcVideoEngineTestFake, AllocateExternalCaptureDeviceFail) {
300 vie_.set_fail_alloc_capturer(true);
301 EXPECT_TRUE(engine_.Init(talk_base::Thread::Current()));
302 channel_ = engine_.CreateChannel(voice_channel_);
303 EXPECT_TRUE(channel_ == NULL);
304}
305
306// Test that we apply our default codecs properly.
307TEST_F(WebRtcVideoEngineTestFake, SetSendCodecs) {
308 EXPECT_TRUE(SetupEngine());
309 int channel_num = vie_.GetLastChannel();
310 std::vector<cricket::VideoCodec> codecs(engine_.codecs());
311 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
312 VerifyVP8SendCodec(channel_num, kVP8Codec.width, kVP8Codec.height);
313 EXPECT_TRUE(vie_.GetHybridNackFecStatus(channel_num));
314 EXPECT_FALSE(vie_.GetNackStatus(channel_num));
315 // TODO(juberti): Check RTCP, PLI, TMMBR.
316}
317
318TEST_F(WebRtcVideoEngineTestFake, SetSendCodecsWithMinMaxBitrate) {
319 EXPECT_TRUE(SetupEngine());
320 int channel_num = vie_.GetLastChannel();
321 std::vector<cricket::VideoCodec> codecs(engine_.codecs());
322 codecs[0].params[cricket::kCodecParamMinBitrate] = "10";
323 codecs[0].params[cricket::kCodecParamMaxBitrate] = "20";
324 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
325
326 VerifyVP8SendCodec(
327 channel_num, kVP8Codec.width, kVP8Codec.height, 0, 20, 10, 20);
328
329 cricket::VideoCodec codec;
330 EXPECT_TRUE(channel_->GetSendCodec(&codec));
331 EXPECT_EQ("10", codec.params[cricket::kCodecParamMinBitrate]);
332 EXPECT_EQ("20", codec.params[cricket::kCodecParamMaxBitrate]);
333}
334
335TEST_F(WebRtcVideoEngineTestFake, SetSendCodecsWithMinMaxBitrateInvalid) {
336 EXPECT_TRUE(SetupEngine());
337 std::vector<cricket::VideoCodec> codecs(engine_.codecs());
338 codecs[0].params[cricket::kCodecParamMinBitrate] = "30";
339 codecs[0].params[cricket::kCodecParamMaxBitrate] = "20";
340 EXPECT_FALSE(channel_->SetSendCodecs(codecs));
341}
342
343TEST_F(WebRtcVideoEngineTestFake, SetSendCodecsWithLargeMinMaxBitrate) {
344 EXPECT_TRUE(SetupEngine());
345 int channel_num = vie_.GetLastChannel();
346 std::vector<cricket::VideoCodec> codecs(engine_.codecs());
347 codecs[0].params[cricket::kCodecParamMinBitrate] = "1000";
348 codecs[0].params[cricket::kCodecParamMaxBitrate] = "2000";
349 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
350
351 VerifyVP8SendCodec(
352 channel_num, kVP8Codec.width, kVP8Codec.height, 0, 2000, 1000,
353 1000);
354}
355
356TEST_F(WebRtcVideoEngineTestFake, SetSendCodecsWithMaxQuantization) {
357 EXPECT_TRUE(SetupEngine());
358 int channel_num = vie_.GetLastChannel();
359 std::vector<cricket::VideoCodec> codecs(engine_.codecs());
360 codecs[0].params[cricket::kCodecParamMaxQuantization] = "21";
361 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
362
363 VerifyVP8SendCodec(
364 channel_num, kVP8Codec.width, kVP8Codec.height, 0, 2000, 50, 300,
365 30, 21);
366
367 cricket::VideoCodec codec;
368 EXPECT_TRUE(channel_->GetSendCodec(&codec));
369 EXPECT_EQ("21", codec.params[cricket::kCodecParamMaxQuantization]);
370}
371
372TEST_F(WebRtcVideoEngineTestFake, SetOptionsWithMaxBitrate) {
373 EXPECT_TRUE(SetupEngine());
374 int channel_num = vie_.GetLastChannel();
375 std::vector<cricket::VideoCodec> codecs(engine_.codecs());
376 codecs[0].params[cricket::kCodecParamMinBitrate] = "10";
377 codecs[0].params[cricket::kCodecParamMaxBitrate] = "20";
378 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
379
380 VerifyVP8SendCodec(
381 channel_num, kVP8Codec.width, kVP8Codec.height, 0, 20, 10, 20);
382
383 // Verify that max bitrate doesn't change after SetOptions().
384 cricket::VideoOptions options;
385 options.video_noise_reduction.Set(true);
386 EXPECT_TRUE(channel_->SetOptions(options));
387 VerifyVP8SendCodec(
388 channel_num, kVP8Codec.width, kVP8Codec.height, 0, 20, 10, 20);
389
390 options.video_noise_reduction.Set(false);
391 options.conference_mode.Set(false);
392 EXPECT_TRUE(channel_->SetOptions(options));
393 VerifyVP8SendCodec(
394 channel_num, kVP8Codec.width, kVP8Codec.height, 0, 20, 10, 20);
395}
396
wu@webrtc.orgcecfd182013-10-30 05:18:12 +0000397TEST_F(WebRtcVideoEngineTestFake, SetOptionsWithLoweredBitrate) {
398 EXPECT_TRUE(SetupEngine());
399 int channel_num = vie_.GetLastChannel();
400 std::vector<cricket::VideoCodec> codecs(engine_.codecs());
401 codecs[0].params[cricket::kCodecParamMinBitrate] = "50";
402 codecs[0].params[cricket::kCodecParamMaxBitrate] = "100";
403 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
404
405 VerifyVP8SendCodec(
406 channel_num, kVP8Codec.width, kVP8Codec.height, 0, 100, 50, 100);
407
408 // Verify that min bitrate changes after SetOptions().
409 cricket::VideoOptions options;
410 options.lower_min_bitrate.Set(true);
411 EXPECT_TRUE(channel_->SetOptions(options));
412 VerifyVP8SendCodec(
413 channel_num, kVP8Codec.width, kVP8Codec.height, 0, 100, 30, 100);
414}
415
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000416TEST_F(WebRtcVideoEngineTestFake, MaxBitrateResetWithConferenceMode) {
417 EXPECT_TRUE(SetupEngine());
418 int channel_num = vie_.GetLastChannel();
419 std::vector<cricket::VideoCodec> codecs(engine_.codecs());
420 codecs[0].params[cricket::kCodecParamMinBitrate] = "10";
421 codecs[0].params[cricket::kCodecParamMaxBitrate] = "20";
422 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
423
424 VerifyVP8SendCodec(
425 channel_num, kVP8Codec.width, kVP8Codec.height, 0, 20, 10, 20);
426
427 cricket::VideoOptions options;
428 options.conference_mode.Set(true);
429 EXPECT_TRUE(channel_->SetOptions(options));
430 options.conference_mode.Set(false);
431 EXPECT_TRUE(channel_->SetOptions(options));
432 VerifyVP8SendCodec(
433 channel_num, kVP8Codec.width, kVP8Codec.height, 0,
434 kMaxBandwidthKbps, 10, 20);
435}
436
437// Verify the current send bitrate is used as start bitrate when reconfiguring
438// the send codec.
439TEST_F(WebRtcVideoEngineTestFake, StartSendBitrate) {
440 EXPECT_TRUE(SetupEngine());
441 EXPECT_TRUE(channel_->AddSendStream(
442 cricket::StreamParams::CreateLegacy(1)));
443 int send_channel = vie_.GetLastChannel();
444 cricket::VideoCodec codec(kVP8Codec);
445 std::vector<cricket::VideoCodec> codec_list;
446 codec_list.push_back(codec);
447 EXPECT_TRUE(channel_->SetSendCodecs(codec_list));
448 const unsigned int kVideoMaxSendBitrateKbps = 2000;
449 const unsigned int kVideoMinSendBitrateKbps = 50;
450 const unsigned int kVideoDefaultStartSendBitrateKbps = 300;
451 VerifyVP8SendCodec(send_channel, kVP8Codec.width, kVP8Codec.height, 0,
452 kVideoMaxSendBitrateKbps, kVideoMinSendBitrateKbps,
453 kVideoDefaultStartSendBitrateKbps);
454 EXPECT_EQ(0, vie_.StartSend(send_channel));
455
456 // Increase the send bitrate and verify it is used as start bitrate.
457 const unsigned int kVideoSendBitrateBps = 768000;
458 vie_.SetSendBitrates(send_channel, kVideoSendBitrateBps, 0, 0);
459 EXPECT_TRUE(channel_->SetSendCodecs(codec_list));
460 VerifyVP8SendCodec(send_channel, kVP8Codec.width, kVP8Codec.height, 0,
461 kVideoMaxSendBitrateKbps, kVideoMinSendBitrateKbps,
462 kVideoSendBitrateBps / 1000);
463
464 // Never set a start bitrate higher than the max bitrate.
465 vie_.SetSendBitrates(send_channel, kVideoMaxSendBitrateKbps + 500, 0, 0);
466 EXPECT_TRUE(channel_->SetSendCodecs(codec_list));
467 VerifyVP8SendCodec(send_channel, kVP8Codec.width, kVP8Codec.height, 0,
468 kVideoMaxSendBitrateKbps, kVideoMinSendBitrateKbps,
469 kVideoDefaultStartSendBitrateKbps);
470
471 // Use the default start bitrate if the send bitrate is lower.
472 vie_.SetSendBitrates(send_channel, kVideoDefaultStartSendBitrateKbps - 50, 0,
473 0);
474 EXPECT_TRUE(channel_->SetSendCodecs(codec_list));
475 VerifyVP8SendCodec(send_channel, kVP8Codec.width, kVP8Codec.height, 0,
476 kVideoMaxSendBitrateKbps, kVideoMinSendBitrateKbps,
477 kVideoDefaultStartSendBitrateKbps);
478}
479
480
481// Test that we constrain send codecs properly.
482TEST_F(WebRtcVideoEngineTestFake, ConstrainSendCodecs) {
483 EXPECT_TRUE(SetupEngine());
484 int channel_num = vie_.GetLastChannel();
485
486 // Set max settings of 640x400x30.
487 EXPECT_TRUE(engine_.SetDefaultEncoderConfig(
488 cricket::VideoEncoderConfig(kVP8Codec)));
489
490 // Send codec format bigger than max setting.
491 cricket::VideoCodec codec(kVP8Codec);
492 codec.width = 1280;
493 codec.height = 800;
494 codec.framerate = 60;
495 std::vector<cricket::VideoCodec> codec_list;
496 codec_list.push_back(codec);
497
498 // Set send codec and verify codec has been constrained.
499 EXPECT_TRUE(channel_->SetSendCodecs(codec_list));
500 VerifyVP8SendCodec(channel_num, kVP8Codec.width, kVP8Codec.height);
501}
502
503// Test that SetSendCodecs rejects bad format.
504TEST_F(WebRtcVideoEngineTestFake, SetSendCodecsRejectBadFormat) {
505 EXPECT_TRUE(SetupEngine());
506 int channel_num = vie_.GetLastChannel();
507
508 // Set w = 0.
509 cricket::VideoCodec codec(kVP8Codec);
510 codec.width = 0;
511 std::vector<cricket::VideoCodec> codec_list;
512 codec_list.push_back(codec);
513
514 // Verify SetSendCodecs failed and send codec is not changed on engine.
515 EXPECT_FALSE(channel_->SetSendCodecs(codec_list));
516 webrtc::VideoCodec gcodec;
517 // Set plType to something other than the value to test against ensuring
518 // that failure will happen if it is not changed.
519 gcodec.plType = 1;
520 EXPECT_EQ(0, vie_.GetSendCodec(channel_num, gcodec));
521 EXPECT_EQ(0, gcodec.plType);
522
523 // Set h = 0.
524 codec_list[0].width = 640;
525 codec_list[0].height = 0;
526
527 // Verify SetSendCodecs failed and send codec is not changed on engine.
528 EXPECT_FALSE(channel_->SetSendCodecs(codec_list));
529 // Set plType to something other than the value to test against ensuring
530 // that failure will happen if it is not changed.
531 gcodec.plType = 1;
532 EXPECT_EQ(0, vie_.GetSendCodec(channel_num, gcodec));
533 EXPECT_EQ(0, gcodec.plType);
534}
535
536// Test that SetSendCodecs rejects bad codec.
537TEST_F(WebRtcVideoEngineTestFake, SetSendCodecsRejectBadCodec) {
538 EXPECT_TRUE(SetupEngine());
539 int channel_num = vie_.GetLastChannel();
540
541 // Set bad codec name.
542 cricket::VideoCodec codec(kVP8Codec);
543 codec.name = "bad";
544 std::vector<cricket::VideoCodec> codec_list;
545 codec_list.push_back(codec);
546
547 // Verify SetSendCodecs failed and send codec is not changed on engine.
548 EXPECT_FALSE(channel_->SetSendCodecs(codec_list));
549 webrtc::VideoCodec gcodec;
550 // Set plType to something other than the value to test against ensuring
551 // that failure will happen if it is not changed.
552 gcodec.plType = 1;
553 EXPECT_EQ(0, vie_.GetSendCodec(channel_num, gcodec));
554 EXPECT_EQ(0, gcodec.plType);
555}
556
557// Test that vie send codec is reset on new video frame size.
558TEST_F(WebRtcVideoEngineTestFake, ResetVieSendCodecOnNewFrameSize) {
559 EXPECT_TRUE(SetupEngine());
560 int channel_num = vie_.GetLastChannel();
561
562 // Set send codec.
563 std::vector<cricket::VideoCodec> codec_list;
564 codec_list.push_back(kVP8Codec);
565 EXPECT_TRUE(channel_->SetSendCodecs(codec_list));
566 EXPECT_TRUE(channel_->AddSendStream(
567 cricket::StreamParams::CreateLegacy(123)));
568 EXPECT_TRUE(channel_->SetSend(true));
569
570 // Capture a smaller frame and verify vie send codec has been reset to
571 // the new size.
572 SendI420Frame(kVP8Codec.width / 2, kVP8Codec.height / 2);
573 VerifyVP8SendCodec(channel_num, kVP8Codec.width / 2, kVP8Codec.height / 2);
574
575 // Capture a frame bigger than send_codec_ and verify vie send codec has been
576 // reset (and clipped) to send_codec_.
577 SendI420Frame(kVP8Codec.width * 2, kVP8Codec.height * 2);
578 VerifyVP8SendCodec(channel_num, kVP8Codec.width, kVP8Codec.height);
579}
580
581// Test that we set our inbound codecs properly.
582TEST_F(WebRtcVideoEngineTestFake, SetRecvCodecs) {
583 EXPECT_TRUE(SetupEngine());
584 int channel_num = vie_.GetLastChannel();
585
586 std::vector<cricket::VideoCodec> codecs;
587 codecs.push_back(kVP8Codec);
588 EXPECT_TRUE(channel_->SetRecvCodecs(codecs));
589
590 webrtc::VideoCodec wcodec;
591 EXPECT_TRUE(engine_.ConvertFromCricketVideoCodec(kVP8Codec, &wcodec));
592 EXPECT_TRUE(vie_.ReceiveCodecRegistered(channel_num, wcodec));
593}
594
595// Test that channel connects and disconnects external capturer correctly.
596TEST_F(WebRtcVideoEngineTestFake, HasExternalCapturer) {
597 EXPECT_TRUE(SetupEngine());
598 int channel_num = vie_.GetLastChannel();
599
600 EXPECT_EQ(1, vie_.GetNumCapturers());
601 int capture_id = vie_.GetCaptureId(channel_num);
602 EXPECT_EQ(channel_num, vie_.GetCaptureChannelId(capture_id));
603
604 // Delete the channel should disconnect the capturer.
605 delete channel_;
606 channel_ = NULL;
607 EXPECT_EQ(0, vie_.GetNumCapturers());
608}
609
610// Test that channel adds and removes renderer correctly.
611TEST_F(WebRtcVideoEngineTestFake, HasRenderer) {
612 EXPECT_TRUE(SetupEngine());
613 int channel_num = vie_.GetLastChannel();
614
615 EXPECT_TRUE(vie_.GetHasRenderer(channel_num));
616 EXPECT_FALSE(vie_.GetRenderStarted(channel_num));
617}
618
619// Test that rtcp is enabled on the channel.
620TEST_F(WebRtcVideoEngineTestFake, RtcpEnabled) {
621 EXPECT_TRUE(SetupEngine());
622 int channel_num = vie_.GetLastChannel();
623 EXPECT_EQ(webrtc::kRtcpCompound_RFC4585, vie_.GetRtcpStatus(channel_num));
624}
625
626// Test that key frame request method is set on the channel.
627TEST_F(WebRtcVideoEngineTestFake, KeyFrameRequestEnabled) {
628 EXPECT_TRUE(SetupEngine());
629 int channel_num = vie_.GetLastChannel();
630 EXPECT_EQ(webrtc::kViEKeyFrameRequestPliRtcp,
631 vie_.GetKeyFrameRequestMethod(channel_num));
632}
633
634// Test that remb receive and send is enabled for the default channel in a 1:1
635// call.
636TEST_F(WebRtcVideoEngineTestFake, RembEnabled) {
637 EXPECT_TRUE(SetupEngine());
638 int channel_num = vie_.GetLastChannel();
639 EXPECT_TRUE(channel_->AddSendStream(
640 cricket::StreamParams::CreateLegacy(1)));
641 EXPECT_TRUE(channel_->SetSendCodecs(engine_.codecs()));
642 EXPECT_TRUE(vie_.GetRembStatusBwPartition(channel_num));
643 EXPECT_TRUE(channel_->SetSend(true));
644 EXPECT_TRUE(vie_.GetRembStatusBwPartition(channel_num));
645 EXPECT_TRUE(vie_.GetRembStatusContribute(channel_num));
646}
647
648// When in conference mode, test that remb is enabled on a receive channel but
649// not for the default channel and that it uses the default channel for sending
650// remb packets.
651TEST_F(WebRtcVideoEngineTestFake, RembEnabledOnReceiveChannels) {
652 EXPECT_TRUE(SetupEngine());
653 int default_channel = vie_.GetLastChannel();
654 cricket::VideoOptions options;
655 options.conference_mode.Set(true);
656 EXPECT_TRUE(channel_->SetOptions(options));
657 EXPECT_TRUE(channel_->AddSendStream(
658 cricket::StreamParams::CreateLegacy(1)));
659 EXPECT_TRUE(channel_->SetSendCodecs(engine_.codecs()));
660 EXPECT_TRUE(vie_.GetRembStatusBwPartition(default_channel));
661 EXPECT_TRUE(vie_.GetRembStatusContribute(default_channel));
662 EXPECT_TRUE(channel_->SetSend(true));
663 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(1)));
664 int new_channel_num = vie_.GetLastChannel();
665 EXPECT_NE(default_channel, new_channel_num);
666
667 EXPECT_TRUE(vie_.GetRembStatusBwPartition(default_channel));
668 EXPECT_TRUE(vie_.GetRembStatusContribute(default_channel));
669 EXPECT_FALSE(vie_.GetRembStatusBwPartition(new_channel_num));
670 EXPECT_TRUE(vie_.GetRembStatusContribute(new_channel_num));
671}
672
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000673TEST_F(WebRtcVideoEngineTestFake, RecvStreamWithRtx) {
674 EXPECT_TRUE(SetupEngine());
675 int default_channel = vie_.GetLastChannel();
676 cricket::VideoOptions options;
677 options.conference_mode.Set(true);
678 EXPECT_TRUE(channel_->SetOptions(options));
679 EXPECT_TRUE(channel_->AddSendStream(
680 cricket::CreateSimWithRtxStreamParams("cname",
681 MAKE_VECTOR(kSsrcs3),
682 MAKE_VECTOR(kRtxSsrcs3))));
683 EXPECT_TRUE(channel_->SetSendCodecs(engine_.codecs()));
684 EXPECT_TRUE(channel_->SetSend(true));
685 EXPECT_TRUE(channel_->AddRecvStream(
686 cricket::CreateSimWithRtxStreamParams("cname",
687 MAKE_VECTOR(kSsrcs1),
688 MAKE_VECTOR(kRtxSsrc1))));
689 int new_channel_num = vie_.GetLastChannel();
690 EXPECT_NE(default_channel, new_channel_num);
691 EXPECT_EQ(4, vie_.GetRemoteRtxSsrc(new_channel_num));
692}
693
694TEST_F(WebRtcVideoEngineTestFake, RecvStreamNoRtx) {
695 EXPECT_TRUE(SetupEngine());
696 int default_channel = vie_.GetLastChannel();
697 cricket::VideoOptions options;
698 options.conference_mode.Set(true);
699 EXPECT_TRUE(channel_->SetOptions(options));
700 EXPECT_TRUE(channel_->AddSendStream(
701 cricket::CreateSimWithRtxStreamParams("cname",
702 MAKE_VECTOR(kSsrcs3),
703 MAKE_VECTOR(kRtxSsrcs3))));
704 EXPECT_TRUE(channel_->SetSendCodecs(engine_.codecs()));
705 EXPECT_TRUE(channel_->SetSend(true));
706 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(1)));
707 int new_channel_num = vie_.GetLastChannel();
708 EXPECT_NE(default_channel, new_channel_num);
709 EXPECT_EQ(-1, vie_.GetRemoteRtxSsrc(new_channel_num));
710}
711
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000712// Test support for RTP timestamp offset header extension.
713TEST_F(WebRtcVideoEngineTestFake, RtpTimestampOffsetHeaderExtensions) {
714 EXPECT_TRUE(SetupEngine());
715 int channel_num = vie_.GetLastChannel();
716 cricket::VideoOptions options;
717 options.conference_mode.Set(true);
718 EXPECT_TRUE(channel_->SetOptions(options));
719
720 // Verify extensions are off by default.
721 EXPECT_EQ(0, vie_.GetSendRtpTimestampOffsetExtensionId(channel_num));
722 EXPECT_EQ(0, vie_.GetReceiveRtpTimestampOffsetExtensionId(channel_num));
723
724 // Enable RTP timestamp extension.
725 const int id = 14;
726 std::vector<cricket::RtpHeaderExtension> extensions;
727 extensions.push_back(cricket::RtpHeaderExtension(
728 "urn:ietf:params:rtp-hdrext:toffset", id));
729
730 // Verify the send extension id.
731 EXPECT_TRUE(channel_->SetSendRtpHeaderExtensions(extensions));
732 EXPECT_EQ(id, vie_.GetSendRtpTimestampOffsetExtensionId(channel_num));
733
734 // Remove the extension id.
735 std::vector<cricket::RtpHeaderExtension> empty_extensions;
736 EXPECT_TRUE(channel_->SetSendRtpHeaderExtensions(empty_extensions));
737 EXPECT_EQ(0, vie_.GetSendRtpTimestampOffsetExtensionId(channel_num));
738
739 // Verify receive extension id.
740 EXPECT_TRUE(channel_->SetRecvRtpHeaderExtensions(extensions));
741 EXPECT_EQ(id, vie_.GetReceiveRtpTimestampOffsetExtensionId(channel_num));
742
743 // Add a new receive stream and verify the extension is set.
744 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(2)));
745 int new_channel_num = vie_.GetLastChannel();
746 EXPECT_NE(channel_num, new_channel_num);
747 EXPECT_EQ(id, vie_.GetReceiveRtpTimestampOffsetExtensionId(new_channel_num));
748
749 // Remove the extension id.
750 EXPECT_TRUE(channel_->SetRecvRtpHeaderExtensions(empty_extensions));
751 EXPECT_EQ(0, vie_.GetReceiveRtpTimestampOffsetExtensionId(channel_num));
752 EXPECT_EQ(0, vie_.GetReceiveRtpTimestampOffsetExtensionId(new_channel_num));
753}
754
755// Test support for absolute send time header extension.
756TEST_F(WebRtcVideoEngineTestFake, AbsoluteSendTimeHeaderExtensions) {
757 EXPECT_TRUE(SetupEngine());
758 int channel_num = vie_.GetLastChannel();
759 cricket::VideoOptions options;
760 options.conference_mode.Set(true);
761 EXPECT_TRUE(channel_->SetOptions(options));
762
763 // Verify extensions are off by default.
764 EXPECT_EQ(0, vie_.GetSendAbsoluteSendTimeExtensionId(channel_num));
765 EXPECT_EQ(0, vie_.GetReceiveAbsoluteSendTimeExtensionId(channel_num));
766
767 // Enable RTP timestamp extension.
768 const int id = 12;
769 std::vector<cricket::RtpHeaderExtension> extensions;
770 extensions.push_back(cricket::RtpHeaderExtension(
771 "http://www.webrtc.org/experiments/rtp-hdrext/abs-send-time", id));
772
773 // Verify the send extension id.
774 EXPECT_TRUE(channel_->SetSendRtpHeaderExtensions(extensions));
775 EXPECT_EQ(id, vie_.GetSendAbsoluteSendTimeExtensionId(channel_num));
776
777 // Remove the extension id.
778 std::vector<cricket::RtpHeaderExtension> empty_extensions;
779 EXPECT_TRUE(channel_->SetSendRtpHeaderExtensions(empty_extensions));
780 EXPECT_EQ(0, vie_.GetSendAbsoluteSendTimeExtensionId(channel_num));
781
782 // Verify receive extension id.
783 EXPECT_TRUE(channel_->SetRecvRtpHeaderExtensions(extensions));
784 EXPECT_EQ(id, vie_.GetReceiveAbsoluteSendTimeExtensionId(channel_num));
785
786 // Add a new receive stream and verify the extension is set.
787 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(2)));
788 int new_channel_num = vie_.GetLastChannel();
789 EXPECT_NE(channel_num, new_channel_num);
790 EXPECT_EQ(id, vie_.GetReceiveAbsoluteSendTimeExtensionId(new_channel_num));
791
792 // Remove the extension id.
793 EXPECT_TRUE(channel_->SetRecvRtpHeaderExtensions(empty_extensions));
794 EXPECT_EQ(0, vie_.GetReceiveAbsoluteSendTimeExtensionId(channel_num));
795 EXPECT_EQ(0, vie_.GetReceiveAbsoluteSendTimeExtensionId(new_channel_num));
796}
797
798TEST_F(WebRtcVideoEngineTestFake, LeakyBucketTest) {
799 EXPECT_TRUE(SetupEngine());
800
801 // Verify this is off by default.
802 EXPECT_TRUE(channel_->AddSendStream(cricket::StreamParams::CreateLegacy(1)));
803 int first_send_channel = vie_.GetLastChannel();
804 EXPECT_FALSE(vie_.GetTransmissionSmoothingStatus(first_send_channel));
805
806 // Enable the experiment and verify.
807 cricket::VideoOptions options;
808 options.conference_mode.Set(true);
809 options.video_leaky_bucket.Set(true);
810 EXPECT_TRUE(channel_->SetOptions(options));
811 EXPECT_TRUE(vie_.GetTransmissionSmoothingStatus(first_send_channel));
812
813 // Add a receive channel and verify leaky bucket isn't enabled.
814 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(2)));
815 int recv_channel_num = vie_.GetLastChannel();
816 EXPECT_NE(first_send_channel, recv_channel_num);
817 EXPECT_FALSE(vie_.GetTransmissionSmoothingStatus(recv_channel_num));
818
819 // Add a new send stream and verify leaky bucket is enabled from start.
820 EXPECT_TRUE(channel_->AddSendStream(cricket::StreamParams::CreateLegacy(3)));
821 int second_send_channel = vie_.GetLastChannel();
822 EXPECT_NE(first_send_channel, second_send_channel);
823 EXPECT_TRUE(vie_.GetTransmissionSmoothingStatus(second_send_channel));
824}
825
826TEST_F(WebRtcVideoEngineTestFake, BufferedModeLatency) {
827 EXPECT_TRUE(SetupEngine());
828
829 // Verify this is off by default.
830 EXPECT_TRUE(channel_->AddSendStream(cricket::StreamParams::CreateLegacy(1)));
831 int first_send_channel = vie_.GetLastChannel();
832 EXPECT_EQ(0, vie_.GetSenderTargetDelay(first_send_channel));
833 EXPECT_EQ(0, vie_.GetReceiverTargetDelay(first_send_channel));
834
835 // Enable the experiment and verify. The default channel will have both
836 // sender and receiver buffered mode enabled.
837 cricket::VideoOptions options;
838 options.conference_mode.Set(true);
839 options.buffered_mode_latency.Set(100);
840 EXPECT_TRUE(channel_->SetOptions(options));
841 EXPECT_EQ(100, vie_.GetSenderTargetDelay(first_send_channel));
842 EXPECT_EQ(100, vie_.GetReceiverTargetDelay(first_send_channel));
843
844 // Add a receive channel and verify sender buffered mode isn't enabled.
845 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(2)));
846 int recv_channel_num = vie_.GetLastChannel();
847 EXPECT_NE(first_send_channel, recv_channel_num);
848 EXPECT_EQ(0, vie_.GetSenderTargetDelay(recv_channel_num));
849 EXPECT_EQ(100, vie_.GetReceiverTargetDelay(recv_channel_num));
850
851 // Add a new send stream and verify sender buffered mode is enabled.
852 EXPECT_TRUE(channel_->AddSendStream(cricket::StreamParams::CreateLegacy(3)));
853 int second_send_channel = vie_.GetLastChannel();
854 EXPECT_NE(first_send_channel, second_send_channel);
855 EXPECT_EQ(100, vie_.GetSenderTargetDelay(second_send_channel));
856 EXPECT_EQ(0, vie_.GetReceiverTargetDelay(second_send_channel));
857
858 // Disable sender buffered mode and verify.
859 options.buffered_mode_latency.Set(cricket::kBufferedModeDisabled);
860 EXPECT_TRUE(channel_->SetOptions(options));
861 EXPECT_EQ(0, vie_.GetSenderTargetDelay(first_send_channel));
862 EXPECT_EQ(0, vie_.GetReceiverTargetDelay(first_send_channel));
863 EXPECT_EQ(0, vie_.GetSenderTargetDelay(second_send_channel));
864 EXPECT_EQ(0, vie_.GetReceiverTargetDelay(second_send_channel));
865 EXPECT_EQ(0, vie_.GetSenderTargetDelay(recv_channel_num));
866 EXPECT_EQ(0, vie_.GetReceiverTargetDelay(recv_channel_num));
867}
868
869TEST_F(WebRtcVideoEngineTestFake, AdditiveVideoOptions) {
870 EXPECT_TRUE(SetupEngine());
871
872 EXPECT_TRUE(channel_->AddSendStream(cricket::StreamParams::CreateLegacy(1)));
873 int first_send_channel = vie_.GetLastChannel();
874 EXPECT_EQ(0, vie_.GetSenderTargetDelay(first_send_channel));
875 EXPECT_EQ(0, vie_.GetReceiverTargetDelay(first_send_channel));
876
877 cricket::VideoOptions options1;
878 options1.buffered_mode_latency.Set(100);
879 EXPECT_TRUE(channel_->SetOptions(options1));
880 EXPECT_EQ(100, vie_.GetSenderTargetDelay(first_send_channel));
881 EXPECT_EQ(100, vie_.GetReceiverTargetDelay(first_send_channel));
882 EXPECT_FALSE(vie_.GetTransmissionSmoothingStatus(first_send_channel));
883
884 cricket::VideoOptions options2;
885 options2.video_leaky_bucket.Set(true);
886 EXPECT_TRUE(channel_->SetOptions(options2));
887 EXPECT_TRUE(vie_.GetTransmissionSmoothingStatus(first_send_channel));
888 // The buffered_mode_latency still takes effect.
889 EXPECT_EQ(100, vie_.GetSenderTargetDelay(first_send_channel));
890 EXPECT_EQ(100, vie_.GetReceiverTargetDelay(first_send_channel));
891
892 options1.buffered_mode_latency.Set(50);
893 EXPECT_TRUE(channel_->SetOptions(options1));
894 EXPECT_EQ(50, vie_.GetSenderTargetDelay(first_send_channel));
895 EXPECT_EQ(50, vie_.GetReceiverTargetDelay(first_send_channel));
896 // The video_leaky_bucket still takes effect.
897 EXPECT_TRUE(vie_.GetTransmissionSmoothingStatus(first_send_channel));
898}
899
900// Test that AddRecvStream doesn't create new channel for 1:1 call.
901TEST_F(WebRtcVideoEngineTestFake, AddRecvStream1On1) {
902 EXPECT_TRUE(SetupEngine());
903 int channel_num = vie_.GetLastChannel();
904 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(1)));
905 EXPECT_EQ(channel_num, vie_.GetLastChannel());
906}
907
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +0000908// Test that NACK, PLI and REMB are enabled for internal codec.
909TEST_F(WebRtcVideoEngineTestFake, InternalCodecFeedbackParams) {
910 EXPECT_TRUE(SetupEngine());
911
912 std::vector<cricket::VideoCodec> codecs(engine_.codecs());
913 // Vp8 will appear at the beginning.
914 size_t pos = 0;
915 EXPECT_EQ("VP8", codecs[pos].name);
916 VerifyCodecFeedbackParams(codecs[pos]);
917}
918
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000919// Test that AddRecvStream doesn't change remb for 1:1 call.
920TEST_F(WebRtcVideoEngineTestFake, NoRembChangeAfterAddRecvStream) {
921 EXPECT_TRUE(SetupEngine());
922 int channel_num = vie_.GetLastChannel();
923 EXPECT_TRUE(channel_->AddSendStream(
924 cricket::StreamParams::CreateLegacy(1)));
925 EXPECT_TRUE(channel_->SetSendCodecs(engine_.codecs()));
926 EXPECT_TRUE(vie_.GetRembStatusBwPartition(channel_num));
927 EXPECT_TRUE(vie_.GetRembStatusContribute(channel_num));
928 EXPECT_TRUE(channel_->SetSend(true));
929 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(1)));
930 EXPECT_TRUE(vie_.GetRembStatusBwPartition(channel_num));
931 EXPECT_TRUE(vie_.GetRembStatusContribute(channel_num));
932}
933
934// Verify default REMB setting and that it can be turned on and off.
935TEST_F(WebRtcVideoEngineTestFake, RembOnOff) {
936 EXPECT_TRUE(SetupEngine());
937 int channel_num = vie_.GetLastChannel();
938 // Verify REMB sending is always off by default.
939 EXPECT_FALSE(vie_.GetRembStatusBwPartition(channel_num));
940
941 // Verify that REMB is turned on when setting default codecs since the
942 // default codecs have REMB enabled.
943 EXPECT_TRUE(channel_->SetSendCodecs(engine_.codecs()));
944 EXPECT_TRUE(vie_.GetRembStatusBwPartition(channel_num));
945
946 // Verify that REMB is turned off when codecs without REMB are set.
947 std::vector<cricket::VideoCodec> codecs = engine_.codecs();
948 // Clearing the codecs' FeedbackParams and setting send codecs should disable
949 // REMB.
950 for (std::vector<cricket::VideoCodec>::iterator iter = codecs.begin();
951 iter != codecs.end(); ++iter) {
952 // Intersecting with empty will clear the FeedbackParams.
953 cricket::FeedbackParams empty_params;
954 iter->feedback_params.Intersect(empty_params);
955 EXPECT_TRUE(iter->feedback_params.params().empty());
956 }
957 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
958 EXPECT_FALSE(vie_.GetRembStatusBwPartition(channel_num));
959}
960
961// Test that nack is enabled on the channel if we don't offer red/fec.
962TEST_F(WebRtcVideoEngineTestFake, NackEnabled) {
963 EXPECT_TRUE(SetupEngine());
964 int channel_num = vie_.GetLastChannel();
965 std::vector<cricket::VideoCodec> codecs(engine_.codecs());
966 codecs.resize(1); // toss out red and ulpfec
967 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
968 EXPECT_TRUE(vie_.GetNackStatus(channel_num));
969}
970
971// Test that we enable hybrid NACK FEC mode.
972TEST_F(WebRtcVideoEngineTestFake, HybridNackFec) {
973 EXPECT_TRUE(SetupEngine());
974 int channel_num = vie_.GetLastChannel();
975 EXPECT_TRUE(channel_->SetRecvCodecs(engine_.codecs()));
976 EXPECT_TRUE(channel_->SetSendCodecs(engine_.codecs()));
977 EXPECT_TRUE(vie_.GetHybridNackFecStatus(channel_num));
978 EXPECT_FALSE(vie_.GetNackStatus(channel_num));
979}
980
981// Test that we enable hybrid NACK FEC mode when calling SetSendCodecs and
982// SetReceiveCodecs in reversed order.
983TEST_F(WebRtcVideoEngineTestFake, HybridNackFecReversedOrder) {
984 EXPECT_TRUE(SetupEngine());
985 int channel_num = vie_.GetLastChannel();
986 EXPECT_TRUE(channel_->SetSendCodecs(engine_.codecs()));
987 EXPECT_TRUE(channel_->SetRecvCodecs(engine_.codecs()));
988 EXPECT_TRUE(vie_.GetHybridNackFecStatus(channel_num));
989 EXPECT_FALSE(vie_.GetNackStatus(channel_num));
990}
991
992// Test NACK vs Hybrid NACK/FEC interop call setup, i.e. only use NACK even if
993// red/fec is offered as receive codec.
994TEST_F(WebRtcVideoEngineTestFake, VideoProtectionInterop) {
995 EXPECT_TRUE(SetupEngine());
996 int channel_num = vie_.GetLastChannel();
997 std::vector<cricket::VideoCodec> recv_codecs(engine_.codecs());
998 std::vector<cricket::VideoCodec> send_codecs(engine_.codecs());
999 // Only add VP8 as send codec.
1000 send_codecs.resize(1);
1001 EXPECT_TRUE(channel_->SetRecvCodecs(recv_codecs));
1002 EXPECT_TRUE(channel_->SetSendCodecs(send_codecs));
1003 EXPECT_FALSE(vie_.GetHybridNackFecStatus(channel_num));
1004 EXPECT_TRUE(vie_.GetNackStatus(channel_num));
1005}
1006
1007// Test NACK vs Hybrid NACK/FEC interop call setup, i.e. only use NACK even if
1008// red/fec is offered as receive codec. Call order reversed compared to
1009// VideoProtectionInterop.
1010TEST_F(WebRtcVideoEngineTestFake, VideoProtectionInteropReversed) {
1011 EXPECT_TRUE(SetupEngine());
1012 int channel_num = vie_.GetLastChannel();
1013 std::vector<cricket::VideoCodec> recv_codecs(engine_.codecs());
1014 std::vector<cricket::VideoCodec> send_codecs(engine_.codecs());
1015 // Only add VP8 as send codec.
1016 send_codecs.resize(1);
1017 EXPECT_TRUE(channel_->SetSendCodecs(send_codecs));
1018 EXPECT_TRUE(channel_->SetRecvCodecs(recv_codecs));
1019 EXPECT_FALSE(vie_.GetHybridNackFecStatus(channel_num));
1020 EXPECT_TRUE(vie_.GetNackStatus(channel_num));
1021}
1022
1023// Test that NACK, not hybrid mode, is enabled in conference mode.
1024TEST_F(WebRtcVideoEngineTestFake, HybridNackFecConference) {
1025 EXPECT_TRUE(SetupEngine());
1026 // Setup the send channel.
1027 int send_channel_num = vie_.GetLastChannel();
1028 cricket::VideoOptions options;
1029 options.conference_mode.Set(true);
1030 EXPECT_TRUE(channel_->SetOptions(options));
1031 EXPECT_TRUE(channel_->SetRecvCodecs(engine_.codecs()));
1032 EXPECT_TRUE(channel_->SetSendCodecs(engine_.codecs()));
1033 EXPECT_FALSE(vie_.GetHybridNackFecStatus(send_channel_num));
1034 EXPECT_TRUE(vie_.GetNackStatus(send_channel_num));
1035 // Add a receive stream.
1036 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(1)));
1037 int receive_channel_num = vie_.GetLastChannel();
1038 EXPECT_FALSE(vie_.GetHybridNackFecStatus(receive_channel_num));
1039 EXPECT_TRUE(vie_.GetNackStatus(receive_channel_num));
1040}
1041
1042// Test that when AddRecvStream in conference mode, a new channel is created
1043// for receiving. And the new channel's "original channel" is the send channel.
1044TEST_F(WebRtcVideoEngineTestFake, AddRemoveRecvStreamConference) {
1045 EXPECT_TRUE(SetupEngine());
1046 // Setup the send channel.
1047 int send_channel_num = vie_.GetLastChannel();
1048 cricket::VideoOptions options;
1049 options.conference_mode.Set(true);
1050 EXPECT_TRUE(channel_->SetOptions(options));
1051 // Add a receive stream.
1052 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(1)));
1053 int receive_channel_num = vie_.GetLastChannel();
1054 EXPECT_EQ(send_channel_num, vie_.GetOriginalChannelId(receive_channel_num));
1055 EXPECT_TRUE(channel_->RemoveRecvStream(1));
1056 EXPECT_FALSE(vie_.IsChannel(receive_channel_num));
1057}
1058
1059// Test that we can create a channel and start/stop rendering out on it.
1060TEST_F(WebRtcVideoEngineTestFake, SetRender) {
1061 EXPECT_TRUE(SetupEngine());
1062 int channel_num = vie_.GetLastChannel();
1063
1064 // Verify we can start/stop/start/stop rendering.
1065 EXPECT_TRUE(channel_->SetRender(true));
1066 EXPECT_TRUE(vie_.GetRenderStarted(channel_num));
1067 EXPECT_TRUE(channel_->SetRender(false));
1068 EXPECT_FALSE(vie_.GetRenderStarted(channel_num));
1069 EXPECT_TRUE(channel_->SetRender(true));
1070 EXPECT_TRUE(vie_.GetRenderStarted(channel_num));
1071 EXPECT_TRUE(channel_->SetRender(false));
1072 EXPECT_FALSE(vie_.GetRenderStarted(channel_num));
1073}
1074
1075// Test that we can create a channel and start/stop sending out on it.
1076TEST_F(WebRtcVideoEngineTestFake, SetSend) {
1077 EXPECT_TRUE(SetupEngine());
1078 int channel_num = vie_.GetLastChannel();
1079
1080 // Set send codecs on the channel.
1081 std::vector<cricket::VideoCodec> codecs;
1082 codecs.push_back(kVP8Codec);
1083 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1084 EXPECT_TRUE(channel_->AddSendStream(
1085 cricket::StreamParams::CreateLegacy(123)));
1086
1087 // Verify we can start/stop/start/stop sending.
1088 EXPECT_TRUE(channel_->SetSend(true));
1089 EXPECT_TRUE(vie_.GetSend(channel_num));
1090 EXPECT_TRUE(channel_->SetSend(false));
1091 EXPECT_FALSE(vie_.GetSend(channel_num));
1092 EXPECT_TRUE(channel_->SetSend(true));
1093 EXPECT_TRUE(vie_.GetSend(channel_num));
1094 EXPECT_TRUE(channel_->SetSend(false));
1095 EXPECT_FALSE(vie_.GetSend(channel_num));
1096}
1097
1098// Test that we set bandwidth properly when using full auto bandwidth mode.
1099TEST_F(WebRtcVideoEngineTestFake, SetBandwidthAuto) {
1100 EXPECT_TRUE(SetupEngine());
1101 int channel_num = vie_.GetLastChannel();
1102 EXPECT_TRUE(channel_->SetSendCodecs(engine_.codecs()));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001103 EXPECT_TRUE(channel_->SetMaxSendBandwidth(cricket::kAutoBandwidth));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001104 VerifyVP8SendCodec(channel_num, kVP8Codec.width, kVP8Codec.height);
1105}
1106
1107// Test that we set bandwidth properly when using auto with upper bound.
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001108TEST_F(WebRtcVideoEngineTestFake, SetBandwidthCapped) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001109 EXPECT_TRUE(SetupEngine());
1110 int channel_num = vie_.GetLastChannel();
1111 EXPECT_TRUE(channel_->SetSendCodecs(engine_.codecs()));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001112 EXPECT_TRUE(channel_->SetMaxSendBandwidth(768000));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001113 VerifyVP8SendCodec(channel_num, kVP8Codec.width, kVP8Codec.height, 0, 768U);
1114}
1115
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001116// Test that we reduce the start bandwidth when the requested max is less than
1117// the default start bandwidth.
1118TEST_F(WebRtcVideoEngineTestFake, SetMaxBandwidthBelowDefaultStart) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001119 EXPECT_TRUE(SetupEngine());
1120 int channel_num = vie_.GetLastChannel();
1121 EXPECT_TRUE(channel_->SetSendCodecs(engine_.codecs()));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001122 int max_bandwidth_kbps = (kMinBandwidthKbps + kStartBandwidthKbps) / 2;
1123 EXPECT_TRUE(channel_->SetMaxSendBandwidth(max_bandwidth_kbps * 1000));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001124 VerifyVP8SendCodec(channel_num, kVP8Codec.width, kVP8Codec.height, 0,
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001125 max_bandwidth_kbps, kMinBandwidthKbps, max_bandwidth_kbps);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001126}
1127
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001128// Test that we reduce the min bandwidth when the requested max is less than
1129// the min bandwidth.
1130TEST_F(WebRtcVideoEngineTestFake, SetMaxBandwidthBelowMin) {
1131 EXPECT_TRUE(SetupEngine());
1132 int channel_num = vie_.GetLastChannel();
1133 EXPECT_TRUE(channel_->SetSendCodecs(engine_.codecs()));
1134 int max_bandwidth_kbps = kMinBandwidthKbps / 2;
1135 EXPECT_TRUE(channel_->SetMaxSendBandwidth(max_bandwidth_kbps * 1000));
1136 VerifyVP8SendCodec(channel_num, kVP8Codec.width, kVP8Codec.height, 0,
1137 max_bandwidth_kbps, max_bandwidth_kbps, max_bandwidth_kbps);
1138}
1139
1140// Test that the start bandwidth can be controlled separately from the max
1141// bandwidth.
1142TEST_F(WebRtcVideoEngineTestFake, SetStartBandwidth) {
1143 EXPECT_TRUE(SetupEngine());
1144 int channel_num = vie_.GetLastChannel();
1145 EXPECT_TRUE(channel_->SetSendCodecs(engine_.codecs()));
1146 int start_bandwidth_kbps = kStartBandwidthKbps + 1;
1147 EXPECT_TRUE(channel_->SetStartSendBandwidth(start_bandwidth_kbps * 1000));
1148 VerifyVP8SendCodec(channel_num, kVP8Codec.width, kVP8Codec.height, 0,
1149 kMaxBandwidthKbps, kMinBandwidthKbps, start_bandwidth_kbps);
1150
1151 // Check that SetMaxSendBandwidth doesn't overwrite the start bandwidth.
1152 int max_bandwidth_kbps = kMaxBandwidthKbps + 1;
1153 EXPECT_TRUE(channel_->SetMaxSendBandwidth(max_bandwidth_kbps * 1000));
1154 VerifyVP8SendCodec(channel_num, kVP8Codec.width, kVP8Codec.height, 0,
1155 max_bandwidth_kbps, kMinBandwidthKbps, start_bandwidth_kbps);
1156}
1157
1158// Test that SetMaxSendBandwidth is ignored in conference mode.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001159TEST_F(WebRtcVideoEngineTestFake, SetBandwidthInConference) {
1160 EXPECT_TRUE(SetupEngine());
1161 int channel_num = vie_.GetLastChannel();
1162 cricket::VideoOptions options;
1163 options.conference_mode.Set(true);
1164 EXPECT_TRUE(channel_->SetOptions(options));
1165 EXPECT_TRUE(channel_->SetSendCodecs(engine_.codecs()));
1166 VerifyVP8SendCodec(channel_num, kVP8Codec.width, kVP8Codec.height);
1167
1168 // Set send bandwidth.
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001169 EXPECT_TRUE(channel_->SetMaxSendBandwidth(768000));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001170
1171 // Verify bitrate not changed.
1172 webrtc::VideoCodec gcodec;
1173 EXPECT_EQ(0, vie_.GetSendCodec(channel_num, gcodec));
1174 EXPECT_EQ(kMinBandwidthKbps, gcodec.minBitrate);
1175 EXPECT_EQ(kStartBandwidthKbps, gcodec.startBitrate);
1176 EXPECT_EQ(kMaxBandwidthKbps, gcodec.maxBitrate);
1177 EXPECT_NE(768U, gcodec.minBitrate);
1178 EXPECT_NE(768U, gcodec.startBitrate);
1179 EXPECT_NE(768U, gcodec.maxBitrate);
1180}
1181
1182// Test that sending screencast frames doesn't change bitrate.
1183TEST_F(WebRtcVideoEngineTestFake, SetBandwidthScreencast) {
1184 EXPECT_TRUE(SetupEngine());
1185 int channel_num = vie_.GetLastChannel();
1186
1187 // Set send codec.
1188 cricket::VideoCodec codec(kVP8Codec);
1189 std::vector<cricket::VideoCodec> codec_list;
1190 codec_list.push_back(codec);
1191 EXPECT_TRUE(channel_->AddSendStream(
1192 cricket::StreamParams::CreateLegacy(123)));
1193 EXPECT_TRUE(channel_->SetSendCodecs(codec_list));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001194 EXPECT_TRUE(channel_->SetMaxSendBandwidth(111000));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001195 EXPECT_TRUE(channel_->SetSend(true));
1196
1197 SendI420ScreencastFrame(kVP8Codec.width, kVP8Codec.height);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001198 VerifyVP8SendCodec(channel_num, kVP8Codec.width, kVP8Codec.height, 0, 111);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001199}
1200
1201
1202// Test SetSendSsrc.
1203TEST_F(WebRtcVideoEngineTestFake, SetSendSsrcAndCname) {
1204 EXPECT_TRUE(SetupEngine());
1205 int channel_num = vie_.GetLastChannel();
1206
1207 cricket::StreamParams stream;
1208 stream.ssrcs.push_back(1234);
1209 stream.cname = "cname";
1210 channel_->AddSendStream(stream);
1211
1212 unsigned int ssrc = 0;
1213 EXPECT_EQ(0, vie_.GetLocalSSRC(channel_num, ssrc));
1214 EXPECT_EQ(1234U, ssrc);
1215 EXPECT_EQ(1, vie_.GetNumSsrcs(channel_num));
1216
1217 char rtcp_cname[256];
1218 EXPECT_EQ(0, vie_.GetRTCPCName(channel_num, rtcp_cname));
1219 EXPECT_STREQ("cname", rtcp_cname);
1220}
1221
1222
1223// Test that the local SSRC is the same on sending and receiving channels if the
1224// receive channel is created before the send channel.
1225TEST_F(WebRtcVideoEngineTestFake, SetSendSsrcAfterCreatingReceiveChannel) {
1226 EXPECT_TRUE(SetupEngine());
1227
1228 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(1)));
1229 int receive_channel_num = vie_.GetLastChannel();
1230 cricket::StreamParams stream = cricket::StreamParams::CreateLegacy(1234);
1231 EXPECT_TRUE(channel_->AddSendStream(stream));
1232 int send_channel_num = vie_.GetLastChannel();
1233 unsigned int ssrc = 0;
1234 EXPECT_EQ(0, vie_.GetLocalSSRC(send_channel_num, ssrc));
1235 EXPECT_EQ(1234U, ssrc);
1236 EXPECT_EQ(1, vie_.GetNumSsrcs(send_channel_num));
1237 ssrc = 0;
1238 EXPECT_EQ(0, vie_.GetLocalSSRC(receive_channel_num, ssrc));
1239 EXPECT_EQ(1234U, ssrc);
1240 EXPECT_EQ(1, vie_.GetNumSsrcs(receive_channel_num));
1241}
1242
1243
1244// Test SetOptions with denoising flag.
1245TEST_F(WebRtcVideoEngineTestFake, SetOptionsWithDenoising) {
1246 EXPECT_TRUE(SetupEngine());
1247 EXPECT_EQ(1, vie_.GetNumCapturers());
1248 int channel_num = vie_.GetLastChannel();
1249 int capture_id = vie_.GetCaptureId(channel_num);
1250 // Set send codecs on the channel.
1251 std::vector<cricket::VideoCodec> codecs;
1252 codecs.push_back(kVP8Codec);
1253 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1254
1255 // Set options with OPT_VIDEO_NOISE_REDUCTION flag.
1256 cricket::VideoOptions options;
1257 options.video_noise_reduction.Set(true);
1258 EXPECT_TRUE(channel_->SetOptions(options));
1259
1260 // Verify capture has denoising turned on.
1261 webrtc::VideoCodec send_codec;
1262 memset(&send_codec, 0, sizeof(send_codec)); // avoid uninitialized warning
1263 EXPECT_EQ(0, vie_.GetSendCodec(channel_num, send_codec));
1264 EXPECT_TRUE(send_codec.codecSpecific.VP8.denoisingOn);
1265 EXPECT_FALSE(vie_.GetCaptureDenoising(capture_id));
1266
1267 // Set options back to zero.
1268 options.video_noise_reduction.Set(false);
1269 EXPECT_TRUE(channel_->SetOptions(options));
1270
1271 // Verify capture has denoising turned off.
1272 EXPECT_EQ(0, vie_.GetSendCodec(channel_num, send_codec));
1273 EXPECT_FALSE(send_codec.codecSpecific.VP8.denoisingOn);
1274 EXPECT_FALSE(vie_.GetCaptureDenoising(capture_id));
1275}
1276
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001277// Test disabled because it drops frames when adapt-before-effects is turned
1278// off (turned off because it was exposing a crash - see bug 12250150). This is
1279// safe for now because this test exercises an unused feature.
1280// TODO(tpsiaki) reenable once adapt-before-effects is turned back on.
1281TEST_F(WebRtcVideoEngineTestFake, DISABLED_MultipleSendStreamsWithOneCapturer) {
wu@webrtc.org24301a62013-12-13 19:17:43 +00001282 EXPECT_TRUE(SetupEngine());
1283
1284 // Start the capturer
1285 cricket::FakeVideoCapturer capturer;
1286 cricket::VideoFormat capture_format_vga = cricket::VideoFormat(640, 480,
1287 cricket::VideoFormat::FpsToInterval(30), cricket::FOURCC_I420);
1288 EXPECT_EQ(cricket::CS_RUNNING, capturer.Start(capture_format_vga));
1289
1290 // Add send streams and connect the capturer
1291 for (unsigned int i = 0; i < sizeof(kSsrcs2)/sizeof(kSsrcs2[0]); ++i) {
1292 EXPECT_TRUE(channel_->AddSendStream(
1293 cricket::StreamParams::CreateLegacy(kSsrcs2[i])));
1294 // Register the capturer to the ssrc.
1295 EXPECT_TRUE(channel_->SetCapturer(kSsrcs2[i], &capturer));
1296 }
1297
1298 const int channel0 = vie_.GetChannelFromLocalSsrc(kSsrcs2[0]);
1299 ASSERT_NE(-1, channel0);
1300 const int channel1 = vie_.GetChannelFromLocalSsrc(kSsrcs2[1]);
1301 ASSERT_NE(-1, channel1);
1302 ASSERT_NE(channel0, channel1);
1303
1304 // Set send codec.
1305 std::vector<cricket::VideoCodec> codecs;
1306 cricket::VideoCodec send_codec(100, "VP8", 640, 480, 30, 0);
1307 codecs.push_back(send_codec);
1308 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1309
1310 EXPECT_TRUE(capturer.CaptureFrame());
1311 EXPECT_EQ(1, vie_.GetIncomingFrameNum(channel0));
1312 EXPECT_EQ(1, vie_.GetIncomingFrameNum(channel1));
1313
1314 EXPECT_TRUE(channel_->RemoveSendStream(kSsrcs2[0]));
1315 EXPECT_TRUE(capturer.CaptureFrame());
1316 // channel0 is the default channel, so it won't be deleted.
1317 // But it should be disconnected from the capturer.
1318 EXPECT_EQ(1, vie_.GetIncomingFrameNum(channel0));
1319 EXPECT_EQ(2, vie_.GetIncomingFrameNum(channel1));
1320
1321 EXPECT_TRUE(channel_->RemoveSendStream(kSsrcs2[1]));
1322 EXPECT_TRUE(capturer.CaptureFrame());
1323 EXPECT_EQ(1, vie_.GetIncomingFrameNum(channel0));
1324 // channel1 has already been deleted.
1325 EXPECT_EQ(-1, vie_.GetIncomingFrameNum(channel1));
1326}
1327
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001328
wu@webrtc.org97077a32013-10-25 21:18:33 +00001329// Disabled since its flaky: b/11288120
1330TEST_F(WebRtcVideoEngineTestFake, DISABLED_SendReceiveBitratesStats) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001331 EXPECT_TRUE(SetupEngine());
1332 cricket::VideoOptions options;
1333 options.conference_mode.Set(true);
1334 EXPECT_TRUE(channel_->SetOptions(options));
1335 EXPECT_TRUE(channel_->AddSendStream(
1336 cricket::StreamParams::CreateLegacy(1)));
1337 int send_channel = vie_.GetLastChannel();
1338 cricket::VideoCodec codec(kVP8Codec720p);
1339 std::vector<cricket::VideoCodec> codec_list;
1340 codec_list.push_back(codec);
1341 EXPECT_TRUE(channel_->SetSendCodecs(codec_list));
1342
1343 EXPECT_TRUE(channel_->AddRecvStream(
1344 cricket::StreamParams::CreateLegacy(2)));
1345 int first_receive_channel = vie_.GetLastChannel();
1346 EXPECT_NE(send_channel, first_receive_channel);
1347 EXPECT_TRUE(channel_->AddRecvStream(
1348 cricket::StreamParams::CreateLegacy(3)));
1349 int second_receive_channel = vie_.GetLastChannel();
1350 EXPECT_NE(first_receive_channel, second_receive_channel);
1351
1352 cricket::VideoMediaInfo info;
1353 EXPECT_TRUE(channel_->GetStats(&info));
1354 ASSERT_EQ(1U, info.bw_estimations.size());
1355 ASSERT_EQ(0, info.bw_estimations[0].actual_enc_bitrate);
1356 ASSERT_EQ(0, info.bw_estimations[0].transmit_bitrate);
1357 ASSERT_EQ(0, info.bw_estimations[0].retransmit_bitrate);
1358 ASSERT_EQ(0, info.bw_estimations[0].available_send_bandwidth);
1359 ASSERT_EQ(0, info.bw_estimations[0].available_recv_bandwidth);
1360 ASSERT_EQ(0, info.bw_estimations[0].target_enc_bitrate);
1361
1362 // Start sending and receiving on one of the channels and verify bitrates.
1363 EXPECT_EQ(0, vie_.StartSend(send_channel));
1364 int send_video_bitrate = 800;
1365 int send_fec_bitrate = 100;
1366 int send_nack_bitrate = 20;
1367 int send_total_bitrate = send_video_bitrate + send_fec_bitrate +
1368 send_nack_bitrate;
1369 int send_bandwidth = 950;
1370 vie_.SetSendBitrates(send_channel, send_video_bitrate, send_fec_bitrate,
1371 send_nack_bitrate);
1372 vie_.SetSendBandwidthEstimate(send_channel, send_bandwidth);
1373
1374 EXPECT_EQ(0, vie_.StartReceive(first_receive_channel));
1375 int first_channel_receive_bandwidth = 600;
1376 vie_.SetReceiveBandwidthEstimate(first_receive_channel,
1377 first_channel_receive_bandwidth);
1378
1379 info.Clear();
1380 EXPECT_TRUE(channel_->GetStats(&info));
1381 ASSERT_EQ(1U, info.bw_estimations.size());
1382 ASSERT_EQ(send_video_bitrate, info.bw_estimations[0].actual_enc_bitrate);
1383 ASSERT_EQ(send_total_bitrate, info.bw_estimations[0].transmit_bitrate);
1384 ASSERT_EQ(send_nack_bitrate, info.bw_estimations[0].retransmit_bitrate);
1385 ASSERT_EQ(send_bandwidth, info.bw_estimations[0].available_send_bandwidth);
1386 ASSERT_EQ(first_channel_receive_bandwidth,
1387 info.bw_estimations[0].available_recv_bandwidth);
1388 ASSERT_EQ(send_video_bitrate, info.bw_estimations[0].target_enc_bitrate);
1389
1390 // Start receiving on the second channel and verify received rate.
1391 EXPECT_EQ(0, vie_.StartReceive(second_receive_channel));
1392 int second_channel_receive_bandwidth = 100;
1393 vie_.SetReceiveBandwidthEstimate(second_receive_channel,
1394 second_channel_receive_bandwidth);
1395
1396 info.Clear();
1397 EXPECT_TRUE(channel_->GetStats(&info));
1398 ASSERT_EQ(1U, info.bw_estimations.size());
1399 ASSERT_EQ(send_video_bitrate, info.bw_estimations[0].actual_enc_bitrate);
1400 ASSERT_EQ(send_total_bitrate, info.bw_estimations[0].transmit_bitrate);
1401 ASSERT_EQ(send_nack_bitrate, info.bw_estimations[0].retransmit_bitrate);
1402 ASSERT_EQ(send_bandwidth, info.bw_estimations[0].available_send_bandwidth);
1403 ASSERT_EQ(first_channel_receive_bandwidth + second_channel_receive_bandwidth,
1404 info.bw_estimations[0].available_recv_bandwidth);
1405 ASSERT_EQ(send_video_bitrate, info.bw_estimations[0].target_enc_bitrate);
1406}
1407
1408TEST_F(WebRtcVideoEngineTestFake, TestSetAdaptInputToCpuUsage) {
1409 EXPECT_TRUE(SetupEngine());
1410 cricket::VideoOptions options_in, options_out;
1411 bool cpu_adapt = false;
1412 channel_->SetOptions(options_in);
1413 EXPECT_TRUE(channel_->GetOptions(&options_out));
1414 EXPECT_FALSE(options_out.adapt_input_to_cpu_usage.Get(&cpu_adapt));
1415 // Set adapt input CPU usage option.
1416 options_in.adapt_input_to_cpu_usage.Set(true);
1417 EXPECT_TRUE(channel_->SetOptions(options_in));
1418 EXPECT_TRUE(channel_->GetOptions(&options_out));
1419 EXPECT_TRUE(options_out.adapt_input_to_cpu_usage.Get(&cpu_adapt));
1420 EXPECT_TRUE(cpu_adapt);
1421}
1422
1423TEST_F(WebRtcVideoEngineTestFake, TestSetCpuThreshold) {
1424 EXPECT_TRUE(SetupEngine());
1425 float low, high;
1426 cricket::VideoOptions options_in, options_out;
1427 // Verify that initial values are set.
1428 EXPECT_TRUE(channel_->GetOptions(&options_out));
1429 EXPECT_TRUE(options_out.system_low_adaptation_threshhold.Get(&low));
1430 EXPECT_EQ(low, 0.65f);
1431 EXPECT_TRUE(options_out.system_high_adaptation_threshhold.Get(&high));
1432 EXPECT_EQ(high, 0.85f);
1433 // Set new CPU threshold values.
1434 options_in.system_low_adaptation_threshhold.Set(0.45f);
1435 options_in.system_high_adaptation_threshhold.Set(0.95f);
1436 EXPECT_TRUE(channel_->SetOptions(options_in));
1437 EXPECT_TRUE(channel_->GetOptions(&options_out));
1438 EXPECT_TRUE(options_out.system_low_adaptation_threshhold.Get(&low));
1439 EXPECT_EQ(low, 0.45f);
1440 EXPECT_TRUE(options_out.system_high_adaptation_threshhold.Get(&high));
1441 EXPECT_EQ(high, 0.95f);
1442}
1443
1444TEST_F(WebRtcVideoEngineTestFake, TestSetInvalidCpuThreshold) {
1445 EXPECT_TRUE(SetupEngine());
1446 float low, high;
1447 cricket::VideoOptions options_in, options_out;
1448 // Valid range is [0, 1].
1449 options_in.system_low_adaptation_threshhold.Set(-1.5f);
1450 options_in.system_high_adaptation_threshhold.Set(1.5f);
1451 EXPECT_TRUE(channel_->SetOptions(options_in));
1452 EXPECT_TRUE(channel_->GetOptions(&options_out));
1453 EXPECT_TRUE(options_out.system_low_adaptation_threshhold.Get(&low));
1454 EXPECT_EQ(low, 0.0f);
1455 EXPECT_TRUE(options_out.system_high_adaptation_threshhold.Get(&high));
1456 EXPECT_EQ(high, 1.0f);
1457}
1458
1459
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +00001460TEST_F(WebRtcVideoEngineTestFake, ResetCodecOnScreencast) {
1461 EXPECT_TRUE(SetupEngine());
1462 cricket::VideoOptions options;
1463 options.video_noise_reduction.Set(true);
1464 EXPECT_TRUE(channel_->SetOptions(options));
1465
1466 // Set send codec.
1467 cricket::VideoCodec codec(kVP8Codec);
1468 std::vector<cricket::VideoCodec> codec_list;
1469 codec_list.push_back(codec);
1470 EXPECT_TRUE(channel_->AddSendStream(
1471 cricket::StreamParams::CreateLegacy(123)));
1472 EXPECT_TRUE(channel_->SetSendCodecs(codec_list));
1473 EXPECT_TRUE(channel_->SetSend(true));
1474 EXPECT_EQ(1, vie_.num_set_send_codecs());
1475
1476 webrtc::VideoCodec gcodec;
1477 memset(&gcodec, 0, sizeof(gcodec));
1478 int channel_num = vie_.GetLastChannel();
1479 EXPECT_EQ(0, vie_.GetSendCodec(channel_num, gcodec));
1480 EXPECT_TRUE(gcodec.codecSpecific.VP8.denoisingOn);
1481
1482 // Send a screencast frame with the same size.
1483 // Verify that denoising is turned off.
1484 SendI420ScreencastFrame(kVP8Codec.width, kVP8Codec.height);
1485 EXPECT_EQ(2, vie_.num_set_send_codecs());
1486 EXPECT_EQ(0, vie_.GetSendCodec(channel_num, gcodec));
1487 EXPECT_FALSE(gcodec.codecSpecific.VP8.denoisingOn);
1488}
1489
1490
1491TEST_F(WebRtcVideoEngineTestFake, DontRegisterDecoderIfFactoryIsNotGiven) {
1492 engine_.SetExternalDecoderFactory(NULL);
1493 EXPECT_TRUE(SetupEngine());
1494 int channel_num = vie_.GetLastChannel();
1495
1496 std::vector<cricket::VideoCodec> codecs;
1497 codecs.push_back(kVP8Codec);
1498 EXPECT_TRUE(channel_->SetRecvCodecs(codecs));
1499
1500 EXPECT_EQ(0, vie_.GetNumExternalDecoderRegistered(channel_num));
1501}
1502
1503TEST_F(WebRtcVideoEngineTestFake, RegisterDecoderIfFactoryIsGiven) {
1504 decoder_factory_.AddSupportedVideoCodecType(webrtc::kVideoCodecVP8);
1505 engine_.SetExternalDecoderFactory(&decoder_factory_);
1506 EXPECT_TRUE(SetupEngine());
1507 int channel_num = vie_.GetLastChannel();
1508
1509 std::vector<cricket::VideoCodec> codecs;
1510 codecs.push_back(kVP8Codec);
1511 EXPECT_TRUE(channel_->SetRecvCodecs(codecs));
1512
1513 EXPECT_TRUE(vie_.ExternalDecoderRegistered(channel_num, 100));
1514 EXPECT_EQ(1, vie_.GetNumExternalDecoderRegistered(channel_num));
1515}
1516
1517TEST_F(WebRtcVideoEngineTestFake, DontRegisterDecoderMultipleTimes) {
1518 decoder_factory_.AddSupportedVideoCodecType(webrtc::kVideoCodecVP8);
1519 engine_.SetExternalDecoderFactory(&decoder_factory_);
1520 EXPECT_TRUE(SetupEngine());
1521 int channel_num = vie_.GetLastChannel();
1522
1523 std::vector<cricket::VideoCodec> codecs;
1524 codecs.push_back(kVP8Codec);
1525 EXPECT_TRUE(channel_->SetRecvCodecs(codecs));
1526
1527 EXPECT_TRUE(vie_.ExternalDecoderRegistered(channel_num, 100));
1528 EXPECT_EQ(1, vie_.GetNumExternalDecoderRegistered(channel_num));
1529 EXPECT_EQ(1, decoder_factory_.GetNumCreatedDecoders());
1530
1531 EXPECT_TRUE(channel_->SetRecvCodecs(codecs));
1532 EXPECT_EQ(1, vie_.GetNumExternalDecoderRegistered(channel_num));
1533 EXPECT_EQ(1, decoder_factory_.GetNumCreatedDecoders());
1534}
1535
1536TEST_F(WebRtcVideoEngineTestFake, DontRegisterDecoderForNonVP8) {
1537 decoder_factory_.AddSupportedVideoCodecType(webrtc::kVideoCodecVP8);
1538 engine_.SetExternalDecoderFactory(&decoder_factory_);
1539 EXPECT_TRUE(SetupEngine());
1540 int channel_num = vie_.GetLastChannel();
1541
1542 std::vector<cricket::VideoCodec> codecs;
1543 codecs.push_back(kRedCodec);
1544 EXPECT_TRUE(channel_->SetRecvCodecs(codecs));
1545
1546 EXPECT_EQ(0, vie_.GetNumExternalDecoderRegistered(channel_num));
1547}
1548
1549TEST_F(WebRtcVideoEngineTestFake, DontRegisterEncoderIfFactoryIsNotGiven) {
1550 engine_.SetExternalEncoderFactory(NULL);
1551 EXPECT_TRUE(SetupEngine());
1552 int channel_num = vie_.GetLastChannel();
1553
1554 std::vector<cricket::VideoCodec> codecs;
1555 codecs.push_back(kVP8Codec);
1556 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1557
1558 EXPECT_EQ(0, vie_.GetNumExternalEncoderRegistered(channel_num));
1559}
1560
1561TEST_F(WebRtcVideoEngineTestFake, RegisterEncoderIfFactoryIsGiven) {
1562 encoder_factory_.AddSupportedVideoCodecType(webrtc::kVideoCodecVP8, "VP8");
1563 engine_.SetExternalEncoderFactory(&encoder_factory_);
1564 EXPECT_TRUE(SetupEngine());
1565 int channel_num = vie_.GetLastChannel();
1566
1567 std::vector<cricket::VideoCodec> codecs;
1568 codecs.push_back(kVP8Codec);
1569 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1570
1571 EXPECT_TRUE(channel_->AddSendStream(
1572 cricket::StreamParams::CreateLegacy(kSsrc)));
1573
1574 EXPECT_TRUE(vie_.ExternalEncoderRegistered(channel_num, 100));
1575 EXPECT_EQ(1, vie_.GetNumExternalEncoderRegistered(channel_num));
1576
1577 // Remove stream previously added to free the external encoder instance.
1578 EXPECT_TRUE(channel_->RemoveSendStream(kSsrc));
1579}
1580
1581TEST_F(WebRtcVideoEngineTestFake, DontRegisterEncoderMultipleTimes) {
1582 encoder_factory_.AddSupportedVideoCodecType(webrtc::kVideoCodecVP8, "VP8");
1583 engine_.SetExternalEncoderFactory(&encoder_factory_);
1584 EXPECT_TRUE(SetupEngine());
1585 int channel_num = vie_.GetLastChannel();
1586
1587 std::vector<cricket::VideoCodec> codecs;
1588 codecs.push_back(kVP8Codec);
1589 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1590
1591 EXPECT_TRUE(channel_->AddSendStream(
1592 cricket::StreamParams::CreateLegacy(kSsrc)));
1593
1594 EXPECT_TRUE(vie_.ExternalEncoderRegistered(channel_num, 100));
1595 EXPECT_EQ(1, vie_.GetNumExternalEncoderRegistered(channel_num));
1596 EXPECT_EQ(1, encoder_factory_.GetNumCreatedEncoders());
1597
1598 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1599 EXPECT_EQ(1, vie_.GetNumExternalEncoderRegistered(channel_num));
1600 EXPECT_EQ(1, encoder_factory_.GetNumCreatedEncoders());
1601
1602 // Remove stream previously added to free the external encoder instance.
1603 EXPECT_TRUE(channel_->RemoveSendStream(kSsrc));
1604}
1605
1606TEST_F(WebRtcVideoEngineTestFake, RegisterEncoderWithMultipleSendStreams) {
1607 encoder_factory_.AddSupportedVideoCodecType(webrtc::kVideoCodecVP8, "VP8");
1608 engine_.SetExternalEncoderFactory(&encoder_factory_);
1609 EXPECT_TRUE(SetupEngine());
1610
1611 std::vector<cricket::VideoCodec> codecs;
1612 codecs.push_back(kVP8Codec);
1613 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1614 EXPECT_EQ(1, vie_.GetTotalNumExternalEncoderRegistered());
1615
1616 // When we add the first stream (1234), it reuses the default send channel,
1617 // so it doesn't increase the registration count of external encoders.
1618 EXPECT_TRUE(channel_->AddSendStream(
1619 cricket::StreamParams::CreateLegacy(1234)));
1620 EXPECT_EQ(1, vie_.GetTotalNumExternalEncoderRegistered());
1621
1622 // When we add the second stream (2345), it creates a new channel and
1623 // increments the registration count.
1624 EXPECT_TRUE(channel_->AddSendStream(
1625 cricket::StreamParams::CreateLegacy(2345)));
1626 EXPECT_EQ(2, vie_.GetTotalNumExternalEncoderRegistered());
1627
1628 // At this moment the total registration count is two, but only one encoder
1629 // is registered per channel.
1630 int channel_num = vie_.GetLastChannel();
1631 EXPECT_EQ(1, vie_.GetNumExternalEncoderRegistered(channel_num));
1632
1633 // Removing send streams decrements the registration count.
1634 EXPECT_TRUE(channel_->RemoveSendStream(1234));
1635 EXPECT_EQ(1, vie_.GetTotalNumExternalEncoderRegistered());
1636
1637 // When we remove the last send stream, it also destroys the last send
1638 // channel and causes the registration count to drop to zero. It is a little
1639 // weird, but not a bug.
1640 EXPECT_TRUE(channel_->RemoveSendStream(2345));
1641 EXPECT_EQ(0, vie_.GetTotalNumExternalEncoderRegistered());
1642}
1643
1644TEST_F(WebRtcVideoEngineTestFake, DontRegisterEncoderForNonVP8) {
1645 encoder_factory_.AddSupportedVideoCodecType(webrtc::kVideoCodecGeneric,
1646 "GENERIC");
1647 engine_.SetExternalEncoderFactory(&encoder_factory_);
1648 EXPECT_TRUE(SetupEngine());
1649 int channel_num = vie_.GetLastChannel();
1650
1651 // Note: unlike the SetRecvCodecs, we must set a valid video codec for
1652 // channel_->SetSendCodecs() to succeed.
1653 std::vector<cricket::VideoCodec> codecs;
1654 codecs.push_back(kVP8Codec);
1655 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1656
1657 EXPECT_EQ(0, vie_.GetNumExternalEncoderRegistered(channel_num));
1658}
1659
1660// Test that NACK, PLI and REMB are enabled for external codec.
1661TEST_F(WebRtcVideoEngineTestFake, ExternalCodecFeedbackParams) {
1662 encoder_factory_.AddSupportedVideoCodecType(webrtc::kVideoCodecGeneric,
1663 "GENERIC");
1664 engine_.SetExternalEncoderFactory(&encoder_factory_);
1665 encoder_factory_.NotifyCodecsAvailable();
1666 EXPECT_TRUE(SetupEngine());
1667
1668 std::vector<cricket::VideoCodec> codecs(engine_.codecs());
1669 // The external codec will appear at last.
1670 size_t pos = codecs.size() - 1;
1671 EXPECT_EQ("GENERIC", codecs[pos].name);
1672 VerifyCodecFeedbackParams(codecs[pos]);
1673}
1674
1675// Test external codec with be added to the end of the supported codec list.
1676TEST_F(WebRtcVideoEngineTestFake, ExternalCodecAddedToTheEnd) {
1677 EXPECT_TRUE(SetupEngine());
1678
1679 std::vector<cricket::VideoCodec> codecs(engine_.codecs());
1680 EXPECT_EQ("VP8", codecs[0].name);
1681
1682 encoder_factory_.AddSupportedVideoCodecType(webrtc::kVideoCodecGeneric,
1683 "GENERIC");
1684 engine_.SetExternalEncoderFactory(&encoder_factory_);
1685 encoder_factory_.NotifyCodecsAvailable();
1686
1687 codecs = engine_.codecs();
1688 cricket::VideoCodec internal_codec = codecs[0];
1689 cricket::VideoCodec external_codec = codecs[codecs.size() - 1];
1690 // The external codec will appear at last.
1691 EXPECT_EQ("GENERIC", external_codec.name);
1692 // The internal codec is preferred.
1693 EXPECT_GE(internal_codec.preference, external_codec.preference);
1694}
1695
1696// Test that external codec with be ignored if it has the same name as one of
1697// the internal codecs.
1698TEST_F(WebRtcVideoEngineTestFake, ExternalCodecIgnored) {
1699 EXPECT_TRUE(SetupEngine());
1700
1701 std::vector<cricket::VideoCodec> internal_codecs(engine_.codecs());
1702 EXPECT_EQ("VP8", internal_codecs[0].name);
1703
1704 encoder_factory_.AddSupportedVideoCodecType(webrtc::kVideoCodecVP8, "VP8");
1705 engine_.SetExternalEncoderFactory(&encoder_factory_);
1706 encoder_factory_.NotifyCodecsAvailable();
1707
1708 std::vector<cricket::VideoCodec> codecs = engine_.codecs();
1709 EXPECT_EQ("VP8", codecs[0].name);
1710 EXPECT_EQ(internal_codecs[0].height, codecs[0].height);
1711 EXPECT_EQ(internal_codecs[0].width, codecs[0].width);
1712 // Verify the last codec is not the external codec.
1713 EXPECT_NE("VP8", codecs[codecs.size() - 1].name);
1714}
1715
1716TEST_F(WebRtcVideoEngineTestFake, UpdateEncoderCodecsAfterSetFactory) {
1717 engine_.SetExternalEncoderFactory(&encoder_factory_);
1718 EXPECT_TRUE(SetupEngine());
1719 int channel_num = vie_.GetLastChannel();
1720
1721 encoder_factory_.AddSupportedVideoCodecType(webrtc::kVideoCodecVP8, "VP8");
1722 encoder_factory_.NotifyCodecsAvailable();
1723 std::vector<cricket::VideoCodec> codecs;
1724 codecs.push_back(kVP8Codec);
1725 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1726
1727 EXPECT_TRUE(channel_->AddSendStream(
1728 cricket::StreamParams::CreateLegacy(kSsrc)));
1729
1730 EXPECT_TRUE(vie_.ExternalEncoderRegistered(channel_num, 100));
1731 EXPECT_EQ(1, vie_.GetNumExternalEncoderRegistered(channel_num));
1732 EXPECT_EQ(1, encoder_factory_.GetNumCreatedEncoders());
1733
1734 // Remove stream previously added to free the external encoder instance.
1735 EXPECT_TRUE(channel_->RemoveSendStream(kSsrc));
1736}
1737
1738// Tests that OnReadyToSend will be propagated into ViE.
1739TEST_F(WebRtcVideoEngineTestFake, OnReadyToSend) {
1740 EXPECT_TRUE(SetupEngine());
1741 int channel_num = vie_.GetLastChannel();
1742 EXPECT_TRUE(vie_.GetIsTransmitting(channel_num));
1743
1744 channel_->OnReadyToSend(false);
1745 EXPECT_FALSE(vie_.GetIsTransmitting(channel_num));
1746
1747 channel_->OnReadyToSend(true);
1748 EXPECT_TRUE(vie_.GetIsTransmitting(channel_num));
1749}
1750
1751#if 0
1752TEST_F(WebRtcVideoEngineTestFake, CaptureFrameTimestampToNtpTimestamp) {
1753 EXPECT_TRUE(SetupEngine());
1754 int capture_id = vie_.GetCaptureId(vie_.GetLastChannel());
1755
1756 // Set send codec.
1757 cricket::VideoCodec codec(kVP8Codec);
1758 std::vector<cricket::VideoCodec> codec_list;
1759 codec_list.push_back(codec);
1760 EXPECT_TRUE(channel_->AddSendStream(
1761 cricket::StreamParams::CreateLegacy(123)));
1762 EXPECT_TRUE(channel_->SetSendCodecs(codec_list));
1763 EXPECT_TRUE(channel_->SetSend(true));
1764
1765 int64 timestamp = time(NULL) * talk_base::kNumNanosecsPerSec;
1766 SendI420ScreencastFrameWithTimestamp(
1767 kVP8Codec.width, kVP8Codec.height, timestamp);
1768 EXPECT_EQ(talk_base::UnixTimestampNanosecsToNtpMillisecs(timestamp),
1769 vie_.GetCaptureLastTimestamp(capture_id));
1770
1771 SendI420ScreencastFrameWithTimestamp(kVP8Codec.width, kVP8Codec.height, 0);
1772 EXPECT_EQ(0, vie_.GetCaptureLastTimestamp(capture_id));
1773}
1774#endif
1775
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001776/////////////////////////
1777// Tests with real ViE //
1778/////////////////////////
1779
1780// Tests that we can find codecs by name or id.
1781TEST_F(WebRtcVideoEngineTest, FindCodec) {
1782 // We should not need to init engine in order to get codecs.
1783 const std::vector<cricket::VideoCodec>& c = engine_.codecs();
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +00001784 EXPECT_EQ(4U, c.size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001785
1786 cricket::VideoCodec vp8(104, "VP8", 320, 200, 30, 0);
1787 EXPECT_TRUE(engine_.FindCodec(vp8));
1788
1789 cricket::VideoCodec vp8_ci(104, "vp8", 320, 200, 30, 0);
1790 EXPECT_TRUE(engine_.FindCodec(vp8));
1791
1792 cricket::VideoCodec vp8_diff_fr_diff_pref(104, "VP8", 320, 200, 50, 50);
1793 EXPECT_TRUE(engine_.FindCodec(vp8_diff_fr_diff_pref));
1794
1795 cricket::VideoCodec vp8_diff_id(95, "VP8", 320, 200, 30, 0);
1796 EXPECT_FALSE(engine_.FindCodec(vp8_diff_id));
1797 vp8_diff_id.id = 97;
1798 EXPECT_TRUE(engine_.FindCodec(vp8_diff_id));
1799
1800 cricket::VideoCodec vp8_diff_res(104, "VP8", 320, 111, 30, 0);
1801 EXPECT_FALSE(engine_.FindCodec(vp8_diff_res));
1802
1803 // PeerConnection doesn't negotiate the resolution at this point.
1804 // Test that FindCodec can handle the case when width/height is 0.
1805 cricket::VideoCodec vp8_zero_res(104, "VP8", 0, 0, 30, 0);
1806 EXPECT_TRUE(engine_.FindCodec(vp8_zero_res));
1807
1808 cricket::VideoCodec red(101, "RED", 0, 0, 30, 0);
1809 EXPECT_TRUE(engine_.FindCodec(red));
1810
1811 cricket::VideoCodec red_ci(101, "red", 0, 0, 30, 0);
1812 EXPECT_TRUE(engine_.FindCodec(red));
1813
1814 cricket::VideoCodec fec(102, "ULPFEC", 0, 0, 30, 0);
1815 EXPECT_TRUE(engine_.FindCodec(fec));
1816
1817 cricket::VideoCodec fec_ci(102, "ulpfec", 0, 0, 30, 0);
1818 EXPECT_TRUE(engine_.FindCodec(fec));
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +00001819
1820 cricket::VideoCodec rtx(96, "rtx", 0, 0, 30, 0);
1821 EXPECT_TRUE(engine_.FindCodec(rtx));
1822}
1823
1824TEST_F(WebRtcVideoEngineTest, RtxCodecHasAptSet) {
1825 std::vector<cricket::VideoCodec>::const_iterator it;
1826 bool apt_checked = false;
1827 for (it = engine_.codecs().begin(); it != engine_.codecs().end(); ++it) {
1828 if (_stricmp(cricket::kRtxCodecName, it->name.c_str()) && it->id != 96) {
1829 continue;
1830 }
1831 int apt;
1832 EXPECT_TRUE(it->GetParam("apt", &apt));
1833 EXPECT_EQ(100, apt);
1834 apt_checked = true;
1835 }
1836 EXPECT_TRUE(apt_checked);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001837}
1838
1839TEST_F(WebRtcVideoEngineTest, StartupShutdown) {
1840 EXPECT_TRUE(engine_.Init(talk_base::Thread::Current()));
1841 engine_.Terminate();
1842}
1843
1844TEST_PRE_VIDEOENGINE_INIT(WebRtcVideoEngineTest, ConstrainNewCodec)
1845TEST_POST_VIDEOENGINE_INIT(WebRtcVideoEngineTest, ConstrainNewCodec)
1846
1847TEST_PRE_VIDEOENGINE_INIT(WebRtcVideoEngineTest, ConstrainRunningCodec)
1848TEST_POST_VIDEOENGINE_INIT(WebRtcVideoEngineTest, ConstrainRunningCodec)
1849
1850// TODO(juberti): Figure out why ViE is munging the COM refcount.
1851#ifdef WIN32
1852TEST_F(WebRtcVideoEngineTest, DISABLED_CheckCoInitialize) {
1853 Base::CheckCoInitialize();
1854}
1855#endif
1856
1857TEST_F(WebRtcVideoEngineTest, CreateChannel) {
1858 EXPECT_TRUE(engine_.Init(talk_base::Thread::Current()));
1859 cricket::VideoMediaChannel* channel = engine_.CreateChannel(NULL);
1860 EXPECT_TRUE(channel != NULL);
1861 delete channel;
1862}
1863
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001864TEST_F(WebRtcVideoMediaChannelTest, SetRecvCodecs) {
1865 std::vector<cricket::VideoCodec> codecs;
1866 codecs.push_back(kVP8Codec);
1867 EXPECT_TRUE(channel_->SetRecvCodecs(codecs));
1868}
1869TEST_F(WebRtcVideoMediaChannelTest, SetRecvCodecsWrongPayloadType) {
1870 std::vector<cricket::VideoCodec> codecs;
1871 codecs.push_back(kVP8Codec);
1872 codecs[0].id = 99;
1873 EXPECT_TRUE(channel_->SetRecvCodecs(codecs));
1874}
1875TEST_F(WebRtcVideoMediaChannelTest, SetRecvCodecsUnsupportedCodec) {
1876 std::vector<cricket::VideoCodec> codecs;
1877 codecs.push_back(kVP8Codec);
1878 codecs.push_back(cricket::VideoCodec(101, "VP1", 640, 400, 30, 0));
1879 EXPECT_FALSE(channel_->SetRecvCodecs(codecs));
1880}
1881
1882TEST_F(WebRtcVideoMediaChannelTest, SetSend) {
1883 Base::SetSend();
1884}
1885TEST_F(WebRtcVideoMediaChannelTest, SetSendWithoutCodecs) {
1886 Base::SetSendWithoutCodecs();
1887}
1888TEST_F(WebRtcVideoMediaChannelTest, SetSendSetsTransportBufferSizes) {
1889 Base::SetSendSetsTransportBufferSizes();
1890}
1891
1892TEST_F(WebRtcVideoMediaChannelTest, SendAndReceiveVp8Vga) {
1893 SendAndReceive(cricket::VideoCodec(100, "VP8", 640, 400, 30, 0));
1894}
1895TEST_F(WebRtcVideoMediaChannelTest, SendAndReceiveVp8Qvga) {
1896 SendAndReceive(cricket::VideoCodec(100, "VP8", 320, 200, 30, 0));
1897}
1898TEST_F(WebRtcVideoMediaChannelTest, SendAndReceiveH264SvcQqvga) {
1899 SendAndReceive(cricket::VideoCodec(100, "VP8", 160, 100, 30, 0));
1900}
1901TEST_F(WebRtcVideoMediaChannelTest, SendManyResizeOnce) {
1902 SendManyResizeOnce();
1903}
1904
1905TEST_F(WebRtcVideoMediaChannelTest, SendVp8HdAndReceiveAdaptedVp8Vga) {
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00001906 EXPECT_TRUE(channel_->SetCapturer(kSsrc, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001907 channel_->UpdateAspectRatio(1280, 720);
1908 video_capturer_.reset(new cricket::FakeVideoCapturer);
1909 const std::vector<cricket::VideoFormat>* formats =
1910 video_capturer_->GetSupportedFormats();
1911 cricket::VideoFormat capture_format_hd = (*formats)[0];
1912 EXPECT_EQ(cricket::CS_RUNNING, video_capturer_->Start(capture_format_hd));
1913 EXPECT_TRUE(channel_->SetCapturer(kSsrc, video_capturer_.get()));
1914
1915 // Capture format HD -> adapt (OnOutputFormatRequest VGA) -> VGA.
1916 cricket::VideoCodec codec(100, "VP8", 1280, 720, 30, 0);
1917 EXPECT_TRUE(SetOneCodec(codec));
1918 codec.width /= 2;
1919 codec.height /= 2;
1920 EXPECT_TRUE(channel_->SetSendStreamFormat(kSsrc, cricket::VideoFormat(
1921 codec.width, codec.height,
1922 cricket::VideoFormat::FpsToInterval(codec.framerate),
1923 cricket::FOURCC_ANY)));
1924 EXPECT_TRUE(SetSend(true));
1925 EXPECT_TRUE(channel_->SetRender(true));
1926 EXPECT_EQ(0, renderer_.num_rendered_frames());
1927 EXPECT_TRUE(SendFrame());
1928 EXPECT_FRAME_WAIT(1, codec.width, codec.height, kTimeout);
1929}
1930
1931// TODO(juberti): Fix this test to tolerate missing stats.
1932TEST_F(WebRtcVideoMediaChannelTest, DISABLED_GetStats) {
1933 Base::GetStats();
1934}
1935
1936// TODO(juberti): Fix this test to tolerate missing stats.
1937TEST_F(WebRtcVideoMediaChannelTest, DISABLED_GetStatsMultipleRecvStreams) {
1938 Base::GetStatsMultipleRecvStreams();
1939}
1940
1941TEST_F(WebRtcVideoMediaChannelTest, GetStatsMultipleSendStreams) {
1942 Base::GetStatsMultipleSendStreams();
1943}
1944
1945TEST_F(WebRtcVideoMediaChannelTest, SetSendBandwidth) {
1946 Base::SetSendBandwidth();
1947}
1948TEST_F(WebRtcVideoMediaChannelTest, SetSendSsrc) {
1949 Base::SetSendSsrc();
1950}
1951TEST_F(WebRtcVideoMediaChannelTest, SetSendSsrcAfterSetCodecs) {
1952 Base::SetSendSsrcAfterSetCodecs();
1953}
1954
1955TEST_F(WebRtcVideoMediaChannelTest, SetRenderer) {
1956 Base::SetRenderer();
1957}
1958
1959TEST_F(WebRtcVideoMediaChannelTest, AddRemoveRecvStreams) {
1960 Base::AddRemoveRecvStreams();
1961}
1962
1963TEST_F(WebRtcVideoMediaChannelTest, AddRemoveRecvStreamAndRender) {
1964 Base::AddRemoveRecvStreamAndRender();
1965}
1966
1967TEST_F(WebRtcVideoMediaChannelTest, AddRemoveRecvStreamsNoConference) {
1968 Base::AddRemoveRecvStreamsNoConference();
1969}
1970
1971TEST_F(WebRtcVideoMediaChannelTest, AddRemoveSendStreams) {
1972 Base::AddRemoveSendStreams();
1973}
1974
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001975TEST_F(WebRtcVideoMediaChannelTest, SimulateConference) {
1976 Base::SimulateConference();
1977}
1978
1979TEST_F(WebRtcVideoMediaChannelTest, AddRemoveCapturer) {
1980 Base::AddRemoveCapturer();
1981}
1982
1983TEST_F(WebRtcVideoMediaChannelTest, RemoveCapturerWithoutAdd) {
1984 Base::RemoveCapturerWithoutAdd();
1985}
1986
1987TEST_F(WebRtcVideoMediaChannelTest, AddRemoveCapturerMultipleSources) {
1988 Base::AddRemoveCapturerMultipleSources();
1989}
1990
wu@webrtc.orgde305012013-10-31 15:40:38 +00001991// This test verifies DSCP settings are properly applied on video media channel.
1992TEST_F(WebRtcVideoMediaChannelTest, TestSetDscpOptions) {
1993 talk_base::scoped_ptr<cricket::FakeNetworkInterface> network_interface(
1994 new cricket::FakeNetworkInterface);
1995 channel_->SetInterface(network_interface.get());
1996 cricket::VideoOptions options;
1997 options.dscp.Set(true);
1998 EXPECT_TRUE(channel_->SetOptions(options));
1999 EXPECT_EQ(talk_base::DSCP_AF41, network_interface->dscp());
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +00002000 // Verify previous value is not modified if dscp option is not set.
2001 cricket::VideoOptions options1;
2002 EXPECT_TRUE(channel_->SetOptions(options1));
2003 EXPECT_EQ(talk_base::DSCP_AF41, network_interface->dscp());
wu@webrtc.orgde305012013-10-31 15:40:38 +00002004 options.dscp.Set(false);
2005 EXPECT_TRUE(channel_->SetOptions(options));
2006 EXPECT_EQ(talk_base::DSCP_DEFAULT, network_interface->dscp());
2007 channel_->SetInterface(NULL);
2008}
2009
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002010
2011TEST_F(WebRtcVideoMediaChannelTest, SetOptionsSucceedsWhenSending) {
2012 cricket::VideoOptions options;
2013 options.conference_mode.Set(true);
2014 EXPECT_TRUE(channel_->SetOptions(options));
2015
2016 // Verify SetOptions returns true on a different options.
2017 cricket::VideoOptions options2;
2018 options2.adapt_input_to_cpu_usage.Set(true);
2019 EXPECT_TRUE(channel_->SetOptions(options2));
2020
2021 // Set send codecs on the channel and start sending.
2022 std::vector<cricket::VideoCodec> codecs;
2023 codecs.push_back(kVP8Codec);
2024 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
2025 EXPECT_TRUE(channel_->SetSend(true));
2026
2027 // Verify SetOptions returns true if channel is already sending.
2028 cricket::VideoOptions options3;
2029 options3.conference_mode.Set(true);
2030 EXPECT_TRUE(channel_->SetOptions(options3));
2031}
2032
2033// Tests empty StreamParams is rejected.
2034TEST_F(WebRtcVideoMediaChannelTest, RejectEmptyStreamParams) {
2035 Base::RejectEmptyStreamParams();
2036}
2037
2038
2039TEST_F(WebRtcVideoMediaChannelTest, AdaptResolution16x10) {
2040 Base::AdaptResolution16x10();
2041}
2042
2043TEST_F(WebRtcVideoMediaChannelTest, AdaptResolution4x3) {
2044 Base::AdaptResolution4x3();
2045}
2046
2047TEST_F(WebRtcVideoMediaChannelTest, MuteStream) {
2048 Base::MuteStream();
2049}
2050
2051TEST_F(WebRtcVideoMediaChannelTest, MultipleSendStreams) {
2052 Base::MultipleSendStreams();
2053}
2054
2055// TODO(juberti): Restore this test once we support sending 0 fps.
2056TEST_F(WebRtcVideoMediaChannelTest, DISABLED_AdaptDropAllFrames) {
2057 Base::AdaptDropAllFrames();
2058}
2059// TODO(juberti): Understand why we get decode errors on this test.
2060TEST_F(WebRtcVideoMediaChannelTest, DISABLED_AdaptFramerate) {
2061 Base::AdaptFramerate();
2062}
2063
2064TEST_F(WebRtcVideoMediaChannelTest, SetSendStreamFormat0x0) {
2065 Base::SetSendStreamFormat0x0();
2066}
2067
2068// TODO(zhurunz): Fix the flakey test.
2069TEST_F(WebRtcVideoMediaChannelTest, DISABLED_SetSendStreamFormat) {
2070 Base::SetSendStreamFormat();
2071}
2072
2073TEST_F(WebRtcVideoMediaChannelTest, TwoStreamsSendAndReceive) {
2074 Base::TwoStreamsSendAndReceive(cricket::VideoCodec(100, "VP8", 640, 400, 30,
2075 0));
2076}
2077
2078TEST_F(WebRtcVideoMediaChannelTest, TwoStreamsReUseFirstStream) {
2079 Base::TwoStreamsReUseFirstStream(cricket::VideoCodec(100, "VP8", 640, 400, 30,
2080 0));
2081}