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

Side by Side Diff: remoting/host/capture_scheduler.h

Issue 850983002: Implement video frame acknowledgements in the chromoting protocol. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 10 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
OLDNEW
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" 12 #include "base/callback.h"
13 #include "base/threading/non_thread_safe.h" 13 #include "base/threading/non_thread_safe.h"
14 #include "base/time/tick_clock.h" 14 #include "base/time/tick_clock.h"
15 #include "base/time/time.h" 15 #include "base/time/time.h"
16 #include "base/timer/timer.h" 16 #include "base/timer/timer.h"
17 #include "remoting/base/running_average.h" 17 #include "remoting/base/running_average.h"
18 18
19 namespace remoting { 19 namespace remoting {
20 20
21 // CaptureScheduler is used by the VideoScheduler to scheduler frame capturer, 21 // CaptureScheduler is used by the VideoScheduler to scheduler frame capturer,
22 // taking into account capture delay, encoder delay, network bandwidth, etc. 22 // taking into account capture delay, encoder delay, network bandwidth, etc.
23 class CaptureScheduler : public base::NonThreadSafe { 23 class CaptureScheduler : public base::NonThreadSafe {
24 public: 24 public:
25 explicit CaptureScheduler(const base::Closure& capture_closure); 25 CaptureScheduler(const base::Closure& capture_closure, bool acks_supported);
26 ~CaptureScheduler(); 26 ~CaptureScheduler();
27 27
28 // Starts the scheduler. 28 // Starts the scheduler.
29 void Start(); 29 void Start();
30 30
31 // Pauses or unpauses the stream. 31 // Pauses or unpauses the stream.
32 void Pause(bool pause); 32 void Pause(bool pause);
33 33
34 // Notifies the scheduler that a capture has been completed. 34 // Notifies the scheduler that a capture has been completed.
35 void OnCaptureCompleted(); 35 void OnCaptureCompleted();
36 36
37 // Notifies the scheduler than a frame has been encoded. 37 // Notifies the scheduler than a frame has been encoded.
38 void OnFrameEncoded(base::TimeDelta encode_time); 38 void OnFrameEncoded(base::TimeDelta encode_time);
39 39
40 // Notifies the scheduler than a frame has been sent. 40 // Notifies the scheduler than a frame has been sent.
41 void OnFrameSent(); 41 void OnFrameSent();
42 42
43 // Notifies the scheduler than a frame has been acknowledged.
44 void OnFrameAck();
45
46 // Sets maximum number of pending frames in the sending queue. When ACKs are
47 // supported frames is considered to be pending until ACK message is received,
Wez 2015/02/03 00:54:32 s/is/are
Sergey Ulanov 2015/02/09 19:14:54 Removed this function now
48 // otherwise it's pending until it's sent (OnFrameSent() is called).
Wez 2015/02/03 00:54:32 If the two things are treated equivalently, simply
Sergey Ulanov 2015/02/09 19:14:54 Removed this function now
49 void set_maximum_pending_frames(int max_pending_frames) {
50 max_pending_frames_ = max_pending_frames;
51 }
52
43 // Sets minimum interval between frames. 53 // Sets minimum interval between frames.
44 void set_minimum_interval(base::TimeDelta minimum_interval) { 54 void set_minimum_interval(base::TimeDelta minimum_interval) {
45 minimum_interval_ = minimum_interval; 55 minimum_interval_ = minimum_interval;
46 } 56 }
47 57
48 // Helper functions for tests. 58 // Helper functions for tests.
49 void set_tick_clock_for_tests(scoped_ptr<base::TickClock> tick_clock) { 59 void set_tick_clock_for_tests(scoped_ptr<base::TickClock> tick_clock) {
50 tick_clock_ = tick_clock.Pass(); 60 tick_clock_ = tick_clock.Pass();
51 } 61 }
52 void set_timer_for_tests(scoped_ptr<base::Timer> timer) { 62 void set_timer_for_tests(scoped_ptr<base::Timer> timer) {
53 capture_timer_ = timer.Pass(); 63 capture_timer_ = timer.Pass();
54 } 64 }
55 void set_num_of_processors_for_tests(int num_of_processors) { 65 void set_num_of_processors_for_tests(int num_of_processors) {
56 num_of_processors_ = num_of_processors; 66 num_of_processors_ = num_of_processors;
57 } 67 }
58 68
59 private: 69 private:
60 // Schedules |capture_timer_| to call CaptureNextFrame() at appropriate time. 70 // Schedules |capture_timer_| to call CaptureNextFrame() at appropriate time.
61 // Doesn't do anything if next frame cannot be captured yet (e.g. because 71 // Doesn't do anything if next frame cannot be captured yet (e.g. because
62 // there are too many frames being processed). 72 // there are too many frames being processed).
63 void ScheduleNextCapture(); 73 void ScheduleNextCapture();
64 74
65 // Called by |capture_timer_|. Calls |capture_closure_| to start capturing a 75 // Called by |capture_timer_|. Calls |capture_closure_| to start capturing a
66 // new frame. 76 // new frame.
67 void CaptureNextFrame(); 77 void CaptureNextFrame();
68 78
69 base::Closure capture_closure_; 79 base::Closure capture_closure_;
70 80
81 // Set to true if the connection supports video frame acknowledgments.
82 bool acks_supported_;
83
84 // Maximum number of pending frames.
85 int max_pending_frames_;
86
71 scoped_ptr<base::TickClock> tick_clock_; 87 scoped_ptr<base::TickClock> tick_clock_;
72 88
73 // Timer used to schedule CaptureNextFrame(). 89 // Timer used to schedule CaptureNextFrame().
74 scoped_ptr<base::Timer> capture_timer_; 90 scoped_ptr<base::Timer> capture_timer_;
75 91
76 // Minimum interval between frames. 92 // Minimum interval between frames.
77 base::TimeDelta minimum_interval_; 93 base::TimeDelta minimum_interval_;
78 94
79 int num_of_processors_; 95 int num_of_processors_;
80 96
81 RunningAverage capture_time_; 97 RunningAverage capture_time_;
82 RunningAverage encode_time_; 98 RunningAverage encode_time_;
83 99
84 int pending_frames_; 100 int num_encoding_frames_;
101 int num_sending_frames_;
102
85 bool capture_pending_; 103 bool capture_pending_;
86 base::TimeTicks last_capture_started_time_; 104 base::TimeTicks last_capture_started_time_;
87 bool is_paused_; 105 bool is_paused_;
88 106
89 DISALLOW_COPY_AND_ASSIGN(CaptureScheduler); 107 DISALLOW_COPY_AND_ASSIGN(CaptureScheduler);
90 }; 108 };
91 109
92 } // namespace remoting 110 } // namespace remoting
93 111
94 #endif // REMOTING_HOST_CAPTURE_SCHEDULER_H_ 112 #endif // REMOTING_HOST_CAPTURE_SCHEDULER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698