using System; using System.Runtime.InteropServices; namespace RtcUtil { public enum MediaDeviceKind { AUDIOINPUT, AUDIOOUTPUT, VIDEOINPUT }; public class MediaDeviceInfo { public string DeviceId { get; set; } public string Label { get; set; } public MediaDeviceKind Kind { get; set; } public string GroupId { get; set; } } [StructLayout(LayoutKind.Sequential)] public struct NativeMediaDeviceInfo { public UInt32 DeviceNumber; [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 256)] public string DeviceNameUTF8; [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 256)] public string DeviceUniqueIdUTF8; [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 256)] public string ProductUniqueIdUTF8; } public class MediaDevices { [DllImport("x64\\RtcUtil.Native.x64.dll", EntryPoint = "CreateVideoDeviceInfo", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Ansi)] internal static extern int CreateVideoDeviceInfo(out IntPtr deviceInfo); [DllImport("x64\\RtcUtil.Native.x64.dll", EntryPoint = "GetVidoeDeviceInfo", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Ansi)] internal static extern int GetVidoeDeviceInfo(IntPtr hDeviceInfo, UInt32 deviceNumber, out IntPtr meadiaDeviceInfo); public static IList EnumerateVideoDevices() { var list = new List(); IntPtr ptrInfo; var num = CreateVideoDeviceInfo(out ptrInfo); if (ptrInfo != IntPtr.Zero) { for(UInt32 i =0;i< num; i++) { IntPtr ptrMdDeviceInfo; var retValue = GetVidoeDeviceInfo(ptrInfo, i, out ptrMdDeviceInfo); if (retValue != -1) { var info = (NativeMediaDeviceInfo)Marshal.PtrToStructure(ptrMdDeviceInfo, typeof(NativeMediaDeviceInfo)); list.Add(info.DeviceNameUTF8);//TODO need other properties , such as ID ? } } } return list; } } }