* [FFmpeg-devel] [PATCH v4 1/2] lavc: add HWACCEL_CAP_RESET_WITHOUT_UNINIT capacity for hwaccel @ 2022-11-08 11:45 Fei Wang 2022-11-08 11:45 ` [FFmpeg-devel] [PATCH v4 2/2] lavc/vaapi_decode: add support for HWACCEL_CAP_RESET_WITHOUT_UNINIT Fei Wang 0 siblings, 1 reply; 4+ messages in thread From: Fei Wang @ 2022-11-08 11:45 UTC (permalink / raw) To: ffmpeg-devel; +Cc: Fei Wang 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@intel.com> --- 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 { /** -- 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-request@ffmpeg.org with subject "unsubscribe". ^ permalink raw reply [flat|nested] 4+ messages in thread
* [FFmpeg-devel] [PATCH v4 2/2] lavc/vaapi_decode: add support for HWACCEL_CAP_RESET_WITHOUT_UNINIT 2022-11-08 11:45 [FFmpeg-devel] [PATCH v4 1/2] lavc: add HWACCEL_CAP_RESET_WITHOUT_UNINIT capacity for hwaccel Fei Wang @ 2022-11-08 11:45 ` Fei Wang 2022-11-11 3:45 ` Xiang, Haihao 0 siblings, 1 reply; 4+ messages in thread From: Fei Wang @ 2022-11-08 11:45 UTC (permalink / raw) To: ffmpeg-devel; +Cc: Fei Wang 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 <fei.w.wang@intel.com> --- 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, - &ctx->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, - &ctx->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, + &ctx->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, + &ctx->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-request@ffmpeg.org with subject "unsubscribe". ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [FFmpeg-devel] [PATCH v4 2/2] lavc/vaapi_decode: add support for HWACCEL_CAP_RESET_WITHOUT_UNINIT 2022-11-08 11:45 ` [FFmpeg-devel] [PATCH v4 2/2] lavc/vaapi_decode: add support for HWACCEL_CAP_RESET_WITHOUT_UNINIT Fei Wang @ 2022-11-11 3:45 ` Xiang, Haihao 2022-11-14 1:19 ` Wang, Fei W 0 siblings, 1 reply; 4+ messages in thread From: Xiang, Haihao @ 2022-11-11 3:45 UTC (permalink / raw) To: ffmpeg-devel; +Cc: Wang, Fei W 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 <fei.w.wang@intel.com> > --- > 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, > - &ctx->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, > - &ctx->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, > + &ctx->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, > + &ctx->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-request@ffmpeg.org with subject "unsubscribe". ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [FFmpeg-devel] [PATCH v4 2/2] lavc/vaapi_decode: add support for HWACCEL_CAP_RESET_WITHOUT_UNINIT 2022-11-11 3:45 ` Xiang, Haihao @ 2022-11-14 1:19 ` Wang, Fei W 0 siblings, 0 replies; 4+ messages in thread From: Wang, Fei W @ 2022-11-14 1:19 UTC (permalink / raw) To: ffmpeg-devel, Xiang, Haihao On Fri, 2022-11-11 at 03:45 +0000, 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 <fei.w.wang@intel.com> > > --- > > 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, > > - &ctx->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, > > - &ctx->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, > > + &ctx->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, > > + &ctx->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-request@ffmpeg.org with subject "unsubscribe". ^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2022-11-14 1:19 UTC | newest] Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2022-11-08 11:45 [FFmpeg-devel] [PATCH v4 1/2] lavc: add HWACCEL_CAP_RESET_WITHOUT_UNINIT capacity for hwaccel Fei Wang 2022-11-08 11:45 ` [FFmpeg-devel] [PATCH v4 2/2] lavc/vaapi_decode: add support for HWACCEL_CAP_RESET_WITHOUT_UNINIT Fei Wang 2022-11-11 3:45 ` Xiang, Haihao 2022-11-14 1:19 ` Wang, Fei W
Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel This inbox may be cloned and mirrored by anyone: git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git # If you have public-inbox 1.1+ installed, you may # initialize and index your mirror using the following commands: public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \ ffmpegdev@gitmailbox.com public-inbox-index ffmpegdev Example config snippet for mirrors. AGPL code for this site: git clone https://public-inbox.org/public-inbox.git