aboutsummaryrefslogtreecommitdiffstats
path: root/src/output
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2011-09-18 11:51:18 +0200
committerMax Kellermann <max@duempel.org>2011-09-18 11:51:18 +0200
commitd4d838c8bbe6d537055f9ae91436c8c8c7e76e09 (patch)
treed5171254318d4f75d6d4f897ed957c5b7e7d9381 /src/output
parentc61a889c8633714e0f5aec83eb8917ef308db628 (diff)
downloadmpd-d4d838c8bbe6d537055f9ae91436c8c8c7e76e09.tar.gz
mpd-d4d838c8bbe6d537055f9ae91436c8c8c7e76e09.tar.xz
mpd-d4d838c8bbe6d537055f9ae91436c8c8c7e76e09.zip
output/roar: move code to roar_cancel_locked() and others
Wrap the locking code.
Diffstat (limited to 'src/output')
-rw-r--r--src/output/roar_output_plugin.c94
1 files changed, 55 insertions, 39 deletions
diff --git a/src/output/roar_output_plugin.c b/src/output/roar_output_plugin.c
index 2d1cb09c7..c43b5ac34 100644
--- a/src/output/roar_output_plugin.c
+++ b/src/output/roar_output_plugin.c
@@ -55,39 +55,49 @@ roar_output_quark(void)
return g_quark_from_static_string("roar_output");
}
+static int
+roar_output_get_volume_locked(struct roar *roar)
+{
+ if (roar->vss == NULL || !roar->alive)
+ return 0;
+
+ float l, r;
+ int error;
+ roar_vs_volume_get(roar->vss, &l, &r, &error);
+ return (l + r) * 50;
+}
+
int
roar_output_get_volume(struct roar *roar)
{
g_mutex_lock(roar->lock);
- if (roar->vss && roar->alive) {
- float l, r;
- int error;
- roar_vs_volume_get(roar->vss, &l, &r, &error);
- g_mutex_unlock(roar->lock);
- return (l + r) * 50;
- } else {
- g_mutex_unlock(roar->lock);
- return 0;
- }
+ int volume = roar_output_get_volume_locked(roar);
+ g_mutex_unlock(roar->lock);
+ return volume;
+}
+
+static bool
+roar_output_set_volume_locked(struct roar *roar, unsigned volume)
+{
+ assert(volume <= 100);
+
+ if (roar->vss == NULL || !roar->alive)
+ return false;
+
+ int error;
+ float level = volume / 100.0;
+
+ roar_vs_volume_mono(roar->vss, level, &error);
+ return true;
}
bool
roar_output_set_volume(struct roar *roar, unsigned volume)
{
g_mutex_lock(roar->lock);
- if (roar->vss && roar->alive) {
- assert(volume <= 100);
-
- int error;
- float level = volume / 100.0;
-
- roar_vs_volume_mono(roar->vss, level, &error);
- g_mutex_unlock(roar->lock);
- return true;
- } else {
- g_mutex_unlock(roar->lock);
- return false;
- }
+ bool success = roar_output_set_volume_locked(roar, volume);
+ g_mutex_unlock(roar->lock);
+ return success;
}
static void
@@ -207,27 +217,33 @@ roar_close(void *data)
}
static void
+roar_cancel_locked(struct roar *self)
+{
+ if (self->vss == NULL)
+ return;
+
+ roar_vs_t *vss = self->vss;
+ self->vss = NULL;
+ roar_vs_close(vss, ROAR_VS_TRUE, &(self->err));
+ self->alive = false;
+
+ vss = roar_vs_new_from_con(&(self->con), &(self->err));
+ if (vss == NULL)
+ return;
+
+ roar_vs_stream(vss, &(self->info), ROAR_DIR_PLAY, &(self->err));
+ roar_vs_role(vss, self->role, &(self->err));
+ self->vss = vss;
+ self->alive = true;
+}
+
+static void
roar_cancel(void *data)
{
roar_t * self = data;
g_mutex_lock(self->lock);
- if (self->vss != NULL)
- {
- roar_vs_t *vss = self->vss;
- self->vss = NULL;
- roar_vs_close(vss, ROAR_VS_TRUE, &(self->err));
- self->alive = false;
-
- vss = roar_vs_new_from_con(&(self->con), &(self->err));
- if (vss)
- {
- roar_vs_stream(vss, &(self->info), ROAR_DIR_PLAY, &(self->err));
- roar_vs_role(vss, self->role, &(self->err));
- self->vss = vss;
- self->alive = true;
- }
- }
+ roar_cancel_locked(self);
g_mutex_unlock(self->lock);
}