[FFmpeg-devel] [PATCH] New registration system for avfilter filters

Michael Niedermayer michaelni
Mon Nov 23 00:07:02 CET 2009


On Sun, Nov 22, 2009 at 08:47:47PM +0100, Stefano Sabatini wrote:
> Hi,
> 
> this may be applied to the other list of registered elements in
> libav*.
> 
> This system avoids a non-const field in struct AVFilter, thus allowing
> for the use of shareable memory for the AVFilter definitions.
> 
> I'm also attaching a patch for an av_filter_next() which uses it, and
> an application example.
> 
> Regards.
> -- 
> FFmpeg = Frightening and Funny Monstrous Pitiful ExchanGer

>  avfilter.c |   31 +++++++++++++++++--------------
>  avfilter.h |    4 +++-
>  2 files changed, 20 insertions(+), 15 deletions(-)
> f971a01b2d1e8e9d30b76b68e9bbc99d7495b028  change-avfilter-register.patch
> Index: ffmpeg/libavfilter/avfilter.c
> ===================================================================
> --- ffmpeg.orig/libavfilter/avfilter.c	2009-11-22 18:50:31.000000000 +0100
> +++ ffmpeg/libavfilter/avfilter.c	2009-11-22 20:22:49.000000000 +0100
> @@ -328,33 +328,36 @@
>      draw_slice(link, y, h);
>  }
>  
> -AVFilter *first_avfilter = NULL;
> +#define MAX_REGISTERED_AVFILTERS_NB 64
> +
> +AVFilter *registered_avfilters[MAX_REGISTERED_AVFILTERS_NB + 1];
>  
>  AVFilter *avfilter_get_by_name(const char *name)
>  {
> -    AVFilter *filter;
> -
> -    for (filter = first_avfilter; filter; filter = filter->next)
> -        if (!strcmp(filter->name, name))
> -            return filter;

> +    for (int i = 0; registered_avfilters[i] && i < MAX_REGISTERED_AVFILTERS_NB; i++)

i suspect that breaks gcc 2.95


> +        if (!strcmp(registered_avfilters[i]->name, name))
> +            return registered_avfilters[i];
>  
>      return NULL;
>  }
>  

> -void avfilter_register(AVFilter *filter)
> +int avfilter_register(AVFilter *filter)
>  {
> -    AVFilter **p;
> -    p = &first_avfilter;
> -    while (*p)
> -        p = &(*p)->next;
> +    int i;
> +
> +    for (i = 0; registered_avfilters[i] && i < MAX_REGISTERED_AVFILTERS_NB; i++)
> +        ;

please keep a registered_avfilters_idx variable somewhere instead of this
search


> +
> +    if (i == MAX_REGISTERED_AVFILTERS_NB)
> +        return -1;
>  
> -    *p = filter;
> -    filter->next = NULL;
> +    registered_avfilters[i] = filter;
> +    return 0;
>  }
>  

>  void avfilter_uninit(void)
>  {
> -    first_avfilter = NULL;
> +    memset(registered_avfilters, 0, sizeof(AVFilter *) * MAX_REGISTERED_AVFILTERS_NB);

sizeof(registered_avfilters)


>  }
>  
>  static int pad_count(const AVFilterPad *pads)
> Index: ffmpeg/libavfilter/avfilter.h
> ===================================================================
> --- ffmpeg.orig/libavfilter/avfilter.h	2009-11-22 18:57:25.000000000 +0100
> +++ ffmpeg/libavfilter/avfilter.h	2009-11-22 20:22:42.000000000 +0100
> @@ -581,8 +581,10 @@
>   * filter can still by instantiated with avfilter_open even if it is not
>   * registered.
>   * @param filter the filter to register
> + * @return 0 if the registration was succesfull, a negative value
> + * otherwise
>   */
> -void avfilter_register(AVFilter *filter);
> +int avfilter_register(AVFilter *filter);
>  
>  /**
>   * Gets a filter definition matching the given name.

>  avfilter.c |    5 +++++
>  avfilter.h |    8 ++++++++
>  2 files changed, 13 insertions(+)
> 0bc88e1fb02fcf55bffe0a9f582663f1b35bc1f3  implement-av-filter-next.patch

ok

[...]

-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

Incandescent light bulbs waste a lot of energy as heat so the EU forbids them.
Their replacement, compact fluorescent lamps, much more expensive, dont fit in
many old lamps, flicker, contain toxic mercury, produce a fraction of the light
that is claimed and in a unnatural spectrum rendering colors different than
in natural light. Ah and we now need to turn the heaters up more in winter to
compensate the lower wasted heat. Who wins? Not the environment, thats for sure
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20091123/403d972c/attachment.pgp>



More information about the ffmpeg-devel mailing list