Revision 6d8c67a7 libavfilter/avfilter.c

View differences:

libavfilter/avfilter.c
27 27
#include "avfilter.h"
28 28
#include "allfilters.h"
29 29

  
30
/** list of registered filters, sorted by name */
31
static int filter_count = 0;
32
static AVFilter **filters = NULL;
30
/** list of registered filters */
31
struct FilterList
32
{
33
    AVFilter *filter;
34
    struct FilterList *next;
35
} *filters = NULL;
33 36

  
34 37
/** helper macros to get the in/out pad on the dst/src filter */
35 38
#define link_dpad(link)     link->dst-> input_pads[link->dstpad]
......
239 242
    link_dpad(link).draw_slice(link, y, h);
240 243
}
241 244

  
242
static int filter_cmp(const void *aa, const void *bb)
243
{
244
    const AVFilter *a = *(const AVFilter **)aa, *b = *(const AVFilter **)bb;
245
    return strcmp(a->name, b->name);
246
}
247

  
248 245
AVFilter *avfilter_get_by_name(char *name)
249 246
{
250
    AVFilter key = { .name = name, };
251
    AVFilter *key2 = &key;
252
    AVFilter **ret;
247
    struct FilterList *filt;
248

  
249
    for(filt = filters; filt; filt = filt->next)
250
        if(!strcmp(filt->filter->name, name))
251
            return filt->filter;
253 252

  
254
    ret = bsearch(&key2, filters, filter_count, sizeof(AVFilter **), filter_cmp);
255
    if(ret)
256
        return *ret;
257 253
    return NULL;
258 254
}
259 255

  
260 256
/* FIXME: insert in order, rather than insert at end + resort */
261 257
void avfilter_register(AVFilter *filter)
262 258
{
263
    filters = av_realloc(filters, sizeof(AVFilter*) * (filter_count+1));
264
    filters[filter_count] = filter;
265
    qsort(filters, ++filter_count, sizeof(AVFilter **), filter_cmp);
259
    struct FilterList *newfilt = av_malloc(sizeof(struct FilterList));
260

  
261
    newfilt->filter = filter;
262
    newfilt->next   = filters;
263
    filters         = newfilt;
266 264
}
267 265

  
268 266
void avfilter_init(void)
......
283 281

  
284 282
void avfilter_uninit(void)
285 283
{
286
    av_freep(&filters);
287
    filter_count = 0;
284
    struct FilterList *tmp;
285

  
286
    for(; filters; filters = tmp) {
287
        tmp = filters->next;
288
        av_free(filters);
289
    }
288 290
}
289 291

  
290 292
static int pad_count(const AVFilterPad *pads)

Also available in: Unified diff