8 #include "backends/base.h"
11 /* Base ALCbackend method implementations. */
12 void ALCbackend_Construct(ALCbackend
*self
, ALCdevice
*device
)
14 self
->mDevice
= device
;
15 InitializeCriticalSection(&self
->mMutex
);
18 void ALCbackend_Destruct(ALCbackend
*self
)
20 DeleteCriticalSection(&self
->mMutex
);
23 ALCboolean
ALCbackend_reset(ALCbackend
* UNUSED(self
))
28 ALCenum
ALCbackend_captureSamples(ALCbackend
* UNUSED(self
), void* UNUSED(buffer
), ALCuint
UNUSED(samples
))
30 return ALC_INVALID_DEVICE
;
33 ALCuint
ALCbackend_availableSamples(ALCbackend
* UNUSED(self
))
38 ALint64
ALCbackend_getLatency(ALCbackend
* UNUSED(self
))
43 void ALCbackend_lock(ALCbackend
*self
)
45 EnterCriticalSection(&self
->mMutex
);
48 void ALCbackend_unlock(ALCbackend
*self
)
50 LeaveCriticalSection(&self
->mMutex
);
54 /* Base ALCbackendFactory method implementations. */
55 void ALCbackendFactory_deinit(ALCbackendFactory
* UNUSED(self
))
60 /* Wrappers to use an old-style backend with the new interface. */
61 typedef struct PlaybackWrapper
{
62 DERIVE_FROM_TYPE(ALCbackend
);
65 static void PlaybackWrapper_Construct(PlaybackWrapper
*self
, ALCdevice
*device
);
66 static DECLARE_FORWARD(PlaybackWrapper
, ALCbackend
, void, Destruct
)
67 static ALCenum
PlaybackWrapper_open(PlaybackWrapper
*self
, const ALCchar
*name
);
68 static void PlaybackWrapper_close(PlaybackWrapper
*self
);
69 static ALCboolean
PlaybackWrapper_reset(PlaybackWrapper
*self
);
70 static ALCboolean
PlaybackWrapper_start(PlaybackWrapper
*self
);
71 static void PlaybackWrapper_stop(PlaybackWrapper
*self
);
72 static DECLARE_FORWARD2(PlaybackWrapper
, ALCbackend
, ALCenum
, captureSamples
, void*, ALCuint
)
73 static DECLARE_FORWARD(PlaybackWrapper
, ALCbackend
, ALCuint
, availableSamples
)
74 static ALint64
PlaybackWrapper_getLatency(PlaybackWrapper
*self
);
75 static DECLARE_FORWARD(PlaybackWrapper
, ALCbackend
, void, lock
)
76 static DECLARE_FORWARD(PlaybackWrapper
, ALCbackend
, void, unlock
)
77 static void PlaybackWrapper_Delete(PlaybackWrapper
*self
);
78 DEFINE_ALCBACKEND_VTABLE(PlaybackWrapper
);
80 static void PlaybackWrapper_Construct(PlaybackWrapper
*self
, ALCdevice
*device
)
82 ALCbackend_Construct(STATIC_CAST(ALCbackend
, self
), device
);
83 SET_VTABLE2(PlaybackWrapper
, ALCbackend
, self
);
86 static ALCenum
PlaybackWrapper_open(PlaybackWrapper
*self
, const ALCchar
*name
)
88 ALCdevice
*device
= STATIC_CAST(ALCbackend
, self
)->mDevice
;
89 return device
->Funcs
->OpenPlayback(device
, name
);
92 static void PlaybackWrapper_close(PlaybackWrapper
*self
)
94 ALCdevice
*device
= STATIC_CAST(ALCbackend
, self
)->mDevice
;
95 device
->Funcs
->ClosePlayback(device
);
98 static ALCboolean
PlaybackWrapper_reset(PlaybackWrapper
*self
)
100 ALCdevice
*device
= STATIC_CAST(ALCbackend
, self
)->mDevice
;
101 return device
->Funcs
->ResetPlayback(device
);
104 static ALCboolean
PlaybackWrapper_start(PlaybackWrapper
*self
)
106 ALCdevice
*device
= STATIC_CAST(ALCbackend
, self
)->mDevice
;
107 return device
->Funcs
->StartPlayback(device
);
110 static void PlaybackWrapper_stop(PlaybackWrapper
*self
)
112 ALCdevice
*device
= STATIC_CAST(ALCbackend
, self
)->mDevice
;
113 device
->Funcs
->StopPlayback(device
);
116 static ALint64
PlaybackWrapper_getLatency(PlaybackWrapper
*self
)
118 ALCdevice
*device
= STATIC_CAST(ALCbackend
, self
)->mDevice
;
119 return device
->Funcs
->GetLatency(device
);
122 static void PlaybackWrapper_Delete(PlaybackWrapper
*self
)
128 typedef struct CaptureWrapper
{
129 DERIVE_FROM_TYPE(ALCbackend
);
132 static void CaptureWrapper_Construct(CaptureWrapper
*self
, ALCdevice
*device
);
133 static DECLARE_FORWARD(CaptureWrapper
, ALCbackend
, void, Destruct
)
134 static ALCenum
CaptureWrapper_open(CaptureWrapper
*self
, const ALCchar
*name
);
135 static void CaptureWrapper_close(CaptureWrapper
*self
);
136 static DECLARE_FORWARD(CaptureWrapper
, ALCbackend
, ALCboolean
, reset
)
137 static ALCboolean
CaptureWrapper_start(CaptureWrapper
*self
);
138 static void CaptureWrapper_stop(CaptureWrapper
*self
);
139 static ALCenum
CaptureWrapper_captureSamples(CaptureWrapper
*self
, void *buffer
, ALCuint samples
);
140 static ALCuint
CaptureWrapper_availableSamples(CaptureWrapper
*self
);
141 static ALint64
CaptureWrapper_getLatency(CaptureWrapper
*self
);
142 static DECLARE_FORWARD(CaptureWrapper
, ALCbackend
, void, lock
)
143 static DECLARE_FORWARD(CaptureWrapper
, ALCbackend
, void, unlock
)
144 static void CaptureWrapper_Delete(CaptureWrapper
*self
);
145 DEFINE_ALCBACKEND_VTABLE(CaptureWrapper
);
148 static void CaptureWrapper_Construct(CaptureWrapper
*self
, ALCdevice
*device
)
150 ALCbackend_Construct(STATIC_CAST(ALCbackend
, self
), device
);
151 SET_VTABLE2(CaptureWrapper
, ALCbackend
, self
);
154 static ALCenum
CaptureWrapper_open(CaptureWrapper
*self
, const ALCchar
*name
)
156 ALCdevice
*device
= STATIC_CAST(ALCbackend
, self
)->mDevice
;
157 return device
->Funcs
->OpenCapture(device
, name
);
160 static void CaptureWrapper_close(CaptureWrapper
*self
)
162 ALCdevice
*device
= STATIC_CAST(ALCbackend
, self
)->mDevice
;
163 device
->Funcs
->CloseCapture(device
);
166 static ALCboolean
CaptureWrapper_start(CaptureWrapper
*self
)
168 ALCdevice
*device
= STATIC_CAST(ALCbackend
, self
)->mDevice
;
169 device
->Funcs
->StartCapture(device
);
173 static void CaptureWrapper_stop(CaptureWrapper
*self
)
175 ALCdevice
*device
= STATIC_CAST(ALCbackend
, self
)->mDevice
;
176 device
->Funcs
->StopCapture(device
);
179 static ALCenum
CaptureWrapper_captureSamples(CaptureWrapper
*self
, void *buffer
, ALCuint samples
)
181 ALCdevice
*device
= STATIC_CAST(ALCbackend
, self
)->mDevice
;
182 return device
->Funcs
->CaptureSamples(device
, buffer
, samples
);
185 static ALCuint
CaptureWrapper_availableSamples(CaptureWrapper
*self
)
187 ALCdevice
*device
= STATIC_CAST(ALCbackend
, self
)->mDevice
;
188 return device
->Funcs
->AvailableSamples(device
);
191 static ALint64
CaptureWrapper_getLatency(CaptureWrapper
*self
)
193 ALCdevice
*device
= STATIC_CAST(ALCbackend
, self
)->mDevice
;
194 return device
->Funcs
->GetLatency(device
);
197 static void CaptureWrapper_Delete(CaptureWrapper
*self
)
203 ALCbackend
*create_backend_wrapper(ALCdevice
*device
, ALCbackend_Type type
)
205 if(type
== ALCbackend_Playback
)
207 PlaybackWrapper
*backend
;
209 backend
= malloc(sizeof(*backend
));
210 if(!backend
) return NULL
;
212 PlaybackWrapper_Construct(backend
, device
);
214 return STATIC_CAST(ALCbackend
, backend
);
217 if(type
== ALCbackend_Capture
)
219 CaptureWrapper
*backend
;
221 backend
= malloc(sizeof(*backend
));
222 if(!backend
) return NULL
;
224 CaptureWrapper_Construct(backend
, device
);
226 return STATIC_CAST(ALCbackend
, backend
);