History

lavfi: replace avfilter_open() with avfilter_graph_alloc_filter().

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.

Anton Khirnov committed 13 years ago

Commit bc1a9851 parent 38f0c077 files · +83 −20Browse files

Unified · Split

7 files
  1. doc/APIchanges +1 −0
  2. libavfilter/avfilter.c +13 −7
  3. libavfilter/avfilter.h +24 −2
  4. libavfilter/avfiltergraph.c +30 −4
  5. libavfilter/graphparser.c +2 −7
  6. libavfilter/internal.h +10 −0
  7. libavfilter/version.h +3 −0
doc/APIchanges+1−0
@@ -16,6 +16,7 @@ API changes, most recent first: · 15 unmodified lines
1616 2013-xx-xx - lavfi 3.8.0
1717 Move all content from avfiltergraph.h to avfilter.h. Deprecate
1818 avfilterhraph.h, user applications should include just avfilter.h
19+ Add avfilter_graph_alloc_filter(), deprecate avfilter_open().
1920
2021 2013-xx-xx - lavfi 3.7.0 - avfilter.h
2122 Add AVFilter.priv_class for exporting filter options through the AVOptions API
libavfilter/avfilter.c+13−7
@@ -352,17 +352,16 @@ static const AVClass avfilter_class = { · 351 unmodified lines
352352 .child_class_next = filter_child_class_next,
353353 };
354354
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)
356356 {
357357 AVFilterContext *ret;
358− *filter_ctx = NULL;
359358
360359 if (!filter)
361− return AVERROR(EINVAL);
360+ return NULL;
362361
363362 ret = av_mallocz(sizeof(AVFilterContext));
364363 if (!ret)
365− return AVERROR(ENOMEM);
364+ return NULL;
366365
367366 ret->av_class = &avfilter_class;
368367 ret->filter = filter;
@@ -404,8 +403,7 @@ int avfilter_open(AVFilterContext **filter_ctx, AVFilter *filter, const char *in · 35 unmodified lines
404403 ret->input_count = ret->nb_inputs;
405404 #endif
406405
407− *filter_ctx = ret;
408− return 0;
406+ return ret;
409407
410408 err:
411409 av_freep(&ret->inputs);
@@ -416,9 +414,17 @@ err: · 4 unmodified lines
416414 ret->nb_outputs = 0;
417415 av_freep(&ret->priv);
418416 av_free(ret);
419− return AVERROR(ENOMEM);
417+ return NULL;
420418 }
421419
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+
422428 void avfilter_free(AVFilterContext *filter)
423429 {
424430 int i;
libavfilter/avfilter.h+24−2
@@ -602,8 +602,8 @@ void avfilter_uninit(void); · 601 unmodified lines
602602 /**
603603 * Register a filter. This is only needed if you plan to use
604604 * 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.
607607 *
608608 * @param filter the filter to register
609609 * @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
628628 */
629629 AVFilter **av_filter_next(AVFilter **filter);
630630
631+#if FF_API_AVFILTER_OPEN
631632 /**
632633 * Create a filter instance.
633634 *
@@ -636,8 +637,11 @@ AVFilter **av_filter_next(AVFilter **filter); · 2 unmodified lines
636637 * @param filter the filter to create an instance of
637638 * @param inst_name Name to give to the new instance. Can be NULL for none.
638639 * @return >= 0 in case of success, a negative error code otherwise
640+ * @deprecated use avfilter_graph_alloc_filter() instead
639641 */
642+attribute_deprecated
640643 int avfilter_open(AVFilterContext **filter_ctx, AVFilter *filter, const char *inst_name);
644+#endif
641645
642646 /**
643647 * Initialize a filter.
@@ -720,6 +724,24 @@ typedef struct AVFilterGraph { · 76 unmodified lines
720724 */
721725 AVFilterGraph *avfilter_graph_alloc(void);
722726
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+
723745 /**
724746 * Get a filter instance with name name from graph.
725747 *
libavfilter/avfiltergraph.c+30−4
@@ -81,12 +81,12 @@ int avfilter_graph_create_filter(AVFilterContext **filt_ctx, AVFilter *filt, · 80 unmodified lines
8181 {
8282 int ret;
8383
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);
8687 if ((ret = avfilter_init_filter(*filt_ctx, args, opaque)) < 0)
8788 goto fail;
88− if ((ret = avfilter_graph_add_filter(graph_ctx, *filt_ctx)) < 0)
89− goto fail;
89+
9090 return 0;
9191
9292 fail:
@@ -96,6 +96,32 @@ fail: · 3 unmodified lines
9696 return ret;
9797 }
9898
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+
99125 /**
100126 * Check for the validity of graph.
101127 *
libavfilter/graphparser.c+2−7
@@ -109,16 +109,11 @@ static int create_filter(AVFilterContext **filt_ctx, AVFilterGraph *ctx, int ind · 108 unmodified lines
109109 return AVERROR(EINVAL);
110110 }
111111
112− ret = avfilter_open(filt_ctx, filt, inst_name);
112+ *filt_ctx = avfilter_graph_alloc_filter(ctx, filt, inst_name);
113113 if (!*filt_ctx) {
114114 av_log(log_ctx, AV_LOG_ERROR,
115115 "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);
122117 }
123118
124119 if (!strcmp(filt_name, "scale") && args && !strstr(args, "flags") &&
libavfilter/internal.h+10−0
@@ -196,4 +196,14 @@ int ff_request_frame(AVFilterLink *link); · 195 unmodified lines
196196 */
197197 int ff_filter_frame(AVFilterLink *link, AVFrame *frame);
198198
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+
199209 #endif /* AVFILTER_INTERNAL_H */
libavfilter/version.h+3−0
@@ -58,5 +58,8 @@ · 57 unmodified lines
5858 #ifndef FF_API_OLD_FILTER_OPTS
5959 #define FF_API_OLD_FILTER_OPTS (LIBAVFILTER_VERSION_MAJOR < 4)
6060 #endif
61+#ifndef FF_API_AVFILTER_OPEN
62+#define FF_API_AVFILTER_OPEN (LIBAVFILTER_VERSION_MAJOR < 4)
63+#endif
6164
6265 #endif /* AVFILTER_VERSION_H */

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