[FFmpeg-devel] [PATCH] Implement av_set_options_string()

Michael Niedermayer michaelni
Wed May 6 05:15:40 CEST 2009


On Wed, May 06, 2009 at 12:33:28AM +0200, Stefano Sabatini wrote:
> On date Sunday 2009-05-03 11:21:23 +0200, Stefano Sabatini encoded:
> > On date Friday 2009-05-01 20:02:40 +0200, Stefano Sabatini encoded:
> > > On date Saturday 2009-04-25 23:11:40 +0200, Stefano Sabatini encoded:
> > > > Hi, as in subject.
> > > > 
> > > > The result of the test is:
> > > > 
> > > > [test @ 0xbfaf32a0]Setting options string ''
> > > > 
> > > > [test @ 0xbfaf32a0]Setting options string 'foo='
> > > > [test @ 0xbfaf32a0]Setting value '' for key 'foo'
> > > > [test @ 0xbfaf32a0]Unknown option key 'foo'
> > > > [test @ 0xbfaf32a0]Error setting options string: 'foo='
> > > > 
> > > > [test @ 0xbfaf32a0]Setting options string 'foo'
> > > > [test @ 0xbfaf32a0]No key or key/value separator found after key
> > > > [test @ 0xbfaf32a0]Error setting options string: 'foo'
> > > > 
> > > > [test @ 0xbfaf32a0]Setting options string 'foo=val'
> > > > [test @ 0xbfaf32a0]Setting value 'val' for key 'foo'
> > > > [test @ 0xbfaf32a0]Unknown option key 'foo'
> > > > [test @ 0xbfaf32a0]Error setting options string: 'foo=val'
> > > > 
> > > > [test @ 0xbfaf32a0]Setting options string 'toggle=1:foo'
> > > > [test @ 0xbfaf32a0]Setting value '1' for key 'toggle'
> > > > [test @ 0xbfaf32a0]No key or key/value separator found after key
> > > > [test @ 0xbfaf32a0]Error setting options string: 'toggle=1:foo'
> > > > 
> > > > [test @ 0xbfaf32a0]Setting options string 'toggle=100'
> > > > [test @ 0xbfaf32a0]Setting value '100' for key 'toggle'
> > > > Value 100.000000 for parameter 'toggle' out of range
> > > > [test @ 0xbfaf32a0]Invalid value '100' for key 'toggle'
> > > > [test @ 0xbfaf32a0]Error setting options string: 'toggle=100'
> > > > 
> > > > [test @ 0xbfaf32a0]Setting options string 'flags=+mu-lame:num=42:toggle=0'
> > > > [test @ 0xbfaf32a0]Setting value '+mu-lame' for key 'flags'
> > > > [test @ 0xbfaf32a0]Setting value '42' for key 'num'
> > > > [test @ 0xbfaf32a0]Setting value '0' for key 'toggle'
> > > > 
> > > > [test @ 0xbfaf32a0]Setting options string 'num=42:string=blahblah'
> > > > [test @ 0xbfaf32a0]Setting value '42' for key 'num'
> > > > [test @ 0xbfaf32a0]Setting value 'blahblah' for key 'string'
> > > > 
> > > > [test @ 0xbfaf32a0]Setting options string 'num=42:string=blahblah'
> > > > [test @ 0xbfaf32a0]Setting value '42' for key 'num'
> > > > [test @ 0xbfaf32a0]Setting value 'blahblah' for key 'string'
> > > 
> > > Patch updated, AV_DEFINE_CLASS patch included for convenience.
> > 
> > Ping.
> 
> Patch updated, I'll post the other patch to a separate thread.
> 
> Regards.
> -- 
> FFmpeg = Faithless and Furious Mastering Philosofic Enlightened Gadget

>  parseutils.c |  129 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
>  parseutils.h |   17 +++++++
>  2 files changed, 146 insertions(+)
> 0ba9f5103f7f28a4d4255fa591c33610a9817246  parseutils-implement-set-options.patch
> Index: libavfilter-soc/ffmpeg/libavfilter/parseutils.c
> ===================================================================
> --- libavfilter-soc.orig/ffmpeg/libavfilter/parseutils.c	2009-05-06 00:28:02.000000000 +0200
> +++ libavfilter-soc/ffmpeg/libavfilter/parseutils.c	2009-05-06 00:29:32.000000000 +0200
> @@ -248,10 +248,109 @@
>      return 0;
>  }
>  
> +/**
> + * Stores the value in the field in ctx that is named like key.
> + * ctx must be an AVClass context, storing is done using AVOptions.
> + *

> + * @param buf the buffer to parse, buf will be updated to point to the
> + * character just after the parsed string

the string to parse ...


> + * @param key_val_sep a 0-terminated list of the characters used to
> + * separate key from value
> + * @param pairs_sep a 0-terminated list of the characters used to
> + * separate pairs

... seperate 2 pairs from each other 


> + * @return 0 if no key/value pair has been found, 1 if a key/value
> + * pair has been successfully parsed and set, a negative value
> + * otherwise
> + */
> +static int parse_key_value_pair(void *ctx, const char **buf,
> +                                const char *key_val_sep, const char *pairs_sep)
> +{
> +    char *key = av_get_token(buf, key_val_sep);

> +    char *val = NULL;

redundant init


[...]
> +int av_set_options_string(void *ctx, const char *opts,
> +                          const char *key_val_sep, const char *pairs_sep)
> +{
> +    int count = 0;
> +
> +    while (*opts) {
> +        if (parse_key_value_pair(ctx, &opts, key_val_sep, pairs_sep) < 0)
> +            return -1;
> +        count++;

> +        if (*opts)
> +            opts++;

is that really needed?


> +    }
> +
> +    if (*opts) {

unreachablee


[...]
> +static const AVOption options[]= {
> +{"num", "set num", OFFSET(num), FF_OPT_TYPE_INT, 0, 0, 100},
> +{"toggle", "set toggle", OFFSET(toggle), FF_OPT_TYPE_INT, 0, 0, 1},
> +{"string", "set string", OFFSET(string), FF_OPT_TYPE_STRING, DEFAULT, CHAR_MIN, CHAR_MAX},
> +{"flags", "set flags", OFFSET(flags), FF_OPT_TYPE_FLAGS, DEFAULT, 0, INT_MAX, 0, "flags"},
> +{"cool", "set cool flag ", 0, FF_OPT_TYPE_CONST, TEST_FLAG_COOL, INT_MIN, INT_MAX, 0, "flags"},
> +{"lame", "set lame flag ", 0, FF_OPT_TYPE_CONST, TEST_FLAG_LAME, INT_MIN, INT_MAX, 0, "flags"},
> +{"mu", "set mu flag ", 0, FF_OPT_TYPE_CONST, TEST_FLAG_MU, INT_MIN, INT_MAX, 0, "flags"},
> +{"rational", "set rational", OFFSET(rational), FF_OPT_TYPE_RATIONAL, DEFAULT, 0, 10},
> +{NULL},
> +};

vertical align


> +
> +AV_DEFINE_CLASS(test);
> +
>  int main()
>  {
>      int i;

ive not approved AV_DEFINE_CLASS() yet


> @@ -319,6 +418,36 @@
>          }
>      }
>  
> +    printf("\nTesting av_set_options_string()\n");
> +    {
> +        TestContext test_ctx;
> +        const char *options[] = {
> +            "",
> +            "foo=",
> +            "foo",
> +            "foo=val",
> +            "toggle=1:foo",
> +            "toggle=100",
> +            "flags=+mu-lame:num=42:toggle=0",
> +            "num=42:string=blahblah",
> +            "rational=0:rational=1/2:rational=1/-1",
> +            "rational=-1/0",
> +        };

a little whitespacein the strings would help readability


[...]
> Index: libavfilter-soc/ffmpeg/libavfilter/parseutils.h
> ===================================================================
> --- libavfilter-soc.orig/ffmpeg/libavfilter/parseutils.h	2009-05-06 00:28:08.000000000 +0200
> +++ libavfilter-soc/ffmpeg/libavfilter/parseutils.h	2009-05-06 00:29:32.000000000 +0200
> @@ -63,4 +63,21 @@
>      options                                         \
>  }
>  
> +/**
> + * Parses the key/value pairs list in opts. For each key/value pair
> + * found, stores the value in the field in ctx that is named like the
> + * key. ctx must be an AVClass context, storing is done using
> + * AVOptions.
> + *
> + * @param key_val_sep a 0-terminated list of the characters used to
> + * separate key from value

> + * @param pairs_sep a 0-terminated list of the characters used to
> + * separate key/value pairs

seperate 2 ...

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

I hate to see young programmers poisoned by the kind of thinking
Ulrich Drepper puts forward since it is simply too narrow -- Roman Shaposhnik
-------------- 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/20090506/bf66262c/attachment.pgp>



More information about the ffmpeg-devel mailing list