InitSDK.java 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. package com.gzlh.config.hksdk;
  2. import cn.hutool.log.StaticLog;
  3. import com.gzlh.utils.osSelect;
  4. import com.sun.jna.Native;
  5. import org.springframework.context.annotation.Bean;
  6. import org.springframework.stereotype.Component;
  7. import javax.annotation.Resource;
  8. @Component
  9. public class InitSDK {
  10. @Resource
  11. private HkLibProperties hkLibProperties;
  12. @Resource
  13. private FExceptionCallBack fExceptionCallBack;
  14. @Resource
  15. private MessageCallBack messageCallBack;
  16. /**
  17. * 动态库加载
  18. *
  19. * @return
  20. */
  21. @Bean
  22. public HCNetSDK gethCNetSDK() {
  23. synchronized (HCNetSDK.class) {
  24. HCNetSDK hCNetSDK = (HCNetSDK) Native.loadLibrary(hkLibProperties.getLibPath(), HCNetSDK.class);
  25. if (osSelect.isLinux()) {
  26. HCNetSDK.BYTE_ARRAY ptrByteArray1 = new HCNetSDK.BYTE_ARRAY(256);
  27. HCNetSDK.BYTE_ARRAY ptrByteArray2 = new HCNetSDK.BYTE_ARRAY(256);
  28. //这里是库的绝对路径,请根据实际情况修改,注意改路径必须有访问权限
  29. String strPath1 = hkLibProperties.getLinuxLibcryptoPath();
  30. String strPath2 = hkLibProperties.getLinuxLibsslPath();
  31. System.arraycopy(strPath1.getBytes(), 0, ptrByteArray1.byValue, 0, strPath1.length());
  32. ptrByteArray1.write();
  33. hCNetSDK.NET_DVR_SetSDKInitCfg(3, ptrByteArray1.getPointer());
  34. System.arraycopy(strPath2.getBytes(), 0, ptrByteArray2.byValue, 0, strPath2.length());
  35. ptrByteArray2.write();
  36. hCNetSDK.NET_DVR_SetSDKInitCfg(4, ptrByteArray2.getPointer());
  37. String strPathCom = hkLibProperties.getLibHome();
  38. HCNetSDK.NET_DVR_LOCAL_SDK_PATH struComPath = new HCNetSDK.NET_DVR_LOCAL_SDK_PATH();
  39. System.arraycopy(strPathCom.getBytes(), 0, struComPath.sPath, 0, strPathCom.length());
  40. struComPath.write();
  41. hCNetSDK.NET_DVR_SetSDKInitCfg(2, struComPath.getPointer());
  42. }
  43. boolean initSuc = hCNetSDK.NET_DVR_Init();
  44. if (!initSuc) {
  45. StaticLog.info("=========初始化海康SDK:失败==============");
  46. return null;
  47. }
  48. StaticLog.info("=========初始化海康SDK:成功==============");
  49. boolean callFlag = hCNetSDK.NET_DVR_SetExceptionCallBack_V30(0, 0, fExceptionCallBack, null);
  50. StaticLog.info("设置海康回调:{}", callFlag ? "成功-----------" : "失败---------->");
  51. boolean logFlag = hCNetSDK.NET_DVR_SetLogToFile(3, hkLibProperties.getLogHome(), false);
  52. StaticLog.info("设置海康日志目录:{},{}", hkLibProperties.getLogHome(), logFlag ? "成功-----------" : "失败---------->");
  53. boolean msgFlag = hCNetSDK.NET_DVR_SetDVRMessageCallBack_V50(1,messageCallBack,null);
  54. StaticLog.info("设置海康消息回调:{}",msgFlag? "成功-----------" : "失败---------->");
  55. return hCNetSDK;
  56. }
  57. }
  58. }