aboutsummaryrefslogtreecommitdiffstats
path: root/src/mixer
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2009-01-25 17:45:16 +0100
committerMax Kellermann <max@duempel.org>2009-01-25 17:45:16 +0100
commit936449c6225624102d0a6cb78f9bb4da84375d60 (patch)
tree790c03c5f7769197bc81e058055921a0d246af26 /src/mixer
parentdc575106c296435940482cc2655804c71ee2d934 (diff)
downloadmpd-936449c6225624102d0a6cb78f9bb4da84375d60.tar.gz
mpd-936449c6225624102d0a6cb78f9bb4da84375d60.tar.xz
mpd-936449c6225624102d0a6cb78f9bb4da84375d60.zip
mixer_api: removed struct mixer_data
The mixer plugins should re-use the mixer struct and incorporate it in their object class.
Diffstat (limited to '')
-rw-r--r--src/mixer/alsa_mixer.c19
-rw-r--r--src/mixer/oss_mixer.c19
-rw-r--r--src/mixer_api.c27
-rw-r--r--src/mixer_api.h19
4 files changed, 45 insertions, 39 deletions
diff --git a/src/mixer/alsa_mixer.c b/src/mixer/alsa_mixer.c
index 95e5c70ee..d35040499 100644
--- a/src/mixer/alsa_mixer.c
+++ b/src/mixer/alsa_mixer.c
@@ -26,6 +26,9 @@
#define VOLUME_MIXER_ALSA_CONTROL_DEFAULT "PCM"
struct alsa_mixer {
+ /** the base mixer class */
+ struct mixer base;
+
char *device;
char *control;
snd_mixer_t *handle;
@@ -35,10 +38,12 @@ struct alsa_mixer {
int volume_set;
};
-static struct mixer_data *
+static struct mixer *
alsa_mixer_init(const struct config_param *param)
{
- struct alsa_mixer *am = g_malloc(sizeof(struct alsa_mixer));
+ struct alsa_mixer *am = g_new(struct alsa_mixer, 1);
+
+ mixer_init(&am->base, &alsa_mixer);
am->device = config_dup_block_string(param, "mixer_device", NULL);
am->control = config_dup_block_string(param, "mixer_control", NULL);
@@ -49,11 +54,11 @@ alsa_mixer_init(const struct config_param *param)
am->volume_max = 0;
am->volume_set = -1;
- return (struct mixer_data *)am;
+ return &am->base;
}
static void
-alsa_mixer_finish(struct mixer_data *data)
+alsa_mixer_finish(struct mixer *data)
{
struct alsa_mixer *am = (struct alsa_mixer *)data;
@@ -63,7 +68,7 @@ alsa_mixer_finish(struct mixer_data *data)
}
static void
-alsa_mixer_close(struct mixer_data *data)
+alsa_mixer_close(struct mixer *data)
{
struct alsa_mixer *am = (struct alsa_mixer *)data;
if (am->handle) snd_mixer_close(am->handle);
@@ -71,7 +76,7 @@ alsa_mixer_close(struct mixer_data *data)
}
static bool
-alsa_mixer_open(struct mixer_data *data)
+alsa_mixer_open(struct mixer *data)
{
struct alsa_mixer *am = (struct alsa_mixer *)data;
int err;
@@ -142,7 +147,7 @@ alsa_mixer_open(struct mixer_data *data)
}
static bool
-alsa_mixer_control(struct mixer_data *data, int cmd, void *arg)
+alsa_mixer_control(struct mixer *data, int cmd, void *arg)
{
struct alsa_mixer *am = (struct alsa_mixer *)data;
switch (cmd) {
diff --git a/src/mixer/oss_mixer.c b/src/mixer/oss_mixer.c
index 261616747..4dbd40bbb 100644
--- a/src/mixer/oss_mixer.c
+++ b/src/mixer/oss_mixer.c
@@ -36,16 +36,21 @@
#define VOLUME_MIXER_OSS_DEFAULT "/dev/mixer"
struct oss_mixer {
+ /** the base mixer class */
+ struct mixer base;
+
char *device;
char *control;
int device_fd;
int volume_control;
};
-static struct mixer_data *
+static struct mixer *
oss_mixer_init(const struct config_param *param)
{
- struct oss_mixer *om = g_malloc(sizeof(struct oss_mixer));
+ struct oss_mixer *om = g_new(struct oss_mixer, 1);
+
+ mixer_init(&om->base, &oss_mixer);
om->device = config_dup_block_string(param, "mixer_device", NULL);
om->control = config_dup_block_string(param, "mixer_control", NULL);
@@ -53,11 +58,11 @@ oss_mixer_init(const struct config_param *param)
om->device_fd = -1;
om->volume_control = SOUND_MIXER_PCM;
- return (struct mixer_data *)om;
+ return &om->base;
}
static void
-oss_mixer_finish(struct mixer_data *data)
+oss_mixer_finish(struct mixer *data)
{
struct oss_mixer *om = (struct oss_mixer *) data;
@@ -67,7 +72,7 @@ oss_mixer_finish(struct mixer_data *data)
}
static void
-oss_mixer_close(struct mixer_data *data)
+oss_mixer_close(struct mixer *data)
{
struct oss_mixer *om = (struct oss_mixer *) data;
if (om->device_fd != -1)
@@ -91,7 +96,7 @@ oss_find_mixer(const char *name)
}
static bool
-oss_mixer_open(struct mixer_data *data)
+oss_mixer_open(struct mixer *data)
{
struct oss_mixer *om = (struct oss_mixer *) data;
const char *device = VOLUME_MIXER_OSS_DEFAULT;
@@ -133,7 +138,7 @@ oss_mixer_open(struct mixer_data *data)
}
static bool
-oss_mixer_control(struct mixer_data *data, int cmd, void *arg)
+oss_mixer_control(struct mixer *data, int cmd, void *arg)
{
struct oss_mixer *om = (struct oss_mixer *) data;
switch (cmd) {
diff --git a/src/mixer_api.c b/src/mixer_api.c
index 0cf4e0c92..b0905bc5e 100644
--- a/src/mixer_api.c
+++ b/src/mixer_api.c
@@ -21,14 +21,6 @@
#include "mixer_api.h"
-void mixer_finish(struct mixer *mixer)
-{
- assert(mixer != NULL && mixer->plugin != NULL);
- mixer->plugin->finish(mixer->data);
- mixer->data = NULL;
- mixer->plugin = NULL;
-}
-
struct mixer *
mixer_new(const struct mixer_plugin *plugin, const struct config_param *param)
{
@@ -36,33 +28,36 @@ mixer_new(const struct mixer_plugin *plugin, const struct config_param *param)
assert(plugin != NULL);
- mixer = g_new(struct mixer, 1);
- mixer->plugin = plugin;
- mixer->data = mixer->plugin->init(param);
+ mixer = plugin->init(param);
+
+ assert(mixer->plugin == plugin);
+
return mixer;
}
void
mixer_free(struct mixer *mixer)
{
- mixer_finish(mixer);
- g_free(mixer);
+ assert(mixer != NULL);
+ assert(mixer->plugin != NULL);
+
+ mixer->plugin->finish(mixer);
}
bool mixer_open(struct mixer *mixer)
{
assert(mixer != NULL && mixer->plugin != NULL);
- return mixer->plugin->open(mixer->data);
+ return mixer->plugin->open(mixer);
}
bool mixer_control(struct mixer *mixer, int cmd, void *arg)
{
assert(mixer != NULL && mixer->plugin != NULL);
- return mixer->plugin->control(mixer->data, cmd, arg);
+ return mixer->plugin->control(mixer, cmd, arg);
}
void mixer_close(struct mixer *mixer)
{
assert(mixer != NULL && mixer->plugin != NULL);
- mixer->plugin->close(mixer->data);
+ mixer->plugin->close(mixer);
}
diff --git a/src/mixer_api.h b/src/mixer_api.h
index 50a9cb165..b79d02a1c 100644
--- a/src/mixer_api.h
+++ b/src/mixer_api.h
@@ -28,41 +28,42 @@
extern const struct mixer_plugin alsa_mixer;
extern const struct mixer_plugin oss_mixer;
-struct mixer_data;
-
struct mixer_plugin {
/**
* Alocates and configures a mixer device.
*/
- struct mixer_data *(*init)(const struct config_param *param);
+ struct mixer *(*init)(const struct config_param *param);
/**
* Finish and free mixer data
*/
- void (*finish)(struct mixer_data *data);
+ void (*finish)(struct mixer *data);
/**
* Open mixer device
*/
- bool (*open)(struct mixer_data *data);
+ bool (*open)(struct mixer *data);
/**
* Control mixer device.
*/
- bool (*control)(struct mixer_data *data, int cmd, void *arg);
+ bool (*control)(struct mixer *data, int cmd, void *arg);
/**
* Close mixer device
*/
- void (*close)(struct mixer_data *data);
+ void (*close)(struct mixer *data);
};
struct mixer {
const struct mixer_plugin *plugin;
- struct mixer_data *data;
};
-void mixer_finish(struct mixer *mixer);
+static inline void
+mixer_init(struct mixer *mixer, const struct mixer_plugin *plugin)
+{
+ mixer->plugin = plugin;
+}
struct mixer *
mixer_new(const struct mixer_plugin *plugin, const struct config_param *param);