コード例 #1
0
 /// <summary>
 /// Permite consultar la información de un dispositivo de video determinado por su Id lógico.
 /// </summary>
 public object GetPTZUnitById(int id)
 {
     if (LoginGuid() is bool)
     {
         objCameraPTZ = new PTZDevice();
         try
         {
             foreach (IVideoInSceneEntity camera in m_DvtelSystem.AdministrationAPI.GetCachedEntitiesOfType(typeof(IVideoInSceneEntity), null).Values)
             {
                 if (camera.LogicalId == id)
                 {
                     if (EstadoDispositivoPtz(camera.Id) is bool)
                     {
                         objCameraPTZ = GetDataPtz(m_DvtelSystem, camera);
                         return(ResponseMethod(CodeStatus.OK, string.Empty, objCameraPTZ));
                     }
                     return(objModelResponseMethod);
                 }
             }
             if (objCameraPTZ == null)
             {
                 return(ResponseMethod(CodeStatus.NOT_FOUND, "El dispositivo no es un dispositivo de video", null));
             }
             return(ResponseMethod(CodeStatus.OK, string.Empty, objCameraPTZ));
         }
         catch (Exception errorGet)
         {
             return(ResponseMethod(CodeStatus.INTERNAL_SERVER_ERROR, errorGet.Message, null));
         }
     }
     return(objModelResponseMethod);
 }
コード例 #2
0
        static void Main(string[] args)
        {
            var p = PTZDevice.GetDevice(ConfigurationManager.AppSettings["DeviceName"], PTZType.Relative);

            while (true)
            {
                ConsoleKeyInfo info = Console.ReadKey();
                if (info.Key == ConsoleKey.LeftArrow)
                {
                    p.Move(-1, 0);
                }
                else if (info.Key == ConsoleKey.RightArrow)
                {
                    p.Move(1, 0);
                }
                else if (info.Key == ConsoleKey.UpArrow)
                {
                    p.Move(0, 1);
                }
                else if (info.Key == ConsoleKey.DownArrow)
                {
                    p.Move(0, -1);
                }
                else if (info.Key == ConsoleKey.Home)
                {
                    p.Zoom(1);
                }
                else if (info.Key == ConsoleKey.End)
                {
                    p.Zoom(-1);
                }
            }
        }
コード例 #3
0
        private async void MainWindow_Loaded(object sender, RoutedEventArgs e)
        {
            var deviceName = ConfigurationManager.AppSettings["DeviceName"];

            device = PTZDevice.GetDevice(deviceName, PTZType.Relative);

            url         = ConfigurationManager.AppSettings["relayServerUrl"];
            remoteGroup = Environment.MachineName; //They have to hardcode the group, but for us it's our machine name
            connection  = new HubConnection(url);
            proxy       = connection.CreateHubProxy("RelayHub");

            connection.TraceLevel  = TraceLevels.StateChanges | TraceLevels.Events;
            connection.TraceWriter = new PTZRemoteTraceWriter(Log);

            //Can't do this here because DirectShow has to be on the UI thread!
            // This would cause an obscure COM casting error with no clue what's up. So, um, ya.
            //proxy.On<int, int>("Move",(x,y) => device.Move(x, y));
            //proxy.On<int>("Zoom", (z) => device.Zoom(z));

            magic = SynchronizationContext.Current;

            proxy.On <int, int>("Move", (x, y) =>
            {
                //Toss this over the fence from this background thread to the UI thread
                magic.Post((_) => {
                    Log(String.Format("Move({0},{1})", x, y));
                    device.Move(x, y);
                }, null);
            });

            proxy.On <int>("Zoom", (z) =>
            {
                magic.Post((_) =>
                {
                    Log(String.Format("Zoom({0})", z));
                    device.Zoom(z);
                }, null);
            });


            try
            {
                await connection.Start();

                Log("After connection.Start()");
                await proxy.Invoke("JoinRelay", remoteGroup);

                Log("After JoinRelay");
            }
            catch (Exception pants)
            {
                Log(pants.GetError().ToString());
                throw;
            }
        }
コード例 #4
0
 /// <summary>
 /// Permite consultar la información de un dispositivo de video determinado por su Id .
 /// </summary>
 public object GetPTZUnitByGuid(Guid guid)
 {
     if (LoginGuid() is bool)
     {
         objCameraPTZ = new PTZDevice();
         if (EstadoDispositivoPtz(guid) is bool)
         {
             objCameraPTZ = GetDataPtz(m_DvtelSystem, camera);
             return(ResponseMethod(CodeStatus.OK, string.Empty, objCameraPTZ));
         }
     }
     return(objModelResponseMethod);
 }
コード例 #5
0
 /// <summary>
 /// Obtiene la información de los dispositivos de video en el sistema.
 /// </summary>
 public object GetCamerasPTZ()
 {
     if (LoginGuid() is bool)
     {
         var listCamaras = new List <object>();
         foreach (IVideoInSceneEntity camera in m_DvtelSystem.AdministrationAPI.GetCachedEntitiesOfType(typeof(IVideoInSceneEntity), null).Values)
         {
             /*if (camera.IsPtzEnabled)
              * {*/
             objCameraPTZ = new PTZDevice();
             objCameraPTZ = GetDataPtz(m_DvtelSystem, camera);
             listCamaras.Add(objCameraPTZ);
             //}
         }
         if (listCamaras.Count < 1)
         {
             return(ResponseMethod(CodeStatus.NOT_FOUND, "No se encontraron dispositivos tipo PTZ", null));
         }
         return(ResponseMethod(CodeStatus.OK, string.Empty, listCamaras));
     }
     return(objModelResponseMethod);
 }
コード例 #6
0
        /// <summary>
        /// Obtiene los datos de un dispositivo de video ,sirve de método auxiliar para la obtención de información.
        /// </summary>
        private PTZDevice GetDataPtz(IDvtelSystemId latitudeSystem, IVideoInSceneEntity camera)
        {
            objCameraPTZ = new PTZDevice();
            var deviceApi = latitudeSystem.GetAPI <IDeviceAPI>();
            var ptzClient = deviceApi.AcquirePTZControl(camera);

            var m_playerAPI = latitudeSystem.GetAPI <IPlayerAPI>();

            /*if (ptzClient != null)
             * {*/
            objCameraPTZ.canFocus         = ptzClient != null? ptzClient.CanFocus: false;
            objCameraPTZ.canIris          = ptzClient != null ? ptzClient.CanIris : false;
            objCameraPTZ.canPanTilt       = ptzClient != null ? ptzClient.CanPanTilt : false;
            objCameraPTZ.canZoom          = ptzClient != null ? ptzClient.CanZoom : false;
            objCameraPTZ.isLocked         = ptzClient != null ? ptzClient.IsLocked : false;
            objCameraPTZ.numberOfPatterns = ptzClient != null ? ptzClient.NumberOfPatterns:0;
            objCameraPTZ.numberOfPresets  = ptzClient != null ? ptzClient.NumberOfPresets:0;
            objCameraPTZ.sceneId          = ptzClient != null ? ptzClient.SceneId:Guid.Empty;
            objCameraPTZ.sessionId        = ptzClient != null ? ptzClient.SessionId : Guid.Empty;


            var locationBaseEntity = ptzClient != null?ptzClient.GetCurrentLocation() : null;

            if (locationBaseEntity is IPtzMotorNormalized3DLocationEntity)
            {
                var location = (IPtzMotorNormalized3DLocationEntity)locationBaseEntity;
                objCameraPTZ.panValue  = location.PanValue.ToString();
                objCameraPTZ.tiltValue = location.TiltValue.ToString();
                objCameraPTZ.zoomValue = location.ZoomValue.ToString();
            }

            if (locationBaseEntity is IPtzMotor3DLocationEntity)
            {
                var absLocation = (IPtzMotor3DLocationEntity)locationBaseEntity;
                objCameraPTZ.panValue  = absLocation.PanValue;
                objCameraPTZ.tiltValue = absLocation.TiltValue;
                objCameraPTZ.zoomValue = absLocation.ZoomValue;
            }



            PTZDevice.geoLocation geographicLocation = new PTZDevice.geoLocation();
            entity = m_DvtelSystem.AdministrationAPI.GetCachedEntity(camera.Id);


            var objIPTZMotorEntity2 = entity as IPTZMotorEntity;
            IAdminCenterEntity objIAdminCenterEntity = entity as IAdminCenterEntity;

            bool isReady = false;
            ISceneGeoLocationEntity objISceneGeoLocationEntity;

            objISceneGeoLocationEntity = entity as ISceneGeoLocationEntity;
            if (objISceneGeoLocationEntity != null)
            {
                isReady = true;
            }

            objISceneGeoLocationEntity = camera as ISceneGeoLocationEntity;
            if (objISceneGeoLocationEntity != null)
            {
                isReady = true;
            }
            dynamic ipstream = camera.GetStreamSourceIp();

            var eje = camera.DvtelSystem.CreateEntity <ISceneGeoLocationEntity>();



            if (isReady)
            {
                geographicLocation.latitude     = objISceneGeoLocationEntity.Latitude;
                geographicLocation.altitude     = objISceneGeoLocationEntity.Altitude;
                geographicLocation.longitude    = objISceneGeoLocationEntity.Longitude;
                objCameraPTZ.geographicLocation = geographicLocation;
            }
            eje = entity as ISceneGeoLocationEntity;

            dynamic entityReferencer = entity.GetEntityReferencers()[0].Entity;

            try
            {
                objCameraPTZ.firmware = entityReferencer.FirmwareVersion;
            } catch
            {
                objCameraPTZ.firmware = string.Empty;
            }
            try
            {
                objCameraPTZ.model = entityReferencer != null ? entityReferencer.Model : string.Empty;
            }
            catch
            {
                objCameraPTZ.model = string.Empty;
            }
            try
            {
                objCameraPTZ.pluginName = entityReferencer != null ? entityReferencer.Plugin.Name : string.Empty;
            }
            catch
            {
                objCameraPTZ.pluginName = string.Empty;
            }
            try
            {
                objCameraPTZ.pluginVersion = entityReferencer != null ? entityReferencer.pluginVersion : string.Empty;
            }
            catch
            {
                objCameraPTZ.pluginVersion = string.Empty;
            }



            var DataEntities             = camera.ExternalDataEntities;
            var ExternalPluginWorkspaces = camera.ExternalPluginWorkspaces;
            var GetActiveSchedules       = camera.GetActiveSchedules();
            var extendedTypes            = camera.GetAllExtendedTypes();
            var detetionurl   = camera.GetCameraMotionDetectionSettingsUrl();
            var metadata      = camera.GetEntityMetaData();
            var cam_entityref = camera.GetEntityReferencers();

            var locationCamera = camera.GetPropertyLocalizationEnum(SceneGeoLocationEntityEnum.Altitude);

            locationCamera = camera.GetPropertyLocalizationEnum(SceneGeoLocationEntityEnum.Latitude);
            locationCamera = camera.GetPropertyLocalizationEnum(SceneGeoLocationEntityEnum.Longitude);


            objCameraPTZ.description  = camera.Description;
            objCameraPTZ.guid         = camera.Id;
            objCameraPTZ.isPtzOnline  = camera.IsPtzOnline;
            objCameraPTZ.logicalId    = camera.LogicalId;
            objCameraPTZ.name         = camera.Name;
            objCameraPTZ.creationTime = camera.CreationTime;
            objCameraPTZ.isViewable   = camera.IsViewable;
            objCameraPTZ.deviceUrl    = camera.GetCameraGeneralPageUrl();

            dynamic dyCamera      = camera;
            dynamic dyEntity      = entity;
            dynamic entityDynamic = entity;
            var     logiclaloc    = entityDynamic.LogicalLocation;

            try
            {
                foreach (var vEvent in camera.EventHandlers.Values.ToList())
                {
                    objCameraPTZ.supportedEvents += vEvent.Caption + " ";
                }
            }
            catch
            { objCameraPTZ.supportedEvents = ""; }

            objCameraPTZ.clientsConnectionType = camera.ClientsConnectionType != null?camera.ClientsConnectionType.ToString() : string.Empty;

            objCameraPTZ.detailedInformation    = camera.DetailedInformation;
            objCameraPTZ.deviceDriverExternalId = camera.DeviceDriver != null?camera.DeviceDriver.ExternalId.ToString() : string.Empty;

            objCameraPTZ.isAccessible      = camera.IsAccessible;
            objCameraPTZ.isEnabled         = camera.IsEnabled;
            objCameraPTZ.linkedUrl         = camera.LinkedUrl != null? camera.LinkedUrl.Url:string.Empty;
            objCameraPTZ.videoSourceFormat = camera.VideoSourceFormat.ToString();

            // dynamic dymLoc=GetLoc

            try
            {
                foreach (var vAddress in camera.Addresses.Values.ToList())
                {
                    objCameraPTZ.address += vAddress.Caption + " ";
                }
            }
            catch
            {
                objCameraPTZ.address = "";
            }
            objCameraPTZ.timeZone     = camera.TimeZone.ToString();
            objCameraPTZ.IsPtzLocked  = camera.IsPtzLocked;
            objCameraPTZ.IsPtzEnabled = camera.IsPtzEnabled;
            //}
            return(objCameraPTZ);
        }
コード例 #7
0
        protected override void OnStart(string[] args)
        {
            PTZDevice device = null;

            httpsv = new HttpServer(4649);

            httpsv.OnGet += (sender, e) =>
            {
                HttpListenerRequest  req = e.Request;
                HttpListenerResponse res = e.Response;

                string msg   = "";
                string query = req.QueryString.ToString();
                if (query.Contains("init"))
                {
                    Match  match      = Regex.Match(query, "init=(.+)");
                    string deviceName = match.Groups[1].Captures[0].ToString();
                    try
                    {
                        device         = PTZDevice.GetDevice(deviceName, PTZType.Relative);
                        msg            = "Device created";
                        res.StatusCode = (int)HttpStatusCode.OK;
                    }
                    catch (Exception ex)
                    {
                        msg            = ex.Message;
                        res.StatusCode = (int)HttpStatusCode.InternalServerError;
                    }
                }
                else if (query.Contains("action"))
                {
                    if (device == null)
                    {
                        msg            = "Device must be initialized before using";
                        res.StatusCode = (int)HttpStatusCode.BadRequest;
                    }
                    else
                    {
                        Match  match  = Regex.Match(query, "action=(.+)");
                        string action = match.Groups[1].Captures[0].ToString();
                        if (action.Equals("move_left"))
                        {
                            device.Move(-1, 0);
                        }
                        else if (action.Equals("move_right"))
                        {
                            device.Move(1, 0);
                        }
                        else if (action.Equals("move_up"))
                        {
                            device.Move(0, -1);
                        }
                        else if (action.Equals("move_down"))
                        {
                            device.Move(0, 1);
                        }
                        else if (action.Equals("zoom_in"))
                        {
                            device.Zoom(1);
                        }
                        else if (action.Equals("zoom_out"))
                        {
                            device.Zoom(-1);
                        }
                        else
                        {
                            msg            = "Unsupported action: " + action;
                            res.StatusCode = (int)HttpStatusCode.BadRequest;
                        }
                    }
                }
                else
                {
                    msg            = "Invalida request";
                    res.StatusCode = (int)HttpStatusCode.BadRequest;
                }

                string json = "{\"message\":\"" + msg + "\", \"query\":\"" + req.QueryString + "\"}";
                res.ContentType     = "application/json";
                res.ContentEncoding = Encoding.UTF8;

                res.WriteContent(Encoding.UTF8.GetBytes(json));
            };

            httpsv.Start();

            if (httpsv.IsListening)
            {
                Console.WriteLine("Listening on port {0}, and providing WebSocket services:", httpsv.Port);
                foreach (var path in httpsv.WebSocketServices.Paths)
                {
                    Console.WriteLine("- {0}", path);
                }
            }
        }
コード例 #8
0
        public void Zoom(int value)
        {
            var p = PTZDevice.GetDevice(ConfigurationManager.AppSettings["DeviceName"], PTZType.Relative);

            p.Zoom(value);
        }
コード例 #9
0
        public void Move(int x, int y)
        {
            var p = PTZDevice.GetDevice(ConfigurationManager.AppSettings["DeviceName"], PTZType.Relative);

            p.Move(x, y);
        }