/// <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="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; }
/// <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> /// 查询Lisence控制项(暂无) /// </summary> public SmcErr QueryLisence(out int numLisence) { SmcErr err = new CgwError(); numLisence = 0; err = CheckSession(); return err; }
/// <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> /// 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>] 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; }
/// <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> /// 切换视频码流 内部接口 /// </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; }
/// <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="channelLabel"></param> /// <param name="cameraNo"></param> /// <param name="isOn"></param> /// <returns></returns> private SmcErr SetCameraAudio(string channelLabel, string cameraNo, bool isOn) { SmcErr err = new CgwError(); NLogEx.LoggerEx logEx = new NLogEx.LoggerEx(log); //List<string> channelLabelList = null; logEx.Trace("SetCameraAudio,channelLabel:{0},cameraNo:{1},isOn:{2}",channelLabel,cameraNo,isOn); //注销代码,默认该摄像头的所有channelLabel的通道列表 by zWX231378 2015/7/13(对SetMic接口会有影响,因暂不支持音频,不修改) //// 获取跟channelLabel相同摄像头和会议号的通道列表 //err = GetCameraRelaitonChannel(channelLabel, cameraNo, out channelLabelList); //if (!err.IsSuccess()) //{ // logEx.Trace("SetCameraAudio GetCameraRelaitonChannel failed, errNo={0}.", err.ErrNo); //} if (true == isOn) { this.TryStartSendAudio(channelLabel, cameraNo); } else { //this.TryStopSendAudio(channelLabelList, cameraNo); this.TryStopSendAudio(channelLabel, cameraNo); } // 成功日志 logEx.Trace("SetCameraAudio successfully,channelLabel:{0},cameraNo:{1}, isOn={2}.", channelLabel, cameraNo, isOn); 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; }
/// <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></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; }
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."); }
/// <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; }
/// <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="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> /// 断开融合网关 /// </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> /// 尝试启动摄像头码流 /// 如果关联摄像头通道个数大于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> public SmcErr MuteCamera() { SmcErr err = new CgwError(); err = CheckSession(); if (err.IsSuccess()) { } 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> /// 获取监控设备列表 /// </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; }
/// <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); } } } }
/// <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; }
/// <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> /// 检查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> /// 同步通道信息 /// 将输入的通道信息更新到本地,本地存在但输入中没有的通道需要删除,本地没有而输入中有的通道需要添加 /// 本地存在并且输入中也有的通道,也得判断会议号是否变化,有变化还得更新码流,删除/添加软终端呼叫通道等 /// </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="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; }
/// <summary> /// 设置扬声器状态(暂不支持) /// </summary> /// <param name="cameraNo"></param> /// <param name="isOn">扬声器是否开启</param> /// <returns></returns> public SmcErr SetSpeaker(string cameraNo, bool isOn) { SmcErr err = new CgwError(); return err; }