output/Internal: move "client" to struct AudioOutputControl

This commit is contained in:
Max Kellermann 2017-05-23 00:31:13 +02:00
parent 194f733ca7
commit ebecee3d85
7 changed files with 24 additions and 47 deletions

View File

@ -38,8 +38,9 @@ static constexpr PeriodClock::Duration REOPEN_AFTER = std::chrono::seconds(10);
struct notify audio_output_client_notify; struct notify audio_output_client_notify;
AudioOutputControl::AudioOutputControl(AudioOutput *_output) AudioOutputControl::AudioOutputControl(AudioOutput *_output,
:output(_output), AudioOutputClient &_client)
:output(_output), client(_client),
thread(BIND_THIS_METHOD(Task)), thread(BIND_THIS_METHOD(Task)),
mutex(output->mutex) mutex(output->mutex)
{ {
@ -59,12 +60,6 @@ AudioOutputControl::GetName() const noexcept
return output->GetName(); return output->GetName();
} }
AudioOutputClient &
AudioOutputControl::GetClient() noexcept
{
return *output->client;
}
Mixer * Mixer *
AudioOutputControl::GetMixer() const noexcept AudioOutputControl::GetMixer() const noexcept
{ {

View File

@ -50,6 +50,12 @@ class AudioOutputClient;
class AudioOutputControl { class AudioOutputControl {
AudioOutput *output; 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 * The error that occurred in the output thread. It is
* cleared whenever the output is opened successfully. * cleared whenever the output is opened successfully.
@ -164,7 +170,7 @@ class AudioOutputControl {
public: public:
Mutex &mutex; Mutex &mutex;
explicit AudioOutputControl(AudioOutput *_output); AudioOutputControl(AudioOutput *_output, AudioOutputClient &_client);
#ifndef NDEBUG #ifndef NDEBUG
~AudioOutputControl() { ~AudioOutputControl() {
@ -185,7 +191,9 @@ public:
gcc_pure gcc_pure
const char *GetName() const noexcept; const char *GetName() const noexcept;
AudioOutputClient &GetClient() noexcept; AudioOutputClient &GetClient() noexcept {
return client;
}
gcc_pure gcc_pure
Mixer *GetMixer() const noexcept; Mixer *GetMixer() const noexcept;

View File

@ -265,8 +265,7 @@ AudioOutput *
audio_output_new(EventLoop &event_loop, audio_output_new(EventLoop &event_loop,
const ReplayGainConfig &replay_gain_config, const ReplayGainConfig &replay_gain_config,
const ConfigBlock &block, const ConfigBlock &block,
MixerListener &mixer_listener, MixerListener &mixer_listener)
AudioOutputClient &client)
{ {
const AudioOutputPlugin *plugin; const AudioOutputPlugin *plugin;
@ -302,6 +301,5 @@ audio_output_new(EventLoop &event_loop,
throw; throw;
} }
ao->client = &client;
return ao; return ao;
} }

View File

@ -30,7 +30,6 @@ class MusicPipe;
class EventLoop; class EventLoop;
class Mixer; class Mixer;
class MixerListener; class MixerListener;
class AudioOutputClient;
struct MusicChunk; struct MusicChunk;
struct ConfigBlock; struct ConfigBlock;
struct AudioOutputPlugin; struct AudioOutputPlugin;
@ -135,12 +134,6 @@ struct AudioOutput {
*/ */
mutable Mutex mutex; mutable Mutex mutex;
/**
* The PlayerControl object which "owns" this output. This
* object is needed to signal command completion.
*/
AudioOutputClient *client;
/** /**
* Source of audio data. * Source of audio data.
*/ */
@ -258,8 +251,7 @@ AudioOutput *
audio_output_new(EventLoop &event_loop, audio_output_new(EventLoop &event_loop,
const ReplayGainConfig &replay_gain_config, const ReplayGainConfig &replay_gain_config,
const ConfigBlock &block, const ConfigBlock &block,
MixerListener &mixer_listener, MixerListener &mixer_listener);
AudioOutputClient &client);
void void
audio_output_free(AudioOutput *ao) noexcept; audio_output_free(AudioOutput *ao) noexcept;

View File

@ -53,11 +53,10 @@ static AudioOutput *
LoadOutput(EventLoop &event_loop, LoadOutput(EventLoop &event_loop,
const ReplayGainConfig &replay_gain_config, const ReplayGainConfig &replay_gain_config,
MixerListener &mixer_listener, MixerListener &mixer_listener,
AudioOutputClient &client, const ConfigBlock &block) const ConfigBlock &block)
try { try {
return audio_output_new(event_loop, replay_gain_config, block, return audio_output_new(event_loop, replay_gain_config, block,
mixer_listener, mixer_listener);
client);
} catch (const std::runtime_error &e) { } catch (const std::runtime_error &e) {
if (block.line > 0) if (block.line > 0)
std::throw_with_nested(FormatRuntimeError("Failed to configure output in line %i", 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, auto *output = LoadOutput(event_loop, replay_gain_config,
mixer_listener, mixer_listener,
client, block); block);
auto *control = new AudioOutputControl(output); auto *control = new AudioOutputControl(output, client);
try { try {
control->Configure(block); control->Configure(block);

View File

@ -365,7 +365,7 @@ AudioOutputControl::Play() noexcept
give it a chance to refill the pipe before give it a chance to refill the pipe before
it runs empty */ it runs empty */
const ScopeUnlock unlock(mutex); const ScopeUnlock unlock(mutex);
output->client->ChunksConsumed(); client.ChunksConsumed();
n = 0; n = 0;
} }
@ -374,7 +374,7 @@ AudioOutputControl::Play() noexcept
} while (FillSourceOrClose()); } while (FillSourceOrClose());
const ScopeUnlock unlock(mutex); const ScopeUnlock unlock(mutex);
output->client->ChunksConsumed(); client.ChunksConsumed();
return true; return true;
} }

View File

@ -20,7 +20,6 @@
#include "config.h" #include "config.h"
#include "output/Internal.hxx" #include "output/Internal.hxx"
#include "output/OutputPlugin.hxx" #include "output/OutputPlugin.hxx"
#include "output/Client.hxx"
#include "config/Param.hxx" #include "config/Param.hxx"
#include "config/ConfigGlobal.hxx" #include "config/ConfigGlobal.hxx"
#include "config/ConfigOption.hxx" #include "config/ConfigOption.hxx"
@ -43,16 +42,6 @@
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h> #include <stdio.h>
class DummyAudioOutputClient final : public AudioOutputClient {
public:
/* virtual methods from AudioOutputClient */
void ChunksConsumed() override {
}
void ApplyEnabled() override {
}
};
const FilterPlugin * const FilterPlugin *
filter_plugin_by_name(gcc_unused const char *name) noexcept 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 * static AudioOutput *
load_audio_output(EventLoop &event_loop, AudioOutputClient &client, load_audio_output(EventLoop &event_loop, const char *name)
const char *name)
{ {
const auto *param = config_find_block(ConfigBlockOption::AUDIO_OUTPUT, const auto *param = config_find_block(ConfigBlockOption::AUDIO_OUTPUT,
"name", name); "name", name);
@ -71,8 +59,7 @@ load_audio_output(EventLoop &event_loop, AudioOutputClient &client,
name); name);
return audio_output_new(event_loop, ReplayGainConfig(), *param, return audio_output_new(event_loop, ReplayGainConfig(), *param,
*(MixerListener *)nullptr, *(MixerListener *)nullptr);
client);
} }
static void static void
@ -140,9 +127,7 @@ try {
/* initialize the audio output */ /* initialize the audio output */
DummyAudioOutputClient client; AudioOutput *ao = load_audio_output(io_thread.GetEventLoop(), argv[2]);
AudioOutput *ao = load_audio_output(io_thread.GetEventLoop(), client,
argv[2]);
/* parse the audio format */ /* parse the audio format */