2 * Copyright 2009 Maarten Lankhorst
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20 #include "wine/port.h"
27 #elif defined(HAVE_OPENAL_AL_H)
28 #include <OpenAL/al.h>
29 #include <OpenAL/alc.h>
36 #include "wine/library.h"
42 #include "propkeydef.h"
43 #include "mmdeviceapi.h"
46 #include "audioclient.h"
47 #include "endpointvolume.h"
48 #include "audiopolicy.h"
52 #include "wine/debug.h"
54 WINE_DEFAULT_DEBUG_CHANNEL(mmdevapi);
60 static CRITICAL_SECTION_DEBUG openal_crst_debug =
63 { &openal_crst_debug.ProcessLocksList,
64 &openal_crst_debug.ProcessLocksList },
65 0, 0, { (DWORD_PTR)(__FILE__ ": openal_crst_debug") }
67 CRITICAL_SECTION openal_crst = { &openal_crst_debug, -1, 0, 0, 0, 0 };
69 static void *openal_handle = RTLD_DEFAULT;
71 #ifdef SONAME_LIBOPENAL
72 LPALCCREATECONTEXT palcCreateContext = NULL;
73 LPALCMAKECONTEXTCURRENT palcMakeContextCurrent = NULL;
74 LPALCPROCESSCONTEXT palcProcessContext = NULL;
75 LPALCSUSPENDCONTEXT palcSuspendContext = NULL;
76 LPALCDESTROYCONTEXT palcDestroyContext = NULL;
77 LPALCGETCURRENTCONTEXT palcGetCurrentContext = NULL;
78 LPALCGETCONTEXTSDEVICE palcGetContextsDevice = NULL;
79 LPALCOPENDEVICE palcOpenDevice = NULL;
80 LPALCCLOSEDEVICE palcCloseDevice = NULL;
81 LPALCGETERROR palcGetError = NULL;
82 LPALCISEXTENSIONPRESENT palcIsExtensionPresent = NULL;
83 LPALCGETPROCADDRESS palcGetProcAddress = NULL;
84 LPALCGETENUMVALUE palcGetEnumValue = NULL;
85 LPALCGETSTRING palcGetString = NULL;
86 LPALCGETINTEGERV palcGetIntegerv = NULL;
87 LPALCCAPTUREOPENDEVICE palcCaptureOpenDevice = NULL;
88 LPALCCAPTURECLOSEDEVICE palcCaptureCloseDevice = NULL;
89 LPALCCAPTURESTART palcCaptureStart = NULL;
90 LPALCCAPTURESTOP palcCaptureStop = NULL;
91 LPALCCAPTURESAMPLES palcCaptureSamples = NULL;
92 LPALENABLE palEnable = NULL;
93 LPALDISABLE palDisable = NULL;
94 LPALISENABLED palIsEnabled = NULL;
95 LPALGETSTRING palGetString = NULL;
96 LPALGETBOOLEANV palGetBooleanv = NULL;
97 LPALGETINTEGERV palGetIntegerv = NULL;
98 LPALGETFLOATV palGetFloatv = NULL;
99 LPALGETDOUBLEV palGetDoublev = NULL;
100 LPALGETBOOLEAN palGetBoolean = NULL;
101 LPALGETINTEGER palGetInteger = NULL;
102 LPALGETFLOAT palGetFloat = NULL;
103 LPALGETDOUBLE palGetDouble = NULL;
104 LPALGETERROR palGetError = NULL;
105 LPALISEXTENSIONPRESENT palIsExtensionPresent = NULL;
106 LPALGETPROCADDRESS palGetProcAddress = NULL;
107 LPALGETENUMVALUE palGetEnumValue = NULL;
108 LPALLISTENERF palListenerf = NULL;
109 LPALLISTENER3F palListener3f = NULL;
110 LPALLISTENERFV palListenerfv = NULL;
111 LPALLISTENERI palListeneri = NULL;
112 LPALLISTENER3I palListener3i = NULL;
113 LPALLISTENERIV palListeneriv = NULL;
114 LPALGETLISTENERF palGetListenerf = NULL;
115 LPALGETLISTENER3F palGetListener3f = NULL;
116 LPALGETLISTENERFV palGetListenerfv = NULL;
117 LPALGETLISTENERI palGetListeneri = NULL;
118 LPALGETLISTENER3I palGetListener3i = NULL;
119 LPALGETLISTENERIV palGetListeneriv = NULL;
120 LPALGENSOURCES palGenSources = NULL;
121 LPALDELETESOURCES palDeleteSources = NULL;
122 LPALISSOURCE palIsSource = NULL;
123 LPALSOURCEF palSourcef = NULL;
124 LPALSOURCE3F palSource3f = NULL;
125 LPALSOURCEFV palSourcefv = NULL;
126 LPALSOURCEI palSourcei = NULL;
127 LPALSOURCE3I palSource3i = NULL;
128 LPALSOURCEIV palSourceiv = NULL;
129 LPALGETSOURCEF palGetSourcef = NULL;
130 LPALGETSOURCE3F palGetSource3f = NULL;
131 LPALGETSOURCEFV palGetSourcefv = NULL;
132 LPALGETSOURCEI palGetSourcei = NULL;
133 LPALGETSOURCE3I palGetSource3i = NULL;
134 LPALGETSOURCEIV palGetSourceiv = NULL;
135 LPALSOURCEPLAYV palSourcePlayv = NULL;
136 LPALSOURCESTOPV palSourceStopv = NULL;
137 LPALSOURCEREWINDV palSourceRewindv = NULL;
138 LPALSOURCEPAUSEV palSourcePausev = NULL;
139 LPALSOURCEPLAY palSourcePlay = NULL;
140 LPALSOURCESTOP palSourceStop = NULL;
141 LPALSOURCEREWIND palSourceRewind = NULL;
142 LPALSOURCEPAUSE palSourcePause = NULL;
143 LPALSOURCEQUEUEBUFFERS palSourceQueueBuffers = NULL;
144 LPALSOURCEUNQUEUEBUFFERS palSourceUnqueueBuffers = NULL;
145 LPALGENBUFFERS palGenBuffers = NULL;
146 LPALDELETEBUFFERS palDeleteBuffers = NULL;
147 LPALISBUFFER palIsBuffer = NULL;
148 LPALBUFFERF palBufferf = NULL;
149 LPALBUFFER3F palBuffer3f = NULL;
150 LPALBUFFERFV palBufferfv = NULL;
151 LPALBUFFERI palBufferi = NULL;
152 LPALBUFFER3I palBuffer3i = NULL;
153 LPALBUFFERIV palBufferiv = NULL;
154 LPALGETBUFFERF palGetBufferf = NULL;
155 LPALGETBUFFER3F palGetBuffer3f = NULL;
156 LPALGETBUFFERFV palGetBufferfv = NULL;
157 LPALGETBUFFERI palGetBufferi = NULL;
158 LPALGETBUFFER3I palGetBuffer3i = NULL;
159 LPALGETBUFFERIV palGetBufferiv = NULL;
160 LPALBUFFERDATA palBufferData = NULL;
161 LPALDOPPLERFACTOR palDopplerFactor = NULL;
162 LPALDOPPLERVELOCITY palDopplerVelocity = NULL;
163 LPALDISTANCEMODEL palDistanceModel = NULL;
164 LPALSPEEDOFSOUND palSpeedOfSound = NULL;
167 typeof(alcGetCurrentContext) *get_context;
168 typeof(alcMakeContextCurrent) *set_context;
170 static void load_libopenal(void)
174 #ifdef SONAME_LIBOPENAL
176 openal_handle = wine_dlopen(SONAME_LIBOPENAL, RTLD_NOW, error, sizeof(error));
179 ERR("Couldn't load " SONAME_LIBOPENAL ": %s\n", error);
183 #define LOAD_FUNCPTR(f) \
184 if((p##f = wine_dlsym(openal_handle, #f, NULL, 0)) == NULL) { \
185 ERR("Couldn't lookup %s in libopenal\n", #f); \
189 LOAD_FUNCPTR(alcCreateContext);
190 LOAD_FUNCPTR(alcMakeContextCurrent);
191 LOAD_FUNCPTR(alcProcessContext);
192 LOAD_FUNCPTR(alcSuspendContext);
193 LOAD_FUNCPTR(alcDestroyContext);
194 LOAD_FUNCPTR(alcGetCurrentContext);
195 LOAD_FUNCPTR(alcGetContextsDevice);
196 LOAD_FUNCPTR(alcOpenDevice);
197 LOAD_FUNCPTR(alcCloseDevice);
198 LOAD_FUNCPTR(alcGetError);
199 LOAD_FUNCPTR(alcIsExtensionPresent);
200 LOAD_FUNCPTR(alcGetProcAddress);
201 LOAD_FUNCPTR(alcGetEnumValue);
202 LOAD_FUNCPTR(alcGetString);
203 LOAD_FUNCPTR(alcGetIntegerv);
204 LOAD_FUNCPTR(alcCaptureOpenDevice);
205 LOAD_FUNCPTR(alcCaptureCloseDevice);
206 LOAD_FUNCPTR(alcCaptureStart);
207 LOAD_FUNCPTR(alcCaptureStop);
208 LOAD_FUNCPTR(alcCaptureSamples);
209 LOAD_FUNCPTR(alEnable);
210 LOAD_FUNCPTR(alDisable);
211 LOAD_FUNCPTR(alIsEnabled);
212 LOAD_FUNCPTR(alGetString);
213 LOAD_FUNCPTR(alGetBooleanv);
214 LOAD_FUNCPTR(alGetIntegerv);
215 LOAD_FUNCPTR(alGetFloatv);
216 LOAD_FUNCPTR(alGetDoublev);
217 LOAD_FUNCPTR(alGetBoolean);
218 LOAD_FUNCPTR(alGetInteger);
219 LOAD_FUNCPTR(alGetFloat);
220 LOAD_FUNCPTR(alGetDouble);
221 LOAD_FUNCPTR(alGetError);
222 LOAD_FUNCPTR(alIsExtensionPresent);
223 LOAD_FUNCPTR(alGetProcAddress);
224 LOAD_FUNCPTR(alGetEnumValue);
225 LOAD_FUNCPTR(alListenerf);
226 LOAD_FUNCPTR(alListener3f);
227 LOAD_FUNCPTR(alListenerfv);
228 LOAD_FUNCPTR(alListeneri);
229 LOAD_FUNCPTR(alListener3i);
230 LOAD_FUNCPTR(alListeneriv);
231 LOAD_FUNCPTR(alGetListenerf);
232 LOAD_FUNCPTR(alGetListener3f);
233 LOAD_FUNCPTR(alGetListenerfv);
234 LOAD_FUNCPTR(alGetListeneri);
235 LOAD_FUNCPTR(alGetListener3i);
236 LOAD_FUNCPTR(alGetListeneriv);
237 LOAD_FUNCPTR(alGenSources);
238 LOAD_FUNCPTR(alDeleteSources);
239 LOAD_FUNCPTR(alIsSource);
240 LOAD_FUNCPTR(alSourcef);
241 LOAD_FUNCPTR(alSource3f);
242 LOAD_FUNCPTR(alSourcefv);
243 LOAD_FUNCPTR(alSourcei);
244 LOAD_FUNCPTR(alSource3i);
245 LOAD_FUNCPTR(alSourceiv);
246 LOAD_FUNCPTR(alGetSourcef);
247 LOAD_FUNCPTR(alGetSource3f);
248 LOAD_FUNCPTR(alGetSourcefv);
249 LOAD_FUNCPTR(alGetSourcei);
250 LOAD_FUNCPTR(alGetSource3i);
251 LOAD_FUNCPTR(alGetSourceiv);
252 LOAD_FUNCPTR(alSourcePlayv);
253 LOAD_FUNCPTR(alSourceStopv);
254 LOAD_FUNCPTR(alSourceRewindv);
255 LOAD_FUNCPTR(alSourcePausev);
256 LOAD_FUNCPTR(alSourcePlay);
257 LOAD_FUNCPTR(alSourceStop);
258 LOAD_FUNCPTR(alSourceRewind);
259 LOAD_FUNCPTR(alSourcePause);
260 LOAD_FUNCPTR(alSourceQueueBuffers);
261 LOAD_FUNCPTR(alSourceUnqueueBuffers);
262 LOAD_FUNCPTR(alGenBuffers);
263 LOAD_FUNCPTR(alDeleteBuffers);
264 LOAD_FUNCPTR(alIsBuffer);
265 LOAD_FUNCPTR(alBufferf);
266 LOAD_FUNCPTR(alBuffer3f);
267 LOAD_FUNCPTR(alBufferfv);
268 LOAD_FUNCPTR(alBufferi);
269 LOAD_FUNCPTR(alBuffer3i);
270 LOAD_FUNCPTR(alBufferiv);
271 LOAD_FUNCPTR(alGetBufferf);
272 LOAD_FUNCPTR(alGetBuffer3f);
273 LOAD_FUNCPTR(alGetBufferfv);
274 LOAD_FUNCPTR(alGetBufferi);
275 LOAD_FUNCPTR(alGetBuffer3i);
276 LOAD_FUNCPTR(alGetBufferiv);
277 LOAD_FUNCPTR(alBufferData);
278 LOAD_FUNCPTR(alDopplerFactor);
279 LOAD_FUNCPTR(alDopplerVelocity);
280 LOAD_FUNCPTR(alDistanceModel);
281 LOAD_FUNCPTR(alSpeedOfSound);
287 WARN("Unloading openal\n");
288 if (openal_handle != RTLD_DEFAULT)
289 wine_dlclose(openal_handle, NULL, 0);
290 openal_handle = NULL;
296 local_contexts = palcIsExtensionPresent(NULL, "ALC_EXT_thread_local_context");
299 set_context = palcGetProcAddress(NULL, "alcSetThreadContext");
300 get_context = palcGetProcAddress(NULL, "alcGetThreadContext");
301 if (!set_context || !get_context)
303 ERR("TLS advertised but functions not found, disabling thread local context\n");
309 set_context = palcMakeContextCurrent;
310 get_context = palcGetCurrentContext;
315 #endif /*HAVE_OPENAL*/
317 BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
319 TRACE("(0x%p, %d, %p)\n", hinstDLL, fdwReason, lpvReserved);
323 case DLL_PROCESS_ATTACH:
324 DisableThreadLibraryCalls(hinstDLL);
327 #endif /*HAVE_OPENAL*/
329 case DLL_PROCESS_DETACH:
337 HRESULT WINAPI DllCanUnloadNow(void)
342 typedef HRESULT (*FnCreateInstance)(REFIID riid, LPVOID *ppobj);
345 const IClassFactoryVtbl *lpVtbl;
347 FnCreateInstance pfnCreateInstance;
350 static HRESULT WINAPI
351 MMCF_QueryInterface(LPCLASSFACTORY iface, REFIID riid, LPVOID *ppobj)
353 IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
354 TRACE("(%p, %s, %p)\n", This, debugstr_guid(riid), ppobj);
357 if (IsEqualIID(riid, &IID_IUnknown) ||
358 IsEqualIID(riid, &IID_IClassFactory))
361 IUnknown_AddRef(iface);
365 return E_NOINTERFACE;
368 static ULONG WINAPI MMCF_AddRef(LPCLASSFACTORY iface)
373 static ULONG WINAPI MMCF_Release(LPCLASSFACTORY iface)
375 /* static class, won't be freed */
379 static HRESULT WINAPI MMCF_CreateInstance(
380 LPCLASSFACTORY iface,
385 IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
386 TRACE("(%p, %p, %s, %p)\n", This, pOuter, debugstr_guid(riid), ppobj);
389 return CLASS_E_NOAGGREGATION;
392 WARN("invalid parameter\n");
396 return This->pfnCreateInstance(riid, ppobj);
399 static HRESULT WINAPI MMCF_LockServer(LPCLASSFACTORY iface, BOOL dolock)
401 IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
402 FIXME("(%p, %d) stub!\n", This, dolock);
406 static const IClassFactoryVtbl MMCF_Vtbl = {
414 static IClassFactoryImpl MMDEVAPI_CF[] = {
415 { &MMCF_Vtbl, &CLSID_MMDeviceEnumerator, (FnCreateInstance)MMDevEnum_Create }
418 HRESULT WINAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID *ppv)
421 TRACE("(%s, %s, %p)\n", debugstr_guid(rclsid), debugstr_guid(riid), ppv);
424 WARN("invalid parameter\n");
430 if (!IsEqualIID(riid, &IID_IClassFactory) &&
431 !IsEqualIID(riid, &IID_IUnknown)) {
432 WARN("no interface for %s\n", debugstr_guid(riid));
433 return E_NOINTERFACE;
436 for (i = 0; i < sizeof(MMDEVAPI_CF)/sizeof(MMDEVAPI_CF[0]); ++i)
438 if (IsEqualGUID(rclsid, MMDEVAPI_CF[i].rclsid)) {
439 IUnknown_AddRef((IClassFactory*) &MMDEVAPI_CF[i]);
440 *ppv = &MMDEVAPI_CF[i];
446 WARN("(%s, %s, %p): no class found.\n", debugstr_guid(rclsid),
447 debugstr_guid(riid), ppv);
448 return CLASS_E_CLASSNOTAVAILABLE;