Mercurial > libavcodec.hg
annotate opts.c @ 2430:805cbcf4dc8a libavcodec
Mention the l5 pp filter in 'mplayer -pphelp' output.
author | diego |
---|---|
date | Sat, 15 Jan 2005 10:34:49 +0000 |
parents | 932d306bf1dc |
children |
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" | |
1125
0980ae063f4e
restoring OS/2 compatibility patch by ("Slavik Gnatenko" <miracle9 at newmail dot ru>)
michaelni
parents:
1124
diff
changeset
|
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 |
1446 | 42 /* avoid compatibility problems by redefining it */ |
43 static int av_strcasecmp(const char *s1, const char *s2) | |
44 { | |
45 signed char val; | |
46 | |
47 for(;;) { | |
48 val = toupper(*s1) - toupper(*s2); | |
49 if (val != 0) | |
50 break; | |
51 if (*s1 != '\0') | |
52 break; | |
53 s1++; | |
54 s2++; | |
55 } | |
56 return val; | |
57 } | |
58 | |
1124
64c7c76ed17c
* 'externaly' visible option list begins avoptions_ prefix
kabi
parents:
1114
diff
changeset
|
59 |
1058 | 60 static int parse_bool(const AVOption *c, char *s, int *var) |
1019 | 61 { |
62 int b = 1; /* by default -on- when present */ | |
63 if (s) { | |
1446 | 64 if (!av_strcasecmp(s, "off") || !av_strcasecmp(s, "false") |
1019 | 65 || !strcmp(s, "0")) |
66 b = 0; | |
1446 | 67 else if (!av_strcasecmp(s, "on") || !av_strcasecmp(s, "true") |
1019 | 68 || !strcmp(s, "1")) |
69 b = 1; | |
70 else | |
71 return -1; | |
72 } | |
73 | |
1124
64c7c76ed17c
* 'externaly' visible option list begins avoptions_ prefix
kabi
parents:
1114
diff
changeset
|
74 if (c->type == FF_OPT_TYPE_FLAG) { |
64c7c76ed17c
* 'externaly' visible option list begins avoptions_ prefix
kabi
parents:
1114
diff
changeset
|
75 if (b) |
64c7c76ed17c
* 'externaly' visible option list begins avoptions_ prefix
kabi
parents:
1114
diff
changeset
|
76 *var |= (int)c->min; |
64c7c76ed17c
* 'externaly' visible option list begins avoptions_ prefix
kabi
parents:
1114
diff
changeset
|
77 else |
64c7c76ed17c
* 'externaly' visible option list begins avoptions_ prefix
kabi
parents:
1114
diff
changeset
|
78 *var &= ~(int)c->min; |
64c7c76ed17c
* 'externaly' visible option list begins avoptions_ prefix
kabi
parents:
1114
diff
changeset
|
79 } else |
64c7c76ed17c
* 'externaly' visible option list begins avoptions_ prefix
kabi
parents:
1114
diff
changeset
|
80 *var = b; |
1019 | 81 return 0; |
82 } | |
83 | |
1058 | 84 static int parse_double(const AVOption *c, char *s, double *var) |
1019 | 85 { |
86 double d; | |
87 if (!s) | |
88 return -1; | |
89 d = atof(s); | |
90 if (c->min != c->max) { | |
91 if (d < c->min || d > c->max) { | |
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1446
diff
changeset
|
92 av_log(NULL, AV_LOG_ERROR, "Option: %s double value: %f out of range <%f, %f>\n", |
1019 | 93 c->name, d, c->min, c->max); |
94 return -1; | |
95 } | |
96 } | |
1058 | 97 *var = d; |
1019 | 98 return 0; |
99 } | |
100 | |
1058 | 101 static int parse_int(const AVOption* c, char* s, int* var) |
1019 | 102 { |
103 int i; | |
104 if (!s) | |
105 return -1; | |
106 i = atoi(s); | |
107 if (c->min != c->max) { | |
108 if (i < (int)c->min || i > (int)c->max) { | |
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1446
diff
changeset
|
109 av_log(NULL, AV_LOG_ERROR, "Option: %s integer value: %d out of range <%d, %d>\n", |
1019 | 110 c->name, i, (int)c->min, (int)c->max); |
111 return -1; | |
112 } | |
113 } | |
1058 | 114 *var = i; |
1019 | 115 return 0; |
116 } | |
117 | |
1114 | 118 static int parse_string(const AVOption *c, char *s, void* strct, char **var) |
1019 | 119 { |
120 if (!s) | |
121 return -1; | |
122 | |
1058 | 123 if (c->type == FF_OPT_TYPE_RCOVERRIDE) { |
1019 | 124 int sf, ef, qs; |
125 float qf; | |
126 if (sscanf(s, "%d,%d,%d,%f", &sf, &ef, &qs, &qf) == 4 && sf < ef) { | |
1114 | 127 AVCodecContext *avctx = (AVCodecContext *) strct; |
1058 | 128 RcOverride *o; |
129 avctx->rc_override = av_realloc(avctx->rc_override, | |
130 sizeof(RcOverride) * (avctx->rc_override_count + 1)); | |
131 o = avctx->rc_override + avctx->rc_override_count++; | |
1019 | 132 o->start_frame = sf; |
133 o->end_frame = ef; | |
134 o->qscale = qs; | |
135 o->quality_factor = qf; | |
136 | |
137 //printf("parsed Rc: %d,%d,%d,%f (%d)\n", sf,ef,qs,qf, avctx->rc_override_count); | |
138 } else { | |
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1446
diff
changeset
|
139 av_log(NULL, AV_LOG_ERROR, "incorrect/unparsable Rc: \"%s\"\n", s); |
1019 | 140 } |
141 } else | |
1058 | 142 *var = av_strdup(s); |
1019 | 143 return 0; |
144 } | |
145 | |
1114 | 146 int avoption_parse(void* strct, const AVOption* list, const char *opts) |
962 | 147 { |
1058 | 148 int r = 0; |
149 char* dopts = av_strdup(opts); | |
150 if (dopts) { | |
151 char *str = dopts; | |
152 | |
153 while (str && *str && r == 0) { | |
154 const AVOption *stack[FF_OPT_MAX_DEPTH]; | |
1114 | 155 const AVOption *c = list; |
1058 | 156 int depth = 0; |
157 char* e = strchr(str, ':'); | |
158 char* p; | |
159 if (e) | |
160 *e++ = 0; | |
161 | |
162 p = strchr(str, '='); | |
163 if (p) | |
164 *p++ = 0; | |
962 | 165 |
1058 | 166 // going through option structures |
167 for (;;) { | |
168 if (!c->name) { | |
1114 | 169 if (c->help) { |
1058 | 170 stack[depth++] = c; |
1114 | 171 c = (const AVOption*) c->help; |
1058 | 172 assert(depth > FF_OPT_MAX_DEPTH); |
173 } else { | |
174 if (depth == 0) | |
175 break; // finished | |
176 c = stack[--depth]; | |
177 c++; | |
178 } | |
179 } else { | |
180 if (!strcmp(c->name, str)) { | |
1114 | 181 void* ptr = (char*)strct + c->offset; |
962 | 182 |
1058 | 183 switch (c->type & FF_OPT_TYPE_MASK) { |
184 case FF_OPT_TYPE_BOOL: | |
185 r = parse_bool(c, p, (int*)ptr); | |
186 break; | |
187 case FF_OPT_TYPE_DOUBLE: | |
188 r = parse_double(c, p, (double*)ptr); | |
189 break; | |
190 case FF_OPT_TYPE_INT: | |
191 r = parse_int(c, p, (int*)ptr); | |
192 break; | |
193 case FF_OPT_TYPE_STRING: | |
1114 | 194 r = parse_string(c, p, strct, (char**)ptr); |
1058 | 195 break; |
196 default: | |
197 assert(0 == 1); | |
198 } | |
199 } | |
200 c++; | |
201 } | |
1019 | 202 } |
1058 | 203 str = e; |
1019 | 204 } |
1058 | 205 av_free(dopts); |
962 | 206 } |
1058 | 207 return r; |
962 | 208 } |