[FFmpeg-cvslog] fftools/ffmpeg_filter: split finding an unused stream into a function
Anton Khirnov
git at videolan.org
Mon May 22 18:11:29 EEST 2023
ffmpeg | branch: master | Anton Khirnov <anton at khirnov.net> | Thu May 11 10:40:58 2023 +0200| [ede6794d6a31c781f680e47c20515e18db0da454] | committer: Anton Khirnov
fftools/ffmpeg_filter: split finding an unused stream into a function
Avoids filtering code from digging in demuxer internals.
> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=ede6794d6a31c781f680e47c20515e18db0da454
---
fftools/ffmpeg.h | 5 +++++
fftools/ffmpeg_demux.c | 10 ++++++++++
fftools/ffmpeg_filter.c | 8 +-------
3 files changed, 16 insertions(+), 7 deletions(-)
diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h
index 3c7991c73a..9cb7198dfd 100644
--- a/fftools/ffmpeg.h
+++ b/fftools/ffmpeg.h
@@ -882,6 +882,11 @@ int ifile_get_packet(InputFile *f, AVPacket **pkt);
void ist_output_add(InputStream *ist, OutputStream *ost);
void ist_filter_add(InputStream *ist, InputFilter *ifilter, int is_simple);
+/**
+ * Find an unused input stream of given type.
+ */
+InputStream *ist_find_unused(enum AVMediaType type);
+
/* iterate over all input streams in all input files;
* pass NULL to start iteration */
InputStream *ist_iter(InputStream *prev);
diff --git a/fftools/ffmpeg_demux.c b/fftools/ffmpeg_demux.c
index 0a37cc7c25..b93e171037 100644
--- a/fftools/ffmpeg_demux.c
+++ b/fftools/ffmpeg_demux.c
@@ -130,6 +130,16 @@ static Demuxer *demuxer_from_ifile(InputFile *f)
return (Demuxer*)f;
}
+InputStream *ist_find_unused(enum AVMediaType type)
+{
+ for (InputStream *ist = ist_iter(NULL); ist; ist = ist_iter(ist)) {
+ if (ist->par->codec_type == type && ist->discard &&
+ ist->user_set_discard != AVDISCARD_ALL)
+ return ist;
+ }
+ return NULL;
+}
+
static void report_new_stream(Demuxer *d, const AVPacket *pkt)
{
AVStream *st = d->f.ctx->streams[pkt->stream_index];
diff --git a/fftools/ffmpeg_filter.c b/fftools/ffmpeg_filter.c
index 274eefe11c..8cc76209d0 100644
--- a/fftools/ffmpeg_filter.c
+++ b/fftools/ffmpeg_filter.c
@@ -420,13 +420,7 @@ static void init_input_filter(FilterGraph *fg, AVFilterInOut *in)
exit_program(1);
}
} else {
- /* find the first unused stream of corresponding type */
- for (ist = ist_iter(NULL); ist; ist = ist_iter(ist)) {
- if (ist->user_set_discard == AVDISCARD_ALL)
- continue;
- if (ist->dec_ctx->codec_type == type && ist->discard)
- break;
- }
+ ist = ist_find_unused(type);
if (!ist) {
av_log(NULL, AV_LOG_FATAL, "Cannot find a matching stream for "
"unlabeled input pad %d on filter %s\n", in->pad_idx,
More information about the ffmpeg-cvslog
mailing list