public MyClient(IClient client, IStreamService streamService, Camera currentCamera)
 {
     this.client = client;
     this.streamService = streamService;
     Connector = new MediaConnector();
     _forwarder = new VideoForwarder();
     _camera = currentCamera;
 }
        public void Start(Camera model)
        {
            if(Model != null)
                Connector.Disconnect(Model.VideoSender, bitmapSourceProvider);

            bitmapSourceProvider = new BitmapSourceProvider();

            Viewer.SetImageProvider(bitmapSourceProvider);

            Connector = new MediaConnector();

            Model = model;
            Connector.Connect(model.VideoSender, bitmapSourceProvider);

            Viewer.Start();
        }
 void OnCameraAdded(Camera camera)
 {
     var handler = CameraAdded;
     if (handler != null)
         handler(this, new CameraAddedEventArgs(camera));
 }
        bool CameraListContains(ObservableList<Camera> list, Camera cam)
        {
            foreach (var camera in list)
            {
                if (camera.CameraInfo.Equals(cam.CameraInfo) || String.Format("{0}/", camera.CameraInfo).Equals(cam.CameraInfo))
                    return true;
            }

            return false;
        }
        void StartViewer(Camera camera)
        {
            if (videoViewer == null)
                return;
            if (camera == null)
            {
                StopViewer();
                return;
            }

            videoViewer.SetImageProvider(camera.BitmapSourceProvider);
            videoViewer.Start();
        }
 void WireDownCameraEvents(Camera camera)
 {
     camera.CameraStateChanged -= Model_CameraStateChanged;
     camera.GetFilePath -= Model_GetFilePath;
     camera.AlarmEvent -= Model_AlarmEvent;
 }
 void WireUpCameraEvents(Camera camera)
 {
     camera.CameraStateChanged += Model_CameraStateChanged;
     camera.GetFilePath += Model_GetFilePath;
     camera.AlarmEvent += Model_AlarmEvent;
 }
        void AddCamera(Camera camera)
        {
            ConnectModel.CameraList.Add(camera);

            ControlSizeToTextboxes();
        }
        void ConnectButton_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                if (ConnectModel == null || _connecting)
                    return;

                if (CurrentModel == null)
                    CurrentModel = GetCurrentModel((CameraDeviceInfo)CameraDevicesCombo.SelectedItem);

                if (CurrentModel == null ||
                    (!String.IsNullOrEmpty(CurrentModel.CameraState) && !CurrentModel.CameraState.Equals("Disconnected")))
                    return;

                if (CurrentModel is IpCameraEngine)
                {
                    if (!IsSavedCamera(CurrentModel))
                        CurrentModel = new IpCameraEngine(CameraAddress, UserName, Password);
                    //else
                    //    CurrentModel = GetSavedCamera(CurrentModel).Camera;
                }

                AddCamera(CurrentModel);
                WireUpCameraEvents(CurrentModel);

                if (CurrentModel.CameraError != null && CurrentModel.CameraError.ToUpper().Contains("LOST"))
                    CurrentModel.CameraError = String.Empty;

                CurrentModel.Connect();
                _connecting = true;

                StartViewer(CurrentModel);

                Server.Model = CurrentModel;

                if (CurrentModel.CameraStreams == null)
                    ModelList.Add(CurrentModel);
            }
            catch
            {
            }
        }
        void ConnectModel_DeviceAdded(object sender, DeviceAddedEventArgs e)
        {
            // add webcam
            if (e.Info.WebCameraInfo != null)
            {
                var createdCamera = new WebCameraEngine(e.Info.WebCameraInfo);
                AddCamera(createdCamera);
                //CurrentModel = createdCamera;
            }
            else if (e.Info.IpCameraInfo != null)
            {
                // add IP camera
                if (e.Info.IpCameraInfo.Uri == null)
                    return;

                var ipCamera = new IpCameraEngine(e.Info.IpCameraInfo.Uri.ToString(), UserName, Password);

                if (CurrentModel != null && CurrentModel.CameraInfo.Equals(ipCamera.CameraInfo))
                    CurrentModel = null;

                AddCamera(ipCamera);
                // CurrentModel = ipCamera;
            }
        }
        SavedCamera GetSavedCamera(Camera camera, int selected)
        {
            if (camera == null)
                return null;

            var index = GetListIndex(selected);

            if (index == 0)
                return null;

            foreach (var savedCamera in ConnectModel.SavedCameras)
            {
                if (!ContainedSavedCamera(savedCamera, camera.CameraInfo))
                    continue;

                index--;

                if (index == 0)
                    return savedCamera;
            }

            return null;
        }
        bool IsSavedCamera(Camera camera)
        {
            if (camera == null || ConnectModel.SavedCameras.Count <= 0)
                return false;

            var saved = false;

            foreach (var savedCamera in ConnectModel.SavedCameras)
            {
                saved = ContainedSavedCamera(savedCamera, camera.CameraInfo);

                if (saved)
                    return saved;
            }

            return saved;
        }
        public bool RemoveCamera(Camera camera)
        {
            for (var i = CameraList.Count - 1; i >= 0; i--)
            {
                if (CameraList[i].CameraInfo != camera.CameraInfo)
                    continue;

                return CameraList.Remove(CameraList.FirstOrDefault(c=> c.CameraInfo.Equals(camera.CameraInfo)));
            }

            return false;
        }
        SliderModel GetSliderValues(Camera model)
        {
            if (model == null || model.CameraImage == null)
                return null;

            switch (SettingName)
            {
                case Type.Brightness:
                    if (Model == null || Model.CameraImage == null) return new SliderModel();
                    if (model.CameraImage.IsBrightnessSupported)
                    {
                        return new SliderModel
                        {
                            Min = model.CameraImage.BrightnessInterval.Min,
                            Max = model.CameraImage.BrightnessInterval.Max,
                            Value = model.CameraImage.Brightness,
                        };
                    }
                    break;

                case Type.Contrast:
                    if (Model == null || Model.CameraImage == null) return new SliderModel();
                    if (model.CameraImage.IsContrastSupported)
                    {
                        return new SliderModel
                        {
                            Min = model.CameraImage.ContrastInterval.Min,
                            Max = model.CameraImage.ContrastInterval.Max,
                            Value = model.CameraImage.Contrast
                        };
                    }
                    break;

                case Type.Saturation:
                    if (Model == null || Model.CameraImage == null) return new SliderModel();
                    if (model.CameraImage.IsColorSaturationSupported)
                    {
                        return new SliderModel
                        {
                            Min = model.CameraImage.ColorSaturationInterval.Min,
                            Max = model.CameraImage.ColorSaturationInterval.Max,
                            Value = model.CameraImage.ColorSaturation
                        };
                    }
                    break;

                case Type.Sharpness:
                    if (Model == null || Model.CameraImage == null) return new SliderModel();
                    if (Model.CameraImage.IsSharpnessSupported)
                    {
                        return new SliderModel
                        {
                            Min = model.CameraImage.SharpnessInterval.Min,
                            Max = model.CameraImage.SharpnessInterval.Max,
                            Value = model.CameraImage.Sharpness
                        };
                    }
                    break;

                case Type.BackLight:
                    if (Model == null || Model.CameraImage == null) return new SliderModel();
                    if (Model.CameraImage.IsBackLightCompensationSupported)
                    {
                        return new SliderModel
                        {
                            Min = model.CameraImage.BackLightInterval.Min,
                            Max = model.CameraImage.BackLightInterval.Max,
                            Value = model.CameraImage.BackLightCompensation,
                        };
                    }
                    break;

                case Type.WhiteBalanceCb:
                    if (Model == null || Model.CameraImage == null) return new SliderModel();
                    if (Model.CameraImage.IsWhiteBalanceSupported)
                    {
                        return new SliderModel
                        {
                            Min = model.CameraImage.WhiteBalanceYbGainInterval.Min,
                            Max = model.CameraImage.WhiteBalanceYbGainInterval.Max,
                            Value = model.CameraImage.WhiteBalance.CbGain
                        };
                    }
                    break;

                case Type.WhiteBalanceCr:
                    if (Model == null || Model.CameraImage == null) return new SliderModel();
                    if (Model.CameraImage.IsWhiteBalanceSupported)
                    {
                        return new SliderModel
                        {
                            Min = model.CameraImage.WhiteBalanceYrGainInterval.Min,
                            Max = model.CameraImage.WhiteBalanceYrGainInterval.Max,
                            Value = model.CameraImage.WhiteBalance.CrGain
                        };
                    }
                    break;

                case Type.FrameRate:
                    if (Model == null || Model.CurrentStream == null || Model.CurrentStream.VideoEncoding == null) return new SliderModel();
                    return new SliderModel
                    {
                        Min = 0,
                        Max = 100,
                        Value = Model.CurrentStream.VideoEncoding.FrameRate
                    };
            }
            return new SliderModel();
        }
 public MyMediaGateway(MediaGatewayConfig config, Camera currentCamera)
     : base(config)
 {
     _currentCam = currentCamera;
     clients = new Dictionary<IClient, MyClient>();
 }