Multi-port service method and system based on Onvif protocol
Through the multi-port service method based on the Onvif protocol, the addition of audio and video media channels and event monitoring are solved, and the problem of Onvif protocol devices cannot distinguish groups is achieved, and flexible client access and high concurrent response are achieved.
Patent Information
- Application Number
- CN202510269886.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-03-07
- Publication Date
- 2025-07-08
AI Technical Summary
The existing Onvif protocol devices and devices cannot effectively distinguish groups, resulting in the client being unable to selectively access and use multi-channel services, and the single-port multi-channel device cannot be added and used by the client.
Using a multi-port service method based on the Onvif protocol, the audio and video media channel addition, event monitoring and multi-threading process are used to distinguish and display each audio and video media channel and the event monitoring and thread pool processing IO events are used.
It realizes flexible access to different clients under the same server, improves the number of concurrent connections and server usage, supports multi-port services like multiple service devices, and meets the needs of high concurrent response.
Smart Images

Figure CN120281972A_ABST
Abstract
Description
Technical Field
[0001] The present invention belongs to the technical field of streaming media, and particularly relates to a multi-port service method based on the Onvif protocol. Background Art
[0002] Existing devices and apparatuses that support the Open Network Video Interface Forum (Onvif) have the following characteristics: some devices only support a single port, and each port contains three video streams, namely the main, secondary, and auxiliary streams. Here, the device refers to hardware such as a camera that supports the onvif protocol, and it is also equivalent to an onvif service device itself. That is, the camera can respond to the access of an onvif client, so the camera itself is also an onvif service; some apparatuses, such as a Network Video Recorder (NVR) storage device, support multiple channels, and each channel has main, secondary, and auxiliary video streams. However, the Onvif protocol of the entire NVR only supports a single port. That is, once the NVR device is detected (through protocol broadcast detection), all the channels of the device will be displayed, and it is impossible to further distinguish groups, or only some groups will be displayed. Some clients, when accessing and adding a server, can only add one channel to one port. At this time, if the server is a single-port multi-channel, each channel cannot be added and used by the client. Here, the client refers to the end that sends requests integrated with the Onvif protocol. Summary of the Invention
[0003] In view of the above problems, the present invention provides a method and system for multi-port service based on the Onvif protocol, which can selectively perform group discovery and group display when a client accesses, improving the flexibility of the server and the selective access support.
[0004] To solve the above technical problems, the present invention adopts the following technical solutions:
[0005] The first aspect of the present invention provides a method for multi-port service based on the Onvif protocol, including the following steps:
[0006] Perform audio and video media channel addition: The server adds audio and video media channels according to the user's requirements, and adds each audio and video media channel by distinguishing ports. Each port corresponds to multiple audio and video media channels for distinguishing groups;
[0007] Perform event monitoring: After adding device information, a long-term event monitoring thread is enabled internally to monitor the IO events of the port and monitor the requests of external clients for each port; handle event monitoring through the level-triggered mode of the epoll model;
[0008] Perform multi-threading processing: Process the monitored IO events, that is, the HTTP requests sent by the client; perform asynchronous event processing through the combination of a task queue and a thread pool.
[0009] In a possible implementation, the HTTP requests sent by the client come from the client performing device discovery or directly adding channels of interest according to known ports.
[0010] In a possible implementation, when adding audio-video media channels, each port has different device information, user login names, and passwords; after adding the audio-video media channels, two IO handles of fds are created, one for processing the discovery of audio-video media channels and the other for processing specific protocol interactions, and these two handles are independently monitored in the event listening thread.
[0011] In a possible implementation, when the event listening thread monitors the IO event of a specific fd, it adds the IO event of the fd to the thread queue and wakes up a thread in the thread pool; when there is an idle thread in the thread pool, it processes the IO event of the fd, including responding to the specific information, channel information, media information, and video recording information of the device.
[0012] In a possible implementation, when processing the HTTP requests sent by the client, each thread in the thread pool is responsible for processing the IO events of one or more fds, and automatically releases resources and rejoins the idle thread queue after completing the task.
[0013] The second aspect of the present invention provides a system for multi-port services based on the Onvif protocol, including a server and a client. The server further includes an audio-video media channel adding module, an event listening module, and a multi-threading processing module;
[0014] The audio-video media channel adding module is used to add audio-video media channels according to the requirements of the user, add each audio-video media channel by distinguishing ports, and each port corresponds to multiple audio-video media channels for distinguishing groups;
[0015] The event listening module is used to internally enable a long-term event listening thread after adding device information to monitor the IO events of the ports and monitor the requests of external clients for each port; process event listening through the level trigger mode of the epoll model;
[0016] The multi-threading processing module is used to process the monitored IO events, that is, the HTTP requests sent by the client; perform asynchronous event processing through the combination of a task queue and a thread pool.
[0017] In a possible implementation, the HTTP request sent by the client comes from the client for device discovery or directly adds an interested channel based on a known port.
[0018] In a possible implementation, when adding an audio - video media channel, each port has different device information, user login name, and password; after adding the audio - video media channel, two IO handles of fd are created, one for handling audio - video media channel discovery and the other for handling specific protocol interactions, and these two handles are independently monitored in the event - listening thread.
[0019] In a possible implementation, when the event - listening thread monitors an IO event of a specific fd, it adds the IO event of the fd to the thread queue and wakes up a thread in the thread pool; when there is an idle thread in the thread pool, it processes the IO event of the fd, including responding to the specific information, channel information, media information, and video recording information of the device.
[0020] In a possible implementation, when processing the HTTP request sent by the client, each thread in the thread pool is responsible for processing the IO events of one or more fds, and automatically releases resources and rejoins the idle thread queue after completing the task.
[0021] Adopting the present invention has the following beneficial effects: It can achieve the purpose of group differentiation through multiple ports, so as to display different audio - video media channel information for different clients when accessing the same service, without the need for multiple servers for support; it improves the concurrent connection number and the utilization rate of the server; this service solution, by supporting multiple ports, a single server is equivalent to integrating multiple traditional service devices. BRIEF DESCRIPTION OF THE DRAWINGS
[0022] Figure 1 It is a flowchart of a method for a multi - port service based on the Onvif protocol according to an embodiment of the present invention;
[0023] Figure 2 It is a principle block diagram of a system for a multi - port service based on the Onvif protocol according to another embodiment of the present invention. DETAILED DESCRIPTION OF THE EMBODIMENTS
[0024] Next, the technical solutions in the embodiments of the present invention will be clearly and completely described in conjunction with the accompanying drawings in the embodiments of the present invention. Obviously, the described embodiments are some, but not all, of the embodiments of the present invention. All other embodiments obtained by those of ordinary skill in the art based on the embodiments of the present invention without creative efforts shall fall within the protection scope of the present invention.
[0025] See Figure 1, which shows a schematic flow chart of a multi-port service method based on the Onvif protocol according to an embodiment of the present invention, including the following steps:
[0026] S10. Add audio and video media channels: The server adds audio and video media channels according to the user's requirements, adds each audio and video media channel by distinguishing ports, and each port corresponds to multiple audio and video media channels for group distinction;
[0027] S20. Perform event monitoring: After the device information is added, a long-term event monitoring thread is enabled internally to monitor the IO events of the ports and monitor the requests of external clients for each port; handle event monitoring through the level-triggered mode of the epoll model;
[0028] S30. Perform multi-threaded processing: Process the monitored IO events, that is, the HTTP requests sent by the client; perform asynchronous event processing through the combination of a task queue and a thread pool.
[0029] In a specific application example, the HTTP request sent by the client can come from the client for device discovery or directly add an interested channel according to a known port. If the client enables device discovery, the request can be sent to multiple ports of the server through the broadcast protocol. After the event monitoring thread receives the "device discovery" request, the task is sent to the thread pool processing module for task processing. In each specific task processing stage, multiple port information is fed back to the client, and the client can discover multiple port devices at one time. If a specific port access is directly enabled, it means that the client knows the specific available ports of the server and which channels are inside the port and are the audio and video media channels that the client wants to access. Therefore, the specific port can be directly accessed through the Onvif protocol.
[0030] In a specific application example, when adding audio and video media channels, each port has different device information, user login names and passwords; after adding the audio and video media channels, two IO handles of fd are created, one for processing audio and video media channel discovery and the other for processing specific protocol interactions, and these two handles are independently monitored in the event monitoring thread.
[0031] Further, when the event listening thread monitors the IO event of a specific fd, it adds the monitored IO event of the fd to the thread queue and wakes up a thread in the thread pool. When there is an idle thread in the thread pool, it processes the IO event of the fd, including responding to the specific information, channel information, media information, and video recording information of the device. When processing the HTTP request sent by the client, each thread in the thread pool is responsible for processing the IO events of one or more fds, and automatically releases resources and rejoins the idle thread queue after completing the task. Since the HTTP requests from the client are all short tasks of the Onvif protocol, such as device discovery, obtaining device information, URL information, etc.; these requests are basically one-time and do not have long-term occupation, so using the thread pool solution for processing is more suitable for processing short and intensive tasks and makes full use of thread resources.
[0032] Through the above-set multi-port service method based on the Onvif protocol, when the client only supports accessing single-port and single-channel devices such as IPC (cameras), it can be converted into a service where one port corresponds to one channel; when the customer needs to distinguish groups and only access some channels of the server, different audio and video channels can be added within different ports to meet the customer's needs; when multiple clients need to access different audio and video channels of different ports, the server can handle multiple clients with a single process and does not need to start multiple service processes, and a single process can meet the high-concurrency response.
[0033] Corresponding to the method embodiment, Figure 2 Shown is a system of a multi-port service based on the Onvif protocol according to another embodiment of the present invention, including a server 10 and a client 20. The server further includes an audio and video media channel adding module 101, an event listening module 102, and a multi-thread processing module 103. Among them, the audio and video media channel adding module 101 is used to add audio and video media channels according to the user's requirements, add each audio and video media channel by distinguishing ports, and each port corresponds to multiple audio and video media channels for distinguishing groups, such as Figure 2 there are port 1, port 2, port 3, and port 4, and port 1 corresponds to channels 1, 2, and 3; the event listening module 102 is used to enable a long-term event listening thread internally after adding device information to monitor the IO events of the ports and monitor the requests of external clients for each port; the event listening is processed through the level-triggered mode of the epoll model; the multi-thread processing module is used to process the monitored IO events, that is, the HTTP requests sent by the client; asynchronous event processing is performed through the combination of a task queue and a thread pool.
[0034] In specific application examples, the HTTP requests sent by the client can come from the client's device discovery or directly add channels of interest based on known ports. If the client enables device discovery, it can send requests to multiple ports of the server through the broadcast protocol. After the event listening thread receives the "device discovery" request, it sends the task to the thread pool processing module for task processing. In each specific task processing stage, multiple port information is fed back to the client, and the client can discover multiple port devices at one time. If specific port access is directly enabled, it means that the client already knows the specific available ports of the server and which channels are inside the port, and these are the audio and video media channels that the client wants to access. Therefore, specific port access can be directly performed through the Onvif protocol.
[0035] In specific application examples, when adding audio and video media channels, each port has different device information, user login names, and passwords. After adding the audio and video media channels, two IO handles of fd are created. One is used to handle the discovery of audio and video media channels, and the other is used to handle specific protocol interactions. These two handles are independently monitored in the event listening thread.
[0036] Furthermore, when the event listening thread monitors the IO event of a specific fd, it adds the monitored IO event of the fd to the thread queue and wakes up a thread in the thread pool. When there is an idle thread in the thread pool, it processes the IO event of the fd, including responding to the specific information, channel information, media information, and video recording information of the device. When processing the HTTP requests sent by the client, each thread in the thread pool is responsible for processing the IO events of one or more fds, and automatically releases resources and rejoins the idle thread queue after completing the task. Since the HTTP requests from the client are all short tasks of the Onvif protocol, such as device discovery, obtaining device information, URL information, etc.; these requests are basically one-time and do not have long-term occupancy. Therefore, using the thread pool solution for processing is more suitable for short and intensive task processing and makes full use of thread resources.
[0037] Through the above-set multi-port service system based on the Onvif protocol, when the client only supports accessing devices with single ports and single channels such as IP cameras, it can be converted into a service where one port corresponds to one channel. When the customer needs to distinguish groups and only access some channels of the server, different audio and video channels can be added within different ports to meet the customer's needs. When multiple clients need to access different audio and video channels of different ports, the server can serve multiple clients with a single process and does not need to start multiple service processes, and a single process can meet high-concurrency responses.
[0038] It should be understood that the exemplary embodiments described herein are illustrative and not restrictive. Although one or more embodiments of the present invention have been described in conjunction with the accompanying drawings, those of ordinary skill in the art should understand that various changes in form and detail may be made without departing from the spirit and scope of the present invention as defined by the appended claims.
Claims
1. A method for a multi-port service based on the Onvif protocol, characterized in that, It includes the following steps: Perform audio - video media channel addition: The server adds audio - video media channels according to the user's requirements. The audio - video media channels are added by differentiating ports. Each port corresponds to multiple audio - video media channels, which are used to distinguish groups; Perform event listening: After adding device information, a long - term event - listening thread is enabled internally to listen for IO events of the ports and listen for requests from external clients to each port; Process event listening through the level - triggered mode of the epoll model; Perform multi - thread processing: Process the listened IO events, that is, the HTTP requests sent by the client; Asynchronous event processing is performed through the combination of a task queue and a thread pool.
2. The method of multi-port service based on the Onvif protocol according to claim 1, characterized in that, The HTTP requests sent by the client come from the client for device discovery or directly adding interested channels according to known ports.
3. The method of multi-port service based on the Onvif protocol according to claim 1, wherein, When performing audio - video media channel addition, each port has different device information, user login names, and passwords; After adding the audio - video media channels, two IO handles of fd are created. One is used to process audio - video media channel discovery, and the other is used to process specific protocol interactions. These two handles are independently monitored in the event - listening thread.
4. The method of multi-port service based on the Onvif protocol according to claim 3, characterized in that When the event - listening thread listens to the IO event of a specific fd, the IO event of the fd is added to the thread queue to wake up a thread in the thread pool; When there is an idle thread in the thread pool, process the IO event of the fd, including responding with the specific information, channel information, media information, and video recording information of the device.
5. The method for multi-port service based on the Onvif protocol according to claim 4, characterized in that, When processing the HTTP requests sent by the client, each thread in the thread pool is responsible for processing the IO events of one or more fds, and automatically releases resources and rejoins the idle thread queue after completing the task.
6. A system for multi-port services based on the Onvif protocol, characterized in that, It includes a server and a client. The server further includes an audio - video media channel addition module, an event - listening module, and a multi - thread processing module; The audio - video media channel addition module is used to add audio - video media channels according to the user's requirements. The audio - video media channels are added by differentiating ports. Each port corresponds to multiple audio - video media channels, which are used to distinguish groups; The event - listening module is used to enable a long - term event - listening thread internally after adding device information to listen for IO events of the ports and listen for requests from external clients to each port; Process event listening through the level - triggered mode of the epoll model; The multi - thread processing module is used to process the listened IO events, that is, the HTTP requests sent by the client; Asynchronous event processing is performed through the combination of a task queue and a thread pool.
7. The system of the multi-port service based on the Onvif protocol according to claim 6, wherein, The HTTP requests sent by the client come from the client for device discovery or directly adding interested channels according to known ports.
8. The system of the multi-port service based on the Onvif protocol according to claim 6, wherein, When performing audio - video media channel addition, each port has different device information, user login names, and passwords; After adding the audio - video media channels, two IO handles of fd are created. One is used to process audio - video media channel discovery, and the other is used to process specific protocol interactions. These two handles are independently monitored in the event - listening thread.
9. The system of multi-port service based on the Onvif protocol according to claim 8, characterized in that, The event monitoring thread monitors the IO events of a specific fd, adds the IO events of the fd to the thread queue, and wakes up a thread in the thread pool; when there is an idle thread in the thread pool, it processes the IO events of the fd, including responding to the specific information, channel information, media information, and video recording information of the device.
10. The system of the multi-port service based on the Onvif protocol according to claim 9, characterized in that, When processing the HTTP request sent by the client, each thread in the thread pool is responsible for processing the IO events of one or more fds, automatically releases resources after completing the task, and rejoins the idle thread queue.