aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2013-01-16 23:29:56 +0100
committerMax Kellermann <max@duempel.org>2013-01-16 23:29:56 +0100
commite22ef6c481ab6fff3a704c515804101d9ae399a1 (patch)
tree3323ddf2f6fa21501278eb34f783d5b65ccea25d /src
parent2bb01093c0898d2605ba7df0b2cba6e8541a8509 (diff)
downloadmpd-e22ef6c481ab6fff3a704c515804101d9ae399a1.tar.gz
mpd-e22ef6c481ab6fff3a704c515804101d9ae399a1.tar.xz
mpd-e22ef6c481ab6fff3a704c515804101d9ae399a1.zip
output/roar: convert to C++
Diffstat (limited to 'src')
-rw-r--r--src/OutputList.cxx2
-rw-r--r--src/mixer/RoarMixerPlugin.cxx (renamed from src/mixer/roar_mixer_plugin.c)76
-rw-r--r--src/output/RoarOutputPlugin.cxx (renamed from src/output/roar_output_plugin.c)148
-rw-r--r--src/output/RoarOutputPlugin.hxx (renamed from src/output/roar_output_plugin.h)10
4 files changed, 99 insertions, 137 deletions
diff --git a/src/OutputList.cxx b/src/OutputList.cxx
index df064219f..a9a0b3d33 100644
--- a/src/OutputList.cxx
+++ b/src/OutputList.cxx
@@ -34,7 +34,7 @@
#include "output/pipe_output_plugin.h"
#include "output/pulse_output_plugin.h"
#include "output/recorder_output_plugin.h"
-#include "output/roar_output_plugin.h"
+#include "output/RoarOutputPlugin.hxx"
#include "output/shout_output_plugin.h"
#include "output/solaris_output_plugin.h"
#include "output/winmm_output_plugin.h"
diff --git a/src/mixer/roar_mixer_plugin.c b/src/mixer/RoarMixerPlugin.cxx
index 47d3c17f9..2803203b7 100644
--- a/src/mixer/roar_mixer_plugin.c
+++ b/src/mixer/RoarMixerPlugin.cxx
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2003-2010 The Music Player Daemon Project
+ * Copyright (C) 2003-2013 The Music Player Daemon Project
* Copyright (C) 2010-2011 Philipp 'ph3-der-loewe' Schafft
* Copyright (C) 2010-2011 Hans-Kristian 'maister' Arntzen
*
@@ -22,83 +22,55 @@
#include "config.h"
#include "mixer_api.h"
#include "output_api.h"
-#include "output/roar_output_plugin.h"
+#include "output/RoarOutputPlugin.hxx"
-#include <glib.h>
-
-#include <assert.h>
-#include <stdlib.h>
-#include <unistd.h>
-
-typedef struct roar_mpd_mixer
-{
+struct RoarMixer {
/** the base mixer class */
struct mixer base;
- struct roar *self;
-} roar_mixer_t;
+ RoarOutput *self;
-/**
- * The quark used for GError.domain.
- */
-static inline GQuark
-roar_mixer_quark(void)
-{
- return g_quark_from_static_string("roar_mixer");
-}
+ RoarMixer(RoarOutput *_output):self(_output) {
+ mixer_init(&base, &roar_mixer_plugin);
+ }
+};
static struct mixer *
-roar_mixer_init(void *ao, G_GNUC_UNUSED const struct config_param *param,
- G_GNUC_UNUSED GError **error_r)
+roar_mixer_init(void *ao, gcc_unused const struct config_param *param,
+ gcc_unused GError **error_r)
{
- roar_mixer_t *self = g_new(roar_mixer_t, 1);
- self->self = ao;
-
- mixer_init(&self->base, &roar_mixer_plugin);
-
+ RoarMixer *self = new RoarMixer((RoarOutput *)ao);
return &self->base;
}
static void
roar_mixer_finish(struct mixer *data)
{
- roar_mixer_t *self = (roar_mixer_t *) data;
+ RoarMixer *self = (RoarMixer *) data;
- g_free(self);
-}
-
-static void
-roar_mixer_close(G_GNUC_UNUSED struct mixer *data)
-{
-}
-
-static bool
-roar_mixer_open(G_GNUC_UNUSED struct mixer *data,
- G_GNUC_UNUSED GError **error_r)
-{
- return true;
+ delete self;
}
static int
-roar_mixer_get_volume(struct mixer *mixer, G_GNUC_UNUSED GError **error_r)
+roar_mixer_get_volume(struct mixer *mixer, gcc_unused GError **error_r)
{
- roar_mixer_t *self = (roar_mixer_t *)mixer;
+ RoarMixer *self = (RoarMixer *)mixer;
return roar_output_get_volume(self->self);
}
static bool
roar_mixer_set_volume(struct mixer *mixer, unsigned volume,
- G_GNUC_UNUSED GError **error_r)
+ gcc_unused GError **error_r)
{
- roar_mixer_t *self = (roar_mixer_t *)mixer;
+ RoarMixer *self = (RoarMixer *)mixer;
return roar_output_set_volume(self->self, volume);
}
const struct mixer_plugin roar_mixer_plugin = {
- .init = roar_mixer_init,
- .finish = roar_mixer_finish,
- .open = roar_mixer_open,
- .close = roar_mixer_close,
- .get_volume = roar_mixer_get_volume,
- .set_volume = roar_mixer_set_volume,
- .global = false,
+ roar_mixer_init,
+ roar_mixer_finish,
+ nullptr,
+ nullptr,
+ roar_mixer_get_volume,
+ roar_mixer_set_volume,
+ false,
};
diff --git a/src/output/roar_output_plugin.c b/src/output/RoarOutputPlugin.cxx
index 1c2c48321..43aeb09a2 100644
--- a/src/output/roar_output_plugin.c
+++ b/src/output/RoarOutputPlugin.cxx
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2003-2010 The Music Player Daemon Project
+ * Copyright (C) 2003-2013 The Music Player Daemon Project
* Copyright (C) 2010-2011 Philipp 'ph3-der-loewe' Schafft
* Copyright (C) 2010-2011 Hans-Kristian 'maister' Arntzen
*
@@ -19,25 +19,19 @@
*/
#include "config.h"
-#include "roar_output_plugin.h"
+#include "RoarOutputPlugin.hxx"
#include "output_api.h"
#include "mixer_list.h"
-#include "roar_output_plugin.h"
+#include "thread/Mutex.hxx"
#include <glib.h>
-#include <stdint.h>
-#include <unistd.h>
-#include <stdlib.h>
-#include <string.h>
-#include <stdint.h>
#include <roaraudio.h>
#undef G_LOG_DOMAIN
#define G_LOG_DOMAIN "roaraudio"
-typedef struct roar
-{
+struct RoarOutput {
struct audio_output base;
roar_vs_t * vss;
@@ -47,9 +41,18 @@ typedef struct roar
int role;
struct roar_connection con;
struct roar_audio_info info;
- GMutex *lock;
+ Mutex mutex;
volatile bool alive;
-} roar_t;
+
+ RoarOutput()
+ :err(ROAR_ERROR_NONE),
+ host(nullptr), name(nullptr) {}
+
+ ~RoarOutput() {
+ g_free(host);
+ g_free(name);
+ }
+};
static inline GQuark
roar_output_quark(void)
@@ -58,9 +61,9 @@ roar_output_quark(void)
}
static int
-roar_output_get_volume_locked(struct roar *roar)
+roar_output_get_volume_locked(RoarOutput *roar)
{
- if (roar->vss == NULL || !roar->alive)
+ if (roar->vss == nullptr || !roar->alive)
return -1;
float l, r;
@@ -72,20 +75,18 @@ roar_output_get_volume_locked(struct roar *roar)
}
int
-roar_output_get_volume(struct roar *roar)
+roar_output_get_volume(RoarOutput *roar)
{
- g_mutex_lock(roar->lock);
- int volume = roar_output_get_volume_locked(roar);
- g_mutex_unlock(roar->lock);
- return volume;
+ const ScopeLock protect(roar->mutex);
+ return roar_output_get_volume_locked(roar);
}
static bool
-roar_output_set_volume_locked(struct roar *roar, unsigned volume)
+roar_output_set_volume_locked(RoarOutput *roar, unsigned volume)
{
assert(volume <= 100);
- if (roar->vss == NULL || !roar->alive)
+ if (roar->vss == nullptr || !roar->alive)
return false;
int error;
@@ -96,22 +97,20 @@ roar_output_set_volume_locked(struct roar *roar, unsigned volume)
}
bool
-roar_output_set_volume(struct roar *roar, unsigned volume)
+roar_output_set_volume(RoarOutput *roar, unsigned volume)
{
- g_mutex_lock(roar->lock);
- bool success = roar_output_set_volume_locked(roar, volume);
- g_mutex_unlock(roar->lock);
- return success;
+ const ScopeLock protect(roar->mutex);
+ return roar_output_set_volume_locked(roar, volume);
}
static void
-roar_configure(struct roar * self, const struct config_param *param)
+roar_configure(RoarOutput *self, const struct config_param *param)
{
- self->host = config_dup_block_string(param, "server", NULL);
+ self->host = config_dup_block_string(param, "server", nullptr);
self->name = config_dup_block_string(param, "name", "MPD");
const char *role = config_get_block_string(param, "role", "music");
- self->role = role != NULL
+ self->role = role != nullptr
? roar_str2role(role)
: ROAR_ROLE_MUSIC;
}
@@ -119,15 +118,13 @@ roar_configure(struct roar * self, const struct config_param *param)
static struct audio_output *
roar_init(const struct config_param *param, GError **error_r)
{
- struct roar *self = g_new0(struct roar, 1);
+ RoarOutput *self = new RoarOutput();
if (!ao_base_init(&self->base, &roar_output_plugin, param, error_r)) {
- g_free(self);
- return NULL;
+ delete self;
+ return nullptr;
}
- self->lock = g_mutex_new();
- self->err = ROAR_ERROR_NONE;
roar_configure(self, param);
return &self->base;
}
@@ -135,14 +132,10 @@ roar_init(const struct config_param *param, GError **error_r)
static void
roar_finish(struct audio_output *ao)
{
- struct roar *self = (struct roar *)ao;
-
- g_free(self->host);
- g_free(self->name);
- g_mutex_free(self->lock);
+ RoarOutput *self = (RoarOutput *)ao;
ao_base_finish(&self->base);
- g_free(self);
+ delete self;
}
static void
@@ -181,24 +174,22 @@ roar_use_audio_format(struct roar_audio_info *info,
static bool
roar_open(struct audio_output *ao, struct audio_format *audio_format, GError **error)
{
- struct roar *self = (struct roar *)ao;
- g_mutex_lock(self->lock);
+ RoarOutput *self = (RoarOutput *)ao;
+ const ScopeLock protect(self->mutex);
if (roar_simple_connect(&(self->con), self->host, self->name) < 0)
{
g_set_error(error, roar_output_quark(), 0,
"Failed to connect to Roar server");
- g_mutex_unlock(self->lock);
return false;
}
self->vss = roar_vs_new_from_con(&(self->con), &(self->err));
- if (self->vss == NULL || self->err != ROAR_ERROR_NONE)
+ if (self->vss == nullptr || self->err != ROAR_ERROR_NONE)
{
g_set_error(error, roar_output_quark(), 0,
"Failed to connect to server");
- g_mutex_unlock(self->lock);
return false;
}
@@ -208,43 +199,41 @@ roar_open(struct audio_output *ao, struct audio_format *audio_format, GError **e
&(self->err)) < 0)
{
g_set_error(error, roar_output_quark(), 0, "Failed to start stream");
- g_mutex_unlock(self->lock);
return false;
}
roar_vs_role(self->vss, self->role, &(self->err));
self->alive = true;
- g_mutex_unlock(self->lock);
return true;
}
static void
roar_close(struct audio_output *ao)
{
- struct roar *self = (struct roar *)ao;
- g_mutex_lock(self->lock);
+ RoarOutput *self = (RoarOutput *)ao;
+ const ScopeLock protect(self->mutex);
+
self->alive = false;
- if (self->vss != NULL)
+ if (self->vss != nullptr)
roar_vs_close(self->vss, ROAR_VS_TRUE, &(self->err));
- self->vss = NULL;
+ self->vss = nullptr;
roar_disconnect(&(self->con));
- g_mutex_unlock(self->lock);
}
static void
-roar_cancel_locked(struct roar *self)
+roar_cancel_locked(RoarOutput *self)
{
- if (self->vss == NULL)
+ if (self->vss == nullptr)
return;
roar_vs_t *vss = self->vss;
- self->vss = NULL;
+ self->vss = nullptr;
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)
+ if (vss == nullptr)
return;
if (roar_vs_stream(vss, &(self->info), ROAR_DIR_PLAY,
@@ -262,20 +251,19 @@ roar_cancel_locked(struct roar *self)
static void
roar_cancel(struct audio_output *ao)
{
- struct roar *self = (struct roar *)ao;
+ RoarOutput *self = (RoarOutput *)ao;
- g_mutex_lock(self->lock);
+ const ScopeLock protect(self->mutex);
roar_cancel_locked(self);
- g_mutex_unlock(self->lock);
}
static size_t
roar_play(struct audio_output *ao, const void *chunk, size_t size, GError **error)
{
- struct roar *self = (struct roar *)ao;
+ RoarOutput *self = (RoarOutput *)ao;
ssize_t rc;
- if (self->vss == NULL)
+ if (self->vss == nullptr)
{
g_set_error(error, roar_output_quark(), 0, "Connection is invalid");
return 0;
@@ -332,19 +320,20 @@ roar_tag_convert(enum tag_type type, bool *is_uuid)
return "HASH";
default:
- return NULL;
+ return nullptr;
}
}
static void
roar_send_tag(struct audio_output *ao, const struct tag *meta)
{
- struct roar *self = (struct roar *)ao;
+ RoarOutput *self = (RoarOutput *)ao;
- if (self->vss == NULL)
+ if (self->vss == nullptr)
return;
- g_mutex_lock(self->lock);
+ const ScopeLock protect(self->mutex);
+
size_t cnt = 1;
struct roar_keyval vals[32];
memset(vals, 0, sizeof(vals));
@@ -361,7 +350,7 @@ roar_send_tag(struct audio_output *ao, const struct tag *meta)
{
bool is_uuid = false;
const char *key = roar_tag_convert(meta->items[i]->type, &is_uuid);
- if (key != NULL)
+ if (key != nullptr)
{
if (is_uuid)
{
@@ -383,19 +372,22 @@ roar_send_tag(struct audio_output *ao, const struct tag *meta)
for (unsigned i = 0; i < 32; i++)
g_free(vals[i].key);
-
- g_mutex_unlock(self->lock);
}
const struct audio_output_plugin roar_output_plugin = {
- .name = "roar",
- .init = roar_init,
- .finish = roar_finish,
- .open = roar_open,
- .play = roar_play,
- .cancel = roar_cancel,
- .close = roar_close,
- .send_tag = roar_send_tag,
-
- .mixer_plugin = &roar_mixer_plugin
+ "roar",
+ nullptr,
+ roar_init,
+ roar_finish,
+ nullptr,
+ nullptr,
+ roar_open,
+ roar_close,
+ nullptr,
+ roar_send_tag,
+ roar_play,
+ nullptr,
+ roar_cancel,
+ nullptr,
+ &roar_mixer_plugin,
};
diff --git a/src/output/roar_output_plugin.h b/src/output/RoarOutputPlugin.hxx
index 78b628cc4..faa4b4d5c 100644
--- a/src/output/roar_output_plugin.h
+++ b/src/output/RoarOutputPlugin.hxx
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2003-2011 The Music Player Daemon Project
+ * Copyright (C) 2003-2013 The Music Player Daemon Project
* http://www.musicpd.org
*
* This program is free software; you can redistribute it and/or modify
@@ -20,16 +20,14 @@
#ifndef MPD_ROAR_OUTPUT_PLUGIN_H
#define MPD_ROAR_OUTPUT_PLUGIN_H
-#include <stdbool.h>
-
-struct roar;
+struct RoarOutput;
extern const struct audio_output_plugin roar_output_plugin;
int
-roar_output_get_volume(struct roar *roar);
+roar_output_get_volume(RoarOutput *roar);
bool
-roar_output_set_volume(struct roar *roar, unsigned volume);
+roar_output_set_volume(RoarOutput *roar, unsigned volume);
#endif