我正在使用 gSOAP 配置 ONVIF 兼容摄像头。 目前,我正在通过执行类似的操作来手动设置请求中的所有参数。这是针对 SetVideEncoderConfiguration
MediaBindingProxy mediaDevice (uri);
AUTHENTICATE (mediaDevice);
_trt__SetVideoEncoderConfiguration req;
_trt__SetVideoEncoderConfigurationResponse resp;
struct tt__VideoEncoderConfiguration encoderConfig;
struct tt__VideoResolution resolutionConfig;
encoderConfig.Name = strdup (name);
encoderConfig.UseCount = 1;
encoderConfig.Quality = 50;
if (strcmp (encoding, "H264") == 0)
encoderConfig.Encoding = tt__VideoEncoding__H264;
else if (strcmp (encoding, "JPEG") == 0)
encoderConfig.Encoding = tt__VideoEncoding__JPEG;
encoderConfig.token = strdup (profileToken);
encoderConfig.SessionTimeout = (LONG64)"PT0S";
resolutionConfig.Width=1280;
resolutionConfig.Height=720;
encoderConfig.Resolution = &resolutionConfig;
tt__VideoRateControl rateControl;
rateControl.FrameRateLimit = 15;
rateControl.EncodingInterval = 1;
rateControl.BitrateLimit = 4500;
encoderConfig.RateControl = &rateControl;
struct tt__H264Configuration h264;
h264.GovLength = 30;
h264.H264Profile = tt__H264Profile__Baseline;
encoderConfig.H264 = &h264;
struct tt__MulticastConfiguration multicast;
struct tt__IPAddress address;
address.IPv4Address = strdup ("0.0.0.0");
multicast.Address = &address;
encoderConfig.Multicast = &multicast;
req.Configuration = &encoderConfig;
req.ForcePersistence = true;
int ret = mediaDevice.SetVideoEncoderConfiguration (&req, resp);
qDebug () << "Set Encoder: " << ret;
有更简单的方法吗?可能是一些设置请求参数的函数调用?我发现 GetMediaUri 的另一种方法是使用类似
soap_new_req__trt__GetStreamUri (mediaDevice.soap,soap_new_req_tt__StreamSetup (mediaDevice.soap, (enum tt__StreamType)0, soap_new_tt__Transport(mediaDevice.soap), 1, NULL), "profile1");
这是使用 gSOAP 进行客户端代码的唯一两种方法吗?
-曼达尔·乔希
最佳答案
soap_new_T()
有四种变体分配 T
类型的数据在 C++ 中使用 gSOAP:
-
T * soap_new_T(struct soap*)
返回T
的新实例这是默认的 在soap
管理的堆上初始化并分配上下文。 -
T * soap_new_T(struct soap*, int n)
返回n
的数组新实例T
在托管堆上。数组中的实例默认初始化,如上所述。 -
T * soap_new_req_T(struct soap*, ...)
(仅限结构和类)返回一个T
的新实例在托管堆上分配并将所需的数据成员设置为其他参数...
中指定的值. -
T * soap_new_set_T(struct soap*, ...)
(仅限结构和类)返回一个T
的新实例在托管堆上并将公共(public)/可序列化数据成员设置为其他参数...
中指定的值.
使用soap_strdup(struct soap*, const char*)
而不是strdup
将字符串复制到托管堆上。
托管堆上的所有数据都被批量删除 soap_destroy(soap)
和
soap_end(soap)
(按顺序调用)必须在 soap_done(soap)
之前调用或soap_free(soap)
.
要分配数据指针,请使用模板:
template<class T>
T * soap_make(struct soap *soap, T val)
{
T *p = (T*)soap_malloc(soap, sizeof(T));
if (p)
*p = val;
return p;
}
template<class T>
T **soap_make_array(struct soap *soap, T* array, int n)
{
T **p = (T**)soap_malloc(soap, n * sizeof(T*));
for (int i = 0; i < n; ++i)
p[i] = &array[i];
return p;
}
然后使用 soap_make<int>(soap, 123)
创建指向值 123
的指针在托管堆上和 soap_make_array(soap, soap_new_CLASSNAME(soap, 100), 100)
创建 100 个指向 CLASSNAME
的 100 个实例的指针.
gSOAP 工具还可以为您生成深层复制操作:CLASSNAME::soap_dup(struct soap*)
创建对象的深拷贝并将其分配在另一个 soap
中您作为参数提供的上下文。使用NULL
作为分配非托管深拷贝的参数(但这些副本不能有指针循环!)。然后使用 CLASSNAME::soap_del()
删除非托管副本用于深度删除所有成员,然后 delete
对象本身。
参见Memory management in C++更多细节。使用 gSOAP 2.8.39 及更高版本。
关于gsoap - 是否有更简单的方法来设置/获取 gSOAP 请求/响应中的值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41052091/