From patchwork Wed Aug 11 01:17:49 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 29412 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:8e8b:0:0:0:0:0 with SMTP id q133csp955926iod; Tue, 10 Aug 2021 18:18:47 -0700 (PDT) X-Google-Smtp-Source: ABdhPJym90xbm4l9pndORcTDPloI7nZi4DFT2UfYaASQg3IoJiCqrw62tuZo3NJiwIDMV0DYiiV9 X-Received: by 2002:a17:906:eda3:: with SMTP id sa3mr1185590ejb.451.1628644726864; Tue, 10 Aug 2021 18:18:46 -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 u6si23117642eju.564.2021.08.10.18.18.46; Tue, 10 Aug 2021 18:18:46 -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=KZDzPjfR; 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 9F4E268A464; Wed, 11 Aug 2021 04:18:37 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from EUR04-DB3-obe.outbound.protection.outlook.com (mail-oln040092074054.outbound.protection.outlook.com [40.92.74.54]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 9F19768A404 for ; Wed, 11 Aug 2021 04:18:31 +0300 (EEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Ck5u71BeG1DiRaS9GuwXpaJuvCjPn5crSLmZSXWS+62Y5nfhUC5C1dwjO9GMxUVbN4TkcM1tkeAH3wi3l2vnT2ccu4s2aCWisSCr6sZ2NfW3V3H/F63P8TBwXLlc2DlEgSMHiDeD6fyzAJ6ZiCbjJMT61uYnnBKhukBiR9STxvCb4wHJbIlj34D+oof80SjVnjChHVez419iQwD2uO6vJuB2i2XOlBIvCTdwGZFlUYvvn+HdUAGoMpKw3lOP2WeAnm+gwcX5w+OxvEK/r4VzfZUN2B7rAd8Z+8z6wkiXWqUbk8FW/21DtcLQaAPsjkVrp6MF06Y2XQxGI72pLAhC5w== 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=vwiTrB++L7WUarvTCqYOoSAOAkyIK90BcAnicbErNOI=; b=GzlVs3e0aHV5gW8Y/ewR5xt+Ci3YhIhKgk7gWZ9/hbsksM2SVkh4agq10ySPsxr3F1LhGbybfdsP3imcIoy/jUlDiESNMB8IOjhn2quRLQ6QDnUXMiQmRp9VgVnGiENWEzhpAGTR4f96384AaO1grJbFX8uPIzFh+KP/xVO8nGsfyNfqlqwXq7jKAVW5/UrwG/v3Fn7GJGg7iscXM1F6Qgwt+4sB6tFwTuVG08zTgbPXten0lGaY/DSdls/d01GIpG3G2sAkPJomLKX1oeoxhW7rc9jE3xgIUu9WbffCdhSqu3VxTzuSo3TH/lqInx4xhou8JkGASH6ire1sNcF6OA== 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=vwiTrB++L7WUarvTCqYOoSAOAkyIK90BcAnicbErNOI=; b=KZDzPjfRhjEMqDRGs6QzkVIOnZ4ywuP+MXpLgSmuwPqc69Gr4+lJROaQ5mWVv7Symfd4DzgYIHQIeAqhF/OkdjJzbkScEKh8SeDb/STPJupknNnhVih+chbpOjSHwh3kFUNP2MMM+TUs2ovL+H2QuTF5MfiuxaA8GBdqz8Gj34OCZ0IENWPqojl7OTsGfGoyNdT0mGtmsA+M+BmVUbI/7pZqUXo3X1zsdqzhjfWBi44Lf2xQOTP2wuOlM/Woa2WjlUy9GJ420S8w5KSBstB5Q1b30ZQ/l+5gvVOuXXau3Kt0bl4NY9UCJGib+YuoXjbgpAtRN6Aat28YP8qyLYX0JQ== Received: from AM7PR03MB6660.eurprd03.prod.outlook.com (2603:10a6:20b:1c1::22) by AS8PR03MB6886.eurprd03.prod.outlook.com (2603:10a6:20b:23c::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4415.15; Wed, 11 Aug 2021 01:18:19 +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.4394.023; Wed, 11 Aug 2021 01:18:19 +0000 From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Wed, 11 Aug 2021 03:17:49 +0200 Message-ID: X-Mailer: git-send-email 2.30.2 In-Reply-To: References: X-TMN: [HZOee2JrVAbn4ui3lssDQYcQSWJAarC2] X-ClientProxiedBy: FR3P281CA0032.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:1c::13) To AM7PR03MB6660.eurprd03.prod.outlook.com (2603:10a6:20b:1c1::22) X-Microsoft-Original-Message-ID: <20210811011753.739659-3-andreas.rheinhardt@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from sblaptop.fritz.box (188.192.95.102) by FR3P281CA0032.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:1c::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4415.5 via Frontend Transport; Wed, 11 Aug 2021 01:18:19 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 76da6709-6010-41d3-c675-08d95c65e774 X-MS-Exchange-SLBlob-MailProps: S/btQ8cKWiT4+P6zBac8zxhOSuRwKn5livLxJ7B0lLSF2v9q8pqtvH6PMMBS3GZE58rcVrvPrdC1PFI8kvYymUrsLGN/FZTJ6GiXb08y40uFn68If3US1NgmxQger9DpvEifzUakXAsKAgfcM41IFIGJRiRfv9jr1i/u0QiYFyAv7LsEa4Be9xx2puunGDDGy6Us/jZCX+MRKwjvFo0btNvVNWuEFmfSEZBnRSlqtEP7kcqyMVVrYuPq4HIXTG6SWbGkG/bG6rzRBRVhRcGNJa9/NsakK7Ywew02QxaIjJbbM9SmlZKW1rvtypDIGptAV10XzO1IxRVOpEWmesNKXsfPqUjff3O0EVrPYGO6umXzRFOnq/5pVCyAYS22YAgc3g5zqzI+1Di9xncXMq2fqDUzHSvVuwfVMu6hkGmPR/dCDlSc3Ei0LOiWlVOanp4gBq9icLHH+q/6RGCi8UKlIjJjEbar0EaUf4/CTRZVWBmHVamZdUgt1/Am4Rcf1377H8Bf6/dZFkt3BZbtidNRU7+/E9RbHBCp6D0SzEdF5suYcLgQPUI1ejl5EM8QwRg3MlRL+CVGtV8vnPR7VBmE4+f0FZnCRSj6ZGEut7clrUpcrJVmiKtsBNlFJitg5OolypcwIBb9hxlnLa/DkQ8MPHi4YbCbriefIIhnE+zyPnqMTBrtI0OPEYj7zESP3I7xoZ9Fai4mf8YbKw3C82RSSKBwq6028wDlXkB1jFnIYQnn1LqIwTzHSYNMnMpf00iDO9P3WDv2ClI= X-MS-TrafficTypeDiagnostic: AS8PR03MB6886: X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 0RDpoDcEyCb4liPpfpf1cHNHHc8cihugkZsQSGXy0gRvxB5Jg+sWjb/mnjT7MWN+aKBMW8zVclFoRHfdnA1mgq7IscS2CoZZjOCRL/XX+Gai82JHrh4/2EM2oeDISJfKoIeOByWwnuVqfiQo+AjCJQemVxfq+j1zY737jIaCj2+o0Yc2b0psqh61c7sn4lopXSLrMVNkPdl/Q6fqAmFa+5WWjXoXsbq5w7qmi4PzML9wMYtV9DdksoWy8C0hx7Jpy6MPxbcrH3EdpvOBk2Pxl96LkiTWsfSUc+w/53dVnFB9H5tHow43n/Nod7V60SaignYBnj1d6nqHg7iTuzVYD4B8x6bbGqbZYMQEELuaqezh2epcvkr9cIfjCRIsoExcsHZq+Mp29VUmqPmeSQb+Px13A2eviihwlKC52K9uB1t0aQYI0ZIQCeIiPW7BL1Z3 X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: B78JWe8BuhAz2xeB6xHT8gBKSdYaODymnBaq4OO4HBHQEe3k/0qdrpvKmozgqwx8vll7pxLxgcUUP17lifYGTKTwe3jsyLicFmYPWAugyK63LaYDwRTty96VanJnQgZfKCuV97UcprtB/U3hm2Vh9w== X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 76da6709-6010-41d3-c675-08d95c65e774 X-MS-Exchange-CrossTenant-AuthSource: AM7PR03MB6660.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Aug 2021 01:18:19.6239 (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: AS8PR03MB6886 Subject: [FFmpeg-devel] [PATCH 06/10] avfilter: Avoid allocation of AVFilterGraphInternal 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: 9yPPBAJ8IVsv This can be achieved by allocating it together with AVFilterGraph, with the public AVFilterGraph as first element in the new structure. Given that said structure is now more than just the internal, it has been renamed to FFFilterGraph. Accessing it is not type-safe, so this unsafety has been confined to a single function. This breaks ABI due to the removal of the removal of the AVFilterGraph.internal pointer. Signed-off-by: Andreas Rheinhardt --- This one is fairly easy due to the internal not being used much; I also followed Nicolas suggestion to factor the unsafe code out into a dedicated function. libavfilter/avfilter.c | 6 +++--- libavfilter/avfilter.h | 7 ------- libavfilter/avfiltergraph.c | 21 +++++++-------------- libavfilter/internal.h | 10 ++++++++-- libavfilter/pthread.c | 20 +++++++++++--------- 5 files changed, 29 insertions(+), 35 deletions(-) diff --git a/libavfilter/avfilter.c b/libavfilter/avfilter.c index c04aefcaa8..7e48ff14c5 100644 --- a/libavfilter/avfilter.c +++ b/libavfilter/avfilter.c @@ -167,7 +167,7 @@ int avfilter_link(AVFilterContext *src, unsigned srcpad, link->type = src->output_pads[srcpad].type; av_assert0(AV_PIX_FMT_NONE == -1 && AV_SAMPLE_FMT_NONE == -1); link->format = -1; - ff_framequeue_init(&link->fifo, &src->graph->internal->frame_queues); + ff_framequeue_init(&link->fifo, &filtergraph(src->graph)->frame_queues); return 0; } @@ -868,9 +868,9 @@ int avfilter_init_dict(AVFilterContext *ctx, AVDictionary **options) if (ctx->filter->flags & AVFILTER_FLAG_SLICE_THREADS && ctx->thread_type & ctx->graph->thread_type & AVFILTER_THREAD_SLICE && - ctx->graph->internal->thread_execute) { + filtergraph(ctx->graph)->thread_execute) { ctx->thread_type = AVFILTER_THREAD_SLICE; - ctx->internal->execute = ctx->graph->internal->thread_execute; + ctx->internal->execute = filtergraph(ctx->graph)->thread_execute; } else { ctx->thread_type = 0; } diff --git a/libavfilter/avfilter.h b/libavfilter/avfilter.h index 360f63bc45..4436eb7d2d 100644 --- a/libavfilter/avfilter.h +++ b/libavfilter/avfilter.h @@ -758,8 +758,6 @@ int avfilter_insert_filter(AVFilterLink *link, AVFilterContext *filt, */ const AVClass *avfilter_get_class(void); -typedef struct AVFilterGraphInternal AVFilterGraphInternal; - /** * A function pointer passed to the @ref AVFilterGraph.execute callback to be * executed multiple times, possibly in parallel. @@ -817,11 +815,6 @@ typedef struct AVFilterGraph { */ int nb_threads; - /** - * Opaque object for libavfilter internal use. - */ - AVFilterGraphInternal *internal; - /** * Opaque user data. May be set by the caller to an arbitrary value, e.g. to * be used from callbacks like @ref AVFilterGraph.execute. diff --git a/libavfilter/avfiltergraph.c b/libavfilter/avfiltergraph.c index f6bbcd8578..f8a2426c46 100644 --- a/libavfilter/avfiltergraph.c +++ b/libavfilter/avfiltergraph.c @@ -82,21 +82,15 @@ int ff_graph_thread_init(AVFilterGraph *graph) AVFilterGraph *avfilter_graph_alloc(void) { - AVFilterGraph *ret = av_mallocz(sizeof(*ret)); + FFFilterGraph *const ret = av_mallocz(sizeof(*ret)); if (!ret) return NULL; - ret->internal = av_mallocz(sizeof(*ret->internal)); - if (!ret->internal) { - av_freep(&ret); - return NULL; - } + ret->pub.av_class = &filtergraph_class; + av_opt_set_defaults(&ret->pub); + ff_framequeue_global_init(&ret->frame_queues); - ret->av_class = &filtergraph_class; - av_opt_set_defaults(ret); - ff_framequeue_global_init(&ret->internal->frame_queues); - - return ret; + return &ret->pub; } void ff_filter_graph_remove_filter(AVFilterGraph *graph, AVFilterContext *filter) @@ -132,7 +126,6 @@ void avfilter_graph_free(AVFilterGraph **graph) av_freep(&(*graph)->scale_sws_opts); av_freep(&(*graph)->aresample_swr_opts); av_freep(&(*graph)->filters); - av_freep(&(*graph)->internal); av_freep(graph); } @@ -170,9 +163,9 @@ AVFilterContext *avfilter_graph_alloc_filter(AVFilterGraph *graph, { AVFilterContext **filters, *s; - if (graph->thread_type && !graph->internal->thread_execute) { + if (graph->thread_type && !filtergraph(graph)->thread_execute) { if (graph->execute) { - graph->internal->thread_execute = graph->execute; + filtergraph(graph)->thread_execute = graph->execute; } else { int ret = ff_graph_thread_init(graph); if (ret < 0) { diff --git a/libavfilter/internal.h b/libavfilter/internal.h index 6c908690b4..2d1dab5788 100644 --- a/libavfilter/internal.h +++ b/libavfilter/internal.h @@ -122,11 +122,17 @@ struct AVFilterPad { int needs_writable; }; -struct AVFilterGraphInternal { +typedef struct FFFilterGraph { + AVFilterGraph pub; void *thread; avfilter_execute_func *thread_execute; FFFrameQueueGlobal frame_queues; -}; +} FFFilterGraph; + +static av_always_inline FFFilterGraph *filtergraph(AVFilterGraph *graph) +{ + return (FFFilterGraph*)graph; +} struct AVFilterInternal { avfilter_execute_func *execute; diff --git a/libavfilter/pthread.c b/libavfilter/pthread.c index 34fc699505..0b8e98f60e 100644 --- a/libavfilter/pthread.c +++ b/libavfilter/pthread.c @@ -59,7 +59,7 @@ static void slice_thread_uninit(ThreadContext *c) static int thread_execute(AVFilterContext *ctx, avfilter_action_func *func, void *arg, int *ret, int nb_jobs) { - ThreadContext *c = ctx->graph->internal->thread; + ThreadContext *const c = filtergraph(ctx->graph)->thread; if (nb_jobs <= 0) return 0; @@ -82,6 +82,7 @@ static int thread_init_internal(ThreadContext *c, int nb_threads) int ff_graph_thread_init(AVFilterGraph *graph) { + FFFilterGraph *const internal = filtergraph(graph); int ret; if (graph->nb_threads == 1) { @@ -89,27 +90,28 @@ int ff_graph_thread_init(AVFilterGraph *graph) return 0; } - graph->internal->thread = av_mallocz(sizeof(ThreadContext)); - if (!graph->internal->thread) + internal->thread = av_mallocz(sizeof(ThreadContext)); + if (!internal->thread) return AVERROR(ENOMEM); - ret = thread_init_internal(graph->internal->thread, graph->nb_threads); + ret = thread_init_internal(internal->thread, graph->nb_threads); if (ret <= 1) { - av_freep(&graph->internal->thread); + av_freep(&internal->thread); graph->thread_type = 0; graph->nb_threads = 1; return (ret < 0) ? ret : 0; } graph->nb_threads = ret; - graph->internal->thread_execute = thread_execute; + internal->thread_execute = thread_execute; return 0; } void ff_graph_thread_free(AVFilterGraph *graph) { - if (graph->internal->thread) - slice_thread_uninit(graph->internal->thread); - av_freep(&graph->internal->thread); + FFFilterGraph *const internal = filtergraph(graph); + if (internal->thread) + slice_thread_uninit(internal->thread); + av_freep(&internal->thread); }