Clean up a couple variable names and declarations
[openal-soft.git] / Alc / backends / base.c
blobff808f5357b166abd8327808310e0259b199c4c9
2 #include "config.h"
4 #include <stdlib.h>
6 #include "alMain.h"
8 #include "backends/base.h"
11 extern inline ALuint64 GetDeviceClockTime(ALCdevice *device);
13 /* Base ALCbackend method implementations. */
14 void ALCbackend_Construct(ALCbackend *self, ALCdevice *device)
16 int ret = almtx_init(&self->mMutex, almtx_recursive);
17 assert(ret == althrd_success);
18 self->mDevice = device;
21 void ALCbackend_Destruct(ALCbackend *self)
23 almtx_destroy(&self->mMutex);
26 ALCboolean ALCbackend_reset(ALCbackend* UNUSED(self))
28 return ALC_FALSE;
31 ALCenum ALCbackend_captureSamples(ALCbackend* UNUSED(self), void* UNUSED(buffer), ALCuint UNUSED(samples))
33 return ALC_INVALID_DEVICE;
36 ALCuint ALCbackend_availableSamples(ALCbackend* UNUSED(self))
38 return 0;
41 ClockLatency ALCbackend_getClockLatency(ALCbackend *self)
43 ALCdevice *device = self->mDevice;
44 ClockLatency ret;
46 almtx_lock(&self->mMutex);
47 ret.ClockTime = GetDeviceClockTime(device);
48 // TODO: Perhaps should be NumUpdates-1 worth of UpdateSize?
49 ret.Latency = 0;
50 almtx_unlock(&self->mMutex);
52 return ret;
55 void ALCbackend_lock(ALCbackend *self)
57 int ret = almtx_lock(&self->mMutex);
58 assert(ret == althrd_success);
61 void ALCbackend_unlock(ALCbackend *self)
63 int ret = almtx_unlock(&self->mMutex);
64 assert(ret == althrd_success);
68 /* Base ALCbackendFactory method implementations. */
69 void ALCbackendFactory_deinit(ALCbackendFactory* UNUSED(self))
74 /* Wrappers to use an old-style backend with the new interface. */
75 typedef struct PlaybackWrapper {
76 DERIVE_FROM_TYPE(ALCbackend);
78 const BackendFuncs *Funcs;
79 } PlaybackWrapper;
81 static void PlaybackWrapper_Construct(PlaybackWrapper *self, ALCdevice *device, const BackendFuncs *funcs);
82 static DECLARE_FORWARD(PlaybackWrapper, ALCbackend, void, Destruct)
83 static ALCenum PlaybackWrapper_open(PlaybackWrapper *self, const ALCchar *name);
84 static void PlaybackWrapper_close(PlaybackWrapper *self);
85 static ALCboolean PlaybackWrapper_reset(PlaybackWrapper *self);
86 static ALCboolean PlaybackWrapper_start(PlaybackWrapper *self);
87 static void PlaybackWrapper_stop(PlaybackWrapper *self);
88 static DECLARE_FORWARD2(PlaybackWrapper, ALCbackend, ALCenum, captureSamples, void*, ALCuint)
89 static DECLARE_FORWARD(PlaybackWrapper, ALCbackend, ALCuint, availableSamples)
90 static DECLARE_FORWARD(PlaybackWrapper, ALCbackend, ClockLatency, getClockLatency)
91 static DECLARE_FORWARD(PlaybackWrapper, ALCbackend, void, lock)
92 static DECLARE_FORWARD(PlaybackWrapper, ALCbackend, void, unlock)
93 DECLARE_DEFAULT_ALLOCATORS(PlaybackWrapper)
94 DEFINE_ALCBACKEND_VTABLE(PlaybackWrapper);
96 static void PlaybackWrapper_Construct(PlaybackWrapper *self, ALCdevice *device, const BackendFuncs *funcs)
98 ALCbackend_Construct(STATIC_CAST(ALCbackend, self), device);
99 SET_VTABLE2(PlaybackWrapper, ALCbackend, self);
101 self->Funcs = funcs;
104 static ALCenum PlaybackWrapper_open(PlaybackWrapper *self, const ALCchar *name)
106 ALCdevice *device = STATIC_CAST(ALCbackend, self)->mDevice;
107 return self->Funcs->OpenPlayback(device, name);
110 static void PlaybackWrapper_close(PlaybackWrapper *self)
112 ALCdevice *device = STATIC_CAST(ALCbackend, self)->mDevice;
113 self->Funcs->ClosePlayback(device);
116 static ALCboolean PlaybackWrapper_reset(PlaybackWrapper *self)
118 ALCdevice *device = STATIC_CAST(ALCbackend, self)->mDevice;
119 return self->Funcs->ResetPlayback(device);
122 static ALCboolean PlaybackWrapper_start(PlaybackWrapper *self)
124 ALCdevice *device = STATIC_CAST(ALCbackend, self)->mDevice;
125 return self->Funcs->StartPlayback(device);
128 static void PlaybackWrapper_stop(PlaybackWrapper *self)
130 ALCdevice *device = STATIC_CAST(ALCbackend, self)->mDevice;
131 self->Funcs->StopPlayback(device);
135 typedef struct CaptureWrapper {
136 DERIVE_FROM_TYPE(ALCbackend);
138 const BackendFuncs *Funcs;
139 } CaptureWrapper;
141 static void CaptureWrapper_Construct(CaptureWrapper *self, ALCdevice *device, const BackendFuncs *funcs);
142 static DECLARE_FORWARD(CaptureWrapper, ALCbackend, void, Destruct)
143 static ALCenum CaptureWrapper_open(CaptureWrapper *self, const ALCchar *name);
144 static void CaptureWrapper_close(CaptureWrapper *self);
145 static DECLARE_FORWARD(CaptureWrapper, ALCbackend, ALCboolean, reset)
146 static ALCboolean CaptureWrapper_start(CaptureWrapper *self);
147 static void CaptureWrapper_stop(CaptureWrapper *self);
148 static ALCenum CaptureWrapper_captureSamples(CaptureWrapper *self, void *buffer, ALCuint samples);
149 static ALCuint CaptureWrapper_availableSamples(CaptureWrapper *self);
150 static DECLARE_FORWARD(CaptureWrapper, ALCbackend, ClockLatency, getClockLatency)
151 static DECLARE_FORWARD(CaptureWrapper, ALCbackend, void, lock)
152 static DECLARE_FORWARD(CaptureWrapper, ALCbackend, void, unlock)
153 DECLARE_DEFAULT_ALLOCATORS(CaptureWrapper)
154 DEFINE_ALCBACKEND_VTABLE(CaptureWrapper);
156 static void CaptureWrapper_Construct(CaptureWrapper *self, ALCdevice *device, const BackendFuncs *funcs)
158 ALCbackend_Construct(STATIC_CAST(ALCbackend, self), device);
159 SET_VTABLE2(CaptureWrapper, ALCbackend, self);
161 self->Funcs = funcs;
164 static ALCenum CaptureWrapper_open(CaptureWrapper *self, const ALCchar *name)
166 ALCdevice *device = STATIC_CAST(ALCbackend, self)->mDevice;
167 return self->Funcs->OpenCapture(device, name);
170 static void CaptureWrapper_close(CaptureWrapper *self)
172 ALCdevice *device = STATIC_CAST(ALCbackend, self)->mDevice;
173 self->Funcs->CloseCapture(device);
176 static ALCboolean CaptureWrapper_start(CaptureWrapper *self)
178 ALCdevice *device = STATIC_CAST(ALCbackend, self)->mDevice;
179 self->Funcs->StartCapture(device);
180 return ALC_TRUE;
183 static void CaptureWrapper_stop(CaptureWrapper *self)
185 ALCdevice *device = STATIC_CAST(ALCbackend, self)->mDevice;
186 self->Funcs->StopCapture(device);
189 static ALCenum CaptureWrapper_captureSamples(CaptureWrapper *self, void *buffer, ALCuint samples)
191 ALCdevice *device = STATIC_CAST(ALCbackend, self)->mDevice;
192 return self->Funcs->CaptureSamples(device, buffer, samples);
195 static ALCuint CaptureWrapper_availableSamples(CaptureWrapper *self)
197 ALCdevice *device = STATIC_CAST(ALCbackend, self)->mDevice;
198 return self->Funcs->AvailableSamples(device);
202 ALCbackend *create_backend_wrapper(ALCdevice *device, const BackendFuncs *funcs, ALCbackend_Type type)
204 if(type == ALCbackend_Playback)
206 PlaybackWrapper *backend;
208 NEW_OBJ(backend, PlaybackWrapper)(device, funcs);
209 if(!backend) return NULL;
211 return STATIC_CAST(ALCbackend, backend);
214 if(type == ALCbackend_Capture)
216 CaptureWrapper *backend;
218 NEW_OBJ(backend, CaptureWrapper)(device, funcs);
219 if(!backend) return NULL;
221 return STATIC_CAST(ALCbackend, backend);
224 return NULL;