Commit 575a5bd0 authored by Max Kellermann's avatar Max Kellermann

output/null: move functions into the struct

parent ae4c189e
...@@ -20,6 +20,7 @@ ...@@ -20,6 +20,7 @@
#include "config.h" #include "config.h"
#include "NullOutputPlugin.hxx" #include "NullOutputPlugin.hxx"
#include "../OutputAPI.hxx" #include "../OutputAPI.hxx"
#include "../Wrapper.hxx"
#include "../Timer.hxx" #include "../Timer.hxx"
struct NullOutput { struct NullOutput {
...@@ -35,104 +36,75 @@ struct NullOutput { ...@@ -35,104 +36,75 @@ struct NullOutput {
bool Initialize(const config_param &param, Error &error) { bool Initialize(const config_param &param, Error &error) {
return base.Configure(param, error); return base.Configure(param, error);
} }
};
static AudioOutput *
null_init(const config_param &param, Error &error)
{
NullOutput *nd = new NullOutput();
if (!nd->Initialize(param, error)) {
delete nd;
return nullptr;
}
nd->sync = param.GetBlockValue("sync", true);
return &nd->base;
}
static void
null_finish(AudioOutput *ao)
{
NullOutput *nd = (NullOutput *)ao;
delete nd;
}
static bool static NullOutput *Create(const config_param &param, Error &error);
null_open(AudioOutput *ao, AudioFormat &audio_format,
gcc_unused Error &error)
{
NullOutput *nd = (NullOutput *)ao;
if (nd->sync) bool Open(AudioFormat &audio_format, gcc_unused Error &error) {
nd->timer = new Timer(audio_format); if (sync)
timer = new Timer(audio_format);
return true; return true;
} }
static void
null_close(AudioOutput *ao)
{
NullOutput *nd = (NullOutput *)ao;
if (nd->sync)
delete nd->timer;
}
static unsigned void Close() {
null_delay(AudioOutput *ao) if (sync)
{ delete timer;
NullOutput *nd = (NullOutput *)ao; }
return nd->sync && nd->timer->IsStarted() unsigned Delay() const {
? nd->timer->GetDelay() return sync && timer->IsStarted()
? timer->GetDelay()
: 0; : 0;
} }
static size_t
null_play(AudioOutput *ao, gcc_unused const void *chunk, size_t size,
gcc_unused Error &error)
{
NullOutput *nd = (NullOutput *)ao;
Timer *timer = nd->timer;
if (!nd->sync)
return size;
size_t Play(gcc_unused const void *chunk, size_t size,
gcc_unused Error &error) {
if (sync) {
if (!timer->IsStarted()) if (!timer->IsStarted())
timer->Start(); timer->Start();
timer->Add(size); timer->Add(size);
}
return size; return size;
} }
static void void Cancel() {
null_cancel(AudioOutput *ao) if (sync)
timer->Reset();
}
};
inline NullOutput *
NullOutput::Create(const config_param &param, Error &error)
{ {
NullOutput *nd = (NullOutput *)ao; NullOutput *nd = new NullOutput();
if (!nd->sync) if (!nd->Initialize(param, error)) {
return; delete nd;
return nullptr;
}
nd->timer->Reset(); nd->sync = param.GetBlockValue("sync", true);
return nd;
} }
typedef AudioOutputWrapper<NullOutput> Wrapper;
const struct AudioOutputPlugin null_output_plugin = { const struct AudioOutputPlugin null_output_plugin = {
"null", "null",
nullptr, nullptr,
null_init, &Wrapper::Init,
null_finish, &Wrapper::Finish,
nullptr, nullptr,
nullptr, nullptr,
null_open, &Wrapper::Open,
null_close, &Wrapper::Close,
null_delay, &Wrapper::Delay,
nullptr, nullptr,
null_play, &Wrapper::Play,
nullptr, nullptr,
null_cancel, &Wrapper::Cancel,
nullptr, nullptr,
nullptr, nullptr,
}; };
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