Example #1
0
        public void Disable()
        {
            if (!IsEnabled)
                return;

            if (InvokeRequired)
            {
                Invoke(new SwitchDelegate(Disable));
                return;
            }

            IsEnabled = false;
            _processing = true;

            if (_recordingThread != null)
                RecordSwitch(false);

            if (VolumeControl != null && VolumeControl.IsEnabled)
                VolumeControl.Disable();

            if (TopLevelControl != null)
            {
                if (((MainForm) TopLevelControl).TalkCamera == this)
                    ((MainForm) TopLevelControl).TalkTo(this, false);
            }

            Application.DoEvents();

            if (SavingTimeLapse)
            {
                CloseTimeLapseWriter();
            }
            if (_camera != null)
            {
                _camera.ClearMotionZones();
                Calibrating = false;
                if (Camera.MotionDetector != null)
                {
                    try
                    {
                        Camera.MotionDetector.Reset();
                    }
                    catch (Exception ex)
                    {
                        Log.Error("Camera " + Camobject.id, ex);
                    }
                    Camera.MotionDetector = null;
                }
                if (_camera.VideoSource != null)
                {
                    _camera.VideoSource.PlayingFinished -= SourcePlayingFinished;
                    _camera.VideoSource.VideoSourceError -= SourceVideoSourceError;
                    _camera.NewFrame -= CameraNewFrame;
                    _camera.Alarm -= CameraAlarm;

                    if (_camera.VideoSource is KinectStream)
                    {
                        ((KinectStream)_camera.VideoSource).TripWire -= CameraAlarm;
                    }
                    try
                    {
                        _camera.SignalToStop();
                        if (_camera.VideoSource is VideoCaptureDevice)
                        {
                            _camera.VideoSource.WaitForStop();
                        }
                    }
                    catch (Exception ex)
                    {
                        Log.Error("Camera " + Camobject.id, ex);
                    }

                    if (_camera.VideoSource is XimeaVideoSource)
                    {
                        XimeaSource = null;
                        _camera.VideoSource = null;
                    }
                    _camera.Plugin = null;
                }
                try
                {
                    if (_camera.LastFrameUnmanaged != null)
                    {
                        _camera.LastFrameUnmanaged.Dispose();
                        _camera.LastFrameUnmanaged = null;
                    }
                }
                catch
                {
                }

                if (_camera.Mask != null)
                {
                    _camera.Mask.Dispose();
                    _camera.Mask = null;
                }
                _camera = null;
                BackgroundColor = MainForm.BackgroundColor;
            }
            Camobject.settings.active = false;
            _recordingTime = 0;
            InactiveRecord = 0;
            _timeLapseTotal = _timeLapseFrameCount = 0;
            ForcedRecording = false;

            MovementDetected = false;
            Alerted = false;
            FlashCounter = 0;
            ReconnectCount = 0;
            PTZNavigate = false;
            UpdateFloorplans(false);
            MainForm.NeedsSync = true;
            _errorTime = _reconnectTime = DateTime.MinValue;

            if (!ShuttingDown)
                Invalidate();

            if (_videoBuffer != null)
            {
                _videoBuffer.Clear();
            }

            _processing = false;
        }
Example #2
0
        private void OpenVideoSource(IVideoSource source, bool @override)
        {
            if (!@override && Camera?.VideoSource != null && Camera.VideoSource.Source == source.Source)
            {
                return;
            }
            if (Camera != null && Camera.IsRunning)
            {
                Disable();
            }
            var vlcStream = source as VlcStream;
            if (vlcStream != null)
            {
                vlcStream.FormatWidth = Camobject.settings.desktopresizewidth;
                vlcStream.FormatHeight = Camobject.settings.desktopresizeheight;
            }

            var kinectStream = source as KinectStream;
            if (kinectStream != null)
            {
                kinectStream.InitTripWires(Camobject.alerts.pluginconfig);
                kinectStream.TripWire += Alarm;
            }

            var kinectNetworkStream = source as KinectNetworkStream;
            if (kinectNetworkStream != null)
            {
                //add the camera alert handler hook to the provider
                kinectNetworkStream.AlertHandler += CameraWindow_AlertHandler;
            }

            var audiostream = source as ISupportsAudio;
            if (audiostream != null)
            {
                audiostream.HasAudioStream += VideoSourceHasAudioStream;
            }

            Camera = new Camera(source);
            Camera.NewFrame -= CameraNewFrame;
            Camera.PlayingFinished -= VideoDeviceVideoFinished;
            Camera.Alarm -= Alarm;
            Camera.ErrorHandler -= CameraWindow_ErrorHandler;


            Camera.NewFrame += CameraNewFrame;
            Camera.PlayingFinished += VideoDeviceVideoFinished;
            Camera.Alarm += Alarm;
            Camera.ErrorHandler += CameraWindow_ErrorHandler;

            Camera.PiPConfig = Camobject.settings.pip.config;

            SetVideoSourceProperties();
        }
Example #3
0
        private void OpenVideoSource(IVideoSource source, bool @override)
        {
            if (!@override && Camera != null && Camera.VideoSource != null && Camera.VideoSource.Source == source.Source)
            {
                return;
            }
            if (Camera != null && Camera.IsRunning)
            {
                Disable();
            }
            if (source is VlcStream)
            {
                ((VlcStream) source).FormatWidth = Camobject.settings.desktopresizewidth;
                ((VlcStream) source).FormatHeight = Camobject.settings.desktopresizeheight;
            }

            if (source is FFMPEGStream)
            {
                ((FFMPEGStream)source).HasAudioStream += VideoSourceHasAudioStream;
            }
            if (source is VlcStream)
            {
                ((VlcStream)source).HasAudioStream += VideoSourceHasAudioStream;
            }
            if (source is KinectStream)
            {
                ((KinectStream)source).HasAudioStream += VideoSourceHasAudioStream;
                ((KinectStream)source).InitTripWires(Camobject.alerts.pluginconfig);
                ((KinectStream)source).TripWire += CameraAlarm;
            }
            if (source is KinectNetworkStream)
            {
                ((KinectNetworkStream)source).HasAudioStream += VideoSourceHasAudioStream;
                ((KinectNetworkStream)source).AlertHandler += CameraWindow_AlertHandler;
            }
            source.PlayingFinished += SourcePlayingFinished;
            source.VideoSourceError += SourceVideoSourceError;

            Camera = new Camera(source);
        }
Example #4
0
        private void OpenVideoSource(CameraWindow cw)
        {
            cw.CameraReconnect -= CWCameraReconnect;
            cw.CameraDisabled -= CWCameraDisabled;
            cw.CameraReconnected -= CWCameraReconnected;
            cw.CameraEnabled -= CWCameraEnabled;

            cw.CameraReconnect += CWCameraReconnect;
            cw.CameraDisabled += CWCameraDisabled;
            cw.CameraReconnected += CWCameraReconnected;
            cw.CameraEnabled += CWCameraEnabled;
            cw.HasClones = true;

            bool opened = false;
            if (cw.Camera?.VideoSource != null)
            {
                var source = cw.Camera.VideoSource;
                Camera = new Camera(source);

                Camera.NewFrame -= CameraNewFrame;
                Camera.PlayingFinished -= VideoDeviceVideoFinished;
                Camera.Alarm -= Alarm;
                Camera.ErrorHandler -= CameraWindow_ErrorHandler;
                    
                Camera.NewFrame += CameraNewFrame;
                Camera.PlayingFinished += VideoDeviceVideoFinished;
                Camera.Alarm += Alarm;
                Camera.ErrorHandler += CameraWindow_ErrorHandler;
              
                Calibrating = true;
                _lastRun = Helper.Now.Ticks;
                Camera.Start();
                if (cw.VolumeControl != null && !Camobject.settings.ignoreaudio)
                {
                    if (Camobject.id == -1)
                    {
                        Camobject.id = MainForm.NextCameraId;
                        MainForm.Cameras.Add(Camobject);
                    }
                    var vl = VolumeControl;
                    if (vl == null)
                    {
                        vl = MainForm.InstanceReference.AddCameraMicrophone(Camobject.id, Camobject.name + " mic");
                        Camobject.settings.micpair = vl.Micobject.id;
                    }
                       
                    var m = vl.Micobject;
                    if (m != null)
                    {
                        m.settings.samples = cw.VolumeControl.Micobject.settings.samples;
                        m.settings.channels = cw.VolumeControl.Micobject.settings.channels;
                        m.settings.typeindex = 4;
                        m.settings.buffer = Camobject.recorder.bufferseconds;
                        m.settings.bits = 16;
                        //m.alerts.active = false;
                        //m.detector.recordonalert = false;
                        //m.detector.recordondetect = false;
                    }

                    vl.Disable();
                    vl.Enable();

                    cw.VolumeControl.AudioDeviceEnabled += VLAudioDeviceEnabled;
                        
                }
                opened = true;
            }
            if (!opened)
            {
                SetErrorState("Source camera offline");
                VideoSourceErrorState = true;
                _requestRefresh = true;
            }
        }