1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162 |
- 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<string> EnumerateVideoDevices()
- {
- var list = new List<string>();
- 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;
- }
- }
- }
|