From patchwork Sat Jul 15 10:45:44 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 42723 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:6da1:b0:131:a7d0:bc6d with SMTP id gl33csp4240486pzb; Sat, 15 Jul 2023 03:50:59 -0700 (PDT) X-Google-Smtp-Source: APBJJlGv70H1yR8GLtcRiioa+wkZl78jbRxa+3mirlxOG/tB53+kbYIgwT6z8hPkax3+BP9tkD4X X-Received: by 2002:a17:907:2347:b0:978:8937:19ba with SMTP id we7-20020a170907234700b00978893719bamr6224008ejb.44.1689418258827; Sat, 15 Jul 2023 03:50:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689418258; cv=none; d=google.com; s=arc-20160816; b=HuarGDTsAp/lCsUjm4nHWz3fGL4zTXMzxSrvwA481gxb8QU4eGjKUosKlHAojaqXTo SDBaS1zfvb1MxsLk20jOGKr7ctBaU2D5HERHvdBv+PxJQ+cVYAS+4vg84T+enssy+tUD lo7fWENptC1a9YnRRD9sJjmkx1QzAJeomMQP0h381X04resGsfYAXCrgOL5kq+tbyaRZ XUjxBUk9sn1AmhKGSBM4dJ1ZhtW+8BcVaFaBRxSDGC/q8S9vo6Xufj4LupmV0IOdJCb1 OP2uQBBjUAtxvFeyLwsYbv9jpvsZb8b9VkBlXYuRWSgAIikXatDS4XDdw+QPaLAeav7J tO3Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding: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=4YQOckn+M9hPqlo6bIsgXuBZ+fkiMnnrdD8N5QYUFnc=; fh=8ZF2QtiKOjBtyn9wuO2cMeZaLsE4aq02Bq77gGK61E8=; b=UZrydBw2vcAdrXmGVEj+KNRY2F42k2XJ8xPszHwZIhzPEq3Ifu+c413IlZd7zVJOL0 usk6ba53Bkbv2uJYgqxWdm8PGcRDDHf83BoJJ8Acs72oPptEX2ExpxKlHgL4EC1yzNJN Y1uFUl5+vFPoXEguuaYWPTWp5TzYJHJCKIGtV8lx8B97MxWh2V72nA3Qflhrus0mCjdc BW1IM3FvqimJe69AoFnTkGrmClrVy9sS+gOTWzrdP5RucDyX5CZbIA6FaQDDDXn2uTKm Q347Wfh27y3uV5puhZd+JMGD65SOgqFcouAJIVWHEugXisDw7aiqvyHEyWHb9NmDzD5V K1JA== 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 y15-20020a170906448f00b00992e23f0e6asi10761244ejo.822.2023.07.15.03.50.58; Sat, 15 Jul 2023 03:50:58 -0700 (PDT) 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 CF50868C768; Sat, 15 Jul 2023 13:47:08 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail0.khirnov.net (red.khirnov.net [176.97.15.12]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id B532468C6D2 for ; Sat, 15 Jul 2023 13:46:45 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 68AB82404EE for ; Sat, 15 Jul 2023 12:46:45 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id opNmEs_rGBFC for ; Sat, 15 Jul 2023 12:46:44 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:2a00:c500:561:201::7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "libav.khirnov.net", Issuer "smtp.khirnov.net SMTP CA" (verified OK)) by mail0.khirnov.net (Postfix) with ESMTPS id 048B1240D1F for ; Sat, 15 Jul 2023 12:46:27 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id DAFD33A1A05 for ; Sat, 15 Jul 2023 12:46:20 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Sat, 15 Jul 2023 12:45:44 +0200 Message-Id: <20230715104611.17902-20-anton@khirnov.net> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230715104611.17902-1-anton@khirnov.net> References: <20230715104611.17902-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 20/47] fftools/ffmpeg_filter: return error codes from fg_create() instead of aborting 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: wjB3EO4SXyYW --- fftools/ffmpeg.h | 2 +- fftools/ffmpeg_filter.c | 38 ++++++++++++++++++++++---------------- fftools/ffmpeg_opt.c | 8 ++------ 3 files changed, 25 insertions(+), 23 deletions(-) diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h index 043eb5e6ec..ba73dcffdc 100644 --- a/fftools/ffmpeg.h +++ b/fftools/ffmpeg.h @@ -752,7 +752,7 @@ int ofilter_bind_ost(OutputFilter *ofilter, OutputStream *ost); * @param graph_desc Graph description; an av_malloc()ed string, filtergraph * takes ownership of it. */ -FilterGraph *fg_create(char *graph_desc); +int fg_create(FilterGraph **pfg, char *graph_desc); void fg_free(FilterGraph **pfg); diff --git a/fftools/ffmpeg_filter.c b/fftools/ffmpeg_filter.c index 2a3204121a..485154a448 100644 --- a/fftools/ffmpeg_filter.c +++ b/fftools/ffmpeg_filter.c @@ -538,16 +538,11 @@ static char *describe_filter_link(FilterGraph *fg, AVFilterInOut *inout, int in) AVFilterContext *ctx = inout->filter_ctx; AVFilterPad *pads = in ? ctx->input_pads : ctx->output_pads; int nb_pads = in ? ctx->nb_inputs : ctx->nb_outputs; - char *res; if (nb_pads > 1) - res = av_strdup(ctx->filter->name); - else - res = av_asprintf("%s:%s", ctx->filter->name, - avfilter_pad_get_name(pads, inout->pad_idx)); - if (!res) - report_and_exit(AVERROR(ENOMEM)); - return res; + return av_strdup(ctx->filter->name); + return av_asprintf("%s:%s", ctx->filter->name, + avfilter_pad_get_name(pads, inout->pad_idx)); } static OutputFilter *ofilter_alloc(FilterGraph *fg) @@ -799,7 +794,7 @@ static const AVClass fg_class = { .category = AV_CLASS_CATEGORY_FILTER, }; -FilterGraph *fg_create(char *graph_desc) +int fg_create(FilterGraph **pfg, char *graph_desc) { FilterGraphPriv *fgp = allocate_array_elem(&filtergraphs, sizeof(*fgp), &nb_filtergraphs); FilterGraph *fg = &fgp->fg; @@ -808,6 +803,9 @@ FilterGraph *fg_create(char *graph_desc) AVFilterGraph *graph; int ret = 0; + if (pfg) + *pfg = fg; + fg->class = &fg_class; fg->index = nb_filtergraphs - 1; fgp->graph_desc = graph_desc; @@ -817,13 +815,13 @@ FilterGraph *fg_create(char *graph_desc) fgp->frame = av_frame_alloc(); if (!fgp->frame) - report_and_exit(AVERROR(ENOMEM)); + return AVERROR(ENOMEM); /* this graph is only used for determining the kinds of inputs * and outputs we have, and is discarded on exit from this function */ graph = avfilter_graph_alloc(); if (!graph) - report_and_exit(AVERROR(ENOMEM)); + return AVERROR(ENOMEM);; graph->nb_threads = 1; ret = graph_parse(graph, fgp->graph_desc, &inputs, &outputs, NULL); @@ -840,6 +838,10 @@ FilterGraph *fg_create(char *graph_desc) ifp->type = avfilter_pad_get_type(cur->filter_ctx->input_pads, cur->pad_idx); ifilter->name = describe_filter_link(fg, cur, 1); + if (!ifilter->name) { + ret = AVERROR(ENOMEM); + goto fail; + } } for (AVFilterInOut *cur = outputs; cur; cur = cur->next) { @@ -851,6 +853,10 @@ FilterGraph *fg_create(char *graph_desc) ofilter->type = avfilter_pad_get_type(cur->filter_ctx->output_pads, cur->pad_idx); ofilter->name = describe_filter_link(fg, cur, 0); + if (!ofilter->name) { + ret = AVERROR(ENOMEM); + goto fail; + } } if (!fg->nb_outputs) { @@ -865,9 +871,9 @@ fail: avfilter_graph_free(&graph); if (ret < 0) - report_and_exit(ret); + return ret; - return fg; + return 0; } int init_simple_filtergraph(InputStream *ist, OutputStream *ost, @@ -877,9 +883,9 @@ int init_simple_filtergraph(InputStream *ist, OutputStream *ost, FilterGraphPriv *fgp; int ret; - fg = fg_create(graph_desc); - if (!fg) - report_and_exit(AVERROR(ENOMEM)); + ret = fg_create(&fg, graph_desc); + if (ret < 0) + return ret; fgp = fgp_from_fg(fg); fgp->is_simple = 1; diff --git a/fftools/ffmpeg_opt.c b/fftools/ffmpeg_opt.c index 44bf263621..25a1083366 100644 --- a/fftools/ffmpeg_opt.c +++ b/fftools/ffmpeg_opt.c @@ -1112,9 +1112,7 @@ static int opt_filter_complex(void *optctx, const char *opt, const char *arg) if (!graph_desc) return AVERROR(ENOMEM); - fg_create(graph_desc); - - return 0; + return fg_create(NULL, graph_desc); } static int opt_filter_complex_script(void *optctx, const char *opt, const char *arg) @@ -1123,9 +1121,7 @@ static int opt_filter_complex_script(void *optctx, const char *opt, const char * if (!graph_desc) return AVERROR(EINVAL); - fg_create(graph_desc); - - return 0; + return fg_create(NULL, graph_desc); } void show_help_default(const char *opt, const char *arg)