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

Michael Niedermayer michaelni at gmx.at
Fri Aug 10 01:44:54 CEST 2012


On Thu, Aug 09, 2012 at 10:58:21PM +0200, Stefano Sabatini wrote:
> Allow iteration over specific filter options.
> ---
>  libavfilter/avfilter.c |   31 +++++++++++++++++++++++++++++++
>  libavfilter/avfilter.h |    6 ++++++
>  2 files changed, 37 insertions(+), 0 deletions(-)
> 
> diff --git a/libavfilter/avfilter.c b/libavfilter/avfilter.c
> index c698d8a..e5935cd 100644
> --- a/libavfilter/avfilter.c
> +++ b/libavfilter/avfilter.c
> @@ -432,13 +432,44 @@ 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;
> +    return NULL;
> +}
> +
> +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


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

Rewriting code that is poorly written but fully understood is good.
Rewriting code that one doesnt understand is a sign that one is less smart
then the original author, trying to rewrite it will not make it better.
-------------- 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/20120810/72a3afeb/attachment.asc>


More information about the ffmpeg-devel mailing list