avcodec/libvpxenc: Only search for side data when intending to use it

Also rewrite the code so that a variable that is only used
depending upon CONFIG_LIBVPX_VP9_ENCODER is not declared
outside of the #if block.
(The variable was declared with av_uninit, but it should have been
av_unused, as the former does not work for all compilers.)

Reviewed-by: James Zern <jzern@google.com>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
This commit is contained in:
Andreas Rheinhardt 2024-03-26 16:26:13 +01:00
parent e465cebfee
commit 1093b40218
1 changed files with 10 additions and 9 deletions

View File

@ -357,20 +357,21 @@ static int frame_data_submit(AVCodecContext *avctx, AVFifo *fifo,
const struct vpx_codec_enc_cfg *enccfg = ctx->encoder.config.enc; const struct vpx_codec_enc_cfg *enccfg = ctx->encoder.config.enc;
FrameData fd = { .pts = frame->pts }; FrameData fd = { .pts = frame->pts };
AVFrameSideData *av_uninit(sd);
int ret; int ret;
#if CONFIG_LIBVPX_VP9_ENCODER #if CONFIG_LIBVPX_VP9_ENCODER
if (avctx->codec_id == AV_CODEC_ID_VP9 &&
// Keep HDR10+ if it has bit depth higher than 8 and // Keep HDR10+ if it has bit depth higher than 8 and
// it has PQ trc (SMPTE2084). // it has PQ trc (SMPTE2084).
sd = av_frame_get_side_data(frame, AV_FRAME_DATA_DYNAMIC_HDR_PLUS);
if (avctx->codec_id == AV_CODEC_ID_VP9 && sd &&
enccfg->g_bit_depth > 8 && avctx->color_trc == AVCOL_TRC_SMPTE2084) { enccfg->g_bit_depth > 8 && avctx->color_trc == AVCOL_TRC_SMPTE2084) {
const AVFrameSideData *sd = av_frame_get_side_data(frame, AV_FRAME_DATA_DYNAMIC_HDR_PLUS);
if (sd) {
fd.hdr10_plus = av_buffer_ref(sd->buf); fd.hdr10_plus = av_buffer_ref(sd->buf);
if (!fd.hdr10_plus) if (!fd.hdr10_plus)
return AVERROR(ENOMEM); return AVERROR(ENOMEM);
} }
}
#endif #endif
fd.duration = frame->duration; fd.duration = frame->duration;