blob: b2123f9b9fda44b07c0a6c5b0e38d8cf9ce020e4 [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.orgf7d501d2014-03-27 23:48:25 +0000131 channel_->SendFrame(&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.orgf7d501d2014-03-27 23:48:25 +0000148 channel_->SendFrame(&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));
wu@webrtc.org05e7b442014-04-01 17:44:24 +0000316 EXPECT_EQ(1, vie_.GetNumSetSendCodecs());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000317 // TODO(juberti): Check RTCP, PLI, TMMBR.
318}
319
wu@webrtc.org05e7b442014-04-01 17:44:24 +0000320// Test that ViE Channel doesn't call SetSendCodec again if same codec is tried
321// to apply.
322TEST_F(WebRtcVideoEngineTestFake, DontResetSetSendCodec) {
323 EXPECT_TRUE(SetupEngine());
324 int channel_num = vie_.GetLastChannel();
325 std::vector<cricket::VideoCodec> codecs(engine_.codecs());
326 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
327 VerifyVP8SendCodec(channel_num, kVP8Codec.width, kVP8Codec.height);
328 EXPECT_TRUE(vie_.GetHybridNackFecStatus(channel_num));
329 EXPECT_FALSE(vie_.GetNackStatus(channel_num));
330 EXPECT_EQ(1, vie_.GetNumSetSendCodecs());
331 // Try setting same code again.
332 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
333 // Since it's exact same codec which is already set, media channel shouldn't
334 // send the codec to ViE.
335 EXPECT_EQ(1, vie_.GetNumSetSendCodecs());
336}
337
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000338TEST_F(WebRtcVideoEngineTestFake, SetSendCodecsWithMinMaxBitrate) {
339 EXPECT_TRUE(SetupEngine());
340 int channel_num = vie_.GetLastChannel();
341 std::vector<cricket::VideoCodec> codecs(engine_.codecs());
342 codecs[0].params[cricket::kCodecParamMinBitrate] = "10";
343 codecs[0].params[cricket::kCodecParamMaxBitrate] = "20";
344 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
345
346 VerifyVP8SendCodec(
347 channel_num, kVP8Codec.width, kVP8Codec.height, 0, 20, 10, 20);
348
349 cricket::VideoCodec codec;
350 EXPECT_TRUE(channel_->GetSendCodec(&codec));
351 EXPECT_EQ("10", codec.params[cricket::kCodecParamMinBitrate]);
352 EXPECT_EQ("20", codec.params[cricket::kCodecParamMaxBitrate]);
353}
354
355TEST_F(WebRtcVideoEngineTestFake, SetSendCodecsWithMinMaxBitrateInvalid) {
356 EXPECT_TRUE(SetupEngine());
357 std::vector<cricket::VideoCodec> codecs(engine_.codecs());
358 codecs[0].params[cricket::kCodecParamMinBitrate] = "30";
359 codecs[0].params[cricket::kCodecParamMaxBitrate] = "20";
360 EXPECT_FALSE(channel_->SetSendCodecs(codecs));
361}
362
363TEST_F(WebRtcVideoEngineTestFake, SetSendCodecsWithLargeMinMaxBitrate) {
364 EXPECT_TRUE(SetupEngine());
365 int channel_num = vie_.GetLastChannel();
366 std::vector<cricket::VideoCodec> codecs(engine_.codecs());
367 codecs[0].params[cricket::kCodecParamMinBitrate] = "1000";
368 codecs[0].params[cricket::kCodecParamMaxBitrate] = "2000";
369 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
370
371 VerifyVP8SendCodec(
372 channel_num, kVP8Codec.width, kVP8Codec.height, 0, 2000, 1000,
373 1000);
374}
375
376TEST_F(WebRtcVideoEngineTestFake, SetSendCodecsWithMaxQuantization) {
377 EXPECT_TRUE(SetupEngine());
378 int channel_num = vie_.GetLastChannel();
379 std::vector<cricket::VideoCodec> codecs(engine_.codecs());
380 codecs[0].params[cricket::kCodecParamMaxQuantization] = "21";
381 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
382
383 VerifyVP8SendCodec(
384 channel_num, kVP8Codec.width, kVP8Codec.height, 0, 2000, 50, 300,
385 30, 21);
386
387 cricket::VideoCodec codec;
388 EXPECT_TRUE(channel_->GetSendCodec(&codec));
389 EXPECT_EQ("21", codec.params[cricket::kCodecParamMaxQuantization]);
390}
391
392TEST_F(WebRtcVideoEngineTestFake, SetOptionsWithMaxBitrate) {
393 EXPECT_TRUE(SetupEngine());
394 int channel_num = vie_.GetLastChannel();
395 std::vector<cricket::VideoCodec> codecs(engine_.codecs());
396 codecs[0].params[cricket::kCodecParamMinBitrate] = "10";
397 codecs[0].params[cricket::kCodecParamMaxBitrate] = "20";
398 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
399
400 VerifyVP8SendCodec(
401 channel_num, kVP8Codec.width, kVP8Codec.height, 0, 20, 10, 20);
402
403 // Verify that max bitrate doesn't change after SetOptions().
404 cricket::VideoOptions options;
405 options.video_noise_reduction.Set(true);
406 EXPECT_TRUE(channel_->SetOptions(options));
407 VerifyVP8SendCodec(
408 channel_num, kVP8Codec.width, kVP8Codec.height, 0, 20, 10, 20);
409
410 options.video_noise_reduction.Set(false);
411 options.conference_mode.Set(false);
412 EXPECT_TRUE(channel_->SetOptions(options));
413 VerifyVP8SendCodec(
414 channel_num, kVP8Codec.width, kVP8Codec.height, 0, 20, 10, 20);
415}
416
wu@webrtc.orgcecfd182013-10-30 05:18:12 +0000417TEST_F(WebRtcVideoEngineTestFake, SetOptionsWithLoweredBitrate) {
418 EXPECT_TRUE(SetupEngine());
419 int channel_num = vie_.GetLastChannel();
420 std::vector<cricket::VideoCodec> codecs(engine_.codecs());
421 codecs[0].params[cricket::kCodecParamMinBitrate] = "50";
422 codecs[0].params[cricket::kCodecParamMaxBitrate] = "100";
423 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
424
425 VerifyVP8SendCodec(
426 channel_num, kVP8Codec.width, kVP8Codec.height, 0, 100, 50, 100);
427
428 // Verify that min bitrate changes after SetOptions().
429 cricket::VideoOptions options;
430 options.lower_min_bitrate.Set(true);
431 EXPECT_TRUE(channel_->SetOptions(options));
432 VerifyVP8SendCodec(
433 channel_num, kVP8Codec.width, kVP8Codec.height, 0, 100, 30, 100);
434}
435
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000436TEST_F(WebRtcVideoEngineTestFake, MaxBitrateResetWithConferenceMode) {
437 EXPECT_TRUE(SetupEngine());
438 int channel_num = vie_.GetLastChannel();
439 std::vector<cricket::VideoCodec> codecs(engine_.codecs());
440 codecs[0].params[cricket::kCodecParamMinBitrate] = "10";
441 codecs[0].params[cricket::kCodecParamMaxBitrate] = "20";
442 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
443
444 VerifyVP8SendCodec(
445 channel_num, kVP8Codec.width, kVP8Codec.height, 0, 20, 10, 20);
446
447 cricket::VideoOptions options;
448 options.conference_mode.Set(true);
449 EXPECT_TRUE(channel_->SetOptions(options));
450 options.conference_mode.Set(false);
451 EXPECT_TRUE(channel_->SetOptions(options));
452 VerifyVP8SendCodec(
453 channel_num, kVP8Codec.width, kVP8Codec.height, 0,
454 kMaxBandwidthKbps, 10, 20);
455}
456
457// Verify the current send bitrate is used as start bitrate when reconfiguring
458// the send codec.
459TEST_F(WebRtcVideoEngineTestFake, StartSendBitrate) {
460 EXPECT_TRUE(SetupEngine());
461 EXPECT_TRUE(channel_->AddSendStream(
462 cricket::StreamParams::CreateLegacy(1)));
463 int send_channel = vie_.GetLastChannel();
464 cricket::VideoCodec codec(kVP8Codec);
465 std::vector<cricket::VideoCodec> codec_list;
466 codec_list.push_back(codec);
467 EXPECT_TRUE(channel_->SetSendCodecs(codec_list));
468 const unsigned int kVideoMaxSendBitrateKbps = 2000;
469 const unsigned int kVideoMinSendBitrateKbps = 50;
470 const unsigned int kVideoDefaultStartSendBitrateKbps = 300;
471 VerifyVP8SendCodec(send_channel, kVP8Codec.width, kVP8Codec.height, 0,
472 kVideoMaxSendBitrateKbps, kVideoMinSendBitrateKbps,
473 kVideoDefaultStartSendBitrateKbps);
474 EXPECT_EQ(0, vie_.StartSend(send_channel));
475
476 // Increase the send bitrate and verify it is used as start bitrate.
477 const unsigned int kVideoSendBitrateBps = 768000;
478 vie_.SetSendBitrates(send_channel, kVideoSendBitrateBps, 0, 0);
479 EXPECT_TRUE(channel_->SetSendCodecs(codec_list));
480 VerifyVP8SendCodec(send_channel, kVP8Codec.width, kVP8Codec.height, 0,
481 kVideoMaxSendBitrateKbps, kVideoMinSendBitrateKbps,
482 kVideoSendBitrateBps / 1000);
483
484 // Never set a start bitrate higher than the max bitrate.
485 vie_.SetSendBitrates(send_channel, kVideoMaxSendBitrateKbps + 500, 0, 0);
486 EXPECT_TRUE(channel_->SetSendCodecs(codec_list));
487 VerifyVP8SendCodec(send_channel, kVP8Codec.width, kVP8Codec.height, 0,
488 kVideoMaxSendBitrateKbps, kVideoMinSendBitrateKbps,
489 kVideoDefaultStartSendBitrateKbps);
490
491 // Use the default start bitrate if the send bitrate is lower.
492 vie_.SetSendBitrates(send_channel, kVideoDefaultStartSendBitrateKbps - 50, 0,
493 0);
494 EXPECT_TRUE(channel_->SetSendCodecs(codec_list));
495 VerifyVP8SendCodec(send_channel, kVP8Codec.width, kVP8Codec.height, 0,
496 kVideoMaxSendBitrateKbps, kVideoMinSendBitrateKbps,
497 kVideoDefaultStartSendBitrateKbps);
498}
499
500
501// Test that we constrain send codecs properly.
502TEST_F(WebRtcVideoEngineTestFake, ConstrainSendCodecs) {
503 EXPECT_TRUE(SetupEngine());
504 int channel_num = vie_.GetLastChannel();
505
506 // Set max settings of 640x400x30.
507 EXPECT_TRUE(engine_.SetDefaultEncoderConfig(
508 cricket::VideoEncoderConfig(kVP8Codec)));
509
510 // Send codec format bigger than max setting.
511 cricket::VideoCodec codec(kVP8Codec);
512 codec.width = 1280;
513 codec.height = 800;
514 codec.framerate = 60;
515 std::vector<cricket::VideoCodec> codec_list;
516 codec_list.push_back(codec);
517
518 // Set send codec and verify codec has been constrained.
519 EXPECT_TRUE(channel_->SetSendCodecs(codec_list));
520 VerifyVP8SendCodec(channel_num, kVP8Codec.width, kVP8Codec.height);
521}
522
523// Test that SetSendCodecs rejects bad format.
524TEST_F(WebRtcVideoEngineTestFake, SetSendCodecsRejectBadFormat) {
525 EXPECT_TRUE(SetupEngine());
526 int channel_num = vie_.GetLastChannel();
527
528 // Set w = 0.
529 cricket::VideoCodec codec(kVP8Codec);
530 codec.width = 0;
531 std::vector<cricket::VideoCodec> codec_list;
532 codec_list.push_back(codec);
533
534 // Verify SetSendCodecs failed and send codec is not changed on engine.
535 EXPECT_FALSE(channel_->SetSendCodecs(codec_list));
536 webrtc::VideoCodec gcodec;
537 // Set plType to something other than the value to test against ensuring
538 // that failure will happen if it is not changed.
539 gcodec.plType = 1;
540 EXPECT_EQ(0, vie_.GetSendCodec(channel_num, gcodec));
541 EXPECT_EQ(0, gcodec.plType);
542
543 // Set h = 0.
544 codec_list[0].width = 640;
545 codec_list[0].height = 0;
546
547 // Verify SetSendCodecs failed and send codec is not changed on engine.
548 EXPECT_FALSE(channel_->SetSendCodecs(codec_list));
549 // Set plType to something other than the value to test against ensuring
550 // that failure will happen if it is not changed.
551 gcodec.plType = 1;
552 EXPECT_EQ(0, vie_.GetSendCodec(channel_num, gcodec));
553 EXPECT_EQ(0, gcodec.plType);
554}
555
556// Test that SetSendCodecs rejects bad codec.
557TEST_F(WebRtcVideoEngineTestFake, SetSendCodecsRejectBadCodec) {
558 EXPECT_TRUE(SetupEngine());
559 int channel_num = vie_.GetLastChannel();
560
561 // Set bad codec name.
562 cricket::VideoCodec codec(kVP8Codec);
563 codec.name = "bad";
564 std::vector<cricket::VideoCodec> codec_list;
565 codec_list.push_back(codec);
566
567 // Verify SetSendCodecs failed and send codec is not changed on engine.
568 EXPECT_FALSE(channel_->SetSendCodecs(codec_list));
569 webrtc::VideoCodec gcodec;
570 // Set plType to something other than the value to test against ensuring
571 // that failure will happen if it is not changed.
572 gcodec.plType = 1;
573 EXPECT_EQ(0, vie_.GetSendCodec(channel_num, gcodec));
574 EXPECT_EQ(0, gcodec.plType);
575}
576
577// Test that vie send codec is reset on new video frame size.
578TEST_F(WebRtcVideoEngineTestFake, ResetVieSendCodecOnNewFrameSize) {
579 EXPECT_TRUE(SetupEngine());
580 int channel_num = vie_.GetLastChannel();
581
582 // Set send codec.
583 std::vector<cricket::VideoCodec> codec_list;
584 codec_list.push_back(kVP8Codec);
585 EXPECT_TRUE(channel_->SetSendCodecs(codec_list));
586 EXPECT_TRUE(channel_->AddSendStream(
587 cricket::StreamParams::CreateLegacy(123)));
588 EXPECT_TRUE(channel_->SetSend(true));
589
590 // Capture a smaller frame and verify vie send codec has been reset to
591 // the new size.
592 SendI420Frame(kVP8Codec.width / 2, kVP8Codec.height / 2);
593 VerifyVP8SendCodec(channel_num, kVP8Codec.width / 2, kVP8Codec.height / 2);
594
595 // Capture a frame bigger than send_codec_ and verify vie send codec has been
596 // reset (and clipped) to send_codec_.
597 SendI420Frame(kVP8Codec.width * 2, kVP8Codec.height * 2);
598 VerifyVP8SendCodec(channel_num, kVP8Codec.width, kVP8Codec.height);
599}
600
601// Test that we set our inbound codecs properly.
602TEST_F(WebRtcVideoEngineTestFake, SetRecvCodecs) {
603 EXPECT_TRUE(SetupEngine());
604 int channel_num = vie_.GetLastChannel();
605
606 std::vector<cricket::VideoCodec> codecs;
607 codecs.push_back(kVP8Codec);
608 EXPECT_TRUE(channel_->SetRecvCodecs(codecs));
609
610 webrtc::VideoCodec wcodec;
611 EXPECT_TRUE(engine_.ConvertFromCricketVideoCodec(kVP8Codec, &wcodec));
612 EXPECT_TRUE(vie_.ReceiveCodecRegistered(channel_num, wcodec));
613}
614
615// Test that channel connects and disconnects external capturer correctly.
616TEST_F(WebRtcVideoEngineTestFake, HasExternalCapturer) {
617 EXPECT_TRUE(SetupEngine());
618 int channel_num = vie_.GetLastChannel();
619
620 EXPECT_EQ(1, vie_.GetNumCapturers());
621 int capture_id = vie_.GetCaptureId(channel_num);
622 EXPECT_EQ(channel_num, vie_.GetCaptureChannelId(capture_id));
623
624 // Delete the channel should disconnect the capturer.
625 delete channel_;
626 channel_ = NULL;
627 EXPECT_EQ(0, vie_.GetNumCapturers());
628}
629
630// Test that channel adds and removes renderer correctly.
631TEST_F(WebRtcVideoEngineTestFake, HasRenderer) {
632 EXPECT_TRUE(SetupEngine());
633 int channel_num = vie_.GetLastChannel();
634
635 EXPECT_TRUE(vie_.GetHasRenderer(channel_num));
636 EXPECT_FALSE(vie_.GetRenderStarted(channel_num));
637}
638
639// Test that rtcp is enabled on the channel.
640TEST_F(WebRtcVideoEngineTestFake, RtcpEnabled) {
641 EXPECT_TRUE(SetupEngine());
642 int channel_num = vie_.GetLastChannel();
643 EXPECT_EQ(webrtc::kRtcpCompound_RFC4585, vie_.GetRtcpStatus(channel_num));
644}
645
646// Test that key frame request method is set on the channel.
647TEST_F(WebRtcVideoEngineTestFake, KeyFrameRequestEnabled) {
648 EXPECT_TRUE(SetupEngine());
649 int channel_num = vie_.GetLastChannel();
650 EXPECT_EQ(webrtc::kViEKeyFrameRequestPliRtcp,
651 vie_.GetKeyFrameRequestMethod(channel_num));
652}
653
654// Test that remb receive and send is enabled for the default channel in a 1:1
655// call.
656TEST_F(WebRtcVideoEngineTestFake, RembEnabled) {
657 EXPECT_TRUE(SetupEngine());
658 int channel_num = vie_.GetLastChannel();
659 EXPECT_TRUE(channel_->AddSendStream(
660 cricket::StreamParams::CreateLegacy(1)));
661 EXPECT_TRUE(channel_->SetSendCodecs(engine_.codecs()));
662 EXPECT_TRUE(vie_.GetRembStatusBwPartition(channel_num));
663 EXPECT_TRUE(channel_->SetSend(true));
664 EXPECT_TRUE(vie_.GetRembStatusBwPartition(channel_num));
665 EXPECT_TRUE(vie_.GetRembStatusContribute(channel_num));
666}
667
668// When in conference mode, test that remb is enabled on a receive channel but
669// not for the default channel and that it uses the default channel for sending
670// remb packets.
671TEST_F(WebRtcVideoEngineTestFake, RembEnabledOnReceiveChannels) {
672 EXPECT_TRUE(SetupEngine());
673 int default_channel = vie_.GetLastChannel();
674 cricket::VideoOptions options;
675 options.conference_mode.Set(true);
676 EXPECT_TRUE(channel_->SetOptions(options));
677 EXPECT_TRUE(channel_->AddSendStream(
678 cricket::StreamParams::CreateLegacy(1)));
679 EXPECT_TRUE(channel_->SetSendCodecs(engine_.codecs()));
680 EXPECT_TRUE(vie_.GetRembStatusBwPartition(default_channel));
681 EXPECT_TRUE(vie_.GetRembStatusContribute(default_channel));
682 EXPECT_TRUE(channel_->SetSend(true));
683 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(1)));
684 int new_channel_num = vie_.GetLastChannel();
685 EXPECT_NE(default_channel, new_channel_num);
686
687 EXPECT_TRUE(vie_.GetRembStatusBwPartition(default_channel));
688 EXPECT_TRUE(vie_.GetRembStatusContribute(default_channel));
689 EXPECT_FALSE(vie_.GetRembStatusBwPartition(new_channel_num));
690 EXPECT_TRUE(vie_.GetRembStatusContribute(new_channel_num));
691}
692
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000693TEST_F(WebRtcVideoEngineTestFake, RecvStreamWithRtx) {
694 EXPECT_TRUE(SetupEngine());
695 int default_channel = vie_.GetLastChannel();
696 cricket::VideoOptions options;
697 options.conference_mode.Set(true);
698 EXPECT_TRUE(channel_->SetOptions(options));
699 EXPECT_TRUE(channel_->AddSendStream(
700 cricket::CreateSimWithRtxStreamParams("cname",
701 MAKE_VECTOR(kSsrcs3),
702 MAKE_VECTOR(kRtxSsrcs3))));
703 EXPECT_TRUE(channel_->SetSendCodecs(engine_.codecs()));
704 EXPECT_TRUE(channel_->SetSend(true));
705 EXPECT_TRUE(channel_->AddRecvStream(
706 cricket::CreateSimWithRtxStreamParams("cname",
707 MAKE_VECTOR(kSsrcs1),
708 MAKE_VECTOR(kRtxSsrc1))));
709 int new_channel_num = vie_.GetLastChannel();
710 EXPECT_NE(default_channel, new_channel_num);
711 EXPECT_EQ(4, vie_.GetRemoteRtxSsrc(new_channel_num));
712}
713
714TEST_F(WebRtcVideoEngineTestFake, RecvStreamNoRtx) {
715 EXPECT_TRUE(SetupEngine());
716 int default_channel = vie_.GetLastChannel();
717 cricket::VideoOptions options;
718 options.conference_mode.Set(true);
719 EXPECT_TRUE(channel_->SetOptions(options));
720 EXPECT_TRUE(channel_->AddSendStream(
721 cricket::CreateSimWithRtxStreamParams("cname",
722 MAKE_VECTOR(kSsrcs3),
723 MAKE_VECTOR(kRtxSsrcs3))));
724 EXPECT_TRUE(channel_->SetSendCodecs(engine_.codecs()));
725 EXPECT_TRUE(channel_->SetSend(true));
726 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(1)));
727 int new_channel_num = vie_.GetLastChannel();
728 EXPECT_NE(default_channel, new_channel_num);
729 EXPECT_EQ(-1, vie_.GetRemoteRtxSsrc(new_channel_num));
730}
731
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000732// Test support for RTP timestamp offset header extension.
733TEST_F(WebRtcVideoEngineTestFake, RtpTimestampOffsetHeaderExtensions) {
734 EXPECT_TRUE(SetupEngine());
735 int channel_num = vie_.GetLastChannel();
736 cricket::VideoOptions options;
737 options.conference_mode.Set(true);
738 EXPECT_TRUE(channel_->SetOptions(options));
739
740 // Verify extensions are off by default.
741 EXPECT_EQ(0, vie_.GetSendRtpTimestampOffsetExtensionId(channel_num));
742 EXPECT_EQ(0, vie_.GetReceiveRtpTimestampOffsetExtensionId(channel_num));
743
744 // Enable RTP timestamp extension.
745 const int id = 14;
746 std::vector<cricket::RtpHeaderExtension> extensions;
747 extensions.push_back(cricket::RtpHeaderExtension(
748 "urn:ietf:params:rtp-hdrext:toffset", id));
749
750 // Verify the send extension id.
751 EXPECT_TRUE(channel_->SetSendRtpHeaderExtensions(extensions));
752 EXPECT_EQ(id, vie_.GetSendRtpTimestampOffsetExtensionId(channel_num));
753
754 // Remove the extension id.
755 std::vector<cricket::RtpHeaderExtension> empty_extensions;
756 EXPECT_TRUE(channel_->SetSendRtpHeaderExtensions(empty_extensions));
757 EXPECT_EQ(0, vie_.GetSendRtpTimestampOffsetExtensionId(channel_num));
758
759 // Verify receive extension id.
760 EXPECT_TRUE(channel_->SetRecvRtpHeaderExtensions(extensions));
761 EXPECT_EQ(id, vie_.GetReceiveRtpTimestampOffsetExtensionId(channel_num));
762
763 // Add a new receive stream and verify the extension is set.
764 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(2)));
765 int new_channel_num = vie_.GetLastChannel();
766 EXPECT_NE(channel_num, new_channel_num);
767 EXPECT_EQ(id, vie_.GetReceiveRtpTimestampOffsetExtensionId(new_channel_num));
768
769 // Remove the extension id.
770 EXPECT_TRUE(channel_->SetRecvRtpHeaderExtensions(empty_extensions));
771 EXPECT_EQ(0, vie_.GetReceiveRtpTimestampOffsetExtensionId(channel_num));
772 EXPECT_EQ(0, vie_.GetReceiveRtpTimestampOffsetExtensionId(new_channel_num));
773}
774
775// Test support for absolute send time header extension.
776TEST_F(WebRtcVideoEngineTestFake, AbsoluteSendTimeHeaderExtensions) {
777 EXPECT_TRUE(SetupEngine());
778 int channel_num = vie_.GetLastChannel();
779 cricket::VideoOptions options;
780 options.conference_mode.Set(true);
781 EXPECT_TRUE(channel_->SetOptions(options));
782
783 // Verify extensions are off by default.
784 EXPECT_EQ(0, vie_.GetSendAbsoluteSendTimeExtensionId(channel_num));
785 EXPECT_EQ(0, vie_.GetReceiveAbsoluteSendTimeExtensionId(channel_num));
786
787 // Enable RTP timestamp extension.
788 const int id = 12;
789 std::vector<cricket::RtpHeaderExtension> extensions;
790 extensions.push_back(cricket::RtpHeaderExtension(
791 "http://www.webrtc.org/experiments/rtp-hdrext/abs-send-time", id));
792
793 // Verify the send extension id.
794 EXPECT_TRUE(channel_->SetSendRtpHeaderExtensions(extensions));
795 EXPECT_EQ(id, vie_.GetSendAbsoluteSendTimeExtensionId(channel_num));
796
797 // Remove the extension id.
798 std::vector<cricket::RtpHeaderExtension> empty_extensions;
799 EXPECT_TRUE(channel_->SetSendRtpHeaderExtensions(empty_extensions));
800 EXPECT_EQ(0, vie_.GetSendAbsoluteSendTimeExtensionId(channel_num));
801
802 // Verify receive extension id.
803 EXPECT_TRUE(channel_->SetRecvRtpHeaderExtensions(extensions));
804 EXPECT_EQ(id, vie_.GetReceiveAbsoluteSendTimeExtensionId(channel_num));
805
806 // Add a new receive stream and verify the extension is set.
807 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(2)));
808 int new_channel_num = vie_.GetLastChannel();
809 EXPECT_NE(channel_num, new_channel_num);
810 EXPECT_EQ(id, vie_.GetReceiveAbsoluteSendTimeExtensionId(new_channel_num));
811
812 // Remove the extension id.
813 EXPECT_TRUE(channel_->SetRecvRtpHeaderExtensions(empty_extensions));
814 EXPECT_EQ(0, vie_.GetReceiveAbsoluteSendTimeExtensionId(channel_num));
815 EXPECT_EQ(0, vie_.GetReceiveAbsoluteSendTimeExtensionId(new_channel_num));
816}
817
818TEST_F(WebRtcVideoEngineTestFake, LeakyBucketTest) {
819 EXPECT_TRUE(SetupEngine());
820
821 // Verify this is off by default.
822 EXPECT_TRUE(channel_->AddSendStream(cricket::StreamParams::CreateLegacy(1)));
823 int first_send_channel = vie_.GetLastChannel();
824 EXPECT_FALSE(vie_.GetTransmissionSmoothingStatus(first_send_channel));
825
826 // Enable the experiment and verify.
827 cricket::VideoOptions options;
828 options.conference_mode.Set(true);
829 options.video_leaky_bucket.Set(true);
830 EXPECT_TRUE(channel_->SetOptions(options));
831 EXPECT_TRUE(vie_.GetTransmissionSmoothingStatus(first_send_channel));
832
833 // Add a receive channel and verify leaky bucket isn't enabled.
834 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(2)));
835 int recv_channel_num = vie_.GetLastChannel();
836 EXPECT_NE(first_send_channel, recv_channel_num);
837 EXPECT_FALSE(vie_.GetTransmissionSmoothingStatus(recv_channel_num));
838
839 // Add a new send stream and verify leaky bucket is enabled from start.
840 EXPECT_TRUE(channel_->AddSendStream(cricket::StreamParams::CreateLegacy(3)));
841 int second_send_channel = vie_.GetLastChannel();
842 EXPECT_NE(first_send_channel, second_send_channel);
843 EXPECT_TRUE(vie_.GetTransmissionSmoothingStatus(second_send_channel));
844}
845
henrike@webrtc.org6e3dbc22014-03-25 17:09:47 +0000846// Verify that SuspendBelowMinBitrate is enabled if it is set in the options.
847TEST_F(WebRtcVideoEngineTestFake, SuspendBelowMinBitrateTest) {
848 EXPECT_TRUE(SetupEngine());
849
850 // Verify this is off by default.
851 EXPECT_TRUE(channel_->AddSendStream(cricket::StreamParams::CreateLegacy(1)));
852 int first_send_channel = vie_.GetLastChannel();
853 EXPECT_FALSE(vie_.GetSuspendBelowMinBitrateStatus(first_send_channel));
854
855 // Enable the experiment and verify.
856 cricket::VideoOptions options;
857 options.suspend_below_min_bitrate.Set(true);
858 EXPECT_TRUE(channel_->SetOptions(options));
859 EXPECT_TRUE(vie_.GetSuspendBelowMinBitrateStatus(first_send_channel));
860
861 // Add a new send stream and verify suspend_below_min_bitrate is enabled.
862 EXPECT_TRUE(channel_->AddSendStream(cricket::StreamParams::CreateLegacy(2)));
863 int second_send_channel = vie_.GetLastChannel();
864 EXPECT_NE(first_send_channel, second_send_channel);
865 EXPECT_TRUE(vie_.GetSuspendBelowMinBitrateStatus(second_send_channel));
866}
867
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000868TEST_F(WebRtcVideoEngineTestFake, BufferedModeLatency) {
869 EXPECT_TRUE(SetupEngine());
870
871 // Verify this is off by default.
872 EXPECT_TRUE(channel_->AddSendStream(cricket::StreamParams::CreateLegacy(1)));
873 int first_send_channel = vie_.GetLastChannel();
874 EXPECT_EQ(0, vie_.GetSenderTargetDelay(first_send_channel));
875 EXPECT_EQ(0, vie_.GetReceiverTargetDelay(first_send_channel));
876
877 // Enable the experiment and verify. The default channel will have both
878 // sender and receiver buffered mode enabled.
879 cricket::VideoOptions options;
880 options.conference_mode.Set(true);
881 options.buffered_mode_latency.Set(100);
882 EXPECT_TRUE(channel_->SetOptions(options));
883 EXPECT_EQ(100, vie_.GetSenderTargetDelay(first_send_channel));
884 EXPECT_EQ(100, vie_.GetReceiverTargetDelay(first_send_channel));
885
886 // Add a receive channel and verify sender buffered mode isn't enabled.
887 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(2)));
888 int recv_channel_num = vie_.GetLastChannel();
889 EXPECT_NE(first_send_channel, recv_channel_num);
890 EXPECT_EQ(0, vie_.GetSenderTargetDelay(recv_channel_num));
891 EXPECT_EQ(100, vie_.GetReceiverTargetDelay(recv_channel_num));
892
893 // Add a new send stream and verify sender buffered mode is enabled.
894 EXPECT_TRUE(channel_->AddSendStream(cricket::StreamParams::CreateLegacy(3)));
895 int second_send_channel = vie_.GetLastChannel();
896 EXPECT_NE(first_send_channel, second_send_channel);
897 EXPECT_EQ(100, vie_.GetSenderTargetDelay(second_send_channel));
898 EXPECT_EQ(0, vie_.GetReceiverTargetDelay(second_send_channel));
899
900 // Disable sender buffered mode and verify.
901 options.buffered_mode_latency.Set(cricket::kBufferedModeDisabled);
902 EXPECT_TRUE(channel_->SetOptions(options));
903 EXPECT_EQ(0, vie_.GetSenderTargetDelay(first_send_channel));
904 EXPECT_EQ(0, vie_.GetReceiverTargetDelay(first_send_channel));
905 EXPECT_EQ(0, vie_.GetSenderTargetDelay(second_send_channel));
906 EXPECT_EQ(0, vie_.GetReceiverTargetDelay(second_send_channel));
907 EXPECT_EQ(0, vie_.GetSenderTargetDelay(recv_channel_num));
908 EXPECT_EQ(0, vie_.GetReceiverTargetDelay(recv_channel_num));
909}
910
911TEST_F(WebRtcVideoEngineTestFake, AdditiveVideoOptions) {
912 EXPECT_TRUE(SetupEngine());
913
914 EXPECT_TRUE(channel_->AddSendStream(cricket::StreamParams::CreateLegacy(1)));
915 int first_send_channel = vie_.GetLastChannel();
916 EXPECT_EQ(0, vie_.GetSenderTargetDelay(first_send_channel));
917 EXPECT_EQ(0, vie_.GetReceiverTargetDelay(first_send_channel));
918
919 cricket::VideoOptions options1;
920 options1.buffered_mode_latency.Set(100);
921 EXPECT_TRUE(channel_->SetOptions(options1));
922 EXPECT_EQ(100, vie_.GetSenderTargetDelay(first_send_channel));
923 EXPECT_EQ(100, vie_.GetReceiverTargetDelay(first_send_channel));
924 EXPECT_FALSE(vie_.GetTransmissionSmoothingStatus(first_send_channel));
925
926 cricket::VideoOptions options2;
927 options2.video_leaky_bucket.Set(true);
928 EXPECT_TRUE(channel_->SetOptions(options2));
929 EXPECT_TRUE(vie_.GetTransmissionSmoothingStatus(first_send_channel));
930 // The buffered_mode_latency still takes effect.
931 EXPECT_EQ(100, vie_.GetSenderTargetDelay(first_send_channel));
932 EXPECT_EQ(100, vie_.GetReceiverTargetDelay(first_send_channel));
933
934 options1.buffered_mode_latency.Set(50);
935 EXPECT_TRUE(channel_->SetOptions(options1));
936 EXPECT_EQ(50, vie_.GetSenderTargetDelay(first_send_channel));
937 EXPECT_EQ(50, vie_.GetReceiverTargetDelay(first_send_channel));
938 // The video_leaky_bucket still takes effect.
939 EXPECT_TRUE(vie_.GetTransmissionSmoothingStatus(first_send_channel));
940}
941
henrike@webrtc.orgb0ecc1c2014-03-26 22:44:28 +0000942TEST_F(WebRtcVideoEngineTestFake, SetCpuOveruseOptionsWithCaptureJitterMethod) {
943 EXPECT_TRUE(SetupEngine());
944
945 // Verify this is off by default.
946 EXPECT_TRUE(channel_->AddSendStream(cricket::StreamParams::CreateLegacy(1)));
947 int first_send_channel = vie_.GetLastChannel();
948 webrtc::CpuOveruseOptions cpu_option =
949 vie_.GetCpuOveruseOptions(first_send_channel);
950 EXPECT_EQ(0, cpu_option.low_capture_jitter_threshold_ms);
951 EXPECT_EQ(0, cpu_option.high_capture_jitter_threshold_ms);
952 EXPECT_FALSE(cpu_option.enable_capture_jitter_method);
953 EXPECT_FALSE(cpu_option.enable_encode_usage_method);
954
955 // Set low and high threshold and verify that cpu options are set.
956 cricket::VideoOptions options;
957 options.conference_mode.Set(true);
958 options.cpu_underuse_threshold.Set(10);
959 options.cpu_overuse_threshold.Set(20);
960 EXPECT_TRUE(channel_->SetOptions(options));
961 cpu_option = vie_.GetCpuOveruseOptions(first_send_channel);
962 EXPECT_EQ(10, cpu_option.low_capture_jitter_threshold_ms);
963 EXPECT_EQ(20, cpu_option.high_capture_jitter_threshold_ms);
964 EXPECT_TRUE(cpu_option.enable_capture_jitter_method);
965 EXPECT_FALSE(cpu_option.enable_encode_usage_method);
966
967 // Add a receive channel and verify that cpu options are not set.
968 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(2)));
969 int recv_channel_num = vie_.GetLastChannel();
970 EXPECT_NE(first_send_channel, recv_channel_num);
971 cpu_option = vie_.GetCpuOveruseOptions(recv_channel_num);
972 EXPECT_EQ(0, cpu_option.low_capture_jitter_threshold_ms);
973 EXPECT_EQ(0, cpu_option.high_capture_jitter_threshold_ms);
974 EXPECT_FALSE(cpu_option.enable_capture_jitter_method);
975 EXPECT_FALSE(cpu_option.enable_encode_usage_method);
976
977 // Add a new send stream and verify that cpu options are set from start.
978 EXPECT_TRUE(channel_->AddSendStream(cricket::StreamParams::CreateLegacy(3)));
979 int second_send_channel = vie_.GetLastChannel();
980 EXPECT_NE(first_send_channel, second_send_channel);
981 cpu_option = vie_.GetCpuOveruseOptions(second_send_channel);
982 EXPECT_EQ(10, cpu_option.low_capture_jitter_threshold_ms);
983 EXPECT_EQ(20, cpu_option.high_capture_jitter_threshold_ms);
984 EXPECT_TRUE(cpu_option.enable_capture_jitter_method);
985 EXPECT_FALSE(cpu_option.enable_encode_usage_method);
986}
987
988TEST_F(WebRtcVideoEngineTestFake, SetInvalidCpuOveruseThresholds) {
989 EXPECT_TRUE(SetupEngine());
990 EXPECT_TRUE(channel_->AddSendStream(cricket::StreamParams::CreateLegacy(1)));
991 int channel_num = vie_.GetLastChannel();
992
993 // Only low threshold set. Verify that cpu options are not set.
994 cricket::VideoOptions options;
995 options.conference_mode.Set(true);
996 options.cpu_underuse_threshold.Set(10);
997 EXPECT_TRUE(channel_->SetOptions(options));
998 webrtc::CpuOveruseOptions cpu_option = vie_.GetCpuOveruseOptions(channel_num);
999 EXPECT_EQ(0, cpu_option.low_capture_jitter_threshold_ms);
1000 EXPECT_EQ(0, cpu_option.high_capture_jitter_threshold_ms);
1001 EXPECT_FALSE(cpu_option.enable_capture_jitter_method);
1002 EXPECT_FALSE(cpu_option.enable_encode_usage_method);
1003
1004 // Set high threshold to a negative value. Verify that options are not set.
1005 options.cpu_overuse_threshold.Set(-1);
1006 EXPECT_TRUE(channel_->SetOptions(options));
1007 cpu_option = vie_.GetCpuOveruseOptions(channel_num);
1008 EXPECT_EQ(0, cpu_option.low_capture_jitter_threshold_ms);
1009 EXPECT_EQ(0, cpu_option.high_capture_jitter_threshold_ms);
1010 EXPECT_FALSE(cpu_option.enable_capture_jitter_method);
1011 EXPECT_FALSE(cpu_option.enable_encode_usage_method);
1012
1013 // Low and high threshold valid. Verify that cpu options are set.
1014 options.cpu_overuse_threshold.Set(20);
1015 EXPECT_TRUE(channel_->SetOptions(options));
1016 cpu_option = vie_.GetCpuOveruseOptions(channel_num);
1017 EXPECT_EQ(10, cpu_option.low_capture_jitter_threshold_ms);
1018 EXPECT_EQ(20, cpu_option.high_capture_jitter_threshold_ms);
1019 EXPECT_TRUE(cpu_option.enable_capture_jitter_method);
1020 EXPECT_FALSE(cpu_option.enable_encode_usage_method);
1021}
1022
1023TEST_F(WebRtcVideoEngineTestFake, SetCpuOveruseOptionsWithEncodeUsageMethod) {
1024 EXPECT_TRUE(SetupEngine());
1025 EXPECT_TRUE(channel_->AddSendStream(cricket::StreamParams::CreateLegacy(1)));
1026 int first_send_channel = vie_.GetLastChannel();
1027
1028 // Set low and high threshold and enable encode usage method.
1029 // Verify that cpu options are set.
1030 cricket::VideoOptions options;
1031 options.conference_mode.Set(true);
1032 options.cpu_underuse_threshold.Set(10);
1033 options.cpu_overuse_threshold.Set(20);
1034 options.cpu_overuse_encode_usage.Set(true);
1035 EXPECT_TRUE(channel_->SetOptions(options));
1036 webrtc::CpuOveruseOptions cpu_option =
1037 vie_.GetCpuOveruseOptions(first_send_channel);
1038 EXPECT_EQ(10, cpu_option.low_encode_usage_threshold_percent);
1039 EXPECT_EQ(20, cpu_option.high_encode_usage_threshold_percent);
1040 EXPECT_FALSE(cpu_option.enable_capture_jitter_method);
1041 EXPECT_TRUE(cpu_option.enable_encode_usage_method);
1042
1043 // Add a new send stream and verify that cpu options are set from start.
1044 EXPECT_TRUE(channel_->AddSendStream(cricket::StreamParams::CreateLegacy(3)));
1045 int second_send_channel = vie_.GetLastChannel();
1046 EXPECT_NE(first_send_channel, second_send_channel);
1047 cpu_option = vie_.GetCpuOveruseOptions(second_send_channel);
1048 EXPECT_EQ(10, cpu_option.low_encode_usage_threshold_percent);
1049 EXPECT_EQ(20, cpu_option.high_encode_usage_threshold_percent);
1050 EXPECT_FALSE(cpu_option.enable_capture_jitter_method);
1051 EXPECT_TRUE(cpu_option.enable_encode_usage_method);
1052}
henrike@webrtc.orgb0ecc1c2014-03-26 22:44:28 +00001053
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001054// Test that AddRecvStream doesn't create new channel for 1:1 call.
1055TEST_F(WebRtcVideoEngineTestFake, AddRecvStream1On1) {
1056 EXPECT_TRUE(SetupEngine());
1057 int channel_num = vie_.GetLastChannel();
1058 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(1)));
1059 EXPECT_EQ(channel_num, vie_.GetLastChannel());
1060}
1061
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +00001062// Test that NACK, PLI and REMB are enabled for internal codec.
1063TEST_F(WebRtcVideoEngineTestFake, InternalCodecFeedbackParams) {
1064 EXPECT_TRUE(SetupEngine());
1065
1066 std::vector<cricket::VideoCodec> codecs(engine_.codecs());
1067 // Vp8 will appear at the beginning.
1068 size_t pos = 0;
1069 EXPECT_EQ("VP8", codecs[pos].name);
1070 VerifyCodecFeedbackParams(codecs[pos]);
1071}
1072
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001073// Test that AddRecvStream doesn't change remb for 1:1 call.
1074TEST_F(WebRtcVideoEngineTestFake, NoRembChangeAfterAddRecvStream) {
1075 EXPECT_TRUE(SetupEngine());
1076 int channel_num = vie_.GetLastChannel();
1077 EXPECT_TRUE(channel_->AddSendStream(
1078 cricket::StreamParams::CreateLegacy(1)));
1079 EXPECT_TRUE(channel_->SetSendCodecs(engine_.codecs()));
1080 EXPECT_TRUE(vie_.GetRembStatusBwPartition(channel_num));
1081 EXPECT_TRUE(vie_.GetRembStatusContribute(channel_num));
1082 EXPECT_TRUE(channel_->SetSend(true));
1083 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(1)));
1084 EXPECT_TRUE(vie_.GetRembStatusBwPartition(channel_num));
1085 EXPECT_TRUE(vie_.GetRembStatusContribute(channel_num));
1086}
1087
1088// Verify default REMB setting and that it can be turned on and off.
1089TEST_F(WebRtcVideoEngineTestFake, RembOnOff) {
1090 EXPECT_TRUE(SetupEngine());
1091 int channel_num = vie_.GetLastChannel();
1092 // Verify REMB sending is always off by default.
1093 EXPECT_FALSE(vie_.GetRembStatusBwPartition(channel_num));
1094
1095 // Verify that REMB is turned on when setting default codecs since the
1096 // default codecs have REMB enabled.
1097 EXPECT_TRUE(channel_->SetSendCodecs(engine_.codecs()));
1098 EXPECT_TRUE(vie_.GetRembStatusBwPartition(channel_num));
1099
1100 // Verify that REMB is turned off when codecs without REMB are set.
1101 std::vector<cricket::VideoCodec> codecs = engine_.codecs();
1102 // Clearing the codecs' FeedbackParams and setting send codecs should disable
1103 // REMB.
1104 for (std::vector<cricket::VideoCodec>::iterator iter = codecs.begin();
1105 iter != codecs.end(); ++iter) {
1106 // Intersecting with empty will clear the FeedbackParams.
1107 cricket::FeedbackParams empty_params;
1108 iter->feedback_params.Intersect(empty_params);
1109 EXPECT_TRUE(iter->feedback_params.params().empty());
1110 }
1111 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1112 EXPECT_FALSE(vie_.GetRembStatusBwPartition(channel_num));
1113}
1114
1115// Test that nack is enabled on the channel if we don't offer red/fec.
1116TEST_F(WebRtcVideoEngineTestFake, NackEnabled) {
1117 EXPECT_TRUE(SetupEngine());
1118 int channel_num = vie_.GetLastChannel();
1119 std::vector<cricket::VideoCodec> codecs(engine_.codecs());
1120 codecs.resize(1); // toss out red and ulpfec
1121 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1122 EXPECT_TRUE(vie_.GetNackStatus(channel_num));
1123}
1124
1125// Test that we enable hybrid NACK FEC mode.
1126TEST_F(WebRtcVideoEngineTestFake, HybridNackFec) {
1127 EXPECT_TRUE(SetupEngine());
1128 int channel_num = vie_.GetLastChannel();
1129 EXPECT_TRUE(channel_->SetRecvCodecs(engine_.codecs()));
1130 EXPECT_TRUE(channel_->SetSendCodecs(engine_.codecs()));
1131 EXPECT_TRUE(vie_.GetHybridNackFecStatus(channel_num));
1132 EXPECT_FALSE(vie_.GetNackStatus(channel_num));
1133}
1134
1135// Test that we enable hybrid NACK FEC mode when calling SetSendCodecs and
1136// SetReceiveCodecs in reversed order.
1137TEST_F(WebRtcVideoEngineTestFake, HybridNackFecReversedOrder) {
1138 EXPECT_TRUE(SetupEngine());
1139 int channel_num = vie_.GetLastChannel();
1140 EXPECT_TRUE(channel_->SetSendCodecs(engine_.codecs()));
1141 EXPECT_TRUE(channel_->SetRecvCodecs(engine_.codecs()));
1142 EXPECT_TRUE(vie_.GetHybridNackFecStatus(channel_num));
1143 EXPECT_FALSE(vie_.GetNackStatus(channel_num));
1144}
1145
1146// Test NACK vs Hybrid NACK/FEC interop call setup, i.e. only use NACK even if
1147// red/fec is offered as receive codec.
1148TEST_F(WebRtcVideoEngineTestFake, VideoProtectionInterop) {
1149 EXPECT_TRUE(SetupEngine());
1150 int channel_num = vie_.GetLastChannel();
1151 std::vector<cricket::VideoCodec> recv_codecs(engine_.codecs());
1152 std::vector<cricket::VideoCodec> send_codecs(engine_.codecs());
1153 // Only add VP8 as send codec.
1154 send_codecs.resize(1);
1155 EXPECT_TRUE(channel_->SetRecvCodecs(recv_codecs));
1156 EXPECT_TRUE(channel_->SetSendCodecs(send_codecs));
1157 EXPECT_FALSE(vie_.GetHybridNackFecStatus(channel_num));
1158 EXPECT_TRUE(vie_.GetNackStatus(channel_num));
1159}
1160
1161// Test NACK vs Hybrid NACK/FEC interop call setup, i.e. only use NACK even if
1162// red/fec is offered as receive codec. Call order reversed compared to
1163// VideoProtectionInterop.
1164TEST_F(WebRtcVideoEngineTestFake, VideoProtectionInteropReversed) {
1165 EXPECT_TRUE(SetupEngine());
1166 int channel_num = vie_.GetLastChannel();
1167 std::vector<cricket::VideoCodec> recv_codecs(engine_.codecs());
1168 std::vector<cricket::VideoCodec> send_codecs(engine_.codecs());
1169 // Only add VP8 as send codec.
1170 send_codecs.resize(1);
1171 EXPECT_TRUE(channel_->SetSendCodecs(send_codecs));
1172 EXPECT_TRUE(channel_->SetRecvCodecs(recv_codecs));
1173 EXPECT_FALSE(vie_.GetHybridNackFecStatus(channel_num));
1174 EXPECT_TRUE(vie_.GetNackStatus(channel_num));
1175}
1176
1177// Test that NACK, not hybrid mode, is enabled in conference mode.
1178TEST_F(WebRtcVideoEngineTestFake, HybridNackFecConference) {
1179 EXPECT_TRUE(SetupEngine());
1180 // Setup the send channel.
1181 int send_channel_num = vie_.GetLastChannel();
1182 cricket::VideoOptions options;
1183 options.conference_mode.Set(true);
1184 EXPECT_TRUE(channel_->SetOptions(options));
1185 EXPECT_TRUE(channel_->SetRecvCodecs(engine_.codecs()));
1186 EXPECT_TRUE(channel_->SetSendCodecs(engine_.codecs()));
1187 EXPECT_FALSE(vie_.GetHybridNackFecStatus(send_channel_num));
1188 EXPECT_TRUE(vie_.GetNackStatus(send_channel_num));
1189 // Add a receive stream.
1190 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(1)));
1191 int receive_channel_num = vie_.GetLastChannel();
1192 EXPECT_FALSE(vie_.GetHybridNackFecStatus(receive_channel_num));
1193 EXPECT_TRUE(vie_.GetNackStatus(receive_channel_num));
1194}
1195
1196// Test that when AddRecvStream in conference mode, a new channel is created
1197// for receiving. And the new channel's "original channel" is the send channel.
1198TEST_F(WebRtcVideoEngineTestFake, AddRemoveRecvStreamConference) {
1199 EXPECT_TRUE(SetupEngine());
1200 // Setup the send channel.
1201 int send_channel_num = vie_.GetLastChannel();
1202 cricket::VideoOptions options;
1203 options.conference_mode.Set(true);
1204 EXPECT_TRUE(channel_->SetOptions(options));
1205 // Add a receive stream.
1206 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(1)));
1207 int receive_channel_num = vie_.GetLastChannel();
1208 EXPECT_EQ(send_channel_num, vie_.GetOriginalChannelId(receive_channel_num));
1209 EXPECT_TRUE(channel_->RemoveRecvStream(1));
1210 EXPECT_FALSE(vie_.IsChannel(receive_channel_num));
1211}
1212
henrike@webrtc.org6e3dbc22014-03-25 17:09:47 +00001213// Test that adding/removing stream with 0 ssrc should fail (and not crash).
1214// For crbug/351699 and 350988.
1215TEST_F(WebRtcVideoEngineTestFake, AddRemoveRecvStreamWith0Ssrc) {
1216 EXPECT_TRUE(SetupEngine());
1217 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(1)));
1218 EXPECT_FALSE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(0)));
1219 EXPECT_FALSE(channel_->RemoveRecvStream(0));
1220 EXPECT_TRUE(channel_->RemoveRecvStream(1));
1221}
1222
1223TEST_F(WebRtcVideoEngineTestFake, AddRemoveSendStreamWith0Ssrc) {
1224 EXPECT_TRUE(SetupEngine());
1225 EXPECT_TRUE(channel_->AddSendStream(cricket::StreamParams::CreateLegacy(1)));
1226 EXPECT_FALSE(channel_->AddSendStream(cricket::StreamParams::CreateLegacy(0)));
1227 EXPECT_FALSE(channel_->RemoveSendStream(0));
1228 EXPECT_TRUE(channel_->RemoveSendStream(1));
1229}
1230
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001231// Test that we can create a channel and start/stop rendering out on it.
1232TEST_F(WebRtcVideoEngineTestFake, SetRender) {
1233 EXPECT_TRUE(SetupEngine());
1234 int channel_num = vie_.GetLastChannel();
1235
1236 // Verify we can start/stop/start/stop rendering.
1237 EXPECT_TRUE(channel_->SetRender(true));
1238 EXPECT_TRUE(vie_.GetRenderStarted(channel_num));
1239 EXPECT_TRUE(channel_->SetRender(false));
1240 EXPECT_FALSE(vie_.GetRenderStarted(channel_num));
1241 EXPECT_TRUE(channel_->SetRender(true));
1242 EXPECT_TRUE(vie_.GetRenderStarted(channel_num));
1243 EXPECT_TRUE(channel_->SetRender(false));
1244 EXPECT_FALSE(vie_.GetRenderStarted(channel_num));
1245}
1246
1247// Test that we can create a channel and start/stop sending out on it.
1248TEST_F(WebRtcVideoEngineTestFake, SetSend) {
1249 EXPECT_TRUE(SetupEngine());
1250 int channel_num = vie_.GetLastChannel();
wu@webrtc.orgb9a088b2014-02-13 23:18:49 +00001251 // Verify receiving is also started.
1252 EXPECT_TRUE(vie_.GetReceive(channel_num));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001253
1254 // Set send codecs on the channel.
1255 std::vector<cricket::VideoCodec> codecs;
1256 codecs.push_back(kVP8Codec);
1257 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1258 EXPECT_TRUE(channel_->AddSendStream(
1259 cricket::StreamParams::CreateLegacy(123)));
1260
1261 // Verify we can start/stop/start/stop sending.
1262 EXPECT_TRUE(channel_->SetSend(true));
1263 EXPECT_TRUE(vie_.GetSend(channel_num));
1264 EXPECT_TRUE(channel_->SetSend(false));
1265 EXPECT_FALSE(vie_.GetSend(channel_num));
1266 EXPECT_TRUE(channel_->SetSend(true));
1267 EXPECT_TRUE(vie_.GetSend(channel_num));
1268 EXPECT_TRUE(channel_->SetSend(false));
1269 EXPECT_FALSE(vie_.GetSend(channel_num));
1270}
1271
1272// Test that we set bandwidth properly when using full auto bandwidth mode.
1273TEST_F(WebRtcVideoEngineTestFake, SetBandwidthAuto) {
1274 EXPECT_TRUE(SetupEngine());
1275 int channel_num = vie_.GetLastChannel();
1276 EXPECT_TRUE(channel_->SetSendCodecs(engine_.codecs()));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001277 EXPECT_TRUE(channel_->SetMaxSendBandwidth(cricket::kAutoBandwidth));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001278 VerifyVP8SendCodec(channel_num, kVP8Codec.width, kVP8Codec.height);
1279}
1280
1281// Test that we set bandwidth properly when using auto with upper bound.
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001282TEST_F(WebRtcVideoEngineTestFake, SetBandwidthCapped) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001283 EXPECT_TRUE(SetupEngine());
1284 int channel_num = vie_.GetLastChannel();
1285 EXPECT_TRUE(channel_->SetSendCodecs(engine_.codecs()));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001286 EXPECT_TRUE(channel_->SetMaxSendBandwidth(768000));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001287 VerifyVP8SendCodec(channel_num, kVP8Codec.width, kVP8Codec.height, 0, 768U);
1288}
1289
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001290// Test that we reduce the start bandwidth when the requested max is less than
1291// the default start bandwidth.
1292TEST_F(WebRtcVideoEngineTestFake, SetMaxBandwidthBelowDefaultStart) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001293 EXPECT_TRUE(SetupEngine());
1294 int channel_num = vie_.GetLastChannel();
1295 EXPECT_TRUE(channel_->SetSendCodecs(engine_.codecs()));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001296 int max_bandwidth_kbps = (kMinBandwidthKbps + kStartBandwidthKbps) / 2;
1297 EXPECT_TRUE(channel_->SetMaxSendBandwidth(max_bandwidth_kbps * 1000));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001298 VerifyVP8SendCodec(channel_num, kVP8Codec.width, kVP8Codec.height, 0,
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001299 max_bandwidth_kbps, kMinBandwidthKbps, max_bandwidth_kbps);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001300}
1301
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001302// Test that we reduce the min bandwidth when the requested max is less than
1303// the min bandwidth.
1304TEST_F(WebRtcVideoEngineTestFake, SetMaxBandwidthBelowMin) {
1305 EXPECT_TRUE(SetupEngine());
1306 int channel_num = vie_.GetLastChannel();
1307 EXPECT_TRUE(channel_->SetSendCodecs(engine_.codecs()));
1308 int max_bandwidth_kbps = kMinBandwidthKbps / 2;
1309 EXPECT_TRUE(channel_->SetMaxSendBandwidth(max_bandwidth_kbps * 1000));
1310 VerifyVP8SendCodec(channel_num, kVP8Codec.width, kVP8Codec.height, 0,
1311 max_bandwidth_kbps, max_bandwidth_kbps, max_bandwidth_kbps);
1312}
1313
1314// Test that the start bandwidth can be controlled separately from the max
1315// bandwidth.
1316TEST_F(WebRtcVideoEngineTestFake, SetStartBandwidth) {
1317 EXPECT_TRUE(SetupEngine());
1318 int channel_num = vie_.GetLastChannel();
1319 EXPECT_TRUE(channel_->SetSendCodecs(engine_.codecs()));
1320 int start_bandwidth_kbps = kStartBandwidthKbps + 1;
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 // Check that SetMaxSendBandwidth doesn't overwrite the start bandwidth.
1326 int max_bandwidth_kbps = kMaxBandwidthKbps + 1;
1327 EXPECT_TRUE(channel_->SetMaxSendBandwidth(max_bandwidth_kbps * 1000));
1328 VerifyVP8SendCodec(channel_num, kVP8Codec.width, kVP8Codec.height, 0,
1329 max_bandwidth_kbps, kMinBandwidthKbps, start_bandwidth_kbps);
1330}
1331
wu@webrtc.org1e6cb2c2014-03-24 17:01:50 +00001332// Test that the start bandwidth can be controlled by experiment.
1333TEST_F(WebRtcVideoEngineTestFake, SetStartBandwidthOption) {
1334 EXPECT_TRUE(SetupEngine());
1335 int channel_num = vie_.GetLastChannel();
1336 EXPECT_TRUE(channel_->SetSendCodecs(engine_.codecs()));
1337 int start_bandwidth_kbps = kStartBandwidthKbps;
1338 EXPECT_TRUE(channel_->SetStartSendBandwidth(start_bandwidth_kbps * 1000));
1339 VerifyVP8SendCodec(channel_num, kVP8Codec.width, kVP8Codec.height, 0,
1340 kMaxBandwidthKbps, kMinBandwidthKbps, start_bandwidth_kbps);
1341
1342 // Set the start bitrate option.
1343 start_bandwidth_kbps = 1000;
1344 cricket::VideoOptions options;
1345 options.video_start_bitrate.Set(
1346 start_bandwidth_kbps);
1347 EXPECT_TRUE(channel_->SetOptions(options));
1348
1349 // Check that start bitrate has changed to the new value.
1350 VerifyVP8SendCodec(channel_num, kVP8Codec.width, kVP8Codec.height, 0,
1351 kMaxBandwidthKbps, kMinBandwidthKbps, start_bandwidth_kbps);
1352}
1353
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001354// Test that SetMaxSendBandwidth is ignored in conference mode.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001355TEST_F(WebRtcVideoEngineTestFake, SetBandwidthInConference) {
1356 EXPECT_TRUE(SetupEngine());
1357 int channel_num = vie_.GetLastChannel();
1358 cricket::VideoOptions options;
1359 options.conference_mode.Set(true);
1360 EXPECT_TRUE(channel_->SetOptions(options));
1361 EXPECT_TRUE(channel_->SetSendCodecs(engine_.codecs()));
1362 VerifyVP8SendCodec(channel_num, kVP8Codec.width, kVP8Codec.height);
1363
1364 // Set send bandwidth.
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001365 EXPECT_TRUE(channel_->SetMaxSendBandwidth(768000));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001366
1367 // Verify bitrate not changed.
1368 webrtc::VideoCodec gcodec;
1369 EXPECT_EQ(0, vie_.GetSendCodec(channel_num, gcodec));
1370 EXPECT_EQ(kMinBandwidthKbps, gcodec.minBitrate);
1371 EXPECT_EQ(kStartBandwidthKbps, gcodec.startBitrate);
1372 EXPECT_EQ(kMaxBandwidthKbps, gcodec.maxBitrate);
1373 EXPECT_NE(768U, gcodec.minBitrate);
1374 EXPECT_NE(768U, gcodec.startBitrate);
1375 EXPECT_NE(768U, gcodec.maxBitrate);
1376}
1377
1378// Test that sending screencast frames doesn't change bitrate.
1379TEST_F(WebRtcVideoEngineTestFake, SetBandwidthScreencast) {
1380 EXPECT_TRUE(SetupEngine());
1381 int channel_num = vie_.GetLastChannel();
1382
1383 // Set send codec.
1384 cricket::VideoCodec codec(kVP8Codec);
1385 std::vector<cricket::VideoCodec> codec_list;
1386 codec_list.push_back(codec);
1387 EXPECT_TRUE(channel_->AddSendStream(
1388 cricket::StreamParams::CreateLegacy(123)));
1389 EXPECT_TRUE(channel_->SetSendCodecs(codec_list));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001390 EXPECT_TRUE(channel_->SetMaxSendBandwidth(111000));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001391 EXPECT_TRUE(channel_->SetSend(true));
1392
1393 SendI420ScreencastFrame(kVP8Codec.width, kVP8Codec.height);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001394 VerifyVP8SendCodec(channel_num, kVP8Codec.width, kVP8Codec.height, 0, 111);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001395}
1396
1397
1398// Test SetSendSsrc.
1399TEST_F(WebRtcVideoEngineTestFake, SetSendSsrcAndCname) {
1400 EXPECT_TRUE(SetupEngine());
1401 int channel_num = vie_.GetLastChannel();
1402
1403 cricket::StreamParams stream;
1404 stream.ssrcs.push_back(1234);
1405 stream.cname = "cname";
1406 channel_->AddSendStream(stream);
1407
1408 unsigned int ssrc = 0;
1409 EXPECT_EQ(0, vie_.GetLocalSSRC(channel_num, ssrc));
1410 EXPECT_EQ(1234U, ssrc);
1411 EXPECT_EQ(1, vie_.GetNumSsrcs(channel_num));
1412
1413 char rtcp_cname[256];
1414 EXPECT_EQ(0, vie_.GetRTCPCName(channel_num, rtcp_cname));
1415 EXPECT_STREQ("cname", rtcp_cname);
1416}
1417
1418
1419// Test that the local SSRC is the same on sending and receiving channels if the
1420// receive channel is created before the send channel.
1421TEST_F(WebRtcVideoEngineTestFake, SetSendSsrcAfterCreatingReceiveChannel) {
1422 EXPECT_TRUE(SetupEngine());
1423
1424 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(1)));
1425 int receive_channel_num = vie_.GetLastChannel();
1426 cricket::StreamParams stream = cricket::StreamParams::CreateLegacy(1234);
1427 EXPECT_TRUE(channel_->AddSendStream(stream));
1428 int send_channel_num = vie_.GetLastChannel();
1429 unsigned int ssrc = 0;
1430 EXPECT_EQ(0, vie_.GetLocalSSRC(send_channel_num, ssrc));
1431 EXPECT_EQ(1234U, ssrc);
1432 EXPECT_EQ(1, vie_.GetNumSsrcs(send_channel_num));
1433 ssrc = 0;
1434 EXPECT_EQ(0, vie_.GetLocalSSRC(receive_channel_num, ssrc));
1435 EXPECT_EQ(1234U, ssrc);
1436 EXPECT_EQ(1, vie_.GetNumSsrcs(receive_channel_num));
1437}
1438
1439
1440// Test SetOptions with denoising flag.
1441TEST_F(WebRtcVideoEngineTestFake, SetOptionsWithDenoising) {
1442 EXPECT_TRUE(SetupEngine());
1443 EXPECT_EQ(1, vie_.GetNumCapturers());
1444 int channel_num = vie_.GetLastChannel();
1445 int capture_id = vie_.GetCaptureId(channel_num);
1446 // Set send codecs on the channel.
1447 std::vector<cricket::VideoCodec> codecs;
1448 codecs.push_back(kVP8Codec);
1449 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1450
1451 // Set options with OPT_VIDEO_NOISE_REDUCTION flag.
1452 cricket::VideoOptions options;
1453 options.video_noise_reduction.Set(true);
1454 EXPECT_TRUE(channel_->SetOptions(options));
1455
1456 // Verify capture has denoising turned on.
1457 webrtc::VideoCodec send_codec;
1458 memset(&send_codec, 0, sizeof(send_codec)); // avoid uninitialized warning
1459 EXPECT_EQ(0, vie_.GetSendCodec(channel_num, send_codec));
1460 EXPECT_TRUE(send_codec.codecSpecific.VP8.denoisingOn);
1461 EXPECT_FALSE(vie_.GetCaptureDenoising(capture_id));
1462
1463 // Set options back to zero.
1464 options.video_noise_reduction.Set(false);
1465 EXPECT_TRUE(channel_->SetOptions(options));
1466
1467 // Verify capture has denoising turned off.
1468 EXPECT_EQ(0, vie_.GetSendCodec(channel_num, send_codec));
1469 EXPECT_FALSE(send_codec.codecSpecific.VP8.denoisingOn);
1470 EXPECT_FALSE(vie_.GetCaptureDenoising(capture_id));
1471}
1472
wu@webrtc.orga8910d22014-01-23 22:12:45 +00001473TEST_F(WebRtcVideoEngineTestFake, MultipleSendStreamsWithOneCapturer) {
wu@webrtc.org24301a62013-12-13 19:17:43 +00001474 EXPECT_TRUE(SetupEngine());
1475
1476 // Start the capturer
1477 cricket::FakeVideoCapturer capturer;
1478 cricket::VideoFormat capture_format_vga = cricket::VideoFormat(640, 480,
1479 cricket::VideoFormat::FpsToInterval(30), cricket::FOURCC_I420);
1480 EXPECT_EQ(cricket::CS_RUNNING, capturer.Start(capture_format_vga));
1481
1482 // Add send streams and connect the capturer
1483 for (unsigned int i = 0; i < sizeof(kSsrcs2)/sizeof(kSsrcs2[0]); ++i) {
1484 EXPECT_TRUE(channel_->AddSendStream(
1485 cricket::StreamParams::CreateLegacy(kSsrcs2[i])));
1486 // Register the capturer to the ssrc.
1487 EXPECT_TRUE(channel_->SetCapturer(kSsrcs2[i], &capturer));
1488 }
1489
1490 const int channel0 = vie_.GetChannelFromLocalSsrc(kSsrcs2[0]);
1491 ASSERT_NE(-1, channel0);
1492 const int channel1 = vie_.GetChannelFromLocalSsrc(kSsrcs2[1]);
1493 ASSERT_NE(-1, channel1);
1494 ASSERT_NE(channel0, channel1);
1495
wu@webrtc.orgb9a088b2014-02-13 23:18:49 +00001496 // Both channels should have started receiving after created.
1497 EXPECT_TRUE(vie_.GetReceive(channel0));
1498 EXPECT_TRUE(vie_.GetReceive(channel1));
1499
wu@webrtc.org24301a62013-12-13 19:17:43 +00001500 // Set send codec.
1501 std::vector<cricket::VideoCodec> codecs;
1502 cricket::VideoCodec send_codec(100, "VP8", 640, 480, 30, 0);
1503 codecs.push_back(send_codec);
1504 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1505
wu@webrtc.orgb9a088b2014-02-13 23:18:49 +00001506 EXPECT_TRUE(channel_->SetSend(true));
1507 EXPECT_TRUE(vie_.GetSend(channel0));
1508 EXPECT_TRUE(vie_.GetSend(channel1));
1509
wu@webrtc.org24301a62013-12-13 19:17:43 +00001510 EXPECT_TRUE(capturer.CaptureFrame());
1511 EXPECT_EQ(1, vie_.GetIncomingFrameNum(channel0));
1512 EXPECT_EQ(1, vie_.GetIncomingFrameNum(channel1));
1513
1514 EXPECT_TRUE(channel_->RemoveSendStream(kSsrcs2[0]));
1515 EXPECT_TRUE(capturer.CaptureFrame());
1516 // channel0 is the default channel, so it won't be deleted.
1517 // But it should be disconnected from the capturer.
1518 EXPECT_EQ(1, vie_.GetIncomingFrameNum(channel0));
1519 EXPECT_EQ(2, vie_.GetIncomingFrameNum(channel1));
1520
1521 EXPECT_TRUE(channel_->RemoveSendStream(kSsrcs2[1]));
1522 EXPECT_TRUE(capturer.CaptureFrame());
1523 EXPECT_EQ(1, vie_.GetIncomingFrameNum(channel0));
1524 // channel1 has already been deleted.
1525 EXPECT_EQ(-1, vie_.GetIncomingFrameNum(channel1));
1526}
1527
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001528
wu@webrtc.org97077a32013-10-25 21:18:33 +00001529// Disabled since its flaky: b/11288120
1530TEST_F(WebRtcVideoEngineTestFake, DISABLED_SendReceiveBitratesStats) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001531 EXPECT_TRUE(SetupEngine());
1532 cricket::VideoOptions options;
1533 options.conference_mode.Set(true);
1534 EXPECT_TRUE(channel_->SetOptions(options));
1535 EXPECT_TRUE(channel_->AddSendStream(
1536 cricket::StreamParams::CreateLegacy(1)));
1537 int send_channel = vie_.GetLastChannel();
1538 cricket::VideoCodec codec(kVP8Codec720p);
1539 std::vector<cricket::VideoCodec> codec_list;
1540 codec_list.push_back(codec);
1541 EXPECT_TRUE(channel_->SetSendCodecs(codec_list));
1542
1543 EXPECT_TRUE(channel_->AddRecvStream(
1544 cricket::StreamParams::CreateLegacy(2)));
1545 int first_receive_channel = vie_.GetLastChannel();
1546 EXPECT_NE(send_channel, first_receive_channel);
1547 EXPECT_TRUE(channel_->AddRecvStream(
1548 cricket::StreamParams::CreateLegacy(3)));
1549 int second_receive_channel = vie_.GetLastChannel();
1550 EXPECT_NE(first_receive_channel, second_receive_channel);
1551
1552 cricket::VideoMediaInfo info;
wu@webrtc.orgb9a088b2014-02-13 23:18:49 +00001553 EXPECT_TRUE(channel_->GetStats(cricket::StatsOptions(), &info));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001554 ASSERT_EQ(1U, info.bw_estimations.size());
1555 ASSERT_EQ(0, info.bw_estimations[0].actual_enc_bitrate);
1556 ASSERT_EQ(0, info.bw_estimations[0].transmit_bitrate);
1557 ASSERT_EQ(0, info.bw_estimations[0].retransmit_bitrate);
1558 ASSERT_EQ(0, info.bw_estimations[0].available_send_bandwidth);
1559 ASSERT_EQ(0, info.bw_estimations[0].available_recv_bandwidth);
1560 ASSERT_EQ(0, info.bw_estimations[0].target_enc_bitrate);
1561
1562 // Start sending and receiving on one of the channels and verify bitrates.
1563 EXPECT_EQ(0, vie_.StartSend(send_channel));
1564 int send_video_bitrate = 800;
1565 int send_fec_bitrate = 100;
1566 int send_nack_bitrate = 20;
1567 int send_total_bitrate = send_video_bitrate + send_fec_bitrate +
1568 send_nack_bitrate;
1569 int send_bandwidth = 950;
1570 vie_.SetSendBitrates(send_channel, send_video_bitrate, send_fec_bitrate,
1571 send_nack_bitrate);
1572 vie_.SetSendBandwidthEstimate(send_channel, send_bandwidth);
1573
1574 EXPECT_EQ(0, vie_.StartReceive(first_receive_channel));
1575 int first_channel_receive_bandwidth = 600;
1576 vie_.SetReceiveBandwidthEstimate(first_receive_channel,
1577 first_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,
1587 info.bw_estimations[0].available_recv_bandwidth);
1588 ASSERT_EQ(send_video_bitrate, info.bw_estimations[0].target_enc_bitrate);
1589
1590 // Start receiving on the second channel and verify received rate.
1591 EXPECT_EQ(0, vie_.StartReceive(second_receive_channel));
1592 int second_channel_receive_bandwidth = 100;
1593 vie_.SetReceiveBandwidthEstimate(second_receive_channel,
1594 second_channel_receive_bandwidth);
1595
1596 info.Clear();
wu@webrtc.orgb9a088b2014-02-13 23:18:49 +00001597 EXPECT_TRUE(channel_->GetStats(cricket::StatsOptions(), &info));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001598 ASSERT_EQ(1U, info.bw_estimations.size());
1599 ASSERT_EQ(send_video_bitrate, info.bw_estimations[0].actual_enc_bitrate);
1600 ASSERT_EQ(send_total_bitrate, info.bw_estimations[0].transmit_bitrate);
1601 ASSERT_EQ(send_nack_bitrate, info.bw_estimations[0].retransmit_bitrate);
1602 ASSERT_EQ(send_bandwidth, info.bw_estimations[0].available_send_bandwidth);
1603 ASSERT_EQ(first_channel_receive_bandwidth + second_channel_receive_bandwidth,
1604 info.bw_estimations[0].available_recv_bandwidth);
1605 ASSERT_EQ(send_video_bitrate, info.bw_estimations[0].target_enc_bitrate);
1606}
1607
1608TEST_F(WebRtcVideoEngineTestFake, TestSetAdaptInputToCpuUsage) {
1609 EXPECT_TRUE(SetupEngine());
1610 cricket::VideoOptions options_in, options_out;
1611 bool cpu_adapt = false;
1612 channel_->SetOptions(options_in);
1613 EXPECT_TRUE(channel_->GetOptions(&options_out));
1614 EXPECT_FALSE(options_out.adapt_input_to_cpu_usage.Get(&cpu_adapt));
1615 // Set adapt input CPU usage option.
1616 options_in.adapt_input_to_cpu_usage.Set(true);
1617 EXPECT_TRUE(channel_->SetOptions(options_in));
1618 EXPECT_TRUE(channel_->GetOptions(&options_out));
1619 EXPECT_TRUE(options_out.adapt_input_to_cpu_usage.Get(&cpu_adapt));
1620 EXPECT_TRUE(cpu_adapt);
1621}
1622
1623TEST_F(WebRtcVideoEngineTestFake, TestSetCpuThreshold) {
1624 EXPECT_TRUE(SetupEngine());
1625 float low, high;
1626 cricket::VideoOptions options_in, options_out;
1627 // Verify that initial values are set.
1628 EXPECT_TRUE(channel_->GetOptions(&options_out));
1629 EXPECT_TRUE(options_out.system_low_adaptation_threshhold.Get(&low));
1630 EXPECT_EQ(low, 0.65f);
1631 EXPECT_TRUE(options_out.system_high_adaptation_threshhold.Get(&high));
1632 EXPECT_EQ(high, 0.85f);
1633 // Set new CPU threshold values.
1634 options_in.system_low_adaptation_threshhold.Set(0.45f);
1635 options_in.system_high_adaptation_threshhold.Set(0.95f);
1636 EXPECT_TRUE(channel_->SetOptions(options_in));
1637 EXPECT_TRUE(channel_->GetOptions(&options_out));
1638 EXPECT_TRUE(options_out.system_low_adaptation_threshhold.Get(&low));
1639 EXPECT_EQ(low, 0.45f);
1640 EXPECT_TRUE(options_out.system_high_adaptation_threshhold.Get(&high));
1641 EXPECT_EQ(high, 0.95f);
1642}
1643
1644TEST_F(WebRtcVideoEngineTestFake, TestSetInvalidCpuThreshold) {
1645 EXPECT_TRUE(SetupEngine());
1646 float low, high;
1647 cricket::VideoOptions options_in, options_out;
1648 // Valid range is [0, 1].
1649 options_in.system_low_adaptation_threshhold.Set(-1.5f);
1650 options_in.system_high_adaptation_threshhold.Set(1.5f);
1651 EXPECT_TRUE(channel_->SetOptions(options_in));
1652 EXPECT_TRUE(channel_->GetOptions(&options_out));
1653 EXPECT_TRUE(options_out.system_low_adaptation_threshhold.Get(&low));
1654 EXPECT_EQ(low, 0.0f);
1655 EXPECT_TRUE(options_out.system_high_adaptation_threshhold.Get(&high));
1656 EXPECT_EQ(high, 1.0f);
1657}
1658
1659
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +00001660TEST_F(WebRtcVideoEngineTestFake, ResetCodecOnScreencast) {
1661 EXPECT_TRUE(SetupEngine());
1662 cricket::VideoOptions options;
1663 options.video_noise_reduction.Set(true);
1664 EXPECT_TRUE(channel_->SetOptions(options));
1665
1666 // Set send codec.
1667 cricket::VideoCodec codec(kVP8Codec);
1668 std::vector<cricket::VideoCodec> codec_list;
1669 codec_list.push_back(codec);
1670 EXPECT_TRUE(channel_->AddSendStream(
1671 cricket::StreamParams::CreateLegacy(123)));
1672 EXPECT_TRUE(channel_->SetSendCodecs(codec_list));
1673 EXPECT_TRUE(channel_->SetSend(true));
wu@webrtc.org05e7b442014-04-01 17:44:24 +00001674 EXPECT_EQ(1, vie_.GetNumSetSendCodecs());
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +00001675
1676 webrtc::VideoCodec gcodec;
1677 memset(&gcodec, 0, sizeof(gcodec));
1678 int channel_num = vie_.GetLastChannel();
1679 EXPECT_EQ(0, vie_.GetSendCodec(channel_num, gcodec));
1680 EXPECT_TRUE(gcodec.codecSpecific.VP8.denoisingOn);
1681
1682 // Send a screencast frame with the same size.
1683 // Verify that denoising is turned off.
1684 SendI420ScreencastFrame(kVP8Codec.width, kVP8Codec.height);
wu@webrtc.org05e7b442014-04-01 17:44:24 +00001685 EXPECT_EQ(2, vie_.GetNumSetSendCodecs());
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +00001686 EXPECT_EQ(0, vie_.GetSendCodec(channel_num, gcodec));
1687 EXPECT_FALSE(gcodec.codecSpecific.VP8.denoisingOn);
1688}
1689
1690
1691TEST_F(WebRtcVideoEngineTestFake, DontRegisterDecoderIfFactoryIsNotGiven) {
1692 engine_.SetExternalDecoderFactory(NULL);
1693 EXPECT_TRUE(SetupEngine());
1694 int channel_num = vie_.GetLastChannel();
1695
1696 std::vector<cricket::VideoCodec> codecs;
1697 codecs.push_back(kVP8Codec);
1698 EXPECT_TRUE(channel_->SetRecvCodecs(codecs));
1699
1700 EXPECT_EQ(0, vie_.GetNumExternalDecoderRegistered(channel_num));
1701}
1702
1703TEST_F(WebRtcVideoEngineTestFake, RegisterDecoderIfFactoryIsGiven) {
1704 decoder_factory_.AddSupportedVideoCodecType(webrtc::kVideoCodecVP8);
1705 engine_.SetExternalDecoderFactory(&decoder_factory_);
1706 EXPECT_TRUE(SetupEngine());
1707 int channel_num = vie_.GetLastChannel();
1708
1709 std::vector<cricket::VideoCodec> codecs;
1710 codecs.push_back(kVP8Codec);
1711 EXPECT_TRUE(channel_->SetRecvCodecs(codecs));
1712
1713 EXPECT_TRUE(vie_.ExternalDecoderRegistered(channel_num, 100));
1714 EXPECT_EQ(1, vie_.GetNumExternalDecoderRegistered(channel_num));
1715}
1716
1717TEST_F(WebRtcVideoEngineTestFake, DontRegisterDecoderMultipleTimes) {
1718 decoder_factory_.AddSupportedVideoCodecType(webrtc::kVideoCodecVP8);
1719 engine_.SetExternalDecoderFactory(&decoder_factory_);
1720 EXPECT_TRUE(SetupEngine());
1721 int channel_num = vie_.GetLastChannel();
1722
1723 std::vector<cricket::VideoCodec> codecs;
1724 codecs.push_back(kVP8Codec);
1725 EXPECT_TRUE(channel_->SetRecvCodecs(codecs));
1726
1727 EXPECT_TRUE(vie_.ExternalDecoderRegistered(channel_num, 100));
1728 EXPECT_EQ(1, vie_.GetNumExternalDecoderRegistered(channel_num));
1729 EXPECT_EQ(1, decoder_factory_.GetNumCreatedDecoders());
1730
1731 EXPECT_TRUE(channel_->SetRecvCodecs(codecs));
1732 EXPECT_EQ(1, vie_.GetNumExternalDecoderRegistered(channel_num));
1733 EXPECT_EQ(1, decoder_factory_.GetNumCreatedDecoders());
1734}
1735
1736TEST_F(WebRtcVideoEngineTestFake, DontRegisterDecoderForNonVP8) {
1737 decoder_factory_.AddSupportedVideoCodecType(webrtc::kVideoCodecVP8);
1738 engine_.SetExternalDecoderFactory(&decoder_factory_);
1739 EXPECT_TRUE(SetupEngine());
1740 int channel_num = vie_.GetLastChannel();
1741
1742 std::vector<cricket::VideoCodec> codecs;
1743 codecs.push_back(kRedCodec);
1744 EXPECT_TRUE(channel_->SetRecvCodecs(codecs));
1745
1746 EXPECT_EQ(0, vie_.GetNumExternalDecoderRegistered(channel_num));
1747}
1748
1749TEST_F(WebRtcVideoEngineTestFake, DontRegisterEncoderIfFactoryIsNotGiven) {
1750 engine_.SetExternalEncoderFactory(NULL);
1751 EXPECT_TRUE(SetupEngine());
1752 int channel_num = vie_.GetLastChannel();
1753
1754 std::vector<cricket::VideoCodec> codecs;
1755 codecs.push_back(kVP8Codec);
1756 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1757
1758 EXPECT_EQ(0, vie_.GetNumExternalEncoderRegistered(channel_num));
1759}
1760
1761TEST_F(WebRtcVideoEngineTestFake, RegisterEncoderIfFactoryIsGiven) {
1762 encoder_factory_.AddSupportedVideoCodecType(webrtc::kVideoCodecVP8, "VP8");
1763 engine_.SetExternalEncoderFactory(&encoder_factory_);
1764 EXPECT_TRUE(SetupEngine());
1765 int channel_num = vie_.GetLastChannel();
1766
1767 std::vector<cricket::VideoCodec> codecs;
1768 codecs.push_back(kVP8Codec);
1769 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1770
1771 EXPECT_TRUE(channel_->AddSendStream(
1772 cricket::StreamParams::CreateLegacy(kSsrc)));
1773
1774 EXPECT_TRUE(vie_.ExternalEncoderRegistered(channel_num, 100));
1775 EXPECT_EQ(1, vie_.GetNumExternalEncoderRegistered(channel_num));
1776
1777 // Remove stream previously added to free the external encoder instance.
1778 EXPECT_TRUE(channel_->RemoveSendStream(kSsrc));
1779}
1780
1781TEST_F(WebRtcVideoEngineTestFake, DontRegisterEncoderMultipleTimes) {
1782 encoder_factory_.AddSupportedVideoCodecType(webrtc::kVideoCodecVP8, "VP8");
1783 engine_.SetExternalEncoderFactory(&encoder_factory_);
1784 EXPECT_TRUE(SetupEngine());
1785 int channel_num = vie_.GetLastChannel();
1786
1787 std::vector<cricket::VideoCodec> codecs;
1788 codecs.push_back(kVP8Codec);
1789 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1790
1791 EXPECT_TRUE(channel_->AddSendStream(
1792 cricket::StreamParams::CreateLegacy(kSsrc)));
1793
1794 EXPECT_TRUE(vie_.ExternalEncoderRegistered(channel_num, 100));
1795 EXPECT_EQ(1, vie_.GetNumExternalEncoderRegistered(channel_num));
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +00001796
1797 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1798 EXPECT_EQ(1, vie_.GetNumExternalEncoderRegistered(channel_num));
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +00001799
1800 // Remove stream previously added to free the external encoder instance.
1801 EXPECT_TRUE(channel_->RemoveSendStream(kSsrc));
1802}
1803
1804TEST_F(WebRtcVideoEngineTestFake, RegisterEncoderWithMultipleSendStreams) {
1805 encoder_factory_.AddSupportedVideoCodecType(webrtc::kVideoCodecVP8, "VP8");
1806 engine_.SetExternalEncoderFactory(&encoder_factory_);
1807 EXPECT_TRUE(SetupEngine());
1808
1809 std::vector<cricket::VideoCodec> codecs;
1810 codecs.push_back(kVP8Codec);
1811 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1812 EXPECT_EQ(1, vie_.GetTotalNumExternalEncoderRegistered());
1813
1814 // When we add the first stream (1234), it reuses the default send channel,
1815 // so it doesn't increase the registration count of external encoders.
1816 EXPECT_TRUE(channel_->AddSendStream(
1817 cricket::StreamParams::CreateLegacy(1234)));
1818 EXPECT_EQ(1, vie_.GetTotalNumExternalEncoderRegistered());
1819
1820 // When we add the second stream (2345), it creates a new channel and
1821 // increments the registration count.
1822 EXPECT_TRUE(channel_->AddSendStream(
1823 cricket::StreamParams::CreateLegacy(2345)));
1824 EXPECT_EQ(2, vie_.GetTotalNumExternalEncoderRegistered());
1825
1826 // At this moment the total registration count is two, but only one encoder
1827 // is registered per channel.
1828 int channel_num = vie_.GetLastChannel();
1829 EXPECT_EQ(1, vie_.GetNumExternalEncoderRegistered(channel_num));
1830
1831 // Removing send streams decrements the registration count.
1832 EXPECT_TRUE(channel_->RemoveSendStream(1234));
1833 EXPECT_EQ(1, vie_.GetTotalNumExternalEncoderRegistered());
1834
1835 // When we remove the last send stream, it also destroys the last send
1836 // channel and causes the registration count to drop to zero. It is a little
1837 // weird, but not a bug.
1838 EXPECT_TRUE(channel_->RemoveSendStream(2345));
1839 EXPECT_EQ(0, vie_.GetTotalNumExternalEncoderRegistered());
1840}
1841
1842TEST_F(WebRtcVideoEngineTestFake, DontRegisterEncoderForNonVP8) {
1843 encoder_factory_.AddSupportedVideoCodecType(webrtc::kVideoCodecGeneric,
1844 "GENERIC");
1845 engine_.SetExternalEncoderFactory(&encoder_factory_);
1846 EXPECT_TRUE(SetupEngine());
1847 int channel_num = vie_.GetLastChannel();
1848
1849 // Note: unlike the SetRecvCodecs, we must set a valid video codec for
1850 // channel_->SetSendCodecs() to succeed.
1851 std::vector<cricket::VideoCodec> codecs;
1852 codecs.push_back(kVP8Codec);
1853 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1854
1855 EXPECT_EQ(0, vie_.GetNumExternalEncoderRegistered(channel_num));
1856}
1857
1858// Test that NACK, PLI and REMB are enabled for external codec.
1859TEST_F(WebRtcVideoEngineTestFake, ExternalCodecFeedbackParams) {
1860 encoder_factory_.AddSupportedVideoCodecType(webrtc::kVideoCodecGeneric,
1861 "GENERIC");
1862 engine_.SetExternalEncoderFactory(&encoder_factory_);
1863 encoder_factory_.NotifyCodecsAvailable();
1864 EXPECT_TRUE(SetupEngine());
1865
1866 std::vector<cricket::VideoCodec> codecs(engine_.codecs());
1867 // The external codec will appear at last.
1868 size_t pos = codecs.size() - 1;
1869 EXPECT_EQ("GENERIC", codecs[pos].name);
1870 VerifyCodecFeedbackParams(codecs[pos]);
1871}
1872
1873// Test external codec with be added to the end of the supported codec list.
1874TEST_F(WebRtcVideoEngineTestFake, ExternalCodecAddedToTheEnd) {
1875 EXPECT_TRUE(SetupEngine());
1876
1877 std::vector<cricket::VideoCodec> codecs(engine_.codecs());
1878 EXPECT_EQ("VP8", codecs[0].name);
1879
1880 encoder_factory_.AddSupportedVideoCodecType(webrtc::kVideoCodecGeneric,
1881 "GENERIC");
1882 engine_.SetExternalEncoderFactory(&encoder_factory_);
1883 encoder_factory_.NotifyCodecsAvailable();
1884
1885 codecs = engine_.codecs();
1886 cricket::VideoCodec internal_codec = codecs[0];
1887 cricket::VideoCodec external_codec = codecs[codecs.size() - 1];
1888 // The external codec will appear at last.
1889 EXPECT_EQ("GENERIC", external_codec.name);
1890 // The internal codec is preferred.
1891 EXPECT_GE(internal_codec.preference, external_codec.preference);
1892}
1893
1894// Test that external codec with be ignored if it has the same name as one of
1895// the internal codecs.
1896TEST_F(WebRtcVideoEngineTestFake, ExternalCodecIgnored) {
1897 EXPECT_TRUE(SetupEngine());
1898
1899 std::vector<cricket::VideoCodec> internal_codecs(engine_.codecs());
1900 EXPECT_EQ("VP8", internal_codecs[0].name);
1901
1902 encoder_factory_.AddSupportedVideoCodecType(webrtc::kVideoCodecVP8, "VP8");
1903 engine_.SetExternalEncoderFactory(&encoder_factory_);
1904 encoder_factory_.NotifyCodecsAvailable();
1905
1906 std::vector<cricket::VideoCodec> codecs = engine_.codecs();
1907 EXPECT_EQ("VP8", codecs[0].name);
1908 EXPECT_EQ(internal_codecs[0].height, codecs[0].height);
1909 EXPECT_EQ(internal_codecs[0].width, codecs[0].width);
1910 // Verify the last codec is not the external codec.
1911 EXPECT_NE("VP8", codecs[codecs.size() - 1].name);
1912}
1913
1914TEST_F(WebRtcVideoEngineTestFake, UpdateEncoderCodecsAfterSetFactory) {
1915 engine_.SetExternalEncoderFactory(&encoder_factory_);
1916 EXPECT_TRUE(SetupEngine());
1917 int channel_num = vie_.GetLastChannel();
1918
1919 encoder_factory_.AddSupportedVideoCodecType(webrtc::kVideoCodecVP8, "VP8");
1920 encoder_factory_.NotifyCodecsAvailable();
1921 std::vector<cricket::VideoCodec> codecs;
1922 codecs.push_back(kVP8Codec);
1923 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1924
1925 EXPECT_TRUE(channel_->AddSendStream(
1926 cricket::StreamParams::CreateLegacy(kSsrc)));
1927
1928 EXPECT_TRUE(vie_.ExternalEncoderRegistered(channel_num, 100));
1929 EXPECT_EQ(1, vie_.GetNumExternalEncoderRegistered(channel_num));
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +00001930
1931 // Remove stream previously added to free the external encoder instance.
1932 EXPECT_TRUE(channel_->RemoveSendStream(kSsrc));
1933}
1934
1935// Tests that OnReadyToSend will be propagated into ViE.
1936TEST_F(WebRtcVideoEngineTestFake, OnReadyToSend) {
1937 EXPECT_TRUE(SetupEngine());
1938 int channel_num = vie_.GetLastChannel();
1939 EXPECT_TRUE(vie_.GetIsTransmitting(channel_num));
1940
1941 channel_->OnReadyToSend(false);
1942 EXPECT_FALSE(vie_.GetIsTransmitting(channel_num));
1943
1944 channel_->OnReadyToSend(true);
1945 EXPECT_TRUE(vie_.GetIsTransmitting(channel_num));
1946}
1947
1948#if 0
1949TEST_F(WebRtcVideoEngineTestFake, CaptureFrameTimestampToNtpTimestamp) {
1950 EXPECT_TRUE(SetupEngine());
1951 int capture_id = vie_.GetCaptureId(vie_.GetLastChannel());
1952
1953 // Set send codec.
1954 cricket::VideoCodec codec(kVP8Codec);
1955 std::vector<cricket::VideoCodec> codec_list;
1956 codec_list.push_back(codec);
1957 EXPECT_TRUE(channel_->AddSendStream(
1958 cricket::StreamParams::CreateLegacy(123)));
1959 EXPECT_TRUE(channel_->SetSendCodecs(codec_list));
1960 EXPECT_TRUE(channel_->SetSend(true));
1961
1962 int64 timestamp = time(NULL) * talk_base::kNumNanosecsPerSec;
1963 SendI420ScreencastFrameWithTimestamp(
1964 kVP8Codec.width, kVP8Codec.height, timestamp);
1965 EXPECT_EQ(talk_base::UnixTimestampNanosecsToNtpMillisecs(timestamp),
1966 vie_.GetCaptureLastTimestamp(capture_id));
1967
1968 SendI420ScreencastFrameWithTimestamp(kVP8Codec.width, kVP8Codec.height, 0);
1969 EXPECT_EQ(0, vie_.GetCaptureLastTimestamp(capture_id));
1970}
1971#endif
1972
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001973/////////////////////////
1974// Tests with real ViE //
1975/////////////////////////
1976
1977// Tests that we can find codecs by name or id.
1978TEST_F(WebRtcVideoEngineTest, FindCodec) {
1979 // We should not need to init engine in order to get codecs.
1980 const std::vector<cricket::VideoCodec>& c = engine_.codecs();
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +00001981 EXPECT_EQ(4U, c.size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001982
1983 cricket::VideoCodec vp8(104, "VP8", 320, 200, 30, 0);
1984 EXPECT_TRUE(engine_.FindCodec(vp8));
1985
1986 cricket::VideoCodec vp8_ci(104, "vp8", 320, 200, 30, 0);
1987 EXPECT_TRUE(engine_.FindCodec(vp8));
1988
1989 cricket::VideoCodec vp8_diff_fr_diff_pref(104, "VP8", 320, 200, 50, 50);
1990 EXPECT_TRUE(engine_.FindCodec(vp8_diff_fr_diff_pref));
1991
1992 cricket::VideoCodec vp8_diff_id(95, "VP8", 320, 200, 30, 0);
1993 EXPECT_FALSE(engine_.FindCodec(vp8_diff_id));
1994 vp8_diff_id.id = 97;
1995 EXPECT_TRUE(engine_.FindCodec(vp8_diff_id));
1996
1997 cricket::VideoCodec vp8_diff_res(104, "VP8", 320, 111, 30, 0);
1998 EXPECT_FALSE(engine_.FindCodec(vp8_diff_res));
1999
2000 // PeerConnection doesn't negotiate the resolution at this point.
2001 // Test that FindCodec can handle the case when width/height is 0.
2002 cricket::VideoCodec vp8_zero_res(104, "VP8", 0, 0, 30, 0);
2003 EXPECT_TRUE(engine_.FindCodec(vp8_zero_res));
2004
2005 cricket::VideoCodec red(101, "RED", 0, 0, 30, 0);
2006 EXPECT_TRUE(engine_.FindCodec(red));
2007
2008 cricket::VideoCodec red_ci(101, "red", 0, 0, 30, 0);
2009 EXPECT_TRUE(engine_.FindCodec(red));
2010
2011 cricket::VideoCodec fec(102, "ULPFEC", 0, 0, 30, 0);
2012 EXPECT_TRUE(engine_.FindCodec(fec));
2013
2014 cricket::VideoCodec fec_ci(102, "ulpfec", 0, 0, 30, 0);
2015 EXPECT_TRUE(engine_.FindCodec(fec));
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +00002016
2017 cricket::VideoCodec rtx(96, "rtx", 0, 0, 30, 0);
2018 EXPECT_TRUE(engine_.FindCodec(rtx));
2019}
2020
2021TEST_F(WebRtcVideoEngineTest, RtxCodecHasAptSet) {
2022 std::vector<cricket::VideoCodec>::const_iterator it;
2023 bool apt_checked = false;
2024 for (it = engine_.codecs().begin(); it != engine_.codecs().end(); ++it) {
2025 if (_stricmp(cricket::kRtxCodecName, it->name.c_str()) && it->id != 96) {
2026 continue;
2027 }
2028 int apt;
2029 EXPECT_TRUE(it->GetParam("apt", &apt));
2030 EXPECT_EQ(100, apt);
2031 apt_checked = true;
2032 }
2033 EXPECT_TRUE(apt_checked);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002034}
2035
2036TEST_F(WebRtcVideoEngineTest, StartupShutdown) {
2037 EXPECT_TRUE(engine_.Init(talk_base::Thread::Current()));
2038 engine_.Terminate();
2039}
2040
2041TEST_PRE_VIDEOENGINE_INIT(WebRtcVideoEngineTest, ConstrainNewCodec)
2042TEST_POST_VIDEOENGINE_INIT(WebRtcVideoEngineTest, ConstrainNewCodec)
2043
2044TEST_PRE_VIDEOENGINE_INIT(WebRtcVideoEngineTest, ConstrainRunningCodec)
2045TEST_POST_VIDEOENGINE_INIT(WebRtcVideoEngineTest, ConstrainRunningCodec)
2046
2047// TODO(juberti): Figure out why ViE is munging the COM refcount.
2048#ifdef WIN32
2049TEST_F(WebRtcVideoEngineTest, DISABLED_CheckCoInitialize) {
2050 Base::CheckCoInitialize();
2051}
2052#endif
2053
2054TEST_F(WebRtcVideoEngineTest, CreateChannel) {
2055 EXPECT_TRUE(engine_.Init(talk_base::Thread::Current()));
2056 cricket::VideoMediaChannel* channel = engine_.CreateChannel(NULL);
2057 EXPECT_TRUE(channel != NULL);
2058 delete channel;
2059}
2060
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002061TEST_F(WebRtcVideoMediaChannelTest, SetRecvCodecs) {
2062 std::vector<cricket::VideoCodec> codecs;
2063 codecs.push_back(kVP8Codec);
2064 EXPECT_TRUE(channel_->SetRecvCodecs(codecs));
2065}
2066TEST_F(WebRtcVideoMediaChannelTest, SetRecvCodecsWrongPayloadType) {
2067 std::vector<cricket::VideoCodec> codecs;
2068 codecs.push_back(kVP8Codec);
2069 codecs[0].id = 99;
2070 EXPECT_TRUE(channel_->SetRecvCodecs(codecs));
2071}
2072TEST_F(WebRtcVideoMediaChannelTest, SetRecvCodecsUnsupportedCodec) {
2073 std::vector<cricket::VideoCodec> codecs;
2074 codecs.push_back(kVP8Codec);
2075 codecs.push_back(cricket::VideoCodec(101, "VP1", 640, 400, 30, 0));
2076 EXPECT_FALSE(channel_->SetRecvCodecs(codecs));
2077}
2078
mallinath@webrtc.org92fdfeb2014-02-17 18:49:41 +00002079TEST_F(WebRtcVideoMediaChannelTest, GetRtpSendTimeExtension) {
2080 // Enable RTP timestamp extension.
2081 const int id = 12;
2082 std::vector<cricket::RtpHeaderExtension> extensions;
2083 extensions.push_back(cricket::RtpHeaderExtension(
2084 "http://www.webrtc.org/experiments/rtp-hdrext/abs-send-time", id));
2085
2086 // Verify the send extension id.
2087 EXPECT_TRUE(channel_->SetSendRtpHeaderExtensions(extensions));
2088 EXPECT_EQ(id, channel_->GetRtpSendTimeExtnId());
2089}
2090
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002091TEST_F(WebRtcVideoMediaChannelTest, SetSend) {
2092 Base::SetSend();
2093}
2094TEST_F(WebRtcVideoMediaChannelTest, SetSendWithoutCodecs) {
2095 Base::SetSendWithoutCodecs();
2096}
2097TEST_F(WebRtcVideoMediaChannelTest, SetSendSetsTransportBufferSizes) {
2098 Base::SetSendSetsTransportBufferSizes();
2099}
2100
2101TEST_F(WebRtcVideoMediaChannelTest, SendAndReceiveVp8Vga) {
2102 SendAndReceive(cricket::VideoCodec(100, "VP8", 640, 400, 30, 0));
2103}
2104TEST_F(WebRtcVideoMediaChannelTest, SendAndReceiveVp8Qvga) {
2105 SendAndReceive(cricket::VideoCodec(100, "VP8", 320, 200, 30, 0));
2106}
2107TEST_F(WebRtcVideoMediaChannelTest, SendAndReceiveH264SvcQqvga) {
2108 SendAndReceive(cricket::VideoCodec(100, "VP8", 160, 100, 30, 0));
2109}
2110TEST_F(WebRtcVideoMediaChannelTest, SendManyResizeOnce) {
2111 SendManyResizeOnce();
2112}
2113
2114TEST_F(WebRtcVideoMediaChannelTest, SendVp8HdAndReceiveAdaptedVp8Vga) {
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00002115 EXPECT_TRUE(channel_->SetCapturer(kSsrc, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002116 channel_->UpdateAspectRatio(1280, 720);
2117 video_capturer_.reset(new cricket::FakeVideoCapturer);
2118 const std::vector<cricket::VideoFormat>* formats =
2119 video_capturer_->GetSupportedFormats();
2120 cricket::VideoFormat capture_format_hd = (*formats)[0];
2121 EXPECT_EQ(cricket::CS_RUNNING, video_capturer_->Start(capture_format_hd));
2122 EXPECT_TRUE(channel_->SetCapturer(kSsrc, video_capturer_.get()));
2123
2124 // Capture format HD -> adapt (OnOutputFormatRequest VGA) -> VGA.
2125 cricket::VideoCodec codec(100, "VP8", 1280, 720, 30, 0);
2126 EXPECT_TRUE(SetOneCodec(codec));
2127 codec.width /= 2;
2128 codec.height /= 2;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002129 EXPECT_TRUE(SetSend(true));
2130 EXPECT_TRUE(channel_->SetRender(true));
2131 EXPECT_EQ(0, renderer_.num_rendered_frames());
2132 EXPECT_TRUE(SendFrame());
2133 EXPECT_FRAME_WAIT(1, codec.width, codec.height, kTimeout);
2134}
2135
2136// TODO(juberti): Fix this test to tolerate missing stats.
2137TEST_F(WebRtcVideoMediaChannelTest, DISABLED_GetStats) {
2138 Base::GetStats();
2139}
2140
2141// TODO(juberti): Fix this test to tolerate missing stats.
2142TEST_F(WebRtcVideoMediaChannelTest, DISABLED_GetStatsMultipleRecvStreams) {
2143 Base::GetStatsMultipleRecvStreams();
2144}
2145
2146TEST_F(WebRtcVideoMediaChannelTest, GetStatsMultipleSendStreams) {
2147 Base::GetStatsMultipleSendStreams();
2148}
2149
2150TEST_F(WebRtcVideoMediaChannelTest, SetSendBandwidth) {
2151 Base::SetSendBandwidth();
2152}
2153TEST_F(WebRtcVideoMediaChannelTest, SetSendSsrc) {
2154 Base::SetSendSsrc();
2155}
2156TEST_F(WebRtcVideoMediaChannelTest, SetSendSsrcAfterSetCodecs) {
2157 Base::SetSendSsrcAfterSetCodecs();
2158}
2159
2160TEST_F(WebRtcVideoMediaChannelTest, SetRenderer) {
2161 Base::SetRenderer();
2162}
2163
2164TEST_F(WebRtcVideoMediaChannelTest, AddRemoveRecvStreams) {
2165 Base::AddRemoveRecvStreams();
2166}
2167
2168TEST_F(WebRtcVideoMediaChannelTest, AddRemoveRecvStreamAndRender) {
2169 Base::AddRemoveRecvStreamAndRender();
2170}
2171
2172TEST_F(WebRtcVideoMediaChannelTest, AddRemoveRecvStreamsNoConference) {
2173 Base::AddRemoveRecvStreamsNoConference();
2174}
2175
2176TEST_F(WebRtcVideoMediaChannelTest, AddRemoveSendStreams) {
2177 Base::AddRemoveSendStreams();
2178}
2179
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002180TEST_F(WebRtcVideoMediaChannelTest, SimulateConference) {
2181 Base::SimulateConference();
2182}
2183
2184TEST_F(WebRtcVideoMediaChannelTest, AddRemoveCapturer) {
2185 Base::AddRemoveCapturer();
2186}
2187
2188TEST_F(WebRtcVideoMediaChannelTest, RemoveCapturerWithoutAdd) {
2189 Base::RemoveCapturerWithoutAdd();
2190}
2191
2192TEST_F(WebRtcVideoMediaChannelTest, AddRemoveCapturerMultipleSources) {
2193 Base::AddRemoveCapturerMultipleSources();
2194}
2195
wu@webrtc.orgde305012013-10-31 15:40:38 +00002196// This test verifies DSCP settings are properly applied on video media channel.
2197TEST_F(WebRtcVideoMediaChannelTest, TestSetDscpOptions) {
2198 talk_base::scoped_ptr<cricket::FakeNetworkInterface> network_interface(
2199 new cricket::FakeNetworkInterface);
2200 channel_->SetInterface(network_interface.get());
2201 cricket::VideoOptions options;
2202 options.dscp.Set(true);
2203 EXPECT_TRUE(channel_->SetOptions(options));
2204 EXPECT_EQ(talk_base::DSCP_AF41, network_interface->dscp());
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +00002205 // Verify previous value is not modified if dscp option is not set.
2206 cricket::VideoOptions options1;
2207 EXPECT_TRUE(channel_->SetOptions(options1));
2208 EXPECT_EQ(talk_base::DSCP_AF41, network_interface->dscp());
wu@webrtc.orgde305012013-10-31 15:40:38 +00002209 options.dscp.Set(false);
2210 EXPECT_TRUE(channel_->SetOptions(options));
2211 EXPECT_EQ(talk_base::DSCP_DEFAULT, network_interface->dscp());
2212 channel_->SetInterface(NULL);
2213}
2214
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002215
2216TEST_F(WebRtcVideoMediaChannelTest, SetOptionsSucceedsWhenSending) {
2217 cricket::VideoOptions options;
2218 options.conference_mode.Set(true);
2219 EXPECT_TRUE(channel_->SetOptions(options));
2220
2221 // Verify SetOptions returns true on a different options.
2222 cricket::VideoOptions options2;
2223 options2.adapt_input_to_cpu_usage.Set(true);
2224 EXPECT_TRUE(channel_->SetOptions(options2));
2225
2226 // Set send codecs on the channel and start sending.
2227 std::vector<cricket::VideoCodec> codecs;
2228 codecs.push_back(kVP8Codec);
2229 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
2230 EXPECT_TRUE(channel_->SetSend(true));
2231
2232 // Verify SetOptions returns true if channel is already sending.
2233 cricket::VideoOptions options3;
2234 options3.conference_mode.Set(true);
2235 EXPECT_TRUE(channel_->SetOptions(options3));
2236}
2237
2238// Tests empty StreamParams is rejected.
2239TEST_F(WebRtcVideoMediaChannelTest, RejectEmptyStreamParams) {
2240 Base::RejectEmptyStreamParams();
2241}
2242
2243
2244TEST_F(WebRtcVideoMediaChannelTest, AdaptResolution16x10) {
2245 Base::AdaptResolution16x10();
2246}
2247
2248TEST_F(WebRtcVideoMediaChannelTest, AdaptResolution4x3) {
2249 Base::AdaptResolution4x3();
2250}
2251
2252TEST_F(WebRtcVideoMediaChannelTest, MuteStream) {
2253 Base::MuteStream();
2254}
2255
2256TEST_F(WebRtcVideoMediaChannelTest, MultipleSendStreams) {
2257 Base::MultipleSendStreams();
2258}
2259
2260// TODO(juberti): Restore this test once we support sending 0 fps.
2261TEST_F(WebRtcVideoMediaChannelTest, DISABLED_AdaptDropAllFrames) {
2262 Base::AdaptDropAllFrames();
2263}
2264// TODO(juberti): Understand why we get decode errors on this test.
2265TEST_F(WebRtcVideoMediaChannelTest, DISABLED_AdaptFramerate) {
2266 Base::AdaptFramerate();
2267}
2268
2269TEST_F(WebRtcVideoMediaChannelTest, SetSendStreamFormat0x0) {
2270 Base::SetSendStreamFormat0x0();
2271}
2272
2273// TODO(zhurunz): Fix the flakey test.
2274TEST_F(WebRtcVideoMediaChannelTest, DISABLED_SetSendStreamFormat) {
2275 Base::SetSendStreamFormat();
2276}
2277
2278TEST_F(WebRtcVideoMediaChannelTest, TwoStreamsSendAndReceive) {
2279 Base::TwoStreamsSendAndReceive(cricket::VideoCodec(100, "VP8", 640, 400, 30,
2280 0));
2281}
2282
2283TEST_F(WebRtcVideoMediaChannelTest, TwoStreamsReUseFirstStream) {
2284 Base::TwoStreamsReUseFirstStream(cricket::VideoCodec(100, "VP8", 640, 400, 30,
2285 0));
2286}
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00002287
buildbot@webrtc.org0b3c6c32014-04-17 10:03:57 +00002288TEST_F(WebRtcVideoMediaChannelTest, DISABLED_TwoStreamsSendAndUnsignalledRecv) {
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00002289 Base::TwoStreamsSendAndUnsignalledRecv(cricket::VideoCodec(100, "VP8", 640,
2290 400, 30, 0));
2291}
2292
henrike@webrtc.org806768a2014-02-27 21:03:09 +00002293TEST_F(WebRtcVideoMediaChannelTest,
henrike@webrtc.org18e59112014-03-14 17:19:38 +00002294 TwoStreamsSendAndFailUnsignalledRecv) {
henrike@webrtc.org806768a2014-02-27 21:03:09 +00002295 webrtc::Trace::set_level_filter(webrtc::kTraceAll);
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00002296 Base::TwoStreamsSendAndFailUnsignalledRecv(
2297 cricket::VideoCodec(100, "VP8", 640, 400, 30, 0));
2298}
2299
2300TEST_F(WebRtcVideoMediaChannelTest,
henrike@webrtc.org18e59112014-03-14 17:19:38 +00002301 TwoStreamsSendAndFailUnsignalledRecvInOneToOne) {
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00002302 Base::TwoStreamsSendAndFailUnsignalledRecvInOneToOne(
2303 cricket::VideoCodec(100, "VP8", 640, 400, 30, 0));
2304}
2305
2306TEST_F(WebRtcVideoMediaChannelTest,
henrike@webrtc.org18e59112014-03-14 17:19:38 +00002307 TwoStreamsAddAndRemoveUnsignalledRecv) {
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00002308 Base::TwoStreamsAddAndRemoveUnsignalledRecv(cricket::VideoCodec(100, "VP8",
2309 640, 400, 30,
2310 0));
2311}