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.

342 lines
9.7 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
5 months ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
la_mojo cameras: track PTZ health and re-initialise a failed PTZ protocol PTZ health per camera (deviceNodeCamera): - PTZ_HEALTH_INFO: state (NONE / INIT / OK / FAILED), failure and recovery counters, consecutive failed initialisations, time of the last state change / failure, next retry and the last error text. getPtzHealth() returns a copy (mutex-protected, any thread). - getPtzStatus() - already sent to the remote server as CAMERA_STATUS_PTZ_OK - now reflects it: 1 for OK (or no PTZ protocol), 0 while PTZ is initialising or failed. Before it was 1 as soon as the state machine left CAM_WS_INIT, whatever the protocol did. Failure detection and re-initialisation: - While idle (CAM_WS_READY) the camera checks the protocol's validate() every loop and calls the new protocolPTZ::probe() every 30 s (ONVIF: GetStatus; a SOAP Fault still means "reachable", only a communication error marks the camera lost). Default probe() is the protocol's validate(), so serial protocols are unchanged. - On failure the PTZ protocol is recreated through CAM_WS_INIT: first attempt at once, then 5, 10, 20, 40, 60 s (capped) between attempts; recoveries are logged and counted. - A failed target-driven goAbsolute/goPreset no longer ends the camera thread (CAM_WS_END rebuilt the whole node): for ONVIF a command the camera rejected (connection OK) only drops that ROI, anything else re-initialises the PTZ protocol. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0139veDo3XyavMuVhdnHcN16
12 hours ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
la_mojo cameras: track PTZ health and re-initialise a failed PTZ protocol PTZ health per camera (deviceNodeCamera): - PTZ_HEALTH_INFO: state (NONE / INIT / OK / FAILED), failure and recovery counters, consecutive failed initialisations, time of the last state change / failure, next retry and the last error text. getPtzHealth() returns a copy (mutex-protected, any thread). - getPtzStatus() - already sent to the remote server as CAMERA_STATUS_PTZ_OK - now reflects it: 1 for OK (or no PTZ protocol), 0 while PTZ is initialising or failed. Before it was 1 as soon as the state machine left CAM_WS_INIT, whatever the protocol did. Failure detection and re-initialisation: - While idle (CAM_WS_READY) the camera checks the protocol's validate() every loop and calls the new protocolPTZ::probe() every 30 s (ONVIF: GetStatus; a SOAP Fault still means "reachable", only a communication error marks the camera lost). Default probe() is the protocol's validate(), so serial protocols are unchanged. - On failure the PTZ protocol is recreated through CAM_WS_INIT: first attempt at once, then 5, 10, 20, 40, 60 s (capped) between attempts; recoveries are logged and counted. - A failed target-driven goAbsolute/goPreset no longer ends the camera thread (CAM_WS_END rebuilt the whole node): for ONVIF a command the camera rejected (connection OK) only drops that ROI, anything else re-initialises the PTZ protocol. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0139veDo3XyavMuVhdnHcN16
12 hours ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
la_mojo cameras: track PTZ health and re-initialise a failed PTZ protocol PTZ health per camera (deviceNodeCamera): - PTZ_HEALTH_INFO: state (NONE / INIT / OK / FAILED), failure and recovery counters, consecutive failed initialisations, time of the last state change / failure, next retry and the last error text. getPtzHealth() returns a copy (mutex-protected, any thread). - getPtzStatus() - already sent to the remote server as CAMERA_STATUS_PTZ_OK - now reflects it: 1 for OK (or no PTZ protocol), 0 while PTZ is initialising or failed. Before it was 1 as soon as the state machine left CAM_WS_INIT, whatever the protocol did. Failure detection and re-initialisation: - While idle (CAM_WS_READY) the camera checks the protocol's validate() every loop and calls the new protocolPTZ::probe() every 30 s (ONVIF: GetStatus; a SOAP Fault still means "reachable", only a communication error marks the camera lost). Default probe() is the protocol's validate(), so serial protocols are unchanged. - On failure the PTZ protocol is recreated through CAM_WS_INIT: first attempt at once, then 5, 10, 20, 40, 60 s (capped) between attempts; recoveries are logged and counted. - A failed target-driven goAbsolute/goPreset no longer ends the camera thread (CAM_WS_END rebuilt the whole node): for ONVIF a command the camera rejected (connection OK) only drops that ROI, anything else re-initialises the PTZ protocol. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0139veDo3XyavMuVhdnHcN16
12 hours ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. //----------------------------------------------------------------------------
  2. // Dr.Frucht Systems Ltd.
  3. // Copyright � 2000-2017. All Rights Reserved.
  4. // Version 2.0 6/11/2019
  5. // Last modification: 6/11/2019
  6. // PROJECT:
  7. // SUBSYSTEM:
  8. // FILE: rgooseIPCamera.h
  9. // AUTHOR: gagua
  10. // OVERVIEW
  11. // ~~~~~~~~
  12. // Header file of rgooseIPCamera.h
  13. //----------------------------------------------------------------------------
  14. //
  15. #ifndef __DEVICE_NODE_CAMERA_HEADER__
  16. #define __DEVICE_NODE_CAMERA_HEADER__
  17. #include "../../components/base/basicEventHeap.h"
  18. #include "../../components/base/basicMutex.h"
  19. #include "../../components/base/basicThread.h"
  20. #include "../../data/protocol/protocolPTZ.h"
  21. #include <queue>
  22. #include <vector>
  23. // #include "rgooseDBConnector.h"
  24. #include "deviceNode.h"
  25. // https://www.ebay.com/itm/Professional-Rolling-Makeup-Case-Bulb-Mirror-Cosmetic-Artist-Dressing-Train-Case/233264525474
  26. // ffmpeg -i input.mp4 -af loudnorm=I=-23:LRA=7:tp=-2:print_format=json -f null -
  27. // ffmpeg -i input.mp4 -af loudnorm=I=-23:LRA=7:tp=-2:measured_I=-30:measured_LRA=1.1:measured_tp=-11 04:measured_thresh=-40.21:offset=-0.47 -ar 48k -y output.mp4
  28. #define CAM_POST_INIT
  29. //#define NO_CAMERA_FUSION_ENGINE
  30. #define CAM_CTRL_PROTO_VISCA 1
  31. #define CAM_CTRL_PROTO_PELCO 2
  32. #define CAM_CTRL_PROTO_ONVIF 3
  33. #define CAM_CTRL_PROTO_PSIA 4
  34. #define CAM_CTRL_PROTO_T28181 5
  35. #define CAM_CTRL_PROTO_BRCP 6
  36. // Wait before EVT_CAMERA_ON_POSITION when the protocol cannot report the end of a move
  37. #define CAM_MOVE_FIXED_WAIT_MS 3000
  38. #define UART_TYPE_HARDWARE 1
  39. #define UART_TYPE_SOL 2
  40. #define ARGUS_CAM_PCMD_MOVE_MASK 0x7F
  41. #define ARGUS_CAM_PCMD_CMD_MASK 0x80
  42. #define ARGUS_CAM_PCMD_STOP 1
  43. #define ARGUS_PRESET_TYPE_POSITION 1
  44. #define ARGUS_PRESET_TYPE_HOME 2
  45. #define ARGUS_PRESET_TYPE_IR_AUTO 3
  46. #define ARGUS_PRESET_TYPE_IR_ON 4
  47. #define ARGUS_PRESET_TYPE_IR_OFF 5
  48. #define ARGUS_PRESET_TYPE_IR_WISHER 6
  49. #define DEFAULT_SHINE_ON_TARGET_TO 60 // seconds
  50. typedef struct S_CAM_PTZ_CMD
  51. {
  52. uint8_t CMD;
  53. float PAN;
  54. float TILT;
  55. float ZOOM;
  56. } CAM_PTZ_CMD;
  57. typedef enum E_CAM_PTZ_CMD
  58. {
  59. PTZ_STOP = 0,
  60. PTZ_MOVE = 1,
  61. PTZ_ABSOLUTE = 2,
  62. PTZ_RELOAD_CAMERA = 3,
  63. PTZ_CAPTURE_ONLY = 4,
  64. PTZ_SET_PRESET = 5,
  65. PTZ_CALL_PRESET = 6
  66. } PTZ_CMD;
  67. typedef std::queue<CAM_PTZ_CMD *> CAM_PTZ_CMD_QUEUE;
  68. typedef enum E_CAM_WORKING_STATE
  69. {
  70. CAM_WS_INIT = 0,
  71. CAM_WS_POWER_INIT = 1,
  72. CAM_WS_WHITE_BALLANCE = 2,
  73. CAM_WS_BACKLIGHT = 3,
  74. CAM_WS_AUTO_FOCUS = 4,
  75. CAM_WS_INIT_GO_HOME = 5,
  76. CAM_WS_AUTOMATED_MOVE = 10,
  77. CAM_WS_STOP_MOVE = 11,
  78. CAM_WS_GO_ABS_POSITION = 12,
  79. CAM_WS_GO_HOMING_PRESET = 13,
  80. CAM_WS_GO_PRESET = 14,
  81. CAM_WS_GO_ABS_ROI = 15,
  82. CAM_WS_SET_PRESET = 16,
  83. CAM_WS_READY = 64,
  84. CAM_WS_BUSY = 128,
  85. CAM_WS_WAIT_ONPOS = 129,
  86. CAM_WS_END = 255
  87. } CAM_WORK_STATE;
  88. /*
  89. PTZ control health of a camera (deviceNodeCamera::getPtzHealth), e.g. for the health status sent to the
  90. remote server. getPtzStatus() > 0 <=> state is PTZ_HEALTH_OK or PTZ_HEALTH_NONE.
  91. */
  92. typedef enum E_PTZ_HEALTH_STATE
  93. {
  94. PTZ_HEALTH_NONE = 0, // camera has no PTZ control protocol (static camera): nothing that can fail
  95. PTZ_HEALTH_INIT = 1, // protocol not created yet (first initialisation)
  96. PTZ_HEALTH_OK = 2, // protocol created and working
  97. PTZ_HEALTH_FAILED = 3 // protocol lost or cannot be created; re-initialisation is retried (next_retry)
  98. } PTZ_HEALTH_STATE;
  99. typedef struct S_PTZ_HEALTH_INFO
  100. {
  101. PTZ_HEALTH_STATE state;
  102. uint32_t failures; // PTZ failures detected since start (lost protocol / failed init)
  103. uint32_t recoveries; // successful re-initialisations after a failure
  104. uint32_t failed_inits; // consecutive failed initialisations (reset on success)
  105. time_t since; // time of the last state change
  106. time_t last_failure; // time of the last failure (0 = never)
  107. time_t next_retry; // next re-initialisation attempt while FAILED (0 = none)
  108. char last_error[128];
  109. } PTZ_HEALTH_INFO;
  110. #define CAM_PTZ_PROBE_INTERVAL_S 30 // idle liveness check of the PTZ protocol (protocolPTZ::probe)
  111. #define CAM_PTZ_RETRY_MIN_S 5 // first re-initialisation delay after a failure
  112. #define CAM_PTZ_RETRY_MAX_S 60 // delay doubles per failed attempt up to this
  113. typedef struct S_CAM_TASK
  114. {
  115. bool isDone;
  116. uint32_t source_evt_id;
  117. bool movemet_needed;
  118. CAM_PTZ_CMD * CMD;
  119. } CAM_TASK;
  120. typedef std::queue<CAM_TASK *> CAM_TASK_QUEUE;
  121. #define LOSE_INTERES_TIME_MS 2000
  122. inline CAM_ROI * createCAM_ROI(void)
  123. {
  124. //CAM_ROI * tROI = (CAM_ROI *) malloc(sizeof(CAM_ROI));
  125. CAM_ROI * tROI = new CAM_ROI();
  126. if (tROI)
  127. {
  128. //memset(tROI, 0, sizeof(CAM_ROI));
  129. tROI->targets.clear();
  130. };
  131. return tROI;
  132. }
  133. inline void utilizeROI(CAM_ROI *& ptr)
  134. {
  135. if (ptr)
  136. {
  137. if (ptr->targets.size())
  138. {
  139. for (vCAM_TRACK_RECORDS::iterator idx = ptr->targets.begin(); idx != ptr->targets.end(); idx++)
  140. {
  141. free(*idx);
  142. }
  143. ptr->targets.clear();
  144. };
  145. //free(ptr);
  146. delete( ptr );
  147. ptr = NULL;
  148. };
  149. }
  150. class deviceNodeCamera : public deviceNode, public basicThread
  151. {
  152. private:
  153. basicPosition m_oPosition;
  154. time_t m_tTimeTSeconds;
  155. CAM_ROI * m_pCurrentROI;
  156. float m_fMaxRange;
  157. float m_fMinRange;
  158. float m_fMaxFL;
  159. float m_fMinFL;
  160. float m_fR2FL; // Range to Focal Length
  161. float m_fZoomCorrection;
  162. uint16_t m_nRealFrameWidth;
  163. uint16_t m_nRealFrameHeight;
  164. float m_fMinHFov;
  165. float m_fMaxHFov;
  166. float m_fMinVFov;
  167. float m_fMaxVFov;
  168. protocolPTZ * m_pProtocol;
  169. // PTZ health (written by the camera thread, read by others through getPtzHealth / getPtzStatus)
  170. PTZ_HEALTH_INFO m_sPtzHealth;
  171. basicMutex m_mPtzHealth;
  172. time_t m_tPtzLastProbe;
  173. void ptzHealthSet(PTZ_HEALTH_STATE state, const char * reason = NULL);
  174. bool ptzReinitDue(void);
  175. void ptzCheck(uint8_t tState);
  176. void ptzLost(const char * reason);
  177. void ptzCommandFailed(const char * command);
  178. // basicTransport * m_pTransport;
  179. CAM_TASK_QUEUE m_qCAM_TASK;
  180. basicMutex m_mQPROTECTOR;
  181. uint32_t m_nRelativeMoveCounter;
  182. uint32_t m_nHomingCounter;
  183. uint8_t m_bRelativeMoveMatrix;
  184. uint8_t m_bCurrentPresetCol;
  185. uint8_t m_bCurrentPresetRow;
  186. float m_fSpeedRise;
  187. float m_fRM_Pan;
  188. float m_fRM_Tilt;
  189. float m_fRM_Zoom;
  190. float m_fCP_Pan;
  191. float m_fCP_Tilt;
  192. float m_fCP_Zoom;
  193. bool m_bSkeepPositioningWait;
  194. bool m_bNoMoveDoneReport; // protocol cannot report the end of a move -> fixed wait before EVT_CAMERA_ON_POSITION
  195. bool m_bNoAbsPositionning;
  196. bool m_bCameraIsStatic;
  197. // IR functionality
  198. basicMutex m_mIRProtector;
  199. bool m_bShineOnTarget;
  200. bool m_bIRIsOn;
  201. uint8_t m_bIRTO; // Default 60 seconds (1 video slice)
  202. //
  203. bool m_bCameraOnHomePosition;
  204. /* Methotds Sutable to Control Camera */
  205. bool relativeMove(float PanSPD, float TiltSPD, float ZoomSPD);
  206. bool relativeStop();
  207. bool absoluteMove(uint32_t RefID, float PanPOS, float TiltPOS, float ZoomPOS);
  208. bool absoluteMove(uint32_t RefID, C3D_ORIENT_ONVIF O);
  209. void updateOpticalParameters(uint16_t frame_width, uint16_t frame_heigth);
  210. void translateROI2PRESET(float P, float T, float Z, uint8_t & col, uint8_t & row);
  211. protected:
  212. DBC_CAM_DATA m_sCamData;
  213. MEDIA_SOURCE_DESC m_sMediaSource;
  214. basicEventHeap * m_pBEH;
  215. // bool m_bSourceConnected;
  216. // uint32_t m_nActiveStreamID;
  217. // bool inTheFOV( float lat, float lon, float alt );
  218. #ifndef NO_CAMERA_FUSION_ENGINE
  219. /* tracking Fusion methods */
  220. vCAM_ROIS m_vROIS;
  221. basicMutex m_mROIsProtector;
  222. bool fusion_consumeData(uint32_t db_id, C3D_SPH_DEGREES tOR);
  223. bool fusion_validateROI(uint64_t cts, CAM_ROI * ptr);
  224. bool fusion_compare(CAM_ROI * ptr, C3D_SPH_DEGREES tp);
  225. void fusion_validate(void);
  226. CAM_ROI * fusion_fetchROI(void);
  227. DBC_SNAPSHOT_DATA * fusion_translate_ROI(CAM_ROI *(&ptr));
  228. #else
  229. #endif
  230. /* presets Fusion methods */
  231. CAM_PRESETS_SET m_sCamPresets;
  232. virtual bool load_presets(void);
  233. CSTR getPresetToken(uint8_t CCOL, uint8_t CROW);
  234. CSTR getPresetToken(uint8_t specialRole);
  235. bool testFOV(C3D_WGS84_LOC); // Global Coords
  236. bool testFOV(C3D_DECART); // System Coords
  237. bool testFOV(C3D_SPH_RADIANS); // Local Coords
  238. bool testFOV(C3D_SPH_DEGREES); // Local Coords
  239. // bool lookAtWGS84( uint32_t TargetRefID, float lat, float lon, float alt );
  240. bool lookAt(uint32_t TargetRefID, C3D_WGS84_LOC L); // GLobal
  241. bool lookAt(uint32_t TargetRefID, C3D_DECART L); // System
  242. bool lookAt(uint32_t TargetRefID, C3D_SPH_RADIANS L); // Local
  243. bool lookAt(uint32_t TargetRefID, C3D_SPH_DEGREES L); // Local
  244. bool makeSnap(uint32_t TargetRefID);
  245. // void setBusy( bool Status );
  246. bool connectToStream(uint32_t id);
  247. bool disconnectFromStream(void);
  248. CAM_TASK * fetchCamTask(void);
  249. bool pushCamTask(CAM_TASK *);
  250. virtual void m_fThreadProc(void);
  251. public:
  252. explicit deviceNodeCamera(uint32_t NodeID);
  253. explicit deviceNodeCamera(DBC_NODE_DATA * Data);
  254. virtual ~deviceNodeCamera();
  255. bool create();
  256. virtual bool validate();
  257. virtual bool validateStream(void);
  258. bool setNoPositionWait(bool FL = true);
  259. virtual uint8_t getCamStatus()
  260. {
  261. return (uint8_t) m_sCamData.online;
  262. }
  263. uint32_t getCamStream()
  264. {
  265. return m_sCamData.stream_id;
  266. }
  267. virtual uint8_t getFlipMode()
  268. {
  269. return m_sCamData.flip_mode;
  270. }
  271. virtual uint8_t getPtzStatus();
  272. void getPtzHealth(PTZ_HEALTH_INFO * info);
  273. virtual uint8_t getStreamStatus();
  274. virtual float getSystemLocationX(){
  275. return m_sCamData.x;
  276. };
  277. virtual float getSystemLocationY(){
  278. return m_sCamData.y;
  279. };
  280. virtual float getSystemLocationZ(){
  281. return m_sCamData.z;
  282. };
  283. virtual float getMaxRange(){
  284. return m_fMaxRange;
  285. };
  286. };
  287. typedef std::vector<deviceNodeCamera *> vectorNodeCameras;
  288. #endif