Summary of the invention
In order to solve the problems of the technologies described above, the invention provides a kind of method and device of displaying video stream, when ensureing as far as possible few buffered video frame, the played in order of frame of video can be ensured.
In order to reach the object of the invention, the invention provides a kind of method of displaying video stream, comprising:
Receiver, video frame, calculates the maximum in the network delay of the frame of video received, the frame of video received is put into frame of video buffer queue;
Timestamp according to frame of video reads time frame of video the earliest from frame of video buffer queue, for the frame of video read out calculates reproduction time, if current time is more than or equal to the reproduction time of the frame of video read out, then the frame of video read out is removed from frame of video buffer queue and carry out decoding and play; Wherein, described reproduction time=frame of video timestamp time+the described frame of video received network delay in maximum.
Further, the maximum in the network delay of the frame of video that described calculating has received, comprising:
According to MaxDelay=delay1+ MaxDelayDelta calculates the maximum in the network delay of the frame of video received, and wherein, MaxDelay is the maximum in the network delay of the frame of video received, and MaxDelayDelta is Max{delay1-delay1, delay2-delay1..., delayn-delay1, n>=1, delay1for the network delay of first frame of video received, delaynfor the network delay of the n-th frame of video received.
Further, the described frame of video for reading out calculates reproduction time, comprising:
According to rti=at1+ (tsi-ts1)+MaxDelayDelta calculates described reproduction time, wherein, 1≤i≤n, rtifor the reproduction time of i-th frame of video received, at1for receiving the time of first frame of video, tsifor the timestamp time of i-th frame of video received, ts1for the timestamp time of first frame of video received.
Further, according to delayi-delay1=(ati-at1)-(tsi-ts1) calculate described MaxDelayDelta, wherein, 1≤i≤n, delayifor the network delay of i-th frame of video received, atifor receiving the time of i-th frame of video, at1for receiving the time of first frame of video, tsifor the timestamp time of i-th frame of video received, ts1for the timestamp time of first frame of video received.
Further, described receiver, video frame, comprising:
If what receive is first frame of video, then record the timestamp time ts of first frame of video1with the time at receiving first frame of video1, and frame of video is put into frame of video buffer queue; If what receive is subsequent video frame, then according to delayi-delay1computing network time delay relative value, and recalculate the maximum MaxDelayDelta in the network delay relative value of all frame of video received, then frame of video is put into frame of video buffer queue.
Further, a kind of device of displaying video stream, comprising: receiving element, the first computing unit, broadcast unit and the second computing unit, wherein:
Described receiving element, for receiver, video frame, puts into frame of video buffer queue by the frame of video received;
Described first computing unit, for calculating the maximum in the network delay of the frame of video that described receiving element has received;
Described broadcast unit, for reading time frame of video the earliest according to the timestamp of frame of video from frame of video buffer queue, if current time is more than or equal to the reproduction time of the frame of video read out, then the frame of video read out is removed from frame of video buffer queue and carry out decoding and play;
Described second computing unit, calculates reproduction time for the frame of video that reads out for described broadcast unit, wherein, the timestamp of described reproduction time=frame of video time+the described frame of video received network delay in maximum.
Further, described first computing unit calculates the maximum in the network delay of the frame of video received, and comprising:
According to MaxDelay=delay1+ MaxDelayDelta calculates the maximum in the network delay of the frame of video received, and wherein, MaxDelay is the maximum in the network delay of the frame of video received, and MaxDelayDelta is Max{delay1-delay1, delay2-delay1..., delayn-delay1, n>=1, delay1for the network delay of first frame of video received, delaynfor the network delay of the n-th frame of video received.
Further, described second computing unit is that the frame of video that described broadcast unit reads out calculates reproduction time, comprising:
According to rti=at1+ (tsi-ts1)+MaxDelayDelta calculates described reproduction time, wherein, 1≤i≤n, rtifor the reproduction time of i-th frame of video received, at1for receiving the time of first frame of video, tsifor the timestamp time of i-th frame of video received, ts1for the timestamp time of first frame of video received.
Further, described first computing unit, also for according to delayi-delay1=(ati-at1)-(tsi-ts1) calculate described MaxDelayDelta, wherein, 1≤i≤n, delayifor the network delay of i-th frame of video received, atifor receiving the time of i-th frame of video, at1for receiving the time of first frame of video, tsifor the timestamp time of i-th frame of video received, ts1for the timestamp time of first frame of video received.
Further, described receiving element receiver, video frame, comprising:
If what receive is first frame of video, then record the timestamp time ts of first frame of video1with the time at receiving first frame of video1, and frame of video is put into frame of video buffer queue; If what receive is subsequent video frame, then indicate described first computing unit according to delayi-delay1computing network time delay relative value, and recalculate the maximum MaxDelayDelta in the network delay relative value of all frame of video received, then frame of video is put into frame of video buffer queue.
Compared with prior art, the present invention includes receiver, video frame, calculate the maximum in the network delay of the frame of video received, the frame of video received is put into frame of video buffer queue; Timestamp according to frame of video reads time frame of video the earliest from frame of video buffer queue, for the frame of video read out calculates reproduction time, if current time is more than or equal to the reproduction time of the frame of video read out, then the frame of video read out is removed from frame of video buffer queue and carry out decoding and play; Wherein, described reproduction time=frame of video timestamp time+the described frame of video received network delay in maximum.The present invention when ensureing the quantity of as far as possible few buffered video frame, can ensure again the played in order of frame of video simultaneously, both having ensured that presentation of video frames continuity in turn ensure that the instantaneity of presentation of video frames.
Other features and advantages of the present invention will be set forth in the following description, and, partly become apparent from specification, or understand by implementing the present invention.Object of the present invention and other advantages realize by structure specifically noted in specification, claims and accompanying drawing and obtain.
Embodiment
For making the object, technical solutions and advantages of the present invention clearly understand, hereinafter will be described in detail to embodiments of the invention by reference to the accompanying drawings.It should be noted that, when not conflicting, the embodiment in the application and the feature in embodiment can combination in any mutually.
Can perform in the computer system of such as one group of computer executable instructions in the step shown in the flow chart of accompanying drawing.Further, although show logical order in flow charts, in some cases, can be different from the step shown or described by order execution herein.
As shown in Figure 1, the method for displaying video stream of the present invention, comprising:
Step 101: receiver, video frame, calculates the maximum in the network delay of the frame of video received, the frame of video received is put into frame of video buffer queue;
The present invention calculates the maximum in the network delay of the frame of video received, and comprising: according to MaxDelay=delay1+ MaxDelayDelta calculates the maximum in the network delay of the frame of video received, and wherein, MaxDelay is the maximum in the network delay of the frame of video received, and MaxDelayDelta is Max{delay1-delay1, delay2-delay1..., delayn-delay1, n>=1, delay1for the network delay of first frame of video received, delaynfor the network delay of the n-th frame of video received.
Suppose that the timestamp time of first frame of video (frame of video 1) when gathering received is ts1, the timestamp time of frame of video 2 when gathering is ts2, the time that frame of video 1 arrives receiving terminal is at1(also namely receiving the time of first frame of video), the time that frame of video 2 arrives receiving terminal is at2.
The network delay delay of frame of video 11be: delay1=at1-ts1;
The network delay delay of frame of video 22be: delay2=at2-ts2;
By that analogy, the network delay of frame of video n is: delayn=atn-tsn.
The maximum calculated in the network delay of the frame of video received can, after the network delay calculating each frame of video received, adopt the method compared to obtain the maximum of network delay.
The present invention also can by calculating each network delay relative to delay1the maximum of difference, then adding delay1the network delay of frame of video that received of method in maximum.That is:
Max{delay1,delay2,...,delayn}=delay1+Max{delay1-delay1,delay2-delay1,...,delayn-delay1}。
Step 102: the timestamp according to frame of video reads time frame of video the earliest from frame of video buffer queue, for the frame of video read out calculates reproduction time; Wherein, reproduction time=frame of video timestamp time+network delay of frame of video that received in maximum;
Frame of video generally understands affix acquisition time when gathering, and acquisition time is called timestamp, and the time sequencing that each frame of video gathers and interval can be known by timestamp in one end of receiver, video stream.Receiving terminal can obtain the time of each frame of video in transmission over networks, i.e. network delay by the difference calculating time when receiving each frame of video and acquisition time.Due to the unsteadiness of network, the network delay of each frame of video is generally different.By calculating, the maximum in the network delay of each frame of video can be obtained, this maximum delay adds that the acquisition time of frame of video is necessarily greater than or equal to the time that frame of video arrives receiving terminal, using the timestamp time of each frame of video, receiving terminal adds that the maximum of network delay just can ensure before reproduction time reaches, necessarily have received the frame that will play as the reproduction time of frame of video, also just ensure that the continuity that frame is play.
The timestamp time of the frame of video that can just read in the present invention is directly added with the maximum in the network delay of the frame of video calculated the reproduction time obtaining the frame of video read.
When calculating the maximum in the network delay of frame of video received, if adopt Max{delay1, delay2..., delayn}=delay1+ Max{delay1-delay1, delay2-delay1..., delayn-delay1, also can according to rti=at1+ (tsi-ts1)+MaxDelayDelta calculates the reproduction time of frame of video read, wherein, 1≤i≤n, rtifor the reproduction time of i-th frame of video received, at1for receiving the time of first frame of video, tsifor the timestamp time of i-th frame of video received, ts1for the timestamp time of first frame of video received.
If Max{delay1-delay1, delay2-delay1..., delayn-delay1}=MaxDelayDelta, so the maximum MaxDelay of network delay is:
MaxDelay=delay1the reproduction time rt of+MaxDelayDelta, frame of video iibe then:
rti=tsi+delay1+MaxDelayDelta=tsi+(at1-ts1)+MaxDelayDelta
=at1+(tsi-ts1)+MaxDelayDelta。
Reproduction time can be calculated without the need to receiving terminal and collection terminal clock synchronous by the method.
Further, the present invention can according to delayi-delay1=(ati-at1)-(tsi-ts1) calculate MaxDelayDelta, wherein, 1≤i≤n, delayifor the network delay of i-th frame of video received, atifor receiving the time of i-th frame of video, at1for receiving the time of first frame of video, tsifor the timestamp time of i-th frame of video received, ts1for the timestamp time of first frame of video received.
The network delay of frame of video i (1≤i≤n) is relative to delay1difference be:
Delayi-delay1=(ati-tsi)-(at1-ts1)=(ati-at1)-(tsi-ts1), that is:
delayi-delay1=(ati-at1)-(tsi-ts1)。
By this conversion, avoid the receiving terminal clock problem that cause calculating inaccurate asynchronous with collection terminal clock.
Step 103: if current time is more than or equal to the reproduction time of the frame of video read out, then remove the frame of video read out and carry out decoding and play from frame of video buffer queue.
Below with according to rti=at1+ (tsi-ts1) to calculate the reproduction time of frame of video read be that example further illustrates method of the present invention to+MaxDelayDelta.
Step a: frame of video receiving thread is from network reception frame of video, if first time receives frame of video just record its timestamp ts1with the time at arrived1, and put it into frame of video buffer queue; Frame of video is received, then computing network time delay relative value delay if not first timei-delay1, and recalculate the maximum MaxDelayDelta of the network delay relative value of all frames received, finally put it into frame of video buffer queue;
The size of temporally being stabbed by frame of video i is inserted into frame of video buffer queue, ensures that the size that queue is temporally stabbed arranges.
Step b: presentation of video frames thread reads the oldest frame of video of timestamp, according to rt from frame of video buffer queuei=at1+ (tsi-ts1)+MaxDelayDelta calculates its reproduction time;
Step c: if current time is more than or equal to the reproduction time of the frame of video of reading, removes this frame of video and carries out decoding and play, otherwise continue to wait for from queue.
As shown in Figure 2, present invention also offers a kind of device of displaying video stream, comprising: receiving element, the first computing unit, broadcast unit and the second computing unit, wherein:
Receiving element, for receiver, video frame, puts into frame of video buffer queue by the frame of video received;
First computing unit, for calculating the maximum in the network delay of the frame of video that receiving element has received;
Broadcast unit, for reading time frame of video the earliest according to the timestamp of frame of video from frame of video buffer queue, if current time is more than or equal to the reproduction time of the frame of video read out, then the frame of video read out is removed from frame of video buffer queue and carry out decoding and play;
Second computing unit, calculates reproduction time for the frame of video that reads out for broadcast unit, wherein, the timestamp of reproduction time=frame of video time+network delay of frame of video that received in maximum.
Further, the first computing unit calculates the maximum in the network delay of the frame of video received, and comprising:
According to MaxDelay=delay1+ MaxDelayDelta calculates the maximum in the network delay of the frame of video received, and wherein, MaxDelay is the maximum in the network delay of the frame of video received, and MaxDelayDelta is Max{delay1-delay1, delay2-delay1..., delayn-delay1, n>=1, delay1for the network delay of first frame of video received, delaynfor the network delay of the n-th frame of video received.
Further, the second computing unit is that the frame of video that broadcast unit reads out calculates reproduction time, comprising:
According to rti=at1+ (tsi-ts1)+MaxDelayDelta calculates reproduction time, wherein, 1≤i≤n, rtifor the reproduction time of i-th frame of video received, at1for receiving the time of first frame of video, tsifor the timestamp time of i-th frame of video received, ts1for the timestamp time of first frame of video received.
Further, the first computing unit, also for according to delayi-delay1=(ati-at1)-(tsi-ts1) calculate MaxDelayDelta, wherein, 1≤i≤n, delayifor the network delay of i-th frame of video received, atifor receiving the time of i-th frame of video, at1for receiving the time of first frame of video, tsifor the timestamp time of i-th frame of video received, ts1for the timestamp time of first frame of video received.
Further, receiving element receiver, video frame, comprising:
If what receive is first frame of video, then record the timestamp time ts of first frame of video1with the time at receiving first frame of video1, and frame of video is put into frame of video buffer queue; If what receive is subsequent video frame, then indicate the first computing unit according to delayi-delay1computing network time delay relative value, and recalculate the maximum MaxDelayDelta in the network delay relative value of all frame of video received, then frame of video is put into frame of video buffer queue.
Although the execution mode disclosed by the present invention is as above, the execution mode that described content only adopts for ease of understanding the present invention, and be not used to limit the present invention.Those of skill in the art belonging to any the present invention; under the prerequisite not departing from the spirit and scope disclosed by the present invention; any amendment and change can be carried out in the form implemented and details; but scope of patent protection of the present invention, the scope that still must define with appending claims is as the criterion.