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 #include <wine/list.h>
29 static const WCHAR software_mmdevapi
[] =
30 { 'S','o','f','t','w','a','r','e','\\',
31 'M','i','c','r','o','s','o','f','t','\\',
32 'W','i','n','d','o','w','s','\\',
33 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
34 'M','M','D','e','v','i','c','e','s','\\',
35 'A','u','d','i','o',0};
36 static const WCHAR reg_render
[] =
37 { 'R','e','n','d','e','r',0 };
38 static const WCHAR reg_capture
[] =
39 { 'C','a','p','t','u','r','e',0 };
40 static const WCHAR reg_devicestate
[] =
41 { 'D','e','v','i','c','e','S','t','a','t','e',0 };
42 static const WCHAR reg_properties
[] =
43 { 'P','r','o','p','e','r','t','i','e','s',0 };
44 static const WCHAR slashW
[] = {'\\',0};
45 static const WCHAR reg_out_nameW
[] = {'D','e','f','a','u','l','t','O','u','t','p','u','t',0};
46 static const WCHAR reg_vout_nameW
[] = {'D','e','f','a','u','l','t','V','o','i','c','e','O','u','t','p','u','t',0};
47 static const WCHAR reg_in_nameW
[] = {'D','e','f','a','u','l','t','I','n','p','u','t',0};
48 static const WCHAR reg_vin_nameW
[] = {'D','e','f','a','u','l','t','V','o','i','c','e','I','n','p','u','t',0};
50 static HKEY key_render
;
51 static HKEY key_capture
;
53 typedef struct MMDevPropStoreImpl
55 IPropertyStore IPropertyStore_iface
;
61 typedef struct MMDevEnumImpl
63 IMMDeviceEnumerator IMMDeviceEnumerator_iface
;
67 static MMDevEnumImpl
*MMDevEnumerator
;
68 static MMDevice
**MMDevice_head
;
69 static MMDevice
*MMDevice_def_rec
, *MMDevice_def_play
;
70 static DWORD MMDevice_count
;
71 static const IMMDeviceEnumeratorVtbl MMDevEnumVtbl
;
72 static const IMMDeviceCollectionVtbl MMDevColVtbl
;
73 static const IMMDeviceVtbl MMDeviceVtbl
;
74 static const IPropertyStoreVtbl MMDevPropVtbl
;
75 static const IMMEndpointVtbl MMEndpointVtbl
;
77 static IMMDevice info_device
;
79 typedef struct MMDevColImpl
81 IMMDeviceCollection IMMDeviceCollection_iface
;
87 typedef struct IPropertyBagImpl
{
88 IPropertyBag IPropertyBag_iface
;
92 static const IPropertyBagVtbl PB_Vtbl
;
94 static HRESULT
MMDevPropStore_Create(MMDevice
*This
, DWORD access
, IPropertyStore
**ppv
);
96 static inline MMDevPropStore
*impl_from_IPropertyStore(IPropertyStore
*iface
)
98 return CONTAINING_RECORD(iface
, MMDevPropStore
, IPropertyStore_iface
);
101 static inline MMDevEnumImpl
*impl_from_IMMDeviceEnumerator(IMMDeviceEnumerator
*iface
)
103 return CONTAINING_RECORD(iface
, MMDevEnumImpl
, IMMDeviceEnumerator_iface
);
106 static inline MMDevColImpl
*impl_from_IMMDeviceCollection(IMMDeviceCollection
*iface
)
108 return CONTAINING_RECORD(iface
, MMDevColImpl
, IMMDeviceCollection_iface
);
111 static inline IPropertyBagImpl
*impl_from_IPropertyBag(IPropertyBag
*iface
)
113 return CONTAINING_RECORD(iface
, IPropertyBagImpl
, IPropertyBag_iface
);
116 static const WCHAR propkey_formatW
[] = {
117 '{','%','0','8','X','-','%','0','4','X','-',
118 '%','0','4','X','-','%','0','2','X','%','0','2','X','-',
119 '%','0','2','X','%','0','2','X','%','0','2','X','%','0','2','X',
120 '%','0','2','X','%','0','2','X','}',',','%','d',0 };
122 static HRESULT
MMDevPropStore_OpenPropKey(const GUID
*guid
, DWORD flow
, HKEY
*propkey
)
127 StringFromGUID2(guid
, buffer
, 39);
128 if ((ret
= RegOpenKeyExW(flow
== eRender
? key_render
: key_capture
, buffer
, 0, KEY_READ
|KEY_WRITE
, &key
)) != ERROR_SUCCESS
)
130 WARN("Opening key %s failed with %u\n", debugstr_w(buffer
), ret
);
133 ret
= RegOpenKeyExW(key
, reg_properties
, 0, KEY_READ
|KEY_WRITE
, propkey
);
135 if (ret
!= ERROR_SUCCESS
)
137 WARN("Opening key %s failed with %u\n", debugstr_w(reg_properties
), ret
);
143 static HRESULT
MMDevice_GetPropValue(const GUID
*devguid
, DWORD flow
, REFPROPERTYKEY key
, PROPVARIANT
*pv
)
146 const GUID
*id
= &key
->fmtid
;
152 hr
= MMDevPropStore_OpenPropKey(devguid
, flow
, ®key
);
155 wsprintfW( buffer
, propkey_formatW
, id
->Data1
, id
->Data2
, id
->Data3
,
156 id
->Data4
[0], id
->Data4
[1], id
->Data4
[2], id
->Data4
[3],
157 id
->Data4
[4], id
->Data4
[5], id
->Data4
[6], id
->Data4
[7], key
->pid
);
158 ret
= RegGetValueW(regkey
, NULL
, buffer
, RRF_RT_ANY
, &type
, NULL
, &size
);
159 if (ret
!= ERROR_SUCCESS
)
161 WARN("Reading %s returned %d\n", debugstr_w(buffer
), ret
);
163 PropVariantClear(pv
);
172 pv
->u
.pwszVal
= CoTaskMemAlloc(size
);
176 RegGetValueW(regkey
, NULL
, buffer
, RRF_RT_REG_SZ
, NULL
, (BYTE
*)pv
->u
.pwszVal
, &size
);
182 RegGetValueW(regkey
, NULL
, buffer
, RRF_RT_REG_DWORD
, NULL
, (BYTE
*)&pv
->u
.ulVal
, &size
);
188 pv
->u
.blob
.cbSize
= size
;
189 pv
->u
.blob
.pBlobData
= CoTaskMemAlloc(size
);
190 if (!pv
->u
.blob
.pBlobData
)
193 RegGetValueW(regkey
, NULL
, buffer
, RRF_RT_REG_BINARY
, NULL
, (BYTE
*)pv
->u
.blob
.pBlobData
, &size
);
197 ERR("Unknown/unhandled type: %u\n", type
);
198 PropVariantClear(pv
);
205 static HRESULT
MMDevice_SetPropValue(const GUID
*devguid
, DWORD flow
, REFPROPERTYKEY key
, REFPROPVARIANT pv
)
208 const GUID
*id
= &key
->fmtid
;
213 hr
= MMDevPropStore_OpenPropKey(devguid
, flow
, ®key
);
216 wsprintfW( buffer
, propkey_formatW
, id
->Data1
, id
->Data2
, id
->Data3
,
217 id
->Data4
[0], id
->Data4
[1], id
->Data4
[2], id
->Data4
[3],
218 id
->Data4
[4], id
->Data4
[5], id
->Data4
[6], id
->Data4
[7], key
->pid
);
223 ret
= RegSetValueExW(regkey
, buffer
, 0, REG_DWORD
, (const BYTE
*)&pv
->u
.ulVal
, sizeof(DWORD
));
228 ret
= RegSetValueExW(regkey
, buffer
, 0, REG_BINARY
, pv
->u
.blob
.pBlobData
, pv
->u
.blob
.cbSize
);
229 TRACE("Blob %p %u\n", pv
->u
.blob
.pBlobData
, pv
->u
.blob
.cbSize
);
235 ret
= RegSetValueExW(regkey
, buffer
, 0, REG_SZ
, (const BYTE
*)pv
->u
.pwszVal
, sizeof(WCHAR
)*(1+lstrlenW(pv
->u
.pwszVal
)));
240 FIXME("Unhandled type %u\n", pv
->vt
);
245 TRACE("Writing %s returned %u\n", debugstr_w(buffer
), ret
);
249 static HRESULT
set_driver_prop_value(GUID
*id
, const EDataFlow flow
, const PROPERTYKEY
*prop
)
254 if (!drvs
.pGetPropValue
)
257 hr
= drvs
.pGetPropValue(id
, prop
, &pv
);
261 MMDevice_SetPropValue(id
, flow
, prop
, &pv
);
262 PropVariantClear(&pv
);
268 /* Creates or updates the state of a device
269 * If GUID is null, a random guid will be assigned
270 * and the device will be created
272 static MMDevice
*MMDevice_Create(WCHAR
*name
, GUID
*id
, EDataFlow flow
, DWORD state
, BOOL setdefault
)
275 MMDevice
*cur
= NULL
;
279 static const PROPERTYKEY deviceinterface_key
= {
280 {0x233164c8, 0x1b2c, 0x4c7d, {0xbc, 0x68, 0xb6, 0x71, 0x68, 0x7a, 0x25, 0x67}}, 1
283 static const PROPERTYKEY devicepath_key
= {
284 {0xb3f8fa53, 0x0004, 0x438e, {0x90, 0x03, 0x51, 0xa4, 0x6e, 0x13, 0x9b, 0xfc}}, 2
287 for (i
= 0; i
< MMDevice_count
; ++i
)
289 MMDevice
*device
= MMDevice_head
[i
];
290 if (device
->flow
== flow
&& IsEqualGUID(&device
->devguid
, id
)){
297 /* No device found, allocate new one */
298 cur
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*cur
));
302 cur
->IMMDevice_iface
.lpVtbl
= &MMDeviceVtbl
;
303 cur
->IMMEndpoint_iface
.lpVtbl
= &MMEndpointVtbl
;
305 InitializeCriticalSection(&cur
->crst
);
306 cur
->crst
.DebugInfo
->Spare
[0] = (DWORD_PTR
)(__FILE__
": MMDevice.crst");
309 MMDevice_head
= HeapAlloc(GetProcessHeap(), 0, sizeof(*MMDevice_head
));
311 MMDevice_head
= HeapReAlloc(GetProcessHeap(), 0, MMDevice_head
, sizeof(*MMDevice_head
)*(1+MMDevice_count
));
312 MMDevice_head
[MMDevice_count
++] = cur
;
313 }else if(cur
->ref
> 0)
314 WARN("Modifying an MMDevice with postitive reference count!\n");
316 HeapFree(GetProcessHeap(), 0, cur
->drv_id
);
323 StringFromGUID2(&cur
->devguid
, guidstr
, sizeof(guidstr
)/sizeof(*guidstr
));
330 if (RegCreateKeyExW(root
, guidstr
, 0, NULL
, 0, KEY_WRITE
|KEY_READ
, NULL
, &key
, NULL
) == ERROR_SUCCESS
)
333 RegSetValueExW(key
, reg_devicestate
, 0, REG_DWORD
, (const BYTE
*)&state
, sizeof(DWORD
));
334 if (!RegCreateKeyExW(key
, reg_properties
, 0, NULL
, 0, KEY_WRITE
|KEY_READ
, NULL
, &keyprop
, NULL
))
340 MMDevice_SetPropValue(id
, flow
, (const PROPERTYKEY
*)&DEVPKEY_Device_FriendlyName
, &pv
);
341 MMDevice_SetPropValue(id
, flow
, (const PROPERTYKEY
*)&DEVPKEY_Device_DeviceDesc
, &pv
);
343 pv
.u
.pwszVal
= guidstr
;
344 MMDevice_SetPropValue(id
, flow
, &deviceinterface_key
, &pv
);
346 set_driver_prop_value(id
, flow
, &devicepath_key
);
348 if (FAILED(set_driver_prop_value(id
, flow
, &PKEY_AudioEndpoint_FormFactor
)))
351 pv
.u
.ulVal
= (flow
== eCapture
) ? Microphone
: Speakers
;
353 MMDevice_SetPropValue(id
, flow
, &PKEY_AudioEndpoint_FormFactor
, &pv
);
356 if (flow
!= eCapture
)
360 PropVariantInit(&pv2
);
362 /* make read-write by not overwriting if already set */
363 if (FAILED(MMDevice_GetPropValue(id
, flow
, &PKEY_AudioEndpoint_PhysicalSpeakers
, &pv2
)) || pv2
.vt
!= VT_UI4
)
364 set_driver_prop_value(id
, flow
, &PKEY_AudioEndpoint_PhysicalSpeakers
);
366 PropVariantClear(&pv2
);
369 RegCloseKey(keyprop
);
377 MMDevice_def_play
= cur
;
379 MMDevice_def_rec
= cur
;
384 static HRESULT
load_devices_from_reg(void)
391 ret
= RegCreateKeyExW(HKEY_LOCAL_MACHINE
, software_mmdevapi
, 0, NULL
, 0, KEY_WRITE
|KEY_READ
, NULL
, &root
, NULL
);
392 if (ret
== ERROR_SUCCESS
)
393 ret
= RegCreateKeyExW(root
, reg_capture
, 0, NULL
, 0, KEY_READ
|KEY_WRITE
, NULL
, &key_capture
, NULL
);
394 if (ret
== ERROR_SUCCESS
)
395 ret
= RegCreateKeyExW(root
, reg_render
, 0, NULL
, 0, KEY_READ
|KEY_WRITE
, NULL
, &key_render
, NULL
);
399 if (ret
!= ERROR_SUCCESS
)
401 RegCloseKey(key_capture
);
402 key_render
= key_capture
= NULL
;
403 WARN("Couldn't create key: %u\n", ret
);
411 PROPVARIANT pv
= { VT_EMPTY
};
413 len
= sizeof(guidvalue
)/sizeof(guidvalue
[0]);
414 ret
= RegEnumKeyExW(cur
, i
++, guidvalue
, &len
, NULL
, NULL
, NULL
, NULL
);
415 if (ret
== ERROR_NO_MORE_ITEMS
)
417 if (cur
== key_capture
)
426 if (ret
!= ERROR_SUCCESS
)
428 if (SUCCEEDED(CLSIDFromString(guidvalue
, &guid
))
429 && SUCCEEDED(MMDevice_GetPropValue(&guid
, curflow
, (const PROPERTYKEY
*)&DEVPKEY_Device_FriendlyName
, &pv
))
430 && pv
.vt
== VT_LPWSTR
)
432 DWORD size_bytes
= (strlenW(pv
.u
.pwszVal
) + 1) * sizeof(WCHAR
);
433 WCHAR
*name
= HeapAlloc(GetProcessHeap(), 0, size_bytes
);
434 memcpy(name
, pv
.u
.pwszVal
, size_bytes
);
435 MMDevice_Create(name
, &guid
, curflow
,
436 DEVICE_STATE_NOTPRESENT
, FALSE
);
437 CoTaskMemFree(pv
.u
.pwszVal
);
444 static HRESULT
set_format(MMDevice
*dev
)
447 IAudioClient
*client
;
449 PROPVARIANT pv
= { VT_EMPTY
};
451 hr
= drvs
.pGetAudioEndpoint(&dev
->devguid
, &dev
->IMMDevice_iface
, &client
);
455 hr
= IAudioClient_GetMixFormat(client
, &fmt
);
457 IAudioClient_Release(client
);
461 IAudioClient_Release(client
);
464 pv
.u
.blob
.cbSize
= sizeof(WAVEFORMATEX
) + fmt
->cbSize
;
465 pv
.u
.blob
.pBlobData
= (BYTE
*)fmt
;
466 MMDevice_SetPropValue(&dev
->devguid
, dev
->flow
,
467 &PKEY_AudioEngine_DeviceFormat
, &pv
);
468 MMDevice_SetPropValue(&dev
->devguid
, dev
->flow
,
469 &PKEY_AudioEngine_OEMFormat
, &pv
);
474 static HRESULT
load_driver_devices(EDataFlow flow
)
481 if(!drvs
.pGetEndpointIDs
)
484 hr
= drvs
.pGetEndpointIDs(flow
, &ids
, &guids
, &num
, &def
);
488 for(i
= 0; i
< num
; ++i
){
490 dev
= MMDevice_Create(ids
[i
], &guids
[i
], flow
, DEVICE_STATE_ACTIVE
,
495 HeapFree(GetProcessHeap(), 0, guids
);
496 HeapFree(GetProcessHeap(), 0, ids
);
501 static void MMDevice_Destroy(MMDevice
*This
)
504 TRACE("Freeing %s\n", debugstr_w(This
->drv_id
));
505 /* Since this function is called at destruction time, reordering of the list is unimportant */
506 for (i
= 0; i
< MMDevice_count
; ++i
)
508 if (MMDevice_head
[i
] == This
)
510 MMDevice_head
[i
] = MMDevice_head
[--MMDevice_count
];
514 This
->crst
.DebugInfo
->Spare
[0] = 0;
515 DeleteCriticalSection(&This
->crst
);
516 HeapFree(GetProcessHeap(), 0, This
->drv_id
);
517 HeapFree(GetProcessHeap(), 0, This
);
520 static inline MMDevice
*impl_from_IMMDevice(IMMDevice
*iface
)
522 return CONTAINING_RECORD(iface
, MMDevice
, IMMDevice_iface
);
525 static HRESULT WINAPI
MMDevice_QueryInterface(IMMDevice
*iface
, REFIID riid
, void **ppv
)
527 MMDevice
*This
= impl_from_IMMDevice(iface
);
528 TRACE("(%p)->(%s,%p)\n", iface
, debugstr_guid(riid
), ppv
);
533 if (IsEqualIID(riid
, &IID_IUnknown
)
534 || IsEqualIID(riid
, &IID_IMMDevice
))
536 else if (IsEqualIID(riid
, &IID_IMMEndpoint
))
537 *ppv
= &This
->IMMEndpoint_iface
;
540 IUnknown_AddRef((IUnknown
*)*ppv
);
543 WARN("Unknown interface %s\n", debugstr_guid(riid
));
544 return E_NOINTERFACE
;
547 static ULONG WINAPI
MMDevice_AddRef(IMMDevice
*iface
)
549 MMDevice
*This
= impl_from_IMMDevice(iface
);
552 ref
= InterlockedIncrement(&This
->ref
);
553 TRACE("Refcount now %i\n", ref
);
557 static ULONG WINAPI
MMDevice_Release(IMMDevice
*iface
)
559 MMDevice
*This
= impl_from_IMMDevice(iface
);
562 ref
= InterlockedDecrement(&This
->ref
);
563 TRACE("Refcount now %i\n", ref
);
567 static HRESULT WINAPI
MMDevice_Activate(IMMDevice
*iface
, REFIID riid
, DWORD clsctx
, PROPVARIANT
*params
, void **ppv
)
569 HRESULT hr
= E_NOINTERFACE
;
570 MMDevice
*This
= impl_from_IMMDevice(iface
);
572 TRACE("(%p)->(%p,%x,%p,%p)\n", iface
, riid
, clsctx
, params
, ppv
);
577 if (IsEqualIID(riid
, &IID_IAudioClient
)){
578 hr
= drvs
.pGetAudioEndpoint(&This
->devguid
, iface
, (IAudioClient
**)ppv
);
579 }else if (IsEqualIID(riid
, &IID_IAudioEndpointVolume
))
580 hr
= AudioEndpointVolume_Create(This
, (IAudioEndpointVolume
**)ppv
);
581 else if (IsEqualIID(riid
, &IID_IAudioSessionManager
)
582 || IsEqualIID(riid
, &IID_IAudioSessionManager2
))
584 hr
= drvs
.pGetAudioSessionManager(iface
, (IAudioSessionManager2
**)ppv
);
586 else if (IsEqualIID(riid
, &IID_IBaseFilter
))
588 if (This
->flow
== eRender
)
589 hr
= CoCreateInstance(&CLSID_DSoundRender
, NULL
, clsctx
, riid
, ppv
);
591 ERR("Not supported for recording?\n");
594 IPersistPropertyBag
*ppb
;
595 hr
= IUnknown_QueryInterface((IUnknown
*)*ppv
, &IID_IPersistPropertyBag
, (void*)&ppb
);
598 /* ::Load cannot assume the interface stays alive after the function returns,
599 * so just create the interface on the stack, saves a lot of complicated code */
600 IPropertyBagImpl bag
= { { &PB_Vtbl
} };
601 bag
.devguid
= This
->devguid
;
602 hr
= IPersistPropertyBag_Load(ppb
, &bag
.IPropertyBag_iface
, NULL
);
603 IPersistPropertyBag_Release(ppb
);
605 IBaseFilter_Release((IBaseFilter
*)*ppv
);
609 FIXME("Wine doesn't support IPersistPropertyBag on DSoundRender yet, ignoring..\n");
614 else if (IsEqualIID(riid
, &IID_IDeviceTopology
))
616 FIXME("IID_IDeviceTopology unsupported\n");
618 else if (IsEqualIID(riid
, &IID_IDirectSound
)
619 || IsEqualIID(riid
, &IID_IDirectSound8
))
621 if (This
->flow
== eRender
)
622 hr
= CoCreateInstance(&CLSID_DirectSound8
, NULL
, clsctx
, riid
, ppv
);
625 hr
= IDirectSound_Initialize((IDirectSound
*)*ppv
, &This
->devguid
);
627 IDirectSound_Release((IDirectSound
*)*ppv
);
630 else if (IsEqualIID(riid
, &IID_IDirectSoundCapture
)
631 || IsEqualIID(riid
, &IID_IDirectSoundCapture8
))
633 if (This
->flow
== eCapture
)
634 hr
= CoCreateInstance(&CLSID_DirectSoundCapture8
, NULL
, clsctx
, riid
, ppv
);
637 hr
= IDirectSoundCapture_Initialize((IDirectSoundCapture
*)*ppv
, &This
->devguid
);
639 IDirectSoundCapture_Release((IDirectSoundCapture
*)*ppv
);
643 ERR("Invalid/unknown iid %s\n", debugstr_guid(riid
));
648 TRACE("Returning %08x\n", hr
);
652 static HRESULT WINAPI
MMDevice_OpenPropertyStore(IMMDevice
*iface
, DWORD access
, IPropertyStore
**ppv
)
654 MMDevice
*This
= impl_from_IMMDevice(iface
);
655 TRACE("(%p)->(%x,%p)\n", This
, access
, ppv
);
659 return MMDevPropStore_Create(This
, access
, ppv
);
662 static HRESULT WINAPI
MMDevice_GetId(IMMDevice
*iface
, WCHAR
**itemid
)
664 MMDevice
*This
= impl_from_IMMDevice(iface
);
666 GUID
*id
= &This
->devguid
;
667 static const WCHAR formatW
[] = { '{','0','.','0','.','%','u','.','0','0','0','0','0','0','0','0','}','.',
668 '{','%','0','8','X','-','%','0','4','X','-',
669 '%','0','4','X','-','%','0','2','X','%','0','2','X','-',
670 '%','0','2','X','%','0','2','X','%','0','2','X','%','0','2','X',
671 '%','0','2','X','%','0','2','X','}',0 };
673 TRACE("(%p)->(%p)\n", This
, itemid
);
676 *itemid
= str
= CoTaskMemAlloc(56 * sizeof(WCHAR
));
678 return E_OUTOFMEMORY
;
679 wsprintfW( str
, formatW
, This
->flow
, id
->Data1
, id
->Data2
, id
->Data3
,
680 id
->Data4
[0], id
->Data4
[1], id
->Data4
[2], id
->Data4
[3],
681 id
->Data4
[4], id
->Data4
[5], id
->Data4
[6], id
->Data4
[7] );
682 TRACE("returning %s\n", wine_dbgstr_w(str
));
686 static HRESULT WINAPI
MMDevice_GetState(IMMDevice
*iface
, DWORD
*state
)
688 MMDevice
*This
= impl_from_IMMDevice(iface
);
689 TRACE("(%p)->(%p)\n", iface
, state
);
693 *state
= This
->state
;
697 static const IMMDeviceVtbl MMDeviceVtbl
=
699 MMDevice_QueryInterface
,
703 MMDevice_OpenPropertyStore
,
708 static inline MMDevice
*impl_from_IMMEndpoint(IMMEndpoint
*iface
)
710 return CONTAINING_RECORD(iface
, MMDevice
, IMMEndpoint_iface
);
713 static HRESULT WINAPI
MMEndpoint_QueryInterface(IMMEndpoint
*iface
, REFIID riid
, void **ppv
)
715 MMDevice
*This
= impl_from_IMMEndpoint(iface
);
716 TRACE("(%p)->(%s, %p)\n", This
, debugstr_guid(riid
), ppv
);
717 return IMMDevice_QueryInterface(&This
->IMMDevice_iface
, riid
, ppv
);
720 static ULONG WINAPI
MMEndpoint_AddRef(IMMEndpoint
*iface
)
722 MMDevice
*This
= impl_from_IMMEndpoint(iface
);
723 TRACE("(%p)\n", This
);
724 return IMMDevice_AddRef(&This
->IMMDevice_iface
);
727 static ULONG WINAPI
MMEndpoint_Release(IMMEndpoint
*iface
)
729 MMDevice
*This
= impl_from_IMMEndpoint(iface
);
730 TRACE("(%p)\n", This
);
731 return IMMDevice_Release(&This
->IMMDevice_iface
);
734 static HRESULT WINAPI
MMEndpoint_GetDataFlow(IMMEndpoint
*iface
, EDataFlow
*flow
)
736 MMDevice
*This
= impl_from_IMMEndpoint(iface
);
737 TRACE("(%p)->(%p)\n", This
, flow
);
744 static const IMMEndpointVtbl MMEndpointVtbl
=
746 MMEndpoint_QueryInterface
,
749 MMEndpoint_GetDataFlow
752 static HRESULT
MMDevCol_Create(IMMDeviceCollection
**ppv
, EDataFlow flow
, DWORD state
)
756 This
= HeapAlloc(GetProcessHeap(), 0, sizeof(*This
));
759 return E_OUTOFMEMORY
;
760 This
->IMMDeviceCollection_iface
.lpVtbl
= &MMDevColVtbl
;
764 *ppv
= &This
->IMMDeviceCollection_iface
;
768 static void MMDevCol_Destroy(MMDevColImpl
*This
)
770 HeapFree(GetProcessHeap(), 0, This
);
773 static HRESULT WINAPI
MMDevCol_QueryInterface(IMMDeviceCollection
*iface
, REFIID riid
, void **ppv
)
775 MMDevColImpl
*This
= impl_from_IMMDeviceCollection(iface
);
776 TRACE("(%p)->(%s, %p)\n", This
, debugstr_guid(riid
), ppv
);
780 if (IsEqualIID(riid
, &IID_IUnknown
)
781 || IsEqualIID(riid
, &IID_IMMDeviceCollection
))
786 return E_NOINTERFACE
;
787 IUnknown_AddRef((IUnknown
*)*ppv
);
791 static ULONG WINAPI
MMDevCol_AddRef(IMMDeviceCollection
*iface
)
793 MMDevColImpl
*This
= impl_from_IMMDeviceCollection(iface
);
794 LONG ref
= InterlockedIncrement(&This
->ref
);
795 TRACE("Refcount now %i\n", ref
);
799 static ULONG WINAPI
MMDevCol_Release(IMMDeviceCollection
*iface
)
801 MMDevColImpl
*This
= impl_from_IMMDeviceCollection(iface
);
802 LONG ref
= InterlockedDecrement(&This
->ref
);
803 TRACE("Refcount now %i\n", ref
);
805 MMDevCol_Destroy(This
);
809 static HRESULT WINAPI
MMDevCol_GetCount(IMMDeviceCollection
*iface
, UINT
*numdevs
)
811 MMDevColImpl
*This
= impl_from_IMMDeviceCollection(iface
);
814 TRACE("(%p)->(%p)\n", This
, numdevs
);
819 for (i
= 0; i
< MMDevice_count
; ++i
)
821 MMDevice
*cur
= MMDevice_head
[i
];
822 if ((cur
->flow
== This
->flow
|| This
->flow
== eAll
)
823 && (cur
->state
& This
->state
))
829 static HRESULT WINAPI
MMDevCol_Item(IMMDeviceCollection
*iface
, UINT n
, IMMDevice
**dev
)
831 MMDevColImpl
*This
= impl_from_IMMDeviceCollection(iface
);
834 TRACE("(%p)->(%u, %p)\n", This
, n
, dev
);
838 for (j
= 0; j
< MMDevice_count
; ++j
)
840 MMDevice
*cur
= MMDevice_head
[j
];
841 if ((cur
->flow
== This
->flow
|| This
->flow
== eAll
)
842 && (cur
->state
& This
->state
)
845 *dev
= &cur
->IMMDevice_iface
;
846 IMMDevice_AddRef(*dev
);
850 WARN("Could not obtain item %u\n", n
);
855 static const IMMDeviceCollectionVtbl MMDevColVtbl
=
857 MMDevCol_QueryInterface
,
864 HRESULT
MMDevEnum_Create(REFIID riid
, void **ppv
)
866 MMDevEnumImpl
*This
= MMDevEnumerator
;
870 This
= HeapAlloc(GetProcessHeap(), 0, sizeof(*This
));
873 return E_OUTOFMEMORY
;
875 This
->IMMDeviceEnumerator_iface
.lpVtbl
= &MMDevEnumVtbl
;
876 MMDevEnumerator
= This
;
878 load_devices_from_reg();
879 load_driver_devices(eRender
);
880 load_driver_devices(eCapture
);
882 return IUnknown_QueryInterface((IUnknown
*)This
, riid
, ppv
);
885 void MMDevEnum_Free(void)
887 while (MMDevice_count
)
888 MMDevice_Destroy(MMDevice_head
[0]);
889 RegCloseKey(key_render
);
890 RegCloseKey(key_capture
);
891 key_render
= key_capture
= NULL
;
892 HeapFree(GetProcessHeap(), 0, MMDevEnumerator
);
893 MMDevEnumerator
= 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
))
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 %i\n", ref
);
922 static ULONG WINAPI
MMDevEnum_Release(IMMDeviceEnumerator
*iface
)
924 MMDevEnumImpl
*This
= impl_from_IMMDeviceEnumerator(iface
);
925 LONG ref
= InterlockedDecrement(&This
->ref
);
928 TRACE("Refcount now %i\n", ref
);
932 static HRESULT WINAPI
MMDevEnum_EnumAudioEndpoints(IMMDeviceEnumerator
*iface
, EDataFlow flow
, DWORD mask
, IMMDeviceCollection
**devices
)
934 MMDevEnumImpl
*This
= impl_from_IMMDeviceEnumerator(iface
);
935 TRACE("(%p)->(%u,%u,%p)\n", This
, flow
, mask
, devices
);
939 if (flow
>= EDataFlow_enum_count
)
941 if (mask
& ~DEVICE_STATEMASK_ALL
)
943 return MMDevCol_Create(devices
, flow
, mask
);
946 static HRESULT WINAPI
MMDevEnum_GetDefaultAudioEndpoint(IMMDeviceEnumerator
*iface
, EDataFlow flow
, ERole role
, IMMDevice
**device
)
948 MMDevEnumImpl
*This
= impl_from_IMMDeviceEnumerator(iface
);
953 TRACE("(%p)->(%u,%u,%p)\n", This
, flow
, role
, device
);
958 if((flow
!= eRender
&& flow
!= eCapture
) ||
959 (role
!= eConsole
&& role
!= eMultimedia
&& role
!= eCommunications
)){
960 WARN("Unknown flow (%u) or role (%u)\n", flow
, role
);
966 if(!drvs
.module_name
[0])
969 lstrcpyW(reg_key
, drv_keyW
);
970 lstrcatW(reg_key
, slashW
);
971 lstrcatW(reg_key
, drvs
.module_name
);
973 if(RegOpenKeyW(HKEY_CURRENT_USER
, reg_key
, &key
) == ERROR_SUCCESS
){
974 const WCHAR
*reg_x_name
, *reg_vx_name
;
976 DWORD size
= sizeof(def_id
), state
;
979 reg_x_name
= reg_out_nameW
;
980 reg_vx_name
= reg_vout_nameW
;
982 reg_x_name
= reg_in_nameW
;
983 reg_vx_name
= reg_vin_nameW
;
986 if(role
== eCommunications
&&
987 RegQueryValueExW(key
, reg_vx_name
, 0, NULL
,
988 (BYTE
*)def_id
, &size
) == ERROR_SUCCESS
){
989 hr
= IMMDeviceEnumerator_GetDevice(iface
, def_id
, device
);
991 if(SUCCEEDED(IMMDevice_GetState(*device
, &state
)) &&
992 state
== DEVICE_STATE_ACTIVE
){
998 TRACE("Unable to find voice device %s\n", wine_dbgstr_w(def_id
));
1001 if(RegQueryValueExW(key
, reg_x_name
, 0, NULL
,
1002 (BYTE
*)def_id
, &size
) == ERROR_SUCCESS
){
1003 hr
= IMMDeviceEnumerator_GetDevice(iface
, def_id
, device
);
1005 if(SUCCEEDED(IMMDevice_GetState(*device
, &state
)) &&
1006 state
== DEVICE_STATE_ACTIVE
){
1012 TRACE("Unable to find device %s\n", wine_dbgstr_w(def_id
));
1018 if (flow
== eRender
)
1019 *device
= &MMDevice_def_play
->IMMDevice_iface
;
1021 *device
= &MMDevice_def_rec
->IMMDevice_iface
;
1025 IMMDevice_AddRef(*device
);
1029 static HRESULT WINAPI
MMDevEnum_GetDevice(IMMDeviceEnumerator
*iface
, const WCHAR
*name
, IMMDevice
**device
)
1031 MMDevEnumImpl
*This
= impl_from_IMMDeviceEnumerator(iface
);
1033 IMMDevice
*dev
= NULL
;
1035 static const WCHAR wine_info_deviceW
[] = {'W','i','n','e',' ',
1036 'i','n','f','o',' ','d','e','v','i','c','e',0};
1038 TRACE("(%p)->(%s,%p)\n", This
, debugstr_w(name
), device
);
1040 if(!name
|| !device
)
1043 if(!lstrcmpW(name
, wine_info_deviceW
)){
1044 *device
= &info_device
;
1048 for (i
= 0; i
< MMDevice_count
; ++i
)
1051 dev
= &MMDevice_head
[i
]->IMMDevice_iface
;
1052 IMMDevice_GetId(dev
, &str
);
1054 if (str
&& !lstrcmpW(str
, name
))
1057 IMMDevice_AddRef(dev
);
1063 TRACE("Could not find device %s\n", debugstr_w(name
));
1064 return E_INVALIDARG
;
1067 struct NotificationClientWrapper
{
1068 IMMNotificationClient
*client
;
1072 static struct list g_notif_clients
= LIST_INIT(g_notif_clients
);
1073 static HANDLE g_notif_thread
;
1075 static CRITICAL_SECTION g_notif_lock
;
1076 static CRITICAL_SECTION_DEBUG g_notif_lock_debug
=
1078 0, 0, &g_notif_lock
,
1079 { &g_notif_lock_debug
.ProcessLocksList
, &g_notif_lock_debug
.ProcessLocksList
},
1080 0, 0, { (DWORD_PTR
)(__FILE__
": g_notif_lock") }
1082 static CRITICAL_SECTION g_notif_lock
= { &g_notif_lock_debug
, -1, 0, 0, 0, 0 };
1084 static void notify_clients(EDataFlow flow
, ERole role
, const WCHAR
*id
)
1086 struct NotificationClientWrapper
*wrapper
;
1087 LIST_FOR_EACH_ENTRY(wrapper
, &g_notif_clients
,
1088 struct NotificationClientWrapper
, entry
)
1089 IMMNotificationClient_OnDefaultDeviceChanged(wrapper
->client
, flow
,
1092 /* Windows 7 treats changes to eConsole as changes to eMultimedia */
1093 if(role
== eConsole
)
1094 notify_clients(flow
, eMultimedia
, id
);
1097 static BOOL
notify_if_changed(EDataFlow flow
, ERole role
, HKEY key
,
1098 const WCHAR
*val_name
, WCHAR
*old_val
, IMMDevice
*def_dev
)
1100 WCHAR new_val
[64], *id
;
1104 size
= sizeof(new_val
);
1105 if(RegQueryValueExW(key
, val_name
, 0, NULL
,
1106 (BYTE
*)new_val
, &size
) != ERROR_SUCCESS
){
1107 if(old_val
[0] != 0){
1108 /* set by user -> system default */
1110 hr
= IMMDevice_GetId(def_dev
, &id
);
1112 ERR("GetId failed: %08x\n", hr
);
1118 notify_clients(flow
, role
, id
);
1125 /* system default -> system default, noop */
1129 if(!lstrcmpW(old_val
, new_val
)){
1130 /* set by user -> same value */
1134 if(new_val
[0] != 0){
1135 /* set by user -> different value */
1136 notify_clients(flow
, role
, new_val
);
1137 memcpy(old_val
, new_val
, sizeof(new_val
));
1141 /* set by user -> system default */
1143 hr
= IMMDevice_GetId(def_dev
, &id
);
1145 ERR("GetId failed: %08x\n", hr
);
1151 notify_clients(flow
, role
, id
);
1158 static DWORD WINAPI
notif_thread_proc(void *user
)
1162 WCHAR out_name
[64], vout_name
[64], in_name
[64], vin_name
[64];
1165 lstrcpyW(reg_key
, drv_keyW
);
1166 lstrcatW(reg_key
, slashW
);
1167 lstrcatW(reg_key
, drvs
.module_name
);
1169 if(RegCreateKeyExW(HKEY_CURRENT_USER
, reg_key
, 0, NULL
, 0,
1170 MAXIMUM_ALLOWED
, NULL
, &key
, NULL
) != ERROR_SUCCESS
){
1171 ERR("RegCreateKeyEx failed: %u\n", GetLastError());
1175 size
= sizeof(out_name
);
1176 if(RegQueryValueExW(key
, reg_out_nameW
, 0, NULL
,
1177 (BYTE
*)out_name
, &size
) != ERROR_SUCCESS
)
1180 size
= sizeof(vout_name
);
1181 if(RegQueryValueExW(key
, reg_vout_nameW
, 0, NULL
,
1182 (BYTE
*)vout_name
, &size
) != ERROR_SUCCESS
)
1185 size
= sizeof(in_name
);
1186 if(RegQueryValueExW(key
, reg_in_nameW
, 0, NULL
,
1187 (BYTE
*)in_name
, &size
) != ERROR_SUCCESS
)
1190 size
= sizeof(vin_name
);
1191 if(RegQueryValueExW(key
, reg_vin_nameW
, 0, NULL
,
1192 (BYTE
*)vin_name
, &size
) != ERROR_SUCCESS
)
1196 if(RegNotifyChangeKeyValue(key
, FALSE
, REG_NOTIFY_CHANGE_LAST_SET
,
1197 NULL
, FALSE
) != ERROR_SUCCESS
){
1198 ERR("RegNotifyChangeKeyValue failed: %u\n", GetLastError());
1200 g_notif_thread
= NULL
;
1204 EnterCriticalSection(&g_notif_lock
);
1206 notify_if_changed(eRender
, eConsole
, key
, reg_out_nameW
,
1207 out_name
, &MMDevice_def_play
->IMMDevice_iface
);
1208 notify_if_changed(eRender
, eCommunications
, key
, reg_vout_nameW
,
1209 vout_name
, &MMDevice_def_play
->IMMDevice_iface
);
1210 notify_if_changed(eCapture
, eConsole
, key
, reg_in_nameW
,
1211 in_name
, &MMDevice_def_rec
->IMMDevice_iface
);
1212 notify_if_changed(eCapture
, eCommunications
, key
, reg_vin_nameW
,
1213 vin_name
, &MMDevice_def_rec
->IMMDevice_iface
);
1215 LeaveCriticalSection(&g_notif_lock
);
1220 g_notif_thread
= NULL
;
1225 static HRESULT WINAPI
MMDevEnum_RegisterEndpointNotificationCallback(IMMDeviceEnumerator
*iface
, IMMNotificationClient
*client
)
1227 MMDevEnumImpl
*This
= impl_from_IMMDeviceEnumerator(iface
);
1228 struct NotificationClientWrapper
*wrapper
;
1230 TRACE("(%p)->(%p)\n", This
, client
);
1235 wrapper
= HeapAlloc(GetProcessHeap(), 0, sizeof(*wrapper
));
1237 return E_OUTOFMEMORY
;
1239 wrapper
->client
= client
;
1241 EnterCriticalSection(&g_notif_lock
);
1243 list_add_tail(&g_notif_clients
, &wrapper
->entry
);
1245 if(!g_notif_thread
){
1246 g_notif_thread
= CreateThread(NULL
, 0, notif_thread_proc
, NULL
, 0, NULL
);
1248 ERR("CreateThread failed: %u\n", GetLastError());
1251 LeaveCriticalSection(&g_notif_lock
);
1256 static HRESULT WINAPI
MMDevEnum_UnregisterEndpointNotificationCallback(IMMDeviceEnumerator
*iface
, IMMNotificationClient
*client
)
1258 MMDevEnumImpl
*This
= impl_from_IMMDeviceEnumerator(iface
);
1259 struct NotificationClientWrapper
*wrapper
, *wrapper2
;
1261 TRACE("(%p)->(%p)\n", This
, client
);
1266 EnterCriticalSection(&g_notif_lock
);
1268 LIST_FOR_EACH_ENTRY_SAFE(wrapper
, wrapper2
, &g_notif_clients
,
1269 struct NotificationClientWrapper
, entry
){
1270 if(wrapper
->client
== client
){
1271 list_remove(&wrapper
->entry
);
1272 HeapFree(GetProcessHeap(), 0, wrapper
);
1273 LeaveCriticalSection(&g_notif_lock
);
1278 LeaveCriticalSection(&g_notif_lock
);
1283 static const IMMDeviceEnumeratorVtbl MMDevEnumVtbl
=
1285 MMDevEnum_QueryInterface
,
1288 MMDevEnum_EnumAudioEndpoints
,
1289 MMDevEnum_GetDefaultAudioEndpoint
,
1290 MMDevEnum_GetDevice
,
1291 MMDevEnum_RegisterEndpointNotificationCallback
,
1292 MMDevEnum_UnregisterEndpointNotificationCallback
1295 static HRESULT
MMDevPropStore_Create(MMDevice
*parent
, DWORD access
, IPropertyStore
**ppv
)
1297 MMDevPropStore
*This
;
1298 if (access
!= STGM_READ
1299 && access
!= STGM_WRITE
1300 && access
!= STGM_READWRITE
)
1302 WARN("Invalid access %08x\n", access
);
1303 return E_INVALIDARG
;
1305 This
= HeapAlloc(GetProcessHeap(), 0, sizeof(*This
));
1306 *ppv
= &This
->IPropertyStore_iface
;
1308 return E_OUTOFMEMORY
;
1309 This
->IPropertyStore_iface
.lpVtbl
= &MMDevPropVtbl
;
1311 This
->parent
= parent
;
1312 This
->access
= access
;
1316 static void MMDevPropStore_Destroy(MMDevPropStore
*This
)
1318 HeapFree(GetProcessHeap(), 0, This
);
1321 static HRESULT WINAPI
MMDevPropStore_QueryInterface(IPropertyStore
*iface
, REFIID riid
, void **ppv
)
1323 MMDevPropStore
*This
= impl_from_IPropertyStore(iface
);
1324 TRACE("(%p)->(%s, %p)\n", This
, debugstr_guid(riid
), ppv
);
1328 if (IsEqualIID(riid
, &IID_IUnknown
)
1329 || IsEqualIID(riid
, &IID_IPropertyStore
))
1334 return E_NOINTERFACE
;
1335 IUnknown_AddRef((IUnknown
*)*ppv
);
1339 static ULONG WINAPI
MMDevPropStore_AddRef(IPropertyStore
*iface
)
1341 MMDevPropStore
*This
= impl_from_IPropertyStore(iface
);
1342 LONG ref
= InterlockedIncrement(&This
->ref
);
1343 TRACE("Refcount now %i\n", ref
);
1347 static ULONG WINAPI
MMDevPropStore_Release(IPropertyStore
*iface
)
1349 MMDevPropStore
*This
= impl_from_IPropertyStore(iface
);
1350 LONG ref
= InterlockedDecrement(&This
->ref
);
1351 TRACE("Refcount now %i\n", ref
);
1353 MMDevPropStore_Destroy(This
);
1357 static HRESULT WINAPI
MMDevPropStore_GetCount(IPropertyStore
*iface
, DWORD
*nprops
)
1359 MMDevPropStore
*This
= impl_from_IPropertyStore(iface
);
1365 TRACE("(%p)->(%p)\n", iface
, nprops
);
1368 hr
= MMDevPropStore_OpenPropKey(&This
->parent
->devguid
, This
->parent
->flow
, &propkey
);
1373 DWORD len
= sizeof(buffer
)/sizeof(*buffer
);
1374 if (RegEnumValueW(propkey
, i
, buffer
, &len
, NULL
, NULL
, NULL
, NULL
) != ERROR_SUCCESS
)
1378 RegCloseKey(propkey
);
1379 TRACE("Returning %i\n", i
);
1384 static HRESULT WINAPI
MMDevPropStore_GetAt(IPropertyStore
*iface
, DWORD prop
, PROPERTYKEY
*key
)
1386 MMDevPropStore
*This
= impl_from_IPropertyStore(iface
);
1388 DWORD len
= sizeof(buffer
)/sizeof(*buffer
);
1392 TRACE("(%p)->(%u,%p)\n", iface
, prop
, key
);
1396 hr
= MMDevPropStore_OpenPropKey(&This
->parent
->devguid
, This
->parent
->flow
, &propkey
);
1400 if (RegEnumValueW(propkey
, prop
, buffer
, &len
, NULL
, NULL
, NULL
, NULL
) != ERROR_SUCCESS
1403 WARN("GetAt %u failed\n", prop
);
1404 return E_INVALIDARG
;
1406 RegCloseKey(propkey
);
1408 CLSIDFromString(buffer
, &key
->fmtid
);
1409 key
->pid
= atoiW(&buffer
[39]);
1413 static HRESULT WINAPI
MMDevPropStore_GetValue(IPropertyStore
*iface
, REFPROPERTYKEY key
, PROPVARIANT
*pv
)
1415 MMDevPropStore
*This
= impl_from_IPropertyStore(iface
);
1416 TRACE("(%p)->(\"%s,%u\", %p)\n", This
, key
? debugstr_guid(&key
->fmtid
) : NULL
, key
? key
->pid
: 0, pv
);
1420 if (This
->access
!= STGM_READ
1421 && This
->access
!= STGM_READWRITE
)
1422 return STG_E_ACCESSDENIED
;
1425 if (IsEqualPropertyKey(*key
, PKEY_AudioEndpoint_GUID
))
1428 pv
->u
.pwszVal
= CoTaskMemAlloc(39 * sizeof(WCHAR
));
1430 return E_OUTOFMEMORY
;
1431 StringFromGUID2(&This
->parent
->devguid
, pv
->u
.pwszVal
, 39);
1435 return MMDevice_GetPropValue(&This
->parent
->devguid
, This
->parent
->flow
, key
, pv
);
1438 static HRESULT WINAPI
MMDevPropStore_SetValue(IPropertyStore
*iface
, REFPROPERTYKEY key
, REFPROPVARIANT pv
)
1440 MMDevPropStore
*This
= impl_from_IPropertyStore(iface
);
1441 TRACE("(%p)->(\"%s,%u\", %p)\n", This
, key
? debugstr_guid(&key
->fmtid
) : NULL
, key
? key
->pid
: 0, pv
);
1446 if (This
->access
!= STGM_WRITE
1447 && This
->access
!= STGM_READWRITE
)
1448 return STG_E_ACCESSDENIED
;
1449 return MMDevice_SetPropValue(&This
->parent
->devguid
, This
->parent
->flow
, key
, pv
);
1452 static HRESULT WINAPI
MMDevPropStore_Commit(IPropertyStore
*iface
)
1454 MMDevPropStore
*This
= impl_from_IPropertyStore(iface
);
1455 TRACE("(%p)\n", iface
);
1457 if (This
->access
!= STGM_WRITE
1458 && This
->access
!= STGM_READWRITE
)
1459 return STG_E_ACCESSDENIED
;
1461 /* Does nothing - for mmdevapi, the propstore values are written on SetValue,
1467 static const IPropertyStoreVtbl MMDevPropVtbl
=
1469 MMDevPropStore_QueryInterface
,
1470 MMDevPropStore_AddRef
,
1471 MMDevPropStore_Release
,
1472 MMDevPropStore_GetCount
,
1473 MMDevPropStore_GetAt
,
1474 MMDevPropStore_GetValue
,
1475 MMDevPropStore_SetValue
,
1476 MMDevPropStore_Commit
1480 /* Property bag for IBaseFilter activation */
1481 static HRESULT WINAPI
PB_QueryInterface(IPropertyBag
*iface
, REFIID riid
, void **ppv
)
1483 ERR("Should not be called\n");
1485 return E_NOINTERFACE
;
1488 static ULONG WINAPI
PB_AddRef(IPropertyBag
*iface
)
1490 ERR("Should not be called\n");
1494 static ULONG WINAPI
PB_Release(IPropertyBag
*iface
)
1496 ERR("Should not be called\n");
1500 static HRESULT WINAPI
PB_Read(IPropertyBag
*iface
, LPCOLESTR name
, VARIANT
*var
, IErrorLog
*log
)
1502 static const WCHAR dsguid
[] = { 'D','S','G','u','i','d', 0 };
1503 IPropertyBagImpl
*This
= impl_from_IPropertyBag(iface
);
1504 TRACE("Trying to read %s, type %u\n", debugstr_w(name
), var
->n1
.n2
.vt
);
1505 if (!lstrcmpW(name
, dsguid
))
1508 StringFromGUID2(&This
->devguid
, guidstr
,sizeof(guidstr
)/sizeof(*guidstr
));
1509 var
->n1
.n2
.vt
= VT_BSTR
;
1510 var
->n1
.n2
.n3
.bstrVal
= SysAllocString(guidstr
);
1513 ERR("Unknown property '%s' queried\n", debugstr_w(name
));
1517 static HRESULT WINAPI
PB_Write(IPropertyBag
*iface
, LPCOLESTR name
, VARIANT
*var
)
1519 ERR("Should not be called\n");
1523 static const IPropertyBagVtbl PB_Vtbl
=
1532 static ULONG WINAPI
info_device_ps_AddRef(IPropertyStore
*iface
)
1537 static ULONG WINAPI
info_device_ps_Release(IPropertyStore
*iface
)
1542 static HRESULT WINAPI
info_device_ps_GetValue(IPropertyStore
*iface
,
1543 REFPROPERTYKEY key
, PROPVARIANT
*pv
)
1545 TRACE("(static)->(\"%s,%u\", %p)\n", debugstr_guid(&key
->fmtid
), key
? key
->pid
: 0, pv
);
1550 if (IsEqualPropertyKey(*key
, DEVPKEY_Device_Driver
))
1552 INT size
= (lstrlenW(drvs
.module_name
) + 1) * sizeof(WCHAR
);
1554 pv
->u
.pwszVal
= CoTaskMemAlloc(size
);
1556 return E_OUTOFMEMORY
;
1557 memcpy(pv
->u
.pwszVal
, drvs
.module_name
, size
);
1561 return E_INVALIDARG
;
1564 static const IPropertyStoreVtbl info_device_ps_Vtbl
=
1567 info_device_ps_AddRef
,
1568 info_device_ps_Release
,
1571 info_device_ps_GetValue
,
1576 static IPropertyStore info_device_ps
= {
1577 &info_device_ps_Vtbl
1580 static ULONG WINAPI
info_device_AddRef(IMMDevice
*iface
)
1585 static ULONG WINAPI
info_device_Release(IMMDevice
*iface
)
1590 static HRESULT WINAPI
info_device_OpenPropertyStore(IMMDevice
*iface
,
1591 DWORD access
, IPropertyStore
**ppv
)
1593 TRACE("(static)->(%x, %p)\n", access
, ppv
);
1594 *ppv
= &info_device_ps
;
1598 static const IMMDeviceVtbl info_device_Vtbl
=
1602 info_device_Release
,
1604 info_device_OpenPropertyStore
,
1609 static IMMDevice info_device
= {