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.

156 lines
4.4 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. // a map ROI (kernel, EVT_CLASS_SYSTEM) has no preferred camera: only the cameras that can see it
  55. if( tDATA && ( E->m_eClass != EVT_CLASS_SYSTEM || testFOV( tDATA->system_target ) ) ) lookAt(E->m_db_id, tDATA->system_target);
  56. }
  57. break;
  58. };
  59. case EVT_CAMERA_AI_MODE_ON:{
  60. if( E->m_nDestinationNodeID == m_sNodeData.node_id ) m_bCameraAIControled = true;
  61. break;
  62. };
  63. case EVT_CAMERA_AI_MODE_OFF:{
  64. if( E->m_nDestinationNodeID == m_sNodeData.node_id ) m_bCameraAIControled = false;
  65. break;
  66. };
  67. case EVT_CAMERA_MOVE_TO:{
  68. //Event used by AI Analytics to move camera
  69. TARGET_DATA *tDATA = (TARGET_DATA *)E->m_pEvtData;
  70. if (tDATA) {
  71. lookAt( E->m_db_id, tDATA->system_target );
  72. };
  73. break;
  74. };
  75. case EVT_TARGET_1D:
  76. case EVT_TARGET_2D_BLACK:
  77. case EVT_TARGET_2D_WHITE:
  78. case EVT_TARGET_3D_BLACK:
  79. case EVT_TARGET_3D_WHITE:{
  80. if ( !m_bCameraAIControled ) {
  81. TARGET_DATA *tDATA = (TARGET_DATA *)E->m_pEvtData;
  82. if (tDATA){
  83. #ifdef DEBUG_EXTRA
  84. LOG("CHECK CAMERA FOV");
  85. #endif
  86. if (testFOV(tDATA->system_target)){
  87. #ifdef DEBUG_EXTRA
  88. LOG("TARGET IN CAMERA FOV");
  89. #endif
  90. lookAt(E->m_db_id, tDATA->system_target);
  91. };
  92. };
  93. }
  94. break;
  95. };
  96. default: break;
  97. };
  98. return true;
  99. }
  100. bool deviceNodePTZCamControl::validate()
  101. {
  102. #ifdef DEBUG_EXTRA
  103. LOG("VALIDATE");
  104. #endif
  105. if (CAM_WS_END == getWM())
  106. {
  107. return false;
  108. }
  109. // Validate Camera Settings
  110. /*{
  111. DBC_CAM_DATA *tDATA = argusNetNode::m_pDBC->getCamData( m_sNodeData.aux_id );
  112. if( tDATA ) {
  113. if( memcmp( &m_sCamData, tDATA, sizeof(DBC_CAM_DATA)) != 0 ){
  114. free( tDATA );
  115. LOG("Cam Settings Changed!");
  116. return false;
  117. };
  118. free( tDATA );
  119. } else{
  120. LOG("Cam Deleted!");
  121. return false;
  122. };
  123. }*/
  124. // Validate Stream - > moved to Video Encoder!
  125. /*
  126. {
  127. if( m_sNodeData.aux_parameter ) {
  128. #ifdef DEBUG_EXTRA
  129. LOG("VALIDATE Stream");
  130. #endif
  131. if( !m_bSourceConnected ) {
  132. if( connectToStream( m_sNodeData.aux_parameter ) ) {
  133. argusNetNode::m_pDBC->setStreamValid( m_sNodeData.aux_parameter );
  134. } else {
  135. argusNetNode::m_pDBC->setStreamValid( m_sNodeData.aux_parameter, false );
  136. };
  137. } else {
  138. validateStream();
  139. };
  140. };
  141. }
  142. */
  143. return deviceNodeCamera::validate();
  144. }
  145. #undef LOG
  146. #undef LOG_ERROR