output/Plugin: pass EventLoop& to init()

Eliminate dependency on io_thread_get().
This commit is contained in:
Max Kellermann 2017-01-25 09:47:43 +01:00
parent d3f35dab1e
commit 8fd9d91974
24 changed files with 58 additions and 42 deletions

View File

@ -295,7 +295,7 @@ audio_output_new(EventLoop &event_loop,
plugin->name); plugin->name);
} }
AudioOutput *ao = ao_plugin_init(*plugin, block); AudioOutput *ao = ao_plugin_init(event_loop, *plugin, block);
assert(ao != nullptr); assert(ao != nullptr);
try { try {

View File

@ -22,12 +22,13 @@
#include "Internal.hxx" #include "Internal.hxx"
AudioOutput * AudioOutput *
ao_plugin_init(const AudioOutputPlugin &plugin, ao_plugin_init(EventLoop &event_loop,
const AudioOutputPlugin &plugin,
const ConfigBlock &block) const ConfigBlock &block)
{ {
assert(plugin.init != nullptr); assert(plugin.init != nullptr);
return plugin.init(block); return plugin.init(event_loop, block);
} }
void void

View File

@ -31,6 +31,7 @@ struct AudioFormat;
struct Tag; struct Tag;
struct AudioOutput; struct AudioOutput;
struct MixerPlugin; struct MixerPlugin;
class EventLoop;
/** /**
* A plugin which controls an audio output device. * A plugin which controls an audio output device.
@ -56,7 +57,7 @@ struct AudioOutputPlugin {
* @param param the configuration section, or nullptr if there is * @param param the configuration section, or nullptr if there is
* no configuration * no configuration
*/ */
AudioOutput *(*init)(const ConfigBlock &block); AudioOutput *(*init)(EventLoop &event_loop, const ConfigBlock &block);
/** /**
* Free resources allocated by this device. * Free resources allocated by this device.
@ -162,7 +163,8 @@ ao_plugin_test_default_device(const AudioOutputPlugin *plugin)
gcc_malloc gcc_malloc
AudioOutput * AudioOutput *
ao_plugin_init(const AudioOutputPlugin &plugin, ao_plugin_init(EventLoop &event_loop,
const AudioOutputPlugin &plugin,
const ConfigBlock &block); const ConfigBlock &block);
void void

View File

@ -33,8 +33,9 @@ struct AudioOutputWrapper {
return ContainerCast(ao, &T::base); return ContainerCast(ao, &T::base);
} }
static AudioOutput *Init(const ConfigBlock &block) { static AudioOutput *Init(EventLoop &event_loop,
T *t = T::Create(block); const ConfigBlock &block) {
T *t = T::Create(event_loop, block);
return &t->base; return &t->base;
} }

View File

@ -136,7 +136,8 @@ public:
return device.empty() ? default_device : device.c_str(); return device.empty() ? default_device : device.c_str();
} }
static AlsaOutput *Create(const ConfigBlock &block); static AlsaOutput *Create(EventLoop &event_loop,
const ConfigBlock &block);
void Enable(); void Enable();
void Disable(); void Disable();
@ -207,7 +208,7 @@ AlsaOutput::AlsaOutput(const ConfigBlock &block)
} }
inline AlsaOutput * inline AlsaOutput *
AlsaOutput::Create(const ConfigBlock &block) AlsaOutput::Create(EventLoop &, const ConfigBlock &block)
{ {
return new AlsaOutput(block); return new AlsaOutput(block);
} }

View File

@ -51,7 +51,7 @@ class AoOutput {
~AoOutput(); ~AoOutput();
public: public:
static AoOutput *Create(const ConfigBlock &block) { static AoOutput *Create(EventLoop &, const ConfigBlock &block) {
return new AoOutput(block); return new AoOutput(block);
} }

View File

@ -54,7 +54,8 @@ public:
CloseFifo(); CloseFifo();
} }
static FifoOutput *Create(const ConfigBlock &block); static FifoOutput *Create(EventLoop &event_loop,
const ConfigBlock &block);
void Create(); void Create();
void Check(); void Check();
@ -169,7 +170,7 @@ try {
} }
inline FifoOutput * inline FifoOutput *
FifoOutput::Create(const ConfigBlock &block) FifoOutput::Create(EventLoop &, const ConfigBlock &block)
{ {
return new FifoOutput(block); return new FifoOutput(block);
} }

View File

@ -71,7 +71,8 @@ public:
~HaikuOutput(); ~HaikuOutput();
static HaikuOutput *Create(const ConfigBlock &block); static HaikuOutput *Create(EventLoop &event_loop,
const ConfigBlock &block);
void Open(AudioFormat &audio_format); void Open(AudioFormat &audio_format);
void Close(); void Close();
@ -119,7 +120,7 @@ haiku_test_default_device(void)
} }
inline HaikuOutput * inline HaikuOutput *
HaikuOutput::Create(const ConfigBlock &block) HaikuOutput::Create(EventLoop &, const ConfigBlock &block)
{ {
initialize_application(); initialize_application();

View File

@ -444,7 +444,7 @@ JackOutput::Disable()
} }
static AudioOutput * static AudioOutput *
mpd_jack_init(const ConfigBlock &block) mpd_jack_init(EventLoop &, const ConfigBlock &block)
{ {
jack_set_error_function(mpd_jack_error); jack_set_error_function(mpd_jack_error);

View File

@ -37,7 +37,8 @@ public:
:base(null_output_plugin, block), :base(null_output_plugin, block),
sync(block.GetBlockValue("sync", true)) {} sync(block.GetBlockValue("sync", true)) {}
static NullOutput *Create(const ConfigBlock &block); static NullOutput *Create(EventLoop &event_loop,
const ConfigBlock &block);
void Open(AudioFormat &audio_format) { void Open(AudioFormat &audio_format) {
if (sync) if (sync)
@ -72,7 +73,7 @@ public:
}; };
inline NullOutput * inline NullOutput *
NullOutput::Create(const ConfigBlock &block) NullOutput::Create(EventLoop &, const ConfigBlock &block)
{ {
return new NullOutput(block); return new NullOutput(block);
} }

View File

@ -104,7 +104,7 @@ OSXOutput::OSXOutput(const ConfigBlock &block)
} }
static AudioOutput * static AudioOutput *
osx_output_init(const ConfigBlock &block) osx_output_init(EventLoop &, const ConfigBlock &block)
{ {
OSXOutput *oo = new OSXOutput(block); OSXOutput *oo = new OSXOutput(block);

View File

@ -52,7 +52,8 @@ class OpenALOutput {
OpenALOutput(const ConfigBlock &block); OpenALOutput(const ConfigBlock &block);
static OpenALOutput *Create(const ConfigBlock &block); static OpenALOutput *Create(EventLoop &event_loop,
const ConfigBlock &block);
void Open(AudioFormat &audio_format); void Open(AudioFormat &audio_format);
void Close(); void Close();
@ -146,7 +147,7 @@ OpenALOutput::OpenALOutput(const ConfigBlock &block)
} }
inline OpenALOutput * inline OpenALOutput *
OpenALOutput::Create(const ConfigBlock &block) OpenALOutput::Create(EventLoop &, const ConfigBlock &block)
{ {
return new OpenALOutput(block); return new OpenALOutput(block);
} }

View File

@ -89,7 +89,8 @@ public:
:base(oss_output_plugin, block), :base(oss_output_plugin, block),
fd(-1), device(_device) {} fd(-1), device(_device) {}
static OssOutput *Create(const ConfigBlock &block); static OssOutput *Create(EventLoop &event_loop,
const ConfigBlock &block);
#ifdef AFMT_S24_PACKED #ifdef AFMT_S24_PACKED
void Enable() { void Enable() {
@ -226,7 +227,7 @@ oss_open_default()
} }
inline OssOutput * inline OssOutput *
OssOutput::Create(const ConfigBlock &block) OssOutput::Create(EventLoop &, const ConfigBlock &block)
{ {
const char *device = block.GetBlockValue("device"); const char *device = block.GetBlockValue("device");
if (device != nullptr) if (device != nullptr)

View File

@ -39,7 +39,8 @@ class PipeOutput {
PipeOutput(const ConfigBlock &block); PipeOutput(const ConfigBlock &block);
public: public:
static PipeOutput *Create(const ConfigBlock &block); static PipeOutput *Create(EventLoop &event_loop,
const ConfigBlock &block);
void Open(AudioFormat &audio_format); void Open(AudioFormat &audio_format);
@ -59,7 +60,7 @@ PipeOutput::PipeOutput(const ConfigBlock &block)
} }
inline PipeOutput * inline PipeOutput *
PipeOutput::Create(const ConfigBlock &block) PipeOutput::Create(EventLoop &, const ConfigBlock &block)
{ {
return new PipeOutput(block); return new PipeOutput(block);
} }

View File

@ -93,7 +93,8 @@ public:
gcc_const gcc_const
static bool TestDefaultDevice(); static bool TestDefaultDevice();
static PulseOutput *Create(const ConfigBlock &block); static PulseOutput *Create(EventLoop &event_loop,
const ConfigBlock &block);
void Enable(); void Enable();
void Disable(); void Disable();
@ -415,7 +416,7 @@ PulseOutput::SetupContext()
} }
PulseOutput * PulseOutput *
PulseOutput::Create(const ConfigBlock &block) PulseOutput::Create(EventLoop &, const ConfigBlock &block)
{ {
return new PulseOutput(block); return new PulseOutput(block);
} }

View File

@ -81,7 +81,8 @@ class RecorderOutput {
delete prepared_encoder; delete prepared_encoder;
} }
static RecorderOutput *Create(const ConfigBlock &block); static RecorderOutput *Create(EventLoop &event_loop,
const ConfigBlock &block);
void Open(AudioFormat &audio_format); void Open(AudioFormat &audio_format);
void Close(); void Close();
@ -141,7 +142,7 @@ RecorderOutput::RecorderOutput(const ConfigBlock &block)
} }
RecorderOutput * RecorderOutput *
RecorderOutput::Create(const ConfigBlock &block) RecorderOutput::Create(EventLoop &, const ConfigBlock &block)
{ {
return new RecorderOutput(block); return new RecorderOutput(block);
} }

View File

@ -58,7 +58,7 @@ public:
return &base; return &base;
} }
static RoarOutput *Create(const ConfigBlock &block) { static RoarOutput *Create(EventLoop &, const ConfigBlock &block) {
return new RoarOutput(block); return new RoarOutput(block);
} }

View File

@ -58,7 +58,8 @@ struct ShoutOutput final {
explicit ShoutOutput(const ConfigBlock &block); explicit ShoutOutput(const ConfigBlock &block);
~ShoutOutput(); ~ShoutOutput();
static ShoutOutput *Create(const ConfigBlock &block); static ShoutOutput *Create(EventLoop &event_loop,
const ConfigBlock &block);
void Open(AudioFormat &audio_format); void Open(AudioFormat &audio_format);
void Close(); void Close();
@ -246,7 +247,7 @@ ShoutOutput::~ShoutOutput()
} }
ShoutOutput * ShoutOutput *
ShoutOutput::Create(const ConfigBlock &block) ShoutOutput::Create(EventLoop &, const ConfigBlock &block)
{ {
if (shout_init_count == 0) if (shout_init_count == 0)
shout_init(); shout_init();

View File

@ -47,7 +47,8 @@ class SndioOutput {
public: public:
SndioOutput(const ConfigBlock &block); SndioOutput(const ConfigBlock &block);
static SndioOutput *Create(const ConfigBlock &block); static SndioOutput *Create(EventLoop &event_loop,
const ConfigBlock &block);
void Open(AudioFormat &audio_format); void Open(AudioFormat &audio_format);
void Close(); void Close();
@ -64,7 +65,7 @@ SndioOutput::SndioOutput(const ConfigBlock &block)
} }
SndioOutput * SndioOutput *
SndioOutput::Create(const ConfigBlock &block) SndioOutput::Create(EventLoop &, const ConfigBlock &block)
{ {
return new SndioOutput(block); return new SndioOutput(block);
} }

View File

@ -65,7 +65,7 @@ class SolarisOutput {
device(block.GetBlockValue("device", "/dev/audio")) {} device(block.GetBlockValue("device", "/dev/audio")) {}
public: public:
static SolarisOutput *Create(const ConfigBlock &block) { static SolarisOutput *Create(EventLoop &, const ConfigBlock &block) {
return new SolarisOutput(block); return new SolarisOutput(block);
} }

View File

@ -63,7 +63,7 @@ public:
return handle; return handle;
} }
static WinmmOutput *Create(const ConfigBlock &block) { static WinmmOutput *Create(EventLoop &, const ConfigBlock &block) {
return new WinmmOutput(block); return new WinmmOutput(block);
} }

View File

@ -155,7 +155,8 @@ public:
HttpdOutput(EventLoop &_loop, const ConfigBlock &block); HttpdOutput(EventLoop &_loop, const ConfigBlock &block);
~HttpdOutput(); ~HttpdOutput();
static HttpdOutput *Create(const ConfigBlock &block); static HttpdOutput *Create(EventLoop &event_loop,
const ConfigBlock &block);
#if CLANG_OR_GCC_VERSION(4,7) #if CLANG_OR_GCC_VERSION(4,7)
constexpr constexpr

View File

@ -30,7 +30,6 @@
#include "Page.hxx" #include "Page.hxx"
#include "IcyMetaDataServer.hxx" #include "IcyMetaDataServer.hxx"
#include "system/fd_util.h" #include "system/fd_util.h"
#include "IOThread.hxx"
#include "event/Call.hxx" #include "event/Call.hxx"
#include "util/RuntimeError.hxx" #include "util/RuntimeError.hxx"
#include "util/Domain.hxx" #include "util/Domain.hxx"
@ -118,9 +117,9 @@ HttpdOutput::Unbind()
} }
HttpdOutput * HttpdOutput *
HttpdOutput::Create(const ConfigBlock &block) HttpdOutput::Create(EventLoop &event_loop, const ConfigBlock &block)
{ {
return new HttpdOutput(io_thread_get(), block); return new HttpdOutput(event_loop, block);
} }
/** /**
@ -466,7 +465,7 @@ HttpdOutput::CancelAllClients()
void void
HttpdOutput::Cancel() HttpdOutput::Cancel()
{ {
BlockingCall(io_thread_get(), [this](){ BlockingCall(GetEventLoop(), [this](){
CancelAllClients(); CancelAllClients();
}); });
} }

View File

@ -91,7 +91,8 @@ public:
return &base; return &base;
} }
static SlesOutput *Create(const ConfigBlock &block); static SlesOutput *Create(EventLoop &event_loop,
const ConfigBlock &block);
void Open(AudioFormat &audio_format); void Open(AudioFormat &audio_format);
void Close(); void Close();
@ -413,7 +414,7 @@ sles_test_default_device()
} }
inline SlesOutput * inline SlesOutput *
SlesOutput::Create(const ConfigBlock &block) SlesOutput::Create(EventLoop &, const ConfigBlock &block)
{ {
return new SlesOutput(block); return new SlesOutput(block);
} }