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

Side by Side Diff: media/capture/content/smooth_event_sampler.h

Issue 1864813002: Tab/Desktop Capture: Use requests instead of timer-based refreshing. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@video_refresh_from_sinks
Patch Set: Addressed comments from PS2, and sampling decision logic change w.r.t. recent animation. Created 4 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
OLDNEW
1 // Copyright (c) 2015 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2015 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 #ifndef MEDIA_CAPTURE_SMOOTH_EVENT_SAMPLER_H_ 5 #ifndef MEDIA_CAPTURE_SMOOTH_EVENT_SAMPLER_H_
6 #define MEDIA_CAPTURE_SMOOTH_EVENT_SAMPLER_H_ 6 #define MEDIA_CAPTURE_SMOOTH_EVENT_SAMPLER_H_
7 7
8 #include "base/macros.h" 8 #include "base/macros.h"
9 #include "base/time/time.h" 9 #include "base/time/time.h"
10 #include "media/base/media_export.h" 10 #include "media/base/media_export.h"
11 11
12 namespace media { 12 namespace media {
13 13
14 // Filters a sequence of events to achieve a target frequency. 14 // Filters a sequence of events to achieve a target frequency.
15 class MEDIA_EXPORT SmoothEventSampler { 15 class MEDIA_EXPORT SmoothEventSampler {
16 public: 16 public:
17 enum { 17 explicit SmoothEventSampler(base::TimeDelta min_capture_period);
18 // The maximum amount of time that can elapse before considering unchanged
19 // content as dirty for the purposes of timer-based overdue sampling. This
20 // is the same value found in cc::FrameRateCounter.
21 OVERDUE_DIRTY_THRESHOLD_MILLIS = 250 // 4 FPS
22 };
23
24 SmoothEventSampler(base::TimeDelta min_capture_period,
25 int redundant_capture_goal);
26 18
27 // Get/Set minimum capture period. When setting a new value, the state of the 19 // Get/Set minimum capture period. When setting a new value, the state of the
28 // sampler is retained so that sampling will continue smoothly. 20 // sampler is retained so that sampling will continue smoothly.
29 base::TimeDelta min_capture_period() const { return min_capture_period_; } 21 base::TimeDelta min_capture_period() const { return min_capture_period_; }
30 void SetMinCapturePeriod(base::TimeDelta p); 22 void SetMinCapturePeriod(base::TimeDelta p);
31 23
32 // Add a new event to the event history, and consider whether it ought to be 24 // Add a new event to the event history, and consider whether it ought to be
33 // sampled. The event is not recorded as a sample until RecordSample() is 25 // sampled. The event is not recorded as a sample until RecordSample() is
34 // called. 26 // called.
35 void ConsiderPresentationEvent(base::TimeTicks event_time); 27 void ConsiderPresentationEvent(base::TimeTicks event_time);
36 28
37 // Returns true if the last event considered should be sampled. 29 // Returns true if the last event considered should be sampled.
38 bool ShouldSample() const; 30 bool ShouldSample() const;
39 31
40 // Operates on the last event added by ConsiderPresentationEvent(), marking 32 // Operates on the last event added by ConsiderPresentationEvent(), marking
41 // it as sampled. After this point we are current in the stream of events, as 33 // it as sampled. After this point we are current in the stream of events, as
42 // we have sampled the most recent event. 34 // we have sampled the most recent event.
43 void RecordSample(); 35 void RecordSample();
44 36
45 // Returns true if, at time |event_time|, sampling should occur because too
46 // much time will have passed relative to the last event and/or sample.
47 bool IsOverdueForSamplingAt(base::TimeTicks event_time) const;
48
49 // Returns true if ConsiderPresentationEvent() has been called since the last 37 // Returns true if ConsiderPresentationEvent() has been called since the last
50 // call to RecordSample(). 38 // call to RecordSample().
51 bool HasUnrecordedEvent() const; 39 bool HasUnrecordedEvent() const;
52 40
53 private: 41 private:
54 base::TimeDelta min_capture_period_; 42 base::TimeDelta min_capture_period_;
55 const int redundant_capture_goal_;
56 base::TimeDelta token_bucket_capacity_; 43 base::TimeDelta token_bucket_capacity_;
57 44
58 base::TimeTicks current_event_; 45 base::TimeTicks current_event_;
59 base::TimeTicks last_sample_; 46 base::TimeTicks last_sample_;
60 int overdue_sample_count_;
61 base::TimeDelta token_bucket_; 47 base::TimeDelta token_bucket_;
62 48
63 DISALLOW_COPY_AND_ASSIGN(SmoothEventSampler); 49 DISALLOW_COPY_AND_ASSIGN(SmoothEventSampler);
64 }; 50 };
65 51
66 } // namespace media 52 } // namespace media
67 53
68 #endif // MEDIA_CAPTURE_SMOOTH_EVENT_SAMPLER_H_ 54 #endif // MEDIA_CAPTURE_SMOOTH_EVENT_SAMPLER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698