[FFmpeg-devel] [PATCH 1/8] avutil/opt: add AV_OPT_TYPE_BOOL
Clément Bœsch
u at pkh.me
Tue Sep 8 22:58:14 CEST 2015
On Sun, Sep 06, 2015 at 11:16:36PM +0200, Michael Niedermayer wrote:
> 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
>
Ah, nice, changed.
> patch LGTM
>
I made a bunch more changes & fixes:
- dropped the redundant "0", "1" (any number within the range will be OK)
- checked the ranges (so "auto" is not accepted if the range doesn't go
down to -1 for instance
- tested that av_opt_set_int() works as expected as requested by nev
- added on/off alias
Bumped & applied.
Thanks all for the reviews.
--
Clément B.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 473 bytes
Desc: not available
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20150908/af4c6f44/attachment.sig>
More information about the ffmpeg-devel
mailing list