大华相机DH-IPC-HFW3237M支持的ONVIF协议

使用libONVIF C++库。

先发现相机。

配置

lib目录
包含
编译提示缺的文件,到libonvif里面拷贝过来。

改UDP端口

代码

使用msvc 2022的向导生成空项目,从项目的main示例拷贝过来。

CameraOnvif.h

cpp 复制代码
#pragma once

#include <QObject>
#include <QUrl>

#include "Response.h"
#include "SoapHelper.h"
#include "OnvifDevice.h"
#include "OnvifDiscovery.h"

class CameraOnvif : public QObject
{
	QOBJECT_H

public:
	CameraOnvif(QObject* parent = nullptr);
	~CameraOnvif();

	QObject* _parent;

};

CameraOnvif.cpp

cpp 复制代码
#include "CameraOnvif.h"

CameraOnvif::CameraOnvif(QObject* parent)
{
	_parent = parent;

	auto cb = SoapCtx::Builder();
	cb.SetSendTimeout(1000);
	cb.SetReceiveTimeout(2000);
	auto discovery = new OnvifDiscoveryClient(QUrl("soap.udp://239.255.255.250:3702"), cb.Build(), _parent);
	ProbeTypeRequest request;
	request.Types = (char*)"tds:Device";
	auto uuidOne = QString("uuid:%1").arg(SoapHelper::GenerateUuid());
	auto probeResponseTwo = discovery->Probe(request, uuidOne);
	request.Types = (char*)"tdn:NetworkVideoTransmitter";
	auto uuidTwo = QString("uuid:%1").arg(SoapHelper::GenerateUuid());
	auto probeResponseOne = discovery->Probe(request, uuidTwo);

	if (probeResponseOne && probeResponseTwo) {
		auto foundMatches = 0;
		auto matchResp = discovery->ReceiveProbeMatches();

		if (matchResp && matchResp.GetResultObject()) {
			auto relatesTo = matchResp.GetSoapHeaderRelatesTo();
			if (!relatesTo.isNull() && (uuidOne.compare(relatesTo) == 0 || uuidTwo.compare(relatesTo) == 0)) {
				if (auto matchs = matchResp.GetResultObject()) {
					if (matchs->wsdd__ProbeMatches) {
						for (auto i = 0; i < matchs->wsdd__ProbeMatches->__sizeProbeMatch; ++i) {
							wsdd__ProbeMatchesType match = matchs->wsdd__ProbeMatches[i];
							for (auto ii = 0; ii < match.__sizeProbeMatch; ++ii) {
								foundMatches++;
								auto probe = match.ProbeMatch[ii];
								qDebug() << "Found match:" << "    Type:" << probe.Types << " Endpoint:" << probe.XAddrs;
								if (probe.wsa5__EndpointReference.Address) {
									qDebug() << "     Reference:" << probe.wsa5__EndpointReference.Address;
								}
								if (probe.Scopes) {
									auto scopeList = QString::fromLocal8Bit(probe.Scopes->__item).split(' ');
									auto matchBy = QString::fromLocal8Bit(probe.Scopes->MatchBy);
									if (!matchBy.isEmpty()) {
										qDebug() << "    Match:" << matchBy;
									}
									qDebug() << "    Scope:";
									for (auto scope : scopeList) {
										if (!scope.isEmpty()) qDebug() << "        " << scope;
									}
								}
							}
						}
					}
				}
			}
			else {
				qDebug() << "Skipping non related message with id:" << relatesTo;
			}
		}
	}
	else {
		qCritical() << "nothing";
	}
}

CameraOnvif::~CameraOnvif()
{
}

调用类。

cpp 复制代码
#include "camera_onvif.h"

camera_onvif::camera_onvif(QWidget *parent)
    : QMainWindow(parent)
{
    ui.setupUi(this);

    auto camera = new CameraOnvif(this);
}

camera_onvif::~camera_onvif()
{}

结果

Found match: Type: "http://www.onvif.org/ver10/network/wsdl":NetworkVideoTransmitter tds:Device Endpoint: http://192.168.1.109/onvif/device_service

Reference: uuid:42164801-9662-9563-32ba-33e24ea19662

Scope:

"onvif://www.onvif.org/location/country/china"

"onvif://www.onvif.org/name/Dahua"

"onvif://www.onvif.org/hardware/DH-IPC-HFW3237M-I2"

"onvif://www.onvif.org/Profile/Streaming"

"onvif://www.onvif.org/type/Network_Video_Transmitter"

"onvif://www.onvif.org/extension/unique_identifier/0"

"onvif://www.onvif.org/Profile/T"

相关推荐
静止了 所有的花开1 个月前
Onvif服务端开发
音视频·onvif
不会飞的渡渡鸟2 个月前
在Windows下编译支持https的wsdl2h
onvif
不被定义的程序猿3 个月前
onvif相关的http api有哪些功能点
网络·onvif
装不满的克莱因瓶10 个月前
Win10 搭建FTP存储服务器站点【超详细教程】
运维·服务器·windows·ftp·大华摄像头·大华