110,534
社区成员
发帖
与我相关
我的任务
分享
/// 设备信息
typedef struct _H264_DVR_DEVICEINFO
{
char sSoftWareVersion[64]; ///< 软件版本信息
char sHardWareVersion[64]; ///< 硬件版本信息
char sEncryptVersion[64]; ///< 加密版本信息
SDK_SYSTEM_TIME tmBuildTime;///< 软件创建时间
char sSerialNumber[64]; ///< 设备序列号
int byChanNum; ///< 视频输入通道数
int iVideoOutChannel; ///< 视频输出通道数
int byAlarmInPortNum; ///< 报警输入通道数
int byAlarmOutPortNum; ///< 报警输出通道数
int iTalkInChannel; ///< 对讲输入通道数
int iTalkOutChannel; ///< 对讲输出通道数
int iExtraChannel; ///< 扩展通道数
int iAudioInChannel; ///< 音频输入通道数
int iCombineSwitch; ///< 组合编码通道分割模式是否支持切换
int iDigChannel; ///<数字通道数
unsigned int uiDeviceRunTime; ///<系统运行时间
}H264_DVR_DEVICEINFO,*LPH264_DVR_DEVICEINFO;
typedef struct H264_DVR_CLIENTINFO{
int nChannel; //通道号
int nStream; //0表示主码流,为1表示子码流
int nMode; //0:TCP方式,1:UDP方式,2:多播方式,3 - RTP方式,4-音视频分开(TCP)
int nComType; //只对组合编码通道有效, 组合编码通道的拼图模式
void* hWnd;
H264_DVR_CLIENTINFO()
{
hWnd=0;
}
}*LPH264_DVR_CLIENTINFO;
//服务器断开回调原形
typedef void (CALL_METHOD *fDisConnect)(long lLoginID, char *pchDVRIP, long nDVRPort, unsigned long dwUser);
//*** */SDK初始化
H264_DVR_API long CALL_METHOD H264_DVR_Init(fDisConnect cbDisConnect, unsigned long dwUser);
//打开实时预览
H264_DVR_API long CALL_METHOD H264_DVR_RealPlay(long lLoginID, LPH264_DVR_CLIENTINFO lpClientInfo);
/// <summary>
/// 设备信息
/// H264_DVR_DEVICEINFO,*LPH264_DVR_DEVICEINFO;
/// </summary>
public struct H264_DVR_DEVICEINFO
{
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 64)]
public byte[] sSoftWareVersion; ///< 软件版本信息
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 64)]
public byte[] sHardWareVersion; ///< 硬件版本信息
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 64)]
public byte[] sEncryptVersion; ///< 加密版本信息
public SDK_SYSTEM_TIME tmBuildTime;///< 软件创建时间
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 64)]
public byte[] sSerialNumber; ///< 设备序列号
public Int32 byChanNum; ///< 视频输入通道数
public Int32 iVideoOutChannel; ///< 视频输出通道数
public Int32 byAlarmInPortNum; ///< 报警输入通道数
public Int32 byAlarmOutPortNum; ///< 报警输出通道数
public Int32 iTalkInChannel; ///< 对讲输入通道数
public Int32 iTalkOutChannel; ///< 对讲输出通道数
public Int32 iExtraChannel; ///< 扩展通道数
public Int32 iAudioInChannel; ///< 音频输入通道数
public Int32 iCombineSwitch; ///< 组合编码通道分割模式是否支持切换
public Int32 iDigChannel; ///<数字通道数
public Int32 uiDeviceRunTime; ///<系统运行时间
}
/// <summary>
/// *LPH264_DVR_CLIENTINFO;
/// </summary>
public struct H264_DVR_CLIENTINFO
{
/// <summary>
/// //通道号
/// </summary>
public int nChannel;
/// <summary>
/// //0表示主码流,为1表示子码流
/// </summary>
public int nStream;
/// <summary>
/// //0:TCP方式,1:UDP方式,2:多播方式,3 - RTP方式,4-音视频分开(TCP)
/// </summary>
public int nMode;
/// <summary>
/// //只对组合编码通道有效, 组合编码通道的拼图模式
/// </summary>
public int nComType;
public IntPtr hWnd;
//H264_DVR_CLIENTINFO(IntPtr hWnd)
//{
// hWnd = IntPtr.Zero;
//}
}
/// <summary>
/////服务器断开回调原形
/// typedef void (CALL_METHOD *fDisConnect)(long lLoginID, char *pchDVRIP, long nDVRPort, unsigned long dwUser);
/// </summary>
public delegate void fDisConnect(int lLoginID, string pchDVRIP, int nDVRPort, uint dwUser);
/// <summary>
/////*** */SDK初始化
/// H264_DVR_API long CALL_METHOD H264_DVR_Init(fDisConnect cbDisConnect, unsigned long dwUser);
/// </summary>
[DllImport("netsdk.dll")]
public static extern int H264_DVR_Init(fDisConnect cbDisConnect, uint dwUser);
/// <summary>
/////获取错误信息
/// H264_DVR_API long CALL_METHOD H264_DVR_GetLastError();
/// </summary>
[DllImport("netsdk.dll")]
public static extern int H264_DVR_GetLastError();
/// <summary>
///向设备注册
///H264_DVR_API long CALL_METHOD H264_DVR_Login(char *sDVRIP, unsigned short wDVRPort, char *sUserName, char *sPassword,LPH264_DVR_DEVICEINFO lpDeviceInfo, int *error);
/// </summary>
[DllImport("netsdk.dll")]
public static extern int H264_DVR_Login(string sDVRIP, ushort wDVRPort, string sUserName, string sPassword, ref H264_DVR_DEVICEINFO lpDeviceInfo, IntPtr error);
/// <summary>
///打开实时预览
///H264_DVR_API long CALL_METHOD H264_DVR_RealPlay(long lLoginID, LPH264_DVR_CLIENTINFO lpClientInfo);
/// </summary>
[DllImport("netsdk.dll")]
public static extern int H264_DVR_RealPlay(int lLoginID, ref H264_DVR_CLIENTINFO lpClientInfo);
/// <summary>
///向设备注册
///H264_DVR_API long CALL_METHOD H264_DVR_Login(char *sDVRIP, unsigned short wDVRPort, char *sUserName, char *sPassword,LPH264_DVR_DEVICEINFO lpDeviceInfo, int *error);
/// </summary>
[DllImport("netsdk.dll")]
public static extern int H264_DVR_Login(string sDVRIP, ushort wDVRPort, string sUserName, string sPassword, ref H264_DVR_DEVICEINFO lpDeviceInfo, IntPtr error);
/// <summary>
///向设备注册
///H264_DVR_API long CALL_METHOD H264_DVR_Login(char *sDVRIP, unsigned short wDVRPort, char *sUserName, char *sPassword,LPH264_DVR_DEVICEINFO lpDeviceInfo, int *error);
/// </summary>
[DllImport("netsdk.dll")]
public static extern int H264_DVR_Login(string sDVRIP, ushort wDVRPort, string sUserName, string sPassword, ref H264_DVR_DEVICEINFO lpDeviceInfo, ref int error);
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using MonitorClient;
using System.Net.Sockets;
namespace MonitorClient
{
public partial class Form1 : Form
{
int curLoginID = -1;
NetSDK.fDisConnect fc;
int lRealHandle = -1;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
fc = new NetSDK.fDisConnect(Connect);
NetSDK.H264_DVR_Init(fc, 1);
NetSDK.H264_DVR_SetConnectTime(3000,1);
}
private void button1_Click(object sender, EventArgs e)
{
H264_DVR_DEVICEINFO dfo = new H264_DVR_DEVICEINFO();
try
{
curLoginID = NetSDK.H264_DVR_Login("192.168.0.10", 34567, "admin", "", out dfo, IntPtr.Zero);
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
if (curLoginID == -1)
{
MessageBox.Show(string.Format("登录DVS失败,错误码: {0}", NetSDK.H264_DVR_GetLastError()), "登录DVS失败", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
H264_DVR_CLIENTINFO cfo = new H264_DVR_CLIENTINFO();
cfo.hWnd = this.panel1.Handle;
cfo.nChannel = 2;
cfo.nComType = 1;
cfo.nMode = 0;
cfo.nStream = 1;
lRealHandle= NetSDK.H264_DVR_RealPlay(curLoginID, ref cfo);
if (lRealHandle == -1)
{
MessageBox.Show(string.Format("播放失败,错误码: {0}", NetSDK.H264_DVR_GetLastError()));
return;
}
}
private void Connect(int lLoginID, string pchDVRIP, int nDVRPort, uint dwUser)
{
lLoginID = curLoginID;
pchDVRIP = "192.168.0.10";
nDVRPort = 34567;
dwUser = 0;
}
}
}