//录播文件十六进制转换 public WaveData hexadecimalFileSerialize(WaveData data) { for (int i = 0; i < data.CHANNEL_DATA.Count; i++) { ChannelDataGroup gt = data.CHANNEL_DATA[i]; for (int j = 0; j < gt.channelDatas.Count; j++) { ChannelData cd = gt.channelDatas[j]; int chanelDataMoving = 0; List<int> hexadecimalFormatData = new List<int>(); while (chanelDataMoving < cd.POINT_DATA.Length) { byte[] needFormatData = cd.POINT_DATA.Skip(chanelDataMoving).Take(2).ToArray(); short s = 0; //一个16位整形变量,初值为 0000 0000 0000 0000 s = (short)(s ^ needFormatData[1]); //将b1赋给s的低8位 s = (short)(s << 8); //s的低8位移动到高8位 s = (short)(s ^ needFormatData[0]); hexadecimalFormatData.Add(s); chanelDataMoving += 2; } gt.channelDatas[j].HEX_POINT_DATA = hexadecimalFormatData.ToArray(); gt.channelDatas[j].HEX_POINT_DATA_LENGTH = cd.HEX_POINT_DATA.Length; } } return data; }
//录播文件通道数据二进制解压缩 private List<ChannelDataGroup> binaryFormatChannelData(List<object> pointDataGroups) { List<ChannelDataGroup> cgl = new List<ChannelDataGroup>(); foreach (object item in pointDataGroups) { ChannelDataGroup cg = new ChannelDataGroup(); int channel_data_moving = 0; byte[] channelData = (byte[])item; cg.channelDatas = new List<ChannelData>(); for (int i = 0; i <= 1; i++) { ChannelData cd = new ChannelData(); cd.DATA_WIDTH = channelData[0 + channel_data_moving]; cd.COMPRESS_MARK = channelData[1 + channel_data_moving]; cd.DATA_LENGTH = (i == 0) ? CHANNEL_DATA_GROUP_1_LENGTH : CHANNEL_DATA_GROUP_2_LENGTH; byte[] POINT_DATA = new byte[cd.DATA_LENGTH]; POINT_DATA = channelData.Skip(4 + channel_data_moving).Take(cd.DATA_LENGTH).ToArray(); if (cd.DATA_WIDTH == 0xff) { cd.POINT_DATA = POINT_DATA; cd.DATA_LENGTH_BYTE = new byte[] { Convert.ToByte(cd.DATA_LENGTH & 0xff), Convert.ToByte(cd.DATA_LENGTH >> 8) }; } else { List<byte> formatedDataList = new List<byte>(); int pointDataMoving = 0; while (pointDataMoving < cd.DATA_LENGTH) { byte[] needFormatData = POINT_DATA.Skip(pointDataMoving).Take(3).ToArray(); byte[] formatedData = binaryFormatPointData(needFormatData); formatedDataList = formatedDataList.Concat(formatedData.ToList()).ToList(); pointDataMoving += 3; } cd.POINT_DATA = formatedDataList.ToArray(); cd.DATA_LENGTH = formatedDataList.Count(); cd.DATA_LENGTH_BYTE = new byte[] { Convert.ToByte(cd.DATA_LENGTH & 0xff), Convert.ToByte(cd.DATA_LENGTH >> 8) }; } cg.channelDatas.Add(cd); channel_data_moving += CHANNEL_DATA_GROUP_1_LENGTH + 4; } cgl.Add(cg); } return cgl; }