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 scheduler frame capturer, |
Wez
2015/02/02 21:40:49
s/scheduler/schedule
Sergey Ulanov
2015/02/03 23:49:52
Done.
| |
22 // taking into account capture delay, encoder delay, network bandwidth, etc. | |
23 class CaptureScheduler : public base::NonThreadSafe { | |
18 public: | 24 public: |
19 CaptureScheduler(); | 25 explicit CaptureScheduler(const base::Closure& capture_closure); |
Wez
2015/02/02 21:40:48
Suggest adding a comment to explain that |capture_
Sergey Ulanov
2015/02/03 23:49:52
Done.
| |
20 ~CaptureScheduler(); | 26 ~CaptureScheduler(); |
21 | 27 |
22 // Returns the time to wait after initiating a capture before triggering | 28 // Starts the scheduler. |
23 // the next. | 29 void Start(); |
24 base::TimeDelta NextCaptureDelay(); | |
25 | 30 |
26 // Records time spent on capturing and encoding. | 31 // Pauses or unpauses the stream. |
27 void RecordCaptureTime(base::TimeDelta capture_time); | 32 void Pause(bool pause); |
28 void RecordEncodeTime(base::TimeDelta encode_time); | 33 |
34 // Notifies the scheduler that a capture has been completed. | |
35 void OnCaptureCompleted(); | |
36 | |
37 // Notifies the scheduler than a frame has been encoded. | |
Wez
2015/02/02 21:40:48
s/than/that
Sergey Ulanov
2015/02/03 23:49:52
Done.
| |
38 void OnFrameEncoded(base::TimeDelta encode_time); | |
39 | |
40 // Notifies the scheduler than a frame has been sent. | |
Wez
2015/02/02 21:40:48
s/than/that
Sergey Ulanov
2015/02/03 23:49:52
Done.
| |
41 void OnFrameSent(); | |
29 | 42 |
30 // Sets minimum interval between frames. | 43 // Sets minimum interval between frames. |
31 void set_minimum_interval(base::TimeDelta minimum_interval) { | 44 void set_minimum_interval(base::TimeDelta minimum_interval) { |
32 minimum_interval_ = minimum_interval; | 45 minimum_interval_ = minimum_interval; |
33 } | 46 } |
34 | 47 |
35 // Overrides the number of processors for testing. | 48 // Helper functions for tests. |
36 void SetNumOfProcessorsForTest(int num_of_processors); | 49 void set_tick_clock_for_tests(scoped_ptr<base::TickClock> tick_clock) { |
Wez
2015/02/02 21:40:48
nit: Should these be SetTickClockForTest and simil
Sergey Ulanov
2015/02/03 23:49:52
Done.
| |
50 tick_clock_ = tick_clock.Pass(); | |
51 } | |
52 void set_timer_for_tests(scoped_ptr<base::Timer> timer) { | |
53 capture_timer_ = timer.Pass(); | |
54 } | |
55 void set_num_of_processors_for_tests(int num_of_processors) { | |
56 num_of_processors_ = num_of_processors; | |
57 } | |
37 | 58 |
38 private: | 59 private: |
60 // Schedules |capture_timer_| to call CaptureNextFrame() at appropriate time. | |
61 // Doesn't do anything if next frame cannot be captured yet (e.g. because | |
62 // there are too many frames being processed). | |
63 void ScheduleNextCapture(); | |
64 | |
65 // Called by |capture_timer_|. Calls |capture_closure_| to start capturing a | |
66 // new frame. | |
67 void CaptureNextFrame(); | |
68 | |
69 base::Closure capture_closure_; | |
70 | |
71 scoped_ptr<base::TickClock> tick_clock_; | |
72 | |
73 // Timer used to schedule CaptureNextFrame(). | |
74 scoped_ptr<base::Timer> capture_timer_; | |
75 | |
76 // Minimum interval between frames. | |
Wez
2015/02/02 21:40:48
How is this set and what's it used for?
Sergey Ulanov
2015/02/03 23:49:52
Removed it.
| |
39 base::TimeDelta minimum_interval_; | 77 base::TimeDelta minimum_interval_; |
78 | |
40 int num_of_processors_; | 79 int num_of_processors_; |
80 | |
41 RunningAverage capture_time_; | 81 RunningAverage capture_time_; |
42 RunningAverage encode_time_; | 82 RunningAverage encode_time_; |
43 | 83 |
84 int pending_frames_; | |
Wez
2015/02/02 21:40:48
What does it mean for a frame to be "pending" - fr
Sergey Ulanov
2015/02/03 23:49:52
Done.
| |
85 bool capture_pending_; | |
86 base::TimeTicks last_capture_started_time_; | |
87 bool is_paused_; | |
88 | |
44 DISALLOW_COPY_AND_ASSIGN(CaptureScheduler); | 89 DISALLOW_COPY_AND_ASSIGN(CaptureScheduler); |
45 }; | 90 }; |
46 | 91 |
47 } // namespace remoting | 92 } // namespace remoting |
48 | 93 |
49 #endif // REMOTING_HOST_CAPTURE_SCHEDULER_H_ | 94 #endif // REMOTING_HOST_CAPTURE_SCHEDULER_H_ |
OLD | NEW |