Prevent possible buffer overflow in AL_PRINT
[openal-soft.git] / OpenAL32 / Include / alMain.h
blob1f62b53552b67c1761287f3b984e4609efe1db77
1 #ifndef AL_MAIN_H
2 #define AL_MAIN_H
4 #define AL_MAX_CHANNELS 4
5 #define AL_MAX_SOURCES 32
7 #include <string.h>
9 #include "alu.h"
11 #ifdef _WIN32
12 #include <windows.h>
13 //#define strcasecmp _stricmp
15 #else
17 #include <assert.h>
18 #include <pthread.h>
20 #define IsBadWritePtr(a,b) (0)
22 typedef pthread_mutex_t CRITICAL_SECTION;
23 static inline void EnterCriticalSection(CRITICAL_SECTION *cs)
25 int ret;
26 ret = pthread_mutex_lock(cs);
27 assert(ret == 0);
29 static inline void LeaveCriticalSection(CRITICAL_SECTION *cs)
31 int ret;
32 ret = pthread_mutex_unlock(cs);
33 assert(ret == 0);
35 static inline void InitializeCriticalSection(CRITICAL_SECTION *cs)
37 pthread_mutexattr_t attrib;
38 int ret;
40 ret = pthread_mutexattr_init(&attrib);
41 assert(ret == 0);
43 ret = pthread_mutexattr_settype(&attrib, PTHREAD_MUTEX_RECURSIVE);
44 assert(ret == 0);
45 ret = pthread_mutex_init(cs, &attrib);
46 assert(ret == 0);
48 pthread_mutexattr_destroy(&attrib);
51 static inline void DeleteCriticalSection(CRITICAL_SECTION *cs)
53 int ret;
54 ret = pthread_mutex_destroy(cs);
55 assert(ret == 0);
58 #define min(x,y) (((x)<(y))?(x):(y))
59 #define max(x,y) (((x)>(y))?(x):(y))
60 #endif
62 #include "alBuffer.h"
63 #include "alError.h"
64 #include "alExtension.h"
65 #include "alListener.h"
66 #include "alSource.h"
67 #include "alState.h"
68 #include "alThunk.h"
70 #ifdef __cplusplus
71 extern "C"
73 #endif
75 extern CRITICAL_SECTION _alMutex;
77 extern char _alDebug[256];
79 #define AL_PRINT(...) do { \
80 int _al_print_i; \
81 char *_al_print_fn = strrchr(__FILE__, '/'); \
82 if(!_al_print_fn) _al_print_fn = __FILE__; \
83 else _al_print_fn += 1; \
84 _al_print_i = snprintf(_alDebug, sizeof(_alDebug), "AL lib: %s:%d: ", _al_print_fn, __LINE__); \
85 if(_al_print_i < (int)sizeof(_alDebug) && _al_print_i > 0) \
86 snprintf(_alDebug+_al_print_i, sizeof(_alDebug)-_al_print_i, __VA_ARGS__); \
87 _alDebug[sizeof(_alDebug)-1] = 0; \
88 fprintf(stderr, "%s", _alDebug); \
89 } while(0)
92 #define AL_FORMAT_MONO_IMA4 0x1300
93 #define AL_FORMAT_STEREO_IMA4 0x1301
94 // These are from AL_EXT_MCFORMATS, which we don't support yet but the mixer
95 // can use 4-channel formats
96 #define AL_FORMAT_QUAD8 0x1204
97 #define AL_FORMAT_QUAD16 0x1205
99 #define SWMIXER_OUTPUT_RATE 44100
100 //#define OUTPUT_BUFFER_SIZE (32768*SWMIXER_OUTPUT_RATE/22050)
102 #define SPEEDOFSOUNDMETRESPERSEC (343.3f)
104 typedef struct {
105 ALCboolean (*OpenPlayback)(ALCdevice*, const ALCchar*);
106 void (*ClosePlayback)(ALCdevice*);
108 ALCboolean (*OpenCapture)(ALCdevice*, const ALCchar*, ALCuint, ALCenum, ALCsizei);
109 void (*CloseCapture)(ALCdevice*);
110 void (*StartCapture)(ALCdevice*);
111 void (*StopCapture)(ALCdevice*);
112 void (*CaptureSamples)(ALCdevice*, void*, ALCuint);
113 ALCuint (*AvailableSamples)(ALCdevice*);
114 } BackendFuncs;
116 void alc_alsa_init(BackendFuncs *func_list);
117 void alc_oss_init(BackendFuncs *func_list);
118 void alcDSoundInit(BackendFuncs *func_list);
119 void alcWinMMInit(BackendFuncs *FuncList);
122 struct ALCdevice_struct
124 ALboolean InUse;
125 ALboolean IsCaptureDevice;
127 ALuint Frequency;
128 ALuint UpdateFreq;
129 ALuint FrameSize;
130 ALuint Channels;
131 ALenum Format;
133 ALCchar *szDeviceName;
135 // Maximum number of sources that can be created
136 ALuint MaxNoOfSources;
138 // Context created on this device
139 ALCcontext *Context;
141 BackendFuncs *Funcs;
142 void *ExtraData; // For the backend's use
145 #define ALCdevice_OpenPlayback(a,b) ((a)->Funcs->OpenPlayback((a), (b)))
146 #define ALCdevice_ClosePlayback(a) ((a)->Funcs->ClosePlayback((a)))
147 #define ALCdevice_OpenCapture(a,b,c,d,e) ((a)->Funcs->OpenCapture((a), (b), (c), (d), (e)))
148 #define ALCdevice_CloseCapture(a) ((a)->Funcs->CloseCapture((a)))
149 #define ALCdevice_StartCapture(a) ((a)->Funcs->StartCapture((a)))
150 #define ALCdevice_StopCapture(a) ((a)->Funcs->StopCapture((a)))
151 #define ALCdevice_CaptureSamples(a,b,c) ((a)->Funcs->CaptureSamples((a), (b), (c)))
152 #define ALCdevice_AvailableSamples(a) ((a)->Funcs->AvailableSamples((a)))
154 struct ALCcontext_struct
156 ALlistener Listener;
158 ALsource *Source;
159 ALuint SourceCount;
161 ALenum LastError;
162 ALboolean InUse;
164 ALuint Frequency;
166 ALenum DistanceModel;
168 ALfloat DopplerFactor;
169 ALfloat DopplerVelocity;
170 ALfloat flSpeedOfSound;
172 ALint lNumMonoSources;
173 ALint lNumStereoSources;
175 ALCdevice *Device;
176 ALCchar ExtensionList[1024];
178 ALCcontext *next;
181 ALCchar *AppendDeviceList(char *name);
182 ALCchar *AppendAllDeviceList(char *name);
183 ALCchar *AppendCaptureDeviceList(char *name);
185 ALCvoid SetALCError(ALenum errorCode);
187 ALCvoid SuspendContext(ALCcontext *context);
188 ALCvoid ProcessContext(ALCcontext *context);
190 ALvoid *StartThread(ALuint (*func)(ALvoid*), ALvoid *ptr);
191 ALuint StopThread(ALvoid *thread);
193 typedef struct RingBuffer RingBuffer;
194 RingBuffer *CreateRingBuffer(ALsizei frame_size, ALsizei length);
195 void DestroyRingBuffer(RingBuffer *ring);
196 ALsizei RingBufferSize(RingBuffer *ring);
197 void WriteRingBuffer(RingBuffer *ring, const ALubyte *data, ALsizei len);
198 void ReadRingBuffer(RingBuffer *ring, ALubyte *data, ALsizei len);
200 void ReadALConfig(void);
201 void FreeALConfig(void);
202 const char *GetConfigValue(const char *blockName, const char *keyName, const char *def);
203 int GetConfigValueInt(const char *blockName, const char *keyName, int def);
204 float GetConfigValueFloat(const char *blockName, const char *keyName, float def);
206 #ifdef __cplusplus
208 #endif
210 #endif