AudioOutput: make "plugin" a reference

This commit is contained in:
Max Kellermann 2014-01-29 00:53:49 +01:00
parent bf803e241f
commit cb7366f472
5 changed files with 37 additions and 37 deletions

View File

@ -47,7 +47,7 @@
#define AUDIO_FILTERS "filters" #define AUDIO_FILTERS "filters"
AudioOutput::AudioOutput(const AudioOutputPlugin &_plugin) AudioOutput::AudioOutput(const AudioOutputPlugin &_plugin)
:plugin(&_plugin), :plugin(_plugin),
enabled(true), really_enabled(false), enabled(true), really_enabled(false),
open(false), open(false),
pause(false), pause(false),
@ -59,10 +59,10 @@ AudioOutput::AudioOutput(const AudioOutputPlugin &_plugin)
other_replay_gain_filter(nullptr), other_replay_gain_filter(nullptr),
command(AO_COMMAND_NONE) command(AO_COMMAND_NONE)
{ {
assert(plugin->finish != nullptr); assert(plugin.finish != nullptr);
assert(plugin->open != nullptr); assert(plugin.open != nullptr);
assert(plugin->close != nullptr); assert(plugin.close != nullptr);
assert(plugin->play != nullptr); assert(plugin.play != nullptr);
} }
static const AudioOutputPlugin * static const AudioOutputPlugin *
@ -245,7 +245,7 @@ audio_output_setup(AudioOutput *ao, const config_param &param,
Error mixer_error; Error mixer_error;
ao->mixer = audio_output_load_mixer(ao, param, ao->mixer = audio_output_load_mixer(ao, param,
ao->plugin->mixer_plugin, ao->plugin.mixer_plugin,
*ao->filter, mixer_error); *ao->filter, mixer_error);
if (ao->mixer == nullptr && mixer_error.IsDefined()) if (ao->mixer == nullptr && mixer_error.IsDefined())
FormatError(mixer_error, FormatError(mixer_error,

View File

@ -69,7 +69,7 @@ struct AudioOutput {
/** /**
* The plugin which implements this output device. * The plugin which implements this output device.
*/ */
const AudioOutputPlugin *const plugin; const AudioOutputPlugin &plugin;
/** /**
* The #mixer object associated with this audio output device. * The #mixer object associated with this audio output device.

View File

@ -104,7 +104,7 @@ void
audio_output_enable(AudioOutput *ao) audio_output_enable(AudioOutput *ao)
{ {
if (!ao->thread.IsDefined()) { if (!ao->thread.IsDefined()) {
if (ao->plugin->enable == nullptr) { if (ao->plugin.enable == nullptr) {
/* don't bother to start the thread now if the /* don't bother to start the thread now if the
device doesn't even have a enable() method; device doesn't even have a enable() method;
just assign the variable and we're done */ just assign the variable and we're done */
@ -122,7 +122,7 @@ void
audio_output_disable(AudioOutput *ao) audio_output_disable(AudioOutput *ao)
{ {
if (!ao->thread.IsDefined()) { if (!ao->thread.IsDefined()) {
if (ao->plugin->disable == nullptr) if (ao->plugin.disable == nullptr)
ao->really_enabled = false; ao->really_enabled = false;
else else
/* if there's no thread yet, the device cannot /* if there's no thread yet, the device cannot
@ -248,7 +248,7 @@ audio_output_play(AudioOutput *ao)
void audio_output_pause(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, /* the device has no pause mode: close the mixer,
unless its "global" flag is set (checked by unless its "global" flag is set (checked by
mixer_auto_close()) */ mixer_auto_close()) */

View File

@ -35,75 +35,75 @@ ao_plugin_init(const AudioOutputPlugin *plugin,
void void
ao_plugin_finish(AudioOutput *ao) ao_plugin_finish(AudioOutput *ao)
{ {
ao->plugin->finish(ao); ao->plugin.finish(ao);
} }
bool bool
ao_plugin_enable(AudioOutput *ao, Error &error_r) ao_plugin_enable(AudioOutput *ao, Error &error_r)
{ {
return ao->plugin->enable != nullptr return ao->plugin.enable != nullptr
? ao->plugin->enable(ao, error_r) ? ao->plugin.enable(ao, error_r)
: true; : true;
} }
void void
ao_plugin_disable(AudioOutput *ao) ao_plugin_disable(AudioOutput *ao)
{ {
if (ao->plugin->disable != nullptr) if (ao->plugin.disable != nullptr)
ao->plugin->disable(ao); ao->plugin.disable(ao);
} }
bool bool
ao_plugin_open(AudioOutput *ao, AudioFormat &audio_format, ao_plugin_open(AudioOutput *ao, AudioFormat &audio_format,
Error &error) Error &error)
{ {
return ao->plugin->open(ao, audio_format, error); return ao->plugin.open(ao, audio_format, error);
} }
void void
ao_plugin_close(AudioOutput *ao) ao_plugin_close(AudioOutput *ao)
{ {
ao->plugin->close(ao); ao->plugin.close(ao);
} }
unsigned unsigned
ao_plugin_delay(AudioOutput *ao) ao_plugin_delay(AudioOutput *ao)
{ {
return ao->plugin->delay != nullptr return ao->plugin.delay != nullptr
? ao->plugin->delay(ao) ? ao->plugin.delay(ao)
: 0; : 0;
} }
void void
ao_plugin_send_tag(AudioOutput *ao, const Tag *tag) ao_plugin_send_tag(AudioOutput *ao, const Tag *tag)
{ {
if (ao->plugin->send_tag != nullptr) if (ao->plugin.send_tag != nullptr)
ao->plugin->send_tag(ao, tag); ao->plugin.send_tag(ao, tag);
} }
size_t size_t
ao_plugin_play(AudioOutput *ao, const void *chunk, size_t size, ao_plugin_play(AudioOutput *ao, const void *chunk, size_t size,
Error &error) Error &error)
{ {
return ao->plugin->play(ao, chunk, size, error); return ao->plugin.play(ao, chunk, size, error);
} }
void void
ao_plugin_drain(AudioOutput *ao) ao_plugin_drain(AudioOutput *ao)
{ {
if (ao->plugin->drain != nullptr) if (ao->plugin.drain != nullptr)
ao->plugin->drain(ao); ao->plugin.drain(ao);
} }
void void
ao_plugin_cancel(AudioOutput *ao) ao_plugin_cancel(AudioOutput *ao)
{ {
if (ao->plugin->cancel != nullptr) if (ao->plugin.cancel != nullptr)
ao->plugin->cancel(ao); ao->plugin.cancel(ao);
} }
bool bool
ao_plugin_pause(AudioOutput *ao) ao_plugin_pause(AudioOutput *ao)
{ {
return ao->plugin->pause != nullptr && ao->plugin->pause(ao); return ao->plugin.pause != nullptr && ao->plugin.pause(ao);
} }

View File

@ -65,7 +65,7 @@ ao_enable(AudioOutput *ao)
if (!success) { if (!success) {
FormatError(error, FormatError(error,
"Failed to enable \"%s\" [%s]", "Failed to enable \"%s\" [%s]",
ao->name, ao->plugin->name); ao->name, ao->plugin.name);
return false; return false;
} }
@ -157,7 +157,7 @@ ao_open(AudioOutput *ao)
ao_filter_open(ao, ao->in_audio_format, error); ao_filter_open(ao, ao->in_audio_format, error);
if (!filter_audio_format.IsDefined()) { if (!filter_audio_format.IsDefined()) {
FormatError(error, "Failed to open filter for \"%s\" [%s]", FormatError(error, "Failed to open filter for \"%s\" [%s]",
ao->name, ao->plugin->name); ao->name, ao->plugin.name);
ao->fail_timer.Update(); ao->fail_timer.Update();
return; return;
@ -176,7 +176,7 @@ ao_open(AudioOutput *ao)
if (!success) { if (!success) {
FormatError(error, "Failed to open \"%s\" [%s]", FormatError(error, "Failed to open \"%s\" [%s]",
ao->name, ao->plugin->name); ao->name, ao->plugin.name);
ao_filter_close(ao); ao_filter_close(ao);
ao->fail_timer.Update(); ao->fail_timer.Update();
@ -186,7 +186,7 @@ ao_open(AudioOutput *ao)
if (!convert_filter_set(ao->convert_filter, ao->out_audio_format, if (!convert_filter_set(ao->convert_filter, ao->out_audio_format,
error)) { error)) {
FormatError(error, "Failed to convert for \"%s\" [%s]", FormatError(error, "Failed to convert for \"%s\" [%s]",
ao->name, ao->plugin->name); ao->name, ao->plugin.name);
ao_filter_close(ao); ao_filter_close(ao);
ao->fail_timer.Update(); ao->fail_timer.Update();
@ -197,7 +197,7 @@ ao_open(AudioOutput *ao)
FormatDebug(output_domain, FormatDebug(output_domain,
"opened plugin=%s name=\"%s\" audio_format=%s", "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)); audio_format_to_string(ao->out_audio_format, &af_string));
if (ao->in_audio_format != ao->out_audio_format) if (ao->in_audio_format != ao->out_audio_format)
@ -229,7 +229,7 @@ ao_close(AudioOutput *ao, bool drain)
ao->mutex.lock(); ao->mutex.lock();
FormatDebug(output_domain, "closed plugin=%s name=\"%s\"", FormatDebug(output_domain, "closed plugin=%s name=\"%s\"",
ao->plugin->name, ao->name); ao->plugin.name, ao->name);
} }
static void static void
@ -245,7 +245,7 @@ ao_reopen_filter(AudioOutput *ao)
error)) { error)) {
FormatError(error, FormatError(error,
"Failed to open filter for \"%s\" [%s]", "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(), /* this is a little code duplication fro ao_close(),
but we cannot call this function because we must 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); &length, error);
if (data == nullptr) { if (data == nullptr) {
FormatError(error, "\"%s\" [%s] failed to filter", FormatError(error, "\"%s\" [%s] failed to filter",
ao->name, ao->plugin->name); ao->name, ao->plugin.name);
return nullptr; return nullptr;
} }
} }
@ -413,7 +413,7 @@ ao_filter_chunk(AudioOutput *ao, const struct music_chunk *chunk,
data = ao->filter->FilterPCM(data, length, &length, error); data = ao->filter->FilterPCM(data, length, &length, error);
if (data == nullptr) { if (data == nullptr) {
FormatError(error, "\"%s\" [%s] failed to filter", FormatError(error, "\"%s\" [%s] failed to filter",
ao->name, ao->plugin->name); ao->name, ao->plugin.name);
return nullptr; return nullptr;
} }
@ -462,7 +462,7 @@ ao_play_chunk(AudioOutput *ao, const struct music_chunk *chunk)
if (nbytes == 0) { if (nbytes == 0) {
/* play()==0 means failure */ /* play()==0 means failure */
FormatError(error, "\"%s\" [%s] failed to play", FormatError(error, "\"%s\" [%s] failed to play",
ao->name, ao->plugin->name); ao->name, ao->plugin.name);
ao_close(ao, false); ao_close(ao, false);