其他分享
首页 > 其他分享> > 海康SDK(四) 设置视频通道编码ID

海康SDK(四) 设置视频通道编码ID

作者:互联网

要修改的地方:
在这里插入图片描述

具体接口

在这里插入图片描述
在这里插入图片描述

具体实现

        /// <summary>
        /// 设置视频通道编码ID
        /// </summary>
        /// <param name="channel">通道号</param>
        /// <param name="devId">视频通道编码ID</param>
        public void SetDeviceChannelId(uint channel, string devId)
        {
            //lpInBuffer对应结构体
            CHCNetSDK.NET_DVR_STREAM_INFO mlpInBuffer = new CHCNetSDK.NET_DVR_STREAM_INFO();
            Int32 dwInBufferSize = Marshal.SizeOf(mlpInBuffer);
            mlpInBuffer.dwSize = (uint)dwInBufferSize;
            mlpInBuffer.dwChannel = channel;
            IntPtr ptrInBuffCond = Marshal.AllocHGlobal(dwInBufferSize);
            Marshal.StructureToPtr(mlpInBuffer, ptrInBuffCond, false);

            //lpInParamBuffer对应结构体
            CHCNetSDK.NET_DVR_GBT28181_CHANINFO_CFG mlpOutBuffer = new CHCNetSDK.NET_DVR_GBT28181_CHANINFO_CFG();
            Int32 dwOutBufferSize = Marshal.SizeOf(mlpOutBuffer);
            mlpOutBuffer.szVideoChannelNumID = devId;
            mlpOutBuffer.dwSize = (uint)dwOutBufferSize;
            IntPtr ptrOutbuffCfg = Marshal.AllocHGlobal(dwOutBufferSize);
            Marshal.StructureToPtr(mlpOutBuffer, ptrOutbuffCfg, false);

            UInt32 dwStatusList = 0;
            IntPtr lpStatusList = Marshal.AllocHGlobal(4);
            Marshal.StructureToPtr(dwStatusList, lpStatusList, false);

            //调用接口 3252:NET_DVR_SET_GBT28181_CHANINFO_CFG
            bool r = CHCNetSDK.NET_DVR_SetDeviceConfig(m_lUserID, 3252, 1, ptrInBuffCond, dwInBufferSize, lpStatusList, ptrOutbuffCfg, dwOutBufferSize);
            if (r)
            { 
                //CHCNetSDK.NET_DVR_GBT28181_CHANINFO_CFG focusModeCfg2 = (CHCNetSDK.NET_DVR_GBT28181_CHANINFO_CFG)Marshal.PtrToStructure(ptrOutbuffCfg, typeof(CHCNetSDK.NET_DVR_GBT28181_CHANINFO_CFG)); 
            }
            else
            {
                uint iLastErr = CHCNetSDK.NET_DVR_GetLastError(); 
            }
            Marshal.FreeHGlobal(ptrInBuffCond);//释放指针 
            Marshal.FreeHGlobal(ptrOutbuffCfg);//释放指针 
            Marshal.FreeHGlobal(lpStatusList);//释放指针  
        }

标签:CHCNetSDK,CFG,ID,海康,GBT28181,NET,SDK,Marshal,DVR
来源: https://blog.csdn.net/Strawberry_ahh/article/details/111564762