From: Fei Wang <fei.w.wang-at-intel.com@ffmpeg.org> To: ffmpeg-devel@ffmpeg.org Cc: Fei Wang <fei.w.wang@intel.com>, Linjie Fu <linjie.fu@intel.com> Subject: [FFmpeg-devel] [PATCH v2 2/3] lavc/decode: Add internal surface re-allocate method for hwaccel Date: Thu, 18 Aug 2022 10:25:06 +0800 Message-ID: <20220818022507.1780806-2-fei.w.wang@intel.com> (raw) In-Reply-To: <20220818022507.1780806-1-fei.w.wang@intel.com> From: Linjie Fu <linjie.fu@intel.com> Add HWACCEL_CAP_INTERNAL_ALLOC flag to indicate hwaccels are able to re-allocate surface internally through ff_decode_get_hw_frames_ctx. So that hwaccels don't need to reinitialize all hw configs when decode parameters change. Signed-off-by: Linjie Fu <linjie.fu@intel.com> Signed-off-by: Fei Wang <fei.w.wang@intel.com> --- libavcodec/decode.c | 36 ++++++++++++++++++++++++++++++++++++ libavcodec/hwconfig.h | 1 + 2 files changed, 37 insertions(+) diff --git a/libavcodec/decode.c b/libavcodec/decode.c index 3b69426c09..6a22627036 100644 --- a/libavcodec/decode.c +++ b/libavcodec/decode.c @@ -1174,6 +1174,33 @@ static const AVCodecHWConfigInternal *get_hw_config(AVCodecContext *avctx, enum return NULL; } +static int hwaccel_realloc_surface(AVCodecContext *avctx) +{ + const AVCodecHWConfigInternal *hw_config; + int ret; + + if (avctx->hw_frames_ctx) + av_buffer_unref(&avctx->hw_frames_ctx); + + hw_config = get_hw_config(avctx, avctx->pix_fmt); + if (!hw_config) + return AV_PIX_FMT_NONE; + + if (avctx->hw_device_ctx && + hw_config->public.methods & AV_CODEC_HW_CONFIG_METHOD_HW_DEVICE_CTX) { + const AVHWDeviceContext *device_ctx = + (AVHWDeviceContext*)avctx->hw_device_ctx->data; + ret = ff_decode_get_hw_frames_ctx(avctx, device_ctx->type); + if (ret < 0) { + av_log(avctx, AV_LOG_WARNING, "Failed to re-allocate hwaccel surface internally.\n"); + return AV_PIX_FMT_NONE; + } + } else + return AV_PIX_FMT_NONE; + + return hw_config->public.pix_fmt; +} + int ff_get_format(AVCodecContext *avctx, const enum AVPixelFormat *fmt) { const AVPixFmtDescriptor *desc; @@ -1200,6 +1227,15 @@ int ff_get_format(AVCodecContext *avctx, const enum AVPixelFormat *fmt) return AV_PIX_FMT_NONE; for (;;) { + if (avctx->internal->hwaccel_priv_data && + avctx->hwaccel->caps_internal & HWACCEL_CAP_INTERNAL_ALLOC) { + err = hwaccel_realloc_surface(avctx); + if (err < 0) + av_log(avctx, AV_LOG_WARNING, "Try to re-initialize all.\n"); + else + return err; + } + // Remove the previous hwaccel, if there was one. hwaccel_uninit(avctx); diff --git a/libavcodec/hwconfig.h b/libavcodec/hwconfig.h index 721424912c..7405c66c07 100644 --- a/libavcodec/hwconfig.h +++ b/libavcodec/hwconfig.h @@ -24,6 +24,7 @@ #define HWACCEL_CAP_ASYNC_SAFE (1 << 0) +#define HWACCEL_CAP_INTERNAL_ALLOC (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".
next prev parent reply other threads:[~2022-08-18 2:25 UTC|newest] Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top 2022-08-18 2:25 [FFmpeg-devel] [PATCH v2 1/3] lavc/decode: Warp get_hw_config function Fei Wang 2022-08-18 2:25 ` Fei Wang [this message] 2022-08-18 2:25 ` [FFmpeg-devel] [PATCH v2 3/3] lavc/vaapi_vp9: add surface internal re-allocation capability Fei Wang
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20220818022507.1780806-2-fei.w.wang@intel.com \ --to=fei.w.wang-at-intel.com@ffmpeg.org \ --cc=fei.w.wang@intel.com \ --cc=ffmpeg-devel@ffmpeg.org \ --cc=linjie.fu@intel.com \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
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