aboutsummaryrefslogtreecommitdiffstats
path: root/src/output/plugins/NullOutputPlugin.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'src/output/plugins/NullOutputPlugin.cxx')
-rw-r--r--src/output/plugins/NullOutputPlugin.cxx133
1 files changed, 54 insertions, 79 deletions
diff --git a/src/output/plugins/NullOutputPlugin.cxx b/src/output/plugins/NullOutputPlugin.cxx
index 098f58926..e1731f0fe 100644
--- a/src/output/plugins/NullOutputPlugin.cxx
+++ b/src/output/plugins/NullOutputPlugin.cxx
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2003-2014 The Music Player Daemon Project
+ * Copyright (C) 2003-2015 The Music Player Daemon Project
* http://www.musicpd.org
*
* This program is free software; you can redistribute it and/or modify
@@ -20,119 +20,94 @@
#include "config.h"
#include "NullOutputPlugin.hxx"
#include "../OutputAPI.hxx"
+#include "../Wrapper.hxx"
#include "../Timer.hxx"
-struct NullOutput {
+class NullOutput {
+ friend struct AudioOutputWrapper<NullOutput>;
+
AudioOutput base;
bool sync;
Timer *timer;
+public:
NullOutput()
:base(null_output_plugin) {}
- bool Initialize(const config_param &param, Error &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;
+ bool Initialize(const ConfigBlock &block, Error &error) {
+ return base.Configure(block, error);
}
- nd->sync = param.GetBlockValue("sync", true);
+ static NullOutput *Create(const ConfigBlock &block, Error &error);
- return &nd->base;
-}
+ bool Open(AudioFormat &audio_format, gcc_unused Error &error) {
+ if (sync)
+ timer = new Timer(audio_format);
-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;
+ }
- return true;
-}
+ void Close() {
+ if (sync)
+ delete timer;
+ }
-static void
-null_close(AudioOutput *ao)
-{
- NullOutput *nd = (NullOutput *)ao;
+ unsigned Delay() const {
+ return sync && timer->IsStarted()
+ ? timer->GetDelay()
+ : 0;
+ }
- if (nd->sync)
- delete nd->timer;
-}
+ 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);
+ }
-static unsigned
-null_delay(AudioOutput *ao)
-{
- NullOutput *nd = (NullOutput *)ao;
+ return size;
+ }
- return nd->sync && nd->timer->IsStarted()
- ? nd->timer->GetDelay()
- : 0;
-}
+ void Cancel() {
+ if (sync)
+ timer->Reset();
+ }
+};
-static size_t
-null_play(AudioOutput *ao, gcc_unused const void *chunk, size_t size,
- gcc_unused Error &error)
+inline NullOutput *
+NullOutput::Create(const ConfigBlock &block, Error &error)
{
- NullOutput *nd = (NullOutput *)ao;
- Timer *timer = nd->timer;
+ NullOutput *nd = new NullOutput();
- if (!nd->sync)
- return size;
+ if (!nd->Initialize(block, error)) {
+ delete nd;
+ return nullptr;
+ }
- if (!timer->IsStarted())
- timer->Start();
- timer->Add(size);
+ nd->sync = block.GetBlockValue("sync", true);
- return size;
+ return nd;
}
-static void
-null_cancel(AudioOutput *ao)
-{
- NullOutput *nd = (NullOutput *)ao;
-
- if (!nd->sync)
- return;
-
- nd->timer->Reset();
-}
+typedef AudioOutputWrapper<NullOutput> 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,
};