From patchwork Wed Dec 13 19:29:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: FFmpeg Technical Committee X-Patchwork-Id: 45115 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:1225:b0:181:818d:5e7f with SMTP id v37csp4501079pzf; Wed, 13 Dec 2023 11:30:41 -0800 (PST) X-Google-Smtp-Source: AGHT+IE4YuL+JxAygB2tMejSZ9bA215gITuCvOdUrFBZNAwJwd1PqKfePb7ETNjp0hYW1Gt6c47T X-Received: by 2002:a17:907:a70f:b0:a1d:1c71:8158 with SMTP id vw15-20020a170907a70f00b00a1d1c718158mr9202207ejc.4.1702495840887; Wed, 13 Dec 2023 11:30:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702495840; cv=none; d=google.com; s=arc-20160816; b=Ec3q0yEgQ+3bX/PAu+HurlcgE/bX6yUOv3IgL5uAqEzBO6t4IqpI4fNF+HUAN/s8/b K+7khnyghKCaBsgaDj6LmQdiEWZhM0TNwzzTZmiSlScTFVExTIxhVKjYD8tDWIZT2D9g +oWtNTvsH98yNehjT5C9CbfiiR+bk7VV8cQ+WQFGeliPP3LkwM4XX7GTA9a1fXMxd32f GpuPLlvMRuBJwDEmg0Nyk0XndQx//cvRM/9+p0cz0a6vryV2HTnTQSQBKxPJ4DpB/sgc /H8YUD+Jtgi9jqrMoSoHYesaC+wAt/B9Dwd+0LQ+ye+SCFNAwBfJ/t2jdOJUnwUU+mCd sTCA== 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=ttcn8p0wFf9q/W5/45516lN/YCPlXFcYWHd5TWt5SfY=; fh=YOA8vD9MJZuwZ71F/05pj6KdCjf6jQRmzLS+CATXUQk=; b=tXPD2Vo89dOtrYGGoer+x/zubZcL3Ev2eFNZmbnVTo3KkALfZ7LbVrgBznPKK/Ik9U n1X8QuEWmvtQ1aNtBby+jf+e1AOMFDxHQtDDNbC5cVbZz7s8vawudM8r1y3ltZ5oTIk6 jnnFut9VvnsiD+N7Vh4QNJ0U1V5tUuA3N5oN70WpPetCTzjIjZf0KJUIKqaqS1I6sGEX 86JM1Yngl9nAAdL+0ZOWWQjjp8BI+65Rpk1+0WGBRsLrvufiW2QfR6Vkxxh4G2zMl9Sp Xt3GHXr4BFEbSwJ2Yeq3zjZ4G65MWD9fZXlzKhy37SWAqyOYttWPKw0/LnYCRZ0cK/gq MuvA== 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 gu2-20020a170906f28200b00a193d8f5147si5467611ejb.67.2023.12.13.11.30.34; Wed, 13 Dec 2023 11:30:40 -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 95ECB68D093; Wed, 13 Dec 2023 21:30:29 +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 D289068CFEA for ; Wed, 13 Dec 2023 21:30:22 +0200 (EET) Received: from localhost (mail1.khirnov.net [IPv6:::1]) by mail1.khirnov.net (Postfix) with ESMTP id 4EEEF1D3A for ; Wed, 13 Dec 2023 20:30:22 +0100 (CET) Received: from mail1.khirnov.net ([IPv6:::1]) by localhost (mail1.khirnov.net [IPv6:::1]) (amavis, port 10024) with ESMTP id TRt2acKW_v_8 for ; Wed, 13 Dec 2023 20:30:21 +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 4CDE3162E for ; Wed, 13 Dec 2023 20:30:21 +0100 (CET) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 1BCCB3A0585 for ; Wed, 13 Dec 2023 20:30:14 +0100 (CET) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Wed, 13 Dec 2023 20:29:57 +0100 Message-ID: <20231213193007.17471-2-anton@khirnov.net> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231213193007.17471-1-anton@khirnov.net> References: <20231213193007.17471-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 02/12] fftools/ffmpeg: replace InputStream.file_index by a pointer 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: UtDtfWaY0XBe Reduces the need to use the input_files global array. --- fftools/ffmpeg.c | 6 +++--- fftools/ffmpeg.h | 4 +++- fftools/ffmpeg_dec.c | 10 +++++----- fftools/ffmpeg_demux.c | 9 ++++----- fftools/ffmpeg_filter.c | 14 +++++++------- fftools/ffmpeg_mux_init.c | 10 +++++----- 6 files changed, 27 insertions(+), 26 deletions(-) diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c index 30b594fd97..3aab302c27 100644 --- a/fftools/ffmpeg.c +++ b/fftools/ffmpeg.c @@ -390,7 +390,7 @@ OutputStream *ost_iter(OutputStream *prev) InputStream *ist_iter(InputStream *prev) { - int if_idx = prev ? prev->file_index : 0; + int if_idx = prev ? prev->file->index : 0; int ist_idx = prev ? prev->index + 1 : 0; for (; if_idx < nb_input_files; if_idx++) { @@ -752,7 +752,7 @@ static void print_stream_maps(void) for (int j = 0; j < ist->nb_filters; j++) { if (!filtergraph_is_simple(ist->filters[j]->graph)) { av_log(NULL, AV_LOG_INFO, " Stream #%d:%d (%s) -> %s", - ist->file_index, ist->index, ist->dec ? ist->dec->name : "?", + ist->file->index, ist->index, ist->dec ? ist->dec->name : "?", ist->filters[j]->name); if (nb_filtergraphs > 1) av_log(NULL, AV_LOG_INFO, " (graph %d)", ist->filters[j]->graph->index); @@ -781,7 +781,7 @@ static void print_stream_maps(void) } av_log(NULL, AV_LOG_INFO, " Stream #%d:%d -> #%d:%d", - ost->ist->file_index, + ost->ist->file->index, ost->ist->index, ost->file_index, ost->index); diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h index 69bd23f576..d7b6e689fc 100644 --- a/fftools/ffmpeg.h +++ b/fftools/ffmpeg.h @@ -333,7 +333,9 @@ typedef struct Decoder Decoder; typedef struct InputStream { const AVClass *class; - int file_index; + /* parent source */ + struct InputFile *file; + int index; AVStream *st; diff --git a/fftools/ffmpeg_dec.c b/fftools/ffmpeg_dec.c index 5dde82a276..219bcf39e4 100644 --- a/fftools/ffmpeg_dec.c +++ b/fftools/ffmpeg_dec.c @@ -193,7 +193,7 @@ static void audio_ts_process(void *logctx, Decoder *d, AVFrame *frame) static int64_t video_duration_estimate(const InputStream *ist, const AVFrame *frame) { const Decoder *d = ist->decoder; - const InputFile *ifile = input_files[ist->file_index]; + const InputFile *ifile = ist->file; int64_t codec_duration = 0; // XXX lavf currently makes up frame durations when they are not provided by @@ -455,7 +455,7 @@ static int transcode_subtitles(InputStream *ist, const AVPacket *pkt, static int packet_decode(InputStream *ist, AVPacket *pkt, AVFrame *frame) { - const InputFile *ifile = input_files[ist->file_index]; + const InputFile *ifile = ist->file; Decoder *d = ist->decoder; AVCodecContext *dec = ist->dec_ctx; const char *type_desc = av_get_media_type_string(dec->codec_type); @@ -504,7 +504,7 @@ static int packet_decode(InputStream *ist, AVPacket *pkt, AVFrame *frame) update_benchmark(NULL); ret = avcodec_receive_frame(dec, frame); update_benchmark("decode_%s %d.%d", type_desc, - ist->file_index, ist->index); + ifile->index, ist->index); if (ret == AVERROR(EAGAIN)) { av_assert0(pkt); // should never happen during flushing @@ -550,7 +550,7 @@ static int packet_decode(InputStream *ist, AVPacket *pkt, AVFrame *frame) ret = video_frame_process(ist, frame); if (ret < 0) { av_log(NULL, AV_LOG_FATAL, "Error while processing the decoded " - "data for stream #%d:%d\n", ist->file_index, ist->index); + "data for stream #%d:%d\n", ifile->index, ist->index); return ret; } } @@ -568,7 +568,7 @@ static int packet_decode(InputStream *ist, AVPacket *pkt, AVFrame *frame) static void dec_thread_set_name(const InputStream *ist) { char name[16]; - snprintf(name, sizeof(name), "dec%d:%d:%s", ist->file_index, ist->index, + snprintf(name, sizeof(name), "dec%d:%d:%s", ist->file->index, ist->index, ist->dec_ctx->codec->name); ff_thread_setname(name); } diff --git a/fftools/ffmpeg_demux.c b/fftools/ffmpeg_demux.c index 91cd7a1125..61fb856106 100644 --- a/fftools/ffmpeg_demux.c +++ b/fftools/ffmpeg_demux.c @@ -463,8 +463,7 @@ static int input_packet_process(Demuxer *d, AVPacket *pkt, unsigned *send_flags) av_ts2str(pkt->pts), av_ts2timestr(pkt->pts, &pkt->time_base), av_ts2str(pkt->dts), av_ts2timestr(pkt->dts, &pkt->time_base), av_ts2str(pkt->duration), av_ts2timestr(pkt->duration, &pkt->time_base), - av_ts2str(input_files[ist->file_index]->ts_offset), - av_ts2timestr(input_files[ist->file_index]->ts_offset, &AV_TIME_BASE_Q)); + av_ts2str(f->ts_offset), av_ts2timestr(f->ts_offset, &AV_TIME_BASE_Q)); } pkt->stream_index = ds->sch_idx_stream; @@ -761,7 +760,7 @@ void ifile_close(InputFile **pf) static int ist_use(InputStream *ist, int decoding_needed) { - Demuxer *d = demuxer_from_ifile(input_files[ist->file_index]); + Demuxer *d = demuxer_from_ifile(ist->file); DemuxStream *ds = ds_from_ist(ist); int ret; @@ -830,7 +829,7 @@ int ist_output_add(InputStream *ist, OutputStream *ost) int ist_filter_add(InputStream *ist, InputFilter *ifilter, int is_simple) { - Demuxer *d = demuxer_from_ifile(input_files[ist->file_index]); + Demuxer *d = demuxer_from_ifile(ist->file); DemuxStream *ds = ds_from_ist(ist); int ret; @@ -994,7 +993,7 @@ static DemuxStream *demux_stream_alloc(Demuxer *d, AVStream *st) ds->sch_idx_dec = -1; ds->ist.st = st; - ds->ist.file_index = f->index; + ds->ist.file = f; ds->ist.index = st->index; ds->ist.class = &input_stream_class; diff --git a/fftools/ffmpeg_filter.c b/fftools/ffmpeg_filter.c index 3b0d457cc2..40608d9e44 100644 --- a/fftools/ffmpeg_filter.c +++ b/fftools/ffmpeg_filter.c @@ -1456,7 +1456,7 @@ static int configure_input_video_filter(FilterGraph *fg, AVFilterGraph *graph, const AVFilter *buffer_filt = avfilter_get_by_name("buffer"); const AVPixFmtDescriptor *desc; InputStream *ist = ifp->ist; - InputFile *f = input_files[ist->file_index]; + InputFile *f = ist->file; AVRational fr = ist->framerate; AVRational sar; AVBPrint args; @@ -1497,7 +1497,7 @@ static int configure_input_video_filter(FilterGraph *fg, AVFilterGraph *graph, if (fr.num && fr.den) av_bprintf(&args, ":frame_rate=%d/%d", fr.num, fr.den); snprintf(name, sizeof(name), "graph %d input from stream %d:%d", fg->index, - ist->file_index, ist->index); + f->index, ist->index); if ((ret = avfilter_graph_create_filter(&ifp->filter, buffer_filt, name, @@ -1556,7 +1556,7 @@ static int configure_input_video_filter(FilterGraph *fg, AVFilterGraph *graph, } snprintf(name, sizeof(name), "trim_in_%d_%d", - ist->file_index, ist->index); + f->index, ist->index); if (copy_ts) { tsoffset = f->start_time == AV_NOPTS_VALUE ? 0 : f->start_time; if (!start_at_zero && f->ctx->start_time != AV_NOPTS_VALUE) @@ -1584,7 +1584,7 @@ static int configure_input_audio_filter(FilterGraph *fg, AVFilterGraph *graph, AVFilterContext *last_filter; const AVFilter *abuffer_filt = avfilter_get_by_name("abuffer"); InputStream *ist = ifp->ist; - InputFile *f = input_files[ist->file_index]; + InputFile *f = ist->file; AVBPrint args; char name[255]; int ret, pad_idx = 0; @@ -1609,7 +1609,7 @@ static int configure_input_audio_filter(FilterGraph *fg, AVFilterGraph *graph, } else av_bprintf(&args, ":channels=%d", ifp->ch_layout.nb_channels); snprintf(name, sizeof(name), "graph_%d_in_%d_%d", fg->index, - ist->file_index, ist->index); + f->index, ist->index); if ((ret = avfilter_graph_create_filter(&ifp->filter, abuffer_filt, name, args.str, NULL, @@ -1618,7 +1618,7 @@ static int configure_input_audio_filter(FilterGraph *fg, AVFilterGraph *graph, last_filter = ifp->filter; snprintf(name, sizeof(name), "trim for input stream %d:%d", - ist->file_index, ist->index); + f->index, ist->index); if (copy_ts) { tsoffset = f->start_time == AV_NOPTS_VALUE ? 0 : f->start_time; if (!start_at_zero && f->ctx->start_time != AV_NOPTS_VALUE) @@ -2569,7 +2569,7 @@ static int send_eof(FilterGraphThread *fgt, InputFilter *ifilter, if (ifp->format < 0) { av_log(NULL, AV_LOG_ERROR, "Cannot determine format of input stream %d:%d after EOF\n", - ifp->ist->file_index, ifp->ist->index); + ifp->ist->file->index, ifp->ist->index); return AVERROR_INVALIDDATA; } } diff --git a/fftools/ffmpeg_mux_init.c b/fftools/ffmpeg_mux_init.c index 6459296ab0..64c173e006 100644 --- a/fftools/ffmpeg_mux_init.c +++ b/fftools/ffmpeg_mux_init.c @@ -819,7 +819,7 @@ static int new_stream_video(Muxer *mux, const OptionsContext *o, } if (ost->ist && ost->vsync_method == VSYNC_CFR) { - const InputFile *ifile = input_files[ost->ist->file_index]; + const InputFile *ifile = ost->ist->file; if (ifile->nb_streams == 1 && ifile->input_ts_offset == 0) ost->vsync_method = VSYNC_VSCFR; @@ -907,7 +907,7 @@ static int new_stream_audio(Muxer *mux, const OptionsContext *o, ist = ost->ist; } - if (!ist || (ist->file_index == map->file_idx && ist->index == map->stream_idx)) { + if (!ist || (ist->file->index == map->file_idx && ist->index == map->stream_idx)) { ret = av_reallocp_array(&ost->audio_channels_map, ost->audio_channels_mapped + 1, sizeof(*ost->audio_channels_map)); @@ -970,7 +970,7 @@ static int streamcopy_init(const Muxer *mux, OutputStream *ost) MuxStream *ms = ms_from_ost(ost); const InputStream *ist = ost->ist; - const InputFile *ifile = input_files[ist->file_index]; + const InputFile *ifile = ist->file; AVCodecParameters *par = ost->par_in; uint32_t codec_tag = par->codec_tag; @@ -1208,7 +1208,7 @@ static int ost_add(Muxer *mux, const OptionsContext *o, enum AVMediaType type, av_get_media_type_string(type)); if (ist) av_log(ost, AV_LOG_VERBOSE, "input stream %d:%d", - ist->file_index, ist->index); + ist->file->index, ist->index); else if (ofilter) av_log(ost, AV_LOG_VERBOSE, "complex filtergraph %d:[%s]\n", ofilter->graph->index, ofilter->name); @@ -1480,7 +1480,7 @@ static int ost_add(Muxer *mux, const OptionsContext *o, enum AVMediaType type, if (ret < 0) return ret; } else { - ret = sch_connect(mux->sch, SCH_DSTREAM(ost->ist->file_index, sched_idx), + ret = sch_connect(mux->sch, SCH_DSTREAM(ost->ist->file->index, sched_idx), SCH_MSTREAM(ost->file_index, ms->sch_idx)); if (ret < 0) return ret;