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.

228 lines
8.3 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
5 years ago
5 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
5 years ago
​
​
​
​
​
​
​
​
​
​
​
​
5 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
5 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
5 years ago
5 years ago
​
​
5 years ago
​
​
5 years ago
​
​
​
​
​
​
​
​
​
​
5 years ago
​
​
​
​
​
​
​
5 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
5 years ago
​
​
​
​
​
​
​
​
​
​
​
​
5 years ago
​
​
5 years ago
​
5 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 __ARGUS_CAMERA_HEADER__
  16. #define __ARGUS_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 "rgooseNode.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. typedef struct S_CAM_PTZ_CMD{
  39. uint8_t CMD;
  40. float PAN;
  41. float TILT;
  42. float ZOOM;
  43. }CAM_PTZ_CMD;
  44. typedef enum E_CAM_PTZ_CMD{
  45. PTZ_STOP = 0,
  46. PTZ_MOVE = 1,
  47. PTZ_ABSOLUTE = 2,
  48. PTZ_RELOAD_CAMERA = 3,
  49. PTZ_CAPTURE_ONLY = 4
  50. }PTZ_CMD;
  51. typedef std::queue<CAM_PTZ_CMD *> CAM_PTZ_CMD_QUEUE;
  52. typedef enum E_CAM_WORKING_STATE{
  53. CAM_WS_INIT = 0,
  54. CAM_WS_WHITE_BALLANCE = 1,
  55. CAM_WS_BACKLIGHT = 2,
  56. CAM_WS_AUTO_FOCUS = 3,
  57. CAM_WS_INIT_GO_HOME = 4,
  58. CAM_WS_AUTOMATED_MOVE = 10,
  59. CAM_WS_STOP_MOVE = 11,
  60. CAM_WS_GO_ABS_POSITION = 12,
  61. CAM_WS_READY = 64,
  62. CAM_WS_BUSY = 128,
  63. CAM_WS_WAIT_ONPOS = 129,
  64. CAM_WS_END = 255
  65. }CAM_WORK_STATE;
  66. typedef struct S_CAM_TASK{
  67. bool isDone;
  68. uint32_t source_evt_id;
  69. bool movemet_needed;
  70. CAM_PTZ_CMD * CMD;
  71. } CAM_TASK;
  72. typedef std::queue<CAM_TASK *> CAM_TASK_QUEUE;
  73. typedef struct S_CAM_TRACK_RECORD{
  74. C3D_SPH_DEGREES target_direction;
  75. uint32_t evt_db_ID;
  76. uint64_t ts_ms;
  77. }CAM_TRACK_RECORD;
  78. typedef std::vector<CAM_TRACK_RECORD*> vCAM_TRACK_RECORDS;
  79. typedef struct S_CAM_ROI{
  80. C3D_ORIENT_ONVIF cam_orientation;
  81. vCAM_TRACK_RECORDS targets;
  82. uint64_t ts_ms;
  83. /** to do fusion things - consume more targets **/
  84. C3D_SPH_DEGREES cam_position;
  85. float h_fov;
  86. float v_fov;
  87. float min_range;
  88. float max_range;
  89. }CAM_ROI;
  90. typedef std::vector<CAM_ROI *> vCAM_ROIS;
  91. #define LOSE_INTERES_TIME_MS 2000
  92. inline CAM_ROI *createCAM_ROI( void ){
  93. CAM_ROI * tROI = (CAM_ROI*)malloc(sizeof(CAM_ROI));
  94. if( tROI ){
  95. memset( tROI,0,sizeof(CAM_ROI));
  96. tROI->targets.clear();
  97. };
  98. return tROI;
  99. };
  100. inline void utilizeROI( CAM_ROI *&ptr ){
  101. if( ptr ) {
  102. if ( tROI->targets.size() ) {
  103. for( vCAM_TRACK_RECORDS::iterator idx = tROI->targets.begin(); idx != tROI->targets.end(); idx++ ) free( *idx );
  104. tROI->targets.clear();
  105. };
  106. free( tROI );
  107. tROI = NULL;
  108. };
  109. };
  110. class ARGUS_Camera: public argusNetNode, public basicThread {
  111. private:
  112. basicLogCollection * m_pLog;
  113. //basicPosition * m_pPosition;
  114. basicPosition m_oPosition;
  115. //argusDBC * m_pDBC;
  116. time_t m_tTimeTSeconds;
  117. //uint8_t m_bState;
  118. //bool m_bBusy;
  119. CAM_ROI * m_pCurrentROI;
  120. float m_fMaxRange;
  121. float m_fMinRange;
  122. float m_fMaxFL;
  123. float m_fMinFL;
  124. float m_fR2FL; // Range to Focal Length
  125. uint16_t m_nRealFrameWidth;
  126. uint16_t m_nRealFrameHeight;
  127. float m_fMinHFov;
  128. float m_fMaxHFov;
  129. float m_fMinVFov;
  130. float m_fMaxVFov;
  131. protocolPTZ * m_pProtocol;
  132. basicTransport * m_pTransport;
  133. CAM_TASK_QUEUE m_qCAM_TASK;
  134. basicMutex m_mQPROTECTOR;
  135. //videoAVLIBSource * m_pSource;
  136. //videoLIVE555Source * m_pSource;
  137. //basicMediaSource * m_pSource;
  138. uint32_t m_nRelativeMoveCounter;
  139. uint8_t m_bRelativeMoveMatrix;
  140. float m_fSpeedRise;
  141. float m_fRM_Pan;
  142. float m_fRM_Tilt;
  143. float m_fRM_Zoom;
  144. /* Methotds Sutable to Control Camera */
  145. bool relativeMove( float PanSPD, float TiltSPD, float ZoomSPD );
  146. bool relativeStop();
  147. bool absoluteMove( uint32_t RefID, float PanPOS, float TiltPOS, float ZoomPOS );
  148. bool absoluteMove( uint32_t RefID, C3D_ORIENT_ONVIF O );
  149. /* tracking Fusion methods */
  150. vCAM_ROIS m_vROIS;
  151. basicMutex m_mROIsProtector;
  152. bool fusion_consumeData( uint32_t db_id, C3D_SPH_DEGREES tOR );
  153. bool fusion_validateROI( uint64_t cts, CAM_ROI *ptr );
  154. bool fusion_compare( CAM_ROI *ptr, C3D_SPH_DEGREES tp );
  155. void fusion_validate( void );
  156. CAM_ROI * fusion_fetchROI( void );
  157. DBC_SNAPSHOT_DATA * fusion_translate_ROI( CAM_ROI *(&ptr) );
  158. void updateOpticalParameters( uint16_t frame_width, uint16_t frame_heigth );
  159. protected:
  160. DBC_CAM_DATA m_sCamData;
  161. MEDIA_SOURCE_DESC m_sMediaSource;
  162. basicEventHeap * m_pBEH;
  163. //bool m_bSourceConnected;
  164. //uint32_t m_nActiveStreamID;
  165. //bool inTheFOV( float lat, float lon, float alt );
  166. bool testFOV( C3D_WGS84_LOC ); //Global Coords
  167. bool testFOV( C3D_DECART ); //System Coords
  168. bool testFOV( C3D_SPH_RADIANS ); //Local Coords
  169. bool testFOV( C3D_SPH_DEGREES ); //Local Coords
  170. //bool lookAtWGS84( uint32_t TargetRefID, float lat, float lon, float alt );
  171. bool lookAt( uint32_t TargetRefID, C3D_WGS84_LOC L ); // GLobal
  172. bool lookAt( uint32_t TargetRefID, C3D_DECART L ); // System
  173. bool lookAt( uint32_t TargetRefID, C3D_SPH_RADIANS L ); // Local
  174. bool lookAt( uint32_t TargetRefID, C3D_SPH_DEGREES L ); // Local
  175. bool makeSnap( uint32_t TargetRefID );
  176. //void setBusy( bool Status );
  177. bool connectToStream( uint32_t id );
  178. bool disconnectFromStream( void );
  179. bool validateStream( void );
  180. CAM_TASK * fetchCamTask( void );
  181. bool pushCamTask( CAM_TASK * );
  182. virtual void m_fThreadProc( void );
  183. public:
  184. explicit ARGUS_Camera( uint32_t NodeID );
  185. explicit ARGUS_Camera( DBC_NODE_DATA *Data );
  186. virtual ~ARGUS_Camera();
  187. bool create();
  188. };
  189. typedef std::vector<ARGUS_Camera *> vectorARGUS_Cameras;
  190. #endif