aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAnton Khirnov <anton@khirnov.net>2024-08-06 12:13:56 +0200
committerAnton Khirnov <anton@khirnov.net>2024-08-13 10:28:54 +0200
commit93227a68f12f3443b6cd6babbe4619cbe6747b82 (patch)
tree9155ca9e2071f7d90ab2c655b0f324367912b5a6
parente218bde9f9e3b41d89921ed475065da88b5c0b83 (diff)
downloadffmpeg-93227a68f12f3443b6cd6babbe4619cbe6747b82.tar.gz
fftools/ffmpeg: replace remaining uses of MATCH_PER_STREAM_OPT()
-rw-r--r--fftools/ffmpeg.h49
-rw-r--r--fftools/ffmpeg_demux.c39
-rw-r--r--fftools/ffmpeg_mux_init.c71
-rw-r--r--fftools/ffmpeg_opt.c5
4 files changed, 91 insertions, 73 deletions
diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h
index 7d82d7d7c2..674ae340f2 100644
--- a/fftools/ffmpeg.h
+++ b/fftools/ffmpeg.h
@@ -857,53 +857,16 @@ OutputStream *ost_iter(OutputStream *prev);
void update_benchmark(const char *fmt, ...);
-#define SPECIFIER_OPT_FMT_str "%s"
-#define SPECIFIER_OPT_FMT_i "%i"
-#define SPECIFIER_OPT_FMT_i64 "%"PRId64
-#define SPECIFIER_OPT_FMT_ui64 "%"PRIu64
-#define SPECIFIER_OPT_FMT_f "%f"
-#define SPECIFIER_OPT_FMT_dbl "%lf"
-
-#define WARN_MULTIPLE_OPT_USAGE(optname, type, idx, st)\
-{\
- char namestr[128] = "";\
- const SpecifierOpt *so = &o->optname.opt[idx];\
- const char *spec = so->specifier && so->specifier[0] ? so->specifier : "";\
- snprintf(namestr, sizeof(namestr), "-%s", o->optname.opt_canon->name);\
- if (o->optname.opt_canon->flags & OPT_HAS_ALT) {\
- const char * const *names_alt = o->optname.opt_canon->u1.names_alt;\
- for (int _i = 0; names_alt[_i]; _i++)\
- av_strlcatf(namestr, sizeof(namestr), "/-%s", names_alt[_i]);\
- }\
- av_log(NULL, AV_LOG_WARNING, "Multiple %s options specified for stream %d, only the last option '-%s%s%s "SPECIFIER_OPT_FMT_##type"' will be used.\n",\
- namestr, st->index, o->optname.opt_canon->name, spec[0] ? ":" : "", spec, so->u.type);\
-}
-
-#define MATCH_PER_STREAM_OPT_CLEAN(name, type, outvar, fmtctx, st, clean)\
-{\
- int _ret, _matches = 0, _match_idx;\
- for (int _i = 0; _i < o->name.nb_opt; _i++) {\
- char *spec = o->name.opt[_i].specifier;\
- if ((_ret = check_stream_specifier(fmtctx, st, spec)) > 0) {\
- outvar = o->name.opt[_i].u.type;\
- _match_idx = _i;\
- _matches++;\
- } else if (_ret < 0)\
- clean;\
- }\
- if (_matches > 1 && o->name.opt_canon)\
- WARN_MULTIPLE_OPT_USAGE(name, type, _match_idx, st);\
-}
-
-#define MATCH_PER_STREAM_OPT(name, type, outvar, fmtctx, st)\
-{\
- MATCH_PER_STREAM_OPT_CLEAN(name, type, outvar, fmtctx, st, return _ret)\
-}
-
const char *opt_match_per_type_str(const SpecifierOptList *sol,
char mediatype);
int opt_match_per_stream_str(void *logctx, const SpecifierOptList *sol,
AVFormatContext *fc, AVStream *st, const char **out);
+int opt_match_per_stream_int(void *logctx, const SpecifierOptList *sol,
+ AVFormatContext *fc, AVStream *st, int *out);
+int opt_match_per_stream_int64(void *logctx, const SpecifierOptList *sol,
+ AVFormatContext *fc, AVStream *st, int64_t *out);
+int opt_match_per_stream_dbl(void *logctx, const SpecifierOptList *sol,
+ AVFormatContext *fc, AVStream *st, double *out);
int muxer_thread(void *arg);
int encoder_thread(void *arg);
diff --git a/fftools/ffmpeg_demux.c b/fftools/ffmpeg_demux.c
index 0c92d31c10..e9a4b5c22a 100644
--- a/fftools/ffmpeg_demux.c
+++ b/fftools/ffmpeg_demux.c
@@ -1153,11 +1153,18 @@ static int add_display_matrix_to_stream(const OptionsContext *o,
double rotation = DBL_MAX;
int hflip = -1, vflip = -1;
int hflip_set = 0, vflip_set = 0, rotation_set = 0;
+ int ret;
int32_t *buf;
- MATCH_PER_STREAM_OPT(display_rotations, dbl, rotation, ctx, st);
- MATCH_PER_STREAM_OPT(display_hflips, i, hflip, ctx, st);
- MATCH_PER_STREAM_OPT(display_vflips, i, vflip, ctx, st);
+ ret = opt_match_per_stream_dbl(ist, &o->display_rotations, ctx, st, &rotation);
+ if (ret < 0)
+ return ret;
+ ret = opt_match_per_stream_int(ist, &o->display_hflips, ctx, st, &hflip);
+ if (ret < 0)
+ return ret;
+ ret = opt_match_per_stream_int(ist, &o->display_vflips, ctx, st, &vflip);
+ if (ret < 0)
+ return ret;
rotation_set = rotation != DBL_MAX;
hflip_set = hflip != -1;
@@ -1255,10 +1262,14 @@ static int ist_add(const OptionsContext *o, Demuxer *d, AVStream *st, AVDictiona
ds->dec_opts.time_base = st->time_base;
ds->ts_scale = 1.0;
- MATCH_PER_STREAM_OPT(ts_scale, dbl, ds->ts_scale, ic, st);
+ ret = opt_match_per_stream_dbl(ist, &o->ts_scale, ic, st, &ds->ts_scale);
+ if (ret < 0)
+ return ret;
ds->autorotate = 1;
- MATCH_PER_STREAM_OPT(autorotate, i, ds->autorotate, ic, st);
+ ret = opt_match_per_stream_int(ist, &o->autorotate, ic, st, &ds->autorotate);
+ if (ret < 0)
+ return ret;
ds->apply_cropping = CROP_ALL;
ret = opt_match_per_stream_str(ist, &o->apply_cropping, ic, st, &apply_cropping);
@@ -1397,7 +1408,9 @@ static int ist_add(const OptionsContext *o, Demuxer *d, AVStream *st, AVDictiona
}
ds->reinit_filters = -1;
- MATCH_PER_STREAM_OPT(reinit_filters, i, ds->reinit_filters, ic, st);
+ ret = opt_match_per_stream_int(ist, &o->reinit_filters, ic, st, &ds->reinit_filters);
+ if (ret < 0)
+ return ret;
ist->user_set_discard = AVDISCARD_NONE;
@@ -1445,7 +1458,9 @@ static int ist_add(const OptionsContext *o, Demuxer *d, AVStream *st, AVDictiona
#if FFMPEG_OPT_TOP
ist->top_field_first = -1;
- MATCH_PER_STREAM_OPT(top_field_first, i, ist->top_field_first, ic, st);
+ ret = opt_match_per_stream_int(ist, &o->top_field_first, ic, st, &ist->top_field_first);
+ if (ret < 0)
+ return ret;
#endif
break;
@@ -1474,7 +1489,10 @@ static int ist_add(const OptionsContext *o, Demuxer *d, AVStream *st, AVDictiona
}
} else {
int guess_layout_max = INT_MAX;
- MATCH_PER_STREAM_OPT(guess_layout_max, i, guess_layout_max, ic, st);
+ ret = opt_match_per_stream_int(ist, &o->guess_layout_max, ic, st, &guess_layout_max);
+ if (ret < 0)
+ return ret;
+
guess_input_channel_layout(ist, par, guess_layout_max);
}
break;
@@ -1482,7 +1500,10 @@ static int ist_add(const OptionsContext *o, Demuxer *d, AVStream *st, AVDictiona
case AVMEDIA_TYPE_DATA:
case AVMEDIA_TYPE_SUBTITLE: {
const char *canvas_size = NULL;
- MATCH_PER_STREAM_OPT(fix_sub_duration, i, ist->fix_sub_duration, ic, st);
+
+ ret = opt_match_per_stream_int(ist, &o->fix_sub_duration, ic, st, &ist->fix_sub_duration);
+ if (ret < 0)
+ return ret;
ret = opt_match_per_stream_str(ist, &o->canvas_sizes, ic, st, &canvas_size);
if (ret < 0)
diff --git a/fftools/ffmpeg_mux_init.c b/fftools/ffmpeg_mux_init.c
index c7efeda7bf..2b3a4ddcf9 100644
--- a/fftools/ffmpeg_mux_init.c
+++ b/fftools/ffmpeg_mux_init.c
@@ -735,7 +735,9 @@ static int new_stream_video(Muxer *mux, const OptionsContext *o,
video_enc->rc_override_count = i;
/* two pass mode */
- MATCH_PER_STREAM_OPT(pass, i, do_pass, oc, st);
+ ret = opt_match_per_stream_int(ost, &o->pass, oc, st, &do_pass);
+ if (ret < 0)
+ return ret;
if (do_pass) {
if (do_pass & 1)
video_enc->flags |= AV_CODEC_FLAG_PASS1;
@@ -792,11 +794,15 @@ static int new_stream_video(Muxer *mux, const OptionsContext *o,
}
}
- MATCH_PER_STREAM_OPT(force_fps, i, ost->force_fps, oc, st);
+ ret = opt_match_per_stream_int(ost, &o->force_fps, oc, st, &ost->force_fps);
+ if (ret < 0)
+ return ret;
#if FFMPEG_OPT_TOP
ost->top_field_first = -1;
- MATCH_PER_STREAM_OPT(top_field_first, i, ost->top_field_first, oc, st);
+ ret = opt_match_per_stream_int(ost, &o->top_field_first, oc, st, &ost->top_field_first);
+ if (ret < 0)
+ return ret;
if (ost->top_field_first >= 0)
av_log(ost, AV_LOG_WARNING, "-top is deprecated, use the setfield filter instead\n");
#endif
@@ -868,7 +874,9 @@ static int new_stream_audio(Muxer *mux, const OptionsContext *o,
const char *sample_fmt = NULL;
int ret;
- MATCH_PER_STREAM_OPT(audio_channels, i, channels, oc, st);
+ ret = opt_match_per_stream_int(ost, &o->audio_channels, oc, st, &channels);
+ if (ret < 0)
+ return ret;
if (channels) {
audio_enc->ch_layout.order = AV_CHANNEL_ORDER_UNSPEC;
audio_enc->ch_layout.nb_channels = channels;
@@ -891,7 +899,9 @@ static int new_stream_audio(Muxer *mux, const OptionsContext *o,
return AVERROR(EINVAL);
}
- MATCH_PER_STREAM_OPT(audio_sample_rate, i, audio_enc->sample_rate, oc, st);
+ ret = opt_match_per_stream_int(ost, &o->audio_sample_rate, oc, st, &audio_enc->sample_rate);
+ if (ret < 0)
+ return ret;
ret = opt_match_per_stream_str(ost, &o->apad, oc, st, &ms->apad);
if (ret < 0)
@@ -1205,7 +1215,9 @@ static int ost_add(Muxer *mux, const OptionsContext *o, enum AVMediaType type,
if (ret < 0)
goto fail;
- MATCH_PER_STREAM_OPT(autoscale, i, autoscale, oc, st);
+ ret = opt_match_per_stream_int(ost, &o->autoscale, oc, st, &autoscale);
+ if (ret < 0)
+ goto fail;
if (preset && (!(ret = get_preset_file_2(preset, enc->codec->name, &s)))) {
AVBPrint bprint;
av_bprint_init(&bprint, 0, AV_BPRINT_SIZE_UNLIMITED);
@@ -1351,7 +1363,7 @@ static int ost_add(Muxer *mux, const OptionsContext *o, enum AVMediaType type,
ret = opt_match_per_stream_str(ost, &o->time_bases, oc, st, &time_base);
if (ret < 0)
- return ret;
+ goto fail;
if (time_base) {
AVRational q;
if (av_parse_ratio(&q, time_base, INT_MAX, 0, NULL) < 0 ||
@@ -1364,7 +1376,9 @@ static int ost_add(Muxer *mux, const OptionsContext *o, enum AVMediaType type,
}
ms->max_frames = INT64_MAX;
- MATCH_PER_STREAM_OPT(max_frames, i64, ms->max_frames, oc, st);
+ ret = opt_match_per_stream_int64(ost, &o->max_frames, oc, st, &ms->max_frames);
+ if (ret < 0)
+ return ret;
for (int i = 0; i < o->max_frames.nb_opt; i++) {
char *p = o->max_frames.opt[i].specifier;
if (!*p && type != AVMEDIA_TYPE_VIDEO) {
@@ -1374,11 +1388,13 @@ static int ost_add(Muxer *mux, const OptionsContext *o, enum AVMediaType type,
}
ms->copy_prior_start = -1;
- MATCH_PER_STREAM_OPT(copy_prior_start, i, ms->copy_prior_start, oc ,st);
+ ret = opt_match_per_stream_int(ost, &o->copy_prior_start, oc, st, &ms->copy_prior_start);
+ if (ret < 0)
+ goto fail;
ret = opt_match_per_stream_str(ost, &o->bitstream_filters, oc, st, &bsfs);
if (ret < 0)
- return ret;
+ goto fail;
if (bsfs && *bsfs) {
ret = av_bsf_list_parse_str(bsfs, &ms->bsf_ctx);
if (ret < 0) {
@@ -1389,7 +1405,7 @@ static int ost_add(Muxer *mux, const OptionsContext *o, enum AVMediaType type,
ret = opt_match_per_stream_str(ost, &o->codec_tags, oc, st, &codec_tag);
if (ret < 0)
- return ret;
+ goto fail;
if (codec_tag) {
uint32_t tag = strtol(codec_tag, &next, 0);
if (*next) {
@@ -1403,7 +1419,9 @@ static int ost_add(Muxer *mux, const OptionsContext *o, enum AVMediaType type,
ost->enc_ctx->codec_tag = tag;
}
- MATCH_PER_STREAM_OPT(qscale, dbl, qscale, oc, st);
+ ret = opt_match_per_stream_dbl(ost, &o->qscale, oc, st, &qscale);
+ if (ret < 0)
+ return ret;
if (ost->enc_ctx && qscale >= 0) {
ost->enc_ctx->flags |= AV_CODEC_FLAG_QSCALE;
ost->enc_ctx->global_quality = FF_QP2LAMBDA * qscale;
@@ -1413,24 +1431,37 @@ static int ost_add(Muxer *mux, const OptionsContext *o, enum AVMediaType type,
int max_muxing_queue_size = 128;
int muxing_queue_data_threshold = 50 * 1024 * 1024;
- MATCH_PER_STREAM_OPT(max_muxing_queue_size, i, max_muxing_queue_size, oc, st);
- MATCH_PER_STREAM_OPT(muxing_queue_data_threshold, i, muxing_queue_data_threshold, oc, st);
+ ret = opt_match_per_stream_int(ost, &o->max_muxing_queue_size, oc, st,
+ &max_muxing_queue_size);
+ if (ret < 0)
+ goto fail;
+
+ ret = opt_match_per_stream_int(ost, &o->muxing_queue_data_threshold,
+ oc, st, &muxing_queue_data_threshold);
+ if (ret < 0)
+ goto fail;
sch_mux_stream_buffering(mux->sch, mux->sch_idx, ms->sch_idx,
max_muxing_queue_size, muxing_queue_data_threshold);
}
- MATCH_PER_STREAM_OPT(bits_per_raw_sample, i, ost->bits_per_raw_sample,
- oc, st);
+ ret = opt_match_per_stream_int(ost, &o->bits_per_raw_sample, oc, st,
+ &ost->bits_per_raw_sample);
+ if (ret < 0)
+ goto fail;
- MATCH_PER_STREAM_OPT(fix_sub_duration_heartbeat, i, ost->fix_sub_duration_heartbeat,
- oc, st);
+ ret = opt_match_per_stream_int(ost, &o->fix_sub_duration_heartbeat,
+ oc, st, &ost->fix_sub_duration_heartbeat);
+ if (ret < 0)
+ goto fail;
if (oc->oformat->flags & AVFMT_GLOBALHEADER && ost->enc_ctx)
ost->enc_ctx->flags |= AV_CODEC_FLAG_GLOBAL_HEADER;
- MATCH_PER_STREAM_OPT(copy_initial_nonkeyframes, i,
- ms->copy_initial_nonkeyframes, oc, st);
+ ret = opt_match_per_stream_int(ost, &o->copy_initial_nonkeyframes,
+ oc, st, &ms->copy_initial_nonkeyframes);
+ if (ret < 0)
+ goto fail;
switch (type) {
case AVMEDIA_TYPE_VIDEO: ret = new_stream_video (mux, o, ost, &keep_pix_fmt, &vsync_method); break;
diff --git a/fftools/ffmpeg_opt.c b/fftools/ffmpeg_opt.c
index 736b3ee743..c32d3ddc55 100644
--- a/fftools/ffmpeg_opt.c
+++ b/fftools/ffmpeg_opt.c
@@ -229,7 +229,10 @@ int opt_match_per_stream_ ## name(void *logctx, const SpecifierOptList *sol,
return 0; \
}
-OPT_MATCH_PER_STREAM(str, const char *, OPT_TYPE_STRING, str);
+OPT_MATCH_PER_STREAM(str, const char *, OPT_TYPE_STRING, str);
+OPT_MATCH_PER_STREAM(int, int, OPT_TYPE_INT, i);
+OPT_MATCH_PER_STREAM(int64, int64_t, OPT_TYPE_INT64, i64);
+OPT_MATCH_PER_STREAM(dbl, double, OPT_TYPE_DOUBLE, dbl);
int parse_and_set_vsync(const char *arg, int *vsync_var, int file_idx, int st_idx, int is_global)
{