Revision bec89a84

View differences:

libavcodec/apiexample.c
413 413
	int depth = 0;
414 414
	for (;;) {
415 415
	    if (!c->name) {
416
		if (c->sub) {
416
		if (c->help) {
417 417
		    stack[depth++] = c;
418
		    c = c->sub;
418
		    c = (const AVOption*)c->help;
419 419
		} else {
420 420
		    if (depth == 0)
421 421
			break; // finished
libavcodec/avcodec.h
829 829
#define FF_EC_DEBLOCK     2
830 830

  
831 831
    /**
832
     * dsp_mask could be used to disable unwanted
832
     * dsp_mask could be add used to disable unwanted CPU features
833 833
     * CPU features (i.e. MMX, SSE. ...)
834
     */
835
     unsigned dsp_mask;
834
     *
835
     * with FORCE flag you may instead enable given CPU features
836
     * (Dangerous: usable in case of misdetection, improper usage however will
837
     * result into program crash)
838
     */
839
    unsigned dsp_mask;
840
#define FF_MM_FORCE	0x80000000 /* force usage of selected flags (OR) */
841
    /* lower 16 bits - CPU features */
842
#ifdef HAVE_MMX
843
#define FF_MM_MMX	0x0001 /* standard MMX */
844
#define FF_MM_3DNOW	0x0004 /* AMD 3DNOW */
845
#define FF_MM_MMXEXT	0x0002 /* SSE integer functions or AMD MMX ext */
846
#define FF_MM_SSE	0x0008 /* SSE functions */
847
#define FF_MM_SSE2	0x0010 /* PIV SSE2 functions */
848
#endif /* HAVE_MMX */
836 849

  
837 850
    /**
838 851
     * bits per sample/pixel from the demuxer (needed for huffyuv).
......
1012 1025

  
1013 1026
} AVCodecContext;
1014 1027

  
1015
//void avcodec_getopt(AVCodecContext* avctx, const char* str, avc_config_t** config);
1016 1028

  
1017 1029
/**
1018 1030
 * AVOption.
......
1020 1032
typedef struct AVOption {
1021 1033
    /** options' name */
1022 1034
    const char *name; /* if name is NULL, it indicates a link to next */
1023
    /** short English text help */
1024
    const char *help;
1035
    /** short English text help or const struct AVOption* subpointer */
1036
    const char *help; //	const struct AVOption* sub;
1025 1037
    /** offset to context structure where the parsed value should be stored */
1026 1038
    int offset;
1027 1039
    /** options' type */
......
1046 1058
     * defval might select other then first argument as default
1047 1059
     */
1048 1060
    const char *defstr;
1049
    const struct AVOption *sub; /* used when name is NULL */
1050
    /* when it's NULL return to previous level (or finish reading) */
1051 1061
#define FF_OPT_MAX_DEPTH 10
1052 1062
} AVOption;
1053 1063

  
1054 1064
/**
1065
 * Parse option(s) and sets fields in passed structure
1066
 * @param strct	structure where the parsed results will be written
1067
 * @param list  list with AVOptions
1068
 * @param opts	string with options for parsing
1069
 */
1070
int avoption_parse(void* strct, const AVOption* list, const char* opts);
1071

  
1072

  
1073
/**
1055 1074
 * AVCodec.
1056 1075
 */
1057 1076
typedef struct AVCodec {
libavcodec/common.h
57 57
    { name, help, offsetof(AVCodecContext, field), FF_OPT_TYPE_STRING, .defval = val, .defstr = str }
58 58
#define AVOPTION_CODEC_RCOVERRIDE(name, help, field) \
59 59
    { name, help, offsetof(AVCodecContext, field), FF_OPT_TYPE_RCOVERRIDE, .defval = 0, .defstr = NULL }
60
#define AVOPTION_SUB(ptr) { .name = NULL, .sub = ptr }
60
#define AVOPTION_SUB(ptr) { .name = NULL, .help = (const char*)ptr }
61 61
#define AVOPTION_END() AVOPTION_SUB(NULL)
62 62

  
63 63
#endif /* HAVE_AV_CONFIG_H */
libavcodec/opts.c
12 12

  
13 13
#include "avcodec.h"
14 14

  
15
extern const AVOption common_options[2];
16

  
17
const AVOption common_options[2] = {
18
    AVOPTION_CODEC_INT("common", "test", bit_rate, 0, 10, 0),
15
#ifdef HAVE_MMX
16
extern const AVOption common_options[3 + 5];
17
#else
18
extern const AVOption common_options[3];
19
#endif
20

  
21
const AVOption common_options[] = {
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 31
    AVOPTION_END()
20 32
};
21 33

  
......
71 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 88
    if (!s)
77 89
	return -1;
......
80 92
	int sf, ef, qs;
81 93
	float qf;
82 94
	if (sscanf(s, "%d,%d,%d,%f", &sf, &ef, &qs, &qf) == 4 && sf < ef) {
95
	    AVCodecContext *avctx = (AVCodecContext *) strct;
83 96
	    RcOverride *o;
84 97
	    avctx->rc_override = av_realloc(avctx->rc_override,
85 98
					    sizeof(RcOverride) * (avctx->rc_override_count + 1));
......
98 111
    return 0;
99 112
}
100 113

  
101
/**
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)
114
int avoption_parse(void* strct, const AVOption* list, const char *opts)
108 115
{
109 116
    int r = 0;
110 117
    char* dopts = av_strdup(opts);
......
113 120

  
114 121
	while (str && *str && r == 0) {
115 122
	    const AVOption *stack[FF_OPT_MAX_DEPTH];
123
	    const AVOption *c = list;
116 124
	    int depth = 0;
117
	    const AVOption *c = codec->options;
118 125
	    char* e = strchr(str, ':');
119 126
	    char* p;
120 127
	    if (e)
......
127 134
            // going through option structures
128 135
	    for (;;) {
129 136
		if (!c->name) {
130
		    if (c->sub) {
137
		    if (c->help) {
131 138
			stack[depth++] = c;
132
			c = c->sub;
139
			c = (const AVOption*) c->help;
133 140
			assert(depth > FF_OPT_MAX_DEPTH);
134 141
		    } else {
135 142
			if (depth == 0)
......
139 146
		    }
140 147
		} else {
141 148
		    if (!strcmp(c->name, str)) {
142
			void* ptr = (char*)avctx + c->offset;
149
			void* ptr = (char*)strct + c->offset;
143 150

  
144 151
			switch (c->type & FF_OPT_TYPE_MASK) {
145 152
			case FF_OPT_TYPE_BOOL:
......
152 159
			    r = parse_int(c, p, (int*)ptr);
153 160
			    break;
154 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 163
			    break;
157 164
			default:
158 165
			    assert(0 == 1);

Also available in: Unified diff