2003-01-06 18:06:51 +00:00
|
|
|
/*
|
|
|
|
* LGPL
|
|
|
|
*/
|
|
|
|
|
2003-03-06 11:32:04 +00:00
|
|
|
/**
|
|
|
|
* @file opts.c
|
|
|
|
* options parser.
|
2003-01-06 18:06:51 +00:00
|
|
|
* typical parsed command line:
|
|
|
|
* msmpeg4:bitrate=720000:qmax=16
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "avcodec.h"
|
2003-03-12 18:57:33 +00:00
|
|
|
#include "os_support.h"
|
2003-03-11 12:09:13 +00:00
|
|
|
|
2003-03-10 11:48:33 +00:00
|
|
|
const AVOption avoptions_common[] = {
|
2003-03-07 13:48:02 +00:00
|
|
|
AVOPTION_CODEC_FLAG("bit_exact", "use only bit-exact stuff", flags, CODEC_FLAG_BITEXACT, 0),
|
|
|
|
AVOPTION_CODEC_FLAG("mm_force", "force mm flags", dsp_mask, FF_MM_FORCE, 0),
|
|
|
|
#ifdef HAVE_MMX
|
|
|
|
AVOPTION_CODEC_FLAG("mm_mmx", "mask MMX feature", dsp_mask, FF_MM_MMX, 0),
|
|
|
|
AVOPTION_CODEC_FLAG("mm_3dnow", "mask 3DNow feature", dsp_mask, FF_MM_3DNOW, 0),
|
|
|
|
AVOPTION_CODEC_FLAG("mm_mmxext", "mask MMXEXT (MMX2) feature", dsp_mask, FF_MM_MMXEXT, 0),
|
|
|
|
AVOPTION_CODEC_FLAG("mm_sse", "mask SSE feature", dsp_mask, FF_MM_SSE, 0),
|
|
|
|
AVOPTION_CODEC_FLAG("mm_sse2", "mask SSE2 feature", dsp_mask, FF_MM_SSE2, 0),
|
|
|
|
#endif
|
2003-02-10 09:38:38 +00:00
|
|
|
AVOPTION_END()
|
|
|
|
};
|
|
|
|
|
2003-03-10 11:48:33 +00:00
|
|
|
const AVOption avoptions_workaround_bug[] = {
|
|
|
|
AVOPTION_CODEC_FLAG("bug_autodetect", "workaround bug autodetection", workaround_bugs, FF_BUG_AUTODETECT, 1),
|
|
|
|
AVOPTION_CODEC_FLAG("bug_old_msmpeg4", "workaround old msmpeg4 bug", workaround_bugs, FF_BUG_OLD_MSMPEG4, 0),
|
|
|
|
AVOPTION_CODEC_FLAG("bug_xvid_ilace", "workaround XviD interlace bug", workaround_bugs, FF_BUG_XVID_ILACE, 0),
|
|
|
|
AVOPTION_CODEC_FLAG("bug_ump4", "workaround ump4 bug", workaround_bugs, FF_BUG_UMP4, 0),
|
|
|
|
AVOPTION_CODEC_FLAG("bug_no_padding", "workaround padding bug", workaround_bugs, FF_BUG_NO_PADDING, 0),
|
|
|
|
AVOPTION_CODEC_FLAG("bug_ac_vlc", "workaround ac VLC bug", workaround_bugs, FF_BUG_AC_VLC, 0),
|
|
|
|
AVOPTION_CODEC_FLAG("bug_qpel_chroma", "workaround qpel chroma bug", workaround_bugs, FF_BUG_QPEL_CHROMA, 0),
|
|
|
|
AVOPTION_CODEC_FLAG("bug_std_qpel", "workaround std qpel bug", workaround_bugs, FF_BUG_STD_QPEL, 0),
|
|
|
|
AVOPTION_CODEC_FLAG("bug_qpel_chroma2", "workaround qpel chroma2 bug", workaround_bugs, FF_BUG_QPEL_CHROMA2, 0),
|
|
|
|
AVOPTION_CODEC_FLAG("bug_direct_blocksize", "workaround direct blocksize bug", workaround_bugs, FF_BUG_DIRECT_BLOCKSIZE, 0),
|
|
|
|
AVOPTION_END()
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2003-02-10 09:38:38 +00:00
|
|
|
static int parse_bool(const AVOption *c, char *s, int *var)
|
2003-01-20 19:04:39 +00:00
|
|
|
{
|
|
|
|
int b = 1; /* by default -on- when present */
|
|
|
|
if (s) {
|
|
|
|
if (!strcasecmp(s, "off") || !strcasecmp(s, "false")
|
|
|
|
|| !strcmp(s, "0"))
|
|
|
|
b = 0;
|
|
|
|
else if (!strcasecmp(s, "on") || !strcasecmp(s, "true")
|
|
|
|
|| !strcmp(s, "1"))
|
|
|
|
b = 1;
|
|
|
|
else
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2003-03-10 11:48:33 +00:00
|
|
|
if (c->type == FF_OPT_TYPE_FLAG) {
|
|
|
|
if (b)
|
|
|
|
*var |= (int)c->min;
|
|
|
|
else
|
|
|
|
*var &= ~(int)c->min;
|
|
|
|
} else
|
|
|
|
*var = b;
|
2003-01-20 19:04:39 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2003-02-10 09:38:38 +00:00
|
|
|
static int parse_double(const AVOption *c, char *s, double *var)
|
2003-01-20 19:04:39 +00:00
|
|
|
{
|
|
|
|
double d;
|
|
|
|
if (!s)
|
|
|
|
return -1;
|
|
|
|
d = atof(s);
|
|
|
|
if (c->min != c->max) {
|
|
|
|
if (d < c->min || d > c->max) {
|
|
|
|
fprintf(stderr, "Option: %s double value: %f out of range <%f, %f>\n",
|
|
|
|
c->name, d, c->min, c->max);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
2003-02-10 09:38:38 +00:00
|
|
|
*var = d;
|
2003-01-20 19:04:39 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2003-02-10 09:38:38 +00:00
|
|
|
static int parse_int(const AVOption* c, char* s, int* var)
|
2003-01-20 19:04:39 +00:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
if (!s)
|
|
|
|
return -1;
|
|
|
|
i = atoi(s);
|
|
|
|
if (c->min != c->max) {
|
|
|
|
if (i < (int)c->min || i > (int)c->max) {
|
|
|
|
fprintf(stderr, "Option: %s integer value: %d out of range <%d, %d>\n",
|
|
|
|
c->name, i, (int)c->min, (int)c->max);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
2003-02-10 09:38:38 +00:00
|
|
|
*var = i;
|
2003-01-20 19:04:39 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2003-03-07 13:48:02 +00:00
|
|
|
static int parse_string(const AVOption *c, char *s, void* strct, char **var)
|
2003-01-20 19:04:39 +00:00
|
|
|
{
|
|
|
|
if (!s)
|
|
|
|
return -1;
|
|
|
|
|
2003-02-10 09:38:38 +00:00
|
|
|
if (c->type == FF_OPT_TYPE_RCOVERRIDE) {
|
2003-01-20 19:04:39 +00:00
|
|
|
int sf, ef, qs;
|
|
|
|
float qf;
|
|
|
|
if (sscanf(s, "%d,%d,%d,%f", &sf, &ef, &qs, &qf) == 4 && sf < ef) {
|
2003-03-07 13:48:02 +00:00
|
|
|
AVCodecContext *avctx = (AVCodecContext *) strct;
|
2003-02-10 09:38:38 +00:00
|
|
|
RcOverride *o;
|
|
|
|
avctx->rc_override = av_realloc(avctx->rc_override,
|
|
|
|
sizeof(RcOverride) * (avctx->rc_override_count + 1));
|
|
|
|
o = avctx->rc_override + avctx->rc_override_count++;
|
2003-01-20 19:04:39 +00:00
|
|
|
o->start_frame = sf;
|
|
|
|
o->end_frame = ef;
|
|
|
|
o->qscale = qs;
|
|
|
|
o->quality_factor = qf;
|
|
|
|
|
|
|
|
//printf("parsed Rc: %d,%d,%d,%f (%d)\n", sf,ef,qs,qf, avctx->rc_override_count);
|
|
|
|
} else {
|
|
|
|
printf("incorrect/unparsable Rc: \"%s\"\n", s);
|
|
|
|
}
|
|
|
|
} else
|
2003-02-10 09:38:38 +00:00
|
|
|
*var = av_strdup(s);
|
2003-01-20 19:04:39 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2003-03-07 13:48:02 +00:00
|
|
|
int avoption_parse(void* strct, const AVOption* list, const char *opts)
|
2003-01-20 19:04:39 +00:00
|
|
|
{
|
2003-02-10 09:38:38 +00:00
|
|
|
int r = 0;
|
|
|
|
char* dopts = av_strdup(opts);
|
|
|
|
if (dopts) {
|
|
|
|
char *str = dopts;
|
|
|
|
|
|
|
|
while (str && *str && r == 0) {
|
|
|
|
const AVOption *stack[FF_OPT_MAX_DEPTH];
|
2003-03-07 13:48:02 +00:00
|
|
|
const AVOption *c = list;
|
2003-02-10 09:38:38 +00:00
|
|
|
int depth = 0;
|
|
|
|
char* e = strchr(str, ':');
|
|
|
|
char* p;
|
|
|
|
if (e)
|
|
|
|
*e++ = 0;
|
|
|
|
|
|
|
|
p = strchr(str, '=');
|
|
|
|
if (p)
|
|
|
|
*p++ = 0;
|
|
|
|
|
|
|
|
// going through option structures
|
|
|
|
for (;;) {
|
|
|
|
if (!c->name) {
|
2003-03-07 13:48:02 +00:00
|
|
|
if (c->help) {
|
2003-02-10 09:38:38 +00:00
|
|
|
stack[depth++] = c;
|
2003-03-07 13:48:02 +00:00
|
|
|
c = (const AVOption*) c->help;
|
2003-02-10 09:38:38 +00:00
|
|
|
assert(depth > FF_OPT_MAX_DEPTH);
|
|
|
|
} else {
|
|
|
|
if (depth == 0)
|
|
|
|
break; // finished
|
|
|
|
c = stack[--depth];
|
|
|
|
c++;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (!strcmp(c->name, str)) {
|
2003-03-07 13:48:02 +00:00
|
|
|
void* ptr = (char*)strct + c->offset;
|
2003-02-10 09:38:38 +00:00
|
|
|
|
|
|
|
switch (c->type & FF_OPT_TYPE_MASK) {
|
|
|
|
case FF_OPT_TYPE_BOOL:
|
|
|
|
r = parse_bool(c, p, (int*)ptr);
|
|
|
|
break;
|
|
|
|
case FF_OPT_TYPE_DOUBLE:
|
|
|
|
r = parse_double(c, p, (double*)ptr);
|
|
|
|
break;
|
|
|
|
case FF_OPT_TYPE_INT:
|
|
|
|
r = parse_int(c, p, (int*)ptr);
|
|
|
|
break;
|
|
|
|
case FF_OPT_TYPE_STRING:
|
2003-03-07 13:48:02 +00:00
|
|
|
r = parse_string(c, p, strct, (char**)ptr);
|
2003-02-10 09:38:38 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
assert(0 == 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
c++;
|
|
|
|
}
|
2003-01-20 19:04:39 +00:00
|
|
|
}
|
2003-02-10 09:38:38 +00:00
|
|
|
str = e;
|
2003-01-20 19:04:39 +00:00
|
|
|
}
|
2003-02-10 09:38:38 +00:00
|
|
|
av_free(dopts);
|
|
|
|
}
|
|
|
|
return r;
|
2003-01-20 19:04:39 +00:00
|
|
|
}
|