| 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/webrtc_video_stream.h" | 5 #include "remoting/protocol/webrtc_video_stream.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/single_thread_task_runner.h" | 8 #include "base/single_thread_task_runner.h" |
| 9 #include "base/task_runner_util.h" | 9 #include "base/task_runner_util.h" |
| 10 #include "base/threading/thread_task_runner_handle.h" | 10 #include "base/threading/thread_task_runner_handle.h" |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 136 | 136 |
| 137 void WebrtcVideoStream::OnCaptureResult( | 137 void WebrtcVideoStream::OnCaptureResult( |
| 138 webrtc::DesktopCapturer::Result result, | 138 webrtc::DesktopCapturer::Result result, |
| 139 std::unique_ptr<webrtc::DesktopFrame> frame) { | 139 std::unique_ptr<webrtc::DesktopFrame> frame) { |
| 140 DCHECK(thread_checker_.CalledOnValidThread()); | 140 DCHECK(thread_checker_.CalledOnValidThread()); |
| 141 | 141 |
| 142 captured_frame_timestamps_->capture_ended_time = base::TimeTicks::Now(); | 142 captured_frame_timestamps_->capture_ended_time = base::TimeTicks::Now(); |
| 143 captured_frame_timestamps_->capture_delay = | 143 captured_frame_timestamps_->capture_delay = |
| 144 base::TimeDelta::FromMilliseconds(frame ? frame->capture_time_ms() : 0); | 144 base::TimeDelta::FromMilliseconds(frame ? frame->capture_time_ms() : 0); |
| 145 | 145 |
| 146 if (!frame) { |
| 147 // Save event timestamps to be used for the next frame. |
| 148 next_frame_input_event_timestamps_ = |
| 149 captured_frame_timestamps_->input_event_timestamps; |
| 150 captured_frame_timestamps_->input_event_timestamps = InputEventTimestamps(); |
| 151 } |
| 152 |
| 146 WebrtcVideoEncoder::FrameParams frame_params; | 153 WebrtcVideoEncoder::FrameParams frame_params; |
| 147 if (!scheduler_->OnFrameCaptured(frame.get(), &frame_params)) { | 154 if (!scheduler_->OnFrameCaptured(frame.get(), &frame_params)) { |
| 148 return; | 155 return; |
| 149 } | 156 } |
| 150 | 157 |
| 151 // TODO(sergeyu): Handle ERROR_PERMANENT result here. | 158 // TODO(sergeyu): Handle ERROR_PERMANENT result here. |
| 152 if (frame) { | 159 if (frame) { |
| 153 webrtc::DesktopVector dpi = | 160 webrtc::DesktopVector dpi = |
| 154 frame->dpi().is_zero() ? webrtc::DesktopVector(kDefaultDpi, kDefaultDpi) | 161 frame->dpi().is_zero() ? webrtc::DesktopVector(kDefaultDpi, kDefaultDpi) |
| 155 : frame->dpi(); | 162 : frame->dpi(); |
| 156 | 163 |
| 157 if (!frame_size_.equals(frame->size()) || !frame_dpi_.equals(dpi)) { | 164 if (!frame_size_.equals(frame->size()) || !frame_dpi_.equals(dpi)) { |
| 158 frame_size_ = frame->size(); | 165 frame_size_ = frame->size(); |
| 159 frame_dpi_ = dpi; | 166 frame_dpi_ = dpi; |
| 160 if (observer_) | 167 if (observer_) |
| 161 observer_->OnVideoSizeChanged(this, frame_size_, frame_dpi_); | 168 observer_->OnVideoSizeChanged(this, frame_size_, frame_dpi_); |
| 162 } | 169 } |
| 163 } else { | |
| 164 // Save event timestamps to be used for the next frame. | |
| 165 next_frame_input_event_timestamps_ = | |
| 166 captured_frame_timestamps_->input_event_timestamps; | |
| 167 captured_frame_timestamps_->input_event_timestamps = InputEventTimestamps(); | |
| 168 } | 170 } |
| 169 | 171 |
| 170 base::PostTaskAndReplyWithResult( | 172 base::PostTaskAndReplyWithResult( |
| 171 encode_task_runner_.get(), FROM_HERE, | 173 encode_task_runner_.get(), FROM_HERE, |
| 172 base::Bind(&WebrtcVideoStream::EncodeFrame, encoder_.get(), | 174 base::Bind(&WebrtcVideoStream::EncodeFrame, encoder_.get(), |
| 173 base::Passed(std::move(frame)), frame_params, | 175 base::Passed(std::move(frame)), frame_params, |
| 174 base::Passed(std::move(captured_frame_timestamps_))), | 176 base::Passed(std::move(captured_frame_timestamps_))), |
| 175 base::Bind(&WebrtcVideoStream::OnFrameEncoded, | 177 base::Bind(&WebrtcVideoStream::OnFrameEncoded, |
| 176 weak_factory_.GetWeakPtr())); | 178 weak_factory_.GetWeakPtr())); |
| 177 } | 179 } |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 261 | 263 |
| 262 stats.encode_delay = frame.timestamps->encode_ended_time - | 264 stats.encode_delay = frame.timestamps->encode_ended_time - |
| 263 frame.timestamps->encode_started_time; | 265 frame.timestamps->encode_started_time; |
| 264 | 266 |
| 265 video_stats_dispatcher_.OnVideoFrameStats(result.frame_id, stats); | 267 video_stats_dispatcher_.OnVideoFrameStats(result.frame_id, stats); |
| 266 } | 268 } |
| 267 } | 269 } |
| 268 | 270 |
| 269 } // namespace protocol | 271 } // namespace protocol |
| 270 } // namespace remoting | 272 } // namespace remoting |
| OLD | NEW |