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.

279 lines
7.1 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  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 CAM_CTRL_PROTO_VISCA 1
  30. #define CAM_CTRL_PROTO_PELCO 2
  31. #define CAM_CTRL_PROTO_ONVIF 3
  32. #define CAM_CTRL_PROTO_PSIA 4
  33. #define CAM_CTRL_PROTO_T28181 5
  34. #define UART_TYPE_HARDWARE 1
  35. #define UART_TYPE_SOL 2
  36. #define ARGUS_CAM_PCMD_MOVE_MASK 0x7F
  37. #define ARGUS_CAM_PCMD_CMD_MASK 0x80
  38. #define ARGUS_CAM_PCMD_STOP 1
  39. #define ARGUS_PRESET_TYPE_POSITION 1
  40. #define ARGUS_PRESET_TYPE_HOME 2
  41. #define ARGUS_PRESET_TYPE_IR_AUTO 3
  42. #define ARGUS_PRESET_TYPE_IR_ON 4
  43. #define ARGUS_PRESET_TYPE_IR_OFF 5
  44. #define ARGUS_PRESET_TYPE_IR_WISHER 6
  45. #define DEFAULT_SHINE_ON_TARGET_TO 60 // seconds
  46. typedef struct S_CAM_PTZ_CMD
  47. {
  48. uint8_t CMD;
  49. float PAN;
  50. float TILT;
  51. float ZOOM;
  52. } CAM_PTZ_CMD;
  53. typedef enum E_CAM_PTZ_CMD
  54. {
  55. PTZ_STOP = 0,
  56. PTZ_MOVE = 1,
  57. PTZ_ABSOLUTE = 2,
  58. PTZ_RELOAD_CAMERA = 3,
  59. PTZ_CAPTURE_ONLY = 4,
  60. PTZ_SET_PRESET = 5,
  61. PTZ_CALL_PRESET = 6
  62. } PTZ_CMD;
  63. typedef std::queue<CAM_PTZ_CMD *> CAM_PTZ_CMD_QUEUE;
  64. typedef enum E_CAM_WORKING_STATE
  65. {
  66. CAM_WS_INIT = 0,
  67. CAM_WS_POWER_INIT = 1,
  68. CAM_WS_WHITE_BALLANCE = 2,
  69. CAM_WS_BACKLIGHT = 3,
  70. CAM_WS_AUTO_FOCUS = 4,
  71. CAM_WS_INIT_GO_HOME = 5,
  72. CAM_WS_AUTOMATED_MOVE = 10,
  73. CAM_WS_STOP_MOVE = 11,
  74. CAM_WS_GO_ABS_POSITION = 12,
  75. CAM_WS_GO_HOMING_PRESET = 13,
  76. CAM_WS_GO_PRESET = 14,
  77. CAM_WS_GO_ABS_ROI = 15,
  78. CAM_WS_SET_PRESET = 16,
  79. CAM_WS_READY = 64,
  80. CAM_WS_BUSY = 128,
  81. CAM_WS_WAIT_ONPOS = 129,
  82. CAM_WS_END = 255
  83. } CAM_WORK_STATE;
  84. typedef struct S_CAM_TASK
  85. {
  86. bool isDone;
  87. uint32_t source_evt_id;
  88. bool movemet_needed;
  89. CAM_PTZ_CMD * CMD;
  90. } CAM_TASK;
  91. typedef std::queue<CAM_TASK *> CAM_TASK_QUEUE;
  92. #define LOSE_INTERES_TIME_MS 2000
  93. inline CAM_ROI * createCAM_ROI(void)
  94. {
  95. CAM_ROI * tROI = (CAM_ROI *) malloc(sizeof(CAM_ROI));
  96. if (tROI)
  97. {
  98. memset(tROI, 0, sizeof(CAM_ROI));
  99. tROI->targets.clear();
  100. };
  101. return tROI;
  102. }
  103. inline void utilizeROI(CAM_ROI *& ptr)
  104. {
  105. if (ptr)
  106. {
  107. if (ptr->targets.size())
  108. {
  109. for (vCAM_TRACK_RECORDS::iterator idx = ptr->targets.begin(); idx != ptr->targets.end(); idx++)
  110. {
  111. free(*idx);
  112. }
  113. ptr->targets.clear();
  114. };
  115. free(ptr);
  116. ptr = NULL;
  117. };
  118. }
  119. class deviceNodeCamera : public deviceNode, public basicThread
  120. {
  121. private:
  122. basicPosition m_oPosition;
  123. time_t m_tTimeTSeconds;
  124. CAM_ROI * m_pCurrentROI;
  125. float m_fMaxRange;
  126. float m_fMinRange;
  127. float m_fMaxFL;
  128. float m_fMinFL;
  129. float m_fR2FL; // Range to Focal Length
  130. float m_fZoomCorrection;
  131. uint16_t m_nRealFrameWidth;
  132. uint16_t m_nRealFrameHeight;
  133. float m_fMinHFov;
  134. float m_fMaxHFov;
  135. float m_fMinVFov;
  136. float m_fMaxVFov;
  137. protocolPTZ * m_pProtocol;
  138. // basicTransport * m_pTransport;
  139. CAM_TASK_QUEUE m_qCAM_TASK;
  140. basicMutex m_mQPROTECTOR;
  141. uint32_t m_nRelativeMoveCounter;
  142. uint32_t m_nHomingCounter;
  143. uint8_t m_bRelativeMoveMatrix;
  144. uint8_t m_bCurrentPresetCol;
  145. uint8_t m_bCurrentPresetRow;
  146. float m_fSpeedRise;
  147. float m_fRM_Pan;
  148. float m_fRM_Tilt;
  149. float m_fRM_Zoom;
  150. float m_fCP_Pan;
  151. float m_fCP_Tilt;
  152. float m_fCP_Zoom;
  153. bool m_bSkeepPositioningWait;
  154. bool m_bNoAbsPositionning;
  155. bool m_bCameraIsStatic;
  156. // IR functionality
  157. basicMutex m_mIRProtector;
  158. bool m_bShineOnTarget;
  159. bool m_bIRIsOn;
  160. uint8_t m_bIRTO; // Default 60 seconds (1 video slice)
  161. //
  162. bool m_bCameraOnHomePosition;
  163. /* Methotds Sutable to Control Camera */
  164. bool relativeMove(float PanSPD, float TiltSPD, float ZoomSPD);
  165. bool relativeStop();
  166. bool absoluteMove(uint32_t RefID, float PanPOS, float TiltPOS, float ZoomPOS);
  167. bool absoluteMove(uint32_t RefID, C3D_ORIENT_ONVIF O);
  168. void updateOpticalParameters(uint16_t frame_width, uint16_t frame_heigth);
  169. void translateROI2PRESET(float P, float T, float Z, uint8_t & col, uint8_t & row);
  170. protected:
  171. DBC_CAM_DATA m_sCamData;
  172. MEDIA_SOURCE_DESC m_sMediaSource;
  173. basicEventHeap * m_pBEH;
  174. // bool m_bSourceConnected;
  175. // uint32_t m_nActiveStreamID;
  176. // bool inTheFOV( float lat, float lon, float alt );
  177. /* tracking Fusion methods */
  178. vCAM_ROIS m_vROIS;
  179. basicMutex m_mROIsProtector;
  180. bool fusion_consumeData(uint32_t db_id, C3D_SPH_DEGREES tOR);
  181. bool fusion_validateROI(uint64_t cts, CAM_ROI * ptr);
  182. bool fusion_compare(CAM_ROI * ptr, C3D_SPH_DEGREES tp);
  183. void fusion_validate(void);
  184. CAM_ROI * fusion_fetchROI(void);
  185. DBC_SNAPSHOT_DATA * fusion_translate_ROI(CAM_ROI *(&ptr));
  186. /* presets Fusion methods */
  187. CAM_PRESETS_SET m_sCamPresets;
  188. virtual bool load_presets(void);
  189. CSTR getPresetToken(uint8_t CCOL, uint8_t CROW);
  190. CSTR getPresetToken(uint8_t specialRole);
  191. bool testFOV(C3D_WGS84_LOC); // Global Coords
  192. bool testFOV(C3D_DECART); // System Coords
  193. bool testFOV(C3D_SPH_RADIANS); // Local Coords
  194. bool testFOV(C3D_SPH_DEGREES); // Local Coords
  195. // bool lookAtWGS84( uint32_t TargetRefID, float lat, float lon, float alt );
  196. bool lookAt(uint32_t TargetRefID, C3D_WGS84_LOC L); // GLobal
  197. bool lookAt(uint32_t TargetRefID, C3D_DECART L); // System
  198. bool lookAt(uint32_t TargetRefID, C3D_SPH_RADIANS L); // Local
  199. bool lookAt(uint32_t TargetRefID, C3D_SPH_DEGREES L); // Local
  200. bool makeSnap(uint32_t TargetRefID);
  201. // void setBusy( bool Status );
  202. bool connectToStream(uint32_t id);
  203. bool disconnectFromStream(void);
  204. CAM_TASK * fetchCamTask(void);
  205. bool pushCamTask(CAM_TASK *);
  206. virtual void m_fThreadProc(void);
  207. public:
  208. explicit deviceNodeCamera(uint32_t NodeID);
  209. explicit deviceNodeCamera(DBC_NODE_DATA * Data);
  210. virtual ~deviceNodeCamera();
  211. bool create();
  212. virtual bool validate();
  213. virtual bool validateStream(void);
  214. bool setNoPositionWait(bool FL = true);
  215. virtual uint8_t getCamStatus()
  216. {
  217. return (uint8_t) m_sCamData.online;
  218. }
  219. uint32_t getCamStream()
  220. {
  221. return m_sCamData.stream_id;
  222. }
  223. virtual uint8_t getFlipMode()
  224. {
  225. return m_sCamData.flip_mode;
  226. }
  227. virtual uint8_t getPtzStatus();
  228. virtual uint8_t getStreamStatus();
  229. };
  230. typedef std::vector<deviceNodeCamera *> vectorNodeCameras;
  231. #endif