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