diff options
author | Max Kellermann <max@duempel.org> | 2014-02-06 21:10:12 +0100 |
---|---|---|
committer | Max Kellermann <max@duempel.org> | 2014-02-06 21:10:12 +0100 |
commit | 0a0659d737e8788fc1ba02e8c113e55204782716 (patch) | |
tree | 8855ba68e8648bbb81ea94899406e4b2988ae489 /src | |
parent | b6df4680df08db7827af56d5adf2a04264f2dcb9 (diff) |
mixer/Plugin: pass AudioOutput reference to init()
Passing a void pointer is unsafe.
Diffstat (limited to 'src')
-rw-r--r-- | src/mixer/MixerControl.cxx | 2 | ||||
-rw-r--r-- | src/mixer/MixerControl.hxx | 3 | ||||
-rw-r--r-- | src/mixer/MixerPlugin.hxx | 5 | ||||
-rw-r--r-- | src/mixer/plugins/AlsaMixerPlugin.cxx | 2 | ||||
-rw-r--r-- | src/mixer/plugins/OssMixerPlugin.cxx | 2 | ||||
-rw-r--r-- | src/mixer/plugins/PulseMixerPlugin.cxx | 31 | ||||
-rw-r--r-- | src/mixer/plugins/PulseMixerPlugin.hxx | 6 | ||||
-rw-r--r-- | src/mixer/plugins/RoarMixerPlugin.cxx | 8 | ||||
-rw-r--r-- | src/mixer/plugins/SoftwareMixerPlugin.cxx | 3 | ||||
-rw-r--r-- | src/mixer/plugins/WinmmMixerPlugin.cxx | 10 | ||||
-rw-r--r-- | src/output/Init.cxx | 4 | ||||
-rw-r--r-- | src/output/plugins/PulseOutputPlugin.cxx | 64 | ||||
-rw-r--r-- | src/output/plugins/PulseOutputPlugin.hxx | 10 | ||||
-rw-r--r-- | src/output/plugins/RoarOutputPlugin.cxx | 8 | ||||
-rw-r--r-- | src/output/plugins/RoarOutputPlugin.hxx | 4 | ||||
-rw-r--r-- | src/output/plugins/WinmmOutputPlugin.cxx | 4 | ||||
-rw-r--r-- | src/output/plugins/WinmmOutputPlugin.hxx | 2 |
17 files changed, 79 insertions, 89 deletions
diff --git a/src/mixer/MixerControl.cxx b/src/mixer/MixerControl.cxx index e7b6e8395..568fad058 100644 --- a/src/mixer/MixerControl.cxx +++ b/src/mixer/MixerControl.cxx @@ -26,7 +26,7 @@ Mixer * mixer_new(EventLoop &event_loop, - const MixerPlugin &plugin, void *ao, + const MixerPlugin &plugin, AudioOutput &ao, const config_param ¶m, Error &error) { diff --git a/src/mixer/MixerControl.hxx b/src/mixer/MixerControl.hxx index cc2ccc087..46a9138e6 100644 --- a/src/mixer/MixerControl.hxx +++ b/src/mixer/MixerControl.hxx @@ -28,11 +28,12 @@ class Error; class Mixer; class EventLoop; +struct AudioOutput; struct MixerPlugin; struct config_param; Mixer * -mixer_new(EventLoop &event_loop, const MixerPlugin &plugin, void *ao, +mixer_new(EventLoop &event_loop, const MixerPlugin &plugin, AudioOutput &ao, const config_param ¶m, Error &error); diff --git a/src/mixer/MixerPlugin.hxx b/src/mixer/MixerPlugin.hxx index 27e59accf..bf9af14e3 100644 --- a/src/mixer/MixerPlugin.hxx +++ b/src/mixer/MixerPlugin.hxx @@ -28,6 +28,7 @@ #define MPD_MIXER_PLUGIN_HXX struct config_param; +struct AudioOutput; class Mixer; class EventLoop; class Error; @@ -36,13 +37,13 @@ struct MixerPlugin { /** * Alocates and configures a mixer device. * - * @param ao the pointer returned by AudioOutputPlugin.init + * @param ao the associated AudioOutput * @param param the configuration section * @param error_r location to store the error occurring, or * nullptr to ignore errors * @return a mixer object, or nullptr on error */ - Mixer *(*init)(EventLoop &event_loop, void *ao, + Mixer *(*init)(EventLoop &event_loop, AudioOutput &ao, const config_param ¶m, Error &error); diff --git a/src/mixer/plugins/AlsaMixerPlugin.cxx b/src/mixer/plugins/AlsaMixerPlugin.cxx index 3a520725f..26007fef3 100644 --- a/src/mixer/plugins/AlsaMixerPlugin.cxx +++ b/src/mixer/plugins/AlsaMixerPlugin.cxx @@ -167,7 +167,7 @@ AlsaMixer::Configure(const config_param ¶m) } static Mixer * -alsa_mixer_init(EventLoop &event_loop, gcc_unused void *ao, +alsa_mixer_init(EventLoop &event_loop, gcc_unused AudioOutput &ao, const config_param ¶m, gcc_unused Error &error) { diff --git a/src/mixer/plugins/OssMixerPlugin.cxx b/src/mixer/plugins/OssMixerPlugin.cxx index fc86f292e..939fe0824 100644 --- a/src/mixer/plugins/OssMixerPlugin.cxx +++ b/src/mixer/plugins/OssMixerPlugin.cxx @@ -97,7 +97,7 @@ OssMixer::Configure(const config_param ¶m, Error &error) } static Mixer * -oss_mixer_init(gcc_unused EventLoop &event_loop, gcc_unused void *ao, +oss_mixer_init(gcc_unused EventLoop &event_loop, gcc_unused AudioOutput &ao, const config_param ¶m, Error &error) { diff --git a/src/mixer/plugins/PulseMixerPlugin.cxx b/src/mixer/plugins/PulseMixerPlugin.cxx index 10aa6a93a..b838de689 100644 --- a/src/mixer/plugins/PulseMixerPlugin.cxx +++ b/src/mixer/plugins/PulseMixerPlugin.cxx @@ -35,13 +35,13 @@ #include <assert.h> class PulseMixer final : public Mixer { - PulseOutput *output; + PulseOutput &output; bool online; struct pa_cvolume volume; public: - PulseMixer(PulseOutput *_output) + PulseMixer(PulseOutput &_output) :Mixer(pulse_mixer_plugin), output(_output), online(false) { @@ -130,7 +130,7 @@ PulseMixer::Update(pa_context *context, pa_stream *stream) } void -pulse_mixer_on_connect(gcc_unused PulseMixer *pm, +pulse_mixer_on_connect(gcc_unused PulseMixer &pm, struct pa_context *context) { pa_operation *o; @@ -151,41 +151,34 @@ pulse_mixer_on_connect(gcc_unused PulseMixer *pm, } void -pulse_mixer_on_disconnect(PulseMixer *pm) +pulse_mixer_on_disconnect(PulseMixer &pm) { - pm->Offline(); + pm.Offline(); } void -pulse_mixer_on_change(PulseMixer *pm, +pulse_mixer_on_change(PulseMixer &pm, struct pa_context *context, struct pa_stream *stream) { - pm->Update(context, stream); + pm.Update(context, stream); } static Mixer * -pulse_mixer_init(gcc_unused EventLoop &event_loop, void *ao, +pulse_mixer_init(gcc_unused EventLoop &event_loop, AudioOutput &ao, gcc_unused const config_param ¶m, - Error &error) + gcc_unused Error &error) { - PulseOutput *po = (PulseOutput *)ao; - - if (ao == nullptr) { - error.Set(pulse_mixer_domain, - "The pulse mixer cannot work without the audio output"); - return nullptr; - } - + PulseOutput &po = (PulseOutput &)ao; PulseMixer *pm = new PulseMixer(po); - pulse_output_set_mixer(po, pm); + pulse_output_set_mixer(po, *pm); return pm; } PulseMixer::~PulseMixer() { - pulse_output_clear_mixer(output, this); + pulse_output_clear_mixer(output, *this); } int diff --git a/src/mixer/plugins/PulseMixerPlugin.hxx b/src/mixer/plugins/PulseMixerPlugin.hxx index 23cf03566..9b3a6daf1 100644 --- a/src/mixer/plugins/PulseMixerPlugin.hxx +++ b/src/mixer/plugins/PulseMixerPlugin.hxx @@ -25,12 +25,12 @@ struct pa_context; struct pa_stream; void -pulse_mixer_on_connect(PulseMixer *pm, pa_context *context); +pulse_mixer_on_connect(PulseMixer &pm, pa_context *context); void -pulse_mixer_on_disconnect(PulseMixer *pm); +pulse_mixer_on_disconnect(PulseMixer &pm); void -pulse_mixer_on_change(PulseMixer *pm, pa_context *context, pa_stream *stream); +pulse_mixer_on_change(PulseMixer &pm, pa_context *context, pa_stream *stream); #endif diff --git a/src/mixer/plugins/RoarMixerPlugin.cxx b/src/mixer/plugins/RoarMixerPlugin.cxx index d1ac8a6e3..7c2a25dfb 100644 --- a/src/mixer/plugins/RoarMixerPlugin.cxx +++ b/src/mixer/plugins/RoarMixerPlugin.cxx @@ -26,10 +26,10 @@ class RoarMixer final : public Mixer { /** the base mixer class */ - RoarOutput *self; + RoarOutput &self; public: - RoarMixer(RoarOutput *_output) + RoarMixer(RoarOutput &_output) :Mixer(roar_mixer_plugin), self(_output) {} @@ -46,11 +46,11 @@ public: }; static Mixer * -roar_mixer_init(gcc_unused EventLoop &event_loop, void *ao, +roar_mixer_init(gcc_unused EventLoop &event_loop, AudioOutput &ao, gcc_unused const config_param ¶m, gcc_unused Error &error) { - return new RoarMixer((RoarOutput *)ao); + return new RoarMixer((RoarOutput &)ao); } int diff --git a/src/mixer/plugins/SoftwareMixerPlugin.cxx b/src/mixer/plugins/SoftwareMixerPlugin.cxx index 7dba2ee5e..78f0769ab 100644 --- a/src/mixer/plugins/SoftwareMixerPlugin.cxx +++ b/src/mixer/plugins/SoftwareMixerPlugin.cxx @@ -84,7 +84,8 @@ public: }; static Mixer * -software_mixer_init(gcc_unused EventLoop &event_loop, gcc_unused void *ao, +software_mixer_init(gcc_unused EventLoop &event_loop, + gcc_unused AudioOutput &ao, gcc_unused const config_param ¶m, gcc_unused Error &error) { diff --git a/src/mixer/plugins/WinmmMixerPlugin.cxx b/src/mixer/plugins/WinmmMixerPlugin.cxx index d69480264..6b81fa095 100644 --- a/src/mixer/plugins/WinmmMixerPlugin.cxx +++ b/src/mixer/plugins/WinmmMixerPlugin.cxx @@ -31,10 +31,10 @@ #include <windows.h> class WinmmMixer final : public Mixer { - WinmmOutput *output; + WinmmOutput &output; public: - WinmmMixer(WinmmOutput *_output) + WinmmMixer(WinmmOutput &_output) :Mixer(winmm_mixer_plugin), output(_output) { } @@ -67,13 +67,11 @@ winmm_volume_encode(int volume) } static Mixer * -winmm_mixer_init(gcc_unused EventLoop &event_loop, void *ao, +winmm_mixer_init(gcc_unused EventLoop &event_loop, AudioOutput &ao, gcc_unused const config_param ¶m, gcc_unused Error &error) { - assert(ao != nullptr); - - return new WinmmMixer((WinmmOutput *)ao); + return new WinmmMixer((WinmmOutput &)ao); } int diff --git a/src/output/Init.cxx b/src/output/Init.cxx index 8d1e7d341..f69ea362f 100644 --- a/src/output/Init.cxx +++ b/src/output/Init.cxx @@ -129,10 +129,10 @@ audio_output_load_mixer(EventLoop &event_loop, AudioOutput *ao, if (plugin == nullptr) return nullptr; - return mixer_new(event_loop, *plugin, ao, param, error); + return mixer_new(event_loop, *plugin, *ao, param, error); case MIXER_TYPE_SOFTWARE: - mixer = mixer_new(event_loop, software_mixer_plugin, nullptr, + mixer = mixer_new(event_loop, software_mixer_plugin, *ao, config_param(), IgnoreError()); assert(mixer != nullptr); diff --git a/src/output/plugins/PulseOutputPlugin.cxx b/src/output/plugins/PulseOutputPlugin.cxx index 1f255718f..4e24984c4 100644 --- a/src/output/plugins/PulseOutputPlugin.cxx +++ b/src/output/plugins/PulseOutputPlugin.cxx @@ -70,70 +70,66 @@ SetError(Error &error, pa_context *context, const char *msg) } void -pulse_output_lock(PulseOutput *po) +pulse_output_lock(PulseOutput &po) { - pa_threaded_mainloop_lock(po->mainloop); + pa_threaded_mainloop_lock(po.mainloop); } void -pulse_output_unlock(PulseOutput *po) +pulse_output_unlock(PulseOutput &po) { - pa_threaded_mainloop_unlock(po->mainloop); + pa_threaded_mainloop_unlock(po.mainloop); } void -pulse_output_set_mixer(PulseOutput *po, PulseMixer *pm) +pulse_output_set_mixer(PulseOutput &po, PulseMixer &pm) { - assert(po != nullptr); - assert(po->mixer == nullptr); - assert(pm != nullptr); + assert(po.mixer == nullptr); - po->mixer = pm; + po.mixer = ± - if (po->mainloop == nullptr) + if (po.mainloop == nullptr) return; - pa_threaded_mainloop_lock(po->mainloop); + pa_threaded_mainloop_lock(po.mainloop); - if (po->context != nullptr && - pa_context_get_state(po->context) == PA_CONTEXT_READY) { - pulse_mixer_on_connect(pm, po->context); + if (po.context != nullptr && + pa_context_get_state(po.context) == PA_CONTEXT_READY) { + pulse_mixer_on_connect(pm, po.context); - if (po->stream != nullptr && - pa_stream_get_state(po->stream) == PA_STREAM_READY) - pulse_mixer_on_change(pm, po->context, po->stream); + if (po.stream != nullptr && + pa_stream_get_state(po.stream) == PA_STREAM_READY) + pulse_mixer_on_change(pm, po.context, po.stream); } - pa_threaded_mainloop_unlock(po->mainloop); + pa_threaded_mainloop_unlock(po.mainloop); } void -pulse_output_clear_mixer(PulseOutput *po, gcc_unused PulseMixer *pm) +pulse_output_clear_mixer(PulseOutput &po, gcc_unused PulseMixer &pm) { - assert(po != nullptr); - assert(pm != nullptr); - assert(po->mixer == pm); + assert(po.mixer == &pm); - po->mixer = nullptr; + po.mixer = nullptr; } bool -pulse_output_set_volume(PulseOutput *po, const pa_cvolume *volume, +pulse_output_set_volume(PulseOutput &po, const pa_cvolume *volume, Error &error) { pa_operation *o; - if (po->context == nullptr || po->stream == nullptr || - pa_stream_get_state(po->stream) != PA_STREAM_READY) { + if (po.context == nullptr || po.stream == nullptr || + pa_stream_get_state(po.stream) != PA_STREAM_READY) { error.Set(pulse_output_domain, "disconnected"); return false; } - o = pa_context_set_sink_input_volume(po->context, - pa_stream_get_index(po->stream), + o = pa_context_set_sink_input_volume(po.context, + pa_stream_get_index(po.stream), volume, nullptr, nullptr); if (o == nullptr) { - SetError(error, po->context, + SetError(error, po.context, "failed to set PulseAudio volume"); return false; } @@ -190,7 +186,7 @@ pulse_output_context_state_cb(struct pa_context *context, void *userdata) switch (pa_context_get_state(context)) { case PA_CONTEXT_READY: if (po->mixer != nullptr) - pulse_mixer_on_connect(po->mixer, context); + pulse_mixer_on_connect(*po->mixer, context); pa_threaded_mainloop_signal(po->mainloop, 0); break; @@ -198,7 +194,7 @@ pulse_output_context_state_cb(struct pa_context *context, void *userdata) case PA_CONTEXT_TERMINATED: case PA_CONTEXT_FAILED: if (po->mixer != nullptr) - pulse_mixer_on_disconnect(po->mixer); + pulse_mixer_on_disconnect(*po->mixer); /* the caller thread might be waiting for these states */ @@ -231,7 +227,7 @@ pulse_output_subscribe_cb(pa_context *context, idx == pa_stream_get_index(po->stream) && (type == PA_SUBSCRIPTION_EVENT_NEW || type == PA_SUBSCRIPTION_EVENT_CHANGE)) - pulse_mixer_on_change(po->mixer, context, po->stream); + pulse_mixer_on_change(*po->mixer, context, po->stream); } /** @@ -487,7 +483,7 @@ pulse_output_stream_state_cb(pa_stream *stream, void *userdata) switch (pa_stream_get_state(stream)) { case PA_STREAM_READY: if (po->mixer != nullptr) - pulse_mixer_on_change(po->mixer, po->context, stream); + pulse_mixer_on_change(*po->mixer, po->context, stream); pa_threaded_mainloop_signal(po->mainloop, 0); break; @@ -495,7 +491,7 @@ pulse_output_stream_state_cb(pa_stream *stream, void *userdata) case PA_STREAM_FAILED: case PA_STREAM_TERMINATED: if (po->mixer != nullptr) - pulse_mixer_on_disconnect(po->mixer); + pulse_mixer_on_disconnect(*po->mixer); pa_threaded_mainloop_signal(po->mainloop, 0); break; diff --git a/src/output/plugins/PulseOutputPlugin.hxx b/src/output/plugins/PulseOutputPlugin.hxx index 4d8bf4b59..9219780a5 100644 --- a/src/output/plugins/PulseOutputPlugin.hxx +++ b/src/output/plugins/PulseOutputPlugin.hxx @@ -28,19 +28,19 @@ class Error; extern const struct AudioOutputPlugin pulse_output_plugin; void -pulse_output_lock(PulseOutput *po); +pulse_output_lock(PulseOutput &po); void -pulse_output_unlock(PulseOutput *po); +pulse_output_unlock(PulseOutput &po); void -pulse_output_set_mixer(PulseOutput *po, PulseMixer *pm); +pulse_output_set_mixer(PulseOutput &po, PulseMixer &pm); void -pulse_output_clear_mixer(PulseOutput *po, PulseMixer *pm); +pulse_output_clear_mixer(PulseOutput &po, PulseMixer &pm); bool -pulse_output_set_volume(PulseOutput *po, +pulse_output_set_volume(PulseOutput &po, const pa_cvolume *volume, Error &error); #endif diff --git a/src/output/plugins/RoarOutputPlugin.cxx b/src/output/plugins/RoarOutputPlugin.cxx index dca9fa346..ac4dd8a4e 100644 --- a/src/output/plugins/RoarOutputPlugin.cxx +++ b/src/output/plugins/RoarOutputPlugin.cxx @@ -93,9 +93,9 @@ RoarOutput::GetVolume() const } int -roar_output_get_volume(RoarOutput *roar) +roar_output_get_volume(RoarOutput &roar) { - return roar->GetVolume(); + return roar.GetVolume(); } bool @@ -115,9 +115,9 @@ RoarOutput::SetVolume(unsigned volume) } bool -roar_output_set_volume(RoarOutput *roar, unsigned volume) +roar_output_set_volume(RoarOutput &roar, unsigned volume) { - return roar->SetVolume(volume); + return roar.SetVolume(volume); } inline void diff --git a/src/output/plugins/RoarOutputPlugin.hxx b/src/output/plugins/RoarOutputPlugin.hxx index 8b7c37512..5f5a9246e 100644 --- a/src/output/plugins/RoarOutputPlugin.hxx +++ b/src/output/plugins/RoarOutputPlugin.hxx @@ -25,9 +25,9 @@ class RoarOutput; extern const struct AudioOutputPlugin roar_output_plugin; int -roar_output_get_volume(RoarOutput *roar); +roar_output_get_volume(RoarOutput &roar); bool -roar_output_set_volume(RoarOutput *roar, unsigned volume); +roar_output_set_volume(RoarOutput &roar, unsigned volume); #endif diff --git a/src/output/plugins/WinmmOutputPlugin.cxx b/src/output/plugins/WinmmOutputPlugin.cxx index d61f2055a..cae39df5f 100644 --- a/src/output/plugins/WinmmOutputPlugin.cxx +++ b/src/output/plugins/WinmmOutputPlugin.cxx @@ -59,9 +59,9 @@ struct WinmmOutput { static constexpr Domain winmm_output_domain("winmm_output"); HWAVEOUT -winmm_output_get_handle(WinmmOutput *output) +winmm_output_get_handle(WinmmOutput &output) { - return output->handle; + return output.handle; } static bool diff --git a/src/output/plugins/WinmmOutputPlugin.hxx b/src/output/plugins/WinmmOutputPlugin.hxx index 450e58b4e..50fae4f2f 100644 --- a/src/output/plugins/WinmmOutputPlugin.hxx +++ b/src/output/plugins/WinmmOutputPlugin.hxx @@ -35,7 +35,7 @@ extern const struct AudioOutputPlugin winmm_output_plugin; gcc_pure HWAVEOUT -winmm_output_get_handle(WinmmOutput *); +winmm_output_get_handle(WinmmOutput &output); #endif |