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
33 #include "wine/debug.h"
36 #include "dsound_private.h"
39 #ifdef NONAMELESSSTRUCT
45 WINE_DEFAULT_DEBUG_CHANNEL(dsound);
47 /*******************************************************************************
48 * IKsPrivatePropertySet
51 /* IUnknown methods */
52 static HRESULT WINAPI IKsPrivatePropertySetImpl_QueryInterface(
53 LPKSPROPERTYSET iface,
57 IKsPrivatePropertySetImpl *This = (IKsPrivatePropertySetImpl *)iface;
58 TRACE("(%p,%s,%p)\n",This,debugstr_guid(riid),ppobj);
60 if (IsEqualIID(riid, &IID_IUnknown) ||
61 IsEqualIID(riid, &IID_IKsPropertySet)) {
63 IUnknown_AddRef(iface);
70 static ULONG WINAPI IKsPrivatePropertySetImpl_AddRef(LPKSPROPERTYSET iface)
72 IKsPrivatePropertySetImpl *This = (IKsPrivatePropertySetImpl *)iface;
73 ULONG ref = InterlockedIncrement(&(This->ref));
74 TRACE("(%p) ref was %d\n", This, ref - 1);
78 static ULONG WINAPI IKsPrivatePropertySetImpl_Release(LPKSPROPERTYSET iface)
80 IKsPrivatePropertySetImpl *This = (IKsPrivatePropertySetImpl *)iface;
81 ULONG ref = InterlockedDecrement(&(This->ref));
82 TRACE("(%p) ref was %d\n", This, ref + 1);
85 HeapFree(GetProcessHeap(), 0, This);
86 TRACE("(%p) released\n", This);
91 static HRESULT DSPROPERTY_WaveDeviceMappingW(
96 HRESULT hr = DSERR_INVALIDPARAM;
97 PDSPROPERTY_DIRECTSOUNDDEVICE_WAVEDEVICEMAPPING_W_DATA ppd;
98 TRACE("(pPropData=%p,cbPropData=%d,pcbReturned=%p)\n",
99 pPropData,cbPropData,pcbReturned);
104 WARN("invalid parameter: pPropData\n");
105 return DSERR_INVALIDPARAM;
108 if (ppd->DataFlow == DIRECTSOUNDDEVICE_DATAFLOW_RENDER) {
111 TRACE("DataFlow=DIRECTSOUNDDEVICE_DATAFLOW_RENDER\n");
112 wodn = waveOutGetNumDevs();
113 for (wod = 0; wod < wodn; wod++) {
116 res = waveOutGetDevCapsW(wod, &capsW, sizeof(capsW));
117 if (res == MMSYSERR_NOERROR) {
118 if (lstrcmpW(capsW.szPname, ppd->DeviceName) == 0) {
119 ppd->DeviceId = DSOUND_renderer_guids[wod];
121 TRACE("found %s for %s\n", debugstr_guid(&ppd->DeviceId),
122 debugstr_w(ppd->DeviceName));
127 } else if (ppd->DataFlow == DIRECTSOUNDDEVICE_DATAFLOW_CAPTURE) {
130 TRACE("DataFlow=DIRECTSOUNDDEVICE_DATAFLOW_CAPTURE\n");
131 widn = waveInGetNumDevs();
132 for (wid = 0; wid < widn; wid++) {
135 res = waveInGetDevCapsW(wid, &capsW, sizeof(capsW));
136 if (res == MMSYSERR_NOERROR) {
137 if (lstrcmpW(capsW.szPname, ppd->DeviceName) == 0) {
138 ppd->DeviceId = DSOUND_capture_guids[wid];
140 TRACE("found %s for %s\n", debugstr_guid(&ppd->DeviceId),
141 debugstr_w(ppd->DeviceName));
149 *pcbReturned = cbPropData;
154 static HRESULT DSPROPERTY_WaveDeviceMappingA(
159 DSPROPERTY_DIRECTSOUNDDEVICE_WAVEDEVICEMAPPING_A_DATA *ppd = pPropData;
160 DSPROPERTY_DIRECTSOUNDDEVICE_WAVEDEVICEMAPPING_W_DATA data;
164 TRACE("(pPropData=%p,cbPropData=%d,pcbReturned=%p)\n",
165 pPropData,cbPropData,pcbReturned);
167 if (!ppd || !ppd->DeviceName) {
168 WARN("invalid parameter: ppd=%p\n", ppd);
169 return DSERR_INVALIDPARAM;
172 data.DataFlow = ppd->DataFlow;
173 len = MultiByteToWideChar(CP_ACP, 0, ppd->DeviceName, -1, NULL, 0);
174 data.DeviceName = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
175 if (!data.DeviceName)
176 return E_OUTOFMEMORY;
177 MultiByteToWideChar(CP_ACP, 0, ppd->DeviceName, -1, data.DeviceName, len);
179 hr = DSPROPERTY_WaveDeviceMappingW(&data, cbPropData, pcbReturned);
180 HeapFree(GetProcessHeap(), 0, data.DeviceName);
181 ppd->DeviceId = data.DeviceId;
184 *pcbReturned = cbPropData;
189 static HRESULT DSPROPERTY_DescriptionW(
194 PDSPROPERTY_DIRECTSOUNDDEVICE_DESCRIPTION_W_DATA ppd = pPropData;
197 ULONG wod, wid, wodn, widn;
200 TRACE("pPropData=%p,cbPropData=%d,pcbReturned=%p)\n",
201 pPropData,cbPropData,pcbReturned);
203 TRACE("DeviceId=%s\n",debugstr_guid(&ppd->DeviceId));
204 if ( IsEqualGUID( &ppd->DeviceId , &GUID_NULL) ) {
205 /* default device of type specified by ppd->DataFlow */
206 if (ppd->DataFlow == DIRECTSOUNDDEVICE_DATAFLOW_CAPTURE) {
207 TRACE("DataFlow=DIRECTSOUNDDEVICE_DATAFLOW_CAPTURE\n");
208 ppd->DeviceId = DSDEVID_DefaultCapture;
209 } else if (ppd->DataFlow == DIRECTSOUNDDEVICE_DATAFLOW_RENDER) {
210 TRACE("DataFlow=DIRECTSOUNDDEVICE_DATAFLOW_RENDER\n");
211 ppd->DeviceId = DSDEVID_DefaultPlayback;
213 WARN("DataFlow=Unknown(%d)\n", ppd->DataFlow);
214 return E_PROP_ID_UNSUPPORTED;
218 GetDeviceID(&ppd->DeviceId, &dev_guid);
220 wodn = waveOutGetNumDevs();
221 widn = waveInGetNumDevs();
222 wid = wod = dev_guid.Data4[7];
223 if (!memcmp(&dev_guid, &DSOUND_renderer_guids[0], sizeof(GUID)-1)
226 ppd->DataFlow = DIRECTSOUNDDEVICE_DATAFLOW_RENDER;
227 ppd->WaveDeviceId = wod;
229 else if (!memcmp(&dev_guid, &DSOUND_capture_guids[0], sizeof(GUID)-1)
232 ppd->DataFlow = DIRECTSOUNDDEVICE_DATAFLOW_CAPTURE;
233 ppd->WaveDeviceId = wid;
237 WARN("Device not found\n");
238 return E_PROP_ID_UNSUPPORTED;
241 if (ppd->DataFlow == DIRECTSOUNDDEVICE_DATAFLOW_RENDER)
242 err = waveOutMessage(UlongToHandle(wod),DRV_QUERYDSOUNDDESC,(DWORD_PTR)&desc,0);
244 err = waveInMessage(UlongToHandle(wod),DRV_QUERYDSOUNDDESC,(DWORD_PTR)&desc,0);
246 if (err != MMSYSERR_NOERROR)
248 WARN("waveMessage(DRV_QUERYDSOUNDDESC) failed!\n");
249 return E_PROP_ID_UNSUPPORTED;
253 /* FIXME: Still a memory leak.. */
255 static WCHAR wInterface[] = { 'I','n','t','e','r','f','a','c','e',0 };
257 modlen = MultiByteToWideChar( CP_ACP, 0, desc.szDrvname, -1, NULL, 0 );
258 desclen = MultiByteToWideChar( CP_ACP, 0, desc.szDesc, -1, NULL, 0 );
259 ppd->Module = HeapAlloc(GetProcessHeap(),0,modlen*sizeof(WCHAR));
260 ppd->Description = HeapAlloc(GetProcessHeap(),0,desclen*sizeof(WCHAR));
261 ppd->Interface = wInterface;
262 if (!ppd->Description || !ppd->Module)
264 WARN("Out of memory\n");
265 HeapFree(GetProcessHeap(), 0, ppd->Description);
266 HeapFree(GetProcessHeap(), 0, ppd->Module);
267 ppd->Description = ppd->Module = NULL;
268 return E_OUTOFMEMORY;
271 MultiByteToWideChar( CP_ACP, 0, desc.szDrvname, -1, ppd->Module, modlen );
272 MultiByteToWideChar( CP_ACP, 0, desc.szDesc, -1, ppd->Description, desclen );
275 ppd->Type = DIRECTSOUNDDEVICE_TYPE_VXD;
278 *pcbReturned = sizeof(*ppd);
279 TRACE("*pcbReturned=%d\n", *pcbReturned);
285 static HRESULT DSPROPERTY_EnumerateW(
290 PDSPROPERTY_DIRECTSOUNDDEVICE_ENUMERATE_W_DATA ppd = pPropData;
291 DSPROPERTY_DIRECTSOUNDDEVICE_DESCRIPTION_W_DATA data;
294 TRACE("(pPropData=%p,cbPropData=%d,pcbReturned=%p)\n",
295 pPropData,cbPropData,pcbReturned);
300 if (!ppd || !ppd->Callback)
302 WARN("Invalid ppd %p\n", ppd);
303 return E_PROP_ID_UNSUPPORTED;
306 wodn = waveOutGetNumDevs();
307 widn = waveInGetNumDevs();
309 data.DeviceId = DSOUND_renderer_guids[0];
310 for (i = 0; i < wodn; ++i)
313 data.DeviceId.Data4[7] = i;
314 hr = DSPROPERTY_DescriptionW(&data, sizeof(data), NULL);
317 ERR("DescriptionW failed!\n");
320 ret = ppd->Callback(&data, ppd->Context);
321 HeapFree(GetProcessHeap(), 0, data.Module);
322 HeapFree(GetProcessHeap(), 0, data.Description);
327 data.DeviceId = DSOUND_capture_guids[0];
328 for (i = 0; i < widn; ++i)
331 data.DeviceId.Data4[7] = i;
332 hr = DSPROPERTY_DescriptionW(&data, sizeof(data), NULL);
335 ERR("DescriptionW failed!\n");
338 ret = ppd->Callback(&data, ppd->Context);
339 HeapFree(GetProcessHeap(), 0, data.Module);
340 HeapFree(GetProcessHeap(), 0, data.Description);
347 static BOOL DSPROPERTY_descWtoA(const DSPROPERTY_DIRECTSOUNDDEVICE_DESCRIPTION_W_DATA *dataW,
348 DSPROPERTY_DIRECTSOUNDDEVICE_DESCRIPTION_A_DATA *dataA)
350 DWORD modlen, desclen;
351 static char Interface[] = "Interface";
353 modlen = WideCharToMultiByte(CP_ACP, 0, dataW->Module, -1, NULL, 0, NULL, NULL);
354 desclen = WideCharToMultiByte(CP_ACP, 0, dataW->Description, -1, NULL, 0, NULL, NULL);
355 dataA->Type = dataW->Type;
356 dataA->DataFlow = dataW->DataFlow;
357 dataA->DeviceId = dataW->DeviceId;
358 dataA->WaveDeviceId = dataW->WaveDeviceId;
359 dataA->Interface = Interface;
360 dataA->Module = HeapAlloc(GetProcessHeap(), 0, modlen);
361 dataA->Description = HeapAlloc(GetProcessHeap(), 0, desclen);
362 if (!dataA->Module || !dataA->Description)
364 HeapFree(GetProcessHeap(), 0, dataA->Module);
365 HeapFree(GetProcessHeap(), 0, dataA->Description);
366 dataA->Module = dataA->Description = NULL;
370 WideCharToMultiByte(CP_ACP, 0, dataW->Module, -1, dataA->Module, modlen, NULL, NULL);
371 WideCharToMultiByte(CP_ACP, 0, dataW->Description, -1, dataA->Description, desclen, NULL, NULL);
375 static void DSPROPERTY_descWto1(const DSPROPERTY_DIRECTSOUNDDEVICE_DESCRIPTION_W_DATA *dataW,
376 DSPROPERTY_DIRECTSOUNDDEVICE_DESCRIPTION_1_DATA *data1)
378 data1->DeviceId = dataW->DeviceId;
379 lstrcpynW(data1->ModuleW, dataW->Module, sizeof(data1->ModuleW)/sizeof(*data1->ModuleW));
380 lstrcpynW(data1->DescriptionW, dataW->Description, sizeof(data1->DescriptionW)/sizeof(*data1->DescriptionW));
381 WideCharToMultiByte(CP_ACP, 0, data1->DescriptionW, -1, data1->DescriptionA, sizeof(data1->DescriptionA)-1, NULL, NULL);
382 WideCharToMultiByte(CP_ACP, 0, data1->ModuleW, -1, data1->ModuleA, sizeof(data1->ModuleA)-1, NULL, NULL);
383 data1->DescriptionA[sizeof(data1->DescriptionA)-1] = 0;
384 data1->ModuleA[sizeof(data1->ModuleA)-1] = 0;
385 data1->Type = dataW->Type;
386 data1->DataFlow = dataW->DataFlow;
387 data1->WaveDeviceId = data1->Devnode = dataW->WaveDeviceId;
390 static BOOL CALLBACK DSPROPERTY_enumWtoA(DSPROPERTY_DIRECTSOUNDDEVICE_DESCRIPTION_W_DATA *descW, void *data)
392 DSPROPERTY_DIRECTSOUNDDEVICE_DESCRIPTION_A_DATA descA;
393 DSPROPERTY_DIRECTSOUNDDEVICE_ENUMERATE_A_DATA *ppd = data;
396 ret = DSPROPERTY_descWtoA(descW, &descA);
399 ret = ppd->Callback(&descA, ppd->Context);
400 HeapFree(GetProcessHeap(), 0, descA.Module);
401 HeapFree(GetProcessHeap(), 0, descA.Description);
405 static HRESULT DSPROPERTY_EnumerateA(
410 DSPROPERTY_DIRECTSOUNDDEVICE_ENUMERATE_A_DATA *ppd = pPropData;
411 DSPROPERTY_DIRECTSOUNDDEVICE_ENUMERATE_W_DATA data;
413 if (!ppd || !ppd->Callback)
415 WARN("Invalid ppd %p\n", ppd);
416 return E_PROP_ID_UNSUPPORTED;
419 data.Callback = DSPROPERTY_enumWtoA;
422 return DSPROPERTY_EnumerateW(&data, cbPropData, pcbReturned);
425 static BOOL CALLBACK DSPROPERTY_enumWto1(DSPROPERTY_DIRECTSOUNDDEVICE_DESCRIPTION_W_DATA *descW, void *data)
427 DSPROPERTY_DIRECTSOUNDDEVICE_DESCRIPTION_1_DATA desc1;
428 DSPROPERTY_DIRECTSOUNDDEVICE_ENUMERATE_1_DATA *ppd = data;
431 DSPROPERTY_descWto1(descW, &desc1);
432 ret = ppd->Callback(&desc1, ppd->Context);
436 static HRESULT DSPROPERTY_Enumerate1(
441 DSPROPERTY_DIRECTSOUNDDEVICE_ENUMERATE_1_DATA *ppd = pPropData;
442 DSPROPERTY_DIRECTSOUNDDEVICE_ENUMERATE_W_DATA data;
444 if (!ppd || !ppd->Callback)
446 WARN("Invalid ppd %p\n", ppd);
447 return E_PROP_ID_UNSUPPORTED;
450 data.Callback = DSPROPERTY_enumWto1;
453 return DSPROPERTY_EnumerateW(&data, cbPropData, pcbReturned);
456 static HRESULT DSPROPERTY_DescriptionA(
461 DSPROPERTY_DIRECTSOUNDDEVICE_DESCRIPTION_W_DATA data;
462 DSPROPERTY_DIRECTSOUNDDEVICE_DESCRIPTION_A_DATA *ppd = pPropData;
466 *pcbReturned = sizeof(*ppd);
470 data.DeviceId = ppd->DeviceId;
471 data.DataFlow = ppd->DataFlow;
472 hr = DSPROPERTY_DescriptionW(&data, sizeof(data), NULL);
475 if (!DSPROPERTY_descWtoA(&data, ppd))
477 HeapFree(GetProcessHeap(), 0, data.Module);
478 HeapFree(GetProcessHeap(), 0, data.Interface);
482 static HRESULT DSPROPERTY_Description1(
487 DSPROPERTY_DIRECTSOUNDDEVICE_DESCRIPTION_W_DATA data;
488 DSPROPERTY_DIRECTSOUNDDEVICE_DESCRIPTION_1_DATA *ppd = pPropData;
492 *pcbReturned = sizeof(*ppd);
496 data.DeviceId = ppd->DeviceId;
497 data.DataFlow = ppd->DataFlow;
498 hr = DSPROPERTY_DescriptionW(&data, sizeof(data), NULL);
501 DSPROPERTY_descWto1(&data, ppd);
502 HeapFree(GetProcessHeap(), 0, data.Module);
503 HeapFree(GetProcessHeap(), 0, data.Interface);
507 static HRESULT WINAPI IKsPrivatePropertySetImpl_Get(
508 LPKSPROPERTYSET iface,
511 LPVOID pInstanceData,
512 ULONG cbInstanceData,
517 IKsPrivatePropertySetImpl *This = (IKsPrivatePropertySetImpl *)iface;
518 TRACE("(iface=%p,guidPropSet=%s,dwPropID=%d,pInstanceData=%p,cbInstanceData=%d,pPropData=%p,cbPropData=%d,pcbReturned=%p)\n",
519 This,debugstr_guid(guidPropSet),dwPropID,pInstanceData,cbInstanceData,pPropData,cbPropData,pcbReturned);
521 if ( IsEqualGUID( &DSPROPSETID_DirectSoundDevice, guidPropSet) ) {
523 case DSPROPERTY_DIRECTSOUNDDEVICE_WAVEDEVICEMAPPING_A:
524 return DSPROPERTY_WaveDeviceMappingA(pPropData,cbPropData,pcbReturned);
525 case DSPROPERTY_DIRECTSOUNDDEVICE_DESCRIPTION_1:
526 return DSPROPERTY_Description1(pPropData,cbPropData,pcbReturned);
527 case DSPROPERTY_DIRECTSOUNDDEVICE_ENUMERATE_1:
528 return DSPROPERTY_Enumerate1(pPropData,cbPropData,pcbReturned);
529 case DSPROPERTY_DIRECTSOUNDDEVICE_WAVEDEVICEMAPPING_W:
530 return DSPROPERTY_WaveDeviceMappingW(pPropData,cbPropData,pcbReturned);
531 case DSPROPERTY_DIRECTSOUNDDEVICE_DESCRIPTION_A:
532 return DSPROPERTY_DescriptionA(pPropData,cbPropData,pcbReturned);
533 case DSPROPERTY_DIRECTSOUNDDEVICE_DESCRIPTION_W:
534 return DSPROPERTY_DescriptionW(pPropData,cbPropData,pcbReturned);
535 case DSPROPERTY_DIRECTSOUNDDEVICE_ENUMERATE_A:
536 return DSPROPERTY_EnumerateA(pPropData,cbPropData,pcbReturned);
537 case DSPROPERTY_DIRECTSOUNDDEVICE_ENUMERATE_W:
538 return DSPROPERTY_EnumerateW(pPropData,cbPropData,pcbReturned);
540 FIXME("unsupported ID: %d\n",dwPropID);
544 FIXME("unsupported property: %s\n",debugstr_guid(guidPropSet));
549 FIXME("*pcbReturned=%d\n", *pcbReturned);
552 return E_PROP_ID_UNSUPPORTED;
555 static HRESULT WINAPI IKsPrivatePropertySetImpl_Set(
556 LPKSPROPERTYSET iface,
559 LPVOID pInstanceData,
560 ULONG cbInstanceData,
564 IKsPrivatePropertySetImpl *This = (IKsPrivatePropertySetImpl *)iface;
566 FIXME("(%p,%s,%d,%p,%d,%p,%d), stub!\n",This,debugstr_guid(guidPropSet),dwPropID,pInstanceData,cbInstanceData,pPropData,cbPropData);
567 return E_PROP_ID_UNSUPPORTED;
570 static HRESULT WINAPI IKsPrivatePropertySetImpl_QuerySupport(
571 LPKSPROPERTYSET iface,
574 PULONG pTypeSupport )
576 IKsPrivatePropertySetImpl *This = (IKsPrivatePropertySetImpl *)iface;
577 TRACE("(%p,%s,%d,%p)\n",This,debugstr_guid(guidPropSet),dwPropID,pTypeSupport);
579 if ( IsEqualGUID( &DSPROPSETID_DirectSoundDevice, guidPropSet) ) {
581 case DSPROPERTY_DIRECTSOUNDDEVICE_WAVEDEVICEMAPPING_A:
582 *pTypeSupport = KSPROPERTY_SUPPORT_GET;
584 case DSPROPERTY_DIRECTSOUNDDEVICE_DESCRIPTION_1:
585 *pTypeSupport = KSPROPERTY_SUPPORT_GET;
587 case DSPROPERTY_DIRECTSOUNDDEVICE_ENUMERATE_1:
588 *pTypeSupport = KSPROPERTY_SUPPORT_GET;
590 case DSPROPERTY_DIRECTSOUNDDEVICE_WAVEDEVICEMAPPING_W:
591 *pTypeSupport = KSPROPERTY_SUPPORT_GET;
593 case DSPROPERTY_DIRECTSOUNDDEVICE_DESCRIPTION_A:
594 *pTypeSupport = KSPROPERTY_SUPPORT_GET;
596 case DSPROPERTY_DIRECTSOUNDDEVICE_DESCRIPTION_W:
597 *pTypeSupport = KSPROPERTY_SUPPORT_GET;
599 case DSPROPERTY_DIRECTSOUNDDEVICE_ENUMERATE_A:
600 *pTypeSupport = KSPROPERTY_SUPPORT_GET;
602 case DSPROPERTY_DIRECTSOUNDDEVICE_ENUMERATE_W:
603 *pTypeSupport = KSPROPERTY_SUPPORT_GET;
606 FIXME("unsupported ID: %d\n",dwPropID);
610 FIXME("unsupported property: %s\n",debugstr_guid(guidPropSet));
613 return E_PROP_ID_UNSUPPORTED;
616 static const IKsPropertySetVtbl ikspvt = {
617 IKsPrivatePropertySetImpl_QueryInterface,
618 IKsPrivatePropertySetImpl_AddRef,
619 IKsPrivatePropertySetImpl_Release,
620 IKsPrivatePropertySetImpl_Get,
621 IKsPrivatePropertySetImpl_Set,
622 IKsPrivatePropertySetImpl_QuerySupport
625 HRESULT IKsPrivatePropertySetImpl_Create(
627 IKsPrivatePropertySetImpl **piks)
629 IKsPrivatePropertySetImpl *iks;
630 TRACE("(%s, %p)\n", debugstr_guid(riid), piks);
632 if (!IsEqualIID(riid, &IID_IUnknown) &&
633 !IsEqualIID(riid, &IID_IKsPropertySet)) {
635 return E_NOINTERFACE;
638 iks = HeapAlloc(GetProcessHeap(),0,sizeof(*iks));
640 iks->lpVtbl = &ikspvt;