Summary of the invention
The processing method and the device that the purpose of this invention is to provide a kind of user datagram protocol message are to solve Network Packet Loss, the out of order problem that User Datagram Protoco (UDP) audio/video flow quality is impacted in the prior art.
For achieving the above object, the present invention proposes a kind of processing method of user datagram protocol message, comprising:
A, add the redundancy check piece in message to be sent, described redundancy check piece is stored the result of the redundant operation of the data division of a plurality of messages before the described message to be sent; Steps A specifically comprises:
In message to be sent, the data division of message is divided into n data blocks in equal, add the redundancy check piece according to the residue length available of pre-set length or message simultaneously, make the equal in length of described redundancy check piece and described data block, and store before the described message to be sent the result of the redundant operation of corresponding data piece in n the message; Described redundant operation comprises:
Utilize current message to reach the data block and the following matrix of redundancy check block structure of n message before:
Wherein, A
I, j, i=1,2, n+1, j=1,2, n+1 are j piece of i message, last piece of each message is the redundancy check piece, and if A
I, jBe sky, then A
I, j=0;
Utilization XOR algorithm obtains the result:
After B, receiving terminal judge that current message is lost,, recover to lose the data division of message according to carrying out the error correction computing with data division and/or the redundancy check piece of losing a plurality of messages that message is associated; Step B specifically comprises:
After judging that current message is lost, according to lose before the message n-1 and afterwards the redundancy check piece and the corresponding data piece of n message carry out the error correction computing, the data division of message is lost in recovery; Described error correction computing comprises:
Utilize described lose message and before n-1 and the data block and the following matrix of redundancy check block structure of n message afterwards:
Wherein, B
I, j, i=1,2,2n, j=1,2, n+1 are j piece of i message, last piece of each message is the redundancy check piece, and if B
I, jBe sky, then B
I, j=0;
Utilization XOR algorithm obtains the result:
……
Also comprise before the steps A:
According to the length restriction of MTU, obtain the residue length available of message by the length that detects message to be sent.
Also comprise in the steps A:
In message to be sent, add the verification identification code, be used to discern described redundancy check piece, and the original series of message is identified.
Whether the receiving terminal of user datagram protocol message described in the step B obtains the original series information of message according to described verification identification code, lose to judge current message.
Steps A specifically comprises:
In message to be sent, add m redundancy check piece according to the residue length available of pre-set length or message, respectively the data division of m message is before carried out redundancy backup; The equal in length of described redundancy check piece and described data division.
Step B specifically comprises:
After judging that current message is lost,, directly recover to lose the data division of message according to losing message i redundancy check piece of i message afterwards; Wherein, i=1,2, m.
The present invention also proposes a kind of method for packing of user datagram protocol message, comprising:
Encapsulate and send message add the redundancy check piece in message to be sent after, described redundancy check piece is stored the described message to be sent redundant operation result of the data division of a plurality of messages before;
Described method for packing specifically comprises:
In message to be sent, the data division of message is divided into n data blocks in equal, add the redundancy check piece according to the residue length available of pre-set length or message simultaneously, make the equal in length of described redundancy check piece and described data block, and store before the described message to be sent the result of the redundant operation of corresponding data piece in n the message; Described redundant operation comprises:
Utilize current message to reach the data block and the following matrix of redundancy check block structure of n message before:
Wherein, A
I, j, i=1,2, n+1, j=1,2, n+1 are j piece of i message, last piece of each message is the redundancy check piece, and if A
I, jBe sky, then A
I, j=0;
Utilization XOR algorithm obtains the result:
Also comprise before the described method for packing:
According to the length restriction of MTU, obtain the residue length available of message by the length that detects message to be sent.
Described method for packing also comprises:
In message to be sent, add the verification identification code, be used to discern described redundancy check piece, and the original series of message is identified.
Described method for packing specifically comprises:
In message to be sent, add m redundancy check piece according to the residue length available of pre-set length or message, respectively the data division of m message is before carried out redundancy backup; The equal in length of described redundancy check piece and described data division.
The present invention also proposes a kind of de-encapsulation method of user datagram protocol message, comprising:
After message sink judges that current message is lost,, recover to lose the data division of message according to carrying out the error correction computing with data division and/or the redundancy check piece of losing a plurality of messages that message is associated;
Described de-encapsulation method specifically comprises:
After judging that current message is lost, according to lose before the message n-1 and afterwards the redundancy check piece and the corresponding data piece of n message carry out the error correction computing, the data division of message is lost in recovery; Described error correction computing comprises:
Utilize described lose message and before n-1 and the data block and the following matrix of redundancy check block structure of n message afterwards:
Wherein, B
I, j, i=1,2,2n, j=1,2, n+1 are j piece of i message, last piece of each message is the redundancy check piece, and if B
I, jBe sky, then B
I, j=0;
Utilization XOR algorithm obtains the result:
……
The current message of described judgement is lost specifically and is comprised:
Whether message sink obtains the original series information of message according to the verification identification code in the message that receives, lose to judge current message.
Described de-encapsulation method specifically comprises:
After judging that current message is lost,, directly recover to lose the data division of message according to losing message i redundancy check piece of i message afterwards; Wherein i=1,2m, m are the number that in the message message data piece is before carried out the redundancy check piece of redundancy backup.
The present invention proposes a kind of dispensing device of user datagram protocol message, comprises the message sending module, also comprises the message package module;
Described message package module adds the redundancy check piece in message, and sends message by described message sending module to receiving terminal after encapsulation is finished; Described redundancy check piece carries out redundant operation by the data division at least one message before the described message to be sent and obtains;
Described message package module adds the redundancy check piece and specifically comprises:
The data division of message is divided into n data blocks in equal, adds the redundancy check piece according to the residue length available of pre-set length or message simultaneously, make the equal in length of described redundancy check piece and described data block; Corresponding data piece to n message before the described message to be sent carries out after the redundant operation result being stored in described redundancy check piece; Or
In message to be sent, add m redundancy check piece, the equal in length of described redundancy check piece and data division according to the residue length available of pre-set length or message; Data division to m message before the described message to be sent carries out respectively behind the redundancy backup result being stored in described redundancy check piece;
Described corresponding data piece to n message before the message to be sent carries out redundant operation and comprises:
Utilize described message to be sent to reach the data block and the following matrix of redundancy check block structure of n message before:
Wherein, A
I, j, i=1,2, n+1, j=1,2, n+1 are j piece of i message, last piece of each message is the redundancy check piece, and if A
I, jBe sky, then A
I, j=0;
Utilization XOR algorithm obtains the result:
Also comprise the message length detection module;
Described message length detection module detects described message length to be sent, and obtains the residue length available of described message according to the length restriction of testing result and MTU.
Described message package module further adds the verification identification code in message to be sent, be used to discern described redundancy check piece, and the original series of message is identified.
The present invention also proposes a kind of receiving system of user datagram protocol message, comprises the message receiver module, also comprises sequence of message detection module and packet parsing module;
Whether described sequence of message detection module is used for the message that described message receiver module receives is carried out Sequence Detection, lose to judge message;
Described packet parsing module according to carrying out the error correction computing with data division and/or the redundancy check piece of losing a plurality of messages that message is associated, recovers to lose the data division of message;
Described packet parsing module is carried out the error correction computing and is specifically comprised:
According to lose before the message n-1 and afterwards the redundancy check piece and the corresponding data piece of n message carry out the error correction computing, the data division of message is lost in recovery; Or
According to losing message i redundancy check piece of i message afterwards, directly recover to lose the data division of message; Wherein i=1,2m, m are the number that in the message message data piece is before carried out the redundancy check piece of redundancy backup;
Described basis lose before the message n-1 and afterwards the redundancy check piece of n message and corresponding data piece carry out the error correction computing and comprise:
Utilize described lose message and before n-1 and the data block and the following matrix of redundancy check block structure of n message afterwards:
Wherein, B
I, j, i=1,2,2n, j=1,2, n+1 are j piece of i message, last piece of each message is the redundancy check piece, and if B
I, jBe sky, then B
I, j=0;
Utilization XOR algorithm obtains the result:
……
Whether described sequence of message detection module obtains the original series information of message according to the verification identification code in the message, lose to judge message.
Compared with prior art, the present invention has the following advantages:
The present invention is under the situation that does not increase the Network Transmission message amount, by in each user datagram protocol message, adding a redundancy check piece, when packet loss, out of order and error code appear in Network Transmission, can recover the data of losing in the message by processing method of the present invention and device, improved the data transmission credibility of user datagram protocol message, thereby improved the audio frequency and video quality, remedied of the influence of Network Transmission problem User Datagram Protoco (UDP) audio frequency and video quality.
Embodiment
In conjunction with the accompanying drawings the present invention is further set forth with specific embodiment below.
The processing method of a kind of UDP message of the present invention as shown in Figure 2, may further comprise the steps:
S201, in message to be sent, add redundancy check piece and verification identification code; Wherein, the redundancy check piece stores before the message to be sent the result of the redundant operation of data division at least one message, and the verification identification code is used for receiving terminal and discerns described redundancy check piece, and the original series of message is identified;
After S202, receiving terminal receive message, judge according to the verification identification code in the message whether current message is lost, if then change step S203; May occur the packet loss of UDP message, out of order and error code in the Network Transmission, after receiving terminal receives message, obtain the original series information of message, when packet loss or error code occurring, can directly judge this message dropping according to verification identification code wherein; And occur can waiting for the regular hour when out of order, if still do not receive message then judge this message dropping;
S203, according to and data division and/or the redundancy check piece of losing at least one message that message is associated carry out the error correction computing, recover to lose the data division of message; Wherein, the algorithm of error correction computing should be decided on the redundant operation among the step S201, in the following specific embodiment specific descriptions will be arranged.
The processing method of UDP message of the present invention is applicable to the audio and video data streams that encapsulation format is comparatively fixing.In implementation process, can set in advance the length of redundancy check piece according to stable error correcting capability demand; Also can be along with the change of error correcting capability demand, and according to the residue length available of UDP message regulate add the length of redundancy check piece.Specifically describe with the processing method of three specific embodiments below above-mentioned UDP message.
First embodiment is with the UDP message of employing TS comparatively common in the prior art (Transport Stream, transport stream) the stream object as redundant correcting.Be implemented as follows:
(1), fix, data are carried out piecemeal, utilize the residue length available of message to add the redundancy check piece simultaneously according to the UDP message length of TS stream;
TS stream is made up of the TS bag of fixed size, and each TS packet length is 188 bytes.Because the maximum IP packet length that Ethernet allows is 1500 bytes, therefore be encapsulated in TS in each UDP message and be surrounded by and only have 7, total length is 1316 bytes, adds the IP head of 20 bytes and the UDP head of 8 bytes, therefore the total length of UDP message is 1344 bytes, and concrete form as shown in Figure 3.Simultaneously can learn that this message has the residue length available of 156 bytes.
According to the length of 156 bytes of residue, the bag of 7 TS in the message is divided into 10, wherein preceding 9 block lengths are 132 bytes, last piece is 128 bytes (1316=132 * 9+128); Simultaneously at the last interpolation length of each message verification identification code that is 4 bytes and the redundancy check piece of 132 bytes, this moment, the total length of this message was 1480 bytes, still 1500 byte MTU (the MaximumTransmission Unit that do not exceed the Ethernet acquiescence, MTU) restriction, the message format behind the interpolation redundancy check piece as shown in Figure 4.
Wherein, the verification identification code of 4 bytes can be used 0x4747xxxx form (the data block identification code of TS stream is 0x47), the xxxx of 16 systems is 0-65535 circulation summary counters of identification UDP sequence of message, to guarantee that receiving terminal does not need the sequence information of fields such as IP, UDP, the independent verification identification code that relies on, just can obtain the original series information of outgoing packet, thereby judge the current packet loss, out of order that whether takes place.
(2), structure redundant operation matrix carries out redundant operation, and the redundant operation result is stored in the redundancy check piece;
With 20 continuous UDP messages is example, and each packet has 11 pieces, and wherein preceding 10 is data block, and last piece is the redundancy check piece, the matrix A that is constructed as follows:
Wherein, A
I, jJ piece in i UDP message of (i=1,2,20, j=1,2,11) expression;
Utilize XOR to obtain the result of redundancy check piece in the 11st to 20 message again:
……
As from the foregoing, the partial data piece before the generation of each redundancy check piece all needs in 10 continuous messages, also, the data of each redundancy check piece all with 10 continuous messages before in partial data take place related.
(3), after receiving terminal judges that message is lost, carry out the error correction computing, the data division of message is lost in recovery according to special packet.
By as can be known aforementioned, receiving terminal can obtain the original series information of message according to the verification identification code in the message, further judges whether to take place packet loss, out of order.When Network Transmission packet loss appears, when out of order, receiving terminal if also do not receive packet, is then handled as message dropping after waiting for certain hour.Just need to carry out in accordance with the following methods the error correction computing this moment.
At first with lose before the message 9 and afterwards 10 continuous messages with lose matrix B of the common formation of message:
Wherein, B
I, jJ piece in i UDP message of (i=1,220, j=1,211) expression), the message of assumed lost is the 10th here.
The data division of then losing message can be obtained by following formula:
……
If there are not data in the above data block, promptly data block is empty, and then zero padding automatically in computing according to the principle of operation of step-by-step XOR, can not have influence on the result of computing.
Further can get by calculating, among above-mentioned first embodiment, if realize processing method of the present invention, can allow to lose a message in 20 then continuous messages, then packet loss is (1/20) * 100%=5%.Among the present invention, the TS enclosed mass number that encapsulates in the UDP message can not fixed, such as in above-mentioned first embodiment, each message has encapsulated 7 TS bags, and further improve error correcting capability if desired, then can reduce the number of the TS bag that encapsulates in each message, be used for increasing the length of redundancy check piece, thereby reduce the number of needed message when recovering.
With the UDP message that is packaged with 6 TS pieces is processing method second embodiment that example is described UDP message of the present invention.
At first,, message data is partly carried out piecemeal, add the redundancy check piece simultaneously according to the residue length available of UDP message;
UDP message data length is: 188 * 6=1128 (byte)
Message residue length available is: 1500-(188 * 6+28+4)=340 (bytes)
Length available according to residue 340 bytes can be divided into data division 4, and to add length simultaneously be the redundancy check piece of 1128/4=282 byte and the verification identification code of 4 bytes.UDP message format after interpolation redundancy check piece and the verification identification code as shown in Figure 5.
Construct encapsulant matrix and decapsulation matrix by step (2), (3) of similar above-mentioned first embodiment afterwards.Compare with first embodiment, data block in the UDP message becomes 4 by 10, can get by identical XOR algorithm, needed message number then became 7 by 19 when message was lost in recovery, be to allow to lose a bag in continuous 8 packets, the packet loss that allows is 12.5%, thereby has further improved error correcting capability.Because the algorithm of structural matrix is identical with first embodiment, so present embodiment is not given unnecessary details in this.
Except the UDP message of TS stream, the present invention is applicable to the carrying of the extended formatting data that have the specific clear area of UDP message too.Then with G.729 20ms voice RTP (Real-time Transport Protocol, RTP) packing, message size is 60 bytes to the UDP message all the time among the 3rd embodiment.Comprising speech payload 20 bytes, RTP 12 byte, UDP 8 byte and IP 20 bytes, much smaller than 1500 byte limit, there is a large amount of clear areas, can deposit the redundancy check piece, with the mutual redundancy between the message before and after realizing.
At this moment, do not need to carry out piecemeal, the XOR of above-mentioned two embodiment, directly repeat initial data and get final product.It is example that present embodiment carries out redundancy backup with each message to 2 messages before, and Fig. 6 is the UDP message format that carries out after the redundancy check, and as shown in the figure, each message has also attached two messages in front payload of totally 48 bytes except that 20 bytes of payload of self.
Below be the matrix that constitutes by 10 continuous messages:
Wherein, each row has been represented a UDP message, and digital N represents that this message stores N the payload in the message, for example in the 8th message, and except the payload of itself, the also redundant payload of the 7th and the 6th message.Therefore, this redundancy check method allows to lose two bags in per three continuous packets, i.e. the packet loss of network permission is 66.7%.Need to prove that the redundancy check piece of Tian Jiaing need take the byte of a large amount of length as stated above, so this kind redundancy check method only is applicable to the less and residue length available bigger UDP message of data division.
The method for packing of a kind of UDP message of the present invention as shown in Figure 7, may further comprise the steps:
S701, in message to be sent, add redundancy check piece and verification identification code; For the comparatively fixing UDP message of the demand of encapsulation format and error correcting capability, the length that can set in advance the redundancy check piece is added; And when in the different UDP message of different encapsulation format or error correcting capability demand, using method for packing of the present invention, then can be by the length of detection messages, MTU according to message limits the residue length available of obtaining message, further carries out the interpolation of redundancy check piece;
S702, data division at least one message before the message to be sent is carried out redundant operation, and the result is stored in the redundancy check piece.
Wherein, the specific algorithm of the mode of above-mentioned interpolation redundancy check piece and redundant operation can be looked the residue length available of message and difference.If the residue length of message is less, can carry out adding the redundancy check piece behind the piecemeal according to the residue length available of pre-set length or message data division to message, and make the length of redundancy check piece and the equal in length of data block, and redundant operation this moment can be adopted typical XOR algorithm; If there is a large amount of clear areas in the message, just do not need to carry out the piecemeal of data division, do not need to carry out XOR yet, only need directly before message data is partly repeated backup.
The de-encapsulation method of a kind of UDP message of the present invention as shown in Figure 8, may further comprise the steps:
S801, judge whether current message is lost; Wherein, receiving terminal can judge whether to take place packet loss or out of order by the sequence information of fields such as the IP in the message, UDP; And in being added with the UDP message of verification identification code, receiving terminal can independently rely on the verification identification code to obtain the original series of message, judges further whether current message is lost;
S802, according to and data division and/or the redundancy check piece of losing at least one message that message is associated carry out the error correction computing, recover to lose the data division of message; Wherein, the algorithm of concrete error correction computing should be decided on the packaged type of redundancy check piece in the UDP message, if the redundancy check piece that receives in the message is to obtain by piecemeal and XOR, then error correction recovers also should unite and loses message before with the redundancy check piece and the corresponding data piece of several messages carry out XOR afterwards; And if the redundancy check piece in the message is by directly duplicating of other message obtained, then the error correction redundancy check piece that also only need to recover to store after losing message the message of redundant information directly recovers.
The dispensing device of a kind of UDP message of the present invention as shown in Figure 9, comprises message length detection module 91, message package module 92 and message sending module 93.
Message length detection module 91 detects to sent message length, and obtains the residue length available of message according to testing result and MTU limited length.
Message package module 92 adds redundancy check piece and verification identification code according to the residue length available of message in message to be sent; And after the data division of at least one message carries out redundant operation before to message to be sent the result is stored in the redundancy check piece.In addition, message package module 92 can also add by the length that sets in advance the redundancy check piece.Concrete addition manner is decided by the residue length available, if the residue length of message is less, can carry out adding the redundancy check piece behind the piecemeal according to the residue length available of pre-set length or message data division to message, and make the length of redundancy check piece and the equal in length of data block, and redundant operation this moment can be adopted typical XOR algorithm; If there is a large amount of clear areas in the message, just do not need to carry out the piecemeal of data division, do not need to carry out XOR yet, only need directly before message data is partly repeated after the backup result to be stored in the redundancy check piece.
After 92 pairs of message encapsulation of message package module are finished, send to receiving terminal by message sending module 93.
The receiving system of a kind of UDP message of the present invention as shown in figure 10, comprising: message receiver module 101, sequence of message detection module 102 and packet parsing module 103.
After message receiver module 101 receives the UDP message, carry out Sequence Detection, whether lose to judge message by 102 pairs of messages that receive of sequence of message detection module.Concrete determination methods, sequence of message detection module 102 can be by IP, the UDP field in the message, and the sequence information that obtains message is to judge whether to take place packet loss or out of order; Also can independently differentiate the original series of message, and then judge whether current message is lost according to the verification identification code of adding in the message.
After sequence of message detection module 102 judged that current message is lost, packet parsing module 103 was according to carrying out the error correction computing with data division and/or the redundancy check piece of losing at least one message that message is associated, and the data division of message is lost in recovery.The algorithm of concrete error correction computing should be decided on the packaged type of redundancy check piece in the UDP message, if the redundancy check piece that receives in the message adds by piecemeal and XOR, then error correction recovers also should unite and loses message before with the redundancy check piece and the corresponding data piece of several messages carry out XOR afterwards; And if the redundancy check piece in the message is by directly duplicating of other message obtained, then the error correction redundancy check piece that also only need to recover to store after losing message the message of redundant information directly recovers.
More than disclosed only be several specific embodiment of the present invention, still, the present invention is not limited thereto, any those skilled in the art can think variation all should fall into protection scope of the present invention.