constant qscale was broken due to libavcodec changes, fix taken from ve_lavc.c
[mplayer/greg.git] / m_option.h
blobae386c0195fd50402d672850581d34cbe59ee789
1 #ifndef _M_OPTION_H
2 #define _M_OPTION_H
4 typedef struct m_option_type m_option_type_t;
5 typedef struct m_option m_option_t;
6 struct m_struct_st;
8 ///////////////////////////// Options types declarations ////////////////////////////
10 // Simple types
11 extern m_option_type_t m_option_type_flag;
12 extern m_option_type_t m_option_type_int;
13 extern m_option_type_t m_option_type_float;
14 extern m_option_type_t m_option_type_string;
15 extern m_option_type_t m_option_type_string_list;
16 extern m_option_type_t m_option_type_position;
18 extern m_option_type_t m_option_type_print;
19 extern m_option_type_t m_option_type_print_indirect;
20 extern m_option_type_t m_option_type_subconfig;
21 extern m_option_type_t m_option_type_imgfmt;
23 // Func based types
24 extern m_option_type_t m_option_type_func_full;
25 extern m_option_type_t m_option_type_func_param;
26 extern m_option_type_t m_option_type_func;
28 typedef void (*m_opt_default_func_t)(m_option_t *, char*);
29 typedef int (*m_opt_func_full_t)(m_option_t *, char *, char *);
30 typedef int (*m_opt_func_param_t)(m_option_t *, char *);
31 typedef int (*m_opt_func_t)(m_option_t *);
32 ///////////// Backward compat
33 typedef m_opt_default_func_t cfg_default_func_t;
34 typedef m_opt_func_full_t cfg_func_arg_param_t;
35 typedef m_opt_func_param_t cfg_func_param_t;
36 typedef m_opt_func_t cfg_func_t;
38 typedef struct {
39 void** list;
40 void* name_off;
41 void* info_off;
42 void* desc_off;
43 } m_obj_list_t;
45 typedef struct {
46 char* name;
47 char** attribs;
48 } m_obj_settings_t;
49 extern m_option_type_t m_option_type_obj_settings_list;
51 // Presets are mean to be used with options struct
54 typedef struct {
55 struct m_struct_st* in_desc;
56 struct m_struct_st* out_desc;
57 void* presets; // Pointer to an arry of struct defined by in_desc
58 void* name_off; // Offset of the preset name inside the in_struct
59 } m_obj_presets_t;
60 extern m_option_type_t m_option_type_obj_presets;
62 extern m_option_type_t m_option_type_custom_url;
64 typedef struct {
65 struct m_struct_st* desc; // Fields description
66 char separator; // Field separator to use
67 } m_obj_params_t;
68 extern m_option_type_t m_option_type_obj_params;
70 typedef struct {
71 int start;
72 int end;
73 } m_span_t;
74 extern m_obj_params_t m_span_params_def;
77 // FIXME: backward compatibility
78 #define CONF_TYPE_FLAG (&m_option_type_flag)
79 #define CONF_TYPE_INT (&m_option_type_int)
80 #define CONF_TYPE_FLOAT (&m_option_type_float)
81 #define CONF_TYPE_STRING (&m_option_type_string)
82 #define CONF_TYPE_FUNC (&m_option_type_func)
83 #define CONF_TYPE_FUNC_PARAM (&m_option_type_func_param)
84 #define CONF_TYPE_PRINT (&m_option_type_print)
85 #define CONF_TYPE_PRINT_INDIRECT (&m_option_type_print_indirect)
86 #define CONF_TYPE_FUNC_FULL (&m_option_type_func_full)
87 #define CONF_TYPE_SUBCONFIG (&m_option_type_subconfig)
88 #define CONF_TYPE_STRING_LIST (&m_option_type_string_list)
89 #define CONF_TYPE_POSITION (&m_option_type_position)
90 #define CONF_TYPE_IMGFMT (&m_option_type_imgfmt)
91 #define CONF_TYPE_SPAN (&m_option_type_span)
92 #define CONF_TYPE_OBJ_SETTINGS_LIST (&m_option_type_obj_settings_list)
93 #define CONF_TYPE_OBJ_PRESETS (&m_option_type_obj_presets)
94 #define CONF_TYPE_CUSTOM_URL (&m_option_type_custom_url)
95 #define CONF_TYPE_OBJ_PARAMS (&m_option_type_obj_params)
97 /////////////////////////////////////////////////////////////////////////////////////////////
99 struct m_option_type {
100 char* name;
101 char* comments; // syntax desc, etc
102 unsigned int size; // size needed for a save slot
103 unsigned int flags;
105 // parse is the only requiered function all others can be NULL
106 // If dst if non-NULL it should create/update the save slot
107 // If dst is NULL it should just test the validity of the arg if possible
108 // Src tell from where come this setting (ie cfg file, command line, playlist, ....
109 // It should return 1 if param was used, 0 if not.
110 // On error it must return 1 of the error code below
111 int (*parse)(m_option_t* opt,char *name, char *param, void* dst, int src);
112 // Print back a value in human form
113 char* (*print)(m_option_t* opt, void* val);
115 // These 3 will be a memcpy in 50% of the case, it's called to save/restore the status of
116 // the var it's there for complex type like CONF_TYPE_FUNC*
117 // update a save slot (dst) from the current value in the prog (src)
118 void (*save)(m_option_t* opt,void* dst, void* src);
119 // set the current value (dst) from a save slot
120 void (*set)(m_option_t* opt,void* dst, void* src);
121 // Copy betewen 2 slot (if NULL and size > 0 a memcpy will be used
122 void (*copy)(m_option_t* opt,void* dst, void* src);
123 // Free the data allocated for a save slot if needed
124 void (*free)(void* dst);
127 struct m_option {
128 char *name;
129 void *p;
130 m_option_type_t* type;
131 unsigned int flags;
132 double min,max;
133 // This used to be function pointer to hold a 'reverse to defaults' func.
134 // Nom it can be used to pass any type of extra args.
135 // Passing a 'default func' is still valid for all func based option types
136 void* priv; // Type dependent data (for all kind of extended setting)
140 //////////////////////////////// Option flags /////////////////////////////////
142 // Option flags
143 #define M_OPT_MIN (1<<0)
144 #define M_OPT_MAX (1<<1)
145 #define M_OPT_RANGE (M_OPT_MIN|M_OPT_MAX)
146 #define M_OPT_NOCFG (1<<2)
147 #define M_OPT_NOCMD (1<<3)
148 // This option is global : it won't be saved on push and the command
149 // line parser will set it when it's parsed (ie. it won't be set later)
150 // e.g options : -v, -quiet
151 #define M_OPT_GLOBAL (1<<4)
152 // Do not save this option : it won't be saved on push but the command
153 // line parser will put it with it's entry (ie : it may be set later)
154 // e.g options : -include
155 #define M_OPT_NOSAVE (1<<5)
156 // Emulate old behaviour by pushing the option only if it was set by the user
157 #define M_OPT_OLD (1<<6)
159 // FIXME: backward compatibility
160 #define CONF_MIN M_OPT_MIN
161 #define CONF_MAX M_OPT_MAX
162 #define CONF_RANGE M_OPT_RANGE
163 #define CONF_NOCFG M_OPT_NOCFG
164 #define CONF_NOCMD M_OPT_NOCMD
165 #define CONF_GLOBAL M_OPT_GLOBAL
166 #define CONF_NOSAVE M_OPT_NOSAVE
167 #define CONF_OLD M_OPT_OLD
170 ///////////////////////////// Option type flags ///////////////////////////////////
172 // These flags are for the parsers. The description here apply to the m_config_t
173 // based parsers (ie. cmd line and config file parsers)
174 // Some parser will refuse option types that have some of these flags
176 // This flag is used for the subconfig
177 // When this flag is set, opt->p should point to another m_option_t array
178 // Only the parse function will be called. If dst is set, it should create/update
179 // an array of char* containg opt/val pairs.
180 // Then the options in the child array will then be set automaticly.
181 // You can only affect the way suboption are parsed.
182 // Also note that suboptions may be directly accessed by using -option:subopt blah :-)
183 #define M_OPT_TYPE_HAS_CHILD (1<<0)
184 // If this flag is set the option type support option name with * at the end (used for -aa*)
185 // This only affect the option name matching, the option type have to implement
186 // the needed stuff.
187 #define M_OPT_TYPE_ALLOW_WILDCARD (1<<1)
188 // This flag indicate that the data is dynamicly allocated (opt->p point to a pointer)
189 // It enable a little hack wich replace the initial value by a dynamic copy
190 // in case the initial value is staticly allocated (pretty common with strings)
191 #define M_OPT_TYPE_DYNAMIC (1<<2)
192 /// If this is set the parse function doesn't directly return
193 // the wanted thing. Options use this if for some reasons they have to wait
194 // until the set call to be able to correctly set the target var.
195 // So for those types you have to first parse and then set the target var
196 // If this flag isn't set you can parse directly to the target var
197 // It's used for the callback based option as the callback call may append
198 // later on.
199 #define M_OPT_TYPE_INDIRECT (1<<3)
202 ///////////////////////////// Parser flags ////////////////////////////////////////
204 // Config mode : some parser type behave differently depending
205 // on config->mode value wich is passed in the src param of parse()
206 #define M_CONFIG_FILE 0
207 #define M_COMMAND_LINE 1
209 // Option parser error code
210 #define M_OPT_UNKNOWN -1
211 #define M_OPT_MISSING_PARAM -2
212 #define M_OPT_INVALID -3
213 #define M_OPT_OUT_OF_RANGE -4
214 #define M_OPT_PARSER_ERR -5
215 #define M_OPT_EXIT -6
217 // FIXME: backward compatibility
218 #define ERR_NOT_AN_OPTION M_OPT_UNKNOWN
219 #define ERR_MISSING_PARAM M_OPT_MISSING_PARAM
220 #define ERR_OUT_OF_RANGE M_OPT_OUT_OF_RANGE
221 #define ERR_FUNC_ERR M_OPT_PARSER_ERR
223 m_option_t* m_option_list_find(m_option_t* list,char* name);
225 inline static int
226 m_option_parse(m_option_t* opt,char *name, char *param, void* dst, int src) {
227 return opt->type->parse(opt,name,param,dst,src);
230 inline static char*
231 m_option_print(m_option_t* opt, void* val_ptr) {
232 if(opt->type->print)
233 return opt->type->print(opt,val_ptr);
234 else
235 return (char*)-1;
238 inline static void
239 m_option_save(m_option_t* opt,void* dst, void* src) {
240 if(opt->type->save)
241 opt->type->save(opt,dst,src);
244 inline static void
245 m_option_set(m_option_t* opt,void* dst, void* src) {
246 if(opt->type->set)
247 opt->type->set(opt,dst,src);
250 inline static void
251 m_option_copy(m_option_t* opt,void* dst, void* src) {
252 if(opt->type->copy)
253 opt->type->set(opt,dst,src);
254 else if(opt->type->size > 0)
255 memcpy(dst,src,opt->type->size);
258 inline static void
259 m_option_free(m_option_t* opt,void* dst) {
260 if(opt->type->free)
261 opt->type->free(dst);
264 #endif /* _M_OPTION_H */