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.
 
 
 
 
 
 

303 lines
9.7 KiB

#include "objectCamera_ONVIF_PTZ.h"
#include "../../data/onvif/include/onvifclient.hpp"
#define LOG( X ) m_pLog->Log( "objectCamera_ONVIF_PTZ", this, X )
#define LOG_ERROR( X ) m_pLog->Log( "objectCamera_ONVIF_PTZ", this, _LOG_ERROR, X )
objectCamera_ONVIF_PTZ::objectCamera_ONVIF_PTZ(config_setting_t *Settings) :basicCameraPTZ(Settings){
m_pLog = basicLogCollection::getInstance();
m_eControllProtocolType = PTZ_PROTO_ONVIF;
m_pDeviceURI = NULL;
m_pAccessUser = NULL;
m_pAccessPassword = NULL;
m_pProfileToken = NULL;
};
objectCamera_ONVIF_PTZ::~objectCamera_ONVIF_PTZ(){
// Delete Video Source
if( m_pVideoSource != NULL ){
delete( (videoAVLIBSource*) m_pVideoSource );
};
if (m_pDeviceURI != NULL){
delete(m_pDeviceURI);
};
if (m_pAccessUser != NULL){
delete(m_pAccessUser);
};
if (m_pAccessPassword != NULL){
delete(m_pAccessPassword);
};
};
bool objectCamera_ONVIF_PTZ::create(void){
config_setting_t *pSetting;
if( m_pSettings == NULL ) return false;
/* Load Srom Settings */
if( !basicCameraPTZ::create() ) return false;
pSetting = config_setting_get_member(m_pSettings, "DEVICE_URI");
if( pSetting == NULL ) return false;
if (m_pDeviceURI == NULL) m_pDeviceURI = (CSTR)malloc(255);
sprintf(m_pDeviceURI, "%s", config_setting_get_string(pSetting));
pSetting = config_setting_get_member(m_pSettings, "ONVIF_USER");
if (pSetting == NULL) return false;
if (m_pAccessUser == NULL) m_pAccessUser = (CSTR)malloc(255);
sprintf(m_pAccessUser, "%s", config_setting_get_string(pSetting));
pSetting = config_setting_get_member(m_pSettings, "ONVIF_PASSWORD");
if (pSetting == NULL) return false;
if (m_pAccessPassword == NULL) m_pAccessPassword = (CSTR)malloc(255);
sprintf(m_pAccessPassword, "%s", config_setting_get_string(pSetting));
pSetting = config_setting_get_member(m_pSettings, "PROFILE_ID");
if (pSetting == NULL) return false;
m_nProfileID = config_setting_get_int(pSetting);
//Init OnVif device Node
m_pDeviceNode = new OnvifClientDevice(std::string(m_pDeviceURI), std::string(m_pAccessUser), std::string(m_pAccessPassword));
if (m_pDeviceNode == NULL) return false;
int RetVal;
RetVal = m_pDeviceNode->GetCapabilities();
if (RetVal == SOAP_ERR) return false;
OnvifClientMedia media(*m_pDeviceNode);
_trt__GetProfilesResponse profiles;
RetVal = media.GetProfiles(profiles);
if (RetVal == SOAP_ERR) return false;
_trt__GetSnapshotUriResponse SnapshotUriResponse;
_trt__GetStreamUriResponse StreamUriResponse;
tt__StreamSetup StreamSetup;
tt__MediaUri a;
RetVal = media.GetSnapshotUri(SnapshotUriResponse, profiles.Profiles.at(m_nProfileID)->token);
if (RetVal == SOAP_ERR) return false;
RetVal = media.GetStreamUri(StreamUriResponse, StreamSetup, profiles.Profiles.at(m_nProfileID)->token);
if (RetVal == SOAP_ERR) return false;
m_pProfileToken = new std::string(profiles.Profiles.at(m_nProfileID)->token);
m_pPtzNode = new OnvifClientPTZ(*m_pDeviceNode);
if (m_pPtzNode == NULL) return false;
RetVal = m_pPtzNode->Initialize();
if (RetVal == SOAP_ERR) return false;
if (m_sCameraInfo.m_pSourcePath == NULL) m_sCameraInfo.m_pSourcePath = (CSTR)malloc(1024);
char prefix[8], postfix[1024];
memcpy(prefix, StreamUriResponse.MediaUri->Uri.c_str(), 7);
prefix[7] = '\0';
memcpy(postfix, StreamUriResponse.MediaUri->Uri.c_str()+7, strlen(StreamUriResponse.MediaUri->Uri.c_str())-7);
postfix[strlen(StreamUriResponse.MediaUri->Uri.c_str()) - 7] = '\0';
sprintf(m_sCameraInfo.m_pSourcePath, "%s%s:%s@%s", prefix, m_pAccessUser, m_pAccessPassword, postfix);
//init video
videoAVLIBSource *tSource;
tSource = new videoAVLIBSource();
if (tSource->open((CSTR)m_sCameraInfo.m_pSourcePath, false, 25, m_sCameraInfo.m_iSourcePort, m_sCameraInfo.m_iWidth, m_sCameraInfo.m_iHeight)){
//tNode->setTimeLapse(3000);
tSource->attachDestination(m_pVideoNode);
tSource->setStreaming(true);
m_pVideoSource = (basicMediaSource *)tSource;
} else {
delete tSource;
return false;
};
return true;
};
bool objectCamera_ONVIF_PTZ::create(mediaSourceInfo *SI){
config_setting_t *pSetting;
if (m_pSettings == NULL) return false;
if (SI == NULL) return false;
if (!basicCameraPTZ::create(SI)) return false;
pSetting = config_setting_get_member(m_pSettings, "DEVICE_URI");
if (m_pDeviceURI == NULL) m_pDeviceURI = (CSTR)malloc(255);
sprintf(m_pDeviceURI, "%s", SI->devicePath);
if (pSetting == NULL){
pSetting = config_setting_add(m_pSettings, "DEVICE_URI", CONFIG_TYPE_STRING);
};
config_setting_set_string(pSetting, m_pDeviceURI);
pSetting = config_setting_get_member(m_pSettings, "ONVIF_USER");
if (m_pAccessUser == NULL) m_pAccessUser = (CSTR)malloc(255);
sprintf(m_pAccessUser, "%s", SI->deviceName);
if (pSetting == NULL){
pSetting = config_setting_add(m_pSettings, "ONVIF_USER", CONFIG_TYPE_STRING);
};
config_setting_set_string(pSetting, m_pAccessUser);
pSetting = config_setting_get_member(m_pSettings, "ONVIF_PASSWORD");
if (m_pAccessPassword == NULL) m_pAccessPassword = (CSTR)malloc(255);
sprintf(m_pAccessPassword, "%s", SI->deviceName);
if (pSetting == NULL){
pSetting = config_setting_add(m_pSettings, "ONVIF_PASSWORD", CONFIG_TYPE_STRING);
};
config_setting_set_string(pSetting, m_pAccessPassword);
pSetting = config_setting_get_member(m_pSettings, "PROFILE_ID");
m_nProfileID = SI->comTransportType;
if (pSetting == NULL){
pSetting = config_setting_add(m_pSettings, "PROFILE_ID", CONFIG_TYPE_INT);
};
config_setting_set_int(pSetting, m_nProfileID);
basicSettingsProvider::getInstance()->compromise();
return create();
};
void objectCamera_ONVIF_PTZ::dispatch(basicEvent *Evt){
if( Evt->m_eClass == EVT_CLASS_SENSOR ) {
switch (Evt->m_eType){
case EVT_ALARM:
// Basic Camera Reaction
break;
default:
break;
};
} else
if (Evt->m_eClass == EVT_CLASS_IMAGE){
switch (Evt->m_eType){
case EVT_COMMAND:
basicCameraCommand *pData;
pData = (basicCameraCommand *)Evt->m_pEvtData;
// Basic Camera Commands
switch( pData->m_cCode ){
case CMD_CAMERA_INIT:
//m_pProtocol->init();
break;
case CMD_CAMERA_SET_PTZ:
//m_pProtocol->goAbsolute( cP, cT, cZ );
break;
default:
break;
};
break;
default:
break;
};
};
};
void objectCamera_ONVIF_PTZ::cmdBeginPanLeft(void){
//m_pProtocol->goLeft();
//_tptz__RelativeMoveResponse Responce;
//tt__PTZVector Trans;
_tptz__ContinuousMoveResponse Response;
tt__Vector2D PanTilt; /* optional element of type tt:Vector2D */
tt__Vector1D Zoom;
tt__PTZSpeed Speed;
LONG64 Timeout;
Timeout = 5000;
PanTilt.x = -1.f;
PanTilt.y = 0.f;
Zoom.x = 0.f;
Speed.PanTilt = &PanTilt;
Speed.Zoom = &Zoom;
m_pPtzNode->ContinuousMove( Response, Speed, Timeout, *m_pProfileToken );
//m_pPtzNode->RelativeMove(Responce, Trans, )
};
void objectCamera_ONVIF_PTZ::cmdBeginPanRight(void){
//m_pProtocol->goRight();
_tptz__ContinuousMoveResponse Response;
tt__Vector2D PanTilt; /* optional element of type tt:Vector2D */
tt__Vector1D Zoom;
tt__PTZSpeed Speed;
LONG64 Timeout;
Timeout = 5000;
PanTilt.x = 1.f;
PanTilt.y = 0.f;
Zoom.x = 0.f;
Speed.PanTilt = &PanTilt;
Speed.Zoom = &Zoom;
m_pPtzNode->ContinuousMove(Response, Speed, Timeout, *m_pProfileToken);
};
void objectCamera_ONVIF_PTZ::cmdEndManualPan(void){
//m_pProtocol->goStop();
_tptz__StopResponse Responce;
m_pPtzNode->Stop(Responce, true, true, *m_pProfileToken);
};
void objectCamera_ONVIF_PTZ::cmdBeginTiltUp(void){
//m_pProtocol->goUp();
_tptz__ContinuousMoveResponse Response;
tt__Vector2D PanTilt; /* optional element of type tt:Vector2D */
tt__Vector1D Zoom;
tt__PTZSpeed Speed;
LONG64 Timeout;
Timeout = 5000;
PanTilt.x = 0.f;
PanTilt.y = 1.f;
Zoom.x = 0.f;
Speed.PanTilt = &PanTilt;
Speed.Zoom = &Zoom;
m_pPtzNode->ContinuousMove(Response, Speed, Timeout, *m_pProfileToken);
};
void objectCamera_ONVIF_PTZ::cmdBeginTiltDown(void){
//m_pProtocol->goDown();
_tptz__ContinuousMoveResponse Response;
tt__Vector2D PanTilt; /* optional element of type tt:Vector2D */
tt__Vector1D Zoom;
tt__PTZSpeed Speed;
LONG64 Timeout;
Timeout = 5000;
PanTilt.x = 0.f;
PanTilt.y = -1.f;
Zoom.x = 0.f;
Speed.PanTilt = &PanTilt;
Speed.Zoom = &Zoom;
m_pPtzNode->ContinuousMove(Response, Speed, Timeout, *m_pProfileToken);
};
void objectCamera_ONVIF_PTZ::cmdEndManualTilt(void){
//m_pProtocol->goStop();
_tptz__StopResponse Responce;
m_pPtzNode->Stop(Responce, true, true, *m_pProfileToken);
};
void objectCamera_ONVIF_PTZ::cmdBeginZoomWide(void){
//m_pProtocol->startZoomWide();
_tptz__ContinuousMoveResponse Response;
tt__Vector2D PanTilt; /* optional element of type tt:Vector2D */
tt__Vector1D Zoom;
tt__PTZSpeed Speed;
LONG64 Timeout;
Timeout = 5000;
PanTilt.x = 0.f;
PanTilt.y = 0.f;
Zoom.x = -1.f;
Speed.PanTilt = &PanTilt;
Speed.Zoom = &Zoom;
m_pPtzNode->ContinuousMove(Response, Speed, Timeout, *m_pProfileToken);
};
void objectCamera_ONVIF_PTZ::cmdBeginZoomTele(void){
//m_pProtocol->startZoomTele();
_tptz__ContinuousMoveResponse Response;
tt__Vector2D PanTilt; /* optional element of type tt:Vector2D */
tt__Vector1D Zoom;
tt__PTZSpeed Speed;
LONG64 Timeout;
Timeout = 5000;
PanTilt.x = 0.f;
PanTilt.y = 0.f;
Zoom.x = 1.f;
Speed.PanTilt = &PanTilt;
Speed.Zoom = &Zoom;
m_pPtzNode->ContinuousMove(Response, Speed, Timeout, *m_pProfileToken);
};
void objectCamera_ONVIF_PTZ::cmdEndManualZoom(void){
//m_pProtocol->stopZoom();
_tptz__StopResponse Responce;
m_pPtzNode->Stop(Responce, true, true, *m_pProfileToken);
};
#undef LOG
#undef LOG_ERROR