Commit cb8449a6 authored by Max Kellermann's avatar Max Kellermann

MixerInternal: convert to class

parent 62146771
...@@ -795,7 +795,7 @@ MIXER_API_SRC = \ ...@@ -795,7 +795,7 @@ MIXER_API_SRC = \
src/MixerControl.cxx src/MixerControl.hxx \ src/MixerControl.cxx src/MixerControl.hxx \
src/MixerType.cxx src/MixerType.hxx \ src/MixerType.cxx src/MixerType.hxx \
src/MixerAll.cxx src/MixerAll.hxx \ src/MixerAll.cxx src/MixerAll.hxx \
src/MixerInternal.cxx src/MixerInternal.hxx src/MixerInternal.hxx
libmixer_plugins_a_SOURCES = \ libmixer_plugins_a_SOURCES = \
src/mixer/SoftwareMixerPlugin.cxx \ src/mixer/SoftwareMixerPlugin.cxx \
...@@ -1325,7 +1325,6 @@ test_run_output_SOURCES = test/run_output.cxx \ ...@@ -1325,7 +1325,6 @@ test_run_output_SOURCES = test/run_output.cxx \
src/resolver.c \ src/resolver.c \
src/OutputInit.cxx src/OutputFinish.cxx src/OutputList.cxx \ src/OutputInit.cxx src/OutputFinish.cxx src/OutputList.cxx \
src/OutputPlugin.cxx \ src/OutputPlugin.cxx \
src/MixerInternal.cxx \
src/MixerControl.cxx \ src/MixerControl.cxx \
src/MixerType.cxx \ src/MixerType.cxx \
src/FilterPlugin.cxx \ src/FilterPlugin.cxx \
...@@ -1345,7 +1344,6 @@ test_read_mixer_LDADD = \ ...@@ -1345,7 +1344,6 @@ test_read_mixer_LDADD = \
$(GLIB_LIBS) $(GLIB_LIBS)
test_read_mixer_SOURCES = test/read_mixer.cxx \ test_read_mixer_SOURCES = test/read_mixer.cxx \
src/MixerControl.cxx \ src/MixerControl.cxx \
src/MixerInternal.cxx \
src/FilterPlugin.cxx \ src/FilterPlugin.cxx \
src/filter/VolumeFilterPlugin.cxx \ src/filter/VolumeFilterPlugin.cxx \
src/fd_util.c src/fd_util.c
......
...@@ -40,7 +40,6 @@ static int ...@@ -40,7 +40,6 @@ static int
output_mixer_get_volume(unsigned i) output_mixer_get_volume(unsigned i)
{ {
struct audio_output *output; struct audio_output *output;
struct mixer *mixer;
int volume; int volume;
GError *error = NULL; GError *error = NULL;
...@@ -50,7 +49,7 @@ output_mixer_get_volume(unsigned i) ...@@ -50,7 +49,7 @@ output_mixer_get_volume(unsigned i)
if (!output->enabled) if (!output->enabled)
return -1; return -1;
mixer = output->mixer; Mixer *mixer = output->mixer;
if (mixer == NULL) if (mixer == NULL)
return -1; return -1;
...@@ -88,7 +87,6 @@ static bool ...@@ -88,7 +87,6 @@ static bool
output_mixer_set_volume(unsigned i, unsigned volume) output_mixer_set_volume(unsigned i, unsigned volume)
{ {
struct audio_output *output; struct audio_output *output;
struct mixer *mixer;
bool success; bool success;
GError *error = NULL; GError *error = NULL;
...@@ -99,7 +97,7 @@ output_mixer_set_volume(unsigned i, unsigned volume) ...@@ -99,7 +97,7 @@ output_mixer_set_volume(unsigned i, unsigned volume)
if (!output->enabled) if (!output->enabled)
return false; return false;
mixer = output->mixer; Mixer *mixer = output->mixer;
if (mixer == NULL) if (mixer == NULL)
return false; return false;
...@@ -132,7 +130,6 @@ static int ...@@ -132,7 +130,6 @@ static int
output_mixer_get_software_volume(unsigned i) output_mixer_get_software_volume(unsigned i)
{ {
struct audio_output *output; struct audio_output *output;
struct mixer *mixer;
assert(i < audio_output_count()); assert(i < audio_output_count());
...@@ -140,8 +137,8 @@ output_mixer_get_software_volume(unsigned i) ...@@ -140,8 +137,8 @@ output_mixer_get_software_volume(unsigned i)
if (!output->enabled) if (!output->enabled)
return -1; return -1;
mixer = output->mixer; Mixer *mixer = output->mixer;
if (mixer == NULL || mixer->plugin != &software_mixer_plugin) if (mixer == NULL || !mixer->IsPlugin(software_mixer_plugin))
return -1; return -1;
return mixer_get_volume(mixer, NULL); return mixer_get_volume(mixer, NULL);
......
...@@ -27,24 +27,24 @@ ...@@ -27,24 +27,24 @@
#undef G_LOG_DOMAIN #undef G_LOG_DOMAIN
#define G_LOG_DOMAIN "mixer" #define G_LOG_DOMAIN "mixer"
struct mixer * Mixer *
mixer_new(const struct mixer_plugin *plugin, void *ao, mixer_new(const struct mixer_plugin *plugin, void *ao,
const struct config_param *param, const struct config_param *param,
GError **error_r) GError **error_r)
{ {
struct mixer *mixer; Mixer *mixer;
assert(plugin != NULL); assert(plugin != NULL);
mixer = plugin->init(ao, param, error_r); mixer = plugin->init(ao, param, error_r);
assert(mixer == NULL || mixer->plugin == plugin); assert(mixer == NULL || mixer->IsPlugin(*plugin));
return mixer; return mixer;
} }
void void
mixer_free(struct mixer *mixer) mixer_free(Mixer *mixer)
{ {
assert(mixer != NULL); assert(mixer != NULL);
assert(mixer->plugin != NULL); assert(mixer->plugin != NULL);
...@@ -60,7 +60,7 @@ mixer_free(struct mixer *mixer) ...@@ -60,7 +60,7 @@ mixer_free(struct mixer *mixer)
} }
bool bool
mixer_open(struct mixer *mixer, GError **error_r) mixer_open(Mixer *mixer, GError **error_r)
{ {
bool success; bool success;
...@@ -84,7 +84,7 @@ mixer_open(struct mixer *mixer, GError **error_r) ...@@ -84,7 +84,7 @@ mixer_open(struct mixer *mixer, GError **error_r)
} }
static void static void
mixer_close_internal(struct mixer *mixer) mixer_close_internal(Mixer *mixer)
{ {
assert(mixer != NULL); assert(mixer != NULL);
assert(mixer->plugin != NULL); assert(mixer->plugin != NULL);
...@@ -97,7 +97,7 @@ mixer_close_internal(struct mixer *mixer) ...@@ -97,7 +97,7 @@ mixer_close_internal(struct mixer *mixer)
} }
void void
mixer_close(struct mixer *mixer) mixer_close(Mixer *mixer)
{ {
assert(mixer != NULL); assert(mixer != NULL);
assert(mixer->plugin != NULL); assert(mixer->plugin != NULL);
...@@ -111,7 +111,7 @@ mixer_close(struct mixer *mixer) ...@@ -111,7 +111,7 @@ mixer_close(struct mixer *mixer)
} }
void void
mixer_auto_close(struct mixer *mixer) mixer_auto_close(Mixer *mixer)
{ {
if (!mixer->plugin->global) if (!mixer->plugin->global)
mixer_close(mixer); mixer_close(mixer);
...@@ -122,7 +122,7 @@ mixer_auto_close(struct mixer *mixer) ...@@ -122,7 +122,7 @@ mixer_auto_close(struct mixer *mixer)
* calling this function. * calling this function.
*/ */
static void static void
mixer_failed(struct mixer *mixer) mixer_failed(Mixer *mixer)
{ {
assert(mixer->open); assert(mixer->open);
...@@ -132,7 +132,7 @@ mixer_failed(struct mixer *mixer) ...@@ -132,7 +132,7 @@ mixer_failed(struct mixer *mixer)
} }
int int
mixer_get_volume(struct mixer *mixer, GError **error_r) mixer_get_volume(Mixer *mixer, GError **error_r)
{ {
int volume; int volume;
...@@ -161,7 +161,7 @@ mixer_get_volume(struct mixer *mixer, GError **error_r) ...@@ -161,7 +161,7 @@ mixer_get_volume(struct mixer *mixer, GError **error_r)
} }
bool bool
mixer_set_volume(struct mixer *mixer, unsigned volume, GError **error_r) mixer_set_volume(Mixer *mixer, unsigned volume, GError **error_r)
{ {
bool success; bool success;
......
...@@ -27,7 +27,7 @@ ...@@ -27,7 +27,7 @@
#include "gerror.h" #include "gerror.h"
struct mixer; class Mixer;
struct mixer_plugin; struct mixer_plugin;
struct config_param; struct config_param;
...@@ -35,32 +35,32 @@ struct config_param; ...@@ -35,32 +35,32 @@ struct config_param;
extern "C" { extern "C" {
#endif #endif
struct mixer * Mixer *
mixer_new(const struct mixer_plugin *plugin, void *ao, mixer_new(const struct mixer_plugin *plugin, void *ao,
const struct config_param *param, const struct config_param *param,
GError **error_r); GError **error_r);
void void
mixer_free(struct mixer *mixer); mixer_free(Mixer *mixer);
bool bool
mixer_open(struct mixer *mixer, GError **error_r); mixer_open(Mixer *mixer, GError **error_r);
void void
mixer_close(struct mixer *mixer); mixer_close(Mixer *mixer);
/** /**
* Close the mixer unless the plugin's "global" flag is set. This is * Close the mixer unless the plugin's "global" flag is set. This is
* called when the #audio_output is closed. * called when the #audio_output is closed.
*/ */
void void
mixer_auto_close(struct mixer *mixer); mixer_auto_close(Mixer *mixer);
int int
mixer_get_volume(struct mixer *mixer, GError **error_r); mixer_get_volume(Mixer *mixer, GError **error_r);
bool bool
mixer_set_volume(struct mixer *mixer, unsigned volume, GError **error_r); mixer_set_volume(Mixer *mixer, unsigned volume, GError **error_r);
#ifdef __cplusplus #ifdef __cplusplus
} }
......
/*
* 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
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#include "config.h"
#include "MixerInternal.hxx"
#undef G_LOG_DOMAIN
#define G_LOG_DOMAIN "mixer"
void
mixer_init(struct mixer *mixer, const struct mixer_plugin *plugin)
{
mixer->plugin = plugin;
mixer->mutex = g_mutex_new();
mixer->open = false;
mixer->failed = false;
}
...@@ -25,7 +25,8 @@ ...@@ -25,7 +25,8 @@
#include <glib.h> #include <glib.h>
struct mixer { class Mixer {
public:
const struct mixer_plugin *plugin; const struct mixer_plugin *plugin;
/** /**
...@@ -44,9 +45,17 @@ struct mixer { ...@@ -44,9 +45,17 @@ struct mixer {
* automatically? * automatically?
*/ */
bool failed; bool failed;
};
void public:
mixer_init(struct mixer *mixer, const struct mixer_plugin *plugin); Mixer(const mixer_plugin &_plugin)
:plugin(&_plugin),
mutex(g_mutex_new()),
open(false),
failed(false) {}
bool IsPlugin(const mixer_plugin &other) const {
return plugin == &other;
}
};
#endif #endif
...@@ -32,7 +32,7 @@ ...@@ -32,7 +32,7 @@
#include <stdbool.h> #include <stdbool.h>
struct config_param; struct config_param;
struct mixer; class Mixer;
struct mixer_plugin { struct mixer_plugin {
/** /**
...@@ -45,13 +45,13 @@ struct mixer_plugin { ...@@ -45,13 +45,13 @@ struct mixer_plugin {
* NULL to ignore errors * NULL to ignore errors
* @return a mixer object, or NULL on error * @return a mixer object, or NULL on error
*/ */
struct mixer *(*init)(void *ao, const struct config_param *param, Mixer *(*init)(void *ao, const struct config_param *param,
GError **error_r); GError **error_r);
/** /**
* Finish and free mixer data * Finish and free mixer data
*/ */
void (*finish)(struct mixer *data); void (*finish)(Mixer *data);
/** /**
* Open mixer device * Open mixer device
...@@ -60,12 +60,12 @@ struct mixer_plugin { ...@@ -60,12 +60,12 @@ struct mixer_plugin {
* NULL to ignore errors * NULL to ignore errors
* @return true on success, false on error * @return true on success, false on error
*/ */
bool (*open)(struct mixer *data, GError **error_r); bool (*open)(Mixer *data, GError **error_r);
/** /**
* Close mixer device * Close mixer device
*/ */
void (*close)(struct mixer *data); void (*close)(Mixer *data);
/** /**
* Reads the current volume. * Reads the current volume.
...@@ -75,7 +75,7 @@ struct mixer_plugin { ...@@ -75,7 +75,7 @@ struct mixer_plugin {
* @return the current volume (0..100 including) or -1 if * @return the current volume (0..100 including) or -1 if
* unavailable or on error (error_r set, mixer will be closed) * unavailable or on error (error_r set, mixer will be closed)
*/ */
int (*get_volume)(struct mixer *mixer, GError **error_r); int (*get_volume)(Mixer *mixer, GError **error_r);
/** /**
* Sets the volume. * Sets the volume.
...@@ -85,7 +85,7 @@ struct mixer_plugin { ...@@ -85,7 +85,7 @@ struct mixer_plugin {
* @param volume the new volume (0..100 including) * @param volume the new volume (0..100 including)
* @return true on success, false on error * @return true on success, false on error
*/ */
bool (*set_volume)(struct mixer *mixer, unsigned volume, bool (*set_volume)(Mixer *mixer, unsigned volume,
GError **error_r); GError **error_r);
/** /**
......
...@@ -64,7 +64,6 @@ bool ...@@ -64,7 +64,6 @@ bool
audio_output_disable_index(unsigned idx) audio_output_disable_index(unsigned idx)
{ {
struct audio_output *ao; struct audio_output *ao;
struct mixer *mixer;
if (idx >= audio_output_count()) if (idx >= audio_output_count())
return false; return false;
...@@ -76,7 +75,7 @@ audio_output_disable_index(unsigned idx) ...@@ -76,7 +75,7 @@ audio_output_disable_index(unsigned idx)
ao->enabled = false; ao->enabled = false;
idle_add(IDLE_OUTPUT); idle_add(IDLE_OUTPUT);
mixer = ao->mixer; Mixer *mixer = ao->mixer;
if (mixer != NULL) { if (mixer != NULL) {
mixer_close(mixer); mixer_close(mixer);
idle_add(IDLE_MIXER); idle_add(IDLE_MIXER);
......
...@@ -96,14 +96,14 @@ audio_output_mixer_type(const struct config_param *param) ...@@ -96,14 +96,14 @@ audio_output_mixer_type(const struct config_param *param)
"hardware")); "hardware"));
} }
static struct mixer * static Mixer *
audio_output_load_mixer(struct audio_output *ao, audio_output_load_mixer(struct audio_output *ao,
const struct config_param *param, const struct config_param *param,
const struct mixer_plugin *plugin, const struct mixer_plugin *plugin,
Filter &filter_chain, Filter &filter_chain,
GError **error_r) GError **error_r)
{ {
struct mixer *mixer; Mixer *mixer;
switch (audio_output_mixer_type(param)) { switch (audio_output_mixer_type(param)) {
case MIXER_TYPE_NONE: case MIXER_TYPE_NONE:
......
...@@ -43,7 +43,7 @@ class ReplayGainFilter final : public Filter { ...@@ -43,7 +43,7 @@ class ReplayGainFilter final : public Filter {
* If set, then this hardware mixer is used for applying * If set, then this hardware mixer is used for applying
* replay gain, instead of the software volume library. * replay gain, instead of the software volume library.
*/ */
struct mixer *mixer; Mixer *mixer;
/** /**
* The base volume level for scale=1.0, between 1 and 100 * The base volume level for scale=1.0, between 1 and 100
...@@ -80,7 +80,7 @@ public: ...@@ -80,7 +80,7 @@ public:
replay_gain_info_init(&info); replay_gain_info_init(&info);
} }
void SetMixer(struct mixer *_mixer, unsigned _base) { void SetMixer(Mixer *_mixer, unsigned _base) {
assert(_mixer == NULL || (_base > 0 && _base <= 100)); assert(_mixer == NULL || (_base > 0 && _base <= 100));
mixer = _mixer; mixer = _mixer;
...@@ -217,7 +217,7 @@ const struct filter_plugin replay_gain_filter_plugin = { ...@@ -217,7 +217,7 @@ const struct filter_plugin replay_gain_filter_plugin = {
}; };
void void
replay_gain_filter_set_mixer(Filter *_filter, struct mixer *mixer, replay_gain_filter_set_mixer(Filter *_filter, Mixer *mixer,
unsigned base) unsigned base)
{ {
ReplayGainFilter *filter = (ReplayGainFilter *)_filter; ReplayGainFilter *filter = (ReplayGainFilter *)_filter;
......
...@@ -23,7 +23,7 @@ ...@@ -23,7 +23,7 @@
#include "replay_gain_info.h" #include "replay_gain_info.h"
class Filter; class Filter;
struct mixer; class Mixer;
/** /**
* Enables or disables the hardware mixer for applying replay gain. * Enables or disables the hardware mixer for applying replay gain.
...@@ -34,7 +34,7 @@ struct mixer; ...@@ -34,7 +34,7 @@ struct mixer;
* (including). * (including).
*/ */
void void
replay_gain_filter_set_mixer(Filter *_filter, struct mixer *mixer, replay_gain_filter_set_mixer(Filter *_filter, Mixer *mixer,
unsigned base); unsigned base);
/** /**
......
...@@ -45,7 +45,7 @@ private: ...@@ -45,7 +45,7 @@ private:
virtual void DispatchSockets() override; virtual void DispatchSockets() override;
}; };
class AlsaMixer final : public mixer { class AlsaMixer final : public Mixer {
const char *device; const char *device;
const char *control; const char *control;
unsigned int index; unsigned int index;
...@@ -59,9 +59,7 @@ class AlsaMixer final : public mixer { ...@@ -59,9 +59,7 @@ class AlsaMixer final : public mixer {
AlsaMixerMonitor *monitor; AlsaMixerMonitor *monitor;
public: public:
AlsaMixer() { AlsaMixer():Mixer(alsa_mixer_plugin) {}
mixer_init(this, &alsa_mixer_plugin);
}
void Configure(const config_param *param); void Configure(const config_param *param);
bool Setup(GError **error_r); bool Setup(GError **error_r);
...@@ -150,7 +148,7 @@ AlsaMixer::Configure(const config_param *param) ...@@ -150,7 +148,7 @@ AlsaMixer::Configure(const config_param *param)
VOLUME_MIXER_ALSA_INDEX_DEFAULT); VOLUME_MIXER_ALSA_INDEX_DEFAULT);
} }
static struct mixer * static Mixer *
alsa_mixer_init(G_GNUC_UNUSED void *ao, const struct config_param *param, alsa_mixer_init(G_GNUC_UNUSED void *ao, const struct config_param *param,
G_GNUC_UNUSED GError **error_r) G_GNUC_UNUSED GError **error_r)
{ {
...@@ -161,7 +159,7 @@ alsa_mixer_init(G_GNUC_UNUSED void *ao, const struct config_param *param, ...@@ -161,7 +159,7 @@ alsa_mixer_init(G_GNUC_UNUSED void *ao, const struct config_param *param,
} }
static void static void
alsa_mixer_finish(struct mixer *data) alsa_mixer_finish(Mixer *data)
{ {
AlsaMixer *am = (AlsaMixer *)data; AlsaMixer *am = (AlsaMixer *)data;
...@@ -254,7 +252,7 @@ AlsaMixer::Open(GError **error_r) ...@@ -254,7 +252,7 @@ AlsaMixer::Open(GError **error_r)
} }
static bool static bool
alsa_mixer_open(struct mixer *data, GError **error_r) alsa_mixer_open(Mixer *data, GError **error_r)
{ {
AlsaMixer *am = (AlsaMixer *)data; AlsaMixer *am = (AlsaMixer *)data;
...@@ -273,7 +271,7 @@ AlsaMixer::Close() ...@@ -273,7 +271,7 @@ AlsaMixer::Close()
} }
static void static void
alsa_mixer_close(struct mixer *data) alsa_mixer_close(Mixer *data)
{ {
AlsaMixer *am = (AlsaMixer *)data; AlsaMixer *am = (AlsaMixer *)data;
am->Close(); am->Close();
...@@ -319,7 +317,7 @@ AlsaMixer::GetVolume(GError **error_r) ...@@ -319,7 +317,7 @@ AlsaMixer::GetVolume(GError **error_r)
} }
static int static int
alsa_mixer_get_volume(struct mixer *mixer, GError **error_r) alsa_mixer_get_volume(Mixer *mixer, GError **error_r)
{ {
AlsaMixer *am = (AlsaMixer *)mixer; AlsaMixer *am = (AlsaMixer *)mixer;
return am->GetVolume(error_r); return am->GetVolume(error_r);
...@@ -355,7 +353,7 @@ AlsaMixer::SetVolume(unsigned volume, GError **error_r) ...@@ -355,7 +353,7 @@ AlsaMixer::SetVolume(unsigned volume, GError **error_r)
} }
static bool static bool
alsa_mixer_set_volume(struct mixer *mixer, unsigned volume, GError **error_r) alsa_mixer_set_volume(Mixer *mixer, unsigned volume, GError **error_r)
{ {
AlsaMixer *am = (AlsaMixer *)mixer; AlsaMixer *am = (AlsaMixer *)mixer;
return am->SetVolume(volume, error_r); return am->SetVolume(volume, error_r);
......
...@@ -40,7 +40,7 @@ ...@@ -40,7 +40,7 @@
#define VOLUME_MIXER_OSS_DEFAULT "/dev/mixer" #define VOLUME_MIXER_OSS_DEFAULT "/dev/mixer"
class OssMixer : public mixer { class OssMixer : public Mixer {
const char *device; const char *device;
const char *control; const char *control;
...@@ -48,9 +48,7 @@ class OssMixer : public mixer { ...@@ -48,9 +48,7 @@ class OssMixer : public mixer {
int volume_control; int volume_control;
public: public:
OssMixer() { OssMixer():Mixer(oss_mixer_plugin) {}
mixer_init(this, &oss_mixer_plugin);
}
bool Configure(const config_param *param, GError **error_r); bool Configure(const config_param *param, GError **error_r);
bool Open(GError **error_r); bool Open(GError **error_r);
...@@ -104,7 +102,7 @@ OssMixer::Configure(const config_param *param, GError **error_r) ...@@ -104,7 +102,7 @@ OssMixer::Configure(const config_param *param, GError **error_r)
return true; return true;
} }
static struct mixer * static Mixer *
oss_mixer_init(G_GNUC_UNUSED void *ao, const struct config_param *param, oss_mixer_init(G_GNUC_UNUSED void *ao, const struct config_param *param,
GError **error_r) GError **error_r)
{ {
...@@ -119,7 +117,7 @@ oss_mixer_init(G_GNUC_UNUSED void *ao, const struct config_param *param, ...@@ -119,7 +117,7 @@ oss_mixer_init(G_GNUC_UNUSED void *ao, const struct config_param *param,
} }
static void static void
oss_mixer_finish(struct mixer *data) oss_mixer_finish(Mixer *data)
{ {
OssMixer *om = (OssMixer *) data; OssMixer *om = (OssMixer *) data;
...@@ -135,7 +133,7 @@ OssMixer::Close() ...@@ -135,7 +133,7 @@ OssMixer::Close()
} }
static void static void
oss_mixer_close(struct mixer *data) oss_mixer_close(Mixer *data)
{ {
OssMixer *om = (OssMixer *) data; OssMixer *om = (OssMixer *) data;
om->Close(); om->Close();
...@@ -176,7 +174,7 @@ OssMixer::Open(GError **error_r) ...@@ -176,7 +174,7 @@ OssMixer::Open(GError **error_r)
} }
static bool static bool
oss_mixer_open(struct mixer *data, GError **error_r) oss_mixer_open(Mixer *data, GError **error_r)
{ {
OssMixer *om = (OssMixer *) data; OssMixer *om = (OssMixer *) data;
...@@ -211,7 +209,7 @@ OssMixer::GetVolume(GError **error_r) ...@@ -211,7 +209,7 @@ OssMixer::GetVolume(GError **error_r)
} }
static int static int
oss_mixer_get_volume(struct mixer *mixer, GError **error_r) oss_mixer_get_volume(Mixer *mixer, GError **error_r)
{ {
OssMixer *om = (OssMixer *)mixer; OssMixer *om = (OssMixer *)mixer;
return om->GetVolume(error_r); return om->GetVolume(error_r);
...@@ -240,7 +238,7 @@ OssMixer::SetVolume(unsigned volume, GError **error_r) ...@@ -240,7 +238,7 @@ OssMixer::SetVolume(unsigned volume, GError **error_r)
} }
static bool static bool
oss_mixer_set_volume(struct mixer *mixer, unsigned volume, GError **error_r) oss_mixer_set_volume(Mixer *mixer, unsigned volume, GError **error_r)
{ {
OssMixer *om = (OssMixer *)mixer; OssMixer *om = (OssMixer *)mixer;
return om->SetVolume(volume, error_r); return om->SetVolume(volume, error_r);
......
...@@ -39,16 +39,16 @@ ...@@ -39,16 +39,16 @@
#undef G_LOG_DOMAIN #undef G_LOG_DOMAIN
#define G_LOG_DOMAIN "pulse_mixer" #define G_LOG_DOMAIN "pulse_mixer"
struct PulseMixer : mixer { struct PulseMixer final : public Mixer {
PulseOutput *output; PulseOutput *output;
bool online; bool online;
struct pa_cvolume volume; struct pa_cvolume volume;
PulseMixer(PulseOutput *_output) PulseMixer(PulseOutput *_output)
:output(_output), online(false) :Mixer(pulse_mixer_plugin),
output(_output), online(false)
{ {
mixer_init(this, &pulse_mixer_plugin);
} }
}; };
...@@ -152,7 +152,7 @@ pulse_mixer_on_change(PulseMixer *pm, ...@@ -152,7 +152,7 @@ pulse_mixer_on_change(PulseMixer *pm,
pulse_mixer_update(pm, context, stream); pulse_mixer_update(pm, context, stream);
} }
static struct mixer * static Mixer *
pulse_mixer_init(void *ao, G_GNUC_UNUSED const struct config_param *param, pulse_mixer_init(void *ao, G_GNUC_UNUSED const struct config_param *param,
GError **error_r) GError **error_r)
{ {
...@@ -172,7 +172,7 @@ pulse_mixer_init(void *ao, G_GNUC_UNUSED const struct config_param *param, ...@@ -172,7 +172,7 @@ pulse_mixer_init(void *ao, G_GNUC_UNUSED const struct config_param *param,
} }
static void static void
pulse_mixer_finish(struct mixer *data) pulse_mixer_finish(Mixer *data)
{ {
PulseMixer *pm = (PulseMixer *) data; PulseMixer *pm = (PulseMixer *) data;
...@@ -182,7 +182,7 @@ pulse_mixer_finish(struct mixer *data) ...@@ -182,7 +182,7 @@ pulse_mixer_finish(struct mixer *data)
} }
static int static int
pulse_mixer_get_volume(struct mixer *mixer, G_GNUC_UNUSED GError **error_r) pulse_mixer_get_volume(Mixer *mixer, G_GNUC_UNUSED GError **error_r)
{ {
PulseMixer *pm = (PulseMixer *) mixer; PulseMixer *pm = (PulseMixer *) mixer;
int ret; int ret;
...@@ -199,7 +199,7 @@ pulse_mixer_get_volume(struct mixer *mixer, G_GNUC_UNUSED GError **error_r) ...@@ -199,7 +199,7 @@ pulse_mixer_get_volume(struct mixer *mixer, G_GNUC_UNUSED GError **error_r)
} }
static bool static bool
pulse_mixer_set_volume(struct mixer *mixer, unsigned volume, GError **error_r) pulse_mixer_set_volume(Mixer *mixer, unsigned volume, GError **error_r)
{ {
PulseMixer *pm = (PulseMixer *) mixer; PulseMixer *pm = (PulseMixer *) mixer;
struct pa_cvolume cvolume; struct pa_cvolume cvolume;
......
...@@ -24,26 +24,24 @@ ...@@ -24,26 +24,24 @@
#include "output_api.h" #include "output_api.h"
#include "output/RoarOutputPlugin.hxx" #include "output/RoarOutputPlugin.hxx"
struct RoarMixer { struct RoarMixer final : public Mixer {
/** the base mixer class */ /** the base mixer class */
struct mixer base;
RoarOutput *self; RoarOutput *self;
RoarMixer(RoarOutput *_output):self(_output) { RoarMixer(RoarOutput *_output)
mixer_init(&base, &roar_mixer_plugin); :Mixer(roar_mixer_plugin),
} self(_output) {}
}; };
static struct mixer * static Mixer *
roar_mixer_init(void *ao, gcc_unused const struct config_param *param, roar_mixer_init(void *ao, gcc_unused const struct config_param *param,
gcc_unused GError **error_r) gcc_unused GError **error_r)
{ {
RoarMixer *self = new RoarMixer((RoarOutput *)ao); return new RoarMixer((RoarOutput *)ao);
return &self->base;
} }
static void static void
roar_mixer_finish(struct mixer *data) roar_mixer_finish(Mixer *data)
{ {
RoarMixer *self = (RoarMixer *) data; RoarMixer *self = (RoarMixer *) data;
...@@ -51,14 +49,14 @@ roar_mixer_finish(struct mixer *data) ...@@ -51,14 +49,14 @@ roar_mixer_finish(struct mixer *data)
} }
static int static int
roar_mixer_get_volume(struct mixer *mixer, gcc_unused GError **error_r) roar_mixer_get_volume(Mixer *mixer, gcc_unused GError **error_r)
{ {
RoarMixer *self = (RoarMixer *)mixer; RoarMixer *self = (RoarMixer *)mixer;
return roar_output_get_volume(self->self); return roar_output_get_volume(self->self);
} }
static bool static bool
roar_mixer_set_volume(struct mixer *mixer, unsigned volume, roar_mixer_set_volume(Mixer *mixer, unsigned volume,
gcc_unused GError **error_r) gcc_unused GError **error_r)
{ {
RoarMixer *self = (RoarMixer *)mixer; RoarMixer *self = (RoarMixer *)mixer;
......
...@@ -29,18 +29,17 @@ ...@@ -29,18 +29,17 @@
#include <assert.h> #include <assert.h>
#include <math.h> #include <math.h>
struct SoftwareMixer final : public mixer { struct SoftwareMixer final : public Mixer {
Filter *filter; Filter *filter;
unsigned volume; unsigned volume;
SoftwareMixer() SoftwareMixer()
:filter(filter_new(&volume_filter_plugin, nullptr, nullptr)), :Mixer(software_mixer_plugin),
volume(100) filter(filter_new(&volume_filter_plugin, nullptr, nullptr)),
volume(100)
{ {
assert(filter != nullptr); assert(filter != nullptr);
mixer_init(this, &software_mixer_plugin);
} }
~SoftwareMixer() { ~SoftwareMixer() {
...@@ -48,7 +47,7 @@ struct SoftwareMixer final : public mixer { ...@@ -48,7 +47,7 @@ struct SoftwareMixer final : public mixer {
} }
}; };
static struct mixer * static Mixer *
software_mixer_init(G_GNUC_UNUSED void *ao, software_mixer_init(G_GNUC_UNUSED void *ao,
G_GNUC_UNUSED const struct config_param *param, G_GNUC_UNUSED const struct config_param *param,
G_GNUC_UNUSED GError **error_r) G_GNUC_UNUSED GError **error_r)
...@@ -57,7 +56,7 @@ software_mixer_init(G_GNUC_UNUSED void *ao, ...@@ -57,7 +56,7 @@ software_mixer_init(G_GNUC_UNUSED void *ao,
} }
static void static void
software_mixer_finish(struct mixer *data) software_mixer_finish(Mixer *data)
{ {
SoftwareMixer *sm = (SoftwareMixer *)data; SoftwareMixer *sm = (SoftwareMixer *)data;
...@@ -65,7 +64,7 @@ software_mixer_finish(struct mixer *data) ...@@ -65,7 +64,7 @@ software_mixer_finish(struct mixer *data)
} }
static int static int
software_mixer_get_volume(struct mixer *mixer, G_GNUC_UNUSED GError **error_r) software_mixer_get_volume(Mixer *mixer, G_GNUC_UNUSED GError **error_r)
{ {
SoftwareMixer *sm = (SoftwareMixer *)mixer; SoftwareMixer *sm = (SoftwareMixer *)mixer;
...@@ -73,7 +72,7 @@ software_mixer_get_volume(struct mixer *mixer, G_GNUC_UNUSED GError **error_r) ...@@ -73,7 +72,7 @@ software_mixer_get_volume(struct mixer *mixer, G_GNUC_UNUSED GError **error_r)
} }
static bool static bool
software_mixer_set_volume(struct mixer *mixer, unsigned volume, software_mixer_set_volume(Mixer *mixer, unsigned volume,
G_GNUC_UNUSED GError **error_r) G_GNUC_UNUSED GError **error_r)
{ {
SoftwareMixer *sm = (SoftwareMixer *)mixer; SoftwareMixer *sm = (SoftwareMixer *)mixer;
...@@ -103,11 +102,10 @@ const struct mixer_plugin software_mixer_plugin = { ...@@ -103,11 +102,10 @@ const struct mixer_plugin software_mixer_plugin = {
}; };
Filter * Filter *
software_mixer_get_filter(struct mixer *mixer) software_mixer_get_filter(Mixer *mixer)
{ {
SoftwareMixer *sm = (SoftwareMixer *)mixer; SoftwareMixer *sm = (SoftwareMixer *)mixer;
assert(sm->IsPlugin(software_mixer_plugin));
assert(sm->plugin == &software_mixer_plugin);
return sm->filter; return sm->filter;
} }
...@@ -20,7 +20,7 @@ ...@@ -20,7 +20,7 @@
#ifndef MPD_SOFTWARE_MIXER_PLUGIN_HXX #ifndef MPD_SOFTWARE_MIXER_PLUGIN_HXX
#define MPD_SOFTWARE_MIXER_PLUGIN_HXX #define MPD_SOFTWARE_MIXER_PLUGIN_HXX
struct mixer; class Mixer;
class Filter; class Filter;
/** /**
...@@ -28,6 +28,6 @@ class Filter; ...@@ -28,6 +28,6 @@ class Filter;
* of this mixer plugin should install this filter. * of this mixer plugin should install this filter.
*/ */
Filter * Filter *
software_mixer_get_filter(struct mixer *mixer); software_mixer_get_filter(Mixer *mixer);
#endif #endif
...@@ -31,12 +31,12 @@ ...@@ -31,12 +31,12 @@
#undef G_LOG_DOMAIN #undef G_LOG_DOMAIN
#define G_LOG_DOMAIN "winmm_mixer" #define G_LOG_DOMAIN "winmm_mixer"
struct WinmmMixer final : public mixer { struct WinmmMixer final : public Mixer {
WinmmOutput *output; WinmmOutput *output;
WinmmMixer(WinmmOutput *_output) WinmmMixer(WinmmOutput *_output)
:output(_output) { :Mixer(winmm_mixer_plugin),
mixer_init(this, &winmm_mixer_plugin); output(_output) {
} }
}; };
...@@ -59,7 +59,7 @@ winmm_volume_encode(int volume) ...@@ -59,7 +59,7 @@ winmm_volume_encode(int volume)
return MAKELONG(value, value); return MAKELONG(value, value);
} }
static struct mixer * static Mixer *
winmm_mixer_init(void *ao, G_GNUC_UNUSED const struct config_param *param, winmm_mixer_init(void *ao, G_GNUC_UNUSED const struct config_param *param,
G_GNUC_UNUSED GError **error_r) G_GNUC_UNUSED GError **error_r)
{ {
...@@ -69,7 +69,7 @@ winmm_mixer_init(void *ao, G_GNUC_UNUSED const struct config_param *param, ...@@ -69,7 +69,7 @@ winmm_mixer_init(void *ao, G_GNUC_UNUSED const struct config_param *param,
} }
static void static void
winmm_mixer_finish(struct mixer *data) winmm_mixer_finish(Mixer *data)
{ {
WinmmMixer *wm = (WinmmMixer *)data; WinmmMixer *wm = (WinmmMixer *)data;
...@@ -77,7 +77,7 @@ winmm_mixer_finish(struct mixer *data) ...@@ -77,7 +77,7 @@ winmm_mixer_finish(struct mixer *data)
} }
static int static int
winmm_mixer_get_volume(struct mixer *mixer, GError **error_r) winmm_mixer_get_volume(Mixer *mixer, GError **error_r)
{ {
WinmmMixer *wm = (WinmmMixer *) mixer; WinmmMixer *wm = (WinmmMixer *) mixer;
DWORD volume; DWORD volume;
...@@ -94,7 +94,7 @@ winmm_mixer_get_volume(struct mixer *mixer, GError **error_r) ...@@ -94,7 +94,7 @@ winmm_mixer_get_volume(struct mixer *mixer, GError **error_r)
} }
static bool static bool
winmm_mixer_set_volume(struct mixer *mixer, unsigned volume, GError **error_r) winmm_mixer_set_volume(Mixer *mixer, unsigned volume, GError **error_r)
{ {
WinmmMixer *wm = (WinmmMixer *) mixer; WinmmMixer *wm = (WinmmMixer *) mixer;
DWORD value = winmm_volume_encode(volume); DWORD value = winmm_volume_encode(volume);
......
...@@ -76,7 +76,11 @@ struct audio_output { ...@@ -76,7 +76,11 @@ struct audio_output {
* May be NULL if none is available, or if software volume is * May be NULL if none is available, or if software volume is
* configured. * configured.
*/ */
#ifdef __cplusplus
class Mixer *mixer;
#else
struct mixer *mixer; struct mixer *mixer;
#endif
/** /**
* Will this output receive tags from the decoder? The * Will this output receive tags from the decoder? The
......
...@@ -111,7 +111,6 @@ pcm_volume(G_GNUC_UNUSED void *buffer, G_GNUC_UNUSED size_t length, ...@@ -111,7 +111,6 @@ pcm_volume(G_GNUC_UNUSED void *buffer, G_GNUC_UNUSED size_t length,
int main(int argc, G_GNUC_UNUSED char **argv) int main(int argc, G_GNUC_UNUSED char **argv)
{ {
GError *error = NULL; GError *error = NULL;
struct mixer *mixer;
bool success; bool success;
int volume; int volume;
...@@ -124,7 +123,7 @@ int main(int argc, G_GNUC_UNUSED char **argv) ...@@ -124,7 +123,7 @@ int main(int argc, G_GNUC_UNUSED char **argv)
main_loop = new EventLoop(EventLoop::Default()); main_loop = new EventLoop(EventLoop::Default());
mixer = mixer_new(&alsa_mixer_plugin, NULL, NULL, &error); Mixer *mixer = mixer_new(&alsa_mixer_plugin, NULL, NULL, &error);
if (mixer == NULL) { if (mixer == NULL) {
g_printerr("mixer_new() failed: %s\n", error->message); g_printerr("mixer_new() failed: %s\n", error->message);
g_error_free(error); g_error_free(error);
......
...@@ -36,7 +36,7 @@ ...@@ -36,7 +36,7 @@
#include <unistd.h> #include <unistd.h>
bool bool
mixer_set_volume(G_GNUC_UNUSED struct mixer *mixer, mixer_set_volume(gcc_unused Mixer *mixer,
G_GNUC_UNUSED unsigned volume, G_GNUC_UNUSED GError **error_r) G_GNUC_UNUSED unsigned volume, G_GNUC_UNUSED GError **error_r)
{ {
return true; return true;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment