aboutsummaryrefslogtreecommitdiffstats
path: root/Alc/backends/base.h
blob: f1da721d3bc1f693c8e0a31f735dd5fdf0b73844 (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
#ifndef AL_BACKENDS_BASE_H
#define AL_BACKENDS_BASE_H

#include "alMain.h"
#include "compat.h"


struct ALCbackendVtable;

typedef struct ALCbackend {
    const struct ALCbackendVtable *vtbl;

    ALCdevice *mDevice;

    CRITICAL_SECTION mMutex;
} ALCbackend;

void ALCbackend_Construct(ALCbackend *self, ALCdevice *device);
void ALCbackend_Destruct(ALCbackend *self);
ALint64 ALCbackend_getLatency(ALCbackend *self);
void ALCbackend_lock(ALCbackend *self);
void ALCbackend_unlock(ALCbackend *self);

struct ALCbackendVtable {
    void (*const Destruct)(ALCbackend *state);

    ALCenum (*const open)(ALCbackend*, const ALCchar*);
    void (*const close)(ALCbackend*);

    ALCboolean (*reset)(ALCbackend*);
    ALCboolean (*start)(ALCbackend*);
    void (*stop)(ALCbackend*);

    ALCenum (*captureSamples)(ALCbackend*, void*, ALCuint);
    ALCuint (*availableSamples)(ALCbackend*);

    ALint64 (*getLatency)(ALCbackend*);

    void (*lock)(ALCbackend*);
    void (*unlock)(ALCbackend*);

    void (*const Delete)(ALCbackend *state);
};

#define DEFINE_ALCBACKEND_VTABLE(T)                                           \
static void T##_ALCbackend_Destruct(ALCbackend *obj)                          \
{ T##_Destruct(STATIC_UPCAST(T, ALCbackend, obj)); }                          \
static ALCenum T##_ALCbackend_open(ALCbackend *obj, const ALCchar *p1)        \
{ return T##_open(STATIC_UPCAST(T, ALCbackend, obj), p1); }                   \
static void T##_ALCbackend_close(ALCbackend *obj)                             \
{ T##_close(STATIC_UPCAST(T, ALCbackend, obj)); }                             \
static ALCboolean T##_ALCbackend_reset(ALCbackend *obj)                       \
{ return T##_reset(STATIC_UPCAST(T, ALCbackend, obj)); }                      \
static ALCboolean T##_ALCbackend_start(ALCbackend *obj)                       \
{ return T##_start(STATIC_UPCAST(T, ALCbackend, obj)); }                      \
static void T##_ALCbackend_stop(ALCbackend *obj)                              \
{ T##_stop(STATIC_UPCAST(T, ALCbackend, obj)); }                              \
static ALCenum T##_ALCbackend_captureSamples(ALCbackend *obj, void *a, ALCuint b) \
{ return T##_captureSamples(STATIC_UPCAST(T, ALCbackend, obj), a, b); }           \
static ALCuint T##_ALCbackend_availableSamples(ALCbackend *obj)               \
{ return T##_availableSamples(STATIC_UPCAST(T, ALCbackend, obj)); }           \
static ALint64 T##_ALCbackend_getLatency(ALCbackend *obj)                     \
{ return T##_getLatency(STATIC_UPCAST(T, ALCbackend, obj)); }                 \
static void T##_ALCbackend_lock(ALCbackend *obj)                              \
{ T##_lock(STATIC_UPCAST(T, ALCbackend, obj)); }                              \
static void T##_ALCbackend_unlock(ALCbackend *obj)                            \
{ T##_unlock(STATIC_UPCAST(T, ALCbackend, obj)); }                            \
static void T##_ALCbackend_Delete(ALCbackend *obj)                            \
{ T##_Delete(STATIC_UPCAST(T, ALCbackend, obj)); }                            \
                                                                              \
static const struct ALCbackendVtable T##_ALCbackend_vtable = {                \
    T##_ALCbackend_Destruct,                                                  \
                                                                              \
    T##_ALCbackend_open,                                                      \
    T##_ALCbackend_close,                                                     \
    T##_ALCbackend_reset,                                                     \
    T##_ALCbackend_start,                                                     \
    T##_ALCbackend_stop,                                                      \
    T##_ALCbackend_captureSamples,                                            \
    T##_ALCbackend_availableSamples,                                          \
    T##_ALCbackend_getLatency,                                                \
    T##_ALCbackend_lock,                                                      \
    T##_ALCbackend_unlock,                                                    \
                                                                              \
    T##_ALCbackend_Delete,                                                    \
}


typedef enum ALCbackend_Type {
    ALCbackend_Playback,
    ALCbackend_Capture
} ALCbackend_Type;


struct ALCbackendFactoryVtable;

typedef struct ALCbackendFactory {
    const struct ALCbackendFactoryVtable *vtbl;
} ALCbackendFactory;

struct ALCbackendFactoryVtable {
    ALCboolean (*const init)(ALCbackendFactory *self);
    void (*const deinit)(ALCbackendFactory *self);

    ALCboolean (*const querySupport)(ALCbackendFactory *self, ALCbackend_Type type);

    void (*const probe)(ALCbackendFactory *self, enum DevProbe type);

    ALCbackend* (*const createBackend)(ALCbackendFactory *self, ALCdevice *device);
};

#define DEFINE_ALCBACKENDFACTORY_VTABLE(T)                                    \
static ALCboolean T##_ALCbackendFactory_init(ALCbackendFactory *obj)          \
{ return T##_init(STATIC_UPCAST(T, ALCbackendFactory, obj)); }                \
static void T##_ALCbackendFactory_deinit(ALCbackendFactory *obj)              \
{ T##_deinit(STATIC_UPCAST(T, ALCbackendFactory, obj)); }                     \
static ALCboolean T##_ALCbackendFactory_querySupport(ALCbackendFactory *obj, ALCbackend_Type a) \
{ return T##_querySupport(STATIC_UPCAST(T, ALCbackendFactory, obj), a); }                       \
static void T##_ALCbackendFactory_probe(ALCbackendFactory *obj, enum DevProbe a) \
{ T##_probe(STATIC_UPCAST(T, ALCbackendFactory, obj), a); }                      \
static ALCbackend* T##_ALCbackendFactory_createBackend(ALCbackendFactory *obj, ALCdevice *a) \
{ return T##_createBackend(STATIC_UPCAST(T, ALCbackendFactory, obj), a); }                   \
                                                                              \
static const struct ALCbackendFactoryVtable T##_ALCbackendFactory_vtable = {  \
    T##_ALCbackendFactory_init,                                               \
    T##_ALCbackendFactory_deinit,                                             \
    T##_ALCbackendFactory_querySupport,                                       \
    T##_ALCbackendFactory_probe,                                              \
    T##_ALCbackendFactory_createBackend,                                      \
}


ALCbackendFactory *ALCalsaBackendFactory_getFactory(void);
ALCbackendFactory *ALCnullBackendFactory_getFactory(void);

ALCbackend *create_backend_wrapper(ALCdevice *device, ALCbackend_Type type);

#endif /* AL_BACKENDS_BASE_H */