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