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.

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