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