コード例 #1
0
ファイル: CameraWindow.cs プロジェクト: WesleyYep/ispyconnect
        private void OpenVideoSource(IVideoSource source, bool @override)
        {
            if (!@override && Camera != null && Camera.VideoSource != null && Camera.VideoSource.Source == source.Source)
            {
                return;
            }
            if (Camera != null)
            {
                Disable();
            }

            Camera = new Camera(source);
            source.PlayingFinished += SourcePlayingFinished;
            source.VideoSourceError += SourceVideoSourceError;
        }
コード例 #2
0
ファイル: CameraWindow.cs プロジェクト: WesleyYep/ispyconnect
        public void Disable()
        {
            _processing = true;
            Application.DoEvents();

            if (_camera != null)
            {
                _camera.NewFrame -= CameraNewFrame;
                _camera.VideoSource.PlayingFinished -= SourcePlayingFinished;
                _camera.VideoSource.VideoSourceError -= SourceVideoSourceError;

                if (_camera.IsRunning)
                {
                    try
                    {
                        _camera.SignalToStop();
                        if (_camera.VideoSource is VideoCaptureDevice)
                        {
                            //need to make sure removal of this videosource is successful
                            int counter = 0;
                            while (_camera.IsRunning && counter < 2)
                            {
                                Thread.Sleep(500);
                                counter++;
                            }
                            if (_camera.IsRunning)
                                _camera.Stop();
                        }
                    }
                    catch (Exception ex)
                    {
                        MainForm.LogExceptionToFile(ex, "Camera " + Camobject.id);
                    }
                    _camera.VideoSource = null;
                }
                try
                {
                    _camera.LastFrameUnmanaged.Dispose();
                    _camera.LastFrameUnmanaged = null;
                }
                catch
                {
                }
                _camera = null;
                BackColor = iSpyServer.Default.BackColor;
            }
            Camobject.settings.active = false;
            _frameCount = 0;

            foreach (
                objectsFloorplan ofp in
                    MainForm.FloorPlans.Where(
                        p => [email protected](q => q.type == "camera" && q.id == Camobject.id).Count() > 0).
                        ToList())
            {
                ofp.needsupdate = true;
            }
            MainForm.NeedsSync = true;
            if (!ShuttingDown)
                Invalidate();
            GC.Collect();
            _processing = false;
        }