/// <summary> /// 将ChannelEncoder.xml转换成AVEncoderInfoDto 字典 /// </summary> /// <returns></returns> private IDictionary <int, AVEncoderInfoDto> GetXMLChannelEncoderList() { IDictionary <int, AVEncoderInfoDto> avEncoderInfo = new Dictionary <int, AVEncoderInfoDto>(); string xmlPath = AppDomain.CurrentDomain.BaseDirectory; string xmlName = "ChannlEncoder.xml"; string fullPath = xmlPath + "\\" + xmlName; XmlDocument xmlDoc = new XmlDocument(); xmlDoc.Load(fullPath); XmlNodeList nodeList = xmlDoc.SelectSingleNode("ChannlEncoder").ChildNodes; foreach (XmlNode xn in nodeList) { AVEncoderInfoDto avInfo = new AVEncoderInfoDto(); XmlElement xe = (XmlElement)xn; string streamType = xe.Attributes["StreamType"].Value; int subStream = 0; int.TryParse(streamType, out subStream); XmlNodeList resultList = xe.ChildNodes; if (resultList != null && resultList.Count == 5) { XmlElement resolution = (XmlElement)resultList[0]; XmlElement frameRate = (XmlElement)resultList[1]; XmlElement bitrateMode = (XmlElement)resultList[2]; XmlElement bitrate = (XmlElement)resultList[3]; XmlElement iFrameInterval = (XmlElement)resultList[4]; byte btRes; byte.TryParse(resolution.InnerText.Trim(), out btRes); avInfo.Resolution = btRes; byte btFra; byte.TryParse(frameRate.InnerText.Trim(), out btFra); avInfo.FrameRate = btFra; byte btMode; byte.TryParse(bitrateMode.InnerText.Trim(), out btMode); avInfo.BitrateMode = btMode; byte btIFr; byte.TryParse(iFrameInterval.InnerText.Trim(), out btIFr); avInfo.IFrameInterval = btIFr; uint uiBit; uint.TryParse(bitrate.InnerText.Trim(), out uiBit); avInfo.Bitrate = uiBit; avEncoderInfo.Add(subStream, avInfo); } } return(avEncoderInfo); }
/// <summary> /// 设置通道码流 /// </summary> /// <param name="channelId">通道id</param> /// <param name="streamType">码流类型</param> /// <param name="customerToken">用户token</param> /// <returns></returns> public ResponseBaseDto UpdateChannelEncoderInfo(int channelId, int streamType, string customerToken) { ResponseBaseDto dto = new ResponseBaseDto(); UserTokenCache utc = UserTokenCache.GetInstance(); OperaterLog oLog = new OperaterLog(); TokenCacheProperty tcp = new TokenCacheProperty(); oLog.Action = "设置通道码流"; try { if (utc.IsValid(customerToken) == false) { dto.Code = (int)CodeEnum.ServerNoToken; dto.Message = "用户token已失效,请重新登录后继续"; return(dto); } dto = bllHelper.CheckCustomer(dto, customerToken, ref tcp); if (dto.Code != 0) { oLog.TargetType = (int)OperaterLogEnum.Channel; oLog.Remarks = dto.Message; oLog.Result = dto.Code; bllHelper.AddOperaterLog(oLog, tcp); return(dto); } else { IList <Channel> channelFlag = channelServer.SelectChannelByChannelId(new Channel() { ChannelId = channelId }); oLog.TargetId = channelId; if (channelFlag == null) { dto.Code = (int)CodeEnum.NoHardWare; dto.Message = "需要修改的通道不存在"; } else if (streamType == 0) { dto.Code = (int)CodeEnum.NoHardWare; dto.Message = "未选中码流类型"; } else { try { //获取已预制的码流配置 IDictionary <int, AVEncoderInfoDto> avEncoderInfoList = GetXMLChannelEncoderList(); AVEncoderInfoDto enCoderInfo = avEncoderInfoList[streamType]; //调用BP4Server 设置码流 Bsr.ServiceProxy.Utils.ServiceFactory serviceFactory = new ServiceProxy.Utils.ServiceFactory(); var seviceAddr = bllHelper.GetServerModelStr(); serviceFactory.GetProxy <ICamera>(new Uri(seviceAddr)).Use( p => { if (streamType == 1) { //主码流 p.UpdateEncoderInfo(channelFlag[0].BPServerChannelId, (byte)(1), enCoderInfo); } else if (streamType == 2 || streamType == 3) { //选择码流类型(streamType)在BP4Server中 2和3都属于子码流 p.UpdateEncoderInfo(channelFlag[0].BPServerChannelId, (byte)(1 << 1), enCoderInfo); } else { //第3码流 p.UpdateEncoderInfo(channelFlag[0].BPServerChannelId, (byte)(1 << 2), enCoderInfo); } }); } catch (Exception ex) { dto.Code = (int)CodeEnum.ApplicationErr; dto.Message = "通道所属设备已离线!离线状态无法修改通道码流"; myLog.ErrorFormat("UpdateChannelEncoderInfo(BP4Server设备已离线)通道Id:{0}", ex, channelId); return(dto); } } }/*end if(utc.IsValid(customerToken) == false)*/ } catch (Exception ex) { dto.Code = (int)CodeEnum.ApplicationErr; dto.Message = "网络异常,请刷新页面后继续"; myLog.WarnFormat("UpdateChannelEncoderInfo方法异常,用户Id:{0},通道Id:{1}", ex, tcp.CustomerId, channelId); } oLog.TargetType = (int)OperaterLogEnum.Channel; oLog.Remarks = dto.Message; oLog.Result = dto.Code; bllHelper.AddOperaterLog(oLog, tcp); return(dto); }