From 4b5caee6b1cb91d918d28da6a9aae47718339cad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Erik=20Spr=C3=A5ng?= Date: Tue, 18 Jan 2022 19:20:40 +0100 Subject: [PATCH] VP9 encoder: mark only base spatial layer as keyframe MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Bug: webrtc:13576 Change-Id: Ia4173d3aa2c8e546a818eccc5d6c09d1150dcaf4 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/247188 Reviewed-by: Danil Chapovalov Commit-Queue: Erik Språng Cr-Commit-Position: refs/heads/main@{#35736} --- .../codecs/vp9/libvpx_vp9_encoder.cc | 26 ++++++++++--------- 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/modules/video_coding/codecs/vp9/libvpx_vp9_encoder.cc b/modules/video_coding/codecs/vp9/libvpx_vp9_encoder.cc index 75c2f16961..0c3196c854 100644 --- a/modules/video_coding/codecs/vp9/libvpx_vp9_encoder.cc +++ b/modules/video_coding/codecs/vp9/libvpx_vp9_encoder.cc @@ -1634,18 +1634,6 @@ void LibvpxVp9Encoder::GetEncodedLayerFrame(const vpx_codec_cx_pkt* pkt) { encoded_image_.SetEncodedData(EncodedImageBuffer::Create( static_cast(pkt->data.frame.buf), pkt->data.frame.sz)); - const bool is_key_frame = - (pkt->data.frame.flags & VPX_FRAME_IS_KEY) ? true : false; - // Ensure encoder issued key frame on request. - RTC_DCHECK(is_key_frame || !force_key_frame_); - - // Check if encoded frame is a key frame. - encoded_image_._frameType = VideoFrameType::kVideoFrameDelta; - if (is_key_frame) { - encoded_image_._frameType = VideoFrameType::kVideoFrameKey; - force_key_frame_ = false; - } - codec_specific_ = {}; absl::optional spatial_index; if (!PopulateCodecSpecific(&codec_specific_, &spatial_index, *pkt, @@ -1656,6 +1644,20 @@ void LibvpxVp9Encoder::GetEncodedLayerFrame(const vpx_codec_cx_pkt* pkt) { } encoded_image_.SetSpatialIndex(spatial_index); + const bool is_key_frame = + ((pkt->data.frame.flags & VPX_FRAME_IS_KEY) ? true : false) && + !codec_specific_.codecSpecific.VP9.inter_layer_predicted; + + // Ensure encoder issued key frame on request. + RTC_DCHECK(is_key_frame || !force_key_frame_); + + // Check if encoded frame is a key frame. + encoded_image_._frameType = VideoFrameType::kVideoFrameDelta; + if (is_key_frame) { + encoded_image_._frameType = VideoFrameType::kVideoFrameKey; + force_key_frame_ = false; + } + UpdateReferenceBuffers(*pkt, pics_since_key_); TRACE_COUNTER1("webrtc", "EncodedFrameSize", encoded_image_.size());