From patchwork Sun Jan 28 03:01:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marton Balint X-Patchwork-Id: 45863 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a21:8786:b0:199:de12:6fa6 with SMTP id ph6csp832843pzb; Sat, 27 Jan 2024 19:02:05 -0800 (PST) X-Google-Smtp-Source: AGHT+IGwvl/4RvFzfUBGS5jXPx4eRgme5dv8GFKGl21gsNX91RiCbN/+2f5mBFV5L54iFoskptq1 X-Received: by 2002:a2e:80ca:0:b0:2cd:ce2:496e with SMTP id r10-20020a2e80ca000000b002cd0ce2496emr1395957ljg.37.1706410924995; Sat, 27 Jan 2024 19:02:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1706410924; cv=none; d=google.com; s=arc-20160816; b=MhrAUjYrvqCshjHeajsR3rsAFDk+TdLFbbay8y/wOTaSYpe8f+zu0Kdz1VxEjXcRqc MGa2BGOklJvFK9GBon6CMNALbiAnBUUhkKtpOG/RUj+GYCGgubVPao2XpwPUizPch7I2 sxoHWjFgdawiai16Pf9patlB7oW7H2S8QIW6BO5tEa5e1qP5UqeDT+ohPWFdRYEpNn2N bpu7UKu70S1Zaon0jOia7f08RCrk3XVfIZ88xynRbo7/MrKBCFcRusIsNO8xzy+1ilmi M8EJf5pIvunxczSPSQNBJ0dnSDSbAjeWySDLXXuMQqkcNAzO6mqSuv/MYYb0nhKz+/mb B5GQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:mime-version:references:in-reply-to :message-id:date:to:from:delivered-to; bh=G96g8IlgHQLTzBpdqYMeq0BaFNMz8EhOtPTrGBLzfrw=; fh=s+G8Ss4JbeMFkWPSp2LmIH/LXFyBlALRiww1j3FPjHY=; b=tjpuWIht0UTG2WBZcPa3z/QDM9Ip2cih8wfPVxVlE3wFJK5XqPMiGpAAAO8hQb0WF+ IXhd4Cl/l0wLuFbThfHrZpjcmyE8LmQGWBwiixTHicjdouxt1H4tr6qswlz2rRTiDWR6 IMiSpzdzU+O8lQTH6Sg+gzVxkkyAUYwxU67g4+cHCu302W0cp8RAlCFahrla+zCWj9PL /88FlahDJVyMDjKc+buGk88vzT+493Daumdv3usnMt8GcYUFcB7yY1Sod+P6GIg0RrKc bsCVC64du9QoCPBZp7NLpQZS/ZaHwrsaY5A9O6nSeonEDFmtx37PhiLy1Pyyil27LbGP E/rA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id h13-20020a0564020e0d00b0055c5b3d78d2si2320022edh.316.2024.01.27.19.02.04; Sat, 27 Jan 2024 19:02:04 -0800 (PST) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 77FC568D14E; Sun, 28 Jan 2024 05:01:55 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from iq.passwd.hu (iq.passwd.hu [217.27.212.140]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id C7B0168D128 for ; Sun, 28 Jan 2024 05:01:48 +0200 (EET) Received: from localhost (localhost [127.0.0.1]) by iq.passwd.hu (Postfix) with ESMTP id 9984AE9CD7; Sun, 28 Jan 2024 04:01:48 +0100 (CET) X-Virus-Scanned: amavisd-new at passwd.hu Received: from iq.passwd.hu ([127.0.0.1]) by localhost (iq.passwd.hu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 4KP25Nj5H0Wf; Sun, 28 Jan 2024 04:01:46 +0100 (CET) Received: from bluegene.passwd.hu (localhost [127.0.0.1]) by iq.passwd.hu (Postfix) with ESMTP id CD91DE9CBF; Sun, 28 Jan 2024 04:01:45 +0100 (CET) From: Marton Balint To: ffmpeg-devel@ffmpeg.org Date: Sun, 28 Jan 2024 04:01:35 +0100 Message-Id: <20240128030136.5585-2-cus@passwd.hu> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20240128030136.5585-1-cus@passwd.hu> References: <20240128030136.5585-1-cus@passwd.hu> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 2/3] avfilter/yadif_common: factorize some part of the config_output and the uninit functions 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: Marton Balint Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: 8oGHfH7in+Xu This unifies slightly diverged code and ensures that cc_fifo is always initialized. Signed-off-by: Marton Balint --- libavfilter/vf_bwdif.c | 30 +++------------------- libavfilter/vf_bwdif_cuda.c | 15 +++-------- libavfilter/vf_bwdif_vulkan.c | 12 ++++----- libavfilter/vf_yadif.c | 33 +++--------------------- libavfilter/vf_yadif_cuda.c | 27 +++---------------- libavfilter/vf_yadif_videotoolbox.m | 19 +++----------- libavfilter/yadif.h | 4 +++ libavfilter/yadif_common.c | 40 +++++++++++++++++++++++++++++ 8 files changed, 66 insertions(+), 114 deletions(-) diff --git a/libavfilter/vf_bwdif.c b/libavfilter/vf_bwdif.c index 353cd0b61a..9042db8d7f 100644 --- a/libavfilter/vf_bwdif.c +++ b/libavfilter/vf_bwdif.c @@ -137,17 +137,6 @@ static void filter(AVFilterContext *ctx, AVFrame *dstpic, } } -static av_cold void uninit(AVFilterContext *ctx) -{ - BWDIFContext *bwdif = ctx->priv; - YADIFContext *yadif = &bwdif->yadif; - - av_frame_free(&yadif->prev); - av_frame_free(&yadif->cur ); - av_frame_free(&yadif->next); - ff_ccfifo_uninit(&yadif->cc_fifo); -} - static const enum AVPixelFormat pix_fmts[] = { AV_PIX_FMT_YUV410P, AV_PIX_FMT_YUV411P, AV_PIX_FMT_YUV420P, AV_PIX_FMT_YUV422P, AV_PIX_FMT_YUV440P, AV_PIX_FMT_YUV444P, @@ -176,20 +165,9 @@ static int config_props(AVFilterLink *link) YADIFContext *yadif = &s->yadif; int ret; - link->time_base = av_mul_q(ctx->inputs[0]->time_base, (AVRational){1, 2}); - link->w = link->src->inputs[0]->w; - link->h = link->src->inputs[0]->h; - - if(yadif->mode&1) - link->frame_rate = av_mul_q(link->src->inputs[0]->frame_rate, (AVRational){2,1}); - else - link->frame_rate = ctx->inputs[0]->frame_rate; - - ret = ff_ccfifo_init(&yadif->cc_fifo, link->frame_rate, ctx); - if (ret < 0 ) { - av_log(ctx, AV_LOG_ERROR, "Failure to setup CC FIFO queue\n"); - return ret; - } + ret = ff_yadif_config_output_common(link); + if (ret < 0) + return AVERROR(EINVAL); yadif->csp = av_pix_fmt_desc_get(link->format); yadif->filter = filter; @@ -251,7 +229,7 @@ const AVFilter ff_vf_bwdif = { .description = NULL_IF_CONFIG_SMALL("Deinterlace the input image."), .priv_size = sizeof(BWDIFContext), .priv_class = &bwdif_class, - .uninit = uninit, + .uninit = ff_yadif_uninit, FILTER_INPUTS(avfilter_vf_bwdif_inputs), FILTER_OUTPUTS(avfilter_vf_bwdif_outputs), FILTER_PIXFMTS_ARRAY(pix_fmts), diff --git a/libavfilter/vf_bwdif_cuda.c b/libavfilter/vf_bwdif_cuda.c index 418f15f989..7585d1fe25 100644 --- a/libavfilter/vf_bwdif_cuda.c +++ b/libavfilter/vf_bwdif_cuda.c @@ -208,9 +208,7 @@ static av_cold void deint_cuda_uninit(AVFilterContext *ctx) CHECK_CU(cu->cuCtxPopCurrent(&dummy)); } - av_frame_free(&y->prev); - av_frame_free(&y->cur); - av_frame_free(&y->next); + ff_yadif_uninit(ctx); av_buffer_unref(&s->device_ref); s->hwctx = NULL; @@ -288,14 +286,9 @@ static int config_output(AVFilterLink *link) goto exit; } - link->time_base = av_mul_q(ctx->inputs[0]->time_base, (AVRational){1, 2}); - link->w = ctx->inputs[0]->w; - link->h = ctx->inputs[0]->h; - - if(y->mode & 1) - link->frame_rate = av_mul_q(ctx->inputs[0]->frame_rate, - (AVRational){2, 1}); - + ret = ff_yadif_config_output_common(link); + if (ret < 0) + goto exit; y->csp = av_pix_fmt_desc_get(output_frames->sw_format); y->filter = filter; diff --git a/libavfilter/vf_bwdif_vulkan.c b/libavfilter/vf_bwdif_vulkan.c index c51df9aa26..57711fb672 100644 --- a/libavfilter/vf_bwdif_vulkan.c +++ b/libavfilter/vf_bwdif_vulkan.c @@ -296,6 +296,8 @@ static void bwdif_vulkan_uninit(AVFilterContext *avctx) ff_vk_uninit(&s->vkctx); + ff_yadif_uninit(avctx); + s->initialized = 0; } @@ -354,13 +356,9 @@ static int bwdif_vulkan_config_output(AVFilterLink *outlink) if (!outlink->hw_frames_ctx) return AVERROR(ENOMEM); - outlink->time_base = av_mul_q(avctx->inputs[0]->time_base, (AVRational){1, 2}); - outlink->w = vkctx->output_width; - outlink->h = vkctx->output_height; - - if (y->mode & 1) - outlink->frame_rate = av_mul_q(avctx->inputs[0]->frame_rate, - (AVRational){2, 1}); + err = ff_yadif_config_output_common(outlink); + if (err < 0) + return err; y->csp = av_pix_fmt_desc_get(vkctx->frames->sw_format); y->filter = bwdif_vulkan_filter_frame; diff --git a/libavfilter/vf_yadif.c b/libavfilter/vf_yadif.c index a5a856bf5f..aa5ca4a889 100644 --- a/libavfilter/vf_yadif.c +++ b/libavfilter/vf_yadif.c @@ -251,16 +251,6 @@ static void filter(AVFilterContext *ctx, AVFrame *dstpic, } } -static av_cold void uninit(AVFilterContext *ctx) -{ - YADIFContext *yadif = ctx->priv; - - av_frame_free(&yadif->prev); - av_frame_free(&yadif->cur ); - av_frame_free(&yadif->next); - ff_ccfifo_uninit(&yadif->cc_fifo); -} - static const enum AVPixelFormat pix_fmts[] = { AV_PIX_FMT_YUV420P, AV_PIX_FMT_YUV422P, AV_PIX_FMT_YUV444P, AV_PIX_FMT_YUV410P, AV_PIX_FMT_YUV411P, AV_PIX_FMT_YUV440P, @@ -285,26 +275,9 @@ static int config_output(AVFilterLink *outlink) YADIFContext *s = ctx->priv; int ret; - outlink->time_base = av_mul_q(ctx->inputs[0]->time_base, (AVRational){1, 2}); - outlink->w = ctx->inputs[0]->w; - outlink->h = ctx->inputs[0]->h; - - if(s->mode & 1) - outlink->frame_rate = av_mul_q(ctx->inputs[0]->frame_rate, - (AVRational){2, 1}); - else - outlink->frame_rate = ctx->inputs[0]->frame_rate; - - ret = ff_ccfifo_init(&s->cc_fifo, outlink->frame_rate, ctx); - if (ret < 0) { - av_log(ctx, AV_LOG_ERROR, "Failure to setup CC FIFO queue\n"); + ret = ff_yadif_config_output_common(outlink); + if (ret < 0) return ret; - } - - if (outlink->w < 3 || outlink->h < 3) { - av_log(ctx, AV_LOG_ERROR, "Video of less than 3 columns or lines is not supported\n"); - return AVERROR(EINVAL); - } s->csp = av_pix_fmt_desc_get(outlink->format); s->filter = filter; @@ -354,7 +327,7 @@ const AVFilter ff_vf_yadif = { .description = NULL_IF_CONFIG_SMALL("Deinterlace the input image."), .priv_size = sizeof(YADIFContext), .priv_class = &yadif_class, - .uninit = uninit, + .uninit = ff_yadif_uninit, FILTER_INPUTS(avfilter_vf_yadif_inputs), FILTER_OUTPUTS(avfilter_vf_yadif_outputs), FILTER_PIXFMTS_ARRAY(pix_fmts), diff --git a/libavfilter/vf_yadif_cuda.c b/libavfilter/vf_yadif_cuda.c index d777757e65..17389f092f 100644 --- a/libavfilter/vf_yadif_cuda.c +++ b/libavfilter/vf_yadif_cuda.c @@ -200,10 +200,7 @@ static av_cold void deint_cuda_uninit(AVFilterContext *ctx) CHECK_CU(cu->cuCtxPopCurrent(&dummy)); } - av_frame_free(&y->prev); - av_frame_free(&y->cur); - av_frame_free(&y->next); - ff_ccfifo_uninit(&y->cc_fifo); + ff_yadif_uninit(ctx); av_buffer_unref(&s->device_ref); s->hwctx = NULL; @@ -281,27 +278,9 @@ static int config_output(AVFilterLink *link) goto exit; } - link->time_base = av_mul_q(ctx->inputs[0]->time_base, (AVRational){1, 2}); - link->w = ctx->inputs[0]->w; - link->h = ctx->inputs[0]->h; - - if(y->mode & 1) - link->frame_rate = av_mul_q(ctx->inputs[0]->frame_rate, - (AVRational){2, 1}); - else - link->frame_rate = ctx->inputs[0]->frame_rate; - - ret = ff_ccfifo_init(&y->cc_fifo, link->frame_rate, ctx); - if (ret < 0) { - av_log(ctx, AV_LOG_ERROR, "Failure to setup CC FIFO queue\n"); - goto exit; - } - - if (link->w < 3 || link->h < 3) { - av_log(ctx, AV_LOG_ERROR, "Video of less than 3 columns or lines is not supported\n"); - ret = AVERROR(EINVAL); + ret = ff_yadif_config_output_common(link); + if (ret < 0) goto exit; - } y->csp = av_pix_fmt_desc_get(output_frames->sw_format); y->filter = filter; diff --git a/libavfilter/vf_yadif_videotoolbox.m b/libavfilter/vf_yadif_videotoolbox.m index 69186c2254..28d836b782 100644 --- a/libavfilter/vf_yadif_videotoolbox.m +++ b/libavfilter/vf_yadif_videotoolbox.m @@ -174,9 +174,7 @@ static av_cold void do_uninit(AVFilterContext *ctx) API_AVAILABLE(macos(10.11), YADIFVTContext *s = ctx->priv; YADIFContext *y = &s->yadif; - av_frame_free(&y->prev); - av_frame_free(&y->cur); - av_frame_free(&y->next); + ff_yadif_uninit(ctx); av_buffer_unref(&s->device_ref); av_buffer_unref(&s->input_frames_ref); @@ -363,20 +361,9 @@ static int do_config_output(AVFilterLink *link) API_AVAILABLE(macos(10.11), ios( goto exit; } - link->time_base.num = ctx->inputs[0]->time_base.num; - link->time_base.den = ctx->inputs[0]->time_base.den * 2; - link->w = ctx->inputs[0]->w; - link->h = ctx->inputs[0]->h; - - if(y->mode & 1) - link->frame_rate = av_mul_q(ctx->inputs[0]->frame_rate, - (AVRational){2, 1}); - - if (link->w < 3 || link->h < 3) { - av_log(ctx, AV_LOG_ERROR, "Video of less than 3 columns or lines is not supported\n"); - ret = AVERROR(EINVAL); + ret = ff_yadif_config_output_common(link); + if (ret < 0) goto exit; - } y->csp = av_pix_fmt_desc_get(output_frames->sw_format); y->filter = filter; diff --git a/libavfilter/yadif.h b/libavfilter/yadif.h index fbb99fd46e..2c4fed62d2 100644 --- a/libavfilter/yadif.h +++ b/libavfilter/yadif.h @@ -94,6 +94,10 @@ int ff_yadif_filter_frame(AVFilterLink *link, AVFrame *frame); int ff_yadif_request_frame(AVFilterLink *link); +int ff_yadif_config_output_common(AVFilterLink *outlink); + +void ff_yadif_uninit(AVFilterContext *ctx); + extern const AVOption ff_yadif_options[]; #endif /* AVFILTER_YADIF_H */ diff --git a/libavfilter/yadif_common.c b/libavfilter/yadif_common.c index 21097011f5..933372529e 100644 --- a/libavfilter/yadif_common.c +++ b/libavfilter/yadif_common.c @@ -209,6 +209,46 @@ int ff_yadif_request_frame(AVFilterLink *link) return 0; } +int ff_yadif_config_output_common(AVFilterLink *outlink) +{ + AVFilterContext *ctx = outlink->src; + YADIFContext *yadif = ctx->priv; + int ret; + + outlink->time_base = av_mul_q(ctx->inputs[0]->time_base, (AVRational){1, 2}); + outlink->w = ctx->inputs[0]->w; + outlink->h = ctx->inputs[0]->h; + + if (outlink->w < 3 || outlink->h < 3) { + av_log(ctx, AV_LOG_ERROR, "Video of less than 3 columns or lines is not supported\n"); + return AVERROR(EINVAL); + } + + if(yadif->mode & 1) + outlink->frame_rate = av_mul_q(ctx->inputs[0]->frame_rate, + (AVRational){2, 1}); + else + outlink->frame_rate = ctx->inputs[0]->frame_rate; + + ret = ff_ccfifo_init(&yadif->cc_fifo, outlink->frame_rate, ctx); + if (ret < 0) { + av_log(ctx, AV_LOG_ERROR, "Failure to setup CC FIFO queue\n"); + return ret; + } + + return 0; +} + +void ff_yadif_uninit(AVFilterContext *ctx) +{ + YADIFContext *yadif = ctx->priv; + + av_frame_free(&yadif->prev); + av_frame_free(&yadif->cur ); + av_frame_free(&yadif->next); + ff_ccfifo_uninit(&yadif->cc_fifo); +} + #define OFFSET(x) offsetof(YADIFContext, x) #define FLAGS AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM