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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 * Most thread locking is complete. There may be a few race
23 * conditions still lurking.
25 * Tested with a Soundblaster clone, a Gravis UltraSound Classic,
26 * and a Turtle Beach Tropez+.
29 * Implement SetCooperativeLevel properly (need to address focus issues)
30 * Implement DirectSound3DBuffers (stubs in place)
31 * Use hardware 3D support if available
32 * Add critical section locking inside Release and AddRef methods
33 * Handle static buffers - put those in hardware, non-static not in hardware
34 * Hardware DuplicateSoundBuffer
35 * Proper volume calculation, and setting volume in HEL primary buffer
36 * Optimize WINMM and negotiate fragment size, decrease DS_HEL_MARGIN
40 #include "wine/port.h"
45 #include <sys/types.h>
46 #include <sys/fcntl.h>
54 #define NONAMELESSSTRUCT
55 #define NONAMELESSUNION
66 #include "wine/windef16.h"
67 #include "wine/winbase16.h"
68 #include "wine/debug.h"
71 #include "dsound_private.h"
74 WINE_DEFAULT_DEBUG_CHANNEL(dsound);
76 /* these are eligible for tuning... they must be high on slow machines... */
77 /* some stuff may get more responsive with lower values though... */
78 #define DS_EMULDRIVER 0 /* some games (Quake 2, UT) refuse to accept
79 emulated dsound devices. set to 0 ! */
80 #define DS_HEL_MARGIN 5 /* HEL only: number of waveOut fragments ahead to mix in new buffers
81 * (keep this close or equal to DS_HEL_QUEUE for best results) */
82 #define DS_HEL_QUEUE 5 /* HEL only: number of waveOut fragments ahead to queue to driver
83 * (this will affect HEL sound reliability and latency) */
85 #define DS_SND_QUEUE_MAX 28 /* max number of fragments to prebuffer */
86 #define DS_SND_QUEUE_MIN 12 /* min number of fragments to prebuffer */
88 IDirectSoundImpl* dsound = NULL;
90 HRESULT mmErr(UINT err)
93 case MMSYSERR_NOERROR:
95 case MMSYSERR_ALLOCATED:
96 return DSERR_ALLOCATED;
98 case MMSYSERR_INVALHANDLE:
99 case WAVERR_STILLPLAYING:
100 return DSERR_GENERIC; /* FIXME */
101 case MMSYSERR_NODRIVER:
102 return DSERR_NODRIVER;
104 return DSERR_OUTOFMEMORY;
105 case MMSYSERR_INVALPARAM:
106 case WAVERR_BADFORMAT:
107 case WAVERR_UNPREPARED:
108 return DSERR_INVALIDPARAM;
109 case MMSYSERR_NOTSUPPORTED:
110 return DSERR_UNSUPPORTED;
112 FIXME("Unknown MMSYS error %d\n",err);
113 return DSERR_GENERIC;
117 int ds_emuldriver = DS_EMULDRIVER;
118 int ds_hel_margin = DS_HEL_MARGIN;
119 int ds_hel_queue = DS_HEL_QUEUE;
120 int ds_snd_queue_max = DS_SND_QUEUE_MAX;
121 int ds_snd_queue_min = DS_SND_QUEUE_MIN;
122 int ds_hw_accel = DS_HW_ACCEL_FULL;
123 int ds_default_playback = 0;
124 int ds_default_capture = 0;
127 * Get a config key from either the app-specific or the default config
130 inline static DWORD get_config_key( HKEY defkey, HKEY appkey, const char *name,
131 char *buffer, DWORD size )
133 if (appkey && !RegQueryValueExA( appkey, name, 0, NULL, buffer, &size )) return 0;
134 return RegQueryValueExA( defkey, name, 0, NULL, buffer, &size );
139 * Setup the dsound options.
142 void setup_dsound_options(void)
144 char buffer[MAX_PATH+1];
145 HKEY hkey, appkey = 0;
147 buffer[MAX_PATH]='\0';
149 if (RegCreateKeyExA( HKEY_LOCAL_MACHINE, "Software\\Wine\\Wine\\Config\\dsound", 0, NULL,
150 REG_OPTION_VOLATILE, KEY_ALL_ACCESS, NULL, &hkey, NULL ))
152 ERR("Cannot create config registry key\n" );
156 if (GetModuleFileNameA( 0, buffer, MAX_PATH ))
160 if (!RegOpenKeyA( HKEY_LOCAL_MACHINE, "Software\\Wine\\Wine\\Config\\AppDefaults", &tmpkey ))
162 char appname[MAX_PATH+16];
163 char *p = strrchr( buffer, '\\' );
165 appname[MAX_PATH]='\0';
166 strncpy(appname,p+1,MAX_PATH);
167 strcat(appname,"\\dsound");
168 TRACE("appname = [%s] \n",appname);
169 if (RegOpenKeyA( tmpkey, appname, &appkey )) appkey = 0;
170 RegCloseKey( tmpkey );
177 if (!get_config_key( hkey, appkey, "EmulDriver", buffer, MAX_PATH ))
178 ds_emuldriver = strcmp(buffer, "N");
180 if (!get_config_key( hkey, appkey, "HELmargin", buffer, MAX_PATH ))
181 ds_hel_margin = atoi(buffer);
183 if (!get_config_key( hkey, appkey, "HELqueue", buffer, MAX_PATH ))
184 ds_hel_queue = atoi(buffer);
186 if (!get_config_key( hkey, appkey, "SndQueueMax", buffer, MAX_PATH ))
187 ds_snd_queue_max = atoi(buffer);
189 if (!get_config_key( hkey, appkey, "SndQueueMin", buffer, MAX_PATH ))
190 ds_snd_queue_min = atoi(buffer);
192 if (!get_config_key( hkey, appkey, "HardwareAcceleration", buffer, MAX_PATH )) {
193 if (strcmp(buffer, "Full") == 0)
194 ds_hw_accel = DS_HW_ACCEL_FULL;
195 else if (strcmp(buffer, "Standard") == 0)
196 ds_hw_accel = DS_HW_ACCEL_STANDARD;
197 else if (strcmp(buffer, "Basic") == 0)
198 ds_hw_accel = DS_HW_ACCEL_BASIC;
199 else if (strcmp(buffer, "Emulation") == 0)
200 ds_hw_accel = DS_HW_ACCEL_EMULATION;
203 if (!get_config_key( hkey, appkey, "DefaultPlayback", buffer, MAX_PATH ))
204 ds_default_playback = atoi(buffer);
206 if (!get_config_key( hkey, appkey, "DefaultCapture", buffer, MAX_PATH ))
207 ds_default_capture = atoi(buffer);
209 if (appkey) RegCloseKey( appkey );
212 if (ds_emuldriver != DS_EMULDRIVER )
213 WARN("ds_emuldriver = %d (default=%d)\n",ds_emuldriver, DS_EMULDRIVER);
214 if (ds_hel_margin != DS_HEL_MARGIN )
215 WARN("ds_hel_margin = %d (default=%d)\n",ds_hel_margin, DS_HEL_MARGIN );
216 if (ds_hel_queue != DS_HEL_QUEUE )
217 WARN("ds_hel_queue = %d (default=%d)\n",ds_hel_queue, DS_HEL_QUEUE );
218 if (ds_snd_queue_max != DS_SND_QUEUE_MAX)
219 WARN("ds_snd_queue_max = %d (default=%d)\n",ds_snd_queue_max ,DS_SND_QUEUE_MAX);
220 if (ds_snd_queue_min != DS_SND_QUEUE_MIN)
221 WARN("ds_snd_queue_min = %d (default=%d)\n",ds_snd_queue_min ,DS_SND_QUEUE_MIN);
222 if (ds_hw_accel != DS_HW_ACCEL_FULL)
223 WARN("ds_hw_accel = %s (default=Full)\n",
224 ds_hw_accel==DS_HW_ACCEL_FULL ? "Full" :
225 ds_hw_accel==DS_HW_ACCEL_STANDARD ? "Standard" :
226 ds_hw_accel==DS_HW_ACCEL_BASIC ? "Basic" :
227 ds_hw_accel==DS_HW_ACCEL_EMULATION ? "Emulation" :
229 if (ds_default_playback != 0)
230 WARN("ds_default_playback = %d (default=0)\n",ds_default_playback);
231 if (ds_default_capture != 0)
232 WARN("ds_default_capture = %d (default=0)\n",ds_default_playback);
237 /***************************************************************************
238 * GetDeviceID [DSOUND.9]
240 * Retrieves unique identifier of default device specified
243 * pGuidSrc [I] Address of device GUID.
244 * pGuidDest [O] Address to receive unique device GUID.
248 * Failure: DSERR_INVALIDPARAM
251 * pGuidSrc is a valid device GUID or DSDEVID_DefaultPlayback,
252 * DSDEVID_DefaultCapture, DSDEVID_DefaultVoicePlayback, or
253 * DSDEVID_DefaultVoiceCapture.
254 * Returns pGuidSrc if pGuidSrc is a valid device or the device
255 * GUID for the specified constants.
257 HRESULT WINAPI GetDeviceID(LPCGUID pGuidSrc, LPGUID pGuidDest)
259 TRACE("(%p,%p)\n",pGuidSrc,pGuidDest);
261 if ( pGuidSrc == NULL) {
262 WARN("invalid parameter: pGuidSrc == NULL\n");
263 return DSERR_INVALIDPARAM;
266 if ( pGuidDest == NULL ) {
267 WARN("invalid parameter: pGuidDest == NULL\n");
268 return DSERR_INVALIDPARAM;
271 if ( IsEqualGUID( &DSDEVID_DefaultPlayback, pGuidSrc ) ||
272 IsEqualGUID( &DSDEVID_DefaultVoicePlayback, pGuidSrc ) ) {
274 int err = mmErr(waveOutMessage((HWAVEOUT)ds_default_playback,DRV_QUERYDSOUNDGUID,(DWORD)&guid,0));
276 memcpy(pGuidDest, &guid, sizeof(GUID));
281 if ( IsEqualGUID( &DSDEVID_DefaultCapture, pGuidSrc ) ||
282 IsEqualGUID( &DSDEVID_DefaultVoiceCapture, pGuidSrc ) ) {
284 int err = mmErr(waveInMessage((HWAVEIN)ds_default_capture,DRV_QUERYDSOUNDGUID,(DWORD)&guid,0));
286 memcpy(pGuidDest, &guid, sizeof(GUID));
291 memcpy(pGuidDest, pGuidSrc, sizeof(GUID));
297 /***************************************************************************
298 * DirectSoundEnumerateA [DSOUND.2]
300 * Enumerate all DirectSound drivers installed in the system
303 * lpDSEnumCallback [I] Address of callback function.
304 * lpContext [I] Address of user defined context passed to callback function.
308 * Failure: DSERR_INVALIDPARAM
310 HRESULT WINAPI DirectSoundEnumerateA(
311 LPDSENUMCALLBACKA lpDSEnumCallback,
319 TRACE("lpDSEnumCallback = %p, lpContext = %p\n",
320 lpDSEnumCallback, lpContext);
322 if (lpDSEnumCallback == NULL) {
323 WARN("invalid parameter: lpDSEnumCallback == NULL\n");
324 return DSERR_INVALIDPARAM;
327 devs = waveOutGetNumDevs();
329 if (GetDeviceID(&DSDEVID_DefaultPlayback, &guid) == DS_OK) {
331 for (wod = 0; wod < devs; ++wod) {
332 err = mmErr(waveOutMessage((HWAVEOUT)wod,DRV_QUERYDSOUNDGUID,(DWORD)&temp,0));
334 if (IsEqualGUID( &guid, &temp ) ) {
335 err = mmErr(waveOutMessage((HWAVEOUT)wod,DRV_QUERYDSOUNDDESC,(DWORD)&desc,0));
337 TRACE("calling lpDSEnumCallback(%s,\"%s\",\"%s\",%p)\n",
338 debugstr_guid(&DSDEVID_DefaultPlayback),"Primary Sound Driver",desc.szDrvName,lpContext);
339 if (lpDSEnumCallback(NULL, "Primary Sound Driver", desc.szDrvName, lpContext) == FALSE)
348 for (wod = 0; wod < devs; ++wod) {
349 err = mmErr(waveOutMessage((HWAVEOUT)wod,DRV_QUERYDSOUNDDESC,(DWORD)&desc,0));
351 err = mmErr(waveOutMessage((HWAVEOUT)wod,DRV_QUERYDSOUNDGUID,(DWORD)&guid,0));
353 TRACE("calling lpDSEnumCallback(%s,\"%s\",\"%s\",%p)\n",
354 debugstr_guid(&guid),desc.szDesc,desc.szDrvName,lpContext);
355 if (lpDSEnumCallback(&guid, desc.szDesc, desc.szDrvName, lpContext) == FALSE)
363 /***************************************************************************
364 * DirectSoundEnumerateW [DSOUND.3]
366 * Enumerate all DirectSound drivers installed in the system
369 * lpDSEnumCallback [I] Address of callback function.
370 * lpContext [I] Address of user defined context passed to callback function.
374 * Failure: DSERR_INVALIDPARAM
376 HRESULT WINAPI DirectSoundEnumerateW(
377 LPDSENUMCALLBACKW lpDSEnumCallback,
384 WCHAR wDesc[MAXPNAMELEN];
385 WCHAR wName[MAXPNAMELEN];
387 TRACE("lpDSEnumCallback = %p, lpContext = %p\n",
388 lpDSEnumCallback, lpContext);
390 if (lpDSEnumCallback == NULL) {
391 WARN("invalid parameter: lpDSEnumCallback == NULL\n");
392 return DSERR_INVALIDPARAM;
395 devs = waveOutGetNumDevs();
397 if (GetDeviceID(&DSDEVID_DefaultPlayback, &guid) == DS_OK) {
399 for (wod = 0; wod < devs; ++wod) {
400 err = mmErr(waveOutMessage((HWAVEOUT)wod,DRV_QUERYDSOUNDGUID,(DWORD)&temp,0));
402 if (IsEqualGUID( &guid, &temp ) ) {
403 err = mmErr(waveOutMessage((HWAVEOUT)wod,DRV_QUERYDSOUNDDESC,(DWORD)&desc,0));
405 TRACE("calling lpDSEnumCallback(%s,\"%s\",\"%s\",%p)\n",
406 debugstr_guid(&DSDEVID_DefaultPlayback),"Primary Sound Driver",desc.szDrvName,lpContext);
407 MultiByteToWideChar( CP_ACP, 0, "Primary Sound Driver", -1,
408 wDesc, sizeof(wDesc)/sizeof(WCHAR) );
409 MultiByteToWideChar( CP_ACP, 0, desc.szDrvName, -1,
410 wName, sizeof(wName)/sizeof(WCHAR) );
411 if (lpDSEnumCallback(NULL, wDesc, wName, lpContext) == FALSE)
420 for (wod = 0; wod < devs; ++wod) {
421 err = mmErr(waveOutMessage((HWAVEOUT)wod,DRV_QUERYDSOUNDDESC,(DWORD)&desc,0));
423 err = mmErr(waveOutMessage((HWAVEOUT)wod,DRV_QUERYDSOUNDGUID,(DWORD)&guid,0));
425 TRACE("calling lpDSEnumCallback(%s,\"%s\",\"%s\",%p)\n",
426 debugstr_guid(&guid),desc.szDesc,desc.szDrvName,lpContext);
427 MultiByteToWideChar( CP_ACP, 0, desc.szDesc, -1,
428 wDesc, sizeof(wDesc)/sizeof(WCHAR) );
429 MultiByteToWideChar( CP_ACP, 0, desc.szDrvName, -1,
430 wName, sizeof(wName)/sizeof(WCHAR) );
431 if (lpDSEnumCallback(&guid, wDesc, wName, lpContext) == FALSE)
440 static void _dump_DSBCAPS(DWORD xmask) {
445 #define FE(x) { x, #x },
446 FE(DSBCAPS_PRIMARYBUFFER)
448 FE(DSBCAPS_LOCHARDWARE)
449 FE(DSBCAPS_LOCSOFTWARE)
451 FE(DSBCAPS_CTRLFREQUENCY)
453 FE(DSBCAPS_CTRLVOLUME)
454 FE(DSBCAPS_CTRLPOSITIONNOTIFY)
455 FE(DSBCAPS_CTRLDEFAULT)
457 FE(DSBCAPS_STICKYFOCUS)
458 FE(DSBCAPS_GLOBALFOCUS)
459 FE(DSBCAPS_GETCURRENTPOSITION2)
460 FE(DSBCAPS_MUTE3DATMAXDISTANCE)
465 for (i=0;i<sizeof(flags)/sizeof(flags[0]);i++)
466 if ((flags[i].mask & xmask) == flags[i].mask)
467 DPRINTF("%s ",flags[i].name);
470 /*******************************************************************************
474 static HRESULT WINAPI IDirectSoundImpl_SetCooperativeLevel(
475 LPDIRECTSOUND8 iface,HWND hwnd,DWORD level
477 ICOM_THIS(IDirectSoundImpl,iface);
478 TRACE("(%p,%08lx,%ld)\n",This,(DWORD)hwnd,level);
480 if (level==DSSCL_PRIORITY || level==DSSCL_EXCLUSIVE) {
481 FIXME("level=%s not fully supported\n",
482 level==DSSCL_PRIORITY ? "DSSCL_PRIORITY" : "DSSCL_EXCLUSIVE");
485 This->priolevel = level;
490 static HRESULT WINAPI IDirectSoundImpl_CreateSoundBuffer(
491 LPDIRECTSOUND8 iface,LPDSBUFFERDESC dsbd,LPLPDIRECTSOUNDBUFFER8 ppdsb,LPUNKNOWN lpunk
493 ICOM_THIS(IDirectSoundImpl,iface);
495 HRESULT hres = DS_OK;
497 TRACE("(%p,%p,%p,%p)\n",This,dsbd,ppdsb,lpunk);
500 WARN("invalid parameter: This == NULL\n");
501 return DSERR_INVALIDPARAM;
505 WARN("invalid parameter: dsbd == NULL\n");
506 return DSERR_INVALIDPARAM;
510 WARN("invalid parameter: ppdsb == NULL\n");
511 return DSERR_INVALIDPARAM;
514 if (TRACE_ON(dsound)) {
515 TRACE("(structsize=%ld)\n",dsbd->dwSize);
516 TRACE("(flags=0x%08lx:\n",dsbd->dwFlags);
517 _dump_DSBCAPS(dsbd->dwFlags);
519 TRACE("(bufferbytes=%ld)\n",dsbd->dwBufferBytes);
520 TRACE("(lpwfxFormat=%p)\n",dsbd->lpwfxFormat);
523 wfex = dsbd->lpwfxFormat;
526 TRACE("(formattag=0x%04x,chans=%d,samplerate=%ld,"
527 "bytespersec=%ld,blockalign=%d,bitspersamp=%d,cbSize=%d)\n",
528 wfex->wFormatTag, wfex->nChannels, wfex->nSamplesPerSec,
529 wfex->nAvgBytesPerSec, wfex->nBlockAlign,
530 wfex->wBitsPerSample, wfex->cbSize);
532 if (dsbd->dwFlags & DSBCAPS_PRIMARYBUFFER) {
534 WARN("Primary Buffer already created\n");
535 IDirectSoundBuffer_AddRef((LPDIRECTSOUNDBUFFER8)(This->primary));
536 *ppdsb = (LPDIRECTSOUNDBUFFER8)(This->primary);
539 hres = PrimaryBufferImpl_Create(This, (PrimaryBufferImpl**)&(This->primary), &(This->dsbd));
541 IDirectSoundBuffer_AddRef((LPDIRECTSOUNDBUFFER8)(This->primary));
542 *ppdsb = (LPDIRECTSOUNDBUFFER8)(This->primary);
544 WARN("PrimaryBufferImpl_Create failed\n");
547 IDirectSoundBufferImpl * dsb;
548 hres = IDirectSoundBufferImpl_Create(This, (IDirectSoundBufferImpl**)&dsb, dsbd);
550 hres = SecondaryBufferImpl_Create(dsb, (SecondaryBufferImpl**)ppdsb);
552 dsb->dsb = (SecondaryBufferImpl*)*ppdsb;
553 IDirectSoundBuffer_AddRef((LPDIRECTSOUNDBUFFER8)*ppdsb);
555 WARN("SecondaryBufferImpl_Create failed\n");
557 WARN("IDirectSoundBufferImpl_Create failed\n");
563 static HRESULT WINAPI IDirectSoundImpl_DuplicateSoundBuffer(
564 LPDIRECTSOUND8 iface,LPDIRECTSOUNDBUFFER8 psb,LPLPDIRECTSOUNDBUFFER8 ppdsb
566 ICOM_THIS(IDirectSoundImpl,iface);
567 IDirectSoundBufferImpl* pdsb;
568 IDirectSoundBufferImpl* dsb;
569 HRESULT hres = DS_OK;
570 TRACE("(%p,%p,%p)\n",This,psb,ppdsb);
573 WARN("invalid parameter: This == NULL\n");
574 return DSERR_INVALIDPARAM;
578 WARN("invalid parameter: psb == NULL\n");
579 return DSERR_INVALIDPARAM;
583 WARN("invalid parameter: ppdsb == NULL\n");
584 return DSERR_INVALIDPARAM;
587 /* FIXME: hack to make sure we have a secondary buffer */
588 if ((DWORD)((SecondaryBufferImpl *)psb)->dsb == (DWORD)This) {
589 ERR("trying to duplicate primary buffer\n");
591 return DSERR_INVALIDCALL;
594 pdsb = ((SecondaryBufferImpl *)psb)->dsb;
597 FIXME("need to duplicate hardware buffer\n");
599 return DSERR_INVALIDCALL;
602 dsb = (IDirectSoundBufferImpl*)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(*dsb));
605 WARN("out of memory\n");
607 return DSERR_OUTOFMEMORY;
610 memcpy(dsb, pdsb, sizeof(IDirectSoundBufferImpl));
612 dsb->state = STATE_STOPPED;
619 dsb->iks = NULL; /* FIXME? */
621 memcpy(&(dsb->wfx), &(pdsb->wfx), sizeof(dsb->wfx));
622 InitializeCriticalSection(&(dsb->lock));
623 /* register buffer */
624 RtlAcquireResourceExclusive(&(This->lock), TRUE);
626 IDirectSoundBufferImpl **newbuffers = (IDirectSoundBufferImpl**)HeapReAlloc(GetProcessHeap(),0,This->buffers,sizeof(IDirectSoundBufferImpl**)*(This->nrofbuffers+1));
628 This->buffers = newbuffers;
629 This->buffers[This->nrofbuffers] = dsb;
631 TRACE("buffer count is now %d\n", This->nrofbuffers);
633 ERR("out of memory for buffer list! Current buffer count is %d\n", This->nrofbuffers);
634 IDirectSoundBuffer8_Release(psb);
635 DeleteCriticalSection(&(dsb->lock));
636 RtlReleaseResource(&(This->lock));
637 HeapFree(GetProcessHeap(),0,dsb);
639 return DSERR_OUTOFMEMORY;
642 RtlReleaseResource(&(This->lock));
643 IDirectSound_AddRef(iface);
644 hres = SecondaryBufferImpl_Create(dsb, (SecondaryBufferImpl**)ppdsb);
646 dsb->dsb = (SecondaryBufferImpl*)*ppdsb;
647 IDirectSoundBuffer_AddRef((LPDIRECTSOUNDBUFFER8)*ppdsb);
649 WARN("SecondaryBufferImpl_Create failed\n");
654 static HRESULT WINAPI IDirectSoundImpl_GetCaps(LPDIRECTSOUND8 iface,LPDSCAPS lpDSCaps) {
655 ICOM_THIS(IDirectSoundImpl,iface);
656 TRACE("(%p,%p)\n",This,lpDSCaps);
659 WARN("invalid parameter: This == NULL\n");
660 return DSERR_INVALIDPARAM;
663 if (lpDSCaps == NULL) {
664 WARN("invalid parameter: lpDSCaps = NULL\n");
665 return DSERR_INVALIDPARAM;
668 /* check is there is enough room */
669 if (lpDSCaps->dwSize < sizeof(*lpDSCaps)) {
670 WARN("invalid parameter: lpDSCaps->dwSize = %ld < %d\n",
671 lpDSCaps->dwSize, sizeof(*lpDSCaps));
672 return DSERR_INVALIDPARAM;
675 lpDSCaps->dwFlags = This->drvcaps.dwFlags;
676 TRACE("(flags=0x%08lx)\n",lpDSCaps->dwFlags);
678 lpDSCaps->dwMinSecondarySampleRate = This->drvcaps.dwMinSecondarySampleRate;
679 lpDSCaps->dwMaxSecondarySampleRate = This->drvcaps.dwMaxSecondarySampleRate;
681 lpDSCaps->dwPrimaryBuffers = This->drvcaps.dwPrimaryBuffers;
683 lpDSCaps->dwMaxHwMixingAllBuffers = This->drvcaps.dwMaxHwMixingAllBuffers;
684 lpDSCaps->dwMaxHwMixingStaticBuffers = This->drvcaps.dwMaxHwMixingStaticBuffers;
685 lpDSCaps->dwMaxHwMixingStreamingBuffers = This->drvcaps.dwMaxHwMixingStreamingBuffers;
687 lpDSCaps->dwFreeHwMixingAllBuffers = This->drvcaps.dwFreeHwMixingAllBuffers;
688 lpDSCaps->dwFreeHwMixingStaticBuffers = This->drvcaps.dwFreeHwMixingStaticBuffers;
689 lpDSCaps->dwFreeHwMixingStreamingBuffers = This->drvcaps.dwFreeHwMixingStreamingBuffers;
691 lpDSCaps->dwMaxHw3DAllBuffers = This->drvcaps.dwMaxHw3DAllBuffers;
692 lpDSCaps->dwMaxHw3DStaticBuffers = This->drvcaps.dwMaxHw3DStaticBuffers;
693 lpDSCaps->dwMaxHw3DStreamingBuffers = This->drvcaps.dwMaxHw3DStreamingBuffers;
695 lpDSCaps->dwFreeHw3DAllBuffers = This->drvcaps.dwFreeHw3DAllBuffers;
696 lpDSCaps->dwFreeHw3DStaticBuffers = This->drvcaps.dwFreeHw3DStaticBuffers;
697 lpDSCaps->dwFreeHw3DStreamingBuffers = This->drvcaps.dwFreeHw3DStreamingBuffers;
699 lpDSCaps->dwTotalHwMemBytes = This->drvcaps.dwTotalHwMemBytes;
701 lpDSCaps->dwFreeHwMemBytes = This->drvcaps.dwFreeHwMemBytes;
703 lpDSCaps->dwMaxContigFreeHwMemBytes = This->drvcaps.dwMaxContigFreeHwMemBytes;
705 /* driver doesn't have these */
706 lpDSCaps->dwUnlockTransferRateHwBuffers = 4096; /* But we have none... */
708 lpDSCaps->dwPlayCpuOverheadSwBuffers = 1; /* 1% */
713 static ULONG WINAPI IDirectSoundImpl_AddRef(LPDIRECTSOUND8 iface) {
714 ICOM_THIS(IDirectSoundImpl,iface);
715 TRACE("(%p) ref was %ld, thread is %04lx\n", This, This->ref, GetCurrentThreadId());
716 return InterlockedIncrement(&This->ref);
719 static ULONG WINAPI IDirectSoundImpl_Release(LPDIRECTSOUND8 iface) {
720 ICOM_THIS(IDirectSoundImpl,iface);
723 TRACE("(%p) ref was %ld, thread is %04lx\n", This, This->ref, GetCurrentThreadId());
724 ulReturn = InterlockedDecrement(&This->ref);
729 timeKillEvent(This->timerID);
730 timeEndPeriod(DS_TIME_RES);
731 /* wait for timer to expire */
732 Sleep(DS_TIME_RES+1);
734 RtlAcquireResourceShared(&(This->lock), TRUE);
737 for( i=0;i<This->nrofbuffers;i++)
738 IDirectSoundBuffer8_Release((LPDIRECTSOUNDBUFFER8)This->buffers[i]);
741 RtlReleaseResource(&(This->lock));
744 WARN("primary buffer not released\n");
745 IDirectSoundBuffer8_Release((LPDIRECTSOUNDBUFFER8)This->primary);
748 hres = DSOUND_PrimaryDestroy(This);
750 WARN("DSOUND_PrimaryDestroy failed\n");
753 IDsDriver_Close(This->driver);
755 if (This->drvdesc.dwFlags & DSDDESC_DOMMSYSTEMOPEN)
756 waveOutClose(This->hwo);
759 IDsDriver_Release(This->driver);
761 RtlDeleteResource(&This->lock);
762 DeleteCriticalSection(&This->mixlock);
763 DeleteCriticalSection(&This->ds3dl_lock);
764 HeapFree(GetProcessHeap(),0,This);
766 TRACE("(%p) released\n",This);
772 static HRESULT WINAPI IDirectSoundImpl_SetSpeakerConfig(
773 LPDIRECTSOUND8 iface,DWORD config
775 ICOM_THIS(IDirectSoundImpl,iface);
776 TRACE("(%p,0x%08lx)\n",This,config);
778 This->speaker_config = config;
780 WARN("not fully functional\n");
784 static HRESULT WINAPI IDirectSoundImpl_QueryInterface(
785 LPDIRECTSOUND8 iface,REFIID riid,LPVOID *ppobj
787 ICOM_THIS(IDirectSoundImpl,iface);
788 TRACE("(%p,%s,%p)\n",This,debugstr_guid(riid),ppobj);
791 WARN("invalid parameter\n");
795 *ppobj = NULL; /* assume failure */
797 if ( IsEqualGUID(riid, &IID_IUnknown) ||
798 IsEqualGUID(riid, &IID_IDirectSound) ||
799 IsEqualGUID(riid, &IID_IDirectSound8) ) {
800 IDirectSound8_AddRef((LPDIRECTSOUND8)This);
805 if ( IsEqualGUID( &IID_IDirectSound3DListener, riid ) ) {
806 WARN("app requested IDirectSound3DListener on dsound object\n");
807 return E_NOINTERFACE;
810 FIXME( "Unknown IID %s\n", debugstr_guid( riid ) );
811 return E_NOINTERFACE;
814 static HRESULT WINAPI IDirectSoundImpl_Compact(
815 LPDIRECTSOUND8 iface)
817 ICOM_THIS(IDirectSoundImpl,iface);
818 TRACE("(%p)\n", This);
822 static HRESULT WINAPI IDirectSoundImpl_GetSpeakerConfig(
823 LPDIRECTSOUND8 iface,
824 LPDWORD lpdwSpeakerConfig)
826 ICOM_THIS(IDirectSoundImpl,iface);
827 TRACE("(%p, %p)\n", This, lpdwSpeakerConfig);
829 if (lpdwSpeakerConfig == NULL) {
830 WARN("invalid parameter\n");
831 return DSERR_INVALIDPARAM;
834 WARN("not fully functional\n");
836 *lpdwSpeakerConfig = This->speaker_config;
841 static HRESULT WINAPI IDirectSoundImpl_Initialize(
842 LPDIRECTSOUND8 iface,
845 ICOM_THIS(IDirectSoundImpl,iface);
846 TRACE("(%p, %s)\n", This, debugstr_guid(lpcGuid));
850 static HRESULT WINAPI IDirectSoundImpl_VerifyCertification(
851 LPDIRECTSOUND8 iface,
852 LPDWORD pdwCertified)
854 ICOM_THIS(IDirectSoundImpl,iface);
855 TRACE("(%p, %p)\n", This, pdwCertified);
856 *pdwCertified = DS_CERTIFIED;
860 static ICOM_VTABLE(IDirectSound8) dsvt =
862 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
863 IDirectSoundImpl_QueryInterface,
864 IDirectSoundImpl_AddRef,
865 IDirectSoundImpl_Release,
866 IDirectSoundImpl_CreateSoundBuffer,
867 IDirectSoundImpl_GetCaps,
868 IDirectSoundImpl_DuplicateSoundBuffer,
869 IDirectSoundImpl_SetCooperativeLevel,
870 IDirectSoundImpl_Compact,
871 IDirectSoundImpl_GetSpeakerConfig,
872 IDirectSoundImpl_SetSpeakerConfig,
873 IDirectSoundImpl_Initialize,
874 IDirectSoundImpl_VerifyCertification
878 /*******************************************************************************
879 * DirectSoundCreate (DSOUND.1)
881 * Creates and initializes a DirectSound interface.
884 * lpcGUID [I] Address of the GUID that identifies the sound device.
885 * ppDS [O] Address of a variable to receive the interface pointer.
886 * pUnkOuter [I] Must be NULL.
890 * Failure: DSERR_ALLOCATED, DSERR_INVALIDPARAM, DSERR_NOAGGREGATION,
891 * DSERR_NODRIVER, DSERR_OUTOFMEMORY
893 HRESULT WINAPI DirectSoundCreate8(LPCGUID lpcGUID,LPDIRECTSOUND8 *ppDS,IUnknown *pUnkOuter )
895 IDirectSoundImpl** ippDS=(IDirectSoundImpl**)ppDS;
896 PIDSDRIVER drv = NULL;
898 HRESULT err = DSERR_INVALIDPARAM;
900 BOOLEAN found = FALSE;
902 TRACE("(%s,%p,%p)\n",debugstr_guid(lpcGUID),ippDS,pUnkOuter);
905 WARN("invalid parameter: ippDS == NULL\n");
906 return DSERR_INVALIDPARAM;
909 /* Get dsound configuration */
910 setup_dsound_options();
912 /* Default device? */
913 if (!lpcGUID || IsEqualGUID(lpcGUID, &GUID_NULL))
914 lpcGUID = &DSDEVID_DefaultPlayback;
916 if (GetDeviceID(lpcGUID, &devGuid) != DS_OK) {
917 WARN("invalid parameter: lpcGUID\n");
919 return DSERR_INVALIDPARAM;
923 if (IsEqualGUID(&devGuid, &dsound->guid) ) {
924 /* FIXME: this is wrong, need to create a new instance */
925 ERR("dsound already opened\n");
926 IDirectSound_AddRef((LPDIRECTSOUND)dsound);
930 ERR("different dsound already opened\n");
934 /* Enumerate WINMM audio devices and find the one we want */
935 wodn = waveOutGetNumDevs();
939 return DSERR_NODRIVER;
942 TRACE(" expecting GUID %s.\n", debugstr_guid(&devGuid));
944 for (wod=0; wod<wodn; wod++) {
946 err = mmErr(waveOutMessage((HWAVEOUT)wod,DRV_QUERYDSOUNDGUID,(DWORD)(&guid),0));
948 WARN("waveOutMessage failed; err=%lx\n",err);
952 TRACE("got GUID %s for wod %d.\n", debugstr_guid(&guid), wod);
953 if (IsEqualGUID( &devGuid, &guid) ) {
961 WARN("invalid parameter\n");
963 return DSERR_INVALIDPARAM;
966 if (found == FALSE) {
967 WARN("No device found matching given ID - trying with default one !\n");
968 wod = ds_default_playback;
971 /* DRV_QUERYDSOUNDIFACE is a "Wine extension" to get the DSound interface */
972 waveOutMessage((HWAVEOUT)wod, DRV_QUERYDSOUNDIFACE, (DWORD)&drv, 0);
974 /* Disable the direct sound driver to force emulation if requested. */
975 if (ds_hw_accel == DS_HW_ACCEL_EMULATION)
978 /* Allocate memory */
979 *ippDS = (IDirectSoundImpl*)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(IDirectSoundImpl));
980 if (*ippDS == NULL) {
981 WARN("out of memory\n");
982 return DSERR_OUTOFMEMORY;
985 (*ippDS)->lpVtbl = &dsvt;
988 (*ippDS)->driver = drv;
989 (*ippDS)->priolevel = DSSCL_NORMAL;
990 (*ippDS)->fraglen = 0;
991 (*ippDS)->hwbuf = NULL;
992 (*ippDS)->buffer = NULL;
993 (*ippDS)->buflen = 0;
994 (*ippDS)->writelead = 0;
995 (*ippDS)->state = STATE_STOPPED;
996 (*ippDS)->nrofbuffers = 0;
997 (*ippDS)->buffers = NULL;
998 (*ippDS)->primary = NULL;
999 (*ippDS)->speaker_config = DSSPEAKER_STEREO | (DSSPEAKER_GEOMETRY_NARROW << 16);
1001 /* 3D listener initial parameters */
1002 (*ippDS)->listener = NULL;
1003 (*ippDS)->ds3dl.dwSize = sizeof(DS3DLISTENER);
1004 (*ippDS)->ds3dl.vPosition.x = 0.0;
1005 (*ippDS)->ds3dl.vPosition.y = 0.0;
1006 (*ippDS)->ds3dl.vPosition.z = 0.0;
1007 (*ippDS)->ds3dl.vVelocity.x = 0.0;
1008 (*ippDS)->ds3dl.vVelocity.y = 0.0;
1009 (*ippDS)->ds3dl.vVelocity.z = 0.0;
1010 (*ippDS)->ds3dl.vOrientFront.x = 0.0;
1011 (*ippDS)->ds3dl.vOrientFront.y = 0.0;
1012 (*ippDS)->ds3dl.vOrientFront.z = 1.0;
1013 (*ippDS)->ds3dl.vOrientTop.x = 0.0;
1014 (*ippDS)->ds3dl.vOrientTop.y = 1.0;
1015 (*ippDS)->ds3dl.vOrientTop.z = 0.0;
1016 (*ippDS)->ds3dl.flDistanceFactor = DS3D_DEFAULTDISTANCEFACTOR;
1017 (*ippDS)->ds3dl.flRolloffFactor = DS3D_DEFAULTROLLOFFFACTOR;
1018 (*ippDS)->ds3dl.flDopplerFactor = DS3D_DEFAULTDOPPLERFACTOR;
1020 InitializeCriticalSection(&(*ippDS)->ds3dl_lock);
1022 (*ippDS)->prebuf = ds_snd_queue_max;
1023 (*ippDS)->guid = devGuid;
1025 /* Get driver description */
1027 err = IDsDriver_GetDriverDesc(drv,&((*ippDS)->drvdesc));
1029 WARN("IDsDriver_GetDriverDesc failed\n");
1030 HeapFree(GetProcessHeap(),0,*ippDS);
1035 /* if no DirectSound interface available, use WINMM API instead */
1036 (*ippDS)->drvdesc.dwFlags = DSDDESC_DOMMSYSTEMOPEN | DSDDESC_DOMMSYSTEMSETFORMAT;
1039 (*ippDS)->drvdesc.dnDevNode = wod;
1041 /* Set default wave format (may need it for waveOutOpen) */
1042 (*ippDS)->wfx.wFormatTag = WAVE_FORMAT_PCM;
1043 /* We rely on the sound driver to return the actual sound format of
1044 * the device if it does not support 22050x8x2 and is given the
1045 * WAVE_DIRECTSOUND flag.
1047 (*ippDS)->wfx.nSamplesPerSec = 22050;
1048 (*ippDS)->wfx.wBitsPerSample = 8;
1049 (*ippDS)->wfx.nChannels = 2;
1050 (*ippDS)->wfx.nBlockAlign = (*ippDS)->wfx.wBitsPerSample * (*ippDS)->wfx.nChannels / 8;
1051 (*ippDS)->wfx.nAvgBytesPerSec = (*ippDS)->wfx.nSamplesPerSec * (*ippDS)->wfx.nBlockAlign;
1052 (*ippDS)->wfx.cbSize = 0;
1054 /* If the driver requests being opened through MMSYSTEM
1055 * (which is recommended by the DDK), it is supposed to happen
1056 * before the DirectSound interface is opened */
1057 if ((*ippDS)->drvdesc.dwFlags & DSDDESC_DOMMSYSTEMOPEN)
1059 DWORD flags = CALLBACK_FUNCTION;
1061 /* disable direct sound if requested */
1062 if (ds_hw_accel != DS_HW_ACCEL_EMULATION)
1063 flags |= WAVE_DIRECTSOUND;
1065 err = mmErr(waveOutOpen(&((*ippDS)->hwo),
1066 (*ippDS)->drvdesc.dnDevNode, &((*ippDS)->wfx),
1067 (DWORD)DSOUND_callback, (DWORD)(*ippDS),
1070 WARN("waveOutOpen failed\n");
1071 HeapFree(GetProcessHeap(),0,*ippDS);
1078 err = IDsDriver_Open(drv);
1080 WARN("IDsDriver_Open failed\n");
1081 HeapFree(GetProcessHeap(),0,*ippDS);
1086 /* the driver is now open, so it's now allowed to call GetCaps */
1087 err = IDsDriver_GetCaps(drv,&((*ippDS)->drvcaps));
1089 WARN("IDsDriver_GetCaps failed\n");
1090 HeapFree(GetProcessHeap(),0,*ippDS);
1096 err = mmErr(waveOutGetDevCapsA((*ippDS)->drvdesc.dnDevNode, &woc, sizeof(woc)));
1098 WARN("waveOutGetDevCaps failed\n");
1099 HeapFree(GetProcessHeap(),0,*ippDS);
1103 ZeroMemory(&(*ippDS)->drvcaps, sizeof((*ippDS)->drvcaps));
1104 if ((woc.dwFormats & WAVE_FORMAT_1M08) ||
1105 (woc.dwFormats & WAVE_FORMAT_2M08) ||
1106 (woc.dwFormats & WAVE_FORMAT_4M08) ||
1107 (woc.dwFormats & WAVE_FORMAT_48M08) ||
1108 (woc.dwFormats & WAVE_FORMAT_96M08)) {
1109 (*ippDS)->drvcaps.dwFlags |= DSCAPS_PRIMARY8BIT;
1110 (*ippDS)->drvcaps.dwFlags |= DSCAPS_PRIMARYMONO;
1112 if ((woc.dwFormats & WAVE_FORMAT_1M16) ||
1113 (woc.dwFormats & WAVE_FORMAT_2M16) ||
1114 (woc.dwFormats & WAVE_FORMAT_4M16) ||
1115 (woc.dwFormats & WAVE_FORMAT_48M16) ||
1116 (woc.dwFormats & WAVE_FORMAT_96M16)) {
1117 (*ippDS)->drvcaps.dwFlags |= DSCAPS_PRIMARY16BIT;
1118 (*ippDS)->drvcaps.dwFlags |= DSCAPS_PRIMARYMONO;
1120 if ((woc.dwFormats & WAVE_FORMAT_1S08) ||
1121 (woc.dwFormats & WAVE_FORMAT_2S08) ||
1122 (woc.dwFormats & WAVE_FORMAT_4S08) ||
1123 (woc.dwFormats & WAVE_FORMAT_48S08) ||
1124 (woc.dwFormats & WAVE_FORMAT_96S08)) {
1125 (*ippDS)->drvcaps.dwFlags |= DSCAPS_PRIMARY8BIT;
1126 (*ippDS)->drvcaps.dwFlags |= DSCAPS_PRIMARYSTEREO;
1128 if ((woc.dwFormats & WAVE_FORMAT_1S16) ||
1129 (woc.dwFormats & WAVE_FORMAT_2S16) ||
1130 (woc.dwFormats & WAVE_FORMAT_4S16) ||
1131 (woc.dwFormats & WAVE_FORMAT_48S16) ||
1132 (woc.dwFormats & WAVE_FORMAT_96S16)) {
1133 (*ippDS)->drvcaps.dwFlags |= DSCAPS_PRIMARY16BIT;
1134 (*ippDS)->drvcaps.dwFlags |= DSCAPS_PRIMARYSTEREO;
1137 (*ippDS)->drvcaps.dwFlags |= DSCAPS_EMULDRIVER;
1138 (*ippDS)->drvcaps.dwMinSecondarySampleRate = DSBFREQUENCY_MIN;
1139 (*ippDS)->drvcaps.dwMaxSecondarySampleRate = DSBFREQUENCY_MAX;
1140 (*ippDS)->drvcaps.dwPrimaryBuffers = 1;
1143 (*ippDS)->volpan.lVolume = 0;
1144 (*ippDS)->volpan.lPan = 0;
1145 DSOUND_RecalcVolPan(&((*ippDS)->volpan));
1147 InitializeCriticalSection(&((*ippDS)->mixlock));
1148 RtlInitializeResource(&((*ippDS)->lock));
1153 hres = DSOUND_PrimaryCreate(dsound);
1154 if (hres != DS_OK) {
1155 WARN("DSOUND_PrimaryCreate failed\n");
1158 timeBeginPeriod(DS_TIME_RES);
1159 dsound->timerID = timeSetEvent(DS_TIME_DEL, DS_TIME_RES, DSOUND_timer,
1160 (DWORD)dsound, TIME_PERIODIC | TIME_CALLBACK_FUNCTION);
1167 /*******************************************************************************
1168 * DirectSound ClassFactory
1171 static HRESULT WINAPI
1172 DSCF_QueryInterface(LPCLASSFACTORY iface,REFIID riid,LPVOID *ppobj) {
1173 ICOM_THIS(IClassFactoryImpl,iface);
1175 FIXME("(%p)->(%s,%p),stub!\n",This,debugstr_guid(riid),ppobj);
1176 return E_NOINTERFACE;
1180 DSCF_AddRef(LPCLASSFACTORY iface) {
1181 ICOM_THIS(IClassFactoryImpl,iface);
1182 TRACE("(%p) ref was %ld\n", This, This->ref);
1183 return ++(This->ref);
1186 static ULONG WINAPI DSCF_Release(LPCLASSFACTORY iface) {
1187 ICOM_THIS(IClassFactoryImpl,iface);
1188 /* static class, won't be freed */
1189 TRACE("(%p) ref was %ld\n", This, This->ref);
1190 return --(This->ref);
1193 static HRESULT WINAPI DSCF_CreateInstance(
1194 LPCLASSFACTORY iface,LPUNKNOWN pOuter,REFIID riid,LPVOID *ppobj
1196 ICOM_THIS(IClassFactoryImpl,iface);
1197 TRACE("(%p)->(%p,%s,%p)\n",This,pOuter,debugstr_guid(riid),ppobj);
1199 if (ppobj == NULL) {
1200 WARN("invalid parameter\n");
1201 return DSERR_INVALIDPARAM;
1206 if ( IsEqualGUID( &IID_IDirectSound, riid ) ||
1207 IsEqualGUID( &IID_IDirectSound8, riid ) ) {
1208 /* FIXME: reuse already created dsound if present? */
1209 return DirectSoundCreate8(0,(LPDIRECTSOUND8*)ppobj,pOuter);
1212 WARN("(%p,%p,%s,%p) Interface not found!\n",This,pOuter,debugstr_guid(riid),ppobj);
1213 return E_NOINTERFACE;
1216 static HRESULT WINAPI DSCF_LockServer(LPCLASSFACTORY iface,BOOL dolock) {
1217 ICOM_THIS(IClassFactoryImpl,iface);
1218 FIXME("(%p)->(%d),stub!\n",This,dolock);
1222 static ICOM_VTABLE(IClassFactory) DSCF_Vtbl = {
1223 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
1224 DSCF_QueryInterface,
1227 DSCF_CreateInstance,
1231 static IClassFactoryImpl DSOUND_CF = { &DSCF_Vtbl, 1 };
1233 /*******************************************************************************
1234 * DirectSoundPrivate ClassFactory
1237 static HRESULT WINAPI
1238 DSPCF_QueryInterface(LPCLASSFACTORY iface,REFIID riid,LPVOID *ppobj) {
1239 ICOM_THIS(IClassFactoryImpl,iface);
1241 FIXME("(%p)->(%s,%p),stub!\n",This,debugstr_guid(riid),ppobj);
1242 return E_NOINTERFACE;
1246 DSPCF_AddRef(LPCLASSFACTORY iface) {
1247 ICOM_THIS(IClassFactoryImpl,iface);
1248 TRACE("(%p) ref was %ld\n", This, This->ref);
1249 return ++(This->ref);
1253 DSPCF_Release(LPCLASSFACTORY iface) {
1254 ICOM_THIS(IClassFactoryImpl,iface);
1255 /* static class, won't be freed */
1256 TRACE("(%p) ref was %ld\n", This, This->ref);
1257 return --(This->ref);
1260 static HRESULT WINAPI
1261 DSPCF_CreateInstance(
1262 LPCLASSFACTORY iface,LPUNKNOWN pOuter,REFIID riid,LPVOID *ppobj
1264 ICOM_THIS(IClassFactoryImpl,iface);
1265 TRACE("(%p)->(%p,%s,%p)\n",This,pOuter,debugstr_guid(riid),ppobj);
1267 if (ppobj == NULL) {
1268 WARN("invalid parameter\n");
1269 return DSERR_INVALIDPARAM;
1274 if ( IsEqualGUID( &IID_IKsPropertySet, riid ) ) {
1275 return IKsPrivatePropertySetImpl_Create((IKsPrivatePropertySetImpl**)ppobj);
1278 WARN("(%p,%p,%s,%p) Interface not found!\n",This,pOuter,debugstr_guid(riid),ppobj);
1279 return E_NOINTERFACE;
1282 static HRESULT WINAPI
1283 DSPCF_LockServer(LPCLASSFACTORY iface,BOOL dolock) {
1284 ICOM_THIS(IClassFactoryImpl,iface);
1285 FIXME("(%p)->(%d),stub!\n",This,dolock);
1289 static ICOM_VTABLE(IClassFactory) DSPCF_Vtbl = {
1290 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
1291 DSPCF_QueryInterface,
1294 DSPCF_CreateInstance,
1298 static IClassFactoryImpl DSOUND_PRIVATE_CF = { &DSPCF_Vtbl, 1 };
1300 /*******************************************************************************
1301 * DllGetClassObject [DSOUND.5]
1302 * Retrieves class object from a DLL object
1305 * Docs say returns STDAPI
1308 * rclsid [I] CLSID for the class object
1309 * riid [I] Reference to identifier of interface for class object
1310 * ppv [O] Address of variable to receive interface pointer for riid
1314 * Failure: CLASS_E_CLASSNOTAVAILABLE, E_OUTOFMEMORY, E_INVALIDARG,
1317 DWORD WINAPI DSOUND_DllGetClassObject(REFCLSID rclsid,REFIID riid,LPVOID *ppv)
1319 TRACE("(%s,%s,%p)\n", debugstr_guid(rclsid), debugstr_guid(riid), ppv);
1322 WARN("invalid parameter\n");
1323 return E_INVALIDARG;
1328 if ( IsEqualCLSID( &CLSID_DirectSound, rclsid ) ||
1329 IsEqualCLSID( &CLSID_DirectSound8, rclsid ) ) {
1330 if ( IsEqualCLSID( &IID_IClassFactory, riid ) ) {
1331 *ppv = (LPVOID)&DSOUND_CF;
1332 IClassFactory_AddRef((IClassFactory*)*ppv);
1335 WARN("(%s,%s,%p): no interface found.\n",
1336 debugstr_guid(rclsid), debugstr_guid(riid), ppv);
1340 if ( IsEqualCLSID( &CLSID_DirectSoundCapture, rclsid ) ||
1341 IsEqualCLSID( &CLSID_DirectSoundCapture8, rclsid ) ) {
1342 if ( IsEqualCLSID( &IID_IClassFactory, riid ) ) {
1343 *ppv = (LPVOID)&DSOUND_CAPTURE_CF;
1344 IClassFactory_AddRef((IClassFactory*)*ppv);
1347 WARN("(%s,%s,%p): no interface found.\n",
1348 debugstr_guid(rclsid), debugstr_guid(riid), ppv);
1352 if ( IsEqualCLSID( &CLSID_DirectSoundFullDuplex, rclsid ) ) {
1353 if ( IsEqualCLSID( &IID_IClassFactory, riid ) ) {
1354 *ppv = (LPVOID)&DSOUND_FULLDUPLEX_CF;
1355 IClassFactory_AddRef((IClassFactory*)*ppv);
1358 WARN("(%s,%s,%p): no interface found.\n",
1359 debugstr_guid(rclsid), debugstr_guid(riid), ppv);
1363 if ( IsEqualCLSID( &CLSID_DirectSoundPrivate, rclsid ) ) {
1364 if ( IsEqualCLSID( &IID_IClassFactory, riid ) ) {
1365 *ppv = (LPVOID)&DSOUND_PRIVATE_CF;
1366 IClassFactory_AddRef((IClassFactory*)*ppv);
1369 WARN("(%s,%s,%p): no interface found.\n",
1370 debugstr_guid(rclsid), debugstr_guid(riid), ppv);
1374 WARN("(%s,%s,%p): no class found.\n", debugstr_guid(rclsid), debugstr_guid(riid), ppv);
1375 return CLASS_E_CLASSNOTAVAILABLE;
1379 /*******************************************************************************
1380 * DllCanUnloadNow [DSOUND.4]
1381 * Determines whether the DLL is in use.
1387 DWORD WINAPI DSOUND_DllCanUnloadNow(void)
1389 FIXME("(void): stub\n");