Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
* [FFmpeg-devel] [PATCH 1/3] fftools/ffmpeg_sched: add filter API to signal EOF on input
@ 2024-01-24 10:46 Anton Khirnov
  2024-01-24 10:46 ` [FFmpeg-devel] [PATCH 2/3] fftools/ffmpeg_filter: do not end filtering when a graph input EOFs Anton Khirnov
  2024-01-24 10:46 ` [FFmpeg-devel] [PATCH 3/3] tests/fate/ffmpeg: add a test for the issue fixed in previous commit Anton Khirnov
  0 siblings, 2 replies; 3+ messages in thread
From: Anton Khirnov @ 2024-01-24 10:46 UTC (permalink / raw)
  To: ffmpeg-devel

---
 fftools/ffmpeg_sched.c | 27 +++++++++++++++++++++++++--
 fftools/ffmpeg_sched.h |  7 +++++++
 2 files changed, 32 insertions(+), 2 deletions(-)

diff --git a/fftools/ffmpeg_sched.c b/fftools/ffmpeg_sched.c
index 4fc5a33941..c6ed2e21ff 100644
--- a/fftools/ffmpeg_sched.c
+++ b/fftools/ffmpeg_sched.c
@@ -226,6 +226,7 @@ typedef struct SchFilterIn {
     SchedulerNode       src;
     SchedulerNode       src_sched;
     int                 send_finished;
+    int                 receive_finished;
 } SchFilterIn;
 
 typedef struct SchFilterOut {
@@ -237,7 +238,8 @@ typedef struct SchFilterGraph {
 
     SchFilterIn        *inputs;
     unsigned         nb_inputs;
-    atomic_uint      nb_inputs_finished;
+    atomic_uint      nb_inputs_finished_send;
+    unsigned         nb_inputs_finished_receive;
 
     SchFilterOut       *outputs;
     unsigned         nb_outputs;
@@ -1959,7 +1961,7 @@ static int send_to_filter(Scheduler *sch, SchFilterGraph *fg,
         tq_send_finish(fg->queue, in_idx);
 
         // close the control stream when all actual inputs are done
-        if (atomic_fetch_add(&fg->nb_inputs_finished, 1) == fg->nb_inputs - 1)
+        if (atomic_fetch_add(&fg->nb_inputs_finished_send, 1) == fg->nb_inputs - 1)
             tq_send_finish(fg->queue, fg->nb_inputs);
     }
     return 0;
@@ -2143,6 +2145,27 @@ int sch_filter_receive(Scheduler *sch, unsigned fg_idx,
     }
 }
 
+void sch_filter_receive_finish(Scheduler *sch, unsigned fg_idx, unsigned in_idx)
+{
+    SchFilterGraph *fg;
+    SchFilterIn    *fi;
+
+    av_assert0(fg_idx < sch->nb_filters);
+    fg = &sch->filters[fg_idx];
+
+    av_assert0(in_idx < fg->nb_inputs);
+    fi = &fg->inputs[in_idx];
+
+    if (!fi->receive_finished) {
+        fi->receive_finished = 1;
+        tq_receive_finish(fg->queue, in_idx);
+
+        // close the control stream when all actual inputs are done
+        if (++fg->nb_inputs_finished_receive == fg->nb_inputs)
+            tq_receive_finish(fg->queue, fg->nb_inputs);
+    }
+}
+
 int sch_filter_send(Scheduler *sch, unsigned fg_idx, unsigned out_idx, AVFrame *frame)
 {
     SchFilterGraph *fg;
diff --git a/fftools/ffmpeg_sched.h b/fftools/ffmpeg_sched.h
index b167d8d158..811146f6ed 100644
--- a/fftools/ffmpeg_sched.h
+++ b/fftools/ffmpeg_sched.h
@@ -388,6 +388,13 @@ int sch_dec_send(Scheduler *sch, unsigned dec_idx, struct AVFrame *frame);
  */
 int sch_filter_receive(Scheduler *sch, unsigned fg_idx,
                        unsigned *in_idx, struct AVFrame *frame);
+/**
+ * Called by filter tasks to signal that a filter input will no longer accept input.
+ *
+ * @param fg_idx Filtergraph index previously returned from sch_add_filtergraph().
+ * @param in_idx Index of the input to finish.
+ */
+void sch_filter_receive_finish(Scheduler *sch, unsigned fg_idx, unsigned in_idx);
 
 /**
  * Called by filtergraph tasks to send a filtered frame or EOF to consumers.
-- 
2.42.0

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [FFmpeg-devel] [PATCH 2/3] fftools/ffmpeg_filter: do not end filtering when a graph input EOFs
  2024-01-24 10:46 [FFmpeg-devel] [PATCH 1/3] fftools/ffmpeg_sched: add filter API to signal EOF on input Anton Khirnov
@ 2024-01-24 10:46 ` Anton Khirnov
  2024-01-24 10:46 ` [FFmpeg-devel] [PATCH 3/3] tests/fate/ffmpeg: add a test for the issue fixed in previous commit Anton Khirnov
  1 sibling, 0 replies; 3+ messages in thread
From: Anton Khirnov @ 2024-01-24 10:46 UTC (permalink / raw)
  To: ffmpeg-devel

There may be other inputs or sources in the filtergraph. Propagate the
EOF to the scheduler and continue filtering.

Fixes #10803
---
 fftools/ffmpeg_filter.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/fftools/ffmpeg_filter.c b/fftools/ffmpeg_filter.c
index 82ee4fae7d..ab64b4610a 100644
--- a/fftools/ffmpeg_filter.c
+++ b/fftools/ffmpeg_filter.c
@@ -2871,6 +2871,12 @@ static void *filter_thread(void *arg)
             ret = send_eof(&fgt, ifilter, fgt.frame->pts, fgt.frame->time_base);
         }
         av_frame_unref(fgt.frame);
+        if (ret == AVERROR_EOF) {
+            av_log(fg, AV_LOG_VERBOSE, "Input %u no longer accepts new data\n",
+                   input_idx);
+            sch_filter_receive_finish(fgp->sch, fgp->sch_idx, input_idx);
+            continue;
+        }
         if (ret < 0)
             goto finish;
 
-- 
2.42.0

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [FFmpeg-devel] [PATCH 3/3] tests/fate/ffmpeg: add a test for the issue fixed in previous commit
  2024-01-24 10:46 [FFmpeg-devel] [PATCH 1/3] fftools/ffmpeg_sched: add filter API to signal EOF on input Anton Khirnov
  2024-01-24 10:46 ` [FFmpeg-devel] [PATCH 2/3] fftools/ffmpeg_filter: do not end filtering when a graph input EOFs Anton Khirnov
@ 2024-01-24 10:46 ` Anton Khirnov
  1 sibling, 0 replies; 3+ messages in thread
From: Anton Khirnov @ 2024-01-24 10:46 UTC (permalink / raw)
  To: ffmpeg-devel

---
 tests/fate/ffmpeg.mak               | 10 ++++++
 tests/ref/fate/ffmpeg-filter-in-eof | 55 +++++++++++++++++++++++++++++
 2 files changed, 65 insertions(+)
 create mode 100644 tests/ref/fate/ffmpeg-filter-in-eof

diff --git a/tests/fate/ffmpeg.mak b/tests/fate/ffmpeg.mak
index 84489e9fea..8c2f008d04 100644
--- a/tests/fate/ffmpeg.mak
+++ b/tests/fate/ffmpeg.mak
@@ -261,3 +261,13 @@ FATE_SAMPLES_FFMPEG-$(call ENCDEC, PCM_S16LE TTA, NULL MATROSKA) += fate-ffmpeg-
 # use -stream_loop, because it tests flushing bsfs
 fate-ffmpeg-bsf-input: CMD = framecrc -stream_loop 2 -bsf setts=PTS*2 -i $(TARGET_SAMPLES)/hevc/extradata-reload-multi-stsd.mov -c copy
 FATE_SAMPLES_FFMPEG-$(call FRAMECRC, MOV, , SETTS_BSF) += fate-ffmpeg-bsf-input
+
+# Test behaviour when a complex filtergraph returns EOF on one of its inputs,
+# but other inputs are still active.
+# cf. #10803
+fate-ffmpeg-filter-in-eof: tests/data/vsynth_lena.yuv
+fate-ffmpeg-filter-in-eof: CMD = framecrc                                                      \
+    -f rawvideo -s 352x288 -pix_fmt yuv420p -t 1 -i $(TARGET_PATH)/tests/data/vsynth_lena.yuv  \
+    -f rawvideo -s 352x288 -pix_fmt yuv420p -t 1 -i $(TARGET_PATH)/tests/data/vsynth_lena.yuv  \
+    -filter_complex "[0][1]concat" -c:v rawvideo
+FATE_FFMPEG-$(call FRAMECRC, RAWVIDEO, RAWVIDEO, CONCAT_FILTER) += fate-ffmpeg-filter-in-eof
diff --git a/tests/ref/fate/ffmpeg-filter-in-eof b/tests/ref/fate/ffmpeg-filter-in-eof
new file mode 100644
index 0000000000..77be842408
--- /dev/null
+++ b/tests/ref/fate/ffmpeg-filter-in-eof
@@ -0,0 +1,55 @@
+#tb 0: 1/25
+#media_type 0: video
+#codec_id 0: rawvideo
+#dimensions 0: 352x288
+#sar 0: 0/1
+0,          0,          0,        1,   152064, 0x07945924
+0,          1,          1,        1,   152064, 0x08472470
+0,          2,          2,        1,   152064, 0x63fde13b
+0,          3,          3,        1,   152064, 0x67ba9c55
+0,          4,          4,        1,   152064, 0x8aa34b24
+0,          5,          5,        1,   152064, 0x9fba089e
+0,          6,          6,        1,   152064, 0xb040d8e3
+0,          7,          7,        1,   152064, 0x3061ae08
+0,          8,          8,        1,   152064, 0xf5907946
+0,          9,          9,        1,   152064, 0x0ea24935
+0,         10,         10,        1,   152064, 0x7d87276b
+0,         11,         11,        1,   152064, 0x122c252b
+0,         12,         12,        1,   152064, 0xdb0f3889
+0,         13,         13,        1,   152064, 0x88466739
+0,         14,         14,        1,   152064, 0xca87a583
+0,         15,         15,        1,   152064, 0x34f9da44
+0,         16,         16,        1,   152064, 0x1d4e1646
+0,         17,         17,        1,   152064, 0x29975c2b
+0,         18,         18,        1,   152064, 0xbf82aae9
+0,         19,         19,        1,   152064, 0x33c2fd7c
+0,         20,         20,        1,   152064, 0xa3c95f44
+0,         21,         21,        1,   152064, 0x5f93bc9d
+0,         22,         22,        1,   152064, 0xa6f11b51
+0,         23,         23,        1,   152064, 0x39bc6b45
+0,         24,         24,        1,   152064, 0xfd509e1d
+0,         25,         25,        1,   152064, 0x07945924
+0,         26,         26,        1,   152064, 0x08472470
+0,         27,         27,        1,   152064, 0x63fde13b
+0,         28,         28,        1,   152064, 0x67ba9c55
+0,         29,         29,        1,   152064, 0x8aa34b24
+0,         30,         30,        1,   152064, 0x9fba089e
+0,         31,         31,        1,   152064, 0xb040d8e3
+0,         32,         32,        1,   152064, 0x3061ae08
+0,         33,         33,        1,   152064, 0xf5907946
+0,         34,         34,        1,   152064, 0x0ea24935
+0,         35,         35,        1,   152064, 0x7d87276b
+0,         36,         36,        1,   152064, 0x122c252b
+0,         37,         37,        1,   152064, 0xdb0f3889
+0,         38,         38,        1,   152064, 0x88466739
+0,         39,         39,        1,   152064, 0xca87a583
+0,         40,         40,        1,   152064, 0x34f9da44
+0,         41,         41,        1,   152064, 0x1d4e1646
+0,         42,         42,        1,   152064, 0x29975c2b
+0,         43,         43,        1,   152064, 0xbf82aae9
+0,         44,         44,        1,   152064, 0x33c2fd7c
+0,         45,         45,        1,   152064, 0xa3c95f44
+0,         46,         46,        1,   152064, 0x5f93bc9d
+0,         47,         47,        1,   152064, 0xa6f11b51
+0,         48,         48,        1,   152064, 0x39bc6b45
+0,         49,         49,        1,   152064, 0xfd509e1d
-- 
2.42.0

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2024-01-24 10:46 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-01-24 10:46 [FFmpeg-devel] [PATCH 1/3] fftools/ffmpeg_sched: add filter API to signal EOF on input Anton Khirnov
2024-01-24 10:46 ` [FFmpeg-devel] [PATCH 2/3] fftools/ffmpeg_filter: do not end filtering when a graph input EOFs Anton Khirnov
2024-01-24 10:46 ` [FFmpeg-devel] [PATCH 3/3] tests/fate/ffmpeg: add a test for the issue fixed in previous commit Anton Khirnov

Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
		ffmpegdev@gitmailbox.com
	public-inbox-index ffmpegdev

Example config snippet for mirrors.


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git