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 DEFINE_GUID(GUID_NULL
,0,0,0,0,0,0,0,0,0,0,0);
47 static HKEY key_render
;
48 static HKEY key_capture
;
50 typedef struct MMDevPropStoreImpl
52 IPropertyStore IPropertyStore_iface
;
58 typedef struct MMDevEnumImpl
60 IMMDeviceEnumerator IMMDeviceEnumerator_iface
;
64 static MMDevice
*MMDevice_def_rec
, *MMDevice_def_play
;
65 static const IMMDeviceEnumeratorVtbl MMDevEnumVtbl
;
66 static const IMMDeviceCollectionVtbl MMDevColVtbl
;
67 static const IMMDeviceVtbl MMDeviceVtbl
;
68 static const IPropertyStoreVtbl MMDevPropVtbl
;
69 static const IMMEndpointVtbl MMEndpointVtbl
;
71 static MMDevEnumImpl enumerator
;
72 static struct list device_list
= LIST_INIT(device_list
);
73 static IMMDevice info_device
;
75 typedef struct MMDevColImpl
77 IMMDeviceCollection IMMDeviceCollection_iface
;
83 typedef struct IPropertyBagImpl
{
84 IPropertyBag IPropertyBag_iface
;
88 static const IPropertyBagVtbl PB_Vtbl
;
90 static HRESULT
MMDevPropStore_Create(MMDevice
*This
, DWORD access
, IPropertyStore
**ppv
);
92 static inline MMDevPropStore
*impl_from_IPropertyStore(IPropertyStore
*iface
)
94 return CONTAINING_RECORD(iface
, MMDevPropStore
, IPropertyStore_iface
);
97 static inline MMDevEnumImpl
*impl_from_IMMDeviceEnumerator(IMMDeviceEnumerator
*iface
)
99 return CONTAINING_RECORD(iface
, MMDevEnumImpl
, IMMDeviceEnumerator_iface
);
102 static inline MMDevColImpl
*impl_from_IMMDeviceCollection(IMMDeviceCollection
*iface
)
104 return CONTAINING_RECORD(iface
, MMDevColImpl
, IMMDeviceCollection_iface
);
107 static inline IPropertyBagImpl
*impl_from_IPropertyBag(IPropertyBag
*iface
)
109 return CONTAINING_RECORD(iface
, IPropertyBagImpl
, IPropertyBag_iface
);
112 static const WCHAR propkey_formatW
[] = L
"{%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X},%d";
114 static HRESULT
MMDevPropStore_OpenPropKey(const GUID
*guid
, DWORD flow
, HKEY
*propkey
)
119 StringFromGUID2(guid
, buffer
, 39);
120 if ((ret
= RegOpenKeyExW(flow
== eRender
? key_render
: key_capture
, buffer
, 0, KEY_READ
|KEY_WRITE
|KEY_WOW64_64KEY
, &key
)) != ERROR_SUCCESS
)
122 WARN("Opening key %s failed with %lu\n", debugstr_w(buffer
), ret
);
125 ret
= RegOpenKeyExW(key
, L
"Properties", 0, KEY_READ
|KEY_WRITE
|KEY_WOW64_64KEY
, propkey
);
127 if (ret
!= ERROR_SUCCESS
)
129 WARN("Opening key Properties failed with %lu\n", ret
);
135 static HRESULT
MMDevice_GetPropValue(const GUID
*devguid
, DWORD flow
, REFPROPERTYKEY key
, PROPVARIANT
*pv
)
138 const GUID
*id
= &key
->fmtid
;
144 hr
= MMDevPropStore_OpenPropKey(devguid
, flow
, ®key
);
147 wsprintfW( buffer
, propkey_formatW
, id
->Data1
, id
->Data2
, id
->Data3
,
148 id
->Data4
[0], id
->Data4
[1], id
->Data4
[2], id
->Data4
[3],
149 id
->Data4
[4], id
->Data4
[5], id
->Data4
[6], id
->Data4
[7], key
->pid
);
150 ret
= RegGetValueW(regkey
, NULL
, buffer
, RRF_RT_ANY
, &type
, NULL
, &size
);
151 if (ret
!= ERROR_SUCCESS
)
153 WARN("Reading %s returned %ld\n", debugstr_w(buffer
), ret
);
164 pv
->pwszVal
= CoTaskMemAlloc(size
);
168 RegGetValueW(regkey
, NULL
, buffer
, RRF_RT_REG_SZ
, NULL
, (BYTE
*)pv
->pwszVal
, &size
);
174 RegGetValueW(regkey
, NULL
, buffer
, RRF_RT_REG_DWORD
, NULL
, (BYTE
*)&pv
->ulVal
, &size
);
180 pv
->blob
.cbSize
= size
;
181 pv
->blob
.pBlobData
= CoTaskMemAlloc(size
);
182 if (!pv
->blob
.pBlobData
)
185 RegGetValueW(regkey
, NULL
, buffer
, RRF_RT_REG_BINARY
, NULL
, (BYTE
*)pv
->blob
.pBlobData
, &size
);
189 ERR("Unknown/unhandled type: %lu\n", type
);
190 PropVariantClear(pv
);
197 static HRESULT
MMDevice_SetPropValue(const GUID
*devguid
, DWORD flow
, REFPROPERTYKEY key
, REFPROPVARIANT pv
)
200 const GUID
*id
= &key
->fmtid
;
205 hr
= MMDevPropStore_OpenPropKey(devguid
, flow
, ®key
);
208 wsprintfW( buffer
, propkey_formatW
, id
->Data1
, id
->Data2
, id
->Data3
,
209 id
->Data4
[0], id
->Data4
[1], id
->Data4
[2], id
->Data4
[3],
210 id
->Data4
[4], id
->Data4
[5], id
->Data4
[6], id
->Data4
[7], key
->pid
);
215 ret
= RegSetValueExW(regkey
, buffer
, 0, REG_DWORD
, (const BYTE
*)&pv
->ulVal
, sizeof(DWORD
));
220 ret
= RegSetValueExW(regkey
, buffer
, 0, REG_BINARY
, pv
->blob
.pBlobData
, pv
->blob
.cbSize
);
221 TRACE("Blob %p %lu\n", pv
->blob
.pBlobData
, pv
->blob
.cbSize
);
227 ret
= RegSetValueExW(regkey
, buffer
, 0, REG_SZ
, (const BYTE
*)pv
->pwszVal
, sizeof(WCHAR
)*(1+lstrlenW(pv
->pwszVal
)));
232 FIXME("Unhandled type %u\n", pv
->vt
);
237 TRACE("Writing %s returned %lu\n", debugstr_w(buffer
), ret
);
241 static HRESULT
set_driver_prop_value(GUID
*id
, const EDataFlow flow
, const PROPERTYKEY
*prop
)
243 struct get_prop_value_params params
;
246 unsigned int size
= 0;
248 TRACE("%s, (%s,%lu)\n", wine_dbgstr_guid(id
), wine_dbgstr_guid(&prop
->fmtid
), prop
->pid
);
250 if (!drvs
.pget_device_name_from_guid(id
, &dev_name
, ¶ms
.flow
))
253 params
.device
= dev_name
;
257 params
.buffer
= NULL
;
258 params
.buffer_size
= &size
;
261 __wine_unix_call(drvs
.module_unixlib
, get_prop_value
, ¶ms
);
263 if (params
.result
!= E_NOT_SUFFICIENT_BUFFER
)
266 CoTaskMemFree(params
.buffer
);
267 params
.buffer
= CoTaskMemAlloc(*params
.buffer_size
);
268 if (!params
.buffer
) {
270 return E_OUTOFMEMORY
;
274 if (FAILED(params
.result
))
275 CoTaskMemFree(params
.buffer
);
279 if (SUCCEEDED(params
.result
)) {
280 MMDevice_SetPropValue(id
, flow
, prop
, &pv
);
281 PropVariantClear(&pv
);
284 return params
.result
;
287 struct product_name_overrides
290 const WCHAR
*product
;
293 static const struct product_name_overrides product_name_overrides
[] =
295 /* Sony controllers */
296 { .id
= L
"VID_054C&PID_0CE6", .product
= L
"Wireless Controller" },
299 static const WCHAR
*find_product_name_override(const WCHAR
*device_id
)
301 const WCHAR
*match_id
= wcschr( device_id
, '\\' ) + 1;
304 for (i
= 0; i
< ARRAY_SIZE(product_name_overrides
); ++i
)
305 if (!wcsnicmp( product_name_overrides
[i
].id
, match_id
, 17 ))
306 return product_name_overrides
[i
].product
;
311 /* Creates or updates the state of a device
312 * If GUID is null, a random guid will be assigned
313 * and the device will be created
315 static MMDevice
*MMDevice_Create(WCHAR
*name
, GUID
*id
, EDataFlow flow
, DWORD state
, BOOL setdefault
)
318 MMDevice
*device
, *cur
= NULL
;
321 static const PROPERTYKEY deviceinterface_key
= {
322 {0x233164c8, 0x1b2c, 0x4c7d, {0xbc, 0x68, 0xb6, 0x71, 0x68, 0x7a, 0x25, 0x67}}, 1
325 static const PROPERTYKEY devicepath_key
= {
326 {0xb3f8fa53, 0x0004, 0x438e, {0x90, 0x03, 0x51, 0xa4, 0x6e, 0x13, 0x9b, 0xfc}}, 2
329 LIST_FOR_EACH_ENTRY(device
, &device_list
, MMDevice
, entry
)
331 if (device
->flow
== flow
&& IsEqualGUID(&device
->devguid
, id
)){
338 /* No device found, allocate new one */
339 cur
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*cur
));
343 cur
->IMMDevice_iface
.lpVtbl
= &MMDeviceVtbl
;
344 cur
->IMMEndpoint_iface
.lpVtbl
= &MMEndpointVtbl
;
346 InitializeCriticalSection(&cur
->crst
);
347 cur
->crst
.DebugInfo
->Spare
[0] = (DWORD_PTR
)(__FILE__
": MMDevice.crst");
349 list_add_tail(&device_list
, &cur
->entry
);
350 }else if(cur
->ref
> 0)
351 WARN("Modifying an MMDevice with postitive reference count!\n");
353 HeapFree(GetProcessHeap(), 0, cur
->drv_id
);
360 StringFromGUID2(&cur
->devguid
, guidstr
, ARRAY_SIZE(guidstr
));
367 if (RegCreateKeyExW(root
, guidstr
, 0, NULL
, 0, KEY_WRITE
|KEY_READ
|KEY_WOW64_64KEY
, NULL
, &key
, NULL
) == ERROR_SUCCESS
)
370 RegSetValueExW(key
, L
"DeviceState", 0, REG_DWORD
, (const BYTE
*)&state
, sizeof(DWORD
));
371 if (!RegCreateKeyExW(key
, L
"Properties", 0, NULL
, 0, KEY_WRITE
|KEY_READ
|KEY_WOW64_64KEY
, NULL
, &keyprop
, NULL
))
378 if (SUCCEEDED(set_driver_prop_value(id
, flow
, &devicepath_key
))) {
381 PropVariantInit(&pv2
);
383 if (SUCCEEDED(MMDevice_GetPropValue(id
, flow
, &devicepath_key
, &pv2
)) && pv2
.vt
== VT_LPWSTR
) {
384 const WCHAR
*override
;
385 if ((override
= find_product_name_override(pv2
.pwszVal
)) != NULL
)
386 pv
.pwszVal
= (WCHAR
*) override
;
389 PropVariantClear(&pv2
);
392 MMDevice_SetPropValue(id
, flow
, (const PROPERTYKEY
*)&DEVPKEY_Device_FriendlyName
, &pv
);
393 MMDevice_SetPropValue(id
, flow
, (const PROPERTYKEY
*)&DEVPKEY_DeviceInterface_FriendlyName
, &pv
);
394 MMDevice_SetPropValue(id
, flow
, (const PROPERTYKEY
*)&DEVPKEY_Device_DeviceDesc
, &pv
);
396 pv
.pwszVal
= guidstr
;
397 MMDevice_SetPropValue(id
, flow
, &deviceinterface_key
, &pv
);
399 if (FAILED(set_driver_prop_value(id
, flow
, &PKEY_AudioEndpoint_FormFactor
)))
402 pv
.ulVal
= (flow
== eCapture
) ? Microphone
: Speakers
;
404 MMDevice_SetPropValue(id
, flow
, &PKEY_AudioEndpoint_FormFactor
, &pv
);
407 if (flow
!= eCapture
)
411 PropVariantInit(&pv2
);
413 /* make read-write by not overwriting if already set */
414 if (FAILED(MMDevice_GetPropValue(id
, flow
, &PKEY_AudioEndpoint_PhysicalSpeakers
, &pv2
)) || pv2
.vt
!= VT_UI4
)
415 set_driver_prop_value(id
, flow
, &PKEY_AudioEndpoint_PhysicalSpeakers
);
417 PropVariantClear(&pv2
);
420 RegCloseKey(keyprop
);
428 MMDevice_def_play
= cur
;
430 MMDevice_def_rec
= cur
;
435 HRESULT
load_devices_from_reg(void)
442 ret
= RegCreateKeyExW(HKEY_LOCAL_MACHINE
,
443 L
"Software\\Microsoft\\Windows\\CurrentVersion\\MMDevices\\Audio", 0, NULL
, 0,
444 KEY_WRITE
|KEY_READ
|KEY_WOW64_64KEY
, NULL
, &root
, NULL
);
445 if (ret
== ERROR_SUCCESS
)
446 ret
= RegCreateKeyExW(root
, L
"Capture", 0, NULL
, 0, KEY_READ
|KEY_WRITE
|KEY_WOW64_64KEY
, NULL
, &key_capture
, NULL
);
447 if (ret
== ERROR_SUCCESS
)
448 ret
= RegCreateKeyExW(root
, L
"Render", 0, NULL
, 0, KEY_READ
|KEY_WRITE
|KEY_WOW64_64KEY
, NULL
, &key_render
, NULL
);
452 if (ret
!= ERROR_SUCCESS
)
454 RegCloseKey(key_capture
);
455 key_render
= key_capture
= NULL
;
456 WARN("Couldn't create key: %lu\n", ret
);
464 PROPVARIANT pv
= { VT_EMPTY
};
466 len
= ARRAY_SIZE(guidvalue
);
467 ret
= RegEnumKeyExW(cur
, i
++, guidvalue
, &len
, NULL
, NULL
, NULL
, NULL
);
468 if (ret
== ERROR_NO_MORE_ITEMS
)
470 if (cur
== key_capture
)
479 if (ret
!= ERROR_SUCCESS
)
481 if (SUCCEEDED(CLSIDFromString(guidvalue
, &guid
))
482 && SUCCEEDED(MMDevice_GetPropValue(&guid
, curflow
, (const PROPERTYKEY
*)&DEVPKEY_Device_FriendlyName
, &pv
))
483 && pv
.vt
== VT_LPWSTR
)
485 DWORD size_bytes
= (lstrlenW(pv
.pwszVal
) + 1) * sizeof(WCHAR
);
486 WCHAR
*name
= HeapAlloc(GetProcessHeap(), 0, size_bytes
);
487 memcpy(name
, pv
.pwszVal
, size_bytes
);
488 MMDevice_Create(name
, &guid
, curflow
,
489 DEVICE_STATE_NOTPRESENT
, FALSE
);
490 CoTaskMemFree(pv
.pwszVal
);
497 static HRESULT
set_format(MMDevice
*dev
)
500 IAudioClient
*client
;
502 PROPVARIANT pv
= { VT_EMPTY
};
504 hr
= AudioClient_Create(&dev
->devguid
, &dev
->IMMDevice_iface
, &client
);
508 hr
= IAudioClient_GetMixFormat(client
, &fmt
);
510 IAudioClient_Release(client
);
514 IAudioClient_Release(client
);
517 pv
.blob
.cbSize
= sizeof(WAVEFORMATEX
) + fmt
->cbSize
;
518 pv
.blob
.pBlobData
= (BYTE
*)fmt
;
519 MMDevice_SetPropValue(&dev
->devguid
, dev
->flow
,
520 &PKEY_AudioEngine_DeviceFormat
, &pv
);
521 MMDevice_SetPropValue(&dev
->devguid
, dev
->flow
,
522 &PKEY_AudioEngine_OEMFormat
, &pv
);
528 HRESULT
load_driver_devices(EDataFlow flow
)
535 if(!drvs
.pGetEndpointIDs
)
538 hr
= drvs
.pGetEndpointIDs(flow
, &ids
, &guids
, &num
, &def
);
542 for(i
= 0; i
< num
; ++i
){
544 dev
= MMDevice_Create(ids
[i
], &guids
[i
], flow
, DEVICE_STATE_ACTIVE
,
549 HeapFree(GetProcessHeap(), 0, guids
);
550 HeapFree(GetProcessHeap(), 0, ids
);
555 static void MMDevice_Destroy(MMDevice
*This
)
557 TRACE("Freeing %s\n", debugstr_w(This
->drv_id
));
558 list_remove(&This
->entry
);
559 This
->crst
.DebugInfo
->Spare
[0] = 0;
560 DeleteCriticalSection(&This
->crst
);
561 HeapFree(GetProcessHeap(), 0, This
->drv_id
);
562 HeapFree(GetProcessHeap(), 0, This
);
565 static inline MMDevice
*impl_from_IMMDevice(IMMDevice
*iface
)
567 return CONTAINING_RECORD(iface
, MMDevice
, IMMDevice_iface
);
570 static HRESULT WINAPI
MMDevice_QueryInterface(IMMDevice
*iface
, REFIID riid
, void **ppv
)
572 MMDevice
*This
= impl_from_IMMDevice(iface
);
573 TRACE("(%p)->(%s,%p)\n", iface
, debugstr_guid(riid
), ppv
);
578 if (IsEqualIID(riid
, &IID_IUnknown
)
579 || IsEqualIID(riid
, &IID_IMMDevice
))
580 *ppv
= &This
->IMMDevice_iface
;
581 else if (IsEqualIID(riid
, &IID_IMMEndpoint
))
582 *ppv
= &This
->IMMEndpoint_iface
;
585 IUnknown_AddRef((IUnknown
*)*ppv
);
588 WARN("Unknown interface %s\n", debugstr_guid(riid
));
589 return E_NOINTERFACE
;
592 static ULONG WINAPI
MMDevice_AddRef(IMMDevice
*iface
)
594 MMDevice
*This
= impl_from_IMMDevice(iface
);
597 ref
= InterlockedIncrement(&This
->ref
);
598 TRACE("Refcount now %li\n", ref
);
602 static ULONG WINAPI
MMDevice_Release(IMMDevice
*iface
)
604 MMDevice
*This
= impl_from_IMMDevice(iface
);
607 ref
= InterlockedDecrement(&This
->ref
);
608 TRACE("Refcount now %li\n", ref
);
612 static HRESULT WINAPI
MMDevice_Activate(IMMDevice
*iface
, REFIID riid
, DWORD clsctx
, PROPVARIANT
*params
, void **ppv
)
614 HRESULT hr
= E_NOINTERFACE
;
615 MMDevice
*This
= impl_from_IMMDevice(iface
);
617 TRACE("(%p)->(%s, %lx, %p, %p)\n", iface
, debugstr_guid(riid
), clsctx
, params
, ppv
);
622 if (IsEqualIID(riid
, &IID_IAudioClient
) ||
623 IsEqualIID(riid
, &IID_IAudioClient2
) ||
624 IsEqualIID(riid
, &IID_IAudioClient3
)){
625 hr
= AudioClient_Create(&This
->devguid
, iface
, (IAudioClient
**)ppv
);
626 }else if (IsEqualIID(riid
, &IID_IAudioEndpointVolume
) ||
627 IsEqualIID(riid
, &IID_IAudioEndpointVolumeEx
))
628 hr
= AudioEndpointVolume_Create(This
, (IAudioEndpointVolumeEx
**)ppv
);
629 else if (IsEqualIID(riid
, &IID_IAudioSessionManager
)
630 || IsEqualIID(riid
, &IID_IAudioSessionManager2
))
632 hr
= AudioSessionManager_Create(iface
, (IAudioSessionManager2
**)ppv
);
634 else if (IsEqualIID(riid
, &IID_IBaseFilter
))
636 if (This
->flow
== eRender
)
637 hr
= CoCreateInstance(&CLSID_DSoundRender
, NULL
, clsctx
, riid
, ppv
);
639 ERR("Not supported for recording?\n");
642 IPersistPropertyBag
*ppb
;
643 hr
= IUnknown_QueryInterface((IUnknown
*)*ppv
, &IID_IPersistPropertyBag
, (void **)&ppb
);
646 /* ::Load cannot assume the interface stays alive after the function returns,
647 * so just create the interface on the stack, saves a lot of complicated code */
648 IPropertyBagImpl bag
= { { &PB_Vtbl
} };
649 bag
.devguid
= This
->devguid
;
650 hr
= IPersistPropertyBag_Load(ppb
, &bag
.IPropertyBag_iface
, NULL
);
651 IPersistPropertyBag_Release(ppb
);
653 IBaseFilter_Release((IBaseFilter
*)*ppv
);
657 FIXME("Wine doesn't support IPersistPropertyBag on DSoundRender yet, ignoring..\n");
662 else if (IsEqualIID(riid
, &IID_IDeviceTopology
))
664 FIXME("IID_IDeviceTopology unsupported\n");
666 else if (IsEqualIID(riid
, &IID_IDirectSound
)
667 || IsEqualIID(riid
, &IID_IDirectSound8
))
669 if (This
->flow
== eRender
)
670 hr
= CoCreateInstance(&CLSID_DirectSound8
, NULL
, clsctx
, riid
, ppv
);
673 hr
= IDirectSound_Initialize((IDirectSound
*)*ppv
, &This
->devguid
);
675 IDirectSound_Release((IDirectSound
*)*ppv
);
678 else if (IsEqualIID(riid
, &IID_IDirectSoundCapture
))
680 if (This
->flow
== eCapture
)
681 hr
= CoCreateInstance(&CLSID_DirectSoundCapture8
, NULL
, clsctx
, riid
, ppv
);
684 hr
= IDirectSoundCapture_Initialize((IDirectSoundCapture
*)*ppv
, &This
->devguid
);
686 IDirectSoundCapture_Release((IDirectSoundCapture
*)*ppv
);
689 else if (IsEqualIID(riid
, &IID_ISpatialAudioClient
))
691 hr
= SpatialAudioClient_Create(iface
, (ISpatialAudioClient
**)ppv
);
694 ERR("Invalid/unknown iid %s\n", debugstr_guid(riid
));
699 TRACE("Returning %08lx\n", hr
);
703 static HRESULT WINAPI
MMDevice_OpenPropertyStore(IMMDevice
*iface
, DWORD access
, IPropertyStore
**ppv
)
705 MMDevice
*This
= impl_from_IMMDevice(iface
);
706 TRACE("(%p)->(%lx,%p)\n", This
, access
, ppv
);
710 return MMDevPropStore_Create(This
, access
, ppv
);
713 static HRESULT WINAPI
MMDevice_GetId(IMMDevice
*iface
, WCHAR
**itemid
)
715 MMDevice
*This
= impl_from_IMMDevice(iface
);
717 GUID
*id
= &This
->devguid
;
719 TRACE("(%p)->(%p)\n", This
, itemid
);
722 *itemid
= str
= CoTaskMemAlloc(56 * sizeof(WCHAR
));
724 return E_OUTOFMEMORY
;
725 wsprintfW(str
, L
"{0.0.%u.00000000}.{%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X}",
726 This
->flow
, id
->Data1
, id
->Data2
, id
->Data3
,
727 id
->Data4
[0], id
->Data4
[1], id
->Data4
[2], id
->Data4
[3],
728 id
->Data4
[4], id
->Data4
[5], id
->Data4
[6], id
->Data4
[7]);
729 TRACE("returning %s\n", wine_dbgstr_w(str
));
733 static HRESULT WINAPI
MMDevice_GetState(IMMDevice
*iface
, DWORD
*state
)
735 MMDevice
*This
= impl_from_IMMDevice(iface
);
736 TRACE("(%p)->(%p)\n", iface
, state
);
740 *state
= This
->state
;
744 static const IMMDeviceVtbl MMDeviceVtbl
=
746 MMDevice_QueryInterface
,
750 MMDevice_OpenPropertyStore
,
755 static inline MMDevice
*impl_from_IMMEndpoint(IMMEndpoint
*iface
)
757 return CONTAINING_RECORD(iface
, MMDevice
, IMMEndpoint_iface
);
760 static HRESULT WINAPI
MMEndpoint_QueryInterface(IMMEndpoint
*iface
, REFIID riid
, void **ppv
)
762 MMDevice
*This
= impl_from_IMMEndpoint(iface
);
763 TRACE("(%p)->(%s, %p)\n", This
, debugstr_guid(riid
), ppv
);
764 return IMMDevice_QueryInterface(&This
->IMMDevice_iface
, riid
, ppv
);
767 static ULONG WINAPI
MMEndpoint_AddRef(IMMEndpoint
*iface
)
769 MMDevice
*This
= impl_from_IMMEndpoint(iface
);
770 TRACE("(%p)\n", This
);
771 return IMMDevice_AddRef(&This
->IMMDevice_iface
);
774 static ULONG WINAPI
MMEndpoint_Release(IMMEndpoint
*iface
)
776 MMDevice
*This
= impl_from_IMMEndpoint(iface
);
777 TRACE("(%p)\n", This
);
778 return IMMDevice_Release(&This
->IMMDevice_iface
);
781 static HRESULT WINAPI
MMEndpoint_GetDataFlow(IMMEndpoint
*iface
, EDataFlow
*flow
)
783 MMDevice
*This
= impl_from_IMMEndpoint(iface
);
784 TRACE("(%p)->(%p)\n", This
, flow
);
791 static const IMMEndpointVtbl MMEndpointVtbl
=
793 MMEndpoint_QueryInterface
,
796 MMEndpoint_GetDataFlow
799 static HRESULT
MMDevCol_Create(IMMDeviceCollection
**ppv
, EDataFlow flow
, DWORD state
)
803 This
= HeapAlloc(GetProcessHeap(), 0, sizeof(*This
));
806 return E_OUTOFMEMORY
;
807 This
->IMMDeviceCollection_iface
.lpVtbl
= &MMDevColVtbl
;
811 *ppv
= &This
->IMMDeviceCollection_iface
;
815 static void MMDevCol_Destroy(MMDevColImpl
*This
)
817 HeapFree(GetProcessHeap(), 0, This
);
820 static HRESULT WINAPI
MMDevCol_QueryInterface(IMMDeviceCollection
*iface
, REFIID riid
, void **ppv
)
822 MMDevColImpl
*This
= impl_from_IMMDeviceCollection(iface
);
823 TRACE("(%p)->(%s, %p)\n", This
, debugstr_guid(riid
), ppv
);
827 if (IsEqualIID(riid
, &IID_IUnknown
)
828 || IsEqualIID(riid
, &IID_IMMDeviceCollection
))
829 *ppv
= &This
->IMMDeviceCollection_iface
;
833 return E_NOINTERFACE
;
834 IUnknown_AddRef((IUnknown
*)*ppv
);
838 static ULONG WINAPI
MMDevCol_AddRef(IMMDeviceCollection
*iface
)
840 MMDevColImpl
*This
= impl_from_IMMDeviceCollection(iface
);
841 LONG ref
= InterlockedIncrement(&This
->ref
);
842 TRACE("Refcount now %li\n", ref
);
846 static ULONG WINAPI
MMDevCol_Release(IMMDeviceCollection
*iface
)
848 MMDevColImpl
*This
= impl_from_IMMDeviceCollection(iface
);
849 LONG ref
= InterlockedDecrement(&This
->ref
);
850 TRACE("Refcount now %li\n", ref
);
852 MMDevCol_Destroy(This
);
856 static HRESULT WINAPI
MMDevCol_GetCount(IMMDeviceCollection
*iface
, UINT
*numdevs
)
858 MMDevColImpl
*This
= impl_from_IMMDeviceCollection(iface
);
861 TRACE("(%p)->(%p)\n", This
, numdevs
);
866 LIST_FOR_EACH_ENTRY(cur
, &device_list
, MMDevice
, entry
)
868 if ((cur
->flow
== This
->flow
|| This
->flow
== eAll
)
869 && (cur
->state
& This
->state
))
875 static HRESULT WINAPI
MMDevCol_Item(IMMDeviceCollection
*iface
, UINT n
, IMMDevice
**dev
)
877 MMDevColImpl
*This
= impl_from_IMMDeviceCollection(iface
);
881 TRACE("(%p)->(%u, %p)\n", This
, n
, dev
);
885 LIST_FOR_EACH_ENTRY(cur
, &device_list
, MMDevice
, entry
)
887 if ((cur
->flow
== This
->flow
|| This
->flow
== eAll
)
888 && (cur
->state
& This
->state
)
891 *dev
= &cur
->IMMDevice_iface
;
892 IMMDevice_AddRef(*dev
);
896 WARN("Could not obtain item %u\n", n
);
901 static const IMMDeviceCollectionVtbl MMDevColVtbl
=
903 MMDevCol_QueryInterface
,
910 HRESULT
MMDevEnum_Create(REFIID riid
, void **ppv
)
912 return IMMDeviceEnumerator_QueryInterface(&enumerator
.IMMDeviceEnumerator_iface
, riid
, ppv
);
915 void MMDevEnum_Free(void)
917 MMDevice
*device
, *next
;
918 LIST_FOR_EACH_ENTRY_SAFE(device
, next
, &device_list
, MMDevice
, entry
)
919 MMDevice_Destroy(device
);
920 RegCloseKey(key_render
);
921 RegCloseKey(key_capture
);
922 key_render
= key_capture
= NULL
;
925 static HRESULT WINAPI
MMDevEnum_QueryInterface(IMMDeviceEnumerator
*iface
, REFIID riid
, void **ppv
)
927 MMDevEnumImpl
*This
= impl_from_IMMDeviceEnumerator(iface
);
928 TRACE("(%p)->(%s, %p)\n", This
, debugstr_guid(riid
), ppv
);
932 if (IsEqualIID(riid
, &IID_IUnknown
)
933 || IsEqualIID(riid
, &IID_IMMDeviceEnumerator
))
934 *ppv
= &This
->IMMDeviceEnumerator_iface
;
938 return E_NOINTERFACE
;
939 IUnknown_AddRef((IUnknown
*)*ppv
);
943 static ULONG WINAPI
MMDevEnum_AddRef(IMMDeviceEnumerator
*iface
)
945 MMDevEnumImpl
*This
= impl_from_IMMDeviceEnumerator(iface
);
946 LONG ref
= InterlockedIncrement(&This
->ref
);
947 TRACE("Refcount now %li\n", ref
);
951 static ULONG WINAPI
MMDevEnum_Release(IMMDeviceEnumerator
*iface
)
953 MMDevEnumImpl
*This
= impl_from_IMMDeviceEnumerator(iface
);
954 LONG ref
= InterlockedDecrement(&This
->ref
);
955 TRACE("Refcount now %li\n", ref
);
959 static HRESULT WINAPI
MMDevEnum_EnumAudioEndpoints(IMMDeviceEnumerator
*iface
, EDataFlow flow
, DWORD mask
, IMMDeviceCollection
**devices
)
961 MMDevEnumImpl
*This
= impl_from_IMMDeviceEnumerator(iface
);
962 TRACE("(%p)->(%u,%lu,%p)\n", This
, flow
, mask
, devices
);
966 if (flow
>= EDataFlow_enum_count
)
968 if (mask
& ~DEVICE_STATEMASK_ALL
)
970 return MMDevCol_Create(devices
, flow
, mask
);
973 static HRESULT WINAPI
MMDevEnum_GetDefaultAudioEndpoint(IMMDeviceEnumerator
*iface
, EDataFlow flow
, ERole role
, IMMDevice
**device
)
975 MMDevEnumImpl
*This
= impl_from_IMMDeviceEnumerator(iface
);
980 TRACE("(%p)->(%u,%u,%p)\n", This
, flow
, role
, device
);
985 if((flow
!= eRender
&& flow
!= eCapture
) ||
986 (role
!= eConsole
&& role
!= eMultimedia
&& role
!= eCommunications
)){
987 WARN("Unknown flow (%u) or role (%u)\n", flow
, role
);
993 if(!drvs
.module_name
[0])
996 lstrcpyW(reg_key
, drv_keyW
);
997 lstrcatW(reg_key
, L
"\\");
998 lstrcatW(reg_key
, drvs
.module_name
);
1000 if(RegOpenKeyW(HKEY_CURRENT_USER
, reg_key
, &key
) == ERROR_SUCCESS
){
1001 const WCHAR
*reg_x_name
, *reg_vx_name
;
1003 DWORD size
= sizeof(def_id
), state
;
1005 if(flow
== eRender
){
1006 reg_x_name
= L
"DefaultOutput";
1007 reg_vx_name
= L
"DefaultVoiceOutput";
1009 reg_x_name
= L
"DefaultInput";
1010 reg_vx_name
= L
"DefaultVoiceInput";
1013 if(role
== eCommunications
&&
1014 RegQueryValueExW(key
, reg_vx_name
, 0, NULL
,
1015 (BYTE
*)def_id
, &size
) == ERROR_SUCCESS
){
1016 hr
= IMMDeviceEnumerator_GetDevice(iface
, def_id
, device
);
1018 if(SUCCEEDED(IMMDevice_GetState(*device
, &state
)) &&
1019 state
== DEVICE_STATE_ACTIVE
){
1025 TRACE("Unable to find voice device %s\n", wine_dbgstr_w(def_id
));
1028 if(RegQueryValueExW(key
, reg_x_name
, 0, NULL
,
1029 (BYTE
*)def_id
, &size
) == ERROR_SUCCESS
){
1030 hr
= IMMDeviceEnumerator_GetDevice(iface
, def_id
, device
);
1032 if(SUCCEEDED(IMMDevice_GetState(*device
, &state
)) &&
1033 state
== DEVICE_STATE_ACTIVE
){
1039 TRACE("Unable to find device %s\n", wine_dbgstr_w(def_id
));
1045 if (flow
== eRender
)
1046 *device
= &MMDevice_def_play
->IMMDevice_iface
;
1048 *device
= &MMDevice_def_rec
->IMMDevice_iface
;
1052 IMMDevice_AddRef(*device
);
1056 static HRESULT WINAPI
MMDevEnum_GetDevice(IMMDeviceEnumerator
*iface
, const WCHAR
*name
, IMMDevice
**device
)
1058 MMDevEnumImpl
*This
= impl_from_IMMDeviceEnumerator(iface
);
1060 IMMDevice
*dev
= NULL
;
1062 TRACE("(%p)->(%s,%p)\n", This
, debugstr_w(name
), device
);
1064 if(!name
|| !device
)
1067 if(!lstrcmpW(name
, L
"Wine info device")){
1068 *device
= &info_device
;
1072 LIST_FOR_EACH_ENTRY(impl
, &device_list
, MMDevice
, entry
)
1076 dev
= &impl
->IMMDevice_iface
;
1077 hr
= IMMDevice_GetId(dev
, &str
);
1080 WARN("GetId failed: %08lx\n", hr
);
1084 if (str
&& !lstrcmpW(str
, name
))
1087 IMMDevice_AddRef(dev
);
1093 TRACE("Could not find device %s\n", debugstr_w(name
));
1094 return E_INVALIDARG
;
1097 struct NotificationClientWrapper
{
1098 IMMNotificationClient
*client
;
1102 static struct list g_notif_clients
= LIST_INIT(g_notif_clients
);
1103 static HANDLE g_notif_thread
;
1105 static CRITICAL_SECTION g_notif_lock
;
1106 static CRITICAL_SECTION_DEBUG g_notif_lock_debug
=
1108 0, 0, &g_notif_lock
,
1109 { &g_notif_lock_debug
.ProcessLocksList
, &g_notif_lock_debug
.ProcessLocksList
},
1110 0, 0, { (DWORD_PTR
)(__FILE__
": g_notif_lock") }
1112 static CRITICAL_SECTION g_notif_lock
= { &g_notif_lock_debug
, -1, 0, 0, 0, 0 };
1114 static void notify_clients(EDataFlow flow
, ERole role
, const WCHAR
*id
)
1116 struct NotificationClientWrapper
*wrapper
;
1117 LIST_FOR_EACH_ENTRY(wrapper
, &g_notif_clients
,
1118 struct NotificationClientWrapper
, entry
)
1119 IMMNotificationClient_OnDefaultDeviceChanged(wrapper
->client
, flow
,
1122 /* Windows 7 treats changes to eConsole as changes to eMultimedia */
1123 if(role
== eConsole
)
1124 notify_clients(flow
, eMultimedia
, id
);
1127 static BOOL
notify_if_changed(EDataFlow flow
, ERole role
, HKEY key
,
1128 const WCHAR
*val_name
, WCHAR
*old_val
, IMMDevice
*def_dev
)
1130 WCHAR new_val
[64], *id
;
1134 size
= sizeof(new_val
);
1135 if(RegQueryValueExW(key
, val_name
, 0, NULL
,
1136 (BYTE
*)new_val
, &size
) != ERROR_SUCCESS
){
1137 if(old_val
[0] != 0){
1138 /* set by user -> system default */
1140 hr
= IMMDevice_GetId(def_dev
, &id
);
1142 ERR("GetId failed: %08lx\n", hr
);
1148 notify_clients(flow
, role
, id
);
1155 /* system default -> system default, noop */
1159 if(!lstrcmpW(old_val
, new_val
)){
1160 /* set by user -> same value */
1164 if(new_val
[0] != 0){
1165 /* set by user -> different value */
1166 notify_clients(flow
, role
, new_val
);
1167 memcpy(old_val
, new_val
, sizeof(new_val
));
1171 /* set by user -> system default */
1173 hr
= IMMDevice_GetId(def_dev
, &id
);
1175 ERR("GetId failed: %08lx\n", hr
);
1181 notify_clients(flow
, role
, id
);
1188 static DWORD WINAPI
notif_thread_proc(void *user
)
1192 WCHAR out_name
[64], vout_name
[64], in_name
[64], vin_name
[64];
1195 SetThreadDescription(GetCurrentThread(), L
"wine_mmdevapi_notification");
1197 lstrcpyW(reg_key
, drv_keyW
);
1198 lstrcatW(reg_key
, L
"\\");
1199 lstrcatW(reg_key
, drvs
.module_name
);
1201 if(RegCreateKeyExW(HKEY_CURRENT_USER
, reg_key
, 0, NULL
, 0,
1202 MAXIMUM_ALLOWED
, NULL
, &key
, NULL
) != ERROR_SUCCESS
){
1203 ERR("RegCreateKeyEx failed: %lu\n", GetLastError());
1207 size
= sizeof(out_name
);
1208 if(RegQueryValueExW(key
, L
"DefaultOutput", 0, NULL
, (BYTE
*)out_name
, &size
) != ERROR_SUCCESS
)
1211 size
= sizeof(vout_name
);
1212 if(RegQueryValueExW(key
, L
"DefaultVoiceOutput", 0, NULL
, (BYTE
*)vout_name
, &size
) != ERROR_SUCCESS
)
1215 size
= sizeof(in_name
);
1216 if(RegQueryValueExW(key
, L
"DefaultInput", 0, NULL
, (BYTE
*)in_name
, &size
) != ERROR_SUCCESS
)
1219 size
= sizeof(vin_name
);
1220 if(RegQueryValueExW(key
, L
"DefaultVoiceInput", 0, NULL
, (BYTE
*)vin_name
, &size
) != ERROR_SUCCESS
)
1224 if(RegNotifyChangeKeyValue(key
, FALSE
, REG_NOTIFY_CHANGE_LAST_SET
,
1225 NULL
, FALSE
) != ERROR_SUCCESS
){
1226 ERR("RegNotifyChangeKeyValue failed: %lu\n", GetLastError());
1228 g_notif_thread
= NULL
;
1232 EnterCriticalSection(&g_notif_lock
);
1234 notify_if_changed(eRender
, eConsole
, key
, L
"DefaultOutput",
1235 out_name
, &MMDevice_def_play
->IMMDevice_iface
);
1236 notify_if_changed(eRender
, eCommunications
, key
, L
"DefaultVoiceOutput",
1237 vout_name
, &MMDevice_def_play
->IMMDevice_iface
);
1238 notify_if_changed(eCapture
, eConsole
, key
, L
"DefaultInput",
1239 in_name
, &MMDevice_def_rec
->IMMDevice_iface
);
1240 notify_if_changed(eCapture
, eCommunications
, key
, L
"DefaultVoiceInput",
1241 vin_name
, &MMDevice_def_rec
->IMMDevice_iface
);
1243 LeaveCriticalSection(&g_notif_lock
);
1248 g_notif_thread
= NULL
;
1253 static HRESULT WINAPI
MMDevEnum_RegisterEndpointNotificationCallback(IMMDeviceEnumerator
*iface
, IMMNotificationClient
*client
)
1255 MMDevEnumImpl
*This
= impl_from_IMMDeviceEnumerator(iface
);
1256 struct NotificationClientWrapper
*wrapper
;
1258 TRACE("(%p)->(%p)\n", This
, client
);
1263 wrapper
= HeapAlloc(GetProcessHeap(), 0, sizeof(*wrapper
));
1265 return E_OUTOFMEMORY
;
1267 wrapper
->client
= client
;
1269 EnterCriticalSection(&g_notif_lock
);
1271 list_add_tail(&g_notif_clients
, &wrapper
->entry
);
1273 if(!g_notif_thread
){
1274 g_notif_thread
= CreateThread(NULL
, 0, notif_thread_proc
, NULL
, 0, NULL
);
1276 ERR("CreateThread failed: %lu\n", GetLastError());
1279 LeaveCriticalSection(&g_notif_lock
);
1284 static HRESULT WINAPI
MMDevEnum_UnregisterEndpointNotificationCallback(IMMDeviceEnumerator
*iface
, IMMNotificationClient
*client
)
1286 MMDevEnumImpl
*This
= impl_from_IMMDeviceEnumerator(iface
);
1287 struct NotificationClientWrapper
*wrapper
;
1289 TRACE("(%p)->(%p)\n", This
, client
);
1294 EnterCriticalSection(&g_notif_lock
);
1296 LIST_FOR_EACH_ENTRY(wrapper
, &g_notif_clients
, struct NotificationClientWrapper
, entry
){
1297 if(wrapper
->client
== client
){
1298 list_remove(&wrapper
->entry
);
1299 HeapFree(GetProcessHeap(), 0, wrapper
);
1300 LeaveCriticalSection(&g_notif_lock
);
1305 LeaveCriticalSection(&g_notif_lock
);
1310 static const IMMDeviceEnumeratorVtbl MMDevEnumVtbl
=
1312 MMDevEnum_QueryInterface
,
1315 MMDevEnum_EnumAudioEndpoints
,
1316 MMDevEnum_GetDefaultAudioEndpoint
,
1317 MMDevEnum_GetDevice
,
1318 MMDevEnum_RegisterEndpointNotificationCallback
,
1319 MMDevEnum_UnregisterEndpointNotificationCallback
1322 static MMDevEnumImpl enumerator
=
1328 static HRESULT
MMDevPropStore_Create(MMDevice
*parent
, DWORD access
, IPropertyStore
**ppv
)
1330 MMDevPropStore
*This
;
1331 if (access
!= STGM_READ
1332 && access
!= STGM_WRITE
1333 && access
!= STGM_READWRITE
)
1335 WARN("Invalid access %08lx\n", access
);
1336 return E_INVALIDARG
;
1338 This
= HeapAlloc(GetProcessHeap(), 0, sizeof(*This
));
1339 *ppv
= &This
->IPropertyStore_iface
;
1341 return E_OUTOFMEMORY
;
1342 This
->IPropertyStore_iface
.lpVtbl
= &MMDevPropVtbl
;
1344 This
->parent
= parent
;
1345 This
->access
= access
;
1349 static void MMDevPropStore_Destroy(MMDevPropStore
*This
)
1351 HeapFree(GetProcessHeap(), 0, This
);
1354 static HRESULT WINAPI
MMDevPropStore_QueryInterface(IPropertyStore
*iface
, REFIID riid
, void **ppv
)
1356 MMDevPropStore
*This
= impl_from_IPropertyStore(iface
);
1357 TRACE("(%p)->(%s, %p)\n", This
, debugstr_guid(riid
), ppv
);
1361 if (IsEqualIID(riid
, &IID_IUnknown
)
1362 || IsEqualIID(riid
, &IID_IPropertyStore
))
1363 *ppv
= &This
->IPropertyStore_iface
;
1367 return E_NOINTERFACE
;
1368 IUnknown_AddRef((IUnknown
*)*ppv
);
1372 static ULONG WINAPI
MMDevPropStore_AddRef(IPropertyStore
*iface
)
1374 MMDevPropStore
*This
= impl_from_IPropertyStore(iface
);
1375 LONG ref
= InterlockedIncrement(&This
->ref
);
1376 TRACE("Refcount now %li\n", ref
);
1380 static ULONG WINAPI
MMDevPropStore_Release(IPropertyStore
*iface
)
1382 MMDevPropStore
*This
= impl_from_IPropertyStore(iface
);
1383 LONG ref
= InterlockedDecrement(&This
->ref
);
1384 TRACE("Refcount now %li\n", ref
);
1386 MMDevPropStore_Destroy(This
);
1390 static HRESULT WINAPI
MMDevPropStore_GetCount(IPropertyStore
*iface
, DWORD
*nprops
)
1392 MMDevPropStore
*This
= impl_from_IPropertyStore(iface
);
1398 TRACE("(%p)->(%p)\n", iface
, nprops
);
1401 hr
= MMDevPropStore_OpenPropKey(&This
->parent
->devguid
, This
->parent
->flow
, &propkey
);
1406 DWORD len
= ARRAY_SIZE(buffer
);
1407 if (RegEnumValueW(propkey
, i
, buffer
, &len
, NULL
, NULL
, NULL
, NULL
) != ERROR_SUCCESS
)
1411 RegCloseKey(propkey
);
1412 TRACE("Returning %li\n", i
);
1417 static HRESULT WINAPI
MMDevPropStore_GetAt(IPropertyStore
*iface
, DWORD prop
, PROPERTYKEY
*key
)
1419 MMDevPropStore
*This
= impl_from_IPropertyStore(iface
);
1421 DWORD len
= ARRAY_SIZE(buffer
);
1425 TRACE("(%p)->(%lu,%p)\n", iface
, prop
, key
);
1429 hr
= MMDevPropStore_OpenPropKey(&This
->parent
->devguid
, This
->parent
->flow
, &propkey
);
1433 if (RegEnumValueW(propkey
, prop
, buffer
, &len
, NULL
, NULL
, NULL
, NULL
) != ERROR_SUCCESS
1436 WARN("GetAt %lu failed\n", prop
);
1437 return E_INVALIDARG
;
1439 RegCloseKey(propkey
);
1441 CLSIDFromString(buffer
, &key
->fmtid
);
1442 key
->pid
= wcstol(&buffer
[39], NULL
, 10);
1446 static HRESULT WINAPI
MMDevPropStore_GetValue(IPropertyStore
*iface
, REFPROPERTYKEY key
, PROPVARIANT
*pv
)
1448 MMDevPropStore
*This
= impl_from_IPropertyStore(iface
);
1450 TRACE("(%p)->(\"%s,%lu\", %p)\n", This
, key
? debugstr_guid(&key
->fmtid
) : NULL
, key
? key
->pid
: 0, pv
);
1454 if (This
->access
!= STGM_READ
1455 && This
->access
!= STGM_READWRITE
)
1456 return STG_E_ACCESSDENIED
;
1459 if (IsEqualPropertyKey(*key
, PKEY_AudioEndpoint_GUID
))
1462 pv
->pwszVal
= CoTaskMemAlloc(39 * sizeof(WCHAR
));
1464 return E_OUTOFMEMORY
;
1465 StringFromGUID2(&This
->parent
->devguid
, pv
->pwszVal
, 39);
1469 hres
= MMDevice_GetPropValue(&This
->parent
->devguid
, This
->parent
->flow
, key
, pv
);
1473 if (WARN_ON(mmdevapi
))
1475 if ((IsEqualPropertyKey(*key
, DEVPKEY_Device_FriendlyName
) ||
1476 IsEqualPropertyKey(*key
, DEVPKEY_DeviceInterface_FriendlyName
) ||
1477 IsEqualPropertyKey(*key
, DEVPKEY_Device_DeviceDesc
)) &&
1478 pv
->vt
== VT_LPWSTR
&& wcslen(pv
->pwszVal
) > 62)
1479 WARN("Returned name exceeds length limit of some broken apps/libs, might crash: %s\n", debugstr_w(pv
->pwszVal
));
1484 static HRESULT WINAPI
MMDevPropStore_SetValue(IPropertyStore
*iface
, REFPROPERTYKEY key
, REFPROPVARIANT pv
)
1486 MMDevPropStore
*This
= impl_from_IPropertyStore(iface
);
1487 TRACE("(%p)->(\"%s,%lu\", %p)\n", This
, key
? debugstr_guid(&key
->fmtid
) : NULL
, key
? key
->pid
: 0, pv
);
1492 if (This
->access
!= STGM_WRITE
1493 && This
->access
!= STGM_READWRITE
)
1494 return STG_E_ACCESSDENIED
;
1495 return MMDevice_SetPropValue(&This
->parent
->devguid
, This
->parent
->flow
, key
, pv
);
1498 static HRESULT WINAPI
MMDevPropStore_Commit(IPropertyStore
*iface
)
1500 MMDevPropStore
*This
= impl_from_IPropertyStore(iface
);
1501 TRACE("(%p)\n", iface
);
1503 if (This
->access
!= STGM_WRITE
1504 && This
->access
!= STGM_READWRITE
)
1505 return STG_E_ACCESSDENIED
;
1507 /* Does nothing - for mmdevapi, the propstore values are written on SetValue,
1513 static const IPropertyStoreVtbl MMDevPropVtbl
=
1515 MMDevPropStore_QueryInterface
,
1516 MMDevPropStore_AddRef
,
1517 MMDevPropStore_Release
,
1518 MMDevPropStore_GetCount
,
1519 MMDevPropStore_GetAt
,
1520 MMDevPropStore_GetValue
,
1521 MMDevPropStore_SetValue
,
1522 MMDevPropStore_Commit
1526 /* Property bag for IBaseFilter activation */
1527 static HRESULT WINAPI
PB_QueryInterface(IPropertyBag
*iface
, REFIID riid
, void **ppv
)
1529 ERR("Should not be called\n");
1531 return E_NOINTERFACE
;
1534 static ULONG WINAPI
PB_AddRef(IPropertyBag
*iface
)
1536 ERR("Should not be called\n");
1540 static ULONG WINAPI
PB_Release(IPropertyBag
*iface
)
1542 ERR("Should not be called\n");
1546 static HRESULT WINAPI
PB_Read(IPropertyBag
*iface
, LPCOLESTR name
, VARIANT
*var
, IErrorLog
*log
)
1548 IPropertyBagImpl
*This
= impl_from_IPropertyBag(iface
);
1549 TRACE("Trying to read %s, type %u\n", debugstr_w(name
), var
->n1
.n2
.vt
);
1550 if (!lstrcmpW(name
, L
"DSGuid"))
1553 StringFromGUID2(&This
->devguid
, guidstr
,ARRAY_SIZE(guidstr
));
1554 var
->n1
.n2
.vt
= VT_BSTR
;
1555 var
->n1
.n2
.n3
.bstrVal
= SysAllocString(guidstr
);
1558 ERR("Unknown property '%s' queried\n", debugstr_w(name
));
1562 static HRESULT WINAPI
PB_Write(IPropertyBag
*iface
, LPCOLESTR name
, VARIANT
*var
)
1564 ERR("Should not be called\n");
1568 static const IPropertyBagVtbl PB_Vtbl
=
1577 static ULONG WINAPI
info_device_ps_AddRef(IPropertyStore
*iface
)
1582 static ULONG WINAPI
info_device_ps_Release(IPropertyStore
*iface
)
1587 static HRESULT WINAPI
info_device_ps_GetValue(IPropertyStore
*iface
,
1588 REFPROPERTYKEY key
, PROPVARIANT
*pv
)
1590 TRACE("(static)->(\"%s,%lu\", %p)\n", debugstr_guid(&key
->fmtid
), key
? key
->pid
: 0, pv
);
1595 if (IsEqualPropertyKey(*key
, DEVPKEY_Device_Driver
))
1597 INT size
= (lstrlenW(drvs
.module_name
) + 1) * sizeof(WCHAR
);
1599 pv
->pwszVal
= CoTaskMemAlloc(size
);
1601 return E_OUTOFMEMORY
;
1602 memcpy(pv
->pwszVal
, drvs
.module_name
, size
);
1606 return E_INVALIDARG
;
1609 static const IPropertyStoreVtbl info_device_ps_Vtbl
=
1612 info_device_ps_AddRef
,
1613 info_device_ps_Release
,
1616 info_device_ps_GetValue
,
1621 static IPropertyStore info_device_ps
= {
1622 &info_device_ps_Vtbl
1625 static ULONG WINAPI
info_device_AddRef(IMMDevice
*iface
)
1630 static ULONG WINAPI
info_device_Release(IMMDevice
*iface
)
1635 static HRESULT WINAPI
info_device_OpenPropertyStore(IMMDevice
*iface
,
1636 DWORD access
, IPropertyStore
**ppv
)
1638 TRACE("(static)->(%lx, %p)\n", access
, ppv
);
1639 *ppv
= &info_device_ps
;
1643 static const IMMDeviceVtbl info_device_Vtbl
=
1647 info_device_Release
,
1649 info_device_OpenPropertyStore
,
1654 static IMMDevice info_device
= {