125 lines
4.6 KiB
C
Raw Normal View History

2013-10-27 16:37:40 -07:00
#ifndef AL_BACKENDS_BASE_H
#define AL_BACKENDS_BASE_H
#include "alMain.h"
#include <string>
#include <mutex>
struct ClockLatency {
/* FIXME: These should be nanoseconds. Will require changing backends that
* provide this info.
*/
ALint64 ClockTime;
ALint64 Latency;
};
/* Helper to get the current clock time from the device's ClockBase, and
* SamplesDone converted from the sample rate.
*/
inline ALuint64 GetDeviceClockTime(ALCdevice *device)
{
using std::chrono::seconds;
using std::chrono::nanoseconds;
using std::chrono::duration_cast;
auto ns = duration_cast<nanoseconds>(seconds{device->SamplesDone}) / device->Frequency;
return (device->ClockBase + ns).count();
}
void ALCdevice_Lock(ALCdevice *device);
void ALCdevice_Unlock(ALCdevice *device);
ClockLatency GetClockLatency(ALCdevice *device);
2013-10-27 16:37:40 -07:00
struct ALCbackendVtable;
struct ALCbackend {
2013-10-27 16:37:40 -07:00
const struct ALCbackendVtable *vtbl;
ALCdevice *mDevice;
2013-10-28 12:05:33 -07:00
std::recursive_mutex mMutex;
};
2013-10-27 16:37:40 -07:00
2013-10-28 12:05:33 -07:00
void ALCbackend_Construct(ALCbackend *self, ALCdevice *device);
void ALCbackend_Destruct(ALCbackend *self);
ALCboolean ALCbackend_reset(ALCbackend *self);
ALCenum ALCbackend_captureSamples(ALCbackend *self, void *buffer, ALCuint samples);
ALCuint ALCbackend_availableSamples(ALCbackend *self);
ClockLatency ALCbackend_getClockLatency(ALCbackend *self);
void ALCbackend_lock(ALCbackend *self);
void ALCbackend_unlock(ALCbackend *self);
2013-10-27 16:37:40 -07:00
struct ALCbackendVtable {
void (*const Destruct)(ALCbackend*);
2013-10-27 16:37:40 -07:00
ALCenum (*const open)(ALCbackend*, const ALCchar*);
2013-11-02 16:58:26 -07:00
ALCboolean (*const reset)(ALCbackend*);
ALCboolean (*const start)(ALCbackend*);
void (*const stop)(ALCbackend*);
2013-10-27 16:37:40 -07:00
2013-11-02 16:58:26 -07:00
ALCenum (*const captureSamples)(ALCbackend*, void*, ALCuint);
ALCuint (*const availableSamples)(ALCbackend*);
ClockLatency (*const getClockLatency)(ALCbackend*);
2013-10-27 16:37:40 -07:00
2013-11-02 16:58:26 -07:00
void (*const lock)(ALCbackend*);
void (*const unlock)(ALCbackend*);
void (*const Delete)(void*);
2013-10-27 16:37:40 -07:00
};
#define DEFINE_ALCBACKEND_VTABLE(T) \
DECLARE_THUNK(T, ALCbackend, void, Destruct) \
DECLARE_THUNK1(T, ALCbackend, ALCenum, open, const ALCchar*) \
DECLARE_THUNK(T, ALCbackend, ALCboolean, reset) \
DECLARE_THUNK(T, ALCbackend, ALCboolean, start) \
DECLARE_THUNK(T, ALCbackend, void, stop) \
DECLARE_THUNK2(T, ALCbackend, ALCenum, captureSamples, void*, ALCuint) \
DECLARE_THUNK(T, ALCbackend, ALCuint, availableSamples) \
DECLARE_THUNK(T, ALCbackend, ClockLatency, getClockLatency) \
DECLARE_THUNK(T, ALCbackend, void, lock) \
DECLARE_THUNK(T, ALCbackend, void, unlock) \
static void T##_ALCbackend_Delete(void *ptr) \
{ T##_Delete(STATIC_UPCAST(T, ALCbackend, (ALCbackend*)ptr)); } \
2013-10-27 16:37:40 -07:00
\
static const struct ALCbackendVtable T##_ALCbackend_vtable = { \
2013-10-27 16:37:40 -07:00
T##_ALCbackend_Destruct, \
\
T##_ALCbackend_open, \
T##_ALCbackend_reset, \
T##_ALCbackend_start, \
T##_ALCbackend_stop, \
T##_ALCbackend_captureSamples, \
T##_ALCbackend_availableSamples, \
T##_ALCbackend_getClockLatency, \
T##_ALCbackend_lock, \
T##_ALCbackend_unlock, \
2013-10-27 16:37:40 -07:00
\
T##_ALCbackend_Delete, \
}
enum ALCbackend_Type {
ALCbackend_Playback,
2013-11-04 10:51:22 -08:00
ALCbackend_Capture,
ALCbackend_Loopback
};
2013-10-28 07:27:35 -07:00
struct BackendFactory {
virtual bool init() = 0;
virtual void deinit() { }
virtual bool querySupport(ALCbackend_Type type) = 0;
virtual void probe(enum DevProbe type, std::string *outnames) = 0;
virtual ALCbackend *createBackend(ALCdevice *device, ALCbackend_Type type) = 0;
};
2013-10-27 16:37:40 -07:00
#endif /* AL_BACKENDS_BASE_H */