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