2025-03-17 13:44:44 +08:00
|
|
|
|
#include "CCamInfo.h"
|
2025-03-14 17:05:48 +08:00
|
|
|
|
#include "OnvifLibs/onvif.h"
|
|
|
|
|
|
#include <QString>
|
|
|
|
|
|
#include "CPresetInfo.h"
|
|
|
|
|
|
#include <pub_logger_api/logger.h>
|
|
|
|
|
|
CCamInfo::CCamInfo()
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
std::string CCamInfo::pointTag() const
|
|
|
|
|
|
{
|
|
|
|
|
|
return m_pointTag;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CCamInfo::setPointTag(const std::string &pointTag)
|
|
|
|
|
|
{
|
|
|
|
|
|
m_pointTag = pointTag;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
std::string CCamInfo::camTag() const
|
|
|
|
|
|
{
|
|
|
|
|
|
return m_camTag;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CCamInfo::setCamTag(const std::string &camTag)
|
|
|
|
|
|
{
|
|
|
|
|
|
m_camTag = camTag;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
std::string CCamInfo::presetTag() const
|
|
|
|
|
|
{
|
|
|
|
|
|
return m_presetTag;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CCamInfo::setPresetTag(const std::string &presetTag)
|
|
|
|
|
|
{
|
|
|
|
|
|
m_presetTag = presetTag;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
std::string CCamInfo::ip() const
|
|
|
|
|
|
{
|
|
|
|
|
|
return m_ip;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CCamInfo::setIp(const std::string &ip)
|
|
|
|
|
|
{
|
|
|
|
|
|
m_ip = ip;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
std::string CCamInfo::description() const
|
|
|
|
|
|
{
|
|
|
|
|
|
return m_description;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CCamInfo::setDescription(const std::string &description)
|
|
|
|
|
|
{
|
|
|
|
|
|
m_description = description;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
std::string CCamInfo::username() const
|
|
|
|
|
|
{
|
|
|
|
|
|
return m_username;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CCamInfo::setUsername(const std::string &username)
|
|
|
|
|
|
{
|
|
|
|
|
|
m_username = username;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
std::string CCamInfo::password() const
|
|
|
|
|
|
{
|
|
|
|
|
|
return m_password;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CCamInfo::setPassword(const std::string &password)
|
|
|
|
|
|
{
|
|
|
|
|
|
m_password = password;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
std::string CCamInfo::serviceAddr() const
|
|
|
|
|
|
{
|
|
|
|
|
|
return m_serviceAddr;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CCamInfo::setServiceAddr(const std::string &serviceAddr)
|
|
|
|
|
|
{
|
|
|
|
|
|
m_serviceAddr = serviceAddr;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
std::string CCamInfo::mediaAddr() const
|
|
|
|
|
|
{
|
|
|
|
|
|
return m_mediaAddr;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CCamInfo::setMediaAddr(const std::string &mediaAddr)
|
|
|
|
|
|
{
|
|
|
|
|
|
m_mediaAddr = mediaAddr;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
std::string CCamInfo::ptzAddr() const
|
|
|
|
|
|
{
|
|
|
|
|
|
return m_ptzAddr;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CCamInfo::setPtzAddr(const std::string &ptzAddr)
|
|
|
|
|
|
{
|
|
|
|
|
|
m_ptzAddr = ptzAddr;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
std::string CCamInfo::recordSearchAddr() const
|
|
|
|
|
|
{
|
|
|
|
|
|
return m_recordSearchAddr;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CCamInfo::setRecordSearchAddr(const std::string &recordSearchAddr)
|
|
|
|
|
|
{
|
|
|
|
|
|
m_recordSearchAddr = recordSearchAddr;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
std::string CCamInfo::replayAddr() const
|
|
|
|
|
|
{
|
|
|
|
|
|
return m_replayAddr;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CCamInfo::setReplayAddr(const std::string &replayAddr)
|
|
|
|
|
|
{
|
|
|
|
|
|
m_replayAddr = replayAddr;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool CCamInfo::isStreamEnabled() const
|
|
|
|
|
|
{
|
|
|
|
|
|
return m_isStreamEnabled;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CCamInfo::setIsStreamEnabled(bool isStreamEnabled)
|
|
|
|
|
|
{
|
|
|
|
|
|
m_isStreamEnabled = isStreamEnabled;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool CCamInfo::isPtzEnabled() const
|
|
|
|
|
|
{
|
|
|
|
|
|
return m_isPtzEnabled;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CCamInfo::setIsPtzEnabled(bool isPtzEnabled)
|
|
|
|
|
|
{
|
|
|
|
|
|
m_isPtzEnabled = isPtzEnabled;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool CCamInfo::isReplayEnabled() const
|
|
|
|
|
|
{
|
|
|
|
|
|
return m_isReplayEnabled;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CCamInfo::setIsReplayEnabled(bool isReplayEnabled)
|
|
|
|
|
|
{
|
|
|
|
|
|
m_isReplayEnabled = isReplayEnabled;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
std::vector<CPresetInfo> CCamInfo::presets() const
|
|
|
|
|
|
{
|
|
|
|
|
|
return m_presets;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CCamInfo::setPresets(const std::vector<CPresetInfo> &presets)
|
|
|
|
|
|
{
|
|
|
|
|
|
m_presets = presets;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CCamInfo::addPreset(const std::string &presetTag_, const std::string &presetToken_, const std::string &presetDesc_)
|
|
|
|
|
|
{
|
|
|
|
|
|
m_presets.push_back(CPresetInfo(presetTag_,presetToken_,presetDesc_));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool CCamInfo::getPresetDesc(const std::string &preset_tag, std::string &outDesc)
|
|
|
|
|
|
{
|
|
|
|
|
|
for(int i = 0; i < (int)m_presets.size(); i++)
|
|
|
|
|
|
{
|
|
|
|
|
|
if(m_presets.at(i).presetTag == preset_tag)
|
|
|
|
|
|
{
|
|
|
|
|
|
outDesc = m_presets.at(i).presetDesc;
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool CCamInfo::getPresetToken(const std::string &preset_tag, std::string &outToken)
|
|
|
|
|
|
{
|
|
|
|
|
|
for(int i = 0; i < (int)m_presets.size(); i++)
|
|
|
|
|
|
{
|
|
|
|
|
|
if(m_presets.at(i).presetTag == preset_tag)
|
|
|
|
|
|
{
|
|
|
|
|
|
outToken = m_presets.at(i).presetToken;
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int CCamInfo::getChan_no() const
|
|
|
|
|
|
{
|
|
|
|
|
|
return m_chan_no;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CCamInfo::setChan_no(int chan_no)
|
|
|
|
|
|
{
|
|
|
|
|
|
m_chan_no = chan_no;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int CCamInfo::getOnvifArgs()
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/***
|
|
|
|
|
|
* 大概想一下,应该做什么。
|
|
|
|
|
|
* 最终目的,填充streamRtspAddr(直播用)和replayRtspAddr(回放用)和profileToken(ptz用,搭配ptzxaddr) 和能力使能
|
|
|
|
|
|
* 1. 生成onvif的device_address
|
|
|
|
|
|
* 2. 获取能力 capabilities,根据能力填充使能信息
|
|
|
|
|
|
* 若MediaXAddr为空,则无法直播
|
|
|
|
|
|
* 若PTZXAddr为空,则无法进行ptz控制
|
|
|
|
|
|
* 若SearchXAddr和ReplayXAddr有一为空,则无法进行回放
|
|
|
|
|
|
* 3. 填充直播相关的东西
|
|
|
|
|
|
* 3.1 获取profile
|
|
|
|
|
|
* 3.2 获取直播地址
|
|
|
|
|
|
* 4. 获取录播相关的东西
|
|
|
|
|
|
* 4.1 获取录播recordingtoken
|
|
|
|
|
|
* 4.2 获取回放地址
|
|
|
|
|
|
*
|
|
|
|
|
|
*
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
LOGINFO("In getOnvifArgs() start getCapabilities");
|
|
|
|
|
|
std::string service_addr = std::string("http://") + this->ip() + "/onvif/device_service";
|
|
|
|
|
|
this->setServiceAddr(service_addr);
|
|
|
|
|
|
|
|
|
|
|
|
//=============能力相关=================
|
|
|
|
|
|
XAddr addr;
|
|
|
|
|
|
int result = 0;
|
|
|
|
|
|
result =Onvif::getCapabilities(service_addr,addr);
|
|
|
|
|
|
|
|
|
|
|
|
if(addr.MediaXAddr == "")
|
|
|
|
|
|
{
|
|
|
|
|
|
this->setIsStreamEnabled(false);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if(addr.PTZXAddr == "")
|
|
|
|
|
|
{
|
|
|
|
|
|
this->setIsPtzEnabled(false);
|
|
|
|
|
|
}
|
|
|
|
|
|
this->setPtzAddr(addr.PTZXAddr);
|
|
|
|
|
|
|
|
|
|
|
|
if(addr.ReplayXAddr == "" || addr.SearchXAddr == "")
|
|
|
|
|
|
{
|
|
|
|
|
|
this->setIsReplayEnabled(false);
|
|
|
|
|
|
}
|
|
|
|
|
|
//=============能力相关=================
|
|
|
|
|
|
|
|
|
|
|
|
LOGINFO("In getOnvifArgs() start getStreamInfo");
|
|
|
|
|
|
//=============直播相关====================
|
|
|
|
|
|
if(addr.MediaXAddr != "")
|
|
|
|
|
|
{
|
|
|
|
|
|
if(Onvif::getProfileTokens(addr.MediaXAddr,this->getChan_no(),this->username(),this->password(),this->m_mediaProfileToken) != Onvif::NoError)
|
|
|
|
|
|
{
|
|
|
|
|
|
this->setIsStreamEnabled(false);
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
if(Onvif::getStreamUrl(addr.MediaXAddr,this->m_mediaProfileToken,this->username(),this->password(),this->m_streamRtspAddr) != Onvif::NoError)
|
|
|
|
|
|
{
|
|
|
|
|
|
this->setIsStreamEnabled(false);
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
this->m_streamRtspAddr = this->m_streamRtspAddr.substr(0,7) + this->username() + ":" + this->password() + "@" + this->m_streamRtspAddr.substr(7);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
//=============直播相关====================
|
|
|
|
|
|
|
|
|
|
|
|
LOGINFO("In getOnvifArgs() start getReplayInfo");
|
|
|
|
|
|
//=============回放相关====================
|
|
|
|
|
|
|
|
|
|
|
|
if(addr.ReplayXAddr != "" && addr.SearchXAddr != "")
|
|
|
|
|
|
{
|
|
|
|
|
|
if(Onvif::getRecordToken(addr.SearchXAddr,this->getChan_no(),this->username(),this->password(),this->m_recordToken) != Onvif::NoError)
|
|
|
|
|
|
{
|
|
|
|
|
|
this->setIsReplayEnabled(false);
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
if(Onvif::getReplayUrl(addr.ReplayXAddr,this->m_recordToken,this->username(),this->password(),this->m_replayRtspAddr) != Onvif::NoError)
|
|
|
|
|
|
{
|
|
|
|
|
|
this->setIsReplayEnabled(false);
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
this->m_replayRtspAddr = this->m_replayRtspAddr.substr(0,7) + this->username() + ":" + this->password() + "@" +this->m_replayRtspAddr.substr(7);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
//=============回放相关====================
|
|
|
|
|
|
return result;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
std::string CCamInfo::getStreamRtspAddr() const
|
|
|
|
|
|
{
|
|
|
|
|
|
return m_streamRtspAddr;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
std::string CCamInfo::getReplayRtspAddr() const
|
|
|
|
|
|
{
|
|
|
|
|
|
return m_replayRtspAddr;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool CCamInfo::continuousMove(int cmd, double cmd_speed)
|
|
|
|
|
|
{
|
|
|
|
|
|
if(!m_isPtzEnabled)
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
|
|
if(Onvif::continuousMove(this->ptzAddr(),this->m_mediaProfileToken,this->username(),this->password(),cmd,cmd_speed) == -1)
|
|
|
|
|
|
{
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool CCamInfo::stopMove()
|
|
|
|
|
|
{
|
|
|
|
|
|
if(!m_isPtzEnabled)
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
|
|
if(Onvif::stopMove(this->ptzAddr(),this->m_mediaProfileToken,this->username(),this->password()) == -1)
|
|
|
|
|
|
{
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool CCamInfo::gotoPreset(const std::string &preset_tag)
|
|
|
|
|
|
{
|
|
|
|
|
|
if(!m_isPtzEnabled)
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
|
|
std::string preset_token;
|
|
|
|
|
|
if(!getPresetToken(preset_tag,preset_token))
|
|
|
|
|
|
return false;
|
|
|
|
|
|
if(Onvif::gotoPreset(this->ptzAddr(),this->m_mediaProfileToken,preset_token,this->username(),this->password()) == -1)
|
|
|
|
|
|
{
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|