海康SDK(三) 获取视频通道编码ID

在修改国标接入配置信息中,也包括修改【视频通道编码ID】,在获取设备的配置信息中并未找到此字段的信息,找了好久才找到。。。所以特此记录一下。

使用接口

海康SDK(三) 获取视频通道编码ID
海康SDK(三) 获取视频通道编码ID

具体实现

        /// <summary>
        /// 获取视频通道编码ID
        /// </summary>
        /// <param name="channel"> 通道Id</param>
        /// <returns></returns>
        public string GetDeviceChannelId(uint channel)
        {
            string videoChannelNumID = string.Empty;
            //lpInBuffer对应结构体-NET_DVR_STREAM_INFO
            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);
            //lpOutBuffer对应结构体-NET_DVR_GBT28181_CHANINFO_CFG
            CHCNetSDK.NET_DVR_GBT28181_CHANINFO_CFG mlpOutBuffer = new CHCNetSDK.NET_DVR_GBT28181_CHANINFO_CFG();
            Int32 dwOutBufferSize = Marshal.SizeOf(mlpOutBuffer);
            IntPtr ptrOutbuffCfg = Marshal.AllocHGlobal(dwOutBufferSize);
            Marshal.StructureToPtr(mlpOutBuffer, ptrOutbuffCfg, false);

            UInt32 dwStatusList = 0;
            IntPtr lpStatusList = Marshal.AllocHGlobal(4);
            Marshal.StructureToPtr(dwStatusList, lpStatusList, false);
            //调用接口
            bool r = CHCNetSDK.NET_DVR_GetDeviceConfig(m_lUserID, 3251, 1, ptrInBuffCond, dwInBufferSize, lpStatusList, ptrOutbuffCfg, dwOutBufferSize);
            if (r)
            {
                //指针转结构体
                CHCNetSDK.NET_DVR_GBT28181_CHANINFO_CFG cfgResult = (CHCNetSDK.NET_DVR_GBT28181_CHANINFO_CFG)Marshal.PtrToStructure(ptrOutbuffCfg, typeof(CHCNetSDK.NET_DVR_GBT28181_CHANINFO_CFG));
                //获取视频通道编码id
                videoChannelNumID = cfgResult.szVideoChannelNumID;
            }
            else
            {
                videoChannelNumID = string.Empty;
                uint iLastErr = CHCNetSDK.NET_DVR_GetLastError();
                ShowLog(string.Format("获取设备视频通道ID失败!错误码为{0}", iLastErr));
            }
            Marshal.FreeHGlobal(ptrInBuffCond);//释放指针 
            Marshal.FreeHGlobal(ptrOutbuffCfg);//释放指针 
            Marshal.FreeHGlobal(lpStatusList);//释放指针 
            return videoChannelNumID;  
        }
上一篇:IOS UI 第十一篇: UITABLEVIEW


下一篇:数据库上篇-01:基本的SELECT语句