| 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" | 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 Loading... |
| 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 static scoped_refptr<VideoScheduler> Create( | 83 static scoped_refptr<VideoScheduler> Create( |
| 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 // Stop scheduling frame captures. This object cannot be re-used once | 100 // Stop scheduling frame captures. This object cannot be re-used once |
| 99 // it has been stopped. | 101 // it has been stopped. |
| 100 void Stop(); | 102 void Stop(); |
| 101 | 103 |
| 102 // Pauses or resumes scheduling of frame captures. Pausing/resuming captures | 104 // Pauses or resumes scheduling of frame captures. Pausing/resuming captures |
| 103 // only affects capture scheduling and does not stop/start the capturer. | 105 // only affects capture scheduling and does not stop/start the capturer. |
| 104 void Pause(bool pause); | 106 void Pause(bool pause); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 118 scoped_ptr<VideoEncoder> encoder, | 120 scoped_ptr<VideoEncoder> encoder, |
| 119 protocol::CursorShapeStub* cursor_stub, | 121 protocol::CursorShapeStub* cursor_stub, |
| 120 protocol::VideoStub* video_stub); | 122 protocol::VideoStub* video_stub); |
| 121 virtual ~VideoScheduler(); | 123 virtual ~VideoScheduler(); |
| 122 | 124 |
| 123 // Capturer thread ---------------------------------------------------------- | 125 // Capturer thread ---------------------------------------------------------- |
| 124 | 126 |
| 125 // Starts the capturer on the capture thread. | 127 // Starts the capturer on the capture thread. |
| 126 void StartOnCaptureThread(); | 128 void StartOnCaptureThread(); |
| 127 | 129 |
| 128 // Stops scheduling frame captures on the capture thread, and posts | 130 // Stops scheduling frame captures on the capture thread. |
| 129 // StopOnEncodeThread() to the network thread when done. | |
| 130 void StopOnCaptureThread(); | 131 void StopOnCaptureThread(); |
| 131 | 132 |
| 132 // Schedules the next call to CaptureNextFrame. | 133 // Schedules the next call to CaptureNextFrame. |
| 133 void ScheduleNextCapture(); | 134 void ScheduleNextCapture(); |
| 134 | 135 |
| 135 // Starts the next frame capture, unless there are already too many pending. | 136 // Starts the next frame capture, unless there are already too many pending. |
| 136 void CaptureNextFrame(); | 137 void CaptureNextFrame(); |
| 137 | 138 |
| 138 // Called when a frame capture has been encoded & sent to the client. | 139 // Called when a frame capture has been encoded & sent to the client. |
| 139 void FrameCaptureCompleted(); | 140 void FrameCaptureCompleted(); |
| 140 | 141 |
| 141 // Network thread ----------------------------------------------------------- | 142 // Network thread ----------------------------------------------------------- |
| 142 | 143 |
| 143 // Send |packet| to the client, unless we are in the process of stopping. | 144 // Send |packet| to the client, unless we are in the process of stopping. |
| 144 void SendVideoPacket(scoped_ptr<VideoPacket> packet); | 145 void SendVideoPacket(scoped_ptr<VideoPacket> packet); |
| 145 | 146 |
| 146 // Callback passed to |video_stub_| for the last packet in each frame, to | 147 // Callback passed to |video_stub_| for the last packet in each frame, to |
| 147 // rate-limit frame captures to network throughput. | 148 // rate-limit frame captures to network throughput. |
| 148 void VideoFrameSentCallback(); | 149 void VideoFrameSentCallback(); |
| 149 | 150 |
| 150 // Send updated cursor shape to client. | 151 // Send updated cursor shape to client. |
| 151 void SendCursorShape(scoped_ptr<protocol::CursorShapeInfo> cursor_shape); | 152 void SendCursorShape(scoped_ptr<protocol::CursorShapeInfo> cursor_shape); |
| 152 | 153 |
| 153 // Encoder thread ----------------------------------------------------------- | 154 // Encoder thread ----------------------------------------------------------- |
| 154 | 155 |
| 155 // Encode a frame, passing generated VideoPackets to SendVideoPacket(). | 156 // Encode a frame, passing generated VideoPackets to SendVideoPacket(). |
| 156 void EncodeFrame(scoped_refptr<media::ScreenCaptureData> capture_data); | 157 void EncodeFrame(scoped_ptr<webrtc::DesktopFrame> frame, |
| 158 int sequence_number); |
| 157 | 159 |
| 158 void EncodedDataAvailableCallback(scoped_ptr<VideoPacket> packet); | 160 void EncodedDataAvailableCallback(int sequence_number, |
| 159 | 161 scoped_ptr<VideoPacket> packet); |
| 160 // Used to synchronize capture and encode thread teardown, notifying the | |
| 161 // network thread when done. | |
| 162 void StopOnEncodeThread(scoped_ptr<media::ScreenCapturer> capturer); | |
| 163 | 162 |
| 164 // Task runners used by this class. | 163 // Task runners used by this class. |
| 165 scoped_refptr<base::SingleThreadTaskRunner> capture_task_runner_; | 164 scoped_refptr<base::SingleThreadTaskRunner> capture_task_runner_; |
| 166 scoped_refptr<base::SingleThreadTaskRunner> encode_task_runner_; | 165 scoped_refptr<base::SingleThreadTaskRunner> encode_task_runner_; |
| 167 scoped_refptr<base::SingleThreadTaskRunner> network_task_runner_; | 166 scoped_refptr<base::SingleThreadTaskRunner> network_task_runner_; |
| 168 | 167 |
| 169 // Used to capture frames. Always accessed on the capture thread. | 168 // Used to capture frames. Always accessed on the capture thread. |
| 170 scoped_ptr<media::ScreenCapturer> capturer_; | 169 scoped_ptr<media::ScreenCapturer> capturer_; |
| 171 | 170 |
| 172 // Used to encode captured frames. Always accessed on the encode thread. | 171 // Used to encode captured frames. Always accessed on the encode thread. |
| (...skipping 21 matching lines...) Expand all Loading... |
| 194 | 193 |
| 195 // An object to schedule capturing. | 194 // An object to schedule capturing. |
| 196 CaptureScheduler scheduler_; | 195 CaptureScheduler scheduler_; |
| 197 | 196 |
| 198 DISALLOW_COPY_AND_ASSIGN(VideoScheduler); | 197 DISALLOW_COPY_AND_ASSIGN(VideoScheduler); |
| 199 }; | 198 }; |
| 200 | 199 |
| 201 } // namespace remoting | 200 } // namespace remoting |
| 202 | 201 |
| 203 #endif // REMOTING_HOST_VIDEO_SCHEDULER_H_ | 202 #endif // REMOTING_HOST_VIDEO_SCHEDULER_H_ |
| OLD | NEW |