@ -1647,6 +1647,8 @@ bool pOnvif::media_GetVideoSources(void)
return false ;
}
static bool readPtzRange ( XMLNode & node , ptzRange * out ) ;
bool pOnvif : : media_GetProfiles ( void )
{
char tBuffer [ DEFAULT_BUFFER_SIZE ] ;
@ -1737,6 +1739,16 @@ bool pOnvif::media_GetProfiles(void)
{
tPtr - > ptz = true ;
safeCopy ( tPtr - > ptznodetoken , sizeof ( tPtr - > ptznodetoken ) , nNode . getChildNode ( " NodeToken " , 0 ) . getText ( 0 ) ) ;
safeCopy ( tPtr - > ptzdefaultptspace , sizeof ( tPtr - > ptzdefaultptspace ) , nNode . getChildNode ( " DefaultAbsolutePantTiltPositionSpace " , 0 ) . getText ( 0 ) ) ;
safeCopy ( tPtr - > ptzdefaultzoomspace , sizeof ( tPtr - > ptzdefaultzoomspace ) , nNode . getChildNode ( " DefaultAbsoluteZoomPositionSpace " , 0 ) . getText ( 0 ) ) ;
{
XMLNode tL = nNode . getChildNode ( " PanTiltLimits " , 0 ) . getChildNode ( " Range " , 0 ) ;
readPtzRange ( tL , & tPtr - > ptzpantiltlimits ) ;
}
{
XMLNode tL = nNode . getChildNode ( " ZoomLimits " , 0 ) . getChildNode ( " Range " , 0 ) ;
readPtzRange ( tL , & tPtr - > ptzzoomlimits ) ;
}
} ;
}
m_vVideoProfiles . push_back ( tPtr ) ;
@ -2059,6 +2071,95 @@ void pOnvif::setGenericSpeedSpaces(void)
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 ;
memset ( & m_sPanTiltPosSpace , 0 , sizeof ( m_sPanTiltPosSpace ) ) ;
memset ( & m_sZoomPosSpace , 0 , sizeof ( m_sZoomPosSpace ) ) ;
}
/*
Reads a < . . . > element with < URI > , < XRange > < Min / Max > < / XRange > and optional < YRange > ( a node ' s position space
or the Range of a PTZConfiguration ' s PanTiltLimits / ZoomLimits ) .
*/
static bool readPtzRange ( XMLNode & node , ptzRange * out )
{
memset ( out , 0 , sizeof ( ptzRange ) ) ;
if ( node . isEmpty ( ) )
{
return false ;
} ;
LPCTSTR tUri = node . getChildNode ( " URI " , 0 ) . getText ( 0 ) ;
if ( tUri ! = NULL )
{
safeCopy ( out - > uri , sizeof ( out - > uri ) , tUri ) ;
} ;
XMLNode tX = node . getChildNode ( " XRange " , 0 ) ;
LPCTSTR tXMin = tX . getChildNode ( " Min " , 0 ) . getText ( 0 ) ;
LPCTSTR tXMax = tX . getChildNode ( " Max " , 0 ) . getText ( 0 ) ;
if ( tXMin = = NULL | | tXMax = = NULL )
{
return false ;
} ;
out - > xmin = ( float ) atof ( tXMin ) ;
out - > xmax = ( float ) atof ( tXMax ) ;
XMLNode tY = node . getChildNode ( " YRange " , 0 ) ;
LPCTSTR tYMin = tY . getChildNode ( " Min " , 0 ) . getText ( 0 ) ;
LPCTSTR tYMax = tY . getChildNode ( " Max " , 0 ) . getText ( 0 ) ;
if ( tYMin ! = NULL & & tYMax ! = NULL )
{
out - > ymin = ( float ) atof ( tYMin ) ;
out - > ymax = ( float ) atof ( tYMax ) ;
out - > hasY = true ;
} ;
out - > valid = true ;
return true ;
}
// The position space of the node: the generic one if offered, otherwise the first one
static void pickPositionSpace ( XMLNode & spaces , LPCTSTR name , LPCTSTR genericUri , ptzRange * out )
{
memset ( out , 0 , sizeof ( ptzRange ) ) ;
for ( int i = 0 ; ; i + + )
{
XMLNode tSpace = spaces . getChildNode ( name , i ) ;
if ( tSpace . isEmpty ( ) )
{
break ;
} ;
ptzRange tR ;
if ( ! readPtzRange ( tSpace , & tR ) )
{
continue ;
} ;
if ( ! out - > valid | | strcmp ( tR . uri , genericUri ) = = 0 )
{
* out = tR ;
} ;
if ( strcmp ( tR . uri , genericUri ) = = 0 )
{
break ;
} ;
} ;
}
static void ptzRangeText ( char * buf , size_t size , const ptzRange & r )
{
if ( ! r . valid )
{
snprintf ( buf , size , " n/a " ) ;
}
else if ( r . hasY )
{
snprintf ( buf , size , " x [%.4f .. %.4f] y [%.4f .. %.4f] (%.100s) " , r . xmin , r . xmax , r . ymin , r . ymax , r . uri ) ;
}
else
{
snprintf ( buf , size , " [%.4f .. %.4f] (%.100s) " , r . xmin , r . xmax , r . uri ) ;
} ;
}
// Small tolerance: values read back from the device are printed with limited precision
static bool ptzInRange ( float v , float vmin , float vmax )
{
return ( v > = vmin - 0.0001f ) & & ( v < = vmax + 0.0001f ) ;
}
/*
@ -2139,6 +2240,8 @@ bool pOnvif::ptz_GetNode(CSTR ptzNodeToken)
} ;
bool tPT = pickSpeedSpace ( tSpaces , " PanTiltSpeedSpace " , PONVIF_SPACE_PT_GENERIC_SPEED , & m_sPanTiltSpeedSpace ) ;
bool tZM = pickSpeedSpace ( tSpaces , " ZoomSpeedSpace " , PONVIF_SPACE_ZOOM_GENERIC_SPEED , & m_sZoomSpeedSpace ) ;
pickPositionSpace ( tSpaces , " AbsolutePanTiltPositionSpace " , PONVIF_SPACE_PT_GENERIC_POS , & m_sPanTiltPosSpace ) ;
pickPositionSpace ( tSpaces , " AbsoluteZoomPositionSpace " , PONVIF_SPACE_ZOOM_GENERIC_POS , & m_sZoomPosSpace ) ;
return tPT | | tZM ;
}
@ -2208,11 +2311,89 @@ bool pOnvif::ptz_AbsoluteMove(CSTR profileToken, float position_pantilt_x, float
// 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 ] ;
// Limits that apply to this move: the profile's PTZConfiguration limits, else the node's position spaces
const videoSourceProfile * tProfile = NULL ;
for ( size_t i = 0 ; i < m_vVideoProfiles . size ( ) ; i + + )
{
if ( m_vVideoProfiles [ i ] ! = NULL & & strcmp ( m_vVideoProfiles [ i ] - > profiletoken , profileToken ) = = 0 )
{
tProfile = m_vVideoProfiles [ i ] ;
break ;
} ;
} ;
const ptzRange & tPTR = ( tProfile ! = NULL & & tProfile - > ptzpantiltlimits . valid ) ? tProfile - > ptzpantiltlimits : m_sPanTiltPosSpace ;
const ptzRange & tZR = ( tProfile ! = NULL & & tProfile - > ptzzoomlimits . valid ) ? tProfile - > ptzzoomlimits : m_sZoomPosSpace ;
char tOut [ 64 ] ;
tOut [ 0 ] = ( char ) 0 ;
int tLen = 0 ;
if ( tPTR . valid & & ! ptzInRange ( position_pantilt_x , tPTR . xmin , tPTR . xmax ) )
{
tLen + = snprintf ( tOut + tLen , sizeof ( tOut ) - tLen , " PAN " ) ;
} ;
if ( tPTR . valid & & tPTR . hasY & & ! ptzInRange ( position_pantilt_y , tPTR . ymin , tPTR . ymax ) & & tLen < ( int ) sizeof ( tOut ) )
{
tLen + = snprintf ( tOut + tLen , sizeof ( tOut ) - tLen , " TILT " ) ;
} ;
if ( tZR . valid & & ! ptzInRange ( zoom , tZR . xmin , tZR . xmax ) & & tLen < ( int ) sizeof ( tOut ) )
{
tLen + = snprintf ( tOut + tLen , sizeof ( tOut ) - tLen , " ZOOM " ) ;
} ;
char tMove [ CTEXT * 2 ] ;
snprintf ( tMove , sizeof ( tMove ) , " AbsoluteMove pan=%0.6f tilt=%0.6f zoom=%0.6f (speed pt=%0.4f zoom=%0.4f) " , position_pantilt_x , position_pantilt_y , zoom , tPT , tZM ) ;
if ( tOut [ 0 ] ! = 0 )
{
char tB [ CTEXT * 4 ] ;
snprintf ( tB , sizeof ( tB ) , " %s: OUT OF CAMERA LIMITS:%s " , tMove , tOut ) ;
LOG_ERROR ( tB ) ;
}
# ifdef DEBUG_PONVIF_PTZ
else
{
LOG ( tMove ) ;
} ;
# endif
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
return _send_request ( m_pPTZURI , tBuffer , true ) ;
bool tOk = _send_request ( m_pPTZURI , tBuffer , true ) ;
if ( ! tOk )
{
char tB [ CTEXT * 4 ] ;
snprintf ( tB , sizeof ( tB ) , " %s REJECTED (%s) " , tMove , ( m_cLastFault [ 0 ] ! = 0 ) ? m_cLastFault : " no answer " ) ;
LOG_ERROR ( tB ) ;
if ( m_eLastError = = PONVIF_ERR_FAULT )
{
ptz_LogRanges ( profileToken ) ;
} ;
} ;
return tOk ;
}
void pOnvif : : ptz_LogRanges ( CSTR profileToken )
{
char tR1 [ CTEXT * 2 ] ;
char tR2 [ CTEXT * 2 ] ;
char tB [ CTEXT * 6 ] ;
ptzRangeText ( tR1 , sizeof ( tR1 ) , m_sPanTiltPosSpace ) ;
ptzRangeText ( tR2 , sizeof ( tR2 ) , m_sZoomPosSpace ) ;
snprintf ( tB , sizeof ( tB ) , " PTZ node position space: PanTilt %s, Zoom %s " , tR1 , tR2 ) ;
LOG ( tB ) ;
for ( size_t i = 0 ; i < m_vVideoProfiles . size ( ) ; i + + )
{
const videoSourceProfile * tP = m_vVideoProfiles [ i ] ;
if ( tP = = NULL | | ! tP - > ptz | | ( profileToken ! = NULL & & strcmp ( tP - > profiletoken , profileToken ) ! = 0 ) )
{
continue ;
} ;
ptzRangeText ( tR1 , sizeof ( tR1 ) , tP - > ptzpantiltlimits ) ;
ptzRangeText ( tR2 , sizeof ( tR2 ) , tP - > ptzzoomlimits ) ;
snprintf ( tB , sizeof ( tB ) , " PTZ profile %.60s limits: PanTilt %s, Zoom %s " , tP - > profiletoken , tR1 , tR2 ) ;
LOG ( tB ) ;
snprintf ( tB , sizeof ( tB ) , " PTZ profile %.60s default spaces: PanTilt %.120s, Zoom %.120s (the PanTilt position is sent without a space) " , tP - > profiletoken ,
tP - > ptzdefaultptspace [ 0 ] ? tP - > ptzdefaultptspace : " n/a " , tP - > ptzdefaultzoomspace [ 0 ] ? tP - > ptzdefaultzoomspace : " n/a " ) ;
LOG ( tB ) ;
} ;
}
bool pOnvif : : ptz_ContinuousMove ( CSTR profileToken , float velocity_pantilt_x , float velocity_pantilt_y )