blob: 32e742c2f975895f21e130a831d38dc7977d4047 [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 +0000942#ifdef USE_WEBRTC_DEV_BRANCH
943TEST_F(WebRtcVideoEngineTestFake, SetCpuOveruseOptionsWithCaptureJitterMethod) {
944 EXPECT_TRUE(SetupEngine());
945
946 // Verify this is off by default.
947 EXPECT_TRUE(channel_->AddSendStream(cricket::StreamParams::CreateLegacy(1)));
948 int first_send_channel = vie_.GetLastChannel();
949 webrtc::CpuOveruseOptions cpu_option =
950 vie_.GetCpuOveruseOptions(first_send_channel);
951 EXPECT_EQ(0, cpu_option.low_capture_jitter_threshold_ms);
952 EXPECT_EQ(0, cpu_option.high_capture_jitter_threshold_ms);
953 EXPECT_FALSE(cpu_option.enable_capture_jitter_method);
954 EXPECT_FALSE(cpu_option.enable_encode_usage_method);
955
956 // Set low and high threshold and verify that cpu options are set.
957 cricket::VideoOptions options;
958 options.conference_mode.Set(true);
959 options.cpu_underuse_threshold.Set(10);
960 options.cpu_overuse_threshold.Set(20);
961 EXPECT_TRUE(channel_->SetOptions(options));
962 cpu_option = vie_.GetCpuOveruseOptions(first_send_channel);
963 EXPECT_EQ(10, cpu_option.low_capture_jitter_threshold_ms);
964 EXPECT_EQ(20, cpu_option.high_capture_jitter_threshold_ms);
965 EXPECT_TRUE(cpu_option.enable_capture_jitter_method);
966 EXPECT_FALSE(cpu_option.enable_encode_usage_method);
967
968 // Add a receive channel and verify that cpu options are not set.
969 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(2)));
970 int recv_channel_num = vie_.GetLastChannel();
971 EXPECT_NE(first_send_channel, recv_channel_num);
972 cpu_option = vie_.GetCpuOveruseOptions(recv_channel_num);
973 EXPECT_EQ(0, cpu_option.low_capture_jitter_threshold_ms);
974 EXPECT_EQ(0, cpu_option.high_capture_jitter_threshold_ms);
975 EXPECT_FALSE(cpu_option.enable_capture_jitter_method);
976 EXPECT_FALSE(cpu_option.enable_encode_usage_method);
977
978 // Add a new send stream and verify that cpu options are set from start.
979 EXPECT_TRUE(channel_->AddSendStream(cricket::StreamParams::CreateLegacy(3)));
980 int second_send_channel = vie_.GetLastChannel();
981 EXPECT_NE(first_send_channel, second_send_channel);
982 cpu_option = vie_.GetCpuOveruseOptions(second_send_channel);
983 EXPECT_EQ(10, cpu_option.low_capture_jitter_threshold_ms);
984 EXPECT_EQ(20, cpu_option.high_capture_jitter_threshold_ms);
985 EXPECT_TRUE(cpu_option.enable_capture_jitter_method);
986 EXPECT_FALSE(cpu_option.enable_encode_usage_method);
987}
988
989TEST_F(WebRtcVideoEngineTestFake, SetInvalidCpuOveruseThresholds) {
990 EXPECT_TRUE(SetupEngine());
991 EXPECT_TRUE(channel_->AddSendStream(cricket::StreamParams::CreateLegacy(1)));
992 int channel_num = vie_.GetLastChannel();
993
994 // Only low threshold set. Verify that cpu options are not set.
995 cricket::VideoOptions options;
996 options.conference_mode.Set(true);
997 options.cpu_underuse_threshold.Set(10);
998 EXPECT_TRUE(channel_->SetOptions(options));
999 webrtc::CpuOveruseOptions cpu_option = vie_.GetCpuOveruseOptions(channel_num);
1000 EXPECT_EQ(0, cpu_option.low_capture_jitter_threshold_ms);
1001 EXPECT_EQ(0, cpu_option.high_capture_jitter_threshold_ms);
1002 EXPECT_FALSE(cpu_option.enable_capture_jitter_method);
1003 EXPECT_FALSE(cpu_option.enable_encode_usage_method);
1004
1005 // Set high threshold to a negative value. Verify that options are not set.
1006 options.cpu_overuse_threshold.Set(-1);
1007 EXPECT_TRUE(channel_->SetOptions(options));
1008 cpu_option = vie_.GetCpuOveruseOptions(channel_num);
1009 EXPECT_EQ(0, cpu_option.low_capture_jitter_threshold_ms);
1010 EXPECT_EQ(0, cpu_option.high_capture_jitter_threshold_ms);
1011 EXPECT_FALSE(cpu_option.enable_capture_jitter_method);
1012 EXPECT_FALSE(cpu_option.enable_encode_usage_method);
1013
1014 // Low and high threshold valid. Verify that cpu options are set.
1015 options.cpu_overuse_threshold.Set(20);
1016 EXPECT_TRUE(channel_->SetOptions(options));
1017 cpu_option = vie_.GetCpuOveruseOptions(channel_num);
1018 EXPECT_EQ(10, cpu_option.low_capture_jitter_threshold_ms);
1019 EXPECT_EQ(20, cpu_option.high_capture_jitter_threshold_ms);
1020 EXPECT_TRUE(cpu_option.enable_capture_jitter_method);
1021 EXPECT_FALSE(cpu_option.enable_encode_usage_method);
1022}
1023
1024TEST_F(WebRtcVideoEngineTestFake, SetCpuOveruseOptionsWithEncodeUsageMethod) {
1025 EXPECT_TRUE(SetupEngine());
1026 EXPECT_TRUE(channel_->AddSendStream(cricket::StreamParams::CreateLegacy(1)));
1027 int first_send_channel = vie_.GetLastChannel();
1028
1029 // Set low and high threshold and enable encode usage method.
1030 // Verify that cpu options are set.
1031 cricket::VideoOptions options;
1032 options.conference_mode.Set(true);
1033 options.cpu_underuse_threshold.Set(10);
1034 options.cpu_overuse_threshold.Set(20);
1035 options.cpu_overuse_encode_usage.Set(true);
1036 EXPECT_TRUE(channel_->SetOptions(options));
1037 webrtc::CpuOveruseOptions cpu_option =
1038 vie_.GetCpuOveruseOptions(first_send_channel);
1039 EXPECT_EQ(10, cpu_option.low_encode_usage_threshold_percent);
1040 EXPECT_EQ(20, cpu_option.high_encode_usage_threshold_percent);
1041 EXPECT_FALSE(cpu_option.enable_capture_jitter_method);
1042 EXPECT_TRUE(cpu_option.enable_encode_usage_method);
1043
1044 // Add a new send stream and verify that cpu options are set from start.
1045 EXPECT_TRUE(channel_->AddSendStream(cricket::StreamParams::CreateLegacy(3)));
1046 int second_send_channel = vie_.GetLastChannel();
1047 EXPECT_NE(first_send_channel, second_send_channel);
1048 cpu_option = vie_.GetCpuOveruseOptions(second_send_channel);
1049 EXPECT_EQ(10, cpu_option.low_encode_usage_threshold_percent);
1050 EXPECT_EQ(20, cpu_option.high_encode_usage_threshold_percent);
1051 EXPECT_FALSE(cpu_option.enable_capture_jitter_method);
1052 EXPECT_TRUE(cpu_option.enable_encode_usage_method);
1053}
1054#endif
1055
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001056// Test that AddRecvStream doesn't create new channel for 1:1 call.
1057TEST_F(WebRtcVideoEngineTestFake, AddRecvStream1On1) {
1058 EXPECT_TRUE(SetupEngine());
1059 int channel_num = vie_.GetLastChannel();
1060 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(1)));
1061 EXPECT_EQ(channel_num, vie_.GetLastChannel());
1062}
1063
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +00001064// Test that NACK, PLI and REMB are enabled for internal codec.
1065TEST_F(WebRtcVideoEngineTestFake, InternalCodecFeedbackParams) {
1066 EXPECT_TRUE(SetupEngine());
1067
1068 std::vector<cricket::VideoCodec> codecs(engine_.codecs());
1069 // Vp8 will appear at the beginning.
1070 size_t pos = 0;
1071 EXPECT_EQ("VP8", codecs[pos].name);
1072 VerifyCodecFeedbackParams(codecs[pos]);
1073}
1074
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001075// Test that AddRecvStream doesn't change remb for 1:1 call.
1076TEST_F(WebRtcVideoEngineTestFake, NoRembChangeAfterAddRecvStream) {
1077 EXPECT_TRUE(SetupEngine());
1078 int channel_num = vie_.GetLastChannel();
1079 EXPECT_TRUE(channel_->AddSendStream(
1080 cricket::StreamParams::CreateLegacy(1)));
1081 EXPECT_TRUE(channel_->SetSendCodecs(engine_.codecs()));
1082 EXPECT_TRUE(vie_.GetRembStatusBwPartition(channel_num));
1083 EXPECT_TRUE(vie_.GetRembStatusContribute(channel_num));
1084 EXPECT_TRUE(channel_->SetSend(true));
1085 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(1)));
1086 EXPECT_TRUE(vie_.GetRembStatusBwPartition(channel_num));
1087 EXPECT_TRUE(vie_.GetRembStatusContribute(channel_num));
1088}
1089
1090// Verify default REMB setting and that it can be turned on and off.
1091TEST_F(WebRtcVideoEngineTestFake, RembOnOff) {
1092 EXPECT_TRUE(SetupEngine());
1093 int channel_num = vie_.GetLastChannel();
1094 // Verify REMB sending is always off by default.
1095 EXPECT_FALSE(vie_.GetRembStatusBwPartition(channel_num));
1096
1097 // Verify that REMB is turned on when setting default codecs since the
1098 // default codecs have REMB enabled.
1099 EXPECT_TRUE(channel_->SetSendCodecs(engine_.codecs()));
1100 EXPECT_TRUE(vie_.GetRembStatusBwPartition(channel_num));
1101
1102 // Verify that REMB is turned off when codecs without REMB are set.
1103 std::vector<cricket::VideoCodec> codecs = engine_.codecs();
1104 // Clearing the codecs' FeedbackParams and setting send codecs should disable
1105 // REMB.
1106 for (std::vector<cricket::VideoCodec>::iterator iter = codecs.begin();
1107 iter != codecs.end(); ++iter) {
1108 // Intersecting with empty will clear the FeedbackParams.
1109 cricket::FeedbackParams empty_params;
1110 iter->feedback_params.Intersect(empty_params);
1111 EXPECT_TRUE(iter->feedback_params.params().empty());
1112 }
1113 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1114 EXPECT_FALSE(vie_.GetRembStatusBwPartition(channel_num));
1115}
1116
1117// Test that nack is enabled on the channel if we don't offer red/fec.
1118TEST_F(WebRtcVideoEngineTestFake, NackEnabled) {
1119 EXPECT_TRUE(SetupEngine());
1120 int channel_num = vie_.GetLastChannel();
1121 std::vector<cricket::VideoCodec> codecs(engine_.codecs());
1122 codecs.resize(1); // toss out red and ulpfec
1123 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1124 EXPECT_TRUE(vie_.GetNackStatus(channel_num));
1125}
1126
1127// Test that we enable hybrid NACK FEC mode.
1128TEST_F(WebRtcVideoEngineTestFake, HybridNackFec) {
1129 EXPECT_TRUE(SetupEngine());
1130 int channel_num = vie_.GetLastChannel();
1131 EXPECT_TRUE(channel_->SetRecvCodecs(engine_.codecs()));
1132 EXPECT_TRUE(channel_->SetSendCodecs(engine_.codecs()));
1133 EXPECT_TRUE(vie_.GetHybridNackFecStatus(channel_num));
1134 EXPECT_FALSE(vie_.GetNackStatus(channel_num));
1135}
1136
1137// Test that we enable hybrid NACK FEC mode when calling SetSendCodecs and
1138// SetReceiveCodecs in reversed order.
1139TEST_F(WebRtcVideoEngineTestFake, HybridNackFecReversedOrder) {
1140 EXPECT_TRUE(SetupEngine());
1141 int channel_num = vie_.GetLastChannel();
1142 EXPECT_TRUE(channel_->SetSendCodecs(engine_.codecs()));
1143 EXPECT_TRUE(channel_->SetRecvCodecs(engine_.codecs()));
1144 EXPECT_TRUE(vie_.GetHybridNackFecStatus(channel_num));
1145 EXPECT_FALSE(vie_.GetNackStatus(channel_num));
1146}
1147
1148// Test NACK vs Hybrid NACK/FEC interop call setup, i.e. only use NACK even if
1149// red/fec is offered as receive codec.
1150TEST_F(WebRtcVideoEngineTestFake, VideoProtectionInterop) {
1151 EXPECT_TRUE(SetupEngine());
1152 int channel_num = vie_.GetLastChannel();
1153 std::vector<cricket::VideoCodec> recv_codecs(engine_.codecs());
1154 std::vector<cricket::VideoCodec> send_codecs(engine_.codecs());
1155 // Only add VP8 as send codec.
1156 send_codecs.resize(1);
1157 EXPECT_TRUE(channel_->SetRecvCodecs(recv_codecs));
1158 EXPECT_TRUE(channel_->SetSendCodecs(send_codecs));
1159 EXPECT_FALSE(vie_.GetHybridNackFecStatus(channel_num));
1160 EXPECT_TRUE(vie_.GetNackStatus(channel_num));
1161}
1162
1163// Test NACK vs Hybrid NACK/FEC interop call setup, i.e. only use NACK even if
1164// red/fec is offered as receive codec. Call order reversed compared to
1165// VideoProtectionInterop.
1166TEST_F(WebRtcVideoEngineTestFake, VideoProtectionInteropReversed) {
1167 EXPECT_TRUE(SetupEngine());
1168 int channel_num = vie_.GetLastChannel();
1169 std::vector<cricket::VideoCodec> recv_codecs(engine_.codecs());
1170 std::vector<cricket::VideoCodec> send_codecs(engine_.codecs());
1171 // Only add VP8 as send codec.
1172 send_codecs.resize(1);
1173 EXPECT_TRUE(channel_->SetSendCodecs(send_codecs));
1174 EXPECT_TRUE(channel_->SetRecvCodecs(recv_codecs));
1175 EXPECT_FALSE(vie_.GetHybridNackFecStatus(channel_num));
1176 EXPECT_TRUE(vie_.GetNackStatus(channel_num));
1177}
1178
1179// Test that NACK, not hybrid mode, is enabled in conference mode.
1180TEST_F(WebRtcVideoEngineTestFake, HybridNackFecConference) {
1181 EXPECT_TRUE(SetupEngine());
1182 // Setup the send channel.
1183 int send_channel_num = vie_.GetLastChannel();
1184 cricket::VideoOptions options;
1185 options.conference_mode.Set(true);
1186 EXPECT_TRUE(channel_->SetOptions(options));
1187 EXPECT_TRUE(channel_->SetRecvCodecs(engine_.codecs()));
1188 EXPECT_TRUE(channel_->SetSendCodecs(engine_.codecs()));
1189 EXPECT_FALSE(vie_.GetHybridNackFecStatus(send_channel_num));
1190 EXPECT_TRUE(vie_.GetNackStatus(send_channel_num));
1191 // Add a receive stream.
1192 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(1)));
1193 int receive_channel_num = vie_.GetLastChannel();
1194 EXPECT_FALSE(vie_.GetHybridNackFecStatus(receive_channel_num));
1195 EXPECT_TRUE(vie_.GetNackStatus(receive_channel_num));
1196}
1197
1198// Test that when AddRecvStream in conference mode, a new channel is created
1199// for receiving. And the new channel's "original channel" is the send channel.
1200TEST_F(WebRtcVideoEngineTestFake, AddRemoveRecvStreamConference) {
1201 EXPECT_TRUE(SetupEngine());
1202 // Setup the send channel.
1203 int send_channel_num = vie_.GetLastChannel();
1204 cricket::VideoOptions options;
1205 options.conference_mode.Set(true);
1206 EXPECT_TRUE(channel_->SetOptions(options));
1207 // Add a receive stream.
1208 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(1)));
1209 int receive_channel_num = vie_.GetLastChannel();
1210 EXPECT_EQ(send_channel_num, vie_.GetOriginalChannelId(receive_channel_num));
1211 EXPECT_TRUE(channel_->RemoveRecvStream(1));
1212 EXPECT_FALSE(vie_.IsChannel(receive_channel_num));
1213}
1214
henrike@webrtc.org6e3dbc22014-03-25 17:09:47 +00001215// Test that adding/removing stream with 0 ssrc should fail (and not crash).
1216// For crbug/351699 and 350988.
1217TEST_F(WebRtcVideoEngineTestFake, AddRemoveRecvStreamWith0Ssrc) {
1218 EXPECT_TRUE(SetupEngine());
1219 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(1)));
1220 EXPECT_FALSE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(0)));
1221 EXPECT_FALSE(channel_->RemoveRecvStream(0));
1222 EXPECT_TRUE(channel_->RemoveRecvStream(1));
1223}
1224
1225TEST_F(WebRtcVideoEngineTestFake, AddRemoveSendStreamWith0Ssrc) {
1226 EXPECT_TRUE(SetupEngine());
1227 EXPECT_TRUE(channel_->AddSendStream(cricket::StreamParams::CreateLegacy(1)));
1228 EXPECT_FALSE(channel_->AddSendStream(cricket::StreamParams::CreateLegacy(0)));
1229 EXPECT_FALSE(channel_->RemoveSendStream(0));
1230 EXPECT_TRUE(channel_->RemoveSendStream(1));
1231}
1232
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001233// Test that we can create a channel and start/stop rendering out on it.
1234TEST_F(WebRtcVideoEngineTestFake, SetRender) {
1235 EXPECT_TRUE(SetupEngine());
1236 int channel_num = vie_.GetLastChannel();
1237
1238 // Verify we can start/stop/start/stop rendering.
1239 EXPECT_TRUE(channel_->SetRender(true));
1240 EXPECT_TRUE(vie_.GetRenderStarted(channel_num));
1241 EXPECT_TRUE(channel_->SetRender(false));
1242 EXPECT_FALSE(vie_.GetRenderStarted(channel_num));
1243 EXPECT_TRUE(channel_->SetRender(true));
1244 EXPECT_TRUE(vie_.GetRenderStarted(channel_num));
1245 EXPECT_TRUE(channel_->SetRender(false));
1246 EXPECT_FALSE(vie_.GetRenderStarted(channel_num));
1247}
1248
1249// Test that we can create a channel and start/stop sending out on it.
1250TEST_F(WebRtcVideoEngineTestFake, SetSend) {
1251 EXPECT_TRUE(SetupEngine());
1252 int channel_num = vie_.GetLastChannel();
wu@webrtc.orgb9a088b2014-02-13 23:18:49 +00001253 // Verify receiving is also started.
1254 EXPECT_TRUE(vie_.GetReceive(channel_num));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001255
1256 // Set send codecs on the channel.
1257 std::vector<cricket::VideoCodec> codecs;
1258 codecs.push_back(kVP8Codec);
1259 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1260 EXPECT_TRUE(channel_->AddSendStream(
1261 cricket::StreamParams::CreateLegacy(123)));
1262
1263 // Verify we can start/stop/start/stop sending.
1264 EXPECT_TRUE(channel_->SetSend(true));
1265 EXPECT_TRUE(vie_.GetSend(channel_num));
1266 EXPECT_TRUE(channel_->SetSend(false));
1267 EXPECT_FALSE(vie_.GetSend(channel_num));
1268 EXPECT_TRUE(channel_->SetSend(true));
1269 EXPECT_TRUE(vie_.GetSend(channel_num));
1270 EXPECT_TRUE(channel_->SetSend(false));
1271 EXPECT_FALSE(vie_.GetSend(channel_num));
1272}
1273
1274// Test that we set bandwidth properly when using full auto bandwidth mode.
1275TEST_F(WebRtcVideoEngineTestFake, SetBandwidthAuto) {
1276 EXPECT_TRUE(SetupEngine());
1277 int channel_num = vie_.GetLastChannel();
1278 EXPECT_TRUE(channel_->SetSendCodecs(engine_.codecs()));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001279 EXPECT_TRUE(channel_->SetMaxSendBandwidth(cricket::kAutoBandwidth));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001280 VerifyVP8SendCodec(channel_num, kVP8Codec.width, kVP8Codec.height);
1281}
1282
1283// Test that we set bandwidth properly when using auto with upper bound.
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001284TEST_F(WebRtcVideoEngineTestFake, SetBandwidthCapped) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001285 EXPECT_TRUE(SetupEngine());
1286 int channel_num = vie_.GetLastChannel();
1287 EXPECT_TRUE(channel_->SetSendCodecs(engine_.codecs()));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001288 EXPECT_TRUE(channel_->SetMaxSendBandwidth(768000));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001289 VerifyVP8SendCodec(channel_num, kVP8Codec.width, kVP8Codec.height, 0, 768U);
1290}
1291
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001292// Test that we reduce the start bandwidth when the requested max is less than
1293// the default start bandwidth.
1294TEST_F(WebRtcVideoEngineTestFake, SetMaxBandwidthBelowDefaultStart) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001295 EXPECT_TRUE(SetupEngine());
1296 int channel_num = vie_.GetLastChannel();
1297 EXPECT_TRUE(channel_->SetSendCodecs(engine_.codecs()));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001298 int max_bandwidth_kbps = (kMinBandwidthKbps + kStartBandwidthKbps) / 2;
1299 EXPECT_TRUE(channel_->SetMaxSendBandwidth(max_bandwidth_kbps * 1000));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001300 VerifyVP8SendCodec(channel_num, kVP8Codec.width, kVP8Codec.height, 0,
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001301 max_bandwidth_kbps, kMinBandwidthKbps, max_bandwidth_kbps);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001302}
1303
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001304// Test that we reduce the min bandwidth when the requested max is less than
1305// the min bandwidth.
1306TEST_F(WebRtcVideoEngineTestFake, SetMaxBandwidthBelowMin) {
1307 EXPECT_TRUE(SetupEngine());
1308 int channel_num = vie_.GetLastChannel();
1309 EXPECT_TRUE(channel_->SetSendCodecs(engine_.codecs()));
1310 int max_bandwidth_kbps = kMinBandwidthKbps / 2;
1311 EXPECT_TRUE(channel_->SetMaxSendBandwidth(max_bandwidth_kbps * 1000));
1312 VerifyVP8SendCodec(channel_num, kVP8Codec.width, kVP8Codec.height, 0,
1313 max_bandwidth_kbps, max_bandwidth_kbps, max_bandwidth_kbps);
1314}
1315
1316// Test that the start bandwidth can be controlled separately from the max
1317// bandwidth.
1318TEST_F(WebRtcVideoEngineTestFake, SetStartBandwidth) {
1319 EXPECT_TRUE(SetupEngine());
1320 int channel_num = vie_.GetLastChannel();
1321 EXPECT_TRUE(channel_->SetSendCodecs(engine_.codecs()));
1322 int start_bandwidth_kbps = kStartBandwidthKbps + 1;
1323 EXPECT_TRUE(channel_->SetStartSendBandwidth(start_bandwidth_kbps * 1000));
1324 VerifyVP8SendCodec(channel_num, kVP8Codec.width, kVP8Codec.height, 0,
1325 kMaxBandwidthKbps, kMinBandwidthKbps, start_bandwidth_kbps);
1326
1327 // Check that SetMaxSendBandwidth doesn't overwrite the start bandwidth.
1328 int max_bandwidth_kbps = kMaxBandwidthKbps + 1;
1329 EXPECT_TRUE(channel_->SetMaxSendBandwidth(max_bandwidth_kbps * 1000));
1330 VerifyVP8SendCodec(channel_num, kVP8Codec.width, kVP8Codec.height, 0,
1331 max_bandwidth_kbps, kMinBandwidthKbps, start_bandwidth_kbps);
1332}
1333
wu@webrtc.org1e6cb2c2014-03-24 17:01:50 +00001334// Test that the start bandwidth can be controlled by experiment.
1335TEST_F(WebRtcVideoEngineTestFake, SetStartBandwidthOption) {
1336 EXPECT_TRUE(SetupEngine());
1337 int channel_num = vie_.GetLastChannel();
1338 EXPECT_TRUE(channel_->SetSendCodecs(engine_.codecs()));
1339 int start_bandwidth_kbps = kStartBandwidthKbps;
1340 EXPECT_TRUE(channel_->SetStartSendBandwidth(start_bandwidth_kbps * 1000));
1341 VerifyVP8SendCodec(channel_num, kVP8Codec.width, kVP8Codec.height, 0,
1342 kMaxBandwidthKbps, kMinBandwidthKbps, start_bandwidth_kbps);
1343
1344 // Set the start bitrate option.
1345 start_bandwidth_kbps = 1000;
1346 cricket::VideoOptions options;
1347 options.video_start_bitrate.Set(
1348 start_bandwidth_kbps);
1349 EXPECT_TRUE(channel_->SetOptions(options));
1350
1351 // Check that start bitrate has changed to the new value.
1352 VerifyVP8SendCodec(channel_num, kVP8Codec.width, kVP8Codec.height, 0,
1353 kMaxBandwidthKbps, kMinBandwidthKbps, start_bandwidth_kbps);
1354}
1355
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001356// Test that SetMaxSendBandwidth is ignored in conference mode.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001357TEST_F(WebRtcVideoEngineTestFake, SetBandwidthInConference) {
1358 EXPECT_TRUE(SetupEngine());
1359 int channel_num = vie_.GetLastChannel();
1360 cricket::VideoOptions options;
1361 options.conference_mode.Set(true);
1362 EXPECT_TRUE(channel_->SetOptions(options));
1363 EXPECT_TRUE(channel_->SetSendCodecs(engine_.codecs()));
1364 VerifyVP8SendCodec(channel_num, kVP8Codec.width, kVP8Codec.height);
1365
1366 // Set send bandwidth.
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001367 EXPECT_TRUE(channel_->SetMaxSendBandwidth(768000));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001368
1369 // Verify bitrate not changed.
1370 webrtc::VideoCodec gcodec;
1371 EXPECT_EQ(0, vie_.GetSendCodec(channel_num, gcodec));
1372 EXPECT_EQ(kMinBandwidthKbps, gcodec.minBitrate);
1373 EXPECT_EQ(kStartBandwidthKbps, gcodec.startBitrate);
1374 EXPECT_EQ(kMaxBandwidthKbps, gcodec.maxBitrate);
1375 EXPECT_NE(768U, gcodec.minBitrate);
1376 EXPECT_NE(768U, gcodec.startBitrate);
1377 EXPECT_NE(768U, gcodec.maxBitrate);
1378}
1379
1380// Test that sending screencast frames doesn't change bitrate.
1381TEST_F(WebRtcVideoEngineTestFake, SetBandwidthScreencast) {
1382 EXPECT_TRUE(SetupEngine());
1383 int channel_num = vie_.GetLastChannel();
1384
1385 // Set send codec.
1386 cricket::VideoCodec codec(kVP8Codec);
1387 std::vector<cricket::VideoCodec> codec_list;
1388 codec_list.push_back(codec);
1389 EXPECT_TRUE(channel_->AddSendStream(
1390 cricket::StreamParams::CreateLegacy(123)));
1391 EXPECT_TRUE(channel_->SetSendCodecs(codec_list));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001392 EXPECT_TRUE(channel_->SetMaxSendBandwidth(111000));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001393 EXPECT_TRUE(channel_->SetSend(true));
1394
1395 SendI420ScreencastFrame(kVP8Codec.width, kVP8Codec.height);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001396 VerifyVP8SendCodec(channel_num, kVP8Codec.width, kVP8Codec.height, 0, 111);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001397}
1398
1399
1400// Test SetSendSsrc.
1401TEST_F(WebRtcVideoEngineTestFake, SetSendSsrcAndCname) {
1402 EXPECT_TRUE(SetupEngine());
1403 int channel_num = vie_.GetLastChannel();
1404
1405 cricket::StreamParams stream;
1406 stream.ssrcs.push_back(1234);
1407 stream.cname = "cname";
1408 channel_->AddSendStream(stream);
1409
1410 unsigned int ssrc = 0;
1411 EXPECT_EQ(0, vie_.GetLocalSSRC(channel_num, ssrc));
1412 EXPECT_EQ(1234U, ssrc);
1413 EXPECT_EQ(1, vie_.GetNumSsrcs(channel_num));
1414
1415 char rtcp_cname[256];
1416 EXPECT_EQ(0, vie_.GetRTCPCName(channel_num, rtcp_cname));
1417 EXPECT_STREQ("cname", rtcp_cname);
1418}
1419
1420
1421// Test that the local SSRC is the same on sending and receiving channels if the
1422// receive channel is created before the send channel.
1423TEST_F(WebRtcVideoEngineTestFake, SetSendSsrcAfterCreatingReceiveChannel) {
1424 EXPECT_TRUE(SetupEngine());
1425
1426 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(1)));
1427 int receive_channel_num = vie_.GetLastChannel();
1428 cricket::StreamParams stream = cricket::StreamParams::CreateLegacy(1234);
1429 EXPECT_TRUE(channel_->AddSendStream(stream));
1430 int send_channel_num = vie_.GetLastChannel();
1431 unsigned int ssrc = 0;
1432 EXPECT_EQ(0, vie_.GetLocalSSRC(send_channel_num, ssrc));
1433 EXPECT_EQ(1234U, ssrc);
1434 EXPECT_EQ(1, vie_.GetNumSsrcs(send_channel_num));
1435 ssrc = 0;
1436 EXPECT_EQ(0, vie_.GetLocalSSRC(receive_channel_num, ssrc));
1437 EXPECT_EQ(1234U, ssrc);
1438 EXPECT_EQ(1, vie_.GetNumSsrcs(receive_channel_num));
1439}
1440
1441
1442// Test SetOptions with denoising flag.
1443TEST_F(WebRtcVideoEngineTestFake, SetOptionsWithDenoising) {
1444 EXPECT_TRUE(SetupEngine());
1445 EXPECT_EQ(1, vie_.GetNumCapturers());
1446 int channel_num = vie_.GetLastChannel();
1447 int capture_id = vie_.GetCaptureId(channel_num);
1448 // Set send codecs on the channel.
1449 std::vector<cricket::VideoCodec> codecs;
1450 codecs.push_back(kVP8Codec);
1451 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1452
1453 // Set options with OPT_VIDEO_NOISE_REDUCTION flag.
1454 cricket::VideoOptions options;
1455 options.video_noise_reduction.Set(true);
1456 EXPECT_TRUE(channel_->SetOptions(options));
1457
1458 // Verify capture has denoising turned on.
1459 webrtc::VideoCodec send_codec;
1460 memset(&send_codec, 0, sizeof(send_codec)); // avoid uninitialized warning
1461 EXPECT_EQ(0, vie_.GetSendCodec(channel_num, send_codec));
1462 EXPECT_TRUE(send_codec.codecSpecific.VP8.denoisingOn);
1463 EXPECT_FALSE(vie_.GetCaptureDenoising(capture_id));
1464
1465 // Set options back to zero.
1466 options.video_noise_reduction.Set(false);
1467 EXPECT_TRUE(channel_->SetOptions(options));
1468
1469 // Verify capture has denoising turned off.
1470 EXPECT_EQ(0, vie_.GetSendCodec(channel_num, send_codec));
1471 EXPECT_FALSE(send_codec.codecSpecific.VP8.denoisingOn);
1472 EXPECT_FALSE(vie_.GetCaptureDenoising(capture_id));
1473}
1474
wu@webrtc.orga8910d22014-01-23 22:12:45 +00001475TEST_F(WebRtcVideoEngineTestFake, MultipleSendStreamsWithOneCapturer) {
wu@webrtc.org24301a62013-12-13 19:17:43 +00001476 EXPECT_TRUE(SetupEngine());
1477
1478 // Start the capturer
1479 cricket::FakeVideoCapturer capturer;
1480 cricket::VideoFormat capture_format_vga = cricket::VideoFormat(640, 480,
1481 cricket::VideoFormat::FpsToInterval(30), cricket::FOURCC_I420);
1482 EXPECT_EQ(cricket::CS_RUNNING, capturer.Start(capture_format_vga));
1483
1484 // Add send streams and connect the capturer
1485 for (unsigned int i = 0; i < sizeof(kSsrcs2)/sizeof(kSsrcs2[0]); ++i) {
1486 EXPECT_TRUE(channel_->AddSendStream(
1487 cricket::StreamParams::CreateLegacy(kSsrcs2[i])));
1488 // Register the capturer to the ssrc.
1489 EXPECT_TRUE(channel_->SetCapturer(kSsrcs2[i], &capturer));
1490 }
1491
1492 const int channel0 = vie_.GetChannelFromLocalSsrc(kSsrcs2[0]);
1493 ASSERT_NE(-1, channel0);
1494 const int channel1 = vie_.GetChannelFromLocalSsrc(kSsrcs2[1]);
1495 ASSERT_NE(-1, channel1);
1496 ASSERT_NE(channel0, channel1);
1497
wu@webrtc.orgb9a088b2014-02-13 23:18:49 +00001498 // Both channels should have started receiving after created.
1499 EXPECT_TRUE(vie_.GetReceive(channel0));
1500 EXPECT_TRUE(vie_.GetReceive(channel1));
1501
wu@webrtc.org24301a62013-12-13 19:17:43 +00001502 // Set send codec.
1503 std::vector<cricket::VideoCodec> codecs;
1504 cricket::VideoCodec send_codec(100, "VP8", 640, 480, 30, 0);
1505 codecs.push_back(send_codec);
1506 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1507
wu@webrtc.orgb9a088b2014-02-13 23:18:49 +00001508 EXPECT_TRUE(channel_->SetSend(true));
1509 EXPECT_TRUE(vie_.GetSend(channel0));
1510 EXPECT_TRUE(vie_.GetSend(channel1));
1511
wu@webrtc.org24301a62013-12-13 19:17:43 +00001512 EXPECT_TRUE(capturer.CaptureFrame());
1513 EXPECT_EQ(1, vie_.GetIncomingFrameNum(channel0));
1514 EXPECT_EQ(1, vie_.GetIncomingFrameNum(channel1));
1515
1516 EXPECT_TRUE(channel_->RemoveSendStream(kSsrcs2[0]));
1517 EXPECT_TRUE(capturer.CaptureFrame());
1518 // channel0 is the default channel, so it won't be deleted.
1519 // But it should be disconnected from the capturer.
1520 EXPECT_EQ(1, vie_.GetIncomingFrameNum(channel0));
1521 EXPECT_EQ(2, vie_.GetIncomingFrameNum(channel1));
1522
1523 EXPECT_TRUE(channel_->RemoveSendStream(kSsrcs2[1]));
1524 EXPECT_TRUE(capturer.CaptureFrame());
1525 EXPECT_EQ(1, vie_.GetIncomingFrameNum(channel0));
1526 // channel1 has already been deleted.
1527 EXPECT_EQ(-1, vie_.GetIncomingFrameNum(channel1));
1528}
1529
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001530
wu@webrtc.org97077a32013-10-25 21:18:33 +00001531// Disabled since its flaky: b/11288120
1532TEST_F(WebRtcVideoEngineTestFake, DISABLED_SendReceiveBitratesStats) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001533 EXPECT_TRUE(SetupEngine());
1534 cricket::VideoOptions options;
1535 options.conference_mode.Set(true);
1536 EXPECT_TRUE(channel_->SetOptions(options));
1537 EXPECT_TRUE(channel_->AddSendStream(
1538 cricket::StreamParams::CreateLegacy(1)));
1539 int send_channel = vie_.GetLastChannel();
1540 cricket::VideoCodec codec(kVP8Codec720p);
1541 std::vector<cricket::VideoCodec> codec_list;
1542 codec_list.push_back(codec);
1543 EXPECT_TRUE(channel_->SetSendCodecs(codec_list));
1544
1545 EXPECT_TRUE(channel_->AddRecvStream(
1546 cricket::StreamParams::CreateLegacy(2)));
1547 int first_receive_channel = vie_.GetLastChannel();
1548 EXPECT_NE(send_channel, first_receive_channel);
1549 EXPECT_TRUE(channel_->AddRecvStream(
1550 cricket::StreamParams::CreateLegacy(3)));
1551 int second_receive_channel = vie_.GetLastChannel();
1552 EXPECT_NE(first_receive_channel, second_receive_channel);
1553
1554 cricket::VideoMediaInfo info;
wu@webrtc.orgb9a088b2014-02-13 23:18:49 +00001555 EXPECT_TRUE(channel_->GetStats(cricket::StatsOptions(), &info));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001556 ASSERT_EQ(1U, info.bw_estimations.size());
1557 ASSERT_EQ(0, info.bw_estimations[0].actual_enc_bitrate);
1558 ASSERT_EQ(0, info.bw_estimations[0].transmit_bitrate);
1559 ASSERT_EQ(0, info.bw_estimations[0].retransmit_bitrate);
1560 ASSERT_EQ(0, info.bw_estimations[0].available_send_bandwidth);
1561 ASSERT_EQ(0, info.bw_estimations[0].available_recv_bandwidth);
1562 ASSERT_EQ(0, info.bw_estimations[0].target_enc_bitrate);
1563
1564 // Start sending and receiving on one of the channels and verify bitrates.
1565 EXPECT_EQ(0, vie_.StartSend(send_channel));
1566 int send_video_bitrate = 800;
1567 int send_fec_bitrate = 100;
1568 int send_nack_bitrate = 20;
1569 int send_total_bitrate = send_video_bitrate + send_fec_bitrate +
1570 send_nack_bitrate;
1571 int send_bandwidth = 950;
1572 vie_.SetSendBitrates(send_channel, send_video_bitrate, send_fec_bitrate,
1573 send_nack_bitrate);
1574 vie_.SetSendBandwidthEstimate(send_channel, send_bandwidth);
1575
1576 EXPECT_EQ(0, vie_.StartReceive(first_receive_channel));
1577 int first_channel_receive_bandwidth = 600;
1578 vie_.SetReceiveBandwidthEstimate(first_receive_channel,
1579 first_channel_receive_bandwidth);
1580
1581 info.Clear();
wu@webrtc.orgb9a088b2014-02-13 23:18:49 +00001582 EXPECT_TRUE(channel_->GetStats(cricket::StatsOptions(), &info));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001583 ASSERT_EQ(1U, info.bw_estimations.size());
1584 ASSERT_EQ(send_video_bitrate, info.bw_estimations[0].actual_enc_bitrate);
1585 ASSERT_EQ(send_total_bitrate, info.bw_estimations[0].transmit_bitrate);
1586 ASSERT_EQ(send_nack_bitrate, info.bw_estimations[0].retransmit_bitrate);
1587 ASSERT_EQ(send_bandwidth, info.bw_estimations[0].available_send_bandwidth);
1588 ASSERT_EQ(first_channel_receive_bandwidth,
1589 info.bw_estimations[0].available_recv_bandwidth);
1590 ASSERT_EQ(send_video_bitrate, info.bw_estimations[0].target_enc_bitrate);
1591
1592 // Start receiving on the second channel and verify received rate.
1593 EXPECT_EQ(0, vie_.StartReceive(second_receive_channel));
1594 int second_channel_receive_bandwidth = 100;
1595 vie_.SetReceiveBandwidthEstimate(second_receive_channel,
1596 second_channel_receive_bandwidth);
1597
1598 info.Clear();
wu@webrtc.orgb9a088b2014-02-13 23:18:49 +00001599 EXPECT_TRUE(channel_->GetStats(cricket::StatsOptions(), &info));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001600 ASSERT_EQ(1U, info.bw_estimations.size());
1601 ASSERT_EQ(send_video_bitrate, info.bw_estimations[0].actual_enc_bitrate);
1602 ASSERT_EQ(send_total_bitrate, info.bw_estimations[0].transmit_bitrate);
1603 ASSERT_EQ(send_nack_bitrate, info.bw_estimations[0].retransmit_bitrate);
1604 ASSERT_EQ(send_bandwidth, info.bw_estimations[0].available_send_bandwidth);
1605 ASSERT_EQ(first_channel_receive_bandwidth + second_channel_receive_bandwidth,
1606 info.bw_estimations[0].available_recv_bandwidth);
1607 ASSERT_EQ(send_video_bitrate, info.bw_estimations[0].target_enc_bitrate);
1608}
1609
1610TEST_F(WebRtcVideoEngineTestFake, TestSetAdaptInputToCpuUsage) {
1611 EXPECT_TRUE(SetupEngine());
1612 cricket::VideoOptions options_in, options_out;
1613 bool cpu_adapt = false;
1614 channel_->SetOptions(options_in);
1615 EXPECT_TRUE(channel_->GetOptions(&options_out));
1616 EXPECT_FALSE(options_out.adapt_input_to_cpu_usage.Get(&cpu_adapt));
1617 // Set adapt input CPU usage option.
1618 options_in.adapt_input_to_cpu_usage.Set(true);
1619 EXPECT_TRUE(channel_->SetOptions(options_in));
1620 EXPECT_TRUE(channel_->GetOptions(&options_out));
1621 EXPECT_TRUE(options_out.adapt_input_to_cpu_usage.Get(&cpu_adapt));
1622 EXPECT_TRUE(cpu_adapt);
1623}
1624
1625TEST_F(WebRtcVideoEngineTestFake, TestSetCpuThreshold) {
1626 EXPECT_TRUE(SetupEngine());
1627 float low, high;
1628 cricket::VideoOptions options_in, options_out;
1629 // Verify that initial values are set.
1630 EXPECT_TRUE(channel_->GetOptions(&options_out));
1631 EXPECT_TRUE(options_out.system_low_adaptation_threshhold.Get(&low));
1632 EXPECT_EQ(low, 0.65f);
1633 EXPECT_TRUE(options_out.system_high_adaptation_threshhold.Get(&high));
1634 EXPECT_EQ(high, 0.85f);
1635 // Set new CPU threshold values.
1636 options_in.system_low_adaptation_threshhold.Set(0.45f);
1637 options_in.system_high_adaptation_threshhold.Set(0.95f);
1638 EXPECT_TRUE(channel_->SetOptions(options_in));
1639 EXPECT_TRUE(channel_->GetOptions(&options_out));
1640 EXPECT_TRUE(options_out.system_low_adaptation_threshhold.Get(&low));
1641 EXPECT_EQ(low, 0.45f);
1642 EXPECT_TRUE(options_out.system_high_adaptation_threshhold.Get(&high));
1643 EXPECT_EQ(high, 0.95f);
1644}
1645
1646TEST_F(WebRtcVideoEngineTestFake, TestSetInvalidCpuThreshold) {
1647 EXPECT_TRUE(SetupEngine());
1648 float low, high;
1649 cricket::VideoOptions options_in, options_out;
1650 // Valid range is [0, 1].
1651 options_in.system_low_adaptation_threshhold.Set(-1.5f);
1652 options_in.system_high_adaptation_threshhold.Set(1.5f);
1653 EXPECT_TRUE(channel_->SetOptions(options_in));
1654 EXPECT_TRUE(channel_->GetOptions(&options_out));
1655 EXPECT_TRUE(options_out.system_low_adaptation_threshhold.Get(&low));
1656 EXPECT_EQ(low, 0.0f);
1657 EXPECT_TRUE(options_out.system_high_adaptation_threshhold.Get(&high));
1658 EXPECT_EQ(high, 1.0f);
1659}
1660
1661
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +00001662TEST_F(WebRtcVideoEngineTestFake, ResetCodecOnScreencast) {
1663 EXPECT_TRUE(SetupEngine());
1664 cricket::VideoOptions options;
1665 options.video_noise_reduction.Set(true);
1666 EXPECT_TRUE(channel_->SetOptions(options));
1667
1668 // Set send codec.
1669 cricket::VideoCodec codec(kVP8Codec);
1670 std::vector<cricket::VideoCodec> codec_list;
1671 codec_list.push_back(codec);
1672 EXPECT_TRUE(channel_->AddSendStream(
1673 cricket::StreamParams::CreateLegacy(123)));
1674 EXPECT_TRUE(channel_->SetSendCodecs(codec_list));
1675 EXPECT_TRUE(channel_->SetSend(true));
wu@webrtc.org05e7b442014-04-01 17:44:24 +00001676 EXPECT_EQ(1, vie_.GetNumSetSendCodecs());
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +00001677
1678 webrtc::VideoCodec gcodec;
1679 memset(&gcodec, 0, sizeof(gcodec));
1680 int channel_num = vie_.GetLastChannel();
1681 EXPECT_EQ(0, vie_.GetSendCodec(channel_num, gcodec));
1682 EXPECT_TRUE(gcodec.codecSpecific.VP8.denoisingOn);
1683
1684 // Send a screencast frame with the same size.
1685 // Verify that denoising is turned off.
1686 SendI420ScreencastFrame(kVP8Codec.width, kVP8Codec.height);
wu@webrtc.org05e7b442014-04-01 17:44:24 +00001687 EXPECT_EQ(2, vie_.GetNumSetSendCodecs());
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +00001688 EXPECT_EQ(0, vie_.GetSendCodec(channel_num, gcodec));
1689 EXPECT_FALSE(gcodec.codecSpecific.VP8.denoisingOn);
1690}
1691
1692
1693TEST_F(WebRtcVideoEngineTestFake, DontRegisterDecoderIfFactoryIsNotGiven) {
1694 engine_.SetExternalDecoderFactory(NULL);
1695 EXPECT_TRUE(SetupEngine());
1696 int channel_num = vie_.GetLastChannel();
1697
1698 std::vector<cricket::VideoCodec> codecs;
1699 codecs.push_back(kVP8Codec);
1700 EXPECT_TRUE(channel_->SetRecvCodecs(codecs));
1701
1702 EXPECT_EQ(0, vie_.GetNumExternalDecoderRegistered(channel_num));
1703}
1704
1705TEST_F(WebRtcVideoEngineTestFake, RegisterDecoderIfFactoryIsGiven) {
1706 decoder_factory_.AddSupportedVideoCodecType(webrtc::kVideoCodecVP8);
1707 engine_.SetExternalDecoderFactory(&decoder_factory_);
1708 EXPECT_TRUE(SetupEngine());
1709 int channel_num = vie_.GetLastChannel();
1710
1711 std::vector<cricket::VideoCodec> codecs;
1712 codecs.push_back(kVP8Codec);
1713 EXPECT_TRUE(channel_->SetRecvCodecs(codecs));
1714
1715 EXPECT_TRUE(vie_.ExternalDecoderRegistered(channel_num, 100));
1716 EXPECT_EQ(1, vie_.GetNumExternalDecoderRegistered(channel_num));
1717}
1718
1719TEST_F(WebRtcVideoEngineTestFake, DontRegisterDecoderMultipleTimes) {
1720 decoder_factory_.AddSupportedVideoCodecType(webrtc::kVideoCodecVP8);
1721 engine_.SetExternalDecoderFactory(&decoder_factory_);
1722 EXPECT_TRUE(SetupEngine());
1723 int channel_num = vie_.GetLastChannel();
1724
1725 std::vector<cricket::VideoCodec> codecs;
1726 codecs.push_back(kVP8Codec);
1727 EXPECT_TRUE(channel_->SetRecvCodecs(codecs));
1728
1729 EXPECT_TRUE(vie_.ExternalDecoderRegistered(channel_num, 100));
1730 EXPECT_EQ(1, vie_.GetNumExternalDecoderRegistered(channel_num));
1731 EXPECT_EQ(1, decoder_factory_.GetNumCreatedDecoders());
1732
1733 EXPECT_TRUE(channel_->SetRecvCodecs(codecs));
1734 EXPECT_EQ(1, vie_.GetNumExternalDecoderRegistered(channel_num));
1735 EXPECT_EQ(1, decoder_factory_.GetNumCreatedDecoders());
1736}
1737
1738TEST_F(WebRtcVideoEngineTestFake, DontRegisterDecoderForNonVP8) {
1739 decoder_factory_.AddSupportedVideoCodecType(webrtc::kVideoCodecVP8);
1740 engine_.SetExternalDecoderFactory(&decoder_factory_);
1741 EXPECT_TRUE(SetupEngine());
1742 int channel_num = vie_.GetLastChannel();
1743
1744 std::vector<cricket::VideoCodec> codecs;
1745 codecs.push_back(kRedCodec);
1746 EXPECT_TRUE(channel_->SetRecvCodecs(codecs));
1747
1748 EXPECT_EQ(0, vie_.GetNumExternalDecoderRegistered(channel_num));
1749}
1750
1751TEST_F(WebRtcVideoEngineTestFake, DontRegisterEncoderIfFactoryIsNotGiven) {
1752 engine_.SetExternalEncoderFactory(NULL);
1753 EXPECT_TRUE(SetupEngine());
1754 int channel_num = vie_.GetLastChannel();
1755
1756 std::vector<cricket::VideoCodec> codecs;
1757 codecs.push_back(kVP8Codec);
1758 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1759
1760 EXPECT_EQ(0, vie_.GetNumExternalEncoderRegistered(channel_num));
1761}
1762
1763TEST_F(WebRtcVideoEngineTestFake, RegisterEncoderIfFactoryIsGiven) {
1764 encoder_factory_.AddSupportedVideoCodecType(webrtc::kVideoCodecVP8, "VP8");
1765 engine_.SetExternalEncoderFactory(&encoder_factory_);
1766 EXPECT_TRUE(SetupEngine());
1767 int channel_num = vie_.GetLastChannel();
1768
1769 std::vector<cricket::VideoCodec> codecs;
1770 codecs.push_back(kVP8Codec);
1771 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1772
1773 EXPECT_TRUE(channel_->AddSendStream(
1774 cricket::StreamParams::CreateLegacy(kSsrc)));
1775
1776 EXPECT_TRUE(vie_.ExternalEncoderRegistered(channel_num, 100));
1777 EXPECT_EQ(1, vie_.GetNumExternalEncoderRegistered(channel_num));
1778
1779 // Remove stream previously added to free the external encoder instance.
1780 EXPECT_TRUE(channel_->RemoveSendStream(kSsrc));
1781}
1782
1783TEST_F(WebRtcVideoEngineTestFake, DontRegisterEncoderMultipleTimes) {
1784 encoder_factory_.AddSupportedVideoCodecType(webrtc::kVideoCodecVP8, "VP8");
1785 engine_.SetExternalEncoderFactory(&encoder_factory_);
1786 EXPECT_TRUE(SetupEngine());
1787 int channel_num = vie_.GetLastChannel();
1788
1789 std::vector<cricket::VideoCodec> codecs;
1790 codecs.push_back(kVP8Codec);
1791 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1792
1793 EXPECT_TRUE(channel_->AddSendStream(
1794 cricket::StreamParams::CreateLegacy(kSsrc)));
1795
1796 EXPECT_TRUE(vie_.ExternalEncoderRegistered(channel_num, 100));
1797 EXPECT_EQ(1, vie_.GetNumExternalEncoderRegistered(channel_num));
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +00001798
1799 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1800 EXPECT_EQ(1, vie_.GetNumExternalEncoderRegistered(channel_num));
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +00001801
1802 // Remove stream previously added to free the external encoder instance.
1803 EXPECT_TRUE(channel_->RemoveSendStream(kSsrc));
1804}
1805
1806TEST_F(WebRtcVideoEngineTestFake, RegisterEncoderWithMultipleSendStreams) {
1807 encoder_factory_.AddSupportedVideoCodecType(webrtc::kVideoCodecVP8, "VP8");
1808 engine_.SetExternalEncoderFactory(&encoder_factory_);
1809 EXPECT_TRUE(SetupEngine());
1810
1811 std::vector<cricket::VideoCodec> codecs;
1812 codecs.push_back(kVP8Codec);
1813 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1814 EXPECT_EQ(1, vie_.GetTotalNumExternalEncoderRegistered());
1815
1816 // When we add the first stream (1234), it reuses the default send channel,
1817 // so it doesn't increase the registration count of external encoders.
1818 EXPECT_TRUE(channel_->AddSendStream(
1819 cricket::StreamParams::CreateLegacy(1234)));
1820 EXPECT_EQ(1, vie_.GetTotalNumExternalEncoderRegistered());
1821
1822 // When we add the second stream (2345), it creates a new channel and
1823 // increments the registration count.
1824 EXPECT_TRUE(channel_->AddSendStream(
1825 cricket::StreamParams::CreateLegacy(2345)));
1826 EXPECT_EQ(2, vie_.GetTotalNumExternalEncoderRegistered());
1827
1828 // At this moment the total registration count is two, but only one encoder
1829 // is registered per channel.
1830 int channel_num = vie_.GetLastChannel();
1831 EXPECT_EQ(1, vie_.GetNumExternalEncoderRegistered(channel_num));
1832
1833 // Removing send streams decrements the registration count.
1834 EXPECT_TRUE(channel_->RemoveSendStream(1234));
1835 EXPECT_EQ(1, vie_.GetTotalNumExternalEncoderRegistered());
1836
1837 // When we remove the last send stream, it also destroys the last send
1838 // channel and causes the registration count to drop to zero. It is a little
1839 // weird, but not a bug.
1840 EXPECT_TRUE(channel_->RemoveSendStream(2345));
1841 EXPECT_EQ(0, vie_.GetTotalNumExternalEncoderRegistered());
1842}
1843
1844TEST_F(WebRtcVideoEngineTestFake, DontRegisterEncoderForNonVP8) {
1845 encoder_factory_.AddSupportedVideoCodecType(webrtc::kVideoCodecGeneric,
1846 "GENERIC");
1847 engine_.SetExternalEncoderFactory(&encoder_factory_);
1848 EXPECT_TRUE(SetupEngine());
1849 int channel_num = vie_.GetLastChannel();
1850
1851 // Note: unlike the SetRecvCodecs, we must set a valid video codec for
1852 // channel_->SetSendCodecs() to succeed.
1853 std::vector<cricket::VideoCodec> codecs;
1854 codecs.push_back(kVP8Codec);
1855 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1856
1857 EXPECT_EQ(0, vie_.GetNumExternalEncoderRegistered(channel_num));
1858}
1859
1860// Test that NACK, PLI and REMB are enabled for external codec.
1861TEST_F(WebRtcVideoEngineTestFake, ExternalCodecFeedbackParams) {
1862 encoder_factory_.AddSupportedVideoCodecType(webrtc::kVideoCodecGeneric,
1863 "GENERIC");
1864 engine_.SetExternalEncoderFactory(&encoder_factory_);
1865 encoder_factory_.NotifyCodecsAvailable();
1866 EXPECT_TRUE(SetupEngine());
1867
1868 std::vector<cricket::VideoCodec> codecs(engine_.codecs());
1869 // The external codec will appear at last.
1870 size_t pos = codecs.size() - 1;
1871 EXPECT_EQ("GENERIC", codecs[pos].name);
1872 VerifyCodecFeedbackParams(codecs[pos]);
1873}
1874
1875// Test external codec with be added to the end of the supported codec list.
1876TEST_F(WebRtcVideoEngineTestFake, ExternalCodecAddedToTheEnd) {
1877 EXPECT_TRUE(SetupEngine());
1878
1879 std::vector<cricket::VideoCodec> codecs(engine_.codecs());
1880 EXPECT_EQ("VP8", codecs[0].name);
1881
1882 encoder_factory_.AddSupportedVideoCodecType(webrtc::kVideoCodecGeneric,
1883 "GENERIC");
1884 engine_.SetExternalEncoderFactory(&encoder_factory_);
1885 encoder_factory_.NotifyCodecsAvailable();
1886
1887 codecs = engine_.codecs();
1888 cricket::VideoCodec internal_codec = codecs[0];
1889 cricket::VideoCodec external_codec = codecs[codecs.size() - 1];
1890 // The external codec will appear at last.
1891 EXPECT_EQ("GENERIC", external_codec.name);
1892 // The internal codec is preferred.
1893 EXPECT_GE(internal_codec.preference, external_codec.preference);
1894}
1895
1896// Test that external codec with be ignored if it has the same name as one of
1897// the internal codecs.
1898TEST_F(WebRtcVideoEngineTestFake, ExternalCodecIgnored) {
1899 EXPECT_TRUE(SetupEngine());
1900
1901 std::vector<cricket::VideoCodec> internal_codecs(engine_.codecs());
1902 EXPECT_EQ("VP8", internal_codecs[0].name);
1903
1904 encoder_factory_.AddSupportedVideoCodecType(webrtc::kVideoCodecVP8, "VP8");
1905 engine_.SetExternalEncoderFactory(&encoder_factory_);
1906 encoder_factory_.NotifyCodecsAvailable();
1907
1908 std::vector<cricket::VideoCodec> codecs = engine_.codecs();
1909 EXPECT_EQ("VP8", codecs[0].name);
1910 EXPECT_EQ(internal_codecs[0].height, codecs[0].height);
1911 EXPECT_EQ(internal_codecs[0].width, codecs[0].width);
1912 // Verify the last codec is not the external codec.
1913 EXPECT_NE("VP8", codecs[codecs.size() - 1].name);
1914}
1915
1916TEST_F(WebRtcVideoEngineTestFake, UpdateEncoderCodecsAfterSetFactory) {
1917 engine_.SetExternalEncoderFactory(&encoder_factory_);
1918 EXPECT_TRUE(SetupEngine());
1919 int channel_num = vie_.GetLastChannel();
1920
1921 encoder_factory_.AddSupportedVideoCodecType(webrtc::kVideoCodecVP8, "VP8");
1922 encoder_factory_.NotifyCodecsAvailable();
1923 std::vector<cricket::VideoCodec> codecs;
1924 codecs.push_back(kVP8Codec);
1925 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1926
1927 EXPECT_TRUE(channel_->AddSendStream(
1928 cricket::StreamParams::CreateLegacy(kSsrc)));
1929
1930 EXPECT_TRUE(vie_.ExternalEncoderRegistered(channel_num, 100));
1931 EXPECT_EQ(1, vie_.GetNumExternalEncoderRegistered(channel_num));
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +00001932
1933 // Remove stream previously added to free the external encoder instance.
1934 EXPECT_TRUE(channel_->RemoveSendStream(kSsrc));
1935}
1936
1937// Tests that OnReadyToSend will be propagated into ViE.
1938TEST_F(WebRtcVideoEngineTestFake, OnReadyToSend) {
1939 EXPECT_TRUE(SetupEngine());
1940 int channel_num = vie_.GetLastChannel();
1941 EXPECT_TRUE(vie_.GetIsTransmitting(channel_num));
1942
1943 channel_->OnReadyToSend(false);
1944 EXPECT_FALSE(vie_.GetIsTransmitting(channel_num));
1945
1946 channel_->OnReadyToSend(true);
1947 EXPECT_TRUE(vie_.GetIsTransmitting(channel_num));
1948}
1949
1950#if 0
1951TEST_F(WebRtcVideoEngineTestFake, CaptureFrameTimestampToNtpTimestamp) {
1952 EXPECT_TRUE(SetupEngine());
1953 int capture_id = vie_.GetCaptureId(vie_.GetLastChannel());
1954
1955 // Set send codec.
1956 cricket::VideoCodec codec(kVP8Codec);
1957 std::vector<cricket::VideoCodec> codec_list;
1958 codec_list.push_back(codec);
1959 EXPECT_TRUE(channel_->AddSendStream(
1960 cricket::StreamParams::CreateLegacy(123)));
1961 EXPECT_TRUE(channel_->SetSendCodecs(codec_list));
1962 EXPECT_TRUE(channel_->SetSend(true));
1963
1964 int64 timestamp = time(NULL) * talk_base::kNumNanosecsPerSec;
1965 SendI420ScreencastFrameWithTimestamp(
1966 kVP8Codec.width, kVP8Codec.height, timestamp);
1967 EXPECT_EQ(talk_base::UnixTimestampNanosecsToNtpMillisecs(timestamp),
1968 vie_.GetCaptureLastTimestamp(capture_id));
1969
1970 SendI420ScreencastFrameWithTimestamp(kVP8Codec.width, kVP8Codec.height, 0);
1971 EXPECT_EQ(0, vie_.GetCaptureLastTimestamp(capture_id));
1972}
1973#endif
1974
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001975/////////////////////////
1976// Tests with real ViE //
1977/////////////////////////
1978
1979// Tests that we can find codecs by name or id.
1980TEST_F(WebRtcVideoEngineTest, FindCodec) {
1981 // We should not need to init engine in order to get codecs.
1982 const std::vector<cricket::VideoCodec>& c = engine_.codecs();
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +00001983 EXPECT_EQ(4U, c.size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001984
1985 cricket::VideoCodec vp8(104, "VP8", 320, 200, 30, 0);
1986 EXPECT_TRUE(engine_.FindCodec(vp8));
1987
1988 cricket::VideoCodec vp8_ci(104, "vp8", 320, 200, 30, 0);
1989 EXPECT_TRUE(engine_.FindCodec(vp8));
1990
1991 cricket::VideoCodec vp8_diff_fr_diff_pref(104, "VP8", 320, 200, 50, 50);
1992 EXPECT_TRUE(engine_.FindCodec(vp8_diff_fr_diff_pref));
1993
1994 cricket::VideoCodec vp8_diff_id(95, "VP8", 320, 200, 30, 0);
1995 EXPECT_FALSE(engine_.FindCodec(vp8_diff_id));
1996 vp8_diff_id.id = 97;
1997 EXPECT_TRUE(engine_.FindCodec(vp8_diff_id));
1998
1999 cricket::VideoCodec vp8_diff_res(104, "VP8", 320, 111, 30, 0);
2000 EXPECT_FALSE(engine_.FindCodec(vp8_diff_res));
2001
2002 // PeerConnection doesn't negotiate the resolution at this point.
2003 // Test that FindCodec can handle the case when width/height is 0.
2004 cricket::VideoCodec vp8_zero_res(104, "VP8", 0, 0, 30, 0);
2005 EXPECT_TRUE(engine_.FindCodec(vp8_zero_res));
2006
2007 cricket::VideoCodec red(101, "RED", 0, 0, 30, 0);
2008 EXPECT_TRUE(engine_.FindCodec(red));
2009
2010 cricket::VideoCodec red_ci(101, "red", 0, 0, 30, 0);
2011 EXPECT_TRUE(engine_.FindCodec(red));
2012
2013 cricket::VideoCodec fec(102, "ULPFEC", 0, 0, 30, 0);
2014 EXPECT_TRUE(engine_.FindCodec(fec));
2015
2016 cricket::VideoCodec fec_ci(102, "ulpfec", 0, 0, 30, 0);
2017 EXPECT_TRUE(engine_.FindCodec(fec));
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +00002018
2019 cricket::VideoCodec rtx(96, "rtx", 0, 0, 30, 0);
2020 EXPECT_TRUE(engine_.FindCodec(rtx));
2021}
2022
2023TEST_F(WebRtcVideoEngineTest, RtxCodecHasAptSet) {
2024 std::vector<cricket::VideoCodec>::const_iterator it;
2025 bool apt_checked = false;
2026 for (it = engine_.codecs().begin(); it != engine_.codecs().end(); ++it) {
2027 if (_stricmp(cricket::kRtxCodecName, it->name.c_str()) && it->id != 96) {
2028 continue;
2029 }
2030 int apt;
2031 EXPECT_TRUE(it->GetParam("apt", &apt));
2032 EXPECT_EQ(100, apt);
2033 apt_checked = true;
2034 }
2035 EXPECT_TRUE(apt_checked);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002036}
2037
2038TEST_F(WebRtcVideoEngineTest, StartupShutdown) {
2039 EXPECT_TRUE(engine_.Init(talk_base::Thread::Current()));
2040 engine_.Terminate();
2041}
2042
2043TEST_PRE_VIDEOENGINE_INIT(WebRtcVideoEngineTest, ConstrainNewCodec)
2044TEST_POST_VIDEOENGINE_INIT(WebRtcVideoEngineTest, ConstrainNewCodec)
2045
2046TEST_PRE_VIDEOENGINE_INIT(WebRtcVideoEngineTest, ConstrainRunningCodec)
2047TEST_POST_VIDEOENGINE_INIT(WebRtcVideoEngineTest, ConstrainRunningCodec)
2048
2049// TODO(juberti): Figure out why ViE is munging the COM refcount.
2050#ifdef WIN32
2051TEST_F(WebRtcVideoEngineTest, DISABLED_CheckCoInitialize) {
2052 Base::CheckCoInitialize();
2053}
2054#endif
2055
2056TEST_F(WebRtcVideoEngineTest, CreateChannel) {
2057 EXPECT_TRUE(engine_.Init(talk_base::Thread::Current()));
2058 cricket::VideoMediaChannel* channel = engine_.CreateChannel(NULL);
2059 EXPECT_TRUE(channel != NULL);
2060 delete channel;
2061}
2062
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002063TEST_F(WebRtcVideoMediaChannelTest, SetRecvCodecs) {
2064 std::vector<cricket::VideoCodec> codecs;
2065 codecs.push_back(kVP8Codec);
2066 EXPECT_TRUE(channel_->SetRecvCodecs(codecs));
2067}
2068TEST_F(WebRtcVideoMediaChannelTest, SetRecvCodecsWrongPayloadType) {
2069 std::vector<cricket::VideoCodec> codecs;
2070 codecs.push_back(kVP8Codec);
2071 codecs[0].id = 99;
2072 EXPECT_TRUE(channel_->SetRecvCodecs(codecs));
2073}
2074TEST_F(WebRtcVideoMediaChannelTest, SetRecvCodecsUnsupportedCodec) {
2075 std::vector<cricket::VideoCodec> codecs;
2076 codecs.push_back(kVP8Codec);
2077 codecs.push_back(cricket::VideoCodec(101, "VP1", 640, 400, 30, 0));
2078 EXPECT_FALSE(channel_->SetRecvCodecs(codecs));
2079}
2080
mallinath@webrtc.org92fdfeb2014-02-17 18:49:41 +00002081TEST_F(WebRtcVideoMediaChannelTest, GetRtpSendTimeExtension) {
2082 // Enable RTP timestamp extension.
2083 const int id = 12;
2084 std::vector<cricket::RtpHeaderExtension> extensions;
2085 extensions.push_back(cricket::RtpHeaderExtension(
2086 "http://www.webrtc.org/experiments/rtp-hdrext/abs-send-time", id));
2087
2088 // Verify the send extension id.
2089 EXPECT_TRUE(channel_->SetSendRtpHeaderExtensions(extensions));
2090 EXPECT_EQ(id, channel_->GetRtpSendTimeExtnId());
2091}
2092
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002093TEST_F(WebRtcVideoMediaChannelTest, SetSend) {
2094 Base::SetSend();
2095}
2096TEST_F(WebRtcVideoMediaChannelTest, SetSendWithoutCodecs) {
2097 Base::SetSendWithoutCodecs();
2098}
2099TEST_F(WebRtcVideoMediaChannelTest, SetSendSetsTransportBufferSizes) {
2100 Base::SetSendSetsTransportBufferSizes();
2101}
2102
2103TEST_F(WebRtcVideoMediaChannelTest, SendAndReceiveVp8Vga) {
2104 SendAndReceive(cricket::VideoCodec(100, "VP8", 640, 400, 30, 0));
2105}
2106TEST_F(WebRtcVideoMediaChannelTest, SendAndReceiveVp8Qvga) {
2107 SendAndReceive(cricket::VideoCodec(100, "VP8", 320, 200, 30, 0));
2108}
2109TEST_F(WebRtcVideoMediaChannelTest, SendAndReceiveH264SvcQqvga) {
2110 SendAndReceive(cricket::VideoCodec(100, "VP8", 160, 100, 30, 0));
2111}
2112TEST_F(WebRtcVideoMediaChannelTest, SendManyResizeOnce) {
2113 SendManyResizeOnce();
2114}
2115
2116TEST_F(WebRtcVideoMediaChannelTest, SendVp8HdAndReceiveAdaptedVp8Vga) {
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00002117 EXPECT_TRUE(channel_->SetCapturer(kSsrc, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002118 channel_->UpdateAspectRatio(1280, 720);
2119 video_capturer_.reset(new cricket::FakeVideoCapturer);
2120 const std::vector<cricket::VideoFormat>* formats =
2121 video_capturer_->GetSupportedFormats();
2122 cricket::VideoFormat capture_format_hd = (*formats)[0];
2123 EXPECT_EQ(cricket::CS_RUNNING, video_capturer_->Start(capture_format_hd));
2124 EXPECT_TRUE(channel_->SetCapturer(kSsrc, video_capturer_.get()));
2125
2126 // Capture format HD -> adapt (OnOutputFormatRequest VGA) -> VGA.
2127 cricket::VideoCodec codec(100, "VP8", 1280, 720, 30, 0);
2128 EXPECT_TRUE(SetOneCodec(codec));
2129 codec.width /= 2;
2130 codec.height /= 2;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002131 EXPECT_TRUE(SetSend(true));
2132 EXPECT_TRUE(channel_->SetRender(true));
2133 EXPECT_EQ(0, renderer_.num_rendered_frames());
2134 EXPECT_TRUE(SendFrame());
2135 EXPECT_FRAME_WAIT(1, codec.width, codec.height, kTimeout);
2136}
2137
2138// TODO(juberti): Fix this test to tolerate missing stats.
2139TEST_F(WebRtcVideoMediaChannelTest, DISABLED_GetStats) {
2140 Base::GetStats();
2141}
2142
2143// TODO(juberti): Fix this test to tolerate missing stats.
2144TEST_F(WebRtcVideoMediaChannelTest, DISABLED_GetStatsMultipleRecvStreams) {
2145 Base::GetStatsMultipleRecvStreams();
2146}
2147
2148TEST_F(WebRtcVideoMediaChannelTest, GetStatsMultipleSendStreams) {
2149 Base::GetStatsMultipleSendStreams();
2150}
2151
2152TEST_F(WebRtcVideoMediaChannelTest, SetSendBandwidth) {
2153 Base::SetSendBandwidth();
2154}
2155TEST_F(WebRtcVideoMediaChannelTest, SetSendSsrc) {
2156 Base::SetSendSsrc();
2157}
2158TEST_F(WebRtcVideoMediaChannelTest, SetSendSsrcAfterSetCodecs) {
2159 Base::SetSendSsrcAfterSetCodecs();
2160}
2161
2162TEST_F(WebRtcVideoMediaChannelTest, SetRenderer) {
2163 Base::SetRenderer();
2164}
2165
2166TEST_F(WebRtcVideoMediaChannelTest, AddRemoveRecvStreams) {
2167 Base::AddRemoveRecvStreams();
2168}
2169
2170TEST_F(WebRtcVideoMediaChannelTest, AddRemoveRecvStreamAndRender) {
2171 Base::AddRemoveRecvStreamAndRender();
2172}
2173
2174TEST_F(WebRtcVideoMediaChannelTest, AddRemoveRecvStreamsNoConference) {
2175 Base::AddRemoveRecvStreamsNoConference();
2176}
2177
2178TEST_F(WebRtcVideoMediaChannelTest, AddRemoveSendStreams) {
2179 Base::AddRemoveSendStreams();
2180}
2181
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002182TEST_F(WebRtcVideoMediaChannelTest, SimulateConference) {
2183 Base::SimulateConference();
2184}
2185
2186TEST_F(WebRtcVideoMediaChannelTest, AddRemoveCapturer) {
2187 Base::AddRemoveCapturer();
2188}
2189
2190TEST_F(WebRtcVideoMediaChannelTest, RemoveCapturerWithoutAdd) {
2191 Base::RemoveCapturerWithoutAdd();
2192}
2193
2194TEST_F(WebRtcVideoMediaChannelTest, AddRemoveCapturerMultipleSources) {
2195 Base::AddRemoveCapturerMultipleSources();
2196}
2197
wu@webrtc.orgde305012013-10-31 15:40:38 +00002198// This test verifies DSCP settings are properly applied on video media channel.
2199TEST_F(WebRtcVideoMediaChannelTest, TestSetDscpOptions) {
2200 talk_base::scoped_ptr<cricket::FakeNetworkInterface> network_interface(
2201 new cricket::FakeNetworkInterface);
2202 channel_->SetInterface(network_interface.get());
2203 cricket::VideoOptions options;
2204 options.dscp.Set(true);
2205 EXPECT_TRUE(channel_->SetOptions(options));
2206 EXPECT_EQ(talk_base::DSCP_AF41, network_interface->dscp());
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +00002207 // Verify previous value is not modified if dscp option is not set.
2208 cricket::VideoOptions options1;
2209 EXPECT_TRUE(channel_->SetOptions(options1));
2210 EXPECT_EQ(talk_base::DSCP_AF41, network_interface->dscp());
wu@webrtc.orgde305012013-10-31 15:40:38 +00002211 options.dscp.Set(false);
2212 EXPECT_TRUE(channel_->SetOptions(options));
2213 EXPECT_EQ(talk_base::DSCP_DEFAULT, network_interface->dscp());
2214 channel_->SetInterface(NULL);
2215}
2216
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002217
2218TEST_F(WebRtcVideoMediaChannelTest, SetOptionsSucceedsWhenSending) {
2219 cricket::VideoOptions options;
2220 options.conference_mode.Set(true);
2221 EXPECT_TRUE(channel_->SetOptions(options));
2222
2223 // Verify SetOptions returns true on a different options.
2224 cricket::VideoOptions options2;
2225 options2.adapt_input_to_cpu_usage.Set(true);
2226 EXPECT_TRUE(channel_->SetOptions(options2));
2227
2228 // Set send codecs on the channel and start sending.
2229 std::vector<cricket::VideoCodec> codecs;
2230 codecs.push_back(kVP8Codec);
2231 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
2232 EXPECT_TRUE(channel_->SetSend(true));
2233
2234 // Verify SetOptions returns true if channel is already sending.
2235 cricket::VideoOptions options3;
2236 options3.conference_mode.Set(true);
2237 EXPECT_TRUE(channel_->SetOptions(options3));
2238}
2239
2240// Tests empty StreamParams is rejected.
2241TEST_F(WebRtcVideoMediaChannelTest, RejectEmptyStreamParams) {
2242 Base::RejectEmptyStreamParams();
2243}
2244
2245
2246TEST_F(WebRtcVideoMediaChannelTest, AdaptResolution16x10) {
2247 Base::AdaptResolution16x10();
2248}
2249
2250TEST_F(WebRtcVideoMediaChannelTest, AdaptResolution4x3) {
2251 Base::AdaptResolution4x3();
2252}
2253
2254TEST_F(WebRtcVideoMediaChannelTest, MuteStream) {
2255 Base::MuteStream();
2256}
2257
2258TEST_F(WebRtcVideoMediaChannelTest, MultipleSendStreams) {
2259 Base::MultipleSendStreams();
2260}
2261
2262// TODO(juberti): Restore this test once we support sending 0 fps.
2263TEST_F(WebRtcVideoMediaChannelTest, DISABLED_AdaptDropAllFrames) {
2264 Base::AdaptDropAllFrames();
2265}
2266// TODO(juberti): Understand why we get decode errors on this test.
2267TEST_F(WebRtcVideoMediaChannelTest, DISABLED_AdaptFramerate) {
2268 Base::AdaptFramerate();
2269}
2270
2271TEST_F(WebRtcVideoMediaChannelTest, SetSendStreamFormat0x0) {
2272 Base::SetSendStreamFormat0x0();
2273}
2274
2275// TODO(zhurunz): Fix the flakey test.
2276TEST_F(WebRtcVideoMediaChannelTest, DISABLED_SetSendStreamFormat) {
2277 Base::SetSendStreamFormat();
2278}
2279
2280TEST_F(WebRtcVideoMediaChannelTest, TwoStreamsSendAndReceive) {
2281 Base::TwoStreamsSendAndReceive(cricket::VideoCodec(100, "VP8", 640, 400, 30,
2282 0));
2283}
2284
2285TEST_F(WebRtcVideoMediaChannelTest, TwoStreamsReUseFirstStream) {
2286 Base::TwoStreamsReUseFirstStream(cricket::VideoCodec(100, "VP8", 640, 400, 30,
2287 0));
2288}
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00002289
henrike@webrtc.org18e59112014-03-14 17:19:38 +00002290TEST_F(WebRtcVideoMediaChannelTest, TwoStreamsSendAndUnsignalledRecv) {
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00002291 Base::TwoStreamsSendAndUnsignalledRecv(cricket::VideoCodec(100, "VP8", 640,
2292 400, 30, 0));
2293}
2294
henrike@webrtc.org806768a2014-02-27 21:03:09 +00002295TEST_F(WebRtcVideoMediaChannelTest,
henrike@webrtc.org18e59112014-03-14 17:19:38 +00002296 TwoStreamsSendAndFailUnsignalledRecv) {
henrike@webrtc.org806768a2014-02-27 21:03:09 +00002297 webrtc::Trace::set_level_filter(webrtc::kTraceAll);
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00002298 Base::TwoStreamsSendAndFailUnsignalledRecv(
2299 cricket::VideoCodec(100, "VP8", 640, 400, 30, 0));
2300}
2301
2302TEST_F(WebRtcVideoMediaChannelTest,
henrike@webrtc.org18e59112014-03-14 17:19:38 +00002303 TwoStreamsSendAndFailUnsignalledRecvInOneToOne) {
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00002304 Base::TwoStreamsSendAndFailUnsignalledRecvInOneToOne(
2305 cricket::VideoCodec(100, "VP8", 640, 400, 30, 0));
2306}
2307
2308TEST_F(WebRtcVideoMediaChannelTest,
henrike@webrtc.org18e59112014-03-14 17:19:38 +00002309 TwoStreamsAddAndRemoveUnsignalledRecv) {
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00002310 Base::TwoStreamsAddAndRemoveUnsignalledRecv(cricket::VideoCodec(100, "VP8",
2311 640, 400, 30,
2312 0));
2313}