OLD | NEW |
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" | |
16 #include "remoting/codec/video_encoder.h" | 15 #include "remoting/codec/video_encoder.h" |
17 #include "remoting/host/capture_scheduler.h" | 16 #include "remoting/host/capture_scheduler.h" |
18 #include "remoting/proto/video.pb.h" | 17 #include "remoting/proto/video.pb.h" |
19 #include "third_party/skia/include/core/SkSize.h" | 18 #include "third_party/skia/include/core/SkSize.h" |
| 19 #include "third_party/webrtc/modules/desktop_capture/screen_capturer.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 ScreenCapturer; | 26 class ScreenCapturer; |
27 } // namespace media | 27 } // namespace media |
28 | 28 |
29 namespace remoting { | 29 namespace remoting { |
30 | 30 |
31 class CursorShapeInfo; | 31 class CursorShapeInfo; |
32 | 32 |
33 namespace protocol { | 33 namespace protocol { |
34 class CursorShapeInfo; | 34 class CursorShapeInfo; |
35 class CursorShapeStub; | 35 class CursorShapeStub; |
36 class VideoStub; | 36 class VideoStub; |
37 } // namespace protocol | 37 } // namespace protocol |
38 | 38 |
39 // Class responsible for scheduling frame captures from a media::ScreenCapturer, | 39 // Class responsible for scheduling frame captures from a |
40 // delivering them to a VideoEncoder to encode, and finally passing the encoded | 40 // webrtc::ScreenCapturer, delivering them to a VideoEncoder to encode, and |
41 // video packets to the specified VideoStub to send on the network. | 41 // finally passing the encoded video packets to the specified VideoStub to send |
| 42 // on the network. |
42 // | 43 // |
43 // THREADING | 44 // THREADING |
44 // | 45 // |
45 // This class is supplied TaskRunners to use for capture, encode and network | 46 // This class is supplied TaskRunners to use for capture, encode and network |
46 // operations. Capture, encode and network transmission tasks are interleaved | 47 // operations. Capture, encode and network transmission tasks are interleaved |
47 // as illustrated below: | 48 // as illustrated below: |
48 // | 49 // |
49 // | CAPTURE ENCODE NETWORK | 50 // | CAPTURE ENCODE NETWORK |
50 // | ............. | 51 // | ............. |
51 // | . Capture . | 52 // | . Capture . |
(...skipping 15 matching lines...) Expand all Loading... |
67 // | Time | 68 // | Time |
68 // v | 69 // v |
69 // | 70 // |
70 // VideoScheduler would ideally schedule captures so as to saturate the slowest | 71 // VideoScheduler would ideally schedule captures so as to saturate the slowest |
71 // of the capture, encode and network processes. However, it also needs to | 72 // of the capture, encode and network processes. However, it also needs to |
72 // rate-limit captures to avoid overloading the host system, either by consuming | 73 // rate-limit captures to avoid overloading the host system, either by consuming |
73 // too much CPU, or hogging the host's graphics subsystem. | 74 // too much CPU, or hogging the host's graphics subsystem. |
74 | 75 |
75 class VideoScheduler : public base::RefCountedThreadSafe<VideoScheduler>, | 76 class VideoScheduler : public base::RefCountedThreadSafe<VideoScheduler>, |
76 public webrtc::DesktopCapturer::Callback, | 77 public webrtc::DesktopCapturer::Callback, |
77 public media::ScreenCapturer::MouseShapeObserver { | 78 public webrtc::ScreenCapturer::MouseShapeObserver { |
78 public: | 79 public: |
79 // Creates a VideoScheduler running capture, encode and network tasks on the | 80 // Creates a VideoScheduler running capture, encode and network tasks on the |
80 // supplied TaskRunners. Video and cursor shape updates will be pumped to | 81 // supplied TaskRunners. Video and cursor shape updates will be pumped to |
81 // |video_stub| and |client_stub|, which must remain valid until Stop() is | 82 // |video_stub| and |client_stub|, which must remain valid until Stop() is |
82 // called. |capturer| is used to capture frames. | 83 // called. |capturer| is used to capture frames. |
83 VideoScheduler( | 84 VideoScheduler( |
84 scoped_refptr<base::SingleThreadTaskRunner> capture_task_runner, | 85 scoped_refptr<base::SingleThreadTaskRunner> capture_task_runner, |
85 scoped_refptr<base::SingleThreadTaskRunner> encode_task_runner, | 86 scoped_refptr<base::SingleThreadTaskRunner> encode_task_runner, |
86 scoped_refptr<base::SingleThreadTaskRunner> network_task_runner, | 87 scoped_refptr<base::SingleThreadTaskRunner> network_task_runner, |
87 scoped_ptr<media::ScreenCapturer> capturer, | 88 scoped_ptr<webrtc::ScreenCapturer> capturer, |
88 scoped_ptr<VideoEncoder> encoder, | 89 scoped_ptr<VideoEncoder> encoder, |
89 protocol::CursorShapeStub* cursor_stub, | 90 protocol::CursorShapeStub* cursor_stub, |
90 protocol::VideoStub* video_stub); | 91 protocol::VideoStub* video_stub); |
91 | 92 |
92 // webrtc::DesktopCapturer::Callback implementation. | 93 // webrtc::DesktopCapturer::Callback implementation. |
93 virtual webrtc::SharedMemory* CreateSharedMemory(size_t size) OVERRIDE; | 94 virtual webrtc::SharedMemory* CreateSharedMemory(size_t size) OVERRIDE; |
94 virtual void OnCaptureCompleted(webrtc::DesktopFrame* frame) OVERRIDE; | 95 virtual void OnCaptureCompleted(webrtc::DesktopFrame* frame) OVERRIDE; |
95 | 96 |
96 // media::ScreenCapturer::MouseShapeObserver implementation. | 97 // webrtc::ScreenCapturer::MouseShapeObserver implementation. |
97 virtual void OnCursorShapeChanged( | 98 virtual void OnCursorShapeChanged( |
98 scoped_ptr<media::MouseCursorShape> cursor_shape) OVERRIDE; | 99 webrtc::MouseCursorShape* cursor_shape) OVERRIDE; |
99 | 100 |
100 // Starts scheduling frame captures. | 101 // Starts scheduling frame captures. |
101 void Start(); | 102 void Start(); |
102 | 103 |
103 // Stop scheduling frame captures. This object cannot be re-used once | 104 // Stop scheduling frame captures. This object cannot be re-used once |
104 // it has been stopped. | 105 // it has been stopped. |
105 void Stop(); | 106 void Stop(); |
106 | 107 |
107 // Pauses or resumes scheduling of frame captures. Pausing/resuming captures | 108 // Pauses or resumes scheduling of frame captures. Pausing/resuming captures |
108 // only affects capture scheduling and does not stop/start the capturer. | 109 // only affects capture scheduling and does not stop/start the capturer. |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
153 | 154 |
154 void EncodedDataAvailableCallback(int sequence_number, | 155 void EncodedDataAvailableCallback(int sequence_number, |
155 scoped_ptr<VideoPacket> packet); | 156 scoped_ptr<VideoPacket> packet); |
156 | 157 |
157 // Task runners used by this class. | 158 // Task runners used by this class. |
158 scoped_refptr<base::SingleThreadTaskRunner> capture_task_runner_; | 159 scoped_refptr<base::SingleThreadTaskRunner> capture_task_runner_; |
159 scoped_refptr<base::SingleThreadTaskRunner> encode_task_runner_; | 160 scoped_refptr<base::SingleThreadTaskRunner> encode_task_runner_; |
160 scoped_refptr<base::SingleThreadTaskRunner> network_task_runner_; | 161 scoped_refptr<base::SingleThreadTaskRunner> network_task_runner_; |
161 | 162 |
162 // Used to capture frames. Always accessed on the capture thread. | 163 // Used to capture frames. Always accessed on the capture thread. |
163 scoped_ptr<media::ScreenCapturer> capturer_; | 164 scoped_ptr<webrtc::ScreenCapturer> capturer_; |
164 | 165 |
165 // Used to encode captured frames. Always accessed on the encode thread. | 166 // Used to encode captured frames. Always accessed on the encode thread. |
166 scoped_ptr<VideoEncoder> encoder_; | 167 scoped_ptr<VideoEncoder> encoder_; |
167 | 168 |
168 // Interfaces through which video frames and cursor shapes are passed to the | 169 // Interfaces through which video frames and cursor shapes are passed to the |
169 // client. These members are always accessed on the network thread. | 170 // client. These members are always accessed on the network thread. |
170 protocol::CursorShapeStub* cursor_stub_; | 171 protocol::CursorShapeStub* cursor_stub_; |
171 protocol::VideoStub* video_stub_; | 172 protocol::VideoStub* video_stub_; |
172 | 173 |
173 // Timer used to schedule CaptureNextFrame(). | 174 // Timer used to schedule CaptureNextFrame(). |
(...skipping 18 matching lines...) Expand all Loading... |
192 | 193 |
193 // An object to schedule capturing. | 194 // An object to schedule capturing. |
194 CaptureScheduler scheduler_; | 195 CaptureScheduler scheduler_; |
195 | 196 |
196 DISALLOW_COPY_AND_ASSIGN(VideoScheduler); | 197 DISALLOW_COPY_AND_ASSIGN(VideoScheduler); |
197 }; | 198 }; |
198 | 199 |
199 } // namespace remoting | 200 } // namespace remoting |
200 | 201 |
201 #endif // REMOTING_HOST_VIDEO_SCHEDULER_H_ | 202 #endif // REMOTING_HOST_VIDEO_SCHEDULER_H_ |
OLD | NEW |