From patchwork Mon Dec 18 09:57:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 45219 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:1225:b0:181:818d:5e7f with SMTP id v37csp7222599pzf; Mon, 18 Dec 2023 02:00:23 -0800 (PST) X-Google-Smtp-Source: AGHT+IG7b4WkAZhEoAYjufhIyhpBDANyyrnKEvVBsHeoB7TjemshA5dd05kFznuy+EMDFOpFSo6R X-Received: by 2002:a05:6512:68e:b0:50b:eadf:f16e with SMTP id t14-20020a056512068e00b0050beadff16emr9932471lfe.89.1702893622946; Mon, 18 Dec 2023 02:00:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702893622; cv=none; d=google.com; s=arc-20160816; b=ANPNrM3zP0qhvOJosYjnVfxd/jQXfK/8E/dMBCe8oU9CjLxNyfISLVbtAYSX11vIcw vqd6jcMQqxy9q0e8IVFF8VaJAJr3Ts912LNnxwbQNz5OxaDEjpMFsGr0OIjyfv+ggT9C 1Y9LX67ytEripHhuKExj8g2+rChut5+AuWfUd9QeH+2IjPmVoZ6jBZC2nfyqVLkTHmfc KYFdFk1fqxsNOu3fcnir71QynsypmLi+UQqIRY2uiKu7Zv4nF4ZNcnWwEJzBfRXnvMMi SYM5cM41biNe083Hdsi5ulgF+E3MAcN5WP39TFdhcuC9IsPQl76KLxd+GPvF34tiZO/a SG8Q== 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=b4yxc/bNUkCFEZWNUThZbUegO/0n8JqnbqQH78NOhc8=; fh=YOA8vD9MJZuwZ71F/05pj6KdCjf6jQRmzLS+CATXUQk=; b=qu19mErSoSD4RPsGYLTmeZoTMjN1R+M1HVu51gAi3Mi2lrnURE4faXvIAuA5oAJCAk br3jcvFxTnKX7+iVaV6MGFPhOf/MYCLj3ka4hEgWih9EfLp8oOQi7myAha4K8jaBc1Qq QRmN2rZN1icd6TTWfx0iyqGE/nM/HxSUiB8nRE/hMrhiY6uBKCf65sv30tc2rObqaI+k TYTV7pORW1xXlpmyeZNAyCW6nUNU4HgMQHVhNd3x2RYXNqS7QTM7KErkuVFXgmFDz/QJ EwO/gX+CCX4zsuH7yAF8mvmHwrJFOAo2/l25oSa1ea2pTuJ2zflgjhrdFUM6OWsyrVgO Ghqg== 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 f22-20020a17090624d600b00a236489086dsi168812ejb.884.2023.12.18.02.00.21; Mon, 18 Dec 2023 02:00:22 -0800 (PST) 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 A902668D2C6; Mon, 18 Dec 2023 11:58:17 +0200 (EET) 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 AA54268D1E6 for ; Mon, 18 Dec 2023 11:57:58 +0200 (EET) Received: from localhost (mail1.khirnov.net [IPv6:::1]) by mail1.khirnov.net (Postfix) with ESMTP id 7BF851B9A for ; Mon, 18 Dec 2023 10:57:55 +0100 (CET) Received: from mail1.khirnov.net ([IPv6:::1]) by localhost (mail1.khirnov.net [IPv6:::1]) (amavis, port 10024) with ESMTP id Pu1pKeTDc_5W for ; Mon, 18 Dec 2023 10:57:55 +0100 (CET) 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 7C6931CAF for ; Mon, 18 Dec 2023 10:57:51 +0100 (CET) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 6B7183A07CC for ; Mon, 18 Dec 2023 10:57:44 +0100 (CET) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Mon, 18 Dec 2023 10:57:13 +0100 Message-ID: <20231218095722.25879-11-anton@khirnov.net> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231218095722.25879-1-anton@khirnov.net> References: <20231218095722.25879-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 11/20] fftools/ffmpeg: change the MATCH_PER_TYPE_OPT macro into a function 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: tMqIpQpgvE4M There is no reason for it to be a macro anymore, this makes the code using it cleaner and simpler. --- fftools/cmdutils.c | 6 +++++- fftools/cmdutils.h | 2 ++ fftools/ffmpeg.h | 11 ++--------- fftools/ffmpeg_demux.c | 16 ++++++++-------- fftools/ffmpeg_mux_init.c | 4 ++-- fftools/ffmpeg_opt.c | 17 ++++++++++++++--- 6 files changed, 33 insertions(+), 23 deletions(-) diff --git a/fftools/cmdutils.c b/fftools/cmdutils.c index f53c4b7aec..26e5e6e986 100644 --- a/fftools/cmdutils.c +++ b/fftools/cmdutils.c @@ -239,14 +239,15 @@ static int write_option(void *optctx, const OptionDef *po, const char *opt, * a global var*/ void *dst = po->flags & OPT_FLAG_OFFSET ? (uint8_t *)optctx + po->u.off : po->u.dst_ptr; + SpecifierOptList *sol = NULL; double num; int ret; if (po->flags & OPT_FLAG_SPEC) { - SpecifierOptList *sol = dst; char *p = strchr(opt, ':'); char *str; + sol = dst; ret = GROW_ARRAY(sol->opt, sol->nb_opt); if (ret < 0) return ret; @@ -312,6 +313,9 @@ static int write_option(void *optctx, const OptionDef *po, const char *opt, if (po->flags & OPT_EXIT) return AVERROR_EXIT; + if (sol) + sol->type = po->type; + return 0; } diff --git a/fftools/cmdutils.h b/fftools/cmdutils.h index 8ef9a07e9e..db91b788f8 100644 --- a/fftools/cmdutils.h +++ b/fftools/cmdutils.h @@ -117,6 +117,8 @@ typedef struct SpecifierOpt { typedef struct SpecifierOptList { SpecifierOpt *opt; int nb_opt; + + enum OptionType type; } SpecifierOptList; typedef struct OptionDef { diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h index 94f70f7efb..9905d16095 100644 --- a/fftools/ffmpeg.h +++ b/fftools/ffmpeg.h @@ -802,15 +802,8 @@ void update_benchmark(const char *fmt, ...); WARN_MULTIPLE_OPT_USAGE(name, type, so, st);\ } -#define MATCH_PER_TYPE_OPT(name, type, outvar, fmtctx, mediatype)\ -{\ - int i;\ - for (i = 0; i < o->name.nb_opt; i++) {\ - char *spec = o->name.opt[i].specifier;\ - if (!strcmp(spec, mediatype))\ - outvar = o->name.opt[i].u.type;\ - }\ -} +const char *opt_match_per_type_str(const SpecifierOptList *sol, + char mediatype); extern const char * const opt_name_codec_names[]; extern const char * const opt_name_codec_tags[]; diff --git a/fftools/ffmpeg_demux.c b/fftools/ffmpeg_demux.c index 6672113bca..5594286a79 100644 --- a/fftools/ffmpeg_demux.c +++ b/fftools/ffmpeg_demux.c @@ -1334,10 +1334,10 @@ int ifile_open(const OptionsContext *o, const char *filename, Scheduler *sch) int64_t timestamp; AVDictionary *unused_opts = NULL; const AVDictionaryEntry *e = NULL; - char * video_codec_name = NULL; - char * audio_codec_name = NULL; - char *subtitle_codec_name = NULL; - char * data_codec_name = NULL; + const char* video_codec_name = NULL; + const char* audio_codec_name = NULL; + const char* subtitle_codec_name = NULL; + const char* data_codec_name = NULL; int scan_all_pmts_set = 0; int64_t start_time = o->start_time; @@ -1427,10 +1427,10 @@ int ifile_open(const OptionsContext *o, const char *filename, Scheduler *sch) if (o->frame_pix_fmts.nb_opt) av_dict_set(&o->g->format_opts, "pixel_format", o->frame_pix_fmts.opt[o->frame_pix_fmts.nb_opt - 1].u.str, 0); - MATCH_PER_TYPE_OPT(codec_names, str, video_codec_name, ic, "v"); - MATCH_PER_TYPE_OPT(codec_names, str, audio_codec_name, ic, "a"); - MATCH_PER_TYPE_OPT(codec_names, str, subtitle_codec_name, ic, "s"); - MATCH_PER_TYPE_OPT(codec_names, str, data_codec_name, ic, "d"); + video_codec_name = opt_match_per_type_str(&o->codec_names, 'v'); + audio_codec_name = opt_match_per_type_str(&o->codec_names, 'a'); + subtitle_codec_name = opt_match_per_type_str(&o->codec_names, 's'); + data_codec_name = opt_match_per_type_str(&o->codec_names, 'd'); if (video_codec_name) ret = err_merge(ret, find_codec(NULL, video_codec_name , AVMEDIA_TYPE_VIDEO , 0, diff --git a/fftools/ffmpeg_mux_init.c b/fftools/ffmpeg_mux_init.c index 6e6e8b8b6a..6dbee50d1c 100644 --- a/fftools/ffmpeg_mux_init.c +++ b/fftools/ffmpeg_mux_init.c @@ -1611,10 +1611,10 @@ static int map_auto_audio(Muxer *mux, const OptionsContext *o) static int map_auto_subtitle(Muxer *mux, const OptionsContext *o) { AVFormatContext *oc = mux->fc; - char *subtitle_codec_name = NULL; + const char *subtitle_codec_name = NULL; /* subtitles: pick first */ - MATCH_PER_TYPE_OPT(codec_names, str, subtitle_codec_name, oc, "s"); + subtitle_codec_name = opt_match_per_type_str(&o->codec_names, 's'); if (!avcodec_find_encoder(oc->oformat->subtitle_codec) && !subtitle_codec_name) return 0; diff --git a/fftools/ffmpeg_opt.c b/fftools/ffmpeg_opt.c index 653f62770e..567eff917e 100644 --- a/fftools/ffmpeg_opt.c +++ b/fftools/ffmpeg_opt.c @@ -182,6 +182,19 @@ AVDictionary *strip_specifiers(const AVDictionary *dict) return ret; } +const char *opt_match_per_type_str(const SpecifierOptList *sol, + char mediatype) +{ + av_assert0(!sol->nb_opt || sol->type == OPT_TYPE_STRING); + + for (int i = 0; i < sol->nb_opt; i++) { + const char *spec = sol->opt[i].specifier; + if (spec[0] == mediatype && !spec[1]) + return sol->opt[i].u.str; + } + return NULL; +} + int parse_and_set_vsync(const char *arg, int *vsync_var, int file_idx, int st_idx, int is_global) { if (!av_strcasecmp(arg, "cfr")) *vsync_var = VSYNC_CFR; @@ -1019,9 +1032,7 @@ static int opt_preset(void *optctx, const char *opt, const char *arg) const char *codec_name = NULL; int ret = 0; - tmp_line[0] = *opt; - tmp_line[1] = 0; - MATCH_PER_TYPE_OPT(codec_names, str, codec_name, NULL, tmp_line); + codec_name = opt_match_per_type_str(&o->codec_names, *opt); if (!(f = get_preset_file(filename, sizeof(filename), arg, *opt == 'f', codec_name))) { if(!strncmp(arg, "libx264-lossless", strlen("libx264-lossless"))){