Multifunctional real-time imaging platform
By designing a multi-functional real-time imaging platform, we solve the problems of single function, poor compatibility and high delay of traditional video surveillance systems, achieve low-latency video transmission and flexible monitoring functions, support multi-platform compatibility and high concurrency scenarios, and improve Monitor system effectiveness and user experience.
Patent Information
- Application Number
- CN202410817075.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-06-24
- Publication Date
- 2024-10-01
- Estimated Expiration
- 2044-06-24
AI Technical Summary
Traditional video surveillance systems have single functions, lack flexible control, poor cross-platform compatibility, inconvenient remote access, and high latency, which affect the effectiveness of surveillance and user experience.
A multifunctional real-time imaging platform is designed, which uses a Web client to support multi-platform compatibility. It achieves high concurrency through thread pools, non-blocking sockets and epoll models. It performs video streaming based on the FLV streaming media format and supports Camera remote setup and upgrades.
It achieves low-latency real-time video transmission, provides a flexible video surveillance solution, supports high concurrency scenarios, has good compatibility and easy portability, and ensures the universality and security of the system.
Smart Images

Figure CN118741046A_ABST
Abstract
Description
Technical Field
[0001] The invention belongs to the technical fields of imaging, video transmission, video monitoring, etc., and in particular relates to a multifunctional real-time imaging platform. Background Art
[0002] Traditional video surveillance systems are relatively simple in function and lack flexible control over cameras. This limitation makes it impossible for users to adjust the video in real time according to actual needs, which seriously affects the effectiveness and flexibility of monitoring. In addition, most monitoring systems use a host computer, which has disadvantages such as poor cross-platform compatibility and inconvenient remote access.
[0003] In terms of real-time video streaming transmission technology, traditional technical solutions have high latency problems and are difficult to meet the needs of low-latency applications. Solutions based on RTMP (Real-Time Messaging Protocol) and HLS (HTTP Live Streaming) were common transmission technologies in the early days. Although RTMP has relatively low latency, it is gradually being abandoned by modern browsers due to its reliance on Flash plug-ins. HLS was originally designed to provide stability and compatibility, but its sharding mechanism usually causes a latency of 5-10 seconds or even higher, making it impossible to achieve low-latency real-time video transmission.
[0004] In addition, early video streaming solutions also had problems with browser compatibility. Many solutions rely on plug-ins or specific browser features, such as RTMP relying on Flash plug-ins. Flash plug-ins not only have security risks, but are also gradually being eliminated by major browsers. This leads to poor compatibility of these solutions in modern browsers, affecting the user's viewing experience and the universality of the system.
[0005] In summary, traditional video surveillance systems have obvious deficiencies in terms of functions, platform compatibility, remote access, and browser compatibility. These problems limit the application and development of surveillance systems, and it is necessary to improve and optimize existing technical solutions to provide more flexible, efficient, and secure surveillance solutions. Summary of the invention
[0006] The purpose of the present invention is to address the deficiencies of traditional video surveillance systems and to propose a multifunctional real-time imaging platform that supports high concurrency, cross-platform compatibility, easy transplantation, strong real-time performance, and supports remote camera settings and upgrades.
[0007] The present invention mainly solves the problems of traditional video surveillance systems through the following approaches: 1. Using the Web end as the client, it supports multi-platform compatibility, remote camera settings and upgrades. 2. Based on the FLV streaming media format, it solves the problems of large delay and poor compatibility in traditional video streaming technology. 3. Through the high-performance concurrent model, it can be better applied to high-concurrency scenarios.
[0008] The object of the present invention is achieved through the following technical solutions: a multifunctional real-time imaging platform, including a server and a client; the server is built based on the Linux system, and its concurrency model is realized by a thread pool, a non-blocking socket, an epoll based on a level trigger, and a Reactor event processing model; the design process of the server and the client includes:
[0009] (1) creating a thread pool, which includes a worker thread, a streaming thread, and an upgrade thread, and presetting a maximum capacity of worker threads for the thread pool;
[0010] (2) Create a socket through socket, set it to non-blocking mode using fcntl, then bind it to the server's IP address and specified port, and call bind and listen to start listening for client connection requests; call epoll_create to create an epoll instance, use epoll_ctl to register the socket to the epoll instance, and listen to readable events on the socket to notify the main thread when a new client connection request is received;
[0011] (3) In the main thread, epoll_wait is used to monitor the readable events on the socket. If a readable event is detected on the socket, accept is called to accept the new client connection request and return the new socket. The new socket is configured in non-blocking mode. epoll_ctl is used to register the new socket with the epoll instance and monitor the readable events on the new socket. When a readable event is detected on the new socket, recv is called in a loop until the complete HTTP request is read and the completed HTTP request is added to the request queue.
[0012] (4) Get the task from the request queue, parse the HTTP request, generate the corresponding HTTP response according to the specific content of the HTTP request obtained by parsing, and call send in a loop to return the complete HTTP response to the client.
[0013] Furthermore, in the thread pool, the working thread is used to process client requests. In order to ensure that the streaming function and the upgrade function of the server are not affected by the working thread, a streaming thread and an upgrade thread are created separately.
[0014] Furthermore, in the thread pool, a higher thread priority is set for the streaming thread and the upgrading thread to ensure the priority during scheduling.
[0015] Furthermore, in step (4), if the HTTP request is the URL corresponding to the camera video stream preview request, the server distributes the task to the streaming thread, calls the streaming API interface in the camera SDK in the streaming thread, converts the RTMP video stream into an FLV video stream through the open source ZLMediaKit framework, places the FLV video stream in the main body of the HTTP response, calls send in a loop, returns the complete HTTP response to the client, and maintains a long connection to continue streaming.
[0016] Furthermore, after the client receives the FLV video stream from the server, it creates a new media extension source through MSE and associates the new media extension source with the HTML5 video element; it uses flv.js to process the FLV video stream, which parses the FLV file, encodes it into MP4 fragments, and loads the MP4 fragments into the media extension source, which then pushes the MP4 fragments to the associated HTML5 video element for playback.
[0017] Furthermore, in step (4), if the HTTP request is a URL corresponding to a Web login request, the server distributes the task to a work thread, in which the account and password in the request body of the HTTP request are parsed out respectively, and SQLite is used as a database; a connection is taken out from the database connection pool to access the database, and the parsed account and password are compared with the corresponding account and password in the database to verify whether they are equal, and the verification result is used as the main body of the HTTP response, and send is called in a loop to return the complete HTTP response to the client; if they are equal, the verification is passed, and the client enters the main page; if they are not equal, the verification fails, and the client stays on the login page.
[0018] Furthermore, in step (4), if the HTTP request is a URL corresponding to a camera image parameter configuration request, a camera device parameter configuration request, or a camera code stream parameter configuration request, the server distributes the task to the worker thread; if the HTTP request is a GET method request, the camera SDK related API interface is called to obtain relevant information and return it to the client; if the HTTP request is a POST method request, the camera SDK related API interface is called, and the setting result is returned to the client after the setting is successful.
[0019] Furthermore, in step (4), if the HTTP request is the URL corresponding to the camera SDK upgrade preprocessing request, the server distributes the task to the upgrade thread, and then completes the upgrade function according to the following sub-steps:
[0020] a) In the upgrade thread, the upgrade preparation identification field is placed in the body of the HTTP response, and send is called cyclically to return the complete HTTP response to the client, informing the client that the server is ready to receive the upgrade package, while maintaining a long connection;
[0021] b) The client receives the response returned by step a), reads a data segment of a preset length from the upgrade package file each time, puts the read data segment into the request body of the HTTP request, adds a preset length field to the header field of the HTTP request, and sends it to the server via the POST method;
[0022] c) The server obtains the task from the request queue and parses the HTTP request. If the camera upgrade package sends the corresponding URL, the task is distributed to the upgrade thread, the upgrade package file in the request body of the HTTP request is placed in the cache, and the size of the received upgrade package files is accumulated. During this period, the server does not make any relevant HTTP response reply;
[0023] d) After the client sends all the contents of the upgrade package file, it fills the number of bytes sent as a verification packet into the request body of the HTTP request and sends it to the server via the POST method to verify whether the upgrade package file on the server has been received completely;
[0024] e) The server obtains the task from the request queue and parses the HTTP request. If it is the URL corresponding to the camera verification package verification, the task is distributed to the upgrade thread, and the number of bytes sent in the request body of the HTTP request is compared with the number of bytes received in the server buffer. If they are equal, the verification passes, and the upgrade API interface in the camera SDK is called to enter the upgrade mode; if they are not equal, the verification fails, and the server puts the upgrade failure identification field in the body of the HTTP response, and calls send in a loop to return the complete HTTP response to the client. After receiving the HTTP response, the client starts the upgrade again according to step b) until the upgrade is successful.
[0025] Furthermore, the upgrade API interface in the camera SDK is called to enter the upgrade mode, specifically: the upgrade package files received in the cache area are gradually written into the firmware, and after writing, the camera is restarted and the upgrade package files are loaded. After the camera is started, the server puts the upgrade completion identification field in the body of the HTTP response, and calls send in a loop to return the complete HTTP response to the client, informing the client that the server has completed the upgrade, and calls close to close the current socket.
[0026] The beneficial effects of the present invention are as follows:
[0027] 1. The client implements real-time streaming based on HTTP+FLV+MSE. The implementation is simple and the delay time can be controlled within 1-2s.
[0028] 2. Provide a multifunctional real-time imaging platform that supports camera gimbal control, camera image parameter setting, camera code stream parameter setting, camera device parameter setting, and camera remote upgrade.
[0029] 3. The server uses the open source framework ZLMediaKit for FLV streaming, which has excellent performance and simple implementation.
[0030] 4. The server uses SQLite as the database to store some status data of the client, which is lightweight.
[0031] 5. The platform has good compatibility and can be easily ported to any camera that provides SDK with relevant functions.
[0032] 6. The server implements a high concurrency model through thread pools, non-blocking sockets, horizontally triggered epoll and Reactor event processing models, which can be better applied to high concurrency scenarios. BRIEF DESCRIPTION OF THE DRAWINGS
[0033] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0034] Figure 1 An overall design framework of a server of a multifunctional real-time imaging platform provided by an embodiment of the present invention.
[0035] Figure 2 An overall design framework of a client of a multifunctional real-time imaging platform provided by an embodiment of the present invention. DETAILED DESCRIPTION
[0036] In order to make the above-mentioned objects, features and advantages of the present invention more obvious and easy to understand, the specific embodiments of the present invention are described in detail below with reference to the accompanying drawings.
[0037] In the following description, many specific details are set forth to facilitate a full understanding of the present invention, but the present invention may also be implemented in other ways different from those described herein, and those skilled in the art may make similar generalizations without violating the connotation of the present invention. Therefore, the present invention is not limited to the specific embodiments disclosed below.
[0038] This embodiment provides a multifunctional real-time imaging platform, which includes a server and a client. The overall design frameworks of the server and the client are respectively as follows: Figure 1 and Figure 2 shown.
[0039] The server is built on the Linux system, and its concurrency model is implemented through thread pool, non-blocking socket, epoll based on level triggering, and Reactor event processing model. Specifically, the design process of the server and client includes the following steps:
[0040] 1. Create a thread pool and preset the maximum capacity of worker threads for the thread pool. These worker threads will be used to process client requests. At the same time, in order to ensure that the server-side streaming and upgrade functions are not affected by other worker threads, create a separate streaming thread and an upgrade thread, and set a higher thread priority to ensure priority during scheduling. Usually, the streaming thread and the upgrade thread have the same priority, and both are higher than the worker thread priority.
[0041] 2. Create a socket through socket, set it to non-blocking mode using fcntl, then bind to the server's IP address and specified port, and call bind and listen to start listening for client connection requests. Then call epoll_create to create an epoll instance, use epoll_ctl to register the socket to the epoll instance, and listen to the readable event (EPOLLIN) on the socket to notify the main thread when a new client connection request is received.
[0042] 3. In the main thread, listen to the readable events on the socket through epoll_wait. If a readable event is detected on the socket, call accept to accept the new client connection request and return a new socket. The returned new socket is also configured in non-blocking mode. Use epoll_ctl to register the new socket to the epoll instance and listen to the readable events on the new socket. When a readable event is detected on the new socket, call recv in a loop until the complete HTTP request is read, and add the completed HTTP request to the request queue.
[0043] 4. Get the task from the request queue and parse the HTTP request, including extracting the request line, header and request body. Generate an appropriate HTTP response based on the specific content of the HTTP request obtained by parsing, and call send in a loop to return the complete HTTP response to the client.
[0044] 1) If the HTTP request is the URL corresponding to the camera video stream preview request, the server distributes the task to the streaming thread, calls the streaming API interface in the camera SDK in the streaming thread, converts the RTMP video stream into an FLV video stream through the open source ZLMediaKit framework, puts the FLV video stream in the body of the HTTP response, calls send in a loop, returns the complete HTTP response to the client, and maintains a long connection to continue streaming.
[0045] After the client receives the FLV video stream from the server, it creates a new media extension source through MSE (Media Source Extensions) and associates the new media extension source with the HTML5 video element. Then, flv.js is used to process the FLV video stream, which parses the FLV file, encodes it into an MP4 segment, and loads the MP4 segment into the media extension source, which then pushes the MP4 segment to the associated HTML5 video element for playback.
[0046] 2) If the HTTP request is the URL corresponding to the Web login request, the server distributes the task to the working thread, in which the account and password in the request body of the HTTP request are parsed out respectively. Considering the limited resources of embedded devices, lightweight SQLite is used as the database. A connection is taken out from the database connection pool to access the database, and the parsed account and password are compared with the corresponding account and password in the database to verify whether they are equal. The verification result is used as the main part of the HTTP response, and send is called in a loop to return the complete HTTP response to the client. If the judgment is equal, the verification is passed, and the client enters the main page. If the judgment is not equal, the verification fails, and the client stays on the login page.
[0047] 3) If the HTTP request is a URL corresponding to a camera image parameter configuration request, a camera device parameter configuration request, or a camera code stream parameter configuration request, the server distributes the task to the worker thread.
[0048] If the HTTP request is a GET method request, call the camera SDK related API interface to obtain relevant information and return it to the client. For example, if it is an HTTP request to obtain the camera gimbal speed, call the camera SDK API interface for obtaining the camera gimbal speed, and after obtaining the camera gimbal speed, put it in the body of the HTTP response and return it to the client.
[0049] If the HTTP request is a POST method request, the camera SDK related API interface is also called, and the setting result is returned to the client after the setting is successful. For example, if it is an HTTP request to set the camera gimbal speed, the camera SDK API interface for setting the camera gimbal speed is called, and after the setting is successful, the set camera gimbal speed is placed in the body of the HTTP response and returned to the client.
[0050] 4) If the HTTP request is the URL corresponding to the camera SDK upgrade preprocessing request, the server distributes the task to the upgrade thread, and then completes the upgrade function according to the following sub-steps:
[0051] a) In the upgrade thread, the upgrade preparation identification field (such as Upgrade: Ready) is placed in the body of the HTTP response, and send is called in a loop to return the complete HTTP response to the client, informing the client that the server is ready to receive the upgrade package while maintaining a long connection.
[0052] b) The client receives the response returned by step a). To ensure the success rate of the upgrade, the client reads a data segment of a preset length of the upgrade package file each time. In this embodiment, the length of the upgrade package file read each time is 32KB. The read data segment is placed in the request body of the HTTP request, and the Content-Length field is added to the header field of the HTTP request as 32KB, and sent to the server via the POST method. In addition, the size of the upgrade package file that has been sent needs to be accumulated for subsequent verification of whether the server has successfully received the complete upgrade package file.
[0053] c) The server obtains the task from the request queue and parses the HTTP request. If the camera upgrade package sends the corresponding URL, the task is distributed to the upgrade thread, the upgrade package file in the request body of the HTTP request is placed in the cache, and the size of the received upgrade package files is accumulated. During this period, the server does not make any relevant HTTP response reply.
[0054] d) After the client sends all the contents of the upgrade package file, it fills the number of bytes sent into the request body of the HTTP request as a verification packet, and sends it to the server through the POST method to verify whether the upgrade package file on the server is received completely.
[0055] e) The server obtains the task from the request queue and parses the HTTP request. If it is the URL corresponding to the camera verification package verification, the task is distributed to the upgrade thread, and the number of bytes sent in the request body of the HTTP request is compared with the number of bytes received in the server buffer. If they are equal, the verification is passed, and the upgrade API interface in the camera SDK is called. Then it will enter the upgrade mode, and the upgrade package files received in the buffer will be gradually written to the firmware. After writing, the camera will restart and load the upgrade package file. After the camera is started, the server will put the upgrade completion identification field (for example, Upgrade: Done) in the main part of the HTTP response, and call send in a loop to return the complete HTTP response to the client, informing the client that the server has completed the upgrade, and call close to close the current socket. If they are not equal, the verification fails, and the server will put the upgrade failure identification field (for example, Upgrade: Fail) in the main part of the HTTP response, and call send in a loop to return the complete HTTP response to the client. After receiving the HTTP response, the client will retry the upgrade according to step b) until the upgrade is successful.
[0056] The above is only a preferred embodiment of the present invention. Although the present invention has been disclosed as a preferred embodiment, it is not intended to limit the present invention. Any technician familiar with the art can make many possible changes and modifications to the technical solution of the present invention by using the above disclosed methods and technical contents without departing from the scope of the technical solution of the present invention, or modify it into an equivalent embodiment of equivalent changes. Therefore, any simple modification, equivalent change and modification made to the above embodiments according to the technical essence of the present invention without departing from the content of the technical solution of the present invention still falls within the scope of protection of the technical solution of the present invention.
Claims
1. A multifunctional real-time imaging platform, characterized in that: The platform includes a server and a client; The server is built on the Linux system, and its concurrency model is implemented through thread pool, non-blocking socket, epoll based on horizontal triggering and Reactor event processing model; The design process of the server and client includes: (1) creating a thread pool, which includes a worker thread, a streaming thread, and an upgrade thread, and presetting a maximum capacity of worker threads for the thread pool; (2) Create a socket through socket, set it to non-blocking mode using fcntl, then bind it to the server's IP address and specified port, and call bind and listen to start listening for client connection requests; call epoll_create to create an epoll instance, use epoll_ctl to register the socket to the epoll instance, and listen to readable events on the socket to notify the main thread when a new client connection request is received; (3) In the main thread, epoll_wait is used to monitor the readable events on the socket. If a readable event is detected on the socket, accept is called to accept the new client connection request and return the new socket. The new socket is configured in non-blocking mode. epoll_ctl is used to register the new socket with the epoll instance and monitor the readable events on the new socket. When a readable event is detected on the new socket, recv is called in a loop until the complete HTTP request is read and the completed HTTP request is added to the request queue. (4) Get the task from the request queue, parse the HTTP request, generate the corresponding HTTP response according to the specific content of the HTTP request obtained by parsing, and call send in a loop to return the complete HTTP response to the client.
2. The multifunctional real-time imaging platform according to claim 1, characterized in that: In the thread pool, the working thread is used to process client requests. In order to ensure that the streaming function and the upgrade function of the server are not affected by the working thread, a streaming thread and an upgrade thread are created separately.
3. The multifunctional real-time imaging platform according to claim 1, characterized in that: In the thread pool, a higher thread priority is set for the streaming thread and the upgrading thread to ensure the priority during scheduling.
4. The multifunctional real-time imaging platform according to claim 1, characterized in that: In step (4), if the HTTP request is the URL corresponding to the camera video stream preview request, the server distributes the task to the streaming thread, calls the streaming API interface in the camera SDK in the streaming thread, converts the RTMP video stream into an FLV video stream through the open source ZLMediaKit framework, places the FLV video stream in the main body of the HTTP response, calls send in a loop, returns the complete HTTP response to the client, and maintains a long connection to continue streaming.
5. The multifunctional real-time imaging platform according to claim 4, characterized in that: In step (4), after receiving the FLV video stream from the server, the client creates a new media extension source through MSE and associates the new media extension source with the HTML5 video element; Use flv.js to process FLV video streams. It will parse FLV files, encode them into MP4 segments, and load the MP4 segments into media extension sources. The media extension source then pushes the MP4 segments to the associated HTML5 video element for playback.
6. The multifunctional real-time imaging platform according to claim 1, characterized in that: In step (4), if the HTTP request is a URL corresponding to a Web login request, the server distributes the task to a work thread, in which the account and password in the request body of the HTTP request are parsed out respectively, and SQLite is used as a database; a connection is taken out from the database connection pool to access the database, and the parsed account and password are compared with the corresponding account and password in the database to verify whether they are equal, and the verification result is used as the main body of the HTTP response, and send is called in a loop to return the complete HTTP response to the client; if it is judged to be equal, that is, the verification is passed, and the client enters the main page; if it is judged to be unequal, that is, the verification fails, and the client stays on the login page.
7. The multifunctional real-time imaging platform according to claim 1, characterized in that: In step (4), if the HTTP request is a URL corresponding to a camera image parameter configuration request, a camera device parameter configuration request, or a camera code stream parameter configuration request, the server distributes the task to the worker thread; If the HTTP request is a GET method request, call the camera SDK related API interface to obtain relevant information and return it to the client; if the HTTP request is a POST method request, call the camera SDK related API interface, and return the setting result to the client after successful setting.
8. The multifunctional real-time imaging platform according to claim 1, characterized in that: In step (4), if the HTTP request is the URL corresponding to the camera SDK upgrade preprocessing request, the server distributes the task to the upgrade thread, and then completes the upgrade function according to the following sub-steps: a) In the upgrade thread, the upgrade preparation identification field is placed in the body of the HTTP response, and send is called cyclically to return the complete HTTP response to the client, informing the client that the server is ready to receive the upgrade package, while maintaining a long connection; b) The client receives the response returned by step a), reads a data segment of a preset length from the upgrade package file each time, puts the read data segment into the request body of the HTTP request, adds a preset length field to the header field of the HTTP request, and sends it to the server via the POST method; c) The server obtains the task from the request queue and parses the HTTP request. If the camera upgrade package sends the corresponding URL, the task is distributed to the upgrade thread, the upgrade package file in the request body of the HTTP request is placed in the cache, and the size of the received upgrade package files is accumulated. During this period, the server does not make any relevant HTTP response reply; d) After the client sends all the contents of the upgrade package file, it fills the number of bytes sent as a verification packet into the request body of the HTTP request and sends it to the server via the POST method to verify whether the upgrade package file on the server has been received completely; e) The server obtains the task from the request queue and parses the HTTP request. If it is the URL corresponding to the camera verification package verification, the task is distributed to the upgrade thread, and the number of bytes sent in the request body of the HTTP request is compared with the number of bytes received in the server buffer. If they are equal, the verification passes, and the upgrade API interface in the camera SDK is called to enter the upgrade mode; If they are not equal, the verification fails. The server puts the upgrade failure identification field in the body of the HTTP response, and calls send in a loop to return the complete HTTP response to the client. After receiving the HTTP response, the client starts the upgrade again according to step b) until the upgrade is successful.
9. The multifunctional real-time imaging platform according to claim 8, characterized in that: The upgrade API interface in the camera SDK is called to enter the upgrade mode, specifically: the upgrade package files received in the cache area are gradually written into the firmware, and the camera is restarted and the upgrade package files are loaded after writing. After the camera is started, the server puts the upgrade completion identification field in the body of the HTTP response, and calls send in a loop to return the complete HTTP response to the client, informing the client that the server has completed the upgrade, and calls close to close the current socket.
Citation Information
Patent Citations
System and method for counting number of online client sides based on TCP / IP communication protocol
CN106506253A
Clientless cross-platform video playing implementation method
CN107197386A
Method for playing H.265 video across browsers based on HTTP-FLV protocol
CN111683293A
Multi-scene inter-process communication method applicable for Linux server cluster
CN113010333A
System and method for file transmission
WO2012065520A1
