From 496f70fc0d717719a6defb645918785381efa22b Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Fri, 22 Feb 2013 20:51:23 +0100 Subject: mixer_plugin: convert to C++ --- src/MixerAll.cxx | 5 +- src/MixerControl.cxx | 185 ++++++++++++++++++++++++++++++++++ src/MixerControl.hxx | 69 +++++++++++++ src/MixerInternal.cxx | 33 ++++++ src/MixerInternal.hxx | 52 ++++++++++ src/MixerList.hxx | 35 +++++++ src/MixerPlugin.hxx | 99 ++++++++++++++++++ src/MixerType.cxx | 39 +++++++ src/MixerType.hxx | 47 +++++++++ src/OutputCommand.cxx | 2 +- src/OutputControl.cxx | 4 +- src/OutputFinish.cxx | 2 +- src/OutputInit.cxx | 6 +- src/filter/ReplayGainFilterPlugin.cxx | 2 +- src/mixer/AlsaMixerPlugin.cxx | 2 +- src/mixer/OssMixerPlugin.cxx | 2 +- src/mixer/PulseMixerPlugin.cxx | 2 +- src/mixer/RoarMixerPlugin.cxx | 2 +- src/mixer/SoftwareMixerPlugin.cxx | 2 +- src/mixer/WinmmMixerPlugin.cxx | 2 +- src/mixer_api.c | 33 ------ src/mixer_api.h | 60 ----------- src/mixer_control.c | 185 ---------------------------------- src/mixer_control.h | 71 ------------- src/mixer_list.h | 35 ------- src/mixer_plugin.h | 99 ------------------ src/mixer_type.c | 39 ------- src/mixer_type.h | 47 --------- src/output/AlsaOutputPlugin.cxx | 2 +- src/output/OssOutputPlugin.cxx | 2 +- src/output/RoarOutputPlugin.cxx | 2 +- src/output/WinmmOutputPlugin.cxx | 2 +- src/output/pulse_output_plugin.c | 2 +- 33 files changed, 581 insertions(+), 590 deletions(-) create mode 100644 src/MixerControl.cxx create mode 100644 src/MixerControl.hxx create mode 100644 src/MixerInternal.cxx create mode 100644 src/MixerInternal.hxx create mode 100644 src/MixerList.hxx create mode 100644 src/MixerPlugin.hxx create mode 100644 src/MixerType.cxx create mode 100644 src/MixerType.hxx delete mode 100644 src/mixer_api.c delete mode 100644 src/mixer_api.h delete mode 100644 src/mixer_control.c delete mode 100644 src/mixer_control.h delete mode 100644 src/mixer_list.h delete mode 100644 src/mixer_plugin.h delete mode 100644 src/mixer_type.c delete mode 100644 src/mixer_type.h (limited to 'src') diff --git a/src/MixerAll.cxx b/src/MixerAll.cxx index b38005520..00343a1a0 100644 --- a/src/MixerAll.cxx +++ b/src/MixerAll.cxx @@ -19,13 +19,14 @@ #include "config.h" #include "MixerAll.hxx" +#include "MixerControl.hxx" +#include "MixerInternal.hxx" +#include "MixerList.hxx" #include "OutputAll.hxx" #include "PcmVolume.hxx" extern "C" { -#include "mixer_control.h" #include "output_internal.h" -#include "mixer_api.h" } #include diff --git a/src/MixerControl.cxx b/src/MixerControl.cxx new file mode 100644 index 000000000..4ca1c76ec --- /dev/null +++ b/src/MixerControl.cxx @@ -0,0 +1,185 @@ +/* + * 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 "MixerControl.hxx" +#include "MixerInternal.hxx" + +#include +#include + +#undef G_LOG_DOMAIN +#define G_LOG_DOMAIN "mixer" + +struct mixer * +mixer_new(const struct mixer_plugin *plugin, void *ao, + const struct config_param *param, + GError **error_r) +{ + struct mixer *mixer; + + assert(plugin != NULL); + + mixer = plugin->init(ao, param, error_r); + + assert(mixer == NULL || mixer->plugin == plugin); + + return mixer; +} + +void +mixer_free(struct mixer *mixer) +{ + assert(mixer != NULL); + assert(mixer->plugin != NULL); + assert(mixer->mutex != NULL); + + /* mixers with the "global" flag set might still be open at + this point (see mixer_auto_close()) */ + mixer_close(mixer); + + g_mutex_free(mixer->mutex); + + mixer->plugin->finish(mixer); +} + +bool +mixer_open(struct mixer *mixer, GError **error_r) +{ + bool success; + + assert(mixer != NULL); + assert(mixer->plugin != NULL); + + g_mutex_lock(mixer->mutex); + + if (mixer->open) + success = true; + else if (mixer->plugin->open == NULL) + success = mixer->open = true; + else + success = mixer->open = mixer->plugin->open(mixer, error_r); + + mixer->failed = !success; + + g_mutex_unlock(mixer->mutex); + + return success; +} + +static void +mixer_close_internal(struct mixer *mixer) +{ + assert(mixer != NULL); + assert(mixer->plugin != NULL); + assert(mixer->open); + + if (mixer->plugin->close != NULL) + mixer->plugin->close(mixer); + + mixer->open = false; +} + +void +mixer_close(struct mixer *mixer) +{ + assert(mixer != NULL); + assert(mixer->plugin != NULL); + + g_mutex_lock(mixer->mutex); + + if (mixer->open) + mixer_close_internal(mixer); + + g_mutex_unlock(mixer->mutex); +} + +void +mixer_auto_close(struct mixer *mixer) +{ + if (!mixer->plugin->global) + mixer_close(mixer); +} + +/* + * Close the mixer due to failure. The mutex must be locked before + * calling this function. + */ +static void +mixer_failed(struct mixer *mixer) +{ + assert(mixer->open); + + mixer_close_internal(mixer); + + mixer->failed = true; +} + +int +mixer_get_volume(struct mixer *mixer, GError **error_r) +{ + int volume; + + assert(mixer != NULL); + + if (mixer->plugin->global && !mixer->failed && + !mixer_open(mixer, error_r)) + return -1; + + g_mutex_lock(mixer->mutex); + + if (mixer->open) { + GError *error = NULL; + + volume = mixer->plugin->get_volume(mixer, &error); + if (volume < 0 && error != NULL) { + g_propagate_error(error_r, error); + mixer_failed(mixer); + } + } else + volume = -1; + + g_mutex_unlock(mixer->mutex); + + return volume; +} + +bool +mixer_set_volume(struct mixer *mixer, unsigned volume, GError **error_r) +{ + bool success; + + assert(mixer != NULL); + assert(volume <= 100); + + if (mixer->plugin->global && !mixer->failed && + !mixer_open(mixer, error_r)) + return false; + + g_mutex_lock(mixer->mutex); + + if (mixer->open) { + success = mixer->plugin->set_volume(mixer, volume, error_r); + } else + success = false; + + g_mutex_unlock(mixer->mutex); + + return success; +} diff --git a/src/MixerControl.hxx b/src/MixerControl.hxx new file mode 100644 index 000000000..ee1e959da --- /dev/null +++ b/src/MixerControl.hxx @@ -0,0 +1,69 @@ +/* + * 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. + */ + +/** \file + * + * Functions which manipulate a #mixer object. + */ + +#ifndef MPD_MIXER_CONTROL_HXX +#define MPD_MIXER_CONTROL_HXX + +#include "gerror.h" + +struct mixer; +struct mixer_plugin; +struct config_param; + +#ifdef __cplusplus +extern "C" { +#endif + +struct mixer * +mixer_new(const struct mixer_plugin *plugin, void *ao, + const struct config_param *param, + GError **error_r); + +void +mixer_free(struct mixer *mixer); + +bool +mixer_open(struct mixer *mixer, GError **error_r); + +void +mixer_close(struct mixer *mixer); + +/** + * Close the mixer unless the plugin's "global" flag is set. This is + * called when the #audio_output is closed. + */ +void +mixer_auto_close(struct mixer *mixer); + +int +mixer_get_volume(struct mixer *mixer, GError **error_r); + +bool +mixer_set_volume(struct mixer *mixer, unsigned volume, GError **error_r); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/src/MixerInternal.cxx b/src/MixerInternal.cxx new file mode 100644 index 000000000..b8729fc7e --- /dev/null +++ b/src/MixerInternal.cxx @@ -0,0 +1,33 @@ +/* + * 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; +} diff --git a/src/MixerInternal.hxx b/src/MixerInternal.hxx new file mode 100644 index 000000000..9c39e3e35 --- /dev/null +++ b/src/MixerInternal.hxx @@ -0,0 +1,52 @@ +/* + * 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. + */ + +#ifndef MPD_MIXER_INTERNAL_HXX +#define MPD_MIXER_INTERNAL_HXX + +#include "MixerPlugin.hxx" +#include "MixerList.hxx" + +#include + +struct mixer { + const struct mixer_plugin *plugin; + + /** + * This mutex protects all of the mixer struct, including its + * implementation, so plugins don't have to deal with that. + */ + GMutex *mutex; + + /** + * Is the mixer device currently open? + */ + bool open; + + /** + * Has this mixer failed, and should not be reopened + * automatically? + */ + bool failed; +}; + +void +mixer_init(struct mixer *mixer, const struct mixer_plugin *plugin); + +#endif diff --git a/src/MixerList.hxx b/src/MixerList.hxx new file mode 100644 index 000000000..440f442ba --- /dev/null +++ b/src/MixerList.hxx @@ -0,0 +1,35 @@ +/* + * 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. + */ + +/** \file + * + * This header provides "extern" declarations for all mixer plugins. + */ + +#ifndef MPD_MIXER_LIST_HXX +#define MPD_MIXER_LIST_HXX + +extern const struct mixer_plugin software_mixer_plugin; +extern const struct mixer_plugin alsa_mixer_plugin; +extern const struct mixer_plugin oss_mixer_plugin; +extern const struct mixer_plugin roar_mixer_plugin; +extern const struct mixer_plugin pulse_mixer_plugin; +extern const struct mixer_plugin winmm_mixer_plugin; + +#endif diff --git a/src/MixerPlugin.hxx b/src/MixerPlugin.hxx new file mode 100644 index 000000000..1fbdfbbc2 --- /dev/null +++ b/src/MixerPlugin.hxx @@ -0,0 +1,99 @@ +/* + * 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. + */ + +/** \file + * + * This header declares the mixer_plugin class. It should not be + * included directly; use MixerInternal.hxx instead in mixer + * implementations. + */ + +#ifndef MPD_MIXER_PLUGIN_HXX +#define MPD_MIXER_PLUGIN_HXX + +#include "gerror.h" + +#include + +struct config_param; +struct mixer; + +struct mixer_plugin { + /** + * Alocates and configures a mixer device. + * + * @param ao the pointer returned by audio_output_plugin.init + * @param param the configuration section, or NULL if there is + * no configuration + * @param error_r location to store the error occurring, or + * NULL to ignore errors + * @return a mixer object, or NULL on error + */ + struct mixer *(*init)(void *ao, const struct config_param *param, + GError **error_r); + + /** + * Finish and free mixer data + */ + void (*finish)(struct mixer *data); + + /** + * Open mixer device + * + * @param error_r location to store the error occurring, or + * NULL to ignore errors + * @return true on success, false on error + */ + bool (*open)(struct mixer *data, GError **error_r); + + /** + * Close mixer device + */ + void (*close)(struct mixer *data); + + /** + * Reads the current volume. + * + * @param error_r location to store the error occurring, or + * NULL to ignore errors + * @return the current volume (0..100 including) or -1 if + * unavailable or on error (error_r set, mixer will be closed) + */ + int (*get_volume)(struct mixer *mixer, GError **error_r); + + /** + * Sets the volume. + * + * @param error_r location to store the error occurring, or + * NULL to ignore errors + * @param volume the new volume (0..100 including) + * @return true on success, false on error + */ + bool (*set_volume)(struct mixer *mixer, unsigned volume, + GError **error_r); + + /** + * If true, then the mixer is automatically opened, even if + * its audio output is not open. If false, then the mixer is + * disabled as long as its audio output is closed. + */ + bool global; +}; + +#endif diff --git a/src/MixerType.cxx b/src/MixerType.cxx new file mode 100644 index 000000000..435079790 --- /dev/null +++ b/src/MixerType.cxx @@ -0,0 +1,39 @@ +/* + * 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 "MixerType.hxx" + +#include +#include + +enum mixer_type +mixer_type_parse(const char *input) +{ + assert(input != NULL); + + if (strcmp(input, "none") == 0 || strcmp(input, "disabled") == 0) + return MIXER_TYPE_NONE; + else if (strcmp(input, "hardware") == 0) + return MIXER_TYPE_HARDWARE; + else if (strcmp(input, "software") == 0) + return MIXER_TYPE_SOFTWARE; + else + return MIXER_TYPE_UNKNOWN; +} diff --git a/src/MixerType.hxx b/src/MixerType.hxx new file mode 100644 index 000000000..320a36c04 --- /dev/null +++ b/src/MixerType.hxx @@ -0,0 +1,47 @@ +/* + * 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. + */ + +#ifndef MPD_MIXER_TYPE_HXX +#define MPD_MIXER_TYPE_HXX + +enum mixer_type { + /** parser error */ + MIXER_TYPE_UNKNOWN, + + /** mixer disabled */ + MIXER_TYPE_NONE, + + /** software mixer with pcm_volume() */ + MIXER_TYPE_SOFTWARE, + + /** hardware mixer (output's plugin) */ + MIXER_TYPE_HARDWARE, +}; + +/** + * Parses a "mixer_type" setting from the configuration file. + * + * @param input the configured string value; must not be NULL + * @return a #mixer_type value; MIXER_TYPE_UNKNOWN means #input could + * not be parsed + */ +enum mixer_type +mixer_type_parse(const char *input); + +#endif diff --git a/src/OutputCommand.cxx b/src/OutputCommand.cxx index be52b49a8..beb44f0ef 100644 --- a/src/OutputCommand.cxx +++ b/src/OutputCommand.cxx @@ -28,12 +28,12 @@ #include "OutputCommand.hxx" #include "OutputAll.hxx" #include "PlayerControl.hxx" +#include "MixerControl.hxx" #include "Idle.hxx" extern "C" { #include "output_internal.h" #include "output_plugin.h" -#include "mixer_control.h" } extern unsigned audio_output_state_version; diff --git a/src/OutputControl.cxx b/src/OutputControl.cxx index 37565082e..c451938f7 100644 --- a/src/OutputControl.cxx +++ b/src/OutputControl.cxx @@ -24,10 +24,10 @@ extern "C" { #include "output_internal.h" -#include "mixer_control.h" -#include "mixer_plugin.h" } +#include "MixerPlugin.hxx" +#include "MixerControl.hxx" #include "notify.hxx" #include "filter/ReplayGainFilterPlugin.hxx" #include "FilterPlugin.hxx" diff --git a/src/OutputFinish.cxx b/src/OutputFinish.cxx index 8b9480b88..559a5cf25 100644 --- a/src/OutputFinish.cxx +++ b/src/OutputFinish.cxx @@ -22,9 +22,9 @@ extern "C" { #include "output_internal.h" #include "output_plugin.h" -#include "mixer_control.h" } +#include "MixerControl.hxx" #include "FilterInternal.hxx" #include diff --git a/src/OutputInit.cxx b/src/OutputInit.cxx index 8c60fe4f1..de6869256 100644 --- a/src/OutputInit.cxx +++ b/src/OutputInit.cxx @@ -27,11 +27,11 @@ extern "C" { #include "output_internal.h" -#include "mixer_control.h" -#include "mixer_type.h" -#include "mixer_list.h" } +#include "MixerList.hxx" +#include "MixerType.hxx" +#include "MixerControl.hxx" #include "mixer/SoftwareMixerPlugin.hxx" #include "FilterPlugin.hxx" #include "FilterRegistry.hxx" diff --git a/src/filter/ReplayGainFilterPlugin.cxx b/src/filter/ReplayGainFilterPlugin.cxx index 13c8a4063..1fa2269b4 100644 --- a/src/filter/ReplayGainFilterPlugin.cxx +++ b/src/filter/ReplayGainFilterPlugin.cxx @@ -25,7 +25,7 @@ #include "audio_format.h" #include "replay_gain_info.h" #include "replay_gain_config.h" -#include "mixer_control.h" +#include "MixerControl.hxx" #include "PcmVolume.hxx" extern "C" { diff --git a/src/mixer/AlsaMixerPlugin.cxx b/src/mixer/AlsaMixerPlugin.cxx index 17f8b9a6f..d75016c00 100644 --- a/src/mixer/AlsaMixerPlugin.cxx +++ b/src/mixer/AlsaMixerPlugin.cxx @@ -18,7 +18,7 @@ */ #include "config.h" -#include "mixer_api.h" +#include "MixerInternal.hxx" #include "output_api.h" #include "GlobalEvents.hxx" #include "Main.hxx" diff --git a/src/mixer/OssMixerPlugin.cxx b/src/mixer/OssMixerPlugin.cxx index 490a65414..8d266b40a 100644 --- a/src/mixer/OssMixerPlugin.cxx +++ b/src/mixer/OssMixerPlugin.cxx @@ -18,7 +18,7 @@ */ #include "config.h" -#include "mixer_api.h" +#include "MixerInternal.hxx" #include "output_api.h" #include "fd_util.h" diff --git a/src/mixer/PulseMixerPlugin.cxx b/src/mixer/PulseMixerPlugin.cxx index 65dbc01fe..d7c6c8043 100644 --- a/src/mixer/PulseMixerPlugin.cxx +++ b/src/mixer/PulseMixerPlugin.cxx @@ -19,7 +19,7 @@ #include "config.h" #include "PulseMixerPlugin.h" -#include "mixer_api.h" +#include "MixerInternal.hxx" #include "output/pulse_output_plugin.h" #include "conf.h" #include "GlobalEvents.hxx" diff --git a/src/mixer/RoarMixerPlugin.cxx b/src/mixer/RoarMixerPlugin.cxx index 2803203b7..a027f8570 100644 --- a/src/mixer/RoarMixerPlugin.cxx +++ b/src/mixer/RoarMixerPlugin.cxx @@ -20,7 +20,7 @@ #include "config.h" -#include "mixer_api.h" +#include "MixerInternal.hxx" #include "output_api.h" #include "output/RoarOutputPlugin.hxx" diff --git a/src/mixer/SoftwareMixerPlugin.cxx b/src/mixer/SoftwareMixerPlugin.cxx index 16463938f..6c287ea07 100644 --- a/src/mixer/SoftwareMixerPlugin.cxx +++ b/src/mixer/SoftwareMixerPlugin.cxx @@ -19,7 +19,7 @@ #include "config.h" #include "SoftwareMixerPlugin.hxx" -#include "mixer_api.h" +#include "MixerInternal.hxx" #include "FilterPlugin.hxx" #include "FilterRegistry.hxx" #include "filter/VolumeFilterPlugin.hxx" diff --git a/src/mixer/WinmmMixerPlugin.cxx b/src/mixer/WinmmMixerPlugin.cxx index e3b7948e3..bf3155864 100644 --- a/src/mixer/WinmmMixerPlugin.cxx +++ b/src/mixer/WinmmMixerPlugin.cxx @@ -18,7 +18,7 @@ */ #include "config.h" -#include "mixer_api.h" +#include "MixerInternal.hxx" #include "output_api.h" #include "output/WinmmOutputPlugin.hxx" diff --git a/src/mixer_api.c b/src/mixer_api.c deleted file mode 100644 index c85916c94..000000000 --- a/src/mixer_api.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (C) 2003-2011 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 "mixer_api.h" - -#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; -} diff --git a/src/mixer_api.h b/src/mixer_api.h deleted file mode 100644 index f0c9a0937..000000000 --- a/src/mixer_api.h +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright (C) 2003-2011 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. - */ - -#ifndef MPD_MIXER_H -#define MPD_MIXER_H - -#include "mixer_plugin.h" -#include "mixer_list.h" - -#include - -struct mixer { - const struct mixer_plugin *plugin; - - /** - * This mutex protects all of the mixer struct, including its - * implementation, so plugins don't have to deal with that. - */ - GMutex *mutex; - - /** - * Is the mixer device currently open? - */ - bool open; - - /** - * Has this mixer failed, and should not be reopened - * automatically? - */ - bool failed; -}; - -#ifdef __cplusplus -extern "C" { -#endif - -void -mixer_init(struct mixer *mixer, const struct mixer_plugin *plugin); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/src/mixer_control.c b/src/mixer_control.c deleted file mode 100644 index 3e984dd04..000000000 --- a/src/mixer_control.c +++ /dev/null @@ -1,185 +0,0 @@ -/* - * Copyright (C) 2003-2011 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 "mixer_control.h" -#include "mixer_api.h" - -#include -#include - -#undef G_LOG_DOMAIN -#define G_LOG_DOMAIN "mixer" - -struct mixer * -mixer_new(const struct mixer_plugin *plugin, void *ao, - const struct config_param *param, - GError **error_r) -{ - struct mixer *mixer; - - assert(plugin != NULL); - - mixer = plugin->init(ao, param, error_r); - - assert(mixer == NULL || mixer->plugin == plugin); - - return mixer; -} - -void -mixer_free(struct mixer *mixer) -{ - assert(mixer != NULL); - assert(mixer->plugin != NULL); - assert(mixer->mutex != NULL); - - /* mixers with the "global" flag set might still be open at - this point (see mixer_auto_close()) */ - mixer_close(mixer); - - g_mutex_free(mixer->mutex); - - mixer->plugin->finish(mixer); -} - -bool -mixer_open(struct mixer *mixer, GError **error_r) -{ - bool success; - - assert(mixer != NULL); - assert(mixer->plugin != NULL); - - g_mutex_lock(mixer->mutex); - - if (mixer->open) - success = true; - else if (mixer->plugin->open == NULL) - success = mixer->open = true; - else - success = mixer->open = mixer->plugin->open(mixer, error_r); - - mixer->failed = !success; - - g_mutex_unlock(mixer->mutex); - - return success; -} - -static void -mixer_close_internal(struct mixer *mixer) -{ - assert(mixer != NULL); - assert(mixer->plugin != NULL); - assert(mixer->open); - - if (mixer->plugin->close != NULL) - mixer->plugin->close(mixer); - - mixer->open = false; -} - -void -mixer_close(struct mixer *mixer) -{ - assert(mixer != NULL); - assert(mixer->plugin != NULL); - - g_mutex_lock(mixer->mutex); - - if (mixer->open) - mixer_close_internal(mixer); - - g_mutex_unlock(mixer->mutex); -} - -void -mixer_auto_close(struct mixer *mixer) -{ - if (!mixer->plugin->global) - mixer_close(mixer); -} - -/* - * Close the mixer due to failure. The mutex must be locked before - * calling this function. - */ -static void -mixer_failed(struct mixer *mixer) -{ - assert(mixer->open); - - mixer_close_internal(mixer); - - mixer->failed = true; -} - -int -mixer_get_volume(struct mixer *mixer, GError **error_r) -{ - int volume; - - assert(mixer != NULL); - - if (mixer->plugin->global && !mixer->failed && - !mixer_open(mixer, error_r)) - return -1; - - g_mutex_lock(mixer->mutex); - - if (mixer->open) { - GError *error = NULL; - - volume = mixer->plugin->get_volume(mixer, &error); - if (volume < 0 && error != NULL) { - g_propagate_error(error_r, error); - mixer_failed(mixer); - } - } else - volume = -1; - - g_mutex_unlock(mixer->mutex); - - return volume; -} - -bool -mixer_set_volume(struct mixer *mixer, unsigned volume, GError **error_r) -{ - bool success; - - assert(mixer != NULL); - assert(volume <= 100); - - if (mixer->plugin->global && !mixer->failed && - !mixer_open(mixer, error_r)) - return false; - - g_mutex_lock(mixer->mutex); - - if (mixer->open) { - success = mixer->plugin->set_volume(mixer, volume, error_r); - } else - success = false; - - g_mutex_unlock(mixer->mutex); - - return success; -} diff --git a/src/mixer_control.h b/src/mixer_control.h deleted file mode 100644 index 46219e5dd..000000000 --- a/src/mixer_control.h +++ /dev/null @@ -1,71 +0,0 @@ -/* - * Copyright (C) 2003-2011 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. - */ - -/** \file - * - * Functions which manipulate a #mixer object. - */ - -#ifndef MPD_MIXER_CONTROL_H -#define MPD_MIXER_CONTROL_H - -#include "gerror.h" - -#include - -struct mixer; -struct mixer_plugin; -struct config_param; - -#ifdef __cplusplus -extern "C" { -#endif - -struct mixer * -mixer_new(const struct mixer_plugin *plugin, void *ao, - const struct config_param *param, - GError **error_r); - -void -mixer_free(struct mixer *mixer); - -bool -mixer_open(struct mixer *mixer, GError **error_r); - -void -mixer_close(struct mixer *mixer); - -/** - * Close the mixer unless the plugin's "global" flag is set. This is - * called when the #audio_output is closed. - */ -void -mixer_auto_close(struct mixer *mixer); - -int -mixer_get_volume(struct mixer *mixer, GError **error_r); - -bool -mixer_set_volume(struct mixer *mixer, unsigned volume, GError **error_r); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/src/mixer_list.h b/src/mixer_list.h deleted file mode 100644 index 078358ec3..000000000 --- a/src/mixer_list.h +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright (C) 2003-2011 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. - */ - -/** \file - * - * This header provides "extern" declarations for all mixer plugins. - */ - -#ifndef MPD_MIXER_LIST_H -#define MPD_MIXER_LIST_H - -extern const struct mixer_plugin software_mixer_plugin; -extern const struct mixer_plugin alsa_mixer_plugin; -extern const struct mixer_plugin oss_mixer_plugin; -extern const struct mixer_plugin roar_mixer_plugin; -extern const struct mixer_plugin pulse_mixer_plugin; -extern const struct mixer_plugin winmm_mixer_plugin; - -#endif diff --git a/src/mixer_plugin.h b/src/mixer_plugin.h deleted file mode 100644 index 2f3beed1d..000000000 --- a/src/mixer_plugin.h +++ /dev/null @@ -1,99 +0,0 @@ -/* - * Copyright (C) 2003-2011 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. - */ - -/** \file - * - * This header declares the mixer_plugin class. It should not be - * included directly; use mixer_api.h instead in mixer - * implementations. - */ - -#ifndef MPD_MIXER_PLUGIN_H -#define MPD_MIXER_PLUGIN_H - -#include "gerror.h" - -#include - -struct config_param; -struct mixer; - -struct mixer_plugin { - /** - * Alocates and configures a mixer device. - * - * @param ao the pointer returned by audio_output_plugin.init - * @param param the configuration section, or NULL if there is - * no configuration - * @param error_r location to store the error occurring, or - * NULL to ignore errors - * @return a mixer object, or NULL on error - */ - struct mixer *(*init)(void *ao, const struct config_param *param, - GError **error_r); - - /** - * Finish and free mixer data - */ - void (*finish)(struct mixer *data); - - /** - * Open mixer device - * - * @param error_r location to store the error occurring, or - * NULL to ignore errors - * @return true on success, false on error - */ - bool (*open)(struct mixer *data, GError **error_r); - - /** - * Close mixer device - */ - void (*close)(struct mixer *data); - - /** - * Reads the current volume. - * - * @param error_r location to store the error occurring, or - * NULL to ignore errors - * @return the current volume (0..100 including) or -1 if - * unavailable or on error (error_r set, mixer will be closed) - */ - int (*get_volume)(struct mixer *mixer, GError **error_r); - - /** - * Sets the volume. - * - * @param error_r location to store the error occurring, or - * NULL to ignore errors - * @param volume the new volume (0..100 including) - * @return true on success, false on error - */ - bool (*set_volume)(struct mixer *mixer, unsigned volume, - GError **error_r); - - /** - * If true, then the mixer is automatically opened, even if - * its audio output is not open. If false, then the mixer is - * disabled as long as its audio output is closed. - */ - bool global; -}; - -#endif diff --git a/src/mixer_type.c b/src/mixer_type.c deleted file mode 100644 index a479caf16..000000000 --- a/src/mixer_type.c +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright (C) 2003-2011 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 "mixer_type.h" - -#include -#include - -enum mixer_type -mixer_type_parse(const char *input) -{ - assert(input != NULL); - - if (strcmp(input, "none") == 0 || strcmp(input, "disabled") == 0) - return MIXER_TYPE_NONE; - else if (strcmp(input, "hardware") == 0) - return MIXER_TYPE_HARDWARE; - else if (strcmp(input, "software") == 0) - return MIXER_TYPE_SOFTWARE; - else - return MIXER_TYPE_UNKNOWN; -} diff --git a/src/mixer_type.h b/src/mixer_type.h deleted file mode 100644 index 15d136b5b..000000000 --- a/src/mixer_type.h +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright (C) 2003-2011 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. - */ - -#ifndef MPD_MIXER_TYPE_H -#define MPD_MIXER_TYPE_H - -enum mixer_type { - /** parser error */ - MIXER_TYPE_UNKNOWN, - - /** mixer disabled */ - MIXER_TYPE_NONE, - - /** software mixer with pcm_volume() */ - MIXER_TYPE_SOFTWARE, - - /** hardware mixer (output's plugin) */ - MIXER_TYPE_HARDWARE, -}; - -/** - * Parses a "mixer_type" setting from the configuration file. - * - * @param input the configured string value; must not be NULL - * @return a #mixer_type value; MIXER_TYPE_UNKNOWN means #input could - * not be parsed - */ -enum mixer_type -mixer_type_parse(const char *input); - -#endif diff --git a/src/output/AlsaOutputPlugin.cxx b/src/output/AlsaOutputPlugin.cxx index 1badeb63d..c87c4cb99 100644 --- a/src/output/AlsaOutputPlugin.cxx +++ b/src/output/AlsaOutputPlugin.cxx @@ -20,7 +20,7 @@ #include "config.h" #include "AlsaOutputPlugin.hxx" #include "output_api.h" -#include "mixer_list.h" +#include "MixerList.hxx" #include "pcm_export.h" #include diff --git a/src/output/OssOutputPlugin.cxx b/src/output/OssOutputPlugin.cxx index ace88b6f4..0111b13f6 100644 --- a/src/output/OssOutputPlugin.cxx +++ b/src/output/OssOutputPlugin.cxx @@ -20,7 +20,7 @@ #include "config.h" #include "OssOutputPlugin.hxx" #include "output_api.h" -#include "mixer_list.h" +#include "MixerList.hxx" #include "fd_util.h" #include diff --git a/src/output/RoarOutputPlugin.cxx b/src/output/RoarOutputPlugin.cxx index 43aeb09a2..9d6c45917 100644 --- a/src/output/RoarOutputPlugin.cxx +++ b/src/output/RoarOutputPlugin.cxx @@ -21,7 +21,7 @@ #include "config.h" #include "RoarOutputPlugin.hxx" #include "output_api.h" -#include "mixer_list.h" +#include "MixerList.hxx" #include "thread/Mutex.hxx" #include diff --git a/src/output/WinmmOutputPlugin.cxx b/src/output/WinmmOutputPlugin.cxx index 7944e2bdd..b9652fc0b 100644 --- a/src/output/WinmmOutputPlugin.cxx +++ b/src/output/WinmmOutputPlugin.cxx @@ -21,7 +21,7 @@ #include "WinmmOutputPlugin.hxx" #include "output_api.h" #include "pcm_buffer.h" -#include "mixer_list.h" +#include "MixerList.hxx" #include #include diff --git a/src/output/pulse_output_plugin.c b/src/output/pulse_output_plugin.c index 457fa9f04..e82d3d3fc 100644 --- a/src/output/pulse_output_plugin.c +++ b/src/output/pulse_output_plugin.c @@ -20,7 +20,7 @@ #include "config.h" #include "pulse_output_plugin.h" #include "output_api.h" -#include "mixer_list.h" +#include "MixerList.hxx" #include "mixer/PulseMixerPlugin.h" #include -- cgit v1.2.3