前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Jetson Nano 使用gSOAP生成ONVIF框架代码及动态库 -- 3 ONVIF 动态库生成

Jetson Nano 使用gSOAP生成ONVIF框架代码及动态库 -- 3 ONVIF 动态库生成

原创
作者头像
DN
修改2020-07-06 10:52:16
1.9K0
修改2020-07-06 10:52:16
举报
文章被收录于专栏:JETSON NANO AI

3.1  其他相关源码拷贝

使用cd /opt/gsoap-2.8/gsoap/命令,进入gsoap目录。

使用sudo cp dom.c samples/onvif/命令,拷贝dom.c文件

使用sudo cp stdsoap2.c stdsoap2.h samples/onvif/,将soap标准文件进行拷贝。

使用sudo cp custom/duration.c custom/duration.h samples/onvif命令拷贝

使用sudo cp custom/struct_timeval.c custom/struct_timeval.h samples/onvif/命令拷贝

使用sudo cp plugin/mecevp.c plugin/mecevp.h plugin/smdevp.c plugin/smdevp.h plugin/threads.c plugin/threads.h plugin/wsaapi.c plugin/wsaapi.h plugin/wsseapi.c plugin/wsseapi.h samples/onvif/命令拷贝

拷贝完成后,onvif目录下存在如下图所示的文件内容:

3.2  生成动态库

使用cd /opt/gsoap-2.8/gsoap/samples/onvif/

使用sudo gcc -D WITH_OPENSSL -D WITH_NOEMPTYSTRUCT -D SOAP_DEBUG -fpic -shared -lpthread -ldl -lm stdsoap2.c soapC.c soapClient.c wsaapi.c wsseapi.c smdevp.c mecevp.c threads.c dom.c duration.c struct_timeval.c -Wall -o libonvif_c.so命令,生成libonvif_c.so动态库,执行结果如下图所示:

备注,该编译生成过程需要几分钟时间,请耐心等待。过程中存在一些警告提示,可以忽略。

编译完成后,会在当前目录下生成libonvif_c.so动态库文件。

3.3  调试动态库

生成动态库的最终目的是期望可以在其他没有安装相应工具的Jeston Nano系统上直接调用,所以在开始这一章节操作说明前,先制作一张只带官方提供的镜像系统的SD卡,并将其插入Nano核心板上进行配置,最终就开始进行动态库的调试。

3.3.1  编写应用

应用接口主要是参考网上并结合自己的理解整理出来测试的,在此只用于验证动态库的可用性,在正式产品中需要根据需求进行接口开发。 #include <stdio.h>

#include <stdlib.h>

#include <assert.h>

#include "soapH.h"

#include "wsaapi.h"

#include "wsseapi.h"

#include "wsdd.nsmap"

#define SOAP_ASSERT assert

#define SOAP_DBGLOG printf

#define SOAP_DBGERR printf

#define SOAP_TO "urn:schemas-xmlsoap-org:ws:2005:04:discovery"

#define SOAP_ACTION "http://schemas.xmlsoap.org/ws/2005/04/discovery/Probe"

#define SOAP_MCAST_ADDR "soap.udp://239.255.255.250:3702" // onvif规定的组播地址

#define SOAP_ITEM "" // 寻找的设备范围

#define SOAP_TYPES "dn:NetworkVideoTransmitter" // 寻找的设备类型

#define USERNAME "admin"

#define PASSWORD "xmrbi3967968"

char username[16] = "admin";

char password[16] = "xmrbi3967968";

char VideoSourceToken[32] = {0};

char EncoderToken[32] = {0};

#define SOAP_SOCK_TIMEOUT (10) // socket超时时间(单秒秒)

#define SOAP_CHECK_ERROR(result, soap, str) \

do { \

if (SOAP_OK != (result) || SOAP_OK != (soap)->error) { \

soap_perror((soap), (str)); \

if (SOAP_OK == (result)) { \

(result) = (soap)->error; \

} \

goto EXIT; \

} \

} while (0)

void soap_perror(struct soap *soap, const char *str)

{

if (NULL == 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));

}

return;

}

void* ONVIF_soap_malloc(struct soap *soap, unsigned int n)

{

void *p = NULL;

if (n > 0) {

p = soap_malloc(soap, n);

SOAP_ASSERT(NULL != p);

memset(p, 0x00 ,n);

}

return p;

}

struct soap *ONVIF_soap_new(int timeout)

{

struct soap *soap = NULL; // soap环境变量

SOAP_ASSERT(NULL != (soap = soap_new()));

soap_set_namespaces(soap, namespaces); // 设置soap的namespaces

soap->recv_timeout = timeout; // 设置超时(超过指定时间没有数据就退出)

soap->send_timeout = timeout;

soap->connect_timeout = timeout;

#if defined(__linux__) || defined(__linux) // 参考https://www.genivia.com/dev.html#client-c的修改:

soap->socket_flags = MSG_NOSIGNAL; // To prevent connection reset errors

#endif

soap_set_mode(soap, SOAP_C_UTFSTRING); // 设置为UTF-8编码,否则叠加中文OSD会乱码

return soap;

}

void ONVIF_soap_delete(struct soap *soap)

{

soap_destroy(soap); // remove deserialized class instances (C++ only)

soap_end(soap); // Clean up deserialized data (except class instances) and temporary data

soap_done(soap); // Reset, close communications, and remove callbacks

soap_free(soap); // Reset and deallocate the context created with soap_new or soap_copy

}

/************************************************************************

**函数:ONVIF_init_heade

**功能:初始化soap描述消息头

**参数:

[in] soap - soap环境变量

**返回:无

**备注:

1). 在本函数内部通过ONVIF_soap_malloc分配的内存,将在ONVIF_soap_delete中被释放

************************************************************************/

void ONVIF_init_header(struct soap *soap)

{

struct SOAP_ENV__Header *header = NULL;

SOAP_ASSERT(NULL != 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;

}

/************************************************************************

**函数:ONVIF_init_ProbeType

**功能:初始化探测设备的范围和类型

**参数:

[in] soap - soap环境变量

[out] probe - 填充要探测的设备范围和类型

**返回:

0表明探测到,非0表明未探测到

**备注:

1). 在本函数内部通过ONVIF_soap_malloc分配的内存,将在ONVIF_soap_delete中被释放

************************************************************************/

void ONVIF_init_ProbeType(struct soap *soap, struct wsdd__ProbeType *probe)

{

struct wsdd__ScopesType *scope = NULL; // 用于描述查找哪类的Web服务

SOAP_ASSERT(NULL != soap);

SOAP_ASSERT(NULL != probe);

scope = (struct wsdd__ScopesType *)ONVIF_soap_malloc(soap, sizeof(struct wsdd__ScopesType));

soap_default_wsdd__ScopesType(soap, scope); // 设置寻找设备的范围

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); // 设置寻找设备的类型

strcpy(probe->Types, SOAP_TYPES);

return;

}

/************************************************************************

**函数:ONVIF_SetAuthInfo

**功能:设置认证信息

**参数:

[in] soap - soap环境变量

[in] username - 用户名

[in] password - 密码

**返回:

0表明成功,非0表明失败

**备注:

************************************************************************/

static int ONVIF_SetAuthInfo(struct soap *soap, const char *username, const char *password)

{

int result = 0;

SOAP_ASSERT(NULL != username);

SOAP_ASSERT(NULL != password);

result = soap_wsse_add_UsernameTokenDigest(soap, NULL, username, password);

SOAP_CHECK_ERROR(result, soap, "add_UsernameTokenDigest");

EXIT:

return result;

}

void ONVIF_DetectDevice(void (*cb)(char *DeviceXAddr))

{

int i;

int result = 0;

unsigned int count = 0; // 搜索到的设备个数

struct soap *soap = NULL; // soap环境变量

struct wsdd__ProbeType req; // 用于发送Probe消息

struct __wsdd__ProbeMatches rep; // 用于接收Probe应答

struct wsdd__ProbeMatchType *probeMatch;

SOAP_ASSERT(NULL != (soap = ONVIF_soap_new(SOAP_SOCK_TIMEOUT)));

ONVIF_init_header(soap); // 设置消息头描述

ONVIF_init_ProbeType(soap, &req); // 设置寻找的设备的范围和类型

result = soap_send___wsdd__Probe(soap, SOAP_MCAST_ADDR, NULL, &req); // 向组播地址广播Probe消息

while (SOAP_OK == result) // 开始循环接收设备发送过来的消息

{

memset(&rep, 0x00, sizeof(rep));

result = soap_recv___wsdd__ProbeMatches(soap, &rep);

if (SOAP_OK == result) {

printf("soap_recv___wsdd__ProbeMatches OK!\n");

if (soap->error) {

soap_perror(soap, "ProbeMatches");

} else { // 成功接收到设备的应答消息

printf("__sizeProbeMatch:%d\n",rep.wsdd__ProbeMatches->__sizeProbeMatch);

printf("Types : %s\n", rep.wsdd__ProbeMatches->ProbeMatch->Types);

printf("XAddrs : %s\n", rep.wsdd__ProbeMatches->ProbeMatch->XAddrs);

//dump__wsdd__ProbeMatches(&rep);

if (NULL != rep.wsdd__ProbeMatches) {

count += rep.wsdd__ProbeMatches->__sizeProbeMatch;

for(i = 0; i < rep.wsdd__ProbeMatches->__sizeProbeMatch; i++) {

probeMatch = rep.wsdd__ProbeMatches->ProbeMatch + i;

if (NULL != cb) {

cb(probeMatch->XAddrs); // 使用设备服务地址执行函数回调

}

}

}

else

printf("wsdd__ProbeMatches is NULL!\n");

}

} else if (soap->error) {

break;

}

}

SOAP_DBGLOG("\ndetect end! It has detected %d devices!\n", count);

if (NULL != soap) {

ONVIF_soap_delete(soap);

}

return ;

}

/************************************************************************

**函数:ONVIF_GetDeviceInformation

**功能:获取设备基本信息

**参数:

[in] DeviceXAddr - 设备服务地址

**返回:

0表明成功,非0表明失败

**备注:

************************************************************************/

int ONVIF_GetDeviceInformation(const char *DeviceXAddr)

{

int result = 0;

struct soap *soap = NULL;

struct _tds__GetDeviceInformation devinfo_req;

struct _tds__GetDeviceInformationResponse devinfo_resp;

SOAP_ASSERT(NULL != DeviceXAddr);

SOAP_ASSERT(NULL != (soap = ONVIF_soap_new(SOAP_SOCK_TIMEOUT)));

ONVIF_SetAuthInfo(soap, USERNAME, PASSWORD);

memset(&devinfo_req, 0x00, sizeof(devinfo_req));

memset(&devinfo_resp, 0x00, sizeof(devinfo_resp));

result = soap_call___tds__GetDeviceInformation(soap, DeviceXAddr, NULL, &devinfo_req, &devinfo_resp);

SOAP_CHECK_ERROR(result, soap, "GetDeviceInformation");

//dump_tds__GetDeviceInformationResponse(&devinfo_resp);

printf("\nGetDeviceInformation >>\n");

printf(" Manufacturer: %s\n", devinfo_resp.Manufacturer);

printf(" Model: %s\n", devinfo_resp.Model);

printf(" FirmwareVersion: %s\n", devinfo_resp.FirmwareVersion);

printf(" SerialNumber: %s\n", devinfo_resp.SerialNumber);

printf(" HardwareId: %s\n", devinfo_resp.HardwareId);

EXIT:

if (NULL != soap) {

ONVIF_soap_delete(soap);

}

return result;

}

/************************************************************************

**函数:ONVIF_GetCapabilities

**功能:获取设备能力信息

**参数:

[in] DeviceXAddr - 设备服务地址

**返回:

0表明成功,非0表明失败

**备注:

1). 其中最主要的参数之一是媒体服务地址

************************************************************************/

int ONVIF_GetCapabilities(const char *DeviceXAddr)

{

int result = 0;

struct soap *soap = NULL;

struct _tds__GetCapabilities req;

struct _tds__GetCapabilitiesResponse rep;

SOAP_ASSERT(NULL != DeviceXAddr);

SOAP_ASSERT(NULL != (soap = ONVIF_soap_new(SOAP_SOCK_TIMEOUT)));

ONVIF_SetAuthInfo(soap, USERNAME, PASSWORD);

memset(&req, 0x00, sizeof(req));

memset(&rep, 0x00, sizeof(rep));

req.Category = tt__CapabilityCategory__Media;

result = soap_call___tds__GetCapabilities(soap, DeviceXAddr, NULL, &req, &rep); // question:

SOAP_CHECK_ERROR(result, soap, "GetCapabilities");

//dump_tds__GetCapabilitiesResponse(&rep);

printf("\nGetCapabilities >>\n");

printf(" Analytics\n");

printf(" XAddr : %s\n", rep.Capabilities->Analytics->XAddr);

printf(" RuleSupport : %d\n", rep.Capabilities->Analytics->RuleSupport);

printf(" AnalyticsModuleSupport : %d\n", rep.Capabilities->Analytics->AnalyticsModuleSupport);

printf(" Device\n");

printf(" XAddr : %s\n", rep.Capabilities->Device->XAddr);

printf(" Events\n");

printf(" XAddr : %s\n", rep.Capabilities->Events->XAddr);

printf(" Imaging\n");

printf(" XAddr : %s\n", rep.Capabilities->Imaging->XAddr);

printf(" Media\n");

printf(" XAddr : %s\n", rep.Capabilities->Media->XAddr);

printf(" PTZ");

if( rep.Capabilities->PTZ != NULL )

{

printf(": (0x%x)\n", rep.Capabilities->PTZ);

printf(" XAddr : %s\n", rep.Capabilities->PTZ->XAddr);

}

else

printf(": (null)\n");

printf(" Extension\n");

printf(" DeviceIO");

if( rep.Capabilities->Extension->DeviceIO != NULL )

{

printf(": (0x%x)\n", rep.Capabilities->Extension->DeviceIO);

printf(" XAddr : %s\n", rep.Capabilities->Extension->DeviceIO->XAddr);

}

else

printf(": (null)\n");

printf(" Display");

if( rep.Capabilities->Extension->Display != NULL )

{

printf(": (0x%x)\n", rep.Capabilities->Extension->Display);

printf(" XAddr : %s\n", rep.Capabilities->Extension->Display->XAddr);

}

else

printf(": (null)\n");

printf(" Recording");

if( rep.Capabilities->Extension->Recording != NULL )

{

printf(": (0x%x)\n", rep.Capabilities->Extension->Recording);

printf(" XAddr : %s\n", rep.Capabilities->Extension->Recording->XAddr);

}

else

printf(": (null)\n");

printf(" Search");

if( rep.Capabilities->Extension->Search != NULL )

{

printf(": (0x%x)\n", rep.Capabilities->Extension->Search);

printf(" XAddr : %s\n", rep.Capabilities->Extension->Search->XAddr);

}

else

printf(": (null)\n");

printf(" Replay");

if( rep.Capabilities->Extension->Replay != NULL )

{

printf(": (0x%x)\n", rep.Capabilities->Extension->Replay);

printf(" XAddr : %s\n", rep.Capabilities->Extension->Replay->XAddr);

}

else

printf(": (null)\n");

printf(" Receiver");

if( rep.Capabilities->Extension->Receiver != NULL )

{

printf(": (0x%x)\n", rep.Capabilities->Extension->Receiver);

printf(" XAddr : %s\n", rep.Capabilities->Extension->Receiver->XAddr);

}

else

printf(": (null)\n");

printf(" AnalyticsDevice");

if( rep.Capabilities->Extension->AnalyticsDevice != NULL )

{

printf(": (0x%x)\n", rep.Capabilities->Extension->AnalyticsDevice);

printf(" XAddr : %s\n", rep.Capabilities->Extension->AnalyticsDevice->XAddr);

}

else

printf(": (null)\n");

printf(" Extensions");

if( rep.Capabilities->Extension->Extensions != NULL )

{

printf(": (0x%x)\n", rep.Capabilities->Extension->Extensions);

}

else

printf(": (null)\n");

EXIT:

if (NULL != soap) {

ONVIF_soap_delete(soap);

}

return result;

}

int ONVIF_GetProfiles(const char *MediaXAddr)

{

int result = 0;

struct soap *soap = NULL;

struct _trt__GetProfiles Profiles_req;

struct _trt__GetProfilesResponse Profiles_rep;

SOAP_ASSERT(NULL != MediaXAddr);

SOAP_ASSERT(NULL != (soap = ONVIF_soap_new(SOAP_SOCK_TIMEOUT)));

ONVIF_SetAuthInfo(soap, USERNAME, PASSWORD);

result = soap_call___trt__GetProfiles(soap, MediaXAddr, NULL, &Profiles_req, &Profiles_rep);

SOAP_CHECK_ERROR(result, soap, "GetProfiles");

printf("\nGetProfiles >>\n");

printf(" __sizeProfiles: %d\n", Profiles_rep.__sizeProfiles);

printf(" Profiles: ");

if( Profiles_rep.Profiles != NULL )

{

printf(": (0x%x)\n", Profiles_rep.Profiles);

printf(" Name: %s\n", Profiles_rep.Profiles->Name);

printf(" VideoSourceConfiguration: ");

if( Profiles_rep.Profiles->VideoSourceConfiguration != NULL )

{

printf(": (0x%x)\n", Profiles_rep.Profiles->VideoSourceConfiguration);

printf(" Name: %s\n", Profiles_rep.Profiles->VideoSourceConfiguration->Name);

printf(" UseCount: %d\n", Profiles_rep.Profiles->VideoSourceConfiguration->UseCount);

printf(" token: %d\n", Profiles_rep.Profiles->VideoSourceConfiguration->token);

strcpy(VideoSourceToken, Profiles_rep.Profiles->VideoSourceConfiguration->SourceToken);

printf(" SourceToken: %d\n", Profiles_rep.Profiles->VideoSourceConfiguration->SourceToken);

}

else

printf(": (null)\n");

printf(" AudioSourceConfiguration: ");

if( Profiles_rep.Profiles->AudioSourceConfiguration != NULL )

{

printf(": (0x%x)\n", Profiles_rep.Profiles->AudioSourceConfiguration);

}

else

printf(": (null)\n");

printf(" VideoEncoderConfiguration: ");

if( Profiles_rep.Profiles->VideoEncoderConfiguration != NULL )

{

printf(": (0x%x)\n", Profiles_rep.Profiles->VideoEncoderConfiguration);

printf(" Name: %s\n", Profiles_rep.Profiles->VideoEncoderConfiguration->Name);

printf(" UseCount: %d\n", Profiles_rep.Profiles->VideoEncoderConfiguration->UseCount);

printf(" token: %s\n", Profiles_rep.Profiles->VideoEncoderConfiguration->token);

strcpy(EncoderToken, Profiles_rep.Profiles->VideoEncoderConfiguration->token);

printf(" Encoding: %d (JPEG = 0, MPEG4 = 1, H264 = 2)\n", Profiles_rep.Profiles->VideoEncoderConfiguration->Encoding);

printf(" Resolution: \n");

printf(" Width: %d, Height: %d\n", Profiles_rep.Profiles->VideoEncoderConfiguration->Resolution->Width, Profiles_rep.Profiles->VideoEncoderConfiguration->Resolution->Height);

printf(" Quality: %f\n", Profiles_rep.Profiles->VideoEncoderConfiguration->Quality);

printf(" RateControl: \n");

printf(" FrameRateLimit: %d\n", Profiles_rep.Profiles->VideoEncoderConfiguration->RateControl->FrameRateLimit);

printf(" EncodingInterval: %d\n", Profiles_rep.Profiles->VideoEncoderConfiguration->RateControl->EncodingInterval);

printf(" BitrateLimit: %d\n", Profiles_rep.Profiles->VideoEncoderConfiguration->RateControl->BitrateLimit);

printf(" GuaranteedFrameRate: %d\n", Profiles_rep.Profiles->VideoEncoderConfiguration->GuaranteedFrameRate);

}

else

printf(": (null)\n");

printf(" AudioEncoderConfiguration: ");

if( Profiles_rep.Profiles->AudioEncoderConfiguration != NULL )

{

printf(": (0x%x)\n", Profiles_rep.Profiles->AudioEncoderConfiguration);

}

else

printf(": (null)\n");

printf(" VideoAnalyticsConfiguration: ");

if( Profiles_rep.Profiles->VideoAnalyticsConfiguration != NULL )

{

printf(": (0x%x)\n", Profiles_rep.Profiles->VideoAnalyticsConfiguration);

}

else

printf(": (null)\n");

printf(" PTZConfiguration: ");

if( Profiles_rep.Profiles->PTZConfiguration != NULL )

{

printf(": (0x%x)\n", Profiles_rep.Profiles->PTZConfiguration);

}

else

printf(": (null)\n");

printf(" MetadataConfiguration: ");

if( Profiles_rep.Profiles->MetadataConfiguration != NULL )

{

printf(": (0x%x)\n", Profiles_rep.Profiles->MetadataConfiguration);

}

else

printf(": (null)\n");

printf(" token: %s\n", Profiles_rep.Profiles->token);

}

else

printf(": (null)\n");

EXIT:

if (NULL != soap) {

ONVIF_soap_delete(soap);

}

return result;

}

/************************************************************************

**函数:ONVIF_SetVideoEncoderConfiguration

**功能:修改指定的视频编码器配置信息

**参数:

[in] MediaXAddr - 媒体服务地址

[in] venc - 视频编码器配置信息

**返回:

0表明成功,非0表明失败

**备注:

1). 所设置的分辨率必须是GetVideoEncoderConfigurationOptions返回的“分辨率选项集”中的一种,否则调用SetVideoEncoderConfiguration会失败。

************************************************************************/

int ONVIF_SetVideoEncoderConfiguration(const char *MediaXAddr)

{

int result = 0;

struct soap *soap = NULL;

struct _trt__GetVideoEncoderConfiguration gVECfg_req;

struct _trt__GetVideoEncoderConfigurationResponse gVECfg_rep;

struct _trt__SetVideoEncoderConfiguration sVECfg_req;

struct _trt__SetVideoEncoderConfigurationResponse sVECfg_rep;

SOAP_ASSERT(NULL != MediaXAddr);

SOAP_ASSERT(NULL != (soap = ONVIF_soap_new(SOAP_SOCK_TIMEOUT)));

memset(&gVECfg_req, 0x00, sizeof(gVECfg_req));

memset(&gVECfg_rep, 0x00, sizeof(gVECfg_rep));

gVECfg_req.ConfigurationToken = EncoderToken;

ONVIF_SetAuthInfo(soap, USERNAME, PASSWORD);

result = soap_call___trt__GetVideoEncoderConfiguration(soap, MediaXAddr, NULL, &gVECfg_req, &gVECfg_rep);

SOAP_CHECK_ERROR(result, soap, "GetVideoEncoderConfiguration");

if (NULL == gVECfg_rep.Configuration) {

SOAP_DBGERR("video encoder configuration is NULL.\n");

goto EXIT;

}

memset(&sVECfg_req, 0x00, sizeof(sVECfg_req));

memset(&sVECfg_rep, 0x00, sizeof(sVECfg_rep));

sVECfg_req.ForcePersistence = xsd__boolean__true_;

sVECfg_req.Configuration = gVECfg_rep.Configuration;

if (NULL != sVECfg_req.Configuration->Resolution) {

sVECfg_req.Configuration->Resolution->Width = 1280;

sVECfg_req.Configuration->Resolution->Height = 960;

}

ONVIF_SetAuthInfo(soap, USERNAME, PASSWORD);

result = soap_call___trt__SetVideoEncoderConfiguration(soap, MediaXAddr, NULL, &sVECfg_req, &sVECfg_rep);

SOAP_CHECK_ERROR(result, soap, "SetVideoEncoderConfiguration");

EXIT:

if (SOAP_OK == result) {

SOAP_DBGLOG("\nSetVideoEncoderConfiguration success!!!\n");

}

if (NULL != soap) {

ONVIF_soap_delete(soap);

}

return result;

}

int ONVIF_SetImagingSettings(const char *ImagingXAddr)

{

int result = 0;

struct soap *soap = NULL;

struct _timg__GetImagingSettings gISets_req;

struct _timg__GetImagingSettingsResponse gISets_rep;

struct _timg__SetImagingSettings sISets_req;

struct _timg__SetImagingSettingsResponse sISets_rep;

enum xsd__boolean ForceStorage = xsd__boolean__true_;

float maxgain = 60;

SOAP_ASSERT(NULL != ImagingXAddr);

SOAP_ASSERT(NULL != (soap = ONVIF_soap_new(SOAP_SOCK_TIMEOUT)));

memset(&gISets_req, 0x00, sizeof(gISets_req));

memset(&gISets_rep, 0x00, sizeof(gISets_rep));

gISets_req.VideoSourceToken = VideoSourceToken;

ONVIF_SetAuthInfo(soap, USERNAME, PASSWORD);

result = soap_call___timg__GetImagingSettings(soap, ImagingXAddr, NULL, &gISets_req, &gISets_rep);

SOAP_CHECK_ERROR(result, soap, "GetImagingSettings");

if (NULL == gISets_rep.ImagingSettings) {

SOAP_DBGERR("video Imaging Settings is NULL.\n");

goto EXIT;

}

printf("Brightness: %f\n", *(gISets_rep.ImagingSettings->Brightness));

printf("ColorSaturation: %f\n", *(gISets_rep.ImagingSettings->ColorSaturation));

printf("Contrast: %f\n", *(gISets_rep.ImagingSettings->Contrast));

if( NULL != gISets_rep.ImagingSettings->Focus )

{

printf("Contrast: %d\n", gISets_rep.ImagingSettings->Focus->AutoFocusMode );

}

#if 1

if( NULL != gISets_rep.ImagingSettings->Exposure )

{

printf("MinExposureTime: %f\n", *gISets_rep.ImagingSettings->Exposure->MinExposureTime);

printf("MaxExposureTime: %f\n", *gISets_rep.ImagingSettings->Exposure->MaxExposureTime);

printf("MinGain: %f\n", *gISets_rep.ImagingSettings->Exposure->MinGain);

printf("MaxGain: %f\n", *gISets_rep.ImagingSettings->Exposure->MaxGain);

//printf("ExposureTime: %f\n", gISets_rep.ImagingSettings->Exposure->ExposureTime);

//printf("Gain: %f\n", *gISets_rep.ImagingSettings->Exposure->Gain);

}

#endif

if( NULL != gISets_rep.ImagingSettings->BacklightCompensation )

{

printf("Mode: %d\n", gISets_rep.ImagingSettings->BacklightCompensation->Mode);

printf("Level: %d\n", gISets_rep.ImagingSettings->BacklightCompensation->Level);

}

memset(&sISets_req, 0x00, sizeof(sISets_req));

memset(&sISets_rep, 0x00, sizeof(sISets_rep));

sISets_req.ForcePersistence = &ForceStorage;

sISets_req.ImagingSettings = gISets_rep.ImagingSettings;

sISets_req.VideoSourceToken = VideoSourceToken;

if( NULL != sISets_req.ImagingSettings )

{

printf("Brightness: %f\n", *(sISets_req.ImagingSettings->Brightness));

printf("ColorSaturation: %f\n", *(sISets_req.ImagingSettings->ColorSaturation));

printf("Contrast: %f\n", *(sISets_req.ImagingSettings->Contrast));

*sISets_req.ImagingSettings->Brightness = 52;

*sISets_req.ImagingSettings->ColorSaturation = 53;

*sISets_req.ImagingSettings->Contrast = 54;

printf("Brightness: %f\n", *(sISets_req.ImagingSettings->Brightness));

printf("ColorSaturation: %f\n", *(sISets_req.ImagingSettings->ColorSaturation));

printf("Contrast: %f\n", *(sISets_req.ImagingSettings->Contrast));

}

if( NULL != sISets_req.ImagingSettings->Focus )

{

printf("Contrast: %d\n", sISets_req.ImagingSettings->Focus->AutoFocusMode );

sISets_req.ImagingSettings->Focus->AutoFocusMode = tt__AutoFocusMode__AUTO;

printf("Contrast: %d\n", sISets_req.ImagingSettings->Focus->AutoFocusMode );

}

#if 1

if( NULL != gISets_rep.ImagingSettings->Exposure )

{

*sISets_req.ImagingSettings->Exposure->MaxGain = 20;

*sISets_req.ImagingSettings->Exposure->MinExposureTime = 10;

*sISets_req.ImagingSettings->Exposure->MaxExposureTime = 40000;

printf("MinExposureTime: %f\n", *(sISets_req.ImagingSettings->Exposure->MinExposureTime));

printf("MaxExposureTime: %f\n", *(sISets_req.ImagingSettings->Exposure->MaxExposureTime));

printf("MinGain: %f\n", *(sISets_req.ImagingSettings->Exposure->MinGain));

printf("MaxGain: %f\n", *(sISets_req.ImagingSettings->Exposure->MaxGain));

//printf("ExposureTime: %f\n", sISets_rep.ImagingSettings->Exposure->ExposureTime);

//printf("Gain: %f\n", sISets_rep.ImagingSettings->Exposure->Gain);

}

#endif

ONVIF_SetAuthInfo(soap, USERNAME, PASSWORD);

result = soap_call___timg__SetImagingSettings(soap, ImagingXAddr, NULL, &sISets_req, &sISets_rep);

SOAP_CHECK_ERROR(result, soap, "SetImagingSettings");

EXIT:

if (SOAP_OK == result) {

SOAP_DBGLOG("\nSetImagingSettings success!!!\n");

}

if (NULL != soap) {

ONVIF_soap_delete(soap);

}

return result;

}

void cb_discovery(char *DeviceXAddr)

{

ONVIF_GetDeviceInformation(DeviceXAddr);

ONVIF_GetCapabilities(DeviceXAddr);

}

int main(int argc, char **argv)

{

#if 1

char DeviceXAddr[] = "http://192.168.41.61:80/onvif/device_service";

char MediaXAddr[] = "http://192.168.41.61:80/onvif/media_service";

char ImagingXAddr[] = "http://192.168.41.61:80/onvif/imaging_service";

#if 0

char DeviceXAddr_1[] = "http://192.168.41.184/onvif/device_service";

char MediaXAddr_1[] = "http://192.168.41.184/onvif/media_service";

char ImagingXAddr_1[] = "http://192.168.41.184/onvif/imaging_service";

#endif

char DeviceXAddr_1[] = "http://192.168.41.188/onvif/device_service";

char MediaXAddr_1[] = "http://192.168.41.188/onvif/Media";

char ImagingXAddr_1[] = "http://192.168.41.188/onvif/Imaging";

ONVIF_GetDeviceInformation(DeviceXAddr);

ONVIF_GetCapabilities(DeviceXAddr);

ONVIF_GetProfiles(MediaXAddr);

ONVIF_SetImagingSettings(ImagingXAddr);

ONVIF_GetDeviceInformation(DeviceXAddr_1);

ONVIF_GetCapabilities(DeviceXAddr_1);

ONVIF_GetProfiles(MediaXAddr_1);

ONVIF_SetVideoEncoderConfiguration(MediaXAddr_1);

ONVIF_SetImagingSettings(ImagingXAddr_1);

#endif

//ONVIF_DetectDevice(cb_discovery);

return 0;

}

以上就是main.c的全部代码内容。

3.3.2  编译应用

使用sudo mkdir /opt/onvif命令,创建onvif目录

将动态库和应用实现文件拷贝到onvif目录下,使用sudo gcc -o main main.c -L./ -lonvif_c命令生成可执行文件,如下图所示:

备注:根据提示将相应的头文件拷贝到相应的目录中,其中openssl所需头文件直接拷贝到/usr/include下,如下图所示:

再次使用sudo gcc -o main main.c -L./ -lonvif_c命令,执行结果如下图所示:

使用sudo gcc -o main main.c -L./ -lonvif_c -L./ -lssl -L./ -lcrypto命令进行编译,执行结果如下图所示:

编译后提示找不到-lssl、-lcrypto动态库,解决办法是使用软连接生成动态库文件,如下命令,执行结果如下图:

sudo ln -s libcrypto.so.3 libcrypto.so

sudo ln -s libssl.so.3 libssl.so

再次使用sudo gcc -o main main.c -L./ -lonvif_c -L./ -lssl -L./ -lcrypto进行编译,执行结果如下图所示:

无提示错误,说明应用编译成功,且可在目录下找到main可执行文件。

3.3.3  执行应用

使用sudo ./main命令,执行应用程序。

错误提示信息:./main: error while loading shared libraries: libonvif_c.so: cannot open shared object file: Error 40

解决方法是将程序所关联的动态库拷贝到系统库路径下,命令如下,执行结果如下图所示:

sudo cp libcrypto.so.3 libssl.so.3 libonvif_c.so /usr/lib/

再次sudo ./main命令,执行结果如下图所示:

通过以上步骤,验证了生成的ONVIF动态库是可用的。

备注:

在实际开发中,我们可以将这些动态库和头文件进行打包,然后通过相关Makefile和shell脚本生成应用,从而减少工具安装、ONVIF框架生成等步骤。

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档