Exemple #1
0
        /// <summary>
        ///  刷新设备状态
        /// </summary>
        public void RefreshDevice(CameraDeviceManager cameraDeviceManager)
        {
            //刷新设备的连接状态
            bool isChanged = cameraDeviceManager.DetectState();

            if (isChanged)
            {
                //用界面线程来对_currentCameraDevice进行设置,防止设置对_currentCameraDevice设置时的多线程问题
                AppThread.Instance.Invoke(() =>
                {
                    if (cameraDeviceManager.DefaultCameraDevice != null)
                    {
                        _currentCameraDevice = cameraDeviceManager.DefaultCameraDevice;
                        Start();
                    }
                    else
                    {
                        Stop();
                        _currentCameraDevice = null;
                    }
                });
            }
        }
Exemple #2
0
        private bool InnerDetectState()
        {
            CameraDeviceList.Clear();
            //获取所有设备
            FilterInfoCollection _filterInfoCollection = new FilterInfoCollection(FilterCategory.VideoInputDevice);

            if (_filterInfoCollection.Count > 0)
            {
                foreach (FilterInfo filterInfo in _filterInfoCollection)
                {
                    CameraDevice cameraDevice = new CameraDevice(filterInfo.MonikerString);
                    CameraDeviceList.Add(cameraDevice);
                }
            }
            //设置DefaultCameraDevice并返回状态是否变化
            if (DefaultCameraDevice == null)
            {
                if (CameraDeviceList.Count > 0)
                {
                    DefaultCameraDevice = CameraDeviceList[0];
                    return(true);
                }
                return(false);
            }
            else
            {
                foreach (CameraDevice device in CameraDeviceList)
                {
                    if (device.Name == DefaultCameraDevice.Name)
                    {
                        return(false);
                    }
                }
                DefaultCameraDevice = null;
                return(true);
            }
        }