From 932939c5a80971ee155613038c392603d92fdf03 Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Wed, 24 Jan 2018 20:04:57 -0800 Subject: Enable events in alffplay --- examples/alffplay.cpp | 73 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) (limited to 'examples/alffplay.cpp') diff --git a/examples/alffplay.cpp b/examples/alffplay.cpp index f372983a..6eedcd76 100644 --- a/examples/alffplay.cpp +++ b/examples/alffplay.cpp @@ -50,6 +50,24 @@ typedef void* (AL_APIENTRY*LPALMAPBUFFERSOFT)(ALuint buffer, ALsizei offset, ALs typedef void (AL_APIENTRY*LPALUNMAPBUFFERSOFT)(ALuint buffer); typedef void (AL_APIENTRY*LPALFLUSHMAPPEDBUFFERSOFT)(ALuint buffer, ALsizei offset, ALsizei length); #endif + +#ifndef AL_SOFT_events +#define AL_SOFT_events 1 +#define AL_EVENT_CALLBACK_FUNCTION_SOFT 0x1220 +#define AL_EVENT_CALLBACK_USER_PARAM_SOFT 0x1221 +#define AL_EVENT_TYPE_BUFFER_COMPLETED_SOFT 0x1222 +#define AL_EVENT_TYPE_SOURCE_STATE_CHANGED_SOFT 0x1223 +#define AL_EVENT_TYPE_ERROR_SOFT 0x1224 +#define AL_EVENT_TYPE_PERFORMANCE_SOFT 0x1225 +#define AL_EVENT_TYPE_DEPRECATED_SOFT 0x1226 +typedef void (AL_APIENTRY*ALEVENTPROCSOFT)(ALenum eventType, ALuint object, ALuint param, + ALsizei length, const ALchar *message, + void *userParam); +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 **values); +#endif } namespace { @@ -70,6 +88,9 @@ LPALBUFFERSTORAGESOFT alBufferStorageSOFT; LPALMAPBUFFERSOFT alMapBufferSOFT; LPALUNMAPBUFFERSOFT alUnmapBufferSOFT; +LPALEVENTCONTROLSOFT alEventControlSOFT; +LPALEVENTCALLBACKSOFT alEventCallbackSOFT; + const seconds AVNoSyncThreshold(10); const milliseconds VideoSyncThreshold(10); @@ -232,6 +253,10 @@ struct AudioState { av_freep(&mSamples); } + static void AL_APIENTRY EventCallback(ALenum eventType, ALuint object, ALuint param, + ALsizei length, const ALchar *message, + void *userParam); + nanoseconds getClockNoLock(); nanoseconds getClock() { @@ -653,11 +678,45 @@ bool AudioState::readAudio(uint8_t *samples, int length) } +void AL_APIENTRY AudioState::EventCallback(ALenum eventType, ALuint object, ALuint param, + ALsizei length, const ALchar *message, + void *userParam) +{ + AudioState *self = reinterpret_cast(userParam); + + std::cout<< "---- AL Event on AudioState "< lock(mSrcMutex); ALenum fmt; + if(alEventControlSOFT) + { + alEventControlSOFT(5, types, AL_TRUE); + alEventCallbackSOFT(EventCallback, this); + } + /* Find a suitable format for OpenAL. */ mDstChanLayout = 0; if(mCodecCtx->sample_fmt == AV_SAMPLE_FMT_U8 || mCodecCtx->sample_fmt == AV_SAMPLE_FMT_U8P) @@ -887,6 +946,12 @@ int AudioState::handler() finish: av_freep(&samples); + if(alEventControlSOFT) + { + alEventControlSOFT(5, types, AL_FALSE); + alEventCallbackSOFT(nullptr, nullptr); + } + return 0; } @@ -1643,6 +1708,14 @@ int main(int argc, char *argv[]) alUnmapBufferSOFT = reinterpret_cast( alGetProcAddress("alUnmapBufferSOFT")); } + if(alIsExtensionPresent("AL_SOFTX_events")) + { + std::cout<< "Found AL_SOFT_events" <( + alGetProcAddress("alEventControlSOFT")); + alEventCallbackSOFT = reinterpret_cast( + alGetProcAddress("alEventCallbackSOFT")); + } if(fileidx < argc && strcmp(argv[fileidx], "-direct") == 0) { -- cgit v1.2.3