diff options
Diffstat (limited to 'libavutil/opt.c')
-rw-r--r-- | libavutil/opt.c | 28 |
1 files changed, 16 insertions, 12 deletions
diff --git a/libavutil/opt.c b/libavutil/opt.c index 7c80135..db4722b 100644 --- a/libavutil/opt.c +++ b/libavutil/opt.c @@ -2,20 +2,20 @@ * AVOptions * Copyright (c) 2005 Michael Niedermayer <michaelni@gmx.at> * - * This file is part of Libav. + * This file is part of FFmpeg. * - * Libav is free software; you can redistribute it and/or + * FFmpeg is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * - * Libav is distributed in the hope that it will be useful, + * FFmpeg is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public - * License along with Libav; if not, write to the Free Software + * License along with FFmpeg; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ @@ -36,10 +36,9 @@ //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) { - AVClass *c= *(AVClass**)v; //FIXME silly way of storing AVClass - const AVOption *o= c->option; + const AVOption *o = NULL; - for (; o && o->name; o++) { + while ((o = av_next_option(v, o))) { if (!strcmp(o->name, name) && (!unit || (o->unit && !strcmp(o->unit, unit))) && (o->flags & mask) == flags) return o; } @@ -57,7 +56,7 @@ const AVOption *av_next_option(void *obj, const AVOption *last) const AVOption *av_opt_next(void *obj, const AVOption *last) { if (last && last[1].name) return ++last; - else if (last) return NULL; + else if (last || !(*(AVClass**)obj)->option->name) return NULL; else return (*(AVClass**)obj)->option; } @@ -72,6 +71,7 @@ static int read_number(const AVOption *o, void *dst, double *num, int *den, int6 case AV_OPT_TYPE_RATIONAL: *intnum = ((AVRational*)dst)->num; *den = ((AVRational*)dst)->den; return 0; + case AV_OPT_TYPE_CONST: *num = o->default_val.dbl; return 0; } return AVERROR(EINVAL); } @@ -227,7 +227,7 @@ int av_opt_set(void *obj, const char *name, const char *val, int search_flags) const AVOption *o = av_opt_find2(obj, name, NULL, 0, search_flags, &target_obj); if (!o || !target_obj) return AVERROR_OPTION_NOT_FOUND; - if (!val) + if (!val && o->type != AV_OPT_TYPE_STRING) return AVERROR(EINVAL); dst = ((uint8_t*)target_obj) + o->offset; @@ -323,7 +323,7 @@ int av_opt_set_q(void *obj, const char *name, AVRational val, int search_flags) */ const char *av_get_string(void *obj, const char *name, const AVOption **o_out, char *buf, int buf_len) { - const AVOption *o = av_opt_find(obj, name, NULL, 0, 0); + const AVOption *o = av_opt_find(obj, name, NULL, 0, AV_OPT_SEARCH_CHILDREN); void *dst; uint8_t *bin; int len, i; @@ -342,6 +342,7 @@ const char *av_get_string(void *obj, const char *name, const AVOption **o_out, c case AV_OPT_TYPE_FLOAT: snprintf(buf, buf_len, "%f" , *(float *)dst);break; case AV_OPT_TYPE_DOUBLE: snprintf(buf, buf_len, "%f" , *(double *)dst);break; case AV_OPT_TYPE_RATIONAL: snprintf(buf, buf_len, "%d/%d", ((AVRational*)dst)->num, ((AVRational*)dst)->den);break; + case AV_OPT_TYPE_CONST: snprintf(buf, buf_len, "%f" , o->default_val.dbl);break; case AV_OPT_TYPE_STRING: return *(void**)dst; case AV_OPT_TYPE_BINARY: len = *(int*)(((uint8_t *)dst) + sizeof(uint8_t *)); @@ -362,7 +363,7 @@ int av_opt_get(void *obj, const char *name, int search_flags, uint8_t **out_val) uint8_t *bin, buf[128]; int len, i, ret; - if (!o || !target_obj) + if (!o || !target_obj || (o->offset<=0 && o->type != AV_OPT_TYPE_CONST)) return AVERROR_OPTION_NOT_FOUND; dst = (uint8_t*)target_obj + o->offset; @@ -375,6 +376,7 @@ int av_opt_get(void *obj, const char *name, int search_flags, uint8_t **out_val) case AV_OPT_TYPE_FLOAT: ret = snprintf(buf, sizeof(buf), "%f" , *(float *)dst);break; case AV_OPT_TYPE_DOUBLE: ret = snprintf(buf, sizeof(buf), "%f" , *(double *)dst);break; case AV_OPT_TYPE_RATIONAL: ret = snprintf(buf, sizeof(buf), "%d/%d", ((AVRational*)dst)->num, ((AVRational*)dst)->den);break; + case AV_OPT_TYPE_CONST: ret = snprintf(buf, sizeof(buf), "%f" , o->default_val.dbl);break; case AV_OPT_TYPE_STRING: if (*(uint8_t**)dst) *out_val = av_strdup(*(uint8_t**)dst); @@ -696,6 +698,8 @@ int av_set_options_string(void *ctx, const char *opts, { int ret, count = 0; + if (!opts) + return 0; while (*opts) { if ((ret = parse_key_value_pair(ctx, &opts, key_val_sep, pairs_sep)) < 0) return ret; @@ -766,7 +770,7 @@ const AVOption *av_opt_find2(void *obj, const char *name, const char *unit, while (o = av_opt_next(obj, o)) { if (!strcmp(o->name, name) && (o->flags & opt_flags) == opt_flags && ((!unit && o->type != AV_OPT_TYPE_CONST) || - (unit && o->unit && !strcmp(o->unit, unit)))) { + (unit && o->type == AV_OPT_TYPE_CONST && o->unit && !strcmp(o->unit, unit)))) { if (target_obj) { if (!(search_flags & AV_OPT_SEARCH_FAKE_OBJ)) *target_obj = obj; |