Commit cb7366f4 authored by Max Kellermann's avatar Max Kellermann

AudioOutput: make "plugin" a reference

parent bf803e24
......@@ -47,7 +47,7 @@
#define AUDIO_FILTERS "filters"
AudioOutput::AudioOutput(const AudioOutputPlugin &_plugin)
:plugin(&_plugin),
:plugin(_plugin),
enabled(true), really_enabled(false),
open(false),
pause(false),
......@@ -59,10 +59,10 @@ AudioOutput::AudioOutput(const AudioOutputPlugin &_plugin)
other_replay_gain_filter(nullptr),
command(AO_COMMAND_NONE)
{
assert(plugin->finish != nullptr);
assert(plugin->open != nullptr);
assert(plugin->close != nullptr);
assert(plugin->play != nullptr);
assert(plugin.finish != nullptr);
assert(plugin.open != nullptr);
assert(plugin.close != nullptr);
assert(plugin.play != nullptr);
}
static const AudioOutputPlugin *
......@@ -245,7 +245,7 @@ audio_output_setup(AudioOutput *ao, const config_param &param,
Error mixer_error;
ao->mixer = audio_output_load_mixer(ao, param,
ao->plugin->mixer_plugin,
ao->plugin.mixer_plugin,
*ao->filter, mixer_error);
if (ao->mixer == nullptr && mixer_error.IsDefined())
FormatError(mixer_error,
......
......@@ -69,7 +69,7 @@ struct AudioOutput {
/**
* The plugin which implements this output device.
*/
const AudioOutputPlugin *const plugin;
const AudioOutputPlugin &plugin;
/**
* The #mixer object associated with this audio output device.
......
......@@ -104,7 +104,7 @@ void
audio_output_enable(AudioOutput *ao)
{
if (!ao->thread.IsDefined()) {
if (ao->plugin->enable == nullptr) {
if (ao->plugin.enable == nullptr) {
/* don't bother to start the thread now if the
device doesn't even have a enable() method;
just assign the variable and we're done */
......@@ -122,7 +122,7 @@ void
audio_output_disable(AudioOutput *ao)
{
if (!ao->thread.IsDefined()) {
if (ao->plugin->disable == nullptr)
if (ao->plugin.disable == nullptr)
ao->really_enabled = false;
else
/* if there's no thread yet, the device cannot
......@@ -248,7 +248,7 @@ audio_output_play(AudioOutput *ao)
void audio_output_pause(AudioOutput *ao)
{
if (ao->mixer != nullptr && ao->plugin->pause == nullptr)
if (ao->mixer != nullptr && ao->plugin.pause == nullptr)
/* the device has no pause mode: close the mixer,
unless its "global" flag is set (checked by
mixer_auto_close()) */
......
......@@ -35,75 +35,75 @@ ao_plugin_init(const AudioOutputPlugin *plugin,
void
ao_plugin_finish(AudioOutput *ao)
{
ao->plugin->finish(ao);
ao->plugin.finish(ao);
}
bool
ao_plugin_enable(AudioOutput *ao, Error &error_r)
{
return ao->plugin->enable != nullptr
? ao->plugin->enable(ao, error_r)
return ao->plugin.enable != nullptr
? ao->plugin.enable(ao, error_r)
: true;
}
void
ao_plugin_disable(AudioOutput *ao)
{
if (ao->plugin->disable != nullptr)
ao->plugin->disable(ao);
if (ao->plugin.disable != nullptr)
ao->plugin.disable(ao);
}
bool
ao_plugin_open(AudioOutput *ao, AudioFormat &audio_format,
Error &error)
{
return ao->plugin->open(ao, audio_format, error);
return ao->plugin.open(ao, audio_format, error);
}
void
ao_plugin_close(AudioOutput *ao)
{
ao->plugin->close(ao);
ao->plugin.close(ao);
}
unsigned
ao_plugin_delay(AudioOutput *ao)
{
return ao->plugin->delay != nullptr
? ao->plugin->delay(ao)
return ao->plugin.delay != nullptr
? ao->plugin.delay(ao)
: 0;
}
void
ao_plugin_send_tag(AudioOutput *ao, const Tag *tag)
{
if (ao->plugin->send_tag != nullptr)
ao->plugin->send_tag(ao, tag);
if (ao->plugin.send_tag != nullptr)
ao->plugin.send_tag(ao, tag);
}
size_t
ao_plugin_play(AudioOutput *ao, const void *chunk, size_t size,
Error &error)
{
return ao->plugin->play(ao, chunk, size, error);
return ao->plugin.play(ao, chunk, size, error);
}
void
ao_plugin_drain(AudioOutput *ao)
{
if (ao->plugin->drain != nullptr)
ao->plugin->drain(ao);
if (ao->plugin.drain != nullptr)
ao->plugin.drain(ao);
}
void
ao_plugin_cancel(AudioOutput *ao)
{
if (ao->plugin->cancel != nullptr)
ao->plugin->cancel(ao);
if (ao->plugin.cancel != nullptr)
ao->plugin.cancel(ao);
}
bool
ao_plugin_pause(AudioOutput *ao)
{
return ao->plugin->pause != nullptr && ao->plugin->pause(ao);
return ao->plugin.pause != nullptr && ao->plugin.pause(ao);
}
......@@ -65,7 +65,7 @@ ao_enable(AudioOutput *ao)
if (!success) {
FormatError(error,
"Failed to enable \"%s\" [%s]",
ao->name, ao->plugin->name);
ao->name, ao->plugin.name);
return false;
}
......@@ -157,7 +157,7 @@ ao_open(AudioOutput *ao)
ao_filter_open(ao, ao->in_audio_format, error);
if (!filter_audio_format.IsDefined()) {
FormatError(error, "Failed to open filter for \"%s\" [%s]",
ao->name, ao->plugin->name);
ao->name, ao->plugin.name);
ao->fail_timer.Update();
return;
......@@ -176,7 +176,7 @@ ao_open(AudioOutput *ao)
if (!success) {
FormatError(error, "Failed to open \"%s\" [%s]",
ao->name, ao->plugin->name);
ao->name, ao->plugin.name);
ao_filter_close(ao);
ao->fail_timer.Update();
......@@ -186,7 +186,7 @@ ao_open(AudioOutput *ao)
if (!convert_filter_set(ao->convert_filter, ao->out_audio_format,
error)) {
FormatError(error, "Failed to convert for \"%s\" [%s]",
ao->name, ao->plugin->name);
ao->name, ao->plugin.name);
ao_filter_close(ao);
ao->fail_timer.Update();
......@@ -197,7 +197,7 @@ ao_open(AudioOutput *ao)
FormatDebug(output_domain,
"opened plugin=%s name=\"%s\" audio_format=%s",
ao->plugin->name, ao->name,
ao->plugin.name, ao->name,
audio_format_to_string(ao->out_audio_format, &af_string));
if (ao->in_audio_format != ao->out_audio_format)
......@@ -229,7 +229,7 @@ ao_close(AudioOutput *ao, bool drain)
ao->mutex.lock();
FormatDebug(output_domain, "closed plugin=%s name=\"%s\"",
ao->plugin->name, ao->name);
ao->plugin.name, ao->name);
}
static void
......@@ -245,7 +245,7 @@ ao_reopen_filter(AudioOutput *ao)
error)) {
FormatError(error,
"Failed to open filter for \"%s\" [%s]",
ao->name, ao->plugin->name);
ao->name, ao->plugin.name);
/* this is a little code duplication fro ao_close(),
but we cannot call this function because we must
......@@ -342,7 +342,7 @@ ao_chunk_data(AudioOutput *ao, const struct music_chunk *chunk,
&length, error);
if (data == nullptr) {
FormatError(error, "\"%s\" [%s] failed to filter",
ao->name, ao->plugin->name);
ao->name, ao->plugin.name);
return nullptr;
}
}
......@@ -413,7 +413,7 @@ ao_filter_chunk(AudioOutput *ao, const struct music_chunk *chunk,
data = ao->filter->FilterPCM(data, length, &length, error);
if (data == nullptr) {
FormatError(error, "\"%s\" [%s] failed to filter",
ao->name, ao->plugin->name);
ao->name, ao->plugin.name);
return nullptr;
}
......@@ -462,7 +462,7 @@ ao_play_chunk(AudioOutput *ao, const struct music_chunk *chunk)
if (nbytes == 0) {
/* play()==0 means failure */
FormatError(error, "\"%s\" [%s] failed to play",
ao->name, ao->plugin->name);
ao->name, ao->plugin.name);
ao_close(ao, false);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment