| 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 |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 50 bool last_adapt_was_no_op; | 50 bool last_adapt_was_no_op; |
| 51 | 51 |
| 52 int cropped_width; | 52 int cropped_width; |
| 53 int cropped_height; | 53 int cropped_height; |
| 54 int out_width; | 54 int out_width; |
| 55 int out_height; | 55 int out_height; |
| 56 }; | 56 }; |
| 57 | 57 |
| 58 explicit VideoCapturerListener(VideoAdapter* adapter) | 58 explicit VideoCapturerListener(VideoAdapter* adapter) |
| 59 : video_adapter_(adapter), | 59 : video_adapter_(adapter), |
| 60 cropped_width_(0), |
| 61 cropped_height_(0), |
| 62 out_width_(0), |
| 63 out_height_(0), |
| 60 captured_frames_(0), | 64 captured_frames_(0), |
| 61 dropped_frames_(0), | 65 dropped_frames_(0), |
| 62 last_adapt_was_no_op_(false) { | 66 last_adapt_was_no_op_(false) {} |
| 63 } | |
| 64 | 67 |
| 65 void OnFrame(const webrtc::VideoFrame& frame) { | 68 void OnFrame(const webrtc::VideoFrame& frame) { |
| 66 rtc::CritScope lock(&crit_); | 69 rtc::CritScope lock(&crit_); |
| 67 const int in_width = frame.width(); | 70 const int in_width = frame.width(); |
| 68 const int in_height = frame.height(); | 71 const int in_height = frame.height(); |
| 69 int cropped_width; | 72 int cropped_width; |
| 70 int cropped_height; | 73 int cropped_height; |
| 71 int out_width; | 74 int out_width; |
| 72 int out_height; | 75 int out_height; |
| 73 if (video_adapter_->AdaptFrameResolution( | 76 if (video_adapter_->AdaptFrameResolution( |
| (...skipping 612 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 686 TEST_F(VideoAdapterTest, TestOnResolutionRequestInSmallSteps) { | 689 TEST_F(VideoAdapterTest, TestOnResolutionRequestInSmallSteps) { |
| 687 EXPECT_TRUE(adapter_.AdaptFrameResolution(1280, 720, 0, | 690 EXPECT_TRUE(adapter_.AdaptFrameResolution(1280, 720, 0, |
| 688 &cropped_width_, &cropped_height_, | 691 &cropped_width_, &cropped_height_, |
| 689 &out_width_, &out_height_)); | 692 &out_width_, &out_height_)); |
| 690 EXPECT_EQ(1280, cropped_width_); | 693 EXPECT_EQ(1280, cropped_width_); |
| 691 EXPECT_EQ(720, cropped_height_); | 694 EXPECT_EQ(720, cropped_height_); |
| 692 EXPECT_EQ(1280, out_width_); | 695 EXPECT_EQ(1280, out_width_); |
| 693 EXPECT_EQ(720, out_height_); | 696 EXPECT_EQ(720, out_height_); |
| 694 | 697 |
| 695 // Adapt down one step. | 698 // Adapt down one step. |
| 696 adapter_.OnResolutionRequest(rtc::Optional<int>(1280 * 720 - 1), | 699 adapter_.OnResolutionRequest(rtc::Optional<int>(), |
| 697 rtc::Optional<int>()); | 700 rtc::Optional<int>(1280 * 720 - 1)); |
| 698 EXPECT_TRUE(adapter_.AdaptFrameResolution(1280, 720, 0, | 701 EXPECT_TRUE(adapter_.AdaptFrameResolution(1280, 720, 0, |
| 699 &cropped_width_, &cropped_height_, | 702 &cropped_width_, &cropped_height_, |
| 700 &out_width_, &out_height_)); | 703 &out_width_, &out_height_)); |
| 701 EXPECT_EQ(1280, cropped_width_); | 704 EXPECT_EQ(1280, cropped_width_); |
| 702 EXPECT_EQ(720, cropped_height_); | 705 EXPECT_EQ(720, cropped_height_); |
| 703 EXPECT_EQ(960, out_width_); | 706 EXPECT_EQ(960, out_width_); |
| 704 EXPECT_EQ(540, out_height_); | 707 EXPECT_EQ(540, out_height_); |
| 705 | 708 |
| 706 // Adapt down one step more. | 709 // Adapt down one step more. |
| 707 adapter_.OnResolutionRequest(rtc::Optional<int>(960 * 540 - 1), | 710 adapter_.OnResolutionRequest(rtc::Optional<int>(), |
| 708 rtc::Optional<int>()); | 711 rtc::Optional<int>(960 * 540 - 1)); |
| 709 EXPECT_TRUE(adapter_.AdaptFrameResolution(1280, 720, 0, | 712 EXPECT_TRUE(adapter_.AdaptFrameResolution(1280, 720, 0, |
| 710 &cropped_width_, &cropped_height_, | 713 &cropped_width_, &cropped_height_, |
| 711 &out_width_, &out_height_)); | 714 &out_width_, &out_height_)); |
| 712 EXPECT_EQ(1280, cropped_width_); | 715 EXPECT_EQ(1280, cropped_width_); |
| 713 EXPECT_EQ(720, cropped_height_); | 716 EXPECT_EQ(720, cropped_height_); |
| 714 EXPECT_EQ(640, out_width_); | 717 EXPECT_EQ(640, out_width_); |
| 715 EXPECT_EQ(360, out_height_); | 718 EXPECT_EQ(360, out_height_); |
| 716 | 719 |
| 717 // Adapt down one step more. | 720 // Adapt down one step more. |
| 718 adapter_.OnResolutionRequest(rtc::Optional<int>(640 * 360 - 1), | 721 adapter_.OnResolutionRequest(rtc::Optional<int>(), |
| 719 rtc::Optional<int>()); | 722 rtc::Optional<int>(640 * 360 - 1)); |
| 720 EXPECT_TRUE(adapter_.AdaptFrameResolution(1280, 720, 0, | 723 EXPECT_TRUE(adapter_.AdaptFrameResolution(1280, 720, 0, |
| 721 &cropped_width_, &cropped_height_, | 724 &cropped_width_, &cropped_height_, |
| 722 &out_width_, &out_height_)); | 725 &out_width_, &out_height_)); |
| 723 EXPECT_EQ(1280, cropped_width_); | 726 EXPECT_EQ(1280, cropped_width_); |
| 724 EXPECT_EQ(720, cropped_height_); | 727 EXPECT_EQ(720, cropped_height_); |
| 725 EXPECT_EQ(480, out_width_); | 728 EXPECT_EQ(480, out_width_); |
| 726 EXPECT_EQ(270, out_height_); | 729 EXPECT_EQ(270, out_height_); |
| 727 | 730 |
| 728 // Adapt up one step. | 731 // Adapt up one step. |
| 729 adapter_.OnResolutionRequest(rtc::Optional<int>(), | 732 adapter_.OnResolutionRequest(rtc::Optional<int>(640 * 360), |
| 730 rtc::Optional<int>(480 * 270)); | 733 rtc::Optional<int>(960 * 540)); |
| 731 EXPECT_TRUE(adapter_.AdaptFrameResolution(1280, 720, 0, | 734 EXPECT_TRUE(adapter_.AdaptFrameResolution(1280, 720, 0, |
| 732 &cropped_width_, &cropped_height_, | 735 &cropped_width_, &cropped_height_, |
| 733 &out_width_, &out_height_)); | 736 &out_width_, &out_height_)); |
| 734 EXPECT_EQ(1280, cropped_width_); | 737 EXPECT_EQ(1280, cropped_width_); |
| 735 EXPECT_EQ(720, cropped_height_); | 738 EXPECT_EQ(720, cropped_height_); |
| 736 EXPECT_EQ(640, out_width_); | 739 EXPECT_EQ(640, out_width_); |
| 737 EXPECT_EQ(360, out_height_); | 740 EXPECT_EQ(360, out_height_); |
| 738 | 741 |
| 739 // Adapt up one step more. | 742 // Adapt up one step more. |
| 740 adapter_.OnResolutionRequest(rtc::Optional<int>(), | 743 adapter_.OnResolutionRequest(rtc::Optional<int>(960 * 540), |
| 741 rtc::Optional<int>(640 * 360)); | 744 rtc::Optional<int>(1280 * 720)); |
| 742 EXPECT_TRUE(adapter_.AdaptFrameResolution(1280, 720, 0, | 745 EXPECT_TRUE(adapter_.AdaptFrameResolution(1280, 720, 0, |
| 743 &cropped_width_, &cropped_height_, | 746 &cropped_width_, &cropped_height_, |
| 744 &out_width_, &out_height_)); | 747 &out_width_, &out_height_)); |
| 745 EXPECT_EQ(1280, cropped_width_); | 748 EXPECT_EQ(1280, cropped_width_); |
| 746 EXPECT_EQ(720, cropped_height_); | 749 EXPECT_EQ(720, cropped_height_); |
| 747 EXPECT_EQ(960, out_width_); | 750 EXPECT_EQ(960, out_width_); |
| 748 EXPECT_EQ(540, out_height_); | 751 EXPECT_EQ(540, out_height_); |
| 749 | 752 |
| 750 // Adapt up one step more. | 753 // Adapt up one step more. |
| 751 adapter_.OnResolutionRequest(rtc::Optional<int>(), | 754 adapter_.OnResolutionRequest(rtc::Optional<int>(1280 * 720), |
| 752 rtc::Optional<int>(960 * 720)); | 755 rtc::Optional<int>(1920 * 1080)); |
| 753 EXPECT_TRUE(adapter_.AdaptFrameResolution(1280, 720, 0, | 756 EXPECT_TRUE(adapter_.AdaptFrameResolution(1280, 720, 0, |
| 754 &cropped_width_, &cropped_height_, | 757 &cropped_width_, &cropped_height_, |
| 755 &out_width_, &out_height_)); | 758 &out_width_, &out_height_)); |
| 756 EXPECT_EQ(1280, cropped_width_); | 759 EXPECT_EQ(1280, cropped_width_); |
| 757 EXPECT_EQ(720, cropped_height_); | 760 EXPECT_EQ(720, cropped_height_); |
| 758 EXPECT_EQ(1280, out_width_); | 761 EXPECT_EQ(1280, out_width_); |
| 759 EXPECT_EQ(720, out_height_); | 762 EXPECT_EQ(720, out_height_); |
| 760 } | 763 } |
| 761 | 764 |
| 762 TEST_F(VideoAdapterTest, TestOnResolutionRequestMaxZero) { | 765 TEST_F(VideoAdapterTest, TestOnResolutionRequestMaxZero) { |
| 763 EXPECT_TRUE(adapter_.AdaptFrameResolution(1280, 720, 0, | 766 EXPECT_TRUE(adapter_.AdaptFrameResolution(1280, 720, 0, |
| 764 &cropped_width_, &cropped_height_, | 767 &cropped_width_, &cropped_height_, |
| 765 &out_width_, &out_height_)); | 768 &out_width_, &out_height_)); |
| 766 EXPECT_EQ(1280, cropped_width_); | 769 EXPECT_EQ(1280, cropped_width_); |
| 767 EXPECT_EQ(720, cropped_height_); | 770 EXPECT_EQ(720, cropped_height_); |
| 768 EXPECT_EQ(1280, out_width_); | 771 EXPECT_EQ(1280, out_width_); |
| 769 EXPECT_EQ(720, out_height_); | 772 EXPECT_EQ(720, out_height_); |
| 770 | 773 |
| 771 adapter_.OnResolutionRequest(rtc::Optional<int>(0), rtc::Optional<int>()); | 774 adapter_.OnResolutionRequest(rtc::Optional<int>(), rtc::Optional<int>(0)); |
| 772 EXPECT_FALSE(adapter_.AdaptFrameResolution(1280, 720, 0, | 775 EXPECT_FALSE(adapter_.AdaptFrameResolution(1280, 720, 0, |
| 773 &cropped_width_, &cropped_height_, | 776 &cropped_width_, &cropped_height_, |
| 774 &out_width_, &out_height_)); | 777 &out_width_, &out_height_)); |
| 775 } | 778 } |
| 776 | 779 |
| 777 TEST_F(VideoAdapterTest, TestOnResolutionRequestInLargeSteps) { | 780 TEST_F(VideoAdapterTest, TestOnResolutionRequestInLargeSteps) { |
| 778 adapter_.OnResolutionRequest(rtc::Optional<int>(640 * 360 - 1), | 781 // Large step down. |
| 779 rtc::Optional<int>()); | 782 adapter_.OnResolutionRequest(rtc::Optional<int>(), |
| 783 rtc::Optional<int>(640 * 360 - 1)); |
| 780 EXPECT_TRUE(adapter_.AdaptFrameResolution(1280, 720, 0, | 784 EXPECT_TRUE(adapter_.AdaptFrameResolution(1280, 720, 0, |
| 781 &cropped_width_, &cropped_height_, | 785 &cropped_width_, &cropped_height_, |
| 782 &out_width_, &out_height_)); | 786 &out_width_, &out_height_)); |
| 783 EXPECT_EQ(1280, cropped_width_); | 787 EXPECT_EQ(1280, cropped_width_); |
| 784 EXPECT_EQ(720, cropped_height_); | 788 EXPECT_EQ(720, cropped_height_); |
| 785 EXPECT_EQ(480, out_width_); | 789 EXPECT_EQ(480, out_width_); |
| 786 EXPECT_EQ(270, out_height_); | 790 EXPECT_EQ(270, out_height_); |
| 787 | 791 |
| 788 adapter_.OnResolutionRequest(rtc::Optional<int>(), | 792 // Large step up. |
| 789 rtc::Optional<int>(960 * 720)); | 793 adapter_.OnResolutionRequest(rtc::Optional<int>(1280 * 720), |
| 794 rtc::Optional<int>(1920 * 1080)); |
| 790 EXPECT_TRUE(adapter_.AdaptFrameResolution(1280, 720, 0, | 795 EXPECT_TRUE(adapter_.AdaptFrameResolution(1280, 720, 0, |
| 791 &cropped_width_, &cropped_height_, | 796 &cropped_width_, &cropped_height_, |
| 792 &out_width_, &out_height_)); | 797 &out_width_, &out_height_)); |
| 793 EXPECT_EQ(1280, cropped_width_); | 798 EXPECT_EQ(1280, cropped_width_); |
| 794 EXPECT_EQ(720, cropped_height_); | 799 EXPECT_EQ(720, cropped_height_); |
| 795 EXPECT_EQ(1280, out_width_); | 800 EXPECT_EQ(1280, out_width_); |
| 796 EXPECT_EQ(720, out_height_); | 801 EXPECT_EQ(720, out_height_); |
| 797 } | 802 } |
| 798 | 803 |
| 799 TEST_F(VideoAdapterTest, TestOnOutputFormatRequestCapsMaxResolution) { | 804 TEST_F(VideoAdapterTest, TestOnOutputFormatRequestCapsMaxResolution) { |
| (...skipping 10 matching lines...) Expand all Loading... |
| 810 VideoFormat new_format(640, 360, 0, FOURCC_I420); | 815 VideoFormat new_format(640, 360, 0, FOURCC_I420); |
| 811 adapter_.OnOutputFormatRequest(new_format); | 816 adapter_.OnOutputFormatRequest(new_format); |
| 812 EXPECT_TRUE(adapter_.AdaptFrameResolution(1280, 720, 0, | 817 EXPECT_TRUE(adapter_.AdaptFrameResolution(1280, 720, 0, |
| 813 &cropped_width_, &cropped_height_, | 818 &cropped_width_, &cropped_height_, |
| 814 &out_width_, &out_height_)); | 819 &out_width_, &out_height_)); |
| 815 EXPECT_EQ(1280, cropped_width_); | 820 EXPECT_EQ(1280, cropped_width_); |
| 816 EXPECT_EQ(720, cropped_height_); | 821 EXPECT_EQ(720, cropped_height_); |
| 817 EXPECT_EQ(480, out_width_); | 822 EXPECT_EQ(480, out_width_); |
| 818 EXPECT_EQ(270, out_height_); | 823 EXPECT_EQ(270, out_height_); |
| 819 | 824 |
| 820 adapter_.OnResolutionRequest(rtc::Optional<int>(), | 825 adapter_.OnResolutionRequest(rtc::Optional<int>(960 * 720), |
| 821 rtc::Optional<int>(960 * 720)); | 826 rtc::Optional<int>()); |
| 822 EXPECT_TRUE(adapter_.AdaptFrameResolution(1280, 720, 0, | 827 EXPECT_TRUE(adapter_.AdaptFrameResolution(1280, 720, 0, |
| 823 &cropped_width_, &cropped_height_, | 828 &cropped_width_, &cropped_height_, |
| 824 &out_width_, &out_height_)); | 829 &out_width_, &out_height_)); |
| 825 EXPECT_EQ(1280, cropped_width_); | 830 EXPECT_EQ(1280, cropped_width_); |
| 826 EXPECT_EQ(720, cropped_height_); | 831 EXPECT_EQ(720, cropped_height_); |
| 827 EXPECT_EQ(640, out_width_); | 832 EXPECT_EQ(640, out_width_); |
| 828 EXPECT_EQ(360, out_height_); | 833 EXPECT_EQ(360, out_height_); |
| 829 } | 834 } |
| 830 | 835 |
| 831 TEST_F(VideoAdapterTest, TestOnResolutionRequestReset) { | 836 TEST_F(VideoAdapterTest, TestOnResolutionRequestReset) { |
| 832 EXPECT_TRUE(adapter_.AdaptFrameResolution(1280, 720, 0, | 837 EXPECT_TRUE(adapter_.AdaptFrameResolution(1280, 720, 0, |
| 833 &cropped_width_, &cropped_height_, | 838 &cropped_width_, &cropped_height_, |
| 834 &out_width_, &out_height_)); | 839 &out_width_, &out_height_)); |
| 835 EXPECT_EQ(1280, cropped_width_); | 840 EXPECT_EQ(1280, cropped_width_); |
| 836 EXPECT_EQ(720, cropped_height_); | 841 EXPECT_EQ(720, cropped_height_); |
| 837 EXPECT_EQ(1280, out_width_); | 842 EXPECT_EQ(1280, out_width_); |
| 838 EXPECT_EQ(720, out_height_); | 843 EXPECT_EQ(720, out_height_); |
| 839 | 844 |
| 840 adapter_.OnResolutionRequest(rtc::Optional<int>(640 * 360 - 1), | 845 adapter_.OnResolutionRequest(rtc::Optional<int>(), |
| 841 rtc::Optional<int>()); | 846 rtc::Optional<int>(640 * 360 - 1)); |
| 842 EXPECT_TRUE(adapter_.AdaptFrameResolution(1280, 720, 0, | 847 EXPECT_TRUE(adapter_.AdaptFrameResolution(1280, 720, 0, |
| 843 &cropped_width_, &cropped_height_, | 848 &cropped_width_, &cropped_height_, |
| 844 &out_width_, &out_height_)); | 849 &out_width_, &out_height_)); |
| 845 EXPECT_EQ(1280, cropped_width_); | 850 EXPECT_EQ(1280, cropped_width_); |
| 846 EXPECT_EQ(720, cropped_height_); | 851 EXPECT_EQ(720, cropped_height_); |
| 847 EXPECT_EQ(480, out_width_); | 852 EXPECT_EQ(480, out_width_); |
| 848 EXPECT_EQ(270, out_height_); | 853 EXPECT_EQ(270, out_height_); |
| 849 | 854 |
| 850 adapter_.OnResolutionRequest(rtc::Optional<int>(), rtc::Optional<int>()); | 855 adapter_.OnResolutionRequest(rtc::Optional<int>(), rtc::Optional<int>()); |
| 851 EXPECT_TRUE(adapter_.AdaptFrameResolution(1280, 720, 0, | 856 EXPECT_TRUE(adapter_.AdaptFrameResolution(1280, 720, 0, |
| (...skipping 12 matching lines...) Expand all Loading... |
| 864 EXPECT_TRUE(adapter_.AdaptFrameResolution(640, 480, 0, | 869 EXPECT_TRUE(adapter_.AdaptFrameResolution(640, 480, 0, |
| 865 &cropped_width_, &cropped_height_, | 870 &cropped_width_, &cropped_height_, |
| 866 &out_width_, &out_height_)); | 871 &out_width_, &out_height_)); |
| 867 // Expect cropping to 16:9 format and no scaling. | 872 // Expect cropping to 16:9 format and no scaling. |
| 868 EXPECT_EQ(640, cropped_width_); | 873 EXPECT_EQ(640, cropped_width_); |
| 869 EXPECT_EQ(360, cropped_height_); | 874 EXPECT_EQ(360, cropped_height_); |
| 870 EXPECT_EQ(640, out_width_); | 875 EXPECT_EQ(640, out_width_); |
| 871 EXPECT_EQ(360, out_height_); | 876 EXPECT_EQ(360, out_height_); |
| 872 | 877 |
| 873 // Adapt down one step. | 878 // Adapt down one step. |
| 874 adapter_.OnResolutionRequest(rtc::Optional<int>(640 * 360 - 1), | 879 adapter_.OnResolutionRequest(rtc::Optional<int>(), |
| 875 rtc::Optional<int>()); | 880 rtc::Optional<int>(640 * 360 - 1)); |
| 876 // Expect cropping to 16:9 format and 3/4 scaling. | 881 // Expect cropping to 16:9 format and 3/4 scaling. |
| 877 EXPECT_TRUE(adapter_.AdaptFrameResolution(640, 480, 0, | 882 EXPECT_TRUE(adapter_.AdaptFrameResolution(640, 480, 0, |
| 878 &cropped_width_, &cropped_height_, | 883 &cropped_width_, &cropped_height_, |
| 879 &out_width_, &out_height_)); | 884 &out_width_, &out_height_)); |
| 880 EXPECT_EQ(640, cropped_width_); | 885 EXPECT_EQ(640, cropped_width_); |
| 881 EXPECT_EQ(360, cropped_height_); | 886 EXPECT_EQ(360, cropped_height_); |
| 882 EXPECT_EQ(480, out_width_); | 887 EXPECT_EQ(480, out_width_); |
| 883 EXPECT_EQ(270, out_height_); | 888 EXPECT_EQ(270, out_height_); |
| 884 | 889 |
| 885 // Adapt down one step more. | 890 // Adapt down one step more. |
| 886 adapter_.OnResolutionRequest(rtc::Optional<int>(480 * 270 - 1), | 891 adapter_.OnResolutionRequest(rtc::Optional<int>(), |
| 887 rtc::Optional<int>()); | 892 rtc::Optional<int>(480 * 270 - 1)); |
| 888 // Expect cropping to 16:9 format and 1/2 scaling. | 893 // Expect cropping to 16:9 format and 1/2 scaling. |
| 889 EXPECT_TRUE(adapter_.AdaptFrameResolution(640, 480, 0, | 894 EXPECT_TRUE(adapter_.AdaptFrameResolution(640, 480, 0, |
| 890 &cropped_width_, &cropped_height_, | 895 &cropped_width_, &cropped_height_, |
| 891 &out_width_, &out_height_)); | 896 &out_width_, &out_height_)); |
| 892 EXPECT_EQ(640, cropped_width_); | 897 EXPECT_EQ(640, cropped_width_); |
| 893 EXPECT_EQ(360, cropped_height_); | 898 EXPECT_EQ(360, cropped_height_); |
| 894 EXPECT_EQ(320, out_width_); | 899 EXPECT_EQ(320, out_width_); |
| 895 EXPECT_EQ(180, out_height_); | 900 EXPECT_EQ(180, out_height_); |
| 896 | 901 |
| 897 // Adapt up one step. | 902 // Adapt up one step. |
| 898 adapter_.OnResolutionRequest(rtc::Optional<int>(), | 903 adapter_.OnResolutionRequest(rtc::Optional<int>(480 * 270), |
| 899 rtc::Optional<int>(320 * 180)); | 904 rtc::Optional<int>(640 * 360)); |
| 900 // Expect cropping to 16:9 format and 3/4 scaling. | 905 // Expect cropping to 16:9 format and 3/4 scaling. |
| 901 EXPECT_TRUE(adapter_.AdaptFrameResolution(640, 480, 0, | 906 EXPECT_TRUE(adapter_.AdaptFrameResolution(640, 480, 0, |
| 902 &cropped_width_, &cropped_height_, | 907 &cropped_width_, &cropped_height_, |
| 903 &out_width_, &out_height_)); | 908 &out_width_, &out_height_)); |
| 904 EXPECT_EQ(640, cropped_width_); | 909 EXPECT_EQ(640, cropped_width_); |
| 905 EXPECT_EQ(360, cropped_height_); | 910 EXPECT_EQ(360, cropped_height_); |
| 906 EXPECT_EQ(480, out_width_); | 911 EXPECT_EQ(480, out_width_); |
| 907 EXPECT_EQ(270, out_height_); | 912 EXPECT_EQ(270, out_height_); |
| 908 | 913 |
| 909 // Adapt up one step more. | 914 // Adapt up one step more. |
| 910 adapter_.OnResolutionRequest(rtc::Optional<int>(), | 915 adapter_.OnResolutionRequest(rtc::Optional<int>(640 * 360), |
| 911 rtc::Optional<int>(480 * 270)); | 916 rtc::Optional<int>(960 * 540)); |
| 912 // Expect cropping to 16:9 format and no scaling. | 917 // Expect cropping to 16:9 format and no scaling. |
| 913 EXPECT_TRUE(adapter_.AdaptFrameResolution(640, 480, 0, | 918 EXPECT_TRUE(adapter_.AdaptFrameResolution(640, 480, 0, |
| 914 &cropped_width_, &cropped_height_, | 919 &cropped_width_, &cropped_height_, |
| 915 &out_width_, &out_height_)); | 920 &out_width_, &out_height_)); |
| 916 EXPECT_EQ(640, cropped_width_); | 921 EXPECT_EQ(640, cropped_width_); |
| 917 EXPECT_EQ(360, cropped_height_); | 922 EXPECT_EQ(360, cropped_height_); |
| 918 EXPECT_EQ(640, out_width_); | 923 EXPECT_EQ(640, out_width_); |
| 919 EXPECT_EQ(360, out_height_); | 924 EXPECT_EQ(360, out_height_); |
| 920 | 925 |
| 921 // Try to adapt up one step more. | 926 // Try to adapt up one step more. |
| 922 adapter_.OnResolutionRequest(rtc::Optional<int>(), | 927 adapter_.OnResolutionRequest(rtc::Optional<int>(960 * 540), |
| 923 rtc::Optional<int>(640 * 360)); | 928 rtc::Optional<int>(1280 * 720)); |
| 924 // Expect cropping to 16:9 format and no scaling. | 929 // Expect cropping to 16:9 format and no scaling. |
| 925 EXPECT_TRUE(adapter_.AdaptFrameResolution(640, 480, 0, | 930 EXPECT_TRUE(adapter_.AdaptFrameResolution(640, 480, 0, |
| 926 &cropped_width_, &cropped_height_, | 931 &cropped_width_, &cropped_height_, |
| 927 &out_width_, &out_height_)); | 932 &out_width_, &out_height_)); |
| 928 EXPECT_EQ(640, cropped_width_); | 933 EXPECT_EQ(640, cropped_width_); |
| 929 EXPECT_EQ(360, cropped_height_); | 934 EXPECT_EQ(360, cropped_height_); |
| 930 EXPECT_EQ(640, out_width_); | 935 EXPECT_EQ(640, out_width_); |
| 931 EXPECT_EQ(360, out_height_); | 936 EXPECT_EQ(360, out_height_); |
| 932 } | 937 } |
| 933 | 938 |
| 934 TEST_F(VideoAdapterTest, TestCroppingOddResolution) { | 939 TEST_F(VideoAdapterTest, TestCroppingOddResolution) { |
| 935 // Ask for 640x360 (16:9 aspect), with 3/16 scaling. | 940 // Ask for 640x360 (16:9 aspect), with 3/16 scaling. |
| 936 adapter_.OnOutputFormatRequest( | 941 adapter_.OnOutputFormatRequest( |
| 937 VideoFormat(640, 360, 0, FOURCC_I420)); | 942 VideoFormat(640, 360, 0, FOURCC_I420)); |
| 938 adapter_.OnResolutionRequest(rtc::Optional<int>(640 * 360 * 3 / 16 * 3 / 16), | 943 adapter_.OnResolutionRequest(rtc::Optional<int>(), |
| 939 rtc::Optional<int>()); | 944 rtc::Optional<int>(640 * 360 * 3 / 16 * 3 / 16)); |
| 940 | 945 |
| 941 // Send 640x480 (4:3 aspect). | 946 // Send 640x480 (4:3 aspect). |
| 942 EXPECT_TRUE(adapter_.AdaptFrameResolution(640, 480, 0, | 947 EXPECT_TRUE(adapter_.AdaptFrameResolution(640, 480, 0, |
| 943 &cropped_width_, &cropped_height_, | 948 &cropped_width_, &cropped_height_, |
| 944 &out_width_, &out_height_)); | 949 &out_width_, &out_height_)); |
| 945 | 950 |
| 946 // Instead of getting the exact aspect ratio with cropped resolution 640x360, | 951 // Instead of getting the exact aspect ratio with cropped resolution 640x360, |
| 947 // the resolution should be adjusted to get a perfect scale factor instead. | 952 // the resolution should be adjusted to get a perfect scale factor instead. |
| 948 EXPECT_EQ(640, cropped_width_); | 953 EXPECT_EQ(640, cropped_width_); |
| 949 EXPECT_EQ(368, cropped_height_); | 954 EXPECT_EQ(368, cropped_height_); |
| 950 EXPECT_EQ(120, out_width_); | 955 EXPECT_EQ(120, out_width_); |
| 951 EXPECT_EQ(69, out_height_); | 956 EXPECT_EQ(69, out_height_); |
| 952 } | 957 } |
| 953 | 958 |
| 954 TEST_F(VideoAdapterTest, TestAdaptToVerySmallResolution) { | 959 TEST_F(VideoAdapterTest, TestAdaptToVerySmallResolution) { |
| 955 // Ask for 1920x1080 (16:9 aspect), with 1/16 scaling. | 960 // Ask for 1920x1080 (16:9 aspect), with 1/16 scaling. |
| 956 const int w = 1920; | 961 const int w = 1920; |
| 957 const int h = 1080; | 962 const int h = 1080; |
| 958 adapter_.OnOutputFormatRequest(VideoFormat(w, h, 0, FOURCC_I420)); | 963 adapter_.OnOutputFormatRequest(VideoFormat(w, h, 0, FOURCC_I420)); |
| 959 adapter_.OnResolutionRequest(rtc::Optional<int>(w * h * 1 / 16 * 1 / 16), | 964 adapter_.OnResolutionRequest(rtc::Optional<int>(), |
| 960 rtc::Optional<int>()); | 965 rtc::Optional<int>(w * h * 1 / 16 * 1 / 16)); |
| 961 | 966 |
| 962 // Send 1920x1080 (16:9 aspect). | 967 // Send 1920x1080 (16:9 aspect). |
| 963 EXPECT_TRUE(adapter_.AdaptFrameResolution( | 968 EXPECT_TRUE(adapter_.AdaptFrameResolution( |
| 964 w, h, 0, &cropped_width_, &cropped_height_, &out_width_, &out_height_)); | 969 w, h, 0, &cropped_width_, &cropped_height_, &out_width_, &out_height_)); |
| 965 | 970 |
| 966 // Instead of getting the exact aspect ratio with cropped resolution 1920x1080 | 971 // Instead of getting the exact aspect ratio with cropped resolution 1920x1080 |
| 967 // the resolution should be adjusted to get a perfect scale factor instead. | 972 // the resolution should be adjusted to get a perfect scale factor instead. |
| 968 EXPECT_EQ(1920, cropped_width_); | 973 EXPECT_EQ(1920, cropped_width_); |
| 969 EXPECT_EQ(1072, cropped_height_); | 974 EXPECT_EQ(1072, cropped_height_); |
| 970 EXPECT_EQ(120, out_width_); | 975 EXPECT_EQ(120, out_width_); |
| 971 EXPECT_EQ(67, out_height_); | 976 EXPECT_EQ(67, out_height_); |
| 972 | 977 |
| 973 // Adapt back up one step to 3/32. | 978 // Adapt back up one step to 3/32. |
| 974 adapter_.OnResolutionRequest(rtc::Optional<int>(), | 979 adapter_.OnResolutionRequest(rtc::Optional<int>(w * h * 3 / 32 * 3 / 32), |
| 975 rtc::Optional<int>(w * h * 1 / 16 * 1 / 16)); | 980 rtc::Optional<int>(w * h * 1 / 8 * 1 / 8)); |
| 976 | 981 |
| 977 // Send 1920x1080 (16:9 aspect). | 982 // Send 1920x1080 (16:9 aspect). |
| 978 EXPECT_TRUE(adapter_.AdaptFrameResolution( | 983 EXPECT_TRUE(adapter_.AdaptFrameResolution( |
| 979 w, h, 0, &cropped_width_, &cropped_height_, &out_width_, &out_height_)); | 984 w, h, 0, &cropped_width_, &cropped_height_, &out_width_, &out_height_)); |
| 980 | 985 |
| 981 EXPECT_EQ(180, out_width_); | 986 EXPECT_EQ(180, out_width_); |
| 982 EXPECT_EQ(99, out_height_); | 987 EXPECT_EQ(99, out_height_); |
| 983 } | 988 } |
| 984 | 989 |
| 985 TEST_F(VideoAdapterTest, AdaptFrameResolutionDropWithResolutionRequest) { | 990 TEST_F(VideoAdapterTest, AdaptFrameResolutionDropWithResolutionRequest) { |
| 986 VideoFormat output_format = capture_format_; | 991 VideoFormat output_format = capture_format_; |
| 987 output_format.width = 0; | 992 output_format.width = 0; |
| 988 output_format.height = 0; | 993 output_format.height = 0; |
| 989 adapter_.OnOutputFormatRequest(output_format); | 994 adapter_.OnOutputFormatRequest(output_format); |
| 990 EXPECT_FALSE(adapter_.AdaptFrameResolution( | 995 EXPECT_FALSE(adapter_.AdaptFrameResolution( |
| 991 capture_format_.width, capture_format_.height, 0, | 996 capture_format_.width, capture_format_.height, 0, |
| 992 &cropped_width_, &cropped_height_, | 997 &cropped_width_, &cropped_height_, |
| 993 &out_width_, &out_height_)); | 998 &out_width_, &out_height_)); |
| 994 | 999 |
| 995 adapter_.OnResolutionRequest(rtc::Optional<int>(), | 1000 adapter_.OnResolutionRequest(rtc::Optional<int>(960 * 540), |
| 996 rtc::Optional<int>(640 * 480)); | 1001 rtc::Optional<int>()); |
| 997 | 1002 |
| 998 // Still expect all frames to be dropped | 1003 // Still expect all frames to be dropped |
| 999 EXPECT_FALSE(adapter_.AdaptFrameResolution( | 1004 EXPECT_FALSE(adapter_.AdaptFrameResolution( |
| 1000 capture_format_.width, capture_format_.height, 0, | 1005 capture_format_.width, capture_format_.height, 0, |
| 1001 &cropped_width_, &cropped_height_, | 1006 &cropped_width_, &cropped_height_, |
| 1002 &out_width_, &out_height_)); | 1007 &out_width_, &out_height_)); |
| 1003 | 1008 |
| 1004 adapter_.OnResolutionRequest(rtc::Optional<int>(640 * 480 - 1), | 1009 adapter_.OnResolutionRequest(rtc::Optional<int>(), |
| 1005 rtc::Optional<int>()); | 1010 rtc::Optional<int>(640 * 480 - 1)); |
| 1006 | 1011 |
| 1007 // Still expect all frames to be dropped | 1012 // Still expect all frames to be dropped |
| 1008 EXPECT_FALSE(adapter_.AdaptFrameResolution( | 1013 EXPECT_FALSE(adapter_.AdaptFrameResolution( |
| 1009 capture_format_.width, capture_format_.height, 0, | 1014 capture_format_.width, capture_format_.height, 0, |
| 1010 &cropped_width_, &cropped_height_, | 1015 &cropped_width_, &cropped_height_, |
| 1011 &out_width_, &out_height_)); | 1016 &out_width_, &out_height_)); |
| 1012 } | 1017 } |
| 1013 | 1018 |
| 1014 } // namespace cricket | 1019 } // namespace cricket |
| OLD | NEW |