From patchwork Thu Jul 13 10:55:37 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 42658 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:6da1:b0:131:a7d0:bc6d with SMTP id gl33csp2824116pzb; Thu, 13 Jul 2023 04:01:24 -0700 (PDT) X-Google-Smtp-Source: APBJJlEBoIYip7V90Fok3+hkjOTH1dZJeidLOQD+DpzKiSRboqgAnCkXlt0as6C2CFV1JFNO4YNf X-Received: by 2002:a05:6512:68e:b0:4f8:770f:1b08 with SMTP id t14-20020a056512068e00b004f8770f1b08mr957431lfe.13.1689246084321; Thu, 13 Jul 2023 04:01:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689246084; cv=none; d=google.com; s=arc-20160816; b=Iz+41zdUtccUuJg24uPZ08YUULga4h2m6f9U8fECgle4+KHbMzclBaO5u0ETVJzfob dMu6XpSiuOJ7DzCkwvmlRih1yGcHzvQaZQnAWEL1ZhxzyU3o2iZHubucc8s2505W38VG cxPHCnJ9okDYqi4yC72GE1Q3k6g6azOzVkg9bfWuT8AlqPDB1mJtfWhhT12I2BinzMo+ ZtuPHRRvx5ZlJ4mPOQ1gqj7aYhXaiR7aoCfOL0Ur8+D+IMD8GvjxCiH+IG+eEiigv8jN 0eZlQ95l0pcIPW5DHzTShzG62fLLfYmNUo9XU8r18AehGODMZ6XnvMPa6H1TXhbcNHld n0vw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; 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:references:in-reply-to:message-id :date:to:from:delivered-to; bh=DpY3uwO7ohGLcmndEk1SVMAeqwVtDQBeir601wxXXTU=; fh=8ZF2QtiKOjBtyn9wuO2cMeZaLsE4aq02Bq77gGK61E8=; b=ae7ibbWoXbvXUFjk4naxDhOJ8T38l/lbkJdQkclCcIi/yaXJ9n+0tq6tqeZ9U1CN+N Ctb5v0eZjZrr3uY2KUeq95fr8gA+uV0bBgNdbclVJXi8mvwPg1Tv6qPcpCKPuJ4nVnQS VtuDgWuYlBALHlagTFu0zG9Ik9EF4K720RtQnnqrWKHP6OxsDmMLPAKG45WZoBnPTBA4 V6ixwqamLT5ger8bX7RJhllO2H4wLUEi/8QA9s4gaxWEjEIG+vNM8Y3HdOjEvE4QWSc8 3VJckyF04IEJ+VSOAtKDP+tta5CWgdnr48+M99zWlXCCJ4x3Lv7s4Cp9M22Q5L+fZRPU ZLHA== ARC-Authentication-Results: i=1; mx.google.com; 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 g7-20020aa7c587000000b0051debd504casi7162761edq.160.2023.07.13.04.01.23; Thu, 13 Jul 2023 04:01:24 -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; 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 958DB68C726; Thu, 13 Jul 2023 13:58:15 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail0.khirnov.net (red.khirnov.net [176.97.15.12]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 2F07468C656 for ; Thu, 13 Jul 2023 13:57:55 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id DEC622404EC for ; Thu, 13 Jul 2023 12:57:54 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id SK8LFGwTGnHm for ; Thu, 13 Jul 2023 12:57:54 +0200 (CEST) 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 mail0.khirnov.net (Postfix) with ESMTPS id D0FF8240D1F for ; Thu, 13 Jul 2023 12:57:41 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id B41A23A1889 for ; Thu, 13 Jul 2023 12:57:35 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Thu, 13 Jul 2023 12:55:37 +0200 Message-Id: <20230713105553.21052-17-anton@khirnov.net> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230713105553.21052-1-anton@khirnov.net> References: <20230713105553.21052-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 17/33] fftools/ffmpeg_mux_init: return error codes from metadata processing instead of aborting 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: rHw8elfpOuU0 --- fftools/ffmpeg_mux_init.c | 63 ++++++++++++++++++++++++--------------- 1 file changed, 39 insertions(+), 24 deletions(-) diff --git a/fftools/ffmpeg_mux_init.c b/fftools/ffmpeg_mux_init.c index b0befb8924..2bd152039d 100644 --- a/fftools/ffmpeg_mux_init.c +++ b/fftools/ffmpeg_mux_init.c @@ -1851,8 +1851,8 @@ fail: * @param index for type c/p, chapter/program index is written here * @param stream_spec for type s, the stream specifier is written here */ -static void parse_meta_type(void *logctx, const char *arg, - char *type, int *index, const char **stream_spec) +static int parse_meta_type(void *logctx, const char *arg, + char *type, int *index, const char **stream_spec) { if (*arg) { *type = *arg; @@ -1862,7 +1862,7 @@ static void parse_meta_type(void *logctx, const char *arg, case 's': if (*(++arg) && *arg != ':') { av_log(logctx, AV_LOG_FATAL, "Invalid metadata specifier %s.\n", arg); - exit_program(1); + return AVERROR(EINVAL); } *stream_spec = *arg == ':' ? arg + 1 : ""; break; @@ -1873,14 +1873,16 @@ static void parse_meta_type(void *logctx, const char *arg, break; default: av_log(logctx, AV_LOG_FATAL, "Invalid metadata type %c.\n", *arg); - exit_program(1); + return AVERROR(EINVAL); } } else *type = 'g'; + + return 0; } -static void of_add_metadata(OutputFile *of, AVFormatContext *oc, - const OptionsContext *o) +static int of_add_metadata(OutputFile *of, AVFormatContext *oc, + const OptionsContext *o) { for (int i = 0; i < o->nb_metadata; i++) { AVDictionary **m; @@ -1892,11 +1894,14 @@ static void of_add_metadata(OutputFile *of, AVFormatContext *oc, if (!val) { av_log(of, AV_LOG_FATAL, "No '=' character in metadata string %s.\n", o->metadata[i].u.str); - exit_program(1); + return AVERROR(EINVAL); } *val++ = 0; - parse_meta_type(of, o->metadata[i].specifier, &type, &index, &stream_spec); + ret = parse_meta_type(of, o->metadata[i].specifier, &type, &index, &stream_spec); + if (ret < 0) + return ret; + if (type == 's') { for (int j = 0; j < oc->nb_streams; j++) { OutputStream *ost = of->streams[j]; @@ -1922,7 +1927,7 @@ static void of_add_metadata(OutputFile *of, AVFormatContext *oc, } #endif } else if (ret < 0) - exit_program(1); + return ret; } } else { switch (type) { @@ -1932,24 +1937,26 @@ static void of_add_metadata(OutputFile *of, AVFormatContext *oc, case 'c': if (index < 0 || index >= oc->nb_chapters) { av_log(of, AV_LOG_FATAL, "Invalid chapter index %d in metadata specifier.\n", index); - exit_program(1); + return AVERROR(EINVAL); } m = &oc->chapters[index]->metadata; break; case 'p': if (index < 0 || index >= oc->nb_programs) { av_log(of, AV_LOG_FATAL, "Invalid program index %d in metadata specifier.\n", index); - exit_program(1); + return AVERROR(EINVAL); } m = &oc->programs[index]->metadata; break; default: av_log(of, AV_LOG_FATAL, "Invalid metadata specifier %s.\n", o->metadata[i].specifier); - exit_program(1); + return AVERROR(EINVAL); } av_dict_set(m, o->metadata[i].u.str, *val ? val : NULL, 0); } } + + return 0; } static int copy_chapters(InputFile *ifile, OutputFile *ofile, AVFormatContext *os, @@ -2008,8 +2015,11 @@ static int copy_metadata(Muxer *mux, AVFormatContext *ic, const char *istream_spec = NULL, *ostream_spec = NULL; int idx_in = 0, idx_out = 0; - parse_meta_type(mux, inspec, &type_in, &idx_in, &istream_spec); - parse_meta_type(mux, outspec, &type_out, &idx_out, &ostream_spec); + ret = parse_meta_type(mux, inspec, &type_in, &idx_in, &istream_spec); + if (ret >= 0) + ret = parse_meta_type(mux, outspec, &type_out, &idx_out, &ostream_spec); + if (ret < 0) + return ret; if (type_in == 'g' || type_out == 'g' || !*outspec) *metadata_global_manual = 1; @@ -2026,7 +2036,7 @@ static int copy_metadata(Muxer *mux, AVFormatContext *ic, if ((index) < 0 || (index) >= (nb_elems)) {\ av_log(mux, AV_LOG_FATAL, "Invalid %s index %d while processing metadata maps.\n",\ (desc), (index));\ - exit_program(1);\ + return AVERROR(EINVAL);\ } #define SET_DICT(type, meta, context, index)\ @@ -2057,11 +2067,11 @@ static int copy_metadata(Muxer *mux, AVFormatContext *ic, meta_in = &ic->streams[i]->metadata; break; } else if (ret < 0) - exit_program(1); + return ret; } if (!meta_in) { av_log(mux, AV_LOG_FATAL, "Stream specifier %s does not match any streams.\n", istream_spec); - exit_program(1); + return AVERROR(EINVAL); } } @@ -2071,7 +2081,7 @@ static int copy_metadata(Muxer *mux, AVFormatContext *ic, meta_out = &oc->streams[i]->metadata; av_dict_copy(meta_out, *meta_in, AV_DICT_DONT_OVERWRITE); } else if (ret < 0) - exit_program(1); + return ret; } } else av_dict_copy(meta_out, *meta_in, AV_DICT_DONT_OVERWRITE); @@ -2087,6 +2097,7 @@ static int copy_meta(Muxer *mux, const OptionsContext *o) int metadata_global_manual = 0; int metadata_streams_manual = 0; int metadata_chapters_manual = 0; + int ret; /* copy metadata */ for (int i = 0; i < o->nb_metadata_map; i++) { @@ -2098,11 +2109,13 @@ static int copy_meta(Muxer *mux, const OptionsContext *o) "processing metadata maps\n", in_file_index); return AVERROR(EINVAL); } - copy_metadata(mux, - in_file_index >= 0 ? input_files[in_file_index]->ctx : NULL, - o->metadata_map[i].specifier, *p ? p + 1 : p, - &metadata_global_manual, &metadata_streams_manual, - &metadata_chapters_manual); + ret = copy_metadata(mux, + in_file_index >= 0 ? input_files[in_file_index]->ctx : NULL, + o->metadata_map[i].specifier, *p ? p + 1 : p, + &metadata_global_manual, &metadata_streams_manual, + &metadata_chapters_manual); + if (ret < 0) + return ret; } /* copy chapters */ @@ -2541,7 +2554,9 @@ int of_open(const OptionsContext *o, const char *filename) if (err < 0) return err; - of_add_metadata(of, oc, o); + err = of_add_metadata(of, oc, o); + if (err < 0) + return err; err = set_dispositions(mux, o); if (err < 0) {