Qt writes video surveillance system 77-Onvif components to support abnormal time equipment

I. Introduction

After going through a lot of on-site equipment testing, at least dozens of manufacturers and hundreds of equipment, I have encountered strange problems, and tried to solve them one by one. I found that there is a problem that needs to be brought when the authentication is issued. Time, not the time of the sender, if it is not the time on the device, the authentication may fail. This problem has been tested by more than a dozen various video surveillance system clients on the market, but none of them have been implemented. Through packet capture analysis, the authentication information carried by the client software is the local time, not the time of the device, which makes it impossible to pass The onvif protocol is used to load the device. This experience is very unfriendly, because it is likely that the device was manufactured in 1970 or 2000, etc., and the device may not have a battery. After a long time after power failure, the time is likely to be restored. , and the setting date and time command also needs to bring authentication information, but fortunately, the date and time command does not require authentication information, so through this as a breakthrough, before the first command that requires authentication information, actively obtain the date of the next device Time, and then compare it with the local time to take out a second difference (how many seconds is the difference between the time on the device and the local time). If the device is in 2000, the difference is a very large negative value. When preparing the authentication information When it is time, just take the local time and add this difference, so that the time sent is equivalent to the time on the device. If the time on the device has been updated, you need to obtain the time again.

Onvif component function design:

  • Search for devices to obtain device information such as manufacturer and model.
  • You can specify the network card to search, and there may be multiple network cards and multiple network segment addresses.
  • You can manually specify a single device address search, which is used when the multicast search fails but the network works.
  • You can choose to count up the searched devices in an accumulative way, which is especially necessary in the case of a large number of devices across network segments.
  • Get multiple configuration file information profile of the device.
  • Obtain the video stream address rtsp of the corresponding configuration file, and parameters such as resolution.
  • PTZ control, move up and down, left and right, focus zoom in and out, relative and absolute movement.
  • Obtain preset position information, add, delete, modify and query, and trigger preset positions.
  • Subscribe to events and receive various messages from devices, especially alarm events such as IO port alarms.
  • Grab a picture to get the current picture of the device.
  • Obtain and device network configuration information such as IP address, etc.
  • Get and set NTP time synchronization and set device time.
  • Get and set video parameters and picture parameters (brightness, color, saturation).
  • Reboot the device.
  • Add, delete, modify, query OSD information.

2. Rendering

insert image description here

3. Experience address

  1. Domestic site: https://gitee.com/feiyangqingyun
  2. International site: https://github.com/feiyangqingyun
  3. Personal works: https://blog.csdn.net/feiyangqingyun/article/details/97565652
  4. Experience address: https://pan.baidu.com/s/1d7TH_GEYl5nOecuNlWJJ7g Extraction code: 01jf File name: bin_video_system.

4. Related codes

QString OnvifOther::getDateTime()
{
    
    
    QString result = writeData("GetSystemDateAndTime", "tt:Year|tt:Month|tt:Day|tt:Hour|tt:Minute|tt:Second|tt:TZ", "获取设备时间", true, true);
    QStringList list = result.split(OnvifResultSplit);
    if (list.count() != 7) {
    
    
        return result;
    }

    QString year = getResult(list.at(0));
    QString month = getResult(list.at(1));
    QString day = getResult(list.at(2));
    QString hour = getResult(list.at(3));
    QString min = getResult(list.at(4));
    QString sec = getResult(list.at(5));

    //计算时区并赋值
    QString timezone = list.at(6);
    timezone = timezone.mid(6, timezone.length() - 6);
    device->timezone = timezone;

    //将日期根据时区进行运算
    QString str = QString("%1-%2-%3 %4:%5:%6").arg(year).arg(month).arg(day).arg(hour).arg(min).arg(sec);
    QDateTime dt = QDateTime::fromString(str, "yyyy-M-d h:m:s");
    if (!device->timezone.contains("GMT-08")) {
    
    
        dt = dt.addSecs(8 * 60 * 60);
    }

    //2023-05-22 新增时间差值计算(有些设备需要用设备的时间去鉴权)
    device->timeOffset = QDateTime::currentDateTime().secsTo(dt);

    //不足两位补零
    list = dt.toString("yyyy-M-d-h-m-s").split("-");
    result = QString("%1-%2-%3 %4:%5:%6 %7").arg(list.at(0)).arg(list.at(1), 2, '0').arg(list.at(2), 2, '0')
             .arg(list.at(3), 2, '0').arg(list.at(4), 2, '0').arg(list.at(5), 2, '0').arg(timezone);
    return result;
}

bool OnvifOther::setDateTime(const QDateTime &datetime, bool ntp)
{
    
    
    QStringList temp = datetime.toString("yyyy-M-d-h-m-s").split("-");
    QString wsdl = "http://www.onvif.org/ver10/device/wsdl";
    QString schema = "http://www.onvif.org/ver10/schema";

    QStringList list;
    list << QString("    <SetSystemDateAndTime xmlns=\"%1\">").arg(wsdl);
    list << QString("      <DateTimeType>%1</DateTimeType>").arg(ntp ? "NTP" : "Manual");
    list << QString("      <DaylightSavings>%1</DaylightSavings>").arg("false");
    list << QString("      <TimeZone>");
    list << QString("        <TZ xmlns=\"%1\">%2</TZ>").arg(schema).arg(ntp ? device->timezone : "CST-8");
    list << QString("      </TimeZone>");

    if (!ntp) {
    
    
        list << QString("      <UTCDateTime>");
        list << QString("        <Date xmlns=\"%1\">").arg(schema);
        list << QString("          <Year>%1</Year>").arg(temp.at(0));
        list << QString("          <Month>%1</Month>").arg(temp.at(1));
        list << QString("          <Day>%1</Day>").arg(temp.at(2));
        list << QString("        </Date>");
        list << QString("        <Time xmlns=\"%1\">").arg(schema);
        list << QString("          <Hour>%1</Hour>").arg(temp.at(3));
        list << QString("          <Minute>%1</Minute>").arg(temp.at(4));
        list << QString("          <Second>%1</Second>").arg(temp.at(5));
        list << QString("        </Time>");
        list << QString("      </UTCDateTime>");
    }

    list << QString("    </SetSystemDateAndTime>");

    QString result = writeData(list.join("\r\n"), "SetSystemDateAndTimeResponse", "设置设备时间", false);
    return result.contains("SetSystemDateAndTimeResponse");
}

QString OnvifXml::getUserToken(const QString &userName, const QString &userPwd, qint64 timeOffset)
{
    
    
    //要转成UTC格式的时间 "2019-08-10T03:31:37S"  "2020-10-11T09:24:44.988Z"
    //有些设备需要按照设备上的时间来鉴权(否则会失败)
    QDateTime DateTime = QDateTime::currentDateTime().addSecs(timeOffset).toUTC();
    QByteArray Created = DateTime.toString("yyyy-MM-ddThh:mm:ss.zzzZ").toLatin1();

    //指定字符串进行密码加密 LKqI6G/AikKCQrN0zqZFlg==
    QByteArray Nonce = Created.toBase64();
    QByteArray Nonce2 = QByteArray::fromBase64(Nonce);
    QByteArray Password = Nonce2 + Created + userPwd.toLatin1();
    Password = QCryptographicHash::hash(Password, QCryptographicHash::Sha1).toBase64();

    //固定字符串
    QString Enter = "\r\n        ";
    QString Type = "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordDigest";
    QString EncodingType = "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary";
    QString xmlns = "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd";

    QStringList list;
    if (wsseToken) {
    
    
        list << QString("%1<wsse:Username>%2</wsse:Username>").arg(Enter).arg(userName);
        list << QString("%1<wsse:Password Type=\"%2\">%3</wsse:Password>").arg(Enter).arg(Type).arg(QString(Password));
        list << QString("%1<wsse:Nonce>%2</wsse:Nonce>").arg(Enter).arg(QString(Nonce));
        list << QString("%1<wsu:Created>%2</wsu:Created>").arg(Enter).arg(QString(Created));
    } else {
    
    
        list << QString("%1<Username>%2</Username>").arg(Enter).arg(userName);
        list << QString("%1<Password Type=\"%2\">%3</Password>").arg(Enter).arg(Type).arg(QString(Password));
        list << QString("%1<Nonce EncodingType=\"%2\">%3</Nonce>").arg(Enter).arg(EncodingType).arg(QString(Nonce));
        list << QString("%1<Created xmlns=\"%2\">%3</Created>").arg(Enter).arg(xmlns).arg(QString(Created));
    }

    list << QString("%1").arg("\r\n      ");
    return list.join("");
}

5. Features

5.1 Software modules

  1. Video monitoring module, various docking small window sub-modules, including device list, graphic alarm information, window information, PTZ control, preset position, cruise setting, device control, floating map, web browsing, etc.
  2. Video playback module, including local playback, remote playback, device playback, picture playback, video upload, etc.
  3. Electronic map module, including picture map, online map, offline map, path planning, etc.
  4. Log query module, including local logs, device logs, etc.
  5. System settings module, including system settings (basic settings, video parameters, database settings, map configuration, serial port configuration, etc.), video recorder management, camera management, polling configuration, recording plan, user management, etc.

5.2 Basic functions

  1. Support various video streams (rtsp, rtmp, http, etc.), video files (mp4, rmvb, avi, etc.), local USB camera playback.
  2. Support multi-screen switching, including 1, 4, 6, 8, 9, 13, 16, 25, 36, 64 screen switching.
  3. Support full screen switching, a variety of switching methods including the right mouse button menu, toolbar buttons, shortcut keys (alt+enter full screen, esc to exit full screen).
  4. Support video polling, including 1, 4, 9, 16 screen polling, and can set polling group (polling plan), polling interval, code stream type, etc.
  5. Support onvif protocol, including device search, PTZ control, preset position, device control (picture parameters, proofreading time, system restart, snapshot pictures, etc.).
  6. Support permission management, different users can correspond to different module permissions, such as deleting logs, shutting down the system, etc.
  7. Various databases are supported, including sqlite, mysql, sqlserver, postgresql, oracle, Renda Jincang, etc.
  8. The local USB camera supports setting parameters such as resolution and frame rate.
  9. All docking modules automatically generate corresponding menus to control display and hide, which can be popped up by right clicking on the title bar.
  10. Support display all modules, hide all modules, reset normal layout, reset full screen layout.
  11. Double-click the device to pop up a real-time preview video, supporting image maps, online maps, offline maps, etc.
  12. Drag the camera node to the corresponding window to play the video, and support dragging local files to play directly.
  13. Deleting videos supports multiple methods such as right mouse button deletion, suspension bar closing deletion, dragging to the outside of the video monitoring panel to delete, etc.
  14. The device button on the picture map can be dragged freely, and the location information is automatically saved. On the Baidu map, you can click the mouse to obtain the latitude and longitude information, which is used to update the device location.
  15. Any channel in the video monitoring panel window supports dragging and switching, and responds instantly.
  16. It encapsulates Baidu map, view switching, movement track, equipment point, mouse press to obtain latitude and longitude, etc.
  17. Operations such as double-clicking a node, dragging a node, or dragging a window to exchange positions, etc., will automatically update and save the last playback address, which will be automatically applied next time the software is opened.
  18. The volume bar control in the lower right corner, loses focus and automatically hides, and the volume bar has a mute icon.
  19. Support video screenshot, you can specify a single or screenshot of all channels, and there is also a screenshot button in the small toolbar at the bottom.
  20. Support overtime automatically hide the mouse pointer, automatic full screen mechanism.
  21. Support onvif PTZ control, you can move the PTZ camera up, down, left, and right, including reset and focus adjustment.
  22. Support onvif preset position, you can add, delete, modify the preset position, you can call the start position.
  23. Support onvif image parameter settings, including brightness, contrast, saturation, sharpness, etc.
  24. Support other operations of onvif, including image capture, network settings, time adjustment, restart, event subscription, etc.
  25. Support any onvif camera, including but not limited to Hikvision, Dahua, Uniview, Tiandiweiye, Huawei, etc.
  26. Video can be saved, with optional timing storage or single file storage, and optional storage interval.
  27. You can set the video stream communication mode tcp+udp, and you can set the video decoding speed priority, quality priority, balance, etc.
  28. You can set the software Chinese name, English name, LOGO icon, etc.
  29. Stored video files can be exported to a specified directory and uploaded to the server in batches.
  30. Perfect recording plan settings, support for each channel 7 * 24 hours every half hour to set whether to store recordings.

5.3 Features

  1. The main interface adopts the docking form mode, and various components are added in the form of small modules, and any module can be customized.
  2. The docking module can be dragged anywhere to embed and float, and it supports maximizing full screen and multiple screens.
  3. Dual layout file storage mechanism, normal mode and full-screen mode correspond to different layout schemes, automatically switch and save, for example, full-screen mode can highlight several modules and display them transparently in the designated position, which is more sci-fi and modern.
  4. The original onvif protocol mechanism adopts the underlying protocol analysis (udp broadcast search + http request execution command), which is lighter, easier to understand and easier to learn and expand, and does not rely on any third-party components such as gsoap.
  5. Original data import, export, and print mechanisms, cross-platform without relying on any components, and instantly export data.
  6. Multiple built-in original components, super value in the universe, including data import and export components (export to xls, pdf, printing), database components (database management thread, automatic cleaning data thread, universal paging, data request, etc.), map components , video monitoring components, multi-threaded file sending and receiving components, onvif communication components, common browser kernel components, etc.
  7. Custom information box + error box + inquiry box + prompt box in the lower right corner (including multiple formats), etc.
  8. Exquisite skinning, up to 17 sets of skin styles can be changed at will, all styles are unified, including menus, etc.
  9. The video control floating bar can add multiple buttons by itself, and the small toolbar at the bottom of the monitoring interface can also add buttons by itself.
  10. Double-click the camera node to automatically play the video, double-click the node to automatically add videos in sequence, and automatically jump to the next one, double-click the parent node to automatically add all videos under the node. Optional main stream and sub stream.
  11. Video recorder management, camera management, can add, delete, modify, import, export and print information, and immediately apply the new device information to generate a tree list without restarting.
  12. A variety of kernels can be selected to switch freely, ffmpeg, vlc, mpv, etc., can be set in pro. It is recommended to use ffmpeg, which is the most cross-platform, and the compiled libraries on the linux and mac platforms are provided by default.
  13. Support hard decoding, you can set the hard decoding type (qsv, dxva2, d3d11va, etc.).
  14. By default, opengl is used to draw video, ultra-low CPU resource usage, supports yuyv and nv12 two formats of drawing, and the performance is explosive.
  15. Labels and graphic information support three drawing methods, drawing to the mask layer, drawing to the picture, and drawing from the source (corresponding information can be stored in a file).
  16. Highly customizable, users can easily derive their own functions on this basis, such as adding custom modules, adding operation modes, robot monitoring, drone monitoring, excavator monitoring, etc.
  17. Support xp, win7, win10, win11, linux, mac, various domestic systems (UOS, Winning Kirin, Galaxy Kirin, etc.), embedded linux and other systems.
  18. The comments are complete, the project structure is clear, the super detailed and complete user development manual is accurate to the function description of each code file, and the version is continuously iterated.

Guess you like

Origin blog.csdn.net/feiyangqingyun/article/details/130941229