diff --git a/src/output/Control.cxx b/src/output/Control.cxx index 6cdebeb41..e87f46113 100644 --- a/src/output/Control.cxx +++ b/src/output/Control.cxx @@ -38,8 +38,9 @@ static constexpr PeriodClock::Duration REOPEN_AFTER = std::chrono::seconds(10); struct notify audio_output_client_notify; -AudioOutputControl::AudioOutputControl(AudioOutput *_output) - :output(_output), +AudioOutputControl::AudioOutputControl(AudioOutput *_output, + AudioOutputClient &_client) + :output(_output), client(_client), thread(BIND_THIS_METHOD(Task)), mutex(output->mutex) { @@ -59,12 +60,6 @@ AudioOutputControl::GetName() const noexcept return output->GetName(); } -AudioOutputClient & -AudioOutputControl::GetClient() noexcept -{ - return *output->client; -} - Mixer * AudioOutputControl::GetMixer() const noexcept { diff --git a/src/output/Control.hxx b/src/output/Control.hxx index cf071e3ac..9ed26b536 100644 --- a/src/output/Control.hxx +++ b/src/output/Control.hxx @@ -50,6 +50,12 @@ class AudioOutputClient; class AudioOutputControl { AudioOutput *output; + /** + * The PlayerControl object which "owns" this output. This + * object is needed to signal command completion. + */ + AudioOutputClient &client; + /** * The error that occurred in the output thread. It is * cleared whenever the output is opened successfully. @@ -164,7 +170,7 @@ class AudioOutputControl { public: Mutex &mutex; - explicit AudioOutputControl(AudioOutput *_output); + AudioOutputControl(AudioOutput *_output, AudioOutputClient &_client); #ifndef NDEBUG ~AudioOutputControl() { @@ -185,7 +191,9 @@ public: gcc_pure const char *GetName() const noexcept; - AudioOutputClient &GetClient() noexcept; + AudioOutputClient &GetClient() noexcept { + return client; + } gcc_pure Mixer *GetMixer() const noexcept; diff --git a/src/output/Init.cxx b/src/output/Init.cxx index 128a8b4c2..b3ff68a1b 100644 --- a/src/output/Init.cxx +++ b/src/output/Init.cxx @@ -265,8 +265,7 @@ AudioOutput * audio_output_new(EventLoop &event_loop, const ReplayGainConfig &replay_gain_config, const ConfigBlock &block, - MixerListener &mixer_listener, - AudioOutputClient &client) + MixerListener &mixer_listener) { const AudioOutputPlugin *plugin; @@ -302,6 +301,5 @@ audio_output_new(EventLoop &event_loop, throw; } - ao->client = &client; return ao; } diff --git a/src/output/Internal.hxx b/src/output/Internal.hxx index 8166f00c8..842e16db7 100644 --- a/src/output/Internal.hxx +++ b/src/output/Internal.hxx @@ -30,7 +30,6 @@ class MusicPipe; class EventLoop; class Mixer; class MixerListener; -class AudioOutputClient; struct MusicChunk; struct ConfigBlock; struct AudioOutputPlugin; @@ -135,12 +134,6 @@ struct AudioOutput { */ mutable Mutex mutex; - /** - * The PlayerControl object which "owns" this output. This - * object is needed to signal command completion. - */ - AudioOutputClient *client; - /** * Source of audio data. */ @@ -258,8 +251,7 @@ AudioOutput * audio_output_new(EventLoop &event_loop, const ReplayGainConfig &replay_gain_config, const ConfigBlock &block, - MixerListener &mixer_listener, - AudioOutputClient &client); + MixerListener &mixer_listener); void audio_output_free(AudioOutput *ao) noexcept; diff --git a/src/output/MultipleOutputs.cxx b/src/output/MultipleOutputs.cxx index 986510f7f..0be03f14c 100644 --- a/src/output/MultipleOutputs.cxx +++ b/src/output/MultipleOutputs.cxx @@ -53,11 +53,10 @@ static AudioOutput * LoadOutput(EventLoop &event_loop, const ReplayGainConfig &replay_gain_config, MixerListener &mixer_listener, - AudioOutputClient &client, const ConfigBlock &block) + const ConfigBlock &block) try { return audio_output_new(event_loop, replay_gain_config, block, - mixer_listener, - client); + mixer_listener); } catch (const std::runtime_error &e) { if (block.line > 0) std::throw_with_nested(FormatRuntimeError("Failed to configure output in line %i", @@ -74,8 +73,8 @@ LoadOutputControl(EventLoop &event_loop, { auto *output = LoadOutput(event_loop, replay_gain_config, mixer_listener, - client, block); - auto *control = new AudioOutputControl(output); + block); + auto *control = new AudioOutputControl(output, client); try { control->Configure(block); diff --git a/src/output/Thread.cxx b/src/output/Thread.cxx index c9530b7ee..918d94b63 100644 --- a/src/output/Thread.cxx +++ b/src/output/Thread.cxx @@ -365,7 +365,7 @@ AudioOutputControl::Play() noexcept give it a chance to refill the pipe before it runs empty */ const ScopeUnlock unlock(mutex); - output->client->ChunksConsumed(); + client.ChunksConsumed(); n = 0; } @@ -374,7 +374,7 @@ AudioOutputControl::Play() noexcept } while (FillSourceOrClose()); const ScopeUnlock unlock(mutex); - output->client->ChunksConsumed(); + client.ChunksConsumed(); return true; } diff --git a/test/run_output.cxx b/test/run_output.cxx index ce926714b..ba772e6b2 100644 --- a/test/run_output.cxx +++ b/test/run_output.cxx @@ -20,7 +20,6 @@ #include "config.h" #include "output/Internal.hxx" #include "output/OutputPlugin.hxx" -#include "output/Client.hxx" #include "config/Param.hxx" #include "config/ConfigGlobal.hxx" #include "config/ConfigOption.hxx" @@ -43,16 +42,6 @@ #include #include -class DummyAudioOutputClient final : public AudioOutputClient { -public: - /* virtual methods from AudioOutputClient */ - void ChunksConsumed() override { - } - - void ApplyEnabled() override { - } -}; - const FilterPlugin * filter_plugin_by_name(gcc_unused const char *name) noexcept { @@ -61,8 +50,7 @@ filter_plugin_by_name(gcc_unused const char *name) noexcept } static AudioOutput * -load_audio_output(EventLoop &event_loop, AudioOutputClient &client, - const char *name) +load_audio_output(EventLoop &event_loop, const char *name) { const auto *param = config_find_block(ConfigBlockOption::AUDIO_OUTPUT, "name", name); @@ -71,8 +59,7 @@ load_audio_output(EventLoop &event_loop, AudioOutputClient &client, name); return audio_output_new(event_loop, ReplayGainConfig(), *param, - *(MixerListener *)nullptr, - client); + *(MixerListener *)nullptr); } static void @@ -140,9 +127,7 @@ try { /* initialize the audio output */ - DummyAudioOutputClient client; - AudioOutput *ao = load_audio_output(io_thread.GetEventLoop(), client, - argv[2]); + AudioOutput *ao = load_audio_output(io_thread.GetEventLoop(), argv[2]); /* parse the audio format */