Start a new backend factory API
[openal-soft.git] / Alc / backends / base.h
blob5f7deb622281e2e0cb0af3445e49d604a1abb5c3
1 #ifndef AL_BACKENDS_BASE_H
2 #define AL_BACKENDS_BASE_H
4 #include "alMain.h"
6 #ifdef __cplusplus
8 #include <string>
9 #include <mutex>
11 struct ClockLatency {
12 ALint64 ClockTime;
13 ALint64 Latency;
16 /* Helper to get the current clock time from the device's ClockBase, and
17 * SamplesDone converted from the sample rate.
19 inline ALuint64 GetDeviceClockTime(ALCdevice *device)
21 return device->ClockBase + (device->SamplesDone * DEVICE_CLOCK_RES /
22 device->Frequency);
25 void ALCdevice_Lock(ALCdevice *device);
26 void ALCdevice_Unlock(ALCdevice *device);
28 ClockLatency GetClockLatency(ALCdevice *device);
31 struct ALCbackendVtable;
33 struct ALCbackend {
34 const struct ALCbackendVtable *vtbl;
36 ALCdevice *mDevice;
38 std::recursive_mutex mMutex;
41 void ALCbackend_Construct(ALCbackend *self, ALCdevice *device);
42 void ALCbackend_Destruct(ALCbackend *self);
43 ALCboolean ALCbackend_reset(ALCbackend *self);
44 ALCenum ALCbackend_captureSamples(ALCbackend *self, void *buffer, ALCuint samples);
45 ALCuint ALCbackend_availableSamples(ALCbackend *self);
46 ClockLatency ALCbackend_getClockLatency(ALCbackend *self);
47 void ALCbackend_lock(ALCbackend *self);
48 void ALCbackend_unlock(ALCbackend *self);
50 struct ALCbackendVtable {
51 void (*const Destruct)(ALCbackend*);
53 ALCenum (*const open)(ALCbackend*, const ALCchar*);
55 ALCboolean (*const reset)(ALCbackend*);
56 ALCboolean (*const start)(ALCbackend*);
57 void (*const stop)(ALCbackend*);
59 ALCenum (*const captureSamples)(ALCbackend*, void*, ALCuint);
60 ALCuint (*const availableSamples)(ALCbackend*);
62 ClockLatency (*const getClockLatency)(ALCbackend*);
64 void (*const lock)(ALCbackend*);
65 void (*const unlock)(ALCbackend*);
67 void (*const Delete)(void*);
70 #define DEFINE_ALCBACKEND_VTABLE(T) \
71 DECLARE_THUNK(T, ALCbackend, void, Destruct) \
72 DECLARE_THUNK1(T, ALCbackend, ALCenum, open, const ALCchar*) \
73 DECLARE_THUNK(T, ALCbackend, ALCboolean, reset) \
74 DECLARE_THUNK(T, ALCbackend, ALCboolean, start) \
75 DECLARE_THUNK(T, ALCbackend, void, stop) \
76 DECLARE_THUNK2(T, ALCbackend, ALCenum, captureSamples, void*, ALCuint) \
77 DECLARE_THUNK(T, ALCbackend, ALCuint, availableSamples) \
78 DECLARE_THUNK(T, ALCbackend, ClockLatency, getClockLatency) \
79 DECLARE_THUNK(T, ALCbackend, void, lock) \
80 DECLARE_THUNK(T, ALCbackend, void, unlock) \
81 static void T##_ALCbackend_Delete(void *ptr) \
82 { T##_Delete(STATIC_UPCAST(T, ALCbackend, (ALCbackend*)ptr)); } \
84 static const struct ALCbackendVtable T##_ALCbackend_vtable = { \
85 T##_ALCbackend_Destruct, \
87 T##_ALCbackend_open, \
88 T##_ALCbackend_reset, \
89 T##_ALCbackend_start, \
90 T##_ALCbackend_stop, \
91 T##_ALCbackend_captureSamples, \
92 T##_ALCbackend_availableSamples, \
93 T##_ALCbackend_getClockLatency, \
94 T##_ALCbackend_lock, \
95 T##_ALCbackend_unlock, \
97 T##_ALCbackend_Delete, \
101 enum ALCbackend_Type {
102 ALCbackend_Playback,
103 ALCbackend_Capture,
104 ALCbackend_Loopback
108 struct ALCbackendFactoryVtable;
110 struct ALCbackendFactory {
111 const struct ALCbackendFactoryVtable *vtbl;
114 void ALCbackendFactory_deinit(ALCbackendFactory *self);
116 struct ALCbackendFactoryVtable {
117 ALCboolean (*const init)(ALCbackendFactory *self);
118 void (*const deinit)(ALCbackendFactory *self);
120 ALCboolean (*const querySupport)(ALCbackendFactory *self, ALCbackend_Type type);
122 void (*const probe)(ALCbackendFactory *self, enum DevProbe type, std::string *outnames);
124 ALCbackend* (*const createBackend)(ALCbackendFactory *self, ALCdevice *device, ALCbackend_Type type);
127 #define DEFINE_ALCBACKENDFACTORY_VTABLE(T) \
128 DECLARE_THUNK(T, ALCbackendFactory, ALCboolean, init) \
129 DECLARE_THUNK(T, ALCbackendFactory, void, deinit) \
130 DECLARE_THUNK1(T, ALCbackendFactory, ALCboolean, querySupport, ALCbackend_Type) \
131 DECLARE_THUNK2(T, ALCbackendFactory, void, probe, enum DevProbe, std::string*) \
132 DECLARE_THUNK2(T, ALCbackendFactory, ALCbackend*, createBackend, ALCdevice*, ALCbackend_Type) \
134 static const struct ALCbackendFactoryVtable T##_ALCbackendFactory_vtable = { \
135 T##_ALCbackendFactory_init, \
136 T##_ALCbackendFactory_deinit, \
137 T##_ALCbackendFactory_querySupport, \
138 T##_ALCbackendFactory_probe, \
139 T##_ALCbackendFactory_createBackend, \
143 ALCbackendFactory *ALCpulseBackendFactory_getFactory(void);
144 ALCbackendFactory *ALCalsaBackendFactory_getFactory(void);
145 ALCbackendFactory *ALCcoreAudioBackendFactory_getFactory(void);
146 ALCbackendFactory *ALCossBackendFactory_getFactory(void);
147 ALCbackendFactory *ALCjackBackendFactory_getFactory(void);
148 ALCbackendFactory *ALCsolarisBackendFactory_getFactory(void);
149 ALCbackendFactory *SndioBackendFactory_getFactory(void);
150 ALCbackendFactory *ALCqsaBackendFactory_getFactory(void);
151 ALCbackendFactory *ALCwasapiBackendFactory_getFactory(void);
152 ALCbackendFactory *ALCdsoundBackendFactory_getFactory(void);
153 ALCbackendFactory *ALCwinmmBackendFactory_getFactory(void);
154 ALCbackendFactory *ALCportBackendFactory_getFactory(void);
155 ALCbackendFactory *ALCopenslBackendFactory_getFactory(void);
156 ALCbackendFactory *ALCwaveBackendFactory_getFactory(void);
157 ALCbackendFactory *ALCsdl2BackendFactory_getFactory(void);
158 ALCbackendFactory *ALCloopbackFactory_getFactory(void);
161 struct BackendFactory {
162 virtual bool init() = 0;
163 virtual void deinit() { }
165 virtual bool querySupport(ALCbackend_Type type) = 0;
167 virtual void probe(enum DevProbe type, std::string *outnames) = 0;
169 virtual ALCbackend *createBackend(ALCdevice *device, ALCbackend_Type type) = 0;
173 #endif /* __cplusplus */
174 #endif /* AL_BACKENDS_BASE_H */