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.

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