aboutsummaryrefslogtreecommitdiffstats
path: root/Alc/backends/base.c
blob: 0c28599333e0ba2c88e31ed9dae2a5fbbe56d2a5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248

#include "config.h"

#include <stdlib.h>

#include "alMain.h"

#include "backends/base.h"


/* Base ALCbackend method implementations. */
void ALCbackend_Construct(ALCbackend *self, ALCdevice *device)
{
    self->mDevice = device;
    InitializeCriticalSection(&self->mMutex);
}

void ALCbackend_Destruct(ALCbackend *self)
{
    DeleteCriticalSection(&self->mMutex);
}

ALCboolean ALCbackend_reset(ALCbackend* UNUSED(self))
{
    return ALC_FALSE;
}

ALCenum ALCbackend_captureSamples(ALCbackend* UNUSED(self), void* UNUSED(buffer), ALCuint UNUSED(samples))
{
    return ALC_INVALID_DEVICE;
}

ALCuint ALCbackend_availableSamples(ALCbackend* UNUSED(self))
{
    return 0;
}

ALint64 ALCbackend_getLatency(ALCbackend* UNUSED(self))
{
    return 0;
}

void ALCbackend_lock(ALCbackend *self)
{
    EnterCriticalSection(&self->mMutex);
}

void ALCbackend_unlock(ALCbackend *self)
{
    LeaveCriticalSection(&self->mMutex);
}


/* Wrappers to use an old-style backend with the new interface. */
typedef struct PlaybackWrapper {
    DERIVE_FROM_TYPE(ALCbackend);
} PlaybackWrapper;
DECLARE_ALCBACKEND_VTABLE(PlaybackWrapper);

static void PlaybackWrapper_Construct(PlaybackWrapper *self, ALCdevice *device)
{
    ALCbackend_Construct(STATIC_CAST(ALCbackend, self), device);
    SET_VTABLE2(PlaybackWrapper, ALCbackend, self);
}

static void PlaybackWrapper_Destruct(PlaybackWrapper *self)
{
    ALCbackend_Destruct(STATIC_CAST(ALCbackend, self));
}

static ALCenum PlaybackWrapper_open(PlaybackWrapper *self, const ALCchar *name)
{
    ALCdevice *device = STATIC_CAST(ALCbackend, self)->mDevice;
    return device->Funcs->OpenPlayback(device, name);
}

static void PlaybackWrapper_close(PlaybackWrapper *self)
{
    ALCdevice *device = STATIC_CAST(ALCbackend, self)->mDevice;
    device->Funcs->ClosePlayback(device);
}

static ALCboolean PlaybackWrapper_reset(PlaybackWrapper *self)
{
    ALCdevice *device = STATIC_CAST(ALCbackend, self)->mDevice;
    return device->Funcs->ResetPlayback(device);
}

static ALCboolean PlaybackWrapper_start(PlaybackWrapper *self)
{
    ALCdevice *device = STATIC_CAST(ALCbackend, self)->mDevice;
    return device->Funcs->StartPlayback(device);
}

static void PlaybackWrapper_stop(PlaybackWrapper *self)
{
    ALCdevice *device = STATIC_CAST(ALCbackend, self)->mDevice;
    device->Funcs->StopPlayback(device);
}

ALCenum PlaybackWrapper_captureSamples(PlaybackWrapper* UNUSED(self), void* UNUSED(buffer), ALCuint UNUSED(samples))
{
    return ALC_INVALID_VALUE;
}

ALCuint PlaybackWrapper_availableSamples(PlaybackWrapper* UNUSED(self))
{
    return 0;
}

static ALint64 PlaybackWrapper_getLatency(PlaybackWrapper *self)
{
    ALCdevice *device = STATIC_CAST(ALCbackend, self)->mDevice;
    return device->Funcs->GetLatency(device);
}

static void PlaybackWrapper_lock(PlaybackWrapper *self)
{
    ALCdevice *device = STATIC_CAST(ALCbackend, self)->mDevice;
    device->Funcs->Lock(device);
}

static void PlaybackWrapper_unlock(PlaybackWrapper *self)
{
    ALCdevice *device = STATIC_CAST(ALCbackend, self)->mDevice;
    device->Funcs->Unlock(device);
}

static void PlaybackWrapper_Delete(PlaybackWrapper *self)
{
    free(self);
}

DEFINE_ALCBACKEND_VTABLE(PlaybackWrapper);


typedef struct CaptureWrapper {
    DERIVE_FROM_TYPE(ALCbackend);
} CaptureWrapper;
DECLARE_ALCBACKEND_VTABLE(CaptureWrapper);

static void CaptureWrapper_Construct(CaptureWrapper *self, ALCdevice *device)
{
    ALCbackend_Construct(STATIC_CAST(ALCbackend, self), device);
    SET_VTABLE2(CaptureWrapper, ALCbackend, self);
}

static void CaptureWrapper_Destruct(CaptureWrapper *self)
{
    ALCbackend_Destruct(STATIC_CAST(ALCbackend, self));
}

static ALCenum CaptureWrapper_open(CaptureWrapper *self, const ALCchar *name)
{
    ALCdevice *device = STATIC_CAST(ALCbackend, self)->mDevice;
    return device->Funcs->OpenCapture(device, name);
}

static void CaptureWrapper_close(CaptureWrapper *self)
{
    ALCdevice *device = STATIC_CAST(ALCbackend, self)->mDevice;
    device->Funcs->CloseCapture(device);
}

static ALCboolean CaptureWrapper_reset(CaptureWrapper* UNUSED(self))
{
    return ALC_FALSE;
}

static ALCboolean CaptureWrapper_start(CaptureWrapper *self)
{
    ALCdevice *device = STATIC_CAST(ALCbackend, self)->mDevice;
    device->Funcs->StartCapture(device);
    return ALC_TRUE;
}

static void CaptureWrapper_stop(CaptureWrapper *self)
{
    ALCdevice *device = STATIC_CAST(ALCbackend, self)->mDevice;
    device->Funcs->StopCapture(device);
}

ALCenum CaptureWrapper_captureSamples(CaptureWrapper *self, void *buffer, ALCuint samples)
{
    ALCdevice *device = STATIC_CAST(ALCbackend, self)->mDevice;
    return device->Funcs->CaptureSamples(device, buffer, samples);
}

ALCuint CaptureWrapper_availableSamples(CaptureWrapper *self)
{
    ALCdevice *device = STATIC_CAST(ALCbackend, self)->mDevice;
    return device->Funcs->AvailableSamples(device);
}

static ALint64 CaptureWrapper_getLatency(CaptureWrapper *self)
{
    ALCdevice *device = STATIC_CAST(ALCbackend, self)->mDevice;
    return device->Funcs->GetLatency(device);
}

static void CaptureWrapper_lock(CaptureWrapper *self)
{
    ALCdevice *device = STATIC_CAST(ALCbackend, self)->mDevice;
    device->Funcs->Lock(device);
}

static void CaptureWrapper_unlock(CaptureWrapper *self)
{
    ALCdevice *device = STATIC_CAST(ALCbackend, self)->mDevice;
    device->Funcs->Unlock(device);
}

static void CaptureWrapper_Delete(CaptureWrapper *self)
{
    free(self);
}

DEFINE_ALCBACKEND_VTABLE(CaptureWrapper);


ALCbackend *create_backend_wrapper(ALCdevice *device, ALCbackend_Type type)
{
    if(type == ALCbackend_Playback)
    {
        PlaybackWrapper *backend;

        backend = malloc(sizeof(*backend));
        if(!backend) return NULL;

        PlaybackWrapper_Construct(backend, device);

        return STATIC_CAST(ALCbackend, backend);
    }

    if(type == ALCbackend_Capture)
    {
        CaptureWrapper *backend;

        backend = malloc(sizeof(*backend));
        if(!backend) return NULL;

        CaptureWrapper_Construct(backend, device);

        return STATIC_CAST(ALCbackend, backend);
    }

    return NULL;
}