CN106603518A - Time stamp generating method and time stamp generating device of real-time transmission protocol system - Google Patents
Time stamp generating method and time stamp generating device of real-time transmission protocol system Download PDFInfo
- Publication number
- CN106603518A CN106603518A CN201611102465.3A CN201611102465A CN106603518A CN 106603518 A CN106603518 A CN 106603518A CN 201611102465 A CN201611102465 A CN 201611102465A CN 106603518 A CN106603518 A CN 106603518A
- Authority
- CN
- China
- Prior art keywords
- time
- data frame
- difference
- value
- current data
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Granted
Links
Classifications
-
- H—ELECTRICITY
- H04—ELECTRIC COMMUNICATION TECHNIQUE
- H04L—TRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
- H04L65/00—Network arrangements, protocols or services for supporting real-time applications in data packet communication
- H04L65/60—Network streaming of media packets
- H04L65/65—Network streaming protocols, e.g. real-time transport protocol [RTP] or real-time control protocol [RTCP]
-
- H—ELECTRICITY
- H04—ELECTRIC COMMUNICATION TECHNIQUE
- H04J—MULTIPLEX COMMUNICATION
- H04J3/00—Time-division multiplex systems
- H04J3/02—Details
- H04J3/06—Synchronising arrangements
- H04J3/0635—Clock or time synchronisation in a network
- H04J3/0638—Clock or time synchronisation among nodes; Internode synchronisation
- H04J3/0658—Clock or time synchronisation among packet nodes
- H04J3/0661—Clock or time synchronisation among packet nodes using timestamps
Landscapes
- Engineering & Computer Science (AREA)
- Multimedia (AREA)
- Computer Networks & Wireless Communication (AREA)
- Signal Processing (AREA)
- Data Exchanges In Wide-Area Networks (AREA)
Abstract
Description
技术领域technical field
本申请涉及领域,尤其涉及一种实时传输协议系统的时间戳生成方法及装置。The present application relates to the field, in particular to a method and device for generating a time stamp of a real-time transport protocol system.
背景技术Background technique
时间戳反映了RTP分组中的数据的第一个字节的采样时刻。在一次会话开始时的时间戳初值也是随机选择的。即使是没有信号发送时,时间戳的数值也要随时间不断的增加。接收端使用时间戳可准确知道应当在什么时间还原哪一个数据块,从而消除传输中的抖动。时间戳还可用来使视频应用中声音和图像同步。The timestamp reflects the sampling instant of the first byte of data in the RTP packet. The initial value of the timestamp at the beginning of a session is also randomly selected. Even when no signal is sent, the value of the timestamp will continue to increase over time. Timestamps are used by the receiving end to know exactly which data block should be restored at what time, eliminating jitter in transmission. Timestamps can also be used to synchronize sound and images in video applications.
现有技术中,时间戳一般取法有两种。第一种取法:随机生成视频流初始帧的时间戳,记为T0,根据帧率和视频采样率计算时间戳增量。例如:视频采样率为90000,帧率为25,RTP时间戳单位为1/90000,每帧的时间间隔为0.04秒,RTP时间戳增量=90000×0.04=3600,记为Delta=3600,之后,对每一帧i(i为大于0的自然数),对应的时间戳Ti=Ti-1+Delta。第二种取法:在视频编码器编出一帧数据时,通过系统函数,取到当前时间相对1970年1月1日的时间差,记为D0,单位是秒;将这个取值转换成RTP时间戳。例如:视频采样率为90000,RTP时间戳单位为1/90000,则RTP时间戳T0=D0×90000,之后每一帧的时间戳都按上述方法循环取得,即:Ti=Di×90000。In the prior art, there are generally two ways to obtain the time stamp. The first method: Randomly generate the timestamp of the initial frame of the video stream, denoted as T0, and calculate the timestamp increment according to the frame rate and video sampling rate. For example: the video sampling rate is 90000, the frame rate is 25, the RTP timestamp unit is 1/90000, the time interval of each frame is 0.04 seconds, the RTP timestamp increment=90000×0.04=3600, recorded as Delta=3600, after , for each frame i (i is a natural number greater than 0), the corresponding time stamp Ti=Ti-1+Delta. The second method: when the video encoder compiles a frame of data, use the system function to obtain the time difference between the current time and January 1, 1970, which is recorded as D0, and the unit is second; convert this value into RTP time stamp. For example: the video sampling rate is 90000, and the RTP timestamp unit is 1/90000, then the RTP timestamp T0=D0×90000, and then the timestamp of each frame is obtained cyclically according to the above method, namely: Ti=Di×90000.
上述两种取法存在如下问题:第一种取法属于理想取法,在实际应用中,视频编码器并不能保证每帧视频数据编出来所用的时间是固定0.04秒,所以实际的Delta取值是会随之变动的,如果Delta固定取3600,应用时间长了会有误差累计,而且误差会越来越大,最后导致客户端接收视频流后解码出现异常而断流。第二种取法是在实际应用中使用较多的取法,是实际取了每帧数据编码出来所对应的实际时间(相对1970年1月1日的时间差),不会有误差累计,但是这种取法存在的问题是:在系统时间被改变时,取到的时间戳也会跟着跳变,会造成客户端接收视频流后解码出现异常而断流。The above two methods have the following problems: The first method is an ideal method. In practical applications, the video encoder cannot guarantee that the time used to encode each frame of video data is fixed at 0.04 seconds, so the actual value of Delta will vary with time. As for the change, if the Delta is fixed at 3600, the error will accumulate after a long time of application, and the error will become larger and larger, which will eventually cause the client to receive the video stream and the decoding will be abnormal and the stream will be cut off. The second method is used more in practical applications. It actually takes the actual time corresponding to the encoding of each frame of data (relative to the time difference on January 1, 1970), and there will be no error accumulation. However, this The problem with this method is that when the system time is changed, the obtained timestamp will also jump accordingly, which will cause the client to receive the video stream and decode it abnormally and the stream will be cut off.
综上,现有技术中还没有一种较好的时间戳生成方法,能够解决因系统时间被修改而造成的时间戳跟着跳变的问题。To sum up, there is no better time stamp generation method in the prior art, which can solve the problem of the time stamp jumping due to the modification of the system time.
发明内容Contents of the invention
本申请提供一种实时传输协议系统的时间戳生成方法及装置,可以解决因系统时间被修改而造成的时间戳跟着跳变的问题,减少时间戳的生成错误。The present application provides a time stamp generation method and device for a real-time transport protocol system, which can solve the problem of time stamp jumps caused by modification of system time, and reduce time stamp generation errors.
根据本申请的第一方面,本申请提供一种实时传输协议系统的时间戳生成方法,包括:获取当前数据帧的时间取值以及所述当前数据帧的前一数据帧的时间取值;分别计算所述当前数据帧的时间取值与预设时间的第一差值Di以及所述当前数据帧的前一数据帧的时间取值与预设时间的第二差值Di-1;根据所述第一差值和所述第二差值之间的差值大小的绝对值|Di–Di-1|判断系统时间是否发生跳变;若否,则将Di-Di-1作为第一备用差值Delta,将所述第一备用差值Delta与前一数据帧的时间输出值Outi-1相加,得到当前数据帧的时间输出值Outi;若是,则获取所述前一数据帧的前一数据帧,作为第三数据帧,分别获取所述前一数据帧的时间取值与所述第三数据帧的时间取值;分别计算所述当前数据帧的前一数据帧的时间取值与预设时间的第二差值Di-1以及所述第三数据帧的时间取值与预设时间的第三差值Di-2;将Di-1-Di-2作为第二备用差值Delta',将所述第二备用差值Delta'与前一数据帧的时间输出值Outi-1相加,得到当前数据帧的时间输出值Outi;将所述当前数据帧的时间输出值Outi与数据的采样率相乘,得到当前数据帧的时间戳。According to the first aspect of the present application, the present application provides a method for generating a time stamp of a real-time transport protocol system, comprising: obtaining the time value of the current data frame and the time value of the previous data frame of the current data frame; Calculating a first difference D i between the time value of the current data frame and a preset time and a second difference D i-1 between the time value of the previous data frame of the current data frame and a preset time; According to the absolute value |D i -D i-1 | of the difference between the first difference and the second difference, it is judged whether the system time jumps; if not, D i -D i -1 as the first backup difference Delta, the first backup difference Delta and the time output value Out i-1 of the previous data frame are added to obtain the time output value Out i of the current data frame; if so, then obtain The previous data frame of the previous data frame is used as a third data frame, and the time value of the previous data frame and the time value of the third data frame are obtained respectively; the time value of the current data frame is calculated respectively The second difference D i-1 between the time value of the previous data frame and the preset time and the third difference D i-2 between the time value of the third data frame and the preset time; the D i- 1 -D i-2 is used as the second backup difference Delta', and the second backup difference Delta' is added to the time output value Out i-1 of the previous data frame to obtain the time output value Out of the current data frame i ; multiplying the time output value Out i of the current data frame with the sampling rate of the data to obtain the timestamp of the current data frame.
根据本申请的第二方面,本申请提供一种实时传输协议系统的时间戳生成装置,包括:获取单元,用于获取当前数据帧的时间取值以及所述当前数据帧的前一数据帧的时间取值;第一差值计算单元,用于分别计算所述当前数据帧的时间取值与预设时间的第一差值Di以及所述当前数据帧的前一数据帧的时间取值与预设时间的第二差值Di-1;绝对值大小判断单元,用于根据所述第一差值和所述第二差值之间的差值大小的绝对值|Di–Di-1|判断系统时间是否发生跳变;第一时间输出值计算单元,用于在所述绝对值大小判断单元的判断结果为否时,将Di-Di-1作为第一备用差值Delta,将所述第一备用差值Delta与前一数据帧的时间输出值Outi-1相加,得到当前数据帧的时间输出值Outi;时间取值单元,用于在所述绝对值大小判断单元的判断结果为是时,获取所述前一数据帧的前一数据帧,作为第三数据帧,分别获取所述前一数据帧的时间取值与所述第三数据帧的时间取值;第二差值计算单元,用于分别计算所述当前数据帧的前一数据帧的时间取值与预设时间的第二差值Di-1以及所述第三数据帧的时间取值与预设时间的第三差值Di-2;第二时间输出值计算单元,用于将Di-1-Di-2作为第二备用差值Delta',将所述第二备用差值Delta'与前一数据帧的时间输出值Outi-1相加,得到当前数据帧的时间输出值Outi;时间戳生成单元,用于将所述当前数据帧的时间输出值Outi与数据的采样率相乘,得到当前数据帧的时间戳。According to the second aspect of the present application, the present application provides a time stamp generation device of a real-time transport protocol system, including: an acquisition unit, configured to acquire the time value of the current data frame and the time value of the previous data frame of the current data frame Time value; the first difference calculation unit is used to calculate the first difference D i between the time value of the current data frame and the preset time and the time value of the previous data frame of the current data frame The second difference D i-1 with the preset time; the absolute value judgment unit is used to determine the absolute value |D i -D according to the difference between the first difference and the second difference i-1 | Judging whether the system time jumps; the first time output value calculation unit is used to use D i -D i-1 as the first backup difference when the judgment result of the absolute value judgment unit is no Value Delta, add the time output value Out i-1 of described first spare difference Delta and previous data frame, obtain the time output value Out i of current data frame; When the judgment result of the value size judging unit is yes, the previous data frame of the previous data frame is obtained as the third data frame, and the time value of the previous data frame and the time value of the third data frame are respectively obtained. Time value; the second difference calculation unit is used to calculate the second difference D i-1 between the time value of the previous data frame of the current data frame and the preset time and the second difference D i-1 of the third data frame The third difference D i-2 between the time value and the preset time; the second time output value calculation unit is used to use D i-1- D i-2 as the second backup difference Delta', and the first Two standby difference Delta' and the time output value Out i-1 of the previous data frame are added to obtain the time output value Out i of the current data frame; the timestamp generating unit is used for the time output value of the current data frame Out i is multiplied by the sampling rate of the data to get the timestamp of the current data frame.
本申请的实时传输协议系统的时间戳生成方法及装置,获取当前数据帧的时间取值以及当前数据帧的前一数据帧的时间取值,分别计算当前数据帧的时间取值与预设时间的第一差值Di以及当前数据帧的前一数据帧的时间取值与预设时间的第二差值Di-1,根据第一差值和所述第二差值之间的差值大小的绝对值|Di–Di-1|判断系统时间是否发生跳变,若否,则将Di-Di-1作为第一备用差值Delta,将第一备用差值Delta与前一数据帧的时间输出值Outi-1相加,得到当前数据帧的时间输出值Outi;若是,则分别获取当前数据帧的前一数据帧的时间取值与当前帧的前二帧数据帧的时间取值,分别计算当前数据帧的前一数据帧的时间取值与预设时间的第二差值Di-1以及前二帧数据帧的时间取值与预设时间的第三差值Di-2;将Di-1-Di-2作为第二备用差值Delta',将第二备用差值Delta'与前一数据帧的时间输出值Outi-1相加,得到当前数据帧的时间输出值Outi。最后,将当前数据帧的时间输出值Outi与数据的采样率相乘,得到当前数据帧的时间戳,解决因系统时间被修改而造成的时间戳跟着跳变的问题,有效减少时间戳的生成错误。The time stamp generation method and device of the real-time transmission protocol system of the present application obtain the time value of the current data frame and the time value of the previous data frame of the current data frame, and calculate the time value and preset time of the current data frame respectively The first difference D i of the current data frame and the second difference D i-1 between the time value of the previous data frame of the current data frame and the preset time, according to the difference between the first difference and the second difference The absolute value of the value|D i -D i-1 |judging whether the system time jumps, if not, then use D i -D i-1 as the first backup difference Delta, and the first backup difference Delta and Add the time output value Out i-1 of the previous data frame to obtain the time output value Out i of the current data frame; if so, obtain the time value of the previous data frame of the current data frame and the first two frames of the current frame respectively For the time value of the data frame, calculate the second difference D i-1 between the time value of the previous data frame of the current data frame and the preset time and the second difference between the time value of the previous two data frames and the preset time Three difference values D i-2 ; use D i-1- D i-2 as the second backup difference Delta', add the second backup difference Delta' to the time output value Out i-1 of the previous data frame , to get the time output value Out i of the current data frame. Finally, the time output value Out i of the current data frame is multiplied by the sampling rate of the data to obtain the time stamp of the current data frame, which solves the problem of the time stamp following the jump caused by the modification of the system time and effectively reduces the time stamp. Build error.
附图说明Description of drawings
本发明的上述和/或附加的方面和优点从结合下面附图对实施方式的描述中将变得明显和容易理解,其中:The above and/or additional aspects and advantages of the present invention will become apparent and comprehensible from the description of the embodiments in conjunction with the following drawings, wherein:
图1为本申请实施例的实时传输协议系统的时间戳生成方法流程图;Fig. 1 is the flow chart of the time stamp generating method of the real-time transport protocol system of the embodiment of the present application;
图2为本申请实施例的实时传输协议系统的时间戳生成装置结构示意图;FIG. 2 is a schematic structural diagram of a time stamp generating device of a real-time transport protocol system according to an embodiment of the present application;
图3为本申请实施例的实时传输协议系统的时间戳生成装置另一结构示意图。FIG. 3 is another schematic structural diagram of a time stamp generation device of the real-time transport protocol system according to the embodiment of the present application.
具体实施方式detailed description
下面通过具体实施方式结合附图对本发明作进一步详细说明。本申请提供一种实时传输协议系统的时间戳生成方法及装置,可以减少时间戳的生成错误。The present invention will be further described in detail below through specific embodiments in conjunction with the accompanying drawings. The present application provides a time stamp generation method and device for a real-time transport protocol system, which can reduce time stamp generation errors.
实施例一:Embodiment one:
请参阅图1,图1为本申请实施例一的方法流程图,如图1所示,本申请实施例提供一种实时传输协议系统的时间戳生成方法,具体可以包括以下步骤:Please refer to FIG. 1. FIG. 1 is a flow chart of the method of Embodiment 1 of the present application. As shown in FIG. 1, the embodiment of the present application provides a timestamp generation method for a real-time transport protocol system, which may specifically include the following steps:
S101、获取当前数据帧的时间取值以及当前数据帧的前一数据帧的时间取值。S101. Obtain the time value of the current data frame and the time value of the previous data frame of the current data frame.
S102、分别计算当前数据帧的时间取值与预设时间的第一差值Di以及当前数据帧的前一数据帧的时间取值与预设时间的第二差值Di-1。S102. Calculate respectively the first difference D i between the time value of the current data frame and the preset time and the second difference D i-1 between the time value of the previous data frame of the current data frame and the preset time.
S103、根据第一差值和第二差值之间的差值大小的绝对值|Di–Di-1|判断系统时间是否发生跳变,若否,则执行步骤S104及S109,若是,则执行步骤S105-S109。S103. According to the absolute value |D i -D i-1 | of the difference between the first difference and the second difference, it is judged whether the system time jumps, if not, execute steps S104 and S109, if so, Then execute steps S105-S109.
判断的过程具体可以是:判断所述第一差值和所述第二差值之间的差值大小的绝对值|Di–Di-1|是否大于预设值,若是,则表示系统时间发生跳变,若否,则表示系统时间未跳变。The judging process may specifically be: judging whether the absolute value |D i -D i-1 | of the difference between the first difference and the second difference is greater than a preset value, if so, it means The time has jumped, if not, it means that the system time has not jumped.
优选的,预设值为2S。即差值大于2S,表示系统时间跳变,如果小于两秒,则默认系统时间没有发生跳变。Preferably, the preset value is 2S. That is, if the difference is greater than 2S, it means that the system time jumps. If it is less than 2 seconds, the default system time does not jump.
S104、将Di-Di-1作为第一备用差值Delta,将第一备用差值Delta与前一数据帧的时间输出值Outi-1相加,得到当前数据帧的时间输出值Outi。S104. Using D i -D i-1 as the first backup difference Delta, adding the first backup difference Delta to the time output value Out i-1 of the previous data frame to obtain the time output value Out of the current data frame i .
S105、获取前一数据帧的前一数据帧,作为第三数据帧,分别获取所述前一数据帧的时间取值与所述第三数据帧的时间取值。S105. Obtain a previous data frame of the previous data frame as a third data frame, and respectively obtain a time value of the previous data frame and a time value of the third data frame.
上述步骤S105也即获取当前数据帧的前两帧的数据帧,以第i数据帧表示当前数据帧,那么上述前一数据帧的前一数据帧即为第i-2数据帧。为了后续表述方便,将所述前一帧数据帧的前一数据帧表述为第三数据帧。The above step S105 is to obtain the data frames of the first two frames of the current data frame, and use the i-th data frame to represent the current data frame, then the previous data frame of the above-mentioned previous data frame is the i-2th data frame. For the convenience of subsequent description, the previous data frame of the previous data frame is expressed as a third data frame.
S106、分别计算当前数据帧的前一数据帧的时间取值与预设时间的第二差值Di-1以及第三数据帧的时间取值与预设时间的第三差值Di-2。S106. Calculate respectively the second difference D i-1 between the time value of the previous data frame of the current data frame and the preset time and the third difference D i -1 between the time value of the third data frame and the preset time 2 .
S107、将Di-1-Di-2的差值作为第二备用差值Delta',将第二备用差值Delta'与前一数据帧的时间输出值Outi-1相加,得到当前数据帧的时间输出值Outi。S107. Using the difference between D i-1- D i-2 as the second backup difference Delta', adding the second backup difference Delta' to the time output value Out i-1 of the previous data frame to obtain the current The time output values Out i of the data frame.
S108、将当前数据帧的时间输出值Outi与数据的采样率相乘,得到当前数据帧的时间戳。S108. Multiply the time output value Out i of the current data frame by the sampling rate of the data to obtain the time stamp of the current data frame.
一种实施例中,本申请方法还包括:获取第零帧数据帧的时间取值与预设时间的时间差D0,将D0作为第零帧数据帧的时间输出值。In an embodiment, the method of the present application further includes: acquiring a time difference D 0 between the time value of the zeroth data frame and a preset time, and using D 0 as the time output value of the zeroth data frame.
在初始编码时,以D0作为首帧数据帧的时间输出值。可以理解的是,后续各帧的时间输出值都是在前一帧时间输出值的基础上计算得到。During initial encoding, D 0 is used as the time output value of the first data frame. It can be understood that the time output values of subsequent frames are all calculated on the basis of the time output values of the previous frame.
实施例二:Embodiment two:
本申请实施例提供一种实时传输协议系统的时间戳生成方法,具体可以包括以下步骤:An embodiment of the present application provides a method for generating a time stamp of a real-time transport protocol system, which may specifically include the following steps:
S201、初始,视频编码器编码出第0帧视频数据帧的同时,获取当前时间T0与预设时间Tb之间的时间差D0,作为时间基准点,同时将当前时间输出值Out0=D0,也即,将时间基准点D0作为初始数据帧的时间输出值Out0输出。S201. Initially, when the video encoder encodes the 0th frame of video data frame, it obtains the time difference D 0 between the current time T0 and the preset time Tb as a time reference point, and at the same time outputs the current time value Out 0 =D 0 , that is, the time reference point D 0 is output as the time output value Out 0 of the initial data frame.
预设时间Tb可以是例如1970年1月1日,本例以此时间作介绍。可以理解的是,预设时间是用于作为参考时间,本例中预设时间Tb的具体的时间点也可以是其他日期时间,如1971年1月1日,具体在设置预设时间Tb时,可以根据实际需求以及计算精度将预设时间取到毫秒级别,但值得指出的是,本例中预设时间Tb在整个计算过程是保持不变的。The preset time Tb may be, for example, January 1, 1970, which is used in this example for introduction. It can be understood that the preset time is used as a reference time. In this example, the specific time point of the preset time Tb can also be other date and time, such as January 1, 1971, specifically when setting the preset time Tb , the preset time can be taken to the millisecond level according to actual needs and calculation accuracy, but it is worth pointing out that in this example, the preset time Tb remains unchanged throughout the calculation process.
S202、获取当前数据帧的时间取值Ti与预设时间Tb之间的时间差,得到第一差值Di;获取当前数据帧的前一数据帧的时间取值Ti’与预设时间Tb的第二差值Di-1。S202. Obtain the time difference between the time value Ti of the current data frame and the preset time Tb to obtain the first difference Di; obtain the time value Ti' of the previous data frame of the current data frame and the first difference between the preset time Tb Two differences D i-1 .
本例以系统当前编码至第5帧数据帧为例进行说明。可以理解的是,本例同样适用于在第5帧以后各数据帧以及第5帧之前各数据帧的时间戳生成方式。In this example, the system is currently encoding to the fifth frame data frame as an example for illustration. It can be understood that this example is also applicable to the timestamp generation method of each data frame after the fifth frame and each data frame before the fifth frame.
上述步骤S202中,获取当前数据帧的时间取值Ti与预设时间Tb之间的时间差,得到第一差值Di举例为:获取第5帧数据帧的时间取值T5与预设时间Tb的时间差,得到第一差值D5。In the above step S202, the time difference between the time value Ti of the current data frame and the preset time Tb is obtained, and the first difference D i is obtained as an example: the time value T5 and the preset time Tb of the fifth frame data frame are obtained to obtain the first difference D 5 .
上述步骤S202中,获取当前数据帧的前一数据帧的时间取值Ti’与预设时间Tb的第二差值Di-1举例为:获取第4帧数据帧的时间取值T4与预设时间Tb的时间差,得到第二差值D4。In the above step S202, the second difference D i-1 between the time value Ti' of the previous data frame of the current data frame and the preset time Tb is obtained as an example: the time value T4 and the preset time value T4 of the fourth frame data frame are obtained. Assuming a time difference of time Tb, the second difference D 4 is obtained.
S203、根据第一差值Di和第二差值Di-1之间的差值大小的绝对值|Di–Di-1|判断系统时间是否发生跳变,若否,则执行步骤S204-S205及步骤210,若是,则执行步骤S206-S210。S203. According to the absolute value of the difference between the first difference D i and the second difference D i-1 |D i -D i-1 |, determine whether the system time jumps, if not, execute the step S204-S205 and step 210, if yes, execute steps S206-S210.
上述步骤S203中判断系统时间是否发生跳变的过程举例为:根据第一差值D5和第二差值D4之间的差值大小的绝对值|D5–D4|判断系统时间是否发生跳变。An example of the process of judging whether the system time jumps in the above step S203 is: according to the absolute value of the difference between the first difference D 5 and the second difference D 4 |D 5 -D 4 | jump occurs.
S204、将Di-Di-1作为第一备用差值Delta。S204. Use D i -D i-1 as the first backup difference Delta.
S205、将第一备用差值Delta与前一数据帧的时间输出值Outi-1相加,得到当前数据帧的时间输出值Outi。S205. Add the first standby difference Delta to the time output value Out i-1 of the previous data frame to obtain the time output value Out i of the current data frame.
按照实际应用场景可以是:计算第5帧数据帧的时间取值与1970年1月1日的第一差值D5,计算第4帧数据帧的时间取值与1970年1月1日之间的第一差值D4。According to the actual application scenario, it can be: calculate the first difference D 5 between the time value of the fifth frame data frame and January 1, 1970, and calculate the difference between the time value of the fourth frame data frame and January 1, 1970 The first difference D 4 between.
上述步骤S204-S205为:将D5-D4的值作为第一备用差值Delta。The above steps S204-S205 are: taking the value of D 5 -D 4 as the first backup difference value Delta.
将Delta与第4帧数据帧的时间输出值Out4相加,得到当前数据帧的时间输出值Out5。即:Out5=Out4+Delta=Out4+D5-D4。Add Delta to the time output value Out 4 of the fourth data frame to obtain the time output value Out 5 of the current data frame. That is: Out 5 =Out 4 +Delta =Out 4 +D 5 -D 4 .
S206、获取前一数据帧的前一数据帧,作为第三数据帧,分别获取前一数据帧的时间取值与第三数据帧的时间取值。S206. Obtain a previous data frame of the previous data frame as a third data frame, respectively obtain the time value of the previous data frame and the time value of the third data frame.
本实施例应用场景中,步骤S206为获取第3帧数据帧,作为第三数据帧,获取第3帧数据帧的时间取值以及获取第4帧数据帧的时间取值。In the application scenario of this embodiment, step S206 is to acquire the third data frame, as the third data frame, acquire the time value of the third data frame and the time value of the fourth data frame.
S207、分别计算当前数据帧的前一数据帧的时间取值与预设时间的第二差值Di-1以及第三数据帧的时间取值与预设时间的第三差值Di-2。S207. Calculate respectively the second difference D i-1 between the time value of the previous data frame of the current data frame and the preset time and the third difference D i -1 between the time value of the third data frame and the preset time 2 .
本实施例应用场景中,上述步骤S207为:获取第4帧数据帧的时间取值T4与预设时间Tb的时间差,得到第二差值D4,以及,获取第3帧数据帧的时间取值T3与预设时间Tb的时间差,得到第三差值D3。In the application scenario of this embodiment, the above step S207 is: obtain the time difference between the time value T4 of the fourth frame data frame and the preset time Tb, obtain the second difference D 4 , and obtain the time value of the third frame data frame The time difference between the value T3 and the preset time Tb to obtain the third difference D 3 .
S208、将Di-1-Di-2作为第二备用差值Delta'。S208. Use D i-1 - D i-2 as the second backup difference Delta'.
S209、将前一数据帧的时间输出值Outi-1与第二备用差值Delta’相加,得到的数值当前数据帧的时间输出值Outi。S209. Add the time output value Out i-1 of the previous data frame to the second spare difference Delta' to obtain the time output value Out i of the current data frame.
按照实际应用场景可以是:计算第4帧数据帧的时间取值与1970年1月1日的第二差值D4,计算第3帧数据帧的时间取值与1970年1月1日之间的第三差值D3。According to the actual application scenario, it can be: calculate the second difference D 4 between the time value of the fourth frame data frame and January 1, 1970, and calculate the difference between the time value of the third frame data frame and January 1, 1970 The third difference D 3 between.
上述步骤S208-S209为:将D4-D3的值作为第二备用差值Delta’。The above steps S208-S209 are: taking the value of D 4 -D 3 as the second spare difference value Delta'.
将Delta’与第4帧数据帧的时间输出值Out4相加,得到当前数据帧的时间输出值Out5。即:Out5=Out4+Delta’。也即,Out5=Out4+D4-D3。Add Delta' to the time output value Out 4 of the fourth data frame to obtain the time output value Out 5 of the current data frame. That is: Out 5 =Out 4 +Delta'. That is, Out 5 =Out 4 +D 4 −D 3 .
S210、将当前数据帧的时间输出值Outi与数据的采样率相乘,得到当前数据帧的时间戳。S210. Multiply the time output value Out i of the current data frame by the sampling rate of the data to obtain the time stamp of the current data frame.
假设时间戳为TC,采样率为f,以计算第5帧的时间戳为例子,则步骤S210可以是:Assuming that the time stamp is T C and the sampling rate is f, taking the calculation of the time stamp of the fifth frame as an example, step S210 may be:
当系统时间没有改变时,TC=Out5×f=(Out4+D5-D4)×fWhen the system time does not change, T C =Out 5 ×f=(Out 4 +D 5 -D 4 )×f
当系统时间被改变时,TC=Out5×f=(Out4+D4-D3)×fWhen the system time is changed, T C =Out 5 ×f=(Out 4 +D 4 -D 3 )×f
实施例三:Embodiment three:
请参阅图2,图2为本申请实施例二的结构示意图,如图2所示,本申请实施例提供一种实时传输协议系统的时间戳生成装置,可以包括:Please refer to FIG. 2. FIG. 2 is a schematic structural diagram of Embodiment 2 of the present application. As shown in FIG. 2, the embodiment of the present application provides a timestamp generating device for a real-time transport protocol system, which may include:
获取单元30,用于获取当前数据帧的时间取值以及所述当前数据帧的前一数据帧的时间取值。The acquiring unit 30 is configured to acquire the time value of the current data frame and the time value of the previous data frame of the current data frame.
第一差值计算单元31,用于分别计算所述当前数据帧的时间取值与预设时间的第一差值Di以及所述当前数据帧的前一数据帧的时间取值与预设时间的第二差值Di-1。The first difference calculation unit 31 is used to calculate the first difference D i between the time value of the current data frame and the preset time and the time value and preset time value of the previous data frame of the current data frame The second difference in time D i-1 .
绝对值大小判断单元32,用于根据所述第一差值和所述第二差值之间的差值大小的绝对值|Di–Di-1|判断系统时间是否发生跳变。The absolute value judging unit 32 is configured to judge whether the system time jumps according to the absolute value |D i −D i-1 | of the difference between the first difference and the second difference.
第一时间输出值计算单元33,用于在绝对值大小判断单元32的判断结果为否时,将Di-Di-1作为第一备用差值Delta,将所述第一备用差值Delta与前一数据帧的时间输出值Outi-1相加,得到当前数据帧的时间输出值Outi。The first time output value calculation unit 33 is used to use D i -D i-1 as the first backup difference Delta when the judgment result of the absolute value judgment unit 32 is No, and use the first backup difference Delta It is added to the time output value Out i-1 of the previous data frame to obtain the time output value Out i of the current data frame.
时间取值单元34,用于在绝对值大小判断单32元的判断结果为是时,获取所述前一数据帧的前一数据帧,作为第三数据帧,分别获取所述前一数据帧的时间取值与所述第三数据帧的时间取值。The time value unit 34 is used to obtain the previous data frame of the previous data frame as the third data frame when the judgment result of the absolute value judgment unit 32 is yes, and respectively obtain the previous data frame The time value of and the time value of the third data frame.
第二差值计算单元35,用于分别计算所述当前数据帧的前一数据帧的时间取值与预设时间的第二差值Di-1以及所述第三数据帧的时间取值与预设时间的第三差值Di-2。The second difference calculation unit 35 is used to calculate the second difference D i-1 between the time value of the previous data frame of the current data frame and the preset time and the time value of the third data frame respectively A third difference D i-2 from the preset time.
第二时间输出值计算单元36,用于将Di-1-Di-2作为第二备用差值Delta',将所述第二备用差值Delta'与前一数据帧的时间输出值Outi-1相加,得到当前数据帧的时间输出值Outi。The second time output value calculation unit 36 is used to use D i-1- D i-2 as the second backup difference Delta', and compare the second backup difference Delta' with the time output value Out of the previous data frame Add i-1 to get the time output value Out i of the current data frame.
时间戳生成单元37,用于将所述当前数据帧的时间输出值Outi与数据的采样率相乘,得到当前数据帧的时间戳。A time stamp generating unit 37, configured to multiply the time output value Out i of the current data frame by the sampling rate of the data to obtain the time stamp of the current data frame.
一个实施例中,绝对值大小判断单元30具体用于:In one embodiment, the absolute value judgment unit 30 is specifically used for:
判断所述第一差值和所述第二差值之间的差值大小的绝对值|Di–Di-1|是否大于预设值,若是,则表示系统时间发生跳变,若否,则表示系统时间未跳变。Judging whether the absolute value |D i -D i-1 | of the difference between the first difference and the second difference is greater than a preset value, if yes, it means that the system time jumps, if not , it means that the system time has not jumped.
优选的,预设值为2S。Preferably, the preset value is 2S.
一个实施例中,如图3所示,本实施例装置还包括:初始获取单元38,用于获取第零帧数据帧的时间取值与预设时间的时间差D0,将D0作为第零帧数据帧的时间输出值。In one embodiment, as shown in FIG. 3 , the device of this embodiment further includes: an initial acquisition unit 38, configured to acquire the time difference D 0 between the time value of the zeroth frame data frame and the preset time, and D 0 is used as the zeroth frame The time output value of the frame data frame.
本申请的实时传输协议系统的时间戳生成方法及装置,当系统时间没有被修改时,计算本次与上次时间取值的时间差,将时间差累加到上次的时间输出值上作为本次的时间输出值。如果时间有跳变,则不再计算时间差,用上次计算出的时间差,累加到上次的时间输出值上,作为本次的时间输出值。最后将当前数据帧的时间输出值与数据的采样率相乘,得到当前数据帧的时间戳,解决了因系统时间被修改而造成的时间戳跟着跳变的问题,减少时间戳的生成错误。The time stamp generation method and device of the real-time transport protocol system of the present application, when the system time has not been modified, calculate the time difference between this time and the last time value, and add the time difference to the last time output value as this time Time output value. If the time jumps, the time difference is no longer calculated, and the time difference calculated last time is added to the last time output value as the current time output value. Finally, the time output value of the current data frame is multiplied by the sampling rate of the data to obtain the time stamp of the current data frame, which solves the problem of the time stamp following the jump caused by the modification of the system time and reduces the generation error of the time stamp.
以上内容是结合具体的实施方式对本发明所作的进一步详细说明,不能认定本发明的具体实施只局限于这些说明。对于本发明所属技术领域的普通技术人员来说,在不脱离本发明构思的前提下,还可以做出若干简单推演或替换。The above content is a further detailed description of the present invention in conjunction with specific embodiments, and it cannot be assumed that the specific implementation of the present invention is limited to these descriptions. Those of ordinary skill in the technical field to which the present invention belongs can also make some simple deduction or replacement without departing from the concept of the present invention.
Claims (8)
Priority Applications (1)
| Application Number | Priority Date | Filing Date | Title |
|---|---|---|---|
| CN201611102465.3A CN106603518B (en) | 2016-12-05 | 2016-12-05 | A kind of the timestamp generation method and device of real-time transport protocol system |
Applications Claiming Priority (1)
| Application Number | Priority Date | Filing Date | Title |
|---|---|---|---|
| CN201611102465.3A CN106603518B (en) | 2016-12-05 | 2016-12-05 | A kind of the timestamp generation method and device of real-time transport protocol system |
Publications (2)
| Publication Number | Publication Date |
|---|---|
| CN106603518A true CN106603518A (en) | 2017-04-26 |
| CN106603518B CN106603518B (en) | 2019-08-20 |
Family
ID=58595615
Family Applications (1)
| Application Number | Title | Priority Date | Filing Date |
|---|---|---|---|
| CN201611102465.3A Active CN106603518B (en) | 2016-12-05 | 2016-12-05 | A kind of the timestamp generation method and device of real-time transport protocol system |
Country Status (1)
| Country | Link |
|---|---|
| CN (1) | CN106603518B (en) |
Cited By (5)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN107392983A (en) * | 2017-08-07 | 2017-11-24 | 东方联合动画有限公司 | A kind of method and system for recording animation |
| CN110896464A (en) * | 2019-11-19 | 2020-03-20 | 北京奇艺世纪科技有限公司 | Audio data generation method, device and system and controller |
| CN111277896A (en) * | 2020-02-13 | 2020-06-12 | 上海高重信息科技有限公司 | Method and device for image splicing of network video stream |
| CN111629241A (en) * | 2020-05-22 | 2020-09-04 | 海信电子科技(深圳)有限公司 | Method for providing time information in physical layer signaling and display equipment |
| CN114726658A (en) * | 2020-08-31 | 2022-07-08 | 华为技术有限公司 | Method and device |
Citations (6)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| EP1351472A2 (en) * | 2002-04-01 | 2003-10-08 | Samsung Electronics Co., Ltd. | Forming RTP packets |
| CN1671124A (en) * | 2004-03-19 | 2005-09-21 | 清华大学 | Communication terminal device, communication terminal receiving method, communication system, and gateway |
| CN102088397A (en) * | 2009-12-03 | 2011-06-08 | 中兴通讯股份有限公司 | Communication network element and clock frequency correction system and method |
| CN102761468A (en) * | 2011-04-26 | 2012-10-31 | 中兴通讯股份有限公司 | Method and system for adaptive adjustment of voice jitter buffer |
| CN103347004A (en) * | 2013-06-19 | 2013-10-09 | 深圳市共进电子股份有限公司 | Method for improving VBD data transmission quality |
| CN105763942A (en) * | 2016-04-22 | 2016-07-13 | 烽火通信科技股份有限公司 | Calculating method of IPTV set top box VMOS value |
-
2016
- 2016-12-05 CN CN201611102465.3A patent/CN106603518B/en active Active
Patent Citations (6)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| EP1351472A2 (en) * | 2002-04-01 | 2003-10-08 | Samsung Electronics Co., Ltd. | Forming RTP packets |
| CN1671124A (en) * | 2004-03-19 | 2005-09-21 | 清华大学 | Communication terminal device, communication terminal receiving method, communication system, and gateway |
| CN102088397A (en) * | 2009-12-03 | 2011-06-08 | 中兴通讯股份有限公司 | Communication network element and clock frequency correction system and method |
| CN102761468A (en) * | 2011-04-26 | 2012-10-31 | 中兴通讯股份有限公司 | Method and system for adaptive adjustment of voice jitter buffer |
| CN103347004A (en) * | 2013-06-19 | 2013-10-09 | 深圳市共进电子股份有限公司 | Method for improving VBD data transmission quality |
| CN105763942A (en) * | 2016-04-22 | 2016-07-13 | 烽火通信科技股份有限公司 | Calculating method of IPTV set top box VMOS value |
Cited By (7)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN107392983A (en) * | 2017-08-07 | 2017-11-24 | 东方联合动画有限公司 | A kind of method and system for recording animation |
| CN107392983B (en) * | 2017-08-07 | 2020-12-08 | 东方联合动画有限公司 | A method and system for recording animation |
| CN110896464A (en) * | 2019-11-19 | 2020-03-20 | 北京奇艺世纪科技有限公司 | Audio data generation method, device and system and controller |
| CN111277896A (en) * | 2020-02-13 | 2020-06-12 | 上海高重信息科技有限公司 | Method and device for image splicing of network video stream |
| CN111629241A (en) * | 2020-05-22 | 2020-09-04 | 海信电子科技(深圳)有限公司 | Method for providing time information in physical layer signaling and display equipment |
| CN114726658A (en) * | 2020-08-31 | 2022-07-08 | 华为技术有限公司 | Method and device |
| CN114726658B (en) * | 2020-08-31 | 2023-04-11 | 华为技术有限公司 | Method and device for measuring time deviation |
Also Published As
| Publication number | Publication date |
|---|---|
| CN106603518B (en) | 2019-08-20 |
Similar Documents
| Publication | Publication Date | Title |
|---|---|---|
| CN106603518B (en) | A kind of the timestamp generation method and device of real-time transport protocol system | |
| US9407387B2 (en) | Apparatus and method for synchronized transmission of multimedia content over an asynchronous network | |
| CN101820500B (en) | Slave device, time synchronization method in slave device, master device, and electronic equipment system | |
| JP6227714B2 (en) | Method and apparatus for synchronizing a slave clock to a master clock | |
| JP3655249B2 (en) | Data receiving / reproducing method and data communication apparatus | |
| US20100209070A1 (en) | Slave device, time synchronization method in slave device, master device, and electronic equipment system | |
| JP2004180255A (en) | Network system | |
| US10594424B2 (en) | Time synchronization slave apparatus capable of adjusting time synchronization period, and method of determining time synchronization period | |
| US9621682B2 (en) | Reduced latency media distribution system | |
| TW201802700A (en) | Systems and methods for controlling isochronous data streams | |
| CN102065060B (en) | Media stream switching synchronization method and streaming media server | |
| CN105207767B (en) | A method and device for frequency synchronization between a PTP master clock and a slave clock | |
| JP2009212876A (en) | Ip stream transmission/reception system, ip stream receiver, and reception processing timing synchronization method used for the same | |
| US9706509B2 (en) | Synchronization of streaming data | |
| CN102256128B (en) | Synchronous decoding method and device | |
| JP4655006B2 (en) | IP stream transmission / reception system, IP stream reception apparatus, and reception processing timing synchronization method used therefor | |
| CN105323053A (en) | Business clock transparent transmission method and apparatus | |
| WO2017097034A1 (en) | Time stamp processing method and apparatus for time message in optical transport network | |
| JP5741064B2 (en) | Video / audio processing apparatus and video / audio processing method | |
| CN103227707A (en) | Synchronization processing apparatus, synchronization processing method and program | |
| CN117879747A (en) | Method, device, equipment and storage medium for obtaining message timestamp | |
| JP5239405B2 (en) | TS receiver and timing reproduction method used therefor | |
| WO2014073293A1 (en) | Communication apparatus, communication system, synchronization method, and program | |
| JP2004104701A (en) | Communication terminal device and data communication program | |
| JP5441650B2 (en) | Media receiver |
Legal Events
| Date | Code | Title | Description |
|---|---|---|---|
| PB01 | Publication | ||
| PB01 | Publication | ||
| SE01 | Entry into force of request for substantive examination | ||
| SE01 | Entry into force of request for substantive examination | ||
| GR01 | Patent grant | ||
| GR01 | Patent grant | ||
| CP03 | Change of name, title or address |
Address after: 518000 6th floor, building 3, Nanyou 4th Industrial Zone, Nanshan Avenue, Nanshan District, Shenzhen City, Guangdong Province Patentee after: Shenzhen Sanjiang Intelligent Control Technology Co.,Ltd. Address before: 518054 6th floor, building 3, Nanyou 4th Industrial Zone, Nanshan Avenue, Nanshan District, Shenzhen City, Guangdong Province Patentee before: SHENZHEN FANHAI SANJIANG TECHNOLOGY DEVELOPMENT Co.,Ltd. |
|
| CP03 | Change of name, title or address |