Mercurial > libavcodec.hg
comparison opt.c @ 4369:e10acab2322a libavcodec
Constantize AVOption, solve few warnings, patch from flameeyes@gentoo.org aka "the other Diego"
author | lu_zero |
---|---|
date | Sun, 21 Jan 2007 12:32:01 +0000 |
parents | 573f56f4f846 |
children | b0016ed89048 |
comparison
equal
deleted
inserted
replaced
4368:db099de6638f | 4369:e10acab2322a |
---|---|
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 AVOption *find_opt(void *v, const char *name, const char *unit){ | 34 static const AVOption *find_opt(void *v, const char *name, const char *unit){ |
35 AVClass *c= *(AVClass**)v; //FIXME silly way of storing AVClass | 35 AVClass *c= *(AVClass**)v; //FIXME silly way of storing AVClass |
36 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)) ) |
40 return o; | 40 return o; |
41 } | 41 } |
42 return NULL; | 42 return NULL; |
43 } | 43 } |
44 | 44 |
45 AVOption *av_next_option(void *obj, AVOption *last){ | 45 const AVOption *av_next_option(void *obj, const AVOption *last){ |
46 if(last && last[1].name) return ++last; | 46 if(last && last[1].name) return ++last; |
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 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 AVOption *o= find_opt(obj, name, NULL); | 52 const AVOption *o= find_opt(obj, name, NULL); |
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) { |
74 return NULL; | 74 return NULL; |
75 } | 75 } |
76 return o; | 76 return o; |
77 } | 77 } |
78 | 78 |
79 static AVOption *set_all_opt(void *v, const char *unit, double d){ | 79 static const AVOption *set_all_opt(void *v, const char *unit, double d){ |
80 AVClass *c= *(AVClass**)v; //FIXME silly way of storing AVClass | 80 AVClass *c= *(AVClass**)v; //FIXME silly way of storing AVClass |
81 AVOption *o= c->option; | 81 const AVOption *o= c->option; |
82 AVOption *ret=NULL; | 82 const AVOption *ret=NULL; |
83 | 83 |
84 for(;o && o->name; o++){ | 84 for(;o && o->name; o++){ |
85 if(o->type != FF_OPT_TYPE_CONST && o->unit && !strcmp(o->unit, unit)){ | 85 if(o->type != FF_OPT_TYPE_CONST && o->unit && !strcmp(o->unit, unit)){ |
86 double tmp= d; | 86 double tmp= d; |
87 if(o->type == FF_OPT_TYPE_FLAGS) | 87 if(o->type == FF_OPT_TYPE_FLAGS) |
106 "E", | 106 "E", |
107 "QP2LAMBDA", | 107 "QP2LAMBDA", |
108 0 | 108 0 |
109 }; | 109 }; |
110 | 110 |
111 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 AVOption *o= find_opt(obj, name, NULL); | 112 const AVOption *o= find_opt(obj, name, NULL); |
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 AVOption *o_named= find_opt(obj, buf, o->unit); | 136 const AVOption *o_named= find_opt(obj, buf, o->unit); |
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; |
160 | 160 |
161 memcpy(((uint8_t*)obj) + o->offset, val, sizeof(val)); | 161 memcpy(((uint8_t*)obj) + o->offset, val, sizeof(val)); |
162 return o; | 162 return o; |
163 } | 163 } |
164 | 164 |
165 AVOption *av_set_double(void *obj, const char *name, double n){ | 165 const AVOption *av_set_double(void *obj, const char *name, double n){ |
166 return av_set_number(obj, name, n, 1, 1); | 166 return av_set_number(obj, name, n, 1, 1); |
167 } | 167 } |
168 | 168 |
169 AVOption *av_set_q(void *obj, const char *name, AVRational n){ | 169 const AVOption *av_set_q(void *obj, const char *name, AVRational n){ |
170 return av_set_number(obj, name, n.num, n.den, 1); | 170 return av_set_number(obj, name, n.num, n.den, 1); |
171 } | 171 } |
172 | 172 |
173 AVOption *av_set_int(void *obj, const char *name, int64_t n){ | 173 const AVOption *av_set_int(void *obj, const char *name, int64_t n){ |
174 return av_set_number(obj, name, 1, 1, n); | 174 return av_set_number(obj, name, 1, 1, n); |
175 } | 175 } |
176 | 176 |
177 /** | 177 /** |
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, 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 AVOption *o= find_opt(obj, name, NULL); | 183 const AVOption *o= find_opt(obj, name, NULL); |
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; |
203 default: return NULL; | 203 default: 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, 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 AVOption *o= find_opt(obj, name, NULL); | 209 const AVOption *o= find_opt(obj, name, NULL); |
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; |
228 error: | 228 error: |
229 *den=*intnum=0; | 229 *den=*intnum=0; |
230 return -1; | 230 return -1; |
231 } | 231 } |
232 | 232 |
233 double av_get_double(void *obj, const char *name, AVOption **o_out){ | 233 double av_get_double(void *obj, const char *name, const AVOption **o_out){ |
234 int64_t intnum=1; | 234 int64_t intnum=1; |
235 double num=1; | 235 double num=1; |
236 int den=1; | 236 int den=1; |
237 | 237 |
238 av_get_number(obj, name, o_out, &num, &den, &intnum); | 238 av_get_number(obj, name, o_out, &num, &den, &intnum); |
239 return num*intnum/den; | 239 return num*intnum/den; |
240 } | 240 } |
241 | 241 |
242 AVRational av_get_q(void *obj, const char *name, AVOption **o_out){ | 242 AVRational av_get_q(void *obj, const char *name, const AVOption **o_out){ |
243 int64_t intnum=1; | 243 int64_t intnum=1; |
244 double num=1; | 244 double num=1; |
245 int den=1; | 245 int den=1; |
246 | 246 |
247 av_get_number(obj, name, o_out, &num, &den, &intnum); | 247 av_get_number(obj, name, o_out, &num, &den, &intnum); |
249 return (AVRational){intnum, den}; | 249 return (AVRational){intnum, den}; |
250 else | 250 else |
251 return av_d2q(num*intnum/den, 1<<24); | 251 return av_d2q(num*intnum/den, 1<<24); |
252 } | 252 } |
253 | 253 |
254 int64_t av_get_int(void *obj, const char *name, AVOption **o_out){ | 254 int64_t av_get_int(void *obj, const char *name, const AVOption **o_out){ |
255 int64_t intnum=1; | 255 int64_t intnum=1; |
256 double num=1; | 256 double num=1; |
257 int den=1; | 257 int den=1; |
258 | 258 |
259 av_get_number(obj, name, o_out, &num, &den, &intnum); | 259 av_get_number(obj, name, o_out, &num, &den, &intnum); |
260 return num*intnum/den; | 260 return num*intnum/den; |
261 } | 261 } |
262 | 262 |
263 static void opt_list(void *obj, void *av_log_obj, char *unit) | 263 static void opt_list(void *obj, void *av_log_obj, const char *unit) |
264 { | 264 { |
265 AVOption *opt=NULL; | 265 const AVOption *opt=NULL; |
266 | 266 |
267 while((opt= av_next_option(obj, opt))){ | 267 while((opt= av_next_option(obj, opt))){ |
268 if(!(opt->flags & (AV_OPT_FLAG_ENCODING_PARAM|AV_OPT_FLAG_DECODING_PARAM))) | 268 if(!(opt->flags & (AV_OPT_FLAG_ENCODING_PARAM|AV_OPT_FLAG_DECODING_PARAM))) |
269 continue; | 269 continue; |
270 | 270 |
343 * | 343 * |
344 * @param s AVCodecContext or AVFormatContext for which the defaults will be set | 344 * @param s AVCodecContext or AVFormatContext for which the defaults will be set |
345 */ | 345 */ |
346 void av_opt_set_defaults(void *s) | 346 void av_opt_set_defaults(void *s) |
347 { | 347 { |
348 AVOption *opt = NULL; | 348 const AVOption *opt = NULL; |
349 while ((opt = av_next_option(s, opt)) != NULL) { | 349 while ((opt = av_next_option(s, opt)) != NULL) { |
350 switch(opt->type) { | 350 switch(opt->type) { |
351 case FF_OPT_TYPE_CONST: | 351 case FF_OPT_TYPE_CONST: |
352 /* Nothing to be done here */ | 352 /* Nothing to be done here */ |
353 break; | 353 break; |