From 6d4b4c0de3152bc2deb2df09ec3e98e032124593 Mon Sep 17 00:00:00 2001 From: wm4 Date: Fri, 12 Jan 2018 04:02:55 +0100 Subject: audio: add global options for resampler defaults This is part of trying to get rid of --af-defaults, and the af resample filter. It requires a complicated mechanism to set the defaults on the resample filter for backwards compatibility. --- options/m_config.c | 17 ++++++++++++----- options/m_config.h | 3 --- options/m_option.h | 5 +++++ options/options.c | 5 ++++- options/options.h | 3 ++- 5 files changed, 23 insertions(+), 10 deletions(-) (limited to 'options') diff --git a/options/m_config.c b/options/m_config.c index 8bf7e0ef91..a487b64869 100644 --- a/options/m_config.c +++ b/options/m_config.c @@ -194,11 +194,18 @@ struct m_config *m_config_new(void *talloc_ctx, struct mp_log *log, return config; } -struct m_config *m_config_from_obj_desc(void *talloc_ctx, struct mp_log *log, - struct m_obj_desc *desc) +static struct m_config *m_config_from_obj_desc(void *talloc_ctx, + struct mp_log *log, + struct mpv_global *global, + struct m_obj_desc *desc) { - return m_config_new(talloc_ctx, log, desc->priv_size, desc->priv_defaults, - desc->options); + struct m_config *c = + m_config_new(talloc_ctx, log, desc->priv_size, desc->priv_defaults, + desc->options); + c->global = global; + if (desc->set_defaults && c->global) + desc->set_defaults(c->global, c->optstruct); + return c; } // Like m_config_from_obj_desc(), but don't allocate option struct. @@ -260,7 +267,7 @@ 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) { - struct m_config *config = m_config_from_obj_desc(ta_parent, log, desc); + struct m_config *config = m_config_from_obj_desc(ta_parent, log, global, desc); for (int n = 0; defaults && defaults[n].name; n++) { struct m_obj_settings *entry = &defaults[n]; diff --git a/options/m_config.h b/options/m_config.h index 6c4e9b759f..80aeaef789 100644 --- a/options/m_config.h +++ b/options/m_config.h @@ -123,9 +123,6 @@ struct m_config *m_config_new(void *talloc_ctx, struct mp_log *log, // mpv_global. Expected to be called at early init on the main m_config. void m_config_create_shadow(struct m_config *config); -struct m_config *m_config_from_obj_desc(void *talloc_ctx, struct mp_log *log, - struct m_obj_desc *desc); - struct m_config *m_config_from_obj_desc_noalloc(void *talloc_ctx, struct mp_log *log, struct m_obj_desc *desc); diff --git a/options/m_option.h b/options/m_option.h index a1039e2a82..405b59da0a 100644 --- a/options/m_option.h +++ b/options/m_option.h @@ -32,6 +32,7 @@ typedef struct m_option m_option_t; struct m_config; struct mp_log; struct mpv_node; +struct mpv_global; ///////////////////////////// Options types declarations //////////////////// @@ -129,6 +130,10 @@ struct m_obj_desc { bool hidden; // Callback to print custom help if "help" is passed void (*print_help)(struct mp_log *log); + // Callback that allows you to override the static default values. The + // pointer p points to the struct described by options/priv_size, with + // priv_defaults already applied. You can write to it to set any defaults. + void (*set_defaults)(struct mpv_global *global, void *p); // Set by m_obj_list_find(). If the requested name is an old alias, this // is set to the old name (while the name field uses the new name). const char *replaced_name; diff --git a/options/options.c b/options/options.c index c0697e8e71..1de76f53e4 100644 --- a/options/options.c +++ b/options/options.c @@ -94,6 +94,8 @@ extern const struct m_sub_options angle_conf; extern const struct m_sub_options cocoa_conf; extern const struct m_sub_options android_conf; +extern const struct m_sub_options resample_config; + static const struct m_sub_options screenshot_conf = { .opts = image_writer_opts, .size = sizeof(struct image_writer_opts), @@ -474,7 +476,6 @@ const m_option_t mp_opts[] = { OPT_INTRANGE("audio-samplerate", force_srate, UPDATE_AUDIO, 1000, 16*48000), OPT_CHANNELS("audio-channels", audio_output_channels, UPDATE_AUDIO), OPT_AUDIOFORMAT("audio-format", audio_output_format, UPDATE_AUDIO), - OPT_FLAG("audio-normalize-downmix", audio_normalize, UPDATE_AUDIO), OPT_DOUBLE("speed", playback_speed, M_OPT_RANGE, .min = 0.01, .max = 100.0), OPT_FLAG("audio-pitch-correction", pitch_correction, 0), @@ -691,6 +692,8 @@ const m_option_t mp_opts[] = { OPT_STRING("record-file", record_file, M_OPT_FILE), + OPT_SUBSTRUCT("", resample_opts, resample_config, 0), + OPT_SUBSTRUCT("", input_opts, input_config, 0), OPT_SUBSTRUCT("", vo, vo_sub_opts, 0), diff --git a/options/options.h b/options/options.h index 38afc1c831..424a1c8f0e 100644 --- a/options/options.h +++ b/options/options.h @@ -275,7 +275,6 @@ typedef struct MPOpts { struct m_channels audio_output_channels; int audio_output_format; - int audio_normalize; int force_srate; double playback_speed; int pitch_correction; @@ -331,6 +330,8 @@ typedef struct MPOpts { int wingl_dwm_flush; + struct mp_resample_opts *resample_opts; + struct gl_video_opts *gl_video_opts; struct angle_opts *angle_opts; struct opengl_opts *opengl_opts; -- cgit v1.2.3