Mercurial > libavcodec.hg
annotate opts.c @ 1124:64c7c76ed17c libavcodec
* 'externaly' visible option list begins avoptions_ prefix
* fixed FLAG AVOption
author | kabi |
---|---|
date | Mon, 10 Mar 2003 11:48:33 +0000 |
parents | e4762efc3617 |
children | 0980ae063f4e |
rev | line source |
---|---|
962 | 1 /* |
2 * LGPL | |
3 */ | |
4 | |
1106 | 5 /** |
6 * @file opts.c | |
7 * options parser. | |
962 | 8 * typical parsed command line: |
9 * msmpeg4:bitrate=720000:qmax=16 | |
10 * | |
11 */ | |
12 | |
13 #include "avcodec.h" | |
1058 | 14 |
1124
64c7c76ed17c
* 'externaly' visible option list begins avoptions_ prefix
kabi
parents:
1114
diff
changeset
|
15 const AVOption avoptions_common[] = { |
1114 | 16 AVOPTION_CODEC_FLAG("bit_exact", "use only bit-exact stuff", flags, CODEC_FLAG_BITEXACT, 0), |
17 AVOPTION_CODEC_FLAG("mm_force", "force mm flags", dsp_mask, FF_MM_FORCE, 0), | |
18 #ifdef HAVE_MMX | |
19 AVOPTION_CODEC_FLAG("mm_mmx", "mask MMX feature", dsp_mask, FF_MM_MMX, 0), | |
20 AVOPTION_CODEC_FLAG("mm_3dnow", "mask 3DNow feature", dsp_mask, FF_MM_3DNOW, 0), | |
21 AVOPTION_CODEC_FLAG("mm_mmxext", "mask MMXEXT (MMX2) feature", dsp_mask, FF_MM_MMXEXT, 0), | |
22 AVOPTION_CODEC_FLAG("mm_sse", "mask SSE feature", dsp_mask, FF_MM_SSE, 0), | |
23 AVOPTION_CODEC_FLAG("mm_sse2", "mask SSE2 feature", dsp_mask, FF_MM_SSE2, 0), | |
24 #endif | |
1058 | 25 AVOPTION_END() |
26 }; | |
962 | 27 |
1124
64c7c76ed17c
* 'externaly' visible option list begins avoptions_ prefix
kabi
parents:
1114
diff
changeset
|
28 const AVOption avoptions_workaround_bug[] = { |
64c7c76ed17c
* 'externaly' visible option list begins avoptions_ prefix
kabi
parents:
1114
diff
changeset
|
29 AVOPTION_CODEC_FLAG("bug_autodetect", "workaround bug autodetection", workaround_bugs, FF_BUG_AUTODETECT, 1), |
64c7c76ed17c
* 'externaly' visible option list begins avoptions_ prefix
kabi
parents:
1114
diff
changeset
|
30 AVOPTION_CODEC_FLAG("bug_old_msmpeg4", "workaround old msmpeg4 bug", workaround_bugs, FF_BUG_OLD_MSMPEG4, 0), |
64c7c76ed17c
* 'externaly' visible option list begins avoptions_ prefix
kabi
parents:
1114
diff
changeset
|
31 AVOPTION_CODEC_FLAG("bug_xvid_ilace", "workaround XviD interlace bug", workaround_bugs, FF_BUG_XVID_ILACE, 0), |
64c7c76ed17c
* 'externaly' visible option list begins avoptions_ prefix
kabi
parents:
1114
diff
changeset
|
32 AVOPTION_CODEC_FLAG("bug_ump4", "workaround ump4 bug", workaround_bugs, FF_BUG_UMP4, 0), |
64c7c76ed17c
* 'externaly' visible option list begins avoptions_ prefix
kabi
parents:
1114
diff
changeset
|
33 AVOPTION_CODEC_FLAG("bug_no_padding", "workaround padding bug", workaround_bugs, FF_BUG_NO_PADDING, 0), |
64c7c76ed17c
* 'externaly' visible option list begins avoptions_ prefix
kabi
parents:
1114
diff
changeset
|
34 AVOPTION_CODEC_FLAG("bug_ac_vlc", "workaround ac VLC bug", workaround_bugs, FF_BUG_AC_VLC, 0), |
64c7c76ed17c
* 'externaly' visible option list begins avoptions_ prefix
kabi
parents:
1114
diff
changeset
|
35 AVOPTION_CODEC_FLAG("bug_qpel_chroma", "workaround qpel chroma bug", workaround_bugs, FF_BUG_QPEL_CHROMA, 0), |
64c7c76ed17c
* 'externaly' visible option list begins avoptions_ prefix
kabi
parents:
1114
diff
changeset
|
36 AVOPTION_CODEC_FLAG("bug_std_qpel", "workaround std qpel bug", workaround_bugs, FF_BUG_STD_QPEL, 0), |
64c7c76ed17c
* 'externaly' visible option list begins avoptions_ prefix
kabi
parents:
1114
diff
changeset
|
37 AVOPTION_CODEC_FLAG("bug_qpel_chroma2", "workaround qpel chroma2 bug", workaround_bugs, FF_BUG_QPEL_CHROMA2, 0), |
64c7c76ed17c
* 'externaly' visible option list begins avoptions_ prefix
kabi
parents:
1114
diff
changeset
|
38 AVOPTION_CODEC_FLAG("bug_direct_blocksize", "workaround direct blocksize bug", workaround_bugs, FF_BUG_DIRECT_BLOCKSIZE, 0), |
64c7c76ed17c
* 'externaly' visible option list begins avoptions_ prefix
kabi
parents:
1114
diff
changeset
|
39 AVOPTION_END() |
64c7c76ed17c
* 'externaly' visible option list begins avoptions_ prefix
kabi
parents:
1114
diff
changeset
|
40 }; |
64c7c76ed17c
* 'externaly' visible option list begins avoptions_ prefix
kabi
parents:
1114
diff
changeset
|
41 |
64c7c76ed17c
* 'externaly' visible option list begins avoptions_ prefix
kabi
parents:
1114
diff
changeset
|
42 |
1058 | 43 static int parse_bool(const AVOption *c, char *s, int *var) |
1019 | 44 { |
45 int b = 1; /* by default -on- when present */ | |
46 if (s) { | |
47 if (!strcasecmp(s, "off") || !strcasecmp(s, "false") | |
48 || !strcmp(s, "0")) | |
49 b = 0; | |
50 else if (!strcasecmp(s, "on") || !strcasecmp(s, "true") | |
51 || !strcmp(s, "1")) | |
52 b = 1; | |
53 else | |
54 return -1; | |
55 } | |
56 | |
1124
64c7c76ed17c
* 'externaly' visible option list begins avoptions_ prefix
kabi
parents:
1114
diff
changeset
|
57 if (c->type == FF_OPT_TYPE_FLAG) { |
64c7c76ed17c
* 'externaly' visible option list begins avoptions_ prefix
kabi
parents:
1114
diff
changeset
|
58 if (b) |
64c7c76ed17c
* 'externaly' visible option list begins avoptions_ prefix
kabi
parents:
1114
diff
changeset
|
59 *var |= (int)c->min; |
64c7c76ed17c
* 'externaly' visible option list begins avoptions_ prefix
kabi
parents:
1114
diff
changeset
|
60 else |
64c7c76ed17c
* 'externaly' visible option list begins avoptions_ prefix
kabi
parents:
1114
diff
changeset
|
61 *var &= ~(int)c->min; |
64c7c76ed17c
* 'externaly' visible option list begins avoptions_ prefix
kabi
parents:
1114
diff
changeset
|
62 } else |
64c7c76ed17c
* 'externaly' visible option list begins avoptions_ prefix
kabi
parents:
1114
diff
changeset
|
63 *var = b; |
1019 | 64 return 0; |
65 } | |
66 | |
1058 | 67 static int parse_double(const AVOption *c, char *s, double *var) |
1019 | 68 { |
69 double d; | |
70 if (!s) | |
71 return -1; | |
72 d = atof(s); | |
73 if (c->min != c->max) { | |
74 if (d < c->min || d > c->max) { | |
75 fprintf(stderr, "Option: %s double value: %f out of range <%f, %f>\n", | |
76 c->name, d, c->min, c->max); | |
77 return -1; | |
78 } | |
79 } | |
1058 | 80 *var = d; |
1019 | 81 return 0; |
82 } | |
83 | |
1058 | 84 static int parse_int(const AVOption* c, char* s, int* var) |
1019 | 85 { |
86 int i; | |
87 if (!s) | |
88 return -1; | |
89 i = atoi(s); | |
90 if (c->min != c->max) { | |
91 if (i < (int)c->min || i > (int)c->max) { | |
92 fprintf(stderr, "Option: %s integer value: %d out of range <%d, %d>\n", | |
93 c->name, i, (int)c->min, (int)c->max); | |
94 return -1; | |
95 } | |
96 } | |
1058 | 97 *var = i; |
1019 | 98 return 0; |
99 } | |
100 | |
1114 | 101 static int parse_string(const AVOption *c, char *s, void* strct, char **var) |
1019 | 102 { |
103 if (!s) | |
104 return -1; | |
105 | |
1058 | 106 if (c->type == FF_OPT_TYPE_RCOVERRIDE) { |
1019 | 107 int sf, ef, qs; |
108 float qf; | |
109 if (sscanf(s, "%d,%d,%d,%f", &sf, &ef, &qs, &qf) == 4 && sf < ef) { | |
1114 | 110 AVCodecContext *avctx = (AVCodecContext *) strct; |
1058 | 111 RcOverride *o; |
112 avctx->rc_override = av_realloc(avctx->rc_override, | |
113 sizeof(RcOverride) * (avctx->rc_override_count + 1)); | |
114 o = avctx->rc_override + avctx->rc_override_count++; | |
1019 | 115 o->start_frame = sf; |
116 o->end_frame = ef; | |
117 o->qscale = qs; | |
118 o->quality_factor = qf; | |
119 | |
120 //printf("parsed Rc: %d,%d,%d,%f (%d)\n", sf,ef,qs,qf, avctx->rc_override_count); | |
121 } else { | |
122 printf("incorrect/unparsable Rc: \"%s\"\n", s); | |
123 } | |
124 } else | |
1058 | 125 *var = av_strdup(s); |
1019 | 126 return 0; |
127 } | |
128 | |
1114 | 129 int avoption_parse(void* strct, const AVOption* list, const char *opts) |
962 | 130 { |
1058 | 131 int r = 0; |
132 char* dopts = av_strdup(opts); | |
133 if (dopts) { | |
134 char *str = dopts; | |
135 | |
136 while (str && *str && r == 0) { | |
137 const AVOption *stack[FF_OPT_MAX_DEPTH]; | |
1114 | 138 const AVOption *c = list; |
1058 | 139 int depth = 0; |
140 char* e = strchr(str, ':'); | |
141 char* p; | |
142 if (e) | |
143 *e++ = 0; | |
144 | |
145 p = strchr(str, '='); | |
146 if (p) | |
147 *p++ = 0; | |
962 | 148 |
1058 | 149 // going through option structures |
150 for (;;) { | |
151 if (!c->name) { | |
1114 | 152 if (c->help) { |
1058 | 153 stack[depth++] = c; |
1114 | 154 c = (const AVOption*) c->help; |
1058 | 155 assert(depth > FF_OPT_MAX_DEPTH); |
156 } else { | |
157 if (depth == 0) | |
158 break; // finished | |
159 c = stack[--depth]; | |
160 c++; | |
161 } | |
162 } else { | |
163 if (!strcmp(c->name, str)) { | |
1114 | 164 void* ptr = (char*)strct + c->offset; |
962 | 165 |
1058 | 166 switch (c->type & FF_OPT_TYPE_MASK) { |
167 case FF_OPT_TYPE_BOOL: | |
168 r = parse_bool(c, p, (int*)ptr); | |
169 break; | |
170 case FF_OPT_TYPE_DOUBLE: | |
171 r = parse_double(c, p, (double*)ptr); | |
172 break; | |
173 case FF_OPT_TYPE_INT: | |
174 r = parse_int(c, p, (int*)ptr); | |
175 break; | |
176 case FF_OPT_TYPE_STRING: | |
1114 | 177 r = parse_string(c, p, strct, (char**)ptr); |
1058 | 178 break; |
179 default: | |
180 assert(0 == 1); | |
181 } | |
182 } | |
183 c++; | |
184 } | |
1019 | 185 } |
1058 | 186 str = e; |
1019 | 187 } |
1058 | 188 av_free(dopts); |
962 | 189 } |
1058 | 190 return r; |
962 | 191 } |