Mercurial > libavcodec.hg
annotate opt.c @ 3740:0082fb8c77b6 libavcodec
set supported pixel formats for a few encoders (fixes crashes with grayscale)
author | michael |
---|---|
date | Wed, 20 Sep 2006 21:17:37 +0000 |
parents | 6c407dc6ab4a |
children | 67a63fa775a7 |
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 |
3731
8b8773577dd9
Add support for SI (k, M, ...) and IEC/IEEE (Ki, Mi, ...) units.
takis
parents:
3718
diff
changeset
|
30 static int8_t si_prefixes['z' - 'E' + 1]={ |
8b8773577dd9
Add support for SI (k, M, ...) and IEC/IEEE (Ki, Mi, ...) units.
takis
parents:
3718
diff
changeset
|
31 ['y'-'E']= -24, |
8b8773577dd9
Add support for SI (k, M, ...) and IEC/IEEE (Ki, Mi, ...) units.
takis
parents:
3718
diff
changeset
|
32 ['z'-'E']= -21, |
8b8773577dd9
Add support for SI (k, M, ...) and IEC/IEEE (Ki, Mi, ...) units.
takis
parents:
3718
diff
changeset
|
33 ['a'-'E']= -18, |
8b8773577dd9
Add support for SI (k, M, ...) and IEC/IEEE (Ki, Mi, ...) units.
takis
parents:
3718
diff
changeset
|
34 ['f'-'E']= -15, |
8b8773577dd9
Add support for SI (k, M, ...) and IEC/IEEE (Ki, Mi, ...) units.
takis
parents:
3718
diff
changeset
|
35 ['p'-'E']= -12, |
8b8773577dd9
Add support for SI (k, M, ...) and IEC/IEEE (Ki, Mi, ...) units.
takis
parents:
3718
diff
changeset
|
36 ['n'-'E']= - 9, |
8b8773577dd9
Add support for SI (k, M, ...) and IEC/IEEE (Ki, Mi, ...) units.
takis
parents:
3718
diff
changeset
|
37 ['u'-'E']= - 6, |
8b8773577dd9
Add support for SI (k, M, ...) and IEC/IEEE (Ki, Mi, ...) units.
takis
parents:
3718
diff
changeset
|
38 ['m'-'E']= - 3, |
8b8773577dd9
Add support for SI (k, M, ...) and IEC/IEEE (Ki, Mi, ...) units.
takis
parents:
3718
diff
changeset
|
39 ['c'-'E']= - 2, |
8b8773577dd9
Add support for SI (k, M, ...) and IEC/IEEE (Ki, Mi, ...) units.
takis
parents:
3718
diff
changeset
|
40 ['d'-'E']= - 1, |
8b8773577dd9
Add support for SI (k, M, ...) and IEC/IEEE (Ki, Mi, ...) units.
takis
parents:
3718
diff
changeset
|
41 ['h'-'E']= 2, |
8b8773577dd9
Add support for SI (k, M, ...) and IEC/IEEE (Ki, Mi, ...) units.
takis
parents:
3718
diff
changeset
|
42 ['k'-'E']= 3, |
8b8773577dd9
Add support for SI (k, M, ...) and IEC/IEEE (Ki, Mi, ...) units.
takis
parents:
3718
diff
changeset
|
43 ['K'-'E']= 3, |
8b8773577dd9
Add support for SI (k, M, ...) and IEC/IEEE (Ki, Mi, ...) units.
takis
parents:
3718
diff
changeset
|
44 ['M'-'E']= 6, |
8b8773577dd9
Add support for SI (k, M, ...) and IEC/IEEE (Ki, Mi, ...) units.
takis
parents:
3718
diff
changeset
|
45 ['G'-'E']= 9, |
8b8773577dd9
Add support for SI (k, M, ...) and IEC/IEEE (Ki, Mi, ...) units.
takis
parents:
3718
diff
changeset
|
46 ['T'-'E']= 12, |
8b8773577dd9
Add support for SI (k, M, ...) and IEC/IEEE (Ki, Mi, ...) units.
takis
parents:
3718
diff
changeset
|
47 ['P'-'E']= 15, |
8b8773577dd9
Add support for SI (k, M, ...) and IEC/IEEE (Ki, Mi, ...) units.
takis
parents:
3718
diff
changeset
|
48 ['E'-'E']= 18, |
8b8773577dd9
Add support for SI (k, M, ...) and IEC/IEEE (Ki, Mi, ...) units.
takis
parents:
3718
diff
changeset
|
49 ['Z'-'E']= 21, |
8b8773577dd9
Add support for SI (k, M, ...) and IEC/IEEE (Ki, Mi, ...) units.
takis
parents:
3718
diff
changeset
|
50 ['Y'-'E']= 24, |
8b8773577dd9
Add support for SI (k, M, ...) and IEC/IEEE (Ki, Mi, ...) units.
takis
parents:
3718
diff
changeset
|
51 }; |
8b8773577dd9
Add support for SI (k, M, ...) and IEC/IEEE (Ki, Mi, ...) units.
takis
parents:
3718
diff
changeset
|
52 |
8b8773577dd9
Add support for SI (k, M, ...) and IEC/IEEE (Ki, Mi, ...) units.
takis
parents:
3718
diff
changeset
|
53 /** strtod() function extended with 'k', 'M', 'G', 'ki', 'Mi', 'Gi' and 'B' |
8b8773577dd9
Add support for SI (k, M, ...) and IEC/IEEE (Ki, Mi, ...) units.
takis
parents:
3718
diff
changeset
|
54 * postfixes. This allows using f.e. kB, MiB, G and B as a postfix. This |
8b8773577dd9
Add support for SI (k, M, ...) and IEC/IEEE (Ki, Mi, ...) units.
takis
parents:
3718
diff
changeset
|
55 * function assumes that the unit of numbers is bits not bytes. |
3718
73626972ccbb
Allow parameter values (AVOptions) to use the 'k', 'M', 'G'
takis
parents:
3703
diff
changeset
|
56 */ |
3731
8b8773577dd9
Add support for SI (k, M, ...) and IEC/IEEE (Ki, Mi, ...) units.
takis
parents:
3718
diff
changeset
|
57 double av_strtod(const char *name, char **tail) { |
2862 | 58 double d; |
3731
8b8773577dd9
Add support for SI (k, M, ...) and IEC/IEEE (Ki, Mi, ...) units.
takis
parents:
3718
diff
changeset
|
59 int p = 0; |
8b8773577dd9
Add support for SI (k, M, ...) and IEC/IEEE (Ki, Mi, ...) units.
takis
parents:
3718
diff
changeset
|
60 char *next; |
8b8773577dd9
Add support for SI (k, M, ...) and IEC/IEEE (Ki, Mi, ...) units.
takis
parents:
3718
diff
changeset
|
61 d = strtod(name, &next); |
8b8773577dd9
Add support for SI (k, M, ...) and IEC/IEEE (Ki, Mi, ...) units.
takis
parents:
3718
diff
changeset
|
62 /* if parsing succeeded, check for and interpret postfixes */ |
8b8773577dd9
Add support for SI (k, M, ...) and IEC/IEEE (Ki, Mi, ...) units.
takis
parents:
3718
diff
changeset
|
63 if (next!=name) { |
8b8773577dd9
Add support for SI (k, M, ...) and IEC/IEEE (Ki, Mi, ...) units.
takis
parents:
3718
diff
changeset
|
64 |
8b8773577dd9
Add support for SI (k, M, ...) and IEC/IEEE (Ki, Mi, ...) units.
takis
parents:
3718
diff
changeset
|
65 if(*next >= 'E' && *next <= 'z'){ |
8b8773577dd9
Add support for SI (k, M, ...) and IEC/IEEE (Ki, Mi, ...) units.
takis
parents:
3718
diff
changeset
|
66 int e= si_prefixes[*next - 'E']; |
8b8773577dd9
Add support for SI (k, M, ...) and IEC/IEEE (Ki, Mi, ...) units.
takis
parents:
3718
diff
changeset
|
67 if(e){ |
8b8773577dd9
Add support for SI (k, M, ...) and IEC/IEEE (Ki, Mi, ...) units.
takis
parents:
3718
diff
changeset
|
68 if(next[1] == 'i'){ |
8b8773577dd9
Add support for SI (k, M, ...) and IEC/IEEE (Ki, Mi, ...) units.
takis
parents:
3718
diff
changeset
|
69 d*= pow( 2, e/0.3); |
8b8773577dd9
Add support for SI (k, M, ...) and IEC/IEEE (Ki, Mi, ...) units.
takis
parents:
3718
diff
changeset
|
70 next+=2; |
8b8773577dd9
Add support for SI (k, M, ...) and IEC/IEEE (Ki, Mi, ...) units.
takis
parents:
3718
diff
changeset
|
71 }else{ |
8b8773577dd9
Add support for SI (k, M, ...) and IEC/IEEE (Ki, Mi, ...) units.
takis
parents:
3718
diff
changeset
|
72 d*= pow(10, e); |
8b8773577dd9
Add support for SI (k, M, ...) and IEC/IEEE (Ki, Mi, ...) units.
takis
parents:
3718
diff
changeset
|
73 next++; |
8b8773577dd9
Add support for SI (k, M, ...) and IEC/IEEE (Ki, Mi, ...) units.
takis
parents:
3718
diff
changeset
|
74 } |
8b8773577dd9
Add support for SI (k, M, ...) and IEC/IEEE (Ki, Mi, ...) units.
takis
parents:
3718
diff
changeset
|
75 } |
8b8773577dd9
Add support for SI (k, M, ...) and IEC/IEEE (Ki, Mi, ...) units.
takis
parents:
3718
diff
changeset
|
76 } |
8b8773577dd9
Add support for SI (k, M, ...) and IEC/IEEE (Ki, Mi, ...) units.
takis
parents:
3718
diff
changeset
|
77 |
8b8773577dd9
Add support for SI (k, M, ...) and IEC/IEEE (Ki, Mi, ...) units.
takis
parents:
3718
diff
changeset
|
78 if(*next=='B') { |
8b8773577dd9
Add support for SI (k, M, ...) and IEC/IEEE (Ki, Mi, ...) units.
takis
parents:
3718
diff
changeset
|
79 d*=8; |
8b8773577dd9
Add support for SI (k, M, ...) and IEC/IEEE (Ki, Mi, ...) units.
takis
parents:
3718
diff
changeset
|
80 *next++; |
8b8773577dd9
Add support for SI (k, M, ...) and IEC/IEEE (Ki, Mi, ...) units.
takis
parents:
3718
diff
changeset
|
81 } |
3718
73626972ccbb
Allow parameter values (AVOptions) to use the 'k', 'M', 'G'
takis
parents:
3703
diff
changeset
|
82 } |
3731
8b8773577dd9
Add support for SI (k, M, ...) and IEC/IEEE (Ki, Mi, ...) units.
takis
parents:
3718
diff
changeset
|
83 /* if requested, fill in tail with the position after the last parsed |
8b8773577dd9
Add support for SI (k, M, ...) and IEC/IEEE (Ki, Mi, ...) units.
takis
parents:
3718
diff
changeset
|
84 character */ |
8b8773577dd9
Add support for SI (k, M, ...) and IEC/IEEE (Ki, Mi, ...) units.
takis
parents:
3718
diff
changeset
|
85 if (tail) |
8b8773577dd9
Add support for SI (k, M, ...) and IEC/IEEE (Ki, Mi, ...) units.
takis
parents:
3718
diff
changeset
|
86 *tail = next; |
3718
73626972ccbb
Allow parameter values (AVOptions) to use the 'k', 'M', 'G'
takis
parents:
3703
diff
changeset
|
87 return d; |
73626972ccbb
Allow parameter values (AVOptions) to use the 'k', 'M', 'G'
takis
parents:
3703
diff
changeset
|
88 } |
73626972ccbb
Allow parameter values (AVOptions) to use the 'k', 'M', 'G'
takis
parents:
3703
diff
changeset
|
89 |
73626972ccbb
Allow parameter values (AVOptions) to use the 'k', 'M', 'G'
takis
parents:
3703
diff
changeset
|
90 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
|
91 double d; |
73626972ccbb
Allow parameter values (AVOptions) to use the 'k', 'M', 'G'
takis
parents:
3703
diff
changeset
|
92 d= av_strtod(name, tail); |
2862 | 93 if(*tail>name && (**tail=='/' || **tail==':')) |
3718
73626972ccbb
Allow parameter values (AVOptions) to use the 'k', 'M', 'G'
takis
parents:
3703
diff
changeset
|
94 d/=av_strtod((*tail)+1, tail); |
2862 | 95 return d; |
96 } | |
97 | |
98 //FIXME order them and do a bin search | |
2877 | 99 static AVOption *find_opt(void *v, const char *name, const char *unit){ |
2862 | 100 AVClass *c= *(AVClass**)v; //FIXME silly way of storing AVClass |
101 AVOption *o= c->option; | |
2967 | 102 |
2862 | 103 for(;o && o->name; o++){ |
2877 | 104 if(!strcmp(o->name, name) && (!unit || !strcmp(o->unit, unit)) ) |
2862 | 105 return o; |
106 } | |
107 return NULL; | |
108 } | |
109 | |
2865
3b999ce45b37
AVOption enumeration support and some flags to classify AVOptions
michael
parents:
2862
diff
changeset
|
110 AVOption *av_next_option(void *obj, AVOption *last){ |
3b999ce45b37
AVOption enumeration support and some flags to classify AVOptions
michael
parents:
2862
diff
changeset
|
111 if(last && last[1].name) return ++last; |
3b999ce45b37
AVOption enumeration support and some flags to classify AVOptions
michael
parents:
2862
diff
changeset
|
112 else if(last) return NULL; |
3b999ce45b37
AVOption enumeration support and some flags to classify AVOptions
michael
parents:
2862
diff
changeset
|
113 else return (*(AVClass**)obj)->option; |
3b999ce45b37
AVOption enumeration support and some flags to classify AVOptions
michael
parents:
2862
diff
changeset
|
114 } |
3b999ce45b37
AVOption enumeration support and some flags to classify AVOptions
michael
parents:
2862
diff
changeset
|
115 |
2873 | 116 static AVOption *av_set_number(void *obj, const char *name, double num, int den, int64_t intnum){ |
2877 | 117 AVOption *o= find_opt(obj, name, NULL); |
2862 | 118 void *dst; |
2967 | 119 if(!o || o->offset<=0) |
2873 | 120 return NULL; |
2967 | 121 |
3735
6c407dc6ab4a
Inform the user that a certain AVOption is out of range.
takis
parents:
3731
diff
changeset
|
122 if(o->max*den < num*intnum || o->min*den > num*intnum) { |
6c407dc6ab4a
Inform the user that a certain AVOption is out of range.
takis
parents:
3731
diff
changeset
|
123 av_log(NULL, AV_LOG_ERROR, "Value %lf for parameter '%s' out of range.\n", num, name); |
2873 | 124 return NULL; |
3735
6c407dc6ab4a
Inform the user that a certain AVOption is out of range.
takis
parents:
3731
diff
changeset
|
125 } |
2967 | 126 |
2862 | 127 dst= ((uint8_t*)obj) + o->offset; |
128 | |
129 switch(o->type){ | |
2967 | 130 case FF_OPT_TYPE_FLAGS: |
2873 | 131 case FF_OPT_TYPE_INT: *(int *)dst= lrintf(num/den)*intnum; break; |
132 case FF_OPT_TYPE_INT64: *(int64_t *)dst= lrintf(num/den)*intnum; break; | |
133 case FF_OPT_TYPE_FLOAT: *(float *)dst= num*intnum/den; break; | |
134 case FF_OPT_TYPE_DOUBLE:*(double *)dst= num*intnum/den; break; | |
2862 | 135 case FF_OPT_TYPE_RATIONAL: |
2873 | 136 if((int)num == num) *(AVRational*)dst= (AVRational){num*intnum, den}; |
137 else *(AVRational*)dst= av_d2q(num*intnum/den, 1<<24); | |
2862 | 138 default: |
2873 | 139 return NULL; |
2862 | 140 } |
2873 | 141 return o; |
2862 | 142 } |
143 | |
2877 | 144 static AVOption *set_all_opt(void *v, const char *unit, double d){ |
145 AVClass *c= *(AVClass**)v; //FIXME silly way of storing AVClass | |
146 AVOption *o= c->option; | |
147 AVOption *ret=NULL; | |
2967 | 148 |
2877 | 149 for(;o && o->name; o++){ |
150 if(o->type != FF_OPT_TYPE_CONST && o->unit && !strcmp(o->unit, unit)){ | |
151 double tmp= d; | |
152 if(o->type == FF_OPT_TYPE_FLAGS) | |
153 tmp= av_get_int(v, o->name, NULL) | (int64_t)d; | |
154 | |
155 av_set_number(v, o->name, tmp, 1, 1); | |
156 ret= o; | |
157 } | |
158 } | |
159 return ret; | |
160 } | |
161 | |
2862 | 162 //FIXME use eval.c maybe? |
2873 | 163 AVOption *av_set_string(void *obj, const char *name, const char *val){ |
2877 | 164 AVOption *o= find_opt(obj, name, NULL); |
165 if(o && o->offset==0 && o->type == FF_OPT_TYPE_CONST && o->unit){ | |
166 return set_all_opt(obj, o->unit, o->default_val); | |
167 } | |
2967 | 168 if(!o || !val || o->offset<=0) |
2873 | 169 return NULL; |
2862 | 170 if(o->type != FF_OPT_TYPE_STRING){ |
171 for(;;){ | |
172 int i; | |
173 char buf[256], *tail; | |
2874
b6def74f5811
flags and named constants with type checking of course for AVOption
michael
parents:
2873
diff
changeset
|
174 int cmd=0; |
b6def74f5811
flags and named constants with type checking of course for AVOption
michael
parents:
2873
diff
changeset
|
175 double d; |
2862 | 176 |
2874
b6def74f5811
flags and named constants with type checking of course for AVOption
michael
parents:
2873
diff
changeset
|
177 if(*val == '+' || *val == '-') |
b6def74f5811
flags and named constants with type checking of course for AVOption
michael
parents:
2873
diff
changeset
|
178 cmd= *(val++); |
2967 | 179 |
2874
b6def74f5811
flags and named constants with type checking of course for AVOption
michael
parents:
2873
diff
changeset
|
180 for(i=0; i<sizeof(buf)-1 && val[i] && val[i]!='+' && val[i]!='-'; i++) |
2862 | 181 buf[i]= val[i]; |
182 buf[i]=0; | |
183 val+= i; | |
2967 | 184 |
2874
b6def74f5811
flags and named constants with type checking of course for AVOption
michael
parents:
2873
diff
changeset
|
185 d= av_parse_num(buf, &tail); |
b6def74f5811
flags and named constants with type checking of course for AVOption
michael
parents:
2873
diff
changeset
|
186 if(tail <= buf){ |
2877 | 187 AVOption *o_named= find_opt(obj, buf, o->unit); |
2967 | 188 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
|
189 d= o_named->default_val; |
b6def74f5811
flags and named constants with type checking of course for AVOption
michael
parents:
2873
diff
changeset
|
190 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
|
191 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
|
192 else if(!strcmp(buf, "min" )) d= o->min; |
2873 | 193 else return NULL; |
2862 | 194 } |
2874
b6def74f5811
flags and named constants with type checking of course for AVOption
michael
parents:
2873
diff
changeset
|
195 if(o->type == FF_OPT_TYPE_FLAGS){ |
b6def74f5811
flags and named constants with type checking of course for AVOption
michael
parents:
2873
diff
changeset
|
196 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
|
197 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
|
198 }else if(cmd=='-') |
b6def74f5811
flags and named constants with type checking of course for AVOption
michael
parents:
2873
diff
changeset
|
199 d= -d; |
2862 | 200 |
2874
b6def74f5811
flags and named constants with type checking of course for AVOption
michael
parents:
2873
diff
changeset
|
201 av_set_number(obj, name, d, 1, 1); |
2862 | 202 if(!*val) |
2874
b6def74f5811
flags and named constants with type checking of course for AVOption
michael
parents:
2873
diff
changeset
|
203 return o; |
2862 | 204 } |
2873 | 205 return NULL; |
2862 | 206 } |
2967 | 207 |
2862 | 208 memcpy(((uint8_t*)obj) + o->offset, val, sizeof(val)); |
2873 | 209 return o; |
2862 | 210 } |
211 | |
2873 | 212 AVOption *av_set_double(void *obj, const char *name, double n){ |
2862 | 213 return av_set_number(obj, name, n, 1, 1); |
214 } | |
215 | |
2873 | 216 AVOption *av_set_q(void *obj, const char *name, AVRational n){ |
2862 | 217 return av_set_number(obj, name, n.num, n.den, 1); |
218 } | |
219 | |
2873 | 220 AVOption *av_set_int(void *obj, const char *name, int64_t n){ |
2862 | 221 return av_set_number(obj, name, 1, 1, n); |
222 } | |
223 | |
2873 | 224 /** |
2967 | 225 * |
2873 | 226 * @param buf a buffer which is used for returning non string values as strings, can be NULL |
227 * @param buf_len allocated length in bytes of buf | |
228 */ | |
229 const char *av_get_string(void *obj, const char *name, AVOption **o_out, char *buf, int buf_len){ | |
2877 | 230 AVOption *o= find_opt(obj, name, NULL); |
2873 | 231 void *dst; |
2862 | 232 if(!o || o->offset<=0) |
233 return NULL; | |
2873 | 234 if(o->type != FF_OPT_TYPE_STRING && (!buf || !buf_len)) |
2862 | 235 return NULL; |
236 | |
2873 | 237 dst= ((uint8_t*)obj) + o->offset; |
238 if(o_out) *o_out= o; | |
2967 | 239 |
2873 | 240 if(o->type == FF_OPT_TYPE_STRING) |
241 return dst; | |
2967 | 242 |
2873 | 243 switch(o->type){ |
2874
b6def74f5811
flags and named constants with type checking of course for AVOption
michael
parents:
2873
diff
changeset
|
244 case FF_OPT_TYPE_FLAGS: snprintf(buf, buf_len, "0x%08X",*(int *)dst);break; |
2873 | 245 case FF_OPT_TYPE_INT: snprintf(buf, buf_len, "%d" , *(int *)dst);break; |
2962 | 246 case FF_OPT_TYPE_INT64: snprintf(buf, buf_len, "%"PRId64, *(int64_t*)dst);break; |
2873 | 247 case FF_OPT_TYPE_FLOAT: snprintf(buf, buf_len, "%f" , *(float *)dst);break; |
248 case FF_OPT_TYPE_DOUBLE: snprintf(buf, buf_len, "%f" , *(double *)dst);break; | |
249 case FF_OPT_TYPE_RATIONAL: snprintf(buf, buf_len, "%d/%d", ((AVRational*)dst)->num, ((AVRational*)dst)->den);break; | |
250 default: return NULL; | |
251 } | |
252 return buf; | |
2862 | 253 } |
254 | |
2873 | 255 static int av_get_number(void *obj, const char *name, AVOption **o_out, double *num, int *den, int64_t *intnum){ |
2877 | 256 AVOption *o= find_opt(obj, name, NULL); |
2862 | 257 void *dst; |
258 if(!o || o->offset<=0) | |
2873 | 259 goto error; |
2862 | 260 |
261 dst= ((uint8_t*)obj) + o->offset; | |
262 | |
2873 | 263 if(o_out) *o_out= o; |
264 | |
2862 | 265 switch(o->type){ |
2967 | 266 case FF_OPT_TYPE_FLAGS: |
2873 | 267 case FF_OPT_TYPE_INT: *intnum= *(int *)dst;return 0; |
268 case FF_OPT_TYPE_INT64: *intnum= *(int64_t*)dst;return 0; | |
269 case FF_OPT_TYPE_FLOAT: *num= *(float *)dst;return 0; | |
270 case FF_OPT_TYPE_DOUBLE: *num= *(double *)dst;return 0; | |
2967 | 271 case FF_OPT_TYPE_RATIONAL: *intnum= ((AVRational*)dst)->num; |
2873 | 272 *den = ((AVRational*)dst)->den; |
273 return 0; | |
2862 | 274 } |
2873 | 275 error: |
276 *den=*intnum=0; | |
277 return -1; | |
2862 | 278 } |
2873 | 279 |
280 double av_get_double(void *obj, const char *name, AVOption **o_out){ | |
281 int64_t intnum=1; | |
282 double num=1; | |
283 int den=1; | |
284 | |
285 av_get_number(obj, name, o_out, &num, &den, &intnum); | |
286 return num*intnum/den; | |
287 } | |
288 | |
289 AVRational av_get_q(void *obj, const char *name, AVOption **o_out){ | |
290 int64_t intnum=1; | |
291 double num=1; | |
292 int den=1; | |
293 | |
294 av_get_number(obj, name, o_out, &num, &den, &intnum); | |
295 if(num == 1.0 && (int)intnum == intnum) | |
296 return (AVRational){intnum, den}; | |
297 else | |
298 return av_d2q(num*intnum/den, 1<<24); | |
299 } | |
300 | |
301 int64_t av_get_int(void *obj, const char *name, AVOption **o_out){ | |
302 int64_t intnum=1; | |
303 double num=1; | |
304 int den=1; | |
305 | |
306 av_get_number(obj, name, o_out, &num, &den, &intnum); | |
307 return num*intnum/den; | |
308 } | |
309 | |
2876 | 310 int av_opt_show(void *obj, void *av_log_obj){ |
2873 | 311 AVOption *opt=NULL; |
2967 | 312 |
2873 | 313 if(!obj) |
314 return -1; | |
2876 | 315 |
316 av_log(av_log_obj, AV_LOG_INFO, "%s AVOptions:\n", (*(AVClass**)obj)->class_name); | |
2873 | 317 |
318 while((opt= av_next_option(obj, opt))){ | |
319 if(!(opt->flags & (AV_OPT_FLAG_ENCODING_PARAM|AV_OPT_FLAG_DECODING_PARAM))) | |
320 continue; | |
2967 | 321 |
2876 | 322 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
|
323 |
25493c849d70
Give a hint about what is the expected the data type of command line options.
gpoirier
parents:
3036
diff
changeset
|
324 switch( opt->type ) |
25493c849d70
Give a hint about what is the expected the data type of command line options.
gpoirier
parents:
3036
diff
changeset
|
325 { |
25493c849d70
Give a hint about what is the expected the data type of command line options.
gpoirier
parents:
3036
diff
changeset
|
326 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
|
327 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
|
328 break; |
25493c849d70
Give a hint about what is the expected the data type of command line options.
gpoirier
parents:
3036
diff
changeset
|
329 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
|
330 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
|
331 break; |
25493c849d70
Give a hint about what is the expected the data type of command line options.
gpoirier
parents:
3036
diff
changeset
|
332 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
|
333 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
|
334 break; |
25493c849d70
Give a hint about what is the expected the data type of command line options.
gpoirier
parents:
3036
diff
changeset
|
335 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
|
336 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
|
337 break; |
25493c849d70
Give a hint about what is the expected the data type of command line options.
gpoirier
parents:
3036
diff
changeset
|
338 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
|
339 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
|
340 break; |
25493c849d70
Give a hint about what is the expected the data type of command line options.
gpoirier
parents:
3036
diff
changeset
|
341 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
|
342 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
|
343 break; |
25493c849d70
Give a hint about what is the expected the data type of command line options.
gpoirier
parents:
3036
diff
changeset
|
344 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
|
345 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
|
346 break; |
25493c849d70
Give a hint about what is the expected the data type of command line options.
gpoirier
parents:
3036
diff
changeset
|
347 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
|
348 default: |
25493c849d70
Give a hint about what is the expected the data type of command line options.
gpoirier
parents:
3036
diff
changeset
|
349 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
|
350 break; |
25493c849d70
Give a hint about what is the expected the data type of command line options.
gpoirier
parents:
3036
diff
changeset
|
351 } |
2876 | 352 av_log(av_log_obj, AV_LOG_INFO, "%c", (opt->flags & AV_OPT_FLAG_ENCODING_PARAM) ? 'E' : '.'); |
353 av_log(av_log_obj, AV_LOG_INFO, "%c", (opt->flags & AV_OPT_FLAG_DECODING_PARAM) ? 'D' : '.'); | |
354 av_log(av_log_obj, AV_LOG_INFO, "%c", (opt->flags & AV_OPT_FLAG_VIDEO_PARAM ) ? 'V' : '.'); | |
355 av_log(av_log_obj, AV_LOG_INFO, "%c", (opt->flags & AV_OPT_FLAG_AUDIO_PARAM ) ? 'A' : '.'); | |
356 av_log(av_log_obj, AV_LOG_INFO, "%c", (opt->flags & AV_OPT_FLAG_SUBTITLE_PARAM) ? 'S' : '.'); | |
2967 | 357 |
2888 | 358 if(opt->help) |
359 av_log(av_log_obj, AV_LOG_INFO, " %s", opt->help); | |
360 av_log(av_log_obj, AV_LOG_INFO, "\n"); | |
2873 | 361 } |
362 return 0; | |
363 } | |
3702 | 364 |
3703
301d975b69e3
adds doxygen docs to av_opt_set_defaults. Patch by Takis
gpoirier
parents:
3702
diff
changeset
|
365 /** 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
|
366 * 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
|
367 * array default_val field. |
301d975b69e3
adds doxygen docs to av_opt_set_defaults. Patch by Takis
gpoirier
parents:
3702
diff
changeset
|
368 * |
301d975b69e3
adds doxygen docs to av_opt_set_defaults. Patch by Takis
gpoirier
parents:
3702
diff
changeset
|
369 * @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
|
370 */ |
3702 | 371 void av_opt_set_defaults(void *s) |
372 { | |
373 AVOption *opt = NULL; | |
374 while ((opt = av_next_option(s, opt)) != NULL) { | |
375 switch(opt->type) { | |
376 case FF_OPT_TYPE_CONST: | |
377 /* Nothing to be done here */ | |
378 break; | |
379 case FF_OPT_TYPE_FLAGS: | |
380 case FF_OPT_TYPE_INT: { | |
381 int val; | |
382 val = opt->default_val; | |
383 av_set_int(s, opt->name, val); | |
384 } | |
385 break; | |
386 case FF_OPT_TYPE_FLOAT: { | |
387 double val; | |
388 val = opt->default_val; | |
389 av_set_double(s, opt->name, val); | |
390 } | |
391 break; | |
392 case FF_OPT_TYPE_RATIONAL: { | |
393 AVRational val; | |
394 val = av_d2q(opt->default_val, INT_MAX); | |
395 av_set_q(s, opt->name, val); | |
396 } | |
397 break; | |
398 case FF_OPT_TYPE_STRING: | |
399 /* Cannot set default for string as default_val is of type * double */ | |
400 break; | |
401 default: | |
402 av_log(s, AV_LOG_DEBUG, "AVOption type %d of option %s not implemented yet\n", opt->type, opt->name); | |
403 } | |
404 } | |
405 } | |
406 |