diff options
author | Chris Robinson <[email protected]> | 2013-10-28 12:05:33 -0700 |
---|---|---|
committer | Chris Robinson <[email protected]> | 2013-10-28 12:05:33 -0700 |
commit | f24cb447818ea21ff5a5d80d6396abb4723fd2ed (patch) | |
tree | 3f10c96f9e11d1f0dd58501f166ba399ebdbeda8 | |
parent | 2912d130c26056f21e938bbd776bbe8583c055cd (diff) |
Move the device mutex to the backend
-rw-r--r-- | Alc/ALc.c | 53 | ||||
-rw-r--r-- | Alc/alcRing.c | 1 | ||||
-rw-r--r-- | Alc/backends/alsa.c | 1 | ||||
-rw-r--r-- | Alc/backends/base.h | 5 | ||||
-rw-r--r-- | Alc/backends/dsound.c | 1 | ||||
-rw-r--r-- | Alc/backends/mmdevapi.c | 1 | ||||
-rw-r--r-- | Alc/backends/null.c | 11 | ||||
-rw-r--r-- | Alc/backends/oss.c | 1 | ||||
-rw-r--r-- | Alc/backends/pulseaudio.c | 1 | ||||
-rw-r--r-- | Alc/backends/solaris.c | 1 | ||||
-rw-r--r-- | Alc/backends/wave.c | 1 | ||||
-rw-r--r-- | Alc/helpers.c | 2 | ||||
-rw-r--r-- | Alc/threads.c | 3 | ||||
-rw-r--r-- | OpenAL32/Include/alMain.h | 4 | ||||
-rw-r--r-- | OpenAL32/alError.c | 5 |
15 files changed, 70 insertions, 21 deletions
@@ -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; diff --git a/Alc/alcRing.c b/Alc/alcRing.c index 2d9d5069..f831860f 100644 --- a/Alc/alcRing.c +++ b/Alc/alcRing.c @@ -24,6 +24,7 @@ #include <stdlib.h> #include "alMain.h" +#include "compat.h" struct RingBuffer { diff --git a/Alc/backends/alsa.c b/Alc/backends/alsa.c index c60187fa..0e0b4436 100644 --- a/Alc/backends/alsa.c +++ b/Alc/backends/alsa.c @@ -27,6 +27,7 @@ #include "alMain.h" #include "alu.h" #include "threads.h" +#include "compat.h" #include <alsa/asoundlib.h> diff --git a/Alc/backends/base.h b/Alc/backends/base.h index 272a3f65..22602b23 100644 --- a/Alc/backends/base.h +++ b/Alc/backends/base.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); diff --git a/Alc/backends/dsound.c b/Alc/backends/dsound.c index f09967a0..9fa4bd61 100644 --- a/Alc/backends/dsound.c +++ b/Alc/backends/dsound.c @@ -35,6 +35,7 @@ #include "alMain.h" #include "alu.h" #include "threads.h" +#include "compat.h" #ifndef DSSPEAKER_5POINT1 # define DSSPEAKER_5POINT1 0x00000006 diff --git a/Alc/backends/mmdevapi.c b/Alc/backends/mmdevapi.c index fb70d609..31be2ed1 100644 --- a/Alc/backends/mmdevapi.c +++ b/Alc/backends/mmdevapi.c @@ -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); diff --git a/Alc/backends/null.c b/Alc/backends/null.c index d21ebf0c..af68c585 100644 --- a/Alc/backends/null.c +++ b/Alc/backends/null.c @@ -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); } diff --git a/Alc/backends/oss.c b/Alc/backends/oss.c index 35ae80cc..a9510a35 100644 --- a/Alc/backends/oss.c +++ b/Alc/backends/oss.c @@ -34,6 +34,7 @@ #include "alMain.h" #include "alu.h" #include "threads.h" +#include "compat.h" #include <sys/soundcard.h> diff --git a/Alc/backends/pulseaudio.c b/Alc/backends/pulseaudio.c index 4dc016a1..c24b86e2 100644 --- a/Alc/backends/pulseaudio.c +++ b/Alc/backends/pulseaudio.c @@ -26,6 +26,7 @@ #include "alMain.h" #include "alu.h" #include "threads.h" +#include "compat.h" #include <pulse/pulseaudio.h> diff --git a/Alc/backends/solaris.c b/Alc/backends/solaris.c index c6fd32e9..c4d40273 100644 --- a/Alc/backends/solaris.c +++ b/Alc/backends/solaris.c @@ -34,6 +34,7 @@ #include "alMain.h" #include "alu.h" #include "threads.h" +#include "compat.h" #include <sys/audioio.h> diff --git a/Alc/backends/wave.c b/Alc/backends/wave.c index e7698430..ec88862b 100644 --- a/Alc/backends/wave.c +++ b/Alc/backends/wave.c @@ -31,6 +31,7 @@ #include "alMain.h" #include "alu.h" #include "threads.h" +#include "compat.h" typedef struct { diff --git a/Alc/helpers.c b/Alc/helpers.c index 4d715553..6681fde7 100644 --- a/Alc/helpers.c +++ b/Alc/helpers.c @@ -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) { diff --git a/Alc/threads.c b/Alc/threads.c index 1f7e3a6c..1c422949 100644 --- a/Alc/threads.c +++ b/Alc/threads.c @@ -32,6 +32,9 @@ #ifdef _WIN32 +#define WIN32_LEAN_AND_MEAN +#include <windows.h> + typedef struct althread_info { ALuint (*func)(ALvoid*); ALvoid *ptr; diff --git a/OpenAL32/Include/alMain.h b/OpenAL32/Include/alMain.h index ebedada8..a02c71b6 100644 --- a/OpenAL32/Include/alMain.h +++ b/OpenAL32/Include/alMain.h @@ -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; diff --git a/OpenAL32/alError.c b/OpenAL32/alError.c index d18c1867..b557532e 100644 --- a/OpenAL32/alError.c +++ b/OpenAL32/alError.c @@ -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" |