[FFmpeg-devel] [PATCH 2/2] opt: print ranges in opt_list()

Clément Bœsch ubitux at gmail.com
Fri Dec 7 03:01:32 CET 2012


On Tue, Dec 04, 2012 at 11:39:42PM +0100, Stefano Sabatini wrote:
> On date Tuesday 2012-12-04 20:46:41 +0100, Michael Niedermayer encoded:
> > The formating can and should be improved.
> > 
> > Signed-off-by: Michael Niedermayer <michaelni at gmx.at>
> > ---
> >  libavutil/opt.c |   42 ++++++++++++++++++++++++++++++++++++++++++
> >  1 file changed, 42 insertions(+)
> > 
> > diff --git a/libavutil/opt.c b/libavutil/opt.c
> > index cd26682..7c94cff 100644
> > --- a/libavutil/opt.c
> > +++ b/libavutil/opt.c
> > @@ -37,6 +37,8 @@
> >  #include "mathematics.h"
> >  #include "samplefmt.h"
> >  
> > +#include <float.h>
> > +
> >  #if FF_API_FIND_OPT
> >  //FIXME order them and do a bin search
> >  const AVOption *av_find_opt(void *v, const char *name, const char *unit, int mask, int flags)
> > @@ -728,10 +730,31 @@ int av_opt_flag_is_set(void *obj, const char *field_name, const char *flag_name)
> >      return res & flag->default_val.i64;
> >  }
> >  
> > +static void log_value(void *av_log_obj, int level, double d)
> > +{
> > +    if      (d == INT_MAX) {
> > +        av_log(av_log_obj, level, "INT_MAX");
> > +    } else if (d == INT_MIN) {
> > +        av_log(av_log_obj, level, "INT_MIN");
> > +    } else if (d == (double)INT64_MAX) {
> > +        av_log(av_log_obj, level, "I64_MAX");
> > +    } else if (d == INT64_MIN) {
> > +        av_log(av_log_obj, level, "I64_MIN");
> > +    } else if (d == FLT_MAX) {
> > +        av_log(av_log_obj, level, "FLT_MAX");
> > +    } else if (d == FLT_MIN) {
> > +        av_log(av_log_obj, level, "FLT_MIN");
> > +    } else {
> > +        av_log(av_log_obj, level, "%7.2g", d);
> > +    }
> > +}
> > +
> >  static void opt_list(void *obj, void *av_log_obj, const char *unit,
> >                       int req_flags, int rej_flags)
> >  {
> >      const AVOption *opt=NULL;
> > +    AVOptionRanges *r;
> > +    int i;
> >  
> >      while ((opt = av_opt_next(obj, opt))) {
> >          if (!(opt->flags & req_flags) || (opt->flags & rej_flags))
> > @@ -798,6 +821,25 @@ static void opt_list(void *obj, void *av_log_obj, const char *unit,
> >          av_log(av_log_obj, AV_LOG_INFO, "%c", (opt->flags & AV_OPT_FLAG_AUDIO_PARAM   ) ? 'A' : '.');
> >          av_log(av_log_obj, AV_LOG_INFO, "%c", (opt->flags & AV_OPT_FLAG_SUBTITLE_PARAM) ? 'S' : '.');
> >  
> > +        r = av_opt_query_ranges(obj, opt->name, AV_OPT_SEARCH_FAKE_OBJ);
> > +        if(r) {
> > +            switch (opt->type) {
> > +            case AV_OPT_TYPE_INT:
> > +            case AV_OPT_TYPE_INT64:
> > +            case AV_OPT_TYPE_DOUBLE:
> > +            case AV_OPT_TYPE_FLOAT:
> > +            case AV_OPT_TYPE_RATIONAL:
> > +                for (i=0; i<r->nb_ranges; i++) {
> > +                    log_value(av_log_obj, AV_LOG_INFO, r->range[i]->value_min);
> > +                    av_log(av_log_obj, AV_LOG_INFO, "-");
> > +                    log_value(av_log_obj, AV_LOG_INFO, r->range[i]->value_max);
> > +                    av_log(av_log_obj, AV_LOG_INFO, " ");
> > +                }
> > +                break;
> > +            }
> > +            av_opt_freep_ranges(&r);
> > +        }
> 
> I suggest to print the value range after the help message, something like:
> si                <int>   ..F... set stream index (range: [-1, INT_MAX])
> 
> note the space between min and max, or people will get confused
> (-123--1... WTF??).
> 
> Alternatives:
> si                <int:[-1, INT_MAX]>   ..F... set stream index
> 
> but looks cryptic (and not align-friendly), or something more verbose like:
> si                <int>   ..F... set stream index (value ranging from -1 to INT_MAX)
> 

I like that one, "(from X to Y)" or even "(X to Y)" might be enough.

-- 
Clément B.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 490 bytes
Desc: not available
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20121207/68493bbd/attachment.asc>


More information about the ffmpeg-devel mailing list