Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 // This class chooses a capture interval so as to limit CPU usage to not exceed | 5 // This class chooses a capture interval so as to limit CPU usage to not exceed |
| 6 // a specified %age. It bases this on the CPU usage of recent capture and encode | 6 // a specified %age. It bases this on the CPU usage of recent capture and encode |
| 7 // operations, and on the number of available CPUs. | 7 // operations, and on the number of available CPUs. |
| 8 | 8 |
| 9 #ifndef REMOTING_HOST_CAPTURE_SCHEDULER_H_ | 9 #ifndef REMOTING_HOST_CAPTURE_SCHEDULER_H_ |
| 10 #define REMOTING_HOST_CAPTURE_SCHEDULER_H_ | 10 #define REMOTING_HOST_CAPTURE_SCHEDULER_H_ |
| 11 | 11 |
| 12 #include "base/callback.h" | |
| 13 #include "base/threading/non_thread_safe.h" | |
| 14 #include "base/time/tick_clock.h" | |
| 12 #include "base/time/time.h" | 15 #include "base/time/time.h" |
| 16 #include "base/timer/timer.h" | |
| 13 #include "remoting/base/running_average.h" | 17 #include "remoting/base/running_average.h" |
| 14 | 18 |
| 15 namespace remoting { | 19 namespace remoting { |
| 16 | 20 |
| 17 class CaptureScheduler { | 21 // CaptureScheduler is used by the VideoScheduler to schedule frame capturer, |
| 22 // taking into account capture delay, encoder delay, network bandwidth, etc. | |
| 23 class CaptureScheduler : public base::NonThreadSafe { | |
| 18 public: | 24 public: |
| 19 CaptureScheduler(); | 25 // |capture_closure| is called every time a new frame needs to be captured. |
| 26 explicit CaptureScheduler(const base::Closure& capture_closure); | |
| 20 ~CaptureScheduler(); | 27 ~CaptureScheduler(); |
| 21 | 28 |
| 22 // Returns the time to wait after initiating a capture before triggering | 29 // Starts the scheduler. |
| 23 // the next. | 30 void Start(); |
| 24 base::TimeDelta NextCaptureDelay(); | |
| 25 | 31 |
| 26 // Records time spent on capturing and encoding. | 32 // Pauses or unpauses the stream. |
| 27 void RecordCaptureTime(base::TimeDelta capture_time); | 33 void Pause(bool pause); |
| 28 void RecordEncodeTime(base::TimeDelta encode_time); | 34 |
| 35 // Notifies the scheduler that a capture has been completed. | |
| 36 void OnCaptureCompleted(); | |
| 37 | |
| 38 // Notifies the scheduler that a frame has been encoded. | |
| 39 void OnFrameEncoded(base::TimeDelta encode_time); | |
| 40 | |
| 41 // Notifies the scheduler that a frame has been sent. | |
| 42 void OnFrameSent(); | |
| 29 | 43 |
| 30 // Sets minimum interval between frames. | 44 // Sets minimum interval between frames. |
| 31 void set_minimum_interval(base::TimeDelta minimum_interval) { | 45 void set_minimum_interval(base::TimeDelta minimum_interval) { |
| 32 minimum_interval_ = minimum_interval; | 46 minimum_interval_ = minimum_interval; |
| 33 } | 47 } |
| 34 | 48 |
| 35 // Overrides the number of processors for testing. | 49 // Helper functions for tests. |
| 50 void SetTickClockForTest(scoped_ptr<base::TickClock> tick_clock); | |
| 51 void SetTimerForTest(scoped_ptr<base::Timer> timer); | |
| 36 void SetNumOfProcessorsForTest(int num_of_processors); | 52 void SetNumOfProcessorsForTest(int num_of_processors); |
| 37 | 53 |
| 38 private: | 54 private: |
| 55 // Schedules |capture_timer_| to call CaptureNextFrame() at appropriate time. | |
| 56 // Doesn't do anything if next frame cannot be captured yet (e.g. because | |
| 57 // there are too many frames being processed). | |
| 58 void ScheduleNextCapture(); | |
| 59 | |
| 60 // Called by |capture_timer_|. Calls |capture_closure_| to start capturing a | |
| 61 // new frame. | |
| 62 void CaptureNextFrame(); | |
| 63 | |
| 64 base::Closure capture_closure_; | |
| 65 | |
| 66 scoped_ptr<base::TickClock> tick_clock_; | |
| 67 | |
| 68 // Timer used to schedule CaptureNextFrame(). | |
| 69 scoped_ptr<base::Timer> capture_timer_; | |
| 70 | |
| 71 // Minimum interval between frames that determines maximum possible framerate. | |
| 39 base::TimeDelta minimum_interval_; | 72 base::TimeDelta minimum_interval_; |
| 73 | |
| 40 int num_of_processors_; | 74 int num_of_processors_; |
| 75 | |
| 41 RunningAverage capture_time_; | 76 RunningAverage capture_time_; |
| 42 RunningAverage encode_time_; | 77 RunningAverage encode_time_; |
| 43 | 78 |
| 79 // Total number of pending frames that are being captured, encoded or sent. | |
| 80 int pending_frames_; | |
| 81 | |
| 82 // Set to true when capture is pending. | |
| 83 bool capture_pending_; | |
| 84 | |
| 85 // Time the last capture started. Used to schedule |capture_timer_|. | |
|
Wez
2015/02/05 02:40:25
Suggest: "Time at which the last capture started."
Sergey Ulanov
2015/02/05 19:13:27
Done.
| |
| 86 base::TimeTicks last_capture_started_time_; | |
| 87 | |
| 88 bool is_paused_; | |
| 89 | |
| 44 DISALLOW_COPY_AND_ASSIGN(CaptureScheduler); | 90 DISALLOW_COPY_AND_ASSIGN(CaptureScheduler); |
| 45 }; | 91 }; |
| 46 | 92 |
| 47 } // namespace remoting | 93 } // namespace remoting |
| 48 | 94 |
| 49 #endif // REMOTING_HOST_CAPTURE_SCHEDULER_H_ | 95 #endif // REMOTING_HOST_CAPTURE_SCHEDULER_H_ |
| OLD | NEW |