| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2010 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2010 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 |
| 11 #include <limits.h> // For INT_MAX | 11 #include <limits.h> // For INT_MAX |
| 12 | 12 |
| 13 #include <memory> | 13 #include <memory> |
| 14 #include <string> | 14 #include <string> |
| 15 #include <vector> | 15 #include <vector> |
| 16 | 16 |
| 17 #include "webrtc/base/gunit.h" | 17 #include "webrtc/base/gunit.h" |
| 18 #include "webrtc/base/logging.h" | 18 #include "webrtc/base/logging.h" |
| 19 #include "webrtc/media/base/fakevideocapturer.h" | 19 #include "webrtc/media/base/fakevideocapturer.h" |
| 20 #include "webrtc/media/base/mediachannel.h" | 20 #include "webrtc/media/base/mediachannel.h" |
| 21 #include "webrtc/media/base/testutils.h" | 21 #include "webrtc/media/base/testutils.h" |
| 22 #include "webrtc/media/base/videoadapter.h" | 22 #include "webrtc/media/base/videoadapter.h" |
| 23 | 23 |
| 24 namespace cricket { | 24 namespace cricket { |
| 25 namespace { |
| 26 const int kDefaultFps = 30; |
| 27 } // namespace |
| 25 | 28 |
| 26 class VideoAdapterTest : public testing::Test { | 29 class VideoAdapterTest : public testing::Test { |
| 27 public: | 30 public: |
| 28 virtual void SetUp() { | 31 virtual void SetUp() { |
| 29 capturer_.reset(new FakeVideoCapturer); | 32 capturer_.reset(new FakeVideoCapturer); |
| 30 capture_format_ = capturer_->GetSupportedFormats()->at(0); | 33 capture_format_ = capturer_->GetSupportedFormats()->at(0); |
| 31 capture_format_.interval = VideoFormat::FpsToInterval(30); | 34 capture_format_.interval = VideoFormat::FpsToInterval(kDefaultFps); |
| 32 | 35 |
| 33 listener_.reset(new VideoCapturerListener(&adapter_)); | 36 listener_.reset(new VideoCapturerListener(&adapter_)); |
| 34 capturer_->AddOrUpdateSink(listener_.get(), rtc::VideoSinkWants()); | 37 capturer_->AddOrUpdateSink(listener_.get(), rtc::VideoSinkWants()); |
| 35 } | 38 } |
| 36 | 39 |
| 37 virtual void TearDown() { | 40 virtual void TearDown() { |
| 38 // Explicitly disconnect the VideoCapturer before to avoid data races | 41 // Explicitly disconnect the VideoCapturer before to avoid data races |
| 39 // (frames delivered to VideoCapturerListener while it's being destructed). | 42 // (frames delivered to VideoCapturerListener while it's being destructed). |
| 40 capturer_->RemoveSink(listener_.get()); | 43 capturer_->RemoveSink(listener_.get()); |
| 41 } | 44 } |
| (...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 283 capturer_->CaptureFrame(); | 286 capturer_->CaptureFrame(); |
| 284 | 287 |
| 285 // Verify no frame drop. | 288 // Verify no frame drop. |
| 286 EXPECT_EQ(0, listener_->GetStats().dropped_frames); | 289 EXPECT_EQ(0, listener_->GetStats().dropped_frames); |
| 287 } | 290 } |
| 288 | 291 |
| 289 // After the first timestamp, add a big offset to the timestamps. Expect that | 292 // After the first timestamp, add a big offset to the timestamps. Expect that |
| 290 // the adapter is conservative and resets to the new offset and does not drop | 293 // the adapter is conservative and resets to the new offset and does not drop |
| 291 // any frame. | 294 // any frame. |
| 292 TEST_F(VideoAdapterTest, AdaptFramerateTimestampOffset) { | 295 TEST_F(VideoAdapterTest, AdaptFramerateTimestampOffset) { |
| 293 const int64_t capture_interval = VideoFormat::FpsToInterval(30); | 296 const int64_t capture_interval = VideoFormat::FpsToInterval(kDefaultFps); |
| 294 adapter_.OnOutputFormatRequest( | 297 adapter_.OnOutputFormatRequest( |
| 295 VideoFormat(640, 480, capture_interval, cricket::FOURCC_ANY)); | 298 VideoFormat(640, 480, capture_interval, cricket::FOURCC_ANY)); |
| 296 | 299 |
| 297 const int64_t first_timestamp = 0; | 300 const int64_t first_timestamp = 0; |
| 298 adapter_.AdaptFrameResolution(640, 480, first_timestamp, | 301 adapter_.AdaptFrameResolution(640, 480, first_timestamp, |
| 299 &cropped_width_, &cropped_height_, | 302 &cropped_width_, &cropped_height_, |
| 300 &out_width_, &out_height_); | 303 &out_width_, &out_height_); |
| 301 EXPECT_GT(out_width_, 0); | 304 EXPECT_GT(out_width_, 0); |
| 302 EXPECT_GT(out_height_, 0); | 305 EXPECT_GT(out_height_, 0); |
| 303 | 306 |
| 304 const int64_t big_offset = -987654321LL * 1000; | 307 const int64_t big_offset = -987654321LL * 1000; |
| 305 const int64_t second_timestamp = big_offset; | 308 const int64_t second_timestamp = big_offset; |
| 306 adapter_.AdaptFrameResolution(640, 480, second_timestamp, | 309 adapter_.AdaptFrameResolution(640, 480, second_timestamp, |
| 307 &cropped_width_, &cropped_height_, | 310 &cropped_width_, &cropped_height_, |
| 308 &out_width_, &out_height_); | 311 &out_width_, &out_height_); |
| 309 EXPECT_GT(out_width_, 0); | 312 EXPECT_GT(out_width_, 0); |
| 310 EXPECT_GT(out_height_, 0); | 313 EXPECT_GT(out_height_, 0); |
| 311 | 314 |
| 312 const int64_t third_timestamp = big_offset + capture_interval; | 315 const int64_t third_timestamp = big_offset + capture_interval; |
| 313 adapter_.AdaptFrameResolution(640, 480, third_timestamp, | 316 adapter_.AdaptFrameResolution(640, 480, third_timestamp, |
| 314 &cropped_width_, &cropped_height_, | 317 &cropped_width_, &cropped_height_, |
| 315 &out_width_, &out_height_); | 318 &out_width_, &out_height_); |
| 316 EXPECT_GT(out_width_, 0); | 319 EXPECT_GT(out_width_, 0); |
| 317 EXPECT_GT(out_height_, 0); | 320 EXPECT_GT(out_height_, 0); |
| 318 } | 321 } |
| 319 | 322 |
| 320 // Request 30 fps and send 30 fps with jitter. Expect that no frame is dropped. | 323 // Request 30 fps and send 30 fps with jitter. Expect that no frame is dropped. |
| 321 TEST_F(VideoAdapterTest, AdaptFramerateTimestampJitter) { | 324 TEST_F(VideoAdapterTest, AdaptFramerateTimestampJitter) { |
| 322 const int64_t capture_interval = VideoFormat::FpsToInterval(30); | 325 const int64_t capture_interval = VideoFormat::FpsToInterval(kDefaultFps); |
| 323 adapter_.OnOutputFormatRequest( | 326 adapter_.OnOutputFormatRequest( |
| 324 VideoFormat(640, 480, capture_interval, cricket::FOURCC_ANY)); | 327 VideoFormat(640, 480, capture_interval, cricket::FOURCC_ANY)); |
| 325 | 328 |
| 326 adapter_.AdaptFrameResolution(640, 480, capture_interval * 0 / 10, | 329 adapter_.AdaptFrameResolution(640, 480, capture_interval * 0 / 10, |
| 327 &cropped_width_, &cropped_height_, | 330 &cropped_width_, &cropped_height_, |
| 328 &out_width_, &out_height_); | 331 &out_width_, &out_height_); |
| 329 EXPECT_GT(out_width_, 0); | 332 EXPECT_GT(out_width_, 0); |
| 330 EXPECT_GT(out_height_, 0); | 333 EXPECT_GT(out_height_, 0); |
| 331 | 334 |
| 332 adapter_.AdaptFrameResolution(640, 480, capture_interval * 10 / 10 - 1, | 335 adapter_.AdaptFrameResolution(640, 480, capture_interval * 10 / 10 - 1, |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 377 request_format.interval *= 2; | 380 request_format.interval *= 2; |
| 378 adapter_.OnOutputFormatRequest(request_format); | 381 adapter_.OnOutputFormatRequest(request_format); |
| 379 | 382 |
| 380 for (int i = 0; i < 20; ++i) | 383 for (int i = 0; i < 20; ++i) |
| 381 capturer_->CaptureFrame(); | 384 capturer_->CaptureFrame(); |
| 382 | 385 |
| 383 // Verify frame drop after adaptation. | 386 // Verify frame drop after adaptation. |
| 384 EXPECT_GT(listener_->GetStats().dropped_frames, 0); | 387 EXPECT_GT(listener_->GetStats().dropped_frames, 0); |
| 385 } | 388 } |
| 386 | 389 |
| 390 // Do not adapt the frame rate or the resolution. Expect no frame drop, no |
| 391 // cropping, and no resolution change. |
| 392 TEST_F(VideoAdapterTest, OnFramerateRequestMax) { |
| 393 adapter_.OnResolutionFramerateRequest( |
| 394 rtc::Optional<int>(), rtc::Optional<int>(), |
| 395 rtc::Optional<int>(std::numeric_limits<int>::max())); |
| 396 |
| 397 EXPECT_EQ(CS_RUNNING, capturer_->Start(capture_format_)); |
| 398 for (int i = 0; i < 10; ++i) |
| 399 capturer_->CaptureFrame(); |
| 400 |
| 401 // Verify no frame drop and no resolution change. |
| 402 VideoCapturerListener::Stats stats = listener_->GetStats(); |
| 403 EXPECT_GE(stats.captured_frames, 10); |
| 404 EXPECT_EQ(0, stats.dropped_frames); |
| 405 VerifyAdaptedResolution(stats, capture_format_.width, capture_format_.height, |
| 406 capture_format_.width, capture_format_.height); |
| 407 EXPECT_TRUE(stats.last_adapt_was_no_op); |
| 408 } |
| 409 |
| 410 TEST_F(VideoAdapterTest, OnFramerateRequestZero) { |
| 411 adapter_.OnResolutionFramerateRequest( |
| 412 rtc::Optional<int>(), rtc::Optional<int>(), rtc::Optional<int>(0)); |
| 413 EXPECT_EQ(CS_RUNNING, capturer_->Start(capture_format_)); |
| 414 for (int i = 0; i < 10; ++i) |
| 415 capturer_->CaptureFrame(); |
| 416 |
| 417 // Verify no crash and that frames aren't dropped. |
| 418 VideoCapturerListener::Stats stats = listener_->GetStats(); |
| 419 EXPECT_GE(stats.captured_frames, 10); |
| 420 EXPECT_EQ(10, stats.dropped_frames); |
| 421 } |
| 422 |
| 423 // Adapt the frame rate to be half of the capture rate at the beginning. Expect |
| 424 // the number of dropped frames to be half of the number the captured frames. |
| 425 TEST_F(VideoAdapterTest, OnFramerateRequestHalf) { |
| 426 adapter_.OnResolutionFramerateRequest(rtc::Optional<int>(), |
| 427 rtc::Optional<int>(), |
| 428 rtc::Optional<int>(kDefaultFps / 2)); |
| 429 EXPECT_EQ(CS_RUNNING, capturer_->Start(capture_format_)); |
| 430 for (int i = 0; i < 10; ++i) |
| 431 capturer_->CaptureFrame(); |
| 432 |
| 433 // Verify no crash and that frames aren't dropped. |
| 434 VideoCapturerListener::Stats stats = listener_->GetStats(); |
| 435 EXPECT_GE(stats.captured_frames, 10); |
| 436 EXPECT_EQ(5, stats.dropped_frames); |
| 437 VerifyAdaptedResolution(stats, capture_format_.width, capture_format_.height, |
| 438 capture_format_.width, capture_format_.height); |
| 439 } |
| 440 |
| 387 // Set a very high output pixel resolution. Expect no cropping or resolution | 441 // Set a very high output pixel resolution. Expect no cropping or resolution |
| 388 // change. | 442 // change. |
| 389 TEST_F(VideoAdapterTest, AdaptFrameResolutionHighLimit) { | 443 TEST_F(VideoAdapterTest, AdaptFrameResolutionHighLimit) { |
| 390 VideoFormat output_format = capture_format_; | 444 VideoFormat output_format = capture_format_; |
| 391 output_format.width *= 10; | 445 output_format.width *= 10; |
| 392 output_format.height *= 10; | 446 output_format.height *= 10; |
| 393 adapter_.OnOutputFormatRequest(output_format); | 447 adapter_.OnOutputFormatRequest(output_format); |
| 394 EXPECT_TRUE(adapter_.AdaptFrameResolution( | 448 EXPECT_TRUE(adapter_.AdaptFrameResolution( |
| 395 capture_format_.width, capture_format_.height, 0, | 449 capture_format_.width, capture_format_.height, 0, |
| 396 &cropped_width_, &cropped_height_, | 450 &cropped_width_, &cropped_height_, |
| (...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 689 TEST_F(VideoAdapterTest, TestOnResolutionRequestInSmallSteps) { | 743 TEST_F(VideoAdapterTest, TestOnResolutionRequestInSmallSteps) { |
| 690 EXPECT_TRUE(adapter_.AdaptFrameResolution(1280, 720, 0, | 744 EXPECT_TRUE(adapter_.AdaptFrameResolution(1280, 720, 0, |
| 691 &cropped_width_, &cropped_height_, | 745 &cropped_width_, &cropped_height_, |
| 692 &out_width_, &out_height_)); | 746 &out_width_, &out_height_)); |
| 693 EXPECT_EQ(1280, cropped_width_); | 747 EXPECT_EQ(1280, cropped_width_); |
| 694 EXPECT_EQ(720, cropped_height_); | 748 EXPECT_EQ(720, cropped_height_); |
| 695 EXPECT_EQ(1280, out_width_); | 749 EXPECT_EQ(1280, out_width_); |
| 696 EXPECT_EQ(720, out_height_); | 750 EXPECT_EQ(720, out_height_); |
| 697 | 751 |
| 698 // Adapt down one step. | 752 // Adapt down one step. |
| 699 adapter_.OnResolutionRequest(rtc::Optional<int>(), | 753 adapter_.OnResolutionFramerateRequest(rtc::Optional<int>(), |
| 700 rtc::Optional<int>(1280 * 720 - 1)); | 754 rtc::Optional<int>(1280 * 720 - 1), |
| 755 rtc::Optional<int>()); |
| 701 EXPECT_TRUE(adapter_.AdaptFrameResolution(1280, 720, 0, | 756 EXPECT_TRUE(adapter_.AdaptFrameResolution(1280, 720, 0, |
| 702 &cropped_width_, &cropped_height_, | 757 &cropped_width_, &cropped_height_, |
| 703 &out_width_, &out_height_)); | 758 &out_width_, &out_height_)); |
| 704 EXPECT_EQ(1280, cropped_width_); | 759 EXPECT_EQ(1280, cropped_width_); |
| 705 EXPECT_EQ(720, cropped_height_); | 760 EXPECT_EQ(720, cropped_height_); |
| 706 EXPECT_EQ(960, out_width_); | 761 EXPECT_EQ(960, out_width_); |
| 707 EXPECT_EQ(540, out_height_); | 762 EXPECT_EQ(540, out_height_); |
| 708 | 763 |
| 709 // Adapt down one step more. | 764 // Adapt down one step more. |
| 710 adapter_.OnResolutionRequest(rtc::Optional<int>(), | 765 adapter_.OnResolutionFramerateRequest(rtc::Optional<int>(), |
| 711 rtc::Optional<int>(960 * 540 - 1)); | 766 rtc::Optional<int>(960 * 540 - 1), |
| 767 rtc::Optional<int>()); |
| 712 EXPECT_TRUE(adapter_.AdaptFrameResolution(1280, 720, 0, | 768 EXPECT_TRUE(adapter_.AdaptFrameResolution(1280, 720, 0, |
| 713 &cropped_width_, &cropped_height_, | 769 &cropped_width_, &cropped_height_, |
| 714 &out_width_, &out_height_)); | 770 &out_width_, &out_height_)); |
| 715 EXPECT_EQ(1280, cropped_width_); | 771 EXPECT_EQ(1280, cropped_width_); |
| 716 EXPECT_EQ(720, cropped_height_); | 772 EXPECT_EQ(720, cropped_height_); |
| 717 EXPECT_EQ(640, out_width_); | 773 EXPECT_EQ(640, out_width_); |
| 718 EXPECT_EQ(360, out_height_); | 774 EXPECT_EQ(360, out_height_); |
| 719 | 775 |
| 720 // Adapt down one step more. | 776 // Adapt down one step more. |
| 721 adapter_.OnResolutionRequest(rtc::Optional<int>(), | 777 adapter_.OnResolutionFramerateRequest(rtc::Optional<int>(), |
| 722 rtc::Optional<int>(640 * 360 - 1)); | 778 rtc::Optional<int>(640 * 360 - 1), |
| 779 rtc::Optional<int>()); |
| 723 EXPECT_TRUE(adapter_.AdaptFrameResolution(1280, 720, 0, | 780 EXPECT_TRUE(adapter_.AdaptFrameResolution(1280, 720, 0, |
| 724 &cropped_width_, &cropped_height_, | 781 &cropped_width_, &cropped_height_, |
| 725 &out_width_, &out_height_)); | 782 &out_width_, &out_height_)); |
| 726 EXPECT_EQ(1280, cropped_width_); | 783 EXPECT_EQ(1280, cropped_width_); |
| 727 EXPECT_EQ(720, cropped_height_); | 784 EXPECT_EQ(720, cropped_height_); |
| 728 EXPECT_EQ(480, out_width_); | 785 EXPECT_EQ(480, out_width_); |
| 729 EXPECT_EQ(270, out_height_); | 786 EXPECT_EQ(270, out_height_); |
| 730 | 787 |
| 731 // Adapt up one step. | 788 // Adapt up one step. |
| 732 adapter_.OnResolutionRequest(rtc::Optional<int>(640 * 360), | 789 adapter_.OnResolutionFramerateRequest(rtc::Optional<int>(640 * 360), |
| 733 rtc::Optional<int>(960 * 540)); | 790 rtc::Optional<int>(960 * 540), |
| 791 rtc::Optional<int>()); |
| 734 EXPECT_TRUE(adapter_.AdaptFrameResolution(1280, 720, 0, | 792 EXPECT_TRUE(adapter_.AdaptFrameResolution(1280, 720, 0, |
| 735 &cropped_width_, &cropped_height_, | 793 &cropped_width_, &cropped_height_, |
| 736 &out_width_, &out_height_)); | 794 &out_width_, &out_height_)); |
| 737 EXPECT_EQ(1280, cropped_width_); | 795 EXPECT_EQ(1280, cropped_width_); |
| 738 EXPECT_EQ(720, cropped_height_); | 796 EXPECT_EQ(720, cropped_height_); |
| 739 EXPECT_EQ(640, out_width_); | 797 EXPECT_EQ(640, out_width_); |
| 740 EXPECT_EQ(360, out_height_); | 798 EXPECT_EQ(360, out_height_); |
| 741 | 799 |
| 742 // Adapt up one step more. | 800 // Adapt up one step more. |
| 743 adapter_.OnResolutionRequest(rtc::Optional<int>(960 * 540), | 801 adapter_.OnResolutionFramerateRequest(rtc::Optional<int>(960 * 540), |
| 744 rtc::Optional<int>(1280 * 720)); | 802 rtc::Optional<int>(1280 * 720), |
| 803 rtc::Optional<int>()); |
| 745 EXPECT_TRUE(adapter_.AdaptFrameResolution(1280, 720, 0, | 804 EXPECT_TRUE(adapter_.AdaptFrameResolution(1280, 720, 0, |
| 746 &cropped_width_, &cropped_height_, | 805 &cropped_width_, &cropped_height_, |
| 747 &out_width_, &out_height_)); | 806 &out_width_, &out_height_)); |
| 748 EXPECT_EQ(1280, cropped_width_); | 807 EXPECT_EQ(1280, cropped_width_); |
| 749 EXPECT_EQ(720, cropped_height_); | 808 EXPECT_EQ(720, cropped_height_); |
| 750 EXPECT_EQ(960, out_width_); | 809 EXPECT_EQ(960, out_width_); |
| 751 EXPECT_EQ(540, out_height_); | 810 EXPECT_EQ(540, out_height_); |
| 752 | 811 |
| 753 // Adapt up one step more. | 812 // Adapt up one step more. |
| 754 adapter_.OnResolutionRequest(rtc::Optional<int>(1280 * 720), | 813 adapter_.OnResolutionFramerateRequest(rtc::Optional<int>(1280 * 720), |
| 755 rtc::Optional<int>(1920 * 1080)); | 814 rtc::Optional<int>(1920 * 1080), |
| 815 rtc::Optional<int>()); |
| 756 EXPECT_TRUE(adapter_.AdaptFrameResolution(1280, 720, 0, | 816 EXPECT_TRUE(adapter_.AdaptFrameResolution(1280, 720, 0, |
| 757 &cropped_width_, &cropped_height_, | 817 &cropped_width_, &cropped_height_, |
| 758 &out_width_, &out_height_)); | 818 &out_width_, &out_height_)); |
| 759 EXPECT_EQ(1280, cropped_width_); | 819 EXPECT_EQ(1280, cropped_width_); |
| 760 EXPECT_EQ(720, cropped_height_); | 820 EXPECT_EQ(720, cropped_height_); |
| 761 EXPECT_EQ(1280, out_width_); | 821 EXPECT_EQ(1280, out_width_); |
| 762 EXPECT_EQ(720, out_height_); | 822 EXPECT_EQ(720, out_height_); |
| 763 } | 823 } |
| 764 | 824 |
| 765 TEST_F(VideoAdapterTest, TestOnResolutionRequestMaxZero) { | 825 TEST_F(VideoAdapterTest, TestOnResolutionRequestMaxZero) { |
| 766 EXPECT_TRUE(adapter_.AdaptFrameResolution(1280, 720, 0, | 826 EXPECT_TRUE(adapter_.AdaptFrameResolution(1280, 720, 0, |
| 767 &cropped_width_, &cropped_height_, | 827 &cropped_width_, &cropped_height_, |
| 768 &out_width_, &out_height_)); | 828 &out_width_, &out_height_)); |
| 769 EXPECT_EQ(1280, cropped_width_); | 829 EXPECT_EQ(1280, cropped_width_); |
| 770 EXPECT_EQ(720, cropped_height_); | 830 EXPECT_EQ(720, cropped_height_); |
| 771 EXPECT_EQ(1280, out_width_); | 831 EXPECT_EQ(1280, out_width_); |
| 772 EXPECT_EQ(720, out_height_); | 832 EXPECT_EQ(720, out_height_); |
| 773 | 833 |
| 774 adapter_.OnResolutionRequest(rtc::Optional<int>(), rtc::Optional<int>(0)); | 834 adapter_.OnResolutionFramerateRequest( |
| 835 rtc::Optional<int>(), rtc::Optional<int>(0), rtc::Optional<int>()); |
| 775 EXPECT_FALSE(adapter_.AdaptFrameResolution(1280, 720, 0, | 836 EXPECT_FALSE(adapter_.AdaptFrameResolution(1280, 720, 0, |
| 776 &cropped_width_, &cropped_height_, | 837 &cropped_width_, &cropped_height_, |
| 777 &out_width_, &out_height_)); | 838 &out_width_, &out_height_)); |
| 778 } | 839 } |
| 779 | 840 |
| 780 TEST_F(VideoAdapterTest, TestOnResolutionRequestInLargeSteps) { | 841 TEST_F(VideoAdapterTest, TestOnResolutionRequestInLargeSteps) { |
| 781 // Large step down. | 842 // Large step down. |
| 782 adapter_.OnResolutionRequest(rtc::Optional<int>(), | 843 adapter_.OnResolutionFramerateRequest(rtc::Optional<int>(), |
| 783 rtc::Optional<int>(640 * 360 - 1)); | 844 rtc::Optional<int>(640 * 360 - 1), |
| 845 rtc::Optional<int>()); |
| 784 EXPECT_TRUE(adapter_.AdaptFrameResolution(1280, 720, 0, | 846 EXPECT_TRUE(adapter_.AdaptFrameResolution(1280, 720, 0, |
| 785 &cropped_width_, &cropped_height_, | 847 &cropped_width_, &cropped_height_, |
| 786 &out_width_, &out_height_)); | 848 &out_width_, &out_height_)); |
| 787 EXPECT_EQ(1280, cropped_width_); | 849 EXPECT_EQ(1280, cropped_width_); |
| 788 EXPECT_EQ(720, cropped_height_); | 850 EXPECT_EQ(720, cropped_height_); |
| 789 EXPECT_EQ(480, out_width_); | 851 EXPECT_EQ(480, out_width_); |
| 790 EXPECT_EQ(270, out_height_); | 852 EXPECT_EQ(270, out_height_); |
| 791 | 853 |
| 792 // Large step up. | 854 // Large step up. |
| 793 adapter_.OnResolutionRequest(rtc::Optional<int>(1280 * 720), | 855 adapter_.OnResolutionFramerateRequest(rtc::Optional<int>(1280 * 720), |
| 794 rtc::Optional<int>(1920 * 1080)); | 856 rtc::Optional<int>(1920 * 1080), |
| 857 rtc::Optional<int>()); |
| 795 EXPECT_TRUE(adapter_.AdaptFrameResolution(1280, 720, 0, | 858 EXPECT_TRUE(adapter_.AdaptFrameResolution(1280, 720, 0, |
| 796 &cropped_width_, &cropped_height_, | 859 &cropped_width_, &cropped_height_, |
| 797 &out_width_, &out_height_)); | 860 &out_width_, &out_height_)); |
| 798 EXPECT_EQ(1280, cropped_width_); | 861 EXPECT_EQ(1280, cropped_width_); |
| 799 EXPECT_EQ(720, cropped_height_); | 862 EXPECT_EQ(720, cropped_height_); |
| 800 EXPECT_EQ(1280, out_width_); | 863 EXPECT_EQ(1280, out_width_); |
| 801 EXPECT_EQ(720, out_height_); | 864 EXPECT_EQ(720, out_height_); |
| 802 } | 865 } |
| 803 | 866 |
| 804 TEST_F(VideoAdapterTest, TestOnOutputFormatRequestCapsMaxResolution) { | 867 TEST_F(VideoAdapterTest, TestOnOutputFormatRequestCapsMaxResolution) { |
| 805 adapter_.OnResolutionRequest(rtc::Optional<int>(), | 868 adapter_.OnResolutionFramerateRequest(rtc::Optional<int>(), |
| 806 rtc::Optional<int>(640 * 360 - 1)); | 869 rtc::Optional<int>(640 * 360 - 1), |
| 870 rtc::Optional<int>()); |
| 807 EXPECT_TRUE(adapter_.AdaptFrameResolution(1280, 720, 0, | 871 EXPECT_TRUE(adapter_.AdaptFrameResolution(1280, 720, 0, |
| 808 &cropped_width_, &cropped_height_, | 872 &cropped_width_, &cropped_height_, |
| 809 &out_width_, &out_height_)); | 873 &out_width_, &out_height_)); |
| 810 EXPECT_EQ(1280, cropped_width_); | 874 EXPECT_EQ(1280, cropped_width_); |
| 811 EXPECT_EQ(720, cropped_height_); | 875 EXPECT_EQ(720, cropped_height_); |
| 812 EXPECT_EQ(480, out_width_); | 876 EXPECT_EQ(480, out_width_); |
| 813 EXPECT_EQ(270, out_height_); | 877 EXPECT_EQ(270, out_height_); |
| 814 | 878 |
| 815 VideoFormat new_format(640, 360, 0, FOURCC_I420); | 879 VideoFormat new_format(640, 360, 0, FOURCC_I420); |
| 816 adapter_.OnOutputFormatRequest(new_format); | 880 adapter_.OnOutputFormatRequest(new_format); |
| 817 EXPECT_TRUE(adapter_.AdaptFrameResolution(1280, 720, 0, | 881 EXPECT_TRUE(adapter_.AdaptFrameResolution(1280, 720, 0, |
| 818 &cropped_width_, &cropped_height_, | 882 &cropped_width_, &cropped_height_, |
| 819 &out_width_, &out_height_)); | 883 &out_width_, &out_height_)); |
| 820 EXPECT_EQ(1280, cropped_width_); | 884 EXPECT_EQ(1280, cropped_width_); |
| 821 EXPECT_EQ(720, cropped_height_); | 885 EXPECT_EQ(720, cropped_height_); |
| 822 EXPECT_EQ(480, out_width_); | 886 EXPECT_EQ(480, out_width_); |
| 823 EXPECT_EQ(270, out_height_); | 887 EXPECT_EQ(270, out_height_); |
| 824 | 888 |
| 825 adapter_.OnResolutionRequest(rtc::Optional<int>(), | 889 adapter_.OnResolutionFramerateRequest(rtc::Optional<int>(), |
| 826 rtc::Optional<int>(960 * 720)); | 890 rtc::Optional<int>(960 * 720), |
| 891 rtc::Optional<int>()); |
| 827 EXPECT_TRUE(adapter_.AdaptFrameResolution(1280, 720, 0, | 892 EXPECT_TRUE(adapter_.AdaptFrameResolution(1280, 720, 0, |
| 828 &cropped_width_, &cropped_height_, | 893 &cropped_width_, &cropped_height_, |
| 829 &out_width_, &out_height_)); | 894 &out_width_, &out_height_)); |
| 830 EXPECT_EQ(1280, cropped_width_); | 895 EXPECT_EQ(1280, cropped_width_); |
| 831 EXPECT_EQ(720, cropped_height_); | 896 EXPECT_EQ(720, cropped_height_); |
| 832 EXPECT_EQ(640, out_width_); | 897 EXPECT_EQ(640, out_width_); |
| 833 EXPECT_EQ(360, out_height_); | 898 EXPECT_EQ(360, out_height_); |
| 834 } | 899 } |
| 835 | 900 |
| 836 TEST_F(VideoAdapterTest, TestOnResolutionRequestReset) { | 901 TEST_F(VideoAdapterTest, TestOnResolutionRequestReset) { |
| 837 EXPECT_TRUE(adapter_.AdaptFrameResolution(1280, 720, 0, | 902 EXPECT_TRUE(adapter_.AdaptFrameResolution(1280, 720, 0, |
| 838 &cropped_width_, &cropped_height_, | 903 &cropped_width_, &cropped_height_, |
| 839 &out_width_, &out_height_)); | 904 &out_width_, &out_height_)); |
| 840 EXPECT_EQ(1280, cropped_width_); | 905 EXPECT_EQ(1280, cropped_width_); |
| 841 EXPECT_EQ(720, cropped_height_); | 906 EXPECT_EQ(720, cropped_height_); |
| 842 EXPECT_EQ(1280, out_width_); | 907 EXPECT_EQ(1280, out_width_); |
| 843 EXPECT_EQ(720, out_height_); | 908 EXPECT_EQ(720, out_height_); |
| 844 | 909 |
| 845 adapter_.OnResolutionRequest(rtc::Optional<int>(), | 910 adapter_.OnResolutionFramerateRequest(rtc::Optional<int>(), |
| 846 rtc::Optional<int>(640 * 360 - 1)); | 911 rtc::Optional<int>(640 * 360 - 1), |
| 912 rtc::Optional<int>()); |
| 847 EXPECT_TRUE(adapter_.AdaptFrameResolution(1280, 720, 0, | 913 EXPECT_TRUE(adapter_.AdaptFrameResolution(1280, 720, 0, |
| 848 &cropped_width_, &cropped_height_, | 914 &cropped_width_, &cropped_height_, |
| 849 &out_width_, &out_height_)); | 915 &out_width_, &out_height_)); |
| 850 EXPECT_EQ(1280, cropped_width_); | 916 EXPECT_EQ(1280, cropped_width_); |
| 851 EXPECT_EQ(720, cropped_height_); | 917 EXPECT_EQ(720, cropped_height_); |
| 852 EXPECT_EQ(480, out_width_); | 918 EXPECT_EQ(480, out_width_); |
| 853 EXPECT_EQ(270, out_height_); | 919 EXPECT_EQ(270, out_height_); |
| 854 | 920 |
| 855 adapter_.OnResolutionRequest(rtc::Optional<int>(), rtc::Optional<int>()); | 921 adapter_.OnResolutionFramerateRequest( |
| 922 rtc::Optional<int>(), rtc::Optional<int>(), rtc::Optional<int>()); |
| 856 EXPECT_TRUE(adapter_.AdaptFrameResolution(1280, 720, 0, | 923 EXPECT_TRUE(adapter_.AdaptFrameResolution(1280, 720, 0, |
| 857 &cropped_width_, &cropped_height_, | 924 &cropped_width_, &cropped_height_, |
| 858 &out_width_, &out_height_)); | 925 &out_width_, &out_height_)); |
| 859 EXPECT_EQ(1280, cropped_width_); | 926 EXPECT_EQ(1280, cropped_width_); |
| 860 EXPECT_EQ(720, cropped_height_); | 927 EXPECT_EQ(720, cropped_height_); |
| 861 EXPECT_EQ(1280, out_width_); | 928 EXPECT_EQ(1280, out_width_); |
| 862 EXPECT_EQ(720, out_height_); | 929 EXPECT_EQ(720, out_height_); |
| 863 } | 930 } |
| 864 | 931 |
| 865 TEST_F(VideoAdapterTest, TestCroppingWithResolutionRequest) { | 932 TEST_F(VideoAdapterTest, TestCroppingWithResolutionRequest) { |
| 866 // Ask for 640x360 (16:9 aspect). | 933 // Ask for 640x360 (16:9 aspect). |
| 867 adapter_.OnOutputFormatRequest(VideoFormat(640, 360, 0, FOURCC_I420)); | 934 adapter_.OnOutputFormatRequest(VideoFormat(640, 360, 0, FOURCC_I420)); |
| 868 // Send 640x480 (4:3 aspect). | 935 // Send 640x480 (4:3 aspect). |
| 869 EXPECT_TRUE(adapter_.AdaptFrameResolution(640, 480, 0, | 936 EXPECT_TRUE(adapter_.AdaptFrameResolution(640, 480, 0, |
| 870 &cropped_width_, &cropped_height_, | 937 &cropped_width_, &cropped_height_, |
| 871 &out_width_, &out_height_)); | 938 &out_width_, &out_height_)); |
| 872 // Expect cropping to 16:9 format and no scaling. | 939 // Expect cropping to 16:9 format and no scaling. |
| 873 EXPECT_EQ(640, cropped_width_); | 940 EXPECT_EQ(640, cropped_width_); |
| 874 EXPECT_EQ(360, cropped_height_); | 941 EXPECT_EQ(360, cropped_height_); |
| 875 EXPECT_EQ(640, out_width_); | 942 EXPECT_EQ(640, out_width_); |
| 876 EXPECT_EQ(360, out_height_); | 943 EXPECT_EQ(360, out_height_); |
| 877 | 944 |
| 878 // Adapt down one step. | 945 // Adapt down one step. |
| 879 adapter_.OnResolutionRequest(rtc::Optional<int>(), | 946 adapter_.OnResolutionFramerateRequest(rtc::Optional<int>(), |
| 880 rtc::Optional<int>(640 * 360 - 1)); | 947 rtc::Optional<int>(640 * 360 - 1), |
| 948 rtc::Optional<int>()); |
| 881 // Expect cropping to 16:9 format and 3/4 scaling. | 949 // Expect cropping to 16:9 format and 3/4 scaling. |
| 882 EXPECT_TRUE(adapter_.AdaptFrameResolution(640, 480, 0, | 950 EXPECT_TRUE(adapter_.AdaptFrameResolution(640, 480, 0, |
| 883 &cropped_width_, &cropped_height_, | 951 &cropped_width_, &cropped_height_, |
| 884 &out_width_, &out_height_)); | 952 &out_width_, &out_height_)); |
| 885 EXPECT_EQ(640, cropped_width_); | 953 EXPECT_EQ(640, cropped_width_); |
| 886 EXPECT_EQ(360, cropped_height_); | 954 EXPECT_EQ(360, cropped_height_); |
| 887 EXPECT_EQ(480, out_width_); | 955 EXPECT_EQ(480, out_width_); |
| 888 EXPECT_EQ(270, out_height_); | 956 EXPECT_EQ(270, out_height_); |
| 889 | 957 |
| 890 // Adapt down one step more. | 958 // Adapt down one step more. |
| 891 adapter_.OnResolutionRequest(rtc::Optional<int>(), | 959 adapter_.OnResolutionFramerateRequest(rtc::Optional<int>(), |
| 892 rtc::Optional<int>(480 * 270 - 1)); | 960 rtc::Optional<int>(480 * 270 - 1), |
| 961 rtc::Optional<int>()); |
| 893 // Expect cropping to 16:9 format and 1/2 scaling. | 962 // Expect cropping to 16:9 format and 1/2 scaling. |
| 894 EXPECT_TRUE(adapter_.AdaptFrameResolution(640, 480, 0, | 963 EXPECT_TRUE(adapter_.AdaptFrameResolution(640, 480, 0, |
| 895 &cropped_width_, &cropped_height_, | 964 &cropped_width_, &cropped_height_, |
| 896 &out_width_, &out_height_)); | 965 &out_width_, &out_height_)); |
| 897 EXPECT_EQ(640, cropped_width_); | 966 EXPECT_EQ(640, cropped_width_); |
| 898 EXPECT_EQ(360, cropped_height_); | 967 EXPECT_EQ(360, cropped_height_); |
| 899 EXPECT_EQ(320, out_width_); | 968 EXPECT_EQ(320, out_width_); |
| 900 EXPECT_EQ(180, out_height_); | 969 EXPECT_EQ(180, out_height_); |
| 901 | 970 |
| 902 // Adapt up one step. | 971 // Adapt up one step. |
| 903 adapter_.OnResolutionRequest(rtc::Optional<int>(480 * 270), | 972 adapter_.OnResolutionFramerateRequest(rtc::Optional<int>(480 * 270), |
| 904 rtc::Optional<int>(640 * 360)); | 973 rtc::Optional<int>(640 * 360), |
| 974 rtc::Optional<int>()); |
| 905 // Expect cropping to 16:9 format and 3/4 scaling. | 975 // Expect cropping to 16:9 format and 3/4 scaling. |
| 906 EXPECT_TRUE(adapter_.AdaptFrameResolution(640, 480, 0, | 976 EXPECT_TRUE(adapter_.AdaptFrameResolution(640, 480, 0, |
| 907 &cropped_width_, &cropped_height_, | 977 &cropped_width_, &cropped_height_, |
| 908 &out_width_, &out_height_)); | 978 &out_width_, &out_height_)); |
| 909 EXPECT_EQ(640, cropped_width_); | 979 EXPECT_EQ(640, cropped_width_); |
| 910 EXPECT_EQ(360, cropped_height_); | 980 EXPECT_EQ(360, cropped_height_); |
| 911 EXPECT_EQ(480, out_width_); | 981 EXPECT_EQ(480, out_width_); |
| 912 EXPECT_EQ(270, out_height_); | 982 EXPECT_EQ(270, out_height_); |
| 913 | 983 |
| 914 // Adapt up one step more. | 984 // Adapt up one step more. |
| 915 adapter_.OnResolutionRequest(rtc::Optional<int>(640 * 360), | 985 adapter_.OnResolutionFramerateRequest(rtc::Optional<int>(640 * 360), |
| 916 rtc::Optional<int>(960 * 540)); | 986 rtc::Optional<int>(960 * 540), |
| 987 rtc::Optional<int>()); |
| 917 // Expect cropping to 16:9 format and no scaling. | 988 // Expect cropping to 16:9 format and no scaling. |
| 918 EXPECT_TRUE(adapter_.AdaptFrameResolution(640, 480, 0, | 989 EXPECT_TRUE(adapter_.AdaptFrameResolution(640, 480, 0, |
| 919 &cropped_width_, &cropped_height_, | 990 &cropped_width_, &cropped_height_, |
| 920 &out_width_, &out_height_)); | 991 &out_width_, &out_height_)); |
| 921 EXPECT_EQ(640, cropped_width_); | 992 EXPECT_EQ(640, cropped_width_); |
| 922 EXPECT_EQ(360, cropped_height_); | 993 EXPECT_EQ(360, cropped_height_); |
| 923 EXPECT_EQ(640, out_width_); | 994 EXPECT_EQ(640, out_width_); |
| 924 EXPECT_EQ(360, out_height_); | 995 EXPECT_EQ(360, out_height_); |
| 925 | 996 |
| 926 // Try to adapt up one step more. | 997 // Try to adapt up one step more. |
| 927 adapter_.OnResolutionRequest(rtc::Optional<int>(960 * 540), | 998 adapter_.OnResolutionFramerateRequest(rtc::Optional<int>(960 * 540), |
| 928 rtc::Optional<int>(1280 * 720)); | 999 rtc::Optional<int>(1280 * 720), |
| 1000 rtc::Optional<int>()); |
| 929 // Expect cropping to 16:9 format and no scaling. | 1001 // Expect cropping to 16:9 format and no scaling. |
| 930 EXPECT_TRUE(adapter_.AdaptFrameResolution(640, 480, 0, | 1002 EXPECT_TRUE(adapter_.AdaptFrameResolution(640, 480, 0, |
| 931 &cropped_width_, &cropped_height_, | 1003 &cropped_width_, &cropped_height_, |
| 932 &out_width_, &out_height_)); | 1004 &out_width_, &out_height_)); |
| 933 EXPECT_EQ(640, cropped_width_); | 1005 EXPECT_EQ(640, cropped_width_); |
| 934 EXPECT_EQ(360, cropped_height_); | 1006 EXPECT_EQ(360, cropped_height_); |
| 935 EXPECT_EQ(640, out_width_); | 1007 EXPECT_EQ(640, out_width_); |
| 936 EXPECT_EQ(360, out_height_); | 1008 EXPECT_EQ(360, out_height_); |
| 937 } | 1009 } |
| 938 | 1010 |
| 939 TEST_F(VideoAdapterTest, TestCroppingOddResolution) { | 1011 TEST_F(VideoAdapterTest, TestCroppingOddResolution) { |
| 940 // Ask for 640x360 (16:9 aspect), with 3/16 scaling. | 1012 // Ask for 640x360 (16:9 aspect), with 3/16 scaling. |
| 941 adapter_.OnOutputFormatRequest( | 1013 adapter_.OnOutputFormatRequest( |
| 942 VideoFormat(640, 360, 0, FOURCC_I420)); | 1014 VideoFormat(640, 360, 0, FOURCC_I420)); |
| 943 adapter_.OnResolutionRequest(rtc::Optional<int>(), | 1015 adapter_.OnResolutionFramerateRequest( |
| 944 rtc::Optional<int>(640 * 360 * 3 / 16 * 3 / 16)); | 1016 rtc::Optional<int>(), rtc::Optional<int>(640 * 360 * 3 / 16 * 3 / 16), |
| 1017 rtc::Optional<int>()); |
| 945 | 1018 |
| 946 // Send 640x480 (4:3 aspect). | 1019 // Send 640x480 (4:3 aspect). |
| 947 EXPECT_TRUE(adapter_.AdaptFrameResolution(640, 480, 0, | 1020 EXPECT_TRUE(adapter_.AdaptFrameResolution(640, 480, 0, |
| 948 &cropped_width_, &cropped_height_, | 1021 &cropped_width_, &cropped_height_, |
| 949 &out_width_, &out_height_)); | 1022 &out_width_, &out_height_)); |
| 950 | 1023 |
| 951 // Instead of getting the exact aspect ratio with cropped resolution 640x360, | 1024 // Instead of getting the exact aspect ratio with cropped resolution 640x360, |
| 952 // the resolution should be adjusted to get a perfect scale factor instead. | 1025 // the resolution should be adjusted to get a perfect scale factor instead. |
| 953 EXPECT_EQ(640, cropped_width_); | 1026 EXPECT_EQ(640, cropped_width_); |
| 954 EXPECT_EQ(368, cropped_height_); | 1027 EXPECT_EQ(368, cropped_height_); |
| 955 EXPECT_EQ(120, out_width_); | 1028 EXPECT_EQ(120, out_width_); |
| 956 EXPECT_EQ(69, out_height_); | 1029 EXPECT_EQ(69, out_height_); |
| 957 } | 1030 } |
| 958 | 1031 |
| 959 TEST_F(VideoAdapterTest, TestAdaptToVerySmallResolution) { | 1032 TEST_F(VideoAdapterTest, TestAdaptToVerySmallResolution) { |
| 960 // Ask for 1920x1080 (16:9 aspect), with 1/16 scaling. | 1033 // Ask for 1920x1080 (16:9 aspect), with 1/16 scaling. |
| 961 const int w = 1920; | 1034 const int w = 1920; |
| 962 const int h = 1080; | 1035 const int h = 1080; |
| 963 adapter_.OnOutputFormatRequest(VideoFormat(w, h, 0, FOURCC_I420)); | 1036 adapter_.OnOutputFormatRequest(VideoFormat(w, h, 0, FOURCC_I420)); |
| 964 adapter_.OnResolutionRequest(rtc::Optional<int>(), | 1037 adapter_.OnResolutionFramerateRequest( |
| 965 rtc::Optional<int>(w * h * 1 / 16 * 1 / 16)); | 1038 rtc::Optional<int>(), rtc::Optional<int>(w * h * 1 / 16 * 1 / 16), |
| 1039 rtc::Optional<int>()); |
| 966 | 1040 |
| 967 // Send 1920x1080 (16:9 aspect). | 1041 // Send 1920x1080 (16:9 aspect). |
| 968 EXPECT_TRUE(adapter_.AdaptFrameResolution( | 1042 EXPECT_TRUE(adapter_.AdaptFrameResolution( |
| 969 w, h, 0, &cropped_width_, &cropped_height_, &out_width_, &out_height_)); | 1043 w, h, 0, &cropped_width_, &cropped_height_, &out_width_, &out_height_)); |
| 970 | 1044 |
| 971 // Instead of getting the exact aspect ratio with cropped resolution 1920x1080 | 1045 // Instead of getting the exact aspect ratio with cropped resolution 1920x1080 |
| 972 // the resolution should be adjusted to get a perfect scale factor instead. | 1046 // the resolution should be adjusted to get a perfect scale factor instead. |
| 973 EXPECT_EQ(1920, cropped_width_); | 1047 EXPECT_EQ(1920, cropped_width_); |
| 974 EXPECT_EQ(1072, cropped_height_); | 1048 EXPECT_EQ(1072, cropped_height_); |
| 975 EXPECT_EQ(120, out_width_); | 1049 EXPECT_EQ(120, out_width_); |
| 976 EXPECT_EQ(67, out_height_); | 1050 EXPECT_EQ(67, out_height_); |
| 977 | 1051 |
| 978 // Adapt back up one step to 3/32. | 1052 // Adapt back up one step to 3/32. |
| 979 adapter_.OnResolutionRequest(rtc::Optional<int>(w * h * 3 / 32 * 3 / 32), | 1053 adapter_.OnResolutionFramerateRequest( |
| 980 rtc::Optional<int>(w * h * 1 / 8 * 1 / 8)); | 1054 rtc::Optional<int>(w * h * 3 / 32 * 3 / 32), |
| 1055 rtc::Optional<int>(w * h * 1 / 8 * 1 / 8), rtc::Optional<int>()); |
| 981 | 1056 |
| 982 // Send 1920x1080 (16:9 aspect). | 1057 // Send 1920x1080 (16:9 aspect). |
| 983 EXPECT_TRUE(adapter_.AdaptFrameResolution( | 1058 EXPECT_TRUE(adapter_.AdaptFrameResolution( |
| 984 w, h, 0, &cropped_width_, &cropped_height_, &out_width_, &out_height_)); | 1059 w, h, 0, &cropped_width_, &cropped_height_, &out_width_, &out_height_)); |
| 985 | 1060 |
| 986 EXPECT_EQ(180, out_width_); | 1061 EXPECT_EQ(180, out_width_); |
| 987 EXPECT_EQ(99, out_height_); | 1062 EXPECT_EQ(99, out_height_); |
| 988 } | 1063 } |
| 989 | 1064 |
| 990 TEST_F(VideoAdapterTest, AdaptFrameResolutionDropWithResolutionRequest) { | 1065 TEST_F(VideoAdapterTest, AdaptFrameResolutionDropWithResolutionRequest) { |
| 991 VideoFormat output_format = capture_format_; | 1066 VideoFormat output_format = capture_format_; |
| 992 output_format.width = 0; | 1067 output_format.width = 0; |
| 993 output_format.height = 0; | 1068 output_format.height = 0; |
| 994 adapter_.OnOutputFormatRequest(output_format); | 1069 adapter_.OnOutputFormatRequest(output_format); |
| 995 EXPECT_FALSE(adapter_.AdaptFrameResolution( | 1070 EXPECT_FALSE(adapter_.AdaptFrameResolution( |
| 996 capture_format_.width, capture_format_.height, 0, | 1071 capture_format_.width, capture_format_.height, 0, |
| 997 &cropped_width_, &cropped_height_, | 1072 &cropped_width_, &cropped_height_, |
| 998 &out_width_, &out_height_)); | 1073 &out_width_, &out_height_)); |
| 999 | 1074 |
| 1000 adapter_.OnResolutionRequest(rtc::Optional<int>(960 * 540), | 1075 adapter_.OnResolutionFramerateRequest(rtc::Optional<int>(960 * 540), |
| 1001 rtc::Optional<int>()); | 1076 rtc::Optional<int>(), |
| 1077 rtc::Optional<int>()); |
| 1002 | 1078 |
| 1003 // Still expect all frames to be dropped | 1079 // Still expect all frames to be dropped |
| 1004 EXPECT_FALSE(adapter_.AdaptFrameResolution( | 1080 EXPECT_FALSE(adapter_.AdaptFrameResolution( |
| 1005 capture_format_.width, capture_format_.height, 0, | 1081 capture_format_.width, capture_format_.height, 0, |
| 1006 &cropped_width_, &cropped_height_, | 1082 &cropped_width_, &cropped_height_, |
| 1007 &out_width_, &out_height_)); | 1083 &out_width_, &out_height_)); |
| 1008 | 1084 |
| 1009 adapter_.OnResolutionRequest(rtc::Optional<int>(), | 1085 adapter_.OnResolutionFramerateRequest(rtc::Optional<int>(), |
| 1010 rtc::Optional<int>(640 * 480 - 1)); | 1086 rtc::Optional<int>(640 * 480 - 1), |
| 1087 rtc::Optional<int>()); |
| 1011 | 1088 |
| 1012 // Still expect all frames to be dropped | 1089 // Still expect all frames to be dropped |
| 1013 EXPECT_FALSE(adapter_.AdaptFrameResolution( | 1090 EXPECT_FALSE(adapter_.AdaptFrameResolution( |
| 1014 capture_format_.width, capture_format_.height, 0, | 1091 capture_format_.width, capture_format_.height, 0, |
| 1015 &cropped_width_, &cropped_height_, | 1092 &cropped_width_, &cropped_height_, |
| 1016 &out_width_, &out_height_)); | 1093 &out_width_, &out_height_)); |
| 1017 } | 1094 } |
| 1018 | 1095 |
| 1019 // Test that we will adapt to max given a target pixel count close to max. | 1096 // Test that we will adapt to max given a target pixel count close to max. |
| 1020 TEST_F(VideoAdapterTest, TestAdaptToMax) { | 1097 TEST_F(VideoAdapterTest, TestAdaptToMax) { |
| 1021 adapter_.OnOutputFormatRequest(VideoFormat(640, 360, 0, FOURCC_I420)); | 1098 adapter_.OnOutputFormatRequest(VideoFormat(640, 360, 0, FOURCC_I420)); |
| 1022 adapter_.OnResolutionRequest(rtc::Optional<int>(640 * 360 - 1) /* target */, | 1099 adapter_.OnResolutionFramerateRequest( |
| 1023 rtc::Optional<int>()); | 1100 rtc::Optional<int>(640 * 360 - 1) /* target */, rtc::Optional<int>(), |
| 1101 rtc::Optional<int>()); |
| 1024 | 1102 |
| 1025 EXPECT_TRUE(adapter_.AdaptFrameResolution(640, 360, 0, &cropped_width_, | 1103 EXPECT_TRUE(adapter_.AdaptFrameResolution(640, 360, 0, &cropped_width_, |
| 1026 &cropped_height_, &out_width_, | 1104 &cropped_height_, &out_width_, |
| 1027 &out_height_)); | 1105 &out_height_)); |
| 1028 EXPECT_EQ(640, out_width_); | 1106 EXPECT_EQ(640, out_width_); |
| 1029 EXPECT_EQ(360, out_height_); | 1107 EXPECT_EQ(360, out_height_); |
| 1030 } | 1108 } |
| 1031 | |
| 1032 } // namespace cricket | 1109 } // namespace cricket |
| OLD | NEW |