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 "OpenALOutputPlugin.hxx"
|
||||
#include "../OutputAPI.hxx"
|
||||
#include "../Wrapper.hxx"
|
||||
#include "util/RuntimeError.hxx"
|
||||
|
||||
#include <unistd.h>
|
||||
@@ -33,14 +32,10 @@
|
||||
#include <OpenAL/alc.h>
|
||||
#endif
|
||||
|
||||
class OpenALOutput {
|
||||
friend struct AudioOutputWrapper<OpenALOutput>;
|
||||
|
||||
class OpenALOutput final : AudioOutput {
|
||||
/* should be enough for buffer size = 2048 */
|
||||
static constexpr unsigned NUM_BUFFERS = 16;
|
||||
|
||||
AudioOutput base;
|
||||
|
||||
const char *device_name;
|
||||
ALCdevice *device;
|
||||
ALCcontext *context;
|
||||
@@ -52,14 +47,18 @@ class OpenALOutput {
|
||||
|
||||
OpenALOutput(const ConfigBlock &block);
|
||||
|
||||
static OpenALOutput *Create(EventLoop &event_loop,
|
||||
const ConfigBlock &block);
|
||||
public:
|
||||
static AudioOutput *Create(EventLoop &,
|
||||
const ConfigBlock &block) {
|
||||
return new OpenALOutput(block);
|
||||
}
|
||||
|
||||
void Open(AudioFormat &audio_format);
|
||||
void Close();
|
||||
private:
|
||||
void Open(AudioFormat &audio_format) override;
|
||||
void Close() noexcept override;
|
||||
|
||||
gcc_pure
|
||||
std::chrono::steady_clock::duration Delay() const noexcept {
|
||||
std::chrono::steady_clock::duration Delay() const noexcept override {
|
||||
return filled < NUM_BUFFERS || HasProcessed()
|
||||
? std::chrono::steady_clock::duration::zero()
|
||||
/* we don't know exactly how long we must wait
|
||||
@@ -68,9 +67,9 @@ class OpenALOutput {
|
||||
: std::chrono::milliseconds(50);
|
||||
}
|
||||
|
||||
size_t Play(const void *chunk, size_t size);
|
||||
size_t Play(const void *chunk, size_t size) override;
|
||||
|
||||
void Cancel();
|
||||
void Cancel() noexcept override;
|
||||
|
||||
private:
|
||||
gcc_pure
|
||||
@@ -138,7 +137,7 @@ OpenALOutput::SetupContext()
|
||||
}
|
||||
|
||||
OpenALOutput::OpenALOutput(const ConfigBlock &block)
|
||||
:base(openal_output_plugin),
|
||||
:AudioOutput(0),
|
||||
device_name(block.GetBlockValue("device"))
|
||||
{
|
||||
if (device_name == nullptr)
|
||||
@@ -146,13 +145,7 @@ OpenALOutput::OpenALOutput(const ConfigBlock &block)
|
||||
ALC_DEFAULT_DEVICE_SPECIFIER);
|
||||
}
|
||||
|
||||
inline OpenALOutput *
|
||||
OpenALOutput::Create(EventLoop &, const ConfigBlock &block)
|
||||
{
|
||||
return new OpenALOutput(block);
|
||||
}
|
||||
|
||||
inline void
|
||||
void
|
||||
OpenALOutput::Open(AudioFormat &audio_format)
|
||||
{
|
||||
format = openal_audio_format(audio_format);
|
||||
@@ -176,8 +169,8 @@ OpenALOutput::Open(AudioFormat &audio_format)
|
||||
frequency = audio_format.sample_rate;
|
||||
}
|
||||
|
||||
inline void
|
||||
OpenALOutput::Close()
|
||||
void
|
||||
OpenALOutput::Close() noexcept
|
||||
{
|
||||
alcMakeContextCurrent(context);
|
||||
alDeleteSources(1, &source);
|
||||
@@ -186,7 +179,7 @@ OpenALOutput::Close()
|
||||
alcCloseDevice(device);
|
||||
}
|
||||
|
||||
inline size_t
|
||||
size_t
|
||||
OpenALOutput::Play(const void *chunk, size_t size)
|
||||
{
|
||||
if (alcGetCurrentContext() != context)
|
||||
@@ -214,8 +207,8 @@ OpenALOutput::Play(const void *chunk, size_t size)
|
||||
return size;
|
||||
}
|
||||
|
||||
inline void
|
||||
OpenALOutput::Cancel()
|
||||
void
|
||||
OpenALOutput::Cancel() noexcept
|
||||
{
|
||||
filled = 0;
|
||||
alcMakeContextCurrent(context);
|
||||
@@ -226,22 +219,9 @@ OpenALOutput::Cancel()
|
||||
filled = 0;
|
||||
}
|
||||
|
||||
typedef AudioOutputWrapper<OpenALOutput> Wrapper;
|
||||
|
||||
const struct AudioOutputPlugin openal_output_plugin = {
|
||||
"openal",
|
||||
nullptr,
|
||||
&Wrapper::Init,
|
||||
&Wrapper::Finish,
|
||||
nullptr,
|
||||
nullptr,
|
||||
&Wrapper::Open,
|
||||
&Wrapper::Close,
|
||||
&Wrapper::Delay,
|
||||
nullptr,
|
||||
&Wrapper::Play,
|
||||
nullptr,
|
||||
&Wrapper::Cancel,
|
||||
nullptr,
|
||||
OpenALOutput::Create,
|
||||
nullptr,
|
||||
};
|
||||
|
Reference in New Issue
Block a user