private static void UpdateChannel(ref CameraChannel channel, Byte byEnable, Int32 byIPID) { if (byIPID == 0) { channel.ChannelState = (Int32)CameraChannelState.IDLE; channel.IsEnabled = false; } else { if (byEnable == 0) { channel.ChannelState = (Int32)CameraChannelState.Offline; channel.IsEnabled = false; } else { channel.ChannelState = (Int32)CameraChannelState.Online; channel.IsEnabled = true; } } }
public OResult <IEnumerable <CameraChannel> > GetChannels() { UInt32 dwReturn = 0; var iGroupNo = 0; //0表示仅获取第一组64个通道,如果设备IP通道大于64路,需要按组号0~i多次调用NET_DVR_GET_IPPARACFG_V40获取 var iIPDevID = new Int32[96]; var dwAChanTotalNum = (UInt32)_deviceInfo.struDeviceV30.byChanNum; var dwDChanTotalNum = (UInt32)(_deviceInfo.struDeviceV30.byIPChanNum + 256 * _deviceInfo.struDeviceV30.byHighDChanNum); IntPtr ptrIpParaCfgV40 = IntPtr.Zero; var channels = new List <CameraChannel>(16); try { if (dwDChanTotalNum > 0) { var m_struIpParaCfgV40 = new CHCNetSDK.NET_DVR_IPPARACFG_V40(); var dwSize = (UInt32)Marshal.SizeOf(m_struIpParaCfgV40); ptrIpParaCfgV40 = Marshal.AllocHGlobal((Int32)dwSize); Marshal.StructureToPtr(m_struIpParaCfgV40, ptrIpParaCfgV40, false); if (CHCNetSDK.NET_DVR_GetDVRConfig(_userId, CHCNetSDK.NET_DVR_GET_IPPARACFG_V40, iGroupNo, ptrIpParaCfgV40, dwSize, ref dwReturn)) { m_struIpParaCfgV40 = (CHCNetSDK.NET_DVR_IPPARACFG_V40)Marshal.PtrToStructure(ptrIpParaCfgV40, typeof(CHCNetSDK.NET_DVR_IPPARACFG_V40)); if (dwAChanTotalNum > 0) { for (var i = 0; i < dwAChanTotalNum; i++) { channels.Add(new CameraChannel() { ChannelNo = _deviceInfo.struDeviceV30.byStartChan + i, ChannelType = (Int32)CameraChannelType.AC, IsEnabled = m_struIpParaCfgV40.byAnalogChanEnable[i] != 0 }); } } UInt32 iDChanNum = 64; if (dwDChanTotalNum < 64) { iDChanNum = dwDChanTotalNum; //如果设备IP通道小于64路,按实际路数获取 } CHCNetSDK.NET_DVR_IPCHANINFO m_struChanInfo; CHCNetSDK.NET_DVR_PU_STREAM_URL m_struStreamURL; CHCNetSDK.NET_DVR_IPCHANINFO_V40 m_struChanInfoV40; if (iDChanNum > 0) { for (var i = 0; i < iDChanNum; i++) { var byStreamType = m_struIpParaCfgV40.struStreamMode[i].byGetStreamType; dwSize = (UInt32)Marshal.SizeOf(m_struIpParaCfgV40.struStreamMode[i].uGetStream); var dcChannel = new CameraChannel() { ChannelNo = (Int32)m_struIpParaCfgV40.dwStartDChan + i, ChannelType = (Int32)CameraChannelType.DC }; switch (byStreamType) { //目前NVR仅支持直接从设备取流 case 0: IntPtr ptrChanInfo = Marshal.AllocHGlobal((Int32)dwSize); Marshal.StructureToPtr(m_struIpParaCfgV40.struStreamMode[i].uGetStream, ptrChanInfo, false); m_struChanInfo = (CHCNetSDK.NET_DVR_IPCHANINFO)Marshal.PtrToStructure(ptrChanInfo, typeof(CHCNetSDK.NET_DVR_IPCHANINFO)); UpdateChannel(ref dcChannel, m_struChanInfo.byEnable, m_struChanInfo.byIPID); iIPDevID[i] = m_struChanInfo.byIPID + m_struChanInfo.byIPIDHigh * 256 - iGroupNo * 64 - 1; Marshal.FreeHGlobal(ptrChanInfo); break; case 4: IntPtr ptrStreamURL = Marshal.AllocHGlobal((Int32)dwSize); Marshal.StructureToPtr(m_struIpParaCfgV40.struStreamMode[i].uGetStream, ptrStreamURL, false); m_struStreamURL = (CHCNetSDK.NET_DVR_PU_STREAM_URL)Marshal.PtrToStructure(ptrStreamURL, typeof(CHCNetSDK.NET_DVR_PU_STREAM_URL)); UpdateChannel(ref dcChannel, m_struStreamURL.byEnable, m_struStreamURL.wIPID); iIPDevID[i] = m_struStreamURL.wIPID - iGroupNo * 64 - 1; Marshal.FreeHGlobal(ptrStreamURL); break; case 6: IntPtr ptrChanInfoV40 = Marshal.AllocHGlobal((Int32)dwSize); Marshal.StructureToPtr(m_struIpParaCfgV40.struStreamMode[i].uGetStream, ptrChanInfoV40, false); m_struChanInfoV40 = (CHCNetSDK.NET_DVR_IPCHANINFO_V40)Marshal.PtrToStructure(ptrChanInfoV40, typeof(CHCNetSDK.NET_DVR_IPCHANINFO_V40)); UpdateChannel(ref dcChannel, m_struChanInfoV40.byEnable, m_struChanInfoV40.wIPID); iIPDevID[i] = m_struChanInfoV40.wIPID - iGroupNo * 64 - 1; Marshal.FreeHGlobal(ptrChanInfoV40); break; default: break; } channels.Add(dcChannel); } } } } else { for (var i = 0; i < dwAChanTotalNum; i++) { channels.Add(new CameraChannel() { ChannelNo = _deviceInfo.struDeviceV30.byStartChan + i, ChannelType = (Int32)CameraChannelType.AC, IsEnabled = true }); } } return(new OResult <IEnumerable <CameraChannel> >(channels)); } finally { Marshal.FreeHGlobal(ptrIpParaCfgV40); } }