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.

363 lines
11 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
6 days ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
Camera: re-create only the PTZ protocol on ONVIF trouble, keep the node and its stream A pOnvif problem could delete and re-create the whole camera node, which dropped the video stream bound to it, so recordings were cut although the video was fine. deviceNodeCamera::validate() compared the whole camera record with memcmp; any difference rebuilt the node: - CAM_WS_INIT sets m_sCamData.online = false before re-creating the PTZ protocol and writes the DB only afterwards. A validate() during a slow ONVIF re-init saw "online" differ and deleted the camera mid-re-init. - The ONVIF discovery (updateIPCam) wrote online=1 and the whole XAddrs list into onvif_ctrl (the web UI and la_mojo store only the path), so the record changed on discovery rounds. - A failed read (SQLite busy, queries fail at once) returned NULL = "camera deleted". Now: - Field classes (camDataChange): - runtime and discovery fields (online, status, session, max_range, uuid, mac): ignored; - name and hardware: taken over; - PTZ access (onvif_ctrl, onvif_access, port, auth_mode, ptz_token): the camera thread re-creates only the PTZ protocol, keeping the node and the stream; - anything else (ip and credentials used by the stream, stream_id, type, geometry, ...): rebuild as before, logged with the reason. - A lasting PTZ problem rebuilds the camera only after CAM_REBUILD_AFTER_FAILED_INITS (10) failed protocol initialisations in a row (several minutes with the retry back-off). - Node / camera record not read: rebuild only after NODE_DATA_MISSES_TO_REBUILD (3) validations in a row, for all nodes (deviceNode::validate). - updateIPCam: onvif_ctrl = path of the first XAddr. Host and port come from the first XAddr only: ':' was searched in the whole list, so a second, IPv6 XAddr gave a broken IP. A result without an address doesn't wipe the IP. Tested (functions extracted unchanged): camDataChange classifies online / status / max_range / uuid / mac as ignored, rename as cosmetic, port / onvif_ctrl / auth / ptz token as PTZ re-init, and ip / password / stream / geometry as rebuild. The XAddrs parser was checked with a port, without a port, with an IPv6 second XAddr, with a query, and with no address. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0139veDo3XyavMuVhdnHcN16
4 hours ago
Camera: re-create only the PTZ protocol on ONVIF trouble, keep the node and its stream A pOnvif problem could delete and re-create the whole camera node, which dropped the video stream bound to it, so recordings were cut although the video was fine. deviceNodeCamera::validate() compared the whole camera record with memcmp; any difference rebuilt the node: - CAM_WS_INIT sets m_sCamData.online = false before re-creating the PTZ protocol and writes the DB only afterwards. A validate() during a slow ONVIF re-init saw "online" differ and deleted the camera mid-re-init. - The ONVIF discovery (updateIPCam) wrote online=1 and the whole XAddrs list into onvif_ctrl (the web UI and la_mojo store only the path), so the record changed on discovery rounds. - A failed read (SQLite busy, queries fail at once) returned NULL = "camera deleted". Now: - Field classes (camDataChange): - runtime and discovery fields (online, status, session, max_range, uuid, mac): ignored; - name and hardware: taken over; - PTZ access (onvif_ctrl, onvif_access, port, auth_mode, ptz_token): the camera thread re-creates only the PTZ protocol, keeping the node and the stream; - anything else (ip and credentials used by the stream, stream_id, type, geometry, ...): rebuild as before, logged with the reason. - A lasting PTZ problem rebuilds the camera only after CAM_REBUILD_AFTER_FAILED_INITS (10) failed protocol initialisations in a row (several minutes with the retry back-off). - Node / camera record not read: rebuild only after NODE_DATA_MISSES_TO_REBUILD (3) validations in a row, for all nodes (deviceNode::validate). - updateIPCam: onvif_ctrl = path of the first XAddr. Host and port come from the first XAddr only: ':' was searched in the whole list, so a second, IPv6 XAddr gave a broken IP. A result without an address doesn't wipe the IP. Tested (functions extracted unchanged): camDataChange classifies online / status / max_range / uuid / mac as ignored, rename as cosmetic, port / onvif_ctrl / auth / ptz token as PTZ re-init, and ip / password / stream / geometry as rebuild. The XAddrs parser was checked with a port, without a port, with an IPv6 second XAddr, with a query, and with no address. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0139veDo3XyavMuVhdnHcN16
4 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
6 days 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
6 days ago
​
​
​
​
​
​
​
​
​
Camera: re-create only the PTZ protocol on ONVIF trouble, keep the node and its stream A pOnvif problem could delete and re-create the whole camera node, which dropped the video stream bound to it, so recordings were cut although the video was fine. deviceNodeCamera::validate() compared the whole camera record with memcmp; any difference rebuilt the node: - CAM_WS_INIT sets m_sCamData.online = false before re-creating the PTZ protocol and writes the DB only afterwards. A validate() during a slow ONVIF re-init saw "online" differ and deleted the camera mid-re-init. - The ONVIF discovery (updateIPCam) wrote online=1 and the whole XAddrs list into onvif_ctrl (the web UI and la_mojo store only the path), so the record changed on discovery rounds. - A failed read (SQLite busy, queries fail at once) returned NULL = "camera deleted". Now: - Field classes (camDataChange): - runtime and discovery fields (online, status, session, max_range, uuid, mac): ignored; - name and hardware: taken over; - PTZ access (onvif_ctrl, onvif_access, port, auth_mode, ptz_token): the camera thread re-creates only the PTZ protocol, keeping the node and the stream; - anything else (ip and credentials used by the stream, stream_id, type, geometry, ...): rebuild as before, logged with the reason. - A lasting PTZ problem rebuilds the camera only after CAM_REBUILD_AFTER_FAILED_INITS (10) failed protocol initialisations in a row (several minutes with the retry back-off). - Node / camera record not read: rebuild only after NODE_DATA_MISSES_TO_REBUILD (3) validations in a row, for all nodes (deviceNode::validate). - updateIPCam: onvif_ctrl = path of the first XAddr. Host and port come from the first XAddr only: ':' was searched in the whole list, so a second, IPv6 XAddr gave a broken IP. A result without an address doesn't wipe the IP. Tested (functions extracted unchanged): camDataChange classifies online / status / max_range / uuid / mac as ignored, rename as cosmetic, port / onvif_ctrl / auth / ptz token as PTZ re-init, and ip / password / stream / geometry as rebuild. The XAddrs parser was checked with a port, without a port, with an IPv6 second XAddr, with a query, and with no address. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0139veDo3XyavMuVhdnHcN16
4 hours ago
​
​
​
​
​
​
Camera: re-create only the PTZ protocol on ONVIF trouble, keep the node and its stream A pOnvif problem could delete and re-create the whole camera node, which dropped the video stream bound to it, so recordings were cut although the video was fine. deviceNodeCamera::validate() compared the whole camera record with memcmp; any difference rebuilt the node: - CAM_WS_INIT sets m_sCamData.online = false before re-creating the PTZ protocol and writes the DB only afterwards. A validate() during a slow ONVIF re-init saw "online" differ and deleted the camera mid-re-init. - The ONVIF discovery (updateIPCam) wrote online=1 and the whole XAddrs list into onvif_ctrl (the web UI and la_mojo store only the path), so the record changed on discovery rounds. - A failed read (SQLite busy, queries fail at once) returned NULL = "camera deleted". Now: - Field classes (camDataChange): - runtime and discovery fields (online, status, session, max_range, uuid, mac): ignored; - name and hardware: taken over; - PTZ access (onvif_ctrl, onvif_access, port, auth_mode, ptz_token): the camera thread re-creates only the PTZ protocol, keeping the node and the stream; - anything else (ip and credentials used by the stream, stream_id, type, geometry, ...): rebuild as before, logged with the reason. - A lasting PTZ problem rebuilds the camera only after CAM_REBUILD_AFTER_FAILED_INITS (10) failed protocol initialisations in a row (several minutes with the retry back-off). - Node / camera record not read: rebuild only after NODE_DATA_MISSES_TO_REBUILD (3) validations in a row, for all nodes (deviceNode::validate). - updateIPCam: onvif_ctrl = path of the first XAddr. Host and port come from the first XAddr only: ':' was searched in the whole list, so a second, IPv6 XAddr gave a broken IP. A result without an address doesn't wipe the IP. Tested (functions extracted unchanged): camDataChange classifies online / status / max_range / uuid / mac as ignored, rename as cosmetic, port / onvif_ctrl / auth / ptz token as PTZ re-init, and ip / password / stream / geometry as rebuild. The XAddrs parser was checked with a port, without a port, with an IPv6 second XAddr, with a query, and with no address. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0139veDo3XyavMuVhdnHcN16
4 hours ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
4 days 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
6 days 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. /*
  114. PTZ trouble:
  115. - the protocol is re-created; when it works again within a few attempts the camera goes straight back to
  116. CAM_WS_READY (no power mode / WB / BLC / AF / home again: its settings are unchanged)
  117. - CAM_REBUILD_AFTER_FAILED_INITS failed re-creations in a row (with the back-off 0, 5, 10 s ...) are a major
  118. problem (camera power supply, network): the node is rebuilt and the new node fully initialises the camera.
  119. Only for a camera whose protocol worked in this node - one that never worked keeps retrying (back-off).
  120. */
  121. #ifndef CAM_REBUILD_AFTER_FAILED_INITS
  122. #define CAM_REBUILD_AFTER_FAILED_INITS 3
  123. #endif
  124. typedef struct S_CAM_TASK
  125. {
  126. bool isDone;
  127. uint32_t source_evt_id;
  128. bool movemet_needed;
  129. CAM_PTZ_CMD * CMD;
  130. } CAM_TASK;
  131. typedef std::queue<CAM_TASK *> CAM_TASK_QUEUE;
  132. #define LOSE_INTERES_TIME_MS 2000
  133. inline CAM_ROI * createCAM_ROI(void)
  134. {
  135. //CAM_ROI * tROI = (CAM_ROI *) malloc(sizeof(CAM_ROI));
  136. CAM_ROI * tROI = new CAM_ROI();
  137. if (tROI)
  138. {
  139. //memset(tROI, 0, sizeof(CAM_ROI));
  140. tROI->targets.clear();
  141. };
  142. return tROI;
  143. }
  144. inline void utilizeROI(CAM_ROI *& ptr)
  145. {
  146. if (ptr)
  147. {
  148. if (ptr->targets.size())
  149. {
  150. for (vCAM_TRACK_RECORDS::iterator idx = ptr->targets.begin(); idx != ptr->targets.end(); idx++)
  151. {
  152. free(*idx);
  153. }
  154. ptr->targets.clear();
  155. };
  156. //free(ptr);
  157. delete( ptr );
  158. ptr = NULL;
  159. };
  160. }
  161. class deviceNodeCamera : public deviceNode, public basicThread
  162. {
  163. private:
  164. basicPosition m_oPosition;
  165. time_t m_tTimeTSeconds;
  166. CAM_ROI * m_pCurrentROI;
  167. float m_fMaxRange;
  168. float m_fMinRange;
  169. float m_fMaxFL;
  170. float m_fMinFL;
  171. float m_fR2FL; // Range to Focal Length
  172. float m_fZoomCorrection;
  173. uint16_t m_nRealFrameWidth;
  174. uint16_t m_nRealFrameHeight;
  175. float m_fMinHFov;
  176. float m_fMaxHFov;
  177. float m_fMinVFov;
  178. float m_fMaxVFov;
  179. protocolPTZ * m_pProtocol;
  180. // PTZ health (written by the camera thread, read by others through getPtzHealth / getPtzStatus)
  181. PTZ_HEALTH_INFO m_sPtzHealth;
  182. basicMutex m_mPtzHealth;
  183. time_t m_tPtzLastProbe;
  184. void ptzHealthSet(PTZ_HEALTH_STATE state, const char * reason = NULL);
  185. bool ptzReinitDue(void);
  186. void ptzCheck(uint8_t tState);
  187. void ptzLost(const char * reason);
  188. void ptzCommandFailed(const char * command);
  189. // Camera settings changed in the DB (validate, node factory thread) that need only a PTZ protocol
  190. // re-initialisation or no action: applied by the camera thread (it owns m_sCamData)
  191. basicMutex m_mPendingCamData;
  192. DBC_CAM_DATA m_sPendingCamData;
  193. volatile bool m_bPendingCamData;
  194. volatile bool m_bPendingProtoReinit;
  195. volatile bool m_bPtzEverOk; // the PTZ protocol worked in this node (re-creation = recovery)
  196. void applyPendingCamData(void);
  197. // basicTransport * m_pTransport;
  198. CAM_TASK_QUEUE m_qCAM_TASK;
  199. basicMutex m_mQPROTECTOR;
  200. uint32_t m_nRelativeMoveCounter;
  201. uint32_t m_nHomingCounter;
  202. uint8_t m_bRelativeMoveMatrix;
  203. uint8_t m_bCurrentPresetCol;
  204. uint8_t m_bCurrentPresetRow;
  205. float m_fSpeedRise;
  206. float m_fRM_Pan;
  207. float m_fRM_Tilt;
  208. float m_fRM_Zoom;
  209. float m_fCP_Pan;
  210. float m_fCP_Tilt;
  211. float m_fCP_Zoom;
  212. bool m_bSkeepPositioningWait;
  213. bool m_bNoMoveDoneReport; // protocol cannot report the end of a move -> fixed wait before EVT_CAMERA_ON_POSITION
  214. bool m_bNoAbsPositionning;
  215. bool m_bCameraIsStatic;
  216. // IR functionality
  217. basicMutex m_mIRProtector;
  218. bool m_bShineOnTarget;
  219. bool m_bIRIsOn;
  220. uint8_t m_bIRTO; // Default 60 seconds (1 video slice)
  221. //
  222. bool m_bCameraOnHomePosition;
  223. /* Methotds Sutable to Control Camera */
  224. bool relativeMove(float PanSPD, float TiltSPD, float ZoomSPD);
  225. bool relativeStop();
  226. bool absoluteMove(uint32_t RefID, float PanPOS, float TiltPOS, float ZoomPOS);
  227. bool absoluteMove(uint32_t RefID, C3D_ORIENT_ONVIF O);
  228. void updateOpticalParameters(uint16_t frame_width, uint16_t frame_heigth);
  229. void translateROI2PRESET(float P, float T, float Z, uint8_t & col, uint8_t & row);
  230. protected:
  231. DBC_CAM_DATA m_sCamData;
  232. MEDIA_SOURCE_DESC m_sMediaSource;
  233. basicEventHeap * m_pBEH;
  234. bool m_bCameraAIControled;
  235. // bool m_bSourceConnected;
  236. // uint32_t m_nActiveStreamID;
  237. // bool inTheFOV( float lat, float lon, float alt );
  238. #ifndef NO_CAMERA_FUSION_ENGINE
  239. /* tracking Fusion methods */
  240. vCAM_ROIS m_vROIS;
  241. basicMutex m_mROIsProtector;
  242. bool fusion_consumeData(uint32_t db_id, C3D_SPH_DEGREES tOR);
  243. bool fusion_validateROI(uint64_t cts, CAM_ROI * ptr);
  244. bool fusion_compare(CAM_ROI * ptr, C3D_SPH_DEGREES tp);
  245. void fusion_validate(void);
  246. CAM_ROI * fusion_fetchROI(void);
  247. DBC_SNAPSHOT_DATA * fusion_translate_ROI(CAM_ROI *(&ptr));
  248. #else
  249. #endif
  250. /* presets Fusion methods */
  251. CAM_PRESETS_SET m_sCamPresets;
  252. virtual bool load_presets(void);
  253. CSTR getPresetToken(uint8_t CCOL, uint8_t CROW);
  254. CSTR getPresetToken(uint8_t specialRole);
  255. bool testFOV(C3D_WGS84_LOC); // Global Coords
  256. bool testFOV(C3D_DECART); // System Coords
  257. bool testFOV(C3D_SPH_RADIANS); // Local Coords
  258. bool testFOV(C3D_SPH_DEGREES); // Local Coords
  259. // bool lookAtWGS84( uint32_t TargetRefID, float lat, float lon, float alt );
  260. bool lookAt(uint32_t TargetRefID, C3D_WGS84_LOC L); // GLobal
  261. bool lookAt(uint32_t TargetRefID, C3D_DECART L); // System
  262. bool lookAt(uint32_t TargetRefID, C3D_SPH_RADIANS L); // Local
  263. bool lookAt(uint32_t TargetRefID, C3D_SPH_DEGREES L); // Local
  264. bool makeSnap(uint32_t TargetRefID);
  265. // void setBusy( bool Status );
  266. bool connectToStream(uint32_t id);
  267. bool disconnectFromStream(void);
  268. CAM_TASK * fetchCamTask(void);
  269. bool pushCamTask(CAM_TASK *);
  270. virtual void m_fThreadProc(void);
  271. public:
  272. explicit deviceNodeCamera(uint32_t NodeID);
  273. explicit deviceNodeCamera(DBC_NODE_DATA * Data);
  274. virtual ~deviceNodeCamera();
  275. bool create();
  276. virtual bool validate();
  277. virtual bool validateStream(void);
  278. bool setNoPositionWait(bool FL = true);
  279. virtual uint8_t getCamStatus()
  280. {
  281. return (uint8_t) m_sCamData.online;
  282. }
  283. uint32_t getCamStream()
  284. {
  285. return m_sCamData.stream_id;
  286. }
  287. virtual uint8_t getFlipMode()
  288. {
  289. return m_sCamData.flip_mode;
  290. }
  291. virtual uint8_t getPtzStatus();
  292. void getPtzHealth(PTZ_HEALTH_INFO * info);
  293. virtual uint8_t getStreamStatus();
  294. virtual float getSystemLocationX(){
  295. return m_sCamData.x;
  296. };
  297. virtual float getSystemLocationY(){
  298. return m_sCamData.y;
  299. };
  300. virtual float getSystemLocationZ(){
  301. return m_sCamData.z;
  302. };
  303. virtual float getMaxRange(){
  304. return m_fMaxRange;
  305. };
  306. };
  307. typedef std::vector<deviceNodeCamera *> vectorNodeCameras;
  308. #endif