Browse Source

Merge pull request #23: ONVIF AbsoluteMove: send the speed in a named speed space, at its maximum

master
ClaudeAI 46 minutes ago
parent
commit
8e345e6161
  1. 109
      lib/data/ponvif/ponvif.cpp
  2. 35
      lib/data/ponvif/ponvif.h
  3. 9
      lib/data/protocol/protocolPTZ_ONVIF.cpp

109
lib/data/ponvif/ponvif.cpp

@ -132,6 +132,7 @@ pOnvif::pOnvif()
m_bDiscoveryHideDuplicates = true; m_bDiscoveryHideDuplicates = true;
m_pHttpAccessManager = NULL; m_pHttpAccessManager = NULL;
memset( &m_sCapabilities, 0, sizeof( nodeCapability ) ); memset( &m_sCapabilities, 0, sizeof( nodeCapability ) );
setGenericSpeedSpaces();
m_bAuthMode = 0; m_bAuthMode = 0;
parser_done = false; parser_done = false;
m_pPendingRequest = NULL; m_pPendingRequest = NULL;
@ -2050,32 +2051,94 @@ bool pOnvif::ptz_GetPresets(CSTR profileToken)
return false; return false;
} }
void pOnvif::setGenericSpeedSpaces(void)
{
memset(&m_sPanTiltSpeedSpace, 0, sizeof(m_sPanTiltSpeedSpace));
memset(&m_sZoomSpeedSpace, 0, sizeof(m_sZoomSpeedSpace));
safeCopy(m_sPanTiltSpeedSpace.uri, sizeof(m_sPanTiltSpeedSpace.uri), PONVIF_SPACE_PT_GENERIC_SPEED);
safeCopy(m_sZoomSpeedSpace.uri, sizeof(m_sZoomSpeedSpace.uri), PONVIF_SPACE_ZOOM_GENERIC_SPEED);
m_sPanTiltSpeedSpace.max = m_sZoomSpeedSpace.max = 1.0f;
}
/*
Picks the speed space to use out of the node's <PanTiltSpeedSpace> / <ZoomSpeedSpace> list:
the generic one if the node has it, otherwise the first one (with its own range).
*/
static bool pickSpeedSpace(XMLNode & spaces, LPCTSTR name, LPCTSTR genericUri, ptzSpeedSpace * out)
{
// nChildNode(name) compares the prefixed name ("tt:..."), getChildNode(name, i) ignores the prefix
int tPick = -1;
for (int i = 0;; i++)
{
XMLNode tSpace = spaces.getChildNode(name, i);
if (tSpace.isEmpty())
{
break;
};
LPCTSTR tUri = tSpace.getChildNode("URI", 0).getText(0);
if (tUri == NULL)
{
continue;
};
if (tPick < 0 || strcmp(tUri, genericUri) == 0)
{
tPick = i;
};
if (strcmp(tUri, genericUri) == 0)
{
break;
};
};
if (tPick < 0)
{
return false;
};
XMLNode tSpace = spaces.getChildNode(name, tPick);
XMLNode tRange = tSpace.getChildNode("XRange", 0);
LPCTSTR tMin = tRange.getChildNode("Min", 0).getText(0);
LPCTSTR tMax = tRange.getChildNode("Max", 0).getText(0);
float fMax = (tMax != NULL) ? (float) atof(tMax) : 0.0f;
if (fMax <= 0.0f)
{
return false; // no usable range: keep the generic space
};
memset(out, 0, sizeof(ptzSpeedSpace));
safeCopy(out->uri, sizeof(out->uri), tSpace.getChildNode("URI", 0).getText(0));
out->min = (tMin != NULL) ? (float) atof(tMin) : 0.0f;
out->max = fMax;
out->valid = true;
return true;
}
bool pOnvif::ptz_GetNode(CSTR ptzNodeToken) bool pOnvif::ptz_GetNode(CSTR ptzNodeToken)
{ {
if (m_pPTZURI == NULL)
if (m_pPTZURI == NULL || ptzNodeToken == NULL || ptzNodeToken[0] == 0)
{ {
return false; return false;
} }
char tBuffer[DEFAULT_BUFFER_SIZE]; char tBuffer[DEFAULT_BUFFER_SIZE];
_buildRequest(tBuffer, sizeof(tBuffer), PONVIF_BODY_GET_PTZ_NODE, xesc(ptzNodeToken).c_str()); _buildRequest(tBuffer, sizeof(tBuffer), PONVIF_BODY_GET_PTZ_NODE, xesc(ptzNodeToken).c_str());
if (_send_request(m_pPTZURI, tBuffer))
if (! _send_request(m_pPTZURI, tBuffer, true))
{ {
XMLResults tParseResults;
XMLNode response = XMLNode::parseString(m_pLastResponse, "root", &tParseResults);
LOG("RCPT:");
printf("%s\n", m_pLastResponse);
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 $response['Envelope']['Body']['GetNodeResponse'];
};
return false;
}; };
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 tSpaces = response.getChildNode("Body", 0).getChildNode("GetNodeResponse", 0).getChildNode("PTZNode", 0).getChildNode("SupportedPTZSpaces", 0);
if (tSpaces.isEmpty())
{
return false;
};
bool tPT = pickSpeedSpace(tSpaces, "PanTiltSpeedSpace", PONVIF_SPACE_PT_GENERIC_SPEED, &m_sPanTiltSpeedSpace);
bool tZM = pickSpeedSpace(tSpaces, "ZoomSpeedSpace", PONVIF_SPACE_ZOOM_GENERIC_SPEED, &m_sZoomSpeedSpace);
return tPT || tZM;
} }
bool pOnvif::ptz_GotoPreset(CSTR profileToken, CSTR presetToken, float speed_pantilt_x, float speed_pantilt_y, float speed_zoom_x) bool pOnvif::ptz_GotoPreset(CSTR profileToken, CSTR presetToken, float speed_pantilt_x, float speed_pantilt_y, float speed_zoom_x)
@ -2133,14 +2196,20 @@ bool pOnvif::ptz_RelativeMoveZoom(CSTR profileToken, float zoom, float speedZoom
return _send_request(m_pPTZURI, tBuffer, true); return _send_request(m_pPTZURI, tBuffer, true);
} }
bool pOnvif::ptz_AbsoluteMove(CSTR profileToken, float position_pantilt_x, float position_pantilt_y, float zoom)
bool pOnvif::ptz_AbsoluteMove(CSTR profileToken, float position_pantilt_x, float position_pantilt_y, float zoom, float speed)
{ {
if (m_pPTZURI == NULL) if (m_pPTZURI == NULL)
{ {
return false; return false;
} }
char tBuffer[DEFAULT_BUFFER_SIZE];
_buildRequest(tBuffer, sizeof(tBuffer), PONVIF_BODY_ABSOLUTE_MOVE, xesc(profileToken).c_str(), position_pantilt_x, position_pantilt_y, zoom);
// The Speed is sent with its space: without it the device uses its default speed space, where
// x="1" is not necessarily the maximal speed (the moves were slower than the preset moves).
// The generic pan/tilt speed is a scalar (x); y is sent with the same value for devices reading it.
float tPT = (speed < 0.0f) ? m_sPanTiltSpeedSpace.max : m_sPanTiltSpeedSpace.min + speed * (m_sPanTiltSpeedSpace.max - m_sPanTiltSpeedSpace.min);
float tZM = (speed < 0.0f) ? m_sZoomSpeedSpace.max : m_sZoomSpeedSpace.min + speed * (m_sZoomSpeedSpace.max - m_sZoomSpeedSpace.min);
char tBuffer[DEFAULT_BUFFER_SIZE];
_buildRequest(tBuffer, sizeof(tBuffer), PONVIF_BODY_ABSOLUTE_MOVE, xesc(profileToken).c_str(), position_pantilt_x, position_pantilt_y, zoom, tPT, tPT,
xesc(m_sPanTiltSpeedSpace.uri).c_str(), tZM, xesc(m_sZoomSpeedSpace.uri).c_str());
// Wait for the answer so that a SOAP Fault (e.g. position out of range) is detected // Wait for the answer so that a SOAP Fault (e.g. position out of range) is detected
return _send_request(m_pPTZURI, tBuffer, true); return _send_request(m_pPTZURI, tBuffer, true);
} }

35
lib/data/ponvif/ponvif.h

@ -72,7 +72,14 @@
#define PONVIF_BODY_ABSOLUTE_MOVE \ #define PONVIF_BODY_ABSOLUTE_MOVE \
"<AbsoluteMove xmlns=\"" PONVIF_NS_PTZ "\"><ProfileToken>%s</ProfileToken><Position><PanTilt x=\"%0.6f\" y=\"%0.6f\" xmlns=\"" PONVIF_NS_SCHEMA \ "<AbsoluteMove xmlns=\"" PONVIF_NS_PTZ "\"><ProfileToken>%s</ProfileToken><Position><PanTilt x=\"%0.6f\" y=\"%0.6f\" xmlns=\"" PONVIF_NS_SCHEMA \
"\"/><Zoom x=\"%0.6f\" space=\"http://www.onvif.org/ver10/tptz/ZoomSpaces/PositionGenericSpace\" xmlns=\"" PONVIF_NS_SCHEMA \ "\"/><Zoom x=\"%0.6f\" space=\"http://www.onvif.org/ver10/tptz/ZoomSpaces/PositionGenericSpace\" xmlns=\"" PONVIF_NS_SCHEMA \
"\"/></Position><Speed><PanTilt x=\"1\" y=\"1\" xmlns=\"" PONVIF_NS_SCHEMA "\"/><Zoom x=\"1\" xmlns=\"" PONVIF_NS_SCHEMA "\"/></Speed></AbsoluteMove>"
"\"/></Position><Speed><PanTilt x=\"%0.4f\" y=\"%0.4f\" space=\"%s\" xmlns=\"" PONVIF_NS_SCHEMA "\"/><Zoom x=\"%0.4f\" space=\"%s\" xmlns=\"" PONVIF_NS_SCHEMA \
"\"/></Speed></AbsoluteMove>"
// Generic speed spaces (ONVIF PTZ spec: every node with configurable speed provides them, range 0..1).
// The speed of an AbsoluteMove is sent in these spaces (or in the node's own speed space, see ptzSpeedSpace).
// Without a space attribute, a device interprets the value in its own default speed space (the one of
// the PTZConfiguration's DefaultPTZSpeed): there "1" can be a slow speed.
#define PONVIF_SPACE_PT_GENERIC_SPEED "http://www.onvif.org/ver10/tptz/PanTiltSpaces/GenericSpeedSpace"
#define PONVIF_SPACE_ZOOM_GENERIC_SPEED "http://www.onvif.org/ver10/tptz/ZoomSpaces/ZoomGenericSpeedSpace"
// ContinuousMove is assembled from these parts (pan/tilt and zoom in one request) // ContinuousMove is assembled from these parts (pan/tilt and zoom in one request)
#define PONVIF_BODY_CONTINUOUS_MOVE_BEGIN "<ContinuousMove xmlns=\"" PONVIF_NS_PTZ "\"><ProfileToken>%s</ProfileToken><Velocity>" #define PONVIF_BODY_CONTINUOUS_MOVE_BEGIN "<ContinuousMove xmlns=\"" PONVIF_NS_PTZ "\"><ProfileToken>%s</ProfileToken><Velocity>"
#define PONVIF_BODY_CONTINUOUS_MOVE_PT \ #define PONVIF_BODY_CONTINUOUS_MOVE_PT \
@ -114,6 +121,15 @@ typedef struct S_videoSourceProfile
char ptznodetoken[CTEXT]; // PTZConfiguration/NodeToken char ptznodetoken[CTEXT]; // PTZConfiguration/NodeToken
} videoSourceProfile; } videoSourceProfile;
// A speed space of the PTZ node (GetNode -> SupportedPTZSpaces/PanTiltSpeedSpace | ZoomSpeedSpace)
typedef struct S_ptzSpeedSpace
{
char uri[CTEXT];
float min;
float max;
bool valid; // read from the device
} ptzSpeedSpace;
// Result of the last request (pOnvif::getLastError) // Result of the last request (pOnvif::getLastError)
typedef enum E_onvifError typedef enum E_onvifError
{ {
@ -503,6 +519,7 @@ class pOnvif
{ {
private: private:
void cleanNodeCapability( nodeCapability *ptr ); void cleanNodeCapability( nodeCapability *ptr );
void setGenericSpeedSpaces(void);
curlRequestsManager * m_pHttpAccessManager; curlRequestsManager * m_pHttpAccessManager;
basicMutex m_mResponseProtector; basicMutex m_mResponseProtector;
CURL * m_pCURL; CURL * m_pCURL;
@ -541,6 +558,8 @@ class pOnvif
volatile long m_nLastHttpCode; // HTTP status of the last reply (set by parser()) volatile long m_nLastHttpCode; // HTTP status of the last reply (set by parser())
onvifError m_eLastError; onvifError m_eLastError;
char m_cLastFault[CTEXT]; char m_cLastFault[CTEXT];
ptzSpeedSpace m_sPanTiltSpeedSpace; // speed space used for AbsoluteMove (generic 0..1 by default)
ptzSpeedSpace m_sZoomSpeedSpace;
#ifndef CURL_MANAGER #ifndef CURL_MANAGER
static int _writer(char * data, size_t size, size_t nmemb, pOnvif * Ptr); static int _writer(char * data, size_t size, size_t nmemb, pOnvif * Ptr);
#endif #endif
@ -602,7 +621,18 @@ class pOnvif
CSTR media_GetSnapshotUri(CSTR profileToken); CSTR media_GetSnapshotUri(CSTR profileToken);
bool ptz_GetPresets(CSTR profileToken); bool ptz_GetPresets(CSTR profileToken);
// Reads the node's speed spaces (used by ptz_AbsoluteMove: maximal speed). False if not read
bool ptz_GetNode(CSTR ptzNodeToken); bool ptz_GetNode(CSTR ptzNodeToken);
const ptzSpeedSpace & getPanTiltSpeedSpace(void) const
{
return m_sPanTiltSpeedSpace;
}
const ptzSpeedSpace & getZoomSpeedSpace(void) const
{
return m_sZoomSpeedSpace;
}
bool ptz_GetStatus(CSTR profileToken, ptzStatus * tStatus); bool ptz_GetStatus(CSTR profileToken, ptzStatus * tStatus);
// PTZ service capabilities (ONVIF PTZ GetServiceCapabilities). // PTZ service capabilities (ONVIF PTZ GetServiceCapabilities).
// Each output is 1 = supported, 0 = not supported, -1 = not reported by the device. // Each output is 1 = supported, 0 = not supported, -1 = not reported by the device.
@ -612,7 +642,8 @@ class pOnvif
bool ptz_SetPreset(CSTR profileToken, CSTR presetName); bool ptz_SetPreset(CSTR profileToken, CSTR presetName);
bool ptz_RelativeMove(CSTR profileToken, float translation_pantilt_x, float translation_pantilt_y, float speed_pantilt_x, float speed_pantilt_y); bool ptz_RelativeMove(CSTR profileToken, float translation_pantilt_x, float translation_pantilt_y, float speed_pantilt_x, float speed_pantilt_y);
bool ptz_RelativeMoveZoom(CSTR profileToken, float zoom, float speedZoom); bool ptz_RelativeMoveZoom(CSTR profileToken, float zoom, float speedZoom);
bool ptz_AbsoluteMove(CSTR profileToken, float position_pantilt_x, float position_pantilt_y, float zoom);
// Moves at the maximal speed of the speed space (speed < 0, default) or at speed (0..1 of that range)
bool ptz_AbsoluteMove(CSTR profileToken, float position_pantilt_x, float position_pantilt_y, float zoom, float speed = -1.0f);
bool ptz_ContinuousMove(CSTR profileToken, float velocity_pantilt_x, float velocity_pantilt_y); bool ptz_ContinuousMove(CSTR profileToken, float velocity_pantilt_x, float velocity_pantilt_y);
bool ptz_ContinuousMoveZoom(CSTR profileToken, float zoom); bool ptz_ContinuousMoveZoom(CSTR profileToken, float zoom);
// One ContinuousMove for pan/tilt and zoom; axes with has* == false are left out of the request // One ContinuousMove for pan/tilt and zoom; axes with has* == false are left out of the request

9
lib/data/protocol/protocolPTZ_ONVIF.cpp

@ -217,6 +217,15 @@ bool protocolPTZ_ONVIF::create(void)
LOG(tB); LOG(tB);
} }
detectStatusSupport(); detectStatusSupport();
// Speed space of the node: AbsoluteMove at the maximal speed of it (generic 0..1 if not read)
{
bool tRead = m_pOnVif->ptz_GetNode(m_pProfile->ptznodetoken);
const ptzSpeedSpace & tPT = m_pOnVif->getPanTiltSpeedSpace();
const ptzSpeedSpace & tZM = m_pOnVif->getZoomSpeedSpace();
char tB[CTEXT * 4];
snprintf(tB, sizeof(tB), "PTZ speed (%s): PanTilt %.120s max %.3f, Zoom %.120s max %.3f", tRead ? "from node" : "generic default", tPT.uri, tPT.max, tZM.uri, tZM.max);
LOG(tB);
}
LOG("DONE"); LOG("DONE");
m_bStatus = 1; m_bStatus = 1;
return true; return true;

Loading…
Cancel
Save