Mercurial > libavcodec.hg
comparison opt.c @ 2877:b447caeb6978 libavcodec
convert some options in ffmpeg.c to AVOptions
author | michael |
---|---|
date | Mon, 12 Sep 2005 10:23:52 +0000 |
parents | 8026edf6a349 |
children | 4d91f38477ee |
comparison
equal
deleted
inserted
replaced
2876:8026edf6a349 | 2877:b447caeb6978 |
---|---|
33 d/=strtod((*tail)+1, tail); | 33 d/=strtod((*tail)+1, tail); |
34 return d; | 34 return d; |
35 } | 35 } |
36 | 36 |
37 //FIXME order them and do a bin search | 37 //FIXME order them and do a bin search |
38 static AVOption *find_opt(void *v, const char *name){ | 38 static AVOption *find_opt(void *v, const char *name, const char *unit){ |
39 AVClass *c= *(AVClass**)v; //FIXME silly way of storing AVClass | 39 AVClass *c= *(AVClass**)v; //FIXME silly way of storing AVClass |
40 AVOption *o= c->option; | 40 AVOption *o= c->option; |
41 | 41 |
42 for(;o && o->name; o++){ | 42 for(;o && o->name; o++){ |
43 if(!strcmp(o->name, name)) | 43 if(!strcmp(o->name, name) && (!unit || !strcmp(o->unit, unit)) ) |
44 return o; | 44 return o; |
45 } | 45 } |
46 return NULL; | 46 return NULL; |
47 } | 47 } |
48 | 48 |
51 else if(last) return NULL; | 51 else if(last) return NULL; |
52 else return (*(AVClass**)obj)->option; | 52 else return (*(AVClass**)obj)->option; |
53 } | 53 } |
54 | 54 |
55 static AVOption *av_set_number(void *obj, const char *name, double num, int den, int64_t intnum){ | 55 static AVOption *av_set_number(void *obj, const char *name, double num, int den, int64_t intnum){ |
56 AVOption *o= find_opt(obj, name); | 56 AVOption *o= find_opt(obj, name, NULL); |
57 void *dst; | 57 void *dst; |
58 if(!o || o->offset<=0) | 58 if(!o || o->offset<=0) |
59 return NULL; | 59 return NULL; |
60 | 60 |
61 if(o->max*den < num*intnum || o->min*den > num*intnum) | 61 if(o->max*den < num*intnum || o->min*den > num*intnum) |
76 return NULL; | 76 return NULL; |
77 } | 77 } |
78 return o; | 78 return o; |
79 } | 79 } |
80 | 80 |
81 static AVOption *set_all_opt(void *v, const char *unit, double d){ | |
82 AVClass *c= *(AVClass**)v; //FIXME silly way of storing AVClass | |
83 AVOption *o= c->option; | |
84 AVOption *ret=NULL; | |
85 | |
86 for(;o && o->name; o++){ | |
87 if(o->type != FF_OPT_TYPE_CONST && o->unit && !strcmp(o->unit, unit)){ | |
88 double tmp= d; | |
89 if(o->type == FF_OPT_TYPE_FLAGS) | |
90 tmp= av_get_int(v, o->name, NULL) | (int64_t)d; | |
91 | |
92 av_set_number(v, o->name, tmp, 1, 1); | |
93 ret= o; | |
94 } | |
95 } | |
96 return ret; | |
97 } | |
98 | |
81 //FIXME use eval.c maybe? | 99 //FIXME use eval.c maybe? |
82 AVOption *av_set_string(void *obj, const char *name, const char *val){ | 100 AVOption *av_set_string(void *obj, const char *name, const char *val){ |
83 AVOption *o= find_opt(obj, name); | 101 AVOption *o= find_opt(obj, name, NULL); |
102 if(o && o->offset==0 && o->type == FF_OPT_TYPE_CONST && o->unit){ | |
103 return set_all_opt(obj, o->unit, o->default_val); | |
104 } | |
84 if(!o || !val || o->offset<=0) | 105 if(!o || !val || o->offset<=0) |
85 return NULL; | 106 return NULL; |
86 if(o->type != FF_OPT_TYPE_STRING){ | 107 if(o->type != FF_OPT_TYPE_STRING){ |
87 for(;;){ | 108 for(;;){ |
88 int i; | 109 int i; |
98 buf[i]=0; | 119 buf[i]=0; |
99 val+= i; | 120 val+= i; |
100 | 121 |
101 d= av_parse_num(buf, &tail); | 122 d= av_parse_num(buf, &tail); |
102 if(tail <= buf){ | 123 if(tail <= buf){ |
103 AVOption *o_named= find_opt(obj, buf); | 124 AVOption *o_named= find_opt(obj, buf, o->unit); |
104 if(o_named && o_named->type == FF_OPT_TYPE_CONST && !strcmp(o_named->unit, o->unit)) | 125 if(o_named && o_named->type == FF_OPT_TYPE_CONST) |
105 d= o_named->default_val; | 126 d= o_named->default_val; |
106 else if(!strcmp(buf, "default")) d= o->default_val; | 127 else if(!strcmp(buf, "default")) d= o->default_val; |
107 else if(!strcmp(buf, "max" )) d= o->max; | 128 else if(!strcmp(buf, "max" )) d= o->max; |
108 else if(!strcmp(buf, "min" )) d= o->min; | 129 else if(!strcmp(buf, "min" )) d= o->min; |
109 else return NULL; | 130 else return NULL; |
141 * | 162 * |
142 * @param buf a buffer which is used for returning non string values as strings, can be NULL | 163 * @param buf a buffer which is used for returning non string values as strings, can be NULL |
143 * @param buf_len allocated length in bytes of buf | 164 * @param buf_len allocated length in bytes of buf |
144 */ | 165 */ |
145 const char *av_get_string(void *obj, const char *name, AVOption **o_out, char *buf, int buf_len){ | 166 const char *av_get_string(void *obj, const char *name, AVOption **o_out, char *buf, int buf_len){ |
146 AVOption *o= find_opt(obj, name); | 167 AVOption *o= find_opt(obj, name, NULL); |
147 void *dst; | 168 void *dst; |
148 if(!o || o->offset<=0) | 169 if(!o || o->offset<=0) |
149 return NULL; | 170 return NULL; |
150 if(o->type != FF_OPT_TYPE_STRING && (!buf || !buf_len)) | 171 if(o->type != FF_OPT_TYPE_STRING && (!buf || !buf_len)) |
151 return NULL; | 172 return NULL; |
167 } | 188 } |
168 return buf; | 189 return buf; |
169 } | 190 } |
170 | 191 |
171 static int av_get_number(void *obj, const char *name, AVOption **o_out, double *num, int *den, int64_t *intnum){ | 192 static int av_get_number(void *obj, const char *name, AVOption **o_out, double *num, int *den, int64_t *intnum){ |
172 AVOption *o= find_opt(obj, name); | 193 AVOption *o= find_opt(obj, name, NULL); |
173 void *dst; | 194 void *dst; |
174 if(!o || o->offset<=0) | 195 if(!o || o->offset<=0) |
175 goto error; | 196 goto error; |
176 | 197 |
177 dst= ((uint8_t*)obj) + o->offset; | 198 dst= ((uint8_t*)obj) + o->offset; |