| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2012 The WebRTC project authors. All Rights Reserved. | 2 * Copyright 2012 The WebRTC project authors. All Rights Reserved. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license | 4 * 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ | 9 */ |
| 10 | 10 |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 109 protected: | 109 protected: |
| 110 VideoCapturerTrackSourceTest() { InitCapturer(false); } | 110 VideoCapturerTrackSourceTest() { InitCapturer(false); } |
| 111 void InitCapturer(bool is_screencast) { | 111 void InitCapturer(bool is_screencast) { |
| 112 capturer_cleanup_ = std::unique_ptr<TestVideoCapturer>( | 112 capturer_cleanup_ = std::unique_ptr<TestVideoCapturer>( |
| 113 new TestVideoCapturer(is_screencast)); | 113 new TestVideoCapturer(is_screencast)); |
| 114 capturer_ = capturer_cleanup_.get(); | 114 capturer_ = capturer_cleanup_.get(); |
| 115 } | 115 } |
| 116 | 116 |
| 117 void InitScreencast() { InitCapturer(true); } | 117 void InitScreencast() { InitCapturer(true); } |
| 118 | 118 |
| 119 void CreateVideoCapturerSource() { CreateVideoCapturerSource(NULL); } | 119 void CreateVideoCapturerSource() { CreateVideoCapturerSource(nullptr); } |
| 120 | 120 |
| 121 void CreateVideoCapturerSource( | 121 void CreateVideoCapturerSource( |
| 122 const webrtc::MediaConstraintsInterface* constraints) { | 122 const webrtc::MediaConstraintsInterface* constraints) { |
| 123 // VideoSource take ownership of |capturer_| | 123 // VideoSource take ownership of |capturer_| |
| 124 source_ = VideoCapturerTrackSource::Create(rtc::Thread::Current(), | 124 source_ = VideoCapturerTrackSource::Create(rtc::Thread::Current(), |
| 125 capturer_cleanup_.release(), | 125 capturer_cleanup_.release(), |
| 126 constraints, false); | 126 constraints, false); |
| 127 | 127 |
| 128 ASSERT_TRUE(source_.get() != NULL); | 128 ASSERT_TRUE(source_.get() != nullptr); |
| 129 | 129 |
| 130 state_observer_.reset(new StateObserver(source_)); | 130 state_observer_.reset(new StateObserver(source_)); |
| 131 source_->RegisterObserver(state_observer_.get()); | 131 source_->RegisterObserver(state_observer_.get()); |
| 132 source_->AddOrUpdateSink(&renderer_, rtc::VideoSinkWants()); | 132 source_->AddOrUpdateSink(&renderer_, rtc::VideoSinkWants()); |
| 133 } | 133 } |
| 134 | 134 |
| 135 std::unique_ptr<TestVideoCapturer> capturer_cleanup_; | 135 std::unique_ptr<TestVideoCapturer> capturer_cleanup_; |
| 136 TestVideoCapturer* capturer_; | 136 TestVideoCapturer* capturer_; |
| 137 cricket::FakeVideoRenderer renderer_; | 137 cricket::FakeVideoRenderer renderer_; |
| 138 std::unique_ptr<StateObserver> state_observer_; | 138 std::unique_ptr<StateObserver> state_observer_; |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 173 TEST_F(VideoCapturerTrackSourceTest, MandatoryConstraintCif5Fps) { | 173 TEST_F(VideoCapturerTrackSourceTest, MandatoryConstraintCif5Fps) { |
| 174 FakeConstraints constraints; | 174 FakeConstraints constraints; |
| 175 constraints.AddMandatory(MediaConstraintsInterface::kMaxWidth, 352); | 175 constraints.AddMandatory(MediaConstraintsInterface::kMaxWidth, 352); |
| 176 constraints.AddMandatory(MediaConstraintsInterface::kMaxHeight, 288); | 176 constraints.AddMandatory(MediaConstraintsInterface::kMaxHeight, 288); |
| 177 constraints.AddMandatory(MediaConstraintsInterface::kMaxFrameRate, 5); | 177 constraints.AddMandatory(MediaConstraintsInterface::kMaxFrameRate, 5); |
| 178 | 178 |
| 179 CreateVideoCapturerSource(&constraints); | 179 CreateVideoCapturerSource(&constraints); |
| 180 EXPECT_EQ_WAIT(MediaSourceInterface::kLive, state_observer_->state(), | 180 EXPECT_EQ_WAIT(MediaSourceInterface::kLive, state_observer_->state(), |
| 181 kMaxWaitMs); | 181 kMaxWaitMs); |
| 182 const cricket::VideoFormat* format = capturer_->GetCaptureFormat(); | 182 const cricket::VideoFormat* format = capturer_->GetCaptureFormat(); |
| 183 ASSERT_TRUE(format != NULL); | 183 ASSERT_TRUE(format != nullptr); |
| 184 EXPECT_EQ(352, format->width); | 184 EXPECT_EQ(352, format->width); |
| 185 EXPECT_EQ(288, format->height); | 185 EXPECT_EQ(288, format->height); |
| 186 EXPECT_EQ(5, format->framerate()); | 186 EXPECT_EQ(5, format->framerate()); |
| 187 } | 187 } |
| 188 | 188 |
| 189 // Test that the capture output is 720P if the camera support it and the | 189 // Test that the capture output is 720P if the camera support it and the |
| 190 // optional constraint is set to 720P. | 190 // optional constraint is set to 720P. |
| 191 TEST_F(VideoCapturerTrackSourceTest, MandatoryMinVgaOptional720P) { | 191 TEST_F(VideoCapturerTrackSourceTest, MandatoryMinVgaOptional720P) { |
| 192 FakeConstraints constraints; | 192 FakeConstraints constraints; |
| 193 constraints.AddMandatory(MediaConstraintsInterface::kMinWidth, 640); | 193 constraints.AddMandatory(MediaConstraintsInterface::kMinWidth, 640); |
| 194 constraints.AddMandatory(MediaConstraintsInterface::kMinHeight, 480); | 194 constraints.AddMandatory(MediaConstraintsInterface::kMinHeight, 480); |
| 195 constraints.AddOptional(MediaConstraintsInterface::kMinWidth, 1280); | 195 constraints.AddOptional(MediaConstraintsInterface::kMinWidth, 1280); |
| 196 constraints.AddOptional(MediaConstraintsInterface::kMinAspectRatio, | 196 constraints.AddOptional(MediaConstraintsInterface::kMinAspectRatio, |
| 197 1280.0 / 720); | 197 1280.0 / 720); |
| 198 | 198 |
| 199 CreateVideoCapturerSource(&constraints); | 199 CreateVideoCapturerSource(&constraints); |
| 200 EXPECT_EQ_WAIT(MediaSourceInterface::kLive, state_observer_->state(), | 200 EXPECT_EQ_WAIT(MediaSourceInterface::kLive, state_observer_->state(), |
| 201 kMaxWaitMs); | 201 kMaxWaitMs); |
| 202 const cricket::VideoFormat* format = capturer_->GetCaptureFormat(); | 202 const cricket::VideoFormat* format = capturer_->GetCaptureFormat(); |
| 203 ASSERT_TRUE(format != NULL); | 203 ASSERT_TRUE(format != nullptr); |
| 204 EXPECT_EQ(1280, format->width); | 204 EXPECT_EQ(1280, format->width); |
| 205 EXPECT_EQ(720, format->height); | 205 EXPECT_EQ(720, format->height); |
| 206 EXPECT_EQ(30, format->framerate()); | 206 EXPECT_EQ(30, format->framerate()); |
| 207 } | 207 } |
| 208 | 208 |
| 209 // Test that the capture output have aspect ratio 4:3 if a mandatory constraint | 209 // Test that the capture output have aspect ratio 4:3 if a mandatory constraint |
| 210 // require it even if an optional constraint request a higher resolution | 210 // require it even if an optional constraint request a higher resolution |
| 211 // that don't have this aspect ratio. | 211 // that don't have this aspect ratio. |
| 212 TEST_F(VideoCapturerTrackSourceTest, MandatoryAspectRatio4To3) { | 212 TEST_F(VideoCapturerTrackSourceTest, MandatoryAspectRatio4To3) { |
| 213 FakeConstraints constraints; | 213 FakeConstraints constraints; |
| 214 constraints.AddMandatory(MediaConstraintsInterface::kMinWidth, 640); | 214 constraints.AddMandatory(MediaConstraintsInterface::kMinWidth, 640); |
| 215 constraints.AddMandatory(MediaConstraintsInterface::kMinHeight, 480); | 215 constraints.AddMandatory(MediaConstraintsInterface::kMinHeight, 480); |
| 216 constraints.AddMandatory(MediaConstraintsInterface::kMaxAspectRatio, | 216 constraints.AddMandatory(MediaConstraintsInterface::kMaxAspectRatio, |
| 217 640.0 / 480); | 217 640.0 / 480); |
| 218 constraints.AddOptional(MediaConstraintsInterface::kMinWidth, 1280); | 218 constraints.AddOptional(MediaConstraintsInterface::kMinWidth, 1280); |
| 219 | 219 |
| 220 CreateVideoCapturerSource(&constraints); | 220 CreateVideoCapturerSource(&constraints); |
| 221 EXPECT_EQ_WAIT(MediaSourceInterface::kLive, state_observer_->state(), | 221 EXPECT_EQ_WAIT(MediaSourceInterface::kLive, state_observer_->state(), |
| 222 kMaxWaitMs); | 222 kMaxWaitMs); |
| 223 const cricket::VideoFormat* format = capturer_->GetCaptureFormat(); | 223 const cricket::VideoFormat* format = capturer_->GetCaptureFormat(); |
| 224 ASSERT_TRUE(format != NULL); | 224 ASSERT_TRUE(format != nullptr); |
| 225 EXPECT_EQ(640, format->width); | 225 EXPECT_EQ(640, format->width); |
| 226 EXPECT_EQ(480, format->height); | 226 EXPECT_EQ(480, format->height); |
| 227 EXPECT_EQ(30, format->framerate()); | 227 EXPECT_EQ(30, format->framerate()); |
| 228 } | 228 } |
| 229 | 229 |
| 230 // Test that the source state transition to kEnded if the mandatory aspect ratio | 230 // Test that the source state transition to kEnded if the mandatory aspect ratio |
| 231 // is set higher than supported. | 231 // is set higher than supported. |
| 232 TEST_F(VideoCapturerTrackSourceTest, MandatoryAspectRatioTooHigh) { | 232 TEST_F(VideoCapturerTrackSourceTest, MandatoryAspectRatioTooHigh) { |
| 233 FakeConstraints constraints; | 233 FakeConstraints constraints; |
| 234 constraints.AddMandatory(MediaConstraintsInterface::kMinAspectRatio, 2); | 234 constraints.AddMandatory(MediaConstraintsInterface::kMinAspectRatio, 2); |
| 235 CreateVideoCapturerSource(&constraints); | 235 CreateVideoCapturerSource(&constraints); |
| 236 EXPECT_EQ_WAIT(MediaSourceInterface::kEnded, state_observer_->state(), | 236 EXPECT_EQ_WAIT(MediaSourceInterface::kEnded, state_observer_->state(), |
| 237 kMaxWaitMs); | 237 kMaxWaitMs); |
| 238 } | 238 } |
| 239 | 239 |
| 240 // Test that the source ignores an optional aspect ratio that is higher than | 240 // Test that the source ignores an optional aspect ratio that is higher than |
| 241 // supported. | 241 // supported. |
| 242 TEST_F(VideoCapturerTrackSourceTest, OptionalAspectRatioTooHigh) { | 242 TEST_F(VideoCapturerTrackSourceTest, OptionalAspectRatioTooHigh) { |
| 243 FakeConstraints constraints; | 243 FakeConstraints constraints; |
| 244 constraints.AddOptional(MediaConstraintsInterface::kMinAspectRatio, 2); | 244 constraints.AddOptional(MediaConstraintsInterface::kMinAspectRatio, 2); |
| 245 CreateVideoCapturerSource(&constraints); | 245 CreateVideoCapturerSource(&constraints); |
| 246 EXPECT_EQ_WAIT(MediaSourceInterface::kLive, state_observer_->state(), | 246 EXPECT_EQ_WAIT(MediaSourceInterface::kLive, state_observer_->state(), |
| 247 kMaxWaitMs); | 247 kMaxWaitMs); |
| 248 const cricket::VideoFormat* format = capturer_->GetCaptureFormat(); | 248 const cricket::VideoFormat* format = capturer_->GetCaptureFormat(); |
| 249 ASSERT_TRUE(format != NULL); | 249 ASSERT_TRUE(format != nullptr); |
| 250 double aspect_ratio = static_cast<double>(format->width) / format->height; | 250 double aspect_ratio = static_cast<double>(format->width) / format->height; |
| 251 EXPECT_LT(aspect_ratio, 2); | 251 EXPECT_LT(aspect_ratio, 2); |
| 252 } | 252 } |
| 253 | 253 |
| 254 // Test that the source starts video with the default resolution if the | 254 // Test that the source starts video with the default resolution if the |
| 255 // camera doesn't support capability enumeration and there are no constraints. | 255 // camera doesn't support capability enumeration and there are no constraints. |
| 256 TEST_F(VideoCapturerTrackSourceTest, NoCameraCapability) { | 256 TEST_F(VideoCapturerTrackSourceTest, NoCameraCapability) { |
| 257 capturer_->TestWithoutCameraFormats(); | 257 capturer_->TestWithoutCameraFormats(); |
| 258 | 258 |
| 259 CreateVideoCapturerSource(); | 259 CreateVideoCapturerSource(); |
| 260 EXPECT_EQ_WAIT(MediaSourceInterface::kLive, state_observer_->state(), | 260 EXPECT_EQ_WAIT(MediaSourceInterface::kLive, state_observer_->state(), |
| 261 kMaxWaitMs); | 261 kMaxWaitMs); |
| 262 const cricket::VideoFormat* format = capturer_->GetCaptureFormat(); | 262 const cricket::VideoFormat* format = capturer_->GetCaptureFormat(); |
| 263 ASSERT_TRUE(format != NULL); | 263 ASSERT_TRUE(format != nullptr); |
| 264 EXPECT_EQ(640, format->width); | 264 EXPECT_EQ(640, format->width); |
| 265 EXPECT_EQ(480, format->height); | 265 EXPECT_EQ(480, format->height); |
| 266 EXPECT_EQ(30, format->framerate()); | 266 EXPECT_EQ(30, format->framerate()); |
| 267 } | 267 } |
| 268 | 268 |
| 269 // Test that the source can start the video and get the requested aspect ratio | 269 // Test that the source can start the video and get the requested aspect ratio |
| 270 // if the camera doesn't support capability enumeration and the aspect ratio is | 270 // if the camera doesn't support capability enumeration and the aspect ratio is |
| 271 // set. | 271 // set. |
| 272 TEST_F(VideoCapturerTrackSourceTest, NoCameraCapability16To9Ratio) { | 272 TEST_F(VideoCapturerTrackSourceTest, NoCameraCapability16To9Ratio) { |
| 273 capturer_->TestWithoutCameraFormats(); | 273 capturer_->TestWithoutCameraFormats(); |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 390 constraints.AddMandatory(MediaConstraintsInterface::kMaxHeight, 288); | 390 constraints.AddMandatory(MediaConstraintsInterface::kMaxHeight, 288); |
| 391 constraints.AddOptional(MediaConstraintsInterface::kMaxFrameRate, 5); | 391 constraints.AddOptional(MediaConstraintsInterface::kMaxFrameRate, 5); |
| 392 | 392 |
| 393 constraints.AddMandatory(MediaConstraintsInterface::kNoiseReduction, false); | 393 constraints.AddMandatory(MediaConstraintsInterface::kNoiseReduction, false); |
| 394 constraints.AddOptional(MediaConstraintsInterface::kNoiseReduction, true); | 394 constraints.AddOptional(MediaConstraintsInterface::kNoiseReduction, true); |
| 395 | 395 |
| 396 CreateVideoCapturerSource(&constraints); | 396 CreateVideoCapturerSource(&constraints); |
| 397 EXPECT_EQ_WAIT(MediaSourceInterface::kLive, state_observer_->state(), | 397 EXPECT_EQ_WAIT(MediaSourceInterface::kLive, state_observer_->state(), |
| 398 kMaxWaitMs); | 398 kMaxWaitMs); |
| 399 const cricket::VideoFormat* format = capturer_->GetCaptureFormat(); | 399 const cricket::VideoFormat* format = capturer_->GetCaptureFormat(); |
| 400 ASSERT_TRUE(format != NULL); | 400 ASSERT_TRUE(format != nullptr); |
| 401 EXPECT_EQ(352, format->width); | 401 EXPECT_EQ(352, format->width); |
| 402 EXPECT_EQ(288, format->height); | 402 EXPECT_EQ(288, format->height); |
| 403 EXPECT_EQ(5, format->framerate()); | 403 EXPECT_EQ(5, format->framerate()); |
| 404 | 404 |
| 405 EXPECT_EQ(rtc::Optional<bool>(false), source_->needs_denoising()); | 405 EXPECT_EQ(rtc::Optional<bool>(false), source_->needs_denoising()); |
| 406 } | 406 } |
| 407 | 407 |
| 408 // Tests that the source starts video with the default resolution for | 408 // Tests that the source starts video with the default resolution for |
| 409 // screencast if no constraint is set. | 409 // screencast if no constraint is set. |
| 410 TEST_F(VideoCapturerTrackSourceTest, ScreencastResolutionNoConstraint) { | 410 TEST_F(VideoCapturerTrackSourceTest, ScreencastResolutionNoConstraint) { |
| 411 InitScreencast(); | 411 InitScreencast(); |
| 412 capturer_->TestWithoutCameraFormats(); | 412 capturer_->TestWithoutCameraFormats(); |
| 413 | 413 |
| 414 CreateVideoCapturerSource(); | 414 CreateVideoCapturerSource(); |
| 415 ASSERT_TRUE(source_->is_screencast()); | 415 ASSERT_TRUE(source_->is_screencast()); |
| 416 EXPECT_EQ_WAIT(MediaSourceInterface::kLive, state_observer_->state(), | 416 EXPECT_EQ_WAIT(MediaSourceInterface::kLive, state_observer_->state(), |
| 417 kMaxWaitMs); | 417 kMaxWaitMs); |
| 418 const cricket::VideoFormat* format = capturer_->GetCaptureFormat(); | 418 const cricket::VideoFormat* format = capturer_->GetCaptureFormat(); |
| 419 ASSERT_TRUE(format != NULL); | 419 ASSERT_TRUE(format != nullptr); |
| 420 EXPECT_EQ(640, format->width); | 420 EXPECT_EQ(640, format->width); |
| 421 EXPECT_EQ(480, format->height); | 421 EXPECT_EQ(480, format->height); |
| 422 EXPECT_EQ(30, format->framerate()); | 422 EXPECT_EQ(30, format->framerate()); |
| 423 } | 423 } |
| 424 | 424 |
| 425 // Tests that the source starts video with the max width and height set by | 425 // Tests that the source starts video with the max width and height set by |
| 426 // constraints for screencast. | 426 // constraints for screencast. |
| 427 TEST_F(VideoCapturerTrackSourceTest, ScreencastResolutionWithConstraint) { | 427 TEST_F(VideoCapturerTrackSourceTest, ScreencastResolutionWithConstraint) { |
| 428 FakeConstraints constraints; | 428 FakeConstraints constraints; |
| 429 constraints.AddMandatory(MediaConstraintsInterface::kMaxWidth, 480); | 429 constraints.AddMandatory(MediaConstraintsInterface::kMaxWidth, 480); |
| 430 constraints.AddMandatory(MediaConstraintsInterface::kMaxHeight, 270); | 430 constraints.AddMandatory(MediaConstraintsInterface::kMaxHeight, 270); |
| 431 | 431 |
| 432 InitScreencast(); | 432 InitScreencast(); |
| 433 capturer_->TestWithoutCameraFormats(); | 433 capturer_->TestWithoutCameraFormats(); |
| 434 | 434 |
| 435 CreateVideoCapturerSource(&constraints); | 435 CreateVideoCapturerSource(&constraints); |
| 436 ASSERT_TRUE(source_->is_screencast()); | 436 ASSERT_TRUE(source_->is_screencast()); |
| 437 EXPECT_EQ_WAIT(MediaSourceInterface::kLive, state_observer_->state(), | 437 EXPECT_EQ_WAIT(MediaSourceInterface::kLive, state_observer_->state(), |
| 438 kMaxWaitMs); | 438 kMaxWaitMs); |
| 439 const cricket::VideoFormat* format = capturer_->GetCaptureFormat(); | 439 const cricket::VideoFormat* format = capturer_->GetCaptureFormat(); |
| 440 ASSERT_TRUE(format != NULL); | 440 ASSERT_TRUE(format != nullptr); |
| 441 EXPECT_EQ(480, format->width); | 441 EXPECT_EQ(480, format->width); |
| 442 EXPECT_EQ(270, format->height); | 442 EXPECT_EQ(270, format->height); |
| 443 EXPECT_EQ(30, format->framerate()); | 443 EXPECT_EQ(30, format->framerate()); |
| 444 } | 444 } |
| 445 | 445 |
| 446 TEST_F(VideoCapturerTrackSourceTest, MandatorySubOneFpsConstraints) { | 446 TEST_F(VideoCapturerTrackSourceTest, MandatorySubOneFpsConstraints) { |
| 447 FakeConstraints constraints; | 447 FakeConstraints constraints; |
| 448 constraints.AddMandatory(MediaConstraintsInterface::kMaxFrameRate, 0.5); | 448 constraints.AddMandatory(MediaConstraintsInterface::kMaxFrameRate, 0.5); |
| 449 | 449 |
| 450 CreateVideoCapturerSource(&constraints); | 450 CreateVideoCapturerSource(&constraints); |
| 451 EXPECT_EQ_WAIT(MediaSourceInterface::kEnded, state_observer_->state(), | 451 EXPECT_EQ_WAIT(MediaSourceInterface::kEnded, state_observer_->state(), |
| 452 kMaxWaitMs); | 452 kMaxWaitMs); |
| 453 ASSERT_TRUE(capturer_->GetCaptureFormat() == NULL); | 453 ASSERT_TRUE(capturer_->GetCaptureFormat() == nullptr); |
| 454 } | 454 } |
| 455 | 455 |
| 456 TEST_F(VideoCapturerTrackSourceTest, OptionalSubOneFpsConstraints) { | 456 TEST_F(VideoCapturerTrackSourceTest, OptionalSubOneFpsConstraints) { |
| 457 FakeConstraints constraints; | 457 FakeConstraints constraints; |
| 458 constraints.AddOptional(MediaConstraintsInterface::kMaxFrameRate, 0.5); | 458 constraints.AddOptional(MediaConstraintsInterface::kMaxFrameRate, 0.5); |
| 459 | 459 |
| 460 CreateVideoCapturerSource(&constraints); | 460 CreateVideoCapturerSource(&constraints); |
| 461 EXPECT_EQ_WAIT(MediaSourceInterface::kLive, state_observer_->state(), | 461 EXPECT_EQ_WAIT(MediaSourceInterface::kLive, state_observer_->state(), |
| 462 kMaxWaitMs); | 462 kMaxWaitMs); |
| 463 const cricket::VideoFormat* format = capturer_->GetCaptureFormat(); | 463 const cricket::VideoFormat* format = capturer_->GetCaptureFormat(); |
| 464 ASSERT_TRUE(format != NULL); | 464 ASSERT_TRUE(format != nullptr); |
| 465 EXPECT_EQ(1, format->framerate()); | 465 EXPECT_EQ(1, format->framerate()); |
| 466 } | 466 } |
| OLD | NEW |