comparison opt.c @ 4628:b0016ed89048 libavcodec

make av_find_opt() available to the public and add a mask+flags parameter to search for specific AVOptions
author michael
date Wed, 07 Mar 2007 02:03:44 +0000
parents e10acab2322a
children 2faa1399dd68
comparison
equal deleted inserted replaced
4627:e112ff86e261 4628:b0016ed89048
29 #include "avcodec.h" 29 #include "avcodec.h"
30 #include "opt.h" 30 #include "opt.h"
31 #include "eval.h" 31 #include "eval.h"
32 32
33 //FIXME order them and do a bin search 33 //FIXME order them and do a bin search
34 static const AVOption *find_opt(void *v, const char *name, const char *unit){ 34 const AVOption *av_find_opt(void *v, const char *name, const char *unit, int mask, int flags){
35 AVClass *c= *(AVClass**)v; //FIXME silly way of storing AVClass 35 AVClass *c= *(AVClass**)v; //FIXME silly way of storing AVClass
36 const AVOption *o= c->option; 36 const AVOption *o= c->option;
37 37
38 for(;o && o->name; o++){ 38 for(;o && o->name; o++){
39 if(!strcmp(o->name, name) && (!unit || !strcmp(o->unit, unit)) ) 39 if(!strcmp(o->name, name) && (!unit || !strcmp(o->unit, unit)) && (o->flags & mask) == flags )
40 return o; 40 return o;
41 } 41 }
42 return NULL; 42 return NULL;
43 } 43 }
44 44
47 else if(last) return NULL; 47 else if(last) return NULL;
48 else return (*(AVClass**)obj)->option; 48 else return (*(AVClass**)obj)->option;
49 } 49 }
50 50
51 static const AVOption *av_set_number(void *obj, const char *name, double num, int den, int64_t intnum){ 51 static const AVOption *av_set_number(void *obj, const char *name, double num, int den, int64_t intnum){
52 const AVOption *o= find_opt(obj, name, NULL); 52 const AVOption *o= av_find_opt(obj, name, NULL, 0, 0);
53 void *dst; 53 void *dst;
54 if(!o || o->offset<=0) 54 if(!o || o->offset<=0)
55 return NULL; 55 return NULL;
56 56
57 if(o->max*den < num*intnum || o->min*den > num*intnum) { 57 if(o->max*den < num*intnum || o->min*den > num*intnum) {
107 "QP2LAMBDA", 107 "QP2LAMBDA",
108 0 108 0
109 }; 109 };
110 110
111 const AVOption *av_set_string(void *obj, const char *name, const char *val){ 111 const AVOption *av_set_string(void *obj, const char *name, const char *val){
112 const AVOption *o= find_opt(obj, name, NULL); 112 const AVOption *o= av_find_opt(obj, name, NULL, 0, 0);
113 if(o && o->offset==0 && o->type == FF_OPT_TYPE_CONST && o->unit){ 113 if(o && o->offset==0 && o->type == FF_OPT_TYPE_CONST && o->unit){
114 return set_all_opt(obj, o->unit, o->default_val); 114 return set_all_opt(obj, o->unit, o->default_val);
115 } 115 }
116 if(!o || !val || o->offset<=0) 116 if(!o || !val || o->offset<=0)
117 return NULL; 117 return NULL;
131 buf[i]=0; 131 buf[i]=0;
132 val+= i; 132 val+= i;
133 133
134 d = ff_eval2(buf, const_values, const_names, NULL, NULL, NULL, NULL, NULL, &error); 134 d = ff_eval2(buf, const_values, const_names, NULL, NULL, NULL, NULL, NULL, &error);
135 if(isnan(d)) { 135 if(isnan(d)) {
136 const AVOption *o_named= find_opt(obj, buf, o->unit); 136 const AVOption *o_named= av_find_opt(obj, buf, o->unit, 0, 0);
137 if(o_named && o_named->type == FF_OPT_TYPE_CONST) 137 if(o_named && o_named->type == FF_OPT_TYPE_CONST)
138 d= o_named->default_val; 138 d= o_named->default_val;
139 else if(!strcmp(buf, "default")) d= o->default_val; 139 else if(!strcmp(buf, "default")) d= o->default_val;
140 else if(!strcmp(buf, "max" )) d= o->max; 140 else if(!strcmp(buf, "max" )) d= o->max;
141 else if(!strcmp(buf, "min" )) d= o->min; 141 else if(!strcmp(buf, "min" )) d= o->min;
178 * 178 *
179 * @param buf a buffer which is used for returning non string values as strings, can be NULL 179 * @param buf a buffer which is used for returning non string values as strings, can be NULL
180 * @param buf_len allocated length in bytes of buf 180 * @param buf_len allocated length in bytes of buf
181 */ 181 */
182 const char *av_get_string(void *obj, const char *name, const AVOption **o_out, char *buf, int buf_len){ 182 const char *av_get_string(void *obj, const char *name, const AVOption **o_out, char *buf, int buf_len){
183 const AVOption *o= find_opt(obj, name, NULL); 183 const AVOption *o= av_find_opt(obj, name, NULL, 0, 0);
184 void *dst; 184 void *dst;
185 if(!o || o->offset<=0) 185 if(!o || o->offset<=0)
186 return NULL; 186 return NULL;
187 if(o->type != FF_OPT_TYPE_STRING && (!buf || !buf_len)) 187 if(o->type != FF_OPT_TYPE_STRING && (!buf || !buf_len))
188 return NULL; 188 return NULL;
204 } 204 }
205 return buf; 205 return buf;
206 } 206 }
207 207
208 static int av_get_number(void *obj, const char *name, const AVOption **o_out, double *num, int *den, int64_t *intnum){ 208 static int av_get_number(void *obj, const char *name, const AVOption **o_out, double *num, int *den, int64_t *intnum){
209 const AVOption *o= find_opt(obj, name, NULL); 209 const AVOption *o= av_find_opt(obj, name, NULL, 0, 0);
210 void *dst; 210 void *dst;
211 if(!o || o->offset<=0) 211 if(!o || o->offset<=0)
212 goto error; 212 goto error;
213 213
214 dst= ((uint8_t*)obj) + o->offset; 214 dst= ((uint8_t*)obj) + o->offset;