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.

303 lines
7.8 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
5 months 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. typedef struct S_CAM_TASK
  89. {
  90. bool isDone;
  91. uint32_t source_evt_id;
  92. bool movemet_needed;
  93. CAM_PTZ_CMD * CMD;
  94. } CAM_TASK;
  95. typedef std::queue<CAM_TASK *> CAM_TASK_QUEUE;
  96. #define LOSE_INTERES_TIME_MS 2000
  97. inline CAM_ROI * createCAM_ROI(void)
  98. {
  99. //CAM_ROI * tROI = (CAM_ROI *) malloc(sizeof(CAM_ROI));
  100. CAM_ROI * tROI = new CAM_ROI();
  101. if (tROI)
  102. {
  103. //memset(tROI, 0, sizeof(CAM_ROI));
  104. tROI->targets.clear();
  105. };
  106. return tROI;
  107. }
  108. inline void utilizeROI(CAM_ROI *& ptr)
  109. {
  110. if (ptr)
  111. {
  112. if (ptr->targets.size())
  113. {
  114. for (vCAM_TRACK_RECORDS::iterator idx = ptr->targets.begin(); idx != ptr->targets.end(); idx++)
  115. {
  116. free(*idx);
  117. }
  118. ptr->targets.clear();
  119. };
  120. //free(ptr);
  121. delete( ptr );
  122. ptr = NULL;
  123. };
  124. }
  125. class deviceNodeCamera : public deviceNode, public basicThread
  126. {
  127. private:
  128. basicPosition m_oPosition;
  129. time_t m_tTimeTSeconds;
  130. CAM_ROI * m_pCurrentROI;
  131. float m_fMaxRange;
  132. float m_fMinRange;
  133. float m_fMaxFL;
  134. float m_fMinFL;
  135. float m_fR2FL; // Range to Focal Length
  136. float m_fZoomCorrection;
  137. uint16_t m_nRealFrameWidth;
  138. uint16_t m_nRealFrameHeight;
  139. float m_fMinHFov;
  140. float m_fMaxHFov;
  141. float m_fMinVFov;
  142. float m_fMaxVFov;
  143. protocolPTZ * m_pProtocol;
  144. // basicTransport * m_pTransport;
  145. CAM_TASK_QUEUE m_qCAM_TASK;
  146. basicMutex m_mQPROTECTOR;
  147. uint32_t m_nRelativeMoveCounter;
  148. uint32_t m_nHomingCounter;
  149. uint8_t m_bRelativeMoveMatrix;
  150. uint8_t m_bCurrentPresetCol;
  151. uint8_t m_bCurrentPresetRow;
  152. float m_fSpeedRise;
  153. float m_fRM_Pan;
  154. float m_fRM_Tilt;
  155. float m_fRM_Zoom;
  156. float m_fCP_Pan;
  157. float m_fCP_Tilt;
  158. float m_fCP_Zoom;
  159. bool m_bSkeepPositioningWait;
  160. bool m_bNoMoveDoneReport; // protocol cannot report the end of a move -> fixed wait before EVT_CAMERA_ON_POSITION
  161. bool m_bNoAbsPositionning;
  162. bool m_bCameraIsStatic;
  163. // IR functionality
  164. basicMutex m_mIRProtector;
  165. bool m_bShineOnTarget;
  166. bool m_bIRIsOn;
  167. uint8_t m_bIRTO; // Default 60 seconds (1 video slice)
  168. //
  169. bool m_bCameraOnHomePosition;
  170. /* Methotds Sutable to Control Camera */
  171. bool relativeMove(float PanSPD, float TiltSPD, float ZoomSPD);
  172. bool relativeStop();
  173. bool absoluteMove(uint32_t RefID, float PanPOS, float TiltPOS, float ZoomPOS);
  174. bool absoluteMove(uint32_t RefID, C3D_ORIENT_ONVIF O);
  175. void updateOpticalParameters(uint16_t frame_width, uint16_t frame_heigth);
  176. void translateROI2PRESET(float P, float T, float Z, uint8_t & col, uint8_t & row);
  177. protected:
  178. DBC_CAM_DATA m_sCamData;
  179. MEDIA_SOURCE_DESC m_sMediaSource;
  180. basicEventHeap * m_pBEH;
  181. // bool m_bSourceConnected;
  182. // uint32_t m_nActiveStreamID;
  183. // bool inTheFOV( float lat, float lon, float alt );
  184. #ifndef NO_CAMERA_FUSION_ENGINE
  185. /* tracking Fusion methods */
  186. vCAM_ROIS m_vROIS;
  187. basicMutex m_mROIsProtector;
  188. bool fusion_consumeData(uint32_t db_id, C3D_SPH_DEGREES tOR);
  189. bool fusion_validateROI(uint64_t cts, CAM_ROI * ptr);
  190. bool fusion_compare(CAM_ROI * ptr, C3D_SPH_DEGREES tp);
  191. void fusion_validate(void);
  192. CAM_ROI * fusion_fetchROI(void);
  193. DBC_SNAPSHOT_DATA * fusion_translate_ROI(CAM_ROI *(&ptr));
  194. #else
  195. #endif
  196. /* presets Fusion methods */
  197. CAM_PRESETS_SET m_sCamPresets;
  198. virtual bool load_presets(void);
  199. CSTR getPresetToken(uint8_t CCOL, uint8_t CROW);
  200. CSTR getPresetToken(uint8_t specialRole);
  201. bool testFOV(C3D_WGS84_LOC); // Global Coords
  202. bool testFOV(C3D_DECART); // System Coords
  203. bool testFOV(C3D_SPH_RADIANS); // Local Coords
  204. bool testFOV(C3D_SPH_DEGREES); // Local Coords
  205. // bool lookAtWGS84( uint32_t TargetRefID, float lat, float lon, float alt );
  206. bool lookAt(uint32_t TargetRefID, C3D_WGS84_LOC L); // GLobal
  207. bool lookAt(uint32_t TargetRefID, C3D_DECART L); // System
  208. bool lookAt(uint32_t TargetRefID, C3D_SPH_RADIANS L); // Local
  209. bool lookAt(uint32_t TargetRefID, C3D_SPH_DEGREES L); // Local
  210. bool makeSnap(uint32_t TargetRefID);
  211. // void setBusy( bool Status );
  212. bool connectToStream(uint32_t id);
  213. bool disconnectFromStream(void);
  214. CAM_TASK * fetchCamTask(void);
  215. bool pushCamTask(CAM_TASK *);
  216. virtual void m_fThreadProc(void);
  217. public:
  218. explicit deviceNodeCamera(uint32_t NodeID);
  219. explicit deviceNodeCamera(DBC_NODE_DATA * Data);
  220. virtual ~deviceNodeCamera();
  221. bool create();
  222. virtual bool validate();
  223. virtual bool validateStream(void);
  224. bool setNoPositionWait(bool FL = true);
  225. virtual uint8_t getCamStatus()
  226. {
  227. return (uint8_t) m_sCamData.online;
  228. }
  229. uint32_t getCamStream()
  230. {
  231. return m_sCamData.stream_id;
  232. }
  233. virtual uint8_t getFlipMode()
  234. {
  235. return m_sCamData.flip_mode;
  236. }
  237. virtual uint8_t getPtzStatus();
  238. virtual uint8_t getStreamStatus();
  239. virtual float getSystemLocationX(){
  240. return m_sCamData.x;
  241. };
  242. virtual float getSystemLocationY(){
  243. return m_sCamData.y;
  244. };
  245. virtual float getSystemLocationZ(){
  246. return m_sCamData.z;
  247. };
  248. virtual float getMaxRange(){
  249. return m_fMaxRange;
  250. };
  251. };
  252. typedef std::vector<deviceNodeCamera *> vectorNodeCameras;
  253. #endif