(新手)JNA调用海康SDK问题,跪求大神要疯了~
现附上主要部分代码
public static class NET_DVR_PREVIEWINFO extends Structure {
/**
* 通道号,目前设备模拟通道号从1开始,数字通道的起始通道号通过NET_DVR_GetDVRConfig
*(配置命令NET_DVR_GET_IPPARACFG_V40)获取(dwStartDChan)。
*/
public long lChannel;
/**/
/**
* 码流类型:0-主码流,1-子码流,2-码流3,3-虚拟码流,
*/
public int dwStreamType;
/**
* 连接方式:0- TCP方式,1- UDP方式,2- 多播方式,3- RTP方式,4-RTP/RTSP,5-RTP/HTTP
*/
public int lLinkMode;
/**
* 播放窗口的句柄,为NULL表示不解码显示。
*/
public HWND hPlayWnd;
/**
* 0- 非阻塞取流,1- 阻塞取流。如果阻塞取流,SDK内部connect失败将会有5s的超时才能够返回,不适合于轮询取流操作。
*/
public boolean bBlocked;
/**
* 0-不启用录像回传,1-启用录像回传。ANR断网补录功能,客户端和设备之间网络异常恢复之后自动将前端数据同步过来,需要设备支持。
*/
public boolean bPassbackRecord;
/**
* 预览模式:0- 正常预览,1- 延迟预览
*/
public String byPreviewMode;
/**
* 流ID,为字母、数字和"_"的组合,lChannel为0xffffffff时启用此参数
*/
public String byStreamID;
/**
* 应用层取流协议:0- 私有协议,1- RTSP协议。
* 主子码流支持的取流协议通过登录返回结构参数NET_DVR_DEVICEINFO_V30的byMainProto、bySubProto值得知。
* 设备同时支持私协议和RTSP协议时,该参数才有效,默认使用私有协议,可选RTSP协议。
*/
public String byProtoType;
/**
* 保留,置为0
*/
public String byRes1;
/**
* 播放库播放缓冲区最大缓冲帧数,取值范围:1~50,置0时默认为1。
* 设置显示缓冲需要在播放库调用PlayM4_Play之前调用,该参数替换原先NET_DVR_SetPlayerBufNumber接口
*/
public int dwDisplayBufNum;
/**
* 保留,置为0
*/
public String byRes;
@Override
protected List getFieldOrder() {
return Arrays.asList(new String[]{"lChannel", "dwStreamType","lLinkMode",
"hPlayWnd","bBlocked","bPassbackRecord","byPreviewMode",
"byStreamID","byProtoType","byRes1","dwDisplayBufNum","byRes"});
}
}
public static interface RealDataCallback_V30 extends Callback{
/**
* @param lRealHandle 当前的预览句柄,NET_DVR_RealPlay_V40的返回值
* @param dwDataType 数据类型:1-系统头数据,2-流数据,3音频数据,112-私有数据包括智能信息
* @param pBuffer 存放数据的缓冲区
* @param dwBufSize 缓冲区大小
* @param pUser 用户数据
* @return -1-表示失败
*/
void invoke(
long lRealHandle,
int dwDataType,
String pBuffer,
int dwBufSize,
String pUser);
}
public abstract long NET_DVR_RealPlay_V40(long lUserID, NET_DVR_PREVIEWINFO lpPreviewInfo,
RealDataCallback_V30 fRealDataCallBack_V30, String pUser);
下面是调用的代码,删掉了部分感觉没用swing界面编写的代码方便你们看:
private Panel panelRealPlay;
private Button buttonRealPlay;
private Button buttonStopRealPlay;
private JLabel jLabel1;
private JLabel jLabel2;
private JLabel jLabel3;
private JLabel jLabel4;
private Label label1;
private TextField textFieldChan;
private TextField textFieldIP;
private TextField textFieldPasswd;
private TextField textFieldPort;
private TextField textFieldUser;
private void initComponents() {
buttonRealPlay = new Button();
panelRealPlay = new Panel();
jLabel1 = new JLabel();
jLabel2 = new JLabel();
jLabel3 = new JLabel();
jLabel4 = new JLabel();
textFieldIP = new TextField();
textFieldUser = new TextField();
textFieldPasswd = new TextField();
textFieldPort = new TextField();
textFieldChan = new TextField();
label1 = new Label();
buttonStopRealPlay = new Button();
buttonRealPlay.setLabel("预览");
buttonRealPlay.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
buttonRealPlayActionPerformed(evt);
}
});
panelRealPlay.setBackground(new Color(204, 204, 204));
jLabel1.setText("IP");
jLabel2.setText("User");
jLabel3.setText("Passwd");
jLabel4.setText("Port");
textFieldIP.setText("192.168.0.74");
textFieldUser.setText("admin");
textFieldPasswd.setEchoChar('*');
textFieldPasswd.setText("888888");
textFieldPort.setText("81");
textFieldChan.setText("1");
label1.setText("Chan");
buttonStopRealPlay.setLabel("停止");
buttonStopRealPlay.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
buttonStopRealPlayActionPerformed(evt);
}
});
GroupLayout layout = new GroupLayout(this);
this.setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(GroupLayout.Alignment.LEADING)
.addComponent(panelRealPlay, javax.swing.GroupLayout.PREFERRED_SIZE, 191, javax.swing.GroupLay out.PREFERRED_SIZE)
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADIN
.addComponent(panelRealPlay, javax.swing.GroupLayout.DEFAULT_SIZE, 206, Short.MAX_VALUE))
);
}// </editor-fold>//GEN-END:initComponents
private void buttonRealPlayActionPerformed(ActionEvent evt)//GEN-FIRST:event_buttonRealPlayActionPerformed
{//GEN-HEADEREND:event_buttonRealPlayActionPerformed
//初始化
boolean binitSuc = HCNetSDK.INSTANCE.NET_DVR_Init();
if (binitSuc != true)
{
System.out.println("初始化失败");
} else
{
System.out.println("初始化成功");
}
//注册
DVR_DEVICEINFO.ByReference lpDeviceInfo=new DVR_DEVICEINFO.ByReference();
long lUserID = HCNetSDK.INSTANCE.NET_DVR_Login_V30(textFieldIP.getText(),
Integer.parseInt(textFieldPort.getText()),
textFieldUser.getText(),
textFieldPasswd.getText(),
lpDeviceInfo);
if (lUserID == -1)
{
System.out.println("登录设备失败");
return;
} else
{
System.out.println("登录设备成功,lUserID:"+lUserID);
}
//预览
HWND hWnd = new HWND(Native.getComponentPointer(panelRealPlay));//获取窗口句柄
HCNetSDK.NET_DVR_PREVIEWINFO lpPreviewInfo = new HCNetSDK.NET_DVR_PREVIEWINFO();
lpPreviewInfo.lChannel = 1;
lpPreviewInfo.dwStreamType = 0;
lpPreviewInfo.lLinkMode = 0;
lpPreviewInfo.hPlayWnd = hWnd;
lpPreviewInfo.bBlocked = false;
lpPreviewInfo.bPassbackRecord = true;
lpPreviewInfo.byPreviewMode = "0";
lpPreviewInfo.byStreamID = "50";
lpPreviewInfo.byProtoType = "0";
lpPreviewInfo.byRes1 = "0";
lpPreviewInfo.dwDisplayBufNum = 50;
lpPreviewInfo.byRes = "0";
long result;
result = HCNetSDK.INSTANCE.NET_DVR_RealPlay_V40(lUserID, lpPreviewInfo,
new HCNetSDK.RealDataCallback_V30() {
@Override
public void invoke(long lRealHandle, int dwDataType, String pBuffer,
int dwBufSize, String pUser) {
System.out.println("回调函数:");
}
}, "0.0.0.0");
public void init()
{
try
{
java.awt.EventQueue.invokeAndWait(new Runnable()
{
public void run()
{
initComponents();
}
});
} catch (Exception ex)
{
ex.printStackTrace();
}
}
调用NET_DVR_RealPlay_V40方法失败,通过NET_DVR_GetLastError取得错误信息,NET_DVR_LOAD_HCPREVIEW_SDK_ERROR-107错误:预览组件加载失败。跪求具体的结局方案,或者告知哪里编写有错误~求大神别潜水啊,跪求帮忙弄了一天了。