ad_libav: flush decoder output after last input packet
[mplayer.git] / m_config.h
blob24e80eb5388bf58eec28d002fd8068961c90de5c
1 /*
2 * This file is part of MPlayer.
4 * MPlayer is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * MPlayer is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with MPlayer; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 #ifndef MPLAYER_M_CONFIG_H
20 #define MPLAYER_M_CONFIG_H
22 #include <stdbool.h>
24 #include "bstr.h"
26 // m_config provides an API to manipulate the config variables in MPlayer.
27 // It makes use of the Options API to provide a context stack that
28 // allows saving and later restoring the state of all variables.
30 typedef struct m_profile m_profile_t;
31 struct m_option;
32 struct m_option_type;
34 // Config option save slot
35 struct m_config_save_slot {
36 // Previous level slot.
37 struct m_config_save_slot *prev;
38 // Level at which the save was made.
39 int lvl;
40 // We have to store other datatypes in this as well,
41 // so make sure we get properly aligned addresses.
42 unsigned char data[0] __attribute__ ((aligned(8)));
45 // Config option
46 struct m_config_option {
47 struct m_config_option *next;
48 // Full name (ie option:subopt).
49 char *name;
50 // Compiled without support for this option? If so set to name of feature
51 char *disabled_feature;
52 // Option description.
53 const struct m_option *opt;
54 // Save slot stack.
55 struct m_config_save_slot *slots;
56 // See \ref ConfigOptionFlags.
57 unsigned int flags;
60 // Profiles allow to predefine some sets of options that can then
61 // be applied later on with the internal -profile option.
63 // Config profile
64 struct m_profile {
65 struct m_profile *next;
66 char *name;
67 char *desc;
68 int num_opts;
69 // Option/value pair array.
70 char **opts;
73 enum option_source {
74 // Set when parsing from a config file.
75 M_CONFIG_FILE,
76 // Set when parsing command line arguments.
77 M_COMMAND_LINE,
78 // Set when pre-parsing the command line
79 M_COMMAND_LINE_PRE_PARSE,
82 // Config object
83 /** \ingroup Config */
84 typedef struct m_config {
85 // Registered options.
86 /** This contains all options and suboptions.
88 struct m_config_option *opts;
89 // Current stack level.
90 int lvl;
91 enum option_source mode;
92 // List of defined profiles.
93 struct m_profile *profiles;
94 // Depth when recursively including profiles.
95 int profile_depth;
97 void *optstruct; // struct mpopts or other
98 int (*includefunc)(struct m_config *conf, char *filename);
99 bool full; // main config with save slot handling etc
100 } m_config_t;
103 // Set if an option has been set at the current level.
104 #define M_CFG_OPT_SET (1 << 0)
106 // Set if another option already uses the same variable.
107 #define M_CFG_OPT_ALIAS (1 << 1)
109 // Create a new config object.
110 struct m_config *
111 m_config_new(void *optstruct,
112 int includefunc(struct m_config *conf, char *filename));
114 struct m_config *m_config_simple(const struct m_option *options);
116 void m_config_initialize(struct m_config *conf, void *optstruct);
118 // Free a config object.
119 void m_config_free(struct m_config *config);
121 /* Push a new context.
122 * \param config The config object.
124 void m_config_push(struct m_config *config);
126 /* Pop the current context restoring the previous context state.
127 * \param config The config object.
129 void m_config_pop(struct m_config *config);
131 /* Register some options to be used.
132 * \param config The config object.
133 * \param args An array of \ref m_option struct.
134 * \return 1 on success, 0 on failure.
136 int m_config_register_options(struct m_config *config,
137 const struct m_option *args);
139 /* Set an option.
140 * \param config The config object.
141 * \param name The option's name.
142 * \param param The value of the option, can be NULL.
143 * \param ambiguous_param: old style cmdline option, "param" may be a
144 parameter to this option or something entirely unrelated
145 * \return See \ref OptionParserReturn.
147 int m_config_set_option(struct m_config *config, struct bstr name,
148 struct bstr param, bool ambiguous_param);
150 static inline int m_config_set_option0(struct m_config *config,
151 const char *name, const char *param,
152 bool ambiguous)
154 return m_config_set_option(config, bstr(name), bstr(param), ambiguous);
157 /* Check if an option setting is valid.
158 * Same as above m_config_set_option() but doesn't actually set anything.
160 int m_config_check_option(struct m_config *config, struct bstr name,
161 struct bstr param, bool ambiguous_param);
163 static inline int m_config_check_option0(struct m_config *config,
164 const char *name, const char *param,
165 bool ambiguous)
167 return m_config_check_option(config, bstr(name), bstr(param), ambiguous);
170 int m_config_parse_suboptions(struct m_config *config, void *optstruct,
171 char *name, char *subopts);
174 /* Get the option matching the given name.
175 * \param config The config object.
176 * \param name The option's name.
178 const struct m_option *m_config_get_option(const struct m_config *config,
179 struct bstr name);
181 /* Print a list of all registered options.
182 * \param config The config object.
184 void m_config_print_option_list(const struct m_config *config);
187 /* Find the profile with the given name.
188 * \param config The config object.
189 * \param arg The profile's name.
190 * \return The profile object or NULL.
192 struct m_profile *m_config_get_profile(const struct m_config *config,
193 char *name);
195 /* Get the profile with the given name, creating it if necessary.
196 * \param config The config object.
197 * \param arg The profile's name.
198 * \return The profile object.
200 struct m_profile *m_config_add_profile(struct m_config *config, char *name);
202 /* Set the description of a profile.
203 * Used by the config file parser when defining a profile.
205 * \param p The profile object.
206 * \param arg The profile's name.
208 void m_profile_set_desc(struct m_profile *p, char *desc);
210 /* Add an option to a profile.
211 * Used by the config file parser when defining a profile.
213 * \param config The config object.
214 * \param p The profile object.
215 * \param name The option's name.
216 * \param val The option's value.
218 int m_config_set_profile_option(struct m_config *config, struct m_profile *p,
219 char *name, char *val);
221 /* Enables profile usage
222 * Used by the config file parser when loading a profile.
224 * \param config The config object.
225 * \param p The profile object.
227 void m_config_set_profile(struct m_config *config, struct m_profile *p);
229 #endif /* MPLAYER_M_CONFIG_H */