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

Michael Niedermayer michaelni
Fri Jan 8 03:34:30 CET 2010


On Fri, Jan 08, 2010 at 12:41:20AM +0100, Stefano Sabatini wrote:
> On date Thursday 2010-01-07 00:14:54 +0100, Michael Niedermayer encoded:
> > 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
> 
> Updated.
> 
> Regards.
> -- 
> FFmpeg = Furious Fostering Meaningful Patchable Enigmatic Genius

>  vf_scale.c |   18 ++++++++++++++++--
>  1 file changed, 16 insertions(+), 2 deletions(-)
> 8c1113ccf355ef4ece527db4ab3c8b32578c7634  make-scale-filter-declare-managed-fmts.patch

ok

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

> ... defining _GNU_SOURCE...
For the love of all that is holy, and some that is not, don't do that.
-- Luca & Mans
-------------- 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/20100108/c6c8ba6d/attachment.pgp>



More information about the ffmpeg-devel mailing list