blob: e37bc3c27868dd27fc20f27030cde36fc89809d9 [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
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000659TEST_F(WebRtcVideoEngineTestFake, RecvStreamWithRtx) {
660 EXPECT_TRUE(SetupEngine());
661 int default_channel = vie_.GetLastChannel();
662 cricket::VideoOptions options;
663 options.conference_mode.Set(true);
664 EXPECT_TRUE(channel_->SetOptions(options));
665 EXPECT_TRUE(channel_->AddSendStream(
666 cricket::CreateSimWithRtxStreamParams("cname",
667 MAKE_VECTOR(kSsrcs3),
668 MAKE_VECTOR(kRtxSsrcs3))));
669 EXPECT_TRUE(channel_->SetSendCodecs(engine_.codecs()));
670 EXPECT_TRUE(channel_->SetSend(true));
671 EXPECT_TRUE(channel_->AddRecvStream(
672 cricket::CreateSimWithRtxStreamParams("cname",
673 MAKE_VECTOR(kSsrcs1),
674 MAKE_VECTOR(kRtxSsrc1))));
675 int new_channel_num = vie_.GetLastChannel();
676 EXPECT_NE(default_channel, new_channel_num);
677 EXPECT_EQ(4, vie_.GetRemoteRtxSsrc(new_channel_num));
678}
679
680TEST_F(WebRtcVideoEngineTestFake, RecvStreamNoRtx) {
681 EXPECT_TRUE(SetupEngine());
682 int default_channel = vie_.GetLastChannel();
683 cricket::VideoOptions options;
684 options.conference_mode.Set(true);
685 EXPECT_TRUE(channel_->SetOptions(options));
686 EXPECT_TRUE(channel_->AddSendStream(
687 cricket::CreateSimWithRtxStreamParams("cname",
688 MAKE_VECTOR(kSsrcs3),
689 MAKE_VECTOR(kRtxSsrcs3))));
690 EXPECT_TRUE(channel_->SetSendCodecs(engine_.codecs()));
691 EXPECT_TRUE(channel_->SetSend(true));
692 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(1)));
693 int new_channel_num = vie_.GetLastChannel();
694 EXPECT_NE(default_channel, new_channel_num);
695 EXPECT_EQ(-1, vie_.GetRemoteRtxSsrc(new_channel_num));
696}
697
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000698// Test support for RTP timestamp offset header extension.
699TEST_F(WebRtcVideoEngineTestFake, RtpTimestampOffsetHeaderExtensions) {
700 EXPECT_TRUE(SetupEngine());
701 int channel_num = vie_.GetLastChannel();
702 cricket::VideoOptions options;
703 options.conference_mode.Set(true);
704 EXPECT_TRUE(channel_->SetOptions(options));
705
706 // Verify extensions are off by default.
707 EXPECT_EQ(0, vie_.GetSendRtpTimestampOffsetExtensionId(channel_num));
708 EXPECT_EQ(0, vie_.GetReceiveRtpTimestampOffsetExtensionId(channel_num));
709
710 // Enable RTP timestamp extension.
711 const int id = 14;
712 std::vector<cricket::RtpHeaderExtension> extensions;
713 extensions.push_back(cricket::RtpHeaderExtension(
714 "urn:ietf:params:rtp-hdrext:toffset", id));
715
716 // Verify the send extension id.
717 EXPECT_TRUE(channel_->SetSendRtpHeaderExtensions(extensions));
718 EXPECT_EQ(id, vie_.GetSendRtpTimestampOffsetExtensionId(channel_num));
719
720 // Remove the extension id.
721 std::vector<cricket::RtpHeaderExtension> empty_extensions;
722 EXPECT_TRUE(channel_->SetSendRtpHeaderExtensions(empty_extensions));
723 EXPECT_EQ(0, vie_.GetSendRtpTimestampOffsetExtensionId(channel_num));
724
725 // Verify receive extension id.
726 EXPECT_TRUE(channel_->SetRecvRtpHeaderExtensions(extensions));
727 EXPECT_EQ(id, vie_.GetReceiveRtpTimestampOffsetExtensionId(channel_num));
728
729 // Add a new receive stream and verify the extension is set.
730 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(2)));
731 int new_channel_num = vie_.GetLastChannel();
732 EXPECT_NE(channel_num, new_channel_num);
733 EXPECT_EQ(id, vie_.GetReceiveRtpTimestampOffsetExtensionId(new_channel_num));
734
735 // Remove the extension id.
736 EXPECT_TRUE(channel_->SetRecvRtpHeaderExtensions(empty_extensions));
737 EXPECT_EQ(0, vie_.GetReceiveRtpTimestampOffsetExtensionId(channel_num));
738 EXPECT_EQ(0, vie_.GetReceiveRtpTimestampOffsetExtensionId(new_channel_num));
739}
740
741// Test support for absolute send time header extension.
742TEST_F(WebRtcVideoEngineTestFake, AbsoluteSendTimeHeaderExtensions) {
743 EXPECT_TRUE(SetupEngine());
744 int channel_num = vie_.GetLastChannel();
745 cricket::VideoOptions options;
746 options.conference_mode.Set(true);
747 EXPECT_TRUE(channel_->SetOptions(options));
748
749 // Verify extensions are off by default.
750 EXPECT_EQ(0, vie_.GetSendAbsoluteSendTimeExtensionId(channel_num));
751 EXPECT_EQ(0, vie_.GetReceiveAbsoluteSendTimeExtensionId(channel_num));
752
753 // Enable RTP timestamp extension.
754 const int id = 12;
755 std::vector<cricket::RtpHeaderExtension> extensions;
756 extensions.push_back(cricket::RtpHeaderExtension(
757 "http://www.webrtc.org/experiments/rtp-hdrext/abs-send-time", id));
758
759 // Verify the send extension id.
760 EXPECT_TRUE(channel_->SetSendRtpHeaderExtensions(extensions));
761 EXPECT_EQ(id, vie_.GetSendAbsoluteSendTimeExtensionId(channel_num));
762
763 // Remove the extension id.
764 std::vector<cricket::RtpHeaderExtension> empty_extensions;
765 EXPECT_TRUE(channel_->SetSendRtpHeaderExtensions(empty_extensions));
766 EXPECT_EQ(0, vie_.GetSendAbsoluteSendTimeExtensionId(channel_num));
767
768 // Verify receive extension id.
769 EXPECT_TRUE(channel_->SetRecvRtpHeaderExtensions(extensions));
770 EXPECT_EQ(id, vie_.GetReceiveAbsoluteSendTimeExtensionId(channel_num));
771
772 // Add a new receive stream and verify the extension is set.
773 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(2)));
774 int new_channel_num = vie_.GetLastChannel();
775 EXPECT_NE(channel_num, new_channel_num);
776 EXPECT_EQ(id, vie_.GetReceiveAbsoluteSendTimeExtensionId(new_channel_num));
777
778 // Remove the extension id.
779 EXPECT_TRUE(channel_->SetRecvRtpHeaderExtensions(empty_extensions));
780 EXPECT_EQ(0, vie_.GetReceiveAbsoluteSendTimeExtensionId(channel_num));
781 EXPECT_EQ(0, vie_.GetReceiveAbsoluteSendTimeExtensionId(new_channel_num));
782}
783
784TEST_F(WebRtcVideoEngineTestFake, LeakyBucketTest) {
785 EXPECT_TRUE(SetupEngine());
786
787 // Verify this is off by default.
788 EXPECT_TRUE(channel_->AddSendStream(cricket::StreamParams::CreateLegacy(1)));
789 int first_send_channel = vie_.GetLastChannel();
790 EXPECT_FALSE(vie_.GetTransmissionSmoothingStatus(first_send_channel));
791
792 // Enable the experiment and verify.
793 cricket::VideoOptions options;
794 options.conference_mode.Set(true);
795 options.video_leaky_bucket.Set(true);
796 EXPECT_TRUE(channel_->SetOptions(options));
797 EXPECT_TRUE(vie_.GetTransmissionSmoothingStatus(first_send_channel));
798
799 // Add a receive channel and verify leaky bucket isn't enabled.
800 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(2)));
801 int recv_channel_num = vie_.GetLastChannel();
802 EXPECT_NE(first_send_channel, recv_channel_num);
803 EXPECT_FALSE(vie_.GetTransmissionSmoothingStatus(recv_channel_num));
804
805 // Add a new send stream and verify leaky bucket is enabled from start.
806 EXPECT_TRUE(channel_->AddSendStream(cricket::StreamParams::CreateLegacy(3)));
807 int second_send_channel = vie_.GetLastChannel();
808 EXPECT_NE(first_send_channel, second_send_channel);
809 EXPECT_TRUE(vie_.GetTransmissionSmoothingStatus(second_send_channel));
810}
811
812TEST_F(WebRtcVideoEngineTestFake, BufferedModeLatency) {
813 EXPECT_TRUE(SetupEngine());
814
815 // Verify this is off by default.
816 EXPECT_TRUE(channel_->AddSendStream(cricket::StreamParams::CreateLegacy(1)));
817 int first_send_channel = vie_.GetLastChannel();
818 EXPECT_EQ(0, vie_.GetSenderTargetDelay(first_send_channel));
819 EXPECT_EQ(0, vie_.GetReceiverTargetDelay(first_send_channel));
820
821 // Enable the experiment and verify. The default channel will have both
822 // sender and receiver buffered mode enabled.
823 cricket::VideoOptions options;
824 options.conference_mode.Set(true);
825 options.buffered_mode_latency.Set(100);
826 EXPECT_TRUE(channel_->SetOptions(options));
827 EXPECT_EQ(100, vie_.GetSenderTargetDelay(first_send_channel));
828 EXPECT_EQ(100, vie_.GetReceiverTargetDelay(first_send_channel));
829
830 // Add a receive channel and verify sender buffered mode isn't enabled.
831 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(2)));
832 int recv_channel_num = vie_.GetLastChannel();
833 EXPECT_NE(first_send_channel, recv_channel_num);
834 EXPECT_EQ(0, vie_.GetSenderTargetDelay(recv_channel_num));
835 EXPECT_EQ(100, vie_.GetReceiverTargetDelay(recv_channel_num));
836
837 // Add a new send stream and verify sender buffered mode is enabled.
838 EXPECT_TRUE(channel_->AddSendStream(cricket::StreamParams::CreateLegacy(3)));
839 int second_send_channel = vie_.GetLastChannel();
840 EXPECT_NE(first_send_channel, second_send_channel);
841 EXPECT_EQ(100, vie_.GetSenderTargetDelay(second_send_channel));
842 EXPECT_EQ(0, vie_.GetReceiverTargetDelay(second_send_channel));
843
844 // Disable sender buffered mode and verify.
845 options.buffered_mode_latency.Set(cricket::kBufferedModeDisabled);
846 EXPECT_TRUE(channel_->SetOptions(options));
847 EXPECT_EQ(0, vie_.GetSenderTargetDelay(first_send_channel));
848 EXPECT_EQ(0, vie_.GetReceiverTargetDelay(first_send_channel));
849 EXPECT_EQ(0, vie_.GetSenderTargetDelay(second_send_channel));
850 EXPECT_EQ(0, vie_.GetReceiverTargetDelay(second_send_channel));
851 EXPECT_EQ(0, vie_.GetSenderTargetDelay(recv_channel_num));
852 EXPECT_EQ(0, vie_.GetReceiverTargetDelay(recv_channel_num));
853}
854
855TEST_F(WebRtcVideoEngineTestFake, AdditiveVideoOptions) {
856 EXPECT_TRUE(SetupEngine());
857
858 EXPECT_TRUE(channel_->AddSendStream(cricket::StreamParams::CreateLegacy(1)));
859 int first_send_channel = vie_.GetLastChannel();
860 EXPECT_EQ(0, vie_.GetSenderTargetDelay(first_send_channel));
861 EXPECT_EQ(0, vie_.GetReceiverTargetDelay(first_send_channel));
862
863 cricket::VideoOptions options1;
864 options1.buffered_mode_latency.Set(100);
865 EXPECT_TRUE(channel_->SetOptions(options1));
866 EXPECT_EQ(100, vie_.GetSenderTargetDelay(first_send_channel));
867 EXPECT_EQ(100, vie_.GetReceiverTargetDelay(first_send_channel));
868 EXPECT_FALSE(vie_.GetTransmissionSmoothingStatus(first_send_channel));
869
870 cricket::VideoOptions options2;
871 options2.video_leaky_bucket.Set(true);
872 EXPECT_TRUE(channel_->SetOptions(options2));
873 EXPECT_TRUE(vie_.GetTransmissionSmoothingStatus(first_send_channel));
874 // The buffered_mode_latency still takes effect.
875 EXPECT_EQ(100, vie_.GetSenderTargetDelay(first_send_channel));
876 EXPECT_EQ(100, vie_.GetReceiverTargetDelay(first_send_channel));
877
878 options1.buffered_mode_latency.Set(50);
879 EXPECT_TRUE(channel_->SetOptions(options1));
880 EXPECT_EQ(50, vie_.GetSenderTargetDelay(first_send_channel));
881 EXPECT_EQ(50, vie_.GetReceiverTargetDelay(first_send_channel));
882 // The video_leaky_bucket still takes effect.
883 EXPECT_TRUE(vie_.GetTransmissionSmoothingStatus(first_send_channel));
884}
885
886// Test that AddRecvStream doesn't create new channel for 1:1 call.
887TEST_F(WebRtcVideoEngineTestFake, AddRecvStream1On1) {
888 EXPECT_TRUE(SetupEngine());
889 int channel_num = vie_.GetLastChannel();
890 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(1)));
891 EXPECT_EQ(channel_num, vie_.GetLastChannel());
892}
893
894// Test that AddRecvStream doesn't change remb for 1:1 call.
895TEST_F(WebRtcVideoEngineTestFake, NoRembChangeAfterAddRecvStream) {
896 EXPECT_TRUE(SetupEngine());
897 int channel_num = vie_.GetLastChannel();
898 EXPECT_TRUE(channel_->AddSendStream(
899 cricket::StreamParams::CreateLegacy(1)));
900 EXPECT_TRUE(channel_->SetSendCodecs(engine_.codecs()));
901 EXPECT_TRUE(vie_.GetRembStatusBwPartition(channel_num));
902 EXPECT_TRUE(vie_.GetRembStatusContribute(channel_num));
903 EXPECT_TRUE(channel_->SetSend(true));
904 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(1)));
905 EXPECT_TRUE(vie_.GetRembStatusBwPartition(channel_num));
906 EXPECT_TRUE(vie_.GetRembStatusContribute(channel_num));
907}
908
909// Verify default REMB setting and that it can be turned on and off.
910TEST_F(WebRtcVideoEngineTestFake, RembOnOff) {
911 EXPECT_TRUE(SetupEngine());
912 int channel_num = vie_.GetLastChannel();
913 // Verify REMB sending is always off by default.
914 EXPECT_FALSE(vie_.GetRembStatusBwPartition(channel_num));
915
916 // Verify that REMB is turned on when setting default codecs since the
917 // default codecs have REMB enabled.
918 EXPECT_TRUE(channel_->SetSendCodecs(engine_.codecs()));
919 EXPECT_TRUE(vie_.GetRembStatusBwPartition(channel_num));
920
921 // Verify that REMB is turned off when codecs without REMB are set.
922 std::vector<cricket::VideoCodec> codecs = engine_.codecs();
923 // Clearing the codecs' FeedbackParams and setting send codecs should disable
924 // REMB.
925 for (std::vector<cricket::VideoCodec>::iterator iter = codecs.begin();
926 iter != codecs.end(); ++iter) {
927 // Intersecting with empty will clear the FeedbackParams.
928 cricket::FeedbackParams empty_params;
929 iter->feedback_params.Intersect(empty_params);
930 EXPECT_TRUE(iter->feedback_params.params().empty());
931 }
932 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
933 EXPECT_FALSE(vie_.GetRembStatusBwPartition(channel_num));
934}
935
936// Test that nack is enabled on the channel if we don't offer red/fec.
937TEST_F(WebRtcVideoEngineTestFake, NackEnabled) {
938 EXPECT_TRUE(SetupEngine());
939 int channel_num = vie_.GetLastChannel();
940 std::vector<cricket::VideoCodec> codecs(engine_.codecs());
941 codecs.resize(1); // toss out red and ulpfec
942 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
943 EXPECT_TRUE(vie_.GetNackStatus(channel_num));
944}
945
946// Test that we enable hybrid NACK FEC mode.
947TEST_F(WebRtcVideoEngineTestFake, HybridNackFec) {
948 EXPECT_TRUE(SetupEngine());
949 int channel_num = vie_.GetLastChannel();
950 EXPECT_TRUE(channel_->SetRecvCodecs(engine_.codecs()));
951 EXPECT_TRUE(channel_->SetSendCodecs(engine_.codecs()));
952 EXPECT_TRUE(vie_.GetHybridNackFecStatus(channel_num));
953 EXPECT_FALSE(vie_.GetNackStatus(channel_num));
954}
955
956// Test that we enable hybrid NACK FEC mode when calling SetSendCodecs and
957// SetReceiveCodecs in reversed order.
958TEST_F(WebRtcVideoEngineTestFake, HybridNackFecReversedOrder) {
959 EXPECT_TRUE(SetupEngine());
960 int channel_num = vie_.GetLastChannel();
961 EXPECT_TRUE(channel_->SetSendCodecs(engine_.codecs()));
962 EXPECT_TRUE(channel_->SetRecvCodecs(engine_.codecs()));
963 EXPECT_TRUE(vie_.GetHybridNackFecStatus(channel_num));
964 EXPECT_FALSE(vie_.GetNackStatus(channel_num));
965}
966
967// Test NACK vs Hybrid NACK/FEC interop call setup, i.e. only use NACK even if
968// red/fec is offered as receive codec.
969TEST_F(WebRtcVideoEngineTestFake, VideoProtectionInterop) {
970 EXPECT_TRUE(SetupEngine());
971 int channel_num = vie_.GetLastChannel();
972 std::vector<cricket::VideoCodec> recv_codecs(engine_.codecs());
973 std::vector<cricket::VideoCodec> send_codecs(engine_.codecs());
974 // Only add VP8 as send codec.
975 send_codecs.resize(1);
976 EXPECT_TRUE(channel_->SetRecvCodecs(recv_codecs));
977 EXPECT_TRUE(channel_->SetSendCodecs(send_codecs));
978 EXPECT_FALSE(vie_.GetHybridNackFecStatus(channel_num));
979 EXPECT_TRUE(vie_.GetNackStatus(channel_num));
980}
981
982// Test NACK vs Hybrid NACK/FEC interop call setup, i.e. only use NACK even if
983// red/fec is offered as receive codec. Call order reversed compared to
984// VideoProtectionInterop.
985TEST_F(WebRtcVideoEngineTestFake, VideoProtectionInteropReversed) {
986 EXPECT_TRUE(SetupEngine());
987 int channel_num = vie_.GetLastChannel();
988 std::vector<cricket::VideoCodec> recv_codecs(engine_.codecs());
989 std::vector<cricket::VideoCodec> send_codecs(engine_.codecs());
990 // Only add VP8 as send codec.
991 send_codecs.resize(1);
992 EXPECT_TRUE(channel_->SetSendCodecs(send_codecs));
993 EXPECT_TRUE(channel_->SetRecvCodecs(recv_codecs));
994 EXPECT_FALSE(vie_.GetHybridNackFecStatus(channel_num));
995 EXPECT_TRUE(vie_.GetNackStatus(channel_num));
996}
997
998// Test that NACK, not hybrid mode, is enabled in conference mode.
999TEST_F(WebRtcVideoEngineTestFake, HybridNackFecConference) {
1000 EXPECT_TRUE(SetupEngine());
1001 // Setup the send channel.
1002 int send_channel_num = vie_.GetLastChannel();
1003 cricket::VideoOptions options;
1004 options.conference_mode.Set(true);
1005 EXPECT_TRUE(channel_->SetOptions(options));
1006 EXPECT_TRUE(channel_->SetRecvCodecs(engine_.codecs()));
1007 EXPECT_TRUE(channel_->SetSendCodecs(engine_.codecs()));
1008 EXPECT_FALSE(vie_.GetHybridNackFecStatus(send_channel_num));
1009 EXPECT_TRUE(vie_.GetNackStatus(send_channel_num));
1010 // Add a receive stream.
1011 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(1)));
1012 int receive_channel_num = vie_.GetLastChannel();
1013 EXPECT_FALSE(vie_.GetHybridNackFecStatus(receive_channel_num));
1014 EXPECT_TRUE(vie_.GetNackStatus(receive_channel_num));
1015}
1016
1017// Test that when AddRecvStream in conference mode, a new channel is created
1018// for receiving. And the new channel's "original channel" is the send channel.
1019TEST_F(WebRtcVideoEngineTestFake, AddRemoveRecvStreamConference) {
1020 EXPECT_TRUE(SetupEngine());
1021 // Setup the send channel.
1022 int send_channel_num = vie_.GetLastChannel();
1023 cricket::VideoOptions options;
1024 options.conference_mode.Set(true);
1025 EXPECT_TRUE(channel_->SetOptions(options));
1026 // Add a receive stream.
1027 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(1)));
1028 int receive_channel_num = vie_.GetLastChannel();
1029 EXPECT_EQ(send_channel_num, vie_.GetOriginalChannelId(receive_channel_num));
1030 EXPECT_TRUE(channel_->RemoveRecvStream(1));
1031 EXPECT_FALSE(vie_.IsChannel(receive_channel_num));
1032}
1033
1034// Test that we can create a channel and start/stop rendering out on it.
1035TEST_F(WebRtcVideoEngineTestFake, SetRender) {
1036 EXPECT_TRUE(SetupEngine());
1037 int channel_num = vie_.GetLastChannel();
1038
1039 // Verify we can start/stop/start/stop rendering.
1040 EXPECT_TRUE(channel_->SetRender(true));
1041 EXPECT_TRUE(vie_.GetRenderStarted(channel_num));
1042 EXPECT_TRUE(channel_->SetRender(false));
1043 EXPECT_FALSE(vie_.GetRenderStarted(channel_num));
1044 EXPECT_TRUE(channel_->SetRender(true));
1045 EXPECT_TRUE(vie_.GetRenderStarted(channel_num));
1046 EXPECT_TRUE(channel_->SetRender(false));
1047 EXPECT_FALSE(vie_.GetRenderStarted(channel_num));
1048}
1049
1050// Test that we can create a channel and start/stop sending out on it.
1051TEST_F(WebRtcVideoEngineTestFake, SetSend) {
1052 EXPECT_TRUE(SetupEngine());
1053 int channel_num = vie_.GetLastChannel();
1054
1055 // Set send codecs on the channel.
1056 std::vector<cricket::VideoCodec> codecs;
1057 codecs.push_back(kVP8Codec);
1058 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1059 EXPECT_TRUE(channel_->AddSendStream(
1060 cricket::StreamParams::CreateLegacy(123)));
1061
1062 // Verify we can start/stop/start/stop sending.
1063 EXPECT_TRUE(channel_->SetSend(true));
1064 EXPECT_TRUE(vie_.GetSend(channel_num));
1065 EXPECT_TRUE(channel_->SetSend(false));
1066 EXPECT_FALSE(vie_.GetSend(channel_num));
1067 EXPECT_TRUE(channel_->SetSend(true));
1068 EXPECT_TRUE(vie_.GetSend(channel_num));
1069 EXPECT_TRUE(channel_->SetSend(false));
1070 EXPECT_FALSE(vie_.GetSend(channel_num));
1071}
1072
1073// Test that we set bandwidth properly when using full auto bandwidth mode.
1074TEST_F(WebRtcVideoEngineTestFake, SetBandwidthAuto) {
1075 EXPECT_TRUE(SetupEngine());
1076 int channel_num = vie_.GetLastChannel();
1077 EXPECT_TRUE(channel_->SetSendCodecs(engine_.codecs()));
1078 EXPECT_TRUE(channel_->SetSendBandwidth(true, cricket::kAutoBandwidth));
1079 VerifyVP8SendCodec(channel_num, kVP8Codec.width, kVP8Codec.height);
1080}
1081
1082// Test that we set bandwidth properly when using auto with upper bound.
1083TEST_F(WebRtcVideoEngineTestFake, SetBandwidthAutoCapped) {
1084 EXPECT_TRUE(SetupEngine());
1085 int channel_num = vie_.GetLastChannel();
1086 EXPECT_TRUE(channel_->SetSendCodecs(engine_.codecs()));
1087 EXPECT_TRUE(channel_->SetSendBandwidth(true, 768000));
1088 VerifyVP8SendCodec(channel_num, kVP8Codec.width, kVP8Codec.height, 0, 768U);
1089}
1090
1091// Test that we set bandwidth properly when using a fixed bandwidth.
1092TEST_F(WebRtcVideoEngineTestFake, SetBandwidthFixed) {
1093 EXPECT_TRUE(SetupEngine());
1094 int channel_num = vie_.GetLastChannel();
1095 EXPECT_TRUE(channel_->SetSendCodecs(engine_.codecs()));
1096 EXPECT_TRUE(channel_->SetSendBandwidth(false, 768000));
1097 VerifyVP8SendCodec(channel_num, kVP8Codec.width, kVP8Codec.height, 0,
1098 768U, 768U, 768U);
1099}
1100
1101// Test that SetSendBandwidth is ignored in conference mode.
1102TEST_F(WebRtcVideoEngineTestFake, SetBandwidthInConference) {
1103 EXPECT_TRUE(SetupEngine());
1104 int channel_num = vie_.GetLastChannel();
1105 cricket::VideoOptions options;
1106 options.conference_mode.Set(true);
1107 EXPECT_TRUE(channel_->SetOptions(options));
1108 EXPECT_TRUE(channel_->SetSendCodecs(engine_.codecs()));
1109 VerifyVP8SendCodec(channel_num, kVP8Codec.width, kVP8Codec.height);
1110
1111 // Set send bandwidth.
1112 EXPECT_TRUE(channel_->SetSendBandwidth(false, 768000));
1113
1114 // Verify bitrate not changed.
1115 webrtc::VideoCodec gcodec;
1116 EXPECT_EQ(0, vie_.GetSendCodec(channel_num, gcodec));
1117 EXPECT_EQ(kMinBandwidthKbps, gcodec.minBitrate);
1118 EXPECT_EQ(kStartBandwidthKbps, gcodec.startBitrate);
1119 EXPECT_EQ(kMaxBandwidthKbps, gcodec.maxBitrate);
1120 EXPECT_NE(768U, gcodec.minBitrate);
1121 EXPECT_NE(768U, gcodec.startBitrate);
1122 EXPECT_NE(768U, gcodec.maxBitrate);
1123}
1124
1125// Test that sending screencast frames doesn't change bitrate.
1126TEST_F(WebRtcVideoEngineTestFake, SetBandwidthScreencast) {
1127 EXPECT_TRUE(SetupEngine());
1128 int channel_num = vie_.GetLastChannel();
1129
1130 // Set send codec.
1131 cricket::VideoCodec codec(kVP8Codec);
1132 std::vector<cricket::VideoCodec> codec_list;
1133 codec_list.push_back(codec);
1134 EXPECT_TRUE(channel_->AddSendStream(
1135 cricket::StreamParams::CreateLegacy(123)));
1136 EXPECT_TRUE(channel_->SetSendCodecs(codec_list));
1137 EXPECT_TRUE(channel_->SetSendBandwidth(false, 111000));
1138 EXPECT_TRUE(channel_->SetSend(true));
1139
1140 SendI420ScreencastFrame(kVP8Codec.width, kVP8Codec.height);
1141 VerifyVP8SendCodec(channel_num, kVP8Codec.width, kVP8Codec.height, 0,
1142 111, 111, 111);
1143}
1144
1145
1146// Test SetSendSsrc.
1147TEST_F(WebRtcVideoEngineTestFake, SetSendSsrcAndCname) {
1148 EXPECT_TRUE(SetupEngine());
1149 int channel_num = vie_.GetLastChannel();
1150
1151 cricket::StreamParams stream;
1152 stream.ssrcs.push_back(1234);
1153 stream.cname = "cname";
1154 channel_->AddSendStream(stream);
1155
1156 unsigned int ssrc = 0;
1157 EXPECT_EQ(0, vie_.GetLocalSSRC(channel_num, ssrc));
1158 EXPECT_EQ(1234U, ssrc);
1159 EXPECT_EQ(1, vie_.GetNumSsrcs(channel_num));
1160
1161 char rtcp_cname[256];
1162 EXPECT_EQ(0, vie_.GetRTCPCName(channel_num, rtcp_cname));
1163 EXPECT_STREQ("cname", rtcp_cname);
1164}
1165
1166
1167// Test that the local SSRC is the same on sending and receiving channels if the
1168// receive channel is created before the send channel.
1169TEST_F(WebRtcVideoEngineTestFake, SetSendSsrcAfterCreatingReceiveChannel) {
1170 EXPECT_TRUE(SetupEngine());
1171
1172 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(1)));
1173 int receive_channel_num = vie_.GetLastChannel();
1174 cricket::StreamParams stream = cricket::StreamParams::CreateLegacy(1234);
1175 EXPECT_TRUE(channel_->AddSendStream(stream));
1176 int send_channel_num = vie_.GetLastChannel();
1177 unsigned int ssrc = 0;
1178 EXPECT_EQ(0, vie_.GetLocalSSRC(send_channel_num, ssrc));
1179 EXPECT_EQ(1234U, ssrc);
1180 EXPECT_EQ(1, vie_.GetNumSsrcs(send_channel_num));
1181 ssrc = 0;
1182 EXPECT_EQ(0, vie_.GetLocalSSRC(receive_channel_num, ssrc));
1183 EXPECT_EQ(1234U, ssrc);
1184 EXPECT_EQ(1, vie_.GetNumSsrcs(receive_channel_num));
1185}
1186
1187
1188// Test SetOptions with denoising flag.
1189TEST_F(WebRtcVideoEngineTestFake, SetOptionsWithDenoising) {
1190 EXPECT_TRUE(SetupEngine());
1191 EXPECT_EQ(1, vie_.GetNumCapturers());
1192 int channel_num = vie_.GetLastChannel();
1193 int capture_id = vie_.GetCaptureId(channel_num);
1194 // Set send codecs on the channel.
1195 std::vector<cricket::VideoCodec> codecs;
1196 codecs.push_back(kVP8Codec);
1197 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1198
1199 // Set options with OPT_VIDEO_NOISE_REDUCTION flag.
1200 cricket::VideoOptions options;
1201 options.video_noise_reduction.Set(true);
1202 EXPECT_TRUE(channel_->SetOptions(options));
1203
1204 // Verify capture has denoising turned on.
1205 webrtc::VideoCodec send_codec;
1206 memset(&send_codec, 0, sizeof(send_codec)); // avoid uninitialized warning
1207 EXPECT_EQ(0, vie_.GetSendCodec(channel_num, send_codec));
1208 EXPECT_TRUE(send_codec.codecSpecific.VP8.denoisingOn);
1209 EXPECT_FALSE(vie_.GetCaptureDenoising(capture_id));
1210
1211 // Set options back to zero.
1212 options.video_noise_reduction.Set(false);
1213 EXPECT_TRUE(channel_->SetOptions(options));
1214
1215 // Verify capture has denoising turned off.
1216 EXPECT_EQ(0, vie_.GetSendCodec(channel_num, send_codec));
1217 EXPECT_FALSE(send_codec.codecSpecific.VP8.denoisingOn);
1218 EXPECT_FALSE(vie_.GetCaptureDenoising(capture_id));
1219}
1220
1221
wu@webrtc.org97077a32013-10-25 21:18:33 +00001222// Disabled since its flaky: b/11288120
1223TEST_F(WebRtcVideoEngineTestFake, DISABLED_SendReceiveBitratesStats) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001224 EXPECT_TRUE(SetupEngine());
1225 cricket::VideoOptions options;
1226 options.conference_mode.Set(true);
1227 EXPECT_TRUE(channel_->SetOptions(options));
1228 EXPECT_TRUE(channel_->AddSendStream(
1229 cricket::StreamParams::CreateLegacy(1)));
1230 int send_channel = vie_.GetLastChannel();
1231 cricket::VideoCodec codec(kVP8Codec720p);
1232 std::vector<cricket::VideoCodec> codec_list;
1233 codec_list.push_back(codec);
1234 EXPECT_TRUE(channel_->SetSendCodecs(codec_list));
1235
1236 EXPECT_TRUE(channel_->AddRecvStream(
1237 cricket::StreamParams::CreateLegacy(2)));
1238 int first_receive_channel = vie_.GetLastChannel();
1239 EXPECT_NE(send_channel, first_receive_channel);
1240 EXPECT_TRUE(channel_->AddRecvStream(
1241 cricket::StreamParams::CreateLegacy(3)));
1242 int second_receive_channel = vie_.GetLastChannel();
1243 EXPECT_NE(first_receive_channel, second_receive_channel);
1244
1245 cricket::VideoMediaInfo info;
1246 EXPECT_TRUE(channel_->GetStats(&info));
1247 ASSERT_EQ(1U, info.bw_estimations.size());
1248 ASSERT_EQ(0, info.bw_estimations[0].actual_enc_bitrate);
1249 ASSERT_EQ(0, info.bw_estimations[0].transmit_bitrate);
1250 ASSERT_EQ(0, info.bw_estimations[0].retransmit_bitrate);
1251 ASSERT_EQ(0, info.bw_estimations[0].available_send_bandwidth);
1252 ASSERT_EQ(0, info.bw_estimations[0].available_recv_bandwidth);
1253 ASSERT_EQ(0, info.bw_estimations[0].target_enc_bitrate);
1254
1255 // Start sending and receiving on one of the channels and verify bitrates.
1256 EXPECT_EQ(0, vie_.StartSend(send_channel));
1257 int send_video_bitrate = 800;
1258 int send_fec_bitrate = 100;
1259 int send_nack_bitrate = 20;
1260 int send_total_bitrate = send_video_bitrate + send_fec_bitrate +
1261 send_nack_bitrate;
1262 int send_bandwidth = 950;
1263 vie_.SetSendBitrates(send_channel, send_video_bitrate, send_fec_bitrate,
1264 send_nack_bitrate);
1265 vie_.SetSendBandwidthEstimate(send_channel, send_bandwidth);
1266
1267 EXPECT_EQ(0, vie_.StartReceive(first_receive_channel));
1268 int first_channel_receive_bandwidth = 600;
1269 vie_.SetReceiveBandwidthEstimate(first_receive_channel,
1270 first_channel_receive_bandwidth);
1271
1272 info.Clear();
1273 EXPECT_TRUE(channel_->GetStats(&info));
1274 ASSERT_EQ(1U, info.bw_estimations.size());
1275 ASSERT_EQ(send_video_bitrate, info.bw_estimations[0].actual_enc_bitrate);
1276 ASSERT_EQ(send_total_bitrate, info.bw_estimations[0].transmit_bitrate);
1277 ASSERT_EQ(send_nack_bitrate, info.bw_estimations[0].retransmit_bitrate);
1278 ASSERT_EQ(send_bandwidth, info.bw_estimations[0].available_send_bandwidth);
1279 ASSERT_EQ(first_channel_receive_bandwidth,
1280 info.bw_estimations[0].available_recv_bandwidth);
1281 ASSERT_EQ(send_video_bitrate, info.bw_estimations[0].target_enc_bitrate);
1282
1283 // Start receiving on the second channel and verify received rate.
1284 EXPECT_EQ(0, vie_.StartReceive(second_receive_channel));
1285 int second_channel_receive_bandwidth = 100;
1286 vie_.SetReceiveBandwidthEstimate(second_receive_channel,
1287 second_channel_receive_bandwidth);
1288
1289 info.Clear();
1290 EXPECT_TRUE(channel_->GetStats(&info));
1291 ASSERT_EQ(1U, info.bw_estimations.size());
1292 ASSERT_EQ(send_video_bitrate, info.bw_estimations[0].actual_enc_bitrate);
1293 ASSERT_EQ(send_total_bitrate, info.bw_estimations[0].transmit_bitrate);
1294 ASSERT_EQ(send_nack_bitrate, info.bw_estimations[0].retransmit_bitrate);
1295 ASSERT_EQ(send_bandwidth, info.bw_estimations[0].available_send_bandwidth);
1296 ASSERT_EQ(first_channel_receive_bandwidth + second_channel_receive_bandwidth,
1297 info.bw_estimations[0].available_recv_bandwidth);
1298 ASSERT_EQ(send_video_bitrate, info.bw_estimations[0].target_enc_bitrate);
1299}
1300
1301TEST_F(WebRtcVideoEngineTestFake, TestSetAdaptInputToCpuUsage) {
1302 EXPECT_TRUE(SetupEngine());
1303 cricket::VideoOptions options_in, options_out;
1304 bool cpu_adapt = false;
1305 channel_->SetOptions(options_in);
1306 EXPECT_TRUE(channel_->GetOptions(&options_out));
1307 EXPECT_FALSE(options_out.adapt_input_to_cpu_usage.Get(&cpu_adapt));
1308 // Set adapt input CPU usage option.
1309 options_in.adapt_input_to_cpu_usage.Set(true);
1310 EXPECT_TRUE(channel_->SetOptions(options_in));
1311 EXPECT_TRUE(channel_->GetOptions(&options_out));
1312 EXPECT_TRUE(options_out.adapt_input_to_cpu_usage.Get(&cpu_adapt));
1313 EXPECT_TRUE(cpu_adapt);
1314}
1315
1316TEST_F(WebRtcVideoEngineTestFake, TestSetCpuThreshold) {
1317 EXPECT_TRUE(SetupEngine());
1318 float low, high;
1319 cricket::VideoOptions options_in, options_out;
1320 // Verify that initial values are set.
1321 EXPECT_TRUE(channel_->GetOptions(&options_out));
1322 EXPECT_TRUE(options_out.system_low_adaptation_threshhold.Get(&low));
1323 EXPECT_EQ(low, 0.65f);
1324 EXPECT_TRUE(options_out.system_high_adaptation_threshhold.Get(&high));
1325 EXPECT_EQ(high, 0.85f);
1326 // Set new CPU threshold values.
1327 options_in.system_low_adaptation_threshhold.Set(0.45f);
1328 options_in.system_high_adaptation_threshhold.Set(0.95f);
1329 EXPECT_TRUE(channel_->SetOptions(options_in));
1330 EXPECT_TRUE(channel_->GetOptions(&options_out));
1331 EXPECT_TRUE(options_out.system_low_adaptation_threshhold.Get(&low));
1332 EXPECT_EQ(low, 0.45f);
1333 EXPECT_TRUE(options_out.system_high_adaptation_threshhold.Get(&high));
1334 EXPECT_EQ(high, 0.95f);
1335}
1336
1337TEST_F(WebRtcVideoEngineTestFake, TestSetInvalidCpuThreshold) {
1338 EXPECT_TRUE(SetupEngine());
1339 float low, high;
1340 cricket::VideoOptions options_in, options_out;
1341 // Valid range is [0, 1].
1342 options_in.system_low_adaptation_threshhold.Set(-1.5f);
1343 options_in.system_high_adaptation_threshhold.Set(1.5f);
1344 EXPECT_TRUE(channel_->SetOptions(options_in));
1345 EXPECT_TRUE(channel_->GetOptions(&options_out));
1346 EXPECT_TRUE(options_out.system_low_adaptation_threshhold.Get(&low));
1347 EXPECT_EQ(low, 0.0f);
1348 EXPECT_TRUE(options_out.system_high_adaptation_threshhold.Get(&high));
1349 EXPECT_EQ(high, 1.0f);
1350}
1351
1352
1353/////////////////////////
1354// Tests with real ViE //
1355/////////////////////////
1356
1357// Tests that we can find codecs by name or id.
1358TEST_F(WebRtcVideoEngineTest, FindCodec) {
1359 // We should not need to init engine in order to get codecs.
1360 const std::vector<cricket::VideoCodec>& c = engine_.codecs();
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +00001361 EXPECT_EQ(4U, c.size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001362
1363 cricket::VideoCodec vp8(104, "VP8", 320, 200, 30, 0);
1364 EXPECT_TRUE(engine_.FindCodec(vp8));
1365
1366 cricket::VideoCodec vp8_ci(104, "vp8", 320, 200, 30, 0);
1367 EXPECT_TRUE(engine_.FindCodec(vp8));
1368
1369 cricket::VideoCodec vp8_diff_fr_diff_pref(104, "VP8", 320, 200, 50, 50);
1370 EXPECT_TRUE(engine_.FindCodec(vp8_diff_fr_diff_pref));
1371
1372 cricket::VideoCodec vp8_diff_id(95, "VP8", 320, 200, 30, 0);
1373 EXPECT_FALSE(engine_.FindCodec(vp8_diff_id));
1374 vp8_diff_id.id = 97;
1375 EXPECT_TRUE(engine_.FindCodec(vp8_diff_id));
1376
1377 cricket::VideoCodec vp8_diff_res(104, "VP8", 320, 111, 30, 0);
1378 EXPECT_FALSE(engine_.FindCodec(vp8_diff_res));
1379
1380 // PeerConnection doesn't negotiate the resolution at this point.
1381 // Test that FindCodec can handle the case when width/height is 0.
1382 cricket::VideoCodec vp8_zero_res(104, "VP8", 0, 0, 30, 0);
1383 EXPECT_TRUE(engine_.FindCodec(vp8_zero_res));
1384
1385 cricket::VideoCodec red(101, "RED", 0, 0, 30, 0);
1386 EXPECT_TRUE(engine_.FindCodec(red));
1387
1388 cricket::VideoCodec red_ci(101, "red", 0, 0, 30, 0);
1389 EXPECT_TRUE(engine_.FindCodec(red));
1390
1391 cricket::VideoCodec fec(102, "ULPFEC", 0, 0, 30, 0);
1392 EXPECT_TRUE(engine_.FindCodec(fec));
1393
1394 cricket::VideoCodec fec_ci(102, "ulpfec", 0, 0, 30, 0);
1395 EXPECT_TRUE(engine_.FindCodec(fec));
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +00001396
1397 cricket::VideoCodec rtx(96, "rtx", 0, 0, 30, 0);
1398 EXPECT_TRUE(engine_.FindCodec(rtx));
1399}
1400
1401TEST_F(WebRtcVideoEngineTest, RtxCodecHasAptSet) {
1402 std::vector<cricket::VideoCodec>::const_iterator it;
1403 bool apt_checked = false;
1404 for (it = engine_.codecs().begin(); it != engine_.codecs().end(); ++it) {
1405 if (_stricmp(cricket::kRtxCodecName, it->name.c_str()) && it->id != 96) {
1406 continue;
1407 }
1408 int apt;
1409 EXPECT_TRUE(it->GetParam("apt", &apt));
1410 EXPECT_EQ(100, apt);
1411 apt_checked = true;
1412 }
1413 EXPECT_TRUE(apt_checked);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001414}
1415
1416TEST_F(WebRtcVideoEngineTest, StartupShutdown) {
1417 EXPECT_TRUE(engine_.Init(talk_base::Thread::Current()));
1418 engine_.Terminate();
1419}
1420
1421TEST_PRE_VIDEOENGINE_INIT(WebRtcVideoEngineTest, ConstrainNewCodec)
1422TEST_POST_VIDEOENGINE_INIT(WebRtcVideoEngineTest, ConstrainNewCodec)
1423
1424TEST_PRE_VIDEOENGINE_INIT(WebRtcVideoEngineTest, ConstrainRunningCodec)
1425TEST_POST_VIDEOENGINE_INIT(WebRtcVideoEngineTest, ConstrainRunningCodec)
1426
1427// TODO(juberti): Figure out why ViE is munging the COM refcount.
1428#ifdef WIN32
1429TEST_F(WebRtcVideoEngineTest, DISABLED_CheckCoInitialize) {
1430 Base::CheckCoInitialize();
1431}
1432#endif
1433
1434TEST_F(WebRtcVideoEngineTest, CreateChannel) {
1435 EXPECT_TRUE(engine_.Init(talk_base::Thread::Current()));
1436 cricket::VideoMediaChannel* channel = engine_.CreateChannel(NULL);
1437 EXPECT_TRUE(channel != NULL);
1438 delete channel;
1439}
1440
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001441TEST_F(WebRtcVideoMediaChannelTest, SetRecvCodecs) {
1442 std::vector<cricket::VideoCodec> codecs;
1443 codecs.push_back(kVP8Codec);
1444 EXPECT_TRUE(channel_->SetRecvCodecs(codecs));
1445}
1446TEST_F(WebRtcVideoMediaChannelTest, SetRecvCodecsWrongPayloadType) {
1447 std::vector<cricket::VideoCodec> codecs;
1448 codecs.push_back(kVP8Codec);
1449 codecs[0].id = 99;
1450 EXPECT_TRUE(channel_->SetRecvCodecs(codecs));
1451}
1452TEST_F(WebRtcVideoMediaChannelTest, SetRecvCodecsUnsupportedCodec) {
1453 std::vector<cricket::VideoCodec> codecs;
1454 codecs.push_back(kVP8Codec);
1455 codecs.push_back(cricket::VideoCodec(101, "VP1", 640, 400, 30, 0));
1456 EXPECT_FALSE(channel_->SetRecvCodecs(codecs));
1457}
1458
1459TEST_F(WebRtcVideoMediaChannelTest, SetSend) {
1460 Base::SetSend();
1461}
1462TEST_F(WebRtcVideoMediaChannelTest, SetSendWithoutCodecs) {
1463 Base::SetSendWithoutCodecs();
1464}
1465TEST_F(WebRtcVideoMediaChannelTest, SetSendSetsTransportBufferSizes) {
1466 Base::SetSendSetsTransportBufferSizes();
1467}
1468
1469TEST_F(WebRtcVideoMediaChannelTest, SendAndReceiveVp8Vga) {
1470 SendAndReceive(cricket::VideoCodec(100, "VP8", 640, 400, 30, 0));
1471}
1472TEST_F(WebRtcVideoMediaChannelTest, SendAndReceiveVp8Qvga) {
1473 SendAndReceive(cricket::VideoCodec(100, "VP8", 320, 200, 30, 0));
1474}
1475TEST_F(WebRtcVideoMediaChannelTest, SendAndReceiveH264SvcQqvga) {
1476 SendAndReceive(cricket::VideoCodec(100, "VP8", 160, 100, 30, 0));
1477}
1478TEST_F(WebRtcVideoMediaChannelTest, SendManyResizeOnce) {
1479 SendManyResizeOnce();
1480}
1481
1482TEST_F(WebRtcVideoMediaChannelTest, SendVp8HdAndReceiveAdaptedVp8Vga) {
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00001483 EXPECT_TRUE(channel_->SetCapturer(kSsrc, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001484 channel_->UpdateAspectRatio(1280, 720);
1485 video_capturer_.reset(new cricket::FakeVideoCapturer);
1486 const std::vector<cricket::VideoFormat>* formats =
1487 video_capturer_->GetSupportedFormats();
1488 cricket::VideoFormat capture_format_hd = (*formats)[0];
1489 EXPECT_EQ(cricket::CS_RUNNING, video_capturer_->Start(capture_format_hd));
1490 EXPECT_TRUE(channel_->SetCapturer(kSsrc, video_capturer_.get()));
1491
1492 // Capture format HD -> adapt (OnOutputFormatRequest VGA) -> VGA.
1493 cricket::VideoCodec codec(100, "VP8", 1280, 720, 30, 0);
1494 EXPECT_TRUE(SetOneCodec(codec));
1495 codec.width /= 2;
1496 codec.height /= 2;
1497 EXPECT_TRUE(channel_->SetSendStreamFormat(kSsrc, cricket::VideoFormat(
1498 codec.width, codec.height,
1499 cricket::VideoFormat::FpsToInterval(codec.framerate),
1500 cricket::FOURCC_ANY)));
1501 EXPECT_TRUE(SetSend(true));
1502 EXPECT_TRUE(channel_->SetRender(true));
1503 EXPECT_EQ(0, renderer_.num_rendered_frames());
1504 EXPECT_TRUE(SendFrame());
1505 EXPECT_FRAME_WAIT(1, codec.width, codec.height, kTimeout);
1506}
1507
1508// TODO(juberti): Fix this test to tolerate missing stats.
1509TEST_F(WebRtcVideoMediaChannelTest, DISABLED_GetStats) {
1510 Base::GetStats();
1511}
1512
1513// TODO(juberti): Fix this test to tolerate missing stats.
1514TEST_F(WebRtcVideoMediaChannelTest, DISABLED_GetStatsMultipleRecvStreams) {
1515 Base::GetStatsMultipleRecvStreams();
1516}
1517
1518TEST_F(WebRtcVideoMediaChannelTest, GetStatsMultipleSendStreams) {
1519 Base::GetStatsMultipleSendStreams();
1520}
1521
1522TEST_F(WebRtcVideoMediaChannelTest, SetSendBandwidth) {
1523 Base::SetSendBandwidth();
1524}
1525TEST_F(WebRtcVideoMediaChannelTest, SetSendSsrc) {
1526 Base::SetSendSsrc();
1527}
1528TEST_F(WebRtcVideoMediaChannelTest, SetSendSsrcAfterSetCodecs) {
1529 Base::SetSendSsrcAfterSetCodecs();
1530}
1531
1532TEST_F(WebRtcVideoMediaChannelTest, SetRenderer) {
1533 Base::SetRenderer();
1534}
1535
1536TEST_F(WebRtcVideoMediaChannelTest, AddRemoveRecvStreams) {
1537 Base::AddRemoveRecvStreams();
1538}
1539
1540TEST_F(WebRtcVideoMediaChannelTest, AddRemoveRecvStreamAndRender) {
1541 Base::AddRemoveRecvStreamAndRender();
1542}
1543
1544TEST_F(WebRtcVideoMediaChannelTest, AddRemoveRecvStreamsNoConference) {
1545 Base::AddRemoveRecvStreamsNoConference();
1546}
1547
1548TEST_F(WebRtcVideoMediaChannelTest, AddRemoveSendStreams) {
1549 Base::AddRemoveSendStreams();
1550}
1551
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001552TEST_F(WebRtcVideoMediaChannelTest, SimulateConference) {
1553 Base::SimulateConference();
1554}
1555
1556TEST_F(WebRtcVideoMediaChannelTest, AddRemoveCapturer) {
1557 Base::AddRemoveCapturer();
1558}
1559
1560TEST_F(WebRtcVideoMediaChannelTest, RemoveCapturerWithoutAdd) {
1561 Base::RemoveCapturerWithoutAdd();
1562}
1563
1564TEST_F(WebRtcVideoMediaChannelTest, AddRemoveCapturerMultipleSources) {
1565 Base::AddRemoveCapturerMultipleSources();
1566}
1567
wu@webrtc.orgde305012013-10-31 15:40:38 +00001568// This test verifies DSCP settings are properly applied on video media channel.
1569TEST_F(WebRtcVideoMediaChannelTest, TestSetDscpOptions) {
1570 talk_base::scoped_ptr<cricket::FakeNetworkInterface> network_interface(
1571 new cricket::FakeNetworkInterface);
1572 channel_->SetInterface(network_interface.get());
1573 cricket::VideoOptions options;
1574 options.dscp.Set(true);
1575 EXPECT_TRUE(channel_->SetOptions(options));
1576 EXPECT_EQ(talk_base::DSCP_AF41, network_interface->dscp());
1577 options.dscp.Set(false);
1578 EXPECT_TRUE(channel_->SetOptions(options));
1579 EXPECT_EQ(talk_base::DSCP_DEFAULT, network_interface->dscp());
1580 channel_->SetInterface(NULL);
1581}
1582
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001583
1584TEST_F(WebRtcVideoMediaChannelTest, SetOptionsSucceedsWhenSending) {
1585 cricket::VideoOptions options;
1586 options.conference_mode.Set(true);
1587 EXPECT_TRUE(channel_->SetOptions(options));
1588
1589 // Verify SetOptions returns true on a different options.
1590 cricket::VideoOptions options2;
1591 options2.adapt_input_to_cpu_usage.Set(true);
1592 EXPECT_TRUE(channel_->SetOptions(options2));
1593
1594 // Set send codecs on the channel and start sending.
1595 std::vector<cricket::VideoCodec> codecs;
1596 codecs.push_back(kVP8Codec);
1597 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1598 EXPECT_TRUE(channel_->SetSend(true));
1599
1600 // Verify SetOptions returns true if channel is already sending.
1601 cricket::VideoOptions options3;
1602 options3.conference_mode.Set(true);
1603 EXPECT_TRUE(channel_->SetOptions(options3));
1604}
1605
1606// Tests empty StreamParams is rejected.
1607TEST_F(WebRtcVideoMediaChannelTest, RejectEmptyStreamParams) {
1608 Base::RejectEmptyStreamParams();
1609}
1610
1611
1612TEST_F(WebRtcVideoMediaChannelTest, AdaptResolution16x10) {
1613 Base::AdaptResolution16x10();
1614}
1615
1616TEST_F(WebRtcVideoMediaChannelTest, AdaptResolution4x3) {
1617 Base::AdaptResolution4x3();
1618}
1619
1620TEST_F(WebRtcVideoMediaChannelTest, MuteStream) {
1621 Base::MuteStream();
1622}
1623
1624TEST_F(WebRtcVideoMediaChannelTest, MultipleSendStreams) {
1625 Base::MultipleSendStreams();
1626}
1627
1628// TODO(juberti): Restore this test once we support sending 0 fps.
1629TEST_F(WebRtcVideoMediaChannelTest, DISABLED_AdaptDropAllFrames) {
1630 Base::AdaptDropAllFrames();
1631}
1632// TODO(juberti): Understand why we get decode errors on this test.
1633TEST_F(WebRtcVideoMediaChannelTest, DISABLED_AdaptFramerate) {
1634 Base::AdaptFramerate();
1635}
1636
1637TEST_F(WebRtcVideoMediaChannelTest, SetSendStreamFormat0x0) {
1638 Base::SetSendStreamFormat0x0();
1639}
1640
1641// TODO(zhurunz): Fix the flakey test.
1642TEST_F(WebRtcVideoMediaChannelTest, DISABLED_SetSendStreamFormat) {
1643 Base::SetSendStreamFormat();
1644}
1645
1646TEST_F(WebRtcVideoMediaChannelTest, TwoStreamsSendAndReceive) {
1647 Base::TwoStreamsSendAndReceive(cricket::VideoCodec(100, "VP8", 640, 400, 30,
1648 0));
1649}
1650
1651TEST_F(WebRtcVideoMediaChannelTest, TwoStreamsReUseFirstStream) {
1652 Base::TwoStreamsReUseFirstStream(cricket::VideoCodec(100, "VP8", 640, 400, 30,
1653 0));
1654}
1655
1656TEST_F(WebRtcVideoEngineTestFake, ResetCodecOnScreencast) {
1657 EXPECT_TRUE(SetupEngine());
1658 cricket::VideoOptions options;
1659 options.video_noise_reduction.Set(true);
1660 EXPECT_TRUE(channel_->SetOptions(options));
1661
1662 // Set send codec.
1663 cricket::VideoCodec codec(kVP8Codec);
1664 std::vector<cricket::VideoCodec> codec_list;
1665 codec_list.push_back(codec);
1666 EXPECT_TRUE(channel_->AddSendStream(
1667 cricket::StreamParams::CreateLegacy(123)));
1668 EXPECT_TRUE(channel_->SetSendCodecs(codec_list));
1669 EXPECT_TRUE(channel_->SetSend(true));
1670 EXPECT_EQ(1, vie_.num_set_send_codecs());
1671
1672 webrtc::VideoCodec gcodec;
1673 memset(&gcodec, 0, sizeof(gcodec));
1674 int channel_num = vie_.GetLastChannel();
1675 EXPECT_EQ(0, vie_.GetSendCodec(channel_num, gcodec));
1676 EXPECT_TRUE(gcodec.codecSpecific.VP8.denoisingOn);
1677
1678 // Send a screencast frame with the same size.
1679 // Verify that denoising is turned off.
1680 SendI420ScreencastFrame(kVP8Codec.width, kVP8Codec.height);
1681 EXPECT_EQ(2, vie_.num_set_send_codecs());
1682 EXPECT_EQ(0, vie_.GetSendCodec(channel_num, gcodec));
1683 EXPECT_FALSE(gcodec.codecSpecific.VP8.denoisingOn);
1684}
1685
1686
1687TEST_F(WebRtcVideoEngineTestFake, DontRegisterDecoderIfFactoryIsNotGiven) {
1688 engine_.SetExternalDecoderFactory(NULL);
1689 EXPECT_TRUE(SetupEngine());
1690 int channel_num = vie_.GetLastChannel();
1691
1692 std::vector<cricket::VideoCodec> codecs;
1693 codecs.push_back(kVP8Codec);
1694 EXPECT_TRUE(channel_->SetRecvCodecs(codecs));
1695
1696 EXPECT_EQ(0, vie_.GetNumExternalDecoderRegistered(channel_num));
1697}
1698
1699TEST_F(WebRtcVideoEngineTestFake, RegisterDecoderIfFactoryIsGiven) {
1700 decoder_factory_.AddSupportedVideoCodecType(webrtc::kVideoCodecVP8);
1701 engine_.SetExternalDecoderFactory(&decoder_factory_);
1702 EXPECT_TRUE(SetupEngine());
1703 int channel_num = vie_.GetLastChannel();
1704
1705 std::vector<cricket::VideoCodec> codecs;
1706 codecs.push_back(kVP8Codec);
1707 EXPECT_TRUE(channel_->SetRecvCodecs(codecs));
1708
1709 EXPECT_TRUE(vie_.ExternalDecoderRegistered(channel_num, 100));
1710 EXPECT_EQ(1, vie_.GetNumExternalDecoderRegistered(channel_num));
1711}
1712
1713TEST_F(WebRtcVideoEngineTestFake, DontRegisterDecoderMultipleTimes) {
1714 decoder_factory_.AddSupportedVideoCodecType(webrtc::kVideoCodecVP8);
1715 engine_.SetExternalDecoderFactory(&decoder_factory_);
1716 EXPECT_TRUE(SetupEngine());
1717 int channel_num = vie_.GetLastChannel();
1718
1719 std::vector<cricket::VideoCodec> codecs;
1720 codecs.push_back(kVP8Codec);
1721 EXPECT_TRUE(channel_->SetRecvCodecs(codecs));
1722
1723 EXPECT_TRUE(vie_.ExternalDecoderRegistered(channel_num, 100));
1724 EXPECT_EQ(1, vie_.GetNumExternalDecoderRegistered(channel_num));
1725 EXPECT_EQ(1, decoder_factory_.GetNumCreatedDecoders());
1726
1727 EXPECT_TRUE(channel_->SetRecvCodecs(codecs));
1728 EXPECT_EQ(1, vie_.GetNumExternalDecoderRegistered(channel_num));
1729 EXPECT_EQ(1, decoder_factory_.GetNumCreatedDecoders());
1730}
1731
1732TEST_F(WebRtcVideoEngineTestFake, DontRegisterDecoderForNonVP8) {
1733 decoder_factory_.AddSupportedVideoCodecType(webrtc::kVideoCodecVP8);
1734 engine_.SetExternalDecoderFactory(&decoder_factory_);
1735 EXPECT_TRUE(SetupEngine());
1736 int channel_num = vie_.GetLastChannel();
1737
1738 std::vector<cricket::VideoCodec> codecs;
1739 codecs.push_back(kRedCodec);
1740 EXPECT_TRUE(channel_->SetRecvCodecs(codecs));
1741
1742 EXPECT_EQ(0, vie_.GetNumExternalDecoderRegistered(channel_num));
1743}
1744
1745TEST_F(WebRtcVideoEngineTestFake, DontRegisterEncoderIfFactoryIsNotGiven) {
1746 engine_.SetExternalEncoderFactory(NULL);
1747 EXPECT_TRUE(SetupEngine());
1748 int channel_num = vie_.GetLastChannel();
1749
1750 std::vector<cricket::VideoCodec> codecs;
1751 codecs.push_back(kVP8Codec);
1752 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1753
1754 EXPECT_EQ(0, vie_.GetNumExternalEncoderRegistered(channel_num));
1755}
1756
1757TEST_F(WebRtcVideoEngineTestFake, RegisterEncoderIfFactoryIsGiven) {
1758 encoder_factory_.AddSupportedVideoCodecType(webrtc::kVideoCodecVP8, "VP8");
1759 engine_.SetExternalEncoderFactory(&encoder_factory_);
1760 EXPECT_TRUE(SetupEngine());
1761 int channel_num = vie_.GetLastChannel();
1762
1763 std::vector<cricket::VideoCodec> codecs;
1764 codecs.push_back(kVP8Codec);
1765 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1766
1767 EXPECT_TRUE(vie_.ExternalEncoderRegistered(channel_num, 100));
1768 EXPECT_EQ(1, vie_.GetNumExternalEncoderRegistered(channel_num));
1769}
1770
1771TEST_F(WebRtcVideoEngineTestFake, DontRegisterEncoderMultipleTimes) {
1772 encoder_factory_.AddSupportedVideoCodecType(webrtc::kVideoCodecVP8, "VP8");
1773 engine_.SetExternalEncoderFactory(&encoder_factory_);
1774 EXPECT_TRUE(SetupEngine());
1775 int channel_num = vie_.GetLastChannel();
1776
1777 std::vector<cricket::VideoCodec> codecs;
1778 codecs.push_back(kVP8Codec);
1779 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1780
1781 EXPECT_TRUE(vie_.ExternalEncoderRegistered(channel_num, 100));
1782 EXPECT_EQ(1, vie_.GetNumExternalEncoderRegistered(channel_num));
1783 EXPECT_EQ(1, encoder_factory_.GetNumCreatedEncoders());
1784
1785 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1786 EXPECT_EQ(1, vie_.GetNumExternalEncoderRegistered(channel_num));
1787 EXPECT_EQ(1, encoder_factory_.GetNumCreatedEncoders());
1788}
1789
1790TEST_F(WebRtcVideoEngineTestFake, RegisterEncoderWithMultipleSendStreams) {
1791 encoder_factory_.AddSupportedVideoCodecType(webrtc::kVideoCodecVP8, "VP8");
1792 engine_.SetExternalEncoderFactory(&encoder_factory_);
1793 EXPECT_TRUE(SetupEngine());
1794
1795 std::vector<cricket::VideoCodec> codecs;
1796 codecs.push_back(kVP8Codec);
1797 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1798 EXPECT_EQ(1, vie_.GetTotalNumExternalEncoderRegistered());
1799
1800 // When we add the first stream (1234), it reuses the default send channel,
1801 // so it doesn't increase the registration count of external encoders.
1802 EXPECT_TRUE(channel_->AddSendStream(
1803 cricket::StreamParams::CreateLegacy(1234)));
1804 EXPECT_EQ(1, vie_.GetTotalNumExternalEncoderRegistered());
1805
1806 // When we add the second stream (2345), it creates a new channel and
1807 // increments the registration count.
1808 EXPECT_TRUE(channel_->AddSendStream(
1809 cricket::StreamParams::CreateLegacy(2345)));
1810 EXPECT_EQ(2, vie_.GetTotalNumExternalEncoderRegistered());
1811
1812 // At this moment the total registration count is two, but only one encoder
1813 // is registered per channel.
1814 int channel_num = vie_.GetLastChannel();
1815 EXPECT_EQ(1, vie_.GetNumExternalEncoderRegistered(channel_num));
1816
1817 // Removing send streams decrements the registration count.
1818 EXPECT_TRUE(channel_->RemoveSendStream(1234));
1819 EXPECT_EQ(1, vie_.GetTotalNumExternalEncoderRegistered());
1820
1821 // When we remove the last send stream, it also destroys the last send
1822 // channel and causes the registration count to drop to zero. It is a little
1823 // weird, but not a bug.
1824 EXPECT_TRUE(channel_->RemoveSendStream(2345));
1825 EXPECT_EQ(0, vie_.GetTotalNumExternalEncoderRegistered());
1826}
1827
1828TEST_F(WebRtcVideoEngineTestFake, DontRegisterEncoderForNonVP8) {
1829 encoder_factory_.AddSupportedVideoCodecType(webrtc::kVideoCodecGeneric,
1830 "GENERIC");
1831 engine_.SetExternalEncoderFactory(&encoder_factory_);
1832 EXPECT_TRUE(SetupEngine());
1833 int channel_num = vie_.GetLastChannel();
1834
1835 // Note: unlike the SetRecvCodecs, we must set a valid video codec for
1836 // channel_->SetSendCodecs() to succeed.
1837 std::vector<cricket::VideoCodec> codecs;
1838 codecs.push_back(kVP8Codec);
1839 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1840
1841 EXPECT_EQ(0, vie_.GetNumExternalEncoderRegistered(channel_num));
1842}
1843
1844// Test that NACK and REMB are enabled for external codec.
1845TEST_F(WebRtcVideoEngineTestFake, FeedbackParamsForNonVP8) {
1846 encoder_factory_.AddSupportedVideoCodecType(webrtc::kVideoCodecGeneric,
1847 "GENERIC");
1848 engine_.SetExternalEncoderFactory(&encoder_factory_);
1849 encoder_factory_.NotifyCodecsAvailable();
1850 EXPECT_TRUE(SetupEngine());
1851
1852 std::vector<cricket::VideoCodec> codecs(engine_.codecs());
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00001853 // The external codec will appear at last.
1854 size_t pos = codecs.size() - 1;
1855 EXPECT_EQ("GENERIC", codecs[pos].name);
1856 EXPECT_TRUE(codecs[pos].HasFeedbackParam(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001857 cricket::FeedbackParam(cricket::kRtcpFbParamNack,
1858 cricket::kParamValueEmpty)));
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00001859 EXPECT_TRUE(codecs[pos].HasFeedbackParam(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001860 cricket::FeedbackParam(cricket::kRtcpFbParamRemb,
1861 cricket::kParamValueEmpty)));
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00001862 EXPECT_TRUE(codecs[pos].HasFeedbackParam(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001863 cricket::FeedbackParam(cricket::kRtcpFbParamCcm,
1864 cricket::kRtcpFbCcmParamFir)));
1865}
1866
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00001867// Test external codec with be added to the end of the supported codec list.
1868TEST_F(WebRtcVideoEngineTestFake, ExternalCodecAddedToTheEnd) {
1869 EXPECT_TRUE(SetupEngine());
1870
1871 std::vector<cricket::VideoCodec> codecs(engine_.codecs());
1872 EXPECT_EQ("VP8", codecs[0].name);
1873
1874 encoder_factory_.AddSupportedVideoCodecType(webrtc::kVideoCodecGeneric,
1875 "GENERIC");
1876 engine_.SetExternalEncoderFactory(&encoder_factory_);
1877 encoder_factory_.NotifyCodecsAvailable();
1878
1879 codecs = engine_.codecs();
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00001880 cricket::VideoCodec internal_codec = codecs[0];
1881 cricket::VideoCodec external_codec = codecs[codecs.size() - 1];
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00001882 // The external codec will appear at last.
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00001883 EXPECT_EQ("GENERIC", external_codec.name);
1884 // The internal codec is preferred.
1885 EXPECT_GE(internal_codec.preference, external_codec.preference);
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00001886}
1887
1888// Test that external codec with be ignored if it has the same name as one of
1889// the internal codecs.
1890TEST_F(WebRtcVideoEngineTestFake, ExternalCodecIgnored) {
1891 EXPECT_TRUE(SetupEngine());
1892
1893 std::vector<cricket::VideoCodec> internal_codecs(engine_.codecs());
1894 EXPECT_EQ("VP8", internal_codecs[0].name);
1895
1896 encoder_factory_.AddSupportedVideoCodecType(webrtc::kVideoCodecVP8, "VP8");
1897 engine_.SetExternalEncoderFactory(&encoder_factory_);
1898 encoder_factory_.NotifyCodecsAvailable();
1899
1900 std::vector<cricket::VideoCodec> codecs = engine_.codecs();
1901 EXPECT_EQ("VP8", codecs[0].name);
1902 EXPECT_EQ(internal_codecs[0].height, codecs[0].height);
1903 EXPECT_EQ(internal_codecs[0].width, codecs[0].width);
1904 // Verify the last codec is not the external codec.
1905 EXPECT_NE("VP8", codecs[codecs.size() - 1].name);
1906}
1907
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001908TEST_F(WebRtcVideoEngineTestFake, UpdateEncoderCodecsAfterSetFactory) {
1909 engine_.SetExternalEncoderFactory(&encoder_factory_);
1910 EXPECT_TRUE(SetupEngine());
1911 int channel_num = vie_.GetLastChannel();
1912
1913 encoder_factory_.AddSupportedVideoCodecType(webrtc::kVideoCodecVP8, "VP8");
1914 encoder_factory_.NotifyCodecsAvailable();
1915 std::vector<cricket::VideoCodec> codecs;
1916 codecs.push_back(kVP8Codec);
1917 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1918
1919 EXPECT_TRUE(vie_.ExternalEncoderRegistered(channel_num, 100));
1920 EXPECT_EQ(1, vie_.GetNumExternalEncoderRegistered(channel_num));
1921 EXPECT_EQ(1, encoder_factory_.GetNumCreatedEncoders());
1922}
1923
1924// Tests that OnReadyToSend will be propagated into ViE.
1925TEST_F(WebRtcVideoEngineTestFake, OnReadyToSend) {
1926 EXPECT_TRUE(SetupEngine());
1927 int channel_num = vie_.GetLastChannel();
1928 EXPECT_TRUE(vie_.GetIsTransmitting(channel_num));
1929
1930 channel_->OnReadyToSend(false);
1931 EXPECT_FALSE(vie_.GetIsTransmitting(channel_num));
1932
1933 channel_->OnReadyToSend(true);
1934 EXPECT_TRUE(vie_.GetIsTransmitting(channel_num));
1935}
1936
1937#if 0
1938TEST_F(WebRtcVideoEngineTestFake, CaptureFrameTimestampToNtpTimestamp) {
1939 EXPECT_TRUE(SetupEngine());
1940 int capture_id = vie_.GetCaptureId(vie_.GetLastChannel());
1941
1942 // Set send codec.
1943 cricket::VideoCodec codec(kVP8Codec);
1944 std::vector<cricket::VideoCodec> codec_list;
1945 codec_list.push_back(codec);
1946 EXPECT_TRUE(channel_->AddSendStream(
1947 cricket::StreamParams::CreateLegacy(123)));
1948 EXPECT_TRUE(channel_->SetSendCodecs(codec_list));
1949 EXPECT_TRUE(channel_->SetSend(true));
1950
1951 int64 timestamp = time(NULL) * talk_base::kNumNanosecsPerSec;
1952 SendI420ScreencastFrameWithTimestamp(
1953 kVP8Codec.width, kVP8Codec.height, timestamp);
1954 EXPECT_EQ(talk_base::UnixTimestampNanosecsToNtpMillisecs(timestamp),
1955 vie_.GetCaptureLastTimestamp(capture_id));
1956
1957 SendI420ScreencastFrameWithTimestamp(kVP8Codec.width, kVP8Codec.height, 0);
1958 EXPECT_EQ(0, vie_.GetCaptureLastTimestamp(capture_id));
1959}
1960#endif