From patchwork Sun Aug 15 09:55:37 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 29530 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6602:2a4a:0:0:0:0 with SMTP id k10csp1104330iov; Sun, 15 Aug 2021 02:57:07 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwvgcQ8V8T67IEVnKnE/evYNnHAbYmYZdik+4oKKfj25anXi/H+/afrxnwoI0C8jqXydQV+ X-Received: by 2002:a17:906:3bc3:: with SMTP id v3mr10875263ejf.482.1629021427644; Sun, 15 Aug 2021 02:57:07 -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 bq14si7142982edb.57.2021.08.15.02.57.07; Sun, 15 Aug 2021 02:57:07 -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=oubKci5q; 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 C797768A214; Sun, 15 Aug 2021 12:56:24 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from EUR02-AM5-obe.outbound.protection.outlook.com (mail-oln040092067105.outbound.protection.outlook.com [40.92.67.105]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 42404689B43 for ; Sun, 15 Aug 2021 12:56:21 +0300 (EEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=nzQtZrxiws1pbsketr40pv0PCl0qccKmq3RQd7Un/ULyqVRYQKmKtZNp/ZaFYc+5DCbE0yqEAPE7UZdgp1RskVNBihzl2+DWJY7GVGFp3gFWa6BdJmKhQhNJ5+5IkWS5l519XJ0aassI5t2ySban617f9cmD7NyWvr1urc55WM/qru+Lb62Ezmg4aKetJx1sS7Tkui0hEZt5Vgu2mWd7vwWQedQvIw/gnWEfCQSRcXkrqp9gYla//35mh9NM3B4vtxOyHPrD7xq8mfDxjpXcfRDi7Acpq6629i/9CA81HPhIlwN1zC3dVKOaCQF6ZgV4kmvMRfzhOIglKkGuiCpKCw== 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=iXVlzC2JE5OmOoqK30dfRDgNCNCVh5kUK9JKNtESVp0=; b=O0ByYstE6Nwow8Osft7UifIMvn6zyiBAnLSe09H2DCcSBlTSmy7/2HSAzuIfP2aUjt/p5FL4qYj/pg8YbGrNLh1a0u84AbAyiWtpbc2hGR8NQ2ExjqH72gEG9B6UuwyKF2XPTUlkFSKAltbmcwOU6f6UEM6/4yTiTE1lrjbdeoi4d8D6SfrB3cVRiSWxSPQTiyut/R4b/lgdvTLhNtB+TmdO2QVQQgcn5ZmoXlTvy9VvLsSDGVFrG36DDMPA9f0PG+wA0uvGjx7RgJG+gREZs6hYZ6iM2ZFk/wMpHuVtOkdQGUtickN9iWDj5CCdPqQ9CVIPtSgM0ixJKl5FjqyLoQ== 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=iXVlzC2JE5OmOoqK30dfRDgNCNCVh5kUK9JKNtESVp0=; b=oubKci5qn/WW15E9ATLCrKCi8HL0jdIozn2GBfz6coiicRs0cxAEJ4ZWIxS1QHkv0wr3D0w87SlUV1uxENkj7vcY9E6vVDXUTuk5v//N6ykMMYcXG/r/I+fg16KbYswltkMzKKDVUOOxnBpUMZOfgw9913rjhG8ygICei92tjHt4geD++NjzhNbi0+46AR6rRKpIzRcOAeuE0KqpwuhbVVZ+JRUZsR/DoWoURP7xMm/lA/YPMFXYOj8EcCPqr6C+kdjpbVkWxmjwKjx6pCokwpFkXaiAjdk06vqajEvzRZAOGI6c4fV1gqgNm25NVhHHOOujEhQmskWs7pRm6x0AiA== Received: from AM7PR03MB6660.eurprd03.prod.outlook.com (2603:10a6:20b:1c1::22) by AM6PR03MB5542.eurprd03.prod.outlook.com (2603:10a6:20b:f8::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4415.14; Sun, 15 Aug 2021 09:56:10 +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.022; Sun, 15 Aug 2021 09:56:10 +0000 From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Sun, 15 Aug 2021 11:55:37 +0200 Message-ID: X-Mailer: git-send-email 2.30.2 In-Reply-To: References: X-TMN: [dGAVdqGGmHErV5roCN4DWGu6BMqEDzBd] X-ClientProxiedBy: AM4PR0202CA0005.eurprd02.prod.outlook.com (2603:10a6:200:89::15) To AM7PR03MB6660.eurprd03.prod.outlook.com (2603:10a6:20b:1c1::22) X-Microsoft-Original-Message-ID: <20210815095538.2116202-8-andreas.rheinhardt@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from sblaptop.fritz.box (188.192.142.38) by AM4PR0202CA0005.eurprd02.prod.outlook.com (2603:10a6:200:89::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4415.16 via Frontend Transport; Sun, 15 Aug 2021 09:56:10 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 68b04073-34e7-45a6-2f28-08d95fd2e8e5 X-MS-Exchange-SLBlob-MailProps: S/btQ8cKWiRlrIlNS1TwwsM0PAgDGnqzBd1f6OZZXvkYI3kLDZOn6I6xeraA4jY0zIjT00sT/ewGyVnfm+WXUh3NcZ+Go8tq6SqjuFBnoQyN3H+ksdv5gOdQaSHCnCjMA7tdbPSwiFwCuEK49Z9cKJ3JDbRpbb5W0CDyRgyhddqc3+hu8OcpGFt6KukIEP2OvkQ6vJuftOBKSuNK6dSAqJ/5c5ncb7+/IwLCA62orK7+dT6ISQfaCgF5ECWWRgD1klJuSyFMXJSHcOMcsDAi+JoperUAKgHjTY+o4WyCAjO12Am44TEwwZPy6cJD7ArDVQ05FGlFHLhNHrvBqak8d1Ooc9rRpdUY62RQmazFmrOMhkKQ1RxdlpuLOdLr4OpVogGdelKf+4N8diU/j2G/Am/9fLldOuce6JbVUrz17qF9Ecxln13e73G2kWro6MF+2C88nIflSjdcTe13Y408/b0pwQ8q4HHZjhFr1hyx3YMGZYo+05h/fghNn0NQEOQ8FAyXaXzB79e0xsmdPv95zV/gdZWlCauu9mJXt8B95O6q6FdFjIJTZyrOtKWODIfELaQJrttT8yKNFC1RwBidgO0Y4W5kctbH7ADUI2alB5YkwxQLHLM88CbEHI5jdn7o+O1mvWvyBvGnqecW3YLNoVd2MEYBBxx4pGfuhG+n6cJx10bGWmw+LTmV+cJvoAuZFn61NvmP/1ynjYtzj2k4cOTi0bkm6GqQJqBEpneoLXxnfFTNEJhPUEPrgWgAR6KnzUrIATNjKi4= X-MS-TrafficTypeDiagnostic: AM6PR03MB5542: X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: JogZzBxk0E7SQ1f2+4mBiyPbneoNEoaoS3pD7uv96V83h2VAHNllizfdXMZHYbIxhJdM8j8jDSySUU/WN/2gkKMez8DxcUzYCmoJWMWJQ9iVfC8o6RNfcGiNbpl9cUAZ3dSlG/aqSo0st1KdB2lJwUeAyAAR3V/DM3R8VXpoaDboZlPkfWj2sM7ikkGK3cmgtSY9TwX28gYfan0oFxYNo+s7SCZXCPFWhh0QRC2aqw/uYK4F8Vuis+9lBGX9HdotkzEJl48/czl2abFvzmf6kuiF+KTHnxaaPljictw6aw8YzXi8E3narPuUU69Zrlj5Xe9UCQwn/vxEnATNfRvU6r1+gcbUU3yc5pAUmMsLNG4Rb3zlgCvBUqJ43wbPVxa0LrUKlKSqiCE6zqL9W14A1it/zfafQnEOSzIm9wsbhIS4DAPVMEsM7wxvDD4BfZ9j X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: C0Fapq6tSzydCsXU+mcXTJTrKmzbxQeKH9+VXox75Mp/SKU9k10YjUL/zdZzT3F3mAURMh4gh63Ct0x8iu8/A3bFJA1JxC/FhJ5iIdSe6myALT1SarSuoZo+HnNPM3kCaOdi1tBFNr7CKxnk0mq+iA== X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 68b04073-34e7-45a6-2f28-08d95fd2e8e5 X-MS-Exchange-CrossTenant-AuthSource: AM7PR03MB6660.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Aug 2021 09:56:10.6602 (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: AM6PR03MB5542 Subject: [FFmpeg-devel] [PATCH 09/10] avfilter/formats: Don't set samplerate or channel count on video links 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: hzOsI+Guhc0v This currently happens by accident in a few filters that use ff_set_common_(samplerates|channel_layouts) like afir (if the response option is set) or agraphmonitor (due to the default code in avfiltergraph.c). So change those functions to make sure it does no longer happen. Signed-off-by: Andreas Rheinhardt --- 1. Contrary to ff_default_query_formats() the default code in avfiltergraph.c still uses ff_all_channel_layouts, not ff_all_channel_counts. I believe that this doesn't make sense and intend to change it after having inspected all filters for compatibility with the change. After it is changed, ff_default_query_formats() can be used directly. 2. These defaults can be used to e.g. remove lots of ff_set_common_all_samplerates() and calls. I will also look into this. 3. I don't like the way it is decided whether the audio components get initialized in ff_default_query_formats() and in the default code in avfiltergraph.c: In many cases this will lead to an unnecessary allocation (if the query_formats function has already set everything) and furthermore I don't think one should only look at the first input or (lacking that) the first output. Using internal per-filter flags seems more reasonable for this. 4. Just a quick question: If several links are set to individual lists that each contain exactly one element that coincides for all of these lists, then one could just as well use a shared list for all these links!? After all, in both cases the format negotiation will lead to the same result: The given format will be choosen for all these links. (E.g. vf_yadif_cuda.c can be simplified if the answer turns out to be yes (as I expect).) libavfilter/formats.c | 16 ++++++++++------ libavfilter/formats.h | 6 +++--- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/libavfilter/formats.c b/libavfilter/formats.c index cc73c5abcb..9ceb32255b 100644 --- a/libavfilter/formats.c +++ b/libavfilter/formats.c @@ -622,14 +622,16 @@ void ff_formats_changeref(AVFilterFormats **oldref, AVFilterFormats **newref) FORMATS_CHANGEREF(oldref, newref); } -#define SET_COMMON_FORMATS(ctx, fmts, ref_fn, unref_fn) \ +#define SET_COMMON_FORMATS(ctx, fmts, _type, ref_fn, unref_fn) \ int i; \ \ if (!fmts) \ return AVERROR(ENOMEM); \ \ for (i = 0; i < ctx->nb_inputs; i++) { \ - if (ctx->inputs[i] && !ctx->inputs[i]->outcfg.fmts) { \ + AVFilterLink *const link = ctx->inputs[i]; \ + if (link && !link->outcfg.fmts && \ + (_type == AVMEDIA_TYPE_UNKNOWN || link->type == _type)) { \ int ret = ref_fn(fmts, &ctx->inputs[i]->outcfg.fmts); \ if (ret < 0) { \ return ret; \ @@ -637,7 +639,9 @@ void ff_formats_changeref(AVFilterFormats **oldref, AVFilterFormats **newref) } \ } \ for (i = 0; i < ctx->nb_outputs; i++) { \ - if (ctx->outputs[i] && !ctx->outputs[i]->incfg.fmts) { \ + AVFilterLink *const link = ctx->outputs[i]; \ + if (link && !link->incfg.fmts && \ + (_type == AVMEDIA_TYPE_UNKNOWN || link->type == _type)) { \ int ret = ref_fn(fmts, &ctx->outputs[i]->incfg.fmts); \ if (ret < 0) { \ return ret; \ @@ -653,7 +657,7 @@ void ff_formats_changeref(AVFilterFormats **oldref, AVFilterFormats **newref) int ff_set_common_channel_layouts(AVFilterContext *ctx, AVFilterChannelLayouts *channel_layouts) { - SET_COMMON_FORMATS(ctx, channel_layouts, + SET_COMMON_FORMATS(ctx, channel_layouts, AVMEDIA_TYPE_AUDIO, ff_channel_layouts_ref, ff_channel_layouts_unref); } @@ -671,7 +675,7 @@ int ff_set_common_all_channel_counts(AVFilterContext *ctx) int ff_set_common_samplerates(AVFilterContext *ctx, AVFilterFormats *samplerates) { - SET_COMMON_FORMATS(ctx, samplerates, + SET_COMMON_FORMATS(ctx, samplerates, AVMEDIA_TYPE_AUDIO, ff_formats_ref, ff_formats_unref); } @@ -693,7 +697,7 @@ int ff_set_common_all_samplerates(AVFilterContext *ctx) */ int ff_set_common_formats(AVFilterContext *ctx, AVFilterFormats *formats) { - SET_COMMON_FORMATS(ctx, formats, + SET_COMMON_FORMATS(ctx, formats, AVMEDIA_TYPE_UNKNOWN, ff_formats_ref, ff_formats_unref); } diff --git a/libavfilter/formats.h b/libavfilter/formats.h index ed513c265a..bef6557578 100644 --- a/libavfilter/formats.h +++ b/libavfilter/formats.h @@ -144,9 +144,9 @@ av_warn_unused_result AVFilterChannelLayouts *ff_make_format64_list(const int64_t *fmts); /** - * A helper for query_formats() which sets all links to the same list of channel - * layouts/sample rates. If there are no links hooked to this filter, the list - * is freed. + * Helpers for query_formats() which set all free audio links to the same list + * of channel layouts/sample rates. If there are no links hooked to this list, + * the list is freed. */ av_warn_unused_result int ff_set_common_channel_layouts(AVFilterContext *ctx,