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 B2A4C493D4 for ; Fri, 9 Feb 2024 14:54:22 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 2C71068D0F5; Fri, 9 Feb 2024 16:54:04 +0200 (EET) Received: from haasn.dev (haasn.dev [78.46.187.166]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 43C7768CD10 for ; Fri, 9 Feb 2024 16:53:55 +0200 (EET) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=haasn.xyz; s=mail; t=1707490435; bh=e7Mk2nKzHPnARdd2O3TaTbd8Di/Oh7URCTl9W4C9Iv8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=QgATJ+WcLMdihGlNtDEqaguYb49b+ncS8BWAPdcmlkWPTYcRhDPgqIxp3NAwq+r6L CuFUU7c5Hf1+4LaQBYs3rzWwz3hv4Yrhha+2SxGkMuxk4YFG2UcqIfvbzcT7tmcv5/ lPWg+w/JGx3UfnPO2Ap8kFMnofSX8MF5nwzw0Htg= Received: from haasn.dev (unknown [10.30.0.2]) by haasn.dev (Postfix) with ESMTP id 05F0C41826; Fri, 9 Feb 2024 15:53:55 +0100 (CET) From: Niklas Haas To: ffmpeg-devel@ffmpeg.org Date: Fri, 9 Feb 2024 15:53:47 +0100 Message-ID: <20240209145349.104511-3-ffmpeg@haasn.xyz> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240209145349.104511-1-ffmpeg@haasn.xyz> References: <20240209145349.104511-1-ffmpeg@haasn.xyz> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 3/5] avfilter/hwupload: move hwctx init to init() 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: Niklas Haas 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: Niklas Haas --- libavfilter/vf_hwupload.c | 49 ++++++++++++++++++++++----------------- 1 file changed, 28 insertions(+), 21 deletions(-) diff --git a/libavfilter/vf_hwupload.c b/libavfilter/vf_hwupload.c index ef61bb4137..bc1e32af1a 100644 --- a/libavfilter/vf_hwupload.c +++ b/libavfilter/vf_hwupload.c @@ -39,35 +39,41 @@ typedef struct HWUploadContext { char *device_type; } HWUploadContext; -static int hwupload_query_formats(AVFilterContext *avctx) +static av_cold int hwupload_init(AVFilterContext *avctx) { HWUploadContext *ctx = avctx->priv; - AVHWFramesConstraints *constraints = NULL; - const enum AVPixelFormat *input_pix_fmts, *output_pix_fmts; - AVFilterFormats *input_formats = NULL; - int err, i; + int err; - if (ctx->hwdevice_ref) { - /* We already have a specified device. */ - } else if (avctx->hw_device_ctx) { - if (ctx->device_type) { - err = av_hwdevice_ctx_create_derived( - &ctx->hwdevice_ref, - av_hwdevice_find_type_by_name(ctx->device_type), - avctx->hw_device_ctx, 0); - if (err < 0) - return err; - } else { - ctx->hwdevice_ref = av_buffer_ref(avctx->hw_device_ctx); - if (!ctx->hwdevice_ref) - return AVERROR(ENOMEM); - } - } else { + if (!avctx->hw_device_ctx) { av_log(ctx, AV_LOG_ERROR, "A hardware device reference is required " "to upload frames to.\n"); return AVERROR(EINVAL); } + if (ctx->device_type) { + err = av_hwdevice_ctx_create_derived( + &ctx->hwdevice_ref, + av_hwdevice_find_type_by_name(ctx->device_type), + avctx->hw_device_ctx, 0); + if (err < 0) + return err; + } else { + ctx->hwdevice_ref = av_buffer_ref(avctx->hw_device_ctx); + if (!ctx->hwdevice_ref) + return AVERROR(ENOMEM); + } + + return 0; +} + +static int hwupload_query_formats(AVFilterContext *avctx) +{ + HWUploadContext *ctx = avctx->priv; + AVHWFramesConstraints *constraints = NULL; + const enum AVPixelFormat *input_pix_fmts, *output_pix_fmts; + AVFilterFormats *input_formats = NULL; + int err, i; + constraints = av_hwdevice_get_hwframe_constraints(ctx->hwdevice_ref, NULL); if (!constraints) { err = AVERROR(EINVAL); @@ -251,6 +257,7 @@ static const AVFilterPad hwupload_outputs[] = { const AVFilter ff_vf_hwupload = { .name = "hwupload", .description = NULL_IF_CONFIG_SMALL("Upload a normal frame to a hardware frame"), + .init = hwupload_init, .uninit = hwupload_uninit, .priv_size = sizeof(HWUploadContext), .priv_class = &hwupload_class, -- 2.43.0 _______________________________________________ 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".