wined3d: Cleanup IWineD3DBaseSwapChainImpl_GetBackBuffer() a bit.
[wine/multimedia.git] / dlls / mmdevapi / devenum.c
blob6fa637fc789d296ed3c12f7e838d65a1062e622b
1 /*
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
19 #include "config.h"
21 #include <stdarg.h>
23 #ifdef HAVE_AL_AL_H
24 #include <AL/al.h>
25 #include <AL/alc.h>
26 #elif defined(HAVE_OPENAL_AL_H)
27 #include <OpenAL/al.h>
28 #include <OpenAL/alc.h>
29 #endif
31 #define NONAMELESSUNION
32 #define CINTERFACE
33 #define COBJMACROS
34 #include "windef.h"
35 #include "winbase.h"
36 #include "winnls.h"
37 #include "winreg.h"
38 #include "wine/debug.h"
39 #include "wine/unicode.h"
41 #include "ole2.h"
42 #include "mmdeviceapi.h"
43 #include "dshow.h"
44 #include "dsound.h"
45 #include "audioclient.h"
46 #include "endpointvolume.h"
47 #include "audiopolicy.h"
49 #include "mmdevapi.h"
50 #include "devpkey.h"
52 WINE_DEFAULT_DEBUG_CHANNEL(mmdevapi);
54 static const WCHAR software_mmdevapi[] =
55 { 'S','o','f','t','w','a','r','e','\\',
56 'M','i','c','r','o','s','o','f','t','\\',
57 'W','i','n','d','o','w','s','\\',
58 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
59 'M','M','D','e','v','i','c','e','s','\\',
60 'A','u','d','i','o',0};
61 static const WCHAR reg_render[] =
62 { 'R','e','n','d','e','r',0 };
63 static const WCHAR reg_capture[] =
64 { 'C','a','p','t','u','r','e',0 };
65 static const WCHAR reg_devicestate[] =
66 { 'D','e','v','i','c','e','S','t','a','t','e',0 };
67 static const WCHAR reg_properties[] =
68 { 'P','r','o','p','e','r','t','i','e','s',0 };
70 static HKEY key_render;
71 static HKEY key_capture;
73 typedef struct MMDevPropStoreImpl
75 const IPropertyStoreVtbl *lpVtbl;
76 LONG ref;
77 MMDevice *parent;
78 DWORD access;
79 } MMDevPropStore;
81 typedef struct MMDevEnumImpl
83 const IMMDeviceEnumeratorVtbl *lpVtbl;
84 LONG ref;
85 } MMDevEnumImpl;
87 static MMDevEnumImpl *MMDevEnumerator;
88 static MMDevice **MMDevice_head;
89 static MMDevice *MMDevice_def_rec, *MMDevice_def_play;
90 static DWORD MMDevice_count;
91 static const IMMDeviceEnumeratorVtbl MMDevEnumVtbl;
92 static const IMMDeviceCollectionVtbl MMDevColVtbl;
93 static const IMMDeviceVtbl MMDeviceVtbl;
94 static const IPropertyStoreVtbl MMDevPropVtbl;
95 static const IMMEndpointVtbl MMEndpointVtbl;
97 typedef struct MMDevColImpl
99 const IMMDeviceCollectionVtbl *lpVtbl;
100 LONG ref;
101 EDataFlow flow;
102 DWORD state;
103 } MMDevColImpl;
105 typedef struct IPropertyBagImpl {
106 const IPropertyBagVtbl *lpVtbl;
107 GUID devguid;
108 } IPropertyBagImpl;
109 static const IPropertyBagVtbl PB_Vtbl;
111 static HRESULT MMDevPropStore_Create(MMDevice *This, DWORD access, IPropertyStore **ppv);
113 /* Creates or updates the state of a device
114 * If GUID is null, a random guid will be assigned
115 * and the device will be created
117 static void MMDevice_Create(MMDevice **dev, WCHAR *name, GUID *id, EDataFlow flow, DWORD state, BOOL setdefault)
119 HKEY key, root;
120 MMDevice *cur;
121 WCHAR guidstr[39];
122 DWORD i;
124 for (i = 0; i < MMDevice_count; ++i)
126 cur = MMDevice_head[i];
127 if (cur->flow == flow && !lstrcmpW(cur->alname, name))
129 LONG ret;
130 /* Same device, update state */
131 cur->state = state;
132 StringFromGUID2(&cur->devguid, guidstr, sizeof(guidstr)/sizeof(*guidstr));
133 ret = RegOpenKeyExW(flow == eRender ? key_render : key_capture, guidstr, 0, KEY_WRITE, &key);
134 if (ret == ERROR_SUCCESS)
136 RegSetValueExW(key, reg_devicestate, 0, REG_DWORD, (const BYTE*)&state, sizeof(DWORD));
137 RegCloseKey(key);
139 goto done;
143 /* No device found, allocate new one */
144 cur = HeapAlloc(GetProcessHeap(), 0, sizeof(*cur));
145 if (!cur)
146 return;
147 cur->alname = HeapAlloc(GetProcessHeap(), 0, (lstrlenW(name)+1)*sizeof(WCHAR));
148 if (!cur->alname)
150 HeapFree(GetProcessHeap(), 0, cur);
151 return;
153 lstrcpyW(cur->alname, name);
154 cur->lpVtbl = &MMDeviceVtbl;
155 cur->lpEndpointVtbl = &MMEndpointVtbl;
156 cur->ref = 0;
157 InitializeCriticalSection(&cur->crst);
158 cur->crst.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": MMDevice.crst");
159 cur->flow = flow;
160 cur->state = state;
161 cur->device = NULL;
162 if (!id)
164 id = &cur->devguid;
165 CoCreateGuid(id);
167 cur->devguid = *id;
168 StringFromGUID2(id, guidstr, sizeof(guidstr)/sizeof(*guidstr));
169 if (flow == eRender)
170 root = key_render;
171 else
172 root = key_capture;
173 if (!RegCreateKeyExW(root, guidstr, 0, NULL, 0, KEY_WRITE|KEY_READ, NULL, &key, NULL))
175 HKEY keyprop;
176 RegSetValueExW(key, reg_devicestate, 0, REG_DWORD, (const BYTE*)&state, sizeof(DWORD));
177 if (!RegCreateKeyExW(key, reg_properties, 0, NULL, 0, KEY_WRITE|KEY_READ, NULL, &keyprop, NULL))
179 PROPVARIANT pv;
180 pv.vt = VT_LPWSTR;
181 pv.u.pwszVal = name;
182 MMDevice_SetPropValue(id, flow, (const PROPERTYKEY*)&DEVPKEY_Device_FriendlyName, &pv);
183 MMDevice_SetPropValue(id, flow, (const PROPERTYKEY*)&DEVPKEY_Device_DeviceDesc, &pv);
184 RegCloseKey(keyprop);
186 RegCloseKey(key);
188 if (!MMDevice_head)
189 MMDevice_head = HeapAlloc(GetProcessHeap(), 0, sizeof(*MMDevice_head));
190 else
191 MMDevice_head = HeapReAlloc(GetProcessHeap(), 0, MMDevice_head, sizeof(*MMDevice_head)*(1+MMDevice_count));
192 MMDevice_head[MMDevice_count++] = cur;
194 done:
195 if (setdefault)
197 if (flow == eRender)
198 MMDevice_def_play = cur;
199 else
200 MMDevice_def_rec = cur;
202 if (dev)
203 *dev = cur;
206 static void MMDevice_Destroy(MMDevice *This)
208 DWORD i;
209 TRACE("Freeing %s\n", debugstr_w(This->alname));
210 /* Since this function is called at destruction time, reordering of the list is unimportant */
211 for (i = 0; i < MMDevice_count; ++i)
213 if (MMDevice_head[i] == This)
215 MMDevice_head[i] = MMDevice_head[--MMDevice_count];
216 break;
219 #ifdef HAVE_OPENAL
220 if (This->device)
221 palcCloseDevice(This->device);
222 #endif
223 This->crst.DebugInfo->Spare[0] = 0;
224 DeleteCriticalSection(&This->crst);
225 HeapFree(GetProcessHeap(), 0, This->alname);
226 HeapFree(GetProcessHeap(), 0, This);
229 static HRESULT WINAPI MMDevice_QueryInterface(IMMDevice *iface, REFIID riid, void **ppv)
231 MMDevice *This = (MMDevice *)iface;
232 TRACE("(%p)->(%s,%p)\n", iface, debugstr_guid(riid), ppv);
234 if (!ppv)
235 return E_POINTER;
236 *ppv = NULL;
237 if (IsEqualIID(riid, &IID_IUnknown)
238 || IsEqualIID(riid, &IID_IMMDevice))
239 *ppv = This;
240 else if (IsEqualIID(riid, &IID_IMMEndpoint))
241 *ppv = &This->lpEndpointVtbl;
242 if (*ppv)
244 IUnknown_AddRef((IUnknown*)*ppv);
245 return S_OK;
247 WARN("Unknown interface %s\n", debugstr_guid(riid));
248 return E_NOINTERFACE;
251 static ULONG WINAPI MMDevice_AddRef(IMMDevice *iface)
253 MMDevice *This = (MMDevice *)iface;
254 LONG ref;
256 ref = InterlockedIncrement(&This->ref);
257 TRACE("Refcount now %i\n", ref);
258 return ref;
261 static ULONG WINAPI MMDevice_Release(IMMDevice *iface)
263 MMDevice *This = (MMDevice *)iface;
264 LONG ref;
266 ref = InterlockedDecrement(&This->ref);
267 TRACE("Refcount now %i\n", ref);
268 return ref;
271 static HRESULT WINAPI MMDevice_Activate(IMMDevice *iface, REFIID riid, DWORD clsctx, PROPVARIANT *params, void **ppv)
273 HRESULT hr = E_NOINTERFACE;
275 #ifdef HAVE_OPENAL
276 MMDevice *This = (MMDevice *)iface;
278 TRACE("(%p)->(%p,%x,%p,%p)\n", iface, riid, clsctx, params, ppv);
280 if (!ppv)
281 return E_POINTER;
283 if (!openal_loaded)
285 WARN("OpenAL is still not loaded\n");
286 hr = AUDCLNT_E_SERVICE_NOT_RUNNING;
288 else if (IsEqualIID(riid, &IID_IAudioClient))
289 hr = AudioClient_Create(This, (IAudioClient**)ppv);
290 else if (IsEqualIID(riid, &IID_IAudioEndpointVolume))
291 hr = AudioEndpointVolume_Create(This, (IAudioEndpointVolume**)ppv);
292 else if (IsEqualIID(riid, &IID_IAudioSessionManager)
293 || IsEqualIID(riid, &IID_IAudioSessionManager2))
295 FIXME("IID_IAudioSessionManager unsupported\n");
297 else if (IsEqualIID(riid, &IID_IBaseFilter))
299 if (This->flow == eRender)
300 hr = CoCreateInstance(&CLSID_DSoundRender, NULL, clsctx, riid, ppv);
301 else
302 ERR("Not supported for recording?\n");
303 if (SUCCEEDED(hr))
305 IPersistPropertyBag *ppb;
306 hr = IUnknown_QueryInterface((IUnknown*)*ppv, &IID_IPersistPropertyBag, (void*)&ppb);
307 if (SUCCEEDED(hr))
309 /* ::Load cannot assume the interface stays alive after the function returns,
310 * so just create the interface on the stack, saves a lot of complicated code */
311 IPropertyBagImpl bag = { &PB_Vtbl, This->devguid };
312 hr = IPersistPropertyBag_Load(ppb, (IPropertyBag*)&bag, NULL);
313 IPersistPropertyBag_Release(ppb);
314 if (FAILED(hr))
315 IBaseFilter_Release((IBaseFilter*)*ppv);
317 else
319 FIXME("Wine doesn't support IPersistPropertyBag on DSoundRender yet, ignoring..\n");
320 hr = S_OK;
324 else if (IsEqualIID(riid, &IID_IDeviceTopology))
326 FIXME("IID_IDeviceTopology unsupported\n");
328 else if (IsEqualIID(riid, &IID_IDirectSound)
329 || IsEqualIID(riid, &IID_IDirectSound8))
331 if (This->flow == eRender)
332 hr = CoCreateInstance(&CLSID_DirectSound8, NULL, clsctx, riid, ppv);
333 if (SUCCEEDED(hr))
335 hr = IDirectSound_Initialize((IDirectSound*)*ppv, &This->devguid);
336 if (FAILED(hr))
337 IDirectSound_Release((IDirectSound*)*ppv);
340 else if (IsEqualIID(riid, &IID_IDirectSoundCapture)
341 || IsEqualIID(riid, &IID_IDirectSoundCapture8))
343 if (This->flow == eCapture)
344 hr = CoCreateInstance(&CLSID_DirectSoundCapture8, NULL, clsctx, riid, ppv);
345 if (SUCCEEDED(hr))
347 hr = IDirectSoundCapture_Initialize((IDirectSoundCapture*)*ppv, &This->devguid);
348 if (FAILED(hr))
349 IDirectSoundCapture_Release((IDirectSoundCapture*)*ppv);
352 else
353 ERR("Invalid/unknown iid %s\n", debugstr_guid(riid));
354 #else
355 if (!ppv) return E_POINTER;
356 hr = AUDCLNT_E_SERVICE_NOT_RUNNING;
357 #endif
359 if (FAILED(hr))
360 *ppv = NULL;
362 TRACE("Returning %08x\n", hr);
363 return hr;
366 static HRESULT WINAPI MMDevice_OpenPropertyStore(IMMDevice *iface, DWORD access, IPropertyStore **ppv)
368 MMDevice *This = (MMDevice *)iface;
369 TRACE("(%p)->(%x,%p)\n", This, access, ppv);
371 if (!ppv)
372 return E_POINTER;
373 return MMDevPropStore_Create(This, access, ppv);
376 static HRESULT WINAPI MMDevice_GetId(IMMDevice *iface, WCHAR **itemid)
378 MMDevice *This = (MMDevice *)iface;
379 WCHAR *str;
380 GUID *id = &This->devguid;
381 static const WCHAR formatW[] = { '{','0','.','0','.','0','.','0','0','0','0','0','0','0','0','}','.',
382 '{','%','0','8','X','-','%','0','4','X','-',
383 '%','0','4','X','-','%','0','2','X','%','0','2','X','-',
384 '%','0','2','X','%','0','2','X','%','0','2','X','%','0','2','X',
385 '%','0','2','X','%','0','2','X','}',0 };
387 TRACE("(%p)->(%p)\n", This, itemid);
388 if (!itemid)
389 return E_POINTER;
390 *itemid = str = CoTaskMemAlloc(56 * sizeof(WCHAR));
391 if (!str)
392 return E_OUTOFMEMORY;
393 wsprintfW( str, formatW, id->Data1, id->Data2, id->Data3,
394 id->Data4[0], id->Data4[1], id->Data4[2], id->Data4[3],
395 id->Data4[4], id->Data4[5], id->Data4[6], id->Data4[7] );
396 return S_OK;
399 static HRESULT WINAPI MMDevice_GetState(IMMDevice *iface, DWORD *state)
401 MMDevice *This = (MMDevice *)iface;
402 TRACE("(%p)->(%p)\n", iface, state);
404 if (!state)
405 return E_POINTER;
406 *state = This->state;
407 return S_OK;
410 static const IMMDeviceVtbl MMDeviceVtbl =
412 MMDevice_QueryInterface,
413 MMDevice_AddRef,
414 MMDevice_Release,
415 MMDevice_Activate,
416 MMDevice_OpenPropertyStore,
417 MMDevice_GetId,
418 MMDevice_GetState
421 static MMDevice *get_this_from_endpoint(IMMEndpoint *iface)
423 return (MMDevice*)((char*)iface - offsetof(MMDevice,lpEndpointVtbl));
426 static HRESULT WINAPI MMEndpoint_QueryInterface(IMMEndpoint *iface, REFIID riid, void **ppv)
428 MMDevice *This = get_this_from_endpoint(iface);
429 return IMMDevice_QueryInterface((IMMDevice*)This, riid, ppv);
432 static ULONG WINAPI MMEndpoint_AddRef(IMMEndpoint *iface)
434 MMDevice *This = get_this_from_endpoint(iface);
435 return IMMDevice_AddRef((IMMDevice*)This);
438 static ULONG WINAPI MMEndpoint_Release(IMMEndpoint *iface)
440 MMDevice *This = get_this_from_endpoint(iface);
441 return IMMDevice_Release((IMMDevice*)This);
444 static HRESULT WINAPI MMEndpoint_GetDataFlow(IMMEndpoint *iface, EDataFlow *flow)
446 MMDevice *This = get_this_from_endpoint(iface);
447 if (!flow)
448 return E_POINTER;
449 *flow = This->flow;
450 return S_OK;
453 static const IMMEndpointVtbl MMEndpointVtbl =
455 MMEndpoint_QueryInterface,
456 MMEndpoint_AddRef,
457 MMEndpoint_Release,
458 MMEndpoint_GetDataFlow
461 static HRESULT MMDevCol_Create(IMMDeviceCollection **ppv, EDataFlow flow, DWORD state)
463 MMDevColImpl *This;
465 This = HeapAlloc(GetProcessHeap(), 0, sizeof(*This));
466 *ppv = NULL;
467 if (!This)
468 return E_OUTOFMEMORY;
469 This->lpVtbl = &MMDevColVtbl;
470 This->ref = 1;
471 This->flow = flow;
472 This->state = state;
473 *ppv = (IMMDeviceCollection*)This;
474 return S_OK;
477 static void MMDevCol_Destroy(MMDevColImpl *This)
479 HeapFree(GetProcessHeap(), 0, This);
482 static HRESULT WINAPI MMDevCol_QueryInterface(IMMDeviceCollection *iface, REFIID riid, void **ppv)
484 MMDevColImpl *This = (MMDevColImpl*)iface;
486 if (!ppv)
487 return E_POINTER;
488 if (IsEqualIID(riid, &IID_IUnknown)
489 || IsEqualIID(riid, &IID_IMMDeviceCollection))
490 *ppv = This;
491 else
492 *ppv = NULL;
493 if (!*ppv)
494 return E_NOINTERFACE;
495 IUnknown_AddRef((IUnknown*)*ppv);
496 return S_OK;
499 static ULONG WINAPI MMDevCol_AddRef(IMMDeviceCollection *iface)
501 MMDevColImpl *This = (MMDevColImpl*)iface;
502 LONG ref = InterlockedIncrement(&This->ref);
503 TRACE("Refcount now %i\n", ref);
504 return ref;
507 static ULONG WINAPI MMDevCol_Release(IMMDeviceCollection *iface)
509 MMDevColImpl *This = (MMDevColImpl*)iface;
510 LONG ref = InterlockedDecrement(&This->ref);
511 TRACE("Refcount now %i\n", ref);
512 if (!ref)
513 MMDevCol_Destroy(This);
514 return ref;
517 static HRESULT WINAPI MMDevCol_GetCount(IMMDeviceCollection *iface, UINT *numdevs)
519 MMDevColImpl *This = (MMDevColImpl*)iface;
520 DWORD i;
522 TRACE("(%p)->(%p)\n", This, numdevs);
523 if (!numdevs)
524 return E_POINTER;
526 *numdevs = 0;
527 for (i = 0; i < MMDevice_count; ++i)
529 MMDevice *cur = MMDevice_head[i];
530 if ((cur->flow == This->flow || This->flow == eAll)
531 && (cur->state & This->state))
532 ++(*numdevs);
534 return S_OK;
537 static HRESULT WINAPI MMDevCol_Item(IMMDeviceCollection *iface, UINT n, IMMDevice **dev)
539 MMDevColImpl *This = (MMDevColImpl*)iface;
540 DWORD i = 0, j = 0;
542 TRACE("(%p)->(%u, %p)\n", This, n, dev);
543 if (!dev)
544 return E_POINTER;
546 for (j = 0; j < MMDevice_count; ++j)
548 MMDevice *cur = MMDevice_head[j];
549 if ((cur->flow == This->flow || This->flow == eAll)
550 && (cur->state & This->state)
551 && i++ == n)
553 *dev = (IMMDevice *)cur;
554 IMMDevice_AddRef(*dev);
555 return S_OK;
558 WARN("Could not obtain item %u\n", n);
559 *dev = NULL;
560 return E_INVALIDARG;
563 static const IMMDeviceCollectionVtbl MMDevColVtbl =
565 MMDevCol_QueryInterface,
566 MMDevCol_AddRef,
567 MMDevCol_Release,
568 MMDevCol_GetCount,
569 MMDevCol_Item
572 static const WCHAR propkey_formatW[] = {
573 '{','%','0','8','X','-','%','0','4','X','-',
574 '%','0','4','X','-','%','0','2','X','%','0','2','X','-',
575 '%','0','2','X','%','0','2','X','%','0','2','X','%','0','2','X',
576 '%','0','2','X','%','0','2','X','}',',','%','d',0 };
578 static HRESULT MMDevPropStore_OpenPropKey(const GUID *guid, DWORD flow, HKEY *propkey)
580 WCHAR buffer[39];
581 LONG ret;
582 HKEY key;
583 StringFromGUID2(guid, buffer, 39);
584 if ((ret = RegOpenKeyExW(flow == eRender ? key_render : key_capture, buffer, 0, KEY_READ|KEY_WRITE, &key)) != ERROR_SUCCESS)
586 WARN("Opening key %s failed with %u\n", debugstr_w(buffer), ret);
587 return E_FAIL;
589 ret = RegOpenKeyExW(key, reg_properties, 0, KEY_READ|KEY_WRITE, propkey);
590 RegCloseKey(key);
591 if (ret != ERROR_SUCCESS)
593 WARN("Opening key %s failed with %u\n", debugstr_w(reg_properties), ret);
594 return E_FAIL;
596 return S_OK;
599 HRESULT MMDevice_GetPropValue(const GUID *devguid, DWORD flow, REFPROPERTYKEY key, PROPVARIANT *pv)
601 WCHAR buffer[80];
602 const GUID *id = &key->fmtid;
603 DWORD type, size;
604 HRESULT hr = S_OK;
605 HKEY regkey;
606 LONG ret;
608 hr = MMDevPropStore_OpenPropKey(devguid, flow, &regkey);
609 if (FAILED(hr))
610 return hr;
611 wsprintfW( buffer, propkey_formatW, id->Data1, id->Data2, id->Data3,
612 id->Data4[0], id->Data4[1], id->Data4[2], id->Data4[3],
613 id->Data4[4], id->Data4[5], id->Data4[6], id->Data4[7], key->pid );
614 ret = RegGetValueW(regkey, NULL, buffer, RRF_RT_ANY, &type, NULL, &size);
615 if (ret != ERROR_SUCCESS)
617 WARN("Reading %s returned %d\n", debugstr_w(buffer), ret);
618 RegCloseKey(regkey);
619 PropVariantClear(pv);
620 return S_OK;
623 switch (type)
625 case REG_SZ:
627 pv->vt = VT_LPWSTR;
628 pv->u.pwszVal = CoTaskMemAlloc(size);
629 if (!pv->u.pwszVal)
630 hr = E_OUTOFMEMORY;
631 else
632 RegGetValueW(regkey, NULL, buffer, RRF_RT_REG_SZ, NULL, (BYTE*)pv->u.pwszVal, &size);
633 break;
635 case REG_DWORD:
637 pv->vt = VT_UI4;
638 RegGetValueW(regkey, NULL, buffer, RRF_RT_REG_DWORD, NULL, (BYTE*)&pv->u.ulVal, &size);
639 break;
641 case REG_BINARY:
643 pv->vt = VT_BLOB;
644 pv->u.blob.cbSize = size;
645 pv->u.blob.pBlobData = CoTaskMemAlloc(size);
646 if (!pv->u.blob.pBlobData)
647 hr = E_OUTOFMEMORY;
648 else
649 RegGetValueW(regkey, NULL, buffer, RRF_RT_REG_BINARY, NULL, (BYTE*)pv->u.blob.pBlobData, &size);
650 break;
652 default:
653 ERR("Unknown/unhandled type: %u\n", type);
654 PropVariantClear(pv);
655 break;
657 RegCloseKey(regkey);
658 return hr;
661 HRESULT MMDevice_SetPropValue(const GUID *devguid, DWORD flow, REFPROPERTYKEY key, REFPROPVARIANT pv)
663 WCHAR buffer[80];
664 const GUID *id = &key->fmtid;
665 HRESULT hr;
666 HKEY regkey;
667 LONG ret;
669 hr = MMDevPropStore_OpenPropKey(devguid, flow, &regkey);
670 if (FAILED(hr))
671 return hr;
672 wsprintfW( buffer, propkey_formatW, id->Data1, id->Data2, id->Data3,
673 id->Data4[0], id->Data4[1], id->Data4[2], id->Data4[3],
674 id->Data4[4], id->Data4[5], id->Data4[6], id->Data4[7], key->pid );
675 switch (pv->vt)
677 case VT_UI4:
679 ret = RegSetValueExW(regkey, buffer, 0, REG_DWORD, (const BYTE*)&pv->u.ulVal, sizeof(DWORD));
680 break;
682 case VT_BLOB:
684 ret = RegSetValueExW(regkey, buffer, 0, REG_BINARY, pv->u.blob.pBlobData, pv->u.blob.cbSize);
685 TRACE("Blob %p %u\n", pv->u.blob.pBlobData, pv->u.blob.cbSize);
687 break;
689 case VT_LPWSTR:
691 ret = RegSetValueExW(regkey, buffer, 0, REG_SZ, (const BYTE*)pv->u.pwszVal, sizeof(WCHAR)*(1+lstrlenW(pv->u.pwszVal)));
692 break;
694 default:
695 ret = 0;
696 FIXME("Unhandled type %u\n", pv->vt);
697 hr = E_INVALIDARG;
698 break;
700 RegCloseKey(regkey);
701 TRACE("Writing %s returned %u\n", debugstr_w(buffer), ret);
702 return hr;
705 #ifdef HAVE_OPENAL
707 static void openal_setformat(MMDevice *This, DWORD freq)
709 HRESULT hr;
710 PROPVARIANT pv = { VT_EMPTY };
712 hr = MMDevice_GetPropValue(&This->devguid, This->flow, &PKEY_AudioEngine_DeviceFormat, &pv);
713 if (SUCCEEDED(hr) && pv.vt == VT_BLOB)
715 WAVEFORMATEX *pwfx;
716 pwfx = (WAVEFORMATEX*)pv.u.blob.pBlobData;
717 if (pwfx->nSamplesPerSec != freq)
719 pwfx->nSamplesPerSec = freq;
720 pwfx->nAvgBytesPerSec = freq * pwfx->nBlockAlign;
721 MMDevice_SetPropValue(&This->devguid, This->flow, &PKEY_AudioEngine_DeviceFormat, &pv);
723 CoTaskMemFree(pwfx);
725 else
727 WAVEFORMATEXTENSIBLE wfxe;
729 wfxe.Format.wFormatTag = WAVE_FORMAT_EXTENSIBLE;
730 wfxe.Format.nChannels = 2;
731 wfxe.Format.wBitsPerSample = 32;
732 wfxe.Format.nBlockAlign = wfxe.Format.nChannels * wfxe.Format.wBitsPerSample/8;
733 wfxe.Format.nSamplesPerSec = freq;
734 wfxe.Format.nAvgBytesPerSec = wfxe.Format.nSamplesPerSec * wfxe.Format.nBlockAlign;
735 wfxe.Format.cbSize = sizeof(wfxe)-sizeof(WAVEFORMATEX);
736 wfxe.Samples.wValidBitsPerSample = 32;
737 wfxe.SubFormat = KSDATAFORMAT_SUBTYPE_IEEE_FLOAT;
738 wfxe.dwChannelMask = SPEAKER_FRONT_LEFT|SPEAKER_FRONT_RIGHT;
740 pv.vt = VT_BLOB;
741 pv.u.blob.cbSize = sizeof(wfxe);
742 pv.u.blob.pBlobData = (BYTE*)&wfxe;
743 MMDevice_SetPropValue(&This->devguid, This->flow, &PKEY_AudioEngine_DeviceFormat, &pv);
744 MMDevice_SetPropValue(&This->devguid, This->flow, &PKEY_AudioEngine_OEMFormat, &pv);
748 static int blacklist_pulse;
750 static int blacklist(const char *dev) {
751 #ifdef __linux__
752 if (!strncmp(dev, "OSS ", 4))
753 return 1;
754 #endif
755 if (blacklist_pulse && !strncmp(dev, "PulseAudio ", 11))
756 return 1;
757 if (!strncmp(dev, "ALSA ", 5) && strstr(dev, "hw:"))
758 return 1;
759 if (!strncmp(dev, "PortAudio ", 10))
760 return 1;
761 return 0;
764 static void pulse_fixup(const char *devstr, const char **defstr, int render) {
765 static int warned;
766 int default_pulse;
768 if (render && !blacklist_pulse && !local_contexts)
769 blacklist_pulse = 1;
771 if (!blacklist_pulse || !devstr || !*devstr)
772 return;
774 default_pulse = !strncmp(*defstr, "PulseAudio ", 11);
776 while (*devstr && !strncmp(devstr, "PulseAudio ", 11))
777 devstr += strlen(devstr) + 1;
779 /* Could still be a newer version, so check for 1.11 if more devices are enabled */
780 if (render && *devstr) {
781 ALCdevice *dev = palcOpenDevice(devstr);
782 ALCcontext *ctx = palcCreateContext(dev, NULL);
783 if (ctx) {
784 const char *ver;
786 setALContext(ctx);
787 ver = palGetString(AL_VERSION);
788 popALContext();
789 palcDestroyContext(ctx);
791 if (!strcmp(ver, "1.1 ALSOFT 1.11.753")) {
792 blacklist_pulse = 0;
793 palcCloseDevice(dev);
794 return;
797 if (dev)
798 palcCloseDevice(dev);
801 if (!warned++) {
802 ERR("Disabling pulseaudio because of old openal version\n");
803 ERR("Please upgrade to openal-soft v1.12 or newer\n");
805 TRACE("New default: %s\n", devstr);
806 if (default_pulse)
807 *defstr = devstr;
810 static void openal_scanrender(void)
812 WCHAR name[MAX_PATH];
813 ALCdevice *dev;
814 const ALCchar *devstr, *defaultstr;
815 int defblacklisted;
816 EnterCriticalSection(&openal_crst);
817 if (palcIsExtensionPresent(NULL, "ALC_ENUMERATE_ALL_EXT")) {
818 defaultstr = palcGetString(NULL, ALC_DEFAULT_ALL_DEVICES_SPECIFIER);
819 devstr = palcGetString(NULL, ALC_ALL_DEVICES_SPECIFIER);
820 } else {
821 defaultstr = palcGetString(NULL, ALC_DEFAULT_DEVICE_SPECIFIER);
822 devstr = palcGetString(NULL, ALC_DEVICE_SPECIFIER);
824 pulse_fixup(devstr, &defaultstr, 1);
825 defblacklisted = blacklist(defaultstr);
826 if (defblacklisted)
827 WARN("Disabling blacklist because %s is blacklisted\n", defaultstr);
828 if (devstr)
829 for (; *devstr; devstr += strlen(devstr)+1) {
830 MMDevice *mmdev;
831 MultiByteToWideChar( CP_UNIXCP, 0, devstr, -1,
832 name, sizeof(name)/sizeof(*name)-1 );
833 name[sizeof(name)/sizeof(*name)-1] = 0;
834 /* Only enable blacklist if the default device isn't blacklisted */
835 if (!defblacklisted && blacklist(devstr)) {
836 WARN("Not adding %s: device is blacklisted\n", devstr);
837 continue;
839 TRACE("Adding %s\n", devstr);
840 dev = palcOpenDevice(devstr);
841 MMDevice_Create(&mmdev, name, NULL, eRender, dev ? DEVICE_STATE_ACTIVE : DEVICE_STATE_NOTPRESENT, !strcmp(devstr, defaultstr));
842 if (dev)
844 ALint freq = 44100;
845 palcGetIntegerv(dev, ALC_FREQUENCY, 1, &freq);
846 openal_setformat(mmdev, freq);
847 palcCloseDevice(dev);
849 else
850 WARN("Could not open device: %04x\n", palcGetError(NULL));
852 LeaveCriticalSection(&openal_crst);
855 static void openal_scancapture(void)
857 WCHAR name[MAX_PATH];
858 ALCdevice *dev;
859 const ALCchar *devstr, *defaultstr;
860 int defblacklisted;
862 EnterCriticalSection(&openal_crst);
863 devstr = palcGetString(NULL, ALC_CAPTURE_DEVICE_SPECIFIER);
864 defaultstr = palcGetString(NULL, ALC_CAPTURE_DEFAULT_DEVICE_SPECIFIER);
865 pulse_fixup(devstr, &defaultstr, 0);
866 defblacklisted = blacklist(defaultstr);
867 if (defblacklisted)
868 WARN("Disabling blacklist because %s is blacklisted\n", defaultstr);
869 if (devstr && *devstr)
870 for (; *devstr; devstr += strlen(devstr)+1) {
871 MMDevice *mmdev;
872 ALint freq = 44100;
873 MultiByteToWideChar( CP_UNIXCP, 0, devstr, -1,
874 name, sizeof(name)/sizeof(*name)-1 );
875 name[sizeof(name)/sizeof(*name)-1] = 0;
876 if (!defblacklisted && blacklist(devstr)) {
877 WARN("Not adding %s: device is blacklisted\n", devstr);
878 continue;
880 TRACE("Adding %s\n", devstr);
881 dev = palcCaptureOpenDevice(devstr, freq, AL_FORMAT_MONO16, 65536);
882 MMDevice_Create(&mmdev, name, NULL, eCapture, dev ? DEVICE_STATE_ACTIVE : DEVICE_STATE_NOTPRESENT, !strcmp(devstr, defaultstr));
883 if (dev) {
884 openal_setformat(mmdev, freq);
885 palcCaptureCloseDevice(dev);
886 } else
887 WARN("Could not open device: %04x\n", palcGetError(NULL));
889 LeaveCriticalSection(&openal_crst);
891 #endif /*HAVE_OPENAL*/
893 HRESULT MMDevEnum_Create(REFIID riid, void **ppv)
895 MMDevEnumImpl *This = MMDevEnumerator;
897 if (!This)
899 DWORD i = 0;
900 HKEY root, cur;
901 LONG ret;
902 DWORD curflow;
904 This = HeapAlloc(GetProcessHeap(), 0, sizeof(*This));
905 *ppv = NULL;
906 if (!This)
907 return E_OUTOFMEMORY;
908 This->ref = 1;
909 This->lpVtbl = &MMDevEnumVtbl;
910 MMDevEnumerator = This;
912 ret = RegCreateKeyExW(HKEY_LOCAL_MACHINE, software_mmdevapi, 0, NULL, 0, KEY_WRITE|KEY_READ, NULL, &root, NULL);
913 if (ret == ERROR_SUCCESS)
914 ret = RegCreateKeyExW(root, reg_capture, 0, NULL, 0, KEY_READ|KEY_WRITE, NULL, &key_capture, NULL);
915 if (ret == ERROR_SUCCESS)
916 ret = RegCreateKeyExW(root, reg_render, 0, NULL, 0, KEY_READ|KEY_WRITE, NULL, &key_render, NULL);
917 RegCloseKey(root);
918 cur = key_capture;
919 curflow = eCapture;
920 if (ret != ERROR_SUCCESS)
922 RegCloseKey(key_capture);
923 key_render = key_capture = NULL;
924 WARN("Couldn't create key: %u\n", ret);
925 return E_FAIL;
927 else do {
928 WCHAR guidvalue[39];
929 GUID guid;
930 DWORD len;
931 PROPVARIANT pv = { VT_EMPTY };
933 len = sizeof(guidvalue);
934 ret = RegEnumKeyExW(cur, i++, guidvalue, &len, NULL, NULL, NULL, NULL);
935 if (ret == ERROR_NO_MORE_ITEMS)
937 if (cur == key_capture)
939 cur = key_render;
940 curflow = eRender;
941 i = 0;
942 continue;
944 break;
946 if (ret != ERROR_SUCCESS)
947 continue;
948 if (SUCCEEDED(CLSIDFromString(guidvalue, &guid))
949 && SUCCEEDED(MMDevice_GetPropValue(&guid, curflow, (const PROPERTYKEY*)&DEVPKEY_Device_FriendlyName, &pv))
950 && pv.vt == VT_LPWSTR)
952 MMDevice_Create(NULL, pv.u.pwszVal, &guid, curflow,
953 DEVICE_STATE_NOTPRESENT, FALSE);
954 CoTaskMemFree(pv.u.pwszVal);
956 } while (1);
957 #ifdef HAVE_OPENAL
958 if (openal_loaded)
960 openal_scanrender();
961 openal_scancapture();
963 else
964 FIXME("OpenAL support not enabled, application will not find sound devices\n");
965 #else
966 ERR("OpenAL support not compiled in, application will not find sound devices\n");
967 #endif /*HAVE_OPENAL*/
969 return IUnknown_QueryInterface((IUnknown*)This, riid, ppv);
972 void MMDevEnum_Free(void)
974 while (MMDevice_count)
975 MMDevice_Destroy(MMDevice_head[0]);
976 RegCloseKey(key_render);
977 RegCloseKey(key_capture);
978 key_render = key_capture = NULL;
979 HeapFree(GetProcessHeap(), 0, MMDevEnumerator);
980 MMDevEnumerator = NULL;
983 static HRESULT WINAPI MMDevEnum_QueryInterface(IMMDeviceEnumerator *iface, REFIID riid, void **ppv)
985 MMDevEnumImpl *This = (MMDevEnumImpl*)iface;
987 if (!ppv)
988 return E_POINTER;
989 if (IsEqualIID(riid, &IID_IUnknown)
990 || IsEqualIID(riid, &IID_IMMDeviceEnumerator))
991 *ppv = This;
992 else
993 *ppv = NULL;
994 if (!*ppv)
995 return E_NOINTERFACE;
996 IUnknown_AddRef((IUnknown*)*ppv);
997 return S_OK;
1000 static ULONG WINAPI MMDevEnum_AddRef(IMMDeviceEnumerator *iface)
1002 MMDevEnumImpl *This = (MMDevEnumImpl*)iface;
1003 LONG ref = InterlockedIncrement(&This->ref);
1004 TRACE("Refcount now %i\n", ref);
1005 return ref;
1008 static ULONG WINAPI MMDevEnum_Release(IMMDeviceEnumerator *iface)
1010 MMDevEnumImpl *This = (MMDevEnumImpl*)iface;
1011 LONG ref = InterlockedDecrement(&This->ref);
1012 if (!ref)
1013 MMDevEnum_Free();
1014 TRACE("Refcount now %i\n", ref);
1015 return ref;
1018 static HRESULT WINAPI MMDevEnum_EnumAudioEndpoints(IMMDeviceEnumerator *iface, EDataFlow flow, DWORD mask, IMMDeviceCollection **devices)
1020 MMDevEnumImpl *This = (MMDevEnumImpl*)iface;
1021 TRACE("(%p)->(%u,%u,%p)\n", This, flow, mask, devices);
1022 if (!devices)
1023 return E_POINTER;
1024 *devices = NULL;
1025 if (flow >= EDataFlow_enum_count)
1026 return E_INVALIDARG;
1027 if (mask & ~DEVICE_STATEMASK_ALL)
1028 return E_INVALIDARG;
1029 return MMDevCol_Create(devices, flow, mask);
1032 static HRESULT WINAPI MMDevEnum_GetDefaultAudioEndpoint(IMMDeviceEnumerator *iface, EDataFlow flow, ERole role, IMMDevice **device)
1034 MMDevEnumImpl *This = (MMDevEnumImpl*)iface;
1035 TRACE("(%p)->(%u,%u,%p)\n", This, flow, role, device);
1037 if (!device)
1038 return E_POINTER;
1039 *device = NULL;
1041 if (flow == eRender)
1042 *device = (IMMDevice*)MMDevice_def_play;
1043 else if (flow == eCapture)
1044 *device = (IMMDevice*)MMDevice_def_rec;
1045 else
1047 WARN("Unknown flow %u\n", flow);
1048 return E_INVALIDARG;
1051 if (!*device)
1052 return E_NOTFOUND;
1053 IMMDevice_AddRef(*device);
1054 return S_OK;
1057 static HRESULT WINAPI MMDevEnum_GetDevice(IMMDeviceEnumerator *iface, const WCHAR *name, IMMDevice **device)
1059 MMDevEnumImpl *This = (MMDevEnumImpl*)iface;
1060 DWORD i=0;
1061 IMMDevice *dev = NULL;
1063 TRACE("(%p)->(%s,%p)\n", This, debugstr_w(name), device);
1064 for (i = 0; i < MMDevice_count; ++i)
1066 WCHAR *str;
1067 dev = (IMMDevice*)MMDevice_head[i];
1068 IMMDevice_GetId(dev, &str);
1070 if (str && !lstrcmpW(str, name))
1072 CoTaskMemFree(str);
1073 break;
1075 CoTaskMemFree(str);
1077 if (dev)
1079 IUnknown_AddRef(dev);
1080 *device = dev;
1081 return S_OK;
1083 WARN("Could not find device %s\n", debugstr_w(name));
1084 return E_NOTFOUND;
1087 static HRESULT WINAPI MMDevEnum_RegisterEndpointNotificationCallback(IMMDeviceEnumerator *iface, IMMNotificationClient *client)
1089 MMDevEnumImpl *This = (MMDevEnumImpl*)iface;
1090 TRACE("(%p)->(%p)\n", This, client);
1091 FIXME("stub\n");
1092 return S_OK;
1095 static HRESULT WINAPI MMDevEnum_UnregisterEndpointNotificationCallback(IMMDeviceEnumerator *iface, IMMNotificationClient *client)
1097 MMDevEnumImpl *This = (MMDevEnumImpl*)iface;
1098 TRACE("(%p)->(%p)\n", This, client);
1099 FIXME("stub\n");
1100 return S_OK;
1103 static const IMMDeviceEnumeratorVtbl MMDevEnumVtbl =
1105 MMDevEnum_QueryInterface,
1106 MMDevEnum_AddRef,
1107 MMDevEnum_Release,
1108 MMDevEnum_EnumAudioEndpoints,
1109 MMDevEnum_GetDefaultAudioEndpoint,
1110 MMDevEnum_GetDevice,
1111 MMDevEnum_RegisterEndpointNotificationCallback,
1112 MMDevEnum_UnregisterEndpointNotificationCallback
1115 static HRESULT MMDevPropStore_Create(MMDevice *parent, DWORD access, IPropertyStore **ppv)
1117 MMDevPropStore *This;
1118 if (access != STGM_READ
1119 && access != STGM_WRITE
1120 && access != STGM_READWRITE)
1122 WARN("Invalid access %08x\n", access);
1123 return E_INVALIDARG;
1125 This = HeapAlloc(GetProcessHeap(), 0, sizeof(*This));
1126 *ppv = (IPropertyStore*)This;
1127 if (!This)
1128 return E_OUTOFMEMORY;
1129 This->lpVtbl = &MMDevPropVtbl;
1130 This->ref = 1;
1131 This->parent = parent;
1132 This->access = access;
1133 return S_OK;
1136 static void MMDevPropStore_Destroy(MMDevPropStore *This)
1138 HeapFree(GetProcessHeap(), 0, This);
1141 static HRESULT WINAPI MMDevPropStore_QueryInterface(IPropertyStore *iface, REFIID riid, void **ppv)
1143 MMDevPropStore *This = (MMDevPropStore*)iface;
1145 if (!ppv)
1146 return E_POINTER;
1147 if (IsEqualIID(riid, &IID_IUnknown)
1148 || IsEqualIID(riid, &IID_IPropertyStore))
1149 *ppv = This;
1150 else
1151 *ppv = NULL;
1152 if (!*ppv)
1153 return E_NOINTERFACE;
1154 IUnknown_AddRef((IUnknown*)*ppv);
1155 return S_OK;
1158 static ULONG WINAPI MMDevPropStore_AddRef(IPropertyStore *iface)
1160 MMDevPropStore *This = (MMDevPropStore*)iface;
1161 LONG ref = InterlockedIncrement(&This->ref);
1162 TRACE("Refcount now %i\n", ref);
1163 return ref;
1166 static ULONG WINAPI MMDevPropStore_Release(IPropertyStore *iface)
1168 MMDevPropStore *This = (MMDevPropStore*)iface;
1169 LONG ref = InterlockedDecrement(&This->ref);
1170 TRACE("Refcount now %i\n", ref);
1171 if (!ref)
1172 MMDevPropStore_Destroy(This);
1173 return ref;
1176 static HRESULT WINAPI MMDevPropStore_GetCount(IPropertyStore *iface, DWORD *nprops)
1178 MMDevPropStore *This = (MMDevPropStore*)iface;
1179 WCHAR buffer[50];
1180 DWORD i = 0;
1181 HKEY propkey;
1182 HRESULT hr;
1184 TRACE("(%p)->(%p)\n", iface, nprops);
1185 if (!nprops)
1186 return E_POINTER;
1187 hr = MMDevPropStore_OpenPropKey(&This->parent->devguid, This->parent->flow, &propkey);
1188 if (FAILED(hr))
1189 return hr;
1190 *nprops = 0;
1191 do {
1192 DWORD len = sizeof(buffer)/sizeof(*buffer);
1193 if (RegEnumKeyExW(propkey, i, buffer, &len, NULL, NULL, NULL, NULL) != ERROR_SUCCESS)
1194 break;
1195 i++;
1196 } while (0);
1197 RegCloseKey(propkey);
1198 TRACE("Returning %i\n", i);
1199 *nprops = i;
1200 return S_OK;
1203 static HRESULT WINAPI MMDevPropStore_GetAt(IPropertyStore *iface, DWORD prop, PROPERTYKEY *key)
1205 MMDevPropStore *This = (MMDevPropStore*)iface;
1206 WCHAR buffer[50];
1207 DWORD len = sizeof(buffer)/sizeof(*buffer);
1208 HRESULT hr;
1209 HKEY propkey;
1211 TRACE("(%p)->(%u,%p)\n", iface, prop, key);
1212 if (!key)
1213 return E_POINTER;
1215 hr = MMDevPropStore_OpenPropKey(&This->parent->devguid, This->parent->flow, &propkey);
1216 if (FAILED(hr))
1217 return hr;
1219 if (RegEnumKeyExW(propkey, prop, buffer, &len, NULL, NULL, NULL, NULL) != ERROR_SUCCESS
1220 || len <= 40)
1222 WARN("GetAt %u failed\n", prop);
1223 return E_INVALIDARG;
1225 RegCloseKey(propkey);
1226 buffer[39] = 0;
1227 CLSIDFromString(buffer, &key->fmtid);
1228 key->pid = atoiW(&buffer[40]);
1229 return S_OK;
1232 static HRESULT WINAPI MMDevPropStore_GetValue(IPropertyStore *iface, REFPROPERTYKEY key, PROPVARIANT *pv)
1234 MMDevPropStore *This = (MMDevPropStore*)iface;
1235 TRACE("(%p)->(\"%s,%u\", %p\n", This, debugstr_guid(&key->fmtid), key ? key->pid : 0, pv);
1237 if (!key || !pv)
1238 return E_POINTER;
1239 if (This->access != STGM_READ
1240 && This->access != STGM_READWRITE)
1241 return STG_E_ACCESSDENIED;
1243 /* Special case */
1244 if (IsEqualPropertyKey(*key, PKEY_AudioEndpoint_GUID))
1246 pv->vt = VT_LPWSTR;
1247 pv->u.pwszVal = CoTaskMemAlloc(39 * sizeof(WCHAR));
1248 if (!pv->u.pwszVal)
1249 return E_OUTOFMEMORY;
1250 StringFromGUID2(&This->parent->devguid, pv->u.pwszVal, 39);
1251 return S_OK;
1254 return MMDevice_GetPropValue(&This->parent->devguid, This->parent->flow, key, pv);
1257 static HRESULT WINAPI MMDevPropStore_SetValue(IPropertyStore *iface, REFPROPERTYKEY key, REFPROPVARIANT pv)
1259 MMDevPropStore *This = (MMDevPropStore*)iface;
1261 if (!key || !pv)
1262 return E_POINTER;
1264 if (This->access != STGM_WRITE
1265 && This->access != STGM_READWRITE)
1266 return STG_E_ACCESSDENIED;
1267 return MMDevice_SetPropValue(&This->parent->devguid, This->parent->flow, key, pv);
1270 static HRESULT WINAPI MMDevPropStore_Commit(IPropertyStore *iface)
1272 FIXME("stub\n");
1273 return E_NOTIMPL;
1276 static const IPropertyStoreVtbl MMDevPropVtbl =
1278 MMDevPropStore_QueryInterface,
1279 MMDevPropStore_AddRef,
1280 MMDevPropStore_Release,
1281 MMDevPropStore_GetCount,
1282 MMDevPropStore_GetAt,
1283 MMDevPropStore_GetValue,
1284 MMDevPropStore_SetValue,
1285 MMDevPropStore_Commit
1289 /* Property bag for IBaseFilter activation */
1290 static HRESULT WINAPI PB_QueryInterface(IPropertyBag *iface, REFIID riid, void **ppv)
1292 ERR("Should not be called\n");
1293 *ppv = NULL;
1294 return E_NOINTERFACE;
1297 static ULONG WINAPI PB_AddRef(IPropertyBag *iface)
1299 ERR("Should not be called\n");
1300 return 2;
1303 static ULONG WINAPI PB_Release(IPropertyBag *iface)
1305 ERR("Should not be called\n");
1306 return 1;
1309 static HRESULT WINAPI PB_Read(IPropertyBag *iface, LPCOLESTR name, VARIANT *var, IErrorLog *log)
1311 static const WCHAR dsguid[] = { 'D','S','G','u','i','d', 0 };
1312 IPropertyBagImpl *This = (IPropertyBagImpl*)iface;
1313 TRACE("Trying to read %s, type %u\n", debugstr_w(name), var->n1.n2.vt);
1314 if (!lstrcmpW(name, dsguid))
1316 WCHAR guidstr[39];
1317 StringFromGUID2(&This->devguid, guidstr,sizeof(guidstr)/sizeof(*guidstr));
1318 var->n1.n2.vt = VT_BSTR;
1319 var->n1.n2.n3.bstrVal = SysAllocString(guidstr);
1320 return S_OK;
1322 ERR("Unknown property '%s' queried\n", debugstr_w(name));
1323 return E_FAIL;
1326 static HRESULT WINAPI PB_Write(IPropertyBag *iface, LPCOLESTR name, VARIANT *var)
1328 ERR("Should not be called\n");
1329 return E_FAIL;
1332 static const IPropertyBagVtbl PB_Vtbl =
1334 PB_QueryInterface,
1335 PB_AddRef,
1336 PB_Release,
1337 PB_Read,
1338 PB_Write