Exemple #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>
        /// 切换通道关联
        /// </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;
        }
        /// <summary>
        /// 清除管道数据
        /// </summary>
        public void StopChannelData()
        {
            NLogEx.LoggerEx logEx = new NLogEx.LoggerEx(log);
            SmcErr err = new CgwError();

            logEx.Trace("start StopChannelData");

            //copy 一份,防止长时间占用锁
            Dictionary<string, MonitorChannelRelation> monitorChannelRelationDicTemp = null;
            try
            {
                monitorChannelRelationDicTemp = new Dictionary<string, MonitorChannelRelation>(monitorChannelRelationDic);
            }
            catch (Exception e)
            {
                logEx.Error("StopChannelData.Execption message:{0}", e.Message);
            }

            if (monitorChannelRelationDicTemp == null)
            {
                //记录日志,获取*监控平台的摄像头列表失败
                logEx.Error("stopChannelVideo failed.No any monitorChannelRelationDic.");
            }
            //循环通道关系字典
            foreach (KeyValuePair<string, MonitorChannelRelation> monitorChannelRelation in monitorChannelRelationDicTemp)
            {
                ////2015/2/13 待测试,判断方式不正确
                if (monitorChannelRelation.Value.IsValid && !string.IsNullOrEmpty(monitorChannelRelation.Value.ConfAccessCode) && !string.IsNullOrEmpty(monitorChannelRelation.Value.CameraNo))
                //if (monitorChannelRelation.Value.IsValid && monitorChannelRelation.Value.ConfAccessCode != "" && monitorChannelRelation.Value.CameraNo != "")
                {
                    string cameraCode = monitorChannelRelation.Value.CameraNo;
                    string channelLabel = monitorChannelRelation.Value.Label;
                    // 停止码流
                    SmcErr errs = this.TryStopSendRtpData(cameraCode, channelLabel);
                    if (!errs.IsSuccess())
                    {
                        logEx.Trace("stopChannelVideo cameraNo:{0} stoprtp failed,errNo={1}.", cameraCode, err.ErrNo);
                    }
                    else
                    {
                        logEx.Trace("stopChannelVideo cameraNo:{0} stoprtp success ", cameraCode);
                    }

                    // 关闭音频码流
                    errs = this.SetCameraAudio(channelLabel, cameraCode, false);
                    if (!err.IsSuccess())
                    {
                        logEx.Trace("stopChannelVideo channelLabel:{0},cameraNo:{1} StartAudio failed,errNo={2}.", channelLabel, cameraCode, err.ErrNo);
                    }
                    else
                    {
                        logEx.Trace("stopChannelVideo cameraNo:{0} stoprtp success ", cameraCode);
                    }
                }
            }
        }
Exemple #4
0
 /// <summary>
 /// 获取监控摄像头列表刷新状态,返回结果为0是表示刷新完毕,为1是刷新操作中。当查询刷新状态为0时,可调用获取监控摄像头列表接口,获取刷新后监控摄像头列表
 /// </summary>
 /// <param name="refreshStatus"></param>
 /// <returns></returns>
 public SmcErr GetRefreshStatus(out SmcErr refreshStatus)
 {
     NLogEx.LoggerEx logEx = new NLogEx.LoggerEx(log);
     logEx.Trace("Enter: CgwService.GetRefreshStatus");
     refreshStatus = new SmcErr();
     refreshStatus.ErrNo = CgwError.ERR_DEVICE_LIST_REFRESH_STATUS_END;
     SmcErr err = new CgwError();
     err = CheckSession();
     if (err.IsSuccess())
     {
         err = MonitorChannelBll.Instance().GetRefreshStatus(out refreshStatus);
     }
     else
     {
         refreshStatus.ErrNo = CgwError.ERR_DEVICE_LIST_REFRESH_STATUS_FAILED;
     }
     if (err.IsSuccess())
     {
         logEx.Info("SMC GetRefreshStatus Success,Current SMC IP is : {0}, refreshStatus : {1}", CgwConst.SmcIp,refreshStatus.ErrNo);
     }
     else
     {
         logEx.Error("SMC GetRefreshStatus Failed,ErrNo :{0}", err.ErrNo);
     }
     return err;
 }
Exemple #5
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;
        }
Exemple #6
0
 /// <summary>
 /// 关闭PTZ操作
 /// </summary>
 /// <param name="Camerano">摄像头</param>
 /// <returns></returns>
 public SmcErr StopPTZ(string Camerano)
 {
     SmcErr err = new CgwError();
     NLogEx.LoggerEx logEx = new NLogEx.LoggerEx(log);
     err = CheckSession();
     if (err.IsSuccess())
     {
         err = MonitorChannelBll.Instance().StopPTZ(Camerano);
     }
     if (err.IsSuccess())
     {
         logEx.Trace("StopPTZ Successful");
     }
     else
     {
         logEx.Error("StopPTZ failed,ErrNo :{0}", err.ErrNo);
     }
     return err;
 }
Exemple #7
0
 /// <summary>
 /// 获取监控设备列表
 /// </summary>
 /// <param name="CameraInfoList">摄像头基本信息</param>
 /// <param name="CameraGroupList">组基本信息</param>
 /// <param name="nodeRelationList">所属分组关系信息</param>
 /// <returns></returns>
 public SmcErr QueryMonitorCamera(out List<Camera> CameraInfoList, out List<CameraGroup> CameraGroupList, out List<NodeRelation> nodeRelationList)
 {
     SmcErr err = new CgwError();
     NLogEx.LoggerEx logEx = new NLogEx.LoggerEx(log);
     CameraInfoList = null;
     CameraGroupList = null;
     nodeRelationList = null;
     err = CheckSession();
     if (err.IsSuccess())
     {
         err = MonitorChannelBll.Instance().QueryMonitorCamera(out CameraInfoList, out CameraGroupList, out nodeRelationList);
     }
     if (err.IsSuccess())
     {
         logEx.Trace("SyncMonitorChannel Successful");
     }
     else
     {
         logEx.Error("SyncMonitorChannel failed,ErrNo :{0}", err.ErrNo);
     }
     return err;
 }
Exemple #8
0
 /// <summary>
 /// 保持连接
 /// </summary>]
 public SmcErr KeepAliver()
 {
     SmcErr err = new CgwError();
     NLogEx.LoggerEx logEx = new NLogEx.LoggerEx(log);
     err = CheckSession();
     if (err.IsSuccess())
     {
         logEx.Trace("KeepAlive Successful");
     }
     else
     {
         logEx.Error("KeepAlive failed,ErrNo :{0}",err.ErrNo);
     }
     return err;
 }
Exemple #9
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;
        }
Exemple #10
0
 /// <summary>
 /// 关闭PTZ操作
 /// </summary>
 /// <param name="Camerano">摄像头</param>
 /// <returns></returns>
 public SmcErr StopControlPtz(string cameraNo, PtzCommandType ptzCommandType)
 {
     SmcErr err = new CgwError();
     NLogEx.LoggerEx logEx = new NLogEx.LoggerEx(log);
     err = CheckSession();
     if (err.IsSuccess())
     {
         err = MonitorChannelBll.Instance().StopControlPtz(cameraNo, ptzCommandType);
     }
     if (err.IsSuccess())
     {
         logEx.Info("SMC StopPTZ  Successful,Current SMC IP is : {0}", CgwConst.SmcIp);
     }
     else
     {
         logEx.Error("SMC StopPTZ failed,ErrNo :{0}", err.ErrNo);
     }
     return err;
 }
Exemple #11
0
 /// <summary>
 /// 设置扬声器
 /// </summary>
 /// <param name="cameraNo"></param>
 /// <param name="isOn"></param>
 /// <returns></returns>
 public SmcErr SetSpeaker(string channelLabel, string cameraNo, bool isOn)
 {
     SmcErr err = new CgwError();
     err = CheckSession();
     NLogEx.LoggerEx logEx = new NLogEx.LoggerEx(log);
     if (err.IsSuccess())
     {
         err = MonitorChannelBll.Instance().SetSpeaker(channelLabel, cameraNo, isOn);
     }
     if (err.IsSuccess())
     {
         logEx.Info("SMC StartControlPtz  Successful,Current SMC IP is : {0}", CgwConst.SmcIp);
     }
     else
     {
         logEx.Error("SMC StartControlPtz failed,ErrNo :{0}", err.ErrNo);
     }
     return err;
 }
Exemple #12
0
        /// <summary>
        /// 刷新监控摄像头列表
        /// </summary>
        /// <returns></returns>
        public SmcErr RefreshMonitorCamera()
        {
            NLogEx.LoggerEx logEx = new NLogEx.LoggerEx(log);
            logEx.Trace("Enter: CgwService.RefreshMonitorCamera");

            SmcErr err = new CgwError();
            err = CheckSession();
            if (err.IsSuccess())
            {
                err = MonitorChannelBll.Instance().RefreshMonitorCamera();
            }
            if (err.IsSuccess())
            {
                logEx.Info("SMC RefreshMonitorCamera  Successful,Current SMC IP is : {0}", CgwConst.SmcIp);
            }
            else
            {
                logEx.Error("SMC RefreshMonitorCamera failed,ErrNo :{0}", err.ErrNo);
            }

            return err;
        }
Exemple #13
0
 /// <summary>
 /// 获取监控设备列表
 /// </summary>
 /// <param name="CameraInfoList">摄像头基本信息</param>
 /// <param name="CameraGroupList">组基本信息</param>
 /// <param name="nodeRelationList">所属分组关系信息</param>
 /// <returns></returns>
 public SmcErr QueryMonitorCamera(PlatformType platformType, PageParam pageParam, out List<Camera> cameraInfoList, out List<CameraGroup> cameraGroupList, out List<NodeRelation> nodeRelationList, out PagesInfo pagesInfo)
 {
     SmcErr err = new CgwError();
     NLogEx.LoggerEx logEx = new NLogEx.LoggerEx(log);
     cameraInfoList = null;
     cameraGroupList = null;
     nodeRelationList = null;
     pagesInfo = null;
     err = CheckSession();
     if (err.IsSuccess())
     {
         err = MonitorChannelBll.Instance().QueryMonitorCamera(platformType, pageParam, out cameraInfoList, out cameraGroupList, out nodeRelationList, out pagesInfo);
     }
     if (err.IsSuccess())
     {
         logEx.Info("SMC QueryMonitorCamera  Successful,Current SMC IP is : {0}", CgwConst.SmcIp);
     }
     else
     {
         logEx.Error("SMC QueryMonitorCamera failed,ErrNo :{0}", err.ErrNo);
     }
     return err;
 }
Exemple #14
0
        /// <summary>
        /// 导入网关license文件
        /// </summary>
        /// <param name="license"></param>
        /// <returns></returns>
        public SmcErr ImportCGWLicense(string license)
        {
            NLogEx.LoggerEx logEx = new NLogEx.LoggerEx(log);
            logEx.Trace("Enter: CgwService.ImportCGWLicense");
            SmcErr err = new CgwError();

            err = CheckSession();
            if (err.IsSuccess())
            {
                err = MonitorChannelBll.Instance().ImportCGWLicense(license);
            }
            if (err.IsSuccess())
            {
                logEx.Info("SMC ImportCGWLicense  Successful,Current SMC IP is : {0}", CgwConst.SmcIp);
            }
            else
            {
                logEx.Error("SMC ImportCGWLicense failed,ErrNo :{0}", err.ErrNo);
            }
            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>
        /// I帧重传
        /// 参数label,由软终端回调的是code,通道管理调用的是channelLabel
        /// </summary>
        /// <param name="channelNo">通道标识或者code</param>
        /// <returns>错误码</returns>
        private uint MakeIFrame(string label)
        {
            SmcErr err = new CgwError();
            string channelLabel = string.Empty;
            string cameraNo = string.Empty;
            NLogEx.LoggerEx logEx = new NLogEx.LoggerEx(log);
            logEx.Trace("MakeIFrame start. label={0}", label);

            // 判断输入号码是否为空
            if (string.IsNullOrEmpty(label))
            {
                // 错误码 日志
                logEx.Trace("MakeIFrame param error");
                return 0;
            }

            try
            {
                bool successed = this.monitorChannelRelationDicLocker.TryEnterReadLock(CgwConst.ENTER_LOCK_WAIT_TIME);
                // 申请互斥
                if (successed)
                {
                    try
                    {
                        foreach (KeyValuePair<string, MonitorChannelRelation> pair in this.monitorChannelRelationDic)
                        {
                            if (pair.Key.IndexOf(label) == 0)
                            {
                                channelLabel = pair.Key;
                                break;
                            }
                        }

                        if (string.IsNullOrEmpty(channelLabel))
                        {
                            // 错误码 日志
                            logEx.Trace("MakeIFrame can't find label:{0}", label);
                            return 0;
                        }

                        cameraNo = this.monitorChannelRelationDic[channelLabel].CameraNo;
                    }
                    finally
                    {
                        // 释放互斥量
                        this.monitorChannelRelationDicLocker.ExitReadLock();
                    }
                }
                else
                {
                    // 日志
                    logEx.Error("MakeIFrame: Enert Read Lock Failed.WaitingReadCount:{0};WaitingWriteCount:{1}.", this.monitorChannelRelationDicLocker.WaitingReadCount, this.monitorChannelRelationDicLocker.WaitingWriteCount);
                    return 0;
                }
            }
            catch (Exception ex)
            {
                // 日志
                logEx.Error(ex, "MakeIFrame: Enter Read Lock Exception.");
                return 0;
            }

            // 调用平台管理接口
            err = CgwMonitorManageAdapter.Instance().MakeIFrame(cameraNo);
            if (!err.IsSuccess())
            {
                logEx.Trace("MakeIFrame cameraNo:{0} failed errNo={1}.", cameraNo, err.ErrNo);
            }

            // 成功日志
            logEx.Trace("MakeIFrame channelLabel={0} cameraNo={1} successfully", channelLabel, cameraNo);

            return 1;
        }
        /// <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;
        }
Exemple #18
0
        /// <summary>
        /// 摄像头闭音(暂无)
        /// </summary>
        public SmcErr MuteCamera()
        {
            SmcErr err = new CgwError();
            err = CheckSession();
            if (err.IsSuccess())
            {

            }
            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;
        }
Exemple #20
0
 /// <summary>
 /// 开始PTZ操作
 /// </summary>
 /// <param name="cameraNo">摄像头NO</param>
 /// <param name="ptzCommand">操作类型</param>
 /// <param name="param">命令参数</param>
 /// <returns></returns>
 public SmcErr StartControlPtz(string cameraNo, PtzCommandType ptzCommand, int param)
 {
     SmcErr err = new CgwError();
     err = CheckSession();
     NLogEx.LoggerEx logEx = new NLogEx.LoggerEx(log);
     if (err.IsSuccess())
     {
         err = MonitorChannelBll.Instance().StartControlPtz(cameraNo, ptzCommand, param);
     }
     if (err.IsSuccess())
     {
         logEx.Trace("StartControlPtz Successful");
     }
     else
     {
         logEx.Error("StartControlPtz failed,ErrNo :{0}", err.ErrNo);
     }
     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;
        }
Exemple #22
0
        /// <summary>
        /// 设置监控通道视频源
        /// </summary>
        /// <param name="channelLabel">通道label</param>
        /// <param name="cameraNo">摄像头NO</param>
        /// <returns></returns>
        public SmcErr SwitchChannelVideoSource(string channelLabel, string cameraNo)
        {
            SmcErr err = new CgwError();
            NLogEx.LoggerEx logEx = new NLogEx.LoggerEx(log);
            err = CheckSession();
            if (err.IsSuccess())
            {
                err = MonitorChannelBll.Instance().SwitchChannelVideoSource(channelLabel, cameraNo);

            }
            if (err.IsSuccess())
            {
                logEx.Trace("SwitchChannelVideoSource Successful");
            }
            else
            {
                logEx.Error("SwitchChannelVideoSource failed,ErrNo :{0}", err.ErrNo);
            }
            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;
        }
        /// <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="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;
        }