diff mbox series

[FFmpeg-devel,09/36] fftools/ffmpeg_filter: split finding an unused stream into a function

Message ID 20230517102029.541-9-anton@khirnov.net
State Accepted
Commit ede6794d6a31c781f680e47c20515e18db0da454
Headers show
Series [FFmpeg-devel,01/36] fftools/ffmpeg: shorten a variable name | expand

Checks

Context Check Description
yinshiyou/make_loongarch64 success Make finished
yinshiyou/make_fate_loongarch64 fail Make fate failed

Commit Message

Anton Khirnov May 17, 2023, 10:20 a.m. UTC
Avoids filtering code from digging in demuxer internals.
---
 fftools/ffmpeg.h        |  5 +++++
 fftools/ffmpeg_demux.c  | 10 ++++++++++
 fftools/ffmpeg_filter.c |  8 +-------
 3 files changed, 16 insertions(+), 7 deletions(-)
diff mbox series

Patch

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,