From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTP id 1ACA4411BD for ; Thu, 18 Aug 2022 02:25:26 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 5EC3068B962; Thu, 18 Aug 2022 05:25:14 +0300 (EEST) Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id AD6C068B4EC for ; Thu, 18 Aug 2022 05:25:07 +0300 (EEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1660789512; x=1692325512; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=cnz/IapPr23Q7qVj+GyvcVMf86PNhDxImPsaqe4bw4M=; b=BLfObAi0OMHMj22cZUBNdwPHGd+Aez/S2YKSQB9aqcU00MNKChcw2OxS dOTXkHGLKe1sNQ3jhvUgeJGs7XUjrch1qyrVzQjk+ozs53SP5OT7JmAGC yjY7rnJ7JUdS+y0MLtb5UREW4P47Rg5g8YToHm5KDGJvDIrOiBQ1E5+sF tzzALH1zoAYMFazrnd+DTGUtP021z7UnVe6xHr7H+bs1+qXbzQm5fphTH UWvkyDiqVDdQv71pRXnnduNdhybfPfdpOH8t8qL3VqnRedOGwauoImKl3 aBYkVEtVE5qkOvufquhiXvzfsHpHJwdcPJpet8FA2Jk8jvZpo0hsh2N2M w==; X-IronPort-AV: E=McAfee;i="6500,9779,10442"; a="378941403" X-IronPort-AV: E=Sophos;i="5.93,245,1654585200"; d="scan'208";a="378941403" Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Aug 2022 19:25:04 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.93,245,1654585200"; d="scan'208";a="935613383" Received: from t.sh.intel.com ([10.239.159.159]) by fmsmga005.fm.intel.com with ESMTP; 17 Aug 2022 19:25:03 -0700 From: Fei Wang To: ffmpeg-devel@ffmpeg.org Date: Thu, 18 Aug 2022 10:25:06 +0800 Message-Id: <20220818022507.1780806-2-fei.w.wang@intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220818022507.1780806-1-fei.w.wang@intel.com> References: <20220818022507.1780806-1-fei.w.wang@intel.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v2 2/3] lavc/decode: Add internal surface re-allocate method for hwaccel X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Cc: Fei Wang , Linjie Fu Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: From: Linjie Fu 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 Signed-off-by: Fei Wang --- 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".