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/memory/scoped_vector.h" | |
11 #include "base/threading/thread_checker.h" | 12 #include "base/threading/thread_checker.h" |
12 #include "base/time/time.h" | 13 #include "base/time/time.h" |
13 #include "base/timer/timer.h" | 14 #include "base/timer/timer.h" |
14 #include "remoting/codec/video_encoder.h" | 15 #include "remoting/codec/video_encoder.h" |
15 #include "remoting/host/capture_scheduler.h" | 16 #include "remoting/host/capture_scheduler.h" |
16 #include "remoting/proto/video.pb.h" | 17 #include "remoting/proto/video.pb.h" |
17 #include "third_party/webrtc/modules/desktop_capture/desktop_capturer.h" | 18 #include "third_party/webrtc/modules/desktop_capture/desktop_capturer.h" |
18 | 19 |
19 namespace base { | 20 namespace base { |
20 class SingleThreadTaskRunner; | 21 class SingleThreadTaskRunner; |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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 // Pauses or resumes scheduling of frame captures. Pausing/resuming captures |
82 // only affects capture scheduling and does not stop/start the capturer. | 83 // only affects capture scheduling and does not stop/start the capturer. |
83 void Pause(bool pause); | 84 void Pause(bool pause); |
84 | 85 |
85 // Updates event timestamp from the last event received from the client. This | 86 // Called whenever input event is received. |
86 // value is sent back to the client for roundtrip latency estimates. | 87 void OnInputEventReceived(int64_t event_timestamp); |
87 void SetLatestEventTimestamp(int64 latest_event_timestamp); | |
88 | 88 |
89 // Sets whether the video encoder should be requested to encode losslessly, | 89 // Sets whether the video encoder should be requested to encode losslessly, |
90 // or to use a lossless color space (typically requiring higher bandwidth). | 90 // or to use a lossless color space (typically requiring higher bandwidth). |
91 void SetLosslessEncode(bool want_lossless); | 91 void SetLosslessEncode(bool want_lossless); |
92 void SetLosslessColor(bool want_lossless); | 92 void SetLosslessColor(bool want_lossless); |
93 | 93 |
94 protocol::VideoFeedbackStub* video_feedback_stub() { | 94 protocol::VideoFeedbackStub* video_feedback_stub() { |
95 return &capture_scheduler_; | 95 return &capture_scheduler_; |
96 } | 96 } |
97 | 97 |
98 private: | 98 private: |
99 struct FrameTimestamps { | |
100 FrameTimestamps(); | |
101 ~FrameTimestamps(); | |
102 | |
103 // The following two field are set only for one frame after each incoming | |
anandc
2015/09/25 19:21:45
"fields"
Sergey Ulanov
2015/09/25 20:35:26
Done.
| |
104 // input event. |input_event_client_timestamp| is event timestamp | |
105 // received from the client. |input_event_received_time| is local time when | |
106 // the event was received. | |
107 int64_t input_event_client_timestamp = -1; | |
108 base::TimeTicks input_event_received_time; | |
109 | |
110 base::TimeTicks capture_started_time; | |
111 base::TimeTicks capture_ended_time; | |
112 base::TimeTicks encode_started_time; | |
113 base::TimeTicks encode_ended_time; | |
114 base::TimeTicks can_send_time; | |
115 }; | |
116 | |
117 struct PacketWithTimestamps { | |
118 PacketWithTimestamps(scoped_ptr<VideoPacket> packet, | |
119 scoped_ptr<FrameTimestamps> timestamps); | |
120 ~PacketWithTimestamps(); | |
121 | |
122 scoped_ptr<VideoPacket> packet; | |
123 scoped_ptr<FrameTimestamps> timestamps; | |
124 }; | |
125 | |
99 // webrtc::DesktopCapturer::Callback interface. | 126 // webrtc::DesktopCapturer::Callback interface. |
100 webrtc::SharedMemory* CreateSharedMemory(size_t size) override; | 127 webrtc::SharedMemory* CreateSharedMemory(size_t size) override; |
101 void OnCaptureCompleted(webrtc::DesktopFrame* frame) override; | 128 void OnCaptureCompleted(webrtc::DesktopFrame* frame) override; |
102 | 129 |
103 // Callback for CaptureScheduler. | 130 // Callback for CaptureScheduler. |
104 void CaptureNextFrame(); | 131 void CaptureNextFrame(); |
105 | 132 |
106 // Sends encoded frame | 133 // Task running on the encoder thread to encode the |frame|. |
107 void SendEncodedFrame(int64 latest_event_timestamp, | 134 static scoped_ptr<PacketWithTimestamps> EncodeFrame( |
108 base::TimeTicks timestamp, | 135 VideoEncoder* encoder, |
109 scoped_ptr<VideoPacket> packet); | 136 scoped_ptr<webrtc::DesktopFrame> frame, |
137 scoped_ptr<FrameTimestamps> timestamps); | |
138 | |
139 // Task called when a frame has finished decoding. | |
anandc
2015/09/25 19:21:44
"finished encoding."
Sergey Ulanov
2015/09/25 20:35:26
Done.
| |
140 void OnFrameEncoded(scoped_ptr<PacketWithTimestamps> packet); | |
141 | |
142 // Sends |packet| to the client. | |
143 void SendPacket(scoped_ptr<PacketWithTimestamps> packet); | |
144 | |
145 // Helper called from SendPacket() to calculate timing fields in the |packet| | |
146 // before sending it. | |
147 void UpdateFrameTimers(VideoPacket* packet, FrameTimestamps* timestamps); | |
110 | 148 |
111 // Callback passed to |video_stub_|. | 149 // Callback passed to |video_stub_|. |
112 void OnVideoPacketSent(); | 150 void OnVideoPacketSent(); |
113 | 151 |
114 // Called by |keep_alive_timer_|. | 152 // Called by |keep_alive_timer_|. |
115 void SendKeepAlivePacket(); | 153 void SendKeepAlivePacket(); |
116 | 154 |
117 // Callback for |video_stub_| called after a keep-alive packet is sent. | 155 // Callback for |video_stub_| called after a keep-alive packet is sent. |
118 void OnKeepAlivePacketSent(); | 156 void OnKeepAlivePacketSent(); |
119 | 157 |
(...skipping 10 matching lines...) Expand all Loading... | |
130 protocol::VideoStub* video_stub_; | 168 protocol::VideoStub* video_stub_; |
131 | 169 |
132 // Timer used to ensure that we send empty keep-alive frames to the client | 170 // Timer used to ensure that we send empty keep-alive frames to the client |
133 // even when the video stream is paused or encoder is busy. | 171 // even when the video stream is paused or encoder is busy. |
134 base::Timer keep_alive_timer_; | 172 base::Timer keep_alive_timer_; |
135 | 173 |
136 // CaptureScheduler calls CaptureNextFrame() whenever a new frame needs to be | 174 // CaptureScheduler calls CaptureNextFrame() whenever a new frame needs to be |
137 // captured. | 175 // captured. |
138 CaptureScheduler capture_scheduler_; | 176 CaptureScheduler capture_scheduler_; |
139 | 177 |
140 // Number updated by the caller to trace performance. | 178 // Timestamps for the frame to be captured next. |
141 int64 latest_event_timestamp_; | 179 scoped_ptr<FrameTimestamps> next_frame_timestamps_; |
180 | |
181 // Timestamps for the frame that's is being captured. | |
anandc
2015/09/25 19:21:44
Remove "is".
Sergey Ulanov
2015/09/25 20:35:26
Done.
| |
182 scoped_ptr<FrameTimestamps> captured_frame_timestamps_; | |
183 | |
184 bool send_pending_; | |
185 | |
186 ScopedVector<PacketWithTimestamps> pending_packets_; | |
142 | 187 |
143 base::ThreadChecker thread_checker_; | 188 base::ThreadChecker thread_checker_; |
144 | 189 |
145 base::WeakPtrFactory<VideoFramePump> weak_factory_; | 190 base::WeakPtrFactory<VideoFramePump> weak_factory_; |
146 | 191 |
147 DISALLOW_COPY_AND_ASSIGN(VideoFramePump); | 192 DISALLOW_COPY_AND_ASSIGN(VideoFramePump); |
148 }; | 193 }; |
149 | 194 |
150 } // namespace remoting | 195 } // namespace remoting |
151 | 196 |
152 #endif // REMOTING_HOST_VIDEO_FRAME_PUMP_H_ | 197 #endif // REMOTING_HOST_VIDEO_FRAME_PUMP_H_ |
OLD | NEW |