changeset 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 bbcb4fda2b86
children 74a46d77e061
files apiexample.c avcodec.h common.h opts.c
diffstat 4 files changed, 52 insertions(+), 26 deletions(-) [+]
line wrap: on
line diff
--- a/apiexample.c	Fri Mar 07 12:37:49 2003 +0000
+++ b/apiexample.c	Fri Mar 07 13:48:02 2003 +0000
@@ -413,9 +413,9 @@
 	int depth = 0;
 	for (;;) {
 	    if (!c->name) {
-		if (c->sub) {
+		if (c->help) {
 		    stack[depth++] = c;
-		    c = c->sub;
+		    c = (const AVOption*)c->help;
 		} else {
 		    if (depth == 0)
 			break; // finished
--- a/avcodec.h	Fri Mar 07 12:37:49 2003 +0000
+++ b/avcodec.h	Fri Mar 07 13:48:02 2003 +0000
@@ -829,10 +829,23 @@
 #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. ...)
+     *
+     * 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;
+    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).
@@ -1012,7 +1025,6 @@
 
 } AVCodecContext;
 
-//void avcodec_getopt(AVCodecContext* avctx, const char* str, avc_config_t** config);
 
 /**
  * AVOption.
@@ -1020,8 +1032,8 @@
 typedef struct AVOption {
     /** options' name */
     const char *name; /* if name is NULL, it indicates a link to next */
-    /** short English text help */
-    const char *help;
+    /** short English text help or const struct AVOption* subpointer */
+    const char *help; //	const struct AVOption* sub;
     /** offset to context structure where the parsed value should be stored */
     int offset;
     /** options' type */
@@ -1046,12 +1058,19 @@
      * defval might select other then first argument as default
      */
     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
 } 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.
  */
 typedef struct AVCodec {
--- a/common.h	Fri Mar 07 12:37:49 2003 +0000
+++ b/common.h	Fri Mar 07 13:48:02 2003 +0000
@@ -57,7 +57,7 @@
     { name, help, offsetof(AVCodecContext, field), FF_OPT_TYPE_STRING, .defval = val, .defstr = str }
 #define AVOPTION_CODEC_RCOVERRIDE(name, help, field) \
     { 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)
 
 #endif /* HAVE_AV_CONFIG_H */
--- a/opts.c	Fri Mar 07 12:37:49 2003 +0000
+++ b/opts.c	Fri Mar 07 13:48:02 2003 +0000
@@ -12,10 +12,22 @@
 
 #include "avcodec.h"
 
-extern const AVOption common_options[2];
+#ifdef HAVE_MMX
+extern const AVOption common_options[3 + 5];
+#else
+extern const AVOption common_options[3];
+#endif
 
-const AVOption common_options[2] = {
-    AVOPTION_CODEC_INT("common", "test", bit_rate, 0, 10, 0),
+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()
 };
 
@@ -71,7 +83,7 @@
     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)
 	return -1;
@@ -80,6 +92,7 @@
 	int sf, ef, qs;
 	float qf;
 	if (sscanf(s, "%d,%d,%d,%f", &sf, &ef, &qs, &qf) == 4 && sf < ef) {
+	    AVCodecContext *avctx = (AVCodecContext *) strct;
 	    RcOverride *o;
 	    avctx->rc_override = av_realloc(avctx->rc_override,
 					    sizeof(RcOverride) * (avctx->rc_override_count + 1));
@@ -98,13 +111,7 @@
     return 0;
 }
 
-/**
- *
- * \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 avoption_parse(void* strct, const AVOption* list, const char *opts)
 {
     int r = 0;
     char* dopts = av_strdup(opts);
@@ -113,8 +120,8 @@
 
 	while (str && *str && r == 0) {
 	    const AVOption *stack[FF_OPT_MAX_DEPTH];
+	    const AVOption *c = list;
 	    int depth = 0;
-	    const AVOption *c = codec->options;
 	    char* e = strchr(str, ':');
 	    char* p;
 	    if (e)
@@ -127,9 +134,9 @@
             // going through option structures
 	    for (;;) {
 		if (!c->name) {
-		    if (c->sub) {
+		    if (c->help) {
 			stack[depth++] = c;
-			c = c->sub;
+			c = (const AVOption*) c->help;
 			assert(depth > FF_OPT_MAX_DEPTH);
 		    } else {
 			if (depth == 0)
@@ -139,7 +146,7 @@
 		    }
 		} else {
 		    if (!strcmp(c->name, str)) {
-			void* ptr = (char*)avctx + c->offset;
+			void* ptr = (char*)strct + c->offset;
 
 			switch (c->type & FF_OPT_TYPE_MASK) {
 			case FF_OPT_TYPE_BOOL:
@@ -152,7 +159,7 @@
 			    r = parse_int(c, p, (int*)ptr);
 			    break;
 			case FF_OPT_TYPE_STRING:
-			    r = parse_string(c, p, avctx, (char**)ptr);
+			    r = parse_string(c, p, strct, (char**)ptr);
 			    break;
 			default:
 			    assert(0 == 1);