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

Stefano Sabatini stefano.sabatini-lala
Sun May 10 02:00:52 CEST 2009


On date Sunday 2009-05-10 01:11:33 +0200, Michael Niedermayer encoded:
> On Fri, May 08, 2009 at 09:07:03AM +0200, Stefano Sabatini wrote:
> > On date Friday 2009-05-08 03:11:07 +0200, Michael Niedermayer encoded:
> > > On Thu, May 07, 2009 at 09:22:01AM +0200, Stefano Sabatini wrote:
> > > > On date Thursday 2009-05-07 02:02:58 +0200, Michael Niedermayer encoded:
> > > [...]
> > > > +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;
> > > 
> > > passing the error code through seems like a good idea ...
> > 
> > Indeed it is... patch updated.
> > 
> > Regards.
> > -- 
> > FFmpeg = Faboulous and Faithless Merciless Puristic Extreme Generator
> 
> >  parseutils.c |  139 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
> >  parseutils.h |   19 ++++++++
> >  2 files changed, 158 insertions(+)
> > b112e8cb0e69efd7091663c8077d454ecb736ecc  parseutils-implement-set-options.patch
> > Index: libavfilter-soc/ffmpeg/libavfilter/parseutils.c
> > ===================================================================
> > --- libavfilter-soc.orig/ffmpeg/libavfilter/parseutils.c	2009-05-06 20:58:43.000000000 +0200
> > +++ libavfilter-soc/ffmpeg/libavfilter/parseutils.c	2009-05-08 09:03:35.000000000 +0200
> > @@ -248,10 +248,110 @@
> >      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 string to parse, buf will be updated to point at the
> > + * separator just after the parsed key/value pair
> > + * @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 two 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
> 
> thats too vague
> there are many failure modes
> from parsing failures, over the key being not in the AVOptions list to
> value not being valid

Yes, patch updated.

The case when the key in unknown is not explicitely managed, it should
be eventually av_set_string3() to be responsible for issuing an error
message in that case.

Result of the test is now:

Testing av_set_options_string()
[test @ 0xbfdfd528]Setting options string ''

[test @ 0xbfdfd528]Setting options string ':'
[test @ 0xbfdfd528]Missing key or no key/value separator found after key ':'
[test @ 0xbfdfd528]Error setting options string: ':'

[test @ 0xbfdfd528]Setting options string '='
[test @ 0xbfdfd528]Missing key or no key/value separator found after key ''
[test @ 0xbfdfd528]Error setting options string: '='

[test @ 0xbfdfd528]Setting options string 'foo=:'
[test @ 0xbfdfd528]Setting value '' for key 'foo'
[test @ 0xbfdfd528]Unknown key 'foo' or invalid value ''
[test @ 0xbfdfd528]Error setting options string: 'foo=:'

[test @ 0xbfdfd528]Setting options string ':=foo'
[test @ 0xbfdfd528]Setting value 'foo' for key ':'
[test @ 0xbfdfd528]Unknown key ':' or invalid value 'foo'
[test @ 0xbfdfd528]Error setting options string: ':=foo'

[test @ 0xbfdfd528]Setting options string '=foo'
[test @ 0xbfdfd528]Missing key or no key/value separator found after key ''
[test @ 0xbfdfd528]Error setting options string: '=foo'

[test @ 0xbfdfd528]Setting options string 'foo='
[test @ 0xbfdfd528]Setting value '' for key 'foo'
[test @ 0xbfdfd528]Unknown key 'foo' or invalid value ''
[test @ 0xbfdfd528]Error setting options string: 'foo='

[test @ 0xbfdfd528]Setting options string 'foo'
[test @ 0xbfdfd528]Missing key or no key/value separator found after key 'foo'
[test @ 0xbfdfd528]Error setting options string: 'foo'

[test @ 0xbfdfd528]Setting options string 'foo=val'
[test @ 0xbfdfd528]Setting value 'val' for key 'foo'
[test @ 0xbfdfd528]Unknown key 'foo' or invalid value 'val'
[test @ 0xbfdfd528]Error setting options string: 'foo=val'

[test @ 0xbfdfd528]Setting options string 'foo==val'
[test @ 0xbfdfd528]Setting value '=val' for key 'foo'
[test @ 0xbfdfd528]Unknown key 'foo' or invalid value '=val'
[test @ 0xbfdfd528]Error setting options string: 'foo==val'

[test @ 0xbfdfd528]Setting options string 'toggle=:'
[test @ 0xbfdfd528]Setting value '' for key 'toggle'
Unable to parse option value "": undefined constant or missing (
[test @ 0xbfdfd528]Unknown key 'toggle' or invalid value ''
[test @ 0xbfdfd528]Error setting options string: 'toggle=:'

[test @ 0xbfdfd528]Setting options string 'string=:'
[test @ 0xbfdfd528]Setting value '' for key 'string'

[test @ 0xbfdfd528]Setting options string 'toggle=1 : foo'
[test @ 0xbfdfd528]Setting value '1' for key 'toggle'
[test @ 0xbfdfd528]Missing key or no key/value separator found after key 'foo'
[test @ 0xbfdfd528]Error setting options string: 'toggle=1 : foo'

[test @ 0xbfdfd528]Setting options string 'toggle=100'
[test @ 0xbfdfd528]Setting value '100' for key 'toggle'
Value 100.000000 for parameter 'toggle' out of range
[test @ 0xbfdfd528]Unknown key 'toggle' or invalid value '100'
[test @ 0xbfdfd528]Error setting options string: 'toggle=100'

[test @ 0xbfdfd528]Setting options string 'toggle==1'
[test @ 0xbfdfd528]Setting value '=1' for key 'toggle'
Unable to parse option value "=1": undefined constant or missing (
[test @ 0xbfdfd528]Unknown key 'toggle' or invalid value '=1'
[test @ 0xbfdfd528]Error setting options string: 'toggle==1'

[test @ 0xbfdfd528]Setting options string 'flags=+mu-lame : num=42: toggle=0'
[test @ 0xbfdfd528]Setting value '+mu-lame' for key 'flags'
[test @ 0xbfdfd528]Setting value '42' for key 'num'
[test @ 0xbfdfd528]Setting value '0' for key 'toggle'

[test @ 0xbfdfd528]Setting options string 'num=42 : string=blahblah'
[test @ 0xbfdfd528]Setting value '42' for key 'num'
[test @ 0xbfdfd528]Setting value 'blahblah' for key 'string'

[test @ 0xbfdfd528]Setting options string 'rational=0 : rational=1/2 : rational=1/-1'
[test @ 0xbfdfd528]Setting value '0' for key 'rational'
[test @ 0xbfdfd528]Setting value '1/2' for key 'rational'
[test @ 0xbfdfd528]Setting value '1/-1' for key 'rational'
Unable to parse option value "1/-1": undefined constant or missing (
[test @ 0xbfdfd528]Unknown key 'rational' or invalid value '1/-1'
[test @ 0xbfdfd528]Error setting options string: 'rational=0 : rational=1/2 : rational=1/-1'

[test @ 0xbfdfd528]Setting options string 'rational=-1/0'
[test @ 0xbfdfd528]Setting value '-1/0' for key 'rational'
Value -inf for parameter 'rational' out of range
[test @ 0xbfdfd528]Unknown key 'rational' or invalid value '-1/0'
[test @ 0xbfdfd528]Error setting options string: 'rational=-1/0'

Regards.
-- 
FFmpeg = Fierce Faithless Minimalistic Prodigious Epehemeral Game
-------------- next part --------------
A non-text attachment was scrubbed...
Name: parseutils-implement-set-options.patch
Type: text/x-diff
Size: 6579 bytes
Desc: not available
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20090510/aa68eb30/attachment.patch>



More information about the ffmpeg-devel mailing list