annotate opts.c @ 1030:801f2739264a libavcodec

undefine malloc macros
author bellard
date Thu, 23 Jan 2003 22:59:06 +0000
parents ef905ded19fe
children 3c3da6edc9a1
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
962
c5aef83c6a3f * first shot for generaly usable option parser for codecs
kabi
parents:
diff changeset
1 /*
c5aef83c6a3f * first shot for generaly usable option parser for codecs
kabi
parents:
diff changeset
2 * LGPL
c5aef83c6a3f * first shot for generaly usable option parser for codecs
kabi
parents:
diff changeset
3 */
c5aef83c6a3f * first shot for generaly usable option parser for codecs
kabi
parents:
diff changeset
4
c5aef83c6a3f * first shot for generaly usable option parser for codecs
kabi
parents:
diff changeset
5 /*
c5aef83c6a3f * first shot for generaly usable option parser for codecs
kabi
parents:
diff changeset
6 * typical parsed command line:
c5aef83c6a3f * first shot for generaly usable option parser for codecs
kabi
parents:
diff changeset
7 * msmpeg4:bitrate=720000:qmax=16
c5aef83c6a3f * first shot for generaly usable option parser for codecs
kabi
parents:
diff changeset
8 *
c5aef83c6a3f * first shot for generaly usable option parser for codecs
kabi
parents:
diff changeset
9 */
c5aef83c6a3f * first shot for generaly usable option parser for codecs
kabi
parents:
diff changeset
10
c5aef83c6a3f * first shot for generaly usable option parser for codecs
kabi
parents:
diff changeset
11 #include "avcodec.h"
1019
ef905ded19fe * code for parsing options
kabi
parents: 962
diff changeset
12 #ifdef OPTS_MAIN
ef905ded19fe * code for parsing options
kabi
parents: 962
diff changeset
13 #include <stdio.h>
ef905ded19fe * code for parsing options
kabi
parents: 962
diff changeset
14 #include <stdlib.h>
ef905ded19fe * code for parsing options
kabi
parents: 962
diff changeset
15 #include <string.h>
ef905ded19fe * code for parsing options
kabi
parents: 962
diff changeset
16 #endif
962
c5aef83c6a3f * first shot for generaly usable option parser for codecs
kabi
parents:
diff changeset
17
c5aef83c6a3f * first shot for generaly usable option parser for codecs
kabi
parents:
diff changeset
18 /*
1019
ef905ded19fe * code for parsing options
kabi
parents: 962
diff changeset
19 * todo - use for decoder options also
962
c5aef83c6a3f * first shot for generaly usable option parser for codecs
kabi
parents:
diff changeset
20 */
c5aef83c6a3f * first shot for generaly usable option parser for codecs
kabi
parents:
diff changeset
21
1019
ef905ded19fe * code for parsing options
kabi
parents: 962
diff changeset
22 static int parse_bool(avc_config_t* c, char* s)
ef905ded19fe * code for parsing options
kabi
parents: 962
diff changeset
23 {
ef905ded19fe * code for parsing options
kabi
parents: 962
diff changeset
24 int b = 1; /* by default -on- when present */
ef905ded19fe * code for parsing options
kabi
parents: 962
diff changeset
25 if (s) {
ef905ded19fe * code for parsing options
kabi
parents: 962
diff changeset
26 if (!strcasecmp(s, "off") || !strcasecmp(s, "false")
ef905ded19fe * code for parsing options
kabi
parents: 962
diff changeset
27 || !strcmp(s, "0"))
ef905ded19fe * code for parsing options
kabi
parents: 962
diff changeset
28 b = 0;
ef905ded19fe * code for parsing options
kabi
parents: 962
diff changeset
29 else if (!strcasecmp(s, "on") || !strcasecmp(s, "true")
ef905ded19fe * code for parsing options
kabi
parents: 962
diff changeset
30 || !strcmp(s, "1"))
ef905ded19fe * code for parsing options
kabi
parents: 962
diff changeset
31 b = 1;
ef905ded19fe * code for parsing options
kabi
parents: 962
diff changeset
32 else
ef905ded19fe * code for parsing options
kabi
parents: 962
diff changeset
33 return -1;
ef905ded19fe * code for parsing options
kabi
parents: 962
diff changeset
34 }
ef905ded19fe * code for parsing options
kabi
parents: 962
diff changeset
35
ef905ded19fe * code for parsing options
kabi
parents: 962
diff changeset
36 if (c && c->val)
ef905ded19fe * code for parsing options
kabi
parents: 962
diff changeset
37 *(int*)(c->val) = b;
ef905ded19fe * code for parsing options
kabi
parents: 962
diff changeset
38 return 0;
ef905ded19fe * code for parsing options
kabi
parents: 962
diff changeset
39 }
ef905ded19fe * code for parsing options
kabi
parents: 962
diff changeset
40
ef905ded19fe * code for parsing options
kabi
parents: 962
diff changeset
41 static int parse_double(avc_config_t* c, char* s)
ef905ded19fe * code for parsing options
kabi
parents: 962
diff changeset
42 {
ef905ded19fe * code for parsing options
kabi
parents: 962
diff changeset
43 double d;
ef905ded19fe * code for parsing options
kabi
parents: 962
diff changeset
44 if (!s)
ef905ded19fe * code for parsing options
kabi
parents: 962
diff changeset
45 return -1;
ef905ded19fe * code for parsing options
kabi
parents: 962
diff changeset
46 d = atof(s);
ef905ded19fe * code for parsing options
kabi
parents: 962
diff changeset
47 if (c->min != c->max) {
ef905ded19fe * code for parsing options
kabi
parents: 962
diff changeset
48 if (d < c->min || d > c->max) {
ef905ded19fe * code for parsing options
kabi
parents: 962
diff changeset
49 fprintf(stderr, "Option: %s double value: %f out of range <%f, %f>\n",
ef905ded19fe * code for parsing options
kabi
parents: 962
diff changeset
50 c->name, d, c->min, c->max);
ef905ded19fe * code for parsing options
kabi
parents: 962
diff changeset
51 return -1;
ef905ded19fe * code for parsing options
kabi
parents: 962
diff changeset
52 }
ef905ded19fe * code for parsing options
kabi
parents: 962
diff changeset
53 }
ef905ded19fe * code for parsing options
kabi
parents: 962
diff changeset
54 if (c && c->val)
ef905ded19fe * code for parsing options
kabi
parents: 962
diff changeset
55 *(double*)(c->val) = d;
ef905ded19fe * code for parsing options
kabi
parents: 962
diff changeset
56 return 0;
ef905ded19fe * code for parsing options
kabi
parents: 962
diff changeset
57 }
ef905ded19fe * code for parsing options
kabi
parents: 962
diff changeset
58
ef905ded19fe * code for parsing options
kabi
parents: 962
diff changeset
59 static int parse_int(avc_config_t* c, char* s)
ef905ded19fe * code for parsing options
kabi
parents: 962
diff changeset
60 {
ef905ded19fe * code for parsing options
kabi
parents: 962
diff changeset
61 int i;
ef905ded19fe * code for parsing options
kabi
parents: 962
diff changeset
62 if (!s)
ef905ded19fe * code for parsing options
kabi
parents: 962
diff changeset
63 return -1;
ef905ded19fe * code for parsing options
kabi
parents: 962
diff changeset
64 i = atoi(s);
ef905ded19fe * code for parsing options
kabi
parents: 962
diff changeset
65 if (c->min != c->max) {
ef905ded19fe * code for parsing options
kabi
parents: 962
diff changeset
66 if (i < (int)c->min || i > (int)c->max) {
ef905ded19fe * code for parsing options
kabi
parents: 962
diff changeset
67 fprintf(stderr, "Option: %s integer value: %d out of range <%d, %d>\n",
ef905ded19fe * code for parsing options
kabi
parents: 962
diff changeset
68 c->name, i, (int)c->min, (int)c->max);
ef905ded19fe * code for parsing options
kabi
parents: 962
diff changeset
69 return -1;
ef905ded19fe * code for parsing options
kabi
parents: 962
diff changeset
70 }
ef905ded19fe * code for parsing options
kabi
parents: 962
diff changeset
71 }
ef905ded19fe * code for parsing options
kabi
parents: 962
diff changeset
72 if (c && c->val)
ef905ded19fe * code for parsing options
kabi
parents: 962
diff changeset
73 *(int*)(c->val) = i;
ef905ded19fe * code for parsing options
kabi
parents: 962
diff changeset
74 return 0;
ef905ded19fe * code for parsing options
kabi
parents: 962
diff changeset
75 }
ef905ded19fe * code for parsing options
kabi
parents: 962
diff changeset
76
ef905ded19fe * code for parsing options
kabi
parents: 962
diff changeset
77 static int parse_string(AVCodecContext* avctx, avc_config_t* c, char* s)
ef905ded19fe * code for parsing options
kabi
parents: 962
diff changeset
78 {
ef905ded19fe * code for parsing options
kabi
parents: 962
diff changeset
79 if (!s)
ef905ded19fe * code for parsing options
kabi
parents: 962
diff changeset
80 return -1;
ef905ded19fe * code for parsing options
kabi
parents: 962
diff changeset
81
ef905ded19fe * code for parsing options
kabi
parents: 962
diff changeset
82 if (c->type == FF_CONF_TYPE_RCOVERIDE) {
ef905ded19fe * code for parsing options
kabi
parents: 962
diff changeset
83 int sf, ef, qs;
ef905ded19fe * code for parsing options
kabi
parents: 962
diff changeset
84 float qf;
ef905ded19fe * code for parsing options
kabi
parents: 962
diff changeset
85 if (sscanf(s, "%d,%d,%d,%f", &sf, &ef, &qs, &qf) == 4 && sf < ef) {
ef905ded19fe * code for parsing options
kabi
parents: 962
diff changeset
86 RcOverride* o;
ef905ded19fe * code for parsing options
kabi
parents: 962
diff changeset
87 *((RcOverride**)c->val) =
ef905ded19fe * code for parsing options
kabi
parents: 962
diff changeset
88 realloc(*((RcOverride**)c->val),
ef905ded19fe * code for parsing options
kabi
parents: 962
diff changeset
89 sizeof(RcOverride) * (avctx->rc_override_count + 1));
ef905ded19fe * code for parsing options
kabi
parents: 962
diff changeset
90 o = *((RcOverride**)c->val) + avctx->rc_override_count++;
ef905ded19fe * code for parsing options
kabi
parents: 962
diff changeset
91 o->start_frame = sf;
ef905ded19fe * code for parsing options
kabi
parents: 962
diff changeset
92 o->end_frame = ef;
ef905ded19fe * code for parsing options
kabi
parents: 962
diff changeset
93 o->qscale = qs;
ef905ded19fe * code for parsing options
kabi
parents: 962
diff changeset
94 o->quality_factor = qf;
ef905ded19fe * code for parsing options
kabi
parents: 962
diff changeset
95
ef905ded19fe * code for parsing options
kabi
parents: 962
diff changeset
96 //printf("parsed Rc: %d,%d,%d,%f (%d)\n", sf,ef,qs,qf, avctx->rc_override_count);
ef905ded19fe * code for parsing options
kabi
parents: 962
diff changeset
97 } else {
ef905ded19fe * code for parsing options
kabi
parents: 962
diff changeset
98 printf("incorrect/unparsable Rc: \"%s\"\n", s);
ef905ded19fe * code for parsing options
kabi
parents: 962
diff changeset
99 }
ef905ded19fe * code for parsing options
kabi
parents: 962
diff changeset
100 } else
ef905ded19fe * code for parsing options
kabi
parents: 962
diff changeset
101 (char*)(c->val) = strdup(s);
ef905ded19fe * code for parsing options
kabi
parents: 962
diff changeset
102 return 0;
ef905ded19fe * code for parsing options
kabi
parents: 962
diff changeset
103 }
ef905ded19fe * code for parsing options
kabi
parents: 962
diff changeset
104
ef905ded19fe * code for parsing options
kabi
parents: 962
diff changeset
105 static int parse(AVCodecContext* avctx, avc_config_t* config, char* str)
ef905ded19fe * code for parsing options
kabi
parents: 962
diff changeset
106 {
ef905ded19fe * code for parsing options
kabi
parents: 962
diff changeset
107 while (str && *str) {
ef905ded19fe * code for parsing options
kabi
parents: 962
diff changeset
108 avc_config_t* c = config;
ef905ded19fe * code for parsing options
kabi
parents: 962
diff changeset
109 char* e = strchr(str, ':');
ef905ded19fe * code for parsing options
kabi
parents: 962
diff changeset
110 char* p;
ef905ded19fe * code for parsing options
kabi
parents: 962
diff changeset
111 if (e)
ef905ded19fe * code for parsing options
kabi
parents: 962
diff changeset
112 *e++ = 0;
ef905ded19fe * code for parsing options
kabi
parents: 962
diff changeset
113
ef905ded19fe * code for parsing options
kabi
parents: 962
diff changeset
114 p = strchr(str, '=');
ef905ded19fe * code for parsing options
kabi
parents: 962
diff changeset
115 if (p)
ef905ded19fe * code for parsing options
kabi
parents: 962
diff changeset
116 *p++ = 0;
ef905ded19fe * code for parsing options
kabi
parents: 962
diff changeset
117
ef905ded19fe * code for parsing options
kabi
parents: 962
diff changeset
118 while (c->name) {
ef905ded19fe * code for parsing options
kabi
parents: 962
diff changeset
119 if (!strcmp(c->name, str)) {
ef905ded19fe * code for parsing options
kabi
parents: 962
diff changeset
120 switch (c->type & FF_CONF_TYPE_MASK) {
ef905ded19fe * code for parsing options
kabi
parents: 962
diff changeset
121 case FF_CONF_TYPE_BOOL:
ef905ded19fe * code for parsing options
kabi
parents: 962
diff changeset
122 parse_bool(c, p);
ef905ded19fe * code for parsing options
kabi
parents: 962
diff changeset
123 break;
ef905ded19fe * code for parsing options
kabi
parents: 962
diff changeset
124 case FF_CONF_TYPE_DOUBLE:
ef905ded19fe * code for parsing options
kabi
parents: 962
diff changeset
125 parse_double(c, p);
ef905ded19fe * code for parsing options
kabi
parents: 962
diff changeset
126 break;
ef905ded19fe * code for parsing options
kabi
parents: 962
diff changeset
127 case FF_CONF_TYPE_INT:
ef905ded19fe * code for parsing options
kabi
parents: 962
diff changeset
128 parse_int(c, p);
ef905ded19fe * code for parsing options
kabi
parents: 962
diff changeset
129 break;
ef905ded19fe * code for parsing options
kabi
parents: 962
diff changeset
130 case FF_CONF_TYPE_STRING:
ef905ded19fe * code for parsing options
kabi
parents: 962
diff changeset
131 parse_string(avctx, c, p);
ef905ded19fe * code for parsing options
kabi
parents: 962
diff changeset
132 break;
ef905ded19fe * code for parsing options
kabi
parents: 962
diff changeset
133 default:
ef905ded19fe * code for parsing options
kabi
parents: 962
diff changeset
134 abort();
ef905ded19fe * code for parsing options
kabi
parents: 962
diff changeset
135 break;
ef905ded19fe * code for parsing options
kabi
parents: 962
diff changeset
136 }
ef905ded19fe * code for parsing options
kabi
parents: 962
diff changeset
137 }
ef905ded19fe * code for parsing options
kabi
parents: 962
diff changeset
138 c++;
ef905ded19fe * code for parsing options
kabi
parents: 962
diff changeset
139 }
ef905ded19fe * code for parsing options
kabi
parents: 962
diff changeset
140 str = e;
ef905ded19fe * code for parsing options
kabi
parents: 962
diff changeset
141 }
ef905ded19fe * code for parsing options
kabi
parents: 962
diff changeset
142 return 0;
ef905ded19fe * code for parsing options
kabi
parents: 962
diff changeset
143 }
ef905ded19fe * code for parsing options
kabi
parents: 962
diff changeset
144
962
c5aef83c6a3f * first shot for generaly usable option parser for codecs
kabi
parents:
diff changeset
145 /**
1019
ef905ded19fe * code for parsing options
kabi
parents: 962
diff changeset
146 *
962
c5aef83c6a3f * first shot for generaly usable option parser for codecs
kabi
parents:
diff changeset
147 * \param avctx where to store parsed results
c5aef83c6a3f * first shot for generaly usable option parser for codecs
kabi
parents:
diff changeset
148 * \param str string with options for parsing
1019
ef905ded19fe * code for parsing options
kabi
parents: 962
diff changeset
149 * or selectional string (pick only options appliable
ef905ded19fe * code for parsing options
kabi
parents: 962
diff changeset
150 * for codec - use ,msmpeg4, (with commas to avoid mismatch)
962
c5aef83c6a3f * first shot for generaly usable option parser for codecs
kabi
parents:
diff changeset
151 * \param config allocated avc_config_t for external parsing
c5aef83c6a3f * first shot for generaly usable option parser for codecs
kabi
parents:
diff changeset
152 * i.e. external program might learn about all available
c5aef83c6a3f * first shot for generaly usable option parser for codecs
kabi
parents:
diff changeset
153 * options for given codec
c5aef83c6a3f * first shot for generaly usable option parser for codecs
kabi
parents:
diff changeset
154 **/
1019
ef905ded19fe * code for parsing options
kabi
parents: 962
diff changeset
155 void avcodec_getopt(AVCodecContext* avctx, const char* str, avc_config_t** config)
962
c5aef83c6a3f * first shot for generaly usable option parser for codecs
kabi
parents:
diff changeset
156 {
c5aef83c6a3f * first shot for generaly usable option parser for codecs
kabi
parents:
diff changeset
157 AVCodecContext avctx_tmp;
c5aef83c6a3f * first shot for generaly usable option parser for codecs
kabi
parents:
diff changeset
158 AVCodecContext* ctx = (avctx) ? avctx : &avctx_tmp;
c5aef83c6a3f * first shot for generaly usable option parser for codecs
kabi
parents:
diff changeset
159 static const char* class_h263 = ",msmpeg4,";
c5aef83c6a3f * first shot for generaly usable option parser for codecs
kabi
parents:
diff changeset
160 //"huffyuv,wmv1,msmpeg4v2,msmpeg4,mpeg4,mpeg1,mpeg1video,mjpeg,rv10,h263,h263p"
c5aef83c6a3f * first shot for generaly usable option parser for codecs
kabi
parents:
diff changeset
161
c5aef83c6a3f * first shot for generaly usable option parser for codecs
kabi
parents:
diff changeset
162 avc_config_t cnf[] =
c5aef83c6a3f * first shot for generaly usable option parser for codecs
kabi
parents:
diff changeset
163 {
c5aef83c6a3f * first shot for generaly usable option parser for codecs
kabi
parents:
diff changeset
164 // FIXME: sorted by importance!!!
c5aef83c6a3f * first shot for generaly usable option parser for codecs
kabi
parents:
diff changeset
165 // expert option should follow more common ones
c5aef83c6a3f * first shot for generaly usable option parser for codecs
kabi
parents:
diff changeset
166 {
c5aef83c6a3f * first shot for generaly usable option parser for codecs
kabi
parents:
diff changeset
167 "bitrate", "desired video bitrate",
c5aef83c6a3f * first shot for generaly usable option parser for codecs
kabi
parents:
diff changeset
168 FF_CONF_TYPE_INT, &ctx->bit_rate, 4, 240000000, 800000, NULL, class_h263
c5aef83c6a3f * first shot for generaly usable option parser for codecs
kabi
parents:
diff changeset
169 }, {
c5aef83c6a3f * first shot for generaly usable option parser for codecs
kabi
parents:
diff changeset
170 "vhq", "very high quality",
c5aef83c6a3f * first shot for generaly usable option parser for codecs
kabi
parents:
diff changeset
171 FF_CONF_TYPE_FLAG, &ctx->flags, 0, CODEC_FLAG_HQ, 0, NULL, class_h263
c5aef83c6a3f * first shot for generaly usable option parser for codecs
kabi
parents:
diff changeset
172 }, {
c5aef83c6a3f * first shot for generaly usable option parser for codecs
kabi
parents:
diff changeset
173 "ratetol", "number of bits the bitstream is allowed to diverge from the reference"
c5aef83c6a3f * first shot for generaly usable option parser for codecs
kabi
parents:
diff changeset
174 "the reference can be CBR (for CBR pass1) or VBR (for pass2)",
c5aef83c6a3f * first shot for generaly usable option parser for codecs
kabi
parents:
diff changeset
175 FF_CONF_TYPE_INT, &ctx->bit_rate_tolerance, 4, 240000000, 8000, NULL, class_h263
c5aef83c6a3f * first shot for generaly usable option parser for codecs
kabi
parents:
diff changeset
176 }, {
c5aef83c6a3f * first shot for generaly usable option parser for codecs
kabi
parents:
diff changeset
177 "qmin", "minimum quantizer", FF_CONF_TYPE_INT, &ctx->qmin, 1, 31, 2, NULL, class_h263
c5aef83c6a3f * first shot for generaly usable option parser for codecs
kabi
parents:
diff changeset
178 }, {
c5aef83c6a3f * first shot for generaly usable option parser for codecs
kabi
parents:
diff changeset
179 "qmax", "maximum qunatizer", FF_CONF_TYPE_INT, &ctx->qmax, 1, 31, 31, NULL, class_h263
c5aef83c6a3f * first shot for generaly usable option parser for codecs
kabi
parents:
diff changeset
180 }, {
c5aef83c6a3f * first shot for generaly usable option parser for codecs
kabi
parents:
diff changeset
181 "rc_eq", "rate control equation",
c5aef83c6a3f * first shot for generaly usable option parser for codecs
kabi
parents:
diff changeset
182 FF_CONF_TYPE_STRING, &ctx->rc_eq, 0, 0, 0, "tex^qComp" /* FILLME options */, class_h263
c5aef83c6a3f * first shot for generaly usable option parser for codecs
kabi
parents:
diff changeset
183 }, {
c5aef83c6a3f * first shot for generaly usable option parser for codecs
kabi
parents:
diff changeset
184 "rc_minrate", "rate control minimum bitrate",
c5aef83c6a3f * first shot for generaly usable option parser for codecs
kabi
parents:
diff changeset
185 FF_CONF_TYPE_INT, &ctx->rc_min_rate, 4, 24000000, 0, NULL, class_h263
c5aef83c6a3f * first shot for generaly usable option parser for codecs
kabi
parents:
diff changeset
186 }, {
c5aef83c6a3f * first shot for generaly usable option parser for codecs
kabi
parents:
diff changeset
187 "rc_maxrate", "rate control maximum bitrate",
c5aef83c6a3f * first shot for generaly usable option parser for codecs
kabi
parents:
diff changeset
188 FF_CONF_TYPE_INT, &ctx->rc_max_rate, 4, 24000000, 0, NULL, class_h263
c5aef83c6a3f * first shot for generaly usable option parser for codecs
kabi
parents:
diff changeset
189 }, {
c5aef83c6a3f * first shot for generaly usable option parser for codecs
kabi
parents:
diff changeset
190 "psnr", "calculate PSNR of compressed frames",
c5aef83c6a3f * first shot for generaly usable option parser for codecs
kabi
parents:
diff changeset
191 FF_CONF_TYPE_FLAG, &ctx->flags, 0, CODEC_FLAG_PSNR, 0, NULL, class_h263
c5aef83c6a3f * first shot for generaly usable option parser for codecs
kabi
parents:
diff changeset
192 }, {
c5aef83c6a3f * first shot for generaly usable option parser for codecs
kabi
parents:
diff changeset
193 "rc_override", "ratecontrol override (=startframe,endframe,qscale,quality_factor)",
1019
ef905ded19fe * code for parsing options
kabi
parents: 962
diff changeset
194 FF_CONF_TYPE_RCOVERIDE, &ctx->rc_override, 0, 0, 0, "0,0,0,0", class_h263
962
c5aef83c6a3f * first shot for generaly usable option parser for codecs
kabi
parents:
diff changeset
195 },
c5aef83c6a3f * first shot for generaly usable option parser for codecs
kabi
parents:
diff changeset
196
c5aef83c6a3f * first shot for generaly usable option parser for codecs
kabi
parents:
diff changeset
197 { NULL, NULL, 0, NULL, 0, 0, 0, NULL, NULL }
c5aef83c6a3f * first shot for generaly usable option parser for codecs
kabi
parents:
diff changeset
198 };
c5aef83c6a3f * first shot for generaly usable option parser for codecs
kabi
parents:
diff changeset
199
1019
ef905ded19fe * code for parsing options
kabi
parents: 962
diff changeset
200 if (config) {
962
c5aef83c6a3f * first shot for generaly usable option parser for codecs
kabi
parents:
diff changeset
201 *config = malloc(sizeof(cnf));
1019
ef905ded19fe * code for parsing options
kabi
parents: 962
diff changeset
202 if (*config) {
ef905ded19fe * code for parsing options
kabi
parents: 962
diff changeset
203 avc_config_t* src = cnf;
ef905ded19fe * code for parsing options
kabi
parents: 962
diff changeset
204 avc_config_t* dst = *config;
ef905ded19fe * code for parsing options
kabi
parents: 962
diff changeset
205 while (src->name) {
ef905ded19fe * code for parsing options
kabi
parents: 962
diff changeset
206 if (!str || !src->supported || strstr(src->supported, str))
ef905ded19fe * code for parsing options
kabi
parents: 962
diff changeset
207 memcpy(dst++, src, sizeof(avc_config_t));
ef905ded19fe * code for parsing options
kabi
parents: 962
diff changeset
208 src++;
ef905ded19fe * code for parsing options
kabi
parents: 962
diff changeset
209 }
ef905ded19fe * code for parsing options
kabi
parents: 962
diff changeset
210 memset(dst, 0, sizeof(avc_config_t));
ef905ded19fe * code for parsing options
kabi
parents: 962
diff changeset
211 }
ef905ded19fe * code for parsing options
kabi
parents: 962
diff changeset
212 } else if (str) {
ef905ded19fe * code for parsing options
kabi
parents: 962
diff changeset
213 char* s = strdup(str);
ef905ded19fe * code for parsing options
kabi
parents: 962
diff changeset
214 if (s) {
ef905ded19fe * code for parsing options
kabi
parents: 962
diff changeset
215 parse(avctx, cnf, s);
ef905ded19fe * code for parsing options
kabi
parents: 962
diff changeset
216 free(s);
ef905ded19fe * code for parsing options
kabi
parents: 962
diff changeset
217 }
962
c5aef83c6a3f * first shot for generaly usable option parser for codecs
kabi
parents:
diff changeset
218 }
c5aef83c6a3f * first shot for generaly usable option parser for codecs
kabi
parents:
diff changeset
219 }
1019
ef905ded19fe * code for parsing options
kabi
parents: 962
diff changeset
220
ef905ded19fe * code for parsing options
kabi
parents: 962
diff changeset
221 #ifdef OPTS_MAIN
ef905ded19fe * code for parsing options
kabi
parents: 962
diff changeset
222 /*
ef905ded19fe * code for parsing options
kabi
parents: 962
diff changeset
223 * API test -
ef905ded19fe * code for parsing options
kabi
parents: 962
diff changeset
224 * arg1: options
ef905ded19fe * code for parsing options
kabi
parents: 962
diff changeset
225 * arg2: codec type
ef905ded19fe * code for parsing options
kabi
parents: 962
diff changeset
226 *
ef905ded19fe * code for parsing options
kabi
parents: 962
diff changeset
227 * compile standalone: make CFLAGS="-DOPTS_MAIN" opts
ef905ded19fe * code for parsing options
kabi
parents: 962
diff changeset
228 */
ef905ded19fe * code for parsing options
kabi
parents: 962
diff changeset
229 int main(int argc, char* argv[])
ef905ded19fe * code for parsing options
kabi
parents: 962
diff changeset
230 {
ef905ded19fe * code for parsing options
kabi
parents: 962
diff changeset
231 AVCodecContext avctx;
ef905ded19fe * code for parsing options
kabi
parents: 962
diff changeset
232 avc_config_t* config;
ef905ded19fe * code for parsing options
kabi
parents: 962
diff changeset
233 char* def = malloc(5000);
ef905ded19fe * code for parsing options
kabi
parents: 962
diff changeset
234 const char* col = "";
ef905ded19fe * code for parsing options
kabi
parents: 962
diff changeset
235 int i = 0;
ef905ded19fe * code for parsing options
kabi
parents: 962
diff changeset
236
ef905ded19fe * code for parsing options
kabi
parents: 962
diff changeset
237 memset(&avctx, 0, sizeof(avctx));
ef905ded19fe * code for parsing options
kabi
parents: 962
diff changeset
238 *def = 0;
ef905ded19fe * code for parsing options
kabi
parents: 962
diff changeset
239 avcodec_getopt(&avctx, argv[1], NULL);
ef905ded19fe * code for parsing options
kabi
parents: 962
diff changeset
240
ef905ded19fe * code for parsing options
kabi
parents: 962
diff changeset
241 avcodec_getopt(NULL, (argc > 2) ? argv[2] : NULL, &config);
ef905ded19fe * code for parsing options
kabi
parents: 962
diff changeset
242 if (config)
ef905ded19fe * code for parsing options
kabi
parents: 962
diff changeset
243 while (config->name) {
ef905ded19fe * code for parsing options
kabi
parents: 962
diff changeset
244 int t = config->type & FF_CONF_TYPE_MASK;
ef905ded19fe * code for parsing options
kabi
parents: 962
diff changeset
245 printf("Config %s %s\n", config->name,
ef905ded19fe * code for parsing options
kabi
parents: 962
diff changeset
246 t == FF_CONF_TYPE_BOOL ? "bool" :
ef905ded19fe * code for parsing options
kabi
parents: 962
diff changeset
247 t == FF_CONF_TYPE_DOUBLE ? "double" :
ef905ded19fe * code for parsing options
kabi
parents: 962
diff changeset
248 t == FF_CONF_TYPE_INT ? "integer" :
ef905ded19fe * code for parsing options
kabi
parents: 962
diff changeset
249 t == FF_CONF_TYPE_STRING ? "string" :
ef905ded19fe * code for parsing options
kabi
parents: 962
diff changeset
250 "unknown??");
ef905ded19fe * code for parsing options
kabi
parents: 962
diff changeset
251 switch (t) {
ef905ded19fe * code for parsing options
kabi
parents: 962
diff changeset
252 case FF_CONF_TYPE_BOOL:
ef905ded19fe * code for parsing options
kabi
parents: 962
diff changeset
253 i += sprintf(def + i, "%s%s=%s",
ef905ded19fe * code for parsing options
kabi
parents: 962
diff changeset
254 col, config->name,
ef905ded19fe * code for parsing options
kabi
parents: 962
diff changeset
255 config->defval != 0. ? "on" : "off");
ef905ded19fe * code for parsing options
kabi
parents: 962
diff changeset
256 break;
ef905ded19fe * code for parsing options
kabi
parents: 962
diff changeset
257 case FF_CONF_TYPE_DOUBLE:
ef905ded19fe * code for parsing options
kabi
parents: 962
diff changeset
258 i += sprintf(def + i, "%s%s=%f",
ef905ded19fe * code for parsing options
kabi
parents: 962
diff changeset
259 col, config->name, config->defval);
ef905ded19fe * code for parsing options
kabi
parents: 962
diff changeset
260 break;
ef905ded19fe * code for parsing options
kabi
parents: 962
diff changeset
261 case FF_CONF_TYPE_INT:
ef905ded19fe * code for parsing options
kabi
parents: 962
diff changeset
262 i += sprintf(def + i, "%s%s=%d",
ef905ded19fe * code for parsing options
kabi
parents: 962
diff changeset
263 col, config->name, (int) config->defval);
ef905ded19fe * code for parsing options
kabi
parents: 962
diff changeset
264 break;
ef905ded19fe * code for parsing options
kabi
parents: 962
diff changeset
265 case FF_CONF_TYPE_STRING:
ef905ded19fe * code for parsing options
kabi
parents: 962
diff changeset
266 i += sprintf(def + i, "%s%s=%s",
ef905ded19fe * code for parsing options
kabi
parents: 962
diff changeset
267 col, config->name, config->defstr);
ef905ded19fe * code for parsing options
kabi
parents: 962
diff changeset
268 break;
ef905ded19fe * code for parsing options
kabi
parents: 962
diff changeset
269 }
ef905ded19fe * code for parsing options
kabi
parents: 962
diff changeset
270 col = ":";
ef905ded19fe * code for parsing options
kabi
parents: 962
diff changeset
271 config++;
ef905ded19fe * code for parsing options
kabi
parents: 962
diff changeset
272 }
ef905ded19fe * code for parsing options
kabi
parents: 962
diff changeset
273
ef905ded19fe * code for parsing options
kabi
parents: 962
diff changeset
274 printf("Default Options: %s\n", def);
ef905ded19fe * code for parsing options
kabi
parents: 962
diff changeset
275
ef905ded19fe * code for parsing options
kabi
parents: 962
diff changeset
276 return 0;
ef905ded19fe * code for parsing options
kabi
parents: 962
diff changeset
277 }
ef905ded19fe * code for parsing options
kabi
parents: 962
diff changeset
278 #endif