[FFmpeg-devel] [PATCH] lavfi: add avfilter_get_class() and iteration callbacks

Michael Niedermayer michaelni at gmx.at
Sun Aug 12 14:22:22 CEST 2012


On Sun, Aug 12, 2012 at 12:10:50PM +0200, Stefano Sabatini wrote:
> On date Friday 2012-08-10 01:44:54 +0200, Michael Niedermayer encoded:
> > On Thu, Aug 09, 2012 at 10:58:21PM +0200, Stefano Sabatini wrote:
> [...]
> > > +static const AVClass *filter_child_class_next(const AVClass *prev)
> > > +{
> > > +    AVFilter **filter_ptr = NULL;
> > > +
> > 
> > > +    /* find the filter that corresponds to prev */
> > > +    while (prev && (filter_ptr = av_filter_next(filter_ptr)))
> > > +        if ((*filter_ptr)->priv_class == prev)
> > > +            break;
> > 
> > this is a bit fragile
> > filter_ptr starts at NULL and will then iterate over an array of
> > pointers but it will not become null again, thus if prev is not
> > found it will crash
> 
> Fixed the test and added an additional check in case prev!=NULL and no
> filter was found.
> 

> BTW note that I find this whole _child_class_next business rather
> ugly, it imposes that two distinct contexts cannot share the same
> class, requires O(N^2) time complexity for iteration, and I find the
> adopted terminology and documentation overly confusing.

yes ...


> 
> A simple iteration over the list of registered filters may be IMO much
> simpler and flexible, but I'm retaining the logic for consistency with
> how it is done for the other components.
> -- 
> FFmpeg = Foolish Foolish Mournful Pitiless Enhancing Guru

>  avfilter.c |   35 +++++++++++++++++++++++++++++++++++
>  avfilter.h |    6 ++++++
>  2 files changed, 41 insertions(+)
> 7dfb67b9e94d9337949d59787082a6f76622277e  0009-lavfi-add-avfilter_get_class-and-iteration-callbacks.patch
> From 2eefe9b0ab73f96e6aa2de50050ba20c4f8e2da9 Mon Sep 17 00:00:00 2001
> From: Stefano Sabatini <stefasab at gmail.com>
> Date: Thu, 9 Aug 2012 14:59:10 +0200
> Subject: [PATCH] lavfi: add avfilter_get_class() and iteration callbacks
> 
> Allow iteration over specific filter options.
> ---
>  libavfilter/avfilter.c |   35 +++++++++++++++++++++++++++++++++++
>  libavfilter/avfilter.h |    6 ++++++
>  2 files changed, 41 insertions(+), 0 deletions(-)
> 
> diff --git a/libavfilter/avfilter.c b/libavfilter/avfilter.c
> index c698d8a..9b28b90 100644
> --- a/libavfilter/avfilter.c
> +++ b/libavfilter/avfilter.c
> @@ -432,13 +432,48 @@ static const char *default_filter_name(void *filter_ctx)
>      return ctx->name ? ctx->name : ctx->filter->name;
>  }
>  
> +static void *filter_child_next(void *obj, void *prev)
> +{
> +    AVFilterContext *ctx = obj;
> +    if (!prev && ctx->filter && ctx->filter->priv_class && ctx->priv)
> +        return ctx->priv;

the ctx->priv check is redudnant

except that, patch LGTM

[...]
-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

Asymptotically faster algorithms should always be preferred if you have
asymptotical amounts of data
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: Digital signature
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20120812/0849a92f/attachment.asc>


More information about the ffmpeg-devel mailing list