diff mbox

[FFmpeg-devel,05/16] lavfi: add a preinit callback to filters.

Message ID 20170810114642.26779-5-george@nsup.org
State New
Headers show

Commit Message

Nicolas George Aug. 10, 2017, 11:46 a.m. UTC
It is necessary for filters with child objects, to set the class
and default options values.

Signed-off-by: Nicolas George <george@nsup.org>
---
 libavfilter/avfilter.c |  8 ++++++++
 libavfilter/avfilter.h | 15 +++++++++++++++
 2 files changed, 23 insertions(+)


Unchanged.
diff mbox

Patch

diff --git a/libavfilter/avfilter.c b/libavfilter/avfilter.c
index 185ba8df00..dcd975e104 100644
--- a/libavfilter/avfilter.c
+++ b/libavfilter/avfilter.c
@@ -692,6 +692,7 @@  static int default_execute(AVFilterContext *ctx, avfilter_action_func *func, voi
 AVFilterContext *ff_filter_alloc(const AVFilter *filter, const char *inst_name)
 {
     AVFilterContext *ret;
+    int preinited = 0;
 
     if (!filter)
         return NULL;
@@ -708,6 +709,11 @@  AVFilterContext *ff_filter_alloc(const AVFilter *filter, const char *inst_name)
         if (!ret->priv)
             goto err;
     }
+    if (filter->preinit) {
+        if (filter->preinit(ret) < 0)
+            goto err;
+        preinited = 1;
+    }
 
     av_opt_set_defaults(ret);
     if (filter->priv_class) {
@@ -745,6 +751,8 @@  AVFilterContext *ff_filter_alloc(const AVFilter *filter, const char *inst_name)
     return ret;
 
 err:
+    if (preinited)
+        filter->uninit(ret);
     av_freep(&ret->inputs);
     av_freep(&ret->input_pads);
     ret->nb_inputs = 0;
diff --git a/libavfilter/avfilter.h b/libavfilter/avfilter.h
index 60662c19ac..73a723d583 100644
--- a/libavfilter/avfilter.h
+++ b/libavfilter/avfilter.h
@@ -195,6 +195,21 @@  typedef struct AVFilter {
      */
 
     /**
+     * Filter pre-initialization function
+     *
+     * This callback will be called immediately after the filter context is
+     * allocated, to allow allocating and initing sub-objects.
+     *
+     * If this callback is not NULL, the uninit callback will be called on
+     * allocation failure.
+     *
+     * @return 0 on success,
+     *         AVERROR code on failure (but the code will be
+     *           dropped and treated as ENOMEM by the calling code)
+     */
+    int (*preinit)(AVFilterContext *ctx);
+
+    /**
      * Filter initialization function.
      *
      * This callback will be called only once during the filter lifetime, after