Mercurial > libavcodec.hg
annotate opt.c @ 3718:73626972ccbb libavcodec
Allow parameter values (AVOptions) to use the 'k', 'M', 'G'
and 'B' postfixes.
| author | takis |
|---|---|
| date | Thu, 14 Sep 2006 11:23:41 +0000 |
| parents | 301d975b69e3 |
| children | 8b8773577dd9 |
| rev | line source |
|---|---|
| 2862 | 1 /* |
| 2 * AVOptions | |
| 3 * Copyright (c) 2005 Michael Niedermayer <michaelni@gmx.at> | |
| 4 * | |
| 5 * This library is free software; you can redistribute it and/or | |
| 6 * modify it under the terms of the GNU Lesser General Public | |
| 7 * License as published by the Free Software Foundation; either | |
| 8 * version 2 of the License, or (at your option) any later version. | |
| 9 * | |
| 10 * This library is distributed in the hope that it will be useful, | |
| 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
| 13 * Lesser General Public License for more details. | |
| 14 * | |
| 15 * You should have received a copy of the GNU Lesser General Public | |
| 16 * License along with this library; if not, write to the Free Software | |
|
3036
0b546eab515d
Update licensing information: The FSF changed postal address.
diego
parents:
2967
diff
changeset
|
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
| 2862 | 18 * |
| 19 */ | |
| 2967 | 20 |
| 2862 | 21 /** |
| 22 * @file opt.c | |
| 23 * AVOptions | |
| 24 * @author Michael Niedermayer <michaelni@gmx.at> | |
| 25 */ | |
| 2967 | 26 |
| 2862 | 27 #include "avcodec.h" |
| 2880 | 28 #include "opt.h" |
| 2967 | 29 |
|
3718
73626972ccbb
Allow parameter values (AVOptions) to use the 'k', 'M', 'G'
takis
parents:
3703
diff
changeset
|
30 /** |
|
73626972ccbb
Allow parameter values (AVOptions) to use the 'k', 'M', 'G'
takis
parents:
3703
diff
changeset
|
31 * strtod() function extended with 'k', 'M' and 'B' postfixes. |
|
73626972ccbb
Allow parameter values (AVOptions) to use the 'k', 'M', 'G'
takis
parents:
3703
diff
changeset
|
32 * This allows using kB, MB, k, M and B as a postfix. This function |
|
73626972ccbb
Allow parameter values (AVOptions) to use the 'k', 'M', 'G'
takis
parents:
3703
diff
changeset
|
33 * assumes that the unit of numbers is bits not bytes. |
|
73626972ccbb
Allow parameter values (AVOptions) to use the 'k', 'M', 'G'
takis
parents:
3703
diff
changeset
|
34 */ |
|
73626972ccbb
Allow parameter values (AVOptions) to use the 'k', 'M', 'G'
takis
parents:
3703
diff
changeset
|
35 static double av_strtod(const char *name, char **tail) { |
| 2862 | 36 double d; |
| 37 d= strtod(name, tail); | |
|
3718
73626972ccbb
Allow parameter values (AVOptions) to use the 'k', 'M', 'G'
takis
parents:
3703
diff
changeset
|
38 if(*tail>name && (**tail=='k')) { |
|
73626972ccbb
Allow parameter values (AVOptions) to use the 'k', 'M', 'G'
takis
parents:
3703
diff
changeset
|
39 d*=1000; |
|
73626972ccbb
Allow parameter values (AVOptions) to use the 'k', 'M', 'G'
takis
parents:
3703
diff
changeset
|
40 (*tail)++; |
|
73626972ccbb
Allow parameter values (AVOptions) to use the 'k', 'M', 'G'
takis
parents:
3703
diff
changeset
|
41 } |
|
73626972ccbb
Allow parameter values (AVOptions) to use the 'k', 'M', 'G'
takis
parents:
3703
diff
changeset
|
42 else if(*tail && (**tail=='M')) { |
|
73626972ccbb
Allow parameter values (AVOptions) to use the 'k', 'M', 'G'
takis
parents:
3703
diff
changeset
|
43 d*=1000000; |
|
73626972ccbb
Allow parameter values (AVOptions) to use the 'k', 'M', 'G'
takis
parents:
3703
diff
changeset
|
44 (*tail)++; |
|
73626972ccbb
Allow parameter values (AVOptions) to use the 'k', 'M', 'G'
takis
parents:
3703
diff
changeset
|
45 } |
|
73626972ccbb
Allow parameter values (AVOptions) to use the 'k', 'M', 'G'
takis
parents:
3703
diff
changeset
|
46 else if(*tail && (**tail=='G')) { |
|
73626972ccbb
Allow parameter values (AVOptions) to use the 'k', 'M', 'G'
takis
parents:
3703
diff
changeset
|
47 d*=1000000000; |
|
73626972ccbb
Allow parameter values (AVOptions) to use the 'k', 'M', 'G'
takis
parents:
3703
diff
changeset
|
48 (*tail)++; |
|
73626972ccbb
Allow parameter values (AVOptions) to use the 'k', 'M', 'G'
takis
parents:
3703
diff
changeset
|
49 } |
|
73626972ccbb
Allow parameter values (AVOptions) to use the 'k', 'M', 'G'
takis
parents:
3703
diff
changeset
|
50 if(*tail && (**tail=='B')) { |
|
73626972ccbb
Allow parameter values (AVOptions) to use the 'k', 'M', 'G'
takis
parents:
3703
diff
changeset
|
51 d*=8; |
|
73626972ccbb
Allow parameter values (AVOptions) to use the 'k', 'M', 'G'
takis
parents:
3703
diff
changeset
|
52 (*tail)++; |
|
73626972ccbb
Allow parameter values (AVOptions) to use the 'k', 'M', 'G'
takis
parents:
3703
diff
changeset
|
53 } |
|
73626972ccbb
Allow parameter values (AVOptions) to use the 'k', 'M', 'G'
takis
parents:
3703
diff
changeset
|
54 return d; |
|
73626972ccbb
Allow parameter values (AVOptions) to use the 'k', 'M', 'G'
takis
parents:
3703
diff
changeset
|
55 } |
|
73626972ccbb
Allow parameter values (AVOptions) to use the 'k', 'M', 'G'
takis
parents:
3703
diff
changeset
|
56 |
|
73626972ccbb
Allow parameter values (AVOptions) to use the 'k', 'M', 'G'
takis
parents:
3703
diff
changeset
|
57 static double av_parse_num(const char *name, char **tail){ |
|
73626972ccbb
Allow parameter values (AVOptions) to use the 'k', 'M', 'G'
takis
parents:
3703
diff
changeset
|
58 double d; |
|
73626972ccbb
Allow parameter values (AVOptions) to use the 'k', 'M', 'G'
takis
parents:
3703
diff
changeset
|
59 d= av_strtod(name, tail); |
| 2862 | 60 if(*tail>name && (**tail=='/' || **tail==':')) |
|
3718
73626972ccbb
Allow parameter values (AVOptions) to use the 'k', 'M', 'G'
takis
parents:
3703
diff
changeset
|
61 d/=av_strtod((*tail)+1, tail); |
| 2862 | 62 return d; |
| 63 } | |
| 64 | |
| 65 //FIXME order them and do a bin search | |
| 2877 | 66 static AVOption *find_opt(void *v, const char *name, const char *unit){ |
| 2862 | 67 AVClass *c= *(AVClass**)v; //FIXME silly way of storing AVClass |
| 68 AVOption *o= c->option; | |
| 2967 | 69 |
| 2862 | 70 for(;o && o->name; o++){ |
| 2877 | 71 if(!strcmp(o->name, name) && (!unit || !strcmp(o->unit, unit)) ) |
| 2862 | 72 return o; |
| 73 } | |
| 74 return NULL; | |
| 75 } | |
| 76 | |
|
2865
3b999ce45b37
AVOption enumeration support and some flags to classify AVOptions
michael
parents:
2862
diff
changeset
|
77 AVOption *av_next_option(void *obj, AVOption *last){ |
|
3b999ce45b37
AVOption enumeration support and some flags to classify AVOptions
michael
parents:
2862
diff
changeset
|
78 if(last && last[1].name) return ++last; |
|
3b999ce45b37
AVOption enumeration support and some flags to classify AVOptions
michael
parents:
2862
diff
changeset
|
79 else if(last) return NULL; |
|
3b999ce45b37
AVOption enumeration support and some flags to classify AVOptions
michael
parents:
2862
diff
changeset
|
80 else return (*(AVClass**)obj)->option; |
|
3b999ce45b37
AVOption enumeration support and some flags to classify AVOptions
michael
parents:
2862
diff
changeset
|
81 } |
|
3b999ce45b37
AVOption enumeration support and some flags to classify AVOptions
michael
parents:
2862
diff
changeset
|
82 |
| 2873 | 83 static AVOption *av_set_number(void *obj, const char *name, double num, int den, int64_t intnum){ |
| 2877 | 84 AVOption *o= find_opt(obj, name, NULL); |
| 2862 | 85 void *dst; |
| 2967 | 86 if(!o || o->offset<=0) |
| 2873 | 87 return NULL; |
| 2967 | 88 |
| 2862 | 89 if(o->max*den < num*intnum || o->min*den > num*intnum) |
| 2873 | 90 return NULL; |
| 2967 | 91 |
| 2862 | 92 dst= ((uint8_t*)obj) + o->offset; |
| 93 | |
| 94 switch(o->type){ | |
| 2967 | 95 case FF_OPT_TYPE_FLAGS: |
| 2873 | 96 case FF_OPT_TYPE_INT: *(int *)dst= lrintf(num/den)*intnum; break; |
| 97 case FF_OPT_TYPE_INT64: *(int64_t *)dst= lrintf(num/den)*intnum; break; | |
| 98 case FF_OPT_TYPE_FLOAT: *(float *)dst= num*intnum/den; break; | |
| 99 case FF_OPT_TYPE_DOUBLE:*(double *)dst= num*intnum/den; break; | |
| 2862 | 100 case FF_OPT_TYPE_RATIONAL: |
| 2873 | 101 if((int)num == num) *(AVRational*)dst= (AVRational){num*intnum, den}; |
| 102 else *(AVRational*)dst= av_d2q(num*intnum/den, 1<<24); | |
| 2862 | 103 default: |
| 2873 | 104 return NULL; |
| 2862 | 105 } |
| 2873 | 106 return o; |
| 2862 | 107 } |
| 108 | |
| 2877 | 109 static AVOption *set_all_opt(void *v, const char *unit, double d){ |
| 110 AVClass *c= *(AVClass**)v; //FIXME silly way of storing AVClass | |
| 111 AVOption *o= c->option; | |
| 112 AVOption *ret=NULL; | |
| 2967 | 113 |
| 2877 | 114 for(;o && o->name; o++){ |
| 115 if(o->type != FF_OPT_TYPE_CONST && o->unit && !strcmp(o->unit, unit)){ | |
| 116 double tmp= d; | |
| 117 if(o->type == FF_OPT_TYPE_FLAGS) | |
| 118 tmp= av_get_int(v, o->name, NULL) | (int64_t)d; | |
| 119 | |
| 120 av_set_number(v, o->name, tmp, 1, 1); | |
| 121 ret= o; | |
| 122 } | |
| 123 } | |
| 124 return ret; | |
| 125 } | |
| 126 | |
| 2862 | 127 //FIXME use eval.c maybe? |
| 2873 | 128 AVOption *av_set_string(void *obj, const char *name, const char *val){ |
| 2877 | 129 AVOption *o= find_opt(obj, name, NULL); |
| 130 if(o && o->offset==0 && o->type == FF_OPT_TYPE_CONST && o->unit){ | |
| 131 return set_all_opt(obj, o->unit, o->default_val); | |
| 132 } | |
| 2967 | 133 if(!o || !val || o->offset<=0) |
| 2873 | 134 return NULL; |
| 2862 | 135 if(o->type != FF_OPT_TYPE_STRING){ |
| 136 for(;;){ | |
| 137 int i; | |
| 138 char buf[256], *tail; | |
|
2874
b6def74f5811
flags and named constants with type checking of course for AVOption
michael
parents:
2873
diff
changeset
|
139 int cmd=0; |
|
b6def74f5811
flags and named constants with type checking of course for AVOption
michael
parents:
2873
diff
changeset
|
140 double d; |
| 2862 | 141 |
|
2874
b6def74f5811
flags and named constants with type checking of course for AVOption
michael
parents:
2873
diff
changeset
|
142 if(*val == '+' || *val == '-') |
|
b6def74f5811
flags and named constants with type checking of course for AVOption
michael
parents:
2873
diff
changeset
|
143 cmd= *(val++); |
| 2967 | 144 |
|
2874
b6def74f5811
flags and named constants with type checking of course for AVOption
michael
parents:
2873
diff
changeset
|
145 for(i=0; i<sizeof(buf)-1 && val[i] && val[i]!='+' && val[i]!='-'; i++) |
| 2862 | 146 buf[i]= val[i]; |
| 147 buf[i]=0; | |
| 148 val+= i; | |
| 2967 | 149 |
|
2874
b6def74f5811
flags and named constants with type checking of course for AVOption
michael
parents:
2873
diff
changeset
|
150 d= av_parse_num(buf, &tail); |
|
b6def74f5811
flags and named constants with type checking of course for AVOption
michael
parents:
2873
diff
changeset
|
151 if(tail <= buf){ |
| 2877 | 152 AVOption *o_named= find_opt(obj, buf, o->unit); |
| 2967 | 153 if(o_named && o_named->type == FF_OPT_TYPE_CONST) |
|
2874
b6def74f5811
flags and named constants with type checking of course for AVOption
michael
parents:
2873
diff
changeset
|
154 d= o_named->default_val; |
|
b6def74f5811
flags and named constants with type checking of course for AVOption
michael
parents:
2873
diff
changeset
|
155 else if(!strcmp(buf, "default")) d= o->default_val; |
|
b6def74f5811
flags and named constants with type checking of course for AVOption
michael
parents:
2873
diff
changeset
|
156 else if(!strcmp(buf, "max" )) d= o->max; |
|
b6def74f5811
flags and named constants with type checking of course for AVOption
michael
parents:
2873
diff
changeset
|
157 else if(!strcmp(buf, "min" )) d= o->min; |
| 2873 | 158 else return NULL; |
| 2862 | 159 } |
|
2874
b6def74f5811
flags and named constants with type checking of course for AVOption
michael
parents:
2873
diff
changeset
|
160 if(o->type == FF_OPT_TYPE_FLAGS){ |
|
b6def74f5811
flags and named constants with type checking of course for AVOption
michael
parents:
2873
diff
changeset
|
161 if (cmd=='+') d= av_get_int(obj, name, NULL) | (int64_t)d; |
|
b6def74f5811
flags and named constants with type checking of course for AVOption
michael
parents:
2873
diff
changeset
|
162 else if(cmd=='-') d= av_get_int(obj, name, NULL) &~(int64_t)d; |
|
b6def74f5811
flags and named constants with type checking of course for AVOption
michael
parents:
2873
diff
changeset
|
163 }else if(cmd=='-') |
|
b6def74f5811
flags and named constants with type checking of course for AVOption
michael
parents:
2873
diff
changeset
|
164 d= -d; |
| 2862 | 165 |
|
2874
b6def74f5811
flags and named constants with type checking of course for AVOption
michael
parents:
2873
diff
changeset
|
166 av_set_number(obj, name, d, 1, 1); |
| 2862 | 167 if(!*val) |
|
2874
b6def74f5811
flags and named constants with type checking of course for AVOption
michael
parents:
2873
diff
changeset
|
168 return o; |
| 2862 | 169 } |
| 2873 | 170 return NULL; |
| 2862 | 171 } |
| 2967 | 172 |
| 2862 | 173 memcpy(((uint8_t*)obj) + o->offset, val, sizeof(val)); |
| 2873 | 174 return o; |
| 2862 | 175 } |
| 176 | |
| 2873 | 177 AVOption *av_set_double(void *obj, const char *name, double n){ |
| 2862 | 178 return av_set_number(obj, name, n, 1, 1); |
| 179 } | |
| 180 | |
| 2873 | 181 AVOption *av_set_q(void *obj, const char *name, AVRational n){ |
| 2862 | 182 return av_set_number(obj, name, n.num, n.den, 1); |
| 183 } | |
| 184 | |
| 2873 | 185 AVOption *av_set_int(void *obj, const char *name, int64_t n){ |
| 2862 | 186 return av_set_number(obj, name, 1, 1, n); |
| 187 } | |
| 188 | |
| 2873 | 189 /** |
| 2967 | 190 * |
| 2873 | 191 * @param buf a buffer which is used for returning non string values as strings, can be NULL |
| 192 * @param buf_len allocated length in bytes of buf | |
| 193 */ | |
| 194 const char *av_get_string(void *obj, const char *name, AVOption **o_out, char *buf, int buf_len){ | |
| 2877 | 195 AVOption *o= find_opt(obj, name, NULL); |
| 2873 | 196 void *dst; |
| 2862 | 197 if(!o || o->offset<=0) |
| 198 return NULL; | |
| 2873 | 199 if(o->type != FF_OPT_TYPE_STRING && (!buf || !buf_len)) |
| 2862 | 200 return NULL; |
| 201 | |
| 2873 | 202 dst= ((uint8_t*)obj) + o->offset; |
| 203 if(o_out) *o_out= o; | |
| 2967 | 204 |
| 2873 | 205 if(o->type == FF_OPT_TYPE_STRING) |
| 206 return dst; | |
| 2967 | 207 |
| 2873 | 208 switch(o->type){ |
|
2874
b6def74f5811
flags and named constants with type checking of course for AVOption
michael
parents:
2873
diff
changeset
|
209 case FF_OPT_TYPE_FLAGS: snprintf(buf, buf_len, "0x%08X",*(int *)dst);break; |
| 2873 | 210 case FF_OPT_TYPE_INT: snprintf(buf, buf_len, "%d" , *(int *)dst);break; |
| 2962 | 211 case FF_OPT_TYPE_INT64: snprintf(buf, buf_len, "%"PRId64, *(int64_t*)dst);break; |
| 2873 | 212 case FF_OPT_TYPE_FLOAT: snprintf(buf, buf_len, "%f" , *(float *)dst);break; |
| 213 case FF_OPT_TYPE_DOUBLE: snprintf(buf, buf_len, "%f" , *(double *)dst);break; | |
| 214 case FF_OPT_TYPE_RATIONAL: snprintf(buf, buf_len, "%d/%d", ((AVRational*)dst)->num, ((AVRational*)dst)->den);break; | |
| 215 default: return NULL; | |
| 216 } | |
| 217 return buf; | |
| 2862 | 218 } |
| 219 | |
| 2873 | 220 static int av_get_number(void *obj, const char *name, AVOption **o_out, double *num, int *den, int64_t *intnum){ |
| 2877 | 221 AVOption *o= find_opt(obj, name, NULL); |
| 2862 | 222 void *dst; |
| 223 if(!o || o->offset<=0) | |
| 2873 | 224 goto error; |
| 2862 | 225 |
| 226 dst= ((uint8_t*)obj) + o->offset; | |
| 227 | |
| 2873 | 228 if(o_out) *o_out= o; |
| 229 | |
| 2862 | 230 switch(o->type){ |
| 2967 | 231 case FF_OPT_TYPE_FLAGS: |
| 2873 | 232 case FF_OPT_TYPE_INT: *intnum= *(int *)dst;return 0; |
| 233 case FF_OPT_TYPE_INT64: *intnum= *(int64_t*)dst;return 0; | |
| 234 case FF_OPT_TYPE_FLOAT: *num= *(float *)dst;return 0; | |
| 235 case FF_OPT_TYPE_DOUBLE: *num= *(double *)dst;return 0; | |
| 2967 | 236 case FF_OPT_TYPE_RATIONAL: *intnum= ((AVRational*)dst)->num; |
| 2873 | 237 *den = ((AVRational*)dst)->den; |
| 238 return 0; | |
| 2862 | 239 } |
| 2873 | 240 error: |
| 241 *den=*intnum=0; | |
| 242 return -1; | |
| 2862 | 243 } |
| 2873 | 244 |
| 245 double av_get_double(void *obj, const char *name, AVOption **o_out){ | |
| 246 int64_t intnum=1; | |
| 247 double num=1; | |
| 248 int den=1; | |
| 249 | |
| 250 av_get_number(obj, name, o_out, &num, &den, &intnum); | |
| 251 return num*intnum/den; | |
| 252 } | |
| 253 | |
| 254 AVRational av_get_q(void *obj, const char *name, AVOption **o_out){ | |
| 255 int64_t intnum=1; | |
| 256 double num=1; | |
| 257 int den=1; | |
| 258 | |
| 259 av_get_number(obj, name, o_out, &num, &den, &intnum); | |
| 260 if(num == 1.0 && (int)intnum == intnum) | |
| 261 return (AVRational){intnum, den}; | |
| 262 else | |
| 263 return av_d2q(num*intnum/den, 1<<24); | |
| 264 } | |
| 265 | |
| 266 int64_t av_get_int(void *obj, const char *name, AVOption **o_out){ | |
| 267 int64_t intnum=1; | |
| 268 double num=1; | |
| 269 int den=1; | |
| 270 | |
| 271 av_get_number(obj, name, o_out, &num, &den, &intnum); | |
| 272 return num*intnum/den; | |
| 273 } | |
| 274 | |
| 2876 | 275 int av_opt_show(void *obj, void *av_log_obj){ |
| 2873 | 276 AVOption *opt=NULL; |
| 2967 | 277 |
| 2873 | 278 if(!obj) |
| 279 return -1; | |
| 2876 | 280 |
| 281 av_log(av_log_obj, AV_LOG_INFO, "%s AVOptions:\n", (*(AVClass**)obj)->class_name); | |
| 2873 | 282 |
| 283 while((opt= av_next_option(obj, opt))){ | |
| 284 if(!(opt->flags & (AV_OPT_FLAG_ENCODING_PARAM|AV_OPT_FLAG_DECODING_PARAM))) | |
| 285 continue; | |
| 2967 | 286 |
| 2876 | 287 av_log(av_log_obj, AV_LOG_INFO, "-%-17s ", opt->name); |
|
3141
25493c849d70
Give a hint about what is the expected the data type of command line options.
gpoirier
parents:
3036
diff
changeset
|
288 |
|
25493c849d70
Give a hint about what is the expected the data type of command line options.
gpoirier
parents:
3036
diff
changeset
|
289 switch( opt->type ) |
|
25493c849d70
Give a hint about what is the expected the data type of command line options.
gpoirier
parents:
3036
diff
changeset
|
290 { |
|
25493c849d70
Give a hint about what is the expected the data type of command line options.
gpoirier
parents:
3036
diff
changeset
|
291 case FF_OPT_TYPE_FLAGS: |
|
25493c849d70
Give a hint about what is the expected the data type of command line options.
gpoirier
parents:
3036
diff
changeset
|
292 av_log( av_log_obj, AV_LOG_INFO, "%-7s ", "<flags>" ); |
|
25493c849d70
Give a hint about what is the expected the data type of command line options.
gpoirier
parents:
3036
diff
changeset
|
293 break; |
|
25493c849d70
Give a hint about what is the expected the data type of command line options.
gpoirier
parents:
3036
diff
changeset
|
294 case FF_OPT_TYPE_INT: |
|
25493c849d70
Give a hint about what is the expected the data type of command line options.
gpoirier
parents:
3036
diff
changeset
|
295 av_log( av_log_obj, AV_LOG_INFO, "%-7s ", "<int>" ); |
|
25493c849d70
Give a hint about what is the expected the data type of command line options.
gpoirier
parents:
3036
diff
changeset
|
296 break; |
|
25493c849d70
Give a hint about what is the expected the data type of command line options.
gpoirier
parents:
3036
diff
changeset
|
297 case FF_OPT_TYPE_INT64: |
|
25493c849d70
Give a hint about what is the expected the data type of command line options.
gpoirier
parents:
3036
diff
changeset
|
298 av_log( av_log_obj, AV_LOG_INFO, "%-7s ", "<int64>" ); |
|
25493c849d70
Give a hint about what is the expected the data type of command line options.
gpoirier
parents:
3036
diff
changeset
|
299 break; |
|
25493c849d70
Give a hint about what is the expected the data type of command line options.
gpoirier
parents:
3036
diff
changeset
|
300 case FF_OPT_TYPE_DOUBLE: |
|
25493c849d70
Give a hint about what is the expected the data type of command line options.
gpoirier
parents:
3036
diff
changeset
|
301 av_log( av_log_obj, AV_LOG_INFO, "%-7s ", "<double>" ); |
|
25493c849d70
Give a hint about what is the expected the data type of command line options.
gpoirier
parents:
3036
diff
changeset
|
302 break; |
|
25493c849d70
Give a hint about what is the expected the data type of command line options.
gpoirier
parents:
3036
diff
changeset
|
303 case FF_OPT_TYPE_FLOAT: |
|
25493c849d70
Give a hint about what is the expected the data type of command line options.
gpoirier
parents:
3036
diff
changeset
|
304 av_log( av_log_obj, AV_LOG_INFO, "%-7s ", "<float>" ); |
|
25493c849d70
Give a hint about what is the expected the data type of command line options.
gpoirier
parents:
3036
diff
changeset
|
305 break; |
|
25493c849d70
Give a hint about what is the expected the data type of command line options.
gpoirier
parents:
3036
diff
changeset
|
306 case FF_OPT_TYPE_STRING: |
|
25493c849d70
Give a hint about what is the expected the data type of command line options.
gpoirier
parents:
3036
diff
changeset
|
307 av_log( av_log_obj, AV_LOG_INFO, "%-7s ", "<string>" ); |
|
25493c849d70
Give a hint about what is the expected the data type of command line options.
gpoirier
parents:
3036
diff
changeset
|
308 break; |
|
25493c849d70
Give a hint about what is the expected the data type of command line options.
gpoirier
parents:
3036
diff
changeset
|
309 case FF_OPT_TYPE_RATIONAL: |
|
25493c849d70
Give a hint about what is the expected the data type of command line options.
gpoirier
parents:
3036
diff
changeset
|
310 av_log( av_log_obj, AV_LOG_INFO, "%-7s ", "<rational>" ); |
|
25493c849d70
Give a hint about what is the expected the data type of command line options.
gpoirier
parents:
3036
diff
changeset
|
311 break; |
|
25493c849d70
Give a hint about what is the expected the data type of command line options.
gpoirier
parents:
3036
diff
changeset
|
312 case FF_OPT_TYPE_CONST: |
|
25493c849d70
Give a hint about what is the expected the data type of command line options.
gpoirier
parents:
3036
diff
changeset
|
313 default: |
|
25493c849d70
Give a hint about what is the expected the data type of command line options.
gpoirier
parents:
3036
diff
changeset
|
314 av_log( av_log_obj, AV_LOG_INFO, "%-7s ", "" ); |
|
25493c849d70
Give a hint about what is the expected the data type of command line options.
gpoirier
parents:
3036
diff
changeset
|
315 break; |
|
25493c849d70
Give a hint about what is the expected the data type of command line options.
gpoirier
parents:
3036
diff
changeset
|
316 } |
| 2876 | 317 av_log(av_log_obj, AV_LOG_INFO, "%c", (opt->flags & AV_OPT_FLAG_ENCODING_PARAM) ? 'E' : '.'); |
| 318 av_log(av_log_obj, AV_LOG_INFO, "%c", (opt->flags & AV_OPT_FLAG_DECODING_PARAM) ? 'D' : '.'); | |
| 319 av_log(av_log_obj, AV_LOG_INFO, "%c", (opt->flags & AV_OPT_FLAG_VIDEO_PARAM ) ? 'V' : '.'); | |
| 320 av_log(av_log_obj, AV_LOG_INFO, "%c", (opt->flags & AV_OPT_FLAG_AUDIO_PARAM ) ? 'A' : '.'); | |
| 321 av_log(av_log_obj, AV_LOG_INFO, "%c", (opt->flags & AV_OPT_FLAG_SUBTITLE_PARAM) ? 'S' : '.'); | |
| 2967 | 322 |
| 2888 | 323 if(opt->help) |
| 324 av_log(av_log_obj, AV_LOG_INFO, " %s", opt->help); | |
| 325 av_log(av_log_obj, AV_LOG_INFO, "\n"); | |
| 2873 | 326 } |
| 327 return 0; | |
| 328 } | |
| 3702 | 329 |
|
3703
301d975b69e3
adds doxygen docs to av_opt_set_defaults. Patch by Takis
gpoirier
parents:
3702
diff
changeset
|
330 /** Set the values of the AVCodecContext or AVFormatContext structure. |
|
301d975b69e3
adds doxygen docs to av_opt_set_defaults. Patch by Takis
gpoirier
parents:
3702
diff
changeset
|
331 * They are set to the defaults specified in the according AVOption options |
|
301d975b69e3
adds doxygen docs to av_opt_set_defaults. Patch by Takis
gpoirier
parents:
3702
diff
changeset
|
332 * array default_val field. |
|
301d975b69e3
adds doxygen docs to av_opt_set_defaults. Patch by Takis
gpoirier
parents:
3702
diff
changeset
|
333 * |
|
301d975b69e3
adds doxygen docs to av_opt_set_defaults. Patch by Takis
gpoirier
parents:
3702
diff
changeset
|
334 * @param s AVCodecContext or AVFormatContext for which the defaults will be set |
|
301d975b69e3
adds doxygen docs to av_opt_set_defaults. Patch by Takis
gpoirier
parents:
3702
diff
changeset
|
335 */ |
| 3702 | 336 void av_opt_set_defaults(void *s) |
| 337 { | |
| 338 AVOption *opt = NULL; | |
| 339 while ((opt = av_next_option(s, opt)) != NULL) { | |
| 340 switch(opt->type) { | |
| 341 case FF_OPT_TYPE_CONST: | |
| 342 /* Nothing to be done here */ | |
| 343 break; | |
| 344 case FF_OPT_TYPE_FLAGS: | |
| 345 case FF_OPT_TYPE_INT: { | |
| 346 int val; | |
| 347 val = opt->default_val; | |
| 348 av_set_int(s, opt->name, val); | |
| 349 } | |
| 350 break; | |
| 351 case FF_OPT_TYPE_FLOAT: { | |
| 352 double val; | |
| 353 val = opt->default_val; | |
| 354 av_set_double(s, opt->name, val); | |
| 355 } | |
| 356 break; | |
| 357 case FF_OPT_TYPE_RATIONAL: { | |
| 358 AVRational val; | |
| 359 val = av_d2q(opt->default_val, INT_MAX); | |
| 360 av_set_q(s, opt->name, val); | |
| 361 } | |
| 362 break; | |
| 363 case FF_OPT_TYPE_STRING: | |
| 364 /* Cannot set default for string as default_val is of type * double */ | |
| 365 break; | |
| 366 default: | |
| 367 av_log(s, AV_LOG_DEBUG, "AVOption type %d of option %s not implemented yet\n", opt->type, opt->name); | |
| 368 } | |
| 369 } | |
| 370 } | |
| 371 |
