From 3934d2d30cf97271dc7b33e3b77b101f09f916e7 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Sat, 17 Sep 2011 19:50:36 +0200 Subject: output/pulse: don't expose internal struct in public header Provide _lock() and _unlock() to wrap all accesses from the mixer plugin. --- src/mixer/pulse_mixer_plugin.c | 12 ++++++----- src/output/pulse_output_plugin.c | 43 ++++++++++++++++++++++++++++++++++++++++ src/output/pulse_output_plugin.h | 37 ++++++---------------------------- test/read_mixer.c | 10 ++++++++++ 4 files changed, 66 insertions(+), 36 deletions(-) diff --git a/src/mixer/pulse_mixer_plugin.c b/src/mixer/pulse_mixer_plugin.c index 8fbba4c5..a82c032b 100644 --- a/src/mixer/pulse_mixer_plugin.c +++ b/src/mixer/pulse_mixer_plugin.c @@ -191,13 +191,13 @@ pulse_mixer_get_volume(struct mixer *mixer, G_GNUC_UNUSED GError **error_r) struct pulse_mixer *pm = (struct pulse_mixer *) mixer; int ret; - pa_threaded_mainloop_lock(pm->output->mainloop); + pulse_output_lock(pm->output); ret = pm->online ? (int)((100*(pa_cvolume_avg(&pm->volume)+1))/PA_VOLUME_NORM) : -1; - pa_threaded_mainloop_unlock(pm->output->mainloop); + pulse_output_unlock(pm->output); return ret; } @@ -209,9 +209,10 @@ pulse_mixer_set_volume(struct mixer *mixer, unsigned volume, GError **error_r) struct pa_cvolume cvolume; bool success; - pa_threaded_mainloop_lock(pm->output->mainloop); + pulse_output_lock(pm->output); + if (!pm->online) { - pa_threaded_mainloop_unlock(pm->output->mainloop); + pulse_output_unlock(pm->output); g_set_error(error_r, pulse_mixer_quark(), 0, "disconnected"); return false; } @@ -221,7 +222,8 @@ pulse_mixer_set_volume(struct mixer *mixer, unsigned volume, GError **error_r) success = pulse_output_set_volume(pm->output, &cvolume, error_r); if (success) pm->volume = cvolume; - pa_threaded_mainloop_unlock(pm->output->mainloop); + + pulse_output_unlock(pm->output); return success; } diff --git a/src/output/pulse_output_plugin.c b/src/output/pulse_output_plugin.c index 62f27967..12b68fc3 100644 --- a/src/output/pulse_output_plugin.c +++ b/src/output/pulse_output_plugin.c @@ -31,11 +31,42 @@ #include #include #include +#include #include +#include #define MPD_PULSE_NAME "Music Player Daemon" +#if !defined(PA_CHECK_VERSION) +/** + * This macro was implemented in libpulse 0.9.16. + */ +#define PA_CHECK_VERSION(a,b,c) false +#endif + +struct pulse_output { + const char *name; + const char *server; + const char *sink; + + struct pulse_mixer *mixer; + + struct pa_threaded_mainloop *mainloop; + struct pa_context *context; + struct pa_stream *stream; + + size_t writable; + +#if !PA_CHECK_VERSION(0,9,11) + /** + * We need this variable because pa_stream_is_corked() wasn't + * added before 0.9.11. + */ + bool pause; +#endif +}; + /** * The quark used for GError.domain. */ @@ -45,6 +76,18 @@ pulse_output_quark(void) return g_quark_from_static_string("pulse_output"); } +void +pulse_output_lock(struct pulse_output *po) +{ + pa_threaded_mainloop_lock(po->mainloop); +} + +void +pulse_output_unlock(struct pulse_output *po) +{ + pa_threaded_mainloop_unlock(po->mainloop); +} + void pulse_output_set_mixer(struct pulse_output *po, struct pulse_mixer *pm) { diff --git a/src/output/pulse_output_plugin.h b/src/output/pulse_output_plugin.h index 2261175d..3f260238 100644 --- a/src/output/pulse_output_plugin.h +++ b/src/output/pulse_output_plugin.h @@ -21,43 +21,18 @@ #define MPD_PULSE_OUTPUT_PLUGIN_H #include -#include #include -#include - -#if !defined(PA_CHECK_VERSION) -/** - * This macro was implemented in libpulse 0.9.16. - */ -#define PA_CHECK_VERSION(a,b,c) false -#endif - -struct pa_operation; +struct pulse_output; +struct pulse_mixer; struct pa_cvolume; -struct pulse_output { - const char *name; - const char *server; - const char *sink; - - struct pulse_mixer *mixer; - - struct pa_threaded_mainloop *mainloop; - struct pa_context *context; - struct pa_stream *stream; - - size_t writable; +void +pulse_output_lock(struct pulse_output *po); -#if !PA_CHECK_VERSION(0,9,11) - /** - * We need this variable because pa_stream_is_corked() wasn't - * added before 0.9.11. - */ - bool pause; -#endif -}; +void +pulse_output_unlock(struct pulse_output *po); void pulse_output_set_mixer(struct pulse_output *po, struct pulse_mixer *pm); diff --git a/test/read_mixer.c b/test/read_mixer.c index 6512e2e9..6d7ec345 100644 --- a/test/read_mixer.c +++ b/test/read_mixer.c @@ -33,6 +33,16 @@ #ifdef HAVE_PULSE #include "output/pulse_output_plugin.h" +void +pulse_output_lock(G_GNUC_UNUSED struct pulse_output *po) +{ +} + +void +pulse_output_unlock(G_GNUC_UNUSED struct pulse_output *po) +{ +} + void pulse_output_set_mixer(G_GNUC_UNUSED struct pulse_output *po, G_GNUC_UNUSED struct pulse_mixer *pm) -- cgit v1.2.3