output/Interface: convert to abstract class
Yet another C-style vtable replaced with C++.
This commit is contained in:
@@ -20,7 +20,6 @@
|
||||
#include "config.h"
|
||||
#include "PipeOutputPlugin.hxx"
|
||||
#include "../OutputAPI.hxx"
|
||||
#include "../Wrapper.hxx"
|
||||
#include "system/Error.hxx"
|
||||
|
||||
#include <string>
|
||||
@@ -28,43 +27,36 @@
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
class PipeOutput {
|
||||
friend struct AudioOutputWrapper<PipeOutput>;
|
||||
|
||||
AudioOutput base;
|
||||
|
||||
class PipeOutput final : AudioOutput {
|
||||
const std::string cmd;
|
||||
FILE *fh;
|
||||
|
||||
PipeOutput(const ConfigBlock &block);
|
||||
|
||||
public:
|
||||
static PipeOutput *Create(EventLoop &event_loop,
|
||||
const ConfigBlock &block);
|
||||
static AudioOutput *Create(EventLoop &,
|
||||
const ConfigBlock &block) {
|
||||
return new PipeOutput(block);
|
||||
}
|
||||
|
||||
void Open(AudioFormat &audio_format);
|
||||
private:
|
||||
void Open(AudioFormat &audio_format) override;
|
||||
|
||||
void Close() {
|
||||
void Close() noexcept override {
|
||||
pclose(fh);
|
||||
}
|
||||
|
||||
size_t Play(const void *chunk, size_t size);
|
||||
size_t Play(const void *chunk, size_t size) override;
|
||||
};
|
||||
|
||||
PipeOutput::PipeOutput(const ConfigBlock &block)
|
||||
:base(pipe_output_plugin),
|
||||
:AudioOutput(0),
|
||||
cmd(block.GetBlockValue("command", ""))
|
||||
{
|
||||
if (cmd.empty())
|
||||
throw std::runtime_error("No \"command\" parameter specified");
|
||||
}
|
||||
|
||||
inline PipeOutput *
|
||||
PipeOutput::Create(EventLoop &, const ConfigBlock &block)
|
||||
{
|
||||
return new PipeOutput(block);
|
||||
}
|
||||
|
||||
inline void
|
||||
PipeOutput::Open(gcc_unused AudioFormat &audio_format)
|
||||
{
|
||||
@@ -83,22 +75,9 @@ PipeOutput::Play(const void *chunk, size_t size)
|
||||
return nbytes;
|
||||
}
|
||||
|
||||
typedef AudioOutputWrapper<PipeOutput> Wrapper;
|
||||
|
||||
const struct AudioOutputPlugin pipe_output_plugin = {
|
||||
"pipe",
|
||||
nullptr,
|
||||
&Wrapper::Init,
|
||||
&Wrapper::Finish,
|
||||
nullptr,
|
||||
nullptr,
|
||||
&Wrapper::Open,
|
||||
&Wrapper::Close,
|
||||
nullptr,
|
||||
nullptr,
|
||||
&Wrapper::Play,
|
||||
nullptr,
|
||||
nullptr,
|
||||
nullptr,
|
||||
&PipeOutput::Create,
|
||||
nullptr,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user