| 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 #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 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 105 encode_task_runner_->PostTask( | 105 encode_task_runner_->PostTask( |
| 106 FROM_HERE, base::Bind(&VideoEncoder::SetLosslessColor, | 106 FROM_HERE, base::Bind(&VideoEncoder::SetLosslessColor, |
| 107 base::Unretained(encoder_.get()), want_lossless)); | 107 base::Unretained(encoder_.get()), want_lossless)); |
| 108 } | 108 } |
| 109 | 109 |
| 110 void VideoFramePump::SetSizeCallback(const SizeCallback& size_callback) { | 110 void VideoFramePump::SetSizeCallback(const SizeCallback& size_callback) { |
| 111 DCHECK(thread_checker_.CalledOnValidThread()); | 111 DCHECK(thread_checker_.CalledOnValidThread()); |
| 112 size_callback_ = size_callback; | 112 size_callback_ = size_callback; |
| 113 } | 113 } |
| 114 | 114 |
| 115 void VideoFramePump::OnCaptureCompleted(webrtc::DesktopFrame* frame) { | 115 void VideoFramePump::OnCaptureResult( |
| 116 webrtc::DesktopCapturer::Result result, |
| 117 std::unique_ptr<webrtc::DesktopFrame> frame) { |
| 116 DCHECK(thread_checker_.CalledOnValidThread()); | 118 DCHECK(thread_checker_.CalledOnValidThread()); |
| 117 | 119 |
| 118 capture_scheduler_.OnCaptureCompleted(); | 120 capture_scheduler_.OnCaptureCompleted(); |
| 119 | 121 |
| 120 captured_frame_timestamps_->capture_ended_time = base::TimeTicks::Now(); | 122 captured_frame_timestamps_->capture_ended_time = base::TimeTicks::Now(); |
| 121 | 123 |
| 122 if (frame) { | 124 if (frame) { |
| 123 webrtc::DesktopVector dpi = | 125 webrtc::DesktopVector dpi = |
| 124 frame->dpi().is_zero() ? webrtc::DesktopVector(kDefaultDpi, kDefaultDpi) | 126 frame->dpi().is_zero() ? webrtc::DesktopVector(kDefaultDpi, kDefaultDpi) |
| 125 : frame->dpi(); | 127 : frame->dpi(); |
| 126 if (!frame_size_.equals(frame->size()) || !frame_dpi_.equals(dpi)) { | 128 if (!frame_size_.equals(frame->size()) || !frame_dpi_.equals(dpi)) { |
| 127 frame_size_ = frame->size(); | 129 frame_size_ = frame->size(); |
| 128 frame_dpi_ = dpi; | 130 frame_dpi_ = dpi; |
| 129 if (!size_callback_.is_null()) | 131 if (!size_callback_.is_null()) |
| 130 size_callback_.Run(frame_size_, frame_dpi_); | 132 size_callback_.Run(frame_size_, frame_dpi_); |
| 131 } | 133 } |
| 132 } | 134 } |
| 133 | 135 |
| 134 // Even when |frame| is nullptr we still need to post it to the encode thread | 136 // Even when |frame| is nullptr we still need to post it to the encode thread |
| 135 // to make sure frames are freed in the same order they are received and | 137 // to make sure frames are freed in the same order they are received and |
| 136 // that we don't start capturing frame n+2 before frame n is freed. | 138 // that we don't start capturing frame n+2 before frame n is freed. |
| 137 base::PostTaskAndReplyWithResult( | 139 base::PostTaskAndReplyWithResult( |
| 138 encode_task_runner_.get(), FROM_HERE, | 140 encode_task_runner_.get(), FROM_HERE, |
| 139 base::Bind(&VideoFramePump::EncodeFrame, encoder_.get(), | 141 base::Bind(&VideoFramePump::EncodeFrame, encoder_.get(), |
| 140 base::Passed(base::WrapUnique(frame)), | 142 base::Passed(&frame), |
| 141 base::Passed(&captured_frame_timestamps_)), | 143 base::Passed(&captured_frame_timestamps_)), |
| 142 base::Bind(&VideoFramePump::OnFrameEncoded, weak_factory_.GetWeakPtr())); | 144 base::Bind(&VideoFramePump::OnFrameEncoded, weak_factory_.GetWeakPtr())); |
| 143 } | 145 } |
| 144 | 146 |
| 145 void VideoFramePump::CaptureNextFrame() { | 147 void VideoFramePump::CaptureNextFrame() { |
| 146 DCHECK(thread_checker_.CalledOnValidThread()); | 148 DCHECK(thread_checker_.CalledOnValidThread()); |
| 147 | 149 |
| 148 // |next_frame_timestamps_| is not set if no input events were received since | 150 // |next_frame_timestamps_| is not set if no input events were received since |
| 149 // the previous frame. In that case create FrameTimestamps instance without | 151 // the previous frame. In that case create FrameTimestamps instance without |
| 150 // setting |input_event_client_timestamp| and |input_event_received_time|. | 152 // setting |input_event_client_timestamp| and |input_event_received_time|. |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 265 } | 267 } |
| 266 | 268 |
| 267 void VideoFramePump::OnKeepAlivePacketSent() { | 269 void VideoFramePump::OnKeepAlivePacketSent() { |
| 268 DCHECK(thread_checker_.CalledOnValidThread()); | 270 DCHECK(thread_checker_.CalledOnValidThread()); |
| 269 | 271 |
| 270 keep_alive_timer_.Reset(); | 272 keep_alive_timer_.Reset(); |
| 271 } | 273 } |
| 272 | 274 |
| 273 } // namespace protocol | 275 } // namespace protocol |
| 274 } // namespace remoting | 276 } // namespace remoting |
| OLD | NEW |