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.

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