Move the device mutex to the backend
This commit is contained in:
@@ -114,8 +114,14 @@ typedef struct BackendWrapper {
|
||||
} BackendWrapper;
|
||||
#define BACKENDWRAPPER_INITIALIZER { { GET_VTABLE2(ALCbackend, BackendWrapper) } }
|
||||
|
||||
static void BackendWrapper_Destruct(BackendWrapper* UNUSED(self))
|
||||
static void BackendWrapper_Construct(BackendWrapper *self, ALCdevice *device)
|
||||
{
|
||||
ALCbackend_Construct(STATIC_CAST(ALCbackend, self), device);
|
||||
}
|
||||
|
||||
static void BackendWrapper_Destruct(BackendWrapper *self)
|
||||
{
|
||||
ALCbackend_Destruct(STATIC_CAST(ALCbackend, self));
|
||||
}
|
||||
|
||||
static ALCenum BackendWrapper_open(BackendWrapper *self, const ALCchar *name)
|
||||
@@ -182,7 +188,7 @@ ALCbackend *create_backend_wrapper(ALCdevice *device)
|
||||
if(!backend) return NULL;
|
||||
SET_VTABLE2(BackendWrapper, ALCbackend, backend);
|
||||
|
||||
STATIC_CAST(ALCbackend, backend)->mDevice = device;
|
||||
BackendWrapper_Construct(backend, device);
|
||||
|
||||
return STATIC_CAST(ALCbackend, backend);
|
||||
}
|
||||
@@ -1466,11 +1472,11 @@ static ALCboolean IsValidALCChannels(ALCenum channels)
|
||||
|
||||
void ALCdevice_LockDefault(ALCdevice *device)
|
||||
{
|
||||
EnterCriticalSection(&device->Mutex);
|
||||
ALCbackend_lock(device->Backend);
|
||||
}
|
||||
void ALCdevice_UnlockDefault(ALCdevice *device)
|
||||
{
|
||||
LeaveCriticalSection(&device->Mutex);
|
||||
ALCbackend_unlock(device->Backend);
|
||||
}
|
||||
ALint64 ALCdevice_GetLatencyDefault(ALCdevice *UNUSED(device))
|
||||
{
|
||||
@@ -1504,6 +1510,18 @@ void UnlockContext(ALCcontext *context)
|
||||
}
|
||||
|
||||
|
||||
/* These should go to a seaparate source. */
|
||||
void ALCbackend_Construct(ALCbackend *self, ALCdevice *device)
|
||||
{
|
||||
self->mDevice = device;
|
||||
InitializeCriticalSection(&self->mMutex);
|
||||
}
|
||||
|
||||
void ALCbackend_Destruct(ALCbackend *self)
|
||||
{
|
||||
DeleteCriticalSection(&self->mMutex);
|
||||
}
|
||||
|
||||
ALint64 ALCbackend_getLatency(ALCbackend* UNUSED(self))
|
||||
{
|
||||
return 0;
|
||||
@@ -1511,12 +1529,12 @@ ALint64 ALCbackend_getLatency(ALCbackend* UNUSED(self))
|
||||
|
||||
void ALCbackend_lock(ALCbackend *self)
|
||||
{
|
||||
ALCdevice_LockDefault(self->mDevice);
|
||||
EnterCriticalSection(&self->mMutex);
|
||||
}
|
||||
|
||||
void ALCbackend_unlock(ALCbackend *self)
|
||||
{
|
||||
ALCdevice_UnlockDefault(self->mDevice);
|
||||
LeaveCriticalSection(&self->mMutex);
|
||||
}
|
||||
|
||||
|
||||
@@ -2046,8 +2064,6 @@ static ALCvoid FreeDevice(ALCdevice *device)
|
||||
free(device->DeviceName);
|
||||
device->DeviceName = NULL;
|
||||
|
||||
DeleteCriticalSection(&device->Mutex);
|
||||
|
||||
al_free(device);
|
||||
}
|
||||
|
||||
@@ -2963,7 +2979,6 @@ ALC_API ALCdevice* ALC_APIENTRY alcOpenDevice(const ALCchar *deviceName)
|
||||
device->ref = 1;
|
||||
device->Connected = ALC_TRUE;
|
||||
device->Type = Playback;
|
||||
InitializeCriticalSection(&device->Mutex);
|
||||
device->LastError = ALC_NO_ERROR;
|
||||
|
||||
device->Flags = 0;
|
||||
@@ -2997,7 +3012,6 @@ ALC_API ALCdevice* ALC_APIENTRY alcOpenDevice(const ALCchar *deviceName)
|
||||
}
|
||||
if(!device->Backend)
|
||||
{
|
||||
DeleteCriticalSection(&device->Mutex);
|
||||
al_free(device);
|
||||
alcSetError(NULL, ALC_OUT_OF_MEMORY);
|
||||
return NULL;
|
||||
@@ -3143,7 +3157,6 @@ ALC_API ALCdevice* ALC_APIENTRY alcOpenDevice(const ALCchar *deviceName)
|
||||
if((err=VCALL(device->Backend,open)(deviceName)) != ALC_NO_ERROR)
|
||||
{
|
||||
DELETE_OBJ(device->Backend);
|
||||
DeleteCriticalSection(&device->Mutex);
|
||||
al_free(device);
|
||||
alcSetError(NULL, err);
|
||||
return NULL;
|
||||
@@ -3250,7 +3263,6 @@ ALC_API ALCdevice* ALC_APIENTRY alcCaptureOpenDevice(const ALCchar *deviceName,
|
||||
device->ref = 1;
|
||||
device->Connected = ALC_TRUE;
|
||||
device->Type = Capture;
|
||||
InitializeCriticalSection(&device->Mutex);
|
||||
|
||||
InitUIntMap(&device->BufferMap, ~0);
|
||||
InitUIntMap(&device->EffectMap, ~0);
|
||||
@@ -3258,13 +3270,20 @@ ALC_API ALCdevice* ALC_APIENTRY alcCaptureOpenDevice(const ALCchar *deviceName,
|
||||
|
||||
device->DeviceName = NULL;
|
||||
|
||||
device->Backend = create_backend_wrapper(device);
|
||||
if(!device->Backend)
|
||||
{
|
||||
al_free(device);
|
||||
alcSetError(NULL, ALC_OUT_OF_MEMORY);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
device->Flags |= DEVICE_FREQUENCY_REQUEST;
|
||||
device->Frequency = frequency;
|
||||
|
||||
device->Flags |= DEVICE_CHANNELS_REQUEST | DEVICE_SAMPLE_TYPE_REQUEST;
|
||||
if(DecomposeDevFormat(format, &device->FmtChans, &device->FmtType) == AL_FALSE)
|
||||
{
|
||||
DeleteCriticalSection(&device->Mutex);
|
||||
al_free(device);
|
||||
alcSetError(NULL, ALC_INVALID_ENUM);
|
||||
return NULL;
|
||||
@@ -3275,7 +3294,6 @@ ALC_API ALCdevice* ALC_APIENTRY alcCaptureOpenDevice(const ALCchar *deviceName,
|
||||
|
||||
if((err=ALCdevice_OpenCapture(device, deviceName)) != ALC_NO_ERROR)
|
||||
{
|
||||
DeleteCriticalSection(&device->Mutex);
|
||||
al_free(device);
|
||||
alcSetError(NULL, err);
|
||||
return NULL;
|
||||
@@ -3401,7 +3419,6 @@ ALC_API ALCdevice* ALC_APIENTRY alcLoopbackOpenDeviceSOFT(const ALCchar *deviceN
|
||||
device->ref = 1;
|
||||
device->Connected = ALC_TRUE;
|
||||
device->Type = Loopback;
|
||||
InitializeCriticalSection(&device->Mutex);
|
||||
device->LastError = ALC_NO_ERROR;
|
||||
|
||||
device->Flags = 0;
|
||||
@@ -3420,6 +3437,12 @@ ALC_API ALCdevice* ALC_APIENTRY alcLoopbackOpenDeviceSOFT(const ALCchar *deviceN
|
||||
InitUIntMap(&device->FilterMap, ~0);
|
||||
|
||||
device->Backend = create_backend_wrapper(device);
|
||||
if(!device->Backend)
|
||||
{
|
||||
al_free(device);
|
||||
alcSetError(NULL, ALC_OUT_OF_MEMORY);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
//Set output format
|
||||
device->NumUpdates = 0;
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "alMain.h"
|
||||
#include "compat.h"
|
||||
|
||||
|
||||
struct RingBuffer {
|
||||
|
||||
@@ -27,6 +27,7 @@
|
||||
#include "alMain.h"
|
||||
#include "alu.h"
|
||||
#include "threads.h"
|
||||
#include "compat.h"
|
||||
|
||||
#include <alsa/asoundlib.h>
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#define AL_BACKENDS_BASE_H
|
||||
|
||||
#include "alMain.h"
|
||||
#include "compat.h"
|
||||
|
||||
|
||||
struct ALCbackendVtable;
|
||||
@@ -10,8 +11,12 @@ 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);
|
||||
|
||||
@@ -35,6 +35,7 @@
|
||||
#include "alMain.h"
|
||||
#include "alu.h"
|
||||
#include "threads.h"
|
||||
#include "compat.h"
|
||||
|
||||
#ifndef DSSPEAKER_5POINT1
|
||||
# define DSSPEAKER_5POINT1 0x00000006
|
||||
|
||||
@@ -41,6 +41,7 @@
|
||||
#include "alMain.h"
|
||||
#include "alu.h"
|
||||
#include "threads.h"
|
||||
#include "compat.h"
|
||||
|
||||
|
||||
DEFINE_GUID(KSDATAFORMAT_SUBTYPE_PCM, 0x00000001, 0x0000, 0x0010, 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71);
|
||||
|
||||
+9
-2
@@ -28,6 +28,7 @@
|
||||
#include "alMain.h"
|
||||
#include "alu.h"
|
||||
#include "threads.h"
|
||||
#include "compat.h"
|
||||
|
||||
#include "backends/base.h"
|
||||
|
||||
@@ -85,8 +86,14 @@ static ALuint ALCnullBackend_mixerProc(ALvoid *ptr)
|
||||
}
|
||||
|
||||
|
||||
static void ALCnullBackend_Destruct(ALCnullBackend* UNUSED(self))
|
||||
static void ALCnullBackend_Construct(ALCnullBackend *self, ALCdevice *device)
|
||||
{
|
||||
ALCbackend_Construct(STATIC_CAST(ALCbackend, self), device);
|
||||
}
|
||||
|
||||
static void ALCnullBackend_Destruct(ALCnullBackend *self)
|
||||
{
|
||||
ALCbackend_Destruct(STATIC_CAST(ALCbackend, self));
|
||||
}
|
||||
|
||||
static ALCenum ALCnullBackend_open(ALCnullBackend *self, const ALCchar *name)
|
||||
@@ -197,7 +204,7 @@ ALCbackend* ALCnullBackendFactory_createBackend(ALCnullBackendFactory* UNUSED(se
|
||||
if(!backend) return NULL;
|
||||
SET_VTABLE2(ALCnullBackend, ALCbackend, backend);
|
||||
|
||||
STATIC_CAST(ALCbackend, backend)->mDevice = device;
|
||||
ALCnullBackend_Construct(backend, device);
|
||||
|
||||
return STATIC_CAST(ALCbackend, backend);
|
||||
}
|
||||
|
||||
@@ -34,6 +34,7 @@
|
||||
#include "alMain.h"
|
||||
#include "alu.h"
|
||||
#include "threads.h"
|
||||
#include "compat.h"
|
||||
|
||||
#include <sys/soundcard.h>
|
||||
|
||||
|
||||
@@ -26,6 +26,7 @@
|
||||
#include "alMain.h"
|
||||
#include "alu.h"
|
||||
#include "threads.h"
|
||||
#include "compat.h"
|
||||
|
||||
#include <pulse/pulseaudio.h>
|
||||
|
||||
|
||||
@@ -34,6 +34,7 @@
|
||||
#include "alMain.h"
|
||||
#include "alu.h"
|
||||
#include "threads.h"
|
||||
#include "compat.h"
|
||||
|
||||
#include <sys/audioio.h>
|
||||
|
||||
|
||||
@@ -31,6 +31,7 @@
|
||||
#include "alMain.h"
|
||||
#include "alu.h"
|
||||
#include "threads.h"
|
||||
#include "compat.h"
|
||||
|
||||
|
||||
typedef struct {
|
||||
|
||||
@@ -344,6 +344,8 @@ WCHAR *strdupW(const WCHAR *str)
|
||||
#include <pthread_np.h>
|
||||
#endif
|
||||
#include <sched.h>
|
||||
#include <time.h>
|
||||
#include <sys/time.h>
|
||||
|
||||
void InitializeCriticalSection(CRITICAL_SECTION *cs)
|
||||
{
|
||||
|
||||
@@ -32,6 +32,9 @@
|
||||
|
||||
#ifdef _WIN32
|
||||
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#include <windows.h>
|
||||
|
||||
typedef struct althread_info {
|
||||
ALuint (*func)(ALvoid*);
|
||||
ALvoid *ptr;
|
||||
|
||||
@@ -15,8 +15,6 @@
|
||||
#include "AL/alc.h"
|
||||
#include "AL/alext.h"
|
||||
|
||||
#include "compat.h"
|
||||
|
||||
#ifndef ALC_SOFT_HRTF
|
||||
#define ALC_SOFT_HRTF 1
|
||||
#define ALC_HRTF_SOFT 0x1992
|
||||
@@ -554,8 +552,6 @@ struct ALCdevice_struct
|
||||
ALCboolean Connected;
|
||||
enum DeviceType Type;
|
||||
|
||||
CRITICAL_SECTION Mutex;
|
||||
|
||||
ALuint Frequency;
|
||||
ALuint UpdateSize;
|
||||
ALuint NumUpdates;
|
||||
|
||||
@@ -22,6 +22,11 @@
|
||||
|
||||
#include <signal.h>
|
||||
|
||||
#ifdef HAVE_WINDOWS_H
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#include <windows.h>
|
||||
#endif
|
||||
|
||||
#include "alMain.h"
|
||||
#include "AL/alc.h"
|
||||
#include "alError.h"
|
||||
|
||||
Reference in New Issue
Block a user