amerkoleci/Vortice.Windows

Enumerating Capture Devices (MediaFoundation)

SuRGeoNix opened this issue · 4 comments

Just wondering if you have this in your plans. I think it would fits for Vortice purpose.

I mainly interesting for this to enumerate audio/video capture devices.

Update: It seems I can use IMMDeviceEnumerator for at least audio capture devices

Please open a discussion instead of issue:

https://github.com/amerkoleci/Vortice.Windows/discussions

I found out that is possible with the newest Media Foundation API with MFEnumDeviceSources. So, probably not really required to add DirectShow. Sample:

var attrs = MediaFactory.MFCreateAttributes(1);
attrs.Set(CaptureDeviceAttributeKeys.SourceType, CaptureDeviceAttributeKeys.SourceTypeVidcap);
var res = MediaFactory.MFEnumDeviceSources(attrs, out IntPtr vidCapsPtr, out int capsCount);

IntPtr* ptrs = (IntPtr*)vidCapsPtr;
for (int i=0; i<capsCount; i++)
{
	var capDevice = new IMFActivate(*ptrs);
	System.Diagnostics.Debug.WriteLine(capDevice.Get(CaptureDeviceAttributeKeys.FriendlyName));
	capDevice.Release();
	ptrs++;
}

b8ec149 added improvements in this scenario. I've added also example that enumerates Audio/Video capture devices:

https://github.com/amerkoleci/Vortice.Windows/blob/main/src/samples/MediaFoundation/EnumerateDevices/Program.cs#L29

Nice one. Much cleaner now!