From ad702a1fce9aaef80fcc72fcdd820f7ce96eb1b1 Mon Sep 17 00:00:00 2001 From: Lynne Date: Fri, 6 Jan 2023 03:32:56 +0100 Subject: [PATCH 26/92] avcodec: add AVHWAccel.flush callback --- libavcodec/av1dec.c | 3 +++ libavcodec/avcodec.h | 5 +++++ libavcodec/h264dec.c | 3 +++ libavcodec/hevcdec.c | 3 +++ libavcodec/vp8.c | 3 +++ libavcodec/vp9.c | 3 +++ 6 files changed, 20 insertions(+) diff --git a/libavcodec/av1dec.c b/libavcodec/av1dec.c index fb558b4900..6fa8b25435 100644 --- a/libavcodec/av1dec.c +++ b/libavcodec/av1dec.c @@ -1419,6 +1419,9 @@ static void av1_decode_flush(AVCodecContext *avctx) av_buffer_unref(&itut_t35.payload_ref); ff_cbs_flush(s->cbc); + + if (avctx->hwaccel && avctx->hwaccel->flush) + avctx->hwaccel->flush(avctx); } #define OFFSET(x) offsetof(AV1DecContext, x) diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h index b43e79a2a6..4ffd6faad2 100644 --- a/libavcodec/avcodec.h +++ b/libavcodec/avcodec.h @@ -2241,6 +2241,11 @@ typedef struct AVHWAccel { * @param data the per-frame hardware accelerator private data to be freed. */ void (*free_frame_priv)(AVCodecContext *avctx, void *data); + + /** + * Callback to flush the hwaccel state. + */ + void (*flush)(AVCodecContext *avctx); } AVHWAccel; /** diff --git a/libavcodec/h264dec.c b/libavcodec/h264dec.c index 2d691731c5..0aee724c0d 100644 --- a/libavcodec/h264dec.c +++ b/libavcodec/h264dec.c @@ -480,6 +480,9 @@ static void h264_decode_flush(AVCodecContext *avctx) ff_h264_free_tables(h); h->context_initialized = 0; + + if (avctx->hwaccel && avctx->hwaccel->flush) + avctx->hwaccel->flush(avctx); } static int get_last_needed_nal(H264Context *h) diff --git a/libavcodec/hevcdec.c b/libavcodec/hevcdec.c index 0230a41311..d120aaeae1 100644 --- a/libavcodec/hevcdec.c +++ b/libavcodec/hevcdec.c @@ -3704,6 +3704,9 @@ static void hevc_decode_flush(AVCodecContext *avctx) av_buffer_unref(&s->rpu_buf); s->max_ra = INT_MAX; s->eos = 1; + + if (avctx->hwaccel && avctx->hwaccel->flush) + avctx->hwaccel->flush(avctx); } #define OFFSET(x) offsetof(HEVCContext, x) diff --git a/libavcodec/vp8.c b/libavcodec/vp8.c index 4c23eb5672..86e7f432bc 100644 --- a/libavcodec/vp8.c +++ b/libavcodec/vp8.c @@ -167,6 +167,9 @@ static void vp8_decode_flush_impl(AVCodecContext *avctx, int free_mem) if (free_mem) free_buffers(s); + + if (avctx->hwaccel && avctx->hwaccel->flush) + avctx->hwaccel->flush(avctx); } static void vp8_decode_flush(AVCodecContext *avctx) diff --git a/libavcodec/vp9.c b/libavcodec/vp9.c index 4f345f18db..54fa08bbe5 100644 --- a/libavcodec/vp9.c +++ b/libavcodec/vp9.c @@ -1791,6 +1791,9 @@ static void vp9_decode_flush(AVCodecContext *avctx) vp9_frame_unref(avctx, &s->s.frames[i]); for (i = 0; i < 8; i++) ff_thread_release_ext_buffer(avctx, &s->s.refs[i]); + + if (avctx->hwaccel && avctx->hwaccel->flush) + avctx->hwaccel->flush(avctx); } static av_cold int vp9_decode_init(AVCodecContext *avctx) -- 2.39.2