00001
00002 using System;
00003 using System.Collections.Generic;
00004 using System.Text;
00005 using System.Runtime.InteropServices;
00006 using DirectShowLib;
00007
00008 namespace Foodolini.Activities.FoodRegistration.Devices
00009 {
00010
00011 public class WindowsCaptureDeviceMonitor : ICaptureDeviceMonitor
00012 {
00013 private WindowsCaptureDeviceMonitor ()
00014 {
00015
00016 }
00017
00018 public bool SupportsAutoRefresh {
00019 get { return false; }
00020 }
00021
00022 #region Singleton implementation
00023
00027 private static WindowsCaptureDeviceMonitor instance = null;
00028
00029 public static WindowsCaptureDeviceMonitor Instance {
00030 get {
00031 if (instance == null)
00032 instance = new WindowsCaptureDeviceMonitor ();
00033 return instance;
00034 }
00035 }
00036
00037 #endregion
00038
00039 #region ICaptureDeviceMonitor implementation
00040
00041 public event EventHandler<DeviceEventArgs> DeviceAdded;
00042
00043 public event EventHandler<DeviceEventArgs> DeviceRemoved;
00044
00045 public System.Collections.Generic.ICollection<IDeviceInfo> Devices {
00046 get {
00047 var retval = new List<IDeviceInfo> ();
00048
00049 int numDevices=0;
00050 foreach (DsDevice device in DsDevice.GetDevicesOfCat (FilterCategory.VideoInputDevice)) {
00051
00052 numDevices++;
00053 }
00054
00055 if(numDevices > 0) {
00056 StringBuilder name = new StringBuilder (256);
00057 StringBuilder desc = new StringBuilder (256);
00058 for (int i = 0; i < 9; i++) {
00059 if (capGetDriverDescription (i, name, (uint)name.Capacity, desc, (uint)desc.Capacity)) {
00060 retval.Add (new DeviceEventArgs (name.ToString () + " (" + desc.ToString () + ")", name.ToString ()));
00061 }
00062 }
00063 }
00064
00065 return retval;
00066 }
00067 }
00068
00090 [DllImport("Avicap32.dll")]
00091 private static extern bool capGetDriverDescription (int driverIndex, StringBuilder name, uint nameLength, StringBuilder description, uint descLength);
00092
00093 #endregion
00094
00095 #region IDisposable implementation
00096 public void Dispose ()
00097 {
00098
00099 }
00100 #endregion
00101 }
00102
00106 public static class CaptureDeviceMonitor
00107 {
00108 public static ICaptureDeviceMonitor Instance {
00109 get { return WindowsCaptureDeviceMonitor.Instance; }
00110 }
00111 }
00112 }