conf: allow param==NULL
Return the default value in the conf_get_block_*() functions when param==NULL was passed. This simplifies a lot of code, because all initialization can be done in one code path, regardless whether configuration is present.
This commit is contained in:
parent
5f77910097
commit
3635c93acb
@ -433,6 +433,9 @@ getBlockParam(const struct config_param * param, const char *name)
|
|||||||
struct block_param *ret = NULL;
|
struct block_param *ret = NULL;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
|
if (param == NULL)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
for (i = 0; i < param->num_block_params; i++) {
|
for (i = 0; i < param->num_block_params; i++) {
|
||||||
if (0 == strcmp(name, param->block_params[i].name)) {
|
if (0 == strcmp(name, param->block_params[i].name)) {
|
||||||
if (ret) {
|
if (ret) {
|
||||||
|
@ -48,9 +48,6 @@ alsa_mixer_configure(struct mixer_data *data, const struct config_param *param)
|
|||||||
struct alsa_mixer *am = (struct alsa_mixer *)data;
|
struct alsa_mixer *am = (struct alsa_mixer *)data;
|
||||||
const char *value;
|
const char *value;
|
||||||
|
|
||||||
if (param == NULL)
|
|
||||||
return;
|
|
||||||
|
|
||||||
value = config_get_block_string(param, "mixer_device", NULL);
|
value = config_get_block_string(param, "mixer_device", NULL);
|
||||||
if (value != NULL) {
|
if (value != NULL) {
|
||||||
g_free(am->device);
|
g_free(am->device);
|
||||||
|
@ -52,9 +52,6 @@ oss_mixer_configure(struct mixer_data *data, const struct config_param *param)
|
|||||||
struct oss_mixer *om = (struct oss_mixer *) data;
|
struct oss_mixer *om = (struct oss_mixer *) data;
|
||||||
const char *value;
|
const char *value;
|
||||||
|
|
||||||
if (param == NULL)
|
|
||||||
return;
|
|
||||||
|
|
||||||
value = config_get_block_string(param, "mixer_device", NULL);
|
value = config_get_block_string(param, "mixer_device", NULL);
|
||||||
if (value != NULL) {
|
if (value != NULL) {
|
||||||
g_free(om->device);
|
g_free(om->device);
|
||||||
|
@ -85,13 +85,9 @@ alsa_data_new(void)
|
|||||||
{
|
{
|
||||||
struct alsa_data *ret = g_new(struct alsa_data, 1);
|
struct alsa_data *ret = g_new(struct alsa_data, 1);
|
||||||
|
|
||||||
ret->device = NULL;
|
|
||||||
ret->mode = 0;
|
ret->mode = 0;
|
||||||
ret->pcm = NULL;
|
ret->pcm = NULL;
|
||||||
ret->writei = snd_pcm_writei;
|
ret->writei = snd_pcm_writei;
|
||||||
ret->use_mmap = false;
|
|
||||||
ret->buffer_time = MPD_ALSA_BUFFER_TIME_US;
|
|
||||||
ret->period_time = MPD_ALSA_PERIOD_TIME_US;
|
|
||||||
|
|
||||||
//use alsa mixer by default
|
//use alsa mixer by default
|
||||||
mixer_init(&ret->mixer, &alsa_mixer);
|
mixer_init(&ret->mixer, &alsa_mixer);
|
||||||
@ -149,8 +145,9 @@ alsa_init(G_GNUC_UNUSED struct audio_output *ao,
|
|||||||
free_global_registered = 1;
|
free_global_registered = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (param) {
|
|
||||||
alsa_configure(ad, param);
|
alsa_configure(ad, param);
|
||||||
|
|
||||||
|
if (param) {
|
||||||
mixer_configure(&ad->mixer, param);
|
mixer_configure(&ad->mixer, param);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -60,16 +60,6 @@ mpd_jack_name(const struct jack_data *jd)
|
|||||||
return audio_output_get_name(jd->ao);
|
return audio_output_get_name(jd->ao);
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct jack_data *
|
|
||||||
mpd_jack_new(void)
|
|
||||||
{
|
|
||||||
struct jack_data *ret = g_new(struct jack_data, 1);
|
|
||||||
|
|
||||||
ret->ringbuffer_size = 32768;
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
mpd_jack_client_free(struct jack_data *jd)
|
mpd_jack_client_free(struct jack_data *jd)
|
||||||
{
|
{
|
||||||
@ -188,12 +178,10 @@ mpd_jack_init(struct audio_output *ao,
|
|||||||
struct jack_data *jd;
|
struct jack_data *jd;
|
||||||
const char *value;
|
const char *value;
|
||||||
|
|
||||||
jd = mpd_jack_new();
|
jd = g_new(struct jack_data, 1);
|
||||||
jd->ao = ao;
|
jd->ao = ao;
|
||||||
|
|
||||||
g_debug("mpd_jack_init (pid=%d)", getpid());
|
g_debug("mpd_jack_init (pid=%d)", getpid());
|
||||||
if (param == NULL)
|
|
||||||
return jd;
|
|
||||||
|
|
||||||
value = config_get_block_string(param, "ports", NULL);
|
value = config_get_block_string(param, "ports", NULL);
|
||||||
if (value != NULL) {
|
if (value != NULL) {
|
||||||
|
@ -392,16 +392,14 @@ oss_initDriver(G_GNUC_UNUSED struct audio_output *audioOutput,
|
|||||||
G_GNUC_UNUSED const struct audio_format *audio_format,
|
G_GNUC_UNUSED const struct audio_format *audio_format,
|
||||||
const struct config_param *param)
|
const struct config_param *param)
|
||||||
{
|
{
|
||||||
if (param) {
|
const char *device = config_get_block_string(param, "device", NULL);
|
||||||
const char *device =
|
|
||||||
config_get_block_string(param, "device", NULL);
|
|
||||||
if (device != NULL) {
|
if (device != NULL) {
|
||||||
OssData *od = newOssData();
|
OssData *od = newOssData();
|
||||||
od->device = device;
|
od->device = device;
|
||||||
mixer_configure(&od->mixer, param);
|
mixer_configure(&od->mixer, param);
|
||||||
return od;
|
return od;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return oss_open_default(param);
|
return oss_open_default(param);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user