| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <string> | 5 #include <string> |
| 6 #include <vector> | 6 #include <vector> |
| 7 | 7 |
| 8 #include "base/bind.h" | 8 #include "base/bind.h" |
| 9 #include "base/run_loop.h" | 9 #include "base/run_loop.h" |
| 10 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
| 11 #include "base/strings/utf_string_conversions.h" | 11 #include "base/strings/utf_string_conversions.h" |
| 12 #include "base/test/scoped_feature_list.h" | |
| 13 #include "base/test/scoped_task_environment.h" | 12 #include "base/test/scoped_task_environment.h" |
| 14 #include "build/build_config.h" | 13 #include "build/build_config.h" |
| 15 #include "content/child/child_process.h" | 14 #include "content/child/child_process.h" |
| 16 #include "content/public/common/content_features.h" | |
| 17 #include "content/renderer/media/media_stream_video_source.h" | 15 #include "content/renderer/media/media_stream_video_source.h" |
| 18 #include "content/renderer/media/media_stream_video_track.h" | 16 #include "content/renderer/media/media_stream_video_track.h" |
| 19 #include "content/renderer/media/mock_constraint_factory.h" | 17 #include "content/renderer/media/mock_constraint_factory.h" |
| 20 #include "content/renderer/media/mock_media_stream_video_sink.h" | 18 #include "content/renderer/media/mock_media_stream_video_sink.h" |
| 21 #include "content/renderer/media/mock_media_stream_video_source.h" | 19 #include "content/renderer/media/mock_media_stream_video_source.h" |
| 22 #include "content/renderer/media/video_track_adapter.h" | 20 #include "content/renderer/media/video_track_adapter.h" |
| 23 #include "media/base/limits.h" | 21 #include "media/base/limits.h" |
| 24 #include "media/base/video_frame.h" | 22 #include "media/base/video_frame.h" |
| 25 #include "testing/gtest/include/gtest/gtest.h" | 23 #include "testing/gtest/include/gtest/gtest.h" |
| 26 #include "third_party/WebKit/public/web/WebHeap.h" | 24 #include "third_party/WebKit/public/web/WebHeap.h" |
| (...skipping 16 matching lines...) Expand all Loading... |
| 43 child_process_(new ChildProcess()), | 41 child_process_(new ChildProcess()), |
| 44 number_of_successful_constraints_applied_(0), | 42 number_of_successful_constraints_applied_(0), |
| 45 number_of_failed_constraints_applied_(0), | 43 number_of_failed_constraints_applied_(0), |
| 46 result_(MEDIA_DEVICE_OK), | 44 result_(MEDIA_DEVICE_OK), |
| 47 result_name_(""), | 45 result_name_(""), |
| 48 mock_source_(new MockMediaStreamVideoSource( | 46 mock_source_(new MockMediaStreamVideoSource( |
| 49 media::VideoCaptureFormat(gfx::Size(1280, 720), | 47 media::VideoCaptureFormat(gfx::Size(1280, 720), |
| 50 1000.0, | 48 1000.0, |
| 51 media::PIXEL_FORMAT_I420), | 49 media::PIXEL_FORMAT_I420), |
| 52 false)) { | 50 false)) { |
| 53 scoped_feature_list_.InitAndDisableFeature( | |
| 54 features::kMediaStreamOldVideoConstraints); | |
| 55 | |
| 56 media::VideoCaptureFormats formats; | 51 media::VideoCaptureFormats formats; |
| 57 formats.push_back(media::VideoCaptureFormat(gfx::Size(1280, 720), 30, | 52 formats.push_back(media::VideoCaptureFormat(gfx::Size(1280, 720), 30, |
| 58 media::PIXEL_FORMAT_I420)); | 53 media::PIXEL_FORMAT_I420)); |
| 59 formats.push_back(media::VideoCaptureFormat(gfx::Size(640, 480), 30, | 54 formats.push_back(media::VideoCaptureFormat(gfx::Size(640, 480), 30, |
| 60 media::PIXEL_FORMAT_I420)); | 55 media::PIXEL_FORMAT_I420)); |
| 61 formats.push_back(media::VideoCaptureFormat(gfx::Size(352, 288), 30, | 56 formats.push_back(media::VideoCaptureFormat(gfx::Size(352, 288), 30, |
| 62 media::PIXEL_FORMAT_I420)); | 57 media::PIXEL_FORMAT_I420)); |
| 63 formats.push_back(media::VideoCaptureFormat(gfx::Size(320, 240), 30, | 58 formats.push_back(media::VideoCaptureFormat(gfx::Size(320, 240), 30, |
| 64 media::PIXEL_FORMAT_I420)); | 59 media::PIXEL_FORMAT_I420)); |
| 65 webkit_source_.Initialize(blink::WebString::FromASCII("dummy_source_id"), | 60 webkit_source_.Initialize(blink::WebString::FromASCII("dummy_source_id"), |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 98 base::Bind(&MediaStreamVideoSourceTest::OnConstraintsApplied, | 93 base::Bind(&MediaStreamVideoSourceTest::OnConstraintsApplied, |
| 99 base::Unretained(this)), | 94 base::Unretained(this)), |
| 100 enabled); | 95 enabled); |
| 101 } | 96 } |
| 102 | 97 |
| 103 blink::WebMediaStreamTrack CreateTrackAndStartSource( | 98 blink::WebMediaStreamTrack CreateTrackAndStartSource( |
| 104 int width, | 99 int width, |
| 105 int height, | 100 int height, |
| 106 double frame_rate, | 101 double frame_rate, |
| 107 bool detect_rotation = false) { | 102 bool detect_rotation = false) { |
| 108 DCHECK(!IsOldVideoConstraints()); | |
| 109 blink::WebMediaStreamTrack track = | 103 blink::WebMediaStreamTrack track = |
| 110 CreateTrack("123", | 104 CreateTrack("123", |
| 111 VideoTrackAdapterSettings( | 105 VideoTrackAdapterSettings( |
| 112 width, height, 0.0, HUGE_VAL, frame_rate, | 106 width, height, 0.0, HUGE_VAL, frame_rate, |
| 113 detect_rotation ? gfx::Size(width, height) | 107 detect_rotation ? gfx::Size(width, height) |
| 114 : base::Optional<gfx::Size>()), | 108 : base::Optional<gfx::Size>()), |
| 115 base::Optional<bool>(), false, 0.0); | 109 base::Optional<bool>(), false, 0.0); |
| 116 | 110 |
| 117 EXPECT_EQ(0, NumberOfSuccessConstraintsCallbacks()); | 111 EXPECT_EQ(0, NumberOfSuccessConstraintsCallbacks()); |
| 118 mock_source_->StartMockedSource(); | 112 mock_source_->StartMockedSource(); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 134 blink::WebString error_name() const { return result_name_; } | 128 blink::WebString error_name() const { return result_name_; } |
| 135 | 129 |
| 136 MockMediaStreamVideoSource* mock_source() { return mock_source_; } | 130 MockMediaStreamVideoSource* mock_source() { return mock_source_; } |
| 137 | 131 |
| 138 const blink::WebMediaStreamSource& webkit_source() { return webkit_source_; } | 132 const blink::WebMediaStreamSource& webkit_source() { return webkit_source_; } |
| 139 | 133 |
| 140 void TestSourceCropFrame(int capture_width, | 134 void TestSourceCropFrame(int capture_width, |
| 141 int capture_height, | 135 int capture_height, |
| 142 int expected_width, | 136 int expected_width, |
| 143 int expected_height) { | 137 int expected_height) { |
| 144 DCHECK(!IsOldVideoConstraints()); | |
| 145 // Configure the track to crop to the expected resolution. | 138 // Configure the track to crop to the expected resolution. |
| 146 blink::WebMediaStreamTrack track = | 139 blink::WebMediaStreamTrack track = |
| 147 CreateTrackAndStartSource(expected_width, expected_height, 30.0); | 140 CreateTrackAndStartSource(expected_width, expected_height, 30.0); |
| 148 | 141 |
| 149 // Produce frames at the capture resolution. | 142 // Produce frames at the capture resolution. |
| 150 MockMediaStreamVideoSink sink; | 143 MockMediaStreamVideoSink sink; |
| 151 sink.ConnectToTrack(track); | 144 sink.ConnectToTrack(track); |
| 152 DeliverVideoFrameAndWaitForRenderer(capture_width, capture_height, &sink); | 145 DeliverVideoFrameAndWaitForRenderer(capture_width, capture_height, &sink); |
| 153 EXPECT_EQ(1, sink.number_of_frames()); | 146 EXPECT_EQ(1, sink.number_of_frames()); |
| 154 | 147 |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 261 const base::test::ScopedTaskEnvironment scoped_task_environment_; | 254 const base::test::ScopedTaskEnvironment scoped_task_environment_; |
| 262 const std::unique_ptr<ChildProcess> child_process_; | 255 const std::unique_ptr<ChildProcess> child_process_; |
| 263 blink::WebMediaStreamTrack track_to_release_; | 256 blink::WebMediaStreamTrack track_to_release_; |
| 264 int number_of_successful_constraints_applied_; | 257 int number_of_successful_constraints_applied_; |
| 265 int number_of_failed_constraints_applied_; | 258 int number_of_failed_constraints_applied_; |
| 266 content::MediaStreamRequestResult result_; | 259 content::MediaStreamRequestResult result_; |
| 267 blink::WebString result_name_; | 260 blink::WebString result_name_; |
| 268 blink::WebMediaStreamSource webkit_source_; | 261 blink::WebMediaStreamSource webkit_source_; |
| 269 // |mock_source_| is owned by |webkit_source_|. | 262 // |mock_source_| is owned by |webkit_source_|. |
| 270 MockMediaStreamVideoSource* mock_source_; | 263 MockMediaStreamVideoSource* mock_source_; |
| 271 base::test::ScopedFeatureList scoped_feature_list_; | |
| 272 }; | 264 }; |
| 273 | 265 |
| 274 TEST_F(MediaStreamVideoSourceTest, AddTrackAndStartSource) { | 266 TEST_F(MediaStreamVideoSourceTest, AddTrackAndStartSource) { |
| 275 blink::WebMediaStreamTrack track = CreateTrack("123"); | 267 blink::WebMediaStreamTrack track = CreateTrack("123"); |
| 276 mock_source()->StartMockedSource(); | 268 mock_source()->StartMockedSource(); |
| 277 EXPECT_EQ(1, NumberOfSuccessConstraintsCallbacks()); | 269 EXPECT_EQ(1, NumberOfSuccessConstraintsCallbacks()); |
| 278 } | 270 } |
| 279 | 271 |
| 280 TEST_F(MediaStreamVideoSourceTest, AddTwoTracksBeforeSourceStarts) { | 272 TEST_F(MediaStreamVideoSourceTest, AddTwoTracksBeforeSourceStarts) { |
| 281 blink::WebMediaStreamTrack track1 = CreateTrack("123"); | 273 blink::WebMediaStreamTrack track1 = CreateTrack("123"); |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 411 DeliverVideoFrameAndWaitForRenderer(640, 480, &sink); | 403 DeliverVideoFrameAndWaitForRenderer(640, 480, &sink); |
| 412 run_loop2.Run(); | 404 run_loop2.Run(); |
| 413 | 405 |
| 414 EXPECT_EQ(muted_state, false); | 406 EXPECT_EQ(muted_state, false); |
| 415 EXPECT_EQ(track.Source().GetReadyState(), | 407 EXPECT_EQ(track.Source().GetReadyState(), |
| 416 blink::WebMediaStreamSource::kReadyStateLive); | 408 blink::WebMediaStreamSource::kReadyStateLive); |
| 417 | 409 |
| 418 sink.DisconnectFromTrack(); | 410 sink.DisconnectFromTrack(); |
| 419 } | 411 } |
| 420 | 412 |
| 421 class MediaStreamVideoSourceOldConstraintsTest : public ::testing::Test { | |
| 422 public: | |
| 423 MediaStreamVideoSourceOldConstraintsTest() | |
| 424 : scoped_task_environment_( | |
| 425 base::test::ScopedTaskEnvironment::MainThreadType::UI), | |
| 426 child_process_(new ChildProcess()), | |
| 427 number_of_successful_constraints_applied_(0), | |
| 428 number_of_failed_constraints_applied_(0), | |
| 429 result_(MEDIA_DEVICE_OK), | |
| 430 result_name_(""), | |
| 431 mock_source_(new MockMediaStreamVideoSource(true)) { | |
| 432 scoped_feature_list_.InitAndEnableFeature( | |
| 433 features::kMediaStreamOldVideoConstraints); | |
| 434 | |
| 435 media::VideoCaptureFormats formats; | |
| 436 formats.push_back(media::VideoCaptureFormat( | |
| 437 gfx::Size(1280, 720), 30, media::PIXEL_FORMAT_I420)); | |
| 438 formats.push_back(media::VideoCaptureFormat( | |
| 439 gfx::Size(640, 480), 30, media::PIXEL_FORMAT_I420)); | |
| 440 formats.push_back(media::VideoCaptureFormat( | |
| 441 gfx::Size(352, 288), 30, media::PIXEL_FORMAT_I420)); | |
| 442 formats.push_back(media::VideoCaptureFormat( | |
| 443 gfx::Size(320, 240), 30, media::PIXEL_FORMAT_I420)); | |
| 444 mock_source_->SetSupportedFormats(formats); | |
| 445 webkit_source_.Initialize(blink::WebString::FromASCII("dummy_source_id"), | |
| 446 blink::WebMediaStreamSource::kTypeVideo, | |
| 447 blink::WebString::FromASCII("dummy_source_name"), | |
| 448 false /* remote */); | |
| 449 webkit_source_.SetExtraData(mock_source_); | |
| 450 } | |
| 451 | |
| 452 void TearDown() override { | |
| 453 webkit_source_.Reset(); | |
| 454 blink::WebHeap::CollectAllGarbageForTesting(); | |
| 455 } | |
| 456 | |
| 457 protected: | |
| 458 // Create a track that's associated with |webkit_source_|. | |
| 459 blink::WebMediaStreamTrack CreateTrack( | |
| 460 const std::string& id, | |
| 461 const blink::WebMediaConstraints& constraints) { | |
| 462 bool enabled = true; | |
| 463 return MediaStreamVideoTrack::CreateVideoTrack( | |
| 464 mock_source_, constraints, | |
| 465 base::Bind( | |
| 466 &MediaStreamVideoSourceOldConstraintsTest::OnConstraintsApplied, | |
| 467 base::Unretained(this)), | |
| 468 enabled); | |
| 469 } | |
| 470 | |
| 471 blink::WebMediaStreamTrack CreateTrackAndStartSource( | |
| 472 const blink::WebMediaConstraints& constraints, | |
| 473 int expected_width, | |
| 474 int expected_height, | |
| 475 int expected_frame_rate) { | |
| 476 DCHECK(IsOldVideoConstraints()); | |
| 477 blink::WebMediaStreamTrack track = CreateTrack("123", constraints); | |
| 478 | |
| 479 mock_source_->CompleteGetSupportedFormats(); | |
| 480 const media::VideoCaptureFormat& format = mock_source()->start_format(); | |
| 481 EXPECT_EQ(expected_width, format.frame_size.width()); | |
| 482 EXPECT_EQ(expected_height, format.frame_size.height()); | |
| 483 EXPECT_EQ(expected_frame_rate, format.frame_rate); | |
| 484 | |
| 485 EXPECT_EQ(0, NumberOfSuccessConstraintsCallbacks()); | |
| 486 mock_source_->StartMockedSource(); | |
| 487 // Once the source has started successfully we expect that the | |
| 488 // ConstraintsCallback in MediaStreamSource::AddTrack completes. | |
| 489 EXPECT_EQ(1, NumberOfSuccessConstraintsCallbacks()); | |
| 490 return track; | |
| 491 } | |
| 492 | |
| 493 int NumberOfSuccessConstraintsCallbacks() const { | |
| 494 return number_of_successful_constraints_applied_; | |
| 495 } | |
| 496 | |
| 497 int NumberOfFailedConstraintsCallbacks() const { | |
| 498 return number_of_failed_constraints_applied_; | |
| 499 } | |
| 500 | |
| 501 content::MediaStreamRequestResult error_type() const { return result_; } | |
| 502 blink::WebString error_name() const { return result_name_; } | |
| 503 | |
| 504 MockMediaStreamVideoSource* mock_source() { return mock_source_; } | |
| 505 | |
| 506 const blink::WebMediaStreamSource& webkit_source() { return webkit_source_; } | |
| 507 | |
| 508 // Test that the source crops/scales to the requested width and | |
| 509 // height even though the camera delivers a larger frame. | |
| 510 void TestSourceCropFrame(int capture_width, | |
| 511 int capture_height, | |
| 512 const blink::WebMediaConstraints& constraints, | |
| 513 int expected_width, | |
| 514 int expected_height) { | |
| 515 DCHECK(IsOldVideoConstraints()); | |
| 516 // Expect the source to start capture with the supported resolution. | |
| 517 blink::WebMediaStreamTrack track = CreateTrackAndStartSource( | |
| 518 constraints, capture_width, capture_height, 30); | |
| 519 | |
| 520 MockMediaStreamVideoSink sink; | |
| 521 sink.ConnectToTrack(track); | |
| 522 DeliverVideoFrameAndWaitForRenderer(capture_width, capture_height, &sink); | |
| 523 EXPECT_EQ(1, sink.number_of_frames()); | |
| 524 | |
| 525 // Expect the delivered frame to be cropped. | |
| 526 EXPECT_EQ(expected_height, sink.frame_size().height()); | |
| 527 EXPECT_EQ(expected_width, sink.frame_size().width()); | |
| 528 sink.DisconnectFromTrack(); | |
| 529 } | |
| 530 | |
| 531 void DeliverVideoFrameAndWaitForRenderer(int width, int height, | |
| 532 MockMediaStreamVideoSink* sink) { | |
| 533 base::RunLoop run_loop; | |
| 534 base::Closure quit_closure = run_loop.QuitClosure(); | |
| 535 EXPECT_CALL(*sink, OnVideoFrame()).WillOnce( | |
| 536 RunClosure(quit_closure)); | |
| 537 scoped_refptr<media::VideoFrame> frame = | |
| 538 media::VideoFrame::CreateBlackFrame(gfx::Size(width, height)); | |
| 539 mock_source()->DeliverVideoFrame(frame); | |
| 540 run_loop.Run(); | |
| 541 } | |
| 542 | |
| 543 void DeliverVideoFrameAndWaitForTwoRenderers( | |
| 544 int width, | |
| 545 int height, | |
| 546 MockMediaStreamVideoSink* sink1, | |
| 547 MockMediaStreamVideoSink* sink2) { | |
| 548 base::RunLoop run_loop; | |
| 549 base::Closure quit_closure = run_loop.QuitClosure(); | |
| 550 EXPECT_CALL(*sink1, OnVideoFrame()); | |
| 551 EXPECT_CALL(*sink2, OnVideoFrame()).WillOnce( | |
| 552 RunClosure(quit_closure)); | |
| 553 scoped_refptr<media::VideoFrame> frame = | |
| 554 media::VideoFrame::CreateBlackFrame(gfx::Size(width, height)); | |
| 555 mock_source()->DeliverVideoFrame(frame); | |
| 556 run_loop.Run(); | |
| 557 } | |
| 558 | |
| 559 void TestTwoTracksWithDifferentConstraints( | |
| 560 const blink::WebMediaConstraints& constraints1, | |
| 561 const blink::WebMediaConstraints& constraints2, | |
| 562 int capture_width, | |
| 563 int capture_height, | |
| 564 int expected_width1, | |
| 565 int expected_height1, | |
| 566 int expected_width2, | |
| 567 int expected_height2) { | |
| 568 blink::WebMediaStreamTrack track1 = | |
| 569 CreateTrackAndStartSource(constraints1, capture_width, capture_height, | |
| 570 MediaStreamVideoSource::kDefaultFrameRate); | |
| 571 | |
| 572 blink::WebMediaStreamTrack track2 = CreateTrack("dummy", constraints2); | |
| 573 | |
| 574 MockMediaStreamVideoSink sink1; | |
| 575 sink1.ConnectToTrack(track1); | |
| 576 EXPECT_EQ(0, sink1.number_of_frames()); | |
| 577 | |
| 578 MockMediaStreamVideoSink sink2; | |
| 579 sink2.ConnectToTrack(track2); | |
| 580 EXPECT_EQ(0, sink2.number_of_frames()); | |
| 581 | |
| 582 DeliverVideoFrameAndWaitForTwoRenderers(capture_width, | |
| 583 capture_height, | |
| 584 &sink1, | |
| 585 &sink2); | |
| 586 | |
| 587 EXPECT_EQ(1, sink1.number_of_frames()); | |
| 588 EXPECT_EQ(expected_width1, sink1.frame_size().width()); | |
| 589 EXPECT_EQ(expected_height1, sink1.frame_size().height()); | |
| 590 | |
| 591 EXPECT_EQ(1, sink2.number_of_frames()); | |
| 592 EXPECT_EQ(expected_width2, sink2.frame_size().width()); | |
| 593 EXPECT_EQ(expected_height2, sink2.frame_size().height()); | |
| 594 | |
| 595 sink1.DisconnectFromTrack(); | |
| 596 sink2.DisconnectFromTrack(); | |
| 597 } | |
| 598 | |
| 599 void SetSourceSupportedFormats(const media::VideoCaptureFormats& formats) { | |
| 600 mock_source_->SetSupportedFormats(formats); | |
| 601 } | |
| 602 | |
| 603 void ReleaseTrackAndSourceOnAddTrackCallback( | |
| 604 const blink::WebMediaStreamTrack& track_to_release) { | |
| 605 track_to_release_ = track_to_release; | |
| 606 } | |
| 607 | |
| 608 private: | |
| 609 void OnConstraintsApplied(MediaStreamSource* source, | |
| 610 MediaStreamRequestResult result, | |
| 611 const blink::WebString& result_name) { | |
| 612 ASSERT_EQ(source, webkit_source().GetExtraData()); | |
| 613 | |
| 614 if (result == MEDIA_DEVICE_OK) { | |
| 615 ++number_of_successful_constraints_applied_; | |
| 616 } else { | |
| 617 result_ = result; | |
| 618 result_name_ = result_name; | |
| 619 ++number_of_failed_constraints_applied_; | |
| 620 } | |
| 621 | |
| 622 if (!track_to_release_.IsNull()) { | |
| 623 mock_source_ = nullptr; | |
| 624 webkit_source_.Reset(); | |
| 625 track_to_release_.Reset(); | |
| 626 } | |
| 627 } | |
| 628 const base::test::ScopedTaskEnvironment scoped_task_environment_; | |
| 629 const std::unique_ptr<ChildProcess> child_process_; | |
| 630 blink::WebMediaStreamTrack track_to_release_; | |
| 631 int number_of_successful_constraints_applied_; | |
| 632 int number_of_failed_constraints_applied_; | |
| 633 content::MediaStreamRequestResult result_; | |
| 634 blink::WebString result_name_; | |
| 635 blink::WebMediaStreamSource webkit_source_; | |
| 636 // |mock_source_| is owned by |webkit_source_|. | |
| 637 MockMediaStreamVideoSource* mock_source_; | |
| 638 base::test::ScopedFeatureList scoped_feature_list_; | |
| 639 }; | |
| 640 | |
| 641 // TODO(guidou): Remove this test. http://crbug.com/706408 | |
| 642 TEST_F(MediaStreamVideoSourceOldConstraintsTest, AddTrackAndStartSource) { | |
| 643 blink::WebMediaConstraints constraints; | |
| 644 constraints.Initialize(); | |
| 645 blink::WebMediaStreamTrack track = CreateTrack("123", constraints); | |
| 646 mock_source()->CompleteGetSupportedFormats(); | |
| 647 mock_source()->StartMockedSource(); | |
| 648 EXPECT_EQ(1, NumberOfSuccessConstraintsCallbacks()); | |
| 649 } | |
| 650 | |
| 651 // TODO(guidou): Remove this test. http://crbug.com/706408 | |
| 652 TEST_F(MediaStreamVideoSourceOldConstraintsTest, | |
| 653 AddTwoTracksBeforeSourceStarts) { | |
| 654 blink::WebMediaConstraints constraints; | |
| 655 constraints.Initialize(); | |
| 656 blink::WebMediaStreamTrack track1 = CreateTrack("123", constraints); | |
| 657 mock_source()->CompleteGetSupportedFormats(); | |
| 658 blink::WebMediaStreamTrack track2 = CreateTrack("123", constraints); | |
| 659 EXPECT_EQ(0, NumberOfSuccessConstraintsCallbacks()); | |
| 660 mock_source()->StartMockedSource(); | |
| 661 EXPECT_EQ(2, NumberOfSuccessConstraintsCallbacks()); | |
| 662 } | |
| 663 | |
| 664 // TODO(guidou): Remove this test. http://crbug.com/706408 | |
| 665 TEST_F(MediaStreamVideoSourceOldConstraintsTest, AddTrackAfterSourceStarts) { | |
| 666 blink::WebMediaConstraints constraints; | |
| 667 constraints.Initialize(); | |
| 668 blink::WebMediaStreamTrack track1 = CreateTrack("123", constraints); | |
| 669 mock_source()->CompleteGetSupportedFormats(); | |
| 670 mock_source()->StartMockedSource(); | |
| 671 EXPECT_EQ(1, NumberOfSuccessConstraintsCallbacks()); | |
| 672 blink::WebMediaStreamTrack track2 = CreateTrack("123", constraints); | |
| 673 EXPECT_EQ(2, NumberOfSuccessConstraintsCallbacks()); | |
| 674 } | |
| 675 | |
| 676 // TODO(guidou): Remove this test. http://crbug.com/706408 | |
| 677 TEST_F(MediaStreamVideoSourceOldConstraintsTest, AddTrackAndFailToStartSource) { | |
| 678 blink::WebMediaConstraints constraints; | |
| 679 constraints.Initialize(); | |
| 680 blink::WebMediaStreamTrack track = CreateTrack("123", constraints); | |
| 681 mock_source()->CompleteGetSupportedFormats(); | |
| 682 mock_source()->FailToStartMockedSource(); | |
| 683 EXPECT_EQ(1, NumberOfFailedConstraintsCallbacks()); | |
| 684 } | |
| 685 | |
| 686 // Does not apply with spec-compliant constraints. | |
| 687 // TODO(guidou): Remove this test. http://crbug.com/706408 | |
| 688 TEST_F(MediaStreamVideoSourceOldConstraintsTest, | |
| 689 AddTwoTracksBeforeGetSupportedFormats) { | |
| 690 blink::WebMediaConstraints constraints; | |
| 691 constraints.Initialize(); | |
| 692 blink::WebMediaStreamTrack track1 = CreateTrack("123", constraints); | |
| 693 blink::WebMediaStreamTrack track2 = CreateTrack("123", constraints); | |
| 694 mock_source()->CompleteGetSupportedFormats(); | |
| 695 mock_source()->StartMockedSource(); | |
| 696 EXPECT_EQ(2, NumberOfSuccessConstraintsCallbacks()); | |
| 697 } | |
| 698 | |
| 699 // Test that the capture output is CIF if we set max constraints to CIF. | |
| 700 // and the capture device support CIF. | |
| 701 // Does not apply with spec-compliant constraints. | |
| 702 // TODO(guidou): Remove this test. http://crbug.com/706408 | |
| 703 TEST_F(MediaStreamVideoSourceOldConstraintsTest, MandatoryConstraintCif5Fps) { | |
| 704 MockConstraintFactory factory; | |
| 705 factory.basic().width.SetMax(352); | |
| 706 factory.basic().height.SetMax(288); | |
| 707 factory.basic().frame_rate.SetMax(5.0); | |
| 708 | |
| 709 CreateTrackAndStartSource(factory.CreateWebMediaConstraints(), 352, 288, 5); | |
| 710 } | |
| 711 | |
| 712 // Test that the capture output is 720P if the camera support it and the | |
| 713 // optional constraint is set to 720P. | |
| 714 // Does not apply with spec-compliant constraints. | |
| 715 // TODO(guidou): Remove this test. http://crbug.com/706408 | |
| 716 TEST_F(MediaStreamVideoSourceOldConstraintsTest, MandatoryMinVgaOptional720P) { | |
| 717 MockConstraintFactory factory; | |
| 718 factory.basic().width.SetMin(640); | |
| 719 factory.basic().height.SetMin(480); | |
| 720 factory.AddAdvanced().width.SetMin(1280); | |
| 721 factory.AddAdvanced().aspect_ratio.SetMin(1280.0 / 720); | |
| 722 | |
| 723 CreateTrackAndStartSource(factory.CreateWebMediaConstraints(), 1280, 720, 30); | |
| 724 } | |
| 725 | |
| 726 // Test that the capture output is 720P if the camera supports it and the | |
| 727 // mandatory constraint is exactly width 1280. | |
| 728 // Does not apply with spec-compliant constraints. | |
| 729 // TODO(guidou): Remove this test. http://crbug.com/706408 | |
| 730 TEST_F(MediaStreamVideoSourceOldConstraintsTest, MandatoryExact720P) { | |
| 731 MockConstraintFactory factory; | |
| 732 factory.basic().width.SetExact(1280); | |
| 733 CreateTrackAndStartSource(factory.CreateWebMediaConstraints(), 1280, 720, 30); | |
| 734 } | |
| 735 | |
| 736 // Test that the capture output have aspect ratio 4:3 if a mandatory constraint | |
| 737 // require it even if an optional constraint request a higher resolution | |
| 738 // that don't have this aspect ratio. | |
| 739 // TODO(guidou): Remove this test. http://crbug.com/706408 | |
| 740 TEST_F(MediaStreamVideoSourceOldConstraintsTest, MandatoryAspectRatio4To3) { | |
| 741 MockConstraintFactory factory; | |
| 742 factory.basic().width.SetMin(640); | |
| 743 factory.basic().height.SetMin(480); | |
| 744 factory.basic().aspect_ratio.SetMax(640.0 / 480); | |
| 745 factory.AddAdvanced().width.SetMin(1280); | |
| 746 | |
| 747 TestSourceCropFrame(1280, 720, factory.CreateWebMediaConstraints(), 960, 720); | |
| 748 } | |
| 749 | |
| 750 // Test that AddTrack succeeds if the mandatory min aspect ratio it set to 2. | |
| 751 TEST_F(MediaStreamVideoSourceOldConstraintsTest, MandatoryAspectRatio2) { | |
| 752 MockConstraintFactory factory; | |
| 753 factory.basic().aspect_ratio.SetMin(2.0); | |
| 754 | |
| 755 TestSourceCropFrame(MediaStreamVideoSource::kDefaultWidth, | |
| 756 MediaStreamVideoSource::kDefaultHeight, | |
| 757 factory.CreateWebMediaConstraints(), 640, 320); | |
| 758 } | |
| 759 | |
| 760 // Does not apply with spec-compliant constraints. | |
| 761 // TODO(guidou): Remove this test. http://crbug.com/706408 | |
| 762 TEST_F(MediaStreamVideoSourceOldConstraintsTest, | |
| 763 MinAspectRatioLargerThanMaxAspectRatio) { | |
| 764 MockConstraintFactory factory; | |
| 765 factory.basic().aspect_ratio.SetMin(2.0); | |
| 766 factory.basic().aspect_ratio.SetMax(1.0); | |
| 767 blink::WebMediaStreamTrack track = | |
| 768 CreateTrack("123", factory.CreateWebMediaConstraints()); | |
| 769 mock_source()->CompleteGetSupportedFormats(); | |
| 770 EXPECT_EQ(1, NumberOfFailedConstraintsCallbacks()); | |
| 771 } | |
| 772 | |
| 773 // Does not apply with spec-compliant constraints. | |
| 774 // TODO(guidou): Remove this test. http://crbug.com/706408 | |
| 775 TEST_F(MediaStreamVideoSourceOldConstraintsTest, MinWidthLargerThanMaxWidth) { | |
| 776 MockConstraintFactory factory; | |
| 777 factory.basic().width.SetMin(640); | |
| 778 factory.basic().width.SetMax(320); | |
| 779 blink::WebMediaStreamTrack track = | |
| 780 CreateTrack("123", factory.CreateWebMediaConstraints()); | |
| 781 mock_source()->CompleteGetSupportedFormats(); | |
| 782 EXPECT_EQ(1, NumberOfFailedConstraintsCallbacks()); | |
| 783 } | |
| 784 | |
| 785 // Does not apply with spec-compliant constraints. | |
| 786 // TODO(guidou): Remove this test. http://crbug.com/706408 | |
| 787 TEST_F(MediaStreamVideoSourceOldConstraintsTest, MinHeightLargerThanMaxHeight) { | |
| 788 MockConstraintFactory factory; | |
| 789 factory.basic().height.SetMin(480); | |
| 790 factory.basic().height.SetMax(360); | |
| 791 | |
| 792 blink::WebMediaStreamTrack track = | |
| 793 CreateTrack("123", factory.CreateWebMediaConstraints()); | |
| 794 mock_source()->CompleteGetSupportedFormats(); | |
| 795 EXPECT_EQ(1, NumberOfFailedConstraintsCallbacks()); | |
| 796 } | |
| 797 | |
| 798 // Does not apply with spec-compliant constraints. | |
| 799 // TODO(guidou): Remove this test. http://crbug.com/706408 | |
| 800 TEST_F(MediaStreamVideoSourceOldConstraintsTest, | |
| 801 MinFrameRateLargerThanMaxFrameRate) { | |
| 802 MockConstraintFactory factory; | |
| 803 factory.basic().frame_rate.SetMin(25); | |
| 804 factory.basic().frame_rate.SetMax(15); | |
| 805 blink::WebMediaStreamTrack track = | |
| 806 CreateTrack("123", factory.CreateWebMediaConstraints()); | |
| 807 mock_source()->CompleteGetSupportedFormats(); | |
| 808 EXPECT_EQ(1, NumberOfFailedConstraintsCallbacks()); | |
| 809 } | |
| 810 | |
| 811 // Does not apply with spec-compliant constraints. | |
| 812 // TODO(guidou): Remove this test. http://crbug.com/706408 | |
| 813 TEST_F(MediaStreamVideoSourceOldConstraintsTest, ExactWidthNotSupported) { | |
| 814 MockConstraintFactory factory; | |
| 815 factory.basic().width.SetExact(12000); | |
| 816 blink::WebMediaStreamTrack track = | |
| 817 CreateTrack("123", factory.CreateWebMediaConstraints()); | |
| 818 mock_source()->CompleteGetSupportedFormats(); | |
| 819 EXPECT_EQ(1, NumberOfFailedConstraintsCallbacks()); | |
| 820 } | |
| 821 | |
| 822 // Does not apply with spec-compliant constraints. | |
| 823 // TODO(guidou): Remove this test. http://crbug.com/706408 | |
| 824 TEST_F(MediaStreamVideoSourceOldConstraintsTest, MinWidthNotSupported) { | |
| 825 MockConstraintFactory factory; | |
| 826 factory.basic().width.SetMin(12000); | |
| 827 blink::WebMediaStreamTrack track = | |
| 828 CreateTrack("123", factory.CreateWebMediaConstraints()); | |
| 829 mock_source()->CompleteGetSupportedFormats(); | |
| 830 EXPECT_EQ(1, NumberOfFailedConstraintsCallbacks()); | |
| 831 } | |
| 832 | |
| 833 // Test that its safe to release the last reference of a blink track and the | |
| 834 // source during the callback if adding a track succeeds. | |
| 835 // TODO(guidou): Remove this test. http://crbug.com/706408 | |
| 836 TEST_F(MediaStreamVideoSourceOldConstraintsTest, | |
| 837 ReleaseTrackAndSourceOnSuccessCallBack) { | |
| 838 MockConstraintFactory factory; | |
| 839 blink::WebMediaStreamTrack track = | |
| 840 CreateTrack("123", factory.CreateWebMediaConstraints()); | |
| 841 ReleaseTrackAndSourceOnAddTrackCallback(track); | |
| 842 mock_source()->CompleteGetSupportedFormats(); | |
| 843 mock_source()->StartMockedSource(); | |
| 844 EXPECT_EQ(1, NumberOfSuccessConstraintsCallbacks()); | |
| 845 } | |
| 846 | |
| 847 // Test that its safe to release the last reference of a blink track and the | |
| 848 // source during the callback if adding a track fails. | |
| 849 // Does not apply with spec-compliant constraints. | |
| 850 // TODO(guidou): Remove this test. http://crbug.com/706408 | |
| 851 TEST_F(MediaStreamVideoSourceOldConstraintsTest, | |
| 852 ReleaseTrackAndSourceOnFailureCallBack) { | |
| 853 MockConstraintFactory factory; | |
| 854 factory.basic().width.SetMin(99999); | |
| 855 { | |
| 856 blink::WebMediaStreamTrack track = | |
| 857 CreateTrack("123", factory.CreateWebMediaConstraints()); | |
| 858 ReleaseTrackAndSourceOnAddTrackCallback(track); | |
| 859 } | |
| 860 mock_source()->CompleteGetSupportedFormats(); | |
| 861 EXPECT_EQ(1, NumberOfFailedConstraintsCallbacks()); | |
| 862 } | |
| 863 | |
| 864 // Test that the source ignores an optional aspect ratio that is higher than | |
| 865 // supported. | |
| 866 // Does not apply with spec-compliant constraints. | |
| 867 // TODO(guidou): Remove this test. http://crbug.com/706408 | |
| 868 TEST_F(MediaStreamVideoSourceOldConstraintsTest, OptionalAspectRatioTooHigh) { | |
| 869 MockConstraintFactory factory; | |
| 870 factory.AddAdvanced().aspect_ratio.SetMin(2.0); | |
| 871 blink::WebMediaStreamTrack track = | |
| 872 CreateTrack("123", factory.CreateWebMediaConstraints()); | |
| 873 mock_source()->CompleteGetSupportedFormats(); | |
| 874 | |
| 875 const media::VideoCaptureFormat& format = mock_source()->start_format(); | |
| 876 const double aspect_ratio = static_cast<double>(format.frame_size.width()) / | |
| 877 format.frame_size.height(); | |
| 878 EXPECT_LT(aspect_ratio, 2); | |
| 879 } | |
| 880 | |
| 881 // Test that the source starts video with the default resolution if the | |
| 882 // that is the only supported. | |
| 883 // Does not apply with spec-compliant constraints. | |
| 884 // TODO(guidou): Remove this test. http://crbug.com/706408 | |
| 885 TEST_F(MediaStreamVideoSourceOldConstraintsTest, DefaultCapability) { | |
| 886 media::VideoCaptureFormats formats; | |
| 887 formats.push_back(media::VideoCaptureFormat( | |
| 888 gfx::Size(MediaStreamVideoSource::kDefaultWidth, | |
| 889 MediaStreamVideoSource::kDefaultHeight), | |
| 890 MediaStreamVideoSource::kDefaultFrameRate, media::PIXEL_FORMAT_I420)); | |
| 891 mock_source()->SetSupportedFormats(formats); | |
| 892 | |
| 893 blink::WebMediaConstraints constraints; | |
| 894 constraints.Initialize(); | |
| 895 CreateTrackAndStartSource(constraints, MediaStreamVideoSource::kDefaultWidth, | |
| 896 MediaStreamVideoSource::kDefaultHeight, 30); | |
| 897 } | |
| 898 | |
| 899 // Does not apply with spec-compliant constraints. | |
| 900 // TODO(guidou): Remove this test. http://crbug.com/706408 | |
| 901 TEST_F(MediaStreamVideoSourceOldConstraintsTest, InvalidMandatoryConstraint) { | |
| 902 MockConstraintFactory factory; | |
| 903 // Use a constraint that is only known for audio. | |
| 904 factory.basic().echo_cancellation.SetExact(true); | |
| 905 blink::WebMediaStreamTrack track = | |
| 906 CreateTrack("123", factory.CreateWebMediaConstraints()); | |
| 907 mock_source()->CompleteGetSupportedFormats(); | |
| 908 EXPECT_EQ(MEDIA_DEVICE_CONSTRAINT_NOT_SATISFIED, error_type()); | |
| 909 EXPECT_EQ("echoCancellation", error_name()); | |
| 910 EXPECT_EQ(1, NumberOfFailedConstraintsCallbacks()); | |
| 911 } | |
| 912 | |
| 913 // Test that the source ignores an unknown optional constraint. | |
| 914 // Does not apply with spec-compliant constraints. | |
| 915 // TODO(guidou): Remove this test. http://crbug.com/706408 | |
| 916 TEST_F(MediaStreamVideoSourceOldConstraintsTest, InvalidOptionalConstraint) { | |
| 917 MockConstraintFactory factory; | |
| 918 factory.AddAdvanced().echo_cancellation.SetExact(true); | |
| 919 | |
| 920 CreateTrackAndStartSource(factory.CreateWebMediaConstraints(), | |
| 921 MediaStreamVideoSource::kDefaultWidth, | |
| 922 MediaStreamVideoSource::kDefaultHeight, 30); | |
| 923 } | |
| 924 | |
| 925 // Tests that the source starts video with the max width and height set by | |
| 926 // constraints for screencast. | |
| 927 // Does not apply with spec-compliant constraints. | |
| 928 // TODO(guidou): Remove this test. http://crbug.com/706408 | |
| 929 TEST_F(MediaStreamVideoSourceOldConstraintsTest, | |
| 930 ScreencastResolutionWithConstraint) { | |
| 931 media::VideoCaptureFormats formats; | |
| 932 formats.push_back(media::VideoCaptureFormat(gfx::Size(480, 270), 30, | |
| 933 media::PIXEL_FORMAT_I420)); | |
| 934 mock_source()->SetSupportedFormats(formats); | |
| 935 MockConstraintFactory factory; | |
| 936 factory.basic().width.SetMax(480); | |
| 937 factory.basic().height.SetMax(270); | |
| 938 | |
| 939 blink::WebMediaStreamTrack track = CreateTrackAndStartSource( | |
| 940 factory.CreateWebMediaConstraints(), 480, 270, 30); | |
| 941 EXPECT_EQ(480, mock_source()->max_requested_height()); | |
| 942 EXPECT_EQ(270, mock_source()->max_requested_width()); | |
| 943 } | |
| 944 | |
| 945 // Test that optional constraints are applied in order. | |
| 946 // Does not apply with spec-compliant constraints. | |
| 947 // TODO(guidou): Remove this test. http://crbug.com/706408 | |
| 948 TEST_F(MediaStreamVideoSourceOldConstraintsTest, OptionalConstraints) { | |
| 949 MockConstraintFactory factory; | |
| 950 // Min width of 2056 pixels can not be fulfilled. | |
| 951 factory.AddAdvanced().width.SetMin(2056); | |
| 952 factory.AddAdvanced().width.SetMin(641); | |
| 953 // Since min width is set to 641 pixels, max width 640 can not be fulfilled. | |
| 954 factory.AddAdvanced().width.SetMax(640); | |
| 955 CreateTrackAndStartSource(factory.CreateWebMediaConstraints(), 1280, 720, 30); | |
| 956 } | |
| 957 | |
| 958 // Test that the source crops to the requested max width and | |
| 959 // height even though the camera delivers a larger frame. | |
| 960 // Redundant with spec-compliant constraints. | |
| 961 // TODO(guidou): Remove this test. http://crbug.com/706408 | |
| 962 TEST_F(MediaStreamVideoSourceOldConstraintsTest, | |
| 963 DeliverCroppedVideoFrameOptional640360) { | |
| 964 MockConstraintFactory factory; | |
| 965 factory.AddAdvanced().width.SetMax(640); | |
| 966 factory.AddAdvanced().height.SetMax(360); | |
| 967 TestSourceCropFrame(640, 480, factory.CreateWebMediaConstraints(), 640, 360); | |
| 968 } | |
| 969 | |
| 970 // Redundant with spec-compliant constraints. | |
| 971 // TODO(guidou): Remove this test. http://crbug.com/706408 | |
| 972 TEST_F(MediaStreamVideoSourceOldConstraintsTest, | |
| 973 DeliverCroppedVideoFrameMandatory640360) { | |
| 974 MockConstraintFactory factory; | |
| 975 factory.basic().width.SetMax(640); | |
| 976 factory.basic().height.SetMax(360); | |
| 977 TestSourceCropFrame(640, 480, factory.CreateWebMediaConstraints(), 640, 360); | |
| 978 } | |
| 979 | |
| 980 // Redundant with spec-compliant constraints. | |
| 981 // TODO(guidou): Remove this test. http://crbug.com/706408 | |
| 982 TEST_F(MediaStreamVideoSourceOldConstraintsTest, | |
| 983 DeliverCroppedVideoFrameMandatory732489) { | |
| 984 MockConstraintFactory factory; | |
| 985 factory.basic().width.SetMax(732); | |
| 986 factory.basic().height.SetMax(489); | |
| 987 factory.basic().width.SetMin(732); | |
| 988 factory.basic().height.SetMin(489); | |
| 989 TestSourceCropFrame(1280, 720, factory.CreateWebMediaConstraints(), 732, 489); | |
| 990 } | |
| 991 | |
| 992 // Test that the source crops to the requested max width and | |
| 993 // height even though the requested frame has odd size. | |
| 994 // Redundant with spec-compliant constraints. | |
| 995 // TODO(guidou): Remove this test. http://crbug.com/706408 | |
| 996 TEST_F(MediaStreamVideoSourceOldConstraintsTest, | |
| 997 DeliverCroppedVideoFrame637359) { | |
| 998 MockConstraintFactory factory; | |
| 999 factory.AddAdvanced().width.SetMax(637); | |
| 1000 factory.AddAdvanced().height.SetMax(359); | |
| 1001 TestSourceCropFrame(640, 480, factory.CreateWebMediaConstraints(), 637, 359); | |
| 1002 } | |
| 1003 | |
| 1004 // Redundant with spec-compliant constraints. | |
| 1005 // TODO(guidou): Remove this test. http://crbug.com/706408 | |
| 1006 TEST_F(MediaStreamVideoSourceOldConstraintsTest, | |
| 1007 DeliverCroppedVideoFrame320320) { | |
| 1008 MockConstraintFactory factory; | |
| 1009 factory.basic().width.SetMax(320); | |
| 1010 factory.basic().height.SetMax(320); | |
| 1011 factory.basic().height.SetMin(320); | |
| 1012 factory.basic().width.SetMax(320); | |
| 1013 TestSourceCropFrame(640, 480, factory.CreateWebMediaConstraints(), 320, 320); | |
| 1014 } | |
| 1015 | |
| 1016 // Redundant with spec-compliant constraints. | |
| 1017 // TODO(guidou): Remove this test. http://crbug.com/706408 | |
| 1018 TEST_F(MediaStreamVideoSourceOldConstraintsTest, | |
| 1019 DeliverSmallerSizeWhenTooLargeMax) { | |
| 1020 MockConstraintFactory factory; | |
| 1021 factory.AddAdvanced().width.SetMax(1920); | |
| 1022 factory.AddAdvanced().height.SetMax(1080); | |
| 1023 factory.AddAdvanced().width.SetMin(1280); | |
| 1024 factory.AddAdvanced().height.SetMin(720); | |
| 1025 TestSourceCropFrame(1280, 720, factory.CreateWebMediaConstraints(), 1280, | |
| 1026 720); | |
| 1027 } | |
| 1028 | |
| 1029 // TODO(guidou): Remove this test. http://crbug.com/706408 | |
| 1030 TEST_F(MediaStreamVideoSourceOldConstraintsTest, TwoTracksWithVGAAndWVGA) { | |
| 1031 MockConstraintFactory factory1; | |
| 1032 factory1.AddAdvanced().width.SetMax(640); | |
| 1033 factory1.AddAdvanced().height.SetMax(480); | |
| 1034 | |
| 1035 MockConstraintFactory factory2; | |
| 1036 factory2.AddAdvanced().height.SetMax(360); | |
| 1037 | |
| 1038 TestTwoTracksWithDifferentConstraints(factory1.CreateWebMediaConstraints(), | |
| 1039 factory2.CreateWebMediaConstraints(), | |
| 1040 640, 480, 640, 480, 640, 360); | |
| 1041 } | |
| 1042 | |
| 1043 // Redundant with spec-compliant constraints | |
| 1044 // TODO(guidou): Remove this test. http://crbug.com/706408 | |
| 1045 TEST_F(MediaStreamVideoSourceOldConstraintsTest, TwoTracksWith720AndWVGA) { | |
| 1046 MockConstraintFactory factory1; | |
| 1047 factory1.AddAdvanced().width.SetMin(1280); | |
| 1048 factory1.AddAdvanced().height.SetMin(720); | |
| 1049 | |
| 1050 MockConstraintFactory factory2; | |
| 1051 factory2.basic().width.SetMax(640); | |
| 1052 factory2.basic().height.SetMax(360); | |
| 1053 | |
| 1054 TestTwoTracksWithDifferentConstraints(factory1.CreateWebMediaConstraints(), | |
| 1055 factory2.CreateWebMediaConstraints(), | |
| 1056 1280, 720, 1280, 720, 640, 360); | |
| 1057 } | |
| 1058 | |
| 1059 // Redundant with spec-compliant constraints | |
| 1060 // TODO(guidou): Remove this test. http://crbug.com/706408 | |
| 1061 TEST_F(MediaStreamVideoSourceOldConstraintsTest, TwoTracksWith720AndW700H700) { | |
| 1062 MockConstraintFactory factory1; | |
| 1063 factory1.AddAdvanced().width.SetMin(1280); | |
| 1064 factory1.AddAdvanced().height.SetMin(720); | |
| 1065 | |
| 1066 MockConstraintFactory factory2; | |
| 1067 factory2.basic().width.SetMax(700); | |
| 1068 factory2.basic().height.SetMax(700); | |
| 1069 | |
| 1070 TestTwoTracksWithDifferentConstraints(factory1.CreateWebMediaConstraints(), | |
| 1071 factory2.CreateWebMediaConstraints(), | |
| 1072 1280, 720, 1280, 720, 700, 700); | |
| 1073 } | |
| 1074 | |
| 1075 // Redundant with spec-compliant constraints | |
| 1076 // TODO(guidou): Remove this test. http://crbug.com/706408 | |
| 1077 TEST_F(MediaStreamVideoSourceOldConstraintsTest, | |
| 1078 TwoTracksWith720AndMaxAspectRatio4To3) { | |
| 1079 MockConstraintFactory factory1; | |
| 1080 factory1.AddAdvanced().width.SetMin(1280); | |
| 1081 factory1.AddAdvanced().height.SetMin(720); | |
| 1082 | |
| 1083 MockConstraintFactory factory2; | |
| 1084 factory2.basic().aspect_ratio.SetMax(640.0 / 480); | |
| 1085 | |
| 1086 TestTwoTracksWithDifferentConstraints(factory1.CreateWebMediaConstraints(), | |
| 1087 factory2.CreateWebMediaConstraints(), | |
| 1088 1280, 720, 1280, 720, 960, 720); | |
| 1089 } | |
| 1090 | |
| 1091 // Redundant with spec-compliant constraints | |
| 1092 // TODO(guidou): Remove this test. http://crbug.com/706408 | |
| 1093 TEST_F(MediaStreamVideoSourceOldConstraintsTest, | |
| 1094 TwoTracksWithVgaAndMinAspectRatio) { | |
| 1095 MockConstraintFactory factory1; | |
| 1096 factory1.AddAdvanced().width.SetMax(640); | |
| 1097 factory1.AddAdvanced().height.SetMax(480); | |
| 1098 | |
| 1099 MockConstraintFactory factory2; | |
| 1100 factory2.basic().aspect_ratio.SetMin(640.0 / 360); | |
| 1101 | |
| 1102 TestTwoTracksWithDifferentConstraints(factory1.CreateWebMediaConstraints(), | |
| 1103 factory2.CreateWebMediaConstraints(), | |
| 1104 640, 480, 640, 480, 640, 360); | |
| 1105 } | |
| 1106 | |
| 1107 // Does not apply with spec-compliant constraints | |
| 1108 // TODO(guidou): Remove this test. http://crbug.com/706408 | |
| 1109 TEST_F(MediaStreamVideoSourceOldConstraintsTest, | |
| 1110 TwoTracksWithSecondTrackFrameRateHigherThanFirst) { | |
| 1111 MockConstraintFactory factory1; | |
| 1112 factory1.basic().frame_rate.SetMin(15); | |
| 1113 factory1.basic().frame_rate.SetMax(15); | |
| 1114 | |
| 1115 blink::WebMediaStreamTrack track1 = | |
| 1116 CreateTrackAndStartSource(factory1.CreateWebMediaConstraints(), | |
| 1117 MediaStreamVideoSource::kDefaultWidth, | |
| 1118 MediaStreamVideoSource::kDefaultHeight, 15); | |
| 1119 | |
| 1120 MockConstraintFactory factory2; | |
| 1121 factory2.basic().frame_rate.SetMin(30); | |
| 1122 blink::WebMediaStreamTrack track2 = | |
| 1123 CreateTrack("123", factory2.CreateWebMediaConstraints()); | |
| 1124 EXPECT_EQ(1, NumberOfFailedConstraintsCallbacks()); | |
| 1125 } | |
| 1126 | |
| 1127 // Test that a source can change the frame resolution on the fly and that | |
| 1128 // tracks sinks get the new frame size unless constraints force the frame to be | |
| 1129 // cropped. | |
| 1130 // TODO(guidou): Remove this test. http://crbug.com/706408 | |
| 1131 TEST_F(MediaStreamVideoSourceOldConstraintsTest, SourceChangeFrameSize) { | |
| 1132 MockConstraintFactory factory; | |
| 1133 factory.AddAdvanced().width.SetMax(800); | |
| 1134 factory.AddAdvanced().height.SetMax(700); | |
| 1135 | |
| 1136 // Expect the source to start capture with the supported resolution. | |
| 1137 // Disable frame-rate adjustment in spec-compliant mode to ensure no frames | |
| 1138 // are dropped. | |
| 1139 blink::WebMediaStreamTrack track = CreateTrackAndStartSource( | |
| 1140 factory.CreateWebMediaConstraints(), 640, 480, 30); | |
| 1141 | |
| 1142 MockMediaStreamVideoSink sink; | |
| 1143 sink.ConnectToTrack(track); | |
| 1144 EXPECT_EQ(0, sink.number_of_frames()); | |
| 1145 DeliverVideoFrameAndWaitForRenderer(320, 240, &sink); | |
| 1146 EXPECT_EQ(1, sink.number_of_frames()); | |
| 1147 // Expect the delivered frame to be passed unchanged since its smaller than | |
| 1148 // max requested. | |
| 1149 EXPECT_EQ(320, sink.frame_size().width()); | |
| 1150 EXPECT_EQ(240, sink.frame_size().height()); | |
| 1151 | |
| 1152 DeliverVideoFrameAndWaitForRenderer(640, 480, &sink); | |
| 1153 EXPECT_EQ(2, sink.number_of_frames()); | |
| 1154 // Expect the delivered frame to be passed unchanged since its smaller than | |
| 1155 // max requested. | |
| 1156 EXPECT_EQ(640, sink.frame_size().width()); | |
| 1157 EXPECT_EQ(480, sink.frame_size().height()); | |
| 1158 | |
| 1159 DeliverVideoFrameAndWaitForRenderer(1280, 720, &sink); | |
| 1160 EXPECT_EQ(3, sink.number_of_frames()); | |
| 1161 // Expect a frame to be cropped since its larger than max requested. | |
| 1162 EXPECT_EQ(800, sink.frame_size().width()); | |
| 1163 EXPECT_EQ(700, sink.frame_size().height()); | |
| 1164 | |
| 1165 sink.DisconnectFromTrack(); | |
| 1166 } | |
| 1167 | |
| 1168 // Test that the constraint negotiation can handle 0.0 fps as frame rate. | |
| 1169 TEST_F(MediaStreamVideoSourceOldConstraintsTest, Use0FpsSupportedFormat) { | |
| 1170 media::VideoCaptureFormats formats; | |
| 1171 formats.push_back(media::VideoCaptureFormat(gfx::Size(640, 480), 0.0f, | |
| 1172 media::PIXEL_FORMAT_I420)); | |
| 1173 formats.push_back(media::VideoCaptureFormat(gfx::Size(320, 240), 0.0f, | |
| 1174 media::PIXEL_FORMAT_I420)); | |
| 1175 mock_source()->SetSupportedFormats(formats); | |
| 1176 | |
| 1177 blink::WebMediaConstraints constraints; | |
| 1178 constraints.Initialize(); | |
| 1179 blink::WebMediaStreamTrack track = CreateTrack("123", constraints); | |
| 1180 mock_source()->CompleteGetSupportedFormats(); | |
| 1181 mock_source()->StartMockedSource(); | |
| 1182 EXPECT_EQ(1, NumberOfSuccessConstraintsCallbacks()); | |
| 1183 | |
| 1184 MockMediaStreamVideoSink sink; | |
| 1185 sink.ConnectToTrack(track); | |
| 1186 EXPECT_EQ(0, sink.number_of_frames()); | |
| 1187 DeliverVideoFrameAndWaitForRenderer(320, 240, &sink); | |
| 1188 EXPECT_EQ(1, sink.number_of_frames()); | |
| 1189 // Expect the delivered frame to be passed unchanged since its smaller than | |
| 1190 // max requested. | |
| 1191 EXPECT_EQ(320, sink.frame_size().width()); | |
| 1192 EXPECT_EQ(240, sink.frame_size().height()); | |
| 1193 sink.DisconnectFromTrack(); | |
| 1194 } | |
| 1195 | |
| 1196 // Test that a source producing no frames change the source ReadyState to muted. | |
| 1197 // that in a reasonable time frame the muted state turns to false. | |
| 1198 TEST_F(MediaStreamVideoSourceOldConstraintsTest, MutedSource) { | |
| 1199 // Setup the source for support a frame rate of 999 fps in order to test | |
| 1200 // the muted event faster. This is since the frame monitoring uses | |
| 1201 // PostDelayedTask that is dependent on the source frame rate. | |
| 1202 // Note that media::limits::kMaxFramesPerSecond is 1000. | |
| 1203 media::VideoCaptureFormats formats; | |
| 1204 formats.push_back(media::VideoCaptureFormat( | |
| 1205 gfx::Size(640, 480), media::limits::kMaxFramesPerSecond - 1, | |
| 1206 media::PIXEL_FORMAT_I420)); | |
| 1207 SetSourceSupportedFormats(formats); | |
| 1208 | |
| 1209 MockConstraintFactory factory; | |
| 1210 blink::WebMediaStreamTrack track = | |
| 1211 CreateTrackAndStartSource(factory.CreateWebMediaConstraints(), 640, 480, | |
| 1212 media::limits::kMaxFramesPerSecond - 1); | |
| 1213 | |
| 1214 MockMediaStreamVideoSink sink; | |
| 1215 sink.ConnectToTrack(track); | |
| 1216 EXPECT_EQ(track.Source().GetReadyState(), | |
| 1217 blink::WebMediaStreamSource::kReadyStateLive); | |
| 1218 | |
| 1219 base::RunLoop run_loop; | |
| 1220 base::Closure quit_closure = run_loop.QuitClosure(); | |
| 1221 bool muted_state = false; | |
| 1222 EXPECT_CALL(*mock_source(), DoSetMutedState(_)) | |
| 1223 .WillOnce(DoAll(SaveArg<0>(&muted_state), RunClosure(quit_closure))); | |
| 1224 run_loop.Run(); | |
| 1225 EXPECT_EQ(muted_state, true); | |
| 1226 | |
| 1227 EXPECT_EQ(track.Source().GetReadyState(), | |
| 1228 blink::WebMediaStreamSource::kReadyStateMuted); | |
| 1229 | |
| 1230 base::RunLoop run_loop2; | |
| 1231 base::Closure quit_closure2 = run_loop2.QuitClosure(); | |
| 1232 EXPECT_CALL(*mock_source(), DoSetMutedState(_)) | |
| 1233 .WillOnce(DoAll(SaveArg<0>(&muted_state), RunClosure(quit_closure2))); | |
| 1234 DeliverVideoFrameAndWaitForRenderer(640, 480, &sink); | |
| 1235 run_loop2.Run(); | |
| 1236 | |
| 1237 EXPECT_EQ(muted_state, false); | |
| 1238 EXPECT_EQ(track.Source().GetReadyState(), | |
| 1239 blink::WebMediaStreamSource::kReadyStateLive); | |
| 1240 | |
| 1241 sink.DisconnectFromTrack(); | |
| 1242 } | |
| 1243 | |
| 1244 // Test that an optional constraint with an invalid aspect ratio is ignored. | |
| 1245 TEST_F(MediaStreamVideoSourceOldConstraintsTest, | |
| 1246 InvalidOptionalAspectRatioIgnored) { | |
| 1247 MockConstraintFactory factory; | |
| 1248 factory.AddAdvanced().aspect_ratio.SetMax(0.0); | |
| 1249 blink::WebMediaStreamTrack track = | |
| 1250 CreateTrack("123", factory.CreateWebMediaConstraints()); | |
| 1251 mock_source()->CompleteGetSupportedFormats(); | |
| 1252 EXPECT_EQ(0, NumberOfFailedConstraintsCallbacks()); | |
| 1253 } | |
| 1254 | |
| 1255 // Test that setting an invalid mandatory aspect ratio fails. | |
| 1256 // Does not apply with spec-compliant constraints. | |
| 1257 TEST_F(MediaStreamVideoSourceOldConstraintsTest, | |
| 1258 InvalidMandatoryAspectRatioFails) { | |
| 1259 MockConstraintFactory factory; | |
| 1260 factory.basic().aspect_ratio.SetMax(0.0); | |
| 1261 blink::WebMediaStreamTrack track = | |
| 1262 CreateTrack("123", factory.CreateWebMediaConstraints()); | |
| 1263 mock_source()->CompleteGetSupportedFormats(); | |
| 1264 EXPECT_EQ(1, NumberOfFailedConstraintsCallbacks()); | |
| 1265 } | |
| 1266 | |
| 1267 } // namespace content | 413 } // namespace content |
| OLD | NEW |