From 0583c1f8d22e3d35611bc8165600282a071499d6 Mon Sep 17 00:00:00 2001 From: Boyuan Zhang Date: Tue, 2 May 2023 12:47:00 -0400 Subject: [PATCH] frontends/va: add default intra idr period Use default value in case h264->intra_idr_period is not set by app. Also to avoid dividing by 0 for later calculations in case it's not set. Signed-off-by: Boyuan Zhang Acked-by: Leo Liu Reviewed-by: Ruijing Dong Part-of: --- src/gallium/frontends/va/picture_h264_enc.c | 8 +++++--- src/gallium/include/pipe/p_video_state.h | 1 + 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/gallium/frontends/va/picture_h264_enc.c b/src/gallium/frontends/va/picture_h264_enc.c index df7164930c0..2377b7df1d6 100644 --- a/src/gallium/frontends/va/picture_h264_enc.c +++ b/src/gallium/frontends/va/picture_h264_enc.c @@ -186,10 +186,13 @@ vlVaHandleVAEncSequenceParameterBufferTypeH264(vlVaDriver *drv, vlVaContext *con getEncParamPresetH264(context); } - context->gop_coeff = ((1024 + h264->intra_idr_period - 1) / h264->intra_idr_period + 1) / 2 * 2; + context->desc.h264enc.intra_idr_period = + h264->intra_idr_period != 0 ? h264->intra_idr_period : PIPE_DEFAULT_INTRA_IDR_PERIOD; + context->gop_coeff = ((1024 + context->desc.h264enc.intra_idr_period - 1) / + context->desc.h264enc.intra_idr_period + 1) / 2 * 2; if (context->gop_coeff > VL_VA_ENC_GOP_COEFF) context->gop_coeff = VL_VA_ENC_GOP_COEFF; - context->desc.h264enc.gop_size = h264->intra_idr_period * context->gop_coeff; + context->desc.h264enc.gop_size = context->desc.h264enc.intra_idr_period * context->gop_coeff; context->desc.h264enc.seq.pic_order_cnt_type = h264->seq_fields.bits.pic_order_cnt_type; context->desc.h264enc.seq.vui_parameters_present_flag = h264->vui_parameters_present_flag; if (h264->vui_parameters_present_flag) { @@ -215,7 +218,6 @@ vlVaHandleVAEncSequenceParameterBufferTypeH264(vlVaDriver *drv, vlVaContext *con context->desc.h264enc.seq.time_scale = time_scale; context->desc.h264enc.rate_ctrl[0].frame_rate_num = time_scale / 2; context->desc.h264enc.rate_ctrl[0].frame_rate_den = num_units_in_tick; - context->desc.h264enc.intra_idr_period = h264->intra_idr_period; if (h264->frame_cropping_flag) { context->desc.h264enc.seq.enc_frame_cropping_flag = h264->frame_cropping_flag; diff --git a/src/gallium/include/pipe/p_video_state.h b/src/gallium/include/pipe/p_video_state.h index 1e29c062b72..29cf2b4f7ef 100644 --- a/src/gallium/include/pipe/p_video_state.h +++ b/src/gallium/include/pipe/p_video_state.h @@ -43,6 +43,7 @@ extern "C" { #define PIPE_H265_MAX_REFERENCES 15 #define PIPE_DEFAULT_FRAME_RATE_DEN 1 #define PIPE_DEFAULT_FRAME_RATE_NUM 30 +#define PIPE_DEFAULT_INTRA_IDR_PERIOD 30 #define PIPE_H2645_EXTENDED_SAR 255 #define PIPE_DEFAULT_DECODER_FEEDBACK_TIMEOUT_NS 1000000000