[FFmpeg-devel] [PATCH v5 1/2] lavc: add HWACCEL_CAP_RESET_WITHOUT_UNINIT capacity for hwaccel
Xiang, Haihao
haihao.xiang at intel.com
Wed Nov 23 13:39:45 EET 2022
On Wed, 2022-11-23 at 11:29 +0000, Xiang, Haihao wrote:
> On Mon, 2022-11-14 at 09:16 +0800, Fei Wang wrote:
> > The capacity can avoid hwaccel being uninited when do the reset. It
> > provides the method for hwaccel if it still want to use the previous
> > initialized configuration after reset. And the configuration can be
> > updated in AVHWAccel.init() if needed.
> >
> > For example, when use vaapi vp9 decode dynamic resolution clips, need
> > to avoid changing vaContext in avctx->internal->hwaccel_priv_data if
> > current frame resolution change and it reference a pervious frame with
> > different resolution. Otherwise reference frame's information bound
> > in vaContext will be lost, then corrupt current frame.
> >
> > Signed-off-by: Fei Wang <fei.w.wang at intel.com>
> > ---
> > update:
> > 1. consider the case of va_config/va_context equal to 0.
> >
> > libavcodec/decode.c | 10 ++++++----
> > libavcodec/hwconfig.h | 7 +++++++
> > 2 files changed, 13 insertions(+), 4 deletions(-)
> >
> > diff --git a/libavcodec/decode.c b/libavcodec/decode.c
> > index 6be2d3d6ed..cfada048e8 100644
> > --- a/libavcodec/decode.c
> > +++ b/libavcodec/decode.c
> > @@ -1109,7 +1109,7 @@ static int hwaccel_init(AVCodecContext *avctx,
> > return AVERROR_PATCHWELCOME;
> > }
> >
> > - if (hwaccel->priv_data_size) {
> > + if (hwaccel->priv_data_size && !avctx->internal->hwaccel_priv_data) {
> > avctx->internal->hwaccel_priv_data =
> > av_mallocz(hwaccel->priv_data_size);
> > if (!avctx->internal->hwaccel_priv_data)
> > @@ -1134,10 +1134,12 @@ static int hwaccel_init(AVCodecContext *avctx,
> >
> > static void hwaccel_uninit(AVCodecContext *avctx)
> > {
> > - if (avctx->hwaccel && avctx->hwaccel->uninit)
> > - avctx->hwaccel->uninit(avctx);
> > + if (avctx->hwaccel && !(avctx->hwaccel->caps_internal &
> > HWACCEL_CAP_RESET_WITHOUT_UNINIT)) {
> > + if (avctx->hwaccel->uninit)
> > + avctx->hwaccel->uninit(avctx);
> >
> > - av_freep(&avctx->internal->hwaccel_priv_data);
> > + av_freep(&avctx->internal->hwaccel_priv_data);
> > + }
> >
> > avctx->hwaccel = NULL;
> >
> > diff --git a/libavcodec/hwconfig.h b/libavcodec/hwconfig.h
> > index 721424912c..5fb4e06d5f 100644
> > --- a/libavcodec/hwconfig.h
> > +++ b/libavcodec/hwconfig.h
> > @@ -25,6 +25,13 @@
> >
> > #define HWACCEL_CAP_ASYNC_SAFE (1 << 0)
> >
> > +/**
> > + * The hwaccel supports reset without calling back AVHWAccel.uninit()
> > + * and realloc avctx->internal->hwaccel_priv_data.
> > + *
> > + * New configuration can set up through AVHWAccel.init().
> > + */
> > +#define HWACCEL_CAP_RESET_WITHOUT_UNINIT (1 << 1)
> >
> > typedef struct AVCodecHWConfigInternal {
> > /**
>
> Patchset LGTM and works well for me. After applying this patchset, I can get
> the
> same md5 values when running the commands below for vp9 clips with resolution
> change.
>
> $ ffmpeg -c:v libvpx-vp9 -i input.webm -autoscale 0 -f md5 -
> $ ffmpeg -hwaccel vaapi -i input.webm -pix_fmt yuv420p -f md5 -
The command using vaapi is below:
$ ffmpeg -hwaccel vaapi -i input.webm -pix_fmt yuv420p -autoscale 0 -f md5 -
>
> Thanks
> Haihao
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel at ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-request at ffmpeg.org with subject "unsubscribe".
More information about the ffmpeg-devel
mailing list