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.

247 lines
9.2 KiB

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