Beispiel #1
0
        public string GetHtml(string camId, IPCameraBase cam)
        {
            PTZProfile profile = GetProfile();

            if (profile == null)
            {
                return("PTZ Profile Not Found");
            }
            if (typeof(PTZSpecV1) == profile.spec.GetType())
            {
                PTZSpecV1 spec = (PTZSpecV1)profile.spec;

                HtmlOptions options = new HtmlOptions();
                options.showPtzArrows    = true;
                options.showPtzDiagonals = spec.EnableDiagonals;

                options.panDelay  = (int)(spec.PanRunTimeMs * 0.9);
                options.tiltDelay = (int)(spec.TiltRunTimeMs * 0.9);

                options.showZoomButtons = spec.EnableZoom;

                options.showZoomInLong   = !string.IsNullOrWhiteSpace(spec.zoomInLong);
                options.showZoomInMedium = !string.IsNullOrWhiteSpace(spec.zoomInMedium);
                options.showZoomInShort  = !string.IsNullOrWhiteSpace(spec.zoomInShort);

                options.showZoomOutLong   = !string.IsNullOrWhiteSpace(spec.zoomOutLong);
                options.showZoomOutMedium = !string.IsNullOrWhiteSpace(spec.zoomOutMedium);
                options.showZoomOutShort  = !string.IsNullOrWhiteSpace(spec.zoomOutShort);

                options.zoomShortDelay  = spec.ZoomRunTimeShortMs;
                options.zoomMediumDelay = spec.ZoomRunTimeMediumMs;
                options.zoomLongDelay   = spec.ZoomRunTimeLongMs;

                options.showPresets = spec.EnablePresets;
                int i = 0;
                options.gettablePresets[i++] = !string.IsNullOrWhiteSpace(spec.load_preset_1);
                options.gettablePresets[i++] = !string.IsNullOrWhiteSpace(spec.load_preset_2);
                options.gettablePresets[i++] = !string.IsNullOrWhiteSpace(spec.load_preset_3);
                options.gettablePresets[i++] = !string.IsNullOrWhiteSpace(spec.load_preset_4);
                options.gettablePresets[i++] = !string.IsNullOrWhiteSpace(spec.load_preset_5);
                options.gettablePresets[i++] = !string.IsNullOrWhiteSpace(spec.load_preset_6);
                options.gettablePresets[i++] = !string.IsNullOrWhiteSpace(spec.load_preset_7);
                options.gettablePresets[i++] = !string.IsNullOrWhiteSpace(spec.load_preset_8);
                i = 0;
                options.settablePresets[i++] = !string.IsNullOrWhiteSpace(spec.save_preset_1);
                options.settablePresets[i++] = !string.IsNullOrWhiteSpace(spec.save_preset_2);
                options.settablePresets[i++] = !string.IsNullOrWhiteSpace(spec.save_preset_3);
                options.settablePresets[i++] = !string.IsNullOrWhiteSpace(spec.save_preset_4);
                options.settablePresets[i++] = !string.IsNullOrWhiteSpace(spec.save_preset_5);
                options.settablePresets[i++] = !string.IsNullOrWhiteSpace(spec.save_preset_6);
                options.settablePresets[i++] = !string.IsNullOrWhiteSpace(spec.save_preset_7);
                options.settablePresets[i++] = !string.IsNullOrWhiteSpace(spec.save_preset_8);

                options.showZoomLevels = false;

                return(PTZHtml.GetHtml(camId, cam, options));
            }
            return("Unsupported PTZ Profile");
        }
Beispiel #2
0
        public bool SupportsZoom()
        {
            PTZProfile profile = GetProfile();

            if (profile == null)
            {
                return(false);
            }
            return(((PTZSpecV1)profile.spec).EnableZoom);
        }
Beispiel #3
0
        private PTZProfile GetProfile()
        {
            if (camSpec.ptzType != PtzType.CustomPTZProfile)
            {
                return(null);
            }
            PTZProfile profile = new PTZProfile();

            profile.Load(Globals.PTZProfilesDirectoryBase + camSpec.ptz_customPTZProfile + ".xml");
            if (profile.spec == null)
            {
                profile = null;
            }
            return(profile);
        }
Beispiel #4
0
        protected override string GetPageHtml(HttpProcessor p, Session s)
        {
            sb.Clear();
            string itemtype = p.GetParam("itemtype");
            string itemid   = p.GetParam("itemid").ToLower();

            sb.Append("<div id=\"itemtype\" itemtype=\"").Append(itemtype).Append("\" style=\"display:none;\"></div>");
            sb.Append("<div id=\"itemid\" itemid=\"").Append(itemid).Append("\" style=\"display:none;\"></div>");
            sb.Append("<div id=\"itemfields\">");
            if (itemtype == "camera")
            {
                sb.AppendLine("<div style=\"display:none;\" id=\"pageToLoadWhenFinished\" page=\"cameras\"></div>");
                bool foundCamera = false;
                lock (MJpegWrapper.cfg)
                {
                    foreach (CameraSpec cs in MJpegWrapper.cfg.cameras)
                    {
                        if (cs.id == itemid)
                        {
                            foundCamera = true;
                            CreateItemEditor(cs);
                            break;
                        }
                    }
                }
                if (!foundCamera)
                {
                    sb.Append("Could not find camera");
                }
                return(sb.ToString());
            }
            else if (itemtype == "user")
            {
                sb.AppendLine("<div style=\"display:none;\" id=\"pageToLoadWhenFinished\" page=\"users\"></div>");
                bool foundUser = false;
                lock (MJpegWrapper.cfg)
                {
                    foreach (Configuration.User u in MJpegWrapper.cfg.users)
                    {
                        if (u.name == itemid)
                        {
                            foundUser = true;
                            CreateItemEditor(u);
                            break;
                        }
                    }
                }
                if (!foundUser)
                {
                    sb.Append("Could not find user");
                }
                return(sb.ToString());
            }
            else if (itemtype == "ptzprofile")
            {
                sb.AppendLine("<div style=\"display:none;\" id=\"pageToLoadWhenFinished\" page=\"ptzprofiles\"></div>");
                bool foundProfile = false;
                lock (MJpegWrapper.cfg)
                {
                    foreach (Configuration.PTZProfile f in PTZProfile.GetPtzProfiles())
                    {
                        if (f.spec.name.ToLower() == itemid)
                        {
                            foundProfile = true;
                            CreateItemEditor(f.spec);
                            break;
                        }
                    }
                }
                if (!foundProfile)
                {
                    sb.Append("Could not find PTZ Profile");
                }
                return(sb.ToString());
            }
            else
            {
                sb.AppendLine("<div style=\"display:none;\" id=\"pageToLoadWhenFinished\" page=\"main\"></div>");
            }
            sb.Append("</div>");
            return(sb.ToString());
        }
Beispiel #5
0
        protected override string GetPageHtml(HttpProcessor p, Session s)
        {
            ItemTable <PTZProfile> tbl = new ItemTable <PTZProfile>("PTZ Profiles", "ptzprofile", "name", PTZProfile.GetPtzProfiles(), PTZProfile.lockObj, ItemTableMode.Add, new ItemTableColumnDefinition <PTZProfile>[]
            {
                new ItemTableColumnDefinition <PTZProfile>("Name", c => { return("<a href=\"javascript:EditItem('" + HttpUtility.JavaScriptStringEncode(c.spec.name) + "')\">" + HttpUtility.HtmlEncode(c.spec.name) + "</a>"); })
            });

            return(tbl.GetSectionHtml());
        }
Beispiel #6
0
        public void MoveSimple(PTZDirection direction)
        {
            PTZProfile profile = GetProfile();

            if (profile == null)
            {
                return;
            }
            if (typeof(PTZSpecV1) == profile.spec.GetType())
            {
                PTZSpecV1 spec = (PTZSpecV1)profile.spec;
                string    url;
                int       waitTime;
                if (direction == PTZDirection.Up)
                {
                    waitTime = spec.TiltRunTimeMs;
                    url      = spec.up;
                }
                else if (direction == PTZDirection.Down)
                {
                    waitTime = spec.TiltRunTimeMs;
                    url      = spec.down;
                }
                else if (direction == PTZDirection.Left)
                {
                    waitTime = spec.PanRunTimeMs;
                    url      = spec.left;
                }
                else if (direction == PTZDirection.Right)
                {
                    waitTime = spec.PanRunTimeMs;
                    url      = spec.right;
                }
                else if (spec.EnableDiagonals)
                {
                    if (direction == PTZDirection.UpLeft)
                    {
                        url = spec.upleft;
                    }
                    else if (direction == PTZDirection.DownLeft)
                    {
                        url = spec.downleft;
                    }
                    else if (direction == PTZDirection.UpRight)
                    {
                        url = spec.upright;
                    }
                    else if (direction == PTZDirection.DownRight)
                    {
                        url = spec.downright;
                    }
                    else
                    {
                        return;
                    }

                    waitTime = Math.Min(spec.PanRunTimeMs, spec.TiltRunTimeMs);
                }
                else
                {
                    return;
                }

                SimpleProxy.GetData(urlBase + url, camSpec.ptz_username, camSpec.ptz_password);

                if (spec.SendStopCommandAfterPanTilt && !string.IsNullOrWhiteSpace(spec.stopPanTilt))
                {
                    Thread.Sleep(waitTime);
                    SimpleProxy.GetData(urlBase + spec.stopPanTilt, camSpec.ptz_username, camSpec.ptz_password);
                }
            }
        }
Beispiel #7
0
        private void Preset(int presetNum, bool save)
        {
            PTZProfile profile = GetProfile();

            if (profile == null)
            {
                return;
            }
            if (typeof(PTZSpecV1) == profile.spec.GetType())
            {
                PTZSpecV1 spec = (PTZSpecV1)profile.spec;
                string    url  = null;
                if (presetNum == 1)
                {
                    url = save ? spec.save_preset_1 : spec.load_preset_1;
                }
                else if (presetNum == 2)
                {
                    url = save ? spec.save_preset_2 : spec.load_preset_2;
                }
                else if (presetNum == 3)
                {
                    url = save ? spec.save_preset_3 : spec.load_preset_3;
                }
                else if (presetNum == 4)
                {
                    url = save ? spec.save_preset_4 : spec.load_preset_4;
                }
                else if (presetNum == 5)
                {
                    url = save ? spec.save_preset_5 : spec.load_preset_5;
                }
                else if (presetNum == 6)
                {
                    url = save ? spec.save_preset_6 : spec.load_preset_6;
                }
                else if (presetNum == 7)
                {
                    url = save ? spec.save_preset_7 : spec.load_preset_7;
                }
                else if (presetNum == 8)
                {
                    url = save ? spec.save_preset_8 : spec.load_preset_8;
                }
                if (!string.IsNullOrWhiteSpace(url))
                {
                    try
                    {
                        byte[] image = MJpegServer.cm.GetLatestImage(cam.cameraSpec.id);
                        if (image.Length > 0)
                        {
                            Util.WriteImageThumbnailToFile(image, Globals.ThumbsDirectoryBase + cam.cameraSpec.id.ToLower() + presetNum + ".jpg");
                        }
                    }
                    catch (Exception ex)
                    {
                        Logger.Debug(ex);
                    }
                    SimpleProxy.GetData(urlBase + url, camSpec.ptz_username, camSpec.ptz_password);
                }
            }
        }
Beispiel #8
0
        public void Zoom(ZoomDirection direction, ZoomAmount amount)
        {
            PTZProfile profile = GetProfile();

            if (profile == null)
            {
                return;
            }
            if (typeof(PTZSpecV1) == profile.spec.GetType())
            {
                PTZSpecV1 spec     = (PTZSpecV1)profile.spec;
                string    url      = null;
                int       waitTime = 0;
                if (direction == ZoomDirection.In)
                {
                    if (amount == ZoomAmount.Short && !string.IsNullOrWhiteSpace(spec.zoomInShort))
                    {
                        waitTime = spec.ZoomRunTimeShortMs;
                        url      = spec.zoomInShort;
                    }
                    else if (amount == ZoomAmount.Medium && !string.IsNullOrWhiteSpace(spec.zoomInMedium))
                    {
                        waitTime = spec.ZoomRunTimeMediumMs;
                        url      = spec.zoomInMedium;
                    }
                    else if (amount == ZoomAmount.Long && !string.IsNullOrWhiteSpace(spec.zoomInLong))
                    {
                        waitTime = spec.ZoomRunTimeLongMs;
                        url      = spec.zoomInLong;
                    }
                }
                else if (direction == ZoomDirection.Out)
                {
                    if (amount == ZoomAmount.Short && !string.IsNullOrWhiteSpace(spec.zoomOutShort))
                    {
                        waitTime = spec.ZoomRunTimeShortMs;
                        url      = spec.zoomOutShort;
                    }
                    else if (amount == ZoomAmount.Medium && !string.IsNullOrWhiteSpace(spec.zoomOutMedium))
                    {
                        waitTime = spec.ZoomRunTimeMediumMs;
                        url      = spec.zoomOutMedium;
                    }
                    else if (amount == ZoomAmount.Long && !string.IsNullOrWhiteSpace(spec.zoomOutLong))
                    {
                        waitTime = spec.ZoomRunTimeLongMs;
                        url      = spec.zoomOutLong;
                    }
                }
                if (string.IsNullOrWhiteSpace(url))
                {
                    return;
                }

                SimpleProxy.GetData(urlBase + url, camSpec.ptz_username, camSpec.ptz_password);

                if (spec.SendStopCommandAfterZoom && !string.IsNullOrWhiteSpace(spec.stopZoom))
                {
                    Thread.Sleep(waitTime);
                    SimpleProxy.GetData(urlBase + spec.stopZoom, camSpec.ptz_username, camSpec.ptz_password);
                }
            }
        }