Mercurial > libavcodec.hg
annotate opts.c @ 1353:cfc80b3a4ada libavcodec
flash video (flv) support patch by (Garrick Meeker <gmeeker at theoryllc dot com>)
author | michaelni |
---|---|
date | Wed, 09 Jul 2003 23:10:59 +0000 |
parents | 300961b1ef4f |
children | daa70b33fc44 |
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" | |
1128 | 14 #include "os_support.h" |
1125
0980ae063f4e
restoring OS/2 compatibility patch by ("Slavik Gnatenko" <miracle9 at newmail dot ru>)
michaelni
parents:
1124
diff
changeset
|
15 |
1124
64c7c76ed17c
* 'externaly' visible option list begins avoptions_ prefix
kabi
parents:
1114
diff
changeset
|
16 const AVOption avoptions_common[] = { |
1114 | 17 AVOPTION_CODEC_FLAG("bit_exact", "use only bit-exact stuff", flags, CODEC_FLAG_BITEXACT, 0), |
18 AVOPTION_CODEC_FLAG("mm_force", "force mm flags", dsp_mask, FF_MM_FORCE, 0), | |
19 #ifdef HAVE_MMX | |
20 AVOPTION_CODEC_FLAG("mm_mmx", "mask MMX feature", dsp_mask, FF_MM_MMX, 0), | |
21 AVOPTION_CODEC_FLAG("mm_3dnow", "mask 3DNow feature", dsp_mask, FF_MM_3DNOW, 0), | |
22 AVOPTION_CODEC_FLAG("mm_mmxext", "mask MMXEXT (MMX2) feature", dsp_mask, FF_MM_MMXEXT, 0), | |
23 AVOPTION_CODEC_FLAG("mm_sse", "mask SSE feature", dsp_mask, FF_MM_SSE, 0), | |
24 AVOPTION_CODEC_FLAG("mm_sse2", "mask SSE2 feature", dsp_mask, FF_MM_SSE2, 0), | |
25 #endif | |
1058 | 26 AVOPTION_END() |
27 }; | |
962 | 28 |
1124
64c7c76ed17c
* 'externaly' visible option list begins avoptions_ prefix
kabi
parents:
1114
diff
changeset
|
29 const AVOption avoptions_workaround_bug[] = { |
64c7c76ed17c
* 'externaly' visible option list begins avoptions_ prefix
kabi
parents:
1114
diff
changeset
|
30 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
|
31 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
|
32 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
|
33 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
|
34 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
|
35 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
|
36 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
|
37 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
|
38 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
|
39 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
|
40 AVOPTION_END() |
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 |
64c7c76ed17c
* 'externaly' visible option list begins avoptions_ prefix
kabi
parents:
1114
diff
changeset
|
43 |
1058 | 44 static int parse_bool(const AVOption *c, char *s, int *var) |
1019 | 45 { |
46 int b = 1; /* by default -on- when present */ | |
47 if (s) { | |
48 if (!strcasecmp(s, "off") || !strcasecmp(s, "false") | |
49 || !strcmp(s, "0")) | |
50 b = 0; | |
51 else if (!strcasecmp(s, "on") || !strcasecmp(s, "true") | |
52 || !strcmp(s, "1")) | |
53 b = 1; | |
54 else | |
55 return -1; | |
56 } | |
57 | |
1124
64c7c76ed17c
* 'externaly' visible option list begins avoptions_ prefix
kabi
parents:
1114
diff
changeset
|
58 if (c->type == FF_OPT_TYPE_FLAG) { |
64c7c76ed17c
* 'externaly' visible option list begins avoptions_ prefix
kabi
parents:
1114
diff
changeset
|
59 if (b) |
64c7c76ed17c
* 'externaly' visible option list begins avoptions_ prefix
kabi
parents:
1114
diff
changeset
|
60 *var |= (int)c->min; |
64c7c76ed17c
* 'externaly' visible option list begins avoptions_ prefix
kabi
parents:
1114
diff
changeset
|
61 else |
64c7c76ed17c
* 'externaly' visible option list begins avoptions_ prefix
kabi
parents:
1114
diff
changeset
|
62 *var &= ~(int)c->min; |
64c7c76ed17c
* 'externaly' visible option list begins avoptions_ prefix
kabi
parents:
1114
diff
changeset
|
63 } else |
64c7c76ed17c
* 'externaly' visible option list begins avoptions_ prefix
kabi
parents:
1114
diff
changeset
|
64 *var = b; |
1019 | 65 return 0; |
66 } | |
67 | |
1058 | 68 static int parse_double(const AVOption *c, char *s, double *var) |
1019 | 69 { |
70 double d; | |
71 if (!s) | |
72 return -1; | |
73 d = atof(s); | |
74 if (c->min != c->max) { | |
75 if (d < c->min || d > c->max) { | |
76 fprintf(stderr, "Option: %s double value: %f out of range <%f, %f>\n", | |
77 c->name, d, c->min, c->max); | |
78 return -1; | |
79 } | |
80 } | |
1058 | 81 *var = d; |
1019 | 82 return 0; |
83 } | |
84 | |
1058 | 85 static int parse_int(const AVOption* c, char* s, int* var) |
1019 | 86 { |
87 int i; | |
88 if (!s) | |
89 return -1; | |
90 i = atoi(s); | |
91 if (c->min != c->max) { | |
92 if (i < (int)c->min || i > (int)c->max) { | |
93 fprintf(stderr, "Option: %s integer value: %d out of range <%d, %d>\n", | |
94 c->name, i, (int)c->min, (int)c->max); | |
95 return -1; | |
96 } | |
97 } | |
1058 | 98 *var = i; |
1019 | 99 return 0; |
100 } | |
101 | |
1114 | 102 static int parse_string(const AVOption *c, char *s, void* strct, char **var) |
1019 | 103 { |
104 if (!s) | |
105 return -1; | |
106 | |
1058 | 107 if (c->type == FF_OPT_TYPE_RCOVERRIDE) { |
1019 | 108 int sf, ef, qs; |
109 float qf; | |
110 if (sscanf(s, "%d,%d,%d,%f", &sf, &ef, &qs, &qf) == 4 && sf < ef) { | |
1114 | 111 AVCodecContext *avctx = (AVCodecContext *) strct; |
1058 | 112 RcOverride *o; |
113 avctx->rc_override = av_realloc(avctx->rc_override, | |
114 sizeof(RcOverride) * (avctx->rc_override_count + 1)); | |
115 o = avctx->rc_override + avctx->rc_override_count++; | |
1019 | 116 o->start_frame = sf; |
117 o->end_frame = ef; | |
118 o->qscale = qs; | |
119 o->quality_factor = qf; | |
120 | |
121 //printf("parsed Rc: %d,%d,%d,%f (%d)\n", sf,ef,qs,qf, avctx->rc_override_count); | |
122 } else { | |
123 printf("incorrect/unparsable Rc: \"%s\"\n", s); | |
124 } | |
125 } else | |
1058 | 126 *var = av_strdup(s); |
1019 | 127 return 0; |
128 } | |
129 | |
1114 | 130 int avoption_parse(void* strct, const AVOption* list, const char *opts) |
962 | 131 { |
1058 | 132 int r = 0; |
133 char* dopts = av_strdup(opts); | |
134 if (dopts) { | |
135 char *str = dopts; | |
136 | |
137 while (str && *str && r == 0) { | |
138 const AVOption *stack[FF_OPT_MAX_DEPTH]; | |
1114 | 139 const AVOption *c = list; |
1058 | 140 int depth = 0; |
141 char* e = strchr(str, ':'); | |
142 char* p; | |
143 if (e) | |
144 *e++ = 0; | |
145 | |
146 p = strchr(str, '='); | |
147 if (p) | |
148 *p++ = 0; | |
962 | 149 |
1058 | 150 // going through option structures |
151 for (;;) { | |
152 if (!c->name) { | |
1114 | 153 if (c->help) { |
1058 | 154 stack[depth++] = c; |
1114 | 155 c = (const AVOption*) c->help; |
1058 | 156 assert(depth > FF_OPT_MAX_DEPTH); |
157 } else { | |
158 if (depth == 0) | |
159 break; // finished | |
160 c = stack[--depth]; | |
161 c++; | |
162 } | |
163 } else { | |
164 if (!strcmp(c->name, str)) { | |
1114 | 165 void* ptr = (char*)strct + c->offset; |
962 | 166 |
1058 | 167 switch (c->type & FF_OPT_TYPE_MASK) { |
168 case FF_OPT_TYPE_BOOL: | |
169 r = parse_bool(c, p, (int*)ptr); | |
170 break; | |
171 case FF_OPT_TYPE_DOUBLE: | |
172 r = parse_double(c, p, (double*)ptr); | |
173 break; | |
174 case FF_OPT_TYPE_INT: | |
175 r = parse_int(c, p, (int*)ptr); | |
176 break; | |
177 case FF_OPT_TYPE_STRING: | |
1114 | 178 r = parse_string(c, p, strct, (char**)ptr); |
1058 | 179 break; |
180 default: | |
181 assert(0 == 1); | |
182 } | |
183 } | |
184 c++; | |
185 } | |
1019 | 186 } |
1058 | 187 str = e; |
1019 | 188 } |
1058 | 189 av_free(dopts); |
962 | 190 } |
1058 | 191 return r; |
962 | 192 } |