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
162013-xx-xx - lavfi 3.8.0162013-xx-xx - lavfi 3.8.0
17 Move all content from avfiltergraph.h to avfilter.h. Deprecate17 Move all content from avfiltergraph.h to avfilter.h. Deprecate
18 avfilterhraph.h, user applications should include just avfilter.h18 avfilterhraph.h, user applications should include just avfilter.h
19 Add avfilter_graph_alloc_filter(), deprecate avfilter_open().
19 20
202013-xx-xx - lavfi 3.7.0 - avfilter.h212013-xx-xx - lavfi 3.7.0 - avfilter.h
21 Add AVFilter.priv_class for exporting filter options through the AVOptions API22 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
352 .child_class_next = filter_child_class_next,352 .child_class_next = filter_child_class_next,
353};353};
354 354
355int avfilter_open(AVFilterContext **filter_ctx, AVFilter *filter, const char *inst_name)355AVFilterContext *ff_filter_alloc(const AVFilter *filter, const char *inst_name)
356{356{
357 AVFilterContext *ret;357 AVFilterContext *ret;
358 *filter_ctx = NULL;
359 358
360 if (!filter)359 if (!filter)
361 return AVERROR(EINVAL);360 return NULL;
362 361
363 ret = av_mallocz(sizeof(AVFilterContext));362 ret = av_mallocz(sizeof(AVFilterContext));
364 if (!ret)363 if (!ret)
365 return AVERROR(ENOMEM);364 return NULL;
366 365
367 ret->av_class = &avfilter_class;366 ret->av_class = &avfilter_class;
368 ret->filter = filter;367 ret->filter = filter;
@@ -404,8 +403,7 @@ int avfilter_open(AVFilterContext **filter_ctx, AVFilter *filter, const char *in · 35 unmodified lines
404 ret->input_count = ret->nb_inputs;403 ret->input_count = ret->nb_inputs;
405#endif404#endif
406 405
407 *filter_ctx = ret;406 return ret;
408 return 0;
409 407
410err:408err:
411 av_freep(&ret->inputs);409 av_freep(&ret->inputs);
@@ -416,9 +414,17 @@ err: · 4 unmodified lines
416 ret->nb_outputs = 0;414 ret->nb_outputs = 0;
417 av_freep(&ret->priv);415 av_freep(&ret->priv);
418 av_free(ret);416 av_free(ret);
419 return AVERROR(ENOMEM);417 return NULL;
420}418}
421 419
420#if FF_API_AVFILTER_OPEN
421int 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
422void avfilter_free(AVFilterContext *filter)428void avfilter_free(AVFilterContext *filter)
423{429{
424 int i;430 int i;
libavfilter/avfilter.h+24−2
@@ -602,8 +602,8 @@ void avfilter_uninit(void); · 601 unmodified lines
602/**602/**
603 * Register a filter. This is only needed if you plan to use603 * Register a filter. This is only needed if you plan to use
604 * avfilter_get_by_name later to lookup the AVFilter structure by name. A604 * 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 not605 * filter can still by instantiated with avfilter_graph_alloc_filter even if it
606 * registered.606 * is not registered.
607 *607 *
608 * @param filter the filter to register608 * @param filter the filter to register
609 * @return 0 if the registration was succesfull, a negative value609 * @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 */
629AVFilter **av_filter_next(AVFilter **filter);629AVFilter **av_filter_next(AVFilter **filter);
630 630
631#if FF_API_AVFILTER_OPEN
631/**632/**
632 * Create a filter instance.633 * Create a filter instance.
633 *634 *
@@ -636,8 +637,11 @@ AVFilter **av_filter_next(AVFilter **filter); · 2 unmodified lines
636 * @param filter the filter to create an instance of637 * @param filter the filter to create an instance of
637 * @param inst_name Name to give to the new instance. Can be NULL for none.638 * @param inst_name Name to give to the new instance. Can be NULL for none.
638 * @return >= 0 in case of success, a negative error code otherwise639 * @return >= 0 in case of success, a negative error code otherwise
640 * @deprecated use avfilter_graph_alloc_filter() instead
639 */641 */
642attribute_deprecated
640int avfilter_open(AVFilterContext **filter_ctx, AVFilter *filter, const char *inst_name);643int avfilter_open(AVFilterContext **filter_ctx, AVFilter *filter, const char *inst_name);
644#endif
641 645
642/**646/**
643 * Initialize a filter.647 * Initialize a filter.
@@ -720,6 +724,24 @@ typedef struct AVFilterGraph { · 76 unmodified lines
720 */724 */
721AVFilterGraph *avfilter_graph_alloc(void);725AVFilterGraph *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 */
741AVFilterContext *avfilter_graph_alloc_filter(AVFilterGraph *graph,
742 const AVFilter *filter,
743 const char *name);
744
723/**745/**
724 * Get a filter instance with name name from graph.746 * Get a filter instance with name name from graph.
725 *747 *
libavfilter/avfiltergraph.c+30−4
@@ -81,12 +81,12 @@ int avfilter_graph_create_filter(AVFilterContext **filt_ctx, AVFilter *filt, · 80 unmodified lines
81{81{
82 int ret;82 int ret;
83 83
84 if ((ret = avfilter_open(filt_ctx, filt, name)) < 0)84 *filt_ctx = avfilter_graph_alloc_filter(graph_ctx, filt, name);
85 goto fail;85 if (!*filt_ctx)
86 return AVERROR(ENOMEM);
86 if ((ret = avfilter_init_filter(*filt_ctx, args, opaque)) < 0)87 if ((ret = avfilter_init_filter(*filt_ctx, args, opaque)) < 0)
87 goto fail;88 goto fail;
88 if ((ret = avfilter_graph_add_filter(graph_ctx, *filt_ctx)) < 0)89
89 goto fail;
90 return 0;90 return 0;
91 91
92fail:92fail:
@@ -96,6 +96,32 @@ fail: · 3 unmodified lines
96 return ret;96 return ret;
97}97}
98 98
99AVFilterContext *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 * Check for the validity of graph.126 * Check for the validity of graph.
101 *127 *
libavfilter/graphparser.c+2−7
@@ -109,16 +109,11 @@ static int create_filter(AVFilterContext **filt_ctx, AVFilterGraph *ctx, int ind · 108 unmodified lines
109 return AVERROR(EINVAL);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 if (!*filt_ctx) {113 if (!*filt_ctx) {
114 av_log(log_ctx, AV_LOG_ERROR,114 av_log(log_ctx, AV_LOG_ERROR,
115 "Error creating filter '%s'\n", filt_name);115 "Error creating filter '%s'\n", filt_name);
116 return ret;116 return AVERROR(ENOMEM);
117 }
118
119 if ((ret = avfilter_graph_add_filter(ctx, *filt_ctx)) < 0) {
120 avfilter_free(*filt_ctx);
121 return ret;
122 }117 }
123 118
124 if (!strcmp(filt_name, "scale") && args && !strstr(args, "flags") &&119 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
196 */196 */
197int ff_filter_frame(AVFilterLink *link, AVFrame *frame);197int 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 */
207AVFilterContext *ff_filter_alloc(const AVFilter *filter, const char *inst_name);
208
199#endif /* AVFILTER_INTERNAL_H */209#endif /* AVFILTER_INTERNAL_H */
libavfilter/version.h+3−0
@@ -58,5 +58,8 @@ · 57 unmodified lines
58#ifndef FF_API_OLD_FILTER_OPTS58#ifndef FF_API_OLD_FILTER_OPTS
59#define FF_API_OLD_FILTER_OPTS (LIBAVFILTER_VERSION_MAJOR < 4)59#define FF_API_OLD_FILTER_OPTS (LIBAVFILTER_VERSION_MAJOR < 4)
60#endif60#endif
61#ifndef FF_API_AVFILTER_OPEN
62#define FF_API_AVFILTER_OPEN (LIBAVFILTER_VERSION_MAJOR < 4)
63#endif
61 64
62#endif /* AVFILTER_VERSION_H */65#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