Mercurial > libavcodec.hg
comparison opts.c @ 1114:e4762efc3617 libavcodec
* more generic avoption_parse
* reused help ptr for sub ptr
author | kabi |
---|---|
date | Fri, 07 Mar 2003 13:48:02 +0000 |
parents | 1e39f273ecd6 |
children | 64c7c76ed17c |
comparison
equal
deleted
inserted
replaced
1113:bbcb4fda2b86 | 1114:e4762efc3617 |
---|---|
10 * | 10 * |
11 */ | 11 */ |
12 | 12 |
13 #include "avcodec.h" | 13 #include "avcodec.h" |
14 | 14 |
15 extern const AVOption common_options[2]; | 15 #ifdef HAVE_MMX |
16 extern const AVOption common_options[3 + 5]; | |
17 #else | |
18 extern const AVOption common_options[3]; | |
19 #endif | |
16 | 20 |
17 const AVOption common_options[2] = { | 21 const AVOption common_options[] = { |
18 AVOPTION_CODEC_INT("common", "test", bit_rate, 0, 10, 0), | 22 AVOPTION_CODEC_FLAG("bit_exact", "use only bit-exact stuff", flags, CODEC_FLAG_BITEXACT, 0), |
23 AVOPTION_CODEC_FLAG("mm_force", "force mm flags", dsp_mask, FF_MM_FORCE, 0), | |
24 #ifdef HAVE_MMX | |
25 AVOPTION_CODEC_FLAG("mm_mmx", "mask MMX feature", dsp_mask, FF_MM_MMX, 0), | |
26 AVOPTION_CODEC_FLAG("mm_3dnow", "mask 3DNow feature", dsp_mask, FF_MM_3DNOW, 0), | |
27 AVOPTION_CODEC_FLAG("mm_mmxext", "mask MMXEXT (MMX2) feature", dsp_mask, FF_MM_MMXEXT, 0), | |
28 AVOPTION_CODEC_FLAG("mm_sse", "mask SSE feature", dsp_mask, FF_MM_SSE, 0), | |
29 AVOPTION_CODEC_FLAG("mm_sse2", "mask SSE2 feature", dsp_mask, FF_MM_SSE2, 0), | |
30 #endif | |
19 AVOPTION_END() | 31 AVOPTION_END() |
20 }; | 32 }; |
21 | 33 |
22 static int parse_bool(const AVOption *c, char *s, int *var) | 34 static int parse_bool(const AVOption *c, char *s, int *var) |
23 { | 35 { |
69 } | 81 } |
70 *var = i; | 82 *var = i; |
71 return 0; | 83 return 0; |
72 } | 84 } |
73 | 85 |
74 static int parse_string(const AVOption *c, char *s, AVCodecContext *avctx, char **var) | 86 static int parse_string(const AVOption *c, char *s, void* strct, char **var) |
75 { | 87 { |
76 if (!s) | 88 if (!s) |
77 return -1; | 89 return -1; |
78 | 90 |
79 if (c->type == FF_OPT_TYPE_RCOVERRIDE) { | 91 if (c->type == FF_OPT_TYPE_RCOVERRIDE) { |
80 int sf, ef, qs; | 92 int sf, ef, qs; |
81 float qf; | 93 float qf; |
82 if (sscanf(s, "%d,%d,%d,%f", &sf, &ef, &qs, &qf) == 4 && sf < ef) { | 94 if (sscanf(s, "%d,%d,%d,%f", &sf, &ef, &qs, &qf) == 4 && sf < ef) { |
95 AVCodecContext *avctx = (AVCodecContext *) strct; | |
83 RcOverride *o; | 96 RcOverride *o; |
84 avctx->rc_override = av_realloc(avctx->rc_override, | 97 avctx->rc_override = av_realloc(avctx->rc_override, |
85 sizeof(RcOverride) * (avctx->rc_override_count + 1)); | 98 sizeof(RcOverride) * (avctx->rc_override_count + 1)); |
86 o = avctx->rc_override + avctx->rc_override_count++; | 99 o = avctx->rc_override + avctx->rc_override_count++; |
87 o->start_frame = sf; | 100 o->start_frame = sf; |
96 } else | 109 } else |
97 *var = av_strdup(s); | 110 *var = av_strdup(s); |
98 return 0; | 111 return 0; |
99 } | 112 } |
100 | 113 |
101 /** | 114 int avoption_parse(void* strct, const AVOption* list, const char *opts) |
102 * | |
103 * \param codec codec for option parsing | |
104 * \param opts string with options for parsing | |
105 * \param avctx where to store parsed results | |
106 */ | |
107 int avcodec_parse(const AVCodec *codec, const char *opts, AVCodecContext *avctx) | |
108 { | 115 { |
109 int r = 0; | 116 int r = 0; |
110 char* dopts = av_strdup(opts); | 117 char* dopts = av_strdup(opts); |
111 if (dopts) { | 118 if (dopts) { |
112 char *str = dopts; | 119 char *str = dopts; |
113 | 120 |
114 while (str && *str && r == 0) { | 121 while (str && *str && r == 0) { |
115 const AVOption *stack[FF_OPT_MAX_DEPTH]; | 122 const AVOption *stack[FF_OPT_MAX_DEPTH]; |
123 const AVOption *c = list; | |
116 int depth = 0; | 124 int depth = 0; |
117 const AVOption *c = codec->options; | |
118 char* e = strchr(str, ':'); | 125 char* e = strchr(str, ':'); |
119 char* p; | 126 char* p; |
120 if (e) | 127 if (e) |
121 *e++ = 0; | 128 *e++ = 0; |
122 | 129 |
125 *p++ = 0; | 132 *p++ = 0; |
126 | 133 |
127 // going through option structures | 134 // going through option structures |
128 for (;;) { | 135 for (;;) { |
129 if (!c->name) { | 136 if (!c->name) { |
130 if (c->sub) { | 137 if (c->help) { |
131 stack[depth++] = c; | 138 stack[depth++] = c; |
132 c = c->sub; | 139 c = (const AVOption*) c->help; |
133 assert(depth > FF_OPT_MAX_DEPTH); | 140 assert(depth > FF_OPT_MAX_DEPTH); |
134 } else { | 141 } else { |
135 if (depth == 0) | 142 if (depth == 0) |
136 break; // finished | 143 break; // finished |
137 c = stack[--depth]; | 144 c = stack[--depth]; |
138 c++; | 145 c++; |
139 } | 146 } |
140 } else { | 147 } else { |
141 if (!strcmp(c->name, str)) { | 148 if (!strcmp(c->name, str)) { |
142 void* ptr = (char*)avctx + c->offset; | 149 void* ptr = (char*)strct + c->offset; |
143 | 150 |
144 switch (c->type & FF_OPT_TYPE_MASK) { | 151 switch (c->type & FF_OPT_TYPE_MASK) { |
145 case FF_OPT_TYPE_BOOL: | 152 case FF_OPT_TYPE_BOOL: |
146 r = parse_bool(c, p, (int*)ptr); | 153 r = parse_bool(c, p, (int*)ptr); |
147 break; | 154 break; |
150 break; | 157 break; |
151 case FF_OPT_TYPE_INT: | 158 case FF_OPT_TYPE_INT: |
152 r = parse_int(c, p, (int*)ptr); | 159 r = parse_int(c, p, (int*)ptr); |
153 break; | 160 break; |
154 case FF_OPT_TYPE_STRING: | 161 case FF_OPT_TYPE_STRING: |
155 r = parse_string(c, p, avctx, (char**)ptr); | 162 r = parse_string(c, p, strct, (char**)ptr); |
156 break; | 163 break; |
157 default: | 164 default: |
158 assert(0 == 1); | 165 assert(0 == 1); |
159 } | 166 } |
160 } | 167 } |