diff --git a/media_driver/linux/common/codec/ddi/media_ddi_encode_vp9.cpp b/media_driver/linux/common/codec/ddi/media_ddi_encode_vp9.cpp index 6a5cfadec4b..97bdc230145 100644 --- a/media_driver/linux/common/codec/ddi/media_ddi_encode_vp9.cpp +++ b/media_driver/linux/common/codec/ddi/media_ddi_encode_vp9.cpp @@ -93,6 +93,16 @@ VAStatus DdiEncodeVp9::EncodeInCodecHal(uint32_t numSlices) CODEC_VP9_ENCODE_SEQUENCE_PARAMS *seqParams = (PCODEC_VP9_ENCODE_SEQUENCE_PARAMS)(m_encodeCtx->pSeqParams); CODEC_VP9_ENCODE_PIC_PARAMS *vp9PicParam = (PCODEC_VP9_ENCODE_PIC_PARAMS)(m_encodeCtx->pPicParams); + if (!headerInsertFlag && + vp9PicParam->PicFlags.fields.frame_type == CODEC_VP9_KEY_FRAME && + m_isPreviousFrameKey) + { + vp9PicParam->PicFlags.fields.refresh_frame_context = 0; + } + + // Update the flag for the next frame + m_isPreviousFrameKey = (vp9PicParam->PicFlags.fields.frame_type == CODEC_VP9_KEY_FRAME); + EncoderParams encodeParams; MOS_ZeroMemory(&encodeParams, sizeof(EncoderParams)); encodeParams.ExecCodecFunction = m_encodeCtx->codecFunction; @@ -393,6 +403,8 @@ VAStatus DdiEncodeVp9::ContextInitialize(CodechalSetting *codecHalSettings) /* RT is used as the default target usage */ vp9TargetUsage = TARGETUSAGE_RT_SPEED; + m_isPreviousFrameKey = false; + return vaStatus; } diff --git a/media_driver/linux/common/codec/ddi/media_ddi_encode_vp9.h b/media_driver/linux/common/codec/ddi/media_ddi_encode_vp9.h index 597f606d293..54a99c8803d 100644 --- a/media_driver/linux/common/codec/ddi/media_ddi_encode_vp9.h +++ b/media_driver/linux/common/codec/ddi/media_ddi_encode_vp9.h @@ -325,4 +325,6 @@ class DdiEncodeVp9 : public DdiEncodeBase uint8_t vp9TargetUsage = 0; bool isSegParamsChanged = false; + + bool m_isPreviousFrameKey = false; }; diff --git a/media_softlet/linux/common/codec/ddi/enc/ddi_encode_vp9_specific.cpp b/media_softlet/linux/common/codec/ddi/enc/ddi_encode_vp9_specific.cpp index 7aabf6ffcff..56b0875379c 100644 --- a/media_softlet/linux/common/codec/ddi/enc/ddi_encode_vp9_specific.cpp +++ b/media_softlet/linux/common/codec/ddi/enc/ddi_encode_vp9_specific.cpp @@ -92,6 +92,16 @@ VAStatus DdiEncodeVp9::EncodeInCodecHal(uint32_t numSlices) CODEC_VP9_ENCODE_SEQUENCE_PARAMS *seqParams = (PCODEC_VP9_ENCODE_SEQUENCE_PARAMS)(m_encodeCtx->pSeqParams); CODEC_VP9_ENCODE_PIC_PARAMS *vp9PicParam = (PCODEC_VP9_ENCODE_PIC_PARAMS)(m_encodeCtx->pPicParams); + if (!headerInsertFlag && + vp9PicParam->PicFlags.fields.frame_type == CODEC_VP9_KEY_FRAME && + m_isPreviousFrameKey) + { + vp9PicParam->PicFlags.fields.refresh_frame_context = 0; + } + + // Update the flag for the next frame + m_isPreviousFrameKey = (vp9PicParam->PicFlags.fields.frame_type == CODEC_VP9_KEY_FRAME); + EncoderParams encodeParams; MOS_ZeroMemory(&encodeParams, sizeof(EncoderParams)); encodeParams.ExecCodecFunction = m_encodeCtx->codecFunction; @@ -404,6 +414,8 @@ VAStatus DdiEncodeVp9::ContextInitialize(CodechalSetting *codecHalSettings) /* RT is used as the default target usage */ vp9TargetUsage = TARGETUSAGE_RT_SPEED; + m_isPreviousFrameKey = false; + return vaStatus; } diff --git a/media_softlet/linux/common/codec/ddi/enc/ddi_encode_vp9_specific.h b/media_softlet/linux/common/codec/ddi/enc/ddi_encode_vp9_specific.h index dd7c35faf84..6b3dff5f067 100644 --- a/media_softlet/linux/common/codec/ddi/enc/ddi_encode_vp9_specific.h +++ b/media_softlet/linux/common/codec/ddi/enc/ddi_encode_vp9_specific.h @@ -357,6 +357,8 @@ class DdiEncodeVp9 : public encode::DdiEncodeBase bool isSegParamsChanged = false; + bool m_isPreviousFrameKey = false; + MEDIA_CLASS_DEFINE_END(encode__DdiEncodeVp9) };