public void InfoIPChannel() { uint dwSize = (uint)Marshal.SizeOf(m_struIpParaCfgV40); IntPtr ptrIpParaCfgV40 = Marshal.AllocHGlobal((Int32)dwSize); Marshal.StructureToPtr(m_struIpParaCfgV40, ptrIpParaCfgV40, false); uint dwReturn = 0; int iGroupNo = 0; //该Demo仅获取第一组64个通道,如果设备IP通道大于64路,需要按组号0~i多次调用NET_DVR_GET_IPPARACFG_V40获取 if (!CHCNetSDK.NET_DVR_GetDVRConfig(m_lUserID, CHCNetSDK.NET_DVR_GET_IPPARACFG_V40, iGroupNo, ptrIpParaCfgV40, dwSize, ref dwReturn)) { iLastErr = CHCNetSDK.NET_DVR_GetLastError(); str = "NET_DVR_GET_IPPARACFG_V40 failed, error code= " + iLastErr; //获取IP资源配置信息失败,输出错误号 Failed to get configuration of IP channels and output the error code DebugInfo(str); } else { DebugInfo("NET_DVR_GET_IPPARACFG_V40 succ!"); m_struIpParaCfgV40 = (CHCNetSDK.NET_DVR_IPPARACFG_V40)Marshal.PtrToStructure(ptrIpParaCfgV40, typeof(CHCNetSDK.NET_DVR_IPPARACFG_V40)); for (i = 0; i < dwAChanTotalNum; i++) { ListAnalogChannel(i + 1, m_struIpParaCfgV40.byAnalogChanEnable[i]); iChannelNum[i] = i + (int)DeviceInfo.byStartChan; } byte byStreamType = 0; uint iDChanNum = 64; if (dwDChanTotalNum < 64) { iDChanNum = dwDChanTotalNum; //如果设备IP通道小于64路,按实际路数获取 } for (i = 0; i < iDChanNum; i++) { iChannelNum[i + dwAChanTotalNum] = i + (int)m_struIpParaCfgV40.dwStartDChan; byStreamType = m_struIpParaCfgV40.struStreamMode[i].byGetStreamType; dwSize = (uint)Marshal.SizeOf(m_struIpParaCfgV40.struStreamMode[i].uGetStream); switch (byStreamType) { //目前NVR仅支持直接从设备取流 NVR supports only the mode: get stream from device directly 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)); //列出IP通道 List the IP channel ListIPChannel(i + 1, 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)); //列出IP通道 List the IP channel ListIPChannel(i + 1, 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)); //列出IP通道 List the IP channel ListIPChannel(i + 1, m_struChanInfoV40.byEnable, m_struChanInfoV40.wIPID); iIPDevID[i] = m_struChanInfoV40.wIPID - iGroupNo * 64 - 1; Marshal.FreeHGlobal(ptrChanInfoV40); break; default: break; } } } Marshal.FreeHGlobal(ptrIpParaCfgV40); }
private void btnChanInfo_Click(object sender, EventArgs e) { CHCNetSDK.NET_DVR_MATRIX_DEC_CHAN_INFO_V41 m_struDecChanInfo = new CHCNetSDK.NET_DVR_MATRIX_DEC_CHAN_INFO_V41(); if (!CHCNetSDK.NET_DVR_MatrixGetDecChanInfo_V41(m_lUserID, dwDecChanNum, ref m_struDecChanInfo)) { iLastErr = CHCNetSDK.NET_DVR_GetLastError(); strErr = "NET_DVR_MatrixGetDecChanInfo_V41 failed, error code= " + iLastErr; //获取当前解码通道信息失败,输出错误号 Failed to get the decoding info of the channel and output the error code MessageBox.Show(strErr); } else { comboBoxStreamMode.SelectedIndex = m_struDecChanInfo.byStreamMode - 1; //通过IP地址或者域名从设备或者流媒体服务器取流 if (m_struDecChanInfo.byStreamMode == 1) { uint dwUnionSize = (uint)Marshal.SizeOf(m_struDecChanInfo.uDecStreamMode); IntPtr ptrStreamUnion = Marshal.AllocHGlobal((Int32)dwUnionSize); Marshal.StructureToPtr(m_struDecChanInfo.uDecStreamMode, ptrStreamUnion, false); m_struStreamDev = (CHCNetSDK.NET_DVR_DEC_STREAM_DEV_EX)Marshal.PtrToStructure(ptrStreamUnion, typeof(CHCNetSDK.NET_DVR_DEC_STREAM_DEV_EX)); Marshal.FreeHGlobal(ptrStreamUnion); comboBoxChanType.SelectedIndex = m_struStreamDev.struDevChanInfo.byChanType; if (m_struStreamDev.struDevChanInfo.byChanType == 2) { textBoxChanNo.Text = m_struStreamDev.struDevChanInfo.byStreamId; } else { textBoxChanNo.Text = Convert.ToString(m_struStreamDev.struDevChanInfo.dwChannel); } textBoxDevIP.Text = m_struStreamDev.struDevChanInfo.byAddress; textBoxDevPort.Text = Convert.ToString(m_struStreamDev.struDevChanInfo.wDVRPort); comboBoxTransType.SelectedIndex = m_struStreamDev.struDevChanInfo.byTransProtocol; comboBoxStreamType.SelectedIndex = m_struStreamDev.struDevChanInfo.byTransMode; for (int i = 0; i < (int)m_struProtoList.dwProtoNum; i++) { //设备(厂家)协议类型,通过NET_DVR_GetIPCProtoList获取 if (m_struProtoList.struProto[i].dwType == m_struStreamDev.struDevChanInfo.byFactoryType) { comboBoxFactory.SelectedIndex = i; } } textBoxUserName.Text = m_struStreamDev.struDevChanInfo.sUserName; textBoxPassword.Text = m_struStreamDev.struDevChanInfo.sPassword; if (m_struStreamDev.struStreamMediaSvrCfg.byValid == 1) { checkBoxStreamSever.Checked = true; textBoxSeverIP.Text = m_struStreamDev.struStreamMediaSvrCfg.byAddress; textBoxServerPort.Text = Convert.ToString(m_struStreamDev.struStreamMediaSvrCfg.wDevPort); comboBoxSeverProcotol.SelectedIndex = m_struStreamDev.struStreamMediaSvrCfg.byTransmitType; } else { checkBoxStreamSever.Checked = false; } } //通过URL从设备或者流媒体服务器取流 if (m_struDecChanInfo.byStreamMode == 2) { uint dwUnionSize = (uint)Marshal.SizeOf(m_struDecChanInfo.uDecStreamMode); IntPtr ptrStreamUnion = Marshal.AllocHGlobal((Int32)dwUnionSize); Marshal.StructureToPtr(m_struDecChanInfo.uDecStreamMode, ptrStreamUnion, false); m_struStreamURL = (CHCNetSDK.NET_DVR_PU_STREAM_URL)Marshal.PtrToStructure(ptrStreamUnion, typeof(CHCNetSDK.NET_DVR_PU_STREAM_URL)); Marshal.FreeHGlobal(ptrStreamUnion); if (m_struStreamURL.byEnable == 1) { textBoxURL.Text = m_struStreamURL.strURL; } } //通过动态域名解析从设备或者流媒体服务器取流 if (m_struDecChanInfo.byStreamMode == 3) { uint dwUnionSize = (uint)Marshal.SizeOf(m_struDecChanInfo.uDecStreamMode); IntPtr ptrStreamUnion = Marshal.AllocHGlobal((Int32)dwUnionSize); Marshal.StructureToPtr(m_struDecChanInfo.uDecStreamMode, ptrStreamUnion, false); m_struStreamDDNS = (CHCNetSDK.NET_DVR_DEC_DDNS_DEV)Marshal.PtrToStructure(ptrStreamUnion, typeof(CHCNetSDK.NET_DVR_DEC_DDNS_DEV)); Marshal.FreeHGlobal(ptrStreamUnion); comboBoxChanType_D.SelectedIndex = m_struStreamDDNS.struDdnsInfo.byChanType; if (m_struStreamDDNS.struDdnsInfo.byChanType == 2) { textBoxChanNo_D.Text = m_struStreamDDNS.struDdnsInfo.byStreamId; } else { textBoxChanNo_D.Text = Convert.ToString(m_struStreamDDNS.struDdnsInfo.dwChannel); } textBoxDevDomain.Text = m_struStreamDDNS.struDdnsInfo.byDevAddress; comboBoxTransType_D.SelectedIndex = m_struStreamDDNS.struDdnsInfo.byTransProtocol; comboBoxStreamType_D.SelectedIndex = m_struStreamDDNS.struDdnsInfo.byTransMode; textBoxDDNSAddr.Text = m_struStreamDDNS.struDdnsInfo.byDdnsAddress; textBoxDDNSPort.Text = Convert.ToString(m_struStreamDDNS.struDdnsInfo.wDdnsPort); for (int i = 0; i < (int)m_struProtoList.dwProtoNum; i++) { //设备(厂家)协议类型,通过NET_DVR_GetIPCProtoList获取 if (m_struProtoList.struProto[i].dwType == m_struStreamDDNS.struDdnsInfo.byFactoryType) { comboBoxFactory_D.SelectedIndex = i; } } textBoxUserName_D.Text = m_struStreamDDNS.struDdnsInfo.sUserName; textBoxPassword_D.Text = m_struStreamDDNS.struDdnsInfo.sPassword; textBoxDevPort_D.Text = Convert.ToString(m_struStreamDDNS.struDdnsInfo.wDevPort); if (m_struStreamDDNS.struMediaServer.byValid == 1) { checkBoxStreamSever.Checked = true; textBoxSeverIP.Text = m_struStreamDDNS.struMediaServer.byAddress; textBoxServerPort.Text = Convert.ToString(m_struStreamDDNS.struMediaServer.wDevPort); comboBoxSeverProcotol.SelectedIndex = m_struStreamDDNS.struMediaServer.byTransmitType; } else { checkBoxStreamSever.Checked = false; } } } }