fftools/ffmpeg: replace InputStream.file_index by a pointer

Reduces the need to use the input_files global array.
This commit is contained in:
Anton Khirnov 2023-12-13 18:39:02 +01:00
parent 84201d8af6
commit 0fcea80b2a
6 changed files with 27 additions and 26 deletions

View File

@ -390,7 +390,7 @@ OutputStream *ost_iter(OutputStream *prev)
InputStream *ist_iter(InputStream *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; int ist_idx = prev ? prev->index + 1 : 0;
for (; if_idx < nb_input_files; if_idx++) { 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++) { for (int j = 0; j < ist->nb_filters; j++) {
if (!filtergraph_is_simple(ist->filters[j]->graph)) { if (!filtergraph_is_simple(ist->filters[j]->graph)) {
av_log(NULL, AV_LOG_INFO, " Stream #%d:%d (%s) -> %s", 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); ist->filters[j]->name);
if (nb_filtergraphs > 1) if (nb_filtergraphs > 1)
av_log(NULL, AV_LOG_INFO, " (graph %d)", ist->filters[j]->graph->index); 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", av_log(NULL, AV_LOG_INFO, " Stream #%d:%d -> #%d:%d",
ost->ist->file_index, ost->ist->file->index,
ost->ist->index, ost->ist->index,
ost->file_index, ost->file_index,
ost->index); ost->index);

View File

@ -338,7 +338,9 @@ typedef struct Decoder Decoder;
typedef struct InputStream { typedef struct InputStream {
const AVClass *class; const AVClass *class;
int file_index; /* parent source */
struct InputFile *file;
int index; int index;
AVStream *st; AVStream *st;

View File

@ -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) static int64_t video_duration_estimate(const InputStream *ist, const AVFrame *frame)
{ {
const Decoder *d = ist->decoder; const Decoder *d = ist->decoder;
const InputFile *ifile = input_files[ist->file_index]; const InputFile *ifile = ist->file;
int64_t codec_duration = 0; int64_t codec_duration = 0;
// XXX lavf currently makes up frame durations when they are not provided by // 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) 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; Decoder *d = ist->decoder;
AVCodecContext *dec = ist->dec_ctx; AVCodecContext *dec = ist->dec_ctx;
const char *type_desc = av_get_media_type_string(dec->codec_type); 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); update_benchmark(NULL);
ret = avcodec_receive_frame(dec, frame); ret = avcodec_receive_frame(dec, frame);
update_benchmark("decode_%s %d.%d", type_desc, update_benchmark("decode_%s %d.%d", type_desc,
ist->file_index, ist->index); ifile->index, ist->index);
if (ret == AVERROR(EAGAIN)) { if (ret == AVERROR(EAGAIN)) {
av_assert0(pkt); // should never happen during flushing 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); ret = video_frame_process(ist, frame);
if (ret < 0) { if (ret < 0) {
av_log(NULL, AV_LOG_FATAL, "Error while processing the decoded " 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; 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) static void dec_thread_set_name(const InputStream *ist)
{ {
char name[16]; 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); ist->dec_ctx->codec->name);
ff_thread_setname(name); ff_thread_setname(name);
} }

View File

@ -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->pts), av_ts2timestr(pkt->pts, &pkt->time_base),
av_ts2str(pkt->dts), av_ts2timestr(pkt->dts, &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(pkt->duration), av_ts2timestr(pkt->duration, &pkt->time_base),
av_ts2str(input_files[ist->file_index]->ts_offset), av_ts2str(f->ts_offset), av_ts2timestr(f->ts_offset, &AV_TIME_BASE_Q));
av_ts2timestr(input_files[ist->file_index]->ts_offset, &AV_TIME_BASE_Q));
} }
pkt->stream_index = ds->sch_idx_stream; 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) 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); DemuxStream *ds = ds_from_ist(ist);
int ret; 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) 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); DemuxStream *ds = ds_from_ist(ist);
int ret; int ret;
@ -991,7 +990,7 @@ static DemuxStream *demux_stream_alloc(Demuxer *d, AVStream *st)
ds->sch_idx_dec = -1; ds->sch_idx_dec = -1;
ds->ist.st = st; ds->ist.st = st;
ds->ist.file_index = f->index; ds->ist.file = f;
ds->ist.index = st->index; ds->ist.index = st->index;
ds->ist.class = &input_stream_class; ds->ist.class = &input_stream_class;

View File

@ -1457,7 +1457,7 @@ static int configure_input_video_filter(FilterGraph *fg, AVFilterGraph *graph,
const AVFilter *buffer_filt = avfilter_get_by_name("buffer"); const AVFilter *buffer_filt = avfilter_get_by_name("buffer");
const AVPixFmtDescriptor *desc; const AVPixFmtDescriptor *desc;
InputStream *ist = ifp->ist; InputStream *ist = ifp->ist;
InputFile *f = input_files[ist->file_index]; InputFile *f = ist->file;
AVRational fr = ist->framerate; AVRational fr = ist->framerate;
AVRational sar; AVRational sar;
AVBPrint args; AVBPrint args;
@ -1498,7 +1498,7 @@ static int configure_input_video_filter(FilterGraph *fg, AVFilterGraph *graph,
if (fr.num && fr.den) if (fr.num && fr.den)
av_bprintf(&args, ":frame_rate=%d/%d", 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, 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, 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", snprintf(name, sizeof(name), "trim_in_%d_%d",
ist->file_index, ist->index); f->index, ist->index);
if (copy_ts) { if (copy_ts) {
tsoffset = f->start_time == AV_NOPTS_VALUE ? 0 : f->start_time; tsoffset = f->start_time == AV_NOPTS_VALUE ? 0 : f->start_time;
if (!start_at_zero && f->ctx->start_time != AV_NOPTS_VALUE) 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; AVFilterContext *last_filter;
const AVFilter *abuffer_filt = avfilter_get_by_name("abuffer"); const AVFilter *abuffer_filt = avfilter_get_by_name("abuffer");
InputStream *ist = ifp->ist; InputStream *ist = ifp->ist;
InputFile *f = input_files[ist->file_index]; InputFile *f = ist->file;
AVBPrint args; AVBPrint args;
char name[255]; char name[255];
int ret, pad_idx = 0; int ret, pad_idx = 0;
@ -1610,7 +1610,7 @@ static int configure_input_audio_filter(FilterGraph *fg, AVFilterGraph *graph,
} else } else
av_bprintf(&args, ":channels=%d", ifp->ch_layout.nb_channels); av_bprintf(&args, ":channels=%d", ifp->ch_layout.nb_channels);
snprintf(name, sizeof(name), "graph_%d_in_%d_%d", fg->index, 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, if ((ret = avfilter_graph_create_filter(&ifp->filter, abuffer_filt,
name, args.str, NULL, name, args.str, NULL,
@ -1619,7 +1619,7 @@ static int configure_input_audio_filter(FilterGraph *fg, AVFilterGraph *graph,
last_filter = ifp->filter; last_filter = ifp->filter;
snprintf(name, sizeof(name), "trim for input stream %d:%d", snprintf(name, sizeof(name), "trim for input stream %d:%d",
ist->file_index, ist->index); f->index, ist->index);
if (copy_ts) { if (copy_ts) {
tsoffset = f->start_time == AV_NOPTS_VALUE ? 0 : f->start_time; tsoffset = f->start_time == AV_NOPTS_VALUE ? 0 : f->start_time;
if (!start_at_zero && f->ctx->start_time != AV_NOPTS_VALUE) 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) { if (ifp->format < 0) {
av_log(NULL, AV_LOG_ERROR, av_log(NULL, AV_LOG_ERROR,
"Cannot determine format of input stream %d:%d after EOF\n", "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; return AVERROR_INVALIDDATA;
} }
} }

View File

@ -819,7 +819,7 @@ static int new_stream_video(Muxer *mux, const OptionsContext *o,
} }
if (ost->ist && ost->vsync_method == VSYNC_CFR) { 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) if (ifile->nb_streams == 1 && ifile->input_ts_offset == 0)
ost->vsync_method = VSYNC_VSCFR; ost->vsync_method = VSYNC_VSCFR;
@ -907,7 +907,7 @@ static int new_stream_audio(Muxer *mux, const OptionsContext *o,
ist = ost->ist; 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, ret = av_reallocp_array(&ost->audio_channels_map,
ost->audio_channels_mapped + 1, ost->audio_channels_mapped + 1,
sizeof(*ost->audio_channels_map)); sizeof(*ost->audio_channels_map));
@ -970,7 +970,7 @@ static int streamcopy_init(const Muxer *mux, OutputStream *ost)
MuxStream *ms = ms_from_ost(ost); MuxStream *ms = ms_from_ost(ost);
const InputStream *ist = ost->ist; const InputStream *ist = ost->ist;
const InputFile *ifile = input_files[ist->file_index]; const InputFile *ifile = ist->file;
AVCodecParameters *par = ost->par_in; AVCodecParameters *par = ost->par_in;
uint32_t codec_tag = par->codec_tag; 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)); av_get_media_type_string(type));
if (ist) if (ist)
av_log(ost, AV_LOG_VERBOSE, "input stream %d:%d", av_log(ost, AV_LOG_VERBOSE, "input stream %d:%d",
ist->file_index, ist->index); ist->file->index, ist->index);
else if (ofilter) else if (ofilter)
av_log(ost, AV_LOG_VERBOSE, "complex filtergraph %d:[%s]\n", av_log(ost, AV_LOG_VERBOSE, "complex filtergraph %d:[%s]\n",
ofilter->graph->index, ofilter->name); ofilter->graph->index, ofilter->name);
@ -1480,7 +1480,7 @@ static int ost_add(Muxer *mux, const OptionsContext *o, enum AVMediaType type,
if (ret < 0) if (ret < 0)
return ret; return ret;
} else { } 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)); SCH_MSTREAM(ost->file_index, ms->sch_idx));
if (ret < 0) if (ret < 0)
return ret; return ret;