1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768 |
- package com.gzlh.config.hksdk;
- import cn.hutool.log.StaticLog;
- import com.gzlh.utils.osSelect;
- import com.sun.jna.Native;
- import org.springframework.context.annotation.Bean;
- import org.springframework.stereotype.Component;
- import javax.annotation.Resource;
- @Component
- public class InitSDK {
- @Resource
- private HkLibProperties hkLibProperties;
- @Resource
- private FExceptionCallBack fExceptionCallBack;
- @Resource
- private MessageCallBack messageCallBack;
- /**
- * 动态库加载
- *
- * @return
- */
- @Bean
- public HCNetSDK gethCNetSDK() {
- synchronized (HCNetSDK.class) {
- HCNetSDK hCNetSDK = (HCNetSDK) Native.loadLibrary(hkLibProperties.getLibPath(), HCNetSDK.class);
- if (osSelect.isLinux()) {
- HCNetSDK.BYTE_ARRAY ptrByteArray1 = new HCNetSDK.BYTE_ARRAY(256);
- HCNetSDK.BYTE_ARRAY ptrByteArray2 = new HCNetSDK.BYTE_ARRAY(256);
- //这里是库的绝对路径,请根据实际情况修改,注意改路径必须有访问权限
- String strPath1 = hkLibProperties.getLinuxLibcryptoPath();
- String strPath2 = hkLibProperties.getLinuxLibsslPath();
- System.arraycopy(strPath1.getBytes(), 0, ptrByteArray1.byValue, 0, strPath1.length());
- ptrByteArray1.write();
- hCNetSDK.NET_DVR_SetSDKInitCfg(3, ptrByteArray1.getPointer());
- System.arraycopy(strPath2.getBytes(), 0, ptrByteArray2.byValue, 0, strPath2.length());
- ptrByteArray2.write();
- hCNetSDK.NET_DVR_SetSDKInitCfg(4, ptrByteArray2.getPointer());
- String strPathCom = hkLibProperties.getLibHome();
- HCNetSDK.NET_DVR_LOCAL_SDK_PATH struComPath = new HCNetSDK.NET_DVR_LOCAL_SDK_PATH();
- System.arraycopy(strPathCom.getBytes(), 0, struComPath.sPath, 0, strPathCom.length());
- struComPath.write();
- hCNetSDK.NET_DVR_SetSDKInitCfg(2, struComPath.getPointer());
- }
- boolean initSuc = hCNetSDK.NET_DVR_Init();
- if (!initSuc) {
- StaticLog.info("=========初始化海康SDK:失败==============");
- return null;
- }
- StaticLog.info("=========初始化海康SDK:成功==============");
- boolean callFlag = hCNetSDK.NET_DVR_SetExceptionCallBack_V30(0, 0, fExceptionCallBack, null);
- StaticLog.info("设置海康回调:{}", callFlag ? "成功-----------" : "失败---------->");
- boolean logFlag = hCNetSDK.NET_DVR_SetLogToFile(3, hkLibProperties.getLogHome(), false);
- StaticLog.info("设置海康日志目录:{},{}", hkLibProperties.getLogHome(), logFlag ? "成功-----------" : "失败---------->");
- boolean msgFlag = hCNetSDK.NET_DVR_SetDVRMessageCallBack_V50(1,messageCallBack,null);
- StaticLog.info("设置海康消息回调:{}",msgFlag? "成功-----------" : "失败---------->");
- return hCNetSDK;
- }
- }
- }
|