2 * Copyright 2009 Maarten Lankhorst
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #define NONAMELESSUNION
27 #include "wine/debug.h"
28 #include "wine/list.h"
32 #include "mmdeviceapi.h"
35 #include "audioclient.h"
36 #include "endpointvolume.h"
37 #include "audiopolicy.h"
38 #include "spatialaudioclient.h"
40 #include "mmdevapi_private.h"
43 WINE_DEFAULT_DEBUG_CHANNEL(mmdevapi
);
45 static HKEY key_render
;
46 static HKEY key_capture
;
48 typedef struct MMDevPropStoreImpl
50 IPropertyStore IPropertyStore_iface
;
56 typedef struct MMDevEnumImpl
58 IMMDeviceEnumerator IMMDeviceEnumerator_iface
;
62 static MMDevice
*MMDevice_def_rec
, *MMDevice_def_play
;
63 static const IMMDeviceEnumeratorVtbl MMDevEnumVtbl
;
64 static const IMMDeviceCollectionVtbl MMDevColVtbl
;
65 static const IMMDeviceVtbl MMDeviceVtbl
;
66 static const IPropertyStoreVtbl MMDevPropVtbl
;
67 static const IMMEndpointVtbl MMEndpointVtbl
;
69 static MMDevEnumImpl enumerator
;
70 static struct list device_list
= LIST_INIT(device_list
);
71 static IMMDevice info_device
;
73 typedef struct MMDevColImpl
75 IMMDeviceCollection IMMDeviceCollection_iface
;
81 typedef struct IPropertyBagImpl
{
82 IPropertyBag IPropertyBag_iface
;
86 static const IPropertyBagVtbl PB_Vtbl
;
88 static HRESULT
MMDevPropStore_Create(MMDevice
*This
, DWORD access
, IPropertyStore
**ppv
);
90 static inline MMDevPropStore
*impl_from_IPropertyStore(IPropertyStore
*iface
)
92 return CONTAINING_RECORD(iface
, MMDevPropStore
, IPropertyStore_iface
);
95 static inline MMDevEnumImpl
*impl_from_IMMDeviceEnumerator(IMMDeviceEnumerator
*iface
)
97 return CONTAINING_RECORD(iface
, MMDevEnumImpl
, IMMDeviceEnumerator_iface
);
100 static inline MMDevColImpl
*impl_from_IMMDeviceCollection(IMMDeviceCollection
*iface
)
102 return CONTAINING_RECORD(iface
, MMDevColImpl
, IMMDeviceCollection_iface
);
105 static inline IPropertyBagImpl
*impl_from_IPropertyBag(IPropertyBag
*iface
)
107 return CONTAINING_RECORD(iface
, IPropertyBagImpl
, IPropertyBag_iface
);
110 static const WCHAR propkey_formatW
[] = L
"{%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X},%d";
112 static HRESULT
MMDevPropStore_OpenPropKey(const GUID
*guid
, DWORD flow
, HKEY
*propkey
)
117 StringFromGUID2(guid
, buffer
, 39);
118 if ((ret
= RegOpenKeyExW(flow
== eRender
? key_render
: key_capture
, buffer
, 0, KEY_READ
|KEY_WRITE
|KEY_WOW64_64KEY
, &key
)) != ERROR_SUCCESS
)
120 WARN("Opening key %s failed with %lu\n", debugstr_w(buffer
), ret
);
123 ret
= RegOpenKeyExW(key
, L
"Properties", 0, KEY_READ
|KEY_WRITE
|KEY_WOW64_64KEY
, propkey
);
125 if (ret
!= ERROR_SUCCESS
)
127 WARN("Opening key Properties failed with %lu\n", ret
);
133 static HRESULT
MMDevice_GetPropValue(const GUID
*devguid
, DWORD flow
, REFPROPERTYKEY key
, PROPVARIANT
*pv
)
136 const GUID
*id
= &key
->fmtid
;
142 hr
= MMDevPropStore_OpenPropKey(devguid
, flow
, ®key
);
145 wsprintfW( buffer
, propkey_formatW
, id
->Data1
, id
->Data2
, id
->Data3
,
146 id
->Data4
[0], id
->Data4
[1], id
->Data4
[2], id
->Data4
[3],
147 id
->Data4
[4], id
->Data4
[5], id
->Data4
[6], id
->Data4
[7], key
->pid
);
148 ret
= RegGetValueW(regkey
, NULL
, buffer
, RRF_RT_ANY
, &type
, NULL
, &size
);
149 if (ret
!= ERROR_SUCCESS
)
151 WARN("Reading %s returned %ld\n", debugstr_w(buffer
), ret
);
162 pv
->pwszVal
= CoTaskMemAlloc(size
);
166 RegGetValueW(regkey
, NULL
, buffer
, RRF_RT_REG_SZ
, NULL
, (BYTE
*)pv
->pwszVal
, &size
);
172 RegGetValueW(regkey
, NULL
, buffer
, RRF_RT_REG_DWORD
, NULL
, (BYTE
*)&pv
->ulVal
, &size
);
178 pv
->blob
.cbSize
= size
;
179 pv
->blob
.pBlobData
= CoTaskMemAlloc(size
);
180 if (!pv
->blob
.pBlobData
)
183 RegGetValueW(regkey
, NULL
, buffer
, RRF_RT_REG_BINARY
, NULL
, (BYTE
*)pv
->blob
.pBlobData
, &size
);
187 ERR("Unknown/unhandled type: %lu\n", type
);
188 PropVariantClear(pv
);
195 static HRESULT
MMDevice_SetPropValue(const GUID
*devguid
, DWORD flow
, REFPROPERTYKEY key
, REFPROPVARIANT pv
)
198 const GUID
*id
= &key
->fmtid
;
203 hr
= MMDevPropStore_OpenPropKey(devguid
, flow
, ®key
);
206 wsprintfW( buffer
, propkey_formatW
, id
->Data1
, id
->Data2
, id
->Data3
,
207 id
->Data4
[0], id
->Data4
[1], id
->Data4
[2], id
->Data4
[3],
208 id
->Data4
[4], id
->Data4
[5], id
->Data4
[6], id
->Data4
[7], key
->pid
);
213 ret
= RegSetValueExW(regkey
, buffer
, 0, REG_DWORD
, (const BYTE
*)&pv
->ulVal
, sizeof(DWORD
));
218 ret
= RegSetValueExW(regkey
, buffer
, 0, REG_BINARY
, pv
->blob
.pBlobData
, pv
->blob
.cbSize
);
219 TRACE("Blob %p %lu\n", pv
->blob
.pBlobData
, pv
->blob
.cbSize
);
225 ret
= RegSetValueExW(regkey
, buffer
, 0, REG_SZ
, (const BYTE
*)pv
->pwszVal
, sizeof(WCHAR
)*(1+lstrlenW(pv
->pwszVal
)));
230 FIXME("Unhandled type %u\n", pv
->vt
);
235 TRACE("Writing %s returned %lu\n", debugstr_w(buffer
), ret
);
239 static HRESULT
set_driver_prop_value(GUID
*id
, const EDataFlow flow
, const PROPERTYKEY
*prop
)
244 if (!drvs
.pGetPropValue
)
247 hr
= drvs
.pGetPropValue(id
, prop
, &pv
);
251 MMDevice_SetPropValue(id
, flow
, prop
, &pv
);
252 PropVariantClear(&pv
);
258 struct product_name_overrides
261 const WCHAR
*product
;
264 static const struct product_name_overrides product_name_overrides
[] =
266 /* Sony controllers */
267 { .id
= L
"VID_054C&PID_0CE6", .product
= L
"Wireless Controller" },
270 static const WCHAR
*find_product_name_override(const WCHAR
*device_id
)
272 const WCHAR
*match_id
= wcschr( device_id
, '\\' ) + 1;
275 for (i
= 0; i
< ARRAY_SIZE(product_name_overrides
); ++i
)
276 if (!wcsnicmp( product_name_overrides
[i
].id
, match_id
, 17 ))
277 return product_name_overrides
[i
].product
;
282 /* Creates or updates the state of a device
283 * If GUID is null, a random guid will be assigned
284 * and the device will be created
286 static MMDevice
*MMDevice_Create(WCHAR
*name
, GUID
*id
, EDataFlow flow
, DWORD state
, BOOL setdefault
)
289 MMDevice
*device
, *cur
= NULL
;
292 static const PROPERTYKEY deviceinterface_key
= {
293 {0x233164c8, 0x1b2c, 0x4c7d, {0xbc, 0x68, 0xb6, 0x71, 0x68, 0x7a, 0x25, 0x67}}, 1
296 static const PROPERTYKEY devicepath_key
= {
297 {0xb3f8fa53, 0x0004, 0x438e, {0x90, 0x03, 0x51, 0xa4, 0x6e, 0x13, 0x9b, 0xfc}}, 2
300 LIST_FOR_EACH_ENTRY(device
, &device_list
, MMDevice
, entry
)
302 if (device
->flow
== flow
&& IsEqualGUID(&device
->devguid
, id
)){
309 /* No device found, allocate new one */
310 cur
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*cur
));
314 cur
->IMMDevice_iface
.lpVtbl
= &MMDeviceVtbl
;
315 cur
->IMMEndpoint_iface
.lpVtbl
= &MMEndpointVtbl
;
317 InitializeCriticalSection(&cur
->crst
);
318 cur
->crst
.DebugInfo
->Spare
[0] = (DWORD_PTR
)(__FILE__
": MMDevice.crst");
320 list_add_tail(&device_list
, &cur
->entry
);
321 }else if(cur
->ref
> 0)
322 WARN("Modifying an MMDevice with postitive reference count!\n");
324 HeapFree(GetProcessHeap(), 0, cur
->drv_id
);
331 StringFromGUID2(&cur
->devguid
, guidstr
, ARRAY_SIZE(guidstr
));
338 if (RegCreateKeyExW(root
, guidstr
, 0, NULL
, 0, KEY_WRITE
|KEY_READ
|KEY_WOW64_64KEY
, NULL
, &key
, NULL
) == ERROR_SUCCESS
)
341 RegSetValueExW(key
, L
"DeviceState", 0, REG_DWORD
, (const BYTE
*)&state
, sizeof(DWORD
));
342 if (!RegCreateKeyExW(key
, L
"Properties", 0, NULL
, 0, KEY_WRITE
|KEY_READ
|KEY_WOW64_64KEY
, NULL
, &keyprop
, NULL
))
349 if (SUCCEEDED(set_driver_prop_value(id
, flow
, &devicepath_key
))) {
352 PropVariantInit(&pv2
);
354 if (SUCCEEDED(MMDevice_GetPropValue(id
, flow
, &devicepath_key
, &pv2
)) && pv2
.vt
== VT_LPWSTR
) {
355 const WCHAR
*override
;
356 if ((override
= find_product_name_override(pv2
.pwszVal
)) != NULL
)
357 pv
.pwszVal
= (WCHAR
*) override
;
360 PropVariantClear(&pv2
);
363 MMDevice_SetPropValue(id
, flow
, (const PROPERTYKEY
*)&DEVPKEY_Device_FriendlyName
, &pv
);
364 MMDevice_SetPropValue(id
, flow
, (const PROPERTYKEY
*)&DEVPKEY_DeviceInterface_FriendlyName
, &pv
);
365 MMDevice_SetPropValue(id
, flow
, (const PROPERTYKEY
*)&DEVPKEY_Device_DeviceDesc
, &pv
);
367 pv
.pwszVal
= guidstr
;
368 MMDevice_SetPropValue(id
, flow
, &deviceinterface_key
, &pv
);
370 if (FAILED(set_driver_prop_value(id
, flow
, &PKEY_AudioEndpoint_FormFactor
)))
373 pv
.ulVal
= (flow
== eCapture
) ? Microphone
: Speakers
;
375 MMDevice_SetPropValue(id
, flow
, &PKEY_AudioEndpoint_FormFactor
, &pv
);
378 if (flow
!= eCapture
)
382 PropVariantInit(&pv2
);
384 /* make read-write by not overwriting if already set */
385 if (FAILED(MMDevice_GetPropValue(id
, flow
, &PKEY_AudioEndpoint_PhysicalSpeakers
, &pv2
)) || pv2
.vt
!= VT_UI4
)
386 set_driver_prop_value(id
, flow
, &PKEY_AudioEndpoint_PhysicalSpeakers
);
388 PropVariantClear(&pv2
);
391 RegCloseKey(keyprop
);
399 MMDevice_def_play
= cur
;
401 MMDevice_def_rec
= cur
;
406 HRESULT
load_devices_from_reg(void)
413 ret
= RegCreateKeyExW(HKEY_LOCAL_MACHINE
,
414 L
"Software\\Microsoft\\Windows\\CurrentVersion\\MMDevices\\Audio", 0, NULL
, 0,
415 KEY_WRITE
|KEY_READ
|KEY_WOW64_64KEY
, NULL
, &root
, NULL
);
416 if (ret
== ERROR_SUCCESS
)
417 ret
= RegCreateKeyExW(root
, L
"Capture", 0, NULL
, 0, KEY_READ
|KEY_WRITE
|KEY_WOW64_64KEY
, NULL
, &key_capture
, NULL
);
418 if (ret
== ERROR_SUCCESS
)
419 ret
= RegCreateKeyExW(root
, L
"Render", 0, NULL
, 0, KEY_READ
|KEY_WRITE
|KEY_WOW64_64KEY
, NULL
, &key_render
, NULL
);
423 if (ret
!= ERROR_SUCCESS
)
425 RegCloseKey(key_capture
);
426 key_render
= key_capture
= NULL
;
427 WARN("Couldn't create key: %lu\n", ret
);
435 PROPVARIANT pv
= { VT_EMPTY
};
437 len
= ARRAY_SIZE(guidvalue
);
438 ret
= RegEnumKeyExW(cur
, i
++, guidvalue
, &len
, NULL
, NULL
, NULL
, NULL
);
439 if (ret
== ERROR_NO_MORE_ITEMS
)
441 if (cur
== key_capture
)
450 if (ret
!= ERROR_SUCCESS
)
452 if (SUCCEEDED(CLSIDFromString(guidvalue
, &guid
))
453 && SUCCEEDED(MMDevice_GetPropValue(&guid
, curflow
, (const PROPERTYKEY
*)&DEVPKEY_Device_FriendlyName
, &pv
))
454 && pv
.vt
== VT_LPWSTR
)
456 DWORD size_bytes
= (lstrlenW(pv
.pwszVal
) + 1) * sizeof(WCHAR
);
457 WCHAR
*name
= HeapAlloc(GetProcessHeap(), 0, size_bytes
);
458 memcpy(name
, pv
.pwszVal
, size_bytes
);
459 MMDevice_Create(name
, &guid
, curflow
,
460 DEVICE_STATE_NOTPRESENT
, FALSE
);
461 CoTaskMemFree(pv
.pwszVal
);
468 static HRESULT
set_format(MMDevice
*dev
)
471 IAudioClient
*client
;
473 PROPVARIANT pv
= { VT_EMPTY
};
475 hr
= drvs
.pGetAudioEndpoint(&dev
->devguid
, &dev
->IMMDevice_iface
, &client
);
479 hr
= IAudioClient_GetMixFormat(client
, &fmt
);
481 IAudioClient_Release(client
);
485 IAudioClient_Release(client
);
488 pv
.blob
.cbSize
= sizeof(WAVEFORMATEX
) + fmt
->cbSize
;
489 pv
.blob
.pBlobData
= (BYTE
*)fmt
;
490 MMDevice_SetPropValue(&dev
->devguid
, dev
->flow
,
491 &PKEY_AudioEngine_DeviceFormat
, &pv
);
492 MMDevice_SetPropValue(&dev
->devguid
, dev
->flow
,
493 &PKEY_AudioEngine_OEMFormat
, &pv
);
499 HRESULT
load_driver_devices(EDataFlow flow
)
506 if(!drvs
.pGetEndpointIDs
)
509 hr
= drvs
.pGetEndpointIDs(flow
, &ids
, &guids
, &num
, &def
);
513 for(i
= 0; i
< num
; ++i
){
515 dev
= MMDevice_Create(ids
[i
], &guids
[i
], flow
, DEVICE_STATE_ACTIVE
,
520 HeapFree(GetProcessHeap(), 0, guids
);
521 HeapFree(GetProcessHeap(), 0, ids
);
526 static void MMDevice_Destroy(MMDevice
*This
)
528 TRACE("Freeing %s\n", debugstr_w(This
->drv_id
));
529 list_remove(&This
->entry
);
530 This
->crst
.DebugInfo
->Spare
[0] = 0;
531 DeleteCriticalSection(&This
->crst
);
532 HeapFree(GetProcessHeap(), 0, This
->drv_id
);
533 HeapFree(GetProcessHeap(), 0, This
);
536 static inline MMDevice
*impl_from_IMMDevice(IMMDevice
*iface
)
538 return CONTAINING_RECORD(iface
, MMDevice
, IMMDevice_iface
);
541 static HRESULT WINAPI
MMDevice_QueryInterface(IMMDevice
*iface
, REFIID riid
, void **ppv
)
543 MMDevice
*This
= impl_from_IMMDevice(iface
);
544 TRACE("(%p)->(%s,%p)\n", iface
, debugstr_guid(riid
), ppv
);
549 if (IsEqualIID(riid
, &IID_IUnknown
)
550 || IsEqualIID(riid
, &IID_IMMDevice
))
551 *ppv
= &This
->IMMDevice_iface
;
552 else if (IsEqualIID(riid
, &IID_IMMEndpoint
))
553 *ppv
= &This
->IMMEndpoint_iface
;
556 IUnknown_AddRef((IUnknown
*)*ppv
);
559 WARN("Unknown interface %s\n", debugstr_guid(riid
));
560 return E_NOINTERFACE
;
563 static ULONG WINAPI
MMDevice_AddRef(IMMDevice
*iface
)
565 MMDevice
*This
= impl_from_IMMDevice(iface
);
568 ref
= InterlockedIncrement(&This
->ref
);
569 TRACE("Refcount now %li\n", ref
);
573 static ULONG WINAPI
MMDevice_Release(IMMDevice
*iface
)
575 MMDevice
*This
= impl_from_IMMDevice(iface
);
578 ref
= InterlockedDecrement(&This
->ref
);
579 TRACE("Refcount now %li\n", ref
);
583 static HRESULT WINAPI
MMDevice_Activate(IMMDevice
*iface
, REFIID riid
, DWORD clsctx
, PROPVARIANT
*params
, void **ppv
)
585 HRESULT hr
= E_NOINTERFACE
;
586 MMDevice
*This
= impl_from_IMMDevice(iface
);
588 TRACE("(%p)->(%s, %lx, %p, %p)\n", iface
, debugstr_guid(riid
), clsctx
, params
, ppv
);
593 if (IsEqualIID(riid
, &IID_IAudioClient
) ||
594 IsEqualIID(riid
, &IID_IAudioClient2
) ||
595 IsEqualIID(riid
, &IID_IAudioClient3
)){
596 hr
= drvs
.pGetAudioEndpoint(&This
->devguid
, iface
, (IAudioClient
**)ppv
);
597 }else if (IsEqualIID(riid
, &IID_IAudioEndpointVolume
) ||
598 IsEqualIID(riid
, &IID_IAudioEndpointVolumeEx
))
599 hr
= AudioEndpointVolume_Create(This
, (IAudioEndpointVolumeEx
**)ppv
);
600 else if (IsEqualIID(riid
, &IID_IAudioSessionManager
)
601 || IsEqualIID(riid
, &IID_IAudioSessionManager2
))
603 hr
= AudioSessionManager_Create(iface
, (IAudioSessionManager2
**)ppv
);
605 else if (IsEqualIID(riid
, &IID_IBaseFilter
))
607 if (This
->flow
== eRender
)
608 hr
= CoCreateInstance(&CLSID_DSoundRender
, NULL
, clsctx
, riid
, ppv
);
610 ERR("Not supported for recording?\n");
613 IPersistPropertyBag
*ppb
;
614 hr
= IUnknown_QueryInterface((IUnknown
*)*ppv
, &IID_IPersistPropertyBag
, (void **)&ppb
);
617 /* ::Load cannot assume the interface stays alive after the function returns,
618 * so just create the interface on the stack, saves a lot of complicated code */
619 IPropertyBagImpl bag
= { { &PB_Vtbl
} };
620 bag
.devguid
= This
->devguid
;
621 hr
= IPersistPropertyBag_Load(ppb
, &bag
.IPropertyBag_iface
, NULL
);
622 IPersistPropertyBag_Release(ppb
);
624 IBaseFilter_Release((IBaseFilter
*)*ppv
);
628 FIXME("Wine doesn't support IPersistPropertyBag on DSoundRender yet, ignoring..\n");
633 else if (IsEqualIID(riid
, &IID_IDeviceTopology
))
635 FIXME("IID_IDeviceTopology unsupported\n");
637 else if (IsEqualIID(riid
, &IID_IDirectSound
)
638 || IsEqualIID(riid
, &IID_IDirectSound8
))
640 if (This
->flow
== eRender
)
641 hr
= CoCreateInstance(&CLSID_DirectSound8
, NULL
, clsctx
, riid
, ppv
);
644 hr
= IDirectSound_Initialize((IDirectSound
*)*ppv
, &This
->devguid
);
646 IDirectSound_Release((IDirectSound
*)*ppv
);
649 else if (IsEqualIID(riid
, &IID_IDirectSoundCapture
))
651 if (This
->flow
== eCapture
)
652 hr
= CoCreateInstance(&CLSID_DirectSoundCapture8
, NULL
, clsctx
, riid
, ppv
);
655 hr
= IDirectSoundCapture_Initialize((IDirectSoundCapture
*)*ppv
, &This
->devguid
);
657 IDirectSoundCapture_Release((IDirectSoundCapture
*)*ppv
);
660 else if (IsEqualIID(riid
, &IID_ISpatialAudioClient
))
662 hr
= SpatialAudioClient_Create(iface
, (ISpatialAudioClient
**)ppv
);
665 ERR("Invalid/unknown iid %s\n", debugstr_guid(riid
));
670 TRACE("Returning %08lx\n", hr
);
674 static HRESULT WINAPI
MMDevice_OpenPropertyStore(IMMDevice
*iface
, DWORD access
, IPropertyStore
**ppv
)
676 MMDevice
*This
= impl_from_IMMDevice(iface
);
677 TRACE("(%p)->(%lx,%p)\n", This
, access
, ppv
);
681 return MMDevPropStore_Create(This
, access
, ppv
);
684 static HRESULT WINAPI
MMDevice_GetId(IMMDevice
*iface
, WCHAR
**itemid
)
686 MMDevice
*This
= impl_from_IMMDevice(iface
);
688 GUID
*id
= &This
->devguid
;
690 TRACE("(%p)->(%p)\n", This
, itemid
);
693 *itemid
= str
= CoTaskMemAlloc(56 * sizeof(WCHAR
));
695 return E_OUTOFMEMORY
;
696 wsprintfW(str
, L
"{0.0.%u.00000000}.{%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X}",
697 This
->flow
, id
->Data1
, id
->Data2
, id
->Data3
,
698 id
->Data4
[0], id
->Data4
[1], id
->Data4
[2], id
->Data4
[3],
699 id
->Data4
[4], id
->Data4
[5], id
->Data4
[6], id
->Data4
[7]);
700 TRACE("returning %s\n", wine_dbgstr_w(str
));
704 static HRESULT WINAPI
MMDevice_GetState(IMMDevice
*iface
, DWORD
*state
)
706 MMDevice
*This
= impl_from_IMMDevice(iface
);
707 TRACE("(%p)->(%p)\n", iface
, state
);
711 *state
= This
->state
;
715 static const IMMDeviceVtbl MMDeviceVtbl
=
717 MMDevice_QueryInterface
,
721 MMDevice_OpenPropertyStore
,
726 static inline MMDevice
*impl_from_IMMEndpoint(IMMEndpoint
*iface
)
728 return CONTAINING_RECORD(iface
, MMDevice
, IMMEndpoint_iface
);
731 static HRESULT WINAPI
MMEndpoint_QueryInterface(IMMEndpoint
*iface
, REFIID riid
, void **ppv
)
733 MMDevice
*This
= impl_from_IMMEndpoint(iface
);
734 TRACE("(%p)->(%s, %p)\n", This
, debugstr_guid(riid
), ppv
);
735 return IMMDevice_QueryInterface(&This
->IMMDevice_iface
, riid
, ppv
);
738 static ULONG WINAPI
MMEndpoint_AddRef(IMMEndpoint
*iface
)
740 MMDevice
*This
= impl_from_IMMEndpoint(iface
);
741 TRACE("(%p)\n", This
);
742 return IMMDevice_AddRef(&This
->IMMDevice_iface
);
745 static ULONG WINAPI
MMEndpoint_Release(IMMEndpoint
*iface
)
747 MMDevice
*This
= impl_from_IMMEndpoint(iface
);
748 TRACE("(%p)\n", This
);
749 return IMMDevice_Release(&This
->IMMDevice_iface
);
752 static HRESULT WINAPI
MMEndpoint_GetDataFlow(IMMEndpoint
*iface
, EDataFlow
*flow
)
754 MMDevice
*This
= impl_from_IMMEndpoint(iface
);
755 TRACE("(%p)->(%p)\n", This
, flow
);
762 static const IMMEndpointVtbl MMEndpointVtbl
=
764 MMEndpoint_QueryInterface
,
767 MMEndpoint_GetDataFlow
770 static HRESULT
MMDevCol_Create(IMMDeviceCollection
**ppv
, EDataFlow flow
, DWORD state
)
774 This
= HeapAlloc(GetProcessHeap(), 0, sizeof(*This
));
777 return E_OUTOFMEMORY
;
778 This
->IMMDeviceCollection_iface
.lpVtbl
= &MMDevColVtbl
;
782 *ppv
= &This
->IMMDeviceCollection_iface
;
786 static void MMDevCol_Destroy(MMDevColImpl
*This
)
788 HeapFree(GetProcessHeap(), 0, This
);
791 static HRESULT WINAPI
MMDevCol_QueryInterface(IMMDeviceCollection
*iface
, REFIID riid
, void **ppv
)
793 MMDevColImpl
*This
= impl_from_IMMDeviceCollection(iface
);
794 TRACE("(%p)->(%s, %p)\n", This
, debugstr_guid(riid
), ppv
);
798 if (IsEqualIID(riid
, &IID_IUnknown
)
799 || IsEqualIID(riid
, &IID_IMMDeviceCollection
))
800 *ppv
= &This
->IMMDeviceCollection_iface
;
804 return E_NOINTERFACE
;
805 IUnknown_AddRef((IUnknown
*)*ppv
);
809 static ULONG WINAPI
MMDevCol_AddRef(IMMDeviceCollection
*iface
)
811 MMDevColImpl
*This
= impl_from_IMMDeviceCollection(iface
);
812 LONG ref
= InterlockedIncrement(&This
->ref
);
813 TRACE("Refcount now %li\n", ref
);
817 static ULONG WINAPI
MMDevCol_Release(IMMDeviceCollection
*iface
)
819 MMDevColImpl
*This
= impl_from_IMMDeviceCollection(iface
);
820 LONG ref
= InterlockedDecrement(&This
->ref
);
821 TRACE("Refcount now %li\n", ref
);
823 MMDevCol_Destroy(This
);
827 static HRESULT WINAPI
MMDevCol_GetCount(IMMDeviceCollection
*iface
, UINT
*numdevs
)
829 MMDevColImpl
*This
= impl_from_IMMDeviceCollection(iface
);
832 TRACE("(%p)->(%p)\n", This
, numdevs
);
837 LIST_FOR_EACH_ENTRY(cur
, &device_list
, MMDevice
, entry
)
839 if ((cur
->flow
== This
->flow
|| This
->flow
== eAll
)
840 && (cur
->state
& This
->state
))
846 static HRESULT WINAPI
MMDevCol_Item(IMMDeviceCollection
*iface
, UINT n
, IMMDevice
**dev
)
848 MMDevColImpl
*This
= impl_from_IMMDeviceCollection(iface
);
852 TRACE("(%p)->(%u, %p)\n", This
, n
, dev
);
856 LIST_FOR_EACH_ENTRY(cur
, &device_list
, MMDevice
, entry
)
858 if ((cur
->flow
== This
->flow
|| This
->flow
== eAll
)
859 && (cur
->state
& This
->state
)
862 *dev
= &cur
->IMMDevice_iface
;
863 IMMDevice_AddRef(*dev
);
867 WARN("Could not obtain item %u\n", n
);
872 static const IMMDeviceCollectionVtbl MMDevColVtbl
=
874 MMDevCol_QueryInterface
,
881 HRESULT
MMDevEnum_Create(REFIID riid
, void **ppv
)
883 return IMMDeviceEnumerator_QueryInterface(&enumerator
.IMMDeviceEnumerator_iface
, riid
, ppv
);
886 void MMDevEnum_Free(void)
888 MMDevice
*device
, *next
;
889 LIST_FOR_EACH_ENTRY_SAFE(device
, next
, &device_list
, MMDevice
, entry
)
890 MMDevice_Destroy(device
);
891 RegCloseKey(key_render
);
892 RegCloseKey(key_capture
);
893 key_render
= key_capture
= NULL
;
896 static HRESULT WINAPI
MMDevEnum_QueryInterface(IMMDeviceEnumerator
*iface
, REFIID riid
, void **ppv
)
898 MMDevEnumImpl
*This
= impl_from_IMMDeviceEnumerator(iface
);
899 TRACE("(%p)->(%s, %p)\n", This
, debugstr_guid(riid
), ppv
);
903 if (IsEqualIID(riid
, &IID_IUnknown
)
904 || IsEqualIID(riid
, &IID_IMMDeviceEnumerator
))
905 *ppv
= &This
->IMMDeviceEnumerator_iface
;
909 return E_NOINTERFACE
;
910 IUnknown_AddRef((IUnknown
*)*ppv
);
914 static ULONG WINAPI
MMDevEnum_AddRef(IMMDeviceEnumerator
*iface
)
916 MMDevEnumImpl
*This
= impl_from_IMMDeviceEnumerator(iface
);
917 LONG ref
= InterlockedIncrement(&This
->ref
);
918 TRACE("Refcount now %li\n", ref
);
922 static ULONG WINAPI
MMDevEnum_Release(IMMDeviceEnumerator
*iface
)
924 MMDevEnumImpl
*This
= impl_from_IMMDeviceEnumerator(iface
);
925 LONG ref
= InterlockedDecrement(&This
->ref
);
926 TRACE("Refcount now %li\n", ref
);
930 static HRESULT WINAPI
MMDevEnum_EnumAudioEndpoints(IMMDeviceEnumerator
*iface
, EDataFlow flow
, DWORD mask
, IMMDeviceCollection
**devices
)
932 MMDevEnumImpl
*This
= impl_from_IMMDeviceEnumerator(iface
);
933 TRACE("(%p)->(%u,%lu,%p)\n", This
, flow
, mask
, devices
);
937 if (flow
>= EDataFlow_enum_count
)
939 if (mask
& ~DEVICE_STATEMASK_ALL
)
941 return MMDevCol_Create(devices
, flow
, mask
);
944 static HRESULT WINAPI
MMDevEnum_GetDefaultAudioEndpoint(IMMDeviceEnumerator
*iface
, EDataFlow flow
, ERole role
, IMMDevice
**device
)
946 MMDevEnumImpl
*This
= impl_from_IMMDeviceEnumerator(iface
);
951 TRACE("(%p)->(%u,%u,%p)\n", This
, flow
, role
, device
);
956 if((flow
!= eRender
&& flow
!= eCapture
) ||
957 (role
!= eConsole
&& role
!= eMultimedia
&& role
!= eCommunications
)){
958 WARN("Unknown flow (%u) or role (%u)\n", flow
, role
);
964 if(!drvs
.module_name
[0])
967 lstrcpyW(reg_key
, drv_keyW
);
968 lstrcatW(reg_key
, L
"\\");
969 lstrcatW(reg_key
, drvs
.module_name
);
971 if(RegOpenKeyW(HKEY_CURRENT_USER
, reg_key
, &key
) == ERROR_SUCCESS
){
972 const WCHAR
*reg_x_name
, *reg_vx_name
;
974 DWORD size
= sizeof(def_id
), state
;
977 reg_x_name
= L
"DefaultOutput";
978 reg_vx_name
= L
"DefaultVoiceOutput";
980 reg_x_name
= L
"DefaultInput";
981 reg_vx_name
= L
"DefaultVoiceInput";
984 if(role
== eCommunications
&&
985 RegQueryValueExW(key
, reg_vx_name
, 0, NULL
,
986 (BYTE
*)def_id
, &size
) == ERROR_SUCCESS
){
987 hr
= IMMDeviceEnumerator_GetDevice(iface
, def_id
, device
);
989 if(SUCCEEDED(IMMDevice_GetState(*device
, &state
)) &&
990 state
== DEVICE_STATE_ACTIVE
){
996 TRACE("Unable to find voice device %s\n", wine_dbgstr_w(def_id
));
999 if(RegQueryValueExW(key
, reg_x_name
, 0, NULL
,
1000 (BYTE
*)def_id
, &size
) == ERROR_SUCCESS
){
1001 hr
= IMMDeviceEnumerator_GetDevice(iface
, def_id
, device
);
1003 if(SUCCEEDED(IMMDevice_GetState(*device
, &state
)) &&
1004 state
== DEVICE_STATE_ACTIVE
){
1010 TRACE("Unable to find device %s\n", wine_dbgstr_w(def_id
));
1016 if (flow
== eRender
)
1017 *device
= &MMDevice_def_play
->IMMDevice_iface
;
1019 *device
= &MMDevice_def_rec
->IMMDevice_iface
;
1023 IMMDevice_AddRef(*device
);
1027 static HRESULT WINAPI
MMDevEnum_GetDevice(IMMDeviceEnumerator
*iface
, const WCHAR
*name
, IMMDevice
**device
)
1029 MMDevEnumImpl
*This
= impl_from_IMMDeviceEnumerator(iface
);
1031 IMMDevice
*dev
= NULL
;
1033 TRACE("(%p)->(%s,%p)\n", This
, debugstr_w(name
), device
);
1035 if(!name
|| !device
)
1038 if(!lstrcmpW(name
, L
"Wine info device")){
1039 *device
= &info_device
;
1043 LIST_FOR_EACH_ENTRY(impl
, &device_list
, MMDevice
, entry
)
1047 dev
= &impl
->IMMDevice_iface
;
1048 hr
= IMMDevice_GetId(dev
, &str
);
1051 WARN("GetId failed: %08lx\n", hr
);
1055 if (str
&& !lstrcmpW(str
, name
))
1058 IMMDevice_AddRef(dev
);
1064 TRACE("Could not find device %s\n", debugstr_w(name
));
1065 return E_INVALIDARG
;
1068 struct NotificationClientWrapper
{
1069 IMMNotificationClient
*client
;
1073 static struct list g_notif_clients
= LIST_INIT(g_notif_clients
);
1074 static HANDLE g_notif_thread
;
1076 static CRITICAL_SECTION g_notif_lock
;
1077 static CRITICAL_SECTION_DEBUG g_notif_lock_debug
=
1079 0, 0, &g_notif_lock
,
1080 { &g_notif_lock_debug
.ProcessLocksList
, &g_notif_lock_debug
.ProcessLocksList
},
1081 0, 0, { (DWORD_PTR
)(__FILE__
": g_notif_lock") }
1083 static CRITICAL_SECTION g_notif_lock
= { &g_notif_lock_debug
, -1, 0, 0, 0, 0 };
1085 static void notify_clients(EDataFlow flow
, ERole role
, const WCHAR
*id
)
1087 struct NotificationClientWrapper
*wrapper
;
1088 LIST_FOR_EACH_ENTRY(wrapper
, &g_notif_clients
,
1089 struct NotificationClientWrapper
, entry
)
1090 IMMNotificationClient_OnDefaultDeviceChanged(wrapper
->client
, flow
,
1093 /* Windows 7 treats changes to eConsole as changes to eMultimedia */
1094 if(role
== eConsole
)
1095 notify_clients(flow
, eMultimedia
, id
);
1098 static BOOL
notify_if_changed(EDataFlow flow
, ERole role
, HKEY key
,
1099 const WCHAR
*val_name
, WCHAR
*old_val
, IMMDevice
*def_dev
)
1101 WCHAR new_val
[64], *id
;
1105 size
= sizeof(new_val
);
1106 if(RegQueryValueExW(key
, val_name
, 0, NULL
,
1107 (BYTE
*)new_val
, &size
) != ERROR_SUCCESS
){
1108 if(old_val
[0] != 0){
1109 /* set by user -> system default */
1111 hr
= IMMDevice_GetId(def_dev
, &id
);
1113 ERR("GetId failed: %08lx\n", hr
);
1119 notify_clients(flow
, role
, id
);
1126 /* system default -> system default, noop */
1130 if(!lstrcmpW(old_val
, new_val
)){
1131 /* set by user -> same value */
1135 if(new_val
[0] != 0){
1136 /* set by user -> different value */
1137 notify_clients(flow
, role
, new_val
);
1138 memcpy(old_val
, new_val
, sizeof(new_val
));
1142 /* set by user -> system default */
1144 hr
= IMMDevice_GetId(def_dev
, &id
);
1146 ERR("GetId failed: %08lx\n", hr
);
1152 notify_clients(flow
, role
, id
);
1159 static DWORD WINAPI
notif_thread_proc(void *user
)
1163 WCHAR out_name
[64], vout_name
[64], in_name
[64], vin_name
[64];
1166 SetThreadDescription(GetCurrentThread(), L
"wine_mmdevapi_notification");
1168 lstrcpyW(reg_key
, drv_keyW
);
1169 lstrcatW(reg_key
, L
"\\");
1170 lstrcatW(reg_key
, drvs
.module_name
);
1172 if(RegCreateKeyExW(HKEY_CURRENT_USER
, reg_key
, 0, NULL
, 0,
1173 MAXIMUM_ALLOWED
, NULL
, &key
, NULL
) != ERROR_SUCCESS
){
1174 ERR("RegCreateKeyEx failed: %lu\n", GetLastError());
1178 size
= sizeof(out_name
);
1179 if(RegQueryValueExW(key
, L
"DefaultOutput", 0, NULL
, (BYTE
*)out_name
, &size
) != ERROR_SUCCESS
)
1182 size
= sizeof(vout_name
);
1183 if(RegQueryValueExW(key
, L
"DefaultVoiceOutput", 0, NULL
, (BYTE
*)vout_name
, &size
) != ERROR_SUCCESS
)
1186 size
= sizeof(in_name
);
1187 if(RegQueryValueExW(key
, L
"DefaultInput", 0, NULL
, (BYTE
*)in_name
, &size
) != ERROR_SUCCESS
)
1190 size
= sizeof(vin_name
);
1191 if(RegQueryValueExW(key
, L
"DefaultVoiceInput", 0, NULL
, (BYTE
*)vin_name
, &size
) != ERROR_SUCCESS
)
1195 if(RegNotifyChangeKeyValue(key
, FALSE
, REG_NOTIFY_CHANGE_LAST_SET
,
1196 NULL
, FALSE
) != ERROR_SUCCESS
){
1197 ERR("RegNotifyChangeKeyValue failed: %lu\n", GetLastError());
1199 g_notif_thread
= NULL
;
1203 EnterCriticalSection(&g_notif_lock
);
1205 notify_if_changed(eRender
, eConsole
, key
, L
"DefaultOutput",
1206 out_name
, &MMDevice_def_play
->IMMDevice_iface
);
1207 notify_if_changed(eRender
, eCommunications
, key
, L
"DefaultVoiceOutput",
1208 vout_name
, &MMDevice_def_play
->IMMDevice_iface
);
1209 notify_if_changed(eCapture
, eConsole
, key
, L
"DefaultInput",
1210 in_name
, &MMDevice_def_rec
->IMMDevice_iface
);
1211 notify_if_changed(eCapture
, eCommunications
, key
, L
"DefaultVoiceInput",
1212 vin_name
, &MMDevice_def_rec
->IMMDevice_iface
);
1214 LeaveCriticalSection(&g_notif_lock
);
1219 g_notif_thread
= NULL
;
1224 static HRESULT WINAPI
MMDevEnum_RegisterEndpointNotificationCallback(IMMDeviceEnumerator
*iface
, IMMNotificationClient
*client
)
1226 MMDevEnumImpl
*This
= impl_from_IMMDeviceEnumerator(iface
);
1227 struct NotificationClientWrapper
*wrapper
;
1229 TRACE("(%p)->(%p)\n", This
, client
);
1234 wrapper
= HeapAlloc(GetProcessHeap(), 0, sizeof(*wrapper
));
1236 return E_OUTOFMEMORY
;
1238 wrapper
->client
= client
;
1240 EnterCriticalSection(&g_notif_lock
);
1242 list_add_tail(&g_notif_clients
, &wrapper
->entry
);
1244 if(!g_notif_thread
){
1245 g_notif_thread
= CreateThread(NULL
, 0, notif_thread_proc
, NULL
, 0, NULL
);
1247 ERR("CreateThread failed: %lu\n", GetLastError());
1250 LeaveCriticalSection(&g_notif_lock
);
1255 static HRESULT WINAPI
MMDevEnum_UnregisterEndpointNotificationCallback(IMMDeviceEnumerator
*iface
, IMMNotificationClient
*client
)
1257 MMDevEnumImpl
*This
= impl_from_IMMDeviceEnumerator(iface
);
1258 struct NotificationClientWrapper
*wrapper
;
1260 TRACE("(%p)->(%p)\n", This
, client
);
1265 EnterCriticalSection(&g_notif_lock
);
1267 LIST_FOR_EACH_ENTRY(wrapper
, &g_notif_clients
, struct NotificationClientWrapper
, entry
){
1268 if(wrapper
->client
== client
){
1269 list_remove(&wrapper
->entry
);
1270 HeapFree(GetProcessHeap(), 0, wrapper
);
1271 LeaveCriticalSection(&g_notif_lock
);
1276 LeaveCriticalSection(&g_notif_lock
);
1281 static const IMMDeviceEnumeratorVtbl MMDevEnumVtbl
=
1283 MMDevEnum_QueryInterface
,
1286 MMDevEnum_EnumAudioEndpoints
,
1287 MMDevEnum_GetDefaultAudioEndpoint
,
1288 MMDevEnum_GetDevice
,
1289 MMDevEnum_RegisterEndpointNotificationCallback
,
1290 MMDevEnum_UnregisterEndpointNotificationCallback
1293 static MMDevEnumImpl enumerator
=
1299 static HRESULT
MMDevPropStore_Create(MMDevice
*parent
, DWORD access
, IPropertyStore
**ppv
)
1301 MMDevPropStore
*This
;
1302 if (access
!= STGM_READ
1303 && access
!= STGM_WRITE
1304 && access
!= STGM_READWRITE
)
1306 WARN("Invalid access %08lx\n", access
);
1307 return E_INVALIDARG
;
1309 This
= HeapAlloc(GetProcessHeap(), 0, sizeof(*This
));
1310 *ppv
= &This
->IPropertyStore_iface
;
1312 return E_OUTOFMEMORY
;
1313 This
->IPropertyStore_iface
.lpVtbl
= &MMDevPropVtbl
;
1315 This
->parent
= parent
;
1316 This
->access
= access
;
1320 static void MMDevPropStore_Destroy(MMDevPropStore
*This
)
1322 HeapFree(GetProcessHeap(), 0, This
);
1325 static HRESULT WINAPI
MMDevPropStore_QueryInterface(IPropertyStore
*iface
, REFIID riid
, void **ppv
)
1327 MMDevPropStore
*This
= impl_from_IPropertyStore(iface
);
1328 TRACE("(%p)->(%s, %p)\n", This
, debugstr_guid(riid
), ppv
);
1332 if (IsEqualIID(riid
, &IID_IUnknown
)
1333 || IsEqualIID(riid
, &IID_IPropertyStore
))
1334 *ppv
= &This
->IPropertyStore_iface
;
1338 return E_NOINTERFACE
;
1339 IUnknown_AddRef((IUnknown
*)*ppv
);
1343 static ULONG WINAPI
MMDevPropStore_AddRef(IPropertyStore
*iface
)
1345 MMDevPropStore
*This
= impl_from_IPropertyStore(iface
);
1346 LONG ref
= InterlockedIncrement(&This
->ref
);
1347 TRACE("Refcount now %li\n", ref
);
1351 static ULONG WINAPI
MMDevPropStore_Release(IPropertyStore
*iface
)
1353 MMDevPropStore
*This
= impl_from_IPropertyStore(iface
);
1354 LONG ref
= InterlockedDecrement(&This
->ref
);
1355 TRACE("Refcount now %li\n", ref
);
1357 MMDevPropStore_Destroy(This
);
1361 static HRESULT WINAPI
MMDevPropStore_GetCount(IPropertyStore
*iface
, DWORD
*nprops
)
1363 MMDevPropStore
*This
= impl_from_IPropertyStore(iface
);
1369 TRACE("(%p)->(%p)\n", iface
, nprops
);
1372 hr
= MMDevPropStore_OpenPropKey(&This
->parent
->devguid
, This
->parent
->flow
, &propkey
);
1377 DWORD len
= ARRAY_SIZE(buffer
);
1378 if (RegEnumValueW(propkey
, i
, buffer
, &len
, NULL
, NULL
, NULL
, NULL
) != ERROR_SUCCESS
)
1382 RegCloseKey(propkey
);
1383 TRACE("Returning %li\n", i
);
1388 static HRESULT WINAPI
MMDevPropStore_GetAt(IPropertyStore
*iface
, DWORD prop
, PROPERTYKEY
*key
)
1390 MMDevPropStore
*This
= impl_from_IPropertyStore(iface
);
1392 DWORD len
= ARRAY_SIZE(buffer
);
1396 TRACE("(%p)->(%lu,%p)\n", iface
, prop
, key
);
1400 hr
= MMDevPropStore_OpenPropKey(&This
->parent
->devguid
, This
->parent
->flow
, &propkey
);
1404 if (RegEnumValueW(propkey
, prop
, buffer
, &len
, NULL
, NULL
, NULL
, NULL
) != ERROR_SUCCESS
1407 WARN("GetAt %lu failed\n", prop
);
1408 return E_INVALIDARG
;
1410 RegCloseKey(propkey
);
1412 CLSIDFromString(buffer
, &key
->fmtid
);
1413 key
->pid
= wcstol(&buffer
[39], NULL
, 10);
1417 static HRESULT WINAPI
MMDevPropStore_GetValue(IPropertyStore
*iface
, REFPROPERTYKEY key
, PROPVARIANT
*pv
)
1419 MMDevPropStore
*This
= impl_from_IPropertyStore(iface
);
1421 TRACE("(%p)->(\"%s,%lu\", %p)\n", This
, key
? debugstr_guid(&key
->fmtid
) : NULL
, key
? key
->pid
: 0, pv
);
1425 if (This
->access
!= STGM_READ
1426 && This
->access
!= STGM_READWRITE
)
1427 return STG_E_ACCESSDENIED
;
1430 if (IsEqualPropertyKey(*key
, PKEY_AudioEndpoint_GUID
))
1433 pv
->pwszVal
= CoTaskMemAlloc(39 * sizeof(WCHAR
));
1435 return E_OUTOFMEMORY
;
1436 StringFromGUID2(&This
->parent
->devguid
, pv
->pwszVal
, 39);
1440 hres
= MMDevice_GetPropValue(&This
->parent
->devguid
, This
->parent
->flow
, key
, pv
);
1444 if (WARN_ON(mmdevapi
))
1446 if ((IsEqualPropertyKey(*key
, DEVPKEY_Device_FriendlyName
) ||
1447 IsEqualPropertyKey(*key
, DEVPKEY_DeviceInterface_FriendlyName
) ||
1448 IsEqualPropertyKey(*key
, DEVPKEY_Device_DeviceDesc
)) &&
1449 pv
->vt
== VT_LPWSTR
&& wcslen(pv
->pwszVal
) > 62)
1450 WARN("Returned name exceeds length limit of some broken apps/libs, might crash: %s\n", debugstr_w(pv
->pwszVal
));
1455 static HRESULT WINAPI
MMDevPropStore_SetValue(IPropertyStore
*iface
, REFPROPERTYKEY key
, REFPROPVARIANT pv
)
1457 MMDevPropStore
*This
= impl_from_IPropertyStore(iface
);
1458 TRACE("(%p)->(\"%s,%lu\", %p)\n", This
, key
? debugstr_guid(&key
->fmtid
) : NULL
, key
? key
->pid
: 0, pv
);
1463 if (This
->access
!= STGM_WRITE
1464 && This
->access
!= STGM_READWRITE
)
1465 return STG_E_ACCESSDENIED
;
1466 return MMDevice_SetPropValue(&This
->parent
->devguid
, This
->parent
->flow
, key
, pv
);
1469 static HRESULT WINAPI
MMDevPropStore_Commit(IPropertyStore
*iface
)
1471 MMDevPropStore
*This
= impl_from_IPropertyStore(iface
);
1472 TRACE("(%p)\n", iface
);
1474 if (This
->access
!= STGM_WRITE
1475 && This
->access
!= STGM_READWRITE
)
1476 return STG_E_ACCESSDENIED
;
1478 /* Does nothing - for mmdevapi, the propstore values are written on SetValue,
1484 static const IPropertyStoreVtbl MMDevPropVtbl
=
1486 MMDevPropStore_QueryInterface
,
1487 MMDevPropStore_AddRef
,
1488 MMDevPropStore_Release
,
1489 MMDevPropStore_GetCount
,
1490 MMDevPropStore_GetAt
,
1491 MMDevPropStore_GetValue
,
1492 MMDevPropStore_SetValue
,
1493 MMDevPropStore_Commit
1497 /* Property bag for IBaseFilter activation */
1498 static HRESULT WINAPI
PB_QueryInterface(IPropertyBag
*iface
, REFIID riid
, void **ppv
)
1500 ERR("Should not be called\n");
1502 return E_NOINTERFACE
;
1505 static ULONG WINAPI
PB_AddRef(IPropertyBag
*iface
)
1507 ERR("Should not be called\n");
1511 static ULONG WINAPI
PB_Release(IPropertyBag
*iface
)
1513 ERR("Should not be called\n");
1517 static HRESULT WINAPI
PB_Read(IPropertyBag
*iface
, LPCOLESTR name
, VARIANT
*var
, IErrorLog
*log
)
1519 IPropertyBagImpl
*This
= impl_from_IPropertyBag(iface
);
1520 TRACE("Trying to read %s, type %u\n", debugstr_w(name
), var
->n1
.n2
.vt
);
1521 if (!lstrcmpW(name
, L
"DSGuid"))
1524 StringFromGUID2(&This
->devguid
, guidstr
,ARRAY_SIZE(guidstr
));
1525 var
->n1
.n2
.vt
= VT_BSTR
;
1526 var
->n1
.n2
.n3
.bstrVal
= SysAllocString(guidstr
);
1529 ERR("Unknown property '%s' queried\n", debugstr_w(name
));
1533 static HRESULT WINAPI
PB_Write(IPropertyBag
*iface
, LPCOLESTR name
, VARIANT
*var
)
1535 ERR("Should not be called\n");
1539 static const IPropertyBagVtbl PB_Vtbl
=
1548 static ULONG WINAPI
info_device_ps_AddRef(IPropertyStore
*iface
)
1553 static ULONG WINAPI
info_device_ps_Release(IPropertyStore
*iface
)
1558 static HRESULT WINAPI
info_device_ps_GetValue(IPropertyStore
*iface
,
1559 REFPROPERTYKEY key
, PROPVARIANT
*pv
)
1561 TRACE("(static)->(\"%s,%lu\", %p)\n", debugstr_guid(&key
->fmtid
), key
? key
->pid
: 0, pv
);
1566 if (IsEqualPropertyKey(*key
, DEVPKEY_Device_Driver
))
1568 INT size
= (lstrlenW(drvs
.module_name
) + 1) * sizeof(WCHAR
);
1570 pv
->pwszVal
= CoTaskMemAlloc(size
);
1572 return E_OUTOFMEMORY
;
1573 memcpy(pv
->pwszVal
, drvs
.module_name
, size
);
1577 return E_INVALIDARG
;
1580 static const IPropertyStoreVtbl info_device_ps_Vtbl
=
1583 info_device_ps_AddRef
,
1584 info_device_ps_Release
,
1587 info_device_ps_GetValue
,
1592 static IPropertyStore info_device_ps
= {
1593 &info_device_ps_Vtbl
1596 static ULONG WINAPI
info_device_AddRef(IMMDevice
*iface
)
1601 static ULONG WINAPI
info_device_Release(IMMDevice
*iface
)
1606 static HRESULT WINAPI
info_device_OpenPropertyStore(IMMDevice
*iface
,
1607 DWORD access
, IPropertyStore
**ppv
)
1609 TRACE("(static)->(%lx, %p)\n", access
, ppv
);
1610 *ppv
= &info_device_ps
;
1614 static const IMMDeviceVtbl info_device_Vtbl
=
1618 info_device_Release
,
1620 info_device_OpenPropertyStore
,
1625 static IMMDevice info_device
= {