OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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_PROTOCOL_VIDEO_FRAME_PUMP_H_ | 5 #ifndef REMOTING_PROTOCOL_VIDEO_FRAME_PUMP_H_ |
6 #define REMOTING_PROTOCOL_VIDEO_FRAME_PUMP_H_ | 6 #define REMOTING_PROTOCOL_VIDEO_FRAME_PUMP_H_ |
7 | 7 |
8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
9 #include "base/memory/ref_counted.h" | |
10 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
11 #include "base/memory/scoped_vector.h" | 10 #include "base/memory/scoped_vector.h" |
12 #include "base/threading/thread_checker.h" | 11 #include "base/threading/thread_checker.h" |
13 #include "base/time/time.h" | 12 #include "base/time/time.h" |
14 #include "base/timer/timer.h" | 13 #include "base/timer/timer.h" |
15 #include "remoting/codec/video_encoder.h" | 14 #include "remoting/codec/video_encoder.h" |
16 #include "remoting/proto/video.pb.h" | 15 #include "remoting/proto/video.pb.h" |
17 #include "remoting/protocol/capture_scheduler.h" | 16 #include "remoting/protocol/capture_scheduler.h" |
| 17 #include "remoting/protocol/video_stream.h" |
18 #include "third_party/webrtc/modules/desktop_capture/desktop_capturer.h" | 18 #include "third_party/webrtc/modules/desktop_capture/desktop_capturer.h" |
19 | 19 |
20 namespace base { | 20 namespace base { |
21 class SingleThreadTaskRunner; | 21 class SingleThreadTaskRunner; |
22 } // namespace base | 22 } // namespace base |
23 | 23 |
24 namespace remoting { | 24 namespace remoting { |
25 namespace protocol { | 25 namespace protocol { |
26 | 26 |
27 class VideoFeedbackStub; | 27 class VideoFeedbackStub; |
(...skipping 28 matching lines...) Expand all Loading... |
56 // | . . | 56 // | . . |
57 // | . . | 57 // | . . |
58 // | ............ | 58 // | ............ |
59 // | Time | 59 // | Time |
60 // v | 60 // v |
61 // | 61 // |
62 // VideoFramePump would ideally schedule captures so as to saturate the slowest | 62 // VideoFramePump would ideally schedule captures so as to saturate the slowest |
63 // of the capture, encode and network processes. However, it also needs to | 63 // of the capture, encode and network processes. However, it also needs to |
64 // rate-limit captures to avoid overloading the host system, either by consuming | 64 // rate-limit captures to avoid overloading the host system, either by consuming |
65 // too much CPU, or hogging the host's graphics subsystem. | 65 // too much CPU, or hogging the host's graphics subsystem. |
66 class VideoFramePump : public webrtc::DesktopCapturer::Callback { | 66 class VideoFramePump : public VideoStream, |
| 67 public webrtc::DesktopCapturer::Callback { |
67 public: | 68 public: |
68 // Enables timestamps for generated frames. Used for testing. | 69 // Enables timestamps for generated frames. Used for testing. |
69 static void EnableTimestampsForTests(); | 70 static void EnableTimestampsForTests(); |
70 | 71 |
71 // Creates a VideoFramePump running capture, encode and network tasks on the | 72 // Creates a VideoFramePump running capture, encode and network tasks on the |
72 // supplied TaskRunners. Video will be pumped to |video_stub|, which must | 73 // supplied TaskRunners. Video will be pumped to |video_stub|, which must |
73 // outlive the pump.. | 74 // outlive the pump.. |
74 VideoFramePump( | 75 VideoFramePump( |
75 scoped_refptr<base::SingleThreadTaskRunner> encode_task_runner, | 76 scoped_refptr<base::SingleThreadTaskRunner> encode_task_runner, |
76 scoped_ptr<webrtc::DesktopCapturer> capturer, | 77 scoped_ptr<webrtc::DesktopCapturer> capturer, |
77 scoped_ptr<VideoEncoder> encoder, | 78 scoped_ptr<VideoEncoder> encoder, |
78 protocol::VideoStub* video_stub); | 79 protocol::VideoStub* video_stub); |
79 ~VideoFramePump() override; | 80 ~VideoFramePump() override; |
80 | 81 |
81 // Pauses or resumes scheduling of frame captures. Pausing/resuming captures | 82 // VideoStream interface. |
82 // only affects capture scheduling and does not stop/start the capturer. | 83 void Pause(bool pause) override; |
83 void Pause(bool pause); | 84 void OnInputEventReceived(int64_t event_timestamp) override; |
84 | 85 void SetLosslessEncode(bool want_lossless) override; |
85 // Called whenever input event is received. | 86 void SetLosslessColor(bool want_lossless) override; |
86 void OnInputEventReceived(int64_t event_timestamp); | 87 void SetSizeCallback(const SizeCallback& size_callback) override; |
87 | |
88 // Sets whether the video encoder should be requested to encode losslessly, | |
89 // or to use a lossless color space (typically requiring higher bandwidth). | |
90 void SetLosslessEncode(bool want_lossless); | |
91 void SetLosslessColor(bool want_lossless); | |
92 | 88 |
93 protocol::VideoFeedbackStub* video_feedback_stub() { | 89 protocol::VideoFeedbackStub* video_feedback_stub() { |
94 return &capture_scheduler_; | 90 return &capture_scheduler_; |
95 } | 91 } |
96 | 92 |
97 private: | 93 private: |
98 struct FrameTimestamps { | 94 struct FrameTimestamps { |
99 FrameTimestamps(); | 95 FrameTimestamps(); |
100 ~FrameTimestamps(); | 96 ~FrameTimestamps(); |
101 | 97 |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
159 | 155 |
160 // Capturer used to capture the screen. | 156 // Capturer used to capture the screen. |
161 scoped_ptr<webrtc::DesktopCapturer> capturer_; | 157 scoped_ptr<webrtc::DesktopCapturer> capturer_; |
162 | 158 |
163 // Used to encode captured frames. Always accessed on the encode thread. | 159 // Used to encode captured frames. Always accessed on the encode thread. |
164 scoped_ptr<VideoEncoder> encoder_; | 160 scoped_ptr<VideoEncoder> encoder_; |
165 | 161 |
166 // Interface through which video frames are passed to the client. | 162 // Interface through which video frames are passed to the client. |
167 protocol::VideoStub* video_stub_; | 163 protocol::VideoStub* video_stub_; |
168 | 164 |
| 165 SizeCallback size_callback_; |
| 166 |
169 // Timer used to ensure that we send empty keep-alive frames to the client | 167 // Timer used to ensure that we send empty keep-alive frames to the client |
170 // even when the video stream is paused or encoder is busy. | 168 // even when the video stream is paused or encoder is busy. |
171 base::Timer keep_alive_timer_; | 169 base::Timer keep_alive_timer_; |
172 | 170 |
173 // CaptureScheduler calls CaptureNextFrame() whenever a new frame needs to be | 171 // CaptureScheduler calls CaptureNextFrame() whenever a new frame needs to be |
174 // captured. | 172 // captured. |
175 CaptureScheduler capture_scheduler_; | 173 CaptureScheduler capture_scheduler_; |
176 | 174 |
177 // Timestamps for the frame to be captured next. | 175 // Timestamps for the frame to be captured next. |
178 scoped_ptr<FrameTimestamps> next_frame_timestamps_; | 176 scoped_ptr<FrameTimestamps> next_frame_timestamps_; |
179 | 177 |
180 // Timestamps for the frame that's being captured. | 178 // Timestamps for the frame that's being captured. |
181 scoped_ptr<FrameTimestamps> captured_frame_timestamps_; | 179 scoped_ptr<FrameTimestamps> captured_frame_timestamps_; |
182 | 180 |
183 bool send_pending_ = false; | 181 bool send_pending_ = false; |
184 | 182 |
185 ScopedVector<PacketWithTimestamps> pending_packets_; | 183 ScopedVector<PacketWithTimestamps> pending_packets_; |
186 | 184 |
187 base::ThreadChecker thread_checker_; | 185 base::ThreadChecker thread_checker_; |
188 | 186 |
189 base::WeakPtrFactory<VideoFramePump> weak_factory_; | 187 base::WeakPtrFactory<VideoFramePump> weak_factory_; |
190 | 188 |
191 DISALLOW_COPY_AND_ASSIGN(VideoFramePump); | 189 DISALLOW_COPY_AND_ASSIGN(VideoFramePump); |
192 }; | 190 }; |
193 | 191 |
194 } // namespace protocol | 192 } // namespace protocol |
195 } // namespace remoting | 193 } // namespace remoting |
196 | 194 |
197 #endif // REMOTING_PROTOCOL_VIDEO_FRAME_PUMP_H_ | 195 #endif // REMOTING_PROTOCOL_VIDEO_FRAME_PUMP_H_ |
OLD | NEW |