前言
写系列文章的时候[前言]部分变得无言了,可能来得顺利了点吧: ) 本章中提供的封装均是我用笨办法从<<Hikvision 板卡网络开发包编程手册V4.7>>和<<DS-4000HC、HCS、HC+、HF、HS、MD卡的Windows编程指南V4.3>>中拷贝出来并参照VC++代码进行整理的,主要是针对HikServer.dll和DS40xxSDK.dll的调用封装。
注意
本系列文章限于学习交流,注重过程,由于涉及公司,所以不提供源代码下载,非常抱歉!!但是请大家放心,核心、实现以及其他能够贴出来的代码我都会贴出来,并且争取尽所能的回答留言里的每一个问题,感谢大家关注,欢迎交流 :)
系列
1. C# 视频监控系列(1):准备
2. C# 视频监控系列(2):客户端——封装API
3. C# 视频监控系列(3):客户端——连接服务器
4. C# 视频监控系列(4):客户端——音频接收和抓图
5. C# 视频监控系列(5):客户端——给服务器端发送字符串和录像(数据捕获)
6. C# 视频监控系列(6):服务器端——封装API(上) [HikServer.dll]
7. C# 视频监控系列(7):服务器端——封装API(下) [DS40xxSDK.dll]
正文
1. DS40xxSDK.dll
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
using System.Drawing;
namespace HikServer.DS40xxSDK
{
#region enum
///
/// 板卡类型
///
public enum BOARD_TYPE_DS : uint
{
DS400XM = 0, //M卡
DS400XH = 1, //H卡
DS4004HC = 2, //4004HC
DS4008HC = 3, //4008HC
DS4016HC = 4, //4016HC
DS4001HF = 5, //4001HF
DS4004HF = 6, //4004HF
DS4002MD = 7, //4002MD
DS4004MD = 8, //4004MD
DS4016HCS = 9, //4016HCS
DS4002HT = 10, //4002HT
DS4004HT = 11, //4004HT
DS4008HT = 12, //4008HT
DS4004HC_PLUS = 13, //4004HC+
DS4008HC_PLUS = 14, //4008HC+
DS4016HC_PLUS = 15, //4016HC+
DS4008HF = 16, //4008HF
DS4008MD = 17, //4008MD
DS4008HS = 18, //4008HS
DS4016HS = 19, //4016HS
INVALID_BOARD_TYPE = 0xffffffff,
}
///
/// 视频预览格式
///
public enum TypeVideoFormat
{
vdfRGB8A_233 = 0x00000001,
vdfRGB8R_332 = 0x00000002,
vdfRGB15Alpha = 0x00000004,
///
/// 16位RGB视频压缩格式
///
vdfRGB16 = 0x00000008,
///
/// 24位RGB视频压缩格式
///
vdfRGB24 = 0x00000010,
vdfRGB24Alpha = 0x00000020,
vdfYUV420Planar = 0x00000040,
///
/// YUV422视频压缩格式
///
vdfYUV422Planar = 0x00000080,
vdfYUV411Planar = 0x00000100,
vdfYUV420Interspersed = 0x00000200,
vdfYUV422Interspersed = 0x00000400,
vdfYUV411Interspersed = 0x00000800,
vdfYUV422Sequence = 0x00001000, /* U0, Y0, V0, Y1: For VO overlay */
vdfYUV422SequenceAlpha = 0x00002000,
/* U0, Y0, V0, Y1: For VO overlay, with low bit for alpha blending */
vdfMono = 0x00004000, /* 8 bit monochrome */
vdfYUV444Planar = 0x00008000,
};
///
/// 视频制式
///
public enum VideoStandard_t : uint
{
///
/// 无视频信号
///
StandardNone = 0x80000000,
///
/// NTSC制式
///
StandardNTSC = 0x00000001,
///
/// PAL制式
///
StandardPAL = 0x00000002,
StandardSECAM = 0x00000004,
} ;
///
/// 编码图像分辨率
///
public enum PictureFormat_t
{
ENC_CIF_FORMAT = 0,
ENC_QCIF_FORMAT = 1,
ENC_2CIF_FORMAT = 2,
ENC_4CIF_FORMAT = 3,
ENC_QQCIF_FORMAT = 4,
ENC_CIFQCIF_FORMAT = 5,
ENC_CIFQQCIF_FORMAT = 6,
ENC_DCIF_FORMAT = 7
};
///
/// 码流控制方式
///
public enum BitrateControlType_t
{
///
/// 变码率
///
brCBR = 0,
///
/// 恒定码率
///
brVBR = 1,
};
public enum FrameType_t
{
PktError = 0,
PktIFrames = 0x0001,
PktPFrames = 0x0002,
PktBBPFrames = 0x0004,
PktAudioFrames = 0x0008,
PktMotionDetection = 0x00010,
PktDspStatus = 0x00020,
PktOrigImage = 0x00040,
PktSysHeader = 0x00080,
PktBPFrames = 0x00100,
PktSFrames = 0x00200,
PktSubIFrames = 0x00400,
PktSubPFrames = 0x00800,
PktSubBBPFrames = 0x01000,
PktSubSysHeader = 0x02000
};
#endregion
#region struct
///
/// 板卡信息结构体
///
public struct DS_BOARD_DETAIL
{
///
/// 板卡类型
///
BOARD_TYPE_DS type;
///
/// 序列号
/// BYTE sn[16];
///
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 16)]
byte[] sn;
///
/// 板卡包含的DSP个数
///
uint dspCount;
///
/// 板卡上第一个DSP的索引
///
uint firstDspIndex;
///
/// 板卡包含的编码通道个数
///
uint encodeChannelCount;
///
/// 板卡上第一个编码通道的索引
///
uint firstEncodeChannelIndex;
///
/// 板卡包含的解码通道个数
///
uint decodeChannelCount;
///
/// 板卡上第一个解码通道的索引
///
uint firstDecodeChannelIndex;
///
/// 板卡包含的视频输出通道个数
///
uint displayChannelCount;
///
/// 板卡上第一个视频输出通道的索引
///
uint firstDisplayChannelIndex;
uint reserved1;
uint reserved2;
uint reserved3;
///
/// 硬件版本,format:major.minor.build,major:bit 16-19,minor: bit 8-15,build: bit 0-7
///
uint version;
}
///
/// DSP信息结构体
///
public struct DSP_DETAIL
{
///
/// 此DSP所包含的编码通道个数
///
uint encodeChannelCount;
///
/// 此DSP上第一个编码通道在所有编码通道中的索引
///
uint firstEncodeChannelIndex;
///
/// 此DSP所包含的解码通道个数
///
uint decodeChannelCount;
///
/// 此DSP上第一个解码通道在所有解码通道中的索引
///
uint firstDecodeChannelIndex;
///
/// 此DSP包含的显示通道个数
///
uint displayChannelCount;
///
/// 此DSP上第一个显示通道在所有显示通道中的索引
///
uint firstDisplayChannelIndex;
uint reserved1;
uint reserved2;
uint reserved3;
uint reserved4;
}
///
/// 特殊功能结构体
///
public struct CHANNEL_CAPABILITY
{
///
/// 音频预览
///
byte[] bAudioPreview;
///
/// 报警信号
///
byte[] bAlarmIO;
///
/// 看家狗
///
byte[] bWatchDog;
}
///
/// 版本信息
///
public struct PVERSION_INFO
{
///
/// DSP版本号,DSP的BUILD号,用于软件升级时标明该版本的最后修改时间
///
ulong DspVersion, DspBuildNum;
///
/// Driver版本号,Driver的BUILD号,用于软件升级时标明该版本的最后修改时间
///
ulong DriverVersion, DriverBuildNum;
///
/// SDK版本号,SDK的BUILD号,用于软件升级时标明该版本的最后修改时间
///
ulong SDKVersion, SDKBuildNum;
}
///
/// 显示窗口内的矩形区域
///
//[StructLayout(LayoutKind.
//public struct RECT
//{
// public long left;
// public long top;
// public long right;
// public long bottom;
//}
///
/// 帧统计信息结构体
///
public struct PFRAMES_STATISTICS
{
///
/// 视频帧
///
ulong VideoFrames;
///
/// 音频帧
///
ulong AudioFrames;
///
/// 丢失帧
///
ulong FramesLost;
///
/// 丢失的码流(字节)
///
ulong QueueOverflow;
///
/// 当前的帧率(bps)
///
ulong CurBps;
}
///
/// 版本信息结构体
///
public struct PHW_VERSION
{
///
/// DSP程序的版本号和Build号
///
ulong DspVersion, DspBuildNum;
///
/// 驱动程序的版本号和Build号
///
ulong DriverVersion, DriverBuildNum;
///
/// SDK 的版本号和Build号
///
ulong SDKVersion, SDKBuildNum;
}
///
/// 系统时间
///
public struct SYSTEMTIME
{
ushort wYear;
ushort wMonth;
ushort wDayOfWeek;
ushort wDay;
ushort wHour;
ushort wMinute;
ushort wSecond;
ushort wMilliseconds;
}
#endregion
#region delegate
///
/// 原始图像流设置
///
/// typedef void (*IMAGE_STREAM_CALLBACK)(UINT channelNumber,void *context);
///
/// 通道号
/// 设备上下文
public delegate void IMAGE_STREAM_CALLBACK(uint channelNumber, IntPtr context);
///
/// 编码数据流直接读取回调函数
///
/// typedef int (*STREAM_DIRECT_READ_CALLBACK)(ULONG channelNumber,void *DataBuf,DWORD Length,int FrameType,void *context);
///
/// 通道号
/// 缓冲区地址
/// 缓冲区长度
/// 缓冲区数据帧类型
/// 设备上下文
///
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
//public delegate int STREAM_DIRECT_READ_CALLBACK(uint channelNumber, byte[] DataBuf, uint Length, FrameType_t FrameType, IntPtr context);
public delegate int STREAM_DIRECT_READ_CALLBACK(int channelNumber, IntPtr DataBuf, int Length, FrameType_t FrameType, IntPtr context);
//public unsafe delegate int STREAM_DIRECT_READ_CALLBACK(uint channelNumber, void * DataBuf, uint Length, int FrameType, IntPtr context);
///
/// 直接读取码流回调函数
///
/// typedef int (*STREAM_READ_CALLBACK)(ULONG channelNumber, void *context)
///
/// 通道号
/// 设备上下文
///
public delegate int STREAM_READ_CALLBACK(ulong channelNumber, IntPtr context);
///
/// 移动侦测结果回调函数
///
/// typedef void (*MOTION_DETECTION_CALLBACK)(ULONG channelNumber, BOOL bMotionDetected,void *context)
///
/// 通道号
///
/// 移动侦测发生标志,如果当前通道所设置的移动侦测
/// 区域内产生了移动侦测,则被置为True;如果当前通道所设置的移动侦测区域内自上
/// 一次产生移动侦测后delay秒内没有发生移动侦测,则被置为False。
///
/// 设备上下文
public delegate void MOTION_DETECTION_CALLBACK(ulong channelNumber, bool bMotionDetected, IntPtr context);
///
/// 画图回调函数
///
/// #define DRAWFUN(x) void (CALLBACK* x)(long nPort,HDC hDc,LONG nUser)
///
/// 通道号
/// offscreen表面设备上下文,相当于显示窗口中的DC
/// 用户数据
public delegate void DrawFun(long nPort, IntPtr HDC, long nUser);