aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChris Robinson <[email protected]>2018-01-23 18:25:59 -0800
committerChris Robinson <[email protected]>2018-01-23 18:25:59 -0800
commitcaa3b4f7f833278498a78f261e8badb85fd2896b (patch)
tree8f733392944198cb06e17aad5b9db67b79fc4d64
parent2266a9e01ef68f112e87eb49bf1621a6456531a9 (diff)
Handle event properties
This just implements the event methods insofar as tracked state. No events are generated/reported yet.
-rw-r--r--Alc/ALc.c18
-rw-r--r--CMakeLists.txt1
-rw-r--r--OpenAL32/Include/alMain.h16
-rw-r--r--OpenAL32/alState.c58
-rw-r--r--OpenAL32/event.c65
5 files changed, 156 insertions, 2 deletions
diff --git a/Alc/ALc.c b/Alc/ALc.c
index 0d8bbe86..aa4634a0 100644
--- a/Alc/ALc.c
+++ b/Alc/ALc.c
@@ -287,6 +287,11 @@ static const struct {
DECL(alMapBufferSOFT),
DECL(alUnmapBufferSOFT),
DECL(alFlushMappedBufferSOFT),
+
+ DECL(alEventControlSOFT),
+ DECL(alEventCallbackSOFT),
+ DECL(alGetPointerSOFT),
+ DECL(alGetPointervSOFT),
};
#undef DECL
@@ -653,6 +658,13 @@ static const struct {
DECL(AL_MAP_WRITE_BIT_SOFT),
DECL(AL_MAP_PERSISTENT_BIT_SOFT),
DECL(AL_PRESERVE_DATA_BIT_SOFT),
+
+ DECL(AL_EVENT_CALLBACK_FUNCTION_SOFT),
+ DECL(AL_EVENT_CALLBACK_USER_PARAM_SOFT),
+ DECL(AL_EVENT_TYPE_BUFFER_COMPLETED_SOFT),
+ DECL(AL_EVENT_TYPE_SOURCE_STATE_CHANGED_SOFT),
+ DECL(AL_EVENT_TYPE_ERROR_SOFT),
+ DECL(AL_EVENT_TYPE_PERFORMANCE_SOFT),
};
#undef DECL
@@ -2534,6 +2546,10 @@ static ALvoid InitContext(ALCcontext *Context)
Context->MetersPerUnit = AL_DEFAULT_METERS_PER_UNIT;
ATOMIC_FLAG_TEST_AND_SET(&Context->PropsClean, almemory_order_relaxed);
ATOMIC_INIT(&Context->DeferUpdates, AL_FALSE);
+ almtx_init(&Context->EventLock, almtx_plain);
+ Context->EnabledEvts = 0;
+ Context->EventCb = NULL;
+ Context->EventParam = NULL;
ATOMIC_INIT(&Context->Update, NULL);
ATOMIC_INIT(&Context->FreeContextProps, NULL);
@@ -2662,6 +2678,8 @@ static void FreeContext(ALCcontext *context)
}
TRACE("Freed "SZFMT" listener property object%s\n", count, (count==1)?"":"s");
+ almtx_destroy(&context->EventLock);
+
ALCdevice_DecRef(context->Device);
context->Device = NULL;
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 76aa19b9..29c0a3b7 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -694,6 +694,7 @@ SET(OPENAL_OBJS OpenAL32/alAuxEffectSlot.c
OpenAL32/alSource.c
OpenAL32/alState.c
OpenAL32/alThunk.c
+ OpenAL32/event.c
OpenAL32/sample_cvt.c
)
SET(ALC_OBJS Alc/ALc.c
diff --git a/OpenAL32/Include/alMain.h b/OpenAL32/Include/alMain.h
index 4b0f3b81..438f7ed5 100644
--- a/OpenAL32/Include/alMain.h
+++ b/OpenAL32/Include/alMain.h
@@ -80,12 +80,12 @@ typedef void (AL_APIENTRY*ALEVENTPROCSOFT)(ALenum eventType, ALuint object, ALui
typedef void (AL_APIENTRY*LPALEVENTCONTROLSOFT)(ALsizei count, const ALenum *types, ALboolean enable);
typedef void (AL_APIENTRY*LPALEVENTCALLBACKSOFT)(ALEVENTPROCSOFT callback, void *userParam);
typedef void* (AL_APIENTRY*LPALGETPOINTERSOFT)(ALenum pname);
-typedef void (AL_APIENTRY*LPALGETPOINTERVSOFT)(ALenum pname, void **params);
+typedef void (AL_APIENTRY*LPALGETPOINTERVSOFT)(ALenum pname, void **values);
#ifdef AL_ALEXT_PROTOTYPES
AL_API void AL_APIENTRY alEventControlSOFT(ALsizei count, const ALenum *types, ALboolean enable);
AL_API void AL_APIENTRY alEventCallbackSOFT(ALEVENTPROCSOFT callback, void *userParam);
AL_API void* AL_APIENTRY alGetPointerSOFT(ALenum pname);
-AL_API void AL_APIENTRY alGetPointervSOFT(ALenum pname, void **params);
+AL_API void AL_APIENTRY alGetPointervSOFT(ALenum pname, void **values);
#endif
#endif
@@ -565,6 +565,13 @@ struct ALCdevice_struct
#define RECORD_THREAD_NAME "alsoft-record"
+enum {
+ EventType_SourceStateChange = 1<<0,
+ EventType_BufferCompleted = 1<<1,
+ EventType_Error = 1<<2,
+ EventType_Performance = 1<<3,
+};
+
struct ALCcontext_struct {
RefCount ref;
@@ -612,6 +619,11 @@ struct ALCcontext_struct {
ATOMIC(struct ALeffectslotArray*) ActiveAuxSlots;
+ almtx_t EventLock;
+ ALbitfieldSOFT EnabledEvts;
+ ALEVENTPROCSOFT EventCb;
+ void *EventParam;
+
/* Default effect slot */
struct ALeffectslot *DefaultSlot;
diff --git a/OpenAL32/alState.c b/OpenAL32/alState.c
index c8c81065..36afd46e 100644
--- a/OpenAL32/alState.c
+++ b/OpenAL32/alState.c
@@ -415,6 +415,64 @@ done:
return value;
}
+AL_API void* AL_APIENTRY alGetPointerSOFT(ALenum pname)
+{
+ ALCcontext *context;
+ void *value = NULL;
+
+ context = GetContextRef();
+ if(!context) return NULL;
+
+ switch(pname)
+ {
+ case AL_EVENT_CALLBACK_FUNCTION_SOFT:
+ value = context->EventCb;
+ break;
+
+ case AL_EVENT_CALLBACK_USER_PARAM_SOFT:
+ value = context->EventParam;
+ break;
+
+ default:
+ SET_ERROR_AND_GOTO(context, AL_INVALID_ENUM, done);
+ }
+
+done:
+ ALCcontext_DecRef(context);
+
+ return value;
+}
+
+AL_API void AL_APIENTRY alGetPointervSOFT(ALenum pname, void **values)
+{
+ ALCcontext *context;
+
+ if(values)
+ {
+ switch(pname)
+ {
+ case AL_EVENT_CALLBACK_FUNCTION_SOFT:
+ case AL_EVENT_CALLBACK_USER_PARAM_SOFT:
+ values[0] = alGetPointerSOFT(pname);
+ return;
+ }
+ }
+
+ context = GetContextRef();
+ if(!context) return;
+
+ if(!(values))
+ SET_ERROR_AND_GOTO(context, AL_INVALID_VALUE, done);
+ switch(pname)
+ {
+ default:
+ SET_ERROR_AND_GOTO(context, AL_INVALID_ENUM, done);
+ }
+
+done:
+ ALCcontext_DecRef(context);
+}
+
AL_API ALvoid AL_APIENTRY alGetBooleanv(ALenum pname, ALboolean *values)
{
ALCcontext *context;
diff --git a/OpenAL32/event.c b/OpenAL32/event.c
new file mode 100644
index 00000000..4e844ce9
--- /dev/null
+++ b/OpenAL32/event.c
@@ -0,0 +1,65 @@
+
+#include "config.h"
+
+#include "AL/alc.h"
+#include "AL/al.h"
+#include "AL/alext.h"
+#include "alMain.h"
+#include "alError.h"
+
+
+AL_API void AL_APIENTRY alEventControlSOFT(ALsizei count, const ALenum *types, ALboolean enable)
+{
+ ALCcontext *context;
+ ALbitfieldSOFT flags = 0;
+ ALsizei i;
+
+ context = GetContextRef();
+ if(!context) return;
+
+ if(count < 0)
+ SET_ERROR_AND_GOTO(context, AL_INVALID_VALUE, done);
+ if(count == 0) goto done;
+ if(!types)
+ SET_ERROR_AND_GOTO(context, AL_INVALID_VALUE, done);
+
+ for(i = 0;i < count;i++)
+ {
+ if(types[i] == AL_EVENT_TYPE_BUFFER_COMPLETED_SOFT)
+ flags |= EventType_BufferCompleted;
+ else if(types[i] == AL_EVENT_TYPE_SOURCE_STATE_CHANGED_SOFT)
+ flags |= EventType_SourceStateChange;
+ else if(types[i] == AL_EVENT_TYPE_ERROR_SOFT)
+ flags |= EventType_Error;
+ else if(types[i] == AL_EVENT_TYPE_PERFORMANCE_SOFT)
+ flags |= EventType_Performance;
+ else
+ SET_ERROR_AND_GOTO(context, AL_INVALID_ENUM, done);
+ }
+
+ almtx_lock(&context->EventLock);
+
+ if(enable)
+ context->EnabledEvts |= flags;
+ else
+ context->EnabledEvts &= ~flags;
+
+ almtx_unlock(&context->EventLock);
+done:
+ ALCcontext_DecRef(context);
+}
+
+AL_API void AL_APIENTRY alEventCallbackSOFT(ALEVENTPROCSOFT callback, void *userParam)
+{
+ ALCcontext *context;
+
+ context = GetContextRef();
+ if(!context) return;
+
+ almtx_lock(&context->EventLock);
+ context->EventCb = callback;
+ context->EventParam = userParam;
+ almtx_unlock(&context->EventLock);
+
+ ALCcontext_DecRef(context);
+}