|
|
|
@ -46,6 +46,10 @@ deviceNodeCamera::deviceNodeCamera(uint32_t NodeID) : |
|
|
|
m_pBEH = basicEventHeap::getInstance(); |
|
|
|
m_bSkeepPositioningWait = true; |
|
|
|
m_bNoMoveDoneReport = false; |
|
|
|
memset(&m_sPtzHealth, 0, sizeof(m_sPtzHealth)); |
|
|
|
m_sPtzHealth.state = PTZ_HEALTH_INIT; |
|
|
|
m_sPtzHealth.since = time(NULL); |
|
|
|
m_tPtzLastProbe = 0; |
|
|
|
m_bNoAbsPositionning = false; |
|
|
|
m_bCameraOnHomePosition = false; |
|
|
|
m_tTimeTSeconds = 0; |
|
|
|
@ -79,6 +83,10 @@ deviceNodeCamera::deviceNodeCamera(DBC_NODE_DATA * Data) : |
|
|
|
m_pBEH = basicEventHeap::getInstance(); |
|
|
|
m_bSkeepPositioningWait = true; |
|
|
|
m_bNoMoveDoneReport = false; |
|
|
|
memset(&m_sPtzHealth, 0, sizeof(m_sPtzHealth)); |
|
|
|
m_sPtzHealth.state = PTZ_HEALTH_INIT; |
|
|
|
m_sPtzHealth.since = time(NULL); |
|
|
|
m_tPtzLastProbe = 0; |
|
|
|
m_bNoAbsPositionning = false; |
|
|
|
m_bCameraOnHomePosition = false; |
|
|
|
m_tTimeTSeconds = 0; |
|
|
|
@ -1072,17 +1080,159 @@ bool deviceNodeCamera::absoluteMove(uint32_t TargetRefID, C3D_ORIENT_ONVIF O) |
|
|
|
return false; |
|
|
|
} |
|
|
|
|
|
|
|
// PTZ control status for the health report: 1 = PTZ works (or the camera has no PTZ), 0 = PTZ failed / not ready
|
|
|
|
uint8_t deviceNodeCamera::getPtzStatus() |
|
|
|
{ |
|
|
|
if (m_sCamData.protocol == 0) |
|
|
|
{ |
|
|
|
return 1; |
|
|
|
} |
|
|
|
if (getWM() > CAM_WS_INIT) |
|
|
|
m_mPtzHealth.lock(); |
|
|
|
PTZ_HEALTH_STATE tState = m_sPtzHealth.state; |
|
|
|
m_mPtzHealth.unlock(); |
|
|
|
return (tState == PTZ_HEALTH_OK || tState == PTZ_HEALTH_NONE) ? 1 : 0; |
|
|
|
} |
|
|
|
|
|
|
|
void deviceNodeCamera::getPtzHealth(PTZ_HEALTH_INFO * info) |
|
|
|
{ |
|
|
|
if (info == NULL) |
|
|
|
{ |
|
|
|
return 1; |
|
|
|
return; |
|
|
|
} |
|
|
|
m_mPtzHealth.lock(); |
|
|
|
memcpy(info, &m_sPtzHealth, sizeof(PTZ_HEALTH_INFO)); |
|
|
|
m_mPtzHealth.unlock(); |
|
|
|
} |
|
|
|
|
|
|
|
/*
|
|
|
|
State changes of the PTZ health. FAILED schedules the next re-initialisation: the first one right away |
|
|
|
(the camera may just have rebooted), then CAM_PTZ_RETRY_MIN_S doubling up to CAM_PTZ_RETRY_MAX_S. |
|
|
|
*/ |
|
|
|
void deviceNodeCamera::ptzHealthSet(PTZ_HEALTH_STATE state, const char * reason) |
|
|
|
{ |
|
|
|
time_t tNow = time(NULL); |
|
|
|
char tB[256]; |
|
|
|
tB[0] = (char) 0; |
|
|
|
m_mPtzHealth.lock(); |
|
|
|
PTZ_HEALTH_STATE tOld = m_sPtzHealth.state; |
|
|
|
if (state == PTZ_HEALTH_FAILED) |
|
|
|
{ |
|
|
|
if (tOld != PTZ_HEALTH_FAILED) |
|
|
|
{ |
|
|
|
m_sPtzHealth.failures++; |
|
|
|
m_sPtzHealth.failed_inits = 0; |
|
|
|
m_sPtzHealth.next_retry = tNow; |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
// another failed initialisation
|
|
|
|
m_sPtzHealth.failed_inits++; |
|
|
|
uint32_t tDelay = CAM_PTZ_RETRY_MIN_S; |
|
|
|
for (uint32_t i = 1; i < m_sPtzHealth.failed_inits && tDelay < CAM_PTZ_RETRY_MAX_S; i++) |
|
|
|
{ |
|
|
|
tDelay *= 2; |
|
|
|
} |
|
|
|
if (tDelay > CAM_PTZ_RETRY_MAX_S) |
|
|
|
{ |
|
|
|
tDelay = CAM_PTZ_RETRY_MAX_S; |
|
|
|
} |
|
|
|
m_sPtzHealth.next_retry = tNow + tDelay; |
|
|
|
}; |
|
|
|
m_sPtzHealth.last_failure = tNow; |
|
|
|
snprintf(m_sPtzHealth.last_error, sizeof(m_sPtzHealth.last_error), "%s", (reason != NULL) ? reason : "PTZ failure"); |
|
|
|
snprintf(tB, sizeof(tB), "PTZ FAILED (%s), failures %u, next re-init in %ld s", m_sPtzHealth.last_error, m_sPtzHealth.failures, |
|
|
|
(long) (m_sPtzHealth.next_retry - tNow)); |
|
|
|
} |
|
|
|
return 0; |
|
|
|
else |
|
|
|
{ |
|
|
|
if (state == PTZ_HEALTH_OK && tOld == PTZ_HEALTH_FAILED) |
|
|
|
{ |
|
|
|
m_sPtzHealth.recoveries++; |
|
|
|
snprintf(tB, sizeof(tB), "PTZ recovered after %u failed attempt(s), recoveries %u", m_sPtzHealth.failed_inits + 1, m_sPtzHealth.recoveries); |
|
|
|
} |
|
|
|
m_sPtzHealth.failed_inits = 0; |
|
|
|
m_sPtzHealth.next_retry = 0; |
|
|
|
}; |
|
|
|
if (state != tOld) |
|
|
|
{ |
|
|
|
m_sPtzHealth.since = tNow; |
|
|
|
} |
|
|
|
m_sPtzHealth.state = state; |
|
|
|
m_mPtzHealth.unlock(); |
|
|
|
if (tB[0]) |
|
|
|
{ |
|
|
|
if (state == PTZ_HEALTH_FAILED) |
|
|
|
{ |
|
|
|
LOG_ERROR(tB); |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
LOG(tB); |
|
|
|
} |
|
|
|
}; |
|
|
|
} |
|
|
|
|
|
|
|
// CAM_WS_INIT may (re)create the protocol now? Only throttled while FAILED.
|
|
|
|
bool deviceNodeCamera::ptzReinitDue(void) |
|
|
|
{ |
|
|
|
m_mPtzHealth.lock(); |
|
|
|
bool tDue = (m_sPtzHealth.state != PTZ_HEALTH_FAILED) || (time(NULL) >= m_sPtzHealth.next_retry); |
|
|
|
m_mPtzHealth.unlock(); |
|
|
|
return tDue; |
|
|
|
} |
|
|
|
|
|
|
|
/*
|
|
|
|
A target-driven PTZ command failed. Before, the camera thread ended (CAM_WS_END -> the node was rebuilt). |
|
|
|
Now: ONVIF tells apart a rejected command (SOAP Fault, camera reachable -> validate() still true: drop this |
|
|
|
ROI and carry on) from a lost camera. Every other failure re-initialises the PTZ protocol. |
|
|
|
*/ |
|
|
|
void deviceNodeCamera::ptzCommandFailed(const char * command) |
|
|
|
{ |
|
|
|
char tB[160]; |
|
|
|
utilizeROI(m_pCurrentROI); |
|
|
|
if (m_sCamData.protocol == CAM_CTRL_PROTO_ONVIF && m_pProtocol != NULL && m_pProtocol->validate()) |
|
|
|
{ |
|
|
|
snprintf(tB, sizeof(tB), "%s rejected by the camera (see the PONVIF log), PTZ connection OK", command); |
|
|
|
LOG_ERROR(tB); |
|
|
|
setWM(CAM_WS_READY); |
|
|
|
return; |
|
|
|
} |
|
|
|
snprintf(tB, sizeof(tB), "%s failed: PTZ protocol lost", command); |
|
|
|
ptzLost(tB); |
|
|
|
} |
|
|
|
|
|
|
|
// The PTZ protocol was lost: mark FAILED and re-initialise it (CAM_WS_INIT deletes and recreates it).
|
|
|
|
void deviceNodeCamera::ptzLost(const char * reason) |
|
|
|
{ |
|
|
|
ptzHealthSet(PTZ_HEALTH_FAILED, reason); |
|
|
|
setWM(CAM_WS_INIT); |
|
|
|
} |
|
|
|
|
|
|
|
/*
|
|
|
|
Called every loop of the camera thread. Only while idle (CAM_WS_READY), so moves are not disturbed: |
|
|
|
- the protocol's own status (validate) is checked every loop; |
|
|
|
- every CAM_PTZ_PROBE_INTERVAL_S the camera is actively asked (protocolPTZ::probe; ONVIF: GetStatus). |
|
|
|
*/ |
|
|
|
void deviceNodeCamera::ptzCheck(uint8_t tState) |
|
|
|
{ |
|
|
|
if (tState != CAM_WS_READY || m_pProtocol == NULL || m_sCamData.protocol == 0) |
|
|
|
{ |
|
|
|
return; |
|
|
|
} |
|
|
|
if (! m_pProtocol->validate()) |
|
|
|
{ |
|
|
|
ptzLost("PTZ protocol reports a failure"); |
|
|
|
return; |
|
|
|
} |
|
|
|
time_t tNow = time(NULL); |
|
|
|
if (tNow - m_tPtzLastProbe >= CAM_PTZ_PROBE_INTERVAL_S) |
|
|
|
{ |
|
|
|
m_tPtzLastProbe = tNow; |
|
|
|
if (! m_pProtocol->probe()) |
|
|
|
{ |
|
|
|
ptzLost("PTZ liveness check failed (camera not reachable)"); |
|
|
|
} |
|
|
|
}; |
|
|
|
} |
|
|
|
|
|
|
|
uint8_t deviceNodeCamera::getStreamStatus() |
|
|
|
@ -1106,6 +1256,8 @@ void deviceNodeCamera::m_fThreadProc(void) |
|
|
|
if ((bNewSecondLoop = (cTimeSeconds != oTimeSeconds))) oTimeSeconds = cTimeSeconds; |
|
|
|
|
|
|
|
uint8_t tState = getWM(); |
|
|
|
ptzCheck(tState); |
|
|
|
tState = getWM(); |
|
|
|
|
|
|
|
//char tB[128];
|
|
|
|
#ifndef NO_CAMERA_FUSION_ENGINE
|
|
|
|
@ -1115,6 +1267,10 @@ void deviceNodeCamera::m_fThreadProc(void) |
|
|
|
{ |
|
|
|
case CAM_WS_INIT: |
|
|
|
{ |
|
|
|
if (! ptzReinitDue()) |
|
|
|
{ |
|
|
|
break; // PTZ failed: wait for the next re-initialisation attempt
|
|
|
|
} |
|
|
|
if (m_pProtocol != NULL) |
|
|
|
{ |
|
|
|
switch (m_sCamData.protocol) |
|
|
|
@ -1371,6 +1527,19 @@ void deviceNodeCamera::m_fThreadProc(void) |
|
|
|
setWM(CAM_WS_POWER_INIT); |
|
|
|
}; |
|
|
|
m_pDBC->updateCamOnlineStatus(m_sCamData.id, m_sCamData.online); |
|
|
|
if (m_sCamData.protocol == 0) |
|
|
|
{ |
|
|
|
ptzHealthSet(PTZ_HEALTH_NONE); |
|
|
|
} |
|
|
|
else if (m_pProtocol != NULL) |
|
|
|
{ |
|
|
|
m_tPtzLastProbe = time(NULL); |
|
|
|
ptzHealthSet(PTZ_HEALTH_OK); |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
ptzHealthSet(PTZ_HEALTH_FAILED, "PTZ protocol initialisation failed"); |
|
|
|
}; |
|
|
|
break; |
|
|
|
}; |
|
|
|
case CAM_WS_POWER_INIT: |
|
|
|
@ -1673,8 +1842,7 @@ void deviceNodeCamera::m_fThreadProc(void) |
|
|
|
m_fCP_Zoom = m_pCurrentROI->cam_orientation.zoom; |
|
|
|
if (! m_pProtocol->goPreset(token)) |
|
|
|
{ |
|
|
|
LOG_ERROR("Cannot Issue goPreset Command!->Restart Camera?"); |
|
|
|
setWM(CAM_WS_END); |
|
|
|
ptzCommandFailed("goPreset"); |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
@ -1739,8 +1907,7 @@ void deviceNodeCamera::m_fThreadProc(void) |
|
|
|
// Do Movement
|
|
|
|
if (! m_pProtocol->goAbsolute(m_pCurrentROI->cam_orientation.pan, m_pCurrentROI->cam_orientation.tilt, m_pCurrentROI->cam_orientation.zoom * m_fZoomCorrection)) |
|
|
|
{ |
|
|
|
LOG_ERROR("Cannot Issue goAbsolute Command!->Restart Camera?"); |
|
|
|
setWM(CAM_WS_END); |
|
|
|
ptzCommandFailed("goAbsolute"); |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
|