[FFmpeg-devel] [PATCH] Make the scale filter only declare the supported formats

Michael Niedermayer michaelni
Thu Jan 7 00:14:54 CET 2010


On Wed, Jan 06, 2010 at 11:33:38PM +0100, Stefano Sabatini wrote:
> On date Wednesday 2010-01-06 21:56:30 +0100, Stefano Sabatini encoded:
> > Index: libavfilter-soc/ffmpeg/libavfilter/vf_scale.c
> > ===================================================================
> > --- libavfilter-soc.orig/ffmpeg/libavfilter/vf_scale.c	2010-01-06 21:53:47.000000000 +0100
> > +++ libavfilter-soc/ffmpeg/libavfilter/vf_scale.c	2010-01-06 21:55:39.000000000 +0100
> > @@ -68,15 +68,24 @@
> >  
> >  static int query_formats(AVFilterContext *ctx)
> >  {
> > -    AVFilterFormats *formats;
> > +    AVFilterFormats *in_formats  = NULL;
> > +    AVFilterFormats *out_formats = NULL;
> > +    enum PixelFormat pix_fmt;
> > +    int ret;
> >  
> >      if (ctx->inputs[0]) {
> > -        formats = avfilter_all_colorspaces();
> > -        avfilter_formats_ref(formats, &ctx->inputs[0]->out_formats);
> > +        for (pix_fmt = 0; pix_fmt < PIX_FMT_NB; pix_fmt++)
> > +            if (sws_isSupportedInput(pix_fmt))
> > +                if ((ret = avfilter_add_colorspace(&in_formats, pix_fmt)) < 0)
> > +                    return ret;
> > +        avfilter_formats_ref(in_formats, &ctx->inputs[0]->out_formats);
> >      }
> >      if (ctx->outputs[0]) {
> > -        formats = avfilter_all_colorspaces();
> > -        avfilter_formats_ref(formats, &ctx->outputs[0]->in_formats);
> > +        for (pix_fmt = 0; pix_fmt < PIX_FMT_NB; pix_fmt++)
> > +            if (sws_isSupportedOutput(pix_fmt))
> > +                if ((ret = avfilter_add_colorspace(&out_formats, pix_fmt)) < 0)
> > +                    return ret;
> > +        avfilter_formats_ref(out_formats, &ctx->outputs[0]->in_formats);
> >      }
> >  
> >      return 0;
> 
> Fixed memleak and simplified.
> -- 
> FFmpeg = Freak and Fundamental Minimalistic Purposeless Ecumenical Governor

>  vf_scale.c |   19 +++++++++++++++++--
>  1 file changed, 17 insertions(+), 2 deletions(-)
> 1a1195338d7422211ad54b5c5c8363077c26ca6b  make-scale-filter-declare-managed-fmts.patch
> Index: libavfilter-soc/ffmpeg/libavfilter/vf_scale.c
> ===================================================================
> --- libavfilter-soc.orig/ffmpeg/libavfilter/vf_scale.c	2010-01-06 21:53:47.000000000 +0100
> +++ libavfilter-soc/ffmpeg/libavfilter/vf_scale.c	2010-01-06 23:29:11.000000000 +0100
> @@ -69,17 +69,32 @@
>  static int query_formats(AVFilterContext *ctx)
>  {
>      AVFilterFormats *formats;
> +    enum PixelFormat pix_fmt;
> +    int ret;
>  
>      if (ctx->inputs[0]) {
> -        formats = avfilter_all_colorspaces();
> +        formats = NULL;
> +        for (pix_fmt = 0; pix_fmt < PIX_FMT_NB; pix_fmt++)
> +            if (   sws_isSupportedInput(pix_fmt)
> +                && (ret = avfilter_add_colorspace(&formats, pix_fmt)) < 0)
> +                goto fail;
>          avfilter_formats_ref(formats, &ctx->inputs[0]->out_formats);
>      }
>      if (ctx->outputs[0]) {
> -        formats = avfilter_all_colorspaces();
> +        formats = NULL;
> +        for (pix_fmt = 0; pix_fmt < PIX_FMT_NB; pix_fmt++)
> +            if (   sws_isSupportedOutput(pix_fmt)
> +                && (ret = avfilter_add_colorspace(&formats, pix_fmt)) < 0)
> +                goto fail;
>          avfilter_formats_ref(formats, &ctx->outputs[0]->in_formats);
>      }
>  
>      return 0;
> +
> +fail:
> +    if (formats)
> +        avfilter_formats_unref(&formats);

do we need the if() ?
in general functions not needing explicit NULL checks are nicer IMHO

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

In a rich man's house there is no place to spit but his face.
-- Diogenes of Sinope
-------------- 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/20100107/f3c7a2c4/attachment.pgp>



More information about the ffmpeg-devel mailing list