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

Side by Side Diff: content/browser/media/capture/animated_content_sampler.h

Issue 1123623005: Tab Capture: AnimatedContentSampler subsampling and phase fixes in tests (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 7 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 CONTENT_BROWSER_MEDIA_CAPTURE_ANIMATED_CONTENT_SAMPLER_H_ 5 #ifndef CONTENT_BROWSER_MEDIA_CAPTURE_ANIMATED_CONTENT_SAMPLER_H_
6 #define CONTENT_BROWSER_MEDIA_CAPTURE_ANIMATED_CONTENT_SAMPLER_H_ 6 #define CONTENT_BROWSER_MEDIA_CAPTURE_ANIMATED_CONTENT_SAMPLER_H_
7 7
8 #include <deque> 8 #include <deque>
9 9
10 #include "base/time/time.h" 10 #include "base/time/time.h"
11 #include "content/common/content_export.h" 11 #include "content/common/content_export.h"
12 #include "ui/gfx/geometry/rect.h" 12 #include "ui/gfx/geometry/rect.h"
13 13
14 namespace content { 14 namespace content {
15 15
16 // Analyzes a sequence of events to detect the presence of constant frame rate 16 // Analyzes a sequence of events to detect the presence of constant frame rate
17 // animated content. In the case where there are multiple regions of animated 17 // animated content. In the case where there are multiple regions of animated
18 // content, AnimatedContentSampler will propose sampling the one having the 18 // content, AnimatedContentSampler will propose sampling the one having the
19 // largest "smoothness" impact, according to human perception (e.g., a 24 FPS 19 // largest "smoothness" impact, according to human perception (e.g., a 24 FPS
20 // video versus a 60 FPS busy spinner). 20 // video versus a 60 FPS busy spinner).
21 // 21 //
22 // In addition, AnimatedContentSampler will provide rewritten frame timestamps, 22 // In addition, AnimatedContentSampler will provide rewritten frame timestamps,
23 // for downstream consumers, that are "truer" to the source content than to the 23 // for downstream consumers, that are "truer" to the source content than to the
24 // local presentation hardware. 24 // local presentation hardware.
25 class CONTENT_EXPORT AnimatedContentSampler { 25 class CONTENT_EXPORT AnimatedContentSampler {
26 public: 26 public:
27 explicit AnimatedContentSampler(base::TimeDelta min_capture_period); 27 explicit AnimatedContentSampler(base::TimeDelta min_capture_period);
28 ~AnimatedContentSampler(); 28 ~AnimatedContentSampler();
29 29
30 // Get/Set the target sampling period. This is used to determine whether to
31 // subsample the frames of animated content.
32 base::TimeDelta target_sampling_period() const {
33 return target_sampling_period_;
34 }
35 void SetTargetSamplingPeriod(base::TimeDelta period);
36
30 // Examines the given presentation event metadata, along with recent history, 37 // Examines the given presentation event metadata, along with recent history,
31 // to detect animated content, updating the state of this sampler. 38 // to detect animated content, updating the state of this sampler.
32 // |damage_rect| is the region of a frame about to be drawn, while 39 // |damage_rect| is the region of a frame about to be drawn, while
33 // |event_time| refers to the frame's estimated presentation time. 40 // |event_time| refers to the frame's estimated presentation time.
34 void ConsiderPresentationEvent(const gfx::Rect& damage_rect, 41 void ConsiderPresentationEvent(const gfx::Rect& damage_rect,
35 base::TimeTicks event_time); 42 base::TimeTicks event_time);
36 43
37 // Returns true if animated content has been detected and a decision has been 44 // Returns true if animated content has been detected and a decision has been
38 // made about whether to sample the last event. 45 // made about whether to sample the last event.
39 bool HasProposal() const; 46 bool HasProposal() const;
40 47
41 // Returns true if the last event considered should be sampled. 48 // Returns true if the last event considered should be sampled.
42 bool ShouldSample() const; 49 bool ShouldSample() const;
43 50
44 // Returns a frame timestamp to provide to consumers of the sampled frame. 51 // Returns a frame timestamp to provide to consumers of the sampled frame.
45 // Only valid when should_sample() returns true. 52 // Only valid when ShouldSample() returns true.
46 base::TimeTicks frame_timestamp() const { return frame_timestamp_; } 53 base::TimeTicks frame_timestamp() const { return frame_timestamp_; }
47 54
55 // Returns the current sampling period. This can be treated as the estimated
56 // duration of the frame to be sampled. Only valid when ShouldSample()
57 // returns true.
58 base::TimeDelta sampling_period() const { return sampling_period_; }
59
48 // Accessors to currently-detected animating region/period, for logging. 60 // Accessors to currently-detected animating region/period, for logging.
49 const gfx::Rect& detected_region() const { return detected_region_; } 61 const gfx::Rect& detected_region() const { return detected_region_; }
50 base::TimeDelta detected_period() const { return detected_period_; } 62 base::TimeDelta detected_period() const { return detected_period_; }
51 63
52 // Records that a frame with the given |frame_timestamp| was sampled. This 64 // Records that a frame with the given |frame_timestamp| was sampled. This
53 // method should be called when *any* sampling is taken, even if it was not 65 // method should be called when *any* sampling is taken, even if it was not
54 // proposed by AnimatedContentSampler. 66 // proposed by AnimatedContentSampler.
55 void RecordSample(base::TimeTicks frame_timestamp); 67 void RecordSample(base::TimeTicks frame_timestamp);
56 68
57 private: 69 private:
(...skipping 21 matching lines...) Expand all
79 // Analyzes the observations relative to the current |event_time| to detect 91 // Analyzes the observations relative to the current |event_time| to detect
80 // stable animating content. If detected, returns true and sets the output 92 // stable animating content. If detected, returns true and sets the output
81 // arguments to the region of the animating content and its mean frame 93 // arguments to the region of the animating content and its mean frame
82 // duration. 94 // duration.
83 bool AnalyzeObservations(base::TimeTicks event_time, 95 bool AnalyzeObservations(base::TimeTicks event_time,
84 gfx::Rect* rect, 96 gfx::Rect* rect,
85 base::TimeDelta* period) const; 97 base::TimeDelta* period) const;
86 98
87 // Called by ConsiderPresentationEvent() when the current event is part of a 99 // Called by ConsiderPresentationEvent() when the current event is part of a
88 // detected animation, to update |frame_timestamp_|. 100 // detected animation, to update |frame_timestamp_|.
89 void UpdateFrameTimestamp(base::TimeTicks event_time); 101 base::TimeTicks ComputeNextFrameTimestamp(base::TimeTicks event_time) const;
102
103 static base::TimeDelta ComputeSamplingPeriod(
hubbe 2015/05/06 19:53:18 Comment?
miu 2015/05/09 20:57:39 Done.
104 base::TimeDelta animation_period,
105 base::TimeDelta target_sampling_period,
106 base::TimeDelta min_capture_period);
90 107
91 // The client expects frame timestamps to be at least this far apart. 108 // The client expects frame timestamps to be at least this far apart.
92 const base::TimeDelta min_capture_period_; 109 const base::TimeDelta min_capture_period_;
93 110
94 // A recent history of observations in chronological order, maintained by 111 // A recent history of observations in chronological order, maintained by
95 // AddObservation(). 112 // AddObservation().
96 ObservationFifo observations_; 113 ObservationFifo observations_;
97 114
98 // The region of currently-detected animated content. If empty, that means 115 // The region of currently-detected animated content. If empty, that means
99 // "not detected." 116 // "not detected."
100 gfx::Rect detected_region_; 117 gfx::Rect detected_region_;
101 118
102 // The mean frame duration of currently-detected animated content. If zero, 119 // The mean frame duration of currently-detected animated content. If zero,
103 // that means "not detected." 120 // that means "not detected."
104 base::TimeDelta detected_period_; 121 base::TimeDelta detected_period_;
105 122
123 // Target period between sampled frames. This can be changed by the client at
124 // any time (e.g., to sample high frame rate content at a lower rate).
125 base::TimeDelta target_sampling_period_;
126
127 // The sampling period computed during the last call to
128 // ConsiderPresentationEvent().
129 base::TimeDelta sampling_period_;
130
131 // Indicates whether the last event caused animated content to be detected and
132 // whether the current event should be sampled.
133 enum { NOT_SAMPLING, START_SAMPLING,
hubbe 2015/05/06 19:53:18 one per line?
miu 2015/05/09 20:57:38 Done.
134 SHOULD_NOT_SAMPLE, SHOULD_SAMPLE } sampling_state_;
135
136 // A token bucket that is used to decide which subset of the frames containing
hubbe 2015/05/06 19:53:18 Wait, what? How exactly is TimeDelta == token buck
miu 2015/05/09 20:57:38 One microsecond == one token. When you can take,
137 // the animated content should be sampled.
138 base::TimeDelta token_bucket_;
139
106 // The rewritten frame timestamp for the latest event. 140 // The rewritten frame timestamp for the latest event.
107 base::TimeTicks frame_timestamp_; 141 base::TimeTicks frame_timestamp_;
108
109 // The frame timestamp provided in the last call to RecordSample(). This
110 // timestamp may or may not have been one proposed by AnimatedContentSampler.
111 base::TimeTicks recorded_frame_timestamp_;
112
113 // Accumulates all the time advancements since the last call to
114 // RecordSample(). When this is greater than zero, there have been one or
115 // more events proposed for sampling, but not yet recorded. This accounts for
116 // the cases where AnimatedContentSampler indicates a frame should be sampled,
117 // but the client chooses not to do so.
118 base::TimeDelta sequence_offset_;
119
120 // A token bucket that is used to decide which frames to drop whenever
121 // |detected_period_| is less than |min_capture_period_|.
122 base::TimeDelta borrowed_time_;
123 }; 142 };
124 143
125 } // namespace content 144 } // namespace content
126 145
127 #endif // CONTENT_BROWSER_MEDIA_CAPTURE_ANIMATED_CONTENT_SAMPLER_H_ 146 #endif // CONTENT_BROWSER_MEDIA_CAPTURE_ANIMATED_CONTENT_SAMPLER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698