From 5080802f42c4a3ba5fad87eb149c4e7192744634 Mon Sep 17 00:00:00 2001 From: Andreas Rheinhardt Date: Mon, 24 Feb 2025 19:30:27 +0100 Subject: [PATCH 22/30] avcodec/h26[134]dec: Always report the buffer to be completely consumed It is pointless to try to report the true number because decode_simple_internal() always treats the buffer as completely consumed for video codecs anyway. (Apart from that: The h263dec code would report to only have consumed the header data in case decoding is aborted due to skip_frame which makes no sense.) Signed-off-by: Andreas Rheinhardt --- libavcodec/h261dec.c | 16 +--------------- libavcodec/h263dec.c | 31 ++++--------------------------- libavcodec/h264dec.c | 15 +-------------- 3 files changed, 6 insertions(+), 56 deletions(-) diff --git a/libavcodec/h261dec.c b/libavcodec/h261dec.c index 116f1d43b2..8a2c4d35b4 100644 --- a/libavcodec/h261dec.c +++ b/libavcodec/h261dec.c @@ -536,20 +536,6 @@ static int h261_decode_gob(H261DecContext *h) return -1; } -/** - * returns the number of bytes consumed for building the current frame - */ -static int get_consumed_bytes(MpegEncContext *s, int buf_size) -{ - int pos = get_bits_count(&s->gb) >> 3; - if (pos == 0) - pos = 1; // avoid infinite loops (i doubt that is needed but ...) - if (pos + 10 > buf_size) - pos = buf_size; // oops ;) - - return pos; -} - static int h261_decode_frame(AVCodecContext *avctx, AVFrame *pict, int *got_frame, AVPacket *avpkt) { @@ -615,7 +601,7 @@ static int h261_decode_frame(AVCodecContext *avctx, AVFrame *pict, *got_frame = 1; - return get_consumed_bytes(s, buf_size); + return buf_size; } const FFCodec ff_h261_decoder = { diff --git a/libavcodec/h263dec.c b/libavcodec/h263dec.c index 452641e408..fa1146f025 100644 --- a/libavcodec/h263dec.c +++ b/libavcodec/h263dec.c @@ -170,29 +170,6 @@ av_cold int ff_h263_decode_init(AVCodecContext *avctx) return 0; } -/** - * Return the number of bytes consumed for building the current frame. - */ -static int get_consumed_bytes(MpegEncContext *s, int buf_size) -{ - int pos = (get_bits_count(&s->gb) + 7) >> 3; - - if (s->divx_packed || s->avctx->hwaccel) { - /* We would have to scan through the whole buf to handle the weird - * reordering ... */ - return buf_size; - } else { - // avoid infinite loops (maybe not needed...) - if (pos == 0) - pos = 1; - // oops ;) - if (pos + 10 > buf_size) - pos = buf_size; - - return pos; - } -} - static int decode_slice(MpegEncContext *s) { const int part_mask = s->partitioned_frame @@ -523,7 +500,7 @@ retry: } } if (ret == FRAME_SKIPPED) - return get_consumed_bytes(s, buf_size); + return buf_size; /* skip if the header was thrashed */ if (ret < 0) { @@ -587,13 +564,13 @@ retry: /* skip B-frames if we don't have reference frames */ if (!s->last_pic.ptr && (s->pict_type == AV_PICTURE_TYPE_B || s->droppable)) - return get_consumed_bytes(s, buf_size); + return buf_size; if ((avctx->skip_frame >= AVDISCARD_NONREF && s->pict_type == AV_PICTURE_TYPE_B) || (avctx->skip_frame >= AVDISCARD_NONKEY && s->pict_type != AV_PICTURE_TYPE_I) || avctx->skip_frame >= AVDISCARD_ALL) - return get_consumed_bytes(s, buf_size); + return buf_size; if ((ret = ff_mpv_frame_start(s, avctx)) < 0) return ret; @@ -702,7 +679,7 @@ frame_end: if (slice_ret < 0 && (avctx->err_recognition & AV_EF_EXPLODE)) return slice_ret; else - return get_consumed_bytes(s, buf_size); + return buf_size; } static const AVCodecHWConfigInternal *const h263_hw_config_list[] = { diff --git a/libavcodec/h264dec.c b/libavcodec/h264dec.c index 45ebe2656d..fd401027d6 100644 --- a/libavcodec/h264dec.c +++ b/libavcodec/h264dec.c @@ -827,19 +827,6 @@ end: return (ret < 0) ? ret : buf_size; } -/** - * Return the number of bytes consumed for building the current frame. - */ -static int get_consumed_bytes(int pos, int buf_size) -{ - if (pos == 0) - pos = 1; // avoid infinite loops (I doubt that is needed but...) - if (pos + 10 > buf_size) - pos = buf_size; // oops ;) - - return pos; -} - static int h264_export_enc_params(AVFrame *f, const H264Picture *p) { AVVideoEncParams *par; @@ -1100,7 +1087,7 @@ static int h264_decode_frame(AVCodecContext *avctx, AVFrame *pict, ff_h264_unref_picture(&h->last_pic_for_ec); - return get_consumed_bytes(buf_index, buf_size); + return buf_size; } #define OFFSET(x) offsetof(H264Context, x) -- 2.45.2