Onvif OSD相关配置
jluyeyu | 发布于 2018-07-16 16:55:56 | 阅读量 1952 | onvif
与OSD有关的命令有:CreateOSD、DeleteOSD、GetOSDs、GetOSD、SetOSD、GetOSDOptions。下面逐一介绍。
GetOSDOptions:获取当前相机具备的OSD选项。如字体大小范围、OSD总数、日期时间格式,等等。
输入:ConfigurationToken [ReferenceToken]
输出:
MaximumNumberOfOSDs 最大OSD数目
Total 总共几个
PlainText [int] Text类型数目
Image [int] 图像类型数目
DateAndTime [int] 时间日期类型数目
Type 支持的类型
‘文字'
'图片'
'扩展
PositionOption 位置
UpperLeft 左上
UpperRight 右上
LowerLeft 左下
LowerRight 右下
Custom 自定义
FontSizeRange 字体大小值的范围。
DateFormat 支持的日期格式列表。
TimeFormat 支持的时间格式列表
FontColor 支持的字体颜色列表。
等
获取ConfigurationToken
/**
* @explan: 获取VideoSourceToken
* @param: const char * mediaAddr media地址
* @param: std::string & videoSourceToken 用于存放VideoSourceToken的字符串
* @return: int
* success return 0
*/
int COvifClient::GetVideoSourceToken(const char* mediaAddr, std::string& videoSourceToken)
{
MediaBindingProxy* pMedia = new MediaBindingProxy();
int result = soap_wsse_add_UsernameTokenDigest(pMedia->soap, NULL, USERNAME, PASSWORD); ///< 启动鉴权
if (SOAP_OK != result)
{
printf_s("soap_wsse_add_UsernameTokenDigest. User:[%s] PASSWORD:[%s]\n", USERNAME, PASSWORD);
return -1;
}
_trt__GetProfiles Profiles_req;
_trt__GetProfilesResponse Profiles_rep;
result = pMedia->GetProfiles(mediaAddr, NULL, &Profiles_req, Profiles_rep);
if (SOAP_OK != result)
{
printf_s("GetProfiles error.\n");
return -1;
}
///< 可能会有好几路流,相应的也会有好几个profile,这里只取第一路码流
videoSourceToken = Profiles_rep.Profiles[0]->VideoSourceConfiguration->token;
return SOAP_OK;
}
/**
* @explan: 显示OSD设置项
* @param: const char * deviceAddr 设备地址
* @return: int
* success return 0
*/
int COvifClient::ShowOSDOpinion(const char* deviceAddr)
{
if (deviceAddr == nullptr)
{
printf_s("deviceAddr == nullptr\n");
return -1;
}
///< 获得Media模块服务地址
std::string mediaAddr;
int result = this->GetMediaAddr(deviceAddr, mediaAddr);
if (SOAP_OK != result)
{
printf_s("GetMediaAddr error.\n");
return -1;
}
MediaBindingProxy* pMedia = new MediaBindingProxy();
result = soap_wsse_add_UsernameTokenDigest(pMedia->soap, NULL, USERNAME, PASSWORD); ///< 启动鉴权
if (SOAP_OK != result)
{
printf_s("soap_wsse_add_UsernameTokenDigest. User:[%s] PASSWORD:[%s]\n", USERNAME, PASSWORD);
return -1;
}
std::string profileToken;
result = GetProfilesToken(mediaAddr.c_str(), profileToken);
if (result != SOAP_OK){
cout << "Get profileToken 失败";
return -1;
}
std::string videoSourceToken;
GetVideoSourceToken(mediaAddr.c_str(), videoSourceToken);
_trt__GetOSDOptions getOptions_req;
_trt__GetOSDOptionsResponse getOptions_rep;
getOptions_req.ConfigurationToken = videoSourceToken;
result=pMedia->GetOSDOptions(mediaAddr.c_str(), NULL, &getOptions_req, getOptions_rep);
if (result != SOAP_OK){
cout << "获取OSD OPinion 失败"<<endl;
showErrorReason(pMedia->soap);
return -1;
}
cout <<"支持Text数目:"<< *getOptions_rep.OSDOptions->MaximumNumberOfOSDs->PlainText<<endl;
cout <<"支持日期时间数目:" << *getOptions_rep.OSDOptions->MaximumNumberOfOSDs->DateAndTime << endl;
return 0;
}
Total 总共几个
Total 总共几个
GetOSDs:
获取当前相机所有OSD项目。包括OSDtoken、叠加类型、字体大小、字体颜色、字体空间、背景颜色,等。
注意,使用这个接口时,必须传入视频源配置token(VideoSourceConfigurationToken)。每个视频源配置都有对应的OSD。比如相机有3路视频输出,则每路都可以叠加独立的字符,不互相干扰。返回值是一个vector,每个元素都是一个叠加的字符及其属性。
输入:token(VideoSourceConfigurationToken)
输出
OSDs 包含的OSD列表
OSDtoken 可以根据这个,修改/删除OSD
OSD字体大小、字体颜色、字体空间、背景颜色等
/**
* @explan: 根据Media地址,获取OSD Token list
* @param: const char * mediaAddr
* @param: std::string OSDList[] OSD Token list
* @return: int
* success return 0
*/
int COvifClient::GetOSDs(const char* mediaAddr, std::string OSDList[])
{
MediaBindingProxy* pMedia = new MediaBindingProxy();
int result = soap_wsse_add_UsernameTokenDigest(pMedia->soap, NULL, USERNAME, PASSWORD); ///< 启动鉴权
if (SOAP_OK != result)
{
printf_s("soap_wsse_add_UsernameTokenDigest. User:[%s] PASSWORD:[%s]\n", USERNAME, PASSWORD);
return -1;
}
std::string profileToken;
result = GetProfilesToken(mediaAddr, profileToken);
if (result != SOAP_OK){
cout << "Get profileToken 失败";
return -1;
}
std::string videoSourceToken;
GetVideoSourceToken(mediaAddr, videoSourceToken);
_trt__GetOSDs OSD_req;
_trt__GetOSDsResponse OSD_rep;
OSD_req.ConfigurationToken = &videoSourceToken;
result=pMedia->GetOSDs(mediaAddr, NULL, &OSD_req, OSD_rep);
if (result != SOAP_OK){
cout << "获取OSD失败 ";
showErrorReason(pMedia->soap);
}
int temp = 0;
for (auto x : OSD_rep.OSDs){
OSDList[temp++] = x->token;
cout << "第" << temp << "个OSD Token 是" << x->token << endl;
if (x->TextString->PlainText != NULL){
std::string text = *x->TextString->PlainText;
cout << text << endl;
}
}
return 0;
}
GetOSD:
基本同getOSDs。但传入参数是OSDtoken,而不是视频源配置token。
CreateOSD:
创建OSD,成功后会返回设备上标识的OSD token。创建的OSD属性参考上面所述,一般设备会有自己OSD的管理机制,比如固定的token:osd_0、osd_1、osd_2,等等,如果已经存在osd_0、osd_2时,则该命令创建时,会返回osd_1。
/**
* @explan: 创建OSD
* @param: const char * mediaAddr Media地址
* @param: std::string & OSDToken 返回一个OSD token
* @return: int
* success return 0
*/
int COvifClient::CreateOSD(const char* mediaAddr, std::string& OSDToken)
{
MediaBindingProxy* pMedia = new MediaBindingProxy();
int result = soap_wsse_add_UsernameTokenDigest(pMedia->soap, NULL, USERNAME, PASSWORD); ///< 启动鉴权
if (SOAP_OK != result)
{
printf_s("soap_wsse_add_UsernameTokenDigest. User:[%s] PASSWORD:[%s]\n", USERNAME, PASSWORD);
return -1;
}
std::string profileToken;
result=GetProfilesToken(mediaAddr, profileToken);
if (result != SOAP_OK){
cout << "Get profileToken 失败"<<endl;
return -1;
}
std::string videoSourceToken;
GetVideoSourceToken(mediaAddr, videoSourceToken);
_trt__GetVideoSourceConfiguration VideoConf_req;
_trt__GetVideoSourceConfigurationResponse VideoConf_rep;
VideoConf_req.ConfigurationToken = videoSourceToken;
result = pMedia->GetVideoSourceConfiguration(mediaAddr,NULL,&VideoConf_req, VideoConf_rep);
if (result != SOAP_OK){
cout << "Get VideoSourceConfiguration 失败"<<endl;
return -1;
}
result = soap_wsse_add_UsernameTokenDigest(pMedia->soap, NULL, USERNAME, PASSWORD); ///< 启动鉴权
if (SOAP_OK != result)
{
printf_s("soap_wsse_add_UsernameTokenDigest. User:[%s] PASSWORD:[%s]\n", USERNAME, PASSWORD);
return -1;
}
_trt__CreateOSD creOSD_req;
_trt__CreateOSDResponse creOSD_rep;
tt__OSDConfiguration OSD;
OSD.token = profileToken;
tt__OSDPosConfiguration Position;
std::string Postype = "Custom";
OSD.Type = tt__OSDType__Text;
//自定义,需要自己设置
Position.Type = Postype;
OSD.Position = &Position;
tt__OSDReference VideoSourceConfigurationToken;
VideoSourceConfigurationToken.__item = VideoConf_rep.Configuration->token;
OSD.VideoSourceConfigurationToken = &VideoSourceConfigurationToken;
creOSD_req.OSD = &OSD;
result = pMedia->CreateOSD(mediaAddr, NULL, &creOSD_req, creOSD_rep);
if (result != SOAP_OK){
cout << "Greate OSD 失败"<<endl;
showErrorReason(pMedia->soap);
return -1;
}
cout <<"OSDToken为:"<< creOSD_rep.OSDToken << endl;
OSDToken = creOSD_rep.OSDToken;
return 0;
}
SetOSD:
设置OSD。与CreateOSD基本一样,但该命令使用的是相机已经存在的OSDtoken。因为这个命令描述为“修改OSD”更妥当一些。
/**
* @explan: 根据OSDtoken 设置OSD
* @param: const char * mediaAddr
* @param: const char * OSDToken
* @return: int
* success return 0
*/
int COvifClient::SetOSD(const char* mediaAddr,const char* OSDToken)
{
MediaBindingProxy* pMedia = new MediaBindingProxy();
int result = soap_wsse_add_UsernameTokenDigest(pMedia->soap, NULL, USERNAME, PASSWORD); ///< 启动鉴权
if (SOAP_OK != result)
{
printf_s("soap_wsse_add_UsernameTokenDigest. User:[%s] PASSWORD:[%s]\n", USERNAME, PASSWORD);
return -1;
}
std::string profileToken;
result = GetProfilesToken(mediaAddr, profileToken);
if (result != SOAP_OK){
return -1;
}
std::string videoSourceToken;
GetVideoSourceToken(mediaAddr, videoSourceToken);
_trt__SetOSD setOSD_req;
_trt__SetOSDResponse setOSD_rep;
tt__OSDConfiguration OSD;
//设置Token
OSD.token = OSDToken;
//设置OSD的类型
OSD.Type = tt__OSDType__Text; //Text/image/exten
//设置OSD位置(自定义)
tt__OSDPosConfiguration Position;
std::string Postype = "Custom";
Position.Type = Postype;
tt__OSDTextConfiguration TextConf;
std::string Text = "test";
TextConf.PlainText = &Text;
int fontSize = 25;
TextConf.FontSize =&fontSize ;
tt__Vector pos;
//float x = 0;
//float y = 0;
//pos.x = &x;
//pos.y = &y;
//Position.Pos = &pos;
OSD.TextString = &TextConf;
//设置Position与OSD关联
OSD.Position = &Position;
//设置VideoToken
tt__OSDReference VideoSourceConfigurationToken;
VideoSourceConfigurationToken.__item = videoSourceToken;
OSD.VideoSourceConfigurationToken = &VideoSourceConfigurationToken;
setOSD_req.OSD = &OSD;
result=pMedia->SetOSD(mediaAddr, NULL, &setOSD_req, setOSD_rep);
if (result != SOAP_OK){
cout << "设置OSD Opinion 失败" << endl;
showErrorReason(pMedia->soap);
return -1;
}
}
DeleteOSD:
删除OSD,传入的OSDToken是相机已经存在的。
/**
* @explan: 根据OSD token删除一个OSD
* @param: const char * mediaAddr media地址
* @param: std::string OSDToken OSD token
* @return: int
* success return 0
*/
int COvifClient::DelectOSD(const char* mediaAddr, std::string OSDToken)
{
MediaBindingProxy* pMedia = new MediaBindingProxy();
int result = soap_wsse_add_UsernameTokenDigest(pMedia->soap, NULL, USERNAME, PASSWORD); ///< 启动鉴权
if (SOAP_OK != result)
{
printf_s("soap_wsse_add_UsernameTokenDigest. User:[%s] PASSWORD:[%s]\n", USERNAME, PASSWORD);
return -1;
}
_trt__DeleteOSD DeleteOSD_req;
_trt__DeleteOSDResponse DeleteOSD_rep;
DeleteOSD_req.OSDToken = OSDToken;
result = pMedia->DeleteOSD(mediaAddr, NULL, &DeleteOSD_req, DeleteOSD_rep);
if (result != SOAP_OK){
cout << "删除OSD失败"<<endl;
showErrorReason(pMedia->soap);
return -1;
}
return 0;
}