diff --git a/lib/components/base/basicTypes.h b/lib/components/base/basicTypes.h index e1c3de32..b647bce4 100644 --- a/lib/components/base/basicTypes.h +++ b/lib/components/base/basicTypes.h @@ -698,6 +698,9 @@ typedef struct S_ptzStatus bool hasMoveStatus; bool PanTiltIdle; bool ZoomIdle; + bool hasPosition; // PanTilt position reported (pan/tilt valid) + bool hasZoomPosition; // Zoom position reported (zoom valid) + bool isMoving; // MoveStatus reported MOVING for at least one axis } ptzStatus; typedef struct S_DBC_ATC_MODULE_DATA{ diff --git a/lib/data/ponvif/ponvif.cpp b/lib/data/ponvif/ponvif.cpp index 5e4d4780..094e92bf 100644 --- a/lib/data/ponvif/ponvif.cpp +++ b/lib/data/ponvif/ponvif.cpp @@ -82,6 +82,8 @@ pOnvif::pOnvif() m_pHttpAccessManager = NULL; memset( &m_sCapabilities, 0, sizeof( nodeCapability ) ); m_bAuthMode = 0; + parser_done = false; + m_pPendingRequest = NULL; LOG("Constructor Done!"); } @@ -1854,6 +1856,37 @@ CSTR pOnvif::media_GetSnapshotUri(CSTR profileToken) return NULL; } +/* + Parses a tt:MoveStatus axis value. Returns 1 = MOVING, 0 = IDLE, -1 = UNKNOWN / not reported. +*/ +static int parseMoveStatusValue(XMLNode & node) +{ + if (node.isEmpty()) + { + return -1; + } + LPCTSTR tText = node.getText(0); + if (tText == NULL) + { + return -1; + } + if (strstr(tText, "MOVING") != NULL) + { + return 1; + } + if (strstr(tText, "IDLE") != NULL) + { + return 0; + } + return -1; +} + +/* + ONVIF PTZ GetStatus. + Position and MoveStatus are both optional in tt:PTZStatus, and inside them every axis is optional, + so every element is checked before it is read; tStatus->has* tells the caller what the camera reported. + An axis whose MoveStatus is not reported is counted as idle. +*/ bool pOnvif::ptz_GetStatus(CSTR profileToken, ptzStatus * tStatus) { if (m_pPTZURI == NULL) @@ -1869,80 +1902,132 @@ bool pOnvif::ptz_GetStatus(CSTR profileToken, ptzStatus * tStatus) tTOKEN = _makeToken(); memset(tStatus, 0, sizeof(ptzStatus)); sprintf(tBuffer, PONVIF_PACK_GET_PTZ_STATUS, tTOKEN.USERNAME, tTOKEN.PASSDIGEST, tTOKEN.NONCE, tTOKEN.TIMESTAMP, profileToken); - if (_send_request(m_pPTZURI, tBuffer, true)) + if (! _send_request(m_pPTZURI, tBuffer, true)) { - XMLResults tParseResults; - XMLNode response = XMLNode::parseString(m_pLastResponse, "root", &tParseResults); - if (tParseResults.error) - { - char tBuf[CTEXT]; - sprintf(tBuf, "XML Parse Error %d at %d:%d", tParseResults.error, tParseResults.nLine, tParseResults.nColumn); - LOG_ERROR(tBuf); - } - else + return false; + } + XMLResults tParseResults; + XMLNode response = XMLNode::parseString(m_pLastResponse, "root", &tParseResults); + if (tParseResults.error) + { + char tBuf[CTEXT]; + sprintf(tBuf, "XML Parse Error %d at %d:%d", tParseResults.error, tParseResults.nLine, tParseResults.nColumn); + LOG_ERROR(tBuf); + return false; + } + XMLNode aNode = response.getChildNode("Body", 0); + if (aNode.isEmpty()) + { + return false; + } + XMLNode bNode = aNode.getChildNode("GetStatusResponse", 0); + if (bNode.isEmpty()) + { + // SOAP Fault or unexpected answer + return false; + } + XMLNode cNode = bNode.getChildNode("PTZStatus", 0); + if (cNode.isEmpty()) + { + return false; + } + XMLNode dNode = cNode.getChildNode("Position", 0); + if (! dNode.isEmpty()) + { + XMLNode eNode = dNode.getChildNode("PanTilt", 0); + if (! eNode.isEmpty()) { - XMLNode aNode = response.getChildNode("Body", 0); - if (aNode.isEmpty()) + LPCTSTR tX = eNode.getAttribute("x"); + LPCTSTR tY = eNode.getAttribute("y"); + if (tX != NULL && tY != NULL) { - return NULL; - } - XMLNode bNode = aNode.getChildNode("GetStatusResponse", 0); - if (! bNode.isEmpty()) + tStatus->pan = (float) atof(tX); + tStatus->tilt = (float) atof(tY); + tStatus->hasPosition = true; + }; + }; + XMLNode fNode = dNode.getChildNode("Zoom", 0); + if (! fNode.isEmpty()) + { + LPCTSTR tX = fNode.getAttribute("x"); + if (tX != NULL) { - XMLNode cNode = bNode.getChildNode("PTZStatus", 0); - if (! cNode.isEmpty()) - { - XMLNode dNode = cNode.getChildNode("Position", 0); - if (! dNode.isEmpty()) - { - XMLNode eNode = dNode.getChildNode("PanTilt", 0); - if (! eNode.isEmpty()) - { - // XMLAttribute ZZ = eNode.getAttribute(1); - // LOG( ZZ.lpszName ); - tStatus->pan = atof(eNode.getAttribute("x")); // ZZ.lpszValue ); - // ZZ = eNode.getAttribute(2); - // LOG( ZZ.lpszName ); - tStatus->tilt = atof(eNode.getAttribute("y")); // ZZ.lpszValue ); - }; - XMLNode fNode = dNode.getChildNode("Zoom", 0); - if (! fNode.isEmpty()) - { - // XMLAttribute ZZ = eNode.getAttribute(1); - // LOG( ZZ.lpszName ); - tStatus->zoom = atof(fNode.getAttribute("x")); // ZZ.lpszValue ); - }; - }; - if (tStatus->pan != .0f || tStatus->tilt != .0f || tStatus->zoom != .0f) - { - XMLNode gNode = cNode.getChildNode("MoveStatus", 0); - if (! gNode.isEmpty()) - { - tStatus->hasMoveStatus = true; - XMLNode hNode = gNode.getChildNode("PanTilt", 0); - if (! hNode.isEmpty()) - { - if (strstr(hNode.getText(0), "IDLE") != NULL) - { - tStatus->PanTiltIdle = true; - } - }; - XMLNode iNode = gNode.getChildNode("Zoom", 0); - if (! iNode.isEmpty()) - { - if (strstr(iNode.getText(0), "IDLE") != NULL) - { - tStatus->ZoomIdle = true; - } - }; - }; - } - return true; - }; + tStatus->zoom = (float) atof(tX); + tStatus->hasZoomPosition = true; }; }; }; - return false; + XMLNode gNode = cNode.getChildNode("MoveStatus", 0); + if (! gNode.isEmpty()) + { + XMLNode hNode = gNode.getChildNode("PanTilt", 0); + XMLNode iNode = gNode.getChildNode("Zoom", 0); + int tPT = parseMoveStatusValue(hNode); + int tZM = parseMoveStatusValue(iNode); + // Only a real IDLE / MOVING value counts as "reported" + tStatus->hasMoveStatus = (tPT >= 0 || tZM >= 0); + tStatus->PanTiltIdle = (tPT != 1); + tStatus->ZoomIdle = (tZM != 1); + tStatus->isMoving = (tPT == 1 || tZM == 1); + }; + return true; +} + +bool pOnvif::ptz_GetServiceCapabilities(int8_t * moveStatus, int8_t * statusPosition) +{ + if (moveStatus) + { + *moveStatus = -1; + } + if (statusPosition) + { + *statusPosition = -1; + } + if (m_pPTZURI == NULL) + { + return false; + } + char tBuffer[DEFAULT_BUFFER_SIZE]; + accessToken tTOKEN; + tTOKEN = _makeToken(); + sprintf(tBuffer, PONVIF_PACK_PTZ_GET_SERVICE_CAPS, tTOKEN.USERNAME, tTOKEN.PASSDIGEST, tTOKEN.NONCE, tTOKEN.TIMESTAMP); + if (! _send_request(m_pPTZURI, tBuffer, true)) + { + return false; + } + XMLResults tParseResults; + XMLNode response = XMLNode::parseString(m_pLastResponse, "root", &tParseResults); + if (tParseResults.error) + { + return false; + } + XMLNode aNode = response.getChildNode("Body", 0); + if (aNode.isEmpty()) + { + return false; + } + XMLNode bNode = aNode.getChildNode("GetServiceCapabilitiesResponse", 0); + if (bNode.isEmpty()) + { + // Older devices (PTZ service < 2.x) answer with a SOAP Fault + return false; + } + XMLNode cNode = bNode.getChildNode("Capabilities", 0); + if (cNode.isEmpty()) + { + return false; + } + LPCTSTR tMS = cNode.getAttribute("MoveStatus"); + LPCTSTR tSP = cNode.getAttribute("StatusPosition"); + if (moveStatus && tMS != NULL) + { + *moveStatus = checkBool(tMS) ? 1 : 0; + } + if (statusPosition && tSP != NULL) + { + *statusPosition = checkBool(tSP) ? 1 : 0; + } + return true; } bool pOnvif::ptz_GetPresets(CSTR profileToken) @@ -2312,6 +2397,14 @@ void * pOnvif::parser(void * obj, void * ptr) if (ME) { + ME->m_mParserLock.lock(); + if (RQ != ME->m_pPendingRequest) + { + // Late reply to a request that already timed out: ignore it, so it cannot be + // taken as the answer to the request that is waiting now. + ME->m_mParserLock.unlock(); + return NULL; + }; if (ME->m_pLastResponse) { free(ME->m_pLastResponse); @@ -2331,6 +2424,7 @@ void * pOnvif::parser(void * obj, void * ptr) #endif }; ME->parser_done = true; + ME->m_mParserLock.unlock(); }; return NULL; } @@ -2361,16 +2455,29 @@ bool pOnvif::_send_request(CSTR url, CSTR post_string, bool mustReturnData) if (mustReturnData) { tRC->setHandler((void *) this, pOnvif::parser, (void *) tRC); + // Arm before the request is queued: the reply can arrive before accomplish() returns. + m_mParserLock.lock(); + parser_done = false; + m_pPendingRequest = (void *) tRC; + m_mParserLock.unlock(); if (m_pHttpAccessManager->accomplish(tRC)) { - parser_done = false; uint8_t cnt = 200; // TO = 2 second while (! RetVal && cnt--) { + m_mParserLock.lock(); RetVal = parser_done; - SLEEP(10); + m_mParserLock.unlock(); + if (! RetVal) + { + SLEEP(10); + } }; }; + // From here on any reply to tRC is stale (tRC may already be deleted by the manager) + m_mParserLock.lock(); + m_pPendingRequest = NULL; + m_mParserLock.unlock(); } else { diff --git a/lib/data/ponvif/ponvif.h b/lib/data/ponvif/ponvif.h index 5c7091c2..c83fc99c 100644 --- a/lib/data/ponvif/ponvif.h +++ b/lib/data/ponvif/ponvif.h @@ -54,6 +54,8 @@ (CSTR)"%s%s%s%s%s" #define PONVIF_PACK_GET_PTZ_STATUS \ (CSTR)"%s%s%s%s%s" +#define PONVIF_PACK_PTZ_GET_SERVICE_CAPS \ + (CSTR)"%s%s%s%s" #define PONVIF_PACK_GOTO_PRESET \ (CSTR)"%s%s%s%s%s%s" #define PONVIF_PACK_REMOVE_PRESET \ @@ -510,7 +512,9 @@ class pOnvif CSTR m_pDiscoveryMCastIP; int m_nDiscoveryMCastPort; bool m_bDiscoveryHideDuplicates; - bool parser_done; + volatile bool parser_done; + void * volatile m_pPendingRequest; // reply that _send_request is waiting for + basicMutex m_mParserLock; // parser() vs. _send_request bookkeeping uint8_t m_bAuthMode; #ifndef CURL_MANAGER static int _writer(char * data, size_t size, size_t nmemb, pOnvif * Ptr); @@ -571,6 +575,9 @@ class pOnvif bool ptz_GetPresets(CSTR profileToken); bool ptz_GetNode(CSTR ptzNodeToken); bool ptz_GetStatus(CSTR profileToken, ptzStatus * tStatus); + // PTZ service capabilities (ONVIF PTZ GetServiceCapabilities). + // Each output is 1 = supported, 0 = not supported, -1 = not reported by the device. + bool ptz_GetServiceCapabilities(int8_t * moveStatus, int8_t * statusPosition); bool ptz_GotoPreset(CSTR profileToken, CSTR presetToken, float speed_pantilt_x, float speed_pantilt_y, float speed_zoom_x); bool ptz_RemovePreset(CSTR profileToken, CSTR presetToken); bool ptz_SetPreset(CSTR profileToken, CSTR presetName); diff --git a/lib/data/protocol/protocolPTZ_ONVIF.cpp b/lib/data/protocol/protocolPTZ_ONVIF.cpp index 990dbde5..fc1a2329 100644 --- a/lib/data/protocol/protocolPTZ_ONVIF.cpp +++ b/lib/data/protocol/protocolPTZ_ONVIF.cpp @@ -14,8 +14,14 @@ protocolPTZ_ONVIF::protocolPTZ_ONVIF(config_setting_t * Settings) : m_pSettings = Settings; m_bAuthMode = 0; #ifdef USE_PONVIF - m_pOnVif = NULL; - m_pProfile = NULL; + m_pOnVif = NULL; + m_pProfile = NULL; + m_bReportsMoveStatus = false; + m_bReportsPosition = false; + m_bTargetValid = false; + m_fTargetPan = 0.0f; + m_fTargetTilt = 0.0f; + m_fTargetZoom = 0.0f; #else m_pDevice = NULL; m_pPTZ = NULL; @@ -33,8 +39,14 @@ protocolPTZ_ONVIF::protocolPTZ_ONVIF(CSTR ip, uint16_t port, CSTR username, CSTR m_bLastCommandIssued = CMD_PTZ_NOOP; m_pSettings = NULL; #ifdef USE_PONVIF - m_pOnVif = NULL; - m_pProfile = NULL; + m_pOnVif = NULL; + m_pProfile = NULL; + m_bReportsMoveStatus = false; + m_bReportsPosition = false; + m_bTargetValid = false; + m_fTargetPan = 0.0f; + m_fTargetTilt = 0.0f; + m_fTargetZoom = 0.0f; #else m_pDevice = NULL; m_pPTZ = NULL; @@ -66,8 +78,14 @@ protocolPTZ_ONVIF::protocolPTZ_ONVIF(CSTR ctl_url, CSTR username, CSTR password, m_bLastCommandIssued = CMD_PTZ_NOOP; m_pSettings = NULL; #ifdef USE_PONVIF - m_pOnVif = NULL; - m_pProfile = NULL; + m_pOnVif = NULL; + m_pProfile = NULL; + m_bReportsMoveStatus = false; + m_bReportsPosition = false; + m_bTargetValid = false; + m_fTargetPan = 0.0f; + m_fTargetTilt = 0.0f; + m_fTargetZoom = 0.0f; #else m_pDevice = NULL; m_pPTZ = NULL; @@ -186,6 +204,7 @@ bool protocolPTZ_ONVIF::create(void) if (m_pOnVif->create()) { m_pProfile = m_pOnVif->getProfiles()->at(0); + detectStatusSupport(); LOG("DONE"); m_bStatus = 1; return true; @@ -376,42 +395,175 @@ bool protocolPTZ_ONVIF::move(uint32_t MoveMatrix) } #include +#include -bool protocolPTZ_ONVIF::waitMoveIsDone(void) +#ifdef USE_PONVIF +static long ptzOnvifNowMs(void) +{ + struct timespec tTS; + clock_gettime(CLOCK_MONOTONIC, &tTS); + return (long) tTS.tv_sec * 1000L + tTS.tv_nsec / 1000000L; +} + +// Pan in the generic space wraps around (-1 == +1 on 360 degree cameras) +static float ptzOnvifPanDistance(float a, float b) { + float d = fabsf(a - b); + if (d > 1.0f) + { + d = 2.0f - d; + } + return d; +} + +/* + Finds out once (after create) how the end of a move can be detected for this camera. + The PTZ service capabilities (MoveStatus / StatusPosition attributes) are asked first; many cameras + don't implement GetServiceCapabilities or leave the attributes out, so a real GetStatus decides. + An explicit "false" in the capabilities wins over a GetStatus reply (some cameras send fixed values). +*/ +void protocolPTZ_ONVIF::detectStatusSupport(void) +{ + m_bReportsMoveStatus = false; + m_bReportsPosition = false; + if (m_pOnVif == NULL || m_pProfile == NULL) + { + return; + } + int8_t capMoveStatus = -1; + int8_t capStatusPosition = -1; + m_pOnVif->ptz_GetServiceCapabilities(&capMoveStatus, &capStatusPosition); ptzStatus tVal; - uint8_t TO = 12; // 3.6 second max - while (m_pOnVif->ptz_GetStatus(m_pProfile->profiletoken, &tVal) && TO) + bool tProbe = m_pOnVif->ptz_GetStatus(m_pProfile->profiletoken, &tVal); + m_bReportsMoveStatus = tProbe && tVal.hasMoveStatus && (capMoveStatus != 0); + m_bReportsPosition = tProbe && tVal.hasPosition && (capStatusPosition != 0); + char tB[256]; + snprintf(tB, sizeof(tB), "PTZ status support: MoveStatus=%s Position=%s (GetStatus %s, capabilities MoveStatus=%d StatusPosition=%d) -> %s", + m_bReportsMoveStatus ? "yes" : "no", m_bReportsPosition ? "yes" : "no", tProbe ? "ok" : "failed", capMoveStatus, capStatusPosition, + m_bReportsMoveStatus ? "wait for IDLE" : (m_bReportsPosition ? "wait for position" : "fixed wait")); + LOG(tB); +} + +bool protocolPTZ_ONVIF::fixedMoveWait(long alreadyWaitedMs) +{ + long tRest = PTZ_ONVIF_FIXED_MOVE_WAIT_MS - alreadyWaitedMs; + if (tRest > 0) { - if (tVal.hasMoveStatus) + SLEEP(tRest); + } + return true; +} + +/* + Blocks until the last AbsoluteMove is finished (see the strategy at the top of protocolPTZ_ONVIF.h). + Returns true when the move is over (or after the fixed wait / timeout), false only if there is no + PTZ connection at all. +*/ +bool protocolPTZ_ONVIF::waitMoveIsDone(void) +{ + if (m_pOnVif == NULL || m_pProfile == NULL) + { + return false; + } + if (! m_bReportsMoveStatus && ! m_bReportsPosition) + { + return fixedMoveWait(0); + } + long tStart = ptzOnvifNowMs(); + int tFailures = 0; + bool tSeenMoving = false; + bool tHavePrev = false; + int tStableCount = 0; + float tPrevPan = 0.0f; + float tPrevTilt = 0.0f; + float tPrevZoom = 0.0f; + char tB[256]; + for (;;) + { + long tElapsed = ptzOnvifNowMs() - tStart; + if (tElapsed >= PTZ_ONVIF_MOVE_TIMEOUT_MS) { - if (tVal.PanTiltIdle && tVal.ZoomIdle) + LOG_ERROR("Timeout waiting for the end of the PTZ move!"); + return true; + }; + ptzStatus tVal; + if (! m_pOnVif->ptz_GetStatus(m_pProfile->profiletoken, &tVal)) + { + if (++tFailures >= PTZ_ONVIF_MAX_STATUS_FAILURES) { - break; + LOG_ERROR("GetStatus keeps failing, falling back to the fixed wait"); + return fixedMoveWait(ptzOnvifNowMs() - tStart); + }; + SLEEP(PTZ_ONVIF_STATUS_POLL_MS); + continue; + }; + tFailures = 0; + + bool tNear = false; + bool tStable = false; + if (m_bReportsPosition && tVal.hasPosition) + { + tNear = m_bTargetValid && (ptzOnvifPanDistance(tVal.pan, m_fTargetPan) <= PTZ_ONVIF_POS_TOLERANCE) && + (fabsf(tVal.tilt - m_fTargetTilt) <= PTZ_ONVIF_POS_TOLERANCE) && + (! tVal.hasZoomPosition || fabsf(tVal.zoom - m_fTargetZoom) <= PTZ_ONVIF_POS_TOLERANCE); + if (tHavePrev && ptzOnvifPanDistance(tVal.pan, tPrevPan) < PTZ_ONVIF_POS_STABLE_EPS && fabsf(tVal.tilt - tPrevTilt) < PTZ_ONVIF_POS_STABLE_EPS && + fabsf(tVal.zoom - tPrevZoom) < PTZ_ONVIF_POS_STABLE_EPS) + { + tStableCount++; } + else + { + tStableCount = 0; + }; + tPrevPan = tVal.pan; + tPrevTilt = tVal.tilt; + tPrevZoom = tVal.zoom; + tHavePrev = true; + tStable = (tStableCount >= PTZ_ONVIF_POS_STABLE_POLLS); + }; + bool tAfterGrace = (tElapsed >= PTZ_ONVIF_MOVE_START_GRACE_MS); + bool tDone = false; + if (m_bReportsMoveStatus && tVal.hasMoveStatus) + { + // Right after the command a camera may still say IDLE: accept IDLE once it was seen + // moving, once the target is reached, or after the start grace time. + if (tVal.isMoving) + { + tSeenMoving = true; + } + else if (tSeenMoving || tNear || tAfterGrace) + { + tDone = true; + }; + } + else if (m_bReportsPosition && tVal.hasPosition) + { + tDone = tNear || (tStable && tAfterGrace); } else { - // if( ( fabs(tVal.pan - dPan) < 0.0005 ) && ( fabs( tVal.tilt - dTilt) < 0.0005 ) ) break;//&& ( fabs( tVal.zoom - dZoom ) < 0.05 ) ) break; + // This reply carries neither MoveStatus nor Position + return fixedMoveWait(tElapsed); }; - SLEEP(333); - TO--; - }; - if (TO) - { -#ifdef DEBUG_EXTRA - LOG("Finished Move!"); -#endif - return true; + if (tDone) + { #ifdef DEBUG_EXTRA - } - else - { - LOG_ERROR("Error Fetching PTZ Status!"); + snprintf(tB, sizeof(tB), "Finished Move in %ld ms (pos %.3f %.3f %.3f)", ptzOnvifNowMs() - tStart, tVal.pan, tVal.tilt, tVal.zoom); + LOG(tB); +#else + (void) tB; #endif + return true; + }; + SLEEP(PTZ_ONVIF_STATUS_POLL_MS); }; +} +#else +bool protocolPTZ_ONVIF::waitMoveIsDone(void) +{ return false; } +#endif bool protocolPTZ_ONVIF::goAbsolute(float dPan, float dTilt, float dZoom) { @@ -430,6 +582,11 @@ bool protocolPTZ_ONVIF::goAbsolute(float dPan, float dTilt, float dZoom) dZoom = 0.0f; } + // Remember the target for waitMoveIsDone() + m_fTargetPan = dPan; + m_fTargetTilt = dTilt; + m_fTargetZoom = dZoom; + m_bTargetValid = true; if (m_pOnVif->ptz_AbsoluteMove(m_pProfile->profiletoken, dPan, dTilt, dZoom)) { }; diff --git a/lib/data/protocol/protocolPTZ_ONVIF.h b/lib/data/protocol/protocolPTZ_ONVIF.h index 6018a3f7..5ce1bf00 100644 --- a/lib/data/protocol/protocolPTZ_ONVIF.h +++ b/lib/data/protocol/protocolPTZ_ONVIF.h @@ -10,6 +10,22 @@ #include "../onvif/include/onvifclient.hpp" #endif +/* + Waiting for the end of an AbsoluteMove (waitMoveIsDone): + - camera reports MoveStatus -> poll GetStatus until pan/tilt and zoom are IDLE + - camera reports Position -> poll GetStatus until the target is reached or the position stops changing + - camera reports neither -> fixed wait (PTZ_ONVIF_FIXED_MOVE_WAIT_MS) + What the camera reports is detected once in create() (PTZ GetServiceCapabilities + a real GetStatus). +*/ +#define PTZ_ONVIF_STATUS_POLL_MS 200 // GetStatus polling period +#define PTZ_ONVIF_MOVE_TIMEOUT_MS 10000 // give up waiting for the end of a move after this +#define PTZ_ONVIF_MOVE_START_GRACE_MS 1000 // a camera may still report IDLE / old position right after the command +#define PTZ_ONVIF_FIXED_MOVE_WAIT_MS 3000 // wait for cameras that report neither MoveStatus nor Position +#define PTZ_ONVIF_POS_TOLERANCE 0.01f // target reached (generic space units) +#define PTZ_ONVIF_POS_STABLE_EPS 0.001f // position "not changing" between two polls +#define PTZ_ONVIF_POS_STABLE_POLLS 2 // consecutive unchanged polls = move finished +#define PTZ_ONVIF_MAX_STATUS_FAILURES 3 // consecutive GetStatus failures before falling back to the fixed wait + class protocolPTZ_ONVIF : public protocolPTZ { private: @@ -30,6 +46,17 @@ class protocolPTZ_ONVIF : public protocolPTZ #endif config_setting_t * m_pSettings; basicMutex m_mInquiryMutex; +#ifdef USE_PONVIF + bool m_bReportsMoveStatus; // camera reports PTZStatus/MoveStatus (IDLE/MOVING) + bool m_bReportsPosition; // camera reports PTZStatus/Position + bool m_bTargetValid; // m_fTarget* hold the last AbsoluteMove target + float m_fTargetPan; + float m_fTargetTilt; + float m_fTargetZoom; + + void detectStatusSupport(void); + bool fixedMoveWait(long alreadyWaitedMs); +#endif public: