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
23 #define NONAMELESSSTRUCT
24 #define NONAMELESSUNION
35 #include "wine/debug.h"
37 #include "dsound_private.h"
44 #ifdef NONAMELESSSTRUCT
50 WINE_DEFAULT_DEBUG_CHANNEL(dsound);
52 static WCHAR wInterface[] = { 'I','n','t','e','r','f','a','c','e',0 };
54 typedef struct IKsPrivatePropertySetImpl
56 IKsPropertySet IKsPropertySet_iface;
58 } IKsPrivatePropertySetImpl;
60 static IKsPrivatePropertySetImpl *impl_from_IKsPropertySet(IKsPropertySet *iface)
62 return CONTAINING_RECORD(iface, IKsPrivatePropertySetImpl, IKsPropertySet_iface);
65 /*******************************************************************************
66 * IKsPrivatePropertySet
69 /* IUnknown methods */
70 static HRESULT WINAPI IKsPrivatePropertySetImpl_QueryInterface(
71 LPKSPROPERTYSET iface,
75 IKsPrivatePropertySetImpl *This = impl_from_IKsPropertySet(iface);
76 TRACE("(%p,%s,%p)\n",This,debugstr_guid(riid),ppobj);
78 if (IsEqualIID(riid, &IID_IUnknown) ||
79 IsEqualIID(riid, &IID_IKsPropertySet)) {
81 IUnknown_AddRef(iface);
88 static ULONG WINAPI IKsPrivatePropertySetImpl_AddRef(LPKSPROPERTYSET iface)
90 IKsPrivatePropertySetImpl *This = impl_from_IKsPropertySet(iface);
91 ULONG ref = InterlockedIncrement(&(This->ref));
92 TRACE("(%p) ref was %d\n", This, ref - 1);
96 static ULONG WINAPI IKsPrivatePropertySetImpl_Release(LPKSPROPERTYSET iface)
98 IKsPrivatePropertySetImpl *This = impl_from_IKsPropertySet(iface);
99 ULONG ref = InterlockedDecrement(&(This->ref));
100 TRACE("(%p) ref was %d\n", This, ref + 1);
103 HeapFree(GetProcessHeap(), 0, This);
104 TRACE("(%p) released\n", This);
110 const WCHAR *tgt_name;
114 static BOOL CALLBACK search_callback(GUID *guid, const WCHAR *desc,
115 const WCHAR *module, void *user)
117 struct search_data *search = user;
119 if(!lstrcmpW(desc, search->tgt_name)){
120 *search->found_guid = *guid;
127 static HRESULT DSPROPERTY_WaveDeviceMappingW(
133 PDSPROPERTY_DIRECTSOUNDDEVICE_WAVEDEVICEMAPPING_W_DATA ppd = pPropData;
134 struct search_data search;
136 TRACE("(pPropData=%p,cbPropData=%d,pcbReturned=%p)\n",
137 pPropData,cbPropData,pcbReturned);
140 WARN("invalid parameter: pPropData\n");
141 return DSERR_INVALIDPARAM;
144 search.tgt_name = ppd->DeviceName;
145 search.found_guid = &ppd->DeviceId;
147 if (ppd->DataFlow == DIRECTSOUNDDEVICE_DATAFLOW_RENDER)
148 hr = enumerate_mmdevices(eRender, DSOUND_renderer_guids,
149 search_callback, &search);
150 else if (ppd->DataFlow == DIRECTSOUNDDEVICE_DATAFLOW_CAPTURE)
151 hr = enumerate_mmdevices(eCapture, DSOUND_capture_guids,
152 search_callback, &search);
154 return DSERR_INVALIDPARAM;
157 /* device was not found */
158 return DSERR_INVALIDPARAM;
161 *pcbReturned = cbPropData;
166 static HRESULT DSPROPERTY_WaveDeviceMappingA(
171 DSPROPERTY_DIRECTSOUNDDEVICE_WAVEDEVICEMAPPING_A_DATA *ppd = pPropData;
172 DSPROPERTY_DIRECTSOUNDDEVICE_WAVEDEVICEMAPPING_W_DATA data;
176 TRACE("(pPropData=%p,cbPropData=%d,pcbReturned=%p)\n",
177 pPropData,cbPropData,pcbReturned);
179 if (!ppd || !ppd->DeviceName) {
180 WARN("invalid parameter: ppd=%p\n", ppd);
181 return DSERR_INVALIDPARAM;
184 data.DataFlow = ppd->DataFlow;
185 len = MultiByteToWideChar(CP_ACP, 0, ppd->DeviceName, -1, NULL, 0);
186 data.DeviceName = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
187 if (!data.DeviceName)
188 return E_OUTOFMEMORY;
189 MultiByteToWideChar(CP_ACP, 0, ppd->DeviceName, -1, data.DeviceName, len);
191 hr = DSPROPERTY_WaveDeviceMappingW(&data, cbPropData, pcbReturned);
192 HeapFree(GetProcessHeap(), 0, data.DeviceName);
193 ppd->DeviceId = data.DeviceId;
196 *pcbReturned = cbPropData;
201 static HRESULT DSPROPERTY_DescriptionW(
206 PDSPROPERTY_DIRECTSOUNDDEVICE_DESCRIPTION_W_DATA ppd = pPropData;
214 TRACE("pPropData=%p,cbPropData=%d,pcbReturned=%p)\n",
215 pPropData,cbPropData,pcbReturned);
217 TRACE("DeviceId=%s\n",debugstr_guid(&ppd->DeviceId));
218 if ( IsEqualGUID( &ppd->DeviceId , &GUID_NULL) ) {
219 /* default device of type specified by ppd->DataFlow */
220 if (ppd->DataFlow == DIRECTSOUNDDEVICE_DATAFLOW_CAPTURE) {
221 TRACE("DataFlow=DIRECTSOUNDDEVICE_DATAFLOW_CAPTURE\n");
222 ppd->DeviceId = DSDEVID_DefaultCapture;
223 } else if (ppd->DataFlow == DIRECTSOUNDDEVICE_DATAFLOW_RENDER) {
224 TRACE("DataFlow=DIRECTSOUNDDEVICE_DATAFLOW_RENDER\n");
225 ppd->DeviceId = DSDEVID_DefaultPlayback;
227 WARN("DataFlow=Unknown(%d)\n", ppd->DataFlow);
228 return E_PROP_ID_UNSUPPORTED;
232 setup_dsound_options();
234 GetDeviceID(&ppd->DeviceId, &dev_guid);
236 hr = get_mmdevice(eRender, &dev_guid, &mmdevice);
238 hr = get_mmdevice(eCapture, &dev_guid, &mmdevice);
243 hr = IMMDevice_OpenPropertyStore(mmdevice, STGM_READ, &ps);
245 IMMDevice_Release(mmdevice);
246 WARN("OpenPropertyStore failed: %08x\n", hr);
250 hr = IPropertyStore_GetValue(ps,
251 (const PROPERTYKEY *)&DEVPKEY_Device_FriendlyName, &pv);
253 IPropertyStore_Release(ps);
254 IMMDevice_Release(mmdevice);
255 WARN("GetValue(FriendlyName) failed: %08x\n", hr);
259 desclen = lstrlenW(pv.u.pwszVal) + 1;
260 /* FIXME: Still a memory leak.. */
261 ppd->Description = HeapAlloc(GetProcessHeap(), 0, desclen * sizeof(WCHAR));
262 memcpy(ppd->Description, pv.u.pwszVal, desclen * sizeof(WCHAR));
263 ppd->Module = wine_vxd_drv;
264 ppd->Interface = wInterface;
265 ppd->Type = DIRECTSOUNDDEVICE_TYPE_VXD;
267 PropVariantClear(&pv);
268 IPropertyStore_Release(ps);
269 IMMDevice_Release(mmdevice);
272 *pcbReturned = sizeof(*ppd);
273 TRACE("*pcbReturned=%d\n", *pcbReturned);
280 BOOL CALLBACK enum_callback(GUID *guid, const WCHAR *desc, const WCHAR *module,
283 PDSPROPERTY_DIRECTSOUNDDEVICE_ENUMERATE_W_DATA ppd = user;
284 DSPROPERTY_DIRECTSOUNDDEVICE_DESCRIPTION_W_DATA data;
288 TRACE("%s %s %s %p\n", wine_dbgstr_guid(guid), wine_dbgstr_w(desc),
289 wine_dbgstr_w(module), user);
294 data.DeviceId = *guid;
296 len = lstrlenW(module) + 1;
297 data.Module = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
298 memcpy(data.Module, module, len * sizeof(WCHAR));
300 len = lstrlenW(desc) + 1;
301 data.Description = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
302 memcpy(data.Description, desc, len * sizeof(WCHAR));
304 data.Interface = wInterface;
306 ret = ppd->Callback(&data, ppd->Context);
308 HeapFree(GetProcessHeap(), 0, data.Module);
309 HeapFree(GetProcessHeap(), 0, data.Description);
314 static HRESULT DSPROPERTY_EnumerateW(
319 PDSPROPERTY_DIRECTSOUNDDEVICE_ENUMERATE_W_DATA ppd = pPropData;
322 TRACE("(pPropData=%p,cbPropData=%d,pcbReturned=%p)\n",
323 pPropData,cbPropData,pcbReturned);
328 if (!ppd || !ppd->Callback)
330 WARN("Invalid ppd %p\n", ppd);
331 return E_PROP_ID_UNSUPPORTED;
334 hr = enumerate_mmdevices(eRender, DSOUND_renderer_guids,
338 hr = enumerate_mmdevices(eCapture, DSOUND_capture_guids,
341 return SUCCEEDED(hr) ? DS_OK : hr;
344 static BOOL DSPROPERTY_descWtoA(const DSPROPERTY_DIRECTSOUNDDEVICE_DESCRIPTION_W_DATA *dataW,
345 DSPROPERTY_DIRECTSOUNDDEVICE_DESCRIPTION_A_DATA *dataA)
347 DWORD modlen, desclen;
348 static char Interface[] = "Interface";
350 modlen = WideCharToMultiByte(CP_ACP, 0, dataW->Module, -1, NULL, 0, NULL, NULL);
351 desclen = WideCharToMultiByte(CP_ACP, 0, dataW->Description, -1, NULL, 0, NULL, NULL);
352 dataA->Type = dataW->Type;
353 dataA->DataFlow = dataW->DataFlow;
354 dataA->DeviceId = dataW->DeviceId;
355 dataA->WaveDeviceId = dataW->WaveDeviceId;
356 dataA->Interface = Interface;
357 dataA->Module = HeapAlloc(GetProcessHeap(), 0, modlen);
358 dataA->Description = HeapAlloc(GetProcessHeap(), 0, desclen);
359 if (!dataA->Module || !dataA->Description)
361 HeapFree(GetProcessHeap(), 0, dataA->Module);
362 HeapFree(GetProcessHeap(), 0, dataA->Description);
363 dataA->Module = dataA->Description = NULL;
367 WideCharToMultiByte(CP_ACP, 0, dataW->Module, -1, dataA->Module, modlen, NULL, NULL);
368 WideCharToMultiByte(CP_ACP, 0, dataW->Description, -1, dataA->Description, desclen, NULL, NULL);
372 static void DSPROPERTY_descWto1(const DSPROPERTY_DIRECTSOUNDDEVICE_DESCRIPTION_W_DATA *dataW,
373 DSPROPERTY_DIRECTSOUNDDEVICE_DESCRIPTION_1_DATA *data1)
375 data1->DeviceId = dataW->DeviceId;
376 lstrcpynW(data1->ModuleW, dataW->Module, sizeof(data1->ModuleW)/sizeof(*data1->ModuleW));
377 lstrcpynW(data1->DescriptionW, dataW->Description, sizeof(data1->DescriptionW)/sizeof(*data1->DescriptionW));
378 WideCharToMultiByte(CP_ACP, 0, data1->DescriptionW, -1, data1->DescriptionA, sizeof(data1->DescriptionA)-1, NULL, NULL);
379 WideCharToMultiByte(CP_ACP, 0, data1->ModuleW, -1, data1->ModuleA, sizeof(data1->ModuleA)-1, NULL, NULL);
380 data1->DescriptionA[sizeof(data1->DescriptionA)-1] = 0;
381 data1->ModuleA[sizeof(data1->ModuleA)-1] = 0;
382 data1->Type = dataW->Type;
383 data1->DataFlow = dataW->DataFlow;
384 data1->WaveDeviceId = data1->Devnode = dataW->WaveDeviceId;
387 static BOOL CALLBACK DSPROPERTY_enumWtoA(DSPROPERTY_DIRECTSOUNDDEVICE_DESCRIPTION_W_DATA *descW, void *data)
389 DSPROPERTY_DIRECTSOUNDDEVICE_DESCRIPTION_A_DATA descA;
390 DSPROPERTY_DIRECTSOUNDDEVICE_ENUMERATE_A_DATA *ppd = data;
393 ret = DSPROPERTY_descWtoA(descW, &descA);
396 ret = ppd->Callback(&descA, ppd->Context);
397 HeapFree(GetProcessHeap(), 0, descA.Module);
398 HeapFree(GetProcessHeap(), 0, descA.Description);
402 static HRESULT DSPROPERTY_EnumerateA(
407 DSPROPERTY_DIRECTSOUNDDEVICE_ENUMERATE_A_DATA *ppd = pPropData;
408 DSPROPERTY_DIRECTSOUNDDEVICE_ENUMERATE_W_DATA data;
410 if (!ppd || !ppd->Callback)
412 WARN("Invalid ppd %p\n", ppd);
413 return E_PROP_ID_UNSUPPORTED;
416 data.Callback = DSPROPERTY_enumWtoA;
419 return DSPROPERTY_EnumerateW(&data, cbPropData, pcbReturned);
422 static BOOL CALLBACK DSPROPERTY_enumWto1(DSPROPERTY_DIRECTSOUNDDEVICE_DESCRIPTION_W_DATA *descW, void *data)
424 DSPROPERTY_DIRECTSOUNDDEVICE_DESCRIPTION_1_DATA desc1;
425 DSPROPERTY_DIRECTSOUNDDEVICE_ENUMERATE_1_DATA *ppd = data;
428 DSPROPERTY_descWto1(descW, &desc1);
429 ret = ppd->Callback(&desc1, ppd->Context);
433 static HRESULT DSPROPERTY_Enumerate1(
438 DSPROPERTY_DIRECTSOUNDDEVICE_ENUMERATE_1_DATA *ppd = pPropData;
439 DSPROPERTY_DIRECTSOUNDDEVICE_ENUMERATE_W_DATA data;
441 if (!ppd || !ppd->Callback)
443 WARN("Invalid ppd %p\n", ppd);
444 return E_PROP_ID_UNSUPPORTED;
447 data.Callback = DSPROPERTY_enumWto1;
450 return DSPROPERTY_EnumerateW(&data, cbPropData, pcbReturned);
453 static HRESULT DSPROPERTY_DescriptionA(
458 DSPROPERTY_DIRECTSOUNDDEVICE_DESCRIPTION_W_DATA data;
459 DSPROPERTY_DIRECTSOUNDDEVICE_DESCRIPTION_A_DATA *ppd = pPropData;
463 *pcbReturned = sizeof(*ppd);
467 data.DeviceId = ppd->DeviceId;
468 data.DataFlow = ppd->DataFlow;
469 hr = DSPROPERTY_DescriptionW(&data, sizeof(data), NULL);
472 if (!DSPROPERTY_descWtoA(&data, ppd))
474 HeapFree(GetProcessHeap(), 0, data.Module);
475 HeapFree(GetProcessHeap(), 0, data.Interface);
479 static HRESULT DSPROPERTY_Description1(
484 DSPROPERTY_DIRECTSOUNDDEVICE_DESCRIPTION_W_DATA data;
485 DSPROPERTY_DIRECTSOUNDDEVICE_DESCRIPTION_1_DATA *ppd = pPropData;
489 *pcbReturned = sizeof(*ppd);
493 data.DeviceId = ppd->DeviceId;
494 data.DataFlow = ppd->DataFlow;
495 hr = DSPROPERTY_DescriptionW(&data, sizeof(data), NULL);
498 DSPROPERTY_descWto1(&data, ppd);
499 HeapFree(GetProcessHeap(), 0, data.Module);
500 HeapFree(GetProcessHeap(), 0, data.Interface);
504 static HRESULT WINAPI IKsPrivatePropertySetImpl_Get(
505 LPKSPROPERTYSET iface,
508 LPVOID pInstanceData,
509 ULONG cbInstanceData,
514 IKsPrivatePropertySetImpl *This = impl_from_IKsPropertySet(iface);
515 TRACE("(iface=%p,guidPropSet=%s,dwPropID=%d,pInstanceData=%p,cbInstanceData=%d,pPropData=%p,cbPropData=%d,pcbReturned=%p)\n",
516 This,debugstr_guid(guidPropSet),dwPropID,pInstanceData,cbInstanceData,pPropData,cbPropData,pcbReturned);
518 if ( IsEqualGUID( &DSPROPSETID_DirectSoundDevice, guidPropSet) ) {
520 case DSPROPERTY_DIRECTSOUNDDEVICE_WAVEDEVICEMAPPING_A:
521 return DSPROPERTY_WaveDeviceMappingA(pPropData,cbPropData,pcbReturned);
522 case DSPROPERTY_DIRECTSOUNDDEVICE_DESCRIPTION_1:
523 return DSPROPERTY_Description1(pPropData,cbPropData,pcbReturned);
524 case DSPROPERTY_DIRECTSOUNDDEVICE_ENUMERATE_1:
525 return DSPROPERTY_Enumerate1(pPropData,cbPropData,pcbReturned);
526 case DSPROPERTY_DIRECTSOUNDDEVICE_WAVEDEVICEMAPPING_W:
527 return DSPROPERTY_WaveDeviceMappingW(pPropData,cbPropData,pcbReturned);
528 case DSPROPERTY_DIRECTSOUNDDEVICE_DESCRIPTION_A:
529 return DSPROPERTY_DescriptionA(pPropData,cbPropData,pcbReturned);
530 case DSPROPERTY_DIRECTSOUNDDEVICE_DESCRIPTION_W:
531 return DSPROPERTY_DescriptionW(pPropData,cbPropData,pcbReturned);
532 case DSPROPERTY_DIRECTSOUNDDEVICE_ENUMERATE_A:
533 return DSPROPERTY_EnumerateA(pPropData,cbPropData,pcbReturned);
534 case DSPROPERTY_DIRECTSOUNDDEVICE_ENUMERATE_W:
535 return DSPROPERTY_EnumerateW(pPropData,cbPropData,pcbReturned);
537 FIXME("unsupported ID: %d\n",dwPropID);
541 FIXME("unsupported property: %s\n",debugstr_guid(guidPropSet));
546 FIXME("*pcbReturned=%d\n", *pcbReturned);
549 return E_PROP_ID_UNSUPPORTED;
552 static HRESULT WINAPI IKsPrivatePropertySetImpl_Set(
553 LPKSPROPERTYSET iface,
556 LPVOID pInstanceData,
557 ULONG cbInstanceData,
561 IKsPrivatePropertySetImpl *This = impl_from_IKsPropertySet(iface);
563 FIXME("(%p,%s,%d,%p,%d,%p,%d), stub!\n",This,debugstr_guid(guidPropSet),dwPropID,pInstanceData,cbInstanceData,pPropData,cbPropData);
564 return E_PROP_ID_UNSUPPORTED;
567 static HRESULT WINAPI IKsPrivatePropertySetImpl_QuerySupport(
568 LPKSPROPERTYSET iface,
571 PULONG pTypeSupport )
573 IKsPrivatePropertySetImpl *This = impl_from_IKsPropertySet(iface);
574 TRACE("(%p,%s,%d,%p)\n",This,debugstr_guid(guidPropSet),dwPropID,pTypeSupport);
576 if ( IsEqualGUID( &DSPROPSETID_DirectSoundDevice, guidPropSet) ) {
578 case DSPROPERTY_DIRECTSOUNDDEVICE_WAVEDEVICEMAPPING_A:
579 *pTypeSupport = KSPROPERTY_SUPPORT_GET;
581 case DSPROPERTY_DIRECTSOUNDDEVICE_DESCRIPTION_1:
582 *pTypeSupport = KSPROPERTY_SUPPORT_GET;
584 case DSPROPERTY_DIRECTSOUNDDEVICE_ENUMERATE_1:
585 *pTypeSupport = KSPROPERTY_SUPPORT_GET;
587 case DSPROPERTY_DIRECTSOUNDDEVICE_WAVEDEVICEMAPPING_W:
588 *pTypeSupport = KSPROPERTY_SUPPORT_GET;
590 case DSPROPERTY_DIRECTSOUNDDEVICE_DESCRIPTION_A:
591 *pTypeSupport = KSPROPERTY_SUPPORT_GET;
593 case DSPROPERTY_DIRECTSOUNDDEVICE_DESCRIPTION_W:
594 *pTypeSupport = KSPROPERTY_SUPPORT_GET;
596 case DSPROPERTY_DIRECTSOUNDDEVICE_ENUMERATE_A:
597 *pTypeSupport = KSPROPERTY_SUPPORT_GET;
599 case DSPROPERTY_DIRECTSOUNDDEVICE_ENUMERATE_W:
600 *pTypeSupport = KSPROPERTY_SUPPORT_GET;
603 FIXME("unsupported ID: %d\n",dwPropID);
607 FIXME("unsupported property: %s\n",debugstr_guid(guidPropSet));
610 return E_PROP_ID_UNSUPPORTED;
613 static const IKsPropertySetVtbl ikspvt = {
614 IKsPrivatePropertySetImpl_QueryInterface,
615 IKsPrivatePropertySetImpl_AddRef,
616 IKsPrivatePropertySetImpl_Release,
617 IKsPrivatePropertySetImpl_Get,
618 IKsPrivatePropertySetImpl_Set,
619 IKsPrivatePropertySetImpl_QuerySupport
622 HRESULT IKsPrivatePropertySetImpl_Create(
624 IKsPropertySet **piks)
626 IKsPrivatePropertySetImpl *iks;
627 TRACE("(%s, %p)\n", debugstr_guid(riid), piks);
629 if (!IsEqualIID(riid, &IID_IUnknown) &&
630 !IsEqualIID(riid, &IID_IKsPropertySet)) {
632 return E_NOINTERFACE;
635 iks = HeapAlloc(GetProcessHeap(),0,sizeof(*iks));
637 iks->IKsPropertySet_iface.lpVtbl = &ikspvt;
639 *piks = &iks->IKsPropertySet_iface;