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 C1A9541015 for ; Fri, 12 Aug 2022 12:55:49 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id C5F5668B959; Fri, 12 Aug 2022 15:55:40 +0300 (EEST) Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 8BE8C6806E8 for ; Fri, 12 Aug 2022 15:55:33 +0300 (EEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1660308938; x=1691844938; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=OvVfzp4uTCy3lKruWBSpTeLEeglMC/s3DnXB6xzKbC4=; b=atmS4ltddby79XQ0UxDLq7GvaZ/bvE4pQh6o6JwEZuUdLhMY1WjJWBJC i82X8bP2oCpIOKpL6ahwKfcWtJocZXpnp3LkrqjjYCirVo3YE/B5TRgip wEmlmMvF31800117YtoSYYeQk84BW/Q/ftb1oMPqx/PobNBvwbU9q8ncx t9/8RLhdIBFd2hrvTsnwQ8Aq/E7ei7hBihdqgaotj328igCckdJf0HBjd DfsLN5rg3/aPBPQmRR4EYA1YQqOISMl5MZOrcUwm2lpK1oaO4w+MvFcj5 A+vG5mBtwjDWVhIW/KHnhe+ylCzvpNdbOLz6+arwWYTHG1kj+viqh+23x w==; X-IronPort-AV: E=McAfee;i="6400,9594,10437"; a="292853528" X-IronPort-AV: E=Sophos;i="5.93,231,1654585200"; d="scan'208";a="292853528" Received: from orsmga006.jf.intel.com ([10.7.209.51]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Aug 2022 05:55:30 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.93,231,1654585200"; d="scan'208";a="582081511" Received: from t.sh.intel.com ([10.239.159.159]) by orsmga006.jf.intel.com with ESMTP; 12 Aug 2022 05:55:29 -0700 From: Fei Wang To: ffmpeg-devel@ffmpeg.org Date: Fri, 12 Aug 2022 20:55:44 +0800 Message-Id: <20220812125545.1229410-2-fei.w.wang@intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220812125545.1229410-1-fei.w.wang@intel.com> References: <20220812125545.1229410-1-fei.w.wang@intel.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v1 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. 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 d66d5a4160..00c9141d91 100644 --- a/libavcodec/decode.c +++ b/libavcodec/decode.c @@ -1176,6 +1176,33 @@ static const AVCodecHWConfigInternal *get_hw_config(AVCodecContext *avctx, enum return hw_config; } +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; @@ -1202,6 +1229,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".