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.

1526 lines
57 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
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
​
​
​
​
​
​
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
​
​
​
​
​
​
​
​
​
​
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
​
​
​
​
​
​
​
​
​
​
​
​
​
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
​
​
​
​
​
  1. #include "deviceNodeCamera.h"
  2. #include "../../components/base/basicCameraInfo.h"
  3. #include "../../components/object/objectSystemAnchor.h"
  4. #include "../../hardware/uart/serialPort.h"
  5. #include "../../hardware/uart/serialSOL.h"
  6. #include "../../data/protocol/protocolPTZ_VISCA.h"
  7. #include "../../data/protocol/protocolPTZ_ONVIF.h"
  8. #include "../../data/protocol/protocolPTZ_PELCO.h"
  9. #include "hardwareManager.h"
  10. #include "hardwareResourceSerialProvider.h"
  11. //#include "rgooseModuleEmbedVideo.h"
  12. #define LOG( X ) deviceNode::m_pLog->Log( "RCAM", this, X )
  13. #ifdef DEBUG
  14. #define LOG_ERROR( X ) {\
  15. char _tBfrErrMSG2w34[256];\
  16. sprintf( _tBfrErrMSG2w34, "In file %s[%d] in func:%s %s",__FILE__, __LINE__, __func__, X );\
  17. deviceNode::m_pLog->Log( "RCAM", this, _LOG_ERROR, _tBfrErrMSG2w34 );\
  18. }
  19. #else
  20. #define LOG_ERROR( X ) deviceNode::m_pLog->Log( "RCAM", this, _LOG_ERROR, X );
  21. #endif
  22. // all sizes in mm
  23. static const float AC_imager_diag[12] = { 5.0f, 5.68f, 6.0f, 6.592f, 8.0f, 8.933f, 11.0f, 16.0f, 22.5f, 30.1f, 43.3f, 69.7f };
  24. static const float AC_imager_width[12] = { 4.0f, 4.536f, 4.8f, 5.27f, 6.4f, 7.176f, 8.8f, 12.8f, 18.0f, 25.1f, 36.0f, 56.0f };
  25. static const float AC_imager_height[12] = { 3.0f, 3.416f, 3.6f, 3.96f, 4.8f, 5.319f, 6.6f, 9.6f, 13.5f, 16.7f, 24.0f, 41.5f };
  26. #define CAM_FOCAL_LENGTH_CNT 49
  27. static const float cam_predef_focal_length[CAM_FOCAL_LENGTH_CNT]={
  28. 2.7f,
  29. 3.0f,
  30. 3.2f,
  31. 3.5f,
  32. 3.7f,
  33. 3.9f,
  34. 4.0f,
  35. 4.3f,
  36. 4.8f,
  37. 5.0f,
  38. 5.1f,
  39. 5.5f,
  40. 5.8f,
  41. 6.0f,
  42. 6.2f,
  43. 6.6f,
  44. 7.0f,
  45. 7.1f,
  46. 7.5f,
  47. 7.6f,
  48. 8.0f,
  49. 8.6f,
  50. 8.9f,
  51. 9.0f,
  52. 9.2f,
  53. 9.3f,
  54. 10.0f,
  55. 10.5f,
  56. 10.6f,
  57. 10.7f,
  58. 11.0f,
  59. 11.3f,
  60. 12.0f,
  61. 12.9f,
  62. 13.0f,
  63. 13.5f,
  64. 13.6f,
  65. 14.0f,
  66. 14.6f,
  67. 15.0f,
  68. 15.1f,
  69. 15.5f,
  70. 16.0f,
  71. 17.0f,
  72. 17.5f,
  73. 17.7f,
  74. 18.0f,
  75. 18.2f,
  76. 19.0f
  77. };
  78. deviceNodeCamera::deviceNodeCamera( uint32_t NodeID ): deviceNode( NodeID ), basicThread(){
  79. //m_pLog = basicLogCollection::getInstance();
  80. m_pBEH = basicEventHeap::getInstance();
  81. m_tTimeTSeconds = 0;
  82. m_pProtocol = NULL;
  83. m_pTransport = NULL;
  84. m_pCurrentROI = NULL;
  85. m_nRealFrameWidth = 640;
  86. //m_bState = 0;
  87. //m_bBusy = true;
  88. m_fMaxRange = m_fMinHFov = m_fMaxHFov = m_fMinVFov = m_fMaxVFov = .0f;
  89. m_nRelativeMoveCounter = 0;
  90. m_bRelativeMoveMatrix = 0;
  91. m_fSpeedRise = 0.03f;
  92. m_fZoomCorrection = 1.0f;
  93. m_fRM_Pan = m_fRM_Tilt = m_fRM_Zoom = .0f;
  94. //m_bSourceConnected = false;
  95. //m_pSource = NULL;
  96. };
  97. deviceNodeCamera::deviceNodeCamera( DBC_NODE_DATA *Data ): deviceNode( Data ), basicThread(){
  98. //m_pLog = basicLogCollection::getInstance();
  99. m_pBEH = basicEventHeap::getInstance();
  100. m_tTimeTSeconds = 0;
  101. m_pProtocol = NULL;
  102. m_pTransport = NULL;
  103. m_pCurrentROI = NULL;
  104. m_nRealFrameWidth = 640;
  105. //m_bState = 0;
  106. //m_bBusy = true;
  107. m_fMaxRange = m_fMinHFov = m_fMaxHFov = m_fMinVFov = m_fMaxVFov = .0f;
  108. m_nRelativeMoveCounter = 0;
  109. m_bRelativeMoveMatrix = 0;
  110. m_fSpeedRise = 0.03f;
  111. m_fZoomCorrection = 1.0f;
  112. m_fRM_Pan = m_fRM_Tilt = m_fRM_Zoom = .0f;
  113. //m_bSourceConnected = false;
  114. //m_pSource = NULL;
  115. };
  116. deviceNodeCamera::~deviceNodeCamera(){
  117. LOG("Destruct");
  118. //m_mQPROTECTOR.unlock();
  119. waitThreadEnd( true );
  120. LOG("Thread Del OK");
  121. if( m_pTransport!= NULL ) {
  122. if( m_sCamData.uart_id ) {
  123. DBC_UART_DATA *tData = NULL;
  124. tData = m_pDBC->getUartData( m_sCamData.uart_id );
  125. switch( tData->type ) {
  126. case UART_TYPE_HARDWARE:{
  127. delete((serialPort*)m_pTransport);
  128. break;
  129. };
  130. case UART_TYPE_SOL:{
  131. delete((serialSOL*)m_pTransport);
  132. break;
  133. };
  134. };
  135. }
  136. };
  137. LOG("Transport Del OK");
  138. if( m_pProtocol != NULL ) {
  139. switch( m_sCamData.protocol ) {
  140. case CAM_CTRL_PROTO_VISCA:
  141. delete( (protocolPTZ_VISCA *) m_pProtocol );
  142. break;
  143. case CAM_CTRL_PROTO_PELCO:
  144. delete( (protocolPTZ_PELCO *) m_pProtocol );
  145. break;
  146. case CAM_CTRL_PROTO_ONVIF:
  147. delete( (protocolPTZ_ONVIF *) m_pProtocol );
  148. break;
  149. default:
  150. delete( m_pProtocol );
  151. };
  152. };
  153. LOG("Proto Del OK");
  154. //if( m_pPosition != NULL ) delete( m_pPosition );
  155. //LOG("Pos Del OK");
  156. //if( m_bSourceConnected ){
  157. // if( m_pSource != NULL ){
  158. // m_pSource->_close();
  159. // delete( m_pSource );
  160. // };
  161. //};
  162. //LOG("Stream Del OK");
  163. };
  164. void deviceNodeCamera::updateOpticalParameters( uint16_t frame_width, uint16_t frame_heigth ){
  165. #ifdef DEBUG
  166. char tB[128];
  167. LOG("Set Optical Parameters");
  168. sprintf( tB, "\tCapturing Frame: %dx%d ", frame_width, frame_heigth );
  169. LOG(tB);
  170. #endif
  171. if( frame_width > 0 && frame_heigth > 0 ) {
  172. m_nRealFrameWidth = frame_width;
  173. m_nRealFrameHeight = frame_heigth;
  174. float tFrameDiag = sqrtf( m_nRealFrameHeight*m_nRealFrameHeight+m_nRealFrameWidth*m_nRealFrameWidth );
  175. switch( m_sCamData.zoom_model ) {
  176. case 0:{
  177. #ifdef DEBUG
  178. LOG("\tFixed Zoom");
  179. #endif
  180. m_fMaxFL = m_fMinFL = cam_predef_focal_length[m_sCamData.lens_f];
  181. m_fMinRange = calcMinDistance_mm( AC_imager_diag[m_sCamData.imager_type], m_fMinFL, tFrameDiag );
  182. m_fMaxRange = calcMaxDistance_mm( AC_imager_diag[m_sCamData.imager_type], m_fMaxFL, tFrameDiag );
  183. m_fR2FL = .0f;
  184. m_fZoomCorrection = .0f;
  185. m_pDBC->updateCamRange( m_sCamData.id, m_fMaxRange );
  186. break;
  187. };
  188. case 1:{
  189. #ifdef DEBUG
  190. LOG("\tAutomated Zoom");
  191. #endif
  192. m_fMinFL = cam_predef_focal_length[m_sCamData.lens_f];
  193. m_fMinRange = calcMinDistance_mm( AC_imager_diag[m_sCamData.imager_type], m_fMinFL, tFrameDiag );
  194. m_fMaxFL = cam_predef_focal_length[m_sCamData.lens_f] * m_sCamData.zoom;
  195. m_fMaxRange = calcMaxDistance_mm( AC_imager_diag[m_sCamData.imager_type], m_fMaxFL, tFrameDiag );
  196. if( m_fMaxRange > m_fMinRange ){
  197. m_fR2FL = ((m_fMaxFL - m_fMinFL) / (m_fMaxRange - m_fMinRange));
  198. } else {
  199. m_fR2FL = .0f;
  200. };
  201. m_fZoomCorrection = 1.0f;
  202. m_pDBC->updateCamRange(m_sCamData.id, m_fMaxRange);
  203. break;
  204. };
  205. case 2:{
  206. #ifdef DEBUG
  207. LOG("\tManual Zoom");
  208. #endif
  209. m_fMinRange = 5.0f; //Minimal 5 meters
  210. if ( m_sCamData.max_range < m_fMinRange ) {
  211. m_fMaxRange = m_fMinRange;
  212. } else {
  213. m_fMaxRange = m_sCamData.max_range;
  214. };
  215. m_fZoomCorrection = m_sCamData.zoom * 0.01f;
  216. m_fMinFL = calcCFL( AC_imager_width[m_sCamData.imager_type], m_fMinRange, tFrameDiag );
  217. m_fMaxFL = calcCFL( AC_imager_width[m_sCamData.imager_type], m_fMaxRange, tFrameDiag );
  218. break;
  219. };
  220. };
  221. m_fMinHFov = rad2deg(calcFOV_mm( AC_imager_width[m_sCamData.imager_type], m_fMaxFL ));
  222. m_fMaxHFov = rad2deg(calcFOV_mm( AC_imager_width[m_sCamData.imager_type], m_fMinFL ));
  223. m_fMinVFov = rad2deg(calcFOV_mm( AC_imager_height[m_sCamData.imager_type], m_fMaxFL ));
  224. m_fMaxVFov = rad2deg(calcFOV_mm( AC_imager_height[m_sCamData.imager_type], m_fMinFL ));
  225. #ifdef DEBUG
  226. sprintf( tB, "\tMinimal FL: %0.3fmm. Maximal FL: %0.3fmm. ", m_fMinFL, m_fMaxFL );
  227. LOG(tB);
  228. sprintf( tB, "\tMinimal Range: %0.2fm. Maximal Range: %0.2fm. ", m_fMinRange, m_fMaxRange );
  229. LOG(tB);
  230. sprintf( tB, "\tMinimal FOVs, Horizontal: %0.2f Vertical: %0.2f", m_fMinHFov, m_fMinVFov );
  231. LOG(tB);
  232. sprintf( tB, "\tMaximal FOVs, Horizontal: %0.2f Vertical: %0.2f", m_fMaxHFov, m_fMaxVFov );
  233. LOG(tB);
  234. #endif
  235. };
  236. };
  237. bool deviceNodeCamera::create(){
  238. setWM( CAM_WS_INIT );
  239. if( m_sNodeData.aux_id == 0 ) return false;
  240. DBC_CAM_DATA * tData = m_pDBC->getCamData( m_sNodeData.aux_id );
  241. if( tData != NULL ) {
  242. memcpy( &m_sCamData, tData, sizeof(DBC_CAM_DATA) );
  243. free( tData );
  244. } else {
  245. LOG_ERROR("Cannot Fetch CAM Data from Database!");
  246. return false;
  247. };
  248. if( !( m_sCamData.lens_f < CAM_FOCAL_LENGTH_CNT ) ) m_sCamData.lens_f = CAM_FOCAL_LENGTH_CNT - 1;
  249. updateOpticalParameters( 1280, 720 ); //HD Ready
  250. if( m_sCamData.ptz_speed_step > .0f ) {
  251. m_fSpeedRise = m_sCamData.ptz_speed_step;
  252. };
  253. //m_pPosition = new basicPosition();// m_sCamData.lat, m_sCamData.lon, m_sCamData.alt, m_sCamData.roll, m_sCamData.pitch, m_sCamData.yaw );
  254. //if( m_pPosition == NULL ) {
  255. // LOG_ERROR("Position Constructor Failure!");
  256. // return false;
  257. //};
  258. //m_oPosition.setPositionXYZ( m_sCamData.x, m_sCamData.y, m_sCamData.z );
  259. //m_oPosition.setOrientationDeg( m_sCamData.x_rot, m_sCamData.y_rot, m_sCamData.z_rot );
  260. systemAnchor * SA = systemAnchor::getInstance();
  261. if( SA ){
  262. LOG("SysAnchor OK");
  263. if ( SA->beLocal() ) {
  264. LOG("SysAnchor beLocal!");
  265. m_oPosition.setPositionXYZ( m_sCamData.x, m_sCamData.y, m_sCamData.z, 0 ); //SA->getUTMZone() );
  266. m_oPosition.setOrientationDeg( m_sCamData.x_rot , m_sCamData.y_rot, m_sCamData.z_rot );
  267. } else {
  268. LOG("SysAnchor is Global Position System!");
  269. C3D_DECART LD = SA->getXYZ();
  270. m_oPosition.setPositionXYZ( LD.x + m_sCamData.x, LD.y + m_sCamData.y, LD.z + m_sCamData.z, SA->getUTMZone() );
  271. m_oPosition.setOrientationDeg( m_sCamData.x_rot , m_sCamData.y_rot, m_sCamData.z_rot );
  272. };
  273. } else {
  274. LOG("No SysAnchor!");
  275. m_oPosition.setPositionXYZ( m_sCamData.x , m_sCamData.y, m_sCamData.z );
  276. m_oPosition.setOrientationDeg( m_sCamData.x_rot , m_sCamData.y_rot, m_sCamData.z_rot );
  277. };
  278. m_oPosition.updateMatrix();
  279. #ifdef DEBUG
  280. char tB[128];
  281. sprintf( tB, "Finalized Camera Location: Lat:%.3f Lon:%.3f Alt:%.3f", m_oPosition.getLat(), m_oPosition.getLon(), m_oPosition.getAlt() );
  282. LOG( tB );
  283. sprintf( tB, "Finalized Camera Location: x:%.3f y:%.3f z:%.3f", m_oPosition.getX(), m_oPosition.getY(), m_oPosition.getZ() );
  284. LOG( tB );
  285. sprintf( tB, "Orientation: x:%.3f y:%.3f z:%.3f", m_oPosition.getRotX_deg(), m_oPosition.getRotY_deg(), m_oPosition.getRotZ_deg() );
  286. LOG( tB );
  287. #endif
  288. if( m_pProtocol != NULL ){
  289. LOG_ERROR("Cannot Start: Service Already Running!");
  290. return false;
  291. };
  292. switch( m_sCamData.protocol ){
  293. case CAM_CTRL_PROTO_VISCA: {
  294. #ifdef DEBUG
  295. LOG("VISCA");
  296. #endif
  297. m_pProtocol = (protocolPTZ *) new protocolPTZ_VISCA( m_sCamData.protocol_aux );
  298. if( m_pProtocol!= NULL ) {
  299. basicTransport *tTransport = NULL;
  300. hardwareManager *tHM = hardwareManager::getInstance();
  301. if( tHM ){
  302. hardwareResource *tRES = tHM->requestResource( HARDWARE_PROVIDER_SERIAL, m_sCamData.uart_id );
  303. if( tRES != NULL ) {
  304. if( tRES->isValid()) {
  305. tTransport = static_cast<basicTransport *>(static_cast<hardwareResourceSerialProvider *>(tRES));
  306. if( m_pProtocol->setTransport( tTransport )){
  307. if( !m_pProtocol->create() ){
  308. LOG_ERROR("Protocol <<< Create >>> Failure!");
  309. };
  310. } else {
  311. LOG_ERROR("Binding Port Failure!");
  312. };
  313. };
  314. #ifdef DEBUG
  315. } else {
  316. LOG("HWM Has No UART PORT!");
  317. #endif
  318. };
  319. #ifdef DEBUG
  320. } else {
  321. LOG_ERROR("Can not get Hardware Manager!");
  322. #endif
  323. };
  324. if( tTransport!= NULL ) {
  325. LOG( "Bind Transport Port!" );
  326. } else {
  327. LOG_ERROR("Transport Creation Failure!");
  328. delete( ( protocolPTZ_VISCA * )m_pProtocol );
  329. m_pProtocol = NULL;
  330. };
  331. #ifdef DEBUG
  332. } else {
  333. LOG_ERROR("Protocol Creation failure!");
  334. #endif
  335. };
  336. break;
  337. };
  338. case CAM_CTRL_PROTO_PELCO:{
  339. #ifdef DEBUG
  340. LOG("PELCO");
  341. #endif
  342. m_pProtocol = (protocolPTZ *) new protocolPTZ_PELCO( m_sCamData.protocol_aux );
  343. if( m_pProtocol!= NULL ) {
  344. basicTransport *tTransport = NULL;
  345. hardwareManager *tHM = hardwareManager::getInstance();
  346. if ( tHM ) {
  347. hardwareResource * tRES = tHM->requestResource( HARDWARE_PROVIDER_SERIAL, m_sCamData.uart_id );
  348. if( tRES != NULL ) {
  349. if( tRES->isValid()) {
  350. tTransport = static_cast<basicTransport *>(static_cast<hardwareResourceSerialProvider *>(tRES));
  351. if( m_pProtocol->setTransport( tTransport )){
  352. if( !m_pProtocol->create() ){
  353. LOG_ERROR("Protocol <<< Create >>> Failure!");
  354. };
  355. } else {
  356. LOG_ERROR("Binding Port Failure!");
  357. };
  358. };
  359. #ifdef DEBUG
  360. } else {
  361. LOG("HWM Has No UART PORT!");
  362. #endif
  363. };
  364. #ifdef DEBUG
  365. } else {
  366. LOG_ERROR("Can not get Hardware Manager!");
  367. #endif
  368. };
  369. if( tTransport!= NULL ) {
  370. LOG( "Bind Transport Port!" );
  371. } else {
  372. LOG_ERROR("Transport Creation Failure!");
  373. delete( ( protocolPTZ_PELCO * )m_pProtocol );
  374. m_pProtocol = NULL;
  375. };
  376. #ifdef DEBUG
  377. } else {
  378. LOG_ERROR("Protocol Creation failure!");
  379. #endif
  380. };
  381. break;
  382. };
  383. case CAM_CTRL_PROTO_ONVIF:{
  384. #ifdef DEBUG
  385. LOG("ONVIF");
  386. #endif
  387. //m_pProtocol = (protocolPTZ *) new protocolPTZ_ONVIF( m_sCamData.ip, m_sCamData.port, m_sCamData.username, m_sCamData.password, m_sCamData.auth_mode );
  388. if( strstr( m_sCamData.onvif_ctrl, "http" ) == NULL ) {
  389. char tURI[256];
  390. if ( m_sCamData.port ) {
  391. sprintf(tURI, "http://%s:%d%s", m_sCamData.ip, m_sCamData.port, m_sCamData.onvif_ctrl);
  392. } else {
  393. sprintf(tURI, "http://%s%s", m_sCamData.ip, m_sCamData.onvif_ctrl);
  394. };
  395. m_pProtocol = (protocolPTZ *)new protocolPTZ_ONVIF( tURI, m_sCamData.username, m_sCamData.password, m_sCamData.auth_mode);
  396. } else {
  397. m_pProtocol = (protocolPTZ *)new protocolPTZ_ONVIF(m_sCamData.onvif_ctrl, m_sCamData.username, m_sCamData.password, m_sCamData.auth_mode);
  398. }
  399. if( m_pProtocol!=NULL ) {
  400. if( !m_pProtocol->create() ) {
  401. LOG_ERROR("Error Creating Proto!");
  402. delete( (protocolPTZ_ONVIF*) m_pProtocol );
  403. m_pProtocol = NULL;
  404. };
  405. };
  406. break;
  407. };
  408. default:{
  409. #ifdef DEBUG
  410. LOG("Camera Has no defined control protocol");
  411. #endif
  412. };
  413. };
  414. if( m_pProtocol == NULL ) {
  415. if( m_sCamData.protocol == 0 ) {
  416. m_sCamData.online = true;
  417. } else LOG_ERROR("No Proto Created!");
  418. } else {
  419. #ifdef DEBUG
  420. LOG("Proto is OK");
  421. #endif
  422. m_sCamData.online = init();
  423. };
  424. m_pDBC->updateCamOnlineStatus( m_sCamData.id, m_sCamData.online );
  425. return m_sCamData.online;
  426. };
  427. //void deviceNodeCamera::setBusy( bool Status ){
  428. //m_bBusy = Status;
  429. //};
  430. bool deviceNodeCamera::relativeMove( float PanSPD, float TiltSPD, float ZoomSPD ){
  431. if( m_sCamData.online ) {
  432. uint32_t MoveMatrix = 0;
  433. if( PanSPD != .0f ){
  434. if( PanSPD > 0 ) {
  435. MoveMatrix |= PTZ_DRIVE_PAN_RIGHT;
  436. } else {
  437. MoveMatrix |= PTZ_DRIVE_PAN_LEFT;
  438. };
  439. };
  440. if( TiltSPD != .0f ){
  441. if( TiltSPD > 0 ) {
  442. MoveMatrix |= PTZ_DRIVE_TILT_UP;
  443. } else {
  444. MoveMatrix |= PTZ_DRIVE_TILT_DOWN;
  445. };
  446. };
  447. if( ZoomSPD != .0f ){
  448. if( ZoomSPD > 0 ) {
  449. MoveMatrix |= PTZ_DRIVE_ZOOM_WIDE;
  450. } else {
  451. MoveMatrix |= PTZ_DRIVE_ZOOM_TELE;
  452. };
  453. };
  454. if( MoveMatrix != 0 ) {
  455. m_pProtocol->setPTZSpeed( fabs(PanSPD), fabs(TiltSPD), fabs(ZoomSPD) );
  456. };
  457. return m_pProtocol->move( MoveMatrix );
  458. };
  459. return false;
  460. };
  461. bool deviceNodeCamera::relativeStop(){
  462. if( m_sCamData.online ) {
  463. return m_pProtocol->move( 0 );
  464. };
  465. return false;
  466. };
  467. CAM_TASK *deviceNodeCamera::fetchCamTask( void ){
  468. CAM_TASK *rVal = NULL;
  469. m_mQPROTECTOR.lock();
  470. if (m_qCAM_TASK.size()) {
  471. rVal = m_qCAM_TASK.front();
  472. m_qCAM_TASK.pop();
  473. };
  474. m_mQPROTECTOR.unlock();
  475. return rVal;
  476. };
  477. bool deviceNodeCamera::pushCamTask( CAM_TASK *ptr ){
  478. if ( ptr == NULL ) return false;
  479. m_mQPROTECTOR.lock();
  480. m_qCAM_TASK.push( ptr );
  481. m_mQPROTECTOR.unlock();
  482. return true;
  483. };
  484. bool deviceNodeCamera::fusion_compare( CAM_ROI *ptr, C3D_SPH_DEGREES tp ){
  485. if( ptr == NULL ) return false;
  486. float tFI = fabsf( ptr->cam_position.fi - tp.fi );
  487. float tTETTA = fabsf( ptr->cam_position.tetta - tp.tetta );
  488. #ifdef DEBUG
  489. char tB[128];
  490. sprintf(tB,"FC: FOV:[%.5f:%.5f] dTG:[%.5f:%.5f] %.2f<%.2f>%.2f",ptr->h_fov ,ptr->v_fov, tFI, tTETTA, ptr->min_range, tp.r, ptr->max_range );
  491. LOG(tB);
  492. #endif
  493. if( tFI > ptr->h_fov ) return false;
  494. if( tTETTA > ptr->v_fov ) return false;
  495. if( tp.r < ptr->min_range ) return false;
  496. if( tp.r > ptr->max_range ) return false;
  497. return true;
  498. };
  499. bool deviceNodeCamera::fusion_consumeData( uint32_t db_id, C3D_SPH_DEGREES tOR ){
  500. if( db_id == 0 ) return false;
  501. CAM_TRACK_RECORD * tTrackRecords = (CAM_TRACK_RECORD * ) malloc( sizeof(CAM_TRACK_RECORD));
  502. if( tTrackRecords == NULL ) return false;
  503. #ifdef DEBUG_EXTRA
  504. LOG("Fusion: Consuming new Data!");
  505. #endif
  506. memset(tTrackRecords, 0, sizeof(CAM_TRACK_RECORD));
  507. tTrackRecords->target_direction.fi = tOR.fi;
  508. tTrackRecords->target_direction.r = tOR.r;
  509. tTrackRecords->target_direction.tetta = tOR.tetta;
  510. tTrackRecords->evt_db_ID = db_id;
  511. tTrackRecords->ts_ms = getMilliseconds();
  512. m_mROIsProtector.lock();
  513. if( m_vROIS.size() ){
  514. vCAM_ROIS::iterator idx = m_vROIS.begin();
  515. for( ; idx < m_vROIS.end(); idx++ ) if ( fusion_compare( *idx, tOR ) ) break;
  516. if ( idx != m_vROIS.end() ) {
  517. // have Match!
  518. #ifdef DEBUG_EXTRA
  519. LOG("ROI MATCHED!");
  520. #endif
  521. (*idx)->targets.push_back( tTrackRecords );
  522. fusion_validateROI( tTrackRecords->ts_ms, (*idx) );
  523. } else {
  524. #ifdef DEBUG_EXTRA
  525. LOG("NO MATCH FOUND!");
  526. #endif
  527. // No mathced ROI -> create new one
  528. CAM_ROI * tROI = (CAM_ROI *)malloc(sizeof(CAM_ROI));
  529. if ( tROI ) {
  530. memset( tROI, 0 , sizeof(CAM_ROI) );
  531. tROI->ts_ms = tTrackRecords->ts_ms;
  532. spherical2onvif( tOR, tROI->cam_orientation, m_fMaxRange, m_sCamData.pan_model, m_sCamData.pan_angles, m_sCamData.tilt_model, m_sCamData.tilt_angles );
  533. tROI->cam_position.fi = tOR.fi;
  534. tROI->cam_position.tetta = tOR.tetta;
  535. tROI->cam_position.r = tOR.r;
  536. float cFL = m_fMinFL + m_fR2FL * ( tROI->cam_position.r - m_fMinRange );
  537. tROI->max_range = calcMaxDistance_mm( AC_imager_diag[m_sCamData.imager_type], cFL, m_nRealFrameWidth );
  538. tROI->min_range = calcMinDistance_mm( AC_imager_diag[m_sCamData.imager_type], cFL, m_nRealFrameWidth );
  539. tROI->h_fov = rad2deg( calcFOV_mm( AC_imager_width[m_sCamData.imager_type], cFL ) ) / 2.0f; // div to no to div in comparation function
  540. tROI->v_fov = rad2deg( calcFOV_mm( AC_imager_height[m_sCamData.imager_type], cFL ) ) / 2.0f; // that will be called more ofthen
  541. tROI->targets.push_back( tTrackRecords );
  542. m_vROIS.push_back( tROI );
  543. };
  544. };
  545. } else {
  546. #ifdef DEBUG_EXTRA
  547. LOG("Fusion: NO ROI -> CREATE!");
  548. #endif
  549. //
  550. CAM_ROI * tROI = (CAM_ROI *)malloc(sizeof(CAM_ROI));
  551. if ( tROI ) {
  552. memset( tROI, 0 , sizeof(CAM_ROI) );
  553. tROI->ts_ms = tTrackRecords->ts_ms;
  554. //Set vector Cam Coordinates
  555. tROI->cam_position.fi = tOR.fi;
  556. tROI->cam_position.tetta = tOR.tetta;
  557. tROI->cam_position.r = tOR.r;
  558. // Set vector OnVIF coordinates
  559. spherical2onvif( tOR, tROI->cam_orientation, m_fMaxRange, m_sCamData.pan_model, m_sCamData.pan_angles, m_sCamData.tilt_model, m_sCamData.tilt_angles );
  560. // make fusion data BOX
  561. float cFL = m_fMinFL + m_fR2FL * ( tROI->cam_position.r );// - m_fMinRange );
  562. tROI->min_range = calcMinDistance_mm( AC_imager_diag[m_sCamData.imager_type], cFL, m_nRealFrameWidth );
  563. tROI->max_range = calcMaxDistance_mm( AC_imager_diag[m_sCamData.imager_type], cFL, m_nRealFrameWidth );
  564. tROI->h_fov = rad2deg( calcFOV_mm( AC_imager_width[m_sCamData.imager_type], cFL ) )/ 2.0f; // div to prevent division in comparation
  565. tROI->v_fov = rad2deg( calcFOV_mm( AC_imager_height[m_sCamData.imager_type], cFL ) )/ 2.0f; // function that will be called more ofthen
  566. // Add ROI to vector
  567. tROI->targets.push_back( tTrackRecords );
  568. m_vROIS.push_back( tROI );
  569. } else LOG_ERROR("No MEM4ROI");
  570. };
  571. m_mROIsProtector.unlock();
  572. return true;
  573. };
  574. bool deviceNodeCamera::fusion_validateROI( uint64_t cts, CAM_ROI *ptr ){
  575. if( ptr == NULL ) return false;
  576. if( (cts - ptr->ts_ms) > LOSE_INTERES_TIME_MS ) return false;
  577. #ifdef DEBUG_EXTRA
  578. char tB[128];
  579. sprintf( tB, "\tROI [%d]", ptr->targets.size() );
  580. LOG( tB );
  581. #endif
  582. if( ptr->targets.size() ) {
  583. double tA = 0.0;
  584. double tB = 0.0;
  585. double tC = 0.0;
  586. uint32_t tCNT = 0;
  587. for( vCAM_TRACK_RECORDS::iterator idx = ptr->targets.begin(); idx < ptr->targets.end(); idx++ ) {
  588. if( ( cts - (*idx)->ts_ms ) > LOSE_INTERES_TIME_MS ) {
  589. free( (*idx) );
  590. ptr->targets.erase( idx );
  591. } else {
  592. tA = tA + (*idx)->target_direction.fi;
  593. tB = tB + (*idx)->target_direction.tetta;
  594. tC = tC + (*idx)->target_direction.r;
  595. tCNT++;
  596. };
  597. };
  598. if( tCNT ) {
  599. C3D_SPH_DEGREES L = { 0 };
  600. L.fi = (float) ( tA /(double) tCNT );
  601. L.tetta = (float) ( tB /(double) tCNT );
  602. L.r = (float) ( tC /(double) tCNT );
  603. spherical2onvif(L, ptr->cam_orientation, m_fMaxRange, m_sCamData.pan_model, m_sCamData.pan_angles, m_sCamData.tilt_model, m_sCamData.tilt_angles);
  604. ptr->ts_ms = cts;
  605. float cFL = m_fMinFL + m_fR2FL * ( ptr->cam_position.r - m_fMinRange );
  606. ptr->max_range = calcMaxDistance_mm( AC_imager_diag[m_sCamData.imager_type], cFL, m_nRealFrameWidth );
  607. ptr->min_range = calcMinDistance_mm( AC_imager_diag[m_sCamData.imager_type], cFL, m_nRealFrameWidth );
  608. ptr->h_fov = rad2deg( calcFOV_mm(AC_imager_width[m_sCamData.imager_type], cFL) )/ 2.0f; // div to prevent division in comparation
  609. ptr->v_fov = rad2deg( calcFOV_mm( AC_imager_height[m_sCamData.imager_type], cFL ) )/ 2.0f; // function that will be called more ofthen
  610. return true;
  611. };
  612. };
  613. return false;
  614. };
  615. CAM_ROI *deviceNodeCamera::fusion_fetchROI( void ){
  616. CAM_ROI *tVAL = NULL;
  617. uint64_t cts = 0;
  618. m_mROIsProtector.lock();
  619. vCAM_ROIS::iterator sRec;
  620. if( m_vROIS.size() ){
  621. for( vCAM_ROIS::iterator idx = m_vROIS.begin(); idx < m_vROIS.end(); idx++ ){
  622. if ( tVAL == NULL ) {
  623. sRec = idx;
  624. tVAL = (*idx);
  625. cts = tVAL->ts_ms;
  626. } else {
  627. #ifdef CAM_FETCH_ROI_NEWEST
  628. if ( (*idx)->ts_ms > cts )
  629. #else
  630. if ( (*idx)->ts_ms < cts )
  631. #endif
  632. {
  633. sRec = idx;
  634. tVAL = (*idx);
  635. cts = tVAL->ts_ms;
  636. };
  637. };
  638. };
  639. m_vROIS.erase( sRec );
  640. };
  641. m_mROIsProtector.unlock();
  642. return tVAL;
  643. };
  644. DBC_SNAPSHOT_DATA *deviceNodeCamera::fusion_translate_ROI( CAM_ROI *(&ptr) ){
  645. DBC_SNAPSHOT_DATA *rVal = NULL;
  646. if( ptr == NULL ) return NULL;
  647. if( ptr->targets.size() ){
  648. //if( m_bSourceConnected ){
  649. rVal = (DBC_SNAPSHOT_DATA *)malloc(sizeof(DBC_SNAPSHOT_DATA));
  650. if( rVal ){
  651. memset( rVal, 0, sizeof(DBC_SNAPSHOT_DATA) );
  652. //rVal->stream_id = m_nActiveStreamID;
  653. rVal->stream_id = m_sNodeData.aux_parameter;
  654. for( vCAM_TRACK_RECORDS::iterator idx = ptr->targets.begin(); idx < ptr->targets.end(); idx++ ) {
  655. rVal->assoc_event_ids.push_back( (*idx)->evt_db_ID );
  656. };
  657. };
  658. //};
  659. ptr->targets.clear();
  660. };
  661. // Destruct ROI MEM
  662. delete( (CAM_ROI *) ptr );
  663. ptr = NULL;
  664. // Not Setting MD5 and TS -> will set at capture time
  665. return rVal;
  666. };
  667. void deviceNodeCamera::fusion_validate( void ){
  668. m_mROIsProtector.lock();
  669. if( m_vROIS.size() ){
  670. #ifdef DEBUG_EXTRA
  671. char tB[128];
  672. sprintf( tB, "Fusion: Have [%d] Regions Of Interes", m_vROIS.size() );
  673. LOG( tB );
  674. #endif
  675. uint64_t cts = getMilliseconds();
  676. for( vCAM_ROIS::iterator idx = m_vROIS.begin(); idx < m_vROIS.end(); idx++ ){
  677. if( !fusion_validateROI( cts, *idx ) ) {
  678. free( (*idx) );
  679. m_vROIS.erase( idx );
  680. };
  681. };
  682. };
  683. m_mROIsProtector.unlock();
  684. };
  685. bool deviceNodeCamera::absoluteMove( uint32_t TargetRefID, float PanPOS, float TiltPOS, float ZoomPOS ){
  686. if( m_sCamData.online ){
  687. CAM_TASK *tTask = (CAM_TASK *)malloc(sizeof(CAM_TASK));
  688. if( tTask ){
  689. memset(tTask, 0, sizeof(CAM_TASK));
  690. tTask->CMD = (CAM_PTZ_CMD *)malloc(sizeof(CAM_PTZ_CMD));
  691. if( tTask->CMD ){
  692. tTask->CMD->CMD = PTZ_ABSOLUTE;
  693. tTask->CMD->PAN = PanPOS;
  694. tTask->CMD->TILT = TiltPOS;
  695. tTask->CMD->ZOOM = ZoomPOS;
  696. tTask->movemet_needed = true;
  697. tTask->source_evt_id = TargetRefID;
  698. setWM( CAM_WS_BUSY );
  699. return pushCamTask( tTask );
  700. } else {
  701. LOG_ERROR("CMD malloc Error!");
  702. free( tTask );
  703. };
  704. } else LOG_ERROR("Task malloc error!");
  705. };
  706. return false;
  707. };
  708. bool deviceNodeCamera::absoluteMove( uint32_t TargetRefID, C3D_ORIENT_ONVIF O ){
  709. if( m_sCamData.online ){
  710. CAM_TASK *tTask = (CAM_TASK *)malloc(sizeof(CAM_TASK));
  711. if( tTask ){
  712. memset(tTask, 0, sizeof(CAM_TASK));
  713. tTask->CMD = (CAM_PTZ_CMD *)malloc(sizeof(CAM_PTZ_CMD));
  714. if( tTask->CMD ){
  715. tTask->CMD->CMD = PTZ_ABSOLUTE;
  716. tTask->CMD->PAN = O.pan;
  717. tTask->CMD->TILT = O.tilt;
  718. tTask->CMD->ZOOM = O.zoom;
  719. tTask->movemet_needed = true;
  720. tTask->source_evt_id = TargetRefID;
  721. setWM( CAM_WS_BUSY );
  722. return pushCamTask( tTask );
  723. } else {
  724. LOG_ERROR("CMD malloc Error!");
  725. free( tTask );
  726. };
  727. } else LOG_ERROR("Task malloc error!");
  728. };
  729. return false;
  730. };
  731. void deviceNodeCamera::m_fThreadProc( void ){
  732. DBC_PUSHED_CMD * PUSHED = NULL;
  733. m_bThreadStatus = TH_WORKING;
  734. bool bNewSecondLoop = false;
  735. uint32_t cTimeSeconds = 0;
  736. uint32_t oTimeSeconds = 0;
  737. while( m_bThreadStatus < TH_ENDED ) {
  738. cTimeSeconds = (uint32_t) time( NULL );
  739. if ( bNewSecondLoop = ( cTimeSeconds != oTimeSeconds ) ) oTimeSeconds = cTimeSeconds;
  740. uint8_t tState = getWM();
  741. char tB[128];
  742. fusion_validate();
  743. switch( tState ) {
  744. case CAM_WS_INIT:{
  745. #ifdef DEBUG
  746. LOG("Init Camera - PowerMode");
  747. #endif
  748. //setBusy( true );
  749. if( m_pProtocol->initCamera() ) setWM( CAM_WS_WHITE_BALLANCE );
  750. //setBusy( false );
  751. break;
  752. };
  753. case CAM_WS_WHITE_BALLANCE:{
  754. #ifdef DEBUG
  755. LOG("Set WB");
  756. #endif
  757. //setBusy( true );
  758. if( m_pProtocol->setWhiteBalanceMode( WB_AUTO ) ) setWM( CAM_WS_BACKLIGHT );
  759. //setBusy( false );
  760. break;
  761. };
  762. case CAM_WS_BACKLIGHT:{
  763. #ifdef DEBUG
  764. LOG("Set BLC");
  765. #endif
  766. //setBusy( true );
  767. if( m_pProtocol->setBackLightMode( true ) ) setWM( CAM_WS_AUTO_FOCUS );
  768. //setBusy( false );
  769. break;
  770. };
  771. case CAM_WS_AUTO_FOCUS:{
  772. #ifdef DEBUG
  773. LOG("Set AF");
  774. #endif
  775. //setBusy( true );
  776. if( m_pProtocol->setAutoFocus( true ) ) setWM( CAM_WS_INIT_GO_HOME );
  777. //setBusy( false );
  778. break;
  779. };
  780. case CAM_WS_INIT_GO_HOME:{
  781. #ifdef DEBUG
  782. LOG("INIT GO -1 0 -1");
  783. #endif
  784. m_nHomingCounter = 0;
  785. if( m_pProtocol->goAbsolute( -1, 0, -1 ) ) {
  786. m_fCP_Pan = -1;
  787. m_fCP_Tilt = 0;
  788. m_fCP_Zoom = -1;
  789. setWM( CAM_WS_READY );
  790. };
  791. break;
  792. };
  793. case CAM_WS_AUTOMATED_MOVE:{
  794. m_nRelativeMoveCounter++;
  795. if( ( m_bRelativeMoveMatrix & 0x03 ) != 0 ) {
  796. //Pan Move
  797. if( ( m_bRelativeMoveMatrix & 0x01 ) == 0 ) {
  798. m_fRM_Pan -= m_fSpeedRise;
  799. } else {
  800. m_fRM_Pan += m_fSpeedRise;
  801. };
  802. };
  803. if( ( m_bRelativeMoveMatrix & 0x0C ) != 0 ) {
  804. //TILT Move
  805. if( ( m_bRelativeMoveMatrix & 0x04 ) == 0 ) {
  806. m_fRM_Tilt -= m_fSpeedRise;
  807. } else {
  808. m_fRM_Tilt += m_fSpeedRise;
  809. }
  810. };
  811. if( ( m_bRelativeMoveMatrix & 0x30 ) != 0 ) {
  812. //ZOOM Move
  813. if( ( m_bRelativeMoveMatrix & 0x10 ) == 0 ) {
  814. //Wide
  815. m_fRM_Zoom -= m_fSpeedRise;
  816. } else {
  817. //Tele
  818. m_fRM_Zoom += m_fSpeedRise;
  819. };
  820. };
  821. if( m_fRM_Pan < -1.0f ) m_fRM_Pan = -1.0f;
  822. if( m_fRM_Pan > 1.0f ) m_fRM_Pan = 1.0f;
  823. if( m_fRM_Tilt < -1.0f ) m_fRM_Tilt = -1.0f;
  824. if( m_fRM_Tilt > 1.0f ) m_fRM_Tilt = 1.0f;
  825. if( m_fRM_Zoom < -1.0f ) m_fRM_Zoom = -1.0f;
  826. if( m_fRM_Zoom > 1.0f ) m_fRM_Zoom = 1.0f;
  827. m_fCP_Zoom += 0.5f*m_fRM_Zoom;
  828. if( m_fCP_Zoom < -1.0f ) m_fCP_Zoom = -1.0f;
  829. if( m_fCP_Zoom > 1.0f ) m_fCP_Zoom = 1.0f;
  830. if( !relativeMove( m_fRM_Pan, m_fRM_Tilt, m_fRM_Zoom ) ){
  831. m_nRelativeMoveCounter = 0;
  832. setWM( CAM_WS_READY );
  833. break;
  834. };
  835. if( m_sCamData.ptz_axel ) { //Manual
  836. if (m_nRelativeMoveCounter > m_sCamData.ptz_axel) {
  837. m_nRelativeMoveCounter = 0;
  838. setWM( CAM_WS_READY );
  839. };
  840. } else {
  841. // Stepping Axel by Zoom
  842. uint8_t tVal = (uint8_t)( 10.0f * ( 2.0f - ( 1.0f + m_fCP_Zoom ) ));
  843. if( m_nRelativeMoveCounter > tVal ) {
  844. m_nRelativeMoveCounter = 0;
  845. setWM( CAM_WS_READY );
  846. };
  847. };
  848. break;
  849. };
  850. case CAM_WS_STOP_MOVE:{
  851. m_nRelativeMoveCounter++;
  852. m_fRM_Pan = .0f;
  853. m_fRM_Pan = .0f;
  854. m_fRM_Tilt = .0f;
  855. m_fRM_Tilt = .0f;
  856. m_fRM_Zoom = .0f;
  857. m_fRM_Zoom = .0f;
  858. if( relativeStop() ) {
  859. m_nHomingCounter = 0;
  860. m_nRelativeMoveCounter = 0;
  861. setWM( CAM_WS_READY );
  862. break;
  863. };
  864. if( m_sCamData.ptz_axel ) {
  865. if (m_nRelativeMoveCounter > m_sCamData.ptz_axel) setWM(CAM_WS_READY);
  866. } else {
  867. uint8_t tVal = (uint8_t)( 10.0f * ( 2.0f - ( 1.0f + m_fCP_Zoom ) ));
  868. if (m_nRelativeMoveCounter > tVal) setWM(CAM_WS_READY);
  869. };
  870. break;
  871. };
  872. case CAM_WS_GO_ABS_ROI:
  873. case CAM_WS_GO_ABS_POSITION:{
  874. setWM( CAM_WS_BUSY );
  875. if( m_pCurrentROI != NULL ){
  876. m_nHomingCounter = 0;
  877. if( m_pBEH ){
  878. EVENT_CONTAINER *tEVT = createBasicEvent(
  879. m_sNodeData.node_id,
  880. EVT_CLASS_CAMERA_CTRL,
  881. EVT_CAMERA_MOVE_TO,
  882. NULL, NULL, NULL );
  883. if( tEVT ){
  884. //tEVT->m_db_id = tTASK->source_evt_id; // EVT ids embed in DATA
  885. m_pBEH->broadcast( tEVT );
  886. };
  887. };
  888. //update position Info
  889. m_fCP_Pan = m_pCurrentROI->cam_orientation.pan;
  890. m_fCP_Tilt = m_pCurrentROI->cam_orientation.tilt;
  891. m_fCP_Zoom = m_pCurrentROI->cam_orientation.zoom;
  892. // Do Movement
  893. if( !m_pProtocol->goAbsolute(
  894. m_pCurrentROI->cam_orientation.pan,
  895. m_pCurrentROI->cam_orientation.tilt,
  896. ( m_pCurrentROI->cam_orientation.zoom * m_fZoomCorrection )
  897. )){
  898. LOG_ERROR("Cannot Issue goAbsolute Command!");
  899. setWM( CAM_WS_READY );
  900. } else {
  901. // Send Capture event
  902. DBC_SNAPSHOT_DATA *tData = fusion_translate_ROI( m_pCurrentROI );
  903. if( tData != NULL ) {
  904. if( m_pBEH ){
  905. EVENT_CONTAINER *tEVT = createBasicEvent(
  906. m_sNodeData.node_id,
  907. EVT_CLASS_CAMERA_CTRL,
  908. EVT_CAMERA_ON_POSITION,
  909. NULL, NULL, tData );
  910. if( tEVT ){
  911. #ifdef DEBUG_EXTRA
  912. LOG("BCAST CAM ONPOS");
  913. #endif
  914. //tEVT->m_db_id = tTASK->source_evt_id; // EVT ids embed in DATA
  915. m_pBEH->broadcast( tEVT );
  916. };
  917. };
  918. };
  919. // Waiting capture finish
  920. //setWM( CAM_WS_BUSY );
  921. };
  922. utilizeROI( m_pCurrentROI );
  923. } else setWM( CAM_WS_READY );
  924. break;
  925. };
  926. case CAM_WS_GO_HOMING_PRESET:{
  927. if( m_sCamData.home_token[0] != (char)0 ) {
  928. //LOG( m_sCamData.home_token );
  929. if( !m_pProtocol->goPreset( m_sCamData.home_token )){
  930. LOG_ERROR("Cannot Issue goPreset Command!");
  931. };
  932. };
  933. setWM( CAM_WS_READY );
  934. break;
  935. };
  936. case CAM_WS_BUSY:{
  937. //Handle Operation TO
  938. setWM( CAM_WS_READY );
  939. break;
  940. };
  941. case CAM_WS_READY:{
  942. m_pCurrentROI = fusion_fetchROI();
  943. if( m_pCurrentROI != NULL ) {
  944. #ifdef DEBUG_EXTRA__
  945. LOG("HAVE ROI to see!");
  946. #endif
  947. setWM( CAM_WS_GO_ABS_POSITION );
  948. } else {
  949. //Idle Work --->
  950. if( m_sCamData.homing_enable ){
  951. if ( bNewSecondLoop ) {
  952. if ( m_nHomingCounter < m_sCamData.homing_to ) {
  953. m_nHomingCounter++;
  954. } else {
  955. //LOG("Go Home Position!");
  956. m_nHomingCounter = 0;
  957. setWM( CAM_WS_GO_HOMING_PRESET );
  958. break;
  959. };
  960. };
  961. };
  962. CAM_TASK * tTASK = fetchCamTask();
  963. if ( tTASK != NULL ) {
  964. if( tTASK->movemet_needed ){
  965. CAM_PTZ_CMD *tCMD = tTASK->CMD;
  966. if( tCMD ) {
  967. switch( tCMD->CMD ) {
  968. case PTZ_STOP:{
  969. m_nHomingCounter = 0;
  970. setWM( CAM_WS_STOP_MOVE );
  971. break;
  972. };
  973. case PTZ_MOVE:{
  974. if( tState != CAM_WS_AUTOMATED_MOVE ) m_nRelativeMoveCounter = 0;
  975. m_bRelativeMoveMatrix = 0;
  976. m_fRM_Pan = tCMD->PAN;
  977. m_fRM_Tilt = tCMD->TILT;
  978. m_fRM_Zoom = tCMD->ZOOM;
  979. m_nHomingCounter = 0;
  980. setWM( CAM_WS_AUTOMATED_MOVE );
  981. break;
  982. };
  983. case PTZ_ABSOLUTE:{
  984. m_pCurrentROI = createCAM_ROI();
  985. if( m_pCurrentROI != NULL ){
  986. CAM_TRACK_RECORD * tTarget = (CAM_TRACK_RECORD*)malloc(sizeof(CAM_TRACK_RECORD));
  987. if ( tTarget != NULL ) {
  988. memset( tTarget, 0, sizeof(CAM_TRACK_RECORD) );
  989. tTarget->evt_db_ID = tTASK->source_evt_id;
  990. m_pCurrentROI->targets.push_back( tTarget );
  991. m_pCurrentROI->cam_orientation.pan = tCMD->PAN;
  992. m_pCurrentROI->cam_orientation.tilt = tCMD->TILT;
  993. m_pCurrentROI->cam_orientation.zoom = tCMD->ZOOM;
  994. m_nHomingCounter = 0;
  995. setWM(CAM_WS_GO_ABS_POSITION);
  996. } else {
  997. utilizeROI( m_pCurrentROI );
  998. };
  999. };
  1000. break;
  1001. };
  1002. case PTZ_RELOAD_CAMERA:{
  1003. LOG("Exit Command Rcpt");
  1004. m_bThreadStatus = TH_ENDED;
  1005. };
  1006. };
  1007. free( tCMD );
  1008. tTASK->CMD = NULL;
  1009. };
  1010. } else {
  1011. // No Movement -> Just Capture
  1012. if( m_pBEH ){
  1013. EVENT_CONTAINER *tEVT = createBasicEvent(
  1014. m_sNodeData.node_id,
  1015. EVT_CLASS_CAMERA_CTRL,
  1016. EVT_CAMERA_ON_POSITION,
  1017. NULL, NULL, NULL );
  1018. if( tEVT ){
  1019. tEVT->m_db_id = tTASK->source_evt_id;
  1020. m_pBEH->broadcast(tEVT);
  1021. };
  1022. };
  1023. };
  1024. free( tTASK );
  1025. } else {
  1026. // Lowest Priority to Web Client Commands
  1027. #ifdef DEBUG_EXTRA__
  1028. LOG("Check Web CMD!");
  1029. #endif
  1030. PUSHED = m_pDBC->getNodePushedCMD( m_sNodeData.node_id );
  1031. if( PUSHED != NULL ) {
  1032. #ifdef DEBUG_EXTRA__
  1033. LOG("HAVE Web CMD!");
  1034. #endif
  1035. m_pDBC->updateNodePushedCMD( PUSHED->id, DBC_CMD_READY_TO_CLEAN );
  1036. if( ( PUSHED->CMD & ARGUS_CAM_PCMD_CMD_MASK ) == ARGUS_CAM_PCMD_CMD_MASK ) {
  1037. switch( PUSHED->CMD ) {
  1038. case 0x80:{
  1039. //m_bWM = ANODE_WM_2D_ISSUE_FULL_RESET;
  1040. break;
  1041. };
  1042. case 0x81:{
  1043. //m_bWM = ANODE_WM_2D_GET_FAST_DRAW;
  1044. break;
  1045. };
  1046. case 0x82:{
  1047. break;
  1048. };
  1049. }; //?? Check if we don't miss something!!
  1050. } else if ( tState == CAM_WS_READY || tState == CAM_WS_AUTOMATED_MOVE ){ //No Way to get here
  1051. //Direct Movment Mode
  1052. if( PUSHED->CMD == ARGUS_CAM_PCMD_STOP ) {
  1053. m_nHomingCounter = 0;
  1054. setWM( CAM_WS_STOP_MOVE );
  1055. } else {
  1056. char tB[64];
  1057. if( tState != CAM_WS_AUTOMATED_MOVE ) m_nRelativeMoveCounter = 0;
  1058. m_bRelativeMoveMatrix = ( PUSHED->CMD ) >> 1;
  1059. m_nHomingCounter = 0;
  1060. setWM( CAM_WS_AUTOMATED_MOVE );
  1061. };
  1062. };
  1063. free( PUSHED );
  1064. PUSHED = NULL;
  1065. };
  1066. };
  1067. };
  1068. break;
  1069. };
  1070. case CAM_WS_END:{
  1071. LOG("Exit Command Rcpt");
  1072. m_bThreadStatus = TH_ENDED;
  1073. break;
  1074. };
  1075. };
  1076. SLEEP( DEFAULT_THREAD_SLEEP_TIME );
  1077. };
  1078. #ifdef DEBUG
  1079. LOG("CTRL Loop End!");
  1080. #endif
  1081. };
  1082. bool deviceNodeCamera::testFOV( C3D_DECART L ){
  1083. //System Coords -> trans to local and go to funct
  1084. systemAnchor* tSystem = systemAnchor::getInstance();
  1085. if ( tSystem == NULL ) return false;
  1086. C3D_SPH_DEGREES SL;
  1087. #ifdef DEBUG
  1088. LOG("Test FOV local Decart coords");
  1089. #endif
  1090. if( !tSystem->convertToLocal( &m_oPosition, L, SL ) ) return false;
  1091. return testFOV( SL );
  1092. };
  1093. bool deviceNodeCamera::testFOV( C3D_WGS84_LOC L ){
  1094. //Global Coords
  1095. systemAnchor* tSystem = systemAnchor::getInstance();
  1096. if ( tSystem == NULL ) return false;
  1097. C3D_SPH_DEGREES SL;
  1098. #ifdef DEBUG
  1099. LOG("Test FOV WGS coords");
  1100. #endif
  1101. if( !tSystem->convertToLocal( &m_oPosition, L, SL ) ) return false;
  1102. return testFOV( SL );
  1103. };
  1104. bool deviceNodeCamera::testFOV( C3D_SPH_RADIANS L ){
  1105. //Local Coords
  1106. C3D_SPH_DEGREES SL;
  1107. #ifdef DEBUG
  1108. LOG("Test FOV local Spherical(rad) coords");
  1109. #endif
  1110. spherical2spherical( L, SL );
  1111. return testFOV( SL );
  1112. };
  1113. bool deviceNodeCamera::testFOV( C3D_SPH_DEGREES SL ){
  1114. #ifdef DEBUG
  1115. char tB[128];
  1116. #endif
  1117. #ifdef DEBUG
  1118. LOG("Test FOV local Spherical(deg) coords");
  1119. #endif
  1120. switch ( m_sCamData.triggering_mode ) {
  1121. case CAM_TRIGGER_STRICT:{
  1122. if( SL.r > m_fMaxRange || SL.r < m_fMinRange ){
  1123. #ifdef DEBUG
  1124. sprintf( tB, "Target Range( %.3f.m ) is not in a Range %.3f.m <-> %.3f.m", SL.r, m_fMinRange, m_fMaxRange );
  1125. LOG( tB );
  1126. #endif
  1127. return false;
  1128. };
  1129. break;
  1130. };
  1131. case CAM_TRIGGER_ALL_NEAR:{
  1132. if( SL.r > m_fMaxRange ){
  1133. #ifdef DEBUG
  1134. sprintf( tB, "Target Range( %.3f.m ) is not in a Range %.3f.m <-> %.3f.m", SL.r, m_fMinRange, m_fMaxRange );
  1135. LOG( tB );
  1136. #endif
  1137. return false;
  1138. };
  1139. break;
  1140. };
  1141. case CAM_TRIGGER_ALL_FAR:{
  1142. if( SL.r < m_fMinRange ){
  1143. #ifdef DEBUG
  1144. sprintf( tB, "Target Range( %.3f.m ) is not in a Range %.3f.m <-> %.3f.m", SL.r, m_fMinRange, m_fMaxRange );
  1145. LOG( tB );
  1146. #endif
  1147. return false;
  1148. };
  1149. break;
  1150. };
  1151. case CAM_TRIGGER_ALL: return true;
  1152. };
  1153. float HS = AC_imager_width[m_sCamData.imager_type];
  1154. float VS = AC_imager_height[m_sCamData.imager_type];
  1155. float HS2 = HS * HS;
  1156. float VS2 = VS * VS;
  1157. float IR = HS / VS;
  1158. float IR2 = IR * IR;
  1159. if( m_sCamData.pan_angles == 0 ) {
  1160. // Fixed Camera
  1161. float tA = fabsf( SL.fi );
  1162. float tZ = 0.5f * ( m_fMinHFov + ( SL.r - m_fMinRange ) * m_fR2FL );
  1163. if ( tA > tZ ) return false;
  1164. } else {
  1165. if( m_sCamData.pan_angles < 360 ) { // If endless PAN -> PASSED
  1166. // Partial Pan
  1167. switch( m_sCamData.pan_model ) {
  1168. case 1: {
  1169. // Regular Pan
  1170. float tFOV = 0.5f * ( m_fMinHFov + ( SL.r - m_fMinRange ) * m_fR2FL );
  1171. float tRad = deg2rad( SL.fi );
  1172. #ifdef DEBUG
  1173. sprintf( tB, "FOV: %0.3f CC: %0.3f", tFOV, tRad );
  1174. LOG( tB );
  1175. #endif
  1176. if( ( tRad < ( -1.0 * tFOV ) ) || ( tRad > ( deg2rad( m_sCamData.pan_angles ) + tFOV ) ) ) return false;
  1177. break;
  1178. };
  1179. case 2:{
  1180. break;
  1181. };
  1182. case 3:{
  1183. break;
  1184. };
  1185. };
  1186. };
  1187. };
  1188. if( m_sCamData.tilt_angles == 0 ){
  1189. //Fixed Camera
  1190. if ( ( SL.tetta < ( m_fMaxVFov / -2.0f ) ) || ( SL.tetta > ( m_fMaxVFov / 2.0f ) ) )return false;
  1191. } else {
  1192. if( m_sCamData.tilt_angles < 90 ) { // if Cam CAN DO 90 -> Pass
  1193. // Partial Tilt
  1194. switch( m_sCamData.tilt_model ) {
  1195. case 1: {
  1196. // Regular Tilt
  1197. float tFOV = 0.5f * ( m_fMinVFov + ( m_fMaxVFov - m_fMinVFov ) * ( SL.r / m_fMaxRange ) ) ;
  1198. float tRad = deg2rad( SL.tetta );
  1199. if( ( tRad < ( -1.0 * tFOV ) ) || ( tRad > ( deg2rad( m_sCamData.tilt_angles ) + tFOV ) ) )return false;
  1200. break;
  1201. };
  1202. case 2:{
  1203. break;
  1204. };
  1205. };
  1206. };
  1207. };
  1208. return true;
  1209. };
  1210. bool deviceNodeCamera::lookAt( uint32_t TargetRefID, C3D_WGS84_LOC L ){
  1211. systemAnchor* tSystem = systemAnchor::getInstance();
  1212. if( tSystem == NULL ) return false;
  1213. C3D_SPH_DEGREES SL;
  1214. #ifdef DEBUG_EXTRA
  1215. LOG("Look at WGS coords!");
  1216. #endif
  1217. tSystem->convertToLocal(&m_oPosition, L, SL );
  1218. return lookAt(TargetRefID, SL );
  1219. };
  1220. bool deviceNodeCamera::lookAt( uint32_t TargetRefID, C3D_DECART L ){
  1221. systemAnchor* tSystem = systemAnchor::getInstance();
  1222. if( tSystem == NULL ) return false;
  1223. C3D_SPH_DEGREES SL;
  1224. #ifdef DEBUG_EXTRA
  1225. LOG("Look at System Decart coords!");
  1226. #endif
  1227. tSystem->convertToLocal( &m_oPosition, L, SL );
  1228. return lookAt(TargetRefID, SL );
  1229. };
  1230. bool deviceNodeCamera::lookAt( uint32_t TargetRefID, C3D_SPH_RADIANS L ){
  1231. C3D_SPH_DEGREES SL;
  1232. #ifdef DEBUG_EXTRA
  1233. LOG("Look at spherical(rad) 2 spherical(deg) coords!");
  1234. #endif
  1235. spherical2spherical( L, SL );
  1236. return lookAt(TargetRefID, SL );
  1237. };
  1238. bool deviceNodeCamera::lookAt( uint32_t TargetRefID, C3D_SPH_DEGREES L ){
  1239. //char tB[128];
  1240. //sprintf(tB, "Target On %.3f %.3f %.3f", L.r, L.fi, L.tetta );
  1241. //LOG( tB );
  1242. //sprintf( tB, "Cam GoTo %.3f %.3f %.3f", fP, fT, fZ );
  1243. //LOG( tB );
  1244. #ifdef DEBUG_EXTRA
  1245. LOG("Look at local spherical deg. coords!(final)");
  1246. #endif
  1247. //if( getWM() == CAM_WS_READY ){
  1248. // C3D_ORIENT_ONVIF LL;
  1249. // spherical2onvif( L, LL, m_fMaxRange, m_sCamData.pan_model, m_sCamData.pan_angles, m_sCamData.tilt_model, m_sCamData.tilt_angles );
  1250. // return absoluteMove( TargetRefID, LL );
  1251. //};
  1252. // Camera is Busy
  1253. return fusion_consumeData(TargetRefID, L);
  1254. };
  1255. bool deviceNodeCamera::makeSnap( uint32_t TargetRefID ){
  1256. CAM_TASK *tTask = (CAM_TASK *)malloc(sizeof(CAM_TASK));
  1257. if( tTask ){
  1258. memset(tTask, 0, sizeof(CAM_TASK));
  1259. tTask->CMD = (CAM_PTZ_CMD *) malloc( sizeof(CAM_PTZ_CMD) );
  1260. if( tTask->CMD ){
  1261. tTask->CMD->CMD = PTZ_CAPTURE_ONLY;
  1262. tTask->source_evt_id = TargetRefID;
  1263. return pushCamTask( tTask );
  1264. } else {
  1265. free( tTask );
  1266. };
  1267. };
  1268. return false;
  1269. };
  1270. bool deviceNodeCamera::connectToStream( uint32_t id ){
  1271. /*
  1272. if( id ){
  1273. argusKernelModule * tKM = NULL;
  1274. argusKernel * tKRNL = NULL;
  1275. argusModuleFactory * tMF = NULL;
  1276. if( m_pDBC == NULL ) {
  1277. LOG_ERROR("No Database Connector!");
  1278. return false;
  1279. };
  1280. tKRNL = argusKernel::getInstance();
  1281. if( tKRNL ) {
  1282. tMF = tKRNL->getModuleFactory();
  1283. if( tMF ) {
  1284. tKM = tMF->getModule( ARGUS_MODULE_EMBED_VIDEO );
  1285. } else {
  1286. LOG_ERROR("No ModuleFactory Instance!");
  1287. return false;
  1288. };
  1289. } else {
  1290. LOG_ERROR("No Kernel Instance!");
  1291. return false;
  1292. };
  1293. if( tKM ) {
  1294. // New Module
  1295. DBC_MEDIA_STREAM_DATA *tDATA = m_pDBC->getMediaStreamData( id );
  1296. if( tDATA ) {
  1297. m_sMediaSource.mediaStreamId = id;
  1298. if( strncmp(tDATA->mrl_proto, "v4l2", 4) == 0 ) {
  1299. if (m_pSource != NULL) delete((videoAVLIBSource*)m_pSource);
  1300. m_pSource = (basicMediaSource *) new videoAVLIBSource(&m_sMediaSource);
  1301. } else {
  1302. if (m_pSource != NULL) delete((videoLIVE555Source*)m_pSource);
  1303. m_pSource = (basicMediaSource *) new videoLIVE555Source(&m_sMediaSource );
  1304. };
  1305. if( m_pSource != NULL ) {
  1306. char tMRL[1024];
  1307. #ifdef DEBUG
  1308. LOG("Source OK");
  1309. #endif
  1310. ((videoLIVE555Source*)m_pSource)->setWM( MS_MODE_STREAM_PROXY | MS_MODE_OVERLAYED_LOOPS | MS_MODE_DECODE_FRAMES );
  1311. int tW = ((argusModuleEmbedVideo*)tKM)->getWidh();
  1312. int tH = ((argusModuleEmbedVideo*)tKM)->getHeight();
  1313. int pix = -1;
  1314. bool in_16_9 = (((tDATA->width*100) / tDATA->height ) > 140 );
  1315. bool out_16_9 = (((tW*100) / tH ) > 140 );
  1316. updateOpticalParameters( tW, tH );
  1317. if( strlen( tDATA->c_type ) ){
  1318. };
  1319. //if( tW > 0 ){
  1320. // //m_pSource->setProportionalByWidth( tW );
  1321. // m_pSource->setSize( tW, tH );
  1322. //};
  1323. if( in_16_9 != out_16_9 ){
  1324. if( in_16_9 ){
  1325. tH = ((( tW * 1000 ) / 16 ) * 9 ) / 1000;
  1326. } else {
  1327. tW = ((( tH * 1000 ) / 3 ) * 4 ) / 1000;
  1328. };
  1329. };
  1330. if (strncmp(tDATA->mrl_proto, "v4l2", 4) == 0) {
  1331. sprintf( tMRL, tDATA->mrl );
  1332. } else {
  1333. DBC_CAM_DATA *tCAM = m_pDBC->getCamData( tDATA->source_id );
  1334. if( tCAM ) {
  1335. sprintf( tMRL, "%s://%s:%s@%s:%d%s", tDATA->mrl_proto, tCAM->username, tCAM->password, tCAM->ip, tDATA->mrl_port, tDATA->mrl );
  1336. free( tCAM );
  1337. } else {
  1338. LOG_ERROR("Error Getting CAM Data!");
  1339. delete( m_pSource );
  1340. m_pSource = NULL;
  1341. return false;
  1342. };
  1343. };
  1344. LOG( tMRL );
  1345. if( m_pSource->_open( tMRL, false, -1.0f, pix, tDATA->width, tDATA->height, tW, tH ) ){
  1346. m_bSourceConnected = m_pSource->attachDestination( (argusModuleEmbedVideo*) tKM );
  1347. if ( !m_bSourceConnected ) {
  1348. //delete( m_pSource );
  1349. if( strncmp(tDATA->mrl_proto, "v4l2", 4) == 0 ) {
  1350. delete((videoAVLIBSource*)m_pSource);
  1351. } else {
  1352. delete((videoLIVE555Source*)m_pSource);
  1353. };
  1354. m_pSource = NULL;
  1355. } else {
  1356. m_nActiveStreamID = id;
  1357. #ifdef DEBUG
  1358. LOG("Source is Connected to Output.");
  1359. #endif
  1360. };
  1361. } else {
  1362. LOG_ERROR("Can not Open Video Source!");
  1363. //delete( m_pSource );
  1364. if( strncmp(tDATA->mrl_proto, "v4l2", 4) == 0 ) {
  1365. delete((videoAVLIBSource*)m_pSource);
  1366. } else {
  1367. delete((videoLIVE555Source*)m_pSource);
  1368. };
  1369. m_pSource = NULL;
  1370. };
  1371. } else {
  1372. LOG_ERROR("Video Source Stream Failure!");
  1373. };
  1374. free( tDATA );
  1375. };
  1376. }
  1377. #ifdef DEBUG
  1378. else LOG("No Video Module!")
  1379. #endif
  1380. ;
  1381. };
  1382. LOG("Connect Finished!");
  1383. return m_bSourceConnected;
  1384. */
  1385. return true;
  1386. };
  1387. bool deviceNodeCamera::disconnectFromStream( void ){
  1388. /*if( m_bSourceConnected ) {
  1389. if( m_pSource ){
  1390. delete( m_pSource );
  1391. m_pSource = NULL;
  1392. };
  1393. m_bSourceConnected = false;
  1394. };
  1395. return !m_bSourceConnected;
  1396. */
  1397. return true;
  1398. };
  1399. bool deviceNodeCamera::validateStream( void ){
  1400. /*
  1401. if( m_bSourceConnected ) {
  1402. if( m_pSource ) {
  1403. if( m_pSource->isAttached() ){
  1404. if( m_pSource->getStatus() < MS_STOPED ) return true;
  1405. #ifdef DEBUG
  1406. LOG("Source is Finished!");
  1407. #endif
  1408. };
  1409. #ifdef DEBUG
  1410. LOG("Source is Disconnected!");
  1411. #endif
  1412. } else LOG_ERROR("No Source Object! Set Disconnected!");
  1413. disconnectFromStream();
  1414. };
  1415. return false;
  1416. */
  1417. return true;
  1418. };
  1419. bool deviceNodeCamera::validate(){
  1420. DBC_CAM_DATA *tDATA = m_pDBC->getCamData( m_sCamData.id );
  1421. if ( tDATA == NULL ) return false;
  1422. if ( memcmp( tDATA, &m_sCamData, sizeof(DBC_CAM_DATA) ) != 0 ) {
  1423. //Settings Changed
  1424. memcpy(&m_sCamData, tDATA, sizeof(DBC_CAM_DATA) );
  1425. };
  1426. free( tDATA );
  1427. if (!validateStream()) return false;
  1428. return deviceNode::validate();
  1429. };
  1430. #undef LOG
  1431. #undef LOG_ERROR