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 8E73A43C2C for ; Tue, 23 Aug 2022 08:20:14 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 07B2768BA4F; Tue, 23 Aug 2022 11:20:07 +0300 (EEST) Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 61C4768B959 for ; Tue, 23 Aug 2022 11:20:00 +0300 (EEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1661242805; x=1692778805; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=hXMBztpKMIjju/lxJYUH9Fc3X2x4ZXbPSs2o6hqJZ1I=; b=bvZL+Tsax0e2Pmu0su8xH+IueG8TlEfimJbbuLbp17Jp0le1+FME1Shk UUe8VYrFqB8QQi9mONaTuwqwVJI1h1QOUVOfyeRN+Os4RYd7fiTI/V4YM pC/Z/wQKngP+ohOp7AIIu/yipwhtm7HEui0g+4wZ3XgFbKzR0SvvN7e2Q EAw6K8WdsfOfVgqinO5B34uMah3sAEzXYWYrdebR7QToqr886KtEPyuju QC6SVPFvJMfzit9l32j6X+ARd4GQjF2YKYdTa5iZxaOnOC9GI0FmO/+Cg N/HP8Vsrl3myhiZNtlrHy4bAU2XltwyRGFpNV0fQiyALLlu9v9Y4f8ue/ Q==; X-IronPort-AV: E=McAfee;i="6500,9779,10447"; a="357604442" X-IronPort-AV: E=Sophos;i="5.93,257,1654585200"; d="scan'208";a="357604442" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Aug 2022 01:19:58 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.93,257,1654585200"; d="scan'208";a="638556928" Received: from t.sh.intel.com ([10.239.159.159]) by orsmga008.jf.intel.com with ESMTP; 23 Aug 2022 01:19:57 -0700 From: Fei Wang To: ffmpeg-devel@ffmpeg.org Date: Tue, 23 Aug 2022 16:19:28 +0800 Message-Id: <20220823081929.413947-2-fei.w.wang@intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220823081929.413947-1-fei.w.wang@intel.com> References: <20220823081929.413947-1-fei.w.wang@intel.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v3 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 related configs when decode resolution change, just need to re-allocate new surface by using new resolution. 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".