Browse Source

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 <jamrial@gmail.com>
James Almer 1 month ago
parent
commit
cce85642c9
2 changed files with 25 additions and 0 deletions
  1. 23 0
      fftools/ffmpeg_sched.c
  2. 2 0
      fftools/ffmpeg_sched.h

+ 23 - 0
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);
 

+ 2 - 0
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.
  *