Audio stream synchronous distribution method, system, electronic device and storage medium
By obtaining the packet sequence number and playback time of the audio stream, adjusting the audio stream calling progress, and adjusting the active and backup attributes according to the loss situation, the problem of audio stream delivery time error and interruption is solved, and the synchronization and smoothness of audio stream switching are improved.
Patent Information
- Application Number
- CN202410141753.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-01-31
- Publication Date
- 2024-10-11
- Estimated Expiration
- 2044-01-31
AI Technical Summary
In the existing technology, there is an audio stream delivery time error when the active and standby servers switch audio streams, resulting in audio stream interruption and loss, affecting user experience.
By obtaining the packet sequence number and playback time of the audio stream, the audio stream calling progress of the standby server is adjusted to synchronize the audio stream transmission of the two servers; when the audio stream is lost, the primary and secondary attributes are determined based on the loss amount and the storage amount, and the attributes are mutually Determine the next packet sequence number when changing to ensure the playback sequence.
It realizes the synchronization of audio stream switching between active and standby servers, reduces the loss and omission of audio streams, and improves switching speed and listening smoothness.
Smart Images

Figure CN117979078B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of audio stream synchronous distribution, and in particular to an audio stream synchronous distribution method, system, electronic device and storage medium. Background Art
[0002] When playing audio, it is inevitable that the audio stream will be lost and interrupted due to various problems. The interruption of audio will bring a bad user experience to the user. The risk resistance of audio tasks can be improved through the deployment of dual-machine hot backup servers. When deploying the server, the main server and the backup server are deployed at the same time, and the two servers run independently. When performing audio output tasks, the main and backup servers respectively send audio streams to the output device, and the output device detects the audio stream. When the currently playing audio stream is detected to be interrupted, it automatically switches to the backup audio stream to achieve the effect of backup and resume playback.
[0003] In the prior art, using the primary and backup servers to switch audio streams has the following disadvantages:
[0004] 1. The error between the initiation time and processing time of the audio output task leads to an error in the time of sending the audio stream;
[0005] 2. The audio stream is interrupted due to network reasons, which further causes many omissions and gaps in the audio stream sent to the device. Summary of the invention
[0006] The present invention provides an audio stream synchronous distribution method to solve the problem that the audio stream sending time is prone to errors during the master-slave switching and the audio stream interruption causes many missing and omissions in the audio stream sent to the device.
[0007] In a first aspect, the present invention provides an audio stream synchronous distribution method, which is applied to an audio stream synchronous distribution system, wherein the audio stream synchronous distribution system includes two servers and an output device that are mutually active and standby, and the server sends the audio stream to the output device in the order of the packet sequence number of the audio stream. The audio stream synchronous distribution method includes:
[0008] When two servers execute an audio task, if the audio stream of the audio task comes from the local server, the play time of the first packet sequence number of the currently played audio stream is obtained;
[0009] Determine the second packet sequence number closest to the playback time in the playback record of the standby server;
[0010] Adjusting the calling progress of the audio stream of the standby server according to the size relationship between the first packet sequence number and the second packet sequence number, so that the audio streams of the two servers are sent synchronously;
[0011] When there is audio stream loss, the master / slave attributes of the two servers are determined according to the number of lost audio streams and the number of audio streams to be played stored on the primary server;
[0012] When the primary and backup attributes are swapped, the packet sequence number of the next audio stream to be played is determined based on the current first packet sequence number.
[0013] In a second aspect, the present invention provides an audio stream synchronous distribution system, the audio stream synchronous distribution system comprising two servers which are mutually active and standby, an output device and a main control center, the server sends the audio stream to the output device in the order of the packet sequence number of the audio stream, and the main control center comprises:
[0014] The first information acquisition module is used to acquire the play time of the first packet sequence number of the currently played audio stream when the two servers execute the audio task, if the audio stream of the audio task comes from the local server;
[0015] A second information acquisition module, used to determine a second packet sequence number closest to the play time in the play record of the standby server;
[0016] A calling progress calibration module, used for adjusting the calling progress of the audio stream of the standby server according to the sequence number size relationship between the first packet sequence number and the second packet sequence number, so that the audio streams of the two servers are sent synchronously;
[0017] A primary and backup attribute determination module, used to determine the primary and backup attributes of the two servers according to the number of lost audio streams and the number of audio streams to be played by the primary server when there is audio stream loss;
[0018] The packet sequence number determination module is used to determine the packet sequence number of the next audio stream to be played according to the current first packet sequence number when the primary and backup attributes are interchanged.
[0019] In a third aspect, the present invention provides an electronic device, the electronic device comprising:
[0020] at least one processor; and
[0021] a memory communicatively connected to the at least one processor; wherein,
[0022] The memory stores a computer program executable by the at least one processor, and the computer program is executed by the at least one processor so that the at least one processor can perform the audio stream synchronous distribution method described in the first aspect of the present invention.
[0023] In a fourth aspect, the present invention provides a computer-readable storage medium storing computer instructions, wherein the computer instructions are used to enable a processor to implement the audio stream synchronous distribution method described in the first aspect of the present invention when executed.
[0024] The embodiment of the present invention provides an audio stream synchronous distribution method, which is applied to an audio stream synchronous distribution system. The audio stream synchronous distribution system includes two servers which are mutually primary and backup. The servers send the audio stream to an output device in the order of the packet numbers of the audio stream. When the two servers execute an audio task, if the audio stream of the audio task comes from the local server, the playback time of the first packet number of the currently played audio stream is obtained; the second packet number closest to the playback time is determined in the playback record of the backup server; the calling progress of the audio stream of the backup server is adjusted according to the relationship between the first packet number and the second packet number, so that the audio streams of the two servers are sent synchronously. Then, the audio calling progress and sending progress of the two servers are synchronized, which can avoid errors in the sending time of the audio stream when the primary and backup attributes are exchanged, achieve the effect of backup and continued playback, and improve the speed of switching the audio streams of the primary and backup servers and the fluency of the listening experience.
[0025] In addition, when there is audio stream loss, the primary and backup attributes of the server are determined based on the number of lost audio streams and the number of audio streams stored in the buffer of the main server. When the primary and backup attributes are swapped, the packet number of the next audio stream to be played is determined based on the current first packet number. This can make the packet number of the next audio stream to be played more in line with the playback order, avoiding the presence of more missing and omissions in the audio stream sent to the output device due to the interruption of the audio stream loss. It can also improve the speed of audio stream switching and the smoothness of the listening experience of the primary and backup servers.
[0026] It should be understood that the contents described in this section are not intended to identify the key or important features of the embodiments of the present invention, nor are they intended to limit the scope of the present invention. Other features of the present invention will become easily understood through the following description. BRIEF DESCRIPTION OF THE DRAWINGS
[0027] In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the following briefly introduces the drawings required for use in the description of the embodiments. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work.
[0028] Figure 1 This is a schematic diagram of synchronous distribution of audio streams between primary and backup servers provided in Embodiment 1 of the present invention;
[0029] Figure 2 is a flow chart of a method for synchronously distributing an audio stream provided by Embodiment 1 of the present invention;
[0030] Figure 3 is a flowchart of an audio stream synchronous distribution method provided by Embodiment 2 of the present invention;
[0031] Figure 4 This is an operation process of an audio stream in an output device provided by Embodiment 2 of the present invention;
[0032] Figure 5 This is a schematic diagram of the structure of a main control center provided by Embodiment 3 of the present invention;
[0033] Figure 6 It is a schematic diagram of the structure of an electronic device provided in Embodiment 4 of the present invention. DETAILED DESCRIPTION
[0034] In order to enable those skilled in the art to better understand the scheme of the present invention, the technical scheme in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work should fall within the scope of protection of the present invention.
[0035] Embodiment 1
[0036] Embodiment 1 of the present invention provides a method for synchronous distribution of audio streams. This embodiment can be applicable to the situation where dual servers are used to synchronously distribute audio streams, and is applied to an audio stream synchronous distribution system. The audio stream synchronous distribution system can be implemented in the form of hardware and / or software, and the audio stream synchronous distribution system can be configured in an electronic device.
[0037] The audio stream synchronous distribution system includes two servers and an output device which are mutually active and standby, and may also include an input device. The server sends the audio stream to the output device in the order of the packet sequence number of the audio stream, wherein the output device may be a speaker.
[0038] Figure 1 A schematic diagram of synchronous distribution of audio streams between primary and backup servers provided in Embodiment 1 of the present invention is shown in FIG. Figure 1As shown, the audio source (audio stream of the audio task) of the main server 11 and the backup server 12 generally comes from the input device 10. Each server is provided with a buffer for storing the audio stream. After receiving the correct audio stream, the server stores it in the buffer. The stored audio stream is the local audio source, and the main and backup servers can communicate with each other. At the same time, the server also needs to send the audio stream to the output device 13. The output device 13 plays the audio stream sent by the main server. Among them, the IPs of the two servers are different. The output device 13 can distinguish the IPs of the servers to record the corresponding identifiers of the current main and backup servers.
[0039] Specifically, the audio stream playback process mainly includes the following steps:
[0040] 1. The server initiates the audio output task, and first divides the task into a trigger task and a timed task. The server initiates the trigger task when it receives the trigger source signal, and the timed task initiates the task after the specified time is reached.
[0041] If the sound source is an input device, the server sends a task input instruction to the input device, which includes the protocol identifier, task information, and audio identifier. The task information includes the volume and the sending address. After receiving the task input instruction, the input device sends the audio stream to the server. At the same time, the server also needs to send the task output instruction to the output device. The task output instruction includes the protocol identifier, task information, audio identifier, and primary and backup identifiers. After that, the server sends the audio stream received or read locally to the output device for output.
[0042] When the two servers execute the audio task, they can verify the consistency of the audio stream sent by the input device and the audio identifier of the audio stream in the task input instruction, specifically including: if the audio stream of the audio task comes from the input device, send the task input instruction to the input device to make the input device send the audio stream; determine whether the audio identifier of the audio stream sent by the input device is the same as the audio identifier in the task input instruction; if so, store the audio stream sent by the input device in the buffer of the server; if not, delete the audio stream sent by the input device. Of course, the verification process can also be completed by the server itself.
[0043] 2. After receiving the audio stream from the primary and backup servers, the output device determines the audio tag of the audio stream. If the audio tag of the audio stream is consistent with the audio identifier of the task output instruction, it is written into the buffer. If not, the audio stream (audio packet) is discarded.
[0044] 3. After receiving the audio stream, the output device loops through the audio stream from the main server and outputs the audio.
[0045] It should be noted that, in the present invention, the audio stream is transmitted between the input device, the server and the output device in the form of an audio package, and the audio package includes an audio identifier, a package number, audio information and audio data. Since it is essentially for transmitting the audio stream, for the convenience of description, this embodiment describes the transmission of the audio stream between the input device, the server and the output device, and does not serve as a content limitation on the information transmitted between the input device, the server and the output device in the present invention.
[0046] Figure 2 A flowchart of a method for synchronously distributing audio streams provided in Embodiment 1 of the present invention is shown in FIG. Figure 2 As shown, the audio stream synchronous distribution method includes:
[0047] S201. When two servers execute an audio task, if the audio stream of the audio task comes from the local server, obtain the play time of the first packet sequence number of the currently played audio stream.
[0048] The audio stream of each audio task corresponds to a packet number. The input device numbers the audio packets (audio streams) to be sent in sequence and sends them to the server. The server sends them to the output device for audio playback according to the packet number, usually in ascending order. For example, an audio includes 200 audio packets (audio streams), which are sequentially sorted as A1, A2...A199, A200. When comparing the size of the packet numbers, the system can automatically take the numbers after the letters as the comparison basis.
[0049] When each server sends an audio stream to an output device, it records the sending time as the playback time corresponding to the audio stream and the packet sequence number.
[0050] If the audio task is a trigger task, because the trigger signal is sent to the main and standby servers at the same time, the system time error of the main and standby servers will not cause the audio stream to be out of sync. However, if it is a timed task, because the task needs to initiate the task according to the system time, the inconsistency of the main and standby time will cause the main and standby server task initiation time to be inconsistent, thereby causing the audio stream to be inconsistent, which will cause errors in the audio stream sending time when the main and standby switch is easy to occur. In an optional embodiment, the main and standby servers have default configuration attributes for determining the default main and standby servers. The main server needs to continue to send heartbeats to the standby server, and the standby server needs to reply after receiving the heartbeat. However, the main and standby attributes of the server are not fixed. After detecting that the heartbeat of the main server is disconnected, the standby server will change its own server attribute to the main server and start sending heartbeats. When the current main server receives the heartbeat reply of the original main server, it sends a protocol to notify the original main server of the change of the main and standby attributes. After receiving the main and standby attribute change protocol, the original main server changes its own attribute to the standby server and stops sending heartbeats. So far, the conversion of the main and standby server attributes has been completed. After the switch, the output device does not need to switch to the current main server, but the time synchronization party has changed from the original main server to the current main server. In order to solve the problem of inconsistent system time between the primary and backup servers, the primary server will periodically calibrate the system time of the backup server. Since the server system will not have a large error in a short period of time, the time calibration protocol does not need to be sent frequently.
[0051] S202: Determine the second packet sequence number closest to the playback time in the playback record of the standby server.
[0052] The play record includes the audio identifier, packet sequence number and play time of the audio stream (audio packet).
[0053] Determine the second packet number closest to the playback time in the playback record of the backup server. For example, the playback time of the first packet number is 09:10:18.10 (indicating 9:10:18.10), and the playback times corresponding to the packet numbers of three audio streams are: 09:10:17.50 (packet number A3), 09:10:18.15 (packet number A4), and 09:10:18.45 (packet number A5). Then, the second packet number closest to the playback time of the first packet number is A4.
[0054] S203: Adjust the calling progress of the audio stream of the standby server according to the size relationship between the first packet sequence number and the second packet sequence number, so that the audio streams of the two servers are sent synchronously.
[0055] As described above, the audio stream of the audio task to be executed by the server can come from an external input device or an audio stream stored locally on the server. If the task audio source comes from the input device, since the audio source is uniformly sent from the input device to the primary and standby servers, there will generally be no situation where the server creates the task time and the audio processing time is out of sync; if the task audio source comes from the local server, since the server needs to assemble the task information, preempt the input and output devices according to the task priority, receive or read and assemble the audio stream in a specified format, send the audio stream, and other operations after the audio task starts, these operations take different times and may cause time errors between the two servers. In addition, during the audio output process, the audio packets actually sent to the device may gradually become out of sync due to the small processing time difference or processing order difference of each audio packet of the primary and standby servers. Since the assembly of task information and the preemption of input and output devices according to the task priority are determined by the performance of the server, it is difficult to make the performance of the two servers completely unified. Therefore, the calling progress of the audio stream of the primary and standby servers can be calibrated. The calling progress of the audio stream includes the reading and sending progress of the audio stream, so that the calling progress of the audio stream of the primary and standby servers is synchronized. The process of calling progress calibration may be performed periodically.
[0056] If the calling progress of the primary and backup servers are the same or similar, then the sequence number sizes of the first packet sequence number and the second packet sequence number must also be similar. Therefore, the calling progress of the backup server can be adjusted according to the sequence number sizes of the first packet sequence number and the second packet sequence number. Because the priority of the primary server is higher than that of the backup server, the calling progress of the backup server for the audio stream is adjusted based on the calling progress of the primary server for the audio stream.
[0057] Specifically, if the first packet sequence number is less than the second packet sequence number, it means that the audio stream call progress of the backup server is faster than that of the main server, so the call progress of the audio stream of the backup server is controlled to be slowed down; if the first packet sequence number is greater than the second packet sequence number, it means that the audio stream call progress of the backup server is slower than that of the main server, so the call progress of the audio stream of the backup server is controlled to be accelerated. If the first packet sequence number is equal to the second packet sequence number, it means that the audio streams of the two servers are sent synchronously, and no adjustment is required.
[0058] Of course, the calibration process of the call progress can also be completed by the standby server itself. First, the main server can periodically send an audio stream progress protocol to the standby server, and the audio stream progress protocol includes the first packet sequence number, the audio identifier associated with the first packet sequence number, and the play time. The standby server calibrates the call progress of the audio stream according to the audio stream progress protocol and the play record.
[0059] S204: When there is audio stream loss, determine the primary and backup attributes of the server according to the number of lost audio streams and the number of stored audio streams to be played on the primary server.
[0060] When the main server has audio stream loss, the severity can be judged according to the number of audio loss losses to determine whether to change the primary and backup attributes of the server. For example, when the number of losses is large and the degree of loss is serious, the server with no audio interruption can be used as the main server in time. When the number of losses is large and the degree of loss is slight, since the playback time of each audio stream is about 20ms, the loss of a few audio streams is difficult for humans to detect, so the current primary and backup attributes can still be maintained. It is also possible to determine whether to change the primary and backup attributes of the two servers based on the number of audio streams to be played on the main server. If the number of audio streams to be played on the main server is small, for example, there are only 1 audio stream or 0 audio streams, then it means that the audio stream may be about to be interrupted. Therefore, the primary and backup attributes can be changed in time to obtain more audio streams to avoid audio stream interruptions.
[0061] S205: When the primary and backup attributes are swapped, the packet sequence number of the next audio stream to be played is determined according to the current first packet sequence number.
[0062] When the primary and backup attributes are swapped, the packet number of the next audio stream to be played is determined based on the current first packet number, so that the packet number of the next audio stream to be played can be more consistent with the playback order, avoiding the presence of more missing and omissions in the audio stream sent to the output device due to audio stream loss and interruption.
[0063] The embodiment of the present invention provides an audio stream synchronous distribution method, which is applied to an audio stream synchronous distribution system. The audio stream synchronous distribution system includes two servers which are mutually primary and backup. The servers send the audio stream to an output device in the order of the size of the packet sequence numbers of the audio stream. The audio stream synchronous distribution method is applied to the primary server, including: when executing an audio task, if the audio stream of the audio task comes from the local server, obtaining the playback time of the first packet sequence number of the currently played audio stream; determining the second packet sequence number closest to the playback time in the playback record of the backup server; adjusting the calling progress of the audio stream of the backup server according to the size relationship between the first packet sequence number and the second packet sequence number, so that the audio streams of the two servers are sent synchronously, then the audio calling progress and sending progress of the two servers are synchronized, which can avoid errors in the sending time of the audio stream when the primary and backup attributes are exchanged, achieve the effect of backup continued broadcasting, and improve the speed of switching the audio streams of the primary and backup servers and the fluency of the listening experience.
[0064] In addition, when there is audio stream loss, the primary and backup attributes of the server are determined based on the number of lost audio streams and the number of audio streams stored in the buffer of the main server. When the primary and backup attributes are swapped, the packet number of the next audio stream to be played is determined based on the current first packet number. This can make the packet number of the next audio stream to be played more in line with the playback order, avoiding the presence of more missing and omissions in the audio stream sent to the output device due to the interruption of the audio stream loss. It can also improve the speed of audio stream switching and the smoothness of the listening experience of the primary and backup servers.
[0065] Embodiment 2
[0066] Figure 3 This is a flowchart of a method for synchronously distributing an audio stream provided in Embodiment 2 of the present invention. Embodiment 2 of the present invention is optimized based on Embodiment 1 above. Figure 3 As shown, the audio stream synchronous distribution method includes:
[0067] S301. When two servers execute an audio task, if the audio stream of the audio task comes from the local server, the play time of the first packet sequence number of the currently played audio stream is obtained.
[0068] S302: Determine the second packet sequence number closest to the play time in the play record of the standby server.
[0069] S303: The sequence number relationship between the first packet sequence number and the second packet sequence number adjusts the calling progress of the audio stream of the standby server so that the audio streams of the two servers are sent synchronously.
[0070] S301-S303 are similar to S101-S103 in the first embodiment, and the details may refer to the relevant contents of S101-S103.
[0071] S304: When there is audio stream loss, obtain the number of lost audio streams and the number of stored audio streams to be played on the primary server.
[0072] The number of audio stream losses can be counted at the output device. The output device detects the audio stream loss, and once the audio loss is detected, the output device starts to accumulate the number of audio stream losses.
[0073] The storage quantity of the audio stream to be played by the main server can be obtained from the buffer of the main server. On the other hand, an audio cache area can also be set in the output device. The audio streams sent by the primary and backup servers are stored in their audio cache areas. Therefore, the storage quantity of the audio stream to be played by the main server can also be obtained from the output device.
[0074] Among them, when the output device receives the audio stream, it may not play the audio stream immediately, but store a small amount of audio stream as a cache before starting to play. When the main server starts audio playback, it selects the audio packet in the middle of the buffer queue to start playing, leaving space for the main and backup servers to switch.
[0075] S305: Determine whether the loss quantity is greater than a preset loss threshold or the storage quantity is less than a preset reserve threshold.
[0076] If not, execute S306; if so, execute S307.
[0077] The preset loss threshold and the preset reserve threshold can be set according to actual needs. Since the playback time of each audio stream is about 20ms, the loss of a few audio streams is difficult for humans to detect, so a certain preset loss threshold can be set, such as 3. The preset reserve threshold can be set to 0 or 1-5.
[0078] When audio stream loss occurs on the primary server, the severity of the audio loss is determined based on a preset loss threshold, thereby determining whether to replace the primary and backup attributes of the server.
[0079] In addition, the preset reserve threshold can be used as a benchmark to determine whether to change the primary and backup attributes of the server. If the storage quantity of the audio stream to be played on the primary server is less than the preset reserve threshold, it means that the audio stream may be about to be interrupted. Therefore, the primary and backup attributes can be replaced in time to obtain more audio streams and avoid audio stream interruptions, thereby optimizing the continuity of audio during packet loss and audio switching.
[0080] S306: Maintain the current master / slave attributes of the two servers.
[0081] S307: Exchange the master and backup attributes of the two servers.
[0082] S308 is executed after S307.
[0083] S308: When the primary and backup attributes are swapped, obtain the packet sequence number set of all audio streams in the replaced primary server.
[0084] Before the replacement, server A is the primary server and server B is the backup server. When the primary and backup attributes are swapped, server B is the primary server and server A is the backup server. To obtain the packet sequence number set of all audio streams in the replaced primary server, you need to obtain the packet sequence number set of all audio streams in server B.
[0085] S309: Determine the packet number of the next audio stream to be played based on the size relationship between the packet number in the packet number set and the current first packet number.
[0086] Based on the relationship between the packet numbers in the packet number set and the current first packet number, the packet number of the audio stream that is close to the first packet number and conforms to the playback order can be determined in the packet number set, and then the audio stream can be sent to the output device for playback, which is conducive to achieving audio switching synchronization.
[0087] Specifically, the packet sequence number of the next audio stream to be played is determined based on the packet sequence number set and the current first packet sequence number, including: determining the minimum packet sequence number and the maximum packet sequence number in the packet sequence number set; judging whether there is a first packet sequence number greater than the minimum packet sequence number and less than the maximum packet sequence number; if so, taking the packet sequence number obtained by increasing the first packet sequence number by 1 as the packet sequence number of the next audio stream to be played; if not, when the first packet sequence number is less than the minimum packet sequence number, taking the minimum packet sequence number as the packet sequence number of the next audio stream to be played; when the first packet sequence number is greater than the maximum packet sequence number, taking the packet sequence number of the audio stream most recently received by the current main server as the packet sequence number of the next audio stream to be played. Among them, if there is a newly received audio stream corresponding to a non-maximum packet sequence number, the packet sequence number of the most recently received audio stream is taken as the packet sequence number of the next audio stream to be played; if there is no newly received audio stream corresponding to a non-maximum packet sequence number, the most recently received audio stream is the audio stream corresponding to the maximum packet sequence number.
[0088] In an optional embodiment, an audio buffer is provided in the output device, and the audio buffer is used to store audio streams sent by two servers. The audio stream synchronous distribution method also includes: when the output device plays the audio stream, updating the first packet sequence number corresponding to the currently played audio stream; after the audio stream is played, deleting the earliest received audio stream in the main audio buffer of the output device.
[0089] In order to clearly describe the operation process of audio stream in output device, Figure 4 The following example illustrates the following steps:
[0090] S401, the output device receives the audio stream sent by the server;
[0091] S402, determining whether the audio identifier of the audio stream is consistent with the audio identifier of the task output instruction;
[0092] The task output instruction may be an instruction sent by a server or a main control center to an output device.
[0093] S403: If they are inconsistent, discard the audio stream;
[0094] S404, if they are consistent, the audio stream is written into the audio buffer area, the output device plays the audio stream sent by the main server, and the packet sequence number of the currently played audio stream is updated;
[0095] S405: After the audio output is completed, the oldest audio packet in the audio buffer is discarded.
[0096] In this embodiment, when there is audio stream loss, the number of audio stream losses and the number of audio streams to be played on the main server are obtained to determine whether the number of losses is greater than a preset loss threshold or the number of storages is less than a preset reserve threshold; if so, the master-slave attributes of the two servers are swapped; if not, the current master-slave attributes of the two servers are maintained. The master-slave attributes can be replaced in time to obtain more audio streams and avoid audio stream interruptions. In addition, when the master-slave attributes are swapped, the packet sequence number set of all audio streams in the replaced main server is obtained, and the packet sequence number of the next audio stream to be played is determined based on the relationship between the packet sequence number in the packet sequence number set and the current first packet sequence number. The packet sequence number of the audio stream that is close to the first packet sequence number and conforms to the playback order can be determined in the packet sequence number set, which is conducive to achieving audio switching synchronization and improving the speed of audio stream switching and the fluency of the listening experience of the master and backup servers.
[0097] Embodiment 3
[0098] Embodiment 3 of the present invention provides an audio stream synchronous distribution system, which includes two servers that serve as a primary and a backup for each other, an output device and a main control center. The server sends the audio stream to the output device in the order of the packet sequence numbers of the audio stream.
[0099] Figure 5 A structural diagram of the main control center provided in the third embodiment of the present invention is shown as follows: Figure 5 As shown, the main control center includes:
[0100] The first information acquisition module 501 is used to acquire the play time of the first packet sequence number of the currently played audio stream when two servers execute an audio task, if the audio stream of the audio task comes from the local server;
[0101] A second information acquisition module 502 is used to determine the second packet sequence number closest to the play time in the play record of the standby server;
[0102] A calling progress calibration module 503, used for adjusting the calling progress of the audio stream of the standby server according to the relationship between the first packet sequence number and the second packet sequence number, so that the audio streams of the two servers are sent synchronously;
[0103] The primary and backup attribute determination module 504 is used to determine the primary and backup attributes of the two servers according to the number of lost audio streams and the number of audio streams to be played stored on the primary server when there is audio stream loss;
[0104] The packet sequence number determination module 505 is used to determine the packet sequence number of the next audio stream to be played according to the current first packet sequence number when the primary and backup attributes are swapped.
[0105] In an optional embodiment, the calling progress calibration module 503 includes:
[0106] A first calibration submodule, configured to control the calling progress of the audio stream of the standby server to slow down if the first packet sequence number is smaller than the second packet sequence number;
[0107] The second calibration submodule is used to control the calling progress of the audio stream of the standby server to speed up if the first packet sequence number is greater than the second packet sequence number.
[0108] In an optional embodiment, the primary and backup attribute determination module 504 includes:
[0109] A criterion acquisition submodule, used for acquiring the number of lost audio streams and the number of stored audio streams to be played by the main server when there is audio stream loss;
[0110] A judgment submodule, used to judge whether the loss quantity is greater than a preset loss threshold or the storage quantity is less than a preset reserve threshold; if so, execute the content of the attribute exchange submodule, if not, execute the content of the attribute retention submodule;
[0111] The attribute exchange submodule is used to exchange the primary and backup attributes of two servers;
[0112] The attribute preservation submodule is used to maintain the current master and backup attributes of the two servers.
[0113] In an optional embodiment, when the primary and backup attributes are swapped, the packet sequence number determination module 505 includes:
[0114] The packet sequence number set acquisition submodule is used to acquire the packet sequence number set of all audio streams in the replaced primary server when the primary and backup attributes are swapped;
[0115] The packet sequence number determination submodule is used to determine the packet sequence number of the next audio stream to be played based on the sequence number size relationship between the packet sequence numbers in the packet sequence number set and the current first packet sequence number.
[0116] In an optional embodiment, the packet sequence number determination submodule includes:
[0117] A criterion determination unit, used to determine the minimum packet sequence number and the maximum packet sequence number in the packet sequence number set;
[0118] A judging unit, configured to judge whether the first packet sequence number is greater than the minimum packet sequence number and less than the maximum packet sequence number; if so, execute the content of the first packet sequence number determining unit; if not, execute the content of the second packet sequence number determining unit;
[0119] A first packet sequence number determining unit, configured to increase the first packet sequence number by 1 to obtain a packet sequence number as a packet sequence number of a next played audio stream;
[0120] The second packet number determination unit is used to use the minimum packet number as the packet number of the next audio stream to be played when the first packet number is less than the minimum packet number; and when the first packet number is greater than the maximum packet number, use the packet number of the audio stream most recently received by the current main server as the packet number of the next audio stream to be played.
[0121] In an optional embodiment, the audio stream synchronization distribution system further includes an input device, and the audio stream synchronization distribution system further includes:
[0122] A task input instruction sending module, used for sending a task input instruction to the input device when two servers execute an audio task, if the audio stream of the audio task comes from an input device, so that the input device sends the audio stream;
[0123] A judgment module, used for judging whether the audio identifier of the audio stream sent by the input device is the same as the audio identifier in the task input instruction; if so, executing the content of the cache module, if not, executing the content of the deletion module;
[0124] A cache module, used for storing the audio stream sent by the input device in a buffer of the server;
[0125] The deleting module is used to delete the audio stream sent by the input device.
[0126] In an optional embodiment, the output device is provided with an audio buffer area, the audio buffer area is used to store the audio streams sent by the two servers, and the audio stream synchronization distribution system further includes:
[0127] A first packet sequence number updating module, used for updating the first packet sequence number corresponding to the currently played audio stream when the output device plays the audio stream;
[0128] The audio stream deletion module is used to delete the earliest received audio stream in the main audio buffer area of the output device after the audio stream is played.
[0129] The audio stream synchronization distribution system provided by the embodiment of the present invention can execute the audio stream synchronization distribution method provided by any embodiment of the present invention, and has the corresponding functional modules and beneficial effects of the execution method.
[0130] Embodiment 4
[0131] Figure 6 A schematic diagram of the structure of an electronic device 40 that can be used to implement an embodiment of the present invention is shown. The electronic device is intended to represent various forms of digital computers, such as laptop computers, desktop computers, workstations, personal digital assistants, servers, blade servers, mainframe computers, and other suitable computers. The electronic device can also represent various forms of mobile devices, such as personal digital processing, cellular phones, smart phones, wearable devices (such as helmets, glasses, watches, etc.) and other similar computing devices. The components shown herein, their connections and relationships, and their functions are merely examples and are not intended to limit the implementation of the present invention described and / or required herein.
[0132] like Figure 6 As shown, the electronic device 40 includes at least one processor 41, and a memory connected to the at least one processor 41, such as a read-only memory (ROM) 42, a random access memory (RAM) 43, etc., wherein the memory stores a computer program that can be executed by at least one processor, and the processor 41 can perform various appropriate actions and processes according to the computer program stored in the read-only memory (ROM) 42 or the computer program loaded from the storage unit 48 to the random access memory (RAM) 43. In the RAM 43, various programs and data required for the operation of the electronic device 40 can also be stored. The processor 41, the ROM 42, and the RAM 43 are connected to each other through a bus 44. An input / output (I / O) interface 45 is also connected to the bus 44.
[0133] A number of components in the electronic device 40 are connected to the I / O interface 45, including: an input unit 46, such as a keyboard, a mouse, etc.; an output unit 47, such as various types of displays, speakers, etc.; a storage unit 48, such as a disk, an optical disk, etc.; and a communication unit 49, such as a network card, a modem, a wireless communication transceiver, etc. The communication unit 49 allows the electronic device 40 to exchange information / data with other devices through a computer network such as the Internet and / or various telecommunication networks.
[0134] The processor 41 may be a variety of general and / or dedicated processing components with processing and computing capabilities. Some examples of the processor 41 include, but are not limited to, a central processing unit (CPU), a graphics processing unit (GPU), various dedicated artificial intelligence (AI) computing chips, various processors running machine learning model algorithms, a digital signal processor (DSP), and any appropriate processor, controller, microcontroller, etc. The processor 41 performs the various methods and processes described above, such as an audio stream synchronization distribution method.
[0135] In some embodiments, the audio stream synchronization distribution method can be implemented as a computer program, which is tangibly contained in a computer-readable storage medium, such as a storage unit 48. In some embodiments, part or all of the computer program can be loaded and / or installed on the electronic device 40 via the ROM 42 and / or the communication unit 49. When the computer program is loaded into the RAM 43 and executed by the processor 41, one or more steps of the audio stream synchronization distribution method described above can be performed. Alternatively, in other embodiments, the processor 41 can be configured to perform the audio stream synchronization distribution method in any other appropriate manner (for example, by means of firmware).
[0136] Various implementations of the systems and techniques described above herein can be implemented in digital electronic circuit systems, integrated circuit systems, field programmable gate arrays (FPGAs), application specific integrated circuits (ASICs), application specific standard products (ASSPs), systems on chips (SOCs), complex programmable logic devices (CPLDs), computer hardware, firmware, software, and / or combinations thereof. These various implementations can include: being implemented in one or more computer programs that can be executed and / or interpreted on a programmable system including at least one programmable processor, which can be a special purpose or general purpose programmable processor that can receive data and instructions from a storage system, at least one input device, and at least one output device, and transmit data and instructions to the storage system, the at least one input device, and the at least one output device.
[0137] Computer programs for implementing the methods of the present invention may be written in any combination of one or more programming languages. These computer programs may be provided to a processor of a general-purpose computer, a special-purpose computer, or other programmable data processing device, so that when the computer program is executed by the processor, the functions / operations specified in the flow chart and / or block diagram are implemented. The computer program may be executed entirely on the machine, partially on the machine, partially on the machine and partially on a remote machine as a stand-alone software package, or entirely on a remote machine or server.
[0138] In the context of the present invention, a computer-readable storage medium may be a tangible medium that may contain or store a computer program for use by or in combination with an instruction execution system, device or equipment. A computer-readable storage medium may include, but is not limited to, electronic, magnetic, optical, electromagnetic, infrared, or semiconductor systems, devices or equipment, or any suitable combination of the foregoing. Alternatively, a computer-readable storage medium may be a machine-readable signal medium. A more specific example of a machine-readable storage medium may include an electrical connection based on one or more lines, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.
[0139] To provide interaction with a user, the systems and techniques described herein may be implemented on an electronic device having: a display device (e.g., a CRT (cathode ray tube) or LCD (liquid crystal display) monitor) for displaying information to the user; and a keyboard and a pointing device (e.g., a mouse or trackball) through which the user can provide input to the electronic device. Other types of devices may also be used to provide interaction with the user; for example, the feedback provided to the user may be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user may be received in any form (including acoustic input, voice input, or tactile input).
[0140] The systems and techniques described herein may be implemented in a computing system that includes backend components (e.g., as a data server), or a computing system that includes middleware components (e.g., an application server), or a computing system that includes frontend components (e.g., a user computer with a graphical user interface or a web browser through which a user can interact with implementations of the systems and techniques described herein), or a computing system that includes any combination of such backend components, middleware components, or frontend components. The components of the system may be interconnected by any form or medium of digital data communication (e.g., a communication network). Examples of communication networks include: a local area network (LAN), a wide area network (WAN), a blockchain network, and the Internet.
[0141] A computing system may include a client and a server. The client and the server are generally remote from each other and usually interact through a communication network. The client and server relationship is generated by computer programs running on the corresponding computers and having a client-server relationship with each other. The server may be a cloud server, also known as a cloud computing server or cloud host, which is a host product in the cloud computing service system to solve the defects of difficult management and weak business scalability in traditional physical hosts and VPS services.
[0142] It should be understood that the various forms of processes shown above can be used to reorder, add or delete steps. For example, the steps described in the present invention can be executed in parallel, sequentially or in different orders, as long as the desired results of the technical solution of the present invention can be achieved, and this document does not limit this.
[0143] The above specific implementations do not constitute a limitation on the protection scope of the present invention. It should be understood by those skilled in the art that various modifications, combinations, sub-combinations and substitutions can be made according to design requirements and other factors. Any modification, equivalent substitution and improvement made within the spirit and principle of the present invention should be included in the protection scope of the present invention.
Claims
1. A method for synchronously distributing an audio stream, characterized in that: The invention is applied to an audio stream synchronous distribution system, wherein the audio stream synchronous distribution system comprises two servers and an output device which are mutually active and standby, and the server sends the audio stream to the output device in the order of the packet sequence number of the audio stream. The audio stream synchronous distribution method comprises: When two servers execute an audio task, if the audio stream of the audio task comes from the local server, the play time of the first packet sequence number of the currently played audio stream is obtained; Determine the second packet sequence number closest to the playback time in the playback record of the standby server; Adjusting the calling progress of the audio stream of the standby server according to the size relationship between the first packet sequence number and the second packet sequence number, so that the audio streams of the two servers are sent synchronously; When there is audio stream loss, the master / slave attributes of the two servers are determined according to the number of lost audio streams and the number of audio streams to be played stored on the primary server; When the primary and backup attributes are swapped, determining the packet sequence number of the next audio stream to be played according to the current first packet sequence number; When the primary and backup attributes are interchanged, determining the packet sequence number of the next played audio stream according to the current first packet sequence number includes: When the primary and backup attributes are swapped, obtain the packet sequence number set of all audio streams in the replaced primary server; The packet number of the next audio stream to be played is determined based on the relationship between the packet number in the packet number set and the current first packet number.
2. The method for synchronously distributing audio streams according to claim 1, wherein: The adjusting the calling progress of the audio stream of the standby server according to the sequence number size relationship between the first packet sequence number and the second packet sequence number includes: If the first packet sequence number is smaller than the second packet sequence number, the calling progress of the audio stream of the control standby server is slowed down; If the first packet sequence number is greater than the second packet sequence number, the calling progress of the audio stream of the control standby server is accelerated.
3. The method for synchronously distributing audio streams according to claim 1, wherein: When there is audio stream loss, determining the primary and backup attributes of the two servers according to the number of lost audio streams and the number of stored audio streams to be played by the primary server includes: When there is audio stream loss, the number of lost audio streams and the storage number of audio streams to be played by the main server are obtained; Determine whether the loss quantity is greater than a preset loss threshold or the storage quantity is less than a preset reserve threshold; If so, swap the master and backup attributes of the two servers; If not, keep the current active / standby attributes of the two servers.
4. The method for synchronously distributing audio streams according to claim 1, wherein: The determining the packet sequence number of the next played audio stream based on the sequence number size relationship between the packet sequence numbers in the packet sequence number set and the current first packet sequence number comprises: Determine a minimum packet sequence number and a maximum packet sequence number in the packet sequence number set; Determine whether the first packet sequence number is greater than the minimum packet sequence number and less than the maximum packet sequence number; If yes, the packet number obtained by increasing the first packet number by 1 is used as the packet number of the next audio stream to be played; If not, when the first packet number is less than the minimum packet number, the minimum packet number is used as the packet number of the next audio stream to be played; when the first packet number is greater than the maximum packet number, the packet number of the audio stream most recently received by the current main server is used as the packet number of the next audio stream to be played.
5. The method for synchronously distributing audio streams according to any one of claims 1 to 4, characterized in that: The audio stream synchronous distribution system further includes an input device, and when the two servers perform audio tasks, further includes: If the audio stream of the audio task comes from an input device, sending a task input instruction to the input device to enable the input device to send the audio stream; Determining whether the audio identifier of the audio stream sent by the input device is the same as the audio identifier in the task input instruction; If yes, storing the audio stream sent by the input device in a buffer of the server; If not, the audio stream sent by the input device is deleted.
6. The method for synchronously distributing audio streams according to any one of claims 1 to 4, characterized in that: The output device is provided with an audio buffer area, and the audio buffer area is used to store the audio streams sent by the two servers. The audio stream synchronous distribution method also includes: When the output device plays the audio stream, update the first packet sequence number corresponding to the currently played audio stream; After the audio stream is played, delete the earliest received audio stream in the primary audio buffer of the output device.
7. An audio stream synchronous distribution system, characterized in that: The audio stream synchronous distribution system includes two servers that are mutually active and standby, an output device and a main control center. The server sends the audio stream to the output device in the order of the packet sequence number of the audio stream. The main control center includes: The first information acquisition module is used to acquire the play time of the first packet sequence number of the currently played audio stream when the two servers execute the audio task, if the audio stream of the audio task comes from the local server; A second information acquisition module, used to determine a second packet sequence number closest to the play time in the play record of the standby server; A calling progress calibration module, used for adjusting the calling progress of the audio stream of the standby server according to the sequence number size relationship between the first packet sequence number and the second packet sequence number, so that the audio streams of the two servers are sent synchronously; A primary and backup attribute determination module, used to determine the primary and backup attributes of the two servers according to the number of lost audio streams and the number of audio streams to be played by the primary server when there is audio stream loss; A packet sequence number determination module, used for determining the packet sequence number of the next audio stream to be played according to the current first packet sequence number when the primary and backup attributes are interchanged; The packet sequence number determination module comprises: The packet sequence number set acquisition submodule is used to acquire the packet sequence number set of all audio streams in the replaced primary server when the primary and backup attributes are swapped; The packet sequence number determination submodule is used to determine the packet sequence number of the next audio stream to be played based on the sequence number size relationship between the packet sequence numbers in the packet sequence number set and the current first packet sequence number.
8. An electronic device, characterized in that: The electronic device comprises: at least one processor; and a memory communicatively connected to the at least one processor; wherein, The memory stores a computer program executable by the at least one processor, and the computer program is executed by the at least one processor to enable the at least one processor to perform the audio stream synchronous distribution method according to any one of claims 1 to 6.
9. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores computer instructions, and the computer instructions are used to enable a processor to implement the audio stream synchronous distribution method according to any one of claims 1 to 6 when executed.
