Example #1
0
        /// <summary>
        /// 分配监控通道
        /// </summary>
        public SmcErr AssignMonitorChannel(List<ChannelInfo> ChannelInfoList)
        {
            SmcErr err = new CgwError();
            NLogEx.LoggerEx logEx = new NLogEx.LoggerEx(log);
            err = CheckSession();
            if (err.IsSuccess())
            {
                if (ChannelInfoList != null)
                {
                    err = MonitorChannelBll.Instance().AssignMonitorChannel(ChannelInfoList);

                }
                else
                {
                    err.SetErrorNo(CgwError.ERR_CGW_BUSINESS_CHANNELLIST_NULL);
                }

            }
            if (err.IsSuccess())
            {
                logEx.Trace("AssignMonitorChannel Successful");
            }
            else
            {
                logEx.Error("AssignMonitorChannel failed,ErrNo :{0}", err.ErrNo);
            }
            return err;
        }
        /// <summary>
        /// 尝试停止摄像头码流发送
        /// 只有当关联摄像头通道为1时,才需要停止发送码流
        /// </summary>
        /// <param name="cameraNo">摄像头编号</param>
        /// <param name="channelLabel">原先关联的通道编号</param>
        /// <returns>结果</returns>
        private SmcErr TryStopSendRtpData(string cameraNo, string channelLabel)
        {
            SmcErr err = new CgwError();
            NLogEx.LoggerEx logEx = new NLogEx.LoggerEx(log);
            logEx.Trace("TryStopSendRtpData start.");

            try
            {
                bool successed = this.cameraVideoRelationDicLocker.TryEnterWriteLock(CgwConst.ENTER_LOCK_WAIT_TIME);
                // 申请互斥
                if (successed)
                {
                    try
                    {
                        if (!this.cameraVideoRelationDic.ContainsKey(cameraNo))
                        {
                            logEx.Trace("TryStopSendRtpData cameraNo={0}, channelLabel={1} can't find cameraNo.", cameraNo, channelLabel);
                            return err;
                        }
                        this.cameraVideoRelationDic[cameraNo].RemoveAll(a => { return a == channelLabel; });
                        // 判断通道是否已经存在
                        if (null == this.cameraVideoRelationDic[cameraNo] || 0 == this.cameraVideoRelationDic[cameraNo].Count)
                        {
                            logEx.Trace("TryStopSendRtpData StopReceiveVideoByPipe cameraNo={0},channelLabel={1}", cameraNo, channelLabel);
                            // 停止视频码流
                            CgwMonitorManageAdapter.Instance().StopReceiveVideoByPipe(cameraNo);

                            this.cameraVideoRelationDic.Remove(cameraNo);
                        }
                    }
                    finally
                    {
                        // 释放互斥量
                        this.cameraVideoRelationDicLocker.ExitWriteLock();
                    }
                }
                else
                {
                    // 日志
                    err.SetErrorNo(CgwError.ERR_CGW_CHANNEL_GET_LOCK_FAIL);
                    logEx.Error("TryStopSendRtpData: Enert Write Lock Failed.WaitingReadCount:{0};WaitingWriteCount:{1}.", this.cameraVideoRelationDicLocker.WaitingReadCount, this.cameraVideoRelationDicLocker.WaitingWriteCount);
                }
            }
            catch (Exception ex)
            {
                // 日志
                err.SetErrorNo(CgwError.ERR_CGW_CHANNEL_SERVICE_ADNORMAL);
                logEx.Error(ex, "TryStopSendRtpData: Enert Write Lock Exception.");
            }

            logEx.Trace("TryStopSendRtpData cameraNo={0}, channelLabel={1} successfully.", cameraNo, channelLabel);
            return err;
        }
        /// <summary>
        /// 尝试启动摄像头码流
        /// 如果关联摄像头通道个数大于0时,不需要任何操作
        /// </summary>
        /// <param name="cameraNo">摄像头编号</param>
        /// <param name="cameraNo">关联的通道编号</param>
        /// <returns>结果</returns>
        private SmcErr TryStartSendRtpData(string cameraNo, string channelLabel)
        {
            SmcErr err = new CgwError();
            NLogEx.LoggerEx logEx = new NLogEx.LoggerEx(log);
            logEx.Trace("TryStartSendRtpData start.cameraNo:{0},channelLabel:{1}", cameraNo, channelLabel);

            try
            {
                //bool successed = this.cameraVideoRelationDicLocker.TryEnterWriteLock(CgwConst.ENTER_LOCK_WAIT_TIME);
                //// 申请互斥
                //if (successed)
                //{
                //    try
                //    {

                if (!this.cameraVideoRelationDic.ContainsKey(cameraNo))
                {
                    if (this.cameraVideoRelationDicLocker.TryEnterWriteLock(CgwConst.ENTER_LOCK_WAIT_TIME))
                    {
                        try
                        {
                            if (startCameraLists.Contains(cameraNo))
                            {
                                logEx.Trace("TryStartSendRtpData start.Contains CameraNo:{0}",cameraNo);
                                err.SetErrorNo(CgwError.START_RECEIVE_VIDEO_FAILED);
                                return err;
                            }
                            else
                            {
                                startCameraLists.Add(cameraNo);
                                logEx.Info("TryStartSendRtpData start.Add CameraNo:{0}",cameraNo);
                            }
                        }
                        finally
                        {
                            this.cameraVideoRelationDicLocker.ExitWriteLock();
                        }
                    }
                    string pipeName = "";
                    logEx.Trace("TryStartSendRtpData Begin StartReceiveVideo cameraNo={0}", cameraNo);
                    err = CgwMonitorManageAdapter.Instance().StartReceiveVideoByPipe(cameraNo, out pipeName);
                    //startCameraLists.Remove(cameraNo);
                    if (!err.IsSuccess())
                    {
                        logEx.Error("TryStartSendRtpData StartReceiveVideo cameraNo={0} failed.", cameraNo);
                        startCameraLists.Remove(cameraNo);
                        return err;
                    }
                    //this.cameraVideoRelationDic.Add(cameraNo, new List<string>());
                }

                if (this.cameraVideoRelationDicLocker.TryEnterWriteLock(CgwConst.ENTER_LOCK_WAIT_TIME))
                {
                    try
                    {
                        if (!this.cameraVideoRelationDic.ContainsKey(cameraNo))
                        {
                            this.cameraVideoRelationDic.Add(cameraNo, new List<string>());
                        }
                        if (startCameraLists.Contains(cameraNo))
                        {
                            startCameraLists.Remove(cameraNo);
                        }

                        // 判断通道是否已经存在
                        bool isExist = this.cameraVideoRelationDic[cameraNo].Exists(a => { return a == channelLabel; });
                        if (!isExist)
                        {
                            logEx.Trace("TryStartSendRtpData add CameraVideoRelationDic cameraNo={0},channelLabel={1}", cameraNo, channelLabel);
                            this.cameraVideoRelationDic[cameraNo].Add(channelLabel);
                        }
                    }
                    finally
                    {
                        this.cameraVideoRelationDicLocker.ExitWriteLock();
                    }
                }
                else
                {
                    err.SetErrorNo(CgwError.ERR_CGW_CHANNEL_GET_LOCK_FAIL);
                    logEx.Error("TryStartSendRtpData: Enert Write Lock Failed.WaitingReadCount:{0};WaitingWriteCount:{1}.", this.cameraVideoRelationDicLocker.WaitingReadCount, this.cameraVideoRelationDicLocker.WaitingWriteCount);
                }
                //}
                //finally
                //{
                //    // 释放互斥量
                //    this.cameraVideoRelationDicLocker.ExitWriteLock();
                //}
                //}
                //else
                //{
                //    // 日志
                //    err.SetErrorNo(CgwError.ERR_CGW_CHANNEL_GET_LOCK_FAIL);
                //    logEx.Error("TryStartSendRtpData: Enert Write Lock Failed.WaitingReadCount:{0};WaitingWriteCount:{1}.", this.cameraVideoRelationDicLocker.WaitingReadCount, this.cameraVideoRelationDicLocker.WaitingWriteCount);
                //}
            }
            catch (Exception ex)
            {
                // 日志
                err.SetErrorNo(CgwError.ERR_CGW_CHANNEL_SERVICE_ADNORMAL);
                logEx.Error(ex, "TryStartSendRtpData: Enert Write Lock Exception.");
            }

            logEx.Trace("TryStartSendRtpData cameraNo={0}, channelLabel={1} successfully.", cameraNo, channelLabel);
            return err;
        }
        /// <summary>
        /// 开启音频码流
        /// </summary>
        /// <param name="channelLabel"></param>
        /// <param name="cameraNo"></param>
        /// <returns></returns>
        private SmcErr TryStartSendAudio(string channelLabel, string cameraNo)
        {
            SmcErr err = new CgwError();
            NLogEx.LoggerEx logEx = new NLogEx.LoggerEx(log);
            logEx.Trace("TryStartSendAudio start.");

            try
            {
                bool successed = this.cameraAudioRelationDicLocker.TryEnterWriteLock(CgwConst.ENTER_LOCK_WAIT_TIME);
                // 申请互斥
                if (successed)
                {
                    try
                    {
                        if (!this.cameraAudioRelationDic.ContainsKey(cameraNo))
                        {
                            err = CgwMonitorManageAdapter.Instance().SetMic(cameraNo, true);
                            if (!err.IsSuccess())
                            {
                                logEx.Error("TryStartSendAudio SetMic start cameraNo={0} failed.", cameraNo);
                                return err;
                            }

                            this.cameraAudioRelationDic.Add(cameraNo, new List<string>());
                        }

                        // 判断通道是否已经存在
                        bool isExist = this.cameraAudioRelationDic[cameraNo].Exists(a => { return a == channelLabel; });
                        if (!isExist)
                        {
                            this.cameraAudioRelationDic[cameraNo].Add(channelLabel);
                        }
                    }
                    finally
                    {
                        // 释放互斥量
                        this.cameraAudioRelationDicLocker.ExitWriteLock();
                    }
                }
                else
                {
                    // 日志
                    err.SetErrorNo(CgwError.ERR_CGW_CHANNEL_GET_LOCK_FAIL);
                    logEx.Error("TryStartSendAudio: Enert Write Lock Failed.WaitingReadCount:{0};WaitingWriteCount:{1}.", this.cameraAudioRelationDicLocker.WaitingReadCount, this.cameraAudioRelationDicLocker.WaitingWriteCount);
                }
            }
            catch (Exception ex)
            {
                // 日志
                err.SetErrorNo(CgwError.ERR_CGW_CHANNEL_SERVICE_ADNORMAL);
                logEx.Error(ex, "TryStartSendAudio: Enert Write Lock Exception.");
            }

            logEx.Trace("TryStartSendAudio cameraNo={0}, channelLabel={1} successfully.", cameraNo, channelLabel);
            return err;
        }
Example #5
0
        /// <summary>
        /// 获取软终端被叫sip端口号
        /// </summary>
        /// <param name="sipPort"></param>
        /// <returns></returns>
        public SmcErr GetSipPort(out uint sipPort)
        {
            NLogEx.LoggerEx logEx = new NLogEx.LoggerEx(log);
            logEx.Trace("Enter: CgwService.GetSipPort");

            SmcErr err = new CgwError();

            sipPort = (uint)ConfigSettings.CgwChanelCallPort;
            logEx.Debug("sipPort = {0}", sipPort);

            if (0 == sipPort)
            {
                err.SetErrorNo(CgwError.ERR_CGW_CONFIGURE_FORMAT);
            }
            return err;
        }
        private void DataException(string cameraNo)
        {
            SmcErr err = new CgwError();
            NLogEx.LoggerEx logEx = new NLogEx.LoggerEx(log);
            logEx.Trace("DataException start.");
            logEx.Trace("DataException cameraNo={0}.", cameraNo);
            try
            {
                if (this.cameraVideoRelationDic.ContainsKey(cameraNo))
                {
                    List<string> channelList = new List<string>(this.cameraVideoRelationDic[cameraNo]);

                    for (int i = 0; i < channelList.Count; i++)
                    {
                        logEx.Trace("DataException channelList={0}.", channelList[i]);
                        //this.monitorChannelRelationDic[channelList[i]].CameraNo = null;
                        offLineCameras.Add(cameraNo);
                        logEx.Trace("DataException offLineCameras count:{0}", offLineCameras.Count);
                        this.TryStopSendRtpData(cameraNo, channelList[i]);
                    }
                }
            }
            catch (Exception ex)
            {
                // 日志
                err.SetErrorNo(CgwError.ERR_CGW_CHANNEL_SERVICE_ADNORMAL);
                logEx.Error("DataException:{0}", ex);
            }
            logEx.Trace("DataException end.");
        }
Example #7
0
        /// <summary>
        /// 断开融合网关
        /// </summary>
        /// <returns></returns>
        public SmcErr DisConnect()
        {
            NLogEx.LoggerEx logEx = new NLogEx.LoggerEx(log);
            SmcErr err = new CgwError();
            if (OperationContext.Current != null)
            {
                string strSessionId = OperationContext.Current.SessionId;
                if (!string.IsNullOrEmpty(strSessionId))
                {
                    err = SessionManage.Instance().RemoveSessionBySessionId(strSessionId);
                    logEx.Trace("DisConnect Successful,Current.SessionId is : ", strSessionId);
                }
                else
                {
                    err.SetErrorNo(CgwError.ERR_CGW_BUSINESS_CURRENTSESSION_NULL);
                    logEx.Warn("Current SessionId is null ! ");
                }
            }
            else
            {
                err.SetErrorNo(CgwError.ERR_CGW_BUSINESS_CURRENTSESSION_NULL);
                logEx.Warn("Current SessionId is null ! ");
            }

            return err;
        }
        /// <summary>
        /// 停止云台控制,摄像头控制
        /// </summary>
        /// <param name="cameraNo">摄像头编号</param>
        /// <param name="ptzCommandType">命令类型</param>
        /// <returns></returns>
        public SmcErr StopControlPtz(string cameraNo, PtzCommandType ptzCommandType)
        {
            NLogEx.LoggerEx logEx = new NLogEx.LoggerEx(log);
            logEx.Trace("Enter: T28181VideoMonitor.StopControlPtz({0}).", cameraNo);

            SmcErr err = new CgwError();

            //将ptz命令转换成T28181的命令
            T28181PTZCmd cmd = new T28181PTZCmd(ptzCommandType, 0);
            string ptzCmd = cmd.ToString();

            //控制权限级别设为1
            int result = sipStack.PtzControl(cameraNo, ptzCmd, "1");
            //如果为0,表示成功
            if (result == CgwConst.IVS_SDK_SUCCESS_TAG)
            {
                logEx.Info("Stop control ptz success.Camera No:{0}.", cameraNo);
            }
            else
            {
                //直接将IVS的错误码返回
                err.SetErrorNo(CgwError.STOP_CONTROL_PTZ_FAILED);
                logEx.Error("Stop control ptz failed.Camera No:{0}.Ivs sdk error code:{1}.", cameraNo, result);
                return err;
            }
            return err;
        }
        /// <summary>
        /// 停止预览
        /// </summary>
        /// <param name="cameraNo">摄像头编号</param>
        /// <returns>成功返回0,失败返回错误码</returns>
        public SmcErr StopReceiveVideo(string cameraNo)
        {
            NLogEx.LoggerEx logEx = new NLogEx.LoggerEx(log);
            logEx.Trace("Enter: T28181VideoMonitor.StopReceiveVideo({0}).", cameraNo);
            SmcErr err = new CgwError();
            //需要停止的预览句柄
            uint needToStopChannel = 0;
            if (this.handelOperateLock.TryEnterWriteLock(CgwConst.ENTER_LOCK_WAIT_TIME))
            {
                try
                {
                    if (this.cameraVideoChannelDic.ContainsKey(cameraNo))
                    {
                        needToStopChannel = this.cameraVideoChannelDic[cameraNo];
                        this.videoChannelDataSenderDic.Remove(needToStopChannel);
                        this.cameraVideoChannelDic.Remove(cameraNo);
                        //关闭rtp回调
                        rtpAdapter.ESDK_RTP_CloseChannel(needToStopChannel);
                    }
                    else
                    {
                        logEx.Warn("Stop Receive camera video data failed. Don't need to end the preview.Camera No:{0}.", cameraNo);
                        //如果预览句柄不存在,不需要处理,直接返回
                        return err;
                    }
                }
                catch (Exception ex)
                {
                    err.SetErrorNo(CgwError.STOP_RECEIVE_VIDEO_FAILED);
                    logEx.Error("Stop Receive camera video data failed.Execption message:{0}", ex.Message);
                    return err;
                }
                finally
                {
                    this.handelOperateLock.ExitWriteLock();
                }
            }

            //调用sdk的停止方法,放在handelOperateLock外面,防止长时间占用锁
            if (needToStopChannel != 0)
            {
                int result = sipStack.StopRecvStream(needToStopChannel);
                //如果不为0,表示预览失败
                if (result != CgwConst.IVS_SDK_SUCCESS_TAG)
                {
                    err.SetErrorNo(CgwError.STOP_RECEIVE_VIDEO_FAILED);
                    logEx.Error("Stop Receive camera video data failed. error code:{0}", result);
                    return err;
                }
                logEx.Info("Stop Receive camera video data success.Camera No:{0},Handle:{1}.", cameraNo, needToStopChannel);
            }

            return err;
        }
Example #10
0
        /// <summary>
        /// 开始云台控制,摄像头控制
        /// </summary>
        /// <param name="cameraNo">摄像头编号</param>
        /// <param name="ptzCommandType">命令类型</param>
        /// <param name="param">命令参数,速度或倍数</param>
        /// <returns></returns>
        public SmcErr StartControlPtz(string cameraNo, PtzCommandType ptzCommand, int param)
        {
            NLogEx.LoggerEx logEx = new NLogEx.LoggerEx(log);
            logEx.Trace("Enter: T28181VideoMonitor.StartControlPtz({0},{1},{2}).", cameraNo, ptzCommand, param);
            SmcErr err = new CgwError();

            //将ptz命令转换成T28181的命令
            T28181PTZCmd cmd = new T28181PTZCmd(ptzCommand, param);
            string ptzCmd = cmd.ToString();

            logEx.Trace("Call T28181VideoMonitor.StartPtzControl({0},{1},{2}).", cameraNo, Enum.GetName(typeof(PtzCommandType), (int)ptzCommand), param);
            //控制权限级别设为1
            int result = sipStack.PtzControl(cameraNo, ptzCmd, "1");

            //如果为0,表示成功
            if (result == CgwConst.IVS_SDK_SUCCESS_TAG)
            {
                logEx.Info("Start control ptz success.Camera No:{0}.", cameraNo);
            }
            else
            {
                err.SetErrorNo(CgwError.START_CONTROL_PTZ_FAILED);
                logEx.Error("Start control ptz failed.Camera No:{0}.T28181VideoMonitor error code:{1}.", cameraNo, result);
                return err;
            }

            return err;
        }
Example #11
0
        /// <summary>
        /// 启动摄像头预览
        /// </summary>
        /// <param name="cameraNo">摄像头编号</param>
        /// <returns></returns>
        public SmcErr StartReceiveVideo(string cameraNo)
        {
            NLogEx.LoggerEx logEx = new NLogEx.LoggerEx(log);
            logEx.Trace("Enter: T28181VideoMonitor.StartReceiveVideo({0}).", cameraNo);
            SmcErr err = new CgwError();

            //打开通道,开始接收实况RTP数据流
            UInt32 channel = sipStack.StartRecvStream(cameraNo, domain, sipPort);

            //如果为0,表示预览失败
            if (channel == CgwConst.T28181_ERROR_HANDLE)
            {
                err.SetErrorNo(CgwError.START_RECEIVE_VIDEO_FAILED);
                logEx.Error("Start Receive camera video data failed.Camera No:{0}.Handle:{1}.", cameraNo, channel);
                return err;
            }
            else
            {
                logEx.Info("Start Receive camera video data success.Camera No:{0},Handle:{1}.", cameraNo, channel);
            }

            //设置rtp解析回调函数
            rtpAdapter.ESDK_RTP_OpenChannel(frameDataCallBack, channel);

            //预览成功,需要停止原来的预览,并将预览句柄添加到缓存
            //需要停止的预览句柄
            UInt32 needToStopChannel = CgwConst.T28181_ERROR_HANDLE;
            if (this.handelOperateLock.TryEnterWriteLock(CgwConst.ENTER_LOCK_WAIT_TIME))
            {
                try
                {
                    //如果预览句柄已经存在,删除掉原来的句柄,用新的句柄替换
                    if (this.cameraVideoChannelDic.ContainsKey(cameraNo))
                    {
                        needToStopChannel = this.cameraVideoChannelDic[cameraNo];
                        this.videoChannelDataSenderDic.Remove(needToStopChannel);
                        this.cameraVideoChannelDic.Remove(cameraNo);
                        //关闭rtp回调
                        rtpAdapter.ESDK_RTP_CloseChannel(needToStopChannel);
                    }
                    this.cameraVideoChannelDic.Add(cameraNo, channel);
                    MediaDataSender mediaDataSender = new MediaDataSender(cameraNo, this.dataCallBack);
                    this.videoChannelDataSenderDic.Add(channel, mediaDataSender);
                }
                finally
                {
                    this.handelOperateLock.ExitWriteLock();
                }
            }

            //重新预览后,更新了预览句柄,需要将原来的预览停止,放在handelOperateLock外面,防止长时间占用锁
            if (needToStopChannel != CgwConst.T28181_ERROR_HANDLE)
            {
                int result = sipStack.StopRecvStream(needToStopChannel);
                //如果不为0,表示停止原来的预览失败,只记录日志,不返回错误,不设置错误码
                if (result != CgwConst.IVS_SDK_SUCCESS_TAG)
                {
                    err.SetErrorNo(CgwError.START_RECEIVE_VIDEO_FAILED);
                    logEx.Error("Get a new preview success. But stop old preview failed.CameraNo:{0},Ivs sdk error code:{0}", cameraNo, result);
                    return err;
                }
            }
            return err;
        }
Example #12
0
        /// <summary>
        /// 初始化T28181监控平台
        /// </summary>
        /// <param name="monitorConfigElement">监控平台配置节点</param>
        /// <returns></returns>
        public SmcErr Load(System.Xml.XmlElement monitorConfigElement)
        {
            NLogEx.LoggerEx logEx = new NLogEx.LoggerEx(log);
            logEx.Trace("Enter: T28181VideoMonitor.Load().");
            SmcErr err = new CgwError();

            try
            {
                //解析xml节点,获取所需参数
                string queryDeviceTimeOut = string.Empty;
                monitorId = CommonFunction.GetSingleNodeValue(monitorConfigElement, CgwConst.ID_TAG);
                domain = CommonFunction.GetSingleNodeValue(monitorConfigElement, CgwConst.IP_TAG);
                sipPort = CommonFunction.GetSingleNodeValue(monitorConfigElement, CgwConst.SIP_PORT);
                deviceID = CommonFunction.GetSingleNodeValue(monitorConfigElement, CgwConst.Device_ID);
                username = CommonFunction.GetSingleNodeValue(monitorConfigElement, CgwConst.USER_TAG);
                password = CommonFunction.GetSingleNodeValue(monitorConfigElement, CgwConst.PASSWORD_TAG);
                localPort = CommonFunction.GetSingleNodeValue(monitorConfigElement, CgwConst.LOCAL_PORT);
                queryDeviceTimeOut = CommonFunction.GetSingleNodeValue(monitorConfigElement, CgwConst.QueryDeviceTimeOut);

                //检测配置文件是否有错误
                int iSipPort = 0;
                bool bRet = int.TryParse(sipPort, out iSipPort);

                if (bRet == false)
                {
                    err.SetErrorNo(CgwError.MONITOR_CONFIG_FILE_INVALID);
                    logEx.Error("Load T28181 monitor failed.Execption sipPort:{0}.", sipPort);
                    return err;
                }

                int iLocalPort = 0;
                bRet = int.TryParse(localPort, out iLocalPort);

                if (bRet == false)
                {
                    err.SetErrorNo(CgwError.MONITOR_CONFIG_FILE_INVALID);
                    logEx.Error("Load T28181 monitor failed.Execption localPort:{0}.", localPort);
                    return err;
                }

                bRet = int.TryParse(queryDeviceTimeOut, out iQueryDeviceTimeOut);
                //转为毫秒
                iQueryDeviceTimeOut *= 1000;

                if (bRet == false)
                {
                    err.SetErrorNo(CgwError.MONITOR_CONFIG_FILE_INVALID);
                    logEx.Error("Load T28181 monitor failed.Execption QueryDeviceTimeOut:{0}.", iQueryDeviceTimeOut);
                    return err;
                }

                //开始连接、注册Sip服务器
                StartConnectRegisterSip(domain, iSipPort, iLocalPort, username, password);

                //开始查询设备列表
                Thread th = new Thread(new ThreadStart(()
                    =>
                    {
                         GetAllCamerasTimer(null, null);
                    }));
                th.Start();
                //启动定时器
                updateCameraTimer.Start();
            }
            catch (Exception e)
            {
                err.SetErrorNo(CgwError.MONITOR_CONFIG_FILE_INVALID);
                logEx.Error("Load T28181 monitor failed.Execption message:{0}.", e.Message);
                return err;
            }

            logEx.Info("Load T28181 monitor success.Monitor id:{0}.", this.monitorId);
            return err;
        }
Example #13
0
        /// <summary>
        /// 连接融合网关
        /// </summary>
        /// <param name="cgwPwd">连接字符串</param>
        /// <returns></returns>
        public SmcErr Connect(string cgwPwd)
        {
            SmcErr err = new CgwError();
            NLogEx.LoggerEx logEx = new NLogEx.LoggerEx(log);
            if (isLoadSuccess == false)
            {
                err.SetErrorNo(CgwError.ERR_CGW_IS_LOADING);
                return err;
            }
            //if (false == string.IsNullOrEmpty(cgwPwd))
            //{

                ////进行SHA256加密
                //string newPassword = CommonFunction.SHA256Encrypt(strPwd);
                //保存当前会话
                //if (newPassword == cgwPwd)
                //{
                    //获取SessionManage中Session个数
                    if (SessionManage.Instance().GetSessionsCount() == 0)
                    {
                        Guid sessionGuid = Guid.NewGuid();
                        //保存至CGW的session管理中
                        CgwSession CgwSession = new CgwSession(sessionGuid, OperationContext.Current.SessionId);

                        isChangeLic = false;
                        MessageProperties properties = OperationContext.Current.IncomingMessageProperties;   //获取传进的消息属性

                        RemoteEndpointMessageProperty endpoint = properties[RemoteEndpointMessageProperty.Name] as RemoteEndpointMessageProperty; //获取消息发送的远程终结点IP和端口
                        if (endpoint != null)
                        {
                            CgwConst.SmcIp = endpoint.Address; // 获取发送消息的客户端的 IP 地址。
                            logEx.Info("SMC Connect CgwService Successful,Current.SMC IP is : {0}", CgwConst.SmcIp);
                        }
                        else
                        {
                            logEx.Info("SMC Connect CgwService Successful,Current.SMC IP is  null.");
                        }
                    }
                    else
                    {
                        err.SetErrorNo(CgwError.ERR_CGW_BUSINESS_SESSION_COUNT_MAX);
                        logEx.Warn("Session Count is  Top Of Max number !");
                    }

                //}
                //else
                //{
                //    err.SetErrorNo(CgwError.ERR_CGW_BUSINESS_PASSWORD_INCORRECT);
                //    logEx.Error("Connect Password is Incorrect !");
                //}
            //}
            //else
            //{
            //    err.SetErrorNo(CgwError.ERR_CGW_BUSINESS_PASSWORD_NULL);
            //    logEx.Error("Connect Password is null !");
            //}
            return err;
        }
Example #14
0
        /// <summary>
        /// 分配监控通道
        /// </summary>
        public SmcErr UpdateMonitorChannel(List<ChannelInfo> channelInfoList)
        {
            SmcErr err = new CgwError();
            NLogEx.LoggerEx logEx = new NLogEx.LoggerEx(log);
            err = CheckSession();
            if (err.IsSuccess())
            {
                if (channelInfoList != null)
                {
                    err = MonitorChannelBll.Instance().AssignMonitorChannel(channelInfoList);

                }
                else
                {
                    err.SetErrorNo(CgwError.ERR_CGW_BUSINESS_CHANNELLIST_NULL);
                }

            }
            if (err.IsSuccess())
            {
                logEx.Info("SMC AssignMonitorChannel  Successful,Current SMC IP is : {0}", CgwConst.SmcIp);
            }
            else
            {
                logEx.Error("SMC AssignMonitorChannel failed,ErrNo :{0}", err.ErrNo);
            }
            return err;
        }
        /// <summary>
        /// 切换通道关联
        /// </summary>
        /// <param name="channelLabel">通道号码</param>
        /// <param name="cameraNo">摄像头编号</param>
        /// <returns>错误码</returns>
        public SmcErr SwitchChannelRelation(string channelLabel, string cameraNo)
        {
            SmcErr err = new CgwError();
            NLogEx.LoggerEx logEx = new NLogEx.LoggerEx(log);
            logEx.Info("SwitchChannelRelation start.");

            try
            {
                bool successed = this.monitorChannelRelationDicLocker.TryEnterReadLock(CgwConst.ENTER_LOCK_WAIT_TIME);
                // 申请互斥
                if (successed)
                {
                    try
                    {
                        if (!this.monitorChannelRelationDic.ContainsKey(channelLabel))
                        {
                            // 错误码 日志
                            logEx.Error("SwitchChannelRelation can't find channelLabel:{0}", channelLabel);
                            err.SetErrorNo(CgwError.ERR_CGW_CHANNEL_NOT_FIND_CHANNELNO);
                            return err;
                        }

                        // 如果通道没有入会,不允许关联摄像头
                        if (string.IsNullOrEmpty(this.monitorChannelRelationDic[channelLabel].ConfAccessCode))
                        {
                            // 错误码 日志
                            logEx.Error("SwitchChannelRelation channelNo:{0} confAccessCode is null", channelLabel);
                            err.SetErrorNo(CgwError.ERR_CGW_CHANNEL_NOT_IN_CONF);
                            return err;
                        }

                    }
                    finally
                    {
                        // 释放互斥量
                        this.monitorChannelRelationDicLocker.ExitReadLock();
                    }
                }
                else
                {
                    // 日志
                    logEx.Error("SwitchChannelRelation: Enter Write Lock Failed.WaitingReadCount:{0};WaitingWriteCount:{1}.", this.monitorChannelRelationDicLocker.WaitingReadCount, this.monitorChannelRelationDicLocker.WaitingWriteCount);
                    err.SetErrorNo(CgwError.ERR_CGW_CHANNEL_GET_LOCK_FAIL);
                }

                // 调用内部接口,切换通道视频
                err = this.SwitchChannelVideo(channelLabel, cameraNo);
                if (!err.IsSuccess())
                {
                    // 日志
                    this.PrintLog();
                    logEx.Error("SwitchChannelRelation SwitchChannelVideo channelNo:{0} cameraNo:{1} failed", channelLabel, cameraNo);
                    return err;
                }
            }
            catch (Exception ex)
            {
                // 日志
                logEx.Error(ex, "SwitchChannelRelation: Enter Write Lock Exception.");
                err.SetErrorNo(CgwError.ERR_CGW_CHANNEL_SERVICE_ADNORMAL);
            }

            // I帧重传
            this.MakeIFrame(channelLabel);

            this.PrintLog();

            // 成功日志
            logEx.Info("SwitchChannelRelation successfully,channelLabel:{0},cameraNo:{1}", channelLabel, cameraNo);

            return err;
        }
Example #16
0
        /// <summary>
        /// 注销T28181监控平台资源
        /// </summary>
        /// <returns></returns>
        public SmcErr Unload()
        {
            NLogEx.LoggerEx logEx = new NLogEx.LoggerEx(log);
            logEx.Trace("Enter: T28181IvsVideoMonitor.Unload().");
            SmcErr err = new CgwError();
            //停止定时器
            this.updateCameraTimer.Stop();

            int result = sipStack.SIP_SDK_UNREGISTER();
            //释放所有实况通道,释放NETSOURCE资源
            result += sipStack.IVS_NETSOURCE_UnInit();
            result += sipStack.SIP_SDK_UnInit();
            result += rtpAdapter.ESDK_RTP_UnInit();

            if (result == CgwConst.IVS_SDK_SUCCESS_TAG)
            {
                logEx.Info("Unload T28181video monitor success.Monitor id:{0}.", this.monitorId);
            }
            else
            {
                err.SetErrorNo(CgwError.MONITOR_UDLOAD_FAILED);
                logEx.Error("Unload T28181video monitor failed.Monitor id:{0}.", this.monitorId);
            }
            return err;
        }
        /// <summary>
        ///  同步通道信息 
        ///  将输入的通道信息更新到本地,本地存在但输入中没有的通道需要删除,本地没有而输入中有的通道需要添加
        ///  本地存在并且输入中也有的通道,也得判断会议号是否变化,有变化还得更新码流,删除/添加软终端呼叫通道等
        /// </summary>
        /// <param name="channelDic">通道标识与会议号字典</param>
        /// <returns>错误码</returns>
        public SmcErr SyncChannelInfo(ref List<ChannelInfo> channelInfoList, int maxChannelNum)
        {
            SmcErr err = new CgwError();
            Dictionary<string, MonitorChannelRelation> temp = null;   // 本地通道号码列表跟输入通道号码列表比较,本地通道号码列表需要删除部分
            List<ChannelInfo> addChannelInfoList = new List<ChannelInfo>();  // 本地通道号码列表跟输入通道号码列表比较,本地通道号码列表需要另外添加部分
            NLogEx.LoggerEx logEx = new NLogEx.LoggerEx(log);
            logEx.Info("SyncChannelInfo start.");

            if (null == channelInfoList || 0 == channelInfoList.Count || maxChannelNum < 0)
            {
                // 错误码 日志
                logEx.Error("SyncChannelInfo param error");
                err.SetErrorNo(CgwError.ERR_CGW_CHANNEL_INPUT_ERROR);
                return err;
            }

            // 根据license中最大可用通道数量,修改输入通道列表中各通道是否有效
            this.ChangeLicense(ref channelInfoList, maxChannelNum);

            try
            {
                bool successed = this.monitorChannelRelationDicLocker.TryEnterWriteLock(CgwConst.ENTER_LOCK_WAIT_TIME);
                // 申请互斥
                if (successed)
                {
                    try
                    {
                        // 区分需要删除的通道和需要添加的通道
                        temp = new Dictionary<string, MonitorChannelRelation>(this.monitorChannelRelationDic);
                        foreach (ChannelInfo item in channelInfoList)
                        {
                            if (this.monitorChannelRelationDic.ContainsKey(item.ChannelLabel))
                            {
                                // 同步通道会议信息
                                err = this.SyncChannelConfAccessCode(item.ChannelLabel, item.AccessCode, ChannelControlType.None);
                                if (!err.IsSuccess())
                                {
                                    logEx.Trace("SyncChannelInfo modify channelLabel:{0} failed, errNo={1}", item.ChannelLabel, err.ErrNo);
                                    return err;
                                }

                                // 修改license是否有效
                                if (null != this.monitorChannelRelationDic[item.ChannelLabel])
                                {
                                    this.monitorChannelRelationDic[item.ChannelLabel].IsValid = item.IsValid;
                                }

                                temp.Remove(item.ChannelLabel);
                            }
                            else
                            {
                                addChannelInfoList.Add(item);
                            }
                        }

                        // 删除通道
                        foreach (KeyValuePair<string, MonitorChannelRelation> item in temp)
                        {
                            // 设置会议号为空,同时删除通道关系字典中通道
                            err = this.SyncChannelConfAccessCode(item.Key, string.Empty, ChannelControlType.Remove);
                            if (!err.IsSuccess())
                            {
                                logEx.Error("SyncChannelInfo del channelLabel:{0} failed, errNo={1}", item.Key, err.ErrNo);
                                return err;
                            }
                        }

                        // 添加通道
                        foreach (ChannelInfo item in addChannelInfoList)
                        {
                            if (this.monitorChannelRelationDic.ContainsKey(item.ChannelLabel))
                            {
                                continue;
                            }

                            // 添加通道,同时设置通道的会议号
                            err = this.SyncChannelConfAccessCode(item.ChannelLabel, item.AccessCode, ChannelControlType.Add);
                            if (!err.IsSuccess())
                            {
                                logEx.Error("SyncChannelInfo add channelLabel:{0} failed, errNo={1}", item.ChannelLabel, err.ErrNo);
                                return err;
                            }

                            // 修改license是否有效
                            if (null != this.monitorChannelRelationDic[item.ChannelLabel])
                            {
                                this.monitorChannelRelationDic[item.ChannelLabel].IsValid = item.IsValid;
                            }
                        }

                        // 日志
                        string channellLog = "Log SyncChannelInfo result:";
                        foreach (KeyValuePair<string, MonitorChannelRelation> pair in this.monitorChannelRelationDic)
                        {
                            string name = string.Format("  ChannelLabel:{0},confAccessCode:{1}, cameraNo:{2}, isValid:{3};", pair.Value.Label, pair.Value.ConfAccessCode, pair.Value.CameraNo, pair.Value.IsValid);
                            channellLog += name;
                        }
                        logEx.Trace(channellLog);

                    }
                    finally
                    {
                        // 释放互斥量
                        this.monitorChannelRelationDicLocker.ExitWriteLock();
                    }
                }
                else
                {
                    // 日志
                    logEx.Error("SyncChannelInfo: Enert Write Lock Failed.WaitingReadCount:{0};WaitingWriteCount:{1}.", this.monitorChannelRelationDicLocker.WaitingReadCount, this.monitorChannelRelationDicLocker.WaitingWriteCount);
                    err.SetErrorNo(CgwError.ERR_CGW_CHANNEL_GET_LOCK_FAIL);
                }
            }
            catch (Exception ex)
            {
                // 日志
                logEx.Error(ex, "SyncChannelInfo: Enert Write Lock Exception.");
                err.SetErrorNo(CgwError.ERR_CGW_CHANNEL_SERVICE_ADNORMAL);
            }

            // 成功日志
            logEx.Info("SyncChannelInfo successfully");

            return err;
        }
        /// <summary>
        /// 停止摄像头的码流和音频流
        /// 同步通道会议信息调用,防止锁占用
        /// </summary>
        /// <param name="channelLabel"></param>
        /// <returns></returns>
        private SmcErr StopCameraRtpAudio(string channelLabel)
        {
            SmcErr err = new CgwError();
            NLogEx.LoggerEx logEx = new NLogEx.LoggerEx(log);
            // 判断监控通道是否存在
            if (!this.monitorChannelRelationDic.ContainsKey(channelLabel))
            {
                // 日志
                err.SetErrorNo(CgwError.ERR_CGW_BUSINESS_CHANNELNO_NULL);
                logEx.Trace("StopCameraRtpAudio can't find channelLabel:{0}", channelLabel);
                return err;
            }
            string oldCameraNo = this.monitorChannelRelationDic[channelLabel].CameraNo;
            if (!string.IsNullOrEmpty(oldCameraNo))
            {
                // 停止码流
                err = this.TryStopSendRtpData(oldCameraNo, channelLabel);
                if (!err.IsSuccess())
                {
                    logEx.Trace("StopCameraRtpAudio (channelLabel:{0},oldCameraNo:{1}) StopRtp failed,errNo={2}.", channelLabel, oldCameraNo, err.ErrNo);
                    return err;
                }

                // 关闭音频码流
                err = this.SetCameraAudio(channelLabel, oldCameraNo, false);
                if (!err.IsSuccess())
                {
                    logEx.Trace("StopCameraRtpAudio (channelLabel:{0},oldCameraNo:{1}) StartAudio failed,errNo={2}.", channelLabel, oldCameraNo, err.ErrNo);
                    return err;
                }

                this.monitorChannelRelationDic[channelLabel].CameraNo = null;

            }
            return err;
        }
        /// <summary>
        /// 获取跟channelLabel相同摄像头和会议号的通道列表
        /// </summary>
        /// <param name="channelLabel"></param>
        /// <param name="cameraNo"></param>
        /// <param name="channelLabelList"></param>
        /// <returns></returns>
        private SmcErr GetCameraRelaitonChannel(string channelLabel, string cameraNo, out List<string> channelLabelList)
        {
            SmcErr err = new CgwError();
            NLogEx.LoggerEx logEx = new NLogEx.LoggerEx(log);
            channelLabelList = new List<string>();
            string confAccessCode = string.Empty;

            // 查找对应的会议号
            if (this.monitorChannelRelationDic.ContainsKey(channelLabel))
            {
                if (this.monitorChannelRelationDic[channelLabel].CameraNo == cameraNo)
                {
                    confAccessCode = this.monitorChannelRelationDic[channelLabel].ConfAccessCode;
                }
                else
                {
                    err.SetErrorNo(CgwError.ERR_CGW_CHANNEL_NOT_FIND_CHANNELNO);
                    logEx.Trace("GetCameraRelaitonChannel can't find channelLabel:{0}, cameraNo={1}.", channelLabel, cameraNo);
                    return err;
                }
            }
            else
            {
                err.SetErrorNo(CgwError.ERR_CGW_CHANNEL_NOT_FIND_CHANNELNO);
                logEx.Trace("GetCameraRelaitonChannel can't find channelLabel:{0}, cameraNo={1}.", channelLabel, cameraNo);
                return err;
            }

            // 查找关联相同摄像头和相同会议号的通道列表
            foreach (KeyValuePair<string, MonitorChannelRelation> pair in this.monitorChannelRelationDic)
            {
                if (pair.Value.CameraNo == cameraNo && pair.Value.ConfAccessCode == confAccessCode)
                {
                    channelLabelList.Add(pair.Key);
                }
            }

            logEx.Trace("GetCameraRelaitonChannel get channellist channelLabel={0}, cameraNo={1}, count={2}", channelLabel, cameraNo, channelLabelList.Count);
            return err;
        }
        /// <summary>
        /// 切换视频码流 内部接口
        /// </summary>
        /// <param name="channelNo">通道号码</param>
        /// <param name="cameraNo">摄像头编号</param>
        private SmcErr SwitchChannelVideo(string channelLabel, string cameraNo)
        {
            SmcErr err = new CgwError();
            NLogEx.LoggerEx logEx = new NLogEx.LoggerEx(log);
            logEx.Trace("SwitchChannelVideo Start. input localCameraNo:{0} cameraNo:{1}", channelLabel, cameraNo);

            string oldCameraNo = null;
            if (this.monitorChannelRelationDicLocker.TryEnterReadLock(CgwConst.ENTER_LOCK_WAIT_TIME))
            {
                try
                {
                    // 判断监控通道是否存在
                    if (!this.monitorChannelRelationDic.ContainsKey(channelLabel))
                    {
                        // 日志
                        err.SetErrorNo(CgwError.ERR_CGW_BUSINESS_CHANNELNO_NULL);
                        logEx.Trace("SwitchChannelVideo can't find channelLabel:{0}", channelLabel);
                        return err;
                    }
                    oldCameraNo = this.monitorChannelRelationDic[channelLabel].CameraNo;
                }
                finally
                {
                    this.monitorChannelRelationDicLocker.ExitReadLock();
                }
            }
            else
            {
                err.SetErrorNo(CgwError.ERR_CGW_CHANNEL_GET_LOCK_FAIL);
                logEx.Error("SwitchChannelVideo: Enter Read Lock Failed.WaitingReadCount:{0};WaitingWriteCount:{1}.", this.monitorChannelRelationDicLocker.WaitingReadCount, this.monitorChannelRelationDicLocker.WaitingWriteCount);
                return err;
            }

            logEx.Trace("SwitchChannelVideo oldCameraNo:{0}",oldCameraNo);

            //2015/2/9 重起的摄像头,重新开始播放视频
            if (offLineCameras.Contains(cameraNo))
            {
                logEx.Trace("SwitchChannelVideo offLineCameras cameraNo:{0}",cameraNo);
                offLineCameras.Remove(cameraNo);

                //停止摄像头码流
                if (!string.IsNullOrEmpty(oldCameraNo))
                {
                    // 停止码流
                    err = this.TryStopSendRtpData(oldCameraNo, channelLabel);
                    if (!err.IsSuccess())//停止失败
                    {
                        //this.monitorChannelRelationDic[channelLabel].CameraNo = null;
                        logEx.Trace("SwitchChannelVideo offLineCameras stop cameraNo:{0} failed,errNo={1}", oldCameraNo, err.ErrNo);
                        //return err;
                    }
                }

                // 启动摄像头码流
                err = this.TryStartSendRtpData(cameraNo, channelLabel);
                if (!err.IsSuccess())
                {
                    //this.monitorChannelRelationDic[channelLabel].CameraNo = null;
                    logEx.Trace("SwitchChannelVideo offLineCameras start (oldCameraNo:{0},cameraNo:{1}) startRtp failed,errNo={2}.", oldCameraNo, cameraNo, err.ErrNo);
                    //return err;
                }
                //this.monitorChannelRelationDic[channelLabel].CameraNo = cameraNo;
            }
            else
            {
                if (string.IsNullOrEmpty(oldCameraNo))
                {
                    if (!string.IsNullOrEmpty(cameraNo))
                    {
                        // 启动摄像头码流
                        err = this.TryStartSendRtpData(cameraNo, channelLabel);
                        if (!err.IsSuccess())
                        {
                            logEx.Trace("SwitchChannelVideo (oldCameraNo:{0},cameraNo:{1}) startRtp failed,errNo={2}.", oldCameraNo, cameraNo, err.ErrNo);
                            return err;
                        }
                        //this.monitorChannelRelationDic[channelLabel].CameraNo = cameraNo;
                    }
                }
                else
                {
                    if (!string.IsNullOrEmpty(cameraNo))
                    {
                        if (cameraNo == oldCameraNo)
                        {
                            logEx.Trace("SwitchChannelVideo oldCameraNo equal CameraNo:{0}.", cameraNo);
                            return err;
                        }

                        // 停止码流
                        err = this.TryStopSendRtpData(oldCameraNo, channelLabel);
                        if (!err.IsSuccess())
                        {
                            logEx.Trace("SwitchChannelVideo (oldCameraNo:{0},cameraNo:{1}) stoprtp failed,errNo={2}.", oldCameraNo, cameraNo, err.ErrNo);
                            return err;
                        }

                        // 启动新摄像头码流
                        err = this.TryStartSendRtpData(cameraNo, channelLabel);
                        if (!err.IsSuccess())
                        {
                            // 原有摄像头编号要置为空,因为旧摄像头已经关闭,避免再次预览旧摄像头,以为还在开启
                            //this.monitorChannelRelationDic[channelLabel].CameraNo = null;
                            logEx.Trace("SwitchChannelVideo (oldCameraNo:{0},cameraNo:{1}) StartRtp failed,errNo={2}.", oldCameraNo, cameraNo, err.ErrNo);
                            //return err;
                        }
                        else
                        {
                            // 关闭音频码流
                            err = this.SetCameraAudio(channelLabel, oldCameraNo, false);
                            if (!err.IsSuccess())
                            {
                                logEx.Trace("SwitchChannelVideo (channelLabel:{0},oldCameraNo:{1},cameraNo:{2}) StartAudio failed,errNo={2}.", channelLabel, oldCameraNo, cameraNo, err.ErrNo);
                                return err;
                            }
                        }
                    }
                    else
                    {
                        // 停止码流
                        err = this.TryStopSendRtpData(oldCameraNo, channelLabel);
                        if (!err.IsSuccess())
                        {
                            logEx.Trace("SwitchChannelVideo (oldCameraNo:{0},cameraNo:{1}) StopRtp failed,errNo={2}.", oldCameraNo, cameraNo, err.ErrNo);
                            return err;
                        }

                        // 关闭音频码流
                        err = this.SetCameraAudio(channelLabel, oldCameraNo, false);
                        if (!err.IsSuccess())
                        {
                            logEx.Trace("SwitchChannelVideo (channelLabel:{0},oldCameraNo:{1},cameraNo:{2}) StartAudio failed,errNo={2}.", channelLabel, oldCameraNo, cameraNo, err.ErrNo);
                            return err;
                        }
                    }

                    //this.monitorChannelRelationDic[channelLabel].CameraNo = cameraNo;
                }
            }
            if (this.monitorChannelRelationDicLocker.TryEnterWriteLock(CgwConst.ENTER_LOCK_WAIT_TIME))
            {
                try
                {
                    if (err.IsSuccess())
                    {
                        this.monitorChannelRelationDic[channelLabel].CameraNo = cameraNo;
                    }
                    else
                    {
                        this.monitorChannelRelationDic[channelLabel].CameraNo = null;
                        return err;
                    }
                }
                finally
                {
                    this.monitorChannelRelationDicLocker.ExitWriteLock();
                }
            }
            else
            {
                err.SetErrorNo(CgwError.ERR_CGW_CHANNEL_GET_LOCK_FAIL);
                logEx.Error("SwitchChannelVideo: Enter Write Lock Failed.WaitingReadCount:{0};WaitingWriteCount:{1}.", this.monitorChannelRelationDicLocker.WaitingReadCount, this.monitorChannelRelationDicLocker.WaitingWriteCount);
                return err;
            }
            logEx.Trace("SwitchChannelVideo localCameraNo:{0} cameraNo:{1} successfully.", channelLabel, cameraNo);
            return err;
        }
Example #21
0
        /// <summary>
        /// 检查Session
        /// </summary>
        /// <returns></returns>
        private SmcErr CheckSession()
        {
            NLogEx.LoggerEx logEx = new NLogEx.LoggerEx(log);
            SmcErr err = new CgwError();
            CGWSession CgwSession = null;
            if (OperationContext.Current != null)
            {
                string strSessionId = OperationContext.Current.SessionId;
                err = SessionManage.Instance().GetSessionsBySessionId(strSessionId, out CgwSession);

                if (err.IsSuccess() == false || CgwSession == null)
                {
                    err.SetErrorNo(CgwError.ERR_CGW_BUSINESS_SESSION_NULL);
                }
                else
                {
                    //更新Session最后访问时间
                    CgwSession.LastVisitedTime = DateTime.Now;
                    logEx.Trace("Current SessionId is:{0}, LastVisitedTime is :{1}", strSessionId, CgwSession.LastVisitedTime.ToLongTimeString());
                }
            }
            else
            {
                err.SetErrorNo(CgwError.ERR_CGW_BUSINESS_CURRENTSESSION_NULL);
            }

            return err;
        }
        /// <summary>
        /// 分配通道
        /// 调度会议时,输入smc分配的通道标识和会议号
        /// 结束会议时,需要再次输入分配的通道标识,会议号设置为空
        /// </summary>
        /// <param name="channelInfoList">通道信息列表</param>
        /// <returns>错误码</returns>
        public SmcErr AssignChannel(List<ChannelInfo> channelInfoList)
        {
            SmcErr err = new CgwError();
            NLogEx.LoggerEx logEx = new NLogEx.LoggerEx(log);
            logEx.Info("AssignChannel start.");

            if (null == channelInfoList || 0 == channelInfoList.Count)
            {
                // 错误码 日志
                logEx.Error("AssignChannel param error");
                err.SetErrorNo(CgwError.ERR_CGW_CHANNEL_INPUT_ERROR);
                return err;
            }

            try
            {
                bool successed = this.monitorChannelRelationDicLocker.TryEnterWriteLock(CgwConst.ENTER_LOCK_WAIT_TIME);
                // 申请互斥
                if (successed)
                {
                    try
                    {
                        foreach (ChannelInfo item in channelInfoList)
                        {
                            // 存在任一在通道字典中找不到的通道号码,返回错误
                            if (!this.monitorChannelRelationDic.ContainsKey(item.ChannelLabel))
                            {
                                // 错误码 日志
                                logEx.Error("AssignChannel can't find channelLabel:{0}", item.ChannelLabel);
                                err.SetErrorNo(CgwError.ERR_CGW_CHANNEL_NOT_FIND_CHANNELNO);
                                return err;
                            }

                            // 存在任一license无效的通道号码,返回错误
                            if (false == this.monitorChannelRelationDic[item.ChannelLabel].IsValid)
                            {
                                // 错误码 日志
                                logEx.Error("AssignChannel channelLabel:{0} is inValid.", item.ChannelLabel);
                                err.SetErrorNo(CgwError.ERR_CGW_CHANNEL_CHANNEL_INVALID);
                                return err;
                            }
                        }

                        foreach (ChannelInfo item in channelInfoList)
                        {
                            // 设置通道会议号
                            err = this.SyncChannelConfAccessCode(item.ChannelLabel, item.AccessCode, ChannelControlType.None);
                            if (!err.IsSuccess())
                            {
                                logEx.Error("AssignChannel syncChannelConfAccessCode ChannelLabel:{0}, ConfAccessCode:{1} failed.", item.ChannelLabel, item.AccessCode);
                                return err;
                            }
                        }

                        // 日志
                        string channellLog = "Log AssignChannel result:";
                        foreach (KeyValuePair<string, MonitorChannelRelation> pair in this.monitorChannelRelationDic)
                        {
                            string name = string.Format("  channelLabel:{0},confAccessCode:{1}, cameraNo:{2}, isValid:{3};", pair.Value.Label, pair.Value.ConfAccessCode, pair.Value.CameraNo, pair.Value.IsValid);
                            channellLog += name;
                        }
                        logEx.Trace(channellLog);
                    }
                    finally
                    {
                        // 释放互斥量
                        this.monitorChannelRelationDicLocker.ExitWriteLock();
                    }
                }
                else
                {
                    // 日志
                    logEx.Error("AssignChannel: Enert Write Lock Failed.WaitingReadCount:{0};WaitingWriteCount:{1}.", this.monitorChannelRelationDicLocker.WaitingReadCount, this.monitorChannelRelationDicLocker.WaitingWriteCount);
                    err.SetErrorNo(CgwError.ERR_CGW_CHANNEL_GET_LOCK_FAIL);
                }
            }
            catch (Exception ex)
            {
                // 日志
                logEx.Error(ex, "AssignChannel: Enert Write Lock Exception.");
                err.SetErrorNo(CgwError.ERR_CGW_CHANNEL_SERVICE_ADNORMAL);
            }

            // 成功日志
            logEx.Info("AssignChannel successfully");

            return err;
        }
Example #23
0
        /// <summary>
        /// 连接融合网关
        /// </summary>
        /// <param name="password">连接字符串</param>
        /// <returns></returns>
        public SmcErr Connect(string password)
        {
            SmcErr err = new CgwError();
            NLogEx.LoggerEx logEx = new NLogEx.LoggerEx(log);
            if (false == string.IsNullOrEmpty(password))
            {
                //获取后台密码字符串
                string s = CommonFunction.GetAppSetting("PassWord");
                //进行SHA256加密
                string newPassword = CommonFunction.SHA256Encrypt(s);
                //保存当前会话
                if (newPassword == password)
                {
                    //获取SessionManage中Session个数
                    if (SessionManage.Instance().GetSessionsCount() == 0)
                    {
                        Guid sessionGuid = Guid.NewGuid();

                        //保存至CGW的session管理中
                        CGWSession CgwSession = new CGWSession(sessionGuid, OperationContext.Current.SessionId);
                        logEx.Trace("Connect Successful,Current.SessionId is : ", OperationContext.Current.SessionId);
                    }
                    else
                    {
                        err.SetErrorNo(CgwError.ERR_CGW_BUSINESS_SESSION_COUNT_MAX);
                        logEx.Warn("Session Count is  Top Of Max number !");
                    }

                }
                else
                {
                    err.SetErrorNo(CgwError.ERR_CGW_BUSINESS_PASSWORD_INCORRECT);
                    logEx.Error("Connect Password is Incorrect !");
                }
            }
            else
            {
                err.SetErrorNo(CgwError.ERR_CGW_BUSINESS_PASSWORD_NULL);
                logEx.Error("Connect Password is null !");
            }
            return err;
        }
Example #24
0
        /// <summary>
        /// 软终端初始化
        /// </summary>
        /// <param name="addr"></param>
        /// <returns></returns>
        public SmcErr Init(InitSotParam param)
        {
            SmcErr err = new CgwError();
            NLogEx.LoggerEx logEx = new NLogEx.LoggerEx(log);

            try
            {
                SoftTerminalCallback handler = new SoftTerminalCallback();
                handler.NlogHandler = new NLogCallback(this.WriteLog);
                handler.IFrameHandler = this.makeIFrameCallback;
                handler.errReportHandler = this.errReportCallback;
                bool isSuccess = this.softTerminalAdapter.RegistSotCallback(handler);
                if (!isSuccess)
                {
                    logEx.Trace("Init Regist callback failed.");
                    err.SetErrorNo(CgwError.ERR_CGW_CHANNEL_SOT_REGIST_CALLBACK_FAIL);
                    return err;
                }

                err = this.softTerminalAdapter.Init(param);
                if (!err.IsSuccess())
                {
                    logEx.Trace("Init failed.");
                    return err;
                }
            }
            catch (System.Exception ex)
            {
                logEx.Error(ex, "Init Exception.");
            }

            logEx.Trace("Init successfully.");
            return err;
        }