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.

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