3 * Copyright 2004 Google Inc.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
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.
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.
28 #include "talk/base/fakecpumonitor.h"
29 #include "talk/base/gunit.h"
30 #include "talk/base/logging.h"
31 #include "talk/base/scoped_ptr.h"
32 #include "talk/base/stream.h"
33 #include "talk/media/base/constants.h"
34 #include "talk/media/base/fakemediaprocessor.h"
35 #include "talk/media/base/fakenetworkinterface.h"
36 #include "talk/media/base/fakevideorenderer.h"
37 #include "talk/media/base/mediachannel.h"
38 #include "talk/media/base/testutils.h"
39 #include "talk/media/base/videoadapter.h"
40 #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"
51 // Tests for the WebRtcVideoEngine/VideoChannel code.
53 static const cricket::VideoCodec kVP8Codec720p(100, "VP8", 1280, 720, 30, 0);
54 static const cricket::VideoCodec kVP8Codec360p(100, "VP8", 640, 360, 30, 0);
55 static const cricket::VideoCodec kVP8Codec270p(100, "VP8", 480, 270, 30, 0);
56 static const cricket::VideoCodec kVP8Codec180p(100, "VP8", 320, 180, 30, 0);
58 static const cricket::VideoCodec kVP8Codec(100, "VP8", 640, 400, 30, 0);
59 static const cricket::VideoCodec kRedCodec(101, "red", 0, 0, 0, 0);
60 static const cricket::VideoCodec kUlpFecCodec(102, "ulpfec", 0, 0, 0, 0);
61 static const cricket::VideoCodec* const kVideoCodecs[] = {
67 static const unsigned int kMinBandwidthKbps = 50;
68 static const unsigned int kStartBandwidthKbps = 300;
69 static const unsigned int kMaxBandwidthKbps = 2000;
71 static const unsigned int kNumberOfTemporalLayers = 1;
73 static const uint32 kSsrcs1[] = {1};
74 static const uint32 kSsrcs2[] = {1, 2};
75 static const uint32 kSsrcs3[] = {1, 2, 3};
76 static const uint32 kRtxSsrc1[] = {4};
77 static const uint32 kRtxSsrcs3[] = {4, 5, 6};
80 class FakeViEWrapper : public cricket::ViEWrapper {
82 explicit FakeViEWrapper(cricket::FakeWebRtcVideoEngine* engine)
83 : cricket::ViEWrapper(engine, // base
90 engine) { // external decoder
94 // Test fixture to test WebRtcVideoEngine with a fake webrtc::VideoEngine.
95 // Useful for testing failure paths.
96 class WebRtcVideoEngineTestFake : public testing::Test,
97 public sigslot::has_slots<> {
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_),
106 voice_channel_(NULL),
107 last_error_(cricket::VideoMediaChannel::ERROR_NONE) {
110 bool result = engine_.Init(talk_base::Thread::Current());
112 channel_ = engine_.CreateChannel(voice_channel_);
113 channel_->SignalMediaError.connect(this,
114 &WebRtcVideoEngineTestFake::OnMediaError);
115 result = (channel_ != NULL);
119 void OnMediaError(uint32 ssrc, cricket::VideoMediaChannel::Error error) {
122 bool SendI420Frame(int width, int height) {
123 if (NULL == channel_) {
126 cricket::WebRtcVideoFrame frame;
127 if (!frame.InitToBlack(width, height, 1, 1, 0, 0)) {
130 cricket::FakeVideoCapturer capturer;
131 channel_->SendFrame(&capturer, &frame);
134 bool SendI420ScreencastFrame(int width, int height) {
135 return SendI420ScreencastFrameWithTimestamp(width, height, 0);
137 bool SendI420ScreencastFrameWithTimestamp(
138 int width, int height, int64 timestamp) {
139 if (NULL == channel_) {
142 cricket::WebRtcVideoFrame frame;
143 if (!frame.InitToBlack(width, height, 1, 1, 0, 0)) {
146 cricket::FakeVideoCapturer capturer;
147 capturer.SetScreencast(true);
148 channel_->SendFrame(&capturer, &frame);
151 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)));
165 void VerifyVP8SendCodec(int channel_num,
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
175 webrtc::VideoCodec gcodec;
176 EXPECT_EQ(0, vie_.GetSendCodec(channel_num, gcodec));
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);
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);
195 virtual void TearDown() {
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_;
208 cricket::VideoMediaChannel::Error last_error_;
211 // Test fixtures to test WebRtcVideoEngine with a real webrtc::VideoEngine.
212 class WebRtcVideoEngineTest
213 : public VideoEngineTest<cricket::WebRtcVideoEngine> {
215 typedef VideoEngineTest<cricket::WebRtcVideoEngine> Base;
217 class WebRtcVideoMediaChannelTest
218 : public VideoMediaChannelTest<
219 cricket::WebRtcVideoEngine, cricket::WebRtcVideoMediaChannel> {
221 typedef VideoMediaChannelTest<cricket::WebRtcVideoEngine,
222 cricket::WebRtcVideoMediaChannel> Base;
223 virtual cricket::VideoCodec DefaultCodec() { return kVP8Codec; }
224 virtual void SetUp() {
227 virtual void TearDown() {
232 /////////////////////////
233 // Tests with fake ViE //
234 /////////////////////////
236 // Tests that our stub library "works".
237 TEST_F(WebRtcVideoEngineTestFake, StartupShutdown) {
238 EXPECT_FALSE(vie_.IsInited());
239 EXPECT_TRUE(engine_.Init(talk_base::Thread::Current()));
240 EXPECT_TRUE(vie_.IsInited());
244 // Tests that webrtc logs are logged when they should be.
245 TEST_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, "");
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,
255 talk_base::Thread::Current()->ProcessMessages(100);
256 talk_base::LogMessage::RemoveLogToStream(&stream);
257 // Access |str| after LogMessage is done with it to avoid data racing.
258 EXPECT_NE(std::string::npos, str.find(webrtc_log));
261 // Tests that webrtc logs are not logged when they should't be.
262 TEST_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, "");
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,
275 talk_base::Thread::Current()->ProcessMessages(10);
276 EXPECT_EQ(std::string::npos, str.find(webrtc_log));
277 talk_base::LogMessage::RemoveLogToStream(&stream);
280 // Tests that we can create and destroy a channel.
281 TEST_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());
288 EXPECT_EQ(0, engine_.GetNumOfChannels());
291 // Tests that we properly handle failures in CreateChannel.
292 TEST_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);
299 // Tests that we properly handle failures in AllocateExternalCaptureDevice.
300 TEST_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);
307 // Test that we apply our default codecs properly.
308 TEST_F(WebRtcVideoEngineTestFake, SetSendCodecs) {
309 EXPECT_TRUE(SetupEngine());
310 int channel_num = vie_.GetLastChannel();
311 std::vector<cricket::VideoCodec> codecs(engine_.codecs());
312 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
313 VerifyVP8SendCodec(channel_num, kVP8Codec.width, kVP8Codec.height);
314 EXPECT_TRUE(vie_.GetHybridNackFecStatus(channel_num));
315 EXPECT_FALSE(vie_.GetNackStatus(channel_num));
316 // TODO(juberti): Check RTCP, PLI, TMMBR.
319 TEST_F(WebRtcVideoEngineTestFake, SetSendCodecsWithMinMaxBitrate) {
320 EXPECT_TRUE(SetupEngine());
321 int channel_num = vie_.GetLastChannel();
322 std::vector<cricket::VideoCodec> codecs(engine_.codecs());
323 codecs[0].params[cricket::kCodecParamMinBitrate] = "10";
324 codecs[0].params[cricket::kCodecParamMaxBitrate] = "20";
325 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
328 channel_num, kVP8Codec.width, kVP8Codec.height, 0, 20, 10, 20);
330 cricket::VideoCodec codec;
331 EXPECT_TRUE(channel_->GetSendCodec(&codec));
332 EXPECT_EQ("10", codec.params[cricket::kCodecParamMinBitrate]);
333 EXPECT_EQ("20", codec.params[cricket::kCodecParamMaxBitrate]);
336 TEST_F(WebRtcVideoEngineTestFake, SetSendCodecsWithMinMaxBitrateInvalid) {
337 EXPECT_TRUE(SetupEngine());
338 std::vector<cricket::VideoCodec> codecs(engine_.codecs());
339 codecs[0].params[cricket::kCodecParamMinBitrate] = "30";
340 codecs[0].params[cricket::kCodecParamMaxBitrate] = "20";
341 EXPECT_FALSE(channel_->SetSendCodecs(codecs));
344 TEST_F(WebRtcVideoEngineTestFake, SetSendCodecsWithLargeMinMaxBitrate) {
345 EXPECT_TRUE(SetupEngine());
346 int channel_num = vie_.GetLastChannel();
347 std::vector<cricket::VideoCodec> codecs(engine_.codecs());
348 codecs[0].params[cricket::kCodecParamMinBitrate] = "1000";
349 codecs[0].params[cricket::kCodecParamMaxBitrate] = "2000";
350 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
353 channel_num, kVP8Codec.width, kVP8Codec.height, 0, 2000, 1000,
357 TEST_F(WebRtcVideoEngineTestFake, SetSendCodecsWithMaxQuantization) {
358 EXPECT_TRUE(SetupEngine());
359 int channel_num = vie_.GetLastChannel();
360 std::vector<cricket::VideoCodec> codecs(engine_.codecs());
361 codecs[0].params[cricket::kCodecParamMaxQuantization] = "21";
362 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
365 channel_num, kVP8Codec.width, kVP8Codec.height, 0, 2000, 50, 300,
368 cricket::VideoCodec codec;
369 EXPECT_TRUE(channel_->GetSendCodec(&codec));
370 EXPECT_EQ("21", codec.params[cricket::kCodecParamMaxQuantization]);
373 TEST_F(WebRtcVideoEngineTestFake, SetOptionsWithMaxBitrate) {
374 EXPECT_TRUE(SetupEngine());
375 int channel_num = vie_.GetLastChannel();
376 std::vector<cricket::VideoCodec> codecs(engine_.codecs());
377 codecs[0].params[cricket::kCodecParamMinBitrate] = "10";
378 codecs[0].params[cricket::kCodecParamMaxBitrate] = "20";
379 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
382 channel_num, kVP8Codec.width, kVP8Codec.height, 0, 20, 10, 20);
384 // Verify that max bitrate doesn't change after SetOptions().
385 cricket::VideoOptions options;
386 options.video_noise_reduction.Set(true);
387 EXPECT_TRUE(channel_->SetOptions(options));
389 channel_num, kVP8Codec.width, kVP8Codec.height, 0, 20, 10, 20);
391 options.video_noise_reduction.Set(false);
392 options.conference_mode.Set(false);
393 EXPECT_TRUE(channel_->SetOptions(options));
395 channel_num, kVP8Codec.width, kVP8Codec.height, 0, 20, 10, 20);
398 TEST_F(WebRtcVideoEngineTestFake, SetOptionsWithLoweredBitrate) {
399 EXPECT_TRUE(SetupEngine());
400 int channel_num = vie_.GetLastChannel();
401 std::vector<cricket::VideoCodec> codecs(engine_.codecs());
402 codecs[0].params[cricket::kCodecParamMinBitrate] = "50";
403 codecs[0].params[cricket::kCodecParamMaxBitrate] = "100";
404 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
407 channel_num, kVP8Codec.width, kVP8Codec.height, 0, 100, 50, 100);
409 // Verify that min bitrate changes after SetOptions().
410 cricket::VideoOptions options;
411 options.lower_min_bitrate.Set(true);
412 EXPECT_TRUE(channel_->SetOptions(options));
414 channel_num, kVP8Codec.width, kVP8Codec.height, 0, 100, 30, 100);
417 TEST_F(WebRtcVideoEngineTestFake, MaxBitrateResetWithConferenceMode) {
418 EXPECT_TRUE(SetupEngine());
419 int channel_num = vie_.GetLastChannel();
420 std::vector<cricket::VideoCodec> codecs(engine_.codecs());
421 codecs[0].params[cricket::kCodecParamMinBitrate] = "10";
422 codecs[0].params[cricket::kCodecParamMaxBitrate] = "20";
423 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
426 channel_num, kVP8Codec.width, kVP8Codec.height, 0, 20, 10, 20);
428 cricket::VideoOptions options;
429 options.conference_mode.Set(true);
430 EXPECT_TRUE(channel_->SetOptions(options));
431 options.conference_mode.Set(false);
432 EXPECT_TRUE(channel_->SetOptions(options));
434 channel_num, kVP8Codec.width, kVP8Codec.height, 0,
435 kMaxBandwidthKbps, 10, 20);
438 // Verify the current send bitrate is used as start bitrate when reconfiguring
440 TEST_F(WebRtcVideoEngineTestFake, StartSendBitrate) {
441 EXPECT_TRUE(SetupEngine());
442 EXPECT_TRUE(channel_->AddSendStream(
443 cricket::StreamParams::CreateLegacy(1)));
444 int send_channel = vie_.GetLastChannel();
445 cricket::VideoCodec codec(kVP8Codec);
446 std::vector<cricket::VideoCodec> codec_list;
447 codec_list.push_back(codec);
448 EXPECT_TRUE(channel_->SetSendCodecs(codec_list));
449 const unsigned int kVideoMaxSendBitrateKbps = 2000;
450 const unsigned int kVideoMinSendBitrateKbps = 50;
451 const unsigned int kVideoDefaultStartSendBitrateKbps = 300;
452 VerifyVP8SendCodec(send_channel, kVP8Codec.width, kVP8Codec.height, 0,
453 kVideoMaxSendBitrateKbps, kVideoMinSendBitrateKbps,
454 kVideoDefaultStartSendBitrateKbps);
455 EXPECT_EQ(0, vie_.StartSend(send_channel));
457 // Increase the send bitrate and verify it is used as start bitrate.
458 const unsigned int kVideoSendBitrateBps = 768000;
459 vie_.SetSendBitrates(send_channel, kVideoSendBitrateBps, 0, 0);
460 EXPECT_TRUE(channel_->SetSendCodecs(codec_list));
461 VerifyVP8SendCodec(send_channel, kVP8Codec.width, kVP8Codec.height, 0,
462 kVideoMaxSendBitrateKbps, kVideoMinSendBitrateKbps,
463 kVideoSendBitrateBps / 1000);
465 // Never set a start bitrate higher than the max bitrate.
466 vie_.SetSendBitrates(send_channel, kVideoMaxSendBitrateKbps + 500, 0, 0);
467 EXPECT_TRUE(channel_->SetSendCodecs(codec_list));
468 VerifyVP8SendCodec(send_channel, kVP8Codec.width, kVP8Codec.height, 0,
469 kVideoMaxSendBitrateKbps, kVideoMinSendBitrateKbps,
470 kVideoDefaultStartSendBitrateKbps);
472 // Use the default start bitrate if the send bitrate is lower.
473 vie_.SetSendBitrates(send_channel, kVideoDefaultStartSendBitrateKbps - 50, 0,
475 EXPECT_TRUE(channel_->SetSendCodecs(codec_list));
476 VerifyVP8SendCodec(send_channel, kVP8Codec.width, kVP8Codec.height, 0,
477 kVideoMaxSendBitrateKbps, kVideoMinSendBitrateKbps,
478 kVideoDefaultStartSendBitrateKbps);
482 // Test that we constrain send codecs properly.
483 TEST_F(WebRtcVideoEngineTestFake, ConstrainSendCodecs) {
484 EXPECT_TRUE(SetupEngine());
485 int channel_num = vie_.GetLastChannel();
487 // Set max settings of 640x400x30.
488 EXPECT_TRUE(engine_.SetDefaultEncoderConfig(
489 cricket::VideoEncoderConfig(kVP8Codec)));
491 // Send codec format bigger than max setting.
492 cricket::VideoCodec codec(kVP8Codec);
495 codec.framerate = 60;
496 std::vector<cricket::VideoCodec> codec_list;
497 codec_list.push_back(codec);
499 // Set send codec and verify codec has been constrained.
500 EXPECT_TRUE(channel_->SetSendCodecs(codec_list));
501 VerifyVP8SendCodec(channel_num, kVP8Codec.width, kVP8Codec.height);
504 // Test that SetSendCodecs rejects bad format.
505 TEST_F(WebRtcVideoEngineTestFake, SetSendCodecsRejectBadFormat) {
506 EXPECT_TRUE(SetupEngine());
507 int channel_num = vie_.GetLastChannel();
510 cricket::VideoCodec codec(kVP8Codec);
512 std::vector<cricket::VideoCodec> codec_list;
513 codec_list.push_back(codec);
515 // Verify SetSendCodecs failed and send codec is not changed on engine.
516 EXPECT_FALSE(channel_->SetSendCodecs(codec_list));
517 webrtc::VideoCodec gcodec;
518 // Set plType to something other than the value to test against ensuring
519 // that failure will happen if it is not changed.
521 EXPECT_EQ(0, vie_.GetSendCodec(channel_num, gcodec));
522 EXPECT_EQ(0, gcodec.plType);
525 codec_list[0].width = 640;
526 codec_list[0].height = 0;
528 // Verify SetSendCodecs failed and send codec is not changed on engine.
529 EXPECT_FALSE(channel_->SetSendCodecs(codec_list));
530 // Set plType to something other than the value to test against ensuring
531 // that failure will happen if it is not changed.
533 EXPECT_EQ(0, vie_.GetSendCodec(channel_num, gcodec));
534 EXPECT_EQ(0, gcodec.plType);
537 // Test that SetSendCodecs rejects bad codec.
538 TEST_F(WebRtcVideoEngineTestFake, SetSendCodecsRejectBadCodec) {
539 EXPECT_TRUE(SetupEngine());
540 int channel_num = vie_.GetLastChannel();
542 // Set bad codec name.
543 cricket::VideoCodec codec(kVP8Codec);
545 std::vector<cricket::VideoCodec> codec_list;
546 codec_list.push_back(codec);
548 // Verify SetSendCodecs failed and send codec is not changed on engine.
549 EXPECT_FALSE(channel_->SetSendCodecs(codec_list));
550 webrtc::VideoCodec gcodec;
551 // Set plType to something other than the value to test against ensuring
552 // that failure will happen if it is not changed.
554 EXPECT_EQ(0, vie_.GetSendCodec(channel_num, gcodec));
555 EXPECT_EQ(0, gcodec.plType);
558 // Test that vie send codec is reset on new video frame size.
559 TEST_F(WebRtcVideoEngineTestFake, ResetVieSendCodecOnNewFrameSize) {
560 EXPECT_TRUE(SetupEngine());
561 int channel_num = vie_.GetLastChannel();
564 std::vector<cricket::VideoCodec> codec_list;
565 codec_list.push_back(kVP8Codec);
566 EXPECT_TRUE(channel_->SetSendCodecs(codec_list));
567 EXPECT_TRUE(channel_->AddSendStream(
568 cricket::StreamParams::CreateLegacy(123)));
569 EXPECT_TRUE(channel_->SetSend(true));
571 // Capture a smaller frame and verify vie send codec has been reset to
573 SendI420Frame(kVP8Codec.width / 2, kVP8Codec.height / 2);
574 VerifyVP8SendCodec(channel_num, kVP8Codec.width / 2, kVP8Codec.height / 2);
576 // Capture a frame bigger than send_codec_ and verify vie send codec has been
577 // reset (and clipped) to send_codec_.
578 SendI420Frame(kVP8Codec.width * 2, kVP8Codec.height * 2);
579 VerifyVP8SendCodec(channel_num, kVP8Codec.width, kVP8Codec.height);
582 // Test that we set our inbound codecs properly.
583 TEST_F(WebRtcVideoEngineTestFake, SetRecvCodecs) {
584 EXPECT_TRUE(SetupEngine());
585 int channel_num = vie_.GetLastChannel();
587 std::vector<cricket::VideoCodec> codecs;
588 codecs.push_back(kVP8Codec);
589 EXPECT_TRUE(channel_->SetRecvCodecs(codecs));
591 webrtc::VideoCodec wcodec;
592 EXPECT_TRUE(engine_.ConvertFromCricketVideoCodec(kVP8Codec, &wcodec));
593 EXPECT_TRUE(vie_.ReceiveCodecRegistered(channel_num, wcodec));
596 // Test that channel connects and disconnects external capturer correctly.
597 TEST_F(WebRtcVideoEngineTestFake, HasExternalCapturer) {
598 EXPECT_TRUE(SetupEngine());
599 int channel_num = vie_.GetLastChannel();
601 EXPECT_EQ(1, vie_.GetNumCapturers());
602 int capture_id = vie_.GetCaptureId(channel_num);
603 EXPECT_EQ(channel_num, vie_.GetCaptureChannelId(capture_id));
605 // Delete the channel should disconnect the capturer.
608 EXPECT_EQ(0, vie_.GetNumCapturers());
611 // Test that channel adds and removes renderer correctly.
612 TEST_F(WebRtcVideoEngineTestFake, HasRenderer) {
613 EXPECT_TRUE(SetupEngine());
614 int channel_num = vie_.GetLastChannel();
616 EXPECT_TRUE(vie_.GetHasRenderer(channel_num));
617 EXPECT_FALSE(vie_.GetRenderStarted(channel_num));
620 // Test that rtcp is enabled on the channel.
621 TEST_F(WebRtcVideoEngineTestFake, RtcpEnabled) {
622 EXPECT_TRUE(SetupEngine());
623 int channel_num = vie_.GetLastChannel();
624 EXPECT_EQ(webrtc::kRtcpCompound_RFC4585, vie_.GetRtcpStatus(channel_num));
627 // Test that key frame request method is set on the channel.
628 TEST_F(WebRtcVideoEngineTestFake, KeyFrameRequestEnabled) {
629 EXPECT_TRUE(SetupEngine());
630 int channel_num = vie_.GetLastChannel();
631 EXPECT_EQ(webrtc::kViEKeyFrameRequestPliRtcp,
632 vie_.GetKeyFrameRequestMethod(channel_num));
635 // Test that remb receive and send is enabled for the default channel in a 1:1
637 TEST_F(WebRtcVideoEngineTestFake, RembEnabled) {
638 EXPECT_TRUE(SetupEngine());
639 int channel_num = vie_.GetLastChannel();
640 EXPECT_TRUE(channel_->AddSendStream(
641 cricket::StreamParams::CreateLegacy(1)));
642 EXPECT_TRUE(channel_->SetSendCodecs(engine_.codecs()));
643 EXPECT_TRUE(vie_.GetRembStatusBwPartition(channel_num));
644 EXPECT_TRUE(channel_->SetSend(true));
645 EXPECT_TRUE(vie_.GetRembStatusBwPartition(channel_num));
646 EXPECT_TRUE(vie_.GetRembStatusContribute(channel_num));
649 // When in conference mode, test that remb is enabled on a receive channel but
650 // not for the default channel and that it uses the default channel for sending
652 TEST_F(WebRtcVideoEngineTestFake, RembEnabledOnReceiveChannels) {
653 EXPECT_TRUE(SetupEngine());
654 int default_channel = vie_.GetLastChannel();
655 cricket::VideoOptions options;
656 options.conference_mode.Set(true);
657 EXPECT_TRUE(channel_->SetOptions(options));
658 EXPECT_TRUE(channel_->AddSendStream(
659 cricket::StreamParams::CreateLegacy(1)));
660 EXPECT_TRUE(channel_->SetSendCodecs(engine_.codecs()));
661 EXPECT_TRUE(vie_.GetRembStatusBwPartition(default_channel));
662 EXPECT_TRUE(vie_.GetRembStatusContribute(default_channel));
663 EXPECT_TRUE(channel_->SetSend(true));
664 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(1)));
665 int new_channel_num = vie_.GetLastChannel();
666 EXPECT_NE(default_channel, new_channel_num);
668 EXPECT_TRUE(vie_.GetRembStatusBwPartition(default_channel));
669 EXPECT_TRUE(vie_.GetRembStatusContribute(default_channel));
670 EXPECT_FALSE(vie_.GetRembStatusBwPartition(new_channel_num));
671 EXPECT_TRUE(vie_.GetRembStatusContribute(new_channel_num));
674 TEST_F(WebRtcVideoEngineTestFake, RecvStreamWithRtx) {
675 EXPECT_TRUE(SetupEngine());
676 int default_channel = vie_.GetLastChannel();
677 cricket::VideoOptions options;
678 options.conference_mode.Set(true);
679 EXPECT_TRUE(channel_->SetOptions(options));
680 EXPECT_TRUE(channel_->AddSendStream(
681 cricket::CreateSimWithRtxStreamParams("cname",
682 MAKE_VECTOR(kSsrcs3),
683 MAKE_VECTOR(kRtxSsrcs3))));
684 EXPECT_TRUE(channel_->SetSendCodecs(engine_.codecs()));
685 EXPECT_TRUE(channel_->SetSend(true));
686 EXPECT_TRUE(channel_->AddRecvStream(
687 cricket::CreateSimWithRtxStreamParams("cname",
688 MAKE_VECTOR(kSsrcs1),
689 MAKE_VECTOR(kRtxSsrc1))));
690 int new_channel_num = vie_.GetLastChannel();
691 EXPECT_NE(default_channel, new_channel_num);
692 EXPECT_EQ(4, vie_.GetRemoteRtxSsrc(new_channel_num));
695 TEST_F(WebRtcVideoEngineTestFake, RecvStreamNoRtx) {
696 EXPECT_TRUE(SetupEngine());
697 int default_channel = vie_.GetLastChannel();
698 cricket::VideoOptions options;
699 options.conference_mode.Set(true);
700 EXPECT_TRUE(channel_->SetOptions(options));
701 EXPECT_TRUE(channel_->AddSendStream(
702 cricket::CreateSimWithRtxStreamParams("cname",
703 MAKE_VECTOR(kSsrcs3),
704 MAKE_VECTOR(kRtxSsrcs3))));
705 EXPECT_TRUE(channel_->SetSendCodecs(engine_.codecs()));
706 EXPECT_TRUE(channel_->SetSend(true));
707 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(1)));
708 int new_channel_num = vie_.GetLastChannel();
709 EXPECT_NE(default_channel, new_channel_num);
710 EXPECT_EQ(-1, vie_.GetRemoteRtxSsrc(new_channel_num));
713 // Test support for RTP timestamp offset header extension.
714 TEST_F(WebRtcVideoEngineTestFake, RtpTimestampOffsetHeaderExtensions) {
715 EXPECT_TRUE(SetupEngine());
716 int channel_num = vie_.GetLastChannel();
717 cricket::VideoOptions options;
718 options.conference_mode.Set(true);
719 EXPECT_TRUE(channel_->SetOptions(options));
721 // Verify extensions are off by default.
722 EXPECT_EQ(0, vie_.GetSendRtpTimestampOffsetExtensionId(channel_num));
723 EXPECT_EQ(0, vie_.GetReceiveRtpTimestampOffsetExtensionId(channel_num));
725 // Enable RTP timestamp extension.
727 std::vector<cricket::RtpHeaderExtension> extensions;
728 extensions.push_back(cricket::RtpHeaderExtension(
729 "urn:ietf:params:rtp-hdrext:toffset", id));
731 // Verify the send extension id.
732 EXPECT_TRUE(channel_->SetSendRtpHeaderExtensions(extensions));
733 EXPECT_EQ(id, vie_.GetSendRtpTimestampOffsetExtensionId(channel_num));
735 // Remove the extension id.
736 std::vector<cricket::RtpHeaderExtension> empty_extensions;
737 EXPECT_TRUE(channel_->SetSendRtpHeaderExtensions(empty_extensions));
738 EXPECT_EQ(0, vie_.GetSendRtpTimestampOffsetExtensionId(channel_num));
740 // Verify receive extension id.
741 EXPECT_TRUE(channel_->SetRecvRtpHeaderExtensions(extensions));
742 EXPECT_EQ(id, vie_.GetReceiveRtpTimestampOffsetExtensionId(channel_num));
744 // Add a new receive stream and verify the extension is set.
745 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(2)));
746 int new_channel_num = vie_.GetLastChannel();
747 EXPECT_NE(channel_num, new_channel_num);
748 EXPECT_EQ(id, vie_.GetReceiveRtpTimestampOffsetExtensionId(new_channel_num));
750 // Remove the extension id.
751 EXPECT_TRUE(channel_->SetRecvRtpHeaderExtensions(empty_extensions));
752 EXPECT_EQ(0, vie_.GetReceiveRtpTimestampOffsetExtensionId(channel_num));
753 EXPECT_EQ(0, vie_.GetReceiveRtpTimestampOffsetExtensionId(new_channel_num));
756 // Test support for absolute send time header extension.
757 TEST_F(WebRtcVideoEngineTestFake, AbsoluteSendTimeHeaderExtensions) {
758 EXPECT_TRUE(SetupEngine());
759 int channel_num = vie_.GetLastChannel();
760 cricket::VideoOptions options;
761 options.conference_mode.Set(true);
762 EXPECT_TRUE(channel_->SetOptions(options));
764 // Verify extensions are off by default.
765 EXPECT_EQ(0, vie_.GetSendAbsoluteSendTimeExtensionId(channel_num));
766 EXPECT_EQ(0, vie_.GetReceiveAbsoluteSendTimeExtensionId(channel_num));
768 // Enable RTP timestamp extension.
770 std::vector<cricket::RtpHeaderExtension> extensions;
771 extensions.push_back(cricket::RtpHeaderExtension(
772 "http://www.webrtc.org/experiments/rtp-hdrext/abs-send-time", id));
774 // Verify the send extension id.
775 EXPECT_TRUE(channel_->SetSendRtpHeaderExtensions(extensions));
776 EXPECT_EQ(id, vie_.GetSendAbsoluteSendTimeExtensionId(channel_num));
778 // Remove the extension id.
779 std::vector<cricket::RtpHeaderExtension> empty_extensions;
780 EXPECT_TRUE(channel_->SetSendRtpHeaderExtensions(empty_extensions));
781 EXPECT_EQ(0, vie_.GetSendAbsoluteSendTimeExtensionId(channel_num));
783 // Verify receive extension id.
784 EXPECT_TRUE(channel_->SetRecvRtpHeaderExtensions(extensions));
785 EXPECT_EQ(id, vie_.GetReceiveAbsoluteSendTimeExtensionId(channel_num));
787 // Add a new receive stream and verify the extension is set.
788 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(2)));
789 int new_channel_num = vie_.GetLastChannel();
790 EXPECT_NE(channel_num, new_channel_num);
791 EXPECT_EQ(id, vie_.GetReceiveAbsoluteSendTimeExtensionId(new_channel_num));
793 // Remove the extension id.
794 EXPECT_TRUE(channel_->SetRecvRtpHeaderExtensions(empty_extensions));
795 EXPECT_EQ(0, vie_.GetReceiveAbsoluteSendTimeExtensionId(channel_num));
796 EXPECT_EQ(0, vie_.GetReceiveAbsoluteSendTimeExtensionId(new_channel_num));
799 TEST_F(WebRtcVideoEngineTestFake, LeakyBucketTest) {
800 EXPECT_TRUE(SetupEngine());
802 // Verify this is off by default.
803 EXPECT_TRUE(channel_->AddSendStream(cricket::StreamParams::CreateLegacy(1)));
804 int first_send_channel = vie_.GetLastChannel();
805 EXPECT_FALSE(vie_.GetTransmissionSmoothingStatus(first_send_channel));
807 // Enable the experiment and verify.
808 cricket::VideoOptions options;
809 options.conference_mode.Set(true);
810 options.video_leaky_bucket.Set(true);
811 EXPECT_TRUE(channel_->SetOptions(options));
812 EXPECT_TRUE(vie_.GetTransmissionSmoothingStatus(first_send_channel));
814 // Add a receive channel and verify leaky bucket isn't enabled.
815 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(2)));
816 int recv_channel_num = vie_.GetLastChannel();
817 EXPECT_NE(first_send_channel, recv_channel_num);
818 EXPECT_FALSE(vie_.GetTransmissionSmoothingStatus(recv_channel_num));
820 // Add a new send stream and verify leaky bucket is enabled from start.
821 EXPECT_TRUE(channel_->AddSendStream(cricket::StreamParams::CreateLegacy(3)));
822 int second_send_channel = vie_.GetLastChannel();
823 EXPECT_NE(first_send_channel, second_send_channel);
824 EXPECT_TRUE(vie_.GetTransmissionSmoothingStatus(second_send_channel));
827 TEST_F(WebRtcVideoEngineTestFake, BufferedModeLatency) {
828 EXPECT_TRUE(SetupEngine());
830 // Verify this is off by default.
831 EXPECT_TRUE(channel_->AddSendStream(cricket::StreamParams::CreateLegacy(1)));
832 int first_send_channel = vie_.GetLastChannel();
833 EXPECT_EQ(0, vie_.GetSenderTargetDelay(first_send_channel));
834 EXPECT_EQ(0, vie_.GetReceiverTargetDelay(first_send_channel));
836 // Enable the experiment and verify. The default channel will have both
837 // sender and receiver buffered mode enabled.
838 cricket::VideoOptions options;
839 options.conference_mode.Set(true);
840 options.buffered_mode_latency.Set(100);
841 EXPECT_TRUE(channel_->SetOptions(options));
842 EXPECT_EQ(100, vie_.GetSenderTargetDelay(first_send_channel));
843 EXPECT_EQ(100, vie_.GetReceiverTargetDelay(first_send_channel));
845 // Add a receive channel and verify sender buffered mode isn't enabled.
846 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(2)));
847 int recv_channel_num = vie_.GetLastChannel();
848 EXPECT_NE(first_send_channel, recv_channel_num);
849 EXPECT_EQ(0, vie_.GetSenderTargetDelay(recv_channel_num));
850 EXPECT_EQ(100, vie_.GetReceiverTargetDelay(recv_channel_num));
852 // Add a new send stream and verify sender buffered mode is enabled.
853 EXPECT_TRUE(channel_->AddSendStream(cricket::StreamParams::CreateLegacy(3)));
854 int second_send_channel = vie_.GetLastChannel();
855 EXPECT_NE(first_send_channel, second_send_channel);
856 EXPECT_EQ(100, vie_.GetSenderTargetDelay(second_send_channel));
857 EXPECT_EQ(0, vie_.GetReceiverTargetDelay(second_send_channel));
859 // Disable sender buffered mode and verify.
860 options.buffered_mode_latency.Set(cricket::kBufferedModeDisabled);
861 EXPECT_TRUE(channel_->SetOptions(options));
862 EXPECT_EQ(0, vie_.GetSenderTargetDelay(first_send_channel));
863 EXPECT_EQ(0, vie_.GetReceiverTargetDelay(first_send_channel));
864 EXPECT_EQ(0, vie_.GetSenderTargetDelay(second_send_channel));
865 EXPECT_EQ(0, vie_.GetReceiverTargetDelay(second_send_channel));
866 EXPECT_EQ(0, vie_.GetSenderTargetDelay(recv_channel_num));
867 EXPECT_EQ(0, vie_.GetReceiverTargetDelay(recv_channel_num));
870 TEST_F(WebRtcVideoEngineTestFake, AdditiveVideoOptions) {
871 EXPECT_TRUE(SetupEngine());
873 EXPECT_TRUE(channel_->AddSendStream(cricket::StreamParams::CreateLegacy(1)));
874 int first_send_channel = vie_.GetLastChannel();
875 EXPECT_EQ(0, vie_.GetSenderTargetDelay(first_send_channel));
876 EXPECT_EQ(0, vie_.GetReceiverTargetDelay(first_send_channel));
878 cricket::VideoOptions options1;
879 options1.buffered_mode_latency.Set(100);
880 EXPECT_TRUE(channel_->SetOptions(options1));
881 EXPECT_EQ(100, vie_.GetSenderTargetDelay(first_send_channel));
882 EXPECT_EQ(100, vie_.GetReceiverTargetDelay(first_send_channel));
883 EXPECT_FALSE(vie_.GetTransmissionSmoothingStatus(first_send_channel));
885 cricket::VideoOptions options2;
886 options2.video_leaky_bucket.Set(true);
887 EXPECT_TRUE(channel_->SetOptions(options2));
888 EXPECT_TRUE(vie_.GetTransmissionSmoothingStatus(first_send_channel));
889 // The buffered_mode_latency still takes effect.
890 EXPECT_EQ(100, vie_.GetSenderTargetDelay(first_send_channel));
891 EXPECT_EQ(100, vie_.GetReceiverTargetDelay(first_send_channel));
893 options1.buffered_mode_latency.Set(50);
894 EXPECT_TRUE(channel_->SetOptions(options1));
895 EXPECT_EQ(50, vie_.GetSenderTargetDelay(first_send_channel));
896 EXPECT_EQ(50, vie_.GetReceiverTargetDelay(first_send_channel));
897 // The video_leaky_bucket still takes effect.
898 EXPECT_TRUE(vie_.GetTransmissionSmoothingStatus(first_send_channel));
901 // Test that AddRecvStream doesn't create new channel for 1:1 call.
902 TEST_F(WebRtcVideoEngineTestFake, AddRecvStream1On1) {
903 EXPECT_TRUE(SetupEngine());
904 int channel_num = vie_.GetLastChannel();
905 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(1)));
906 EXPECT_EQ(channel_num, vie_.GetLastChannel());
909 // Test that NACK, PLI and REMB are enabled for internal codec.
910 TEST_F(WebRtcVideoEngineTestFake, InternalCodecFeedbackParams) {
911 EXPECT_TRUE(SetupEngine());
913 std::vector<cricket::VideoCodec> codecs(engine_.codecs());
914 // Vp8 will appear at the beginning.
916 EXPECT_EQ("VP8", codecs[pos].name);
917 VerifyCodecFeedbackParams(codecs[pos]);
920 // Test that AddRecvStream doesn't change remb for 1:1 call.
921 TEST_F(WebRtcVideoEngineTestFake, NoRembChangeAfterAddRecvStream) {
922 EXPECT_TRUE(SetupEngine());
923 int channel_num = vie_.GetLastChannel();
924 EXPECT_TRUE(channel_->AddSendStream(
925 cricket::StreamParams::CreateLegacy(1)));
926 EXPECT_TRUE(channel_->SetSendCodecs(engine_.codecs()));
927 EXPECT_TRUE(vie_.GetRembStatusBwPartition(channel_num));
928 EXPECT_TRUE(vie_.GetRembStatusContribute(channel_num));
929 EXPECT_TRUE(channel_->SetSend(true));
930 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(1)));
931 EXPECT_TRUE(vie_.GetRembStatusBwPartition(channel_num));
932 EXPECT_TRUE(vie_.GetRembStatusContribute(channel_num));
935 // Verify default REMB setting and that it can be turned on and off.
936 TEST_F(WebRtcVideoEngineTestFake, RembOnOff) {
937 EXPECT_TRUE(SetupEngine());
938 int channel_num = vie_.GetLastChannel();
939 // Verify REMB sending is always off by default.
940 EXPECT_FALSE(vie_.GetRembStatusBwPartition(channel_num));
942 // Verify that REMB is turned on when setting default codecs since the
943 // default codecs have REMB enabled.
944 EXPECT_TRUE(channel_->SetSendCodecs(engine_.codecs()));
945 EXPECT_TRUE(vie_.GetRembStatusBwPartition(channel_num));
947 // Verify that REMB is turned off when codecs without REMB are set.
948 std::vector<cricket::VideoCodec> codecs = engine_.codecs();
949 // Clearing the codecs' FeedbackParams and setting send codecs should disable
951 for (std::vector<cricket::VideoCodec>::iterator iter = codecs.begin();
952 iter != codecs.end(); ++iter) {
953 // Intersecting with empty will clear the FeedbackParams.
954 cricket::FeedbackParams empty_params;
955 iter->feedback_params.Intersect(empty_params);
956 EXPECT_TRUE(iter->feedback_params.params().empty());
958 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
959 EXPECT_FALSE(vie_.GetRembStatusBwPartition(channel_num));
962 // Test that nack is enabled on the channel if we don't offer red/fec.
963 TEST_F(WebRtcVideoEngineTestFake, NackEnabled) {
964 EXPECT_TRUE(SetupEngine());
965 int channel_num = vie_.GetLastChannel();
966 std::vector<cricket::VideoCodec> codecs(engine_.codecs());
967 codecs.resize(1); // toss out red and ulpfec
968 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
969 EXPECT_TRUE(vie_.GetNackStatus(channel_num));
972 // Test that we enable hybrid NACK FEC mode.
973 TEST_F(WebRtcVideoEngineTestFake, HybridNackFec) {
974 EXPECT_TRUE(SetupEngine());
975 int channel_num = vie_.GetLastChannel();
976 EXPECT_TRUE(channel_->SetRecvCodecs(engine_.codecs()));
977 EXPECT_TRUE(channel_->SetSendCodecs(engine_.codecs()));
978 EXPECT_TRUE(vie_.GetHybridNackFecStatus(channel_num));
979 EXPECT_FALSE(vie_.GetNackStatus(channel_num));
982 // Test that we enable hybrid NACK FEC mode when calling SetSendCodecs and
983 // SetReceiveCodecs in reversed order.
984 TEST_F(WebRtcVideoEngineTestFake, HybridNackFecReversedOrder) {
985 EXPECT_TRUE(SetupEngine());
986 int channel_num = vie_.GetLastChannel();
987 EXPECT_TRUE(channel_->SetSendCodecs(engine_.codecs()));
988 EXPECT_TRUE(channel_->SetRecvCodecs(engine_.codecs()));
989 EXPECT_TRUE(vie_.GetHybridNackFecStatus(channel_num));
990 EXPECT_FALSE(vie_.GetNackStatus(channel_num));
993 // Test NACK vs Hybrid NACK/FEC interop call setup, i.e. only use NACK even if
994 // red/fec is offered as receive codec.
995 TEST_F(WebRtcVideoEngineTestFake, VideoProtectionInterop) {
996 EXPECT_TRUE(SetupEngine());
997 int channel_num = vie_.GetLastChannel();
998 std::vector<cricket::VideoCodec> recv_codecs(engine_.codecs());
999 std::vector<cricket::VideoCodec> send_codecs(engine_.codecs());
1000 // Only add VP8 as send codec.
1001 send_codecs.resize(1);
1002 EXPECT_TRUE(channel_->SetRecvCodecs(recv_codecs));
1003 EXPECT_TRUE(channel_->SetSendCodecs(send_codecs));
1004 EXPECT_FALSE(vie_.GetHybridNackFecStatus(channel_num));
1005 EXPECT_TRUE(vie_.GetNackStatus(channel_num));
1008 // Test NACK vs Hybrid NACK/FEC interop call setup, i.e. only use NACK even if
1009 // red/fec is offered as receive codec. Call order reversed compared to
1010 // VideoProtectionInterop.
1011 TEST_F(WebRtcVideoEngineTestFake, VideoProtectionInteropReversed) {
1012 EXPECT_TRUE(SetupEngine());
1013 int channel_num = vie_.GetLastChannel();
1014 std::vector<cricket::VideoCodec> recv_codecs(engine_.codecs());
1015 std::vector<cricket::VideoCodec> send_codecs(engine_.codecs());
1016 // Only add VP8 as send codec.
1017 send_codecs.resize(1);
1018 EXPECT_TRUE(channel_->SetSendCodecs(send_codecs));
1019 EXPECT_TRUE(channel_->SetRecvCodecs(recv_codecs));
1020 EXPECT_FALSE(vie_.GetHybridNackFecStatus(channel_num));
1021 EXPECT_TRUE(vie_.GetNackStatus(channel_num));
1024 // Test that NACK, not hybrid mode, is enabled in conference mode.
1025 TEST_F(WebRtcVideoEngineTestFake, HybridNackFecConference) {
1026 EXPECT_TRUE(SetupEngine());
1027 // Setup the send channel.
1028 int send_channel_num = vie_.GetLastChannel();
1029 cricket::VideoOptions options;
1030 options.conference_mode.Set(true);
1031 EXPECT_TRUE(channel_->SetOptions(options));
1032 EXPECT_TRUE(channel_->SetRecvCodecs(engine_.codecs()));
1033 EXPECT_TRUE(channel_->SetSendCodecs(engine_.codecs()));
1034 EXPECT_FALSE(vie_.GetHybridNackFecStatus(send_channel_num));
1035 EXPECT_TRUE(vie_.GetNackStatus(send_channel_num));
1036 // Add a receive stream.
1037 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(1)));
1038 int receive_channel_num = vie_.GetLastChannel();
1039 EXPECT_FALSE(vie_.GetHybridNackFecStatus(receive_channel_num));
1040 EXPECT_TRUE(vie_.GetNackStatus(receive_channel_num));
1043 // Test that when AddRecvStream in conference mode, a new channel is created
1044 // for receiving. And the new channel's "original channel" is the send channel.
1045 TEST_F(WebRtcVideoEngineTestFake, AddRemoveRecvStreamConference) {
1046 EXPECT_TRUE(SetupEngine());
1047 // Setup the send channel.
1048 int send_channel_num = vie_.GetLastChannel();
1049 cricket::VideoOptions options;
1050 options.conference_mode.Set(true);
1051 EXPECT_TRUE(channel_->SetOptions(options));
1052 // Add a receive stream.
1053 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(1)));
1054 int receive_channel_num = vie_.GetLastChannel();
1055 EXPECT_EQ(send_channel_num, vie_.GetOriginalChannelId(receive_channel_num));
1056 EXPECT_TRUE(channel_->RemoveRecvStream(1));
1057 EXPECT_FALSE(vie_.IsChannel(receive_channel_num));
1060 // Test that we can create a channel and start/stop rendering out on it.
1061 TEST_F(WebRtcVideoEngineTestFake, SetRender) {
1062 EXPECT_TRUE(SetupEngine());
1063 int channel_num = vie_.GetLastChannel();
1065 // Verify we can start/stop/start/stop rendering.
1066 EXPECT_TRUE(channel_->SetRender(true));
1067 EXPECT_TRUE(vie_.GetRenderStarted(channel_num));
1068 EXPECT_TRUE(channel_->SetRender(false));
1069 EXPECT_FALSE(vie_.GetRenderStarted(channel_num));
1070 EXPECT_TRUE(channel_->SetRender(true));
1071 EXPECT_TRUE(vie_.GetRenderStarted(channel_num));
1072 EXPECT_TRUE(channel_->SetRender(false));
1073 EXPECT_FALSE(vie_.GetRenderStarted(channel_num));
1076 // Test that we can create a channel and start/stop sending out on it.
1077 TEST_F(WebRtcVideoEngineTestFake, SetSend) {
1078 EXPECT_TRUE(SetupEngine());
1079 int channel_num = vie_.GetLastChannel();
1080 // Verify receiving is also started.
1081 EXPECT_TRUE(vie_.GetReceive(channel_num));
1083 // Set send codecs on the channel.
1084 std::vector<cricket::VideoCodec> codecs;
1085 codecs.push_back(kVP8Codec);
1086 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1087 EXPECT_TRUE(channel_->AddSendStream(
1088 cricket::StreamParams::CreateLegacy(123)));
1090 // Verify we can start/stop/start/stop sending.
1091 EXPECT_TRUE(channel_->SetSend(true));
1092 EXPECT_TRUE(vie_.GetSend(channel_num));
1093 EXPECT_TRUE(channel_->SetSend(false));
1094 EXPECT_FALSE(vie_.GetSend(channel_num));
1095 EXPECT_TRUE(channel_->SetSend(true));
1096 EXPECT_TRUE(vie_.GetSend(channel_num));
1097 EXPECT_TRUE(channel_->SetSend(false));
1098 EXPECT_FALSE(vie_.GetSend(channel_num));
1101 // Test that we set bandwidth properly when using full auto bandwidth mode.
1102 TEST_F(WebRtcVideoEngineTestFake, SetBandwidthAuto) {
1103 EXPECT_TRUE(SetupEngine());
1104 int channel_num = vie_.GetLastChannel();
1105 EXPECT_TRUE(channel_->SetSendCodecs(engine_.codecs()));
1106 EXPECT_TRUE(channel_->SetMaxSendBandwidth(cricket::kAutoBandwidth));
1107 VerifyVP8SendCodec(channel_num, kVP8Codec.width, kVP8Codec.height);
1110 // Test that we set bandwidth properly when using auto with upper bound.
1111 TEST_F(WebRtcVideoEngineTestFake, SetBandwidthCapped) {
1112 EXPECT_TRUE(SetupEngine());
1113 int channel_num = vie_.GetLastChannel();
1114 EXPECT_TRUE(channel_->SetSendCodecs(engine_.codecs()));
1115 EXPECT_TRUE(channel_->SetMaxSendBandwidth(768000));
1116 VerifyVP8SendCodec(channel_num, kVP8Codec.width, kVP8Codec.height, 0, 768U);
1119 // Test that we reduce the start bandwidth when the requested max is less than
1120 // the default start bandwidth.
1121 TEST_F(WebRtcVideoEngineTestFake, SetMaxBandwidthBelowDefaultStart) {
1122 EXPECT_TRUE(SetupEngine());
1123 int channel_num = vie_.GetLastChannel();
1124 EXPECT_TRUE(channel_->SetSendCodecs(engine_.codecs()));
1125 int max_bandwidth_kbps = (kMinBandwidthKbps + kStartBandwidthKbps) / 2;
1126 EXPECT_TRUE(channel_->SetMaxSendBandwidth(max_bandwidth_kbps * 1000));
1127 VerifyVP8SendCodec(channel_num, kVP8Codec.width, kVP8Codec.height, 0,
1128 max_bandwidth_kbps, kMinBandwidthKbps, max_bandwidth_kbps);
1131 // Test that we reduce the min bandwidth when the requested max is less than
1132 // the min bandwidth.
1133 TEST_F(WebRtcVideoEngineTestFake, SetMaxBandwidthBelowMin) {
1134 EXPECT_TRUE(SetupEngine());
1135 int channel_num = vie_.GetLastChannel();
1136 EXPECT_TRUE(channel_->SetSendCodecs(engine_.codecs()));
1137 int max_bandwidth_kbps = kMinBandwidthKbps / 2;
1138 EXPECT_TRUE(channel_->SetMaxSendBandwidth(max_bandwidth_kbps * 1000));
1139 VerifyVP8SendCodec(channel_num, kVP8Codec.width, kVP8Codec.height, 0,
1140 max_bandwidth_kbps, max_bandwidth_kbps, max_bandwidth_kbps);
1143 // Test that the start bandwidth can be controlled separately from the max
1145 TEST_F(WebRtcVideoEngineTestFake, SetStartBandwidth) {
1146 EXPECT_TRUE(SetupEngine());
1147 int channel_num = vie_.GetLastChannel();
1148 EXPECT_TRUE(channel_->SetSendCodecs(engine_.codecs()));
1149 int start_bandwidth_kbps = kStartBandwidthKbps + 1;
1150 EXPECT_TRUE(channel_->SetStartSendBandwidth(start_bandwidth_kbps * 1000));
1151 VerifyVP8SendCodec(channel_num, kVP8Codec.width, kVP8Codec.height, 0,
1152 kMaxBandwidthKbps, kMinBandwidthKbps, start_bandwidth_kbps);
1154 // Check that SetMaxSendBandwidth doesn't overwrite the start bandwidth.
1155 int max_bandwidth_kbps = kMaxBandwidthKbps + 1;
1156 EXPECT_TRUE(channel_->SetMaxSendBandwidth(max_bandwidth_kbps * 1000));
1157 VerifyVP8SendCodec(channel_num, kVP8Codec.width, kVP8Codec.height, 0,
1158 max_bandwidth_kbps, kMinBandwidthKbps, start_bandwidth_kbps);
1161 // Test that SetMaxSendBandwidth is ignored in conference mode.
1162 TEST_F(WebRtcVideoEngineTestFake, SetBandwidthInConference) {
1163 EXPECT_TRUE(SetupEngine());
1164 int channel_num = vie_.GetLastChannel();
1165 cricket::VideoOptions options;
1166 options.conference_mode.Set(true);
1167 EXPECT_TRUE(channel_->SetOptions(options));
1168 EXPECT_TRUE(channel_->SetSendCodecs(engine_.codecs()));
1169 VerifyVP8SendCodec(channel_num, kVP8Codec.width, kVP8Codec.height);
1171 // Set send bandwidth.
1172 EXPECT_TRUE(channel_->SetMaxSendBandwidth(768000));
1174 // Verify bitrate not changed.
1175 webrtc::VideoCodec gcodec;
1176 EXPECT_EQ(0, vie_.GetSendCodec(channel_num, gcodec));
1177 EXPECT_EQ(kMinBandwidthKbps, gcodec.minBitrate);
1178 EXPECT_EQ(kStartBandwidthKbps, gcodec.startBitrate);
1179 EXPECT_EQ(kMaxBandwidthKbps, gcodec.maxBitrate);
1180 EXPECT_NE(768U, gcodec.minBitrate);
1181 EXPECT_NE(768U, gcodec.startBitrate);
1182 EXPECT_NE(768U, gcodec.maxBitrate);
1185 // Test that sending screencast frames doesn't change bitrate.
1186 TEST_F(WebRtcVideoEngineTestFake, SetBandwidthScreencast) {
1187 EXPECT_TRUE(SetupEngine());
1188 int channel_num = vie_.GetLastChannel();
1191 cricket::VideoCodec codec(kVP8Codec);
1192 std::vector<cricket::VideoCodec> codec_list;
1193 codec_list.push_back(codec);
1194 EXPECT_TRUE(channel_->AddSendStream(
1195 cricket::StreamParams::CreateLegacy(123)));
1196 EXPECT_TRUE(channel_->SetSendCodecs(codec_list));
1197 EXPECT_TRUE(channel_->SetMaxSendBandwidth(111000));
1198 EXPECT_TRUE(channel_->SetSend(true));
1200 SendI420ScreencastFrame(kVP8Codec.width, kVP8Codec.height);
1201 VerifyVP8SendCodec(channel_num, kVP8Codec.width, kVP8Codec.height, 0, 111);
1205 // Test SetSendSsrc.
1206 TEST_F(WebRtcVideoEngineTestFake, SetSendSsrcAndCname) {
1207 EXPECT_TRUE(SetupEngine());
1208 int channel_num = vie_.GetLastChannel();
1210 cricket::StreamParams stream;
1211 stream.ssrcs.push_back(1234);
1212 stream.cname = "cname";
1213 channel_->AddSendStream(stream);
1215 unsigned int ssrc = 0;
1216 EXPECT_EQ(0, vie_.GetLocalSSRC(channel_num, ssrc));
1217 EXPECT_EQ(1234U, ssrc);
1218 EXPECT_EQ(1, vie_.GetNumSsrcs(channel_num));
1220 char rtcp_cname[256];
1221 EXPECT_EQ(0, vie_.GetRTCPCName(channel_num, rtcp_cname));
1222 EXPECT_STREQ("cname", rtcp_cname);
1226 // Test that the local SSRC is the same on sending and receiving channels if the
1227 // receive channel is created before the send channel.
1228 TEST_F(WebRtcVideoEngineTestFake, SetSendSsrcAfterCreatingReceiveChannel) {
1229 EXPECT_TRUE(SetupEngine());
1231 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(1)));
1232 int receive_channel_num = vie_.GetLastChannel();
1233 cricket::StreamParams stream = cricket::StreamParams::CreateLegacy(1234);
1234 EXPECT_TRUE(channel_->AddSendStream(stream));
1235 int send_channel_num = vie_.GetLastChannel();
1236 unsigned int ssrc = 0;
1237 EXPECT_EQ(0, vie_.GetLocalSSRC(send_channel_num, ssrc));
1238 EXPECT_EQ(1234U, ssrc);
1239 EXPECT_EQ(1, vie_.GetNumSsrcs(send_channel_num));
1241 EXPECT_EQ(0, vie_.GetLocalSSRC(receive_channel_num, ssrc));
1242 EXPECT_EQ(1234U, ssrc);
1243 EXPECT_EQ(1, vie_.GetNumSsrcs(receive_channel_num));
1247 // Test SetOptions with denoising flag.
1248 TEST_F(WebRtcVideoEngineTestFake, SetOptionsWithDenoising) {
1249 EXPECT_TRUE(SetupEngine());
1250 EXPECT_EQ(1, vie_.GetNumCapturers());
1251 int channel_num = vie_.GetLastChannel();
1252 int capture_id = vie_.GetCaptureId(channel_num);
1253 // Set send codecs on the channel.
1254 std::vector<cricket::VideoCodec> codecs;
1255 codecs.push_back(kVP8Codec);
1256 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1258 // Set options with OPT_VIDEO_NOISE_REDUCTION flag.
1259 cricket::VideoOptions options;
1260 options.video_noise_reduction.Set(true);
1261 EXPECT_TRUE(channel_->SetOptions(options));
1263 // Verify capture has denoising turned on.
1264 webrtc::VideoCodec send_codec;
1265 memset(&send_codec, 0, sizeof(send_codec)); // avoid uninitialized warning
1266 EXPECT_EQ(0, vie_.GetSendCodec(channel_num, send_codec));
1267 EXPECT_TRUE(send_codec.codecSpecific.VP8.denoisingOn);
1268 EXPECT_FALSE(vie_.GetCaptureDenoising(capture_id));
1270 // Set options back to zero.
1271 options.video_noise_reduction.Set(false);
1272 EXPECT_TRUE(channel_->SetOptions(options));
1274 // Verify capture has denoising turned off.
1275 EXPECT_EQ(0, vie_.GetSendCodec(channel_num, send_codec));
1276 EXPECT_FALSE(send_codec.codecSpecific.VP8.denoisingOn);
1277 EXPECT_FALSE(vie_.GetCaptureDenoising(capture_id));
1280 TEST_F(WebRtcVideoEngineTestFake, MultipleSendStreamsWithOneCapturer) {
1281 EXPECT_TRUE(SetupEngine());
1283 // Start the capturer
1284 cricket::FakeVideoCapturer capturer;
1285 cricket::VideoFormat capture_format_vga = cricket::VideoFormat(640, 480,
1286 cricket::VideoFormat::FpsToInterval(30), cricket::FOURCC_I420);
1287 EXPECT_EQ(cricket::CS_RUNNING, capturer.Start(capture_format_vga));
1289 // Add send streams and connect the capturer
1290 for (unsigned int i = 0; i < sizeof(kSsrcs2)/sizeof(kSsrcs2[0]); ++i) {
1291 EXPECT_TRUE(channel_->AddSendStream(
1292 cricket::StreamParams::CreateLegacy(kSsrcs2[i])));
1293 // Register the capturer to the ssrc.
1294 EXPECT_TRUE(channel_->SetCapturer(kSsrcs2[i], &capturer));
1297 const int channel0 = vie_.GetChannelFromLocalSsrc(kSsrcs2[0]);
1298 ASSERT_NE(-1, channel0);
1299 const int channel1 = vie_.GetChannelFromLocalSsrc(kSsrcs2[1]);
1300 ASSERT_NE(-1, channel1);
1301 ASSERT_NE(channel0, channel1);
1303 // Both channels should have started receiving after created.
1304 EXPECT_TRUE(vie_.GetReceive(channel0));
1305 EXPECT_TRUE(vie_.GetReceive(channel1));
1308 std::vector<cricket::VideoCodec> codecs;
1309 cricket::VideoCodec send_codec(100, "VP8", 640, 480, 30, 0);
1310 codecs.push_back(send_codec);
1311 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1313 EXPECT_TRUE(channel_->SetSend(true));
1314 EXPECT_TRUE(vie_.GetSend(channel0));
1315 EXPECT_TRUE(vie_.GetSend(channel1));
1317 EXPECT_TRUE(capturer.CaptureFrame());
1318 EXPECT_EQ(1, vie_.GetIncomingFrameNum(channel0));
1319 EXPECT_EQ(1, vie_.GetIncomingFrameNum(channel1));
1321 EXPECT_TRUE(channel_->RemoveSendStream(kSsrcs2[0]));
1322 EXPECT_TRUE(capturer.CaptureFrame());
1323 // channel0 is the default channel, so it won't be deleted.
1324 // But it should be disconnected from the capturer.
1325 EXPECT_EQ(1, vie_.GetIncomingFrameNum(channel0));
1326 EXPECT_EQ(2, vie_.GetIncomingFrameNum(channel1));
1328 EXPECT_TRUE(channel_->RemoveSendStream(kSsrcs2[1]));
1329 EXPECT_TRUE(capturer.CaptureFrame());
1330 EXPECT_EQ(1, vie_.GetIncomingFrameNum(channel0));
1331 // channel1 has already been deleted.
1332 EXPECT_EQ(-1, vie_.GetIncomingFrameNum(channel1));
1336 // Disabled since its flaky: b/11288120
1337 TEST_F(WebRtcVideoEngineTestFake, DISABLED_SendReceiveBitratesStats) {
1338 EXPECT_TRUE(SetupEngine());
1339 cricket::VideoOptions options;
1340 options.conference_mode.Set(true);
1341 EXPECT_TRUE(channel_->SetOptions(options));
1342 EXPECT_TRUE(channel_->AddSendStream(
1343 cricket::StreamParams::CreateLegacy(1)));
1344 int send_channel = vie_.GetLastChannel();
1345 cricket::VideoCodec codec(kVP8Codec720p);
1346 std::vector<cricket::VideoCodec> codec_list;
1347 codec_list.push_back(codec);
1348 EXPECT_TRUE(channel_->SetSendCodecs(codec_list));
1350 EXPECT_TRUE(channel_->AddRecvStream(
1351 cricket::StreamParams::CreateLegacy(2)));
1352 int first_receive_channel = vie_.GetLastChannel();
1353 EXPECT_NE(send_channel, first_receive_channel);
1354 EXPECT_TRUE(channel_->AddRecvStream(
1355 cricket::StreamParams::CreateLegacy(3)));
1356 int second_receive_channel = vie_.GetLastChannel();
1357 EXPECT_NE(first_receive_channel, second_receive_channel);
1359 cricket::VideoMediaInfo info;
1360 EXPECT_TRUE(channel_->GetStats(cricket::StatsOptions(), &info));
1361 ASSERT_EQ(1U, info.bw_estimations.size());
1362 ASSERT_EQ(0, info.bw_estimations[0].actual_enc_bitrate);
1363 ASSERT_EQ(0, info.bw_estimations[0].transmit_bitrate);
1364 ASSERT_EQ(0, info.bw_estimations[0].retransmit_bitrate);
1365 ASSERT_EQ(0, info.bw_estimations[0].available_send_bandwidth);
1366 ASSERT_EQ(0, info.bw_estimations[0].available_recv_bandwidth);
1367 ASSERT_EQ(0, info.bw_estimations[0].target_enc_bitrate);
1369 // Start sending and receiving on one of the channels and verify bitrates.
1370 EXPECT_EQ(0, vie_.StartSend(send_channel));
1371 int send_video_bitrate = 800;
1372 int send_fec_bitrate = 100;
1373 int send_nack_bitrate = 20;
1374 int send_total_bitrate = send_video_bitrate + send_fec_bitrate +
1376 int send_bandwidth = 950;
1377 vie_.SetSendBitrates(send_channel, send_video_bitrate, send_fec_bitrate,
1379 vie_.SetSendBandwidthEstimate(send_channel, send_bandwidth);
1381 EXPECT_EQ(0, vie_.StartReceive(first_receive_channel));
1382 int first_channel_receive_bandwidth = 600;
1383 vie_.SetReceiveBandwidthEstimate(first_receive_channel,
1384 first_channel_receive_bandwidth);
1387 EXPECT_TRUE(channel_->GetStats(cricket::StatsOptions(), &info));
1388 ASSERT_EQ(1U, info.bw_estimations.size());
1389 ASSERT_EQ(send_video_bitrate, info.bw_estimations[0].actual_enc_bitrate);
1390 ASSERT_EQ(send_total_bitrate, info.bw_estimations[0].transmit_bitrate);
1391 ASSERT_EQ(send_nack_bitrate, info.bw_estimations[0].retransmit_bitrate);
1392 ASSERT_EQ(send_bandwidth, info.bw_estimations[0].available_send_bandwidth);
1393 ASSERT_EQ(first_channel_receive_bandwidth,
1394 info.bw_estimations[0].available_recv_bandwidth);
1395 ASSERT_EQ(send_video_bitrate, info.bw_estimations[0].target_enc_bitrate);
1397 // Start receiving on the second channel and verify received rate.
1398 EXPECT_EQ(0, vie_.StartReceive(second_receive_channel));
1399 int second_channel_receive_bandwidth = 100;
1400 vie_.SetReceiveBandwidthEstimate(second_receive_channel,
1401 second_channel_receive_bandwidth);
1404 EXPECT_TRUE(channel_->GetStats(cricket::StatsOptions(), &info));
1405 ASSERT_EQ(1U, info.bw_estimations.size());
1406 ASSERT_EQ(send_video_bitrate, info.bw_estimations[0].actual_enc_bitrate);
1407 ASSERT_EQ(send_total_bitrate, info.bw_estimations[0].transmit_bitrate);
1408 ASSERT_EQ(send_nack_bitrate, info.bw_estimations[0].retransmit_bitrate);
1409 ASSERT_EQ(send_bandwidth, info.bw_estimations[0].available_send_bandwidth);
1410 ASSERT_EQ(first_channel_receive_bandwidth + second_channel_receive_bandwidth,
1411 info.bw_estimations[0].available_recv_bandwidth);
1412 ASSERT_EQ(send_video_bitrate, info.bw_estimations[0].target_enc_bitrate);
1415 TEST_F(WebRtcVideoEngineTestFake, TestSetAdaptInputToCpuUsage) {
1416 EXPECT_TRUE(SetupEngine());
1417 cricket::VideoOptions options_in, options_out;
1418 bool cpu_adapt = false;
1419 channel_->SetOptions(options_in);
1420 EXPECT_TRUE(channel_->GetOptions(&options_out));
1421 EXPECT_FALSE(options_out.adapt_input_to_cpu_usage.Get(&cpu_adapt));
1422 // Set adapt input CPU usage option.
1423 options_in.adapt_input_to_cpu_usage.Set(true);
1424 EXPECT_TRUE(channel_->SetOptions(options_in));
1425 EXPECT_TRUE(channel_->GetOptions(&options_out));
1426 EXPECT_TRUE(options_out.adapt_input_to_cpu_usage.Get(&cpu_adapt));
1427 EXPECT_TRUE(cpu_adapt);
1430 TEST_F(WebRtcVideoEngineTestFake, TestSetCpuThreshold) {
1431 EXPECT_TRUE(SetupEngine());
1433 cricket::VideoOptions options_in, options_out;
1434 // Verify that initial values are set.
1435 EXPECT_TRUE(channel_->GetOptions(&options_out));
1436 EXPECT_TRUE(options_out.system_low_adaptation_threshhold.Get(&low));
1437 EXPECT_EQ(low, 0.65f);
1438 EXPECT_TRUE(options_out.system_high_adaptation_threshhold.Get(&high));
1439 EXPECT_EQ(high, 0.85f);
1440 // Set new CPU threshold values.
1441 options_in.system_low_adaptation_threshhold.Set(0.45f);
1442 options_in.system_high_adaptation_threshhold.Set(0.95f);
1443 EXPECT_TRUE(channel_->SetOptions(options_in));
1444 EXPECT_TRUE(channel_->GetOptions(&options_out));
1445 EXPECT_TRUE(options_out.system_low_adaptation_threshhold.Get(&low));
1446 EXPECT_EQ(low, 0.45f);
1447 EXPECT_TRUE(options_out.system_high_adaptation_threshhold.Get(&high));
1448 EXPECT_EQ(high, 0.95f);
1451 TEST_F(WebRtcVideoEngineTestFake, TestSetInvalidCpuThreshold) {
1452 EXPECT_TRUE(SetupEngine());
1454 cricket::VideoOptions options_in, options_out;
1455 // Valid range is [0, 1].
1456 options_in.system_low_adaptation_threshhold.Set(-1.5f);
1457 options_in.system_high_adaptation_threshhold.Set(1.5f);
1458 EXPECT_TRUE(channel_->SetOptions(options_in));
1459 EXPECT_TRUE(channel_->GetOptions(&options_out));
1460 EXPECT_TRUE(options_out.system_low_adaptation_threshhold.Get(&low));
1461 EXPECT_EQ(low, 0.0f);
1462 EXPECT_TRUE(options_out.system_high_adaptation_threshhold.Get(&high));
1463 EXPECT_EQ(high, 1.0f);
1467 TEST_F(WebRtcVideoEngineTestFake, ResetCodecOnScreencast) {
1468 EXPECT_TRUE(SetupEngine());
1469 cricket::VideoOptions options;
1470 options.video_noise_reduction.Set(true);
1471 EXPECT_TRUE(channel_->SetOptions(options));
1474 cricket::VideoCodec codec(kVP8Codec);
1475 std::vector<cricket::VideoCodec> codec_list;
1476 codec_list.push_back(codec);
1477 EXPECT_TRUE(channel_->AddSendStream(
1478 cricket::StreamParams::CreateLegacy(123)));
1479 EXPECT_TRUE(channel_->SetSendCodecs(codec_list));
1480 EXPECT_TRUE(channel_->SetSend(true));
1481 EXPECT_EQ(1, vie_.num_set_send_codecs());
1483 webrtc::VideoCodec gcodec;
1484 memset(&gcodec, 0, sizeof(gcodec));
1485 int channel_num = vie_.GetLastChannel();
1486 EXPECT_EQ(0, vie_.GetSendCodec(channel_num, gcodec));
1487 EXPECT_TRUE(gcodec.codecSpecific.VP8.denoisingOn);
1489 // Send a screencast frame with the same size.
1490 // Verify that denoising is turned off.
1491 SendI420ScreencastFrame(kVP8Codec.width, kVP8Codec.height);
1492 EXPECT_EQ(2, vie_.num_set_send_codecs());
1493 EXPECT_EQ(0, vie_.GetSendCodec(channel_num, gcodec));
1494 EXPECT_FALSE(gcodec.codecSpecific.VP8.denoisingOn);
1498 TEST_F(WebRtcVideoEngineTestFake, DontRegisterDecoderIfFactoryIsNotGiven) {
1499 engine_.SetExternalDecoderFactory(NULL);
1500 EXPECT_TRUE(SetupEngine());
1501 int channel_num = vie_.GetLastChannel();
1503 std::vector<cricket::VideoCodec> codecs;
1504 codecs.push_back(kVP8Codec);
1505 EXPECT_TRUE(channel_->SetRecvCodecs(codecs));
1507 EXPECT_EQ(0, vie_.GetNumExternalDecoderRegistered(channel_num));
1510 TEST_F(WebRtcVideoEngineTestFake, RegisterDecoderIfFactoryIsGiven) {
1511 decoder_factory_.AddSupportedVideoCodecType(webrtc::kVideoCodecVP8);
1512 engine_.SetExternalDecoderFactory(&decoder_factory_);
1513 EXPECT_TRUE(SetupEngine());
1514 int channel_num = vie_.GetLastChannel();
1516 std::vector<cricket::VideoCodec> codecs;
1517 codecs.push_back(kVP8Codec);
1518 EXPECT_TRUE(channel_->SetRecvCodecs(codecs));
1520 EXPECT_TRUE(vie_.ExternalDecoderRegistered(channel_num, 100));
1521 EXPECT_EQ(1, vie_.GetNumExternalDecoderRegistered(channel_num));
1524 TEST_F(WebRtcVideoEngineTestFake, DontRegisterDecoderMultipleTimes) {
1525 decoder_factory_.AddSupportedVideoCodecType(webrtc::kVideoCodecVP8);
1526 engine_.SetExternalDecoderFactory(&decoder_factory_);
1527 EXPECT_TRUE(SetupEngine());
1528 int channel_num = vie_.GetLastChannel();
1530 std::vector<cricket::VideoCodec> codecs;
1531 codecs.push_back(kVP8Codec);
1532 EXPECT_TRUE(channel_->SetRecvCodecs(codecs));
1534 EXPECT_TRUE(vie_.ExternalDecoderRegistered(channel_num, 100));
1535 EXPECT_EQ(1, vie_.GetNumExternalDecoderRegistered(channel_num));
1536 EXPECT_EQ(1, decoder_factory_.GetNumCreatedDecoders());
1538 EXPECT_TRUE(channel_->SetRecvCodecs(codecs));
1539 EXPECT_EQ(1, vie_.GetNumExternalDecoderRegistered(channel_num));
1540 EXPECT_EQ(1, decoder_factory_.GetNumCreatedDecoders());
1543 TEST_F(WebRtcVideoEngineTestFake, DontRegisterDecoderForNonVP8) {
1544 decoder_factory_.AddSupportedVideoCodecType(webrtc::kVideoCodecVP8);
1545 engine_.SetExternalDecoderFactory(&decoder_factory_);
1546 EXPECT_TRUE(SetupEngine());
1547 int channel_num = vie_.GetLastChannel();
1549 std::vector<cricket::VideoCodec> codecs;
1550 codecs.push_back(kRedCodec);
1551 EXPECT_TRUE(channel_->SetRecvCodecs(codecs));
1553 EXPECT_EQ(0, vie_.GetNumExternalDecoderRegistered(channel_num));
1556 TEST_F(WebRtcVideoEngineTestFake, DontRegisterEncoderIfFactoryIsNotGiven) {
1557 engine_.SetExternalEncoderFactory(NULL);
1558 EXPECT_TRUE(SetupEngine());
1559 int channel_num = vie_.GetLastChannel();
1561 std::vector<cricket::VideoCodec> codecs;
1562 codecs.push_back(kVP8Codec);
1563 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1565 EXPECT_EQ(0, vie_.GetNumExternalEncoderRegistered(channel_num));
1568 TEST_F(WebRtcVideoEngineTestFake, RegisterEncoderIfFactoryIsGiven) {
1569 encoder_factory_.AddSupportedVideoCodecType(webrtc::kVideoCodecVP8, "VP8");
1570 engine_.SetExternalEncoderFactory(&encoder_factory_);
1571 EXPECT_TRUE(SetupEngine());
1572 int channel_num = vie_.GetLastChannel();
1574 std::vector<cricket::VideoCodec> codecs;
1575 codecs.push_back(kVP8Codec);
1576 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1578 EXPECT_TRUE(channel_->AddSendStream(
1579 cricket::StreamParams::CreateLegacy(kSsrc)));
1581 EXPECT_TRUE(vie_.ExternalEncoderRegistered(channel_num, 100));
1582 EXPECT_EQ(1, vie_.GetNumExternalEncoderRegistered(channel_num));
1584 // Remove stream previously added to free the external encoder instance.
1585 EXPECT_TRUE(channel_->RemoveSendStream(kSsrc));
1588 TEST_F(WebRtcVideoEngineTestFake, DontRegisterEncoderMultipleTimes) {
1589 encoder_factory_.AddSupportedVideoCodecType(webrtc::kVideoCodecVP8, "VP8");
1590 engine_.SetExternalEncoderFactory(&encoder_factory_);
1591 EXPECT_TRUE(SetupEngine());
1592 int channel_num = vie_.GetLastChannel();
1594 std::vector<cricket::VideoCodec> codecs;
1595 codecs.push_back(kVP8Codec);
1596 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1598 EXPECT_TRUE(channel_->AddSendStream(
1599 cricket::StreamParams::CreateLegacy(kSsrc)));
1601 EXPECT_TRUE(vie_.ExternalEncoderRegistered(channel_num, 100));
1602 EXPECT_EQ(1, vie_.GetNumExternalEncoderRegistered(channel_num));
1603 EXPECT_EQ(1, encoder_factory_.GetNumCreatedEncoders());
1605 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1606 EXPECT_EQ(1, vie_.GetNumExternalEncoderRegistered(channel_num));
1607 EXPECT_EQ(1, encoder_factory_.GetNumCreatedEncoders());
1609 // Remove stream previously added to free the external encoder instance.
1610 EXPECT_TRUE(channel_->RemoveSendStream(kSsrc));
1613 TEST_F(WebRtcVideoEngineTestFake, RegisterEncoderWithMultipleSendStreams) {
1614 encoder_factory_.AddSupportedVideoCodecType(webrtc::kVideoCodecVP8, "VP8");
1615 engine_.SetExternalEncoderFactory(&encoder_factory_);
1616 EXPECT_TRUE(SetupEngine());
1618 std::vector<cricket::VideoCodec> codecs;
1619 codecs.push_back(kVP8Codec);
1620 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1621 EXPECT_EQ(1, vie_.GetTotalNumExternalEncoderRegistered());
1623 // When we add the first stream (1234), it reuses the default send channel,
1624 // so it doesn't increase the registration count of external encoders.
1625 EXPECT_TRUE(channel_->AddSendStream(
1626 cricket::StreamParams::CreateLegacy(1234)));
1627 EXPECT_EQ(1, vie_.GetTotalNumExternalEncoderRegistered());
1629 // When we add the second stream (2345), it creates a new channel and
1630 // increments the registration count.
1631 EXPECT_TRUE(channel_->AddSendStream(
1632 cricket::StreamParams::CreateLegacy(2345)));
1633 EXPECT_EQ(2, vie_.GetTotalNumExternalEncoderRegistered());
1635 // At this moment the total registration count is two, but only one encoder
1636 // is registered per channel.
1637 int channel_num = vie_.GetLastChannel();
1638 EXPECT_EQ(1, vie_.GetNumExternalEncoderRegistered(channel_num));
1640 // Removing send streams decrements the registration count.
1641 EXPECT_TRUE(channel_->RemoveSendStream(1234));
1642 EXPECT_EQ(1, vie_.GetTotalNumExternalEncoderRegistered());
1644 // When we remove the last send stream, it also destroys the last send
1645 // channel and causes the registration count to drop to zero. It is a little
1646 // weird, but not a bug.
1647 EXPECT_TRUE(channel_->RemoveSendStream(2345));
1648 EXPECT_EQ(0, vie_.GetTotalNumExternalEncoderRegistered());
1651 TEST_F(WebRtcVideoEngineTestFake, DontRegisterEncoderForNonVP8) {
1652 encoder_factory_.AddSupportedVideoCodecType(webrtc::kVideoCodecGeneric,
1654 engine_.SetExternalEncoderFactory(&encoder_factory_);
1655 EXPECT_TRUE(SetupEngine());
1656 int channel_num = vie_.GetLastChannel();
1658 // Note: unlike the SetRecvCodecs, we must set a valid video codec for
1659 // channel_->SetSendCodecs() to succeed.
1660 std::vector<cricket::VideoCodec> codecs;
1661 codecs.push_back(kVP8Codec);
1662 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1664 EXPECT_EQ(0, vie_.GetNumExternalEncoderRegistered(channel_num));
1667 // Test that NACK, PLI and REMB are enabled for external codec.
1668 TEST_F(WebRtcVideoEngineTestFake, ExternalCodecFeedbackParams) {
1669 encoder_factory_.AddSupportedVideoCodecType(webrtc::kVideoCodecGeneric,
1671 engine_.SetExternalEncoderFactory(&encoder_factory_);
1672 encoder_factory_.NotifyCodecsAvailable();
1673 EXPECT_TRUE(SetupEngine());
1675 std::vector<cricket::VideoCodec> codecs(engine_.codecs());
1676 // The external codec will appear at last.
1677 size_t pos = codecs.size() - 1;
1678 EXPECT_EQ("GENERIC", codecs[pos].name);
1679 VerifyCodecFeedbackParams(codecs[pos]);
1682 // Test external codec with be added to the end of the supported codec list.
1683 TEST_F(WebRtcVideoEngineTestFake, ExternalCodecAddedToTheEnd) {
1684 EXPECT_TRUE(SetupEngine());
1686 std::vector<cricket::VideoCodec> codecs(engine_.codecs());
1687 EXPECT_EQ("VP8", codecs[0].name);
1689 encoder_factory_.AddSupportedVideoCodecType(webrtc::kVideoCodecGeneric,
1691 engine_.SetExternalEncoderFactory(&encoder_factory_);
1692 encoder_factory_.NotifyCodecsAvailable();
1694 codecs = engine_.codecs();
1695 cricket::VideoCodec internal_codec = codecs[0];
1696 cricket::VideoCodec external_codec = codecs[codecs.size() - 1];
1697 // The external codec will appear at last.
1698 EXPECT_EQ("GENERIC", external_codec.name);
1699 // The internal codec is preferred.
1700 EXPECT_GE(internal_codec.preference, external_codec.preference);
1703 // Test that external codec with be ignored if it has the same name as one of
1704 // the internal codecs.
1705 TEST_F(WebRtcVideoEngineTestFake, ExternalCodecIgnored) {
1706 EXPECT_TRUE(SetupEngine());
1708 std::vector<cricket::VideoCodec> internal_codecs(engine_.codecs());
1709 EXPECT_EQ("VP8", internal_codecs[0].name);
1711 encoder_factory_.AddSupportedVideoCodecType(webrtc::kVideoCodecVP8, "VP8");
1712 engine_.SetExternalEncoderFactory(&encoder_factory_);
1713 encoder_factory_.NotifyCodecsAvailable();
1715 std::vector<cricket::VideoCodec> codecs = engine_.codecs();
1716 EXPECT_EQ("VP8", codecs[0].name);
1717 EXPECT_EQ(internal_codecs[0].height, codecs[0].height);
1718 EXPECT_EQ(internal_codecs[0].width, codecs[0].width);
1719 // Verify the last codec is not the external codec.
1720 EXPECT_NE("VP8", codecs[codecs.size() - 1].name);
1723 TEST_F(WebRtcVideoEngineTestFake, UpdateEncoderCodecsAfterSetFactory) {
1724 engine_.SetExternalEncoderFactory(&encoder_factory_);
1725 EXPECT_TRUE(SetupEngine());
1726 int channel_num = vie_.GetLastChannel();
1728 encoder_factory_.AddSupportedVideoCodecType(webrtc::kVideoCodecVP8, "VP8");
1729 encoder_factory_.NotifyCodecsAvailable();
1730 std::vector<cricket::VideoCodec> codecs;
1731 codecs.push_back(kVP8Codec);
1732 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1734 EXPECT_TRUE(channel_->AddSendStream(
1735 cricket::StreamParams::CreateLegacy(kSsrc)));
1737 EXPECT_TRUE(vie_.ExternalEncoderRegistered(channel_num, 100));
1738 EXPECT_EQ(1, vie_.GetNumExternalEncoderRegistered(channel_num));
1739 EXPECT_EQ(1, encoder_factory_.GetNumCreatedEncoders());
1741 // Remove stream previously added to free the external encoder instance.
1742 EXPECT_TRUE(channel_->RemoveSendStream(kSsrc));
1745 // Tests that OnReadyToSend will be propagated into ViE.
1746 TEST_F(WebRtcVideoEngineTestFake, OnReadyToSend) {
1747 EXPECT_TRUE(SetupEngine());
1748 int channel_num = vie_.GetLastChannel();
1749 EXPECT_TRUE(vie_.GetIsTransmitting(channel_num));
1751 channel_->OnReadyToSend(false);
1752 EXPECT_FALSE(vie_.GetIsTransmitting(channel_num));
1754 channel_->OnReadyToSend(true);
1755 EXPECT_TRUE(vie_.GetIsTransmitting(channel_num));
1759 TEST_F(WebRtcVideoEngineTestFake, CaptureFrameTimestampToNtpTimestamp) {
1760 EXPECT_TRUE(SetupEngine());
1761 int capture_id = vie_.GetCaptureId(vie_.GetLastChannel());
1764 cricket::VideoCodec codec(kVP8Codec);
1765 std::vector<cricket::VideoCodec> codec_list;
1766 codec_list.push_back(codec);
1767 EXPECT_TRUE(channel_->AddSendStream(
1768 cricket::StreamParams::CreateLegacy(123)));
1769 EXPECT_TRUE(channel_->SetSendCodecs(codec_list));
1770 EXPECT_TRUE(channel_->SetSend(true));
1772 int64 timestamp = time(NULL) * talk_base::kNumNanosecsPerSec;
1773 SendI420ScreencastFrameWithTimestamp(
1774 kVP8Codec.width, kVP8Codec.height, timestamp);
1775 EXPECT_EQ(talk_base::UnixTimestampNanosecsToNtpMillisecs(timestamp),
1776 vie_.GetCaptureLastTimestamp(capture_id));
1778 SendI420ScreencastFrameWithTimestamp(kVP8Codec.width, kVP8Codec.height, 0);
1779 EXPECT_EQ(0, vie_.GetCaptureLastTimestamp(capture_id));
1783 /////////////////////////
1784 // Tests with real ViE //
1785 /////////////////////////
1787 // Tests that we can find codecs by name or id.
1788 TEST_F(WebRtcVideoEngineTest, FindCodec) {
1789 // We should not need to init engine in order to get codecs.
1790 const std::vector<cricket::VideoCodec>& c = engine_.codecs();
1791 EXPECT_EQ(4U, c.size());
1793 cricket::VideoCodec vp8(104, "VP8", 320, 200, 30, 0);
1794 EXPECT_TRUE(engine_.FindCodec(vp8));
1796 cricket::VideoCodec vp8_ci(104, "vp8", 320, 200, 30, 0);
1797 EXPECT_TRUE(engine_.FindCodec(vp8));
1799 cricket::VideoCodec vp8_diff_fr_diff_pref(104, "VP8", 320, 200, 50, 50);
1800 EXPECT_TRUE(engine_.FindCodec(vp8_diff_fr_diff_pref));
1802 cricket::VideoCodec vp8_diff_id(95, "VP8", 320, 200, 30, 0);
1803 EXPECT_FALSE(engine_.FindCodec(vp8_diff_id));
1804 vp8_diff_id.id = 97;
1805 EXPECT_TRUE(engine_.FindCodec(vp8_diff_id));
1807 cricket::VideoCodec vp8_diff_res(104, "VP8", 320, 111, 30, 0);
1808 EXPECT_FALSE(engine_.FindCodec(vp8_diff_res));
1810 // PeerConnection doesn't negotiate the resolution at this point.
1811 // Test that FindCodec can handle the case when width/height is 0.
1812 cricket::VideoCodec vp8_zero_res(104, "VP8", 0, 0, 30, 0);
1813 EXPECT_TRUE(engine_.FindCodec(vp8_zero_res));
1815 cricket::VideoCodec red(101, "RED", 0, 0, 30, 0);
1816 EXPECT_TRUE(engine_.FindCodec(red));
1818 cricket::VideoCodec red_ci(101, "red", 0, 0, 30, 0);
1819 EXPECT_TRUE(engine_.FindCodec(red));
1821 cricket::VideoCodec fec(102, "ULPFEC", 0, 0, 30, 0);
1822 EXPECT_TRUE(engine_.FindCodec(fec));
1824 cricket::VideoCodec fec_ci(102, "ulpfec", 0, 0, 30, 0);
1825 EXPECT_TRUE(engine_.FindCodec(fec));
1827 cricket::VideoCodec rtx(96, "rtx", 0, 0, 30, 0);
1828 EXPECT_TRUE(engine_.FindCodec(rtx));
1831 TEST_F(WebRtcVideoEngineTest, RtxCodecHasAptSet) {
1832 std::vector<cricket::VideoCodec>::const_iterator it;
1833 bool apt_checked = false;
1834 for (it = engine_.codecs().begin(); it != engine_.codecs().end(); ++it) {
1835 if (_stricmp(cricket::kRtxCodecName, it->name.c_str()) && it->id != 96) {
1839 EXPECT_TRUE(it->GetParam("apt", &apt));
1840 EXPECT_EQ(100, apt);
1843 EXPECT_TRUE(apt_checked);
1846 TEST_F(WebRtcVideoEngineTest, StartupShutdown) {
1847 EXPECT_TRUE(engine_.Init(talk_base::Thread::Current()));
1848 engine_.Terminate();
1851 TEST_PRE_VIDEOENGINE_INIT(WebRtcVideoEngineTest, ConstrainNewCodec)
1852 TEST_POST_VIDEOENGINE_INIT(WebRtcVideoEngineTest, ConstrainNewCodec)
1854 TEST_PRE_VIDEOENGINE_INIT(WebRtcVideoEngineTest, ConstrainRunningCodec)
1855 TEST_POST_VIDEOENGINE_INIT(WebRtcVideoEngineTest, ConstrainRunningCodec)
1857 // TODO(juberti): Figure out why ViE is munging the COM refcount.
1859 TEST_F(WebRtcVideoEngineTest, DISABLED_CheckCoInitialize) {
1860 Base::CheckCoInitialize();
1864 TEST_F(WebRtcVideoEngineTest, CreateChannel) {
1865 EXPECT_TRUE(engine_.Init(talk_base::Thread::Current()));
1866 cricket::VideoMediaChannel* channel = engine_.CreateChannel(NULL);
1867 EXPECT_TRUE(channel != NULL);
1871 TEST_F(WebRtcVideoMediaChannelTest, SetRecvCodecs) {
1872 std::vector<cricket::VideoCodec> codecs;
1873 codecs.push_back(kVP8Codec);
1874 EXPECT_TRUE(channel_->SetRecvCodecs(codecs));
1876 TEST_F(WebRtcVideoMediaChannelTest, SetRecvCodecsWrongPayloadType) {
1877 std::vector<cricket::VideoCodec> codecs;
1878 codecs.push_back(kVP8Codec);
1880 EXPECT_TRUE(channel_->SetRecvCodecs(codecs));
1882 TEST_F(WebRtcVideoMediaChannelTest, SetRecvCodecsUnsupportedCodec) {
1883 std::vector<cricket::VideoCodec> codecs;
1884 codecs.push_back(kVP8Codec);
1885 codecs.push_back(cricket::VideoCodec(101, "VP1", 640, 400, 30, 0));
1886 EXPECT_FALSE(channel_->SetRecvCodecs(codecs));
1889 TEST_F(WebRtcVideoMediaChannelTest, GetRtpSendTimeExtension) {
1890 // Enable RTP timestamp extension.
1892 std::vector<cricket::RtpHeaderExtension> extensions;
1893 extensions.push_back(cricket::RtpHeaderExtension(
1894 "http://www.webrtc.org/experiments/rtp-hdrext/abs-send-time", id));
1896 // Verify the send extension id.
1897 EXPECT_TRUE(channel_->SetSendRtpHeaderExtensions(extensions));
1898 EXPECT_EQ(id, channel_->GetRtpSendTimeExtnId());
1901 TEST_F(WebRtcVideoMediaChannelTest, SetSend) {
1904 TEST_F(WebRtcVideoMediaChannelTest, SetSendWithoutCodecs) {
1905 Base::SetSendWithoutCodecs();
1907 TEST_F(WebRtcVideoMediaChannelTest, SetSendSetsTransportBufferSizes) {
1908 Base::SetSendSetsTransportBufferSizes();
1911 TEST_F(WebRtcVideoMediaChannelTest, SendAndReceiveVp8Vga) {
1912 SendAndReceive(cricket::VideoCodec(100, "VP8", 640, 400, 30, 0));
1914 TEST_F(WebRtcVideoMediaChannelTest, SendAndReceiveVp8Qvga) {
1915 SendAndReceive(cricket::VideoCodec(100, "VP8", 320, 200, 30, 0));
1917 TEST_F(WebRtcVideoMediaChannelTest, SendAndReceiveH264SvcQqvga) {
1918 SendAndReceive(cricket::VideoCodec(100, "VP8", 160, 100, 30, 0));
1920 TEST_F(WebRtcVideoMediaChannelTest, SendManyResizeOnce) {
1921 SendManyResizeOnce();
1924 TEST_F(WebRtcVideoMediaChannelTest, SendVp8HdAndReceiveAdaptedVp8Vga) {
1925 EXPECT_TRUE(channel_->SetCapturer(kSsrc, NULL));
1926 channel_->UpdateAspectRatio(1280, 720);
1927 video_capturer_.reset(new cricket::FakeVideoCapturer);
1928 const std::vector<cricket::VideoFormat>* formats =
1929 video_capturer_->GetSupportedFormats();
1930 cricket::VideoFormat capture_format_hd = (*formats)[0];
1931 EXPECT_EQ(cricket::CS_RUNNING, video_capturer_->Start(capture_format_hd));
1932 EXPECT_TRUE(channel_->SetCapturer(kSsrc, video_capturer_.get()));
1934 // Capture format HD -> adapt (OnOutputFormatRequest VGA) -> VGA.
1935 cricket::VideoCodec codec(100, "VP8", 1280, 720, 30, 0);
1936 EXPECT_TRUE(SetOneCodec(codec));
1939 EXPECT_TRUE(channel_->SetSendStreamFormat(kSsrc, cricket::VideoFormat(
1940 codec.width, codec.height,
1941 cricket::VideoFormat::FpsToInterval(codec.framerate),
1942 cricket::FOURCC_ANY)));
1943 EXPECT_TRUE(SetSend(true));
1944 EXPECT_TRUE(channel_->SetRender(true));
1945 EXPECT_EQ(0, renderer_.num_rendered_frames());
1946 EXPECT_TRUE(SendFrame());
1947 EXPECT_FRAME_WAIT(1, codec.width, codec.height, kTimeout);
1950 // TODO(juberti): Fix this test to tolerate missing stats.
1951 TEST_F(WebRtcVideoMediaChannelTest, DISABLED_GetStats) {
1955 // TODO(juberti): Fix this test to tolerate missing stats.
1956 TEST_F(WebRtcVideoMediaChannelTest, DISABLED_GetStatsMultipleRecvStreams) {
1957 Base::GetStatsMultipleRecvStreams();
1960 TEST_F(WebRtcVideoMediaChannelTest, GetStatsMultipleSendStreams) {
1961 Base::GetStatsMultipleSendStreams();
1964 TEST_F(WebRtcVideoMediaChannelTest, SetSendBandwidth) {
1965 Base::SetSendBandwidth();
1967 TEST_F(WebRtcVideoMediaChannelTest, SetSendSsrc) {
1968 Base::SetSendSsrc();
1970 TEST_F(WebRtcVideoMediaChannelTest, SetSendSsrcAfterSetCodecs) {
1971 Base::SetSendSsrcAfterSetCodecs();
1974 TEST_F(WebRtcVideoMediaChannelTest, SetRenderer) {
1975 Base::SetRenderer();
1978 TEST_F(WebRtcVideoMediaChannelTest, AddRemoveRecvStreams) {
1979 Base::AddRemoveRecvStreams();
1982 TEST_F(WebRtcVideoMediaChannelTest, AddRemoveRecvStreamAndRender) {
1983 Base::AddRemoveRecvStreamAndRender();
1986 TEST_F(WebRtcVideoMediaChannelTest, AddRemoveRecvStreamsNoConference) {
1987 Base::AddRemoveRecvStreamsNoConference();
1990 TEST_F(WebRtcVideoMediaChannelTest, AddRemoveSendStreams) {
1991 Base::AddRemoveSendStreams();
1994 TEST_F(WebRtcVideoMediaChannelTest, SimulateConference) {
1995 Base::SimulateConference();
1998 TEST_F(WebRtcVideoMediaChannelTest, AddRemoveCapturer) {
1999 Base::AddRemoveCapturer();
2002 TEST_F(WebRtcVideoMediaChannelTest, RemoveCapturerWithoutAdd) {
2003 Base::RemoveCapturerWithoutAdd();
2006 TEST_F(WebRtcVideoMediaChannelTest, AddRemoveCapturerMultipleSources) {
2007 Base::AddRemoveCapturerMultipleSources();
2010 // This test verifies DSCP settings are properly applied on video media channel.
2011 TEST_F(WebRtcVideoMediaChannelTest, TestSetDscpOptions) {
2012 talk_base::scoped_ptr<cricket::FakeNetworkInterface> network_interface(
2013 new cricket::FakeNetworkInterface);
2014 channel_->SetInterface(network_interface.get());
2015 cricket::VideoOptions options;
2016 options.dscp.Set(true);
2017 EXPECT_TRUE(channel_->SetOptions(options));
2018 EXPECT_EQ(talk_base::DSCP_AF41, network_interface->dscp());
2019 // Verify previous value is not modified if dscp option is not set.
2020 cricket::VideoOptions options1;
2021 EXPECT_TRUE(channel_->SetOptions(options1));
2022 EXPECT_EQ(talk_base::DSCP_AF41, network_interface->dscp());
2023 options.dscp.Set(false);
2024 EXPECT_TRUE(channel_->SetOptions(options));
2025 EXPECT_EQ(talk_base::DSCP_DEFAULT, network_interface->dscp());
2026 channel_->SetInterface(NULL);
2030 TEST_F(WebRtcVideoMediaChannelTest, SetOptionsSucceedsWhenSending) {
2031 cricket::VideoOptions options;
2032 options.conference_mode.Set(true);
2033 EXPECT_TRUE(channel_->SetOptions(options));
2035 // Verify SetOptions returns true on a different options.
2036 cricket::VideoOptions options2;
2037 options2.adapt_input_to_cpu_usage.Set(true);
2038 EXPECT_TRUE(channel_->SetOptions(options2));
2040 // Set send codecs on the channel and start sending.
2041 std::vector<cricket::VideoCodec> codecs;
2042 codecs.push_back(kVP8Codec);
2043 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
2044 EXPECT_TRUE(channel_->SetSend(true));
2046 // Verify SetOptions returns true if channel is already sending.
2047 cricket::VideoOptions options3;
2048 options3.conference_mode.Set(true);
2049 EXPECT_TRUE(channel_->SetOptions(options3));
2052 // Tests empty StreamParams is rejected.
2053 TEST_F(WebRtcVideoMediaChannelTest, RejectEmptyStreamParams) {
2054 Base::RejectEmptyStreamParams();
2058 TEST_F(WebRtcVideoMediaChannelTest, AdaptResolution16x10) {
2059 Base::AdaptResolution16x10();
2062 TEST_F(WebRtcVideoMediaChannelTest, AdaptResolution4x3) {
2063 Base::AdaptResolution4x3();
2066 TEST_F(WebRtcVideoMediaChannelTest, MuteStream) {
2070 TEST_F(WebRtcVideoMediaChannelTest, MultipleSendStreams) {
2071 Base::MultipleSendStreams();
2074 // TODO(juberti): Restore this test once we support sending 0 fps.
2075 TEST_F(WebRtcVideoMediaChannelTest, DISABLED_AdaptDropAllFrames) {
2076 Base::AdaptDropAllFrames();
2078 // TODO(juberti): Understand why we get decode errors on this test.
2079 TEST_F(WebRtcVideoMediaChannelTest, DISABLED_AdaptFramerate) {
2080 Base::AdaptFramerate();
2083 TEST_F(WebRtcVideoMediaChannelTest, SetSendStreamFormat0x0) {
2084 Base::SetSendStreamFormat0x0();
2087 // TODO(zhurunz): Fix the flakey test.
2088 TEST_F(WebRtcVideoMediaChannelTest, DISABLED_SetSendStreamFormat) {
2089 Base::SetSendStreamFormat();
2092 TEST_F(WebRtcVideoMediaChannelTest, TwoStreamsSendAndReceive) {
2093 Base::TwoStreamsSendAndReceive(cricket::VideoCodec(100, "VP8", 640, 400, 30,
2097 TEST_F(WebRtcVideoMediaChannelTest, TwoStreamsReUseFirstStream) {
2098 Base::TwoStreamsReUseFirstStream(cricket::VideoCodec(100, "VP8", 640, 400, 30,