One, foreword

Round but onvif do video monitoring system, this thing, it is mainly a general standard for unity, to each manufacturer of some commonly used monitoring devices for operation, such as search, access to information, yuntai control, event subscription, snapping pictures and so on, if you don’t have this specification, then each manufacturer are fragmented, Need to use private SDK to deal with, so it is very troublesome very miserable, dozens of manufacturers need dozens of SDK, for programmers is simply a disaster, think of it is a terrible thing, which programmers do not want to live a few years!

Onvif device search is the most basic function. If you want to perform further processing on devices, you must first search for devices. By default, onVIf search can only search devices on the same network segment. Experienced a variety of complex site conditions of the test, can also be a small feature of the system.

Main features of Onvif

  1. Search for device information such as manufacturer and model.
  2. Obtain multiple profile information profiles of the device.
  3. Obtain the video stream address RTSP and resolution of the corresponding configuration file.
  4. Head control, up and down, left and right movement, zoom in and out, relative and absolute movement.
  5. Gets preset bit information to trigger a preset bit.
  6. Subscribe to events and receive various messages from devices, especially alarm events such as IO port alarm.
  7. Capture the current picture of the device.
  8. Obtain, create, and delete user information.
  9. Get and device network configuration information such as IP address.
  10. Gets and sets NTP time synchronization.
  11. Gets and sets the device time.
  12. Restart the device.

Onvif processing flow

  1. Bind multicast IP (239.255.255.250) to port (3702) and send fixed XML format data to the search device.
  2. The received XML data is parsed to obtain the Onvif address of the device.
  3. Send the corresponding data to the Onvif address, and get the corresponding node data after receiving the data.
  4. The Onvif address is requested to obtain the Media address and Ptz address. The Media address is used to obtain the detailed configuration file, and the Ptz address is used for Ptz control.
  5. PTZ control is to send corresponding data to the PTZ address.
  6. If user authentication is configured, the user token information needs to be sent together and authentication is required each time.
  7. The received data is not standard XML data and cannot be processed with normal node parsing, only with QXmlQuery.
  8. The data returned by each manufacturer’s devices may not be completely consistent, which requires fuzzy search for node values.
  9. The underlying protocol resolution is intentionally used because SOAP is too bloated and the function name is too exotic, so it is intentionally lightweight.
  10. Two required tools, Onvif Device Manager and Onvif Device Test Tool.

Two, functional characteristics

Software modules

  1. Video monitoring module, various docking small window sub-module, including device list, graphic warning, window information, panyt 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 setting module, including system Settings (basic Settings, video parameters, database Settings, map configuration, serial port configuration, etc.), VIDEO recorder management, camera management, polling configuration, user management, etc.

Basis function

  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. Supports full-screen switching, including the right mouse button, toolbar button, and shortcut keys (Alt + Enter full-screen, esc exit full-screen).
  4. Supports video polling, including 1, 4, 9, and 16 screen polling. You can set polling group (polling plan), polling interval, and bit stream type.
  5. Supports the OnVIF protocol, including device search, pte control, device control (picture parameters, check time, system restart, capture pictures, etc.).
  6. Different users can have different module permissions, such as deleting logs and shutting down the system.
  7. Support a variety of databases, including sqlite, mysql, sqlserver, postgresql, oracle, rendajincang and so on.
  8. You can set resolution and frame rate for a local USB camera.
  9. All docking modules automatically generate corresponding menus to control the display and hide, in the title bar right click can pop up.
  10. Display all modules, hide all modules, reset the common layout, and reset the full-screen layout.
  11. Double-click the device to pop up real-time preview video, supporting picture map, online map, offline map, etc.
  12. The camera node can be dragged to the corresponding window to play the video, and the local file can be dragged to play the video.
  13. You can delete a video by right-clicking the mouse button, closing the floating bar, or dragging it outside the video surveillance panel.
  14. The device button on the picture map can be dragged freely to automatically save the location information. You can click the mouse to obtain the longitude and latitude information on the Baidu map to update the location of the device.
  15. Any channel in the video surveillance panel form supports drag exchange, instant response.
  16. Encapsulated Baidu map, view switch, movement track, equipment point, mouse click to obtain latitude and longitude.
  17. Double-click the node, drag the node, drag the window to switch positions and other operations, will automatically update and save the last playing address, the next software open automatic application.
  18. Volume bar control in the lower right corner, automatically hide when losing focus, volume strip mute icon.
  19. You can specify a screenshot for a single channel or all channels. The screenshot button is also available on the bottom toolbar.
  20. The mouse pointer can be automatically hidden when timeout expires and the mouse pointer can be automatically displayed in full screen.
  21. Support onVIF PTZ control, can move PTZ camera up, down, left and right, including reset and focal length adjustment.
  22. Support any ONVIF camera, including but not limited to Hikang, Dahua, Yushi, Weiye, Huawei, etc.
  23. Can save video, can select the time storage or single file storage, optional storage interval time.
  24. Video stream communication mode can be set TCP + UDP, video decoding can be set speed first, quality first, balance, etc.
  25. You can set the software name, English name, and LOGO icon.
  26. You can export stored video files to specific directories or upload them to servers in batches.

features

  1. The main interface adopts the mode of docked form, various components in the form of small modules, can be customized to join any module.
  2. Docking module can drag any position embedded and suspended, support maximum full screen, support multi-screen.
  3. Dual layout file storage mechanism, normal mode and full-screen mode are corresponding to different layout schemes, automatic switching and saving, for example, full-screen mode can highlight several modules transparent display in the specified position, more science fiction sense of modernization.
  4. Original onVIF protocol mechanism, using the underlying protocol resolution (UDP broadcast search + HTTP request execution command) more lightweight easy to understand learning expansion, does not rely on any third-party components such as GSOAP.
  5. Original data import and export mechanism, cross-platform independent of any components, instant data export.
  6. Built in multiple original components, the universe super value super awesome, Including data import and export components (export to XLS, PDF, printing), database components (database management thread, automatic data cleaning thread, universal paging, data request, etc.), map component, video monitoring component, file multithreading transceiver component, onVIF communication component, universal browser kernel component, etc.
  7. Customize information box + error box + query box + lower right prompt box (including various formats).
  8. Exquisite skin change, up to 17 sets of skin styles can be changed at will, all styles are unified, including menu, etc.
  9. Multiple buttons can be added to the video control hover bar, and buttons can also be added to the small toolbar at the bottom of the monitoring interface.
  10. Double click the camera node to automatically play the video, double click the node to automatically add the video, it will automatically jump to the next, double click the parent node to automatically add all the videos under the node. Primary stream and sub-stream are optional.
  11. You can add, delete, and modify the import and export printed information, and immediately apply the new device information to generate a tree list without restarting.
  12. Optional a variety of kernel free switch, FFMPEG, VLC, MPV, etc., can be set in pro. Ffmpeg is recommended. It is most cross-platform and provides libraries compiled on Linux and MAC platforms by default.
  13. Supports hard decoding and can be set to hard decoding type (QSV, DXVA2, d3D11VA, etc.).
  14. The default opengL rendering video, ultra-low CPU resource consumption, support YUYV and NV12 two formats to draw, very awesome.
  15. Highly customizable, users can easily derive their own functions on this basis, such as adding custom modules, adding operation mode, robot monitoring, uav monitoring, excavator monitoring, etc.
  16. Support XP, Win7, Win10, Linux, MAC, a variety of domestic systems (UOS, kyrin, Galaxy Kyrin, etc.), embedded Linux and other systems.
  17. Complete annotation, clear project structure, super detailed complete use of the development manual, accurate to the function description of each code file, continuous iteration version.

3. Experience address

  1. Experience address: pan.baidu.com/s/1d7TH_GEY… Extraction code: 01Jf File name: bin_video_system.zip
  2. Domestic site: gitee.com/feiyangqing…
  3. International site: github.com/feiyangqing…
  4. Profile: blog.csdn.net/feiyangqing…
  5. Zhihu homepage: www.zhihu.com/people/feiy…

Four, effect drawing

Five, core code

OnvifSearch::OnvifSearch(QObject *parent) : QObject(parent)
{
    isOk = false;
    // Timers queue to send search commands. There are several kinds
    timer = new QTimer(this);
    connect(timer, SIGNAL(timeout()), this.SLOT(sendData()));
    timer->setInterval(300);
    currentIP = "127.0.0.1";

    udpSocket = new QUdpSocket(this);
#if(QT_VERSION > = QT_VERSION_CHECK,8,5 (4))
    udpSocket->setSocketOption(QAbstractSocket::MulticastLoopbackOption, 1);
#endif
    connect(udpSocket, SIGNAL(readyRead()), this.SLOT(readData()));
}

OnvifSearch::~OnvifSearch()
{
    if (timer->isActive()) {
        timer->stop();
    }
}

void OnvifSearch::sendData(a)
{
    // Send data one by one, stop if you reach the last one
    // According to the onvif Device Test tool packet capture analysis, just send the first two, the last two are captured by onvif Device Manager
    Filter duplicates where results are received, since some devices return both protocol requests
    writeData("239.255.255.250");
    if (currentFile == ":/send/searchDevice1.xml") {
        currentFile = ":/send/searchDevice2.xml";
    } else if (currentFile == ":/send/searchDevice2.xml") {
        currentFile = ":/send/searchDevice3.xml";
    } else if (currentFile == ":/send/searchDevice3.xml") {
        currentFile = ":/send/searchDevice4.xml";
    } else if (currentFile == ":/send/searchDevice4.xml") {
        timer->stop();
    }
}

void OnvifSearch::writeData(const QString &ip)
{
    QByteArray data = OnvifHelper::getFile(currentFile);
    if(! data.isEmpty()) {
        data = QString(data).arg(OnvifHelper::getUuid()).toUtf8(a); udpSocket->writeDatagram(data, QHostAddress(ip), 3702);
        emit sendData(data); }}void OnvifSearch::readData(a)
{
    QByteArray data;
    QHostAddress host;
    quint16 port = 0;
    while (udpSocket->hasPendingDatagrams()) {
        data.resize(udpSocket->pendingDatagramSize());
        udpSocket->readDatagram(data.data(), data.size(), &host, &port);
        emit receiveData(data);
    }

    checkData(data);
}

void OnvifSearch::readData(const QString &file)
{
    // Read data from file parsing, mainly used to test the data returned by various cameras
    QFile f(file);
    if (f.open(QFile::ReadOnly)) {
        QByteArray data = f.readAll(a); data = data.replace("\ \ \" "."\" ");
        checkData(data); }}void OnvifSearch::checkData(const QByteArray &data)
{
    OnvifQuery query;
    query.setData(data);

    QString discovery = query.getDiscovery(a); QString addr_path =QString("//%1:ProbeMatches/%1:ProbeMatch/%1:XAddrs").arg(discovery);
    QString scopes_path = QString("//%1:ProbeMatches/%1:ProbeMatch/%1:Scopes").arg(discovery);
    QString addr = query.getValue(addr_path);
    QString scopes = query.getValue(scopes_path);

    if(! addr.isEmpty()) {
        / / filter under IPV6 address http://192.168.1.64/onvif/device_service http:// [fe80: : 9 a8b: 20: fe6e: 867 c] / onvif/device_service
        QStringList list = addr.split("");
        addr = list.first(a);if (checkExist(addr)) {
            return;
        }

        // Define the structure storage device information
        DeviceInfo deviceInfo;
        deviceInfo.addr = addr;
        deviceInfo.ip = OnvifHelper::getIP(addr);

        / / remove other information onvif://www.onvif.org/type/NetworkVideoTransmitter onvif://www.onvif.org/name/NVR onvif://www.onvif.org/hardware/hisi onvif://www.onvif.org/location/shanghai
        // The information is returned by broadcast search without the need for a password, and device information can be added to the scopes printed at the same time
        list = scopes.split("");
        foreach (QString str, list) {
            QStringList l = str.split("/");
            if (l.contains("name")) {
                deviceInfo.name = l.last(a); }else if (l.contains("location")) {
                deviceInfo.location = l.last(a); }else if (l.contains("hardware")) {
                deviceInfo.hardware = l.last(a); } } deviceInfos << deviceInfo;emit receiveDevice(deviceInfo);
        emit receiveInfo(QString("New device found -> %1").arg(addr)); }}Copy the code