0

我正在尝试通过 C# SDK (CHCNetSDK.cs) 配置音频丢失检测,但我正在努力寻找有关这方面的任何文档。我可以连接到设备并登录,下一步是从设备获取现有的音频异常检测配置

我很确定我需要使用CHCNetSDK.NET_VCA_AUDIO_ABNORMAL

这是我到目前为止所拥有的

public static CHCNetSDK.NET_VCA_AUDIO_ABNORMAL? GetDevice_AudioDetectConfig(int userID, uint channel)
        {
            NET_VCA_AUDIO_ABNORMAL result = new NET_VCA_AUDIO_ABNORMAL();

            int nSize = Marshal.SizeOf(result);
            //result.dwSize = (uint)nSize;
            IntPtr ptrConfig = Marshal.AllocHGlobal(nSize);
            Marshal.StructureToPtr(result, ptrConfig, false);
            UInt32 dwReturn = 0;
            if (CHCNetSDK.NET_DVR_GetDVRConfig(userID, CHCNetSDK.NET_DVR_GET_PICCFG_V30, (int)channel, ptrConfig, (uint)nSize, ref dwReturn))
            {

                result = (CHCNetSDK.NET_VCA_AUDIO_ABNORMAL)Marshal.PtrToStructure(ptrConfig, typeof(CHCNetSDK.NET_VCA_AUDIO_ABNORMAL));
                Marshal.FreeHGlobal(ptrConfig);
                return result;
            }
            else
            {
                Marshal.FreeHGlobal(ptrConfig);
                return null;
            }
        }

我相信这条线是错误的,NET_DVR_GetDVRConfig 是错误的调用方法

CHCNetSDK.NET_DVR_GetDVRConfig(userID, CHCNetSDK.NET_DVR_GET_PICCFG_V30, (int)channel, ptrConfig, (uint)nSize, ref dwReturn)

如果有人能指出我正确的方向,我将不胜感激。

4

1 回答 1

0

首先从https://www.hikvision.com/en/support/download/sdk/下载最新的 SDK

这是我需要与之交互HCNetSDK.dll以启用音频检测的代码

[DllImport("HCNetSDK.dll", EntryPoint = "NET_DVR_GetDeviceConfig")]
public static extern bool NET_DVR_GetDeviceConfig2(int lUserID, uint dwCommand, uint dwCount, IntPtr lpInBuffer, uint dwInBufferSize, IntPtr lpStatusList, IntPtr lpOutBuffer, uint dwOutBufferSize);

[DllImport("HCNetSDK.dll", EntryPoint = "NET_DVR_SetDeviceConfig")]
public static extern bool NET_DVR_SetDeviceConfig2(int lUserID, uint dwCommand, uint dwCount, IntPtr lpInBuffer, uint dwInBufferSize, IntPtr lpStatusList, IntPtr lpInParamBuffer, uint dwInParamBufferSize);

这在CHCNetSDK.cs文件中

[StructLayoutAttribute(LayoutKind.Sequential)]
public struct NET_VCA_AUDIO_ABNORMAL
        {
            public ushort wDecibel;
            public byte bySensitivity;
            public byte byAudioMode;
            public byte byEnable;
            public byte byThreshold;
            [MarshalAsAttribute(UnmanagedType.ByValArray, SizeConst = 54, ArraySubType = UnmanagedType.I1)]
            public byte[] byRes;
        }

[StructLayoutAttribute(LayoutKind.Sequential)]
public struct NET_DVR_AUDIO_EXCEPTION
        {
            public uint dwSize;
            public byte byEnableAudioInException; 
            [MarshalAsAttribute(UnmanagedType.ByValArray, SizeConst = 3, ArraySubType = UnmanagedType.I1)]
            public byte[] byRes1;
            public NET_VCA_AUDIO_ABNORMAL struAudioAbnormal;
            [MarshalAsAttribute(UnmanagedType.ByValArray, SizeConst = MAX_DAYS * MAX_TIMESEGMENT_V30, ArraySubType = UnmanagedType.Struct)]
            public NET_DVR_SCHEDTIME[] struAlarmSched;
            public NET_DVR_HANDLEEXCEPTION_V40 struHandleException;
            public uint dwMaxRelRecordChanNum;
            public uint dwRelRecordChanNum;
            [MarshalAsAttribute(UnmanagedType.ByValArray, SizeConst = MAX_CHANNUM_V30, ArraySubType = UnmanagedType.U4)]
            public uint[] byRelRecordChan;
            [MarshalAsAttribute(UnmanagedType.ByValArray, SizeConst = 32, ArraySubType = UnmanagedType.I1)]
            public byte[] byRes2;
        }

[StructLayoutAttribute(LayoutKind.Sequential)]
public struct NET_DVR_CHANNEL_GROUP
        {
            public uint dwSize;
            public uint dwChannel;
            public uint dwGroup;
            public byte ByID;

            [MarshalAsAttribute(UnmanagedType.ByValArray, SizeConst = 3, ArraySubType = UnmanagedType.I1)]
            public byte[] byRes1;

            public byte dwPositionNo;

[MarshalAsAttribute(UnmanagedType.ByValArray, SizeConst = 56, ArraySubType = UnmanagedType.I1)]
public byte[] byRes;
        }
public static CHCNetSDK.NET_DVR_AUDIO_EXCEPTION? GetDevice_AudioDetectConfig(int userID, uint channel)
{
            NET_DVR_CHANNEL_GROUP channelGroup = new NET_DVR_CHANNEL_GROUP();
            channelGroup.dwSize = (uint)Marshal.SizeOf(channelGroup);
            channelGroup.dwChannel = channel;
            IntPtr lpInBuffer = Marshal.AllocHGlobal(Marshal.SizeOf(channelGroup));
            Marshal.StructureToPtr(channelGroup, lpInBuffer, false);
            uint dwInBufferSize = Convert.ToUInt32(channelGroup.dwSize);

            NET_DVR_AUDIO_EXCEPTION result = new NET_DVR_AUDIO_EXCEPTION();
            result.dwSize = (uint)Marshal.SizeOf(result);
            IntPtr lpOutBuffer = Marshal.AllocHGlobal(Marshal.SizeOf(result));
            Marshal.StructureToPtr(result, lpOutBuffer, false);
            uint dwOutBufferSize = Convert.ToUInt32(result.dwSize);

            uint lp = 1;
            IntPtr lpStatusList = Marshal.AllocHGlobal(Marshal.SizeOf(lp));
            
            var b = CHCNetSDK.NET_DVR_GetDeviceConfig2(userID, NET_DVR_GET_AUDIOEXCEPTIONPARAM, 1, lpInBuffer, dwInBufferSize, lpStatusList, lpOutBuffer, dwOutBufferSize);
            if (b)
            {
                result = (CHCNetSDK.NET_DVR_AUDIO_EXCEPTION)Marshal.PtrToStructure(lpOutBuffer, typeof(CHCNetSDK.NET_DVR_AUDIO_EXCEPTION));
                Marshal.FreeHGlobal(lpInBuffer);
                Marshal.FreeHGlobal(lpOutBuffer);
                return result;
            }
            else
            {                
                Marshal.FreeHGlobal(lpInBuffer);
                Marshal.FreeHGlobal(lpOutBuffer);
                return null;
            }
}

public static bool SetDevice_AudioDetectConfig(int userID, int channel, CHCNetSDK.NET_DVR_AUDIO_EXCEPTION config)
{
            NET_DVR_CHANNEL_GROUP channelGroup = new NET_DVR_CHANNEL_GROUP();
            channelGroup.dwSize = (uint)Marshal.SizeOf(channelGroup);
            channelGroup.dwChannel = (uint)channel;
            IntPtr lpInBuffer = Marshal.AllocHGlobal(Marshal.SizeOf(channelGroup));
            Marshal.StructureToPtr(channelGroup, lpInBuffer, false);
            uint dwInBufferSize = Convert.ToUInt32(channelGroup.dwSize);

            uint lp = 1;
            IntPtr lpStatusList = Marshal.AllocHGlobal(Marshal.SizeOf(lp));

            config.dwSize = (uint)Marshal.SizeOf(config);
            IntPtr lpInParamBuffer = Marshal.AllocHGlobal(Marshal.SizeOf(config));
            Marshal.StructureToPtr(config, lpInParamBuffer, false);            
            uint dwInParamBufferSize = Convert.ToUInt32(config.dwSize);

            bool success = CHCNetSDK.NET_DVR_SetDeviceConfig2(userID, NET_DVR_SET_AUDIOEXCEPTIONPARAM, 1, lpInBuffer, dwInBufferSize, lpStatusList, lpInParamBuffer, dwInParamBufferSize);

            Marshal.FreeHGlobal(lpInBuffer);
            Marshal.FreeHGlobal(lpInParamBuffer);

            return success;
}
于 2020-10-26T15:06:31.040 回答