base.h 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. #ifndef AL_BACKENDS_BASE_H
  2. #define AL_BACKENDS_BASE_H
  3. #include "alMain.h"
  4. #include "compat.h"
  5. struct ALCbackendVtable;
  6. typedef struct ALCbackend {
  7. const struct ALCbackendVtable *vtbl;
  8. ALCdevice *mDevice;
  9. CRITICAL_SECTION mMutex;
  10. } ALCbackend;
  11. void ALCbackend_Construct(ALCbackend *self, ALCdevice *device);
  12. void ALCbackend_Destruct(ALCbackend *self);
  13. ALCboolean ALCbackend_reset(ALCbackend *self);
  14. ALCenum ALCbackend_captureSamples(ALCbackend *self, void *buffer, ALCuint samples);
  15. ALCuint ALCbackend_availableSamples(ALCbackend *self);
  16. ALint64 ALCbackend_getLatency(ALCbackend *self);
  17. void ALCbackend_lock(ALCbackend *self);
  18. void ALCbackend_unlock(ALCbackend *self);
  19. struct ALCbackendVtable {
  20. void (*const Destruct)(ALCbackend*);
  21. ALCenum (*const open)(ALCbackend*, const ALCchar*);
  22. void (*const close)(ALCbackend*);
  23. ALCboolean (*const reset)(ALCbackend*);
  24. ALCboolean (*const start)(ALCbackend*);
  25. void (*const stop)(ALCbackend*);
  26. ALCenum (*const captureSamples)(ALCbackend*, void*, ALCuint);
  27. ALCuint (*const availableSamples)(ALCbackend*);
  28. ALint64 (*const getLatency)(ALCbackend*);
  29. void (*const lock)(ALCbackend*);
  30. void (*const unlock)(ALCbackend*);
  31. void (*const Delete)(ALCbackend*);
  32. };
  33. #define DECLARE_ALCBACKEND_VTABLE(T) \
  34. static const struct ALCbackendVtable T##_ALCbackend_vtable
  35. #define DEFINE_ALCBACKEND_VTABLE(T) \
  36. DECLARE_THUNK(T, ALCbackend, void, Destruct) \
  37. DECLARE_THUNK1(T, ALCbackend, ALCenum, open, const ALCchar*) \
  38. DECLARE_THUNK(T, ALCbackend, void, close) \
  39. DECLARE_THUNK(T, ALCbackend, ALCboolean, reset) \
  40. DECLARE_THUNK(T, ALCbackend, ALCboolean, start) \
  41. DECLARE_THUNK(T, ALCbackend, void, stop) \
  42. DECLARE_THUNK2(T, ALCbackend, ALCenum, captureSamples, void*, ALCuint) \
  43. DECLARE_THUNK(T, ALCbackend, ALCuint, availableSamples) \
  44. DECLARE_THUNK(T, ALCbackend, ALint64, getLatency) \
  45. DECLARE_THUNK(T, ALCbackend, void, lock) \
  46. DECLARE_THUNK(T, ALCbackend, void, unlock) \
  47. DECLARE_THUNK(T, ALCbackend, void, Delete) \
  48. \
  49. DECLARE_ALCBACKEND_VTABLE(T) = { \
  50. T##_ALCbackend_Destruct, \
  51. \
  52. T##_ALCbackend_open, \
  53. T##_ALCbackend_close, \
  54. T##_ALCbackend_reset, \
  55. T##_ALCbackend_start, \
  56. T##_ALCbackend_stop, \
  57. T##_ALCbackend_captureSamples, \
  58. T##_ALCbackend_availableSamples, \
  59. T##_ALCbackend_getLatency, \
  60. T##_ALCbackend_lock, \
  61. T##_ALCbackend_unlock, \
  62. \
  63. T##_ALCbackend_Delete, \
  64. }
  65. typedef enum ALCbackend_Type {
  66. ALCbackend_Playback,
  67. ALCbackend_Capture,
  68. ALCbackend_Loopback
  69. } ALCbackend_Type;
  70. struct ALCbackendFactoryVtable;
  71. typedef struct ALCbackendFactory {
  72. const struct ALCbackendFactoryVtable *vtbl;
  73. } ALCbackendFactory;
  74. void ALCbackendFactory_deinit(ALCbackendFactory *self);
  75. struct ALCbackendFactoryVtable {
  76. ALCboolean (*const init)(ALCbackendFactory *self);
  77. void (*const deinit)(ALCbackendFactory *self);
  78. ALCboolean (*const querySupport)(ALCbackendFactory *self, ALCbackend_Type type);
  79. void (*const probe)(ALCbackendFactory *self, enum DevProbe type);
  80. ALCbackend* (*const createBackend)(ALCbackendFactory *self, ALCdevice *device, ALCbackend_Type type);
  81. };
  82. #define DEFINE_ALCBACKENDFACTORY_VTABLE(T) \
  83. DECLARE_THUNK(T, ALCbackendFactory, ALCboolean, init) \
  84. DECLARE_THUNK(T, ALCbackendFactory, void, deinit) \
  85. DECLARE_THUNK1(T, ALCbackendFactory, ALCboolean, querySupport, ALCbackend_Type) \
  86. DECLARE_THUNK1(T, ALCbackendFactory, void, probe, enum DevProbe) \
  87. DECLARE_THUNK2(T, ALCbackendFactory, ALCbackend*, createBackend, ALCdevice*, ALCbackend_Type) \
  88. \
  89. static const struct ALCbackendFactoryVtable T##_ALCbackendFactory_vtable = { \
  90. T##_ALCbackendFactory_init, \
  91. T##_ALCbackendFactory_deinit, \
  92. T##_ALCbackendFactory_querySupport, \
  93. T##_ALCbackendFactory_probe, \
  94. T##_ALCbackendFactory_createBackend, \
  95. }
  96. ALCbackendFactory *ALCpulseBackendFactory_getFactory(void);
  97. ALCbackendFactory *ALCalsaBackendFactory_getFactory(void);
  98. ALCbackendFactory *ALCossBackendFactory_getFactory(void);
  99. ALCbackendFactory *ALCnullBackendFactory_getFactory(void);
  100. ALCbackendFactory *ALCloopbackFactory_getFactory(void);
  101. ALCbackend *create_backend_wrapper(ALCdevice *device, ALCbackend_Type type);
  102. #endif /* AL_BACKENDS_BASE_H */