Create and use a backend wrapper for capture

This commit is contained in:
Chris Robinson
2013-10-28 14:38:55 -07:00
parent f8c95f1e90
commit 21f1e54cb9
4 changed files with 142 additions and 50 deletions
+10 -13
View File
@@ -1909,10 +1909,7 @@ static ALCvoid FreeDevice(ALCdevice *device)
{
TRACE("%p\n", device);
if(device->Type != Capture)
VCALL0(device->Backend,close)();
else
ALCdevice_CloseCapture(device);
VCALL0(device->Backend,close)();
DELETE_OBJ(device->Backend);
device->Backend = NULL;
@@ -2405,7 +2402,7 @@ ALC_API ALCvoid ALC_APIENTRY alcGetIntegerv(ALCdevice *device,ALCenum param,ALsi
{
case ALC_CAPTURE_SAMPLES:
ALCdevice_Lock(device);
*data = ALCdevice_AvailableSamples(device);
*data = VCALL0(device->Backend,availableSamples)();
ALCdevice_Unlock(device);
break;
@@ -2890,7 +2887,7 @@ ALC_API ALCdevice* ALC_APIENTRY alcOpenDevice(const ALCchar *deviceName)
device->UpdateSize = 1024;
if(!PlaybackBackend.getFactory)
device->Backend = create_backend_wrapper(device);
device->Backend = create_backend_wrapper(device, ALCbackend_Playback);
else
{
ALCbackendFactory *factory = PlaybackBackend.getFactory();
@@ -3156,7 +3153,7 @@ ALC_API ALCdevice* ALC_APIENTRY alcCaptureOpenDevice(const ALCchar *deviceName,
device->DeviceName = NULL;
device->Backend = create_backend_wrapper(device);
device->Backend = create_backend_wrapper(device, ALCbackend_Capture);
if(!device->Backend)
{
al_free(device);
@@ -3178,7 +3175,7 @@ ALC_API ALCdevice* ALC_APIENTRY alcCaptureOpenDevice(const ALCchar *deviceName,
device->UpdateSize = samples;
device->NumUpdates = 1;
if((err=ALCdevice_OpenCapture(device, deviceName)) != ALC_NO_ERROR)
if((err=VCALL(device->Backend,open)(deviceName)) != ALC_NO_ERROR)
{
al_free(device);
alcSetError(NULL, err);
@@ -3227,7 +3224,7 @@ ALC_API void ALC_APIENTRY alcCaptureStart(ALCdevice *device)
if(device->Connected)
{
if(!(device->Flags&DEVICE_RUNNING))
ALCdevice_StartCapture(device);
VCALL0(device->Backend,start)();
device->Flags |= DEVICE_RUNNING;
}
ALCdevice_Unlock(device);
@@ -3244,7 +3241,7 @@ ALC_API void ALC_APIENTRY alcCaptureStop(ALCdevice *device)
{
ALCdevice_Lock(device);
if((device->Flags&DEVICE_RUNNING))
ALCdevice_StopCapture(device);
VCALL0(device->Backend,stop)();
device->Flags &= ~DEVICE_RUNNING;
ALCdevice_Unlock(device);
}
@@ -3261,8 +3258,8 @@ ALC_API void ALC_APIENTRY alcCaptureSamples(ALCdevice *device, ALCvoid *buffer,
ALCenum err = ALC_INVALID_VALUE;
ALCdevice_Lock(device);
if(samples >= 0 && ALCdevice_AvailableSamples(device) >= (ALCuint)samples)
err = ALCdevice_CaptureSamples(device, buffer, samples);
if(samples >= 0 && VCALL0(device->Backend,availableSamples)() >= (ALCuint)samples)
err = VCALL(device->Backend,captureSamples)(buffer, samples);
ALCdevice_Unlock(device);
if(err != ALC_NO_ERROR)
@@ -3322,7 +3319,7 @@ ALC_API ALCdevice* ALC_APIENTRY alcLoopbackOpenDeviceSOFT(const ALCchar *deviceN
InitUIntMap(&device->EffectMap, ~0);
InitUIntMap(&device->FilterMap, ~0);
device->Backend = create_backend_wrapper(device);
device->Backend = create_backend_wrapper(device, ALCbackend_Playback);
if(!device->Backend)
{
al_free(device);
+129 -28
View File
@@ -36,97 +36,198 @@ void ALCbackend_unlock(ALCbackend *self)
}
/* Wrapper to use an old-style backend with the new interface. */
typedef struct BackendWrapper {
/* Wrappers to use an old-style backend with the new interface. */
typedef struct PlaybackWrapper {
DERIVE_FROM_TYPE(ALCbackend);
} BackendWrapper;
#define BACKENDWRAPPER_INITIALIZER { { GET_VTABLE2(ALCbackend, BackendWrapper) } }
} PlaybackWrapper;
#define PLAYBACKWRAPPER_INITIALIZER { { GET_VTABLE2(ALCbackend, PlaybackWrapper) } }
static void BackendWrapper_Construct(BackendWrapper *self, ALCdevice *device)
static void PlaybackWrapper_Construct(PlaybackWrapper *self, ALCdevice *device)
{
ALCbackend_Construct(STATIC_CAST(ALCbackend, self), device);
}
static void BackendWrapper_Destruct(BackendWrapper *self)
static void PlaybackWrapper_Destruct(PlaybackWrapper *self)
{
ALCbackend_Destruct(STATIC_CAST(ALCbackend, self));
}
static ALCenum BackendWrapper_open(BackendWrapper *self, const ALCchar *name)
static ALCenum PlaybackWrapper_open(PlaybackWrapper *self, const ALCchar *name)
{
ALCdevice *device = STATIC_CAST(ALCbackend, self)->mDevice;
return device->Funcs->OpenPlayback(device, name);
}
static void BackendWrapper_close(BackendWrapper *self)
static void PlaybackWrapper_close(PlaybackWrapper *self)
{
ALCdevice *device = STATIC_CAST(ALCbackend, self)->mDevice;
device->Funcs->ClosePlayback(device);
}
static ALCboolean BackendWrapper_reset(BackendWrapper *self)
static ALCboolean PlaybackWrapper_reset(PlaybackWrapper *self)
{
ALCdevice *device = STATIC_CAST(ALCbackend, self)->mDevice;
return device->Funcs->ResetPlayback(device);
}
static ALCboolean BackendWrapper_start(BackendWrapper *self)
static ALCboolean PlaybackWrapper_start(PlaybackWrapper *self)
{
ALCdevice *device = STATIC_CAST(ALCbackend, self)->mDevice;
return device->Funcs->StartPlayback(device);
}
static void BackendWrapper_stop(BackendWrapper *self)
static void PlaybackWrapper_stop(PlaybackWrapper *self)
{
ALCdevice *device = STATIC_CAST(ALCbackend, self)->mDevice;
device->Funcs->StopPlayback(device);
}
ALCenum BackendWrapper_captureSamples(BackendWrapper* UNUSED(self), void* UNUSED(buffer), ALCuint UNUSED(samples))
ALCenum PlaybackWrapper_captureSamples(PlaybackWrapper* UNUSED(self), void* UNUSED(buffer), ALCuint UNUSED(samples))
{
return ALC_INVALID_VALUE;
}
ALCuint BackendWrapper_availableSamples(BackendWrapper* UNUSED(self))
ALCuint PlaybackWrapper_availableSamples(PlaybackWrapper* UNUSED(self))
{
return 0;
}
static ALint64 BackendWrapper_getLatency(BackendWrapper *self)
static ALint64 PlaybackWrapper_getLatency(PlaybackWrapper *self)
{
ALCdevice *device = STATIC_CAST(ALCbackend, self)->mDevice;
return device->Funcs->GetLatency(device);
}
static void BackendWrapper_lock(BackendWrapper *self)
static void PlaybackWrapper_lock(PlaybackWrapper *self)
{
ALCdevice *device = STATIC_CAST(ALCbackend, self)->mDevice;
return device->Funcs->Lock(device);
}
static void BackendWrapper_unlock(BackendWrapper *self)
static void PlaybackWrapper_unlock(PlaybackWrapper *self)
{
ALCdevice *device = STATIC_CAST(ALCbackend, self)->mDevice;
return device->Funcs->Unlock(device);
}
static void BackendWrapper_Delete(BackendWrapper *self)
static void PlaybackWrapper_Delete(PlaybackWrapper *self)
{
free(self);
}
DEFINE_ALCBACKEND_VTABLE(BackendWrapper);
DEFINE_ALCBACKEND_VTABLE(PlaybackWrapper);
ALCbackend *create_backend_wrapper(ALCdevice *device)
typedef struct CaptureWrapper {
DERIVE_FROM_TYPE(ALCbackend);
} CaptureWrapper;
#define CAPTUREWRAPPER_INITIALIZER { { GET_VTABLE2(ALCbackend, PlaybackWrapper) } }
static void CaptureWrapper_Construct(CaptureWrapper *self, ALCdevice *device)
{
BackendWrapper *backend;
backend = malloc(sizeof(*backend));
if(!backend) return NULL;
SET_VTABLE2(BackendWrapper, ALCbackend, backend);
BackendWrapper_Construct(backend, device);
return STATIC_CAST(ALCbackend, backend);
ALCbackend_Construct(STATIC_CAST(ALCbackend, self), device);
}
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;
return device->Funcs->Lock(device);
}
static void CaptureWrapper_unlock(CaptureWrapper *self)
{
ALCdevice *device = STATIC_CAST(ALCbackend, self)->mDevice;
return 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;
SET_VTABLE2(PlaybackWrapper, ALCbackend, backend);
PlaybackWrapper_Construct(backend, device);
return STATIC_CAST(ALCbackend, backend);
}
if(type == ALCbackend_Capture)
{
CaptureWrapper *backend;
backend = malloc(sizeof(*backend));
if(!backend) return NULL;
SET_VTABLE2(CaptureWrapper, ALCbackend, backend);
CaptureWrapper_Construct(backend, device);
return STATIC_CAST(ALCbackend, backend);
}
return NULL;
}
+3 -2
View File
@@ -87,7 +87,8 @@ static const struct ALCbackendVtable T##_ALCbackend_vtable = { \
typedef enum ALCbackend_Type {
ALCbackend_Playback
ALCbackend_Playback,
ALCbackend_Capture
} ALCbackend_Type;
@@ -131,6 +132,6 @@ static const struct ALCbackendFactoryVtable T##_ALCbackendFactory_vtable = { \
ALCbackendFactory *ALCnullBackendFactory_getFactory(void);
ALCbackend *create_backend_wrapper(ALCdevice *device);
ALCbackend *create_backend_wrapper(ALCdevice *device, ALCbackend_Type type);
#endif /* AL_BACKENDS_BASE_H */
-7
View File
@@ -407,13 +407,6 @@ struct ALCdevice_struct
ALCdevice *volatile next;
};
#define ALCdevice_OpenCapture(a,b) ((a)->Funcs->OpenCapture((a), (b)))
#define ALCdevice_CloseCapture(a) ((a)->Funcs->CloseCapture((a)))
#define ALCdevice_StartCapture(a) ((a)->Funcs->StartCapture((a)))
#define ALCdevice_StopCapture(a) ((a)->Funcs->StopCapture((a)))
#define ALCdevice_CaptureSamples(a,b,c) ((a)->Funcs->CaptureSamples((a), (b), (c)))
#define ALCdevice_AvailableSamples(a) ((a)->Funcs->AvailableSamples((a)))
// Frequency was requested by the app or config file
#define DEVICE_FREQUENCY_REQUEST (1<<1)
// Channel configuration was requested by the config file