DeepFaceLive/xlib/api/win32/dshow/helper.py
2022-05-15 17:45:49 +04:00

40 lines
No EOL
1.5 KiB
Python

from typing import List
from .. import ole32, uuids, strmif, wintypes, objidl, oaidl
def get_video_input_devices_names() -> List[str]:
"""
returns a list of available names of VideoInputDevice's
ole32 should be initialized before use
"""
# based on https://docs.microsoft.com/ru-ru/windows/win32/directshow/selecting-a-capture-device
names = []
sys_dev_enum = strmif.ICreateDevEnum()
if ole32.CoCreateInstance(uuids.CLSID_SystemDeviceEnum, None, ole32.CLSCTX.CLSCTX_INPROC_SERVER, strmif.ICreateDevEnum.IID, sys_dev_enum) == wintypes.ERROR.SUCCESS:
pEnumCat = objidl.IEnumMoniker()
if sys_dev_enum.CreateClassEnumerator(uuids.CLSID_VideoInputDeviceCategory, pEnumCat, 0) == wintypes.ERROR.SUCCESS:
moniker = objidl.IMoniker()
while pEnumCat.Next(1, moniker, None) == wintypes.ERROR.SUCCESS:
prop_bag = oaidl.IPropertyBag()
if moniker.BindToStorage(None, None, oaidl.IPropertyBag.IID, prop_bag) == wintypes.ERROR.SUCCESS:
var = wintypes.VARIANT()
hr = prop_bag.Read(wintypes.LPCOLESTR('Description'), var, None )
if hr != wintypes.ERROR.SUCCESS:
hr = prop_bag.Read(wintypes.LPCOLESTR('FriendlyName'), var, None )
names.append(var.value.bstrVal.value if hr == wintypes.ERROR.SUCCESS else 'unnamed')
prop_bag.Release()
moniker.Release()
pEnumCat.Release()
sys_dev_enum.Release()
return names