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.
... | ... |
@@ -16,6 +16,7 @@ API changes, most recent first: |
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 = { |
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 |
404 | 404 |
ret->input_count = ret->nb_inputs; |
405 | 405 |
#endif |
406 | 406 |
|
407 |
- *filter_ctx = ret; |
|
408 |
- return 0; |
|
407 |
+ return ret; |
|
409 | 408 |
|
410 | 409 |
err: |
411 | 410 |
av_freep(&ret->inputs); |
... | ... |
@@ -416,9 +414,17 @@ err: |
416 | 416 |
ret->nb_outputs = 0; |
417 | 417 |
av_freep(&ret->priv); |
418 | 418 |
av_free(ret); |
419 |
- return AVERROR(ENOMEM); |
|
419 |
+ return NULL; |
|
420 | 420 |
} |
421 | 421 |
|
422 |
+#if FF_API_AVFILTER_OPEN |
|
423 |
+int avfilter_open(AVFilterContext **filter_ctx, AVFilter *filter, const char *inst_name) |
|
424 |
+{ |
|
425 |
+ *filter_ctx = ff_filter_alloc(filter, inst_name); |
|
426 |
+ return *filter_ctx ? 0 : AVERROR(ENOMEM); |
|
427 |
+} |
|
428 |
+#endif |
|
429 |
+ |
|
422 | 430 |
void avfilter_free(AVFilterContext *filter) |
423 | 431 |
{ |
424 | 432 |
int i; |
... | ... |
@@ -602,8 +602,8 @@ void avfilter_uninit(void); |
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); |
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); |
636 | 636 |
* @param filter the filter to create an instance of |
637 | 637 |
* @param inst_name Name to give to the new instance. Can be NULL for none. |
638 | 638 |
* @return >= 0 in case of success, a negative error code otherwise |
639 |
+ * @deprecated use avfilter_graph_alloc_filter() instead |
|
639 | 640 |
*/ |
641 |
+attribute_deprecated |
|
640 | 642 |
int avfilter_open(AVFilterContext **filter_ctx, AVFilter *filter, const char *inst_name); |
643 |
+#endif |
|
641 | 644 |
|
642 | 645 |
/** |
643 | 646 |
* Initialize a filter. |
... | ... |
@@ -721,6 +725,24 @@ typedef struct AVFilterGraph { |
721 | 721 |
AVFilterGraph *avfilter_graph_alloc(void); |
722 | 722 |
|
723 | 723 |
/** |
724 |
+ * Create a new filter instance in a filter graph. |
|
725 |
+ * |
|
726 |
+ * @param graph graph in which the new filter will be used |
|
727 |
+ * @param filter the filter to create an instance of |
|
728 |
+ * @param name Name to give to the new instance (will be copied to |
|
729 |
+ * AVFilterContext.name). This may be used by the caller to identify |
|
730 |
+ * different filters, libavfilter itself assigns no semantics to |
|
731 |
+ * this parameter. May be NULL. |
|
732 |
+ * |
|
733 |
+ * @return the context of the newly created filter instance (note that it is |
|
734 |
+ * also retrievable directly through AVFilterGraph.filters or with |
|
735 |
+ * avfilter_graph_get_filter()) on success or NULL or failure. |
|
736 |
+ */ |
|
737 |
+AVFilterContext *avfilter_graph_alloc_filter(AVFilterGraph *graph, |
|
738 |
+ const AVFilter *filter, |
|
739 |
+ const char *name); |
|
740 |
+ |
|
741 |
+/** |
|
724 | 742 |
* Get a filter instance with name name from graph. |
725 | 743 |
* |
726 | 744 |
* @return the pointer to the found filter instance or NULL if it |
... | ... |
@@ -81,12 +81,12 @@ int avfilter_graph_create_filter(AVFilterContext **filt_ctx, AVFilter *filt, |
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: |
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 |
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); |
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 */ |