CN109428864B - Method and device for improving quality of nginx-rtmp pull flow service - Google Patents

Method and device for improving quality of nginx-rtmp pull flow service Download PDF

Info

Publication number
CN109428864B
CN109428864B CN201710761733.0A CN201710761733A CN109428864B CN 109428864 B CN109428864 B CN 109428864B CN 201710761733 A CN201710761733 A CN 201710761733A CN 109428864 B CN109428864 B CN 109428864B
Authority
CN
China
Prior art keywords
event
service
standby
main
pull
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN201710761733.0A
Other languages
Chinese (zh)
Other versions
CN109428864A (en
Inventor
何绍富
张文明
陈少杰
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Wuhan Douyu Network Technology Co Ltd
Original Assignee
Wuhan Douyu Network Technology Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Wuhan Douyu Network Technology Co Ltd filed Critical Wuhan Douyu Network Technology Co Ltd
Priority to CN201710761733.0A priority Critical patent/CN109428864B/en
Publication of CN109428864A publication Critical patent/CN109428864A/en
Application granted granted Critical
Publication of CN109428864B publication Critical patent/CN109428864B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L65/00Network arrangements, protocols or services for supporting real-time applications in data packet communication
    • H04L65/60Network streaming of media packets
    • H04L65/61Network streaming of media packets for supporting one-way streaming services, e.g. Internet radio
    • H04L65/612Network streaming of media packets for supporting one-way streaming services, e.g. Internet radio for unicast
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L41/00Arrangements for maintenance, administration or management of data switching networks, e.g. of packet switching networks
    • H04L41/06Management of faults, events, alarms or notifications
    • H04L41/0654Management of faults, events, alarms or notifications using network fault recovery
    • H04L41/0663Performing the actions predefined by failover planning, e.g. switching to standby network elements
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L65/00Network arrangements, protocols or services for supporting real-time applications in data packet communication
    • H04L65/60Network streaming of media packets
    • H04L65/75Media network packet handling
    • H04L65/765Media network packet handling intermediate
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L65/00Network arrangements, protocols or services for supporting real-time applications in data packet communication
    • H04L65/80Responding to QoS
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L67/00Network arrangements or protocols for supporting network services or applications
    • H04L67/01Protocols
    • H04L67/02Protocols based on web technology, e.g. hypertext transfer protocol [HTTP]
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L67/00Network arrangements or protocols for supporting network services or applications
    • H04L67/14Session management

Landscapes

  • Engineering & Computer Science (AREA)
  • Multimedia (AREA)
  • Computer Networks & Wireless Communication (AREA)
  • Signal Processing (AREA)
  • Data Exchanges In Wide-Area Networks (AREA)
  • Computer And Data Communications (AREA)

Abstract

The invention provides a method and a device for improving quality of nginx-rtmp pull flow service, wherein the method comprises the following steps: s1, when the back-end service connection is abnormal, calling a relay session closing method, and judging whether the current relay session is a pull flow with a main backup; s2, if the judgment result is yes, acquiring the asynchronous processing event switched between the registered main and standby modes during session loading from the relay session, and adding a first timer for the asynchronous processing event; and S3, closing the current relay session, calling an event processing function corresponding to the asynchronous processing event after the first timer expires, and creating a new service connection for the back-end server. According to the invention, the main and standby logics are added in the nginx-rtmp, when a certain service is disconnected, seamless switching between the main and standby services is started to carry out pull forwarding, so that the quality of the pull forwarding service can be improved by one order of magnitude, and the front-end display is basically not influenced.

Description

Method and device for improving quality of nginx-rtmp pull flow service
Technical Field
The invention relates to the technical field of live broadcasting, in particular to a method and a device for improving quality of nginx-rtmp pull stream service.
Background
How to guarantee live broadcast fluency and stability, guarantee that user's watching live broadcast experience is the focus that every live broadcast platform can all pay close attention to, and in the in-process that live broadcast stream CDN pulled to forward the front end show at present, can appear back-end service and CDN service connection unusually to lead to the front end user to watch the in-process of live broadcast and block or blank the screen occasionally, for the not good live broadcast experience of user, the user may choose directly to withdraw from the live broadcast room.
At present, the problem of abnormal connection between a back-end service and a CDN service is solved, and a key node is generally positioned manually and related services are restarted. The problem with this scheme is that the time to locate the key node is long, because the CDN backend may have multiple hops again, the time to restore the service connection is long, and further, the front-end exhibits no response for a long time, and the user experience is still poor.
Disclosure of Invention
The present invention provides a method and apparatus for improving quality of service for a nginx-rtmp pull flow that overcomes, or at least partially solves, the above-mentioned problems.
According to one aspect of the invention, a method for improving quality of service of nginx-rtmp pull flow is provided, which comprises the following steps:
s1, when the back-end service connection is abnormal, calling a relay session closing method, and judging whether the current relay session is a pull flow with a main backup;
s2, if the judgment result is yes, acquiring the asynchronous processing event switched between the registered main and standby modes during session loading from the relay session, and adding a first timer for the asynchronous processing event;
and S3, closing the current relay session, calling an event processing function corresponding to the asynchronous processing event after the first timer expires, and creating a new service connection for the back-end server.
Wherein, before the step S1, the method further includes:
s0, adding a backup parameter in a pull configuration item of the nginx-rtmp module configuration file, wherein the value of the backup parameter is the url of the standby pull stream;
s01, initializing the main and standby modes by analyzing the configuration file, creating an asynchronous processing event and a second timer for switching between the main and standby modes according to the analysis result, and registering an event processing function triggered by the asynchronous processing event;
and S02, starting a second timer task, and if the main service connection is abnormal, executing the event processing function after the second timer is overtime.
Wherein the step S01 further includes:
s011, analyzing the configuration file, storing a result obtained by analyzing the backup parameters and a result obtained by analyzing the url corresponding to the main service into a target structure corresponding to the pull stream, and adding an initialized control switching identifier into the target structure;
s012, according to the data in the target structure, creating an event processing object switched between the main mode and the standby mode;
and S013, registering an event processing function of the event processing object and adding a second timer to the event processing object.
Wherein, analyzing the configuration file in step S011 further includes:
and adding a command for analyzing backups parameters in the nginx-rtmp replay module, and analyzing the urls corresponding to the main service and the standby pull stream into ip addresses, port addresses and http parameters.
Wherein the step S012 further includes:
applying for a new event storage space from nginx-pool;
setting a target structure which is obtained by the url analysis completion corresponding to the main and standby service as an event processing object;
and applying for a slot from the global events queue, and inserting the event processing object into the global events queue.
In step S3, the step of calling the event processing function corresponding to the asynchronous processing event and creating a new service connection for the backend server further includes:
acquiring data in a target structure corresponding to the event processing object through the epoll event;
judging whether the service to be linked is a main service or a standby service according to the value of the control switching identifier in the target structure;
and creating service connection corresponding to the judgment result, and modifying the value of the control switching identifier.
Wherein the step S3 further includes:
if the service connection corresponding to the judgment result is failed to be established, calling the event processing function of the asynchronous processing event again to establish other service connections for the back-end server after the third timer is overtime.
According to another aspect of the present invention, there is provided an apparatus for improving quality of service of nginx-rtmp pull flows, comprising:
the judging module is used for calling a relay session closing method when the back-end service connection is abnormal, and judging whether the current relay session is a pull flow with a main server and a standby server;
an event obtaining module, configured to, if the determination result is yes, obtain, from the relay session, an asynchronous processing event that is switched between the registered master and standby modes during session loading, and add a first timer to the asynchronous processing event;
and the service connection switching module is used for closing the current relay session, calling an event processing function corresponding to the asynchronous processing event after the first timer is timed out, and establishing a new service connection for the back-end server.
According to another aspect of the present invention, there is provided an apparatus for improving quality of service of nginx-rtmp pull flows, comprising: a memory, a processor, and a bus,
the processor and the memory complete mutual communication through the bus;
the memory stores program instructions executable by the processor, which invokes the program instructions in the memory to perform the method as previously described.
According to yet another aspect of the invention, there is provided a non-transitory computer readable storage medium storing computer instructions which cause the computer to perform the method as described above.
According to the method and the device for improving the quality of the nginx-rtmp service, the main and standby logic is added into the nginx-rtmp, when a certain service is disconnected, seamless switching between the main and standby services is started to forward the pull flow, the quality of the pull flow forwarding service can be improved by one order of magnitude, and front-end display is basically not influenced.
Drawings
Fig. 1 is a schematic flowchart of a method for improving quality of service of a nginx-rtmp pull flow according to an embodiment of the present invention;
fig. 2 is a schematic structural diagram of an apparatus for improving quality of service of a nginx-rtmp pull flow according to another embodiment of the present invention;
fig. 3 is a schematic structural diagram of an apparatus for improving quality of service of a nginx-rtmp pull flow according to another embodiment of the present invention.
Detailed Description
The following detailed description of embodiments of the present invention is provided in connection with the accompanying drawings and examples. The following examples are intended to illustrate the invention but are not intended to limit the scope of the invention.
As shown in fig. 1, a schematic flow chart of a method for improving quality of service of a nginx-rtmp pull flow according to an embodiment of the present invention includes:
s1, when the back-end service connection is abnormal, calling a relay session closing method, and judging whether the current relay session is a pull flow with a main backup;
s2, if the judgment result is yes, acquiring the asynchronous processing event switched between the registered main and standby modes during session loading from the relay session, and adding a first timer for the asynchronous processing event;
and S3, closing the current relay session, calling an event processing function corresponding to the asynchronous processing event after the first timer expires, and creating a new service connection for the back-end server.
In the live broadcast platform architecture of the embodiment of the invention, the video server side is a nginx server and is used for receiving the video and audio source provided by the main broadcast side and providing streaming service for the client side. The process that the anchor terminal transmits the recorded video and audio source to the video server terminal through the network after certain processing (preprocessing, coding and packaging) is called plug flow. It can be known that before streaming, the video and audio data must be encapsulated by using a transport protocol to become streaming data. Common streaming protocols include RTSP, RTMP, HLS, and the like, delay of using RTMP transmission is usually 1-3 seconds, and for a scene with a very high real-time requirement, such as mobile phone live broadcast, RTMP has become the most common streaming protocol in mobile phone live broadcast. And then, pushing the video and audio stream data to a video server through a certain Qos algorithm. The video server side performs certain processing and transcoding on the received video and audio stream data, so that the data stream supports pull streams in formats of HLS, HTTP-FLV, RTMP and the like, supports more than one turn, adapts to terminals with different networks and resolutions, and distributes the video and audio stream data to the client side through the CDN node. And pulling the video and audio stream data by using the specified address and then providing the video and audio stream data to the client, wherein the process is the process of pulling the stream. Push streaming is used as the transmission of a video source, and is much higher than pull streaming in stability and speed, and the stability and speed of pull streaming become more critical factors influencing the live broadcast watching experience of a user. Therefore, the embodiment of the invention mainly considers how to improve the service quality of pull flow forwarding.
Specifically, the streaming refers to a process of pulling live content from a back-end server (i.e., a video server) by using a specified address, and the occurrence of an abnormality in the back-end service in S1 refers to the fact that when the connection between the back-end server and the CDN node is abnormal, the CDN node cannot pull the live content, which causes a situation that the live content played at the front end is stuck, delayed, or black, and brings a bad experience to a user. When the back-end service connection is abnormal, in order to ensure the user experience, the embodiment of the invention adds a timing processing task before closing the current relay session, tries to switch the service connection and carries out the connection process of the standby service. Therefore, in S1, when the backend service connection is abnormal, the method ngx _ rtmp _ relay _ close is called, and in the method ngx _ rtmp _ relay _ close, it is determined whether the current relay session is a pull stream that owns a main line and a standby line, that is, whether the current pull stream line owns both the main line and the standby line. To make the pull stream become a pull stream with a main/standby mode, a value added in a pull configuration item of an original nginx-rtmp module configuration file is a parameter of a standby pull stream url, and whether a current pull stream line has a main line and a standby line at the same time is judged according to whether a result obtained by analyzing the configuration file contains a result of analyzing the standby pull stream url.
In S2, if the current relay session is a pull flow with a master mode and a slave mode, it indicates that a flow switching may be performed, and an asynchronous processing event for switching between the master mode and the slave mode, which is registered when the session is loaded, is obtained from the current relay session, where the asynchronous processing event is used to be triggered when an abnormal connection condition occurs, and a corresponding event processing function is called, thereby implementing a switch between the master mode and the slave mode. Meanwhile, a first timer is added for the acquired asynchronous processing event.
And if the current relay session does not have the pull flow of the main and standby relay sessions, directly closing the current relay session.
And S3, closing the current relay session, releasing the resources, calling an event processing function corresponding to the asynchronous processing event after the first timer is overtime, and creating a new service connection. If the back-end server of the current link is the main server, the corresponding event processing function is called through the triggering of the asynchronous event, and the current link is switched to the standby server, so that the switching of the service connection from the main mode to the standby mode is realized; if the back-end server of the current link is the standby server, the corresponding event processing function is called through the triggering of the asynchronous event, and the current link is switched to the main server, so that the switching of the service connection from the standby mode to the main mode is realized. And the stability of pull stream forwarding is realized through seamless switching between the main mode and the standby mode.
According to the embodiment of the invention, under the condition that the services of the nginx-rtmp pull flow rear end are abnormal, a timing processing task is added before the corresponding session is closed, the service switching is attempted, and an auxiliary service connection process is carried out. The method and the system can seamlessly provide reliable service for the front-end user, the front end basically has no awareness of the switching of the back end, and the service quality can be effectively improved. And the seamless switching does not need human intervention, thereby saving the time for artificial response troubleshooting and ensuring that the front-end display is not influenced. After the back-end services the problem, the related personnel still need to position and troubleshoot the related problem, and only the display of the front-end user is not influenced any more, and the problem processing process is also transparent to the user. If the external service abnormal rate of a single service is x%, the external service abnormal rate of the main service and the standby service is (x%. x%), so theoretically, the quality of the nginx-rtmp pull forwarding service can be improved by one order of magnitude by using the method.
In another embodiment of the present invention, on the basis of the above embodiment, before the step S1, the method further includes:
s0, adding a backup parameter in a pull configuration item of the nginx-rtmp module configuration file, wherein the value of the backup parameter is the url of the standby pull stream;
s01, initializing the main and standby modes by analyzing the configuration file, creating an asynchronous processing event and a second timer for switching between the main and standby modes according to the analysis result, and registering an event processing function triggered by the asynchronous processing event;
and S02, starting a second timer task, and if the main service connection is abnormal, executing the event processing function after the second timer is overtime.
Specifically, in order to implement switching of service connection under the condition of an abnormal service of the back end of the nginx-rtmp stream, the configuration file needs to be modified first, because the overall modification in the embodiment of the present invention is based on the nginx-rtmp module, specifically, the step of adding a backup parameter to a pull configuration item of the original nginx-rtmp configuration file is implemented, and the value of the parameter is the url of the standby pull stream.
And then, when the nginx-rtmp server is started, analyzing the modified configuration file, wherein the main purpose of analyzing the configuration file is to realize the initialization of the connection mode of the main service and the standby service, so that the url addresses of the main service and the standby service are converted into specific IP addresses, port addresses and htttp related parameters, and the connection can be quickly established according to the analysis results when the services are needed. Because the nginx server is an event-driven mechanism, in order to realize the switching of the service connection between the main mode and the standby mode, an asynchronous processing event for switching between the main mode and the standby mode is also required to be created according to an analysis result, a second timer is added for the asynchronous processing event, and an event processing function triggered by the asynchronous processing event is registered.
And starting a second timer task, if the main service connection is abnormal under the current condition, calling the event processing function for the first time after the second timer is overtime to switch the main service connection into the standby service connection, thereby realizing the first optimal process.
Wherein the step S01 further includes:
s011, analyzing the configuration file, storing a result obtained by analyzing the backup parameters and a result obtained by analyzing the url corresponding to the main service into a target structure corresponding to the pull stream, and adding an initialized control switching identifier into the target structure;
the concrete implementation is as follows: adding a command for analyzing backups parameters in an nginx-rtmp playback module, analyzing url of corresponding main service and url of standby service into ip/port/args and the like, namely ip address, port address, http parameters and the like, simultaneously storing a result obtained by analyzing the standby url and a result obtained by the url of a main server into a target corresponding to pull stream of pull (each pull has a target structure for the rear service), and adding an initialized control switching identifier into the target, wherein the identifier is used for identifying which rear-end service is switched to.
S012, according to the data in the target structure, creating an event processing object switched between the main mode and the standby mode;
the specific implementation process is as follows: firstly, applying for a new event storage space from nginx-pool; setting a target structure which is obtained by the url analysis completion corresponding to the main and standby service as an event processing object; and applying for a slot from the global events queue, and inserting the event processing object into the global events queue.
And S013, registering an event processing function of the event processing object and adding a second timer to the event processing object.
Specifically, an event handling function of the event handling object is registered, that is, an interface for calling the event handling function is given, and a second timer is added to the event handling object. And executing through the events queue, starting a second timer task, and when the connection fails, namely the main service cannot provide the service under the current condition, executing the event processing function after the second timer is overtime, so as to switch the main service into the standby service.
Based on the foregoing embodiments, the step of calling the event processing function corresponding to the asynchronous processing event in step S3 and creating a new service connection for the backend server further includes:
acquiring data in a target structure corresponding to the event processing object through the epoll event;
judging whether the service to be linked is a main service or a standby service according to the value of the control switching identifier in the target structure;
and creating service connection corresponding to the judgment result, and modifying the value of the control switching identifier.
Specifically, when the back-end service is abnormal and an asynchronous processing event for switching between the main mode and the standby mode is triggered, an event processing function is called to create a new connection, and the specific implementation process is as follows: acquiring data in a target structure corresponding to the event processing object through the epoll event, wherein the data comprises a main service url analysis result, a standby service url analysis result and a control switching identifier; then, according to the value of the control switching identifier, whether the service to be linked is a main service or a standby service is judged; and establishing corresponding service connection according to the judgment result, for example, if the service to be linked is the standby service, establishing a standby service link according to the analysis result of the standby service url, and modifying the value of the control switching identifier so as to switch to another service next time.
Wherein the step S3 further includes:
if the service connection corresponding to the judgment result is failed to be established, calling the event processing function of the asynchronous processing event again to establish other service connections for the back-end server after the third timer is overtime.
If a plurality of standby service lines exist in the system, when the establishment of the service connection corresponding to the judgment result also fails, after a certain time, a third timer is used for timing, and the event processing function is called to select other standby services to establish a new connection.
As shown in fig. 2, a schematic structural diagram of an apparatus for improving quality of service of a nginx-rtmp pull flow according to another embodiment of the present invention includes: a judging module 21, an event acquiring module 22 and a service connection switching module 23, wherein,
the determining module 21 is configured to, when the backend service connection is abnormal, invoke a relay session closing method, and determine whether a current relay session is a pull flow having a main standby function;
an event obtaining module 22, configured to, if the determination result is yes, obtain, from the relay session, an asynchronous processing event that is switched between the registered master and standby modes during session loading, and add a first timer to the asynchronous processing event;
and the service connection switching module 23 is configured to close the current relay session, and call an event processing function corresponding to the asynchronous processing event after the first timer expires, so as to create a new service connection for the back-end server.
Specifically, the streaming refers to a process of pulling live content on a back-end server by using a specified address, and the abnormal occurrence of the back-end service refers to the situation that when the connection between the back-end server and a CDN node is abnormal, the CDN node cannot pull the live content, so that the live content played by a front end is jammed, delayed, or black, and poor experience is brought to a user. When the back-end service connection is abnormal, in order to ensure the user experience, the embodiment of the invention adds a timing processing task before closing the current relay session, tries to switch the service connection and carries out the connection process of the standby service. Therefore, the determining module 21 is configured to, when the backend service connection is abnormal, invoke a relay session closing method ngx _ rtmp _ relay _ close, and determine whether the current relay session is a pull stream having a main line and a standby line in the ngx _ rtmp _ relay _ close method, that is, determine whether the current pull stream line has the main line and the standby line at the same time. To make the pull stream become a pull stream with a main/standby mode, a value added in a pull configuration item of an original nginx-rtmp module configuration file is a parameter of a standby pull stream url, and whether a current pull stream line has a main line and a standby line at the same time is judged according to whether a result obtained by analyzing the configuration file contains a result of analyzing the standby pull stream url.
The event obtaining module 22 is configured to, if the current relay session is a pull flow with a master mode and a slave mode, indicate that a flow switching may be performed, and obtain an asynchronous processing event for switching between the master mode and the slave mode, which is registered when the session is loaded, from the current relay session, where the asynchronous processing event is used to be triggered when an abnormal connection condition occurs, and a corresponding event processing function is called, so as to implement switching between the master mode and the slave mode. Meanwhile, a first timer is added for the acquired asynchronous processing event.
And if the current relay session does not have the pull flow of the main and standby relay sessions, directly closing the current relay session.
The service connection switching module 23 is configured to close the current relay session, release resources, and call an event processing function corresponding to the asynchronous processing event after the first timer expires, so as to create a new service connection. If the current link is the main server, the corresponding event processing function is called through the triggering of the asynchronous event, and the current link is switched to the standby server, so that the switching of the service connection from the main mode to the standby mode is realized; if the current link is the standby server, the corresponding event processing function is called by starting the asynchronous event, and the current link is switched to the main server, so that the switching of the service connection from the standby mode to the main mode is realized, and the stability of pull stream forwarding is realized by seamless switching between the main mode and the standby mode.
Based on the above embodiment, further include:
the configuration file modification module is used for adding a backup parameter in a pull configuration item of the nginx-rtmp module configuration file, and the value of the backup parameter is the url of the standby pull stream;
the event creating module is used for initializing the main and standby modes by analyzing the configuration file, creating an asynchronous processing event and a second timer for switching between the main and standby modes according to an analysis result, and registering an event processing function triggered by the asynchronous processing event;
and the timed task starting module is used for starting a second timer task, and executing the event processing function after the second timer is overtime if the main service connection is abnormal.
Wherein the event creation module is specifically configured to:
analyzing the configuration file, simultaneously storing a result obtained by analyzing the backup parameters and a result obtained by analyzing the url corresponding to the main service into a target structure corresponding to the pull stream, and adding an initialized control switching identifier into the target structure;
according to the data in the target structure, creating an event processing object for switching between the main mode and the standby mode;
registering an event processing function of the event processing object, and adding a second timer for the event processing object.
The service connection switching module 23 is specifically configured to:
acquiring data in a target structure corresponding to the event processing object through the epoll event;
judging whether the service to be linked is a main service or a standby service according to the value of the control switching identifier in the target structure;
and creating service connection corresponding to the judgment result, and modifying the value of the control switching identifier.
Wherein, the service connection switching module 23 is further configured to:
if the service connection corresponding to the judgment result is failed to be established, calling the event processing function of the asynchronous processing event again to establish other service connections after the third timer is overtime.
According to the device for improving the quality of the nginx-rtmp pull flow service, the main and standby logic is added in the nginx-rtmp, when a certain service is disconnected, seamless switching between the main and standby services is started to forward the pull flow, the quality of the pull flow forwarding service can be improved by one order of magnitude, and front-end display is basically not influenced.
As shown in fig. 3, a schematic structural diagram of an apparatus for improving quality of service of nginx-rtmp pull flow according to an embodiment of the present invention includes: a memory, a processor, and a bus,
the processor and the memory complete mutual communication through the bus;
the memory stores program instructions executable by the processor, and the processor calls the program instructions in the memory to perform the method according to the embodiments, for example, including: s1, when the back-end service connection is abnormal, calling a relay session closing method, and judging whether the current relay session is a pull flow with a main backup; s2, if the judgment result is yes, acquiring the asynchronous processing event switched between the registered main and standby modes during session loading from the relay session, and adding a first timer for the asynchronous processing event; and S3, closing the current relay session, calling an event processing function corresponding to the asynchronous processing event after the first timer expires, and creating a new service connection for the back-end server.
According to yet another aspect of the present invention, there is provided a non-transitory computer readable storage medium storing computer instructions that cause the computer to perform a method as described in the various embodiments above, for example, comprising: s1, when the back-end service connection is abnormal, calling a relay session closing method, and judging whether the current relay session is a pull flow with a main backup; s2, if the judgment result is yes, acquiring the asynchronous processing event switched between the registered main and standby modes during session loading from the relay session, and adding a first timer for the asynchronous processing event; and S3, closing the current relay session, calling an event processing function corresponding to the asynchronous processing event after the first timer expires, and creating a new service connection for the back-end server.
Those of ordinary skill in the art will understand that: all or part of the steps for implementing the method embodiments may be implemented by hardware related to program instructions, and the program may be stored in a computer readable storage medium, and when executed, the program performs the steps including the method embodiments; and the aforementioned storage medium includes: various media that can store program codes, such as ROM, RAM, magnetic or optical disks.
The above-described embodiments of the apparatus for improving quality of service of nginx-rtmp pull stream are merely illustrative, wherein the units described as separate components may or may not be physically separate, and the components displayed as units may or may not be physical units, may be located in one place, or may be distributed on a plurality of network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the solution of the present embodiment. One of ordinary skill in the art can understand and implement it without inventive effort.
Through the above description of the embodiments, those skilled in the art will clearly understand that each embodiment can be implemented by software plus a necessary general hardware platform, and certainly can also be implemented by hardware. With this understanding in mind, the above-described technical solutions may be embodied in the form of a software product, which can be stored in a computer-readable storage medium such as ROM/RAM, magnetic disk, optical disk, etc., and includes instructions for causing a computer device (which may be a personal computer, a server, or a network device, etc.) to execute the methods described in the embodiments or some parts of the embodiments.
Finally, the method of the present invention is only a preferred embodiment and is not intended to limit the scope of the present invention. Any modification, equivalent replacement, or improvement made within the spirit and principle of the present invention should be included in the protection scope of the present invention.

Claims (10)

1. The method for improving quality of service of nginx-rtmp pull flow is characterized by comprising the following steps:
s1, adding a backup parameter in a pull configuration item of the nginx-rtmp module configuration file, wherein the value of the backup parameter is the url of the standby pull stream; when the back-end service connection is abnormal, a relay session closing method is called to judge whether the current relay session is a pull flow with a main standby state or not;
s2, if the judgment result is yes, acquiring the asynchronous processing event switched between the registered main and standby modes during session loading from the relay session, and adding a first timer for the asynchronous processing event;
s3, closing the current relay session, calling an event processing function corresponding to the asynchronous processing event after the first timer expires, and creating a new service connection for the back-end server;
the method for closing the relay session is used for judging whether the current stream pulling line has a main line and a standby line at the same time.
2. The method as claimed in claim 1, wherein the step of adding a backups parameter to the pull configuration item of the nginx-rtmp module configuration file further comprises:
s01, initializing the main and standby modes by analyzing the configuration file, creating an asynchronous processing event and a second timer for switching between the main and standby modes according to the analysis result, and registering an event processing function triggered by the asynchronous processing event;
and S02, starting a second timer task, and if the main service connection is abnormal, executing the event processing function after the second timer is overtime.
3. The method according to claim 2, wherein the step S01 further comprises:
s011, analyzing the configuration file, storing a result obtained by analyzing the backup parameters and a result obtained by analyzing the url corresponding to the main service into a target structure corresponding to the pull stream, and adding an initialized control switching identifier into the target structure;
s012, according to the data in the target structure, creating an event processing object switched between the main mode and the standby mode;
and S013, registering an event processing function of the event processing object and adding a second timer to the event processing object.
4. The method of claim 3, wherein parsing the configuration file in step S011 further comprises:
and adding a command for analyzing backups parameters in the nginx-rtmp replay module, and analyzing the urls corresponding to the main service and the standby pull stream into ip addresses, port addresses and http parameters.
5. The method according to claim 3, wherein the step S012 further comprises:
applying for a new event storage space from nginx-pool;
setting a target structure which is obtained by the url analysis completion corresponding to the main and standby service as an event processing object;
and applying for a slot from the global events queue, and inserting the event processing object into the global events queue.
6. The method according to claim 3, wherein the step S3 calls an event handling function corresponding to the asynchronous processing event, and the step of creating a new service connection for the backend server further comprises:
acquiring data in a target structure corresponding to the event processing object through the epoll event;
judging whether the service to be linked is a main service or a standby service according to the value of the control switching identifier in the target structure;
and creating service connection corresponding to the judgment result, and modifying the value of the control switching identifier.
7. The method according to claim 6, wherein the step S3 further comprises:
if the service connection corresponding to the judgment result is failed to be established, calling the event processing function of the asynchronous processing event again to establish other service connections for the back-end server after the third timer is overtime.
8. An apparatus for improving quality of service of nginx-rtmp pull flows, comprising:
the judgment module is used for adding a backup parameter in a pull configuration item of the nginx-rtmp module configuration file, and the value of the backup parameter is the url of the standby pull stream; when the back-end service connection is abnormal, a relay session closing method is called to judge whether the current relay session is a pull flow with a main standby state or not;
the relay session closing method is used for judging whether the current stream pulling line has a main line and a standby line at the same time;
an event obtaining module, configured to, if the determination result is yes, obtain, from the relay session, an asynchronous processing event that is switched between the registered master and standby modes during session loading, and add a first timer to the asynchronous processing event;
and the service connection switching module is used for closing the current relay session, calling an event processing function corresponding to the asynchronous processing event after the first timer is timed out, and establishing a new service connection for the back-end server.
9. The equipment for improving quality of service of nginx-rtmp pull flow is characterized by comprising the following components: a memory, a processor, and a bus,
the processor and the memory complete mutual communication through the bus;
the memory stores program instructions executable by the processor, which invokes the program instructions in the memory to perform the method of any of claims 1 to 7.
10. A non-transitory computer-readable storage medium storing computer instructions that cause a computer to perform the method of any one of claims 1 to 7.
CN201710761733.0A 2017-08-30 2017-08-30 Method and device for improving quality of nginx-rtmp pull flow service Active CN109428864B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201710761733.0A CN109428864B (en) 2017-08-30 2017-08-30 Method and device for improving quality of nginx-rtmp pull flow service

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201710761733.0A CN109428864B (en) 2017-08-30 2017-08-30 Method and device for improving quality of nginx-rtmp pull flow service

Publications (2)

Publication Number Publication Date
CN109428864A CN109428864A (en) 2019-03-05
CN109428864B true CN109428864B (en) 2021-11-09

Family

ID=65504080

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201710761733.0A Active CN109428864B (en) 2017-08-30 2017-08-30 Method and device for improving quality of nginx-rtmp pull flow service

Country Status (1)

Country Link
CN (1) CN109428864B (en)

Families Citing this family (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN110545439A (en) * 2019-08-29 2019-12-06 中邮科通信技术股份有限公司 Rtmp multi-concurrent live broadcast system and method based on streaming media service
CN111083521B (en) * 2019-12-27 2022-02-01 杭州当虹科技股份有限公司 RTMP release main/standby fast switching method
CN111464759B (en) * 2020-03-26 2022-03-18 广州虎牙科技有限公司 Live broadcast directing method, device, storage medium and equipment
CN113656162A (en) * 2021-08-18 2021-11-16 恒生电子股份有限公司 Resource application method and device, electronic equipment and storage medium
CN114095739B (en) * 2021-10-18 2023-08-01 海南车智易通信息技术有限公司 Video live broadcast system

Citations (8)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101729794A (en) * 2008-10-11 2010-06-09 华为技术有限公司 Method, device and system for realizing live broadcast and live broadcast pretreatment
CN103138983A (en) * 2011-12-01 2013-06-05 苏州达联信息科技有限公司 Method and device of primary-backup switching of video distribution network global server
CN104902289A (en) * 2015-06-29 2015-09-09 秦永红 Design method and system for RTMP (Real Time Messaging Protocol) streaming media live system warm backup
US9135462B2 (en) * 2012-08-29 2015-09-15 Box, Inc. Upload and download streaming encryption to/from a cloud-based platform
CN106254103A (en) * 2016-07-28 2016-12-21 北京中电普华信息技术有限公司 A kind of RTMP group system can Dynamic Configuration and device
CN106656593A (en) * 2016-12-19 2017-05-10 北京华清伟业技术有限公司 Streaming media live broadcast recording redundant hot-standby method and system
CN106973093A (en) * 2017-03-23 2017-07-21 北京奇艺世纪科技有限公司 A kind of service switch method and device
CN107105309A (en) * 2017-04-25 2017-08-29 北京潘达互娱科技有限公司 Live dispatching method and device

Patent Citations (8)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101729794A (en) * 2008-10-11 2010-06-09 华为技术有限公司 Method, device and system for realizing live broadcast and live broadcast pretreatment
CN103138983A (en) * 2011-12-01 2013-06-05 苏州达联信息科技有限公司 Method and device of primary-backup switching of video distribution network global server
US9135462B2 (en) * 2012-08-29 2015-09-15 Box, Inc. Upload and download streaming encryption to/from a cloud-based platform
CN104902289A (en) * 2015-06-29 2015-09-09 秦永红 Design method and system for RTMP (Real Time Messaging Protocol) streaming media live system warm backup
CN106254103A (en) * 2016-07-28 2016-12-21 北京中电普华信息技术有限公司 A kind of RTMP group system can Dynamic Configuration and device
CN106656593A (en) * 2016-12-19 2017-05-10 北京华清伟业技术有限公司 Streaming media live broadcast recording redundant hot-standby method and system
CN106973093A (en) * 2017-03-23 2017-07-21 北京奇艺世纪科技有限公司 A kind of service switch method and device
CN107105309A (en) * 2017-04-25 2017-08-29 北京潘达互娱科技有限公司 Live dispatching method and device

Non-Patent Citations (1)

* Cited by examiner, † Cited by third party
Title
Nginx RTMP 模块 nginx-rtmp-module 指令详解;Defonds;《https://blog.csdn.net/defonds/article/details/9274479/》;20130708;第9页 *

Also Published As

Publication number Publication date
CN109428864A (en) 2019-03-05

Similar Documents

Publication Publication Date Title
CN109428864B (en) Method and device for improving quality of nginx-rtmp pull flow service
CN111246284B (en) Video stream playing method, system, terminal and storage medium
CN112738140B (en) Video stream transmission method, device, storage medium and equipment based on WebRTC
CN108347622B (en) Multimedia data pushing method and device, storage medium and equipment
CN104902289A (en) Design method and system for RTMP (Real Time Messaging Protocol) streaming media live system warm backup
CN106658065B (en) Audio and video synchronization method, device and system
CN108667871B (en) Transmission method and device based on P2P
CN113286190A (en) Cross-network and same-screen control method and device and cross-network and same-screen system
CN107547517B (en) Audio and video program recording method, network equipment and computer device
CN113824925A (en) WEB plug-in-free video monitoring system and method
CN102811342B (en) Video profile cut control, equipment and system
CN104469248A (en) Video session method and device, server and terminal
CN106454538B (en) Real-time bullet screen interaction method
CN109819278B (en) Optimization method of live video
CN109144613B (en) Android definition switching method and device, terminal and readable medium
CN113852866B (en) Media stream processing method, device and system
CN108632681B (en) Method, server and terminal for playing media stream
CN116112620A (en) Processing method and system for improving video stream multipath merging stability
JP4917497B2 (en) Video distribution device, distribution video switching method, distribution video switching program, and distribution video switching program recording medium
CN108377243B (en) Live streaming transmission method and device
US20150271530A1 (en) Video quality enhancement method and apparatus
CN113014615A (en) Data synchronization method, device and system
JP5342578B2 (en) Call control system and information redundancy method used for call control
EP3089459A1 (en) Apparatus and method for implementing video-on-demand quick switching among multiple screens
CN114401254B (en) Streaming media service processing method and device, electronic equipment and storage medium

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant