From 575a5bd0b8f1df1cf10add1426c89a6224409e02 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Fri, 9 Jan 2015 17:44:00 +0100 Subject: [PATCH] output/null: move functions into the struct --- src/output/plugins/NullOutputPlugin.cxx | 124 +++++++++--------------- 1 file changed, 48 insertions(+), 76 deletions(-) diff --git a/src/output/plugins/NullOutputPlugin.cxx b/src/output/plugins/NullOutputPlugin.cxx index eb6a184ef..a7079d98a 100644 --- a/src/output/plugins/NullOutputPlugin.cxx +++ b/src/output/plugins/NullOutputPlugin.cxx @@ -20,6 +20,7 @@ #include "config.h" #include "NullOutputPlugin.hxx" #include "../OutputAPI.hxx" +#include "../Wrapper.hxx" #include "../Timer.hxx" struct NullOutput { @@ -35,10 +36,46 @@ struct NullOutput { bool Initialize(const config_param ¶m, Error &error) { return base.Configure(param, error); } + + static NullOutput *Create(const config_param ¶m, Error &error); + + bool Open(AudioFormat &audio_format, gcc_unused Error &error) { + if (sync) + timer = new Timer(audio_format); + + return true; + } + + void Close() { + if (sync) + delete timer; + } + + unsigned Delay() const { + return sync && timer->IsStarted() + ? timer->GetDelay() + : 0; + } + + size_t Play(gcc_unused const void *chunk, size_t size, + gcc_unused Error &error) { + if (sync) { + if (!timer->IsStarted()) + timer->Start(); + timer->Add(size); + } + + return size; + } + + void Cancel() { + if (sync) + timer->Reset(); + } }; -static AudioOutput * -null_init(const config_param ¶m, Error &error) +inline NullOutput * +NullOutput::Create(const config_param ¶m, Error &error) { NullOutput *nd = new NullOutput(); @@ -49,90 +86,25 @@ null_init(const config_param ¶m, Error &error) nd->sync = param.GetBlockValue("sync", true); - return &nd->base; + return nd; } -static void -null_finish(AudioOutput *ao) -{ - NullOutput *nd = (NullOutput *)ao; - - delete nd; -} - -static bool -null_open(AudioOutput *ao, AudioFormat &audio_format, - gcc_unused Error &error) -{ - NullOutput *nd = (NullOutput *)ao; - - if (nd->sync) - nd->timer = new Timer(audio_format); - - return true; -} - -static void -null_close(AudioOutput *ao) -{ - NullOutput *nd = (NullOutput *)ao; - - if (nd->sync) - delete nd->timer; -} - -static unsigned -null_delay(AudioOutput *ao) -{ - NullOutput *nd = (NullOutput *)ao; - - return nd->sync && nd->timer->IsStarted() - ? nd->timer->GetDelay() - : 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; - - if (!timer->IsStarted()) - timer->Start(); - timer->Add(size); - - return size; -} - -static void -null_cancel(AudioOutput *ao) -{ - NullOutput *nd = (NullOutput *)ao; - - if (!nd->sync) - return; - - nd->timer->Reset(); -} +typedef AudioOutputWrapper Wrapper; const struct AudioOutputPlugin null_output_plugin = { "null", nullptr, - null_init, - null_finish, + &Wrapper::Init, + &Wrapper::Finish, nullptr, nullptr, - null_open, - null_close, - null_delay, + &Wrapper::Open, + &Wrapper::Close, + &Wrapper::Delay, nullptr, - null_play, + &Wrapper::Play, nullptr, - null_cancel, + &Wrapper::Cancel, nullptr, nullptr, };