aboutsummaryrefslogtreecommitdiffstats
path: root/fftools/ffmpeg_filter.c
diff options
context:
space:
mode:
authorAnton Khirnov <anton@khirnov.net>2023-03-15 19:09:11 +0100
committerAnton Khirnov <anton@khirnov.net>2023-03-24 10:23:52 +0100
commit3f63685c3554aea7f72bab1fdbde440820816d37 (patch)
treec99e10a11043d9c8e5af16403240ad1d7641fc28 /fftools/ffmpeg_filter.c
parent632c34993195f716e9fa575af3de80d07fd50991 (diff)
downloadffmpeg-3f63685c3554aea7f72bab1fdbde440820816d37.tar.gz
fftools/ffmpeg: supply hw_device_ctx to filters before initializing them
This is more correct, but was not possible before the recently-added filtergraph parsing API. Also, only pass hw devices to filters that are flagged as capable of using them. Tested-by: Niklas Haas
Diffstat (limited to 'fftools/ffmpeg_filter.c')
-rw-r--r--fftools/ffmpeg_filter.c26
1 files changed, 20 insertions, 6 deletions
diff --git a/fftools/ffmpeg_filter.c b/fftools/ffmpeg_filter.c
index 62d0eefa6d..4fde120067 100644
--- a/fftools/ffmpeg_filter.c
+++ b/fftools/ffmpeg_filter.c
@@ -440,7 +440,8 @@ static int graph_opts_apply(AVFilterGraphSegment *seg)
}
static int graph_parse(AVFilterGraph *graph, const char *desc,
- AVFilterInOut **inputs, AVFilterInOut **outputs)
+ AVFilterInOut **inputs, AVFilterInOut **outputs,
+ AVBufferRef *hw_device)
{
AVFilterGraphSegment *seg;
int ret;
@@ -456,6 +457,20 @@ static int graph_parse(AVFilterGraph *graph, const char *desc,
if (ret < 0)
goto fail;
+ if (hw_device) {
+ for (int i = 0; i < graph->nb_filters; i++) {
+ AVFilterContext *f = graph->filters[i];
+
+ if (!(f->filter->flags & AVFILTER_FLAG_HWDEVICE))
+ continue;
+ f->hw_device_ctx = av_buffer_ref(hw_device);
+ if (!f->hw_device_ctx) {
+ ret = AVERROR(ENOMEM);
+ goto fail;
+ }
+ }
+ }
+
ret = graph_opts_apply(seg);
if (ret < 0)
goto fail;
@@ -480,7 +495,7 @@ int init_complex_filtergraph(FilterGraph *fg)
return AVERROR(ENOMEM);
graph->nb_threads = 1;
- ret = graph_parse(graph, fg->graph_desc, &inputs, &outputs);
+ ret = graph_parse(graph, fg->graph_desc, &inputs, &outputs, NULL);
if (ret < 0)
goto fail;
@@ -1114,6 +1129,7 @@ static int graph_is_meta(AVFilterGraph *graph)
int configure_filtergraph(FilterGraph *fg)
{
+ AVBufferRef *hw_device;
AVFilterInOut *inputs, *outputs, *cur;
int ret, i, simple = filtergraph_is_simple(fg);
const char *graph_desc = simple ? fg->outputs[0]->ost->avfilter :
@@ -1157,11 +1173,9 @@ int configure_filtergraph(FilterGraph *fg)
fg->graph->nb_threads = filter_complex_nbthreads;
}
- if ((ret = graph_parse(fg->graph, graph_desc, &inputs, &outputs)) < 0)
- goto fail;
+ hw_device = hw_device_for_filter();
- ret = hw_device_setup_for_filter(fg);
- if (ret < 0)
+ if ((ret = graph_parse(fg->graph, graph_desc, &inputs, &outputs, hw_device)) < 0)
goto fail;
if (simple && (!inputs || inputs->next || !outputs || outputs->next)) {