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.

166 lines
4.8 KiB

2 years ago
​
​
​
2 years ago
​
​
2 years ago
​
​
​
​
​
​
2 years ago
​
​
2 years ago
​
​
​
2 years ago
​
​
​
2 years ago
​
​
​
​
​
​
​
​
​
​
​
2 years ago
​
5 days ago
​
​
​
​
​
​
​
​
​
​
​
​
5 days ago
​
5 days ago
​
​
​
​
​
​
​
5 days ago
​
​
​
​
​
​
​
5 days ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
​
2 years ago
2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
​
​
  1. #include "deviceNodePTZCamControl.h"
  2. #include "../mojo/mojoKernel.h"
  3. #define LOG(X) deviceNode::m_pLog->Log("PTZ_CAM", this, X)
  4. #define LOG_ERROR(X) deviceNode::m_pLog->Log("PTZ_CAM", this, _LOG_ERROR, X)
  5. deviceNodePTZCamControl::deviceNodePTZCamControl(DBC_NODE_DATA * Data) :
  6. deviceNodeCamera(Data),
  7. basicEventHandler(false) // registered at the end of the constructor
  8. {
  9. // Receive events only now that the object is completely constructed
  10. attachEvents();
  11. }
  12. deviceNodePTZCamControl::deviceNodePTZCamControl(uint32_t id) :
  13. deviceNodeCamera(id),
  14. basicEventHandler(false) // registered at the end of the constructor
  15. {
  16. m_sMediaSource.mediaSourceId = m_sNodeData.aux_id;
  17. strncpy(m_sMediaSource.mediaName, m_sNodeData.name, 128);
  18. m_sMediaSource.mediaName[127] = (char) 0;
  19. memset(&m_sCtrlData, 0, sizeof(CAMERA_CTRL_DATA));
  20. // Receive events only now that the object is completely constructed
  21. attachEvents();
  22. }
  23. deviceNodePTZCamControl::~deviceNodePTZCamControl()
  24. {
  25. detachEvents(); // stop event delivery before the members are destroyed (see basicEventHandler.h)
  26. stopService();
  27. }
  28. bool deviceNodePTZCamControl::startService()
  29. {
  30. return create();
  31. }
  32. bool deviceNodePTZCamControl::stopService()
  33. {
  34. return true;
  35. }
  36. bool deviceNodePTZCamControl::dispatchEvent(EVENT_CONTAINER * E)
  37. {
  38. if (E == NULL) return false;
  39. // if( !m_sCamData.online ) return true;
  40. // if( m_bBusy ) return true;
  41. if (m_sCamData.prefered_events_only){
  42. #ifdef DEBUG_EXTRA
  43. char tB[200];
  44. sprintf( tB, "comp Evt Dest %ld %ld", E->m_nDestinationNodeID, m_sNodeData.node_id );
  45. LOG( tB );
  46. #endif
  47. // Check if we are eligable dest of event
  48. if( E->m_nDestinationNodeID != m_sNodeData.node_id ) return true;
  49. };
  50. switch (E->m_eType){
  51. case EVT_ROI_ACTIVE:{
  52. if ( !m_bCameraAIControled ) {
  53. TARGET_DATA *tDATA = (TARGET_DATA *)E->m_pEvtData;
  54. if( tDATA ){
  55. if( E->m_eClass == EVT_CLASS_SYSTEM ){
  56. // Map ROI (kernel): no preferred camera
  57. if( 1 ){ // ToDo: camera setting - only when the point passes the camera's test (range, pan limits, FOV)
  58. if( testFOV( tDATA->system_target ) ) lookAt(E->m_db_id, tDATA->system_target);
  59. } else { // every camera turns to it (lookAt clamps pan/tilt/zoom to the camera's limits)
  60. lookAt(E->m_db_id, tDATA->system_target);
  61. };
  62. } else {
  63. lookAt(E->m_db_id, tDATA->system_target);
  64. };
  65. };
  66. }
  67. break;
  68. };
  69. case EVT_CAMERA_AI_MODE_ON:{
  70. if( E->m_nDestinationNodeID == m_sNodeData.node_id ) m_bCameraAIControled = true;
  71. break;
  72. };
  73. case EVT_CAMERA_AI_MODE_OFF:{
  74. if( E->m_nDestinationNodeID == m_sNodeData.node_id ) m_bCameraAIControled = false;
  75. break;
  76. };
  77. case EVT_CAMERA_MOVE_TO:{
  78. //Event used by AI Analytics to move camera
  79. TARGET_DATA *tDATA = (TARGET_DATA *)E->m_pEvtData;
  80. if (tDATA) {
  81. lookAt( E->m_db_id, tDATA->system_target );
  82. };
  83. break;
  84. };
  85. case EVT_TARGET_1D:
  86. case EVT_TARGET_2D_BLACK:
  87. case EVT_TARGET_2D_WHITE:
  88. case EVT_TARGET_3D_BLACK:
  89. case EVT_TARGET_3D_WHITE:{
  90. if ( !m_bCameraAIControled ) {
  91. TARGET_DATA *tDATA = (TARGET_DATA *)E->m_pEvtData;
  92. if (tDATA){
  93. #ifdef DEBUG_EXTRA
  94. LOG("CHECK CAMERA FOV");
  95. #endif
  96. if (testFOV(tDATA->system_target)){
  97. #ifdef DEBUG_EXTRA
  98. LOG("TARGET IN CAMERA FOV");
  99. #endif
  100. lookAt(E->m_db_id, tDATA->system_target);
  101. };
  102. };
  103. }
  104. break;
  105. };
  106. default: break;
  107. };
  108. return true;
  109. }
  110. bool deviceNodePTZCamControl::validate()
  111. {
  112. #ifdef DEBUG_EXTRA
  113. LOG("VALIDATE");
  114. #endif
  115. if (CAM_WS_END == getWM())
  116. {
  117. return false;
  118. }
  119. // Validate Camera Settings
  120. /*{
  121. DBC_CAM_DATA *tDATA = argusNetNode::m_pDBC->getCamData( m_sNodeData.aux_id );
  122. if( tDATA ) {
  123. if( memcmp( &m_sCamData, tDATA, sizeof(DBC_CAM_DATA)) != 0 ){
  124. free( tDATA );
  125. LOG("Cam Settings Changed!");
  126. return false;
  127. };
  128. free( tDATA );
  129. } else{
  130. LOG("Cam Deleted!");
  131. return false;
  132. };
  133. }*/
  134. // Validate Stream - > moved to Video Encoder!
  135. /*
  136. {
  137. if( m_sNodeData.aux_parameter ) {
  138. #ifdef DEBUG_EXTRA
  139. LOG("VALIDATE Stream");
  140. #endif
  141. if( !m_bSourceConnected ) {
  142. if( connectToStream( m_sNodeData.aux_parameter ) ) {
  143. argusNetNode::m_pDBC->setStreamValid( m_sNodeData.aux_parameter );
  144. } else {
  145. argusNetNode::m_pDBC->setStreamValid( m_sNodeData.aux_parameter, false );
  146. };
  147. } else {
  148. validateStream();
  149. };
  150. };
  151. }
  152. */
  153. return deviceNodeCamera::validate();
  154. }
  155. #undef LOG
  156. #undef LOG_ERROR