天地伟业摄像头信息
Inheritance: CgwMonitorManage.Common.Camera
Ejemplo n.º 1
0
        /// <summary>
        /// 获取摄像头列表及分组信息
        /// </summary>
        /// <param name="fromMonitorSys">如果该值为true,则实时从监控平台获取,否则从融合网关缓存获取</param>
        /// <param name="cameraList">摄像头列表</param>
        /// <param name="groupList">组信息</param>
        /// <param name="nodeRelationListT">分组关系</param>
        /// <returns></returns>
        public SmcErr GetAllCameras(out List <Camera> cameraList, out List <CameraGroup> groupList, out List <NodeRelation> nodeRelationListT)
        {
            monitorManageServiceGetCameraList.Stop();
            isGetDevicesFinish = false;

            NLogEx.LoggerEx logEx = new NLogEx.LoggerEx(log);
            logEx.Trace("Enter: TiandyVideoMonitor.GetAllCameras().");
            SmcErr err = new CgwError();

            cameraList        = new List <Camera>();
            groupList         = new List <CameraGroup>();
            nodeRelationListT = new List <NodeRelation>();

            if (this.cameraOperateLock.TryEnterReadLock(CgwConst.ENTER_LOCK_WAIT_TIME))
            {
                try
                {
                    #region 深度克隆数据
                    foreach (KeyValuePair <string, TiandyCamera> tiandyCameraKeyValue in this.tiandyCameraDictionary)
                    {
                        TiandyCamera tiandyCamera = tiandyCameraKeyValue.Value;
                        //从缓存获取
                        Camera camera = new Camera(tiandyCamera.No, tiandyCamera.Name);
                        cameraList.Add(camera);
                    }
                    foreach (KeyValuePair <string, CameraGroup> groupDicKeyValue in this.groupDic)
                    {
                        CameraGroup cameraGroupTemp = new CameraGroup(groupDicKeyValue.Value.No, groupDicKeyValue.Value.Name);
                        groupList.Add(cameraGroupTemp);
                    }

                    foreach (NodeRelation nodeRelation in this.nodeRelationList)
                    {
                        NodeRelation nodeRelationTemp = new NodeRelation(nodeRelation.No,
                                                                         nodeRelation.Path,
                                                                         nodeRelation.Type);
                        nodeRelationListT.Add(nodeRelationTemp);
                    }
                    #endregion
                }
                catch (Exception e)
                {
                    err.SetErrorNo(CgwError.GET_ALL_CAMERAS_FAILED);
                    logEx.Error("Get all cameras failed.Execption message:{0}", e.Message);
                    return(err);
                }
                finally
                {
                    this.cameraOperateLock.ExitReadLock();
                }
            }
            monitorManageServiceGetCameraList.Start();
            logEx.Info("Get all cameras success.");
            return(err);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 递归天地伟业返回的设备树,获取所有通道(一个通道对应一个摄像头)、主机、流媒体(中间件)服务器
        /// </summary>
        /// <param name="resourceTree">天地伟业返回的设备树</param>
        /// <param name="tiandyCameraDictionary">摄像头键值对,key为摄像头编号</param>
        /// <param name="hostDictionary">主机键值对,key为主机编号</param>
        /// <param name="mediaServerDictionary">流媒体(中间件)服务键值对,key为编号</param>
        private void RecursionCamera(List<Resource> resourceTree, Dictionary<string, TiandyCamera> tiandyCameraDictionary, Dictionary<string, Host> hostDictionary, Dictionary<string, MediaServer> mediaServerDictionary)
        {
            NLogEx.LoggerEx logEx = new NLogEx.LoggerEx(log);

            if (resourceTree == null)
            {
                logEx.Error("Recursion camera failed.ResourceTree is null.");
                return;
            }
            if (tiandyCameraDictionary == null)
            {
                tiandyCameraDictionary = new Dictionary<string, TiandyCamera>();
            }
            if (hostDictionary == null)
            {
                hostDictionary = new Dictionary<string, Host>();
            }
            if (mediaServerDictionary == null)
            {
                mediaServerDictionary = new Dictionary<string, MediaServer>();
            }
            foreach (Resource resource in resourceTree)
            {
                //TypeId为5时,表示该节点为通道,对应一个摄像头
                if (((int)NodeType.CAMERA).ToString().Equals(resource.TypeId))
                {
                    TiandyCamera camera = new TiandyCamera(resource.Id, resource.Caption);
                    camera.Channel = resource.Ch;
                    //摄像头的父节点为主机
                    camera.HostNo = resource.ParentId;
                    tiandyCameraDictionary.Add(camera.No, camera);

                    //如果是摄像头节点,不需要递归
                    continue;
                }
                else if (((int)NodeType.HOST).ToString().Equals(resource.TypeId))
                {
                    //将主机加入缓存,主机的父节点为流媒体(中间件)服务器
                    Host host = new Host(
                                resource.Id,
                                resource.Username,
                                resource.Pwd,
                                resource.ParentId);

                    hostDictionary.Add(host.No, host);
                }
                else if (((int)NodeType.MEDIASERVER).ToString().Equals(resource.TypeId))
                {
                    //将流媒体(中间件)服务器加入缓存
                    MediaServer mediaServer = new MediaServer(
                                                resource.Id,
                                                resource.Ip,
                                                resource.Port,
                                                resource.Username,
                                                resource.Pwd);

                    mediaServerDictionary.Add(mediaServer.No, mediaServer);
                }

                //递归处理
                RecursionCamera(resource.items, tiandyCameraDictionary, hostDictionary, mediaServerDictionary);
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 递归天地伟业返回的设备树,获取所有通道(一个通道对应一个摄像头)、主机、流媒体(中间件)服务器
        /// </summary>
        /// <param name="resourceTree">天地伟业返回的设备树</param>
        /// <param name="tiandyCameraDictionary">摄像头键值对,key为摄像头编号</param>
        /// <param name="hostDictionary">主机键值对,key为主机编号</param>
        /// <param name="mediaServerDictionary">流媒体(中间件)服务键值对,key为编号</param>
        private void RecursionCamera(List <Resource> resourceTree, Dictionary <string, TiandyCamera> tiandyCameraDictionary, Dictionary <string, Host> hostDictionary, Dictionary <string, MediaServer> mediaServerDictionary)
        {
            NLogEx.LoggerEx logEx = new NLogEx.LoggerEx(log);

            if (resourceTree == null)
            {
                logEx.Error("Recursion camera failed.ResourceTree is null.");
                return;
            }
            if (tiandyCameraDictionary == null)
            {
                tiandyCameraDictionary = new Dictionary <string, TiandyCamera>();
            }
            if (hostDictionary == null)
            {
                hostDictionary = new Dictionary <string, Host>();
            }
            if (mediaServerDictionary == null)
            {
                mediaServerDictionary = new Dictionary <string, MediaServer>();
            }
            foreach (Resource resource in resourceTree)
            {
                //TypeId为5时,表示该节点为通道,对应一个摄像头
                if (((int)NodeType.CAMERA).ToString().Equals(resource.TypeId))
                {
                    TiandyCamera camera = new TiandyCamera(resource.Id, resource.Caption);
                    camera.Channel = resource.Ch;
                    //摄像头的父节点为主机
                    camera.HostNo = resource.ParentId;
                    tiandyCameraDictionary.Add(camera.No, camera);

                    //如果是摄像头节点,不需要递归
                    continue;
                }
                else if (((int)NodeType.HOST).ToString().Equals(resource.TypeId))
                {
                    //将主机加入缓存,主机的父节点为流媒体(中间件)服务器
                    Host host = new Host(
                        resource.Id,
                        resource.Username,
                        resource.Pwd,
                        resource.ParentId);

                    hostDictionary.Add(host.No, host);
                }
                else if (((int)NodeType.MEDIASERVER).ToString().Equals(resource.TypeId))
                {
                    //将流媒体(中间件)服务器加入缓存
                    MediaServer mediaServer = new MediaServer(
                        resource.Id,
                        resource.Ip,
                        resource.Port,
                        resource.Username,
                        resource.Pwd);

                    mediaServerDictionary.Add(mediaServer.No, mediaServer);
                }

                //递归处理
                RecursionCamera(resource.items, tiandyCameraDictionary, hostDictionary, mediaServerDictionary);
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// 启动摄像头预览
        /// </summary>
        /// <param name="cameraNo">摄像头编号</param>
        /// <returns></returns>
        public SmcErr StartReceiveVideo(string cameraNo)
        {
            NLogEx.LoggerEx logEx = new NLogEx.LoggerEx(log);
            logEx.Trace("Enter: TiandyVideoMonitor.StartReceiveVideo({0}).", cameraNo);
            SmcErr err = new CgwError();

            TiandyCamera camera = null;
            Host         host   = null;

            //摄像头所连接的流媒体服务器
            MediaServer cameraMediaServer = null;

            if (this.cameraOperateLock.TryEnterReadLock(CgwConst.ENTER_LOCK_WAIT_TIME))
            {
                try
                {
                    if (!this.tiandyCameraDictionary.ContainsKey(cameraNo))
                    {
                        err.SetErrorNo(CgwError.CAMERA_NOT_FOUND);
                        logEx.Error("Start Receive camera video data failed.Camera No is not found.Camera No:{0}", cameraNo);
                        return(err);
                    }
                    camera            = this.tiandyCameraDictionary[cameraNo];
                    host              = this.hostDictionary[camera.HostNo];
                    cameraMediaServer = this.mediaServerDictionary[host.MediaServerNo];
                }
                catch (Exception e)
                {
                    err.SetErrorNo(CgwError.START_RECEIVE_VIDEO_FAILED);
                    logEx.Error("Start Receive camera video data failed.Camera No:{0},Execption message:{1}", cameraNo, e.Message);
                    return(err);
                }
                finally
                {
                    this.cameraOperateLock.ExitReadLock();
                }
            }

            if (camera == null)
            {
                err.SetErrorNo(CgwError.START_RECEIVE_VIDEO_FAILED);
                logEx.Error("Start Receive camera video data failed.Camera No is not found.Camera No:{0}", cameraNo);
                return(err);
            }

            RealPlayInfo real = new RealPlayInfo();

            real.ch        = camera.Channel;
            real.data_type = (int)TiandyDateType.PRIMARY;
            real.hPlayWnd  = null;

            int result = this.sdkClient.StartReceiveVideo(host.No, cameraMediaServer, ref real);

            //如果为负数,表示预览失败
            if (result < 0)
            {
                err.SetErrorNo(CgwError.START_RECEIVE_VIDEO_FAILED);
                logEx.Error("Start Receive camera video data failed.Camera No:{0}.", cameraNo);
                return(err);
            }
            else
            {
                //需要停止的预览句柄
                int needToStopHandel = CgwConst.START_RECEIVE_VIDEO_DATA_FAILED;
                if (this.handelOperateLock.TryEnterWriteLock(CgwConst.ENTER_LOCK_WAIT_TIME))
                {
                    try
                    {
                        //如果预览句柄已经存在,删除掉原来的句柄,用新的句柄替换
                        if (this.cameraVideoHandeDic.ContainsKey(cameraNo))
                        {
                            needToStopHandel = this.cameraVideoHandeDic[cameraNo];
                            this.videoHandleCameraDic.Remove(needToStopHandel);
                            this.cameraVideoHandeDic.Remove(cameraNo);
                        }
                        this.cameraVideoHandeDic.Add(cameraNo, result);
                        this.videoHandleCameraDic.Add(result, cameraNo);
                    }
                    finally
                    {
                        this.handelOperateLock.ExitWriteLock();
                    }
                }
                logEx.Info("Start Receive camera video data success.Camera No:{0},Handle:{1}.", cameraNo, result);
                //重新预览后,更新了预览句柄,需要将原来的预览停止,放在handelOperateLock外面,防止长时间占用锁
                if (needToStopHandel != CgwConst.START_RECEIVE_VIDEO_DATA_FAILED)
                {
                    this.sdkClient.StopReceiveVideo(needToStopHandel);
                }
            }

            return(err);
        }