2010-01-30 23:24:23 +00:00
|
|
|
/*
|
2015-04-13 07:36:54 +00:00
|
|
|
* This file is part of mpv.
|
2010-01-30 23:24:23 +00:00
|
|
|
*
|
options: change license of most files to LGPL (except options.c/.h)
All authors of the current code have agreed (as far as this commit
requires).
options.c/options.h will take more effort, because it contains all the
option declarations, and thus is touched extremely often.
m_option.c is technically still GPL, because of commit 2c82d5a1d85378dd0
(michael has agreed to LGPL, but only once the core of mpv is LGPL).
The geometry parsing code in m_option.c was originally by someone who
could not be reached. However, it was heavily rewritten anyway, and only
the syntax remains (i.e. not copyright-relevant).
parse_commandline.c contains a change by "adland" (commit 1d0ac71ae8ba),
who could not be reached - this this specific part is GPL only.
Fortunately, it matters only for DVD (and even then is more like a hack,
but whatever).
There are some other relevant changes, but they have all been reverted,
moved somewhere else, deleted, or replaced.
2017-06-12 18:55:17 +00:00
|
|
|
* mpv is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
2010-01-30 23:24:23 +00:00
|
|
|
*
|
2015-04-13 07:36:54 +00:00
|
|
|
* mpv is distributed in the hope that it will be useful,
|
2010-01-30 23:24:23 +00:00
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
options: change license of most files to LGPL (except options.c/.h)
All authors of the current code have agreed (as far as this commit
requires).
options.c/options.h will take more effort, because it contains all the
option declarations, and thus is touched extremely often.
m_option.c is technically still GPL, because of commit 2c82d5a1d85378dd0
(michael has agreed to LGPL, but only once the core of mpv is LGPL).
The geometry parsing code in m_option.c was originally by someone who
could not be reached. However, it was heavily rewritten anyway, and only
the syntax remains (i.e. not copyright-relevant).
parse_commandline.c contains a change by "adland" (commit 1d0ac71ae8ba),
who could not be reached - this this specific part is GPL only.
Fortunately, it matters only for DVD (and even then is more like a hack,
but whatever).
There are some other relevant changes, but they have all been reverted,
moved somewhere else, deleted, or replaced.
2017-06-12 18:55:17 +00:00
|
|
|
* GNU Lesser General Public License for more details.
|
2010-01-30 23:24:23 +00:00
|
|
|
*
|
options: change license of most files to LGPL (except options.c/.h)
All authors of the current code have agreed (as far as this commit
requires).
options.c/options.h will take more effort, because it contains all the
option declarations, and thus is touched extremely often.
m_option.c is technically still GPL, because of commit 2c82d5a1d85378dd0
(michael has agreed to LGPL, but only once the core of mpv is LGPL).
The geometry parsing code in m_option.c was originally by someone who
could not be reached. However, it was heavily rewritten anyway, and only
the syntax remains (i.e. not copyright-relevant).
parse_commandline.c contains a change by "adland" (commit 1d0ac71ae8ba),
who could not be reached - this this specific part is GPL only.
Fortunately, it matters only for DVD (and even then is more like a hack,
but whatever).
There are some other relevant changes, but they have all been reverted,
moved somewhere else, deleted, or replaced.
2017-06-12 18:55:17 +00:00
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with mpv. If not, see <http://www.gnu.org/licenses/>.
|
2010-01-30 23:24:23 +00:00
|
|
|
*/
|
|
|
|
|
2008-02-22 09:09:46 +00:00
|
|
|
#ifndef MPLAYER_M_CONFIG_H
|
|
|
|
#define MPLAYER_M_CONFIG_H
|
2002-11-12 01:56:42 +00:00
|
|
|
|
2013-07-27 19:26:00 +00:00
|
|
|
#include <stddef.h>
|
2016-09-02 13:45:22 +00:00
|
|
|
#include <stdint.h>
|
2011-07-27 17:59:44 +00:00
|
|
|
#include <stdbool.h>
|
|
|
|
|
2014-08-29 10:09:04 +00:00
|
|
|
#include "misc/bstr.h"
|
2011-07-27 17:59:44 +00:00
|
|
|
|
2011-07-05 19:31:44 +00:00
|
|
|
// m_config provides an API to manipulate the config variables in MPlayer.
|
|
|
|
// It makes use of the Options API to provide a context stack that
|
|
|
|
// allows saving and later restoring the state of all variables.
|
|
|
|
|
2006-01-24 11:16:13 +00:00
|
|
|
typedef struct m_profile m_profile_t;
|
2002-11-12 01:56:42 +00:00
|
|
|
struct m_option;
|
|
|
|
struct m_option_type;
|
2012-08-06 15:45:17 +00:00
|
|
|
struct m_sub_options;
|
options: use m_config for options instead of m_struct
For some reason, both m_config and m_struct are somewhat similar, except
that m_config is much more powerful. m_config is used for VOs and some
other things, so to unify them. We plan to kick out m_struct and use
m_config for everything. (Unfortunately, m_config is also a bit more
bloated, so this commit isn't all that great, but it will allow to
reduce the option parser mess somewhat.)
This commit also switches all video filters to use the option macros.
One reason is that m_struct and m_config, even though they both use
m_option, store the offsets of the option fields differently (sigh...),
meaning the options defined for either are incompatible. It's easier to
switch everything in one go.
This commit will allow using the -vf option parser for other things,
like VOs and AOs.
2013-07-21 17:33:08 +00:00
|
|
|
struct m_obj_desc;
|
2013-11-30 23:12:10 +00:00
|
|
|
struct m_obj_settings;
|
2013-12-21 18:45:42 +00:00
|
|
|
struct mp_log;
|
2002-11-12 01:56:42 +00:00
|
|
|
|
2011-07-05 19:31:44 +00:00
|
|
|
// Config option
|
2002-11-12 01:56:42 +00:00
|
|
|
struct m_config_option {
|
2016-08-30 21:47:09 +00:00
|
|
|
bool is_hidden : 1; // Does not show up in help
|
2013-10-25 20:52:54 +00:00
|
|
|
bool is_set_from_cmdline : 1; // Set by user from command line
|
2016-09-23 19:24:50 +00:00
|
|
|
bool is_set_from_config : 1; // Set by a config file
|
2015-07-23 20:59:04 +00:00
|
|
|
bool is_set_locally : 1; // Has a backup entry
|
2014-12-11 00:04:15 +00:00
|
|
|
bool warning_was_printed : 1;
|
2016-09-02 13:45:22 +00:00
|
|
|
int16_t shadow_offset; // Offset into m_config_shadow.data
|
|
|
|
int16_t group; // Index into m_config.groups
|
2013-10-25 20:52:54 +00:00
|
|
|
const char *name; // Full name (ie option-subopt)
|
|
|
|
const struct m_option *opt; // Option description
|
|
|
|
void *data; // Raw value of the option
|
|
|
|
const void *default_data; // Raw default value
|
2002-11-12 01:56:42 +00:00
|
|
|
};
|
|
|
|
|
2011-07-05 19:31:44 +00:00
|
|
|
// Config object
|
2006-04-24 19:20:04 +00:00
|
|
|
/** \ingroup Config */
|
2002-11-12 01:56:42 +00:00
|
|
|
typedef struct m_config {
|
2013-12-21 18:45:42 +00:00
|
|
|
struct mp_log *log;
|
2015-11-04 14:44:37 +00:00
|
|
|
struct mpv_global *global; // can be NULL
|
2013-12-21 18:45:42 +00:00
|
|
|
|
2011-07-05 19:31:44 +00:00
|
|
|
// Registered options.
|
2013-07-27 19:26:00 +00:00
|
|
|
struct m_config_option *opts; // all options, even suboptions
|
2013-10-24 18:00:00 +00:00
|
|
|
int num_opts;
|
2013-07-27 19:26:00 +00:00
|
|
|
|
2014-10-06 19:20:10 +00:00
|
|
|
// Creation parameters
|
|
|
|
size_t size;
|
|
|
|
const void *defaults;
|
|
|
|
const struct m_option *options;
|
|
|
|
|
2011-07-05 19:31:44 +00:00
|
|
|
// List of defined profiles.
|
|
|
|
struct m_profile *profiles;
|
|
|
|
// Depth when recursively including profiles.
|
|
|
|
int profile_depth;
|
|
|
|
|
2013-07-31 18:44:16 +00:00
|
|
|
struct m_opt_backup *backup_opts;
|
|
|
|
|
2013-07-24 17:44:10 +00:00
|
|
|
bool use_profiles;
|
2013-11-23 20:35:03 +00:00
|
|
|
bool is_toplevel;
|
2013-12-21 18:27:19 +00:00
|
|
|
int (*includefunc)(void *ctx, char *filename, int flags);
|
|
|
|
void *includefunc_ctx;
|
2013-07-27 19:26:00 +00:00
|
|
|
|
2016-09-19 17:51:26 +00:00
|
|
|
// Can intercept option write accesses.
|
2016-09-17 18:48:22 +00:00
|
|
|
int (*option_set_callback)(void *ctx, struct m_config_option *co,
|
|
|
|
void *data, int flags);
|
|
|
|
void *option_set_callback_cb;
|
|
|
|
|
2016-09-19 17:51:26 +00:00
|
|
|
// Notification after an option was successfully written to.
|
|
|
|
// Uses flags as set in UPDATE_OPTS_MASK.
|
|
|
|
void (*option_change_callback)(void *ctx, struct m_config_option *co,
|
|
|
|
int flags);
|
|
|
|
void *option_change_callback_ctx;
|
|
|
|
|
2014-06-10 22:32:13 +00:00
|
|
|
// For the command line parser
|
|
|
|
int recursion_depth;
|
|
|
|
|
2013-07-27 19:26:00 +00:00
|
|
|
void *optstruct; // struct mpopts or other
|
2016-09-02 13:45:22 +00:00
|
|
|
|
|
|
|
int shadow_size;
|
|
|
|
|
|
|
|
// List of m_sub_options instances.
|
|
|
|
// Index 0 is the top-level and is always present.
|
|
|
|
struct m_config_group *groups;
|
|
|
|
int num_groups;
|
|
|
|
|
|
|
|
// Thread-safe shadow memory; only set for the main m_config.
|
|
|
|
struct m_config_shadow *shadow;
|
2002-11-12 01:56:42 +00:00
|
|
|
} m_config_t;
|
|
|
|
|
2011-07-05 19:31:44 +00:00
|
|
|
// Create a new config object.
|
2013-11-01 16:33:11 +00:00
|
|
|
// talloc_ctx: talloc parent context for the m_config allocation
|
2013-07-27 19:26:00 +00:00
|
|
|
// size: size of the optstruct (where option values are stored)
|
2013-10-25 13:31:47 +00:00
|
|
|
// size==0 creates a config object with no option struct allocated
|
2013-07-27 19:26:00 +00:00
|
|
|
// defaults: if not NULL, points to a struct of same type as optstruct, which
|
|
|
|
// contains default values for all options
|
|
|
|
// options: list of options. Each option defines a member of the optstruct
|
|
|
|
// and a corresponding option switch or sub-option field.
|
2013-07-31 18:45:06 +00:00
|
|
|
// suboptinit: if not NULL, initialize the suboption string (used for presets)
|
2013-07-27 19:26:00 +00:00
|
|
|
// Note that the m_config object will keep pointers to defaults and options.
|
2013-12-21 18:45:42 +00:00
|
|
|
struct m_config *m_config_new(void *talloc_ctx, struct mp_log *log,
|
|
|
|
size_t size, const void *defaults,
|
2013-10-24 20:20:16 +00:00
|
|
|
const struct m_option *options);
|
2012-05-17 00:31:11 +00:00
|
|
|
|
2016-09-02 13:45:22 +00:00
|
|
|
// Creates "backup" shadow memory for use with m_config_cache. Sets it on
|
|
|
|
// mpv_global. Expected to be called at early init on the main m_config.
|
|
|
|
void m_config_create_shadow(struct m_config *config);
|
|
|
|
|
2013-11-01 16:33:11 +00:00
|
|
|
struct m_config *m_config_from_obj_desc_noalloc(void *talloc_ctx,
|
2013-12-21 18:45:42 +00:00
|
|
|
struct mp_log *log,
|
2013-10-25 13:31:47 +00:00
|
|
|
struct m_obj_desc *desc);
|
|
|
|
|
2016-09-02 12:49:34 +00:00
|
|
|
struct m_config *m_config_from_obj_desc_and_args(void *ta_parent,
|
|
|
|
struct mp_log *log, struct mpv_global *global, struct m_obj_desc *desc,
|
|
|
|
const char *name, struct m_obj_settings *defaults, char **args);
|
2013-11-30 23:12:10 +00:00
|
|
|
|
2016-11-25 20:00:39 +00:00
|
|
|
void *m_config_group_from_desc(void *ta_parent, struct mp_log *log,
|
|
|
|
struct mpv_global *global, struct m_obj_desc *desc, const char *name);
|
|
|
|
|
2013-08-02 15:59:43 +00:00
|
|
|
// Make sure the option is backed up. If it's already backed up, do nothing.
|
|
|
|
// All backed up options can be restored with m_config_restore_backups().
|
|
|
|
void m_config_backup_opt(struct m_config *config, const char *opt);
|
|
|
|
|
|
|
|
// Call m_config_backup_opt() on all options.
|
|
|
|
void m_config_backup_all_opts(struct m_config *config);
|
|
|
|
|
|
|
|
// Restore all options backed up with m_config_backup_opt(), and delete the
|
|
|
|
// backups afterwards.
|
|
|
|
void m_config_restore_backups(struct m_config *config);
|
2002-11-12 01:56:42 +00:00
|
|
|
|
2012-09-21 07:22:25 +00:00
|
|
|
enum {
|
|
|
|
M_SETOPT_PRE_PARSE_ONLY = 1, // Silently ignore non-M_OPT_PRE_PARSE opt.
|
|
|
|
M_SETOPT_CHECK_ONLY = 2, // Don't set, just check name/value
|
|
|
|
M_SETOPT_FROM_CONFIG_FILE = 4, // Reject M_OPT_NOCFG opt. (print error)
|
2013-10-25 20:52:54 +00:00
|
|
|
M_SETOPT_FROM_CMDLINE = 8, // Mark as set by command line
|
|
|
|
M_SETOPT_BACKUP = 16, // Call m_config_backup_opt() before
|
|
|
|
M_SETOPT_PRESERVE_CMDLINE = 32, // Don't set if already marked as FROM_CMDLINE
|
2014-05-18 16:57:02 +00:00
|
|
|
M_SETOPT_NO_FIXED = 64, // Reject M_OPT_FIXED options
|
|
|
|
M_SETOPT_NO_PRE_PARSE = 128, // Reject M_OPT_PREPARSE options
|
2016-09-23 19:24:50 +00:00
|
|
|
M_SETOPT_NO_OVERWRITE = 256, // Skip options marked with FROM_*
|
2012-09-21 07:22:25 +00:00
|
|
|
};
|
|
|
|
|
2014-05-18 16:57:02 +00:00
|
|
|
// Flags for safe option setting during runtime.
|
2016-09-01 18:00:43 +00:00
|
|
|
#define M_SETOPT_RUNTIME M_SETOPT_NO_FIXED
|
2014-05-18 16:57:02 +00:00
|
|
|
|
2017-07-02 11:00:22 +00:00
|
|
|
int m_config_set_option_cli(struct m_config *config, struct bstr name,
|
2012-09-21 07:22:25 +00:00
|
|
|
struct bstr param, int flags);
|
|
|
|
|
2014-05-18 16:57:02 +00:00
|
|
|
int m_config_set_option_raw(struct m_config *config, struct m_config_option *co,
|
|
|
|
void *data, int flags);
|
|
|
|
|
2016-09-23 19:04:20 +00:00
|
|
|
void m_config_mark_co_flags(struct m_config_option *co, int flags);
|
|
|
|
|
2016-09-17 18:48:22 +00:00
|
|
|
int m_config_set_option_raw_direct(struct m_config *config,
|
|
|
|
struct m_config_option *co,
|
|
|
|
void *data, int flags);
|
|
|
|
|
2014-02-24 19:39:51 +00:00
|
|
|
struct mpv_node;
|
|
|
|
int m_config_set_option_node(struct m_config *config, bstr name,
|
2014-05-18 16:57:02 +00:00
|
|
|
struct mpv_node *data, int flags);
|
2014-02-24 19:39:51 +00:00
|
|
|
|
player: more option/property consistency fixes
Some properties had a different type from their equivalent options (such
as mute, volume, deinterlace, edition). This wasn't really sane, as raw
option values should be always within their bounds. On the other hand,
these properties use a different type to reflect runtime limits (such as
range of available editions), or simply to improve the "UI" (you don't
want to cycle throuhg the completely useless "auto" value when cycling
the "mute" property).
Handle this by making them always return the option type, but also
allowing them to provide a "constricted" type, which is used for UI
purposes. All M_PROPERTY_GET_CONSTRICTED_TYPE changes are related to
this.
One consequence is that you can set the volume property to arbitrary
high values just like with the --volume option, but using the "add"
command it still restricts it to the --volume-max range.
Also deprecate --chapter, as it is grossly incompatible to the chapter
property. We pondered renaming it to --chapters, or introducing a more
powerful --range option, but concluded that --start --end is actually
enough.
These changes appear to take care of the last gross property/option
incompatibilities, although there might still be a few lurking.
2016-09-18 14:06:12 +00:00
|
|
|
struct m_config_option *m_config_get_co_raw(const struct m_config *config,
|
|
|
|
struct bstr name);
|
2012-09-18 18:07:24 +00:00
|
|
|
struct m_config_option *m_config_get_co(const struct m_config *config,
|
|
|
|
struct bstr name);
|
|
|
|
|
2016-09-01 18:00:43 +00:00
|
|
|
int m_config_get_co_count(struct m_config *config);
|
|
|
|
struct m_config_option *m_config_get_co_index(struct m_config *config, int index);
|
|
|
|
|
options: use m_config for options instead of m_struct
For some reason, both m_config and m_struct are somewhat similar, except
that m_config is much more powerful. m_config is used for VOs and some
other things, so to unify them. We plan to kick out m_struct and use
m_config for everything. (Unfortunately, m_config is also a bit more
bloated, so this commit isn't all that great, but it will allow to
reduce the option parser mess somewhat.)
This commit also switches all video filters to use the option macros.
One reason is that m_struct and m_config, even though they both use
m_option, store the offsets of the option fields differently (sigh...),
meaning the options defined for either are incompatible. It's easier to
switch everything in one go.
This commit will allow using the -vf option parser for other things,
like VOs and AOs.
2013-07-21 17:33:08 +00:00
|
|
|
// Return the n-th option by position. n==0 is the first option. If there are
|
|
|
|
// less than (n + 1) options, return NULL.
|
|
|
|
const char *m_config_get_positional_option(const struct m_config *config, int n);
|
|
|
|
|
options: change handling of "no-" options yet again
Commit 4a40eed "options: change handling of "no-" options" generally
improved the handling of automatically added negation options
(recognizing "--no-opt", even though only "--opt" is declared in the
option list).
Unfortunately, one corner case was missed, which broke the option
"--input=no-default-bindings" (other suboptions, e.g. VO suboptions,
were not affected, and this is the only option where this mattered).
Instead of increasing the complexity further, use a completely different
approach: add the "--no-" options at runtime, and make them behave like
real options. This approach could be considered slightly less elegant,
because the code now has to worry about some option implementation
details rather than leaving it to the parser, but all in all the new
code is simpler and there are less weird corner cases to worry about.
2013-02-16 18:57:57 +00:00
|
|
|
// Return a hint to the option parser whether a parameter is/may be required.
|
|
|
|
// The option may still accept empty/non-empty parameters independent from
|
|
|
|
// this, and this function is useful only for handling ambiguous options like
|
|
|
|
// flags (e.g. "--a" is ok, "--a=yes" is also ok).
|
|
|
|
// Returns: error code (<0), or number of expected params (0, 1)
|
|
|
|
int m_config_option_requires_param(struct m_config *config, bstr name);
|
2012-09-20 01:32:01 +00:00
|
|
|
|
2016-09-02 13:45:22 +00:00
|
|
|
// Notify m_config_cache users that the option has (probably) changed its value.
|
|
|
|
void m_config_notify_change_co(struct m_config *config,
|
|
|
|
struct m_config_option *co);
|
2017-12-29 16:19:25 +00:00
|
|
|
// Like m_config_notify_change_co(), but automatically find the option by its
|
|
|
|
// pointer within the global option struct (config->optstruct). In practice,
|
|
|
|
// it means it works only on fields in MPContext.opts.
|
|
|
|
void m_config_notify_change_opt_ptr(struct m_config *config, void *ptr);
|
2016-09-02 13:45:22 +00:00
|
|
|
|
2016-09-02 13:59:40 +00:00
|
|
|
bool m_config_is_in_group(struct m_config *config,
|
|
|
|
const struct m_sub_options *group,
|
|
|
|
struct m_config_option *co);
|
|
|
|
|
2014-02-24 20:18:53 +00:00
|
|
|
// Return all (visible) option names as NULL terminated string list.
|
|
|
|
char **m_config_list_options(void *ta_parent, const struct m_config *config);
|
|
|
|
|
2016-09-10 14:29:24 +00:00
|
|
|
void m_config_print_option_list(const struct m_config *config, const char *name);
|
2002-11-12 12:39:05 +00:00
|
|
|
|
2006-04-24 19:20:04 +00:00
|
|
|
|
2011-07-05 19:31:44 +00:00
|
|
|
/* Find the profile with the given name.
|
|
|
|
* \param config The config object.
|
2006-04-24 19:20:04 +00:00
|
|
|
* \param arg The profile's name.
|
|
|
|
* \return The profile object or NULL.
|
|
|
|
*/
|
2013-07-27 19:26:00 +00:00
|
|
|
struct m_profile *m_config_get_profile0(const struct m_config *config,
|
|
|
|
char *name);
|
|
|
|
struct m_profile *m_config_get_profile(const struct m_config *config, bstr name);
|
2006-01-24 11:16:13 +00:00
|
|
|
|
2016-09-02 17:24:12 +00:00
|
|
|
// Apply and clear the default profile - it's the only profile that new config
|
|
|
|
// files do not simply append to (for configfile parser).
|
|
|
|
void m_config_finish_default_profile(struct m_config *config, int flags);
|
|
|
|
|
2011-07-05 19:31:44 +00:00
|
|
|
/* Get the profile with the given name, creating it if necessary.
|
|
|
|
* \param config The config object.
|
2006-04-24 19:20:04 +00:00
|
|
|
* \param arg The profile's name.
|
|
|
|
* \return The profile object.
|
|
|
|
*/
|
2011-07-05 19:31:44 +00:00
|
|
|
struct m_profile *m_config_add_profile(struct m_config *config, char *name);
|
2006-01-24 11:16:13 +00:00
|
|
|
|
2011-07-05 19:31:44 +00:00
|
|
|
/* Set the description of a profile.
|
|
|
|
* Used by the config file parser when defining a profile.
|
2009-07-06 23:26:13 +00:00
|
|
|
*
|
2006-04-24 19:20:04 +00:00
|
|
|
* \param p The profile object.
|
|
|
|
* \param arg The profile's name.
|
|
|
|
*/
|
2013-10-14 21:37:58 +00:00
|
|
|
void m_profile_set_desc(struct m_profile *p, bstr desc);
|
2006-01-24 11:16:13 +00:00
|
|
|
|
2011-07-05 19:31:44 +00:00
|
|
|
/* Add an option to a profile.
|
|
|
|
* Used by the config file parser when defining a profile.
|
2009-07-06 23:26:13 +00:00
|
|
|
*
|
2006-04-24 19:20:04 +00:00
|
|
|
* \param config The config object.
|
|
|
|
* \param p The profile object.
|
|
|
|
* \param name The option's name.
|
|
|
|
* \param val The option's value.
|
|
|
|
*/
|
2011-07-05 19:31:44 +00:00
|
|
|
int m_config_set_profile_option(struct m_config *config, struct m_profile *p,
|
2012-09-21 07:22:25 +00:00
|
|
|
bstr name, bstr val);
|
2006-01-24 11:16:13 +00:00
|
|
|
|
2011-07-05 19:31:44 +00:00
|
|
|
/* Enables profile usage
|
|
|
|
* Used by the config file parser when loading a profile.
|
2009-07-06 23:26:13 +00:00
|
|
|
*
|
2008-01-10 18:41:21 +00:00
|
|
|
* \param config The config object.
|
|
|
|
* \param p The profile object.
|
2013-08-02 15:59:43 +00:00
|
|
|
* \param flags M_SETOPT_* bits
|
2015-05-07 19:03:14 +00:00
|
|
|
* Returns error code (<0) or 0 on success
|
2008-01-10 18:41:21 +00:00
|
|
|
*/
|
2015-05-07 19:03:14 +00:00
|
|
|
int m_config_set_profile(struct m_config *config, char *name, int flags);
|
2006-04-24 19:20:04 +00:00
|
|
|
|
2016-08-28 17:42:03 +00:00
|
|
|
struct mpv_node m_config_get_profiles(struct m_config *config);
|
|
|
|
|
2016-09-02 13:45:22 +00:00
|
|
|
// This can be used to create and synchronize per-thread option structs,
|
|
|
|
// which then can be read without synchronization. No concurrent access to
|
|
|
|
// the cache itself is allowed.
|
|
|
|
struct m_config_cache {
|
|
|
|
// The struct as indicated by m_config_cache_alloc's group parameter.
|
|
|
|
void *opts;
|
|
|
|
|
|
|
|
// Internal.
|
|
|
|
struct m_config_shadow *shadow;
|
|
|
|
struct m_config *shadow_config;
|
|
|
|
long long ts;
|
|
|
|
int group;
|
options: add a thread-safe way to notify option updates
So far, we had a thread-safe way to read options, but no option update
notification mechanism. Everything was funneled though the main thread's
central mp_option_change_callback() function. For example, if the
panscan options were changed, the function called vo_control() with
VOCTRL_SET_PANSCAN to manually notify the VO thread of updates. This
worked, but's pretty inconvenient. Most of these problems come from the
fact that MPlayer was written as a single-threaded program.
This commit works towards a more flexible mechanism. It adds an update
callback to m_config_cache (the thing that is already used for
thread-safe access of global options).
This alone would still be rather inconvenient, at least in context of
VOs. Add another mechanism on top of it that uses mp_dispatch_queue, and
takes care of some annoying synchronization issues. We extend
mp_dispatch_queue itself to make this easier and slightly more
efficient.
As a first application, use this to reimplement certain VO scaling and
renderer options. The update_opts() function translates these to the
"old" VOCTRLs, though.
An annoyingly subtle issue is that m_config_cache's destructor now
releases pending notifications, and must be released before the
associated dispatch queue. Otherwise, it could happen that option
updates during e.g. VO destruction queue or run stale entries, which is
not expected.
Rather untested. The singly-linked list code in dispatch.c is probably
buggy, and I bet some aspects about synchronization are not entirely
sane.
2017-08-22 13:50:33 +00:00
|
|
|
bool in_list;
|
|
|
|
// --- Implicitly synchronized by setting/unsetting wakeup_cb.
|
|
|
|
struct mp_dispatch_queue *wakeup_dispatch_queue;
|
|
|
|
void (*wakeup_dispatch_cb)(void *ctx);
|
|
|
|
void *wakeup_dispatch_cb_ctx;
|
|
|
|
// --- Protected by shadow->lock
|
|
|
|
void (*wakeup_cb)(void *ctx);
|
|
|
|
void *wakeup_cb_ctx;
|
2016-09-02 13:45:22 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// Create a mirror copy from the global options.
|
options: add a thread-safe way to notify option updates
So far, we had a thread-safe way to read options, but no option update
notification mechanism. Everything was funneled though the main thread's
central mp_option_change_callback() function. For example, if the
panscan options were changed, the function called vo_control() with
VOCTRL_SET_PANSCAN to manually notify the VO thread of updates. This
worked, but's pretty inconvenient. Most of these problems come from the
fact that MPlayer was written as a single-threaded program.
This commit works towards a more flexible mechanism. It adds an update
callback to m_config_cache (the thing that is already used for
thread-safe access of global options).
This alone would still be rather inconvenient, at least in context of
VOs. Add another mechanism on top of it that uses mp_dispatch_queue, and
takes care of some annoying synchronization issues. We extend
mp_dispatch_queue itself to make this easier and slightly more
efficient.
As a first application, use this to reimplement certain VO scaling and
renderer options. The update_opts() function translates these to the
"old" VOCTRLs, though.
An annoyingly subtle issue is that m_config_cache's destructor now
releases pending notifications, and must be released before the
associated dispatch queue. Otherwise, it could happen that option
updates during e.g. VO destruction queue or run stale entries, which is
not expected.
Rather untested. The singly-linked list code in dispatch.c is probably
buggy, and I bet some aspects about synchronization are not entirely
sane.
2017-08-22 13:50:33 +00:00
|
|
|
// Keep in mind that a m_config_cache object is not thread-safe; it merely
|
|
|
|
// provides thread-safe access to the global options. All API functions for
|
|
|
|
// the same m_config_cache object must synchronized, unless otherwise noted.
|
2016-09-02 13:45:22 +00:00
|
|
|
// ta_parent: parent for the returned allocation
|
|
|
|
// global: option data source
|
|
|
|
// group: the option group to return. This can be NULL for the global option
|
|
|
|
// struct (MPOpts), or m_sub_options used in a certain OPT_SUBSTRUCT()
|
|
|
|
// item.
|
|
|
|
struct m_config_cache *m_config_cache_alloc(void *ta_parent,
|
|
|
|
struct mpv_global *global,
|
|
|
|
const struct m_sub_options *group);
|
|
|
|
|
options: add a thread-safe way to notify option updates
So far, we had a thread-safe way to read options, but no option update
notification mechanism. Everything was funneled though the main thread's
central mp_option_change_callback() function. For example, if the
panscan options were changed, the function called vo_control() with
VOCTRL_SET_PANSCAN to manually notify the VO thread of updates. This
worked, but's pretty inconvenient. Most of these problems come from the
fact that MPlayer was written as a single-threaded program.
This commit works towards a more flexible mechanism. It adds an update
callback to m_config_cache (the thing that is already used for
thread-safe access of global options).
This alone would still be rather inconvenient, at least in context of
VOs. Add another mechanism on top of it that uses mp_dispatch_queue, and
takes care of some annoying synchronization issues. We extend
mp_dispatch_queue itself to make this easier and slightly more
efficient.
As a first application, use this to reimplement certain VO scaling and
renderer options. The update_opts() function translates these to the
"old" VOCTRLs, though.
An annoyingly subtle issue is that m_config_cache's destructor now
releases pending notifications, and must be released before the
associated dispatch queue. Otherwise, it could happen that option
updates during e.g. VO destruction queue or run stale entries, which is
not expected.
Rather untested. The singly-linked list code in dispatch.c is probably
buggy, and I bet some aspects about synchronization are not entirely
sane.
2017-08-22 13:50:33 +00:00
|
|
|
// If any of the options in the group possibly changes, call this callback. The
|
|
|
|
// callback must not actually access the cache or anything option related.
|
|
|
|
// Instead, it must wake up the thread that normally accesses the cache.
|
|
|
|
void m_config_cache_set_wakeup_cb(struct m_config_cache *cache,
|
|
|
|
void (*cb)(void *ctx), void *cb_ctx);
|
|
|
|
|
|
|
|
// If any of the options in the group change, call this callback on the given
|
|
|
|
// dispatch queue. This is higher level than m_config_cache_set_wakeup_cb(),
|
|
|
|
// and you can do anything you want in the callback (assuming the dispatch
|
|
|
|
// queue is processed in the same thread that accesses m_config_cache API).
|
|
|
|
// To ensure clean shutdown, you must destroy the m_config_cache (or unset the
|
|
|
|
// callback) before the dispatch queue is destroyed.
|
|
|
|
void m_config_cache_set_dispatch_change_cb(struct m_config_cache *cache,
|
|
|
|
struct mp_dispatch_queue *dispatch,
|
|
|
|
void (*cb)(void *ctx), void *cb_ctx);
|
|
|
|
|
2016-09-02 13:45:22 +00:00
|
|
|
// Update the options in cache->opts to current global values. Return whether
|
|
|
|
// there was an update notification at all (which may or may not indicate that
|
|
|
|
// some options have changed).
|
|
|
|
// Keep in mind that while the cache->opts pointer does not change, the option
|
|
|
|
// data itself will (e.g. string options might be reallocated).
|
|
|
|
bool m_config_cache_update(struct m_config_cache *cache);
|
|
|
|
|
2016-09-02 13:58:15 +00:00
|
|
|
// Like m_config_cache_alloc(), but return the struct (m_config_cache->opts)
|
options: add a thread-safe way to notify option updates
So far, we had a thread-safe way to read options, but no option update
notification mechanism. Everything was funneled though the main thread's
central mp_option_change_callback() function. For example, if the
panscan options were changed, the function called vo_control() with
VOCTRL_SET_PANSCAN to manually notify the VO thread of updates. This
worked, but's pretty inconvenient. Most of these problems come from the
fact that MPlayer was written as a single-threaded program.
This commit works towards a more flexible mechanism. It adds an update
callback to m_config_cache (the thing that is already used for
thread-safe access of global options).
This alone would still be rather inconvenient, at least in context of
VOs. Add another mechanism on top of it that uses mp_dispatch_queue, and
takes care of some annoying synchronization issues. We extend
mp_dispatch_queue itself to make this easier and slightly more
efficient.
As a first application, use this to reimplement certain VO scaling and
renderer options. The update_opts() function translates these to the
"old" VOCTRLs, though.
An annoyingly subtle issue is that m_config_cache's destructor now
releases pending notifications, and must be released before the
associated dispatch queue. Otherwise, it could happen that option
updates during e.g. VO destruction queue or run stale entries, which is
not expected.
Rather untested. The singly-linked list code in dispatch.c is probably
buggy, and I bet some aspects about synchronization are not entirely
sane.
2017-08-22 13:50:33 +00:00
|
|
|
// directly, with no way to update the config. Basically this returns a copy
|
|
|
|
// with a snapshot of the current option values.
|
2016-09-02 13:58:15 +00:00
|
|
|
void *mp_get_config_group(void *ta_parent, struct mpv_global *global,
|
|
|
|
const struct m_sub_options *group);
|
|
|
|
|
|
|
|
// Read a single global option in a thread-safe way. For multiple options,
|
|
|
|
// use m_config_cache. The option must exist and match the provided type (the
|
|
|
|
// type is used as a sanity check only). Performs semi-expensive lookup.
|
|
|
|
void mp_read_option_raw(struct mpv_global *global, const char *name,
|
|
|
|
const struct m_option_type *type, void *dst);
|
|
|
|
|
2016-09-02 13:45:22 +00:00
|
|
|
struct m_config *mp_get_root_config(struct mpv_global *global);
|
|
|
|
|
2008-02-22 09:09:46 +00:00
|
|
|
#endif /* MPLAYER_M_CONFIG_H */
|