[FFmpeg-devel] [PATCH] Enhance ffmpeg.c:opt_default()

Stefano Sabatini stefano.sabatini-lala
Sat May 17 12:24:58 CEST 2008


On date Friday 2008-05-16 18:24:11 +0200, Michael Niedermayer encoded:
> On Fri, May 16, 2008 at 01:57:09AM +0200, Stefano Sabatini wrote:
> > On date Thursday 2008-05-15 01:26:58 +0200, Michael Niedermayer encoded:
[...]
> > > av_set_string() should make it clear to the caller if an error happened
> > > and the code should then not continue blindly.
> > > These wraper and exit() functions really are ugly.
> > > 
> > > a "const char **error" argument instead of av_log() calls seems to be
> > > an option.
> > 
> > Michael, do you prefer the attached solution? (yes I'll split it if
> > you approve the general idea.)
> > 
> > I'm defining a new av_set_string2() with this signature:
> > const AVOption *av_set_string2(void *obj, const char *name, const char *val, const char **error_ptr);
> > 
> > which returns the pointer to the option if found even if the value
> > wasn't valid, in this case sets error_ptr to a static string
> > containing an error message: this function uses uses the new
> > av_set_number2().
> > 
> > In order to preserve the semantic of av_set_{double|q|int} I'm also
> > keeping a function av_set_number() with the old semantic and
> > signature.
> > 
> > Comments are welcome.
[...]
> > Index: libavcodec/avcodec.h
> > ===================================================================
> > --- libavcodec/avcodec.h	(revision 13158)
> > +++ libavcodec/avcodec.h	(working copy)
> > @@ -30,7 +30,7 @@
> >  #include "libavutil/avutil.h"
> >  
> >  #define LIBAVCODEC_VERSION_MAJOR 51
> > -#define LIBAVCODEC_VERSION_MINOR 56
> > +#define LIBAVCODEC_VERSION_MINOR 57
> >  #define LIBAVCODEC_VERSION_MICRO  0
> >  
> >  #define LIBAVCODEC_VERSION_INT  AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \
> > Index: libavcodec/opt.h
> > ===================================================================
> > --- libavcodec/opt.h	(revision 13158)
> > +++ libavcodec/opt.h	(working copy)
> > @@ -73,6 +73,7 @@
> >  
> >  const AVOption *av_find_opt(void *obj, const char *name, const char *unit, int mask, int flags);
> >  const AVOption *av_set_string(void *obj, const char *name, const char *val);
> > +const AVOption *av_set_string2(void *obj, const char *name, const char *val, const char **error_ptr);
> >  const AVOption *av_set_double(void *obj, const char *name, double n);
> >  const AVOption *av_set_q(void *obj, const char *name, AVRational n);
> >  const AVOption *av_set_int(void *obj, const char *name, int64_t n);
> > Index: libavcodec/opt.c
> > ===================================================================
> > --- libavcodec/opt.c	(revision 13158)
> > +++ libavcodec/opt.c	(working copy)
> > @@ -25,6 +25,7 @@
> >   * @author Michael Niedermayer <michaelni at gmx.at>
> >   */
> >  
> > +#include <libavutil/avstring.h>
> >  #include "avcodec.h"
> >  #include "opt.h"
> >  #include "eval.h"
> > @@ -47,15 +48,19 @@
> >      else                     return (*(AVClass**)obj)->option;
> >  }
> >  
> > -static const AVOption *av_set_number(void *obj, const char *name, double num, int den, int64_t intnum){
> > +static const AVOption *av_set_number2(void *obj, const char *name, double num, int den, int64_t intnum, const char **error_ptr){
> >      const AVOption *o= av_find_opt(obj, name, NULL, 0, 0);
> > +    static char error[128];
> > +
> 
> rejected

Well I know it sucks like a solution, what about to allocate the error
buffer and leave to the av_set_string2() user to free it?

Regards.
-- 
FFmpeg = Fiendish and Fast Mean Picky EnGraver




More information about the ffmpeg-devel mailing list