Mercurial > libavcodec.hg
annotate opt.c @ 8419:6a12ba62978a libavcodec
Include "libavutil/common.h" where we use llrint() in case ffmpeg's
own llrint() is to be used.
author | andoma |
---|---|
date | Sun, 21 Dec 2008 21:53:42 +0000 |
parents | 8903ad65c412 |
children | c5302e0ecf4e |
rev | line source |
---|---|
2862 | 1 /* |
2 * AVOptions | |
3 * Copyright (c) 2005 Michael Niedermayer <michaelni@gmx.at> | |
4 * | |
3947
c8c591fe26f8
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
3788
diff
changeset
|
5 * This file is part of FFmpeg. |
c8c591fe26f8
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
3788
diff
changeset
|
6 * |
c8c591fe26f8
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
3788
diff
changeset
|
7 * FFmpeg is free software; you can redistribute it and/or |
2862 | 8 * modify it under the terms of the GNU Lesser General Public |
9 * License as published by the Free Software Foundation; either | |
3947
c8c591fe26f8
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
3788
diff
changeset
|
10 * version 2.1 of the License, or (at your option) any later version. |
2862 | 11 * |
3947
c8c591fe26f8
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
3788
diff
changeset
|
12 * FFmpeg is distributed in the hope that it will be useful, |
2862 | 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
15 * Lesser General Public License for more details. | |
16 * | |
17 * You should have received a copy of the GNU Lesser General Public | |
3947
c8c591fe26f8
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
3788
diff
changeset
|
18 * License along with FFmpeg; if not, write to the Free Software |
3036
0b546eab515d
Update licensing information: The FSF changed postal address.
diego
parents:
2967
diff
changeset
|
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
2862 | 20 */ |
2967 | 21 |
2862 | 22 /** |
23 * @file opt.c | |
24 * AVOptions | |
25 * @author Michael Niedermayer <michaelni@gmx.at> | |
26 */ | |
2967 | 27 |
2862 | 28 #include "avcodec.h" |
2880 | 29 #include "opt.h" |
3786
616a81d04758
Pull out the ff_eval* from the mpegvideo header, as it doesn't belong there and
takis
parents:
3778
diff
changeset
|
30 #include "eval.h" |
8419
6a12ba62978a
Include "libavutil/common.h" where we use llrint() in case ffmpeg's
andoma
parents:
8407
diff
changeset
|
31 #include "libavutil/common.h" |
2862 | 32 |
33 //FIXME order them and do a bin search | |
4628
b0016ed89048
make av_find_opt() available to the public and add a mask+flags parameter to search for specific AVOptions
michael
parents:
4369
diff
changeset
|
34 const AVOption *av_find_opt(void *v, const char *name, const char *unit, int mask, int flags){ |
2862 | 35 AVClass *c= *(AVClass**)v; //FIXME silly way of storing AVClass |
4369
e10acab2322a
Constantize AVOption, solve few warnings, patch from flameeyes@gentoo.org aka "the other Diego"
lu_zero
parents:
3961
diff
changeset
|
36 const AVOption *o= c->option; |
2967 | 37 |
2862 | 38 for(;o && o->name; o++){ |
4748
c6a2b573f259
Fix a bug in av_find_opt(). Because some of the AVOption structures have field
takis
parents:
4747
diff
changeset
|
39 if(!strcmp(o->name, name) && (!unit || (o->unit && !strcmp(o->unit, unit))) && (o->flags & mask) == flags ) |
2862 | 40 return o; |
41 } | |
42 return NULL; | |
43 } | |
44 | |
4369
e10acab2322a
Constantize AVOption, solve few warnings, patch from flameeyes@gentoo.org aka "the other Diego"
lu_zero
parents:
3961
diff
changeset
|
45 const AVOption *av_next_option(void *obj, const AVOption *last){ |
2865
3b999ce45b37
AVOption enumeration support and some flags to classify AVOptions
michael
parents:
2862
diff
changeset
|
46 if(last && last[1].name) return ++last; |
3b999ce45b37
AVOption enumeration support and some flags to classify AVOptions
michael
parents:
2862
diff
changeset
|
47 else if(last) return NULL; |
3b999ce45b37
AVOption enumeration support and some flags to classify AVOptions
michael
parents:
2862
diff
changeset
|
48 else return (*(AVClass**)obj)->option; |
3b999ce45b37
AVOption enumeration support and some flags to classify AVOptions
michael
parents:
2862
diff
changeset
|
49 } |
3b999ce45b37
AVOption enumeration support and some flags to classify AVOptions
michael
parents:
2862
diff
changeset
|
50 |
8344
844463c05193
Implement the av_set_number2() internal function, which makes possible
stefano
parents:
8343
diff
changeset
|
51 static int av_set_number2(void *obj, const char *name, double num, int den, int64_t intnum, const AVOption **o_out){ |
4628
b0016ed89048
make av_find_opt() available to the public and add a mask+flags parameter to search for specific AVOptions
michael
parents:
4369
diff
changeset
|
52 const AVOption *o= av_find_opt(obj, name, NULL, 0, 0); |
2862 | 53 void *dst; |
8344
844463c05193
Implement the av_set_number2() internal function, which makes possible
stefano
parents:
8343
diff
changeset
|
54 if(o_out) |
844463c05193
Implement the av_set_number2() internal function, which makes possible
stefano
parents:
8343
diff
changeset
|
55 *o_out= o; |
2967 | 56 if(!o || o->offset<=0) |
8344
844463c05193
Implement the av_set_number2() internal function, which makes possible
stefano
parents:
8343
diff
changeset
|
57 return AVERROR(ENOENT); |
2967 | 58 |
3735
6c407dc6ab4a
Inform the user that a certain AVOption is out of range.
takis
parents:
3731
diff
changeset
|
59 if(o->max*den < num*intnum || o->min*den > num*intnum) { |
8343
a6ca9f8642d6
Remove ending period in a log message, which was inconsistent with
stefano
parents:
8327
diff
changeset
|
60 av_log(NULL, AV_LOG_ERROR, "Value %lf for parameter '%s' out of range\n", num, name); |
8344
844463c05193
Implement the av_set_number2() internal function, which makes possible
stefano
parents:
8343
diff
changeset
|
61 return AVERROR(ERANGE); |
3735
6c407dc6ab4a
Inform the user that a certain AVOption is out of range.
takis
parents:
3731
diff
changeset
|
62 } |
2967 | 63 |
2862 | 64 dst= ((uint8_t*)obj) + o->offset; |
65 | |
66 switch(o->type){ | |
2967 | 67 case FF_OPT_TYPE_FLAGS: |
6451 | 68 case FF_OPT_TYPE_INT: *(int *)dst= llrint(num/den)*intnum; break; |
69 case FF_OPT_TYPE_INT64: *(int64_t *)dst= llrint(num/den)*intnum; break; | |
2873 | 70 case FF_OPT_TYPE_FLOAT: *(float *)dst= num*intnum/den; break; |
71 case FF_OPT_TYPE_DOUBLE:*(double *)dst= num*intnum/den; break; | |
2862 | 72 case FF_OPT_TYPE_RATIONAL: |
2873 | 73 if((int)num == num) *(AVRational*)dst= (AVRational){num*intnum, den}; |
74 else *(AVRational*)dst= av_d2q(num*intnum/den, 1<<24); | |
6015
bb4f24c580f5
Add a missing break, before av_set_number would always return NULL for
reimar
parents:
5977
diff
changeset
|
75 break; |
2862 | 76 default: |
8344
844463c05193
Implement the av_set_number2() internal function, which makes possible
stefano
parents:
8343
diff
changeset
|
77 return AVERROR(EINVAL); |
2862 | 78 } |
8344
844463c05193
Implement the av_set_number2() internal function, which makes possible
stefano
parents:
8343
diff
changeset
|
79 return 0; |
844463c05193
Implement the av_set_number2() internal function, which makes possible
stefano
parents:
8343
diff
changeset
|
80 } |
844463c05193
Implement the av_set_number2() internal function, which makes possible
stefano
parents:
8343
diff
changeset
|
81 |
844463c05193
Implement the av_set_number2() internal function, which makes possible
stefano
parents:
8343
diff
changeset
|
82 static const AVOption *av_set_number(void *obj, const char *name, double num, int den, int64_t intnum){ |
844463c05193
Implement the av_set_number2() internal function, which makes possible
stefano
parents:
8343
diff
changeset
|
83 const AVOption *o = NULL; |
844463c05193
Implement the av_set_number2() internal function, which makes possible
stefano
parents:
8343
diff
changeset
|
84 if (av_set_number2(obj, name, num, den, intnum, &o) < 0) |
844463c05193
Implement the av_set_number2() internal function, which makes possible
stefano
parents:
8343
diff
changeset
|
85 return NULL; |
844463c05193
Implement the av_set_number2() internal function, which makes possible
stefano
parents:
8343
diff
changeset
|
86 else |
844463c05193
Implement the av_set_number2() internal function, which makes possible
stefano
parents:
8343
diff
changeset
|
87 return o; |
2862 | 88 } |
89 | |
7129 | 90 static const double const_values[]={ |
3778 | 91 M_PI, |
92 M_E, | |
93 FF_QP2LAMBDA, | |
94 0 | |
95 }; | |
96 | |
7129 | 97 static const char * const const_names[]={ |
3778 | 98 "PI", |
99 "E", | |
100 "QP2LAMBDA", | |
101 0 | |
102 }; | |
103 | |
6034
72bb141d9c05
Add FF_OPT_TYPE_BINARY and use it to add a cryptokey option
reimar
parents:
6015
diff
changeset
|
104 static int hexchar2int(char c) { |
72bb141d9c05
Add FF_OPT_TYPE_BINARY and use it to add a cryptokey option
reimar
parents:
6015
diff
changeset
|
105 if (c >= '0' && c <= '9') return c - '0'; |
72bb141d9c05
Add FF_OPT_TYPE_BINARY and use it to add a cryptokey option
reimar
parents:
6015
diff
changeset
|
106 if (c >= 'a' && c <= 'f') return c - 'a' + 10; |
72bb141d9c05
Add FF_OPT_TYPE_BINARY and use it to add a cryptokey option
reimar
parents:
6015
diff
changeset
|
107 if (c >= 'A' && c <= 'F') return c - 'A' + 10; |
72bb141d9c05
Add FF_OPT_TYPE_BINARY and use it to add a cryptokey option
reimar
parents:
6015
diff
changeset
|
108 return -1; |
72bb141d9c05
Add FF_OPT_TYPE_BINARY and use it to add a cryptokey option
reimar
parents:
6015
diff
changeset
|
109 } |
72bb141d9c05
Add FF_OPT_TYPE_BINARY and use it to add a cryptokey option
reimar
parents:
6015
diff
changeset
|
110 |
8356 | 111 int av_set_string3(void *obj, const char *name, const char *val, int alloc, const AVOption **o_out){ |
112 int ret; | |
4628
b0016ed89048
make av_find_opt() available to the public and add a mask+flags parameter to search for specific AVOptions
michael
parents:
4369
diff
changeset
|
113 const AVOption *o= av_find_opt(obj, name, NULL, 0, 0); |
8356 | 114 if (o_out) |
115 *o_out = o; | |
116 if(!o) | |
117 return AVERROR(ENOENT); | |
118 if(!val || o->offset<=0) | |
119 return AVERROR(EINVAL); | |
120 | |
6034
72bb141d9c05
Add FF_OPT_TYPE_BINARY and use it to add a cryptokey option
reimar
parents:
6015
diff
changeset
|
121 if(o->type == FF_OPT_TYPE_BINARY){ |
72bb141d9c05
Add FF_OPT_TYPE_BINARY and use it to add a cryptokey option
reimar
parents:
6015
diff
changeset
|
122 uint8_t **dst = (uint8_t **)(((uint8_t*)obj) + o->offset); |
72bb141d9c05
Add FF_OPT_TYPE_BINARY and use it to add a cryptokey option
reimar
parents:
6015
diff
changeset
|
123 int *lendst = (int *)(dst + 1); |
72bb141d9c05
Add FF_OPT_TYPE_BINARY and use it to add a cryptokey option
reimar
parents:
6015
diff
changeset
|
124 uint8_t *bin, *ptr; |
72bb141d9c05
Add FF_OPT_TYPE_BINARY and use it to add a cryptokey option
reimar
parents:
6015
diff
changeset
|
125 int len = strlen(val); |
72bb141d9c05
Add FF_OPT_TYPE_BINARY and use it to add a cryptokey option
reimar
parents:
6015
diff
changeset
|
126 av_freep(dst); |
72bb141d9c05
Add FF_OPT_TYPE_BINARY and use it to add a cryptokey option
reimar
parents:
6015
diff
changeset
|
127 *lendst = 0; |
8356 | 128 if (len & 1) return AVERROR(EINVAL); |
6034
72bb141d9c05
Add FF_OPT_TYPE_BINARY and use it to add a cryptokey option
reimar
parents:
6015
diff
changeset
|
129 len /= 2; |
72bb141d9c05
Add FF_OPT_TYPE_BINARY and use it to add a cryptokey option
reimar
parents:
6015
diff
changeset
|
130 ptr = bin = av_malloc(len); |
72bb141d9c05
Add FF_OPT_TYPE_BINARY and use it to add a cryptokey option
reimar
parents:
6015
diff
changeset
|
131 while (*val) { |
72bb141d9c05
Add FF_OPT_TYPE_BINARY and use it to add a cryptokey option
reimar
parents:
6015
diff
changeset
|
132 int a = hexchar2int(*val++); |
72bb141d9c05
Add FF_OPT_TYPE_BINARY and use it to add a cryptokey option
reimar
parents:
6015
diff
changeset
|
133 int b = hexchar2int(*val++); |
72bb141d9c05
Add FF_OPT_TYPE_BINARY and use it to add a cryptokey option
reimar
parents:
6015
diff
changeset
|
134 if (a < 0 || b < 0) { |
72bb141d9c05
Add FF_OPT_TYPE_BINARY and use it to add a cryptokey option
reimar
parents:
6015
diff
changeset
|
135 av_free(bin); |
8356 | 136 return AVERROR(EINVAL); |
6034
72bb141d9c05
Add FF_OPT_TYPE_BINARY and use it to add a cryptokey option
reimar
parents:
6015
diff
changeset
|
137 } |
72bb141d9c05
Add FF_OPT_TYPE_BINARY and use it to add a cryptokey option
reimar
parents:
6015
diff
changeset
|
138 *ptr++ = (a << 4) | b; |
72bb141d9c05
Add FF_OPT_TYPE_BINARY and use it to add a cryptokey option
reimar
parents:
6015
diff
changeset
|
139 } |
72bb141d9c05
Add FF_OPT_TYPE_BINARY and use it to add a cryptokey option
reimar
parents:
6015
diff
changeset
|
140 *dst = bin; |
72bb141d9c05
Add FF_OPT_TYPE_BINARY and use it to add a cryptokey option
reimar
parents:
6015
diff
changeset
|
141 *lendst = len; |
8356 | 142 return 0; |
6034
72bb141d9c05
Add FF_OPT_TYPE_BINARY and use it to add a cryptokey option
reimar
parents:
6015
diff
changeset
|
143 } |
2862 | 144 if(o->type != FF_OPT_TYPE_STRING){ |
6853 | 145 int notfirst=0; |
2862 | 146 for(;;){ |
147 int i; | |
3778 | 148 char buf[256]; |
2874
b6def74f5811
flags and named constants with type checking of course for AVOption
michael
parents:
2873
diff
changeset
|
149 int cmd=0; |
b6def74f5811
flags and named constants with type checking of course for AVOption
michael
parents:
2873
diff
changeset
|
150 double d; |
6353 | 151 const char *error = NULL; |
2862 | 152 |
2874
b6def74f5811
flags and named constants with type checking of course for AVOption
michael
parents:
2873
diff
changeset
|
153 if(*val == '+' || *val == '-') |
b6def74f5811
flags and named constants with type checking of course for AVOption
michael
parents:
2873
diff
changeset
|
154 cmd= *(val++); |
2967 | 155 |
2874
b6def74f5811
flags and named constants with type checking of course for AVOption
michael
parents:
2873
diff
changeset
|
156 for(i=0; i<sizeof(buf)-1 && val[i] && val[i]!='+' && val[i]!='-'; i++) |
2862 | 157 buf[i]= val[i]; |
158 buf[i]=0; | |
2967 | 159 |
3778 | 160 d = ff_eval2(buf, const_values, const_names, NULL, NULL, NULL, NULL, NULL, &error); |
161 if(isnan(d)) { | |
4628
b0016ed89048
make av_find_opt() available to the public and add a mask+flags parameter to search for specific AVOptions
michael
parents:
4369
diff
changeset
|
162 const AVOption *o_named= av_find_opt(obj, buf, o->unit, 0, 0); |
2967 | 163 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
|
164 d= o_named->default_val; |
b6def74f5811
flags and named constants with type checking of course for AVOption
michael
parents:
2873
diff
changeset
|
165 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
|
166 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
|
167 else if(!strcmp(buf, "min" )) d= o->min; |
4747
66aff3b71861
add 'all' and 'none' options for partitions config
gpoirier
parents:
4629
diff
changeset
|
168 else if(!strcmp(buf, "none" )) d= 0; |
66aff3b71861
add 'all' and 'none' options for partitions config
gpoirier
parents:
4629
diff
changeset
|
169 else if(!strcmp(buf, "all" )) d= ~0; |
3778 | 170 else { |
6794 | 171 if (error) |
3778 | 172 av_log(NULL, AV_LOG_ERROR, "Unable to parse option value \"%s\": %s\n", val, error); |
8356 | 173 return AVERROR(EINVAL); |
3778 | 174 } |
2862 | 175 } |
2874
b6def74f5811
flags and named constants with type checking of course for AVOption
michael
parents:
2873
diff
changeset
|
176 if(o->type == FF_OPT_TYPE_FLAGS){ |
b6def74f5811
flags and named constants with type checking of course for AVOption
michael
parents:
2873
diff
changeset
|
177 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
|
178 else if(cmd=='-') d= av_get_int(obj, name, NULL) &~(int64_t)d; |
6845 | 179 }else{ |
6853 | 180 if (cmd=='+') d= notfirst*av_get_double(obj, name, NULL) + d; |
181 else if(cmd=='-') d= notfirst*av_get_double(obj, name, NULL) - d; | |
6845 | 182 } |
2862 | 183 |
8356 | 184 if ((ret = av_set_number2(obj, name, d, 1, 1, o_out)) < 0) |
185 return ret; | |
6797
51bbc2f553e2
Update offset in the option string later, to have a better error message.
benoit
parents:
6794
diff
changeset
|
186 val+= i; |
2862 | 187 if(!*val) |
8356 | 188 return 0; |
6853 | 189 notfirst=1; |
2862 | 190 } |
8356 | 191 return AVERROR(EINVAL); |
2862 | 192 } |
2967 | 193 |
7224 | 194 if(alloc){ |
7271
8c58eeb20826
Fix the logic to access the location of a string to free when setting
stefano
parents:
7224
diff
changeset
|
195 av_free(*(void**)(((uint8_t*)obj) + o->offset)); |
7224 | 196 val= av_strdup(val); |
197 } | |
198 | |
5976
58ee364cd8fb
make the AVOption code work with strings instead of crash
michael
parents:
5215
diff
changeset
|
199 memcpy(((uint8_t*)obj) + o->offset, &val, sizeof(val)); |
8356 | 200 return 0; |
201 } | |
202 | |
8407
8903ad65c412
Put under #if LIBAVCODEC_VERSION_MAJOR < 53 the deprecated functions
stefano
parents:
8406
diff
changeset
|
203 #if LIBAVCODEC_VERSION_MAJOR < 53 |
8356 | 204 const AVOption *av_set_string2(void *obj, const char *name, const char *val, int alloc){ |
205 const AVOption *o; | |
206 if (av_set_string3(obj, name, val, alloc, &o) < 0) | |
207 return NULL; | |
2873 | 208 return o; |
2862 | 209 } |
210 | |
7224 | 211 const AVOption *av_set_string(void *obj, const char *name, const char *val){ |
8406
ea27308fa023
Remove calls to deprecated av_set_string2() with calls to
stefano
parents:
8356
diff
changeset
|
212 const AVOption *o; |
ea27308fa023
Remove calls to deprecated av_set_string2() with calls to
stefano
parents:
8356
diff
changeset
|
213 if (av_set_string3(obj, name, val, 0, &o) < 0) |
ea27308fa023
Remove calls to deprecated av_set_string2() with calls to
stefano
parents:
8356
diff
changeset
|
214 return NULL; |
ea27308fa023
Remove calls to deprecated av_set_string2() with calls to
stefano
parents:
8356
diff
changeset
|
215 return o; |
7224 | 216 } |
8407
8903ad65c412
Put under #if LIBAVCODEC_VERSION_MAJOR < 53 the deprecated functions
stefano
parents:
8406
diff
changeset
|
217 #endif |
7224 | 218 |
4369
e10acab2322a
Constantize AVOption, solve few warnings, patch from flameeyes@gentoo.org aka "the other Diego"
lu_zero
parents:
3961
diff
changeset
|
219 const AVOption *av_set_double(void *obj, const char *name, double n){ |
2862 | 220 return av_set_number(obj, name, n, 1, 1); |
221 } | |
222 | |
4369
e10acab2322a
Constantize AVOption, solve few warnings, patch from flameeyes@gentoo.org aka "the other Diego"
lu_zero
parents:
3961
diff
changeset
|
223 const AVOption *av_set_q(void *obj, const char *name, AVRational n){ |
2862 | 224 return av_set_number(obj, name, n.num, n.den, 1); |
225 } | |
226 | |
4369
e10acab2322a
Constantize AVOption, solve few warnings, patch from flameeyes@gentoo.org aka "the other Diego"
lu_zero
parents:
3961
diff
changeset
|
227 const AVOption *av_set_int(void *obj, const char *name, int64_t n){ |
2862 | 228 return av_set_number(obj, name, 1, 1, n); |
229 } | |
230 | |
2873 | 231 /** |
2967 | 232 * |
2873 | 233 * @param buf a buffer which is used for returning non string values as strings, can be NULL |
234 * @param buf_len allocated length in bytes of buf | |
235 */ | |
4369
e10acab2322a
Constantize AVOption, solve few warnings, patch from flameeyes@gentoo.org aka "the other Diego"
lu_zero
parents:
3961
diff
changeset
|
236 const char *av_get_string(void *obj, const char *name, const AVOption **o_out, char *buf, int buf_len){ |
4628
b0016ed89048
make av_find_opt() available to the public and add a mask+flags parameter to search for specific AVOptions
michael
parents:
4369
diff
changeset
|
237 const AVOption *o= av_find_opt(obj, name, NULL, 0, 0); |
2873 | 238 void *dst; |
6034
72bb141d9c05
Add FF_OPT_TYPE_BINARY and use it to add a cryptokey option
reimar
parents:
6015
diff
changeset
|
239 uint8_t *bin; |
72bb141d9c05
Add FF_OPT_TYPE_BINARY and use it to add a cryptokey option
reimar
parents:
6015
diff
changeset
|
240 int len, i; |
2862 | 241 if(!o || o->offset<=0) |
242 return NULL; | |
2873 | 243 if(o->type != FF_OPT_TYPE_STRING && (!buf || !buf_len)) |
2862 | 244 return NULL; |
245 | |
2873 | 246 dst= ((uint8_t*)obj) + o->offset; |
247 if(o_out) *o_out= o; | |
2967 | 248 |
2873 | 249 switch(o->type){ |
2874
b6def74f5811
flags and named constants with type checking of course for AVOption
michael
parents:
2873
diff
changeset
|
250 case FF_OPT_TYPE_FLAGS: snprintf(buf, buf_len, "0x%08X",*(int *)dst);break; |
2873 | 251 case FF_OPT_TYPE_INT: snprintf(buf, buf_len, "%d" , *(int *)dst);break; |
2962 | 252 case FF_OPT_TYPE_INT64: snprintf(buf, buf_len, "%"PRId64, *(int64_t*)dst);break; |
2873 | 253 case FF_OPT_TYPE_FLOAT: snprintf(buf, buf_len, "%f" , *(float *)dst);break; |
254 case FF_OPT_TYPE_DOUBLE: snprintf(buf, buf_len, "%f" , *(double *)dst);break; | |
255 case FF_OPT_TYPE_RATIONAL: snprintf(buf, buf_len, "%d/%d", ((AVRational*)dst)->num, ((AVRational*)dst)->den);break; | |
5977 | 256 case FF_OPT_TYPE_STRING: return *(void**)dst; |
6034
72bb141d9c05
Add FF_OPT_TYPE_BINARY and use it to add a cryptokey option
reimar
parents:
6015
diff
changeset
|
257 case FF_OPT_TYPE_BINARY: |
72bb141d9c05
Add FF_OPT_TYPE_BINARY and use it to add a cryptokey option
reimar
parents:
6015
diff
changeset
|
258 len = *(int*)(((uint8_t *)dst) + sizeof(uint8_t *)); |
72bb141d9c05
Add FF_OPT_TYPE_BINARY and use it to add a cryptokey option
reimar
parents:
6015
diff
changeset
|
259 if(len >= (buf_len + 1)/2) return NULL; |
72bb141d9c05
Add FF_OPT_TYPE_BINARY and use it to add a cryptokey option
reimar
parents:
6015
diff
changeset
|
260 bin = *(uint8_t**)dst; |
72bb141d9c05
Add FF_OPT_TYPE_BINARY and use it to add a cryptokey option
reimar
parents:
6015
diff
changeset
|
261 for(i = 0; i < len; i++) snprintf(buf + i*2, 3, "%02X", bin[i]); |
72bb141d9c05
Add FF_OPT_TYPE_BINARY and use it to add a cryptokey option
reimar
parents:
6015
diff
changeset
|
262 break; |
2873 | 263 default: return NULL; |
264 } | |
265 return buf; | |
2862 | 266 } |
267 | |
4369
e10acab2322a
Constantize AVOption, solve few warnings, patch from flameeyes@gentoo.org aka "the other Diego"
lu_zero
parents:
3961
diff
changeset
|
268 static int av_get_number(void *obj, const char *name, const AVOption **o_out, double *num, int *den, int64_t *intnum){ |
4628
b0016ed89048
make av_find_opt() available to the public and add a mask+flags parameter to search for specific AVOptions
michael
parents:
4369
diff
changeset
|
269 const AVOption *o= av_find_opt(obj, name, NULL, 0, 0); |
2862 | 270 void *dst; |
271 if(!o || o->offset<=0) | |
2873 | 272 goto error; |
2862 | 273 |
274 dst= ((uint8_t*)obj) + o->offset; | |
275 | |
2873 | 276 if(o_out) *o_out= o; |
277 | |
2862 | 278 switch(o->type){ |
6451 | 279 case FF_OPT_TYPE_FLAGS: *intnum= *(unsigned int*)dst;return 0; |
2873 | 280 case FF_OPT_TYPE_INT: *intnum= *(int *)dst;return 0; |
281 case FF_OPT_TYPE_INT64: *intnum= *(int64_t*)dst;return 0; | |
282 case FF_OPT_TYPE_FLOAT: *num= *(float *)dst;return 0; | |
283 case FF_OPT_TYPE_DOUBLE: *num= *(double *)dst;return 0; | |
2967 | 284 case FF_OPT_TYPE_RATIONAL: *intnum= ((AVRational*)dst)->num; |
2873 | 285 *den = ((AVRational*)dst)->den; |
286 return 0; | |
2862 | 287 } |
2873 | 288 error: |
289 *den=*intnum=0; | |
290 return -1; | |
2862 | 291 } |
2873 | 292 |
4369
e10acab2322a
Constantize AVOption, solve few warnings, patch from flameeyes@gentoo.org aka "the other Diego"
lu_zero
parents:
3961
diff
changeset
|
293 double av_get_double(void *obj, const char *name, const AVOption **o_out){ |
2873 | 294 int64_t intnum=1; |
295 double num=1; | |
296 int den=1; | |
297 | |
298 av_get_number(obj, name, o_out, &num, &den, &intnum); | |
299 return num*intnum/den; | |
300 } | |
301 | |
4369
e10acab2322a
Constantize AVOption, solve few warnings, patch from flameeyes@gentoo.org aka "the other Diego"
lu_zero
parents:
3961
diff
changeset
|
302 AVRational av_get_q(void *obj, const char *name, const AVOption **o_out){ |
2873 | 303 int64_t intnum=1; |
304 double num=1; | |
305 int den=1; | |
306 | |
307 av_get_number(obj, name, o_out, &num, &den, &intnum); | |
308 if(num == 1.0 && (int)intnum == intnum) | |
309 return (AVRational){intnum, den}; | |
310 else | |
311 return av_d2q(num*intnum/den, 1<<24); | |
312 } | |
313 | |
4369
e10acab2322a
Constantize AVOption, solve few warnings, patch from flameeyes@gentoo.org aka "the other Diego"
lu_zero
parents:
3961
diff
changeset
|
314 int64_t av_get_int(void *obj, const char *name, const AVOption **o_out){ |
2873 | 315 int64_t intnum=1; |
316 double num=1; | |
317 int den=1; | |
318 | |
319 av_get_number(obj, name, o_out, &num, &den, &intnum); | |
320 return num*intnum/den; | |
321 } | |
322 | |
4369
e10acab2322a
Constantize AVOption, solve few warnings, patch from flameeyes@gentoo.org aka "the other Diego"
lu_zero
parents:
3961
diff
changeset
|
323 static void opt_list(void *obj, void *av_log_obj, const char *unit) |
3788
484d719a2028
Reformat the output of the list of available AVOptions, by indenting the
takis
parents:
3786
diff
changeset
|
324 { |
4369
e10acab2322a
Constantize AVOption, solve few warnings, patch from flameeyes@gentoo.org aka "the other Diego"
lu_zero
parents:
3961
diff
changeset
|
325 const AVOption *opt=NULL; |
2967 | 326 |
2873 | 327 while((opt= av_next_option(obj, opt))){ |
328 if(!(opt->flags & (AV_OPT_FLAG_ENCODING_PARAM|AV_OPT_FLAG_DECODING_PARAM))) | |
329 continue; | |
2967 | 330 |
3788
484d719a2028
Reformat the output of the list of available AVOptions, by indenting the
takis
parents:
3786
diff
changeset
|
331 /* Don't print CONST's on level one. |
484d719a2028
Reformat the output of the list of available AVOptions, by indenting the
takis
parents:
3786
diff
changeset
|
332 * Don't print anything but CONST's on level two. |
484d719a2028
Reformat the output of the list of available AVOptions, by indenting the
takis
parents:
3786
diff
changeset
|
333 * Only print items from the requested unit. |
484d719a2028
Reformat the output of the list of available AVOptions, by indenting the
takis
parents:
3786
diff
changeset
|
334 */ |
484d719a2028
Reformat the output of the list of available AVOptions, by indenting the
takis
parents:
3786
diff
changeset
|
335 if (!unit && opt->type==FF_OPT_TYPE_CONST) |
484d719a2028
Reformat the output of the list of available AVOptions, by indenting the
takis
parents:
3786
diff
changeset
|
336 continue; |
484d719a2028
Reformat the output of the list of available AVOptions, by indenting the
takis
parents:
3786
diff
changeset
|
337 else if (unit && opt->type!=FF_OPT_TYPE_CONST) |
484d719a2028
Reformat the output of the list of available AVOptions, by indenting the
takis
parents:
3786
diff
changeset
|
338 continue; |
484d719a2028
Reformat the output of the list of available AVOptions, by indenting the
takis
parents:
3786
diff
changeset
|
339 else if (unit && opt->type==FF_OPT_TYPE_CONST && strcmp(unit, opt->unit)) |
484d719a2028
Reformat the output of the list of available AVOptions, by indenting the
takis
parents:
3786
diff
changeset
|
340 continue; |
484d719a2028
Reformat the output of the list of available AVOptions, by indenting the
takis
parents:
3786
diff
changeset
|
341 else if (unit && opt->type == FF_OPT_TYPE_CONST) |
484d719a2028
Reformat the output of the list of available AVOptions, by indenting the
takis
parents:
3786
diff
changeset
|
342 av_log(av_log_obj, AV_LOG_INFO, " %-15s ", opt->name); |
484d719a2028
Reformat the output of the list of available AVOptions, by indenting the
takis
parents:
3786
diff
changeset
|
343 else |
484d719a2028
Reformat the output of the list of available AVOptions, by indenting the
takis
parents:
3786
diff
changeset
|
344 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
|
345 |
25493c849d70
Give a hint about what is the expected the data type of command line options.
gpoirier
parents:
3036
diff
changeset
|
346 switch( opt->type ) |
25493c849d70
Give a hint about what is the expected the data type of command line options.
gpoirier
parents:
3036
diff
changeset
|
347 { |
25493c849d70
Give a hint about what is the expected the data type of command line options.
gpoirier
parents:
3036
diff
changeset
|
348 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
|
349 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
|
350 break; |
25493c849d70
Give a hint about what is the expected the data type of command line options.
gpoirier
parents:
3036
diff
changeset
|
351 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
|
352 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
|
353 break; |
25493c849d70
Give a hint about what is the expected the data type of command line options.
gpoirier
parents:
3036
diff
changeset
|
354 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
|
355 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
|
356 break; |
25493c849d70
Give a hint about what is the expected the data type of command line options.
gpoirier
parents:
3036
diff
changeset
|
357 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
|
358 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
|
359 break; |
25493c849d70
Give a hint about what is the expected the data type of command line options.
gpoirier
parents:
3036
diff
changeset
|
360 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
|
361 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
|
362 break; |
25493c849d70
Give a hint about what is the expected the data type of command line options.
gpoirier
parents:
3036
diff
changeset
|
363 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
|
364 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
|
365 break; |
25493c849d70
Give a hint about what is the expected the data type of command line options.
gpoirier
parents:
3036
diff
changeset
|
366 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
|
367 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
|
368 break; |
6034
72bb141d9c05
Add FF_OPT_TYPE_BINARY and use it to add a cryptokey option
reimar
parents:
6015
diff
changeset
|
369 case FF_OPT_TYPE_BINARY: |
72bb141d9c05
Add FF_OPT_TYPE_BINARY and use it to add a cryptokey option
reimar
parents:
6015
diff
changeset
|
370 av_log( av_log_obj, AV_LOG_INFO, "%-7s ", "<binary>" ); |
72bb141d9c05
Add FF_OPT_TYPE_BINARY and use it to add a cryptokey option
reimar
parents:
6015
diff
changeset
|
371 break; |
3141
25493c849d70
Give a hint about what is the expected the data type of command line options.
gpoirier
parents:
3036
diff
changeset
|
372 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
|
373 default: |
25493c849d70
Give a hint about what is the expected the data type of command line options.
gpoirier
parents:
3036
diff
changeset
|
374 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
|
375 break; |
25493c849d70
Give a hint about what is the expected the data type of command line options.
gpoirier
parents:
3036
diff
changeset
|
376 } |
2876 | 377 av_log(av_log_obj, AV_LOG_INFO, "%c", (opt->flags & AV_OPT_FLAG_ENCODING_PARAM) ? 'E' : '.'); |
378 av_log(av_log_obj, AV_LOG_INFO, "%c", (opt->flags & AV_OPT_FLAG_DECODING_PARAM) ? 'D' : '.'); | |
379 av_log(av_log_obj, AV_LOG_INFO, "%c", (opt->flags & AV_OPT_FLAG_VIDEO_PARAM ) ? 'V' : '.'); | |
380 av_log(av_log_obj, AV_LOG_INFO, "%c", (opt->flags & AV_OPT_FLAG_AUDIO_PARAM ) ? 'A' : '.'); | |
381 av_log(av_log_obj, AV_LOG_INFO, "%c", (opt->flags & AV_OPT_FLAG_SUBTITLE_PARAM) ? 'S' : '.'); | |
2967 | 382 |
2888 | 383 if(opt->help) |
384 av_log(av_log_obj, AV_LOG_INFO, " %s", opt->help); | |
385 av_log(av_log_obj, AV_LOG_INFO, "\n"); | |
3788
484d719a2028
Reformat the output of the list of available AVOptions, by indenting the
takis
parents:
3786
diff
changeset
|
386 if (opt->unit && opt->type != FF_OPT_TYPE_CONST) { |
484d719a2028
Reformat the output of the list of available AVOptions, by indenting the
takis
parents:
3786
diff
changeset
|
387 opt_list(obj, av_log_obj, opt->unit); |
484d719a2028
Reformat the output of the list of available AVOptions, by indenting the
takis
parents:
3786
diff
changeset
|
388 } |
2873 | 389 } |
3788
484d719a2028
Reformat the output of the list of available AVOptions, by indenting the
takis
parents:
3786
diff
changeset
|
390 } |
484d719a2028
Reformat the output of the list of available AVOptions, by indenting the
takis
parents:
3786
diff
changeset
|
391 |
484d719a2028
Reformat the output of the list of available AVOptions, by indenting the
takis
parents:
3786
diff
changeset
|
392 int av_opt_show(void *obj, void *av_log_obj){ |
484d719a2028
Reformat the output of the list of available AVOptions, by indenting the
takis
parents:
3786
diff
changeset
|
393 if(!obj) |
484d719a2028
Reformat the output of the list of available AVOptions, by indenting the
takis
parents:
3786
diff
changeset
|
394 return -1; |
484d719a2028
Reformat the output of the list of available AVOptions, by indenting the
takis
parents:
3786
diff
changeset
|
395 |
484d719a2028
Reformat the output of the list of available AVOptions, by indenting the
takis
parents:
3786
diff
changeset
|
396 av_log(av_log_obj, AV_LOG_INFO, "%s AVOptions:\n", (*(AVClass**)obj)->class_name); |
484d719a2028
Reformat the output of the list of available AVOptions, by indenting the
takis
parents:
3786
diff
changeset
|
397 |
484d719a2028
Reformat the output of the list of available AVOptions, by indenting the
takis
parents:
3786
diff
changeset
|
398 opt_list(obj, av_log_obj, NULL); |
484d719a2028
Reformat the output of the list of available AVOptions, by indenting the
takis
parents:
3786
diff
changeset
|
399 |
2873 | 400 return 0; |
401 } | |
3702 | 402 |
3703
301d975b69e3
adds doxygen docs to av_opt_set_defaults. Patch by Takis
gpoirier
parents:
3702
diff
changeset
|
403 /** 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
|
404 * 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
|
405 * array default_val field. |
301d975b69e3
adds doxygen docs to av_opt_set_defaults. Patch by Takis
gpoirier
parents:
3702
diff
changeset
|
406 * |
301d975b69e3
adds doxygen docs to av_opt_set_defaults. Patch by Takis
gpoirier
parents:
3702
diff
changeset
|
407 * @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
|
408 */ |
4629
2faa1399dd68
add av_opt_set_defaults2() which sets just defaults from AVOptions whos flags match a user specified & mask = flags
michael
parents:
4628
diff
changeset
|
409 void av_opt_set_defaults2(void *s, int mask, int flags) |
3702 | 410 { |
4369
e10acab2322a
Constantize AVOption, solve few warnings, patch from flameeyes@gentoo.org aka "the other Diego"
lu_zero
parents:
3961
diff
changeset
|
411 const AVOption *opt = NULL; |
3702 | 412 while ((opt = av_next_option(s, opt)) != NULL) { |
4629
2faa1399dd68
add av_opt_set_defaults2() which sets just defaults from AVOptions whos flags match a user specified & mask = flags
michael
parents:
4628
diff
changeset
|
413 if((opt->flags & mask) != flags) |
2faa1399dd68
add av_opt_set_defaults2() which sets just defaults from AVOptions whos flags match a user specified & mask = flags
michael
parents:
4628
diff
changeset
|
414 continue; |
3702 | 415 switch(opt->type) { |
416 case FF_OPT_TYPE_CONST: | |
417 /* Nothing to be done here */ | |
418 break; | |
419 case FF_OPT_TYPE_FLAGS: | |
420 case FF_OPT_TYPE_INT: { | |
421 int val; | |
422 val = opt->default_val; | |
423 av_set_int(s, opt->name, val); | |
424 } | |
425 break; | |
8262 | 426 case FF_OPT_TYPE_INT64: |
427 if((double)(opt->default_val+0.6) == opt->default_val) | |
428 av_log(s, AV_LOG_DEBUG, "loss of precission in default of %s\n", opt->name); | |
429 av_set_int(s, opt->name, opt->default_val); | |
430 break; | |
3702 | 431 case FF_OPT_TYPE_FLOAT: { |
432 double val; | |
433 val = opt->default_val; | |
434 av_set_double(s, opt->name, val); | |
435 } | |
436 break; | |
437 case FF_OPT_TYPE_RATIONAL: { | |
438 AVRational val; | |
439 val = av_d2q(opt->default_val, INT_MAX); | |
440 av_set_q(s, opt->name, val); | |
441 } | |
442 break; | |
443 case FF_OPT_TYPE_STRING: | |
6034
72bb141d9c05
Add FF_OPT_TYPE_BINARY and use it to add a cryptokey option
reimar
parents:
6015
diff
changeset
|
444 case FF_OPT_TYPE_BINARY: |
3702 | 445 /* Cannot set default for string as default_val is of type * double */ |
446 break; | |
447 default: | |
448 av_log(s, AV_LOG_DEBUG, "AVOption type %d of option %s not implemented yet\n", opt->type, opt->name); | |
449 } | |
450 } | |
451 } | |
452 | |
4629
2faa1399dd68
add av_opt_set_defaults2() which sets just defaults from AVOptions whos flags match a user specified & mask = flags
michael
parents:
4628
diff
changeset
|
453 void av_opt_set_defaults(void *s){ |
2faa1399dd68
add av_opt_set_defaults2() which sets just defaults from AVOptions whos flags match a user specified & mask = flags
michael
parents:
4628
diff
changeset
|
454 av_opt_set_defaults2(s, 0, 0); |
2faa1399dd68
add av_opt_set_defaults2() which sets just defaults from AVOptions whos flags match a user specified & mask = flags
michael
parents:
4628
diff
changeset
|
455 } |
2faa1399dd68
add av_opt_set_defaults2() which sets just defaults from AVOptions whos flags match a user specified & mask = flags
michael
parents:
4628
diff
changeset
|
456 |