| 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 |
| 124 // TODO(sergeyu): Handle ERROR_PERMANENT result. |
| 125 |
| 122 if (frame) { | 126 if (frame) { |
| 123 webrtc::DesktopVector dpi = | 127 webrtc::DesktopVector dpi = |
| 124 frame->dpi().is_zero() ? webrtc::DesktopVector(kDefaultDpi, kDefaultDpi) | 128 frame->dpi().is_zero() ? webrtc::DesktopVector(kDefaultDpi, kDefaultDpi) |
| 125 : frame->dpi(); | 129 : frame->dpi(); |
| 126 if (!frame_size_.equals(frame->size()) || !frame_dpi_.equals(dpi)) { | 130 if (!frame_size_.equals(frame->size()) || !frame_dpi_.equals(dpi)) { |
| 127 frame_size_ = frame->size(); | 131 frame_size_ = frame->size(); |
| 128 frame_dpi_ = dpi; | 132 frame_dpi_ = dpi; |
| 129 if (!size_callback_.is_null()) | 133 if (!size_callback_.is_null()) |
| 130 size_callback_.Run(frame_size_, frame_dpi_); | 134 size_callback_.Run(frame_size_, frame_dpi_); |
| 131 } | 135 } |
| 132 } | 136 } |
| 133 | 137 |
| 134 // Even when |frame| is nullptr we still need to post it to the encode thread | 138 // 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 | 139 // 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. | 140 // that we don't start capturing frame n+2 before frame n is freed. |
| 137 base::PostTaskAndReplyWithResult( | 141 base::PostTaskAndReplyWithResult( |
| 138 encode_task_runner_.get(), FROM_HERE, | 142 encode_task_runner_.get(), FROM_HERE, |
| 139 base::Bind(&VideoFramePump::EncodeFrame, encoder_.get(), | 143 base::Bind(&VideoFramePump::EncodeFrame, encoder_.get(), |
| 140 base::Passed(base::WrapUnique(frame)), | 144 base::Passed(&frame), |
| 141 base::Passed(&captured_frame_timestamps_)), | 145 base::Passed(&captured_frame_timestamps_)), |
| 142 base::Bind(&VideoFramePump::OnFrameEncoded, weak_factory_.GetWeakPtr())); | 146 base::Bind(&VideoFramePump::OnFrameEncoded, weak_factory_.GetWeakPtr())); |
| 143 } | 147 } |
| 144 | 148 |
| 145 void VideoFramePump::CaptureNextFrame() { | 149 void VideoFramePump::CaptureNextFrame() { |
| 146 DCHECK(thread_checker_.CalledOnValidThread()); | 150 DCHECK(thread_checker_.CalledOnValidThread()); |
| 147 | 151 |
| 148 // |next_frame_timestamps_| is not set if no input events were received since | 152 // |next_frame_timestamps_| is not set if no input events were received since |
| 149 // the previous frame. In that case create FrameTimestamps instance without | 153 // the previous frame. In that case create FrameTimestamps instance without |
| 150 // setting |input_event_client_timestamp| and |input_event_received_time|. | 154 // setting |input_event_client_timestamp| and |input_event_received_time|. |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 265 } | 269 } |
| 266 | 270 |
| 267 void VideoFramePump::OnKeepAlivePacketSent() { | 271 void VideoFramePump::OnKeepAlivePacketSent() { |
| 268 DCHECK(thread_checker_.CalledOnValidThread()); | 272 DCHECK(thread_checker_.CalledOnValidThread()); |
| 269 | 273 |
| 270 keep_alive_timer_.Reset(); | 274 keep_alive_timer_.Reset(); |
| 271 } | 275 } |
| 272 | 276 |
| 273 } // namespace protocol | 277 } // namespace protocol |
| 274 } // namespace remoting | 278 } // namespace remoting |
| OLD | NEW |