Since we do not support "standalone" filters not attached to an AVFilterGraph, we should not have a public function to create such filters. In addition that function is horribly named, the action it does cannot be possibly described as "opening" a filter.
Unified · Split
| @@ -16,6 +16,7 @@ API changes, most recent first: · 15 unmodified lines | ||
| 16 | 16 | 2013-xx-xx - lavfi 3.8.0 |
| 17 | 17 | Move all content from avfiltergraph.h to avfilter.h. Deprecate |
| 18 | 18 | avfilterhraph.h, user applications should include just avfilter.h |
| 19 | + Add avfilter_graph_alloc_filter(), deprecate avfilter_open(). | |
| 19 | 20 | |
| 20 | 21 | 2013-xx-xx - lavfi 3.7.0 - avfilter.h |
| 21 | 22 | Add AVFilter.priv_class for exporting filter options through the AVOptions API |
| @@ -352,17 +352,16 @@ static const AVClass avfilter_class = { · 351 unmodified lines | ||
| 352 | 352 | .child_class_next = filter_child_class_next, |
| 353 | 353 | }; |
| 354 | 354 | |
| 355 | −int avfilter_open(AVFilterContext **filter_ctx, AVFilter *filter, const char *inst_name) | |
| 355 | +AVFilterContext *ff_filter_alloc(const AVFilter *filter, const char *inst_name) | |
| 356 | 356 | { |
| 357 | 357 | AVFilterContext *ret; |
| 358 | − *filter_ctx = NULL; | |
| 359 | 358 | |
| 360 | 359 | if (!filter) |
| 361 | − return AVERROR(EINVAL); | |
| 360 | + return NULL; | |
| 362 | 361 | |
| 363 | 362 | ret = av_mallocz(sizeof(AVFilterContext)); |
| 364 | 363 | if (!ret) |
| 365 | − return AVERROR(ENOMEM); | |
| 364 | + return NULL; | |
| 366 | 365 | |
| 367 | 366 | ret->av_class = &avfilter_class; |
| 368 | 367 | ret->filter = filter; |
| @@ -404,8 +403,7 @@ int avfilter_open(AVFilterContext **filter_ctx, AVFilter *filter, const char *in · 35 unmodified lines | ||
| 404 | 403 | ret->input_count = ret->nb_inputs; |
| 405 | 404 | #endif |
| 406 | 405 | |
| 407 | − *filter_ctx = ret; | |
| 408 | − return 0; | |
| 406 | + return ret; | |
| 409 | 407 | |
| 410 | 408 | err: |
| 411 | 409 | av_freep(&ret->inputs); |
| @@ -416,9 +414,17 @@ err: · 4 unmodified lines | ||
| 416 | 414 | ret->nb_outputs = 0; |
| 417 | 415 | av_freep(&ret->priv); |
| 418 | 416 | av_free(ret); |
| 419 | − return AVERROR(ENOMEM); | |
| 417 | + return NULL; | |
| 420 | 418 | } |
| 421 | 419 | |
| 420 | +#if FF_API_AVFILTER_OPEN | |
| 421 | +int avfilter_open(AVFilterContext **filter_ctx, AVFilter *filter, const char *inst_name) | |
| 422 | +{ | |
| 423 | + *filter_ctx = ff_filter_alloc(filter, inst_name); | |
| 424 | + return *filter_ctx ? 0 : AVERROR(ENOMEM); | |
| 425 | +} | |
| 426 | +#endif | |
| 427 | + | |
| 422 | 428 | void avfilter_free(AVFilterContext *filter) |
| 423 | 429 | { |
| 424 | 430 | int i; |
| @@ -602,8 +602,8 @@ void avfilter_uninit(void); · 601 unmodified lines | ||
| 602 | 602 | /** |
| 603 | 603 | * Register a filter. This is only needed if you plan to use |
| 604 | 604 | * avfilter_get_by_name later to lookup the AVFilter structure by name. A |
| 605 | − * filter can still by instantiated with avfilter_open even if it is not | |
| 606 | − * registered. | |
| 605 | + * filter can still by instantiated with avfilter_graph_alloc_filter even if it | |
| 606 | + * is not registered. | |
| 607 | 607 | * |
| 608 | 608 | * @param filter the filter to register |
| 609 | 609 | * @return 0 if the registration was succesfull, a negative value |
| @@ -628,6 +628,7 @@ AVFilter *avfilter_get_by_name(const char *name); · 18 unmodified lines | ||
| 628 | 628 | */ |
| 629 | 629 | AVFilter **av_filter_next(AVFilter **filter); |
| 630 | 630 | |
| 631 | +#if FF_API_AVFILTER_OPEN | |
| 631 | 632 | /** |
| 632 | 633 | * Create a filter instance. |
| 633 | 634 | * |
| @@ -636,8 +637,11 @@ AVFilter **av_filter_next(AVFilter **filter); · 2 unmodified lines | ||
| 636 | 637 | * @param filter the filter to create an instance of |
| 637 | 638 | * @param inst_name Name to give to the new instance. Can be NULL for none. |
| 638 | 639 | * @return >= 0 in case of success, a negative error code otherwise |
| 640 | + * @deprecated use avfilter_graph_alloc_filter() instead | |
| 639 | 641 | */ |
| 642 | +attribute_deprecated | |
| 640 | 643 | int avfilter_open(AVFilterContext **filter_ctx, AVFilter *filter, const char *inst_name); |
| 644 | +#endif | |
| 641 | 645 | |
| 642 | 646 | /** |
| 643 | 647 | * Initialize a filter. |
| @@ -720,6 +724,24 @@ typedef struct AVFilterGraph { · 76 unmodified lines | ||
| 720 | 724 | */ |
| 721 | 725 | AVFilterGraph *avfilter_graph_alloc(void); |
| 722 | 726 | |
| 727 | +/** | |
| 728 | + * Create a new filter instance in a filter graph. | |
| 729 | + * | |
| 730 | + * @param graph graph in which the new filter will be used | |
| 731 | + * @param filter the filter to create an instance of | |
| 732 | + * @param name Name to give to the new instance (will be copied to | |
| 733 | + * AVFilterContext.name). This may be used by the caller to identify | |
| 734 | + * different filters, libavfilter itself assigns no semantics to | |
| 735 | + * this parameter. May be NULL. | |
| 736 | + * | |
| 737 | + * @return the context of the newly created filter instance (note that it is | |
| 738 | + * also retrievable directly through AVFilterGraph.filters or with | |
| 739 | + * avfilter_graph_get_filter()) on success or NULL or failure. | |
| 740 | + */ | |
| 741 | +AVFilterContext *avfilter_graph_alloc_filter(AVFilterGraph *graph, | |
| 742 | + const AVFilter *filter, | |
| 743 | + const char *name); | |
| 744 | + | |
| 723 | 745 | /** |
| 724 | 746 | * Get a filter instance with name name from graph. |
| 725 | 747 | * |
| @@ -81,12 +81,12 @@ int avfilter_graph_create_filter(AVFilterContext **filt_ctx, AVFilter *filt, · 80 unmodified lines | ||
| 81 | 81 | { |
| 82 | 82 | int ret; |
| 83 | 83 | |
| 84 | − if ((ret = avfilter_open(filt_ctx, filt, name)) < 0) | |
| 85 | − goto fail; | |
| 84 | + *filt_ctx = avfilter_graph_alloc_filter(graph_ctx, filt, name); | |
| 85 | + if (!*filt_ctx) | |
| 86 | + return AVERROR(ENOMEM); | |
| 86 | 87 | if ((ret = avfilter_init_filter(*filt_ctx, args, opaque)) < 0) |
| 87 | 88 | goto fail; |
| 88 | − if ((ret = avfilter_graph_add_filter(graph_ctx, *filt_ctx)) < 0) | |
| 89 | − goto fail; | |
| 89 | + | |
| 90 | 90 | return 0; |
| 91 | 91 | |
| 92 | 92 | fail: |
| @@ -96,6 +96,32 @@ fail: · 3 unmodified lines | ||
| 96 | 96 | return ret; |
| 97 | 97 | } |
| 98 | 98 | |
| 99 | +AVFilterContext *avfilter_graph_alloc_filter(AVFilterGraph *graph, | |
| 100 | + const AVFilter *filter, | |
| 101 | + const char *name) | |
| 102 | +{ | |
| 103 | + AVFilterContext **filters, *s; | |
| 104 | + | |
| 105 | + s = ff_filter_alloc(filter, name); | |
| 106 | + if (!s) | |
| 107 | + return NULL; | |
| 108 | + | |
| 109 | + filters = av_realloc(graph->filters, sizeof(*filters) * (graph->nb_filters + 1)); | |
| 110 | + if (!filters) { | |
| 111 | + avfilter_free(s); | |
| 112 | + return NULL; | |
| 113 | + } | |
| 114 | + | |
| 115 | + graph->filters = filters; | |
| 116 | + graph->filters[graph->nb_filters++] = s; | |
| 117 | + | |
| 118 | +#if FF_API_FOO_COUNT | |
| 119 | + graph->filter_count = graph->nb_filters; | |
| 120 | +#endif | |
| 121 | + | |
| 122 | + return s; | |
| 123 | +} | |
| 124 | + | |
| 99 | 125 | /** |
| 100 | 126 | * Check for the validity of graph. |
| 101 | 127 | * |
| @@ -109,16 +109,11 @@ static int create_filter(AVFilterContext **filt_ctx, AVFilterGraph *ctx, int ind · 108 unmodified lines | ||
| 109 | 109 | return AVERROR(EINVAL); |
| 110 | 110 | } |
| 111 | 111 | |
| 112 | − ret = avfilter_open(filt_ctx, filt, inst_name); | |
| 112 | + *filt_ctx = avfilter_graph_alloc_filter(ctx, filt, inst_name); | |
| 113 | 113 | if (!*filt_ctx) { |
| 114 | 114 | av_log(log_ctx, AV_LOG_ERROR, |
| 115 | 115 | "Error creating filter '%s'\n", filt_name); |
| 116 | − return ret; | |
| 117 | − } | |
| 118 | − | |
| 119 | − if ((ret = avfilter_graph_add_filter(ctx, *filt_ctx)) < 0) { | |
| 120 | − avfilter_free(*filt_ctx); | |
| 121 | − return ret; | |
| 116 | + return AVERROR(ENOMEM); | |
| 122 | 117 | } |
| 123 | 118 | |
| 124 | 119 | if (!strcmp(filt_name, "scale") && args && !strstr(args, "flags") && |
| @@ -196,4 +196,14 @@ int ff_request_frame(AVFilterLink *link); · 195 unmodified lines | ||
| 196 | 196 | */ |
| 197 | 197 | int ff_filter_frame(AVFilterLink *link, AVFrame *frame); |
| 198 | 198 | |
| 199 | +/** | |
| 200 | + * Allocate a new filter context and return it. | |
| 201 | + * | |
| 202 | + * @param filter what filter to create an instance of | |
| 203 | + * @param inst_name name to give to the new filter context | |
| 204 | + * | |
| 205 | + * @return newly created filter context or NULL on failure | |
| 206 | + */ | |
| 207 | +AVFilterContext *ff_filter_alloc(const AVFilter *filter, const char *inst_name); | |
| 208 | + | |
| 199 | 209 | #endif /* AVFILTER_INTERNAL_H */ |
| @@ -58,5 +58,8 @@ · 57 unmodified lines | ||
| 58 | 58 | #ifndef FF_API_OLD_FILTER_OPTS |
| 59 | 59 | #define FF_API_OLD_FILTER_OPTS (LIBAVFILTER_VERSION_MAJOR < 4) |
| 60 | 60 | #endif |
| 61 | +#ifndef FF_API_AVFILTER_OPEN | |
| 62 | +#define FF_API_AVFILTER_OPEN (LIBAVFILTER_VERSION_MAJOR < 4) | |
| 63 | +#endif | |
| 61 | 64 | |
| 62 | 65 | #endif /* AVFILTER_VERSION_H */ |