From 93223fa95389c60c015cfcee22784a1bf0fdb05b Mon Sep 17 00:00:00 2001 From: Lynne Date: Fri, 6 Jan 2023 03:32:56 +0100 Subject: [PATCH 65/72] 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 d105835d51..3cbb80bcb5 100644 --- a/libavcodec/av1dec.c +++ b/libavcodec/av1dec.c @@ -1228,6 +1228,9 @@ static void av1_decode_flush(AVCodecContext *avctx) s->raw_seq = NULL; ff_cbs_flush(s->cbc); + + if (avctx->hwaccel->flush) + avctx->hwaccel->flush(avctx); } #define OFFSET(x) offsetof(AV1DecContext, x) diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h index 6babfc7132..531998a78c 100644 --- a/libavcodec/avcodec.h +++ b/libavcodec/avcodec.h @@ -2214,6 +2214,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..995bf17a8f 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->flush) + avctx->hwaccel->flush(avctx); } static int get_last_needed_nal(H264Context *h) diff --git a/libavcodec/hevcdec.c b/libavcodec/hevcdec.c index 43cd963175..7c9b46240c 100644 --- a/libavcodec/hevcdec.c +++ b/libavcodec/hevcdec.c @@ -3682,6 +3682,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->flush) + avctx->hwaccel->flush(avctx); } #define OFFSET(x) offsetof(HEVCContext, x) diff --git a/libavcodec/vp8.c b/libavcodec/vp8.c index 4c23eb5672..b591b82ad1 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->flush) + avctx->hwaccel->flush(avctx); } static void vp8_decode_flush(AVCodecContext *avctx) diff --git a/libavcodec/vp9.c b/libavcodec/vp9.c index 4f345f18db..18c2b09f64 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->flush) + avctx->hwaccel->flush(avctx); } static av_cold int vp9_decode_init(AVCodecContext *avctx) -- 2.39.2