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 using cricket::kRtpTimestampOffsetHeaderExtension;
54 using cricket::kRtpAbsoluteSenderTimeHeaderExtension;
56 static const cricket::VideoCodec kVP8Codec720p(100, "VP8", 1280, 720, 30, 0);
57 static const cricket::VideoCodec kVP8Codec360p(100, "VP8", 640, 360, 30, 0);
58 static const cricket::VideoCodec kVP8Codec270p(100, "VP8", 480, 270, 30, 0);
59 static const cricket::VideoCodec kVP8Codec180p(100, "VP8", 320, 180, 30, 0);
61 static const cricket::VideoCodec kVP8Codec(100, "VP8", 640, 400, 30, 0);
62 static const cricket::VideoCodec kRedCodec(101, "red", 0, 0, 0, 0);
63 static const cricket::VideoCodec kUlpFecCodec(102, "ulpfec", 0, 0, 0, 0);
64 static const cricket::VideoCodec* const kVideoCodecs[] = {
70 static const unsigned int kStartBandwidthKbps = 300;
71 static const unsigned int kMinBandwidthKbps = 50;
72 static const unsigned int kMaxBandwidthKbps = 2000;
74 static const unsigned int kNumberOfTemporalLayers = 1;
76 static const uint32 kSsrcs1[] = {1};
77 static const uint32 kSsrcs2[] = {1, 2};
78 static const uint32 kSsrcs3[] = {1, 2, 3};
79 static const uint32 kRtxSsrc1[] = {4};
80 static const uint32 kRtxSsrcs3[] = {4, 5, 6};
83 class FakeViEWrapper : public cricket::ViEWrapper {
85 explicit FakeViEWrapper(cricket::FakeWebRtcVideoEngine* engine)
86 : cricket::ViEWrapper(engine, // base
93 engine) { // external decoder
97 // Test fixture to test WebRtcVideoEngine with a fake webrtc::VideoEngine.
98 // Useful for testing failure paths.
99 class WebRtcVideoEngineTestFake : public testing::Test,
100 public sigslot::has_slots<> {
102 WebRtcVideoEngineTestFake()
103 : vie_(kVideoCodecs, ARRAY_SIZE(kVideoCodecs)),
104 cpu_monitor_(new talk_base::FakeCpuMonitor(
105 talk_base::Thread::Current())),
106 engine_(NULL, // cricket::WebRtcVoiceEngine
107 new FakeViEWrapper(&vie_), cpu_monitor_),
109 voice_channel_(NULL),
110 last_error_(cricket::VideoMediaChannel::ERROR_NONE) {
113 bool result = engine_.Init(talk_base::Thread::Current());
115 channel_ = engine_.CreateChannel(voice_channel_);
116 channel_->SignalMediaError.connect(this,
117 &WebRtcVideoEngineTestFake::OnMediaError);
118 result = (channel_ != NULL);
122 void OnMediaError(uint32 ssrc, cricket::VideoMediaChannel::Error error) {
125 bool SendI420Frame(int width, int height) {
126 if (NULL == channel_) {
129 cricket::WebRtcVideoFrame frame;
130 if (!frame.InitToBlack(width, height, 1, 1, 0, 0)) {
133 cricket::FakeVideoCapturer capturer;
134 channel_->SendFrame(&capturer, &frame);
137 bool SendI420ScreencastFrame(int width, int height) {
138 return SendI420ScreencastFrameWithTimestamp(width, height, 0);
140 bool SendI420ScreencastFrameWithTimestamp(
141 int width, int height, int64 timestamp) {
142 if (NULL == channel_) {
145 cricket::WebRtcVideoFrame frame;
146 if (!frame.InitToBlack(width, height, 1, 1, 0, 0)) {
149 cricket::FakeVideoCapturer capturer;
150 capturer.SetScreencast(true);
151 channel_->SendFrame(&capturer, &frame);
154 void TestSetSendRtpHeaderExtensions(const std::string& ext) {
155 EXPECT_TRUE(SetupEngine());
156 int channel_num = vie_.GetLastChannel();
158 // Verify extensions are off by default.
159 EXPECT_EQ(-1, vie_.GetSendRtpExtensionId(channel_num, ext));
163 std::vector<cricket::RtpHeaderExtension> extensions;
164 extensions.push_back(cricket::RtpHeaderExtension(ext, id));
166 // Verify the send extension id.
167 EXPECT_TRUE(channel_->SetSendRtpHeaderExtensions(extensions));
168 EXPECT_EQ(id, vie_.GetSendRtpExtensionId(channel_num, ext));
169 // Verify call with same set of extensions returns true.
170 EXPECT_TRUE(channel_->SetSendRtpHeaderExtensions(extensions));
171 EXPECT_EQ(id, vie_.GetSendRtpExtensionId(channel_num, ext));
173 // Add a new send stream and verify the extension is set.
174 // The first send stream to occupy the default channel.
176 channel_->AddSendStream(cricket::StreamParams::CreateLegacy(123)));
178 channel_->AddSendStream(cricket::StreamParams::CreateLegacy(234)));
179 int new_send_channel_num = vie_.GetLastChannel();
180 EXPECT_NE(channel_num, new_send_channel_num);
181 EXPECT_EQ(id, vie_.GetSendRtpExtensionId(new_send_channel_num, ext));
183 // Remove the extension id.
184 std::vector<cricket::RtpHeaderExtension> empty_extensions;
185 EXPECT_TRUE(channel_->SetSendRtpHeaderExtensions(empty_extensions));
186 EXPECT_EQ(-1, vie_.GetSendRtpExtensionId(channel_num, ext));
187 EXPECT_EQ(-1, vie_.GetSendRtpExtensionId(new_send_channel_num, ext));
189 void TestSetRecvRtpHeaderExtensions(const std::string& ext) {
190 EXPECT_TRUE(SetupEngine());
191 int channel_num = vie_.GetLastChannel();
193 // Verify extensions are off by default.
194 EXPECT_EQ(-1, vie_.GetReceiveRtpExtensionId(channel_num, ext));
198 std::vector<cricket::RtpHeaderExtension> extensions;
199 extensions.push_back(cricket::RtpHeaderExtension(ext, id));
201 // Verify receive extension id.
202 EXPECT_TRUE(channel_->SetRecvRtpHeaderExtensions(extensions));
203 EXPECT_EQ(id, vie_.GetReceiveRtpExtensionId(channel_num, ext));
204 // Verify call with same set of extensions returns true.
205 EXPECT_TRUE(channel_->SetRecvRtpHeaderExtensions(extensions));
206 EXPECT_EQ(id, vie_.GetReceiveRtpExtensionId(channel_num, ext));
208 // Add a new receive stream and verify the extension is set.
209 // The first send stream to occupy the default channel.
211 channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(345)));
213 channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(456)));
214 int new_recv_channel_num = vie_.GetLastChannel();
215 EXPECT_NE(channel_num, new_recv_channel_num);
216 EXPECT_EQ(id, vie_.GetReceiveRtpExtensionId(new_recv_channel_num, ext));
218 // Remove the extension id.
219 std::vector<cricket::RtpHeaderExtension> empty_extensions;
220 EXPECT_TRUE(channel_->SetRecvRtpHeaderExtensions(empty_extensions));
221 EXPECT_EQ(-1, vie_.GetReceiveRtpExtensionId(channel_num, ext));
222 EXPECT_EQ(-1, vie_.GetReceiveRtpExtensionId(new_recv_channel_num, ext));
224 void VerifyCodecFeedbackParams(const cricket::VideoCodec& codec) {
225 EXPECT_TRUE(codec.HasFeedbackParam(
226 cricket::FeedbackParam(cricket::kRtcpFbParamNack,
227 cricket::kParamValueEmpty)));
228 EXPECT_TRUE(codec.HasFeedbackParam(
229 cricket::FeedbackParam(cricket::kRtcpFbParamNack,
230 cricket::kRtcpFbNackParamPli)));
231 EXPECT_TRUE(codec.HasFeedbackParam(
232 cricket::FeedbackParam(cricket::kRtcpFbParamRemb,
233 cricket::kParamValueEmpty)));
234 EXPECT_TRUE(codec.HasFeedbackParam(
235 cricket::FeedbackParam(cricket::kRtcpFbParamCcm,
236 cricket::kRtcpFbCcmParamFir)));
238 void VerifyVP8SendCodec(int channel_num,
241 unsigned int layers = 0,
242 unsigned int max_bitrate = kMaxBandwidthKbps,
243 unsigned int min_bitrate = kMinBandwidthKbps,
244 unsigned int start_bitrate = kStartBandwidthKbps,
245 unsigned int fps = 30,
246 unsigned int max_quantization = 0
248 webrtc::VideoCodec gcodec;
249 EXPECT_EQ(0, vie_.GetSendCodec(channel_num, gcodec));
251 // Video codec properties.
252 EXPECT_EQ(webrtc::kVideoCodecVP8, gcodec.codecType);
253 EXPECT_STREQ("VP8", gcodec.plName);
254 EXPECT_EQ(100, gcodec.plType);
255 EXPECT_EQ(width, gcodec.width);
256 EXPECT_EQ(height, gcodec.height);
257 EXPECT_EQ(talk_base::_min(start_bitrate, max_bitrate), gcodec.startBitrate);
258 EXPECT_EQ(max_bitrate, gcodec.maxBitrate);
259 EXPECT_EQ(min_bitrate, gcodec.minBitrate);
260 EXPECT_EQ(fps, gcodec.maxFramerate);
262 EXPECT_FALSE(gcodec.codecSpecific.VP8.pictureLossIndicationOn);
263 EXPECT_FALSE(gcodec.codecSpecific.VP8.feedbackModeOn);
264 EXPECT_EQ(webrtc::kComplexityNormal, gcodec.codecSpecific.VP8.complexity);
265 EXPECT_EQ(webrtc::kResilienceOff, gcodec.codecSpecific.VP8.resilience);
266 EXPECT_EQ(max_quantization, gcodec.qpMax);
268 virtual void TearDown() {
274 cricket::FakeWebRtcVideoEngine vie_;
275 cricket::FakeWebRtcVideoDecoderFactory decoder_factory_;
276 cricket::FakeWebRtcVideoEncoderFactory encoder_factory_;
277 talk_base::FakeCpuMonitor* cpu_monitor_;
278 cricket::WebRtcVideoEngine engine_;
279 cricket::WebRtcVideoMediaChannel* channel_;
280 cricket::WebRtcVoiceMediaChannel* voice_channel_;
281 cricket::VideoMediaChannel::Error last_error_;
284 // Test fixtures to test WebRtcVideoEngine with a real webrtc::VideoEngine.
285 class WebRtcVideoEngineTest
286 : public VideoEngineTest<cricket::WebRtcVideoEngine> {
288 typedef VideoEngineTest<cricket::WebRtcVideoEngine> Base;
290 class WebRtcVideoMediaChannelTest
291 : public VideoMediaChannelTest<
292 cricket::WebRtcVideoEngine, cricket::WebRtcVideoMediaChannel> {
294 typedef VideoMediaChannelTest<cricket::WebRtcVideoEngine,
295 cricket::WebRtcVideoMediaChannel> Base;
296 virtual cricket::VideoCodec DefaultCodec() { return kVP8Codec; }
297 virtual void SetUp() {
300 virtual void TearDown() {
305 /////////////////////////
306 // Tests with fake ViE //
307 /////////////////////////
309 // Tests that our stub library "works".
310 TEST_F(WebRtcVideoEngineTestFake, StartupShutdown) {
311 EXPECT_FALSE(vie_.IsInited());
312 EXPECT_TRUE(engine_.Init(talk_base::Thread::Current()));
313 EXPECT_TRUE(vie_.IsInited());
317 // Tests that webrtc logs are logged when they should be.
318 TEST_F(WebRtcVideoEngineTest, WebRtcShouldLog) {
319 const char webrtc_log[] = "WebRtcVideoEngineTest.WebRtcShouldLog";
320 EXPECT_TRUE(engine_.Init(talk_base::Thread::Current()));
321 engine_.SetLogging(talk_base::LS_INFO, "");
323 talk_base::StringStream stream(str);
324 talk_base::LogMessage::AddLogToStream(&stream, talk_base::LS_INFO);
325 EXPECT_EQ(talk_base::LS_INFO, talk_base::LogMessage::GetLogToStream(&stream));
326 webrtc::Trace::Add(webrtc::kTraceStateInfo, webrtc::kTraceUndefined, 0,
328 talk_base::Thread::Current()->ProcessMessages(100);
329 talk_base::LogMessage::RemoveLogToStream(&stream);
330 // Access |str| after LogMessage is done with it to avoid data racing.
331 EXPECT_NE(std::string::npos, str.find(webrtc_log));
334 // Tests that webrtc logs are not logged when they should't be.
335 TEST_F(WebRtcVideoEngineTest, WebRtcShouldNotLog) {
336 const char webrtc_log[] = "WebRtcVideoEngineTest.WebRtcShouldNotLog";
337 EXPECT_TRUE(engine_.Init(talk_base::Thread::Current()));
338 // WebRTC should never be logged lower than LS_INFO.
339 engine_.SetLogging(talk_base::LS_WARNING, "");
341 talk_base::StringStream stream(str);
342 // Make sure that WebRTC is not logged, even at lowest severity
343 talk_base::LogMessage::AddLogToStream(&stream, talk_base::LS_SENSITIVE);
344 EXPECT_EQ(talk_base::LS_SENSITIVE,
345 talk_base::LogMessage::GetLogToStream(&stream));
346 webrtc::Trace::Add(webrtc::kTraceStateInfo, webrtc::kTraceUndefined, 0,
348 talk_base::Thread::Current()->ProcessMessages(10);
349 EXPECT_EQ(std::string::npos, str.find(webrtc_log));
350 talk_base::LogMessage::RemoveLogToStream(&stream);
353 // Tests that we can create and destroy a channel.
354 TEST_F(WebRtcVideoEngineTestFake, CreateChannel) {
355 EXPECT_TRUE(engine_.Init(talk_base::Thread::Current()));
356 channel_ = engine_.CreateChannel(voice_channel_);
357 EXPECT_TRUE(channel_ != NULL);
358 EXPECT_EQ(1, engine_.GetNumOfChannels());
361 EXPECT_EQ(0, engine_.GetNumOfChannels());
364 // Tests that we properly handle failures in CreateChannel.
365 TEST_F(WebRtcVideoEngineTestFake, CreateChannelFail) {
366 vie_.set_fail_create_channel(true);
367 EXPECT_TRUE(engine_.Init(talk_base::Thread::Current()));
368 channel_ = engine_.CreateChannel(voice_channel_);
369 EXPECT_TRUE(channel_ == NULL);
372 // Tests that we properly handle failures in AllocateExternalCaptureDevice.
373 TEST_F(WebRtcVideoEngineTestFake, AllocateExternalCaptureDeviceFail) {
374 vie_.set_fail_alloc_capturer(true);
375 EXPECT_TRUE(engine_.Init(talk_base::Thread::Current()));
376 channel_ = engine_.CreateChannel(voice_channel_);
377 EXPECT_TRUE(channel_ == NULL);
380 // Test that we apply our default codecs properly.
381 TEST_F(WebRtcVideoEngineTestFake, SetSendCodecs) {
382 EXPECT_TRUE(SetupEngine());
383 int channel_num = vie_.GetLastChannel();
384 std::vector<cricket::VideoCodec> codecs(engine_.codecs());
385 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
386 VerifyVP8SendCodec(channel_num, kVP8Codec.width, kVP8Codec.height);
387 EXPECT_TRUE(vie_.GetHybridNackFecStatus(channel_num));
388 EXPECT_FALSE(vie_.GetNackStatus(channel_num));
389 EXPECT_EQ(1, vie_.GetNumSetSendCodecs());
390 // TODO(juberti): Check RTCP, PLI, TMMBR.
393 // Test that ViE Channel doesn't call SetSendCodec again if same codec is tried
395 TEST_F(WebRtcVideoEngineTestFake, DontResetSetSendCodec) {
396 EXPECT_TRUE(SetupEngine());
397 int channel_num = vie_.GetLastChannel();
398 std::vector<cricket::VideoCodec> codecs(engine_.codecs());
399 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
400 VerifyVP8SendCodec(channel_num, kVP8Codec.width, kVP8Codec.height);
401 EXPECT_TRUE(vie_.GetHybridNackFecStatus(channel_num));
402 EXPECT_FALSE(vie_.GetNackStatus(channel_num));
403 EXPECT_EQ(1, vie_.GetNumSetSendCodecs());
404 // Try setting same code again.
405 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
406 // Since it's exact same codec which is already set, media channel shouldn't
407 // send the codec to ViE.
408 EXPECT_EQ(1, vie_.GetNumSetSendCodecs());
411 TEST_F(WebRtcVideoEngineTestFake, SetSendCodecsWithMinMaxBitrate) {
412 EXPECT_TRUE(SetupEngine());
413 int channel_num = vie_.GetLastChannel();
414 std::vector<cricket::VideoCodec> codecs(engine_.codecs());
415 codecs[0].params[cricket::kCodecParamMinBitrate] = "10";
416 codecs[0].params[cricket::kCodecParamMaxBitrate] = "20";
417 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
420 channel_num, kVP8Codec.width, kVP8Codec.height, 0, 20, 10, 20);
422 cricket::VideoCodec codec;
423 EXPECT_TRUE(channel_->GetSendCodec(&codec));
424 EXPECT_EQ("10", codec.params[cricket::kCodecParamMinBitrate]);
425 EXPECT_EQ("20", codec.params[cricket::kCodecParamMaxBitrate]);
428 TEST_F(WebRtcVideoEngineTestFake, SetSendCodecsWithStartBitrate) {
429 EXPECT_TRUE(SetupEngine());
430 int channel_num = vie_.GetLastChannel();
431 std::vector<cricket::VideoCodec> codecs(engine_.codecs());
432 codecs[0].params[cricket::kCodecParamStartBitrate] = "450";
433 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
436 channel_num, kVP8Codec.width, kVP8Codec.height, 0, 2000, 50, 450);
438 cricket::VideoCodec codec;
439 EXPECT_TRUE(channel_->GetSendCodec(&codec));
440 EXPECT_EQ("450", codec.params[cricket::kCodecParamStartBitrate]);
443 TEST_F(WebRtcVideoEngineTestFake, SetSendCodecsWithMinMaxStartBitrate) {
444 EXPECT_TRUE(SetupEngine());
445 int channel_num = vie_.GetLastChannel();
446 std::vector<cricket::VideoCodec> codecs(engine_.codecs());
447 codecs[0].params[cricket::kCodecParamMinBitrate] = "10";
448 codecs[0].params[cricket::kCodecParamMaxBitrate] = "20";
449 codecs[0].params[cricket::kCodecParamStartBitrate] = "14";
450 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
453 channel_num, kVP8Codec.width, kVP8Codec.height, 0, 20, 10, 14);
455 cricket::VideoCodec codec;
456 EXPECT_TRUE(channel_->GetSendCodec(&codec));
457 EXPECT_EQ("10", codec.params[cricket::kCodecParamMinBitrate]);
458 EXPECT_EQ("20", codec.params[cricket::kCodecParamMaxBitrate]);
459 EXPECT_EQ("14", codec.params[cricket::kCodecParamStartBitrate]);
462 TEST_F(WebRtcVideoEngineTestFake, SetSendCodecsWithMinMaxBitrateInvalid) {
463 EXPECT_TRUE(SetupEngine());
464 std::vector<cricket::VideoCodec> codecs(engine_.codecs());
465 codecs[0].params[cricket::kCodecParamMinBitrate] = "30";
466 codecs[0].params[cricket::kCodecParamMaxBitrate] = "20";
467 EXPECT_FALSE(channel_->SetSendCodecs(codecs));
470 TEST_F(WebRtcVideoEngineTestFake, SetSendCodecsWithLargeMinMaxBitrate) {
471 EXPECT_TRUE(SetupEngine());
472 int channel_num = vie_.GetLastChannel();
473 std::vector<cricket::VideoCodec> codecs(engine_.codecs());
474 codecs[0].params[cricket::kCodecParamMinBitrate] = "1000";
475 codecs[0].params[cricket::kCodecParamMaxBitrate] = "2000";
476 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
479 channel_num, kVP8Codec.width, kVP8Codec.height, 0, 2000, 1000,
483 TEST_F(WebRtcVideoEngineTestFake, SetSendCodecsWithMaxQuantization) {
484 EXPECT_TRUE(SetupEngine());
485 int channel_num = vie_.GetLastChannel();
486 std::vector<cricket::VideoCodec> codecs(engine_.codecs());
487 codecs[0].params[cricket::kCodecParamMaxQuantization] = "21";
488 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
491 channel_num, kVP8Codec.width, kVP8Codec.height, 0, 2000, 50, 300,
494 cricket::VideoCodec codec;
495 EXPECT_TRUE(channel_->GetSendCodec(&codec));
496 EXPECT_EQ("21", codec.params[cricket::kCodecParamMaxQuantization]);
499 TEST_F(WebRtcVideoEngineTestFake, SetOptionsWithMaxBitrate) {
500 EXPECT_TRUE(SetupEngine());
501 int channel_num = vie_.GetLastChannel();
502 std::vector<cricket::VideoCodec> codecs(engine_.codecs());
503 codecs[0].params[cricket::kCodecParamMinBitrate] = "10";
504 codecs[0].params[cricket::kCodecParamMaxBitrate] = "20";
505 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
508 channel_num, kVP8Codec.width, kVP8Codec.height, 0, 20, 10, 20);
510 // Verify that max bitrate doesn't change after SetOptions().
511 cricket::VideoOptions options;
512 options.video_noise_reduction.Set(true);
513 EXPECT_TRUE(channel_->SetOptions(options));
515 channel_num, kVP8Codec.width, kVP8Codec.height, 0, 20, 10, 20);
517 options.video_noise_reduction.Set(false);
518 options.conference_mode.Set(false);
519 EXPECT_TRUE(channel_->SetOptions(options));
521 channel_num, kVP8Codec.width, kVP8Codec.height, 0, 20, 10, 20);
524 TEST_F(WebRtcVideoEngineTestFake, SetOptionsWithLoweredBitrate) {
525 EXPECT_TRUE(SetupEngine());
526 int channel_num = vie_.GetLastChannel();
527 std::vector<cricket::VideoCodec> codecs(engine_.codecs());
528 codecs[0].params[cricket::kCodecParamMinBitrate] = "50";
529 codecs[0].params[cricket::kCodecParamMaxBitrate] = "100";
530 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
533 channel_num, kVP8Codec.width, kVP8Codec.height, 0, 100, 50, 100);
535 // Verify that min bitrate changes after SetOptions().
536 cricket::VideoOptions options;
537 options.lower_min_bitrate.Set(true);
538 EXPECT_TRUE(channel_->SetOptions(options));
540 channel_num, kVP8Codec.width, kVP8Codec.height, 0, 100, 30, 100);
543 TEST_F(WebRtcVideoEngineTestFake, MaxBitrateResetWithConferenceMode) {
544 EXPECT_TRUE(SetupEngine());
545 int channel_num = vie_.GetLastChannel();
546 std::vector<cricket::VideoCodec> codecs(engine_.codecs());
547 codecs[0].params[cricket::kCodecParamMinBitrate] = "10";
548 codecs[0].params[cricket::kCodecParamMaxBitrate] = "20";
549 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
552 channel_num, kVP8Codec.width, kVP8Codec.height, 0, 20, 10, 20);
554 cricket::VideoOptions options;
555 options.conference_mode.Set(true);
556 EXPECT_TRUE(channel_->SetOptions(options));
557 options.conference_mode.Set(false);
558 EXPECT_TRUE(channel_->SetOptions(options));
560 channel_num, kVP8Codec.width, kVP8Codec.height, 0,
561 kMaxBandwidthKbps, 10, kStartBandwidthKbps);
564 // Verify the current send bitrate is used as start bitrate when reconfiguring
566 TEST_F(WebRtcVideoEngineTestFake, StartSendBitrate) {
567 EXPECT_TRUE(SetupEngine());
568 EXPECT_TRUE(channel_->AddSendStream(
569 cricket::StreamParams::CreateLegacy(1)));
570 int send_channel = vie_.GetLastChannel();
571 cricket::VideoCodec codec(kVP8Codec);
572 std::vector<cricket::VideoCodec> codec_list;
573 codec_list.push_back(codec);
574 EXPECT_TRUE(channel_->SetSendCodecs(codec_list));
575 const unsigned int kVideoMaxSendBitrateKbps = 2000;
576 const unsigned int kVideoMinSendBitrateKbps = 50;
577 const unsigned int kVideoDefaultStartSendBitrateKbps = 300;
578 VerifyVP8SendCodec(send_channel, kVP8Codec.width, kVP8Codec.height, 0,
579 kVideoMaxSendBitrateKbps, kVideoMinSendBitrateKbps,
580 kVideoDefaultStartSendBitrateKbps);
581 EXPECT_EQ(0, vie_.StartSend(send_channel));
583 // Increase the send bitrate and verify it is used as start bitrate.
584 const unsigned int kVideoSendBitrateBps = 768000;
585 vie_.SetSendBitrates(send_channel, kVideoSendBitrateBps, 0, 0);
586 EXPECT_TRUE(channel_->SetSendCodecs(codec_list));
587 VerifyVP8SendCodec(send_channel, kVP8Codec.width, kVP8Codec.height, 0,
588 kVideoMaxSendBitrateKbps, kVideoMinSendBitrateKbps,
589 kVideoSendBitrateBps / 1000);
591 // Never set a start bitrate higher than the max bitrate.
592 vie_.SetSendBitrates(send_channel, kVideoMaxSendBitrateKbps + 500, 0, 0);
593 EXPECT_TRUE(channel_->SetSendCodecs(codec_list));
594 VerifyVP8SendCodec(send_channel, kVP8Codec.width, kVP8Codec.height, 0,
595 kVideoMaxSendBitrateKbps, kVideoMinSendBitrateKbps,
596 kVideoDefaultStartSendBitrateKbps);
598 // Use the default start bitrate if the send bitrate is lower.
599 vie_.SetSendBitrates(send_channel, kVideoDefaultStartSendBitrateKbps - 50, 0,
601 EXPECT_TRUE(channel_->SetSendCodecs(codec_list));
602 VerifyVP8SendCodec(send_channel, kVP8Codec.width, kVP8Codec.height, 0,
603 kVideoMaxSendBitrateKbps, kVideoMinSendBitrateKbps,
604 kVideoDefaultStartSendBitrateKbps);
608 // Test that we constrain send codecs properly.
609 TEST_F(WebRtcVideoEngineTestFake, ConstrainSendCodecs) {
610 EXPECT_TRUE(SetupEngine());
611 int channel_num = vie_.GetLastChannel();
613 // Set max settings of 640x400x30.
614 EXPECT_TRUE(engine_.SetDefaultEncoderConfig(
615 cricket::VideoEncoderConfig(kVP8Codec)));
617 // Send codec format bigger than max setting.
618 cricket::VideoCodec codec(kVP8Codec);
621 codec.framerate = 60;
622 std::vector<cricket::VideoCodec> codec_list;
623 codec_list.push_back(codec);
625 // Set send codec and verify codec has been constrained.
626 EXPECT_TRUE(channel_->SetSendCodecs(codec_list));
627 VerifyVP8SendCodec(channel_num, kVP8Codec.width, kVP8Codec.height);
630 // Test that SetSendCodecs rejects bad format.
631 TEST_F(WebRtcVideoEngineTestFake, SetSendCodecsRejectBadFormat) {
632 EXPECT_TRUE(SetupEngine());
633 int channel_num = vie_.GetLastChannel();
636 cricket::VideoCodec codec(kVP8Codec);
638 std::vector<cricket::VideoCodec> codec_list;
639 codec_list.push_back(codec);
641 // Verify SetSendCodecs failed and send codec is not changed on engine.
642 EXPECT_FALSE(channel_->SetSendCodecs(codec_list));
643 webrtc::VideoCodec gcodec;
644 // Set plType to something other than the value to test against ensuring
645 // that failure will happen if it is not changed.
647 EXPECT_EQ(0, vie_.GetSendCodec(channel_num, gcodec));
648 EXPECT_EQ(0, gcodec.plType);
651 codec_list[0].width = 640;
652 codec_list[0].height = 0;
654 // Verify SetSendCodecs failed and send codec is not changed on engine.
655 EXPECT_FALSE(channel_->SetSendCodecs(codec_list));
656 // Set plType to something other than the value to test against ensuring
657 // that failure will happen if it is not changed.
659 EXPECT_EQ(0, vie_.GetSendCodec(channel_num, gcodec));
660 EXPECT_EQ(0, gcodec.plType);
663 // Test that SetSendCodecs rejects bad codec.
664 TEST_F(WebRtcVideoEngineTestFake, SetSendCodecsRejectBadCodec) {
665 EXPECT_TRUE(SetupEngine());
666 int channel_num = vie_.GetLastChannel();
668 // Set bad codec name.
669 cricket::VideoCodec codec(kVP8Codec);
671 std::vector<cricket::VideoCodec> codec_list;
672 codec_list.push_back(codec);
674 // Verify SetSendCodecs failed and send codec is not changed on engine.
675 EXPECT_FALSE(channel_->SetSendCodecs(codec_list));
676 webrtc::VideoCodec gcodec;
677 // Set plType to something other than the value to test against ensuring
678 // that failure will happen if it is not changed.
680 EXPECT_EQ(0, vie_.GetSendCodec(channel_num, gcodec));
681 EXPECT_EQ(0, gcodec.plType);
684 // Test that vie send codec is reset on new video frame size.
685 TEST_F(WebRtcVideoEngineTestFake, ResetVieSendCodecOnNewFrameSize) {
686 EXPECT_TRUE(SetupEngine());
687 int channel_num = vie_.GetLastChannel();
690 std::vector<cricket::VideoCodec> codec_list;
691 codec_list.push_back(kVP8Codec);
692 EXPECT_TRUE(channel_->SetSendCodecs(codec_list));
693 EXPECT_TRUE(channel_->AddSendStream(
694 cricket::StreamParams::CreateLegacy(123)));
695 EXPECT_TRUE(channel_->SetSend(true));
697 // Capture a smaller frame and verify vie send codec has been reset to
699 SendI420Frame(kVP8Codec.width / 2, kVP8Codec.height / 2);
700 VerifyVP8SendCodec(channel_num, kVP8Codec.width / 2, kVP8Codec.height / 2);
702 // Capture a frame bigger than send_codec_ and verify vie send codec has been
703 // reset (and clipped) to send_codec_.
704 SendI420Frame(kVP8Codec.width * 2, kVP8Codec.height * 2);
705 VerifyVP8SendCodec(channel_num, kVP8Codec.width, kVP8Codec.height);
708 // Test that we set our inbound codecs properly.
709 TEST_F(WebRtcVideoEngineTestFake, SetRecvCodecs) {
710 EXPECT_TRUE(SetupEngine());
711 int channel_num = vie_.GetLastChannel();
713 std::vector<cricket::VideoCodec> codecs;
714 codecs.push_back(kVP8Codec);
715 EXPECT_TRUE(channel_->SetRecvCodecs(codecs));
717 webrtc::VideoCodec wcodec;
718 EXPECT_TRUE(engine_.ConvertFromCricketVideoCodec(kVP8Codec, &wcodec));
719 EXPECT_TRUE(vie_.ReceiveCodecRegistered(channel_num, wcodec));
722 // Test that we set our inbound RTX codecs properly.
723 TEST_F(WebRtcVideoEngineTestFake, SetRecvCodecsWithRtx) {
724 EXPECT_TRUE(SetupEngine());
725 int channel_num = vie_.GetLastChannel();
727 std::vector<cricket::VideoCodec> codecs;
728 cricket::VideoCodec rtx_codec(96, "rtx", 0, 0, 0, 0);
729 codecs.push_back(rtx_codec);
730 // Should fail since there's no associated payload type set.
731 EXPECT_FALSE(channel_->SetRecvCodecs(codecs));
733 codecs[0].SetParam("apt", 97);
734 // Should still fail since the we don't support RTX on this APT.
735 EXPECT_FALSE(channel_->SetRecvCodecs(codecs));
737 codecs[0].SetParam("apt", kVP8Codec.id);
738 // Should still fail since the associated payload type is unknown.
739 EXPECT_FALSE(channel_->SetRecvCodecs(codecs));
741 codecs.push_back(kVP8Codec);
742 EXPECT_TRUE(channel_->SetRecvCodecs(codecs));
744 webrtc::VideoCodec wcodec;
745 // Should not have been registered as a WebRTC codec.
746 EXPECT_TRUE(engine_.ConvertFromCricketVideoCodec(rtx_codec, &wcodec));
747 EXPECT_STREQ("rtx", wcodec.plName);
748 EXPECT_FALSE(vie_.ReceiveCodecRegistered(channel_num, wcodec));
750 // The RTX payload type should have been set.
751 EXPECT_EQ(rtx_codec.id, vie_.GetRtxRecvPayloadType(channel_num));
754 // Test that RTX packets are routed to the correct video channel.
755 TEST_F(WebRtcVideoEngineTestFake, TestReceiveRtx) {
756 EXPECT_TRUE(SetupEngine());
758 // Setup three channels with associated RTX streams.
759 int channel_num[ARRAY_SIZE(kSsrcs3)];
760 for (size_t i = 0; i < ARRAY_SIZE(kSsrcs3); ++i) {
761 cricket::StreamParams params =
762 cricket::StreamParams::CreateLegacy(kSsrcs3[i]);
763 params.AddFidSsrc(kSsrcs3[i], kRtxSsrcs3[i]);
764 EXPECT_TRUE(channel_->AddRecvStream(params));
765 channel_num[i] = vie_.GetLastChannel();
769 std::vector<cricket::VideoCodec> codec_list;
770 codec_list.push_back(kVP8Codec720p);
771 cricket::VideoCodec rtx_codec(96, "rtx", 0, 0, 0, 0);
772 rtx_codec.SetParam("apt", kVP8Codec.id);
773 codec_list.push_back(rtx_codec);
774 EXPECT_TRUE(channel_->SetRecvCodecs(codec_list));
776 // Construct a fake RTX packet and verify that it is passed to the
777 // right WebRTC channel.
778 const size_t kDataLength = 12;
779 uint8_t data[kDataLength];
780 memset(data, 0, sizeof(data));
782 data[1] = rtx_codec.id;
783 talk_base::SetBE32(&data[8], kRtxSsrcs3[1]);
784 talk_base::Buffer packet(data, kDataLength);
785 talk_base::PacketTime packet_time;
786 channel_->OnPacketReceived(&packet, packet_time);
787 EXPECT_NE(rtx_codec.id, vie_.GetLastRecvdPayloadType(channel_num[0]));
788 EXPECT_EQ(rtx_codec.id, vie_.GetLastRecvdPayloadType(channel_num[1]));
789 EXPECT_NE(rtx_codec.id, vie_.GetLastRecvdPayloadType(channel_num[2]));
792 // Test that channel connects and disconnects external capturer correctly.
793 TEST_F(WebRtcVideoEngineTestFake, HasExternalCapturer) {
794 EXPECT_TRUE(SetupEngine());
795 int channel_num = vie_.GetLastChannel();
797 EXPECT_EQ(1, vie_.GetNumCapturers());
798 int capture_id = vie_.GetCaptureId(channel_num);
799 EXPECT_EQ(channel_num, vie_.GetCaptureChannelId(capture_id));
801 // Delete the channel should disconnect the capturer.
804 EXPECT_EQ(0, vie_.GetNumCapturers());
807 // Test that channel adds and removes renderer correctly.
808 TEST_F(WebRtcVideoEngineTestFake, HasRenderer) {
809 EXPECT_TRUE(SetupEngine());
810 int channel_num = vie_.GetLastChannel();
812 EXPECT_TRUE(vie_.GetHasRenderer(channel_num));
813 EXPECT_FALSE(vie_.GetRenderStarted(channel_num));
816 // Test that rtcp is enabled on the channel.
817 TEST_F(WebRtcVideoEngineTestFake, RtcpEnabled) {
818 EXPECT_TRUE(SetupEngine());
819 int channel_num = vie_.GetLastChannel();
820 EXPECT_EQ(webrtc::kRtcpCompound_RFC4585, vie_.GetRtcpStatus(channel_num));
823 // Test that key frame request method is set on the channel.
824 TEST_F(WebRtcVideoEngineTestFake, KeyFrameRequestEnabled) {
825 EXPECT_TRUE(SetupEngine());
826 int channel_num = vie_.GetLastChannel();
827 EXPECT_EQ(webrtc::kViEKeyFrameRequestPliRtcp,
828 vie_.GetKeyFrameRequestMethod(channel_num));
831 // Test that remb receive and send is enabled for the default channel in a 1:1
833 TEST_F(WebRtcVideoEngineTestFake, RembEnabled) {
834 EXPECT_TRUE(SetupEngine());
835 int channel_num = vie_.GetLastChannel();
836 EXPECT_TRUE(channel_->AddSendStream(
837 cricket::StreamParams::CreateLegacy(1)));
838 EXPECT_TRUE(channel_->SetSendCodecs(engine_.codecs()));
839 EXPECT_TRUE(vie_.GetRembStatusBwPartition(channel_num));
840 EXPECT_TRUE(channel_->SetSend(true));
841 EXPECT_TRUE(vie_.GetRembStatusBwPartition(channel_num));
842 EXPECT_TRUE(vie_.GetRembStatusContribute(channel_num));
845 // When in conference mode, test that remb is enabled on a receive channel but
846 // not for the default channel and that it uses the default channel for sending
848 TEST_F(WebRtcVideoEngineTestFake, RembEnabledOnReceiveChannels) {
849 EXPECT_TRUE(SetupEngine());
850 int default_channel = vie_.GetLastChannel();
851 cricket::VideoOptions options;
852 options.conference_mode.Set(true);
853 EXPECT_TRUE(channel_->SetOptions(options));
854 EXPECT_TRUE(channel_->AddSendStream(
855 cricket::StreamParams::CreateLegacy(1)));
856 EXPECT_TRUE(channel_->SetSendCodecs(engine_.codecs()));
857 EXPECT_TRUE(vie_.GetRembStatusBwPartition(default_channel));
858 EXPECT_TRUE(vie_.GetRembStatusContribute(default_channel));
859 EXPECT_TRUE(channel_->SetSend(true));
860 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(1)));
861 int new_channel_num = vie_.GetLastChannel();
862 EXPECT_NE(default_channel, new_channel_num);
864 EXPECT_TRUE(vie_.GetRembStatusBwPartition(default_channel));
865 EXPECT_TRUE(vie_.GetRembStatusContribute(default_channel));
866 EXPECT_FALSE(vie_.GetRembStatusBwPartition(new_channel_num));
867 EXPECT_TRUE(vie_.GetRembStatusContribute(new_channel_num));
870 TEST_F(WebRtcVideoEngineTestFake, RecvStreamWithRtx) {
871 EXPECT_TRUE(SetupEngine());
872 int default_channel = vie_.GetLastChannel();
873 cricket::VideoOptions options;
874 options.conference_mode.Set(true);
875 EXPECT_TRUE(channel_->SetOptions(options));
876 EXPECT_TRUE(channel_->AddSendStream(
877 cricket::CreateSimWithRtxStreamParams("cname",
878 MAKE_VECTOR(kSsrcs3),
879 MAKE_VECTOR(kRtxSsrcs3))));
880 EXPECT_TRUE(channel_->SetSendCodecs(engine_.codecs()));
881 EXPECT_TRUE(channel_->SetSend(true));
882 EXPECT_TRUE(channel_->AddRecvStream(
883 cricket::CreateSimWithRtxStreamParams("cname",
884 MAKE_VECTOR(kSsrcs1),
885 MAKE_VECTOR(kRtxSsrc1))));
886 int new_channel_num = vie_.GetLastChannel();
887 EXPECT_NE(default_channel, new_channel_num);
888 EXPECT_EQ(4, vie_.GetRemoteRtxSsrc(new_channel_num));
891 TEST_F(WebRtcVideoEngineTestFake, RecvStreamNoRtx) {
892 EXPECT_TRUE(SetupEngine());
893 int default_channel = vie_.GetLastChannel();
894 cricket::VideoOptions options;
895 options.conference_mode.Set(true);
896 EXPECT_TRUE(channel_->SetOptions(options));
897 EXPECT_TRUE(channel_->AddSendStream(
898 cricket::CreateSimWithRtxStreamParams("cname",
899 MAKE_VECTOR(kSsrcs3),
900 MAKE_VECTOR(kRtxSsrcs3))));
901 EXPECT_TRUE(channel_->SetSendCodecs(engine_.codecs()));
902 EXPECT_TRUE(channel_->SetSend(true));
903 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(1)));
904 int new_channel_num = vie_.GetLastChannel();
905 EXPECT_NE(default_channel, new_channel_num);
906 EXPECT_EQ(-1, vie_.GetRemoteRtxSsrc(new_channel_num));
909 // Test support for RTP timestamp offset header extension.
910 TEST_F(WebRtcVideoEngineTestFake, SendRtpTimestampOffsetHeaderExtensions) {
911 TestSetSendRtpHeaderExtensions(kRtpTimestampOffsetHeaderExtension);
913 TEST_F(WebRtcVideoEngineTestFake, RecvRtpTimestampOffsetHeaderExtensions) {
914 TestSetRecvRtpHeaderExtensions(kRtpTimestampOffsetHeaderExtension);
917 // Test support for absolute send time header extension.
918 TEST_F(WebRtcVideoEngineTestFake, SendAbsoluteSendTimeHeaderExtensions) {
919 TestSetSendRtpHeaderExtensions(kRtpAbsoluteSenderTimeHeaderExtension);
921 TEST_F(WebRtcVideoEngineTestFake, RecvAbsoluteSendTimeHeaderExtensions) {
922 TestSetRecvRtpHeaderExtensions(kRtpAbsoluteSenderTimeHeaderExtension);
925 TEST_F(WebRtcVideoEngineTestFake, LeakyBucketTest) {
926 EXPECT_TRUE(SetupEngine());
928 // Verify this is off by default.
929 EXPECT_TRUE(channel_->AddSendStream(cricket::StreamParams::CreateLegacy(1)));
930 int first_send_channel = vie_.GetLastChannel();
931 EXPECT_FALSE(vie_.GetTransmissionSmoothingStatus(first_send_channel));
933 // Enable the experiment and verify.
934 cricket::VideoOptions options;
935 options.conference_mode.Set(true);
936 options.video_leaky_bucket.Set(true);
937 EXPECT_TRUE(channel_->SetOptions(options));
938 EXPECT_TRUE(vie_.GetTransmissionSmoothingStatus(first_send_channel));
940 // Add a receive channel and verify leaky bucket isn't enabled.
941 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(2)));
942 int recv_channel_num = vie_.GetLastChannel();
943 EXPECT_NE(first_send_channel, recv_channel_num);
944 EXPECT_FALSE(vie_.GetTransmissionSmoothingStatus(recv_channel_num));
946 // Add a new send stream and verify leaky bucket is enabled from start.
947 EXPECT_TRUE(channel_->AddSendStream(cricket::StreamParams::CreateLegacy(3)));
948 int second_send_channel = vie_.GetLastChannel();
949 EXPECT_NE(first_send_channel, second_send_channel);
950 EXPECT_TRUE(vie_.GetTransmissionSmoothingStatus(second_send_channel));
953 // Verify that SuspendBelowMinBitrate is enabled if it is set in the options.
954 TEST_F(WebRtcVideoEngineTestFake, SuspendBelowMinBitrateTest) {
955 EXPECT_TRUE(SetupEngine());
957 // Verify this is off by default.
958 EXPECT_TRUE(channel_->AddSendStream(cricket::StreamParams::CreateLegacy(1)));
959 int first_send_channel = vie_.GetLastChannel();
960 EXPECT_FALSE(vie_.GetSuspendBelowMinBitrateStatus(first_send_channel));
962 // Enable the experiment and verify.
963 cricket::VideoOptions options;
964 options.suspend_below_min_bitrate.Set(true);
965 EXPECT_TRUE(channel_->SetOptions(options));
966 EXPECT_TRUE(vie_.GetSuspendBelowMinBitrateStatus(first_send_channel));
968 // Add a new send stream and verify suspend_below_min_bitrate is enabled.
969 EXPECT_TRUE(channel_->AddSendStream(cricket::StreamParams::CreateLegacy(2)));
970 int second_send_channel = vie_.GetLastChannel();
971 EXPECT_NE(first_send_channel, second_send_channel);
972 EXPECT_TRUE(vie_.GetSuspendBelowMinBitrateStatus(second_send_channel));
975 TEST_F(WebRtcVideoEngineTestFake, BufferedModeLatency) {
976 EXPECT_TRUE(SetupEngine());
978 // Verify this is off by default.
979 EXPECT_TRUE(channel_->AddSendStream(cricket::StreamParams::CreateLegacy(1)));
980 int first_send_channel = vie_.GetLastChannel();
981 EXPECT_EQ(0, vie_.GetSenderTargetDelay(first_send_channel));
982 EXPECT_EQ(0, vie_.GetReceiverTargetDelay(first_send_channel));
984 // Enable the experiment and verify. The default channel will have both
985 // sender and receiver buffered mode enabled.
986 cricket::VideoOptions options;
987 options.conference_mode.Set(true);
988 options.buffered_mode_latency.Set(100);
989 EXPECT_TRUE(channel_->SetOptions(options));
990 EXPECT_EQ(100, vie_.GetSenderTargetDelay(first_send_channel));
991 EXPECT_EQ(100, vie_.GetReceiverTargetDelay(first_send_channel));
993 // Add a receive channel and verify sender buffered mode isn't enabled.
994 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(2)));
995 int recv_channel_num = vie_.GetLastChannel();
996 EXPECT_NE(first_send_channel, recv_channel_num);
997 EXPECT_EQ(0, vie_.GetSenderTargetDelay(recv_channel_num));
998 EXPECT_EQ(100, vie_.GetReceiverTargetDelay(recv_channel_num));
1000 // Add a new send stream and verify sender buffered mode is enabled.
1001 EXPECT_TRUE(channel_->AddSendStream(cricket::StreamParams::CreateLegacy(3)));
1002 int second_send_channel = vie_.GetLastChannel();
1003 EXPECT_NE(first_send_channel, second_send_channel);
1004 EXPECT_EQ(100, vie_.GetSenderTargetDelay(second_send_channel));
1005 EXPECT_EQ(0, vie_.GetReceiverTargetDelay(second_send_channel));
1007 // Disable sender buffered mode and verify.
1008 options.buffered_mode_latency.Set(cricket::kBufferedModeDisabled);
1009 EXPECT_TRUE(channel_->SetOptions(options));
1010 EXPECT_EQ(0, vie_.GetSenderTargetDelay(first_send_channel));
1011 EXPECT_EQ(0, vie_.GetReceiverTargetDelay(first_send_channel));
1012 EXPECT_EQ(0, vie_.GetSenderTargetDelay(second_send_channel));
1013 EXPECT_EQ(0, vie_.GetReceiverTargetDelay(second_send_channel));
1014 EXPECT_EQ(0, vie_.GetSenderTargetDelay(recv_channel_num));
1015 EXPECT_EQ(0, vie_.GetReceiverTargetDelay(recv_channel_num));
1018 TEST_F(WebRtcVideoEngineTestFake, AdditiveVideoOptions) {
1019 EXPECT_TRUE(SetupEngine());
1021 EXPECT_TRUE(channel_->AddSendStream(cricket::StreamParams::CreateLegacy(1)));
1022 int first_send_channel = vie_.GetLastChannel();
1023 EXPECT_EQ(0, vie_.GetSenderTargetDelay(first_send_channel));
1024 EXPECT_EQ(0, vie_.GetReceiverTargetDelay(first_send_channel));
1026 cricket::VideoOptions options1;
1027 options1.buffered_mode_latency.Set(100);
1028 EXPECT_TRUE(channel_->SetOptions(options1));
1029 EXPECT_EQ(100, vie_.GetSenderTargetDelay(first_send_channel));
1030 EXPECT_EQ(100, vie_.GetReceiverTargetDelay(first_send_channel));
1031 EXPECT_FALSE(vie_.GetTransmissionSmoothingStatus(first_send_channel));
1033 cricket::VideoOptions options2;
1034 options2.video_leaky_bucket.Set(true);
1035 EXPECT_TRUE(channel_->SetOptions(options2));
1036 EXPECT_TRUE(vie_.GetTransmissionSmoothingStatus(first_send_channel));
1037 // The buffered_mode_latency still takes effect.
1038 EXPECT_EQ(100, vie_.GetSenderTargetDelay(first_send_channel));
1039 EXPECT_EQ(100, vie_.GetReceiverTargetDelay(first_send_channel));
1041 options1.buffered_mode_latency.Set(50);
1042 EXPECT_TRUE(channel_->SetOptions(options1));
1043 EXPECT_EQ(50, vie_.GetSenderTargetDelay(first_send_channel));
1044 EXPECT_EQ(50, vie_.GetReceiverTargetDelay(first_send_channel));
1045 // The video_leaky_bucket still takes effect.
1046 EXPECT_TRUE(vie_.GetTransmissionSmoothingStatus(first_send_channel));
1049 TEST_F(WebRtcVideoEngineTestFake, SetCpuOveruseOptionsWithCaptureJitterMethod) {
1050 EXPECT_TRUE(SetupEngine());
1052 // Verify this is off by default.
1053 EXPECT_TRUE(channel_->AddSendStream(cricket::StreamParams::CreateLegacy(1)));
1054 int first_send_channel = vie_.GetLastChannel();
1055 webrtc::CpuOveruseOptions cpu_option =
1056 vie_.GetCpuOveruseOptions(first_send_channel);
1057 EXPECT_EQ(0, cpu_option.low_capture_jitter_threshold_ms);
1058 EXPECT_EQ(0, cpu_option.high_capture_jitter_threshold_ms);
1059 EXPECT_FALSE(cpu_option.enable_capture_jitter_method);
1060 EXPECT_FALSE(cpu_option.enable_encode_usage_method);
1062 // Set low and high threshold and verify that cpu options are set.
1063 cricket::VideoOptions options;
1064 options.conference_mode.Set(true);
1065 options.cpu_underuse_threshold.Set(10);
1066 options.cpu_overuse_threshold.Set(20);
1067 EXPECT_TRUE(channel_->SetOptions(options));
1068 cpu_option = vie_.GetCpuOveruseOptions(first_send_channel);
1069 EXPECT_EQ(10, cpu_option.low_capture_jitter_threshold_ms);
1070 EXPECT_EQ(20, cpu_option.high_capture_jitter_threshold_ms);
1071 EXPECT_TRUE(cpu_option.enable_capture_jitter_method);
1072 EXPECT_FALSE(cpu_option.enable_encode_usage_method);
1074 // Add a receive channel and verify that cpu options are not set.
1075 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(2)));
1076 int recv_channel_num = vie_.GetLastChannel();
1077 EXPECT_NE(first_send_channel, recv_channel_num);
1078 cpu_option = vie_.GetCpuOveruseOptions(recv_channel_num);
1079 EXPECT_EQ(0, cpu_option.low_capture_jitter_threshold_ms);
1080 EXPECT_EQ(0, cpu_option.high_capture_jitter_threshold_ms);
1081 EXPECT_FALSE(cpu_option.enable_capture_jitter_method);
1082 EXPECT_FALSE(cpu_option.enable_encode_usage_method);
1084 // Add a new send stream and verify that cpu options are set from start.
1085 EXPECT_TRUE(channel_->AddSendStream(cricket::StreamParams::CreateLegacy(3)));
1086 int second_send_channel = vie_.GetLastChannel();
1087 EXPECT_NE(first_send_channel, second_send_channel);
1088 cpu_option = vie_.GetCpuOveruseOptions(second_send_channel);
1089 EXPECT_EQ(10, cpu_option.low_capture_jitter_threshold_ms);
1090 EXPECT_EQ(20, cpu_option.high_capture_jitter_threshold_ms);
1091 EXPECT_TRUE(cpu_option.enable_capture_jitter_method);
1092 EXPECT_FALSE(cpu_option.enable_encode_usage_method);
1095 TEST_F(WebRtcVideoEngineTestFake, SetInvalidCpuOveruseThresholds) {
1096 EXPECT_TRUE(SetupEngine());
1097 EXPECT_TRUE(channel_->AddSendStream(cricket::StreamParams::CreateLegacy(1)));
1098 int channel_num = vie_.GetLastChannel();
1100 // Only low threshold set. Verify that cpu options are not set.
1101 cricket::VideoOptions options;
1102 options.conference_mode.Set(true);
1103 options.cpu_underuse_threshold.Set(10);
1104 EXPECT_TRUE(channel_->SetOptions(options));
1105 webrtc::CpuOveruseOptions cpu_option = vie_.GetCpuOveruseOptions(channel_num);
1106 EXPECT_EQ(0, cpu_option.low_capture_jitter_threshold_ms);
1107 EXPECT_EQ(0, cpu_option.high_capture_jitter_threshold_ms);
1108 EXPECT_FALSE(cpu_option.enable_capture_jitter_method);
1109 EXPECT_FALSE(cpu_option.enable_encode_usage_method);
1111 // Set high threshold to a negative value. Verify that options are not set.
1112 options.cpu_overuse_threshold.Set(-1);
1113 EXPECT_TRUE(channel_->SetOptions(options));
1114 cpu_option = vie_.GetCpuOveruseOptions(channel_num);
1115 EXPECT_EQ(0, cpu_option.low_capture_jitter_threshold_ms);
1116 EXPECT_EQ(0, cpu_option.high_capture_jitter_threshold_ms);
1117 EXPECT_FALSE(cpu_option.enable_capture_jitter_method);
1118 EXPECT_FALSE(cpu_option.enable_encode_usage_method);
1120 // Low and high threshold valid. Verify that cpu options are set.
1121 options.cpu_overuse_threshold.Set(20);
1122 EXPECT_TRUE(channel_->SetOptions(options));
1123 cpu_option = vie_.GetCpuOveruseOptions(channel_num);
1124 EXPECT_EQ(10, cpu_option.low_capture_jitter_threshold_ms);
1125 EXPECT_EQ(20, cpu_option.high_capture_jitter_threshold_ms);
1126 EXPECT_TRUE(cpu_option.enable_capture_jitter_method);
1127 EXPECT_FALSE(cpu_option.enable_encode_usage_method);
1130 TEST_F(WebRtcVideoEngineTestFake, SetCpuOveruseOptionsWithEncodeUsageMethod) {
1131 EXPECT_TRUE(SetupEngine());
1132 EXPECT_TRUE(channel_->AddSendStream(cricket::StreamParams::CreateLegacy(1)));
1133 int first_send_channel = vie_.GetLastChannel();
1135 // Set low and high threshold and enable encode usage method.
1136 // Verify that cpu options are set.
1137 cricket::VideoOptions options;
1138 options.conference_mode.Set(true);
1139 options.cpu_underuse_threshold.Set(10);
1140 options.cpu_overuse_threshold.Set(20);
1141 options.cpu_overuse_encode_usage.Set(true);
1142 EXPECT_TRUE(channel_->SetOptions(options));
1143 webrtc::CpuOveruseOptions cpu_option =
1144 vie_.GetCpuOveruseOptions(first_send_channel);
1145 EXPECT_EQ(10, cpu_option.low_encode_usage_threshold_percent);
1146 EXPECT_EQ(20, cpu_option.high_encode_usage_threshold_percent);
1147 EXPECT_FALSE(cpu_option.enable_capture_jitter_method);
1148 EXPECT_TRUE(cpu_option.enable_encode_usage_method);
1150 // Add a new send stream and verify that cpu options are set from start.
1151 EXPECT_TRUE(channel_->AddSendStream(cricket::StreamParams::CreateLegacy(3)));
1152 int second_send_channel = vie_.GetLastChannel();
1153 EXPECT_NE(first_send_channel, second_send_channel);
1154 cpu_option = vie_.GetCpuOveruseOptions(second_send_channel);
1155 EXPECT_EQ(10, cpu_option.low_encode_usage_threshold_percent);
1156 EXPECT_EQ(20, cpu_option.high_encode_usage_threshold_percent);
1157 EXPECT_FALSE(cpu_option.enable_capture_jitter_method);
1158 EXPECT_TRUE(cpu_option.enable_encode_usage_method);
1161 // Test that AddRecvStream doesn't create new channel for 1:1 call.
1162 TEST_F(WebRtcVideoEngineTestFake, AddRecvStream1On1) {
1163 EXPECT_TRUE(SetupEngine());
1164 int channel_num = vie_.GetLastChannel();
1165 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(1)));
1166 EXPECT_EQ(channel_num, vie_.GetLastChannel());
1169 // Test that NACK, PLI and REMB are enabled for internal codec.
1170 TEST_F(WebRtcVideoEngineTestFake, InternalCodecFeedbackParams) {
1171 EXPECT_TRUE(SetupEngine());
1173 std::vector<cricket::VideoCodec> codecs(engine_.codecs());
1174 // Vp8 will appear at the beginning.
1176 EXPECT_EQ("VP8", codecs[pos].name);
1177 VerifyCodecFeedbackParams(codecs[pos]);
1180 // Test that AddRecvStream doesn't change remb for 1:1 call.
1181 TEST_F(WebRtcVideoEngineTestFake, NoRembChangeAfterAddRecvStream) {
1182 EXPECT_TRUE(SetupEngine());
1183 int channel_num = vie_.GetLastChannel();
1184 EXPECT_TRUE(channel_->AddSendStream(
1185 cricket::StreamParams::CreateLegacy(1)));
1186 EXPECT_TRUE(channel_->SetSendCodecs(engine_.codecs()));
1187 EXPECT_TRUE(vie_.GetRembStatusBwPartition(channel_num));
1188 EXPECT_TRUE(vie_.GetRembStatusContribute(channel_num));
1189 EXPECT_TRUE(channel_->SetSend(true));
1190 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(1)));
1191 EXPECT_TRUE(vie_.GetRembStatusBwPartition(channel_num));
1192 EXPECT_TRUE(vie_.GetRembStatusContribute(channel_num));
1195 // Verify default REMB setting and that it can be turned on and off.
1196 TEST_F(WebRtcVideoEngineTestFake, RembOnOff) {
1197 EXPECT_TRUE(SetupEngine());
1198 int channel_num = vie_.GetLastChannel();
1199 // Verify REMB sending is always off by default.
1200 EXPECT_FALSE(vie_.GetRembStatusBwPartition(channel_num));
1202 // Verify that REMB is turned on when setting default codecs since the
1203 // default codecs have REMB enabled.
1204 EXPECT_TRUE(channel_->SetSendCodecs(engine_.codecs()));
1205 EXPECT_TRUE(vie_.GetRembStatusBwPartition(channel_num));
1207 // Verify that REMB is turned off when codecs without REMB are set.
1208 std::vector<cricket::VideoCodec> codecs = engine_.codecs();
1209 // Clearing the codecs' FeedbackParams and setting send codecs should disable
1211 for (std::vector<cricket::VideoCodec>::iterator iter = codecs.begin();
1212 iter != codecs.end(); ++iter) {
1213 // Intersecting with empty will clear the FeedbackParams.
1214 cricket::FeedbackParams empty_params;
1215 iter->feedback_params.Intersect(empty_params);
1216 EXPECT_TRUE(iter->feedback_params.params().empty());
1218 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1219 EXPECT_FALSE(vie_.GetRembStatusBwPartition(channel_num));
1222 // Test that nack is enabled on the channel if we don't offer red/fec.
1223 TEST_F(WebRtcVideoEngineTestFake, NackEnabled) {
1224 EXPECT_TRUE(SetupEngine());
1225 int channel_num = vie_.GetLastChannel();
1226 std::vector<cricket::VideoCodec> codecs(engine_.codecs());
1227 codecs.resize(1); // toss out red and ulpfec
1228 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1229 EXPECT_TRUE(vie_.GetNackStatus(channel_num));
1232 // Test that we enable hybrid NACK FEC mode.
1233 TEST_F(WebRtcVideoEngineTestFake, HybridNackFec) {
1234 EXPECT_TRUE(SetupEngine());
1235 int channel_num = vie_.GetLastChannel();
1236 EXPECT_TRUE(channel_->SetRecvCodecs(engine_.codecs()));
1237 EXPECT_TRUE(channel_->SetSendCodecs(engine_.codecs()));
1238 EXPECT_TRUE(vie_.GetHybridNackFecStatus(channel_num));
1239 EXPECT_FALSE(vie_.GetNackStatus(channel_num));
1242 // Test that we enable hybrid NACK FEC mode when calling SetSendCodecs and
1243 // SetReceiveCodecs in reversed order.
1244 TEST_F(WebRtcVideoEngineTestFake, HybridNackFecReversedOrder) {
1245 EXPECT_TRUE(SetupEngine());
1246 int channel_num = vie_.GetLastChannel();
1247 EXPECT_TRUE(channel_->SetSendCodecs(engine_.codecs()));
1248 EXPECT_TRUE(channel_->SetRecvCodecs(engine_.codecs()));
1249 EXPECT_TRUE(vie_.GetHybridNackFecStatus(channel_num));
1250 EXPECT_FALSE(vie_.GetNackStatus(channel_num));
1253 // Test NACK vs Hybrid NACK/FEC interop call setup, i.e. only use NACK even if
1254 // red/fec is offered as receive codec.
1255 TEST_F(WebRtcVideoEngineTestFake, VideoProtectionInterop) {
1256 EXPECT_TRUE(SetupEngine());
1257 int channel_num = vie_.GetLastChannel();
1258 std::vector<cricket::VideoCodec> recv_codecs(engine_.codecs());
1259 std::vector<cricket::VideoCodec> send_codecs(engine_.codecs());
1260 // Only add VP8 as send codec.
1261 send_codecs.resize(1);
1262 EXPECT_TRUE(channel_->SetRecvCodecs(recv_codecs));
1263 EXPECT_TRUE(channel_->SetSendCodecs(send_codecs));
1264 EXPECT_FALSE(vie_.GetHybridNackFecStatus(channel_num));
1265 EXPECT_TRUE(vie_.GetNackStatus(channel_num));
1268 // Test NACK vs Hybrid NACK/FEC interop call setup, i.e. only use NACK even if
1269 // red/fec is offered as receive codec. Call order reversed compared to
1270 // VideoProtectionInterop.
1271 TEST_F(WebRtcVideoEngineTestFake, VideoProtectionInteropReversed) {
1272 EXPECT_TRUE(SetupEngine());
1273 int channel_num = vie_.GetLastChannel();
1274 std::vector<cricket::VideoCodec> recv_codecs(engine_.codecs());
1275 std::vector<cricket::VideoCodec> send_codecs(engine_.codecs());
1276 // Only add VP8 as send codec.
1277 send_codecs.resize(1);
1278 EXPECT_TRUE(channel_->SetSendCodecs(send_codecs));
1279 EXPECT_TRUE(channel_->SetRecvCodecs(recv_codecs));
1280 EXPECT_FALSE(vie_.GetHybridNackFecStatus(channel_num));
1281 EXPECT_TRUE(vie_.GetNackStatus(channel_num));
1284 // Test that NACK, not hybrid mode, is enabled in conference mode.
1285 TEST_F(WebRtcVideoEngineTestFake, HybridNackFecConference) {
1286 EXPECT_TRUE(SetupEngine());
1287 // Setup the send channel.
1288 int send_channel_num = vie_.GetLastChannel();
1289 cricket::VideoOptions options;
1290 options.conference_mode.Set(true);
1291 EXPECT_TRUE(channel_->SetOptions(options));
1292 EXPECT_TRUE(channel_->SetRecvCodecs(engine_.codecs()));
1293 EXPECT_TRUE(channel_->SetSendCodecs(engine_.codecs()));
1294 EXPECT_FALSE(vie_.GetHybridNackFecStatus(send_channel_num));
1295 EXPECT_TRUE(vie_.GetNackStatus(send_channel_num));
1296 // Add a receive stream.
1297 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(1)));
1298 int receive_channel_num = vie_.GetLastChannel();
1299 EXPECT_FALSE(vie_.GetHybridNackFecStatus(receive_channel_num));
1300 EXPECT_TRUE(vie_.GetNackStatus(receive_channel_num));
1303 // Test that when AddRecvStream in conference mode, a new channel is created
1304 // for receiving. And the new channel's "original channel" is the send channel.
1305 TEST_F(WebRtcVideoEngineTestFake, AddRemoveRecvStreamConference) {
1306 EXPECT_TRUE(SetupEngine());
1307 // Setup the send channel.
1308 int send_channel_num = vie_.GetLastChannel();
1309 cricket::VideoOptions options;
1310 options.conference_mode.Set(true);
1311 EXPECT_TRUE(channel_->SetOptions(options));
1312 // Add a receive stream.
1313 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(1)));
1314 int receive_channel_num = vie_.GetLastChannel();
1315 EXPECT_EQ(send_channel_num, vie_.GetOriginalChannelId(receive_channel_num));
1316 EXPECT_TRUE(channel_->RemoveRecvStream(1));
1317 EXPECT_FALSE(vie_.IsChannel(receive_channel_num));
1320 // Test that adding/removing stream with 0 ssrc should fail (and not crash).
1321 // For crbug/351699 and 350988.
1322 TEST_F(WebRtcVideoEngineTestFake, AddRemoveRecvStreamWith0Ssrc) {
1323 EXPECT_TRUE(SetupEngine());
1324 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(1)));
1325 EXPECT_FALSE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(0)));
1326 EXPECT_FALSE(channel_->RemoveRecvStream(0));
1327 EXPECT_TRUE(channel_->RemoveRecvStream(1));
1330 TEST_F(WebRtcVideoEngineTestFake, AddRemoveSendStreamWith0Ssrc) {
1331 EXPECT_TRUE(SetupEngine());
1332 EXPECT_TRUE(channel_->AddSendStream(cricket::StreamParams::CreateLegacy(1)));
1333 EXPECT_FALSE(channel_->AddSendStream(cricket::StreamParams::CreateLegacy(0)));
1334 EXPECT_FALSE(channel_->RemoveSendStream(0));
1335 EXPECT_TRUE(channel_->RemoveSendStream(1));
1338 // Test that we can create a channel and start/stop rendering out on it.
1339 TEST_F(WebRtcVideoEngineTestFake, SetRender) {
1340 EXPECT_TRUE(SetupEngine());
1341 int channel_num = vie_.GetLastChannel();
1343 // Verify we can start/stop/start/stop rendering.
1344 EXPECT_TRUE(channel_->SetRender(true));
1345 EXPECT_TRUE(vie_.GetRenderStarted(channel_num));
1346 EXPECT_TRUE(channel_->SetRender(false));
1347 EXPECT_FALSE(vie_.GetRenderStarted(channel_num));
1348 EXPECT_TRUE(channel_->SetRender(true));
1349 EXPECT_TRUE(vie_.GetRenderStarted(channel_num));
1350 EXPECT_TRUE(channel_->SetRender(false));
1351 EXPECT_FALSE(vie_.GetRenderStarted(channel_num));
1354 // Test that we can create a channel and start/stop sending out on it.
1355 TEST_F(WebRtcVideoEngineTestFake, SetSend) {
1356 EXPECT_TRUE(SetupEngine());
1357 int channel_num = vie_.GetLastChannel();
1358 // Verify receiving is also started.
1359 EXPECT_TRUE(vie_.GetReceive(channel_num));
1361 // Set send codecs on the channel.
1362 std::vector<cricket::VideoCodec> codecs;
1363 codecs.push_back(kVP8Codec);
1364 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1365 EXPECT_TRUE(channel_->AddSendStream(
1366 cricket::StreamParams::CreateLegacy(123)));
1368 // Verify we can start/stop/start/stop sending.
1369 EXPECT_TRUE(channel_->SetSend(true));
1370 EXPECT_TRUE(vie_.GetSend(channel_num));
1371 EXPECT_TRUE(channel_->SetSend(false));
1372 EXPECT_FALSE(vie_.GetSend(channel_num));
1373 EXPECT_TRUE(channel_->SetSend(true));
1374 EXPECT_TRUE(vie_.GetSend(channel_num));
1375 EXPECT_TRUE(channel_->SetSend(false));
1376 EXPECT_FALSE(vie_.GetSend(channel_num));
1379 // Test that we set bandwidth properly when using full auto bandwidth mode.
1380 TEST_F(WebRtcVideoEngineTestFake, SetBandwidthAuto) {
1381 EXPECT_TRUE(SetupEngine());
1382 int channel_num = vie_.GetLastChannel();
1383 EXPECT_TRUE(channel_->SetSendCodecs(engine_.codecs()));
1384 EXPECT_TRUE(channel_->SetMaxSendBandwidth(cricket::kAutoBandwidth));
1385 VerifyVP8SendCodec(channel_num, kVP8Codec.width, kVP8Codec.height);
1388 // Test that we set bandwidth properly when using auto with upper bound.
1389 TEST_F(WebRtcVideoEngineTestFake, SetBandwidthCapped) {
1390 EXPECT_TRUE(SetupEngine());
1391 int channel_num = vie_.GetLastChannel();
1392 EXPECT_TRUE(channel_->SetSendCodecs(engine_.codecs()));
1393 EXPECT_TRUE(channel_->SetMaxSendBandwidth(768000));
1394 VerifyVP8SendCodec(channel_num, kVP8Codec.width, kVP8Codec.height, 0, 768U);
1397 // Test that we reduce the start bandwidth when the requested max is less than
1398 // the default start bandwidth.
1399 TEST_F(WebRtcVideoEngineTestFake, SetMaxBandwidthBelowDefaultStart) {
1400 EXPECT_TRUE(SetupEngine());
1401 int channel_num = vie_.GetLastChannel();
1402 EXPECT_TRUE(channel_->SetSendCodecs(engine_.codecs()));
1403 int max_bandwidth_kbps = (kMinBandwidthKbps + kStartBandwidthKbps) / 2;
1404 EXPECT_TRUE(channel_->SetMaxSendBandwidth(max_bandwidth_kbps * 1000));
1405 VerifyVP8SendCodec(channel_num, kVP8Codec.width, kVP8Codec.height, 0,
1406 max_bandwidth_kbps, kMinBandwidthKbps, max_bandwidth_kbps);
1409 // Test that we reduce the min bandwidth when the requested max is less than
1410 // the min bandwidth.
1411 TEST_F(WebRtcVideoEngineTestFake, SetMaxBandwidthBelowMin) {
1412 EXPECT_TRUE(SetupEngine());
1413 int channel_num = vie_.GetLastChannel();
1414 EXPECT_TRUE(channel_->SetSendCodecs(engine_.codecs()));
1415 int max_bandwidth_kbps = kMinBandwidthKbps / 2;
1416 EXPECT_TRUE(channel_->SetMaxSendBandwidth(max_bandwidth_kbps * 1000));
1417 VerifyVP8SendCodec(channel_num, kVP8Codec.width, kVP8Codec.height, 0,
1418 max_bandwidth_kbps, max_bandwidth_kbps, max_bandwidth_kbps);
1421 // Test that the start bandwidth can be controlled separately from the max
1423 TEST_F(WebRtcVideoEngineTestFake, SetStartBandwidth) {
1424 EXPECT_TRUE(SetupEngine());
1425 int channel_num = vie_.GetLastChannel();
1426 EXPECT_TRUE(channel_->SetSendCodecs(engine_.codecs()));
1427 int start_bandwidth_kbps = kStartBandwidthKbps + 1;
1428 EXPECT_TRUE(channel_->SetStartSendBandwidth(start_bandwidth_kbps * 1000));
1429 VerifyVP8SendCodec(channel_num, kVP8Codec.width, kVP8Codec.height, 0,
1430 kMaxBandwidthKbps, kMinBandwidthKbps, start_bandwidth_kbps);
1432 // Check that SetMaxSendBandwidth doesn't overwrite the start bandwidth.
1433 int max_bandwidth_kbps = kMaxBandwidthKbps + 1;
1434 EXPECT_TRUE(channel_->SetMaxSendBandwidth(max_bandwidth_kbps * 1000));
1435 VerifyVP8SendCodec(channel_num, kVP8Codec.width, kVP8Codec.height, 0,
1436 max_bandwidth_kbps, kMinBandwidthKbps, start_bandwidth_kbps);
1439 // Test that the start bandwidth can be controlled by experiment.
1440 TEST_F(WebRtcVideoEngineTestFake, SetStartBandwidthOption) {
1441 EXPECT_TRUE(SetupEngine());
1442 int channel_num = vie_.GetLastChannel();
1443 EXPECT_TRUE(channel_->SetSendCodecs(engine_.codecs()));
1444 int start_bandwidth_kbps = kStartBandwidthKbps;
1445 EXPECT_TRUE(channel_->SetStartSendBandwidth(start_bandwidth_kbps * 1000));
1446 VerifyVP8SendCodec(channel_num, kVP8Codec.width, kVP8Codec.height, 0,
1447 kMaxBandwidthKbps, kMinBandwidthKbps, start_bandwidth_kbps);
1449 // Set the start bitrate option.
1450 start_bandwidth_kbps = 1000;
1451 cricket::VideoOptions options;
1452 options.video_start_bitrate.Set(
1453 start_bandwidth_kbps);
1454 EXPECT_TRUE(channel_->SetOptions(options));
1456 // Check that start bitrate has changed to the new value.
1457 VerifyVP8SendCodec(channel_num, kVP8Codec.width, kVP8Codec.height, 0,
1458 kMaxBandwidthKbps, kMinBandwidthKbps, start_bandwidth_kbps);
1461 // Test that SetMaxSendBandwidth works as expected in conference mode.
1462 TEST_F(WebRtcVideoEngineTestFake, SetBandwidthInConference) {
1463 EXPECT_TRUE(SetupEngine());
1464 int channel_num = vie_.GetLastChannel();
1465 cricket::VideoOptions options;
1466 options.conference_mode.Set(true);
1467 EXPECT_TRUE(channel_->SetOptions(options));
1468 EXPECT_TRUE(channel_->SetSendCodecs(engine_.codecs()));
1469 VerifyVP8SendCodec(channel_num, kVP8Codec.width, kVP8Codec.height);
1471 // Set send bandwidth.
1472 EXPECT_TRUE(channel_->SetMaxSendBandwidth(768000));
1474 // Verify that the max bitrate has changed.
1475 VerifyVP8SendCodec(channel_num, kVP8Codec.width, kVP8Codec.height, 0,
1476 768, kMinBandwidthKbps, kStartBandwidthKbps);
1480 // Test that sending screencast frames doesn't change bitrate.
1481 TEST_F(WebRtcVideoEngineTestFake, SetBandwidthScreencast) {
1482 EXPECT_TRUE(SetupEngine());
1483 int channel_num = vie_.GetLastChannel();
1486 cricket::VideoCodec codec(kVP8Codec);
1487 std::vector<cricket::VideoCodec> codec_list;
1488 codec_list.push_back(codec);
1489 EXPECT_TRUE(channel_->AddSendStream(
1490 cricket::StreamParams::CreateLegacy(123)));
1491 EXPECT_TRUE(channel_->SetSendCodecs(codec_list));
1492 EXPECT_TRUE(channel_->SetMaxSendBandwidth(111000));
1493 EXPECT_TRUE(channel_->SetSend(true));
1495 SendI420ScreencastFrame(kVP8Codec.width, kVP8Codec.height);
1496 VerifyVP8SendCodec(channel_num, kVP8Codec.width, kVP8Codec.height, 0, 111);
1500 // Test SetSendSsrc.
1501 TEST_F(WebRtcVideoEngineTestFake, SetSendSsrcAndCname) {
1502 EXPECT_TRUE(SetupEngine());
1503 int channel_num = vie_.GetLastChannel();
1505 cricket::StreamParams stream;
1506 stream.ssrcs.push_back(1234);
1507 stream.cname = "cname";
1508 channel_->AddSendStream(stream);
1510 unsigned int ssrc = 0;
1511 EXPECT_EQ(0, vie_.GetLocalSSRC(channel_num, ssrc));
1512 EXPECT_EQ(1234U, ssrc);
1513 EXPECT_EQ(1, vie_.GetNumSsrcs(channel_num));
1515 char rtcp_cname[256];
1516 EXPECT_EQ(0, vie_.GetRTCPCName(channel_num, rtcp_cname));
1517 EXPECT_STREQ("cname", rtcp_cname);
1521 // Test that the local SSRC is the same on sending and receiving channels if the
1522 // receive channel is created before the send channel.
1523 TEST_F(WebRtcVideoEngineTestFake, SetSendSsrcAfterCreatingReceiveChannel) {
1524 EXPECT_TRUE(SetupEngine());
1526 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(1)));
1527 int receive_channel_num = vie_.GetLastChannel();
1528 cricket::StreamParams stream = cricket::StreamParams::CreateLegacy(1234);
1529 EXPECT_TRUE(channel_->AddSendStream(stream));
1530 int send_channel_num = vie_.GetLastChannel();
1531 unsigned int ssrc = 0;
1532 EXPECT_EQ(0, vie_.GetLocalSSRC(send_channel_num, ssrc));
1533 EXPECT_EQ(1234U, ssrc);
1534 EXPECT_EQ(1, vie_.GetNumSsrcs(send_channel_num));
1536 EXPECT_EQ(0, vie_.GetLocalSSRC(receive_channel_num, ssrc));
1537 EXPECT_EQ(1234U, ssrc);
1538 EXPECT_EQ(1, vie_.GetNumSsrcs(receive_channel_num));
1542 // Test SetOptions with denoising flag.
1543 TEST_F(WebRtcVideoEngineTestFake, SetOptionsWithDenoising) {
1544 EXPECT_TRUE(SetupEngine());
1545 EXPECT_EQ(1, vie_.GetNumCapturers());
1546 int channel_num = vie_.GetLastChannel();
1547 int capture_id = vie_.GetCaptureId(channel_num);
1548 // Set send codecs on the channel.
1549 std::vector<cricket::VideoCodec> codecs;
1550 codecs.push_back(kVP8Codec);
1551 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1553 // Set options with OPT_VIDEO_NOISE_REDUCTION flag.
1554 cricket::VideoOptions options;
1555 options.video_noise_reduction.Set(true);
1556 EXPECT_TRUE(channel_->SetOptions(options));
1558 // Verify capture has denoising turned on.
1559 webrtc::VideoCodec send_codec;
1560 memset(&send_codec, 0, sizeof(send_codec)); // avoid uninitialized warning
1561 EXPECT_EQ(0, vie_.GetSendCodec(channel_num, send_codec));
1562 EXPECT_TRUE(send_codec.codecSpecific.VP8.denoisingOn);
1563 EXPECT_FALSE(vie_.GetCaptureDenoising(capture_id));
1565 // Set options back to zero.
1566 options.video_noise_reduction.Set(false);
1567 EXPECT_TRUE(channel_->SetOptions(options));
1569 // Verify capture has denoising turned off.
1570 EXPECT_EQ(0, vie_.GetSendCodec(channel_num, send_codec));
1571 EXPECT_FALSE(send_codec.codecSpecific.VP8.denoisingOn);
1572 EXPECT_FALSE(vie_.GetCaptureDenoising(capture_id));
1575 TEST_F(WebRtcVideoEngineTestFake, MultipleSendStreamsWithOneCapturer) {
1576 EXPECT_TRUE(SetupEngine());
1578 // Start the capturer
1579 cricket::FakeVideoCapturer capturer;
1580 cricket::VideoFormat capture_format_vga = cricket::VideoFormat(640, 480,
1581 cricket::VideoFormat::FpsToInterval(30), cricket::FOURCC_I420);
1582 EXPECT_EQ(cricket::CS_RUNNING, capturer.Start(capture_format_vga));
1584 // Add send streams and connect the capturer
1585 for (unsigned int i = 0; i < sizeof(kSsrcs2)/sizeof(kSsrcs2[0]); ++i) {
1586 EXPECT_TRUE(channel_->AddSendStream(
1587 cricket::StreamParams::CreateLegacy(kSsrcs2[i])));
1588 // Register the capturer to the ssrc.
1589 EXPECT_TRUE(channel_->SetCapturer(kSsrcs2[i], &capturer));
1592 const int channel0 = vie_.GetChannelFromLocalSsrc(kSsrcs2[0]);
1593 ASSERT_NE(-1, channel0);
1594 const int channel1 = vie_.GetChannelFromLocalSsrc(kSsrcs2[1]);
1595 ASSERT_NE(-1, channel1);
1596 ASSERT_NE(channel0, channel1);
1598 // Both channels should have started receiving after created.
1599 EXPECT_TRUE(vie_.GetReceive(channel0));
1600 EXPECT_TRUE(vie_.GetReceive(channel1));
1603 std::vector<cricket::VideoCodec> codecs;
1604 cricket::VideoCodec send_codec(100, "VP8", 640, 480, 30, 0);
1605 codecs.push_back(send_codec);
1606 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1608 EXPECT_TRUE(channel_->SetSend(true));
1609 EXPECT_TRUE(vie_.GetSend(channel0));
1610 EXPECT_TRUE(vie_.GetSend(channel1));
1612 EXPECT_TRUE(capturer.CaptureFrame());
1613 EXPECT_EQ(1, vie_.GetIncomingFrameNum(channel0));
1614 EXPECT_EQ(1, vie_.GetIncomingFrameNum(channel1));
1616 EXPECT_TRUE(channel_->RemoveSendStream(kSsrcs2[0]));
1617 EXPECT_TRUE(capturer.CaptureFrame());
1618 // channel0 is the default channel, so it won't be deleted.
1619 // But it should be disconnected from the capturer.
1620 EXPECT_EQ(1, vie_.GetIncomingFrameNum(channel0));
1621 EXPECT_EQ(2, vie_.GetIncomingFrameNum(channel1));
1623 EXPECT_TRUE(channel_->RemoveSendStream(kSsrcs2[1]));
1624 EXPECT_TRUE(capturer.CaptureFrame());
1625 EXPECT_EQ(1, vie_.GetIncomingFrameNum(channel0));
1626 // channel1 has already been deleted.
1627 EXPECT_EQ(-1, vie_.GetIncomingFrameNum(channel1));
1631 TEST_F(WebRtcVideoEngineTestFake, SendReceiveBitratesStats) {
1632 EXPECT_TRUE(SetupEngine());
1633 cricket::VideoOptions options;
1634 options.conference_mode.Set(true);
1635 EXPECT_TRUE(channel_->SetOptions(options));
1636 EXPECT_TRUE(channel_->AddSendStream(
1637 cricket::StreamParams::CreateLegacy(1)));
1638 int first_send_channel = vie_.GetLastChannel();
1639 EXPECT_TRUE(channel_->AddSendStream(
1640 cricket::StreamParams::CreateLegacy(2)));
1641 int second_send_channel = vie_.GetLastChannel();
1642 cricket::VideoCodec codec(kVP8Codec720p);
1643 std::vector<cricket::VideoCodec> codec_list;
1644 codec_list.push_back(codec);
1645 EXPECT_TRUE(channel_->SetSendCodecs(codec_list));
1647 EXPECT_TRUE(channel_->AddRecvStream(
1648 cricket::StreamParams::CreateLegacy(3)));
1649 int first_receive_channel = vie_.GetLastChannel();
1650 EXPECT_NE(first_send_channel, first_receive_channel);
1651 EXPECT_TRUE(channel_->AddRecvStream(
1652 cricket::StreamParams::CreateLegacy(4)));
1653 int second_receive_channel = vie_.GetLastChannel();
1654 EXPECT_NE(first_receive_channel, second_receive_channel);
1656 cricket::VideoMediaInfo info;
1657 EXPECT_TRUE(channel_->GetStats(cricket::StatsOptions(), &info));
1658 ASSERT_EQ(1U, info.bw_estimations.size());
1659 ASSERT_EQ(0, info.bw_estimations[0].actual_enc_bitrate);
1660 ASSERT_EQ(0, info.bw_estimations[0].transmit_bitrate);
1661 ASSERT_EQ(0, info.bw_estimations[0].retransmit_bitrate);
1662 ASSERT_EQ(0, info.bw_estimations[0].available_send_bandwidth);
1663 ASSERT_EQ(0, info.bw_estimations[0].available_recv_bandwidth);
1664 ASSERT_EQ(0, info.bw_estimations[0].target_enc_bitrate);
1666 // Start sending and receiving on one of the channels and verify bitrates.
1667 EXPECT_EQ(0, vie_.StartSend(first_send_channel));
1668 int send_video_bitrate = 800;
1669 int send_fec_bitrate = 100;
1670 int send_nack_bitrate = 20;
1671 int send_total_bitrate = send_video_bitrate + send_fec_bitrate +
1673 int send_bandwidth = 1900;
1674 vie_.SetSendBitrates(first_send_channel, send_video_bitrate, send_fec_bitrate,
1676 vie_.SetSendBandwidthEstimate(first_send_channel, send_bandwidth);
1678 EXPECT_EQ(0, vie_.StartReceive(first_receive_channel));
1679 int receive_bandwidth = 600;
1680 vie_.SetReceiveBandwidthEstimate(first_receive_channel, receive_bandwidth);
1683 EXPECT_TRUE(channel_->GetStats(cricket::StatsOptions(), &info));
1684 ASSERT_EQ(1U, info.bw_estimations.size());
1685 ASSERT_EQ(send_video_bitrate, info.bw_estimations[0].actual_enc_bitrate);
1686 ASSERT_EQ(send_total_bitrate, info.bw_estimations[0].transmit_bitrate);
1687 ASSERT_EQ(send_nack_bitrate, info.bw_estimations[0].retransmit_bitrate);
1688 ASSERT_EQ(send_bandwidth, info.bw_estimations[0].available_send_bandwidth);
1689 ASSERT_EQ(receive_bandwidth, info.bw_estimations[0].available_recv_bandwidth);
1690 ASSERT_EQ(send_video_bitrate, info.bw_estimations[0].target_enc_bitrate);
1692 // Start receiving on the second channel and verify received rate.
1693 EXPECT_EQ(0, vie_.StartSend(second_send_channel));
1694 vie_.SetSendBitrates(second_send_channel,
1698 EXPECT_EQ(0, vie_.StartReceive(second_receive_channel));
1701 EXPECT_TRUE(channel_->GetStats(cricket::StatsOptions(), &info));
1702 ASSERT_EQ(1U, info.bw_estimations.size());
1703 ASSERT_EQ(2 * send_video_bitrate, info.bw_estimations[0].actual_enc_bitrate);
1704 ASSERT_EQ(2 * send_total_bitrate, info.bw_estimations[0].transmit_bitrate);
1705 ASSERT_EQ(2 * send_nack_bitrate, info.bw_estimations[0].retransmit_bitrate);
1706 ASSERT_EQ(send_bandwidth, info.bw_estimations[0].available_send_bandwidth);
1707 ASSERT_EQ(receive_bandwidth, info.bw_estimations[0].available_recv_bandwidth);
1708 ASSERT_EQ(2 * send_video_bitrate, info.bw_estimations[0].target_enc_bitrate);
1711 TEST_F(WebRtcVideoEngineTestFake, TestSetAdaptInputToCpuUsage) {
1712 EXPECT_TRUE(SetupEngine());
1713 cricket::VideoOptions options_in, options_out;
1714 bool cpu_adapt = false;
1715 channel_->SetOptions(options_in);
1716 EXPECT_TRUE(channel_->GetOptions(&options_out));
1717 EXPECT_FALSE(options_out.adapt_input_to_cpu_usage.Get(&cpu_adapt));
1718 // Set adapt input CPU usage option.
1719 options_in.adapt_input_to_cpu_usage.Set(true);
1720 EXPECT_TRUE(channel_->SetOptions(options_in));
1721 EXPECT_TRUE(channel_->GetOptions(&options_out));
1722 EXPECT_TRUE(options_out.adapt_input_to_cpu_usage.Get(&cpu_adapt));
1723 EXPECT_TRUE(cpu_adapt);
1726 TEST_F(WebRtcVideoEngineTestFake, TestSetCpuThreshold) {
1727 EXPECT_TRUE(SetupEngine());
1729 cricket::VideoOptions options_in, options_out;
1730 // Verify that initial values are set.
1731 EXPECT_TRUE(channel_->GetOptions(&options_out));
1732 EXPECT_TRUE(options_out.system_low_adaptation_threshhold.Get(&low));
1733 EXPECT_EQ(low, 0.65f);
1734 EXPECT_TRUE(options_out.system_high_adaptation_threshhold.Get(&high));
1735 EXPECT_EQ(high, 0.85f);
1736 // Set new CPU threshold values.
1737 options_in.system_low_adaptation_threshhold.Set(0.45f);
1738 options_in.system_high_adaptation_threshhold.Set(0.95f);
1739 EXPECT_TRUE(channel_->SetOptions(options_in));
1740 EXPECT_TRUE(channel_->GetOptions(&options_out));
1741 EXPECT_TRUE(options_out.system_low_adaptation_threshhold.Get(&low));
1742 EXPECT_EQ(low, 0.45f);
1743 EXPECT_TRUE(options_out.system_high_adaptation_threshhold.Get(&high));
1744 EXPECT_EQ(high, 0.95f);
1747 TEST_F(WebRtcVideoEngineTestFake, TestSetInvalidCpuThreshold) {
1748 EXPECT_TRUE(SetupEngine());
1750 cricket::VideoOptions options_in, options_out;
1751 // Valid range is [0, 1].
1752 options_in.system_low_adaptation_threshhold.Set(-1.5f);
1753 options_in.system_high_adaptation_threshhold.Set(1.5f);
1754 EXPECT_TRUE(channel_->SetOptions(options_in));
1755 EXPECT_TRUE(channel_->GetOptions(&options_out));
1756 EXPECT_TRUE(options_out.system_low_adaptation_threshhold.Get(&low));
1757 EXPECT_EQ(low, 0.0f);
1758 EXPECT_TRUE(options_out.system_high_adaptation_threshhold.Get(&high));
1759 EXPECT_EQ(high, 1.0f);
1763 TEST_F(WebRtcVideoEngineTestFake, ResetCodecOnScreencast) {
1764 EXPECT_TRUE(SetupEngine());
1765 cricket::VideoOptions options;
1766 options.video_noise_reduction.Set(true);
1767 EXPECT_TRUE(channel_->SetOptions(options));
1770 cricket::VideoCodec codec(kVP8Codec);
1771 std::vector<cricket::VideoCodec> codec_list;
1772 codec_list.push_back(codec);
1773 EXPECT_TRUE(channel_->AddSendStream(
1774 cricket::StreamParams::CreateLegacy(123)));
1775 EXPECT_TRUE(channel_->SetSendCodecs(codec_list));
1776 EXPECT_TRUE(channel_->SetSend(true));
1777 EXPECT_EQ(1, vie_.GetNumSetSendCodecs());
1779 webrtc::VideoCodec gcodec;
1780 memset(&gcodec, 0, sizeof(gcodec));
1781 int channel_num = vie_.GetLastChannel();
1782 EXPECT_EQ(0, vie_.GetSendCodec(channel_num, gcodec));
1783 EXPECT_TRUE(gcodec.codecSpecific.VP8.denoisingOn);
1785 // Send a screencast frame with the same size.
1786 // Verify that denoising is turned off.
1787 SendI420ScreencastFrame(kVP8Codec.width, kVP8Codec.height);
1788 EXPECT_EQ(2, vie_.GetNumSetSendCodecs());
1789 EXPECT_EQ(0, vie_.GetSendCodec(channel_num, gcodec));
1790 EXPECT_FALSE(gcodec.codecSpecific.VP8.denoisingOn);
1794 TEST_F(WebRtcVideoEngineTestFake, DontRegisterDecoderIfFactoryIsNotGiven) {
1795 engine_.SetExternalDecoderFactory(NULL);
1796 EXPECT_TRUE(SetupEngine());
1797 int channel_num = vie_.GetLastChannel();
1799 std::vector<cricket::VideoCodec> codecs;
1800 codecs.push_back(kVP8Codec);
1801 EXPECT_TRUE(channel_->SetRecvCodecs(codecs));
1803 EXPECT_EQ(0, vie_.GetNumExternalDecoderRegistered(channel_num));
1806 TEST_F(WebRtcVideoEngineTestFake, RegisterDecoderIfFactoryIsGiven) {
1807 decoder_factory_.AddSupportedVideoCodecType(webrtc::kVideoCodecVP8);
1808 engine_.SetExternalDecoderFactory(&decoder_factory_);
1809 EXPECT_TRUE(SetupEngine());
1810 int channel_num = vie_.GetLastChannel();
1812 std::vector<cricket::VideoCodec> codecs;
1813 codecs.push_back(kVP8Codec);
1814 EXPECT_TRUE(channel_->SetRecvCodecs(codecs));
1816 EXPECT_TRUE(vie_.ExternalDecoderRegistered(channel_num, 100));
1817 EXPECT_EQ(1, vie_.GetNumExternalDecoderRegistered(channel_num));
1820 TEST_F(WebRtcVideoEngineTestFake, DontRegisterDecoderMultipleTimes) {
1821 decoder_factory_.AddSupportedVideoCodecType(webrtc::kVideoCodecVP8);
1822 engine_.SetExternalDecoderFactory(&decoder_factory_);
1823 EXPECT_TRUE(SetupEngine());
1824 int channel_num = vie_.GetLastChannel();
1826 std::vector<cricket::VideoCodec> codecs;
1827 codecs.push_back(kVP8Codec);
1828 EXPECT_TRUE(channel_->SetRecvCodecs(codecs));
1830 EXPECT_TRUE(vie_.ExternalDecoderRegistered(channel_num, 100));
1831 EXPECT_EQ(1, vie_.GetNumExternalDecoderRegistered(channel_num));
1832 EXPECT_EQ(1, decoder_factory_.GetNumCreatedDecoders());
1834 EXPECT_TRUE(channel_->SetRecvCodecs(codecs));
1835 EXPECT_EQ(1, vie_.GetNumExternalDecoderRegistered(channel_num));
1836 EXPECT_EQ(1, decoder_factory_.GetNumCreatedDecoders());
1839 TEST_F(WebRtcVideoEngineTestFake, DontRegisterDecoderForNonVP8) {
1840 decoder_factory_.AddSupportedVideoCodecType(webrtc::kVideoCodecVP8);
1841 engine_.SetExternalDecoderFactory(&decoder_factory_);
1842 EXPECT_TRUE(SetupEngine());
1843 int channel_num = vie_.GetLastChannel();
1845 std::vector<cricket::VideoCodec> codecs;
1846 codecs.push_back(kRedCodec);
1847 EXPECT_TRUE(channel_->SetRecvCodecs(codecs));
1849 EXPECT_EQ(0, vie_.GetNumExternalDecoderRegistered(channel_num));
1852 TEST_F(WebRtcVideoEngineTestFake, DontRegisterEncoderIfFactoryIsNotGiven) {
1853 engine_.SetExternalEncoderFactory(NULL);
1854 EXPECT_TRUE(SetupEngine());
1855 int channel_num = vie_.GetLastChannel();
1857 std::vector<cricket::VideoCodec> codecs;
1858 codecs.push_back(kVP8Codec);
1859 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1861 EXPECT_EQ(0, vie_.GetNumExternalEncoderRegistered(channel_num));
1864 TEST_F(WebRtcVideoEngineTestFake, RegisterEncoderIfFactoryIsGiven) {
1865 encoder_factory_.AddSupportedVideoCodecType(webrtc::kVideoCodecVP8, "VP8");
1866 engine_.SetExternalEncoderFactory(&encoder_factory_);
1867 EXPECT_TRUE(SetupEngine());
1868 int channel_num = vie_.GetLastChannel();
1870 std::vector<cricket::VideoCodec> codecs;
1871 codecs.push_back(kVP8Codec);
1872 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1874 EXPECT_TRUE(channel_->AddSendStream(
1875 cricket::StreamParams::CreateLegacy(kSsrc)));
1877 EXPECT_TRUE(vie_.ExternalEncoderRegistered(channel_num, 100));
1878 EXPECT_EQ(1, vie_.GetNumExternalEncoderRegistered(channel_num));
1880 // Remove stream previously added to free the external encoder instance.
1881 EXPECT_TRUE(channel_->RemoveSendStream(kSsrc));
1884 TEST_F(WebRtcVideoEngineTestFake, DontRegisterEncoderMultipleTimes) {
1885 encoder_factory_.AddSupportedVideoCodecType(webrtc::kVideoCodecVP8, "VP8");
1886 engine_.SetExternalEncoderFactory(&encoder_factory_);
1887 EXPECT_TRUE(SetupEngine());
1888 int channel_num = vie_.GetLastChannel();
1890 std::vector<cricket::VideoCodec> codecs;
1891 codecs.push_back(kVP8Codec);
1892 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1894 EXPECT_TRUE(channel_->AddSendStream(
1895 cricket::StreamParams::CreateLegacy(kSsrc)));
1897 EXPECT_TRUE(vie_.ExternalEncoderRegistered(channel_num, 100));
1898 EXPECT_EQ(1, vie_.GetNumExternalEncoderRegistered(channel_num));
1900 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1901 EXPECT_EQ(1, vie_.GetNumExternalEncoderRegistered(channel_num));
1903 // Remove stream previously added to free the external encoder instance.
1904 EXPECT_TRUE(channel_->RemoveSendStream(kSsrc));
1907 TEST_F(WebRtcVideoEngineTestFake, RegisterEncoderWithMultipleSendStreams) {
1908 encoder_factory_.AddSupportedVideoCodecType(webrtc::kVideoCodecVP8, "VP8");
1909 engine_.SetExternalEncoderFactory(&encoder_factory_);
1910 EXPECT_TRUE(SetupEngine());
1912 std::vector<cricket::VideoCodec> codecs;
1913 codecs.push_back(kVP8Codec);
1914 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1915 EXPECT_EQ(1, vie_.GetTotalNumExternalEncoderRegistered());
1917 // When we add the first stream (1234), it reuses the default send channel,
1918 // so it doesn't increase the registration count of external encoders.
1919 EXPECT_TRUE(channel_->AddSendStream(
1920 cricket::StreamParams::CreateLegacy(1234)));
1921 EXPECT_EQ(1, vie_.GetTotalNumExternalEncoderRegistered());
1923 // When we add the second stream (2345), it creates a new channel and
1924 // increments the registration count.
1925 EXPECT_TRUE(channel_->AddSendStream(
1926 cricket::StreamParams::CreateLegacy(2345)));
1927 EXPECT_EQ(2, vie_.GetTotalNumExternalEncoderRegistered());
1929 // At this moment the total registration count is two, but only one encoder
1930 // is registered per channel.
1931 int channel_num = vie_.GetLastChannel();
1932 EXPECT_EQ(1, vie_.GetNumExternalEncoderRegistered(channel_num));
1934 // Removing send streams decrements the registration count.
1935 EXPECT_TRUE(channel_->RemoveSendStream(1234));
1936 EXPECT_EQ(1, vie_.GetTotalNumExternalEncoderRegistered());
1938 // When we remove the last send stream, it also destroys the last send
1939 // channel and causes the registration count to drop to zero. It is a little
1940 // weird, but not a bug.
1941 EXPECT_TRUE(channel_->RemoveSendStream(2345));
1942 EXPECT_EQ(0, vie_.GetTotalNumExternalEncoderRegistered());
1945 TEST_F(WebRtcVideoEngineTestFake, DontRegisterEncoderForNonVP8) {
1946 encoder_factory_.AddSupportedVideoCodecType(webrtc::kVideoCodecGeneric,
1948 engine_.SetExternalEncoderFactory(&encoder_factory_);
1949 EXPECT_TRUE(SetupEngine());
1950 int channel_num = vie_.GetLastChannel();
1952 // Note: unlike the SetRecvCodecs, we must set a valid video codec for
1953 // channel_->SetSendCodecs() to succeed.
1954 std::vector<cricket::VideoCodec> codecs;
1955 codecs.push_back(kVP8Codec);
1956 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1958 EXPECT_EQ(0, vie_.GetNumExternalEncoderRegistered(channel_num));
1961 // Test that NACK, PLI and REMB are enabled for external codec.
1962 TEST_F(WebRtcVideoEngineTestFake, ExternalCodecFeedbackParams) {
1963 encoder_factory_.AddSupportedVideoCodecType(webrtc::kVideoCodecGeneric,
1965 engine_.SetExternalEncoderFactory(&encoder_factory_);
1966 encoder_factory_.NotifyCodecsAvailable();
1967 EXPECT_TRUE(SetupEngine());
1969 std::vector<cricket::VideoCodec> codecs(engine_.codecs());
1970 // The external codec will appear at last.
1971 size_t pos = codecs.size() - 1;
1972 EXPECT_EQ("GENERIC", codecs[pos].name);
1973 VerifyCodecFeedbackParams(codecs[pos]);
1976 // Test external codec with be added to the end of the supported codec list.
1977 TEST_F(WebRtcVideoEngineTestFake, ExternalCodecAddedToTheEnd) {
1978 EXPECT_TRUE(SetupEngine());
1980 std::vector<cricket::VideoCodec> codecs(engine_.codecs());
1981 EXPECT_EQ("VP8", codecs[0].name);
1983 encoder_factory_.AddSupportedVideoCodecType(webrtc::kVideoCodecGeneric,
1985 engine_.SetExternalEncoderFactory(&encoder_factory_);
1986 encoder_factory_.NotifyCodecsAvailable();
1988 codecs = engine_.codecs();
1989 cricket::VideoCodec internal_codec = codecs[0];
1990 cricket::VideoCodec external_codec = codecs[codecs.size() - 1];
1991 // The external codec will appear at last.
1992 EXPECT_EQ("GENERIC", external_codec.name);
1993 // The internal codec is preferred.
1994 EXPECT_GE(internal_codec.preference, external_codec.preference);
1997 // Test that external codec with be ignored if it has the same name as one of
1998 // the internal codecs.
1999 TEST_F(WebRtcVideoEngineTestFake, ExternalCodecIgnored) {
2000 EXPECT_TRUE(SetupEngine());
2002 std::vector<cricket::VideoCodec> internal_codecs(engine_.codecs());
2003 EXPECT_EQ("VP8", internal_codecs[0].name);
2005 encoder_factory_.AddSupportedVideoCodecType(webrtc::kVideoCodecVP8, "VP8");
2006 engine_.SetExternalEncoderFactory(&encoder_factory_);
2007 encoder_factory_.NotifyCodecsAvailable();
2009 std::vector<cricket::VideoCodec> codecs = engine_.codecs();
2010 EXPECT_EQ("VP8", codecs[0].name);
2011 EXPECT_EQ(internal_codecs[0].height, codecs[0].height);
2012 EXPECT_EQ(internal_codecs[0].width, codecs[0].width);
2013 // Verify the last codec is not the external codec.
2014 EXPECT_NE("VP8", codecs[codecs.size() - 1].name);
2017 TEST_F(WebRtcVideoEngineTestFake, UpdateEncoderCodecsAfterSetFactory) {
2018 engine_.SetExternalEncoderFactory(&encoder_factory_);
2019 EXPECT_TRUE(SetupEngine());
2020 int channel_num = vie_.GetLastChannel();
2022 encoder_factory_.AddSupportedVideoCodecType(webrtc::kVideoCodecVP8, "VP8");
2023 encoder_factory_.NotifyCodecsAvailable();
2024 std::vector<cricket::VideoCodec> codecs;
2025 codecs.push_back(kVP8Codec);
2026 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
2028 EXPECT_TRUE(channel_->AddSendStream(
2029 cricket::StreamParams::CreateLegacy(kSsrc)));
2031 EXPECT_TRUE(vie_.ExternalEncoderRegistered(channel_num, 100));
2032 EXPECT_EQ(1, vie_.GetNumExternalEncoderRegistered(channel_num));
2034 // Remove stream previously added to free the external encoder instance.
2035 EXPECT_TRUE(channel_->RemoveSendStream(kSsrc));
2038 // Tests that OnReadyToSend will be propagated into ViE.
2039 TEST_F(WebRtcVideoEngineTestFake, OnReadyToSend) {
2040 EXPECT_TRUE(SetupEngine());
2041 int channel_num = vie_.GetLastChannel();
2042 EXPECT_TRUE(vie_.GetIsTransmitting(channel_num));
2044 channel_->OnReadyToSend(false);
2045 EXPECT_FALSE(vie_.GetIsTransmitting(channel_num));
2047 channel_->OnReadyToSend(true);
2048 EXPECT_TRUE(vie_.GetIsTransmitting(channel_num));
2052 TEST_F(WebRtcVideoEngineTestFake, CaptureFrameTimestampToNtpTimestamp) {
2053 EXPECT_TRUE(SetupEngine());
2054 int capture_id = vie_.GetCaptureId(vie_.GetLastChannel());
2057 cricket::VideoCodec codec(kVP8Codec);
2058 std::vector<cricket::VideoCodec> codec_list;
2059 codec_list.push_back(codec);
2060 EXPECT_TRUE(channel_->AddSendStream(
2061 cricket::StreamParams::CreateLegacy(123)));
2062 EXPECT_TRUE(channel_->SetSendCodecs(codec_list));
2063 EXPECT_TRUE(channel_->SetSend(true));
2065 int64 timestamp = time(NULL) * talk_base::kNumNanosecsPerSec;
2066 SendI420ScreencastFrameWithTimestamp(
2067 kVP8Codec.width, kVP8Codec.height, timestamp);
2068 EXPECT_EQ(talk_base::UnixTimestampNanosecsToNtpMillisecs(timestamp),
2069 vie_.GetCaptureLastTimestamp(capture_id));
2071 SendI420ScreencastFrameWithTimestamp(kVP8Codec.width, kVP8Codec.height, 0);
2072 EXPECT_EQ(0, vie_.GetCaptureLastTimestamp(capture_id));
2076 /////////////////////////
2077 // Tests with real ViE //
2078 /////////////////////////
2080 // Tests that we can find codecs by name or id.
2081 TEST_F(WebRtcVideoEngineTest, FindCodec) {
2082 // We should not need to init engine in order to get codecs.
2083 const std::vector<cricket::VideoCodec>& c = engine_.codecs();
2084 EXPECT_EQ(4U, c.size());
2086 cricket::VideoCodec vp8(104, "VP8", 320, 200, 30, 0);
2087 EXPECT_TRUE(engine_.FindCodec(vp8));
2089 cricket::VideoCodec vp8_ci(104, "vp8", 320, 200, 30, 0);
2090 EXPECT_TRUE(engine_.FindCodec(vp8));
2092 cricket::VideoCodec vp8_diff_fr_diff_pref(104, "VP8", 320, 200, 50, 50);
2093 EXPECT_TRUE(engine_.FindCodec(vp8_diff_fr_diff_pref));
2095 cricket::VideoCodec vp8_diff_id(95, "VP8", 320, 200, 30, 0);
2096 EXPECT_FALSE(engine_.FindCodec(vp8_diff_id));
2097 vp8_diff_id.id = 97;
2098 EXPECT_TRUE(engine_.FindCodec(vp8_diff_id));
2100 cricket::VideoCodec vp8_diff_res(104, "VP8", 320, 111, 30, 0);
2101 EXPECT_FALSE(engine_.FindCodec(vp8_diff_res));
2103 // PeerConnection doesn't negotiate the resolution at this point.
2104 // Test that FindCodec can handle the case when width/height is 0.
2105 cricket::VideoCodec vp8_zero_res(104, "VP8", 0, 0, 30, 0);
2106 EXPECT_TRUE(engine_.FindCodec(vp8_zero_res));
2108 cricket::VideoCodec red(101, "RED", 0, 0, 30, 0);
2109 EXPECT_TRUE(engine_.FindCodec(red));
2111 cricket::VideoCodec red_ci(101, "red", 0, 0, 30, 0);
2112 EXPECT_TRUE(engine_.FindCodec(red));
2114 cricket::VideoCodec fec(102, "ULPFEC", 0, 0, 30, 0);
2115 EXPECT_TRUE(engine_.FindCodec(fec));
2117 cricket::VideoCodec fec_ci(102, "ulpfec", 0, 0, 30, 0);
2118 EXPECT_TRUE(engine_.FindCodec(fec));
2120 cricket::VideoCodec rtx(96, "rtx", 0, 0, 30, 0);
2121 rtx.SetParam("apt", kVP8Codec.id);
2122 EXPECT_TRUE(engine_.FindCodec(rtx));
2125 TEST_F(WebRtcVideoEngineTest, RtxCodecHasAptSet) {
2126 std::vector<cricket::VideoCodec>::const_iterator it;
2127 bool apt_checked = false;
2128 for (it = engine_.codecs().begin(); it != engine_.codecs().end(); ++it) {
2129 if (_stricmp(cricket::kRtxCodecName, it->name.c_str()) && it->id != 96) {
2133 EXPECT_TRUE(it->GetParam("apt", &apt));
2134 EXPECT_EQ(100, apt);
2137 EXPECT_TRUE(apt_checked);
2140 TEST_F(WebRtcVideoEngineTest, StartupShutdown) {
2141 EXPECT_TRUE(engine_.Init(talk_base::Thread::Current()));
2142 engine_.Terminate();
2145 TEST_PRE_VIDEOENGINE_INIT(WebRtcVideoEngineTest, ConstrainNewCodec)
2146 TEST_POST_VIDEOENGINE_INIT(WebRtcVideoEngineTest, ConstrainNewCodec)
2148 TEST_PRE_VIDEOENGINE_INIT(WebRtcVideoEngineTest, ConstrainRunningCodec)
2149 TEST_POST_VIDEOENGINE_INIT(WebRtcVideoEngineTest, ConstrainRunningCodec)
2151 // TODO(juberti): Figure out why ViE is munging the COM refcount.
2153 TEST_F(WebRtcVideoEngineTest, DISABLED_CheckCoInitialize) {
2154 Base::CheckCoInitialize();
2158 TEST_F(WebRtcVideoEngineTest, CreateChannel) {
2159 EXPECT_TRUE(engine_.Init(talk_base::Thread::Current()));
2160 cricket::VideoMediaChannel* channel = engine_.CreateChannel(NULL);
2161 EXPECT_TRUE(channel != NULL);
2165 TEST_F(WebRtcVideoMediaChannelTest, SetRecvCodecs) {
2166 std::vector<cricket::VideoCodec> codecs;
2167 codecs.push_back(kVP8Codec);
2168 EXPECT_TRUE(channel_->SetRecvCodecs(codecs));
2170 TEST_F(WebRtcVideoMediaChannelTest, SetRecvCodecsWrongPayloadType) {
2171 std::vector<cricket::VideoCodec> codecs;
2172 codecs.push_back(kVP8Codec);
2174 EXPECT_TRUE(channel_->SetRecvCodecs(codecs));
2176 TEST_F(WebRtcVideoMediaChannelTest, SetRecvCodecsUnsupportedCodec) {
2177 std::vector<cricket::VideoCodec> codecs;
2178 codecs.push_back(kVP8Codec);
2179 codecs.push_back(cricket::VideoCodec(101, "VP1", 640, 400, 30, 0));
2180 EXPECT_FALSE(channel_->SetRecvCodecs(codecs));
2183 TEST_F(WebRtcVideoMediaChannelTest, GetRtpSendTimeExtension) {
2184 // Enable RTP timestamp extension.
2186 std::vector<cricket::RtpHeaderExtension> extensions;
2187 extensions.push_back(cricket::RtpHeaderExtension(
2188 "http://www.webrtc.org/experiments/rtp-hdrext/abs-send-time", id));
2190 // Verify the send extension id.
2191 EXPECT_TRUE(channel_->SetSendRtpHeaderExtensions(extensions));
2192 EXPECT_EQ(id, channel_->GetRtpSendTimeExtnId());
2195 TEST_F(WebRtcVideoMediaChannelTest, SetSend) {
2198 TEST_F(WebRtcVideoMediaChannelTest, SetSendWithoutCodecs) {
2199 Base::SetSendWithoutCodecs();
2201 TEST_F(WebRtcVideoMediaChannelTest, SetSendSetsTransportBufferSizes) {
2202 Base::SetSendSetsTransportBufferSizes();
2205 TEST_F(WebRtcVideoMediaChannelTest, SendAndReceiveVp8Vga) {
2206 SendAndReceive(cricket::VideoCodec(100, "VP8", 640, 400, 30, 0));
2208 TEST_F(WebRtcVideoMediaChannelTest, SendAndReceiveVp8Qvga) {
2209 SendAndReceive(cricket::VideoCodec(100, "VP8", 320, 200, 30, 0));
2211 TEST_F(WebRtcVideoMediaChannelTest, SendAndReceiveH264SvcQqvga) {
2212 SendAndReceive(cricket::VideoCodec(100, "VP8", 160, 100, 30, 0));
2214 TEST_F(WebRtcVideoMediaChannelTest, SendManyResizeOnce) {
2215 SendManyResizeOnce();
2218 TEST_F(WebRtcVideoMediaChannelTest, SendVp8HdAndReceiveAdaptedVp8Vga) {
2219 EXPECT_TRUE(channel_->SetCapturer(kSsrc, NULL));
2220 channel_->UpdateAspectRatio(1280, 720);
2221 video_capturer_.reset(new cricket::FakeVideoCapturer);
2222 const std::vector<cricket::VideoFormat>* formats =
2223 video_capturer_->GetSupportedFormats();
2224 cricket::VideoFormat capture_format_hd = (*formats)[0];
2225 EXPECT_EQ(cricket::CS_RUNNING, video_capturer_->Start(capture_format_hd));
2226 EXPECT_TRUE(channel_->SetCapturer(kSsrc, video_capturer_.get()));
2228 // Capture format HD -> adapt (OnOutputFormatRequest VGA) -> VGA.
2229 cricket::VideoCodec codec(100, "VP8", 1280, 720, 30, 0);
2230 EXPECT_TRUE(SetOneCodec(codec));
2233 EXPECT_TRUE(SetSend(true));
2234 EXPECT_TRUE(channel_->SetRender(true));
2235 EXPECT_EQ(0, renderer_.num_rendered_frames());
2236 EXPECT_TRUE(SendFrame());
2237 EXPECT_FRAME_WAIT(1, codec.width, codec.height, kTimeout);
2240 // TODO(juberti): Fix this test to tolerate missing stats.
2241 TEST_F(WebRtcVideoMediaChannelTest, DISABLED_GetStats) {
2245 // TODO(juberti): Fix this test to tolerate missing stats.
2246 TEST_F(WebRtcVideoMediaChannelTest, DISABLED_GetStatsMultipleRecvStreams) {
2247 Base::GetStatsMultipleRecvStreams();
2250 TEST_F(WebRtcVideoMediaChannelTest, GetStatsMultipleSendStreams) {
2251 Base::GetStatsMultipleSendStreams();
2254 TEST_F(WebRtcVideoMediaChannelTest, SetSendBandwidth) {
2255 Base::SetSendBandwidth();
2257 TEST_F(WebRtcVideoMediaChannelTest, SetSendSsrc) {
2258 Base::SetSendSsrc();
2260 TEST_F(WebRtcVideoMediaChannelTest, SetSendSsrcAfterSetCodecs) {
2261 Base::SetSendSsrcAfterSetCodecs();
2264 TEST_F(WebRtcVideoMediaChannelTest, SetRenderer) {
2265 Base::SetRenderer();
2268 TEST_F(WebRtcVideoMediaChannelTest, AddRemoveRecvStreams) {
2269 Base::AddRemoveRecvStreams();
2272 TEST_F(WebRtcVideoMediaChannelTest, AddRemoveRecvStreamAndRender) {
2273 Base::AddRemoveRecvStreamAndRender();
2276 TEST_F(WebRtcVideoMediaChannelTest, AddRemoveRecvStreamsNoConference) {
2277 Base::AddRemoveRecvStreamsNoConference();
2280 TEST_F(WebRtcVideoMediaChannelTest, AddRemoveSendStreams) {
2281 Base::AddRemoveSendStreams();
2284 TEST_F(WebRtcVideoMediaChannelTest, SimulateConference) {
2285 Base::SimulateConference();
2288 TEST_F(WebRtcVideoMediaChannelTest, AddRemoveCapturer) {
2289 Base::AddRemoveCapturer();
2292 TEST_F(WebRtcVideoMediaChannelTest, RemoveCapturerWithoutAdd) {
2293 Base::RemoveCapturerWithoutAdd();
2296 TEST_F(WebRtcVideoMediaChannelTest, AddRemoveCapturerMultipleSources) {
2297 Base::AddRemoveCapturerMultipleSources();
2300 // This test verifies DSCP settings are properly applied on video media channel.
2301 TEST_F(WebRtcVideoMediaChannelTest, TestSetDscpOptions) {
2302 talk_base::scoped_ptr<cricket::FakeNetworkInterface> network_interface(
2303 new cricket::FakeNetworkInterface);
2304 channel_->SetInterface(network_interface.get());
2305 cricket::VideoOptions options;
2306 options.dscp.Set(true);
2307 EXPECT_TRUE(channel_->SetOptions(options));
2308 EXPECT_EQ(talk_base::DSCP_AF41, network_interface->dscp());
2309 // Verify previous value is not modified if dscp option is not set.
2310 cricket::VideoOptions options1;
2311 EXPECT_TRUE(channel_->SetOptions(options1));
2312 EXPECT_EQ(talk_base::DSCP_AF41, network_interface->dscp());
2313 options.dscp.Set(false);
2314 EXPECT_TRUE(channel_->SetOptions(options));
2315 EXPECT_EQ(talk_base::DSCP_DEFAULT, network_interface->dscp());
2316 channel_->SetInterface(NULL);
2320 TEST_F(WebRtcVideoMediaChannelTest, SetOptionsSucceedsWhenSending) {
2321 cricket::VideoOptions options;
2322 options.conference_mode.Set(true);
2323 EXPECT_TRUE(channel_->SetOptions(options));
2325 // Verify SetOptions returns true on a different options.
2326 cricket::VideoOptions options2;
2327 options2.adapt_input_to_cpu_usage.Set(true);
2328 EXPECT_TRUE(channel_->SetOptions(options2));
2330 // Set send codecs on the channel and start sending.
2331 std::vector<cricket::VideoCodec> codecs;
2332 codecs.push_back(kVP8Codec);
2333 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
2334 EXPECT_TRUE(channel_->SetSend(true));
2336 // Verify SetOptions returns true if channel is already sending.
2337 cricket::VideoOptions options3;
2338 options3.conference_mode.Set(true);
2339 EXPECT_TRUE(channel_->SetOptions(options3));
2342 // Tests empty StreamParams is rejected.
2343 TEST_F(WebRtcVideoMediaChannelTest, RejectEmptyStreamParams) {
2344 Base::RejectEmptyStreamParams();
2348 TEST_F(WebRtcVideoMediaChannelTest, AdaptResolution16x10) {
2349 Base::AdaptResolution16x10();
2352 TEST_F(WebRtcVideoMediaChannelTest, AdaptResolution4x3) {
2353 Base::AdaptResolution4x3();
2356 TEST_F(WebRtcVideoMediaChannelTest, MuteStream) {
2360 TEST_F(WebRtcVideoMediaChannelTest, MultipleSendStreams) {
2361 Base::MultipleSendStreams();
2364 // TODO(juberti): Restore this test once we support sending 0 fps.
2365 TEST_F(WebRtcVideoMediaChannelTest, DISABLED_AdaptDropAllFrames) {
2366 Base::AdaptDropAllFrames();
2368 // TODO(juberti): Understand why we get decode errors on this test.
2369 TEST_F(WebRtcVideoMediaChannelTest, DISABLED_AdaptFramerate) {
2370 Base::AdaptFramerate();
2373 TEST_F(WebRtcVideoMediaChannelTest, SetSendStreamFormat0x0) {
2374 Base::SetSendStreamFormat0x0();
2377 // TODO(zhurunz): Fix the flakey test.
2378 TEST_F(WebRtcVideoMediaChannelTest, DISABLED_SetSendStreamFormat) {
2379 Base::SetSendStreamFormat();
2382 TEST_F(WebRtcVideoMediaChannelTest, TwoStreamsSendAndReceive) {
2383 Base::TwoStreamsSendAndReceive(cricket::VideoCodec(100, "VP8", 640, 400, 30,
2387 TEST_F(WebRtcVideoMediaChannelTest, TwoStreamsReUseFirstStream) {
2388 Base::TwoStreamsReUseFirstStream(cricket::VideoCodec(100, "VP8", 640, 400, 30,
2392 TEST_F(WebRtcVideoMediaChannelTest, DISABLED_TwoStreamsSendAndUnsignalledRecv) {
2393 Base::TwoStreamsSendAndUnsignalledRecv(cricket::VideoCodec(100, "VP8", 640,
2397 TEST_F(WebRtcVideoMediaChannelTest,
2398 TwoStreamsSendAndFailUnsignalledRecv) {
2399 webrtc::Trace::set_level_filter(webrtc::kTraceAll);
2400 Base::TwoStreamsSendAndFailUnsignalledRecv(
2401 cricket::VideoCodec(100, "VP8", 640, 400, 30, 0));
2404 TEST_F(WebRtcVideoMediaChannelTest,
2405 TwoStreamsSendAndFailUnsignalledRecvInOneToOne) {
2406 Base::TwoStreamsSendAndFailUnsignalledRecvInOneToOne(
2407 cricket::VideoCodec(100, "VP8", 640, 400, 30, 0));
2410 TEST_F(WebRtcVideoMediaChannelTest,
2411 TwoStreamsAddAndRemoveUnsignalledRecv) {
2412 Base::TwoStreamsAddAndRemoveUnsignalledRecv(cricket::VideoCodec(100, "VP8",