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;
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
{

View File

@ -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;

View File

@ -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;
}

View File

@ -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;

View File

@ -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);

View File

@ -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;
}

View File

@ -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 <stdlib.h>
#include <stdio.h>
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 */