From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTP id 13C1C49457 for ; Sat, 10 Aug 2024 17:16:54 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 874B468DA93; Sat, 10 Aug 2024 20:16:42 +0300 (EEST) Received: from mail1.khirnov.net (quelana.khirnov.net [94.230.150.81]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id E728E68D93B for ; Sat, 10 Aug 2024 20:16:34 +0300 (EEST) Authentication-Results: mail1.khirnov.net; dkim=pass (2048-bit key; unprotected) header.d=khirnov.net header.i=@khirnov.net header.a=rsa-sha256 header.s=mail header.b=e2giyEhP; dkim-atps=neutral Received: from localhost (mail1.khirnov.net [IPv6:::1]) by mail1.khirnov.net (Postfix) with ESMTP id 5088D4DF8 for ; Sat, 10 Aug 2024 19:16:34 +0200 (CEST) Received: from mail1.khirnov.net ([IPv6:::1]) by localhost (mail1.khirnov.net [IPv6:::1]) (amavis, port 10024) with ESMTP id 2mPfcc0E-en9 for ; Sat, 10 Aug 2024 19:16:33 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=khirnov.net; s=mail; t=1723310193; bh=pbEAhCIJ9el2i82Xe/Zcl7QyBB2GA21c0wPXhC9BPlo=; h=From:To:Subject:Date:In-Reply-To:References:From; b=e2giyEhPFKCmZ47QKtBy9VhUe41Bam8j6os5dAiuGPQpe4yuvamUPenKEQIisbKBm ATZf0/9CqFb/RTE4Zzt0moHzjFsmgwKwoAkkol+5cssmQ1jaysQkqQiRIIZyfNhF6c gQSqMtpSmZLNIAuKYzn5U+/1y6pFuq+oEjWMVLjattOT7lllVk8P5S0a6fVmA2psuJ dfmEj7hkMVfkK1hOZ7NqbOr0nbI6GohSJ+d4rfA57wKMupqz+qV7EkGPM8JRg9eYHw DDyvgpp5GcV+peZa45crk2IQnsv9k1YGVtYwlrUu4GYDHZgwW5T4+fMKidPvplA5Ou GhpNUNxJzYhxw== 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 978A6EE6 for ; Sat, 10 Aug 2024 19:16:32 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 464393A05A2 for ; Sat, 10 Aug 2024 19:16:26 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Sat, 10 Aug 2024 19:16:17 +0200 Message-ID: <20240810171621.26757-2-anton@khirnov.net> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240810171621.26757-1-anton@khirnov.net> References: <20240810171621.26757-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 2/6] fftools/ffmpeg: replace remaining uses of MATCH_PER_STREAM_OPT() 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 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: --- fftools/ffmpeg.h | 49 ++++----------------------- fftools/ffmpeg_demux.c | 39 ++++++++++++++++----- fftools/ffmpeg_mux_init.c | 71 ++++++++++++++++++++++++++++----------- fftools/ffmpeg_opt.c | 5 ++- 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) { -- 2.43.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".