全网原创再次熬夜升级/支持云台预置位的onvif设备模拟器/虚拟监控摄像头/可设置主码流子码流

一、前言说明

onvif监控设备模拟器用户不断增加,近期有定制需求,一个是能够主码流子码流切换,一个是能够识别云台操作预置位管理,这两个需求很常用也很合理,直接撸起袖子加油干。之前就是一个设备对应一个采集源,主码流子码流地址都是同一个,实际情况往往需要子码流更小的码率和分辨率,比如采集桌面推流模拟成一个监控通道,主码流按照1080P分辨率采集,子码流可以按照640分辨率采集,在公网环境非常有用,节约流量。所以需要在现有基础上,增加另外一路采集源对应子码流的推流,子码流地址就约定在主码流基础上加上后缀 _sub 即可。主码流地址是rtsp://127.0.0.1:8554/video,那么子码流就是rtsp://127.0.0.1:8554/video_sub。其中主码流和子码流都可以开启编码和指定分辨率等参数。

云台和预置位的识别,之前是没有实现的,之前按照简单做的,能够搜索和获取设备信息、码流地址等,所以打包的xml数据中并没有云台相关,用odm等工具打开对应视频流后,会发现云台功能禁用的,因为发送的相关配置profile信息中,并没有指明开启具备云台,通过抓包分析,需要对应GetNode指令进行应答,如果是预置位的话,需要对GetPresets指令应答,这样才表示云台和预置位都开启。至于云台的上下左右移动变倍聚焦光圈,预置位的添加删除修改查询等,都是通过xml数据进行交互,加上这些交互,然后放出两个信号ptzControl/ptzPreset即可,信号中的参数包括对应枚举值类型OnvifPtzType。打完收工相当完美,这次还顺带支持了聚焦和光圈功能。

二、效果图

video_simulate_onvif4

三、相关地址

  1. 国内站点:https://gitee.com/feiyangqingyun
  2. 国际站点:https://github.com/feiyangqingyun
  3. 个人作品:https://blog.csdn.net/feiyangqingyun/article/details/97565652
  4. 文件地址:https://pan.baidu.com/s/1d7TH_GEYl5nOecuNlWJJ7g 提取码:01jf 文件名:bin_video_simulate

四、功能特点

  1. 标准onvif协议,支持设备搜索、获取参数、快照抓图等。
  2. 支持264/265/aac等标准视音频协议传输。
  3. 支持多路批量onvif设备模拟,每一路都独立的端口。
  4. 支持本地摄像头采集转成onvif,可选择不同的设备、分辨率、帧率等参数。
  5. 支持本地桌面采集转成onvif,可选择不同的屏幕、分辨率、帧率等参数。
  6. 支持各种视频文件和视频流转成onvif,可重新设置编码转换以及分辨率转换。
  7. 支持4K、8K等高清分辨率,不限制分辨率,非264/265会自动转码推流。
  8. 每一路都可以设置统一或者独立的用户验证信息,为空则表示不验证。
  9. 可以把任意内容接入到NVR以及视频监控系统,方便保存录像文件,以便回放可查。
  10. 也可作为压力测试工具,比如模拟几千路onvif设备,让集成平台软件做接入压力测试。
  11. 推出去的流不仅有rtsp格式,还支持rtmp、http、flv、ws-flv、webrtc等方式访问,可以直接网页查看。
  12. 在管理工具上可以看到每一路的推流状况以及分辨率信息,非常直观。
  13. 支持自动重连拉流,重连推流,保证7乘以24小时稳定运行。
  14. 可设置开机自启动运行和后台运行,不显示在任务栏,作为后台服务运行。
  15. 可批量添加文件、添加目录,自动将目录下的所有文件添加到模拟器。
  16. 多功能添加地址面板,可以选择本地设备和监控设备,本地设备会自动识别摄像头设备和桌面设备,监控设备可以选择不同厂家,自动填充对应rtsp格式,填入用户信息即可,可以批量递增添加监控设备。
  17. 可无缝上传到市面上所有的onvif协议设备,包括海康、大华、宇视、华为、天地伟业等,也支持ONVIF Device Manager国际onvif工具。
  18. 支持gb28181设备模拟,具备设备注册、设备注销、设备心跳、设备信息、设备配置、设备状态应答等。
  19. 支持模拟报警和位置上报等,方便平台侧显示对应设备的实时位置。
  20. 支持一键添加批量模拟28181设备,实时显示已注册和已注销状态。
  21. 支持将本地桌面、本地摄像头、任意视频文件、视频流文件、手机摄像头等转换成28181设备,添加到NVR或者国标软件平台。
  22. sip协议同时支持udp和tcp两种通信方式,视频点播同时支持udp/tcp主动/tcp被动三种方式,涵盖所有可能的场景需求。
  23. 提供云台控制信号,上下左右等8个方位移动,拉近拉远等,对应XYZ的值。
  24. 提供预置位操作信号,获取预置位、添加预置位、调用预置位、删除预置位等。
  25. onvif模拟支持主码流和子码流分别对应不同的采集源,比如桌面屏幕采集主码流和子码流对应不同的分辨率。
  26. 无论是onvif设备模拟组件还是28181设备模拟组件,全部原创底层协议解析,纯Qt实现,跨任意平台。
  27. 代码结构框架非常清晰,注释详细,代码精简不繁琐,非常易于学习和移植,可以很容易拓展其他接口需求。
  28. 支持Qt4/Qt5/Qt6以及后续所有版本、所有编译器、所有开发环境。
  29. 支持windows、linux、mac、国产OS、嵌入式linux、RK3588、树莓派、香橙派等系统。

五、相关代码

#include "onviflistenhelper.h"
#include "onvifdevicehelper.h"
#include "onvifdevicelisten.h"
#include "onvifxmldata.h"

void OnvifListenHelper::sendImage(const QImage &image, QTcpSocket *socket)
{
    QBuffer buffer;
    buffer.open(QIODevice::ReadWrite);
    image.save(&buffer, "jpg");
    QByteArray body = buffer.buffer();

    QByteArray data;
    data.append("HTTP/1.1 200 OK\r\n");
    data.append("Connection: close\r\n");
    data.append("Content-Length: ");
    data.append(QString::number(body.size()).toLatin1() + "\r\n");
    data.append("Content-Type: image/jpeg\r\n");
    data.append("\r\n");
    data.append(body);
    socket->write(data);
}

QStringList OnvifListenHelper::notSecurity = QStringList() << "GetSystemDateAndTime" << "GetServices" << "GetCapabilities";
QStringList OnvifListenHelper::needToken = QStringList() << "GetProfile" << "GetStreamUri" << "GetSnapshotUri";
QStringList OnvifListenHelper::needUuid = QStringList() << "CreatePullPointSubscription" << "PullMessages" << "Renew";
QStringList OnvifListenHelper::ptzCmds = QStringList() << "AbsoluteMove" << "RelativeMove" << "ContinuousMove" << "Stop";
QStringList OnvifListenHelper::presetCmds = QStringList() << "GotoPreset" << "RemovePreset" << "SetPreset" << "GotoHomePosition" << "SetHomePosition";

bool OnvifListenHelper::checkData(const QByteArray &buffer, OnvifPostPara &postPara, OnvifDevicePara devicePara)
{
    int index = buffer.indexOf("\r\n\r\n");
    if (index < 0) {
        return false;
    }

    //取出命令关键字
    QByteArray body = buffer.mid(index + 4);
    QString value = OnvifDeviceHelper::getValue3(body, "Body");
    int index1 = value.indexOf("<");
    int index2 = value.indexOf(">");
    QString cmd = value.mid(index1, index2);
    cmd.replace("<", "");
    cmd.replace(">", "");
    cmd.replace("/", "");
    cmd.replace("\r\n", "");
    cmd = cmd.split(" ").first();
    cmd = cmd.split(":").last();
    postPara.cmd = cmd;
    //qDebug() << TIMEMS << cmd << value;

    //用户信息为空则返回
    if (devicePara.userName.isEmpty() || devicePara.userPwd.isEmpty()) {
        return true;
    }

    //有些指令不需要验证用户
    if (notSecurity.contains(cmd)) {
        return true;
    }

    //事件订阅要取出超时时间
    if (needUuid.contains(cmd)) {
        postPara.uuid = OnvifDeviceHelper::getMessageID(body);
        postPara.timeout = OnvifDeviceHelper::getTimeout(body);
    }

    //配置文件标识
    else if (needToken.contains(cmd)) {
        postPara.profileToken = OnvifDeviceHelper::getProfileToken(body);
    }

    //云台控制需要取出XYZ值
    else if (cmd == "ContinuousMove") {
        OnvifDeviceHelper::getPtzValue(body, postPara.panTiltX, postPara.panTiltY, postPara.panTiltZ);
    }

    //聚焦速度
    else if (cmd == "Move") {
        postPara.focusSpeed = OnvifDeviceHelper::getFocusSpeed(body);
    }

    //光圈大小
    else if (cmd == "SetImagingSettings") {
        postPara.irisValue = OnvifDeviceHelper::getIrisValue(body);
    }

    //预置位需要取出名称标识
    else if (presetCmds.contains(cmd)) {
        postPara.presetToken = OnvifDeviceHelper::getPresetToken(body);
        postPara.presetName = OnvifDeviceHelper::getPresetName(body);
    }

    //OSD标识
    else if (cmd == "GetOSD") {
        postPara.osdToken = OnvifDeviceHelper::getOsdToken(body);
    }

    //取出用户信息
    QString Username = OnvifDeviceHelper::getValue5(body, "Username");
    QString Password = OnvifDeviceHelper::getValue5(body, "Password");
    QString Nonce = OnvifDeviceHelper::getValue5(body, "Nonce");
    QString Created = OnvifDeviceHelper::getValue5(body, "Created");

    //验证用户信息
    QByteArray Nonce2 = QByteArray::fromBase64(Nonce.toLatin1());
    QByteArray Password2 = Nonce2 + Created.toLatin1() + devicePara.userPwd.toLatin1();
    Password2 = QCryptographicHash::hash(Password2, QCryptographicHash::Sha1).toBase64();
    //qDebug() << TIMEMS << cmd << Username << Nonce << Created << Password << Password2;
    if (devicePara.userName != Username || Password != Password2) {
        qDebug() << TIMEMS << "user error" << Username << Nonce << Created << Password << Password2;
        return false;
    }

    return true;
}

QByteArray OnvifListenHelper::getData(const QString &body, const QString &flag)
{
    QStringList list;
    list << QString("HTTP/1.1 %1").arg(flag);
    list << QString("Connection: close");
    list << QString("Content-Length: %1").arg(body.size());
    list << QString("Content-Type: application/soap+xml; charset=utf-8");
    //list << QString("CSeq: 0");
    list << "" << body;
    QString data = list.join("\r\n");
    return data.toUtf8();
}

QByteArray OnvifListenHelper::getData(OnvifPostPara postPara, OnvifDevicePara devicePara, OnvifDeviceListen *listen)
{
    QByteArray data;
    QString cmd = postPara.cmd;
    QString token = postPara.profileToken;
    if (cmd == "GetSystemDateAndTime") {
        data = OnvifListenHelper::getSystemDateAndTime();
    } else if (cmd == "GetServices") {
        data = OnvifListenHelper::getServices(devicePara.onvifUrl);
    } else if (cmd == "GetCapabilities") {
        data = OnvifListenHelper::getCapabilities(devicePara.onvifUrl);
    } else if (cmd == "GetProfile") {
        data = OnvifListenHelper::getProfile(token, devicePara);
    } else if (cmd == "GetProfiles") {
        data = OnvifListenHelper::getProfiles(devicePara);
    } else if (cmd == "GetStreamUri") {
        //主码流子码流地址不同
        QString url = (token.endsWith("_2") ? devicePara.rtspSub : devicePara.rtspUrl);
        data = OnvifListenHelper::getStreamUri(url);
    } else if (cmd == "GetVideoSources") {
        data = OnvifListenHelper::getVideoSources(devicePara.videoFps, devicePara.videoWidth, devicePara.videoHeight);
    } else if (cmd == "GetVideoSourceConfiguration") {
        data = OnvifListenHelper::getVideoSourceConfiguration(devicePara.videoWidth, devicePara.videoHeight);
    } else if (cmd == "GetOptions") {
        data = OnvifListenHelper::getOptions();
    } else if (cmd == "GetOSDOptions") {
        data = OnvifListenHelper::getOSDOptions();
    } else if (cmd == "GetOSD") {
        if (postPara.osdToken == "OSD_1") {
            data = OnvifListenHelper::getOSD_1();
        } else {
            data = OnvifListenHelper::getOSD_2();
        }
    } else if (cmd == "GetOSDs") {
        data = OnvifListenHelper::getOSDs();
    } else if (cmd == "GetImagingSettings") {
        data = OnvifListenHelper::getImagingSettings();
    } else if (cmd == "GetMoveOptions") {
        data = OnvifListenHelper::getMoveOptions();
    } else if (cmd == "GetDeviceInformation") {
        data = OnvifListenHelper::getDeviceInformation(devicePara.hardwareId);
    } else if (cmd == "GetScopes") {
        data = OnvifListenHelper::getScopes();
    } else if (cmd == "GetHostname") {
        data = OnvifListenHelper::getHostname();
    } else if (cmd == "GetNetworkDefaultGateway") {
        data = OnvifListenHelper::getNetworkDefaultGateway(devicePara.onvifUrl);
    } else if (cmd == "GetDNS") {
        data = OnvifListenHelper::getDNS();
    } else if (cmd == "GetNetworkInterfaces") {
        QString ip = OnvifDeviceHelper::getUrlIP(devicePara.onvifUrl);
        data = OnvifListenHelper::getNetworkInterfaces(ip);
    } else if (cmd == "GetAnalyticsModules") {
        data = OnvifListenHelper::getAnalyticsModules();
    } else if (cmd == "GetSupportedAnalyticsModules") {
        data = OnvifListenHelper::getSupportedAnalyticsModules();
    } else if (cmd == "GetVideoEncoderConfiguration") {
        data = OnvifListenHelper::getVideoEncoderConfiguration();
    } else if (cmd == "GetVideoEncoderConfigurationOptions") {
        data = OnvifListenHelper::getVideoEncoderConfigurationOptions();
    } else if (cmd == "GetEventProperties") {
        data = OnvifListenHelper::getEventProperties();
    } else if (cmd == "CreatePullPointSubscription") {
        data = OnvifListenHelper::createPullPointSubscription(devicePara.onvifUrl, postPara.timeout);
    } else if (cmd == "PullMessages") {
        return data;
    } else if (cmd == "Subscribe") {
        return data;
    } else if (cmd == "Renew") {
        data = OnvifListenHelper::renew(postPara.timeout);
    } else if (cmd == "Unsubscribe") {
        data = OnvifListenHelper::unsubscribe();
    } else if (cmd == "GetSnapshotUri") {
        data = OnvifListenHelper::getSnapshotUri(token, devicePara.onvifUrl);
    } else if (cmd == "GetNode") {
        data = OnvifListenHelper::getNodes(true);
    } else if (cmd == "GetNodes") {
        data = OnvifListenHelper::getNodes(false);
    } else if (cmd == "GetStatus") {
        data = OnvifListenHelper::getStatus();
    } else if (cmd == "GetPresets") {
        data = OnvifListenHelper::getPresets(devicePara.presets);
    } else if (ptzCmds.contains(cmd)) {
        qreal x = postPara.panTiltX;
        qreal y = postPara.panTiltY;
        qreal z = postPara.panTiltZ;
        OnvifPtzType type = (cmd == "Stop" ? OnvifPtz_Stop : OnvifDeviceHelper::ptzValueToType(x, y, z));
        listen->ptzControl(devicePara.host, devicePara.port, type, x, y, z);
        data = OnvifListenHelper::getResponse(cmd);
    } else if (presetCmds.contains(cmd)) {
        OnvifPtzType type = OnvifDeviceHelper::ptzCmdToType(cmd);;
        listen->ptzPreset(devicePara.host, devicePara.port, type, postPara.presetToken, postPara.presetName);
        data = OnvifListenHelper::getResponse(cmd);
    } else if (cmd == "Move") {
        qreal speed = postPara.focusSpeed;
        OnvifPtzType type = (speed > 0 ? OnvifPtz_FocusIn : OnvifPtz_FocusOut);
        listen->ptzControl(devicePara.host, devicePara.port, type, 0, 0, speed);
        data = OnvifListenHelper::getResponse(cmd);
    } else if (cmd == "SetImagingSettings") {
        qreal value = postPara.irisValue;
        if (value != -1) {
            OnvifPtzType type = (value > 0 ? OnvifPtz_IrisIn : OnvifPtz_IrisOut);
            listen->ptzControl(devicePara.host, devicePara.port, type, 0, 0, value);
        }
        data = OnvifListenHelper::getResponse(cmd);
    } else if (cmd == "SetSynchronizationPoint") {
        data = OnvifListenHelper::getResponseFull("tns1:SetSynchronizationPointResponse");
    } else if (cmd == "SetSystemDateAndTime") {
        data = OnvifListenHelper::getResponse("SetSystemDateAndTime");
    } else {
        qDebug() << "aaa" << TIMEMS << cmd;
    }

    //未知指令答
    if (data.isEmpty()) {
        data = OnvifListenHelper::getActionNotSupported();
    }

    return data;
}

QString OnvifListenHelper::getCurrentTime()
{
    QString currentTime;
    OnvifListenHelper::getDateTime(&currentTime);
    return currentTime;
}

void OnvifListenHelper::getDateTime(QString *currentTime, QString *terminationTime, int timeout)
{
    QDateTime now = QDateTime::currentDateTimeUtc();
    QString format = "yyyy-MM-ddThh:mm:ssZ";
    (*currentTime) = now.toString(format);

    if (terminationTime) {
        (*terminationTime) = now.addSecs(timeout).toString(format);
    }
}

QByteArray OnvifListenHelper::getSystemDateAndTime()
{
    QDateTime now = QDateTime::currentDateTimeUtc();
    QDate date = now.date();
    QTime time = now.time();
    QString body = OnvifDeviceHelper::getFile(":/onvifresponse/GetSystemDateAndTime.xml");
    body = body.arg(time.hour()).arg(time.minute()).arg(time.second()).arg(date.year()).arg(date.month()).arg(date.day());
    return OnvifListenHelper::getData(body);
}

QByteArray OnvifListenHelper::getServices(const QString &url)
{
    QString body = OnvifDeviceHelper::getFile(":/onvifresponse/GetServices.xml");
    body = body.arg(url);
    return OnvifListenHelper::getData(body);
}

QByteArray OnvifListenHelper::getCapabilities(const QString &url)
{
    QString body = OnvifDeviceHelper::getFile(":/onvifresponse/GetCapabilities.xml");
    body = body.arg(url);
    return OnvifListenHelper::getData(body);
}

QByteArray OnvifListenHelper::getProfile(const QString &token, OnvifDevicePara devicePara)
{
    //不同码率取对应的参数
    int fps = devicePara.videoFps;
    int width = devicePara.videoWidth;
    int height = devicePara.videoHeight;
    if (token.endsWith("_2")) {
        fps = devicePara.videoFps2;
        width = devicePara.videoWidth2;
        height = devicePara.videoHeight2;
    }

    QString body = OnvifDeviceHelper::getFile(":/onvifresponse/GetProfile.xml");
    body = body.arg(width).arg(height).arg(fps);
    return OnvifListenHelper::getData(body);
}

QByteArray OnvifListenHelper::getProfiles(OnvifDevicePara devicePara)
{
    int fps = devicePara.videoFps;
    int width = devicePara.videoWidth;
    int height = devicePara.videoHeight;
    int fps2 = devicePara.videoFps2;
    int width2 = devicePara.videoWidth2;
    int height2 = devicePara.videoHeight2;

    QString body = OnvifDeviceHelper::getFile(":/onvifresponse/GetProfiles.xml");
    body = body.arg(width).arg(height).arg(fps).arg(width2).arg(height2).arg(fps2);
    return OnvifListenHelper::getData(body);
}

QByteArray OnvifListenHelper::getStreamUri(const QString &url)
{
    QString body = OnvifDeviceHelper::getFile(":/onvifresponse/GetStreamUri.xml");
    body = body.arg(url);
    return OnvifListenHelper::getData(body);
}

QByteArray OnvifListenHelper::getVideoSources(int fps, int width, int height)
{
    QString body = OnvifDeviceHelper::getFile(":/onvifresponse/GetVideoSources.xml");
    body = body.arg(fps).arg(width).arg(height);
    return OnvifListenHelper::getData(body);
}

QByteArray OnvifListenHelper::getVideoSourceConfiguration(int width, int height)
{
    QString body = OnvifDeviceHelper::getFile(":/onvifresponse/GetVideoSourceConfiguration.xml");
    body = body.arg(width).arg(height);
    return OnvifListenHelper::getData(body);
}

QByteArray OnvifListenHelper::getOptions()
{
    QString body = OnvifDeviceHelper::getFile(":/onvifresponse/GetOptions.xml");
    return OnvifListenHelper::getData(body);
}

QByteArray OnvifListenHelper::getOSDOptions()
{
    QString body = OnvifDeviceHelper::getFile(":/onvifresponse/GetOSDOptions.xml");
    return OnvifListenHelper::getData(body);
}

QByteArray OnvifListenHelper::getOSDs()
{
    QString body = OnvifDeviceHelper::getFile(":/onvifresponse/GetOSDs.xml");
    return OnvifListenHelper::getData(body);
}

QByteArray OnvifListenHelper::getOSD_1()
{
    QString body = OnvifDeviceHelper::getFile(":/onvifresponse/GetOSD_1.xml");
    return OnvifListenHelper::getData(body);
}

QByteArray OnvifListenHelper::getOSD_2()
{
    QString body = OnvifDeviceHelper::getFile(":/onvifresponse/GetOSD_2.xml");
    return OnvifListenHelper::getData(body);
}

QByteArray OnvifListenHelper::getImagingSettings()
{
    QString body = OnvifDeviceHelper::getFile(":/onvifresponse/GetImagingSettings.xml");
    return OnvifListenHelper::getData(body);
}

QByteArray OnvifListenHelper::getMoveOptions()
{
    QString body = OnvifDeviceHelper::getFile(":/onvifresponse/GetMoveOptions.xml");
    return OnvifListenHelper::getData(body);
}

QByteArray OnvifListenHelper::getDeviceInformation(const QString &hardwareId)
{
    QString body = OnvifDeviceHelper::getFile(":/onvifresponse/GetDeviceInformation.xml");
    body = body.arg(hardwareId);
    return OnvifListenHelper::getData(body);
}

QByteArray OnvifListenHelper::getScopes()
{
    QString body = OnvifDeviceHelper::getFile(":/onvifresponse/GetScopes.xml");
    return OnvifListenHelper::getData(body);
}

QByteArray OnvifListenHelper::getHostname()
{
    QString body = OnvifDeviceHelper::getFile(":/onvifresponse/GetHostname.xml");
    return OnvifListenHelper::getData(body);
}

QByteArray OnvifListenHelper::getNetworkDefaultGateway(const QString &url)
{
    //网关强制把末尾地址改成1
    QString ip = OnvifDeviceHelper::getUrlIP(url);
    ip = ip.section('.', 0, 2) + ".1";

    QString body = OnvifDeviceHelper::getFile(":/onvifresponse/GetNetworkDefaultGateway.xml");
    body = body.arg(ip);
    return OnvifListenHelper::getData(body);
}

QByteArray OnvifListenHelper::getDNS()
{
    QString body = OnvifDeviceHelper::getFile(":/onvifresponse/GetDNS.xml");
    body = body.arg("114.114.114.114");
    return OnvifListenHelper::getData(body);
}

QByteArray OnvifListenHelper::getNetworkInterfaces(const QString &ip)
{
    QString body = OnvifDeviceHelper::getFile(":/onvifresponse/GetNetworkInterfaces.xml");
    body = body.arg("15-A3-65-32-B5-E8").arg(ip);
    return OnvifListenHelper::getData(body);
}

QByteArray OnvifListenHelper::getAnalyticsModules()
{
    QString body = OnvifDeviceHelper::getFile(":/onvifresponse/GetAnalyticsModules.xml");
    return OnvifListenHelper::getData(body);
}

QByteArray OnvifListenHelper::getSupportedAnalyticsModules()
{
    QString body = OnvifDeviceHelper::getFile(":/onvifresponse/GetSupportedAnalyticsModules.xml");
    return OnvifListenHelper::getData(body);
}

QByteArray OnvifListenHelper::getVideoEncoderConfiguration()
{
    QString body = OnvifDeviceHelper::getFile(":/onvifresponse/GetVideoEncoderConfiguration.xml");
    return OnvifListenHelper::getData(body);
}

QByteArray OnvifListenHelper::getVideoEncoderConfigurationOptions()
{
    QString body = OnvifDeviceHelper::getFile(":/onvifresponse/GetVideoEncoderConfigurationOptions.xml");
    return OnvifListenHelper::getData(body);
}

QByteArray OnvifListenHelper::getEventProperties()
{
    QString body = OnvifDeviceHelper::getFile(":/onvifresponse/GetEventProperties.xml");
    return OnvifListenHelper::getData(body);
}

QByteArray OnvifListenHelper::createPullPointSubscription(const QString &url, int timeout)
{
    QString currentTime, terminationTime;
    OnvifListenHelper::getDateTime(&currentTime, &terminationTime, timeout);

    QString body = OnvifDeviceHelper::getFile(":/onvifresponse/CreatePullPointSubscription.xml");
    body = body.arg(url, currentTime, terminationTime);
    return OnvifListenHelper::getData(body);
}

QByteArray OnvifListenHelper::pullMessages(const QList<OnvifEventPara> &events, int timeout)
{
    QString currentTime, terminationTime;
    OnvifListenHelper::getDateTime(&currentTime, &terminationTime, timeout);

    QString body = OnvifDeviceHelper::getFile(":/onvifresponse/PullMessages.xml");
    QString message = OnvifXmlData::getMessage(events);
    body = body.arg(currentTime, terminationTime, message);
    return OnvifListenHelper::getData(body);
}

QByteArray OnvifListenHelper::renew(int timeout)
{
    QString currentTime, terminationTime;
    OnvifListenHelper::getDateTime(&currentTime, &terminationTime, timeout);

    QString body = OnvifDeviceHelper::getFile(":/onvifresponse/Renew.xml");
    body = body.arg(currentTime, terminationTime);
    return OnvifListenHelper::getData(body);
}

QByteArray OnvifListenHelper::unsubscribe()
{
    QString body = OnvifDeviceHelper::getFile(":/onvifresponse/Unsubscribe.xml");
    return OnvifListenHelper::getData(body);
}

QByteArray OnvifListenHelper::getSnapshotUri(const QString &token, const QString &url)
{
    QString uri = url + "/snapshot?" + token;
    QString body = OnvifDeviceHelper::getFile(":/onvifresponse/GetSnapshotUri.xml");
    body = body.arg(uri);
    return OnvifListenHelper::getData(body);
}

QByteArray OnvifListenHelper::getNodes(bool node)
{
    QString body = OnvifDeviceHelper::getFile(":/onvifresponse/GetNodes.xml");
    if (node) {
        body.replace("GetNodes", "GetNode");
    }

    return OnvifListenHelper::getData(body);
}

QByteArray OnvifListenHelper::getStatus()
{
    QString currentTime = OnvifListenHelper::getCurrentTime();
    QString body = OnvifDeviceHelper::getFile(":/onvifresponse/GetStatus.xml");
    body = body.arg(currentTime);
    return OnvifListenHelper::getData(body);
}

QByteArray OnvifListenHelper::getPresets(const QStringList &presets)
{
    QString body = OnvifDeviceHelper::getFile(":/onvifresponse/GetPresets.xml");
    body = body.arg(OnvifXmlData::getPresets(presets));
    return OnvifListenHelper::getData(body);
}

QByteArray OnvifListenHelper::getFault(const QString &codeValue, const QString &subCodeValue, const QString &reasonText)
{
    QString body = OnvifDeviceHelper::getFile(":/onvifresponse/Fault.xml");
    body = body.arg(codeValue, subCodeValue, reasonText);
    return OnvifListenHelper::getData(body, "400 Bad Request");
}

QByteArray OnvifListenHelper::getNotAuthorized()
{
    QString codeValue = "s:Sender";
    QString subCodeValue = "ter:NotAuthorized";
    QString reasonText = "Sender not Authorized. Invalid username or password!";
    return OnvifListenHelper::getFault(codeValue, subCodeValue, reasonText);
}

QByteArray OnvifListenHelper::getActionNotSupported()
{
    QString codeValue = "s:Sender";
    QString subCodeValue = "ter:ActionNotSupported";
    QString reasonText = "This optional method is not implemented";
    return OnvifListenHelper::getFault(codeValue, subCodeValue, reasonText);
}

QByteArray OnvifListenHelper::getResponse(const QString &cmd)
{
    return OnvifListenHelper::getResponseFull(cmd + "Response");
}

QByteArray OnvifListenHelper::getResponseFull(const QString &response)
{
    QString body = OnvifDeviceHelper::getFile(":/onvifresponse/Response.xml");
    body = body.arg(response);
    return OnvifListenHelper::getData(body);
}
posted @ 2026-06-05 09:17  飞扬青云  阅读(111)  评论(1)    收藏  举报