History

lavfi: add a preinit callback to filters.

It is necessary for filters with child objects, to set the class and default options values.

Nicolas George committed 9 years ago

Commit f8d7b5f1 parent 19804022 files · +23 −0Browse files

Unified · Split

2 files
  1. libavfilter/avfilter.c +8 −0
  2. libavfilter/avfilter.h +15 −0
libavfilter/avfilter.c+8−0
@@ -692,6 +692,7 @@ static int default_execute(AVFilterContext *ctx, avfilter_action_func *func, voi · 691 unmodified lines
692692 AVFilterContext *ff_filter_alloc(const AVFilter *filter, const char *inst_name)
693693 {
694694 AVFilterContext *ret;
695+ int preinited = 0;
695696
696697 if (!filter)
697698 return NULL;
@@ -708,6 +709,11 @@ AVFilterContext *ff_filter_alloc(const AVFilter *filter, const char *inst_name) · 10 unmodified lines
708709 if (!ret->priv)
709710 goto err;
710711 }
712+ if (filter->preinit) {
713+ if (filter->preinit(ret) < 0)
714+ goto err;
715+ preinited = 1;
716+ }
711717
712718 av_opt_set_defaults(ret);
713719 if (filter->priv_class) {
@@ -745,6 +751,8 @@ AVFilterContext *ff_filter_alloc(const AVFilter *filter, const char *inst_name) · 31 unmodified lines
745751 return ret;
746752
747753 err:
754+ if (preinited)
755+ filter->uninit(ret);
748756 av_freep(&ret->inputs);
749757 av_freep(&ret->input_pads);
750758 ret->nb_inputs = 0;
libavfilter/avfilter.h+15−0
@@ -194,6 +194,21 @@ typedef struct AVFilter { · 193 unmodified lines
194194 *****************************************************************
195195 */
196196
197+ /**
198+ * Filter pre-initialization function
199+ *
200+ * This callback will be called immediately after the filter context is
201+ * allocated, to allow allocating and initing sub-objects.
202+ *
203+ * If this callback is not NULL, the uninit callback will be called on
204+ * allocation failure.
205+ *
206+ * @return 0 on success,
207+ * AVERROR code on failure (but the code will be
208+ * dropped and treated as ENOMEM by the calling code)
209+ */
210+ int (*preinit)(AVFilterContext *ctx);
211+
197212 /**
198213 * Filter initialization function.
199214 *

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t