]> git.sesse.net Git - ffmpeg/blobdiff - libavcodec/opt.c
ac3enc: use dsputil functions in apply_window()
[ffmpeg] / libavcodec / opt.c
index f273c1607b3c22186a54ac767d2e326241744c76..ffa422ec93ddf1f4802f9d41744c20892d56f77c 100644 (file)
 /*
- * AVOptions
- * Copyright (c) 2005 Michael Niedermayer <michaelni@gmx.at>
+ * AVOptions ABI compatibility wrapper
+ * Copyright (c) 2010 Michael Niedermayer <michaelni@gmx.at>
  *
- * This library is free software; you can redistribute it and/or
+ * This file is part of FFmpeg.
+ *
+ * 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 of the License, or (at your option) any later version.
+ * version 2.1 of the License, or (at your option) any later version.
  *
- * This library 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 this library; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
- *
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
-/**
- * @file opt.c
- * AVOptions
- * @author Michael Niedermayer <michaelni@gmx.at>
- */
+
 #include "avcodec.h"
-static double av_parse_num(const char *name, char **tail){
-    double d;
-    d= strtod(name, tail);
-    if(*tail>name && (**tail=='/' || **tail==':'))
-        d/=strtod((*tail)+1, tail);
-    return d;
-}
+#include "opt.h"
 
-//FIXME order them and do a bin search
-static AVOption *find_opt(void *v, const char *name){
-    AVClass *c= *(AVClass**)v; //FIXME silly way of storing AVClass
-    AVOption *o= c->option;
-    
-    for(;o && o->name; o++){
-        if(!strcmp(o->name, name))
-            return o;
-    }
-    return NULL;
-}
+#if LIBAVCODEC_VERSION_MAJOR < 53 && CONFIG_SHARED && HAVE_SYMVER
 
-AVOption *av_next_option(void *obj, AVOption *last){
-    if(last && last[1].name) return ++last;
-    else if(last)            return NULL;
-    else                     return (*(AVClass**)obj)->option;
+FF_SYMVER(const AVOption *, av_find_opt, (void *obj, const char *name, const char *unit, int mask, int flags), "LIBAVCODEC_52"){
+    return av_find_opt(obj, name, unit, mask, flags);
 }
-
-static int av_set_number(void *obj, const char *name, double num, int den, int64_t intnum){
-    AVOption *o= find_opt(obj, name);
-    void *dst;
-    if(!o || o->offset<=0) 
-        return -1;
-    
-    if(o->max*den < num*intnum || o->min*den > num*intnum)
-        return -1;
-        
-    dst= ((uint8_t*)obj) + o->offset;
-
-    switch(o->type){
-    case FF_OPT_TYPE_INT:
-        *(int*)dst= lrintf(num/den)*intnum;
-        break;
-    case FF_OPT_TYPE_INT64:
-        *(int64_t*)dst= lrintf(num/den)*intnum;
-        break;
-    case FF_OPT_TYPE_FLOAT:
-        *(float*)dst= num*intnum/den;
-        break;
-    case FF_OPT_TYPE_DOUBLE:
-        *(double*)dst= num*intnum/den;
-        break;
-    case FF_OPT_TYPE_RATIONAL:
-        if((int)num == num)
-            *(AVRational*)dst= (AVRational){num*intnum, den};
-        else
-            *(AVRational*)dst= av_d2q(num*intnum/den, 1<<24);
-    default:
-        return -1;
-    }
-    return 0;
+FF_SYMVER(int, av_set_string3, (void *obj, const char *name, const char *val, int alloc, const AVOption **o_out), "LIBAVCODEC_52"){
+    return av_set_string3(obj, name, val, alloc, o_out);
 }
-
-//FIXME use eval.c maybe?
-int av_set_string(void *obj, const char *name, const char *val){
-    AVOption *o= find_opt(obj, name);
-    if(!o || !val || o->offset<=0) 
-        return -1;
-    if(o->type != FF_OPT_TYPE_STRING){
-        double d=0, tmp_d;
-        for(;;){
-            int i;
-            char buf[256], *tail;
-
-            for(i=0; i<sizeof(buf)-1 && val[i] && val[i]!='+'; i++)
-                buf[i]= val[i];
-            buf[i]=0;
-            val+= i;
-            
-            tmp_d= av_parse_num(buf, &tail);
-            if(tail > buf)
-                d+= tmp_d;
-            else{
-                AVOption *o_named= find_opt(obj, buf);
-                if(o_named && o_named->type == FF_OPT_TYPE_CONST) 
-                    d+= o_named->default_val;
-                else if(!strcmp(buf, "default")) d+= o->default_val;
-                else if(!strcmp(buf, "max"    )) d+= o->max;
-                else if(!strcmp(buf, "min"    )) d+= o->min;
-                else return -1;
-            }
-
-            if(*val == '+') val++;
-            if(!*val)
-                return av_set_number(obj, name, d, 1, 1);
-        }
-        return -1;
-    }
-    
-    memcpy(((uint8_t*)obj) + o->offset, val, sizeof(val));
-    return 0;
+FF_SYMVER(const AVOption *, av_set_double, (void *obj, const char *name, double n), "LIBAVCODEC_52"){
+    return av_set_double(obj, name, n);
 }
-
-int av_set_double(void *obj, const char *name, double n){
-    return av_set_number(obj, name, n, 1, 1);
+FF_SYMVER(const AVOption *, av_set_q, (void *obj, const char *name, AVRational n), "LIBAVCODEC_52"){
+    return av_set_q(obj, name, n);
 }
-
-int av_set_q(void *obj, const char *name, AVRational n){
-    return av_set_number(obj, name, n.num, n.den, 1);
+FF_SYMVER(const AVOption *, av_set_int, (void *obj, const char *name, int64_t n), "LIBAVCODEC_52"){
+    return av_set_int(obj, name, n);
 }
-
-int av_set_int(void *obj, const char *name, int64_t n){
-    return av_set_number(obj, name, 1, 1, n);
+FF_SYMVER(double, av_get_double, (void *obj, const char *name, const AVOption **o_out), "LIBAVCODEC_52"){
+    return av_get_double(obj, name, o_out);
+}
+FF_SYMVER(AVRational, av_get_q, (void *obj, const char *name, const AVOption **o_out), "LIBAVCODEC_52"){
+    return av_get_q(obj, name, o_out);
+}
+FF_SYMVER(int64_t, av_get_int, (void *obj, const char *name, const AVOption **o_out), "LIBAVCODEC_52"){
+    return av_get_int(obj, name, o_out);
+}
+FF_SYMVER(const char *, av_get_string, (void *obj, const char *name, const AVOption **o_out, char *buf, int buf_len), "LIBAVCODEC_52"){
+    return av_get_string(obj, name, o_out, buf, buf_len);
+}
+FF_SYMVER(const AVOption *, av_next_option, (void *obj, const AVOption *last), "LIBAVCODEC_52"){
+    return av_next_option(obj, last);
+}
+FF_SYMVER(int, av_opt_show2, (void *obj, void *av_log_obj, int req_flags, int rej_flags), "LIBAVCODEC_52"){
+    return av_opt_show2(obj, av_log_obj, req_flags, rej_flags);
+}
+FF_SYMVER(void, av_opt_set_defaults, (void *s), "LIBAVCODEC_52"){
+    return av_opt_set_defaults(s);
 }
+FF_SYMVER(void, av_opt_set_defaults2, (void *s, int mask, int flags), "LIBAVCODEC_52"){
+    return av_opt_set_defaults2(s, mask, flags);
+}
+#endif
 
-const char *av_get_string(void *obj, const char *name){
-    AVOption *o= find_opt(obj, name);
-    if(!o || o->offset<=0)
-        return NULL;
-    if(o->type != FF_OPT_TYPE_STRING) //FIXME convert to string? but what about free()?
+#if FF_API_SET_STRING_OLD
+const AVOption *av_set_string2(void *obj, const char *name, const char *val, int alloc){
+    const AVOption *o;
+    if (av_set_string3(obj, name, val, alloc, &o) < 0)
         return NULL;
-
-    return (const char*)(((uint8_t*)obj) + o->offset);
+    return o;
 }
 
-double av_get_double(void *obj, const char *name){
-    AVOption *o= find_opt(obj, name);
-    void *dst;
-    if(!o || o->offset<=0)
-        return NAN;
-
-    dst= ((uint8_t*)obj) + o->offset;
+const AVOption *av_set_string(void *obj, const char *name, const char *val){
+    const AVOption *o;
+    if (av_set_string3(obj, name, val, 0, &o) < 0)
+        return NULL;
+    return o;
+}
+#endif
 
-    switch(o->type){
-    case FF_OPT_TYPE_INT:       return *(int*)dst;
-    case FF_OPT_TYPE_INT64:     return *(int64_t*)dst; //FIXME maybe write a av_get_int64() ?
-    case FF_OPT_TYPE_FLOAT:     return *(float*)dst;
-    case FF_OPT_TYPE_DOUBLE:    return *(double*)dst;
-    case FF_OPT_TYPE_RATIONAL:  return av_q2d(*(AVRational*)dst); //FIXME maybe write a av_get_q() ?
-    default:                    return NAN;
-    }
+#if FF_API_OPT_SHOW
+int av_opt_show(void *obj, void *av_log_obj){
+    return av_opt_show2(obj, av_log_obj,
+                        AV_OPT_FLAG_ENCODING_PARAM|AV_OPT_FLAG_DECODING_PARAM, 0);
 }
+#endif