#include "onvifCameraFind.h"
#include "globaldata.h"
OnvifCameraFind::OnvifCameraFind()
{
}
OnvifCameraFind::~OnvifCameraFind()
{
quit();
wait();
deleteLater();
}
void OnvifCameraFind::run()
{
ONVIF_DetectDevice();
}
void OnvifCameraFind::delay_ms(unsigned int milliseconds) {
std::this_thread::sleep_for(std::chrono::milliseconds(milliseconds));
}
void OnvifCameraFind::soap_perror(struct soap* soap, const char* str)
{
if (nullptr == str) {
SOAP_DBGERR("[soap] error: %d, %s, %s\n", soap->error, *soap_faultcode(soap), *soap_faultstring(soap));
}
else {
SOAP_DBGERR("[soap] %s error: %d, %s, %s\n", str, soap->error, *soap_faultcode(soap), *soap_faultstring(soap));
}
}
void* OnvifCameraFind::ONVIF_soap_malloc(struct soap* soap, unsigned int n)
{
void* p = nullptr;
if (n > 0) {
p = soap_malloc(soap, n);
SOAP_ASSERT(nullptr != p);
memset(p, 0x00, n);
}
return p;
}
struct soap* OnvifCameraFind::ONVIF_soap_new(int timeout)
{
struct soap* soap = nullptr; // soap environment variable
SOAP_ASSERT(nullptr != (soap = soap_new()));
soap_set_namespaces(soap, namespaces); // set namespaces for soap
soap->recv_timeout = timeout; // set timeout
soap->send_timeout = timeout;
soap->connect_timeout = timeout;
soap_set_mode(soap, SOAP_C_UTFSTRING); // set UTF-8 code
return soap;
}
void OnvifCameraFind::ONVIF_soap_delete(struct soap* soap)
{
soap_destroy(soap);
soap_end(soap);
soap_done(soap);
soap_free(soap);
}
//Init soap description message header
void OnvifCameraFind::ONVIF_init_header(struct soap* soap)
{
struct SOAP_ENV__Header* header = nullptr;
SOAP_ASSERT(nullptr != soap);
header = (struct SOAP_ENV__Header*)ONVIF_soap_malloc(soap, sizeof(struct SOAP_ENV__Header));
soap_default_SOAP_ENV__Header(soap, header);
header->wsa__MessageID = (char*)soap_wsa_rand_uuid(soap);
header->wsa__To = (char*)ONVIF_soap_malloc(soap, strlen(SOAP_TO) + 1);
header->wsa__Action = (char*)ONVIF_soap_malloc(soap, strlen(SOAP_ACTION) + 1);
strcpy(header->wsa__To, SOAP_TO);
strcpy(header->wsa__Action, SOAP_ACTION);
soap->header = header;
return;
}
//Init the range and type of detection devices
void OnvifCameraFind::ONVIF_init_ProbeType(struct soap* soap, struct wsdd__ProbeType* probe)
{
struct wsdd__ScopesType* scope = nullptr; // Used to describe which type of web service to search for
SOAP_ASSERT(nullptr != soap);
SOAP_ASSERT(nullptr != probe);
scope = (struct wsdd__ScopesType*)ONVIF_soap_malloc(soap, sizeof(struct wsdd__ScopesType));
soap_default_wsdd__ScopesType(soap, scope); // Set the range for finding devices
scope->__item = (char*)ONVIF_soap_malloc(soap, strlen(SOAP_ITEM) + 1);
strcpy(scope->__item, SOAP_ITEM);
memset(probe, 0x00, sizeof(struct wsdd__ProbeType));
soap_default_wsdd__ProbeType(soap, probe);
probe->Scopes = scope;
probe->Types = (char*)ONVIF_soap_malloc(soap, strlen(SOAP_TYPES) + 1); // Set the type of device to search for
strcpy(probe->Types, SOAP_TYPES);
return;
}
void OnvifCameraFind::ONVIF_DetectDevice()
{
int i, retry_count = 0;
int result = 0;
unsigned int count = 0;
struct soap* soap = nullptr;
struct wsdd__ProbeType req;
struct __wsdd__ProbeMatches rep;
struct wsdd__ProbeMatchType* probeMatch;
//SOAP_DBGLOG("Starting device discovery (attempt %d of %d)...\n", retry_count + 1, MAX_DISCOVERY_RETRIES);
while (retry_count < MAX_DISCOVERY_RETRIES)
{
// if fail add timeout
int current_timeout = SOAP_SOCK_TIMEOUT + (retry_count * DISCOVERY_TIMEOUT_INCREMENT);
soap = ONVIF_soap_new(current_timeout);
if (!soap) {
//SOAP_DBGERR("Failed to create SOAP context for discovery retry %d\n", retry_count + 1);
retry_count++;
continue;
}
ONVIF_init_header(soap);
ONVIF_init_ProbeType(soap, &req);
// send Probe request
result = soap_send___wsdd__Probe(soap, SOAP_MCAST_ADDR, nullptr, &req);
if (result != SOAP_OK) {
//soap_perror(soap, "Probe send failed");
ONVIF_soap_delete(soap);
retry_count++;
continue;
}
// recv response
bool received_response = false;
time_t start_time = time(nullptr);
while ((time(nullptr) - start_time) < current_timeout)
{
memset(&rep, 0x00, sizeof(rep));
result = soap_recv___wsdd__ProbeMatches(soap, &rep);
if (result == SOAP_OK)
{
received_response = true;
if (soap->error)
{
//soap_perror(soap, "ProbeMatches error");
}
else if (rep.wsdd__ProbeMatches)
{
count += rep.wsdd__ProbeMatches->__sizeProbeMatch;
for (i = 0; i < rep.wsdd__ProbeMatches->__sizeProbeMatch; i++)
{
probeMatch = rep.wsdd__ProbeMatches->ProbeMatch + i;
if ( probeMatch->XAddrs)
{
cb_discovery(probeMatch->XAddrs);
}
}
}
}
else if (soap->error && soap->errnum == ETIMEDOUT)
{
// Continue waiting after timeout without interrupting the entire discovery process
//SOAP_DBGLOG("Discovery timeout - continuing to wait...\n");
continue;
}
else
{
// Other errors, record and exit the loop
//soap_perror(soap, "ProbeMatches fatal error");
break;
}
}
ONVIF_soap_delete(soap);
// If a response is received, exit the retry loop
if (received_response)
{
break;
}
else
{
//SOAP_DBGLOG("Discovery attempt %d timed out. Retrying with increased timeout...\n",
// retry_count + 1);
retry_count++;
}
}
if (count == 0)
{
// SOAP_DBGERR("Device discovery failed after %d attempts\n", MAX_DISCOVERY_RETRIES);
}
else
{
// SOAP_DBGLOG("Discovery completed! Total devices found: %d\n", count);
}
}
//Set authentication information
int OnvifCameraFind::ONVIF_SetAuthInfo(struct soap* soap, const char* username, const char* password)
{
int result = 0;
SOAP_ASSERT(nullptr != USERNAME);
SOAP_ASSERT(nullptr != PASSWORD);
result = soap_wsse_add_UsernameTokenDigest(soap, nullptr, username, password);
SOAP_CHECK_ERROR(result, soap, "add_UsernameTokenDigest");
EXIT:
return result;
}
//Construct a URI address with authentication information
int OnvifCameraFind::make_uri_withauth(const std::string& src_uri, const std::string& username, const std::string& password, std::string* dest_uri)
{
int result = 0;
unsigned int needBufSize = 0;
SOAP_ASSERT(!src_uri.empty());
if (username.empty() && password.empty())
{
// new uri address
*dest_uri = src_uri;
}
else {
std::string::size_type position = src_uri.find("//");
if (std::string::npos == position) {
SOAP_DBGERR("can't found '//', src uri is: %s.\n", src_uri.c_str());
result = -1;
return result;
}
position += 2;
dest_uri->append(src_uri, 0, position);
dest_uri->append(username + ":" + password + "@");
dest_uri->append(src_uri, position, std::string::npos);
}
return result;
}
// Obtain basic device information
int OnvifCameraFind::ONVIF_GetDeviceInformation(const char* DeviceXAddr, ONVIFDeviceInfo& deviceInfo)
{
int result = 0;
struct soap* soap = nullptr;
_tds__GetDeviceInformation devinfo_req;
_tds__GetDeviceInformationResponse devinfo_resp;
SOAP_ASSERT(nullptr != DeviceXAddr);
SOAP_ASSERT(nullptr != (soap = ONVIF_soap_new(SOAP_SOCK_TIMEOUT)));
ONVIF_SetAuthInfo(soap, USERNAME, PASSWORD);
result = soap_call___tds__GetDeviceInformation(soap, DeviceXAddr, nullptr, &devinfo_req, devinfo_resp);
SOAP_CHECK_ERROR(result, soap, "GetDeviceInformation");
// Fill in the device information structure
deviceInfo.manufacturer = devinfo_resp.Manufacturer;
deviceInfo.model = devinfo_resp.Model;
deviceInfo.firmwareVersion = devinfo_resp.FirmwareVersion;
deviceInfo.serialNumber = devinfo_resp.SerialNumber;
deviceInfo.hardwareId = devinfo_resp.HardwareId;
EXIT:
if (nullptr != soap) {
ONVIF_soap_delete(soap);
}
return result;
}
//Obtain device capability information
int OnvifCameraFind::ONVIF_GetCapabilities(const char* DeviceXAddr, std::string& ptzXAddr, std::string& MediaXAddr, ONVIFDeviceInfo& deviceInfo)
{
int result = 0;
struct soap* soap = nullptr;
_tds__GetCapabilities devinfo_req;
_tds__GetCapabilitiesResponse devinfo_resp;
/* SOAP_ASSERT(!ptzXAddr.empty());*/
SOAP_ASSERT(NULL != (soap = ONVIF_soap_new(SOAP_SOCK_TIMEOUT)));
result = soap_call___tds__GetCapabilities(soap, DeviceXAddr, NULL, &devinfo_req, devinfo_resp);
SOAP_CHECK_ERROR(result, soap, "GetCapabilities");
if (devinfo_resp.Capabilities->Device != nullptr) {
deviceInfo.deviceCapabilitiesXAddr = devinfo_resp.Capabilities->Device->XAddr;
}
if (devinfo_resp.Capabilities->Analytics != nullptr) {
deviceInfo.analyticsXAddr = devinfo_resp.Capabilities->Analytics->XAddr;
}
if (devinfo_resp.Capabilities->Events != nullptr) {
deviceInfo.eventsXAddr = devinfo_resp.Capabilities->Events->XAddr;
}
if (devinfo_resp.Capabilities->Imaging != nullptr) {
deviceInfo.imagingXAddr = devinfo_resp.Capabilities->Imaging->XAddr;
}
if (devinfo_resp.Capabilities->Media != nullptr) {
MediaXAddr = devinfo_resp.Capabilities->Media->XAddr;
deviceInfo.mediaXAddr = devinfo_resp.Capabilities->Media->XAddr;
}
if (devinfo_resp.Capabilities->PTZ != nullptr) {
ptzXAddr = devinfo_resp.Capabilities->PTZ->XAddr;
deviceInfo.ptzXAddr = devinfo_resp.Capabilities->PTZ->XAddr;
}
if (devinfo_resp.Capabilities->Extension != nullptr && devinfo_resp.Capabilities->Extension->DeviceIO != nullptr) {
deviceInfo.deviceIOXAddr = devinfo_resp.Capabilities->Extension->DeviceIO->XAddr;
}
EXIT:
if (NULL != soap) {
ONVIF_soap_delete(soap);
}
return result;
}
//Function: Retrieve audio and video streaming data from RTSP
int OnvifCameraFind::ONVIF_GetProfiles(const std::string& mediaXAddr, std::string* profilesToken)
{
int result = 0;
struct soap* soap = nullptr;
_trt__GetProfiles req;
_trt__GetProfilesResponse resp;
SOAP_ASSERT(!mediaXAddr.empty());
SOAP_ASSERT(nullptr != (soap = ONVIF_soap_new(SOAP_SOCK_TIMEOUT)));
ONVIF_SetAuthInfo(soap, USERNAME, PASSWORD);
result = soap_call___trt__GetProfiles(soap, mediaXAddr.c_str(), nullptr, &req, resp);
SOAP_CHECK_ERROR(result, soap, "ONVIF_GetProfiles");
//Check if there is a configuration file
if (resp.Profiles.empty()) {
SOAP_DBGERR("devices not config file\n");
result = -1;
goto EXIT;
}
*profilesToken = resp.Profiles[0]->token;
EXIT:
if (nullptr != soap) {
ONVIF_soap_delete(soap);
}
return result;
}
//Get the address of the WSDL
int OnvifCameraFind::ONVIF_GetWsdlUrl(const char* DeviceXAddr, ONVIFDeviceInfo& deviceInfo)
{
int result = 0;
struct soap* soap = nullptr;
_tds__GetWsdlUrl devinfo_req;
_tds__GetWsdlUrlResponse devinfo_resp;
SOAP_ASSERT(nullptr != DeviceXAddr);
SOAP_ASSERT(nullptr != (soap = ONVIF_soap_new(SOAP_SOCK_TIMEOUT)));
result = soap_call___tds__GetWsdlUrl(soap, DeviceXAddr, nullptr, &devinfo_req, devinfo_resp);
SOAP_CHECK_ERROR(result, soap, "ONVIF_GetWsdlUrl");
deviceInfo.wsdlUrl = devinfo_resp.WsdlUrl;
EXIT:
if (nullptr != soap) {
ONVIF_soap_delete(soap);
}
return result;
}
//Get device stream address (RTSP)
int OnvifCameraFind::ONVIF_GetStreamUri(const std::string& MediaXAddr, const std::string& ProfileToken, std::string* rtspUri)
{
int result = 0;
struct soap* soap = nullptr;
tt__StreamSetup ttStreamSetup;
tt__Transport ttTransport;
_trt__GetStreamUri req;
_trt__GetStreamUriResponse rep;
SOAP_ASSERT(!MediaXAddr.empty());
SOAP_ASSERT(nullptr != (soap = ONVIF_soap_new(SOAP_SOCK_TIMEOUT)));
ttStreamSetup.Stream = tt__StreamType__RTP_Unicast;
ttStreamSetup.Transport = &ttTransport;
ttStreamSetup.Transport->Protocol = tt__TransportProtocol__RTSP;
ttStreamSetup.Transport->Tunnel = nullptr;
req.StreamSetup = &ttStreamSetup;
req.ProfileToken = const_cast<char*>(ProfileToken.c_str());
ONVIF_SetAuthInfo(soap, USERNAME, PASSWORD);
result = soap_call___trt__GetStreamUri(soap, MediaXAddr.c_str(), nullptr, &req, rep);
SOAP_CHECK_ERROR(result, soap, "GetServices");
if (nullptr != rep.MediaUri && !rep.MediaUri->Uri.empty()) {
*rtspUri = rep.MediaUri->Uri;
}
else {
SOAP_DBGERR("get RTSP address fail??MediaUri is null\n");
result = -1;
}
EXIT:
if (nullptr != soap) {
ONVIF_soap_delete(soap);
}
return result;
}
//Get device image capture address (HTTP)
int OnvifCameraFind::ONVIF_GetSnapshotUri(const std::string& MediaXAddr, const std::string& ProfileToken, std::string* snapUri)
{
int result = 0;
struct soap* soap = nullptr;
_trt__GetSnapshotUri req;
_trt__GetSnapshotUriResponse rep;
SOAP_ASSERT(!MediaXAddr.empty() && !ProfileToken.empty());
SOAP_ASSERT(nullptr != (soap = ONVIF_soap_new(SOAP_SOCK_TIMEOUT)));
ONVIF_SetAuthInfo(soap, USERNAME, PASSWORD);
req.ProfileToken = const_cast<char*>(ProfileToken.c_str());
result = soap_call___trt__GetSnapshotUri(soap, MediaXAddr.c_str(), NULL, &req, rep);
SOAP_CHECK_ERROR(result, soap, "GetSnapshotUri");
if (rep.MediaUri != nullptr && !rep.MediaUri->Uri.empty()) {
*snapUri = rep.MediaUri->Uri;
}
EXIT:
if (NULL != soap) {
ONVIF_soap_delete(soap);
}
return result;
}
//Retrieve the current location and status of PTZ
int OnvifCameraFind::ONVIF_PTZ_GetStatus(const std::string& ptzXAddr, const std::string& ProfileToken) {
int result = 0;
struct soap* soap = nullptr;
_tptz__GetStatus getStatus;
_tptz__GetStatusResponse getStatusResponse;
SOAP_ASSERT(!ptzXAddr.empty());
SOAP_ASSERT(nullptr != (soap = ONVIF_soap_new(SOAP_SOCK_TIMEOUT)));
ONVIF_SetAuthInfo(soap, USERNAME, PASSWORD);
getStatus.ProfileToken = const_cast<char*>(ProfileToken.c_str());
result = soap_call___tptz__GetStatus(soap, ptzXAddr.c_str(), nullptr, &getStatus, getStatusResponse);
SOAP_CHECK_ERROR(result, soap, "ONVIF_PTZ_GetStatus");
if (*getStatusResponse.PTZStatus->MoveStatus->PanTilt == tt__MoveStatus__IDLE) {
std::cout << " ???? ... " << std::endl;
}
else if (*getStatusResponse.PTZStatus->MoveStatus->PanTilt == tt__MoveStatus__MOVING) {
std::cout << " ????? ... " << std::endl;
}
else if (*getStatusResponse.PTZStatus->MoveStatus->PanTilt == tt__MoveStatus__UNKNOWN) {
std::cout << " ??? ... " << std::endl;
}
std::cout << "???p: " << getStatusResponse.PTZStatus->Position->PanTilt->x << "\n";
std::cout << "???t: " << getStatusResponse.PTZStatus->Position->PanTilt->y << "\n";
std::cout << "???z: " << getStatusResponse.PTZStatus->Position->Zoom->x << "\n";
EXIT:
if (nullptr != soap) {
ONVIF_soap_delete(soap);
}
return 0;
}
//Move ptz to the specified position at the specified speed
// p : -1 ~ 1 []
// t : -1 ~ 1
// z : 0 ~ 1
int OnvifCameraFind::ONVIF_PTZAbsoluteMove(const std::string& ptzXAddr, const std::string& ProfileToken) {
int result = 0;
struct soap* soap = nullptr;
_tptz__AbsoluteMove absoluteMove;
_tptz__AbsoluteMoveResponse absoluteMoveResponse;
SOAP_ASSERT(!ptzXAddr.empty() && !ProfileToken.empty());
SOAP_ASSERT(nullptr != (soap = ONVIF_soap_new(SOAP_SOCK_TIMEOUT)));
ONVIF_SetAuthInfo(soap, USERNAME, PASSWORD);
absoluteMove.ProfileToken = const_cast<char*>(ProfileToken.c_str());
absoluteMove.Position = soap_new_tt__PTZVector(soap);
absoluteMove.Position->PanTilt = soap_new_tt__Vector2D(soap);
absoluteMove.Position->Zoom = soap_new_tt__Vector1D(soap);
absoluteMove.Speed = soap_new_tt__PTZSpeed(soap);
absoluteMove.Speed->PanTilt = soap_new_tt__Vector2D(soap);
absoluteMove.Speed->Zoom = soap_new_tt__Vector1D(soap);
absoluteMove.Position->PanTilt->x = 0.440833; // p
absoluteMove.Position->PanTilt->y = 0.583455; // t
absoluteMove.Position->Zoom->x = 0.0333333; // z
//The closer the absolute values of x and y are to 1, the faster the speed of the gimbal
absoluteMove.Speed->PanTilt->x = 0.5;
absoluteMove.Speed->PanTilt->y = 0.5;
absoluteMove.Speed->Zoom->x = 0.5;
result = soap_call___tptz__AbsoluteMove(soap, ptzXAddr.c_str(), nullptr, &absoluteMove, absoluteMoveResponse);
SOAP_CHECK_ERROR(result, soap, "ONVIF_PTZAbsoluteMove");
EXIT:
if (nullptr != soap) {
ONVIF_soap_delete(soap);
}
return 0;
}
int OnvifCameraFind::ONVIF_PTZStopMove(const std::string& ptzXAddr, const std::string& ProfileToken)
{
int result = 0;
struct soap* soap = nullptr;
_tptz__Stop tptzStop;
_tptz__StopResponse tptzStopResponse;
SOAP_ASSERT(!ptzXAddr.empty() && !ProfileToken.empty());
SOAP_ASSERT(nullptr != (soap = ONVIF_soap_new(SOAP_SOCK_TIMEOUT)));
ONVIF_SetAuthInfo(soap, USERNAME, PASSWORD);
tptzStop.ProfileToken = const_cast<char*>(ProfileToken.c_str());
result = soap_call___tptz__Stop(soap, ptzXAddr.c_str(), nullptr, &tptzStop, tptzStopResponse);
SOAP_CHECK_ERROR(result, soap, "ONVIF_PTZStopMove");
EXIT:
if (nullptr != soap) {
ONVIF_soap_delete(soap);
}
return result;
}
// speed --> (0, 1]
int OnvifCameraFind::ONVIF_PTZContinuousMove(const std::string& ptzXAddr, const std::string& ProfileToken, enum PTZCMD cmd, float speed)
{
int result = 0;
struct soap* soap = nullptr;
_tptz__ContinuousMove continuousMove;
_tptz__ContinuousMoveResponse continuousMoveResponse;
SOAP_ASSERT(!ptzXAddr.empty() && !ProfileToken.empty());
SOAP_ASSERT(nullptr != (soap = ONVIF_soap_new(SOAP_SOCK_TIMEOUT)));
ONVIF_SetAuthInfo(soap, USERNAME, PASSWORD);
continuousMove.ProfileToken = const_cast<char*>(ProfileToken.c_str());
continuousMove.Velocity = soap_new_tt__PTZSpeed(soap);
continuousMove.Velocity->PanTilt = soap_new_tt__Vector2D(soap);
continuousMove.Velocity->Zoom = soap_new_tt__Vector1D(soap);
switch (cmd)
{
case PTZ_CMD_LEFT:
continuousMove.Velocity->PanTilt->x = -speed;
continuousMove.Velocity->PanTilt->y = 0;
break;
case PTZ_CMD_RIGHT:
continuousMove.Velocity->PanTilt->x = speed;
continuousMove.Velocity->PanTilt->y = 0;
break;
case PTZ_CMD_UP:
continuousMove.Velocity->PanTilt->x = 0;
continuousMove.Velocity->PanTilt->y = speed;
break;
case PTZ_CMD_DOWN:
continuousMove.Velocity->PanTilt->x = 0;
continuousMove.Velocity->PanTilt->y = -speed;
break;
case PTZ_CMD_LEFTUP:
continuousMove.Velocity->PanTilt->x = -speed;
continuousMove.Velocity->PanTilt->y = speed;
break;
case PTZ_CMD_LEFTDOWN:
continuousMove.Velocity->PanTilt->x = -speed;
continuousMove.Velocity->PanTilt->y = -speed;
break;
case PTZ_CMD_RIGHTUP:
continuousMove.Velocity->PanTilt->x = speed;
continuousMove.Velocity->PanTilt->y = speed;
break;
case PTZ_CMD_RIGHTDOWN:
continuousMove.Velocity->PanTilt->x = speed;
continuousMove.Velocity->PanTilt->y = -speed;
break;
case PTZ_CMD_ZOOM_IN:
continuousMove.Velocity->PanTilt->x = 0;
continuousMove.Velocity->PanTilt->y = 0;
continuousMove.Velocity->Zoom->x = speed;
break;
case PTZ_CMD_ZOOM_OUT:
continuousMove.Velocity->PanTilt->x = 0;
continuousMove.Velocity->PanTilt->y = 0;
continuousMove.Velocity->Zoom->x = -speed;
break;
default:
break;
}
// You can also use soap_call_ tptz_ RelativeMove to implement it
result = soap_call___tptz__ContinuousMove(soap, ptzXAddr.c_str(), nullptr, &continuousMove, continuousMoveResponse);
SOAP_CHECK_ERROR(result, soap, "ONVIF_PTZAbsoluteMove");
EXIT:
if (nullptr != soap) {
ONVIF_soap_delete(soap);
}
return result;
}
//???????
void OnvifCameraFind::printDeviceInfo(const ONVIFDeviceInfo& deviceInfo)
{
std::cout << "\n==== Discovered device: " << deviceInfo.deviceXAddr << " ====" << std::endl;
std::cout << "Manufacturer: " << deviceInfo.manufacturer << std::endl;
std::cout << "Model: " << deviceInfo.model << std::endl;
std::cout << "Firmware Version: " << deviceInfo.firmwareVersion << std::endl;
std::cout << "Serial Number: " << deviceInfo.serialNumber << std::endl;
std::cout << "Hardware ID: " << deviceInfo.hardwareId << std::endl;
std::cout << "WSDL Address: " << deviceInfo.wsdlUrl << std::endl;
std::cout << "Device Capability Address: " << deviceInfo.deviceCapabilitiesXAddr << std::endl;
std::cout << "Analysis Service Address: " << deviceInfo.analyticsXAddr << std::endl;
std::cout << "Event Service Address: " << deviceInfo.eventsXAddr << std::endl;
std::cout << "Imaging Service Address: " << deviceInfo.imagingXAddr << std::endl;
std::cout << "Media Service Address: " << deviceInfo.mediaXAddr << std::endl;
std::cout << "PTZ Service Address: " << deviceInfo.ptzXAddr << std::endl;
std::cout << "Device IO Extension Address: " << deviceInfo.deviceIOXAddr << std::endl;
std::cout << "y?????????????: ";
for (const auto& token : deviceInfo.profileTokens) {
std::cout << token << " ";
}
std::cout << std::endl;
std::cout << "Media Profile Token: " << deviceInfo.currentProfileToken << std::endl;
std::cout << "RTSP Stream Address: " << deviceInfo.rtspUri << std::endl;
std::cout << "Capture Address: " << deviceInfo.snapshotUri << std::endl;
}
void OnvifCameraFind::cb_discovery(char* deviceXAddr)
{
std::string ptzXAddr; // PTZ address
std::string mediaXAddr; // Media address
std::string profilesToken;// Configuration file token
std::string snapshotUri;// Capture address
std::string RTSP; // RTSP address
int ret; ONVIFDeviceInfo deviceInfo;
deviceInfo.deviceXAddr = deviceXAddr; //Set device onvif service address
deviceInfo.ip = extractIpFromURL(deviceInfo.deviceXAddr);
GlobalData::getGlobalData()->hxLog(HX_LOG_LEVEL_INFO, "ONVIF find devices [%s]", deviceInfo.ip.c_str());
// get devices information
ret = ONVIF_GetDeviceInformation(deviceXAddr, deviceInfo);
if (ret != 0)
{
GlobalData::getGlobalData()->hxLog(HX_LOG_LEVEL_ERROR,"ONVIF Failed to obtain device information error code[%d]",ret);
return;
}
// get WSDL address
ret = ONVIF_GetWsdlUrl(deviceXAddr, deviceInfo);
if (ret != 0)
{
GlobalData::getGlobalData()->hxLog(HX_LOG_LEVEL_ERROR, "ONVIF Failed to obtain the WSDL address error code[%d]", ret);
return;
}
// get device capabilities, including PTZ address
ret = ONVIF_GetCapabilities(deviceXAddr, ptzXAddr, mediaXAddr, deviceInfo);
if (ret != 0)
{
GlobalData::getGlobalData()->hxLog(HX_LOG_LEVEL_ERROR, "ONVIF Failed to obtain device capability error code[%d]", ret);
}
if (ptzXAddr.empty())
{
GlobalData::getGlobalData()->hxLog(HX_LOG_LEVEL_WARNING, "ONVIF The device does not support PTZ function error code[%d]", ret);
}
// get device configuration files
ret = ONVIF_GetProfiles(mediaXAddr, &profilesToken);
if (ret != 0)
{
GlobalData::getGlobalData()->hxLog(HX_LOG_LEVEL_ERROR, "ONVIF Failed to obtain the audio and video stream configuration information of the device error code[%d]", ret);
return;
}
deviceInfo.currentProfileToken = profilesToken; // Store the current configuration file token
deviceInfo.profileTokens.push_back(profilesToken); // Add to configuration file token list
ret = ONVIF_GetSnapshotUri(mediaXAddr, profilesToken, &snapshotUri);
if (ret == 0) {
deviceInfo.snapshotUri = snapshotUri; // Store snapshot address
}
else
{
GlobalData::getGlobalData()->hxLog(HX_LOG_LEVEL_ERROR, "ONVIF Failed to get capture address error code[%d]", ret);
return;
}
//gte rtsp address
ONVIF_GetStreamUri(mediaXAddr, profilesToken, &RTSP);//rtsp
if (ret == 0)
{
deviceInfo.rtspUri = RTSP; // store RTSP address
}
else
{
GlobalData::getGlobalData()->hxLog(HX_LOG_LEVEL_ERROR, "ONVIF Failed to get rtsp address error code[%d]", ret);
return;
}
m_onvifFindDev.insert(QString(deviceInfo.ip.c_str()), deviceInfo);
emit sig_onvifFindCameraHash(m_onvifFindDev);
//printDeviceInfo(deviceInfo);
}
std::string OnvifCameraFind::extractIpFromURL(const std::string& url)
{
size_t start = url.find("://");
if (start == std::string::npos)
{
start = 0;
}
else
{
start += 3;
}
size_t end = url.find('/', start);
if (end == std::string::npos)
{
end = url.length();
}
return url.substr(start, end - start);
}
void OnvifCameraFind::slot_onvifCameraFindRun()
{
start();
}
Debugger encountered an exception: Exception at 0x7ff742129753, code: 0xc0000005: read access violation at: 0xb8, flags=0x0 (first chance)else
{ a = (tt__AnalyticsEngineInput *)soap_id_forward(soap, soap->href, (void*)a, 0, SOAP_TYPE_tt__AnalyticsEngineInput, SOAP_TYPE_tt__AnalyticsEngineInput, sizeof(tt__AnalyticsEngineInput), 0, soap_finsert, soap_fbase);
if (soap->body && soap_element_end_in(soap, tag))
return NULL;
}
return a;
}
最新发布