Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(75)

Side by Side Diff: remoting/protocol/video_frame_pump.cc

Issue 2413553003: Add InputEventTimestampSource interface. (Closed)
Patch Set: msvc compilation Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « remoting/protocol/video_frame_pump.h ('k') | remoting/protocol/video_stream.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 #include "remoting/protocol/video_frame_pump.h" 5 #include "remoting/protocol/video_frame_pump.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <memory> 8 #include <memory>
9 #include <utility> 9 #include <utility>
10 10
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 DCHECK(video_stub_); 62 DCHECK(video_stub_);
63 63
64 capturer_->Start(this); 64 capturer_->Start(this);
65 capture_scheduler_.Start(); 65 capture_scheduler_.Start();
66 } 66 }
67 67
68 VideoFramePump::~VideoFramePump() { 68 VideoFramePump::~VideoFramePump() {
69 encode_task_runner_->DeleteSoon(FROM_HERE, encoder_.release()); 69 encode_task_runner_->DeleteSoon(FROM_HERE, encoder_.release());
70 } 70 }
71 71
72 void VideoFramePump::SetEventTimestampsSource(
73 scoped_refptr<InputEventTimestampsSource> event_timestamps_source) {
74 DCHECK(thread_checker_.CalledOnValidThread());
75
76 event_timestamps_source_ = event_timestamps_source;
77 }
78
72 void VideoFramePump::Pause(bool pause) { 79 void VideoFramePump::Pause(bool pause) {
73 DCHECK(thread_checker_.CalledOnValidThread()); 80 DCHECK(thread_checker_.CalledOnValidThread());
74 81
75 capture_scheduler_.Pause(pause); 82 capture_scheduler_.Pause(pause);
76 } 83 }
77 84
78 void VideoFramePump::OnInputEventReceived(int64_t event_timestamp) {
79 DCHECK(thread_checker_.CalledOnValidThread());
80
81 if (!next_frame_timestamps_)
82 next_frame_timestamps_.reset(new FrameTimestamps());
83 next_frame_timestamps_->input_event_client_timestamp = event_timestamp;
84 next_frame_timestamps_->input_event_received_time = base::TimeTicks::Now();
85 }
86
87 void VideoFramePump::SetLosslessEncode(bool want_lossless) { 85 void VideoFramePump::SetLosslessEncode(bool want_lossless) {
88 DCHECK(thread_checker_.CalledOnValidThread()); 86 DCHECK(thread_checker_.CalledOnValidThread());
89 87
90 encode_task_runner_->PostTask( 88 encode_task_runner_->PostTask(
91 FROM_HERE, base::Bind(&VideoEncoder::SetLosslessEncode, 89 FROM_HERE, base::Bind(&VideoEncoder::SetLosslessEncode,
92 base::Unretained(encoder_.get()), want_lossless)); 90 base::Unretained(encoder_.get()), want_lossless));
93 } 91 }
94 92
95 void VideoFramePump::SetLosslessColor(bool want_lossless) { 93 void VideoFramePump::SetLosslessColor(bool want_lossless) {
96 DCHECK(thread_checker_.CalledOnValidThread()); 94 DCHECK(thread_checker_.CalledOnValidThread());
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
133 encode_task_runner_.get(), FROM_HERE, 131 encode_task_runner_.get(), FROM_HERE,
134 base::Bind(&VideoFramePump::EncodeFrame, encoder_.get(), 132 base::Bind(&VideoFramePump::EncodeFrame, encoder_.get(),
135 base::Passed(&frame), 133 base::Passed(&frame),
136 base::Passed(&captured_frame_timestamps_)), 134 base::Passed(&captured_frame_timestamps_)),
137 base::Bind(&VideoFramePump::OnFrameEncoded, weak_factory_.GetWeakPtr())); 135 base::Bind(&VideoFramePump::OnFrameEncoded, weak_factory_.GetWeakPtr()));
138 } 136 }
139 137
140 void VideoFramePump::CaptureNextFrame() { 138 void VideoFramePump::CaptureNextFrame() {
141 DCHECK(thread_checker_.CalledOnValidThread()); 139 DCHECK(thread_checker_.CalledOnValidThread());
142 140
143 // |next_frame_timestamps_| is not set if no input events were received since 141 captured_frame_timestamps_.reset(new FrameTimestamps());
144 // the previous frame. In that case create FrameTimestamps instance without 142 captured_frame_timestamps_->capture_started_time = base::TimeTicks::Now();
145 // setting |input_event_client_timestamp| and |input_event_received_time|.
146 if (!next_frame_timestamps_)
147 next_frame_timestamps_.reset(new FrameTimestamps());
148 143
149 captured_frame_timestamps_ = std::move(next_frame_timestamps_); 144 if (event_timestamps_source_) {
150 captured_frame_timestamps_->capture_started_time = base::TimeTicks::Now(); 145 captured_frame_timestamps_->input_event_timestamps =
146 event_timestamps_source_->TakeLastEventTimestamps();
147 }
151 148
152 capturer_->Capture(webrtc::DesktopRegion()); 149 capturer_->Capture(webrtc::DesktopRegion());
153 } 150 }
154 151
155 // static 152 // static
156 std::unique_ptr<VideoFramePump::PacketWithTimestamps> 153 std::unique_ptr<VideoFramePump::PacketWithTimestamps>
157 VideoFramePump::EncodeFrame(VideoEncoder* encoder, 154 VideoFramePump::EncodeFrame(VideoEncoder* encoder,
158 std::unique_ptr<webrtc::DesktopFrame> frame, 155 std::unique_ptr<webrtc::DesktopFrame> frame,
159 std::unique_ptr<FrameTimestamps> timestamps) { 156 std::unique_ptr<FrameTimestamps> timestamps) {
160 timestamps->encode_started_time = base::TimeTicks::Now(); 157 timestamps->encode_started_time = base::TimeTicks::Now();
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
202 UpdateFrameTimers(packet->packet.get(), packet->timestamps.get()); 199 UpdateFrameTimers(packet->packet.get(), packet->timestamps.get());
203 200
204 send_pending_ = true; 201 send_pending_ = true;
205 video_stub_->ProcessVideoPacket(std::move(packet->packet), 202 video_stub_->ProcessVideoPacket(std::move(packet->packet),
206 base::Bind(&VideoFramePump::OnVideoPacketSent, 203 base::Bind(&VideoFramePump::OnVideoPacketSent,
207 weak_factory_.GetWeakPtr())); 204 weak_factory_.GetWeakPtr()));
208 } 205 }
209 206
210 void VideoFramePump::UpdateFrameTimers(VideoPacket* packet, 207 void VideoFramePump::UpdateFrameTimers(VideoPacket* packet,
211 FrameTimestamps* timestamps) { 208 FrameTimestamps* timestamps) {
212 if (!timestamps->input_event_received_time.is_null()) { 209 if (!timestamps->input_event_timestamps.is_null()) {
213 packet->set_capture_pending_time_ms((timestamps->capture_started_time - 210 packet->set_capture_pending_time_ms(
214 timestamps->input_event_received_time) 211 (timestamps->capture_started_time -
215 .InMilliseconds()); 212 timestamps->input_event_timestamps.host_timestamp)
213 .InMilliseconds());
216 packet->set_latest_event_timestamp( 214 packet->set_latest_event_timestamp(
217 timestamps->input_event_client_timestamp); 215 timestamps->input_event_timestamps.client_timestamp.ToInternalValue());
218 } 216 }
219 217
220 packet->set_capture_overhead_time_ms( 218 packet->set_capture_overhead_time_ms(
221 (timestamps->capture_ended_time - timestamps->capture_started_time) 219 (timestamps->capture_ended_time - timestamps->capture_started_time)
222 .InMilliseconds() - 220 .InMilliseconds() -
223 packet->capture_time_ms()); 221 packet->capture_time_ms());
224 222
225 packet->set_encode_pending_time_ms( 223 packet->set_encode_pending_time_ms(
226 (timestamps->encode_started_time - timestamps->capture_ended_time) 224 (timestamps->encode_started_time - timestamps->capture_ended_time)
227 .InMilliseconds()); 225 .InMilliseconds());
(...skipping 28 matching lines...) Expand all
256 } 254 }
257 255
258 void VideoFramePump::OnKeepAlivePacketSent() { 256 void VideoFramePump::OnKeepAlivePacketSent() {
259 DCHECK(thread_checker_.CalledOnValidThread()); 257 DCHECK(thread_checker_.CalledOnValidThread());
260 258
261 keep_alive_timer_.Reset(); 259 keep_alive_timer_.Reset();
262 } 260 }
263 261
264 } // namespace protocol 262 } // namespace protocol
265 } // namespace remoting 263 } // namespace remoting
OLDNEW
« no previous file with comments | « remoting/protocol/video_frame_pump.h ('k') | remoting/protocol/video_stream.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698