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
)
17 self
->mDevice
= device
;
18 ret
= almtx_init(&self
->mMutex
, almtx_recursive
);
19 assert(ret
== althrd_success
);
22 void ALCbackend_Destruct(ALCbackend
*self
)
24 almtx_destroy(&self
->mMutex
);
27 ALCboolean
ALCbackend_reset(ALCbackend
* UNUSED(self
))
32 ALCenum
ALCbackend_captureSamples(ALCbackend
* UNUSED(self
), void* UNUSED(buffer
), ALCuint
UNUSED(samples
))
34 return ALC_INVALID_DEVICE
;
37 ALCuint
ALCbackend_availableSamples(ALCbackend
* UNUSED(self
))
42 ClockLatency
ALCbackend_getClockLatency(ALCbackend
*self
)
44 ALCdevice
*device
= self
->mDevice
;
47 almtx_lock(&self
->mMutex
);
48 ret
.ClockTime
= GetDeviceClockTime(device
);
49 // TODO: Perhaps should be NumUpdates-1 worth of UpdateSize?
51 almtx_unlock(&self
->mMutex
);
56 void ALCbackend_lock(ALCbackend
*self
)
58 int ret
= almtx_lock(&self
->mMutex
);
59 assert(ret
== althrd_success
);
62 void ALCbackend_unlock(ALCbackend
*self
)
64 int ret
= almtx_unlock(&self
->mMutex
);
65 assert(ret
== althrd_success
);
69 /* Base ALCbackendFactory method implementations. */
70 void ALCbackendFactory_deinit(ALCbackendFactory
* UNUSED(self
))
75 /* Wrappers to use an old-style backend with the new interface. */
76 typedef struct PlaybackWrapper
{
77 DERIVE_FROM_TYPE(ALCbackend
);
79 const BackendFuncs
*Funcs
;
82 static void PlaybackWrapper_Construct(PlaybackWrapper
*self
, ALCdevice
*device
, const BackendFuncs
*funcs
);
83 static DECLARE_FORWARD(PlaybackWrapper
, ALCbackend
, void, Destruct
)
84 static ALCenum
PlaybackWrapper_open(PlaybackWrapper
*self
, const ALCchar
*name
);
85 static void PlaybackWrapper_close(PlaybackWrapper
*self
);
86 static ALCboolean
PlaybackWrapper_reset(PlaybackWrapper
*self
);
87 static ALCboolean
PlaybackWrapper_start(PlaybackWrapper
*self
);
88 static void PlaybackWrapper_stop(PlaybackWrapper
*self
);
89 static DECLARE_FORWARD2(PlaybackWrapper
, ALCbackend
, ALCenum
, captureSamples
, void*, ALCuint
)
90 static DECLARE_FORWARD(PlaybackWrapper
, ALCbackend
, ALCuint
, availableSamples
)
91 static DECLARE_FORWARD(PlaybackWrapper
, ALCbackend
, ClockLatency
, getClockLatency
)
92 static DECLARE_FORWARD(PlaybackWrapper
, ALCbackend
, void, lock
)
93 static DECLARE_FORWARD(PlaybackWrapper
, ALCbackend
, void, unlock
)
94 DECLARE_DEFAULT_ALLOCATORS(PlaybackWrapper
)
95 DEFINE_ALCBACKEND_VTABLE(PlaybackWrapper
);
97 static void PlaybackWrapper_Construct(PlaybackWrapper
*self
, ALCdevice
*device
, const BackendFuncs
*funcs
)
99 ALCbackend_Construct(STATIC_CAST(ALCbackend
, self
), device
);
100 SET_VTABLE2(PlaybackWrapper
, ALCbackend
, self
);
105 static ALCenum
PlaybackWrapper_open(PlaybackWrapper
*self
, const ALCchar
*name
)
107 ALCdevice
*device
= STATIC_CAST(ALCbackend
, self
)->mDevice
;
108 return self
->Funcs
->OpenPlayback(device
, name
);
111 static void PlaybackWrapper_close(PlaybackWrapper
*self
)
113 ALCdevice
*device
= STATIC_CAST(ALCbackend
, self
)->mDevice
;
114 self
->Funcs
->ClosePlayback(device
);
117 static ALCboolean
PlaybackWrapper_reset(PlaybackWrapper
*self
)
119 ALCdevice
*device
= STATIC_CAST(ALCbackend
, self
)->mDevice
;
120 return self
->Funcs
->ResetPlayback(device
);
123 static ALCboolean
PlaybackWrapper_start(PlaybackWrapper
*self
)
125 ALCdevice
*device
= STATIC_CAST(ALCbackend
, self
)->mDevice
;
126 return self
->Funcs
->StartPlayback(device
);
129 static void PlaybackWrapper_stop(PlaybackWrapper
*self
)
131 ALCdevice
*device
= STATIC_CAST(ALCbackend
, self
)->mDevice
;
132 self
->Funcs
->StopPlayback(device
);
136 typedef struct CaptureWrapper
{
137 DERIVE_FROM_TYPE(ALCbackend
);
139 const BackendFuncs
*Funcs
;
142 static void CaptureWrapper_Construct(CaptureWrapper
*self
, ALCdevice
*device
, const BackendFuncs
*funcs
);
143 static DECLARE_FORWARD(CaptureWrapper
, ALCbackend
, void, Destruct
)
144 static ALCenum
CaptureWrapper_open(CaptureWrapper
*self
, const ALCchar
*name
);
145 static void CaptureWrapper_close(CaptureWrapper
*self
);
146 static DECLARE_FORWARD(CaptureWrapper
, ALCbackend
, ALCboolean
, reset
)
147 static ALCboolean
CaptureWrapper_start(CaptureWrapper
*self
);
148 static void CaptureWrapper_stop(CaptureWrapper
*self
);
149 static ALCenum
CaptureWrapper_captureSamples(CaptureWrapper
*self
, void *buffer
, ALCuint samples
);
150 static ALCuint
CaptureWrapper_availableSamples(CaptureWrapper
*self
);
151 static DECLARE_FORWARD(CaptureWrapper
, ALCbackend
, ClockLatency
, getClockLatency
)
152 static DECLARE_FORWARD(CaptureWrapper
, ALCbackend
, void, lock
)
153 static DECLARE_FORWARD(CaptureWrapper
, ALCbackend
, void, unlock
)
154 DECLARE_DEFAULT_ALLOCATORS(CaptureWrapper
)
155 DEFINE_ALCBACKEND_VTABLE(CaptureWrapper
);
157 static void CaptureWrapper_Construct(CaptureWrapper
*self
, ALCdevice
*device
, const BackendFuncs
*funcs
)
159 ALCbackend_Construct(STATIC_CAST(ALCbackend
, self
), device
);
160 SET_VTABLE2(CaptureWrapper
, ALCbackend
, self
);
165 static ALCenum
CaptureWrapper_open(CaptureWrapper
*self
, const ALCchar
*name
)
167 ALCdevice
*device
= STATIC_CAST(ALCbackend
, self
)->mDevice
;
168 return self
->Funcs
->OpenCapture(device
, name
);
171 static void CaptureWrapper_close(CaptureWrapper
*self
)
173 ALCdevice
*device
= STATIC_CAST(ALCbackend
, self
)->mDevice
;
174 self
->Funcs
->CloseCapture(device
);
177 static ALCboolean
CaptureWrapper_start(CaptureWrapper
*self
)
179 ALCdevice
*device
= STATIC_CAST(ALCbackend
, self
)->mDevice
;
180 self
->Funcs
->StartCapture(device
);
184 static void CaptureWrapper_stop(CaptureWrapper
*self
)
186 ALCdevice
*device
= STATIC_CAST(ALCbackend
, self
)->mDevice
;
187 self
->Funcs
->StopCapture(device
);
190 static ALCenum
CaptureWrapper_captureSamples(CaptureWrapper
*self
, void *buffer
, ALCuint samples
)
192 ALCdevice
*device
= STATIC_CAST(ALCbackend
, self
)->mDevice
;
193 return self
->Funcs
->CaptureSamples(device
, buffer
, samples
);
196 static ALCuint
CaptureWrapper_availableSamples(CaptureWrapper
*self
)
198 ALCdevice
*device
= STATIC_CAST(ALCbackend
, self
)->mDevice
;
199 return self
->Funcs
->AvailableSamples(device
);
203 ALCbackend
*create_backend_wrapper(ALCdevice
*device
, const BackendFuncs
*funcs
, ALCbackend_Type type
)
205 if(type
== ALCbackend_Playback
)
207 PlaybackWrapper
*backend
;
209 NEW_OBJ(backend
, PlaybackWrapper
)(device
, funcs
);
210 if(!backend
) return NULL
;
212 return STATIC_CAST(ALCbackend
, backend
);
215 if(type
== ALCbackend_Capture
)
217 CaptureWrapper
*backend
;
219 NEW_OBJ(backend
, CaptureWrapper
)(device
, funcs
);
220 if(!backend
) return NULL
;
222 return STATIC_CAST(ALCbackend
, backend
);