blob: c64c83e959380fdf132b44368935b7bc06f40648 [file] [log] [blame]
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001/*
kjellanderb24317b2016-02-10 07:54:43 -08002 * Copyright 2012 The WebRTC project authors. All Rights Reserved.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003 *
kjellanderb24317b2016-02-10 07:54:43 -08004 * 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:36 +00009 */
10
kwibergd1fe2812016-04-27 06:47:29 -070011#include <memory>
henrike@webrtc.org28e20752013-07-10 00:45:36 +000012#include <string>
13#include <vector>
14
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020015#include "api/test/fakeconstraints.h"
16#include "media/base/fakemediaengine.h"
17#include "media/base/fakevideocapturer.h"
18#include "media/base/fakevideorenderer.h"
19#include "pc/videocapturertracksource.h"
20#include "rtc_base/gunit.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000021
22using webrtc::FakeConstraints;
perkja3ede6c2016-03-08 01:27:48 +010023using webrtc::VideoCapturerTrackSource;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000024using webrtc::MediaConstraintsInterface;
25using webrtc::MediaSourceInterface;
26using webrtc::ObserverInterface;
perkja3ede6c2016-03-08 01:27:48 +010027using webrtc::VideoTrackSourceInterface;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000028
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:36 +000036// 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 01:27:48 +010042 explicit TestVideoCapturer(bool is_screencast)
43 : FakeVideoCapturer(is_screencast), test_without_formats_(false) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +000044 std::vector<cricket::VideoFormat> formats;
perkja3ede6c2016-03-08 01:27:48 +010045 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:36 +000060 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 01:27:48 +010089 return FakeVideoCapturer::GetBestCaptureFormat(desired, best_format);
henrike@webrtc.org28e20752013-07-10 00:45:36 +000090 }
91
92 private:
93 bool test_without_formats_;
94};
95
96class StateObserver : public ObserverInterface {
97 public:
perkja3ede6c2016-03-08 01:27:48 +010098 explicit StateObserver(VideoTrackSourceInterface* source)
99 : state_(source->state()), source_(source) {}
100 virtual void OnChanged() { state_ = source_->state(); }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000101 MediaSourceInterface::SourceState state() const { return state_; }
102
103 private:
104 MediaSourceInterface::SourceState state_;
perkja3ede6c2016-03-08 01:27:48 +0100105 rtc::scoped_refptr<VideoTrackSourceInterface> source_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000106};
107
perkja3ede6c2016-03-08 01:27:48 +0100108class VideoCapturerTrackSourceTest : public testing::Test {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000109 protected:
perkja3ede6c2016-03-08 01:27:48 +0100110 VideoCapturerTrackSourceTest() { InitCapturer(false); }
Niels Möller60653ba2016-03-02 11:41:36 +0100111 void InitCapturer(bool is_screencast) {
deadbeef112b2e92017-02-10 20:13:37 -0800112 capturer_ = new TestVideoCapturer(is_screencast);
113 capturer_cleanup_.reset(capturer_);
Niels Möller60653ba2016-03-02 11:41:36 +0100114 }
115
116 void InitScreencast() { InitCapturer(true); }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000117
perkja3ede6c2016-03-08 01:27:48 +0100118 void CreateVideoCapturerSource() { CreateVideoCapturerSource(NULL); }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000119
perkja3ede6c2016-03-08 01:27:48 +0100120 void CreateVideoCapturerSource(
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000121 const webrtc::MediaConstraintsInterface* constraints) {
perkja3ede6c2016-03-08 01:27:48 +0100122 source_ = VideoCapturerTrackSource::Create(rtc::Thread::Current(),
deadbeef112b2e92017-02-10 20:13:37 -0800123 std::move(capturer_cleanup_),
perkja3ede6c2016-03-08 01:27:48 +0100124 constraints, false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000125
wu@webrtc.org967bfff2013-09-19 05:49:50 +0000126 ASSERT_TRUE(source_.get() != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000127
wu@webrtc.org967bfff2013-09-19 05:49:50 +0000128 state_observer_.reset(new StateObserver(source_));
129 source_->RegisterObserver(state_observer_.get());
perkjf2880a02016-03-03 01:51:52 -0800130 source_->AddOrUpdateSink(&renderer_, rtc::VideoSinkWants());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000131 }
132
deadbeef112b2e92017-02-10 20:13:37 -0800133 std::unique_ptr<cricket::VideoCapturer> capturer_cleanup_;
mallinath@webrtc.org1112c302013-09-23 20:34:45 +0000134 TestVideoCapturer* capturer_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000135 cricket::FakeVideoRenderer renderer_;
kwibergd1fe2812016-04-27 06:47:29 -0700136 std::unique_ptr<StateObserver> state_observer_;
perkja3ede6c2016-03-08 01:27:48 +0100137 rtc::scoped_refptr<VideoTrackSourceInterface> source_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000138};
139
wu@webrtc.org967bfff2013-09-19 05:49:50 +0000140// Test that a VideoSource transition to kLive state when the capture
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000141// device have started and kEnded if it is stopped.
142// It also test that an output can receive video frames.
perkja3ede6c2016-03-08 01:27:48 +0100143TEST_F(VideoCapturerTrackSourceTest, CapturerStartStop) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000144 // Initialize without constraints.
perkja3ede6c2016-03-08 01:27:48 +0100145 CreateVideoCapturerSource();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000146 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:50 +0000157// Test that a VideoSource transition to kEnded if the capture device
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000158// fails.
perkja3ede6c2016-03-08 01:27:48 +0100159TEST_F(VideoCapturerTrackSourceTest, CameraFailed) {
160 CreateVideoCapturerSource();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000161 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 01:27:48 +0100171TEST_F(VideoCapturerTrackSourceTest, MandatoryConstraintCif5Fps) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000172 FakeConstraints constraints;
173 constraints.AddMandatory(MediaConstraintsInterface::kMaxWidth, 352);
174 constraints.AddMandatory(MediaConstraintsInterface::kMaxHeight, 288);
175 constraints.AddMandatory(MediaConstraintsInterface::kMaxFrameRate, 5);
176
perkja3ede6c2016-03-08 01:27:48 +0100177 CreateVideoCapturerSource(&constraints);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000178 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-02 23:45:26 -0700184 EXPECT_EQ(5, format->framerate());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000185}
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 01:27:48 +0100189TEST_F(VideoCapturerTrackSourceTest, MandatoryMinVgaOptional720P) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000190 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 01:27:48 +0100197 CreateVideoCapturerSource(&constraints);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000198 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 01:27:48 +0100210TEST_F(VideoCapturerTrackSourceTest, MandatoryAspectRatio4To3) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000211 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 01:27:48 +0100218 CreateVideoCapturerSource(&constraints);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000219 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:36 +0000228// Test that the source state transition to kEnded if the mandatory aspect ratio
229// is set higher than supported.
perkja3ede6c2016-03-08 01:27:48 +0100230TEST_F(VideoCapturerTrackSourceTest, MandatoryAspectRatioTooHigh) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000231 FakeConstraints constraints;
232 constraints.AddMandatory(MediaConstraintsInterface::kMinAspectRatio, 2);
perkja3ede6c2016-03-08 01:27:48 +0100233 CreateVideoCapturerSource(&constraints);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000234 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 01:27:48 +0100240TEST_F(VideoCapturerTrackSourceTest, OptionalAspectRatioTooHigh) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000241 FakeConstraints constraints;
242 constraints.AddOptional(MediaConstraintsInterface::kMinAspectRatio, 2);
perkja3ede6c2016-03-08 01:27:48 +0100243 CreateVideoCapturerSource(&constraints);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000244 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 01:27:48 +0100254TEST_F(VideoCapturerTrackSourceTest, NoCameraCapability) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000255 capturer_->TestWithoutCameraFormats();
256
perkja3ede6c2016-03-08 01:27:48 +0100257 CreateVideoCapturerSource();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000258 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 01:27:48 +0100270TEST_F(VideoCapturerTrackSourceTest, NoCameraCapability16To9Ratio) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000271 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 01:27:48 +0100279 CreateVideoCapturerSource(&constraints);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000280 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 01:27:48 +0100289TEST_F(VideoCapturerTrackSourceTest, InvalidMandatoryConstraint) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000290 FakeConstraints constraints;
291 constraints.AddMandatory("weird key", 640);
292
perkja3ede6c2016-03-08 01:27:48 +0100293 CreateVideoCapturerSource(&constraints);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000294 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 01:27:48 +0100299TEST_F(VideoCapturerTrackSourceTest, InvalidOptionalConstraint) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000300 FakeConstraints constraints;
301 constraints.AddOptional("weird key", 640);
302
perkja3ede6c2016-03-08 01:27:48 +0100303 CreateVideoCapturerSource(&constraints);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000304 EXPECT_EQ_WAIT(MediaSourceInterface::kLive, state_observer_->state(),
305 kMaxWaitMs);
306}
307
perkj0d3eef22016-03-09 02:39:17 +0100308TEST_F(VideoCapturerTrackSourceTest, SetValidDenoisingConstraint) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000309 FakeConstraints constraints;
Perc0d31e92016-03-31 17:23:39 +0200310 constraints.AddMandatory(MediaConstraintsInterface::kNoiseReduction, "false");
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000311
perkja3ede6c2016-03-08 01:27:48 +0100312 CreateVideoCapturerSource(&constraints);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000313
Perc0d31e92016-03-31 17:23:39 +0200314 EXPECT_EQ(rtc::Optional<bool>(false), source_->needs_denoising());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000315}
316
perkj0d3eef22016-03-09 02:39:17 +0100317TEST_F(VideoCapturerTrackSourceTest, NoiseReductionConstraintNotSet) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000318 FakeConstraints constraints;
perkja3ede6c2016-03-08 01:27:48 +0100319 CreateVideoCapturerSource(&constraints);
Perc0d31e92016-03-31 17:23:39 +0200320 EXPECT_EQ(rtc::Optional<bool>(), source_->needs_denoising());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000321}
322
perkj0d3eef22016-03-09 02:39:17 +0100323TEST_F(VideoCapturerTrackSourceTest,
324 MandatoryDenoisingConstraintOverridesOptional) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000325 FakeConstraints constraints;
perkj0d3eef22016-03-09 02:39:17 +0100326 constraints.AddMandatory(MediaConstraintsInterface::kNoiseReduction, false);
327 constraints.AddOptional(MediaConstraintsInterface::kNoiseReduction, true);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000328
perkja3ede6c2016-03-08 01:27:48 +0100329 CreateVideoCapturerSource(&constraints);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000330
Perc0d31e92016-03-31 17:23:39 +0200331 EXPECT_EQ(rtc::Optional<bool>(false), source_->needs_denoising());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000332}
333
perkj0d3eef22016-03-09 02:39:17 +0100334TEST_F(VideoCapturerTrackSourceTest, NoiseReductionAndInvalidKeyOptional) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000335 FakeConstraints constraints;
perkj0d3eef22016-03-09 02:39:17 +0100336 constraints.AddOptional(MediaConstraintsInterface::kNoiseReduction, true);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000337 constraints.AddOptional("invalidKey", false);
338
perkja3ede6c2016-03-08 01:27:48 +0100339 CreateVideoCapturerSource(&constraints);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000340
341 EXPECT_EQ_WAIT(MediaSourceInterface::kLive, state_observer_->state(),
perkja3ede6c2016-03-08 01:27:48 +0100342 kMaxWaitMs);
Perc0d31e92016-03-31 17:23:39 +0200343 EXPECT_EQ(rtc::Optional<bool>(true), source_->needs_denoising());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000344}
345
perkj0d3eef22016-03-09 02:39:17 +0100346TEST_F(VideoCapturerTrackSourceTest, NoiseReductionAndInvalidKeyMandatory) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000347 FakeConstraints constraints;
perkja3ede6c2016-03-08 01:27:48 +0100348 constraints.AddMandatory(MediaConstraintsInterface::kNoiseReduction, false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000349 constraints.AddMandatory("invalidKey", false);
350
perkja3ede6c2016-03-08 01:27:48 +0100351 CreateVideoCapturerSource(&constraints);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000352
353 EXPECT_EQ_WAIT(MediaSourceInterface::kEnded, state_observer_->state(),
perkja3ede6c2016-03-08 01:27:48 +0100354 kMaxWaitMs);
Perc0d31e92016-03-31 17:23:39 +0200355 EXPECT_EQ(rtc::Optional<bool>(), source_->needs_denoising());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000356}
357
perkj0d3eef22016-03-09 02:39:17 +0100358TEST_F(VideoCapturerTrackSourceTest, InvalidDenoisingValueOptional) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000359 FakeConstraints constraints;
perkja3ede6c2016-03-08 01:27:48 +0100360 constraints.AddOptional(MediaConstraintsInterface::kNoiseReduction,
361 "not a boolean");
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000362
perkja3ede6c2016-03-08 01:27:48 +0100363 CreateVideoCapturerSource(&constraints);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000364
365 EXPECT_EQ_WAIT(MediaSourceInterface::kLive, state_observer_->state(),
perkja3ede6c2016-03-08 01:27:48 +0100366 kMaxWaitMs);
Perc0d31e92016-03-31 17:23:39 +0200367
368 EXPECT_EQ(rtc::Optional<bool>(), source_->needs_denoising());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000369}
370
perkj0d3eef22016-03-09 02:39:17 +0100371TEST_F(VideoCapturerTrackSourceTest, InvalidDenoisingValueMandatory) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000372 FakeConstraints constraints;
373 // Optional constraints should be ignored if the mandatory constraints fail.
perkja3ede6c2016-03-08 01:27:48 +0100374 constraints.AddOptional(MediaConstraintsInterface::kNoiseReduction, "false");
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000375 // Values are case-sensitive and must be all lower-case.
perkja3ede6c2016-03-08 01:27:48 +0100376 constraints.AddMandatory(MediaConstraintsInterface::kNoiseReduction, "True");
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000377
perkja3ede6c2016-03-08 01:27:48 +0100378 CreateVideoCapturerSource(&constraints);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000379
380 EXPECT_EQ_WAIT(MediaSourceInterface::kEnded, state_observer_->state(),
perkja3ede6c2016-03-08 01:27:48 +0100381 kMaxWaitMs);
Perc0d31e92016-03-31 17:23:39 +0200382 EXPECT_EQ(rtc::Optional<bool>(), source_->needs_denoising());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000383}
384
perkja3ede6c2016-03-08 01:27:48 +0100385TEST_F(VideoCapturerTrackSourceTest, MixedOptionsAndConstraints) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000386 FakeConstraints constraints;
387 constraints.AddMandatory(MediaConstraintsInterface::kMaxWidth, 352);
388 constraints.AddMandatory(MediaConstraintsInterface::kMaxHeight, 288);
389 constraints.AddOptional(MediaConstraintsInterface::kMaxFrameRate, 5);
390
perkja3ede6c2016-03-08 01:27:48 +0100391 constraints.AddMandatory(MediaConstraintsInterface::kNoiseReduction, false);
392 constraints.AddOptional(MediaConstraintsInterface::kNoiseReduction, true);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000393
perkja3ede6c2016-03-08 01:27:48 +0100394 CreateVideoCapturerSource(&constraints);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000395 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-02 23:45:26 -0700401 EXPECT_EQ(5, format->framerate());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000402
Perc0d31e92016-03-31 17:23:39 +0200403 EXPECT_EQ(rtc::Optional<bool>(false), source_->needs_denoising());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000404}
405
406// Tests that the source starts video with the default resolution for
407// screencast if no constraint is set.
perkja3ede6c2016-03-08 01:27:48 +0100408TEST_F(VideoCapturerTrackSourceTest, ScreencastResolutionNoConstraint) {
Niels Möller60653ba2016-03-02 11:41:36 +0100409 InitScreencast();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000410 capturer_->TestWithoutCameraFormats();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000411
perkja3ede6c2016-03-08 01:27:48 +0100412 CreateVideoCapturerSource();
perkj0d3eef22016-03-09 02:39:17 +0100413 ASSERT_TRUE(source_->is_screencast());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000414 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 01:27:48 +0100425TEST_F(VideoCapturerTrackSourceTest, ScreencastResolutionWithConstraint) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000426 FakeConstraints constraints;
427 constraints.AddMandatory(MediaConstraintsInterface::kMaxWidth, 480);
428 constraints.AddMandatory(MediaConstraintsInterface::kMaxHeight, 270);
429
Niels Möller60653ba2016-03-02 11:41:36 +0100430 InitScreencast();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000431 capturer_->TestWithoutCameraFormats();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000432
perkja3ede6c2016-03-08 01:27:48 +0100433 CreateVideoCapturerSource(&constraints);
perkj0d3eef22016-03-09 02:39:17 +0100434 ASSERT_TRUE(source_->is_screencast());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000435 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 01:27:48 +0100444TEST_F(VideoCapturerTrackSourceTest, MandatorySubOneFpsConstraints) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000445 FakeConstraints constraints;
446 constraints.AddMandatory(MediaConstraintsInterface::kMaxFrameRate, 0.5);
447
perkja3ede6c2016-03-08 01:27:48 +0100448 CreateVideoCapturerSource(&constraints);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000449 EXPECT_EQ_WAIT(MediaSourceInterface::kEnded, state_observer_->state(),
450 kMaxWaitMs);
451 ASSERT_TRUE(capturer_->GetCaptureFormat() == NULL);
452}
453
perkja3ede6c2016-03-08 01:27:48 +0100454TEST_F(VideoCapturerTrackSourceTest, OptionalSubOneFpsConstraints) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000455 FakeConstraints constraints;
456 constraints.AddOptional(MediaConstraintsInterface::kMaxFrameRate, 0.5);
457
perkja3ede6c2016-03-08 01:27:48 +0100458 CreateVideoCapturerSource(&constraints);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000459 EXPECT_EQ_WAIT(MediaSourceInterface::kLive, state_observer_->state(),
460 kMaxWaitMs);
461 const cricket::VideoFormat* format = capturer_->GetCaptureFormat();
462 ASSERT_TRUE(format != NULL);
perkjfa10b552016-10-02 23:45:26 -0700463 EXPECT_EQ(1, format->framerate());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000464}