From patchwork Tue Aug 17 01:53:56 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 29581 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6602:2a4a:0:0:0:0 with SMTP id k10csp2550553iov; Mon, 16 Aug 2021 18:54:38 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw+JDQRmb6Lcaw7SWcDqjXKJi0liTBvbQToDYcGyDjGMvbmU5nDmm/CBU0Tg8C5UCxLKVPi X-Received: by 2002:a05:6402:781:: with SMTP id d1mr1308318edy.32.1629165278612; Mon, 16 Aug 2021 18:54:38 -0700 (PDT) Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id g17si803355edv.391.2021.08.16.18.54.38; Mon, 16 Aug 2021 18:54:38 -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; dkim=neutral (body hash did not verify) header.i=@outlook.com header.s=selector1 header.b=sVQPiNYA; arc=fail (body hash mismatch); 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; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=outlook.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 8EBBC68A61A; Tue, 17 Aug 2021 04:54:30 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from EUR05-DB8-obe.outbound.protection.outlook.com (mail-db8eur05olkn2015.outbound.protection.outlook.com [40.92.89.15]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id EA41D68A5E3 for ; Tue, 17 Aug 2021 04:54:23 +0300 (EEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=QNBioJoTYY4gNK48Uv/KTrlwDGnSBrgz+7EgibRFEWLN7PmOzwD7LtvlAtc+Hn0nM2cmXZJRSXV9qISyba560h49PTtJw5MBN/4eHCd63+LzT39LunYIVl3kBXRQDtydxxNIwZAfZ6sUWaBczF1VtKGHaXAiUem2pCGQB75iZXRXAPxPvWFeRwOuufMUsApNkKgT19HutSSXr6+rhet4UCh9u91LLWrKtjYmfFkRwczlpLg2rpdjR3vue3qni/VMZ4zkDW9QG6caNKo01/8Rkky1k6w4wARONWXsxoZI2gtEa8qFTjHOW4y30YGH1giy9MHH3HK7fc+oeNh5Ye7Sag== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=H5KhfAe1OI0SYYuhVBknKCmbYp+wcfuFlb1D6CKM9k8=; b=GUnmo6S4NlmDwHjNNaisnWdCbPz4R+LIiqft9GYVjGwjeaNOVF0TAJwB+T2qUapYoF5hZsBfv4vJpWsukxUSlhko216tuggz9jzw7r4EoZtfCzHirbv8rbBvxDDFxkp3pj/1ryG26WVJ7qMu6bqKhK2Z+9y2wsdnMN+yWvD0FBirAgI68PolSadHtla09heQVTOnxWiNA2X6YE3fj2mjxcdvT3CdrlLbbdTNy5nOLJkKb2zJTk8orVQlPqnvEzeuyD31iywZBDlbN4v6jF/4XsfeNpxBcsk835HcyjVzKZQ/fSwMqkPS2/00Dek906q7dXOjZFWMzbb9SAjPo54CXA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=outlook.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=H5KhfAe1OI0SYYuhVBknKCmbYp+wcfuFlb1D6CKM9k8=; b=sVQPiNYADwVPgft8RJCwxr7oPgR/rTEROUiGmDZ3rQjLFUhv8V6qlAYX/fAdq+fDN15xwAPnBnpnCAdSGxm9f0RVnvPmX9+ozuE0Cp3jJ8P/XgcU4e0Wg2enPsMePCsIpjDTecmKxro0sAV973RP5BGXl7Ecp6R4bO4OfOcZdiJWe/vv1MWC75SbMuN+sO1xE5LDb/aXIKu+4PpntQspV2fr35i9qrTXtxAHcb9rhMwuhiSHrrWXNJr551ZFHjaBi7rgAbSZCxAioCEQK2DOALy3cspHFwuKJTRcSUylrG+TYHmKonH5glK73OtrPTz0j5akpW3TL6juwBmYrmuQSQ== Received: from AM7PR03MB6660.eurprd03.prod.outlook.com (2603:10a6:20b:1c1::22) by AM7PR03MB6264.eurprd03.prod.outlook.com (2603:10a6:20b:13d::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4415.17; Tue, 17 Aug 2021 01:54:21 +0000 Received: from AM7PR03MB6660.eurprd03.prod.outlook.com ([fe80::ded:bace:bc7:e91d]) by AM7PR03MB6660.eurprd03.prod.outlook.com ([fe80::ded:bace:bc7:e91d%3]) with mapi id 15.20.4415.024; Tue, 17 Aug 2021 01:54:21 +0000 From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Tue, 17 Aug 2021 03:53:56 +0200 Message-ID: X-Mailer: git-send-email 2.30.2 In-Reply-To: References: X-TMN: [/UMpFgRGZV0MC9q2GytT94fqL4AXwQ3s] X-ClientProxiedBy: PR3P189CA0040.EURP189.PROD.OUTLOOK.COM (2603:10a6:102:53::15) To AM7PR03MB6660.eurprd03.prod.outlook.com (2603:10a6:20b:1c1::22) X-Microsoft-Original-Message-ID: <20210817015358.2985475-3-andreas.rheinhardt@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from sblaptop.fritz.box (188.192.142.38) by PR3P189CA0040.EURP189.PROD.OUTLOOK.COM (2603:10a6:102:53::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4415.14 via Frontend Transport; Tue, 17 Aug 2021 01:54:20 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 0c151929-0d8c-4269-541f-08d96121ee69 X-MS-Exchange-SLBlob-MailProps: S/btQ8cKWiSp1XYbE3vnwSazxHNSRmcC0qzLA1iKopkemQR0tXBiOZ7cMvw3cxS/IhjjxjG2FP2uVscW3HzT8h/1djjTov/vVXowV6AsOnFGutsIaW+vFnwzGktR2L5nMmEVCKe+F5iufnn+7S86nyCLReO3NP3cY2OA3U5XpxV84GFNksSYhjMQ35kwuieqVPRypvuIpIDN9aUpbchHtHcTxLreeuoVIQR0aZBAfo2WiFSsWsVJdQOawXrPLmQMAZ2SC5QWWtGf0XT+Z1cB9caPbnwV2+nuIXtMcHBrOlebSPHMAWP4HH/Sqn2uRTocHwdbwh07rO5O/7rE1b4DXTl3W9erIIX+yrIEOU51gz1snKcE2a5Lo3mQ5dtPrDziC7JETFtHGLQySovjcDCW3jWWutCprLIj6PLqTHGEaYlKay+UVuE6c6BcFU9bmH2tMCHUXiocd4/cpYQ+FOs3Ef/FF2xH6/i9xZM6EsFIeRc2TYYBsKtwG3Uib2l3hqeuXUTXr8/g2NvKNIrbG4DrnTshXZj0NfMCwHZ/IAj5HGzvHRI2Sxzs8qNCXmoyBJd1b5J3LAidIMAqX6/MvbVNAVJuhDJueEnpp5RtxqzSjn8UJnyQjJb3D8XpUy+4Zh1U2BxeBcTc3v9mJY8pPtTWXanKI3f0Um8l5YUH/BuaP9KH8NBKdU97Zum1TQmxGCwFV0CGsYnpDkPxmxRl+x/frlUahRViGcn2af55+jvk+8nMkxVqTp/j0UyBDocTRQxWEA2qppeGP6I= X-MS-TrafficTypeDiagnostic: AM7PR03MB6264: X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: or6WdEYE+VcvhxW6dDBbiChrKnEevdpRfTg6JbLiPDU+SjegRDUAPOlM/IB65akg6ItVCgKAyEOI+v4rnOpxKFSAxvJDBd65Uj4wI0d8PrYj4Ox1iARLnG9rJ9GosnMUpH+3APPy5izXZnlSP3mpXuFlkrq0wXvKI8PvpcFxxAZZyOuNIVdD/DYREfMjVQqAyc2+PjTwLEj0dFMPLBsOXYXPIHz9N2KUA5n6lJKXWPGwp1iVgKCGE7hX93P12Bz2VYCTmezzttOJtI8skjOH4g3rozRbW8rrLsOyIO2i9wFx6dRggPKScYENIo1vKngNZcYdpa2W+gsnQmZZfWrPtmRamwX+18o/qD3pu/Yxe0o1Yu6pRXnNyTF/Is8tot0L5fDZyfBuWmd5mYFMStB1Cpsf3VD2Ed2d7AkVbO3JBSlLtR4dg5X4f/wn0WF7n9go X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 13QaGuZJAI9g9f61FL4HpoDFCz0ys6P+Q2+9X4beOoZh0/LmtRS+kZ1BI7AnxpWc+Lk47cY1HtlRzpeE5Twk6/RRYWbxmTdHLpA0c9rWEbWdUpS2JiIYXg84KJl1NS/jOsWeG83GzA+qerocQC2rdA== X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 0c151929-0d8c-4269-541f-08d96121ee69 X-MS-Exchange-CrossTenant-AuthSource: AM7PR03MB6660.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Aug 2021 01:54:21.3153 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM7PR03MB6264 Subject: [FFmpeg-devel] [PATCH 4/6] avfilter/avfilter: Allow to free non-static pads generically 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: Andreas Rheinhardt Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: yt2GzoGEU8lo This can be enabled/disabled on a per-filter basis by setting the new internal flags FF_FILTER_FLAG_FREE_(IN|OUT)PADS and on a per-pad basis by setting the AVFILTERPAD_FLAG_FREE_NAME flag. Signed-off-by: Andreas Rheinhardt --- I decided to combine both approaches: It has the advantage that the marginal extra code for a filter all of whose inputs'/outputs' names need to be freed is zero while making it easy to handle filters that have some inputs/outputs whose names need to be freed. libavfilter/avfilter.c | 15 ++++++++++++++- libavfilter/internal.h | 20 ++++++++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/libavfilter/avfilter.c b/libavfilter/avfilter.c index c3382036d2..48727201f6 100644 --- a/libavfilter/avfilter.c +++ b/libavfilter/avfilter.c @@ -123,8 +123,11 @@ static int insert_pad(unsigned *count, AVFilterPad **pads, *pads = newpads; if (newlinks) *links = newlinks; - if (!newpads || !newlinks) + if (!newpads || !newlinks) { + if (newpad->flags & AVFILTERPAD_FLAG_FREE_NAME) + av_freep(&newpad->name); return AVERROR(ENOMEM); + } memcpy(*pads + idx, newpad, sizeof(AVFilterPad)); (*links)[idx] = NULL; @@ -136,11 +139,17 @@ static int insert_pad(unsigned *count, AVFilterPad **pads, int ff_insert_inpad(AVFilterContext *f, AVFilterPad *p) { + if (f->filter->flags_internal & FF_FILTER_FLAG_FREE_INPADS) + p->flags |= AVFILTERPAD_FLAG_FREE_NAME; + return insert_pad(&f->nb_inputs, &f->input_pads, &f->inputs, p); } int ff_insert_outpad(AVFilterContext *f, AVFilterPad *p) { + if (f->filter->flags_internal & FF_FILTER_FLAG_FREE_OUTPADS) + p->flags |= AVFILTERPAD_FLAG_FREE_NAME; + return insert_pad(&f->nb_outputs, &f->output_pads, &f->outputs, p); } @@ -741,9 +750,13 @@ void avfilter_free(AVFilterContext *filter) for (i = 0; i < filter->nb_inputs; i++) { free_link(filter->inputs[i]); + if (filter->input_pads[i].flags & AVFILTERPAD_FLAG_FREE_NAME) + av_freep(&filter->input_pads[i].name); } for (i = 0; i < filter->nb_outputs; i++) { free_link(filter->outputs[i]); + if (filter->output_pads[i].flags & AVFILTERPAD_FLAG_FREE_NAME) + av_freep(&filter->output_pads[i].name); } if (filter->filter->priv_class) diff --git a/libavfilter/internal.h b/libavfilter/internal.h index 8fe17a5433..0d0335bd1c 100644 --- a/libavfilter/internal.h +++ b/libavfilter/internal.h @@ -68,6 +68,11 @@ struct AVFilterPad { */ #define AVFILTERPAD_FLAG_NEEDS_WRITABLE (1 << 0) + /** + * The pad's name is allocated and should be freed generically. + */ +#define AVFILTERPAD_FLAG_FREE_NAME (1 << 1) + /** * A combination of AVFILTERPAD_FLAG_* flags. */ @@ -227,6 +232,11 @@ void ff_tlog_link(void *ctx, AVFilterLink *link, int end); /** * Append a new input/output pad to the filter's list of such pads. + * + * If the underlying AVFilter has the FF_FILTER_FLAG_FREE_INPADS + * set, the AVFILTERPAD_FLAG_FREE_NAME flag will be set for new inpads, + * ensuring that it will be freed generically (even on insertion error). + * Similarly for outpads. */ int ff_insert_inpad (AVFilterContext *f, AVFilterPad *p); int ff_insert_outpad(AVFilterContext *f, AVFilterPad *p); @@ -317,6 +327,16 @@ void ff_filter_graph_remove_filter(AVFilterGraph *graph, AVFilterContext *filter */ #define FF_FILTER_FLAG_HWFRAME_AWARE (1 << 0) +/** + * The names of all input pads are allocated and should be freed generically. + */ + #define FF_FILTER_FLAG_FREE_INPADS (1 << 1) + +/** + * The names of all output pads are allocated and should be freed generically. + */ + #define FF_FILTER_FLAG_FREE_OUTPADS (1 << 2) + /** * Run one round of processing on a filter graph. */