amerkoleci / Vortice.Windows

.NET bindings for Direct3D12, Direct3D11, WIC, Direct2D1, XInput, XAudio, X3DAudio, DXC, Direct3D9 and DirectInput.
MIT License
1.01k stars 73 forks source link

Enumerating Capture Devices (MediaFoundation) #292

Closed SuRGeoNix closed 2 years ago

SuRGeoNix commented 2 years ago

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

amerkoleci commented 2 years ago

Please open a discussion instead of issue:

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

SuRGeoNix commented 2 years ago

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++;
}
amerkoleci commented 2 years ago

https://github.com/amerkoleci/Vortice.Windows/commit/b8ec1490d366bfb66c17cac680c1f4b1c115d13b 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

SuRGeoNix commented 2 years ago

Nice one. Much cleaner now!