Commit bec89a84 authored by Zdenek Kabelac's avatar Zdenek Kabelac

* more generic avoption_parse

* reused help ptr for sub ptr

Originally committed as revision 1642 to svn://svn.ffmpeg.org/ffmpeg/trunk
parent bdfcbbed
...@@ -413,9 +413,9 @@ int options_example(int argc, char* argv[]) ...@@ -413,9 +413,9 @@ int options_example(int argc, char* argv[])
int depth = 0; int depth = 0;
for (;;) { for (;;) {
if (!c->name) { if (!c->name) {
if (c->sub) { if (c->help) {
stack[depth++] = c; stack[depth++] = c;
c = c->sub; c = (const AVOption*)c->help;
} else { } else {
if (depth == 0) if (depth == 0)
break; // finished break; // finished
......
...@@ -829,10 +829,23 @@ typedef struct AVCodecContext { ...@@ -829,10 +829,23 @@ typedef struct AVCodecContext {
#define FF_EC_DEBLOCK 2 #define FF_EC_DEBLOCK 2
/** /**
* dsp_mask could be used to disable unwanted * dsp_mask could be add used to disable unwanted CPU features
* CPU features (i.e. MMX, SSE. ...) * CPU features (i.e. MMX, SSE. ...)
*/ *
unsigned dsp_mask; * with FORCE flag you may instead enable given CPU features
* (Dangerous: usable in case of misdetection, improper usage however will
* result into program crash)
*/
unsigned dsp_mask;
#define FF_MM_FORCE 0x80000000 /* force usage of selected flags (OR) */
/* lower 16 bits - CPU features */
#ifdef HAVE_MMX
#define FF_MM_MMX 0x0001 /* standard MMX */
#define FF_MM_3DNOW 0x0004 /* AMD 3DNOW */
#define FF_MM_MMXEXT 0x0002 /* SSE integer functions or AMD MMX ext */
#define FF_MM_SSE 0x0008 /* SSE functions */
#define FF_MM_SSE2 0x0010 /* PIV SSE2 functions */
#endif /* HAVE_MMX */
/** /**
* bits per sample/pixel from the demuxer (needed for huffyuv). * bits per sample/pixel from the demuxer (needed for huffyuv).
...@@ -1012,7 +1025,6 @@ typedef struct AVCodecContext { ...@@ -1012,7 +1025,6 @@ typedef struct AVCodecContext {
} AVCodecContext; } AVCodecContext;
//void avcodec_getopt(AVCodecContext* avctx, const char* str, avc_config_t** config);
/** /**
* AVOption. * AVOption.
...@@ -1020,8 +1032,8 @@ typedef struct AVCodecContext { ...@@ -1020,8 +1032,8 @@ typedef struct AVCodecContext {
typedef struct AVOption { typedef struct AVOption {
/** options' name */ /** options' name */
const char *name; /* if name is NULL, it indicates a link to next */ const char *name; /* if name is NULL, it indicates a link to next */
/** short English text help */ /** short English text help or const struct AVOption* subpointer */
const char *help; const char *help; // const struct AVOption* sub;
/** offset to context structure where the parsed value should be stored */ /** offset to context structure where the parsed value should be stored */
int offset; int offset;
/** options' type */ /** options' type */
...@@ -1046,11 +1058,18 @@ typedef struct AVOption { ...@@ -1046,11 +1058,18 @@ typedef struct AVOption {
* defval might select other then first argument as default * defval might select other then first argument as default
*/ */
const char *defstr; const char *defstr;
const struct AVOption *sub; /* used when name is NULL */
/* when it's NULL return to previous level (or finish reading) */
#define FF_OPT_MAX_DEPTH 10 #define FF_OPT_MAX_DEPTH 10
} AVOption; } AVOption;
/**
* Parse option(s) and sets fields in passed structure
* @param strct structure where the parsed results will be written
* @param list list with AVOptions
* @param opts string with options for parsing
*/
int avoption_parse(void* strct, const AVOption* list, const char* opts);
/** /**
* AVCodec. * AVCodec.
*/ */
......
...@@ -57,7 +57,7 @@ ...@@ -57,7 +57,7 @@
{ name, help, offsetof(AVCodecContext, field), FF_OPT_TYPE_STRING, .defval = val, .defstr = str } { name, help, offsetof(AVCodecContext, field), FF_OPT_TYPE_STRING, .defval = val, .defstr = str }
#define AVOPTION_CODEC_RCOVERRIDE(name, help, field) \ #define AVOPTION_CODEC_RCOVERRIDE(name, help, field) \
{ name, help, offsetof(AVCodecContext, field), FF_OPT_TYPE_RCOVERRIDE, .defval = 0, .defstr = NULL } { name, help, offsetof(AVCodecContext, field), FF_OPT_TYPE_RCOVERRIDE, .defval = 0, .defstr = NULL }
#define AVOPTION_SUB(ptr) { .name = NULL, .sub = ptr } #define AVOPTION_SUB(ptr) { .name = NULL, .help = (const char*)ptr }
#define AVOPTION_END() AVOPTION_SUB(NULL) #define AVOPTION_END() AVOPTION_SUB(NULL)
#endif /* HAVE_AV_CONFIG_H */ #endif /* HAVE_AV_CONFIG_H */
......
...@@ -12,10 +12,22 @@ ...@@ -12,10 +12,22 @@
#include "avcodec.h" #include "avcodec.h"
extern const AVOption common_options[2]; #ifdef HAVE_MMX
extern const AVOption common_options[3 + 5];
const AVOption common_options[2] = { #else
AVOPTION_CODEC_INT("common", "test", bit_rate, 0, 10, 0), extern const AVOption common_options[3];
#endif
const AVOption common_options[] = {
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
AVOPTION_END() AVOPTION_END()
}; };
...@@ -71,7 +83,7 @@ static int parse_int(const AVOption* c, char* s, int* var) ...@@ -71,7 +83,7 @@ static int parse_int(const AVOption* c, char* s, int* var)
return 0; return 0;
} }
static int parse_string(const AVOption *c, char *s, AVCodecContext *avctx, char **var) static int parse_string(const AVOption *c, char *s, void* strct, char **var)
{ {
if (!s) if (!s)
return -1; return -1;
...@@ -80,6 +92,7 @@ static int parse_string(const AVOption *c, char *s, AVCodecContext *avctx, char ...@@ -80,6 +92,7 @@ static int parse_string(const AVOption *c, char *s, AVCodecContext *avctx, char
int sf, ef, qs; int sf, ef, qs;
float qf; float qf;
if (sscanf(s, "%d,%d,%d,%f", &sf, &ef, &qs, &qf) == 4 && sf < ef) { if (sscanf(s, "%d,%d,%d,%f", &sf, &ef, &qs, &qf) == 4 && sf < ef) {
AVCodecContext *avctx = (AVCodecContext *) strct;
RcOverride *o; RcOverride *o;
avctx->rc_override = av_realloc(avctx->rc_override, avctx->rc_override = av_realloc(avctx->rc_override,
sizeof(RcOverride) * (avctx->rc_override_count + 1)); sizeof(RcOverride) * (avctx->rc_override_count + 1));
...@@ -98,13 +111,7 @@ static int parse_string(const AVOption *c, char *s, AVCodecContext *avctx, char ...@@ -98,13 +111,7 @@ static int parse_string(const AVOption *c, char *s, AVCodecContext *avctx, char
return 0; return 0;
} }
/** int avoption_parse(void* strct, const AVOption* list, const char *opts)
*
* \param codec codec for option parsing
* \param opts string with options for parsing
* \param avctx where to store parsed results
*/
int avcodec_parse(const AVCodec *codec, const char *opts, AVCodecContext *avctx)
{ {
int r = 0; int r = 0;
char* dopts = av_strdup(opts); char* dopts = av_strdup(opts);
...@@ -113,8 +120,8 @@ int avcodec_parse(const AVCodec *codec, const char *opts, AVCodecContext *avctx) ...@@ -113,8 +120,8 @@ int avcodec_parse(const AVCodec *codec, const char *opts, AVCodecContext *avctx)
while (str && *str && r == 0) { while (str && *str && r == 0) {
const AVOption *stack[FF_OPT_MAX_DEPTH]; const AVOption *stack[FF_OPT_MAX_DEPTH];
const AVOption *c = list;
int depth = 0; int depth = 0;
const AVOption *c = codec->options;
char* e = strchr(str, ':'); char* e = strchr(str, ':');
char* p; char* p;
if (e) if (e)
...@@ -127,9 +134,9 @@ int avcodec_parse(const AVCodec *codec, const char *opts, AVCodecContext *avctx) ...@@ -127,9 +134,9 @@ int avcodec_parse(const AVCodec *codec, const char *opts, AVCodecContext *avctx)
// going through option structures // going through option structures
for (;;) { for (;;) {
if (!c->name) { if (!c->name) {
if (c->sub) { if (c->help) {
stack[depth++] = c; stack[depth++] = c;
c = c->sub; c = (const AVOption*) c->help;
assert(depth > FF_OPT_MAX_DEPTH); assert(depth > FF_OPT_MAX_DEPTH);
} else { } else {
if (depth == 0) if (depth == 0)
...@@ -139,7 +146,7 @@ int avcodec_parse(const AVCodec *codec, const char *opts, AVCodecContext *avctx) ...@@ -139,7 +146,7 @@ int avcodec_parse(const AVCodec *codec, const char *opts, AVCodecContext *avctx)
} }
} else { } else {
if (!strcmp(c->name, str)) { if (!strcmp(c->name, str)) {
void* ptr = (char*)avctx + c->offset; void* ptr = (char*)strct + c->offset;
switch (c->type & FF_OPT_TYPE_MASK) { switch (c->type & FF_OPT_TYPE_MASK) {
case FF_OPT_TYPE_BOOL: case FF_OPT_TYPE_BOOL:
...@@ -152,7 +159,7 @@ int avcodec_parse(const AVCodec *codec, const char *opts, AVCodecContext *avctx) ...@@ -152,7 +159,7 @@ int avcodec_parse(const AVCodec *codec, const char *opts, AVCodecContext *avctx)
r = parse_int(c, p, (int*)ptr); r = parse_int(c, p, (int*)ptr);
break; break;
case FF_OPT_TYPE_STRING: case FF_OPT_TYPE_STRING:
r = parse_string(c, p, avctx, (char**)ptr); r = parse_string(c, p, strct, (char**)ptr);
break; break;
default: default:
assert(0 == 1); assert(0 == 1);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment