| 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/callback.h" | 11 #include "base/callback.h" |
| 12 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
| 13 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
| 14 #include "base/time.h" | 14 #include "base/time.h" |
| 15 #include "base/timer.h" | 15 #include "base/timer.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/host/video_frame_capturer.h" |
| 18 #include "remoting/proto/video.pb.h" | 19 #include "remoting/proto/video.pb.h" |
| 19 | 20 |
| 20 namespace base { | 21 namespace base { |
| 21 class SingleThreadTaskRunner; | 22 class SingleThreadTaskRunner; |
| 22 } // namespace base | 23 } // namespace base |
| 23 | 24 |
| 24 namespace remoting { | 25 namespace remoting { |
| 25 | 26 |
| 26 class CaptureData; | 27 class CaptureData; |
| 27 class VideoFrameCapturer; | 28 class VideoFrameCapturer; |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 61 // | . . | 62 // | . . |
| 62 // | ............ | 63 // | ............ |
| 63 // | Time | 64 // | Time |
| 64 // v | 65 // v |
| 65 // | 66 // |
| 66 // VideoScheduler would ideally schedule captures so as to saturate the slowest | 67 // VideoScheduler would ideally schedule captures so as to saturate the slowest |
| 67 // of the capture, encode and network processes. However, it also needs to | 68 // of the capture, encode and network processes. However, it also needs to |
| 68 // rate-limit captures to avoid overloading the host system, either by consuming | 69 // rate-limit captures to avoid overloading the host system, either by consuming |
| 69 // too much CPU, or hogging the host's graphics subsystem. | 70 // too much CPU, or hogging the host's graphics subsystem. |
| 70 | 71 |
| 71 class VideoScheduler : public base::RefCountedThreadSafe<VideoScheduler> { | 72 class VideoScheduler : public base::RefCountedThreadSafe<VideoScheduler>, |
| 73 public VideoFrameCapturer::Delegate { |
| 72 public: | 74 public: |
| 73 // Creates a VideoScheduler running capture, encode and network tasks on the | 75 // Creates a VideoScheduler running capture, encode and network tasks on the |
| 74 // supplied TaskRunners. Video and cursor shape updates will be pumped to | 76 // supplied TaskRunners. Video and cursor shape updates will be pumped to |
| 75 // |video_stub| and |client_stub|, which must remain valid until Stop() is | 77 // |video_stub| and |client_stub|, which must remain valid until Stop() is |
| 76 // called. |capturer| is used to capture frames and must remain valid until | 78 // called. |capturer| is used to capture frames and must remain valid until |
| 77 // the |done_task| supplied to Stop() is executed. | 79 // the |done_task| supplied to Stop() is executed. |
| 78 VideoScheduler( | 80 VideoScheduler( |
| 79 scoped_refptr<base::SingleThreadTaskRunner> capture_task_runner, | 81 scoped_refptr<base::SingleThreadTaskRunner> capture_task_runner, |
| 80 scoped_refptr<base::SingleThreadTaskRunner> encode_task_runner, | 82 scoped_refptr<base::SingleThreadTaskRunner> encode_task_runner, |
| 81 scoped_refptr<base::SingleThreadTaskRunner> network_task_runner, | 83 scoped_refptr<base::SingleThreadTaskRunner> network_task_runner, |
| 82 VideoFrameCapturer* capturer, | 84 VideoFrameCapturer* capturer, |
| 83 scoped_ptr<VideoEncoder> encoder, | 85 scoped_ptr<VideoEncoder> encoder, |
| 84 protocol::ClientStub* client_stub, | 86 protocol::ClientStub* client_stub, |
| 85 protocol::VideoStub* video_stub); | 87 protocol::VideoStub* video_stub); |
| 86 | 88 |
| 89 // VideoFrameCapturer::Delegate implementation |
| 90 virtual void OnCaptureCompleted( |
| 91 scoped_refptr<CaptureData> capture_data) OVERRIDE; |
| 92 virtual void OnCursorShapeChanged( |
| 93 scoped_ptr<protocol::CursorShapeInfo> cursor_shape) OVERRIDE; |
| 94 |
| 87 // Stop scheduling frame captures. |done_task| is executed on the network | 95 // Stop scheduling frame captures. |done_task| is executed on the network |
| 88 // thread when capturing has stopped. This object cannot be re-used once | 96 // thread when capturing has stopped. This object cannot be re-used once |
| 89 // it has been stopped. | 97 // it has been stopped. |
| 90 void Stop(const base::Closure& done_task); | 98 void Stop(const base::Closure& done_task); |
| 91 | 99 |
| 92 // Pauses or resumes scheduling of frame captures. Pausing/resuming captures | 100 // Pauses or resumes scheduling of frame captures. Pausing/resuming captures |
| 93 // only affects capture scheduling and does not stop/start the capturer. | 101 // only affects capture scheduling and does not stop/start the capturer. |
| 94 void Pause(bool pause); | 102 void Pause(bool pause); |
| 95 | 103 |
| 96 // Updates the sequence number embedded in VideoPackets. | 104 // Updates the sequence number embedded in VideoPackets. |
| (...skipping 12 matching lines...) Expand all Loading... |
| 109 // Stops scheduling frame captures on the capture thread, and posts | 117 // Stops scheduling frame captures on the capture thread, and posts |
| 110 // |done_task| to the network thread when done. | 118 // |done_task| to the network thread when done. |
| 111 void StopOnCaptureThread(const base::Closure& done_task); | 119 void StopOnCaptureThread(const base::Closure& done_task); |
| 112 | 120 |
| 113 // Schedules the next call to CaptureNextFrame. | 121 // Schedules the next call to CaptureNextFrame. |
| 114 void ScheduleNextCapture(); | 122 void ScheduleNextCapture(); |
| 115 | 123 |
| 116 // Starts the next frame capture, unless there are already too many pending. | 124 // Starts the next frame capture, unless there are already too many pending. |
| 117 void CaptureNextFrame(); | 125 void CaptureNextFrame(); |
| 118 | 126 |
| 119 // Called when a frame capture completes. | |
| 120 void CaptureDoneCallback(scoped_refptr<CaptureData> capture_data); | |
| 121 | |
| 122 // Called when the cursor shape changes. | |
| 123 void CursorShapeChangedCallback( | |
| 124 scoped_ptr<protocol::CursorShapeInfo> cursor_data); | |
| 125 | |
| 126 // Called when a frame capture has been encoded & sent to the client. | 127 // Called when a frame capture has been encoded & sent to the client. |
| 127 void FrameCaptureCompleted(); | 128 void FrameCaptureCompleted(); |
| 128 | 129 |
| 129 // Network thread ----------------------------------------------------------- | 130 // Network thread ----------------------------------------------------------- |
| 130 | 131 |
| 131 // Send |packet| to the client, unless we are in the process of stopping. | 132 // Send |packet| to the client, unless we are in the process of stopping. |
| 132 void SendVideoPacket(scoped_ptr<VideoPacket> packet); | 133 void SendVideoPacket(scoped_ptr<VideoPacket> packet); |
| 133 | 134 |
| 134 // Callback passed to |video_stub_| for the last packet in each frame, to | 135 // Callback passed to |video_stub_| for the last packet in each frame, to |
| 135 // rate-limit frame captures to network throughput. | 136 // rate-limit frame captures to network throughput. |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 184 | 185 |
| 185 // An object to schedule capturing. | 186 // An object to schedule capturing. |
| 186 CaptureScheduler scheduler_; | 187 CaptureScheduler scheduler_; |
| 187 | 188 |
| 188 DISALLOW_COPY_AND_ASSIGN(VideoScheduler); | 189 DISALLOW_COPY_AND_ASSIGN(VideoScheduler); |
| 189 }; | 190 }; |
| 190 | 191 |
| 191 } // namespace remoting | 192 } // namespace remoting |
| 192 | 193 |
| 193 #endif // REMOTING_HOST_SCREEN_RECORDER_H_ | 194 #endif // REMOTING_HOST_SCREEN_RECORDER_H_ |
| OLD | NEW |