Commit 7a1d466f authored by Max Kellermann's avatar Max Kellermann

DecoderPlugin: pass config_param reference

parent 83f4c48c
...@@ -201,8 +201,7 @@ decoder_plugin_config(const char *plugin_name) ...@@ -201,8 +201,7 @@ decoder_plugin_config(const char *plugin_name)
const struct config_param *param = NULL; const struct config_param *param = NULL;
while ((param = config_get_next_param(CONF_DECODER, param)) != NULL) { while ((param = config_get_next_param(CONF_DECODER, param)) != NULL) {
const char *name = const char *name = param->GetBlockValue("plugin");
config_get_block_string(param, "plugin", NULL);
if (name == NULL) if (name == NULL)
MPD_ERROR("decoder configuration without 'plugin' name in line %d", MPD_ERROR("decoder configuration without 'plugin' name in line %d",
param->line); param->line);
...@@ -216,16 +215,20 @@ decoder_plugin_config(const char *plugin_name) ...@@ -216,16 +215,20 @@ decoder_plugin_config(const char *plugin_name)
void decoder_plugin_init_all(void) void decoder_plugin_init_all(void)
{ {
struct config_param empty;
for (unsigned i = 0; decoder_plugins[i] != NULL; ++i) { for (unsigned i = 0; decoder_plugins[i] != NULL; ++i) {
const struct decoder_plugin *plugin = decoder_plugins[i]; const struct decoder_plugin *plugin = decoder_plugins[i];
const struct config_param *param = const struct config_param *param =
decoder_plugin_config(plugin->name); decoder_plugin_config(plugin->name);
if (!config_get_block_bool(param, "enabled", true)) if (param == nullptr)
param = ∅
else if (!param->GetBlockValue("enabled", true))
/* the plugin is disabled in mpd.conf */ /* the plugin is disabled in mpd.conf */
continue; continue;
if (decoder_plugin_init(plugin, param)) if (decoder_plugin_init(plugin, *param))
decoder_plugins_enabled[i] = true; decoder_plugins_enabled[i] = true;
} }
} }
......
...@@ -42,7 +42,7 @@ struct decoder_plugin { ...@@ -42,7 +42,7 @@ struct decoder_plugin {
* @return true if the plugin was initialized successfully, * @return true if the plugin was initialized successfully,
* false if the plugin is not available * false if the plugin is not available
*/ */
bool (*init)(const struct config_param *param); bool (*init)(const config_param &param);
/** /**
* Deinitialize a decoder plugin which was initialized * Deinitialize a decoder plugin which was initialized
...@@ -112,7 +112,7 @@ struct decoder_plugin { ...@@ -112,7 +112,7 @@ struct decoder_plugin {
*/ */
static inline bool static inline bool
decoder_plugin_init(const struct decoder_plugin *plugin, decoder_plugin_init(const struct decoder_plugin *plugin,
const struct config_param *param) const config_param &param)
{ {
return plugin->init != nullptr return plugin->init != nullptr
? plugin->init(param) ? plugin->init(param)
......
...@@ -36,11 +36,11 @@ ...@@ -36,11 +36,11 @@
static unsigned sample_rate; static unsigned sample_rate;
static bool static bool
adplug_init(const struct config_param *param) adplug_init(const config_param &param)
{ {
GError *error = NULL; GError *error = NULL;
sample_rate = config_get_block_unsigned(param, "sample_rate", 48000); sample_rate = param.GetBlockValue("sample_rate", 48000u);
if (!audio_check_sample_rate(sample_rate, &error)) { if (!audio_check_sample_rate(sample_rate, &error)) {
g_warning("%s\n", error->message); g_warning("%s\n", error->message);
g_error_free(error); g_error_free(error);
......
...@@ -84,9 +84,9 @@ struct DsdiffMetaData { ...@@ -84,9 +84,9 @@ struct DsdiffMetaData {
static bool lsbitfirst; static bool lsbitfirst;
static bool static bool
dsdiff_init(const struct config_param *param) dsdiff_init(const config_param &param)
{ {
lsbitfirst = config_get_block_bool(param, "lsbitfirst", false); lsbitfirst = param.GetBlockValue("lsbitfirst", false);
return true; return true;
} }
......
...@@ -166,7 +166,7 @@ mpd_ffmpeg_stream_close(struct mpd_ffmpeg_stream *stream) ...@@ -166,7 +166,7 @@ mpd_ffmpeg_stream_close(struct mpd_ffmpeg_stream *stream)
} }
static bool static bool
ffmpeg_init(G_GNUC_UNUSED const struct config_param *param) ffmpeg_init(gcc_unused const config_param &param)
{ {
av_log_set_callback(mpd_ffmpeg_log_callback); av_log_set_callback(mpd_ffmpeg_log_callback);
......
...@@ -287,7 +287,7 @@ flac_decode(struct decoder * decoder, struct input_stream *input_stream) ...@@ -287,7 +287,7 @@ flac_decode(struct decoder * decoder, struct input_stream *input_stream)
} }
static bool static bool
oggflac_init(G_GNUC_UNUSED const struct config_param *param) oggflac_init(gcc_unused const config_param &param)
{ {
return !!FLAC_API_SUPPORTS_OGG_FLAC; return !!FLAC_API_SUPPORTS_OGG_FLAC;
} }
......
...@@ -71,20 +71,19 @@ fluidsynth_mpd_log_function(int level, char *message, G_GNUC_UNUSED void *data) ...@@ -71,20 +71,19 @@ fluidsynth_mpd_log_function(int level, char *message, G_GNUC_UNUSED void *data)
} }
static bool static bool
fluidsynth_init(const struct config_param *param) fluidsynth_init(const config_param &param)
{ {
GError *error = nullptr; GError *error = nullptr;
sample_rate = config_get_block_unsigned(param, "sample_rate", 48000); sample_rate = param.GetBlockValue("sample_rate", 48000u);
if (!audio_check_sample_rate(sample_rate, &error)) { if (!audio_check_sample_rate(sample_rate, &error)) {
g_warning("%s\n", error->message); g_warning("%s\n", error->message);
g_error_free(error); g_error_free(error);
return false; return false;
} }
soundfont_path = soundfont_path = param.GetBlockValue("soundfont",
config_get_block_string(param, "soundfont", "/usr/share/sounds/sf2/FluidR3_GM.sf2");
"/usr/share/sounds/sf2/FluidR3_GM.sf2");
fluid_set_log_function(LAST_LOG_LEVEL, fluid_set_log_function(LAST_LOG_LEVEL,
fluidsynth_mpd_log_function, nullptr); fluidsynth_mpd_log_function, nullptr);
......
...@@ -101,7 +101,7 @@ mad_fixed_to_24_buffer(int32_t *dest, const struct mad_synth *synth, ...@@ -101,7 +101,7 @@ mad_fixed_to_24_buffer(int32_t *dest, const struct mad_synth *synth,
} }
static bool static bool
mp3_plugin_init(G_GNUC_UNUSED const struct config_param *param) mp3_plugin_init(gcc_unused const config_param &param)
{ {
gapless_playback = config_get_bool(CONF_GAPLESS_MP3_PLAYBACK, gapless_playback = config_get_bool(CONF_GAPLESS_MP3_PLAYBACK,
DEFAULT_GAPLESS_MP3_PLAYBACK); DEFAULT_GAPLESS_MP3_PLAYBACK);
......
...@@ -106,15 +106,14 @@ static MDRIVER drv_mpd = { ...@@ -106,15 +106,14 @@ static MDRIVER drv_mpd = {
static unsigned mikmod_sample_rate; static unsigned mikmod_sample_rate;
static bool static bool
mikmod_decoder_init(const struct config_param *param) mikmod_decoder_init(const config_param &param)
{ {
static char params[] = ""; static char params[] = "";
mikmod_sample_rate = config_get_block_unsigned(param, "sample_rate", mikmod_sample_rate = param.GetBlockValue("sample_rate", 44100u);
44100);
if (!audio_valid_sample_rate(mikmod_sample_rate)) if (!audio_valid_sample_rate(mikmod_sample_rate))
MPD_ERROR("Invalid sample rate in line %d: %u", MPD_ERROR("Invalid sample rate in line %d: %u",
param->line, mikmod_sample_rate); param.line, mikmod_sample_rate);
md_device = 0; md_device = 0;
md_reverb = 0; md_reverb = 0;
......
...@@ -32,7 +32,7 @@ ...@@ -32,7 +32,7 @@
#define G_LOG_DOMAIN "mpg123" #define G_LOG_DOMAIN "mpg123"
static bool static bool
mpd_mpg123_init(G_GNUC_UNUSED const struct config_param *param) mpd_mpg123_init(gcc_unused const config_param &param)
{ {
mpg123_init(); mpg123_init();
......
...@@ -58,7 +58,7 @@ IsOpusTags(const ogg_packet &packet) ...@@ -58,7 +58,7 @@ IsOpusTags(const ogg_packet &packet)
} }
static bool static bool
mpd_opus_init(G_GNUC_UNUSED const struct config_param *param) mpd_opus_init(gcc_unused const config_param &param)
{ {
g_debug("%s", opus_get_version_string()); g_debug("%s", opus_get_version_string());
......
...@@ -35,13 +35,13 @@ extern "C" { ...@@ -35,13 +35,13 @@ extern "C" {
static constexpr unsigned WILDMIDI_SAMPLE_RATE = 48000; static constexpr unsigned WILDMIDI_SAMPLE_RATE = 48000;
static bool static bool
wildmidi_init(const struct config_param *param) wildmidi_init(const config_param &param)
{ {
const char *config_file; const char *config_file;
int ret; int ret;
config_file = config_get_block_string(param, "config_file", config_file = param.GetBlockValue("config_file",
"/etc/timidity/timidity.cfg"); "/etc/timidity/timidity.cfg");
if (!g_file_test(config_file, G_FILE_TEST_IS_REGULAR)) { if (!g_file_test(config_file, G_FILE_TEST_IS_REGULAR)) {
g_debug("configuration file does not exist: %s", config_file); g_debug("configuration file does not exist: %s", config_file);
return false; return false;
......
...@@ -83,24 +83,22 @@ sidplay_load_songlength_db(const char *path) ...@@ -83,24 +83,22 @@ sidplay_load_songlength_db(const char *path)
} }
static bool static bool
sidplay_init(const struct config_param *param) sidplay_init(const config_param &param)
{ {
/* read the songlengths database file */ /* read the songlengths database file */
songlength_file=config_get_block_string(param, songlength_file = param.GetBlockValue("songlength_database");
"songlength_database", NULL);
if (songlength_file != NULL) if (songlength_file != NULL)
songlength_database = sidplay_load_songlength_db(songlength_file); songlength_database = sidplay_load_songlength_db(songlength_file);
default_songlength=config_get_block_unsigned(param, default_songlength = param.GetBlockValue("default_songlength", 0u);
"default_songlength", 0);
all_files_are_containers=config_get_block_bool(param, all_files_are_containers =
"all_files_are_containers", true); param.GetBlockValue("all_files_are_containers", true);
path_with_subtune=g_pattern_spec_new( path_with_subtune=g_pattern_spec_new(
"*/" SUBTUNE_PREFIX "???.sid"); "*/" SUBTUNE_PREFIX "???.sid");
filter_setting=config_get_block_bool(param, "filter", true); filter_setting = param.GetBlockValue("filter", true);
return true; return true;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment