diff options
author | Max Kellermann <max@duempel.org> | 2014-02-05 17:25:47 +0100 |
---|---|---|
committer | Max Kellermann <max@duempel.org> | 2014-02-05 17:25:47 +0100 |
commit | 855f26c43d0a9346e6670f09325f1e2b4d354757 (patch) | |
tree | 7543bbc8b3ab1991b8cb28995c075558f239ff50 /src/mixer | |
parent | f86e15953621901c468bfc2a1140c854a91b5a16 (diff) | |
download | mpd-855f26c43d0a9346e6670f09325f1e2b4d354757.tar.gz mpd-855f26c43d0a9346e6670f09325f1e2b4d354757.tar.xz mpd-855f26c43d0a9346e6670f09325f1e2b4d354757.zip |
Mixer: use reference instead of pointer for MixerPlugin
Diffstat (limited to 'src/mixer')
-rw-r--r-- | src/mixer/MixerAll.cxx | 2 | ||||
-rw-r--r-- | src/mixer/MixerControl.cxx | 34 | ||||
-rw-r--r-- | src/mixer/MixerControl.hxx | 2 | ||||
-rw-r--r-- | src/mixer/MixerInternal.hxx | 6 |
4 files changed, 18 insertions, 26 deletions
diff --git a/src/mixer/MixerAll.cxx b/src/mixer/MixerAll.cxx index ac40bc496..5fef6a92f 100644 --- a/src/mixer/MixerAll.cxx +++ b/src/mixer/MixerAll.cxx @@ -149,7 +149,7 @@ MultipleOutputs::SetSoftwareVolume(unsigned volume) const auto mixer = ao->mixer; if (mixer != nullptr && - mixer->plugin == &software_mixer_plugin) + &mixer->plugin == &software_mixer_plugin) mixer_set_volume(mixer, volume, IgnoreError()); } } diff --git a/src/mixer/MixerControl.cxx b/src/mixer/MixerControl.cxx index 2e4b5093a..2c030cdfd 100644 --- a/src/mixer/MixerControl.cxx +++ b/src/mixer/MixerControl.cxx @@ -26,17 +26,13 @@ Mixer * mixer_new(EventLoop &event_loop, - const MixerPlugin *plugin, void *ao, + const MixerPlugin &plugin, void *ao, const config_param ¶m, Error &error) { - Mixer *mixer; + Mixer *mixer = plugin.init(event_loop, ao, param, error); - assert(plugin != nullptr); - - mixer = plugin->init(event_loop, ao, param, error); - - assert(mixer == nullptr || mixer->IsPlugin(*plugin)); + assert(mixer == nullptr || mixer->IsPlugin(plugin)); return mixer; } @@ -45,13 +41,12 @@ void mixer_free(Mixer *mixer) { assert(mixer != nullptr); - assert(mixer->plugin != nullptr); /* mixers with the "global" flag set might still be open at this point (see mixer_auto_close()) */ mixer_close(mixer); - mixer->plugin->finish(mixer); + mixer->plugin.finish(mixer); } bool @@ -60,16 +55,15 @@ mixer_open(Mixer *mixer, Error &error) bool success; assert(mixer != nullptr); - assert(mixer->plugin != nullptr); const ScopeLock protect(mixer->mutex); if (mixer->open) success = true; - else if (mixer->plugin->open == nullptr) + else if (mixer->plugin.open == nullptr) success = mixer->open = true; else - success = mixer->open = mixer->plugin->open(mixer, error); + success = mixer->open = mixer->plugin.open(mixer, error); mixer->failed = !success; @@ -80,11 +74,10 @@ static void mixer_close_internal(Mixer *mixer) { assert(mixer != nullptr); - assert(mixer->plugin != nullptr); assert(mixer->open); - if (mixer->plugin->close != nullptr) - mixer->plugin->close(mixer); + if (mixer->plugin.close != nullptr) + mixer->plugin.close(mixer); mixer->open = false; } @@ -93,7 +86,6 @@ void mixer_close(Mixer *mixer) { assert(mixer != nullptr); - assert(mixer->plugin != nullptr); const ScopeLock protect(mixer->mutex); @@ -104,7 +96,7 @@ mixer_close(Mixer *mixer) void mixer_auto_close(Mixer *mixer) { - if (!mixer->plugin->global) + if (!mixer->plugin.global) mixer_close(mixer); } @@ -129,14 +121,14 @@ mixer_get_volume(Mixer *mixer, Error &error) assert(mixer != nullptr); - if (mixer->plugin->global && !mixer->failed && + if (mixer->plugin.global && !mixer->failed && !mixer_open(mixer, error)) return -1; const ScopeLock protect(mixer->mutex); if (mixer->open) { - volume = mixer->plugin->get_volume(mixer, error); + volume = mixer->plugin.get_volume(mixer, error); if (volume < 0 && error.IsDefined()) mixer_failed(mixer); } else @@ -151,12 +143,12 @@ mixer_set_volume(Mixer *mixer, unsigned volume, Error &error) assert(mixer != nullptr); assert(volume <= 100); - if (mixer->plugin->global && !mixer->failed && + if (mixer->plugin.global && !mixer->failed && !mixer_open(mixer, error)) return false; const ScopeLock protect(mixer->mutex); return mixer->open && - mixer->plugin->set_volume(mixer, volume, error); + mixer->plugin.set_volume(mixer, volume, error); } diff --git a/src/mixer/MixerControl.hxx b/src/mixer/MixerControl.hxx index 8be4e9f63..cc2ccc087 100644 --- a/src/mixer/MixerControl.hxx +++ b/src/mixer/MixerControl.hxx @@ -32,7 +32,7 @@ struct MixerPlugin; struct config_param; Mixer * -mixer_new(EventLoop &event_loop, const MixerPlugin *plugin, void *ao, +mixer_new(EventLoop &event_loop, const MixerPlugin &plugin, void *ao, const config_param ¶m, Error &error); diff --git a/src/mixer/MixerInternal.hxx b/src/mixer/MixerInternal.hxx index 108293740..1524af7f2 100644 --- a/src/mixer/MixerInternal.hxx +++ b/src/mixer/MixerInternal.hxx @@ -26,7 +26,7 @@ class Mixer { public: - const MixerPlugin *plugin; + const MixerPlugin &plugin; /** * This mutex protects all of the mixer struct, including its @@ -47,12 +47,12 @@ public: public: Mixer(const MixerPlugin &_plugin) - :plugin(&_plugin), + :plugin(_plugin), open(false), failed(false) {} bool IsPlugin(const MixerPlugin &other) const { - return plugin == &other; + return &plugin == &other; } }; |