From cce85642c90097e235086e65ddfc0f41c5f90608 Mon Sep 17 00:00:00 2001 From: James Almer Date: Sat, 18 Oct 2025 20:08:49 -0300 Subject: [PATCH] fftools/ffmpeg_sched: add a function to remove a filtergraph from the scheduler For the purpose of merging streams in a stream group, a filtergraph can't be created once we know it will be used. Therefore, allow filtergraphs to be removed from the scheduler after being added. Signed-off-by: James Almer --- fftools/ffmpeg_sched.c | 23 +++++++++++++++++++++++ fftools/ffmpeg_sched.h | 2 ++ 2 files changed, 25 insertions(+) diff --git a/fftools/ffmpeg_sched.c b/fftools/ffmpeg_sched.c index d08f4a061d..ed85bb16de 100644 --- a/fftools/ffmpeg_sched.c +++ b/fftools/ffmpeg_sched.c @@ -405,6 +405,9 @@ static int task_start(SchTask *task) { int ret; + if (!task->parent) + return 0; + av_log(task->func_arg, AV_LOG_VERBOSE, "Starting thread...\n"); av_assert0(!task->thread_running); @@ -454,6 +457,23 @@ static int64_t trailing_dts(const Scheduler *sch, int count_finished) return min_dts == INT64_MAX ? AV_NOPTS_VALUE : min_dts; } +void sch_remove_filtergraph(Scheduler *sch, int idx) +{ + SchFilterGraph *fg = &sch->filters[idx]; + + av_assert0(!fg->task.thread_running); + memset(&fg->task, 0, sizeof(fg->task)); + + tq_free(&fg->queue); + + av_freep(&fg->inputs); + fg->nb_inputs = 0; + av_freep(&fg->outputs); + fg->nb_outputs = 0; + + fg->task_exited = 1; +} + void sch_free(Scheduler **psch) { Scheduler *sch = *psch; @@ -2630,6 +2650,9 @@ static int task_stop(Scheduler *sch, SchTask *task) int ret; void *thread_ret; + if (!task->parent) + return 0; + if (!task->thread_running) return task_cleanup(sch, task->node); diff --git a/fftools/ffmpeg_sched.h b/fftools/ffmpeg_sched.h index 0c01f558e4..2cf3034437 100644 --- a/fftools/ffmpeg_sched.h +++ b/fftools/ffmpeg_sched.h @@ -205,6 +205,8 @@ int sch_add_dec_output(Scheduler *sch, unsigned dec_idx); int sch_add_filtergraph(Scheduler *sch, unsigned nb_inputs, unsigned nb_outputs, SchThreadFunc func, void *ctx); +void sch_remove_filtergraph(Scheduler *sch, int idx); + /** * Add a muxer to the scheduler. *