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

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
« no previous file with comments | « no previous file | remoting/host/capture_scheduler.cc » ('j') | remoting/host/capture_scheduler.cc » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
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.
8
9 #ifndef REMOTING_HOST_CAPTURE_SCHEDULER_H_ 5 #ifndef REMOTING_HOST_CAPTURE_SCHEDULER_H_
10 #define REMOTING_HOST_CAPTURE_SCHEDULER_H_ 6 #define REMOTING_HOST_CAPTURE_SCHEDULER_H_
11 7
12 #include "base/callback.h" 8 #include "base/callback.h"
13 #include "base/threading/non_thread_safe.h" 9 #include "base/threading/non_thread_safe.h"
14 #include "base/time/tick_clock.h" 10 #include "base/time/tick_clock.h"
15 #include "base/time/time.h" 11 #include "base/time/time.h"
16 #include "base/timer/timer.h" 12 #include "base/timer/timer.h"
17 #include "remoting/base/running_average.h" 13 #include "remoting/base/running_average.h"
14 #include "remoting/protocol/video_feedback_stub.h"
18 15
19 namespace remoting { 16 namespace remoting {
20 17
18 class VideoPacket;
19
21 // CaptureScheduler is used by the VideoFramePump to schedule frame capturer, 20 // CaptureScheduler is used by the VideoFramePump to schedule frame capturer,
22 // taking into account capture delay, encoder delay, network bandwidth, etc. 21 // taking into account capture delay, encoder delay, network bandwidth, etc.
23 class CaptureScheduler : public base::NonThreadSafe { 22 //
23 // This class chooses a capture interval so as to limit CPU usage to not exceed
24 // a specified percentage. It bases this on the CPU usage of recent capture and
25 // encode operations, and on the number of available CPUs.
26 //
27 // CaptureScheduler also implements VideoFeedbackStub to receive frame
28 // acknowledgments from the client. If the client supports acknowledgments
29 // then it limits total number of captured frames that haven't been
30 // acknowledged (currently the limit is set to 4 frames). Otherwise it limits
31 // total number of frames in the encoding and sending queues to 2.
32 class CaptureScheduler : public base::NonThreadSafe,
33 public protocol::VideoFeedbackStub {
24 public: 34 public:
25 // |capture_closure| is called every time a new frame needs to be captured.
26 explicit CaptureScheduler(const base::Closure& capture_closure); 35 explicit CaptureScheduler(const base::Closure& capture_closure);
27 ~CaptureScheduler(); 36 ~CaptureScheduler();
28 37
29 // Starts the scheduler. 38 // Starts the scheduler.
30 void Start(); 39 void Start();
31 40
32 // Pauses or unpauses the stream. 41 // Pauses or unpauses the stream.
33 void Pause(bool pause); 42 void Pause(bool pause);
34 43
35 // Notifies the scheduler that a capture has been completed. 44 // Notifies the scheduler that a capture has been completed.
36 void OnCaptureCompleted(); 45 void OnCaptureCompleted();
37 46
38 // Notifies the scheduler that a frame has been encoded. 47 // Notifies the scheduler that a frame has been encoded. The scheduler can
39 void OnFrameEncoded(base::TimeDelta encode_time); 48 // change |packet| if necessary, e.g. set |frame_id|.
49 void OnFrameEncoded(VideoPacket* packet);
40 50
41 // Notifies the scheduler that a frame has been sent. 51 // Notifies the scheduler that a frame has been sent.
42 void OnFrameSent(); 52 void OnFrameSent();
43 53
54 // VideoFeedbackStub interface.
55 void ProcessVideoAck(scoped_ptr<VideoAck> video_ack) override;
56
44 // Sets minimum interval between frames. 57 // Sets minimum interval between frames.
45 void set_minimum_interval(base::TimeDelta minimum_interval) { 58 void set_minimum_interval(base::TimeDelta minimum_interval) {
46 minimum_interval_ = minimum_interval; 59 minimum_interval_ = minimum_interval;
47 } 60 }
48 61
49 // Helper functions for tests. 62 // Helper functions for tests.
50 void SetTickClockForTest(scoped_ptr<base::TickClock> tick_clock); 63 void SetTickClockForTest(scoped_ptr<base::TickClock> tick_clock);
51 void SetTimerForTest(scoped_ptr<base::Timer> timer); 64 void SetTimerForTest(scoped_ptr<base::Timer> timer);
52 void SetNumOfProcessorsForTest(int num_of_processors); 65 void SetNumOfProcessorsForTest(int num_of_processors);
53 66
54 private: 67 private:
55 // Schedules |capture_timer_| to call CaptureNextFrame() at appropriate time. 68 // Schedules |capture_timer_| to call CaptureNextFrame() at appropriate time.
56 // Doesn't do anything if next frame cannot be captured yet (e.g. because 69 // Doesn't do anything if next frame cannot be captured yet (e.g. because
57 // there are too many frames being processed). 70 // there are too many frames being processed).
58 void ScheduleNextCapture(); 71 void ScheduleNextCapture();
59 72
60 // Called by |capture_timer_|. Calls |capture_closure_| to start capturing a 73 // Called by |capture_timer_|. Calls |capture_closure_| to start capturing a
61 // new frame. 74 // new frame.
62 void CaptureNextFrame(); 75 void CaptureNextFrame();
63 76
64 base::Closure capture_closure_; 77 base::Closure capture_closure_;
65 78
79 // Set to true if the connection supports video frame acknowledgments.
80 bool acks_supported_;
81
66 scoped_ptr<base::TickClock> tick_clock_; 82 scoped_ptr<base::TickClock> tick_clock_;
67 83
68 // Timer used to schedule CaptureNextFrame(). 84 // Timer used to schedule CaptureNextFrame().
69 scoped_ptr<base::Timer> capture_timer_; 85 scoped_ptr<base::Timer> capture_timer_;
70 86
71 // Minimum interval between frames that determines maximum possible framerate. 87 // Minimum interval between frames that determines maximum possible framerate.
72 base::TimeDelta minimum_interval_; 88 base::TimeDelta minimum_interval_;
73 89
74 int num_of_processors_; 90 int num_of_processors_;
75 91
76 RunningAverage capture_time_; 92 RunningAverage capture_time_;
77 RunningAverage encode_time_; 93 RunningAverage encode_time_;
78 94
79 // Total number of pending frames that are being captured, encoded or sent. 95 // Number of frames pending encoding.
80 int pending_frames_; 96 int num_encoding_frames_;
97
98 // Number of frames in the sending queue.
99 int num_sending_frames_;
100
101 // Number of outgoing frames for which we haven't received an acknowledgment.
102 int num_unacknowledged_frames_;
81 103
82 // Set to true when capture is pending. 104 // Set to true when capture is pending.
83 bool capture_pending_; 105 bool capture_pending_;
84 106
85 // Time at which the last capture started. Used to schedule |capture_timer_|. 107 // Time at which the last capture started. Used to schedule |capture_timer_|.
86 base::TimeTicks last_capture_started_time_; 108 base::TimeTicks last_capture_started_time_;
87 109
88 bool is_paused_; 110 bool is_paused_;
89 111
112 // frame_id to be assigned to the next outgoing video frame.
Wez 2015/02/21 03:12:02 nit: Either "Frame Id to be ..." or "|frame_id| to
Sergey Ulanov 2015/02/23 17:35:38 Done.
113 uint32_t next_frame_id_;
114
90 DISALLOW_COPY_AND_ASSIGN(CaptureScheduler); 115 DISALLOW_COPY_AND_ASSIGN(CaptureScheduler);
91 }; 116 };
92 117
93 } // namespace remoting 118 } // namespace remoting
94 119
95 #endif // REMOTING_HOST_CAPTURE_SCHEDULER_H_ 120 #endif // REMOTING_HOST_CAPTURE_SCHEDULER_H_
OLDNEW
« no previous file with comments | « no previous file | remoting/host/capture_scheduler.cc » ('j') | remoting/host/capture_scheduler.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698