aboutsummaryrefslogtreecommitdiffstats
path: root/src/output
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2009-03-26 18:23:23 +0100
committerMax Kellermann <max@duempel.org>2009-03-26 18:23:23 +0100
commit66a2c5669e1fcd709a00bd4de8ddfb0d3a0c2a58 (patch)
treec138f37dfc13af01df8606ed7a8f882964a32f27 /src/output
parent209c8a540c80faffb6b04ac6e7fed64a03c679ac (diff)
downloadmpd-66a2c5669e1fcd709a00bd4de8ddfb0d3a0c2a58.tar.gz
mpd-66a2c5669e1fcd709a00bd4de8ddfb0d3a0c2a58.tar.xz
mpd-66a2c5669e1fcd709a00bd4de8ddfb0d3a0c2a58.zip
output_plugin: replaced output_plugin.get_mixer() with mixer_plugin
The mixer core library is now responsible for creating and managing the mixer object. This removes duplicated code from the output plugins.
Diffstat (limited to '')
-rw-r--r--src/output/alsa_plugin.c20
-rw-r--r--src/output/oss_plugin.c21
-rw-r--r--src/output/pulse_plugin.c17
-rw-r--r--src/output_command.c2
-rw-r--r--src/output_control.c19
-rw-r--r--src/output_init.c6
-rw-r--r--src/output_internal.h7
-rw-r--r--src/output_plugin.h25
8 files changed, 42 insertions, 75 deletions
diff --git a/src/output/alsa_plugin.c b/src/output/alsa_plugin.c
index 69f4d500f..0295742e2 100644
--- a/src/output/alsa_plugin.c
+++ b/src/output/alsa_plugin.c
@@ -19,7 +19,6 @@
#include "../output_api.h"
#include "mixer_list.h"
-#include "mixer_control.h"
#include <glib.h>
#include <alsa/asoundlib.h>
@@ -70,9 +69,6 @@ struct alsa_data {
/** the size of one audio frame */
size_t frame_size;
-
- /** the mixer object associated with this output */
- struct mixer *mixer;
};
/**
@@ -105,7 +101,6 @@ static void
alsa_data_free(struct alsa_data *ad)
{
g_free(ad->device);
- mixer_free(ad->mixer);
g_free(ad);
}
@@ -151,7 +146,6 @@ alsa_init(G_GNUC_UNUSED const struct audio_format *audio_format,
}
alsa_configure(ad, param);
- ad->mixer = mixer_new(&alsa_mixer, param);
return ad;
}
@@ -164,14 +158,6 @@ alsa_finish(void *data)
alsa_data_free(ad);
}
-static struct mixer *
-alsa_get_mixer(void *data)
-{
- struct alsa_data *ad = data;
-
- return ad->mixer;
-}
-
static bool
alsa_test_default_device(void)
{
@@ -400,8 +386,6 @@ alsa_open(void *data, struct audio_format *audio_format, GError **error)
int err;
bool success;
- mixer_open(ad->mixer);
-
bitformat = get_bitformat(audio_format);
if (bitformat == SND_PCM_FORMAT_UNKNOWN) {
/* sample format is not supported by this plugin -
@@ -484,8 +468,6 @@ alsa_close(void *data)
snd_pcm_drain(ad->pcm);
snd_pcm_close(ad->pcm);
-
- mixer_close(ad->mixer);
}
static size_t
@@ -514,9 +496,9 @@ const struct audio_output_plugin alsaPlugin = {
.test_default_device = alsa_test_default_device,
.init = alsa_init,
.finish = alsa_finish,
- .get_mixer = alsa_get_mixer,
.open = alsa_open,
.play = alsa_play,
.cancel = alsa_cancel,
.close = alsa_close,
+ .mixer_plugin = &alsa_mixer,
};
diff --git a/src/output/oss_plugin.c b/src/output/oss_plugin.c
index 87ab68a08..a66bc0598 100644
--- a/src/output/oss_plugin.c
+++ b/src/output/oss_plugin.c
@@ -19,7 +19,6 @@
#include "../output_api.h"
#include "mixer_list.h"
-#include "mixer_control.h"
#include <glib.h>
@@ -54,9 +53,6 @@ struct oss_data {
unsigned num_supported[3];
int *unsupported[3];
unsigned num_unsupported[3];
-
- /** the mixer object associated with this output */
- struct mixer *mixer;
};
enum oss_support {
@@ -302,8 +298,6 @@ oss_data_free(struct oss_data *od)
g_free(od->unsupported[OSS_CHANNELS]);
g_free(od->unsupported[OSS_BITS]);
- mixer_free(od->mixer);
-
g_free(od);
}
@@ -372,7 +366,6 @@ oss_open_default(GError **error)
if (ret[i] == OSS_STAT_NO_ERROR) {
struct oss_data *od = oss_data_new();
od->device = default_devices[i];
- od->mixer = mixer_new(&oss_mixer, NULL);
return od;
}
}
@@ -412,7 +405,6 @@ oss_output_init(G_GNUC_UNUSED const struct audio_format *audio_format,
if (device != NULL) {
struct oss_data *od = oss_data_new();
od->device = device;
- od->mixer = mixer_new(&oss_mixer, param);
return od;
}
@@ -427,14 +419,6 @@ oss_output_finish(void *data)
oss_data_free(od);
}
-static struct mixer *
-oss_get_mixer(void *data)
-{
- struct oss_data *od = data;
-
- return od->mixer;
-}
-
static int
oss_set_param(struct oss_data *od, unsigned param, int *value)
{
@@ -562,8 +546,6 @@ oss_output_open(void *data, struct audio_format *audio_format, GError **error)
*audio_format = od->audio_format;
- mixer_open(od->mixer);
-
return ret;
}
@@ -573,7 +555,6 @@ oss_output_close(void *data)
struct oss_data *od = data;
oss_close(od);
- mixer_close(od->mixer);
}
static void
@@ -616,9 +597,9 @@ const struct audio_output_plugin oss_output_plugin = {
.test_default_device = oss_output_test_default_device,
.init = oss_output_init,
.finish = oss_output_finish,
- .get_mixer = oss_get_mixer,
.open = oss_output_open,
.close = oss_output_close,
.play = oss_output_play,
.cancel = oss_output_cancel,
+ .mixer_plugin = &oss_mixer,
};
diff --git a/src/output/pulse_plugin.c b/src/output/pulse_plugin.c
index d32e539bf..08ce32365 100644
--- a/src/output/pulse_plugin.c
+++ b/src/output/pulse_plugin.c
@@ -19,7 +19,6 @@
#include "../output_api.h"
#include "mixer_list.h"
-#include "mixer_control.h"
#include <glib.h>
#include <pulse/simple.h>
@@ -29,7 +28,6 @@
struct pulse_data {
const char *name;
- struct mixer *mixer;
pa_simple *s;
char *server;
@@ -62,7 +60,6 @@ static void pulse_free_data(struct pulse_data *pd)
g_free(pd->server);
g_free(pd->sink);
g_free(pd);
- mixer_free(pd->mixer);
}
static void *
@@ -78,8 +75,6 @@ pulse_init(G_GNUC_UNUSED const struct audio_format *audio_format,
pd->sink = param != NULL
? config_dup_block_string(param, "sink", NULL) : NULL;
- pd->mixer=mixer_new(&pulse_mixer, param);
-
return pd;
}
@@ -90,15 +85,6 @@ static void pulse_finish(void *data)
pulse_free_data(pd);
}
-static struct mixer *
-pulse_get_mixer(void *data)
-{
- struct pulse_data *pd = data;
-
- return pd->mixer;
-}
-
-
static bool pulse_test_default_device(void)
{
pa_simple *s;
@@ -147,7 +133,6 @@ pulse_open(void *data, struct audio_format *audio_format, GError **error_r)
pa_strerror(error));
return false;
}
- mixer_open(pd->mixer);
return true;
}
@@ -190,9 +175,9 @@ const struct audio_output_plugin pulse_plugin = {
.test_default_device = pulse_test_default_device,
.init = pulse_init,
.finish = pulse_finish,
- .get_mixer = pulse_get_mixer,
.open = pulse_open,
.play = pulse_play,
.cancel = pulse_cancel,
.close = pulse_close,
+ .mixer_plugin = &pulse_mixer,
};
diff --git a/src/output_command.c b/src/output_command.c
index 7f16a79d7..5da176dde 100644
--- a/src/output_command.c
+++ b/src/output_command.c
@@ -61,7 +61,7 @@ audio_output_disable_index(unsigned idx)
ao->enabled = false;
idle_add(IDLE_OUTPUT);
- mixer = ao_plugin_get_mixer(ao->plugin, ao->data);
+ mixer = ao->mixer;
if (mixer != NULL) {
mixer_close(mixer);
idle_add(IDLE_MIXER);
diff --git a/src/output_control.c b/src/output_control.c
index 78800794f..d19ce3583 100644
--- a/src/output_control.c
+++ b/src/output_control.c
@@ -21,6 +21,7 @@
#include "output_api.h"
#include "output_internal.h"
#include "output_thread.h"
+#include "mixer_control.h"
#include <assert.h>
#include <stdlib.h>
@@ -61,6 +62,8 @@ audio_output_open(struct audio_output *ao,
const struct audio_format *audio_format,
const struct music_pipe *mp)
{
+ bool open;
+
assert(mp != NULL);
if (ao->fail_timer != NULL) {
@@ -93,10 +96,16 @@ audio_output_open(struct audio_output *ao,
if (ao->thread == NULL)
audio_output_thread_start(ao);
- if (!ao->open)
+ open = ao->open;
+ if (!open) {
ao_command(ao, AO_COMMAND_OPEN);
+ open = ao->open;
+ }
- return ao->open;
+ if (open && ao->mixer != NULL)
+ mixer_open(ao->mixer);
+
+ return open;
}
bool
@@ -139,6 +148,9 @@ void audio_output_close(struct audio_output *ao)
{
assert(!ao->open || ao->fail_timer == NULL);
+ if (ao->mixer != NULL)
+ mixer_close(ao->mixer);
+
if (ao->open)
ao_command(ao, AO_COMMAND_CLOSE);
else if (ao->fail_timer != NULL) {
@@ -158,6 +170,9 @@ void audio_output_finish(struct audio_output *ao)
g_thread_join(ao->thread);
}
+ if (ao->mixer != NULL)
+ mixer_free(ao->mixer);
+
ao_plugin_finish(ao->plugin, ao->data);
notify_deinit(&ao->notify);
diff --git a/src/output_init.c b/src/output_init.c
index f837ba8b8..8ec1e0145 100644
--- a/src/output_init.c
+++ b/src/output_init.c
@@ -22,6 +22,7 @@
#include "output_internal.h"
#include "output_list.h"
#include "audio_parser.h"
+#include "mixer_control.h"
#include <glib.h>
@@ -134,5 +135,10 @@ audio_output_init(struct audio_output *ao, const struct config_param *param,
if (ao->data == NULL)
return false;
+ if (plugin->mixer_plugin != NULL)
+ ao->mixer = mixer_new(plugin->mixer_plugin, param);
+ else
+ ao->mixer = NULL;
+
return true;
}
diff --git a/src/output_internal.h b/src/output_internal.h
index 9fc2425c2..362d24947 100644
--- a/src/output_internal.h
+++ b/src/output_internal.h
@@ -53,6 +53,13 @@ struct audio_output {
void *data;
/**
+ * The #mixer object associated with this audio output device.
+ * May be NULL if none is available, or if software volume is
+ * configured.
+ */
+ struct mixer *mixer;
+
+ /**
* This flag is true, when the audio_format of this device is
* configured in mpd.conf.
*/
diff --git a/src/output_plugin.h b/src/output_plugin.h
index 83b5676a4..13dba0d0b 100644
--- a/src/output_plugin.h
+++ b/src/output_plugin.h
@@ -67,15 +67,6 @@ struct audio_output_plugin {
void (*finish)(void *data);
/**
- * Returns the mixer device associated with this audio output.
- * This does not actually open the mixer device yet.
- *
- * @return the mixer object, or NULL if there is no mixer
- * attached to this audio output
- */
- struct mixer *(*get_mixer)(void *data);
-
- /**
* Really open the device.
*
* @param audio_format the audio format in which data is going
@@ -125,6 +116,14 @@ struct audio_output_plugin {
* for continue to pause
*/
bool (*pause)(void *data);
+
+ /**
+ * The mixer plugin associated with this output plugin. This
+ * may be NULL if no mixer plugin is implemented. When
+ * created, this mixer plugin gets the same #config_param as
+ * this audio output device.
+ */
+ const struct mixer_plugin *mixer_plugin;
};
static inline bool
@@ -150,14 +149,6 @@ ao_plugin_finish(const struct audio_output_plugin *plugin, void *data)
plugin->finish(data);
}
-static inline struct mixer *
-ao_plugin_get_mixer(const struct audio_output_plugin *plugin, void *data)
-{
- return plugin->get_mixer != NULL
- ? plugin->get_mixer(data)
- : NULL;
-}
-
static inline bool
ao_plugin_open(const struct audio_output_plugin *plugin,
void *data, struct audio_format *audio_format,