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.

1572 lines
58 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  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 * tTrackRecord = (CAM_TRACK_RECORD * ) malloc( sizeof(CAM_TRACK_RECORD));
  502. if( tTrackRecord == NULL ) return false;
  503. #ifdef DEBUG_EXTRA
  504. LOG("Fusion: Consuming new Data!");
  505. #endif
  506. memset(tTrackRecord, 0, sizeof(CAM_TRACK_RECORD));
  507. tTrackRecord->target_direction.fi = tOR.fi;
  508. tTrackRecord->target_direction.r = tOR.r;
  509. tTrackRecord->target_direction.tetta = tOR.tetta;
  510. tTrackRecord->evt_db_ID = db_id;
  511. tTrackRecord->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( tTrackRecord );
  522. fusion_validateROI( tTrackRecord->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 = tTrackRecord->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( tTrackRecord );
  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 = tTrackRecord->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( tTrackRecord );
  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. LOG("Added Event ID");
  656. rVal->assoc_event_ids.push_back( (*idx)->evt_db_ID );
  657. };
  658. };
  659. //};
  660. ptr->targets.clear();
  661. } else {
  662. LOG("No Events ID to ROI");
  663. };
  664. // Destruct ROI MEM
  665. delete( (CAM_ROI *) ptr );
  666. ptr = NULL;
  667. // Not Setting MD5 and TS -> will set at capture time
  668. return rVal;
  669. };
  670. void deviceNodeCamera::fusion_validate( void ){
  671. m_mROIsProtector.lock();
  672. if( m_vROIS.size() ){
  673. #ifdef DEBUG_EXTRA
  674. char tB[128];
  675. sprintf( tB, "Fusion: Have [%d] Regions Of Interes", m_vROIS.size() );
  676. LOG( tB );
  677. #endif
  678. uint64_t cts = getMilliseconds();
  679. for( vCAM_ROIS::iterator idx = m_vROIS.begin(); idx < m_vROIS.end(); idx++ ){
  680. if( !fusion_validateROI( cts, *idx ) ) {
  681. free( (*idx) );
  682. m_vROIS.erase( idx );
  683. };
  684. };
  685. };
  686. m_mROIsProtector.unlock();
  687. };
  688. bool deviceNodeCamera::absoluteMove( uint32_t TargetRefID, float PanPOS, float TiltPOS, float ZoomPOS ){
  689. if( m_sCamData.online ){
  690. CAM_TASK *tTask = (CAM_TASK *)malloc(sizeof(CAM_TASK));
  691. if( tTask ){
  692. memset(tTask, 0, sizeof(CAM_TASK));
  693. tTask->CMD = (CAM_PTZ_CMD *)malloc(sizeof(CAM_PTZ_CMD));
  694. if( tTask->CMD ){
  695. tTask->CMD->CMD = PTZ_ABSOLUTE;
  696. tTask->CMD->PAN = PanPOS;
  697. tTask->CMD->TILT = TiltPOS;
  698. tTask->CMD->ZOOM = ZoomPOS;
  699. tTask->movemet_needed = true;
  700. tTask->source_evt_id = TargetRefID;
  701. setWM( CAM_WS_BUSY );
  702. return pushCamTask( tTask );
  703. } else {
  704. LOG_ERROR("CMD malloc Error!");
  705. free( tTask );
  706. };
  707. } else LOG_ERROR("Task malloc error!");
  708. };
  709. return false;
  710. };
  711. bool deviceNodeCamera::absoluteMove( uint32_t TargetRefID, C3D_ORIENT_ONVIF O ){
  712. if( m_sCamData.online ){
  713. CAM_TASK *tTask = (CAM_TASK *)malloc(sizeof(CAM_TASK));
  714. if( tTask ){
  715. memset(tTask, 0, sizeof(CAM_TASK));
  716. tTask->CMD = (CAM_PTZ_CMD *)malloc(sizeof(CAM_PTZ_CMD));
  717. if( tTask->CMD ){
  718. tTask->CMD->CMD = PTZ_ABSOLUTE;
  719. tTask->CMD->PAN = O.pan;
  720. tTask->CMD->TILT = O.tilt;
  721. tTask->CMD->ZOOM = O.zoom;
  722. tTask->movemet_needed = true;
  723. tTask->source_evt_id = TargetRefID;
  724. setWM( CAM_WS_BUSY );
  725. return pushCamTask( tTask );
  726. } else {
  727. LOG_ERROR("CMD malloc Error!");
  728. free( tTask );
  729. };
  730. } else LOG_ERROR("Task malloc error!");
  731. };
  732. return false;
  733. };
  734. void deviceNodeCamera::m_fThreadProc( void ){
  735. DBC_PUSHED_CMD * PUSHED = NULL;
  736. m_bThreadStatus = TH_WORKING;
  737. bool bNewSecondLoop = false;
  738. uint32_t cTimeSeconds = 0;
  739. uint32_t oTimeSeconds = 0;
  740. while( m_bThreadStatus < TH_ENDED ) {
  741. cTimeSeconds = (uint32_t) time( NULL );
  742. if ( bNewSecondLoop = ( cTimeSeconds != oTimeSeconds ) ) oTimeSeconds = cTimeSeconds;
  743. uint8_t tState = getWM();
  744. char tB[128];
  745. fusion_validate();
  746. switch( tState ) {
  747. case CAM_WS_INIT:{
  748. #ifdef DEBUG
  749. LOG("Init Camera - PowerMode");
  750. #endif
  751. //setBusy( true );
  752. if( m_pProtocol->initCamera() ) setWM( CAM_WS_WHITE_BALLANCE );
  753. //setBusy( false );
  754. break;
  755. };
  756. case CAM_WS_WHITE_BALLANCE:{
  757. #ifdef DEBUG
  758. LOG("Set WB");
  759. #endif
  760. //setBusy( true );
  761. if( m_pProtocol->setWhiteBalanceMode( WB_AUTO ) ) setWM( CAM_WS_BACKLIGHT );
  762. //setBusy( false );
  763. break;
  764. };
  765. case CAM_WS_BACKLIGHT:{
  766. #ifdef DEBUG
  767. LOG("Set BLC");
  768. #endif
  769. //setBusy( true );
  770. if( m_pProtocol->setBackLightMode( true ) ) setWM( CAM_WS_AUTO_FOCUS );
  771. //setBusy( false );
  772. break;
  773. };
  774. case CAM_WS_AUTO_FOCUS:{
  775. #ifdef DEBUG
  776. LOG("Set AF");
  777. #endif
  778. //setBusy( true );
  779. if( m_pProtocol->setAutoFocus( true ) ) setWM( CAM_WS_INIT_GO_HOME );
  780. //setBusy( false );
  781. break;
  782. };
  783. case CAM_WS_INIT_GO_HOME:{
  784. #ifdef DEBUG
  785. LOG("INIT GO -1 0 -1");
  786. #endif
  787. m_nHomingCounter = 0;
  788. if( m_pProtocol->goAbsolute( -1, 0, -1 ) ) {
  789. m_fCP_Pan = -1;
  790. m_fCP_Tilt = 0;
  791. m_fCP_Zoom = -1;
  792. setWM( CAM_WS_READY );
  793. };
  794. break;
  795. };
  796. case CAM_WS_AUTOMATED_MOVE:{
  797. m_nRelativeMoveCounter++;
  798. if( ( m_bRelativeMoveMatrix & 0x03 ) != 0 ) {
  799. //Pan Move
  800. if( ( m_bRelativeMoveMatrix & 0x01 ) == 0 ) {
  801. m_fRM_Pan -= m_fSpeedRise;
  802. } else {
  803. m_fRM_Pan += m_fSpeedRise;
  804. };
  805. };
  806. if( ( m_bRelativeMoveMatrix & 0x0C ) != 0 ) {
  807. //TILT Move
  808. if( ( m_bRelativeMoveMatrix & 0x04 ) == 0 ) {
  809. m_fRM_Tilt -= m_fSpeedRise;
  810. } else {
  811. m_fRM_Tilt += m_fSpeedRise;
  812. }
  813. };
  814. if( ( m_bRelativeMoveMatrix & 0x30 ) != 0 ) {
  815. //ZOOM Move
  816. if( ( m_bRelativeMoveMatrix & 0x10 ) == 0 ) {
  817. //Wide
  818. m_fRM_Zoom -= m_fSpeedRise;
  819. } else {
  820. //Tele
  821. m_fRM_Zoom += m_fSpeedRise;
  822. };
  823. };
  824. if( m_fRM_Pan < -1.0f ) m_fRM_Pan = -1.0f;
  825. if( m_fRM_Pan > 1.0f ) m_fRM_Pan = 1.0f;
  826. if( m_fRM_Tilt < -1.0f ) m_fRM_Tilt = -1.0f;
  827. if( m_fRM_Tilt > 1.0f ) m_fRM_Tilt = 1.0f;
  828. if( m_fRM_Zoom < -1.0f ) m_fRM_Zoom = -1.0f;
  829. if( m_fRM_Zoom > 1.0f ) m_fRM_Zoom = 1.0f;
  830. m_fCP_Zoom += 0.5f*m_fRM_Zoom;
  831. if( m_fCP_Zoom < -1.0f ) m_fCP_Zoom = -1.0f;
  832. if( m_fCP_Zoom > 1.0f ) m_fCP_Zoom = 1.0f;
  833. if( !relativeMove( m_fRM_Pan, m_fRM_Tilt, m_fRM_Zoom ) ){
  834. m_nRelativeMoveCounter = 0;
  835. setWM( CAM_WS_READY );
  836. break;
  837. };
  838. if( m_sCamData.ptz_axel ) { //Manual
  839. if (m_nRelativeMoveCounter > m_sCamData.ptz_axel) {
  840. m_nRelativeMoveCounter = 0;
  841. setWM( CAM_WS_READY );
  842. };
  843. } else {
  844. // Stepping Axel by Zoom
  845. uint8_t tVal = (uint8_t)( 10.0f * ( 2.0f - ( 1.0f + m_fCP_Zoom ) ));
  846. if( m_nRelativeMoveCounter > tVal ) {
  847. m_nRelativeMoveCounter = 0;
  848. setWM( CAM_WS_READY );
  849. };
  850. };
  851. break;
  852. };
  853. case CAM_WS_STOP_MOVE:{
  854. m_nRelativeMoveCounter++;
  855. m_fRM_Pan = .0f;
  856. m_fRM_Pan = .0f;
  857. m_fRM_Tilt = .0f;
  858. m_fRM_Tilt = .0f;
  859. m_fRM_Zoom = .0f;
  860. m_fRM_Zoom = .0f;
  861. if( relativeStop() ) {
  862. m_nHomingCounter = 0;
  863. m_nRelativeMoveCounter = 0;
  864. setWM( CAM_WS_READY );
  865. break;
  866. };
  867. if( m_sCamData.ptz_axel ) {
  868. if (m_nRelativeMoveCounter > m_sCamData.ptz_axel) setWM(CAM_WS_READY);
  869. } else {
  870. uint8_t tVal = (uint8_t)( 10.0f * ( 2.0f - ( 1.0f + m_fCP_Zoom ) ));
  871. if (m_nRelativeMoveCounter > tVal) setWM(CAM_WS_READY);
  872. };
  873. break;
  874. };
  875. case CAM_WS_GO_ABS_ROI:
  876. case CAM_WS_GO_ABS_POSITION:{
  877. setWM( CAM_WS_BUSY );
  878. if( m_pCurrentROI != NULL ){
  879. m_nHomingCounter = 0;
  880. if( m_pBEH ){
  881. EVENT_CONTAINER *tEVT = createBasicEvent(
  882. m_sNodeData.node_id,
  883. EVT_CLASS_CAMERA_CTRL,
  884. EVT_CAMERA_MOVE_TO,
  885. NULL, NULL, NULL );
  886. if( tEVT ){
  887. //tEVT->m_db_id = tTASK->source_evt_id; // EVT ids embed in DATA
  888. m_pBEH->broadcast( tEVT );
  889. };
  890. };
  891. //update position Info
  892. m_fCP_Pan = m_pCurrentROI->cam_orientation.pan;
  893. m_fCP_Tilt = m_pCurrentROI->cam_orientation.tilt;
  894. m_fCP_Zoom = m_pCurrentROI->cam_orientation.zoom;
  895. // Do Movement
  896. LOG("GO ABS Movement -> INSTCAP??" );
  897. if( !m_pProtocol->goAbsolute(
  898. m_pCurrentROI->cam_orientation.pan,
  899. m_pCurrentROI->cam_orientation.tilt,
  900. ( m_pCurrentROI->cam_orientation.zoom * m_fZoomCorrection )
  901. )){
  902. LOG_ERROR("Cannot Issue goAbsolute Command!->Restart Camera?");
  903. setWM( CAM_WS_END );//CAM_WS_READY );
  904. } else {
  905. // Waiting Movement finish
  906. setWM( CAM_WS_WAIT_ONPOS );
  907. /*
  908. // Send Capture event
  909. DBC_SNAPSHOT_DATA *tData = fusion_translate_ROI( m_pCurrentROI );
  910. if( tData != NULL ) {
  911. if( m_pBEH ){
  912. EVENT_CONTAINER *tEVT = createBasicEvent(
  913. m_sNodeData.node_id,
  914. EVT_CLASS_CAMERA_CTRL,
  915. EVT_CAMERA_ON_POSITION,
  916. NULL, NULL, tData );
  917. if( tEVT ){
  918. #ifdef DEBUG
  919. LOG("BCAST CAM ONPOS");
  920. #endif
  921. //tEVT->m_db_id = tTASK->source_evt_id; // EVT ids embed in DATA
  922. m_pBEH->broadcast( tEVT );
  923. } else {
  924. free( tData );
  925. };
  926. } else {
  927. free( tData );
  928. };
  929. };
  930. */
  931. };
  932. //utilizeROI( m_pCurrentROI );
  933. } else setWM( CAM_WS_READY );
  934. break;
  935. };
  936. case CAM_WS_WAIT_ONPOS:{
  937. if( m_pCurrentROI != NULL ){
  938. m_pProtocol->waitMoveIsDone();
  939. if( 0 ){
  940. LOG_ERROR("Cannot Issue getPosition Command!->Restart Camera?");
  941. setWM( CAM_WS_END );//CAM_WS_READY );
  942. } else {
  943. // Send Capture event
  944. DBC_SNAPSHOT_DATA *tData = fusion_translate_ROI( m_pCurrentROI );
  945. if( tData != NULL ) {
  946. if( m_pBEH ){
  947. EVENT_CONTAINER *tEVT = createBasicEvent(
  948. m_sNodeData.node_id,
  949. EVT_CLASS_CAMERA_CTRL,
  950. EVT_CAMERA_ON_POSITION,
  951. NULL, NULL, tData );
  952. if( tEVT ){
  953. #ifdef DEBUG
  954. LOG("BCAST CAM ONPOS");
  955. #endif
  956. //tEVT->m_db_id = tTASK->source_evt_id; // EVT ids embed in DATA
  957. m_pBEH->broadcast( tEVT );
  958. } else {
  959. free( tData );
  960. };
  961. } else {
  962. free( tData );
  963. };
  964. };
  965. };
  966. utilizeROI( m_pCurrentROI );
  967. };
  968. setWM( CAM_WS_READY );
  969. break;
  970. };
  971. case CAM_WS_GO_HOMING_PRESET:{
  972. if( m_sCamData.home_token[0] != (char)0 ) {
  973. //LOG( m_sCamData.home_token );
  974. if( !m_pProtocol->goPreset( m_sCamData.home_token )){
  975. LOG_ERROR("Cannot Issue goPreset Command!");
  976. };
  977. };
  978. setWM( CAM_WS_READY );
  979. break;
  980. };
  981. case CAM_WS_BUSY:{
  982. //Handle Operation TO
  983. setWM( CAM_WS_READY );
  984. break;
  985. };
  986. case CAM_WS_READY:{
  987. m_pCurrentROI = fusion_fetchROI();
  988. if( m_pCurrentROI != NULL ) {
  989. #ifdef DEBUG_EXTRA__
  990. LOG("HAVE ROI to see!");
  991. #endif
  992. setWM( CAM_WS_GO_ABS_POSITION );
  993. } else {
  994. //Idle Work --->
  995. if( m_sCamData.homing_enable ){
  996. if ( bNewSecondLoop ) {
  997. if ( m_nHomingCounter < m_sCamData.homing_to ) {
  998. m_nHomingCounter++;
  999. } else {
  1000. //LOG("Go Home Position!");
  1001. m_nHomingCounter = 0;
  1002. setWM( CAM_WS_GO_HOMING_PRESET );
  1003. break;
  1004. };
  1005. };
  1006. };
  1007. CAM_TASK * tTASK = fetchCamTask();
  1008. if ( tTASK != NULL ) {
  1009. if( tTASK->movemet_needed ){
  1010. CAM_PTZ_CMD *tCMD = tTASK->CMD;
  1011. if( tCMD ) {
  1012. switch( tCMD->CMD ) {
  1013. case PTZ_STOP:{
  1014. m_nHomingCounter = 0;
  1015. setWM( CAM_WS_STOP_MOVE );
  1016. break;
  1017. };
  1018. case PTZ_MOVE:{
  1019. if( tState != CAM_WS_AUTOMATED_MOVE ) m_nRelativeMoveCounter = 0;
  1020. m_bRelativeMoveMatrix = 0;
  1021. m_fRM_Pan = tCMD->PAN;
  1022. m_fRM_Tilt = tCMD->TILT;
  1023. m_fRM_Zoom = tCMD->ZOOM;
  1024. m_nHomingCounter = 0;
  1025. setWM( CAM_WS_AUTOMATED_MOVE );
  1026. break;
  1027. };
  1028. case PTZ_ABSOLUTE:{
  1029. m_pCurrentROI = createCAM_ROI();
  1030. if( m_pCurrentROI != NULL ){
  1031. CAM_TRACK_RECORD * tTarget = (CAM_TRACK_RECORD*)malloc(sizeof(CAM_TRACK_RECORD));
  1032. if ( tTarget != NULL ) {
  1033. memset( tTarget, 0, sizeof(CAM_TRACK_RECORD) );
  1034. tTarget->evt_db_ID = tTASK->source_evt_id;
  1035. m_pCurrentROI->targets.push_back( tTarget );
  1036. m_pCurrentROI->cam_orientation.pan = tCMD->PAN;
  1037. m_pCurrentROI->cam_orientation.tilt = tCMD->TILT;
  1038. m_pCurrentROI->cam_orientation.zoom = tCMD->ZOOM;
  1039. m_nHomingCounter = 0;
  1040. setWM(CAM_WS_GO_ABS_POSITION);
  1041. } else {
  1042. utilizeROI( m_pCurrentROI );
  1043. };
  1044. };
  1045. break;
  1046. };
  1047. case PTZ_RELOAD_CAMERA:{
  1048. LOG("Exit Command Rcpt");
  1049. m_bThreadStatus = TH_ENDED;
  1050. };
  1051. };
  1052. free( tCMD );
  1053. tTASK->CMD = NULL;
  1054. };
  1055. } else {
  1056. LOG("No Movement -> INSTCAP" );
  1057. // No Movement -> Just Capture
  1058. if( m_pBEH ){
  1059. EVENT_CONTAINER *tEVT = createBasicEvent(
  1060. m_sNodeData.node_id,
  1061. EVT_CLASS_CAMERA_CTRL,
  1062. EVT_CAMERA_ON_POSITION,
  1063. NULL, NULL, NULL );
  1064. if( tEVT ){
  1065. tEVT->m_db_id = tTASK->source_evt_id;
  1066. m_pBEH->broadcast(tEVT);
  1067. };
  1068. };
  1069. };
  1070. free( tTASK );
  1071. } else {
  1072. // Lowest Priority to Web Client Commands
  1073. #ifdef DEBUG_EXTRA__
  1074. LOG("Check Web CMD!");
  1075. #endif
  1076. PUSHED = m_pDBC->getNodePushedCMD( m_sNodeData.node_id );
  1077. if( PUSHED != NULL ) {
  1078. #ifdef DEBUG_EXTRA__
  1079. LOG("HAVE Web CMD!");
  1080. #endif
  1081. m_pDBC->updateNodePushedCMD( PUSHED->id, DBC_CMD_READY_TO_CLEAN );
  1082. if( ( PUSHED->CMD & ARGUS_CAM_PCMD_CMD_MASK ) == ARGUS_CAM_PCMD_CMD_MASK ) {
  1083. switch( PUSHED->CMD ) {
  1084. case 0x80:{
  1085. //m_bWM = ANODE_WM_2D_ISSUE_FULL_RESET;
  1086. break;
  1087. };
  1088. case 0x81:{
  1089. //m_bWM = ANODE_WM_2D_GET_FAST_DRAW;
  1090. break;
  1091. };
  1092. case 0x82:{
  1093. break;
  1094. };
  1095. }; //?? Check if we don't miss something!!
  1096. } else if ( tState == CAM_WS_READY || tState == CAM_WS_AUTOMATED_MOVE ){ //No Way to get here
  1097. //Direct Movment Mode
  1098. if( PUSHED->CMD == ARGUS_CAM_PCMD_STOP ) {
  1099. m_nHomingCounter = 0;
  1100. setWM( CAM_WS_STOP_MOVE );
  1101. } else {
  1102. char tB[64];
  1103. if( tState != CAM_WS_AUTOMATED_MOVE ) m_nRelativeMoveCounter = 0;
  1104. m_bRelativeMoveMatrix = ( PUSHED->CMD ) >> 1;
  1105. m_nHomingCounter = 0;
  1106. setWM( CAM_WS_AUTOMATED_MOVE );
  1107. };
  1108. };
  1109. free( PUSHED );
  1110. PUSHED = NULL;
  1111. };
  1112. };
  1113. };
  1114. break;
  1115. };
  1116. case CAM_WS_END:{
  1117. LOG("Exit Command Rcpt");
  1118. m_bThreadStatus = TH_ENDED;
  1119. break;
  1120. };
  1121. };
  1122. SLEEP( DEFAULT_THREAD_SLEEP_TIME );
  1123. };
  1124. #ifdef DEBUG
  1125. LOG("CTRL Loop End!");
  1126. #endif
  1127. };
  1128. bool deviceNodeCamera::testFOV( C3D_DECART L ){
  1129. //System Coords -> trans to local and go to funct
  1130. systemAnchor* tSystem = systemAnchor::getInstance();
  1131. if ( tSystem == NULL ) return false;
  1132. C3D_SPH_DEGREES SL;
  1133. #ifdef DEBUG
  1134. LOG("Test FOV local Decart coords");
  1135. #endif
  1136. if( !tSystem->convertToLocal( &m_oPosition, L, SL ) ) return false;
  1137. return testFOV( SL );
  1138. };
  1139. bool deviceNodeCamera::testFOV( C3D_WGS84_LOC L ){
  1140. //Global Coords
  1141. systemAnchor* tSystem = systemAnchor::getInstance();
  1142. if ( tSystem == NULL ) return false;
  1143. C3D_SPH_DEGREES SL;
  1144. #ifdef DEBUG
  1145. LOG("Test FOV WGS coords");
  1146. #endif
  1147. if( !tSystem->convertToLocal( &m_oPosition, L, SL ) ) return false;
  1148. return testFOV( SL );
  1149. };
  1150. bool deviceNodeCamera::testFOV( C3D_SPH_RADIANS L ){
  1151. //Local Coords
  1152. C3D_SPH_DEGREES SL;
  1153. #ifdef DEBUG
  1154. LOG("Test FOV local Spherical(rad) coords");
  1155. #endif
  1156. spherical2spherical( L, SL );
  1157. return testFOV( SL );
  1158. };
  1159. bool deviceNodeCamera::testFOV( C3D_SPH_DEGREES SL ){
  1160. #ifdef DEBUG
  1161. char tB[128];
  1162. #endif
  1163. #ifdef DEBUG
  1164. LOG("Test FOV local Spherical(deg) coords");
  1165. #endif
  1166. switch ( m_sCamData.triggering_mode ) {
  1167. case CAM_TRIGGER_STRICT:{
  1168. if( SL.r > m_fMaxRange || SL.r < m_fMinRange ){
  1169. #ifdef DEBUG
  1170. sprintf( tB, "Target Range( %.3f.m ) is not in a Range %.3f.m <-> %.3f.m", SL.r, m_fMinRange, m_fMaxRange );
  1171. LOG( tB );
  1172. #endif
  1173. return false;
  1174. };
  1175. break;
  1176. };
  1177. case CAM_TRIGGER_ALL_NEAR:{
  1178. if( SL.r > m_fMaxRange ){
  1179. #ifdef DEBUG
  1180. sprintf( tB, "Target Range( %.3f.m ) is not in a Range %.3f.m <-> %.3f.m", SL.r, m_fMinRange, m_fMaxRange );
  1181. LOG( tB );
  1182. #endif
  1183. return false;
  1184. };
  1185. break;
  1186. };
  1187. case CAM_TRIGGER_ALL_FAR:{
  1188. if( SL.r < m_fMinRange ){
  1189. #ifdef DEBUG
  1190. sprintf( tB, "Target Range( %.3f.m ) is not in a Range %.3f.m <-> %.3f.m", SL.r, m_fMinRange, m_fMaxRange );
  1191. LOG( tB );
  1192. #endif
  1193. return false;
  1194. };
  1195. break;
  1196. };
  1197. case CAM_TRIGGER_ALL: return true;
  1198. };
  1199. float HS = AC_imager_width[m_sCamData.imager_type];
  1200. float VS = AC_imager_height[m_sCamData.imager_type];
  1201. float HS2 = HS * HS;
  1202. float VS2 = VS * VS;
  1203. float IR = HS / VS;
  1204. float IR2 = IR * IR;
  1205. if( m_sCamData.pan_angles == 0 ) {
  1206. // Fixed Camera
  1207. float tA = fabsf( SL.fi );
  1208. float tZ = 0.5f * ( m_fMinHFov + ( SL.r - m_fMinRange ) * m_fR2FL );
  1209. if ( tA > tZ ) return false;
  1210. } else {
  1211. if( m_sCamData.pan_angles < 360 ) { // If endless PAN -> PASSED
  1212. // Partial Pan
  1213. switch( m_sCamData.pan_model ) {
  1214. case 1: {
  1215. // Regular Pan
  1216. float tFOV = 0.5f * ( m_fMinHFov + ( SL.r - m_fMinRange ) * m_fR2FL );
  1217. float tRad = deg2rad( SL.fi );
  1218. #ifdef DEBUG
  1219. sprintf( tB, "FOV: %0.3f CC: %0.3f", tFOV, tRad );
  1220. LOG( tB );
  1221. #endif
  1222. if( ( tRad < ( -1.0 * tFOV ) ) || ( tRad > ( deg2rad( m_sCamData.pan_angles ) + tFOV ) ) ) return false;
  1223. break;
  1224. };
  1225. case 2:{
  1226. break;
  1227. };
  1228. case 3:{
  1229. break;
  1230. };
  1231. };
  1232. };
  1233. };
  1234. if( m_sCamData.tilt_angles == 0 ){
  1235. //Fixed Camera
  1236. if ( ( SL.tetta < ( m_fMaxVFov / -2.0f ) ) || ( SL.tetta > ( m_fMaxVFov / 2.0f ) ) )return false;
  1237. } else {
  1238. if( m_sCamData.tilt_angles < 90 ) { // if Cam CAN DO 90 -> Pass
  1239. // Partial Tilt
  1240. switch( m_sCamData.tilt_model ) {
  1241. case 1: {
  1242. // Regular Tilt
  1243. float tFOV = 0.5f * ( m_fMinVFov + ( m_fMaxVFov - m_fMinVFov ) * ( SL.r / m_fMaxRange ) ) ;
  1244. float tRad = deg2rad( SL.tetta );
  1245. if( ( tRad < ( -1.0 * tFOV ) ) || ( tRad > ( deg2rad( m_sCamData.tilt_angles ) + tFOV ) ) )return false;
  1246. break;
  1247. };
  1248. case 2:{
  1249. break;
  1250. };
  1251. };
  1252. };
  1253. };
  1254. return true;
  1255. };
  1256. bool deviceNodeCamera::lookAt( uint32_t TargetRefID, C3D_WGS84_LOC L ){
  1257. systemAnchor* tSystem = systemAnchor::getInstance();
  1258. if( tSystem == NULL ) return false;
  1259. C3D_SPH_DEGREES SL;
  1260. #ifdef DEBUG_EXTRA
  1261. LOG("Look at WGS coords!");
  1262. #endif
  1263. tSystem->convertToLocal(&m_oPosition, L, SL );
  1264. return lookAt(TargetRefID, SL );
  1265. };
  1266. bool deviceNodeCamera::lookAt( uint32_t TargetRefID, C3D_DECART L ){
  1267. systemAnchor* tSystem = systemAnchor::getInstance();
  1268. if( tSystem == NULL ) return false;
  1269. C3D_SPH_DEGREES SL;
  1270. #ifdef DEBUG_EXTRA
  1271. LOG("Look at System Decart coords!");
  1272. #endif
  1273. tSystem->convertToLocal( &m_oPosition, L, SL );
  1274. return lookAt(TargetRefID, SL );
  1275. };
  1276. bool deviceNodeCamera::lookAt( uint32_t TargetRefID, C3D_SPH_RADIANS L ){
  1277. C3D_SPH_DEGREES SL;
  1278. #ifdef DEBUG_EXTRA
  1279. LOG("Look at spherical(rad) 2 spherical(deg) coords!");
  1280. #endif
  1281. spherical2spherical( L, SL );
  1282. return lookAt(TargetRefID, SL );
  1283. };
  1284. bool deviceNodeCamera::lookAt( uint32_t TargetRefID, C3D_SPH_DEGREES L ){
  1285. //char tB[128];
  1286. //sprintf(tB, "Target On %.3f %.3f %.3f", L.r, L.fi, L.tetta );
  1287. //LOG( tB );
  1288. //sprintf( tB, "Cam GoTo %.3f %.3f %.3f", fP, fT, fZ );
  1289. //LOG( tB );
  1290. #ifdef DEBUG_EXTRA
  1291. LOG("Look at local spherical deg. coords!(final)");
  1292. #endif
  1293. //if( getWM() == CAM_WS_READY ){
  1294. // C3D_ORIENT_ONVIF LL;
  1295. // spherical2onvif( L, LL, m_fMaxRange, m_sCamData.pan_model, m_sCamData.pan_angles, m_sCamData.tilt_model, m_sCamData.tilt_angles );
  1296. // return absoluteMove( TargetRefID, LL );
  1297. //};
  1298. // Camera is Busy
  1299. return fusion_consumeData(TargetRefID, L);
  1300. };
  1301. bool deviceNodeCamera::makeSnap( uint32_t TargetRefID ){
  1302. CAM_TASK *tTask = (CAM_TASK *)malloc(sizeof(CAM_TASK));
  1303. if( tTask ){
  1304. memset(tTask, 0, sizeof(CAM_TASK));
  1305. tTask->CMD = (CAM_PTZ_CMD *) malloc( sizeof(CAM_PTZ_CMD) );
  1306. if( tTask->CMD ){
  1307. tTask->CMD->CMD = PTZ_CAPTURE_ONLY;
  1308. tTask->source_evt_id = TargetRefID;
  1309. return pushCamTask( tTask );
  1310. } else {
  1311. free( tTask );
  1312. };
  1313. };
  1314. return false;
  1315. };
  1316. bool deviceNodeCamera::connectToStream( uint32_t id ){
  1317. /*
  1318. if( id ){
  1319. argusKernelModule * tKM = NULL;
  1320. argusKernel * tKRNL = NULL;
  1321. argusModuleFactory * tMF = NULL;
  1322. if( m_pDBC == NULL ) {
  1323. LOG_ERROR("No Database Connector!");
  1324. return false;
  1325. };
  1326. tKRNL = argusKernel::getInstance();
  1327. if( tKRNL ) {
  1328. tMF = tKRNL->getModuleFactory();
  1329. if( tMF ) {
  1330. tKM = tMF->getModule( ARGUS_MODULE_EMBED_VIDEO );
  1331. } else {
  1332. LOG_ERROR("No ModuleFactory Instance!");
  1333. return false;
  1334. };
  1335. } else {
  1336. LOG_ERROR("No Kernel Instance!");
  1337. return false;
  1338. };
  1339. if( tKM ) {
  1340. // New Module
  1341. DBC_MEDIA_STREAM_DATA *tDATA = m_pDBC->getMediaStreamData( id );
  1342. if( tDATA ) {
  1343. m_sMediaSource.mediaStreamId = id;
  1344. if( strncmp(tDATA->mrl_proto, "v4l2", 4) == 0 ) {
  1345. if (m_pSource != NULL) delete((videoAVLIBSource*)m_pSource);
  1346. m_pSource = (basicMediaSource *) new videoAVLIBSource(&m_sMediaSource);
  1347. } else {
  1348. if (m_pSource != NULL) delete((videoLIVE555Source*)m_pSource);
  1349. m_pSource = (basicMediaSource *) new videoLIVE555Source(&m_sMediaSource );
  1350. };
  1351. if( m_pSource != NULL ) {
  1352. char tMRL[1024];
  1353. #ifdef DEBUG
  1354. LOG("Source OK");
  1355. #endif
  1356. ((videoLIVE555Source*)m_pSource)->setWM( MS_MODE_STREAM_PROXY | MS_MODE_OVERLAYED_LOOPS | MS_MODE_DECODE_FRAMES );
  1357. int tW = ((argusModuleEmbedVideo*)tKM)->getWidh();
  1358. int tH = ((argusModuleEmbedVideo*)tKM)->getHeight();
  1359. int pix = -1;
  1360. bool in_16_9 = (((tDATA->width*100) / tDATA->height ) > 140 );
  1361. bool out_16_9 = (((tW*100) / tH ) > 140 );
  1362. updateOpticalParameters( tW, tH );
  1363. if( strlen( tDATA->c_type ) ){
  1364. };
  1365. //if( tW > 0 ){
  1366. // //m_pSource->setProportionalByWidth( tW );
  1367. // m_pSource->setSize( tW, tH );
  1368. //};
  1369. if( in_16_9 != out_16_9 ){
  1370. if( in_16_9 ){
  1371. tH = ((( tW * 1000 ) / 16 ) * 9 ) / 1000;
  1372. } else {
  1373. tW = ((( tH * 1000 ) / 3 ) * 4 ) / 1000;
  1374. };
  1375. };
  1376. if (strncmp(tDATA->mrl_proto, "v4l2", 4) == 0) {
  1377. sprintf( tMRL, tDATA->mrl );
  1378. } else {
  1379. DBC_CAM_DATA *tCAM = m_pDBC->getCamData( tDATA->source_id );
  1380. if( tCAM ) {
  1381. sprintf( tMRL, "%s://%s:%s@%s:%d%s", tDATA->mrl_proto, tCAM->username, tCAM->password, tCAM->ip, tDATA->mrl_port, tDATA->mrl );
  1382. free( tCAM );
  1383. } else {
  1384. LOG_ERROR("Error Getting CAM Data!");
  1385. delete( m_pSource );
  1386. m_pSource = NULL;
  1387. return false;
  1388. };
  1389. };
  1390. LOG( tMRL );
  1391. if( m_pSource->_open( tMRL, false, -1.0f, pix, tDATA->width, tDATA->height, tW, tH ) ){
  1392. m_bSourceConnected = m_pSource->attachDestination( (argusModuleEmbedVideo*) tKM );
  1393. if ( !m_bSourceConnected ) {
  1394. //delete( m_pSource );
  1395. if( strncmp(tDATA->mrl_proto, "v4l2", 4) == 0 ) {
  1396. delete((videoAVLIBSource*)m_pSource);
  1397. } else {
  1398. delete((videoLIVE555Source*)m_pSource);
  1399. };
  1400. m_pSource = NULL;
  1401. } else {
  1402. m_nActiveStreamID = id;
  1403. #ifdef DEBUG
  1404. LOG("Source is Connected to Output.");
  1405. #endif
  1406. };
  1407. } else {
  1408. LOG_ERROR("Can not Open Video Source!");
  1409. //delete( m_pSource );
  1410. if( strncmp(tDATA->mrl_proto, "v4l2", 4) == 0 ) {
  1411. delete((videoAVLIBSource*)m_pSource);
  1412. } else {
  1413. delete((videoLIVE555Source*)m_pSource);
  1414. };
  1415. m_pSource = NULL;
  1416. };
  1417. } else {
  1418. LOG_ERROR("Video Source Stream Failure!");
  1419. };
  1420. free( tDATA );
  1421. };
  1422. }
  1423. #ifdef DEBUG
  1424. else LOG("No Video Module!")
  1425. #endif
  1426. ;
  1427. };
  1428. LOG("Connect Finished!");
  1429. return m_bSourceConnected;
  1430. */
  1431. return true;
  1432. };
  1433. bool deviceNodeCamera::disconnectFromStream( void ){
  1434. /*if( m_bSourceConnected ) {
  1435. if( m_pSource ){
  1436. delete( m_pSource );
  1437. m_pSource = NULL;
  1438. };
  1439. m_bSourceConnected = false;
  1440. };
  1441. return !m_bSourceConnected;
  1442. */
  1443. return true;
  1444. };
  1445. bool deviceNodeCamera::validateStream( void ){
  1446. /*
  1447. if( m_bSourceConnected ) {
  1448. if( m_pSource ) {
  1449. if( m_pSource->isAttached() ){
  1450. if( m_pSource->getStatus() < MS_STOPED ) return true;
  1451. #ifdef DEBUG
  1452. LOG("Source is Finished!");
  1453. #endif
  1454. };
  1455. #ifdef DEBUG
  1456. LOG("Source is Disconnected!");
  1457. #endif
  1458. } else LOG_ERROR("No Source Object! Set Disconnected!");
  1459. disconnectFromStream();
  1460. };
  1461. return false;
  1462. */
  1463. return true;
  1464. };
  1465. bool deviceNodeCamera::validate(){
  1466. DBC_CAM_DATA *tDATA = m_pDBC->getCamData( m_sCamData.id );
  1467. if ( tDATA == NULL ) return false;
  1468. if ( memcmp( tDATA, &m_sCamData, sizeof(DBC_CAM_DATA) ) != 0 ) {
  1469. //Settings Changed
  1470. memcpy(&m_sCamData, tDATA, sizeof(DBC_CAM_DATA) );
  1471. };
  1472. free( tDATA );
  1473. if (!validateStream()) return false;
  1474. return deviceNode::validate();
  1475. };
  1476. #undef LOG
  1477. #undef LOG_ERROR