From patchwork Tue Oct 1 10:54:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 51966 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a59:cb8a:0:b0:48e:c0f8:d0de with SMTP id d10csp192162vqv; Tue, 1 Oct 2024 04:21:21 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCXjbZzezN+mW0YvpFaEhJcX+4xM7nxHibwr5CnGuhBFjbZc2fXWXDE3LSm9uYLywxXoBKHSZdgbIa7t6xJOjNGu@gmail.com X-Google-Smtp-Source: AGHT+IFMKPYfA58J7obTGf1aGRZq4fHiTXKnIWXq8H2IUV9ZUOkMdFDBIFdaysVad5YVFDoRHUZz X-Received: by 2002:a05:6402:42d6:b0:5c5:b84a:8156 with SMTP id 4fb4d7f45d1cf-5c8824e7174mr14467079a12.17.1727781680929; Tue, 01 Oct 2024 04:21:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1727781680; cv=none; d=google.com; s=arc-20240605; b=TnFa7OOyOnvVPzW6wAMG7Ayr3M1Na8wSGtdjLKMGUi+ToZpYELGvjOHP5pERbAGBQe yD9IQWCnvkL+YAOepAoj2JytEOKz/PVyrPklZkgMi9tusjp5PFRjE7rZbpyoc9GYvMN8 fuKL8LvBzdb0ZIr0gZ4PTxdBi5uBofY7DpnI2mF77wGIy7H+T4c3iMy5EGJbJTOryNEO MAnKQVfqSEJ3HA7o+LvdKII0dlSI14t/cOldE408zLKMfqECARpG2Udar3ZpEwT5XUGX XXJ0Ni3fvwHi1GvqONGij1Rs6Wx/5C7aq1+F+WGvDzENWX9TmTRa7gBJkb064AfYtO12 K6Mw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; 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:message-id:date:to:from :dkim-signature:delivered-to; bh=WxrloP/moBLACJujvSXHVvEMPlS1DV75DRHK51tQuY0=; fh=YOA8vD9MJZuwZ71F/05pj6KdCjf6jQRmzLS+CATXUQk=; b=XZUOY0TY2ICgVCXgCllc8p83aNwIp0QpPGePR1nPNRhInWEV/yIzotUnRjVcU+AZoP MSPw+5+OfING1V57bqRq4O1wpBkFt8o7akSv9X9WSfBztzyP0DEsq8YUO0rPhW5T7PBx gGhwmxXrmpi7tcA+Vmdd4spYvTwvNa8ch6tRgYp2YYW/jOqLU6kxIKNgdBoiEVwmV5ht 2hW5nb+AkqfrrOA2J8ChWFYKMWjFRxlOqo4xy9wUYBfaJIJXW76+oJpdNNQffa1/Nsqn mdNHYWjuMVGRislZ+ef30Sjt3c+4CijoVzRc2bUCWPvOXhICYcEk8dF6Q0ViGJYHVdKC 2gDQ==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@khirnov.net header.s=mail header.b=YLGMmA3R; 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 4fb4d7f45d1cf-5c883510ac6si6765520a12.186.2024.10.01.04.21.20; Tue, 01 Oct 2024 04:21:20 -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=@khirnov.net header.s=mail header.b=YLGMmA3R; 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 84C0268DC4F; Tue, 1 Oct 2024 13:54:51 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail1.khirnov.net (quelana.khirnov.net [94.230.150.81]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id E8AAF68DB8F for ; Tue, 1 Oct 2024 13:54:44 +0300 (EEST) Authentication-Results: mail1.khirnov.net; dkim=pass (2048-bit key; unprotected) header.d=khirnov.net header.i=@khirnov.net header.a=rsa-sha256 header.s=mail header.b=YLGMmA3R; dkim-atps=neutral Received: from localhost (mail1.khirnov.net [IPv6:::1]) by mail1.khirnov.net (Postfix) with ESMTP id C4C194E1E for ; Tue, 1 Oct 2024 12:54:36 +0200 (CEST) Received: from mail1.khirnov.net ([IPv6:::1]) by localhost (mail1.khirnov.net [IPv6:::1]) (amavis, port 10024) with ESMTP id bKG3qH33sv_u for ; Tue, 1 Oct 2024 12:54:36 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=khirnov.net; s=mail; t=1727780073; bh=GdsGa9XZpJLeipKUkwdDjxlYHrRRCCYflG/UlVLDPC0=; h=From:To:Subject:Date:From; b=YLGMmA3RMuo5uwsrmQWSRMm8vKUAfsu4RURVSjjIl3cKpOADKWdwG0fiKxEThg0GG B/JsWX2104WecVdw6wcYkQ0myeeuZ2PSEVAcIGiXqI9wQ80etL1h7WeEbt26x5yk1I i/ypeC9IOJgdiLmTxb0Ocgt8AEVO9n4WgSolaPDp7AQQu13VxOO3KFmT0MHGLxHe+f yvwqV8NMkeYCc0Hv4utHy11m6K2GSP4c/z+6r2kUZtOxwHHShbn7vxGXGJbXpTE3wE t/3IxOR/D5uvl29XK66H5Q0IiThgBs3uuMQw5aB9ZcLB8/FRHVsJE0FRfp5xFu+NO4 meQ5LaBfH3Zog== 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 mail1.khirnov.net (Postfix) with ESMTPS id 8ECE14E2B for ; Tue, 1 Oct 2024 12:54:33 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id B95E83A03CA for ; Tue, 01 Oct 2024 12:54:25 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Tue, 1 Oct 2024 12:54:06 +0200 Message-ID: <20241001105421.28967-1-anton@khirnov.net> X-Mailer: git-send-email 2.43.0 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 01/16] lavfi/buffersink: move the option sanity check to init 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: Q68NLvhFhTEZ Options are set before init, so that is the appropriate place to validate them. --- libavfilter/buffersink.c | 60 +++++++++++++++++++++++----------------- 1 file changed, 35 insertions(+), 25 deletions(-) diff --git a/libavfilter/buffersink.c b/libavfilter/buffersink.c index 0cfac2abd5..95cb605712 100644 --- a/libavfilter/buffersink.c +++ b/libavfilter/buffersink.c @@ -155,6 +155,41 @@ static av_cold int common_init(AVFilterContext *ctx) { BufferSinkContext *buf = ctx->priv; +#if FF_API_BUFFERSINK_OPTS + +#define CHECK_LIST_SIZE(field) \ + if (buf->field ## _size % sizeof(*buf->field)) { \ + av_log(ctx, AV_LOG_ERROR, "Invalid size for " #field ": %d, " \ + "should be multiple of %d\n", \ + buf->field ## _size, (int)sizeof(*buf->field)); \ + return AVERROR(EINVAL); \ + } + + if (ctx->input_pads[0].type == AVMEDIA_TYPE_VIDEO) { + if ((buf->pixel_fmts_size || buf->color_spaces_size || buf->color_ranges_size) && + (buf->nb_pixel_formats || buf->nb_colorspaces || buf->nb_colorranges)) { + av_log(ctx, AV_LOG_ERROR, "Cannot combine old and new format lists\n"); + return AVERROR(EINVAL); + } + + CHECK_LIST_SIZE(pixel_fmts) + CHECK_LIST_SIZE(color_spaces) + CHECK_LIST_SIZE(color_ranges) + } else { + if ((buf->sample_fmts_size || buf->channel_layouts_str || buf->sample_rates_size) && + (buf->nb_sample_formats || buf->nb_samplerates || buf->nb_channel_layouts)) { + av_log(ctx, AV_LOG_ERROR, "Cannot combine old and new format lists\n"); + return AVERROR(EINVAL); + } + + CHECK_LIST_SIZE(sample_fmts) + CHECK_LIST_SIZE(sample_rates) + } + +#undef CHECK_LIST_SIZE + +#endif + buf->warning_limit = 100; return 0; } @@ -291,14 +326,6 @@ int av_buffersink_get_ch_layout(const AVFilterContext *ctx, AVChannelLayout *out #if FF_API_BUFFERSINK_OPTS #define NB_ITEMS(list) (list ## _size / sizeof(*list)) - -#define CHECK_LIST_SIZE(field) \ - if (buf->field ## _size % sizeof(*buf->field)) { \ - av_log(ctx, AV_LOG_ERROR, "Invalid size for " #field ": %d, " \ - "should be multiple of %d\n", \ - buf->field ## _size, (int)sizeof(*buf->field)); \ - return AVERROR(EINVAL); \ - } #endif static int vsink_query_formats(AVFilterContext *ctx) @@ -307,12 +334,6 @@ static int vsink_query_formats(AVFilterContext *ctx) int ret; #if FF_API_BUFFERSINK_OPTS - if ((buf->pixel_fmts_size || buf->color_spaces_size || buf->color_ranges_size) && - (buf->nb_pixel_formats || buf->nb_colorspaces || buf->nb_colorranges)) { - av_log(ctx, AV_LOG_ERROR, "Cannot combine old and new format lists\n"); - return AVERROR(EINVAL); - } - if (buf->nb_pixel_formats || buf->nb_colorspaces || buf->nb_colorranges) { #endif if (buf->nb_pixel_formats) { @@ -333,9 +354,6 @@ static int vsink_query_formats(AVFilterContext *ctx) #if FF_API_BUFFERSINK_OPTS } else { unsigned i; - CHECK_LIST_SIZE(pixel_fmts) - CHECK_LIST_SIZE(color_spaces) - CHECK_LIST_SIZE(color_ranges) if (buf->pixel_fmts_size) { AVFilterFormats *formats = NULL; for (i = 0; i < NB_ITEMS(buf->pixel_fmts); i++) @@ -374,12 +392,6 @@ static int asink_query_formats(AVFilterContext *ctx) int ret; #if FF_API_BUFFERSINK_OPTS - if ((buf->sample_fmts_size || buf->channel_layouts_str || buf->sample_rates_size) && - (buf->nb_sample_formats || buf->nb_samplerates || buf->nb_channel_layouts)) { - av_log(ctx, AV_LOG_ERROR, "Cannot combine old and new format lists\n"); - return AVERROR(EINVAL); - } - if (buf->nb_sample_formats || buf->nb_samplerates || buf->nb_channel_layouts) { #endif if (buf->nb_sample_formats) { @@ -403,8 +415,6 @@ static int asink_query_formats(AVFilterContext *ctx) AVChannelLayout layout = { 0 }; AVFilterChannelLayouts *layouts = NULL; unsigned i; - CHECK_LIST_SIZE(sample_fmts) - CHECK_LIST_SIZE(sample_rates) if (buf->sample_fmts_size) { for (i = 0; i < NB_ITEMS(buf->sample_fmts); i++)