RTSP视频结构化智能分析平台EasyNVR通过Onvif协议停止调用云台接口为pending状态排查

在摄像头设备支持云台的情况下,视频结构化安防智能平台EasyNVR是支持通过onvif协议来调用摄像头的云台控制,但是在调用过程中,如果用户名和密码错误,调用停止云台控制接口会一直处于pending状态。

通过浏览器调试界面可以看到该接口的pending状态,一直没有返回内容。分析后端接口,发现具体到StopPTZ方法里面逻辑有问题,目前采用的逻辑如下:

func StopPTZ(host, username, password, deviceUrl string) (err error) {
   if dll == nil {
      err = fmt.Errorf("onvif dll not init")
      return
   }
   ptz := fmt.Sprintf("stop ptz host[%s] username[%s] password[%s] deviceUrl[%s]", host, username, password, deviceUrl)
   global.OperationLogger.Info(ptz)
   _host := uintptr(unsafe.Pointer(syscall.StringBytePtr(host)))
   _username := uintptr(unsafe.Pointer(syscall.StringBytePtr(username)))
   _password := uintptr(unsafe.Pointer(syscall.StringBytePtr(password)))
   _deviceUrl := uintptr(unsafe.Pointer(syscall.StringBytePtr(deviceUrl)))
 
   i := 1
   for i <= 500 {
      r1, _, _ := procStopPtz.Call(_host, _username, _password, _deviceUrl)
      if r1 == 0 {
         break
      }
      if i == 500 {
         log.Printf("EasyOnvifClient_StopPtz failed, ret[%d], retryed 5s", r1)
         err = fmt.Errorf("EasyOnvifClient_StopPtz failed, ret[%d]", r1)
      }
      time.Sleep(10 * time.Millisecond)
   }
 
   return
}
 

我们将其中的i := 1逻辑进行修改,且time.Sleep处为1而非为10,即可解决问题。修改后的逻辑代码参考如下:

func StopPTZ(host, username, password, deviceUrl string) (err error) {
   if dll == nil {
      err = fmt.Errorf("onvif dll not init")
      return
   }
   ptz := fmt.Sprintf("stop ptz host[%s] username[%s] password[%s] deviceUrl[%s]", host, username, password, deviceUrl)
   global.OperationLogger.Info(ptz)
   _host := uintptr(unsafe.Pointer(syscall.StringBytePtr(host)))
   _username := uintptr(unsafe.Pointer(syscall.StringBytePtr(username)))
   _password := uintptr(unsafe.Pointer(syscall.StringBytePtr(password)))
   _deviceUrl := uintptr(unsafe.Pointer(syscall.StringBytePtr(deviceUrl)))
 
   for i := 0; i <= 500; i += 100 {
      r1, _, _ := procStopPtz.Call(_host, _username, _password, _deviceUrl)
      if r1 == 0 {
         return
      }
      if i == 500 {
         log.Printf("EasyOnvifClient_StopPtz failed, ret[%d], retryed 5s", r1)
         err = fmt.Errorf("EasyOnvifClient_StopPtz failed, ret[%d], timeout 5s", r1)
      }
      time.Sleep(1 * time.Millisecond)
   }
 
   return
}
 

  

重新运行并调用接口检查,可以看到以上的报错内容消失,问题已解决:

 

 Onvif协议扩大了EasyNVR对设备的兼容性和控制性,之前我们为大家介绍过EasyNVR中onvif协议标准使用说明及配置方式,有兴趣可以了解一下,如果还想了解更多关于onvif或者EasyNVR的相关内容,欢迎关注我们。

 
原文地址:https://www.cnblogs.com/EasyNVR/p/14666954.html