diff options
Diffstat (limited to 'src/mixer')
-rw-r--r-- | src/mixer/AlsaMixerPlugin.cxx (renamed from src/mixer/alsa_mixer_plugin.c) | 189 | ||||
-rw-r--r-- | src/mixer/OssMixerPlugin.cxx (renamed from src/mixer/oss_mixer_plugin.c) | 16 | ||||
-rw-r--r-- | src/mixer/PulseMixerPlugin.cxx (renamed from src/mixer/pulse_mixer_plugin.c) | 30 | ||||
-rw-r--r-- | src/mixer/PulseMixerPlugin.h (renamed from src/mixer/pulse_mixer_plugin.h) | 10 | ||||
-rw-r--r-- | src/mixer/RoarMixerPlugin.cxx (renamed from src/mixer/roar_mixer_plugin.c) | 76 | ||||
-rw-r--r-- | src/mixer/SoftwareMixerPlugin.cxx (renamed from src/mixer/software_mixer_plugin.c) | 28 | ||||
-rw-r--r-- | src/mixer/SoftwareMixerPlugin.hxx (renamed from src/mixer/software_mixer_plugin.h) | 10 | ||||
-rw-r--r-- | src/mixer/winmm_mixer_plugin.c | 2 |
8 files changed, 126 insertions, 235 deletions
diff --git a/src/mixer/alsa_mixer_plugin.c b/src/mixer/AlsaMixerPlugin.cxx index 22e4e22bd..17f8b9a6f 100644 --- a/src/mixer/alsa_mixer_plugin.c +++ b/src/mixer/AlsaMixerPlugin.cxx @@ -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,7 +20,11 @@ #include "config.h" #include "mixer_api.h" #include "output_api.h" -#include "event_pipe.h" +#include "GlobalEvents.hxx" +#include "Main.hxx" +#include "event/MultiSocketMonitor.hxx" + +#include <algorithm> #include <glib.h> #include <alsa/asoundlib.h> @@ -29,13 +33,16 @@ #define VOLUME_MIXER_ALSA_CONTROL_DEFAULT "PCM" #define VOLUME_MIXER_ALSA_INDEX_DEFAULT 0 -struct alsa_mixer_source { - GSource source; +class AlsaMixerMonitor final : private MultiSocketMonitor { + snd_mixer_t *const mixer; - snd_mixer_t *mixer; +public: + AlsaMixerMonitor(EventLoop &_loop, snd_mixer_t *_mixer) + :MultiSocketMonitor(_loop), mixer(_mixer) {} - /** a linked list of all registered GPollFD objects */ - GSList *fds; +private: + virtual void PrepareSockets(gcc_unused gint *timeout_r) override; + virtual void DispatchSockets() override; }; struct alsa_mixer { @@ -52,7 +59,7 @@ struct alsa_mixer { long volume_max; int volume_set; - struct alsa_mixer_source *source; + AlsaMixerMonitor *monitor; }; /** @@ -64,142 +71,45 @@ alsa_mixer_quark(void) return g_quark_from_static_string("alsa_mixer"); } -/* - * GSource helper functions - * - */ - -static GSList ** -find_fd(GSList **list_r, int fd) -{ - while (true) { - GSList *list = *list_r; - if (list == NULL) - return NULL; - - GPollFD *p = list->data; - if (p->fd == fd) - return list_r; - - list_r = &list->next; - } -} - -static void -alsa_mixer_update_fd(struct alsa_mixer_source *source, const struct pollfd *p, - GSList **old_r) -{ - GSList **found_r = find_fd(old_r, p->fd); - if (found_r == NULL) { - /* new fd */ - GPollFD *q = g_new(GPollFD, 1); - q->fd = p->fd; - q->events = p->events; - g_source_add_poll(&source->source, q); - source->fds = g_slist_prepend(source->fds, q); - return; - } - - GSList *found = *found_r; - *found_r = found->next; - - GPollFD *q = found->data; - if (q->events != p->events) { - /* refresh events */ - g_source_remove_poll(&source->source, q); - q->events = p->events; - g_source_add_poll(&source->source, q); - } - - found->next = source->fds; - source->fds = found; -} - -static void -alsa_mixer_update_fds(struct alsa_mixer_source *source) +void +AlsaMixerMonitor::PrepareSockets(gcc_unused gint *timeout_r) { - int count = snd_mixer_poll_descriptors_count(source->mixer); + int count = snd_mixer_poll_descriptors_count(mixer); if (count < 0) count = 0; struct pollfd *pfds = g_new(struct pollfd, count); - count = snd_mixer_poll_descriptors(source->mixer, pfds, count); + count = snd_mixer_poll_descriptors(mixer, pfds, count); if (count < 0) count = 0; - GSList *old = source->fds; - source->fds = NULL; + struct pollfd *end = pfds + count; - for (int i = 0; i < count; ++i) - alsa_mixer_update_fd(source, &pfds[i], &old); - g_free(pfds); + UpdateSocketList([pfds, end](int fd) -> unsigned { + auto i = std::find_if(pfds, end, [fd](const struct pollfd &pfd){ + return pfd.fd == fd; + }); + if (i == end) + return 0; - for (; old != NULL; old = old->next) { - GPollFD *q = old->data; - g_source_remove_poll(&source->source, q); - g_free(q); - } + auto events = i->events; + i->events = 0; + return events; + }); - g_slist_free(old); -} + for (auto i = pfds; i != end; ++i) + if (i->events != 0) + AddSocket(i->fd, i->events); -/* - * GSource methods - * - */ - -static gboolean -alsa_mixer_source_prepare(GSource *_source, G_GNUC_UNUSED gint *timeout_r) -{ - struct alsa_mixer_source *source = (struct alsa_mixer_source *)_source; - alsa_mixer_update_fds(source); - - return false; -} - -static gboolean -alsa_mixer_source_check(GSource *_source) -{ - struct alsa_mixer_source *source = (struct alsa_mixer_source *)_source; - - for (const GSList *i = source->fds; i != NULL; i = i->next) { - const GPollFD *poll_fd = i->data; - if (poll_fd->revents != 0) - return true; - } - - return false; + g_free(pfds); } -static gboolean -alsa_mixer_source_dispatch(GSource *_source, - G_GNUC_UNUSED GSourceFunc callback, - G_GNUC_UNUSED gpointer user_data) +void +AlsaMixerMonitor::DispatchSockets() { - struct alsa_mixer_source *source = (struct alsa_mixer_source *)_source; - - snd_mixer_handle_events(source->mixer); - return true; + snd_mixer_handle_events(mixer); } -static void -alsa_mixer_source_finalize(GSource *_source) -{ - struct alsa_mixer_source *source = (struct alsa_mixer_source *)_source; - - for (GSList *i = source->fds; i != NULL; i = i->next) - g_free(i->data); - - g_slist_free(source->fds); -} - -static GSourceFuncs alsa_mixer_source_funcs = { - .prepare = alsa_mixer_source_prepare, - .check = alsa_mixer_source_check, - .dispatch = alsa_mixer_source_dispatch, - .finalize = alsa_mixer_source_finalize, -}; - /* * libasound callbacks * @@ -209,7 +119,7 @@ static int alsa_mixer_elem_callback(G_GNUC_UNUSED snd_mixer_elem_t *elem, unsigned mask) { if (mask & SND_CTL_EVENT_MASK_VALUE) - event_pipe_emit(PIPE_EVENT_MIXER); + GlobalEvents::Emit(GlobalEvents::MIXER); return 0; } @@ -304,11 +214,7 @@ alsa_mixer_setup(struct alsa_mixer *am, GError **error_r) snd_mixer_elem_set_callback(am->elem, alsa_mixer_elem_callback); - am->source = (struct alsa_mixer_source *) - g_source_new(&alsa_mixer_source_funcs, sizeof(*am->source)); - am->source->mixer = am->handle; - am->source->fds = NULL; - g_source_attach(&am->source->source, g_main_context_default()); + am->monitor = new AlsaMixerMonitor(*main_loop, am->handle); return true; } @@ -343,8 +249,7 @@ alsa_mixer_close(struct mixer *data) assert(am->handle != NULL); - g_source_destroy(&am->source->source); - g_source_unref(&am->source->source); + delete am->monitor; snd_mixer_elem_set_callback(am->elem, NULL); snd_mixer_close(am->handle); @@ -421,11 +326,11 @@ alsa_mixer_set_volume(struct mixer *mixer, unsigned volume, GError **error_r) } const struct mixer_plugin alsa_mixer_plugin = { - .init = alsa_mixer_init, - .finish = alsa_mixer_finish, - .open = alsa_mixer_open, - .close = alsa_mixer_close, - .get_volume = alsa_mixer_get_volume, - .set_volume = alsa_mixer_set_volume, - .global = true, + alsa_mixer_init, + alsa_mixer_finish, + alsa_mixer_open, + alsa_mixer_close, + alsa_mixer_get_volume, + alsa_mixer_set_volume, + true, }; diff --git a/src/mixer/oss_mixer_plugin.c b/src/mixer/OssMixerPlugin.cxx index 608f1f9b8..490a65414 100644 --- a/src/mixer/oss_mixer_plugin.c +++ b/src/mixer/OssMixerPlugin.cxx @@ -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 @@ -206,11 +206,11 @@ oss_mixer_set_volume(struct mixer *mixer, unsigned volume, GError **error_r) } const struct mixer_plugin oss_mixer_plugin = { - .init = oss_mixer_init, - .finish = oss_mixer_finish, - .open = oss_mixer_open, - .close = oss_mixer_close, - .get_volume = oss_mixer_get_volume, - .set_volume = oss_mixer_set_volume, - .global = true, + oss_mixer_init, + oss_mixer_finish, + oss_mixer_open, + oss_mixer_close, + oss_mixer_get_volume, + oss_mixer_set_volume, + true, }; diff --git a/src/mixer/pulse_mixer_plugin.c b/src/mixer/PulseMixerPlugin.cxx index a82c032b3..65dbc01fe 100644 --- a/src/mixer/pulse_mixer_plugin.c +++ b/src/mixer/PulseMixerPlugin.cxx @@ -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 @@ -18,11 +18,11 @@ */ #include "config.h" -#include "pulse_mixer_plugin.h" +#include "PulseMixerPlugin.h" #include "mixer_api.h" #include "output/pulse_output_plugin.h" #include "conf.h" -#include "event_pipe.h" +#include "GlobalEvents.hxx" #include <glib.h> @@ -66,7 +66,7 @@ pulse_mixer_offline(struct pulse_mixer *pm) pm->online = false; - event_pipe_emit(PIPE_EVENT_MIXER); + GlobalEvents::Emit(GlobalEvents::MIXER); } /** @@ -77,7 +77,7 @@ static void pulse_mixer_volume_cb(G_GNUC_UNUSED pa_context *context, const pa_sink_input_info *i, int eol, void *userdata) { - struct pulse_mixer *pm = userdata; + struct pulse_mixer *pm = (struct pulse_mixer *)userdata; if (eol) return; @@ -90,7 +90,7 @@ pulse_mixer_volume_cb(G_GNUC_UNUSED pa_context *context, const pa_sink_input_inf pm->online = true; pm->volume = i->volume; - event_pipe_emit(PIPE_EVENT_MIXER); + GlobalEvents::Emit(GlobalEvents::MIXER); } static void @@ -153,16 +153,15 @@ static struct mixer * pulse_mixer_init(void *ao, G_GNUC_UNUSED const struct config_param *param, GError **error_r) { - struct pulse_mixer *pm; - struct pulse_output *po = ao; + struct pulse_output *po = (struct pulse_output *)ao; if (ao == NULL) { g_set_error(error_r, pulse_mixer_quark(), 0, "The pulse mixer cannot work without the audio output"); - return false; + return nullptr; } - pm = g_new(struct pulse_mixer,1); + struct pulse_mixer *pm = g_new(struct pulse_mixer,1); mixer_init(&pm->base, &pulse_mixer_plugin); pm->online = false; @@ -229,8 +228,11 @@ pulse_mixer_set_volume(struct mixer *mixer, unsigned volume, GError **error_r) } const struct mixer_plugin pulse_mixer_plugin = { - .init = pulse_mixer_init, - .finish = pulse_mixer_finish, - .get_volume = pulse_mixer_get_volume, - .set_volume = pulse_mixer_set_volume, + pulse_mixer_init, + pulse_mixer_finish, + nullptr, + nullptr, + pulse_mixer_get_volume, + pulse_mixer_set_volume, + false, }; diff --git a/src/mixer/pulse_mixer_plugin.h b/src/mixer/PulseMixerPlugin.h index 461633d37..f432c44a0 100644 --- a/src/mixer/pulse_mixer_plugin.h +++ b/src/mixer/PulseMixerPlugin.h @@ -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 @@ -26,6 +26,10 @@ struct pulse_mixer; struct pa_context; struct pa_stream; +#ifdef __cplusplus +extern "C" { +#endif + void pulse_mixer_on_connect(struct pulse_mixer *pm, struct pa_context *context); @@ -36,4 +40,8 @@ void pulse_mixer_on_change(struct pulse_mixer *pm, struct pa_context *context, struct pa_stream *stream); +#ifdef __cplusplus +} +#endif + #endif 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/mixer/software_mixer_plugin.c b/src/mixer/SoftwareMixerPlugin.cxx index 0206c3b99..16463938f 100644 --- a/src/mixer/software_mixer_plugin.c +++ b/src/mixer/SoftwareMixerPlugin.cxx @@ -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 @@ -18,12 +18,12 @@ */ #include "config.h" -#include "software_mixer_plugin.h" +#include "SoftwareMixerPlugin.hxx" #include "mixer_api.h" -#include "filter_plugin.h" -#include "filter_registry.h" -#include "filter/volume_filter_plugin.h" -#include "pcm_volume.h" +#include "FilterPlugin.hxx" +#include "FilterRegistry.hxx" +#include "filter/VolumeFilterPlugin.hxx" +#include "PcmVolume.hxx" #include <assert.h> #include <math.h> @@ -32,7 +32,7 @@ struct software_mixer { /** the base mixer class */ struct mixer base; - struct filter *filter; + Filter *filter; unsigned volume; }; @@ -91,14 +91,16 @@ software_mixer_set_volume(struct mixer *mixer, unsigned volume, } const struct mixer_plugin software_mixer_plugin = { - .init = software_mixer_init, - .finish = software_mixer_finish, - .get_volume = software_mixer_get_volume, - .set_volume = software_mixer_set_volume, - .global = true, + software_mixer_init, + software_mixer_finish, + nullptr, + nullptr, + software_mixer_get_volume, + software_mixer_set_volume, + true, }; -struct filter * +Filter * software_mixer_get_filter(struct mixer *mixer) { struct software_mixer *sm = (struct software_mixer *)mixer; diff --git a/src/mixer/software_mixer_plugin.h b/src/mixer/SoftwareMixerPlugin.hxx index ee2b2023c..33e9e6c6f 100644 --- a/src/mixer/software_mixer_plugin.h +++ b/src/mixer/SoftwareMixerPlugin.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 @@ -17,17 +17,17 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ -#ifndef SOFTWARE_MIXER_PLUGIN_H -#define SOFTWARE_MIXER_PLUGIN_H +#ifndef MPD_SOFTWARE_MIXER_PLUGIN_HXX +#define MPD_SOFTWARE_MIXER_PLUGIN_HXX struct mixer; -struct filter; +class Filter; /** * Returns the (volume) filter associated with this mixer. All users * of this mixer plugin should install this filter. */ -struct filter * +Filter * software_mixer_get_filter(struct mixer *mixer); #endif diff --git a/src/mixer/winmm_mixer_plugin.c b/src/mixer/winmm_mixer_plugin.c index ceddf6afd..99da60cce 100644 --- a/src/mixer/winmm_mixer_plugin.c +++ b/src/mixer/winmm_mixer_plugin.c @@ -22,6 +22,8 @@ #include "output_api.h" #include "output/winmm_output_plugin.h" +#include <mmsystem.h> + #include <assert.h> #include <math.h> #include <windows.h> |