Data processing method, device, electronic device and computer readable storage medium
By setting the expected packet sequence number on the receiving end and comparing the packet sequence number of the packet, ensuring that the audio and video packets are processed in normal order, the problems of outdated order and packet loss caused by UDP protocol transmission are solved, and the transmission quality of the audio and video stream is improved.
Patent Information
- Application Number
- CN202010754834.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2020-07-30
- Publication Date
- 2025-01-03
- Estimated Expiration
- 2040-07-30
AI Technical Summary
During the audio and video data transmission, data transmission based on the UDP protocol causes problems of out-of-order and packet loss at the receiver, resulting in video stuttering or screen loss, and the existing technology has not effectively solved it.
By setting the expected packet sequence number on the receiving end, comparing the packet sequence number of the data packet with the expected packet sequence number, and performing preset processing when the same is true. Otherwise, deletion is made to ensure that the data packets are stored and processed in normal order, reducing the risk of out-of-order reception.
It realizes normal sequence forwarding and decoding of data packets, alleviates video lag or screen loss, and ensures the transmission quality of audio and video streams.
Smart Images

Figure CN112235234B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of data processing technology, and in particular to a data processing method, device, electronic device and computer-readable storage medium. Background Art
[0002] In the process of data transmission, most of the data is transmitted using a protocol based on TCP (Transmission Control Protocol). This is because the TCP protocol is a connection-oriented, reliable, byte stream-based transport layer communication protocol that can well ensure the reliability of data transmission.
[0003] However, in some fields, such as audio and video, the amount of data transmitted is often large and the network bandwidth is insufficient. If the TCP-based protocol is still used to transmit data, it will be stuck when the network is congested, or even unable to resume video playback. Therefore, in order to ensure the transmission quality of audio and video streams, there are also protocols based on UDP (User Datagram Protocol) in related technologies for transmission. This is mainly because the UDP protocol has a speed advantage that the TCP protocol cannot match.
[0004] However, due to the unreliable nature of UDP transmission, the data packets received by the receiving end are out of order and lost, which can also cause video freezes or screen distortion. The existing technology has not been able to effectively solve the problems of video freezes and screen distortion caused by transmitting data through the UDP protocol. Summary of the invention
[0005] In view of the above problems, embodiments of the present invention are proposed to provide a data processing method, device, electronic device and computer-readable storage medium that overcome the above problems or at least partially solve the above problems.
[0006] In order to solve the above problem, an embodiment of the present invention discloses a data processing method, which is applied to a receiving end. The method includes:
[0007] Receive multiple data packets sent by the sender according to the UDP protocol, and store them in a cache queue in the order in which the multiple data packets are received;
[0008] Obtaining a first data packet from the cache queue in a first-in-first-out order, and adding the first data packet to a sorting queue;
[0009] Determine a size relationship between a packet sequence number of the first data packet and a first expected packet sequence number, where the first expected packet sequence number is the packet sequence number of the data packet that the receiving end currently expects to receive;
[0010] When the packet sequence number of the first data packet is the same as the first expected packet sequence number, taking the first data packet out of the sorting queue and performing a preset process on the first data packet, wherein the preset process includes forwarding and / or decoding;
[0011] When the packet sequence number of the first data packet is smaller than the first expected packet sequence number, the first data packet is deleted from the sorting queue.
[0012] The embodiment of the present invention further discloses a data processing device, which is applied to a receiving end, and the device includes:
[0013] A storage module, used for receiving a plurality of data packets sent by a sending end according to the UDP protocol, and storing the data packets in a cache queue in the order in which the plurality of data packets are received;
[0014] A first adding module, used for obtaining a first data packet from the cache queue in a first-in-first-out order, and adding the first data packet to a sorting queue;
[0015] A first judgment module, used for judging the size relationship between the packet sequence number of the first data packet and a first expected packet sequence number, where the first expected packet sequence number is the packet sequence number of the data packet that the receiving end currently expects to receive;
[0016] a first processing module, configured to, when the packet sequence number of the first data packet is the same as the first expected packet sequence number, take the first data packet out of the sorting queue and perform a preset process on the first data packet, wherein the preset process includes forwarding and / or decoding;
[0017] The first deleting module is used to delete the first data packet from the sorting queue when the packet sequence number of the first data packet is smaller than the first expected packet sequence number.
[0018] The embodiment of the present invention further discloses an electronic device, including:
[0019] one or more processors; and
[0020] One or more computer-readable media having instructions stored thereon, when executed by the one or more processors, enable the processors to execute the data processing method as described in any one of the embodiments of the present invention.
[0021] The embodiment of the present invention further discloses a computer-readable storage medium, which stores a computer program that enables a processor to execute the data processing method described in the embodiment of the present invention.
[0022] The embodiments of the present invention include the following advantages:
[0023] In the data processing method provided by the embodiment of the present invention, by setting the first expected packet sequence number, the packet sequence number of the first data packet is compared with the first expected packet sequence number, and when the packet sequence number of the first data packet is the same as the first expected packet sequence number, the first data packet is taken out from the sorting queue for preset processing. In the present application, since the first data packet with the same first expected packet sequence number is taken out for preset processing each time, it can be ensured that the data packet taken out for preset processing each time is the data packet currently expected to be received by the receiving end, and since the expected packet sequence number is arranged as far as possible in the expected normal order (such as the order of the data packet sequence number), for example, it is arranged as far as possible in the normal order of 1, 2, 3, 4, 5, etc., therefore, the data packets are taken out from the sorting queue in sequence according to the expected normal order, so that each data packet taken out can also be arranged in the order of 1, 2, 3, 4, 5, so that the data packets arriving out of order are sorted and arranged. In this way, when each first data packet is preset, it is forwarded or decoded in the normal order, which realizes forwarding in the normal order of the data packet on the one hand, and reduces the risk of the other receiving end receiving the data packet out of order. On the other hand, decoding according to the normal order of the data packets can reduce the phenomenon of video freeze or screen distortion when decoding and playing the data packets. BRIEF DESCRIPTION OF THE DRAWINGS
[0024] Figure 1 is a schematic diagram of an implementation environment of an embodiment of the present application;
[0025] Figure 2 is a flow chart of a data processing method provided by an embodiment of the present application;
[0026] Figure 3 It is a flowchart of a data processing method proposed in one embodiment of the present application;
[0027] Figure 4 It is a flowchart of another data processing method proposed in one embodiment of the present application;
[0028] Figure 5 It is a flowchart of another data processing method proposed in one embodiment of the present application;
[0029] Figure 6 It is a structural block diagram of a data processing device provided in one embodiment of the present application. DETAILED DESCRIPTION
[0030] In order to make the above-mentioned objects, features and advantages of the present invention more obvious and easy to understand, the present invention is further described in detail below with reference to the accompanying drawings and specific embodiments.
[0031] Please refer to Figure 1 , Figure 1Schematic diagram of the implementation environment of an embodiment of the present application. Figure 1 As shown, the implementation environment includes: a sending end and a receiving end. The sending end and the receiving end perform data transmission according to the UDP protocol, wherein: Figure 1 The dotted line in represents the UDP communication link.
[0032] In this embodiment, the sending end and the receiving end can be the client and the server to each other. That is to say, there is a process in which the client sends a data packet to the server, and there is a process in which the server sends a data packet to the client. Therefore, in one embodiment, when the client sends a data packet to the server, the client is the sending end, the server is the receiving end, and the client sends the data packet to the server according to the UDP protocol; in another embodiment, when the server sends data to the client, the server is the sending end, the client is the receiving end, and the server sends the data packet to the client according to the UDP protocol.
[0033] Reference Figure 2 , Figure 2 It is a flowchart of a data processing method provided in one embodiment of the present application, and the data processing method can be applied to the receiving end.
[0034] like Figure 2 As shown, the method may specifically include the following steps:
[0035] Step S201, receiving multiple data packets sent by a sending end according to the UDP protocol, and storing the multiple data packets in a cache queue in the order in which they are received.
[0036] In this embodiment, before the sending end sends the data packet to the receiving end according to the UDP protocol, it first needs to obtain the data packet. Specifically, the sending end can obtain the data packet through various ways.
[0037] In one embodiment, when the sender is a client, it can be installed on a terminal device, and the terminal device can have an audio and video acquisition function. Therefore, the sender can call the audio and video acquisition function of the terminal device to collect audio and video data, and then use RTP (Real-time Transport Protocol) to package the collected audio and video data according to the set size.
[0038] During the packet encapsulation process at the sender, the packet number starts from 0, and the packet number increases by 1 each time a data packet is encapsulated.
[0039] In another embodiment, the transmitting end may also obtain data packets from other devices. For example, the data packets in the transmitting end may come directly from other transmitting ends or from other receiving ends, thereby obtaining data packets without the transmitting end collecting audio and video data.
[0040] When the sender sends a data packet, the sender can send the data packet during the packetization process, that is, encapsulate a data packet and then send a data packet, or send all the data packets at once after the packetization is completed. Regardless of the method of sending the data packet, the sender can also cache the sent data packets after sending each data packet, such as caching them in the memory of rtpPackets. In this way, the sender can resend the corresponding data packet if the receiving end has not received the data packet, thereby avoiding data packet loss, that is, avoiding packet loss.
[0041] While the sender sends multiple data packets corresponding to audio and video data according to the UDP protocol, the receiver can receive multiple data packets sent by the sender. After receiving the data packets, the receiver can store the multiple data packets in the cache queue packetQueue according to the time sequence of the data packets received.
[0042] Step S202: Obtain a first data packet from the cache queue in a first-in-first-out order, and add the first data packet to a sorting queue.
[0043] In this embodiment, a packet-taking thread packetProcessThread for processing data packets can be pre-set inside the receiving end. The packet-taking thread can cyclically obtain data packets from the cache queue. At this time, the data packet obtained by the packet-taking thread is called the first data packet. Specifically, when the packet-taking thread obtains the first data packet, it obtains it in the first-in-first-out order of the data packets in the cache queue. For example, the packet sequence numbers of the data packets received by the cache queue packetQueue are 2, 6, 8, 5, 4, 3, 9, 15, 11, 13, 16, 14, 11, respectively. Then, the order in which the packet-taking thread packetProcessThread obtains the first data packet from the cache queue is 2, 6, 8, 5, 4, 3, 9, 15, 11, 13, 16, 14, 11. In addition, a sorting queue is also pre-set inside the receiving end, which can also be called a sorting dictionary, for storing the first data packet obtained by the packet-taking thread packetProcessThread from the cache queue. Therefore, after the packet-taking thread packetProcessThread obtains the first data packet from the cache, the first data packet can be added to the sorting queue.
[0044] Step S203, determining the size relationship between the packet sequence number of the first data packet and the first expected packet sequence number.
[0045] The first expected packet sequence number is the packet sequence number of the data packet that the receiving end currently expects to receive.
[0046] In this embodiment, it is first necessary to know the value of the first expected packet sequence number. Specifically, the packet retrieval thread can first determine whether the first data packet is the first received data packet. If it is the first received data packet, the packet sequence number of the first data packet is used as the first expected packet sequence number, and then the first expected packet sequence number is used for subsequent operations; if it is not the first data packet, it means that the expected packet sequence number has been determined before, and at this time, the first expected packet sequence number can be directly obtained according to the corresponding rules.
[0047] Step S204, when the packet sequence number of the first data packet is the same as the first expected packet sequence number, taking the first data packet out of the sorting queue and performing preset processing on the first data packet, wherein the preset processing includes forwarding and / or decoding.
[0048] In this embodiment, if it is determined that the packet sequence number of the first data packet is the same as the first expected packet sequence number, it can be considered that the obtained first data packet has arrived accurately (no packet loss, no disorder). At this time, the packet retrieval thread can take the first data packet out of the sorting queue and perform preset processing.
[0049] Taking into account that the receiving end may have decoding and forwarding functions, the preset processing of the first data packet by the receiving end may include forwarding and / or decoding processing. The forwarding processing specifically includes forwarding the first data packet to another receiving end. For example, in the network architecture of client 1-server-client 2, the server acts as a transit and needs to forward the audio and video data packets to client 2 after receiving the audio and video data packets uploaded by client 1, so that client 2 can play according to the audio and video data packets; the decoding processing specifically includes directly decoding and playing the first data packet. For example, the above-mentioned server may also have a decoding function, so after receiving the first data packet, the server can directly decode and play the first data packet.
[0050] It should be noted that in the above-mentioned client 1-server-client 2 network architecture, since the UDP protocol is used to send data packets between client 1 and the server, the server will execute the steps of the data processing method of the embodiment of the present application after receiving the data packet sent by client 1. The UDP protocol can also be used to send data packets between the server and client 2. Therefore, the client 2 will also execute the steps of the data processing method of the embodiment of the present application after receiving the data packet sent by the server. In this way, the data packet that finally reaches client 2 can be as accurate as possible, that is, it is possible to avoid packet loss and disorder as much as possible.
[0051] Step S205: When the packet sequence number of the first data packet is smaller than the first expected packet sequence number, the first data packet is deleted from the sorting queue.
[0052] In this embodiment, if it is determined that the packet sequence number of the first data packet is less than the first expected packet sequence number, it can be considered that the obtained first data packet is outdated, and it is meaningless to perform preset processing on the outdated data packet. At this time, the packet retrieval thread can delete the first data packet from the sorting queue.
[0053] According to the method of this embodiment, by setting the first expected packet sequence number, the packet sequence number of the first data packet is compared with the first expected packet sequence number, and when the packet sequence number of the first data packet is the same as the first expected packet sequence number, the first data packet is taken out from the sorting queue for preset processing. In the present application, since the first data packet with the same first expected packet sequence number is taken out for preset processing each time, it can be ensured that the data packet taken out for preset processing each time is the data packet currently expected to be received by the receiving end, and since the expected packet sequence number is arranged as far as possible in the expected normal order (such as the order of the data packet sequence number), for example, it is arranged as far as possible in the normal order of 1, 2, 3, 4, 5, etc., therefore, the data packets are taken out from the sorting queue in sequence according to the expected normal order, so that each data packet taken out can also be arranged in the order of 1, 2, 3, 4, 5, so that the data packets arriving out of order are sorted and arranged. In this way, when each first data packet is subjected to preset processing, it is forwarded or decoded in the normal order, which realizes forwarding in the normal order of the data packet on the one hand, and reduces the risk of the other receiving end receiving the data packet out of order. On the other hand, decoding according to the normal order of the data packets can reduce the phenomenon of video freeze or screen distortion when decoding and playing the data packets.
[0054] In this embodiment, the receiving end can be set to two different data packet processing modes, including a first preset mode and a second preset mode. Different preset modes represent different ways of processing data packets, which are specifically reflected in the different ways of taking out data packets for processing. Among them, the first preset mode can also be called a fast mode, and the second preset mode can also be called a slow mode. When the user configures the receiving end configuration information, both modes can be configured at the receiving end, and then provided to the user for selection. Therefore, the user can select the first preset mode or the second preset mode as needed. Regardless of the first preset mode or the second preset mode, the data processing method described above (step S201 to step S205) is the same. The difference is that in the case where the packet sequence number of the first data packet is greater than the first expected packet sequence number, the subsequent data packet processing method is different.
[0055] In one implementation, if the user selects the first preset mode, the data processing method of this embodiment may further include the following steps:
[0056] Step S206A, when the currently executed data processing mode is the first preset mode and the packet sequence number of the first data packet is greater than the first expected packet sequence number, determine whether there is a first lost packet sequence number that is the same as the first expected packet sequence number in the retransmission queue.
[0057] In this embodiment, when the data processing mode selected by the user is the first preset mode, if it is determined that the packet sequence number of the first data packet is greater than the first expected packet sequence number, it can be considered that the acquired first data packet has arrived in advance. Although the preset processing cannot be performed at this time for the data packet that arrives in advance, when the expected packet sequence number increases later, there may be a data packet with the same expected packet sequence number, which can be taken out for preset processing at that time. Therefore, the packet retrieval thread can temporarily store the first data packet in the advanced packet queue, and take it out for preset processing when needed later, so as to avoid discarding the advanced packet or requesting retransmission, thereby saving network resources.
[0058] Step S207A: when the first lost packet sequence number exists in the retransmission queue, keep the first expected packet sequence number unchanged.
[0059] In this embodiment, the receiving end is provided with a retransmission queue, which is used to store the sequence numbers of the data packets that need to be retransmitted, and the sequence numbers of the data packets that need to be retransmitted in the retransmission queue are the lost packet sequence numbers. In addition, the receiving end is also provided with a retransmission thread, which is used to request the sending end to retransmit the data packet corresponding to the lost packet sequence number.
[0060] Since the packet sequence number of the first data packet is greater than the first expected packet sequence number, it means that the first data packet is not the packet sequence number of the data packet currently expected by the receiving end, that is, it is considered that the data packet corresponding to the first expected packet sequence number is lost. At this time, it is possible to query whether there is a first lost packet sequence number that is the same as the first expected packet sequence number in the retransmission queue. If there is a first lost packet sequence number in the retransmission queue, it can be considered that the data packet corresponding to the first expected packet sequence number is still waiting for retransmission. At this time, the first expected packet sequence number can be kept unchanged, and step S202 is returned again, that is, the next data packet in the sequence is obtained from the cache queue again, and the above steps are repeated in sequence. It should be noted that the expected packet sequence number has not changed at this time.
[0061] Step S208A, when the first lost packet sequence number does not exist in the retransmission queue, search the sorting queue for a first target data packet with the same sequence number as the first expected packet, and when the first target data packet exists in the sorting queue, take out the first target data packet from the sorting queue and perform the preset processing on the first target data packet.
[0062] In this embodiment, the data packets in the retransmission queue cannot be retransmitted infinitely, which will cause a surge in the number of data packets at the receiving end. Therefore, it is impossible for the first lost packet sequence number corresponding to the first expected packet sequence number to always exist in the retransmission queue. This embodiment corresponds to another situation when judging whether there is a first lost packet sequence number identical to the first expected packet sequence number in the retransmission queue, that is, the situation where the first lost packet sequence number does not exist in the retransmission queue, that is, the first lost packet sequence number in the retransmission queue is deleted from the retransmission queue after being requested to be retransmitted multiple times by the retransmission thread. In this case, it is possible to search in the sorting queue whether there is a first target data packet identical to the first expected packet sequence number. If the first target data packet is found in the sorting queue, the first target data packet can be directly taken out of the sorting queue and pre-set processing is performed on it.
[0063] It should be noted that if the data packet obtained from the cache queue is not the first one, then the sorting queue can store multiple previously obtained first data packets in addition to the first data packet currently obtained from the cache queue. Here, in the sorting queue, excluding the first data packet currently obtained from the cache queue, it is necessary to search for a first target data packet with the same sequence number as the first expected packet among the remaining first data packets.
[0064] It can be understood that if the first target data packet with the same sequence number as the first expected packet is lost even after multiple retransmission requests, the first target data packet does not exist in the sorting queue. In this case, the following steps can be performed: if the first target data packet does not exist in the sorting queue, take out the second data packet with the smallest packet sequence number from the sorting queue, perform the preset processing on the second data packet, and update the first expected packet sequence number to the packet sequence number of the second data packet.
[0065] In this embodiment, if the first target data packet does not exist in the sorting queue, at this time, the packet retrieval thread can take out the data packet with the smallest packet sequence number in the sorting queue, which is called the second data packet, and perform preset processing on the second data packet, and update the first expected packet sequence number to the packet sequence number of the second data packet, so that the updated first expected packet sequence number can be directly obtained.
[0066] When the first lost packet sequence number does not exist in the retransmission queue, it can be considered that the sender will no longer be requested to send the data packet corresponding to the first lost packet sequence number, and since the first target data packet does not exist in the sorting queue, in order to ensure lower communication delay, it can be considered that the first target data packet will never be received again. At this time, the first target data packet can be skipped, and the data packet with the smallest packet sequence number can be directly selected from the sorting queue for preset processing.
[0067] In one embodiment, after performing preset processing on each data packet, for example, performing preset processing on the first target data packet, or performing preset processing on the second data packet, and updating the first expected packet sequence number to the packet sequence number of the second data packet, in order to simplify the process of obtaining the data packet, in one embodiment, the data processing method of the present application may further include the following steps:
[0068] Step S209A, increasing the first expected packet sequence number according to a preset gain to obtain a second expected packet sequence number;
[0069] Step S210A, querying whether there is a third data packet with the same packet sequence number as the second expected packet sequence number in the leading packet queue, and the packet sequence number of the data packet in the leading packet queue is greater than the first expected packet sequence number;
[0070] Step S211A, when the third data packet exists in the advance packet queue, takes out the third data packet from the advance packet queue, performs the preset processing on the third data packet, and increases the second expected packet sequence number according to the preset gain to obtain the third expected packet sequence number.
[0071] In this embodiment, the preset gain refers to the amplitude of the increase of the first expected packet sequence number. If the first expected packet sequence number increases by 1 each time, the preset gain is 1. The size of the preset gain is the difference between the packet sequence numbers of two adjacent data packets when the audio and video data are packaged. For example, the packet sequence numbers of the two adjacent packets are 2 and 3 respectively, and the preset gain is 1 at this time. For another example, the packet sequence numbers of the two adjacent packets are 20 and 30 respectively, and the preset gain is 10 at this time.
[0072] If the current expected packet sequence number is 2 and the preset gain is 1, then the first expected packet sequence number is increased according to the preset gain, and the obtained second expected packet sequence number is 3.
[0073] After obtaining the second expected packet sequence number, you can first search in the advance packet queue whether there is a third data packet with the same packet sequence number as the second expected packet sequence number. If there is a third data packet in the advance packet queue, you can directly take the third data packet out of the advance packet queue and perform preset processing on the third data packet. Then, continue to increase the second expected packet sequence number according to the preset gain to obtain the third expected packet sequence number, and so on, until there is no data packet corresponding to any expected packet sequence number in the advance packet queue. If there is no data packet corresponding to any expected packet sequence number in the advance packet queue, it is necessary to return to execute the above step S202 again, that is, to obtain the next data packet in the sequence from the cache queue again, and repeat the above steps in sequence.
[0074] It should be noted that if the data packet is not obtained and the data packet is not processed in advance, the expected packet sequence number will not change.
[0075] In this embodiment, by setting an advance packet queue and after the expected packet sequence number changes, first searching the advance packet queue to see whether there is a data packet corresponding to the expected packet sequence number, it is possible to avoid discarding the advance data packet and simplify the steps of obtaining the data packet.
[0076] In one implementation, if the user selects the second preset mode, the data processing method of this embodiment may further include the following steps:
[0077] Step S206B, when the currently executed data processing mode is the second preset mode and the packet sequence number of the first data packet is greater than the first expected packet sequence number, determine whether there is a fourth data packet with the same first expected packet sequence number in the sorting queue.
[0078] Step S207B: when there is a fourth data packet with the same sequence number as the first expected packet in the sorting queue, take the fourth data packet out of the sorting queue and perform the preset processing on the fourth data packet.
[0079] In this embodiment, when the data processing mode selected by the user is the second preset mode, if it is determined that the packet sequence number of the first data packet is greater than the first expected packet sequence number, it is possible to directly query and determine whether there is a fourth data packet with the same first expected packet sequence number in the sorting queue; if there is a fourth data packet with the same first expected packet sequence number in the sorting queue, the fourth data packet is directly taken out of the sorting queue for preset processing.
[0080] It is understandable that if the receiving end does not receive the fourth data packet with the same sequence number as the first expected packet for a long time, the fourth data packet will not exist in the sorting queue. In this case, the following steps can be performed:
[0081] Step S208B: when there is no fourth data packet with the same sequence number as the first expected packet in the sorting queue, determine whether there is a second lost packet with the same sequence number as the first expected packet in the retransmission queue.
[0082] Step S209B: when the second lost packet sequence number exists in the retransmission queue, determine whether the number of data packets in the sorting queue is greater than a first preset number.
[0083] Step S210B: if not, keep the first expected packet sequence number unchanged.
[0084] Step S211B: If yes, then take out the fifth data packet with the smallest packet sequence number from the sorting queue, perform the preset processing on the fifth data packet, and update the first expected packet sequence number to the packet sequence number of the fifth data packet.
[0085] In this embodiment, if the fourth data packet does not exist in the sorting queue, it is then determined whether there is a second lost packet sequence number that is the same as the first expected packet sequence number in the retransmission queue. If the second lost packet sequence number exists in the retransmission queue, it indicates that the retransmission thread will also request to retransmit the data packet corresponding to the second lost packet sequence number, that is, the fourth data packet. At this time, it can be further determined whether the number of data packets in the sorting queue is greater than the first preset number, wherein the first preset number is determined by the designer according to needs. Generally, the larger the first preset number is, the longer the waiting time for receiving the fourth data packet is, and the greater the possibility of receiving the fourth data packet in the sorting queue is, which can ensure the communication quality, but relatively speaking, the communication delay is also relatively large.
[0086] If it is determined that the number of data packets in the sorting queue is greater than the first preset number, it can be considered that the waiting time is long enough but the fourth data packet has not been received. At this time, the packet retrieval thread can take out the data packet with the smallest packet number in the sorting queue, which is called the fifth data packet, and perform preset processing on the fifth data packet, and update the first expected packet number to the packet number of the fifth data packet, so that the updated first expected packet number can be directly obtained.
[0087] If it is determined that the number of data packets in the sorting queue is less than the first preset number, it can be considered that the waiting time is not enough, and you can continue to wait for receiving the fourth data packet. At this time, the packet retrieval thread can keep the first expected packet sequence number unchanged and return to execute the above step S202 again, that is, obtain the next data packet in the sequence from the cache queue again, and repeat the above steps in sequence.
[0088] Similarly, since the data packets in the retransmission queue cannot be retransmitted infinitely, which will cause a surge in the number of data packets at the receiving end, it is impossible for the second lost packet sequence number corresponding to the first expected packet sequence number to always exist in the retransmission queue. Therefore, in this case, after determining whether there is a second lost packet sequence number that is the same as the first expected packet sequence number in the retransmission queue, it may happen that there is no second lost packet sequence number in the retransmission queue. At this time, the following steps can be performed:
[0089] Step S212B, when the second lost packet sequence number does not exist in the retransmission queue, determine whether the number of data packets in the sorting queue is greater than a second preset number, and the second preset number is greater than the first preset number.
[0090] Step S213B, when the number of data packets in the sorting queue is less than a second preset number, keep the first expected packet sequence number unchanged.
[0091] Step S214B, when the number of data packets in the sorting queue is greater than the second preset number, take out the sixth data packet with the smallest packet sequence number from the sorting queue, perform the preset processing on the sixth data packet, and update the first expected packet sequence number to the packet sequence number of the sixth data packet.
[0092] In this embodiment, if there is no second lost packet sequence number in the retransmission queue, it can be further determined whether the number of data packets in the sorting queue is greater than the second preset number. Similarly, the second preset number is determined by the designer according to needs, and the second preset number is greater than the first preset number.
[0093] If it is determined that the number of data packets in the sorting queue is greater than the second preset number, it can be considered that the waiting time is long enough but the fourth data packet has not been received. At this time, the packet retrieval thread can take out the data packet with the smallest packet number in the sorting queue, which is called the sixth data packet, and perform preset processing on the sixth data packet, and update the first expected packet number to the packet number of the sixth data packet, so that the updated first expected packet number can be directly obtained.
[0094] If it is determined that the number of data packets in the sorting queue is less than the second preset number, it can be considered that the waiting time is not enough, and the waiting time for receiving the fourth data packet can continue. At this time, the packet retrieval thread can keep the first expected packet sequence number unchanged and return to execute the above step S202 again, that is, obtain the next data packet in the sequence from the cache queue again, and repeat the above steps in sequence.
[0095] In one embodiment, after performing preset processing on each data packet, for example, performing preset processing on the fourth data packet, or performing preset processing on the fifth data packet, and updating the first expected packet sequence number to the packet sequence number of the fifth data packet, or performing the preset processing on the sixth data packet, and updating the first expected packet sequence number to the packet sequence number of the sixth data packet, considering that there are multiple data packets in the sorting queue, the data packet can be directly obtained from the sorting queue. In one embodiment, the data processing method of the present application may further include the following steps:
[0096] Step S215B: increase the first expected packet sequence number according to the preset gain to obtain a fourth expected packet sequence number.
[0097] Step S216B, querying whether there is a seventh data packet with the same packet sequence number as the fourth expected packet sequence number in the sorting queue.
[0098] Step S217B, when the seventh data packet exists in the sorting queue, takes out the seventh data packet from the sorting queue, performs the preset processing on the seventh data packet, and increases the fourth expected packet sequence number according to the preset gain to obtain the fifth expected packet sequence number.
[0099] In this embodiment, the specific content of the preset gain can refer to the content of the above steps S209A to S211A, which will not be repeated here.
[0100] After obtaining the fourth expected packet sequence number, you can first search in the sorting queue whether there is a seventh data packet with the same packet sequence number as the fourth expected packet sequence number. If there is a seventh data packet in the sorting queue, you can directly take out the seventh data packet from the sorting queue and perform preset processing on the seventh data packet. Then, continue to increase the fourth expected packet sequence number according to the preset gain to obtain the fifth expected packet sequence number, and so on, until there is no data packet corresponding to any expected packet sequence number in the sorting queue. If there is no data packet corresponding to any expected packet sequence number in the sorting queue, it is necessary to return to execute the above step S202 again, that is, to obtain the next data packet in the sequence from the cache queue again, and repeat the above steps in sequence.
[0101] In this embodiment, by setting the first preset number and the second preset number, the packet retrieval thread will not immediately select the data packet with the smallest packet number in the sorting queue for preset processing when it is determined that there is no fourth data packet with the same packet number as the first expected packet in the sorting queue, but will wait for the sorting queue to continue to receive a certain number of data packets. In this way, the sorting queue can set a receiving waiting time to receive the fourth data packet with the same packet number as the first expected packet as much as possible, thereby reducing the probability of the fourth data packet being lost and ensuring the communication quality.
[0102] It should be noted that, in the present embodiment, the first target data packet, the first data packet, the second data packet, the third data packet, the fourth data packet, the fifth data packet and the sixth data packet all refer to a specific data packet. In some cases, one or more of these data packets may refer to the same data packet.
[0103] In one implementation, the data processing method of the present application may further include the following steps:
[0104] Step S21, determining the packet sequence number of a previous data packet obtained adjacent to the first data packet;
[0105] Step S22, when the difference between the packet sequence number of the first data packet and the packet sequence number of the previous data packet is greater than a preset difference, determining the packet sequence number between the packet sequence number of the first data packet and the packet sequence number of the previous data packet as the lost packet sequence number;
[0106] Step S23, adding the lost packet sequence number to the retransmission queue;
[0107] Step S24: Request the sending end to retransmit the data packet in the retransmission queue corresponding to the lost packet sequence number.
[0108] In this embodiment, the size of the preset difference is also the size of the difference in packet numbers between two adjacent data packets when the audio and video data packets are packaged. For example, the packet numbers of the two adjacent packets are 2 and 3 respectively, and the preset gain is 1 at this time. For another example, the packet numbers of the two adjacent packets are 20 and 30 respectively, and the preset gain is 10 at this time.
[0109] In addition, since the first data packet will be obtained in a first-in-first-out order, there may be two situations for the first data packet. One situation is that the first data packet is the first data packet obtained. In this case, there is no packet sequence number of an adjacent online data packet obtained before the first data packet. In this case, the packet sequence number of the adjacent prior data packet obtained before the first data packet can be set to 0 by default, and then the difference between the packet sequence number of the first data packet and the packet sequence number of the prior data packet can be determined; the other situation is that the first data packet is not the first data packet obtained. In this case, there is a packet sequence number of an adjacent online data packet obtained before the first data packet. In this case, the difference between the packet sequence number of the first data packet and the packet sequence number of the prior data packet can also be determined.
[0110] After determining the difference between the packet sequence number of the first data packet and the packet sequence number of the previous data packet, it can be determined whether the difference is greater than a preset difference. If the determined difference is greater than the preset difference, the packet sequence number between the packet sequence number of the first data packet and the packet sequence number of the previous data packet can be determined as the lost packet sequence number, and the lost packet sequence number can be added to the retransmission queue.
[0111] For example, assuming that the preset difference is 1, in one case, the first data packet is the first data packet obtained, and its packet sequence number is 4. The difference between it and 0 is calculated, and the difference is 4, which is greater than the preset difference 1. Therefore, the packet sequence numbers 1, 2, and 3 between 0 and 3 are determined as lost packet sequence numbers and added to the retransmission queue; in another case, the first data packet is not the first data packet obtained, and it is also assumed that its packet sequence number is 4. The data packet obtained before the first data packet is 2. The difference between 4 and 2 is calculated, and the difference is 2, which is also greater than the preset difference 1. Therefore, the packet sequence number 3 between 2 and 4 is determined as the lost packet sequence number and added to the retransmission queue.
[0112] In addition, the receiving end is also provided with a retransmission thread retryThread for processing retransmissions. The retransmission thread is responsible for taking out the lost packet sequence number from the retransmission queue and sending it to the sending end, that is, realizing the function of requesting the sending end to retransmit the data packet corresponding to the lost packet sequence number in the retransmission queue.
[0113] In addition, on the one hand, considering that there may be multiple situations for the lost packet sequence number in the retransmission queue, for example, some lost packet sequence numbers are smaller than the expected packet sequence number, and some lost packet sequence numbers are larger than the expected packet sequence number, it is meaningless to retransmit the lost packet sequence number that is smaller than the expected packet sequence number. On the other hand, considering that the data packets in the retransmission queue cannot be retransmitted infinitely, this will cause a surge in the number of data packets at the receiving end. Therefore, in order to avoid a surge in the number of data packets at the receiving end and also to save network transmission resources, in one implementation, after adding the lost packet sequence number to the retransmission queue, the data processing method of this embodiment may further perform the following steps:
[0114] Step S25, deleting the lost packet sequence numbers whose lost packet sequence numbers are smaller than the first expected packet sequence number from the retransmission queue to obtain the remaining multiple lost packet sequence numbers.
[0115] In this embodiment, the lost packet sequence numbers that are less than the first expected packet sequence number can be deleted from the retransmission queue to obtain the remaining multiple lost packet sequence numbers. In this way, the retransmission operations of the data packets corresponding to the lost packet sequence numbers that are less than the expected packet sequence number can be reduced, bandwidth can be saved, and at the same time, dirty data can be removed.
[0116] Step S26, determining the sequence number of the packet to be retransmitted from the remaining multiple lost packet sequence numbers; wherein the sequence number of the packet to be retransmitted is the sequence number of the lost packet whose number of retransmissions is less than the preset number, or the sequence number of the lost packet whose difference between the last retransmission time and the current time is greater than the preset time threshold, and the number of retransmissions is less than the preset number.
[0117] In this embodiment, multiple strategies for determining the sequence number of packets to be retransmitted are set, which can be selected according to needs. One strategy is to directly determine the sequence number of packets to be retransmitted based on the number of retransmissions, for example, directly determine the sequence number of lost packets with a number of retransmissions less than a preset number as the sequence number of packets to be retransmitted; the other strategy is to consider the retransmission time spent in each retransmission process based on the number of retransmissions, specifically, the sequence number of lost packets with a difference between the last retransmission time and the current time greater than a preset time threshold and a number of retransmissions less than a preset number. In this way, the time spent in the retransmission process of the data packet to be retransmitted can be taken into account, and the receiving end can be waited for to receive the retransmitted data packet at a normal retransmission time after each retransmission as much as possible, thereby reducing the retransmission frequency.
[0118] In this embodiment, a data structure LossPacket can be constructed for the lost packet sequence number in the retransmission queue, including the fields seq_num sequence number, retries retransmission number, and sent_at_time sending time. In this way, each lost packet sequence number, the number of retransmissions corresponding to each lost packet sequence number, and the time spent after each retransmission request for each lost packet sequence number can be recorded.
[0119] Correspondingly, the above step S24 specifically includes: requesting the sending end to retransmit the data packet in the retransmission queue corresponding to the sequence number of the packet to be retransmitted.
[0120] In this embodiment, a variety of strategies for determining the sequence numbers of packets to be retransmitted are set according to the sequence numbers of lost packets, and can be selected as needed, thereby improving the reliability of transmission through UDP and the flexibility of retransmission of lost packets.
[0121] In specific implementation, multiple test results show that the data processing method of this embodiment can ensure that the video is not stuck under 50% packet loss.
[0122] In summary, reference Figure 3 , Figure 3 FIG. 1 is a flow chart of a data processing method proposed in an embodiment of the present application. Figure 3 As shown, the process of a data processing method provided by an embodiment of the present invention is as follows:
[0123] (1) The packet retrieval thread obtains the first data packet from the cache queue, adds the first data packet to the sorting queue, and proceeds to step (2);
[0124] (2) The packet retrieval thread determines whether the first data packet is the first data packet obtained. If yes, it proceeds to step (3); if no, it proceeds to step (4);
[0125] (3) The packet fetching thread uses the packet sequence number of the first data packet as the first expected packet sequence number, fetches the first data packet from the sorting queue and performs a preset process, adds 1 to the first expected packet sequence number, and returns to step (1);
[0126] (4) The packet fetching thread determines the size relationship between the packet sequence number of the first data packet and the first expected packet sequence number. If the packet sequence number of the first data packet is equal to the first expected packet sequence number, the process proceeds to step (5). If the packet sequence number of the first data packet is greater than the first expected packet sequence number, the process proceeds to step (7). If the packet sequence number of the first data packet is less than the first expected packet sequence number, the process proceeds to step (9).
[0127] (5) The packet fetching thread fetches the first data packet from the sorting queue and performs a preset process, adds 1 to the first expected packet sequence number, obtains the second expected packet sequence number, and determines whether there is a third data packet with the same packet sequence number as the second expected packet sequence number in the leading packet queue. If so, proceed to step (6); if not, return to step (1);
[0128] (6) The packet fetching thread fetches the third data packet from the advanced packet queue and performs preset processing, takes the second expected packet sequence number as the first expected packet sequence number, repeats the process of adding 1 to the first expected packet sequence number, and determines whether there is a third data packet with the same packet sequence number as the second expected packet sequence number in the advanced packet queue. If so, proceed to step (6); if not, return to step (1);
[0129] (7) The packet fetching thread adds the first data packet to the advanced packet queue, and determines whether there is a first lost packet sequence number that is the same as the first expected packet sequence number in the retransmission queue. If so, the first expected packet sequence number is kept unchanged and the process returns to step (1). If not, the process determines whether there is a first target data packet that is the same as the first expected packet sequence number in the sorting queue. If so, the process proceeds to step (5). If not, the process proceeds to step (8).
[0130] (8) The packet fetching thread fetches the second data packet with the smallest packet sequence number from the sorting queue and performs preset processing, updates the first expected packet sequence number to the packet sequence number of the second data packet, adds 1 to the first expected packet sequence number, obtains the second expected packet sequence number, and determines whether there is a third data packet with the same packet sequence number as the second expected packet sequence number in the leading packet queue. If so, proceed to step (6); if not, return to step (1);
[0131] (9) Delete the first expected packet sequence number from the sorting queue and return to step (1).
[0132] refer to Figure 4 , Figure 4 FIG. 1 is a flow chart of another data processing method proposed in one embodiment of the present application. Figure 4 As shown, the process of a data processing method provided by an embodiment of the present invention is as follows:
[0133] (1) The packet retrieval thread obtains the first data packet from the cache queue, adds the first data packet to the sorting queue, and proceeds to step (2);
[0134] (2) The packet retrieval thread determines whether the first data packet is the first data packet obtained. If yes, it proceeds to step (3); if no, it proceeds to step (4);
[0135] (3) The packet fetching thread uses the packet sequence number of the first data packet as the first expected packet sequence number, fetches the first data packet from the sorting queue and performs a preset process, adds 1 to the first expected packet sequence number, and returns to step (1);
[0136] (4) The packet retrieval thread determines whether there is a fourth data packet with the same sequence number as the first expected packet in the sorting queue. If so, the process proceeds to step (5); if not, the process proceeds to step (7);
[0137] (5) taking out the fourth data packet from the sorting queue and performing a preset process, adding 1 to the first expected packet sequence number to obtain a fourth expected packet sequence number, and determining whether there is a seventh data packet having the same packet sequence number as the fourth expected packet sequence number in the sorting queue; if so, proceeding to step (6); if not, proceeding to step (1);
[0138] (6) The packet fetching thread fetches the seventh data packet from the sorting queue and performs a preset process, takes the fourth expected packet sequence number as the first expected packet sequence number, repeats the process of adding 1 to the first expected packet sequence number, and determines whether there is a seventh data packet with the same packet sequence number as the fourth expected packet sequence number in the sorting queue. If so, proceed to step (6); if not, return to step (1);
[0139] (7) The packet fetching thread determines whether there is a second lost packet sequence number that is the same as the first expected packet sequence number in the retransmission queue. If not, the process proceeds to step (10). If so, the process proceeds to step (9). If not, the process proceeds to step (8).
[0140] (8) Keep the first expected packet sequence number unchanged and return to step (1);
[0141] (9) The packet fetching thread fetches the fifth data packet with the smallest packet sequence number from the sorting queue, performs a preset process, updates the first expected packet sequence number to the packet sequence number of the fifth data packet, repeats the process of adding 1 to the first expected packet sequence number, and determines whether there is a seventh data packet with the same packet sequence number as the fourth expected packet sequence number in the sorting queue. If so, proceed to step (6); if not, return to step (1);
[0142] (10) The packet fetching thread determines whether the number of data packets in the sorting queue is greater than a second preset number. If so, it proceeds to step (12); if not, it proceeds to step (11);
[0143] (11) Keep the first expected packet sequence number unchanged and return to step (1);
[0144] (12) The packet retrieval thread retrieves the sixth data packet with the smallest packet sequence number from the sorting queue, performs preset processing, updates the first expected packet sequence number to the packet sequence number of the sixth data packet, repeats the process of adding 1 to the first expected packet sequence number, and determines whether there is a seventh data packet with the same packet sequence number as the fourth expected packet sequence number in the sorting queue. If so, proceed to step (6); if not, return to step (1).
[0145] refer to Figure 5 , Figure 5 FIG. 1 is a flow chart of another data processing method proposed in one embodiment of the present application. Figure 5 As shown, the process of a data processing method provided by an embodiment of the present invention is as follows:
[0146] The client collects audio and video data and packages the collected audio and video data into RTP packets. Then the client sends the packaged audio and video data to the server through the UDP protocol, and caches the sent audio and video data packets.
[0147] After receiving the audio and video data packets, the server uses the data processing method of the embodiment of the present application to sort and process the received audio and video data packets, and sends a retransmission request to the client, requesting the client to retransmit the lost data packets. The server then sorts the retransmitted audio and video data packets and the audio and video data packets directly received without retransmission.
[0148] It should be noted that, for the sake of simplicity, the method embodiments are described as a series of action combinations, but those skilled in the art should be aware that the embodiments of the present invention are not limited by the order of the actions described, because according to the embodiments of the present invention, certain steps can be performed in other orders or simultaneously. Secondly, those skilled in the art should also be aware that the embodiments described in the specification are all preferred embodiments, and the actions involved are not necessarily required by the embodiments of the present invention.
[0149] Based on the same technical concept, please refer to Figure 6 , Figure 6 A structural block diagram of a data processing device 600 provided in an embodiment of the present application is shown, which is applied to a receiving end, such as Figure 6 As shown, the device comprises:
[0150] The storage module 601 is used to receive multiple data packets sent by the sender according to the UDP protocol, and store them in a cache queue in the order in which the multiple data packets are received;
[0151] A first adding module 602, configured to obtain a first data packet from the cache queue in a first-in-first-out order, and add the first data packet to a sorting queue;
[0152] A first determination module 603 is used to determine the size relationship between the packet sequence number of the first data packet and a first expected packet sequence number, where the first expected packet sequence number is the packet sequence number of the data packet that the receiving end currently expects to receive;
[0153] A first processing module 604 is configured to, when the packet sequence number of the first data packet is the same as the first expected packet sequence number, take the first data packet out of the sorting queue and perform a preset process on the first data packet, wherein the preset process includes forwarding and / or decoding;
[0154] The first deleting module 605 is configured to delete the first data packet from the sorting queue when the packet sequence number of the first data packet is smaller than the first expected packet sequence number.
[0155] Optionally, the device further comprises:
[0156] A second judgment module is used to judge whether there is a first lost packet sequence number that is the same as the first expected packet sequence number in the retransmission queue when the currently executed data processing mode is the first preset mode and the packet sequence number of the first data packet is greater than the first expected packet sequence number;
[0157] A first maintaining module, configured to maintain the first expected packet sequence number unchanged when the first lost packet sequence number exists in the retransmission queue;
[0158] The second processing module is used to search from the sorting queue whether there is a first target data packet with the same sequence number as the first expected packet when the first lost packet sequence number does not exist in the retransmission queue, and to take out the first target data packet from the sorting queue and perform the preset processing on the first target data packet when the first target data packet exists in the sorting queue.
[0159] Optionally, the device further comprises:
[0160] a third processing module, configured to, when the first target data packet does not exist in the sorting queue, take out a second data packet with the smallest packet sequence number from the sorting queue, perform the preset processing on the second data packet, and update the first expected packet sequence number to the packet sequence number of the second data packet;
[0161] Optionally, the device further comprises:
[0162] A first adding module, configured to increase the first expected packet sequence number according to a preset gain to obtain a second expected packet sequence number;
[0163] A first query module, used for querying whether there is a third data packet with the same packet sequence number as the second expected packet sequence number in the advanced packet queue, and the packet sequence number of the data packet in the advanced packet queue is greater than the first expected packet sequence number;
[0164] The fourth processing module is used to take out the third data packet from the advance packet queue when the third data packet exists in the advance packet queue, perform the preset processing on the third data packet, and increase the second expected packet sequence number according to the preset gain to obtain a third expected packet sequence number.
[0165] Optionally, the device further comprises:
[0166] A third judgment module is used to judge whether there is a fourth data packet with the same sequence number as the first expected packet in the sorting queue when the currently executed data processing mode is the second preset mode and the sequence number of the first data packet is greater than the first expected packet sequence number;
[0167] The fifth processing module is used to take out the fourth data packet from the sorting queue and perform the preset processing on the fourth data packet when there is a fourth data packet with the same sequence number as the first expected packet in the sorting queue.
[0168] Optionally, the device further comprises:
[0169] A fourth judgment module, configured to judge whether there is a second lost packet sequence number that is the same as the first expected packet sequence number in the retransmission queue when there is no fourth data packet that is the same as the first expected packet sequence number in the sorting queue;
[0170] A fifth judgment module, configured to judge whether the number of data packets in the sorting queue is greater than a first preset number when it is judged that the second lost packet sequence number exists in the retransmission queue;
[0171] a second keeping module, configured to keep the first expected packet sequence number unchanged if no;
[0172] The sixth processing module is used for, if yes, taking out the fifth data packet with the smallest packet sequence number from the sorting queue, performing the preset processing on the fifth data packet, and updating the first expected packet sequence number to the packet sequence number of the fifth data packet.
[0173] Optionally, the device further comprises:
[0174] A sixth judgment module, configured to judge whether the number of data packets in the sorting queue is greater than a second preset number when the second lost packet sequence number does not exist in the retransmission queue, and the second preset number is greater than the first preset number;
[0175] A third maintaining module, configured to maintain the first expected packet sequence number unchanged when the number of data packets in the sorting queue is less than a second preset number;
[0176] The seventh processing module is used to take out the sixth data packet with the smallest packet sequence number from the sorting queue when the number of data packets in the sorting queue is greater than the second preset number, perform the preset processing on the sixth data packet, and update the first expected packet sequence number to the packet sequence number of the sixth data packet.
[0177] Optionally, the device further comprises:
[0178] A second adding module, configured to increase the first expected packet sequence number according to the preset gain to obtain a fourth expected packet sequence number;
[0179] A second query module, used for querying whether there is a seventh data packet having the same packet sequence number as the fourth expected packet sequence number in the sorting queue;
[0180] An eighth processing module is used to, when the seventh data packet exists in the sorting queue, take out the seventh data packet from the sorting queue, perform the preset processing on the seventh data packet, and increase the fourth expected packet sequence number according to the preset gain to obtain the fifth expected packet sequence number.
[0181] Optionally, the device further comprises:
[0182] A first determining module, used to determine a packet sequence number of a previous data packet acquired adjacent to the acquisition of the first data packet;
[0183] a second determining module, configured to determine, when a difference between the packet sequence number of the first data packet and the packet sequence number of the previous data packet is greater than a preset difference, a packet sequence number between the packet sequence number of the first data packet and the packet sequence number of the previous data packet as a lost packet sequence number;
[0184] A second adding module, used for adding the lost packet sequence number to the retransmission queue;
[0185] The retransmission module is used to request the sending end to retransmit the data packet corresponding to the lost packet sequence number in the retransmission queue.
[0186] Optionally, the device further comprises:
[0187] A second deleting module is used to delete the lost packet sequence number whose lost packet sequence number is less than the first expected packet sequence number from the retransmission queue to obtain the remaining multiple lost packet sequence numbers;
[0188] A third determination module is used to determine the sequence number of the packet to be retransmitted from the remaining multiple lost packet sequence numbers; wherein the sequence number of the packet to be retransmitted is the sequence number of the lost packet whose number of retransmissions is less than the preset number, or the sequence number of the lost packet whose difference between the last retransmission time and the current time is greater than the preset time threshold and the number of retransmissions is less than the preset number;
[0189] The retransmission module comprises:
[0190] The retransmission submodule is used to request the sending end to retransmit the data packet in the retransmission queue corresponding to the sequence number of the packet to be retransmitted.
[0191] An embodiment of the present invention further provides an electronic device, including:
[0192] one or more processors; and
[0193] One or more computer-readable storage media having instructions stored thereon, when executed by the one or more processors, enable the processors to execute the data processing method as described in any one of the embodiments of the present invention.
[0194] An embodiment of the present invention further provides a computer-readable storage medium, which stores a computer program that enables a processor to execute the data processing method described in the embodiment of the present invention.
[0195] As for the data processing device embodiment, since it is basically similar to the data processing method embodiment, the description is relatively simple, and the relevant parts can be referred to the partial description of the data processing method embodiment.
[0196] The various embodiments in this specification are described in a progressive manner, and each embodiment focuses on the differences from other embodiments. The same or similar parts between the various embodiments can be referenced to each other.
[0197] The data processing method, device, electronic device and computer-readable storage medium provided by the present invention are introduced in detail above. Specific examples are used in this article to illustrate the principles and implementation methods of the present invention. The description of the above embodiments is only used to help understand the method of the present invention and its core idea. At the same time, for those skilled in the art, according to the idea of the present invention, there will be changes in the specific implementation method and application scope. In summary, the content of this specification should not be understood as a limitation on the present invention.
Claims
1. A data processing method, characterized in that: Applied to the receiving end, the method comprises: Receive multiple data packets sent by the sender according to the UDP protocol, and store them in a cache queue in the order in which the multiple data packets are received; Obtaining a first data packet from the cache queue in a first-in-first-out order, and adding the first data packet to a sorting queue; Determine a size relationship between a packet sequence number of the first data packet and a first expected packet sequence number, where the first expected packet sequence number is the packet sequence number of the data packet that the receiving end currently expects to receive; When the packet sequence number of the first data packet is the same as the first expected packet sequence number, taking the first data packet out of the sorting queue and performing a preset process on the first data packet, wherein the preset process includes forwarding and / or decoding; When the packet sequence number of the first data packet is less than the first expected packet sequence number, deleting the first data packet from the sorting queue; The method further comprises: When the currently executed data processing mode is the second preset mode and the packet sequence number of the first data packet is greater than the first expected packet sequence number, determining whether there is a fourth data packet with the same sequence number as the first expected packet in the sorting queue; In the case that there is no fourth data packet with the same sequence number as the first expected packet in the sorting queue, determining whether there is a second lost packet with the same sequence number as the first expected packet in the retransmission queue; In the case of determining that the second lost packet sequence number exists in the retransmission queue, determining whether the number of data packets in the sorting queue is greater than a first preset number; If yes, taking out the fifth data packet with the smallest packet sequence number from the sorting queue, performing the preset processing on the fifth data packet, and updating the first expected packet sequence number to the packet sequence number of the fifth data packet; The method further comprises: When the currently executed data processing mode is the first preset mode and the packet sequence number of the first data packet is greater than the first expected packet sequence number, determining whether there is a first lost packet sequence number that is the same as the first expected packet sequence number in the retransmission queue; When the first lost packet sequence number exists in the retransmission queue, keeping the first expected packet sequence number unchanged; When the first lost packet sequence number does not exist in the retransmission queue, the sorting queue is searched to see whether there is a first target data packet with the same sequence number as the first expected packet. When the first target data packet exists in the sorting queue, the first target data packet is taken out from the sorting queue and the preset processing is performed on the first target data packet.
2. The method according to claim 1, characterized in that The method further comprises: When the first target data packet does not exist in the sorting queue, the second data packet with the smallest packet sequence number is taken out from the sorting queue, the second data packet is subjected to the preset processing, and the first expected packet sequence number is updated to the packet sequence number of the second data packet.
3. The method according to claim 2, characterized in that After performing the preset processing on the first target data packet, or performing the preset processing on the second data packet, and updating the first expected packet sequence number to the packet sequence number of the second data packet, the method further includes: Increase the first expected packet sequence number according to a preset gain to obtain a second expected packet sequence number; querying whether there is a third data packet with the same packet sequence number as the second expected packet sequence number in the advance packet queue, the packet sequence number of the data packet in the advance packet queue being greater than the first expected packet sequence number; In the case where the third data packet exists in the advance packet queue, the third data packet is taken out from the advance packet queue, the preset processing is performed on the third data packet, and the second expected packet sequence number is increased according to the preset gain to obtain a third expected packet sequence number.
4. The method according to claim 1, characterized in that: After determining whether there is a fourth data packet with the same sequence number as the first expected packet in the sorting queue, the method further includes: In the case that there is a fourth data packet having the same sequence number as the first expected packet in the sorting queue, the fourth data packet is taken out from the sorting queue, and the preset processing is performed on the fourth data packet.
5. The method according to claim 4, characterized in that In the case where it is determined that the second lost packet sequence number exists in the retransmission queue, after determining whether the number of data packets in the sorting queue is greater than a first preset number, the method further includes: If not, the first expected packet sequence number remains unchanged.
6. The method according to claim 5, characterized in that The method further comprises: In the case that the second lost packet sequence number does not exist in the retransmission queue, determining whether the number of data packets in the sorting queue is greater than a second preset number, and the second preset number is greater than the first preset number; When the number of data packets in the sorting queue is less than the second preset number, keeping the first expected packet sequence number unchanged; When the number of data packets in the sorting queue is greater than the second preset number, the sixth data packet with the smallest packet sequence number is taken out from the sorting queue, the preset processing is performed on the sixth data packet, and the first expected packet sequence number is updated to the packet sequence number of the sixth data packet.
7. The method according to claim 6, characterized in that After performing the preset processing on the fourth data packet, or performing the preset processing on the fifth data packet, and updating the first expected packet sequence number to the packet sequence number of the fifth data packet, or performing the preset processing on the sixth data packet, and updating the first expected packet sequence number to the packet sequence number of the sixth data packet, the method further includes: Increase the first expected packet sequence number according to a preset gain to obtain a fourth expected packet sequence number; Querying whether there is a seventh data packet having the same packet sequence number as the fourth expected packet sequence number in the sorting queue; In the case where the seventh data packet exists in the sorting queue, the seventh data packet is taken out from the sorting queue, the preset processing is performed on the seventh data packet, and the fourth expected packet sequence number is increased according to the preset gain to obtain the fifth expected packet sequence number.
8. The method according to claim 1 or 5, characterized in that: The method further comprises: Determining a packet sequence number of a previous data packet acquired adjacent to and before acquiring the first data packet; When the difference between the packet sequence number of the first data packet and the packet sequence number of the previous data packet is greater than a preset difference, determining the packet sequence number between the packet sequence number of the first data packet and the packet sequence number of the previous data packet as the lost packet sequence number; Adding the lost packet sequence number to the retransmission queue; Request the sending end to retransmit the data packet in the retransmission queue corresponding to the lost packet sequence number.
9. The method according to claim 8, characterized in that After adding the lost packet sequence number to the retransmission queue, the method further includes: Deleting the lost packet sequence numbers whose lost packet sequence numbers are smaller than the first expected packet sequence number from the retransmission queue to obtain the remaining multiple lost packet sequence numbers; Determine the sequence number of the packet to be retransmitted from the remaining multiple lost packet sequence numbers; wherein the sequence number of the packet to be retransmitted is the sequence number of the lost packet whose number of retransmissions is less than the preset number, or the sequence number of the lost packet whose difference between the last retransmission time and the current time is greater than the preset time threshold and the number of retransmissions is less than the preset number; The requesting the sending end to retransmit the data packet in the retransmission queue corresponding to the lost packet sequence number includes: Request the sending end to retransmit the data packet in the retransmission queue corresponding to the sequence number of the packet to be retransmitted.
10. A data processing device, characterized in that: Applied to a receiving end, the device comprises: A storage module, used for receiving a plurality of data packets sent by a sending end according to the UDP protocol, and storing the data packets in a cache queue in the order in which the plurality of data packets are received; A first adding module, used for obtaining a first data packet from the cache queue in a first-in-first-out order, and adding the first data packet to a sorting queue; A first judgment module, used for judging the size relationship between the packet sequence number of the first data packet and a first expected packet sequence number, where the first expected packet sequence number is the packet sequence number of the data packet that the receiving end currently expects to receive; a first processing module, configured to, when the packet sequence number of the first data packet is the same as the first expected packet sequence number, take the first data packet out of the sorting queue and perform a preset process on the first data packet, wherein the preset process includes forwarding and / or decoding; A first deleting module, configured to delete the first data packet from the sorting queue when the packet sequence number of the first data packet is less than the first expected packet sequence number; The device also includes: A third judgment module is used to judge whether there is a fourth data packet with the same sequence number as the first expected packet in the sorting queue when the currently executed data processing mode is the second preset mode and the sequence number of the first data packet is greater than the first expected packet sequence number; A fourth judgment module, configured to judge whether there is a second lost packet sequence number that is the same as the first expected packet sequence number in the retransmission queue when there is no fourth data packet that is the same as the first expected packet sequence number in the sorting queue; A fifth judgment module, configured to judge whether the number of data packets in the sorting queue is greater than a first preset number when it is judged that the second lost packet sequence number exists in the retransmission queue; a sixth processing module, configured to, if yes, take out a fifth data packet with the smallest packet sequence number from the sorting queue, perform the preset processing on the fifth data packet, and update the first expected packet sequence number to the packet sequence number of the fifth data packet; The device also includes: A second judgment module is used to judge whether there is a first lost packet sequence number that is the same as the first expected packet sequence number in the retransmission queue when the currently executed data processing mode is the first preset mode and the packet sequence number of the first data packet is greater than the first expected packet sequence number; A first maintaining module, configured to maintain the first expected packet sequence number unchanged when the first lost packet sequence number exists in the retransmission queue; The second processing module is used to search from the sorting queue whether there is a first target data packet with the same sequence number as the first expected packet when the first lost packet sequence number does not exist in the retransmission queue, and to take out the first target data packet from the sorting queue and perform the preset processing on the first target data packet when the first target data packet exists in the sorting queue.
11. An electronic device, characterized in that: include: one or more processors; and One or more computer-readable storage media having instructions stored thereon, when executed by the one or more processors, cause the processors to perform the steps of the data processing method according to any one of claims 1 to 9.
12. A computer-readable storage medium, characterized in that: The computer program stored therein enables the processor to execute the steps of the data processing method according to any one of claims 1 to 9.
Citation Information
Patent Citations
Packet transmission method and base station device
CN101123580A
Method and device for processing jitter buffer data
CN105743815A
Data transmission method, device, electronic equipment and storage medium
CN110430024A