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

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

Issue 1109603003: Clean-up: Break sampler classes into their own files. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 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
« no previous file with comments | « no previous file | content/browser/media/capture/animated_content_sampler.cc » ('j') | 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) 2013 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_VIDEO_CAPTURE_ORACLE_H_ 5 #ifndef CONTENT_BROWSER_MEDIA_CAPTURE_ANIMATED_CONTENT_SAMPLER_H_
6 #define CONTENT_BROWSER_MEDIA_CAPTURE_VIDEO_CAPTURE_ORACLE_H_ 6 #define CONTENT_BROWSER_MEDIA_CAPTURE_ANIMATED_CONTENT_SAMPLER_H_
7 7
8 #include <deque> 8 #include <deque>
9 9
10 #include "base/callback_forward.h"
11 #include "base/memory/scoped_ptr.h"
12 #include "base/time/time.h" 10 #include "base/time/time.h"
13 #include "content/common/content_export.h" 11 #include "content/common/content_export.h"
14 #include "ui/gfx/geometry/rect.h" 12 #include "ui/gfx/geometry/rect.h"
15 13
16 namespace content { 14 namespace content {
17 15
18 // Filters a sequence of events to achieve a target frequency.
19 class CONTENT_EXPORT SmoothEventSampler {
20 public:
21 SmoothEventSampler(base::TimeDelta min_capture_period,
22 int redundant_capture_goal);
23
24 base::TimeDelta min_capture_period() const { return min_capture_period_; }
25
26 // Add a new event to the event history, and consider whether it ought to be
27 // sampled. The event is not recorded as a sample until RecordSample() is
28 // called.
29 void ConsiderPresentationEvent(base::TimeTicks event_time);
30
31 // Returns true if the last event considered should be sampled.
32 bool ShouldSample() const;
33
34 // Operates on the last event added by ConsiderPresentationEvent(), marking
35 // it as sampled. After this point we are current in the stream of events, as
36 // we have sampled the most recent event.
37 void RecordSample();
38
39 // Returns true if, at time |event_time|, sampling should occur because too
40 // much time will have passed relative to the last event and/or sample.
41 bool IsOverdueForSamplingAt(base::TimeTicks event_time) const;
42
43 // Returns true if ConsiderPresentationEvent() has been called since the last
44 // call to RecordSample().
45 bool HasUnrecordedEvent() const;
46
47 private:
48 const base::TimeDelta min_capture_period_;
49 const int redundant_capture_goal_;
50 const base::TimeDelta token_bucket_capacity_;
51
52 base::TimeTicks current_event_;
53 base::TimeTicks last_sample_;
54 int overdue_sample_count_;
55 base::TimeDelta token_bucket_;
56
57 DISALLOW_COPY_AND_ASSIGN(SmoothEventSampler);
58 };
59
60 // 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
61 // 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
62 // content, AnimatedContentSampler will propose sampling the one having the 18 // content, AnimatedContentSampler will propose sampling the one having the
63 // 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
64 // video versus a 60 FPS busy spinner). 20 // video versus a 60 FPS busy spinner).
65 // 21 //
66 // In addition, AnimatedContentSampler will provide rewritten frame timestamps, 22 // In addition, AnimatedContentSampler will provide rewritten frame timestamps,
67 // 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
68 // local presentation hardware. 24 // local presentation hardware.
69 class CONTENT_EXPORT AnimatedContentSampler { 25 class CONTENT_EXPORT AnimatedContentSampler {
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
159 // more events proposed for sampling, but not yet recorded. This accounts for 115 // more events proposed for sampling, but not yet recorded. This accounts for
160 // the cases where AnimatedContentSampler indicates a frame should be sampled, 116 // the cases where AnimatedContentSampler indicates a frame should be sampled,
161 // but the client chooses not to do so. 117 // but the client chooses not to do so.
162 base::TimeDelta sequence_offset_; 118 base::TimeDelta sequence_offset_;
163 119
164 // A token bucket that is used to decide which frames to drop whenever 120 // A token bucket that is used to decide which frames to drop whenever
165 // |detected_period_| is less than |min_capture_period_|. 121 // |detected_period_| is less than |min_capture_period_|.
166 base::TimeDelta borrowed_time_; 122 base::TimeDelta borrowed_time_;
167 }; 123 };
168 124
169 // VideoCaptureOracle manages the producer-side throttling of captured frames
170 // from a video capture device. It is informed of every update by the device;
171 // this empowers it to look into the future and decide if a particular frame
172 // ought to be captured in order to achieve its target frame rate.
173 class CONTENT_EXPORT VideoCaptureOracle {
174 public:
175 enum Event {
176 kTimerPoll,
177 kCompositorUpdate,
178 kNumEvents,
179 };
180
181 explicit VideoCaptureOracle(base::TimeDelta min_capture_period);
182 virtual ~VideoCaptureOracle();
183
184 // Record a event of type |event|, and decide whether the caller should do a
185 // frame capture. |damage_rect| is the region of a frame about to be drawn,
186 // and may be an empty Rect, if this is not known. If the caller accepts the
187 // oracle's proposal, it should call RecordCapture() to indicate this.
188 bool ObserveEventAndDecideCapture(Event event,
189 const gfx::Rect& damage_rect,
190 base::TimeTicks event_time);
191
192 // Record the start of a capture. Returns a frame_number to be used with
193 // CompleteCapture().
194 int RecordCapture();
195
196 // Notify of the completion of a capture. Returns true iff the captured frame
197 // should be delivered. |frame_timestamp| is set to the timestamp that should
198 // be provided to the consumer of the frame.
199 bool CompleteCapture(int frame_number, base::TimeTicks* frame_timestamp);
200
201 base::TimeDelta min_capture_period() const {
202 return smoothing_sampler_.min_capture_period();
203 }
204
205 private:
206 // Retrieve/Assign a frame timestamp by capture |frame_number|.
207 base::TimeTicks GetFrameTimestamp(int frame_number) const;
208 void SetFrameTimestamp(int frame_number, base::TimeTicks timestamp);
209
210 // Incremented every time a paint or update event occurs.
211 int frame_number_;
212
213 // Stores the last |event_time| from the last observation/decision. Used to
214 // sanity-check that event times are monotonically non-decreasing.
215 base::TimeTicks last_event_time_[kNumEvents];
216
217 // Stores the frame number from the last delivered frame.
218 int last_delivered_frame_number_;
219
220 // These track present/paint history and propose whether to sample each event
221 // for capture. |smoothing_sampler_| uses a "works for all" heuristic, while
222 // |content_sampler_| specifically detects animated content (e.g., video
223 // playback) and decides which events to sample to "lock into" that content.
224 SmoothEventSampler smoothing_sampler_;
225 AnimatedContentSampler content_sampler_;
226
227 // Recent history of frame timestamps proposed by VideoCaptureOracle. This is
228 // a ring-buffer, and should only be accessed by the Get/SetFrameTimestamp()
229 // methods.
230 enum { kMaxFrameTimestamps = 16 };
231 base::TimeTicks frame_timestamps_[kMaxFrameTimestamps];
232 };
233
234 } // namespace content 125 } // namespace content
235 126
236 #endif // CONTENT_BROWSER_MEDIA_CAPTURE_VIDEO_CAPTURE_ORACLE_H_ 127 #endif // CONTENT_BROWSER_MEDIA_CAPTURE_ANIMATED_CONTENT_SAMPLER_H_
OLDNEW
« no previous file with comments | « no previous file | content/browser/media/capture/animated_content_sampler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698