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"
42 WINE_DEFAULT_DEBUG_CHANNEL(mmdevapi
);
44 static HKEY key_render
;
45 static HKEY key_capture
;
47 typedef struct MMDevPropStoreImpl
49 IPropertyStore IPropertyStore_iface
;
55 typedef struct MMDevEnumImpl
57 IMMDeviceEnumerator IMMDeviceEnumerator_iface
;
61 static MMDevEnumImpl
*MMDevEnumerator
;
62 static MMDevice
**MMDevice_head
;
63 static MMDevice
*MMDevice_def_rec
, *MMDevice_def_play
;
64 static DWORD MMDevice_count
;
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 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 %u\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 %u\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 %d\n", debugstr_w(buffer
), ret
);
153 PropVariantClear(pv
);
162 pv
->u
.pwszVal
= CoTaskMemAlloc(size
);
166 RegGetValueW(regkey
, NULL
, buffer
, RRF_RT_REG_SZ
, NULL
, (BYTE
*)pv
->u
.pwszVal
, &size
);
172 RegGetValueW(regkey
, NULL
, buffer
, RRF_RT_REG_DWORD
, NULL
, (BYTE
*)&pv
->u
.ulVal
, &size
);
178 pv
->u
.blob
.cbSize
= size
;
179 pv
->u
.blob
.pBlobData
= CoTaskMemAlloc(size
);
180 if (!pv
->u
.blob
.pBlobData
)
183 RegGetValueW(regkey
, NULL
, buffer
, RRF_RT_REG_BINARY
, NULL
, (BYTE
*)pv
->u
.blob
.pBlobData
, &size
);
187 ERR("Unknown/unhandled type: %u\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
->u
.ulVal
, sizeof(DWORD
));
218 ret
= RegSetValueExW(regkey
, buffer
, 0, REG_BINARY
, pv
->u
.blob
.pBlobData
, pv
->u
.blob
.cbSize
);
219 TRACE("Blob %p %u\n", pv
->u
.blob
.pBlobData
, pv
->u
.blob
.cbSize
);
225 ret
= RegSetValueExW(regkey
, buffer
, 0, REG_SZ
, (const BYTE
*)pv
->u
.pwszVal
, sizeof(WCHAR
)*(1+lstrlenW(pv
->u
.pwszVal
)));
230 FIXME("Unhandled type %u\n", pv
->vt
);
235 TRACE("Writing %s returned %u\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 /* Creates or updates the state of a device
259 * If GUID is null, a random guid will be assigned
260 * and the device will be created
262 static MMDevice
*MMDevice_Create(WCHAR
*name
, GUID
*id
, EDataFlow flow
, DWORD state
, BOOL setdefault
)
265 MMDevice
*cur
= NULL
;
269 static const PROPERTYKEY deviceinterface_key
= {
270 {0x233164c8, 0x1b2c, 0x4c7d, {0xbc, 0x68, 0xb6, 0x71, 0x68, 0x7a, 0x25, 0x67}}, 1
273 static const PROPERTYKEY devicepath_key
= {
274 {0xb3f8fa53, 0x0004, 0x438e, {0x90, 0x03, 0x51, 0xa4, 0x6e, 0x13, 0x9b, 0xfc}}, 2
277 for (i
= 0; i
< MMDevice_count
; ++i
)
279 MMDevice
*device
= MMDevice_head
[i
];
280 if (device
->flow
== flow
&& IsEqualGUID(&device
->devguid
, id
)){
287 /* No device found, allocate new one */
288 cur
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*cur
));
292 cur
->IMMDevice_iface
.lpVtbl
= &MMDeviceVtbl
;
293 cur
->IMMEndpoint_iface
.lpVtbl
= &MMEndpointVtbl
;
295 InitializeCriticalSection(&cur
->crst
);
296 cur
->crst
.DebugInfo
->Spare
[0] = (DWORD_PTR
)(__FILE__
": MMDevice.crst");
299 MMDevice_head
= HeapAlloc(GetProcessHeap(), 0, sizeof(*MMDevice_head
));
301 MMDevice_head
= HeapReAlloc(GetProcessHeap(), 0, MMDevice_head
, sizeof(*MMDevice_head
)*(1+MMDevice_count
));
302 MMDevice_head
[MMDevice_count
++] = cur
;
303 }else if(cur
->ref
> 0)
304 WARN("Modifying an MMDevice with postitive reference count!\n");
306 HeapFree(GetProcessHeap(), 0, cur
->drv_id
);
313 StringFromGUID2(&cur
->devguid
, guidstr
, ARRAY_SIZE(guidstr
));
320 if (RegCreateKeyExW(root
, guidstr
, 0, NULL
, 0, KEY_WRITE
|KEY_READ
|KEY_WOW64_64KEY
, NULL
, &key
, NULL
) == ERROR_SUCCESS
)
323 RegSetValueExW(key
, L
"DeviceState", 0, REG_DWORD
, (const BYTE
*)&state
, sizeof(DWORD
));
324 if (!RegCreateKeyExW(key
, L
"Properties", 0, NULL
, 0, KEY_WRITE
|KEY_READ
|KEY_WOW64_64KEY
, NULL
, &keyprop
, NULL
))
330 MMDevice_SetPropValue(id
, flow
, (const PROPERTYKEY
*)&DEVPKEY_Device_FriendlyName
, &pv
);
331 MMDevice_SetPropValue(id
, flow
, (const PROPERTYKEY
*)&DEVPKEY_DeviceInterface_FriendlyName
, &pv
);
332 MMDevice_SetPropValue(id
, flow
, (const PROPERTYKEY
*)&DEVPKEY_Device_DeviceDesc
, &pv
);
334 pv
.u
.pwszVal
= guidstr
;
335 MMDevice_SetPropValue(id
, flow
, &deviceinterface_key
, &pv
);
337 set_driver_prop_value(id
, flow
, &devicepath_key
);
339 if (FAILED(set_driver_prop_value(id
, flow
, &PKEY_AudioEndpoint_FormFactor
)))
342 pv
.u
.ulVal
= (flow
== eCapture
) ? Microphone
: Speakers
;
344 MMDevice_SetPropValue(id
, flow
, &PKEY_AudioEndpoint_FormFactor
, &pv
);
347 if (flow
!= eCapture
)
351 PropVariantInit(&pv2
);
353 /* make read-write by not overwriting if already set */
354 if (FAILED(MMDevice_GetPropValue(id
, flow
, &PKEY_AudioEndpoint_PhysicalSpeakers
, &pv2
)) || pv2
.vt
!= VT_UI4
)
355 set_driver_prop_value(id
, flow
, &PKEY_AudioEndpoint_PhysicalSpeakers
);
357 PropVariantClear(&pv2
);
360 RegCloseKey(keyprop
);
368 MMDevice_def_play
= cur
;
370 MMDevice_def_rec
= cur
;
375 static HRESULT
load_devices_from_reg(void)
382 ret
= RegCreateKeyExW(HKEY_LOCAL_MACHINE
,
383 L
"Software\\Microsoft\\Windows\\CurrentVersion\\MMDevices\\Audio", 0, NULL
, 0,
384 KEY_WRITE
|KEY_READ
|KEY_WOW64_64KEY
, NULL
, &root
, NULL
);
385 if (ret
== ERROR_SUCCESS
)
386 ret
= RegCreateKeyExW(root
, L
"Capture", 0, NULL
, 0, KEY_READ
|KEY_WRITE
|KEY_WOW64_64KEY
, NULL
, &key_capture
, NULL
);
387 if (ret
== ERROR_SUCCESS
)
388 ret
= RegCreateKeyExW(root
, L
"Render", 0, NULL
, 0, KEY_READ
|KEY_WRITE
|KEY_WOW64_64KEY
, NULL
, &key_render
, NULL
);
392 if (ret
!= ERROR_SUCCESS
)
394 RegCloseKey(key_capture
);
395 key_render
= key_capture
= NULL
;
396 WARN("Couldn't create key: %u\n", ret
);
404 PROPVARIANT pv
= { VT_EMPTY
};
406 len
= ARRAY_SIZE(guidvalue
);
407 ret
= RegEnumKeyExW(cur
, i
++, guidvalue
, &len
, NULL
, NULL
, NULL
, NULL
);
408 if (ret
== ERROR_NO_MORE_ITEMS
)
410 if (cur
== key_capture
)
419 if (ret
!= ERROR_SUCCESS
)
421 if (SUCCEEDED(CLSIDFromString(guidvalue
, &guid
))
422 && SUCCEEDED(MMDevice_GetPropValue(&guid
, curflow
, (const PROPERTYKEY
*)&DEVPKEY_Device_FriendlyName
, &pv
))
423 && pv
.vt
== VT_LPWSTR
)
425 DWORD size_bytes
= (lstrlenW(pv
.u
.pwszVal
) + 1) * sizeof(WCHAR
);
426 WCHAR
*name
= HeapAlloc(GetProcessHeap(), 0, size_bytes
);
427 memcpy(name
, pv
.u
.pwszVal
, size_bytes
);
428 MMDevice_Create(name
, &guid
, curflow
,
429 DEVICE_STATE_NOTPRESENT
, FALSE
);
430 CoTaskMemFree(pv
.u
.pwszVal
);
437 static HRESULT
set_format(MMDevice
*dev
)
440 IAudioClient
*client
;
442 PROPVARIANT pv
= { VT_EMPTY
};
444 hr
= drvs
.pGetAudioEndpoint(&dev
->devguid
, &dev
->IMMDevice_iface
, &client
);
448 hr
= IAudioClient_GetMixFormat(client
, &fmt
);
450 IAudioClient_Release(client
);
454 IAudioClient_Release(client
);
457 pv
.u
.blob
.cbSize
= sizeof(WAVEFORMATEX
) + fmt
->cbSize
;
458 pv
.u
.blob
.pBlobData
= (BYTE
*)fmt
;
459 MMDevice_SetPropValue(&dev
->devguid
, dev
->flow
,
460 &PKEY_AudioEngine_DeviceFormat
, &pv
);
461 MMDevice_SetPropValue(&dev
->devguid
, dev
->flow
,
462 &PKEY_AudioEngine_OEMFormat
, &pv
);
468 static HRESULT
load_driver_devices(EDataFlow flow
)
475 if(!drvs
.pGetEndpointIDs
)
478 hr
= drvs
.pGetEndpointIDs(flow
, &ids
, &guids
, &num
, &def
);
482 for(i
= 0; i
< num
; ++i
){
484 dev
= MMDevice_Create(ids
[i
], &guids
[i
], flow
, DEVICE_STATE_ACTIVE
,
489 HeapFree(GetProcessHeap(), 0, guids
);
490 HeapFree(GetProcessHeap(), 0, ids
);
495 static void MMDevice_Destroy(MMDevice
*This
)
498 TRACE("Freeing %s\n", debugstr_w(This
->drv_id
));
499 /* Since this function is called at destruction time, reordering of the list is unimportant */
500 for (i
= 0; i
< MMDevice_count
; ++i
)
502 if (MMDevice_head
[i
] == This
)
504 MMDevice_head
[i
] = MMDevice_head
[--MMDevice_count
];
508 This
->crst
.DebugInfo
->Spare
[0] = 0;
509 DeleteCriticalSection(&This
->crst
);
510 HeapFree(GetProcessHeap(), 0, This
->drv_id
);
511 HeapFree(GetProcessHeap(), 0, This
);
514 static inline MMDevice
*impl_from_IMMDevice(IMMDevice
*iface
)
516 return CONTAINING_RECORD(iface
, MMDevice
, IMMDevice_iface
);
519 static HRESULT WINAPI
MMDevice_QueryInterface(IMMDevice
*iface
, REFIID riid
, void **ppv
)
521 MMDevice
*This
= impl_from_IMMDevice(iface
);
522 TRACE("(%p)->(%s,%p)\n", iface
, debugstr_guid(riid
), ppv
);
527 if (IsEqualIID(riid
, &IID_IUnknown
)
528 || IsEqualIID(riid
, &IID_IMMDevice
))
529 *ppv
= &This
->IMMDevice_iface
;
530 else if (IsEqualIID(riid
, &IID_IMMEndpoint
))
531 *ppv
= &This
->IMMEndpoint_iface
;
534 IUnknown_AddRef((IUnknown
*)*ppv
);
537 WARN("Unknown interface %s\n", debugstr_guid(riid
));
538 return E_NOINTERFACE
;
541 static ULONG WINAPI
MMDevice_AddRef(IMMDevice
*iface
)
543 MMDevice
*This
= impl_from_IMMDevice(iface
);
546 ref
= InterlockedIncrement(&This
->ref
);
547 TRACE("Refcount now %i\n", ref
);
551 static ULONG WINAPI
MMDevice_Release(IMMDevice
*iface
)
553 MMDevice
*This
= impl_from_IMMDevice(iface
);
556 ref
= InterlockedDecrement(&This
->ref
);
557 TRACE("Refcount now %i\n", ref
);
561 static HRESULT WINAPI
MMDevice_Activate(IMMDevice
*iface
, REFIID riid
, DWORD clsctx
, PROPVARIANT
*params
, void **ppv
)
563 HRESULT hr
= E_NOINTERFACE
;
564 MMDevice
*This
= impl_from_IMMDevice(iface
);
566 TRACE("(%p)->(%s, %x, %p, %p)\n", iface
, debugstr_guid(riid
), clsctx
, params
, ppv
);
571 if (IsEqualIID(riid
, &IID_IAudioClient
) ||
572 IsEqualIID(riid
, &IID_IAudioClient2
) ||
573 IsEqualIID(riid
, &IID_IAudioClient3
)){
574 hr
= drvs
.pGetAudioEndpoint(&This
->devguid
, iface
, (IAudioClient
**)ppv
);
575 }else if (IsEqualIID(riid
, &IID_IAudioEndpointVolume
) ||
576 IsEqualIID(riid
, &IID_IAudioEndpointVolumeEx
))
577 hr
= AudioEndpointVolume_Create(This
, (IAudioEndpointVolumeEx
**)ppv
);
578 else if (IsEqualIID(riid
, &IID_IAudioSessionManager
)
579 || IsEqualIID(riid
, &IID_IAudioSessionManager2
))
581 hr
= drvs
.pGetAudioSessionManager(iface
, (IAudioSessionManager2
**)ppv
);
583 else if (IsEqualIID(riid
, &IID_IBaseFilter
))
585 if (This
->flow
== eRender
)
586 hr
= CoCreateInstance(&CLSID_DSoundRender
, NULL
, clsctx
, riid
, ppv
);
588 ERR("Not supported for recording?\n");
591 IPersistPropertyBag
*ppb
;
592 hr
= IUnknown_QueryInterface((IUnknown
*)*ppv
, &IID_IPersistPropertyBag
, (void **)&ppb
);
595 /* ::Load cannot assume the interface stays alive after the function returns,
596 * so just create the interface on the stack, saves a lot of complicated code */
597 IPropertyBagImpl bag
= { { &PB_Vtbl
} };
598 bag
.devguid
= This
->devguid
;
599 hr
= IPersistPropertyBag_Load(ppb
, &bag
.IPropertyBag_iface
, NULL
);
600 IPersistPropertyBag_Release(ppb
);
602 IBaseFilter_Release((IBaseFilter
*)*ppv
);
606 FIXME("Wine doesn't support IPersistPropertyBag on DSoundRender yet, ignoring..\n");
611 else if (IsEqualIID(riid
, &IID_IDeviceTopology
))
613 FIXME("IID_IDeviceTopology unsupported\n");
615 else if (IsEqualIID(riid
, &IID_IDirectSound
)
616 || IsEqualIID(riid
, &IID_IDirectSound8
))
618 if (This
->flow
== eRender
)
619 hr
= CoCreateInstance(&CLSID_DirectSound8
, NULL
, clsctx
, riid
, ppv
);
622 hr
= IDirectSound_Initialize((IDirectSound
*)*ppv
, &This
->devguid
);
624 IDirectSound_Release((IDirectSound
*)*ppv
);
627 else if (IsEqualIID(riid
, &IID_IDirectSoundCapture
))
629 if (This
->flow
== eCapture
)
630 hr
= CoCreateInstance(&CLSID_DirectSoundCapture8
, NULL
, clsctx
, riid
, ppv
);
633 hr
= IDirectSoundCapture_Initialize((IDirectSoundCapture
*)*ppv
, &This
->devguid
);
635 IDirectSoundCapture_Release((IDirectSoundCapture
*)*ppv
);
639 ERR("Invalid/unknown iid %s\n", debugstr_guid(riid
));
644 TRACE("Returning %08x\n", hr
);
648 static HRESULT WINAPI
MMDevice_OpenPropertyStore(IMMDevice
*iface
, DWORD access
, IPropertyStore
**ppv
)
650 MMDevice
*This
= impl_from_IMMDevice(iface
);
651 TRACE("(%p)->(%x,%p)\n", This
, access
, ppv
);
655 return MMDevPropStore_Create(This
, access
, ppv
);
658 static HRESULT WINAPI
MMDevice_GetId(IMMDevice
*iface
, WCHAR
**itemid
)
660 MMDevice
*This
= impl_from_IMMDevice(iface
);
662 GUID
*id
= &This
->devguid
;
664 TRACE("(%p)->(%p)\n", This
, itemid
);
667 *itemid
= str
= CoTaskMemAlloc(56 * sizeof(WCHAR
));
669 return E_OUTOFMEMORY
;
670 wsprintfW(str
, L
"{0.0.%u.00000000}.{%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X}",
671 This
->flow
, id
->Data1
, id
->Data2
, id
->Data3
,
672 id
->Data4
[0], id
->Data4
[1], id
->Data4
[2], id
->Data4
[3],
673 id
->Data4
[4], id
->Data4
[5], id
->Data4
[6], id
->Data4
[7]);
674 TRACE("returning %s\n", wine_dbgstr_w(str
));
678 static HRESULT WINAPI
MMDevice_GetState(IMMDevice
*iface
, DWORD
*state
)
680 MMDevice
*This
= impl_from_IMMDevice(iface
);
681 TRACE("(%p)->(%p)\n", iface
, state
);
685 *state
= This
->state
;
689 static const IMMDeviceVtbl MMDeviceVtbl
=
691 MMDevice_QueryInterface
,
695 MMDevice_OpenPropertyStore
,
700 static inline MMDevice
*impl_from_IMMEndpoint(IMMEndpoint
*iface
)
702 return CONTAINING_RECORD(iface
, MMDevice
, IMMEndpoint_iface
);
705 static HRESULT WINAPI
MMEndpoint_QueryInterface(IMMEndpoint
*iface
, REFIID riid
, void **ppv
)
707 MMDevice
*This
= impl_from_IMMEndpoint(iface
);
708 TRACE("(%p)->(%s, %p)\n", This
, debugstr_guid(riid
), ppv
);
709 return IMMDevice_QueryInterface(&This
->IMMDevice_iface
, riid
, ppv
);
712 static ULONG WINAPI
MMEndpoint_AddRef(IMMEndpoint
*iface
)
714 MMDevice
*This
= impl_from_IMMEndpoint(iface
);
715 TRACE("(%p)\n", This
);
716 return IMMDevice_AddRef(&This
->IMMDevice_iface
);
719 static ULONG WINAPI
MMEndpoint_Release(IMMEndpoint
*iface
)
721 MMDevice
*This
= impl_from_IMMEndpoint(iface
);
722 TRACE("(%p)\n", This
);
723 return IMMDevice_Release(&This
->IMMDevice_iface
);
726 static HRESULT WINAPI
MMEndpoint_GetDataFlow(IMMEndpoint
*iface
, EDataFlow
*flow
)
728 MMDevice
*This
= impl_from_IMMEndpoint(iface
);
729 TRACE("(%p)->(%p)\n", This
, flow
);
736 static const IMMEndpointVtbl MMEndpointVtbl
=
738 MMEndpoint_QueryInterface
,
741 MMEndpoint_GetDataFlow
744 static HRESULT
MMDevCol_Create(IMMDeviceCollection
**ppv
, EDataFlow flow
, DWORD state
)
748 This
= HeapAlloc(GetProcessHeap(), 0, sizeof(*This
));
751 return E_OUTOFMEMORY
;
752 This
->IMMDeviceCollection_iface
.lpVtbl
= &MMDevColVtbl
;
756 *ppv
= &This
->IMMDeviceCollection_iface
;
760 static void MMDevCol_Destroy(MMDevColImpl
*This
)
762 HeapFree(GetProcessHeap(), 0, This
);
765 static HRESULT WINAPI
MMDevCol_QueryInterface(IMMDeviceCollection
*iface
, REFIID riid
, void **ppv
)
767 MMDevColImpl
*This
= impl_from_IMMDeviceCollection(iface
);
768 TRACE("(%p)->(%s, %p)\n", This
, debugstr_guid(riid
), ppv
);
772 if (IsEqualIID(riid
, &IID_IUnknown
)
773 || IsEqualIID(riid
, &IID_IMMDeviceCollection
))
774 *ppv
= &This
->IMMDeviceCollection_iface
;
778 return E_NOINTERFACE
;
779 IUnknown_AddRef((IUnknown
*)*ppv
);
783 static ULONG WINAPI
MMDevCol_AddRef(IMMDeviceCollection
*iface
)
785 MMDevColImpl
*This
= impl_from_IMMDeviceCollection(iface
);
786 LONG ref
= InterlockedIncrement(&This
->ref
);
787 TRACE("Refcount now %i\n", ref
);
791 static ULONG WINAPI
MMDevCol_Release(IMMDeviceCollection
*iface
)
793 MMDevColImpl
*This
= impl_from_IMMDeviceCollection(iface
);
794 LONG ref
= InterlockedDecrement(&This
->ref
);
795 TRACE("Refcount now %i\n", ref
);
797 MMDevCol_Destroy(This
);
801 static HRESULT WINAPI
MMDevCol_GetCount(IMMDeviceCollection
*iface
, UINT
*numdevs
)
803 MMDevColImpl
*This
= impl_from_IMMDeviceCollection(iface
);
806 TRACE("(%p)->(%p)\n", This
, numdevs
);
811 for (i
= 0; i
< MMDevice_count
; ++i
)
813 MMDevice
*cur
= MMDevice_head
[i
];
814 if ((cur
->flow
== This
->flow
|| This
->flow
== eAll
)
815 && (cur
->state
& This
->state
))
821 static HRESULT WINAPI
MMDevCol_Item(IMMDeviceCollection
*iface
, UINT n
, IMMDevice
**dev
)
823 MMDevColImpl
*This
= impl_from_IMMDeviceCollection(iface
);
826 TRACE("(%p)->(%u, %p)\n", This
, n
, dev
);
830 for (j
= 0; j
< MMDevice_count
; ++j
)
832 MMDevice
*cur
= MMDevice_head
[j
];
833 if ((cur
->flow
== This
->flow
|| This
->flow
== eAll
)
834 && (cur
->state
& This
->state
)
837 *dev
= &cur
->IMMDevice_iface
;
838 IMMDevice_AddRef(*dev
);
842 WARN("Could not obtain item %u\n", n
);
847 static const IMMDeviceCollectionVtbl MMDevColVtbl
=
849 MMDevCol_QueryInterface
,
856 HRESULT
MMDevEnum_Create(REFIID riid
, void **ppv
)
858 MMDevEnumImpl
*This
= MMDevEnumerator
;
862 This
= HeapAlloc(GetProcessHeap(), 0, sizeof(*This
));
865 return E_OUTOFMEMORY
;
867 This
->IMMDeviceEnumerator_iface
.lpVtbl
= &MMDevEnumVtbl
;
868 MMDevEnumerator
= This
;
870 load_devices_from_reg();
871 load_driver_devices(eRender
);
872 load_driver_devices(eCapture
);
874 return IMMDeviceEnumerator_QueryInterface(&This
->IMMDeviceEnumerator_iface
, riid
, ppv
);
877 void MMDevEnum_Free(void)
879 while (MMDevice_count
)
880 MMDevice_Destroy(MMDevice_head
[0]);
881 RegCloseKey(key_render
);
882 RegCloseKey(key_capture
);
883 key_render
= key_capture
= NULL
;
884 HeapFree(GetProcessHeap(), 0, MMDevEnumerator
);
885 MMDevEnumerator
= NULL
;
888 static HRESULT WINAPI
MMDevEnum_QueryInterface(IMMDeviceEnumerator
*iface
, REFIID riid
, void **ppv
)
890 MMDevEnumImpl
*This
= impl_from_IMMDeviceEnumerator(iface
);
891 TRACE("(%p)->(%s, %p)\n", This
, debugstr_guid(riid
), ppv
);
895 if (IsEqualIID(riid
, &IID_IUnknown
)
896 || IsEqualIID(riid
, &IID_IMMDeviceEnumerator
))
897 *ppv
= &This
->IMMDeviceEnumerator_iface
;
901 return E_NOINTERFACE
;
902 IUnknown_AddRef((IUnknown
*)*ppv
);
906 static ULONG WINAPI
MMDevEnum_AddRef(IMMDeviceEnumerator
*iface
)
908 MMDevEnumImpl
*This
= impl_from_IMMDeviceEnumerator(iface
);
909 LONG ref
= InterlockedIncrement(&This
->ref
);
910 TRACE("Refcount now %i\n", ref
);
914 static ULONG WINAPI
MMDevEnum_Release(IMMDeviceEnumerator
*iface
)
916 MMDevEnumImpl
*This
= impl_from_IMMDeviceEnumerator(iface
);
917 LONG ref
= InterlockedDecrement(&This
->ref
);
920 TRACE("Refcount now %i\n", ref
);
924 static HRESULT WINAPI
MMDevEnum_EnumAudioEndpoints(IMMDeviceEnumerator
*iface
, EDataFlow flow
, DWORD mask
, IMMDeviceCollection
**devices
)
926 MMDevEnumImpl
*This
= impl_from_IMMDeviceEnumerator(iface
);
927 TRACE("(%p)->(%u,%u,%p)\n", This
, flow
, mask
, devices
);
931 if (flow
>= EDataFlow_enum_count
)
933 if (mask
& ~DEVICE_STATEMASK_ALL
)
935 return MMDevCol_Create(devices
, flow
, mask
);
938 static HRESULT WINAPI
MMDevEnum_GetDefaultAudioEndpoint(IMMDeviceEnumerator
*iface
, EDataFlow flow
, ERole role
, IMMDevice
**device
)
940 MMDevEnumImpl
*This
= impl_from_IMMDeviceEnumerator(iface
);
945 TRACE("(%p)->(%u,%u,%p)\n", This
, flow
, role
, device
);
950 if((flow
!= eRender
&& flow
!= eCapture
) ||
951 (role
!= eConsole
&& role
!= eMultimedia
&& role
!= eCommunications
)){
952 WARN("Unknown flow (%u) or role (%u)\n", flow
, role
);
958 if(!drvs
.module_name
[0])
961 lstrcpyW(reg_key
, drv_keyW
);
962 lstrcatW(reg_key
, L
"\\");
963 lstrcatW(reg_key
, drvs
.module_name
);
965 if(RegOpenKeyW(HKEY_CURRENT_USER
, reg_key
, &key
) == ERROR_SUCCESS
){
966 const WCHAR
*reg_x_name
, *reg_vx_name
;
968 DWORD size
= sizeof(def_id
), state
;
971 reg_x_name
= L
"DefaultOutput";
972 reg_vx_name
= L
"DefaultVoiceOutput";
974 reg_x_name
= L
"DefaultInput";
975 reg_vx_name
= L
"DefaultVoiceInput";
978 if(role
== eCommunications
&&
979 RegQueryValueExW(key
, reg_vx_name
, 0, NULL
,
980 (BYTE
*)def_id
, &size
) == ERROR_SUCCESS
){
981 hr
= IMMDeviceEnumerator_GetDevice(iface
, def_id
, device
);
983 if(SUCCEEDED(IMMDevice_GetState(*device
, &state
)) &&
984 state
== DEVICE_STATE_ACTIVE
){
990 TRACE("Unable to find voice device %s\n", wine_dbgstr_w(def_id
));
993 if(RegQueryValueExW(key
, reg_x_name
, 0, NULL
,
994 (BYTE
*)def_id
, &size
) == ERROR_SUCCESS
){
995 hr
= IMMDeviceEnumerator_GetDevice(iface
, def_id
, device
);
997 if(SUCCEEDED(IMMDevice_GetState(*device
, &state
)) &&
998 state
== DEVICE_STATE_ACTIVE
){
1004 TRACE("Unable to find device %s\n", wine_dbgstr_w(def_id
));
1010 if (flow
== eRender
)
1011 *device
= &MMDevice_def_play
->IMMDevice_iface
;
1013 *device
= &MMDevice_def_rec
->IMMDevice_iface
;
1017 IMMDevice_AddRef(*device
);
1021 static HRESULT WINAPI
MMDevEnum_GetDevice(IMMDeviceEnumerator
*iface
, const WCHAR
*name
, IMMDevice
**device
)
1023 MMDevEnumImpl
*This
= impl_from_IMMDeviceEnumerator(iface
);
1025 IMMDevice
*dev
= NULL
;
1027 TRACE("(%p)->(%s,%p)\n", This
, debugstr_w(name
), device
);
1029 if(!name
|| !device
)
1032 if(!lstrcmpW(name
, L
"Wine info device")){
1033 *device
= &info_device
;
1037 for (i
= 0; i
< MMDevice_count
; ++i
)
1041 dev
= &MMDevice_head
[i
]->IMMDevice_iface
;
1042 hr
= IMMDevice_GetId(dev
, &str
);
1045 WARN("GetId failed: %08x\n", hr
);
1049 if (str
&& !lstrcmpW(str
, name
))
1052 IMMDevice_AddRef(dev
);
1058 TRACE("Could not find device %s\n", debugstr_w(name
));
1059 return E_INVALIDARG
;
1062 struct NotificationClientWrapper
{
1063 IMMNotificationClient
*client
;
1067 static struct list g_notif_clients
= LIST_INIT(g_notif_clients
);
1068 static HANDLE g_notif_thread
;
1070 static CRITICAL_SECTION g_notif_lock
;
1071 static CRITICAL_SECTION_DEBUG g_notif_lock_debug
=
1073 0, 0, &g_notif_lock
,
1074 { &g_notif_lock_debug
.ProcessLocksList
, &g_notif_lock_debug
.ProcessLocksList
},
1075 0, 0, { (DWORD_PTR
)(__FILE__
": g_notif_lock") }
1077 static CRITICAL_SECTION g_notif_lock
= { &g_notif_lock_debug
, -1, 0, 0, 0, 0 };
1079 static void notify_clients(EDataFlow flow
, ERole role
, const WCHAR
*id
)
1081 struct NotificationClientWrapper
*wrapper
;
1082 LIST_FOR_EACH_ENTRY(wrapper
, &g_notif_clients
,
1083 struct NotificationClientWrapper
, entry
)
1084 IMMNotificationClient_OnDefaultDeviceChanged(wrapper
->client
, flow
,
1087 /* Windows 7 treats changes to eConsole as changes to eMultimedia */
1088 if(role
== eConsole
)
1089 notify_clients(flow
, eMultimedia
, id
);
1092 static BOOL
notify_if_changed(EDataFlow flow
, ERole role
, HKEY key
,
1093 const WCHAR
*val_name
, WCHAR
*old_val
, IMMDevice
*def_dev
)
1095 WCHAR new_val
[64], *id
;
1099 size
= sizeof(new_val
);
1100 if(RegQueryValueExW(key
, val_name
, 0, NULL
,
1101 (BYTE
*)new_val
, &size
) != ERROR_SUCCESS
){
1102 if(old_val
[0] != 0){
1103 /* set by user -> system default */
1105 hr
= IMMDevice_GetId(def_dev
, &id
);
1107 ERR("GetId failed: %08x\n", hr
);
1113 notify_clients(flow
, role
, id
);
1120 /* system default -> system default, noop */
1124 if(!lstrcmpW(old_val
, new_val
)){
1125 /* set by user -> same value */
1129 if(new_val
[0] != 0){
1130 /* set by user -> different value */
1131 notify_clients(flow
, role
, new_val
);
1132 memcpy(old_val
, new_val
, sizeof(new_val
));
1136 /* set by user -> system default */
1138 hr
= IMMDevice_GetId(def_dev
, &id
);
1140 ERR("GetId failed: %08x\n", hr
);
1146 notify_clients(flow
, role
, id
);
1153 static DWORD WINAPI
notif_thread_proc(void *user
)
1157 WCHAR out_name
[64], vout_name
[64], in_name
[64], vin_name
[64];
1160 lstrcpyW(reg_key
, drv_keyW
);
1161 lstrcatW(reg_key
, L
"\\");
1162 lstrcatW(reg_key
, drvs
.module_name
);
1164 if(RegCreateKeyExW(HKEY_CURRENT_USER
, reg_key
, 0, NULL
, 0,
1165 MAXIMUM_ALLOWED
, NULL
, &key
, NULL
) != ERROR_SUCCESS
){
1166 ERR("RegCreateKeyEx failed: %u\n", GetLastError());
1170 size
= sizeof(out_name
);
1171 if(RegQueryValueExW(key
, L
"DefaultOutput", 0, NULL
, (BYTE
*)out_name
, &size
) != ERROR_SUCCESS
)
1174 size
= sizeof(vout_name
);
1175 if(RegQueryValueExW(key
, L
"DefaultVoiceOutput", 0, NULL
, (BYTE
*)vout_name
, &size
) != ERROR_SUCCESS
)
1178 size
= sizeof(in_name
);
1179 if(RegQueryValueExW(key
, L
"DefaultInput", 0, NULL
, (BYTE
*)in_name
, &size
) != ERROR_SUCCESS
)
1182 size
= sizeof(vin_name
);
1183 if(RegQueryValueExW(key
, L
"DefaultVoiceInput", 0, NULL
, (BYTE
*)vin_name
, &size
) != ERROR_SUCCESS
)
1187 if(RegNotifyChangeKeyValue(key
, FALSE
, REG_NOTIFY_CHANGE_LAST_SET
,
1188 NULL
, FALSE
) != ERROR_SUCCESS
){
1189 ERR("RegNotifyChangeKeyValue failed: %u\n", GetLastError());
1191 g_notif_thread
= NULL
;
1195 EnterCriticalSection(&g_notif_lock
);
1197 notify_if_changed(eRender
, eConsole
, key
, L
"DefaultOutput",
1198 out_name
, &MMDevice_def_play
->IMMDevice_iface
);
1199 notify_if_changed(eRender
, eCommunications
, key
, L
"DefaultVoiceOutput",
1200 vout_name
, &MMDevice_def_play
->IMMDevice_iface
);
1201 notify_if_changed(eCapture
, eConsole
, key
, L
"DefaultInput",
1202 in_name
, &MMDevice_def_rec
->IMMDevice_iface
);
1203 notify_if_changed(eCapture
, eCommunications
, key
, L
"DefaultVoiceInput",
1204 vin_name
, &MMDevice_def_rec
->IMMDevice_iface
);
1206 LeaveCriticalSection(&g_notif_lock
);
1211 g_notif_thread
= NULL
;
1216 static HRESULT WINAPI
MMDevEnum_RegisterEndpointNotificationCallback(IMMDeviceEnumerator
*iface
, IMMNotificationClient
*client
)
1218 MMDevEnumImpl
*This
= impl_from_IMMDeviceEnumerator(iface
);
1219 struct NotificationClientWrapper
*wrapper
;
1221 TRACE("(%p)->(%p)\n", This
, client
);
1226 wrapper
= HeapAlloc(GetProcessHeap(), 0, sizeof(*wrapper
));
1228 return E_OUTOFMEMORY
;
1230 wrapper
->client
= client
;
1232 EnterCriticalSection(&g_notif_lock
);
1234 list_add_tail(&g_notif_clients
, &wrapper
->entry
);
1236 if(!g_notif_thread
){
1237 g_notif_thread
= CreateThread(NULL
, 0, notif_thread_proc
, NULL
, 0, NULL
);
1239 ERR("CreateThread failed: %u\n", GetLastError());
1242 LeaveCriticalSection(&g_notif_lock
);
1247 static HRESULT WINAPI
MMDevEnum_UnregisterEndpointNotificationCallback(IMMDeviceEnumerator
*iface
, IMMNotificationClient
*client
)
1249 MMDevEnumImpl
*This
= impl_from_IMMDeviceEnumerator(iface
);
1250 struct NotificationClientWrapper
*wrapper
;
1252 TRACE("(%p)->(%p)\n", This
, client
);
1257 EnterCriticalSection(&g_notif_lock
);
1259 LIST_FOR_EACH_ENTRY(wrapper
, &g_notif_clients
, struct NotificationClientWrapper
, entry
){
1260 if(wrapper
->client
== client
){
1261 list_remove(&wrapper
->entry
);
1262 HeapFree(GetProcessHeap(), 0, wrapper
);
1263 LeaveCriticalSection(&g_notif_lock
);
1268 LeaveCriticalSection(&g_notif_lock
);
1273 static const IMMDeviceEnumeratorVtbl MMDevEnumVtbl
=
1275 MMDevEnum_QueryInterface
,
1278 MMDevEnum_EnumAudioEndpoints
,
1279 MMDevEnum_GetDefaultAudioEndpoint
,
1280 MMDevEnum_GetDevice
,
1281 MMDevEnum_RegisterEndpointNotificationCallback
,
1282 MMDevEnum_UnregisterEndpointNotificationCallback
1285 static HRESULT
MMDevPropStore_Create(MMDevice
*parent
, DWORD access
, IPropertyStore
**ppv
)
1287 MMDevPropStore
*This
;
1288 if (access
!= STGM_READ
1289 && access
!= STGM_WRITE
1290 && access
!= STGM_READWRITE
)
1292 WARN("Invalid access %08x\n", access
);
1293 return E_INVALIDARG
;
1295 This
= HeapAlloc(GetProcessHeap(), 0, sizeof(*This
));
1296 *ppv
= &This
->IPropertyStore_iface
;
1298 return E_OUTOFMEMORY
;
1299 This
->IPropertyStore_iface
.lpVtbl
= &MMDevPropVtbl
;
1301 This
->parent
= parent
;
1302 This
->access
= access
;
1306 static void MMDevPropStore_Destroy(MMDevPropStore
*This
)
1308 HeapFree(GetProcessHeap(), 0, This
);
1311 static HRESULT WINAPI
MMDevPropStore_QueryInterface(IPropertyStore
*iface
, REFIID riid
, void **ppv
)
1313 MMDevPropStore
*This
= impl_from_IPropertyStore(iface
);
1314 TRACE("(%p)->(%s, %p)\n", This
, debugstr_guid(riid
), ppv
);
1318 if (IsEqualIID(riid
, &IID_IUnknown
)
1319 || IsEqualIID(riid
, &IID_IPropertyStore
))
1320 *ppv
= &This
->IPropertyStore_iface
;
1324 return E_NOINTERFACE
;
1325 IUnknown_AddRef((IUnknown
*)*ppv
);
1329 static ULONG WINAPI
MMDevPropStore_AddRef(IPropertyStore
*iface
)
1331 MMDevPropStore
*This
= impl_from_IPropertyStore(iface
);
1332 LONG ref
= InterlockedIncrement(&This
->ref
);
1333 TRACE("Refcount now %i\n", ref
);
1337 static ULONG WINAPI
MMDevPropStore_Release(IPropertyStore
*iface
)
1339 MMDevPropStore
*This
= impl_from_IPropertyStore(iface
);
1340 LONG ref
= InterlockedDecrement(&This
->ref
);
1341 TRACE("Refcount now %i\n", ref
);
1343 MMDevPropStore_Destroy(This
);
1347 static HRESULT WINAPI
MMDevPropStore_GetCount(IPropertyStore
*iface
, DWORD
*nprops
)
1349 MMDevPropStore
*This
= impl_from_IPropertyStore(iface
);
1355 TRACE("(%p)->(%p)\n", iface
, nprops
);
1358 hr
= MMDevPropStore_OpenPropKey(&This
->parent
->devguid
, This
->parent
->flow
, &propkey
);
1363 DWORD len
= ARRAY_SIZE(buffer
);
1364 if (RegEnumValueW(propkey
, i
, buffer
, &len
, NULL
, NULL
, NULL
, NULL
) != ERROR_SUCCESS
)
1368 RegCloseKey(propkey
);
1369 TRACE("Returning %i\n", i
);
1374 static HRESULT WINAPI
MMDevPropStore_GetAt(IPropertyStore
*iface
, DWORD prop
, PROPERTYKEY
*key
)
1376 MMDevPropStore
*This
= impl_from_IPropertyStore(iface
);
1378 DWORD len
= ARRAY_SIZE(buffer
);
1382 TRACE("(%p)->(%u,%p)\n", iface
, prop
, key
);
1386 hr
= MMDevPropStore_OpenPropKey(&This
->parent
->devguid
, This
->parent
->flow
, &propkey
);
1390 if (RegEnumValueW(propkey
, prop
, buffer
, &len
, NULL
, NULL
, NULL
, NULL
) != ERROR_SUCCESS
1393 WARN("GetAt %u failed\n", prop
);
1394 return E_INVALIDARG
;
1396 RegCloseKey(propkey
);
1398 CLSIDFromString(buffer
, &key
->fmtid
);
1399 key
->pid
= wcstol(&buffer
[39], NULL
, 10);
1403 static HRESULT WINAPI
MMDevPropStore_GetValue(IPropertyStore
*iface
, REFPROPERTYKEY key
, PROPVARIANT
*pv
)
1405 MMDevPropStore
*This
= impl_from_IPropertyStore(iface
);
1406 TRACE("(%p)->(\"%s,%u\", %p)\n", This
, key
? debugstr_guid(&key
->fmtid
) : NULL
, key
? key
->pid
: 0, pv
);
1410 if (This
->access
!= STGM_READ
1411 && This
->access
!= STGM_READWRITE
)
1412 return STG_E_ACCESSDENIED
;
1415 if (IsEqualPropertyKey(*key
, PKEY_AudioEndpoint_GUID
))
1418 pv
->u
.pwszVal
= CoTaskMemAlloc(39 * sizeof(WCHAR
));
1420 return E_OUTOFMEMORY
;
1421 StringFromGUID2(&This
->parent
->devguid
, pv
->u
.pwszVal
, 39);
1425 return MMDevice_GetPropValue(&This
->parent
->devguid
, This
->parent
->flow
, key
, pv
);
1428 static HRESULT WINAPI
MMDevPropStore_SetValue(IPropertyStore
*iface
, REFPROPERTYKEY key
, REFPROPVARIANT pv
)
1430 MMDevPropStore
*This
= impl_from_IPropertyStore(iface
);
1431 TRACE("(%p)->(\"%s,%u\", %p)\n", This
, key
? debugstr_guid(&key
->fmtid
) : NULL
, key
? key
->pid
: 0, pv
);
1436 if (This
->access
!= STGM_WRITE
1437 && This
->access
!= STGM_READWRITE
)
1438 return STG_E_ACCESSDENIED
;
1439 return MMDevice_SetPropValue(&This
->parent
->devguid
, This
->parent
->flow
, key
, pv
);
1442 static HRESULT WINAPI
MMDevPropStore_Commit(IPropertyStore
*iface
)
1444 MMDevPropStore
*This
= impl_from_IPropertyStore(iface
);
1445 TRACE("(%p)\n", iface
);
1447 if (This
->access
!= STGM_WRITE
1448 && This
->access
!= STGM_READWRITE
)
1449 return STG_E_ACCESSDENIED
;
1451 /* Does nothing - for mmdevapi, the propstore values are written on SetValue,
1457 static const IPropertyStoreVtbl MMDevPropVtbl
=
1459 MMDevPropStore_QueryInterface
,
1460 MMDevPropStore_AddRef
,
1461 MMDevPropStore_Release
,
1462 MMDevPropStore_GetCount
,
1463 MMDevPropStore_GetAt
,
1464 MMDevPropStore_GetValue
,
1465 MMDevPropStore_SetValue
,
1466 MMDevPropStore_Commit
1470 /* Property bag for IBaseFilter activation */
1471 static HRESULT WINAPI
PB_QueryInterface(IPropertyBag
*iface
, REFIID riid
, void **ppv
)
1473 ERR("Should not be called\n");
1475 return E_NOINTERFACE
;
1478 static ULONG WINAPI
PB_AddRef(IPropertyBag
*iface
)
1480 ERR("Should not be called\n");
1484 static ULONG WINAPI
PB_Release(IPropertyBag
*iface
)
1486 ERR("Should not be called\n");
1490 static HRESULT WINAPI
PB_Read(IPropertyBag
*iface
, LPCOLESTR name
, VARIANT
*var
, IErrorLog
*log
)
1492 IPropertyBagImpl
*This
= impl_from_IPropertyBag(iface
);
1493 TRACE("Trying to read %s, type %u\n", debugstr_w(name
), var
->n1
.n2
.vt
);
1494 if (!lstrcmpW(name
, L
"DSGuid"))
1497 StringFromGUID2(&This
->devguid
, guidstr
,ARRAY_SIZE(guidstr
));
1498 var
->n1
.n2
.vt
= VT_BSTR
;
1499 var
->n1
.n2
.n3
.bstrVal
= SysAllocString(guidstr
);
1502 ERR("Unknown property '%s' queried\n", debugstr_w(name
));
1506 static HRESULT WINAPI
PB_Write(IPropertyBag
*iface
, LPCOLESTR name
, VARIANT
*var
)
1508 ERR("Should not be called\n");
1512 static const IPropertyBagVtbl PB_Vtbl
=
1521 static ULONG WINAPI
info_device_ps_AddRef(IPropertyStore
*iface
)
1526 static ULONG WINAPI
info_device_ps_Release(IPropertyStore
*iface
)
1531 static HRESULT WINAPI
info_device_ps_GetValue(IPropertyStore
*iface
,
1532 REFPROPERTYKEY key
, PROPVARIANT
*pv
)
1534 TRACE("(static)->(\"%s,%u\", %p)\n", debugstr_guid(&key
->fmtid
), key
? key
->pid
: 0, pv
);
1539 if (IsEqualPropertyKey(*key
, DEVPKEY_Device_Driver
))
1541 INT size
= (lstrlenW(drvs
.module_name
) + 1) * sizeof(WCHAR
);
1543 pv
->u
.pwszVal
= CoTaskMemAlloc(size
);
1545 return E_OUTOFMEMORY
;
1546 memcpy(pv
->u
.pwszVal
, drvs
.module_name
, size
);
1550 return E_INVALIDARG
;
1553 static const IPropertyStoreVtbl info_device_ps_Vtbl
=
1556 info_device_ps_AddRef
,
1557 info_device_ps_Release
,
1560 info_device_ps_GetValue
,
1565 static IPropertyStore info_device_ps
= {
1566 &info_device_ps_Vtbl
1569 static ULONG WINAPI
info_device_AddRef(IMMDevice
*iface
)
1574 static ULONG WINAPI
info_device_Release(IMMDevice
*iface
)
1579 static HRESULT WINAPI
info_device_OpenPropertyStore(IMMDevice
*iface
,
1580 DWORD access
, IPropertyStore
**ppv
)
1582 TRACE("(static)->(%x, %p)\n", access
, ppv
);
1583 *ppv
= &info_device_ps
;
1587 static const IMMDeviceVtbl info_device_Vtbl
=
1591 info_device_Release
,
1593 info_device_OpenPropertyStore
,
1598 static IMMDevice info_device
= {