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 678 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
689 TEST_F(VideoAdapterTest, TestOnResolutionRequestInSmallSteps) { | 689 TEST_F(VideoAdapterTest, TestOnResolutionRequestInSmallSteps) { |
690 EXPECT_TRUE(adapter_.AdaptFrameResolution(1280, 720, 0, | 690 EXPECT_TRUE(adapter_.AdaptFrameResolution(1280, 720, 0, |
691 &cropped_width_, &cropped_height_, | 691 &cropped_width_, &cropped_height_, |
692 &out_width_, &out_height_)); | 692 &out_width_, &out_height_)); |
693 EXPECT_EQ(1280, cropped_width_); | 693 EXPECT_EQ(1280, cropped_width_); |
694 EXPECT_EQ(720, cropped_height_); | 694 EXPECT_EQ(720, cropped_height_); |
695 EXPECT_EQ(1280, out_width_); | 695 EXPECT_EQ(1280, out_width_); |
696 EXPECT_EQ(720, out_height_); | 696 EXPECT_EQ(720, out_height_); |
697 | 697 |
698 // Adapt down one step. | 698 // Adapt down one step. |
699 adapter_.OnResolutionRequest(rtc::Optional<int>(), | 699 adapter_.OnResolutionFramerateRequest(rtc::Optional<int>(), |
700 rtc::Optional<int>(1280 * 720 - 1)); | 700 rtc::Optional<int>(1280 * 720 - 1), |
| 701 rtc::Optional<int>()); |
701 EXPECT_TRUE(adapter_.AdaptFrameResolution(1280, 720, 0, | 702 EXPECT_TRUE(adapter_.AdaptFrameResolution(1280, 720, 0, |
702 &cropped_width_, &cropped_height_, | 703 &cropped_width_, &cropped_height_, |
703 &out_width_, &out_height_)); | 704 &out_width_, &out_height_)); |
704 EXPECT_EQ(1280, cropped_width_); | 705 EXPECT_EQ(1280, cropped_width_); |
705 EXPECT_EQ(720, cropped_height_); | 706 EXPECT_EQ(720, cropped_height_); |
706 EXPECT_EQ(960, out_width_); | 707 EXPECT_EQ(960, out_width_); |
707 EXPECT_EQ(540, out_height_); | 708 EXPECT_EQ(540, out_height_); |
708 | 709 |
709 // Adapt down one step more. | 710 // Adapt down one step more. |
710 adapter_.OnResolutionRequest(rtc::Optional<int>(), | 711 adapter_.OnResolutionFramerateRequest(rtc::Optional<int>(), |
711 rtc::Optional<int>(960 * 540 - 1)); | 712 rtc::Optional<int>(960 * 540 - 1), |
| 713 rtc::Optional<int>()); |
712 EXPECT_TRUE(adapter_.AdaptFrameResolution(1280, 720, 0, | 714 EXPECT_TRUE(adapter_.AdaptFrameResolution(1280, 720, 0, |
713 &cropped_width_, &cropped_height_, | 715 &cropped_width_, &cropped_height_, |
714 &out_width_, &out_height_)); | 716 &out_width_, &out_height_)); |
715 EXPECT_EQ(1280, cropped_width_); | 717 EXPECT_EQ(1280, cropped_width_); |
716 EXPECT_EQ(720, cropped_height_); | 718 EXPECT_EQ(720, cropped_height_); |
717 EXPECT_EQ(640, out_width_); | 719 EXPECT_EQ(640, out_width_); |
718 EXPECT_EQ(360, out_height_); | 720 EXPECT_EQ(360, out_height_); |
719 | 721 |
720 // Adapt down one step more. | 722 // Adapt down one step more. |
721 adapter_.OnResolutionRequest(rtc::Optional<int>(), | 723 adapter_.OnResolutionFramerateRequest(rtc::Optional<int>(), |
722 rtc::Optional<int>(640 * 360 - 1)); | 724 rtc::Optional<int>(640 * 360 - 1), |
| 725 rtc::Optional<int>()); |
723 EXPECT_TRUE(adapter_.AdaptFrameResolution(1280, 720, 0, | 726 EXPECT_TRUE(adapter_.AdaptFrameResolution(1280, 720, 0, |
724 &cropped_width_, &cropped_height_, | 727 &cropped_width_, &cropped_height_, |
725 &out_width_, &out_height_)); | 728 &out_width_, &out_height_)); |
726 EXPECT_EQ(1280, cropped_width_); | 729 EXPECT_EQ(1280, cropped_width_); |
727 EXPECT_EQ(720, cropped_height_); | 730 EXPECT_EQ(720, cropped_height_); |
728 EXPECT_EQ(480, out_width_); | 731 EXPECT_EQ(480, out_width_); |
729 EXPECT_EQ(270, out_height_); | 732 EXPECT_EQ(270, out_height_); |
730 | 733 |
731 // Adapt up one step. | 734 // Adapt up one step. |
732 adapter_.OnResolutionRequest(rtc::Optional<int>(640 * 360), | 735 adapter_.OnResolutionFramerateRequest(rtc::Optional<int>(640 * 360), |
733 rtc::Optional<int>(960 * 540)); | 736 rtc::Optional<int>(960 * 540), |
| 737 rtc::Optional<int>()); |
734 EXPECT_TRUE(adapter_.AdaptFrameResolution(1280, 720, 0, | 738 EXPECT_TRUE(adapter_.AdaptFrameResolution(1280, 720, 0, |
735 &cropped_width_, &cropped_height_, | 739 &cropped_width_, &cropped_height_, |
736 &out_width_, &out_height_)); | 740 &out_width_, &out_height_)); |
737 EXPECT_EQ(1280, cropped_width_); | 741 EXPECT_EQ(1280, cropped_width_); |
738 EXPECT_EQ(720, cropped_height_); | 742 EXPECT_EQ(720, cropped_height_); |
739 EXPECT_EQ(640, out_width_); | 743 EXPECT_EQ(640, out_width_); |
740 EXPECT_EQ(360, out_height_); | 744 EXPECT_EQ(360, out_height_); |
741 | 745 |
742 // Adapt up one step more. | 746 // Adapt up one step more. |
743 adapter_.OnResolutionRequest(rtc::Optional<int>(960 * 540), | 747 adapter_.OnResolutionFramerateRequest(rtc::Optional<int>(960 * 540), |
744 rtc::Optional<int>(1280 * 720)); | 748 rtc::Optional<int>(1280 * 720), |
| 749 rtc::Optional<int>()); |
745 EXPECT_TRUE(adapter_.AdaptFrameResolution(1280, 720, 0, | 750 EXPECT_TRUE(adapter_.AdaptFrameResolution(1280, 720, 0, |
746 &cropped_width_, &cropped_height_, | 751 &cropped_width_, &cropped_height_, |
747 &out_width_, &out_height_)); | 752 &out_width_, &out_height_)); |
748 EXPECT_EQ(1280, cropped_width_); | 753 EXPECT_EQ(1280, cropped_width_); |
749 EXPECT_EQ(720, cropped_height_); | 754 EXPECT_EQ(720, cropped_height_); |
750 EXPECT_EQ(960, out_width_); | 755 EXPECT_EQ(960, out_width_); |
751 EXPECT_EQ(540, out_height_); | 756 EXPECT_EQ(540, out_height_); |
752 | 757 |
753 // Adapt up one step more. | 758 // Adapt up one step more. |
754 adapter_.OnResolutionRequest(rtc::Optional<int>(1280 * 720), | 759 adapter_.OnResolutionFramerateRequest(rtc::Optional<int>(1280 * 720), |
755 rtc::Optional<int>(1920 * 1080)); | 760 rtc::Optional<int>(1920 * 1080), |
| 761 rtc::Optional<int>()); |
756 EXPECT_TRUE(adapter_.AdaptFrameResolution(1280, 720, 0, | 762 EXPECT_TRUE(adapter_.AdaptFrameResolution(1280, 720, 0, |
757 &cropped_width_, &cropped_height_, | 763 &cropped_width_, &cropped_height_, |
758 &out_width_, &out_height_)); | 764 &out_width_, &out_height_)); |
759 EXPECT_EQ(1280, cropped_width_); | 765 EXPECT_EQ(1280, cropped_width_); |
760 EXPECT_EQ(720, cropped_height_); | 766 EXPECT_EQ(720, cropped_height_); |
761 EXPECT_EQ(1280, out_width_); | 767 EXPECT_EQ(1280, out_width_); |
762 EXPECT_EQ(720, out_height_); | 768 EXPECT_EQ(720, out_height_); |
763 } | 769 } |
764 | 770 |
765 TEST_F(VideoAdapterTest, TestOnResolutionRequestMaxZero) { | 771 TEST_F(VideoAdapterTest, TestOnResolutionRequestMaxZero) { |
766 EXPECT_TRUE(adapter_.AdaptFrameResolution(1280, 720, 0, | 772 EXPECT_TRUE(adapter_.AdaptFrameResolution(1280, 720, 0, |
767 &cropped_width_, &cropped_height_, | 773 &cropped_width_, &cropped_height_, |
768 &out_width_, &out_height_)); | 774 &out_width_, &out_height_)); |
769 EXPECT_EQ(1280, cropped_width_); | 775 EXPECT_EQ(1280, cropped_width_); |
770 EXPECT_EQ(720, cropped_height_); | 776 EXPECT_EQ(720, cropped_height_); |
771 EXPECT_EQ(1280, out_width_); | 777 EXPECT_EQ(1280, out_width_); |
772 EXPECT_EQ(720, out_height_); | 778 EXPECT_EQ(720, out_height_); |
773 | 779 |
774 adapter_.OnResolutionRequest(rtc::Optional<int>(), rtc::Optional<int>(0)); | 780 adapter_.OnResolutionFramerateRequest( |
| 781 rtc::Optional<int>(), rtc::Optional<int>(0), rtc::Optional<int>()); |
775 EXPECT_FALSE(adapter_.AdaptFrameResolution(1280, 720, 0, | 782 EXPECT_FALSE(adapter_.AdaptFrameResolution(1280, 720, 0, |
776 &cropped_width_, &cropped_height_, | 783 &cropped_width_, &cropped_height_, |
777 &out_width_, &out_height_)); | 784 &out_width_, &out_height_)); |
778 } | 785 } |
779 | 786 |
780 TEST_F(VideoAdapterTest, TestOnResolutionRequestInLargeSteps) { | 787 TEST_F(VideoAdapterTest, TestOnResolutionRequestInLargeSteps) { |
781 // Large step down. | 788 // Large step down. |
782 adapter_.OnResolutionRequest(rtc::Optional<int>(), | 789 adapter_.OnResolutionFramerateRequest(rtc::Optional<int>(), |
783 rtc::Optional<int>(640 * 360 - 1)); | 790 rtc::Optional<int>(640 * 360 - 1), |
| 791 rtc::Optional<int>()); |
784 EXPECT_TRUE(adapter_.AdaptFrameResolution(1280, 720, 0, | 792 EXPECT_TRUE(adapter_.AdaptFrameResolution(1280, 720, 0, |
785 &cropped_width_, &cropped_height_, | 793 &cropped_width_, &cropped_height_, |
786 &out_width_, &out_height_)); | 794 &out_width_, &out_height_)); |
787 EXPECT_EQ(1280, cropped_width_); | 795 EXPECT_EQ(1280, cropped_width_); |
788 EXPECT_EQ(720, cropped_height_); | 796 EXPECT_EQ(720, cropped_height_); |
789 EXPECT_EQ(480, out_width_); | 797 EXPECT_EQ(480, out_width_); |
790 EXPECT_EQ(270, out_height_); | 798 EXPECT_EQ(270, out_height_); |
791 | 799 |
792 // Large step up. | 800 // Large step up. |
793 adapter_.OnResolutionRequest(rtc::Optional<int>(1280 * 720), | 801 adapter_.OnResolutionFramerateRequest(rtc::Optional<int>(1280 * 720), |
794 rtc::Optional<int>(1920 * 1080)); | 802 rtc::Optional<int>(1920 * 1080), |
| 803 rtc::Optional<int>()); |
795 EXPECT_TRUE(adapter_.AdaptFrameResolution(1280, 720, 0, | 804 EXPECT_TRUE(adapter_.AdaptFrameResolution(1280, 720, 0, |
796 &cropped_width_, &cropped_height_, | 805 &cropped_width_, &cropped_height_, |
797 &out_width_, &out_height_)); | 806 &out_width_, &out_height_)); |
798 EXPECT_EQ(1280, cropped_width_); | 807 EXPECT_EQ(1280, cropped_width_); |
799 EXPECT_EQ(720, cropped_height_); | 808 EXPECT_EQ(720, cropped_height_); |
800 EXPECT_EQ(1280, out_width_); | 809 EXPECT_EQ(1280, out_width_); |
801 EXPECT_EQ(720, out_height_); | 810 EXPECT_EQ(720, out_height_); |
802 } | 811 } |
803 | 812 |
804 TEST_F(VideoAdapterTest, TestOnOutputFormatRequestCapsMaxResolution) { | 813 TEST_F(VideoAdapterTest, TestOnOutputFormatRequestCapsMaxResolution) { |
805 adapter_.OnResolutionRequest(rtc::Optional<int>(), | 814 adapter_.OnResolutionFramerateRequest(rtc::Optional<int>(), |
806 rtc::Optional<int>(640 * 360 - 1)); | 815 rtc::Optional<int>(640 * 360 - 1), |
| 816 rtc::Optional<int>()); |
807 EXPECT_TRUE(adapter_.AdaptFrameResolution(1280, 720, 0, | 817 EXPECT_TRUE(adapter_.AdaptFrameResolution(1280, 720, 0, |
808 &cropped_width_, &cropped_height_, | 818 &cropped_width_, &cropped_height_, |
809 &out_width_, &out_height_)); | 819 &out_width_, &out_height_)); |
810 EXPECT_EQ(1280, cropped_width_); | 820 EXPECT_EQ(1280, cropped_width_); |
811 EXPECT_EQ(720, cropped_height_); | 821 EXPECT_EQ(720, cropped_height_); |
812 EXPECT_EQ(480, out_width_); | 822 EXPECT_EQ(480, out_width_); |
813 EXPECT_EQ(270, out_height_); | 823 EXPECT_EQ(270, out_height_); |
814 | 824 |
815 VideoFormat new_format(640, 360, 0, FOURCC_I420); | 825 VideoFormat new_format(640, 360, 0, FOURCC_I420); |
816 adapter_.OnOutputFormatRequest(new_format); | 826 adapter_.OnOutputFormatRequest(new_format); |
817 EXPECT_TRUE(adapter_.AdaptFrameResolution(1280, 720, 0, | 827 EXPECT_TRUE(adapter_.AdaptFrameResolution(1280, 720, 0, |
818 &cropped_width_, &cropped_height_, | 828 &cropped_width_, &cropped_height_, |
819 &out_width_, &out_height_)); | 829 &out_width_, &out_height_)); |
820 EXPECT_EQ(1280, cropped_width_); | 830 EXPECT_EQ(1280, cropped_width_); |
821 EXPECT_EQ(720, cropped_height_); | 831 EXPECT_EQ(720, cropped_height_); |
822 EXPECT_EQ(480, out_width_); | 832 EXPECT_EQ(480, out_width_); |
823 EXPECT_EQ(270, out_height_); | 833 EXPECT_EQ(270, out_height_); |
824 | 834 |
825 adapter_.OnResolutionRequest(rtc::Optional<int>(), | 835 adapter_.OnResolutionFramerateRequest(rtc::Optional<int>(), |
826 rtc::Optional<int>(960 * 720)); | 836 rtc::Optional<int>(960 * 720), |
| 837 rtc::Optional<int>()); |
827 EXPECT_TRUE(adapter_.AdaptFrameResolution(1280, 720, 0, | 838 EXPECT_TRUE(adapter_.AdaptFrameResolution(1280, 720, 0, |
828 &cropped_width_, &cropped_height_, | 839 &cropped_width_, &cropped_height_, |
829 &out_width_, &out_height_)); | 840 &out_width_, &out_height_)); |
830 EXPECT_EQ(1280, cropped_width_); | 841 EXPECT_EQ(1280, cropped_width_); |
831 EXPECT_EQ(720, cropped_height_); | 842 EXPECT_EQ(720, cropped_height_); |
832 EXPECT_EQ(640, out_width_); | 843 EXPECT_EQ(640, out_width_); |
833 EXPECT_EQ(360, out_height_); | 844 EXPECT_EQ(360, out_height_); |
834 } | 845 } |
835 | 846 |
836 TEST_F(VideoAdapterTest, TestOnResolutionRequestReset) { | 847 TEST_F(VideoAdapterTest, TestOnResolutionRequestReset) { |
837 EXPECT_TRUE(adapter_.AdaptFrameResolution(1280, 720, 0, | 848 EXPECT_TRUE(adapter_.AdaptFrameResolution(1280, 720, 0, |
838 &cropped_width_, &cropped_height_, | 849 &cropped_width_, &cropped_height_, |
839 &out_width_, &out_height_)); | 850 &out_width_, &out_height_)); |
840 EXPECT_EQ(1280, cropped_width_); | 851 EXPECT_EQ(1280, cropped_width_); |
841 EXPECT_EQ(720, cropped_height_); | 852 EXPECT_EQ(720, cropped_height_); |
842 EXPECT_EQ(1280, out_width_); | 853 EXPECT_EQ(1280, out_width_); |
843 EXPECT_EQ(720, out_height_); | 854 EXPECT_EQ(720, out_height_); |
844 | 855 |
845 adapter_.OnResolutionRequest(rtc::Optional<int>(), | 856 adapter_.OnResolutionFramerateRequest(rtc::Optional<int>(), |
846 rtc::Optional<int>(640 * 360 - 1)); | 857 rtc::Optional<int>(640 * 360 - 1), |
| 858 rtc::Optional<int>()); |
847 EXPECT_TRUE(adapter_.AdaptFrameResolution(1280, 720, 0, | 859 EXPECT_TRUE(adapter_.AdaptFrameResolution(1280, 720, 0, |
848 &cropped_width_, &cropped_height_, | 860 &cropped_width_, &cropped_height_, |
849 &out_width_, &out_height_)); | 861 &out_width_, &out_height_)); |
850 EXPECT_EQ(1280, cropped_width_); | 862 EXPECT_EQ(1280, cropped_width_); |
851 EXPECT_EQ(720, cropped_height_); | 863 EXPECT_EQ(720, cropped_height_); |
852 EXPECT_EQ(480, out_width_); | 864 EXPECT_EQ(480, out_width_); |
853 EXPECT_EQ(270, out_height_); | 865 EXPECT_EQ(270, out_height_); |
854 | 866 |
855 adapter_.OnResolutionRequest(rtc::Optional<int>(), rtc::Optional<int>()); | 867 adapter_.OnResolutionFramerateRequest( |
| 868 rtc::Optional<int>(), rtc::Optional<int>(), rtc::Optional<int>()); |
856 EXPECT_TRUE(adapter_.AdaptFrameResolution(1280, 720, 0, | 869 EXPECT_TRUE(adapter_.AdaptFrameResolution(1280, 720, 0, |
857 &cropped_width_, &cropped_height_, | 870 &cropped_width_, &cropped_height_, |
858 &out_width_, &out_height_)); | 871 &out_width_, &out_height_)); |
859 EXPECT_EQ(1280, cropped_width_); | 872 EXPECT_EQ(1280, cropped_width_); |
860 EXPECT_EQ(720, cropped_height_); | 873 EXPECT_EQ(720, cropped_height_); |
861 EXPECT_EQ(1280, out_width_); | 874 EXPECT_EQ(1280, out_width_); |
862 EXPECT_EQ(720, out_height_); | 875 EXPECT_EQ(720, out_height_); |
863 } | 876 } |
864 | 877 |
865 TEST_F(VideoAdapterTest, TestCroppingWithResolutionRequest) { | 878 TEST_F(VideoAdapterTest, TestCroppingWithResolutionRequest) { |
866 // Ask for 640x360 (16:9 aspect). | 879 // Ask for 640x360 (16:9 aspect). |
867 adapter_.OnOutputFormatRequest(VideoFormat(640, 360, 0, FOURCC_I420)); | 880 adapter_.OnOutputFormatRequest(VideoFormat(640, 360, 0, FOURCC_I420)); |
868 // Send 640x480 (4:3 aspect). | 881 // Send 640x480 (4:3 aspect). |
869 EXPECT_TRUE(adapter_.AdaptFrameResolution(640, 480, 0, | 882 EXPECT_TRUE(adapter_.AdaptFrameResolution(640, 480, 0, |
870 &cropped_width_, &cropped_height_, | 883 &cropped_width_, &cropped_height_, |
871 &out_width_, &out_height_)); | 884 &out_width_, &out_height_)); |
872 // Expect cropping to 16:9 format and no scaling. | 885 // Expect cropping to 16:9 format and no scaling. |
873 EXPECT_EQ(640, cropped_width_); | 886 EXPECT_EQ(640, cropped_width_); |
874 EXPECT_EQ(360, cropped_height_); | 887 EXPECT_EQ(360, cropped_height_); |
875 EXPECT_EQ(640, out_width_); | 888 EXPECT_EQ(640, out_width_); |
876 EXPECT_EQ(360, out_height_); | 889 EXPECT_EQ(360, out_height_); |
877 | 890 |
878 // Adapt down one step. | 891 // Adapt down one step. |
879 adapter_.OnResolutionRequest(rtc::Optional<int>(), | 892 adapter_.OnResolutionFramerateRequest(rtc::Optional<int>(), |
880 rtc::Optional<int>(640 * 360 - 1)); | 893 rtc::Optional<int>(640 * 360 - 1), |
| 894 rtc::Optional<int>()); |
881 // Expect cropping to 16:9 format and 3/4 scaling. | 895 // Expect cropping to 16:9 format and 3/4 scaling. |
882 EXPECT_TRUE(adapter_.AdaptFrameResolution(640, 480, 0, | 896 EXPECT_TRUE(adapter_.AdaptFrameResolution(640, 480, 0, |
883 &cropped_width_, &cropped_height_, | 897 &cropped_width_, &cropped_height_, |
884 &out_width_, &out_height_)); | 898 &out_width_, &out_height_)); |
885 EXPECT_EQ(640, cropped_width_); | 899 EXPECT_EQ(640, cropped_width_); |
886 EXPECT_EQ(360, cropped_height_); | 900 EXPECT_EQ(360, cropped_height_); |
887 EXPECT_EQ(480, out_width_); | 901 EXPECT_EQ(480, out_width_); |
888 EXPECT_EQ(270, out_height_); | 902 EXPECT_EQ(270, out_height_); |
889 | 903 |
890 // Adapt down one step more. | 904 // Adapt down one step more. |
891 adapter_.OnResolutionRequest(rtc::Optional<int>(), | 905 adapter_.OnResolutionFramerateRequest(rtc::Optional<int>(), |
892 rtc::Optional<int>(480 * 270 - 1)); | 906 rtc::Optional<int>(480 * 270 - 1), |
| 907 rtc::Optional<int>()); |
893 // Expect cropping to 16:9 format and 1/2 scaling. | 908 // Expect cropping to 16:9 format and 1/2 scaling. |
894 EXPECT_TRUE(adapter_.AdaptFrameResolution(640, 480, 0, | 909 EXPECT_TRUE(adapter_.AdaptFrameResolution(640, 480, 0, |
895 &cropped_width_, &cropped_height_, | 910 &cropped_width_, &cropped_height_, |
896 &out_width_, &out_height_)); | 911 &out_width_, &out_height_)); |
897 EXPECT_EQ(640, cropped_width_); | 912 EXPECT_EQ(640, cropped_width_); |
898 EXPECT_EQ(360, cropped_height_); | 913 EXPECT_EQ(360, cropped_height_); |
899 EXPECT_EQ(320, out_width_); | 914 EXPECT_EQ(320, out_width_); |
900 EXPECT_EQ(180, out_height_); | 915 EXPECT_EQ(180, out_height_); |
901 | 916 |
902 // Adapt up one step. | 917 // Adapt up one step. |
903 adapter_.OnResolutionRequest(rtc::Optional<int>(480 * 270), | 918 adapter_.OnResolutionFramerateRequest(rtc::Optional<int>(480 * 270), |
904 rtc::Optional<int>(640 * 360)); | 919 rtc::Optional<int>(640 * 360), |
| 920 rtc::Optional<int>()); |
905 // Expect cropping to 16:9 format and 3/4 scaling. | 921 // Expect cropping to 16:9 format and 3/4 scaling. |
906 EXPECT_TRUE(adapter_.AdaptFrameResolution(640, 480, 0, | 922 EXPECT_TRUE(adapter_.AdaptFrameResolution(640, 480, 0, |
907 &cropped_width_, &cropped_height_, | 923 &cropped_width_, &cropped_height_, |
908 &out_width_, &out_height_)); | 924 &out_width_, &out_height_)); |
909 EXPECT_EQ(640, cropped_width_); | 925 EXPECT_EQ(640, cropped_width_); |
910 EXPECT_EQ(360, cropped_height_); | 926 EXPECT_EQ(360, cropped_height_); |
911 EXPECT_EQ(480, out_width_); | 927 EXPECT_EQ(480, out_width_); |
912 EXPECT_EQ(270, out_height_); | 928 EXPECT_EQ(270, out_height_); |
913 | 929 |
914 // Adapt up one step more. | 930 // Adapt up one step more. |
915 adapter_.OnResolutionRequest(rtc::Optional<int>(640 * 360), | 931 adapter_.OnResolutionFramerateRequest(rtc::Optional<int>(640 * 360), |
916 rtc::Optional<int>(960 * 540)); | 932 rtc::Optional<int>(960 * 540), |
| 933 rtc::Optional<int>()); |
917 // Expect cropping to 16:9 format and no scaling. | 934 // Expect cropping to 16:9 format and no scaling. |
918 EXPECT_TRUE(adapter_.AdaptFrameResolution(640, 480, 0, | 935 EXPECT_TRUE(adapter_.AdaptFrameResolution(640, 480, 0, |
919 &cropped_width_, &cropped_height_, | 936 &cropped_width_, &cropped_height_, |
920 &out_width_, &out_height_)); | 937 &out_width_, &out_height_)); |
921 EXPECT_EQ(640, cropped_width_); | 938 EXPECT_EQ(640, cropped_width_); |
922 EXPECT_EQ(360, cropped_height_); | 939 EXPECT_EQ(360, cropped_height_); |
923 EXPECT_EQ(640, out_width_); | 940 EXPECT_EQ(640, out_width_); |
924 EXPECT_EQ(360, out_height_); | 941 EXPECT_EQ(360, out_height_); |
925 | 942 |
926 // Try to adapt up one step more. | 943 // Try to adapt up one step more. |
927 adapter_.OnResolutionRequest(rtc::Optional<int>(960 * 540), | 944 adapter_.OnResolutionFramerateRequest(rtc::Optional<int>(960 * 540), |
928 rtc::Optional<int>(1280 * 720)); | 945 rtc::Optional<int>(1280 * 720), |
| 946 rtc::Optional<int>()); |
929 // Expect cropping to 16:9 format and no scaling. | 947 // Expect cropping to 16:9 format and no scaling. |
930 EXPECT_TRUE(adapter_.AdaptFrameResolution(640, 480, 0, | 948 EXPECT_TRUE(adapter_.AdaptFrameResolution(640, 480, 0, |
931 &cropped_width_, &cropped_height_, | 949 &cropped_width_, &cropped_height_, |
932 &out_width_, &out_height_)); | 950 &out_width_, &out_height_)); |
933 EXPECT_EQ(640, cropped_width_); | 951 EXPECT_EQ(640, cropped_width_); |
934 EXPECT_EQ(360, cropped_height_); | 952 EXPECT_EQ(360, cropped_height_); |
935 EXPECT_EQ(640, out_width_); | 953 EXPECT_EQ(640, out_width_); |
936 EXPECT_EQ(360, out_height_); | 954 EXPECT_EQ(360, out_height_); |
937 } | 955 } |
938 | 956 |
939 TEST_F(VideoAdapterTest, TestCroppingOddResolution) { | 957 TEST_F(VideoAdapterTest, TestCroppingOddResolution) { |
940 // Ask for 640x360 (16:9 aspect), with 3/16 scaling. | 958 // Ask for 640x360 (16:9 aspect), with 3/16 scaling. |
941 adapter_.OnOutputFormatRequest( | 959 adapter_.OnOutputFormatRequest( |
942 VideoFormat(640, 360, 0, FOURCC_I420)); | 960 VideoFormat(640, 360, 0, FOURCC_I420)); |
943 adapter_.OnResolutionRequest(rtc::Optional<int>(), | 961 adapter_.OnResolutionFramerateRequest( |
944 rtc::Optional<int>(640 * 360 * 3 / 16 * 3 / 16)); | 962 rtc::Optional<int>(), rtc::Optional<int>(640 * 360 * 3 / 16 * 3 / 16), |
| 963 rtc::Optional<int>()); |
945 | 964 |
946 // Send 640x480 (4:3 aspect). | 965 // Send 640x480 (4:3 aspect). |
947 EXPECT_TRUE(adapter_.AdaptFrameResolution(640, 480, 0, | 966 EXPECT_TRUE(adapter_.AdaptFrameResolution(640, 480, 0, |
948 &cropped_width_, &cropped_height_, | 967 &cropped_width_, &cropped_height_, |
949 &out_width_, &out_height_)); | 968 &out_width_, &out_height_)); |
950 | 969 |
951 // Instead of getting the exact aspect ratio with cropped resolution 640x360, | 970 // Instead of getting the exact aspect ratio with cropped resolution 640x360, |
952 // the resolution should be adjusted to get a perfect scale factor instead. | 971 // the resolution should be adjusted to get a perfect scale factor instead. |
953 EXPECT_EQ(640, cropped_width_); | 972 EXPECT_EQ(640, cropped_width_); |
954 EXPECT_EQ(368, cropped_height_); | 973 EXPECT_EQ(368, cropped_height_); |
955 EXPECT_EQ(120, out_width_); | 974 EXPECT_EQ(120, out_width_); |
956 EXPECT_EQ(69, out_height_); | 975 EXPECT_EQ(69, out_height_); |
957 } | 976 } |
958 | 977 |
959 TEST_F(VideoAdapterTest, TestAdaptToVerySmallResolution) { | 978 TEST_F(VideoAdapterTest, TestAdaptToVerySmallResolution) { |
960 // Ask for 1920x1080 (16:9 aspect), with 1/16 scaling. | 979 // Ask for 1920x1080 (16:9 aspect), with 1/16 scaling. |
961 const int w = 1920; | 980 const int w = 1920; |
962 const int h = 1080; | 981 const int h = 1080; |
963 adapter_.OnOutputFormatRequest(VideoFormat(w, h, 0, FOURCC_I420)); | 982 adapter_.OnOutputFormatRequest(VideoFormat(w, h, 0, FOURCC_I420)); |
964 adapter_.OnResolutionRequest(rtc::Optional<int>(), | 983 adapter_.OnResolutionFramerateRequest( |
965 rtc::Optional<int>(w * h * 1 / 16 * 1 / 16)); | 984 rtc::Optional<int>(), rtc::Optional<int>(w * h * 1 / 16 * 1 / 16), |
| 985 rtc::Optional<int>()); |
966 | 986 |
967 // Send 1920x1080 (16:9 aspect). | 987 // Send 1920x1080 (16:9 aspect). |
968 EXPECT_TRUE(adapter_.AdaptFrameResolution( | 988 EXPECT_TRUE(adapter_.AdaptFrameResolution( |
969 w, h, 0, &cropped_width_, &cropped_height_, &out_width_, &out_height_)); | 989 w, h, 0, &cropped_width_, &cropped_height_, &out_width_, &out_height_)); |
970 | 990 |
971 // Instead of getting the exact aspect ratio with cropped resolution 1920x1080 | 991 // Instead of getting the exact aspect ratio with cropped resolution 1920x1080 |
972 // the resolution should be adjusted to get a perfect scale factor instead. | 992 // the resolution should be adjusted to get a perfect scale factor instead. |
973 EXPECT_EQ(1920, cropped_width_); | 993 EXPECT_EQ(1920, cropped_width_); |
974 EXPECT_EQ(1072, cropped_height_); | 994 EXPECT_EQ(1072, cropped_height_); |
975 EXPECT_EQ(120, out_width_); | 995 EXPECT_EQ(120, out_width_); |
976 EXPECT_EQ(67, out_height_); | 996 EXPECT_EQ(67, out_height_); |
977 | 997 |
978 // Adapt back up one step to 3/32. | 998 // Adapt back up one step to 3/32. |
979 adapter_.OnResolutionRequest(rtc::Optional<int>(w * h * 3 / 32 * 3 / 32), | 999 adapter_.OnResolutionFramerateRequest( |
980 rtc::Optional<int>(w * h * 1 / 8 * 1 / 8)); | 1000 rtc::Optional<int>(w * h * 3 / 32 * 3 / 32), |
| 1001 rtc::Optional<int>(w * h * 1 / 8 * 1 / 8), rtc::Optional<int>()); |
981 | 1002 |
982 // Send 1920x1080 (16:9 aspect). | 1003 // Send 1920x1080 (16:9 aspect). |
983 EXPECT_TRUE(adapter_.AdaptFrameResolution( | 1004 EXPECT_TRUE(adapter_.AdaptFrameResolution( |
984 w, h, 0, &cropped_width_, &cropped_height_, &out_width_, &out_height_)); | 1005 w, h, 0, &cropped_width_, &cropped_height_, &out_width_, &out_height_)); |
985 | 1006 |
986 EXPECT_EQ(180, out_width_); | 1007 EXPECT_EQ(180, out_width_); |
987 EXPECT_EQ(99, out_height_); | 1008 EXPECT_EQ(99, out_height_); |
988 } | 1009 } |
989 | 1010 |
990 TEST_F(VideoAdapterTest, AdaptFrameResolutionDropWithResolutionRequest) { | 1011 TEST_F(VideoAdapterTest, AdaptFrameResolutionDropWithResolutionRequest) { |
991 VideoFormat output_format = capture_format_; | 1012 VideoFormat output_format = capture_format_; |
992 output_format.width = 0; | 1013 output_format.width = 0; |
993 output_format.height = 0; | 1014 output_format.height = 0; |
994 adapter_.OnOutputFormatRequest(output_format); | 1015 adapter_.OnOutputFormatRequest(output_format); |
995 EXPECT_FALSE(adapter_.AdaptFrameResolution( | 1016 EXPECT_FALSE(adapter_.AdaptFrameResolution( |
996 capture_format_.width, capture_format_.height, 0, | 1017 capture_format_.width, capture_format_.height, 0, |
997 &cropped_width_, &cropped_height_, | 1018 &cropped_width_, &cropped_height_, |
998 &out_width_, &out_height_)); | 1019 &out_width_, &out_height_)); |
999 | 1020 |
1000 adapter_.OnResolutionRequest(rtc::Optional<int>(960 * 540), | 1021 adapter_.OnResolutionFramerateRequest(rtc::Optional<int>(960 * 540), |
1001 rtc::Optional<int>()); | 1022 rtc::Optional<int>(), |
| 1023 rtc::Optional<int>()); |
1002 | 1024 |
1003 // Still expect all frames to be dropped | 1025 // Still expect all frames to be dropped |
1004 EXPECT_FALSE(adapter_.AdaptFrameResolution( | 1026 EXPECT_FALSE(adapter_.AdaptFrameResolution( |
1005 capture_format_.width, capture_format_.height, 0, | 1027 capture_format_.width, capture_format_.height, 0, |
1006 &cropped_width_, &cropped_height_, | 1028 &cropped_width_, &cropped_height_, |
1007 &out_width_, &out_height_)); | 1029 &out_width_, &out_height_)); |
1008 | 1030 |
1009 adapter_.OnResolutionRequest(rtc::Optional<int>(), | 1031 adapter_.OnResolutionFramerateRequest(rtc::Optional<int>(), |
1010 rtc::Optional<int>(640 * 480 - 1)); | 1032 rtc::Optional<int>(640 * 480 - 1), |
| 1033 rtc::Optional<int>()); |
1011 | 1034 |
1012 // Still expect all frames to be dropped | 1035 // Still expect all frames to be dropped |
1013 EXPECT_FALSE(adapter_.AdaptFrameResolution( | 1036 EXPECT_FALSE(adapter_.AdaptFrameResolution( |
1014 capture_format_.width, capture_format_.height, 0, | 1037 capture_format_.width, capture_format_.height, 0, |
1015 &cropped_width_, &cropped_height_, | 1038 &cropped_width_, &cropped_height_, |
1016 &out_width_, &out_height_)); | 1039 &out_width_, &out_height_)); |
1017 } | 1040 } |
1018 | 1041 |
1019 // Test that we will adapt to max given a target pixel count close to max. | 1042 // Test that we will adapt to max given a target pixel count close to max. |
1020 TEST_F(VideoAdapterTest, TestAdaptToMax) { | 1043 TEST_F(VideoAdapterTest, TestAdaptToMax) { |
1021 adapter_.OnOutputFormatRequest(VideoFormat(640, 360, 0, FOURCC_I420)); | 1044 adapter_.OnOutputFormatRequest(VideoFormat(640, 360, 0, FOURCC_I420)); |
1022 adapter_.OnResolutionRequest(rtc::Optional<int>(640 * 360 - 1) /* target */, | 1045 adapter_.OnResolutionFramerateRequest( |
1023 rtc::Optional<int>()); | 1046 rtc::Optional<int>(640 * 360 - 1) /* target */, rtc::Optional<int>(), |
| 1047 rtc::Optional<int>()); |
1024 | 1048 |
1025 EXPECT_TRUE(adapter_.AdaptFrameResolution(640, 360, 0, &cropped_width_, | 1049 EXPECT_TRUE(adapter_.AdaptFrameResolution(640, 360, 0, &cropped_width_, |
1026 &cropped_height_, &out_width_, | 1050 &cropped_height_, &out_width_, |
1027 &out_height_)); | 1051 &out_height_)); |
1028 EXPECT_EQ(640, out_width_); | 1052 EXPECT_EQ(640, out_width_); |
1029 EXPECT_EQ(360, out_height_); | 1053 EXPECT_EQ(360, out_height_); |
1030 } | 1054 } |
1031 | 1055 |
1032 } // namespace cricket | 1056 } // namespace cricket |
OLD | NEW |