[FFmpeg-devel] [PATCH] Fix opt_default()

Michael Niedermayer michaelni
Tue Dec 16 02:34:51 CET 2008


On Tue, Dec 16, 2008 at 01:49:50AM +0100, Stefano Sabatini wrote:
> On date Tuesday 2008-12-16 00:31:02 +0100, Stefano Sabatini encoded:
> [...]
> > > > Index: ffmpeg/libavcodec/opt.h
> > > > ===================================================================
> > > > --- ffmpeg.orig/libavcodec/opt.h	2008-12-14 23:17:27.000000000 +0100
> > > > +++ ffmpeg/libavcodec/opt.h	2008-12-14 23:21:18.000000000 +0100
> > > 
> > > > @@ -105,6 +105,14 @@
> > > >  attribute_deprecated const AVOption *av_set_string(void *obj, const char *name, const char *val);
> > > >  
> > > >  /**
> > > > + * @return a pointer to the AVOption corresponding to the field set or
> > > > + * NULL if no matching AVOption exists, or if the value \p val is not
> > > > + * valid
> > > > + * @see av_set_string3()
> > > > + */
> > > > +const AVOption *av_set_string2(void *obj, const char *name, const char *val, int alloc);
> > > > +
> > > 
> > > this should be under #ifdefs to remove it with the next major bump
> > 
> > So I think it should be deprecated and ifdeffed at the same time. See
> > the attached patches (unfortunately there is still a warning which I
> > think we cannot avoid).
> 
> No, that wasn't true.
> 
> > > > +/**
> > > >   * Sets the field of obj with the given name to value.
> > > >   *
> > > >   * @param[in] obj A struct whose first element is a pointer to an
> > > > @@ -120,14 +128,15 @@
> > > >   * scalars or named flags separated by '+' or '-'. Prefixing a flag
> > > >   * with '+' causes it to be set without affecting the other flags;
> > > >   * similarly, '-' unsets a flag.
> > > > - * @return a pointer to the AVOption corresponding to the field set or
> > > > - * NULL if no matching AVOption exists, or if the value \p val is not
> > > > - * valid
> > > 
> > > > + * @param[in,out] o_out if non-NULL put here a pointer to the AVOption
> > > > + * found
> > > 
> > > id say this is just [out]
> > 
> > Fixed.
> 
> [...]
> > Index: ffmpeg/libavcodec/opt.c
> > ===================================================================
> > --- ffmpeg.orig/libavcodec/opt.c	2008-12-15 23:38:55.000000000 +0100
> > +++ ffmpeg/libavcodec/opt.c	2008-12-15 23:46:35.000000000 +0100
> > @@ -107,10 +107,16 @@
> >      return -1;
> >  }
> >  
> > -const AVOption *av_set_string2(void *obj, const char *name, const char *val, int alloc){
> > +int av_set_string3(void *obj, const char *name, const char *val, int alloc, const AVOption **o_out){
> > +    int ret;
> >      const AVOption *o= av_find_opt(obj, name, NULL, 0, 0);
> > -    if(!o || !val || o->offset<=0)
> > -        return NULL;
> > +    if (o_out)
> > +        *o_out = o;
> > +    if(!o)
> > +        return AVERROR(ENOENT);
> > +    if(!val || o->offset<=0)
> > +        return AVERROR(EINVAL);
> > +
> >      if(o->type == FF_OPT_TYPE_BINARY){
> >          uint8_t **dst = (uint8_t **)(((uint8_t*)obj) + o->offset);
> >          int *lendst = (int *)(dst + 1);
> > @@ -118,7 +124,7 @@
> >          int len = strlen(val);
> >          av_freep(dst);
> >          *lendst = 0;
> > -        if (len & 1) return NULL;
> > +        if (len & 1) return AVERROR(EINVAL);
> >          len /= 2;
> >          ptr = bin = av_malloc(len);
> >          while (*val) {
> > @@ -126,13 +132,13 @@
> >              int b = hexchar2int(*val++);
> >              if (a < 0 || b < 0) {
> >                  av_free(bin);
> > -                return NULL;
> > +                return AVERROR(EINVAL);
> >              }
> >              *ptr++ = (a << 4) | b;
> >          }
> >          *dst = bin;
> >          *lendst = len;
> > -        return o;
> > +        return 0;
> >      }
> >      if(o->type != FF_OPT_TYPE_STRING){
> >          int notfirst=0;
> > @@ -163,7 +169,7 @@
> >                  else {
> >                      if (error)
> >                          av_log(NULL, AV_LOG_ERROR, "Unable to parse option value \"%s\": %s\n", val, error);
> > -                    return NULL;
> > +                    return AVERROR(EINVAL);
> >                  }
> >              }
> >              if(o->type == FF_OPT_TYPE_FLAGS){
> > @@ -174,14 +180,14 @@
> >                  else if(cmd=='-') d= notfirst*av_get_double(obj, name, NULL) - d;
> >              }
> >  
> > -            if (!av_set_number(obj, name, d, 1, 1))
> > -                return NULL;
> > +            if ((ret = av_set_number2(obj, name, d, 1, 1, o_out)) < 0)
> > +                return ret;
> >              val+= i;
> >              if(!*val)
> > -                return o;
> > +                return 0;
> >              notfirst=1;
> >          }
> > -        return NULL;
> > +        return AVERROR(EINVAL);
> >      }
> >  
> >      if(alloc){
> > @@ -190,6 +196,13 @@
> >      }
> >  
> >      memcpy(((uint8_t*)obj) + o->offset, &val, sizeof(val));
> > +    return 0;
> > +}
> > +
> > +const AVOption *av_set_string2(void *obj, const char *name, const char *val, int alloc){
> > +    const AVOption *o;
> > +    if (av_set_string3(obj, name, val, 0, &o) < 0)
>                                           ^
> Ooops...
> 
> New patchset attached.
> 
> Regards.
> -- 
> FFmpeg = Forgiving & Furious Multimedia Powered Enchanting Guru

> Index: ffmpeg/libavcodec/opt.h
> ===================================================================
> --- ffmpeg.orig/libavcodec/opt.h	2008-12-15 23:33:10.000000000 +0100
> +++ ffmpeg/libavcodec/opt.h	2008-12-16 01:14:20.000000000 +0100

> @@ -105,6 +105,14 @@
>  attribute_deprecated const AVOption *av_set_string(void *obj, const char *name, const char *val);
>  
>  /**
> + * @return a pointer to the AVOption corresponding to the field set or
> + * NULL if no matching AVOption exists, or if the value \p val is not
> + * valid
> + * @see av_set_string3()
> + */
> +const AVOption *av_set_string2(void *obj, const char *name, const char *val, int alloc);
> +
> +/**
>   * Sets the field of obj with the given name to value.
>   *
>   * @param[in] obj A struct whose first element is a pointer to an

where is the #if version?

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

I wish the Xiph folks would stop pretending they've got something they
do not.  Somehow I fear this will remain a wish. -- M?ns Rullg?rd
-------------- 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/20081216/f45b5d36/attachment.pgp>



More information about the ffmpeg-devel mailing list