CamTimer.WebcamManager.Enumerate C# (CSharp) Method

Enumerate() static private method

static private Enumerate ( ) : CamTimer.Webcam[]
return CamTimer.Webcam[]
        internal static Webcam[] Enumerate()
        {
            List<Webcam> result = new List<Webcam>();

            // directshow enumeration
            try {
                DsDevice[] dsDevices = DsDevice.GetDevicesOfCat(FilterCategory.VideoInputDevice);
                for (int x = 0; x < dsDevices.Length; x++) {
                    result.Add(new WebcamDirectShow(x, dsDevices[x].Name));
                }
            } catch (Exception) { }

            // wia enumeration
            try {
                WIA.DeviceManager deviceManager = new WIA.DeviceManagerClass();
                foreach (WIA.DeviceInfo deviceInfo in deviceManager.DeviceInfos) {
                    if ((deviceInfo.Type == WIA.WiaDeviceType.CameraDeviceType) || (deviceInfo.Type == WIA.WiaDeviceType.VideoDeviceType)) {
                        result.Add(new WebcamWIA(deviceInfo));
                    }
                }
            } catch (Exception) { }

            // avicap32 enumeration
            try {
                for (short x = 0; x < 10; x++) {
                    string name = new string(' ', 255);
                    string version = new string(' ', 255);
                    if (NativeMethods.capGetDriverDescriptionA(x, ref name, name.Length, ref version, version.Length)) {
                        if (name.IndexOf('\x00') > -1) name = name.Substring(0, name.IndexOf('\x00'));
                        if (version.IndexOf('\x00') > -1) version = version.Substring(0, version.IndexOf('\x00'));
                        result.Add(new WebcamAVICap(x, name.Trim()));
                    }
                }
            } catch (Exception) { }

            return result.ToArray();
        }

Usage Example

Example #1
0
        private void EnumerateCams()
        {
            int currentTick = System.Environment.TickCount;

            if ((currentTick - m_lastEnumTick > 5000) || (m_lastEnumTick == 0))
            {
                m_lastEnumTick = currentTick;
                confWebcam.Items.Clear();
                confWebcam.Items.AddRange(WebcamManager.Enumerate());
                confWebcam.Items.Add(Language.FormatString(Language.LanguageString.MainForm_Configuration_RefreshWebcamList));
                confWebcam.SelectedIndex = 0;
            }
        }