diff options
author | Anton Khirnov <anton@khirnov.net> | 2023-12-13 18:39:02 +0100 |
---|---|---|
committer | Anton Khirnov <anton@khirnov.net> | 2023-12-14 20:16:53 +0100 |
commit | 0fcea80b2a328f6fd8fc7403e46b18a6e37d6c86 (patch) | |
tree | f944d1aca6bffbd84d3f46b13ac9963d4c96c45f | |
parent | 84201d8af6255ddfbeffa38afd51f0ecf742390b (diff) | |
download | ffmpeg-0fcea80b2a328f6fd8fc7403e46b18a6e37d6c86.tar.gz |
fftools/ffmpeg: replace InputStream.file_index by a pointer
Reduces the need to use the input_files global array.
-rw-r--r-- | fftools/ffmpeg.c | 6 | ||||
-rw-r--r-- | fftools/ffmpeg.h | 4 | ||||
-rw-r--r-- | fftools/ffmpeg_dec.c | 10 | ||||
-rw-r--r-- | fftools/ffmpeg_demux.c | 9 | ||||
-rw-r--r-- | fftools/ffmpeg_filter.c | 14 | ||||
-rw-r--r-- | fftools/ffmpeg_mux_init.c | 10 |
6 files changed, 27 insertions, 26 deletions
diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c index 42e675dcb9..567afbadad 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++) { @@ -767,7 +767,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); @@ -796,7 +796,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 de79bb1cbe..2c9ca5f538 100644 --- a/fftools/ffmpeg.h +++ b/fftools/ffmpeg.h @@ -338,7 +338,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 ce5aa33f73..5d4ef7909c 100644 --- a/fftools/ffmpeg_dec.c +++ b/fftools/ffmpeg_dec.c @@ -194,7 +194,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 @@ -456,7 +456,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); @@ -512,7 +512,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 @@ -558,7 +558,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; } } @@ -576,7 +576,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 d2466e885d..7625c09674 100644 --- a/fftools/ffmpeg_demux.c +++ b/fftools/ffmpeg_demux.c @@ -460,8 +460,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; @@ -758,7 +757,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; @@ -827,7 +826,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; @@ -991,7 +990,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 002bdb143d..40f52d043f 100644 --- a/fftools/ffmpeg_filter.c +++ b/fftools/ffmpeg_filter.c @@ -1457,7 +1457,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; @@ -1498,7 +1498,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, @@ -1557,7 +1557,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) @@ -1585,7 +1585,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; @@ -1610,7 +1610,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, @@ -1619,7 +1619,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) @@ -2572,7 +2572,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; |