blob: a9f7b18c19596605187cec57a995942b3b7cf1eb [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
buildbot@webrtc.orged97bb02014-05-07 11:15:20 +0000428TEST_F(WebRtcVideoEngineTestFake, SetSendCodecsWithStartBitrate) {
429 EXPECT_TRUE(SetupEngine());
430 int channel_num = vie_.GetLastChannel();
431 std::vector<cricket::VideoCodec> codecs(engine_.codecs());
432 codecs[0].params[cricket::kCodecParamStartBitrate] = "450";
433 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
434
435 VerifyVP8SendCodec(
436 channel_num, kVP8Codec.width, kVP8Codec.height, 0, 2000, 50, 450);
437
438 cricket::VideoCodec codec;
439 EXPECT_TRUE(channel_->GetSendCodec(&codec));
440 EXPECT_EQ("450", codec.params[cricket::kCodecParamStartBitrate]);
441}
442
443TEST_F(WebRtcVideoEngineTestFake, SetSendCodecsWithMinMaxStartBitrate) {
444 EXPECT_TRUE(SetupEngine());
445 int channel_num = vie_.GetLastChannel();
446 std::vector<cricket::VideoCodec> codecs(engine_.codecs());
447 codecs[0].params[cricket::kCodecParamMinBitrate] = "10";
448 codecs[0].params[cricket::kCodecParamMaxBitrate] = "20";
449 codecs[0].params[cricket::kCodecParamStartBitrate] = "14";
450 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
451
452 VerifyVP8SendCodec(
453 channel_num, kVP8Codec.width, kVP8Codec.height, 0, 20, 10, 14);
454
455 cricket::VideoCodec codec;
456 EXPECT_TRUE(channel_->GetSendCodec(&codec));
457 EXPECT_EQ("10", codec.params[cricket::kCodecParamMinBitrate]);
458 EXPECT_EQ("20", codec.params[cricket::kCodecParamMaxBitrate]);
459 EXPECT_EQ("14", codec.params[cricket::kCodecParamStartBitrate]);
460}
461
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000462TEST_F(WebRtcVideoEngineTestFake, SetSendCodecsWithMinMaxBitrateInvalid) {
463 EXPECT_TRUE(SetupEngine());
464 std::vector<cricket::VideoCodec> codecs(engine_.codecs());
465 codecs[0].params[cricket::kCodecParamMinBitrate] = "30";
466 codecs[0].params[cricket::kCodecParamMaxBitrate] = "20";
467 EXPECT_FALSE(channel_->SetSendCodecs(codecs));
468}
469
470TEST_F(WebRtcVideoEngineTestFake, SetSendCodecsWithLargeMinMaxBitrate) {
471 EXPECT_TRUE(SetupEngine());
472 int channel_num = vie_.GetLastChannel();
473 std::vector<cricket::VideoCodec> codecs(engine_.codecs());
474 codecs[0].params[cricket::kCodecParamMinBitrate] = "1000";
475 codecs[0].params[cricket::kCodecParamMaxBitrate] = "2000";
476 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
477
478 VerifyVP8SendCodec(
479 channel_num, kVP8Codec.width, kVP8Codec.height, 0, 2000, 1000,
480 1000);
481}
482
483TEST_F(WebRtcVideoEngineTestFake, SetSendCodecsWithMaxQuantization) {
484 EXPECT_TRUE(SetupEngine());
485 int channel_num = vie_.GetLastChannel();
486 std::vector<cricket::VideoCodec> codecs(engine_.codecs());
487 codecs[0].params[cricket::kCodecParamMaxQuantization] = "21";
488 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
489
490 VerifyVP8SendCodec(
491 channel_num, kVP8Codec.width, kVP8Codec.height, 0, 2000, 50, 300,
492 30, 21);
493
494 cricket::VideoCodec codec;
495 EXPECT_TRUE(channel_->GetSendCodec(&codec));
496 EXPECT_EQ("21", codec.params[cricket::kCodecParamMaxQuantization]);
497}
498
499TEST_F(WebRtcVideoEngineTestFake, SetOptionsWithMaxBitrate) {
500 EXPECT_TRUE(SetupEngine());
501 int channel_num = vie_.GetLastChannel();
502 std::vector<cricket::VideoCodec> codecs(engine_.codecs());
503 codecs[0].params[cricket::kCodecParamMinBitrate] = "10";
504 codecs[0].params[cricket::kCodecParamMaxBitrate] = "20";
505 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
506
507 VerifyVP8SendCodec(
508 channel_num, kVP8Codec.width, kVP8Codec.height, 0, 20, 10, 20);
509
510 // Verify that max bitrate doesn't change after SetOptions().
511 cricket::VideoOptions options;
512 options.video_noise_reduction.Set(true);
513 EXPECT_TRUE(channel_->SetOptions(options));
514 VerifyVP8SendCodec(
515 channel_num, kVP8Codec.width, kVP8Codec.height, 0, 20, 10, 20);
516
517 options.video_noise_reduction.Set(false);
518 options.conference_mode.Set(false);
519 EXPECT_TRUE(channel_->SetOptions(options));
520 VerifyVP8SendCodec(
521 channel_num, kVP8Codec.width, kVP8Codec.height, 0, 20, 10, 20);
522}
523
wu@webrtc.orgcecfd182013-10-30 05:18:12 +0000524TEST_F(WebRtcVideoEngineTestFake, SetOptionsWithLoweredBitrate) {
525 EXPECT_TRUE(SetupEngine());
526 int channel_num = vie_.GetLastChannel();
527 std::vector<cricket::VideoCodec> codecs(engine_.codecs());
528 codecs[0].params[cricket::kCodecParamMinBitrate] = "50";
529 codecs[0].params[cricket::kCodecParamMaxBitrate] = "100";
530 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
531
532 VerifyVP8SendCodec(
533 channel_num, kVP8Codec.width, kVP8Codec.height, 0, 100, 50, 100);
534
535 // Verify that min bitrate changes after SetOptions().
536 cricket::VideoOptions options;
537 options.lower_min_bitrate.Set(true);
538 EXPECT_TRUE(channel_->SetOptions(options));
539 VerifyVP8SendCodec(
540 channel_num, kVP8Codec.width, kVP8Codec.height, 0, 100, 30, 100);
541}
542
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000543TEST_F(WebRtcVideoEngineTestFake, MaxBitrateResetWithConferenceMode) {
544 EXPECT_TRUE(SetupEngine());
545 int channel_num = vie_.GetLastChannel();
546 std::vector<cricket::VideoCodec> codecs(engine_.codecs());
547 codecs[0].params[cricket::kCodecParamMinBitrate] = "10";
548 codecs[0].params[cricket::kCodecParamMaxBitrate] = "20";
549 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
550
551 VerifyVP8SendCodec(
552 channel_num, kVP8Codec.width, kVP8Codec.height, 0, 20, 10, 20);
553
554 cricket::VideoOptions options;
555 options.conference_mode.Set(true);
556 EXPECT_TRUE(channel_->SetOptions(options));
557 options.conference_mode.Set(false);
558 EXPECT_TRUE(channel_->SetOptions(options));
559 VerifyVP8SendCodec(
560 channel_num, kVP8Codec.width, kVP8Codec.height, 0,
561 kMaxBandwidthKbps, 10, 20);
562}
563
564// Verify the current send bitrate is used as start bitrate when reconfiguring
565// the send codec.
566TEST_F(WebRtcVideoEngineTestFake, StartSendBitrate) {
567 EXPECT_TRUE(SetupEngine());
568 EXPECT_TRUE(channel_->AddSendStream(
569 cricket::StreamParams::CreateLegacy(1)));
570 int send_channel = vie_.GetLastChannel();
571 cricket::VideoCodec codec(kVP8Codec);
572 std::vector<cricket::VideoCodec> codec_list;
573 codec_list.push_back(codec);
574 EXPECT_TRUE(channel_->SetSendCodecs(codec_list));
575 const unsigned int kVideoMaxSendBitrateKbps = 2000;
576 const unsigned int kVideoMinSendBitrateKbps = 50;
577 const unsigned int kVideoDefaultStartSendBitrateKbps = 300;
578 VerifyVP8SendCodec(send_channel, kVP8Codec.width, kVP8Codec.height, 0,
579 kVideoMaxSendBitrateKbps, kVideoMinSendBitrateKbps,
580 kVideoDefaultStartSendBitrateKbps);
581 EXPECT_EQ(0, vie_.StartSend(send_channel));
582
583 // Increase the send bitrate and verify it is used as start bitrate.
584 const unsigned int kVideoSendBitrateBps = 768000;
585 vie_.SetSendBitrates(send_channel, kVideoSendBitrateBps, 0, 0);
586 EXPECT_TRUE(channel_->SetSendCodecs(codec_list));
587 VerifyVP8SendCodec(send_channel, kVP8Codec.width, kVP8Codec.height, 0,
588 kVideoMaxSendBitrateKbps, kVideoMinSendBitrateKbps,
589 kVideoSendBitrateBps / 1000);
590
591 // Never set a start bitrate higher than the max bitrate.
592 vie_.SetSendBitrates(send_channel, kVideoMaxSendBitrateKbps + 500, 0, 0);
593 EXPECT_TRUE(channel_->SetSendCodecs(codec_list));
594 VerifyVP8SendCodec(send_channel, kVP8Codec.width, kVP8Codec.height, 0,
595 kVideoMaxSendBitrateKbps, kVideoMinSendBitrateKbps,
596 kVideoDefaultStartSendBitrateKbps);
597
598 // Use the default start bitrate if the send bitrate is lower.
599 vie_.SetSendBitrates(send_channel, kVideoDefaultStartSendBitrateKbps - 50, 0,
600 0);
601 EXPECT_TRUE(channel_->SetSendCodecs(codec_list));
602 VerifyVP8SendCodec(send_channel, kVP8Codec.width, kVP8Codec.height, 0,
603 kVideoMaxSendBitrateKbps, kVideoMinSendBitrateKbps,
604 kVideoDefaultStartSendBitrateKbps);
605}
606
607
608// Test that we constrain send codecs properly.
609TEST_F(WebRtcVideoEngineTestFake, ConstrainSendCodecs) {
610 EXPECT_TRUE(SetupEngine());
611 int channel_num = vie_.GetLastChannel();
612
613 // Set max settings of 640x400x30.
614 EXPECT_TRUE(engine_.SetDefaultEncoderConfig(
615 cricket::VideoEncoderConfig(kVP8Codec)));
616
617 // Send codec format bigger than max setting.
618 cricket::VideoCodec codec(kVP8Codec);
619 codec.width = 1280;
620 codec.height = 800;
621 codec.framerate = 60;
622 std::vector<cricket::VideoCodec> codec_list;
623 codec_list.push_back(codec);
624
625 // Set send codec and verify codec has been constrained.
626 EXPECT_TRUE(channel_->SetSendCodecs(codec_list));
627 VerifyVP8SendCodec(channel_num, kVP8Codec.width, kVP8Codec.height);
628}
629
630// Test that SetSendCodecs rejects bad format.
631TEST_F(WebRtcVideoEngineTestFake, SetSendCodecsRejectBadFormat) {
632 EXPECT_TRUE(SetupEngine());
633 int channel_num = vie_.GetLastChannel();
634
635 // Set w = 0.
636 cricket::VideoCodec codec(kVP8Codec);
637 codec.width = 0;
638 std::vector<cricket::VideoCodec> codec_list;
639 codec_list.push_back(codec);
640
641 // Verify SetSendCodecs failed and send codec is not changed on engine.
642 EXPECT_FALSE(channel_->SetSendCodecs(codec_list));
643 webrtc::VideoCodec gcodec;
644 // Set plType to something other than the value to test against ensuring
645 // that failure will happen if it is not changed.
646 gcodec.plType = 1;
647 EXPECT_EQ(0, vie_.GetSendCodec(channel_num, gcodec));
648 EXPECT_EQ(0, gcodec.plType);
649
650 // Set h = 0.
651 codec_list[0].width = 640;
652 codec_list[0].height = 0;
653
654 // Verify SetSendCodecs failed and send codec is not changed on engine.
655 EXPECT_FALSE(channel_->SetSendCodecs(codec_list));
656 // Set plType to something other than the value to test against ensuring
657 // that failure will happen if it is not changed.
658 gcodec.plType = 1;
659 EXPECT_EQ(0, vie_.GetSendCodec(channel_num, gcodec));
660 EXPECT_EQ(0, gcodec.plType);
661}
662
663// Test that SetSendCodecs rejects bad codec.
664TEST_F(WebRtcVideoEngineTestFake, SetSendCodecsRejectBadCodec) {
665 EXPECT_TRUE(SetupEngine());
666 int channel_num = vie_.GetLastChannel();
667
668 // Set bad codec name.
669 cricket::VideoCodec codec(kVP8Codec);
670 codec.name = "bad";
671 std::vector<cricket::VideoCodec> codec_list;
672 codec_list.push_back(codec);
673
674 // Verify SetSendCodecs failed and send codec is not changed on engine.
675 EXPECT_FALSE(channel_->SetSendCodecs(codec_list));
676 webrtc::VideoCodec gcodec;
677 // Set plType to something other than the value to test against ensuring
678 // that failure will happen if it is not changed.
679 gcodec.plType = 1;
680 EXPECT_EQ(0, vie_.GetSendCodec(channel_num, gcodec));
681 EXPECT_EQ(0, gcodec.plType);
682}
683
684// Test that vie send codec is reset on new video frame size.
685TEST_F(WebRtcVideoEngineTestFake, ResetVieSendCodecOnNewFrameSize) {
686 EXPECT_TRUE(SetupEngine());
687 int channel_num = vie_.GetLastChannel();
688
689 // Set send codec.
690 std::vector<cricket::VideoCodec> codec_list;
691 codec_list.push_back(kVP8Codec);
692 EXPECT_TRUE(channel_->SetSendCodecs(codec_list));
693 EXPECT_TRUE(channel_->AddSendStream(
694 cricket::StreamParams::CreateLegacy(123)));
695 EXPECT_TRUE(channel_->SetSend(true));
696
697 // Capture a smaller frame and verify vie send codec has been reset to
698 // the new size.
699 SendI420Frame(kVP8Codec.width / 2, kVP8Codec.height / 2);
700 VerifyVP8SendCodec(channel_num, kVP8Codec.width / 2, kVP8Codec.height / 2);
701
702 // Capture a frame bigger than send_codec_ and verify vie send codec has been
703 // reset (and clipped) to send_codec_.
704 SendI420Frame(kVP8Codec.width * 2, kVP8Codec.height * 2);
705 VerifyVP8SendCodec(channel_num, kVP8Codec.width, kVP8Codec.height);
706}
707
708// Test that we set our inbound codecs properly.
709TEST_F(WebRtcVideoEngineTestFake, SetRecvCodecs) {
710 EXPECT_TRUE(SetupEngine());
711 int channel_num = vie_.GetLastChannel();
712
713 std::vector<cricket::VideoCodec> codecs;
714 codecs.push_back(kVP8Codec);
715 EXPECT_TRUE(channel_->SetRecvCodecs(codecs));
716
717 webrtc::VideoCodec wcodec;
718 EXPECT_TRUE(engine_.ConvertFromCricketVideoCodec(kVP8Codec, &wcodec));
719 EXPECT_TRUE(vie_.ReceiveCodecRegistered(channel_num, wcodec));
720}
721
722// Test that channel connects and disconnects external capturer correctly.
723TEST_F(WebRtcVideoEngineTestFake, HasExternalCapturer) {
724 EXPECT_TRUE(SetupEngine());
725 int channel_num = vie_.GetLastChannel();
726
727 EXPECT_EQ(1, vie_.GetNumCapturers());
728 int capture_id = vie_.GetCaptureId(channel_num);
729 EXPECT_EQ(channel_num, vie_.GetCaptureChannelId(capture_id));
730
731 // Delete the channel should disconnect the capturer.
732 delete channel_;
733 channel_ = NULL;
734 EXPECT_EQ(0, vie_.GetNumCapturers());
735}
736
737// Test that channel adds and removes renderer correctly.
738TEST_F(WebRtcVideoEngineTestFake, HasRenderer) {
739 EXPECT_TRUE(SetupEngine());
740 int channel_num = vie_.GetLastChannel();
741
742 EXPECT_TRUE(vie_.GetHasRenderer(channel_num));
743 EXPECT_FALSE(vie_.GetRenderStarted(channel_num));
744}
745
746// Test that rtcp is enabled on the channel.
747TEST_F(WebRtcVideoEngineTestFake, RtcpEnabled) {
748 EXPECT_TRUE(SetupEngine());
749 int channel_num = vie_.GetLastChannel();
750 EXPECT_EQ(webrtc::kRtcpCompound_RFC4585, vie_.GetRtcpStatus(channel_num));
751}
752
753// Test that key frame request method is set on the channel.
754TEST_F(WebRtcVideoEngineTestFake, KeyFrameRequestEnabled) {
755 EXPECT_TRUE(SetupEngine());
756 int channel_num = vie_.GetLastChannel();
757 EXPECT_EQ(webrtc::kViEKeyFrameRequestPliRtcp,
758 vie_.GetKeyFrameRequestMethod(channel_num));
759}
760
761// Test that remb receive and send is enabled for the default channel in a 1:1
762// call.
763TEST_F(WebRtcVideoEngineTestFake, RembEnabled) {
764 EXPECT_TRUE(SetupEngine());
765 int channel_num = vie_.GetLastChannel();
766 EXPECT_TRUE(channel_->AddSendStream(
767 cricket::StreamParams::CreateLegacy(1)));
768 EXPECT_TRUE(channel_->SetSendCodecs(engine_.codecs()));
769 EXPECT_TRUE(vie_.GetRembStatusBwPartition(channel_num));
770 EXPECT_TRUE(channel_->SetSend(true));
771 EXPECT_TRUE(vie_.GetRembStatusBwPartition(channel_num));
772 EXPECT_TRUE(vie_.GetRembStatusContribute(channel_num));
773}
774
775// When in conference mode, test that remb is enabled on a receive channel but
776// not for the default channel and that it uses the default channel for sending
777// remb packets.
778TEST_F(WebRtcVideoEngineTestFake, RembEnabledOnReceiveChannels) {
779 EXPECT_TRUE(SetupEngine());
780 int default_channel = vie_.GetLastChannel();
781 cricket::VideoOptions options;
782 options.conference_mode.Set(true);
783 EXPECT_TRUE(channel_->SetOptions(options));
784 EXPECT_TRUE(channel_->AddSendStream(
785 cricket::StreamParams::CreateLegacy(1)));
786 EXPECT_TRUE(channel_->SetSendCodecs(engine_.codecs()));
787 EXPECT_TRUE(vie_.GetRembStatusBwPartition(default_channel));
788 EXPECT_TRUE(vie_.GetRembStatusContribute(default_channel));
789 EXPECT_TRUE(channel_->SetSend(true));
790 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(1)));
791 int new_channel_num = vie_.GetLastChannel();
792 EXPECT_NE(default_channel, new_channel_num);
793
794 EXPECT_TRUE(vie_.GetRembStatusBwPartition(default_channel));
795 EXPECT_TRUE(vie_.GetRembStatusContribute(default_channel));
796 EXPECT_FALSE(vie_.GetRembStatusBwPartition(new_channel_num));
797 EXPECT_TRUE(vie_.GetRembStatusContribute(new_channel_num));
798}
799
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000800TEST_F(WebRtcVideoEngineTestFake, RecvStreamWithRtx) {
801 EXPECT_TRUE(SetupEngine());
802 int default_channel = vie_.GetLastChannel();
803 cricket::VideoOptions options;
804 options.conference_mode.Set(true);
805 EXPECT_TRUE(channel_->SetOptions(options));
806 EXPECT_TRUE(channel_->AddSendStream(
807 cricket::CreateSimWithRtxStreamParams("cname",
808 MAKE_VECTOR(kSsrcs3),
809 MAKE_VECTOR(kRtxSsrcs3))));
810 EXPECT_TRUE(channel_->SetSendCodecs(engine_.codecs()));
811 EXPECT_TRUE(channel_->SetSend(true));
812 EXPECT_TRUE(channel_->AddRecvStream(
813 cricket::CreateSimWithRtxStreamParams("cname",
814 MAKE_VECTOR(kSsrcs1),
815 MAKE_VECTOR(kRtxSsrc1))));
816 int new_channel_num = vie_.GetLastChannel();
817 EXPECT_NE(default_channel, new_channel_num);
818 EXPECT_EQ(4, vie_.GetRemoteRtxSsrc(new_channel_num));
819}
820
821TEST_F(WebRtcVideoEngineTestFake, RecvStreamNoRtx) {
822 EXPECT_TRUE(SetupEngine());
823 int default_channel = vie_.GetLastChannel();
824 cricket::VideoOptions options;
825 options.conference_mode.Set(true);
826 EXPECT_TRUE(channel_->SetOptions(options));
827 EXPECT_TRUE(channel_->AddSendStream(
828 cricket::CreateSimWithRtxStreamParams("cname",
829 MAKE_VECTOR(kSsrcs3),
830 MAKE_VECTOR(kRtxSsrcs3))));
831 EXPECT_TRUE(channel_->SetSendCodecs(engine_.codecs()));
832 EXPECT_TRUE(channel_->SetSend(true));
833 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(1)));
834 int new_channel_num = vie_.GetLastChannel();
835 EXPECT_NE(default_channel, new_channel_num);
836 EXPECT_EQ(-1, vie_.GetRemoteRtxSsrc(new_channel_num));
837}
838
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000839// Test support for RTP timestamp offset header extension.
buildbot@webrtc.org150835e2014-05-06 15:54:38 +0000840TEST_F(WebRtcVideoEngineTestFake, SendRtpTimestampOffsetHeaderExtensions) {
841 TestSetSendRtpHeaderExtensions(kRtpTimestampOffsetHeaderExtension);
842}
843TEST_F(WebRtcVideoEngineTestFake, RecvRtpTimestampOffsetHeaderExtensions) {
844 TestSetRecvRtpHeaderExtensions(kRtpTimestampOffsetHeaderExtension);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000845}
846
847// Test support for absolute send time header extension.
buildbot@webrtc.org150835e2014-05-06 15:54:38 +0000848TEST_F(WebRtcVideoEngineTestFake, SendAbsoluteSendTimeHeaderExtensions) {
849 TestSetSendRtpHeaderExtensions(kRtpAbsoluteSenderTimeHeaderExtension);
850}
851TEST_F(WebRtcVideoEngineTestFake, RecvAbsoluteSendTimeHeaderExtensions) {
852 TestSetRecvRtpHeaderExtensions(kRtpAbsoluteSenderTimeHeaderExtension);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000853}
854
855TEST_F(WebRtcVideoEngineTestFake, LeakyBucketTest) {
856 EXPECT_TRUE(SetupEngine());
857
858 // Verify this is off by default.
859 EXPECT_TRUE(channel_->AddSendStream(cricket::StreamParams::CreateLegacy(1)));
860 int first_send_channel = vie_.GetLastChannel();
861 EXPECT_FALSE(vie_.GetTransmissionSmoothingStatus(first_send_channel));
862
863 // Enable the experiment and verify.
864 cricket::VideoOptions options;
865 options.conference_mode.Set(true);
866 options.video_leaky_bucket.Set(true);
867 EXPECT_TRUE(channel_->SetOptions(options));
868 EXPECT_TRUE(vie_.GetTransmissionSmoothingStatus(first_send_channel));
869
870 // Add a receive channel and verify leaky bucket isn't enabled.
871 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(2)));
872 int recv_channel_num = vie_.GetLastChannel();
873 EXPECT_NE(first_send_channel, recv_channel_num);
874 EXPECT_FALSE(vie_.GetTransmissionSmoothingStatus(recv_channel_num));
875
876 // Add a new send stream and verify leaky bucket is enabled from start.
877 EXPECT_TRUE(channel_->AddSendStream(cricket::StreamParams::CreateLegacy(3)));
878 int second_send_channel = vie_.GetLastChannel();
879 EXPECT_NE(first_send_channel, second_send_channel);
880 EXPECT_TRUE(vie_.GetTransmissionSmoothingStatus(second_send_channel));
881}
882
henrike@webrtc.org6e3dbc22014-03-25 17:09:47 +0000883// Verify that SuspendBelowMinBitrate is enabled if it is set in the options.
884TEST_F(WebRtcVideoEngineTestFake, SuspendBelowMinBitrateTest) {
885 EXPECT_TRUE(SetupEngine());
886
887 // Verify this is off by default.
888 EXPECT_TRUE(channel_->AddSendStream(cricket::StreamParams::CreateLegacy(1)));
889 int first_send_channel = vie_.GetLastChannel();
890 EXPECT_FALSE(vie_.GetSuspendBelowMinBitrateStatus(first_send_channel));
891
892 // Enable the experiment and verify.
893 cricket::VideoOptions options;
894 options.suspend_below_min_bitrate.Set(true);
895 EXPECT_TRUE(channel_->SetOptions(options));
896 EXPECT_TRUE(vie_.GetSuspendBelowMinBitrateStatus(first_send_channel));
897
898 // Add a new send stream and verify suspend_below_min_bitrate is enabled.
899 EXPECT_TRUE(channel_->AddSendStream(cricket::StreamParams::CreateLegacy(2)));
900 int second_send_channel = vie_.GetLastChannel();
901 EXPECT_NE(first_send_channel, second_send_channel);
902 EXPECT_TRUE(vie_.GetSuspendBelowMinBitrateStatus(second_send_channel));
903}
904
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000905TEST_F(WebRtcVideoEngineTestFake, BufferedModeLatency) {
906 EXPECT_TRUE(SetupEngine());
907
908 // Verify this is off by default.
909 EXPECT_TRUE(channel_->AddSendStream(cricket::StreamParams::CreateLegacy(1)));
910 int first_send_channel = vie_.GetLastChannel();
911 EXPECT_EQ(0, vie_.GetSenderTargetDelay(first_send_channel));
912 EXPECT_EQ(0, vie_.GetReceiverTargetDelay(first_send_channel));
913
914 // Enable the experiment and verify. The default channel will have both
915 // sender and receiver buffered mode enabled.
916 cricket::VideoOptions options;
917 options.conference_mode.Set(true);
918 options.buffered_mode_latency.Set(100);
919 EXPECT_TRUE(channel_->SetOptions(options));
920 EXPECT_EQ(100, vie_.GetSenderTargetDelay(first_send_channel));
921 EXPECT_EQ(100, vie_.GetReceiverTargetDelay(first_send_channel));
922
923 // Add a receive channel and verify sender buffered mode isn't enabled.
924 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(2)));
925 int recv_channel_num = vie_.GetLastChannel();
926 EXPECT_NE(first_send_channel, recv_channel_num);
927 EXPECT_EQ(0, vie_.GetSenderTargetDelay(recv_channel_num));
928 EXPECT_EQ(100, vie_.GetReceiverTargetDelay(recv_channel_num));
929
930 // Add a new send stream and verify sender buffered mode is enabled.
931 EXPECT_TRUE(channel_->AddSendStream(cricket::StreamParams::CreateLegacy(3)));
932 int second_send_channel = vie_.GetLastChannel();
933 EXPECT_NE(first_send_channel, second_send_channel);
934 EXPECT_EQ(100, vie_.GetSenderTargetDelay(second_send_channel));
935 EXPECT_EQ(0, vie_.GetReceiverTargetDelay(second_send_channel));
936
937 // Disable sender buffered mode and verify.
938 options.buffered_mode_latency.Set(cricket::kBufferedModeDisabled);
939 EXPECT_TRUE(channel_->SetOptions(options));
940 EXPECT_EQ(0, vie_.GetSenderTargetDelay(first_send_channel));
941 EXPECT_EQ(0, vie_.GetReceiverTargetDelay(first_send_channel));
942 EXPECT_EQ(0, vie_.GetSenderTargetDelay(second_send_channel));
943 EXPECT_EQ(0, vie_.GetReceiverTargetDelay(second_send_channel));
944 EXPECT_EQ(0, vie_.GetSenderTargetDelay(recv_channel_num));
945 EXPECT_EQ(0, vie_.GetReceiverTargetDelay(recv_channel_num));
946}
947
948TEST_F(WebRtcVideoEngineTestFake, AdditiveVideoOptions) {
949 EXPECT_TRUE(SetupEngine());
950
951 EXPECT_TRUE(channel_->AddSendStream(cricket::StreamParams::CreateLegacy(1)));
952 int first_send_channel = vie_.GetLastChannel();
953 EXPECT_EQ(0, vie_.GetSenderTargetDelay(first_send_channel));
954 EXPECT_EQ(0, vie_.GetReceiverTargetDelay(first_send_channel));
955
956 cricket::VideoOptions options1;
957 options1.buffered_mode_latency.Set(100);
958 EXPECT_TRUE(channel_->SetOptions(options1));
959 EXPECT_EQ(100, vie_.GetSenderTargetDelay(first_send_channel));
960 EXPECT_EQ(100, vie_.GetReceiverTargetDelay(first_send_channel));
961 EXPECT_FALSE(vie_.GetTransmissionSmoothingStatus(first_send_channel));
962
963 cricket::VideoOptions options2;
964 options2.video_leaky_bucket.Set(true);
965 EXPECT_TRUE(channel_->SetOptions(options2));
966 EXPECT_TRUE(vie_.GetTransmissionSmoothingStatus(first_send_channel));
967 // The buffered_mode_latency still takes effect.
968 EXPECT_EQ(100, vie_.GetSenderTargetDelay(first_send_channel));
969 EXPECT_EQ(100, vie_.GetReceiverTargetDelay(first_send_channel));
970
971 options1.buffered_mode_latency.Set(50);
972 EXPECT_TRUE(channel_->SetOptions(options1));
973 EXPECT_EQ(50, vie_.GetSenderTargetDelay(first_send_channel));
974 EXPECT_EQ(50, vie_.GetReceiverTargetDelay(first_send_channel));
975 // The video_leaky_bucket still takes effect.
976 EXPECT_TRUE(vie_.GetTransmissionSmoothingStatus(first_send_channel));
977}
978
henrike@webrtc.orgb0ecc1c2014-03-26 22:44:28 +0000979TEST_F(WebRtcVideoEngineTestFake, SetCpuOveruseOptionsWithCaptureJitterMethod) {
980 EXPECT_TRUE(SetupEngine());
981
982 // Verify this is off by default.
983 EXPECT_TRUE(channel_->AddSendStream(cricket::StreamParams::CreateLegacy(1)));
984 int first_send_channel = vie_.GetLastChannel();
985 webrtc::CpuOveruseOptions cpu_option =
986 vie_.GetCpuOveruseOptions(first_send_channel);
987 EXPECT_EQ(0, cpu_option.low_capture_jitter_threshold_ms);
988 EXPECT_EQ(0, cpu_option.high_capture_jitter_threshold_ms);
989 EXPECT_FALSE(cpu_option.enable_capture_jitter_method);
990 EXPECT_FALSE(cpu_option.enable_encode_usage_method);
991
992 // Set low and high threshold and verify that cpu options are set.
993 cricket::VideoOptions options;
994 options.conference_mode.Set(true);
995 options.cpu_underuse_threshold.Set(10);
996 options.cpu_overuse_threshold.Set(20);
997 EXPECT_TRUE(channel_->SetOptions(options));
998 cpu_option = vie_.GetCpuOveruseOptions(first_send_channel);
999 EXPECT_EQ(10, cpu_option.low_capture_jitter_threshold_ms);
1000 EXPECT_EQ(20, cpu_option.high_capture_jitter_threshold_ms);
1001 EXPECT_TRUE(cpu_option.enable_capture_jitter_method);
1002 EXPECT_FALSE(cpu_option.enable_encode_usage_method);
1003
1004 // Add a receive channel and verify that cpu options are not set.
1005 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(2)));
1006 int recv_channel_num = vie_.GetLastChannel();
1007 EXPECT_NE(first_send_channel, recv_channel_num);
1008 cpu_option = vie_.GetCpuOveruseOptions(recv_channel_num);
1009 EXPECT_EQ(0, cpu_option.low_capture_jitter_threshold_ms);
1010 EXPECT_EQ(0, cpu_option.high_capture_jitter_threshold_ms);
1011 EXPECT_FALSE(cpu_option.enable_capture_jitter_method);
1012 EXPECT_FALSE(cpu_option.enable_encode_usage_method);
1013
1014 // Add a new send stream and verify that cpu options are set from start.
1015 EXPECT_TRUE(channel_->AddSendStream(cricket::StreamParams::CreateLegacy(3)));
1016 int second_send_channel = vie_.GetLastChannel();
1017 EXPECT_NE(first_send_channel, second_send_channel);
1018 cpu_option = vie_.GetCpuOveruseOptions(second_send_channel);
1019 EXPECT_EQ(10, cpu_option.low_capture_jitter_threshold_ms);
1020 EXPECT_EQ(20, cpu_option.high_capture_jitter_threshold_ms);
1021 EXPECT_TRUE(cpu_option.enable_capture_jitter_method);
1022 EXPECT_FALSE(cpu_option.enable_encode_usage_method);
1023}
1024
1025TEST_F(WebRtcVideoEngineTestFake, SetInvalidCpuOveruseThresholds) {
1026 EXPECT_TRUE(SetupEngine());
1027 EXPECT_TRUE(channel_->AddSendStream(cricket::StreamParams::CreateLegacy(1)));
1028 int channel_num = vie_.GetLastChannel();
1029
1030 // Only low threshold set. Verify that cpu options are not set.
1031 cricket::VideoOptions options;
1032 options.conference_mode.Set(true);
1033 options.cpu_underuse_threshold.Set(10);
1034 EXPECT_TRUE(channel_->SetOptions(options));
1035 webrtc::CpuOveruseOptions cpu_option = vie_.GetCpuOveruseOptions(channel_num);
1036 EXPECT_EQ(0, cpu_option.low_capture_jitter_threshold_ms);
1037 EXPECT_EQ(0, cpu_option.high_capture_jitter_threshold_ms);
1038 EXPECT_FALSE(cpu_option.enable_capture_jitter_method);
1039 EXPECT_FALSE(cpu_option.enable_encode_usage_method);
1040
1041 // Set high threshold to a negative value. Verify that options are not set.
1042 options.cpu_overuse_threshold.Set(-1);
1043 EXPECT_TRUE(channel_->SetOptions(options));
1044 cpu_option = vie_.GetCpuOveruseOptions(channel_num);
1045 EXPECT_EQ(0, cpu_option.low_capture_jitter_threshold_ms);
1046 EXPECT_EQ(0, cpu_option.high_capture_jitter_threshold_ms);
1047 EXPECT_FALSE(cpu_option.enable_capture_jitter_method);
1048 EXPECT_FALSE(cpu_option.enable_encode_usage_method);
1049
1050 // Low and high threshold valid. Verify that cpu options are set.
1051 options.cpu_overuse_threshold.Set(20);
1052 EXPECT_TRUE(channel_->SetOptions(options));
1053 cpu_option = vie_.GetCpuOveruseOptions(channel_num);
1054 EXPECT_EQ(10, cpu_option.low_capture_jitter_threshold_ms);
1055 EXPECT_EQ(20, cpu_option.high_capture_jitter_threshold_ms);
1056 EXPECT_TRUE(cpu_option.enable_capture_jitter_method);
1057 EXPECT_FALSE(cpu_option.enable_encode_usage_method);
1058}
1059
1060TEST_F(WebRtcVideoEngineTestFake, SetCpuOveruseOptionsWithEncodeUsageMethod) {
1061 EXPECT_TRUE(SetupEngine());
1062 EXPECT_TRUE(channel_->AddSendStream(cricket::StreamParams::CreateLegacy(1)));
1063 int first_send_channel = vie_.GetLastChannel();
1064
1065 // Set low and high threshold and enable encode usage method.
1066 // Verify that cpu options are set.
1067 cricket::VideoOptions options;
1068 options.conference_mode.Set(true);
1069 options.cpu_underuse_threshold.Set(10);
1070 options.cpu_overuse_threshold.Set(20);
1071 options.cpu_overuse_encode_usage.Set(true);
1072 EXPECT_TRUE(channel_->SetOptions(options));
1073 webrtc::CpuOveruseOptions cpu_option =
1074 vie_.GetCpuOveruseOptions(first_send_channel);
1075 EXPECT_EQ(10, cpu_option.low_encode_usage_threshold_percent);
1076 EXPECT_EQ(20, cpu_option.high_encode_usage_threshold_percent);
1077 EXPECT_FALSE(cpu_option.enable_capture_jitter_method);
1078 EXPECT_TRUE(cpu_option.enable_encode_usage_method);
1079
1080 // Add a new send stream and verify that cpu options are set from start.
1081 EXPECT_TRUE(channel_->AddSendStream(cricket::StreamParams::CreateLegacy(3)));
1082 int second_send_channel = vie_.GetLastChannel();
1083 EXPECT_NE(first_send_channel, second_send_channel);
1084 cpu_option = vie_.GetCpuOveruseOptions(second_send_channel);
1085 EXPECT_EQ(10, cpu_option.low_encode_usage_threshold_percent);
1086 EXPECT_EQ(20, cpu_option.high_encode_usage_threshold_percent);
1087 EXPECT_FALSE(cpu_option.enable_capture_jitter_method);
1088 EXPECT_TRUE(cpu_option.enable_encode_usage_method);
1089}
henrike@webrtc.orgb0ecc1c2014-03-26 22:44:28 +00001090
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001091// Test that AddRecvStream doesn't create new channel for 1:1 call.
1092TEST_F(WebRtcVideoEngineTestFake, AddRecvStream1On1) {
1093 EXPECT_TRUE(SetupEngine());
1094 int channel_num = vie_.GetLastChannel();
1095 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(1)));
1096 EXPECT_EQ(channel_num, vie_.GetLastChannel());
1097}
1098
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +00001099// Test that NACK, PLI and REMB are enabled for internal codec.
1100TEST_F(WebRtcVideoEngineTestFake, InternalCodecFeedbackParams) {
1101 EXPECT_TRUE(SetupEngine());
1102
1103 std::vector<cricket::VideoCodec> codecs(engine_.codecs());
1104 // Vp8 will appear at the beginning.
1105 size_t pos = 0;
1106 EXPECT_EQ("VP8", codecs[pos].name);
1107 VerifyCodecFeedbackParams(codecs[pos]);
1108}
1109
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001110// Test that AddRecvStream doesn't change remb for 1:1 call.
1111TEST_F(WebRtcVideoEngineTestFake, NoRembChangeAfterAddRecvStream) {
1112 EXPECT_TRUE(SetupEngine());
1113 int channel_num = vie_.GetLastChannel();
1114 EXPECT_TRUE(channel_->AddSendStream(
1115 cricket::StreamParams::CreateLegacy(1)));
1116 EXPECT_TRUE(channel_->SetSendCodecs(engine_.codecs()));
1117 EXPECT_TRUE(vie_.GetRembStatusBwPartition(channel_num));
1118 EXPECT_TRUE(vie_.GetRembStatusContribute(channel_num));
1119 EXPECT_TRUE(channel_->SetSend(true));
1120 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(1)));
1121 EXPECT_TRUE(vie_.GetRembStatusBwPartition(channel_num));
1122 EXPECT_TRUE(vie_.GetRembStatusContribute(channel_num));
1123}
1124
1125// Verify default REMB setting and that it can be turned on and off.
1126TEST_F(WebRtcVideoEngineTestFake, RembOnOff) {
1127 EXPECT_TRUE(SetupEngine());
1128 int channel_num = vie_.GetLastChannel();
1129 // Verify REMB sending is always off by default.
1130 EXPECT_FALSE(vie_.GetRembStatusBwPartition(channel_num));
1131
1132 // Verify that REMB is turned on when setting default codecs since the
1133 // default codecs have REMB enabled.
1134 EXPECT_TRUE(channel_->SetSendCodecs(engine_.codecs()));
1135 EXPECT_TRUE(vie_.GetRembStatusBwPartition(channel_num));
1136
1137 // Verify that REMB is turned off when codecs without REMB are set.
1138 std::vector<cricket::VideoCodec> codecs = engine_.codecs();
1139 // Clearing the codecs' FeedbackParams and setting send codecs should disable
1140 // REMB.
1141 for (std::vector<cricket::VideoCodec>::iterator iter = codecs.begin();
1142 iter != codecs.end(); ++iter) {
1143 // Intersecting with empty will clear the FeedbackParams.
1144 cricket::FeedbackParams empty_params;
1145 iter->feedback_params.Intersect(empty_params);
1146 EXPECT_TRUE(iter->feedback_params.params().empty());
1147 }
1148 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1149 EXPECT_FALSE(vie_.GetRembStatusBwPartition(channel_num));
1150}
1151
1152// Test that nack is enabled on the channel if we don't offer red/fec.
1153TEST_F(WebRtcVideoEngineTestFake, NackEnabled) {
1154 EXPECT_TRUE(SetupEngine());
1155 int channel_num = vie_.GetLastChannel();
1156 std::vector<cricket::VideoCodec> codecs(engine_.codecs());
1157 codecs.resize(1); // toss out red and ulpfec
1158 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1159 EXPECT_TRUE(vie_.GetNackStatus(channel_num));
1160}
1161
1162// Test that we enable hybrid NACK FEC mode.
1163TEST_F(WebRtcVideoEngineTestFake, HybridNackFec) {
1164 EXPECT_TRUE(SetupEngine());
1165 int channel_num = vie_.GetLastChannel();
1166 EXPECT_TRUE(channel_->SetRecvCodecs(engine_.codecs()));
1167 EXPECT_TRUE(channel_->SetSendCodecs(engine_.codecs()));
1168 EXPECT_TRUE(vie_.GetHybridNackFecStatus(channel_num));
1169 EXPECT_FALSE(vie_.GetNackStatus(channel_num));
1170}
1171
1172// Test that we enable hybrid NACK FEC mode when calling SetSendCodecs and
1173// SetReceiveCodecs in reversed order.
1174TEST_F(WebRtcVideoEngineTestFake, HybridNackFecReversedOrder) {
1175 EXPECT_TRUE(SetupEngine());
1176 int channel_num = vie_.GetLastChannel();
1177 EXPECT_TRUE(channel_->SetSendCodecs(engine_.codecs()));
1178 EXPECT_TRUE(channel_->SetRecvCodecs(engine_.codecs()));
1179 EXPECT_TRUE(vie_.GetHybridNackFecStatus(channel_num));
1180 EXPECT_FALSE(vie_.GetNackStatus(channel_num));
1181}
1182
1183// Test NACK vs Hybrid NACK/FEC interop call setup, i.e. only use NACK even if
1184// red/fec is offered as receive codec.
1185TEST_F(WebRtcVideoEngineTestFake, VideoProtectionInterop) {
1186 EXPECT_TRUE(SetupEngine());
1187 int channel_num = vie_.GetLastChannel();
1188 std::vector<cricket::VideoCodec> recv_codecs(engine_.codecs());
1189 std::vector<cricket::VideoCodec> send_codecs(engine_.codecs());
1190 // Only add VP8 as send codec.
1191 send_codecs.resize(1);
1192 EXPECT_TRUE(channel_->SetRecvCodecs(recv_codecs));
1193 EXPECT_TRUE(channel_->SetSendCodecs(send_codecs));
1194 EXPECT_FALSE(vie_.GetHybridNackFecStatus(channel_num));
1195 EXPECT_TRUE(vie_.GetNackStatus(channel_num));
1196}
1197
1198// Test NACK vs Hybrid NACK/FEC interop call setup, i.e. only use NACK even if
1199// red/fec is offered as receive codec. Call order reversed compared to
1200// VideoProtectionInterop.
1201TEST_F(WebRtcVideoEngineTestFake, VideoProtectionInteropReversed) {
1202 EXPECT_TRUE(SetupEngine());
1203 int channel_num = vie_.GetLastChannel();
1204 std::vector<cricket::VideoCodec> recv_codecs(engine_.codecs());
1205 std::vector<cricket::VideoCodec> send_codecs(engine_.codecs());
1206 // Only add VP8 as send codec.
1207 send_codecs.resize(1);
1208 EXPECT_TRUE(channel_->SetSendCodecs(send_codecs));
1209 EXPECT_TRUE(channel_->SetRecvCodecs(recv_codecs));
1210 EXPECT_FALSE(vie_.GetHybridNackFecStatus(channel_num));
1211 EXPECT_TRUE(vie_.GetNackStatus(channel_num));
1212}
1213
1214// Test that NACK, not hybrid mode, is enabled in conference mode.
1215TEST_F(WebRtcVideoEngineTestFake, HybridNackFecConference) {
1216 EXPECT_TRUE(SetupEngine());
1217 // Setup the send channel.
1218 int send_channel_num = vie_.GetLastChannel();
1219 cricket::VideoOptions options;
1220 options.conference_mode.Set(true);
1221 EXPECT_TRUE(channel_->SetOptions(options));
1222 EXPECT_TRUE(channel_->SetRecvCodecs(engine_.codecs()));
1223 EXPECT_TRUE(channel_->SetSendCodecs(engine_.codecs()));
1224 EXPECT_FALSE(vie_.GetHybridNackFecStatus(send_channel_num));
1225 EXPECT_TRUE(vie_.GetNackStatus(send_channel_num));
1226 // Add a receive stream.
1227 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(1)));
1228 int receive_channel_num = vie_.GetLastChannel();
1229 EXPECT_FALSE(vie_.GetHybridNackFecStatus(receive_channel_num));
1230 EXPECT_TRUE(vie_.GetNackStatus(receive_channel_num));
1231}
1232
1233// Test that when AddRecvStream in conference mode, a new channel is created
1234// for receiving. And the new channel's "original channel" is the send channel.
1235TEST_F(WebRtcVideoEngineTestFake, AddRemoveRecvStreamConference) {
1236 EXPECT_TRUE(SetupEngine());
1237 // Setup the send channel.
1238 int send_channel_num = vie_.GetLastChannel();
1239 cricket::VideoOptions options;
1240 options.conference_mode.Set(true);
1241 EXPECT_TRUE(channel_->SetOptions(options));
1242 // Add a receive stream.
1243 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(1)));
1244 int receive_channel_num = vie_.GetLastChannel();
1245 EXPECT_EQ(send_channel_num, vie_.GetOriginalChannelId(receive_channel_num));
1246 EXPECT_TRUE(channel_->RemoveRecvStream(1));
1247 EXPECT_FALSE(vie_.IsChannel(receive_channel_num));
1248}
1249
henrike@webrtc.org6e3dbc22014-03-25 17:09:47 +00001250// Test that adding/removing stream with 0 ssrc should fail (and not crash).
1251// For crbug/351699 and 350988.
1252TEST_F(WebRtcVideoEngineTestFake, AddRemoveRecvStreamWith0Ssrc) {
1253 EXPECT_TRUE(SetupEngine());
1254 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(1)));
1255 EXPECT_FALSE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(0)));
1256 EXPECT_FALSE(channel_->RemoveRecvStream(0));
1257 EXPECT_TRUE(channel_->RemoveRecvStream(1));
1258}
1259
1260TEST_F(WebRtcVideoEngineTestFake, AddRemoveSendStreamWith0Ssrc) {
1261 EXPECT_TRUE(SetupEngine());
1262 EXPECT_TRUE(channel_->AddSendStream(cricket::StreamParams::CreateLegacy(1)));
1263 EXPECT_FALSE(channel_->AddSendStream(cricket::StreamParams::CreateLegacy(0)));
1264 EXPECT_FALSE(channel_->RemoveSendStream(0));
1265 EXPECT_TRUE(channel_->RemoveSendStream(1));
1266}
1267
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001268// Test that we can create a channel and start/stop rendering out on it.
1269TEST_F(WebRtcVideoEngineTestFake, SetRender) {
1270 EXPECT_TRUE(SetupEngine());
1271 int channel_num = vie_.GetLastChannel();
1272
1273 // Verify we can start/stop/start/stop rendering.
1274 EXPECT_TRUE(channel_->SetRender(true));
1275 EXPECT_TRUE(vie_.GetRenderStarted(channel_num));
1276 EXPECT_TRUE(channel_->SetRender(false));
1277 EXPECT_FALSE(vie_.GetRenderStarted(channel_num));
1278 EXPECT_TRUE(channel_->SetRender(true));
1279 EXPECT_TRUE(vie_.GetRenderStarted(channel_num));
1280 EXPECT_TRUE(channel_->SetRender(false));
1281 EXPECT_FALSE(vie_.GetRenderStarted(channel_num));
1282}
1283
1284// Test that we can create a channel and start/stop sending out on it.
1285TEST_F(WebRtcVideoEngineTestFake, SetSend) {
1286 EXPECT_TRUE(SetupEngine());
1287 int channel_num = vie_.GetLastChannel();
wu@webrtc.orgb9a088b2014-02-13 23:18:49 +00001288 // Verify receiving is also started.
1289 EXPECT_TRUE(vie_.GetReceive(channel_num));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001290
1291 // Set send codecs on the channel.
1292 std::vector<cricket::VideoCodec> codecs;
1293 codecs.push_back(kVP8Codec);
1294 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1295 EXPECT_TRUE(channel_->AddSendStream(
1296 cricket::StreamParams::CreateLegacy(123)));
1297
1298 // Verify we can start/stop/start/stop sending.
1299 EXPECT_TRUE(channel_->SetSend(true));
1300 EXPECT_TRUE(vie_.GetSend(channel_num));
1301 EXPECT_TRUE(channel_->SetSend(false));
1302 EXPECT_FALSE(vie_.GetSend(channel_num));
1303 EXPECT_TRUE(channel_->SetSend(true));
1304 EXPECT_TRUE(vie_.GetSend(channel_num));
1305 EXPECT_TRUE(channel_->SetSend(false));
1306 EXPECT_FALSE(vie_.GetSend(channel_num));
1307}
1308
1309// Test that we set bandwidth properly when using full auto bandwidth mode.
1310TEST_F(WebRtcVideoEngineTestFake, SetBandwidthAuto) {
1311 EXPECT_TRUE(SetupEngine());
1312 int channel_num = vie_.GetLastChannel();
1313 EXPECT_TRUE(channel_->SetSendCodecs(engine_.codecs()));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001314 EXPECT_TRUE(channel_->SetMaxSendBandwidth(cricket::kAutoBandwidth));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001315 VerifyVP8SendCodec(channel_num, kVP8Codec.width, kVP8Codec.height);
1316}
1317
1318// Test that we set bandwidth properly when using auto with upper bound.
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001319TEST_F(WebRtcVideoEngineTestFake, SetBandwidthCapped) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001320 EXPECT_TRUE(SetupEngine());
1321 int channel_num = vie_.GetLastChannel();
1322 EXPECT_TRUE(channel_->SetSendCodecs(engine_.codecs()));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001323 EXPECT_TRUE(channel_->SetMaxSendBandwidth(768000));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001324 VerifyVP8SendCodec(channel_num, kVP8Codec.width, kVP8Codec.height, 0, 768U);
1325}
1326
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001327// Test that we reduce the start bandwidth when the requested max is less than
1328// the default start bandwidth.
1329TEST_F(WebRtcVideoEngineTestFake, SetMaxBandwidthBelowDefaultStart) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001330 EXPECT_TRUE(SetupEngine());
1331 int channel_num = vie_.GetLastChannel();
1332 EXPECT_TRUE(channel_->SetSendCodecs(engine_.codecs()));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001333 int max_bandwidth_kbps = (kMinBandwidthKbps + kStartBandwidthKbps) / 2;
1334 EXPECT_TRUE(channel_->SetMaxSendBandwidth(max_bandwidth_kbps * 1000));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001335 VerifyVP8SendCodec(channel_num, kVP8Codec.width, kVP8Codec.height, 0,
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001336 max_bandwidth_kbps, kMinBandwidthKbps, max_bandwidth_kbps);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001337}
1338
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001339// Test that we reduce the min bandwidth when the requested max is less than
1340// the min bandwidth.
1341TEST_F(WebRtcVideoEngineTestFake, SetMaxBandwidthBelowMin) {
1342 EXPECT_TRUE(SetupEngine());
1343 int channel_num = vie_.GetLastChannel();
1344 EXPECT_TRUE(channel_->SetSendCodecs(engine_.codecs()));
1345 int max_bandwidth_kbps = kMinBandwidthKbps / 2;
1346 EXPECT_TRUE(channel_->SetMaxSendBandwidth(max_bandwidth_kbps * 1000));
1347 VerifyVP8SendCodec(channel_num, kVP8Codec.width, kVP8Codec.height, 0,
1348 max_bandwidth_kbps, max_bandwidth_kbps, max_bandwidth_kbps);
1349}
1350
1351// Test that the start bandwidth can be controlled separately from the max
1352// bandwidth.
1353TEST_F(WebRtcVideoEngineTestFake, SetStartBandwidth) {
1354 EXPECT_TRUE(SetupEngine());
1355 int channel_num = vie_.GetLastChannel();
1356 EXPECT_TRUE(channel_->SetSendCodecs(engine_.codecs()));
1357 int start_bandwidth_kbps = kStartBandwidthKbps + 1;
1358 EXPECT_TRUE(channel_->SetStartSendBandwidth(start_bandwidth_kbps * 1000));
1359 VerifyVP8SendCodec(channel_num, kVP8Codec.width, kVP8Codec.height, 0,
1360 kMaxBandwidthKbps, kMinBandwidthKbps, start_bandwidth_kbps);
1361
1362 // Check that SetMaxSendBandwidth doesn't overwrite the start bandwidth.
1363 int max_bandwidth_kbps = kMaxBandwidthKbps + 1;
1364 EXPECT_TRUE(channel_->SetMaxSendBandwidth(max_bandwidth_kbps * 1000));
1365 VerifyVP8SendCodec(channel_num, kVP8Codec.width, kVP8Codec.height, 0,
1366 max_bandwidth_kbps, kMinBandwidthKbps, start_bandwidth_kbps);
1367}
1368
wu@webrtc.org1e6cb2c2014-03-24 17:01:50 +00001369// Test that the start bandwidth can be controlled by experiment.
1370TEST_F(WebRtcVideoEngineTestFake, SetStartBandwidthOption) {
1371 EXPECT_TRUE(SetupEngine());
1372 int channel_num = vie_.GetLastChannel();
1373 EXPECT_TRUE(channel_->SetSendCodecs(engine_.codecs()));
1374 int start_bandwidth_kbps = kStartBandwidthKbps;
1375 EXPECT_TRUE(channel_->SetStartSendBandwidth(start_bandwidth_kbps * 1000));
1376 VerifyVP8SendCodec(channel_num, kVP8Codec.width, kVP8Codec.height, 0,
1377 kMaxBandwidthKbps, kMinBandwidthKbps, start_bandwidth_kbps);
1378
1379 // Set the start bitrate option.
1380 start_bandwidth_kbps = 1000;
1381 cricket::VideoOptions options;
1382 options.video_start_bitrate.Set(
1383 start_bandwidth_kbps);
1384 EXPECT_TRUE(channel_->SetOptions(options));
1385
1386 // Check that start bitrate has changed to the new value.
1387 VerifyVP8SendCodec(channel_num, kVP8Codec.width, kVP8Codec.height, 0,
1388 kMaxBandwidthKbps, kMinBandwidthKbps, start_bandwidth_kbps);
1389}
1390
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001391// Test that SetMaxSendBandwidth is ignored in conference mode.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001392TEST_F(WebRtcVideoEngineTestFake, SetBandwidthInConference) {
1393 EXPECT_TRUE(SetupEngine());
1394 int channel_num = vie_.GetLastChannel();
1395 cricket::VideoOptions options;
1396 options.conference_mode.Set(true);
1397 EXPECT_TRUE(channel_->SetOptions(options));
1398 EXPECT_TRUE(channel_->SetSendCodecs(engine_.codecs()));
1399 VerifyVP8SendCodec(channel_num, kVP8Codec.width, kVP8Codec.height);
1400
1401 // Set send bandwidth.
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001402 EXPECT_TRUE(channel_->SetMaxSendBandwidth(768000));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001403
1404 // Verify bitrate not changed.
1405 webrtc::VideoCodec gcodec;
1406 EXPECT_EQ(0, vie_.GetSendCodec(channel_num, gcodec));
1407 EXPECT_EQ(kMinBandwidthKbps, gcodec.minBitrate);
1408 EXPECT_EQ(kStartBandwidthKbps, gcodec.startBitrate);
1409 EXPECT_EQ(kMaxBandwidthKbps, gcodec.maxBitrate);
1410 EXPECT_NE(768U, gcodec.minBitrate);
1411 EXPECT_NE(768U, gcodec.startBitrate);
1412 EXPECT_NE(768U, gcodec.maxBitrate);
1413}
1414
1415// Test that sending screencast frames doesn't change bitrate.
1416TEST_F(WebRtcVideoEngineTestFake, SetBandwidthScreencast) {
1417 EXPECT_TRUE(SetupEngine());
1418 int channel_num = vie_.GetLastChannel();
1419
1420 // Set send codec.
1421 cricket::VideoCodec codec(kVP8Codec);
1422 std::vector<cricket::VideoCodec> codec_list;
1423 codec_list.push_back(codec);
1424 EXPECT_TRUE(channel_->AddSendStream(
1425 cricket::StreamParams::CreateLegacy(123)));
1426 EXPECT_TRUE(channel_->SetSendCodecs(codec_list));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001427 EXPECT_TRUE(channel_->SetMaxSendBandwidth(111000));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001428 EXPECT_TRUE(channel_->SetSend(true));
1429
1430 SendI420ScreencastFrame(kVP8Codec.width, kVP8Codec.height);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001431 VerifyVP8SendCodec(channel_num, kVP8Codec.width, kVP8Codec.height, 0, 111);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001432}
1433
1434
1435// Test SetSendSsrc.
1436TEST_F(WebRtcVideoEngineTestFake, SetSendSsrcAndCname) {
1437 EXPECT_TRUE(SetupEngine());
1438 int channel_num = vie_.GetLastChannel();
1439
1440 cricket::StreamParams stream;
1441 stream.ssrcs.push_back(1234);
1442 stream.cname = "cname";
1443 channel_->AddSendStream(stream);
1444
1445 unsigned int ssrc = 0;
1446 EXPECT_EQ(0, vie_.GetLocalSSRC(channel_num, ssrc));
1447 EXPECT_EQ(1234U, ssrc);
1448 EXPECT_EQ(1, vie_.GetNumSsrcs(channel_num));
1449
1450 char rtcp_cname[256];
1451 EXPECT_EQ(0, vie_.GetRTCPCName(channel_num, rtcp_cname));
1452 EXPECT_STREQ("cname", rtcp_cname);
1453}
1454
1455
1456// Test that the local SSRC is the same on sending and receiving channels if the
1457// receive channel is created before the send channel.
1458TEST_F(WebRtcVideoEngineTestFake, SetSendSsrcAfterCreatingReceiveChannel) {
1459 EXPECT_TRUE(SetupEngine());
1460
1461 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(1)));
1462 int receive_channel_num = vie_.GetLastChannel();
1463 cricket::StreamParams stream = cricket::StreamParams::CreateLegacy(1234);
1464 EXPECT_TRUE(channel_->AddSendStream(stream));
1465 int send_channel_num = vie_.GetLastChannel();
1466 unsigned int ssrc = 0;
1467 EXPECT_EQ(0, vie_.GetLocalSSRC(send_channel_num, ssrc));
1468 EXPECT_EQ(1234U, ssrc);
1469 EXPECT_EQ(1, vie_.GetNumSsrcs(send_channel_num));
1470 ssrc = 0;
1471 EXPECT_EQ(0, vie_.GetLocalSSRC(receive_channel_num, ssrc));
1472 EXPECT_EQ(1234U, ssrc);
1473 EXPECT_EQ(1, vie_.GetNumSsrcs(receive_channel_num));
1474}
1475
1476
1477// Test SetOptions with denoising flag.
1478TEST_F(WebRtcVideoEngineTestFake, SetOptionsWithDenoising) {
1479 EXPECT_TRUE(SetupEngine());
1480 EXPECT_EQ(1, vie_.GetNumCapturers());
1481 int channel_num = vie_.GetLastChannel();
1482 int capture_id = vie_.GetCaptureId(channel_num);
1483 // Set send codecs on the channel.
1484 std::vector<cricket::VideoCodec> codecs;
1485 codecs.push_back(kVP8Codec);
1486 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1487
1488 // Set options with OPT_VIDEO_NOISE_REDUCTION flag.
1489 cricket::VideoOptions options;
1490 options.video_noise_reduction.Set(true);
1491 EXPECT_TRUE(channel_->SetOptions(options));
1492
1493 // Verify capture has denoising turned on.
1494 webrtc::VideoCodec send_codec;
1495 memset(&send_codec, 0, sizeof(send_codec)); // avoid uninitialized warning
1496 EXPECT_EQ(0, vie_.GetSendCodec(channel_num, send_codec));
1497 EXPECT_TRUE(send_codec.codecSpecific.VP8.denoisingOn);
1498 EXPECT_FALSE(vie_.GetCaptureDenoising(capture_id));
1499
1500 // Set options back to zero.
1501 options.video_noise_reduction.Set(false);
1502 EXPECT_TRUE(channel_->SetOptions(options));
1503
1504 // Verify capture has denoising turned off.
1505 EXPECT_EQ(0, vie_.GetSendCodec(channel_num, send_codec));
1506 EXPECT_FALSE(send_codec.codecSpecific.VP8.denoisingOn);
1507 EXPECT_FALSE(vie_.GetCaptureDenoising(capture_id));
1508}
1509
wu@webrtc.orga8910d22014-01-23 22:12:45 +00001510TEST_F(WebRtcVideoEngineTestFake, MultipleSendStreamsWithOneCapturer) {
wu@webrtc.org24301a62013-12-13 19:17:43 +00001511 EXPECT_TRUE(SetupEngine());
1512
1513 // Start the capturer
1514 cricket::FakeVideoCapturer capturer;
1515 cricket::VideoFormat capture_format_vga = cricket::VideoFormat(640, 480,
1516 cricket::VideoFormat::FpsToInterval(30), cricket::FOURCC_I420);
1517 EXPECT_EQ(cricket::CS_RUNNING, capturer.Start(capture_format_vga));
1518
1519 // Add send streams and connect the capturer
1520 for (unsigned int i = 0; i < sizeof(kSsrcs2)/sizeof(kSsrcs2[0]); ++i) {
1521 EXPECT_TRUE(channel_->AddSendStream(
1522 cricket::StreamParams::CreateLegacy(kSsrcs2[i])));
1523 // Register the capturer to the ssrc.
1524 EXPECT_TRUE(channel_->SetCapturer(kSsrcs2[i], &capturer));
1525 }
1526
1527 const int channel0 = vie_.GetChannelFromLocalSsrc(kSsrcs2[0]);
1528 ASSERT_NE(-1, channel0);
1529 const int channel1 = vie_.GetChannelFromLocalSsrc(kSsrcs2[1]);
1530 ASSERT_NE(-1, channel1);
1531 ASSERT_NE(channel0, channel1);
1532
wu@webrtc.orgb9a088b2014-02-13 23:18:49 +00001533 // Both channels should have started receiving after created.
1534 EXPECT_TRUE(vie_.GetReceive(channel0));
1535 EXPECT_TRUE(vie_.GetReceive(channel1));
1536
wu@webrtc.org24301a62013-12-13 19:17:43 +00001537 // Set send codec.
1538 std::vector<cricket::VideoCodec> codecs;
1539 cricket::VideoCodec send_codec(100, "VP8", 640, 480, 30, 0);
1540 codecs.push_back(send_codec);
1541 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1542
wu@webrtc.orgb9a088b2014-02-13 23:18:49 +00001543 EXPECT_TRUE(channel_->SetSend(true));
1544 EXPECT_TRUE(vie_.GetSend(channel0));
1545 EXPECT_TRUE(vie_.GetSend(channel1));
1546
wu@webrtc.org24301a62013-12-13 19:17:43 +00001547 EXPECT_TRUE(capturer.CaptureFrame());
1548 EXPECT_EQ(1, vie_.GetIncomingFrameNum(channel0));
1549 EXPECT_EQ(1, vie_.GetIncomingFrameNum(channel1));
1550
1551 EXPECT_TRUE(channel_->RemoveSendStream(kSsrcs2[0]));
1552 EXPECT_TRUE(capturer.CaptureFrame());
1553 // channel0 is the default channel, so it won't be deleted.
1554 // But it should be disconnected from the capturer.
1555 EXPECT_EQ(1, vie_.GetIncomingFrameNum(channel0));
1556 EXPECT_EQ(2, vie_.GetIncomingFrameNum(channel1));
1557
1558 EXPECT_TRUE(channel_->RemoveSendStream(kSsrcs2[1]));
1559 EXPECT_TRUE(capturer.CaptureFrame());
1560 EXPECT_EQ(1, vie_.GetIncomingFrameNum(channel0));
1561 // channel1 has already been deleted.
1562 EXPECT_EQ(-1, vie_.GetIncomingFrameNum(channel1));
1563}
1564
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001565
buildbot@webrtc.orga18b4c92014-05-06 17:48:14 +00001566TEST_F(WebRtcVideoEngineTestFake, SendReceiveBitratesStats) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001567 EXPECT_TRUE(SetupEngine());
1568 cricket::VideoOptions options;
1569 options.conference_mode.Set(true);
1570 EXPECT_TRUE(channel_->SetOptions(options));
1571 EXPECT_TRUE(channel_->AddSendStream(
1572 cricket::StreamParams::CreateLegacy(1)));
buildbot@webrtc.orga18b4c92014-05-06 17:48:14 +00001573 int first_send_channel = vie_.GetLastChannel();
1574 EXPECT_TRUE(channel_->AddSendStream(
1575 cricket::StreamParams::CreateLegacy(2)));
1576 int second_send_channel = vie_.GetLastChannel();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001577 cricket::VideoCodec codec(kVP8Codec720p);
1578 std::vector<cricket::VideoCodec> codec_list;
1579 codec_list.push_back(codec);
1580 EXPECT_TRUE(channel_->SetSendCodecs(codec_list));
1581
1582 EXPECT_TRUE(channel_->AddRecvStream(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001583 cricket::StreamParams::CreateLegacy(3)));
buildbot@webrtc.orga18b4c92014-05-06 17:48:14 +00001584 int first_receive_channel = vie_.GetLastChannel();
1585 EXPECT_NE(first_send_channel, first_receive_channel);
1586 EXPECT_TRUE(channel_->AddRecvStream(
1587 cricket::StreamParams::CreateLegacy(4)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001588 int second_receive_channel = vie_.GetLastChannel();
1589 EXPECT_NE(first_receive_channel, second_receive_channel);
1590
1591 cricket::VideoMediaInfo info;
wu@webrtc.orgb9a088b2014-02-13 23:18:49 +00001592 EXPECT_TRUE(channel_->GetStats(cricket::StatsOptions(), &info));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001593 ASSERT_EQ(1U, info.bw_estimations.size());
1594 ASSERT_EQ(0, info.bw_estimations[0].actual_enc_bitrate);
1595 ASSERT_EQ(0, info.bw_estimations[0].transmit_bitrate);
1596 ASSERT_EQ(0, info.bw_estimations[0].retransmit_bitrate);
1597 ASSERT_EQ(0, info.bw_estimations[0].available_send_bandwidth);
1598 ASSERT_EQ(0, info.bw_estimations[0].available_recv_bandwidth);
1599 ASSERT_EQ(0, info.bw_estimations[0].target_enc_bitrate);
1600
1601 // Start sending and receiving on one of the channels and verify bitrates.
buildbot@webrtc.orga18b4c92014-05-06 17:48:14 +00001602 EXPECT_EQ(0, vie_.StartSend(first_send_channel));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001603 int send_video_bitrate = 800;
1604 int send_fec_bitrate = 100;
1605 int send_nack_bitrate = 20;
1606 int send_total_bitrate = send_video_bitrate + send_fec_bitrate +
1607 send_nack_bitrate;
buildbot@webrtc.orga18b4c92014-05-06 17:48:14 +00001608 int send_bandwidth = 1900;
1609 vie_.SetSendBitrates(first_send_channel, send_video_bitrate, send_fec_bitrate,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001610 send_nack_bitrate);
buildbot@webrtc.orga18b4c92014-05-06 17:48:14 +00001611 vie_.SetSendBandwidthEstimate(first_send_channel, send_bandwidth);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001612
1613 EXPECT_EQ(0, vie_.StartReceive(first_receive_channel));
buildbot@webrtc.orga18b4c92014-05-06 17:48:14 +00001614 int receive_bandwidth = 600;
1615 vie_.SetReceiveBandwidthEstimate(first_receive_channel, receive_bandwidth);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001616
1617 info.Clear();
wu@webrtc.orgb9a088b2014-02-13 23:18:49 +00001618 EXPECT_TRUE(channel_->GetStats(cricket::StatsOptions(), &info));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001619 ASSERT_EQ(1U, info.bw_estimations.size());
1620 ASSERT_EQ(send_video_bitrate, info.bw_estimations[0].actual_enc_bitrate);
1621 ASSERT_EQ(send_total_bitrate, info.bw_estimations[0].transmit_bitrate);
1622 ASSERT_EQ(send_nack_bitrate, info.bw_estimations[0].retransmit_bitrate);
1623 ASSERT_EQ(send_bandwidth, info.bw_estimations[0].available_send_bandwidth);
buildbot@webrtc.orga18b4c92014-05-06 17:48:14 +00001624 ASSERT_EQ(receive_bandwidth, info.bw_estimations[0].available_recv_bandwidth);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001625 ASSERT_EQ(send_video_bitrate, info.bw_estimations[0].target_enc_bitrate);
1626
1627 // Start receiving on the second channel and verify received rate.
buildbot@webrtc.orga18b4c92014-05-06 17:48:14 +00001628 EXPECT_EQ(0, vie_.StartSend(second_send_channel));
1629 vie_.SetSendBitrates(second_send_channel,
1630 send_video_bitrate,
1631 send_fec_bitrate,
1632 send_nack_bitrate);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001633 EXPECT_EQ(0, vie_.StartReceive(second_receive_channel));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001634
1635 info.Clear();
wu@webrtc.orgb9a088b2014-02-13 23:18:49 +00001636 EXPECT_TRUE(channel_->GetStats(cricket::StatsOptions(), &info));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001637 ASSERT_EQ(1U, info.bw_estimations.size());
buildbot@webrtc.orga18b4c92014-05-06 17:48:14 +00001638 ASSERT_EQ(2 * send_video_bitrate, info.bw_estimations[0].actual_enc_bitrate);
1639 ASSERT_EQ(2 * send_total_bitrate, info.bw_estimations[0].transmit_bitrate);
1640 ASSERT_EQ(2 * send_nack_bitrate, info.bw_estimations[0].retransmit_bitrate);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001641 ASSERT_EQ(send_bandwidth, info.bw_estimations[0].available_send_bandwidth);
buildbot@webrtc.orga18b4c92014-05-06 17:48:14 +00001642 ASSERT_EQ(receive_bandwidth, info.bw_estimations[0].available_recv_bandwidth);
1643 ASSERT_EQ(2 * send_video_bitrate, info.bw_estimations[0].target_enc_bitrate);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001644}
1645
1646TEST_F(WebRtcVideoEngineTestFake, TestSetAdaptInputToCpuUsage) {
1647 EXPECT_TRUE(SetupEngine());
1648 cricket::VideoOptions options_in, options_out;
1649 bool cpu_adapt = false;
1650 channel_->SetOptions(options_in);
1651 EXPECT_TRUE(channel_->GetOptions(&options_out));
1652 EXPECT_FALSE(options_out.adapt_input_to_cpu_usage.Get(&cpu_adapt));
1653 // Set adapt input CPU usage option.
1654 options_in.adapt_input_to_cpu_usage.Set(true);
1655 EXPECT_TRUE(channel_->SetOptions(options_in));
1656 EXPECT_TRUE(channel_->GetOptions(&options_out));
1657 EXPECT_TRUE(options_out.adapt_input_to_cpu_usage.Get(&cpu_adapt));
1658 EXPECT_TRUE(cpu_adapt);
1659}
1660
1661TEST_F(WebRtcVideoEngineTestFake, TestSetCpuThreshold) {
1662 EXPECT_TRUE(SetupEngine());
1663 float low, high;
1664 cricket::VideoOptions options_in, options_out;
1665 // Verify that initial values are set.
1666 EXPECT_TRUE(channel_->GetOptions(&options_out));
1667 EXPECT_TRUE(options_out.system_low_adaptation_threshhold.Get(&low));
1668 EXPECT_EQ(low, 0.65f);
1669 EXPECT_TRUE(options_out.system_high_adaptation_threshhold.Get(&high));
1670 EXPECT_EQ(high, 0.85f);
1671 // Set new CPU threshold values.
1672 options_in.system_low_adaptation_threshhold.Set(0.45f);
1673 options_in.system_high_adaptation_threshhold.Set(0.95f);
1674 EXPECT_TRUE(channel_->SetOptions(options_in));
1675 EXPECT_TRUE(channel_->GetOptions(&options_out));
1676 EXPECT_TRUE(options_out.system_low_adaptation_threshhold.Get(&low));
1677 EXPECT_EQ(low, 0.45f);
1678 EXPECT_TRUE(options_out.system_high_adaptation_threshhold.Get(&high));
1679 EXPECT_EQ(high, 0.95f);
1680}
1681
1682TEST_F(WebRtcVideoEngineTestFake, TestSetInvalidCpuThreshold) {
1683 EXPECT_TRUE(SetupEngine());
1684 float low, high;
1685 cricket::VideoOptions options_in, options_out;
1686 // Valid range is [0, 1].
1687 options_in.system_low_adaptation_threshhold.Set(-1.5f);
1688 options_in.system_high_adaptation_threshhold.Set(1.5f);
1689 EXPECT_TRUE(channel_->SetOptions(options_in));
1690 EXPECT_TRUE(channel_->GetOptions(&options_out));
1691 EXPECT_TRUE(options_out.system_low_adaptation_threshhold.Get(&low));
1692 EXPECT_EQ(low, 0.0f);
1693 EXPECT_TRUE(options_out.system_high_adaptation_threshhold.Get(&high));
1694 EXPECT_EQ(high, 1.0f);
1695}
1696
1697
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +00001698TEST_F(WebRtcVideoEngineTestFake, ResetCodecOnScreencast) {
1699 EXPECT_TRUE(SetupEngine());
1700 cricket::VideoOptions options;
1701 options.video_noise_reduction.Set(true);
1702 EXPECT_TRUE(channel_->SetOptions(options));
1703
1704 // Set send codec.
1705 cricket::VideoCodec codec(kVP8Codec);
1706 std::vector<cricket::VideoCodec> codec_list;
1707 codec_list.push_back(codec);
1708 EXPECT_TRUE(channel_->AddSendStream(
1709 cricket::StreamParams::CreateLegacy(123)));
1710 EXPECT_TRUE(channel_->SetSendCodecs(codec_list));
1711 EXPECT_TRUE(channel_->SetSend(true));
wu@webrtc.org05e7b442014-04-01 17:44:24 +00001712 EXPECT_EQ(1, vie_.GetNumSetSendCodecs());
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +00001713
1714 webrtc::VideoCodec gcodec;
1715 memset(&gcodec, 0, sizeof(gcodec));
1716 int channel_num = vie_.GetLastChannel();
1717 EXPECT_EQ(0, vie_.GetSendCodec(channel_num, gcodec));
1718 EXPECT_TRUE(gcodec.codecSpecific.VP8.denoisingOn);
1719
1720 // Send a screencast frame with the same size.
1721 // Verify that denoising is turned off.
1722 SendI420ScreencastFrame(kVP8Codec.width, kVP8Codec.height);
wu@webrtc.org05e7b442014-04-01 17:44:24 +00001723 EXPECT_EQ(2, vie_.GetNumSetSendCodecs());
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +00001724 EXPECT_EQ(0, vie_.GetSendCodec(channel_num, gcodec));
1725 EXPECT_FALSE(gcodec.codecSpecific.VP8.denoisingOn);
1726}
1727
1728
1729TEST_F(WebRtcVideoEngineTestFake, DontRegisterDecoderIfFactoryIsNotGiven) {
1730 engine_.SetExternalDecoderFactory(NULL);
1731 EXPECT_TRUE(SetupEngine());
1732 int channel_num = vie_.GetLastChannel();
1733
1734 std::vector<cricket::VideoCodec> codecs;
1735 codecs.push_back(kVP8Codec);
1736 EXPECT_TRUE(channel_->SetRecvCodecs(codecs));
1737
1738 EXPECT_EQ(0, vie_.GetNumExternalDecoderRegistered(channel_num));
1739}
1740
1741TEST_F(WebRtcVideoEngineTestFake, RegisterDecoderIfFactoryIsGiven) {
1742 decoder_factory_.AddSupportedVideoCodecType(webrtc::kVideoCodecVP8);
1743 engine_.SetExternalDecoderFactory(&decoder_factory_);
1744 EXPECT_TRUE(SetupEngine());
1745 int channel_num = vie_.GetLastChannel();
1746
1747 std::vector<cricket::VideoCodec> codecs;
1748 codecs.push_back(kVP8Codec);
1749 EXPECT_TRUE(channel_->SetRecvCodecs(codecs));
1750
1751 EXPECT_TRUE(vie_.ExternalDecoderRegistered(channel_num, 100));
1752 EXPECT_EQ(1, vie_.GetNumExternalDecoderRegistered(channel_num));
1753}
1754
1755TEST_F(WebRtcVideoEngineTestFake, DontRegisterDecoderMultipleTimes) {
1756 decoder_factory_.AddSupportedVideoCodecType(webrtc::kVideoCodecVP8);
1757 engine_.SetExternalDecoderFactory(&decoder_factory_);
1758 EXPECT_TRUE(SetupEngine());
1759 int channel_num = vie_.GetLastChannel();
1760
1761 std::vector<cricket::VideoCodec> codecs;
1762 codecs.push_back(kVP8Codec);
1763 EXPECT_TRUE(channel_->SetRecvCodecs(codecs));
1764
1765 EXPECT_TRUE(vie_.ExternalDecoderRegistered(channel_num, 100));
1766 EXPECT_EQ(1, vie_.GetNumExternalDecoderRegistered(channel_num));
1767 EXPECT_EQ(1, decoder_factory_.GetNumCreatedDecoders());
1768
1769 EXPECT_TRUE(channel_->SetRecvCodecs(codecs));
1770 EXPECT_EQ(1, vie_.GetNumExternalDecoderRegistered(channel_num));
1771 EXPECT_EQ(1, decoder_factory_.GetNumCreatedDecoders());
1772}
1773
1774TEST_F(WebRtcVideoEngineTestFake, DontRegisterDecoderForNonVP8) {
1775 decoder_factory_.AddSupportedVideoCodecType(webrtc::kVideoCodecVP8);
1776 engine_.SetExternalDecoderFactory(&decoder_factory_);
1777 EXPECT_TRUE(SetupEngine());
1778 int channel_num = vie_.GetLastChannel();
1779
1780 std::vector<cricket::VideoCodec> codecs;
1781 codecs.push_back(kRedCodec);
1782 EXPECT_TRUE(channel_->SetRecvCodecs(codecs));
1783
1784 EXPECT_EQ(0, vie_.GetNumExternalDecoderRegistered(channel_num));
1785}
1786
1787TEST_F(WebRtcVideoEngineTestFake, DontRegisterEncoderIfFactoryIsNotGiven) {
1788 engine_.SetExternalEncoderFactory(NULL);
1789 EXPECT_TRUE(SetupEngine());
1790 int channel_num = vie_.GetLastChannel();
1791
1792 std::vector<cricket::VideoCodec> codecs;
1793 codecs.push_back(kVP8Codec);
1794 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1795
1796 EXPECT_EQ(0, vie_.GetNumExternalEncoderRegistered(channel_num));
1797}
1798
1799TEST_F(WebRtcVideoEngineTestFake, RegisterEncoderIfFactoryIsGiven) {
1800 encoder_factory_.AddSupportedVideoCodecType(webrtc::kVideoCodecVP8, "VP8");
1801 engine_.SetExternalEncoderFactory(&encoder_factory_);
1802 EXPECT_TRUE(SetupEngine());
1803 int channel_num = vie_.GetLastChannel();
1804
1805 std::vector<cricket::VideoCodec> codecs;
1806 codecs.push_back(kVP8Codec);
1807 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1808
1809 EXPECT_TRUE(channel_->AddSendStream(
1810 cricket::StreamParams::CreateLegacy(kSsrc)));
1811
1812 EXPECT_TRUE(vie_.ExternalEncoderRegistered(channel_num, 100));
1813 EXPECT_EQ(1, vie_.GetNumExternalEncoderRegistered(channel_num));
1814
1815 // Remove stream previously added to free the external encoder instance.
1816 EXPECT_TRUE(channel_->RemoveSendStream(kSsrc));
1817}
1818
1819TEST_F(WebRtcVideoEngineTestFake, DontRegisterEncoderMultipleTimes) {
1820 encoder_factory_.AddSupportedVideoCodecType(webrtc::kVideoCodecVP8, "VP8");
1821 engine_.SetExternalEncoderFactory(&encoder_factory_);
1822 EXPECT_TRUE(SetupEngine());
1823 int channel_num = vie_.GetLastChannel();
1824
1825 std::vector<cricket::VideoCodec> codecs;
1826 codecs.push_back(kVP8Codec);
1827 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1828
1829 EXPECT_TRUE(channel_->AddSendStream(
1830 cricket::StreamParams::CreateLegacy(kSsrc)));
1831
1832 EXPECT_TRUE(vie_.ExternalEncoderRegistered(channel_num, 100));
1833 EXPECT_EQ(1, vie_.GetNumExternalEncoderRegistered(channel_num));
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +00001834
1835 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1836 EXPECT_EQ(1, vie_.GetNumExternalEncoderRegistered(channel_num));
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +00001837
1838 // Remove stream previously added to free the external encoder instance.
1839 EXPECT_TRUE(channel_->RemoveSendStream(kSsrc));
1840}
1841
1842TEST_F(WebRtcVideoEngineTestFake, RegisterEncoderWithMultipleSendStreams) {
1843 encoder_factory_.AddSupportedVideoCodecType(webrtc::kVideoCodecVP8, "VP8");
1844 engine_.SetExternalEncoderFactory(&encoder_factory_);
1845 EXPECT_TRUE(SetupEngine());
1846
1847 std::vector<cricket::VideoCodec> codecs;
1848 codecs.push_back(kVP8Codec);
1849 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1850 EXPECT_EQ(1, vie_.GetTotalNumExternalEncoderRegistered());
1851
1852 // When we add the first stream (1234), it reuses the default send channel,
1853 // so it doesn't increase the registration count of external encoders.
1854 EXPECT_TRUE(channel_->AddSendStream(
1855 cricket::StreamParams::CreateLegacy(1234)));
1856 EXPECT_EQ(1, vie_.GetTotalNumExternalEncoderRegistered());
1857
1858 // When we add the second stream (2345), it creates a new channel and
1859 // increments the registration count.
1860 EXPECT_TRUE(channel_->AddSendStream(
1861 cricket::StreamParams::CreateLegacy(2345)));
1862 EXPECT_EQ(2, vie_.GetTotalNumExternalEncoderRegistered());
1863
1864 // At this moment the total registration count is two, but only one encoder
1865 // is registered per channel.
1866 int channel_num = vie_.GetLastChannel();
1867 EXPECT_EQ(1, vie_.GetNumExternalEncoderRegistered(channel_num));
1868
1869 // Removing send streams decrements the registration count.
1870 EXPECT_TRUE(channel_->RemoveSendStream(1234));
1871 EXPECT_EQ(1, vie_.GetTotalNumExternalEncoderRegistered());
1872
1873 // When we remove the last send stream, it also destroys the last send
1874 // channel and causes the registration count to drop to zero. It is a little
1875 // weird, but not a bug.
1876 EXPECT_TRUE(channel_->RemoveSendStream(2345));
1877 EXPECT_EQ(0, vie_.GetTotalNumExternalEncoderRegistered());
1878}
1879
1880TEST_F(WebRtcVideoEngineTestFake, DontRegisterEncoderForNonVP8) {
1881 encoder_factory_.AddSupportedVideoCodecType(webrtc::kVideoCodecGeneric,
1882 "GENERIC");
1883 engine_.SetExternalEncoderFactory(&encoder_factory_);
1884 EXPECT_TRUE(SetupEngine());
1885 int channel_num = vie_.GetLastChannel();
1886
1887 // Note: unlike the SetRecvCodecs, we must set a valid video codec for
1888 // channel_->SetSendCodecs() to succeed.
1889 std::vector<cricket::VideoCodec> codecs;
1890 codecs.push_back(kVP8Codec);
1891 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1892
1893 EXPECT_EQ(0, vie_.GetNumExternalEncoderRegistered(channel_num));
1894}
1895
1896// Test that NACK, PLI and REMB are enabled for external codec.
1897TEST_F(WebRtcVideoEngineTestFake, ExternalCodecFeedbackParams) {
1898 encoder_factory_.AddSupportedVideoCodecType(webrtc::kVideoCodecGeneric,
1899 "GENERIC");
1900 engine_.SetExternalEncoderFactory(&encoder_factory_);
1901 encoder_factory_.NotifyCodecsAvailable();
1902 EXPECT_TRUE(SetupEngine());
1903
1904 std::vector<cricket::VideoCodec> codecs(engine_.codecs());
1905 // The external codec will appear at last.
1906 size_t pos = codecs.size() - 1;
1907 EXPECT_EQ("GENERIC", codecs[pos].name);
1908 VerifyCodecFeedbackParams(codecs[pos]);
1909}
1910
1911// Test external codec with be added to the end of the supported codec list.
1912TEST_F(WebRtcVideoEngineTestFake, ExternalCodecAddedToTheEnd) {
1913 EXPECT_TRUE(SetupEngine());
1914
1915 std::vector<cricket::VideoCodec> codecs(engine_.codecs());
1916 EXPECT_EQ("VP8", codecs[0].name);
1917
1918 encoder_factory_.AddSupportedVideoCodecType(webrtc::kVideoCodecGeneric,
1919 "GENERIC");
1920 engine_.SetExternalEncoderFactory(&encoder_factory_);
1921 encoder_factory_.NotifyCodecsAvailable();
1922
1923 codecs = engine_.codecs();
1924 cricket::VideoCodec internal_codec = codecs[0];
1925 cricket::VideoCodec external_codec = codecs[codecs.size() - 1];
1926 // The external codec will appear at last.
1927 EXPECT_EQ("GENERIC", external_codec.name);
1928 // The internal codec is preferred.
1929 EXPECT_GE(internal_codec.preference, external_codec.preference);
1930}
1931
1932// Test that external codec with be ignored if it has the same name as one of
1933// the internal codecs.
1934TEST_F(WebRtcVideoEngineTestFake, ExternalCodecIgnored) {
1935 EXPECT_TRUE(SetupEngine());
1936
1937 std::vector<cricket::VideoCodec> internal_codecs(engine_.codecs());
1938 EXPECT_EQ("VP8", internal_codecs[0].name);
1939
1940 encoder_factory_.AddSupportedVideoCodecType(webrtc::kVideoCodecVP8, "VP8");
1941 engine_.SetExternalEncoderFactory(&encoder_factory_);
1942 encoder_factory_.NotifyCodecsAvailable();
1943
1944 std::vector<cricket::VideoCodec> codecs = engine_.codecs();
1945 EXPECT_EQ("VP8", codecs[0].name);
1946 EXPECT_EQ(internal_codecs[0].height, codecs[0].height);
1947 EXPECT_EQ(internal_codecs[0].width, codecs[0].width);
1948 // Verify the last codec is not the external codec.
1949 EXPECT_NE("VP8", codecs[codecs.size() - 1].name);
1950}
1951
1952TEST_F(WebRtcVideoEngineTestFake, UpdateEncoderCodecsAfterSetFactory) {
1953 engine_.SetExternalEncoderFactory(&encoder_factory_);
1954 EXPECT_TRUE(SetupEngine());
1955 int channel_num = vie_.GetLastChannel();
1956
1957 encoder_factory_.AddSupportedVideoCodecType(webrtc::kVideoCodecVP8, "VP8");
1958 encoder_factory_.NotifyCodecsAvailable();
1959 std::vector<cricket::VideoCodec> codecs;
1960 codecs.push_back(kVP8Codec);
1961 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
1962
1963 EXPECT_TRUE(channel_->AddSendStream(
1964 cricket::StreamParams::CreateLegacy(kSsrc)));
1965
1966 EXPECT_TRUE(vie_.ExternalEncoderRegistered(channel_num, 100));
1967 EXPECT_EQ(1, vie_.GetNumExternalEncoderRegistered(channel_num));
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +00001968
1969 // Remove stream previously added to free the external encoder instance.
1970 EXPECT_TRUE(channel_->RemoveSendStream(kSsrc));
1971}
1972
1973// Tests that OnReadyToSend will be propagated into ViE.
1974TEST_F(WebRtcVideoEngineTestFake, OnReadyToSend) {
1975 EXPECT_TRUE(SetupEngine());
1976 int channel_num = vie_.GetLastChannel();
1977 EXPECT_TRUE(vie_.GetIsTransmitting(channel_num));
1978
1979 channel_->OnReadyToSend(false);
1980 EXPECT_FALSE(vie_.GetIsTransmitting(channel_num));
1981
1982 channel_->OnReadyToSend(true);
1983 EXPECT_TRUE(vie_.GetIsTransmitting(channel_num));
1984}
1985
1986#if 0
1987TEST_F(WebRtcVideoEngineTestFake, CaptureFrameTimestampToNtpTimestamp) {
1988 EXPECT_TRUE(SetupEngine());
1989 int capture_id = vie_.GetCaptureId(vie_.GetLastChannel());
1990
1991 // Set send codec.
1992 cricket::VideoCodec codec(kVP8Codec);
1993 std::vector<cricket::VideoCodec> codec_list;
1994 codec_list.push_back(codec);
1995 EXPECT_TRUE(channel_->AddSendStream(
1996 cricket::StreamParams::CreateLegacy(123)));
1997 EXPECT_TRUE(channel_->SetSendCodecs(codec_list));
1998 EXPECT_TRUE(channel_->SetSend(true));
1999
2000 int64 timestamp = time(NULL) * talk_base::kNumNanosecsPerSec;
2001 SendI420ScreencastFrameWithTimestamp(
2002 kVP8Codec.width, kVP8Codec.height, timestamp);
2003 EXPECT_EQ(talk_base::UnixTimestampNanosecsToNtpMillisecs(timestamp),
2004 vie_.GetCaptureLastTimestamp(capture_id));
2005
2006 SendI420ScreencastFrameWithTimestamp(kVP8Codec.width, kVP8Codec.height, 0);
2007 EXPECT_EQ(0, vie_.GetCaptureLastTimestamp(capture_id));
2008}
2009#endif
2010
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002011/////////////////////////
2012// Tests with real ViE //
2013/////////////////////////
2014
2015// Tests that we can find codecs by name or id.
2016TEST_F(WebRtcVideoEngineTest, FindCodec) {
2017 // We should not need to init engine in order to get codecs.
2018 const std::vector<cricket::VideoCodec>& c = engine_.codecs();
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +00002019 EXPECT_EQ(4U, c.size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002020
2021 cricket::VideoCodec vp8(104, "VP8", 320, 200, 30, 0);
2022 EXPECT_TRUE(engine_.FindCodec(vp8));
2023
2024 cricket::VideoCodec vp8_ci(104, "vp8", 320, 200, 30, 0);
2025 EXPECT_TRUE(engine_.FindCodec(vp8));
2026
2027 cricket::VideoCodec vp8_diff_fr_diff_pref(104, "VP8", 320, 200, 50, 50);
2028 EXPECT_TRUE(engine_.FindCodec(vp8_diff_fr_diff_pref));
2029
2030 cricket::VideoCodec vp8_diff_id(95, "VP8", 320, 200, 30, 0);
2031 EXPECT_FALSE(engine_.FindCodec(vp8_diff_id));
2032 vp8_diff_id.id = 97;
2033 EXPECT_TRUE(engine_.FindCodec(vp8_diff_id));
2034
2035 cricket::VideoCodec vp8_diff_res(104, "VP8", 320, 111, 30, 0);
2036 EXPECT_FALSE(engine_.FindCodec(vp8_diff_res));
2037
2038 // PeerConnection doesn't negotiate the resolution at this point.
2039 // Test that FindCodec can handle the case when width/height is 0.
2040 cricket::VideoCodec vp8_zero_res(104, "VP8", 0, 0, 30, 0);
2041 EXPECT_TRUE(engine_.FindCodec(vp8_zero_res));
2042
2043 cricket::VideoCodec red(101, "RED", 0, 0, 30, 0);
2044 EXPECT_TRUE(engine_.FindCodec(red));
2045
2046 cricket::VideoCodec red_ci(101, "red", 0, 0, 30, 0);
2047 EXPECT_TRUE(engine_.FindCodec(red));
2048
2049 cricket::VideoCodec fec(102, "ULPFEC", 0, 0, 30, 0);
2050 EXPECT_TRUE(engine_.FindCodec(fec));
2051
2052 cricket::VideoCodec fec_ci(102, "ulpfec", 0, 0, 30, 0);
2053 EXPECT_TRUE(engine_.FindCodec(fec));
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +00002054
2055 cricket::VideoCodec rtx(96, "rtx", 0, 0, 30, 0);
2056 EXPECT_TRUE(engine_.FindCodec(rtx));
2057}
2058
2059TEST_F(WebRtcVideoEngineTest, RtxCodecHasAptSet) {
2060 std::vector<cricket::VideoCodec>::const_iterator it;
2061 bool apt_checked = false;
2062 for (it = engine_.codecs().begin(); it != engine_.codecs().end(); ++it) {
2063 if (_stricmp(cricket::kRtxCodecName, it->name.c_str()) && it->id != 96) {
2064 continue;
2065 }
2066 int apt;
2067 EXPECT_TRUE(it->GetParam("apt", &apt));
2068 EXPECT_EQ(100, apt);
2069 apt_checked = true;
2070 }
2071 EXPECT_TRUE(apt_checked);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002072}
2073
2074TEST_F(WebRtcVideoEngineTest, StartupShutdown) {
2075 EXPECT_TRUE(engine_.Init(talk_base::Thread::Current()));
2076 engine_.Terminate();
2077}
2078
2079TEST_PRE_VIDEOENGINE_INIT(WebRtcVideoEngineTest, ConstrainNewCodec)
2080TEST_POST_VIDEOENGINE_INIT(WebRtcVideoEngineTest, ConstrainNewCodec)
2081
2082TEST_PRE_VIDEOENGINE_INIT(WebRtcVideoEngineTest, ConstrainRunningCodec)
2083TEST_POST_VIDEOENGINE_INIT(WebRtcVideoEngineTest, ConstrainRunningCodec)
2084
2085// TODO(juberti): Figure out why ViE is munging the COM refcount.
2086#ifdef WIN32
2087TEST_F(WebRtcVideoEngineTest, DISABLED_CheckCoInitialize) {
2088 Base::CheckCoInitialize();
2089}
2090#endif
2091
2092TEST_F(WebRtcVideoEngineTest, CreateChannel) {
2093 EXPECT_TRUE(engine_.Init(talk_base::Thread::Current()));
2094 cricket::VideoMediaChannel* channel = engine_.CreateChannel(NULL);
2095 EXPECT_TRUE(channel != NULL);
2096 delete channel;
2097}
2098
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002099TEST_F(WebRtcVideoMediaChannelTest, SetRecvCodecs) {
2100 std::vector<cricket::VideoCodec> codecs;
2101 codecs.push_back(kVP8Codec);
2102 EXPECT_TRUE(channel_->SetRecvCodecs(codecs));
2103}
2104TEST_F(WebRtcVideoMediaChannelTest, SetRecvCodecsWrongPayloadType) {
2105 std::vector<cricket::VideoCodec> codecs;
2106 codecs.push_back(kVP8Codec);
2107 codecs[0].id = 99;
2108 EXPECT_TRUE(channel_->SetRecvCodecs(codecs));
2109}
2110TEST_F(WebRtcVideoMediaChannelTest, SetRecvCodecsUnsupportedCodec) {
2111 std::vector<cricket::VideoCodec> codecs;
2112 codecs.push_back(kVP8Codec);
2113 codecs.push_back(cricket::VideoCodec(101, "VP1", 640, 400, 30, 0));
2114 EXPECT_FALSE(channel_->SetRecvCodecs(codecs));
2115}
2116
mallinath@webrtc.org92fdfeb2014-02-17 18:49:41 +00002117TEST_F(WebRtcVideoMediaChannelTest, GetRtpSendTimeExtension) {
2118 // Enable RTP timestamp extension.
2119 const int id = 12;
2120 std::vector<cricket::RtpHeaderExtension> extensions;
2121 extensions.push_back(cricket::RtpHeaderExtension(
2122 "http://www.webrtc.org/experiments/rtp-hdrext/abs-send-time", id));
2123
2124 // Verify the send extension id.
2125 EXPECT_TRUE(channel_->SetSendRtpHeaderExtensions(extensions));
2126 EXPECT_EQ(id, channel_->GetRtpSendTimeExtnId());
2127}
2128
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002129TEST_F(WebRtcVideoMediaChannelTest, SetSend) {
2130 Base::SetSend();
2131}
2132TEST_F(WebRtcVideoMediaChannelTest, SetSendWithoutCodecs) {
2133 Base::SetSendWithoutCodecs();
2134}
2135TEST_F(WebRtcVideoMediaChannelTest, SetSendSetsTransportBufferSizes) {
2136 Base::SetSendSetsTransportBufferSizes();
2137}
2138
2139TEST_F(WebRtcVideoMediaChannelTest, SendAndReceiveVp8Vga) {
2140 SendAndReceive(cricket::VideoCodec(100, "VP8", 640, 400, 30, 0));
2141}
2142TEST_F(WebRtcVideoMediaChannelTest, SendAndReceiveVp8Qvga) {
2143 SendAndReceive(cricket::VideoCodec(100, "VP8", 320, 200, 30, 0));
2144}
2145TEST_F(WebRtcVideoMediaChannelTest, SendAndReceiveH264SvcQqvga) {
2146 SendAndReceive(cricket::VideoCodec(100, "VP8", 160, 100, 30, 0));
2147}
2148TEST_F(WebRtcVideoMediaChannelTest, SendManyResizeOnce) {
2149 SendManyResizeOnce();
2150}
2151
2152TEST_F(WebRtcVideoMediaChannelTest, SendVp8HdAndReceiveAdaptedVp8Vga) {
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00002153 EXPECT_TRUE(channel_->SetCapturer(kSsrc, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002154 channel_->UpdateAspectRatio(1280, 720);
2155 video_capturer_.reset(new cricket::FakeVideoCapturer);
2156 const std::vector<cricket::VideoFormat>* formats =
2157 video_capturer_->GetSupportedFormats();
2158 cricket::VideoFormat capture_format_hd = (*formats)[0];
2159 EXPECT_EQ(cricket::CS_RUNNING, video_capturer_->Start(capture_format_hd));
2160 EXPECT_TRUE(channel_->SetCapturer(kSsrc, video_capturer_.get()));
2161
2162 // Capture format HD -> adapt (OnOutputFormatRequest VGA) -> VGA.
2163 cricket::VideoCodec codec(100, "VP8", 1280, 720, 30, 0);
2164 EXPECT_TRUE(SetOneCodec(codec));
2165 codec.width /= 2;
2166 codec.height /= 2;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002167 EXPECT_TRUE(SetSend(true));
2168 EXPECT_TRUE(channel_->SetRender(true));
2169 EXPECT_EQ(0, renderer_.num_rendered_frames());
2170 EXPECT_TRUE(SendFrame());
2171 EXPECT_FRAME_WAIT(1, codec.width, codec.height, kTimeout);
2172}
2173
2174// TODO(juberti): Fix this test to tolerate missing stats.
2175TEST_F(WebRtcVideoMediaChannelTest, DISABLED_GetStats) {
2176 Base::GetStats();
2177}
2178
2179// TODO(juberti): Fix this test to tolerate missing stats.
2180TEST_F(WebRtcVideoMediaChannelTest, DISABLED_GetStatsMultipleRecvStreams) {
2181 Base::GetStatsMultipleRecvStreams();
2182}
2183
2184TEST_F(WebRtcVideoMediaChannelTest, GetStatsMultipleSendStreams) {
2185 Base::GetStatsMultipleSendStreams();
2186}
2187
2188TEST_F(WebRtcVideoMediaChannelTest, SetSendBandwidth) {
2189 Base::SetSendBandwidth();
2190}
2191TEST_F(WebRtcVideoMediaChannelTest, SetSendSsrc) {
2192 Base::SetSendSsrc();
2193}
2194TEST_F(WebRtcVideoMediaChannelTest, SetSendSsrcAfterSetCodecs) {
2195 Base::SetSendSsrcAfterSetCodecs();
2196}
2197
2198TEST_F(WebRtcVideoMediaChannelTest, SetRenderer) {
2199 Base::SetRenderer();
2200}
2201
2202TEST_F(WebRtcVideoMediaChannelTest, AddRemoveRecvStreams) {
2203 Base::AddRemoveRecvStreams();
2204}
2205
2206TEST_F(WebRtcVideoMediaChannelTest, AddRemoveRecvStreamAndRender) {
2207 Base::AddRemoveRecvStreamAndRender();
2208}
2209
2210TEST_F(WebRtcVideoMediaChannelTest, AddRemoveRecvStreamsNoConference) {
2211 Base::AddRemoveRecvStreamsNoConference();
2212}
2213
2214TEST_F(WebRtcVideoMediaChannelTest, AddRemoveSendStreams) {
2215 Base::AddRemoveSendStreams();
2216}
2217
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002218TEST_F(WebRtcVideoMediaChannelTest, SimulateConference) {
2219 Base::SimulateConference();
2220}
2221
2222TEST_F(WebRtcVideoMediaChannelTest, AddRemoveCapturer) {
2223 Base::AddRemoveCapturer();
2224}
2225
2226TEST_F(WebRtcVideoMediaChannelTest, RemoveCapturerWithoutAdd) {
2227 Base::RemoveCapturerWithoutAdd();
2228}
2229
2230TEST_F(WebRtcVideoMediaChannelTest, AddRemoveCapturerMultipleSources) {
2231 Base::AddRemoveCapturerMultipleSources();
2232}
2233
wu@webrtc.orgde305012013-10-31 15:40:38 +00002234// This test verifies DSCP settings are properly applied on video media channel.
2235TEST_F(WebRtcVideoMediaChannelTest, TestSetDscpOptions) {
2236 talk_base::scoped_ptr<cricket::FakeNetworkInterface> network_interface(
2237 new cricket::FakeNetworkInterface);
2238 channel_->SetInterface(network_interface.get());
2239 cricket::VideoOptions options;
2240 options.dscp.Set(true);
2241 EXPECT_TRUE(channel_->SetOptions(options));
2242 EXPECT_EQ(talk_base::DSCP_AF41, network_interface->dscp());
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +00002243 // Verify previous value is not modified if dscp option is not set.
2244 cricket::VideoOptions options1;
2245 EXPECT_TRUE(channel_->SetOptions(options1));
2246 EXPECT_EQ(talk_base::DSCP_AF41, network_interface->dscp());
wu@webrtc.orgde305012013-10-31 15:40:38 +00002247 options.dscp.Set(false);
2248 EXPECT_TRUE(channel_->SetOptions(options));
2249 EXPECT_EQ(talk_base::DSCP_DEFAULT, network_interface->dscp());
2250 channel_->SetInterface(NULL);
2251}
2252
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002253
2254TEST_F(WebRtcVideoMediaChannelTest, SetOptionsSucceedsWhenSending) {
2255 cricket::VideoOptions options;
2256 options.conference_mode.Set(true);
2257 EXPECT_TRUE(channel_->SetOptions(options));
2258
2259 // Verify SetOptions returns true on a different options.
2260 cricket::VideoOptions options2;
2261 options2.adapt_input_to_cpu_usage.Set(true);
2262 EXPECT_TRUE(channel_->SetOptions(options2));
2263
2264 // Set send codecs on the channel and start sending.
2265 std::vector<cricket::VideoCodec> codecs;
2266 codecs.push_back(kVP8Codec);
2267 EXPECT_TRUE(channel_->SetSendCodecs(codecs));
2268 EXPECT_TRUE(channel_->SetSend(true));
2269
2270 // Verify SetOptions returns true if channel is already sending.
2271 cricket::VideoOptions options3;
2272 options3.conference_mode.Set(true);
2273 EXPECT_TRUE(channel_->SetOptions(options3));
2274}
2275
2276// Tests empty StreamParams is rejected.
2277TEST_F(WebRtcVideoMediaChannelTest, RejectEmptyStreamParams) {
2278 Base::RejectEmptyStreamParams();
2279}
2280
2281
2282TEST_F(WebRtcVideoMediaChannelTest, AdaptResolution16x10) {
2283 Base::AdaptResolution16x10();
2284}
2285
2286TEST_F(WebRtcVideoMediaChannelTest, AdaptResolution4x3) {
2287 Base::AdaptResolution4x3();
2288}
2289
2290TEST_F(WebRtcVideoMediaChannelTest, MuteStream) {
2291 Base::MuteStream();
2292}
2293
2294TEST_F(WebRtcVideoMediaChannelTest, MultipleSendStreams) {
2295 Base::MultipleSendStreams();
2296}
2297
2298// TODO(juberti): Restore this test once we support sending 0 fps.
2299TEST_F(WebRtcVideoMediaChannelTest, DISABLED_AdaptDropAllFrames) {
2300 Base::AdaptDropAllFrames();
2301}
2302// TODO(juberti): Understand why we get decode errors on this test.
2303TEST_F(WebRtcVideoMediaChannelTest, DISABLED_AdaptFramerate) {
2304 Base::AdaptFramerate();
2305}
2306
2307TEST_F(WebRtcVideoMediaChannelTest, SetSendStreamFormat0x0) {
2308 Base::SetSendStreamFormat0x0();
2309}
2310
2311// TODO(zhurunz): Fix the flakey test.
2312TEST_F(WebRtcVideoMediaChannelTest, DISABLED_SetSendStreamFormat) {
2313 Base::SetSendStreamFormat();
2314}
2315
2316TEST_F(WebRtcVideoMediaChannelTest, TwoStreamsSendAndReceive) {
2317 Base::TwoStreamsSendAndReceive(cricket::VideoCodec(100, "VP8", 640, 400, 30,
2318 0));
2319}
2320
2321TEST_F(WebRtcVideoMediaChannelTest, TwoStreamsReUseFirstStream) {
2322 Base::TwoStreamsReUseFirstStream(cricket::VideoCodec(100, "VP8", 640, 400, 30,
2323 0));
2324}
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00002325
buildbot@webrtc.org0b3c6c32014-04-17 10:03:57 +00002326TEST_F(WebRtcVideoMediaChannelTest, DISABLED_TwoStreamsSendAndUnsignalledRecv) {
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00002327 Base::TwoStreamsSendAndUnsignalledRecv(cricket::VideoCodec(100, "VP8", 640,
2328 400, 30, 0));
2329}
2330
henrike@webrtc.org806768a2014-02-27 21:03:09 +00002331TEST_F(WebRtcVideoMediaChannelTest,
henrike@webrtc.org18e59112014-03-14 17:19:38 +00002332 TwoStreamsSendAndFailUnsignalledRecv) {
henrike@webrtc.org806768a2014-02-27 21:03:09 +00002333 webrtc::Trace::set_level_filter(webrtc::kTraceAll);
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00002334 Base::TwoStreamsSendAndFailUnsignalledRecv(
2335 cricket::VideoCodec(100, "VP8", 640, 400, 30, 0));
2336}
2337
2338TEST_F(WebRtcVideoMediaChannelTest,
henrike@webrtc.org18e59112014-03-14 17:19:38 +00002339 TwoStreamsSendAndFailUnsignalledRecvInOneToOne) {
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00002340 Base::TwoStreamsSendAndFailUnsignalledRecvInOneToOne(
2341 cricket::VideoCodec(100, "VP8", 640, 400, 30, 0));
2342}
2343
2344TEST_F(WebRtcVideoMediaChannelTest,
henrike@webrtc.org18e59112014-03-14 17:19:38 +00002345 TwoStreamsAddAndRemoveUnsignalledRecv) {
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +00002346 Base::TwoStreamsAddAndRemoveUnsignalledRecv(cricket::VideoCodec(100, "VP8",
2347 640, 400, 30,
2348 0));
2349}