From e4574d306f1b5fdbe5343147ef9ef72b1e25c680 Mon Sep 17 00:00:00 2001 From: Ram Mohan M Date: Tue, 3 Oct 2023 14:33:24 +0530 Subject: [PATCH] libavcenc: increment picture count only on valid inputs If the encoder receives inputs that are empty or frames that have to be skipped due to frame rate pull down, do not increment picture count. Bug: oss-fuzz-62827 Test: ./avc-enc-fuzzer --- encoder/ih264e_encode.c | 2 +- encoder/ih264e_utils.c | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/encoder/ih264e_encode.c b/encoder/ih264e_encode.c index 537ce26f..f5d14d22 100644 --- a/encoder/ih264e_encode.c +++ b/encoder/ih264e_encode.c @@ -527,7 +527,7 @@ WORD32 ih264e_encode(iv_obj_t *ps_codec_obj, void *pv_api_ip, void *pv_api_op) } /* curr pic cnt */ - ps_codec->i4_pic_cnt += 1; + ps_codec->i4_pic_cnt += 1; i4_rc_pre_enc_skip = 0; i4_rc_pre_enc_skip = ih264e_input_queue_update( diff --git a/encoder/ih264e_utils.c b/encoder/ih264e_utils.c index 7ea5f193..bf59781c 100644 --- a/encoder/ih264e_utils.c +++ b/encoder/ih264e_utils.c @@ -217,6 +217,7 @@ WORD32 ih264e_input_queue_update(codec_t *ps_codec, { ps_enc_buff->s_raw_buf.apv_bufs[0] = NULL; ps_enc_buff->u4_is_last = ps_ive_ip->u4_is_last; + ps_codec->i4_pic_cnt -= 1; return 0; } @@ -237,6 +238,7 @@ WORD32 ih264e_input_queue_update(codec_t *ps_codec, if (skip_src) { ps_enc_buff->u4_is_last = ps_ive_ip->u4_is_last; + ps_codec->i4_pic_cnt -= 1; return 1; } } @@ -297,8 +299,7 @@ WORD32 ih264e_input_queue_update(codec_t *ps_codec, /* Delay */ - if (ps_codec->i4_encode_api_call_cnt - < (WORD32)(ps_codec->s_cfg.u4_num_bframes)) + if (ps_codec->i4_pic_cnt < (WORD32)(ps_codec->s_cfg.u4_num_bframes)) { ps_enc_buff->s_raw_buf.apv_bufs[0] = NULL; ps_enc_buff->u4_is_last = 0;