public static void GetDevices(ref Dictionary <string, IVideoSource> deviceCache) { var videoDevices = new FilterInfoCollection(FilterCategory.VideoInputDevice); if (videoDevices != null && videoDevices.Count > 0) { foreach (FilterInfo device in videoDevices) { lock (deviceCache) { if (deviceCache.ContainsKey(device.Name)) { continue; } //else .. all other code try { var video = new VideoCaptureDeviceLite(device.MonikerString); // System.Diagnostics.Debug.WriteLine(device.MonikerString.ToString()); //start video to get frame size from first frame video.Start(); System.Threading.Thread.Sleep(100); video.WaitForStop(); var dev = new AforgeVideoSourceLite(device.Name, video) { VideoSize = video.FrameSize ?? System.Drawing.Size.Empty }; deviceCache.Add(device.Name, dev); } catch (Exception e) { System.Windows.Forms.MessageBox.Show(string.Join(Environment.NewLine, e.Message, "", e.Source, "", e.StackTrace)); } } } } }
public AforgeVideoSourceLite(string name_p, VideoCaptureDeviceLite dev) { this.name = name_p; this.videoDevice = dev; }