[FFmpeg-devel] [PATCH 1/8] avutil/opt: add AV_OPT_TYPE_BOOL

Michael Niedermayer michaelni at gmx.at
Sun Sep 6 23:16:36 CEST 2015


On Sun, Sep 06, 2015 at 07:43:47PM +0200, Clément Bœsch wrote:
> TODO: bump lavu minor
> ---
>  libavutil/opt.c    | 69 +++++++++++++++++++++++++++++++++++++++++++++++++++++-
>  libavutil/opt.h    |  1 +
>  tests/ref/fate/opt | 22 +++++++++++++++--
>  3 files changed, 89 insertions(+), 3 deletions(-)
> 
> diff --git a/libavutil/opt.c b/libavutil/opt.c
> index 4030fa8..9912d9e 100644
> --- a/libavutil/opt.c
> +++ b/libavutil/opt.c
> @@ -60,6 +60,7 @@ static int read_number(const AVOption *o, const void *dst, double *num, int *den
>      case AV_OPT_TYPE_FLAGS:     *intnum = *(unsigned int*)dst;return 0;
>      case AV_OPT_TYPE_PIXEL_FMT: *intnum = *(enum AVPixelFormat *)dst;return 0;
>      case AV_OPT_TYPE_SAMPLE_FMT:*intnum = *(enum AVSampleFormat*)dst;return 0;
> +    case AV_OPT_TYPE_BOOL:
>      case AV_OPT_TYPE_INT:       *intnum = *(int         *)dst;return 0;
>      case AV_OPT_TYPE_CHANNEL_LAYOUT:
>      case AV_OPT_TYPE_DURATION:
> @@ -96,6 +97,7 @@ static int write_number(void *obj, const AVOption *o, void *dst, double num, int
>      switch (o->type) {
>      case AV_OPT_TYPE_PIXEL_FMT: *(enum AVPixelFormat *)dst = llrint(num/den) * intnum; break;
>      case AV_OPT_TYPE_SAMPLE_FMT:*(enum AVSampleFormat*)dst = llrint(num/den) * intnum; break;
> +    case AV_OPT_TYPE_BOOL:
>      case AV_OPT_TYPE_FLAGS:
>      case AV_OPT_TYPE_INT:   *(int       *)dst= llrint(num/den)*intnum; break;
>      case AV_OPT_TYPE_DURATION:
> @@ -297,6 +299,49 @@ static int set_string_color(void *obj, const AVOption *o, const char *val, uint8
>      return 0;
>  }
>  
> +static const char *get_bool_name(int val)
> +{
> +    if (val < 0)
> +        return "auto";
> +    return val ? "true" : "false";
> +}
> +

> +static int parse_bool(void *log_ctx, const char *val, int *dst)
> +{
> +    int i;
> +    static const char * const str_y[] = {"1", "true",  "y", "yes", "enable",  "enabled"};
> +    static const char * const str_n[] = {"0", "false", "n", "no",  "disable", "disabled"};
> +
> +    if (!strcmp(val, "auto")) {
> +        *dst = -1;
> +        return 0;
> +    }
> +
> +    for (i = 0; i < FF_ARRAY_ELEMS(str_y); i++) {
> +        if (!strcmp(val, str_y[i])) {
> +            *dst = 1;
> +            return 0;
> +        }
> +    }
> +
> +    for (i = 0; i < FF_ARRAY_ELEMS(str_n); i++) {
> +        if (!strcmp(val, str_n[i])) {
> +            *dst = 0;
> +            return 0;
> +        }
> +    }
> +

this can be simplified with av_match_name() or something similar

patch LGTM

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

The real ebay dictionary, page 3
"Rare item" - "Common item with rare defect or maybe just a lie"
"Professional" - "'Toy' made in china, not functional except as doorstop"
"Experts will know" - "The seller hopes you are not an expert"
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 181 bytes
Desc: Digital signature
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20150906/7a1dc26f/attachment.sig>


More information about the ffmpeg-devel mailing list