From 9c9a9ccd5c3ee3c8a43ff3a5ff84ca645800263f Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Wed, 9 Aug 2017 16:58:59 +0200 Subject: [PATCH] output/Interface: convert to class, make attributes private --- src/output/Filtered.cxx | 6 +++--- src/output/Filtered.hxx | 2 +- src/output/Init.cxx | 8 ++++---- src/output/Interface.hxx | 11 ++++++++++- src/output/OutputPlugin.cxx | 34 +++++++++++++++++----------------- src/output/OutputPlugin.hxx | 2 +- 6 files changed, 36 insertions(+), 27 deletions(-) diff --git a/src/output/Filtered.cxx b/src/output/Filtered.cxx index 13056bc9c..723f55655 100644 --- a/src/output/Filtered.cxx +++ b/src/output/Filtered.cxx @@ -32,15 +32,15 @@ bool FilteredAudioOutput::SupportsEnableDisable() const noexcept { - assert((output->plugin.enable == nullptr) == (output->plugin.disable == nullptr)); + assert((output->GetPlugin().enable == nullptr) == (output->GetPlugin().disable == nullptr)); - return output->plugin.enable != nullptr; + return output->GetPlugin().enable != nullptr; } bool FilteredAudioOutput::SupportsPause() const noexcept { - return output->plugin.pause != nullptr; + return output->GetPlugin().pause != nullptr; } void diff --git a/src/output/Filtered.hxx b/src/output/Filtered.hxx index 937ad9c75..9717c484c 100644 --- a/src/output/Filtered.hxx +++ b/src/output/Filtered.hxx @@ -33,7 +33,7 @@ class Mixer; class MixerListener; struct MusicChunk; struct ConfigBlock; -struct AudioOutput; +class AudioOutput; struct ReplayGainConfig; struct Tag; diff --git a/src/output/Init.cxx b/src/output/Init.cxx index 5d1b58574..fb66b4a5d 100644 --- a/src/output/Init.cxx +++ b/src/output/Init.cxx @@ -55,7 +55,7 @@ FilteredAudioOutput::FilteredAudioOutput(AudioOutput &_output, :output(&_output) { #ifndef NDEBUG - const auto &plugin = output->plugin; + const auto &plugin = output->GetPlugin(); assert(plugin.finish != nullptr); assert(plugin.open != nullptr); assert(plugin.close != nullptr); @@ -172,7 +172,7 @@ FilteredAudioOutput::Configure(const ConfigBlock &block) { char buffer[64]; snprintf(buffer, sizeof(buffer), "\"%s\" (%s)", - name, output->plugin.name); + name, output->GetPlugin().name); log_name = buffer; } @@ -207,7 +207,7 @@ FilteredAudioOutput::Setup(EventLoop &event_loop, MixerListener &mixer_listener, const ConfigBlock &block) { - if (output->need_fully_defined_audio_format && + if (output->GetNeedFullyDefinedAudioFormat() && !config_audio_format.IsFullyDefined()) throw std::runtime_error("Need full audio format specification"); @@ -233,7 +233,7 @@ FilteredAudioOutput::Setup(EventLoop &event_loop, try { mixer = audio_output_load_mixer(event_loop, *this, block, - output->plugin.mixer_plugin, + output->GetPlugin().mixer_plugin, *prepared_filter, mixer_listener); } catch (const std::runtime_error &e) { diff --git a/src/output/Interface.hxx b/src/output/Interface.hxx index 106b4b26d..645a94b2e 100644 --- a/src/output/Interface.hxx +++ b/src/output/Interface.hxx @@ -22,7 +22,7 @@ struct AudioOutputPlugin; -struct AudioOutput { +class AudioOutput { /** * The plugin which implements this output device. */ @@ -30,9 +30,18 @@ struct AudioOutput { bool need_fully_defined_audio_format = false; +public: AudioOutput(const AudioOutputPlugin &_plugin) :plugin(_plugin) {} + const AudioOutputPlugin &GetPlugin() const { + return plugin; + } + + bool GetNeedFullyDefinedAudioFormat() const { + return need_fully_defined_audio_format; + } + /** * Plugins shall call this method if they require an * "audio_format" setting which evaluates diff --git a/src/output/OutputPlugin.cxx b/src/output/OutputPlugin.cxx index 52ce3c3d2..e0a42e7e5 100644 --- a/src/output/OutputPlugin.cxx +++ b/src/output/OutputPlugin.cxx @@ -36,72 +36,72 @@ ao_plugin_init(EventLoop &event_loop, void ao_plugin_finish(AudioOutput *ao) noexcept { - ao->plugin.finish(ao); + ao->GetPlugin().finish(ao); } void ao_plugin_enable(AudioOutput &ao) { - if (ao.plugin.enable != nullptr) - ao.plugin.enable(&ao); + if (ao.GetPlugin().enable != nullptr) + ao.GetPlugin().enable(&ao); } void ao_plugin_disable(AudioOutput &ao) noexcept { - if (ao.plugin.disable != nullptr) - ao.plugin.disable(&ao); + if (ao.GetPlugin().disable != nullptr) + ao.GetPlugin().disable(&ao); } void ao_plugin_open(AudioOutput &ao, AudioFormat &audio_format) { - ao.plugin.open(&ao, audio_format); + ao.GetPlugin().open(&ao, audio_format); } void ao_plugin_close(AudioOutput &ao) noexcept { - ao.plugin.close(&ao); + ao.GetPlugin().close(&ao); } std::chrono::steady_clock::duration ao_plugin_delay(AudioOutput &ao) noexcept { - return ao.plugin.delay != nullptr - ? ao.plugin.delay(&ao) + return ao.GetPlugin().delay != nullptr + ? ao.GetPlugin().delay(&ao) : std::chrono::steady_clock::duration::zero(); } void ao_plugin_send_tag(AudioOutput &ao, const Tag &tag) { - if (ao.plugin.send_tag != nullptr) - ao.plugin.send_tag(&ao, tag); + if (ao.GetPlugin().send_tag != nullptr) + ao.GetPlugin().send_tag(&ao, tag); } size_t ao_plugin_play(AudioOutput &ao, const void *chunk, size_t size) { - return ao.plugin.play(&ao, chunk, size); + return ao.GetPlugin().play(&ao, chunk, size); } void ao_plugin_drain(AudioOutput &ao) { - if (ao.plugin.drain != nullptr) - ao.plugin.drain(&ao); + if (ao.GetPlugin().drain != nullptr) + ao.GetPlugin().drain(&ao); } void ao_plugin_cancel(AudioOutput &ao) noexcept { - if (ao.plugin.cancel != nullptr) - ao.plugin.cancel(&ao); + if (ao.GetPlugin().cancel != nullptr) + ao.GetPlugin().cancel(&ao); } bool ao_plugin_pause(AudioOutput &ao) { - return ao.plugin.pause != nullptr && ao.plugin.pause(&ao); + return ao.GetPlugin().pause != nullptr && ao.GetPlugin().pause(&ao); } diff --git a/src/output/OutputPlugin.hxx b/src/output/OutputPlugin.hxx index 5ce52e15c..254f783fe 100644 --- a/src/output/OutputPlugin.hxx +++ b/src/output/OutputPlugin.hxx @@ -29,7 +29,7 @@ struct ConfigBlock; struct AudioFormat; struct Tag; -struct AudioOutput; +class AudioOutput; struct MixerPlugin; class EventLoop;