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.
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
36 #define NONAMELESSSTRUCT
37 #define NONAMELESSUNION
39 #include "wine/port.h"
41 #include "wine/library.h"
51 #include "wine/debug.h"
67 #include "dsound_private.h"
69 WINE_DEFAULT_DEBUG_CHANNEL(dsound
);
73 IID DSPROPSETID_EAX20_ListenerProperties
= {
74 0x0306a6a8, 0xb224, 0x11d2, { 0x99, 0xe5, 0x00, 0x00, 0xe8, 0xd8, 0xc7, 0x22 }
77 const EAXLISTENERPROPERTIES EnvironmentDefaults
[EAX_ENVIRONMENT_COUNT
] =
79 REVERB_PRESET_GENERIC
,
80 REVERB_PRESET_PADDEDCELL
,
82 REVERB_PRESET_BATHROOM
,
83 REVERB_PRESET_LIVINGROOM
,
84 REVERB_PRESET_STONEROOM
,
85 REVERB_PRESET_AUDITORIUM
,
86 REVERB_PRESET_CONCERTHALL
,
90 REVERB_PRESET_CARPETEDHALLWAY
,
91 REVERB_PRESET_HALLWAY
,
92 REVERB_PRESET_STONECORRIDOR
,
96 REVERB_PRESET_MOUNTAINS
,
99 REVERB_PRESET_PARKINGLOT
,
100 REVERB_PRESET_SEWERPIPE
,
101 REVERB_PRESET_UNDERWATER
,
102 REVERB_PRESET_DRUGGED
,
104 REVERB_PRESET_PSYCHOTIC
107 static CRITICAL_SECTION_DEBUG openal_crst_debug
=
110 { &openal_crst_debug
.ProcessLocksList
,
111 &openal_crst_debug
.ProcessLocksList
},
112 0, 0, { (DWORD_PTR
)(__FILE__
": openal_crst_debug") }
114 CRITICAL_SECTION openal_crst
= { &openal_crst_debug
, -1, 0, 0, 0, 0 };
116 static void *openal_handle
= RTLD_DEFAULT
;
117 int openal_loaded
= 0;
118 #ifdef SONAME_LIBOPENAL
119 LPALCCREATECONTEXT palcCreateContext
= NULL
;
120 LPALCMAKECONTEXTCURRENT palcMakeContextCurrent
= NULL
;
121 LPALCPROCESSCONTEXT palcProcessContext
= NULL
;
122 LPALCSUSPENDCONTEXT palcSuspendContext
= NULL
;
123 LPALCDESTROYCONTEXT palcDestroyContext
= NULL
;
124 LPALCGETCURRENTCONTEXT palcGetCurrentContext
= NULL
;
125 LPALCGETCONTEXTSDEVICE palcGetContextsDevice
= NULL
;
126 LPALCOPENDEVICE palcOpenDevice
= NULL
;
127 LPALCCLOSEDEVICE palcCloseDevice
= NULL
;
128 LPALCGETERROR palcGetError
= NULL
;
129 LPALCISEXTENSIONPRESENT palcIsExtensionPresent
= NULL
;
130 LPALCGETPROCADDRESS palcGetProcAddress
= NULL
;
131 LPALCGETENUMVALUE palcGetEnumValue
= NULL
;
132 LPALCGETSTRING palcGetString
= NULL
;
133 LPALCGETINTEGERV palcGetIntegerv
= NULL
;
134 LPALCCAPTUREOPENDEVICE palcCaptureOpenDevice
= NULL
;
135 LPALCCAPTURECLOSEDEVICE palcCaptureCloseDevice
= NULL
;
136 LPALCCAPTURESTART palcCaptureStart
= NULL
;
137 LPALCCAPTURESTOP palcCaptureStop
= NULL
;
138 LPALCCAPTURESAMPLES palcCaptureSamples
= NULL
;
139 LPALENABLE palEnable
= NULL
;
140 LPALDISABLE palDisable
= NULL
;
141 LPALISENABLED palIsEnabled
= NULL
;
142 LPALGETSTRING palGetString
= NULL
;
143 LPALGETBOOLEANV palGetBooleanv
= NULL
;
144 LPALGETINTEGERV palGetIntegerv
= NULL
;
145 LPALGETFLOATV palGetFloatv
= NULL
;
146 LPALGETDOUBLEV palGetDoublev
= NULL
;
147 LPALGETBOOLEAN palGetBoolean
= NULL
;
148 LPALGETINTEGER palGetInteger
= NULL
;
149 LPALGETFLOAT palGetFloat
= NULL
;
150 LPALGETDOUBLE palGetDouble
= NULL
;
151 LPALGETERROR palGetError
= NULL
;
152 LPALISEXTENSIONPRESENT palIsExtensionPresent
= NULL
;
153 LPALGETPROCADDRESS palGetProcAddress
= NULL
;
154 LPALGETENUMVALUE palGetEnumValue
= NULL
;
155 LPALLISTENERF palListenerf
= NULL
;
156 LPALLISTENER3F palListener3f
= NULL
;
157 LPALLISTENERFV palListenerfv
= NULL
;
158 LPALLISTENERI palListeneri
= NULL
;
159 LPALLISTENER3I palListener3i
= NULL
;
160 LPALLISTENERIV palListeneriv
= NULL
;
161 LPALGETLISTENERF palGetListenerf
= NULL
;
162 LPALGETLISTENER3F palGetListener3f
= NULL
;
163 LPALGETLISTENERFV palGetListenerfv
= NULL
;
164 LPALGETLISTENERI palGetListeneri
= NULL
;
165 LPALGETLISTENER3I palGetListener3i
= NULL
;
166 LPALGETLISTENERIV palGetListeneriv
= NULL
;
167 LPALGENSOURCES palGenSources
= NULL
;
168 LPALDELETESOURCES palDeleteSources
= NULL
;
169 LPALISSOURCE palIsSource
= NULL
;
170 LPALSOURCEF palSourcef
= NULL
;
171 LPALSOURCE3F palSource3f
= NULL
;
172 LPALSOURCEFV palSourcefv
= NULL
;
173 LPALSOURCEI palSourcei
= NULL
;
174 LPALSOURCE3I palSource3i
= NULL
;
175 LPALSOURCEIV palSourceiv
= NULL
;
176 LPALGETSOURCEF palGetSourcef
= NULL
;
177 LPALGETSOURCE3F palGetSource3f
= NULL
;
178 LPALGETSOURCEFV palGetSourcefv
= NULL
;
179 LPALGETSOURCEI palGetSourcei
= NULL
;
180 LPALGETSOURCE3I palGetSource3i
= NULL
;
181 LPALGETSOURCEIV palGetSourceiv
= NULL
;
182 LPALSOURCEPLAYV palSourcePlayv
= NULL
;
183 LPALSOURCESTOPV palSourceStopv
= NULL
;
184 LPALSOURCEREWINDV palSourceRewindv
= NULL
;
185 LPALSOURCEPAUSEV palSourcePausev
= NULL
;
186 LPALSOURCEPLAY palSourcePlay
= NULL
;
187 LPALSOURCESTOP palSourceStop
= NULL
;
188 LPALSOURCEREWIND palSourceRewind
= NULL
;
189 LPALSOURCEPAUSE palSourcePause
= NULL
;
190 LPALSOURCEQUEUEBUFFERS palSourceQueueBuffers
= NULL
;
191 LPALSOURCEUNQUEUEBUFFERS palSourceUnqueueBuffers
= NULL
;
192 LPALGENBUFFERS palGenBuffers
= NULL
;
193 LPALDELETEBUFFERS palDeleteBuffers
= NULL
;
194 LPALISBUFFER palIsBuffer
= NULL
;
195 LPALBUFFERF palBufferf
= NULL
;
196 LPALBUFFER3F palBuffer3f
= NULL
;
197 LPALBUFFERFV palBufferfv
= NULL
;
198 LPALBUFFERI palBufferi
= NULL
;
199 LPALBUFFER3I palBuffer3i
= NULL
;
200 LPALBUFFERIV palBufferiv
= NULL
;
201 LPALGETBUFFERF palGetBufferf
= NULL
;
202 LPALGETBUFFER3F palGetBuffer3f
= NULL
;
203 LPALGETBUFFERFV palGetBufferfv
= NULL
;
204 LPALGETBUFFERI palGetBufferi
= NULL
;
205 LPALGETBUFFER3I palGetBuffer3i
= NULL
;
206 LPALGETBUFFERIV palGetBufferiv
= NULL
;
207 LPALBUFFERDATA palBufferData
= NULL
;
208 LPALDOPPLERFACTOR palDopplerFactor
= NULL
;
209 LPALDOPPLERVELOCITY palDopplerVelocity
= NULL
;
210 LPALDISTANCEMODEL palDistanceModel
= NULL
;
211 LPALSPEEDOFSOUND palSpeedOfSound
= NULL
;
214 LPALCMAKECONTEXTCURRENT set_context
;
215 LPALCGETCURRENTCONTEXT get_context
;
218 static void load_libopenal(void)
222 #ifdef SONAME_LIBOPENAL
224 openal_handle
= wine_dlopen(SONAME_LIBOPENAL
, RTLD_NOW
, error
, sizeof(error
));
226 ERR("Couldn't load " SONAME_LIBOPENAL
": %s\n", error
);
227 #define LOAD_FUNCPTR(f) \
228 if((p##f = wine_dlsym(openal_handle, #f, NULL, 0)) == NULL) { \
229 ERR("Couldn't lookup %s in libopenal\n", #f); \
233 LOAD_FUNCPTR(alcCreateContext
);
234 LOAD_FUNCPTR(alcMakeContextCurrent
);
235 LOAD_FUNCPTR(alcProcessContext
);
236 LOAD_FUNCPTR(alcSuspendContext
);
237 LOAD_FUNCPTR(alcDestroyContext
);
238 LOAD_FUNCPTR(alcGetCurrentContext
);
239 LOAD_FUNCPTR(alcGetContextsDevice
);
240 LOAD_FUNCPTR(alcOpenDevice
);
241 LOAD_FUNCPTR(alcCloseDevice
);
242 LOAD_FUNCPTR(alcGetError
);
243 LOAD_FUNCPTR(alcIsExtensionPresent
);
244 LOAD_FUNCPTR(alcGetProcAddress
);
245 LOAD_FUNCPTR(alcGetEnumValue
);
246 LOAD_FUNCPTR(alcGetString
);
247 LOAD_FUNCPTR(alcGetIntegerv
);
248 LOAD_FUNCPTR(alcCaptureOpenDevice
);
249 LOAD_FUNCPTR(alcCaptureCloseDevice
);
250 LOAD_FUNCPTR(alcCaptureStart
);
251 LOAD_FUNCPTR(alcCaptureStop
);
252 LOAD_FUNCPTR(alcCaptureSamples
);
253 LOAD_FUNCPTR(alEnable
);
254 LOAD_FUNCPTR(alDisable
);
255 LOAD_FUNCPTR(alIsEnabled
);
256 LOAD_FUNCPTR(alGetString
);
257 LOAD_FUNCPTR(alGetBooleanv
);
258 LOAD_FUNCPTR(alGetIntegerv
);
259 LOAD_FUNCPTR(alGetFloatv
);
260 LOAD_FUNCPTR(alGetDoublev
);
261 LOAD_FUNCPTR(alGetBoolean
);
262 LOAD_FUNCPTR(alGetInteger
);
263 LOAD_FUNCPTR(alGetFloat
);
264 LOAD_FUNCPTR(alGetDouble
);
265 LOAD_FUNCPTR(alGetError
);
266 LOAD_FUNCPTR(alIsExtensionPresent
);
267 LOAD_FUNCPTR(alGetProcAddress
);
268 LOAD_FUNCPTR(alGetEnumValue
);
269 LOAD_FUNCPTR(alListenerf
);
270 LOAD_FUNCPTR(alListener3f
);
271 LOAD_FUNCPTR(alListenerfv
);
272 LOAD_FUNCPTR(alListeneri
);
273 LOAD_FUNCPTR(alListener3i
);
274 LOAD_FUNCPTR(alListeneriv
);
275 LOAD_FUNCPTR(alGetListenerf
);
276 LOAD_FUNCPTR(alGetListener3f
);
277 LOAD_FUNCPTR(alGetListenerfv
);
278 LOAD_FUNCPTR(alGetListeneri
);
279 LOAD_FUNCPTR(alGetListener3i
);
280 LOAD_FUNCPTR(alGetListeneriv
);
281 LOAD_FUNCPTR(alGenSources
);
282 LOAD_FUNCPTR(alDeleteSources
);
283 LOAD_FUNCPTR(alIsSource
);
284 LOAD_FUNCPTR(alSourcef
);
285 LOAD_FUNCPTR(alSource3f
);
286 LOAD_FUNCPTR(alSourcefv
);
287 LOAD_FUNCPTR(alSourcei
);
288 LOAD_FUNCPTR(alSource3i
);
289 LOAD_FUNCPTR(alSourceiv
);
290 LOAD_FUNCPTR(alGetSourcef
);
291 LOAD_FUNCPTR(alGetSource3f
);
292 LOAD_FUNCPTR(alGetSourcefv
);
293 LOAD_FUNCPTR(alGetSourcei
);
294 LOAD_FUNCPTR(alGetSource3i
);
295 LOAD_FUNCPTR(alGetSourceiv
);
296 LOAD_FUNCPTR(alSourcePlayv
);
297 LOAD_FUNCPTR(alSourceStopv
);
298 LOAD_FUNCPTR(alSourceRewindv
);
299 LOAD_FUNCPTR(alSourcePausev
);
300 LOAD_FUNCPTR(alSourcePlay
);
301 LOAD_FUNCPTR(alSourceStop
);
302 LOAD_FUNCPTR(alSourceRewind
);
303 LOAD_FUNCPTR(alSourcePause
);
304 LOAD_FUNCPTR(alSourceQueueBuffers
);
305 LOAD_FUNCPTR(alSourceUnqueueBuffers
);
306 LOAD_FUNCPTR(alGenBuffers
);
307 LOAD_FUNCPTR(alDeleteBuffers
);
308 LOAD_FUNCPTR(alIsBuffer
);
309 LOAD_FUNCPTR(alBufferf
);
310 LOAD_FUNCPTR(alBuffer3f
);
311 LOAD_FUNCPTR(alBufferfv
);
312 LOAD_FUNCPTR(alBufferi
);
313 LOAD_FUNCPTR(alBuffer3i
);
314 LOAD_FUNCPTR(alBufferiv
);
315 LOAD_FUNCPTR(alGetBufferf
);
316 LOAD_FUNCPTR(alGetBuffer3f
);
317 LOAD_FUNCPTR(alGetBufferfv
);
318 LOAD_FUNCPTR(alGetBufferi
);
319 LOAD_FUNCPTR(alGetBuffer3i
);
320 LOAD_FUNCPTR(alGetBufferiv
);
321 LOAD_FUNCPTR(alBufferData
);
322 LOAD_FUNCPTR(alDopplerFactor
);
323 LOAD_FUNCPTR(alDopplerVelocity
);
324 LOAD_FUNCPTR(alDistanceModel
);
325 LOAD_FUNCPTR(alSpeedOfSound
);
330 WARN("Unloading openal\n");
331 if (openal_handle
!= RTLD_DEFAULT
)
332 wine_dlclose(openal_handle
, NULL
, 0);
333 openal_handle
= NULL
;
336 local_contexts
= palcIsExtensionPresent(NULL
, "ALC_EXT_thread_local_context");
337 if (local_contexts
) {
338 set_context
= palcGetProcAddress(NULL
, "alcSetThreadContext");
339 get_context
= palcGetProcAddress(NULL
, "alcGetThreadContext");
340 if(!set_context
|| !get_context
)
342 ERR("TLS advertised but functions not found, disabling thread local context\n");
348 set_context
= palcMakeContextCurrent
;
349 get_context
= palcGetCurrentContext
;
355 #endif /*HAVE_OPENAL*/
357 GUID DSOUND_renderer_guids
[MAXWAVEDRIVERS
];
358 GUID DSOUND_capture_guids
[MAXWAVEDRIVERS
];
360 WCHAR wine_vxd_drv
[] = { 'w','i','n','e','m','m','.','v','x','d', 0 };
362 static HINSTANCE instance
;
364 static HRESULT
get_mmdevenum(IMMDeviceEnumerator
**devenum
)
368 init_hr
= CoInitialize(NULL
);
370 hr
= CoCreateInstance(&CLSID_MMDeviceEnumerator
, NULL
,
371 CLSCTX_INPROC_SERVER
, &IID_IMMDeviceEnumerator
, (void**)devenum
);
375 ERR("CoCreateInstance failed: %08x\n", hr
);
382 static void release_mmdevenum(IMMDeviceEnumerator
*devenum
, HRESULT init_hr
)
384 IMMDeviceEnumerator_Release(devenum
);
385 if(SUCCEEDED(init_hr
))
389 static HRESULT
get_mmdevice_guid(IMMDevice
*device
, IPropertyStore
*ps
,
396 hr
= IMMDevice_OpenPropertyStore(device
, STGM_READ
, &ps
);
398 WARN("OpenPropertyStore failed: %08x\n", hr
);
402 IPropertyStore_AddRef(ps
);
404 PropVariantInit(&pv
);
406 hr
= IPropertyStore_GetValue(ps
, &PKEY_AudioEndpoint_GUID
, &pv
);
408 IPropertyStore_Release(ps
);
409 WARN("GetValue(GUID) failed: %08x\n", hr
);
413 CLSIDFromString(pv
.u
.pwszVal
, guid
);
415 PropVariantClear(&pv
);
416 IPropertyStore_Release(ps
);
421 /***************************************************************************
422 * GetDeviceID [DSOUND.9]
424 * Retrieves unique identifier of default device specified
427 * pGuidSrc [I] Address of device GUID.
428 * pGuidDest [O] Address to receive unique device GUID.
432 * Failure: DSERR_INVALIDPARAM
435 * pGuidSrc is a valid device GUID or DSDEVID_DefaultPlayback,
436 * DSDEVID_DefaultCapture, DSDEVID_DefaultVoicePlayback, or
437 * DSDEVID_DefaultVoiceCapture.
438 * Returns pGuidSrc if pGuidSrc is a valid device or the device
439 * GUID for the specified constants.
441 HRESULT WINAPI
GetDeviceID(LPCGUID pGuidSrc
, LPGUID pGuidDest
)
443 IMMDeviceEnumerator
*devenum
;
444 EDataFlow flow
= (EDataFlow
)-1;
445 ERole role
= (ERole
)-1;
448 TRACE("(%s,%p)\n", debugstr_guid(pGuidSrc
),pGuidDest
);
450 if(!pGuidSrc
|| !pGuidDest
)
451 return DSERR_INVALIDPARAM
;
453 init_hr
= get_mmdevenum(&devenum
);
457 if(IsEqualGUID(&DSDEVID_DefaultPlayback
, pGuidSrc
)){
460 }else if(IsEqualGUID(&DSDEVID_DefaultVoicePlayback
, pGuidSrc
)){
461 role
= eCommunications
;
463 }else if(IsEqualGUID(&DSDEVID_DefaultCapture
, pGuidSrc
)){
466 }else if(IsEqualGUID(&DSDEVID_DefaultVoiceCapture
, pGuidSrc
)){
467 role
= eCommunications
;
471 if(role
!= (ERole
)-1 && flow
!= (EDataFlow
)-1){
474 hr
= IMMDeviceEnumerator_GetDefaultAudioEndpoint(devenum
,
475 flow
, role
, &device
);
477 WARN("GetDefaultAudioEndpoint failed: %08x\n", hr
);
478 release_mmdevenum(devenum
, init_hr
);
479 return DSERR_NODRIVER
;
482 hr
= get_mmdevice_guid(device
, NULL
, pGuidDest
);
483 IMMDevice_Release(device
);
485 release_mmdevenum(devenum
, init_hr
);
487 return (hr
== S_OK
) ? DS_OK
: hr
;
490 release_mmdevenum(devenum
, init_hr
);
492 *pGuidDest
= *pGuidSrc
;
499 LPDSENUMCALLBACKA callA
;
503 static BOOL CALLBACK
a_to_w_callback(LPGUID guid
, LPCWSTR descW
, LPCWSTR modW
, LPVOID data
)
505 struct morecontext
*context
= data
;
506 char descA
[MAXPNAMELEN
], modA
[MAXPNAMELEN
];
508 WideCharToMultiByte(CP_ACP
, 0, descW
, -1, descA
, sizeof(descA
), NULL
, NULL
);
509 WideCharToMultiByte(CP_ACP
, 0, modW
, -1, modA
, sizeof(modA
), NULL
, NULL
);
511 return context
->callA(guid
, descA
, modA
, context
->data
);
514 /***************************************************************************
515 * DirectSoundEnumerateA [DSOUND.2]
517 * Enumerate all DirectSound drivers installed in the system
520 * lpDSEnumCallback [I] Address of callback function.
521 * lpContext [I] Address of user defined context passed to callback function.
525 * Failure: DSERR_INVALIDPARAM
527 HRESULT WINAPI
DirectSoundEnumerateA(
528 LPDSENUMCALLBACKA lpDSEnumCallback
,
531 struct morecontext context
;
533 if (lpDSEnumCallback
== NULL
) {
534 WARN("invalid parameter: lpDSEnumCallback == NULL\n");
535 return DSERR_INVALIDPARAM
;
538 context
.callA
= lpDSEnumCallback
;
539 context
.data
= lpContext
;
541 return DirectSoundEnumerateW(a_to_w_callback
, &context
);
544 HRESULT
get_mmdevice(EDataFlow flow
, const GUID
*tgt
, IMMDevice
**device
)
546 IMMDeviceEnumerator
*devenum
;
547 IMMDeviceCollection
*coll
;
551 init_hr
= get_mmdevenum(&devenum
);
555 hr
= IMMDeviceEnumerator_EnumAudioEndpoints(devenum
, flow
,
556 DEVICE_STATE_ACTIVE
, &coll
);
558 WARN("EnumAudioEndpoints failed: %08x\n", hr
);
559 release_mmdevenum(devenum
, init_hr
);
563 hr
= IMMDeviceCollection_GetCount(coll
, &count
);
565 IMMDeviceCollection_Release(coll
);
566 release_mmdevenum(devenum
, init_hr
);
567 WARN("GetCount failed: %08x\n", hr
);
571 for(i
= 0; i
< count
; ++i
){
574 hr
= IMMDeviceCollection_Item(coll
, i
, device
);
578 hr
= get_mmdevice_guid(*device
, NULL
, &guid
);
580 IMMDevice_Release(*device
);
584 if(IsEqualGUID(&guid
, tgt
)){
585 IMMDeviceCollection_Release(coll
);
586 release_mmdevenum(devenum
, init_hr
);
590 IMMDevice_Release(*device
);
593 WARN("No device with GUID %s found!\n", wine_dbgstr_guid(tgt
));
595 IMMDeviceCollection_Release(coll
);
596 release_mmdevenum(devenum
, init_hr
);
598 return DSERR_INVALIDPARAM
;
601 static BOOL
send_device(IMMDevice
*device
, GUID
*guid
,
602 LPDSENUMCALLBACKW cb
, void *user
)
609 PropVariantInit(&pv
);
611 hr
= IMMDevice_OpenPropertyStore(device
, STGM_READ
, &ps
);
613 WARN("OpenPropertyStore failed: %08x\n", hr
);
617 hr
= get_mmdevice_guid(device
, ps
, guid
);
619 IPropertyStore_Release(ps
);
623 hr
= IPropertyStore_GetValue(ps
,
624 (const PROPERTYKEY
*)&DEVPKEY_Device_FriendlyName
, &pv
);
626 IPropertyStore_Release(ps
);
627 WARN("GetValue(FriendlyName) failed: %08x\n", hr
);
631 TRACE("Calling back with %s (%s)\n", wine_dbgstr_guid(guid
),
632 wine_dbgstr_w(pv
.u
.pwszVal
));
634 keep_going
= cb(guid
, pv
.u
.pwszVal
, wine_vxd_drv
, user
);
636 PropVariantClear(&pv
);
637 IPropertyStore_Release(ps
);
642 /* S_FALSE means the callback returned FALSE at some point
643 * S_OK means the callback always returned TRUE */
644 HRESULT
enumerate_mmdevices(EDataFlow flow
, GUID
*guids
,
645 LPDSENUMCALLBACKW cb
, void *user
)
647 IMMDeviceEnumerator
*devenum
;
648 IMMDeviceCollection
*coll
;
649 IMMDevice
*defdev
= NULL
;
654 static const WCHAR primary_desc
[] = {'P','r','i','m','a','r','y',' ',
655 'S','o','u','n','d',' ','D','r','i','v','e','r',0};
656 static const WCHAR empty_drv
[] = {0};
658 init_hr
= get_mmdevenum(&devenum
);
662 hr
= IMMDeviceEnumerator_EnumAudioEndpoints(devenum
, flow
,
663 DEVICE_STATE_ACTIVE
, &coll
);
665 release_mmdevenum(devenum
, init_hr
);
666 WARN("EnumAudioEndpoints failed: %08x\n", hr
);
670 hr
= IMMDeviceCollection_GetCount(coll
, &count
);
672 IMMDeviceCollection_Release(coll
);
673 release_mmdevenum(devenum
, init_hr
);
674 WARN("GetCount failed: %08x\n", hr
);
679 release_mmdevenum(devenum
, init_hr
);
683 TRACE("Calling back with NULL (%s)\n", wine_dbgstr_w(primary_desc
));
684 keep_going
= cb(NULL
, primary_desc
, empty_drv
, user
);
686 /* always send the default device first */
688 hr
= IMMDeviceEnumerator_GetDefaultAudioEndpoint(devenum
, flow
,
689 eMultimedia
, &defdev
);
694 keep_going
= send_device(defdev
, &guids
[0], cb
, user
);
699 for(i
= 0; keep_going
&& i
< count
; ++i
){
702 hr
= IMMDeviceCollection_Item(coll
, i
, &device
);
704 WARN("Item failed: %08x\n", hr
);
708 if(device
!= defdev
){
709 send_device(device
, &guids
[n
], cb
, user
);
713 IMMDevice_Release(device
);
717 IMMDevice_Release(defdev
);
718 IMMDeviceCollection_Release(coll
);
720 release_mmdevenum(devenum
, init_hr
);
722 return (keep_going
== TRUE
) ? S_OK
: S_FALSE
;
725 /***************************************************************************
726 * DirectSoundEnumerateW [DSOUND.3]
728 * Enumerate all DirectSound drivers installed in the system
731 * lpDSEnumCallback [I] Address of callback function.
732 * lpContext [I] Address of user defined context passed to callback function.
736 * Failure: DSERR_INVALIDPARAM
738 HRESULT WINAPI
DirectSoundEnumerateW(
739 LPDSENUMCALLBACKW lpDSEnumCallback
,
744 TRACE("(%p,%p)\n", lpDSEnumCallback
, lpContext
);
746 if (lpDSEnumCallback
== NULL
) {
747 WARN("invalid parameter: lpDSEnumCallback == NULL\n");
748 return DSERR_INVALIDPARAM
;
751 hr
= enumerate_mmdevices(eRender
, DSOUND_renderer_guids
,
752 lpDSEnumCallback
, lpContext
);
753 return SUCCEEDED(hr
) ? DS_OK
: hr
;
756 /***************************************************************************
757 * DirectSoundCaptureEnumerateA [DSOUND.7]
759 * Enumerate all DirectSound drivers installed in the system.
762 * lpDSEnumCallback [I] Address of callback function.
763 * lpContext [I] Address of user defined context passed to callback function.
767 * Failure: DSERR_INVALIDPARAM
769 HRESULT WINAPI
DirectSoundCaptureEnumerateA(
770 LPDSENUMCALLBACKA lpDSEnumCallback
,
773 struct morecontext context
;
775 if (lpDSEnumCallback
== NULL
) {
776 WARN("invalid parameter: lpDSEnumCallback == NULL\n");
777 return DSERR_INVALIDPARAM
;
780 context
.callA
= lpDSEnumCallback
;
781 context
.data
= lpContext
;
783 return DirectSoundCaptureEnumerateW(a_to_w_callback
, &context
);
786 /***************************************************************************
787 * DirectSoundCaptureEnumerateW [DSOUND.8]
789 * Enumerate all DirectSound drivers installed in the system.
792 * lpDSEnumCallback [I] Address of callback function.
793 * lpContext [I] Address of user defined context passed to callback function.
797 * Failure: DSERR_INVALIDPARAM
800 DirectSoundCaptureEnumerateW(
801 LPDSENUMCALLBACKW lpDSEnumCallback
,
806 TRACE("(%p,%p)\n", lpDSEnumCallback
, lpContext
);
808 if (lpDSEnumCallback
== NULL
) {
809 WARN("invalid parameter: lpDSEnumCallback == NULL\n");
810 return DSERR_INVALIDPARAM
;
813 hr
= enumerate_mmdevices(eCapture
, DSOUND_capture_guids
,
814 lpDSEnumCallback
, lpContext
);
815 return SUCCEEDED(hr
) ? DS_OK
: hr
;
818 /*******************************************************************************
819 * DirectSound ClassFactory
822 typedef HRESULT (*FnCreateInstance
)(REFIID riid
, LPVOID
*ppobj
);
825 IClassFactory IClassFactory_iface
;
827 FnCreateInstance pfnCreateInstance
;
830 static inline IClassFactoryImpl
*impl_from_IClassFactory(IClassFactory
*iface
)
832 return CONTAINING_RECORD(iface
, IClassFactoryImpl
, IClassFactory_iface
);
835 static HRESULT WINAPI
836 DSCF_QueryInterface(LPCLASSFACTORY iface
, REFIID riid
, LPVOID
*ppobj
)
838 IClassFactoryImpl
*This
= impl_from_IClassFactory(iface
);
839 TRACE("(%p, %s, %p)\n", This
, debugstr_guid(riid
), ppobj
);
842 if (IsEqualIID(riid
, &IID_IUnknown
) ||
843 IsEqualIID(riid
, &IID_IClassFactory
))
846 IUnknown_AddRef(iface
);
850 return E_NOINTERFACE
;
853 static ULONG WINAPI
DSCF_AddRef(LPCLASSFACTORY iface
)
858 static ULONG WINAPI
DSCF_Release(LPCLASSFACTORY iface
)
860 /* static class, won't be freed */
864 static HRESULT WINAPI
DSCF_CreateInstance(
865 LPCLASSFACTORY iface
,
870 IClassFactoryImpl
*This
= impl_from_IClassFactory(iface
);
871 TRACE("(%p, %p, %s, %p)\n", This
, pOuter
, debugstr_guid(riid
), ppobj
);
874 return CLASS_E_NOAGGREGATION
;
877 WARN("invalid parameter\n");
878 return DSERR_INVALIDPARAM
;
881 return This
->pfnCreateInstance(riid
, ppobj
);
884 static HRESULT WINAPI
DSCF_LockServer(LPCLASSFACTORY iface
, BOOL dolock
)
886 IClassFactoryImpl
*This
= impl_from_IClassFactory(iface
);
887 FIXME("(%p, %d) stub!\n", This
, dolock
);
891 static const IClassFactoryVtbl DSCF_Vtbl
= {
899 static IClassFactoryImpl DSOUND_CF
[] = {
900 { { &DSCF_Vtbl
}, &CLSID_DirectSound
, (FnCreateInstance
)DSOUND_Create
},
901 { { &DSCF_Vtbl
}, &CLSID_DirectSound8
, (FnCreateInstance
)DSOUND_Create8
},
902 { { &DSCF_Vtbl
}, &CLSID_DirectSoundCapture
, (FnCreateInstance
)DSOUND_CaptureCreate
},
903 { { &DSCF_Vtbl
}, &CLSID_DirectSoundCapture8
, (FnCreateInstance
)DSOUND_CaptureCreate8
},
904 { { &DSCF_Vtbl
}, &CLSID_DirectSoundFullDuplex
, (FnCreateInstance
)DSOUND_FullDuplexCreate
},
905 { { &DSCF_Vtbl
}, &CLSID_DirectSoundPrivate
, (FnCreateInstance
)IKsPrivatePropertySetImpl_Create
},
906 { { NULL
}, NULL
, NULL
}
909 /*******************************************************************************
910 * DllGetClassObject [DSOUND.@]
911 * Retrieves class object from a DLL object
914 * Docs say returns STDAPI
917 * rclsid [I] CLSID for the class object
918 * riid [I] Reference to identifier of interface for class object
919 * ppv [O] Address of variable to receive interface pointer for riid
923 * Failure: CLASS_E_CLASSNOTAVAILABLE, E_OUTOFMEMORY, E_INVALIDARG,
926 HRESULT WINAPI
DllGetClassObject(REFCLSID rclsid
, REFIID riid
, LPVOID
*ppv
)
929 TRACE("(%s, %s, %p)\n", debugstr_guid(rclsid
), debugstr_guid(riid
), ppv
);
932 WARN("invalid parameter\n");
938 if (!IsEqualIID(riid
, &IID_IClassFactory
) &&
939 !IsEqualIID(riid
, &IID_IUnknown
)) {
940 WARN("no interface for %s\n", debugstr_guid(riid
));
941 return E_NOINTERFACE
;
944 while (NULL
!= DSOUND_CF
[i
].rclsid
) {
945 if (IsEqualGUID(rclsid
, DSOUND_CF
[i
].rclsid
)) {
946 DSCF_AddRef(&DSOUND_CF
[i
].IClassFactory_iface
);
947 *ppv
= &DSOUND_CF
[i
];
953 WARN("(%s, %s, %p): no class found.\n", debugstr_guid(rclsid
),
954 debugstr_guid(riid
), ppv
);
955 return CLASS_E_CLASSNOTAVAILABLE
;
959 /*******************************************************************************
960 * DllCanUnloadNow [DSOUND.4]
961 * Determines whether the DLL is in use.
964 * Can unload now: S_OK
965 * Cannot unload now (the DLL is still active): S_FALSE
967 HRESULT WINAPI
DllCanUnloadNow(void)
972 #define INIT_GUID(guid, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8) \
973 guid.Data1 = l; guid.Data2 = w1; guid.Data3 = w2; \
974 guid.Data4[0] = b1; guid.Data4[1] = b2; guid.Data4[2] = b3; \
975 guid.Data4[3] = b4; guid.Data4[4] = b5; guid.Data4[5] = b6; \
976 guid.Data4[6] = b7; guid.Data4[7] = b8;
978 /***********************************************************************
979 * DllMain (DSOUND.init)
981 BOOL WINAPI
DllMain(HINSTANCE hInstDLL
, DWORD fdwReason
, LPVOID lpvReserved
)
983 TRACE("(%p %d %p)\n", hInstDLL
, fdwReason
, lpvReserved
);
986 case DLL_PROCESS_ATTACH
:
987 TRACE("DLL_PROCESS_ATTACH\n");
989 DisableThreadLibraryCalls(hInstDLL
);
990 /* Increase refcount on dsound by 1 */
991 GetModuleHandleExW(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS
, (LPCWSTR
)hInstDLL
, &hInstDLL
);
994 #endif /*HAVE_OPENAL*/
996 case DLL_PROCESS_DETACH
:
997 TRACE("DLL_PROCESS_DETACH\n");
998 #ifdef SONAME_LIBOPENAL
1000 wine_dlclose(openal_handle
, NULL
, 0);
1001 #endif /*SONAME_LIBOPENAL*/
1004 TRACE("UNKNOWN REASON\n");
1010 /***********************************************************************
1011 * DllRegisterServer (DSOUND.@)
1013 HRESULT WINAPI
DllRegisterServer(void)
1015 return __wine_register_resources( instance
);
1018 /***********************************************************************
1019 * DllUnregisterServer (DSOUND.@)
1021 HRESULT WINAPI
DllUnregisterServer(void)
1023 return __wine_unregister_resources( instance
);