blob: 8b60f2387708d478564a7f1a1cd71a4951db3288 [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"
mallinath@webrtc.org67ee6b92014-02-03 16:57:16 +000039#include "talk/media/base/videoadapter.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000040#include "talk/media/base/videoengine_unittest.h"
41#include "talk/media/webrtc/fakewebrtcvideocapturemodule.h"
42#include "talk/media/webrtc/fakewebrtcvideoengine.h"
43#include "talk/media/webrtc/fakewebrtcvoiceengine.h"
44#include "talk/media/webrtc/webrtcvideocapturer.h"
45#include "talk/media/webrtc/webrtcvideoengine.h"
46#include "talk/media/webrtc/webrtcvideoframe.h"
47#include "talk/media/webrtc/webrtcvoiceengine.h"
48#include "talk/session/media/mediasession.h"
49#include "webrtc/system_wrappers/interface/trace.h"
50
51// Tests for the WebRtcVideoEngine/VideoChannel code.
52
buildbot@webrtc.org150835e2014-05-06 15:54:38 +000053using cricket::kRtpTimestampOffsetHeaderExtension;
54using cricket::kRtpAbsoluteSenderTimeHeaderExtension;
55
henrike@webrtc.org28e20752013-07-10 00:45:36 +000056static const cricket::VideoCodec kVP8Codec720p(100, "VP8", 1280, 720, 30, 0);
57static const cricket::VideoCodec kVP8Codec360p(100, "VP8", 640, 360, 30, 0);
58static const cricket::VideoCodec kVP8Codec270p(100, "VP8", 480, 270, 30, 0);
59static const cricket::VideoCodec kVP8Codec180p(100, "VP8", 320, 180, 30, 0);
60
61static const cricket::VideoCodec kVP8Codec(100, "VP8", 640, 400, 30, 0);
62static const cricket::VideoCodec kRedCodec(101, "red", 0, 0, 0, 0);
63static const cricket::VideoCodec kUlpFecCodec(102, "ulpfec", 0, 0, 0, 0);
64static const cricket::VideoCodec* const kVideoCodecs[] = {
65 &kVP8Codec,
66 &kRedCodec,
67 &kUlpFecCodec
68};
69
henrike@webrtc.org28e20752013-07-10 00:45:36 +000070static const unsigned int kStartBandwidthKbps = 300;
wu@webrtc.org1e6cb2c2014-03-24 17:01:50 +000071static const unsigned int kMinBandwidthKbps = 50;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000072static const unsigned int kMaxBandwidthKbps = 2000;
73
74static const unsigned int kNumberOfTemporalLayers = 1;
75
wu@webrtc.org9caf2762013-12-11 18:25:07 +000076static const uint32 kSsrcs1[] = {1};
77static const uint32 kSsrcs2[] = {1, 2};
78static const uint32 kSsrcs3[] = {1, 2, 3};
79static const uint32 kRtxSsrc1[] = {4};
80static const uint32 kRtxSsrcs3[] = {4, 5, 6};
81
henrike@webrtc.org28e20752013-07-10 00:45:36 +000082
83class FakeViEWrapper : public cricket::ViEWrapper {
84 public:
85 explicit FakeViEWrapper(cricket::FakeWebRtcVideoEngine* engine)
86 : cricket::ViEWrapper(engine, // base
87 engine, // codec
88 engine, // capture
89 engine, // network
90 engine, // render
91 engine, // rtp
92 engine, // image
93 engine) { // external decoder
94 }
95};
96
97// Test fixture to test WebRtcVideoEngine with a fake webrtc::VideoEngine.
98// Useful for testing failure paths.
wu@webrtc.orgcadf9042013-08-30 21:24:16 +000099class WebRtcVideoEngineTestFake : public testing::Test,
wu@webrtc.orgd64719d2013-08-01 00:00:07 +0000100 public sigslot::has_slots<> {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000101 public:
102 WebRtcVideoEngineTestFake()
103 : vie_(kVideoCodecs, ARRAY_SIZE(kVideoCodecs)),
104 cpu_monitor_(new talk_base::FakeCpuMonitor(
105 talk_base::Thread::Current())),
106 engine_(NULL, // cricket::WebRtcVoiceEngine
107 new FakeViEWrapper(&vie_), cpu_monitor_),
108 channel_(NULL),
wu@webrtc.orgd64719d2013-08-01 00:00:07 +0000109 voice_channel_(NULL),
110 last_error_(cricket::VideoMediaChannel::ERROR_NONE) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000111 }
112 bool SetupEngine() {
113 bool result = engine_.Init(talk_base::Thread::Current());
114 if (result) {
115 channel_ = engine_.CreateChannel(voice_channel_);
wu@webrtc.orgd64719d2013-08-01 00:00:07 +0000116 channel_->SignalMediaError.connect(this,
117 &WebRtcVideoEngineTestFake::OnMediaError);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000118 result = (channel_ != NULL);
119 }
120 return result;
121 }
wu@webrtc.orgd64719d2013-08-01 00:00:07 +0000122 void OnMediaError(uint32 ssrc, cricket::VideoMediaChannel::Error error) {
123 last_error_ = error;
124 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000125 bool SendI420Frame(int width, int height) {
126 if (NULL == channel_) {
127 return false;
128 }
129 cricket::WebRtcVideoFrame frame;
wu@webrtc.org9caf2762013-12-11 18:25:07 +0000130 if (!frame.InitToBlack(width, height, 1, 1, 0, 0)) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000131 return false;
132 }
133 cricket::FakeVideoCapturer capturer;
wu@webrtc.orgf7d501d2014-03-27 23:48:25 +0000134 channel_->SendFrame(&capturer, &frame);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000135 return true;
136 }
137 bool SendI420ScreencastFrame(int width, int height) {
138 return SendI420ScreencastFrameWithTimestamp(width, height, 0);
139 }
140 bool SendI420ScreencastFrameWithTimestamp(
141 int width, int height, int64 timestamp) {
142 if (NULL == channel_) {
143 return false;
144 }
145 cricket::WebRtcVideoFrame frame;
wu@webrtc.org9caf2762013-12-11 18:25:07 +0000146 if (!frame.InitToBlack(width, height, 1, 1, 0, 0)) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000147 return false;
148 }
149 cricket::FakeVideoCapturer capturer;
150 capturer.SetScreencast(true);
wu@webrtc.orgf7d501d2014-03-27 23:48:25 +0000151 channel_->SendFrame(&capturer, &frame);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000152 return true;
153 }
buildbot@webrtc.org150835e2014-05-06 15:54:38 +0000154 void TestSetSendRtpHeaderExtensions(const std::string& ext) {
155 EXPECT_TRUE(SetupEngine());
156 int channel_num = vie_.GetLastChannel();
157
158 // Verify extensions are off by default.
159 EXPECT_EQ(-1, vie_.GetSendRtpExtensionId(channel_num, ext));
160
161 // Enable extension.
162 const int id = 1;
163 std::vector<cricket::RtpHeaderExtension> extensions;
164 extensions.push_back(cricket::RtpHeaderExtension(ext, id));
165
166 // Verify the send extension id.
167 EXPECT_TRUE(channel_->SetSendRtpHeaderExtensions(extensions));
168 EXPECT_EQ(id, vie_.GetSendRtpExtensionId(channel_num, ext));
169 // Verify call with same set of extensions returns true.
170 EXPECT_TRUE(channel_->SetSendRtpHeaderExtensions(extensions));
171 EXPECT_EQ(id, vie_.GetSendRtpExtensionId(channel_num, ext));
172
173 // Add a new send stream and verify the extension is set.
174 // The first send stream to occupy the default channel.
175 EXPECT_TRUE(
176 channel_->AddSendStream(cricket::StreamParams::CreateLegacy(123)));
177 EXPECT_TRUE(
178 channel_->AddSendStream(cricket::StreamParams::CreateLegacy(234)));
179 int new_send_channel_num = vie_.GetLastChannel();
180 EXPECT_NE(channel_num, new_send_channel_num);
181 EXPECT_EQ(id, vie_.GetSendRtpExtensionId(new_send_channel_num, ext));
182
183 // Remove the extension id.
184 std::vector<cricket::RtpHeaderExtension> empty_extensions;
185 EXPECT_TRUE(channel_->SetSendRtpHeaderExtensions(empty_extensions));
186 EXPECT_EQ(-1, vie_.GetSendRtpExtensionId(channel_num, ext));
187 EXPECT_EQ(-1, vie_.GetSendRtpExtensionId(new_send_channel_num, ext));
188 }
189 void TestSetRecvRtpHeaderExtensions(const std::string& ext) {
190 EXPECT_TRUE(SetupEngine());
191 int channel_num = vie_.GetLastChannel();
192
193 // Verify extensions are off by default.
194 EXPECT_EQ(-1, vie_.GetReceiveRtpExtensionId(channel_num, ext));
195
196 // Enable extension.
197 const int id = 2;
198 std::vector<cricket::RtpHeaderExtension> extensions;
199 extensions.push_back(cricket::RtpHeaderExtension(ext, id));
200
201 // Verify receive extension id.
202 EXPECT_TRUE(channel_->SetRecvRtpHeaderExtensions(extensions));
203 EXPECT_EQ(id, vie_.GetReceiveRtpExtensionId(channel_num, ext));
204 // Verify call with same set of extensions returns true.
205 EXPECT_TRUE(channel_->SetRecvRtpHeaderExtensions(extensions));
206 EXPECT_EQ(id, vie_.GetReceiveRtpExtensionId(channel_num, ext));
207
208 // Add a new receive stream and verify the extension is set.
209 // The first send stream to occupy the default channel.
210 EXPECT_TRUE(
211 channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(345)));
212 EXPECT_TRUE(
213 channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(456)));
214 int new_recv_channel_num = vie_.GetLastChannel();
215 EXPECT_NE(channel_num, new_recv_channel_num);
216 EXPECT_EQ(id, vie_.GetReceiveRtpExtensionId(new_recv_channel_num, ext));
217
218 // Remove the extension id.
219 std::vector<cricket::RtpHeaderExtension> empty_extensions;
220 EXPECT_TRUE(channel_->SetRecvRtpHeaderExtensions(empty_extensions));
221 EXPECT_EQ(-1, vie_.GetReceiveRtpExtensionId(channel_num, ext));
222 EXPECT_EQ(-1, vie_.GetReceiveRtpExtensionId(new_recv_channel_num, ext));
223 }
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +0000224 void VerifyCodecFeedbackParams(const cricket::VideoCodec& codec) {
225 EXPECT_TRUE(codec.HasFeedbackParam(
226 cricket::FeedbackParam(cricket::kRtcpFbParamNack,
227 cricket::kParamValueEmpty)));
228 EXPECT_TRUE(codec.HasFeedbackParam(
229 cricket::FeedbackParam(cricket::kRtcpFbParamNack,
230 cricket::kRtcpFbNackParamPli)));
231 EXPECT_TRUE(codec.HasFeedbackParam(
232 cricket::FeedbackParam(cricket::kRtcpFbParamRemb,
233 cricket::kParamValueEmpty)));
234 EXPECT_TRUE(codec.HasFeedbackParam(
235 cricket::FeedbackParam(cricket::kRtcpFbParamCcm,
236 cricket::kRtcpFbCcmParamFir)));
237 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000238 void VerifyVP8SendCodec(int channel_num,
239 unsigned int width,
240 unsigned int height,
241 unsigned int layers = 0,
242 unsigned int max_bitrate = kMaxBandwidthKbps,
243 unsigned int min_bitrate = kMinBandwidthKbps,
244 unsigned int start_bitrate = kStartBandwidthKbps,
245 unsigned int fps = 30,
246 unsigned int max_quantization = 0
247 ) {
248 webrtc::VideoCodec gcodec;
249 EXPECT_EQ(0, vie_.GetSendCodec(channel_num, gcodec));
250
251 // Video codec properties.
252 EXPECT_EQ(webrtc::kVideoCodecVP8, gcodec.codecType);
253 EXPECT_STREQ("VP8", gcodec.plName);
254 EXPECT_EQ(100, gcodec.plType);
255 EXPECT_EQ(width, gcodec.width);
256 EXPECT_EQ(height, gcodec.height);
257 EXPECT_EQ(talk_base::_min(start_bitrate, max_bitrate), gcodec.startBitrate);
258 EXPECT_EQ(max_bitrate, gcodec.maxBitrate);
259 EXPECT_EQ(min_bitrate, gcodec.minBitrate);
260 EXPECT_EQ(fps, gcodec.maxFramerate);
261 // VP8 specific.
262 EXPECT_FALSE(gcodec.codecSpecific.VP8.pictureLossIndicationOn);
263 EXPECT_FALSE(gcodec.codecSpecific.VP8.feedbackModeOn);
264 EXPECT_EQ(webrtc::kComplexityNormal, gcodec.codecSpecific.VP8.complexity);
265 EXPECT_EQ(webrtc::kResilienceOff, gcodec.codecSpecific.VP8.resilience);
266 EXPECT_EQ(max_quantization, gcodec.qpMax);
267 }
268 virtual void TearDown() {
269 delete channel_;
270 engine_.Terminate();
271 }
272
273 protected:
274 cricket::FakeWebRtcVideoEngine vie_;
275 cricket::FakeWebRtcVideoDecoderFactory decoder_factory_;
276 cricket::FakeWebRtcVideoEncoderFactory encoder_factory_;
277 talk_base::FakeCpuMonitor* cpu_monitor_;
278 cricket::WebRtcVideoEngine engine_;
279 cricket::WebRtcVideoMediaChannel* channel_;
280 cricket::WebRtcVoiceMediaChannel* voice_channel_;
wu@webrtc.orgd64719d2013-08-01 00:00:07 +0000281 cricket::VideoMediaChannel::Error last_error_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000282};
283
284// Test fixtures to test WebRtcVideoEngine with a real webrtc::VideoEngine.
285class WebRtcVideoEngineTest
286 : public VideoEngineTest<cricket::WebRtcVideoEngine> {
287 protected:
288 typedef VideoEngineTest<cricket::WebRtcVideoEngine> Base;
289};
290class WebRtcVideoMediaChannelTest
291 : public VideoMediaChannelTest<
292 cricket::WebRtcVideoEngine, cricket::WebRtcVideoMediaChannel> {
293 protected:
294 typedef VideoMediaChannelTest<cricket::WebRtcVideoEngine,
295 cricket::WebRtcVideoMediaChannel> Base;
296 virtual cricket::VideoCodec DefaultCodec() { return kVP8Codec; }
297 virtual void SetUp() {
298 Base::SetUp();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000299 }
300 virtual void TearDown() {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000301 Base::TearDown();
302 }
303};
304
305/////////////////////////
306// Tests with fake ViE //
307/////////////////////////
308
309// Tests that our stub library "works".
310TEST_F(WebRtcVideoEngineTestFake, StartupShutdown) {
311 EXPECT_FALSE(vie_.IsInited());
312 EXPECT_TRUE(engine_.Init(talk_base::Thread::Current()));
313 EXPECT_TRUE(vie_.IsInited());
314 engine_.Terminate();
315}
316
317// Tests that webrtc logs are logged when they should be.
318TEST_F(WebRtcVideoEngineTest, WebRtcShouldLog) {
319 const char webrtc_log[] = "WebRtcVideoEngineTest.WebRtcShouldLog";
320 EXPECT_TRUE(engine_.Init(talk_base::Thread::Current()));
321 engine_.SetLogging(talk_base::LS_INFO, "");
322 std::string str;
323 talk_base::StringStream stream(str);
324 talk_base::LogMessage::AddLogToStream(&stream, talk_base::LS_INFO);
325 EXPECT_EQ(talk_base::LS_INFO, talk_base::LogMessage::GetLogToStream(&stream));
326 webrtc::Trace::Add(webrtc::kTraceStateInfo, webrtc::kTraceUndefined, 0,
327 webrtc_log);
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +0000328 talk_base::Thread::Current()->ProcessMessages(100);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000329 talk_base::LogMessage::RemoveLogToStream(&stream);
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +0000330 // Access |str| after LogMessage is done with it to avoid data racing.
331 EXPECT_NE(std::string::npos, str.find(webrtc_log));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000332}
333
334// Tests that webrtc logs are not logged when they should't be.
335TEST_F(WebRtcVideoEngineTest, WebRtcShouldNotLog) {
336 const char webrtc_log[] = "WebRtcVideoEngineTest.WebRtcShouldNotLog";
337 EXPECT_TRUE(engine_.Init(talk_base::Thread::Current()));
338 // WebRTC should never be logged lower than LS_INFO.
339 engine_.SetLogging(talk_base::LS_WARNING, "");
340 std::string str;
341 talk_base::StringStream stream(str);
342 // Make sure that WebRTC is not logged, even at lowest severity
343 talk_base::LogMessage::AddLogToStream(&stream, talk_base::LS_SENSITIVE);
344 EXPECT_EQ(talk_base::LS_SENSITIVE,
345 talk_base::LogMessage::GetLogToStream(&stream));
346 webrtc::Trace::Add(webrtc::kTraceStateInfo, webrtc::kTraceUndefined, 0,
347 webrtc_log);
348 talk_base::Thread::Current()->ProcessMessages(10);
349 EXPECT_EQ(std::string::npos, str.find(webrtc_log));
350 talk_base::LogMessage::RemoveLogToStream(&stream);
351}
352
353// Tests that we can create and destroy a channel.
354TEST_F(WebRtcVideoEngineTestFake, CreateChannel) {
355 EXPECT_TRUE(engine_.Init(talk_base::Thread::Current()));
356 channel_ = engine_.CreateChannel(voice_channel_);
357 EXPECT_TRUE(channel_ != NULL);
358 EXPECT_EQ(1, engine_.GetNumOfChannels());
359 delete channel_;
360 channel_ = NULL;
361 EXPECT_EQ(0, engine_.GetNumOfChannels());
362}
363
364// Tests that we properly handle failures in CreateChannel.
365TEST_F(WebRtcVideoEngineTestFake, CreateChannelFail) {
366 vie_.set_fail_create_channel(true);
367 EXPECT_TRUE(engine_.Init(talk_base::Thread::Current()));
368 channel_ = engine_.CreateChannel(voice_channel_);
369 EXPECT_TRUE(channel_ == NULL);
370}
371
372// Tests that we properly handle failures in AllocateExternalCaptureDevice.
373TEST_F(WebRtcVideoEngineTestFake, AllocateExternalCaptureDeviceFail) {
374 vie_.set_fail_alloc_capturer(true);
375 EXPECT_TRUE(engine_.Init(talk_base::Thread::Current()));
376 channel_ = engine_.CreateChannel(voice_channel_);
377 EXPECT_TRUE(channel_ == NULL);
378}
379
380// Test that we apply our default codecs properly.
381TEST_F(WebRtcVideoEngineTestFake, SetSendCodecs) {
382 EXPECT_TRUE(SetupEngine());
383 int channel_num = vie_.GetLastChannel();
384 std::vector<cricket::VideoCodec> codecs(engine_.codecs());
385 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
386 VerifyVP8SendCodec(channel_num, kVP8Codec.width, kVP8Codec.height);
387 EXPECT_TRUE(vie_.GetHybridNackFecStatus(channel_num));
388 EXPECT_FALSE(vie_.GetNackStatus(channel_num));
wu@webrtc.org05e7b442014-04-01 17:44:24 +0000389 EXPECT_EQ(1, vie_.GetNumSetSendCodecs());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000390 // TODO(juberti): Check RTCP, PLI, TMMBR.
391}
392
wu@webrtc.org05e7b442014-04-01 17:44:24 +0000393// Test that ViE Channel doesn't call SetSendCodec again if same codec is tried
394// to apply.
395TEST_F(WebRtcVideoEngineTestFake, DontResetSetSendCodec) {
396 EXPECT_TRUE(SetupEngine());
397 int channel_num = vie_.GetLastChannel();
398 std::vector<cricket::VideoCodec> codecs(engine_.codecs());
399 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
400 VerifyVP8SendCodec(channel_num, kVP8Codec.width, kVP8Codec.height);
401 EXPECT_TRUE(vie_.GetHybridNackFecStatus(channel_num));
402 EXPECT_FALSE(vie_.GetNackStatus(channel_num));
403 EXPECT_EQ(1, vie_.GetNumSetSendCodecs());
404 // Try setting same code again.
405 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
406 // Since it's exact same codec which is already set, media channel shouldn't
407 // send the codec to ViE.
408 EXPECT_EQ(1, vie_.GetNumSetSendCodecs());
409}
410
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000411TEST_F(WebRtcVideoEngineTestFake, SetSendCodecsWithMinMaxBitrate) {
412 EXPECT_TRUE(SetupEngine());
413 int channel_num = vie_.GetLastChannel();
414 std::vector<cricket::VideoCodec> codecs(engine_.codecs());
415 codecs[0].params[cricket::kCodecParamMinBitrate] = "10";
416 codecs[0].params[cricket::kCodecParamMaxBitrate] = "20";
417 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
418
419 VerifyVP8SendCodec(
420 channel_num, kVP8Codec.width, kVP8Codec.height, 0, 20, 10, 20);
421
422 cricket::VideoCodec codec;
423 EXPECT_TRUE(channel_->GetSendCodec(&codec));
424 EXPECT_EQ("10", codec.params[cricket::kCodecParamMinBitrate]);
425 EXPECT_EQ("20", codec.params[cricket::kCodecParamMaxBitrate]);
426}
427
428TEST_F(WebRtcVideoEngineTestFake, SetSendCodecsWithMinMaxBitrateInvalid) {
429 EXPECT_TRUE(SetupEngine());
430 std::vector<cricket::VideoCodec> codecs(engine_.codecs());
431 codecs[0].params[cricket::kCodecParamMinBitrate] = "30";
432 codecs[0].params[cricket::kCodecParamMaxBitrate] = "20";
433 EXPECT_FALSE(channel_->SetSendCodecs(codecs));
434}
435
436TEST_F(WebRtcVideoEngineTestFake, SetSendCodecsWithLargeMinMaxBitrate) {
437 EXPECT_TRUE(SetupEngine());
438 int channel_num = vie_.GetLastChannel();
439 std::vector<cricket::VideoCodec> codecs(engine_.codecs());
440 codecs[0].params[cricket::kCodecParamMinBitrate] = "1000";
441 codecs[0].params[cricket::kCodecParamMaxBitrate] = "2000";
442 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
443
444 VerifyVP8SendCodec(
445 channel_num, kVP8Codec.width, kVP8Codec.height, 0, 2000, 1000,
446 1000);
447}
448
449TEST_F(WebRtcVideoEngineTestFake, SetSendCodecsWithMaxQuantization) {
450 EXPECT_TRUE(SetupEngine());
451 int channel_num = vie_.GetLastChannel();
452 std::vector<cricket::VideoCodec> codecs(engine_.codecs());
453 codecs[0].params[cricket::kCodecParamMaxQuantization] = "21";
454 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
455
456 VerifyVP8SendCodec(
457 channel_num, kVP8Codec.width, kVP8Codec.height, 0, 2000, 50, 300,
458 30, 21);
459
460 cricket::VideoCodec codec;
461 EXPECT_TRUE(channel_->GetSendCodec(&codec));
462 EXPECT_EQ("21", codec.params[cricket::kCodecParamMaxQuantization]);
463}
464
465TEST_F(WebRtcVideoEngineTestFake, SetOptionsWithMaxBitrate) {
466 EXPECT_TRUE(SetupEngine());
467 int channel_num = vie_.GetLastChannel();
468 std::vector<cricket::VideoCodec> codecs(engine_.codecs());
469 codecs[0].params[cricket::kCodecParamMinBitrate] = "10";
470 codecs[0].params[cricket::kCodecParamMaxBitrate] = "20";
471 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
472
473 VerifyVP8SendCodec(
474 channel_num, kVP8Codec.width, kVP8Codec.height, 0, 20, 10, 20);
475
476 // Verify that max bitrate doesn't change after SetOptions().
477 cricket::VideoOptions options;
478 options.video_noise_reduction.Set(true);
479 EXPECT_TRUE(channel_->SetOptions(options));
480 VerifyVP8SendCodec(
481 channel_num, kVP8Codec.width, kVP8Codec.height, 0, 20, 10, 20);
482
483 options.video_noise_reduction.Set(false);
484 options.conference_mode.Set(false);
485 EXPECT_TRUE(channel_->SetOptions(options));
486 VerifyVP8SendCodec(
487 channel_num, kVP8Codec.width, kVP8Codec.height, 0, 20, 10, 20);
488}
489
wu@webrtc.orgcecfd182013-10-30 05:18:12 +0000490TEST_F(WebRtcVideoEngineTestFake, SetOptionsWithLoweredBitrate) {
491 EXPECT_TRUE(SetupEngine());
492 int channel_num = vie_.GetLastChannel();
493 std::vector<cricket::VideoCodec> codecs(engine_.codecs());
494 codecs[0].params[cricket::kCodecParamMinBitrate] = "50";
495 codecs[0].params[cricket::kCodecParamMaxBitrate] = "100";
496 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
497
498 VerifyVP8SendCodec(
499 channel_num, kVP8Codec.width, kVP8Codec.height, 0, 100, 50, 100);
500
501 // Verify that min bitrate changes after SetOptions().
502 cricket::VideoOptions options;
503 options.lower_min_bitrate.Set(true);
504 EXPECT_TRUE(channel_->SetOptions(options));
505 VerifyVP8SendCodec(
506 channel_num, kVP8Codec.width, kVP8Codec.height, 0, 100, 30, 100);
507}
508
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000509TEST_F(WebRtcVideoEngineTestFake, MaxBitrateResetWithConferenceMode) {
510 EXPECT_TRUE(SetupEngine());
511 int channel_num = vie_.GetLastChannel();
512 std::vector<cricket::VideoCodec> codecs(engine_.codecs());
513 codecs[0].params[cricket::kCodecParamMinBitrate] = "10";
514 codecs[0].params[cricket::kCodecParamMaxBitrate] = "20";
515 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
516
517 VerifyVP8SendCodec(
518 channel_num, kVP8Codec.width, kVP8Codec.height, 0, 20, 10, 20);
519
520 cricket::VideoOptions options;
521 options.conference_mode.Set(true);
522 EXPECT_TRUE(channel_->SetOptions(options));
523 options.conference_mode.Set(false);
524 EXPECT_TRUE(channel_->SetOptions(options));
525 VerifyVP8SendCodec(
526 channel_num, kVP8Codec.width, kVP8Codec.height, 0,
527 kMaxBandwidthKbps, 10, 20);
528}
529
530// Verify the current send bitrate is used as start bitrate when reconfiguring
531// the send codec.
532TEST_F(WebRtcVideoEngineTestFake, StartSendBitrate) {
533 EXPECT_TRUE(SetupEngine());
534 EXPECT_TRUE(channel_->AddSendStream(
535 cricket::StreamParams::CreateLegacy(1)));
536 int send_channel = vie_.GetLastChannel();
537 cricket::VideoCodec codec(kVP8Codec);
538 std::vector<cricket::VideoCodec> codec_list;
539 codec_list.push_back(codec);
540 EXPECT_TRUE(channel_->SetSendCodecs(codec_list));
541 const unsigned int kVideoMaxSendBitrateKbps = 2000;
542 const unsigned int kVideoMinSendBitrateKbps = 50;
543 const unsigned int kVideoDefaultStartSendBitrateKbps = 300;
544 VerifyVP8SendCodec(send_channel, kVP8Codec.width, kVP8Codec.height, 0,
545 kVideoMaxSendBitrateKbps, kVideoMinSendBitrateKbps,
546 kVideoDefaultStartSendBitrateKbps);
547 EXPECT_EQ(0, vie_.StartSend(send_channel));
548
549 // Increase the send bitrate and verify it is used as start bitrate.
550 const unsigned int kVideoSendBitrateBps = 768000;
551 vie_.SetSendBitrates(send_channel, kVideoSendBitrateBps, 0, 0);
552 EXPECT_TRUE(channel_->SetSendCodecs(codec_list));
553 VerifyVP8SendCodec(send_channel, kVP8Codec.width, kVP8Codec.height, 0,
554 kVideoMaxSendBitrateKbps, kVideoMinSendBitrateKbps,
555 kVideoSendBitrateBps / 1000);
556
557 // Never set a start bitrate higher than the max bitrate.
558 vie_.SetSendBitrates(send_channel, kVideoMaxSendBitrateKbps + 500, 0, 0);
559 EXPECT_TRUE(channel_->SetSendCodecs(codec_list));
560 VerifyVP8SendCodec(send_channel, kVP8Codec.width, kVP8Codec.height, 0,
561 kVideoMaxSendBitrateKbps, kVideoMinSendBitrateKbps,
562 kVideoDefaultStartSendBitrateKbps);
563
564 // Use the default start bitrate if the send bitrate is lower.
565 vie_.SetSendBitrates(send_channel, kVideoDefaultStartSendBitrateKbps - 50, 0,
566 0);
567 EXPECT_TRUE(channel_->SetSendCodecs(codec_list));
568 VerifyVP8SendCodec(send_channel, kVP8Codec.width, kVP8Codec.height, 0,
569 kVideoMaxSendBitrateKbps, kVideoMinSendBitrateKbps,
570 kVideoDefaultStartSendBitrateKbps);
571}
572
573
574// Test that we constrain send codecs properly.
575TEST_F(WebRtcVideoEngineTestFake, ConstrainSendCodecs) {
576 EXPECT_TRUE(SetupEngine());
577 int channel_num = vie_.GetLastChannel();
578
579 // Set max settings of 640x400x30.
580 EXPECT_TRUE(engine_.SetDefaultEncoderConfig(
581 cricket::VideoEncoderConfig(kVP8Codec)));
582
583 // Send codec format bigger than max setting.
584 cricket::VideoCodec codec(kVP8Codec);
585 codec.width = 1280;
586 codec.height = 800;
587 codec.framerate = 60;
588 std::vector<cricket::VideoCodec> codec_list;
589 codec_list.push_back(codec);
590
591 // Set send codec and verify codec has been constrained.
592 EXPECT_TRUE(channel_->SetSendCodecs(codec_list));
593 VerifyVP8SendCodec(channel_num, kVP8Codec.width, kVP8Codec.height);
594}
595
596// Test that SetSendCodecs rejects bad format.
597TEST_F(WebRtcVideoEngineTestFake, SetSendCodecsRejectBadFormat) {
598 EXPECT_TRUE(SetupEngine());
599 int channel_num = vie_.GetLastChannel();
600
601 // Set w = 0.
602 cricket::VideoCodec codec(kVP8Codec);
603 codec.width = 0;
604 std::vector<cricket::VideoCodec> codec_list;
605 codec_list.push_back(codec);
606
607 // Verify SetSendCodecs failed and send codec is not changed on engine.
608 EXPECT_FALSE(channel_->SetSendCodecs(codec_list));
609 webrtc::VideoCodec gcodec;
610 // Set plType to something other than the value to test against ensuring
611 // that failure will happen if it is not changed.
612 gcodec.plType = 1;
613 EXPECT_EQ(0, vie_.GetSendCodec(channel_num, gcodec));
614 EXPECT_EQ(0, gcodec.plType);
615
616 // Set h = 0.
617 codec_list[0].width = 640;
618 codec_list[0].height = 0;
619
620 // Verify SetSendCodecs failed and send codec is not changed on engine.
621 EXPECT_FALSE(channel_->SetSendCodecs(codec_list));
622 // Set plType to something other than the value to test against ensuring
623 // that failure will happen if it is not changed.
624 gcodec.plType = 1;
625 EXPECT_EQ(0, vie_.GetSendCodec(channel_num, gcodec));
626 EXPECT_EQ(0, gcodec.plType);
627}
628
629// Test that SetSendCodecs rejects bad codec.
630TEST_F(WebRtcVideoEngineTestFake, SetSendCodecsRejectBadCodec) {
631 EXPECT_TRUE(SetupEngine());
632 int channel_num = vie_.GetLastChannel();
633
634 // Set bad codec name.
635 cricket::VideoCodec codec(kVP8Codec);
636 codec.name = "bad";
637 std::vector<cricket::VideoCodec> codec_list;
638 codec_list.push_back(codec);
639
640 // Verify SetSendCodecs failed and send codec is not changed on engine.
641 EXPECT_FALSE(channel_->SetSendCodecs(codec_list));
642 webrtc::VideoCodec gcodec;
643 // Set plType to something other than the value to test against ensuring
644 // that failure will happen if it is not changed.
645 gcodec.plType = 1;
646 EXPECT_EQ(0, vie_.GetSendCodec(channel_num, gcodec));
647 EXPECT_EQ(0, gcodec.plType);
648}
649
650// Test that vie send codec is reset on new video frame size.
651TEST_F(WebRtcVideoEngineTestFake, ResetVieSendCodecOnNewFrameSize) {
652 EXPECT_TRUE(SetupEngine());
653 int channel_num = vie_.GetLastChannel();
654
655 // Set send codec.
656 std::vector<cricket::VideoCodec> codec_list;
657 codec_list.push_back(kVP8Codec);
658 EXPECT_TRUE(channel_->SetSendCodecs(codec_list));
659 EXPECT_TRUE(channel_->AddSendStream(
660 cricket::StreamParams::CreateLegacy(123)));
661 EXPECT_TRUE(channel_->SetSend(true));
662
663 // Capture a smaller frame and verify vie send codec has been reset to
664 // the new size.
665 SendI420Frame(kVP8Codec.width / 2, kVP8Codec.height / 2);
666 VerifyVP8SendCodec(channel_num, kVP8Codec.width / 2, kVP8Codec.height / 2);
667
668 // Capture a frame bigger than send_codec_ and verify vie send codec has been
669 // reset (and clipped) to send_codec_.
670 SendI420Frame(kVP8Codec.width * 2, kVP8Codec.height * 2);
671 VerifyVP8SendCodec(channel_num, kVP8Codec.width, kVP8Codec.height);
672}
673
674// Test that we set our inbound codecs properly.
675TEST_F(WebRtcVideoEngineTestFake, SetRecvCodecs) {
676 EXPECT_TRUE(SetupEngine());
677 int channel_num = vie_.GetLastChannel();
678
679 std::vector<cricket::VideoCodec> codecs;
680 codecs.push_back(kVP8Codec);
681 EXPECT_TRUE(channel_->SetRecvCodecs(codecs));
682
683 webrtc::VideoCodec wcodec;
684 EXPECT_TRUE(engine_.ConvertFromCricketVideoCodec(kVP8Codec, &wcodec));
685 EXPECT_TRUE(vie_.ReceiveCodecRegistered(channel_num, wcodec));
686}
687
688// Test that channel connects and disconnects external capturer correctly.
689TEST_F(WebRtcVideoEngineTestFake, HasExternalCapturer) {
690 EXPECT_TRUE(SetupEngine());
691 int channel_num = vie_.GetLastChannel();
692
693 EXPECT_EQ(1, vie_.GetNumCapturers());
694 int capture_id = vie_.GetCaptureId(channel_num);
695 EXPECT_EQ(channel_num, vie_.GetCaptureChannelId(capture_id));
696
697 // Delete the channel should disconnect the capturer.
698 delete channel_;
699 channel_ = NULL;
700 EXPECT_EQ(0, vie_.GetNumCapturers());
701}
702
703// Test that channel adds and removes renderer correctly.
704TEST_F(WebRtcVideoEngineTestFake, HasRenderer) {
705 EXPECT_TRUE(SetupEngine());
706 int channel_num = vie_.GetLastChannel();
707
708 EXPECT_TRUE(vie_.GetHasRenderer(channel_num));
709 EXPECT_FALSE(vie_.GetRenderStarted(channel_num));
710}
711
712// Test that rtcp is enabled on the channel.
713TEST_F(WebRtcVideoEngineTestFake, RtcpEnabled) {
714 EXPECT_TRUE(SetupEngine());
715 int channel_num = vie_.GetLastChannel();
716 EXPECT_EQ(webrtc::kRtcpCompound_RFC4585, vie_.GetRtcpStatus(channel_num));
717}
718
719// Test that key frame request method is set on the channel.
720TEST_F(WebRtcVideoEngineTestFake, KeyFrameRequestEnabled) {
721 EXPECT_TRUE(SetupEngine());
722 int channel_num = vie_.GetLastChannel();
723 EXPECT_EQ(webrtc::kViEKeyFrameRequestPliRtcp,
724 vie_.GetKeyFrameRequestMethod(channel_num));
725}
726
727// Test that remb receive and send is enabled for the default channel in a 1:1
728// call.
729TEST_F(WebRtcVideoEngineTestFake, RembEnabled) {
730 EXPECT_TRUE(SetupEngine());
731 int channel_num = vie_.GetLastChannel();
732 EXPECT_TRUE(channel_->AddSendStream(
733 cricket::StreamParams::CreateLegacy(1)));
734 EXPECT_TRUE(channel_->SetSendCodecs(engine_.codecs()));
735 EXPECT_TRUE(vie_.GetRembStatusBwPartition(channel_num));
736 EXPECT_TRUE(channel_->SetSend(true));
737 EXPECT_TRUE(vie_.GetRembStatusBwPartition(channel_num));
738 EXPECT_TRUE(vie_.GetRembStatusContribute(channel_num));
739}
740
741// When in conference mode, test that remb is enabled on a receive channel but
742// not for the default channel and that it uses the default channel for sending
743// remb packets.
744TEST_F(WebRtcVideoEngineTestFake, RembEnabledOnReceiveChannels) {
745 EXPECT_TRUE(SetupEngine());
746 int default_channel = vie_.GetLastChannel();
747 cricket::VideoOptions options;
748 options.conference_mode.Set(true);
749 EXPECT_TRUE(channel_->SetOptions(options));
750 EXPECT_TRUE(channel_->AddSendStream(
751 cricket::StreamParams::CreateLegacy(1)));
752 EXPECT_TRUE(channel_->SetSendCodecs(engine_.codecs()));
753 EXPECT_TRUE(vie_.GetRembStatusBwPartition(default_channel));
754 EXPECT_TRUE(vie_.GetRembStatusContribute(default_channel));
755 EXPECT_TRUE(channel_->SetSend(true));
756 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(1)));
757 int new_channel_num = vie_.GetLastChannel();
758 EXPECT_NE(default_channel, new_channel_num);
759
760 EXPECT_TRUE(vie_.GetRembStatusBwPartition(default_channel));
761 EXPECT_TRUE(vie_.GetRembStatusContribute(default_channel));
762 EXPECT_FALSE(vie_.GetRembStatusBwPartition(new_channel_num));
763 EXPECT_TRUE(vie_.GetRembStatusContribute(new_channel_num));
764}
765
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000766TEST_F(WebRtcVideoEngineTestFake, RecvStreamWithRtx) {
767 EXPECT_TRUE(SetupEngine());
768 int default_channel = vie_.GetLastChannel();
769 cricket::VideoOptions options;
770 options.conference_mode.Set(true);
771 EXPECT_TRUE(channel_->SetOptions(options));
772 EXPECT_TRUE(channel_->AddSendStream(
773 cricket::CreateSimWithRtxStreamParams("cname",
774 MAKE_VECTOR(kSsrcs3),
775 MAKE_VECTOR(kRtxSsrcs3))));
776 EXPECT_TRUE(channel_->SetSendCodecs(engine_.codecs()));
777 EXPECT_TRUE(channel_->SetSend(true));
778 EXPECT_TRUE(channel_->AddRecvStream(
779 cricket::CreateSimWithRtxStreamParams("cname",
780 MAKE_VECTOR(kSsrcs1),
781 MAKE_VECTOR(kRtxSsrc1))));
782 int new_channel_num = vie_.GetLastChannel();
783 EXPECT_NE(default_channel, new_channel_num);
784 EXPECT_EQ(4, vie_.GetRemoteRtxSsrc(new_channel_num));
785}
786
787TEST_F(WebRtcVideoEngineTestFake, RecvStreamNoRtx) {
788 EXPECT_TRUE(SetupEngine());
789 int default_channel = vie_.GetLastChannel();
790 cricket::VideoOptions options;
791 options.conference_mode.Set(true);
792 EXPECT_TRUE(channel_->SetOptions(options));
793 EXPECT_TRUE(channel_->AddSendStream(
794 cricket::CreateSimWithRtxStreamParams("cname",
795 MAKE_VECTOR(kSsrcs3),
796 MAKE_VECTOR(kRtxSsrcs3))));
797 EXPECT_TRUE(channel_->SetSendCodecs(engine_.codecs()));
798 EXPECT_TRUE(channel_->SetSend(true));
799 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(1)));
800 int new_channel_num = vie_.GetLastChannel();
801 EXPECT_NE(default_channel, new_channel_num);
802 EXPECT_EQ(-1, vie_.GetRemoteRtxSsrc(new_channel_num));
803}
804
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000805// Test support for RTP timestamp offset header extension.
buildbot@webrtc.org150835e2014-05-06 15:54:38 +0000806TEST_F(WebRtcVideoEngineTestFake, SendRtpTimestampOffsetHeaderExtensions) {
807 TestSetSendRtpHeaderExtensions(kRtpTimestampOffsetHeaderExtension);
808}
809TEST_F(WebRtcVideoEngineTestFake, RecvRtpTimestampOffsetHeaderExtensions) {
810 TestSetRecvRtpHeaderExtensions(kRtpTimestampOffsetHeaderExtension);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000811}
812
813// Test support for absolute send time header extension.
buildbot@webrtc.org150835e2014-05-06 15:54:38 +0000814TEST_F(WebRtcVideoEngineTestFake, SendAbsoluteSendTimeHeaderExtensions) {
815 TestSetSendRtpHeaderExtensions(kRtpAbsoluteSenderTimeHeaderExtension);
816}
817TEST_F(WebRtcVideoEngineTestFake, RecvAbsoluteSendTimeHeaderExtensions) {
818 TestSetRecvRtpHeaderExtensions(kRtpAbsoluteSenderTimeHeaderExtension);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000819}
820
821TEST_F(WebRtcVideoEngineTestFake, LeakyBucketTest) {
822 EXPECT_TRUE(SetupEngine());
823
824 // Verify this is off by default.
825 EXPECT_TRUE(channel_->AddSendStream(cricket::StreamParams::CreateLegacy(1)));
826 int first_send_channel = vie_.GetLastChannel();
827 EXPECT_FALSE(vie_.GetTransmissionSmoothingStatus(first_send_channel));
828
829 // Enable the experiment and verify.
830 cricket::VideoOptions options;
831 options.conference_mode.Set(true);
832 options.video_leaky_bucket.Set(true);
833 EXPECT_TRUE(channel_->SetOptions(options));
834 EXPECT_TRUE(vie_.GetTransmissionSmoothingStatus(first_send_channel));
835
836 // Add a receive channel and verify leaky bucket isn't enabled.
837 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(2)));
838 int recv_channel_num = vie_.GetLastChannel();
839 EXPECT_NE(first_send_channel, recv_channel_num);
840 EXPECT_FALSE(vie_.GetTransmissionSmoothingStatus(recv_channel_num));
841
842 // Add a new send stream and verify leaky bucket is enabled from start.
843 EXPECT_TRUE(channel_->AddSendStream(cricket::StreamParams::CreateLegacy(3)));
844 int second_send_channel = vie_.GetLastChannel();
845 EXPECT_NE(first_send_channel, second_send_channel);
846 EXPECT_TRUE(vie_.GetTransmissionSmoothingStatus(second_send_channel));
847}
848
henrike@webrtc.org6e3dbc22014-03-25 17:09:47 +0000849// Verify that SuspendBelowMinBitrate is enabled if it is set in the options.
850TEST_F(WebRtcVideoEngineTestFake, SuspendBelowMinBitrateTest) {
851 EXPECT_TRUE(SetupEngine());
852
853 // Verify this is off by default.
854 EXPECT_TRUE(channel_->AddSendStream(cricket::StreamParams::CreateLegacy(1)));
855 int first_send_channel = vie_.GetLastChannel();
856 EXPECT_FALSE(vie_.GetSuspendBelowMinBitrateStatus(first_send_channel));
857
858 // Enable the experiment and verify.
859 cricket::VideoOptions options;
860 options.suspend_below_min_bitrate.Set(true);
861 EXPECT_TRUE(channel_->SetOptions(options));
862 EXPECT_TRUE(vie_.GetSuspendBelowMinBitrateStatus(first_send_channel));
863
864 // Add a new send stream and verify suspend_below_min_bitrate is enabled.
865 EXPECT_TRUE(channel_->AddSendStream(cricket::StreamParams::CreateLegacy(2)));
866 int second_send_channel = vie_.GetLastChannel();
867 EXPECT_NE(first_send_channel, second_send_channel);
868 EXPECT_TRUE(vie_.GetSuspendBelowMinBitrateStatus(second_send_channel));
869}
870
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000871TEST_F(WebRtcVideoEngineTestFake, BufferedModeLatency) {
872 EXPECT_TRUE(SetupEngine());
873
874 // Verify this is off by default.
875 EXPECT_TRUE(channel_->AddSendStream(cricket::StreamParams::CreateLegacy(1)));
876 int first_send_channel = vie_.GetLastChannel();
877 EXPECT_EQ(0, vie_.GetSenderTargetDelay(first_send_channel));
878 EXPECT_EQ(0, vie_.GetReceiverTargetDelay(first_send_channel));
879
880 // Enable the experiment and verify. The default channel will have both
881 // sender and receiver buffered mode enabled.
882 cricket::VideoOptions options;
883 options.conference_mode.Set(true);
884 options.buffered_mode_latency.Set(100);
885 EXPECT_TRUE(channel_->SetOptions(options));
886 EXPECT_EQ(100, vie_.GetSenderTargetDelay(first_send_channel));
887 EXPECT_EQ(100, vie_.GetReceiverTargetDelay(first_send_channel));
888
889 // Add a receive channel and verify sender buffered mode isn't enabled.
890 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(2)));
891 int recv_channel_num = vie_.GetLastChannel();
892 EXPECT_NE(first_send_channel, recv_channel_num);
893 EXPECT_EQ(0, vie_.GetSenderTargetDelay(recv_channel_num));
894 EXPECT_EQ(100, vie_.GetReceiverTargetDelay(recv_channel_num));
895
896 // Add a new send stream and verify sender buffered mode is enabled.
897 EXPECT_TRUE(channel_->AddSendStream(cricket::StreamParams::CreateLegacy(3)));
898 int second_send_channel = vie_.GetLastChannel();
899 EXPECT_NE(first_send_channel, second_send_channel);
900 EXPECT_EQ(100, vie_.GetSenderTargetDelay(second_send_channel));
901 EXPECT_EQ(0, vie_.GetReceiverTargetDelay(second_send_channel));
902
903 // Disable sender buffered mode and verify.
904 options.buffered_mode_latency.Set(cricket::kBufferedModeDisabled);
905 EXPECT_TRUE(channel_->SetOptions(options));
906 EXPECT_EQ(0, vie_.GetSenderTargetDelay(first_send_channel));
907 EXPECT_EQ(0, vie_.GetReceiverTargetDelay(first_send_channel));
908 EXPECT_EQ(0, vie_.GetSenderTargetDelay(second_send_channel));
909 EXPECT_EQ(0, vie_.GetReceiverTargetDelay(second_send_channel));
910 EXPECT_EQ(0, vie_.GetSenderTargetDelay(recv_channel_num));
911 EXPECT_EQ(0, vie_.GetReceiverTargetDelay(recv_channel_num));
912}
913
914TEST_F(WebRtcVideoEngineTestFake, AdditiveVideoOptions) {
915 EXPECT_TRUE(SetupEngine());
916
917 EXPECT_TRUE(channel_->AddSendStream(cricket::StreamParams::CreateLegacy(1)));
918 int first_send_channel = vie_.GetLastChannel();
919 EXPECT_EQ(0, vie_.GetSenderTargetDelay(first_send_channel));
920 EXPECT_EQ(0, vie_.GetReceiverTargetDelay(first_send_channel));
921
922 cricket::VideoOptions options1;
923 options1.buffered_mode_latency.Set(100);
924 EXPECT_TRUE(channel_->SetOptions(options1));
925 EXPECT_EQ(100, vie_.GetSenderTargetDelay(first_send_channel));
926 EXPECT_EQ(100, vie_.GetReceiverTargetDelay(first_send_channel));
927 EXPECT_FALSE(vie_.GetTransmissionSmoothingStatus(first_send_channel));
928
929 cricket::VideoOptions options2;
930 options2.video_leaky_bucket.Set(true);
931 EXPECT_TRUE(channel_->SetOptions(options2));
932 EXPECT_TRUE(vie_.GetTransmissionSmoothingStatus(first_send_channel));
933 // The buffered_mode_latency still takes effect.
934 EXPECT_EQ(100, vie_.GetSenderTargetDelay(first_send_channel));
935 EXPECT_EQ(100, vie_.GetReceiverTargetDelay(first_send_channel));
936
937 options1.buffered_mode_latency.Set(50);
938 EXPECT_TRUE(channel_->SetOptions(options1));
939 EXPECT_EQ(50, vie_.GetSenderTargetDelay(first_send_channel));
940 EXPECT_EQ(50, vie_.GetReceiverTargetDelay(first_send_channel));
941 // The video_leaky_bucket still takes effect.
942 EXPECT_TRUE(vie_.GetTransmissionSmoothingStatus(first_send_channel));
943}
944
henrike@webrtc.orgb0ecc1c2014-03-26 22:44:28 +0000945TEST_F(WebRtcVideoEngineTestFake, SetCpuOveruseOptionsWithCaptureJitterMethod) {
946 EXPECT_TRUE(SetupEngine());
947
948 // Verify this is off by default.
949 EXPECT_TRUE(channel_->AddSendStream(cricket::StreamParams::CreateLegacy(1)));
950 int first_send_channel = vie_.GetLastChannel();
951 webrtc::CpuOveruseOptions cpu_option =
952 vie_.GetCpuOveruseOptions(first_send_channel);
953 EXPECT_EQ(0, cpu_option.low_capture_jitter_threshold_ms);
954 EXPECT_EQ(0, cpu_option.high_capture_jitter_threshold_ms);
955 EXPECT_FALSE(cpu_option.enable_capture_jitter_method);
956 EXPECT_FALSE(cpu_option.enable_encode_usage_method);
957
958 // Set low and high threshold and verify that cpu options are set.
959 cricket::VideoOptions options;
960 options.conference_mode.Set(true);
961 options.cpu_underuse_threshold.Set(10);
962 options.cpu_overuse_threshold.Set(20);
963 EXPECT_TRUE(channel_->SetOptions(options));
964 cpu_option = vie_.GetCpuOveruseOptions(first_send_channel);
965 EXPECT_EQ(10, cpu_option.low_capture_jitter_threshold_ms);
966 EXPECT_EQ(20, cpu_option.high_capture_jitter_threshold_ms);
967 EXPECT_TRUE(cpu_option.enable_capture_jitter_method);
968 EXPECT_FALSE(cpu_option.enable_encode_usage_method);
969
970 // Add a receive channel and verify that cpu options are not set.
971 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(2)));
972 int recv_channel_num = vie_.GetLastChannel();
973 EXPECT_NE(first_send_channel, recv_channel_num);
974 cpu_option = vie_.GetCpuOveruseOptions(recv_channel_num);
975 EXPECT_EQ(0, cpu_option.low_capture_jitter_threshold_ms);
976 EXPECT_EQ(0, cpu_option.high_capture_jitter_threshold_ms);
977 EXPECT_FALSE(cpu_option.enable_capture_jitter_method);
978 EXPECT_FALSE(cpu_option.enable_encode_usage_method);
979
980 // Add a new send stream and verify that cpu options are set from start.
981 EXPECT_TRUE(channel_->AddSendStream(cricket::StreamParams::CreateLegacy(3)));
982 int second_send_channel = vie_.GetLastChannel();
983 EXPECT_NE(first_send_channel, second_send_channel);
984 cpu_option = vie_.GetCpuOveruseOptions(second_send_channel);
985 EXPECT_EQ(10, cpu_option.low_capture_jitter_threshold_ms);
986 EXPECT_EQ(20, cpu_option.high_capture_jitter_threshold_ms);
987 EXPECT_TRUE(cpu_option.enable_capture_jitter_method);
988 EXPECT_FALSE(cpu_option.enable_encode_usage_method);
989}
990
991TEST_F(WebRtcVideoEngineTestFake, SetInvalidCpuOveruseThresholds) {
992 EXPECT_TRUE(SetupEngine());
993 EXPECT_TRUE(channel_->AddSendStream(cricket::StreamParams::CreateLegacy(1)));
994 int channel_num = vie_.GetLastChannel();
995
996 // Only low threshold set. Verify that cpu options are not set.
997 cricket::VideoOptions options;
998 options.conference_mode.Set(true);
999 options.cpu_underuse_threshold.Set(10);
1000 EXPECT_TRUE(channel_->SetOptions(options));
1001 webrtc::CpuOveruseOptions cpu_option = vie_.GetCpuOveruseOptions(channel_num);
1002 EXPECT_EQ(0, cpu_option.low_capture_jitter_threshold_ms);
1003 EXPECT_EQ(0, cpu_option.high_capture_jitter_threshold_ms);
1004 EXPECT_FALSE(cpu_option.enable_capture_jitter_method);
1005 EXPECT_FALSE(cpu_option.enable_encode_usage_method);
1006
1007 // Set high threshold to a negative value. Verify that options are not set.
1008 options.cpu_overuse_threshold.Set(-1);
1009 EXPECT_TRUE(channel_->SetOptions(options));
1010 cpu_option = vie_.GetCpuOveruseOptions(channel_num);
1011 EXPECT_EQ(0, cpu_option.low_capture_jitter_threshold_ms);
1012 EXPECT_EQ(0, cpu_option.high_capture_jitter_threshold_ms);
1013 EXPECT_FALSE(cpu_option.enable_capture_jitter_method);
1014 EXPECT_FALSE(cpu_option.enable_encode_usage_method);
1015
1016 // Low and high threshold valid. Verify that cpu options are set.
1017 options.cpu_overuse_threshold.Set(20);
1018 EXPECT_TRUE(channel_->SetOptions(options));
1019 cpu_option = vie_.GetCpuOveruseOptions(channel_num);
1020 EXPECT_EQ(10, cpu_option.low_capture_jitter_threshold_ms);
1021 EXPECT_EQ(20, cpu_option.high_capture_jitter_threshold_ms);
1022 EXPECT_TRUE(cpu_option.enable_capture_jitter_method);
1023 EXPECT_FALSE(cpu_option.enable_encode_usage_method);
1024}
1025
1026TEST_F(WebRtcVideoEngineTestFake, SetCpuOveruseOptionsWithEncodeUsageMethod) {
1027 EXPECT_TRUE(SetupEngine());
1028 EXPECT_TRUE(channel_->AddSendStream(cricket::StreamParams::CreateLegacy(1)));
1029 int first_send_channel = vie_.GetLastChannel();
1030
1031 // Set low and high threshold and enable encode usage method.
1032 // Verify that cpu options are set.
1033 cricket::VideoOptions options;
1034 options.conference_mode.Set(true);
1035 options.cpu_underuse_threshold.Set(10);
1036 options.cpu_overuse_threshold.Set(20);
1037 options.cpu_overuse_encode_usage.Set(true);
1038 EXPECT_TRUE(channel_->SetOptions(options));
1039 webrtc::CpuOveruseOptions cpu_option =
1040 vie_.GetCpuOveruseOptions(first_send_channel);
1041 EXPECT_EQ(10, cpu_option.low_encode_usage_threshold_percent);
1042 EXPECT_EQ(20, cpu_option.high_encode_usage_threshold_percent);
1043 EXPECT_FALSE(cpu_option.enable_capture_jitter_method);
1044 EXPECT_TRUE(cpu_option.enable_encode_usage_method);
1045
1046 // Add a new send stream and verify that cpu options are set from start.
1047 EXPECT_TRUE(channel_->AddSendStream(cricket::StreamParams::CreateLegacy(3)));
1048 int second_send_channel = vie_.GetLastChannel();
1049 EXPECT_NE(first_send_channel, second_send_channel);
1050 cpu_option = vie_.GetCpuOveruseOptions(second_send_channel);
1051 EXPECT_EQ(10, cpu_option.low_encode_usage_threshold_percent);
1052 EXPECT_EQ(20, cpu_option.high_encode_usage_threshold_percent);
1053 EXPECT_FALSE(cpu_option.enable_capture_jitter_method);
1054 EXPECT_TRUE(cpu_option.enable_encode_usage_method);
1055}
henrike@webrtc.orgb0ecc1c2014-03-26 22:44:28 +00001056
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001057// Test that AddRecvStream doesn't create new channel for 1:1 call.
1058TEST_F(WebRtcVideoEngineTestFake, AddRecvStream1On1) {
1059 EXPECT_TRUE(SetupEngine());
1060 int channel_num = vie_.GetLastChannel();
1061 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(1)));
1062 EXPECT_EQ(channel_num, vie_.GetLastChannel());
1063}
1064
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +00001065// Test that NACK, PLI and REMB are enabled for internal codec.
1066TEST_F(WebRtcVideoEngineTestFake, InternalCodecFeedbackParams) {
1067 EXPECT_TRUE(SetupEngine());
1068
1069 std::vector<cricket::VideoCodec> codecs(engine_.codecs());
1070 // Vp8 will appear at the beginning.
1071 size_t pos = 0;
1072 EXPECT_EQ("VP8", codecs[pos].name);
1073 VerifyCodecFeedbackParams(codecs[pos]);
1074}
1075
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001076// Test that AddRecvStream doesn't change remb for 1:1 call.
1077TEST_F(WebRtcVideoEngineTestFake, NoRembChangeAfterAddRecvStream) {
1078 EXPECT_TRUE(SetupEngine());
1079 int channel_num = vie_.GetLastChannel();
1080 EXPECT_TRUE(channel_->AddSendStream(
1081 cricket::StreamParams::CreateLegacy(1)));
1082 EXPECT_TRUE(channel_->SetSendCodecs(engine_.codecs()));
1083 EXPECT_TRUE(vie_.GetRembStatusBwPartition(channel_num));
1084 EXPECT_TRUE(vie_.GetRembStatusContribute(channel_num));
1085 EXPECT_TRUE(channel_->SetSend(true));
1086 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(1)));
1087 EXPECT_TRUE(vie_.GetRembStatusBwPartition(channel_num));
1088 EXPECT_TRUE(vie_.GetRembStatusContribute(channel_num));
1089}
1090
1091// Verify default REMB setting and that it can be turned on and off.
1092TEST_F(WebRtcVideoEngineTestFake, RembOnOff) {
1093 EXPECT_TRUE(SetupEngine());
1094 int channel_num = vie_.GetLastChannel();
1095 // Verify REMB sending is always off by default.
1096 EXPECT_FALSE(vie_.GetRembStatusBwPartition(channel_num));
1097
1098 // Verify that REMB is turned on when setting default codecs since the
1099 // default codecs have REMB enabled.
1100 EXPECT_TRUE(channel_->SetSendCodecs(engine_.codecs()));
1101 EXPECT_TRUE(vie_.GetRembStatusBwPartition(channel_num));
1102
1103 // Verify that REMB is turned off when codecs without REMB are set.
1104 std::vector<cricket::VideoCodec> codecs = engine_.codecs();
1105 // Clearing the codecs' FeedbackParams and setting send codecs should disable
1106 // REMB.
1107 for (std::vector<cricket::VideoCodec>::iterator iter = codecs.begin();
1108 iter != codecs.end(); ++iter) {
1109 // Intersecting with empty will clear the FeedbackParams.
1110 cricket::FeedbackParams empty_params;
1111 iter->feedback_params.Intersect(empty_params);
1112 EXPECT_TRUE(iter->feedback_params.params().empty());
1113 }
1114 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1115 EXPECT_FALSE(vie_.GetRembStatusBwPartition(channel_num));
1116}
1117
1118// Test that nack is enabled on the channel if we don't offer red/fec.
1119TEST_F(WebRtcVideoEngineTestFake, NackEnabled) {
1120 EXPECT_TRUE(SetupEngine());
1121 int channel_num = vie_.GetLastChannel();
1122 std::vector<cricket::VideoCodec> codecs(engine_.codecs());
1123 codecs.resize(1); // toss out red and ulpfec
1124 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1125 EXPECT_TRUE(vie_.GetNackStatus(channel_num));
1126}
1127
1128// Test that we enable hybrid NACK FEC mode.
1129TEST_F(WebRtcVideoEngineTestFake, HybridNackFec) {
1130 EXPECT_TRUE(SetupEngine());
1131 int channel_num = vie_.GetLastChannel();
1132 EXPECT_TRUE(channel_->SetRecvCodecs(engine_.codecs()));
1133 EXPECT_TRUE(channel_->SetSendCodecs(engine_.codecs()));
1134 EXPECT_TRUE(vie_.GetHybridNackFecStatus(channel_num));
1135 EXPECT_FALSE(vie_.GetNackStatus(channel_num));
1136}
1137
1138// Test that we enable hybrid NACK FEC mode when calling SetSendCodecs and
1139// SetReceiveCodecs in reversed order.
1140TEST_F(WebRtcVideoEngineTestFake, HybridNackFecReversedOrder) {
1141 EXPECT_TRUE(SetupEngine());
1142 int channel_num = vie_.GetLastChannel();
1143 EXPECT_TRUE(channel_->SetSendCodecs(engine_.codecs()));
1144 EXPECT_TRUE(channel_->SetRecvCodecs(engine_.codecs()));
1145 EXPECT_TRUE(vie_.GetHybridNackFecStatus(channel_num));
1146 EXPECT_FALSE(vie_.GetNackStatus(channel_num));
1147}
1148
1149// Test NACK vs Hybrid NACK/FEC interop call setup, i.e. only use NACK even if
1150// red/fec is offered as receive codec.
1151TEST_F(WebRtcVideoEngineTestFake, VideoProtectionInterop) {
1152 EXPECT_TRUE(SetupEngine());
1153 int channel_num = vie_.GetLastChannel();
1154 std::vector<cricket::VideoCodec> recv_codecs(engine_.codecs());
1155 std::vector<cricket::VideoCodec> send_codecs(engine_.codecs());
1156 // Only add VP8 as send codec.
1157 send_codecs.resize(1);
1158 EXPECT_TRUE(channel_->SetRecvCodecs(recv_codecs));
1159 EXPECT_TRUE(channel_->SetSendCodecs(send_codecs));
1160 EXPECT_FALSE(vie_.GetHybridNackFecStatus(channel_num));
1161 EXPECT_TRUE(vie_.GetNackStatus(channel_num));
1162}
1163
1164// Test NACK vs Hybrid NACK/FEC interop call setup, i.e. only use NACK even if
1165// red/fec is offered as receive codec. Call order reversed compared to
1166// VideoProtectionInterop.
1167TEST_F(WebRtcVideoEngineTestFake, VideoProtectionInteropReversed) {
1168 EXPECT_TRUE(SetupEngine());
1169 int channel_num = vie_.GetLastChannel();
1170 std::vector<cricket::VideoCodec> recv_codecs(engine_.codecs());
1171 std::vector<cricket::VideoCodec> send_codecs(engine_.codecs());
1172 // Only add VP8 as send codec.
1173 send_codecs.resize(1);
1174 EXPECT_TRUE(channel_->SetSendCodecs(send_codecs));
1175 EXPECT_TRUE(channel_->SetRecvCodecs(recv_codecs));
1176 EXPECT_FALSE(vie_.GetHybridNackFecStatus(channel_num));
1177 EXPECT_TRUE(vie_.GetNackStatus(channel_num));
1178}
1179
1180// Test that NACK, not hybrid mode, is enabled in conference mode.
1181TEST_F(WebRtcVideoEngineTestFake, HybridNackFecConference) {
1182 EXPECT_TRUE(SetupEngine());
1183 // Setup the send channel.
1184 int send_channel_num = vie_.GetLastChannel();
1185 cricket::VideoOptions options;
1186 options.conference_mode.Set(true);
1187 EXPECT_TRUE(channel_->SetOptions(options));
1188 EXPECT_TRUE(channel_->SetRecvCodecs(engine_.codecs()));
1189 EXPECT_TRUE(channel_->SetSendCodecs(engine_.codecs()));
1190 EXPECT_FALSE(vie_.GetHybridNackFecStatus(send_channel_num));
1191 EXPECT_TRUE(vie_.GetNackStatus(send_channel_num));
1192 // Add a receive stream.
1193 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(1)));
1194 int receive_channel_num = vie_.GetLastChannel();
1195 EXPECT_FALSE(vie_.GetHybridNackFecStatus(receive_channel_num));
1196 EXPECT_TRUE(vie_.GetNackStatus(receive_channel_num));
1197}
1198
1199// Test that when AddRecvStream in conference mode, a new channel is created
1200// for receiving. And the new channel's "original channel" is the send channel.
1201TEST_F(WebRtcVideoEngineTestFake, AddRemoveRecvStreamConference) {
1202 EXPECT_TRUE(SetupEngine());
1203 // Setup the send channel.
1204 int send_channel_num = vie_.GetLastChannel();
1205 cricket::VideoOptions options;
1206 options.conference_mode.Set(true);
1207 EXPECT_TRUE(channel_->SetOptions(options));
1208 // Add a receive stream.
1209 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(1)));
1210 int receive_channel_num = vie_.GetLastChannel();
1211 EXPECT_EQ(send_channel_num, vie_.GetOriginalChannelId(receive_channel_num));
1212 EXPECT_TRUE(channel_->RemoveRecvStream(1));
1213 EXPECT_FALSE(vie_.IsChannel(receive_channel_num));
1214}
1215
henrike@webrtc.org6e3dbc22014-03-25 17:09:47 +00001216// Test that adding/removing stream with 0 ssrc should fail (and not crash).
1217// For crbug/351699 and 350988.
1218TEST_F(WebRtcVideoEngineTestFake, AddRemoveRecvStreamWith0Ssrc) {
1219 EXPECT_TRUE(SetupEngine());
1220 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(1)));
1221 EXPECT_FALSE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(0)));
1222 EXPECT_FALSE(channel_->RemoveRecvStream(0));
1223 EXPECT_TRUE(channel_->RemoveRecvStream(1));
1224}
1225
1226TEST_F(WebRtcVideoEngineTestFake, AddRemoveSendStreamWith0Ssrc) {
1227 EXPECT_TRUE(SetupEngine());
1228 EXPECT_TRUE(channel_->AddSendStream(cricket::StreamParams::CreateLegacy(1)));
1229 EXPECT_FALSE(channel_->AddSendStream(cricket::StreamParams::CreateLegacy(0)));
1230 EXPECT_FALSE(channel_->RemoveSendStream(0));
1231 EXPECT_TRUE(channel_->RemoveSendStream(1));
1232}
1233
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001234// Test that we can create a channel and start/stop rendering out on it.
1235TEST_F(WebRtcVideoEngineTestFake, SetRender) {
1236 EXPECT_TRUE(SetupEngine());
1237 int channel_num = vie_.GetLastChannel();
1238
1239 // Verify we can start/stop/start/stop rendering.
1240 EXPECT_TRUE(channel_->SetRender(true));
1241 EXPECT_TRUE(vie_.GetRenderStarted(channel_num));
1242 EXPECT_TRUE(channel_->SetRender(false));
1243 EXPECT_FALSE(vie_.GetRenderStarted(channel_num));
1244 EXPECT_TRUE(channel_->SetRender(true));
1245 EXPECT_TRUE(vie_.GetRenderStarted(channel_num));
1246 EXPECT_TRUE(channel_->SetRender(false));
1247 EXPECT_FALSE(vie_.GetRenderStarted(channel_num));
1248}
1249
1250// Test that we can create a channel and start/stop sending out on it.
1251TEST_F(WebRtcVideoEngineTestFake, SetSend) {
1252 EXPECT_TRUE(SetupEngine());
1253 int channel_num = vie_.GetLastChannel();
wu@webrtc.orgb9a088b2014-02-13 23:18:49 +00001254 // Verify receiving is also started.
1255 EXPECT_TRUE(vie_.GetReceive(channel_num));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001256
1257 // Set send codecs on the channel.
1258 std::vector<cricket::VideoCodec> codecs;
1259 codecs.push_back(kVP8Codec);
1260 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1261 EXPECT_TRUE(channel_->AddSendStream(
1262 cricket::StreamParams::CreateLegacy(123)));
1263
1264 // Verify we can start/stop/start/stop sending.
1265 EXPECT_TRUE(channel_->SetSend(true));
1266 EXPECT_TRUE(vie_.GetSend(channel_num));
1267 EXPECT_TRUE(channel_->SetSend(false));
1268 EXPECT_FALSE(vie_.GetSend(channel_num));
1269 EXPECT_TRUE(channel_->SetSend(true));
1270 EXPECT_TRUE(vie_.GetSend(channel_num));
1271 EXPECT_TRUE(channel_->SetSend(false));
1272 EXPECT_FALSE(vie_.GetSend(channel_num));
1273}
1274
1275// Test that we set bandwidth properly when using full auto bandwidth mode.
1276TEST_F(WebRtcVideoEngineTestFake, SetBandwidthAuto) {
1277 EXPECT_TRUE(SetupEngine());
1278 int channel_num = vie_.GetLastChannel();
1279 EXPECT_TRUE(channel_->SetSendCodecs(engine_.codecs()));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001280 EXPECT_TRUE(channel_->SetMaxSendBandwidth(cricket::kAutoBandwidth));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001281 VerifyVP8SendCodec(channel_num, kVP8Codec.width, kVP8Codec.height);
1282}
1283
1284// Test that we set bandwidth properly when using auto with upper bound.
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001285TEST_F(WebRtcVideoEngineTestFake, SetBandwidthCapped) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001286 EXPECT_TRUE(SetupEngine());
1287 int channel_num = vie_.GetLastChannel();
1288 EXPECT_TRUE(channel_->SetSendCodecs(engine_.codecs()));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001289 EXPECT_TRUE(channel_->SetMaxSendBandwidth(768000));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001290 VerifyVP8SendCodec(channel_num, kVP8Codec.width, kVP8Codec.height, 0, 768U);
1291}
1292
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001293// Test that we reduce the start bandwidth when the requested max is less than
1294// the default start bandwidth.
1295TEST_F(WebRtcVideoEngineTestFake, SetMaxBandwidthBelowDefaultStart) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001296 EXPECT_TRUE(SetupEngine());
1297 int channel_num = vie_.GetLastChannel();
1298 EXPECT_TRUE(channel_->SetSendCodecs(engine_.codecs()));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001299 int max_bandwidth_kbps = (kMinBandwidthKbps + kStartBandwidthKbps) / 2;
1300 EXPECT_TRUE(channel_->SetMaxSendBandwidth(max_bandwidth_kbps * 1000));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001301 VerifyVP8SendCodec(channel_num, kVP8Codec.width, kVP8Codec.height, 0,
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001302 max_bandwidth_kbps, kMinBandwidthKbps, max_bandwidth_kbps);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001303}
1304
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001305// Test that we reduce the min bandwidth when the requested max is less than
1306// the min bandwidth.
1307TEST_F(WebRtcVideoEngineTestFake, SetMaxBandwidthBelowMin) {
1308 EXPECT_TRUE(SetupEngine());
1309 int channel_num = vie_.GetLastChannel();
1310 EXPECT_TRUE(channel_->SetSendCodecs(engine_.codecs()));
1311 int max_bandwidth_kbps = kMinBandwidthKbps / 2;
1312 EXPECT_TRUE(channel_->SetMaxSendBandwidth(max_bandwidth_kbps * 1000));
1313 VerifyVP8SendCodec(channel_num, kVP8Codec.width, kVP8Codec.height, 0,
1314 max_bandwidth_kbps, max_bandwidth_kbps, max_bandwidth_kbps);
1315}
1316
1317// Test that the start bandwidth can be controlled separately from the max
1318// bandwidth.
1319TEST_F(WebRtcVideoEngineTestFake, SetStartBandwidth) {
1320 EXPECT_TRUE(SetupEngine());
1321 int channel_num = vie_.GetLastChannel();
1322 EXPECT_TRUE(channel_->SetSendCodecs(engine_.codecs()));
1323 int start_bandwidth_kbps = kStartBandwidthKbps + 1;
1324 EXPECT_TRUE(channel_->SetStartSendBandwidth(start_bandwidth_kbps * 1000));
1325 VerifyVP8SendCodec(channel_num, kVP8Codec.width, kVP8Codec.height, 0,
1326 kMaxBandwidthKbps, kMinBandwidthKbps, start_bandwidth_kbps);
1327
1328 // Check that SetMaxSendBandwidth doesn't overwrite the start bandwidth.
1329 int max_bandwidth_kbps = kMaxBandwidthKbps + 1;
1330 EXPECT_TRUE(channel_->SetMaxSendBandwidth(max_bandwidth_kbps * 1000));
1331 VerifyVP8SendCodec(channel_num, kVP8Codec.width, kVP8Codec.height, 0,
1332 max_bandwidth_kbps, kMinBandwidthKbps, start_bandwidth_kbps);
1333}
1334
wu@webrtc.org1e6cb2c2014-03-24 17:01:50 +00001335// Test that the start bandwidth can be controlled by experiment.
1336TEST_F(WebRtcVideoEngineTestFake, SetStartBandwidthOption) {
1337 EXPECT_TRUE(SetupEngine());
1338 int channel_num = vie_.GetLastChannel();
1339 EXPECT_TRUE(channel_->SetSendCodecs(engine_.codecs()));
1340 int start_bandwidth_kbps = kStartBandwidthKbps;
1341 EXPECT_TRUE(channel_->SetStartSendBandwidth(start_bandwidth_kbps * 1000));
1342 VerifyVP8SendCodec(channel_num, kVP8Codec.width, kVP8Codec.height, 0,
1343 kMaxBandwidthKbps, kMinBandwidthKbps, start_bandwidth_kbps);
1344
1345 // Set the start bitrate option.
1346 start_bandwidth_kbps = 1000;
1347 cricket::VideoOptions options;
1348 options.video_start_bitrate.Set(
1349 start_bandwidth_kbps);
1350 EXPECT_TRUE(channel_->SetOptions(options));
1351
1352 // Check that start bitrate has changed to the new value.
1353 VerifyVP8SendCodec(channel_num, kVP8Codec.width, kVP8Codec.height, 0,
1354 kMaxBandwidthKbps, kMinBandwidthKbps, start_bandwidth_kbps);
1355}
1356
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001357// Test that SetMaxSendBandwidth is ignored in conference mode.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001358TEST_F(WebRtcVideoEngineTestFake, SetBandwidthInConference) {
1359 EXPECT_TRUE(SetupEngine());
1360 int channel_num = vie_.GetLastChannel();
1361 cricket::VideoOptions options;
1362 options.conference_mode.Set(true);
1363 EXPECT_TRUE(channel_->SetOptions(options));
1364 EXPECT_TRUE(channel_->SetSendCodecs(engine_.codecs()));
1365 VerifyVP8SendCodec(channel_num, kVP8Codec.width, kVP8Codec.height);
1366
1367 // Set send bandwidth.
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001368 EXPECT_TRUE(channel_->SetMaxSendBandwidth(768000));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001369
1370 // Verify bitrate not changed.
1371 webrtc::VideoCodec gcodec;
1372 EXPECT_EQ(0, vie_.GetSendCodec(channel_num, gcodec));
1373 EXPECT_EQ(kMinBandwidthKbps, gcodec.minBitrate);
1374 EXPECT_EQ(kStartBandwidthKbps, gcodec.startBitrate);
1375 EXPECT_EQ(kMaxBandwidthKbps, gcodec.maxBitrate);
1376 EXPECT_NE(768U, gcodec.minBitrate);
1377 EXPECT_NE(768U, gcodec.startBitrate);
1378 EXPECT_NE(768U, gcodec.maxBitrate);
1379}
1380
1381// Test that sending screencast frames doesn't change bitrate.
1382TEST_F(WebRtcVideoEngineTestFake, SetBandwidthScreencast) {
1383 EXPECT_TRUE(SetupEngine());
1384 int channel_num = vie_.GetLastChannel();
1385
1386 // Set send codec.
1387 cricket::VideoCodec codec(kVP8Codec);
1388 std::vector<cricket::VideoCodec> codec_list;
1389 codec_list.push_back(codec);
1390 EXPECT_TRUE(channel_->AddSendStream(
1391 cricket::StreamParams::CreateLegacy(123)));
1392 EXPECT_TRUE(channel_->SetSendCodecs(codec_list));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001393 EXPECT_TRUE(channel_->SetMaxSendBandwidth(111000));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001394 EXPECT_TRUE(channel_->SetSend(true));
1395
1396 SendI420ScreencastFrame(kVP8Codec.width, kVP8Codec.height);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001397 VerifyVP8SendCodec(channel_num, kVP8Codec.width, kVP8Codec.height, 0, 111);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001398}
1399
1400
1401// Test SetSendSsrc.
1402TEST_F(WebRtcVideoEngineTestFake, SetSendSsrcAndCname) {
1403 EXPECT_TRUE(SetupEngine());
1404 int channel_num = vie_.GetLastChannel();
1405
1406 cricket::StreamParams stream;
1407 stream.ssrcs.push_back(1234);
1408 stream.cname = "cname";
1409 channel_->AddSendStream(stream);
1410
1411 unsigned int ssrc = 0;
1412 EXPECT_EQ(0, vie_.GetLocalSSRC(channel_num, ssrc));
1413 EXPECT_EQ(1234U, ssrc);
1414 EXPECT_EQ(1, vie_.GetNumSsrcs(channel_num));
1415
1416 char rtcp_cname[256];
1417 EXPECT_EQ(0, vie_.GetRTCPCName(channel_num, rtcp_cname));
1418 EXPECT_STREQ("cname", rtcp_cname);
1419}
1420
1421
1422// Test that the local SSRC is the same on sending and receiving channels if the
1423// receive channel is created before the send channel.
1424TEST_F(WebRtcVideoEngineTestFake, SetSendSsrcAfterCreatingReceiveChannel) {
1425 EXPECT_TRUE(SetupEngine());
1426
1427 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(1)));
1428 int receive_channel_num = vie_.GetLastChannel();
1429 cricket::StreamParams stream = cricket::StreamParams::CreateLegacy(1234);
1430 EXPECT_TRUE(channel_->AddSendStream(stream));
1431 int send_channel_num = vie_.GetLastChannel();
1432 unsigned int ssrc = 0;
1433 EXPECT_EQ(0, vie_.GetLocalSSRC(send_channel_num, ssrc));
1434 EXPECT_EQ(1234U, ssrc);
1435 EXPECT_EQ(1, vie_.GetNumSsrcs(send_channel_num));
1436 ssrc = 0;
1437 EXPECT_EQ(0, vie_.GetLocalSSRC(receive_channel_num, ssrc));
1438 EXPECT_EQ(1234U, ssrc);
1439 EXPECT_EQ(1, vie_.GetNumSsrcs(receive_channel_num));
1440}
1441
1442
1443// Test SetOptions with denoising flag.
1444TEST_F(WebRtcVideoEngineTestFake, SetOptionsWithDenoising) {
1445 EXPECT_TRUE(SetupEngine());
1446 EXPECT_EQ(1, vie_.GetNumCapturers());
1447 int channel_num = vie_.GetLastChannel();
1448 int capture_id = vie_.GetCaptureId(channel_num);
1449 // Set send codecs on the channel.
1450 std::vector<cricket::VideoCodec> codecs;
1451 codecs.push_back(kVP8Codec);
1452 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1453
1454 // Set options with OPT_VIDEO_NOISE_REDUCTION flag.
1455 cricket::VideoOptions options;
1456 options.video_noise_reduction.Set(true);
1457 EXPECT_TRUE(channel_->SetOptions(options));
1458
1459 // Verify capture has denoising turned on.
1460 webrtc::VideoCodec send_codec;
1461 memset(&send_codec, 0, sizeof(send_codec)); // avoid uninitialized warning
1462 EXPECT_EQ(0, vie_.GetSendCodec(channel_num, send_codec));
1463 EXPECT_TRUE(send_codec.codecSpecific.VP8.denoisingOn);
1464 EXPECT_FALSE(vie_.GetCaptureDenoising(capture_id));
1465
1466 // Set options back to zero.
1467 options.video_noise_reduction.Set(false);
1468 EXPECT_TRUE(channel_->SetOptions(options));
1469
1470 // Verify capture has denoising turned off.
1471 EXPECT_EQ(0, vie_.GetSendCodec(channel_num, send_codec));
1472 EXPECT_FALSE(send_codec.codecSpecific.VP8.denoisingOn);
1473 EXPECT_FALSE(vie_.GetCaptureDenoising(capture_id));
1474}
1475
wu@webrtc.orga8910d22014-01-23 22:12:45 +00001476TEST_F(WebRtcVideoEngineTestFake, MultipleSendStreamsWithOneCapturer) {
wu@webrtc.org24301a62013-12-13 19:17:43 +00001477 EXPECT_TRUE(SetupEngine());
1478
1479 // Start the capturer
1480 cricket::FakeVideoCapturer capturer;
1481 cricket::VideoFormat capture_format_vga = cricket::VideoFormat(640, 480,
1482 cricket::VideoFormat::FpsToInterval(30), cricket::FOURCC_I420);
1483 EXPECT_EQ(cricket::CS_RUNNING, capturer.Start(capture_format_vga));
1484
1485 // Add send streams and connect the capturer
1486 for (unsigned int i = 0; i < sizeof(kSsrcs2)/sizeof(kSsrcs2[0]); ++i) {
1487 EXPECT_TRUE(channel_->AddSendStream(
1488 cricket::StreamParams::CreateLegacy(kSsrcs2[i])));
1489 // Register the capturer to the ssrc.
1490 EXPECT_TRUE(channel_->SetCapturer(kSsrcs2[i], &capturer));
1491 }
1492
1493 const int channel0 = vie_.GetChannelFromLocalSsrc(kSsrcs2[0]);
1494 ASSERT_NE(-1, channel0);
1495 const int channel1 = vie_.GetChannelFromLocalSsrc(kSsrcs2[1]);
1496 ASSERT_NE(-1, channel1);
1497 ASSERT_NE(channel0, channel1);
1498
wu@webrtc.orgb9a088b2014-02-13 23:18:49 +00001499 // Both channels should have started receiving after created.
1500 EXPECT_TRUE(vie_.GetReceive(channel0));
1501 EXPECT_TRUE(vie_.GetReceive(channel1));
1502
wu@webrtc.org24301a62013-12-13 19:17:43 +00001503 // Set send codec.
1504 std::vector<cricket::VideoCodec> codecs;
1505 cricket::VideoCodec send_codec(100, "VP8", 640, 480, 30, 0);
1506 codecs.push_back(send_codec);
1507 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1508
wu@webrtc.orgb9a088b2014-02-13 23:18:49 +00001509 EXPECT_TRUE(channel_->SetSend(true));
1510 EXPECT_TRUE(vie_.GetSend(channel0));
1511 EXPECT_TRUE(vie_.GetSend(channel1));
1512
wu@webrtc.org24301a62013-12-13 19:17:43 +00001513 EXPECT_TRUE(capturer.CaptureFrame());
1514 EXPECT_EQ(1, vie_.GetIncomingFrameNum(channel0));
1515 EXPECT_EQ(1, vie_.GetIncomingFrameNum(channel1));
1516
1517 EXPECT_TRUE(channel_->RemoveSendStream(kSsrcs2[0]));
1518 EXPECT_TRUE(capturer.CaptureFrame());
1519 // channel0 is the default channel, so it won't be deleted.
1520 // But it should be disconnected from the capturer.
1521 EXPECT_EQ(1, vie_.GetIncomingFrameNum(channel0));
1522 EXPECT_EQ(2, vie_.GetIncomingFrameNum(channel1));
1523
1524 EXPECT_TRUE(channel_->RemoveSendStream(kSsrcs2[1]));
1525 EXPECT_TRUE(capturer.CaptureFrame());
1526 EXPECT_EQ(1, vie_.GetIncomingFrameNum(channel0));
1527 // channel1 has already been deleted.
1528 EXPECT_EQ(-1, vie_.GetIncomingFrameNum(channel1));
1529}
1530
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001531
buildbot@webrtc.orga18b4c92014-05-06 17:48:14 +00001532TEST_F(WebRtcVideoEngineTestFake, SendReceiveBitratesStats) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001533 EXPECT_TRUE(SetupEngine());
1534 cricket::VideoOptions options;
1535 options.conference_mode.Set(true);
1536 EXPECT_TRUE(channel_->SetOptions(options));
1537 EXPECT_TRUE(channel_->AddSendStream(
1538 cricket::StreamParams::CreateLegacy(1)));
buildbot@webrtc.orga18b4c92014-05-06 17:48:14 +00001539 int first_send_channel = vie_.GetLastChannel();
1540 EXPECT_TRUE(channel_->AddSendStream(
1541 cricket::StreamParams::CreateLegacy(2)));
1542 int second_send_channel = vie_.GetLastChannel();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001543 cricket::VideoCodec codec(kVP8Codec720p);
1544 std::vector<cricket::VideoCodec> codec_list;
1545 codec_list.push_back(codec);
1546 EXPECT_TRUE(channel_->SetSendCodecs(codec_list));
1547
1548 EXPECT_TRUE(channel_->AddRecvStream(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001549 cricket::StreamParams::CreateLegacy(3)));
buildbot@webrtc.orga18b4c92014-05-06 17:48:14 +00001550 int first_receive_channel = vie_.GetLastChannel();
1551 EXPECT_NE(first_send_channel, first_receive_channel);
1552 EXPECT_TRUE(channel_->AddRecvStream(
1553 cricket::StreamParams::CreateLegacy(4)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001554 int second_receive_channel = vie_.GetLastChannel();
1555 EXPECT_NE(first_receive_channel, second_receive_channel);
1556
1557 cricket::VideoMediaInfo info;
wu@webrtc.orgb9a088b2014-02-13 23:18:49 +00001558 EXPECT_TRUE(channel_->GetStats(cricket::StatsOptions(), &info));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001559 ASSERT_EQ(1U, info.bw_estimations.size());
1560 ASSERT_EQ(0, info.bw_estimations[0].actual_enc_bitrate);
1561 ASSERT_EQ(0, info.bw_estimations[0].transmit_bitrate);
1562 ASSERT_EQ(0, info.bw_estimations[0].retransmit_bitrate);
1563 ASSERT_EQ(0, info.bw_estimations[0].available_send_bandwidth);
1564 ASSERT_EQ(0, info.bw_estimations[0].available_recv_bandwidth);
1565 ASSERT_EQ(0, info.bw_estimations[0].target_enc_bitrate);
1566
1567 // Start sending and receiving on one of the channels and verify bitrates.
buildbot@webrtc.orga18b4c92014-05-06 17:48:14 +00001568 EXPECT_EQ(0, vie_.StartSend(first_send_channel));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001569 int send_video_bitrate = 800;
1570 int send_fec_bitrate = 100;
1571 int send_nack_bitrate = 20;
1572 int send_total_bitrate = send_video_bitrate + send_fec_bitrate +
1573 send_nack_bitrate;
buildbot@webrtc.orga18b4c92014-05-06 17:48:14 +00001574 int send_bandwidth = 1900;
1575 vie_.SetSendBitrates(first_send_channel, send_video_bitrate, send_fec_bitrate,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001576 send_nack_bitrate);
buildbot@webrtc.orga18b4c92014-05-06 17:48:14 +00001577 vie_.SetSendBandwidthEstimate(first_send_channel, send_bandwidth);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001578
1579 EXPECT_EQ(0, vie_.StartReceive(first_receive_channel));
buildbot@webrtc.orga18b4c92014-05-06 17:48:14 +00001580 int receive_bandwidth = 600;
1581 vie_.SetReceiveBandwidthEstimate(first_receive_channel, receive_bandwidth);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001582
1583 info.Clear();
wu@webrtc.orgb9a088b2014-02-13 23:18:49 +00001584 EXPECT_TRUE(channel_->GetStats(cricket::StatsOptions(), &info));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001585 ASSERT_EQ(1U, info.bw_estimations.size());
1586 ASSERT_EQ(send_video_bitrate, info.bw_estimations[0].actual_enc_bitrate);
1587 ASSERT_EQ(send_total_bitrate, info.bw_estimations[0].transmit_bitrate);
1588 ASSERT_EQ(send_nack_bitrate, info.bw_estimations[0].retransmit_bitrate);
1589 ASSERT_EQ(send_bandwidth, info.bw_estimations[0].available_send_bandwidth);
buildbot@webrtc.orga18b4c92014-05-06 17:48:14 +00001590 ASSERT_EQ(receive_bandwidth, info.bw_estimations[0].available_recv_bandwidth);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001591 ASSERT_EQ(send_video_bitrate, info.bw_estimations[0].target_enc_bitrate);
1592
1593 // Start receiving on the second channel and verify received rate.
buildbot@webrtc.orga18b4c92014-05-06 17:48:14 +00001594 EXPECT_EQ(0, vie_.StartSend(second_send_channel));
1595 vie_.SetSendBitrates(second_send_channel,
1596 send_video_bitrate,
1597 send_fec_bitrate,
1598 send_nack_bitrate);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001599 EXPECT_EQ(0, vie_.StartReceive(second_receive_channel));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001600
1601 info.Clear();
wu@webrtc.orgb9a088b2014-02-13 23:18:49 +00001602 EXPECT_TRUE(channel_->GetStats(cricket::StatsOptions(), &info));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001603 ASSERT_EQ(1U, info.bw_estimations.size());
buildbot@webrtc.orga18b4c92014-05-06 17:48:14 +00001604 ASSERT_EQ(2 * send_video_bitrate, info.bw_estimations[0].actual_enc_bitrate);
1605 ASSERT_EQ(2 * send_total_bitrate, info.bw_estimations[0].transmit_bitrate);
1606 ASSERT_EQ(2 * send_nack_bitrate, info.bw_estimations[0].retransmit_bitrate);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001607 ASSERT_EQ(send_bandwidth, info.bw_estimations[0].available_send_bandwidth);
buildbot@webrtc.orga18b4c92014-05-06 17:48:14 +00001608 ASSERT_EQ(receive_bandwidth, info.bw_estimations[0].available_recv_bandwidth);
1609 ASSERT_EQ(2 * send_video_bitrate, info.bw_estimations[0].target_enc_bitrate);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001610}
1611
1612TEST_F(WebRtcVideoEngineTestFake, TestSetAdaptInputToCpuUsage) {
1613 EXPECT_TRUE(SetupEngine());
1614 cricket::VideoOptions options_in, options_out;
1615 bool cpu_adapt = false;
1616 channel_->SetOptions(options_in);
1617 EXPECT_TRUE(channel_->GetOptions(&options_out));
1618 EXPECT_FALSE(options_out.adapt_input_to_cpu_usage.Get(&cpu_adapt));
1619 // Set adapt input CPU usage option.
1620 options_in.adapt_input_to_cpu_usage.Set(true);
1621 EXPECT_TRUE(channel_->SetOptions(options_in));
1622 EXPECT_TRUE(channel_->GetOptions(&options_out));
1623 EXPECT_TRUE(options_out.adapt_input_to_cpu_usage.Get(&cpu_adapt));
1624 EXPECT_TRUE(cpu_adapt);
1625}
1626
1627TEST_F(WebRtcVideoEngineTestFake, TestSetCpuThreshold) {
1628 EXPECT_TRUE(SetupEngine());
1629 float low, high;
1630 cricket::VideoOptions options_in, options_out;
1631 // Verify that initial values are set.
1632 EXPECT_TRUE(channel_->GetOptions(&options_out));
1633 EXPECT_TRUE(options_out.system_low_adaptation_threshhold.Get(&low));
1634 EXPECT_EQ(low, 0.65f);
1635 EXPECT_TRUE(options_out.system_high_adaptation_threshhold.Get(&high));
1636 EXPECT_EQ(high, 0.85f);
1637 // Set new CPU threshold values.
1638 options_in.system_low_adaptation_threshhold.Set(0.45f);
1639 options_in.system_high_adaptation_threshhold.Set(0.95f);
1640 EXPECT_TRUE(channel_->SetOptions(options_in));
1641 EXPECT_TRUE(channel_->GetOptions(&options_out));
1642 EXPECT_TRUE(options_out.system_low_adaptation_threshhold.Get(&low));
1643 EXPECT_EQ(low, 0.45f);
1644 EXPECT_TRUE(options_out.system_high_adaptation_threshhold.Get(&high));
1645 EXPECT_EQ(high, 0.95f);
1646}
1647
1648TEST_F(WebRtcVideoEngineTestFake, TestSetInvalidCpuThreshold) {
1649 EXPECT_TRUE(SetupEngine());
1650 float low, high;
1651 cricket::VideoOptions options_in, options_out;
1652 // Valid range is [0, 1].
1653 options_in.system_low_adaptation_threshhold.Set(-1.5f);
1654 options_in.system_high_adaptation_threshhold.Set(1.5f);
1655 EXPECT_TRUE(channel_->SetOptions(options_in));
1656 EXPECT_TRUE(channel_->GetOptions(&options_out));
1657 EXPECT_TRUE(options_out.system_low_adaptation_threshhold.Get(&low));
1658 EXPECT_EQ(low, 0.0f);
1659 EXPECT_TRUE(options_out.system_high_adaptation_threshhold.Get(&high));
1660 EXPECT_EQ(high, 1.0f);
1661}
1662
1663
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +00001664TEST_F(WebRtcVideoEngineTestFake, ResetCodecOnScreencast) {
1665 EXPECT_TRUE(SetupEngine());
1666 cricket::VideoOptions options;
1667 options.video_noise_reduction.Set(true);
1668 EXPECT_TRUE(channel_->SetOptions(options));
1669
1670 // Set send codec.
1671 cricket::VideoCodec codec(kVP8Codec);
1672 std::vector<cricket::VideoCodec> codec_list;
1673 codec_list.push_back(codec);
1674 EXPECT_TRUE(channel_->AddSendStream(
1675 cricket::StreamParams::CreateLegacy(123)));
1676 EXPECT_TRUE(channel_->SetSendCodecs(codec_list));
1677 EXPECT_TRUE(channel_->SetSend(true));
wu@webrtc.org05e7b442014-04-01 17:44:24 +00001678 EXPECT_EQ(1, vie_.GetNumSetSendCodecs());
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +00001679
1680 webrtc::VideoCodec gcodec;
1681 memset(&gcodec, 0, sizeof(gcodec));
1682 int channel_num = vie_.GetLastChannel();
1683 EXPECT_EQ(0, vie_.GetSendCodec(channel_num, gcodec));
1684 EXPECT_TRUE(gcodec.codecSpecific.VP8.denoisingOn);
1685
1686 // Send a screencast frame with the same size.
1687 // Verify that denoising is turned off.
1688 SendI420ScreencastFrame(kVP8Codec.width, kVP8Codec.height);
wu@webrtc.org05e7b442014-04-01 17:44:24 +00001689 EXPECT_EQ(2, vie_.GetNumSetSendCodecs());
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +00001690 EXPECT_EQ(0, vie_.GetSendCodec(channel_num, gcodec));
1691 EXPECT_FALSE(gcodec.codecSpecific.VP8.denoisingOn);
1692}
1693
1694
1695TEST_F(WebRtcVideoEngineTestFake, DontRegisterDecoderIfFactoryIsNotGiven) {
1696 engine_.SetExternalDecoderFactory(NULL);
1697 EXPECT_TRUE(SetupEngine());
1698 int channel_num = vie_.GetLastChannel();
1699
1700 std::vector<cricket::VideoCodec> codecs;
1701 codecs.push_back(kVP8Codec);
1702 EXPECT_TRUE(channel_->SetRecvCodecs(codecs));
1703
1704 EXPECT_EQ(0, vie_.GetNumExternalDecoderRegistered(channel_num));
1705}
1706
1707TEST_F(WebRtcVideoEngineTestFake, RegisterDecoderIfFactoryIsGiven) {
1708 decoder_factory_.AddSupportedVideoCodecType(webrtc::kVideoCodecVP8);
1709 engine_.SetExternalDecoderFactory(&decoder_factory_);
1710 EXPECT_TRUE(SetupEngine());
1711 int channel_num = vie_.GetLastChannel();
1712
1713 std::vector<cricket::VideoCodec> codecs;
1714 codecs.push_back(kVP8Codec);
1715 EXPECT_TRUE(channel_->SetRecvCodecs(codecs));
1716
1717 EXPECT_TRUE(vie_.ExternalDecoderRegistered(channel_num, 100));
1718 EXPECT_EQ(1, vie_.GetNumExternalDecoderRegistered(channel_num));
1719}
1720
1721TEST_F(WebRtcVideoEngineTestFake, DontRegisterDecoderMultipleTimes) {
1722 decoder_factory_.AddSupportedVideoCodecType(webrtc::kVideoCodecVP8);
1723 engine_.SetExternalDecoderFactory(&decoder_factory_);
1724 EXPECT_TRUE(SetupEngine());
1725 int channel_num = vie_.GetLastChannel();
1726
1727 std::vector<cricket::VideoCodec> codecs;
1728 codecs.push_back(kVP8Codec);
1729 EXPECT_TRUE(channel_->SetRecvCodecs(codecs));
1730
1731 EXPECT_TRUE(vie_.ExternalDecoderRegistered(channel_num, 100));
1732 EXPECT_EQ(1, vie_.GetNumExternalDecoderRegistered(channel_num));
1733 EXPECT_EQ(1, decoder_factory_.GetNumCreatedDecoders());
1734
1735 EXPECT_TRUE(channel_->SetRecvCodecs(codecs));
1736 EXPECT_EQ(1, vie_.GetNumExternalDecoderRegistered(channel_num));
1737 EXPECT_EQ(1, decoder_factory_.GetNumCreatedDecoders());
1738}
1739
1740TEST_F(WebRtcVideoEngineTestFake, DontRegisterDecoderForNonVP8) {
1741 decoder_factory_.AddSupportedVideoCodecType(webrtc::kVideoCodecVP8);
1742 engine_.SetExternalDecoderFactory(&decoder_factory_);
1743 EXPECT_TRUE(SetupEngine());
1744 int channel_num = vie_.GetLastChannel();
1745
1746 std::vector<cricket::VideoCodec> codecs;
1747 codecs.push_back(kRedCodec);
1748 EXPECT_TRUE(channel_->SetRecvCodecs(codecs));
1749
1750 EXPECT_EQ(0, vie_.GetNumExternalDecoderRegistered(channel_num));
1751}
1752
1753TEST_F(WebRtcVideoEngineTestFake, DontRegisterEncoderIfFactoryIsNotGiven) {
1754 engine_.SetExternalEncoderFactory(NULL);
1755 EXPECT_TRUE(SetupEngine());
1756 int channel_num = vie_.GetLastChannel();
1757
1758 std::vector<cricket::VideoCodec> codecs;
1759 codecs.push_back(kVP8Codec);
1760 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1761
1762 EXPECT_EQ(0, vie_.GetNumExternalEncoderRegistered(channel_num));
1763}
1764
1765TEST_F(WebRtcVideoEngineTestFake, RegisterEncoderIfFactoryIsGiven) {
1766 encoder_factory_.AddSupportedVideoCodecType(webrtc::kVideoCodecVP8, "VP8");
1767 engine_.SetExternalEncoderFactory(&encoder_factory_);
1768 EXPECT_TRUE(SetupEngine());
1769 int channel_num = vie_.GetLastChannel();
1770
1771 std::vector<cricket::VideoCodec> codecs;
1772 codecs.push_back(kVP8Codec);
1773 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1774
1775 EXPECT_TRUE(channel_->AddSendStream(
1776 cricket::StreamParams::CreateLegacy(kSsrc)));
1777
1778 EXPECT_TRUE(vie_.ExternalEncoderRegistered(channel_num, 100));
1779 EXPECT_EQ(1, vie_.GetNumExternalEncoderRegistered(channel_num));
1780
1781 // Remove stream previously added to free the external encoder instance.
1782 EXPECT_TRUE(channel_->RemoveSendStream(kSsrc));
1783}
1784
1785TEST_F(WebRtcVideoEngineTestFake, DontRegisterEncoderMultipleTimes) {
1786 encoder_factory_.AddSupportedVideoCodecType(webrtc::kVideoCodecVP8, "VP8");
1787 engine_.SetExternalEncoderFactory(&encoder_factory_);
1788 EXPECT_TRUE(SetupEngine());
1789 int channel_num = vie_.GetLastChannel();
1790
1791 std::vector<cricket::VideoCodec> codecs;
1792 codecs.push_back(kVP8Codec);
1793 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1794
1795 EXPECT_TRUE(channel_->AddSendStream(
1796 cricket::StreamParams::CreateLegacy(kSsrc)));
1797
1798 EXPECT_TRUE(vie_.ExternalEncoderRegistered(channel_num, 100));
1799 EXPECT_EQ(1, vie_.GetNumExternalEncoderRegistered(channel_num));
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +00001800
1801 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1802 EXPECT_EQ(1, vie_.GetNumExternalEncoderRegistered(channel_num));
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +00001803
1804 // Remove stream previously added to free the external encoder instance.
1805 EXPECT_TRUE(channel_->RemoveSendStream(kSsrc));
1806}
1807
1808TEST_F(WebRtcVideoEngineTestFake, RegisterEncoderWithMultipleSendStreams) {
1809 encoder_factory_.AddSupportedVideoCodecType(webrtc::kVideoCodecVP8, "VP8");
1810 engine_.SetExternalEncoderFactory(&encoder_factory_);
1811 EXPECT_TRUE(SetupEngine());
1812
1813 std::vector<cricket::VideoCodec> codecs;
1814 codecs.push_back(kVP8Codec);
1815 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1816 EXPECT_EQ(1, vie_.GetTotalNumExternalEncoderRegistered());
1817
1818 // When we add the first stream (1234), it reuses the default send channel,
1819 // so it doesn't increase the registration count of external encoders.
1820 EXPECT_TRUE(channel_->AddSendStream(
1821 cricket::StreamParams::CreateLegacy(1234)));
1822 EXPECT_EQ(1, vie_.GetTotalNumExternalEncoderRegistered());
1823
1824 // When we add the second stream (2345), it creates a new channel and
1825 // increments the registration count.
1826 EXPECT_TRUE(channel_->AddSendStream(
1827 cricket::StreamParams::CreateLegacy(2345)));
1828 EXPECT_EQ(2, vie_.GetTotalNumExternalEncoderRegistered());
1829
1830 // At this moment the total registration count is two, but only one encoder
1831 // is registered per channel.
1832 int channel_num = vie_.GetLastChannel();
1833 EXPECT_EQ(1, vie_.GetNumExternalEncoderRegistered(channel_num));
1834
1835 // Removing send streams decrements the registration count.
1836 EXPECT_TRUE(channel_->RemoveSendStream(1234));
1837 EXPECT_EQ(1, vie_.GetTotalNumExternalEncoderRegistered());
1838
1839 // When we remove the last send stream, it also destroys the last send
1840 // channel and causes the registration count to drop to zero. It is a little
1841 // weird, but not a bug.
1842 EXPECT_TRUE(channel_->RemoveSendStream(2345));
1843 EXPECT_EQ(0, vie_.GetTotalNumExternalEncoderRegistered());
1844}
1845
1846TEST_F(WebRtcVideoEngineTestFake, DontRegisterEncoderForNonVP8) {
1847 encoder_factory_.AddSupportedVideoCodecType(webrtc::kVideoCodecGeneric,
1848 "GENERIC");
1849 engine_.SetExternalEncoderFactory(&encoder_factory_);
1850 EXPECT_TRUE(SetupEngine());
1851 int channel_num = vie_.GetLastChannel();
1852
1853 // Note: unlike the SetRecvCodecs, we must set a valid video codec for
1854 // channel_->SetSendCodecs() to succeed.
1855 std::vector<cricket::VideoCodec> codecs;
1856 codecs.push_back(kVP8Codec);
1857 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1858
1859 EXPECT_EQ(0, vie_.GetNumExternalEncoderRegistered(channel_num));
1860}
1861
1862// Test that NACK, PLI and REMB are enabled for external codec.
1863TEST_F(WebRtcVideoEngineTestFake, ExternalCodecFeedbackParams) {
1864 encoder_factory_.AddSupportedVideoCodecType(webrtc::kVideoCodecGeneric,
1865 "GENERIC");
1866 engine_.SetExternalEncoderFactory(&encoder_factory_);
1867 encoder_factory_.NotifyCodecsAvailable();
1868 EXPECT_TRUE(SetupEngine());
1869
1870 std::vector<cricket::VideoCodec> codecs(engine_.codecs());
1871 // The external codec will appear at last.
1872 size_t pos = codecs.size() - 1;
1873 EXPECT_EQ("GENERIC", codecs[pos].name);
1874 VerifyCodecFeedbackParams(codecs[pos]);
1875}
1876
1877// 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();
1890 cricket::VideoCodec internal_codec = codecs[0];
1891 cricket::VideoCodec external_codec = codecs[codecs.size() - 1];
1892 // The external codec will appear at last.
1893 EXPECT_EQ("GENERIC", external_codec.name);
1894 // The internal codec is preferred.
1895 EXPECT_GE(internal_codec.preference, external_codec.preference);
1896}
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
1918TEST_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
1929 EXPECT_TRUE(channel_->AddSendStream(
1930 cricket::StreamParams::CreateLegacy(kSsrc)));
1931
1932 EXPECT_TRUE(vie_.ExternalEncoderRegistered(channel_num, 100));
1933 EXPECT_EQ(1, vie_.GetNumExternalEncoderRegistered(channel_num));
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +00001934
1935 // Remove stream previously added to free the external encoder instance.
1936 EXPECT_TRUE(channel_->RemoveSendStream(kSsrc));
1937}
1938
1939// Tests that OnReadyToSend will be propagated into ViE.
1940TEST_F(WebRtcVideoEngineTestFake, OnReadyToSend) {
1941 EXPECT_TRUE(SetupEngine());
1942 int channel_num = vie_.GetLastChannel();
1943 EXPECT_TRUE(vie_.GetIsTransmitting(channel_num));
1944
1945 channel_->OnReadyToSend(false);
1946 EXPECT_FALSE(vie_.GetIsTransmitting(channel_num));
1947
1948 channel_->OnReadyToSend(true);
1949 EXPECT_TRUE(vie_.GetIsTransmitting(channel_num));
1950}
1951
1952#if 0
1953TEST_F(WebRtcVideoEngineTestFake, CaptureFrameTimestampToNtpTimestamp) {
1954 EXPECT_TRUE(SetupEngine());
1955 int capture_id = vie_.GetCaptureId(vie_.GetLastChannel());
1956
1957 // Set send codec.
1958 cricket::VideoCodec codec(kVP8Codec);
1959 std::vector<cricket::VideoCodec> codec_list;
1960 codec_list.push_back(codec);
1961 EXPECT_TRUE(channel_->AddSendStream(
1962 cricket::StreamParams::CreateLegacy(123)));
1963 EXPECT_TRUE(channel_->SetSendCodecs(codec_list));
1964 EXPECT_TRUE(channel_->SetSend(true));
1965
1966 int64 timestamp = time(NULL) * talk_base::kNumNanosecsPerSec;
1967 SendI420ScreencastFrameWithTimestamp(
1968 kVP8Codec.width, kVP8Codec.height, timestamp);
1969 EXPECT_EQ(talk_base::UnixTimestampNanosecsToNtpMillisecs(timestamp),
1970 vie_.GetCaptureLastTimestamp(capture_id));
1971
1972 SendI420ScreencastFrameWithTimestamp(kVP8Codec.width, kVP8Codec.height, 0);
1973 EXPECT_EQ(0, vie_.GetCaptureLastTimestamp(capture_id));
1974}
1975#endif
1976
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001977/////////////////////////
1978// Tests with real ViE //
1979/////////////////////////
1980
1981// Tests that we can find codecs by name or id.
1982TEST_F(WebRtcVideoEngineTest, FindCodec) {
1983 // We should not need to init engine in order to get codecs.
1984 const std::vector<cricket::VideoCodec>& c = engine_.codecs();
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +00001985 EXPECT_EQ(4U, c.size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001986
1987 cricket::VideoCodec vp8(104, "VP8", 320, 200, 30, 0);
1988 EXPECT_TRUE(engine_.FindCodec(vp8));
1989
1990 cricket::VideoCodec vp8_ci(104, "vp8", 320, 200, 30, 0);
1991 EXPECT_TRUE(engine_.FindCodec(vp8));
1992
1993 cricket::VideoCodec vp8_diff_fr_diff_pref(104, "VP8", 320, 200, 50, 50);
1994 EXPECT_TRUE(engine_.FindCodec(vp8_diff_fr_diff_pref));
1995
1996 cricket::VideoCodec vp8_diff_id(95, "VP8", 320, 200, 30, 0);
1997 EXPECT_FALSE(engine_.FindCodec(vp8_diff_id));
1998 vp8_diff_id.id = 97;
1999 EXPECT_TRUE(engine_.FindCodec(vp8_diff_id));
2000
2001 cricket::VideoCodec vp8_diff_res(104, "VP8", 320, 111, 30, 0);
2002 EXPECT_FALSE(engine_.FindCodec(vp8_diff_res));
2003
2004 // PeerConnection doesn't negotiate the resolution at this point.
2005 // Test that FindCodec can handle the case when width/height is 0.
2006 cricket::VideoCodec vp8_zero_res(104, "VP8", 0, 0, 30, 0);
2007 EXPECT_TRUE(engine_.FindCodec(vp8_zero_res));
2008
2009 cricket::VideoCodec red(101, "RED", 0, 0, 30, 0);
2010 EXPECT_TRUE(engine_.FindCodec(red));
2011
2012 cricket::VideoCodec red_ci(101, "red", 0, 0, 30, 0);
2013 EXPECT_TRUE(engine_.FindCodec(red));
2014
2015 cricket::VideoCodec fec(102, "ULPFEC", 0, 0, 30, 0);
2016 EXPECT_TRUE(engine_.FindCodec(fec));
2017
2018 cricket::VideoCodec fec_ci(102, "ulpfec", 0, 0, 30, 0);
2019 EXPECT_TRUE(engine_.FindCodec(fec));
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +00002020
2021 cricket::VideoCodec rtx(96, "rtx", 0, 0, 30, 0);
2022 EXPECT_TRUE(engine_.FindCodec(rtx));
2023}
2024
2025TEST_F(WebRtcVideoEngineTest, RtxCodecHasAptSet) {
2026 std::vector<cricket::VideoCodec>::const_iterator it;
2027 bool apt_checked = false;
2028 for (it = engine_.codecs().begin(); it != engine_.codecs().end(); ++it) {
2029 if (_stricmp(cricket::kRtxCodecName, it->name.c_str()) && it->id != 96) {
2030 continue;
2031 }
2032 int apt;
2033 EXPECT_TRUE(it->GetParam("apt", &apt));
2034 EXPECT_EQ(100, apt);
2035 apt_checked = true;
2036 }
2037 EXPECT_TRUE(apt_checked);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002038}
2039
2040TEST_F(WebRtcVideoEngineTest, StartupShutdown) {
2041 EXPECT_TRUE(engine_.Init(talk_base::Thread::Current()));
2042 engine_.Terminate();
2043}
2044
2045TEST_PRE_VIDEOENGINE_INIT(WebRtcVideoEngineTest, ConstrainNewCodec)
2046TEST_POST_VIDEOENGINE_INIT(WebRtcVideoEngineTest, ConstrainNewCodec)
2047
2048TEST_PRE_VIDEOENGINE_INIT(WebRtcVideoEngineTest, ConstrainRunningCodec)
2049TEST_POST_VIDEOENGINE_INIT(WebRtcVideoEngineTest, ConstrainRunningCodec)
2050
2051// TODO(juberti): Figure out why ViE is munging the COM refcount.
2052#ifdef WIN32
2053TEST_F(WebRtcVideoEngineTest, DISABLED_CheckCoInitialize) {
2054 Base::CheckCoInitialize();
2055}
2056#endif
2057
2058TEST_F(WebRtcVideoEngineTest, CreateChannel) {
2059 EXPECT_TRUE(engine_.Init(talk_base::Thread::Current()));
2060 cricket::VideoMediaChannel* channel = engine_.CreateChannel(NULL);
2061 EXPECT_TRUE(channel != NULL);
2062 delete channel;
2063}
2064
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002065TEST_F(WebRtcVideoMediaChannelTest, SetRecvCodecs) {
2066 std::vector<cricket::VideoCodec> codecs;
2067 codecs.push_back(kVP8Codec);
2068 EXPECT_TRUE(channel_->SetRecvCodecs(codecs));
2069}
2070TEST_F(WebRtcVideoMediaChannelTest, SetRecvCodecsWrongPayloadType) {
2071 std::vector<cricket::VideoCodec> codecs;
2072 codecs.push_back(kVP8Codec);
2073 codecs[0].id = 99;
2074 EXPECT_TRUE(channel_->SetRecvCodecs(codecs));
2075}
2076TEST_F(WebRtcVideoMediaChannelTest, SetRecvCodecsUnsupportedCodec) {
2077 std::vector<cricket::VideoCodec> codecs;
2078 codecs.push_back(kVP8Codec);
2079 codecs.push_back(cricket::VideoCodec(101, "VP1", 640, 400, 30, 0));
2080 EXPECT_FALSE(channel_->SetRecvCodecs(codecs));
2081}
2082
mallinath@webrtc.org92fdfeb2014-02-17 18:49:41 +00002083TEST_F(WebRtcVideoMediaChannelTest, GetRtpSendTimeExtension) {
2084 // Enable RTP timestamp extension.
2085 const int id = 12;
2086 std::vector<cricket::RtpHeaderExtension> extensions;
2087 extensions.push_back(cricket::RtpHeaderExtension(
2088 "http://www.webrtc.org/experiments/rtp-hdrext/abs-send-time", id));
2089
2090 // Verify the send extension id.
2091 EXPECT_TRUE(channel_->SetSendRtpHeaderExtensions(extensions));
2092 EXPECT_EQ(id, channel_->GetRtpSendTimeExtnId());
2093}
2094
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002095TEST_F(WebRtcVideoMediaChannelTest, SetSend) {
2096 Base::SetSend();
2097}
2098TEST_F(WebRtcVideoMediaChannelTest, SetSendWithoutCodecs) {
2099 Base::SetSendWithoutCodecs();
2100}
2101TEST_F(WebRtcVideoMediaChannelTest, SetSendSetsTransportBufferSizes) {
2102 Base::SetSendSetsTransportBufferSizes();
2103}
2104
2105TEST_F(WebRtcVideoMediaChannelTest, SendAndReceiveVp8Vga) {
2106 SendAndReceive(cricket::VideoCodec(100, "VP8", 640, 400, 30, 0));
2107}
2108TEST_F(WebRtcVideoMediaChannelTest, SendAndReceiveVp8Qvga) {
2109 SendAndReceive(cricket::VideoCodec(100, "VP8", 320, 200, 30, 0));
2110}
2111TEST_F(WebRtcVideoMediaChannelTest, SendAndReceiveH264SvcQqvga) {
2112 SendAndReceive(cricket::VideoCodec(100, "VP8", 160, 100, 30, 0));
2113}
2114TEST_F(WebRtcVideoMediaChannelTest, SendManyResizeOnce) {
2115 SendManyResizeOnce();
2116}
2117
2118TEST_F(WebRtcVideoMediaChannelTest, SendVp8HdAndReceiveAdaptedVp8Vga) {
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00002119 EXPECT_TRUE(channel_->SetCapturer(kSsrc, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002120 channel_->UpdateAspectRatio(1280, 720);
2121 video_capturer_.reset(new cricket::FakeVideoCapturer);
2122 const std::vector<cricket::VideoFormat>* formats =
2123 video_capturer_->GetSupportedFormats();
2124 cricket::VideoFormat capture_format_hd = (*formats)[0];
2125 EXPECT_EQ(cricket::CS_RUNNING, video_capturer_->Start(capture_format_hd));
2126 EXPECT_TRUE(channel_->SetCapturer(kSsrc, video_capturer_.get()));
2127
2128 // Capture format HD -> adapt (OnOutputFormatRequest VGA) -> VGA.
2129 cricket::VideoCodec codec(100, "VP8", 1280, 720, 30, 0);
2130 EXPECT_TRUE(SetOneCodec(codec));
2131 codec.width /= 2;
2132 codec.height /= 2;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002133 EXPECT_TRUE(SetSend(true));
2134 EXPECT_TRUE(channel_->SetRender(true));
2135 EXPECT_EQ(0, renderer_.num_rendered_frames());
2136 EXPECT_TRUE(SendFrame());
2137 EXPECT_FRAME_WAIT(1, codec.width, codec.height, kTimeout);
2138}
2139
2140// TODO(juberti): Fix this test to tolerate missing stats.
2141TEST_F(WebRtcVideoMediaChannelTest, DISABLED_GetStats) {
2142 Base::GetStats();
2143}
2144
2145// TODO(juberti): Fix this test to tolerate missing stats.
2146TEST_F(WebRtcVideoMediaChannelTest, DISABLED_GetStatsMultipleRecvStreams) {
2147 Base::GetStatsMultipleRecvStreams();
2148}
2149
2150TEST_F(WebRtcVideoMediaChannelTest, GetStatsMultipleSendStreams) {
2151 Base::GetStatsMultipleSendStreams();
2152}
2153
2154TEST_F(WebRtcVideoMediaChannelTest, SetSendBandwidth) {
2155 Base::SetSendBandwidth();
2156}
2157TEST_F(WebRtcVideoMediaChannelTest, SetSendSsrc) {
2158 Base::SetSendSsrc();
2159}
2160TEST_F(WebRtcVideoMediaChannelTest, SetSendSsrcAfterSetCodecs) {
2161 Base::SetSendSsrcAfterSetCodecs();
2162}
2163
2164TEST_F(WebRtcVideoMediaChannelTest, SetRenderer) {
2165 Base::SetRenderer();
2166}
2167
2168TEST_F(WebRtcVideoMediaChannelTest, AddRemoveRecvStreams) {
2169 Base::AddRemoveRecvStreams();
2170}
2171
2172TEST_F(WebRtcVideoMediaChannelTest, AddRemoveRecvStreamAndRender) {
2173 Base::AddRemoveRecvStreamAndRender();
2174}
2175
2176TEST_F(WebRtcVideoMediaChannelTest, AddRemoveRecvStreamsNoConference) {
2177 Base::AddRemoveRecvStreamsNoConference();
2178}
2179
2180TEST_F(WebRtcVideoMediaChannelTest, AddRemoveSendStreams) {
2181 Base::AddRemoveSendStreams();
2182}
2183
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002184TEST_F(WebRtcVideoMediaChannelTest, SimulateConference) {
2185 Base::SimulateConference();
2186}
2187
2188TEST_F(WebRtcVideoMediaChannelTest, AddRemoveCapturer) {
2189 Base::AddRemoveCapturer();
2190}
2191
2192TEST_F(WebRtcVideoMediaChannelTest, RemoveCapturerWithoutAdd) {
2193 Base::RemoveCapturerWithoutAdd();
2194}
2195
2196TEST_F(WebRtcVideoMediaChannelTest, AddRemoveCapturerMultipleSources) {
2197 Base::AddRemoveCapturerMultipleSources();
2198}
2199
wu@webrtc.orgde305012013-10-31 15:40:38 +00002200// This test verifies DSCP settings are properly applied on video media channel.
2201TEST_F(WebRtcVideoMediaChannelTest, TestSetDscpOptions) {
2202 talk_base::scoped_ptr<cricket::FakeNetworkInterface> network_interface(
2203 new cricket::FakeNetworkInterface);
2204 channel_->SetInterface(network_interface.get());
2205 cricket::VideoOptions options;
2206 options.dscp.Set(true);
2207 EXPECT_TRUE(channel_->SetOptions(options));
2208 EXPECT_EQ(talk_base::DSCP_AF41, network_interface->dscp());
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +00002209 // Verify previous value is not modified if dscp option is not set.
2210 cricket::VideoOptions options1;
2211 EXPECT_TRUE(channel_->SetOptions(options1));
2212 EXPECT_EQ(talk_base::DSCP_AF41, network_interface->dscp());
wu@webrtc.orgde305012013-10-31 15:40:38 +00002213 options.dscp.Set(false);
2214 EXPECT_TRUE(channel_->SetOptions(options));
2215 EXPECT_EQ(talk_base::DSCP_DEFAULT, network_interface->dscp());
2216 channel_->SetInterface(NULL);
2217}
2218
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002219
2220TEST_F(WebRtcVideoMediaChannelTest, SetOptionsSucceedsWhenSending) {
2221 cricket::VideoOptions options;
2222 options.conference_mode.Set(true);
2223 EXPECT_TRUE(channel_->SetOptions(options));
2224
2225 // Verify SetOptions returns true on a different options.
2226 cricket::VideoOptions options2;
2227 options2.adapt_input_to_cpu_usage.Set(true);
2228 EXPECT_TRUE(channel_->SetOptions(options2));
2229
2230 // Set send codecs on the channel and start sending.
2231 std::vector<cricket::VideoCodec> codecs;
2232 codecs.push_back(kVP8Codec);
2233 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
2234 EXPECT_TRUE(channel_->SetSend(true));
2235
2236 // Verify SetOptions returns true if channel is already sending.
2237 cricket::VideoOptions options3;
2238 options3.conference_mode.Set(true);
2239 EXPECT_TRUE(channel_->SetOptions(options3));
2240}
2241
2242// Tests empty StreamParams is rejected.
2243TEST_F(WebRtcVideoMediaChannelTest, RejectEmptyStreamParams) {
2244 Base::RejectEmptyStreamParams();
2245}
2246
2247
2248TEST_F(WebRtcVideoMediaChannelTest, AdaptResolution16x10) {
2249 Base::AdaptResolution16x10();
2250}
2251
2252TEST_F(WebRtcVideoMediaChannelTest, AdaptResolution4x3) {
2253 Base::AdaptResolution4x3();
2254}
2255
2256TEST_F(WebRtcVideoMediaChannelTest, MuteStream) {
2257 Base::MuteStream();
2258}
2259
2260TEST_F(WebRtcVideoMediaChannelTest, MultipleSendStreams) {
2261 Base::MultipleSendStreams();
2262}
2263
2264// TODO(juberti): Restore this test once we support sending 0 fps.
2265TEST_F(WebRtcVideoMediaChannelTest, DISABLED_AdaptDropAllFrames) {
2266 Base::AdaptDropAllFrames();
2267}
2268// TODO(juberti): Understand why we get decode errors on this test.
2269TEST_F(WebRtcVideoMediaChannelTest, DISABLED_AdaptFramerate) {
2270 Base::AdaptFramerate();
2271}
2272
2273TEST_F(WebRtcVideoMediaChannelTest, SetSendStreamFormat0x0) {
2274 Base::SetSendStreamFormat0x0();
2275}
2276
2277// TODO(zhurunz): Fix the flakey test.
2278TEST_F(WebRtcVideoMediaChannelTest, DISABLED_SetSendStreamFormat) {
2279 Base::SetSendStreamFormat();
2280}
2281
2282TEST_F(WebRtcVideoMediaChannelTest, TwoStreamsSendAndReceive) {
2283 Base::TwoStreamsSendAndReceive(cricket::VideoCodec(100, "VP8", 640, 400, 30,
2284 0));
2285}
2286
2287TEST_F(WebRtcVideoMediaChannelTest, TwoStreamsReUseFirstStream) {
2288 Base::TwoStreamsReUseFirstStream(cricket::VideoCodec(100, "VP8", 640, 400, 30,
2289 0));
2290}
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00002291
buildbot@webrtc.org0b3c6c32014-04-17 10:03:57 +00002292TEST_F(WebRtcVideoMediaChannelTest, DISABLED_TwoStreamsSendAndUnsignalledRecv) {
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00002293 Base::TwoStreamsSendAndUnsignalledRecv(cricket::VideoCodec(100, "VP8", 640,
2294 400, 30, 0));
2295}
2296
henrike@webrtc.org806768a2014-02-27 21:03:09 +00002297TEST_F(WebRtcVideoMediaChannelTest,
henrike@webrtc.org18e59112014-03-14 17:19:38 +00002298 TwoStreamsSendAndFailUnsignalledRecv) {
henrike@webrtc.org806768a2014-02-27 21:03:09 +00002299 webrtc::Trace::set_level_filter(webrtc::kTraceAll);
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00002300 Base::TwoStreamsSendAndFailUnsignalledRecv(
2301 cricket::VideoCodec(100, "VP8", 640, 400, 30, 0));
2302}
2303
2304TEST_F(WebRtcVideoMediaChannelTest,
henrike@webrtc.org18e59112014-03-14 17:19:38 +00002305 TwoStreamsSendAndFailUnsignalledRecvInOneToOne) {
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00002306 Base::TwoStreamsSendAndFailUnsignalledRecvInOneToOne(
2307 cricket::VideoCodec(100, "VP8", 640, 400, 30, 0));
2308}
2309
2310TEST_F(WebRtcVideoMediaChannelTest,
henrike@webrtc.org18e59112014-03-14 17:19:38 +00002311 TwoStreamsAddAndRemoveUnsignalledRecv) {
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00002312 Base::TwoStreamsAddAndRemoveUnsignalledRecv(cricket::VideoCodec(100, "VP8",
2313 640, 400, 30,
2314 0));
2315}