diff mbox series

[FFmpeg-devel,1/5] avfilter/avfilter: Add avfilter_alloc() and avfilter_query_formats() for initializing filters without a graph

Message ID MN2PR04MB59813121DD005722D5CDBD8ABAB79@MN2PR04MB5981.namprd04.prod.outlook.com
State New
Headers show
Series [FFmpeg-devel,1/5] avfilter/avfilter: Add avfilter_alloc() and avfilter_query_formats() for initializing filters without a graph | expand

Checks

Context Check Description
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished
andriy/make_ppc success Make finished
andriy/make_fate_ppc success Make fate finished

Commit Message

Soft Works Oct. 13, 2021, 4:49 a.m. UTC
The purpose of these additions is for being able to programatically retrieve
the supported formats of a filter for each input and output without adding
the filter to a graph and creating connections.

Signed-off-by: softworkz <softworkz@hotmail.com>
---
 doc/APIchanges              |  3 +++
 libavfilter/avfilter.c      |  4 ++--
 libavfilter/avfilter.h      | 22 ++++++++++++++++++++++
 libavfilter/avfiltergraph.c | 18 ++++++++++++++----
 libavfilter/version.h       |  2 +-
 5 files changed, 42 insertions(+), 7 deletions(-)

Comments

Paul B Mahol Oct. 13, 2021, 7:16 a.m. UTC | #1
On Wed, Oct 13, 2021 at 6:50 AM Soft Works <softworkz@hotmail.com> wrote:

> The purpose of these additions is for being able to programatically
> retrieve
> the supported formats of a filter for each input and output without adding
> the filter to a graph and creating connections.
>

That is flawed by definition.


>
> Signed-off-by: softworkz <softworkz@hotmail.com>
> ---
>  doc/APIchanges              |  3 +++
>  libavfilter/avfilter.c      |  4 ++--
>  libavfilter/avfilter.h      | 22 ++++++++++++++++++++++
>  libavfilter/avfiltergraph.c | 18 ++++++++++++++----
>  libavfilter/version.h       |  2 +-
>  5 files changed, 42 insertions(+), 7 deletions(-)
>
> diff --git a/doc/APIchanges b/doc/APIchanges
> index 7b267a79ac..903de43365 100644
> --- a/doc/APIchanges
> +++ b/doc/APIchanges
> @@ -14,6 +14,9 @@ libavutil:     2021-04-27
>
>  API changes, most recent first:
>
> +2021-10-12 - xxxxxxxxxx - lavf 8.13.100 - avfilter.h
> +  Add avfilter_alloc() and avfilter_query_formats().
> +
>  2021-09-21 - xxxxxxxxxx - lavu 57.7.100 - pixfmt.h
>    Add AV_PIX_FMT_X2BGR10.
>
> diff --git a/libavfilter/avfilter.c b/libavfilter/avfilter.c
> index 7362bcdab5..645af2cb11 100644
> --- a/libavfilter/avfilter.c
> +++ b/libavfilter/avfilter.c
> @@ -769,12 +769,12 @@ void avfilter_free(AVFilterContext *filter)
>
>      for (i = 0; i < filter->nb_inputs; i++) {
>          free_link(filter->inputs[i]);
> -        if (filter->input_pads[i].flags  & AVFILTERPAD_FLAG_FREE_NAME)
> +        if (filter->input_pads && filter->input_pads[i].flags  &
> AVFILTERPAD_FLAG_FREE_NAME)
>              av_freep(&filter->input_pads[i].name);
>      }
>      for (i = 0; i < filter->nb_outputs; i++) {
>          free_link(filter->outputs[i]);
> -        if (filter->output_pads[i].flags & AVFILTERPAD_FLAG_FREE_NAME)
> +        if (filter->output_pads && filter->output_pads[i].flags &
> AVFILTERPAD_FLAG_FREE_NAME)
>              av_freep(&filter->output_pads[i].name);
>      }
>
> diff --git a/libavfilter/avfilter.h b/libavfilter/avfilter.h
> index f7208754a7..24119993d6 100644
> --- a/libavfilter/avfilter.h
> +++ b/libavfilter/avfilter.h
> @@ -911,6 +911,28 @@ typedef struct AVFilterGraph {
>      unsigned disable_auto_convert;
>  } AVFilterGraph;
>
> +/**
> + * Allocate a new filter context and return it.
> + *
> + * @param filter what filter to create an instance of
> + * @param inst_name name to give to the new filter context
> + *
> + * @return newly created filter context or NULL on failure
> + *
> + * @note for adding a filter to a filtergraph, use
> + *       avfilter_graph_alloc_filter() instead.
> + */
> +AVFilterContext *avfilter_alloc(const AVFilter *filter, const char
> *inst_name);
> +
> +/**
> + * Query the formats of a filter.
> + *
> + * @param filter the filter context
> + *
> + * @return 0 on success
> + */
> +int avfilter_query_formats(AVFilterContext *filter);
> +
>  /**
>   * Allocate a filter graph.
>   *
> diff --git a/libavfilter/avfiltergraph.c b/libavfilter/avfiltergraph.c
> index b8b432e98b..64379782fc 100644
> --- a/libavfilter/avfiltergraph.c
> +++ b/libavfilter/avfiltergraph.c
> @@ -81,6 +81,11 @@ int ff_graph_thread_init(AVFilterGraph *graph)
>  }
>  #endif
>
> +AVFilterContext *avfilter_alloc(const AVFilter *filter, const char
> *inst_name)
> +{
> +    return ff_filter_alloc(filter, inst_name);
> +}
> +
>  AVFilterGraph *avfilter_graph_alloc(void)
>  {
>      AVFilterGraph *ret = av_mallocz(sizeof(*ret));
> @@ -395,6 +400,14 @@ static int formats_declared(AVFilterContext *f)
>      return 1;
>  }
>
> +int avfilter_query_formats(AVFilterContext *filter)
> +{
> +    if (filter->filter->formats_state == FF_FILTER_FORMATS_QUERY_FUNC)
> +        return filter_query_formats(filter);
> +
> +    return ff_default_query_formats(filter);
> +}
> +
>  /**
>   * Perform one round of query_formats() and merging formats lists on the
>   * filter graph.
> @@ -418,10 +431,7 @@ static int query_formats(AVFilterGraph *graph, void
> *log_ctx)
>          AVFilterContext *f = graph->filters[i];
>          if (formats_declared(f))
>              continue;
> -        if (f->filter->formats_state == FF_FILTER_FORMATS_QUERY_FUNC)
> -            ret = filter_query_formats(f);
> -        else
> -            ret = ff_default_query_formats(f);
> +        ret = avfilter_query_formats(f);
>          if (ret < 0 && ret != AVERROR(EAGAIN))
>              return ret;
>          /* note: EAGAIN could indicate a partial success, not counted yet
> */
> diff --git a/libavfilter/version.h b/libavfilter/version.h
> index e4c25b9225..dca5aacb45 100644
> --- a/libavfilter/version.h
> +++ b/libavfilter/version.h
> @@ -30,7 +30,7 @@
>  #include "libavutil/version.h"
>
>  #define LIBAVFILTER_VERSION_MAJOR   8
> -#define LIBAVFILTER_VERSION_MINOR  12
> +#define LIBAVFILTER_VERSION_MINOR  13
>  #define LIBAVFILTER_VERSION_MICRO 100
>
>
> --
> 2.30.2.windows.1
>
> _______________________________________________
> 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".
>
Soft Works Oct. 13, 2021, 7:23 a.m. UTC | #2
> -----Original Message-----
> From: ffmpeg-devel <ffmpeg-devel-bounces@ffmpeg.org> On Behalf Of
> Paul B Mahol
> Sent: Wednesday, October 13, 2021 9:16 AM
> To: FFmpeg development discussions and patches <ffmpeg-
> devel@ffmpeg.org>
> Subject: Re: [FFmpeg-devel] [PATCH 1/5] avfilter/avfilter: Add
> avfilter_alloc() and avfilter_query_formats() for initializing
> filters without a graph
> 
> On Wed, Oct 13, 2021 at 6:50 AM Soft Works <softworkz@hotmail.com>
> wrote:
> 
> > The purpose of these additions is for being able to programatically
> > retrieve
> > the supported formats of a filter for each input and output without
> adding
> > the filter to a graph and creating connections.
> >
> 
> That is flawed by definition.

Could you please give an example where you think the output
would be incorrect?

Thanks,
softworkz
diff mbox series

Patch

diff --git a/doc/APIchanges b/doc/APIchanges
index 7b267a79ac..903de43365 100644
--- a/doc/APIchanges
+++ b/doc/APIchanges
@@ -14,6 +14,9 @@  libavutil:     2021-04-27
 
 API changes, most recent first:
 
+2021-10-12 - xxxxxxxxxx - lavf 8.13.100 - avfilter.h
+  Add avfilter_alloc() and avfilter_query_formats().
+
 2021-09-21 - xxxxxxxxxx - lavu 57.7.100 - pixfmt.h
   Add AV_PIX_FMT_X2BGR10.
 
diff --git a/libavfilter/avfilter.c b/libavfilter/avfilter.c
index 7362bcdab5..645af2cb11 100644
--- a/libavfilter/avfilter.c
+++ b/libavfilter/avfilter.c
@@ -769,12 +769,12 @@  void avfilter_free(AVFilterContext *filter)
 
     for (i = 0; i < filter->nb_inputs; i++) {
         free_link(filter->inputs[i]);
-        if (filter->input_pads[i].flags  & AVFILTERPAD_FLAG_FREE_NAME)
+        if (filter->input_pads && filter->input_pads[i].flags  & AVFILTERPAD_FLAG_FREE_NAME)
             av_freep(&filter->input_pads[i].name);
     }
     for (i = 0; i < filter->nb_outputs; i++) {
         free_link(filter->outputs[i]);
-        if (filter->output_pads[i].flags & AVFILTERPAD_FLAG_FREE_NAME)
+        if (filter->output_pads && filter->output_pads[i].flags & AVFILTERPAD_FLAG_FREE_NAME)
             av_freep(&filter->output_pads[i].name);
     }
 
diff --git a/libavfilter/avfilter.h b/libavfilter/avfilter.h
index f7208754a7..24119993d6 100644
--- a/libavfilter/avfilter.h
+++ b/libavfilter/avfilter.h
@@ -911,6 +911,28 @@  typedef struct AVFilterGraph {
     unsigned disable_auto_convert;
 } AVFilterGraph;
 
+/**
+ * Allocate a new filter context and return it.
+ *
+ * @param filter what filter to create an instance of
+ * @param inst_name name to give to the new filter context
+ *
+ * @return newly created filter context or NULL on failure
+ *
+ * @note for adding a filter to a filtergraph, use
+ *       avfilter_graph_alloc_filter() instead.
+ */
+AVFilterContext *avfilter_alloc(const AVFilter *filter, const char *inst_name);
+
+/**
+ * Query the formats of a filter.
+ *
+ * @param filter the filter context
+ *
+ * @return 0 on success
+ */
+int avfilter_query_formats(AVFilterContext *filter);
+
 /**
  * Allocate a filter graph.
  *
diff --git a/libavfilter/avfiltergraph.c b/libavfilter/avfiltergraph.c
index b8b432e98b..64379782fc 100644
--- a/libavfilter/avfiltergraph.c
+++ b/libavfilter/avfiltergraph.c
@@ -81,6 +81,11 @@  int ff_graph_thread_init(AVFilterGraph *graph)
 }
 #endif
 
+AVFilterContext *avfilter_alloc(const AVFilter *filter, const char *inst_name)
+{
+    return ff_filter_alloc(filter, inst_name);
+}
+
 AVFilterGraph *avfilter_graph_alloc(void)
 {
     AVFilterGraph *ret = av_mallocz(sizeof(*ret));
@@ -395,6 +400,14 @@  static int formats_declared(AVFilterContext *f)
     return 1;
 }
 
+int avfilter_query_formats(AVFilterContext *filter)
+{
+    if (filter->filter->formats_state == FF_FILTER_FORMATS_QUERY_FUNC)
+        return filter_query_formats(filter);
+
+    return ff_default_query_formats(filter);
+}
+
 /**
  * Perform one round of query_formats() and merging formats lists on the
  * filter graph.
@@ -418,10 +431,7 @@  static int query_formats(AVFilterGraph *graph, void *log_ctx)
         AVFilterContext *f = graph->filters[i];
         if (formats_declared(f))
             continue;
-        if (f->filter->formats_state == FF_FILTER_FORMATS_QUERY_FUNC)
-            ret = filter_query_formats(f);
-        else
-            ret = ff_default_query_formats(f);
+        ret = avfilter_query_formats(f);
         if (ret < 0 && ret != AVERROR(EAGAIN))
             return ret;
         /* note: EAGAIN could indicate a partial success, not counted yet */
diff --git a/libavfilter/version.h b/libavfilter/version.h
index e4c25b9225..dca5aacb45 100644
--- a/libavfilter/version.h
+++ b/libavfilter/version.h
@@ -30,7 +30,7 @@ 
 #include "libavutil/version.h"
 
 #define LIBAVFILTER_VERSION_MAJOR   8
-#define LIBAVFILTER_VERSION_MINOR  12
+#define LIBAVFILTER_VERSION_MINOR  13
 #define LIBAVFILTER_VERSION_MICRO 100