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 const WCHAR software_mmdevapi
[] =
45 { 'S','o','f','t','w','a','r','e','\\',
46 'M','i','c','r','o','s','o','f','t','\\',
47 'W','i','n','d','o','w','s','\\',
48 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
49 'M','M','D','e','v','i','c','e','s','\\',
50 'A','u','d','i','o',0};
51 static const WCHAR reg_render
[] =
52 { 'R','e','n','d','e','r',0 };
53 static const WCHAR reg_capture
[] =
54 { 'C','a','p','t','u','r','e',0 };
55 static const WCHAR reg_devicestate
[] =
56 { 'D','e','v','i','c','e','S','t','a','t','e',0 };
57 static const WCHAR reg_properties
[] =
58 { 'P','r','o','p','e','r','t','i','e','s',0 };
59 static const WCHAR slashW
[] = {'\\',0};
60 static const WCHAR reg_out_nameW
[] = {'D','e','f','a','u','l','t','O','u','t','p','u','t',0};
61 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};
62 static const WCHAR reg_in_nameW
[] = {'D','e','f','a','u','l','t','I','n','p','u','t',0};
63 static const WCHAR reg_vin_nameW
[] = {'D','e','f','a','u','l','t','V','o','i','c','e','I','n','p','u','t',0};
65 static HKEY key_render
;
66 static HKEY key_capture
;
68 typedef struct MMDevPropStoreImpl
70 IPropertyStore IPropertyStore_iface
;
76 typedef struct MMDevEnumImpl
78 IMMDeviceEnumerator IMMDeviceEnumerator_iface
;
82 static MMDevEnumImpl
*MMDevEnumerator
;
83 static MMDevice
**MMDevice_head
;
84 static MMDevice
*MMDevice_def_rec
, *MMDevice_def_play
;
85 static DWORD MMDevice_count
;
86 static const IMMDeviceEnumeratorVtbl MMDevEnumVtbl
;
87 static const IMMDeviceCollectionVtbl MMDevColVtbl
;
88 static const IMMDeviceVtbl MMDeviceVtbl
;
89 static const IPropertyStoreVtbl MMDevPropVtbl
;
90 static const IMMEndpointVtbl MMEndpointVtbl
;
92 static IMMDevice info_device
;
94 typedef struct MMDevColImpl
96 IMMDeviceCollection IMMDeviceCollection_iface
;
102 typedef struct IPropertyBagImpl
{
103 IPropertyBag IPropertyBag_iface
;
107 static const IPropertyBagVtbl PB_Vtbl
;
109 static HRESULT
MMDevPropStore_Create(MMDevice
*This
, DWORD access
, IPropertyStore
**ppv
);
111 static inline MMDevPropStore
*impl_from_IPropertyStore(IPropertyStore
*iface
)
113 return CONTAINING_RECORD(iface
, MMDevPropStore
, IPropertyStore_iface
);
116 static inline MMDevEnumImpl
*impl_from_IMMDeviceEnumerator(IMMDeviceEnumerator
*iface
)
118 return CONTAINING_RECORD(iface
, MMDevEnumImpl
, IMMDeviceEnumerator_iface
);
121 static inline MMDevColImpl
*impl_from_IMMDeviceCollection(IMMDeviceCollection
*iface
)
123 return CONTAINING_RECORD(iface
, MMDevColImpl
, IMMDeviceCollection_iface
);
126 static inline IPropertyBagImpl
*impl_from_IPropertyBag(IPropertyBag
*iface
)
128 return CONTAINING_RECORD(iface
, IPropertyBagImpl
, IPropertyBag_iface
);
131 static const WCHAR propkey_formatW
[] = {
132 '{','%','0','8','X','-','%','0','4','X','-',
133 '%','0','4','X','-','%','0','2','X','%','0','2','X','-',
134 '%','0','2','X','%','0','2','X','%','0','2','X','%','0','2','X',
135 '%','0','2','X','%','0','2','X','}',',','%','d',0 };
137 static HRESULT
MMDevPropStore_OpenPropKey(const GUID
*guid
, DWORD flow
, HKEY
*propkey
)
142 StringFromGUID2(guid
, buffer
, 39);
143 if ((ret
= RegOpenKeyExW(flow
== eRender
? key_render
: key_capture
, buffer
, 0, KEY_READ
|KEY_WRITE
|KEY_WOW64_64KEY
, &key
)) != ERROR_SUCCESS
)
145 WARN("Opening key %s failed with %u\n", debugstr_w(buffer
), ret
);
148 ret
= RegOpenKeyExW(key
, reg_properties
, 0, KEY_READ
|KEY_WRITE
|KEY_WOW64_64KEY
, propkey
);
150 if (ret
!= ERROR_SUCCESS
)
152 WARN("Opening key %s failed with %u\n", debugstr_w(reg_properties
), ret
);
158 static HRESULT
MMDevice_GetPropValue(const GUID
*devguid
, DWORD flow
, REFPROPERTYKEY key
, PROPVARIANT
*pv
)
161 const GUID
*id
= &key
->fmtid
;
167 hr
= MMDevPropStore_OpenPropKey(devguid
, flow
, ®key
);
170 wsprintfW( buffer
, propkey_formatW
, id
->Data1
, id
->Data2
, id
->Data3
,
171 id
->Data4
[0], id
->Data4
[1], id
->Data4
[2], id
->Data4
[3],
172 id
->Data4
[4], id
->Data4
[5], id
->Data4
[6], id
->Data4
[7], key
->pid
);
173 ret
= RegGetValueW(regkey
, NULL
, buffer
, RRF_RT_ANY
, &type
, NULL
, &size
);
174 if (ret
!= ERROR_SUCCESS
)
176 WARN("Reading %s returned %d\n", debugstr_w(buffer
), ret
);
178 PropVariantClear(pv
);
187 pv
->u
.pwszVal
= CoTaskMemAlloc(size
);
191 RegGetValueW(regkey
, NULL
, buffer
, RRF_RT_REG_SZ
, NULL
, (BYTE
*)pv
->u
.pwszVal
, &size
);
197 RegGetValueW(regkey
, NULL
, buffer
, RRF_RT_REG_DWORD
, NULL
, (BYTE
*)&pv
->u
.ulVal
, &size
);
203 pv
->u
.blob
.cbSize
= size
;
204 pv
->u
.blob
.pBlobData
= CoTaskMemAlloc(size
);
205 if (!pv
->u
.blob
.pBlobData
)
208 RegGetValueW(regkey
, NULL
, buffer
, RRF_RT_REG_BINARY
, NULL
, (BYTE
*)pv
->u
.blob
.pBlobData
, &size
);
212 ERR("Unknown/unhandled type: %u\n", type
);
213 PropVariantClear(pv
);
220 static HRESULT
MMDevice_SetPropValue(const GUID
*devguid
, DWORD flow
, REFPROPERTYKEY key
, REFPROPVARIANT pv
)
223 const GUID
*id
= &key
->fmtid
;
228 hr
= MMDevPropStore_OpenPropKey(devguid
, flow
, ®key
);
231 wsprintfW( buffer
, propkey_formatW
, id
->Data1
, id
->Data2
, id
->Data3
,
232 id
->Data4
[0], id
->Data4
[1], id
->Data4
[2], id
->Data4
[3],
233 id
->Data4
[4], id
->Data4
[5], id
->Data4
[6], id
->Data4
[7], key
->pid
);
238 ret
= RegSetValueExW(regkey
, buffer
, 0, REG_DWORD
, (const BYTE
*)&pv
->u
.ulVal
, sizeof(DWORD
));
243 ret
= RegSetValueExW(regkey
, buffer
, 0, REG_BINARY
, pv
->u
.blob
.pBlobData
, pv
->u
.blob
.cbSize
);
244 TRACE("Blob %p %u\n", pv
->u
.blob
.pBlobData
, pv
->u
.blob
.cbSize
);
250 ret
= RegSetValueExW(regkey
, buffer
, 0, REG_SZ
, (const BYTE
*)pv
->u
.pwszVal
, sizeof(WCHAR
)*(1+lstrlenW(pv
->u
.pwszVal
)));
255 FIXME("Unhandled type %u\n", pv
->vt
);
260 TRACE("Writing %s returned %u\n", debugstr_w(buffer
), ret
);
264 static HRESULT
set_driver_prop_value(GUID
*id
, const EDataFlow flow
, const PROPERTYKEY
*prop
)
269 if (!drvs
.pGetPropValue
)
272 hr
= drvs
.pGetPropValue(id
, prop
, &pv
);
276 MMDevice_SetPropValue(id
, flow
, prop
, &pv
);
277 PropVariantClear(&pv
);
283 /* Creates or updates the state of a device
284 * If GUID is null, a random guid will be assigned
285 * and the device will be created
287 static MMDevice
*MMDevice_Create(WCHAR
*name
, GUID
*id
, EDataFlow flow
, DWORD state
, BOOL setdefault
)
290 MMDevice
*cur
= NULL
;
294 static const PROPERTYKEY deviceinterface_key
= {
295 {0x233164c8, 0x1b2c, 0x4c7d, {0xbc, 0x68, 0xb6, 0x71, 0x68, 0x7a, 0x25, 0x67}}, 1
298 static const PROPERTYKEY devicepath_key
= {
299 {0xb3f8fa53, 0x0004, 0x438e, {0x90, 0x03, 0x51, 0xa4, 0x6e, 0x13, 0x9b, 0xfc}}, 2
302 for (i
= 0; i
< MMDevice_count
; ++i
)
304 MMDevice
*device
= MMDevice_head
[i
];
305 if (device
->flow
== flow
&& IsEqualGUID(&device
->devguid
, id
)){
312 /* No device found, allocate new one */
313 cur
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*cur
));
317 cur
->IMMDevice_iface
.lpVtbl
= &MMDeviceVtbl
;
318 cur
->IMMEndpoint_iface
.lpVtbl
= &MMEndpointVtbl
;
320 InitializeCriticalSection(&cur
->crst
);
321 cur
->crst
.DebugInfo
->Spare
[0] = (DWORD_PTR
)(__FILE__
": MMDevice.crst");
324 MMDevice_head
= HeapAlloc(GetProcessHeap(), 0, sizeof(*MMDevice_head
));
326 MMDevice_head
= HeapReAlloc(GetProcessHeap(), 0, MMDevice_head
, sizeof(*MMDevice_head
)*(1+MMDevice_count
));
327 MMDevice_head
[MMDevice_count
++] = cur
;
328 }else if(cur
->ref
> 0)
329 WARN("Modifying an MMDevice with postitive reference count!\n");
331 HeapFree(GetProcessHeap(), 0, cur
->drv_id
);
338 StringFromGUID2(&cur
->devguid
, guidstr
, ARRAY_SIZE(guidstr
));
345 if (RegCreateKeyExW(root
, guidstr
, 0, NULL
, 0, KEY_WRITE
|KEY_READ
|KEY_WOW64_64KEY
, NULL
, &key
, NULL
) == ERROR_SUCCESS
)
348 RegSetValueExW(key
, reg_devicestate
, 0, REG_DWORD
, (const BYTE
*)&state
, sizeof(DWORD
));
349 if (!RegCreateKeyExW(key
, reg_properties
, 0, NULL
, 0, KEY_WRITE
|KEY_READ
|KEY_WOW64_64KEY
, NULL
, &keyprop
, NULL
))
355 MMDevice_SetPropValue(id
, flow
, (const PROPERTYKEY
*)&DEVPKEY_Device_FriendlyName
, &pv
);
356 MMDevice_SetPropValue(id
, flow
, (const PROPERTYKEY
*)&DEVPKEY_DeviceInterface_FriendlyName
, &pv
);
357 MMDevice_SetPropValue(id
, flow
, (const PROPERTYKEY
*)&DEVPKEY_Device_DeviceDesc
, &pv
);
359 pv
.u
.pwszVal
= guidstr
;
360 MMDevice_SetPropValue(id
, flow
, &deviceinterface_key
, &pv
);
362 set_driver_prop_value(id
, flow
, &devicepath_key
);
364 if (FAILED(set_driver_prop_value(id
, flow
, &PKEY_AudioEndpoint_FormFactor
)))
367 pv
.u
.ulVal
= (flow
== eCapture
) ? Microphone
: Speakers
;
369 MMDevice_SetPropValue(id
, flow
, &PKEY_AudioEndpoint_FormFactor
, &pv
);
372 if (flow
!= eCapture
)
376 PropVariantInit(&pv2
);
378 /* make read-write by not overwriting if already set */
379 if (FAILED(MMDevice_GetPropValue(id
, flow
, &PKEY_AudioEndpoint_PhysicalSpeakers
, &pv2
)) || pv2
.vt
!= VT_UI4
)
380 set_driver_prop_value(id
, flow
, &PKEY_AudioEndpoint_PhysicalSpeakers
);
382 PropVariantClear(&pv2
);
385 RegCloseKey(keyprop
);
393 MMDevice_def_play
= cur
;
395 MMDevice_def_rec
= cur
;
400 static HRESULT
load_devices_from_reg(void)
407 ret
= RegCreateKeyExW(HKEY_LOCAL_MACHINE
, software_mmdevapi
, 0, NULL
, 0, KEY_WRITE
|KEY_READ
|KEY_WOW64_64KEY
, NULL
, &root
, NULL
);
408 if (ret
== ERROR_SUCCESS
)
409 ret
= RegCreateKeyExW(root
, reg_capture
, 0, NULL
, 0, KEY_READ
|KEY_WRITE
|KEY_WOW64_64KEY
, NULL
, &key_capture
, NULL
);
410 if (ret
== ERROR_SUCCESS
)
411 ret
= RegCreateKeyExW(root
, reg_render
, 0, NULL
, 0, KEY_READ
|KEY_WRITE
|KEY_WOW64_64KEY
, NULL
, &key_render
, NULL
);
415 if (ret
!= ERROR_SUCCESS
)
417 RegCloseKey(key_capture
);
418 key_render
= key_capture
= NULL
;
419 WARN("Couldn't create key: %u\n", ret
);
427 PROPVARIANT pv
= { VT_EMPTY
};
429 len
= ARRAY_SIZE(guidvalue
);
430 ret
= RegEnumKeyExW(cur
, i
++, guidvalue
, &len
, NULL
, NULL
, NULL
, NULL
);
431 if (ret
== ERROR_NO_MORE_ITEMS
)
433 if (cur
== key_capture
)
442 if (ret
!= ERROR_SUCCESS
)
444 if (SUCCEEDED(CLSIDFromString(guidvalue
, &guid
))
445 && SUCCEEDED(MMDevice_GetPropValue(&guid
, curflow
, (const PROPERTYKEY
*)&DEVPKEY_Device_FriendlyName
, &pv
))
446 && pv
.vt
== VT_LPWSTR
)
448 DWORD size_bytes
= (lstrlenW(pv
.u
.pwszVal
) + 1) * sizeof(WCHAR
);
449 WCHAR
*name
= HeapAlloc(GetProcessHeap(), 0, size_bytes
);
450 memcpy(name
, pv
.u
.pwszVal
, size_bytes
);
451 MMDevice_Create(name
, &guid
, curflow
,
452 DEVICE_STATE_NOTPRESENT
, FALSE
);
453 CoTaskMemFree(pv
.u
.pwszVal
);
460 static HRESULT
set_format(MMDevice
*dev
)
463 IAudioClient
*client
;
465 PROPVARIANT pv
= { VT_EMPTY
};
467 hr
= drvs
.pGetAudioEndpoint(&dev
->devguid
, &dev
->IMMDevice_iface
, &client
);
471 hr
= IAudioClient_GetMixFormat(client
, &fmt
);
473 IAudioClient_Release(client
);
477 IAudioClient_Release(client
);
480 pv
.u
.blob
.cbSize
= sizeof(WAVEFORMATEX
) + fmt
->cbSize
;
481 pv
.u
.blob
.pBlobData
= (BYTE
*)fmt
;
482 MMDevice_SetPropValue(&dev
->devguid
, dev
->flow
,
483 &PKEY_AudioEngine_DeviceFormat
, &pv
);
484 MMDevice_SetPropValue(&dev
->devguid
, dev
->flow
,
485 &PKEY_AudioEngine_OEMFormat
, &pv
);
491 static HRESULT
load_driver_devices(EDataFlow flow
)
498 if(!drvs
.pGetEndpointIDs
)
501 hr
= drvs
.pGetEndpointIDs(flow
, &ids
, &guids
, &num
, &def
);
505 for(i
= 0; i
< num
; ++i
){
507 dev
= MMDevice_Create(ids
[i
], &guids
[i
], flow
, DEVICE_STATE_ACTIVE
,
512 HeapFree(GetProcessHeap(), 0, guids
);
513 HeapFree(GetProcessHeap(), 0, ids
);
518 static void MMDevice_Destroy(MMDevice
*This
)
521 TRACE("Freeing %s\n", debugstr_w(This
->drv_id
));
522 /* Since this function is called at destruction time, reordering of the list is unimportant */
523 for (i
= 0; i
< MMDevice_count
; ++i
)
525 if (MMDevice_head
[i
] == This
)
527 MMDevice_head
[i
] = MMDevice_head
[--MMDevice_count
];
531 This
->crst
.DebugInfo
->Spare
[0] = 0;
532 DeleteCriticalSection(&This
->crst
);
533 HeapFree(GetProcessHeap(), 0, This
->drv_id
);
534 HeapFree(GetProcessHeap(), 0, This
);
537 static inline MMDevice
*impl_from_IMMDevice(IMMDevice
*iface
)
539 return CONTAINING_RECORD(iface
, MMDevice
, IMMDevice_iface
);
542 static HRESULT WINAPI
MMDevice_QueryInterface(IMMDevice
*iface
, REFIID riid
, void **ppv
)
544 MMDevice
*This
= impl_from_IMMDevice(iface
);
545 TRACE("(%p)->(%s,%p)\n", iface
, debugstr_guid(riid
), ppv
);
550 if (IsEqualIID(riid
, &IID_IUnknown
)
551 || IsEqualIID(riid
, &IID_IMMDevice
))
552 *ppv
= &This
->IMMDevice_iface
;
553 else if (IsEqualIID(riid
, &IID_IMMEndpoint
))
554 *ppv
= &This
->IMMEndpoint_iface
;
557 IUnknown_AddRef((IUnknown
*)*ppv
);
560 WARN("Unknown interface %s\n", debugstr_guid(riid
));
561 return E_NOINTERFACE
;
564 static ULONG WINAPI
MMDevice_AddRef(IMMDevice
*iface
)
566 MMDevice
*This
= impl_from_IMMDevice(iface
);
569 ref
= InterlockedIncrement(&This
->ref
);
570 TRACE("Refcount now %i\n", ref
);
574 static ULONG WINAPI
MMDevice_Release(IMMDevice
*iface
)
576 MMDevice
*This
= impl_from_IMMDevice(iface
);
579 ref
= InterlockedDecrement(&This
->ref
);
580 TRACE("Refcount now %i\n", ref
);
584 static HRESULT WINAPI
MMDevice_Activate(IMMDevice
*iface
, REFIID riid
, DWORD clsctx
, PROPVARIANT
*params
, void **ppv
)
586 HRESULT hr
= E_NOINTERFACE
;
587 MMDevice
*This
= impl_from_IMMDevice(iface
);
589 TRACE("(%p)->(%s, %x, %p, %p)\n", iface
, debugstr_guid(riid
), clsctx
, params
, ppv
);
594 if (IsEqualIID(riid
, &IID_IAudioClient
)){
595 hr
= drvs
.pGetAudioEndpoint(&This
->devguid
, iface
, (IAudioClient
**)ppv
);
596 }else if (IsEqualIID(riid
, &IID_IAudioEndpointVolume
) ||
597 IsEqualIID(riid
, &IID_IAudioEndpointVolumeEx
))
598 hr
= AudioEndpointVolume_Create(This
, (IAudioEndpointVolumeEx
**)ppv
);
599 else if (IsEqualIID(riid
, &IID_IAudioSessionManager
)
600 || IsEqualIID(riid
, &IID_IAudioSessionManager2
))
602 hr
= drvs
.pGetAudioSessionManager(iface
, (IAudioSessionManager2
**)ppv
);
604 else if (IsEqualIID(riid
, &IID_IBaseFilter
))
606 if (This
->flow
== eRender
)
607 hr
= CoCreateInstance(&CLSID_DSoundRender
, NULL
, clsctx
, riid
, ppv
);
609 ERR("Not supported for recording?\n");
612 IPersistPropertyBag
*ppb
;
613 hr
= IUnknown_QueryInterface((IUnknown
*)*ppv
, &IID_IPersistPropertyBag
, (void **)&ppb
);
616 /* ::Load cannot assume the interface stays alive after the function returns,
617 * so just create the interface on the stack, saves a lot of complicated code */
618 IPropertyBagImpl bag
= { { &PB_Vtbl
} };
619 bag
.devguid
= This
->devguid
;
620 hr
= IPersistPropertyBag_Load(ppb
, &bag
.IPropertyBag_iface
, NULL
);
621 IPersistPropertyBag_Release(ppb
);
623 IBaseFilter_Release((IBaseFilter
*)*ppv
);
627 FIXME("Wine doesn't support IPersistPropertyBag on DSoundRender yet, ignoring..\n");
632 else if (IsEqualIID(riid
, &IID_IDeviceTopology
))
634 FIXME("IID_IDeviceTopology unsupported\n");
636 else if (IsEqualIID(riid
, &IID_IDirectSound
)
637 || IsEqualIID(riid
, &IID_IDirectSound8
))
639 if (This
->flow
== eRender
)
640 hr
= CoCreateInstance(&CLSID_DirectSound8
, NULL
, clsctx
, riid
, ppv
);
643 hr
= IDirectSound_Initialize((IDirectSound
*)*ppv
, &This
->devguid
);
645 IDirectSound_Release((IDirectSound
*)*ppv
);
648 else if (IsEqualIID(riid
, &IID_IDirectSoundCapture
))
650 if (This
->flow
== eCapture
)
651 hr
= CoCreateInstance(&CLSID_DirectSoundCapture8
, NULL
, clsctx
, riid
, ppv
);
654 hr
= IDirectSoundCapture_Initialize((IDirectSoundCapture
*)*ppv
, &This
->devguid
);
656 IDirectSoundCapture_Release((IDirectSoundCapture
*)*ppv
);
660 ERR("Invalid/unknown iid %s\n", debugstr_guid(riid
));
665 TRACE("Returning %08x\n", hr
);
669 static HRESULT WINAPI
MMDevice_OpenPropertyStore(IMMDevice
*iface
, DWORD access
, IPropertyStore
**ppv
)
671 MMDevice
*This
= impl_from_IMMDevice(iface
);
672 TRACE("(%p)->(%x,%p)\n", This
, access
, ppv
);
676 return MMDevPropStore_Create(This
, access
, ppv
);
679 static HRESULT WINAPI
MMDevice_GetId(IMMDevice
*iface
, WCHAR
**itemid
)
681 MMDevice
*This
= impl_from_IMMDevice(iface
);
683 GUID
*id
= &This
->devguid
;
684 static const WCHAR formatW
[] = { '{','0','.','0','.','%','u','.','0','0','0','0','0','0','0','0','}','.',
685 '{','%','0','8','X','-','%','0','4','X','-',
686 '%','0','4','X','-','%','0','2','X','%','0','2','X','-',
687 '%','0','2','X','%','0','2','X','%','0','2','X','%','0','2','X',
688 '%','0','2','X','%','0','2','X','}',0 };
690 TRACE("(%p)->(%p)\n", This
, itemid
);
693 *itemid
= str
= CoTaskMemAlloc(56 * sizeof(WCHAR
));
695 return E_OUTOFMEMORY
;
696 wsprintfW( str
, formatW
, This
->flow
, id
->Data1
, id
->Data2
, id
->Data3
,
697 id
->Data4
[0], id
->Data4
[1], id
->Data4
[2], id
->Data4
[3],
698 id
->Data4
[4], id
->Data4
[5], id
->Data4
[6], id
->Data4
[7] );
699 TRACE("returning %s\n", wine_dbgstr_w(str
));
703 static HRESULT WINAPI
MMDevice_GetState(IMMDevice
*iface
, DWORD
*state
)
705 MMDevice
*This
= impl_from_IMMDevice(iface
);
706 TRACE("(%p)->(%p)\n", iface
, state
);
710 *state
= This
->state
;
714 static const IMMDeviceVtbl MMDeviceVtbl
=
716 MMDevice_QueryInterface
,
720 MMDevice_OpenPropertyStore
,
725 static inline MMDevice
*impl_from_IMMEndpoint(IMMEndpoint
*iface
)
727 return CONTAINING_RECORD(iface
, MMDevice
, IMMEndpoint_iface
);
730 static HRESULT WINAPI
MMEndpoint_QueryInterface(IMMEndpoint
*iface
, REFIID riid
, void **ppv
)
732 MMDevice
*This
= impl_from_IMMEndpoint(iface
);
733 TRACE("(%p)->(%s, %p)\n", This
, debugstr_guid(riid
), ppv
);
734 return IMMDevice_QueryInterface(&This
->IMMDevice_iface
, riid
, ppv
);
737 static ULONG WINAPI
MMEndpoint_AddRef(IMMEndpoint
*iface
)
739 MMDevice
*This
= impl_from_IMMEndpoint(iface
);
740 TRACE("(%p)\n", This
);
741 return IMMDevice_AddRef(&This
->IMMDevice_iface
);
744 static ULONG WINAPI
MMEndpoint_Release(IMMEndpoint
*iface
)
746 MMDevice
*This
= impl_from_IMMEndpoint(iface
);
747 TRACE("(%p)\n", This
);
748 return IMMDevice_Release(&This
->IMMDevice_iface
);
751 static HRESULT WINAPI
MMEndpoint_GetDataFlow(IMMEndpoint
*iface
, EDataFlow
*flow
)
753 MMDevice
*This
= impl_from_IMMEndpoint(iface
);
754 TRACE("(%p)->(%p)\n", This
, flow
);
761 static const IMMEndpointVtbl MMEndpointVtbl
=
763 MMEndpoint_QueryInterface
,
766 MMEndpoint_GetDataFlow
769 static HRESULT
MMDevCol_Create(IMMDeviceCollection
**ppv
, EDataFlow flow
, DWORD state
)
773 This
= HeapAlloc(GetProcessHeap(), 0, sizeof(*This
));
776 return E_OUTOFMEMORY
;
777 This
->IMMDeviceCollection_iface
.lpVtbl
= &MMDevColVtbl
;
781 *ppv
= &This
->IMMDeviceCollection_iface
;
785 static void MMDevCol_Destroy(MMDevColImpl
*This
)
787 HeapFree(GetProcessHeap(), 0, This
);
790 static HRESULT WINAPI
MMDevCol_QueryInterface(IMMDeviceCollection
*iface
, REFIID riid
, void **ppv
)
792 MMDevColImpl
*This
= impl_from_IMMDeviceCollection(iface
);
793 TRACE("(%p)->(%s, %p)\n", This
, debugstr_guid(riid
), ppv
);
797 if (IsEqualIID(riid
, &IID_IUnknown
)
798 || IsEqualIID(riid
, &IID_IMMDeviceCollection
))
799 *ppv
= &This
->IMMDeviceCollection_iface
;
803 return E_NOINTERFACE
;
804 IUnknown_AddRef((IUnknown
*)*ppv
);
808 static ULONG WINAPI
MMDevCol_AddRef(IMMDeviceCollection
*iface
)
810 MMDevColImpl
*This
= impl_from_IMMDeviceCollection(iface
);
811 LONG ref
= InterlockedIncrement(&This
->ref
);
812 TRACE("Refcount now %i\n", ref
);
816 static ULONG WINAPI
MMDevCol_Release(IMMDeviceCollection
*iface
)
818 MMDevColImpl
*This
= impl_from_IMMDeviceCollection(iface
);
819 LONG ref
= InterlockedDecrement(&This
->ref
);
820 TRACE("Refcount now %i\n", ref
);
822 MMDevCol_Destroy(This
);
826 static HRESULT WINAPI
MMDevCol_GetCount(IMMDeviceCollection
*iface
, UINT
*numdevs
)
828 MMDevColImpl
*This
= impl_from_IMMDeviceCollection(iface
);
831 TRACE("(%p)->(%p)\n", This
, numdevs
);
836 for (i
= 0; i
< MMDevice_count
; ++i
)
838 MMDevice
*cur
= MMDevice_head
[i
];
839 if ((cur
->flow
== This
->flow
|| This
->flow
== eAll
)
840 && (cur
->state
& This
->state
))
846 static HRESULT WINAPI
MMDevCol_Item(IMMDeviceCollection
*iface
, UINT n
, IMMDevice
**dev
)
848 MMDevColImpl
*This
= impl_from_IMMDeviceCollection(iface
);
851 TRACE("(%p)->(%u, %p)\n", This
, n
, dev
);
855 for (j
= 0; j
< MMDevice_count
; ++j
)
857 MMDevice
*cur
= MMDevice_head
[j
];
858 if ((cur
->flow
== This
->flow
|| This
->flow
== eAll
)
859 && (cur
->state
& This
->state
)
862 *dev
= &cur
->IMMDevice_iface
;
863 IMMDevice_AddRef(*dev
);
867 WARN("Could not obtain item %u\n", n
);
872 static const IMMDeviceCollectionVtbl MMDevColVtbl
=
874 MMDevCol_QueryInterface
,
881 HRESULT
MMDevEnum_Create(REFIID riid
, void **ppv
)
883 MMDevEnumImpl
*This
= MMDevEnumerator
;
887 This
= HeapAlloc(GetProcessHeap(), 0, sizeof(*This
));
890 return E_OUTOFMEMORY
;
892 This
->IMMDeviceEnumerator_iface
.lpVtbl
= &MMDevEnumVtbl
;
893 MMDevEnumerator
= This
;
895 load_devices_from_reg();
896 load_driver_devices(eRender
);
897 load_driver_devices(eCapture
);
899 return IMMDeviceEnumerator_QueryInterface(&This
->IMMDeviceEnumerator_iface
, riid
, ppv
);
902 void MMDevEnum_Free(void)
904 while (MMDevice_count
)
905 MMDevice_Destroy(MMDevice_head
[0]);
906 RegCloseKey(key_render
);
907 RegCloseKey(key_capture
);
908 key_render
= key_capture
= NULL
;
909 HeapFree(GetProcessHeap(), 0, MMDevEnumerator
);
910 MMDevEnumerator
= NULL
;
913 static HRESULT WINAPI
MMDevEnum_QueryInterface(IMMDeviceEnumerator
*iface
, REFIID riid
, void **ppv
)
915 MMDevEnumImpl
*This
= impl_from_IMMDeviceEnumerator(iface
);
916 TRACE("(%p)->(%s, %p)\n", This
, debugstr_guid(riid
), ppv
);
920 if (IsEqualIID(riid
, &IID_IUnknown
)
921 || IsEqualIID(riid
, &IID_IMMDeviceEnumerator
))
922 *ppv
= &This
->IMMDeviceEnumerator_iface
;
926 return E_NOINTERFACE
;
927 IUnknown_AddRef((IUnknown
*)*ppv
);
931 static ULONG WINAPI
MMDevEnum_AddRef(IMMDeviceEnumerator
*iface
)
933 MMDevEnumImpl
*This
= impl_from_IMMDeviceEnumerator(iface
);
934 LONG ref
= InterlockedIncrement(&This
->ref
);
935 TRACE("Refcount now %i\n", ref
);
939 static ULONG WINAPI
MMDevEnum_Release(IMMDeviceEnumerator
*iface
)
941 MMDevEnumImpl
*This
= impl_from_IMMDeviceEnumerator(iface
);
942 LONG ref
= InterlockedDecrement(&This
->ref
);
945 TRACE("Refcount now %i\n", ref
);
949 static HRESULT WINAPI
MMDevEnum_EnumAudioEndpoints(IMMDeviceEnumerator
*iface
, EDataFlow flow
, DWORD mask
, IMMDeviceCollection
**devices
)
951 MMDevEnumImpl
*This
= impl_from_IMMDeviceEnumerator(iface
);
952 TRACE("(%p)->(%u,%u,%p)\n", This
, flow
, mask
, devices
);
956 if (flow
>= EDataFlow_enum_count
)
958 if (mask
& ~DEVICE_STATEMASK_ALL
)
960 return MMDevCol_Create(devices
, flow
, mask
);
963 static HRESULT WINAPI
MMDevEnum_GetDefaultAudioEndpoint(IMMDeviceEnumerator
*iface
, EDataFlow flow
, ERole role
, IMMDevice
**device
)
965 MMDevEnumImpl
*This
= impl_from_IMMDeviceEnumerator(iface
);
970 TRACE("(%p)->(%u,%u,%p)\n", This
, flow
, role
, device
);
975 if((flow
!= eRender
&& flow
!= eCapture
) ||
976 (role
!= eConsole
&& role
!= eMultimedia
&& role
!= eCommunications
)){
977 WARN("Unknown flow (%u) or role (%u)\n", flow
, role
);
983 if(!drvs
.module_name
[0])
986 lstrcpyW(reg_key
, drv_keyW
);
987 lstrcatW(reg_key
, slashW
);
988 lstrcatW(reg_key
, drvs
.module_name
);
990 if(RegOpenKeyW(HKEY_CURRENT_USER
, reg_key
, &key
) == ERROR_SUCCESS
){
991 const WCHAR
*reg_x_name
, *reg_vx_name
;
993 DWORD size
= sizeof(def_id
), state
;
996 reg_x_name
= reg_out_nameW
;
997 reg_vx_name
= reg_vout_nameW
;
999 reg_x_name
= reg_in_nameW
;
1000 reg_vx_name
= reg_vin_nameW
;
1003 if(role
== eCommunications
&&
1004 RegQueryValueExW(key
, reg_vx_name
, 0, NULL
,
1005 (BYTE
*)def_id
, &size
) == ERROR_SUCCESS
){
1006 hr
= IMMDeviceEnumerator_GetDevice(iface
, def_id
, device
);
1008 if(SUCCEEDED(IMMDevice_GetState(*device
, &state
)) &&
1009 state
== DEVICE_STATE_ACTIVE
){
1015 TRACE("Unable to find voice device %s\n", wine_dbgstr_w(def_id
));
1018 if(RegQueryValueExW(key
, reg_x_name
, 0, NULL
,
1019 (BYTE
*)def_id
, &size
) == ERROR_SUCCESS
){
1020 hr
= IMMDeviceEnumerator_GetDevice(iface
, def_id
, device
);
1022 if(SUCCEEDED(IMMDevice_GetState(*device
, &state
)) &&
1023 state
== DEVICE_STATE_ACTIVE
){
1029 TRACE("Unable to find device %s\n", wine_dbgstr_w(def_id
));
1035 if (flow
== eRender
)
1036 *device
= &MMDevice_def_play
->IMMDevice_iface
;
1038 *device
= &MMDevice_def_rec
->IMMDevice_iface
;
1042 IMMDevice_AddRef(*device
);
1046 static HRESULT WINAPI
MMDevEnum_GetDevice(IMMDeviceEnumerator
*iface
, const WCHAR
*name
, IMMDevice
**device
)
1048 MMDevEnumImpl
*This
= impl_from_IMMDeviceEnumerator(iface
);
1050 IMMDevice
*dev
= NULL
;
1052 static const WCHAR wine_info_deviceW
[] = {'W','i','n','e',' ',
1053 'i','n','f','o',' ','d','e','v','i','c','e',0};
1055 TRACE("(%p)->(%s,%p)\n", This
, debugstr_w(name
), device
);
1057 if(!name
|| !device
)
1060 if(!lstrcmpW(name
, wine_info_deviceW
)){
1061 *device
= &info_device
;
1065 for (i
= 0; i
< MMDevice_count
; ++i
)
1069 dev
= &MMDevice_head
[i
]->IMMDevice_iface
;
1070 hr
= IMMDevice_GetId(dev
, &str
);
1073 WARN("GetId failed: %08x\n", hr
);
1077 if (str
&& !lstrcmpW(str
, name
))
1080 IMMDevice_AddRef(dev
);
1086 TRACE("Could not find device %s\n", debugstr_w(name
));
1087 return E_INVALIDARG
;
1090 struct NotificationClientWrapper
{
1091 IMMNotificationClient
*client
;
1095 static struct list g_notif_clients
= LIST_INIT(g_notif_clients
);
1096 static HANDLE g_notif_thread
;
1098 static CRITICAL_SECTION g_notif_lock
;
1099 static CRITICAL_SECTION_DEBUG g_notif_lock_debug
=
1101 0, 0, &g_notif_lock
,
1102 { &g_notif_lock_debug
.ProcessLocksList
, &g_notif_lock_debug
.ProcessLocksList
},
1103 0, 0, { (DWORD_PTR
)(__FILE__
": g_notif_lock") }
1105 static CRITICAL_SECTION g_notif_lock
= { &g_notif_lock_debug
, -1, 0, 0, 0, 0 };
1107 static void notify_clients(EDataFlow flow
, ERole role
, const WCHAR
*id
)
1109 struct NotificationClientWrapper
*wrapper
;
1110 LIST_FOR_EACH_ENTRY(wrapper
, &g_notif_clients
,
1111 struct NotificationClientWrapper
, entry
)
1112 IMMNotificationClient_OnDefaultDeviceChanged(wrapper
->client
, flow
,
1115 /* Windows 7 treats changes to eConsole as changes to eMultimedia */
1116 if(role
== eConsole
)
1117 notify_clients(flow
, eMultimedia
, id
);
1120 static BOOL
notify_if_changed(EDataFlow flow
, ERole role
, HKEY key
,
1121 const WCHAR
*val_name
, WCHAR
*old_val
, IMMDevice
*def_dev
)
1123 WCHAR new_val
[64], *id
;
1127 size
= sizeof(new_val
);
1128 if(RegQueryValueExW(key
, val_name
, 0, NULL
,
1129 (BYTE
*)new_val
, &size
) != ERROR_SUCCESS
){
1130 if(old_val
[0] != 0){
1131 /* set by user -> system default */
1133 hr
= IMMDevice_GetId(def_dev
, &id
);
1135 ERR("GetId failed: %08x\n", hr
);
1141 notify_clients(flow
, role
, id
);
1148 /* system default -> system default, noop */
1152 if(!lstrcmpW(old_val
, new_val
)){
1153 /* set by user -> same value */
1157 if(new_val
[0] != 0){
1158 /* set by user -> different value */
1159 notify_clients(flow
, role
, new_val
);
1160 memcpy(old_val
, new_val
, sizeof(new_val
));
1164 /* set by user -> system default */
1166 hr
= IMMDevice_GetId(def_dev
, &id
);
1168 ERR("GetId failed: %08x\n", hr
);
1174 notify_clients(flow
, role
, id
);
1181 static DWORD WINAPI
notif_thread_proc(void *user
)
1185 WCHAR out_name
[64], vout_name
[64], in_name
[64], vin_name
[64];
1188 lstrcpyW(reg_key
, drv_keyW
);
1189 lstrcatW(reg_key
, slashW
);
1190 lstrcatW(reg_key
, drvs
.module_name
);
1192 if(RegCreateKeyExW(HKEY_CURRENT_USER
, reg_key
, 0, NULL
, 0,
1193 MAXIMUM_ALLOWED
, NULL
, &key
, NULL
) != ERROR_SUCCESS
){
1194 ERR("RegCreateKeyEx failed: %u\n", GetLastError());
1198 size
= sizeof(out_name
);
1199 if(RegQueryValueExW(key
, reg_out_nameW
, 0, NULL
,
1200 (BYTE
*)out_name
, &size
) != ERROR_SUCCESS
)
1203 size
= sizeof(vout_name
);
1204 if(RegQueryValueExW(key
, reg_vout_nameW
, 0, NULL
,
1205 (BYTE
*)vout_name
, &size
) != ERROR_SUCCESS
)
1208 size
= sizeof(in_name
);
1209 if(RegQueryValueExW(key
, reg_in_nameW
, 0, NULL
,
1210 (BYTE
*)in_name
, &size
) != ERROR_SUCCESS
)
1213 size
= sizeof(vin_name
);
1214 if(RegQueryValueExW(key
, reg_vin_nameW
, 0, NULL
,
1215 (BYTE
*)vin_name
, &size
) != ERROR_SUCCESS
)
1219 if(RegNotifyChangeKeyValue(key
, FALSE
, REG_NOTIFY_CHANGE_LAST_SET
,
1220 NULL
, FALSE
) != ERROR_SUCCESS
){
1221 ERR("RegNotifyChangeKeyValue failed: %u\n", GetLastError());
1223 g_notif_thread
= NULL
;
1227 EnterCriticalSection(&g_notif_lock
);
1229 notify_if_changed(eRender
, eConsole
, key
, reg_out_nameW
,
1230 out_name
, &MMDevice_def_play
->IMMDevice_iface
);
1231 notify_if_changed(eRender
, eCommunications
, key
, reg_vout_nameW
,
1232 vout_name
, &MMDevice_def_play
->IMMDevice_iface
);
1233 notify_if_changed(eCapture
, eConsole
, key
, reg_in_nameW
,
1234 in_name
, &MMDevice_def_rec
->IMMDevice_iface
);
1235 notify_if_changed(eCapture
, eCommunications
, key
, reg_vin_nameW
,
1236 vin_name
, &MMDevice_def_rec
->IMMDevice_iface
);
1238 LeaveCriticalSection(&g_notif_lock
);
1243 g_notif_thread
= NULL
;
1248 static HRESULT WINAPI
MMDevEnum_RegisterEndpointNotificationCallback(IMMDeviceEnumerator
*iface
, IMMNotificationClient
*client
)
1250 MMDevEnumImpl
*This
= impl_from_IMMDeviceEnumerator(iface
);
1251 struct NotificationClientWrapper
*wrapper
;
1253 TRACE("(%p)->(%p)\n", This
, client
);
1258 wrapper
= HeapAlloc(GetProcessHeap(), 0, sizeof(*wrapper
));
1260 return E_OUTOFMEMORY
;
1262 wrapper
->client
= client
;
1264 EnterCriticalSection(&g_notif_lock
);
1266 list_add_tail(&g_notif_clients
, &wrapper
->entry
);
1268 if(!g_notif_thread
){
1269 g_notif_thread
= CreateThread(NULL
, 0, notif_thread_proc
, NULL
, 0, NULL
);
1271 ERR("CreateThread failed: %u\n", GetLastError());
1274 LeaveCriticalSection(&g_notif_lock
);
1279 static HRESULT WINAPI
MMDevEnum_UnregisterEndpointNotificationCallback(IMMDeviceEnumerator
*iface
, IMMNotificationClient
*client
)
1281 MMDevEnumImpl
*This
= impl_from_IMMDeviceEnumerator(iface
);
1282 struct NotificationClientWrapper
*wrapper
;
1284 TRACE("(%p)->(%p)\n", This
, client
);
1289 EnterCriticalSection(&g_notif_lock
);
1291 LIST_FOR_EACH_ENTRY(wrapper
, &g_notif_clients
, struct NotificationClientWrapper
, entry
){
1292 if(wrapper
->client
== client
){
1293 list_remove(&wrapper
->entry
);
1294 HeapFree(GetProcessHeap(), 0, wrapper
);
1295 LeaveCriticalSection(&g_notif_lock
);
1300 LeaveCriticalSection(&g_notif_lock
);
1305 static const IMMDeviceEnumeratorVtbl MMDevEnumVtbl
=
1307 MMDevEnum_QueryInterface
,
1310 MMDevEnum_EnumAudioEndpoints
,
1311 MMDevEnum_GetDefaultAudioEndpoint
,
1312 MMDevEnum_GetDevice
,
1313 MMDevEnum_RegisterEndpointNotificationCallback
,
1314 MMDevEnum_UnregisterEndpointNotificationCallback
1317 static HRESULT
MMDevPropStore_Create(MMDevice
*parent
, DWORD access
, IPropertyStore
**ppv
)
1319 MMDevPropStore
*This
;
1320 if (access
!= STGM_READ
1321 && access
!= STGM_WRITE
1322 && access
!= STGM_READWRITE
)
1324 WARN("Invalid access %08x\n", access
);
1325 return E_INVALIDARG
;
1327 This
= HeapAlloc(GetProcessHeap(), 0, sizeof(*This
));
1328 *ppv
= &This
->IPropertyStore_iface
;
1330 return E_OUTOFMEMORY
;
1331 This
->IPropertyStore_iface
.lpVtbl
= &MMDevPropVtbl
;
1333 This
->parent
= parent
;
1334 This
->access
= access
;
1338 static void MMDevPropStore_Destroy(MMDevPropStore
*This
)
1340 HeapFree(GetProcessHeap(), 0, This
);
1343 static HRESULT WINAPI
MMDevPropStore_QueryInterface(IPropertyStore
*iface
, REFIID riid
, void **ppv
)
1345 MMDevPropStore
*This
= impl_from_IPropertyStore(iface
);
1346 TRACE("(%p)->(%s, %p)\n", This
, debugstr_guid(riid
), ppv
);
1350 if (IsEqualIID(riid
, &IID_IUnknown
)
1351 || IsEqualIID(riid
, &IID_IPropertyStore
))
1352 *ppv
= &This
->IPropertyStore_iface
;
1356 return E_NOINTERFACE
;
1357 IUnknown_AddRef((IUnknown
*)*ppv
);
1361 static ULONG WINAPI
MMDevPropStore_AddRef(IPropertyStore
*iface
)
1363 MMDevPropStore
*This
= impl_from_IPropertyStore(iface
);
1364 LONG ref
= InterlockedIncrement(&This
->ref
);
1365 TRACE("Refcount now %i\n", ref
);
1369 static ULONG WINAPI
MMDevPropStore_Release(IPropertyStore
*iface
)
1371 MMDevPropStore
*This
= impl_from_IPropertyStore(iface
);
1372 LONG ref
= InterlockedDecrement(&This
->ref
);
1373 TRACE("Refcount now %i\n", ref
);
1375 MMDevPropStore_Destroy(This
);
1379 static HRESULT WINAPI
MMDevPropStore_GetCount(IPropertyStore
*iface
, DWORD
*nprops
)
1381 MMDevPropStore
*This
= impl_from_IPropertyStore(iface
);
1387 TRACE("(%p)->(%p)\n", iface
, nprops
);
1390 hr
= MMDevPropStore_OpenPropKey(&This
->parent
->devguid
, This
->parent
->flow
, &propkey
);
1395 DWORD len
= ARRAY_SIZE(buffer
);
1396 if (RegEnumValueW(propkey
, i
, buffer
, &len
, NULL
, NULL
, NULL
, NULL
) != ERROR_SUCCESS
)
1400 RegCloseKey(propkey
);
1401 TRACE("Returning %i\n", i
);
1406 static HRESULT WINAPI
MMDevPropStore_GetAt(IPropertyStore
*iface
, DWORD prop
, PROPERTYKEY
*key
)
1408 MMDevPropStore
*This
= impl_from_IPropertyStore(iface
);
1410 DWORD len
= ARRAY_SIZE(buffer
);
1414 TRACE("(%p)->(%u,%p)\n", iface
, prop
, key
);
1418 hr
= MMDevPropStore_OpenPropKey(&This
->parent
->devguid
, This
->parent
->flow
, &propkey
);
1422 if (RegEnumValueW(propkey
, prop
, buffer
, &len
, NULL
, NULL
, NULL
, NULL
) != ERROR_SUCCESS
1425 WARN("GetAt %u failed\n", prop
);
1426 return E_INVALIDARG
;
1428 RegCloseKey(propkey
);
1430 CLSIDFromString(buffer
, &key
->fmtid
);
1431 key
->pid
= wcstol(&buffer
[39], NULL
, 10);
1435 static HRESULT WINAPI
MMDevPropStore_GetValue(IPropertyStore
*iface
, REFPROPERTYKEY key
, PROPVARIANT
*pv
)
1437 MMDevPropStore
*This
= impl_from_IPropertyStore(iface
);
1438 TRACE("(%p)->(\"%s,%u\", %p)\n", This
, key
? debugstr_guid(&key
->fmtid
) : NULL
, key
? key
->pid
: 0, pv
);
1442 if (This
->access
!= STGM_READ
1443 && This
->access
!= STGM_READWRITE
)
1444 return STG_E_ACCESSDENIED
;
1447 if (IsEqualPropertyKey(*key
, PKEY_AudioEndpoint_GUID
))
1450 pv
->u
.pwszVal
= CoTaskMemAlloc(39 * sizeof(WCHAR
));
1452 return E_OUTOFMEMORY
;
1453 StringFromGUID2(&This
->parent
->devguid
, pv
->u
.pwszVal
, 39);
1457 return MMDevice_GetPropValue(&This
->parent
->devguid
, This
->parent
->flow
, key
, pv
);
1460 static HRESULT WINAPI
MMDevPropStore_SetValue(IPropertyStore
*iface
, REFPROPERTYKEY key
, REFPROPVARIANT pv
)
1462 MMDevPropStore
*This
= impl_from_IPropertyStore(iface
);
1463 TRACE("(%p)->(\"%s,%u\", %p)\n", This
, key
? debugstr_guid(&key
->fmtid
) : NULL
, key
? key
->pid
: 0, pv
);
1468 if (This
->access
!= STGM_WRITE
1469 && This
->access
!= STGM_READWRITE
)
1470 return STG_E_ACCESSDENIED
;
1471 return MMDevice_SetPropValue(&This
->parent
->devguid
, This
->parent
->flow
, key
, pv
);
1474 static HRESULT WINAPI
MMDevPropStore_Commit(IPropertyStore
*iface
)
1476 MMDevPropStore
*This
= impl_from_IPropertyStore(iface
);
1477 TRACE("(%p)\n", iface
);
1479 if (This
->access
!= STGM_WRITE
1480 && This
->access
!= STGM_READWRITE
)
1481 return STG_E_ACCESSDENIED
;
1483 /* Does nothing - for mmdevapi, the propstore values are written on SetValue,
1489 static const IPropertyStoreVtbl MMDevPropVtbl
=
1491 MMDevPropStore_QueryInterface
,
1492 MMDevPropStore_AddRef
,
1493 MMDevPropStore_Release
,
1494 MMDevPropStore_GetCount
,
1495 MMDevPropStore_GetAt
,
1496 MMDevPropStore_GetValue
,
1497 MMDevPropStore_SetValue
,
1498 MMDevPropStore_Commit
1502 /* Property bag for IBaseFilter activation */
1503 static HRESULT WINAPI
PB_QueryInterface(IPropertyBag
*iface
, REFIID riid
, void **ppv
)
1505 ERR("Should not be called\n");
1507 return E_NOINTERFACE
;
1510 static ULONG WINAPI
PB_AddRef(IPropertyBag
*iface
)
1512 ERR("Should not be called\n");
1516 static ULONG WINAPI
PB_Release(IPropertyBag
*iface
)
1518 ERR("Should not be called\n");
1522 static HRESULT WINAPI
PB_Read(IPropertyBag
*iface
, LPCOLESTR name
, VARIANT
*var
, IErrorLog
*log
)
1524 static const WCHAR dsguid
[] = { 'D','S','G','u','i','d', 0 };
1525 IPropertyBagImpl
*This
= impl_from_IPropertyBag(iface
);
1526 TRACE("Trying to read %s, type %u\n", debugstr_w(name
), var
->n1
.n2
.vt
);
1527 if (!lstrcmpW(name
, dsguid
))
1530 StringFromGUID2(&This
->devguid
, guidstr
,ARRAY_SIZE(guidstr
));
1531 var
->n1
.n2
.vt
= VT_BSTR
;
1532 var
->n1
.n2
.n3
.bstrVal
= SysAllocString(guidstr
);
1535 ERR("Unknown property '%s' queried\n", debugstr_w(name
));
1539 static HRESULT WINAPI
PB_Write(IPropertyBag
*iface
, LPCOLESTR name
, VARIANT
*var
)
1541 ERR("Should not be called\n");
1545 static const IPropertyBagVtbl PB_Vtbl
=
1554 static ULONG WINAPI
info_device_ps_AddRef(IPropertyStore
*iface
)
1559 static ULONG WINAPI
info_device_ps_Release(IPropertyStore
*iface
)
1564 static HRESULT WINAPI
info_device_ps_GetValue(IPropertyStore
*iface
,
1565 REFPROPERTYKEY key
, PROPVARIANT
*pv
)
1567 TRACE("(static)->(\"%s,%u\", %p)\n", debugstr_guid(&key
->fmtid
), key
? key
->pid
: 0, pv
);
1572 if (IsEqualPropertyKey(*key
, DEVPKEY_Device_Driver
))
1574 INT size
= (lstrlenW(drvs
.module_name
) + 1) * sizeof(WCHAR
);
1576 pv
->u
.pwszVal
= CoTaskMemAlloc(size
);
1578 return E_OUTOFMEMORY
;
1579 memcpy(pv
->u
.pwszVal
, drvs
.module_name
, size
);
1583 return E_INVALIDARG
;
1586 static const IPropertyStoreVtbl info_device_ps_Vtbl
=
1589 info_device_ps_AddRef
,
1590 info_device_ps_Release
,
1593 info_device_ps_GetValue
,
1598 static IPropertyStore info_device_ps
= {
1599 &info_device_ps_Vtbl
1602 static ULONG WINAPI
info_device_AddRef(IMMDevice
*iface
)
1607 static ULONG WINAPI
info_device_Release(IMMDevice
*iface
)
1612 static HRESULT WINAPI
info_device_OpenPropertyStore(IMMDevice
*iface
,
1613 DWORD access
, IPropertyStore
**ppv
)
1615 TRACE("(static)->(%x, %p)\n", access
, ppv
);
1616 *ppv
= &info_device_ps
;
1620 static const IMMDeviceVtbl info_device_Vtbl
=
1624 info_device_Release
,
1626 info_device_OpenPropertyStore
,
1631 static IMMDevice info_device
= {