8 #include "backends/base.h"
11 /* Base ALCbackend method implementations. */
12 void ALCbackend_Construct(ALCbackend
*self
, ALCdevice
*device
)
15 self
->mDevice
= device
;
16 ret
= almtx_init(&self
->mMutex
, almtx_recursive
);
17 assert(ret
== althrd_success
);
20 void ALCbackend_Destruct(ALCbackend
*self
)
22 almtx_destroy(&self
->mMutex
);
25 ALCboolean
ALCbackend_reset(ALCbackend
* UNUSED(self
))
30 ALCenum
ALCbackend_captureSamples(ALCbackend
* UNUSED(self
), void* UNUSED(buffer
), ALCuint
UNUSED(samples
))
32 return ALC_INVALID_DEVICE
;
35 ALCuint
ALCbackend_availableSamples(ALCbackend
* UNUSED(self
))
40 ALint64
ALCbackend_getLatency(ALCbackend
* UNUSED(self
))
45 void ALCbackend_lock(ALCbackend
*self
)
47 int ret
= almtx_lock(&self
->mMutex
);
48 assert(ret
== althrd_success
);
51 void ALCbackend_unlock(ALCbackend
*self
)
53 int ret
= almtx_unlock(&self
->mMutex
);
54 assert(ret
== althrd_success
);
58 /* Base ALCbackendFactory method implementations. */
59 void ALCbackendFactory_deinit(ALCbackendFactory
* UNUSED(self
))
64 /* Wrappers to use an old-style backend with the new interface. */
65 typedef struct PlaybackWrapper
{
66 DERIVE_FROM_TYPE(ALCbackend
);
68 const BackendFuncs
*Funcs
;
71 static void PlaybackWrapper_Construct(PlaybackWrapper
*self
, ALCdevice
*device
, const BackendFuncs
*funcs
);
72 static DECLARE_FORWARD(PlaybackWrapper
, ALCbackend
, void, Destruct
)
73 static ALCenum
PlaybackWrapper_open(PlaybackWrapper
*self
, const ALCchar
*name
);
74 static void PlaybackWrapper_close(PlaybackWrapper
*self
);
75 static ALCboolean
PlaybackWrapper_reset(PlaybackWrapper
*self
);
76 static ALCboolean
PlaybackWrapper_start(PlaybackWrapper
*self
);
77 static void PlaybackWrapper_stop(PlaybackWrapper
*self
);
78 static DECLARE_FORWARD2(PlaybackWrapper
, ALCbackend
, ALCenum
, captureSamples
, void*, ALCuint
)
79 static DECLARE_FORWARD(PlaybackWrapper
, ALCbackend
, ALCuint
, availableSamples
)
80 static DECLARE_FORWARD(PlaybackWrapper
, ALCbackend
, ALint64
, getLatency
)
81 static DECLARE_FORWARD(PlaybackWrapper
, ALCbackend
, void, lock
)
82 static DECLARE_FORWARD(PlaybackWrapper
, ALCbackend
, void, unlock
)
83 DECLARE_DEFAULT_ALLOCATORS(PlaybackWrapper
)
84 DEFINE_ALCBACKEND_VTABLE(PlaybackWrapper
);
86 static void PlaybackWrapper_Construct(PlaybackWrapper
*self
, ALCdevice
*device
, const BackendFuncs
*funcs
)
88 ALCbackend_Construct(STATIC_CAST(ALCbackend
, self
), device
);
89 SET_VTABLE2(PlaybackWrapper
, ALCbackend
, self
);
94 static ALCenum
PlaybackWrapper_open(PlaybackWrapper
*self
, const ALCchar
*name
)
96 ALCdevice
*device
= STATIC_CAST(ALCbackend
, self
)->mDevice
;
97 return self
->Funcs
->OpenPlayback(device
, name
);
100 static void PlaybackWrapper_close(PlaybackWrapper
*self
)
102 ALCdevice
*device
= STATIC_CAST(ALCbackend
, self
)->mDevice
;
103 self
->Funcs
->ClosePlayback(device
);
106 static ALCboolean
PlaybackWrapper_reset(PlaybackWrapper
*self
)
108 ALCdevice
*device
= STATIC_CAST(ALCbackend
, self
)->mDevice
;
109 return self
->Funcs
->ResetPlayback(device
);
112 static ALCboolean
PlaybackWrapper_start(PlaybackWrapper
*self
)
114 ALCdevice
*device
= STATIC_CAST(ALCbackend
, self
)->mDevice
;
115 return self
->Funcs
->StartPlayback(device
);
118 static void PlaybackWrapper_stop(PlaybackWrapper
*self
)
120 ALCdevice
*device
= STATIC_CAST(ALCbackend
, self
)->mDevice
;
121 self
->Funcs
->StopPlayback(device
);
125 typedef struct CaptureWrapper
{
126 DERIVE_FROM_TYPE(ALCbackend
);
128 const BackendFuncs
*Funcs
;
131 static void CaptureWrapper_Construct(CaptureWrapper
*self
, ALCdevice
*device
, const BackendFuncs
*funcs
);
132 static DECLARE_FORWARD(CaptureWrapper
, ALCbackend
, void, Destruct
)
133 static ALCenum
CaptureWrapper_open(CaptureWrapper
*self
, const ALCchar
*name
);
134 static void CaptureWrapper_close(CaptureWrapper
*self
);
135 static DECLARE_FORWARD(CaptureWrapper
, ALCbackend
, ALCboolean
, reset
)
136 static ALCboolean
CaptureWrapper_start(CaptureWrapper
*self
);
137 static void CaptureWrapper_stop(CaptureWrapper
*self
);
138 static ALCenum
CaptureWrapper_captureSamples(CaptureWrapper
*self
, void *buffer
, ALCuint samples
);
139 static ALCuint
CaptureWrapper_availableSamples(CaptureWrapper
*self
);
140 static DECLARE_FORWARD(CaptureWrapper
, ALCbackend
, ALint64
, getLatency
)
141 static DECLARE_FORWARD(CaptureWrapper
, ALCbackend
, void, lock
)
142 static DECLARE_FORWARD(CaptureWrapper
, ALCbackend
, void, unlock
)
143 DECLARE_DEFAULT_ALLOCATORS(CaptureWrapper
)
144 DEFINE_ALCBACKEND_VTABLE(CaptureWrapper
);
146 static void CaptureWrapper_Construct(CaptureWrapper
*self
, ALCdevice
*device
, const BackendFuncs
*funcs
)
148 ALCbackend_Construct(STATIC_CAST(ALCbackend
, self
), device
);
149 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 self
->Funcs
->OpenCapture(device
, name
);
160 static void CaptureWrapper_close(CaptureWrapper
*self
)
162 ALCdevice
*device
= STATIC_CAST(ALCbackend
, self
)->mDevice
;
163 self
->Funcs
->CloseCapture(device
);
166 static ALCboolean
CaptureWrapper_start(CaptureWrapper
*self
)
168 ALCdevice
*device
= STATIC_CAST(ALCbackend
, self
)->mDevice
;
169 self
->Funcs
->StartCapture(device
);
173 static void CaptureWrapper_stop(CaptureWrapper
*self
)
175 ALCdevice
*device
= STATIC_CAST(ALCbackend
, self
)->mDevice
;
176 self
->Funcs
->StopCapture(device
);
179 static ALCenum
CaptureWrapper_captureSamples(CaptureWrapper
*self
, void *buffer
, ALCuint samples
)
181 ALCdevice
*device
= STATIC_CAST(ALCbackend
, self
)->mDevice
;
182 return self
->Funcs
->CaptureSamples(device
, buffer
, samples
);
185 static ALCuint
CaptureWrapper_availableSamples(CaptureWrapper
*self
)
187 ALCdevice
*device
= STATIC_CAST(ALCbackend
, self
)->mDevice
;
188 return self
->Funcs
->AvailableSamples(device
);
192 ALCbackend
*create_backend_wrapper(ALCdevice
*device
, const BackendFuncs
*funcs
, ALCbackend_Type type
)
194 if(type
== ALCbackend_Playback
)
196 PlaybackWrapper
*backend
;
198 backend
= PlaybackWrapper_New(sizeof(*backend
));
199 if(!backend
) return NULL
;
201 PlaybackWrapper_Construct(backend
, device
, funcs
);
203 return STATIC_CAST(ALCbackend
, backend
);
206 if(type
== ALCbackend_Capture
)
208 CaptureWrapper
*backend
;
210 backend
= CaptureWrapper_New(sizeof(*backend
));
211 if(!backend
) return NULL
;
213 CaptureWrapper_Construct(backend
, device
, funcs
);
215 return STATIC_CAST(ALCbackend
, backend
);