我经常要把小区海康或者大华的硬盘录像机推送到自己搭建的gb28181监控平台,每次几百个摄像头编码,有点头大,就用了1个多周写了个批量设置海康和大华硬盘录像机的通道编码的程序,海康和大华的SDK简直不是人看的. 太乱了.
大华读取通道编码的代码
/// <summary>
/// 获取通道编码id列表
/// QQ : 771811549
/// </summary>
/// <returns>通道编码id列表</returns>
public DataTable GetInputIDs()
{
DataTable dt = new DataTable();
dt.Columns.Add("id", typeof(string));
dt.Columns.Add("videoInputID", typeof(string));
if (info.stuSipServerInfo[0].nChannelInfoNum > 0)// 释放内存
{ Marshal.FreeHGlobal(info.stuSipServerInfo[0].pstuChannnelInfo); }
info.stuSipServerInfo[0].nChannelInfoNum = (uint)m_DeviceInfo.nChanNum;//设置通道个数
info.stuSipServerInfo[0].pstuChannnelInfo = Marshal.AllocHGlobal(channelInfoSize * m_DeviceInfo.nChanNum);//分配内存
NETClient.CLIENT_GetConfig(m_LoginID, -1, ref info);//获取数据
NET_SIP_SERVER_INFO ser = info.stuSipServerInfo[0];
for (int j = 0; j < ser.nChannelInfoNum; j++)
{
IntPtr currentPtr = new IntPtr(ser.pstuChannnelInfo.ToInt64() + (j * channelInfoSize));//获取数组偏移指针
NET_CHANNEL_INFO channelInfo = (NET_CHANNEL_INFO)Marshal.PtrToStructure(currentPtr, typeof(NET_CHANNEL_INFO));//获取指针对象
DataRow dr = dt.NewRow();
dr["id"] = j + 1;//通道id
dr["videoInputID"] = channelInfo.szID;//通道编号
dt.Rows.Add(dr);
}
return dt;
}
海康部分代码
public string XML透传(string Url, string Param = "")
{
CHCNetSDK.NET_DVR_XML_CONFIG_INPUT pInputXml = new CHCNetSDK.NET_DVR_XML_CONFIG_INPUT(); //XML透传接口
Int32 nInSize = Marshal.SizeOf(pInputXml);
pInputXml.dwSize = (uint)nInSize;//设置大小
string strRequestUrl = Url;//设置url
uint dwRequestUrlLen = (uint)strRequestUrl.Length;//url长度
pInputXml.lpRequestUrl = Marshal.StringToHGlobalAnsi(strRequestUrl);//请求信令
pInputXml.dwRequestUrlLen = dwRequestUrlLen;//设置长度
string strInputParam = Param;//设置参数
pInputXml.lpInBuffer = Marshal.StringToHGlobalAnsi(strInputParam);//设置缓冲区
pInputXml.dwInBufferSize = (uint)strInputParam.Length;//设置缓冲区大小
CHCNetSDK.NET_DVR_XML_CONFIG_OUTPUT pOutputXml = new CHCNetSDK.NET_DVR_XML_CONFIG_OUTPUT();
pOutputXml.dwSize = (uint)Marshal.SizeOf(pInputXml);//结构体大小
pOutputXml.lpOutBuffer = Marshal.AllocHGlobal(3 * 1024 * 1024);//输出参数缓冲区
pOutputXml.dwOutBufferSize = 3 * 1024 * 1024;//输出参数缓冲区大小
pOutputXml.lpStatusBuffer = Marshal.AllocHGlobal(4096 * 4);//返回的状态参数
pOutputXml.dwStatusSize = 4096 * 4; //状态缓冲区大小(内存大小)
//透传
if (!CHCNetSDK.NET_DVR_STDXMLConfig(m_lUserID, ref pInputXml, ref pOutputXml))
{
uint iLastErr = CHCNetSDK.NET_DVR_GetLastError();//失败
MessageBox.Show("错误号 = " + iLastErr);//XML透传失败,输出错误号
}
//获取输出
uint iXMSize = pOutputXml.dwReturnedXMLSize;
byte[] managedArray = new byte[iXMSize];
Marshal.Copy(pOutputXml.lpOutBuffer, managedArray, 0, (int)iXMSize);
string jg = Encoding.UTF8.GetString(managedArray);
//释放资源
Marshal.FreeHGlobal(pInputXml.lpRequestUrl);
Marshal.FreeHGlobal(pOutputXml.lpOutBuffer);
Marshal.FreeHGlobal(pOutputXml.lpStatusBuffer);
return jg;
}
软件截图:
标签:NVR,C#,pInputXml,pOutputXml,GB28181,uint,NET,Marshal,string From: https://blog.csdn.net/threadroc/article/details/139704756