f8b763f9b9fb7e6009ec7276df3c9edbf8698c3e
[reactos.git] / reactos / dll / directx / dsound / dsound_main.c
1 /* DirectSound
2 *
3 * Copyright 1998 Marcus Meissner
4 * Copyright 1998 Rob Riggs
5 * Copyright 2000-2002 TransGaming Technologies, Inc.
6 *
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.
11 *
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.
16 *
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
20 */
21 /*
22 * Most thread locking is complete. There may be a few race
23 * conditions still lurking.
24 *
25 * Tested with a Soundblaster clone, a Gravis UltraSound Classic,
26 * and a Turtle Beach Tropez+.
27 *
28 * TODO:
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
37 */
38
39 #include <stdarg.h>
40
41 #define COBJMACROS
42 #define NONAMELESSSTRUCT
43 #define NONAMELESSUNION
44 #include "windef.h"
45 #include "winbase.h"
46 #include "winnls.h"
47 #include "winreg.h"
48 #include "mmsystem.h"
49 #include "winternl.h"
50 #include "mmddk.h"
51 #include "wine/debug.h"
52 #include "dsound.h"
53 #include "dsdriver.h"
54 #include "dsound_private.h"
55 #include "dsconf.h"
56
57 WINE_DEFAULT_DEBUG_CHANNEL(dsound);
58
59 /* these are eligible for tuning... they must be high on slow machines... */
60 /* some stuff may get more responsive with lower values though... */
61 #define DS_EMULDRIVER 0 /* some games (Quake 2, UT) refuse to accept
62 emulated dsound devices. set to 0 ! */
63 #define DS_HEL_MARGIN 5 /* HEL only: number of waveOut fragments ahead to mix in new buffers
64 * (keep this close or equal to DS_HEL_QUEUE for best results) */
65 #define DS_HEL_QUEUE 5 /* HEL only: number of waveOut fragments ahead to queue to driver
66 * (this will affect HEL sound reliability and latency) */
67
68 #define DS_SND_QUEUE_MAX 28 /* max number of fragments to prebuffer */
69 #define DS_SND_QUEUE_MIN 12 /* min number of fragments to prebuffer */
70
71 DirectSoundDevice* DSOUND_renderer[MAXWAVEDRIVERS];
72 GUID DSOUND_renderer_guids[MAXWAVEDRIVERS];
73 GUID DSOUND_capture_guids[MAXWAVEDRIVERS];
74
75 HRESULT mmErr(UINT err)
76 {
77 switch(err) {
78 case MMSYSERR_NOERROR:
79 return DS_OK;
80 case MMSYSERR_ALLOCATED:
81 return DSERR_ALLOCATED;
82 case MMSYSERR_ERROR:
83 case MMSYSERR_INVALHANDLE:
84 case WAVERR_STILLPLAYING:
85 return DSERR_GENERIC; /* FIXME */
86 case MMSYSERR_NODRIVER:
87 return DSERR_NODRIVER;
88 case MMSYSERR_NOMEM:
89 return DSERR_OUTOFMEMORY;
90 case MMSYSERR_INVALPARAM:
91 case WAVERR_BADFORMAT:
92 case WAVERR_UNPREPARED:
93 return DSERR_INVALIDPARAM;
94 case MMSYSERR_NOTSUPPORTED:
95 return DSERR_UNSUPPORTED;
96 default:
97 FIXME("Unknown MMSYS error %d\n",err);
98 return DSERR_GENERIC;
99 }
100 }
101
102 int ds_emuldriver = DS_EMULDRIVER;
103 int ds_hel_margin = DS_HEL_MARGIN;
104 int ds_hel_queue = DS_HEL_QUEUE;
105 int ds_snd_queue_max = DS_SND_QUEUE_MAX;
106 int ds_snd_queue_min = DS_SND_QUEUE_MIN;
107 int ds_hw_accel = DS_HW_ACCEL_FULL;
108 int ds_default_playback = 0;
109 int ds_default_capture = 0;
110
111 /*
112 * Get a config key from either the app-specific or the default config
113 */
114
115 inline static DWORD get_config_key( HKEY defkey, HKEY appkey, const char *name,
116 char *buffer, DWORD size )
117 {
118 if (appkey && !RegQueryValueExA( appkey, name, 0, NULL, (LPBYTE)buffer, &size )) return 0;
119 if (defkey && !RegQueryValueExA( defkey, name, 0, NULL, (LPBYTE)buffer, &size )) return 0;
120 return ERROR_FILE_NOT_FOUND;
121 }
122
123
124 /*
125 * Setup the dsound options.
126 */
127
128 void setup_dsound_options(void)
129 {
130 char buffer[MAX_PATH+16];
131 HKEY hkey, appkey = 0;
132 DWORD len;
133
134 buffer[MAX_PATH]='\0';
135
136 /* @@ Wine registry key: HKCU\Software\Wine\DirectSound */
137 if (RegOpenKeyA( HKEY_CURRENT_USER, "Software\\Wine\\DirectSound", &hkey )) hkey = 0;
138
139 len = GetModuleFileNameA( 0, buffer, MAX_PATH );
140 if (len && len < MAX_PATH)
141 {
142 HKEY tmpkey;
143 /* @@ Wine registry key: HKCU\Software\Wine\AppDefaults\app.exe\DirectSound */
144 if (!RegOpenKeyA( HKEY_CURRENT_USER, "Software\\Wine\\AppDefaults", &tmpkey ))
145 {
146 char *p, *appname = buffer;
147 if ((p = strrchr( appname, '/' ))) appname = p + 1;
148 if ((p = strrchr( appname, '\\' ))) appname = p + 1;
149 strcat( appname, "\\DirectSound" );
150 TRACE("appname = [%s] \n",appname);
151 if (RegOpenKeyA( tmpkey, appname, &appkey )) appkey = 0;
152 RegCloseKey( tmpkey );
153 }
154 }
155
156 /* get options */
157
158 if (!get_config_key( hkey, appkey, "EmulDriver", buffer, MAX_PATH ))
159 ds_emuldriver = strcmp(buffer, "N");
160
161 if (!get_config_key( hkey, appkey, "HELmargin", buffer, MAX_PATH ))
162 ds_hel_margin = atoi(buffer);
163
164 if (!get_config_key( hkey, appkey, "HELqueue", buffer, MAX_PATH ))
165 ds_hel_queue = atoi(buffer);
166
167 if (!get_config_key( hkey, appkey, "SndQueueMax", buffer, MAX_PATH ))
168 ds_snd_queue_max = atoi(buffer);
169
170 if (!get_config_key( hkey, appkey, "SndQueueMin", buffer, MAX_PATH ))
171 ds_snd_queue_min = atoi(buffer);
172
173 if (!get_config_key( hkey, appkey, "HardwareAcceleration", buffer, MAX_PATH )) {
174 if (strcmp(buffer, "Full") == 0)
175 ds_hw_accel = DS_HW_ACCEL_FULL;
176 else if (strcmp(buffer, "Standard") == 0)
177 ds_hw_accel = DS_HW_ACCEL_STANDARD;
178 else if (strcmp(buffer, "Basic") == 0)
179 ds_hw_accel = DS_HW_ACCEL_BASIC;
180 else if (strcmp(buffer, "Emulation") == 0)
181 ds_hw_accel = DS_HW_ACCEL_EMULATION;
182 }
183 FIXME("dsound is hardcoded to software emulation until we fix it in ros\n");
184 ds_hw_accel = DS_HW_ACCEL_EMULATION;
185
186 if (!get_config_key( hkey, appkey, "DefaultPlayback", buffer, MAX_PATH ))
187 ds_default_playback = atoi(buffer);
188
189 if (!get_config_key( hkey, appkey, "DefaultCapture", buffer, MAX_PATH ))
190 ds_default_capture = atoi(buffer);
191
192 if (appkey) RegCloseKey( appkey );
193 if (hkey) RegCloseKey( hkey );
194
195 if (ds_emuldriver != DS_EMULDRIVER )
196 WARN("ds_emuldriver = %d (default=%d)\n",ds_emuldriver, DS_EMULDRIVER);
197 if (ds_hel_margin != DS_HEL_MARGIN )
198 WARN("ds_hel_margin = %d (default=%d)\n",ds_hel_margin, DS_HEL_MARGIN );
199 if (ds_hel_queue != DS_HEL_QUEUE )
200 WARN("ds_hel_queue = %d (default=%d)\n",ds_hel_queue, DS_HEL_QUEUE );
201 if (ds_snd_queue_max != DS_SND_QUEUE_MAX)
202 WARN("ds_snd_queue_max = %d (default=%d)\n",ds_snd_queue_max ,DS_SND_QUEUE_MAX);
203 if (ds_snd_queue_min != DS_SND_QUEUE_MIN)
204 WARN("ds_snd_queue_min = %d (default=%d)\n",ds_snd_queue_min ,DS_SND_QUEUE_MIN);
205 if (ds_hw_accel != DS_HW_ACCEL_FULL)
206 WARN("ds_hw_accel = %s (default=Full)\n",
207 ds_hw_accel==DS_HW_ACCEL_FULL ? "Full" :
208 ds_hw_accel==DS_HW_ACCEL_STANDARD ? "Standard" :
209 ds_hw_accel==DS_HW_ACCEL_BASIC ? "Basic" :
210 ds_hw_accel==DS_HW_ACCEL_EMULATION ? "Emulation" :
211 "Unknown");
212 if (ds_default_playback != 0)
213 WARN("ds_default_playback = %d (default=0)\n",ds_default_playback);
214 if (ds_default_capture != 0)
215 WARN("ds_default_capture = %d (default=0)\n",ds_default_playback);
216 }
217
218 const char * get_device_id(LPCGUID pGuid)
219 {
220 if (IsEqualGUID(&DSDEVID_DefaultPlayback, pGuid))
221 return "DSDEVID_DefaultPlayback";
222 else if (IsEqualGUID(&DSDEVID_DefaultVoicePlayback, pGuid))
223 return "DSDEVID_DefaultVoicePlayback";
224 else if (IsEqualGUID(&DSDEVID_DefaultCapture, pGuid))
225 return "DSDEVID_DefaultCapture";
226 else if (IsEqualGUID(&DSDEVID_DefaultVoiceCapture, pGuid))
227 return "DSDEVID_DefaultVoiceCapture";
228 return debugstr_guid(pGuid);
229 }
230
231 /***************************************************************************
232 * GetDeviceID [DSOUND.9]
233 *
234 * Retrieves unique identifier of default device specified
235 *
236 * PARAMS
237 * pGuidSrc [I] Address of device GUID.
238 * pGuidDest [O] Address to receive unique device GUID.
239 *
240 * RETURNS
241 * Success: DS_OK
242 * Failure: DSERR_INVALIDPARAM
243 *
244 * NOTES
245 * pGuidSrc is a valid device GUID or DSDEVID_DefaultPlayback,
246 * DSDEVID_DefaultCapture, DSDEVID_DefaultVoicePlayback, or
247 * DSDEVID_DefaultVoiceCapture.
248 * Returns pGuidSrc if pGuidSrc is a valid device or the device
249 * GUID for the specified constants.
250 */
251 HRESULT WINAPI GetDeviceID(LPCGUID pGuidSrc, LPGUID pGuidDest)
252 {
253 TRACE("(%s,%p)\n", get_device_id(pGuidSrc),pGuidDest);
254
255 if ( pGuidSrc == NULL) {
256 WARN("invalid parameter: pGuidSrc == NULL\n");
257 return DSERR_INVALIDPARAM;
258 }
259
260 if ( pGuidDest == NULL ) {
261 WARN("invalid parameter: pGuidDest == NULL\n");
262 return DSERR_INVALIDPARAM;
263 }
264
265 if ( IsEqualGUID( &DSDEVID_DefaultPlayback, pGuidSrc ) ||
266 IsEqualGUID( &DSDEVID_DefaultVoicePlayback, pGuidSrc ) ) {
267 CopyMemory(pGuidDest, &DSOUND_renderer_guids[ds_default_playback], sizeof(GUID));
268 TRACE("returns %s\n", get_device_id(pGuidDest));
269 return DS_OK;
270 }
271
272 if ( IsEqualGUID( &DSDEVID_DefaultCapture, pGuidSrc ) ||
273 IsEqualGUID( &DSDEVID_DefaultVoiceCapture, pGuidSrc ) ) {
274 CopyMemory(pGuidDest, &DSOUND_capture_guids[ds_default_capture], sizeof(GUID));
275 TRACE("returns %s\n", get_device_id(pGuidDest));
276 return DS_OK;
277 }
278
279 CopyMemory(pGuidDest, pGuidSrc, sizeof(GUID));
280 TRACE("returns %s\n", get_device_id(pGuidDest));
281
282 return DS_OK;
283 }
284
285
286 /***************************************************************************
287 * DirectSoundEnumerateA [DSOUND.2]
288 *
289 * Enumerate all DirectSound drivers installed in the system
290 *
291 * PARAMS
292 * lpDSEnumCallback [I] Address of callback function.
293 * lpContext [I] Address of user defined context passed to callback function.
294 *
295 * RETURNS
296 * Success: DS_OK
297 * Failure: DSERR_INVALIDPARAM
298 */
299 HRESULT WINAPI DirectSoundEnumerateA(
300 LPDSENUMCALLBACKA lpDSEnumCallback,
301 LPVOID lpContext)
302 {
303 unsigned devs, wod;
304 DSDRIVERDESC desc;
305 GUID guid;
306 int err;
307
308 TRACE("lpDSEnumCallback = %p, lpContext = %p\n",
309 lpDSEnumCallback, lpContext);
310
311 if (lpDSEnumCallback == NULL) {
312 WARN("invalid parameter: lpDSEnumCallback == NULL\n");
313 return DSERR_INVALIDPARAM;
314 }
315
316 devs = waveOutGetNumDevs();
317 if (devs > 0) {
318 if (GetDeviceID(&DSDEVID_DefaultPlayback, &guid) == DS_OK) {
319 for (wod = 0; wod < devs; ++wod) {
320 if (IsEqualGUID( &guid, &DSOUND_renderer_guids[wod]) ) {
321 err = mmErr(WineWaveOutMessage((HWAVEOUT)wod,DRV_QUERYDSOUNDDESC,(DWORD_PTR)&desc,0));
322 if (err == DS_OK) {
323 TRACE("calling lpDSEnumCallback(NULL,\"%s\",\"%s\",%p)\n",
324 "Primary Sound Driver",desc.szDrvname,lpContext);
325 if (lpDSEnumCallback(NULL, "Primary Sound Driver", desc.szDrvname, lpContext) == FALSE)
326 return DS_OK;
327 }
328 }
329 }
330 }
331 }
332
333 for (wod = 0; wod < devs; ++wod) {
334 err = mmErr(WineWaveOutMessage((HWAVEOUT)wod,DRV_QUERYDSOUNDDESC,(DWORD_PTR)&desc,0));
335 if (err == DS_OK) {
336 TRACE("calling lpDSEnumCallback(%s,\"%s\",\"%s\",%p)\n",
337 debugstr_guid(&DSOUND_renderer_guids[wod]),desc.szDesc,desc.szDrvname,lpContext);
338 if (lpDSEnumCallback(&DSOUND_renderer_guids[wod], desc.szDesc, desc.szDrvname, lpContext) == FALSE)
339 return DS_OK;
340 }
341 }
342 return DS_OK;
343 }
344
345 /***************************************************************************
346 * DirectSoundEnumerateW [DSOUND.3]
347 *
348 * Enumerate all DirectSound drivers installed in the system
349 *
350 * PARAMS
351 * lpDSEnumCallback [I] Address of callback function.
352 * lpContext [I] Address of user defined context passed to callback function.
353 *
354 * RETURNS
355 * Success: DS_OK
356 * Failure: DSERR_INVALIDPARAM
357 */
358 HRESULT WINAPI DirectSoundEnumerateW(
359 LPDSENUMCALLBACKW lpDSEnumCallback,
360 LPVOID lpContext )
361 {
362 unsigned devs, wod;
363 DSDRIVERDESC desc;
364 GUID guid;
365 int err;
366 WCHAR wDesc[MAXPNAMELEN];
367 WCHAR wName[MAXPNAMELEN];
368
369 TRACE("lpDSEnumCallback = %p, lpContext = %p\n",
370 lpDSEnumCallback, lpContext);
371
372 if (lpDSEnumCallback == NULL) {
373 WARN("invalid parameter: lpDSEnumCallback == NULL\n");
374 return DSERR_INVALIDPARAM;
375 }
376
377 devs = waveOutGetNumDevs();
378 if (devs > 0) {
379 if (GetDeviceID(&DSDEVID_DefaultPlayback, &guid) == DS_OK) {
380 for (wod = 0; wod < devs; ++wod) {
381 if (IsEqualGUID( &guid, &DSOUND_renderer_guids[wod] ) ) {
382 err = mmErr(WineWaveOutMessage((HWAVEOUT)wod,DRV_QUERYDSOUNDDESC,(DWORD_PTR)&desc,0));
383 if (err == DS_OK) {
384 TRACE("calling lpDSEnumCallback(NULL,\"%s\",\"%s\",%p)\n",
385 "Primary Sound Driver",desc.szDrvname,lpContext);
386 MultiByteToWideChar( CP_ACP, 0, "Primary Sound Driver", -1,
387 wDesc, sizeof(wDesc)/sizeof(WCHAR) );
388 MultiByteToWideChar( CP_ACP, 0, desc.szDrvname, -1,
389 wName, sizeof(wName)/sizeof(WCHAR) );
390 if (lpDSEnumCallback(NULL, wDesc, wName, lpContext) == FALSE)
391 return DS_OK;
392 }
393 }
394 }
395 }
396 }
397
398 for (wod = 0; wod < devs; ++wod) {
399 err = mmErr(WineWaveOutMessage((HWAVEOUT)wod,DRV_QUERYDSOUNDDESC,(DWORD_PTR)&desc,0));
400 if (err == DS_OK) {
401 TRACE("calling lpDSEnumCallback(%s,\"%s\",\"%s\",%p)\n",
402 debugstr_guid(&DSOUND_renderer_guids[wod]),desc.szDesc,desc.szDrvname,lpContext);
403 MultiByteToWideChar( CP_ACP, 0, desc.szDesc, -1,
404 wDesc, sizeof(wDesc)/sizeof(WCHAR) );
405 MultiByteToWideChar( CP_ACP, 0, desc.szDrvname, -1,
406 wName, sizeof(wName)/sizeof(WCHAR) );
407 if (lpDSEnumCallback(&DSOUND_renderer_guids[wod], wDesc, wName, lpContext) == FALSE)
408 return DS_OK;
409 }
410 }
411 return DS_OK;
412 }
413
414 /*******************************************************************************
415 * DirectSound ClassFactory
416 */
417
418 static HRESULT WINAPI
419 DSCF_QueryInterface(LPCLASSFACTORY iface,REFIID riid,LPVOID *ppobj) {
420 IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
421
422 FIXME("(%p)->(%s,%p),stub!\n",This,debugstr_guid(riid),ppobj);
423 return E_NOINTERFACE;
424 }
425
426 static ULONG WINAPI DSCF_AddRef(LPCLASSFACTORY iface)
427 {
428 IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
429 ULONG ref = InterlockedIncrement(&(This->ref));
430 TRACE("(%p) ref was %ld\n", This, ref - 1);
431 return ref;
432 }
433
434 static ULONG WINAPI DSCF_Release(LPCLASSFACTORY iface)
435 {
436 IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
437 ULONG ref = InterlockedDecrement(&(This->ref));
438 TRACE("(%p) ref was %ld\n", This, ref + 1);
439 /* static class, won't be freed */
440 return ref;
441 }
442
443 static HRESULT WINAPI DSCF_CreateInstance(
444 LPCLASSFACTORY iface,LPUNKNOWN pOuter,REFIID riid,LPVOID *ppobj
445 ) {
446 IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
447 TRACE("(%p)->(%p,%s,%p)\n",This,pOuter,debugstr_guid(riid),ppobj);
448
449 if (pOuter)
450 return CLASS_E_NOAGGREGATION;
451
452 if (ppobj == NULL) {
453 WARN("invalid parameter\n");
454 return DSERR_INVALIDPARAM;
455 }
456
457 *ppobj = NULL;
458
459 if ( IsEqualIID( &IID_IDirectSound, riid ) )
460 return DSOUND_Create((LPDIRECTSOUND*)ppobj,pOuter);
461
462 if ( IsEqualIID( &IID_IDirectSound8, riid ) )
463 return DSOUND_Create8((LPDIRECTSOUND8*)ppobj,pOuter);
464
465 WARN("(%p,%p,%s,%p) Interface not found!\n",This,pOuter,debugstr_guid(riid),ppobj);
466 return E_NOINTERFACE;
467 }
468
469 static HRESULT WINAPI DSCF_LockServer(LPCLASSFACTORY iface,BOOL dolock) {
470 IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
471 FIXME("(%p)->(%d),stub!\n",This,dolock);
472 return S_OK;
473 }
474
475 static const IClassFactoryVtbl DSCF_Vtbl = {
476 DSCF_QueryInterface,
477 DSCF_AddRef,
478 DSCF_Release,
479 DSCF_CreateInstance,
480 DSCF_LockServer
481 };
482
483 static IClassFactoryImpl DSOUND_CF = { &DSCF_Vtbl, 1 };
484
485 /*******************************************************************************
486 * DirectSoundPrivate ClassFactory
487 */
488
489 static HRESULT WINAPI
490 DSPCF_QueryInterface(LPCLASSFACTORY iface,REFIID riid,LPVOID *ppobj) {
491 IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
492
493 FIXME("(%p)->(%s,%p),stub!\n",This,debugstr_guid(riid),ppobj);
494 return E_NOINTERFACE;
495 }
496
497 static ULONG WINAPI DSPCF_AddRef(LPCLASSFACTORY iface)
498 {
499 IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
500 ULONG ref = InterlockedIncrement(&(This->ref));
501 TRACE("(%p) ref was %ld\n", This, ref - 1);
502 return ref;
503 }
504
505 static ULONG WINAPI DSPCF_Release(LPCLASSFACTORY iface)
506 {
507 IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
508 ULONG ref = InterlockedDecrement(&(This->ref));
509 TRACE("(%p) ref was %ld\n", This, ref + 1);
510 /* static class, won't be freed */
511 return ref;
512 }
513
514 static HRESULT WINAPI
515 DSPCF_CreateInstance(
516 LPCLASSFACTORY iface,LPUNKNOWN pOuter,REFIID riid,LPVOID *ppobj
517 ) {
518 IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
519 TRACE("(%p)->(%p,%s,%p)\n",This,pOuter,debugstr_guid(riid),ppobj);
520
521 if (ppobj == NULL) {
522 WARN("invalid parameter\n");
523 return DSERR_INVALIDPARAM;
524 }
525
526 *ppobj = NULL;
527
528 if ( IsEqualGUID( &IID_IKsPropertySet, riid ) ) {
529 return IKsPrivatePropertySetImpl_Create((IKsPrivatePropertySetImpl**)ppobj);
530 }
531
532 WARN("(%p,%p,%s,%p) Interface not found!\n",This,pOuter,debugstr_guid(riid),ppobj);
533 return E_NOINTERFACE;
534 }
535
536 static HRESULT WINAPI
537 DSPCF_LockServer(LPCLASSFACTORY iface,BOOL dolock) {
538 IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
539 FIXME("(%p)->(%d),stub!\n",This,dolock);
540 return S_OK;
541 }
542
543 static const IClassFactoryVtbl DSPCF_Vtbl = {
544 DSPCF_QueryInterface,
545 DSPCF_AddRef,
546 DSPCF_Release,
547 DSPCF_CreateInstance,
548 DSPCF_LockServer
549 };
550
551 static IClassFactoryImpl DSOUND_PRIVATE_CF = { &DSPCF_Vtbl, 1 };
552
553 /*******************************************************************************
554 * DllGetClassObject [DSOUND.@]
555 * Retrieves class object from a DLL object
556 *
557 * NOTES
558 * Docs say returns STDAPI
559 *
560 * PARAMS
561 * rclsid [I] CLSID for the class object
562 * riid [I] Reference to identifier of interface for class object
563 * ppv [O] Address of variable to receive interface pointer for riid
564 *
565 * RETURNS
566 * Success: S_OK
567 * Failure: CLASS_E_CLASSNOTAVAILABLE, E_OUTOFMEMORY, E_INVALIDARG,
568 * E_UNEXPECTED
569 */
570 HRESULT WINAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID *ppv)
571 {
572 TRACE("(%s,%s,%p)\n", debugstr_guid(rclsid), debugstr_guid(riid), ppv);
573
574 if (ppv == NULL) {
575 WARN("invalid parameter\n");
576 return E_INVALIDARG;
577 }
578
579 *ppv = NULL;
580
581 if ( IsEqualCLSID( &CLSID_DirectSound, rclsid ) ||
582 IsEqualCLSID( &CLSID_DirectSound8, rclsid ) ) {
583 if ( IsEqualCLSID( &IID_IClassFactory, riid ) ) {
584 *ppv = (LPVOID)&DSOUND_CF;
585 IClassFactory_AddRef((IClassFactory*)*ppv);
586 return S_OK;
587 }
588 WARN("(%s,%s,%p): no interface found.\n",
589 debugstr_guid(rclsid), debugstr_guid(riid), ppv);
590 return S_FALSE;
591 }
592
593 if ( IsEqualCLSID( &CLSID_DirectSoundCapture, rclsid ) ||
594 IsEqualCLSID( &CLSID_DirectSoundCapture8, rclsid ) ) {
595 if ( IsEqualCLSID( &IID_IClassFactory, riid ) ) {
596 *ppv = (LPVOID)&DSOUND_CAPTURE_CF;
597 IClassFactory_AddRef((IClassFactory*)*ppv);
598 return S_OK;
599 }
600 WARN("(%s,%s,%p): no interface found.\n",
601 debugstr_guid(rclsid), debugstr_guid(riid), ppv);
602 return S_FALSE;
603 }
604
605 if ( IsEqualCLSID( &CLSID_DirectSoundFullDuplex, rclsid ) ) {
606 if ( IsEqualCLSID( &IID_IClassFactory, riid ) ) {
607 *ppv = (LPVOID)&DSOUND_FULLDUPLEX_CF;
608 IClassFactory_AddRef((IClassFactory*)*ppv);
609 return S_OK;
610 }
611 WARN("(%s,%s,%p): no interface found.\n",
612 debugstr_guid(rclsid), debugstr_guid(riid), ppv);
613 return S_FALSE;
614 }
615
616 if ( IsEqualCLSID( &CLSID_DirectSoundPrivate, rclsid ) ) {
617 if ( IsEqualCLSID( &IID_IClassFactory, riid ) ) {
618 *ppv = (LPVOID)&DSOUND_PRIVATE_CF;
619 IClassFactory_AddRef((IClassFactory*)*ppv);
620 return S_OK;
621 }
622 WARN("(%s,%s,%p): no interface found.\n",
623 debugstr_guid(rclsid), debugstr_guid(riid), ppv);
624 return S_FALSE;
625 }
626
627 WARN("(%s,%s,%p): no class found.\n", debugstr_guid(rclsid), debugstr_guid(riid), ppv);
628 return CLASS_E_CLASSNOTAVAILABLE;
629 }
630
631
632 /*******************************************************************************
633 * DllCanUnloadNow [DSOUND.4]
634 * Determines whether the DLL is in use.
635 *
636 * RETURNS
637 * Success: S_OK
638 * Failure: S_FALSE
639 */
640 HRESULT WINAPI DllCanUnloadNow(void)
641 {
642 FIXME("(void): stub\n");
643 return S_FALSE;
644 }
645
646 #define INIT_GUID(guid, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8) \
647 guid.Data1 = l; guid.Data2 = w1; guid.Data3 = w2; \
648 guid.Data4[0] = b1; guid.Data4[1] = b2; guid.Data4[2] = b3; \
649 guid.Data4[3] = b4; guid.Data4[4] = b5; guid.Data4[5] = b6; \
650 guid.Data4[6] = b7; guid.Data4[7] = b8;
651
652 /***********************************************************************
653 * DllMain (DSOUND.init)
654 */
655 BOOL WINAPI DllMain(HINSTANCE hInstDLL, DWORD fdwReason, LPVOID lpvReserved)
656 {
657 int i;
658 TRACE("(%p %ld %p)\n", hInstDLL, fdwReason, lpvReserved);
659
660 switch (fdwReason) {
661 case DLL_PROCESS_ATTACH:
662 TRACE("DLL_PROCESS_ATTACH\n");
663 for (i = 0; i < MAXWAVEDRIVERS; i++) {
664 DSOUND_renderer[i] = NULL;
665 DSOUND_capture[i] = NULL;
666 INIT_GUID(DSOUND_renderer_guids[i], 0xbd6dd71a, 0x3deb, 0x11d1, 0xb1, 0x71, 0x00, 0xc0, 0x4f, 0xc2, 0x00, 0x00 + i);
667 INIT_GUID(DSOUND_capture_guids[i], 0xbd6dd71b, 0x3deb, 0x11d1, 0xb1, 0x71, 0x00, 0xc0, 0x4f, 0xc2, 0x00, 0x00 + i);
668 }
669 break;
670 case DLL_PROCESS_DETACH:
671 TRACE("DLL_PROCESS_DETACH\n");
672 break;
673 case DLL_THREAD_ATTACH:
674 TRACE("DLL_THREAD_ATTACH\n");
675 break;
676 case DLL_THREAD_DETACH:
677 TRACE("DLL_THREAD_DETACH\n");
678 break;
679 default:
680 TRACE("UNKNOWN REASON\n");
681 break;
682 }
683 return TRUE;
684 }