Remove PlatformFile from profile_browsertest
[chromium-blink-merge.git] / content / browser / media / capture / video_capture_oracle.h
blob6242b6a29a8e5d24338c1c44b7fcf7f61f815402
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef CONTENT_BROWSER_MEDIA_CAPTURE_VIDEO_CAPTURE_ORACLE_H_
6 #define CONTENT_BROWSER_MEDIA_CAPTURE_VIDEO_CAPTURE_ORACLE_H_
8 #include "base/callback_forward.h"
9 #include "base/memory/scoped_ptr.h"
10 #include "base/time/time.h"
11 #include "content/common/content_export.h"
13 namespace content {
15 // Filters a sequence of events to achieve a target frequency.
16 class CONTENT_EXPORT SmoothEventSampler {
17 public:
18 explicit SmoothEventSampler(base::TimeDelta capture_period,
19 bool events_are_reliable,
20 int redundant_capture_goal);
22 // Add a new event to the event history, and return whether it ought to be
23 // sampled based on the desired |capture_period|. The event is not recorded as
24 // a sample until RecordSample() is called.
25 bool AddEventAndConsiderSampling(base::TimeTicks event_time);
27 // Operates on the last event added by AddEventAndConsiderSampling(), marking
28 // it as sampled. After this point we are current in the stream of events, as
29 // we have sampled the most recent event.
30 void RecordSample();
32 // Returns true if, at time |event_time|, sampling should occur because too
33 // much time will have passed relative to the last event and/or sample.
34 bool IsOverdueForSamplingAt(base::TimeTicks event_time) const;
36 // Returns true if AddEventAndConsiderSampling() has been called since the
37 // last call to RecordSample().
38 bool HasUnrecordedEvent() const;
40 private:
41 const bool events_are_reliable_;
42 const base::TimeDelta capture_period_;
43 const int redundant_capture_goal_;
44 const base::TimeDelta token_bucket_capacity_;
46 base::TimeTicks current_event_;
47 base::TimeTicks last_sample_;
48 int overdue_sample_count_;
49 base::TimeDelta token_bucket_;
51 DISALLOW_COPY_AND_ASSIGN(SmoothEventSampler);
54 // VideoCaptureOracle manages the producer-side throttling of captured frames
55 // from a video capture device. It is informed of every update by the device;
56 // this empowers it to look into the future and decide if a particular frame
57 // ought to be captured in order to achieve its target frame rate.
58 class CONTENT_EXPORT VideoCaptureOracle {
59 public:
60 enum Event {
61 kTimerPoll,
62 kCompositorUpdate,
63 kSoftwarePaint,
66 VideoCaptureOracle(base::TimeDelta capture_period,
67 bool events_are_reliable);
68 virtual ~VideoCaptureOracle() {}
70 // Record an event of type |event|, and decide whether the caller should do a
71 // frame capture immediately. Decisions of the oracle are final: the caller
72 // must do what it is told.
73 bool ObserveEventAndDecideCapture(Event event, base::TimeTicks event_time);
75 // Record the start of a capture. Returns a frame_number to be used with
76 // CompleteCapture().
77 int RecordCapture();
79 // Record the completion of a capture. Returns true iff the captured frame
80 // should be delivered.
81 bool CompleteCapture(int frame_number, base::TimeTicks timestamp);
83 base::TimeDelta capture_period() const { return capture_period_; }
85 private:
87 // Time between frames.
88 const base::TimeDelta capture_period_;
90 // Incremented every time a paint or update event occurs.
91 int frame_number_;
93 // Stores the frame number from the last delivered frame.
94 int last_delivered_frame_number_;
96 // Stores the timestamp of the last delivered frame.
97 base::TimeTicks last_delivered_frame_timestamp_;
99 // Tracks present/paint history.
100 SmoothEventSampler sampler_;
103 } // namespace content
105 #endif // CONTENT_BROWSER_MEDIA_CAPTURE_VIDEO_CAPTURE_ORACLE_H_