Exemplo n.º 1
0
        public void Enable()
        {
            _processing = true;

            switch (Camobject.settings.sourceindex)
            {
            case 0:
                var jpegSource = new JPEGStream(Camobject.settings.videosourcestring);
                if (Camobject.settings.frameinterval != 0)
                {
                    jpegSource.FrameInterval = Camobject.settings.frameinterval;
                }
                if (Camobject.settings.login != "")
                {
                    jpegSource.Login    = Camobject.settings.login;
                    jpegSource.Password = Camobject.settings.password;
                }
                //jpegSource.SeparateConnectionGroup = true;
                jpegSource.RequestTimeout = iSpyServer.Default.IPCameraTimeout;
                OpenVideoSource(jpegSource, false);
                break;

            case 1:
                var mjpegSource = new MJPEGStream(Camobject.settings.videosourcestring)
                {
                    Login          = Camobject.settings.login,
                    Password       = Camobject.settings.password,
                    RequestTimeout = iSpyServer.Default.IPCameraTimeout,
                    HttpUserAgent  = Camobject.settings.useragent
                };
                //mjpegSource.SeparateConnectionGroup = true;
                OpenVideoSource(mjpegSource, false);
                break;

            case 2:
                //var fileSource = new AVIFileVideoSource(Camobject.settings.videosourcestring);
                //OpenVideoSource(fileSource, true);
                break;

            case 3:
                string moniker = Camobject.settings.videosourcestring;

                var      videoSource = new VideoCaptureDevice(moniker);
                string[] wh          = Camobject.resolution.Split('x');
                var      sz          = new Size(Convert.ToInt32(wh[0]), Convert.ToInt32(wh[1]));
                var      vc          = videoSource.VideoCapabilities.Where(p => p.FrameSize == sz).ToList();
                if (vc.Count > 0)
                {
                    var vc2 = vc.FirstOrDefault(p => p.AverageFrameRate == Camobject.settings.framerate) ??
                              vc.FirstOrDefault();
                    videoSource.VideoResolution = vc2;
                }

                if (Camobject.settings.crossbarindex != -1 && videoSource.CheckIfCrossbarAvailable())
                {
                    var cbi =
                        videoSource.AvailableCrossbarVideoInputs.FirstOrDefault(
                            p => p.Index == Camobject.settings.crossbarindex);
                    if (cbi != null)
                    {
                        videoSource.CrossbarVideoInput = cbi;
                    }
                }

                OpenVideoSource(videoSource, true);
                break;

            case 4:
                Rectangle area = Rectangle.Empty;
                if (!String.IsNullOrEmpty(Camobject.settings.desktoparea))
                {
                    var i = Array.ConvertAll(Camobject.settings.desktoparea.Split(','), int.Parse);
                    area = new Rectangle(i[0], i[1], i[2], i[3]);
                }
                var desktopSource = new DesktopStream(Convert.ToInt32(Camobject.settings.videosourcestring), area)
                {
                    MousePointer = Camobject.settings.desktopmouse
                };
                if (Camobject.settings.frameinterval != 0)
                {
                    desktopSource.FrameInterval = Camobject.settings.frameinterval;
                }
                OpenVideoSource(desktopSource, false);
                break;

            case 5:
                var ks = new KinectStream(Nv("UniqueKinectId"), Convert.ToBoolean(Nv("KinectSkeleton")));
                OpenVideoSource(ks, true);
                break;
            }


            if (Camera != null)
            {
                if (!Camera.IsRunning)
                {
                    Camera.Start();
                }

                Camobject.settings.active = true;

                if (File.Exists(Camobject.settings.maskimage))
                {
                    Camera.Mask = Image.FromFile(Camobject.settings.maskimage);
                }
            }
            _frameCount             = 0;
            VideoSourceErrorState   = false;
            VideoSourceErrorMessage = "";
            Camobject.ftp.ready     = true;
            MainForm.NeedsSync      = true;

            Invalidate();
            _lastRun    = DateTime.Now.Ticks;
            _processing = false;
        }
Exemplo n.º 2
0
        public void Enable()
        {
            _processing = true;

            switch (Camobject.settings.sourceindex)
            {
                case 0:
                    var jpegSource = new JPEGStream(Camobject.settings.videosourcestring);
                    if (Camobject.settings.frameinterval != 0)
                        jpegSource.FrameInterval = Camobject.settings.frameinterval;
                    if (Camobject.settings.login != "")
                    {
                        jpegSource.Login = Camobject.settings.login;
                        jpegSource.Password = Camobject.settings.password;
                    }
                    //jpegSource.SeparateConnectionGroup = true;
                    jpegSource.RequestTimeout = iSpyServer.Default.IPCameraTimeout;
                    OpenVideoSource(jpegSource, false);
                    break;
                case 1:
                    var mjpegSource = new MJPEGStream(Camobject.settings.videosourcestring)
                                          {
                                              Login = Camobject.settings.login,
                                              Password = Camobject.settings.password,
                                              RequestTimeout = iSpyServer.Default.IPCameraTimeout,
                                              HttpUserAgent = Camobject.settings.useragent
                                          };
                    //mjpegSource.SeparateConnectionGroup = true;
                    OpenVideoSource(mjpegSource, false);
                    break;
                case 2:
                    //var fileSource = new AVIFileVideoSource(Camobject.settings.videosourcestring);
                    //OpenVideoSource(fileSource, true);
                    break;
                case 3:
                    string moniker = Camobject.settings.videosourcestring;

                    var videoSource = new VideoCaptureDevice(moniker);
                    string[] wh = Camobject.resolution.Split('x');
                    var sz = new Size(Convert.ToInt32(wh[0]), Convert.ToInt32(wh[1]));
                    var vc = videoSource.VideoCapabilities.Where(p => p.FrameSize == sz).ToList();
                    if (vc.Count>0)
                    {
                        var vc2 = vc.FirstOrDefault(p => p.AverageFrameRate == Camobject.settings.framerate) ??
                                  vc.FirstOrDefault();
                        videoSource.VideoResolution = vc2;
                    }

                    if (Camobject.settings.crossbarindex!=-1 && videoSource.CheckIfCrossbarAvailable())
                    {
                        var cbi =
                            videoSource.AvailableCrossbarVideoInputs.FirstOrDefault(
                                p => p.Index == Camobject.settings.crossbarindex);
                        if (cbi!=null)
                        {
                            videoSource.CrossbarVideoInput = cbi;
                        }
                    }

                    OpenVideoSource(videoSource, true);
                    break;
                case 4:
                    Rectangle area = Rectangle.Empty;
                    if (!String.IsNullOrEmpty(Camobject.settings.desktoparea))
                    {
                        var i = Array.ConvertAll(Camobject.settings.desktoparea.Split(','), int.Parse);
                        area = new Rectangle(i[0],i[1],i[2],i[3]);
                    }
                    var desktopSource = new DesktopStream(Convert.ToInt32(Camobject.settings.videosourcestring), area)
                                            {MousePointer = Camobject.settings.desktopmouse};
                    if (Camobject.settings.frameinterval != 0)
                        desktopSource.FrameInterval = Camobject.settings.frameinterval;
                    OpenVideoSource(desktopSource, false);
                    break;
                case 5:
                    var ks = new KinectStream(Nv("UniqueKinectId"), Convert.ToBoolean(Nv("KinectSkeleton")));
                    OpenVideoSource(ks, true);
                    break;
            }

            if (Camera != null)
            {
                if (!Camera.IsRunning)
                {
                    Camera.Start();
                }

                Camobject.settings.active = true;

                if (File.Exists(Camobject.settings.maskimage))
                {
                    Camera.Mask = Image.FromFile(Camobject.settings.maskimage);
                }
            }
            _frameCount = 0;
            VideoSourceErrorState = false;
            VideoSourceErrorMessage = "";
            Camobject.ftp.ready = true;
            MainForm.NeedsSync = true;

            Invalidate();
            _lastRun = DateTime.Now.Ticks;
            _processing = false;
        }