Dynamic seamless switching RTP message forwarding method and system based on service awareness

By adopting a business-aware, dynamic, seamless switching RTP packet forwarding method, and utilizing SDP negotiation and shared memory mechanisms, the application layer and kernel layer can work together to dynamically adjust the forwarding path, thus resolving the contradiction between performance and business requirements in existing technologies and improving communication quality and system efficiency.

CN121967385APending Publication Date: 2026-05-01FUJIAN STAR NET JUANFENG INFORMATION TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
FUJIAN STAR NET JUANFENG INFORMATION TECH CO LTD
Filing Date
2025-12-22
Publication Date
2026-05-01

AI Technical Summary

Technical Problem

Existing RTP packet forwarding methods cannot meet both high performance and diverse service requirements, and lack dynamic switching capabilities, leading to a decline in communication quality or interruption.

Method used

By adopting a business-aware dynamic seamless switching method, subscription relationships are generated through SDP negotiation, and collaborative work between the application layer and kernel layer is achieved by combining shared memory and procfs interface. The forwarding path is dynamically adjusted, high-speed pass-through is achieved by using Netfilter mechanism, and seamless switching is achieved when business needs change.

Benefits of technology

It achieves flexible support for diverse real-time communication services while ensuring high performance, avoids call interruptions and packet loss, improves the system's adaptability and resource utilization efficiency, and is suitable for high-concurrency real-time communication scenarios.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121967385A_ABST
    Figure CN121967385A_ABST
Patent Text Reader

Abstract

The invention provides a dynamic seamless switching RTP message forwarding method and system based on service awareness in the technical field of real-time communication, and the method comprises the steps: S1, generating a subscription relation based on SDP negotiation when a session is established, and judging an initial forwarding path according to a service demand; s2, if the judgment result is that service processing is needed, corresponding service operation is executed, and the RTP message is forwarded; if the judgment result is that the session context can be issued to the kernel layer, writing the session context into a shared memory, and issuing a forwarding rule to the kernel layer; s3, executing high-speed transparent transmission of the RTP message by the kernel layer, and updating the statistical information in the shared memory at the same time; s4, the application layer reads the statistical information of the shared memory to carry out QoS monitoring and cutoff detection; and S5, in a session operation process, detecting subscription relationship change, address change or abnormal conditions, and returning to an application layer to take over and forward. The method has the advantages that high performance is guaranteed, and diversified real-time communication services are flexibly supported at the same time.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of real-time communication technology, and in particular to a service-aware, dynamic, seamless switching RTP packet forwarding method and system. Background Technology

[0002] The RTP protocol is widely used in audio and video communication, responsible for the transmission of real-time data streams. Its forwarding efficiency and flexibility directly affect communication quality and service experience. With the diversification of real-time communication service requirements, such as the introduction of transcoding, encryption, and recording functions, forwarding methods not only need to have high performance but also need to support complex business logic, thus giving rise to a service-aware dynamic switching mechanism.

[0003] Currently, the forwarding of RTP packets in real-time communication mainly relies on the following two implementation methods: a) Application Layer Forwarding: RTP packets are processed directly by user-space programs, supporting functions such as transcoding, encryption / decryption, and recording. This method offers high flexibility and is easy to extend with complex business logic, but because packets need to switch between user space and kernel space multiple times, it results in significant processing latency, high resource overhead, and a performance bottleneck.

[0004] b. Kernel-level forwarding: Based on kernel mechanisms such as Netfilter, XDP, or eBPF, RTP packet forwarding is completed directly in kernel space, avoiding context switching and processing of the complete UDP protocol stack, thus achieving high-speed transparent transmission. This method has significant performance advantages, but due to the limitations of the kernel environment, it is difficult to support processing requiring dynamic business logic (such as real-time transcoding), and its scalability is poor.

[0005] The existing technology mainly suffers from the following core problems: (1) It is difficult to balance functionality and performance: application layer forwarding supports complex services, but has low performance; kernel layer forwarding has superior performance, but cannot flexibly support business requirements such as transcoding and encryption. This contradiction means that when facing diverse services, a compromise must be made between performance and functionality.

[0006] (2) Fixed forwarding mode and lack of dynamic switching capability: Once the application layer or kernel layer path is determined when the session is established, it cannot be dynamically switched during the communication process. For example, if the transcoding function needs to be temporarily enabled in the middle of the session, it cannot be seamlessly switched to the application layer for processing, which may lead to a decrease in call quality or even interruption.

[0007] (3) Insufficient business awareness: The existing solution does not make dynamic judgments based on the business attributes of the session (such as whether transcoding is required, encryption status, etc.), making it difficult to switch forwarding paths on demand and limiting the adaptive capabilities of the real-time communication system.

[0008] Therefore, how to provide a service-aware, dynamic, seamless switching RTP packet forwarding method and system to flexibly support diverse real-time communication services while ensuring high performance has become an urgent technical problem to be solved. Summary of the Invention

[0009] The technical problem to be solved by the present invention is to provide a service-aware dynamic seamless switching RTP packet forwarding method and system, which can flexibly support diverse real-time communication services while ensuring high performance.

[0010] In a first aspect, the present invention provides a service-aware, dynamic, seamless switching method for RTP packet forwarding, comprising the following steps: Step S1: When the session is established, a subscription relationship is generated based on SDP negotiation, and the initial forwarding path is determined according to the business requirements including at least one of transcoding, encryption / decryption, recording or listening, and a determination result is generated. Step S2: If the determination result indicates that service processing is required, then the corresponding service operation is executed and the RTP packet is forwarded; if the determination result indicates that it can be delegated to the kernel layer, then the session context is written to shared memory and the forwarding rules are sent to the kernel layer through the procfs control interface. Step S3: The kernel layer performs high-speed transparent transmission of RTP packets based on the Netfilter mechanism, while continuously updating the shared memory with statistical information including SSRC-based counts and active time. Step S4: The application layer periodically reads the statistical information in the shared memory to perform QoS monitoring and disconnection detection; Step S5: During the session, if a change in subscription relationship, address change, or abnormal situation is detected, the application layer immediately cancels the forwarding rule of the kernel layer through the procfs interface and falls back to the application layer to take over the forwarding, so as to achieve dynamic and seamless switching, ensuring that the call is not interrupted and there is no packet loss.

[0011] Furthermore, in step S1, the process of generating the determination result is specifically as follows: The determination of business requirements is based on the subscription model and address learning mechanism. Specifically, it includes: dynamically adjusting the determination logic by listening to session attributes. When the session involves transcoding or encryption / decryption, it is determined that business processing is required; otherwise, it is determined that it can be delegated to the kernel layer.

[0012] Furthermore, in step S2, the session context written to the shared memory includes session ID, source address, destination address, port information, and service identifier, and is sent to the kernel layer in the form of forwarding rules through the procfs interface to achieve context synchronization between the application layer and the kernel layer. The shared memory is used to store statistical information and session context in a ring buffer structure, supports concurrent access by multiple sessions, and achieves efficient synchronization between the application layer and the kernel layer through a semaphore mechanism.

[0013] Furthermore, in step S3, when performing the high-speed pass-through, the overhead of the UDP protocol stack and the switching between user mode and kernel mode is bypassed, and the RTP packets are processed directly based on the Netfilter hook function, and the traditional counting information is returned in real time through shared memory.

[0014] Furthermore, in step S4, the frequency at which the application layer periodically reads the shared memory is configurable to adapt to the QoS requirements of different network environments, and the read operation and the kernel layer update operation are mutually exclusive to ensure data consistency. In step S5, when falling back to the application layer, the forwarding is directly taken over based on the session context and statistical information stored in the shared memory, avoiding session reconstruction and ensuring packet continuity at the moment of switching.

[0015] Secondly, the present invention provides a service-aware, dynamic, seamless switching RTP packet forwarding system, comprising the following modules: The initial forwarding path determination module is used to generate a subscription relationship based on SDP negotiation when a session is established, and to determine the initial forwarding path according to business requirements including at least one of transcoding, encryption / decryption, recording or listening, and generate a determination result. The determination result execution module is used to execute the corresponding business operation and forward the RTP packet if the determination result is that business processing is required; if the determination result is that it can be delegated to the kernel layer, the session context is written to shared memory and the forwarding rules are sent to the kernel layer through the procfs control interface. The RTP packet pass-through module is used by the kernel layer to perform high-speed pass-through of RTP packets based on the Netfilter mechanism, while continuously updating the shared memory with statistical information including SSRC-based counts and active time. The statistics information reading module is used by the application layer to periodically read the statistics information in the shared memory for QoS monitoring and disconnection detection. The application layer takeover module is used to immediately revoke the forwarding rules of the kernel layer through the procfs interface if a change in subscription relationship, address change or abnormal situation is detected during the session, and fall back to application layer takeover forwarding to achieve dynamic and seamless switching, ensuring that the call is not interrupted and there is no packet loss.

[0016] Furthermore, in the initial forwarding path determination module, the process of generating the determination result is as follows: The determination of business requirements is based on the subscription model and address learning mechanism. Specifically, it includes: dynamically adjusting the determination logic by listening to session attributes. When the session involves transcoding or encryption / decryption, it is determined that business processing is required; otherwise, it is determined that it can be delegated to the kernel layer.

[0017] Furthermore, in the determination result execution module, the session context written to the shared memory includes session ID, source address, destination address, port information, and service identifier, and is sent to the kernel layer in the form of forwarding rules through the procfs interface to achieve context synchronization between the application layer and the kernel layer. The shared memory is used to store statistical information and session context in a ring buffer structure, supports concurrent access by multiple sessions, and achieves efficient synchronization between the application layer and the kernel layer through a semaphore mechanism.

[0018] Furthermore, in the RTP packet pass-through module, when performing the high-speed pass-through, the overhead of the UDP protocol stack and user-mode to kernel-mode switching is bypassed, and the RTP packets are directly processed based on the Netfilter hook function, and the relay information is returned in real time through shared memory.

[0019] Furthermore, in the statistical information reading module, the frequency at which the application layer periodically reads the shared memory is configurable to adapt to the QoS requirements of different network environments, and the reading operation and the kernel layer update operation are mutually exclusive to ensure data consistency. In the application layer takeover module, when falling back to the application layer, the module directly takes over the forwarding based on the session context and statistical information stored in the shared memory, avoiding session reconstruction and ensuring message continuity at the moment of switching.

[0020] The advantages of this invention are: 1. During session establishment, a subscription relationship is negotiated and generated based on SDP. The initial forwarding path is determined based on service requirements including at least one of transcoding, encryption / decryption, recording, or monitoring, generating a determination result. If the determination result indicates that service processing is required, the corresponding service operation is executed and RTP packets are forwarded. If the determination result indicates that the forwarding can be delegated to the kernel layer, the session context is written to shared memory, and forwarding rules are distributed to the kernel layer via the procfs control interface. The kernel layer performs high-speed transparent transmission of RTP packets based on the Netfilter mechanism, while continuously updating the shared memory with statistics including SSRC-based counts and active time. The application layer periodically reads the statistics in the shared memory for QoS monitoring and disconnection detection. During session operation, if a change in subscription relationship, address change, or abnormal situation is detected, the application layer immediately revokes the kernel layer's forwarding rules via the procfs interface and reverts to the application layer taking over forwarding. Achieving dynamic and seamless switching ensures uninterrupted calls and zero packet loss. This is achieved by constructing a dynamic system where the application layer and kernel layer work together to flexibly support diverse real-time communication services while maintaining high performance. The core lies in intelligently determining the service-awareness mechanism at the time of session establishment: if transcoding, encryption, or other service processing is required, the feature-rich application layer takes over; if no complex services are needed, forwarding rules are delegated to the kernel layer through shared memory and the procfs interface, using Netfilter hooks to bypass the protocol stack and achieve high-speed pass-through. Most importantly, if service requirements change during session execution (such as a sudden need for recording), the kernel rules can be revoked and the system can seamlessly fall back to application layer processing based on the session context saved in shared memory. This enables dynamic switching between "high-performance pass-through" and "high-feature service processing" modes based on real-time needs while maintaining uninterrupted calls, ultimately balancing performance and flexibility.

[0021] 2. Through a business awareness mechanism, the forwarding path is intelligently determined based on business requirements such as transcoding and encryption / decryption when the session is established. When it is determined that no business processing is required, the session can be delegating to the kernel layer and using the Netfilter mechanism to perform high-speed transparent transmission of RTP packets. This bypasses the overhead of the traditional UDP protocol stack and frequent switching between user space and kernel space, significantly reducing packet forwarding latency and CPU resource consumption. It is especially suitable for high-concurrency real-time communication scenarios, achieving near-line-speed forwarding capabilities, thereby improving the overall system throughput and response speed.

[0022] 3. Subscription relationships are generated based on SDP negotiation, and the judgment logic is dynamically adjusted through the subscription model and address learning mechanism to ensure that only sessions with preset business requirements are processed at the application layer; otherwise, they are quickly pushed down to the kernel layer. This dynamic path selection mechanism enables the system to flexibly allocate processing resources according to the actual business load, avoiding unnecessary application layer processing overhead. While ensuring the integrity of business functions, it maximizes the advantages of high-speed forwarding at the kernel layer, improving resource utilization efficiency and system scalability.

[0023] 4. During session execution, continuous monitoring of subscription relationship changes, address changes, or abnormal situations is conducted. Once a problem is detected, the application layer can immediately revoke the kernel layer's forwarding rules through the procfs interface and smoothly roll back to the application layer taking over forwarding. This switching process is completed directly based on the session context and statistical information stored in shared memory, without the need to rebuild the session, achieving dynamic and seamless switching. This effectively avoids call interruptions or packet loss, enhances the system's fault tolerance and the continuity of real-time communication, and is especially suitable for application scenarios with extremely high service quality and reliability requirements, such as VoIP and video conferencing.

[0024] 5. By storing session context (such as session ID, address and port information) and statistical information (such as SSRC-based counts and active time) in shared memory (using a ring buffer structure and semaphore mechanism), concurrent access by multiple sessions is supported, and data consistency between the application layer and the kernel layer is ensured. This design reduces the overhead of inter-layer communication, avoids performance bottlenecks caused by data copying or lock contention, makes context synchronization fast and reliable, provides a real-time and accurate data foundation for dynamic switching and QoS monitoring, and improves the overall collaborative efficiency of the system.

[0025] 6. The application layer periodically reads statistical information from shared memory for QoS monitoring and disconnection detection. The reading frequency is configurable, and the monitoring granularity can be adjusted according to the needs of different network environments. This allows system administrators to flexibly respond to network fluctuations or performance changes and achieve proactive operation and maintenance. Combined with a mutual exclusion mechanism to ensure data reading consistency, this monitoring mechanism not only improves the system's ability to respond quickly to abnormal situations, but also supports fine-grained analysis and optimization through continuous updates of statistical information, thereby enhancing the system's adaptability and manageability.

[0026] 7. During dynamic handover, when falling back from the kernel layer to the application layer, the forwarding is taken over directly using the pre-saved session context and statistics in shared memory. There is no need to renegotiation or establish a session, avoiding the session reconstruction overhead and initial delay common in traditional handover methods. This ensures the continuous transmission of RTP packets at the moment of handover, effectively preventing call jitter or data loss caused by handover. It is particularly suitable for communication services with strict real-time requirements, enhancing the smoothness and consistency of the user experience. Attached Figure Description

[0027] The present invention will be further described below with reference to the accompanying drawings and embodiments.

[0028] Figure 1 This is a flowchart of a service-aware, dynamic, seamless switching RTP packet forwarding method according to the present invention.

[0029] Figure 2 This is a schematic diagram of the structure of a service-aware, dynamic, seamless switching RTP packet forwarding system according to the present invention. Detailed Implementation

[0030] The overall approach of the technical solution in this application is as follows: During session establishment, intelligent judgment is made based on a service-aware mechanism. If transcoding, encryption, or other service processing is required, the feature-rich application layer takes over. If complex services are not required, forwarding rules are pushed down to the kernel layer via shared memory and the procfs interface, and high-speed pass-through is achieved by using Netfilter hooks to bypass the protocol stack. Most importantly, if service requirements change during session execution, kernel rules can be revoked, and the session context saved in shared memory can be seamlessly rolled back to application layer processing. This allows for dynamic switching between "high-performance pass-through" and "high-feature service processing" modes based on real-time needs, while maintaining uninterrupted communication, thus balancing performance and flexibility. Please refer to Figures 1 to 2 As shown, a preferred embodiment of the service-aware dynamic seamless switching RTP packet forwarding method of the present invention includes the following steps: Step S1: When the session is established, a subscription relationship is generated based on SDP negotiation, and the initial forwarding path is determined according to the business requirements including at least one of transcoding, encryption / decryption, recording or listening, and a determination result is generated. Step S2: If the determination result indicates that service processing is required, then the corresponding service operation is executed and the RTP packet is forwarded; if the determination result indicates that it can be delegated to the kernel layer, then the session context is written to shared memory and the forwarding rules are sent to the kernel layer through the procfs control interface. Step S3: The kernel layer performs high-speed transparent transmission of RTP packets based on the Netfilter mechanism, while continuously updating the shared memory with statistical information including SSRC-based counts and active time. Step S4: The application layer periodically reads the statistical information in the shared memory to perform QoS monitoring and disconnection detection; Step S5: During the session, if a change in subscription relationship, address change, or abnormal situation is detected, the application layer immediately cancels the forwarding rule of the kernel layer through the procfs interface and falls back to the application layer to take over the forwarding, so as to achieve dynamic and seamless switching, ensuring that the call is not interrupted and there is no packet loss.

[0031] In practice, it supports multiple dynamic switchings within the session lifecycle. Each switching is determined based on real-time business needs, and the session state is preserved through shared memory during the switching process, achieving seamless inheritance of accumulated statistical information.

[0032] This invention combines the flexible business processing capabilities of the application layer with the efficient packet forwarding capabilities of the kernel layer, utilizes shared memory as a bidirectional data channel, and uses procfs as a control channel to construct a dynamic, business-aware RTP packet processing pipeline. Its core advantage lies in its ability to intelligently and seamlessly switch between "high-function" and "high-performance" modes based on real-time changing business needs while ensuring communication quality.

[0033] In step S1, the process of generating the determination result is as follows: The determination of business requirements is based on the subscription model and address learning mechanism. Specifically, it includes: dynamically adjusting the determination logic by listening to session attributes. When the session involves transcoding or encryption / decryption, it is determined that business processing is required; otherwise, it is determined that it can be delegated to the kernel layer.

[0034] During the initial session establishment, signaling interaction is completed via the SIP protocol. The SDP (Session Description Protocol) message body carries the media stream's encoding format (e.g., H.264, Opus), IP address, port, and optional service attribute tags (e.g., a=require:encryption). The application layer's initial forwarding path determination module parses the SDP, generating an internal subscription relationship table. The core fields of this table include: Session ID (Call-ID), source / destination IP and port, media type, and a "service requirement" flag (used to indicate whether transcoding, recording, etc., are required). The address learning mechanism associates the address information learned in the signaling phase with subsequent RTP streams of the same session. The determination logic is a configurable policy engine: for example, if the audio encoding negotiated in the SDP is G.711, but the system output requires Opus to save bandwidth, it is determined that "service processing" (transcoding) is required; if the SDP contains an encryption tag or the administrator has configured a forced recording policy, it is also determined that "service processing" is required. For ordinary sessions that do not require any service processing, it is determined that "can be delegated to the kernel layer."

[0035] In step S2, the session context written to the shared memory includes session ID, source address, destination address, port information, and service identifier, and is sent to the kernel layer in the form of forwarding rules through the procfs interface to achieve context synchronization between the application layer and the kernel layer. The shared memory is used to store statistical information and session context in a ring buffer structure, supports concurrent access by multiple sessions, and achieves efficient synchronization between the application layer and the kernel layer through a semaphore mechanism.

[0036] When a rule is determined to be "suitable for delegation to the kernel layer," a session context is prepared. The context data structure is instantiated in shared memory. The shared memory area is designed as a circular buffer consisting of multiple slots, each slot holding the context and statistics of a session. The application layer accesses this shared memory via the `shmget` and `shmat` system calls. Subsequently, the application layer sends a rule to the kernel layer through the `procfs` control interface. After parsing, the kernel layer establishes a corresponding forwarding rule hash table.

[0037] In step S3, when performing the high-speed pass-through, the overhead of the UDP protocol stack and the switching between user mode and kernel mode is bypassed. The RTP packets are processed directly based on the Netfilter hook function, and the timekeeping information is returned in real time through shared memory.

[0038] The kernel-level RTP packet pass-through module is implemented as a loadable kernel module (LKM). It registers a Netfilter hook function at the NF_INET_PRE_ROUTING point. When an RTP packet arrives, the hook function is triggered. It first extracts the packet's five-tuple (protocol, source / destination IP, source / destination port) and performs a fast match in the kernel's forwarding rule hash table. If a match is successful, it directly calls the nf_reroute function to modify the packet's destination address and port, and immediately returns NF_STOLEN, instructing Netfilter to "steal" the packet, thus bypassing the subsequent complex UDP protocol stack processing and copy operations to user space. At the same time, it updates the statistics of the corresponding session slot in shared memory.

[0039] In step S4, the frequency at which the application layer periodically reads the shared memory is configurable to adapt to the QoS requirements of different network environments, and the read operation and the kernel layer update operation are mutually exclusive to ensure data consistency. The application layer statistics reading module runs as an independent monitoring thread. The wake-up interval of this thread can be set to the millisecond level through the configuration file (e.g., 100ms by default, 50ms for highly sensitive scenarios). After each wake-up, it first acquires the mutex lock of the shared memory, and then traverses all active session slots in the circular buffer to read relevant data. By calculating the change in the number of packets per unit time, jitter and packet loss rate (QoS indicators) can be evaluated in real time. If it is found that the count of a certain SSRC has not changed for several consecutive monitoring periods (e.g., more than 1 second), a flow interruption detection alarm is triggered. After reading is completed, the mutex lock is released.

[0040] In step S5, when falling back to the application layer, the forwarding is directly taken over based on the session context and statistical information stored in the shared memory, avoiding session reconstruction and ensuring packet continuity at the moment of switching.

[0041] Suppose a session currently undergoing high-speed pass-through at the kernel layer needs to start recording due to administrator intervention. The application layer takeover module will first detect this subscription change and immediately write a `DEL SESSION 0x12345678` command to ` / proc / net / rtp_forwarder / rules`. Upon receiving the command, the kernel layer removes the forwarding rule from the forwarding rule hash table. Afterward, RTP packets for the corresponding session will no longer be intercepted by hook functions but will be normally sent to the application layer's socket buffer. Simultaneously, the application layer, based on the complete session context pre-saved in shared memory, immediately creates a socket and begins receiving packets, executes the recording logic, and then re-forwards them. Because the switching action is rapid (milliseconds) and the session state (such as the sequence number) is continuously maintained by the kernel layer through shared memory, the application layer can seamlessly resume the data stream, ensuring zero packet loss and call continuity.

[0042] A preferred embodiment of the service-aware dynamic seamless switching RTP packet forwarding system of the present invention includes the following modules: The initial forwarding path determination module is used to generate a subscription relationship based on SDP negotiation when a session is established, and to determine the initial forwarding path according to business requirements including at least one of transcoding, encryption / decryption, recording or listening, and generate a determination result. The determination result execution module is used to execute the corresponding business operation and forward the RTP packet if the determination result is that business processing is required; if the determination result is that it can be delegated to the kernel layer, the session context is written to shared memory and the forwarding rules are sent to the kernel layer through the procfs control interface. The RTP packet pass-through module is used by the kernel layer to perform high-speed pass-through of RTP packets based on the Netfilter mechanism, while continuously updating the shared memory with statistical information including SSRC-based counts and active time. The statistics information reading module is used by the application layer to periodically read the statistics information in the shared memory for QoS monitoring and disconnection detection. The application layer takeover module is used to immediately revoke the forwarding rules of the kernel layer through the procfs interface if a change in subscription relationship, address change or abnormal situation is detected during the session, and fall back to application layer takeover forwarding to achieve dynamic and seamless switching, ensuring that the call is not interrupted and there is no packet loss.

[0043] In practice, it supports multiple dynamic switchings within the session lifecycle. Each switching is determined based on real-time business needs, and the session state is preserved through shared memory during the switching process, achieving seamless inheritance of accumulated statistical information.

[0044] This invention combines the flexible business processing capabilities of the application layer with the efficient packet forwarding capabilities of the kernel layer, utilizes shared memory as a bidirectional data channel, and uses procfs as a control channel to construct a dynamic, business-aware RTP packet processing pipeline. Its core advantage lies in its ability to intelligently and seamlessly switch between "high-function" and "high-performance" modes based on real-time changing business needs while ensuring communication quality.

[0045] In the initial forwarding path determination module, the process of generating the determination result is as follows: The determination of business requirements is based on the subscription model and address learning mechanism. Specifically, it includes: dynamically adjusting the determination logic by listening to session attributes. When the session involves transcoding or encryption / decryption, it is determined that business processing is required; otherwise, it is determined that it can be delegated to the kernel layer.

[0046] During the initial session establishment, signaling interaction is completed via the SIP protocol. The SDP (Session Description Protocol) message body carries the media stream's encoding format (e.g., H.264, Opus), IP address, port, and optional service attribute tags (e.g., a=require:encryption). The application layer's initial forwarding path determination module parses the SDP, generating an internal subscription relationship table. The core fields of this table include: Session ID (Call-ID), source / destination IP and port, media type, and a "service requirement" flag (used to indicate whether transcoding, recording, etc., are required). The address learning mechanism associates the address information learned in the signaling phase with subsequent RTP streams of the same session. The determination logic is a configurable policy engine: for example, if the audio encoding negotiated in the SDP is G.711, but the system output requires Opus to save bandwidth, it is determined that "service processing" (transcoding) is required; if the SDP contains an encryption tag or the administrator has configured a forced recording policy, it is also determined that "service processing" is required. For ordinary sessions that do not require any service processing, it is determined that "can be delegated to the kernel layer."

[0047] In the determination result execution module, the session context written to the shared memory includes session ID, source address, destination address, port information, and service identifier, and is sent to the kernel layer in the form of forwarding rules through the procfs interface to realize context synchronization between the application layer and the kernel layer. The shared memory is used to store statistical information and session context in a ring buffer structure, supports concurrent access by multiple sessions, and achieves efficient synchronization between the application layer and the kernel layer through a semaphore mechanism.

[0048] When a rule is determined to be "suitable for delegation to the kernel layer," a session context is prepared. The context data structure is instantiated in shared memory. The shared memory area is designed as a circular buffer consisting of multiple slots, each slot holding the context and statistics of a session. The application layer accesses this shared memory via the `shmget` and `shmat` system calls. Subsequently, the application layer sends a rule to the kernel layer through the `procfs` control interface. After parsing, the kernel layer establishes a corresponding forwarding rule hash table.

[0049] In the RTP packet pass-through module, when the high-speed pass-through is executed, the overhead of UDP protocol stack and user mode to kernel mode switching is bypassed. The RTP packets are processed directly based on Netfilter hook functions, and the timekeeping information is returned in real time through shared memory.

[0050] The kernel-level RTP packet pass-through module is implemented as a loadable kernel module (LKM). It registers a Netfilter hook function at the NF_INET_PRE_ROUTING point. When an RTP packet arrives, the hook function is triggered. It first extracts the packet's five-tuple (protocol, source / destination IP, source / destination port) and performs a fast match in the kernel's forwarding rule hash table. If a match is successful, it directly calls the nf_reroute function to modify the packet's destination address and port, and immediately returns NF_STOLEN, instructing Netfilter to "steal" the packet, thus bypassing the subsequent complex UDP protocol stack processing and copy operations to user space. At the same time, it updates the statistics of the corresponding session slot in shared memory.

[0051] In the statistical information reading module, the frequency at which the application layer periodically reads the shared memory is configurable to adapt to the QoS requirements of different network environments, and the reading operation and the kernel layer update operation are mutually exclusive to ensure data consistency. The application layer statistics reading module runs as an independent monitoring thread. The wake-up interval of this thread can be set to the millisecond level through the configuration file (e.g., 100ms by default, 50ms for highly sensitive scenarios). After each wake-up, it first acquires the mutex lock of the shared memory, and then traverses all active session slots in the circular buffer to read relevant data. By calculating the change in the number of packets per unit time, jitter and packet loss rate (QoS indicators) can be evaluated in real time. If it is found that the count of a certain SSRC has not changed for several consecutive monitoring periods (e.g., more than 1 second), a flow interruption detection alarm is triggered. After reading is completed, the mutex lock is released.

[0052] In the application layer takeover module, when falling back to the application layer, the module directly takes over the forwarding based on the session context and statistical information stored in the shared memory, avoiding session reconstruction and ensuring message continuity at the moment of switching.

[0053] Suppose a session currently undergoing high-speed pass-through at the kernel layer needs to start recording due to administrator intervention. The application layer takeover module will first detect this subscription change and immediately write a `DEL SESSION 0x12345678` command to ` / proc / net / rtp_forwarder / rules`. Upon receiving the command, the kernel layer removes the forwarding rule from the forwarding rule hash table. Afterward, RTP packets for the corresponding session will no longer be intercepted by hook functions but will be normally sent to the application layer's socket buffer. Simultaneously, the application layer, based on the complete session context pre-saved in shared memory, immediately creates a socket and begins receiving packets, executes the recording logic, and then re-forwards them. Because the switching action is rapid (milliseconds) and the session state (such as the sequence number) is continuously maintained by the kernel layer through shared memory, the application layer can seamlessly resume the data stream, ensuring zero packet loss and call continuity.

[0054] In summary, the advantages of this invention are: 1. During session establishment, a subscription relationship is negotiated and generated based on SDP. The initial forwarding path is determined based on service requirements including at least one of transcoding, encryption / decryption, recording, or monitoring, generating a determination result. If the determination result indicates that service processing is required, the corresponding service operation is executed and RTP packets are forwarded. If the determination result indicates that the forwarding can be delegated to the kernel layer, the session context is written to shared memory, and forwarding rules are distributed to the kernel layer via the procfs control interface. The kernel layer performs high-speed transparent transmission of RTP packets based on the Netfilter mechanism, while continuously updating the shared memory with statistics including SSRC-based counts and active time. The application layer periodically reads the statistics in the shared memory for QoS monitoring and disconnection detection. During session operation, if a change in subscription relationship, address change, or abnormal situation is detected, the application layer immediately revokes the kernel layer's forwarding rules via the procfs interface and reverts to the application layer taking over forwarding. Achieving dynamic and seamless switching ensures uninterrupted calls and zero packet loss. This is achieved by constructing a dynamic system where the application layer and kernel layer work together to flexibly support diverse real-time communication services while maintaining high performance. The core lies in intelligently determining the service-awareness mechanism at the time of session establishment: if transcoding, encryption, or other service processing is required, the feature-rich application layer takes over; if no complex services are needed, forwarding rules are delegated to the kernel layer through shared memory and the procfs interface, using Netfilter hooks to bypass the protocol stack and achieve high-speed pass-through. Most importantly, if service requirements change during session execution (such as a sudden need for recording), the kernel rules can be revoked and the system can seamlessly fall back to application layer processing based on the session context saved in shared memory. This enables dynamic switching between "high-performance pass-through" and "high-feature service processing" modes based on real-time needs while maintaining uninterrupted calls, ultimately balancing performance and flexibility.

[0055] 2. Through a business awareness mechanism, the forwarding path is intelligently determined based on business requirements such as transcoding and encryption / decryption when the session is established. When it is determined that no business processing is required, the session can be delegating to the kernel layer and using the Netfilter mechanism to perform high-speed transparent transmission of RTP packets. This bypasses the overhead of the traditional UDP protocol stack and frequent switching between user space and kernel space, significantly reducing packet forwarding latency and CPU resource consumption. It is especially suitable for high-concurrency real-time communication scenarios, achieving near-line-speed forwarding capabilities, thereby improving the overall system throughput and response speed.

[0056] 3. Subscription relationships are generated based on SDP negotiation, and the judgment logic is dynamically adjusted through the subscription model and address learning mechanism to ensure that only sessions with preset business requirements are processed at the application layer; otherwise, they are quickly pushed down to the kernel layer. This dynamic path selection mechanism enables the system to flexibly allocate processing resources according to the actual business load, avoiding unnecessary application layer processing overhead. While ensuring the integrity of business functions, it maximizes the advantages of high-speed forwarding at the kernel layer, improving resource utilization efficiency and system scalability.

[0057] 4. During session execution, continuous monitoring of subscription relationship changes, address changes, or abnormal situations is conducted. Once a problem is detected, the application layer can immediately revoke the kernel layer's forwarding rules through the procfs interface and smoothly roll back to the application layer taking over forwarding. This switching process is completed directly based on the session context and statistical information stored in shared memory, without the need to rebuild the session, achieving dynamic and seamless switching. This effectively avoids call interruptions or packet loss, enhances the system's fault tolerance and the continuity of real-time communication, and is especially suitable for application scenarios with extremely high service quality and reliability requirements, such as VoIP and video conferencing.

[0058] 5. By storing session context (such as session ID, address and port information) and statistical information (such as SSRC-based counts and active time) in shared memory (using a ring buffer structure and semaphore mechanism), concurrent access by multiple sessions is supported, and data consistency between the application layer and the kernel layer is ensured. This design reduces the overhead of inter-layer communication, avoids performance bottlenecks caused by data copying or lock contention, makes context synchronization fast and reliable, provides a real-time and accurate data foundation for dynamic switching and QoS monitoring, and improves the overall collaborative efficiency of the system.

[0059] 6. The application layer periodically reads statistical information from shared memory for QoS monitoring and disconnection detection. The reading frequency is configurable, and the monitoring granularity can be adjusted according to the needs of different network environments. This allows system administrators to flexibly respond to network fluctuations or performance changes and achieve proactive operation and maintenance. Combined with a mutual exclusion mechanism to ensure data reading consistency, this monitoring mechanism not only improves the system's ability to respond quickly to abnormal situations, but also supports fine-grained analysis and optimization through continuous updates of statistical information, thereby enhancing the system's adaptability and manageability.

[0060] 7. During dynamic handover, when falling back from the kernel layer to the application layer, the forwarding is taken over directly using the pre-saved session context and statistics in shared memory. There is no need to renegotiation or establish a session, avoiding the session reconstruction overhead and initial delay common in traditional handover methods. This ensures the continuous transmission of RTP packets at the moment of handover, effectively preventing call jitter or data loss caused by handover. It is particularly suitable for communication services with strict real-time requirements, enhancing the smoothness and consistency of the user experience.

[0061] While specific embodiments of the present invention have been described above, those skilled in the art should understand that the specific embodiments described are merely illustrative and not intended to limit the scope of the present invention. Equivalent modifications and variations made by those skilled in the art in accordance with the spirit of the present invention should be covered within the scope of protection of the claims of the present invention.

Claims

1. A service-aware, dynamic, seamless switching method for RTP packet forwarding, characterized in that: Includes the following steps: Step S1: When the session is established, a subscription relationship is generated based on SDP negotiation, and the initial forwarding path is determined according to the business requirements including at least one of transcoding, encryption / decryption, recording or listening, and a determination result is generated. Step S2: If the determination result indicates that service processing is required, then the corresponding service operation is executed and the RTP packet is forwarded; if the determination result indicates that it can be delegated to the kernel layer, then the session context is written to shared memory and the forwarding rules are sent to the kernel layer through the procfs control interface. Step S3: The kernel layer performs high-speed transparent transmission of RTP packets based on the Netfilter mechanism, while continuously updating the shared memory with statistical information including SSRC-based counts and active time. Step S4: The application layer periodically reads the statistical information in the shared memory to perform QoS monitoring and disconnection detection; Step S5: During the session, if a change in subscription relationship, address change, or abnormal situation is detected, the application layer immediately cancels the forwarding rule of the kernel layer through the procfs interface and falls back to the application layer to take over the forwarding, so as to achieve dynamic and seamless switching, ensuring that the call is not interrupted and there is no packet loss.

2. The service-aware, dynamic, seamless switching RTP packet forwarding method as described in claim 1, characterized in that: In step S1, the process of generating the determination result is as follows: The determination of business requirements is based on the subscription model and address learning mechanism. Specifically, it includes: dynamically adjusting the determination logic by listening to session attributes. When the session involves transcoding or encryption / decryption, it is determined that business processing is required; otherwise, it is determined that it can be delegated to the kernel layer.

3. The service-aware, dynamic, seamless switching RTP packet forwarding method as described in claim 1, characterized in that: In step S2, the session context written to the shared memory includes session ID, source address, destination address, port information, and service identifier, and is sent to the kernel layer in the form of forwarding rules through the procfs interface to achieve context synchronization between the application layer and the kernel layer. The shared memory is used to store statistical information and session context in a ring buffer structure, supports concurrent access by multiple sessions, and achieves efficient synchronization between the application layer and the kernel layer through a semaphore mechanism.

4. The service-aware, dynamic, seamless switching RTP packet forwarding method as described in claim 1, characterized in that: In step S3, when performing the high-speed pass-through, the overhead of the UDP protocol stack and the switching between user mode and kernel mode is bypassed. The RTP packets are processed directly based on the Netfilter hook function, and the timekeeping information is returned in real time through shared memory.

5. The service-aware, dynamic, seamless switching RTP packet forwarding method as described in claim 1, characterized in that: In step S4, the frequency at which the application layer periodically reads the shared memory is configurable to adapt to the QoS requirements of different network environments, and the read operation and the kernel layer update operation are mutually exclusive to ensure data consistency. In step S5, when falling back to the application layer, the forwarding is directly taken over based on the session context and statistical information stored in the shared memory, avoiding session reconstruction and ensuring packet continuity at the moment of switching.

6. A service-aware, dynamic, seamless switching RTP packet forwarding system, characterized in that: Includes the following modules: The initial forwarding path determination module is used to generate a subscription relationship based on SDP negotiation when a session is established, and to determine the initial forwarding path according to business requirements including at least one of transcoding, encryption / decryption, recording or listening, and generate a determination result. The determination result execution module is used to execute the corresponding business operation and forward the RTP packet if the determination result is that business processing is required; if the determination result is that it can be delegated to the kernel layer, the session context is written to shared memory and the forwarding rules are sent to the kernel layer through the procfs control interface. The RTP packet pass-through module is used by the kernel layer to perform high-speed pass-through of RTP packets based on the Netfilter mechanism, while continuously updating the shared memory with statistical information including SSRC-based counts and active time. The statistics information reading module is used by the application layer to periodically read the statistics information in the shared memory for QoS monitoring and disconnection detection. The application layer takeover module is used to immediately revoke the forwarding rules of the kernel layer through the procfs interface if a change in subscription relationship, address change or abnormal situation is detected during the session, and fall back to application layer takeover forwarding to achieve dynamic and seamless switching, ensuring that the call is not interrupted and there is no packet loss.

7. The service-aware, dynamic, seamless switching RTP packet forwarding system as described in claim 6, characterized in that: In the initial forwarding path determination module, the process of generating the determination result is as follows: The determination of business requirements is based on the subscription model and address learning mechanism. Specifically, it includes: dynamically adjusting the determination logic by listening to session attributes. When the session involves transcoding or encryption / decryption, it is determined that business processing is required; otherwise, it is determined that it can be delegated to the kernel layer.

8. The service-aware, dynamic, seamless switching RTP packet forwarding system as described in claim 6, characterized in that: In the determination result execution module, the session context written to the shared memory includes session ID, source address, destination address, port information, and service identifier, and is sent to the kernel layer in the form of forwarding rules through the procfs interface to realize context synchronization between the application layer and the kernel layer. The shared memory is used to store statistical information and session context in a ring buffer structure, supports concurrent access by multiple sessions, and achieves efficient synchronization between the application layer and the kernel layer through a semaphore mechanism.

9. A service-aware, dynamic, seamless switching RTP packet forwarding system as described in claim 6, characterized in that: In the RTP packet pass-through module, when the high-speed pass-through is executed, the overhead of UDP protocol stack and user mode to kernel mode switching is bypassed. The RTP packets are processed directly based on Netfilter hook functions, and the timekeeping information is returned in real time through shared memory.

10. A service-aware, dynamic, seamless switching RTP packet forwarding system as described in claim 6, characterized in that: In the statistical information reading module, the frequency at which the application layer periodically reads the shared memory is configurable to adapt to the QoS requirements of different network environments, and the reading operation and the kernel layer update operation are mutually exclusive to ensure data consistency. In the application layer takeover module, when falling back to the application layer, the module directly takes over the forwarding based on the session context and statistical information stored in the shared memory, avoiding session reconstruction and ensuring message continuity at the moment of switching.