]> git.sesse.net Git - ffmpeg/blobdiff - libavutil/opt.c
libopenjpeg: rename decoder source file.
[ffmpeg] / libavutil / opt.c
index 7fe272dd9d4e4dfc86662a2ecdd07c59d543a7a7..ca31be3a9aefa8a0cf2f445ca5e589634b67f864 100644 (file)
@@ -55,9 +55,10 @@ 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 || !(*(AVClass**)obj)->option->name) return NULL;
-    else                      return (*(AVClass**)obj)->option;
+    AVClass *class = *(AVClass**)obj;
+    if (!last && class->option[0].name) return class->option;
+    if (last && last[1].name)           return ++last;
+    return NULL;
 }
 
 static int read_number(const AVOption *o, void *dst, double *num, int *den, int64_t *intnum)
@@ -71,6 +72,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);
 }
@@ -341,6 +343,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 *));
@@ -501,7 +504,8 @@ int av_opt_get_q(void *obj, const char *name, int search_flags, AVRational *out_
 int av_opt_flag_is_set(void *obj, const char *field_name, const char *flag_name)
 {
     const AVOption *field = av_opt_find(obj, field_name, NULL, 0, 0);
-    const AVOption *flag  = av_opt_find(obj, flag_name,  NULL, 0, 0);
+    const AVOption *flag  = av_opt_find(obj, flag_name,
+                                        field ? field->unit : NULL, 0, 0);
     int64_t res;
 
     if (!field || !flag || flag->type != AV_OPT_TYPE_CONST ||
@@ -698,6 +702,7 @@ int av_set_options_string(void *ctx, const char *opts,
 
     if (!opts)
         return 0;
+
     while (*opts) {
         if ((ret = parse_key_value_pair(ctx, &opts, key_val_sep, pairs_sep)) < 0)
             return ret;
@@ -748,9 +753,14 @@ const AVOption *av_opt_find(void *obj, const char *name, const char *unit,
 const AVOption *av_opt_find2(void *obj, const char *name, const char *unit,
                              int opt_flags, int search_flags, void **target_obj)
 {
-    const AVClass  *c = *(AVClass**)obj;
+    const AVClass  *c;
     const AVOption *o = NULL;
 
+    if(!obj)
+        return NULL;
+
+    c= *(AVClass**)obj;
+
     if (search_flags & AV_OPT_SEARCH_CHILDREN) {
         if (search_flags & AV_OPT_SEARCH_FAKE_OBJ) {
             const AVClass *child = NULL;