Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(103)

Side by Side Diff: content/browser/renderer_host/media/web_contents_video_capture_device_unittest.cc

Issue 13956003: Tab capture: do 200 rendundant captures of static content. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Self-review fixes. Created 7 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « content/browser/renderer_host/media/web_contents_video_capture_device.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "content/browser/renderer_host/media/web_contents_video_capture_device. h" 5 #include "content/browser/renderer_host/media/web_contents_video_capture_device. h"
6 6
7 #include "base/bind_helpers.h" 7 #include "base/bind_helpers.h"
8 #include "base/debug/debugger.h" 8 #include "base/debug/debugger.h"
9 #include "base/run_loop.h" 9 #include "base/run_loop.h"
10 #include "base/time.h" 10 #include "base/time.h"
(...skipping 705 matching lines...) Expand 10 before | Expand all | Expand 10 after
716 ASSERT_NO_FATAL_FAILURE(consumer()->WaitForNextColor(SK_ColorGREEN)); 716 ASSERT_NO_FATAL_FAILURE(consumer()->WaitForNextColor(SK_ColorGREEN));
717 source()->SetSolidColor(SK_ColorRED); 717 source()->SetSolidColor(SK_ColorRED);
718 ASSERT_NO_FATAL_FAILURE(consumer()->WaitForNextColor(SK_ColorRED)); 718 ASSERT_NO_FATAL_FAILURE(consumer()->WaitForNextColor(SK_ColorRED));
719 719
720 device()->Stop(); 720 device()->Stop();
721 device()->DeAllocate(); 721 device()->DeAllocate();
722 } 722 }
723 723
724 // 60Hz sampled at 30Hz should produce 30Hz. 724 // 60Hz sampled at 30Hz should produce 30Hz.
725 TEST(SmoothEventSamplerTest, Sample60HertzAt30Hertz) { 725 TEST(SmoothEventSamplerTest, Sample60HertzAt30Hertz) {
726 SmoothEventSampler sampler(base::TimeDelta::FromSeconds(1) / 30, true); 726 SmoothEventSampler sampler(base::TimeDelta::FromSeconds(1) / 30, true, 200);
727 const base::TimeDelta vsync = base::TimeDelta::FromSeconds(1) / 60; 727 const base::TimeDelta vsync = base::TimeDelta::FromSeconds(1) / 60;
728 728
729 base::Time t; 729 base::Time t;
730 ASSERT_TRUE(base::Time::FromString("Sat, 23 Mar 2013 1:21:08 GMT", &t)); 730 ASSERT_TRUE(base::Time::FromString("Sat, 23 Mar 2013 1:21:08 GMT", &t));
731 ASSERT_TRUE(sampler.IsOverdueForSamplingAt(t)) 731 for (int i = 0; i < 200; i++) {
732 << "First timer event should sample."; 732 ASSERT_TRUE(sampler.IsOverdueForSamplingAt(t))
733 sampler.RecordSample(); 733 << "Should sample until redundant capture goal is hit";
734 ASSERT_TRUE(sampler.IsOverdueForSamplingAt(t)) 734 sampler.RecordSample();
735 << "Should always be overdue until first paint."; 735 }
736 ASSERT_FALSE(sampler.IsOverdueForSamplingAt(t))
737 << "Should not be overdue once redundant capture goal achieved.";
736 738
737 // Steady state, we should capture every other vsync, indefinitely. 739 // Steady state, we should capture every other vsync, indefinitely.
738 for (int i = 0; i < 100; i++) { 740 for (int i = 0; i < 100; i++) {
739 SCOPED_TRACE(base::StringPrintf("Iteration %d", i)); 741 SCOPED_TRACE(base::StringPrintf("Iteration %d", i));
740 ASSERT_TRUE(sampler.AddEventAndConsiderSampling(t)); 742 ASSERT_TRUE(sampler.AddEventAndConsiderSampling(t));
741 sampler.RecordSample(); 743 sampler.RecordSample();
742 t += vsync; 744 t += vsync;
743 745
744 ASSERT_FALSE(sampler.AddEventAndConsiderSampling(t)); 746 ASSERT_FALSE(sampler.AddEventAndConsiderSampling(t));
745 t += vsync; 747 t += vsync;
(...skipping 19 matching lines...) Expand all
765 ASSERT_FALSE(sampler.IsOverdueForSamplingAt(t)); 767 ASSERT_FALSE(sampler.IsOverdueForSamplingAt(t));
766 768
767 ASSERT_FALSE(sampler.AddEventAndConsiderSampling(t)); 769 ASSERT_FALSE(sampler.AddEventAndConsiderSampling(t));
768 t += vsync; 770 t += vsync;
769 ASSERT_FALSE(sampler.IsOverdueForSamplingAt(t)); 771 ASSERT_FALSE(sampler.IsOverdueForSamplingAt(t));
770 } 772 }
771 } 773 }
772 774
773 // 50Hz sampled at 30Hz should produce 25Hz. 775 // 50Hz sampled at 30Hz should produce 25Hz.
774 TEST(SmoothEventSamplerTest, Sample50HertzAt30Hertz) { 776 TEST(SmoothEventSamplerTest, Sample50HertzAt30Hertz) {
775 SmoothEventSampler sampler(base::TimeDelta::FromSeconds(1) / 30, true); 777 SmoothEventSampler sampler(base::TimeDelta::FromSeconds(1) / 30, true, 2);
776 const base::TimeDelta vsync = base::TimeDelta::FromSeconds(1) / 50; 778 const base::TimeDelta vsync = base::TimeDelta::FromSeconds(1) / 50;
777 779
778 base::Time t; 780 base::Time t;
779 ASSERT_TRUE(base::Time::FromString("Sat, 23 Mar 2013 1:21:08 GMT", &t)); 781 ASSERT_TRUE(base::Time::FromString("Sat, 23 Mar 2013 1:21:08 GMT", &t));
780 ASSERT_TRUE(sampler.IsOverdueForSamplingAt(t)) 782 for (int i = 0; i < 2; i++) {
781 << "First timer event should sample."; 783 ASSERT_TRUE(sampler.IsOverdueForSamplingAt(t))
782 sampler.RecordSample(); 784 << "Should sample until redundant capture goal is hit";
783 ASSERT_TRUE(sampler.IsOverdueForSamplingAt(t)) 785 sampler.RecordSample();
784 << "Should always be overdue until first paint."; 786 }
787 ASSERT_FALSE(sampler.IsOverdueForSamplingAt(t))
788 << "Should not be overdue once redundant capture goal achieved.";
789
790
785 791
786 // Steady state, we should capture every other vsync, indefinitely. 792 // Steady state, we should capture every other vsync, indefinitely.
787 for (int i = 0; i < 100; i++) { 793 for (int i = 0; i < 100; i++) {
788 SCOPED_TRACE(base::StringPrintf("Iteration %d", i)); 794 SCOPED_TRACE(base::StringPrintf("Iteration %d", i));
789 ASSERT_TRUE(sampler.AddEventAndConsiderSampling(t)); 795 ASSERT_TRUE(sampler.AddEventAndConsiderSampling(t));
790 sampler.RecordSample(); 796 sampler.RecordSample();
791 t += vsync; 797 t += vsync;
792 798
793 ASSERT_FALSE(sampler.AddEventAndConsiderSampling(t)); 799 ASSERT_FALSE(sampler.AddEventAndConsiderSampling(t));
794 t += vsync; 800 t += vsync;
(...skipping 19 matching lines...) Expand all
814 ASSERT_FALSE(sampler.IsOverdueForSamplingAt(t)); 820 ASSERT_FALSE(sampler.IsOverdueForSamplingAt(t));
815 821
816 ASSERT_FALSE(sampler.AddEventAndConsiderSampling(t)); 822 ASSERT_FALSE(sampler.AddEventAndConsiderSampling(t));
817 t += vsync; 823 t += vsync;
818 ASSERT_FALSE(sampler.IsOverdueForSamplingAt(t)); 824 ASSERT_FALSE(sampler.IsOverdueForSamplingAt(t));
819 } 825 }
820 } 826 }
821 827
822 // 30Hz sampled at 30Hz should produce 30Hz. 828 // 30Hz sampled at 30Hz should produce 30Hz.
823 TEST(SmoothEventSamplerTest, Sample30HertzAt30Hertz) { 829 TEST(SmoothEventSamplerTest, Sample30HertzAt30Hertz) {
824 SmoothEventSampler sampler(base::TimeDelta::FromSeconds(1) / 30, true); 830 SmoothEventSampler sampler(base::TimeDelta::FromSeconds(1) / 30, true, 3);
825 const base::TimeDelta vsync = base::TimeDelta::FromSeconds(1) / 30; 831 const base::TimeDelta vsync = base::TimeDelta::FromSeconds(1) / 30;
826 832
827 base::Time t; 833 base::Time t;
828 ASSERT_TRUE(base::Time::FromString("Sat, 23 Mar 2013 1:21:08 GMT", &t)); 834 ASSERT_TRUE(base::Time::FromString("Sat, 23 Mar 2013 1:21:08 GMT", &t));
829 ASSERT_TRUE(sampler.IsOverdueForSamplingAt(t)) 835 for (int i = 0; i < 3; i++) {
830 << "First timer event should sample."; 836 ASSERT_TRUE(sampler.IsOverdueForSamplingAt(t))
831 sampler.RecordSample(); 837 << "Should sample until redundant capture goal is hit";
832 ASSERT_TRUE(sampler.IsOverdueForSamplingAt(t)) 838 sampler.RecordSample();
833 << "Should always be overdue until first paint."; 839 }
840 ASSERT_FALSE(sampler.IsOverdueForSamplingAt(t))
841 << "Should not be overdue once redundant capture goal achieved.";
834 842
835 // Steady state, we should capture every vsync, indefinitely. 843 // Steady state, we should capture every vsync, indefinitely.
836 for (int i = 0; i < 200; i++) { 844 for (int i = 0; i < 200; i++) {
837 SCOPED_TRACE(base::StringPrintf("Iteration %d", i)); 845 SCOPED_TRACE(base::StringPrintf("Iteration %d", i));
838 ASSERT_TRUE(sampler.AddEventAndConsiderSampling(t)); 846 ASSERT_TRUE(sampler.AddEventAndConsiderSampling(t));
839 sampler.RecordSample(); 847 sampler.RecordSample();
840 t += vsync; 848 t += vsync;
841 } 849 }
842 850
843 // Now pretend we're limited by backpressure in the pipeline. In this scenario 851 // Now pretend we're limited by backpressure in the pipeline. In this scenario
(...skipping 11 matching lines...) Expand all
855 SCOPED_TRACE(base::StringPrintf("Iteration %d", i)); 863 SCOPED_TRACE(base::StringPrintf("Iteration %d", i));
856 ASSERT_TRUE(sampler.AddEventAndConsiderSampling(t)); 864 ASSERT_TRUE(sampler.AddEventAndConsiderSampling(t));
857 sampler.RecordSample(); 865 sampler.RecordSample();
858 t += vsync; 866 t += vsync;
859 ASSERT_FALSE(sampler.IsOverdueForSamplingAt(t)); 867 ASSERT_FALSE(sampler.IsOverdueForSamplingAt(t));
860 } 868 }
861 } 869 }
862 870
863 // 24Hz sampled at 30Hz should produce 24Hz. 871 // 24Hz sampled at 30Hz should produce 24Hz.
864 TEST(SmoothEventSamplerTest, Sample24HertzAt30Hertz) { 872 TEST(SmoothEventSamplerTest, Sample24HertzAt30Hertz) {
865 SmoothEventSampler sampler(base::TimeDelta::FromSeconds(1) / 30, true); 873 SmoothEventSampler sampler(base::TimeDelta::FromSeconds(1) / 30, true, 333);
866 const base::TimeDelta vsync = base::TimeDelta::FromSeconds(1) / 24; 874 const base::TimeDelta vsync = base::TimeDelta::FromSeconds(1) / 24;
867 875
868 base::Time t; 876 base::Time t;
869 ASSERT_TRUE(base::Time::FromString("Sat, 23 Mar 2013 1:21:08 GMT", &t)); 877 ASSERT_TRUE(base::Time::FromString("Sat, 23 Mar 2013 1:21:08 GMT", &t));
870 ASSERT_TRUE(sampler.IsOverdueForSamplingAt(t)) 878 for (int i = 0; i < 333; i++) {
871 << "First timer event should sample."; 879 ASSERT_TRUE(sampler.IsOverdueForSamplingAt(t))
872 sampler.RecordSample(); 880 << "Should sample until redundant capture goal is hit";
873 ASSERT_TRUE(sampler.IsOverdueForSamplingAt(t)) 881 sampler.RecordSample();
874 << "Should always be overdue until first paint."; 882 }
883 ASSERT_FALSE(sampler.IsOverdueForSamplingAt(t))
884 << "Should not be overdue once redundant capture goal achieved.";
875 885
876 // Steady state, we should capture every vsync, indefinitely. 886 // Steady state, we should capture every vsync, indefinitely.
877 for (int i = 0; i < 200; i++) { 887 for (int i = 0; i < 200; i++) {
878 SCOPED_TRACE(base::StringPrintf("Iteration %d", i)); 888 SCOPED_TRACE(base::StringPrintf("Iteration %d", i));
879 ASSERT_TRUE(sampler.AddEventAndConsiderSampling(t)); 889 ASSERT_TRUE(sampler.AddEventAndConsiderSampling(t));
880 sampler.RecordSample(); 890 sampler.RecordSample();
881 t += vsync; 891 t += vsync;
882 } 892 }
883 893
884 // Now pretend we're limited by backpressure in the pipeline. In this scenario 894 // Now pretend we're limited by backpressure in the pipeline. In this scenario
(...skipping 10 matching lines...) Expand all
895 for (int i = 0; i < 100; i++) { 905 for (int i = 0; i < 100; i++) {
896 SCOPED_TRACE(base::StringPrintf("Iteration %d", i)); 906 SCOPED_TRACE(base::StringPrintf("Iteration %d", i));
897 ASSERT_TRUE(sampler.AddEventAndConsiderSampling(t)); 907 ASSERT_TRUE(sampler.AddEventAndConsiderSampling(t));
898 sampler.RecordSample(); 908 sampler.RecordSample();
899 t += vsync; 909 t += vsync;
900 ASSERT_FALSE(sampler.IsOverdueForSamplingAt(t)); 910 ASSERT_FALSE(sampler.IsOverdueForSamplingAt(t));
901 } 911 }
902 } 912 }
903 913
904 TEST(SmoothEventSamplerTest, DoubleDrawAtOneTimeStillDirties) { 914 TEST(SmoothEventSamplerTest, DoubleDrawAtOneTimeStillDirties) {
905 SmoothEventSampler sampler(base::TimeDelta::FromSeconds(1) / 30, true); 915 SmoothEventSampler sampler(base::TimeDelta::FromSeconds(1) / 30, true, 1);
906 const base::TimeDelta overdue_period = base::TimeDelta::FromSeconds(1); 916 const base::TimeDelta overdue_period = base::TimeDelta::FromSeconds(1);
907 917
908 base::Time t; 918 base::Time t;
909 ASSERT_TRUE(base::Time::FromString("Sat, 23 Mar 2013 1:21:08 GMT", &t)); 919 ASSERT_TRUE(base::Time::FromString("Sat, 23 Mar 2013 1:21:08 GMT", &t));
910 ASSERT_TRUE(sampler.AddEventAndConsiderSampling(t)); 920 ASSERT_TRUE(sampler.AddEventAndConsiderSampling(t));
911 sampler.RecordSample(); 921 sampler.RecordSample();
912 t += overdue_period; 922 t += overdue_period;
913 ASSERT_FALSE(sampler.IsOverdueForSamplingAt(t)) 923 ASSERT_FALSE(sampler.IsOverdueForSamplingAt(t))
914 << "Sampled last event; should not be dirty."; 924 << "Sampled last event; should not be dirty.";
915 925
916 // Now simulate 2 events with the same clock value. 926 // Now simulate 2 events with the same clock value.
917 ASSERT_TRUE(sampler.AddEventAndConsiderSampling(t)); 927 ASSERT_TRUE(sampler.AddEventAndConsiderSampling(t));
918 sampler.RecordSample(); 928 sampler.RecordSample();
919 ASSERT_FALSE(sampler.AddEventAndConsiderSampling(t)) 929 ASSERT_FALSE(sampler.AddEventAndConsiderSampling(t))
920 << "Two events at same time -- expected second not to be sampled."; 930 << "Two events at same time -- expected second not to be sampled.";
921 ASSERT_TRUE(sampler.IsOverdueForSamplingAt(t + overdue_period)) 931 ASSERT_TRUE(sampler.IsOverdueForSamplingAt(t + overdue_period))
922 << "Second event should dirty the capture state."; 932 << "Second event should dirty the capture state.";
923 sampler.RecordSample(); 933 sampler.RecordSample();
924 ASSERT_FALSE(sampler.IsOverdueForSamplingAt(t + overdue_period)); 934 ASSERT_FALSE(sampler.IsOverdueForSamplingAt(t + overdue_period));
925 } 935 }
926 936
927 TEST(SmoothEventSamplerTest, FallbackToPollingIfUpdatesUnreliable) { 937 TEST(SmoothEventSamplerTest, FallbackToPollingIfUpdatesUnreliable) {
928 const base::TimeDelta timer_interval = base::TimeDelta::FromSeconds(1) / 30; 938 const base::TimeDelta timer_interval = base::TimeDelta::FromSeconds(1) / 30;
929 SmoothEventSampler should_not_poll(timer_interval, true); 939 SmoothEventSampler should_not_poll(timer_interval, true, 1);
930 SmoothEventSampler should_poll(timer_interval, false); 940 SmoothEventSampler should_poll(timer_interval, false, 1);
931 941
932 base::Time t; 942 base::Time t;
933 ASSERT_TRUE(base::Time::FromString("Sat, 23 Mar 2013 1:21:08 GMT", &t)); 943 ASSERT_TRUE(base::Time::FromString("Sat, 23 Mar 2013 1:21:08 GMT", &t));
934 ASSERT_TRUE(should_not_poll.AddEventAndConsiderSampling(t)); 944 ASSERT_TRUE(should_not_poll.AddEventAndConsiderSampling(t));
935 ASSERT_TRUE(should_poll.AddEventAndConsiderSampling(t)); 945 ASSERT_TRUE(should_poll.AddEventAndConsiderSampling(t));
936 should_not_poll.RecordSample(); 946 should_not_poll.RecordSample();
937 should_poll.RecordSample(); 947 should_poll.RecordSample();
938 t += timer_interval; 948 t += timer_interval;
939 ASSERT_FALSE(should_not_poll.IsOverdueForSamplingAt(t)) 949 ASSERT_FALSE(should_not_poll.IsOverdueForSamplingAt(t))
940 << "Sampled last event; should not be dirty."; 950 << "Sampled last event; should not be dirty.";
(...skipping 14 matching lines...) Expand all
955 t += timer_interval / 3; 965 t += timer_interval / 3;
956 ASSERT_FALSE(should_not_poll.IsOverdueForSamplingAt(t)) 966 ASSERT_FALSE(should_not_poll.IsOverdueForSamplingAt(t))
957 << "Sampled last event; should not be dirty."; 967 << "Sampled last event; should not be dirty.";
958 ASSERT_TRUE(should_poll.IsOverdueForSamplingAt(t)) 968 ASSERT_TRUE(should_poll.IsOverdueForSamplingAt(t))
959 << "If updates are unreliable, must fall back to polling when idle."; 969 << "If updates are unreliable, must fall back to polling when idle.";
960 should_poll.RecordSample(); 970 should_poll.RecordSample();
961 } 971 }
962 972
963 } // namespace content 973 } // namespace content
964 974
OLDNEW
« no previous file with comments | « content/browser/renderer_host/media/web_contents_video_capture_device.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698