Example #1
0
        private void RefreshVideoCaptureDevices(IList <MediaDevice> videoCaptureDevices)
        {
            RunOnUiThread(() => {
                Collection <MediaDevice> videoCaptureDevicesToRemove = new Collection <MediaDevice>();
                foreach (MediaDevice videoCaptureDevice in Cameras)
                {
                    if (videoCaptureDevices.FirstOrDefault(x => x.Id == videoCaptureDevice.Id) == null)
                    {
                        videoCaptureDevicesToRemove.Add(videoCaptureDevice);
                    }
                }
                foreach (MediaDevice removedVideoCaptureDevices in videoCaptureDevicesToRemove)
                {
                    if (SelectedCamera != null && SelectedCamera.Id == removedVideoCaptureDevices.Id)
                    {
                        SelectedCamera = null;
                    }
                    Cameras.Remove(removedVideoCaptureDevices);
                }
                foreach (MediaDevice videoCaptureDevice in videoCaptureDevices)
                {
                    if (Cameras.FirstOrDefault(x => x.Id == videoCaptureDevice.Id) == null)
                    {
                        Cameras.Add(videoCaptureDevice);
                    }
                }

                if ((SelectedCamera == null) && Cameras.Count > 0)
                {
                    Debug.WriteLine("SelectedCamera RefreshVideoCaptureDevices() Update");
                    SelectedCamera = Cameras.FirstOrDefault();
                }
            });
        }
        /// <summary>
        ///     Refresh video capture devices list.
        /// </summary>
        private async Task RefreshVideoCaptureDevices()
        {
            var videoCaptureDevices         = (await _mediaSettings.GetVideoCaptureDevicesAsync()).Devices;
            var removedDevicesInfo          = "";
            var videoCaptureDevicesToRemove = new Collection <MediaDevice>();

            Cameras = Cameras ?? new ObservableCollection <MediaDevice>();
            foreach (
                var videoCaptureDevice in
                Cameras.Where(
                    videoCaptureDevice =>
                    videoCaptureDevices.FirstOrDefault(x => x.Id == videoCaptureDevice.Id) == null))
            {
                videoCaptureDevicesToRemove.Add(videoCaptureDevice);
                if (EtwStatsEnabled)
                {
                    removedDevicesInfo += "id = " + videoCaptureDevice.Id + " name = " +
                                          videoCaptureDevice.Name + "\n";
                }
            }
            foreach (var removedVideoCaptureDevices in videoCaptureDevicesToRemove)
            {
                if (SelectedCamera != null && SelectedCamera.Id == removedVideoCaptureDevices.Id)
                {
                    SelectedCamera = null;
                }
                Cameras.Remove(removedVideoCaptureDevices);
            }
            if (removedDevicesInfo != "")
            {
                ETWEventLogger.Instance.LogEvent("Video Device(s) Removed", removedDevicesInfo,
                                                 DateTimeOffset.Now.ToUnixTimeMilliseconds().ToString());
            }
            var addedDevicesInfo = "";

            foreach (var videoCaptureDevice in videoCaptureDevices)
            {
                if (Cameras.FirstOrDefault(x => x.Id == videoCaptureDevice.Id) == null)
                {
                    Cameras.Add(videoCaptureDevice);
                    if (EtwStatsEnabled)
                    {
                        addedDevicesInfo += "id = " + videoCaptureDevice.Id + " name = " +
                                            videoCaptureDevice.Name + "\n";
                    }
                }
            }
            if (addedDevicesInfo != "")
            {
                ETWEventLogger.Instance.LogEvent("Video Device(s) Added", addedDevicesInfo,
                                                 DateTimeOffset.Now.ToUnixTimeMilliseconds().ToString());
            }
            if (SelectedCamera == null)
            {
                SelectedCamera = Cameras.FirstOrDefault();
            }
        }
Example #3
0
        private void RefreshCamera()
        {
            CloseSession();
            Cameras.Clear();
            foreach (var camera in CameraHandler.GetCameraList())
            {
                Cameras.Add(camera);
            }

            SelectedCamera = Cameras.FirstOrDefault();
        }
Example #4
0
        public ICamera GetCamera(string abbreviation)
        {
            if (string.IsNullOrEmpty(abbreviation))
            {
                return(new NullCamera());
            }

            var camera = Cameras?.FirstOrDefault(c => string.Equals(c.Abbreviation, abbreviation, StringComparison.InvariantCultureIgnoreCase));

            return(camera ?? new NullCamera());
        }
Example #5
0
        public void SelectCamera(string key)
        {
            var camera = Cameras.FirstOrDefault(c => c.Key.ToLower().IndexOf(key.ToLower()) > -1);

            if (camera != null)
            {
                Debug.Console(2, this, "Selected Camera with key: '{0}'", camera.Key);
                SelectedCamera = camera;
            }
            else
            {
                Debug.Console(2, this, "Unable to select camera with key: '{0}'", key);
            }
        }
Example #6
0
        public DeviceInformation GetCamera(string id)
        {
            if (!Cameras.Any())
            {
                return(null);
            }
            var camera = Cameras.FirstOrDefault(x => x.Id.ToLower() == id?.ToLower());

            if (camera == null)
            {
                camera = Cameras.FirstOrDefault(x => x.EnclosureLocation?.Panel == Panel.Front);
            }
            return(camera ?? Cameras.First());
        }
Example #7
0
        public async Task <DeviceInformation> GetCameraAsync(string id = null)
        {
            if (Cameras == null)
            {
                Cameras = await GetCamerasAsync(null);
            }
            if (!Cameras.Any())
            {
                return(null);
            }
            var camera = Cameras.FirstOrDefault(x => x.Id.ToLower() == id?.ToLower());

            if (camera == null)
            {
                camera = Cameras.FirstOrDefault(x => x.EnclosureLocation?.Panel == Panel.Front);
            }
            return(camera ?? Cameras.First());
        }
Example #8
0
        internal static Camera TryGet(IntPtr handle)
        {
            if (handle == IntPtr.Zero)
            {
                return(null);
            }

            var camera = Cameras.FirstOrDefault(x => x.Handle == handle);

            if (camera != null)
            {
                return(camera);
            }

            camera        = new Camera();
            camera.Handle = handle;

            Cameras.Add(camera);

            return(camera);
        }
Example #9
0
 public Task <Camera> GetCameraByIDAsync(string cameraID) =>
 Task.FromResult(Cameras.FirstOrDefault(c => c.ID == cameraID));