History

lavfi: change the filter registering system to match the other libraries

Removes an arbitrary hardcoded limit on the number of filters.

Anton Khirnov committed 13 years ago

Commit fa2a34c1 parent 7e8fe4b7 files · +48 −29Browse files

Unified · Split

7 files
  1. avconv.c +0 −1
  2. avplay.c +0 −3
  3. cmdutils.c +3 −3
  4. doc/APIchanges +2 −0
  5. libavfilter/avfilter.c +24 −22
  6. libavfilter/avfilter.h +16 −0
  7. libavfilter/version.h +3 −0
avconv.c+0−1
@@ -211,7 +211,6 @@ static void exit_program(void) · 210 unmodified lines
211211
212212 uninit_opts();
213213
214− avfilter_uninit();
215214 avformat_network_deinit();
216215
217216 if (received_sigterm) {
avplay.c+0−3
@@ -1246,9 +1246,6 @@ static void do_exit(void) · 1245 unmodified lines
12461246 cur_stream = NULL;
12471247 }
12481248 uninit_opts();
1249−#if CONFIG_AVFILTER
1250− avfilter_uninit();
1251−#endif
12521249 avformat_network_deinit();
12531250 if (show_status)
12541251 printf("\n");
cmdutils.c+3−3
@@ -1130,12 +1130,12 @@ int show_protocols(void *optctx, const char *opt, const char *arg) · 1129 unmodified lines
11301130
11311131 int show_filters(void *optctx, const char *opt, const char *arg)
11321132 {
1133− AVFilter av_unused(**filter) = NULL;
1133+ const AVFilter av_unused(*filter) = NULL;
11341134
11351135 printf("Filters:\n");
11361136 #if CONFIG_AVFILTER
1137− while ((filter = av_filter_next(filter)) && *filter)
1138− printf("%-16s %s\n", (*filter)->name, (*filter)->description);
1137+ while ((filter = avfilter_next(filter)))
1138+ printf("%-16s %s\n", filter->name, filter->description);
11391139 #endif
11401140 return 0;
11411141 }
doc/APIchanges+2−0
@@ -24,6 +24,8 @@ API changes, most recent first: · 23 unmodified lines
2424 Add avfilter_init_dict().
2525 Add AVFilter.flags field and AVFILTER_FLAG_DYNAMIC_{INPUTS,OUTPUTS} flags.
2626 Add avfilter_pad_count() for counting filter inputs/outputs.
27+ Add avfilter_next(), deprecate av_filter_next().
28+ Deprecate avfilter_uninit().
2729
2830 2013-xx-xx - lavfi 3.7.0 - avfilter.h
2931 Add AVFilter.priv_class for exporting filter options through the AVOptions API
libavfilter/avfilter.c+24−22
@@ -267,42 +267,44 @@ int ff_poll_frame(AVFilterLink *link) · 266 unmodified lines
267267 return min;
268268 }
269269
270−#define MAX_REGISTERED_AVFILTERS_NB 64
271−
272−static AVFilter *registered_avfilters[MAX_REGISTERED_AVFILTERS_NB + 1];
273−
274−static int next_registered_avfilter_idx = 0;
270+static AVFilter *first_filter;
275271
276272 AVFilter *avfilter_get_by_name(const char *name)
277273 {
278− int i;
274+ AVFilter *f = NULL;
279275
280− for (i = 0; registered_avfilters[i]; i++)
281− if (!strcmp(registered_avfilters[i]->name, name))
282− return registered_avfilters[i];
276+ while ((f = avfilter_next(f)))
277+ if (!strcmp(f->name, name))
278+ return f;
283279
284280 return NULL;
285281 }
286282
287283 int avfilter_register(AVFilter *filter)
288284 {
289− if (next_registered_avfilter_idx == MAX_REGISTERED_AVFILTERS_NB)
290− return -1;
291−
292− registered_avfilters[next_registered_avfilter_idx++] = filter;
285+ AVFilter **f = &first_filter;
286+ while (*f)
287+ f = &(*f)->next;
288+ *f = filter;
289+ filter->next = NULL;
293290 return 0;
294291 }
295292
293+const AVFilter *avfilter_next(const AVFilter *prev)
294+{
295+ return prev ? prev->next : first_filter;
296+}
297+
298+#if FF_API_OLD_FILTER_REGISTER
296299 AVFilter **av_filter_next(AVFilter **filter)
297300 {
298− return filter ? ++filter : &registered_avfilters[0];
301+ return filter ? &(*filter)->next : &first_filter;
299302 }
300303
301304 void avfilter_uninit(void)
302305 {
303− memset(registered_avfilters, 0, sizeof(registered_avfilters));
304− next_registered_avfilter_idx = 0;
305306 }
307+#endif
306308
307309 int avfilter_pad_count(const AVFilterPad *pads)
308310 {
@@ -331,15 +333,15 @@ static void *filter_child_next(void *obj, void *prev) · 22 unmodified lines
331333
332334 static const AVClass *filter_child_class_next(const AVClass *prev)
333335 {
334− AVFilter **f = NULL;
336+ AVFilter *f = NULL;
335337
336− while (prev && *(f = av_filter_next(f)))
337− if ((*f)->priv_class == prev)
338+ while (prev && (f = avfilter_next(f)))
339+ if (f->priv_class == prev)
338340 break;
339341
340− while (*(f = av_filter_next(f)))
341− if ((*f)->priv_class)
342− return (*f)->priv_class;
342+ while ((f = avfilter_next(f)))
343+ if (f->priv_class)
344+ return f->priv_class;
343345
344346 return NULL;
345347 }
libavfilter/avfilter.h+16−0
@@ -457,6 +457,8 @@ typedef struct AVFilter { · 456 unmodified lines
457457 int (*query_formats)(AVFilterContext *);
458458
459459 int priv_size; ///< size of private data to allocate for the filter
460+
461+ struct AVFilter *next;
460462 } AVFilter;
461463
462464 /** An instance of a filter */
@@ -622,8 +624,11 @@ AVFilterBufferRef *avfilter_get_audio_buffer_ref_from_arrays(uint8_t **data, · 159 unmodified lines
622624 /** Initialize the filter system. Register all builtin filters. */
623625 void avfilter_register_all(void);
624626
627+#if FF_API_OLD_FILTER_REGISTER
625628 /** Uninitialize the filter system. Unregister all filters. */
629+attribute_deprecated
626630 void avfilter_uninit(void);
631+#endif
627632
628633 /**
629634 * Register a filter. This is only needed if you plan to use
@@ -646,13 +651,24 @@ int avfilter_register(AVFilter *filter); · 16 unmodified lines
646651 */
647652 AVFilter *avfilter_get_by_name(const char *name);
648653
654+/**
655+ * Iterate over all registered filters.
656+ * @return If prev is non-NULL, next registered filter after prev or NULL if
657+ * prev is the last filter. If prev is NULL, return the first registered filter.
658+ */
659+const AVFilter *avfilter_next(const AVFilter *prev);
660+
661+#if FF_API_OLD_FILTER_REGISTER
649662 /**
650663 * If filter is NULL, returns a pointer to the first registered filter pointer,
651664 * if filter is non-NULL, returns the next pointer after filter.
652665 * If the returned pointer points to NULL, the last registered filter
653666 * was already reached.
667+ * @deprecated use avfilter_next()
654668 */
669+attribute_deprecated
655670 AVFilter **av_filter_next(AVFilter **filter);
671+#endif
656672
657673 #if FF_API_AVFILTER_OPEN
658674 /**
libavfilter/version.h+3−0
@@ -64,5 +64,8 @@ · 63 unmodified lines
6464 #ifndef FF_API_AVFILTER_INIT_FILTER
6565 #define FF_API_AVFILTER_INIT_FILTER (LIBAVFILTER_VERSION_MAJOR < 4)
6666 #endif
67+#ifndef FF_API_OLD_FILTER_REGISTER
68+#define FF_API_OLD_FILTER_REGISTER (LIBAVFILTER_VERSION_MAJOR < 4)
69+#endif
6770
6871 #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