blob: 86f93142c6007b9800654fa5e258a766d3b7419e [file] [log] [blame]
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001/*
2 * libjingle
3 * Copyright 2004 Google Inc.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright notice,
11 * this list of conditions and the following disclaimer in the documentation
12 * and/or other materials provided with the distribution.
13 * 3. The name of the author may not be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
19 * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
21 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
22 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
23 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
24 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
25 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28#include "talk/base/fakecpumonitor.h"
29#include "talk/base/gunit.h"
30#include "talk/base/logging.h"
31#include "talk/base/scoped_ptr.h"
32#include "talk/base/stream.h"
33#include "talk/media/base/constants.h"
34#include "talk/media/base/fakemediaprocessor.h"
35#include "talk/media/base/fakenetworkinterface.h"
36#include "talk/media/base/fakevideorenderer.h"
37#include "talk/media/base/mediachannel.h"
38#include "talk/media/base/testutils.h"
39#include "talk/media/base/videoengine_unittest.h"
40#include "talk/media/webrtc/fakewebrtcvideocapturemodule.h"
41#include "talk/media/webrtc/fakewebrtcvideoengine.h"
42#include "talk/media/webrtc/fakewebrtcvoiceengine.h"
43#include "talk/media/webrtc/webrtcvideocapturer.h"
44#include "talk/media/webrtc/webrtcvideoengine.h"
45#include "talk/media/webrtc/webrtcvideoframe.h"
46#include "talk/media/webrtc/webrtcvoiceengine.h"
47#include "talk/session/media/mediasession.h"
48#include "webrtc/system_wrappers/interface/trace.h"
49
50// Tests for the WebRtcVideoEngine/VideoChannel code.
51
52static const cricket::VideoCodec kVP8Codec720p(100, "VP8", 1280, 720, 30, 0);
53static const cricket::VideoCodec kVP8Codec360p(100, "VP8", 640, 360, 30, 0);
54static const cricket::VideoCodec kVP8Codec270p(100, "VP8", 480, 270, 30, 0);
55static const cricket::VideoCodec kVP8Codec180p(100, "VP8", 320, 180, 30, 0);
56
57static const cricket::VideoCodec kVP8Codec(100, "VP8", 640, 400, 30, 0);
58static const cricket::VideoCodec kRedCodec(101, "red", 0, 0, 0, 0);
59static const cricket::VideoCodec kUlpFecCodec(102, "ulpfec", 0, 0, 0, 0);
60static const cricket::VideoCodec* const kVideoCodecs[] = {
61 &kVP8Codec,
62 &kRedCodec,
63 &kUlpFecCodec
64};
65
66static const unsigned int kMinBandwidthKbps = 50;
67static const unsigned int kStartBandwidthKbps = 300;
68static const unsigned int kMaxBandwidthKbps = 2000;
69
70static const unsigned int kNumberOfTemporalLayers = 1;
71
72
73class FakeViEWrapper : public cricket::ViEWrapper {
74 public:
75 explicit FakeViEWrapper(cricket::FakeWebRtcVideoEngine* engine)
76 : cricket::ViEWrapper(engine, // base
77 engine, // codec
78 engine, // capture
79 engine, // network
80 engine, // render
81 engine, // rtp
82 engine, // image
83 engine) { // external decoder
84 }
85};
86
87// Test fixture to test WebRtcVideoEngine with a fake webrtc::VideoEngine.
88// Useful for testing failure paths.
wu@webrtc.orgcadf9042013-08-30 21:24:16 +000089class WebRtcVideoEngineTestFake : public testing::Test,
wu@webrtc.orgd64719d2013-08-01 00:00:07 +000090 public sigslot::has_slots<> {
henrike@webrtc.org28e20752013-07-10 00:45:36 +000091 public:
92 WebRtcVideoEngineTestFake()
93 : vie_(kVideoCodecs, ARRAY_SIZE(kVideoCodecs)),
94 cpu_monitor_(new talk_base::FakeCpuMonitor(
95 talk_base::Thread::Current())),
96 engine_(NULL, // cricket::WebRtcVoiceEngine
97 new FakeViEWrapper(&vie_), cpu_monitor_),
98 channel_(NULL),
wu@webrtc.orgd64719d2013-08-01 00:00:07 +000099 voice_channel_(NULL),
100 last_error_(cricket::VideoMediaChannel::ERROR_NONE) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000101 }
102 bool SetupEngine() {
103 bool result = engine_.Init(talk_base::Thread::Current());
104 if (result) {
105 channel_ = engine_.CreateChannel(voice_channel_);
wu@webrtc.orgd64719d2013-08-01 00:00:07 +0000106 channel_->SignalMediaError.connect(this,
107 &WebRtcVideoEngineTestFake::OnMediaError);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000108 result = (channel_ != NULL);
109 }
110 return result;
111 }
wu@webrtc.orgd64719d2013-08-01 00:00:07 +0000112 void OnMediaError(uint32 ssrc, cricket::VideoMediaChannel::Error error) {
113 last_error_ = error;
114 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000115 bool SendI420Frame(int width, int height) {
116 if (NULL == channel_) {
117 return false;
118 }
119 cricket::WebRtcVideoFrame frame;
120 size_t size = width * height * 3 / 2; // I420
121 talk_base::scoped_array<uint8> pixel(new uint8[size]);
122 if (!frame.Init(cricket::FOURCC_I420,
123 width, height, width, height,
124 pixel.get(), size, 1, 1, 0, 0, 0)) {
125 return false;
126 }
127 cricket::FakeVideoCapturer capturer;
128 channel_->SendFrame(&capturer, &frame);
129 return true;
130 }
131 bool SendI420ScreencastFrame(int width, int height) {
132 return SendI420ScreencastFrameWithTimestamp(width, height, 0);
133 }
134 bool SendI420ScreencastFrameWithTimestamp(
135 int width, int height, int64 timestamp) {
136 if (NULL == channel_) {
137 return false;
138 }
139 cricket::WebRtcVideoFrame frame;
140 size_t size = width * height * 3 / 2; // I420
141 talk_base::scoped_array<uint8> pixel(new uint8[size]);
142 if (!frame.Init(cricket::FOURCC_I420,
143 width, height, width, height,
144 pixel.get(), size, 1, 1, 0, timestamp, 0)) {
145 return false;
146 }
147 cricket::FakeVideoCapturer capturer;
148 capturer.SetScreencast(true);
149 channel_->SendFrame(&capturer, &frame);
150 return true;
151 }
152 void VerifyVP8SendCodec(int channel_num,
153 unsigned int width,
154 unsigned int height,
155 unsigned int layers = 0,
156 unsigned int max_bitrate = kMaxBandwidthKbps,
157 unsigned int min_bitrate = kMinBandwidthKbps,
158 unsigned int start_bitrate = kStartBandwidthKbps,
159 unsigned int fps = 30,
160 unsigned int max_quantization = 0
161 ) {
162 webrtc::VideoCodec gcodec;
163 EXPECT_EQ(0, vie_.GetSendCodec(channel_num, gcodec));
164
165 // Video codec properties.
166 EXPECT_EQ(webrtc::kVideoCodecVP8, gcodec.codecType);
167 EXPECT_STREQ("VP8", gcodec.plName);
168 EXPECT_EQ(100, gcodec.plType);
169 EXPECT_EQ(width, gcodec.width);
170 EXPECT_EQ(height, gcodec.height);
171 EXPECT_EQ(talk_base::_min(start_bitrate, max_bitrate), gcodec.startBitrate);
172 EXPECT_EQ(max_bitrate, gcodec.maxBitrate);
173 EXPECT_EQ(min_bitrate, gcodec.minBitrate);
174 EXPECT_EQ(fps, gcodec.maxFramerate);
175 // VP8 specific.
176 EXPECT_FALSE(gcodec.codecSpecific.VP8.pictureLossIndicationOn);
177 EXPECT_FALSE(gcodec.codecSpecific.VP8.feedbackModeOn);
178 EXPECT_EQ(webrtc::kComplexityNormal, gcodec.codecSpecific.VP8.complexity);
179 EXPECT_EQ(webrtc::kResilienceOff, gcodec.codecSpecific.VP8.resilience);
180 EXPECT_EQ(max_quantization, gcodec.qpMax);
181 }
182 virtual void TearDown() {
183 delete channel_;
184 engine_.Terminate();
185 }
186
187 protected:
188 cricket::FakeWebRtcVideoEngine vie_;
189 cricket::FakeWebRtcVideoDecoderFactory decoder_factory_;
190 cricket::FakeWebRtcVideoEncoderFactory encoder_factory_;
191 talk_base::FakeCpuMonitor* cpu_monitor_;
192 cricket::WebRtcVideoEngine engine_;
193 cricket::WebRtcVideoMediaChannel* channel_;
194 cricket::WebRtcVoiceMediaChannel* voice_channel_;
wu@webrtc.orgd64719d2013-08-01 00:00:07 +0000195 cricket::VideoMediaChannel::Error last_error_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000196};
197
198// Test fixtures to test WebRtcVideoEngine with a real webrtc::VideoEngine.
199class WebRtcVideoEngineTest
200 : public VideoEngineTest<cricket::WebRtcVideoEngine> {
201 protected:
202 typedef VideoEngineTest<cricket::WebRtcVideoEngine> Base;
203};
204class WebRtcVideoMediaChannelTest
205 : public VideoMediaChannelTest<
206 cricket::WebRtcVideoEngine, cricket::WebRtcVideoMediaChannel> {
207 protected:
208 typedef VideoMediaChannelTest<cricket::WebRtcVideoEngine,
209 cricket::WebRtcVideoMediaChannel> Base;
210 virtual cricket::VideoCodec DefaultCodec() { return kVP8Codec; }
211 virtual void SetUp() {
212 Base::SetUp();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000213 }
214 virtual void TearDown() {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000215 Base::TearDown();
216 }
217};
218
219/////////////////////////
220// Tests with fake ViE //
221/////////////////////////
222
223// Tests that our stub library "works".
224TEST_F(WebRtcVideoEngineTestFake, StartupShutdown) {
225 EXPECT_FALSE(vie_.IsInited());
226 EXPECT_TRUE(engine_.Init(talk_base::Thread::Current()));
227 EXPECT_TRUE(vie_.IsInited());
228 engine_.Terminate();
229}
230
231// Tests that webrtc logs are logged when they should be.
232TEST_F(WebRtcVideoEngineTest, WebRtcShouldLog) {
233 const char webrtc_log[] = "WebRtcVideoEngineTest.WebRtcShouldLog";
234 EXPECT_TRUE(engine_.Init(talk_base::Thread::Current()));
235 engine_.SetLogging(talk_base::LS_INFO, "");
236 std::string str;
237 talk_base::StringStream stream(str);
238 talk_base::LogMessage::AddLogToStream(&stream, talk_base::LS_INFO);
239 EXPECT_EQ(talk_base::LS_INFO, talk_base::LogMessage::GetLogToStream(&stream));
240 webrtc::Trace::Add(webrtc::kTraceStateInfo, webrtc::kTraceUndefined, 0,
241 webrtc_log);
242 EXPECT_TRUE_WAIT(std::string::npos != str.find(webrtc_log), 10);
243 talk_base::LogMessage::RemoveLogToStream(&stream);
244}
245
246// Tests that webrtc logs are not logged when they should't be.
247TEST_F(WebRtcVideoEngineTest, WebRtcShouldNotLog) {
248 const char webrtc_log[] = "WebRtcVideoEngineTest.WebRtcShouldNotLog";
249 EXPECT_TRUE(engine_.Init(talk_base::Thread::Current()));
250 // WebRTC should never be logged lower than LS_INFO.
251 engine_.SetLogging(talk_base::LS_WARNING, "");
252 std::string str;
253 talk_base::StringStream stream(str);
254 // Make sure that WebRTC is not logged, even at lowest severity
255 talk_base::LogMessage::AddLogToStream(&stream, talk_base::LS_SENSITIVE);
256 EXPECT_EQ(talk_base::LS_SENSITIVE,
257 talk_base::LogMessage::GetLogToStream(&stream));
258 webrtc::Trace::Add(webrtc::kTraceStateInfo, webrtc::kTraceUndefined, 0,
259 webrtc_log);
260 talk_base::Thread::Current()->ProcessMessages(10);
261 EXPECT_EQ(std::string::npos, str.find(webrtc_log));
262 talk_base::LogMessage::RemoveLogToStream(&stream);
263}
264
265// Tests that we can create and destroy a channel.
266TEST_F(WebRtcVideoEngineTestFake, CreateChannel) {
267 EXPECT_TRUE(engine_.Init(talk_base::Thread::Current()));
268 channel_ = engine_.CreateChannel(voice_channel_);
269 EXPECT_TRUE(channel_ != NULL);
270 EXPECT_EQ(1, engine_.GetNumOfChannels());
271 delete channel_;
272 channel_ = NULL;
273 EXPECT_EQ(0, engine_.GetNumOfChannels());
274}
275
276// Tests that we properly handle failures in CreateChannel.
277TEST_F(WebRtcVideoEngineTestFake, CreateChannelFail) {
278 vie_.set_fail_create_channel(true);
279 EXPECT_TRUE(engine_.Init(talk_base::Thread::Current()));
280 channel_ = engine_.CreateChannel(voice_channel_);
281 EXPECT_TRUE(channel_ == NULL);
282}
283
284// Tests that we properly handle failures in AllocateExternalCaptureDevice.
285TEST_F(WebRtcVideoEngineTestFake, AllocateExternalCaptureDeviceFail) {
286 vie_.set_fail_alloc_capturer(true);
287 EXPECT_TRUE(engine_.Init(talk_base::Thread::Current()));
288 channel_ = engine_.CreateChannel(voice_channel_);
289 EXPECT_TRUE(channel_ == NULL);
290}
291
292// Test that we apply our default codecs properly.
293TEST_F(WebRtcVideoEngineTestFake, SetSendCodecs) {
294 EXPECT_TRUE(SetupEngine());
295 int channel_num = vie_.GetLastChannel();
296 std::vector<cricket::VideoCodec> codecs(engine_.codecs());
297 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
298 VerifyVP8SendCodec(channel_num, kVP8Codec.width, kVP8Codec.height);
299 EXPECT_TRUE(vie_.GetHybridNackFecStatus(channel_num));
300 EXPECT_FALSE(vie_.GetNackStatus(channel_num));
301 // TODO(juberti): Check RTCP, PLI, TMMBR.
302}
303
304TEST_F(WebRtcVideoEngineTestFake, SetSendCodecsWithMinMaxBitrate) {
305 EXPECT_TRUE(SetupEngine());
306 int channel_num = vie_.GetLastChannel();
307 std::vector<cricket::VideoCodec> codecs(engine_.codecs());
308 codecs[0].params[cricket::kCodecParamMinBitrate] = "10";
309 codecs[0].params[cricket::kCodecParamMaxBitrate] = "20";
310 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
311
312 VerifyVP8SendCodec(
313 channel_num, kVP8Codec.width, kVP8Codec.height, 0, 20, 10, 20);
314
315 cricket::VideoCodec codec;
316 EXPECT_TRUE(channel_->GetSendCodec(&codec));
317 EXPECT_EQ("10", codec.params[cricket::kCodecParamMinBitrate]);
318 EXPECT_EQ("20", codec.params[cricket::kCodecParamMaxBitrate]);
319}
320
321TEST_F(WebRtcVideoEngineTestFake, SetSendCodecsWithMinMaxBitrateInvalid) {
322 EXPECT_TRUE(SetupEngine());
323 std::vector<cricket::VideoCodec> codecs(engine_.codecs());
324 codecs[0].params[cricket::kCodecParamMinBitrate] = "30";
325 codecs[0].params[cricket::kCodecParamMaxBitrate] = "20";
326 EXPECT_FALSE(channel_->SetSendCodecs(codecs));
327}
328
329TEST_F(WebRtcVideoEngineTestFake, SetSendCodecsWithLargeMinMaxBitrate) {
330 EXPECT_TRUE(SetupEngine());
331 int channel_num = vie_.GetLastChannel();
332 std::vector<cricket::VideoCodec> codecs(engine_.codecs());
333 codecs[0].params[cricket::kCodecParamMinBitrate] = "1000";
334 codecs[0].params[cricket::kCodecParamMaxBitrate] = "2000";
335 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
336
337 VerifyVP8SendCodec(
338 channel_num, kVP8Codec.width, kVP8Codec.height, 0, 2000, 1000,
339 1000);
340}
341
342TEST_F(WebRtcVideoEngineTestFake, SetSendCodecsWithMaxQuantization) {
343 EXPECT_TRUE(SetupEngine());
344 int channel_num = vie_.GetLastChannel();
345 std::vector<cricket::VideoCodec> codecs(engine_.codecs());
346 codecs[0].params[cricket::kCodecParamMaxQuantization] = "21";
347 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
348
349 VerifyVP8SendCodec(
350 channel_num, kVP8Codec.width, kVP8Codec.height, 0, 2000, 50, 300,
351 30, 21);
352
353 cricket::VideoCodec codec;
354 EXPECT_TRUE(channel_->GetSendCodec(&codec));
355 EXPECT_EQ("21", codec.params[cricket::kCodecParamMaxQuantization]);
356}
357
358TEST_F(WebRtcVideoEngineTestFake, SetOptionsWithMaxBitrate) {
359 EXPECT_TRUE(SetupEngine());
360 int channel_num = vie_.GetLastChannel();
361 std::vector<cricket::VideoCodec> codecs(engine_.codecs());
362 codecs[0].params[cricket::kCodecParamMinBitrate] = "10";
363 codecs[0].params[cricket::kCodecParamMaxBitrate] = "20";
364 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
365
366 VerifyVP8SendCodec(
367 channel_num, kVP8Codec.width, kVP8Codec.height, 0, 20, 10, 20);
368
369 // Verify that max bitrate doesn't change after SetOptions().
370 cricket::VideoOptions options;
371 options.video_noise_reduction.Set(true);
372 EXPECT_TRUE(channel_->SetOptions(options));
373 VerifyVP8SendCodec(
374 channel_num, kVP8Codec.width, kVP8Codec.height, 0, 20, 10, 20);
375
376 options.video_noise_reduction.Set(false);
377 options.conference_mode.Set(false);
378 EXPECT_TRUE(channel_->SetOptions(options));
379 VerifyVP8SendCodec(
380 channel_num, kVP8Codec.width, kVP8Codec.height, 0, 20, 10, 20);
381}
382
383TEST_F(WebRtcVideoEngineTestFake, MaxBitrateResetWithConferenceMode) {
384 EXPECT_TRUE(SetupEngine());
385 int channel_num = vie_.GetLastChannel();
386 std::vector<cricket::VideoCodec> codecs(engine_.codecs());
387 codecs[0].params[cricket::kCodecParamMinBitrate] = "10";
388 codecs[0].params[cricket::kCodecParamMaxBitrate] = "20";
389 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
390
391 VerifyVP8SendCodec(
392 channel_num, kVP8Codec.width, kVP8Codec.height, 0, 20, 10, 20);
393
394 cricket::VideoOptions options;
395 options.conference_mode.Set(true);
396 EXPECT_TRUE(channel_->SetOptions(options));
397 options.conference_mode.Set(false);
398 EXPECT_TRUE(channel_->SetOptions(options));
399 VerifyVP8SendCodec(
400 channel_num, kVP8Codec.width, kVP8Codec.height, 0,
401 kMaxBandwidthKbps, 10, 20);
402}
403
404// Verify the current send bitrate is used as start bitrate when reconfiguring
405// the send codec.
406TEST_F(WebRtcVideoEngineTestFake, StartSendBitrate) {
407 EXPECT_TRUE(SetupEngine());
408 EXPECT_TRUE(channel_->AddSendStream(
409 cricket::StreamParams::CreateLegacy(1)));
410 int send_channel = vie_.GetLastChannel();
411 cricket::VideoCodec codec(kVP8Codec);
412 std::vector<cricket::VideoCodec> codec_list;
413 codec_list.push_back(codec);
414 EXPECT_TRUE(channel_->SetSendCodecs(codec_list));
415 const unsigned int kVideoMaxSendBitrateKbps = 2000;
416 const unsigned int kVideoMinSendBitrateKbps = 50;
417 const unsigned int kVideoDefaultStartSendBitrateKbps = 300;
418 VerifyVP8SendCodec(send_channel, kVP8Codec.width, kVP8Codec.height, 0,
419 kVideoMaxSendBitrateKbps, kVideoMinSendBitrateKbps,
420 kVideoDefaultStartSendBitrateKbps);
421 EXPECT_EQ(0, vie_.StartSend(send_channel));
422
423 // Increase the send bitrate and verify it is used as start bitrate.
424 const unsigned int kVideoSendBitrateBps = 768000;
425 vie_.SetSendBitrates(send_channel, kVideoSendBitrateBps, 0, 0);
426 EXPECT_TRUE(channel_->SetSendCodecs(codec_list));
427 VerifyVP8SendCodec(send_channel, kVP8Codec.width, kVP8Codec.height, 0,
428 kVideoMaxSendBitrateKbps, kVideoMinSendBitrateKbps,
429 kVideoSendBitrateBps / 1000);
430
431 // Never set a start bitrate higher than the max bitrate.
432 vie_.SetSendBitrates(send_channel, kVideoMaxSendBitrateKbps + 500, 0, 0);
433 EXPECT_TRUE(channel_->SetSendCodecs(codec_list));
434 VerifyVP8SendCodec(send_channel, kVP8Codec.width, kVP8Codec.height, 0,
435 kVideoMaxSendBitrateKbps, kVideoMinSendBitrateKbps,
436 kVideoDefaultStartSendBitrateKbps);
437
438 // Use the default start bitrate if the send bitrate is lower.
439 vie_.SetSendBitrates(send_channel, kVideoDefaultStartSendBitrateKbps - 50, 0,
440 0);
441 EXPECT_TRUE(channel_->SetSendCodecs(codec_list));
442 VerifyVP8SendCodec(send_channel, kVP8Codec.width, kVP8Codec.height, 0,
443 kVideoMaxSendBitrateKbps, kVideoMinSendBitrateKbps,
444 kVideoDefaultStartSendBitrateKbps);
445}
446
447
448// Test that we constrain send codecs properly.
449TEST_F(WebRtcVideoEngineTestFake, ConstrainSendCodecs) {
450 EXPECT_TRUE(SetupEngine());
451 int channel_num = vie_.GetLastChannel();
452
453 // Set max settings of 640x400x30.
454 EXPECT_TRUE(engine_.SetDefaultEncoderConfig(
455 cricket::VideoEncoderConfig(kVP8Codec)));
456
457 // Send codec format bigger than max setting.
458 cricket::VideoCodec codec(kVP8Codec);
459 codec.width = 1280;
460 codec.height = 800;
461 codec.framerate = 60;
462 std::vector<cricket::VideoCodec> codec_list;
463 codec_list.push_back(codec);
464
465 // Set send codec and verify codec has been constrained.
466 EXPECT_TRUE(channel_->SetSendCodecs(codec_list));
467 VerifyVP8SendCodec(channel_num, kVP8Codec.width, kVP8Codec.height);
468}
469
470// Test that SetSendCodecs rejects bad format.
471TEST_F(WebRtcVideoEngineTestFake, SetSendCodecsRejectBadFormat) {
472 EXPECT_TRUE(SetupEngine());
473 int channel_num = vie_.GetLastChannel();
474
475 // Set w = 0.
476 cricket::VideoCodec codec(kVP8Codec);
477 codec.width = 0;
478 std::vector<cricket::VideoCodec> codec_list;
479 codec_list.push_back(codec);
480
481 // Verify SetSendCodecs failed and send codec is not changed on engine.
482 EXPECT_FALSE(channel_->SetSendCodecs(codec_list));
483 webrtc::VideoCodec gcodec;
484 // Set plType to something other than the value to test against ensuring
485 // that failure will happen if it is not changed.
486 gcodec.plType = 1;
487 EXPECT_EQ(0, vie_.GetSendCodec(channel_num, gcodec));
488 EXPECT_EQ(0, gcodec.plType);
489
490 // Set h = 0.
491 codec_list[0].width = 640;
492 codec_list[0].height = 0;
493
494 // Verify SetSendCodecs failed and send codec is not changed on engine.
495 EXPECT_FALSE(channel_->SetSendCodecs(codec_list));
496 // Set plType to something other than the value to test against ensuring
497 // that failure will happen if it is not changed.
498 gcodec.plType = 1;
499 EXPECT_EQ(0, vie_.GetSendCodec(channel_num, gcodec));
500 EXPECT_EQ(0, gcodec.plType);
501}
502
503// Test that SetSendCodecs rejects bad codec.
504TEST_F(WebRtcVideoEngineTestFake, SetSendCodecsRejectBadCodec) {
505 EXPECT_TRUE(SetupEngine());
506 int channel_num = vie_.GetLastChannel();
507
508 // Set bad codec name.
509 cricket::VideoCodec codec(kVP8Codec);
510 codec.name = "bad";
511 std::vector<cricket::VideoCodec> codec_list;
512 codec_list.push_back(codec);
513
514 // Verify SetSendCodecs failed and send codec is not changed on engine.
515 EXPECT_FALSE(channel_->SetSendCodecs(codec_list));
516 webrtc::VideoCodec gcodec;
517 // Set plType to something other than the value to test against ensuring
518 // that failure will happen if it is not changed.
519 gcodec.plType = 1;
520 EXPECT_EQ(0, vie_.GetSendCodec(channel_num, gcodec));
521 EXPECT_EQ(0, gcodec.plType);
522}
523
524// Test that vie send codec is reset on new video frame size.
525TEST_F(WebRtcVideoEngineTestFake, ResetVieSendCodecOnNewFrameSize) {
526 EXPECT_TRUE(SetupEngine());
527 int channel_num = vie_.GetLastChannel();
528
529 // Set send codec.
530 std::vector<cricket::VideoCodec> codec_list;
531 codec_list.push_back(kVP8Codec);
532 EXPECT_TRUE(channel_->SetSendCodecs(codec_list));
533 EXPECT_TRUE(channel_->AddSendStream(
534 cricket::StreamParams::CreateLegacy(123)));
535 EXPECT_TRUE(channel_->SetSend(true));
536
537 // Capture a smaller frame and verify vie send codec has been reset to
538 // the new size.
539 SendI420Frame(kVP8Codec.width / 2, kVP8Codec.height / 2);
540 VerifyVP8SendCodec(channel_num, kVP8Codec.width / 2, kVP8Codec.height / 2);
541
542 // Capture a frame bigger than send_codec_ and verify vie send codec has been
543 // reset (and clipped) to send_codec_.
544 SendI420Frame(kVP8Codec.width * 2, kVP8Codec.height * 2);
545 VerifyVP8SendCodec(channel_num, kVP8Codec.width, kVP8Codec.height);
546}
547
548// Test that we set our inbound codecs properly.
549TEST_F(WebRtcVideoEngineTestFake, SetRecvCodecs) {
550 EXPECT_TRUE(SetupEngine());
551 int channel_num = vie_.GetLastChannel();
552
553 std::vector<cricket::VideoCodec> codecs;
554 codecs.push_back(kVP8Codec);
555 EXPECT_TRUE(channel_->SetRecvCodecs(codecs));
556
557 webrtc::VideoCodec wcodec;
558 EXPECT_TRUE(engine_.ConvertFromCricketVideoCodec(kVP8Codec, &wcodec));
559 EXPECT_TRUE(vie_.ReceiveCodecRegistered(channel_num, wcodec));
560}
561
562// Test that channel connects and disconnects external capturer correctly.
563TEST_F(WebRtcVideoEngineTestFake, HasExternalCapturer) {
564 EXPECT_TRUE(SetupEngine());
565 int channel_num = vie_.GetLastChannel();
566
567 EXPECT_EQ(1, vie_.GetNumCapturers());
568 int capture_id = vie_.GetCaptureId(channel_num);
569 EXPECT_EQ(channel_num, vie_.GetCaptureChannelId(capture_id));
570
571 // Delete the channel should disconnect the capturer.
572 delete channel_;
573 channel_ = NULL;
574 EXPECT_EQ(0, vie_.GetNumCapturers());
575}
576
577// Test that channel adds and removes renderer correctly.
578TEST_F(WebRtcVideoEngineTestFake, HasRenderer) {
579 EXPECT_TRUE(SetupEngine());
580 int channel_num = vie_.GetLastChannel();
581
582 EXPECT_TRUE(vie_.GetHasRenderer(channel_num));
583 EXPECT_FALSE(vie_.GetRenderStarted(channel_num));
584}
585
586// Test that rtcp is enabled on the channel.
587TEST_F(WebRtcVideoEngineTestFake, RtcpEnabled) {
588 EXPECT_TRUE(SetupEngine());
589 int channel_num = vie_.GetLastChannel();
590 EXPECT_EQ(webrtc::kRtcpCompound_RFC4585, vie_.GetRtcpStatus(channel_num));
591}
592
593// Test that key frame request method is set on the channel.
594TEST_F(WebRtcVideoEngineTestFake, KeyFrameRequestEnabled) {
595 EXPECT_TRUE(SetupEngine());
596 int channel_num = vie_.GetLastChannel();
597 EXPECT_EQ(webrtc::kViEKeyFrameRequestPliRtcp,
598 vie_.GetKeyFrameRequestMethod(channel_num));
599}
600
601// Test that remb receive and send is enabled for the default channel in a 1:1
602// call.
603TEST_F(WebRtcVideoEngineTestFake, RembEnabled) {
604 EXPECT_TRUE(SetupEngine());
605 int channel_num = vie_.GetLastChannel();
606 EXPECT_TRUE(channel_->AddSendStream(
607 cricket::StreamParams::CreateLegacy(1)));
608 EXPECT_TRUE(channel_->SetSendCodecs(engine_.codecs()));
609 EXPECT_TRUE(vie_.GetRembStatusBwPartition(channel_num));
610 EXPECT_TRUE(channel_->SetSend(true));
611 EXPECT_TRUE(vie_.GetRembStatusBwPartition(channel_num));
612 EXPECT_TRUE(vie_.GetRembStatusContribute(channel_num));
613}
614
615// When in conference mode, test that remb is enabled on a receive channel but
616// not for the default channel and that it uses the default channel for sending
617// remb packets.
618TEST_F(WebRtcVideoEngineTestFake, RembEnabledOnReceiveChannels) {
619 EXPECT_TRUE(SetupEngine());
620 int default_channel = vie_.GetLastChannel();
621 cricket::VideoOptions options;
622 options.conference_mode.Set(true);
623 EXPECT_TRUE(channel_->SetOptions(options));
624 EXPECT_TRUE(channel_->AddSendStream(
625 cricket::StreamParams::CreateLegacy(1)));
626 EXPECT_TRUE(channel_->SetSendCodecs(engine_.codecs()));
627 EXPECT_TRUE(vie_.GetRembStatusBwPartition(default_channel));
628 EXPECT_TRUE(vie_.GetRembStatusContribute(default_channel));
629 EXPECT_TRUE(channel_->SetSend(true));
630 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(1)));
631 int new_channel_num = vie_.GetLastChannel();
632 EXPECT_NE(default_channel, new_channel_num);
633
634 EXPECT_TRUE(vie_.GetRembStatusBwPartition(default_channel));
635 EXPECT_TRUE(vie_.GetRembStatusContribute(default_channel));
636 EXPECT_FALSE(vie_.GetRembStatusBwPartition(new_channel_num));
637 EXPECT_TRUE(vie_.GetRembStatusContribute(new_channel_num));
638}
639
640// Test support for RTP timestamp offset header extension.
641TEST_F(WebRtcVideoEngineTestFake, RtpTimestampOffsetHeaderExtensions) {
642 EXPECT_TRUE(SetupEngine());
643 int channel_num = vie_.GetLastChannel();
644 cricket::VideoOptions options;
645 options.conference_mode.Set(true);
646 EXPECT_TRUE(channel_->SetOptions(options));
647
648 // Verify extensions are off by default.
649 EXPECT_EQ(0, vie_.GetSendRtpTimestampOffsetExtensionId(channel_num));
650 EXPECT_EQ(0, vie_.GetReceiveRtpTimestampOffsetExtensionId(channel_num));
651
652 // Enable RTP timestamp extension.
653 const int id = 14;
654 std::vector<cricket::RtpHeaderExtension> extensions;
655 extensions.push_back(cricket::RtpHeaderExtension(
656 "urn:ietf:params:rtp-hdrext:toffset", id));
657
658 // Verify the send extension id.
659 EXPECT_TRUE(channel_->SetSendRtpHeaderExtensions(extensions));
660 EXPECT_EQ(id, vie_.GetSendRtpTimestampOffsetExtensionId(channel_num));
661
662 // Remove the extension id.
663 std::vector<cricket::RtpHeaderExtension> empty_extensions;
664 EXPECT_TRUE(channel_->SetSendRtpHeaderExtensions(empty_extensions));
665 EXPECT_EQ(0, vie_.GetSendRtpTimestampOffsetExtensionId(channel_num));
666
667 // Verify receive extension id.
668 EXPECT_TRUE(channel_->SetRecvRtpHeaderExtensions(extensions));
669 EXPECT_EQ(id, vie_.GetReceiveRtpTimestampOffsetExtensionId(channel_num));
670
671 // Add a new receive stream and verify the extension is set.
672 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(2)));
673 int new_channel_num = vie_.GetLastChannel();
674 EXPECT_NE(channel_num, new_channel_num);
675 EXPECT_EQ(id, vie_.GetReceiveRtpTimestampOffsetExtensionId(new_channel_num));
676
677 // Remove the extension id.
678 EXPECT_TRUE(channel_->SetRecvRtpHeaderExtensions(empty_extensions));
679 EXPECT_EQ(0, vie_.GetReceiveRtpTimestampOffsetExtensionId(channel_num));
680 EXPECT_EQ(0, vie_.GetReceiveRtpTimestampOffsetExtensionId(new_channel_num));
681}
682
683// Test support for absolute send time header extension.
684TEST_F(WebRtcVideoEngineTestFake, AbsoluteSendTimeHeaderExtensions) {
685 EXPECT_TRUE(SetupEngine());
686 int channel_num = vie_.GetLastChannel();
687 cricket::VideoOptions options;
688 options.conference_mode.Set(true);
689 EXPECT_TRUE(channel_->SetOptions(options));
690
691 // Verify extensions are off by default.
692 EXPECT_EQ(0, vie_.GetSendAbsoluteSendTimeExtensionId(channel_num));
693 EXPECT_EQ(0, vie_.GetReceiveAbsoluteSendTimeExtensionId(channel_num));
694
695 // Enable RTP timestamp extension.
696 const int id = 12;
697 std::vector<cricket::RtpHeaderExtension> extensions;
698 extensions.push_back(cricket::RtpHeaderExtension(
699 "http://www.webrtc.org/experiments/rtp-hdrext/abs-send-time", id));
700
701 // Verify the send extension id.
702 EXPECT_TRUE(channel_->SetSendRtpHeaderExtensions(extensions));
703 EXPECT_EQ(id, vie_.GetSendAbsoluteSendTimeExtensionId(channel_num));
704
705 // Remove the extension id.
706 std::vector<cricket::RtpHeaderExtension> empty_extensions;
707 EXPECT_TRUE(channel_->SetSendRtpHeaderExtensions(empty_extensions));
708 EXPECT_EQ(0, vie_.GetSendAbsoluteSendTimeExtensionId(channel_num));
709
710 // Verify receive extension id.
711 EXPECT_TRUE(channel_->SetRecvRtpHeaderExtensions(extensions));
712 EXPECT_EQ(id, vie_.GetReceiveAbsoluteSendTimeExtensionId(channel_num));
713
714 // Add a new receive stream and verify the extension is set.
715 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(2)));
716 int new_channel_num = vie_.GetLastChannel();
717 EXPECT_NE(channel_num, new_channel_num);
718 EXPECT_EQ(id, vie_.GetReceiveAbsoluteSendTimeExtensionId(new_channel_num));
719
720 // Remove the extension id.
721 EXPECT_TRUE(channel_->SetRecvRtpHeaderExtensions(empty_extensions));
722 EXPECT_EQ(0, vie_.GetReceiveAbsoluteSendTimeExtensionId(channel_num));
723 EXPECT_EQ(0, vie_.GetReceiveAbsoluteSendTimeExtensionId(new_channel_num));
724}
725
726TEST_F(WebRtcVideoEngineTestFake, LeakyBucketTest) {
727 EXPECT_TRUE(SetupEngine());
728
729 // Verify this is off by default.
730 EXPECT_TRUE(channel_->AddSendStream(cricket::StreamParams::CreateLegacy(1)));
731 int first_send_channel = vie_.GetLastChannel();
732 EXPECT_FALSE(vie_.GetTransmissionSmoothingStatus(first_send_channel));
733
734 // Enable the experiment and verify.
735 cricket::VideoOptions options;
736 options.conference_mode.Set(true);
737 options.video_leaky_bucket.Set(true);
738 EXPECT_TRUE(channel_->SetOptions(options));
739 EXPECT_TRUE(vie_.GetTransmissionSmoothingStatus(first_send_channel));
740
741 // Add a receive channel and verify leaky bucket isn't enabled.
742 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(2)));
743 int recv_channel_num = vie_.GetLastChannel();
744 EXPECT_NE(first_send_channel, recv_channel_num);
745 EXPECT_FALSE(vie_.GetTransmissionSmoothingStatus(recv_channel_num));
746
747 // Add a new send stream and verify leaky bucket is enabled from start.
748 EXPECT_TRUE(channel_->AddSendStream(cricket::StreamParams::CreateLegacy(3)));
749 int second_send_channel = vie_.GetLastChannel();
750 EXPECT_NE(first_send_channel, second_send_channel);
751 EXPECT_TRUE(vie_.GetTransmissionSmoothingStatus(second_send_channel));
752}
753
754TEST_F(WebRtcVideoEngineTestFake, BufferedModeLatency) {
755 EXPECT_TRUE(SetupEngine());
756
757 // Verify this is off by default.
758 EXPECT_TRUE(channel_->AddSendStream(cricket::StreamParams::CreateLegacy(1)));
759 int first_send_channel = vie_.GetLastChannel();
760 EXPECT_EQ(0, vie_.GetSenderTargetDelay(first_send_channel));
761 EXPECT_EQ(0, vie_.GetReceiverTargetDelay(first_send_channel));
762
763 // Enable the experiment and verify. The default channel will have both
764 // sender and receiver buffered mode enabled.
765 cricket::VideoOptions options;
766 options.conference_mode.Set(true);
767 options.buffered_mode_latency.Set(100);
768 EXPECT_TRUE(channel_->SetOptions(options));
769 EXPECT_EQ(100, vie_.GetSenderTargetDelay(first_send_channel));
770 EXPECT_EQ(100, vie_.GetReceiverTargetDelay(first_send_channel));
771
772 // Add a receive channel and verify sender buffered mode isn't enabled.
773 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(2)));
774 int recv_channel_num = vie_.GetLastChannel();
775 EXPECT_NE(first_send_channel, recv_channel_num);
776 EXPECT_EQ(0, vie_.GetSenderTargetDelay(recv_channel_num));
777 EXPECT_EQ(100, vie_.GetReceiverTargetDelay(recv_channel_num));
778
779 // Add a new send stream and verify sender buffered mode is enabled.
780 EXPECT_TRUE(channel_->AddSendStream(cricket::StreamParams::CreateLegacy(3)));
781 int second_send_channel = vie_.GetLastChannel();
782 EXPECT_NE(first_send_channel, second_send_channel);
783 EXPECT_EQ(100, vie_.GetSenderTargetDelay(second_send_channel));
784 EXPECT_EQ(0, vie_.GetReceiverTargetDelay(second_send_channel));
785
786 // Disable sender buffered mode and verify.
787 options.buffered_mode_latency.Set(cricket::kBufferedModeDisabled);
788 EXPECT_TRUE(channel_->SetOptions(options));
789 EXPECT_EQ(0, vie_.GetSenderTargetDelay(first_send_channel));
790 EXPECT_EQ(0, vie_.GetReceiverTargetDelay(first_send_channel));
791 EXPECT_EQ(0, vie_.GetSenderTargetDelay(second_send_channel));
792 EXPECT_EQ(0, vie_.GetReceiverTargetDelay(second_send_channel));
793 EXPECT_EQ(0, vie_.GetSenderTargetDelay(recv_channel_num));
794 EXPECT_EQ(0, vie_.GetReceiverTargetDelay(recv_channel_num));
795}
796
797TEST_F(WebRtcVideoEngineTestFake, AdditiveVideoOptions) {
798 EXPECT_TRUE(SetupEngine());
799
800 EXPECT_TRUE(channel_->AddSendStream(cricket::StreamParams::CreateLegacy(1)));
801 int first_send_channel = vie_.GetLastChannel();
802 EXPECT_EQ(0, vie_.GetSenderTargetDelay(first_send_channel));
803 EXPECT_EQ(0, vie_.GetReceiverTargetDelay(first_send_channel));
804
805 cricket::VideoOptions options1;
806 options1.buffered_mode_latency.Set(100);
807 EXPECT_TRUE(channel_->SetOptions(options1));
808 EXPECT_EQ(100, vie_.GetSenderTargetDelay(first_send_channel));
809 EXPECT_EQ(100, vie_.GetReceiverTargetDelay(first_send_channel));
810 EXPECT_FALSE(vie_.GetTransmissionSmoothingStatus(first_send_channel));
811
812 cricket::VideoOptions options2;
813 options2.video_leaky_bucket.Set(true);
814 EXPECT_TRUE(channel_->SetOptions(options2));
815 EXPECT_TRUE(vie_.GetTransmissionSmoothingStatus(first_send_channel));
816 // The buffered_mode_latency still takes effect.
817 EXPECT_EQ(100, vie_.GetSenderTargetDelay(first_send_channel));
818 EXPECT_EQ(100, vie_.GetReceiverTargetDelay(first_send_channel));
819
820 options1.buffered_mode_latency.Set(50);
821 EXPECT_TRUE(channel_->SetOptions(options1));
822 EXPECT_EQ(50, vie_.GetSenderTargetDelay(first_send_channel));
823 EXPECT_EQ(50, vie_.GetReceiverTargetDelay(first_send_channel));
824 // The video_leaky_bucket still takes effect.
825 EXPECT_TRUE(vie_.GetTransmissionSmoothingStatus(first_send_channel));
826}
827
828// Test that AddRecvStream doesn't create new channel for 1:1 call.
829TEST_F(WebRtcVideoEngineTestFake, AddRecvStream1On1) {
830 EXPECT_TRUE(SetupEngine());
831 int channel_num = vie_.GetLastChannel();
832 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(1)));
833 EXPECT_EQ(channel_num, vie_.GetLastChannel());
834}
835
836// Test that AddRecvStream doesn't change remb for 1:1 call.
837TEST_F(WebRtcVideoEngineTestFake, NoRembChangeAfterAddRecvStream) {
838 EXPECT_TRUE(SetupEngine());
839 int channel_num = vie_.GetLastChannel();
840 EXPECT_TRUE(channel_->AddSendStream(
841 cricket::StreamParams::CreateLegacy(1)));
842 EXPECT_TRUE(channel_->SetSendCodecs(engine_.codecs()));
843 EXPECT_TRUE(vie_.GetRembStatusBwPartition(channel_num));
844 EXPECT_TRUE(vie_.GetRembStatusContribute(channel_num));
845 EXPECT_TRUE(channel_->SetSend(true));
846 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(1)));
847 EXPECT_TRUE(vie_.GetRembStatusBwPartition(channel_num));
848 EXPECT_TRUE(vie_.GetRembStatusContribute(channel_num));
849}
850
851// Verify default REMB setting and that it can be turned on and off.
852TEST_F(WebRtcVideoEngineTestFake, RembOnOff) {
853 EXPECT_TRUE(SetupEngine());
854 int channel_num = vie_.GetLastChannel();
855 // Verify REMB sending is always off by default.
856 EXPECT_FALSE(vie_.GetRembStatusBwPartition(channel_num));
857
858 // Verify that REMB is turned on when setting default codecs since the
859 // default codecs have REMB enabled.
860 EXPECT_TRUE(channel_->SetSendCodecs(engine_.codecs()));
861 EXPECT_TRUE(vie_.GetRembStatusBwPartition(channel_num));
862
863 // Verify that REMB is turned off when codecs without REMB are set.
864 std::vector<cricket::VideoCodec> codecs = engine_.codecs();
865 // Clearing the codecs' FeedbackParams and setting send codecs should disable
866 // REMB.
867 for (std::vector<cricket::VideoCodec>::iterator iter = codecs.begin();
868 iter != codecs.end(); ++iter) {
869 // Intersecting with empty will clear the FeedbackParams.
870 cricket::FeedbackParams empty_params;
871 iter->feedback_params.Intersect(empty_params);
872 EXPECT_TRUE(iter->feedback_params.params().empty());
873 }
874 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
875 EXPECT_FALSE(vie_.GetRembStatusBwPartition(channel_num));
876}
877
878// Test that nack is enabled on the channel if we don't offer red/fec.
879TEST_F(WebRtcVideoEngineTestFake, NackEnabled) {
880 EXPECT_TRUE(SetupEngine());
881 int channel_num = vie_.GetLastChannel();
882 std::vector<cricket::VideoCodec> codecs(engine_.codecs());
883 codecs.resize(1); // toss out red and ulpfec
884 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
885 EXPECT_TRUE(vie_.GetNackStatus(channel_num));
886}
887
888// Test that we enable hybrid NACK FEC mode.
889TEST_F(WebRtcVideoEngineTestFake, HybridNackFec) {
890 EXPECT_TRUE(SetupEngine());
891 int channel_num = vie_.GetLastChannel();
892 EXPECT_TRUE(channel_->SetRecvCodecs(engine_.codecs()));
893 EXPECT_TRUE(channel_->SetSendCodecs(engine_.codecs()));
894 EXPECT_TRUE(vie_.GetHybridNackFecStatus(channel_num));
895 EXPECT_FALSE(vie_.GetNackStatus(channel_num));
896}
897
898// Test that we enable hybrid NACK FEC mode when calling SetSendCodecs and
899// SetReceiveCodecs in reversed order.
900TEST_F(WebRtcVideoEngineTestFake, HybridNackFecReversedOrder) {
901 EXPECT_TRUE(SetupEngine());
902 int channel_num = vie_.GetLastChannel();
903 EXPECT_TRUE(channel_->SetSendCodecs(engine_.codecs()));
904 EXPECT_TRUE(channel_->SetRecvCodecs(engine_.codecs()));
905 EXPECT_TRUE(vie_.GetHybridNackFecStatus(channel_num));
906 EXPECT_FALSE(vie_.GetNackStatus(channel_num));
907}
908
909// Test NACK vs Hybrid NACK/FEC interop call setup, i.e. only use NACK even if
910// red/fec is offered as receive codec.
911TEST_F(WebRtcVideoEngineTestFake, VideoProtectionInterop) {
912 EXPECT_TRUE(SetupEngine());
913 int channel_num = vie_.GetLastChannel();
914 std::vector<cricket::VideoCodec> recv_codecs(engine_.codecs());
915 std::vector<cricket::VideoCodec> send_codecs(engine_.codecs());
916 // Only add VP8 as send codec.
917 send_codecs.resize(1);
918 EXPECT_TRUE(channel_->SetRecvCodecs(recv_codecs));
919 EXPECT_TRUE(channel_->SetSendCodecs(send_codecs));
920 EXPECT_FALSE(vie_.GetHybridNackFecStatus(channel_num));
921 EXPECT_TRUE(vie_.GetNackStatus(channel_num));
922}
923
924// Test NACK vs Hybrid NACK/FEC interop call setup, i.e. only use NACK even if
925// red/fec is offered as receive codec. Call order reversed compared to
926// VideoProtectionInterop.
927TEST_F(WebRtcVideoEngineTestFake, VideoProtectionInteropReversed) {
928 EXPECT_TRUE(SetupEngine());
929 int channel_num = vie_.GetLastChannel();
930 std::vector<cricket::VideoCodec> recv_codecs(engine_.codecs());
931 std::vector<cricket::VideoCodec> send_codecs(engine_.codecs());
932 // Only add VP8 as send codec.
933 send_codecs.resize(1);
934 EXPECT_TRUE(channel_->SetSendCodecs(send_codecs));
935 EXPECT_TRUE(channel_->SetRecvCodecs(recv_codecs));
936 EXPECT_FALSE(vie_.GetHybridNackFecStatus(channel_num));
937 EXPECT_TRUE(vie_.GetNackStatus(channel_num));
938}
939
940// Test that NACK, not hybrid mode, is enabled in conference mode.
941TEST_F(WebRtcVideoEngineTestFake, HybridNackFecConference) {
942 EXPECT_TRUE(SetupEngine());
943 // Setup the send channel.
944 int send_channel_num = vie_.GetLastChannel();
945 cricket::VideoOptions options;
946 options.conference_mode.Set(true);
947 EXPECT_TRUE(channel_->SetOptions(options));
948 EXPECT_TRUE(channel_->SetRecvCodecs(engine_.codecs()));
949 EXPECT_TRUE(channel_->SetSendCodecs(engine_.codecs()));
950 EXPECT_FALSE(vie_.GetHybridNackFecStatus(send_channel_num));
951 EXPECT_TRUE(vie_.GetNackStatus(send_channel_num));
952 // Add a receive stream.
953 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(1)));
954 int receive_channel_num = vie_.GetLastChannel();
955 EXPECT_FALSE(vie_.GetHybridNackFecStatus(receive_channel_num));
956 EXPECT_TRUE(vie_.GetNackStatus(receive_channel_num));
957}
958
959// Test that when AddRecvStream in conference mode, a new channel is created
960// for receiving. And the new channel's "original channel" is the send channel.
961TEST_F(WebRtcVideoEngineTestFake, AddRemoveRecvStreamConference) {
962 EXPECT_TRUE(SetupEngine());
963 // Setup the send channel.
964 int send_channel_num = vie_.GetLastChannel();
965 cricket::VideoOptions options;
966 options.conference_mode.Set(true);
967 EXPECT_TRUE(channel_->SetOptions(options));
968 // Add a receive stream.
969 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(1)));
970 int receive_channel_num = vie_.GetLastChannel();
971 EXPECT_EQ(send_channel_num, vie_.GetOriginalChannelId(receive_channel_num));
972 EXPECT_TRUE(channel_->RemoveRecvStream(1));
973 EXPECT_FALSE(vie_.IsChannel(receive_channel_num));
974}
975
976// Test that we can create a channel and start/stop rendering out on it.
977TEST_F(WebRtcVideoEngineTestFake, SetRender) {
978 EXPECT_TRUE(SetupEngine());
979 int channel_num = vie_.GetLastChannel();
980
981 // Verify we can start/stop/start/stop rendering.
982 EXPECT_TRUE(channel_->SetRender(true));
983 EXPECT_TRUE(vie_.GetRenderStarted(channel_num));
984 EXPECT_TRUE(channel_->SetRender(false));
985 EXPECT_FALSE(vie_.GetRenderStarted(channel_num));
986 EXPECT_TRUE(channel_->SetRender(true));
987 EXPECT_TRUE(vie_.GetRenderStarted(channel_num));
988 EXPECT_TRUE(channel_->SetRender(false));
989 EXPECT_FALSE(vie_.GetRenderStarted(channel_num));
990}
991
992// Test that we can create a channel and start/stop sending out on it.
993TEST_F(WebRtcVideoEngineTestFake, SetSend) {
994 EXPECT_TRUE(SetupEngine());
995 int channel_num = vie_.GetLastChannel();
996
997 // Set send codecs on the channel.
998 std::vector<cricket::VideoCodec> codecs;
999 codecs.push_back(kVP8Codec);
1000 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1001 EXPECT_TRUE(channel_->AddSendStream(
1002 cricket::StreamParams::CreateLegacy(123)));
1003
1004 // Verify we can start/stop/start/stop sending.
1005 EXPECT_TRUE(channel_->SetSend(true));
1006 EXPECT_TRUE(vie_.GetSend(channel_num));
1007 EXPECT_TRUE(channel_->SetSend(false));
1008 EXPECT_FALSE(vie_.GetSend(channel_num));
1009 EXPECT_TRUE(channel_->SetSend(true));
1010 EXPECT_TRUE(vie_.GetSend(channel_num));
1011 EXPECT_TRUE(channel_->SetSend(false));
1012 EXPECT_FALSE(vie_.GetSend(channel_num));
1013}
1014
1015// Test that we set bandwidth properly when using full auto bandwidth mode.
1016TEST_F(WebRtcVideoEngineTestFake, SetBandwidthAuto) {
1017 EXPECT_TRUE(SetupEngine());
1018 int channel_num = vie_.GetLastChannel();
1019 EXPECT_TRUE(channel_->SetSendCodecs(engine_.codecs()));
1020 EXPECT_TRUE(channel_->SetSendBandwidth(true, cricket::kAutoBandwidth));
1021 VerifyVP8SendCodec(channel_num, kVP8Codec.width, kVP8Codec.height);
1022}
1023
1024// Test that we set bandwidth properly when using auto with upper bound.
1025TEST_F(WebRtcVideoEngineTestFake, SetBandwidthAutoCapped) {
1026 EXPECT_TRUE(SetupEngine());
1027 int channel_num = vie_.GetLastChannel();
1028 EXPECT_TRUE(channel_->SetSendCodecs(engine_.codecs()));
1029 EXPECT_TRUE(channel_->SetSendBandwidth(true, 768000));
1030 VerifyVP8SendCodec(channel_num, kVP8Codec.width, kVP8Codec.height, 0, 768U);
1031}
1032
1033// Test that we set bandwidth properly when using a fixed bandwidth.
1034TEST_F(WebRtcVideoEngineTestFake, SetBandwidthFixed) {
1035 EXPECT_TRUE(SetupEngine());
1036 int channel_num = vie_.GetLastChannel();
1037 EXPECT_TRUE(channel_->SetSendCodecs(engine_.codecs()));
1038 EXPECT_TRUE(channel_->SetSendBandwidth(false, 768000));
1039 VerifyVP8SendCodec(channel_num, kVP8Codec.width, kVP8Codec.height, 0,
1040 768U, 768U, 768U);
1041}
1042
1043// Test that SetSendBandwidth is ignored in conference mode.
1044TEST_F(WebRtcVideoEngineTestFake, SetBandwidthInConference) {
1045 EXPECT_TRUE(SetupEngine());
1046 int channel_num = vie_.GetLastChannel();
1047 cricket::VideoOptions options;
1048 options.conference_mode.Set(true);
1049 EXPECT_TRUE(channel_->SetOptions(options));
1050 EXPECT_TRUE(channel_->SetSendCodecs(engine_.codecs()));
1051 VerifyVP8SendCodec(channel_num, kVP8Codec.width, kVP8Codec.height);
1052
1053 // Set send bandwidth.
1054 EXPECT_TRUE(channel_->SetSendBandwidth(false, 768000));
1055
1056 // Verify bitrate not changed.
1057 webrtc::VideoCodec gcodec;
1058 EXPECT_EQ(0, vie_.GetSendCodec(channel_num, gcodec));
1059 EXPECT_EQ(kMinBandwidthKbps, gcodec.minBitrate);
1060 EXPECT_EQ(kStartBandwidthKbps, gcodec.startBitrate);
1061 EXPECT_EQ(kMaxBandwidthKbps, gcodec.maxBitrate);
1062 EXPECT_NE(768U, gcodec.minBitrate);
1063 EXPECT_NE(768U, gcodec.startBitrate);
1064 EXPECT_NE(768U, gcodec.maxBitrate);
1065}
1066
1067// Test that sending screencast frames doesn't change bitrate.
1068TEST_F(WebRtcVideoEngineTestFake, SetBandwidthScreencast) {
1069 EXPECT_TRUE(SetupEngine());
1070 int channel_num = vie_.GetLastChannel();
1071
1072 // Set send codec.
1073 cricket::VideoCodec codec(kVP8Codec);
1074 std::vector<cricket::VideoCodec> codec_list;
1075 codec_list.push_back(codec);
1076 EXPECT_TRUE(channel_->AddSendStream(
1077 cricket::StreamParams::CreateLegacy(123)));
1078 EXPECT_TRUE(channel_->SetSendCodecs(codec_list));
1079 EXPECT_TRUE(channel_->SetSendBandwidth(false, 111000));
1080 EXPECT_TRUE(channel_->SetSend(true));
1081
1082 SendI420ScreencastFrame(kVP8Codec.width, kVP8Codec.height);
1083 VerifyVP8SendCodec(channel_num, kVP8Codec.width, kVP8Codec.height, 0,
1084 111, 111, 111);
1085}
1086
1087
1088// Test SetSendSsrc.
1089TEST_F(WebRtcVideoEngineTestFake, SetSendSsrcAndCname) {
1090 EXPECT_TRUE(SetupEngine());
1091 int channel_num = vie_.GetLastChannel();
1092
1093 cricket::StreamParams stream;
1094 stream.ssrcs.push_back(1234);
1095 stream.cname = "cname";
1096 channel_->AddSendStream(stream);
1097
1098 unsigned int ssrc = 0;
1099 EXPECT_EQ(0, vie_.GetLocalSSRC(channel_num, ssrc));
1100 EXPECT_EQ(1234U, ssrc);
1101 EXPECT_EQ(1, vie_.GetNumSsrcs(channel_num));
1102
1103 char rtcp_cname[256];
1104 EXPECT_EQ(0, vie_.GetRTCPCName(channel_num, rtcp_cname));
1105 EXPECT_STREQ("cname", rtcp_cname);
1106}
1107
1108
1109// Test that the local SSRC is the same on sending and receiving channels if the
1110// receive channel is created before the send channel.
1111TEST_F(WebRtcVideoEngineTestFake, SetSendSsrcAfterCreatingReceiveChannel) {
1112 EXPECT_TRUE(SetupEngine());
1113
1114 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(1)));
1115 int receive_channel_num = vie_.GetLastChannel();
1116 cricket::StreamParams stream = cricket::StreamParams::CreateLegacy(1234);
1117 EXPECT_TRUE(channel_->AddSendStream(stream));
1118 int send_channel_num = vie_.GetLastChannel();
1119 unsigned int ssrc = 0;
1120 EXPECT_EQ(0, vie_.GetLocalSSRC(send_channel_num, ssrc));
1121 EXPECT_EQ(1234U, ssrc);
1122 EXPECT_EQ(1, vie_.GetNumSsrcs(send_channel_num));
1123 ssrc = 0;
1124 EXPECT_EQ(0, vie_.GetLocalSSRC(receive_channel_num, ssrc));
1125 EXPECT_EQ(1234U, ssrc);
1126 EXPECT_EQ(1, vie_.GetNumSsrcs(receive_channel_num));
1127}
1128
1129
1130// Test SetOptions with denoising flag.
1131TEST_F(WebRtcVideoEngineTestFake, SetOptionsWithDenoising) {
1132 EXPECT_TRUE(SetupEngine());
1133 EXPECT_EQ(1, vie_.GetNumCapturers());
1134 int channel_num = vie_.GetLastChannel();
1135 int capture_id = vie_.GetCaptureId(channel_num);
1136 // Set send codecs on the channel.
1137 std::vector<cricket::VideoCodec> codecs;
1138 codecs.push_back(kVP8Codec);
1139 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1140
1141 // Set options with OPT_VIDEO_NOISE_REDUCTION flag.
1142 cricket::VideoOptions options;
1143 options.video_noise_reduction.Set(true);
1144 EXPECT_TRUE(channel_->SetOptions(options));
1145
1146 // Verify capture has denoising turned on.
1147 webrtc::VideoCodec send_codec;
1148 memset(&send_codec, 0, sizeof(send_codec)); // avoid uninitialized warning
1149 EXPECT_EQ(0, vie_.GetSendCodec(channel_num, send_codec));
1150 EXPECT_TRUE(send_codec.codecSpecific.VP8.denoisingOn);
1151 EXPECT_FALSE(vie_.GetCaptureDenoising(capture_id));
1152
1153 // Set options back to zero.
1154 options.video_noise_reduction.Set(false);
1155 EXPECT_TRUE(channel_->SetOptions(options));
1156
1157 // Verify capture has denoising turned off.
1158 EXPECT_EQ(0, vie_.GetSendCodec(channel_num, send_codec));
1159 EXPECT_FALSE(send_codec.codecSpecific.VP8.denoisingOn);
1160 EXPECT_FALSE(vie_.GetCaptureDenoising(capture_id));
1161}
1162
1163
1164TEST_F(WebRtcVideoEngineTestFake, SendReceiveBitratesStats) {
1165 EXPECT_TRUE(SetupEngine());
1166 cricket::VideoOptions options;
1167 options.conference_mode.Set(true);
1168 EXPECT_TRUE(channel_->SetOptions(options));
1169 EXPECT_TRUE(channel_->AddSendStream(
1170 cricket::StreamParams::CreateLegacy(1)));
1171 int send_channel = vie_.GetLastChannel();
1172 cricket::VideoCodec codec(kVP8Codec720p);
1173 std::vector<cricket::VideoCodec> codec_list;
1174 codec_list.push_back(codec);
1175 EXPECT_TRUE(channel_->SetSendCodecs(codec_list));
1176
1177 EXPECT_TRUE(channel_->AddRecvStream(
1178 cricket::StreamParams::CreateLegacy(2)));
1179 int first_receive_channel = vie_.GetLastChannel();
1180 EXPECT_NE(send_channel, first_receive_channel);
1181 EXPECT_TRUE(channel_->AddRecvStream(
1182 cricket::StreamParams::CreateLegacy(3)));
1183 int second_receive_channel = vie_.GetLastChannel();
1184 EXPECT_NE(first_receive_channel, second_receive_channel);
1185
1186 cricket::VideoMediaInfo info;
1187 EXPECT_TRUE(channel_->GetStats(&info));
1188 ASSERT_EQ(1U, info.bw_estimations.size());
1189 ASSERT_EQ(0, info.bw_estimations[0].actual_enc_bitrate);
1190 ASSERT_EQ(0, info.bw_estimations[0].transmit_bitrate);
1191 ASSERT_EQ(0, info.bw_estimations[0].retransmit_bitrate);
1192 ASSERT_EQ(0, info.bw_estimations[0].available_send_bandwidth);
1193 ASSERT_EQ(0, info.bw_estimations[0].available_recv_bandwidth);
1194 ASSERT_EQ(0, info.bw_estimations[0].target_enc_bitrate);
1195
1196 // Start sending and receiving on one of the channels and verify bitrates.
1197 EXPECT_EQ(0, vie_.StartSend(send_channel));
1198 int send_video_bitrate = 800;
1199 int send_fec_bitrate = 100;
1200 int send_nack_bitrate = 20;
1201 int send_total_bitrate = send_video_bitrate + send_fec_bitrate +
1202 send_nack_bitrate;
1203 int send_bandwidth = 950;
1204 vie_.SetSendBitrates(send_channel, send_video_bitrate, send_fec_bitrate,
1205 send_nack_bitrate);
1206 vie_.SetSendBandwidthEstimate(send_channel, send_bandwidth);
1207
1208 EXPECT_EQ(0, vie_.StartReceive(first_receive_channel));
1209 int first_channel_receive_bandwidth = 600;
1210 vie_.SetReceiveBandwidthEstimate(first_receive_channel,
1211 first_channel_receive_bandwidth);
1212
1213 info.Clear();
1214 EXPECT_TRUE(channel_->GetStats(&info));
1215 ASSERT_EQ(1U, info.bw_estimations.size());
1216 ASSERT_EQ(send_video_bitrate, info.bw_estimations[0].actual_enc_bitrate);
1217 ASSERT_EQ(send_total_bitrate, info.bw_estimations[0].transmit_bitrate);
1218 ASSERT_EQ(send_nack_bitrate, info.bw_estimations[0].retransmit_bitrate);
1219 ASSERT_EQ(send_bandwidth, info.bw_estimations[0].available_send_bandwidth);
1220 ASSERT_EQ(first_channel_receive_bandwidth,
1221 info.bw_estimations[0].available_recv_bandwidth);
1222 ASSERT_EQ(send_video_bitrate, info.bw_estimations[0].target_enc_bitrate);
1223
1224 // Start receiving on the second channel and verify received rate.
1225 EXPECT_EQ(0, vie_.StartReceive(second_receive_channel));
1226 int second_channel_receive_bandwidth = 100;
1227 vie_.SetReceiveBandwidthEstimate(second_receive_channel,
1228 second_channel_receive_bandwidth);
1229
1230 info.Clear();
1231 EXPECT_TRUE(channel_->GetStats(&info));
1232 ASSERT_EQ(1U, info.bw_estimations.size());
1233 ASSERT_EQ(send_video_bitrate, info.bw_estimations[0].actual_enc_bitrate);
1234 ASSERT_EQ(send_total_bitrate, info.bw_estimations[0].transmit_bitrate);
1235 ASSERT_EQ(send_nack_bitrate, info.bw_estimations[0].retransmit_bitrate);
1236 ASSERT_EQ(send_bandwidth, info.bw_estimations[0].available_send_bandwidth);
1237 ASSERT_EQ(first_channel_receive_bandwidth + second_channel_receive_bandwidth,
1238 info.bw_estimations[0].available_recv_bandwidth);
1239 ASSERT_EQ(send_video_bitrate, info.bw_estimations[0].target_enc_bitrate);
1240}
1241
1242TEST_F(WebRtcVideoEngineTestFake, TestSetAdaptInputToCpuUsage) {
1243 EXPECT_TRUE(SetupEngine());
1244 cricket::VideoOptions options_in, options_out;
1245 bool cpu_adapt = false;
1246 channel_->SetOptions(options_in);
1247 EXPECT_TRUE(channel_->GetOptions(&options_out));
1248 EXPECT_FALSE(options_out.adapt_input_to_cpu_usage.Get(&cpu_adapt));
1249 // Set adapt input CPU usage option.
1250 options_in.adapt_input_to_cpu_usage.Set(true);
1251 EXPECT_TRUE(channel_->SetOptions(options_in));
1252 EXPECT_TRUE(channel_->GetOptions(&options_out));
1253 EXPECT_TRUE(options_out.adapt_input_to_cpu_usage.Get(&cpu_adapt));
1254 EXPECT_TRUE(cpu_adapt);
1255}
1256
1257TEST_F(WebRtcVideoEngineTestFake, TestSetCpuThreshold) {
1258 EXPECT_TRUE(SetupEngine());
1259 float low, high;
1260 cricket::VideoOptions options_in, options_out;
1261 // Verify that initial values are set.
1262 EXPECT_TRUE(channel_->GetOptions(&options_out));
1263 EXPECT_TRUE(options_out.system_low_adaptation_threshhold.Get(&low));
1264 EXPECT_EQ(low, 0.65f);
1265 EXPECT_TRUE(options_out.system_high_adaptation_threshhold.Get(&high));
1266 EXPECT_EQ(high, 0.85f);
1267 // Set new CPU threshold values.
1268 options_in.system_low_adaptation_threshhold.Set(0.45f);
1269 options_in.system_high_adaptation_threshhold.Set(0.95f);
1270 EXPECT_TRUE(channel_->SetOptions(options_in));
1271 EXPECT_TRUE(channel_->GetOptions(&options_out));
1272 EXPECT_TRUE(options_out.system_low_adaptation_threshhold.Get(&low));
1273 EXPECT_EQ(low, 0.45f);
1274 EXPECT_TRUE(options_out.system_high_adaptation_threshhold.Get(&high));
1275 EXPECT_EQ(high, 0.95f);
1276}
1277
1278TEST_F(WebRtcVideoEngineTestFake, TestSetInvalidCpuThreshold) {
1279 EXPECT_TRUE(SetupEngine());
1280 float low, high;
1281 cricket::VideoOptions options_in, options_out;
1282 // Valid range is [0, 1].
1283 options_in.system_low_adaptation_threshhold.Set(-1.5f);
1284 options_in.system_high_adaptation_threshhold.Set(1.5f);
1285 EXPECT_TRUE(channel_->SetOptions(options_in));
1286 EXPECT_TRUE(channel_->GetOptions(&options_out));
1287 EXPECT_TRUE(options_out.system_low_adaptation_threshhold.Get(&low));
1288 EXPECT_EQ(low, 0.0f);
1289 EXPECT_TRUE(options_out.system_high_adaptation_threshhold.Get(&high));
1290 EXPECT_EQ(high, 1.0f);
1291}
1292
1293
1294/////////////////////////
1295// Tests with real ViE //
1296/////////////////////////
1297
1298// Tests that we can find codecs by name or id.
1299TEST_F(WebRtcVideoEngineTest, FindCodec) {
1300 // We should not need to init engine in order to get codecs.
1301 const std::vector<cricket::VideoCodec>& c = engine_.codecs();
1302 EXPECT_EQ(3U, c.size());
1303
1304 cricket::VideoCodec vp8(104, "VP8", 320, 200, 30, 0);
1305 EXPECT_TRUE(engine_.FindCodec(vp8));
1306
1307 cricket::VideoCodec vp8_ci(104, "vp8", 320, 200, 30, 0);
1308 EXPECT_TRUE(engine_.FindCodec(vp8));
1309
1310 cricket::VideoCodec vp8_diff_fr_diff_pref(104, "VP8", 320, 200, 50, 50);
1311 EXPECT_TRUE(engine_.FindCodec(vp8_diff_fr_diff_pref));
1312
1313 cricket::VideoCodec vp8_diff_id(95, "VP8", 320, 200, 30, 0);
1314 EXPECT_FALSE(engine_.FindCodec(vp8_diff_id));
1315 vp8_diff_id.id = 97;
1316 EXPECT_TRUE(engine_.FindCodec(vp8_diff_id));
1317
1318 cricket::VideoCodec vp8_diff_res(104, "VP8", 320, 111, 30, 0);
1319 EXPECT_FALSE(engine_.FindCodec(vp8_diff_res));
1320
1321 // PeerConnection doesn't negotiate the resolution at this point.
1322 // Test that FindCodec can handle the case when width/height is 0.
1323 cricket::VideoCodec vp8_zero_res(104, "VP8", 0, 0, 30, 0);
1324 EXPECT_TRUE(engine_.FindCodec(vp8_zero_res));
1325
1326 cricket::VideoCodec red(101, "RED", 0, 0, 30, 0);
1327 EXPECT_TRUE(engine_.FindCodec(red));
1328
1329 cricket::VideoCodec red_ci(101, "red", 0, 0, 30, 0);
1330 EXPECT_TRUE(engine_.FindCodec(red));
1331
1332 cricket::VideoCodec fec(102, "ULPFEC", 0, 0, 30, 0);
1333 EXPECT_TRUE(engine_.FindCodec(fec));
1334
1335 cricket::VideoCodec fec_ci(102, "ulpfec", 0, 0, 30, 0);
1336 EXPECT_TRUE(engine_.FindCodec(fec));
1337}
1338
1339TEST_F(WebRtcVideoEngineTest, StartupShutdown) {
1340 EXPECT_TRUE(engine_.Init(talk_base::Thread::Current()));
1341 engine_.Terminate();
1342}
1343
1344TEST_PRE_VIDEOENGINE_INIT(WebRtcVideoEngineTest, ConstrainNewCodec)
1345TEST_POST_VIDEOENGINE_INIT(WebRtcVideoEngineTest, ConstrainNewCodec)
1346
1347TEST_PRE_VIDEOENGINE_INIT(WebRtcVideoEngineTest, ConstrainRunningCodec)
1348TEST_POST_VIDEOENGINE_INIT(WebRtcVideoEngineTest, ConstrainRunningCodec)
1349
1350// TODO(juberti): Figure out why ViE is munging the COM refcount.
1351#ifdef WIN32
1352TEST_F(WebRtcVideoEngineTest, DISABLED_CheckCoInitialize) {
1353 Base::CheckCoInitialize();
1354}
1355#endif
1356
1357TEST_F(WebRtcVideoEngineTest, CreateChannel) {
1358 EXPECT_TRUE(engine_.Init(talk_base::Thread::Current()));
1359 cricket::VideoMediaChannel* channel = engine_.CreateChannel(NULL);
1360 EXPECT_TRUE(channel != NULL);
1361 delete channel;
1362}
1363
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001364TEST_F(WebRtcVideoMediaChannelTest, SetRecvCodecs) {
1365 std::vector<cricket::VideoCodec> codecs;
1366 codecs.push_back(kVP8Codec);
1367 EXPECT_TRUE(channel_->SetRecvCodecs(codecs));
1368}
1369TEST_F(WebRtcVideoMediaChannelTest, SetRecvCodecsWrongPayloadType) {
1370 std::vector<cricket::VideoCodec> codecs;
1371 codecs.push_back(kVP8Codec);
1372 codecs[0].id = 99;
1373 EXPECT_TRUE(channel_->SetRecvCodecs(codecs));
1374}
1375TEST_F(WebRtcVideoMediaChannelTest, SetRecvCodecsUnsupportedCodec) {
1376 std::vector<cricket::VideoCodec> codecs;
1377 codecs.push_back(kVP8Codec);
1378 codecs.push_back(cricket::VideoCodec(101, "VP1", 640, 400, 30, 0));
1379 EXPECT_FALSE(channel_->SetRecvCodecs(codecs));
1380}
1381
1382TEST_F(WebRtcVideoMediaChannelTest, SetSend) {
1383 Base::SetSend();
1384}
1385TEST_F(WebRtcVideoMediaChannelTest, SetSendWithoutCodecs) {
1386 Base::SetSendWithoutCodecs();
1387}
1388TEST_F(WebRtcVideoMediaChannelTest, SetSendSetsTransportBufferSizes) {
1389 Base::SetSendSetsTransportBufferSizes();
1390}
1391
1392TEST_F(WebRtcVideoMediaChannelTest, SendAndReceiveVp8Vga) {
1393 SendAndReceive(cricket::VideoCodec(100, "VP8", 640, 400, 30, 0));
1394}
1395TEST_F(WebRtcVideoMediaChannelTest, SendAndReceiveVp8Qvga) {
1396 SendAndReceive(cricket::VideoCodec(100, "VP8", 320, 200, 30, 0));
1397}
1398TEST_F(WebRtcVideoMediaChannelTest, SendAndReceiveH264SvcQqvga) {
1399 SendAndReceive(cricket::VideoCodec(100, "VP8", 160, 100, 30, 0));
1400}
1401TEST_F(WebRtcVideoMediaChannelTest, SendManyResizeOnce) {
1402 SendManyResizeOnce();
1403}
1404
1405TEST_F(WebRtcVideoMediaChannelTest, SendVp8HdAndReceiveAdaptedVp8Vga) {
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00001406 EXPECT_TRUE(channel_->SetCapturer(kSsrc, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001407 channel_->UpdateAspectRatio(1280, 720);
1408 video_capturer_.reset(new cricket::FakeVideoCapturer);
1409 const std::vector<cricket::VideoFormat>* formats =
1410 video_capturer_->GetSupportedFormats();
1411 cricket::VideoFormat capture_format_hd = (*formats)[0];
1412 EXPECT_EQ(cricket::CS_RUNNING, video_capturer_->Start(capture_format_hd));
1413 EXPECT_TRUE(channel_->SetCapturer(kSsrc, video_capturer_.get()));
1414
1415 // Capture format HD -> adapt (OnOutputFormatRequest VGA) -> VGA.
1416 cricket::VideoCodec codec(100, "VP8", 1280, 720, 30, 0);
1417 EXPECT_TRUE(SetOneCodec(codec));
1418 codec.width /= 2;
1419 codec.height /= 2;
1420 EXPECT_TRUE(channel_->SetSendStreamFormat(kSsrc, cricket::VideoFormat(
1421 codec.width, codec.height,
1422 cricket::VideoFormat::FpsToInterval(codec.framerate),
1423 cricket::FOURCC_ANY)));
1424 EXPECT_TRUE(SetSend(true));
1425 EXPECT_TRUE(channel_->SetRender(true));
1426 EXPECT_EQ(0, renderer_.num_rendered_frames());
1427 EXPECT_TRUE(SendFrame());
1428 EXPECT_FRAME_WAIT(1, codec.width, codec.height, kTimeout);
1429}
1430
1431// TODO(juberti): Fix this test to tolerate missing stats.
1432TEST_F(WebRtcVideoMediaChannelTest, DISABLED_GetStats) {
1433 Base::GetStats();
1434}
1435
1436// TODO(juberti): Fix this test to tolerate missing stats.
1437TEST_F(WebRtcVideoMediaChannelTest, DISABLED_GetStatsMultipleRecvStreams) {
1438 Base::GetStatsMultipleRecvStreams();
1439}
1440
1441TEST_F(WebRtcVideoMediaChannelTest, GetStatsMultipleSendStreams) {
1442 Base::GetStatsMultipleSendStreams();
1443}
1444
1445TEST_F(WebRtcVideoMediaChannelTest, SetSendBandwidth) {
1446 Base::SetSendBandwidth();
1447}
1448TEST_F(WebRtcVideoMediaChannelTest, SetSendSsrc) {
1449 Base::SetSendSsrc();
1450}
1451TEST_F(WebRtcVideoMediaChannelTest, SetSendSsrcAfterSetCodecs) {
1452 Base::SetSendSsrcAfterSetCodecs();
1453}
1454
1455TEST_F(WebRtcVideoMediaChannelTest, SetRenderer) {
1456 Base::SetRenderer();
1457}
1458
1459TEST_F(WebRtcVideoMediaChannelTest, AddRemoveRecvStreams) {
1460 Base::AddRemoveRecvStreams();
1461}
1462
1463TEST_F(WebRtcVideoMediaChannelTest, AddRemoveRecvStreamAndRender) {
1464 Base::AddRemoveRecvStreamAndRender();
1465}
1466
1467TEST_F(WebRtcVideoMediaChannelTest, AddRemoveRecvStreamsNoConference) {
1468 Base::AddRemoveRecvStreamsNoConference();
1469}
1470
1471TEST_F(WebRtcVideoMediaChannelTest, AddRemoveSendStreams) {
1472 Base::AddRemoveSendStreams();
1473}
1474
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001475TEST_F(WebRtcVideoMediaChannelTest, SimulateConference) {
1476 Base::SimulateConference();
1477}
1478
1479TEST_F(WebRtcVideoMediaChannelTest, AddRemoveCapturer) {
1480 Base::AddRemoveCapturer();
1481}
1482
1483TEST_F(WebRtcVideoMediaChannelTest, RemoveCapturerWithoutAdd) {
1484 Base::RemoveCapturerWithoutAdd();
1485}
1486
1487TEST_F(WebRtcVideoMediaChannelTest, AddRemoveCapturerMultipleSources) {
1488 Base::AddRemoveCapturerMultipleSources();
1489}
1490
1491
1492TEST_F(WebRtcVideoMediaChannelTest, SetOptionsSucceedsWhenSending) {
1493 cricket::VideoOptions options;
1494 options.conference_mode.Set(true);
1495 EXPECT_TRUE(channel_->SetOptions(options));
1496
1497 // Verify SetOptions returns true on a different options.
1498 cricket::VideoOptions options2;
1499 options2.adapt_input_to_cpu_usage.Set(true);
1500 EXPECT_TRUE(channel_->SetOptions(options2));
1501
1502 // Set send codecs on the channel and start sending.
1503 std::vector<cricket::VideoCodec> codecs;
1504 codecs.push_back(kVP8Codec);
1505 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1506 EXPECT_TRUE(channel_->SetSend(true));
1507
1508 // Verify SetOptions returns true if channel is already sending.
1509 cricket::VideoOptions options3;
1510 options3.conference_mode.Set(true);
1511 EXPECT_TRUE(channel_->SetOptions(options3));
1512}
1513
1514// Tests empty StreamParams is rejected.
1515TEST_F(WebRtcVideoMediaChannelTest, RejectEmptyStreamParams) {
1516 Base::RejectEmptyStreamParams();
1517}
1518
1519
1520TEST_F(WebRtcVideoMediaChannelTest, AdaptResolution16x10) {
1521 Base::AdaptResolution16x10();
1522}
1523
1524TEST_F(WebRtcVideoMediaChannelTest, AdaptResolution4x3) {
1525 Base::AdaptResolution4x3();
1526}
1527
1528TEST_F(WebRtcVideoMediaChannelTest, MuteStream) {
1529 Base::MuteStream();
1530}
1531
1532TEST_F(WebRtcVideoMediaChannelTest, MultipleSendStreams) {
1533 Base::MultipleSendStreams();
1534}
1535
1536// TODO(juberti): Restore this test once we support sending 0 fps.
1537TEST_F(WebRtcVideoMediaChannelTest, DISABLED_AdaptDropAllFrames) {
1538 Base::AdaptDropAllFrames();
1539}
1540// TODO(juberti): Understand why we get decode errors on this test.
1541TEST_F(WebRtcVideoMediaChannelTest, DISABLED_AdaptFramerate) {
1542 Base::AdaptFramerate();
1543}
1544
1545TEST_F(WebRtcVideoMediaChannelTest, SetSendStreamFormat0x0) {
1546 Base::SetSendStreamFormat0x0();
1547}
1548
1549// TODO(zhurunz): Fix the flakey test.
1550TEST_F(WebRtcVideoMediaChannelTest, DISABLED_SetSendStreamFormat) {
1551 Base::SetSendStreamFormat();
1552}
1553
1554TEST_F(WebRtcVideoMediaChannelTest, TwoStreamsSendAndReceive) {
1555 Base::TwoStreamsSendAndReceive(cricket::VideoCodec(100, "VP8", 640, 400, 30,
1556 0));
1557}
1558
1559TEST_F(WebRtcVideoMediaChannelTest, TwoStreamsReUseFirstStream) {
1560 Base::TwoStreamsReUseFirstStream(cricket::VideoCodec(100, "VP8", 640, 400, 30,
1561 0));
1562}
1563
1564TEST_F(WebRtcVideoEngineTestFake, ResetCodecOnScreencast) {
1565 EXPECT_TRUE(SetupEngine());
1566 cricket::VideoOptions options;
1567 options.video_noise_reduction.Set(true);
1568 EXPECT_TRUE(channel_->SetOptions(options));
1569
1570 // Set send codec.
1571 cricket::VideoCodec codec(kVP8Codec);
1572 std::vector<cricket::VideoCodec> codec_list;
1573 codec_list.push_back(codec);
1574 EXPECT_TRUE(channel_->AddSendStream(
1575 cricket::StreamParams::CreateLegacy(123)));
1576 EXPECT_TRUE(channel_->SetSendCodecs(codec_list));
1577 EXPECT_TRUE(channel_->SetSend(true));
1578 EXPECT_EQ(1, vie_.num_set_send_codecs());
1579
1580 webrtc::VideoCodec gcodec;
1581 memset(&gcodec, 0, sizeof(gcodec));
1582 int channel_num = vie_.GetLastChannel();
1583 EXPECT_EQ(0, vie_.GetSendCodec(channel_num, gcodec));
1584 EXPECT_TRUE(gcodec.codecSpecific.VP8.denoisingOn);
1585
1586 // Send a screencast frame with the same size.
1587 // Verify that denoising is turned off.
1588 SendI420ScreencastFrame(kVP8Codec.width, kVP8Codec.height);
1589 EXPECT_EQ(2, vie_.num_set_send_codecs());
1590 EXPECT_EQ(0, vie_.GetSendCodec(channel_num, gcodec));
1591 EXPECT_FALSE(gcodec.codecSpecific.VP8.denoisingOn);
1592}
1593
1594
1595TEST_F(WebRtcVideoEngineTestFake, DontRegisterDecoderIfFactoryIsNotGiven) {
1596 engine_.SetExternalDecoderFactory(NULL);
1597 EXPECT_TRUE(SetupEngine());
1598 int channel_num = vie_.GetLastChannel();
1599
1600 std::vector<cricket::VideoCodec> codecs;
1601 codecs.push_back(kVP8Codec);
1602 EXPECT_TRUE(channel_->SetRecvCodecs(codecs));
1603
1604 EXPECT_EQ(0, vie_.GetNumExternalDecoderRegistered(channel_num));
1605}
1606
1607TEST_F(WebRtcVideoEngineTestFake, RegisterDecoderIfFactoryIsGiven) {
1608 decoder_factory_.AddSupportedVideoCodecType(webrtc::kVideoCodecVP8);
1609 engine_.SetExternalDecoderFactory(&decoder_factory_);
1610 EXPECT_TRUE(SetupEngine());
1611 int channel_num = vie_.GetLastChannel();
1612
1613 std::vector<cricket::VideoCodec> codecs;
1614 codecs.push_back(kVP8Codec);
1615 EXPECT_TRUE(channel_->SetRecvCodecs(codecs));
1616
1617 EXPECT_TRUE(vie_.ExternalDecoderRegistered(channel_num, 100));
1618 EXPECT_EQ(1, vie_.GetNumExternalDecoderRegistered(channel_num));
1619}
1620
1621TEST_F(WebRtcVideoEngineTestFake, DontRegisterDecoderMultipleTimes) {
1622 decoder_factory_.AddSupportedVideoCodecType(webrtc::kVideoCodecVP8);
1623 engine_.SetExternalDecoderFactory(&decoder_factory_);
1624 EXPECT_TRUE(SetupEngine());
1625 int channel_num = vie_.GetLastChannel();
1626
1627 std::vector<cricket::VideoCodec> codecs;
1628 codecs.push_back(kVP8Codec);
1629 EXPECT_TRUE(channel_->SetRecvCodecs(codecs));
1630
1631 EXPECT_TRUE(vie_.ExternalDecoderRegistered(channel_num, 100));
1632 EXPECT_EQ(1, vie_.GetNumExternalDecoderRegistered(channel_num));
1633 EXPECT_EQ(1, decoder_factory_.GetNumCreatedDecoders());
1634
1635 EXPECT_TRUE(channel_->SetRecvCodecs(codecs));
1636 EXPECT_EQ(1, vie_.GetNumExternalDecoderRegistered(channel_num));
1637 EXPECT_EQ(1, decoder_factory_.GetNumCreatedDecoders());
1638}
1639
1640TEST_F(WebRtcVideoEngineTestFake, DontRegisterDecoderForNonVP8) {
1641 decoder_factory_.AddSupportedVideoCodecType(webrtc::kVideoCodecVP8);
1642 engine_.SetExternalDecoderFactory(&decoder_factory_);
1643 EXPECT_TRUE(SetupEngine());
1644 int channel_num = vie_.GetLastChannel();
1645
1646 std::vector<cricket::VideoCodec> codecs;
1647 codecs.push_back(kRedCodec);
1648 EXPECT_TRUE(channel_->SetRecvCodecs(codecs));
1649
1650 EXPECT_EQ(0, vie_.GetNumExternalDecoderRegistered(channel_num));
1651}
1652
1653TEST_F(WebRtcVideoEngineTestFake, DontRegisterEncoderIfFactoryIsNotGiven) {
1654 engine_.SetExternalEncoderFactory(NULL);
1655 EXPECT_TRUE(SetupEngine());
1656 int channel_num = vie_.GetLastChannel();
1657
1658 std::vector<cricket::VideoCodec> codecs;
1659 codecs.push_back(kVP8Codec);
1660 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1661
1662 EXPECT_EQ(0, vie_.GetNumExternalEncoderRegistered(channel_num));
1663}
1664
1665TEST_F(WebRtcVideoEngineTestFake, RegisterEncoderIfFactoryIsGiven) {
1666 encoder_factory_.AddSupportedVideoCodecType(webrtc::kVideoCodecVP8, "VP8");
1667 engine_.SetExternalEncoderFactory(&encoder_factory_);
1668 EXPECT_TRUE(SetupEngine());
1669 int channel_num = vie_.GetLastChannel();
1670
1671 std::vector<cricket::VideoCodec> codecs;
1672 codecs.push_back(kVP8Codec);
1673 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1674
1675 EXPECT_TRUE(vie_.ExternalEncoderRegistered(channel_num, 100));
1676 EXPECT_EQ(1, vie_.GetNumExternalEncoderRegistered(channel_num));
1677}
1678
1679TEST_F(WebRtcVideoEngineTestFake, DontRegisterEncoderMultipleTimes) {
1680 encoder_factory_.AddSupportedVideoCodecType(webrtc::kVideoCodecVP8, "VP8");
1681 engine_.SetExternalEncoderFactory(&encoder_factory_);
1682 EXPECT_TRUE(SetupEngine());
1683 int channel_num = vie_.GetLastChannel();
1684
1685 std::vector<cricket::VideoCodec> codecs;
1686 codecs.push_back(kVP8Codec);
1687 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1688
1689 EXPECT_TRUE(vie_.ExternalEncoderRegistered(channel_num, 100));
1690 EXPECT_EQ(1, vie_.GetNumExternalEncoderRegistered(channel_num));
1691 EXPECT_EQ(1, encoder_factory_.GetNumCreatedEncoders());
1692
1693 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1694 EXPECT_EQ(1, vie_.GetNumExternalEncoderRegistered(channel_num));
1695 EXPECT_EQ(1, encoder_factory_.GetNumCreatedEncoders());
1696}
1697
1698TEST_F(WebRtcVideoEngineTestFake, RegisterEncoderWithMultipleSendStreams) {
1699 encoder_factory_.AddSupportedVideoCodecType(webrtc::kVideoCodecVP8, "VP8");
1700 engine_.SetExternalEncoderFactory(&encoder_factory_);
1701 EXPECT_TRUE(SetupEngine());
1702
1703 std::vector<cricket::VideoCodec> codecs;
1704 codecs.push_back(kVP8Codec);
1705 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1706 EXPECT_EQ(1, vie_.GetTotalNumExternalEncoderRegistered());
1707
1708 // When we add the first stream (1234), it reuses the default send channel,
1709 // so it doesn't increase the registration count of external encoders.
1710 EXPECT_TRUE(channel_->AddSendStream(
1711 cricket::StreamParams::CreateLegacy(1234)));
1712 EXPECT_EQ(1, vie_.GetTotalNumExternalEncoderRegistered());
1713
1714 // When we add the second stream (2345), it creates a new channel and
1715 // increments the registration count.
1716 EXPECT_TRUE(channel_->AddSendStream(
1717 cricket::StreamParams::CreateLegacy(2345)));
1718 EXPECT_EQ(2, vie_.GetTotalNumExternalEncoderRegistered());
1719
1720 // At this moment the total registration count is two, but only one encoder
1721 // is registered per channel.
1722 int channel_num = vie_.GetLastChannel();
1723 EXPECT_EQ(1, vie_.GetNumExternalEncoderRegistered(channel_num));
1724
1725 // Removing send streams decrements the registration count.
1726 EXPECT_TRUE(channel_->RemoveSendStream(1234));
1727 EXPECT_EQ(1, vie_.GetTotalNumExternalEncoderRegistered());
1728
1729 // When we remove the last send stream, it also destroys the last send
1730 // channel and causes the registration count to drop to zero. It is a little
1731 // weird, but not a bug.
1732 EXPECT_TRUE(channel_->RemoveSendStream(2345));
1733 EXPECT_EQ(0, vie_.GetTotalNumExternalEncoderRegistered());
1734}
1735
1736TEST_F(WebRtcVideoEngineTestFake, DontRegisterEncoderForNonVP8) {
1737 encoder_factory_.AddSupportedVideoCodecType(webrtc::kVideoCodecGeneric,
1738 "GENERIC");
1739 engine_.SetExternalEncoderFactory(&encoder_factory_);
1740 EXPECT_TRUE(SetupEngine());
1741 int channel_num = vie_.GetLastChannel();
1742
1743 // Note: unlike the SetRecvCodecs, we must set a valid video codec for
1744 // channel_->SetSendCodecs() to succeed.
1745 std::vector<cricket::VideoCodec> codecs;
1746 codecs.push_back(kVP8Codec);
1747 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1748
1749 EXPECT_EQ(0, vie_.GetNumExternalEncoderRegistered(channel_num));
1750}
1751
1752// Test that NACK and REMB are enabled for external codec.
1753TEST_F(WebRtcVideoEngineTestFake, FeedbackParamsForNonVP8) {
1754 encoder_factory_.AddSupportedVideoCodecType(webrtc::kVideoCodecGeneric,
1755 "GENERIC");
1756 engine_.SetExternalEncoderFactory(&encoder_factory_);
1757 encoder_factory_.NotifyCodecsAvailable();
1758 EXPECT_TRUE(SetupEngine());
1759
1760 std::vector<cricket::VideoCodec> codecs(engine_.codecs());
1761 EXPECT_EQ("GENERIC", codecs[0].name);
1762 EXPECT_TRUE(codecs[0].HasFeedbackParam(
1763 cricket::FeedbackParam(cricket::kRtcpFbParamNack,
1764 cricket::kParamValueEmpty)));
1765 EXPECT_TRUE(codecs[0].HasFeedbackParam(
1766 cricket::FeedbackParam(cricket::kRtcpFbParamRemb,
1767 cricket::kParamValueEmpty)));
1768 EXPECT_TRUE(codecs[0].HasFeedbackParam(
1769 cricket::FeedbackParam(cricket::kRtcpFbParamCcm,
1770 cricket::kRtcpFbCcmParamFir)));
1771}
1772
1773TEST_F(WebRtcVideoEngineTestFake, UpdateEncoderCodecsAfterSetFactory) {
1774 engine_.SetExternalEncoderFactory(&encoder_factory_);
1775 EXPECT_TRUE(SetupEngine());
1776 int channel_num = vie_.GetLastChannel();
1777
1778 encoder_factory_.AddSupportedVideoCodecType(webrtc::kVideoCodecVP8, "VP8");
1779 encoder_factory_.NotifyCodecsAvailable();
1780 std::vector<cricket::VideoCodec> codecs;
1781 codecs.push_back(kVP8Codec);
1782 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1783
1784 EXPECT_TRUE(vie_.ExternalEncoderRegistered(channel_num, 100));
1785 EXPECT_EQ(1, vie_.GetNumExternalEncoderRegistered(channel_num));
1786 EXPECT_EQ(1, encoder_factory_.GetNumCreatedEncoders());
1787}
1788
1789// Tests that OnReadyToSend will be propagated into ViE.
1790TEST_F(WebRtcVideoEngineTestFake, OnReadyToSend) {
1791 EXPECT_TRUE(SetupEngine());
1792 int channel_num = vie_.GetLastChannel();
1793 EXPECT_TRUE(vie_.GetIsTransmitting(channel_num));
1794
1795 channel_->OnReadyToSend(false);
1796 EXPECT_FALSE(vie_.GetIsTransmitting(channel_num));
1797
1798 channel_->OnReadyToSend(true);
1799 EXPECT_TRUE(vie_.GetIsTransmitting(channel_num));
1800}
1801
1802#if 0
1803TEST_F(WebRtcVideoEngineTestFake, CaptureFrameTimestampToNtpTimestamp) {
1804 EXPECT_TRUE(SetupEngine());
1805 int capture_id = vie_.GetCaptureId(vie_.GetLastChannel());
1806
1807 // Set send codec.
1808 cricket::VideoCodec codec(kVP8Codec);
1809 std::vector<cricket::VideoCodec> codec_list;
1810 codec_list.push_back(codec);
1811 EXPECT_TRUE(channel_->AddSendStream(
1812 cricket::StreamParams::CreateLegacy(123)));
1813 EXPECT_TRUE(channel_->SetSendCodecs(codec_list));
1814 EXPECT_TRUE(channel_->SetSend(true));
1815
1816 int64 timestamp = time(NULL) * talk_base::kNumNanosecsPerSec;
1817 SendI420ScreencastFrameWithTimestamp(
1818 kVP8Codec.width, kVP8Codec.height, timestamp);
1819 EXPECT_EQ(talk_base::UnixTimestampNanosecsToNtpMillisecs(timestamp),
1820 vie_.GetCaptureLastTimestamp(capture_id));
1821
1822 SendI420ScreencastFrameWithTimestamp(kVP8Codec.width, kVP8Codec.height, 0);
1823 EXPECT_EQ(0, vie_.GetCaptureLastTimestamp(capture_id));
1824}
1825#endif