1
0
mirror of https://github.com/mpv-player/mpv synced 2024-12-23 23:32:26 +00:00

m_config: add function to copy all options

Needed to copy the global option struct in the next commit.
This commit is contained in:
wm4 2014-10-06 21:20:10 +02:00
parent f440c0626e
commit d26104351b
3 changed files with 25 additions and 1 deletions

View File

@ -196,7 +196,8 @@ struct m_config *m_config_new(void *talloc_ctx, struct mp_log *log,
{
struct m_config *config = talloc(talloc_ctx, struct m_config);
talloc_set_destructor(config, config_destroy);
*config = (struct m_config) {.log = log};
*config = (struct m_config)
{.log = log, .size = size, .defaults = defaults, .options = options};
// size==0 means a dummy object is created
if (size) {
config->optstruct = talloc_zero_size(config, size);
@ -907,6 +908,18 @@ void *m_sub_options_copy(void *talloc_ctx, const struct m_sub_options *opts,
return new;
}
struct m_config *m_config_dup(void *talloc_ctx, struct m_config *config)
{
struct m_config *new = m_config_new(talloc_ctx, config->log, config->size,
config->defaults, config->options);
assert(new->num_opts == config->num_opts);
for (int n = 0; n < new->num_opts; n++) {
assert(new->opts[n].opt->type == config->opts[n].opt->type);
m_option_copy(new->opts[n].opt, new->opts[n].data, config->opts[n].data);
}
return new;
}
// This is used for printing error messages on unknown options.
static const char *const replaced_opts =
"|a52drc#--ad-lavc-ac3drc=level"

View File

@ -55,6 +55,11 @@ typedef struct m_config {
struct m_config_option *opts; // all options, even suboptions
int num_opts;
// Creation parameters
size_t size;
const void *defaults;
const struct m_option *options;
// List of defined profiles.
struct m_profile *profiles;
// Depth when recursively including profiles.
@ -87,6 +92,9 @@ struct m_config *m_config_new(void *talloc_ctx, struct mp_log *log,
size_t size, const void *defaults,
const struct m_option *options);
// (Warning: new object references config->log and others.)
struct m_config *m_config_dup(void *talloc_ctx, struct m_config *config);
struct m_config *m_config_from_obj_desc(void *talloc_ctx, struct mp_log *log,
struct m_obj_desc *desc);

View File

@ -446,6 +446,9 @@ int mp_initialize(struct MPContext *mpctx)
if (!mpctx->playlist->current)
mpctx->playlist->current = mpctx->playlist->first;
//struct m_config *new = m_config_dup(NULL, mpctx->mconfig);
//talloc_free(new);
MP_STATS(mpctx, "end init");
return 0;