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