From: Anton Khirnov <anton@khirnov.net> To: ffmpeg-devel@ffmpeg.org Subject: [FFmpeg-devel] [PATCH 11/20] fftools/ffmpeg: change the MATCH_PER_TYPE_OPT macro into a function Date: Mon, 18 Dec 2023 10:57:13 +0100 Message-ID: <20231218095722.25879-11-anton@khirnov.net> (raw) In-Reply-To: <20231218095722.25879-1-anton@khirnov.net> 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"))){ -- 2.42.0 _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
next prev parent reply other threads:[~2023-12-18 10:00 UTC|newest] Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top 2023-12-18 9:57 [FFmpeg-devel] [PATCH 01/20] fftools/ffmpeg_filter: only set framerate for video Anton Khirnov 2023-12-18 9:57 ` [FFmpeg-devel] [PATCH 02/20] fftools/ffmpeg_opt: drop HAS_ARG from auto{scale, rotate} Anton Khirnov 2023-12-18 9:57 ` [FFmpeg-devel] [PATCH 03/20] fftools/cmdutils: simplify handling of the HAS_ARG option flag Anton Khirnov 2023-12-18 9:57 ` [FFmpeg-devel] [PATCH 04/20] fftools/ffmpeg_opt: move deprecated options to the end of the list Anton Khirnov 2023-12-18 9:57 ` [FFmpeg-devel] [PATCH 05/20] fftools: split off option types from other flags Anton Khirnov 2023-12-18 9:57 ` [FFmpeg-devel] [PATCH 06/20] fftools/cmdutils: rename HAS_ARG to OPT_FUNC_ARG Anton Khirnov 2023-12-18 9:57 ` [FFmpeg-devel] [PATCH 07/20] fftools/cmdutils: renumber option flags sequentially Anton Khirnov 2023-12-18 9:57 ` [FFmpeg-devel] [PATCH 08/20] fftools/cmdutils: include OPT_PERFILE in OPT_OFFSET Anton Khirnov 2023-12-18 9:57 ` [FFmpeg-devel] [PATCH 09/20] fftools/cmdutils: check valid flags for OPT_TYPE_FUNC Anton Khirnov 2023-12-18 9:57 ` [FFmpeg-devel] [PATCH 10/20] fftools/cmdutils: add a struct for a list of SpecifierOpt Anton Khirnov 2023-12-18 9:57 ` Anton Khirnov [this message] 2023-12-18 9:57 ` [FFmpeg-devel] [PATCH 12/20] fftools/ffmpeg: improve WARN_MULTIPLE_OPT_USAGE() Anton Khirnov 2023-12-18 9:57 ` [FFmpeg-devel] [PATCH 13/20] fftools/ffmpeg_opt: update program description to match manpage Anton Khirnov 2023-12-18 9:57 ` [FFmpeg-devel] [PATCH 14/20] fftools/opt_common: mark some options as OPT_EXPERT Anton Khirnov 2023-12-18 9:57 ` [FFmpeg-devel] [PATCH 15/20] fftools/ffmpeg_opt: mark more " Anton Khirnov 2023-12-18 9:57 ` [FFmpeg-devel] [PATCH 16/20] fftools/ffmpeg_opt: refine printing type-specific options Anton Khirnov 2023-12-18 9:57 ` [FFmpeg-devel] [PATCH 17/20] fftools/ffmpeg_opt: print a section for data-stream options Anton Khirnov 2023-12-18 9:57 ` [FFmpeg-devel] [PATCH 18/20] fftools/ffmpeg_opt: fix -dn flags Anton Khirnov 2023-12-18 9:57 ` [FFmpeg-devel] [PATCH 19/20] fftools/ffmpeg: mark -vsync for future removal Anton Khirnov 2023-12-18 9:57 ` [FFmpeg-devel] [PATCH 20/20] fftools/ffmpeg: remove deprecated -[av]bsf Anton Khirnov
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20231218095722.25879-11-anton@khirnov.net \ --to=anton@khirnov.net \ --cc=ffmpeg-devel@ffmpeg.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel This inbox may be cloned and mirrored by anyone: git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git # If you have public-inbox 1.1+ installed, you may # initialize and index your mirror using the following commands: public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \ ffmpegdev@gitmailbox.com public-inbox-index ffmpegdev Example config snippet for mirrors. AGPL code for this site: git clone https://public-inbox.org/public-inbox.git