From 0d70e372d6429d32633cbd388d768798a0da2d64 Mon Sep 17 00:00:00 2001 From: Sebastian Jansson Date: Tue, 17 Apr 2018 13:57:13 +0200 Subject: [PATCH] Avoids caching native buffers of captured frames. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This ensures that capture devices that relies on the frame being released to continue are not blocked by storing the pending frame. Bug: None Change-Id: If501bca4ab7bda5e0438d24e98d67df589ad6a6d Reviewed-on: https://webrtc-review.googlesource.com/70480 Reviewed-by: Sami Kalliomäki Reviewed-by: Erik Språng Commit-Queue: Sebastian Jansson Cr-Commit-Position: refs/heads/master@{#22907} --- video/video_stream_encoder.cc | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/video/video_stream_encoder.cc b/video/video_stream_encoder.cc index 7bb17b01c2..19d64392e3 100644 --- a/video/video_stream_encoder.cc +++ b/video/video_stream_encoder.cc @@ -774,18 +774,33 @@ void VideoStreamEncoder::MaybeEncodeVideoFrame(const VideoFrame& video_frame, stats_proxy_->OnInitialQualityResolutionAdaptDown(); } ++initial_rampup_; - pending_frame_ = video_frame; - pending_frame_post_time_us_ = time_when_posted_us; + // Storing references to a native buffer risks blocking frame capture. + if (video_frame.video_frame_buffer()->type() != + VideoFrameBuffer::Type::kNative) { + pending_frame_ = video_frame; + pending_frame_post_time_us_ = time_when_posted_us; + } else { + // Ensure that any previously stored frame is dropped. + pending_frame_.reset(); + } return; } initial_rampup_ = kMaxInitialFramedrop; if (EncoderPaused()) { - if (pending_frame_) + // Storing references to a native buffer risks blocking frame capture. + if (video_frame.video_frame_buffer()->type() != + VideoFrameBuffer::Type::kNative) { + if (pending_frame_) + TraceFrameDropStart(); + pending_frame_ = video_frame; + pending_frame_post_time_us_ = time_when_posted_us; + } else { + // Ensure that any previously stored frame is dropped. + pending_frame_.reset(); TraceFrameDropStart(); - pending_frame_ = video_frame; - pending_frame_post_time_us_ = time_when_posted_us; + } return; }