Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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_frame_scheduler_simple.h" | 5 #include "remoting/protocol/webrtc_frame_scheduler_simple.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "remoting/protocol/frame_stats.h" | 9 #include "remoting/protocol/frame_stats.h" |
| 10 #include "remoting/protocol/webrtc_dummy_video_encoder.h" | 10 #include "remoting/protocol/webrtc_dummy_video_encoder.h" |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 171 } | 171 } |
| 172 } | 172 } |
| 173 | 173 |
| 174 bool WebrtcFrameSchedulerSimple::OnFrameCaptured( | 174 bool WebrtcFrameSchedulerSimple::OnFrameCaptured( |
| 175 const webrtc::DesktopFrame* frame, | 175 const webrtc::DesktopFrame* frame, |
| 176 WebrtcVideoEncoder::FrameParams* params_out) { | 176 WebrtcVideoEncoder::FrameParams* params_out) { |
| 177 DCHECK(thread_checker_.CalledOnValidThread()); | 177 DCHECK(thread_checker_.CalledOnValidThread()); |
| 178 | 178 |
| 179 base::TimeTicks now = base::TimeTicks::Now(); | 179 base::TimeTicks now = base::TimeTicks::Now(); |
| 180 | 180 |
| 181 if ((!frame || frame->updated_region().is_empty()) && !top_off_is_active_ && | 181 if ((!frame || frame->updated_region().is_empty())) { |
| 182 !key_frame_request_) { | 182 // If we've failed to capture a frame or captured an empty frame we still |
| 183 frame_pending_ = false; | 183 // need to encode and send the previous frame when top-off is active or a |
| 184 ScheduleNextFrame(now); | 184 // key-frame was requested. But it makes sense only when we have a frame to |
| 185 return false; | 185 // send, i.e. there is nothing to send if first capture request failed. |
| 186 bool resend_last_frame = | |
| 187 captured_first_frame_ && (top_off_is_active_ || key_frame_request_); | |
|
Jamie
2017/03/21 18:33:36
Given the name of this variable, I would expect to
Sergey Ulanov
2017/03/21 19:40:26
The encoder keeps current frame internally (in YUV
| |
| 188 if (!resend_last_frame) { | |
| 189 frame_pending_ = false; | |
| 190 ScheduleNextFrame(now); | |
| 191 return false; | |
| 192 } | |
| 186 } | 193 } |
| 187 | 194 |
| 188 if (frame) { | 195 if (frame) { |
| 196 captured_first_frame_ = true; | |
| 189 encoder_bitrate_.SetFrameSize(frame->size()); | 197 encoder_bitrate_.SetFrameSize(frame->size()); |
| 190 } | 198 } |
| 191 | 199 |
| 192 params_out->bitrate_kbps = encoder_bitrate_.GetTargetBitrateKbps(); | 200 params_out->bitrate_kbps = encoder_bitrate_.GetTargetBitrateKbps(); |
| 193 params_out->duration = kTargetFrameInterval; | 201 params_out->duration = kTargetFrameInterval; |
| 194 params_out->key_frame = key_frame_request_; | 202 params_out->key_frame = key_frame_request_; |
| 195 key_frame_request_ = false; | 203 key_frame_request_ = false; |
| 196 | 204 |
| 197 params_out->vpx_min_quantizer = 10; | 205 params_out->vpx_min_quantizer = 10; |
| 198 | 206 |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 296 void WebrtcFrameSchedulerSimple::CaptureNextFrame() { | 304 void WebrtcFrameSchedulerSimple::CaptureNextFrame() { |
| 297 DCHECK(thread_checker_.CalledOnValidThread()); | 305 DCHECK(thread_checker_.CalledOnValidThread()); |
| 298 DCHECK(!frame_pending_); | 306 DCHECK(!frame_pending_); |
| 299 last_capture_started_time_ = base::TimeTicks::Now(); | 307 last_capture_started_time_ = base::TimeTicks::Now(); |
| 300 frame_pending_ = true; | 308 frame_pending_ = true; |
| 301 capture_callback_.Run(); | 309 capture_callback_.Run(); |
| 302 } | 310 } |
| 303 | 311 |
| 304 } // namespace protocol | 312 } // namespace protocol |
| 305 } // namespace remoting | 313 } // namespace remoting |
| OLD | NEW |