diff mbox series

[FFmpeg-devel,2/5] fftools/ffmpeg_filter: provide hwctx when probing graph

Message ID 20240209145349.104511-2-ffmpeg@haasn.xyz
State New
Headers show
Series [FFmpeg-devel,1/5] avfilter: tighten semantics on hw_device_ctx | expand

Checks

Context Check Description
yinshiyou/make_loongarch64 success Make finished
yinshiyou/make_fate_loongarch64 success Make fate finished
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished

Commit Message

Niklas Haas Feb. 9, 2024, 2:53 p.m. UTC
From: Niklas Haas <git@haasn.dev>

Otherwise, filters that depend on a hw_device_ctx being present at
init() time would fail configuring under the semantics outlined in the
previous commit.
---
 fftools/ffmpeg_filter.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

Comments

Anton Khirnov Feb. 9, 2024, 5:12 p.m. UTC | #1
Quoting Niklas Haas (2024-02-09 15:53:46)
> From: Niklas Haas <git@haasn.dev>
> 
> Otherwise, filters that depend on a hw_device_ctx being present at
> init() time would fail configuring under the semantics outlined in the
> previous commit.
> ---
>  fftools/ffmpeg_filter.c | 5 ++++-
>  1 file changed, 4 insertions(+), 1 deletion(-)
> 
> diff --git a/fftools/ffmpeg_filter.c b/fftools/ffmpeg_filter.c
> index 38ddd1963a..46e1d790e7 100644
> --- a/fftools/ffmpeg_filter.c
> +++ b/fftools/ffmpeg_filter.c
> @@ -931,6 +931,7 @@ int fg_create(FilterGraph **pfg, char *graph_desc, Scheduler *sch)
>  
>      AVFilterInOut *inputs, *outputs;
>      AVFilterGraph *graph;
> +    AVBufferRef *hw_device;
>      int ret = 0;
>  
>      fgp = allocate_array_elem(&filtergraphs, sizeof(*fgp), &nb_filtergraphs);
> @@ -961,7 +962,9 @@ int fg_create(FilterGraph **pfg, char *graph_desc, Scheduler *sch)
>          return AVERROR(ENOMEM);;
>      graph->nb_threads = 1;
>  
> -    ret = graph_parse(graph, fgp->graph_desc, &inputs, &outputs, NULL);
> +    hw_device = hw_device_for_filter();

This function may be called before any decoders are opened, and if I'm
reading the code right, opening decoders may creat new globally
available devices which are then returned from hw_device_for_filter().

It should probably be ok to cache the device you get here in
FilterGraphPriv to ensure you always use the same device.
diff mbox series

Patch

diff --git a/fftools/ffmpeg_filter.c b/fftools/ffmpeg_filter.c
index 38ddd1963a..46e1d790e7 100644
--- a/fftools/ffmpeg_filter.c
+++ b/fftools/ffmpeg_filter.c
@@ -931,6 +931,7 @@  int fg_create(FilterGraph **pfg, char *graph_desc, Scheduler *sch)
 
     AVFilterInOut *inputs, *outputs;
     AVFilterGraph *graph;
+    AVBufferRef *hw_device;
     int ret = 0;
 
     fgp = allocate_array_elem(&filtergraphs, sizeof(*fgp), &nb_filtergraphs);
@@ -961,7 +962,9 @@  int fg_create(FilterGraph **pfg, char *graph_desc, Scheduler *sch)
         return AVERROR(ENOMEM);;
     graph->nb_threads = 1;
 
-    ret = graph_parse(graph, fgp->graph_desc, &inputs, &outputs, NULL);
+    hw_device = hw_device_for_filter();
+
+    ret = graph_parse(graph, fgp->graph_desc, &inputs, &outputs, hw_device);
     if (ret < 0)
         goto fail;