| 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 <stddef.h> | 8 #include <stddef.h> |
| 9 #include <stdint.h> | 9 #include <stdint.h> |
| 10 | 10 |
| 11 #include <memory> |
| 12 |
| 11 #include "base/macros.h" | 13 #include "base/macros.h" |
| 12 #include "base/memory/scoped_ptr.h" | |
| 13 #include "base/memory/scoped_vector.h" | 14 #include "base/memory/scoped_vector.h" |
| 14 #include "base/threading/thread_checker.h" | 15 #include "base/threading/thread_checker.h" |
| 15 #include "base/time/time.h" | 16 #include "base/time/time.h" |
| 16 #include "base/timer/timer.h" | 17 #include "base/timer/timer.h" |
| 17 #include "remoting/codec/video_encoder.h" | 18 #include "remoting/codec/video_encoder.h" |
| 18 #include "remoting/proto/video.pb.h" | 19 #include "remoting/proto/video.pb.h" |
| 19 #include "remoting/protocol/capture_scheduler.h" | 20 #include "remoting/protocol/capture_scheduler.h" |
| 20 #include "remoting/protocol/video_stream.h" | 21 #include "remoting/protocol/video_stream.h" |
| 21 #include "third_party/webrtc/modules/desktop_capture/desktop_capturer.h" | 22 #include "third_party/webrtc/modules/desktop_capture/desktop_capturer.h" |
| 22 | 23 |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 68 // too much CPU, or hogging the host's graphics subsystem. | 69 // too much CPU, or hogging the host's graphics subsystem. |
| 69 class VideoFramePump : public VideoStream, | 70 class VideoFramePump : public VideoStream, |
| 70 public webrtc::DesktopCapturer::Callback { | 71 public webrtc::DesktopCapturer::Callback { |
| 71 public: | 72 public: |
| 72 // Enables timestamps for generated frames. Used for testing. | 73 // Enables timestamps for generated frames. Used for testing. |
| 73 static void EnableTimestampsForTests(); | 74 static void EnableTimestampsForTests(); |
| 74 | 75 |
| 75 // Creates a VideoFramePump running capture, encode and network tasks on the | 76 // Creates a VideoFramePump running capture, encode and network tasks on the |
| 76 // supplied TaskRunners. Video will be pumped to |video_stub|, which must | 77 // supplied TaskRunners. Video will be pumped to |video_stub|, which must |
| 77 // outlive the pump.. | 78 // outlive the pump.. |
| 78 VideoFramePump( | 79 VideoFramePump(scoped_refptr<base::SingleThreadTaskRunner> encode_task_runner, |
| 79 scoped_refptr<base::SingleThreadTaskRunner> encode_task_runner, | 80 std::unique_ptr<webrtc::DesktopCapturer> capturer, |
| 80 scoped_ptr<webrtc::DesktopCapturer> capturer, | 81 std::unique_ptr<VideoEncoder> encoder, |
| 81 scoped_ptr<VideoEncoder> encoder, | 82 protocol::VideoStub* video_stub); |
| 82 protocol::VideoStub* video_stub); | |
| 83 ~VideoFramePump() override; | 83 ~VideoFramePump() override; |
| 84 | 84 |
| 85 // VideoStream interface. | 85 // VideoStream interface. |
| 86 void Pause(bool pause) override; | 86 void Pause(bool pause) override; |
| 87 void OnInputEventReceived(int64_t event_timestamp) override; | 87 void OnInputEventReceived(int64_t event_timestamp) override; |
| 88 void SetLosslessEncode(bool want_lossless) override; | 88 void SetLosslessEncode(bool want_lossless) override; |
| 89 void SetLosslessColor(bool want_lossless) override; | 89 void SetLosslessColor(bool want_lossless) override; |
| 90 void SetSizeCallback(const SizeCallback& size_callback) override; | 90 void SetSizeCallback(const SizeCallback& size_callback) override; |
| 91 | 91 |
| 92 protocol::VideoFeedbackStub* video_feedback_stub() { | 92 protocol::VideoFeedbackStub* video_feedback_stub() { |
| (...skipping 13 matching lines...) Expand all Loading... |
| 106 base::TimeTicks input_event_received_time; | 106 base::TimeTicks input_event_received_time; |
| 107 | 107 |
| 108 base::TimeTicks capture_started_time; | 108 base::TimeTicks capture_started_time; |
| 109 base::TimeTicks capture_ended_time; | 109 base::TimeTicks capture_ended_time; |
| 110 base::TimeTicks encode_started_time; | 110 base::TimeTicks encode_started_time; |
| 111 base::TimeTicks encode_ended_time; | 111 base::TimeTicks encode_ended_time; |
| 112 base::TimeTicks can_send_time; | 112 base::TimeTicks can_send_time; |
| 113 }; | 113 }; |
| 114 | 114 |
| 115 struct PacketWithTimestamps { | 115 struct PacketWithTimestamps { |
| 116 PacketWithTimestamps(scoped_ptr<VideoPacket> packet, | 116 PacketWithTimestamps(std::unique_ptr<VideoPacket> packet, |
| 117 scoped_ptr<FrameTimestamps> timestamps); | 117 std::unique_ptr<FrameTimestamps> timestamps); |
| 118 ~PacketWithTimestamps(); | 118 ~PacketWithTimestamps(); |
| 119 | 119 |
| 120 scoped_ptr<VideoPacket> packet; | 120 std::unique_ptr<VideoPacket> packet; |
| 121 scoped_ptr<FrameTimestamps> timestamps; | 121 std::unique_ptr<FrameTimestamps> timestamps; |
| 122 }; | 122 }; |
| 123 | 123 |
| 124 // webrtc::DesktopCapturer::Callback interface. | 124 // webrtc::DesktopCapturer::Callback interface. |
| 125 webrtc::SharedMemory* CreateSharedMemory(size_t size) override; | 125 webrtc::SharedMemory* CreateSharedMemory(size_t size) override; |
| 126 void OnCaptureCompleted(webrtc::DesktopFrame* frame) override; | 126 void OnCaptureCompleted(webrtc::DesktopFrame* frame) override; |
| 127 | 127 |
| 128 // Callback for CaptureScheduler. | 128 // Callback for CaptureScheduler. |
| 129 void CaptureNextFrame(); | 129 void CaptureNextFrame(); |
| 130 | 130 |
| 131 // Task running on the encoder thread to encode the |frame|. | 131 // Task running on the encoder thread to encode the |frame|. |
| 132 static scoped_ptr<PacketWithTimestamps> EncodeFrame( | 132 static std::unique_ptr<PacketWithTimestamps> EncodeFrame( |
| 133 VideoEncoder* encoder, | 133 VideoEncoder* encoder, |
| 134 scoped_ptr<webrtc::DesktopFrame> frame, | 134 std::unique_ptr<webrtc::DesktopFrame> frame, |
| 135 scoped_ptr<FrameTimestamps> timestamps); | 135 std::unique_ptr<FrameTimestamps> timestamps); |
| 136 | 136 |
| 137 // Task called when a frame has finished encoding. | 137 // Task called when a frame has finished encoding. |
| 138 void OnFrameEncoded(scoped_ptr<PacketWithTimestamps> packet); | 138 void OnFrameEncoded(std::unique_ptr<PacketWithTimestamps> packet); |
| 139 | 139 |
| 140 // Sends |packet| to the client. | 140 // Sends |packet| to the client. |
| 141 void SendPacket(scoped_ptr<PacketWithTimestamps> packet); | 141 void SendPacket(std::unique_ptr<PacketWithTimestamps> packet); |
| 142 | 142 |
| 143 // Helper called from SendPacket() to calculate timing fields in the |packet| | 143 // Helper called from SendPacket() to calculate timing fields in the |packet| |
| 144 // before sending it. | 144 // before sending it. |
| 145 void UpdateFrameTimers(VideoPacket* packet, FrameTimestamps* timestamps); | 145 void UpdateFrameTimers(VideoPacket* packet, FrameTimestamps* timestamps); |
| 146 | 146 |
| 147 // Callback passed to |video_stub_|. | 147 // Callback passed to |video_stub_|. |
| 148 void OnVideoPacketSent(); | 148 void OnVideoPacketSent(); |
| 149 | 149 |
| 150 // Called by |keep_alive_timer_|. | 150 // Called by |keep_alive_timer_|. |
| 151 void SendKeepAlivePacket(); | 151 void SendKeepAlivePacket(); |
| 152 | 152 |
| 153 // Callback for |video_stub_| called after a keep-alive packet is sent. | 153 // Callback for |video_stub_| called after a keep-alive packet is sent. |
| 154 void OnKeepAlivePacketSent(); | 154 void OnKeepAlivePacketSent(); |
| 155 | 155 |
| 156 // Task runner used to run |encoder_|. | 156 // Task runner used to run |encoder_|. |
| 157 scoped_refptr<base::SingleThreadTaskRunner> encode_task_runner_; | 157 scoped_refptr<base::SingleThreadTaskRunner> encode_task_runner_; |
| 158 | 158 |
| 159 // Capturer used to capture the screen. | 159 // Capturer used to capture the screen. |
| 160 scoped_ptr<webrtc::DesktopCapturer> capturer_; | 160 std::unique_ptr<webrtc::DesktopCapturer> capturer_; |
| 161 | 161 |
| 162 // Used to encode captured frames. Always accessed on the encode thread. | 162 // Used to encode captured frames. Always accessed on the encode thread. |
| 163 scoped_ptr<VideoEncoder> encoder_; | 163 std::unique_ptr<VideoEncoder> encoder_; |
| 164 | 164 |
| 165 // Interface through which video frames are passed to the client. | 165 // Interface through which video frames are passed to the client. |
| 166 protocol::VideoStub* video_stub_; | 166 protocol::VideoStub* video_stub_; |
| 167 | 167 |
| 168 SizeCallback size_callback_; | 168 SizeCallback size_callback_; |
| 169 webrtc::DesktopSize frame_size_; | 169 webrtc::DesktopSize frame_size_; |
| 170 webrtc::DesktopVector frame_dpi_; | 170 webrtc::DesktopVector frame_dpi_; |
| 171 | 171 |
| 172 // Timer used to ensure that we send empty keep-alive frames to the client | 172 // Timer used to ensure that we send empty keep-alive frames to the client |
| 173 // even when the video stream is paused or encoder is busy. | 173 // even when the video stream is paused or encoder is busy. |
| 174 base::Timer keep_alive_timer_; | 174 base::Timer keep_alive_timer_; |
| 175 | 175 |
| 176 // CaptureScheduler calls CaptureNextFrame() whenever a new frame needs to be | 176 // CaptureScheduler calls CaptureNextFrame() whenever a new frame needs to be |
| 177 // captured. | 177 // captured. |
| 178 CaptureScheduler capture_scheduler_; | 178 CaptureScheduler capture_scheduler_; |
| 179 | 179 |
| 180 // Timestamps for the frame to be captured next. | 180 // Timestamps for the frame to be captured next. |
| 181 scoped_ptr<FrameTimestamps> next_frame_timestamps_; | 181 std::unique_ptr<FrameTimestamps> next_frame_timestamps_; |
| 182 | 182 |
| 183 // Timestamps for the frame that's being captured. | 183 // Timestamps for the frame that's being captured. |
| 184 scoped_ptr<FrameTimestamps> captured_frame_timestamps_; | 184 std::unique_ptr<FrameTimestamps> captured_frame_timestamps_; |
| 185 | 185 |
| 186 bool send_pending_ = false; | 186 bool send_pending_ = false; |
| 187 | 187 |
| 188 ScopedVector<PacketWithTimestamps> pending_packets_; | 188 ScopedVector<PacketWithTimestamps> pending_packets_; |
| 189 | 189 |
| 190 base::ThreadChecker thread_checker_; | 190 base::ThreadChecker thread_checker_; |
| 191 | 191 |
| 192 base::WeakPtrFactory<VideoFramePump> weak_factory_; | 192 base::WeakPtrFactory<VideoFramePump> weak_factory_; |
| 193 | 193 |
| 194 DISALLOW_COPY_AND_ASSIGN(VideoFramePump); | 194 DISALLOW_COPY_AND_ASSIGN(VideoFramePump); |
| 195 }; | 195 }; |
| 196 | 196 |
| 197 } // namespace protocol | 197 } // namespace protocol |
| 198 } // namespace remoting | 198 } // namespace remoting |
| 199 | 199 |
| 200 #endif // REMOTING_PROTOCOL_VIDEO_FRAME_PUMP_H_ | 200 #endif // REMOTING_PROTOCOL_VIDEO_FRAME_PUMP_H_ |
| OLD | NEW |