blob: b6e50ae4ffa8a20c3ba9cefb84a59b5314b4e027 [file] [log] [blame]
henrike@webrtc.org28e20752013-07-10 00:45:361/*
kjellanderb24317b2016-02-10 15:54:432 * Copyright 2012 The WebRTC project authors. All Rights Reserved.
henrike@webrtc.org28e20752013-07-10 00:45:363 *
kjellanderb24317b2016-02-10 15:54:434 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
henrike@webrtc.org28e20752013-07-10 00:45:369 */
10
kwibergd1fe2812016-04-27 13:47:2911#include <memory>
henrike@webrtc.org28e20752013-07-10 00:45:3612#include <string>
13#include <vector>
14
Henrik Kjellander15583c12016-02-10 09:53:1215#include "webrtc/api/test/fakeconstraints.h"
kjellandera96e2d72016-02-05 07:52:2816#include "webrtc/media/base/fakemediaengine.h"
17#include "webrtc/media/base/fakevideocapturer.h"
18#include "webrtc/media/base/fakevideorenderer.h"
ossu7bb87ee2017-01-23 12:56:2519#include "webrtc/pc/videocapturertracksource.h"
Edward Lemurc20978e2017-07-06 17:44:3420#include "webrtc/rtc_base/gunit.h"
henrike@webrtc.org28e20752013-07-10 00:45:3621
22using webrtc::FakeConstraints;
perkja3ede6c2016-03-08 00:27:4823using webrtc::VideoCapturerTrackSource;
henrike@webrtc.org28e20752013-07-10 00:45:3624using webrtc::MediaConstraintsInterface;
25using webrtc::MediaSourceInterface;
26using webrtc::ObserverInterface;
perkja3ede6c2016-03-08 00:27:4827using webrtc::VideoTrackSourceInterface;
henrike@webrtc.org28e20752013-07-10 00:45:3628
29namespace {
30
31// Max wait time for a test.
32const int kMaxWaitMs = 100;
33
34} // anonymous namespace
35
henrike@webrtc.org28e20752013-07-10 00:45:3636// TestVideoCapturer extends cricket::FakeVideoCapturer so it can be used for
37// testing without known camera formats.
38// It keeps its own lists of cricket::VideoFormats for the unit tests in this
39// file.
40class TestVideoCapturer : public cricket::FakeVideoCapturer {
41 public:
perkja3ede6c2016-03-08 00:27:4842 explicit TestVideoCapturer(bool is_screencast)
43 : FakeVideoCapturer(is_screencast), test_without_formats_(false) {
henrike@webrtc.org28e20752013-07-10 00:45:3644 std::vector<cricket::VideoFormat> formats;
perkja3ede6c2016-03-08 00:27:4845 formats.push_back(
46 cricket::VideoFormat(1280, 720, cricket::VideoFormat::FpsToInterval(30),
47 cricket::FOURCC_I420));
48 formats.push_back(
49 cricket::VideoFormat(640, 480, cricket::VideoFormat::FpsToInterval(30),
50 cricket::FOURCC_I420));
51 formats.push_back(
52 cricket::VideoFormat(640, 400, cricket::VideoFormat::FpsToInterval(30),
53 cricket::FOURCC_I420));
54 formats.push_back(
55 cricket::VideoFormat(320, 240, cricket::VideoFormat::FpsToInterval(30),
56 cricket::FOURCC_I420));
57 formats.push_back(
58 cricket::VideoFormat(352, 288, cricket::VideoFormat::FpsToInterval(30),
59 cricket::FOURCC_I420));
henrike@webrtc.org28e20752013-07-10 00:45:3660 ResetSupportedFormats(formats);
61 }
62
63 // This function is used for resetting the supported capture formats and
64 // simulating a cricket::VideoCapturer implementation that don't support
65 // capture format enumeration. This is used to simulate the current
66 // Chrome implementation.
67 void TestWithoutCameraFormats() {
68 test_without_formats_ = true;
69 std::vector<cricket::VideoFormat> formats;
70 ResetSupportedFormats(formats);
71 }
72
73 virtual cricket::CaptureState Start(
74 const cricket::VideoFormat& capture_format) {
75 if (test_without_formats_) {
76 std::vector<cricket::VideoFormat> formats;
77 formats.push_back(capture_format);
78 ResetSupportedFormats(formats);
79 }
80 return FakeVideoCapturer::Start(capture_format);
81 }
82
83 virtual bool GetBestCaptureFormat(const cricket::VideoFormat& desired,
84 cricket::VideoFormat* best_format) {
85 if (test_without_formats_) {
86 *best_format = desired;
87 return true;
88 }
perkja3ede6c2016-03-08 00:27:4889 return FakeVideoCapturer::GetBestCaptureFormat(desired, best_format);
henrike@webrtc.org28e20752013-07-10 00:45:3690 }
91
92 private:
93 bool test_without_formats_;
94};
95
96class StateObserver : public ObserverInterface {
97 public:
perkja3ede6c2016-03-08 00:27:4898 explicit StateObserver(VideoTrackSourceInterface* source)
99 : state_(source->state()), source_(source) {}
100 virtual void OnChanged() { state_ = source_->state(); }
henrike@webrtc.org28e20752013-07-10 00:45:36101 MediaSourceInterface::SourceState state() const { return state_; }
102
103 private:
104 MediaSourceInterface::SourceState state_;
perkja3ede6c2016-03-08 00:27:48105 rtc::scoped_refptr<VideoTrackSourceInterface> source_;
henrike@webrtc.org28e20752013-07-10 00:45:36106};
107
perkja3ede6c2016-03-08 00:27:48108class VideoCapturerTrackSourceTest : public testing::Test {
henrike@webrtc.org28e20752013-07-10 00:45:36109 protected:
perkja3ede6c2016-03-08 00:27:48110 VideoCapturerTrackSourceTest() { InitCapturer(false); }
Niels Möller60653ba2016-03-02 10:41:36111 void InitCapturer(bool is_screencast) {
deadbeef112b2e92017-02-11 04:13:37112 capturer_ = new TestVideoCapturer(is_screencast);
113 capturer_cleanup_.reset(capturer_);
Niels Möller60653ba2016-03-02 10:41:36114 }
115
116 void InitScreencast() { InitCapturer(true); }
henrike@webrtc.org28e20752013-07-10 00:45:36117
perkja3ede6c2016-03-08 00:27:48118 void CreateVideoCapturerSource() { CreateVideoCapturerSource(NULL); }
henrike@webrtc.org28e20752013-07-10 00:45:36119
perkja3ede6c2016-03-08 00:27:48120 void CreateVideoCapturerSource(
henrike@webrtc.org28e20752013-07-10 00:45:36121 const webrtc::MediaConstraintsInterface* constraints) {
perkja3ede6c2016-03-08 00:27:48122 source_ = VideoCapturerTrackSource::Create(rtc::Thread::Current(),
deadbeef112b2e92017-02-11 04:13:37123 std::move(capturer_cleanup_),
perkja3ede6c2016-03-08 00:27:48124 constraints, false);
henrike@webrtc.org28e20752013-07-10 00:45:36125
wu@webrtc.org967bfff2013-09-19 05:49:50126 ASSERT_TRUE(source_.get() != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36127
wu@webrtc.org967bfff2013-09-19 05:49:50128 state_observer_.reset(new StateObserver(source_));
129 source_->RegisterObserver(state_observer_.get());
perkjf2880a02016-03-03 09:51:52130 source_->AddOrUpdateSink(&renderer_, rtc::VideoSinkWants());
henrike@webrtc.org28e20752013-07-10 00:45:36131 }
132
deadbeef112b2e92017-02-11 04:13:37133 std::unique_ptr<cricket::VideoCapturer> capturer_cleanup_;
mallinath@webrtc.org1112c302013-09-23 20:34:45134 TestVideoCapturer* capturer_;
henrike@webrtc.org28e20752013-07-10 00:45:36135 cricket::FakeVideoRenderer renderer_;
kwibergd1fe2812016-04-27 13:47:29136 std::unique_ptr<StateObserver> state_observer_;
perkja3ede6c2016-03-08 00:27:48137 rtc::scoped_refptr<VideoTrackSourceInterface> source_;
henrike@webrtc.org28e20752013-07-10 00:45:36138};
139
wu@webrtc.org967bfff2013-09-19 05:49:50140// Test that a VideoSource transition to kLive state when the capture
henrike@webrtc.org28e20752013-07-10 00:45:36141// device have started and kEnded if it is stopped.
142// It also test that an output can receive video frames.
perkja3ede6c2016-03-08 00:27:48143TEST_F(VideoCapturerTrackSourceTest, CapturerStartStop) {
henrike@webrtc.org28e20752013-07-10 00:45:36144 // Initialize without constraints.
perkja3ede6c2016-03-08 00:27:48145 CreateVideoCapturerSource();
henrike@webrtc.org28e20752013-07-10 00:45:36146 EXPECT_EQ_WAIT(MediaSourceInterface::kLive, state_observer_->state(),
147 kMaxWaitMs);
148
149 ASSERT_TRUE(capturer_->CaptureFrame());
150 EXPECT_EQ(1, renderer_.num_rendered_frames());
151
152 capturer_->Stop();
153 EXPECT_EQ_WAIT(MediaSourceInterface::kEnded, state_observer_->state(),
154 kMaxWaitMs);
155}
156
wu@webrtc.org967bfff2013-09-19 05:49:50157// Test that a VideoSource transition to kEnded if the capture device
henrike@webrtc.org28e20752013-07-10 00:45:36158// fails.
perkja3ede6c2016-03-08 00:27:48159TEST_F(VideoCapturerTrackSourceTest, CameraFailed) {
160 CreateVideoCapturerSource();
henrike@webrtc.org28e20752013-07-10 00:45:36161 EXPECT_EQ_WAIT(MediaSourceInterface::kLive, state_observer_->state(),
162 kMaxWaitMs);
163
164 capturer_->SignalStateChange(capturer_, cricket::CS_FAILED);
165 EXPECT_EQ_WAIT(MediaSourceInterface::kEnded, state_observer_->state(),
166 kMaxWaitMs);
167}
168
169// Test that the capture output is CIF if we set max constraints to CIF.
170// and the capture device support CIF.
perkja3ede6c2016-03-08 00:27:48171TEST_F(VideoCapturerTrackSourceTest, MandatoryConstraintCif5Fps) {
henrike@webrtc.org28e20752013-07-10 00:45:36172 FakeConstraints constraints;
173 constraints.AddMandatory(MediaConstraintsInterface::kMaxWidth, 352);
174 constraints.AddMandatory(MediaConstraintsInterface::kMaxHeight, 288);
175 constraints.AddMandatory(MediaConstraintsInterface::kMaxFrameRate, 5);
176
perkja3ede6c2016-03-08 00:27:48177 CreateVideoCapturerSource(&constraints);
henrike@webrtc.org28e20752013-07-10 00:45:36178 EXPECT_EQ_WAIT(MediaSourceInterface::kLive, state_observer_->state(),
179 kMaxWaitMs);
180 const cricket::VideoFormat* format = capturer_->GetCaptureFormat();
181 ASSERT_TRUE(format != NULL);
182 EXPECT_EQ(352, format->width);
183 EXPECT_EQ(288, format->height);
perkjfa10b552016-10-03 06:45:26184 EXPECT_EQ(5, format->framerate());
henrike@webrtc.org28e20752013-07-10 00:45:36185}
186
187// Test that the capture output is 720P if the camera support it and the
188// optional constraint is set to 720P.
perkja3ede6c2016-03-08 00:27:48189TEST_F(VideoCapturerTrackSourceTest, MandatoryMinVgaOptional720P) {
henrike@webrtc.org28e20752013-07-10 00:45:36190 FakeConstraints constraints;
191 constraints.AddMandatory(MediaConstraintsInterface::kMinWidth, 640);
192 constraints.AddMandatory(MediaConstraintsInterface::kMinHeight, 480);
193 constraints.AddOptional(MediaConstraintsInterface::kMinWidth, 1280);
194 constraints.AddOptional(MediaConstraintsInterface::kMinAspectRatio,
195 1280.0 / 720);
196
perkja3ede6c2016-03-08 00:27:48197 CreateVideoCapturerSource(&constraints);
henrike@webrtc.org28e20752013-07-10 00:45:36198 EXPECT_EQ_WAIT(MediaSourceInterface::kLive, state_observer_->state(),
199 kMaxWaitMs);
200 const cricket::VideoFormat* format = capturer_->GetCaptureFormat();
201 ASSERT_TRUE(format != NULL);
202 EXPECT_EQ(1280, format->width);
203 EXPECT_EQ(720, format->height);
204 EXPECT_EQ(30, format->framerate());
205}
206
207// Test that the capture output have aspect ratio 4:3 if a mandatory constraint
208// require it even if an optional constraint request a higher resolution
209// that don't have this aspect ratio.
perkja3ede6c2016-03-08 00:27:48210TEST_F(VideoCapturerTrackSourceTest, MandatoryAspectRatio4To3) {
henrike@webrtc.org28e20752013-07-10 00:45:36211 FakeConstraints constraints;
212 constraints.AddMandatory(MediaConstraintsInterface::kMinWidth, 640);
213 constraints.AddMandatory(MediaConstraintsInterface::kMinHeight, 480);
214 constraints.AddMandatory(MediaConstraintsInterface::kMaxAspectRatio,
215 640.0 / 480);
216 constraints.AddOptional(MediaConstraintsInterface::kMinWidth, 1280);
217
perkja3ede6c2016-03-08 00:27:48218 CreateVideoCapturerSource(&constraints);
henrike@webrtc.org28e20752013-07-10 00:45:36219 EXPECT_EQ_WAIT(MediaSourceInterface::kLive, state_observer_->state(),
220 kMaxWaitMs);
221 const cricket::VideoFormat* format = capturer_->GetCaptureFormat();
222 ASSERT_TRUE(format != NULL);
223 EXPECT_EQ(640, format->width);
224 EXPECT_EQ(480, format->height);
225 EXPECT_EQ(30, format->framerate());
226}
227
henrike@webrtc.org28e20752013-07-10 00:45:36228// Test that the source state transition to kEnded if the mandatory aspect ratio
229// is set higher than supported.
perkja3ede6c2016-03-08 00:27:48230TEST_F(VideoCapturerTrackSourceTest, MandatoryAspectRatioTooHigh) {
henrike@webrtc.org28e20752013-07-10 00:45:36231 FakeConstraints constraints;
232 constraints.AddMandatory(MediaConstraintsInterface::kMinAspectRatio, 2);
perkja3ede6c2016-03-08 00:27:48233 CreateVideoCapturerSource(&constraints);
henrike@webrtc.org28e20752013-07-10 00:45:36234 EXPECT_EQ_WAIT(MediaSourceInterface::kEnded, state_observer_->state(),
235 kMaxWaitMs);
236}
237
238// Test that the source ignores an optional aspect ratio that is higher than
239// supported.
perkja3ede6c2016-03-08 00:27:48240TEST_F(VideoCapturerTrackSourceTest, OptionalAspectRatioTooHigh) {
henrike@webrtc.org28e20752013-07-10 00:45:36241 FakeConstraints constraints;
242 constraints.AddOptional(MediaConstraintsInterface::kMinAspectRatio, 2);
perkja3ede6c2016-03-08 00:27:48243 CreateVideoCapturerSource(&constraints);
henrike@webrtc.org28e20752013-07-10 00:45:36244 EXPECT_EQ_WAIT(MediaSourceInterface::kLive, state_observer_->state(),
245 kMaxWaitMs);
246 const cricket::VideoFormat* format = capturer_->GetCaptureFormat();
247 ASSERT_TRUE(format != NULL);
248 double aspect_ratio = static_cast<double>(format->width) / format->height;
249 EXPECT_LT(aspect_ratio, 2);
250}
251
252// Test that the source starts video with the default resolution if the
253// camera doesn't support capability enumeration and there are no constraints.
perkja3ede6c2016-03-08 00:27:48254TEST_F(VideoCapturerTrackSourceTest, NoCameraCapability) {
henrike@webrtc.org28e20752013-07-10 00:45:36255 capturer_->TestWithoutCameraFormats();
256
perkja3ede6c2016-03-08 00:27:48257 CreateVideoCapturerSource();
henrike@webrtc.org28e20752013-07-10 00:45:36258 EXPECT_EQ_WAIT(MediaSourceInterface::kLive, state_observer_->state(),
259 kMaxWaitMs);
260 const cricket::VideoFormat* format = capturer_->GetCaptureFormat();
261 ASSERT_TRUE(format != NULL);
262 EXPECT_EQ(640, format->width);
263 EXPECT_EQ(480, format->height);
264 EXPECT_EQ(30, format->framerate());
265}
266
267// Test that the source can start the video and get the requested aspect ratio
268// if the camera doesn't support capability enumeration and the aspect ratio is
269// set.
perkja3ede6c2016-03-08 00:27:48270TEST_F(VideoCapturerTrackSourceTest, NoCameraCapability16To9Ratio) {
henrike@webrtc.org28e20752013-07-10 00:45:36271 capturer_->TestWithoutCameraFormats();
272
273 FakeConstraints constraints;
274 double requested_aspect_ratio = 640.0 / 360;
275 constraints.AddMandatory(MediaConstraintsInterface::kMinWidth, 640);
276 constraints.AddMandatory(MediaConstraintsInterface::kMinAspectRatio,
277 requested_aspect_ratio);
278
perkja3ede6c2016-03-08 00:27:48279 CreateVideoCapturerSource(&constraints);
henrike@webrtc.org28e20752013-07-10 00:45:36280 EXPECT_EQ_WAIT(MediaSourceInterface::kLive, state_observer_->state(),
281 kMaxWaitMs);
282 const cricket::VideoFormat* format = capturer_->GetCaptureFormat();
283 double aspect_ratio = static_cast<double>(format->width) / format->height;
284 EXPECT_LE(requested_aspect_ratio, aspect_ratio);
285}
286
287// Test that the source state transitions to kEnded if an unknown mandatory
288// constraint is found.
perkja3ede6c2016-03-08 00:27:48289TEST_F(VideoCapturerTrackSourceTest, InvalidMandatoryConstraint) {
henrike@webrtc.org28e20752013-07-10 00:45:36290 FakeConstraints constraints;
291 constraints.AddMandatory("weird key", 640);
292
perkja3ede6c2016-03-08 00:27:48293 CreateVideoCapturerSource(&constraints);
henrike@webrtc.org28e20752013-07-10 00:45:36294 EXPECT_EQ_WAIT(MediaSourceInterface::kEnded, state_observer_->state(),
295 kMaxWaitMs);
296}
297
298// Test that the source ignores an unknown optional constraint.
perkja3ede6c2016-03-08 00:27:48299TEST_F(VideoCapturerTrackSourceTest, InvalidOptionalConstraint) {
henrike@webrtc.org28e20752013-07-10 00:45:36300 FakeConstraints constraints;
301 constraints.AddOptional("weird key", 640);
302
perkja3ede6c2016-03-08 00:27:48303 CreateVideoCapturerSource(&constraints);
henrike@webrtc.org28e20752013-07-10 00:45:36304 EXPECT_EQ_WAIT(MediaSourceInterface::kLive, state_observer_->state(),
305 kMaxWaitMs);
306}
307
perkj0d3eef22016-03-09 01:39:17308TEST_F(VideoCapturerTrackSourceTest, SetValidDenoisingConstraint) {
henrike@webrtc.org28e20752013-07-10 00:45:36309 FakeConstraints constraints;
Perc0d31e92016-03-31 15:23:39310 constraints.AddMandatory(MediaConstraintsInterface::kNoiseReduction, "false");
henrike@webrtc.org28e20752013-07-10 00:45:36311
perkja3ede6c2016-03-08 00:27:48312 CreateVideoCapturerSource(&constraints);
henrike@webrtc.org28e20752013-07-10 00:45:36313
Perc0d31e92016-03-31 15:23:39314 EXPECT_EQ(rtc::Optional<bool>(false), source_->needs_denoising());
henrike@webrtc.org28e20752013-07-10 00:45:36315}
316
perkj0d3eef22016-03-09 01:39:17317TEST_F(VideoCapturerTrackSourceTest, NoiseReductionConstraintNotSet) {
henrike@webrtc.org28e20752013-07-10 00:45:36318 FakeConstraints constraints;
perkja3ede6c2016-03-08 00:27:48319 CreateVideoCapturerSource(&constraints);
Perc0d31e92016-03-31 15:23:39320 EXPECT_EQ(rtc::Optional<bool>(), source_->needs_denoising());
henrike@webrtc.org28e20752013-07-10 00:45:36321}
322
perkj0d3eef22016-03-09 01:39:17323TEST_F(VideoCapturerTrackSourceTest,
324 MandatoryDenoisingConstraintOverridesOptional) {
henrike@webrtc.org28e20752013-07-10 00:45:36325 FakeConstraints constraints;
perkj0d3eef22016-03-09 01:39:17326 constraints.AddMandatory(MediaConstraintsInterface::kNoiseReduction, false);
327 constraints.AddOptional(MediaConstraintsInterface::kNoiseReduction, true);
henrike@webrtc.org28e20752013-07-10 00:45:36328
perkja3ede6c2016-03-08 00:27:48329 CreateVideoCapturerSource(&constraints);
henrike@webrtc.org28e20752013-07-10 00:45:36330
Perc0d31e92016-03-31 15:23:39331 EXPECT_EQ(rtc::Optional<bool>(false), source_->needs_denoising());
henrike@webrtc.org28e20752013-07-10 00:45:36332}
333
perkj0d3eef22016-03-09 01:39:17334TEST_F(VideoCapturerTrackSourceTest, NoiseReductionAndInvalidKeyOptional) {
henrike@webrtc.org28e20752013-07-10 00:45:36335 FakeConstraints constraints;
perkj0d3eef22016-03-09 01:39:17336 constraints.AddOptional(MediaConstraintsInterface::kNoiseReduction, true);
henrike@webrtc.org28e20752013-07-10 00:45:36337 constraints.AddOptional("invalidKey", false);
338
perkja3ede6c2016-03-08 00:27:48339 CreateVideoCapturerSource(&constraints);
henrike@webrtc.org28e20752013-07-10 00:45:36340
341 EXPECT_EQ_WAIT(MediaSourceInterface::kLive, state_observer_->state(),
perkja3ede6c2016-03-08 00:27:48342 kMaxWaitMs);
Perc0d31e92016-03-31 15:23:39343 EXPECT_EQ(rtc::Optional<bool>(true), source_->needs_denoising());
henrike@webrtc.org28e20752013-07-10 00:45:36344}
345
perkj0d3eef22016-03-09 01:39:17346TEST_F(VideoCapturerTrackSourceTest, NoiseReductionAndInvalidKeyMandatory) {
henrike@webrtc.org28e20752013-07-10 00:45:36347 FakeConstraints constraints;
perkja3ede6c2016-03-08 00:27:48348 constraints.AddMandatory(MediaConstraintsInterface::kNoiseReduction, false);
henrike@webrtc.org28e20752013-07-10 00:45:36349 constraints.AddMandatory("invalidKey", false);
350
perkja3ede6c2016-03-08 00:27:48351 CreateVideoCapturerSource(&constraints);
henrike@webrtc.org28e20752013-07-10 00:45:36352
353 EXPECT_EQ_WAIT(MediaSourceInterface::kEnded, state_observer_->state(),
perkja3ede6c2016-03-08 00:27:48354 kMaxWaitMs);
Perc0d31e92016-03-31 15:23:39355 EXPECT_EQ(rtc::Optional<bool>(), source_->needs_denoising());
henrike@webrtc.org28e20752013-07-10 00:45:36356}
357
perkj0d3eef22016-03-09 01:39:17358TEST_F(VideoCapturerTrackSourceTest, InvalidDenoisingValueOptional) {
henrike@webrtc.org28e20752013-07-10 00:45:36359 FakeConstraints constraints;
perkja3ede6c2016-03-08 00:27:48360 constraints.AddOptional(MediaConstraintsInterface::kNoiseReduction,
361 "not a boolean");
henrike@webrtc.org28e20752013-07-10 00:45:36362
perkja3ede6c2016-03-08 00:27:48363 CreateVideoCapturerSource(&constraints);
henrike@webrtc.org28e20752013-07-10 00:45:36364
365 EXPECT_EQ_WAIT(MediaSourceInterface::kLive, state_observer_->state(),
perkja3ede6c2016-03-08 00:27:48366 kMaxWaitMs);
Perc0d31e92016-03-31 15:23:39367
368 EXPECT_EQ(rtc::Optional<bool>(), source_->needs_denoising());
henrike@webrtc.org28e20752013-07-10 00:45:36369}
370
perkj0d3eef22016-03-09 01:39:17371TEST_F(VideoCapturerTrackSourceTest, InvalidDenoisingValueMandatory) {
henrike@webrtc.org28e20752013-07-10 00:45:36372 FakeConstraints constraints;
373 // Optional constraints should be ignored if the mandatory constraints fail.
perkja3ede6c2016-03-08 00:27:48374 constraints.AddOptional(MediaConstraintsInterface::kNoiseReduction, "false");
henrike@webrtc.org28e20752013-07-10 00:45:36375 // Values are case-sensitive and must be all lower-case.
perkja3ede6c2016-03-08 00:27:48376 constraints.AddMandatory(MediaConstraintsInterface::kNoiseReduction, "True");
henrike@webrtc.org28e20752013-07-10 00:45:36377
perkja3ede6c2016-03-08 00:27:48378 CreateVideoCapturerSource(&constraints);
henrike@webrtc.org28e20752013-07-10 00:45:36379
380 EXPECT_EQ_WAIT(MediaSourceInterface::kEnded, state_observer_->state(),
perkja3ede6c2016-03-08 00:27:48381 kMaxWaitMs);
Perc0d31e92016-03-31 15:23:39382 EXPECT_EQ(rtc::Optional<bool>(), source_->needs_denoising());
henrike@webrtc.org28e20752013-07-10 00:45:36383}
384
perkja3ede6c2016-03-08 00:27:48385TEST_F(VideoCapturerTrackSourceTest, MixedOptionsAndConstraints) {
henrike@webrtc.org28e20752013-07-10 00:45:36386 FakeConstraints constraints;
387 constraints.AddMandatory(MediaConstraintsInterface::kMaxWidth, 352);
388 constraints.AddMandatory(MediaConstraintsInterface::kMaxHeight, 288);
389 constraints.AddOptional(MediaConstraintsInterface::kMaxFrameRate, 5);
390
perkja3ede6c2016-03-08 00:27:48391 constraints.AddMandatory(MediaConstraintsInterface::kNoiseReduction, false);
392 constraints.AddOptional(MediaConstraintsInterface::kNoiseReduction, true);
henrike@webrtc.org28e20752013-07-10 00:45:36393
perkja3ede6c2016-03-08 00:27:48394 CreateVideoCapturerSource(&constraints);
henrike@webrtc.org28e20752013-07-10 00:45:36395 EXPECT_EQ_WAIT(MediaSourceInterface::kLive, state_observer_->state(),
396 kMaxWaitMs);
397 const cricket::VideoFormat* format = capturer_->GetCaptureFormat();
398 ASSERT_TRUE(format != NULL);
399 EXPECT_EQ(352, format->width);
400 EXPECT_EQ(288, format->height);
perkjfa10b552016-10-03 06:45:26401 EXPECT_EQ(5, format->framerate());
henrike@webrtc.org28e20752013-07-10 00:45:36402
Perc0d31e92016-03-31 15:23:39403 EXPECT_EQ(rtc::Optional<bool>(false), source_->needs_denoising());
henrike@webrtc.org28e20752013-07-10 00:45:36404}
405
406// Tests that the source starts video with the default resolution for
407// screencast if no constraint is set.
perkja3ede6c2016-03-08 00:27:48408TEST_F(VideoCapturerTrackSourceTest, ScreencastResolutionNoConstraint) {
Niels Möller60653ba2016-03-02 10:41:36409 InitScreencast();
henrike@webrtc.org28e20752013-07-10 00:45:36410 capturer_->TestWithoutCameraFormats();
henrike@webrtc.org28e20752013-07-10 00:45:36411
perkja3ede6c2016-03-08 00:27:48412 CreateVideoCapturerSource();
perkj0d3eef22016-03-09 01:39:17413 ASSERT_TRUE(source_->is_screencast());
henrike@webrtc.org28e20752013-07-10 00:45:36414 EXPECT_EQ_WAIT(MediaSourceInterface::kLive, state_observer_->state(),
415 kMaxWaitMs);
416 const cricket::VideoFormat* format = capturer_->GetCaptureFormat();
417 ASSERT_TRUE(format != NULL);
418 EXPECT_EQ(640, format->width);
419 EXPECT_EQ(480, format->height);
420 EXPECT_EQ(30, format->framerate());
421}
422
423// Tests that the source starts video with the max width and height set by
424// constraints for screencast.
perkja3ede6c2016-03-08 00:27:48425TEST_F(VideoCapturerTrackSourceTest, ScreencastResolutionWithConstraint) {
henrike@webrtc.org28e20752013-07-10 00:45:36426 FakeConstraints constraints;
427 constraints.AddMandatory(MediaConstraintsInterface::kMaxWidth, 480);
428 constraints.AddMandatory(MediaConstraintsInterface::kMaxHeight, 270);
429
Niels Möller60653ba2016-03-02 10:41:36430 InitScreencast();
henrike@webrtc.org28e20752013-07-10 00:45:36431 capturer_->TestWithoutCameraFormats();
henrike@webrtc.org28e20752013-07-10 00:45:36432
perkja3ede6c2016-03-08 00:27:48433 CreateVideoCapturerSource(&constraints);
perkj0d3eef22016-03-09 01:39:17434 ASSERT_TRUE(source_->is_screencast());
henrike@webrtc.org28e20752013-07-10 00:45:36435 EXPECT_EQ_WAIT(MediaSourceInterface::kLive, state_observer_->state(),
436 kMaxWaitMs);
437 const cricket::VideoFormat* format = capturer_->GetCaptureFormat();
438 ASSERT_TRUE(format != NULL);
439 EXPECT_EQ(480, format->width);
440 EXPECT_EQ(270, format->height);
441 EXPECT_EQ(30, format->framerate());
442}
443
perkja3ede6c2016-03-08 00:27:48444TEST_F(VideoCapturerTrackSourceTest, MandatorySubOneFpsConstraints) {
henrike@webrtc.org28e20752013-07-10 00:45:36445 FakeConstraints constraints;
446 constraints.AddMandatory(MediaConstraintsInterface::kMaxFrameRate, 0.5);
447
perkja3ede6c2016-03-08 00:27:48448 CreateVideoCapturerSource(&constraints);
henrike@webrtc.org28e20752013-07-10 00:45:36449 EXPECT_EQ_WAIT(MediaSourceInterface::kEnded, state_observer_->state(),
450 kMaxWaitMs);
451 ASSERT_TRUE(capturer_->GetCaptureFormat() == NULL);
452}
453
perkja3ede6c2016-03-08 00:27:48454TEST_F(VideoCapturerTrackSourceTest, OptionalSubOneFpsConstraints) {
henrike@webrtc.org28e20752013-07-10 00:45:36455 FakeConstraints constraints;
456 constraints.AddOptional(MediaConstraintsInterface::kMaxFrameRate, 0.5);
457
perkja3ede6c2016-03-08 00:27:48458 CreateVideoCapturerSource(&constraints);
henrike@webrtc.org28e20752013-07-10 00:45:36459 EXPECT_EQ_WAIT(MediaSourceInterface::kLive, state_observer_->state(),
460 kMaxWaitMs);
461 const cricket::VideoFormat* format = capturer_->GetCaptureFormat();
462 ASSERT_TRUE(format != NULL);
perkjfa10b552016-10-03 06:45:26463 EXPECT_EQ(1, format->framerate());
henrike@webrtc.org28e20752013-07-10 00:45:36464}