From patchwork Fri May 17 15:25:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 48955 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a21:3a48:b0:1af:fc2d:ff5a with SMTP id zu8csp2950964pzb; Fri, 17 May 2024 08:26:21 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCWCRv7LSET4y5l7ewpDi3gT1BTjZyDb+QR+k2xbmkXsvyGPkyXGrRsimoxQh2ihdIgFTG5AvSjQ/wlc+XXmyThmi/sCO3FX2aGpJA== X-Google-Smtp-Source: AGHT+IGRuLVWI0jHht4kY3YS8KmfBy6KCxjr+BQjqyG7dNx7bm9fTG1m7FFr02VrO+XkSXDkv6j0 X-Received: by 2002:a2e:908e:0:b0:2e7:c23:48ef with SMTP id 38308e7fff4ca-2e70c234b6cmr24395471fa.12.1715959581475; Fri, 17 May 2024 08:26:21 -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 38308e7fff4ca-2e4d0bbd5a8si52804911fa.90.2024.05.17.08.26.20; Fri, 17 May 2024 08:26:21 -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="ev6OuS6/"; 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 C77AC68D2E3; Fri, 17 May 2024 18:26:11 +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-db3eur04olkn2084.outbound.protection.outlook.com [40.92.74.84]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 8E09C68D32A for ; Fri, 17 May 2024 18:26:05 +0300 (EEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=SFVPainJs7JZcSE+Dc1WDUNN1/cIZCh+pjsdBPoDSRVlrEUGI1YbMGdi3+KUtw//Cz+ZN1iZcWWpXfwKUM/39S0NaZcuJMJkschFCQ0JwATjZfEh0ff71ZrWupUGqj8z6jqQjnoiCm8NM8TpgheAJYHHna0v9tqWiFFtmQuKEAh0rcnAiPDdmdenn/nCs4IhfvX+gCfj4I0ha2nF+IGodghDYrl6UwexY8hbEzNuQq1zx9vt1y68OmJB9lJ25vteAAh3NuBKGkX/IjyShTwWvXoRy2BDRZnZs7mrXaD49qq4JU/XHsImnHQwzVBts6c0UURjC1hflL44GP/4QlQrEg== 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-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=Jr977efLWp89ATVeuRb4Gp7wPAI2N+y5LHc3r1KABLY=; b=aFKquxtbpVD9mVuoXVb9vN25uAxhbjJqsU8ZFDT+RVRHwZbu/pvejoR3m57VXNZUKA0zKFtYkB0jJG/liUMQPj2Xar/kGjKOW3IeTWR5CyzzvBX0LKZK45Lq5iTQLVQmh+ccwumgPcAlQI2zuAzS6wcrpejlzlMPnLqQ29OOBVXJVXv0Plc0Trjw5NBlP036M0HDy0c7bRPObLkgm1As0FR7oaFo1XNPtd6L1Ub7d8/ngR2m2u8GhdNn8IO+3ZL3kHTgcNzvJ9k2zZ/k+NKs3ATKGUwZVfb2gjAsDOAbxv82RWwU4XMvEz6XzpESaLYNbsmAT8Ri4+osd8z6lYyNTw== 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=Jr977efLWp89ATVeuRb4Gp7wPAI2N+y5LHc3r1KABLY=; b=ev6OuS6/5qEBYH473aKMj0acjpi1yiBKdJKl3sMrSguMDSaoI59dXbr9BPt8Th+6d9EL3hzXmbbePHUjzVM2lVvaID7o0ZN/oZl58zpXebkP5bonhBsU7mmPTn1T2uHKc36aPzn+blpYqJhCmPxUB3+lj7rK1LrWPKbb+Ku7TNryspYW3zdxb/KMp1xGGtOO0AH0TTyVetJ/1y0XS57/cDVlUU1x/6Rr5jF9f4T7tB7QW5slMpnHFyz6mo7jJQ/jVwa39YxHqQKOaQYr0J3zrV8XgE1NVhkeRzGVrYbZJ9vKfcCzsxtvX9O3ZdtZ/bLla3Xgbv3P4l7rrpvc/H9vIg== Received: from AS8P250MB0744.EURP250.PROD.OUTLOOK.COM (2603:10a6:20b:541::14) by DU2P250MB0048.EURP250.PROD.OUTLOOK.COM (2603:10a6:10:23b::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7587.27; Fri, 17 May 2024 15:26:00 +0000 Received: from AS8P250MB0744.EURP250.PROD.OUTLOOK.COM ([fe80::384d:40d4:ecb7:1c9]) by AS8P250MB0744.EURP250.PROD.OUTLOOK.COM ([fe80::384d:40d4:ecb7:1c9%4]) with mapi id 15.20.7544.052; Fri, 17 May 2024 15:26:00 +0000 From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Fri, 17 May 2024 17:25:38 +0200 Message-ID: X-Mailer: git-send-email 2.40.1 In-Reply-To: References: X-TMN: [T3gve+cIPj7mJPxONuEBa3ALKMifMgZW1YfKbJ0YVeU=] X-ClientProxiedBy: FR0P281CA0269.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:b5::7) To AS8P250MB0744.EURP250.PROD.OUTLOOK.COM (2603:10a6:20b:541::14) X-Microsoft-Original-Message-ID: <20240517152540.3794055-3-andreas.rheinhardt@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AS8P250MB0744:EE_|DU2P250MB0048:EE_ X-MS-Office365-Filtering-Correlation-Id: 2ed60b8c-86c7-470f-b7f9-08dc7685a81a X-Microsoft-Antispam: BCL:0; ARA:14566002|461199019|440099019|3412199016|1710799017; X-Microsoft-Antispam-Message-Info: ln8WKPt71HANAT5WRf1eIFQo3qkE0J6Yoiav9LaAqrrKktk6A2UiH5loSYmKCk2CvWPjyT8IrEr45OZtZeLOra4n/9LBubXAiYk7o5N1999Hz2LBe1bQ/0dq2YL0tJG7PBvYEf91YXmv3laU6CWQGWWGBpCGD5XHYsUIRqiB2/pC0AcVy8PFNo+PPTK5MhtT09bwP9Sc8vQ069C3rrynkzIRTlSwL2SIc12VzPblvoKKHpItzhLXEYhwz1ECdgDZXbJGa54CqsBPSgQgJ2/uVDHFTJ0wJE7JN4m6bLic2aU7jupYpUETSS2HVx9vw9h5xguHGThk3yFDrIMGvtgEG2zkiUr1CbdodFJEiq2rLGw5EPPvGkXrTjjJIITiMRydwyJP3ISNq8at+mJ+CQNcisUa4QU3vTnw9+OE0vIOcSwSE81ruXor7PbNhIDQi8KSStylTxhwiQB5rEVPl3zJg1QFYYJMicby7freuxaFzKyka1UL5lNGX3HSKVrAzvw2kgyhLjUmYl3DsOl+ROZrCdToBHEzQ9T69X6KM4j50SKug8g7lYHkjH1SM3RMS3EouWJRPq7DeFqEpErptPG1VvIaGzNvsKdZWduY1bJS167bQyXR9n4rx11JnZ2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vU6VvAU1jGXXOzInnDL2omcVPY1ggNCurCWVnuv7rBcIS8ywisDfLW6cHiXQisXM0WQanu8u0F7a722/VRD0H6K6zrGXRWVOHrdUeef1pNZAbJip8QVIGue+DrZlgnscNN+2X/KydBaYtduV7gOMUtlEcKP0Sf78hFymVG0m3sP5+6XvmW2KKR3WZQWmrjpeJm5d4LmmF8ys/P/bTm8UJMSb29tqv/rZRZrfGoCZ/FujAtB/AW0zT6eRV22tOCORgTLSClSZLugPBLVVv1Xl6XALBumQ== X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 2ed60b8c-86c7-470f-b7f9-08dc7685a81a X-MS-Exchange-CrossTenant-AuthSource: AS8P250MB0744.EURP250.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 May 2024 15:26:00.4460 (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: DU2P250MB0048 Subject: [FFmpeg-devel] [PATCH 4/6] avformat/tee: Use smaller scope for variables 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: w6XqscWzd82w Signed-off-by: Andreas Rheinhardt --- libavformat/tee.c | 71 +++++++++++++++++++++++------------------------ 1 file changed, 35 insertions(+), 36 deletions(-) diff --git a/libavformat/tee.c b/libavformat/tee.c index 87159681ed..0c0543fa65 100644 --- a/libavformat/tee.c +++ b/libavformat/tee.c @@ -119,7 +119,6 @@ static int parse_slave_fifo_options(const char *fifo_options, TeeSlave *tee_slav static int close_slave(TeeSlave *tee_slave) { AVFormatContext *avf; - unsigned i; int ret = 0; av_dict_free(&tee_slave->fifo_options); @@ -131,7 +130,7 @@ static int close_slave(TeeSlave *tee_slave) ret = av_write_trailer(avf); if (tee_slave->bsfs) { - for (i = 0; i < avf->nb_streams; ++i) + for (unsigned i = 0; i < avf->nb_streams; ++i) av_bsf_free(&tee_slave->bsfs[i]); } av_freep(&tee_slave->stream_map); @@ -146,9 +145,8 @@ static int close_slave(TeeSlave *tee_slave) static void close_slaves(AVFormatContext *avf) { TeeContext *tee = avf->priv_data; - unsigned i; - for (i = 0; i < tee->nb_slaves; i++) { + for (unsigned i = 0; i < tee->nb_slaves; i++) { close_slave(&tee->slaves[i]); } av_freep(&tee->slaves); @@ -156,14 +154,12 @@ static void close_slaves(AVFormatContext *avf) static int open_slave(AVFormatContext *avf, char *slave, TeeSlave *tee_slave) { - int i, ret; + int ret; AVDictionary *options = NULL, *bsf_options = NULL; const AVDictionaryEntry *entry; char *filename; - char *format = NULL, *select = NULL, *on_fail = NULL; - char *use_fifo = NULL, *fifo_options_str = NULL; + char *format = NULL, *select = NULL; AVFormatContext *avf2 = NULL; - AVStream *st, *st2; int stream_count; int fullret; char *subselect = NULL, *next_subselect = NULL, *first_subselect = NULL, *tmp_select = NULL; @@ -181,22 +177,25 @@ static int open_slave(AVFormatContext *avf, char *slave, TeeSlave *tee_slave) } while (0) #define STEAL_OPTION(option, field) \ CONSUME_OPTION(option, field, \ - entry->value = NULL; /* prevent it from being freed */) -#define PROCESS_OPTION(option, field, function, on_error) \ - CONSUME_OPTION(option, field, if ((ret = function) < 0) { { on_error } goto end; }) + en->value = NULL; /* prevent it from being freed */) +#define PROCESS_OPTION(option, function, on_error) do { \ + const char *value; \ + CONSUME_OPTION(option, value, if ((ret = function) < 0) \ + { { on_error } goto end; }); \ + } while (0) STEAL_OPTION("f", format); STEAL_OPTION("select", select); - PROCESS_OPTION("onfail", on_fail, - parse_slave_failure_policy_option(on_fail, tee_slave), + PROCESS_OPTION("onfail", + parse_slave_failure_policy_option(value, tee_slave), av_log(avf, AV_LOG_ERROR, "Invalid onfail option value, " "valid options are 'abort' and 'ignore'\n");); - PROCESS_OPTION("use_fifo", use_fifo, - parse_slave_fifo_policy(use_fifo, tee_slave), + PROCESS_OPTION("use_fifo", + parse_slave_fifo_policy(value, tee_slave), av_log(avf, AV_LOG_ERROR, "Error parsing fifo options: %s\n", av_err2str(ret));); - PROCESS_OPTION("fifo_options", fifo_options_str, - parse_slave_fifo_options(fifo_options_str, tee_slave), ;); + PROCESS_OPTION("fifo_options", + parse_slave_fifo_options(value, tee_slave), ;); entry = NULL; while ((entry = av_dict_get(options, "bsfs", entry, AV_DICT_IGNORE_SUFFIX))) { /* trim out strlen("bsfs") characters from key */ @@ -250,8 +249,9 @@ static int open_slave(AVFormatContext *avf, char *slave, TeeSlave *tee_slave) } stream_count = 0; - for (i = 0; i < avf->nb_streams; i++) { - st = avf->streams[i]; + for (unsigned i = 0; i < avf->nb_streams; i++) { + const AVStream *st = avf->streams[i]; + AVStream *st2; if (select) { tmp_select = av_strdup(select); // av_strtok is destructive so we regenerate it in each loop if (!tmp_select) { @@ -326,7 +326,7 @@ static int open_slave(AVFormatContext *avf, char *slave, TeeSlave *tee_slave) spec++; /* consume separator */ } - for (i = 0; i < avf2->nb_streams; i++) { + for (unsigned i = 0; i < avf2->nb_streams; i++) { ret = avformat_match_stream_specifier(avf2, avf2->streams[i], spec); if (ret < 0) { av_log(avf, AV_LOG_ERROR, @@ -357,7 +357,7 @@ static int open_slave(AVFormatContext *avf, char *slave, TeeSlave *tee_slave) av_dict_set(&bsf_options, entry->key, NULL, 0); } - for (i = 0; i < avf->nb_streams; i++){ + for (unsigned i = 0; i < avf->nb_streams; i++){ int target_stream = tee_slave->stream_map[i]; if (target_stream < 0) continue; @@ -407,10 +407,9 @@ end: static void log_slave(TeeSlave *slave, void *log_ctx, int log_level) { - int i; av_log(log_ctx, log_level, "filename:'%s' format:%s\n", slave->avf->url, slave->avf->oformat->name); - for (i = 0; i < slave->avf->nb_streams; i++) { + for (unsigned i = 0; i < slave->avf->nb_streams; i++) { AVStream *st = slave->avf->streams[i]; AVBSFContext *bsf = slave->bsfs[i]; const char *bsf_name; @@ -450,7 +449,7 @@ static int tee_process_slave_failure(AVFormatContext *avf, unsigned slave_idx, i static int tee_write_header(AVFormatContext *avf) { TeeContext *tee = avf->priv_data; - unsigned nb_slaves = 0, i; + unsigned nb_slaves = 0; const char *filename = avf->url; char **slaves = NULL; int ret; @@ -476,7 +475,7 @@ static int tee_write_header(AVFormatContext *avf) } tee->nb_slaves = tee->nb_alive = nb_slaves; - for (i = 0; i < nb_slaves; i++) { + for (unsigned i = 0; i < nb_slaves; i++) { tee->slaves[i].use_fifo = tee->use_fifo; ret = av_dict_copy(&tee->slaves[i].fifo_options, tee->fifo_options, 0); @@ -493,9 +492,9 @@ static int tee_write_header(AVFormatContext *avf) av_freep(&slaves[i]); } - for (i = 0; i < avf->nb_streams; i++) { - int j, mapped = 0; - for (j = 0; j < tee->nb_slaves; j++) + for (unsigned i = 0; i < avf->nb_streams; i++) { + int mapped = 0; + for (unsigned j = 0; j < tee->nb_slaves; j++) if (tee->slaves[j].avf) mapped += tee->slaves[j].stream_map[i] >= 0; if (!mapped) @@ -506,7 +505,7 @@ static int tee_write_header(AVFormatContext *avf) return 0; fail: - for (i = 0; i < nb_slaves; i++) + for (unsigned i = 0; i < nb_slaves; i++) av_freep(&slaves[i]); close_slaves(avf); av_free(slaves); @@ -517,9 +516,8 @@ static int tee_write_trailer(AVFormatContext *avf) { TeeContext *tee = avf->priv_data; int ret_all = 0, ret; - unsigned i; - for (i = 0; i < tee->nb_slaves; i++) { + for (unsigned i = 0; i < tee->nb_slaves; i++) { if ((ret = close_slave(&tee->slaves[i])) < 0) { ret = tee_process_slave_failure(avf, i, ret); if (!ret_all && ret < 0) @@ -533,15 +531,16 @@ static int tee_write_trailer(AVFormatContext *avf) static int tee_write_packet(AVFormatContext *avf, AVPacket *pkt) { TeeContext *tee = avf->priv_data; - AVFormatContext *avf2; - AVBSFContext *bsfs; AVPacket *const pkt2 = ffformatcontext(avf)->pkt; int ret_all = 0, ret; - unsigned i, s; + unsigned s; int s2; - for (i = 0; i < tee->nb_slaves; i++) { - if (!(avf2 = tee->slaves[i].avf)) + for (unsigned i = 0; i < tee->nb_slaves; i++) { + AVFormatContext *avf2 = tee->slaves[i].avf; + AVBSFContext *bsfs; + + if (!avf2) continue; /* Flush slave if pkt is NULL*/