Index: remoting/host/capture_scheduler.h |
diff --git a/remoting/host/capture_scheduler.h b/remoting/host/capture_scheduler.h |
index 9dbecdad3d14720167cf321977f45c46afa4a618..610b35ba490b9cb1ef4b5bcedbde46bd6d28c624 100644 |
--- a/remoting/host/capture_scheduler.h |
+++ b/remoting/host/capture_scheduler.h |
@@ -9,38 +9,83 @@ |
#ifndef REMOTING_HOST_CAPTURE_SCHEDULER_H_ |
#define REMOTING_HOST_CAPTURE_SCHEDULER_H_ |
+#include "base/callback.h" |
+#include "base/threading/non_thread_safe.h" |
+#include "base/time/tick_clock.h" |
#include "base/time/time.h" |
+#include "base/timer/timer.h" |
#include "remoting/base/running_average.h" |
namespace remoting { |
-class CaptureScheduler { |
+// CaptureScheduler is used by the VideoScheduler to scheduler frame capturer, |
+// taking into account capture delay, encoder delay, network bandwidth, etc. |
+class CaptureScheduler : public base::NonThreadSafe { |
public: |
- CaptureScheduler(); |
+ explicit CaptureScheduler(const base::Closure& capture_closure); |
~CaptureScheduler(); |
- // Returns the time to wait after initiating a capture before triggering |
- // the next. |
- base::TimeDelta NextCaptureDelay(); |
+ // Starts the scheduler. |
+ void Start(); |
- // Records time spent on capturing and encoding. |
- void RecordCaptureTime(base::TimeDelta capture_time); |
- void RecordEncodeTime(base::TimeDelta encode_time); |
+ // Pauses or unpauses the stream. |
+ void Pause(bool pause); |
+ |
+ // Notifies the scheduler that a capture has been completed. |
+ void OnCaptureCompleted(); |
+ |
+ // Notifies the scheduler than a frame has been encoded. |
+ void OnFrameEncoded(base::TimeDelta encode_time); |
+ |
+ // Notifies the scheduler than a frame has been sent. |
+ void OnFrameSent(); |
// Sets minimum interval between frames. |
void set_minimum_interval(base::TimeDelta minimum_interval) { |
minimum_interval_ = minimum_interval; |
} |
- // Overrides the number of processors for testing. |
- void SetNumOfProcessorsForTest(int num_of_processors); |
+ // Helper functions for tests. |
+ void set_tick_clock_for_tests(scoped_ptr<base::TickClock> tick_clock) { |
+ tick_clock_ = tick_clock.Pass(); |
+ } |
+ void set_timer_for_tests(scoped_ptr<base::Timer> timer) { |
+ capture_timer_ = timer.Pass(); |
+ } |
+ void set_num_of_processors_for_tests(int num_of_processors) { |
+ num_of_processors_ = num_of_processors; |
+ } |
private: |
+ // Schedules |capture_timer_| to call CaptureNextFrame() at appropriate time. |
+ // Doesn't do anything if next frame cannot be captured yet (e.g. because |
+ // there are too many frames being processed). |
+ void ScheduleNextCapture(); |
+ |
+ // Called by |capture_timer_|. Calls |capture_closure_| to start capturing a |
+ // new frame. |
+ void CaptureNextFrame(); |
+ |
+ base::Closure capture_closure_; |
+ |
+ scoped_ptr<base::TickClock> tick_clock_; |
Wez
2015/02/02 21:40:48
tick_clock_for_tests_?
Sergey Ulanov
2015/02/03 23:49:52
I don't think that would be appropriate name for i
|
+ |
+ // Timer used to schedule CaptureNextFrame(). |
+ scoped_ptr<base::Timer> capture_timer_; |
+ |
+ // Minimum interval between frames. |
base::TimeDelta minimum_interval_; |
+ |
int num_of_processors_; |
+ |
RunningAverage capture_time_; |
RunningAverage encode_time_; |
+ int pending_frames_; |
+ bool capture_pending_; |
+ base::TimeTicks last_capture_started_time_; |
+ bool is_paused_; |
+ |
DISALLOW_COPY_AND_ASSIGN(CaptureScheduler); |
}; |