Re: [FFmpeg-devel] [PATCH v4 2/2] lavc/vaapi_decode: add support for HWACCEL_CAP_RESET_WITHOUT_UNINIT
On Fri, 2022-11-11 at 03:45 +, Xiang, Haihao wrote: > On Tue, 2022-11-08 at 19:45 +0800, Fei Wang wrote: > > This can fix vp9 decode image corruption when the frame size is > > change, > > but the pervious frames still be referenced. > > > > Surfaces don't need to be bound to vaContext only after VAAPI > > 1.0.0: > > https://github.com/intel/libva/commit/492b692005ccd0d8da190209d5b3ae7b7825f4b8 > > > > Signed-off-by: Fei Wang > > --- > > libavcodec/vaapi_decode.c | 41 ++- > > > > libavcodec/vaapi_vp9.c| 4 > > 2 files changed, 27 insertions(+), 18 deletions(-) > > > > diff --git a/libavcodec/vaapi_decode.c b/libavcodec/vaapi_decode.c > > index 134f10eca5..618f3c3e0a 100644 > > --- a/libavcodec/vaapi_decode.c > > +++ b/libavcodec/vaapi_decode.c > > @@ -658,8 +658,10 @@ int ff_vaapi_decode_init(AVCodecContext > > *avctx) > > VAStatus vas; > > int err; > > > > -ctx->va_config = VA_INVALID_ID; > > -ctx->va_context = VA_INVALID_ID; > > +if (!ctx->va_config && !ctx->va_context) { > > +ctx->va_config = VA_INVALID_ID; > > +ctx->va_context = VA_INVALID_ID; > > +} > > 0 is valid for VA config and context, it is possible the underlying > driver > creates VA config and context with id 0. Fixed in V5. Thanks. Fei > > Thanks > Haihao > > > > > err = ff_decode_get_hw_frames_ctx(avctx, > > AV_HWDEVICE_TYPE_VAAPI); > > if (err < 0) > > @@ -670,24 +672,27 @@ int ff_vaapi_decode_init(AVCodecContext > > *avctx) > > ctx->device = ctx->frames->device_ctx; > > ctx->hwctx = ctx->device->hwctx; > > > > -err = vaapi_decode_make_config(avctx, ctx->frames->device_ref, > > - >va_config, NULL); > > -if (err) > > -goto fail; > > - > > -vas = vaCreateContext(ctx->hwctx->display, ctx->va_config, > > - avctx->coded_width, avctx->coded_height, > > - VA_PROGRESSIVE, > > - ctx->hwfc->surface_ids, > > - ctx->hwfc->nb_surfaces, > > - >va_context); > > -if (vas != VA_STATUS_SUCCESS) { > > -av_log(avctx, AV_LOG_ERROR, "Failed to create decode " > > - "context: %d (%s).\n", vas, vaErrorStr(vas)); > > -err = AVERROR(EIO); > > -goto fail; > > +if (ctx->va_config == VA_INVALID_ID) { > > +err = vaapi_decode_make_config(avctx, ctx->frames- > > >device_ref, > > + >va_config, NULL); > > +if (err) > > +goto fail; > > } > > > > +if (ctx->va_context == VA_INVALID_ID) { > > +vas = vaCreateContext(ctx->hwctx->display, ctx->va_config, > > + avctx->coded_width, avctx- > > >coded_height, > > + VA_PROGRESSIVE, > > + ctx->hwfc->surface_ids, > > + ctx->hwfc->nb_surfaces, > > + >va_context); > > +if (vas != VA_STATUS_SUCCESS) { > > +av_log(avctx, AV_LOG_ERROR, "Failed to create decode " > > + "context: %d (%s).\n", vas, vaErrorStr(vas)); > > +err = AVERROR(EIO); > > +goto fail; > > +} > > +} > > av_log(avctx, AV_LOG_DEBUG, "Decode context initialised: " > > "%#x/%#x.\n", ctx->va_config, ctx->va_context); > > > > diff --git a/libavcodec/vaapi_vp9.c b/libavcodec/vaapi_vp9.c > > index 776382f683..245b7a1b3a 100644 > > --- a/libavcodec/vaapi_vp9.c > > +++ b/libavcodec/vaapi_vp9.c > > @@ -181,5 +181,9 @@ const AVHWAccel ff_vp9_vaapi_hwaccel = { > > .uninit = ff_vaapi_decode_uninit, > > .frame_params = ff_vaapi_common_frame_params, > > .priv_data_size = sizeof(VAAPIDecodeContext), > > +#if VA_CHECK_VERSION(1, 0, 0) > > +.caps_internal= HWACCEL_CAP_ASYNC_SAFE | > > HWACCEL_CAP_RESET_WITHOUT_UNINIT, > > +#else > > .caps_internal= HWACCEL_CAP_ASYNC_SAFE, > > +#endif > > }; ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
Re: [FFmpeg-devel] [PATCH v4 2/2] lavc/vaapi_decode: add support for HWACCEL_CAP_RESET_WITHOUT_UNINIT
On Tue, 2022-11-08 at 19:45 +0800, Fei Wang wrote: > This can fix vp9 decode image corruption when the frame size is change, > but the pervious frames still be referenced. > > Surfaces don't need to be bound to vaContext only after VAAPI 1.0.0: > https://github.com/intel/libva/commit/492b692005ccd0d8da190209d5b3ae7b7825f4b8 > > Signed-off-by: Fei Wang > --- > libavcodec/vaapi_decode.c | 41 ++- > libavcodec/vaapi_vp9.c| 4 > 2 files changed, 27 insertions(+), 18 deletions(-) > > diff --git a/libavcodec/vaapi_decode.c b/libavcodec/vaapi_decode.c > index 134f10eca5..618f3c3e0a 100644 > --- a/libavcodec/vaapi_decode.c > +++ b/libavcodec/vaapi_decode.c > @@ -658,8 +658,10 @@ int ff_vaapi_decode_init(AVCodecContext *avctx) > VAStatus vas; > int err; > > -ctx->va_config = VA_INVALID_ID; > -ctx->va_context = VA_INVALID_ID; > +if (!ctx->va_config && !ctx->va_context) { > +ctx->va_config = VA_INVALID_ID; > +ctx->va_context = VA_INVALID_ID; > +} 0 is valid for VA config and context, it is possible the underlying driver creates VA config and context with id 0. Thanks Haihao > > err = ff_decode_get_hw_frames_ctx(avctx, AV_HWDEVICE_TYPE_VAAPI); > if (err < 0) > @@ -670,24 +672,27 @@ int ff_vaapi_decode_init(AVCodecContext *avctx) > ctx->device = ctx->frames->device_ctx; > ctx->hwctx = ctx->device->hwctx; > > -err = vaapi_decode_make_config(avctx, ctx->frames->device_ref, > - >va_config, NULL); > -if (err) > -goto fail; > - > -vas = vaCreateContext(ctx->hwctx->display, ctx->va_config, > - avctx->coded_width, avctx->coded_height, > - VA_PROGRESSIVE, > - ctx->hwfc->surface_ids, > - ctx->hwfc->nb_surfaces, > - >va_context); > -if (vas != VA_STATUS_SUCCESS) { > -av_log(avctx, AV_LOG_ERROR, "Failed to create decode " > - "context: %d (%s).\n", vas, vaErrorStr(vas)); > -err = AVERROR(EIO); > -goto fail; > +if (ctx->va_config == VA_INVALID_ID) { > +err = vaapi_decode_make_config(avctx, ctx->frames->device_ref, > + >va_config, NULL); > +if (err) > +goto fail; > } > > +if (ctx->va_context == VA_INVALID_ID) { > +vas = vaCreateContext(ctx->hwctx->display, ctx->va_config, > + avctx->coded_width, avctx->coded_height, > + VA_PROGRESSIVE, > + ctx->hwfc->surface_ids, > + ctx->hwfc->nb_surfaces, > + >va_context); > +if (vas != VA_STATUS_SUCCESS) { > +av_log(avctx, AV_LOG_ERROR, "Failed to create decode " > + "context: %d (%s).\n", vas, vaErrorStr(vas)); > +err = AVERROR(EIO); > +goto fail; > +} > +} > av_log(avctx, AV_LOG_DEBUG, "Decode context initialised: " > "%#x/%#x.\n", ctx->va_config, ctx->va_context); > > diff --git a/libavcodec/vaapi_vp9.c b/libavcodec/vaapi_vp9.c > index 776382f683..245b7a1b3a 100644 > --- a/libavcodec/vaapi_vp9.c > +++ b/libavcodec/vaapi_vp9.c > @@ -181,5 +181,9 @@ const AVHWAccel ff_vp9_vaapi_hwaccel = { > .uninit = ff_vaapi_decode_uninit, > .frame_params = ff_vaapi_common_frame_params, > .priv_data_size = sizeof(VAAPIDecodeContext), > +#if VA_CHECK_VERSION(1, 0, 0) > +.caps_internal= HWACCEL_CAP_ASYNC_SAFE | > HWACCEL_CAP_RESET_WITHOUT_UNINIT, > +#else > .caps_internal= HWACCEL_CAP_ASYNC_SAFE, > +#endif > }; ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
[FFmpeg-devel] [PATCH v4 2/2] lavc/vaapi_decode: add support for HWACCEL_CAP_RESET_WITHOUT_UNINIT
This can fix vp9 decode image corruption when the frame size is change, but the pervious frames still be referenced. Surfaces don't need to be bound to vaContext only after VAAPI 1.0.0: https://github.com/intel/libva/commit/492b692005ccd0d8da190209d5b3ae7b7825f4b8 Signed-off-by: Fei Wang --- libavcodec/vaapi_decode.c | 41 ++- libavcodec/vaapi_vp9.c| 4 2 files changed, 27 insertions(+), 18 deletions(-) diff --git a/libavcodec/vaapi_decode.c b/libavcodec/vaapi_decode.c index 134f10eca5..618f3c3e0a 100644 --- a/libavcodec/vaapi_decode.c +++ b/libavcodec/vaapi_decode.c @@ -658,8 +658,10 @@ int ff_vaapi_decode_init(AVCodecContext *avctx) VAStatus vas; int err; -ctx->va_config = VA_INVALID_ID; -ctx->va_context = VA_INVALID_ID; +if (!ctx->va_config && !ctx->va_context) { +ctx->va_config = VA_INVALID_ID; +ctx->va_context = VA_INVALID_ID; +} err = ff_decode_get_hw_frames_ctx(avctx, AV_HWDEVICE_TYPE_VAAPI); if (err < 0) @@ -670,24 +672,27 @@ int ff_vaapi_decode_init(AVCodecContext *avctx) ctx->device = ctx->frames->device_ctx; ctx->hwctx = ctx->device->hwctx; -err = vaapi_decode_make_config(avctx, ctx->frames->device_ref, - >va_config, NULL); -if (err) -goto fail; - -vas = vaCreateContext(ctx->hwctx->display, ctx->va_config, - avctx->coded_width, avctx->coded_height, - VA_PROGRESSIVE, - ctx->hwfc->surface_ids, - ctx->hwfc->nb_surfaces, - >va_context); -if (vas != VA_STATUS_SUCCESS) { -av_log(avctx, AV_LOG_ERROR, "Failed to create decode " - "context: %d (%s).\n", vas, vaErrorStr(vas)); -err = AVERROR(EIO); -goto fail; +if (ctx->va_config == VA_INVALID_ID) { +err = vaapi_decode_make_config(avctx, ctx->frames->device_ref, + >va_config, NULL); +if (err) +goto fail; } +if (ctx->va_context == VA_INVALID_ID) { +vas = vaCreateContext(ctx->hwctx->display, ctx->va_config, + avctx->coded_width, avctx->coded_height, + VA_PROGRESSIVE, + ctx->hwfc->surface_ids, + ctx->hwfc->nb_surfaces, + >va_context); +if (vas != VA_STATUS_SUCCESS) { +av_log(avctx, AV_LOG_ERROR, "Failed to create decode " + "context: %d (%s).\n", vas, vaErrorStr(vas)); +err = AVERROR(EIO); +goto fail; +} +} av_log(avctx, AV_LOG_DEBUG, "Decode context initialised: " "%#x/%#x.\n", ctx->va_config, ctx->va_context); diff --git a/libavcodec/vaapi_vp9.c b/libavcodec/vaapi_vp9.c index 776382f683..245b7a1b3a 100644 --- a/libavcodec/vaapi_vp9.c +++ b/libavcodec/vaapi_vp9.c @@ -181,5 +181,9 @@ const AVHWAccel ff_vp9_vaapi_hwaccel = { .uninit = ff_vaapi_decode_uninit, .frame_params = ff_vaapi_common_frame_params, .priv_data_size = sizeof(VAAPIDecodeContext), +#if VA_CHECK_VERSION(1, 0, 0) +.caps_internal= HWACCEL_CAP_ASYNC_SAFE | HWACCEL_CAP_RESET_WITHOUT_UNINIT, +#else .caps_internal= HWACCEL_CAP_ASYNC_SAFE, +#endif }; -- 2.25.1 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".