X-Git-Url: http://git.tuebingen.mpg.de/?p=paraslash.git;a=blobdiff_plain;f=alsa_mix.c;h=6520416fb83931ede15a299118a972f5893b2f34;hp=5a46963e56722c2abc3a162401179c58122497db;hb=a85b3b947174c64ce06b4d6e438677055bf3f1ae;hpb=f167629b3191c57a6b691cd2a6af04a45a74ccb0 diff --git a/alsa_mix.c b/alsa_mix.c index 5a46963e..6520416f 100644 --- a/alsa_mix.c +++ b/alsa_mix.c @@ -100,11 +100,13 @@ static bool channel_has_playback(snd_mixer_selem_channel_id_t chn, static char *alsa_mix_get_channels(struct mixer_handle *handle) { + int ret; char *list = NULL; snd_mixer_selem_id_t *sid; snd_mixer_elem_t *elem; - snd_mixer_selem_id_alloca(&sid); + ret = snd_mixer_selem_id_malloc(&sid); + assert(ret >= 0); elem = snd_mixer_first_elem(handle->mixer); for (; elem; elem = snd_mixer_elem_next(elem)) { char *tmp = list; @@ -122,6 +124,7 @@ static char *alsa_mix_get_channels(struct mixer_handle *handle) name); free(tmp); } + snd_mixer_selem_id_free(sid); return list; } @@ -133,29 +136,36 @@ static int alsa_mix_set_channel(struct mixer_handle *h, if (!mixer_channel) mixer_channel = "Master"; - snd_mixer_selem_id_alloca(&sid); + ret = snd_mixer_selem_id_malloc(&sid); + assert(ret >= 0); snd_mixer_selem_id_set_index(sid, selem_id); snd_mixer_selem_id_set_name(sid, mixer_channel); h->elem = snd_mixer_find_selem(h->mixer, sid); if (!h->elem) { - PARA_NOTICE_LOG("unable to find simple control '%s',%i\n", + PARA_NOTICE_LOG("unable to find simple control '%s',%u\n", snd_mixer_selem_id_get_name(sid), snd_mixer_selem_id_get_index(sid)); - return -E_BAD_CHANNEL; + ret = -E_BAD_CHANNEL; + goto out; } ret = snd_mixer_selem_get_playback_volume_range(h->elem, &h->pmin, &h->pmax); if (ret < 0) { PARA_NOTICE_LOG("unable to get %s range (%s): %s\n", mixer_channel, h->card, snd_strerror(ret)); - return -E_ALSA_MIX_RANGE; + ret = -E_ALSA_MIX_RANGE; + goto out; } if (h->pmin >= h->pmax) { PARA_NOTICE_LOG("alsa reported %s range %ld-%ld (%s)\n", mixer_channel, h->pmin, h->pmax, h->card); - return -E_ALSA_MIX_RANGE; + ret = -E_ALSA_MIX_RANGE; + goto out; } - return 1; + ret = 1; +out: + snd_mixer_selem_id_free(sid); + return ret; } static int alsa_mix_get(struct mixer_handle *h) @@ -206,19 +216,13 @@ static int alsa_mix_set(struct mixer_handle *h, int val) return 1; } -/** - * The init function of the ALSA mixer. - * - * \param self The structure to initialize. - * - * \sa struct \ref mixer, \ref oss_mix_init(). - */ -void alsa_mix_init(struct mixer *self) -{ - self->open = alsa_mix_open; - self->get_channels = alsa_mix_get_channels; - self->set_channel = alsa_mix_set_channel; - self->close = alsa_mix_close; - self->get = alsa_mix_get; - self->set = alsa_mix_set; -} +/** The mixer operations for the ALSA mixer. */ +const struct mixer alsa_mixer = { + .name = "alsa", + .open = alsa_mix_open, + .get_channels = alsa_mix_get_channels, + .set_channel = alsa_mix_set_channel, + .close = alsa_mix_close, + .get = alsa_mix_get, + .set = alsa_mix_set +};