It is necessary for filters with child objects, to set the class and default options values.
Showing the changes to libavfilter (2 of 2 files). Show all
Unified · Split
| @@ -692,6 +692,7 @@ static int default_execute(AVFilterContext *ctx, avfilter_action_func *func, voi · 691 unmodified lines | ||
| 692 | 692 | AVFilterContext *ff_filter_alloc(const AVFilter *filter, const char *inst_name) |
| 693 | 693 | { |
| 694 | 694 | AVFilterContext *ret; |
| 695 | + int preinited = 0; | |
| 695 | 696 | |
| 696 | 697 | if (!filter) |
| 697 | 698 | return NULL; |
| @@ -708,6 +709,11 @@ AVFilterContext *ff_filter_alloc(const AVFilter *filter, const char *inst_name) · 10 unmodified lines | ||
| 708 | 709 | if (!ret->priv) |
| 709 | 710 | goto err; |
| 710 | 711 | } |
| 712 | + if (filter->preinit) { | |
| 713 | + if (filter->preinit(ret) < 0) | |
| 714 | + goto err; | |
| 715 | + preinited = 1; | |
| 716 | + } | |
| 711 | 717 | |
| 712 | 718 | av_opt_set_defaults(ret); |
| 713 | 719 | if (filter->priv_class) { |
| @@ -745,6 +751,8 @@ AVFilterContext *ff_filter_alloc(const AVFilter *filter, const char *inst_name) · 31 unmodified lines | ||
| 745 | 751 | return ret; |
| 746 | 752 | |
| 747 | 753 | err: |
| 754 | + if (preinited) | |
| 755 | + filter->uninit(ret); | |
| 748 | 756 | av_freep(&ret->inputs); |
| 749 | 757 | av_freep(&ret->input_pads); |
| 750 | 758 | ret->nb_inputs = 0; |
| @@ -194,6 +194,21 @@ typedef struct AVFilter { · 193 unmodified lines | ||
| 194 | 194 | ***************************************************************** |
| 195 | 195 | */ |
| 196 | 196 | |
| 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 | + | |
| 197 | 212 | /** |
| 198 | 213 | * Filter initialization function. |
| 199 | 214 | * |