You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

84 lines
3.0 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. #ifndef __PROTOCOL_PTZ_ONVIF_HEADER__
  2. #define __PROTOCOL_PTZ_ONVIF_HEADER__
  3. #include "protocolPTZ.h"
  4. #define USE_PONVIF
  5. #ifdef USE_PONVIF
  6. #include "../ponvif/ponvif.h"
  7. #else
  8. #include "../onvif/include/onvifclient.hpp"
  9. #endif
  10. /*
  11. Waiting for the end of an AbsoluteMove (waitMoveIsDone):
  12. - camera reports MoveStatus -> poll GetStatus until pan/tilt and zoom are IDLE
  13. - camera reports Position -> poll GetStatus until the target is reached or the position stops changing
  14. - camera reports neither -> fixed wait (PTZ_ONVIF_FIXED_MOVE_WAIT_MS)
  15. What the camera reports is detected once in create() (PTZ GetServiceCapabilities + a real GetStatus).
  16. */
  17. #define PTZ_ONVIF_STATUS_POLL_MS 200 // GetStatus polling period
  18. #define PTZ_ONVIF_MOVE_TIMEOUT_MS 10000 // give up waiting for the end of a move after this
  19. #define PTZ_ONVIF_MOVE_START_GRACE_MS 1000 // a camera may still report IDLE / old position right after the command
  20. #define PTZ_ONVIF_FIXED_MOVE_WAIT_MS 3000 // wait for cameras that report neither MoveStatus nor Position
  21. #define PTZ_ONVIF_POS_TOLERANCE 0.01f // target reached (generic space units)
  22. #define PTZ_ONVIF_POS_STABLE_EPS 0.001f // position "not changing" between two polls
  23. #define PTZ_ONVIF_POS_STABLE_POLLS 2 // consecutive unchanged polls = move finished
  24. #define PTZ_ONVIF_MAX_STATUS_FAILURES 3 // consecutive GetStatus failures before falling back to the fixed wait
  25. class protocolPTZ_ONVIF : public protocolPTZ
  26. {
  27. private:
  28. basicLogCollection * m_pLog;
  29. char m_pUser[MAX_CRED_LEN];
  30. char m_pPassword[MAX_CRED_LEN];
  31. char m_pDeviceURI[MAX_PATH_LEN];
  32. uint8_t m_bAuthMode;
  33. #ifdef USE_PONVIF
  34. pOnvif * m_pOnVif;
  35. videoSourceProfile * m_pProfile;
  36. #else
  37. OnvifClientDevice * m_pDevice;
  38. OnvifClientPTZ * m_pPTZ;
  39. std::string m_pPTZToken;
  40. std::string m_pMediaToken;
  41. #endif
  42. config_setting_t * m_pSettings;
  43. basicMutex m_mInquiryMutex;
  44. #ifdef USE_PONVIF
  45. bool m_bReportsMoveStatus; // camera reports PTZStatus/MoveStatus (IDLE/MOVING)
  46. bool m_bReportsPosition; // camera reports PTZStatus/Position
  47. bool m_bTargetValid; // m_fTarget* hold the last AbsoluteMove target
  48. float m_fTargetPan;
  49. float m_fTargetTilt;
  50. float m_fTargetZoom;
  51. void detectStatusSupport(void);
  52. bool fixedMoveWait(long alreadyWaitedMs);
  53. #endif
  54. public:
  55. explicit protocolPTZ_ONVIF(config_setting_t * Settings = NULL);
  56. protocolPTZ_ONVIF(CSTR ip, uint16_t port, CSTR username, CSTR password, uint8_t AuthMode = 0);
  57. protocolPTZ_ONVIF(CSTR ctl_url, CSTR username, CSTR password, uint8_t AuthMode = 0);
  58. virtual ~protocolPTZ_ONVIF();
  59. virtual bool create(void);
  60. #ifndef USE_PONVIF
  61. bool initCamera(void);
  62. #endif
  63. virtual bool move(uint32_t MoveMatrix);
  64. virtual bool goAbsolute(float dPan, float dTilt, float dZoom);
  65. virtual bool goPreset(char * PresetToken);
  66. virtual bool getCameraPresets(void);
  67. bool setIPAddress(CSTR ip);
  68. bool setUsername(CSTR username);
  69. bool setPassword(CSTR password);
  70. bool setAuthMode(uint8_t Mode);
  71. virtual bool waitMoveIsDone(void);
  72. virtual bool validate();
  73. };
  74. #endif