Remove DllRegisterServer and DllUnregisterServer from Windows builds
[wine/multimedia.git] / dsound_main.c
blob641905fce0fb47834bcf75483e052611a521397c
1 /* DirectSound
3 * Copyright 1998 Marcus Meissner
4 * Copyright 1998 Rob Riggs
5 * Copyright 2000-2002 TransGaming Technologies, Inc.
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 * Most thread locking is complete. There may be a few race
22 * conditions still lurking.
24 * TODO:
25 * Implement SetCooperativeLevel properly (need to address focus issues)
26 * Implement DirectSound3DBuffers (stubs in place)
27 * Use hardware 3D support if available
28 * Add critical section locking inside Release and AddRef methods
29 * Handle static buffers - put those in hardware, non-static not in hardware
30 * Hardware DuplicateSoundBuffer
31 * Proper volume calculation for 3d buffers
32 * Remove DS_HEL_FRAGS and use mixer fragment length for it
35 #include <stdarg.h>
37 #ifdef __WINESRC__
39 #include "wine/library.h"
41 #define COBJMACROS
42 #define NONAMELESSSTRUCT
43 #define NONAMELESSUNION
44 #include "windef.h"
45 #include "winbase.h"
46 #include "winuser.h"
47 #include "winnls.h"
48 #include "winreg.h"
49 #include "mmsystem.h"
50 #include "winternl.h"
51 #include "mmddk.h"
52 #include "wine/debug.h"
53 #include "dsound.h"
54 #include "dsconf.h"
55 #include "ks.h"
56 #include "initguid.h"
57 #include "ksmedia.h"
58 #include "rpcproxy.h"
60 #include "dsound_private.h"
62 WINE_DEFAULT_DEBUG_CHANNEL(dsound);
64 #else
66 #define WINVER 0x0600
67 #include <windows.h>
68 #include <dsound.h>
70 #include "dsound_private.h"
72 #ifndef CP_UNIXCP
73 #define CP_UNIXCP 65010
74 #endif
76 DEFINE_GUID(CLSID_DirectSoundPrivate,0x11ab3ec0,0x25ec,0x11d1,0xa4,0xd8,0x00,0xc0,0x4f,0xc2,0x8a,0xca);
78 int LogLevel = 1;
79 #endif
81 static HINSTANCE instance;
83 const GUID DSOUND_renderer_guid = { 0xbd6dd71a, 0x3deb, 0x11d1, { 0xb1, 0x71, 0x00, 0xc0, 0x4f, 0xc2, 0x00, 0x00 } };
84 const GUID DSOUND_capture_guid = { 0xbd6dd71b, 0x3deb, 0x11d1, { 0xb1, 0x71, 0x00, 0xc0, 0x4f, 0xc2, 0x00, 0x00 } };
86 const IID DSPROPSETID_EAX20_ListenerProperties = {
87 0x0306a6a8, 0xb224, 0x11d2, { 0x99, 0xe5, 0x00, 0x00, 0xe8, 0xd8, 0xc7, 0x22 }
90 const EAXLISTENERPROPERTIES EnvironmentDefaults[EAX_ENVIRONMENT_COUNT] =
92 REVERB_PRESET_GENERIC,
93 REVERB_PRESET_PADDEDCELL,
94 REVERB_PRESET_ROOM,
95 REVERB_PRESET_BATHROOM,
96 REVERB_PRESET_LIVINGROOM,
97 REVERB_PRESET_STONEROOM,
98 REVERB_PRESET_AUDITORIUM,
99 REVERB_PRESET_CONCERTHALL,
100 REVERB_PRESET_CAVE,
101 REVERB_PRESET_ARENA,
102 REVERB_PRESET_HANGAR,
103 REVERB_PRESET_CARPETEDHALLWAY,
104 REVERB_PRESET_HALLWAY,
105 REVERB_PRESET_STONECORRIDOR,
106 REVERB_PRESET_ALLEY,
107 REVERB_PRESET_FOREST,
108 REVERB_PRESET_CITY,
109 REVERB_PRESET_MOUNTAINS,
110 REVERB_PRESET_QUARRY,
111 REVERB_PRESET_PLAIN,
112 REVERB_PRESET_PARKINGLOT,
113 REVERB_PRESET_SEWERPIPE,
114 REVERB_PRESET_UNDERWATER,
115 REVERB_PRESET_DRUGGED,
116 REVERB_PRESET_DIZZY,
117 REVERB_PRESET_PSYCHOTIC
120 static CRITICAL_SECTION_DEBUG openal_crst_debug =
122 0, 0, &openal_crst,
123 { &openal_crst_debug.ProcessLocksList,
124 &openal_crst_debug.ProcessLocksList },
125 0, 0, { (DWORD_PTR)(__FILE__ ": openal_crst_debug") }
127 CRITICAL_SECTION openal_crst = { &openal_crst_debug, -1, 0, 0, 0, 0 };
129 int openal_loaded = 0;
130 #ifdef SONAME_LIBOPENAL
131 static void *openal_handle = NULL;
132 LPALCCREATECONTEXT palcCreateContext = NULL;
133 LPALCMAKECONTEXTCURRENT palcMakeContextCurrent = NULL;
134 LPALCPROCESSCONTEXT palcProcessContext = NULL;
135 LPALCSUSPENDCONTEXT palcSuspendContext = NULL;
136 LPALCDESTROYCONTEXT palcDestroyContext = NULL;
137 LPALCGETCURRENTCONTEXT palcGetCurrentContext = NULL;
138 LPALCGETCONTEXTSDEVICE palcGetContextsDevice = NULL;
139 LPALCOPENDEVICE palcOpenDevice = NULL;
140 LPALCCLOSEDEVICE palcCloseDevice = NULL;
141 LPALCGETERROR palcGetError = NULL;
142 LPALCISEXTENSIONPRESENT palcIsExtensionPresent = NULL;
143 LPALCGETPROCADDRESS palcGetProcAddress = NULL;
144 LPALCGETENUMVALUE palcGetEnumValue = NULL;
145 LPALCGETSTRING palcGetString = NULL;
146 LPALCGETINTEGERV palcGetIntegerv = NULL;
147 LPALCCAPTUREOPENDEVICE palcCaptureOpenDevice = NULL;
148 LPALCCAPTURECLOSEDEVICE palcCaptureCloseDevice = NULL;
149 LPALCCAPTURESTART palcCaptureStart = NULL;
150 LPALCCAPTURESTOP palcCaptureStop = NULL;
151 LPALCCAPTURESAMPLES palcCaptureSamples = NULL;
152 LPALENABLE palEnable = NULL;
153 LPALDISABLE palDisable = NULL;
154 LPALISENABLED palIsEnabled = NULL;
155 LPALGETSTRING palGetString = NULL;
156 LPALGETBOOLEANV palGetBooleanv = NULL;
157 LPALGETINTEGERV palGetIntegerv = NULL;
158 LPALGETFLOATV palGetFloatv = NULL;
159 LPALGETDOUBLEV palGetDoublev = NULL;
160 LPALGETBOOLEAN palGetBoolean = NULL;
161 LPALGETINTEGER palGetInteger = NULL;
162 LPALGETFLOAT palGetFloat = NULL;
163 LPALGETDOUBLE palGetDouble = NULL;
164 LPALGETERROR palGetError = NULL;
165 LPALISEXTENSIONPRESENT palIsExtensionPresent = NULL;
166 LPALGETPROCADDRESS palGetProcAddress = NULL;
167 LPALGETENUMVALUE palGetEnumValue = NULL;
168 LPALLISTENERF palListenerf = NULL;
169 LPALLISTENER3F palListener3f = NULL;
170 LPALLISTENERFV palListenerfv = NULL;
171 LPALLISTENERI palListeneri = NULL;
172 LPALLISTENER3I palListener3i = NULL;
173 LPALLISTENERIV palListeneriv = NULL;
174 LPALGETLISTENERF palGetListenerf = NULL;
175 LPALGETLISTENER3F palGetListener3f = NULL;
176 LPALGETLISTENERFV palGetListenerfv = NULL;
177 LPALGETLISTENERI palGetListeneri = NULL;
178 LPALGETLISTENER3I palGetListener3i = NULL;
179 LPALGETLISTENERIV palGetListeneriv = NULL;
180 LPALGENSOURCES palGenSources = NULL;
181 LPALDELETESOURCES palDeleteSources = NULL;
182 LPALISSOURCE palIsSource = NULL;
183 LPALSOURCEF palSourcef = NULL;
184 LPALSOURCE3F palSource3f = NULL;
185 LPALSOURCEFV palSourcefv = NULL;
186 LPALSOURCEI palSourcei = NULL;
187 LPALSOURCE3I palSource3i = NULL;
188 LPALSOURCEIV palSourceiv = NULL;
189 LPALGETSOURCEF palGetSourcef = NULL;
190 LPALGETSOURCE3F palGetSource3f = NULL;
191 LPALGETSOURCEFV palGetSourcefv = NULL;
192 LPALGETSOURCEI palGetSourcei = NULL;
193 LPALGETSOURCE3I palGetSource3i = NULL;
194 LPALGETSOURCEIV palGetSourceiv = NULL;
195 LPALSOURCEPLAYV palSourcePlayv = NULL;
196 LPALSOURCESTOPV palSourceStopv = NULL;
197 LPALSOURCEREWINDV palSourceRewindv = NULL;
198 LPALSOURCEPAUSEV palSourcePausev = NULL;
199 LPALSOURCEPLAY palSourcePlay = NULL;
200 LPALSOURCESTOP palSourceStop = NULL;
201 LPALSOURCEREWIND palSourceRewind = NULL;
202 LPALSOURCEPAUSE palSourcePause = NULL;
203 LPALSOURCEQUEUEBUFFERS palSourceQueueBuffers = NULL;
204 LPALSOURCEUNQUEUEBUFFERS palSourceUnqueueBuffers = NULL;
205 LPALGENBUFFERS palGenBuffers = NULL;
206 LPALDELETEBUFFERS palDeleteBuffers = NULL;
207 LPALISBUFFER palIsBuffer = NULL;
208 LPALBUFFERF palBufferf = NULL;
209 LPALBUFFER3F palBuffer3f = NULL;
210 LPALBUFFERFV palBufferfv = NULL;
211 LPALBUFFERI palBufferi = NULL;
212 LPALBUFFER3I palBuffer3i = NULL;
213 LPALBUFFERIV palBufferiv = NULL;
214 LPALGETBUFFERF palGetBufferf = NULL;
215 LPALGETBUFFER3F palGetBuffer3f = NULL;
216 LPALGETBUFFERFV palGetBufferfv = NULL;
217 LPALGETBUFFERI palGetBufferi = NULL;
218 LPALGETBUFFER3I palGetBuffer3i = NULL;
219 LPALGETBUFFERIV palGetBufferiv = NULL;
220 LPALBUFFERDATA palBufferData = NULL;
221 LPALDOPPLERFACTOR palDopplerFactor = NULL;
222 LPALDOPPLERVELOCITY palDopplerVelocity = NULL;
223 LPALDISTANCEMODEL palDistanceModel = NULL;
224 LPALSPEEDOFSOUND palSpeedOfSound = NULL;
225 #endif
227 LPALCMAKECONTEXTCURRENT set_context;
228 LPALCGETCURRENTCONTEXT get_context;
229 BOOL local_contexts;
231 static void load_libopenal(void)
233 #ifndef __WINESRC__
234 const char *str = getenv("DSOAL_LOGLEVEL");
235 if(str && *str)
236 LogLevel = atoi(str);
237 #elif defined(SONAME_LIBOPENAL)
238 BOOL failed = FALSE;
239 char error[128];
241 openal_handle = wine_dlopen(SONAME_LIBOPENAL, RTLD_NOW, error, sizeof(error));
242 if(!openal_handle)
243 ERR("Couldn't load " SONAME_LIBOPENAL ": %s\n", error);
244 #define LOAD_FUNCPTR(f) \
245 if((p##f = wine_dlsym(openal_handle, #f, NULL, 0)) == NULL) { \
246 ERR("Couldn't lookup %s in " SONAME_LIBOPENAL "\n", #f); \
247 failed = TRUE; \
250 LOAD_FUNCPTR(alcCreateContext);
251 LOAD_FUNCPTR(alcMakeContextCurrent);
252 LOAD_FUNCPTR(alcProcessContext);
253 LOAD_FUNCPTR(alcSuspendContext);
254 LOAD_FUNCPTR(alcDestroyContext);
255 LOAD_FUNCPTR(alcGetCurrentContext);
256 LOAD_FUNCPTR(alcGetContextsDevice);
257 LOAD_FUNCPTR(alcOpenDevice);
258 LOAD_FUNCPTR(alcCloseDevice);
259 LOAD_FUNCPTR(alcGetError);
260 LOAD_FUNCPTR(alcIsExtensionPresent);
261 LOAD_FUNCPTR(alcGetProcAddress);
262 LOAD_FUNCPTR(alcGetEnumValue);
263 LOAD_FUNCPTR(alcGetString);
264 LOAD_FUNCPTR(alcGetIntegerv);
265 LOAD_FUNCPTR(alcCaptureOpenDevice);
266 LOAD_FUNCPTR(alcCaptureCloseDevice);
267 LOAD_FUNCPTR(alcCaptureStart);
268 LOAD_FUNCPTR(alcCaptureStop);
269 LOAD_FUNCPTR(alcCaptureSamples);
270 LOAD_FUNCPTR(alEnable);
271 LOAD_FUNCPTR(alDisable);
272 LOAD_FUNCPTR(alIsEnabled);
273 LOAD_FUNCPTR(alGetString);
274 LOAD_FUNCPTR(alGetBooleanv);
275 LOAD_FUNCPTR(alGetIntegerv);
276 LOAD_FUNCPTR(alGetFloatv);
277 LOAD_FUNCPTR(alGetDoublev);
278 LOAD_FUNCPTR(alGetBoolean);
279 LOAD_FUNCPTR(alGetInteger);
280 LOAD_FUNCPTR(alGetFloat);
281 LOAD_FUNCPTR(alGetDouble);
282 LOAD_FUNCPTR(alGetError);
283 LOAD_FUNCPTR(alIsExtensionPresent);
284 LOAD_FUNCPTR(alGetProcAddress);
285 LOAD_FUNCPTR(alGetEnumValue);
286 LOAD_FUNCPTR(alListenerf);
287 LOAD_FUNCPTR(alListener3f);
288 LOAD_FUNCPTR(alListenerfv);
289 LOAD_FUNCPTR(alListeneri);
290 LOAD_FUNCPTR(alListener3i);
291 LOAD_FUNCPTR(alListeneriv);
292 LOAD_FUNCPTR(alGetListenerf);
293 LOAD_FUNCPTR(alGetListener3f);
294 LOAD_FUNCPTR(alGetListenerfv);
295 LOAD_FUNCPTR(alGetListeneri);
296 LOAD_FUNCPTR(alGetListener3i);
297 LOAD_FUNCPTR(alGetListeneriv);
298 LOAD_FUNCPTR(alGenSources);
299 LOAD_FUNCPTR(alDeleteSources);
300 LOAD_FUNCPTR(alIsSource);
301 LOAD_FUNCPTR(alSourcef);
302 LOAD_FUNCPTR(alSource3f);
303 LOAD_FUNCPTR(alSourcefv);
304 LOAD_FUNCPTR(alSourcei);
305 LOAD_FUNCPTR(alSource3i);
306 LOAD_FUNCPTR(alSourceiv);
307 LOAD_FUNCPTR(alGetSourcef);
308 LOAD_FUNCPTR(alGetSource3f);
309 LOAD_FUNCPTR(alGetSourcefv);
310 LOAD_FUNCPTR(alGetSourcei);
311 LOAD_FUNCPTR(alGetSource3i);
312 LOAD_FUNCPTR(alGetSourceiv);
313 LOAD_FUNCPTR(alSourcePlayv);
314 LOAD_FUNCPTR(alSourceStopv);
315 LOAD_FUNCPTR(alSourceRewindv);
316 LOAD_FUNCPTR(alSourcePausev);
317 LOAD_FUNCPTR(alSourcePlay);
318 LOAD_FUNCPTR(alSourceStop);
319 LOAD_FUNCPTR(alSourceRewind);
320 LOAD_FUNCPTR(alSourcePause);
321 LOAD_FUNCPTR(alSourceQueueBuffers);
322 LOAD_FUNCPTR(alSourceUnqueueBuffers);
323 LOAD_FUNCPTR(alGenBuffers);
324 LOAD_FUNCPTR(alDeleteBuffers);
325 LOAD_FUNCPTR(alIsBuffer);
326 LOAD_FUNCPTR(alBufferf);
327 LOAD_FUNCPTR(alBuffer3f);
328 LOAD_FUNCPTR(alBufferfv);
329 LOAD_FUNCPTR(alBufferi);
330 LOAD_FUNCPTR(alBuffer3i);
331 LOAD_FUNCPTR(alBufferiv);
332 LOAD_FUNCPTR(alGetBufferf);
333 LOAD_FUNCPTR(alGetBuffer3f);
334 LOAD_FUNCPTR(alGetBufferfv);
335 LOAD_FUNCPTR(alGetBufferi);
336 LOAD_FUNCPTR(alGetBuffer3i);
337 LOAD_FUNCPTR(alGetBufferiv);
338 LOAD_FUNCPTR(alBufferData);
339 LOAD_FUNCPTR(alDopplerFactor);
340 LOAD_FUNCPTR(alDopplerVelocity);
341 LOAD_FUNCPTR(alDistanceModel);
342 LOAD_FUNCPTR(alSpeedOfSound);
343 #undef LOAD_FUNCPTR
344 if (failed)
346 WARN("Unloading openal\n");
347 if (openal_handle != RTLD_DEFAULT)
348 wine_dlclose(openal_handle, NULL, 0);
349 openal_handle = NULL;
351 else
352 #endif
354 openal_loaded = 1;
356 local_contexts = alcIsExtensionPresent(NULL, "ALC_EXT_thread_local_context");
357 if(local_contexts)
359 set_context = alcGetProcAddress(NULL, "alcSetThreadContext");
360 get_context = alcGetProcAddress(NULL, "alcGetThreadContext");
361 if(!set_context || !get_context)
363 ERR("TLS advertised but functions not found, disabling thread local context\n");
364 local_contexts = 0;
367 if(!local_contexts)
369 set_context = alcMakeContextCurrent;
370 get_context = alcGetCurrentContext;
375 const ALCchar *DSOUND_getdevicestrings(void)
377 const ALCchar *str = NULL;
378 int multiple;
380 multiple = alcIsExtensionPresent(NULL, "ALC_ENUMERATE_ALL_EXT");
381 if (multiple)
382 str = alcGetString(NULL, ALC_ALL_DEVICES_SPECIFIER);
383 else
384 str = alcGetString(NULL, ALC_DEVICE_SPECIFIER);
385 return str;
388 const ALCchar *DSOUND_getcapturedevicestrings(void)
390 const ALCchar *str = NULL;
391 str = alcGetString(NULL, ALC_CAPTURE_DEVICE_SPECIFIER);
392 return str;
395 /***************************************************************************
396 * GetDeviceID [DSOUND.9]
398 * Retrieves unique identifier of default device specified
400 * PARAMS
401 * pGuidSrc [I] Address of device GUID.
402 * pGuidDest [O] Address to receive unique device GUID.
404 * RETURNS
405 * Success: DS_OK
406 * Failure: DSERR_INVALIDPARAM
408 * NOTES
409 * pGuidSrc is a valid device GUID or DSDEVID_DefaultPlayback,
410 * DSDEVID_DefaultCapture, DSDEVID_DefaultVoicePlayback, or
411 * DSDEVID_DefaultVoiceCapture.
412 * Returns pGuidSrc if pGuidSrc is a valid device or the device
413 * GUID for the specified constants.
415 HRESULT WINAPI GetDeviceID(LPCGUID pGuidSrc, LPGUID pGuidDest)
417 TRACE("(%s,%p)\n", debugstr_guid(pGuidSrc),pGuidDest);
419 if ( pGuidSrc == NULL) {
420 WARN("invalid parameter: pGuidSrc == NULL\n");
421 return DSERR_INVALIDPARAM;
424 if ( pGuidDest == NULL ) {
425 WARN("invalid parameter: pGuidDest == NULL\n");
426 return DSERR_INVALIDPARAM;
429 if ( IsEqualGUID( &DSDEVID_DefaultPlayback, pGuidSrc ) ||
430 IsEqualGUID( &DSDEVID_DefaultVoicePlayback, pGuidSrc ) ) {
431 *pGuidDest = DSOUND_renderer_guid;
432 TRACE("returns %s\n", debugstr_guid(pGuidDest));
433 return DS_OK;
436 if ( IsEqualGUID( &DSDEVID_DefaultCapture, pGuidSrc ) ||
437 IsEqualGUID( &DSDEVID_DefaultVoiceCapture, pGuidSrc ) ) {
438 *pGuidDest = DSOUND_capture_guid;
439 TRACE("returns %s\n", debugstr_guid(pGuidDest));
440 return DS_OK;
443 *pGuidDest = *pGuidSrc;
444 TRACE("returns %s\n", debugstr_guid(pGuidDest));
446 return DS_OK;
449 struct morecontext
451 LPDSENUMCALLBACKW callW;
452 LPVOID data;
455 static BOOL CALLBACK w_to_a_callback(LPGUID guid, LPCSTR descA, LPCSTR modA, LPVOID data)
457 struct morecontext *context = data;
458 WCHAR descW[MAXPNAMELEN], modW[MAXPNAMELEN];
460 MultiByteToWideChar(CP_ACP, 0, descA, -1, descW, sizeof(descW)/sizeof(descW[0]));
461 MultiByteToWideChar(CP_ACP, 0, modA, -1, modW, sizeof(modW)/sizeof(modW[0]));
463 return context->callW(guid, descW, modW, context->data);
466 /***************************************************************************
467 * DirectSoundEnumerateA [DSOUND.2]
469 * Enumerate all DirectSound drivers installed in the system
471 * PARAMS
472 * lpDSEnumCallback [I] Address of callback function.
473 * lpContext [I] Address of user defined context passed to callback function.
475 * RETURNS
476 * Success: DS_OK
477 * Failure: DSERR_INVALIDPARAM
479 HRESULT WINAPI DirectSoundEnumerateA(
480 LPDSENUMCALLBACKA lpDSEnumCallback,
481 LPVOID lpContext)
483 TRACE("lpDSEnumCallback = %p, lpContext = %p\n",
484 lpDSEnumCallback, lpContext);
486 if (lpDSEnumCallback == NULL) {
487 WARN("invalid parameter: lpDSEnumCallback == NULL\n");
488 return DSERR_INVALIDPARAM;
490 else if (openal_loaded)
492 const ALCchar *devstr;
493 GUID guid;
495 EnterCriticalSection(&openal_crst);
496 devstr = DSOUND_getdevicestrings();
497 if(!devstr || !*devstr)
498 goto out;
500 TRACE("calling lpDSEnumCallback(NULL,\"%s\",\"%s\",%p)\n",
501 "Primary Sound Driver","",lpContext);
502 if(lpDSEnumCallback(NULL, "Primary Sound Driver", "", lpContext) == FALSE)
503 goto out;
505 guid = DSOUND_renderer_guid;
506 do {
507 TRACE("calling lpDSEnumCallback(%s,\"%s\",\"%s\",%p)\n",
508 debugstr_guid(&guid),devstr,"wineal.drv",lpContext);
509 if(lpDSEnumCallback(&guid, devstr, "wineal.drv", lpContext) == FALSE)
510 goto out;
511 guid.Data4[7]++;
512 devstr += strlen(devstr)+1;
513 } while(*devstr);
514 out:
515 LeaveCriticalSection(&openal_crst);
517 else
519 ERR("Attempting to enumerate sound cards without OpenAL support\n");
520 ERR("Please recompile wine with OpenAL for sound to work\n");
522 return DS_OK;
525 /***************************************************************************
526 * DirectSoundEnumerateW [DSOUND.3]
528 * Enumerate all DirectSound drivers installed in the system
530 * PARAMS
531 * lpDSEnumCallback [I] Address of callback function.
532 * lpContext [I] Address of user defined context passed to callback function.
534 * RETURNS
535 * Success: DS_OK
536 * Failure: DSERR_INVALIDPARAM
538 HRESULT WINAPI DirectSoundEnumerateW(
539 LPDSENUMCALLBACKW lpDSEnumCallback,
540 LPVOID lpContext )
542 struct morecontext context;
544 if(lpDSEnumCallback == NULL) {
545 WARN("invalid parameter: lpDSEnumCallback == NULL\n");
546 return DSERR_INVALIDPARAM;
549 context.callW = lpDSEnumCallback;
550 context.data = lpContext;
552 return DirectSoundEnumerateA(w_to_a_callback, &context);
555 /***************************************************************************
556 * DirectSoundCaptureEnumerateA [DSOUND.7]
558 * Enumerate all DirectSound drivers installed in the system.
560 * PARAMS
561 * lpDSEnumCallback [I] Address of callback function.
562 * lpContext [I] Address of user defined context passed to callback function.
564 * RETURNS
565 * Success: DS_OK
566 * Failure: DSERR_INVALIDPARAM
568 HRESULT WINAPI DirectSoundCaptureEnumerateA(
569 LPDSENUMCALLBACKA lpDSEnumCallback,
570 LPVOID lpContext)
572 TRACE("(%p,%p)\n", lpDSEnumCallback, lpContext );
574 if (lpDSEnumCallback == NULL) {
575 WARN("invalid parameter: lpDSEnumCallback == NULL\n");
576 return DSERR_INVALIDPARAM;
578 else if (openal_loaded)
580 const ALCchar *devstr;
581 GUID guid;
583 EnterCriticalSection(&openal_crst);
584 devstr = DSOUND_getcapturedevicestrings();
585 if(!devstr || !*devstr)
586 goto out;
588 TRACE("calling lpDSEnumCallback(NULL,\"%s\",\"%s\",%p)\n",
589 "Primary Sound Capture Driver","",lpContext);
590 if(lpDSEnumCallback(NULL, "Primary Sound Driver", "", lpContext) == FALSE)
591 goto out;
593 guid = DSOUND_capture_guid;
594 do {
595 TRACE("calling lpDSEnumCallback(%s,\"%s\",\"%s\",%p)\n",
596 debugstr_guid(&guid),devstr,"wineal.drv",lpContext);
597 if(lpDSEnumCallback(&guid, devstr, "wineal.drv", lpContext) == FALSE)
598 goto out;
599 guid.Data4[7]++;
600 devstr += strlen(devstr)+1;
601 } while(*devstr);
602 out:
603 LeaveCriticalSection(&openal_crst);
605 else
607 ERR("Attempting to enumerate sound cards without OpenAL support\n");
608 ERR("Please recompile wine with OpenAL for sound to work\n");
610 return DS_OK;
613 /***************************************************************************
614 * DirectSoundCaptureEnumerateW [DSOUND.8]
616 * Enumerate all DirectSound drivers installed in the system.
618 * PARAMS
619 * lpDSEnumCallback [I] Address of callback function.
620 * lpContext [I] Address of user defined context passed to callback function.
622 * RETURNS
623 * Success: DS_OK
624 * Failure: DSERR_INVALIDPARAM
626 HRESULT WINAPI
627 DirectSoundCaptureEnumerateW(
628 LPDSENUMCALLBACKW lpDSEnumCallback,
629 LPVOID lpContext)
631 struct morecontext context;
633 if (lpDSEnumCallback == NULL) {
634 WARN("invalid parameter: lpDSEnumCallback == NULL\n");
635 return DSERR_INVALIDPARAM;
638 context.callW = lpDSEnumCallback;
639 context.data = lpContext;
641 return DirectSoundCaptureEnumerateA(w_to_a_callback, &context);
644 /*******************************************************************************
645 * DirectSoundCreate (DSOUND.1)
647 * Creates and initializes a DirectSound interface.
649 * PARAMS
650 * lpcGUID [I] Address of the GUID that identifies the sound device.
651 * ppDS [O] Address of a variable to receive the interface pointer.
652 * pUnkOuter [I] Must be NULL.
654 * RETURNS
655 * Success: DS_OK
656 * Failure: DSERR_ALLOCATED, DSERR_INVALIDPARAM, DSERR_NOAGGREGATION,
657 * DSERR_NODRIVER, DSERR_OUTOFMEMORY
659 HRESULT WINAPI DirectSoundCreate(
660 LPCGUID lpcGUID,
661 LPDIRECTSOUND *ppDS,
662 IUnknown *pUnkOuter)
664 HRESULT hr;
665 LPDIRECTSOUND pDS;
667 TRACE("(%s,%p,%p)\n",debugstr_guid(lpcGUID),ppDS,pUnkOuter);
669 if (ppDS == NULL) {
670 WARN("invalid parameter: ppDS == NULL\n");
671 return DSERR_INVALIDPARAM;
674 if (pUnkOuter != NULL) {
675 WARN("invalid parameter: pUnkOuter != NULL\n");
676 *ppDS = 0;
677 return DSERR_INVALIDPARAM;
680 hr = DSOUND_Create(&IID_IDirectSound, (void **)&pDS);
681 if (hr == DS_OK) {
682 hr = IDirectSound_Initialize(pDS, lpcGUID);
683 if (hr != DS_OK) {
684 if (hr != DSERR_ALREADYINITIALIZED) {
685 IDirectSound_Release(pDS);
686 pDS = 0;
687 } else
688 hr = DS_OK;
692 *ppDS = pDS;
694 return hr;
697 /*******************************************************************************
698 * DirectSoundCreate8 (DSOUND.11)
700 * Creates and initializes a DirectSound8 interface.
702 * PARAMS
703 * lpcGUID [I] Address of the GUID that identifies the sound device.
704 * ppDS [O] Address of a variable to receive the interface pointer.
705 * pUnkOuter [I] Must be NULL.
707 * RETURNS
708 * Success: DS_OK
709 * Failure: DSERR_ALLOCATED, DSERR_INVALIDPARAM, DSERR_NOAGGREGATION,
710 * DSERR_NODRIVER, DSERR_OUTOFMEMORY
712 HRESULT WINAPI DirectSoundCreate8(
713 LPCGUID lpcGUID,
714 LPDIRECTSOUND8 *ppDS,
715 IUnknown *pUnkOuter)
717 HRESULT hr;
718 LPDIRECTSOUND8 pDS;
720 TRACE("(%s,%p,%p)\n",debugstr_guid(lpcGUID),ppDS,pUnkOuter);
722 if (ppDS == NULL) {
723 WARN("invalid parameter: ppDS == NULL\n");
724 return DSERR_INVALIDPARAM;
727 if (pUnkOuter != NULL) {
728 WARN("invalid parameter: pUnkOuter != NULL\n");
729 *ppDS = 0;
730 return DSERR_INVALIDPARAM;
733 hr = DSOUND_Create8(&IID_IDirectSound8, (void**)&pDS);
734 if (hr == DS_OK) {
735 hr = IDirectSound8_Initialize(pDS, lpcGUID);
736 if (hr != DS_OK) {
737 if (hr != DSERR_ALREADYINITIALIZED) {
738 IDirectSound8_Release(pDS);
739 pDS = 0;
740 } else
741 hr = DS_OK;
745 *ppDS = pDS;
747 return hr;
750 /***************************************************************************
751 * DirectSoundCaptureCreate [DSOUND.6]
753 * Create and initialize a DirectSoundCapture interface.
755 * PARAMS
756 * lpcGUID [I] Address of the GUID that identifies the sound capture device.
757 * lplpDSC [O] Address of a variable to receive the interface pointer.
758 * pUnkOuter [I] Must be NULL.
760 * RETURNS
761 * Success: DS_OK
762 * Failure: DSERR_NOAGGREGATION, DSERR_ALLOCATED, DSERR_INVALIDPARAM,
763 * DSERR_OUTOFMEMORY
765 * NOTES
766 * lpcGUID must be one of the values returned from DirectSoundCaptureEnumerate
767 * or NULL for the default device or DSDEVID_DefaultCapture or
768 * DSDEVID_DefaultVoiceCapture.
770 * DSERR_ALLOCATED is returned for sound devices that do not support full duplex.
772 HRESULT WINAPI DirectSoundCaptureCreate(
773 LPCGUID lpcGUID,
774 IDirectSoundCapture **ppDSC,
775 IUnknown *pUnkOuter)
777 void *pDSC;
778 HRESULT hr;
780 TRACE("(%s, %p, %p)\n", debugstr_guid(lpcGUID), ppDSC, pUnkOuter);
782 if(ppDSC == NULL)
784 WARN("invalid parameter: ppDSC == NULL\n");
785 return DSERR_INVALIDPARAM;
787 *ppDSC = NULL;
789 if(pUnkOuter)
791 WARN("invalid parameter: pUnkOuter != NULL\n");
792 return DSERR_NOAGGREGATION;
795 hr = DSOUND_CaptureCreate(&IID_IDirectSoundCapture, &pDSC);
796 if(hr == DS_OK)
798 *ppDSC = pDSC;
799 hr = IDirectSoundCapture_Initialize(*ppDSC, lpcGUID);
800 if(hr != DS_OK)
802 IDirectSoundCapture_Release(*ppDSC);
803 *ppDSC = 0;
807 return hr;
810 /***************************************************************************
811 * DirectSoundCaptureCreate8 [DSOUND.12]
813 * Create and initialize a DirectSoundCapture interface.
815 * PARAMS
816 * lpcGUID [I] Address of the GUID that identifies the sound capture device.
817 * lplpDSC [O] Address of a variable to receive the interface pointer.
818 * pUnkOuter [I] Must be NULL.
820 * RETURNS
821 * Success: DS_OK
822 * Failure: DSERR_NOAGGREGATION, DSERR_ALLOCATED, DSERR_INVALIDPARAM,
823 * DSERR_OUTOFMEMORY
825 * NOTES
826 * lpcGUID must be one of the values returned from DirectSoundCaptureEnumerate
827 * or NULL for the default device or DSDEVID_DefaultCapture or
828 * DSDEVID_DefaultVoiceCapture.
830 * DSERR_ALLOCATED is returned for sound devices that do not support full duplex.
832 HRESULT WINAPI DirectSoundCaptureCreate8(
833 LPCGUID lpcGUID,
834 IDirectSoundCapture8 **ppDSC8,
835 IUnknown *pUnkOuter)
837 void *pDSC8;
838 HRESULT hr;
840 TRACE("(%s, %p, %p)\n", debugstr_guid(lpcGUID), ppDSC8, pUnkOuter);
842 if(ppDSC8 == NULL)
844 WARN("invalid parameter: ppDSC8 == NULL\n");
845 return DSERR_INVALIDPARAM;
847 *ppDSC8 = NULL;
849 if(pUnkOuter)
851 WARN("invalid parameter: pUnkOuter != NULL\n");
852 return DSERR_NOAGGREGATION;
855 hr = DSOUND_CaptureCreate8(&IID_IDirectSoundCapture8, &pDSC8);
856 if(hr == DS_OK)
858 *ppDSC8 = pDSC8;
859 hr = IDirectSoundCapture_Initialize(*ppDSC8, lpcGUID);
860 if(hr != DS_OK)
862 IDirectSoundCapture_Release(*ppDSC8);
863 *ppDSC8 = NULL;
867 return hr;
870 /*******************************************************************************
871 * DirectSound ClassFactory
874 typedef HRESULT (*FnCreateInstance)(REFIID riid, LPVOID *ppobj);
876 typedef struct {
877 IClassFactory IClassFactory_iface;
878 LONG ref;
879 REFCLSID rclsid;
880 FnCreateInstance pfnCreateInstance;
881 } IClassFactoryImpl;
883 static inline IClassFactoryImpl *impl_from_IClassFactory(IClassFactory *iface)
885 return CONTAINING_RECORD(iface, IClassFactoryImpl, IClassFactory_iface);
888 static HRESULT WINAPI DSCF_QueryInterface(LPCLASSFACTORY iface, REFIID riid, LPVOID *ppobj)
890 IClassFactoryImpl *This = impl_from_IClassFactory(iface);
891 TRACE("(%p, %s, %p)\n", This, debugstr_guid(riid), ppobj);
892 if (ppobj == NULL)
893 return E_POINTER;
894 if (IsEqualIID(riid, &IID_IUnknown) ||
895 IsEqualIID(riid, &IID_IClassFactory))
897 *ppobj = iface;
898 IUnknown_AddRef(iface);
899 return S_OK;
901 *ppobj = NULL;
902 return E_NOINTERFACE;
905 static ULONG WINAPI DSCF_AddRef(LPCLASSFACTORY iface)
907 IClassFactoryImpl *This = impl_from_IClassFactory(iface);
908 ULONG ref = InterlockedIncrement(&(This->ref));
909 TRACE("(%p) ref was %"LONGFMT"u\n", This, ref - 1);
910 return ref;
913 static ULONG WINAPI DSCF_Release(LPCLASSFACTORY iface)
915 IClassFactoryImpl *This = impl_from_IClassFactory(iface);
916 ULONG ref = InterlockedDecrement(&(This->ref));
917 TRACE("(%p) ref was %"LONGFMT"u\n", This, ref + 1);
918 /* static class, won't be freed */
919 return ref;
922 static HRESULT WINAPI DSCF_CreateInstance(
923 LPCLASSFACTORY iface,
924 LPUNKNOWN pOuter,
925 REFIID riid,
926 LPVOID *ppobj)
928 IClassFactoryImpl *This = impl_from_IClassFactory(iface);
929 TRACE("(%p, %p, %s, %p)\n", This, pOuter, debugstr_guid(riid), ppobj);
931 if (pOuter)
932 return CLASS_E_NOAGGREGATION;
934 if (ppobj == NULL) {
935 WARN("invalid parameter\n");
936 return DSERR_INVALIDPARAM;
938 *ppobj = NULL;
939 return This->pfnCreateInstance(riid, ppobj);
942 static HRESULT WINAPI DSCF_LockServer(LPCLASSFACTORY iface, BOOL dolock)
944 IClassFactoryImpl *This = impl_from_IClassFactory(iface);
945 FIXME("(%p, %d) stub!\n", This, dolock);
946 return S_OK;
949 static const IClassFactoryVtbl DSCF_Vtbl = {
950 DSCF_QueryInterface,
951 DSCF_AddRef,
952 DSCF_Release,
953 DSCF_CreateInstance,
954 DSCF_LockServer
957 static IClassFactoryImpl DSOUND_CF[] = {
958 { {(IClassFactoryVtbl*)&DSCF_Vtbl}, 1, &CLSID_DirectSound, DSOUND_Create },
959 { {(IClassFactoryVtbl*)&DSCF_Vtbl}, 1, &CLSID_DirectSound8, DSOUND_Create8 },
960 { {(IClassFactoryVtbl*)&DSCF_Vtbl}, 1, &CLSID_DirectSoundCapture, DSOUND_CaptureCreate },
961 { {(IClassFactoryVtbl*)&DSCF_Vtbl}, 1, &CLSID_DirectSoundCapture8, DSOUND_CaptureCreate8 },
962 { {(IClassFactoryVtbl*)&DSCF_Vtbl}, 1, &CLSID_DirectSoundFullDuplex, DSOUND_FullDuplexCreate },
963 { {(IClassFactoryVtbl*)&DSCF_Vtbl}, 1, &CLSID_DirectSoundPrivate, IKsPrivatePropertySetImpl_Create },
964 { {NULL}, 0, NULL, NULL }
967 /*******************************************************************************
968 * DllGetClassObject [DSOUND.@]
969 * Retrieves class object from a DLL object
971 * NOTES
972 * Docs say returns STDAPI
974 * PARAMS
975 * rclsid [I] CLSID for the class object
976 * riid [I] Reference to identifier of interface for class object
977 * ppv [O] Address of variable to receive interface pointer for riid
979 * RETURNS
980 * Success: S_OK
981 * Failure: CLASS_E_CLASSNOTAVAILABLE, E_OUTOFMEMORY, E_INVALIDARG,
982 * E_UNEXPECTED
984 HRESULT WINAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID *ppv)
986 int i = 0;
987 TRACE("(%s, %s, %p)\n", debugstr_guid(rclsid), debugstr_guid(riid), ppv);
989 if (ppv == NULL) {
990 WARN("invalid parameter\n");
991 return E_INVALIDARG;
994 *ppv = NULL;
996 if (!IsEqualIID(riid, &IID_IClassFactory) &&
997 !IsEqualIID(riid, &IID_IUnknown)) {
998 WARN("no interface for %s\n", debugstr_guid(riid));
999 return E_NOINTERFACE;
1002 while (NULL != DSOUND_CF[i].rclsid) {
1003 if (IsEqualGUID(rclsid, DSOUND_CF[i].rclsid)) {
1004 DSCF_AddRef(&DSOUND_CF[i].IClassFactory_iface);
1005 *ppv = &DSOUND_CF[i];
1006 return S_OK;
1008 i++;
1011 WARN("(%s, %s, %p): no class found.\n", debugstr_guid(rclsid),
1012 debugstr_guid(riid), ppv);
1013 return CLASS_E_CLASSNOTAVAILABLE;
1017 /*******************************************************************************
1018 * DllCanUnloadNow [DSOUND.4]
1019 * Determines whether the DLL is in use.
1021 * RETURNS
1022 * Success: S_OK
1023 * Failure: S_FALSE
1025 HRESULT WINAPI DllCanUnloadNow(void)
1027 FIXME("(void): stub\n");
1028 return S_FALSE;
1031 /***********************************************************************
1032 * DllMain (DSOUND.init)
1034 BOOL WINAPI DllMain(HINSTANCE hInstDLL, DWORD fdwReason, LPVOID lpvReserved)
1036 TRACE("(%p, %"LONGFMT"u, %p)\n", hInstDLL, fdwReason, lpvReserved);
1038 switch(fdwReason)
1040 case DLL_PROCESS_ATTACH:
1041 TRACE("DLL_PROCESS_ATTACH\n");
1042 instance = hInstDLL;
1043 load_libopenal();
1044 DisableThreadLibraryCalls(hInstDLL);
1045 /* Increase refcount on dsound by 1 */
1046 GetModuleHandleExW(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS, (LPCWSTR)hInstDLL, &hInstDLL);
1047 break;
1048 case DLL_PROCESS_DETACH:
1049 TRACE("DLL_PROCESS_DETACH\n");
1050 #ifdef SONAME_LIBOPENAL
1051 if(openal_handle)
1052 wine_dlclose(openal_handle, NULL, 0);
1053 #endif /*SONAME_LIBOPENAL*/
1054 break;
1055 default:
1056 TRACE("UNKNOWN REASON\n");
1057 break;
1059 return TRUE;
1062 #ifdef __WINESRC__
1063 /***********************************************************************
1064 * DllRegisterServer (DSOUND.@)
1066 HRESULT WINAPI DllRegisterServer(void)
1068 return __wine_register_resources(instance, NULL);
1071 /***********************************************************************
1072 * DllUnregisterServer (DSOUND.@)
1074 HRESULT WINAPI DllUnregisterServer(void)
1076 return __wine_unregister_resources(instance, NULL);
1078 #endif