The method of RTP-OVER-UDP packet loss and the treatment mechanism that reordersTechnical field
The invention belongs to decoding digital video technical fields, are related to a kind of quickly processing RTP-OVER-UDP packet loss and random orderingAlgorithm, can be used for Streaming Media customer side.
Background technique
In the receipts stream link of stream media technology, RTP-OVER-UDP mode is since it is with preferable network adaptability and biographyDefeated efficiency, is widely used in LAN environment.But due to the limitation of udp protocol itself, when use UDP transmits RTP dataThere is RTP packet packet loss and random ordering, if be not pocessed to the problem, in subsequent processes, decoding in Bao ShiDecoding error can occur in device and cause image-mosaics or frame losing.Therefore, corresponding algorithm must be increased in receipts stream linkSolve the problems, such as RTP packet loss and random ordering.
Currently, the algorithm for solving the problems, such as RTP-OVER-UDP packet loss and out-of-order mainstream is when receiving this RTP packet, first to enterTeam's caching.The RTP serial number that search was sent with the presence or absence of serial number last time in buffer queue again adds 1 RTP packet.If finding thisIt is then moved to transmission caching by the RTP packet of sample.Comparing classical way is realized according to following steps.
Using two bidirectional circulating queues, one is receiving queue, and for reordering, a several transmit queue is used for downPrevious module obtains the data after reordering.
The first step is first stored in receiving queue, compares since tail of the queue, is inserted in behind the member smaller than his serial number.
Second step, from receiving queue, since enemy, the packet of a upper serial number+1 of going out out one by one is gone outPacket be stored in output queue.
Third step does not just go out first, waits if in receiving queue, there are no the serial numbers for wanting to look for.
4th step will want the serial number+1 looked for, repeat third step if receiving queue length is more than the upper limit.
5th step is read out as long as there is packet in output queue, and the packet come out from output queue should be continuous.
As can be seen that existing algorithm complexity is higher, the processing time is longer, increases time delay when video playing.
Summary of the invention
It is an object of the invention in view of the above problems in the prior art, propose a kind of processing RTP-OVER-UDP packet loss andAlgorithm complexity can be effectively reduced in out-of-order algorithm, more existing algorithm, it is easier to be realized by program, enhance streaming media mistakeWhile network adaptability in journey, the processing time shortens, and reduces time delay when video playing.
Technical scheme is as follows:
A kind of method of RTP-OVER-UDP packet loss and the treatment mechanism that reorders, which comprises the following steps:
(1) RTP data are received by UDP;
(2) it parses RTP packet serial number Sequence Number field: defining a chained list and a buffer circle, respectivelyFor RTP packet loss, out-of-order processing and data to be sent are stored, i.e., wait demultiplex/decoding data, wherein each node of chained listData member include RTP data and RTP sequence number field, RTP serial number can be parsed to obtain by corresponding data in RTP, number to be decodedAccording to buffer area storage through out-of-order treated the data of packet loss, the data are by the input number as demultiplexer or Video DecoderAccording to;
(3) chained list node is written into RTP data;
(4) to Sequence Number value Overflow handling;During the value of Sequence Number is increasing, i.e., willWhen reaching 65535, and the RTP serial number received at this time is much smaller than 65535, then it is assumed that RTP sequence number value spilling has occurred, at this moment chainAfter the value of Sequence Number field in table is equal to adding 65535 from the Sequence Number parsed in RTPActual value as Sequence Number field in chained list;
(5) RTP ascending order arrange: by whole RTP nodes in chained list according to the Sequence Number field in node intoThe arrangement of row ascending order;
(6) it writes RTP and loads to buffer area to be sent: in chained list since head node, successively will remove RTP in nodeRTP load data behind packet header is written to buffer area to be sent;
(7) it demultiplexes or decodes.
RTP-OVER-UDP packet loss proposed by the present invention and out-of-order Processing Algorithm write program realization in VC2015.ExperimentShow that the algorithm implementation complexity is lower, it is easy to accomplish, it is 100% to packet loss and out-of-order handling rate, cooperates demultiplexing for rear endWith, decoding and playing module work, video playing is smooth, reaches requirement of real time, it was demonstrated that the program is feasible.
Detailed description of the invention
Fig. 1 is work flow diagram of the invention.
Specific embodiment
As shown in Figure 1, implementation process of the invention is as follows:
(1) RTP data are received by UDP.
(2) RTP packet serial number Sequence Number field is parsed:
A chained list and a buffer circle are defined, RTP packet loss, out-of-order processing are respectively used to and stores number to be sentAccording to that is, wait demultiplex/decoding data.Wherein, the data member of each node of chained list includes RTP data and RTP sequence number field(sequence number field is defined as 32 signless integers when realizing, indicates 65535) range of integer will be greater than, RTPSerial number can be parsed to obtain by corresponding data in RTP.Data buffer zone to be decoded storage is through out-of-order treated data, the number of packet lossAccording to the input data that will be used as demultiplexer or Video Decoder.
(3) chained list node is written into RTP data.
(4) Sequence Number value Overflow handling.
Since the Sequence Number in RTP is 16 signless integers, effective range 0-65535.In view of working asAfter preceding RTP packet Sequence Number value reaches 65535, when next RTP comes, as long as packet loss and random ordering do not occurSituation, the value can be reset as 0.Therefore, it is necessary to do value Overflow handling.The method of processing is the value as Sequence NumberDuring increasing, that is, when being up to 65535, and the RTP serial number received at this time much smaller than 65535 (such as the sequence receivedNumber for 2), then it is assumed that RTP sequence number value spilling has occurred.At this moment the value of the Sequence Number field in chained list is equal to from RTPThe middle actual value parsed after obtained Sequence Number adds 65535 as Sequence Number field in chained list.
(5) RTP ascending order arranges.
Whole RTP nodes in chained list are subjected to ascending order arrangement according to the Sequence Number field in node.
(6) it writes RTP and loads to buffer area to be sent.
In chained list since head node, successively by the RTP load data removed behind the packet header RTP in node be written toSend buffer area.It should be noted that the data temporary cache of several nodes reciprocal not take out in chained list.It does soPurpose be that might have out-of-order situation in the RTP packet of this part to occur.Caching is not handled temporarily, is connect in next UDP messageThe period is received, as long as packet loss does not occur, the out-of-order RTP packet for those of causing just to receive a little later can be received.
(7) it demultiplexes or decodes.