mirror of
https://github.com/mpv-player/mpv
synced 2025-01-13 02:16:40 +00:00
m_config: add some convenience functions
To be used by the following commits.
This commit is contained in:
parent
2c917219cf
commit
72c6bf1345
@ -1143,6 +1143,27 @@ void m_config_notify_change_co(struct m_config *config,
|
||||
mp_msg_update_msglevels(config->global);
|
||||
}
|
||||
|
||||
void *mp_get_config_group(void *ta_parent, struct mpv_global *global,
|
||||
const struct m_sub_options *group)
|
||||
{
|
||||
assert(ta_parent); // without you'd necessarily leak memory
|
||||
struct m_config_cache *cache = m_config_cache_alloc(ta_parent, global, group);
|
||||
return cache->opts;
|
||||
}
|
||||
|
||||
void mp_read_option_raw(struct mpv_global *global, const char *name,
|
||||
const struct m_option_type *type, void *dst)
|
||||
{
|
||||
struct m_config_shadow *shadow = global->config;
|
||||
struct m_config_option *co = m_config_get_co(shadow->root, bstr0(name));
|
||||
assert(co);
|
||||
assert(co->shadow_offset >= 0);
|
||||
assert(co->opt->type == type);
|
||||
|
||||
memset(dst, 0, co->opt->type->size);
|
||||
m_option_copy(co->opt, dst, shadow->data + co->shadow_offset);
|
||||
}
|
||||
|
||||
struct m_config *mp_get_root_config(struct mpv_global *global)
|
||||
{
|
||||
return global->config->root;
|
||||
|
@ -304,6 +304,20 @@ struct m_config_cache *m_config_cache_alloc(void *ta_parent,
|
||||
// data itself will (e.g. string options might be reallocated).
|
||||
bool m_config_cache_update(struct m_config_cache *cache);
|
||||
|
||||
// Like m_config_cache_alloc(), but return the struct (m_config_cache->opts)
|
||||
// directly, with no way to update the config.
|
||||
// Warning: does currently not set the child as its own talloc root, which
|
||||
// means the only way to free the struct is by freeing ta_parent.
|
||||
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);
|
||||
|
||||
struct m_config *mp_get_root_config(struct mpv_global *global);
|
||||
|
||||
#endif /* MPLAYER_M_CONFIG_H */
|
||||
|
Loading…
Reference in New Issue
Block a user