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

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

Issue 13983010: Use webrtc::DesktopCapturer for screen capturer implementation. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 7 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/screen_resolution_unittest.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/memory/ref_counted.h" 11 #include "base/memory/ref_counted.h"
12 #include "base/memory/scoped_ptr.h" 12 #include "base/memory/scoped_ptr.h"
13 #include "base/time.h" 13 #include "base/time.h"
14 #include "base/timer.h" 14 #include "base/timer.h"
15 #include "media/video/capture/screen/screen_capturer.h" 15 #include "media/video/capture/screen/screen_capturer.h"
16 #include "remoting/codec/video_encoder.h" 16 #include "remoting/codec/video_encoder.h"
17 #include "remoting/host/capture_scheduler.h" 17 #include "remoting/host/capture_scheduler.h"
18 #include "remoting/proto/video.pb.h" 18 #include "remoting/proto/video.pb.h"
19 #include "third_party/skia/include/core/SkSize.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 media { 25 namespace media {
26 class ScreenCaptureData;
27 class ScreenCapturer; 26 class ScreenCapturer;
28 } // namespace media 27 } // namespace media
29 28
30 namespace remoting { 29 namespace remoting {
31 30
32 class CursorShapeInfo; 31 class CursorShapeInfo;
33 32
34 namespace protocol { 33 namespace protocol {
35 class CursorShapeInfo; 34 class CursorShapeInfo;
36 class CursorShapeStub; 35 class CursorShapeStub;
(...skipping 30 matching lines...) Expand all
67 // | ............ 66 // | ............
68 // | Time 67 // | Time
69 // v 68 // v
70 // 69 //
71 // VideoScheduler would ideally schedule captures so as to saturate the slowest 70 // VideoScheduler would ideally schedule captures so as to saturate the slowest
72 // of the capture, encode and network processes. However, it also needs to 71 // of the capture, encode and network processes. However, it also needs to
73 // rate-limit captures to avoid overloading the host system, either by consuming 72 // rate-limit captures to avoid overloading the host system, either by consuming
74 // too much CPU, or hogging the host's graphics subsystem. 73 // too much CPU, or hogging the host's graphics subsystem.
75 74
76 class VideoScheduler : public base::RefCountedThreadSafe<VideoScheduler>, 75 class VideoScheduler : public base::RefCountedThreadSafe<VideoScheduler>,
77 public media::ScreenCapturer::Delegate { 76 public webrtc::DesktopCapturer::Callback,
77 public media::ScreenCapturer::MouseShapeObserver {
78 public: 78 public:
79 // Creates a VideoScheduler running capture, encode and network tasks on the 79 // Creates a VideoScheduler running capture, encode and network tasks on the
80 // supplied TaskRunners. Video and cursor shape updates will be pumped to 80 // supplied TaskRunners. Video and cursor shape updates will be pumped to
81 // |video_stub| and |client_stub|, which must remain valid until Stop() is 81 // |video_stub| and |client_stub|, which must remain valid until Stop() is
82 // called. |capturer| is used to capture frames. 82 // called. |capturer| is used to capture frames.
83 VideoScheduler( 83 VideoScheduler(
84 scoped_refptr<base::SingleThreadTaskRunner> capture_task_runner, 84 scoped_refptr<base::SingleThreadTaskRunner> capture_task_runner,
85 scoped_refptr<base::SingleThreadTaskRunner> encode_task_runner, 85 scoped_refptr<base::SingleThreadTaskRunner> encode_task_runner,
86 scoped_refptr<base::SingleThreadTaskRunner> network_task_runner, 86 scoped_refptr<base::SingleThreadTaskRunner> network_task_runner,
87 scoped_ptr<media::ScreenCapturer> capturer, 87 scoped_ptr<media::ScreenCapturer> capturer,
88 scoped_ptr<VideoEncoder> encoder, 88 scoped_ptr<VideoEncoder> encoder,
89 protocol::CursorShapeStub* cursor_stub, 89 protocol::CursorShapeStub* cursor_stub,
90 protocol::VideoStub* video_stub); 90 protocol::VideoStub* video_stub);
91 91
92 // media::ScreenCapturer::Delegate implementation. 92 // webrtc::DesktopCapturer::Callback implementation.
93 virtual void OnCaptureCompleted( 93 virtual webrtc::SharedMemory* CreateSharedMemory(size_t size) OVERRIDE;
94 scoped_refptr<media::ScreenCaptureData> capture_data) OVERRIDE; 94 virtual void OnCaptureCompleted(webrtc::DesktopFrame* frame) OVERRIDE;
95
96 // media::ScreenCapturer::MouseShapeObserver implementation.
95 virtual void OnCursorShapeChanged( 97 virtual void OnCursorShapeChanged(
96 scoped_ptr<media::MouseCursorShape> cursor_shape) OVERRIDE; 98 scoped_ptr<media::MouseCursorShape> cursor_shape) OVERRIDE;
97 99
98 // Starts scheduling frame captures. 100 // Starts scheduling frame captures.
99 void Start(); 101 void Start();
100 102
101 // Stop scheduling frame captures. This object cannot be re-used once 103 // Stop scheduling frame captures. This object cannot be re-used once
102 // it has been stopped. 104 // it has been stopped.
103 void Stop(); 105 void Stop();
104 106
105 // Pauses or resumes scheduling of frame captures. Pausing/resuming captures 107 // Pauses or resumes scheduling of frame captures. Pausing/resuming captures
106 // only affects capture scheduling and does not stop/start the capturer. 108 // only affects capture scheduling and does not stop/start the capturer.
107 void Pause(bool pause); 109 void Pause(bool pause);
108 110
109 // Updates the sequence number embedded in VideoPackets. 111 // Updates the sequence number embedded in VideoPackets.
110 // Sequence numbers are used for performance measurements. 112 // Sequence numbers are used for performance measurements.
111 void UpdateSequenceNumber(int64 sequence_number); 113 void UpdateSequenceNumber(int64 sequence_number);
112 114
113 private: 115 private:
114 friend class base::RefCountedThreadSafe<VideoScheduler>; 116 friend class base::RefCountedThreadSafe<VideoScheduler>;
115 virtual ~VideoScheduler(); 117 virtual ~VideoScheduler();
116 118
117 // Capturer thread ---------------------------------------------------------- 119 // Capturer thread ----------------------------------------------------------
118 120
119 // Starts the capturer on the capture thread. 121 // Starts the capturer on the capture thread.
120 void StartOnCaptureThread(); 122 void StartOnCaptureThread();
121 123
122 // Stops scheduling frame captures on the capture thread, and posts 124 // Stops scheduling frame captures on the capture thread.
123 // StopOnEncodeThread() to the network thread when done.
124 void StopOnCaptureThread(); 125 void StopOnCaptureThread();
125 126
126 // Schedules the next call to CaptureNextFrame. 127 // Schedules the next call to CaptureNextFrame.
127 void ScheduleNextCapture(); 128 void ScheduleNextCapture();
128 129
129 // Starts the next frame capture, unless there are already too many pending. 130 // Starts the next frame capture, unless there are already too many pending.
130 void CaptureNextFrame(); 131 void CaptureNextFrame();
131 132
132 // Called when a frame capture has been encoded & sent to the client. 133 // Called when a frame capture has been encoded & sent to the client.
133 void FrameCaptureCompleted(); 134 void FrameCaptureCompleted();
134 135
135 // Network thread ----------------------------------------------------------- 136 // Network thread -----------------------------------------------------------
136 137
137 // Send |packet| to the client, unless we are in the process of stopping. 138 // Send |packet| to the client, unless we are in the process of stopping.
138 void SendVideoPacket(scoped_ptr<VideoPacket> packet); 139 void SendVideoPacket(scoped_ptr<VideoPacket> packet);
139 140
140 // Callback passed to |video_stub_| for the last packet in each frame, to 141 // Callback passed to |video_stub_| for the last packet in each frame, to
141 // rate-limit frame captures to network throughput. 142 // rate-limit frame captures to network throughput.
142 void VideoFrameSentCallback(); 143 void VideoFrameSentCallback();
143 144
144 // Send updated cursor shape to client. 145 // Send updated cursor shape to client.
145 void SendCursorShape(scoped_ptr<protocol::CursorShapeInfo> cursor_shape); 146 void SendCursorShape(scoped_ptr<protocol::CursorShapeInfo> cursor_shape);
146 147
147 // Encoder thread ----------------------------------------------------------- 148 // Encoder thread -----------------------------------------------------------
148 149
149 // Encode a frame, passing generated VideoPackets to SendVideoPacket(). 150 // Encode a frame, passing generated VideoPackets to SendVideoPacket().
150 void EncodeFrame(scoped_refptr<media::ScreenCaptureData> capture_data); 151 void EncodeFrame(scoped_ptr<webrtc::DesktopFrame> frame,
152 int sequence_number);
151 153
152 void EncodedDataAvailableCallback(scoped_ptr<VideoPacket> packet); 154 void EncodedDataAvailableCallback(int sequence_number,
153 155 scoped_ptr<VideoPacket> packet);
154 // Used to synchronize capture and encode thread teardown, notifying the
155 // network thread when done.
156 void StopOnEncodeThread(scoped_ptr<media::ScreenCapturer> capturer);
157 156
158 // Task runners used by this class. 157 // Task runners used by this class.
159 scoped_refptr<base::SingleThreadTaskRunner> capture_task_runner_; 158 scoped_refptr<base::SingleThreadTaskRunner> capture_task_runner_;
160 scoped_refptr<base::SingleThreadTaskRunner> encode_task_runner_; 159 scoped_refptr<base::SingleThreadTaskRunner> encode_task_runner_;
161 scoped_refptr<base::SingleThreadTaskRunner> network_task_runner_; 160 scoped_refptr<base::SingleThreadTaskRunner> network_task_runner_;
162 161
163 // Used to capture frames. Always accessed on the capture thread. 162 // Used to capture frames. Always accessed on the capture thread.
164 scoped_ptr<media::ScreenCapturer> capturer_; 163 scoped_ptr<media::ScreenCapturer> capturer_;
165 164
166 // Used to encode captured frames. Always accessed on the encode thread. 165 // Used to encode captured frames. Always accessed on the encode thread.
167 scoped_ptr<VideoEncoder> encoder_; 166 scoped_ptr<VideoEncoder> encoder_;
168 167
169 // Interfaces through which video frames and cursor shapes are passed to the 168 // Interfaces through which video frames and cursor shapes are passed to the
170 // client. These members are always accessed on the network thread. 169 // client. These members are always accessed on the network thread.
171 protocol::CursorShapeStub* cursor_stub_; 170 protocol::CursorShapeStub* cursor_stub_;
172 protocol::VideoStub* video_stub_; 171 protocol::VideoStub* video_stub_;
173 172
174 // Timer used to schedule CaptureNextFrame(). 173 // Timer used to schedule CaptureNextFrame().
175 scoped_ptr<base::OneShotTimer<VideoScheduler> > capture_timer_; 174 scoped_ptr<base::OneShotTimer<VideoScheduler> > capture_timer_;
176 175
177 // Count the number of recordings (i.e. capture or encode) happening. 176 // The number of frames being processed, i.e. frames that we are currently
178 int pending_captures_; 177 // capturing, encoding or sending. The value is capped at 2 to minimize
178 // latency.
179 int pending_frames_;
180
181 // Set when the capturer is capturing a frame.
182 bool capture_pending_;
179 183
180 // True if the previous scheduled capture was skipped. 184 // True if the previous scheduled capture was skipped.
181 bool did_skip_frame_; 185 bool did_skip_frame_;
182 186
183 // True if capture of video frames is paused. 187 // True if capture of video frames is paused.
184 bool is_paused_; 188 bool is_paused_;
185 189
186 // This is a number updated by client to trace performance. 190 // This is a number updated by client to trace performance.
187 int64 sequence_number_; 191 int64 sequence_number_;
188 192
189 // An object to schedule capturing. 193 // An object to schedule capturing.
190 CaptureScheduler scheduler_; 194 CaptureScheduler scheduler_;
191 195
192 DISALLOW_COPY_AND_ASSIGN(VideoScheduler); 196 DISALLOW_COPY_AND_ASSIGN(VideoScheduler);
193 }; 197 };
194 198
195 } // namespace remoting 199 } // namespace remoting
196 200
197 #endif // REMOTING_HOST_VIDEO_SCHEDULER_H_ 201 #endif // REMOTING_HOST_VIDEO_SCHEDULER_H_
OLDNEW
« no previous file with comments | « remoting/host/screen_resolution_unittest.cc ('k') | remoting/host/video_scheduler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698