aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2013-08-04 12:25:08 +0200
committerMax Kellermann <max@duempel.org>2013-08-04 14:07:49 +0200
commit81c3224076da6ad727debc6bab8a5422f7322451 (patch)
tree1da1912caa6c7ff863f7affeafae22e9e6004e8f
parent7a1d466fb279659048e80e2853a7906c90d73235 (diff)
downloadmpd-81c3224076da6ad727debc6bab8a5422f7322451.tar.gz
mpd-81c3224076da6ad727debc6bab8a5422f7322451.tar.xz
mpd-81c3224076da6ad727debc6bab8a5422f7322451.zip
OutputPlugin: pass config_param reference
-rw-r--r--src/ConfigData.hxx9
-rw-r--r--src/OutputAll.cxx13
-rw-r--r--src/OutputInit.cxx46
-rw-r--r--src/OutputInternal.hxx4
-rw-r--r--src/OutputPlugin.cxx2
-rw-r--r--src/OutputPlugin.hxx4
-rw-r--r--src/output/AlsaOutputPlugin.cxx28
-rw-r--r--src/output/AoOutputPlugin.cxx16
-rw-r--r--src/output/FifoOutputPlugin.cxx6
-rw-r--r--src/output/HttpdInternal.hxx2
-rw-r--r--src/output/HttpdOutputPlugin.cxx22
-rw-r--r--src/output/JackOutputPlugin.cxx27
-rw-r--r--src/output/NullOutputPlugin.cxx6
-rw-r--r--src/output/OSXOutputPlugin.cxx6
-rw-r--r--src/output/OpenALOutputPlugin.cxx7
-rw-r--r--src/output/OssOutputPlugin.cxx9
-rw-r--r--src/output/PipeOutputPlugin.cxx10
-rw-r--r--src/output/PulseOutputPlugin.cxx12
-rw-r--r--src/output/RecorderOutputPlugin.cxx14
-rw-r--r--src/output/RoarOutputPlugin.cxx10
-rw-r--r--src/output/ShoutOutputPlugin.cxx47
-rw-r--r--src/output/SolarisOutputPlugin.cxx6
-rw-r--r--src/output/WinmmOutputPlugin.cxx4
-rw-r--r--test/run_output.cxx5
24 files changed, 159 insertions, 156 deletions
diff --git a/src/ConfigData.hxx b/src/ConfigData.hxx
index 5e13d073c..d6b024b9b 100644
--- a/src/ConfigData.hxx
+++ b/src/ConfigData.hxx
@@ -80,6 +80,15 @@ struct config_param {
config_param &operator=(const config_param &) = delete;
+ /**
+ * Determine if this is a "null" instance, i.e. an empty
+ * object that was synthesized and not loaded from a
+ * configuration file.
+ */
+ bool IsNull() const {
+ return line == unsigned(-1);
+ }
+
gcc_nonnull_all
void AddBlockParam(const char *_name, const char *_value,
int _line=-1) {
diff --git a/src/OutputAll.cxx b/src/OutputAll.cxx
index a73afbbb6..2e721efa3 100644
--- a/src/OutputAll.cxx
+++ b/src/OutputAll.cxx
@@ -109,16 +109,23 @@ audio_output_all_init(struct player_control *pc)
num_audio_outputs = audio_output_config_count();
audio_outputs = g_new(struct audio_output *, num_audio_outputs);
+ const config_param empty;
+
for (i = 0; i < num_audio_outputs; i++)
{
unsigned int j;
param = config_get_next_param(CONF_AUDIO_OUTPUT, param);
+ if (param == nullptr) {
+ /* only allow param to be nullptr if there
+ just one audio output */
+ assert(i == 0);
+ assert(num_audio_outputs == 1);
- /* only allow param to be NULL if there just one audioOutput */
- assert(param || (num_audio_outputs == 1));
+ param = &empty;
+ }
- struct audio_output *output = audio_output_new(param, pc, &error);
+ struct audio_output *output = audio_output_new(*param, pc, &error);
if (output == NULL) {
if (param != NULL)
MPD_ERROR("line %i: %s",
diff --git a/src/OutputInit.cxx b/src/OutputInit.cxx
index cef4755c6..4ba33be1d 100644
--- a/src/OutputInit.cxx
+++ b/src/OutputInit.cxx
@@ -75,16 +75,17 @@ audio_output_detect(GError **error)
* This handles the deprecated options mixer_type (global) and
* mixer_enabled, if the mixer_type setting is not configured.
*/
+gcc_pure
static enum mixer_type
-audio_output_mixer_type(const struct config_param *param)
+audio_output_mixer_type(const config_param &param)
{
/* read the local "mixer_type" setting */
- const char *p = config_get_block_string(param, "mixer_type", NULL);
+ const char *p = param.GetBlockValue("mixer_type");
if (p != NULL)
return mixer_type_parse(p);
/* try the local "mixer_enabled" setting next (deprecated) */
- if (!config_get_block_bool(param, "mixer_enabled", true))
+ if (!param.GetBlockValue("mixer_enabled", true))
return MIXER_TYPE_NONE;
/* fall back to the global "mixer_type" setting (also
@@ -95,7 +96,7 @@ audio_output_mixer_type(const struct config_param *param)
static Mixer *
audio_output_load_mixer(struct audio_output *ao,
- const struct config_param *param,
+ const config_param &param,
const struct mixer_plugin *plugin,
Filter &filter_chain,
GError **error_r)
@@ -111,7 +112,7 @@ audio_output_load_mixer(struct audio_output *ao,
if (plugin == NULL)
return NULL;
- return mixer_new(plugin, ao, param, error_r);
+ return mixer_new(plugin, ao, &param, error_r);
case MIXER_TYPE_SOFTWARE:
mixer = mixer_new(&software_mixer_plugin, NULL, NULL, NULL);
@@ -129,7 +130,7 @@ audio_output_load_mixer(struct audio_output *ao,
bool
ao_base_init(struct audio_output *ao,
const struct audio_output_plugin *plugin,
- const struct config_param *param, GError **error_r)
+ const config_param &param, GError **error_r)
{
assert(ao != NULL);
assert(plugin != NULL);
@@ -140,19 +141,15 @@ ao_base_init(struct audio_output *ao,
GError *error = NULL;
- if (param) {
- const char *p;
-
- ao->name = config_get_block_string(param, AUDIO_OUTPUT_NAME,
- NULL);
+ if (!param.IsNull()) {
+ ao->name = param.GetBlockValue(AUDIO_OUTPUT_NAME);
if (ao->name == NULL) {
g_set_error(error_r, output_quark(), 0,
"Missing \"name\" configuration");
return false;
}
- p = config_get_block_string(param, AUDIO_OUTPUT_FORMAT,
- NULL);
+ const char *p = param.GetBlockValue(AUDIO_OUTPUT_FORMAT);
if (p != NULL) {
bool success =
audio_format_parse(ao->config_audio_format,
@@ -168,9 +165,9 @@ ao_base_init(struct audio_output *ao,
}
ao->plugin = plugin;
- ao->tags = config_get_block_bool(param, "tags", true);
- ao->always_on = config_get_block_bool(param, "always_on", false);
- ao->enabled = config_get_block_bool(param, "enabled", true);
+ ao->tags = param.GetBlockValue("tags", true);
+ ao->always_on = param.GetBlockValue("always_on", false);
+ ao->enabled = param.GetBlockValue("enabled", true);
ao->really_enabled = false;
ao->open = false;
ao->pause = false;
@@ -194,7 +191,7 @@ ao_base_init(struct audio_output *ao,
}
filter_chain_parse(*ao->filter,
- config_get_block_string(param, AUDIO_FILTERS, ""),
+ param.GetBlockValue(AUDIO_FILTERS, ""),
&error
);
@@ -219,25 +216,24 @@ ao_base_init(struct audio_output *ao,
}
static bool
-audio_output_setup(struct audio_output *ao, const struct config_param *param,
+audio_output_setup(struct audio_output *ao, const config_param &param,
GError **error_r)
{
/* create the replay_gain filter */
const char *replay_gain_handler =
- config_get_block_string(param, "replay_gain_handler",
- "software");
+ param.GetBlockValue("replay_gain_handler", "software");
if (strcmp(replay_gain_handler, "none") != 0) {
ao->replay_gain_filter = filter_new(&replay_gain_filter_plugin,
- param, NULL);
+ &param, NULL);
assert(ao->replay_gain_filter != NULL);
ao->replay_gain_serial = 0;
ao->other_replay_gain_filter = filter_new(&replay_gain_filter_plugin,
- param, NULL);
+ &param, NULL);
assert(ao->other_replay_gain_filter != NULL);
ao->other_replay_gain_serial = 0;
@@ -284,16 +280,16 @@ audio_output_setup(struct audio_output *ao, const struct config_param *param,
}
struct audio_output *
-audio_output_new(const struct config_param *param,
+audio_output_new(const config_param &param,
struct player_control *pc,
GError **error_r)
{
const struct audio_output_plugin *plugin;
- if (param) {
+ if (!param.IsNull()) {
const char *p;
- p = config_get_block_string(param, AUDIO_OUTPUT_TYPE, NULL);
+ p = param.GetBlockValue(AUDIO_OUTPUT_TYPE);
if (p == NULL) {
g_set_error(error_r, output_quark(), 0,
"Missing \"type\" configuration");
diff --git a/src/OutputInternal.hxx b/src/OutputInternal.hxx
index b23ec95b6..20e48279f 100644
--- a/src/OutputInternal.hxx
+++ b/src/OutputInternal.hxx
@@ -261,14 +261,14 @@ audio_output_command_is_finished(const struct audio_output *ao)
}
struct audio_output *
-audio_output_new(const struct config_param *param,
+audio_output_new(const config_param &param,
struct player_control *pc,
GError **error_r);
bool
ao_base_init(struct audio_output *ao,
const struct audio_output_plugin *plugin,
- const struct config_param *param, GError **error_r);
+ const config_param &param, GError **error_r);
void
ao_base_finish(struct audio_output *ao);
diff --git a/src/OutputPlugin.cxx b/src/OutputPlugin.cxx
index 00901aad2..7ac97cab9 100644
--- a/src/OutputPlugin.cxx
+++ b/src/OutputPlugin.cxx
@@ -23,7 +23,7 @@
struct audio_output *
ao_plugin_init(const struct audio_output_plugin *plugin,
- const struct config_param *param,
+ const config_param &param,
GError **error)
{
assert(plugin != NULL);
diff --git a/src/OutputPlugin.hxx b/src/OutputPlugin.hxx
index 4e19ffcfb..5be476b68 100644
--- a/src/OutputPlugin.hxx
+++ b/src/OutputPlugin.hxx
@@ -55,7 +55,7 @@ struct audio_output_plugin {
* @return NULL on error, or an opaque pointer to the plugin's
* data
*/
- struct audio_output *(*init)(const struct config_param *param,
+ struct audio_output *(*init)(const config_param &param,
GError **error);
/**
@@ -168,7 +168,7 @@ ao_plugin_test_default_device(const struct audio_output_plugin *plugin)
gcc_malloc
struct audio_output *
ao_plugin_init(const struct audio_output_plugin *plugin,
- const struct config_param *param,
+ const config_param &param,
GError **error);
void
diff --git a/src/output/AlsaOutputPlugin.cxx b/src/output/AlsaOutputPlugin.cxx
index 0e70babb6..b26a3e1df 100644
--- a/src/output/AlsaOutputPlugin.cxx
+++ b/src/output/AlsaOutputPlugin.cxx
@@ -37,9 +37,7 @@
static const char default_device[] = "default";
-enum {
- MPD_ALSA_BUFFER_TIME_US = 500000,
-};
+static constexpr unsigned MPD_ALSA_BUFFER_TIME_US = 500000;
#define MPD_ALSA_RETRY_NR 5
@@ -117,7 +115,7 @@ struct AlsaOutput {
AlsaOutput():mode(0), writei(snd_pcm_writei) {
}
- bool Init(const config_param *param, GError **error_r) {
+ bool Init(const config_param &param, GError **error_r) {
return ao_base_init(&base, &alsa_output_plugin,
param, error_r);
}
@@ -143,36 +141,36 @@ alsa_device(const AlsaOutput *ad)
}
static void
-alsa_configure(AlsaOutput *ad, const struct config_param *param)
+alsa_configure(AlsaOutput *ad, const config_param &param)
{
- ad->device = config_get_block_string(param, "device", "");
+ ad->device = param.GetBlockValue("device", "");
- ad->use_mmap = config_get_block_bool(param, "use_mmap", false);
+ ad->use_mmap = param.GetBlockValue("use_mmap", false);
- ad->dsd_usb = config_get_block_bool(param, "dsd_usb", false);
+ ad->dsd_usb = param.GetBlockValue("dsd_usb", false);
- ad->buffer_time = config_get_block_unsigned(param, "buffer_time",
- MPD_ALSA_BUFFER_TIME_US);
- ad->period_time = config_get_block_unsigned(param, "period_time", 0);
+ ad->buffer_time = param.GetBlockValue("buffer_time",
+ MPD_ALSA_BUFFER_TIME_US);
+ ad->period_time = param.GetBlockValue("period_time", 0u);
#ifdef SND_PCM_NO_AUTO_RESAMPLE
- if (!config_get_block_bool(param, "auto_resample", true))
+ if (!param.GetBlockValue("auto_resample", true))
ad->mode |= SND_PCM_NO_AUTO_RESAMPLE;
#endif
#ifdef SND_PCM_NO_AUTO_CHANNELS
- if (!config_get_block_bool(param, "auto_channels", true))
+ if (!param.GetBlockValue("auto_channels", true))
ad->mode |= SND_PCM_NO_AUTO_CHANNELS;
#endif
#ifdef SND_PCM_NO_AUTO_FORMAT
- if (!config_get_block_bool(param, "auto_format", true))
+ if (!param.GetBlockValue("auto_format", true))
ad->mode |= SND_PCM_NO_AUTO_FORMAT;
#endif
}
static struct audio_output *
-alsa_init(const struct config_param *param, GError **error_r)
+alsa_init(const config_param &param, GError **error_r)
{
AlsaOutput *ad = new AlsaOutput();
diff --git a/src/output/AoOutputPlugin.cxx b/src/output/AoOutputPlugin.cxx
index d25a30973..db7b9a360 100644
--- a/src/output/AoOutputPlugin.cxx
+++ b/src/output/AoOutputPlugin.cxx
@@ -42,7 +42,7 @@ struct AoOutput {
ao_option *options;
ao_device *device;
- bool Initialize(const config_param *param, GError **error_r) {
+ bool Initialize(const config_param &param, GError **error_r) {
return ao_base_init(&base, &ao_output_plugin, param,
error_r);
}
@@ -51,7 +51,7 @@ struct AoOutput {
ao_base_finish(&base);
}
- bool Configure(const config_param *param, GError **error_r);
+ bool Configure(const config_param &param, GError **error_r);
};
static inline GQuark
@@ -95,20 +95,20 @@ ao_output_error(GError **error_r)
}
inline bool
-AoOutput::Configure(const config_param *param, GError **error_r)
+AoOutput::Configure(const config_param &param, GError **error_r)
{
const char *value;
options = nullptr;
- write_size = config_get_block_unsigned(param, "write_size", 1024);
+ write_size = param.GetBlockValue("write_size", 1024u);
if (ao_output_ref == 0) {
ao_initialize();
}
ao_output_ref++;
- value = config_get_block_string(param, "driver", "default");
+ value = param.GetBlockValue("driver", "default");
if (0 == strcmp(value, "default"))
driver = ao_default_driver_id();
else
@@ -129,9 +129,9 @@ AoOutput::Configure(const config_param *param, GError **error_r)
}
g_debug("using ao driver \"%s\" for \"%s\"\n", ai->short_name,
- config_get_block_string(param, "name", nullptr));
+ param.GetBlockValue("name", nullptr));
- value = config_get_block_string(param, "options", nullptr);
+ value = param.GetBlockValue("options", nullptr);
if (value != nullptr) {
gchar **_options = g_strsplit(value, ";", 0);
@@ -158,7 +158,7 @@ AoOutput::Configure(const config_param *param, GError **error_r)
}
static struct audio_output *
-ao_output_init(const config_param *param, GError **error_r)
+ao_output_init(const config_param &param, GError **error_r)
{
AoOutput *ad = new AoOutput();
diff --git a/src/output/FifoOutputPlugin.cxx b/src/output/FifoOutputPlugin.cxx
index a0d07c702..50062988c 100644
--- a/src/output/FifoOutputPlugin.cxx
+++ b/src/output/FifoOutputPlugin.cxx
@@ -53,7 +53,7 @@ struct FifoOutput {
g_free(path);
}
- bool Initialize(const config_param *param, GError **error_r) {
+ bool Initialize(const config_param &param, GError **error_r) {
return ao_base_init(&base, &fifo_output_plugin, param,
error_r);
}
@@ -186,10 +186,10 @@ fifo_open(FifoOutput *fd, GError **error_r)
}
static struct audio_output *
-fifo_output_init(const config_param *param, GError **error_r)
+fifo_output_init(const config_param &param, GError **error_r)
{
GError *error = nullptr;
- char *path = config_dup_block_path(param, "path", &error);
+ char *path = param.DupBlockPath("path", &error);
if (!path) {
if (error != nullptr)
g_propagate_error(error_r, error);
diff --git a/src/output/HttpdInternal.hxx b/src/output/HttpdInternal.hxx
index 8bc0c130e..e8a37e033 100644
--- a/src/output/HttpdInternal.hxx
+++ b/src/output/HttpdInternal.hxx
@@ -123,7 +123,7 @@ struct HttpdOutput final : private ServerSocket {
HttpdOutput(EventLoop &_loop);
~HttpdOutput();
- bool Configure(const config_param *param, GError **error_r);
+ bool Configure(const config_param &param, GError **error_r);
bool Bind(GError **error_r);
void Unbind();
diff --git a/src/output/HttpdOutputPlugin.cxx b/src/output/HttpdOutputPlugin.cxx
index 462dd3429..21774bac9 100644
--- a/src/output/HttpdOutputPlugin.cxx
+++ b/src/output/HttpdOutputPlugin.cxx
@@ -91,18 +91,17 @@ HttpdOutput::Unbind()
}
inline bool
-HttpdOutput::Configure(const config_param *param, GError **error_r)
+HttpdOutput::Configure(const config_param &param, GError **error_r)
{
/* read configuration */
- name = config_get_block_string(param, "name", "Set name in config");
- genre = config_get_block_string(param, "genre", "Set genre in config");
- website = config_get_block_string(param, "website",
- "Set website in config");
+ name = param.GetBlockValue("name", "Set name in config");
+ genre = param.GetBlockValue("genre", "Set genre in config");
+ website = param.GetBlockValue("website", "Set website in config");
- guint port = config_get_block_unsigned(param, "port", 8000);
+ guint port = param.GetBlockValue("port", 8000u);
const char *encoder_name =
- config_get_block_string(param, "encoder", "vorbis");
+ param.GetBlockValue("encoder", "vorbis");
const auto encoder_plugin = encoder_plugin_get(encoder_name);
if (encoder_plugin == NULL) {
g_set_error(error_r, httpd_output_quark(), 0,
@@ -110,12 +109,11 @@ HttpdOutput::Configure(const config_param *param, GError **error_r)
return false;
}
- clients_max = config_get_block_unsigned(param,"max_clients", 0);
+ clients_max = param.GetBlockValue("max_clients", 0u);
/* set up bind_to_address */
- const char *bind_to_address =
- config_get_block_string(param, "bind_to_address", NULL);
+ const char *bind_to_address = param.GetBlockValue("bind_to_address");
bool success = bind_to_address != NULL &&
strcmp(bind_to_address, "any") != 0
? AddHost(bind_to_address, port, error_r)
@@ -125,7 +123,7 @@ HttpdOutput::Configure(const config_param *param, GError **error_r)
/* initialize encoder */
- encoder = encoder_init(*encoder_plugin, param, error_r);
+ encoder = encoder_init(*encoder_plugin, &param, error_r);
if (encoder == nullptr)
return false;
@@ -138,7 +136,7 @@ HttpdOutput::Configure(const config_param *param, GError **error_r)
}
static struct audio_output *
-httpd_output_init(const struct config_param *param,
+httpd_output_init(const struct config_param &param,
GError **error_r)
{
HttpdOutput *httpd = new HttpdOutput(*main_loop);
diff --git a/src/output/JackOutputPlugin.cxx b/src/output/JackOutputPlugin.cxx
index 6c9ee9335..241857d82 100644
--- a/src/output/JackOutputPlugin.cxx
+++ b/src/output/JackOutputPlugin.cxx
@@ -82,7 +82,7 @@ struct JackOutput {
*/
bool pause;
- bool Initialize(const config_param *param, GError **error_r) {
+ bool Initialize(const config_param &param, GError **error_r) {
return ao_base_init(&base, &jack_output_plugin, param,
error_r);
}
@@ -323,7 +323,7 @@ parse_port_list(int line, const char *source, char **dest, GError **error_r)
}
static struct audio_output *
-mpd_jack_init(const config_param *param, GError **error_r)
+mpd_jack_init(const config_param &param, GError **error_r)
{
JackOutput *jd = new JackOutput();
@@ -336,7 +336,7 @@ mpd_jack_init(const config_param *param, GError **error_r)
jd->options = JackNullOption;
- jd->name = config_get_block_string(param, "client_name", nullptr);
+ jd->name = param.GetBlockValue("client_name", nullptr);
if (jd->name != nullptr)
jd->options = jack_options_t(jd->options | JackUseExactName);
else
@@ -344,35 +344,35 @@ mpd_jack_init(const config_param *param, GError **error_r)
care about the JackUseExactName option */
jd->name = "Music Player Daemon";
- jd->server_name = config_get_block_string(param, "server_name", nullptr);
+ jd->server_name = param.GetBlockValue("server_name", nullptr);
if (jd->server_name != nullptr)
jd->options = jack_options_t(jd->options | JackServerName);
- if (!config_get_block_bool(param, "autostart", false))
+ if (!param.GetBlockValue("autostart", false))
jd->options = jack_options_t(jd->options | JackNoStartServer);
/* configure the source ports */
- value = config_get_block_string(param, "source_ports", "left,right");
- jd->num_source_ports = parse_port_list(param->line, value,
+ value = param.GetBlockValue("source_ports", "left,right");
+ jd->num_source_ports = parse_port_list(param.line, value,
jd->source_ports, error_r);
if (jd->num_source_ports == 0)
return nullptr;
/* configure the destination ports */
- value = config_get_block_string(param, "destination_ports", nullptr);
+ value = param.GetBlockValue("destination_ports", nullptr);
if (value == nullptr) {
/* compatibility with MPD < 0.16 */
- value = config_get_block_string(param, "ports", nullptr);
+ value = param.GetBlockValue("ports", nullptr);
if (value != nullptr)
g_warning("deprecated option 'ports' in line %d",
- param->line);
+ param.line);
}
if (value != nullptr) {
jd->num_destination_ports =
- parse_port_list(param->line, value,
+ parse_port_list(param.line, value,
jd->destination_ports, error_r);
if (jd->num_destination_ports == 0)
return nullptr;
@@ -385,10 +385,9 @@ mpd_jack_init(const config_param *param, GError **error_r)
g_warning("number of source ports (%u) mismatches the "
"number of destination ports (%u) in line %d",
jd->num_source_ports, jd->num_destination_ports,
- param->line);
+ param.line);
- jd->ringbuffer_size =
- config_get_block_unsigned(param, "ringbuffer_size", 32768);
+ jd->ringbuffer_size = param.GetBlockValue("ringbuffer_size", 32768u);
jack_set_error_function(mpd_jack_error);
diff --git a/src/output/NullOutputPlugin.cxx b/src/output/NullOutputPlugin.cxx
index 814a9d2e2..0ce32fbda 100644
--- a/src/output/NullOutputPlugin.cxx
+++ b/src/output/NullOutputPlugin.cxx
@@ -31,7 +31,7 @@ struct NullOutput {
Timer *timer;
- bool Initialize(const config_param *param, GError **error_r) {
+ bool Initialize(const config_param &param, GError **error_r) {
return ao_base_init(&base, &null_output_plugin, param,
error_r);
}
@@ -42,7 +42,7 @@ struct NullOutput {
};
static struct audio_output *
-null_init(const config_param *param, GError **error_r)
+null_init(const config_param &param, GError **error_r)
{
NullOutput *nd = new NullOutput();
@@ -51,7 +51,7 @@ null_init(const config_param *param, GError **error_r)
return nullptr;
}
- nd->sync = config_get_block_bool(param, "sync", true);
+ nd->sync = param.GetBlockValue("sync", true);
return &nd->base;
}
diff --git a/src/output/OSXOutputPlugin.cxx b/src/output/OSXOutputPlugin.cxx
index afe8e064d..6e42b2518 100644
--- a/src/output/OSXOutputPlugin.cxx
+++ b/src/output/OSXOutputPlugin.cxx
@@ -65,9 +65,9 @@ osx_output_test_default_device(void)
}
static void
-osx_output_configure(OSXOutput *oo, const struct config_param *param)
+osx_output_configure(OSXOutput *oo, const config_param &param)
{
- const char *device = config_get_block_string(param, "device", NULL);
+ const char *device = param.GetBlockValue("device");
if (device == NULL || 0 == strcmp(device, "default")) {
oo->component_subtype = kAudioUnitSubType_DefaultOutput;
@@ -85,7 +85,7 @@ osx_output_configure(OSXOutput *oo, const struct config_param *param)
}
static struct audio_output *
-osx_output_init(const struct config_param *param, GError **error_r)
+osx_output_init(const config_param &param, GError **error_r)
{
OSXOutput *oo = new OSXOutput();
if (!ao_base_init(&oo->base, &osx_output_plugin, param, error_r)) {
diff --git a/src/output/OpenALOutputPlugin.cxx b/src/output/OpenALOutputPlugin.cxx
index 81c75f6c4..1864052fa 100644
--- a/src/output/OpenALOutputPlugin.cxx
+++ b/src/output/OpenALOutputPlugin.cxx
@@ -49,7 +49,7 @@ struct OpenALOutput {
ALenum format;
ALuint frequency;
- bool Initialize(const config_param *param, GError **error_r) {
+ bool Initialize(const config_param &param, GError **error_r) {
return ao_base_init(&base, &openal_output_plugin, param,
error_r);
}
@@ -140,10 +140,9 @@ openal_setup_context(OpenALOutput *od,
}
static struct audio_output *
-openal_init(const config_param *param, GError **error_r)
+openal_init(const config_param &param, GError **error_r)
{
- const char *device_name = config_get_block_string(param, "device", nullptr);
-
+ const char *device_name = param.GetBlockValue("device");
if (device_name == nullptr) {
device_name = alcGetString(nullptr, ALC_DEFAULT_DEVICE_SPECIFIER);
}
diff --git a/src/output/OssOutputPlugin.cxx b/src/output/OssOutputPlugin.cxx
index 49b02386b..2ef0edd67 100644
--- a/src/output/OssOutputPlugin.cxx
+++ b/src/output/OssOutputPlugin.cxx
@@ -80,7 +80,7 @@ struct OssOutput {
OssOutput():fd(-1), device(nullptr) {}
- bool Initialize(const config_param *param, GError **error_r) {
+ bool Initialize(const config_param &param, GError **error_r) {
return ao_base_init(&base, &oss_output_plugin, param,
error_r);
}
@@ -160,11 +160,12 @@ oss_open_default(GError **error)
int err[G_N_ELEMENTS(default_devices)];
enum oss_stat ret[G_N_ELEMENTS(default_devices)];
+ const config_param empty;
for (int i = G_N_ELEMENTS(default_devices); --i >= 0; ) {
ret[i] = oss_stat_device(default_devices[i], &err[i]);
if (ret[i] == OSS_STAT_NO_ERROR) {
OssOutput *od = new OssOutput();
- if (!od->Initialize(nullptr, error)) {
+ if (!od->Initialize(empty, error)) {
delete od;
return NULL;
}
@@ -201,9 +202,9 @@ oss_open_default(GError **error)
}
static struct audio_output *
-oss_output_init(const config_param *param, GError **error_r)
+oss_output_init(const config_param &param, GError **error_r)
{
- const char *device = config_get_block_string(param, "device", NULL);
+ const char *device = param.GetBlockValue("device");
if (device != NULL) {
OssOutput *od = new OssOutput();
if (!od->Initialize(param, error_r)) {
diff --git a/src/output/PipeOutputPlugin.cxx b/src/output/PipeOutputPlugin.cxx
index f76dd04c1..f485f1554 100644
--- a/src/output/PipeOutputPlugin.cxx
+++ b/src/output/PipeOutputPlugin.cxx
@@ -30,7 +30,7 @@ struct PipeOutput {
char *cmd;
FILE *fh;
- bool Initialize(const config_param *param, GError **error_r) {
+ bool Initialize(const config_param &param, GError **error_r) {
return ao_base_init(&base, &pipe_output_plugin, param,
error_r);
}
@@ -39,7 +39,7 @@ struct PipeOutput {
ao_base_finish(&base);
}
- bool Configure(const config_param *param, GError **error_r);
+ bool Configure(const config_param &param, GError **error_r);
};
/**
@@ -52,9 +52,9 @@ pipe_output_quark(void)
}
inline bool
-PipeOutput::Configure(const config_param *param, GError **error_r)
+PipeOutput::Configure(const config_param &param, GError **error_r)
{
- cmd = config_dup_block_string(param, "command", nullptr);
+ cmd = param.DupBlockString("command");
if (cmd == nullptr) {
g_set_error(error_r, pipe_output_quark(), 0,
"No \"command\" parameter specified");
@@ -65,7 +65,7 @@ PipeOutput::Configure(const config_param *param, GError **error_r)
}
static struct audio_output *
-pipe_output_init(const config_param *param, GError **error_r)
+pipe_output_init(const config_param &param, GError **error_r)
{
PipeOutput *pd = new PipeOutput();
diff --git a/src/output/PulseOutputPlugin.cxx b/src/output/PulseOutputPlugin.cxx
index 65526c8fb..f59c8d76e 100644
--- a/src/output/PulseOutputPlugin.cxx
+++ b/src/output/PulseOutputPlugin.cxx
@@ -344,7 +344,7 @@ pulse_output_setup_context(PulseOutput *po, GError **error_r)
}
static struct audio_output *
-pulse_output_init(const struct config_param *param, GError **error_r)
+pulse_output_init(const config_param &param, GError **error_r)
{
PulseOutput *po;
@@ -356,9 +356,9 @@ pulse_output_init(const struct config_param *param, GError **error_r)
return nullptr;
}
- po->name = config_get_block_string(param, "name", "mpd_pulse");
- po->server = config_get_block_string(param, "server", nullptr);
- po->sink = config_get_block_string(param, "sink", nullptr);
+ po->name = param.GetBlockValue("name", "mpd_pulse");
+ po->server = param.GetBlockValue("server");
+ po->sink = param.GetBlockValue("sink");
po->mixer = nullptr;
po->mainloop = nullptr;
@@ -923,10 +923,10 @@ pulse_output_pause(struct audio_output *ao)
static bool
pulse_output_test_default_device(void)
{
- PulseOutput *po;
bool success;
- po = (PulseOutput *)pulse_output_init(nullptr, nullptr);
+ const config_param empty;
+ PulseOutput *po = (PulseOutput *)pulse_output_init(empty, nullptr);
if (po == nullptr)
return false;
diff --git a/src/output/RecorderOutputPlugin.cxx b/src/output/RecorderOutputPlugin.cxx
index 2e77463f0..8da6d88f2 100644
--- a/src/output/RecorderOutputPlugin.cxx
+++ b/src/output/RecorderOutputPlugin.cxx
@@ -57,7 +57,7 @@ struct RecorderOutput {
*/
char buffer[32768];
- bool Initialize(const config_param *param, GError **error_r) {
+ bool Initialize(const config_param &param, GError **error_r) {
return ao_base_init(&base, &recorder_output_plugin, param,
error_r);
}
@@ -66,7 +66,7 @@ struct RecorderOutput {
ao_base_finish(&base);
}
- bool Configure(const config_param *param, GError **error_r);
+ bool Configure(const config_param &param, GError **error_r);
bool WriteToFile(const void *data, size_t length, GError **error_r);
@@ -86,12 +86,12 @@ recorder_output_quark(void)
}
inline bool
-RecorderOutput::Configure(const config_param *param, GError **error_r)
+RecorderOutput::Configure(const config_param &param, GError **error_r)
{
/* read configuration */
const char *encoder_name =
- config_get_block_string(param, "encoder", "vorbis");
+ param.GetBlockValue("encoder", "vorbis");
const auto encoder_plugin = encoder_plugin_get(encoder_name);
if (encoder_plugin == nullptr) {
g_set_error(error_r, recorder_output_quark(), 0,
@@ -99,7 +99,7 @@ RecorderOutput::Configure(const config_param *param, GError **error_r)
return false;
}
- path = config_get_block_string(param, "path", nullptr);
+ path = param.GetBlockValue("path");
if (path == nullptr) {
g_set_error(error_r, recorder_output_quark(), 0,
"'path' not configured");
@@ -108,7 +108,7 @@ RecorderOutput::Configure(const config_param *param, GError **error_r)
/* initialize encoder */
- encoder = encoder_init(*encoder_plugin, param, error_r);
+ encoder = encoder_init(*encoder_plugin, &param, error_r);
if (encoder == nullptr)
return false;
@@ -116,7 +116,7 @@ RecorderOutput::Configure(const config_param *param, GError **error_r)
}
static audio_output *
-recorder_output_init(const config_param *param, GError **error_r)
+recorder_output_init(const config_param &param, GError **error_r)
{
RecorderOutput *recorder = new RecorderOutput();
diff --git a/src/output/RoarOutputPlugin.cxx b/src/output/RoarOutputPlugin.cxx
index bf2bf1789..36f7c395b 100644
--- a/src/output/RoarOutputPlugin.cxx
+++ b/src/output/RoarOutputPlugin.cxx
@@ -108,19 +108,19 @@ roar_output_set_volume(RoarOutput *roar, unsigned volume)
}
static void
-roar_configure(RoarOutput *self, const struct config_param *param)
+roar_configure(RoarOutput *self, const config_param &param)
{
- self->host = config_dup_block_string(param, "server", nullptr);
- self->name = config_dup_block_string(param, "name", "MPD");
+ self->host = param.DupBlockString("server", nullptr);
+ self->name = param.DupBlockString("name", "MPD");
- const char *role = config_get_block_string(param, "role", "music");
+ const char *role = param.GetBlockValue("role", "music");
self->role = role != nullptr
? roar_str2role(role)
: ROAR_ROLE_MUSIC;
}
static struct audio_output *
-roar_init(const struct config_param *param, GError **error_r)
+roar_init(const config_param &param, GError **error_r)
{
RoarOutput *self = new RoarOutput();
diff --git a/src/output/ShoutOutputPlugin.cxx b/src/output/ShoutOutputPlugin.cxx
index fbad24ec8..1f307eafc 100644
--- a/src/output/ShoutOutputPlugin.cxx
+++ b/src/output/ShoutOutputPlugin.cxx
@@ -35,7 +35,7 @@
#undef G_LOG_DOMAIN
#define G_LOG_DOMAIN "shout"
-#define DEFAULT_CONN_TIMEOUT 2
+static constexpr unsigned DEFAULT_CONN_TIMEOUT = 2;
struct ShoutOutput final {
struct audio_output base;
@@ -66,7 +66,7 @@ struct ShoutOutput final {
shout_free(shout_conn);
}
- bool Initialize(const config_param *param, GError **error_r) {
+ bool Initialize(const config_param &param, GError **error_r) {
return ao_base_init(&base, &shout_output_plugin, param,
error_r);
}
@@ -75,7 +75,7 @@ struct ShoutOutput final {
ao_base_finish(&base);
}
- bool Configure(const config_param *param, GError **error_r);
+ bool Configure(const config_param &param, GError **error_r);
};
static int shout_init_count;
@@ -102,18 +102,18 @@ shout_encoder_plugin_get(const char *name)
gcc_pure
static const char *
-require_block_string(const struct config_param *param, const char *name)
+require_block_string(const config_param &param, const char *name)
{
- const char *value = config_get_block_string(param, name, nullptr);
+ const char *value = param.GetBlockValue(name);
if (value == nullptr)
MPD_ERROR("no \"%s\" defined for shout device defined at line " \
- "%i\n", name, param->line); \
+ "%i\n", name, param.line);
return value;
}
inline bool
-ShoutOutput::Configure(const config_param *param, GError **error_r)
+ShoutOutput::Configure(const config_param &param, GError **error_r)
{
const AudioFormat audio_format = base.config_audio_format;
@@ -125,8 +125,7 @@ ShoutOutput::Configure(const config_param *param, GError **error_r)
const char *host = require_block_string(param, "host");
const char *mount = require_block_string(param, "mount");
-
- unsigned port = config_get_block_unsigned(param, "port", 0);
+ unsigned port = param.GetBlockValue("port", 0u);
if (port == 0) {
g_set_error(error_r, shout_output_quark(), 0,
"shout port must be configured");
@@ -136,11 +135,11 @@ ShoutOutput::Configure(const config_param *param, GError **error_r)
const char *passwd = require_block_string(param, "password");
const char *name = require_block_string(param, "name");
- bool is_public = config_get_block_bool(param, "public", false);
+ bool is_public = param.GetBlockValue("public", false);
- const char *user = config_get_block_string(param, "user", "source");
+ const char *user = param.GetBlockValue("user", "source");
- const char *value = config_get_block_string(param, "quality", nullptr);
+ const char *value = param.GetBlockValue("quality");
if (value != nullptr) {
char *test;
quality = strtod(value, &test);
@@ -149,18 +148,18 @@ ShoutOutput::Configure(const config_param *param, GError **error_r)
g_set_error(error_r, shout_output_quark(), 0,
"shout quality \"%s\" is not a number in the "
"range -1 to 10, line %i",
- value, param->line);
+ value, param.line);
return false;
}
- if (config_get_block_string(param, "bitrate", nullptr) != nullptr) {
+ if (param.GetBlockValue("bitrate") != nullptr) {
g_set_error(error_r, shout_output_quark(), 0,
"quality and bitrate are "
"both defined");
return false;
}
} else {
- value = config_get_block_string(param, "bitrate", nullptr);
+ value = param.GetBlockValue("bitrate");
if (value == nullptr) {
g_set_error(error_r, shout_output_quark(), 0,
"neither bitrate nor quality defined");
@@ -177,8 +176,7 @@ ShoutOutput::Configure(const config_param *param, GError **error_r)
}
}
- const char *encoding = config_get_block_string(param, "encoding",
- "ogg");
+ const char *encoding = param.GetBlockValue("encoding", "ogg");
const auto encoder_plugin = shout_encoder_plugin_get(encoding);
if (encoder_plugin == nullptr) {
g_set_error(error_r, shout_output_quark(), 0,
@@ -187,7 +185,7 @@ ShoutOutput::Configure(const config_param *param, GError **error_r)
return false;
}
- encoder = encoder_init(*encoder_plugin, param, error_r);
+ encoder = encoder_init(*encoder_plugin, &param, error_r);
if (encoder == nullptr)
return false;
@@ -198,7 +196,7 @@ ShoutOutput::Configure(const config_param *param, GError **error_r)
shout_format = SHOUT_FORMAT_OGG;
unsigned protocol;
- value = config_get_block_string(param, "protocol", nullptr);
+ value = param.GetBlockValue("protocol");
if (value != nullptr) {
if (0 == strcmp(value, "shoutcast") &&
0 != strcmp(encoding, "mp3")) {
@@ -240,24 +238,23 @@ ShoutOutput::Configure(const config_param *param, GError **error_r)
}
/* optional paramters */
- timeout = config_get_block_unsigned(param, "timeout",
- DEFAULT_CONN_TIMEOUT);
+ timeout = param.GetBlockValue("timeout", DEFAULT_CONN_TIMEOUT);
- value = config_get_block_string(param, "genre", nullptr);
+ value = param.GetBlockValue("genre");
if (value != nullptr && shout_set_genre(shout_conn, value)) {
g_set_error(error_r, shout_output_quark(), 0,
"%s", shout_get_error(shout_conn));
return false;
}
- value = config_get_block_string(param, "description", nullptr);
+ value = param.GetBlockValue("description");
if (value != nullptr && shout_set_description(shout_conn, value)) {
g_set_error(error_r, shout_output_quark(), 0,
"%s", shout_get_error(shout_conn));
return false;
}
- value = config_get_block_string(param, "url", nullptr);
+ value = param.GetBlockValue("url");
if (value != nullptr && shout_set_url(shout_conn, value)) {
g_set_error(error_r, shout_output_quark(), 0,
"%s", shout_get_error(shout_conn));
@@ -290,7 +287,7 @@ ShoutOutput::Configure(const config_param *param, GError **error_r)
}
static struct audio_output *
-my_shout_init_driver(const config_param *param, GError **error_r)
+my_shout_init_driver(const config_param &param, GError **error_r)
{
ShoutOutput *sd = new ShoutOutput();
if (!sd->Initialize(param, error_r)) {
diff --git a/src/output/SolarisOutputPlugin.cxx b/src/output/SolarisOutputPlugin.cxx
index 81c793e21..074eae728 100644
--- a/src/output/SolarisOutputPlugin.cxx
+++ b/src/output/SolarisOutputPlugin.cxx
@@ -61,7 +61,7 @@ struct SolarisOutput {
int fd;
- bool Initialize(const config_param *param, GError **error_r) {
+ bool Initialize(const config_param &param, GError **error_r) {
return ao_base_init(&base, &solaris_output_plugin, param,
error_r);
}
@@ -90,7 +90,7 @@ solaris_output_test_default_device(void)
}
static struct audio_output *
-solaris_output_init(const config_param *param, GError **error_r)
+solaris_output_init(const config_param &param, GError **error_r)
{
SolarisOutput *so = new SolarisOutput();
if (!so->Initialize(param, error_r)) {
@@ -98,7 +98,7 @@ solaris_output_init(const config_param *param, GError **error_r)
return nullptr;
}
- so->device = config_get_block_string(param, "device", "/dev/audio");
+ so->device = param.GetBlockValue("device", "/dev/audio");
return &so->base;
}
diff --git a/src/output/WinmmOutputPlugin.cxx b/src/output/WinmmOutputPlugin.cxx
index de6927bd2..d02b52c58 100644
--- a/src/output/WinmmOutputPlugin.cxx
+++ b/src/output/WinmmOutputPlugin.cxx
@@ -114,7 +114,7 @@ fail:
}
static struct audio_output *
-winmm_output_init(const struct config_param *param, GError **error_r)
+winmm_output_init(const config_param &param, GError **error_r)
{
WinmmOutput *wo = new WinmmOutput();
if (!ao_base_init(&wo->base, &winmm_output_plugin, param, error_r)) {
@@ -122,7 +122,7 @@ winmm_output_init(const struct config_param *param, GError **error_r)
return nullptr;
}
- const char *device = config_get_block_string(param, "device", nullptr);
+ const char *device = param.GetBlockValue("device");
if (!get_device_id(device, &wo->device_id, error_r)) {
ao_base_finish(&wo->base);
g_free(wo);
diff --git a/test/run_output.cxx b/test/run_output.cxx
index 34879c657..fbdeebcb6 100644
--- a/test/run_output.cxx
+++ b/test/run_output.cxx
@@ -76,8 +76,7 @@ find_named_config_block(ConfigOption option, const char *name)
const struct config_param *param = NULL;
while ((param = config_get_next_param(option, param)) != NULL) {
- const char *current_name =
- config_get_block_string(param, "name", NULL);
+ const char *current_name = param->GetBlockValue("name");
if (current_name != NULL && strcmp(current_name, name) == 0)
return param;
}
@@ -104,7 +103,7 @@ load_audio_output(const char *name)
static struct player_control dummy_player_control(32, 4);
struct audio_output *ao =
- audio_output_new(param, &dummy_player_control, &error);
+ audio_output_new(*param, &dummy_player_control, &error);
if (ao == NULL) {
g_printerr("%s\n", error->message);
g_error_free(error);