aboutsummaryrefslogtreecommitdiffstats
path: root/src/mixer/alsa_mixer_plugin.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/mixer/alsa_mixer_plugin.c')
-rw-r--r--src/mixer/alsa_mixer_plugin.c59
1 files changed, 34 insertions, 25 deletions
diff --git a/src/mixer/alsa_mixer_plugin.c b/src/mixer/alsa_mixer_plugin.c
index e01b737d1..a6e6f364e 100644
--- a/src/mixer/alsa_mixer_plugin.c
+++ b/src/mixer/alsa_mixer_plugin.c
@@ -81,16 +81,6 @@ alsa_mixer_finish(struct mixer *data)
snd_config_update_free_global();
}
-static void
-alsa_mixer_close(struct mixer *data)
-{
- struct alsa_mixer *am = (struct alsa_mixer *)data;
-
- assert(am->handle != NULL);
-
- snd_mixer_close(am->handle);
-}
-
G_GNUC_PURE
static snd_mixer_elem_t *
alsa_mixer_lookup_elem(snd_mixer_t *handle, const char *name, unsigned idx)
@@ -109,22 +99,11 @@ alsa_mixer_lookup_elem(snd_mixer_t *handle, const char *name, unsigned idx)
}
static bool
-alsa_mixer_open(struct mixer *data, GError **error_r)
+alsa_mixer_setup(struct alsa_mixer *am, GError **error_r)
{
- struct alsa_mixer *am = (struct alsa_mixer *)data;
int err;
- am->volume_set = -1;
-
- err = snd_mixer_open(&am->handle, 0);
- if (err < 0) {
- g_set_error(error_r, alsa_mixer_quark(), err,
- "snd_mixer_open() failed: %s", snd_strerror(err));
- return false;
- }
-
if ((err = snd_mixer_attach(am->handle, am->device)) < 0) {
- alsa_mixer_close(data);
g_set_error(error_r, alsa_mixer_quark(), err,
"failed to attach to %s: %s",
am->device, snd_strerror(err));
@@ -133,7 +112,6 @@ alsa_mixer_open(struct mixer *data, GError **error_r)
if ((err = snd_mixer_selem_register(am->handle, NULL,
NULL)) < 0) {
- alsa_mixer_close(data);
g_set_error(error_r, alsa_mixer_quark(), err,
"snd_mixer_selem_register() failed: %s",
snd_strerror(err));
@@ -141,7 +119,6 @@ alsa_mixer_open(struct mixer *data, GError **error_r)
}
if ((err = snd_mixer_load(am->handle)) < 0) {
- alsa_mixer_close(data);
g_set_error(error_r, alsa_mixer_quark(), err,
"snd_mixer_load() failed: %s\n",
snd_strerror(err));
@@ -150,7 +127,6 @@ alsa_mixer_open(struct mixer *data, GError **error_r)
am->elem = alsa_mixer_lookup_elem(am->handle, am->control, am->index);
if (am->elem == NULL) {
- alsa_mixer_close(data);
g_set_error(error_r, alsa_mixer_quark(), 0,
"no such mixer control: %s", am->control);
return false;
@@ -162,6 +138,39 @@ alsa_mixer_open(struct mixer *data, GError **error_r)
return true;
}
+static bool
+alsa_mixer_open(struct mixer *data, GError **error_r)
+{
+ struct alsa_mixer *am = (struct alsa_mixer *)data;
+ int err;
+
+ am->volume_set = -1;
+
+ err = snd_mixer_open(&am->handle, 0);
+ if (err < 0) {
+ g_set_error(error_r, alsa_mixer_quark(), err,
+ "snd_mixer_open() failed: %s", snd_strerror(err));
+ return false;
+ }
+
+ if (!alsa_mixer_setup(am, error_r)) {
+ snd_mixer_close(am->handle);
+ return false;
+ }
+
+ return true;
+}
+
+static void
+alsa_mixer_close(struct mixer *data)
+{
+ struct alsa_mixer *am = (struct alsa_mixer *)data;
+
+ assert(am->handle != NULL);
+
+ snd_mixer_close(am->handle);
+}
+
static int
alsa_mixer_get_volume(struct mixer *mixer, GError **error_r)
{