From 43c375716a7f3cd73f3b3ce8bb03136bef4f5d82 Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Sat, 5 Oct 2013 00:33:56 -0700 Subject: Only rest as long as needed in the Null renderer --- Alc/backends/null.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'Alc/backends/null.c') diff --git a/Alc/backends/null.c b/Alc/backends/null.c index 93b38063..d001cb41 100644 --- a/Alc/backends/null.c +++ b/Alc/backends/null.c @@ -43,8 +43,6 @@ static ALuint NullProc(ALvoid *ptr) null_data *data = (null_data*)Device->ExtraData; ALuint now, start; ALuint64 avail, done; - const ALuint restTime = (ALuint64)Device->UpdateSize * 1000 / - Device->Frequency / 2; done = 0; start = timeGetTime(); @@ -62,15 +60,16 @@ static ALuint NullProc(ALvoid *ptr) } if(avail-done < Device->UpdateSize) { + ALuint restTime = (Device->UpdateSize - (avail-done)) * 1000 / + Device->Frequency; Sleep(restTime); continue; } - while(avail-done >= Device->UpdateSize) - { + do { aluMixData(Device, NULL, Device->UpdateSize); done += Device->UpdateSize; - } + } while(avail-done >= Device->UpdateSize); } return 0; -- cgit v1.2.3 From f93bfab82435b26fd03fe9dd0436f166758810d4 Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Sun, 27 Oct 2013 07:00:44 -0700 Subject: Set a name for the mixer and recording threads --- Alc/backends/alsa.c | 2 ++ Alc/backends/dsound.c | 1 + Alc/backends/mmdevapi.c | 1 + Alc/backends/null.c | 5 ++++- Alc/backends/oss.c | 2 ++ Alc/backends/pulseaudio.c | 1 + Alc/backends/qsa.c | 1 + Alc/backends/sndio.c | 1 + Alc/backends/solaris.c | 1 + Alc/backends/wave.c | 2 ++ Alc/backends/winmm.c | 2 ++ OpenAL32/Include/alMain.h | 5 +++++ 12 files changed, 23 insertions(+), 1 deletion(-) (limited to 'Alc/backends/null.c') diff --git a/Alc/backends/alsa.c b/Alc/backends/alsa.c index f6c0428e..bb30dac5 100644 --- a/Alc/backends/alsa.c +++ b/Alc/backends/alsa.c @@ -463,6 +463,7 @@ static ALuint ALSAProc(ALvoid *ptr) int err; SetRTPriority(); + SetThreadName(MIXER_THREAD_NAME); update_size = Device->UpdateSize; num_updates = Device->NumUpdates; @@ -552,6 +553,7 @@ static ALuint ALSANoMMapProc(ALvoid *ptr) int err; SetRTPriority(); + SetThreadName(MIXER_THREAD_NAME); update_size = Device->UpdateSize; num_updates = Device->NumUpdates; diff --git a/Alc/backends/dsound.c b/Alc/backends/dsound.c index 9727dd2a..22af15d8 100644 --- a/Alc/backends/dsound.c +++ b/Alc/backends/dsound.c @@ -238,6 +238,7 @@ static ALuint DSoundPlaybackProc(ALvoid *ptr) HRESULT err; SetRTPriority(); + SetThreadName(MIXER_THREAD_NAME); memset(&DSBCaps, 0, sizeof(DSBCaps)); DSBCaps.dwSize = sizeof(DSBCaps); diff --git a/Alc/backends/mmdevapi.c b/Alc/backends/mmdevapi.c index 2181f274..e6447bef 100644 --- a/Alc/backends/mmdevapi.c +++ b/Alc/backends/mmdevapi.c @@ -238,6 +238,7 @@ static ALuint MMDevApiProc(ALvoid *ptr) } SetRTPriority(); + SetThreadName(MIXER_THREAD_NAME); update_size = device->UpdateSize; buffer_len = update_size * device->NumUpdates; diff --git a/Alc/backends/null.c b/Alc/backends/null.c index d001cb41..73e3e8cb 100644 --- a/Alc/backends/null.c +++ b/Alc/backends/null.c @@ -44,6 +44,9 @@ static ALuint NullProc(ALvoid *ptr) ALuint now, start; ALuint64 avail, done; + SetRTPriority(); + SetThreadName(MIXER_THREAD_NAME); + done = 0; start = timeGetTime(); while(!data->killNow && Device->Connected) @@ -55,7 +58,7 @@ static ALuint NullProc(ALvoid *ptr) { /* Timer wrapped (50 days???). Add the remainder of the cycle to * the available count and reset the number of samples done */ - avail += ((ALuint64)1<<32)*Device->Frequency/1000 - done; + avail += (U64(1)<<32)*Device->Frequency/1000 - done; done = 0; } if(avail-done < Device->UpdateSize) diff --git a/Alc/backends/oss.c b/Alc/backends/oss.c index 0ed49517..892e2327 100644 --- a/Alc/backends/oss.c +++ b/Alc/backends/oss.c @@ -85,6 +85,7 @@ static ALuint OSSProc(ALvoid *ptr) ssize_t wrote; SetRTPriority(); + SetThreadName(MIXER_THREAD_NAME); frameSize = FrameSizeFromDevFmt(Device->FmtChans, Device->FmtType); @@ -128,6 +129,7 @@ static ALuint OSSCaptureProc(ALvoid *ptr) int amt; SetRTPriority(); + SetThreadName("alsoft-record"); frameSize = FrameSizeFromDevFmt(Device->FmtChans, Device->FmtType); diff --git a/Alc/backends/pulseaudio.c b/Alc/backends/pulseaudio.c index f96b44fe..5b6e0fad 100644 --- a/Alc/backends/pulseaudio.c +++ b/Alc/backends/pulseaudio.c @@ -791,6 +791,7 @@ static ALuint PulseProc(ALvoid *param) ssize_t len; SetRTPriority(); + SetThreadName(MIXER_THREAD_NAME); pa_threaded_mainloop_lock(data->loop); frame_size = pa_frame_size(&data->spec); diff --git a/Alc/backends/qsa.c b/Alc/backends/qsa.c index 933af5b4..2890a121 100644 --- a/Alc/backends/qsa.c +++ b/Alc/backends/qsa.c @@ -196,6 +196,7 @@ static ALuint qsa_proc_playback(ALvoid* ptr) struct timeval timeout; SetRTPriority(); + SetThreadName(MIXER_THREAD_NAME); /* Increase default 10 priority to 11 to avoid jerky sound */ SchedGet(0, 0, ¶m); diff --git a/Alc/backends/sndio.c b/Alc/backends/sndio.c index 2be88746..4c3a5de6 100644 --- a/Alc/backends/sndio.c +++ b/Alc/backends/sndio.c @@ -58,6 +58,7 @@ static ALuint sndio_proc(ALvoid *ptr) size_t wrote; SetRTPriority(); + SetThreadName(MIXER_THREAD_NAME); frameSize = FrameSizeFromDevFmt(device->FmtChans, device->FmtType); diff --git a/Alc/backends/solaris.c b/Alc/backends/solaris.c index 1c781387..b9288197 100644 --- a/Alc/backends/solaris.c +++ b/Alc/backends/solaris.c @@ -59,6 +59,7 @@ static ALuint SolarisProc(ALvoid *ptr) int wrote; SetRTPriority(); + SetThreadName(MIXER_THREAD_NAME); frameSize = FrameSizeFromDevFmt(Device->FmtChans, Device->FmtType); diff --git a/Alc/backends/wave.c b/Alc/backends/wave.c index 416876be..ce827fe8 100644 --- a/Alc/backends/wave.c +++ b/Alc/backends/wave.c @@ -93,6 +93,8 @@ static ALuint WaveProc(ALvoid *ptr) const ALuint restTime = (ALuint64)Device->UpdateSize * 1000 / Device->Frequency / 2; + SetThreadName(MIXER_THREAD_NAME); + frameSize = FrameSizeFromDevFmt(Device->FmtChans, Device->FmtType); done = 0; diff --git a/Alc/backends/winmm.c b/Alc/backends/winmm.c index 3b2b373b..e003375c 100644 --- a/Alc/backends/winmm.c +++ b/Alc/backends/winmm.c @@ -175,6 +175,7 @@ static DWORD WINAPI PlaybackThreadProc(LPVOID param) FrameSize = FrameSizeFromDevFmt(Device->FmtChans, Device->FmtType); SetRTPriority(); + SetThreadName(MIXER_THREAD_NAME); while(GetMessage(&msg, NULL, 0, 0)) { @@ -237,6 +238,7 @@ static DWORD WINAPI CaptureThreadProc(LPVOID param) MSG msg; FrameSize = FrameSizeFromDevFmt(Device->FmtChans, Device->FmtType); + SetThreadName("alsoft-record"); while(GetMessage(&msg, NULL, 0, 0)) { diff --git a/OpenAL32/Include/alMain.h b/OpenAL32/Include/alMain.h index d8dbdcd9..95146c1b 100644 --- a/OpenAL32/Include/alMain.h +++ b/OpenAL32/Include/alMain.h @@ -714,6 +714,11 @@ struct ALCdevice_struct #define INVALID_OFFSET (~0u) +/* Must be less than 15 characters (16 including terminating null) for + * compatibility with pthread_setname_np limitations. */ +#define MIXER_THREAD_NAME "alsoft-mixer" + + static inline struct ALbuffer *LookupBuffer(ALCdevice *device, ALuint id) { return (struct ALbuffer*)LookupUIntMapKey(&device->BufferMap, id); } static inline struct ALeffect *LookupEffect(ALCdevice *device, ALuint id) -- cgit v1.2.3 From 8ceb800defbf13354866cd7c6a4b676cf54aad5d Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Sun, 27 Oct 2013 08:14:13 -0700 Subject: Rework threading functions --- Alc/alcThread.c | 144 ------------------------------------------ Alc/backends/alsa.c | 10 +-- Alc/backends/dsound.c | 6 +- Alc/backends/mmdevapi.c | 6 +- Alc/backends/null.c | 6 +- Alc/backends/oss.c | 12 ++-- Alc/backends/pulseaudio.c | 10 +-- Alc/backends/qsa.c | 17 +++-- Alc/backends/sndio.c | 6 +- Alc/backends/solaris.c | 9 +-- Alc/backends/wave.c | 6 +- Alc/backends/winmm.c | 1 + Alc/threads.c | 152 +++++++++++++++++++++++++++++++++++++++++++++ CMakeLists.txt | 2 +- OpenAL32/Include/alMain.h | 4 -- OpenAL32/Include/threads.h | 14 +++++ 16 files changed, 213 insertions(+), 192 deletions(-) delete mode 100644 Alc/alcThread.c create mode 100644 Alc/threads.c create mode 100644 OpenAL32/Include/threads.h (limited to 'Alc/backends/null.c') diff --git a/Alc/alcThread.c b/Alc/alcThread.c deleted file mode 100644 index c2f38031..00000000 --- a/Alc/alcThread.c +++ /dev/null @@ -1,144 +0,0 @@ -/** - * OpenAL cross platform audio library - * Copyright (C) 1999-2007 by authors. - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - * Or go to http://www.gnu.org/copyleft/lgpl.html - */ - -#include "config.h" - -#include - -#include "alMain.h" -#include "alThunk.h" - -#define THREAD_STACK_SIZE (1*1024*1024) /* 1MB */ - -#ifdef _WIN32 - -typedef struct { - ALuint (*func)(ALvoid*); - ALvoid *ptr; - HANDLE thread; -} ThreadInfo; - -static DWORD CALLBACK StarterFunc(void *ptr) -{ - ThreadInfo *inf = (ThreadInfo*)ptr; - ALint ret; - - ret = inf->func(inf->ptr); - ExitThread((DWORD)ret); - - return (DWORD)ret; -} - -ALvoid *StartThread(ALuint (*func)(ALvoid*), ALvoid *ptr) -{ - DWORD dummy; - ThreadInfo *inf = malloc(sizeof(ThreadInfo)); - if(!inf) return 0; - - inf->func = func; - inf->ptr = ptr; - - inf->thread = CreateThread(NULL, THREAD_STACK_SIZE, StarterFunc, inf, 0, &dummy); - if(!inf->thread) - { - free(inf); - return NULL; - } - - return inf; -} - -ALuint StopThread(ALvoid *thread) -{ - ThreadInfo *inf = thread; - DWORD ret = 0; - - WaitForSingleObject(inf->thread, INFINITE); - GetExitCodeThread(inf->thread, &ret); - CloseHandle(inf->thread); - - free(inf); - - return (ALuint)ret; -} - -#else - -#include - -typedef struct { - ALuint (*func)(ALvoid*); - ALvoid *ptr; - ALuint ret; - pthread_t thread; -} ThreadInfo; - -static void *StarterFunc(void *ptr) -{ - ThreadInfo *inf = (ThreadInfo*)ptr; - inf->ret = inf->func(inf->ptr); - return NULL; -} - -ALvoid *StartThread(ALuint (*func)(ALvoid*), ALvoid *ptr) -{ - pthread_attr_t attr; - ThreadInfo *inf = malloc(sizeof(ThreadInfo)); - if(!inf) return NULL; - - if(pthread_attr_init(&attr) != 0) - { - free(inf); - return NULL; - } - if(pthread_attr_setstacksize(&attr, THREAD_STACK_SIZE) != 0) - { - pthread_attr_destroy(&attr); - free(inf); - return NULL; - } - - inf->func = func; - inf->ptr = ptr; - if(pthread_create(&inf->thread, &attr, StarterFunc, inf) != 0) - { - pthread_attr_destroy(&attr); - free(inf); - return NULL; - } - pthread_attr_destroy(&attr); - - return inf; -} - -ALuint StopThread(ALvoid *thread) -{ - ThreadInfo *inf = thread; - ALuint ret; - - pthread_join(inf->thread, NULL); - ret = inf->ret; - - free(inf); - - return ret; -} - -#endif diff --git a/Alc/backends/alsa.c b/Alc/backends/alsa.c index bb30dac5..c60187fa 100644 --- a/Alc/backends/alsa.c +++ b/Alc/backends/alsa.c @@ -26,6 +26,7 @@ #include "alMain.h" #include "alu.h" +#include "threads.h" #include @@ -293,7 +294,7 @@ typedef struct { snd_pcm_sframes_t last_avail; volatile int killNow; - ALvoid *thread; + althread_t thread; } alsa_data; typedef struct { @@ -849,6 +850,7 @@ error: static ALCboolean alsa_start_playback(ALCdevice *device) { alsa_data *data = (alsa_data*)device->ExtraData; + ALuint (*thread_func)(ALvoid*) = NULL; snd_pcm_hw_params_t *hp = NULL; snd_pcm_access_t access; const char *funcerr; @@ -872,7 +874,7 @@ static ALCboolean alsa_start_playback(ALCdevice *device) ERR("buffer malloc failed\n"); return ALC_FALSE; } - data->thread = StartThread(ALSANoMMapProc, device); + thread_func = ALSANoMMapProc; } else { @@ -882,9 +884,9 @@ static ALCboolean alsa_start_playback(ALCdevice *device) ERR("snd_pcm_prepare(data->pcmHandle) failed: %s\n", snd_strerror(err)); return ALC_FALSE; } - data->thread = StartThread(ALSAProc, device); + thread_func = ALSAProc; } - if(data->thread == NULL) + if(!StartThread(&data->thread, thread_func, device)) { ERR("Could not create playback thread\n"); free(data->buffer); diff --git a/Alc/backends/dsound.c b/Alc/backends/dsound.c index 22af15d8..f09967a0 100644 --- a/Alc/backends/dsound.c +++ b/Alc/backends/dsound.c @@ -34,6 +34,7 @@ #include "alMain.h" #include "alu.h" +#include "threads.h" #ifndef DSSPEAKER_5POINT1 # define DSSPEAKER_5POINT1 0x00000006 @@ -74,7 +75,7 @@ typedef struct { HANDLE NotifyEvent; volatile int killNow; - ALvoid *thread; + althread_t thread; } DSoundPlaybackData; typedef struct { @@ -632,8 +633,7 @@ static ALCboolean DSoundStartPlayback(ALCdevice *device) { DSoundPlaybackData *data = (DSoundPlaybackData*)device->ExtraData; - data->thread = StartThread(DSoundPlaybackProc, device); - if(data->thread == NULL) + if(!StartThread(&data->thread, DSoundPlaybackProc, device)) return ALC_FALSE; return ALC_TRUE; diff --git a/Alc/backends/mmdevapi.c b/Alc/backends/mmdevapi.c index e6447bef..fb70d609 100644 --- a/Alc/backends/mmdevapi.c +++ b/Alc/backends/mmdevapi.c @@ -40,6 +40,7 @@ #include "alMain.h" #include "alu.h" +#include "threads.h" DEFINE_GUID(KSDATAFORMAT_SUBTYPE_PCM, 0x00000001, 0x0000, 0x0010, 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71); @@ -69,7 +70,7 @@ typedef struct { volatile UINT32 Padding; volatile int killNow; - ALvoid *thread; + althread_t thread; } MMDevApiData; @@ -677,8 +678,7 @@ static DWORD CALLBACK MMDevApiMsgProc(void *ptr) if(SUCCEEDED(hr)) { data->render = ptr; - data->thread = StartThread(MMDevApiProc, device); - if(!data->thread) + if(!StartThread(&data->thread, MMDevApiProc, device)) { if(data->render) IAudioRenderClient_Release(data->render); diff --git a/Alc/backends/null.c b/Alc/backends/null.c index 73e3e8cb..9742424c 100644 --- a/Alc/backends/null.c +++ b/Alc/backends/null.c @@ -27,11 +27,12 @@ #include "alMain.h" #include "alu.h" +#include "threads.h" typedef struct { volatile int killNow; - ALvoid *thread; + althread_t thread; } null_data; @@ -112,8 +113,7 @@ static ALCboolean null_start_playback(ALCdevice *device) { null_data *data = (null_data*)device->ExtraData; - data->thread = StartThread(NullProc, device); - if(data->thread == NULL) + if(!StartThread(&data->thread, NullProc, device)) return ALC_FALSE; return ALC_TRUE; diff --git a/Alc/backends/oss.c b/Alc/backends/oss.c index 892e2327..35ae80cc 100644 --- a/Alc/backends/oss.c +++ b/Alc/backends/oss.c @@ -33,6 +33,7 @@ #include "alMain.h" #include "alu.h" +#include "threads.h" #include @@ -54,14 +55,15 @@ static const char *oss_capture = "/dev/dsp"; typedef struct { int fd; - volatile int killNow; - ALvoid *thread; ALubyte *mix_data; int data_size; RingBuffer *ring; int doCapture; + + volatile int killNow; + althread_t thread; } oss_data; @@ -286,8 +288,7 @@ static ALCboolean oss_start_playback(ALCdevice *device) data->data_size = device->UpdateSize * FrameSizeFromDevFmt(device->FmtChans, device->FmtType); data->mix_data = calloc(1, data->data_size); - data->thread = StartThread(OSSProc, device); - if(data->thread == NULL) + if(!StartThread(&data->thread, OSSProc, device)) { free(data->mix_data); data->mix_data = NULL; @@ -428,8 +429,7 @@ static ALCenum oss_open_capture(ALCdevice *device, const ALCchar *deviceName) data->mix_data = calloc(1, data->data_size); device->ExtraData = data; - data->thread = StartThread(OSSCaptureProc, device); - if(data->thread == NULL) + if(!StartThread(&data->thread, OSSCaptureProc, device)) { device->ExtraData = NULL; free(data->mix_data); diff --git a/Alc/backends/pulseaudio.c b/Alc/backends/pulseaudio.c index 5b6e0fad..4dc016a1 100644 --- a/Alc/backends/pulseaudio.c +++ b/Alc/backends/pulseaudio.c @@ -25,6 +25,7 @@ #include "alMain.h" #include "alu.h" +#include "threads.h" #include @@ -205,11 +206,11 @@ typedef struct { pa_threaded_mainloop *loop; - ALvoid *thread; - volatile ALboolean killNow; - pa_stream *stream; pa_context *context; + + volatile ALboolean killNow; + althread_t thread; } pulse_data; typedef struct { @@ -1151,8 +1152,7 @@ static ALCboolean pulse_start_playback(ALCdevice *device) { pulse_data *data = device->ExtraData; - data->thread = StartThread(PulseProc, device); - if(!data->thread) + if(!StartThread(&data->thread, PulseProc, device)) return ALC_FALSE; return ALC_TRUE; diff --git a/Alc/backends/qsa.c b/Alc/backends/qsa.c index 2890a121..d91ffb2c 100644 --- a/Alc/backends/qsa.c +++ b/Alc/backends/qsa.c @@ -31,20 +31,22 @@ #include "alMain.h" #include "alu.h" +#include "threads.h" + typedef struct { snd_pcm_t* pcmHandle; int audio_fd; + snd_pcm_channel_setup_t csetup; + snd_pcm_channel_params_t cparams; + ALvoid* buffer; ALsizei size; volatile int killNow; - ALvoid* thread; - - snd_pcm_channel_setup_t csetup; - snd_pcm_channel_params_t cparams; + althread_t thread; } qsa_data; typedef struct @@ -619,13 +621,10 @@ static ALCboolean qsa_reset_playback(ALCdevice* device) static ALCboolean qsa_start_playback(ALCdevice* device) { - qsa_data* data=(qsa_data*)device->ExtraData; + qsa_data *data = (qsa_data*)device->ExtraData; - data->thread=StartThread(qsa_proc_playback, device); - if (data->thread==NULL) - { + if(!StartThread(&data->thread, qsa_proc_playback, device)) return ALC_FALSE; - } return ALC_TRUE; } diff --git a/Alc/backends/sndio.c b/Alc/backends/sndio.c index 4c3a5de6..d61ab3df 100644 --- a/Alc/backends/sndio.c +++ b/Alc/backends/sndio.c @@ -26,6 +26,7 @@ #include "alMain.h" #include "alu.h" +#include "threads.h" #include @@ -46,7 +47,7 @@ typedef struct { ALsizei data_size; volatile int killNow; - ALvoid *thread; + althread_t thread; } sndio_data; @@ -223,8 +224,7 @@ static ALCboolean sndio_start_playback(ALCdevice *device) data->data_size = device->UpdateSize * FrameSizeFromDevFmt(device->FmtChans, device->FmtType); data->mix_data = calloc(1, data->data_size); - data->thread = StartThread(sndio_proc, device); - if(data->thread == NULL) + if(!StartThread(&data->thread, sndio_proc, device)) { sio_stop(data->sndHandle); free(data->mix_data); diff --git a/Alc/backends/solaris.c b/Alc/backends/solaris.c index b9288197..c6fd32e9 100644 --- a/Alc/backends/solaris.c +++ b/Alc/backends/solaris.c @@ -33,6 +33,7 @@ #include "alMain.h" #include "alu.h" +#include "threads.h" #include @@ -43,11 +44,12 @@ static const char *solaris_driver = "/dev/audio"; typedef struct { int fd; - volatile int killNow; - ALvoid *thread; ALubyte *mix_data; int data_size; + + volatile int killNow; + althread_t thread; } solaris_data; @@ -208,8 +210,7 @@ static ALCboolean solaris_start_playback(ALCdevice *device) data->data_size = device->UpdateSize * FrameSizeFromDevFmt(device->FmtChans, device->FmtType); data->mix_data = calloc(1, data->data_size); - data->thread = StartThread(SolarisProc, device); - if(data->thread == NULL) + if(!StartThread(&data->thread, SolarisProc, device)) { free(data->mix_data); data->mix_data = NULL; diff --git a/Alc/backends/wave.c b/Alc/backends/wave.c index ce827fe8..6245ef43 100644 --- a/Alc/backends/wave.c +++ b/Alc/backends/wave.c @@ -29,6 +29,7 @@ #include "alMain.h" #include "alu.h" +#include "threads.h" typedef struct { @@ -39,7 +40,7 @@ typedef struct { ALuint size; volatile int killNow; - ALvoid *thread; + althread_t thread; } wave_data; @@ -288,8 +289,7 @@ static ALCboolean wave_start_playback(ALCdevice *device) return ALC_FALSE; } - data->thread = StartThread(WaveProc, device); - if(data->thread == NULL) + if(!StartThread(&data->thread, WaveProc, device)) { free(data->buffer); data->buffer = NULL; diff --git a/Alc/backends/winmm.c b/Alc/backends/winmm.c index e003375c..5a64645b 100644 --- a/Alc/backends/winmm.c +++ b/Alc/backends/winmm.c @@ -29,6 +29,7 @@ #include "alMain.h" #include "alu.h" +#include "threads.h" #ifndef WAVE_FORMAT_IEEE_FLOAT #define WAVE_FORMAT_IEEE_FLOAT 0x0003 diff --git a/Alc/threads.c b/Alc/threads.c new file mode 100644 index 00000000..fd08b432 --- /dev/null +++ b/Alc/threads.c @@ -0,0 +1,152 @@ +/** + * OpenAL cross platform audio library + * Copyright (C) 1999-2007 by authors. + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + * Or go to http://www.gnu.org/copyleft/lgpl.html + */ + +#include "config.h" + +#include "threads.h" + +#include + +#include "alMain.h" +#include "alThunk.h" + +#define THREAD_STACK_SIZE (1*1024*1024) /* 1MB */ + +#ifdef _WIN32 + +typedef struct althread_info { + ALuint (*func)(ALvoid*); + ALvoid *ptr; + HANDLE hdl; +} althread_info; + +static DWORD CALLBACK StarterFunc(void *ptr) +{ + althread_info *inf = (althread_info*)ptr; + ALuint ret; + + ret = inf->func(inf->ptr); + ExitThread((DWORD)ret); + + return (DWORD)ret; +} + + +ALboolean StartThread(althread_t *thread, ALuint (*func)(ALvoid*), ALvoid *ptr) +{ + althread_info *info; + DWORD dummy; + + info = malloc(sizeof(*info)); + if(!info) return AL_FALSE; + + info->func = func; + info->ptr = ptr; + + info->hdl = CreateThread(NULL, THREAD_STACK_SIZE, StarterFunc, info, 0, &dummy); + if(!info->hdl) + { + free(info); + return AL_FALSE; + } + + *thread = info; + return AL_TRUE; +} + +ALuint StopThread(althread_t thread) +{ + DWORD ret = 0; + + WaitForSingleObject(thread->hdl, INFINITE); + GetExitCodeThread(thread->hdl, &ret); + CloseHandle(thread->hdl); + + free(thread); + + return (ALuint)ret; +} + +#else + +#include + +typedef struct althread_info { + ALuint (*func)(ALvoid*); + ALvoid *ptr; + ALuint ret; + pthread_t hdl; +} althread_info; + +static void *StarterFunc(void *ptr) +{ + althread_info *inf = (althread_info*)ptr; + inf->ret = inf->func(inf->ptr); + return NULL; +} + + +ALboolean StartThread(althread_t *thread, ALuint (*func)(ALvoid*), ALvoid *ptr) +{ + pthread_attr_t attr; + althread_info *info; + + info = malloc(sizeof(*info)); + if(!info) return AL_FALSE; + + if(pthread_attr_init(&attr) != 0) + { + free(info); + return AL_FALSE; + } + if(pthread_attr_setstacksize(&attr, THREAD_STACK_SIZE) != 0) + { + pthread_attr_destroy(&attr); + free(info); + return AL_FALSE; + } + + info->func = func; + info->ptr = ptr; + if(pthread_create(&info->hdl, &attr, StarterFunc, info) != 0) + { + pthread_attr_destroy(&attr); + free(info); + return AL_FALSE; + } + pthread_attr_destroy(&attr); + + *thread = info; + return AL_TRUE; +} + +ALuint StopThread(althread_t thread) +{ + ALuint ret; + + pthread_join(thread->hdl, NULL); + ret = thread->ret; + + free(thread); + + return ret; +} + +#endif diff --git a/CMakeLists.txt b/CMakeLists.txt index f9efda81..3346b0e5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -489,7 +489,6 @@ SET(ALC_OBJS Alc/ALc.c Alc/ALu.c Alc/alcConfig.c Alc/alcRing.c - Alc/alcThread.c Alc/bs2b.c Alc/effects/autowah.c Alc/effects/chorus.c @@ -505,6 +504,7 @@ SET(ALC_OBJS Alc/ALc.c Alc/helpers.c Alc/hrtf.c Alc/panning.c + Alc/threads.c Alc/mixer.c Alc/mixer_c.c ) diff --git a/OpenAL32/Include/alMain.h b/OpenAL32/Include/alMain.h index 95146c1b..bfe575bd 100644 --- a/OpenAL32/Include/alMain.h +++ b/OpenAL32/Include/alMain.h @@ -815,10 +815,6 @@ typedef struct { void SetMixerFPUMode(FPUCtl *ctl); void RestoreFPUMode(const FPUCtl *ctl); -ALvoid *StartThread(ALuint (*func)(ALvoid*), ALvoid *ptr); -ALuint StopThread(ALvoid *thread); - -void SetThreadName(const char *name); typedef struct RingBuffer RingBuffer; RingBuffer *CreateRingBuffer(ALsizei frame_size, ALsizei length); diff --git a/OpenAL32/Include/threads.h b/OpenAL32/Include/threads.h new file mode 100644 index 00000000..26493101 --- /dev/null +++ b/OpenAL32/Include/threads.h @@ -0,0 +1,14 @@ +#ifndef AL_THREADS_H +#define AL_THREADS_H + +#include "alMain.h" + +struct althread_info; +typedef struct althread_info* althread_t; + +ALboolean StartThread(althread_t *out, ALuint (*func)(ALvoid*), ALvoid *ptr); +ALuint StopThread(althread_t thread); + +void SetThreadName(const char *name); + +#endif /* AL_THREADS_H */ -- cgit v1.2.3 From c1cdd3095bf2334298b6965f5e4f49510a826bd6 Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Mon, 28 Oct 2013 08:29:19 -0700 Subject: Convert the Null backend to the ALCbackend style --- Alc/ALc.c | 118 ++++++++++++++++++++++++++-------- Alc/backends/base.h | 2 + Alc/backends/null.c | 160 ++++++++++++++++++++++++++++------------------ OpenAL32/Include/alMain.h | 3 - 4 files changed, 193 insertions(+), 90 deletions(-) (limited to 'Alc/backends/null.c') diff --git a/Alc/ALc.c b/Alc/ALc.c index 37e3290f..f98f5af2 100644 --- a/Alc/ALc.c +++ b/Alc/ALc.c @@ -46,6 +46,7 @@ ************************************************/ struct BackendInfo { const char *name; + ALCbackendFactory* (*getFactory)(void); ALCboolean (*Init)(BackendFuncs*); void (*Deinit)(void); void (*Probe)(enum DevProbe); @@ -55,51 +56,51 @@ struct BackendInfo { #define EmptyFuncs { NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL } static struct BackendInfo BackendList[] = { #ifdef HAVE_PULSEAUDIO - { "pulse", alc_pulse_init, alc_pulse_deinit, alc_pulse_probe, EmptyFuncs }, + { "pulse", NULL, alc_pulse_init, alc_pulse_deinit, alc_pulse_probe, EmptyFuncs }, #endif #ifdef HAVE_ALSA - { "alsa", alc_alsa_init, alc_alsa_deinit, alc_alsa_probe, EmptyFuncs }, + { "alsa", NULL, alc_alsa_init, alc_alsa_deinit, alc_alsa_probe, EmptyFuncs }, #endif #ifdef HAVE_COREAUDIO - { "core", alc_ca_init, alc_ca_deinit, alc_ca_probe, EmptyFuncs }, + { "core", NULL, alc_ca_init, alc_ca_deinit, alc_ca_probe, EmptyFuncs }, #endif #ifdef HAVE_OSS - { "oss", alc_oss_init, alc_oss_deinit, alc_oss_probe, EmptyFuncs }, + { "oss", NULL, alc_oss_init, alc_oss_deinit, alc_oss_probe, EmptyFuncs }, #endif #ifdef HAVE_SOLARIS - { "solaris", alc_solaris_init, alc_solaris_deinit, alc_solaris_probe, EmptyFuncs }, + { "solaris", NULL, alc_solaris_init, alc_solaris_deinit, alc_solaris_probe, EmptyFuncs }, #endif #ifdef HAVE_SNDIO - { "sndio", alc_sndio_init, alc_sndio_deinit, alc_sndio_probe, EmptyFuncs }, + { "sndio", NULL, alc_sndio_init, alc_sndio_deinit, alc_sndio_probe, EmptyFuncs }, #endif #ifdef HAVE_QSA - { "qsa", alc_qsa_init, alc_qsa_deinit, alc_qsa_probe, EmptyFuncs }, + { "qsa", NULL, alc_qsa_init, alc_qsa_deinit, alc_qsa_probe, EmptyFuncs }, #endif #ifdef HAVE_MMDEVAPI - { "mmdevapi", alcMMDevApiInit, alcMMDevApiDeinit, alcMMDevApiProbe, EmptyFuncs }, + { "mmdevapi", NULL, alcMMDevApiInit, alcMMDevApiDeinit, alcMMDevApiProbe, EmptyFuncs }, #endif #ifdef HAVE_DSOUND - { "dsound", alcDSoundInit, alcDSoundDeinit, alcDSoundProbe, EmptyFuncs }, + { "dsound", NULL, alcDSoundInit, alcDSoundDeinit, alcDSoundProbe, EmptyFuncs }, #endif #ifdef HAVE_WINMM - { "winmm", alcWinMMInit, alcWinMMDeinit, alcWinMMProbe, EmptyFuncs }, + { "winmm", NULL, alcWinMMInit, alcWinMMDeinit, alcWinMMProbe, EmptyFuncs }, #endif #ifdef HAVE_PORTAUDIO - { "port", alc_pa_init, alc_pa_deinit, alc_pa_probe, EmptyFuncs }, + { "port", NULL, alc_pa_init, alc_pa_deinit, alc_pa_probe, EmptyFuncs }, #endif #ifdef HAVE_OPENSL - { "opensl", alc_opensl_init, alc_opensl_deinit, alc_opensl_probe, EmptyFuncs }, + { "opensl", NULL, alc_opensl_init, alc_opensl_deinit, alc_opensl_probe, EmptyFuncs }, #endif - { "null", alc_null_init, alc_null_deinit, alc_null_probe, EmptyFuncs }, + { "null", ALCnullBackendFactory_getFactory, NULL, NULL, NULL, EmptyFuncs }, #ifdef HAVE_WAVE - { "wave", alc_wave_init, alc_wave_deinit, alc_wave_probe, EmptyFuncs }, + { "wave", NULL, alc_wave_init, alc_wave_deinit, alc_wave_probe, EmptyFuncs }, #endif - { NULL, NULL, NULL, NULL, EmptyFuncs } + { NULL, NULL, NULL, NULL, NULL, EmptyFuncs } }; static struct BackendInfo BackendLoopback = { - "loopback", alc_loopback_init, alc_loopback_deinit, alc_loopback_probe, EmptyFuncs + "loopback", NULL, alc_loopback_init, alc_loopback_deinit, alc_loopback_probe, EmptyFuncs }; #undef EmptyFuncs @@ -1059,7 +1060,7 @@ static void alc_initconfig(void) len = (next ? ((size_t)(next-devs)) : strlen(devs)); while(len > 0 && isspace(devs[len-1])) len--; - for(n = i;BackendList[n].Init;n++) + for(n = i;BackendList[n].name;n++) { if(len == strlen(BackendList[n].name) && strncmp(BackendList[n].name, devs, len) == 0) @@ -1069,7 +1070,7 @@ static void alc_initconfig(void) do { BackendList[n] = BackendList[n+1]; ++n; - } while(BackendList[n].Init); + } while(BackendList[n].name); } else { @@ -1091,14 +1092,40 @@ static void alc_initconfig(void) if(endlist) { BackendList[i].name = NULL; + BackendList[i].getFactory = NULL; BackendList[i].Init = NULL; BackendList[i].Deinit = NULL; BackendList[i].Probe = NULL; } } - for(i = 0;BackendList[i].Init && (!PlaybackBackend.name || !CaptureBackend.name);i++) + for(i = 0;(BackendList[i].Init || BackendList[i].getFactory) && (!PlaybackBackend.name || !CaptureBackend.name);i++) { + if(BackendList[i].getFactory) + { + ALCbackendFactory *factory = BackendList[i].getFactory(); + if(!VCALL0(factory,init,())) + { + WARN("Failed to initialize backend \"%s\"\n", BackendList[i].name); + continue; + } + + TRACE("Initialized backend \"%s\"\n", BackendList[i].name); + if(!PlaybackBackend.name && VCALL(factory,support,(ALCbackend_Playback))) + { + PlaybackBackend = BackendList[i]; + TRACE("Added \"%s\" for playback\n", PlaybackBackend.name); + } +#if 0 + if(!CaptureBackend.name && VCALL(factory,support,(ALCbackend_Capture))) + { + CaptureBackend = BackendList[i]; + TRACE("Added \"%s\" for capture\n", CaptureBackend.name); + } +#endif + continue; + } + if(!BackendList[i].Init(&BackendList[i].Funcs)) { WARN("Failed to initialize backend \"%s\"\n", BackendList[i].name); @@ -1205,8 +1232,16 @@ static void alc_deinit(void) memset(&PlaybackBackend, 0, sizeof(PlaybackBackend)); memset(&CaptureBackend, 0, sizeof(CaptureBackend)); - for(i = 0;BackendList[i].Deinit;i++) - BackendList[i].Deinit(); + for(i = 0;BackendList[i].Deinit || BackendList[i].getFactory;i++) + { + if(!BackendList[i].getFactory) + BackendList[i].Deinit(); + else + { + ALCbackendFactory *factory = BackendList[i].getFactory(); + VCALL0(factory,deinit,()); + } + } BackendLoopback.Deinit(); alc_deinit_safe(); @@ -1225,10 +1260,26 @@ static void ProbeList(ALCchar **list, size_t *listsize, enum DevProbe type) *list = NULL; *listsize = 0; - if(type == ALL_DEVICE_PROBE && PlaybackBackend.Probe) - PlaybackBackend.Probe(type); - else if(type == CAPTURE_DEVICE_PROBE && CaptureBackend.Probe) - CaptureBackend.Probe(type); + if(type == ALL_DEVICE_PROBE && (PlaybackBackend.Probe || PlaybackBackend.getFactory)) + { + if(!PlaybackBackend.getFactory) + PlaybackBackend.Probe(type); + else + { + ALCbackendFactory *factory = PlaybackBackend.getFactory(); + VCALL(factory,probe,(type)); + } + } + else if(type == CAPTURE_DEVICE_PROBE && (CaptureBackend.Probe || CaptureBackend.getFactory)) + { + if(!CaptureBackend.getFactory) + CaptureBackend.Probe(type); + else + { + ALCbackendFactory *factory = CaptureBackend.getFactory(); + VCALL(factory,probe,(type)); + } + } UnlockLists(); } @@ -2937,7 +2988,21 @@ ALC_API ALCdevice* ALC_APIENTRY alcOpenDevice(const ALCchar *deviceName) device->NumUpdates = 4; device->UpdateSize = 1024; - device->Backend = create_backend_wrapper(device); + if(!PlaybackBackend.getFactory) + device->Backend = create_backend_wrapper(device); + else + { + ALCbackendFactory *factory = PlaybackBackend.getFactory(); + device->Backend = VCALL(factory,createBackend,(device)); + } + if(!device->Backend) + { + DeleteCriticalSection(&device->Mutex); + al_free(device); + alcSetError(NULL, ALC_OUT_OF_MEMORY); + return NULL; + } + if(ConfigValueStr(NULL, "channels", &fmt)) { @@ -3077,6 +3142,7 @@ ALC_API ALCdevice* ALC_APIENTRY alcOpenDevice(const ALCchar *deviceName) // Find a playback device to open if((err=VCALL(device->Backend,open,(deviceName))) != ALC_NO_ERROR) { + DELETE_OBJ(device->Backend); DeleteCriticalSection(&device->Mutex); al_free(device); alcSetError(NULL, err); diff --git a/Alc/backends/base.h b/Alc/backends/base.h index 7c1b918b..272a3f65 100644 --- a/Alc/backends/base.h +++ b/Alc/backends/base.h @@ -115,4 +115,6 @@ static const struct ALCbackendFactoryVtable T##_ALCbackendFactory_vtable = { \ } +ALCbackendFactory *ALCnullBackendFactory_getFactory(void); + #endif /* AL_BACKENDS_BASE_H */ diff --git a/Alc/backends/null.c b/Alc/backends/null.c index 9742424c..d21ebf0c 100644 --- a/Alc/backends/null.c +++ b/Alc/backends/null.c @@ -29,19 +29,24 @@ #include "alu.h" #include "threads.h" +#include "backends/base.h" + + +typedef struct ALCnullBackend { + DERIVE_FROM_TYPE(ALCbackend); -typedef struct { volatile int killNow; althread_t thread; -} null_data; +} ALCnullBackend; +#define ALCNULLBACKEND_INITIALIZER { { GET_VTABLE2(ALCbackend, ALCnullBackend) } } static const ALCchar nullDevice[] = "No Output"; -static ALuint NullProc(ALvoid *ptr) +static ALuint ALCnullBackend_mixerProc(ALvoid *ptr) { - ALCdevice *Device = (ALCdevice*)ptr; - null_data *data = (null_data*)Device->ExtraData; + ALCnullBackend *self = (ALCnullBackend*)ptr; + ALCdevice *device = STATIC_CAST(ALCbackend, self)->mDevice; ALuint now, start; ALuint64 avail, done; @@ -50,118 +55,129 @@ static ALuint NullProc(ALvoid *ptr) done = 0; start = timeGetTime(); - while(!data->killNow && Device->Connected) + while(!self->killNow && device->Connected) { now = timeGetTime(); - avail = (ALuint64)(now-start) * Device->Frequency / 1000; + avail = (ALuint64)(now-start) * device->Frequency / 1000; if(avail < done) { /* Timer wrapped (50 days???). Add the remainder of the cycle to * the available count and reset the number of samples done */ - avail += (U64(1)<<32)*Device->Frequency/1000 - done; + avail += (U64(1)<<32)*device->Frequency/1000 - done; done = 0; } - if(avail-done < Device->UpdateSize) + if(avail-done < device->UpdateSize) { - ALuint restTime = (Device->UpdateSize - (avail-done)) * 1000 / - Device->Frequency; + ALuint restTime = (device->UpdateSize - (avail-done)) * 1000 / + device->Frequency; Sleep(restTime); continue; } do { - aluMixData(Device, NULL, Device->UpdateSize); - done += Device->UpdateSize; - } while(avail-done >= Device->UpdateSize); + aluMixData(device, NULL, device->UpdateSize); + done += device->UpdateSize; + } while(avail-done >= device->UpdateSize); } return 0; } -static ALCenum null_open_playback(ALCdevice *device, const ALCchar *deviceName) + +static void ALCnullBackend_Destruct(ALCnullBackend* UNUSED(self)) { - null_data *data; +} - if(!deviceName) - deviceName = nullDevice; - else if(strcmp(deviceName, nullDevice) != 0) +static ALCenum ALCnullBackend_open(ALCnullBackend *self, const ALCchar *name) +{ + ALCdevice *device; + + if(!name) + name = nullDevice; + else if(strcmp(name, nullDevice) != 0) return ALC_INVALID_VALUE; - data = (null_data*)calloc(1, sizeof(*data)); + device = STATIC_CAST(ALCbackend, self)->mDevice; + device->DeviceName = strdup(name); - device->DeviceName = strdup(deviceName); - device->ExtraData = data; return ALC_NO_ERROR; } -static void null_close_playback(ALCdevice *device) +static void ALCnullBackend_close(ALCnullBackend* UNUSED(self)) { - null_data *data = (null_data*)device->ExtraData; +} - free(data); - device->ExtraData = NULL; +static ALCboolean ALCnullBackend_reset(ALCnullBackend *self) +{ + SetDefaultWFXChannelOrder(STATIC_CAST(ALCbackend, self)->mDevice); + return ALC_TRUE; } -static ALCboolean null_reset_playback(ALCdevice *device) +static ALCboolean ALCnullBackend_start(ALCnullBackend *self) { - SetDefaultWFXChannelOrder(device); + if(!StartThread(&self->thread, ALCnullBackend_mixerProc, self)) + return ALC_FALSE; return ALC_TRUE; } -static ALCboolean null_start_playback(ALCdevice *device) +static void ALCnullBackend_stop(ALCnullBackend *self) { - null_data *data = (null_data*)device->ExtraData; + if(!self->thread) + return; - if(!StartThread(&data->thread, NullProc, device)) - return ALC_FALSE; + self->killNow = 1; + StopThread(self->thread); + self->thread = NULL; - return ALC_TRUE; + self->killNow = 0; } -static void null_stop_playback(ALCdevice *device) +static ALint64 ALCnullBackend_getLatency(ALCnullBackend *self) { - null_data *data = (null_data*)device->ExtraData; + return ALCbackend_getLatency(STATIC_CAST(ALCbackend, self)); +} - if(!data->thread) - return; +static void ALCnullBackend_lock(ALCnullBackend *self) +{ + ALCbackend_lock(STATIC_CAST(ALCbackend, self)); +} - data->killNow = 1; - StopThread(data->thread); - data->thread = NULL; +static void ALCnullBackend_unlock(ALCnullBackend *self) +{ + ALCbackend_unlock(STATIC_CAST(ALCbackend, self)); +} - data->killNow = 0; +static void ALCnullBackend_Delete(ALCnullBackend *self) +{ + free(self); } +DEFINE_ALCBACKEND_VTABLE(ALCnullBackend); + -static const BackendFuncs null_funcs = { - null_open_playback, - null_close_playback, - null_reset_playback, - null_start_playback, - null_stop_playback, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - ALCdevice_LockDefault, - ALCdevice_UnlockDefault, - ALCdevice_GetLatencyDefault -}; +typedef struct ALCnullBackendFactory { + DERIVE_FROM_TYPE(ALCbackendFactory); +} ALCnullBackendFactory; +#define ALCNULLBACKENDFACTORY_INITIALIZER { { GET_VTABLE2(ALCnullBackendFactory, ALCbackendFactory) } } -ALCboolean alc_null_init(BackendFuncs *func_list) +ALCboolean ALCnullBackendFactory_init(ALCnullBackendFactory* UNUSED(self)) { - *func_list = null_funcs; return ALC_TRUE; } -void alc_null_deinit(void) +void ALCnullBackendFactory_deinit(ALCnullBackendFactory* UNUSED(self)) { } -void alc_null_probe(enum DevProbe type) +ALCboolean ALCnullBackendFactory_support(ALCnullBackendFactory* UNUSED(self), ALCbackend_Type type) +{ + if(type == ALCbackend_Playback) + return ALC_TRUE; + return ALC_FALSE; +} + +void ALCnullBackendFactory_probe(ALCnullBackendFactory* UNUSED(self), enum DevProbe type) { switch(type) { @@ -172,3 +188,25 @@ void alc_null_probe(enum DevProbe type) break; } } + +ALCbackend* ALCnullBackendFactory_createBackend(ALCnullBackendFactory* UNUSED(self), ALCdevice *device) +{ + ALCnullBackend *backend; + + backend = calloc(1, sizeof(*backend)); + if(!backend) return NULL; + SET_VTABLE2(ALCnullBackend, ALCbackend, backend); + + STATIC_CAST(ALCbackend, backend)->mDevice = device; + + return STATIC_CAST(ALCbackend, backend); +} + +DEFINE_ALCBACKENDFACTORY_VTABLE(ALCnullBackendFactory); + + +ALCbackendFactory *ALCnullBackendFactory_getFactory(void) +{ + static ALCnullBackendFactory factory = ALCNULLBACKENDFACTORY_INITIALIZER; + return STATIC_CAST(ALCbackendFactory, &factory); +} diff --git a/OpenAL32/Include/alMain.h b/OpenAL32/Include/alMain.h index 01a2ec37..74c5b0e6 100644 --- a/OpenAL32/Include/alMain.h +++ b/OpenAL32/Include/alMain.h @@ -497,9 +497,6 @@ void alc_opensl_probe(enum DevProbe type); ALCboolean alc_qsa_init(BackendFuncs *func_list); void alc_qsa_deinit(void); void alc_qsa_probe(enum DevProbe type); -ALCboolean alc_null_init(BackendFuncs *func_list); -void alc_null_deinit(void); -void alc_null_probe(enum DevProbe type); ALCboolean alc_loopback_init(BackendFuncs *func_list); void alc_loopback_deinit(void); void alc_loopback_probe(enum DevProbe type); -- cgit v1.2.3 From f24cb447818ea21ff5a5d80d6396abb4723fd2ed Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Mon, 28 Oct 2013 12:05:33 -0700 Subject: Move the device mutex to the backend --- Alc/ALc.c | 53 +++++++++++++++++++++++++++++++++-------------- Alc/alcRing.c | 1 + Alc/backends/alsa.c | 1 + Alc/backends/base.h | 5 +++++ Alc/backends/dsound.c | 1 + Alc/backends/mmdevapi.c | 1 + Alc/backends/null.c | 11 ++++++++-- Alc/backends/oss.c | 1 + Alc/backends/pulseaudio.c | 1 + Alc/backends/solaris.c | 1 + Alc/backends/wave.c | 1 + Alc/helpers.c | 2 ++ Alc/threads.c | 3 +++ OpenAL32/Include/alMain.h | 4 ---- OpenAL32/alError.c | 5 +++++ 15 files changed, 70 insertions(+), 21 deletions(-) (limited to 'Alc/backends/null.c') diff --git a/Alc/ALc.c b/Alc/ALc.c index 2cbc7331..18ccb5e7 100644 --- a/Alc/ALc.c +++ b/Alc/ALc.c @@ -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 #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 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 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 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 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 #endif #include +#include +#include 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 + 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 +#ifdef HAVE_WINDOWS_H +#define WIN32_LEAN_AND_MEAN +#include +#endif + #include "alMain.h" #include "AL/alc.h" #include "alError.h" -- cgit v1.2.3 From 0617df9b5f6dd2b01d248edd0b4ad989d1c343f8 Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Mon, 28 Oct 2013 12:12:26 -0700 Subject: Fix a couple casts --- Alc/backends/null.c | 4 ++-- Alc/threads.c | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'Alc/backends/null.c') diff --git a/Alc/backends/null.c b/Alc/backends/null.c index af68c585..ecf827a9 100644 --- a/Alc/backends/null.c +++ b/Alc/backends/null.c @@ -70,8 +70,8 @@ static ALuint ALCnullBackend_mixerProc(ALvoid *ptr) } if(avail-done < device->UpdateSize) { - ALuint restTime = (device->UpdateSize - (avail-done)) * 1000 / - device->Frequency; + ALuint restTime = (ALuint)((device->UpdateSize - (avail-done)) * 1000 / + device->Frequency); Sleep(restTime); continue; } diff --git a/Alc/threads.c b/Alc/threads.c index 1c422949..64586ae9 100644 --- a/Alc/threads.c +++ b/Alc/threads.c @@ -105,7 +105,7 @@ void SetThreadName(const char *name) info.dwFlags = 0; __try { - RaiseException(MS_VC_EXCEPTION, 0, sizeof(info)/sizeof(DWORD), (DWORD*)&info); + RaiseException(MS_VC_EXCEPTION, 0, sizeof(info)/sizeof(DWORD), (ULONG_PTR*)&info); } __except(EXCEPTION_CONTINUE_EXECUTION) { } -- cgit v1.2.3 From f8c95f1e90a9bf4e57dbd4e29604e36916f354e4 Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Mon, 28 Oct 2013 13:51:55 -0700 Subject: Add audio capture methods to ALCbackend --- Alc/backends/base.c | 10 ++++++++++ Alc/backends/base.h | 9 +++++++++ Alc/backends/null.c | 10 ++++++++++ 3 files changed, 29 insertions(+) (limited to 'Alc/backends/null.c') diff --git a/Alc/backends/base.c b/Alc/backends/base.c index 70f7a181..8837b0c8 100644 --- a/Alc/backends/base.c +++ b/Alc/backends/base.c @@ -82,6 +82,16 @@ static void BackendWrapper_stop(BackendWrapper *self) device->Funcs->StopPlayback(device); } +ALCenum BackendWrapper_captureSamples(BackendWrapper* UNUSED(self), void* UNUSED(buffer), ALCuint UNUSED(samples)) +{ + return ALC_INVALID_VALUE; +} + +ALCuint BackendWrapper_availableSamples(BackendWrapper* UNUSED(self)) +{ + return 0; +} + static ALint64 BackendWrapper_getLatency(BackendWrapper *self) { ALCdevice *device = STATIC_CAST(ALCbackend, self)->mDevice; diff --git a/Alc/backends/base.h b/Alc/backends/base.h index a118c82e..9ba33097 100644 --- a/Alc/backends/base.h +++ b/Alc/backends/base.h @@ -31,6 +31,9 @@ struct ALCbackendVtable { ALCboolean (*start)(ALCbackend*); void (*stop)(ALCbackend*); + ALCenum (*captureSamples)(ALCbackend*, void*, ALCuint); + ALCuint (*availableSamples)(ALCbackend*); + ALint64 (*getLatency)(ALCbackend*); void (*lock)(ALCbackend*); @@ -52,6 +55,10 @@ static ALCboolean T##_ALCbackend_start(ALCbackend *obj) \ { return T##_start(STATIC_UPCAST(T, ALCbackend, obj)); } \ static void T##_ALCbackend_stop(ALCbackend *obj) \ { T##_stop(STATIC_UPCAST(T, ALCbackend, obj)); } \ +static ALCenum T##_ALCbackend_captureSamples(ALCbackend *obj, void *a, ALCuint b) \ +{ return T##_captureSamples(STATIC_UPCAST(T, ALCbackend, obj), a, b); } \ +static ALCuint T##_ALCbackend_availableSamples(ALCbackend *obj) \ +{ return T##_availableSamples(STATIC_UPCAST(T, ALCbackend, obj)); } \ static ALint64 T##_ALCbackend_getLatency(ALCbackend *obj) \ { return T##_getLatency(STATIC_UPCAST(T, ALCbackend, obj)); } \ static void T##_ALCbackend_lock(ALCbackend *obj) \ @@ -69,6 +76,8 @@ static const struct ALCbackendVtable T##_ALCbackend_vtable = { \ T##_ALCbackend_reset, \ T##_ALCbackend_start, \ T##_ALCbackend_stop, \ + T##_ALCbackend_captureSamples, \ + T##_ALCbackend_availableSamples, \ T##_ALCbackend_getLatency, \ T##_ALCbackend_lock, \ T##_ALCbackend_unlock, \ diff --git a/Alc/backends/null.c b/Alc/backends/null.c index ecf827a9..ab371747 100644 --- a/Alc/backends/null.c +++ b/Alc/backends/null.c @@ -140,6 +140,16 @@ static void ALCnullBackend_stop(ALCnullBackend *self) self->killNow = 0; } +ALCenum ALCnullBackend_captureSamples(ALCnullBackend* UNUSED(self), void* UNUSED(buffer), ALCuint UNUSED(samples)) +{ + return ALC_INVALID_VALUE; +} + +ALCuint ALCnullBackend_availableSamples(ALCnullBackend* UNUSED(self)) +{ + return 0; +} + static ALint64 ALCnullBackend_getLatency(ALCnullBackend *self) { return ALCbackend_getLatency(STATIC_CAST(ALCbackend, self)); -- cgit v1.2.3 From a407d5763949fdb421b38ac4f624b8e9193f33e5 Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Mon, 28 Oct 2013 17:23:19 -0700 Subject: Rename the support method to querySupport --- Alc/ALc.c | 4 ++-- Alc/backends/base.h | 8 ++++---- Alc/backends/null.c | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) (limited to 'Alc/backends/null.c') diff --git a/Alc/ALc.c b/Alc/ALc.c index 53a3917b..7527ebf8 100644 --- a/Alc/ALc.c +++ b/Alc/ALc.c @@ -1031,12 +1031,12 @@ static void alc_initconfig(void) } TRACE("Initialized backend \"%s\"\n", BackendList[i].name); - if(!PlaybackBackend.name && VCALL(factory,support)(ALCbackend_Playback)) + if(!PlaybackBackend.name && VCALL(factory,querySupport)(ALCbackend_Playback)) { PlaybackBackend = BackendList[i]; TRACE("Added \"%s\" for playback\n", PlaybackBackend.name); } - if(!CaptureBackend.name && VCALL(factory,support)(ALCbackend_Capture)) + if(!CaptureBackend.name && VCALL(factory,querySupport)(ALCbackend_Capture)) { CaptureBackend = BackendList[i]; TRACE("Added \"%s\" for capture\n", CaptureBackend.name); diff --git a/Alc/backends/base.h b/Alc/backends/base.h index ed0fff50..f5950ba1 100644 --- a/Alc/backends/base.h +++ b/Alc/backends/base.h @@ -102,7 +102,7 @@ struct ALCbackendFactoryVtable { ALCboolean (*const init)(ALCbackendFactory *self); void (*const deinit)(ALCbackendFactory *self); - ALCboolean (*const support)(ALCbackendFactory *self, ALCbackend_Type type); + ALCboolean (*const querySupport)(ALCbackendFactory *self, ALCbackend_Type type); void (*const probe)(ALCbackendFactory *self, enum DevProbe type); @@ -114,8 +114,8 @@ static ALCboolean T##_ALCbackendFactory_init(ALCbackendFactory *obj) \ { return T##_init(STATIC_UPCAST(T, ALCbackendFactory, obj)); } \ static void T##_ALCbackendFactory_deinit(ALCbackendFactory *obj) \ { T##_deinit(STATIC_UPCAST(T, ALCbackendFactory, obj)); } \ -static ALCboolean T##_ALCbackendFactory_support(ALCbackendFactory *obj, ALCbackend_Type a) \ -{ return T##_support(STATIC_UPCAST(T, ALCbackendFactory, obj), a); } \ +static ALCboolean T##_ALCbackendFactory_querySupport(ALCbackendFactory *obj, ALCbackend_Type a) \ +{ return T##_querySupport(STATIC_UPCAST(T, ALCbackendFactory, obj), a); } \ static void T##_ALCbackendFactory_probe(ALCbackendFactory *obj, enum DevProbe a) \ { T##_probe(STATIC_UPCAST(T, ALCbackendFactory, obj), a); } \ static ALCbackend* T##_ALCbackendFactory_createBackend(ALCbackendFactory *obj, ALCdevice *a) \ @@ -124,7 +124,7 @@ static ALCbackend* T##_ALCbackendFactory_createBackend(ALCbackendFactory *obj, A static const struct ALCbackendFactoryVtable T##_ALCbackendFactory_vtable = { \ T##_ALCbackendFactory_init, \ T##_ALCbackendFactory_deinit, \ - T##_ALCbackendFactory_support, \ + T##_ALCbackendFactory_querySupport, \ T##_ALCbackendFactory_probe, \ T##_ALCbackendFactory_createBackend, \ } diff --git a/Alc/backends/null.c b/Alc/backends/null.c index ab371747..9e762190 100644 --- a/Alc/backends/null.c +++ b/Alc/backends/null.c @@ -187,7 +187,7 @@ void ALCnullBackendFactory_deinit(ALCnullBackendFactory* UNUSED(self)) { } -ALCboolean ALCnullBackendFactory_support(ALCnullBackendFactory* UNUSED(self), ALCbackend_Type type) +ALCboolean ALCnullBackendFactory_querySupport(ALCnullBackendFactory* UNUSED(self), ALCbackend_Type type) { if(type == ALCbackend_Playback) return ALC_TRUE; -- cgit v1.2.3 From 3c65c946d4781cd6773c748b1e13f4c61db535e6 Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Mon, 28 Oct 2013 22:03:54 -0700 Subject: Fix capture with the new backend interface --- Alc/ALc.c | 10 ++++++++-- Alc/backends/alsa.c | 31 ++++++++++++++++++++++++------- Alc/backends/base.h | 6 +++--- Alc/backends/null.c | 4 +++- 4 files changed, 38 insertions(+), 13 deletions(-) (limited to 'Alc/backends/null.c') diff --git a/Alc/ALc.c b/Alc/ALc.c index 4aaf765a..efbc4be5 100644 --- a/Alc/ALc.c +++ b/Alc/ALc.c @@ -2890,7 +2890,7 @@ ALC_API ALCdevice* ALC_APIENTRY alcOpenDevice(const ALCchar *deviceName) else { ALCbackendFactory *factory = PlaybackBackend.getFactory(); - device->Backend = VCALL(factory,createBackend)(device); + device->Backend = VCALL(factory,createBackend)(device, ALCbackend_Playback); } if(!device->Backend) { @@ -3152,7 +3152,13 @@ ALC_API ALCdevice* ALC_APIENTRY alcCaptureOpenDevice(const ALCchar *deviceName, device->DeviceName = NULL; - device->Backend = create_backend_wrapper(device, ALCbackend_Capture); + if(!CaptureBackend.getFactory) + device->Backend = create_backend_wrapper(device, ALCbackend_Capture); + else + { + ALCbackendFactory *factory = CaptureBackend.getFactory(); + device->Backend = VCALL(factory,createBackend)(device, ALCbackend_Capture); + } if(!device->Backend) { al_free(device); diff --git a/Alc/backends/alsa.c b/Alc/backends/alsa.c index c811bdfc..0bed0d4b 100644 --- a/Alc/backends/alsa.c +++ b/Alc/backends/alsa.c @@ -1466,17 +1466,34 @@ void ALCalsaBackendFactory_probe(ALCalsaBackendFactory* UNUSED(self), enum DevPr } } -ALCbackend* ALCalsaBackendFactory_createBackend(ALCalsaBackendFactory* UNUSED(self), ALCdevice *device) +ALCbackend* ALCalsaBackendFactory_createBackend(ALCalsaBackendFactory* UNUSED(self), ALCdevice *device, ALCbackend_Type type) { - ALCplaybackAlsa *backend; + if(type == ALCbackend_Playback) + { + ALCplaybackAlsa *backend; + + backend = calloc(1, sizeof(*backend)); + if(!backend) return NULL; + SET_VTABLE2(ALCplaybackAlsa, ALCbackend, backend); + + ALCplaybackAlsa_Construct(backend, device); + + return STATIC_CAST(ALCbackend, backend); + } + if(type == ALCbackend_Capture) + { + ALCcaptureAlsa *backend; - backend = calloc(1, sizeof(*backend)); - if(!backend) return NULL; - SET_VTABLE2(ALCplaybackAlsa, ALCbackend, backend); + backend = calloc(1, sizeof(*backend)); + if(!backend) return NULL; + SET_VTABLE2(ALCcaptureAlsa, ALCbackend, backend); - ALCplaybackAlsa_Construct(backend, device); + ALCcaptureAlsa_Construct(backend, device); + + return STATIC_CAST(ALCbackend, backend); + } - return STATIC_CAST(ALCbackend, backend); + return NULL; } DEFINE_ALCBACKENDFACTORY_VTABLE(ALCalsaBackendFactory); diff --git a/Alc/backends/base.h b/Alc/backends/base.h index f1da721d..d05ec0f5 100644 --- a/Alc/backends/base.h +++ b/Alc/backends/base.h @@ -106,7 +106,7 @@ struct ALCbackendFactoryVtable { void (*const probe)(ALCbackendFactory *self, enum DevProbe type); - ALCbackend* (*const createBackend)(ALCbackendFactory *self, ALCdevice *device); + ALCbackend* (*const createBackend)(ALCbackendFactory *self, ALCdevice *device, ALCbackend_Type type); }; #define DEFINE_ALCBACKENDFACTORY_VTABLE(T) \ @@ -118,8 +118,8 @@ static ALCboolean T##_ALCbackendFactory_querySupport(ALCbackendFactory *obj, ALC { return T##_querySupport(STATIC_UPCAST(T, ALCbackendFactory, obj), a); } \ static void T##_ALCbackendFactory_probe(ALCbackendFactory *obj, enum DevProbe a) \ { T##_probe(STATIC_UPCAST(T, ALCbackendFactory, obj), a); } \ -static ALCbackend* T##_ALCbackendFactory_createBackend(ALCbackendFactory *obj, ALCdevice *a) \ -{ return T##_createBackend(STATIC_UPCAST(T, ALCbackendFactory, obj), a); } \ +static ALCbackend* T##_ALCbackendFactory_createBackend(ALCbackendFactory *obj, ALCdevice *a, ALCbackend_Type b) \ +{ return T##_createBackend(STATIC_UPCAST(T, ALCbackendFactory, obj), a, b); } \ \ static const struct ALCbackendFactoryVtable T##_ALCbackendFactory_vtable = { \ T##_ALCbackendFactory_init, \ diff --git a/Alc/backends/null.c b/Alc/backends/null.c index 9e762190..c5b178de 100644 --- a/Alc/backends/null.c +++ b/Alc/backends/null.c @@ -206,10 +206,12 @@ void ALCnullBackendFactory_probe(ALCnullBackendFactory* UNUSED(self), enum DevPr } } -ALCbackend* ALCnullBackendFactory_createBackend(ALCnullBackendFactory* UNUSED(self), ALCdevice *device) +ALCbackend* ALCnullBackendFactory_createBackend(ALCnullBackendFactory* UNUSED(self), ALCdevice *device, ALCbackend_Type type) { ALCnullBackend *backend; + assert(type == ALCbackend_Playback); + backend = calloc(1, sizeof(*backend)); if(!backend) return NULL; SET_VTABLE2(ALCnullBackend, ALCbackend, backend); -- cgit v1.2.3 From d4aa4e16a0b6bb53ec9bbe0a8b3f467fb9a243f7 Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Tue, 29 Oct 2013 11:22:18 -0700 Subject: Add a macro to forward methods to a base type --- Alc/backends/alsa.c | 62 ++++++++++++++++++----------------------------- Alc/backends/loopback.c | 17 +++---------- Alc/backends/null.c | 39 ++++++++++------------------- OpenAL32/Include/alMain.h | 3 +++ 4 files changed, 43 insertions(+), 78 deletions(-) (limited to 'Alc/backends/null.c') diff --git a/Alc/backends/alsa.c b/Alc/backends/alsa.c index 0bed0d4b..586c1bf6 100644 --- a/Alc/backends/alsa.c +++ b/Alc/backends/alsa.c @@ -451,10 +451,12 @@ typedef struct ALCplaybackAlsa { volatile int killNow; althread_t thread; } ALCplaybackAlsa; +DECLARE_ALCBACKEND_VTABLE(ALCplaybackAlsa); static ALuint ALCplaybackAlsa_mixerProc(ALvoid *ptr); static ALuint ALCplaybackAlsa_mixerNoMMapProc(ALvoid *ptr); +static DECLARE_FORWARD(ALCplaybackAlsa, ALCbackend, void, Destruct) static ALCenum ALCplaybackAlsa_open(ALCplaybackAlsa *self, const ALCchar *name); static void ALCplaybackAlsa_close(ALCplaybackAlsa *self); static ALCboolean ALCplaybackAlsa_reset(ALCplaybackAlsa *self); @@ -462,8 +464,15 @@ static ALCboolean ALCplaybackAlsa_start(ALCplaybackAlsa *self); static void ALCplaybackAlsa_stop(ALCplaybackAlsa *self); static ALCenum ALCplaybackAlsa_captureSamples(ALCplaybackAlsa *self, ALCvoid *buffer, ALCuint samples); static ALCuint ALCplaybackAlsa_availableSamples(ALCplaybackAlsa *self); -static void ALCplaybackAlsa_lock(ALCplaybackAlsa *self); -static void ALCplaybackAlsa_unlock(ALCplaybackAlsa *self); +static DECLARE_FORWARD(ALCplaybackAlsa, ALCbackend, void, lock) +static DECLARE_FORWARD(ALCplaybackAlsa, ALCbackend, void, unlock) + + +static void ALCplaybackAlsa_Construct(ALCplaybackAlsa *self, ALCdevice *device) +{ + ALCbackend_Construct(STATIC_CAST(ALCbackend, self), device); + SET_VTABLE2(ALCplaybackAlsa, ALCbackend, self); +} static ALuint ALCplaybackAlsa_mixerProc(ALvoid *ptr) @@ -947,22 +956,6 @@ static ALint64 ALCplaybackAlsa_getLatency(ALCplaybackAlsa *self) return maxi64((ALint64)delay*1000000000/device->Frequency, 0); } -static void ALCplaybackAlsa_lock(ALCplaybackAlsa *self) -{ ALCbackend_lock(STATIC_CAST(ALCbackend, self)); } - -static void ALCplaybackAlsa_unlock(ALCplaybackAlsa *self) -{ ALCbackend_unlock(STATIC_CAST(ALCbackend, self)); } - - -static void ALCplaybackAlsa_Construct(ALCplaybackAlsa *self, ALCdevice *device) -{ - ALCbackend_Construct(STATIC_CAST(ALCbackend, self), device); -} - -static void ALCplaybackAlsa_Destruct(ALCplaybackAlsa *self) -{ - ALCbackend_Destruct(STATIC_CAST(ALCbackend, self)); -} static void ALCplaybackAlsa_Delete(ALCplaybackAlsa *self) { @@ -985,7 +978,9 @@ typedef struct ALCcaptureAlsa { snd_pcm_sframes_t last_avail; } ALCcaptureAlsa; +DECLARE_ALCBACKEND_VTABLE(ALCcaptureAlsa); +static DECLARE_FORWARD(ALCcaptureAlsa, ALCbackend, void, Destruct) static ALCenum ALCcaptureAlsa_open(ALCcaptureAlsa *self, const ALCchar *name); static void ALCcaptureAlsa_close(ALCcaptureAlsa *self); static ALCboolean ALCcaptureAlsa_reset(ALCcaptureAlsa *self); @@ -993,8 +988,16 @@ static ALCboolean ALCcaptureAlsa_start(ALCcaptureAlsa *self); static void ALCcaptureAlsa_stop(ALCcaptureAlsa *self); static ALCenum ALCcaptureAlsa_captureSamples(ALCcaptureAlsa *self, ALCvoid *buffer, ALCuint samples); static ALCuint ALCcaptureAlsa_availableSamples(ALCcaptureAlsa *self); -static void ALCcaptureAlsa_lock(ALCcaptureAlsa *self); -static void ALCcaptureAlsa_unlock(ALCcaptureAlsa *self); +static DECLARE_FORWARD(ALCcaptureAlsa, ALCbackend, void, lock) +static DECLARE_FORWARD(ALCcaptureAlsa, ALCbackend, void, unlock) + + +static void ALCcaptureAlsa_Construct(ALCcaptureAlsa *self, ALCdevice *device) +{ + ALCbackend_Construct(STATIC_CAST(ALCbackend, self), device); + SET_VTABLE2(ALCcaptureAlsa, ALCbackend, self); +} + static ALCenum ALCcaptureAlsa_open(ALCcaptureAlsa *self, const ALCchar *name) { @@ -1356,23 +1359,6 @@ static ALint64 ALCcaptureAlsa_getLatency(ALCcaptureAlsa *self) return maxi64((ALint64)delay*1000000000/device->Frequency, 0); } -static void ALCcaptureAlsa_lock(ALCcaptureAlsa *self) -{ ALCbackend_lock(STATIC_CAST(ALCbackend, self)); } - -static void ALCcaptureAlsa_unlock(ALCcaptureAlsa *self) -{ ALCbackend_unlock(STATIC_CAST(ALCbackend, self)); } - - -static void ALCcaptureAlsa_Construct(ALCcaptureAlsa *self, ALCdevice *device) -{ - ALCbackend_Construct(STATIC_CAST(ALCbackend, self), device); -} - -static void ALCcaptureAlsa_Destruct(ALCcaptureAlsa *self) -{ - ALCbackend_Destruct(STATIC_CAST(ALCbackend, self)); -} - static void ALCcaptureAlsa_Delete(ALCcaptureAlsa *self) { free(self); @@ -1474,7 +1460,6 @@ ALCbackend* ALCalsaBackendFactory_createBackend(ALCalsaBackendFactory* UNUSED(se backend = calloc(1, sizeof(*backend)); if(!backend) return NULL; - SET_VTABLE2(ALCplaybackAlsa, ALCbackend, backend); ALCplaybackAlsa_Construct(backend, device); @@ -1486,7 +1471,6 @@ ALCbackend* ALCalsaBackendFactory_createBackend(ALCalsaBackendFactory* UNUSED(se backend = calloc(1, sizeof(*backend)); if(!backend) return NULL; - SET_VTABLE2(ALCcaptureAlsa, ALCbackend, backend); ALCcaptureAlsa_Construct(backend, device); diff --git a/Alc/backends/loopback.c b/Alc/backends/loopback.c index bb5dd503..e400fcf2 100644 --- a/Alc/backends/loopback.c +++ b/Alc/backends/loopback.c @@ -33,7 +33,10 @@ typedef struct ALCloopback { } ALCloopback; DECLARE_ALCBACKEND_VTABLE(ALCloopback); -#define ALCNULLBACKEND_INITIALIZER { { GET_VTABLE2(ALCbackend, ALCloopback) } } +static DECLARE_FORWARD(ALCloopback, ALCbackend, void, Destruct) +static DECLARE_FORWARD(ALCloopback, ALCbackend, ALint64, getLatency) +static DECLARE_FORWARD(ALCloopback, ALCbackend, void, lock) +static DECLARE_FORWARD(ALCloopback, ALCbackend, void, unlock) static void ALCloopback_Construct(ALCloopback *self, ALCdevice *device) @@ -42,10 +45,6 @@ static void ALCloopback_Construct(ALCloopback *self, ALCdevice *device) SET_VTABLE2(ALCloopback, ALCbackend, self); } -static void ALCloopback_Destruct(ALCloopback *self) -{ - ALCbackend_Destruct(STATIC_CAST(ALCbackend, self)); -} static ALCenum ALCloopback_open(ALCloopback *self, const ALCchar *name) { @@ -84,14 +83,6 @@ ALCuint ALCloopback_availableSamples(ALCloopback* UNUSED(self)) return 0; } -static ALint64 ALCloopback_getLatency(ALCloopback *self) -{ return ALCbackend_getLatency(STATIC_CAST(ALCbackend, self)); } - -static void ALCloopback_lock(ALCloopback *self) -{ ALCbackend_lock(STATIC_CAST(ALCbackend, self)); } - -static void ALCloopback_unlock(ALCloopback *self) -{ ALCbackend_unlock(STATIC_CAST(ALCbackend, self)); } static void ALCloopback_Delete(ALCloopback *self) { diff --git a/Alc/backends/null.c b/Alc/backends/null.c index c5b178de..8eeb2689 100644 --- a/Alc/backends/null.c +++ b/Alc/backends/null.c @@ -39,11 +39,23 @@ typedef struct ALCnullBackend { volatile int killNow; althread_t thread; } ALCnullBackend; -#define ALCNULLBACKEND_INITIALIZER { { GET_VTABLE2(ALCbackend, ALCnullBackend) } } +DECLARE_ALCBACKEND_VTABLE(ALCnullBackend); +static DECLARE_FORWARD(ALCnullBackend, ALCbackend, void, Destruct) +static DECLARE_FORWARD(ALCnullBackend, ALCbackend, ALint64, getLatency) +static DECLARE_FORWARD(ALCnullBackend, ALCbackend, void, lock) +static DECLARE_FORWARD(ALCnullBackend, ALCbackend, void, unlock) static const ALCchar nullDevice[] = "No Output"; + +static void ALCnullBackend_Construct(ALCnullBackend *self, ALCdevice *device) +{ + ALCbackend_Construct(STATIC_CAST(ALCbackend, self), device); + SET_VTABLE2(ALCnullBackend, ALCbackend, self); +} + + static ALuint ALCnullBackend_mixerProc(ALvoid *ptr) { ALCnullBackend *self = (ALCnullBackend*)ptr; @@ -86,16 +98,6 @@ static ALuint ALCnullBackend_mixerProc(ALvoid *ptr) } -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) { ALCdevice *device; @@ -150,20 +152,6 @@ ALCuint ALCnullBackend_availableSamples(ALCnullBackend* UNUSED(self)) return 0; } -static ALint64 ALCnullBackend_getLatency(ALCnullBackend *self) -{ - return ALCbackend_getLatency(STATIC_CAST(ALCbackend, self)); -} - -static void ALCnullBackend_lock(ALCnullBackend *self) -{ - ALCbackend_lock(STATIC_CAST(ALCbackend, self)); -} - -static void ALCnullBackend_unlock(ALCnullBackend *self) -{ - ALCbackend_unlock(STATIC_CAST(ALCbackend, self)); -} static void ALCnullBackend_Delete(ALCnullBackend *self) { @@ -214,7 +202,6 @@ ALCbackend* ALCnullBackendFactory_createBackend(ALCnullBackendFactory* UNUSED(se backend = calloc(1, sizeof(*backend)); if(!backend) return NULL; - SET_VTABLE2(ALCnullBackend, ALCbackend, backend); ALCnullBackend_Construct(backend, device); diff --git a/OpenAL32/Include/alMain.h b/OpenAL32/Include/alMain.h index a8175ce7..81ed726b 100644 --- a/OpenAL32/Include/alMain.h +++ b/OpenAL32/Include/alMain.h @@ -102,6 +102,9 @@ static const union { #define SET_VTABLE1(T1, obj) ((obj)->vtbl = GET_VTABLE1(T1)) #define SET_VTABLE2(T1, T2, obj) (STATIC_CAST(T2, obj)->vtbl = GET_VTABLE2(T1, T2)) +#define DECLARE_FORWARD(T1, T2, rettype, func) \ +rettype T1##_##func(T1 *obj) \ +{ return T2##_##func(STATIC_CAST(T2, obj)); } /* Helper to extract an argument list for VCALL. Not used directly. */ #define EXTRACT_VCALL_ARGS(...) __VA_ARGS__)) -- cgit v1.2.3 From 9f0e49917d808b93e0c47ce4fa2cbf7050cfe65a Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Tue, 29 Oct 2013 15:07:13 -0700 Subject: Add default handlers for reset, captureSamples, and availableSamples --- Alc/backends/alsa.c | 23 +++++------------------ Alc/backends/base.c | 15 +++++++++++++++ Alc/backends/base.h | 3 +++ Alc/backends/null.c | 20 ++++++++++---------- Alc/backends/pulseaudio.c | 22 +++------------------- OpenAL32/Include/alMain.h | 4 ++++ 6 files changed, 40 insertions(+), 47 deletions(-) (limited to 'Alc/backends/null.c') diff --git a/Alc/backends/alsa.c b/Alc/backends/alsa.c index 586c1bf6..232a9a5c 100644 --- a/Alc/backends/alsa.c +++ b/Alc/backends/alsa.c @@ -456,14 +456,15 @@ DECLARE_ALCBACKEND_VTABLE(ALCplaybackAlsa); static ALuint ALCplaybackAlsa_mixerProc(ALvoid *ptr); static ALuint ALCplaybackAlsa_mixerNoMMapProc(ALvoid *ptr); +static void ALCplaybackAlsa_Construct(ALCplaybackAlsa *self, ALCdevice *device); static DECLARE_FORWARD(ALCplaybackAlsa, ALCbackend, void, Destruct) static ALCenum ALCplaybackAlsa_open(ALCplaybackAlsa *self, const ALCchar *name); static void ALCplaybackAlsa_close(ALCplaybackAlsa *self); static ALCboolean ALCplaybackAlsa_reset(ALCplaybackAlsa *self); static ALCboolean ALCplaybackAlsa_start(ALCplaybackAlsa *self); static void ALCplaybackAlsa_stop(ALCplaybackAlsa *self); -static ALCenum ALCplaybackAlsa_captureSamples(ALCplaybackAlsa *self, ALCvoid *buffer, ALCuint samples); -static ALCuint ALCplaybackAlsa_availableSamples(ALCplaybackAlsa *self); +static DECLARE_FORWARD2(ALCplaybackAlsa, ALCbackend, ALCenum, captureSamples, void*, ALCuint) +static DECLARE_FORWARD(ALCplaybackAlsa, ALCbackend, ALCuint, availableSamples) static DECLARE_FORWARD(ALCplaybackAlsa, ALCbackend, void, lock) static DECLARE_FORWARD(ALCplaybackAlsa, ALCbackend, void, unlock) @@ -932,16 +933,6 @@ static void ALCplaybackAlsa_stop(ALCplaybackAlsa *self) self->buffer = NULL; } -static ALCenum ALCplaybackAlsa_captureSamples(ALCplaybackAlsa* UNUSED(self), ALCvoid* UNUSED(buffer), ALCuint UNUSED(samples)) -{ - return ALC_INVALID_DEVICE; -} - -static ALCuint ALCplaybackAlsa_availableSamples(ALCplaybackAlsa* UNUSED(self)) -{ - return 0; -} - static ALint64 ALCplaybackAlsa_getLatency(ALCplaybackAlsa *self) { ALCdevice *device = STATIC_CAST(ALCbackend, self)->mDevice; @@ -980,10 +971,11 @@ typedef struct ALCcaptureAlsa { } ALCcaptureAlsa; DECLARE_ALCBACKEND_VTABLE(ALCcaptureAlsa); +static void ALCcaptureAlsa_Construct(ALCcaptureAlsa *self, ALCdevice *device); static DECLARE_FORWARD(ALCcaptureAlsa, ALCbackend, void, Destruct) static ALCenum ALCcaptureAlsa_open(ALCcaptureAlsa *self, const ALCchar *name); static void ALCcaptureAlsa_close(ALCcaptureAlsa *self); -static ALCboolean ALCcaptureAlsa_reset(ALCcaptureAlsa *self); +static DECLARE_FORWARD(ALCcaptureAlsa, ALCbackend, ALCboolean, reset) static ALCboolean ALCcaptureAlsa_start(ALCcaptureAlsa *self); static void ALCcaptureAlsa_stop(ALCcaptureAlsa *self); static ALCenum ALCcaptureAlsa_captureSamples(ALCcaptureAlsa *self, ALCvoid *buffer, ALCuint samples); @@ -1150,11 +1142,6 @@ static void ALCcaptureAlsa_close(ALCcaptureAlsa *self) self->buffer = NULL; } -static ALCboolean ALCcaptureAlsa_reset(ALCcaptureAlsa* UNUSED(self)) -{ - return ALC_FALSE; -} - static ALCboolean ALCcaptureAlsa_start(ALCcaptureAlsa *self) { int err = snd_pcm_start(self->pcmHandle); diff --git a/Alc/backends/base.c b/Alc/backends/base.c index cb999f87..2f3ff924 100644 --- a/Alc/backends/base.c +++ b/Alc/backends/base.c @@ -20,6 +20,21 @@ void ALCbackend_Destruct(ALCbackend *self) DeleteCriticalSection(&self->mMutex); } +ALCboolean ALCbackend_reset(ALCbackend* UNUSED(self)) +{ + return ALC_FALSE; +} + +ALCenum ALCbackend_captureSamples(ALCbackend* UNUSED(self), void* UNUSED(buffer), ALCuint UNUSED(samples)) +{ + return ALC_INVALID_DEVICE; +} + +ALCuint ALCbackend_availableSamples(ALCbackend* UNUSED(self)) +{ + return 0; +} + ALint64 ALCbackend_getLatency(ALCbackend* UNUSED(self)) { return 0; diff --git a/Alc/backends/base.h b/Alc/backends/base.h index 8dd896d8..285d1ac9 100644 --- a/Alc/backends/base.h +++ b/Alc/backends/base.h @@ -17,6 +17,9 @@ typedef struct ALCbackend { void ALCbackend_Construct(ALCbackend *self, ALCdevice *device); void ALCbackend_Destruct(ALCbackend *self); +ALCboolean ALCbackend_reset(ALCbackend *self); +ALCenum ALCbackend_captureSamples(ALCbackend *self, void *buffer, ALCuint samples); +ALCuint ALCbackend_availableSamples(ALCbackend *self); ALint64 ALCbackend_getLatency(ALCbackend *self); void ALCbackend_lock(ALCbackend *self); void ALCbackend_unlock(ALCbackend *self); diff --git a/Alc/backends/null.c b/Alc/backends/null.c index 8eeb2689..6068d990 100644 --- a/Alc/backends/null.c +++ b/Alc/backends/null.c @@ -41,7 +41,17 @@ typedef struct ALCnullBackend { } ALCnullBackend; DECLARE_ALCBACKEND_VTABLE(ALCnullBackend); +static ALuint ALCnullBackend_mixerProc(ALvoid *ptr); + +static void ALCnullBackend_Construct(ALCnullBackend *self, ALCdevice *device); static DECLARE_FORWARD(ALCnullBackend, ALCbackend, void, Destruct) +static ALCenum ALCnullBackend_open(ALCnullBackend *self, const ALCchar *name); +static void ALCnullBackend_close(ALCnullBackend *self); +static ALCboolean ALCnullBackend_reset(ALCnullBackend *self); +static ALCboolean ALCnullBackend_start(ALCnullBackend *self); +static void ALCnullBackend_stop(ALCnullBackend *self); +static DECLARE_FORWARD2(ALCnullBackend, ALCbackend, ALCenum, captureSamples, void*, ALCuint) +static DECLARE_FORWARD(ALCnullBackend, ALCbackend, ALCuint, availableSamples) static DECLARE_FORWARD(ALCnullBackend, ALCbackend, ALint64, getLatency) static DECLARE_FORWARD(ALCnullBackend, ALCbackend, void, lock) static DECLARE_FORWARD(ALCnullBackend, ALCbackend, void, unlock) @@ -142,16 +152,6 @@ static void ALCnullBackend_stop(ALCnullBackend *self) self->killNow = 0; } -ALCenum ALCnullBackend_captureSamples(ALCnullBackend* UNUSED(self), void* UNUSED(buffer), ALCuint UNUSED(samples)) -{ - return ALC_INVALID_VALUE; -} - -ALCuint ALCnullBackend_availableSamples(ALCnullBackend* UNUSED(self)) -{ - return 0; -} - static void ALCnullBackend_Delete(ALCnullBackend *self) { diff --git a/Alc/backends/pulseaudio.c b/Alc/backends/pulseaudio.c index 1d354462..fcb29e16 100644 --- a/Alc/backends/pulseaudio.c +++ b/Alc/backends/pulseaudio.c @@ -508,8 +508,8 @@ static void ALCpulsePlayback_close(ALCpulsePlayback *self); static ALCboolean ALCpulsePlayback_reset(ALCpulsePlayback *self); static ALCboolean ALCpulsePlayback_start(ALCpulsePlayback *self); static void ALCpulsePlayback_stop(ALCpulsePlayback *self); -static ALCenum ALCpulsePlayback_captureSamples(ALCpulsePlayback *self, ALCvoid *buffer, ALCuint samples); -static ALCuint ALCpulsePlayback_availableSamples(ALCpulsePlayback *self); +static DECLARE_FORWARD2(ALCpulsePlayback, ALCbackend, ALCenum, captureSamples, ALCvoid*, ALCuint) +static DECLARE_FORWARD(ALCpulsePlayback, ALCbackend, ALCuint, availableSamples) static void ALCpulsePlayback_lock(ALCpulsePlayback *self); static void ALCpulsePlayback_unlock(ALCpulsePlayback *self); @@ -1083,17 +1083,6 @@ static void ALCpulsePlayback_stop(ALCpulsePlayback *self) } -static ALCenum ALCpulsePlayback_captureSamples(ALCpulsePlayback* UNUSED(self), ALCvoid* UNUSED(buffer), ALCuint UNUSED(samples)) -{ - return ALC_INVALID_DEVICE; -} - -static ALCuint ALCpulsePlayback_availableSamples(ALCpulsePlayback* UNUSED(self)) -{ - return 0; -} - - static void ALCpulsePlayback_lock(ALCpulsePlayback *self) { pa_threaded_mainloop_lock(self->loop); @@ -1166,7 +1155,7 @@ static void ALCpulseCapture_Construct(ALCpulseCapture *self, ALCdevice *device); static DECLARE_FORWARD(ALCpulseCapture, ALCbackend, void, Destruct) static ALCenum ALCpulseCapture_open(ALCpulseCapture *self, const ALCchar *name); static void ALCpulseCapture_close(ALCpulseCapture *self); -static ALCboolean ALCpulseCapture_reset(ALCpulseCapture *self); +static DECLARE_FORWARD(ALCpulseCapture, ALCbackend, ALCboolean, reset) static ALCboolean ALCpulseCapture_start(ALCpulseCapture *self); static void ALCpulseCapture_stop(ALCpulseCapture *self); static ALCenum ALCpulseCapture_captureSamples(ALCpulseCapture *self, ALCvoid *buffer, ALCuint samples); @@ -1481,11 +1470,6 @@ static void ALCpulseCapture_close(ALCpulseCapture *self) self->device_name = NULL; } -static ALCboolean ALCpulseCapture_reset(ALCpulseCapture* UNUSED(self)) -{ - return ALC_FALSE; -} - static ALCboolean ALCpulseCapture_start(ALCpulseCapture *self) { pa_operation *o; diff --git a/OpenAL32/Include/alMain.h b/OpenAL32/Include/alMain.h index 0f31960f..370c20af 100644 --- a/OpenAL32/Include/alMain.h +++ b/OpenAL32/Include/alMain.h @@ -106,6 +106,10 @@ static const union { rettype T1##_##func(T1 *obj) \ { return T2##_##func(STATIC_CAST(T2, obj)); } +#define DECLARE_FORWARD2(T1, T2, rettype, func, argtype1, argtype2) \ +rettype T1##_##func(T1 *obj, argtype1 a, argtype2 b) \ +{ return T2##_##func(STATIC_CAST(T2, obj), a, b); } + /* Helper to extract an argument list for VCALL. Not used directly. */ #define EXTRACT_VCALL_ARGS(...) __VA_ARGS__)) -- cgit v1.2.3 From 3d921e0e6f2d97d49e0589d69054ffc8f1d1e3ab Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Sat, 2 Nov 2013 16:35:05 -0700 Subject: Make backend factory methods static as needed --- Alc/backends/alsa.c | 10 +++++----- Alc/backends/null.c | 34 +++++++++++++++++++--------------- Alc/backends/oss.c | 10 +++++----- Alc/backends/pulseaudio.c | 20 ++++++++++---------- 4 files changed, 39 insertions(+), 35 deletions(-) (limited to 'Alc/backends/null.c') diff --git a/Alc/backends/alsa.c b/Alc/backends/alsa.c index 232a9a5c..7e9e5e79 100644 --- a/Alc/backends/alsa.c +++ b/Alc/backends/alsa.c @@ -1360,14 +1360,14 @@ typedef struct ALCalsaBackendFactory { } ALCalsaBackendFactory; #define ALCALSABACKENDFACTORY_INITIALIZER { { GET_VTABLE2(ALCalsaBackendFactory, ALCbackendFactory) } } -ALCboolean ALCalsaBackendFactory_init(ALCalsaBackendFactory* UNUSED(self)) +static ALCboolean ALCalsaBackendFactory_init(ALCalsaBackendFactory* UNUSED(self)) { if(!alsa_load()) return ALC_FALSE; return ALC_TRUE; } -void ALCalsaBackendFactory_deinit(ALCalsaBackendFactory* UNUSED(self)) +static void ALCalsaBackendFactory_deinit(ALCalsaBackendFactory* UNUSED(self)) { ALuint i; @@ -1396,14 +1396,14 @@ void ALCalsaBackendFactory_deinit(ALCalsaBackendFactory* UNUSED(self)) #endif } -ALCboolean ALCalsaBackendFactory_querySupport(ALCalsaBackendFactory* UNUSED(self), ALCbackend_Type type) +static ALCboolean ALCalsaBackendFactory_querySupport(ALCalsaBackendFactory* UNUSED(self), ALCbackend_Type type) { if(type == ALCbackend_Playback || type == ALCbackend_Capture) return ALC_TRUE; return ALC_FALSE; } -void ALCalsaBackendFactory_probe(ALCalsaBackendFactory* UNUSED(self), enum DevProbe type) +static void ALCalsaBackendFactory_probe(ALCalsaBackendFactory* UNUSED(self), enum DevProbe type) { ALuint i; @@ -1439,7 +1439,7 @@ void ALCalsaBackendFactory_probe(ALCalsaBackendFactory* UNUSED(self), enum DevPr } } -ALCbackend* ALCalsaBackendFactory_createBackend(ALCalsaBackendFactory* UNUSED(self), ALCdevice *device, ALCbackend_Type type) +static ALCbackend* ALCalsaBackendFactory_createBackend(ALCalsaBackendFactory* UNUSED(self), ALCdevice *device, ALCbackend_Type type) { if(type == ALCbackend_Playback) { diff --git a/Alc/backends/null.c b/Alc/backends/null.c index 6068d990..a7056369 100644 --- a/Alc/backends/null.c +++ b/Alc/backends/null.c @@ -166,23 +166,36 @@ typedef struct ALCnullBackendFactory { } ALCnullBackendFactory; #define ALCNULLBACKENDFACTORY_INITIALIZER { { GET_VTABLE2(ALCnullBackendFactory, ALCbackendFactory) } } -ALCboolean ALCnullBackendFactory_init(ALCnullBackendFactory* UNUSED(self)) +ALCbackendFactory *ALCnullBackendFactory_getFactory(void); + +static ALCboolean ALCnullBackendFactory_init(ALCnullBackendFactory *self); +static DECLARE_FORWARD(ALCnullBackendFactory, ALCbackendFactory, void, deinit) +static ALCboolean ALCnullBackendFactory_querySupport(ALCnullBackendFactory *self, ALCbackend_Type type); +static void ALCnullBackendFactory_probe(ALCnullBackendFactory *self, enum DevProbe type); +static ALCbackend* ALCnullBackendFactory_createBackend(ALCnullBackendFactory *self, ALCdevice *device, ALCbackend_Type type); +DEFINE_ALCBACKENDFACTORY_VTABLE(ALCnullBackendFactory); + + +ALCbackendFactory *ALCnullBackendFactory_getFactory(void) { - return ALC_TRUE; + static ALCnullBackendFactory factory = ALCNULLBACKENDFACTORY_INITIALIZER; + return STATIC_CAST(ALCbackendFactory, &factory); } -void ALCnullBackendFactory_deinit(ALCnullBackendFactory* UNUSED(self)) + +static ALCboolean ALCnullBackendFactory_init(ALCnullBackendFactory* UNUSED(self)) { + return ALC_TRUE; } -ALCboolean ALCnullBackendFactory_querySupport(ALCnullBackendFactory* UNUSED(self), ALCbackend_Type type) +static ALCboolean ALCnullBackendFactory_querySupport(ALCnullBackendFactory* UNUSED(self), ALCbackend_Type type) { if(type == ALCbackend_Playback) return ALC_TRUE; return ALC_FALSE; } -void ALCnullBackendFactory_probe(ALCnullBackendFactory* UNUSED(self), enum DevProbe type) +static void ALCnullBackendFactory_probe(ALCnullBackendFactory* UNUSED(self), enum DevProbe type) { switch(type) { @@ -194,7 +207,7 @@ void ALCnullBackendFactory_probe(ALCnullBackendFactory* UNUSED(self), enum DevPr } } -ALCbackend* ALCnullBackendFactory_createBackend(ALCnullBackendFactory* UNUSED(self), ALCdevice *device, ALCbackend_Type type) +static ALCbackend* ALCnullBackendFactory_createBackend(ALCnullBackendFactory* UNUSED(self), ALCdevice *device, ALCbackend_Type type) { ALCnullBackend *backend; @@ -207,12 +220,3 @@ ALCbackend* ALCnullBackendFactory_createBackend(ALCnullBackendFactory* UNUSED(se return STATIC_CAST(ALCbackend, backend); } - -DEFINE_ALCBACKENDFACTORY_VTABLE(ALCnullBackendFactory); - - -ALCbackendFactory *ALCnullBackendFactory_getFactory(void) -{ - static ALCnullBackendFactory factory = ALCNULLBACKENDFACTORY_INITIALIZER; - return STATIC_CAST(ALCbackendFactory, &factory); -} diff --git a/Alc/backends/oss.c b/Alc/backends/oss.c index 3d7de113..c79793c2 100644 --- a/Alc/backends/oss.c +++ b/Alc/backends/oss.c @@ -553,11 +553,11 @@ typedef struct ALCossBackendFactory { ALCbackendFactory *ALCossBackendFactory_getFactory(void); -ALCboolean ALCossBackendFactory_init(ALCossBackendFactory *self); -DECLARE_FORWARD(ALCossBackendFactory, ALCbackendFactory, void, deinit) -ALCboolean ALCossBackendFactory_querySupport(ALCossBackendFactory *self, ALCbackend_Type type); -void ALCossBackendFactory_probe(ALCossBackendFactory *self, enum DevProbe type); -ALCbackend* ALCossBackendFactory_createBackend(ALCossBackendFactory *self, ALCdevice *device, ALCbackend_Type type); +static ALCboolean ALCossBackendFactory_init(ALCossBackendFactory *self); +static DECLARE_FORWARD(ALCossBackendFactory, ALCbackendFactory, void, deinit) +static ALCboolean ALCossBackendFactory_querySupport(ALCossBackendFactory *self, ALCbackend_Type type); +static void ALCossBackendFactory_probe(ALCossBackendFactory *self, enum DevProbe type); +static ALCbackend* ALCossBackendFactory_createBackend(ALCossBackendFactory *self, ALCdevice *device, ALCbackend_Type type); DEFINE_ALCBACKENDFACTORY_VTABLE(ALCossBackendFactory); diff --git a/Alc/backends/pulseaudio.c b/Alc/backends/pulseaudio.c index 54265df3..e2ae52ae 100644 --- a/Alc/backends/pulseaudio.c +++ b/Alc/backends/pulseaudio.c @@ -1602,7 +1602,7 @@ typedef struct ALCpulseBackendFactory { } ALCpulseBackendFactory; #define ALCPULSEBACKENDFACTORY_INITIALIZER { { GET_VTABLE2(ALCpulseBackendFactory, ALCbackendFactory) } } -ALCboolean ALCpulseBackendFactory_init(ALCpulseBackendFactory* UNUSED(self)) +static ALCboolean ALCpulseBackendFactory_init(ALCpulseBackendFactory* UNUSED(self)) { ALCboolean ret = ALC_FALSE; @@ -1646,7 +1646,7 @@ ALCboolean ALCpulseBackendFactory_init(ALCpulseBackendFactory* UNUSED(self)) return ret; } -void ALCpulseBackendFactory_deinit(ALCpulseBackendFactory* UNUSED(self)) +static void ALCpulseBackendFactory_deinit(ALCpulseBackendFactory* UNUSED(self)) { ALuint i; @@ -1675,14 +1675,14 @@ void ALCpulseBackendFactory_deinit(ALCpulseBackendFactory* UNUSED(self)) /* PulseAudio doesn't like being CloseLib'd sometimes */ } -ALCboolean ALCpulseBackendFactory_querySupport(ALCpulseBackendFactory* UNUSED(self), ALCbackend_Type type) +static ALCboolean ALCpulseBackendFactory_querySupport(ALCpulseBackendFactory* UNUSED(self), ALCbackend_Type type) { if(type == ALCbackend_Playback || type == ALCbackend_Capture) return ALC_TRUE; return ALC_FALSE; } -void ALCpulseBackendFactory_probe(ALCpulseBackendFactory* UNUSED(self), enum DevProbe type) +static void ALCpulseBackendFactory_probe(ALCpulseBackendFactory* UNUSED(self), enum DevProbe type) { ALuint i; @@ -1722,7 +1722,7 @@ void ALCpulseBackendFactory_probe(ALCpulseBackendFactory* UNUSED(self), enum Dev } } -ALCbackend* ALCpulseBackendFactory_createBackend(ALCpulseBackendFactory* UNUSED(self), ALCdevice *device, ALCbackend_Type type) +static ALCbackend* ALCpulseBackendFactory_createBackend(ALCpulseBackendFactory* UNUSED(self), ALCdevice *device, ALCbackend_Type type) { if(type == ALCbackend_Playback) { @@ -1762,25 +1762,25 @@ typedef struct ALCpulseBackendFactory { } ALCpulseBackendFactory; #define ALCPULSEBACKENDFACTORY_INITIALIZER { { GET_VTABLE2(ALCpulseBackendFactory, ALCbackendFactory) } } -ALCboolean ALCpulseBackendFactory_init(ALCpulseBackendFactory* UNUSED(self)) +static ALCboolean ALCpulseBackendFactory_init(ALCpulseBackendFactory* UNUSED(self)) { return ALC_FALSE; } -void ALCpulseBackendFactory_deinit(ALCpulseBackendFactory* UNUSED(self)) +static void ALCpulseBackendFactory_deinit(ALCpulseBackendFactory* UNUSED(self)) { } -ALCboolean ALCpulseBackendFactory_querySupport(ALCpulseBackendFactory* UNUSED(self), ALCbackend_Type UNUSED(type)) +static ALCboolean ALCpulseBackendFactory_querySupport(ALCpulseBackendFactory* UNUSED(self), ALCbackend_Type UNUSED(type)) { return ALC_FALSE; } -void ALCpulseBackendFactory_probe(ALCpulseBackendFactory* UNUSED(self), enum DevProbe UNUSED(type)) +static void ALCpulseBackendFactory_probe(ALCpulseBackendFactory* UNUSED(self), enum DevProbe UNUSED(type)) { } -ALCbackend* ALCpulseBackendFactory_createBackend(ALCpulseBackendFactory* UNUSED(self), ALCdevice* UNUSED(device), ALCbackend_Type UNUSED(type)) +static ALCbackend* ALCpulseBackendFactory_createBackend(ALCpulseBackendFactory* UNUSED(self), ALCdevice* UNUSED(device), ALCbackend_Type UNUSED(type)) { return NULL; } -- cgit v1.2.3