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

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

Issue 11761019: Tiny little refactoring of DesktopEnvironment. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 11 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 | Annotate | Revision Log
« no previous file with comments | « remoting/host/remoting_me2me_host.cc ('k') | remoting/host/video_scheduler.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 #ifndef REMOTING_HOST_VIDEO_SCHEDULER_H_ 5 #ifndef REMOTING_HOST_VIDEO_SCHEDULER_H_
6 #define REMOTING_HOST_VIDEO_SCHEDULER_H_ 6 #define REMOTING_HOST_VIDEO_SCHEDULER_H_
7 7
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/basictypes.h" 10 #include "base/basictypes.h"
11 #include "base/callback.h"
12 #include "base/memory/ref_counted.h" 11 #include "base/memory/ref_counted.h"
13 #include "base/memory/scoped_ptr.h" 12 #include "base/memory/scoped_ptr.h"
14 #include "base/time.h" 13 #include "base/time.h"
15 #include "base/timer.h" 14 #include "base/timer.h"
16 #include "remoting/capturer/video_frame_capturer.h" 15 #include "remoting/capturer/video_frame_capturer.h"
17 #include "remoting/codec/video_encoder.h" 16 #include "remoting/codec/video_encoder.h"
18 #include "remoting/host/capture_scheduler.h" 17 #include "remoting/host/capture_scheduler.h"
19 #include "remoting/proto/video.pb.h" 18 #include "remoting/proto/video.pb.h"
19 #include "third_party/skia/include/core/SkSize.h"
20 20
21 namespace base { 21 namespace base {
22 class SingleThreadTaskRunner; 22 class SingleThreadTaskRunner;
23 } // namespace base 23 } // namespace base
24 24
25 namespace remoting { 25 namespace remoting {
26 26
27 class CaptureData; 27 class CaptureData;
28 class CursorShapeInfo; 28 class CursorShapeInfo;
29 class VideoFrameCapturer; 29 class VideoFrameCapturer;
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
69 // of the capture, encode and network processes. However, it also needs to 69 // of the capture, encode and network processes. However, it also needs to
70 // rate-limit captures to avoid overloading the host system, either by consuming 70 // rate-limit captures to avoid overloading the host system, either by consuming
71 // too much CPU, or hogging the host's graphics subsystem. 71 // too much CPU, or hogging the host's graphics subsystem.
72 72
73 class VideoScheduler : public base::RefCountedThreadSafe<VideoScheduler>, 73 class VideoScheduler : public base::RefCountedThreadSafe<VideoScheduler>,
74 public VideoFrameCapturer::Delegate { 74 public VideoFrameCapturer::Delegate {
75 public: 75 public:
76 // Creates a VideoScheduler running capture, encode and network tasks on the 76 // Creates a VideoScheduler running capture, encode and network tasks on the
77 // supplied TaskRunners. Video and cursor shape updates will be pumped to 77 // supplied TaskRunners. Video and cursor shape updates will be pumped to
78 // |video_stub| and |client_stub|, which must remain valid until Stop() is 78 // |video_stub| and |client_stub|, which must remain valid until Stop() is
79 // called. |capturer| is used to capture frames and must remain valid until 79 // called. |capturer| is used to capture frames.
80 // the |done_task| supplied to Stop() is executed.
81 static scoped_refptr<VideoScheduler> Create( 80 static scoped_refptr<VideoScheduler> Create(
82 scoped_refptr<base::SingleThreadTaskRunner> capture_task_runner, 81 scoped_refptr<base::SingleThreadTaskRunner> capture_task_runner,
83 scoped_refptr<base::SingleThreadTaskRunner> encode_task_runner, 82 scoped_refptr<base::SingleThreadTaskRunner> encode_task_runner,
84 scoped_refptr<base::SingleThreadTaskRunner> network_task_runner, 83 scoped_refptr<base::SingleThreadTaskRunner> network_task_runner,
85 VideoFrameCapturer* capturer, 84 scoped_ptr<VideoFrameCapturer> capturer,
86 scoped_ptr<VideoEncoder> encoder, 85 scoped_ptr<VideoEncoder> encoder,
87 protocol::CursorShapeStub* cursor_stub, 86 protocol::CursorShapeStub* cursor_stub,
88 protocol::VideoStub* video_stub); 87 protocol::VideoStub* video_stub);
89 88
90 // VideoFrameCapturer::Delegate implementation. 89 // VideoFrameCapturer::Delegate implementation.
91 virtual void OnCaptureCompleted( 90 virtual void OnCaptureCompleted(
92 scoped_refptr<CaptureData> capture_data) OVERRIDE; 91 scoped_refptr<CaptureData> capture_data) OVERRIDE;
93 virtual void OnCursorShapeChanged( 92 virtual void OnCursorShapeChanged(
94 scoped_ptr<MouseCursorShape> cursor_shape) OVERRIDE; 93 scoped_ptr<MouseCursorShape> cursor_shape) OVERRIDE;
95 94
96 // Stop scheduling frame captures. |done_task| is executed on the network 95 // Stop scheduling frame captures. This object cannot be re-used once
97 // thread when capturing has stopped. This object cannot be re-used once
98 // it has been stopped. 96 // it has been stopped.
99 void Stop(const base::Closure& done_task); 97 void Stop();
100 98
101 // Pauses or resumes scheduling of frame captures. Pausing/resuming captures 99 // Pauses or resumes scheduling of frame captures. Pausing/resuming captures
102 // only affects capture scheduling and does not stop/start the capturer. 100 // only affects capture scheduling and does not stop/start the capturer.
103 void Pause(bool pause); 101 void Pause(bool pause);
104 102
105 // Updates the sequence number embedded in VideoPackets. 103 // Updates the sequence number embedded in VideoPackets.
106 // Sequence numbers are used for performance measurements. 104 // Sequence numbers are used for performance measurements.
107 void UpdateSequenceNumber(int64 sequence_number); 105 void UpdateSequenceNumber(int64 sequence_number);
108 106
107 // Returns size of the most recent captured frame.
108 const SkISize& size_most_recent() const { return size_most_recent_; }
109
109 private: 110 private:
110 friend class base::RefCountedThreadSafe<VideoScheduler>; 111 friend class base::RefCountedThreadSafe<VideoScheduler>;
111 112
112 VideoScheduler( 113 VideoScheduler(
113 scoped_refptr<base::SingleThreadTaskRunner> capture_task_runner, 114 scoped_refptr<base::SingleThreadTaskRunner> capture_task_runner,
114 scoped_refptr<base::SingleThreadTaskRunner> encode_task_runner, 115 scoped_refptr<base::SingleThreadTaskRunner> encode_task_runner,
115 scoped_refptr<base::SingleThreadTaskRunner> network_task_runner, 116 scoped_refptr<base::SingleThreadTaskRunner> network_task_runner,
116 VideoFrameCapturer* capturer, 117 scoped_ptr<VideoFrameCapturer> capturer,
117 scoped_ptr<VideoEncoder> encoder, 118 scoped_ptr<VideoEncoder> encoder,
118 protocol::CursorShapeStub* cursor_stub, 119 protocol::CursorShapeStub* cursor_stub,
119 protocol::VideoStub* video_stub); 120 protocol::VideoStub* video_stub);
120 virtual ~VideoScheduler(); 121 virtual ~VideoScheduler();
121 122
122 // Capturer thread ---------------------------------------------------------- 123 // Capturer thread ----------------------------------------------------------
123 124
124 // Starts the capturer on the capture thread. 125 // Starts the capturer on the capture thread.
125 void StartOnCaptureThread(); 126 void StartOnCaptureThread();
126 127
127 // Stops scheduling frame captures on the capture thread, and posts 128 // Stops scheduling frame captures on the capture thread, and posts
128 // |done_task| to the network thread when done. 129 // StopOnEncodeThread() to the network thread when done.
129 void StopOnCaptureThread(const base::Closure& done_task); 130 void StopOnCaptureThread();
130 131
131 // Schedules the next call to CaptureNextFrame. 132 // Schedules the next call to CaptureNextFrame.
132 void ScheduleNextCapture(); 133 void ScheduleNextCapture();
133 134
134 // Starts the next frame capture, unless there are already too many pending. 135 // Starts the next frame capture, unless there are already too many pending.
135 void CaptureNextFrame(); 136 void CaptureNextFrame();
136 137
137 // Called when a frame capture has been encoded & sent to the client. 138 // Called when a frame capture has been encoded & sent to the client.
138 void FrameCaptureCompleted(); 139 void FrameCaptureCompleted();
139 140
140 // Network thread ----------------------------------------------------------- 141 // Network thread -----------------------------------------------------------
141 142
142 // Send |packet| to the client, unless we are in the process of stopping. 143 // Send |packet| to the client, unless we are in the process of stopping.
143 void SendVideoPacket(scoped_ptr<VideoPacket> packet); 144 void SendVideoPacket(scoped_ptr<VideoPacket> packet);
144 145
145 // Callback passed to |video_stub_| for the last packet in each frame, to 146 // Callback passed to |video_stub_| for the last packet in each frame, to
146 // rate-limit frame captures to network throughput. 147 // rate-limit frame captures to network throughput.
147 void VideoFrameSentCallback(); 148 void VideoFrameSentCallback();
148 149
149 // Send updated cursor shape to client. 150 // Send updated cursor shape to client.
150 void SendCursorShape(scoped_ptr<protocol::CursorShapeInfo> cursor_shape); 151 void SendCursorShape(scoped_ptr<protocol::CursorShapeInfo> cursor_shape);
151 152
153 void StopOnNetworkThread(scoped_ptr<VideoFrameCapturer> capturer);
154
152 // Encoder thread ----------------------------------------------------------- 155 // Encoder thread -----------------------------------------------------------
153 156
154 // Encode a frame, passing generated VideoPackets to SendVideoPacket(). 157 // Encode a frame, passing generated VideoPackets to SendVideoPacket().
155 void EncodeFrame(scoped_refptr<CaptureData> capture_data); 158 void EncodeFrame(scoped_refptr<CaptureData> capture_data);
156 159
157 void EncodedDataAvailableCallback(scoped_ptr<VideoPacket> packet); 160 void EncodedDataAvailableCallback(scoped_ptr<VideoPacket> packet);
158 161
159 // Used to synchronize capture and encode thread teardown, notifying the 162 // Used to synchronize capture and encode thread teardown, notifying the
160 // network thread when done. 163 // network thread when done.
161 void StopOnEncodeThread(const base::Closure& done_task); 164 void StopOnEncodeThread(scoped_ptr<VideoFrameCapturer> capturer);
162 165
163 // Task runners used by this class. 166 // Task runners used by this class.
164 scoped_refptr<base::SingleThreadTaskRunner> capture_task_runner_; 167 scoped_refptr<base::SingleThreadTaskRunner> capture_task_runner_;
165 scoped_refptr<base::SingleThreadTaskRunner> encode_task_runner_; 168 scoped_refptr<base::SingleThreadTaskRunner> encode_task_runner_;
166 scoped_refptr<base::SingleThreadTaskRunner> network_task_runner_; 169 scoped_refptr<base::SingleThreadTaskRunner> network_task_runner_;
167 170
168 // Used to capture frames. Always accessed on the capture thread. 171 // Used to capture frames. Always accessed on the capture thread.
169 VideoFrameCapturer* capturer_; 172 scoped_ptr<VideoFrameCapturer> capturer_;
170 173
171 // Used to encode captured frames. Always accessed on the encode thread. 174 // Used to encode captured frames. Always accessed on the encode thread.
172 scoped_ptr<VideoEncoder> encoder_; 175 scoped_ptr<VideoEncoder> encoder_;
173 176
174 // Interfaces through which video frames and cursor shapes are passed to the 177 // Interfaces through which video frames and cursor shapes are passed to the
175 // client. These members are always accessed on the network thread. 178 // client. These members are always accessed on the network thread.
176 protocol::CursorShapeStub* cursor_stub_; 179 protocol::CursorShapeStub* cursor_stub_;
177 protocol::VideoStub* video_stub_; 180 protocol::VideoStub* video_stub_;
178 181
179 // Timer used to schedule CaptureNextFrame(). 182 // Timer used to schedule CaptureNextFrame().
180 scoped_ptr<base::OneShotTimer<VideoScheduler> > capture_timer_; 183 scoped_ptr<base::OneShotTimer<VideoScheduler> > capture_timer_;
181 184
182 // Count the number of recordings (i.e. capture or encode) happening. 185 // Count the number of recordings (i.e. capture or encode) happening.
183 int pending_captures_; 186 int pending_captures_;
184 187
185 // True if the previous scheduled capture was skipped. 188 // True if the previous scheduled capture was skipped.
186 bool did_skip_frame_; 189 bool did_skip_frame_;
187 190
188 // True if capture of video frames is paused. 191 // True if capture of video frames is paused.
189 bool is_paused_; 192 bool is_paused_;
190 193
191 // This is a number updated by client to trace performance. 194 // This is a number updated by client to trace performance.
192 int64 sequence_number_; 195 int64 sequence_number_;
193 196
194 // An object to schedule capturing. 197 // An object to schedule capturing.
195 CaptureScheduler scheduler_; 198 CaptureScheduler scheduler_;
196 199
200 // Size of the most recent captured frame.
201 SkISize size_most_recent_;
202
197 DISALLOW_COPY_AND_ASSIGN(VideoScheduler); 203 DISALLOW_COPY_AND_ASSIGN(VideoScheduler);
198 }; 204 };
199 205
200 } // namespace remoting 206 } // namespace remoting
201 207
202 #endif // REMOTING_HOST_VIDEO_SCHEDULER_H_ 208 #endif // REMOTING_HOST_VIDEO_SCHEDULER_H_
OLDNEW
« no previous file with comments | « remoting/host/remoting_me2me_host.cc ('k') | remoting/host/video_scheduler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698