| 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_HOST_VIDEO_FRAME_PUMP_H_ | 5 #ifndef REMOTING_HOST_VIDEO_FRAME_PUMP_H_ |
| 6 #define REMOTING_HOST_VIDEO_FRAME_PUMP_H_ | 6 #define REMOTING_HOST_VIDEO_FRAME_PUMP_H_ |
| 7 | 7 |
| 8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
| 9 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
| 10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| 11 #include "base/threading/thread_checker.h" | 11 #include "base/threading/thread_checker.h" |
| 12 #include "base/time/time.h" | 12 #include "base/time/time.h" |
| 13 #include "base/timer/timer.h" | 13 #include "base/timer/timer.h" |
| 14 #include "remoting/codec/video_encoder.h" | 14 #include "remoting/codec/video_encoder.h" |
| 15 #include "remoting/host/capture_scheduler.h" | 15 #include "remoting/host/capture_scheduler.h" |
| 16 #include "remoting/proto/video.pb.h" | 16 #include "remoting/proto/video.pb.h" |
| 17 #include "third_party/webrtc/modules/desktop_capture/desktop_capturer.h" | 17 #include "third_party/webrtc/modules/desktop_capture/desktop_capturer.h" |
| 18 | 18 |
| 19 namespace base { | 19 namespace base { |
| 20 class SingleThreadTaskRunner; | 20 class SingleThreadTaskRunner; |
| 21 } // namespace base | 21 } // namespace base |
| 22 | 22 |
| 23 namespace remoting { | 23 namespace remoting { |
| 24 | 24 |
| 25 namespace protocol { | 25 namespace protocol { |
| 26 class VideoFeedbackStub; |
| 26 class VideoStub; | 27 class VideoStub; |
| 27 } // namespace protocol | 28 } // namespace protocol |
| 28 | 29 |
| 29 // Class responsible for scheduling frame captures from a screen capturer., | 30 // Class responsible for scheduling frame captures from a screen capturer., |
| 30 // delivering them to a VideoEncoder to encode, and | 31 // delivering them to a VideoEncoder to encode, and |
| 31 // finally passing the encoded video packets to the specified VideoStub to send | 32 // finally passing the encoded video packets to the specified VideoStub to send |
| 32 // on the network. | 33 // on the network. |
| 33 // | 34 // |
| 34 // THREADING | 35 // THREADING |
| 35 // | 36 // |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 83 | 84 |
| 84 // Updates event timestamp from the last event received from the client. This | 85 // Updates event timestamp from the last event received from the client. This |
| 85 // value is sent back to the client for roundtrip latency estimates. | 86 // value is sent back to the client for roundtrip latency estimates. |
| 86 void SetLatestEventTimestamp(int64 latest_event_timestamp); | 87 void SetLatestEventTimestamp(int64 latest_event_timestamp); |
| 87 | 88 |
| 88 // Sets whether the video encoder should be requested to encode losslessly, | 89 // Sets whether the video encoder should be requested to encode losslessly, |
| 89 // or to use a lossless color space (typically requiring higher bandwidth). | 90 // or to use a lossless color space (typically requiring higher bandwidth). |
| 90 void SetLosslessEncode(bool want_lossless); | 91 void SetLosslessEncode(bool want_lossless); |
| 91 void SetLosslessColor(bool want_lossless); | 92 void SetLosslessColor(bool want_lossless); |
| 92 | 93 |
| 94 protocol::VideoFeedbackStub* video_feedback_stub() { |
| 95 return &capture_scheduler_; |
| 96 } |
| 97 |
| 93 private: | 98 private: |
| 94 // webrtc::DesktopCapturer::Callback interface. | 99 // webrtc::DesktopCapturer::Callback interface. |
| 95 webrtc::SharedMemory* CreateSharedMemory(size_t size) override; | 100 webrtc::SharedMemory* CreateSharedMemory(size_t size) override; |
| 96 void OnCaptureCompleted(webrtc::DesktopFrame* frame) override; | 101 void OnCaptureCompleted(webrtc::DesktopFrame* frame) override; |
| 97 | 102 |
| 98 // Callback for CaptureScheduler. | 103 // Callback for CaptureScheduler. |
| 99 void CaptureNextFrame(); | 104 void CaptureNextFrame(); |
| 100 | 105 |
| 101 // Sends encoded frame | 106 // Sends encoded frame |
| 102 void SendEncodedFrame(int64 latest_event_timestamp, | 107 void SendEncodedFrame(int64 latest_event_timestamp, |
| 103 base::TimeTicks timestamp, | 108 base::TimeTicks timestamp, |
| 104 scoped_ptr<VideoPacket> packet); | 109 scoped_ptr<VideoPacket> packet); |
| 105 | 110 |
| 106 // Callback passed to |video_stub_| for the last packet in each frame, to | 111 // Callback passed to |video_stub_|. |
| 107 // rate-limit frame captures to network throughput. | |
| 108 void OnVideoPacketSent(); | 112 void OnVideoPacketSent(); |
| 109 | 113 |
| 110 // Called by |keep_alive_timer_|. | 114 // Called by |keep_alive_timer_|. |
| 111 void SendKeepAlivePacket(); | 115 void SendKeepAlivePacket(); |
| 112 | 116 |
| 113 // Callback for |video_stub_| called after a keep-alive packet is sent. | 117 // Callback for |video_stub_| called after a keep-alive packet is sent. |
| 114 void OnKeepAlivePacketSent(); | 118 void OnKeepAlivePacketSent(); |
| 115 | 119 |
| 116 base::ThreadChecker thread_checker_; | |
| 117 | |
| 118 // Task runner used to run |encoder_|. | 120 // Task runner used to run |encoder_|. |
| 119 scoped_refptr<base::SingleThreadTaskRunner> encode_task_runner_; | 121 scoped_refptr<base::SingleThreadTaskRunner> encode_task_runner_; |
| 120 | 122 |
| 121 // Capturer used to capture the screen. | 123 // Capturer used to capture the screen. |
| 122 scoped_ptr<webrtc::DesktopCapturer> capturer_; | 124 scoped_ptr<webrtc::DesktopCapturer> capturer_; |
| 123 | 125 |
| 124 // Used to encode captured frames. Always accessed on the encode thread. | 126 // Used to encode captured frames. Always accessed on the encode thread. |
| 125 scoped_ptr<VideoEncoder> encoder_; | 127 scoped_ptr<VideoEncoder> encoder_; |
| 126 | 128 |
| 127 // Interface through which video frames are passed to the client. | 129 // Interface through which video frames are passed to the client. |
| 128 protocol::VideoStub* video_stub_; | 130 protocol::VideoStub* video_stub_; |
| 129 | 131 |
| 130 // Timer used to ensure that we send empty keep-alive frames to the client | 132 // Timer used to ensure that we send empty keep-alive frames to the client |
| 131 // even when the video stream is paused or encoder is busy. | 133 // even when the video stream is paused or encoder is busy. |
| 132 base::Timer keep_alive_timer_; | 134 base::Timer keep_alive_timer_; |
| 133 | 135 |
| 134 // CaptureScheduler calls CaptureNextFrame() whenever a new frame needs to be | 136 // CaptureScheduler calls CaptureNextFrame() whenever a new frame needs to be |
| 135 // captured. | 137 // captured. |
| 136 CaptureScheduler capture_scheduler_; | 138 CaptureScheduler capture_scheduler_; |
| 137 | 139 |
| 138 // Number updated by the caller to trace performance. | 140 // Number updated by the caller to trace performance. |
| 139 int64 latest_event_timestamp_; | 141 int64 latest_event_timestamp_; |
| 140 | 142 |
| 143 base::ThreadChecker thread_checker_; |
| 144 |
| 141 base::WeakPtrFactory<VideoFramePump> weak_factory_; | 145 base::WeakPtrFactory<VideoFramePump> weak_factory_; |
| 142 | 146 |
| 143 DISALLOW_COPY_AND_ASSIGN(VideoFramePump); | 147 DISALLOW_COPY_AND_ASSIGN(VideoFramePump); |
| 144 }; | 148 }; |
| 145 | 149 |
| 146 } // namespace remoting | 150 } // namespace remoting |
| 147 | 151 |
| 148 #endif // REMOTING_HOST_VIDEO_FRAME_PUMP_H_ | 152 #endif // REMOTING_HOST_VIDEO_FRAME_PUMP_H_ |
| OLD | NEW |