CN113382300B - Audio and video playing method and device - Google Patents
Audio and video playing method and device Download PDFInfo
- Publication number
- CN113382300B CN113382300B CN202110635135.5A CN202110635135A CN113382300B CN 113382300 B CN113382300 B CN 113382300B CN 202110635135 A CN202110635135 A CN 202110635135A CN 113382300 B CN113382300 B CN 113382300B
- Authority
- CN
- China
- Prior art keywords
- time
- clock
- current
- ctr
- stc
- 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.)
- Active
Links
Images
Classifications
-
- H—ELECTRICITY
- H04—ELECTRIC COMMUNICATION TECHNIQUE
- H04N—PICTORIAL COMMUNICATION, e.g. TELEVISION
- H04N21/00—Selective content distribution, e.g. interactive television or video on demand [VOD]
- H04N21/40—Client devices specifically adapted for the reception of or interaction with content, e.g. set-top-box [STB]; Operations thereof
- H04N21/43—Processing of content or additional data, e.g. demultiplexing additional data from a digital video stream; Elementary client operations, e.g. monitoring of home network or synchronising decoder's clock; Client middleware
- H04N21/4302—Content synchronisation processes, e.g. decoder synchronisation
- H04N21/4305—Synchronising client clock from received content stream, e.g. locking decoder clock with encoder clock, extraction of the PCR packets
-
- H—ELECTRICITY
- H04—ELECTRIC COMMUNICATION TECHNIQUE
- H04N—PICTORIAL COMMUNICATION, e.g. TELEVISION
- H04N21/00—Selective content distribution, e.g. interactive television or video on demand [VOD]
- H04N21/40—Client devices specifically adapted for the reception of or interaction with content, e.g. set-top-box [STB]; Operations thereof
- H04N21/43—Processing of content or additional data, e.g. demultiplexing additional data from a digital video stream; Elementary client operations, e.g. monitoring of home network or synchronising decoder's clock; Client middleware
- H04N21/44—Processing of video elementary streams, e.g. splicing a video clip retrieved from local storage with an incoming video stream or rendering scenes according to encoded video stream scene graphs
- H04N21/44012—Processing of video elementary streams, e.g. splicing a video clip retrieved from local storage with an incoming video stream or rendering scenes according to encoded video stream scene graphs involving rendering scenes according to scene graphs, e.g. MPEG-4 scene graphs
-
- H—ELECTRICITY
- H04—ELECTRIC COMMUNICATION TECHNIQUE
- H04N—PICTORIAL COMMUNICATION, e.g. TELEVISION
- H04N21/00—Selective content distribution, e.g. interactive television or video on demand [VOD]
- H04N21/80—Generation or processing of content or additional data by content creator independently of the distribution process; Content per se
- H04N21/85—Assembly of content; Generation of multimedia applications
- H04N21/854—Content authoring
- H04N21/8547—Content authoring involving timestamps for synchronizing content
Landscapes
- Engineering & Computer Science (AREA)
- Multimedia (AREA)
- Signal Processing (AREA)
- Computer Security & Cryptography (AREA)
- Two-Way Televisions, Distribution Of Moving Picture Or The Like (AREA)
- Television Signal Processing For Recording (AREA)
Abstract
Description
技术领域technical field
本发明涉及多媒体技术领域,特别是涉及一种音视频播放方法和装置。The present invention relates to the field of multimedia technologies, in particular to an audio and video playing method and device.
背景技术Background technique
随着越来越多的TV厂商支持下一代电视ATSC3.0标准,4K/8K高分辨率高帧率节目将成为未来电视主流。As more and more TV manufacturers support the next-generation TV ATSC3.0 standard, 4K/8K high-resolution high-frame-rate programs will become the mainstream of future TV.
发明人在实现本发明的过程中发现当采用ATSC3.0标准时,用户终端采用现有的音视频播放方法会存在音视频无法平滑播放的问题。发明人通过认真研究分析发现该问题存在的原因如下:In the process of implementing the present invention, the inventor found that when the ATSC3.0 standard is adopted, the existing audio and video playback method used by the user terminal will have the problem that the audio and video cannot be played smoothly. The reason why the inventor finds that this problem exists through serious research and analysis is as follows:
现有的音视频播放方法中,广播运营商把音视频信号传输给用户终端后,用户终端需要恢复出一个与广播运营商频率一致的时钟,初始值为用户终端接收到的第一个节目参考时间,并基于此时钟来在解码环节处理数据。在现有的电视标准(如MPEG-2国际标准规范《ISO/IEC 13818》)中,明确规定了音视频源端时钟频率具体为27MHz。这样,用户终端可以基于标准规定恢复出与音视频源端频率完全一致的时钟。而在ATSC3.0标准等其他系统中,并没有确定音视频源端时钟频率的具体数值是多少,这样,用户终端将无法恢复出与音视频源端频率完全一致的时钟,从而导致用户终端的参考时钟与音视频源端的编码时钟存在差异。这种差异,在经过几个小时乃至更长时间的持续积累后,会最终导致用户终端发生数据饥饿(即由于参考时钟相对于音视频源端的编码时钟较快,而导致播放进度快于源端生成数据的速度,从而导致播放过程中需要等待音视频数据的到达)或者数据堆积(即由于参考时钟相对于源端的编码时钟较慢,而导致播放进度慢于源端生成数据的速度,从而导致音视频数据在用户终端侧堆积),从而造成音视频不能够平滑播放。In the existing audio and video playback method, after the broadcast operator transmits the audio and video signal to the user terminal, the user terminal needs to restore a clock that is consistent with the frequency of the broadcast operator. The initial value is the first program reference received by the user terminal. Time, and based on this clock to process data in the decoding link. In existing television standards (such as the MPEG-2 international standard specification "ISO/IEC 13818"), it is clearly stipulated that the clock frequency of the audio and video source is specifically 27 MHz. In this way, the user terminal can recover a clock that is completely consistent with the frequency of the audio and video source terminal based on standard regulations. However, in other systems such as the ATSC3.0 standard, the specific value of the clock frequency of the audio and video source is not determined. In this way, the user terminal will not be able to recover a clock that is completely consistent with the frequency of the audio and video source, resulting in the failure of the user terminal. There is a difference between the reference clock and the encoding clock of the audio and video source. This difference, after several hours or even longer time of continuous accumulation, will eventually lead to data starvation in the user terminal (that is, because the reference clock is faster than the encoding clock of the audio and video source, the playback progress is faster than the source end The speed at which data is generated, which leads to the need to wait for the arrival of audio and video data during playback) or data accumulation (that is, because the reference clock is slower than the encoding clock at the source end, the playback progress is slower than the speed at which data is generated at the source end, resulting in Audio and video data accumulate on the user terminal side), resulting in audio and video cannot be played smoothly.
发明内容Contents of the invention
有鉴于此,本发明的主要目的在于提供一种音视频播放方法和装置,可以使得音视频能够平滑播放。In view of this, the main purpose of the present invention is to provide a method and device for playing audio and video, which can enable smooth playback of audio and video.
为了达到上述目的,本发明实施例提出的技术方案为:In order to achieve the above object, the technical scheme proposed in the embodiment of the present invention is:
一种音视频播放方法,包括:A method for playing audio and video, comprising:
在音视频播放过程中,播放终端基于待渲染数据帧的显示时间戳和相应类型数据的播放流逝时间,进行渲染同步控制,并基于源端时间对所述播放终端的专用时钟进行同步调整控制,以匹配源端时间;所述播放流逝时间基于所述专用时钟获得。During audio and video playback, the playback terminal performs rendering synchronization control based on the display timestamp of the data frame to be rendered and the playback elapsed time of the corresponding type of data, and performs synchronous adjustment control on the dedicated clock of the playback terminal based on the source time, to match the source time; the playback elapsed time is obtained based on the dedicated clock.
较佳地,所述进行渲染同步控制包括:Preferably, said rendering synchronization control includes:
当待渲染数据帧到达渲染器时,如果满足Framepts≤STCelapsed≤Framepts+Dmax,则基于当前待渲染数据帧进行渲染;其中,STCelapsed为当前的所述播放流逝时间,Framepts为当前待渲染数据帧的显示时间戳,Dmax为预设的最大允许延迟显示时间;0≤Dmax≤Frameduration;Frameduration为单个数据帧的显示时长;When the data frame to be rendered arrives at the renderer, if Frame pts ≤ STC elapsed ≤ Frame pts + D max is satisfied, rendering is performed based on the current data frame to be rendered; where, STC elapsed is the current elapsed playback time, and Frame pts is The display timestamp of the current data frame to be rendered, D max is the preset maximum allowed delay display time; 0≤D max ≤Frame duration ; Frame duration is the display duration of a single data frame;
如果满足STCelapsed<Framepts,则等待时间△t之后基于当前待渲染数据帧进行渲染,△t=Framepts-STCelapsed;If STC elapsed <Frame pts is satisfied, render based on the current data frame to be rendered after the waiting time △t, △t=Frame pts -STC elapsed ;
如果满足STCelapsed>Framepts+Dmax,则丢弃当前待渲染数据帧。If STC elapsed >Frame pts +D max is satisfied, the current data frame to be rendered is discarded.
较佳地,所述播放流逝时间的获取包括:Preferably, the acquisition of the playing elapsed time includes:
当所述待渲染数据帧到达渲染器时,获取所述专用时钟当前的计数时间;其中,所述专用时钟的计数时间为单调递增值;When the data frame to be rendered arrives at the renderer, obtain the current counting time of the dedicated clock; wherein, the counting time of the dedicated clock is a monotonically increasing value;
计算所述计数时间与第一初始时间的差值,得到所述播放流逝时间;所述第一初始时间为所述音视频播放的首个数据帧到达渲染器时获取的所述计数时间。Calculate the difference between the counted time and the first initial time to obtain the elapsed playback time; the first initial time is the counted time acquired when the first data frame played by the audio and video arrives at the renderer.
较佳地,所述对所述专用时钟进行同步调整控制包括:Preferably, the synchronous adjustment control of the dedicated clock includes:
在预设的同步调整时刻到达时,所述播放终端获取当前的源端时间SrcTimecurr和所述专用时钟当前的计数时间STCcurr,其中,所述计数时间STCcurr和所述源端时间SrcTimecurr均为单调递增值;When the preset synchronization adjustment time arrives, the playback terminal acquires the current source time SrcTime curr and the current counting time STC curr of the dedicated clock, wherein the counting time STC curr and the source time SrcTime curr Both are monotonically increasing values;
计算所述计数时间STCcurr与第二初始时间STCinit的差值,得到第一相对时间STCdiff;计算所述源端时间SrcTimecurr与第三初始时间SrcTimeinit的差值,得到第二相对时间SrcTimediff;其中,所述第二初始时间STCinit为第一个同步调整时刻到达时获取的所述计数时间;所述第三初始时间SrcTimeinit为第一个同步调整时刻到达时获取的所述源端时间;Calculate the difference between the counting time STC curr and the second initial time STC init to obtain the first relative time STC diff ; calculate the difference between the source time SrcTime curr and the third initial time SrcTime init to obtain the second relative time SrcTime diff ; wherein, the second initial time STC init is the counting time obtained when the first synchronization adjustment moment arrives; the third initial time SrcTime init is the count time obtained when the first synchronization adjustment moment arrives source time;
计算所述第一相对时间STCdiff和第二相对时间SrcTimediff的差值,得到所述专用时钟相对于音视频源端时钟的时间误差Timeerror;Calculate the difference between the first relative time STC diff and the second relative time SrcTime diff to obtain the time error Time error of the dedicated clock relative to the audio and video source clock;
如果所述时间误差Timeerror大于预设的最大误差阈值,则按照预设的第一频率微调步长,减小所述专用时钟的输出频率;所述最大误差阈值大于零;If the time error Time error is greater than a preset maximum error threshold, fine-tune the step size according to the preset first frequency to reduce the output frequency of the dedicated clock; the maximum error threshold is greater than zero;
如果所述时间误差Timeerror小于预设的最小误差阈值,则按照预设的第二频率微调步长,增大所述专用时钟的输出频率;所述最小误差阈值小于零。If the time error Time error is smaller than a preset minimum error threshold, fine-tune the step according to a preset second frequency to increase the output frequency of the dedicated clock; the minimum error threshold is smaller than zero.
较佳地,所述专用时钟当前的计数时间的获取包括:Preferably, the acquisition of the current counting time of the dedicated clock includes:
从所述专用时钟获取当前的时钟计数值Wctr_curr;Obtain the current clock count value W ctr_curr from the dedicated clock;
如果当前的上一时钟计数值Wctr_pre为预设初始值,则更新上一时钟计数值Wctr_pre为当前的时钟计数值Wctr_curr;If the current last clock count value W ctr_pre is a preset initial value, then update the last clock count value W ctr_pre to the current clock count value W ctr_curr ;
如果满足Wctr_curr<Wctr_pre,则将当前的回转次数加一;所述回转次数的初始值为0;If W ctr_curr <W ctr_pre is satisfied, add one to the current number of revolutions; the initial value of the number of revolutions is 0;
按照Wctr_accu=Wctr_curr+N×Wctr_max,计算时钟累积计数Wctr_accu;其中,N为当前的回转次数;更新上一时钟计数值Wctr_pre为当前的时钟计数值Wctr_curr;Wctr_max为所述专用时钟的最大时钟计数值;According to W ctr_accu =W ctr_curr +N×W ctr_max , calculate clock accumulative count W ctr_accu ; wherein, N is the current number of revolutions; updating the last clock count value W ctr_pre is the current clock count value W ctr_curr ; W ctr_max is the The maximum clock count value of the dedicated clock;
将所述时钟累积计数Wctr_accu与所述专用时钟的当前时钟频率相除,得到所述专用时钟的当前计数时间。The clock cumulative count W ctr_accu is divided by the current clock frequency of the dedicated clock to obtain the current counting time of the dedicated clock.
本发明实施例公开了一种音视频播放装置,包括:专用时钟、渲染控制单元和时钟同步单元;其中,The embodiment of the present invention discloses an audio and video playback device, including: a dedicated clock, a rendering control unit, and a clock synchronization unit; wherein,
所述渲染控制单元,用于在音视频播放过程中,基于待渲染数据帧的显示时间戳和相应类型数据的播放流逝时间,进行渲染同步控制,所述播放流逝时间基于播放终端的专用时钟获得;The rendering control unit is used to perform synchronous rendering control based on the display time stamp of the data frame to be rendered and the playback elapsed time of the corresponding type of data during the audio and video playback process, and the playback elapsed time is obtained based on a dedicated clock of the playback terminal ;
所述时钟同步单元,用于在所述音视频播放过程中,基于源端时间对所述专用时钟进行同步调整控制,以匹配源端时间。The clock synchronization unit is configured to perform synchronous adjustment control on the dedicated clock based on the source time during the audio and video playing process, so as to match the source time.
较佳地,所述渲染控制单元,具体用于进行所述渲染同步控制,包括:Preferably, the rendering control unit is specifically configured to perform the rendering synchronization control, including:
当待渲染数据帧到达渲染器时,如果满足Framepts≤STCelapsed≤Framepts+Dmax,则基于当前待渲染数据帧进行渲染;其中,STCelapsed为当前的所述播放流逝时间,Framepts为当前待渲染数据帧的显示时间戳,Dmax为预设的最大允许延迟显示时间;0≤Dmax≤Frameduration;Frameduration为单个数据帧的显示时长;When the data frame to be rendered arrives at the renderer, if Frame pts ≤ STC elapsed ≤ Frame pts + D max is satisfied, rendering is performed based on the current data frame to be rendered; where, STC elapsed is the current elapsed playback time, and Frame pts is The display timestamp of the current data frame to be rendered, D max is the preset maximum allowed delay display time; 0≤D max ≤Frame duration ; Frame duration is the display duration of a single data frame;
如果满足STCelapsed<Framepts,则等待时间△t之后基于当前待渲染数据帧进行渲染,△t=Framepts-STCelapsed;If STC elapsed <Frame pts is satisfied, render based on the current data frame to be rendered after the waiting time △t, △t=Frame pts -STC elapsed ;
如果满足STCelapsed>Framepts+Dmax,则丢弃当前待渲染数据帧。If STC elapsed >Frame pts +D max is satisfied, the current data frame to be rendered is discarded.
较佳地,所述渲染控制单元,具体用于获取所述播放流逝时间,包括:Preferably, the rendering control unit is specifically configured to acquire the elapsed playback time, including:
当所述待渲染数据帧到达渲染器时,获取所述专用时钟当前的计数时间;其中,所述专用时钟的计数时间为单调递增值;When the data frame to be rendered arrives at the renderer, obtain the current counting time of the dedicated clock; wherein, the counting time of the dedicated clock is a monotonically increasing value;
计算所述计数时间与第一初始时间的差值,得到所述播放流逝时间;所述第一初始时间为所述音视频播放的首个数据帧到达渲染器时获取的所述计数时间。Calculate the difference between the counted time and the first initial time to obtain the elapsed playback time; the first initial time is the counted time acquired when the first data frame played by the audio and video arrives at the renderer.
较佳地,所述时钟同步单元,具体用于对所述专用时钟进行同步调整控制,包括:Preferably, the clock synchronization unit is specifically configured to perform synchronous adjustment control on the dedicated clock, including:
在预设的同步调整时刻到达时,获取当前的源端时间SrcTimecurr和所述专用时钟当前的计数时间STCcurr,其中,所述计数时间STCcurr和所述源端时间SrcTimecurr均为单调递增值;When the preset synchronization adjustment time arrives, obtain the current source time SrcTime curr and the current counting time STC curr of the dedicated clock, wherein both the counting time STC curr and the source time SrcTime curr are monotonically increasing value;
计算所述计数时间STCcurr与第二初始时间STCinit的差值,得到第一相对时间STCdiff;计算所述源端时间SrcTimecurr与第三初始时间SrcTimeinit的差值,得到第二相对时间SrcTimediff;其中,所述第二初始时间STCinit为第一个同步调整时刻到达时获取的所述计数时间;所述第三初始时间SrcTimeinit为第一个同步调整时刻到达时获取的所述源端时间;Calculate the difference between the counting time STC curr and the second initial time STC init to obtain the first relative time STC diff ; calculate the difference between the source time SrcTime curr and the third initial time SrcTime init to obtain the second relative time SrcTime diff ; wherein, the second initial time STC init is the counting time obtained when the first synchronization adjustment moment arrives; the third initial time SrcTime init is the count time obtained when the first synchronization adjustment moment arrives source time;
计算所述第一相对时间STCdiff和第二相对时间SrcTimediff的差值,得到所述专用时钟相对于音视频源端时钟的时间误差Timeerror;Calculate the difference between the first relative time STC diff and the second relative time SrcTime diff to obtain the time error Time error of the dedicated clock relative to the audio and video source clock;
如果所述时间误差Timeerror大于预设的最大误差阈值,则按照预设的第一频率微调步长,减小所述专用时钟的输出频率;所述最大误差阈值大于零;If the time error Time error is greater than a preset maximum error threshold, fine-tune the step size according to the preset first frequency to reduce the output frequency of the dedicated clock; the maximum error threshold is greater than zero;
如果所述时间误差Timeerror小于预设的最小误差阈值,则按照预设的第二频率微调步长,增大所述专用时钟的输出频率;所述最小误差阈值小于零。If the time error Time error is smaller than a preset minimum error threshold, fine-tune the step according to a preset second frequency to increase the output frequency of the dedicated clock; the minimum error threshold is smaller than zero.
较佳地,所述装置进一步包括专用计时单元;Preferably, the device further includes a dedicated timing unit;
所述计时单元,用于根据所述渲染控制单元或所述时钟同步单元的时间获取指令,确定所述专用时钟当前的计数时间,并反馈给相应单元;其中,确定所述专用时钟当前的计数时间包括:The timing unit is configured to determine the current counting time of the dedicated clock according to the time acquisition instruction of the rendering control unit or the clock synchronization unit, and feed it back to the corresponding unit; wherein, determine the current counting time of the dedicated clock Time includes:
从所述专用时钟获取当前的时钟计数值Wctr_curr;Obtain the current clock count value W ctr_curr from the dedicated clock;
如果当前的上一时钟计数值Wctr_pre为预设初始值,则更新上一时钟计数值Wctr_pre为当前的时钟计数值Wctr_curr;If the current last clock count value W ctr_pre is a preset initial value, then update the last clock count value W ctr_pre to the current clock count value W ctr_curr ;
如果满足Wctr_curr<Wctr_pre,则将当前的回转次数加一;所述回转次数的初始值为0;If W ctr_curr <W ctr_pre is satisfied, add one to the current number of revolutions; the initial value of the number of revolutions is 0;
按照Wctr_accu=Wctr_curr+N×Wctr_max,计算时钟累积计数Wctr_accu;其中,N为当前的回转次数;更新上一时钟计数值Wctr_pre为当前的时钟计数值Wctr_curr;Wctr_max为所述专用时钟的最大时钟计数值;According to W ctr_accu =W ctr_curr +N×W ctr_max , calculate clock accumulative count W ctr_accu ; wherein, N is the current number of revolutions; updating the last clock count value W ctr_pre is the current clock count value W ctr_curr ; W ctr_max is the The maximum clock count value of the dedicated clock;
将所述时钟累积计数Wctr_accu与所述专用时钟的当前时钟频率相除,得到所述专用时钟的当前计数时间。The clock cumulative count W ctr_accu is divided by the current clock frequency of the dedicated clock to obtain the current counting time of the dedicated clock.
本发明实施例还公开了一种音视频播放设备,包括处理器和存储器;The embodiment of the invention also discloses an audio and video playback device, including a processor and a memory;
所述存储器中存储有可被所述处理器执行的应用程序,用于使得所述处理器执行如上所述的音视频播放方法。An application program that can be executed by the processor is stored in the memory, and is used to make the processor execute the above-mentioned audio and video playing method.
本发明实施例还公开了一种计算机可读存储介质,其中存储有计算机可读指令,该计算机可读指令用于执行如上所述的音视频播放方法。The embodiment of the present invention also discloses a computer-readable storage medium, in which computer-readable instructions are stored, and the computer-readable instructions are used to execute the above-mentioned audio and video playing method.
由上述技术方案可见,本发明实施例提出的音视频播放方案,在音视频播放过程中,基于源端时间对播放终端的专用时钟进行同步调整控制,可以在音视频播放过程中确保播放终端的专用时钟和源端的编码时钟相匹配,并在渲染处理环节,基于待渲染数据帧的显示时间戳、以及基于播放终端的专用时钟获得播放流逝时间,进行渲染同步控制。如此,一方面可以利用与源端时间相匹配的专用时钟,实现平滑播放,另一方面,通过在渲染环节进行同步,可以满足直播等实时性要求高的音视频播放需求。另外,基于源端时间对播放终端的专用时钟进行同步调整控制,可以实现源端时钟与播放端时钟之间的解耦,并且,渲染处理环节对时钟精度的要求低于源端的编码时钟精度要求,允许存在音视频渲染能够容忍的误差,如此,播放端的时钟频率不需要和源端时钟一样高频(如达到1GHz),时钟振荡频率的降低也同时意味着功耗的降低,从而可以降低播放端专用时钟的实现成本和功耗。It can be seen from the above technical solutions that the audio and video playback scheme proposed in the embodiment of the present invention, in the audio and video playback process, the dedicated clock of the playback terminal is synchronously adjusted and controlled based on the source time, which can ensure the playback terminal's time during the audio and video playback process. The dedicated clock matches the encoding clock at the source, and in the rendering process, based on the display timestamp of the data frame to be rendered and the playback elapsed time based on the dedicated clock of the playback terminal, rendering synchronization control is performed. In this way, on the one hand, a dedicated clock that matches the source time can be used to achieve smooth playback. On the other hand, by synchronizing in the rendering process, it can meet the audio and video playback needs with high real-time requirements such as live broadcast. In addition, the synchronous adjustment and control of the dedicated clock of the playback terminal based on the source time can realize the decoupling between the source clock and the playback clock, and the rendering processing link has lower requirements for clock accuracy than the encoding clock accuracy requirements of the source. , allowing for tolerance errors in audio and video rendering. In this way, the clock frequency of the playback end does not need to be as high as the source clock frequency (such as reaching 1GHz), and the reduction of the clock oscillation frequency also means the reduction of power consumption, which can reduce the playback Implementation cost and power consumption of the end-specific clock.
附图说明Description of drawings
图1为本发明实施例的音视频播放方法流程示意图。FIG. 1 is a schematic flowchart of an audio and video playback method according to an embodiment of the present invention.
图2为本发明实施例的专用时钟计数时间的获取方法流程示意图;Fig. 2 is a schematic flow chart of a method for obtaining counting time by a dedicated clock according to an embodiment of the present invention;
图3为本发明实施例的播放终端专用时钟的同步调整控制方法流程示意图;3 is a schematic flow chart of a synchronous adjustment control method for a playback terminal dedicated clock according to an embodiment of the present invention;
图4为本发明实施例的音视频播放装置的结构图。FIG. 4 is a structural diagram of an audio and video playback device according to an embodiment of the present invention.
具体实施方式Detailed ways
为使本发明的目的、技术方案和优点更加清楚,下面将结合附图及具体实施例对本发明作进一步地详细描述。In order to make the purpose, technical solution and advantages of the present invention clearer, the present invention will be further described in detail below in conjunction with the accompanying drawings and specific embodiments.
考虑到广播运营商播放的很多节目具有较强的实时性,而采用常规的在解码阶段利用缓冲方式进行同步处理,一方面会导致音视频播放时延长,无法保障音视频播放的实时性,另一方面也无法保障音视频的平滑性。为此,本申请将在音视频播放的渲染环节,基于用户终端的专用时钟进行渲染控制,并在播放过程中基于源端的源端时间对专用时钟进行周期性地同步调整,如此,可以使得接收端播放音视频的速度和源端生成音视频的速度一致,从而达到音视频能够平滑播放的效果。Considering that many programs played by broadcasting operators have strong real-time performance, and the conventional method of synchronizing with buffering in the decoding stage, on the one hand, the audio and video playback time will be prolonged, and the real-time performance of audio and video playback cannot be guaranteed. On the one hand, the smoothness of audio and video cannot be guaranteed. For this reason, this application will perform rendering control based on the dedicated clock of the user terminal in the rendering link of audio and video playback, and periodically adjust the dedicated clock based on the source time of the source during the playback process. In this way, the receiving The speed at which the audio and video are played on the end is the same as the speed at which the source generates audio and video, so that the audio and video can be played smoothly.
图1为本发明实施例的音视频播放方法流程示意图,如图1所示,该实施例主要包括:Fig. 1 is the schematic flow chart of audio and video playing method of the embodiment of the present invention, as shown in Fig. 1, this embodiment mainly comprises:
步骤101、在音视频播放过程中,播放终端基于待渲染数据帧的显示时间戳和相应类型数据的播放流逝时间,进行渲染同步控制,所述播放流逝时间基于所述播放终端的专用时钟获得。
本步骤中,当播放终端启动音视频播放过程后,将对经过解复用和音视频解码器处理后进入渲染环节的每个数据帧,进行渲染同步控制,以达到平滑播放的效果。In this step, after the playback terminal starts the audio and video playback process, it will perform synchronous rendering control on each data frame that enters the rendering link after demultiplexing and audio and video decoder processing, so as to achieve a smooth playback effect.
这里,相比于传统的在解码环节采用的缓存同步方法,采用渲染环节的同步控制,一方面可以满足音视频播放的实时性,另一方面还可以实现音视频播放的平滑效果。Here, compared with the traditional cache synchronization method used in the decoding link, the synchronization control of the rendering link can satisfy the real-time performance of audio and video playback on the one hand, and achieve smooth audio and video playback on the other hand.
所述播放流逝时间用于表征:在音视频播放过程中,自首个音频帧或视频频到达播放终端的渲染器进行渲染处理之后,基于专用时钟的时间所记录的相应类型数据的播放时长。The playback elapsed time is used to represent: in the audio and video playback process, after the first audio frame or video arrives at the renderer of the playback terminal for rendering processing, the playback duration of the corresponding type of data recorded based on the time of the dedicated clock.
较佳地,在一种具体实施方式中,可以采用下述方法获取所述播放流逝时间:Preferably, in a specific implementation manner, the following method may be used to obtain the playback elapsed time:
当所述待渲染数据帧到达渲染器时,获取所述专用时钟当前的计数时间;其中,所述专用时钟的计数时间为单调递增值;计算所述计数时间与第一初始时间的差值,得到所述播放流逝时间。When the data frame to be rendered arrives at the renderer, obtain the current counting time of the dedicated clock; wherein, the counting time of the dedicated clock is a monotonically increasing value; calculate the difference between the counting time and the first initial time, Obtain the playback elapsed time.
所述第一初始时间为在所述音视频播放过程中,与所述待渲染数据帧相同类型的首个数据帧到达渲染器时所获取的所述计数时间。这样,播放流逝时间的初始值为零。由于专用时钟的计数时间为递增时间值,故,播放流逝时间为从零开始递增的时间。The first initial time is the count time obtained when the first data frame of the same type as the data frame to be rendered arrives at the renderer during the audio and video playback. Thus, the initial value of the playback elapsed time is zero. Since the counting time of the dedicated clock is an incremental time value, the playback elapsed time is a time incremented from zero.
较佳地,在一种实施方式中,为了准确获得专用时钟的计数时间,如图2所示,可以采用下述方法获取该计数时间:Preferably, in one embodiment, in order to accurately obtain the counting time of the dedicated clock, as shown in Figure 2, the following method can be used to obtain the counting time:
步骤a1、从播放终端的专用时钟中获取当前的时钟计数值Wctr_curr。Step a1. Obtain the current clock count value W ctr_curr from the dedicated clock of the playback terminal.
这里需要说明的是,本步骤中的专用时钟通过由硬件产生脉冲并计数,计数值除以频率值即可得到相应的计数时间。时钟硬件一般使用有限的寄存器位数来存储时钟计数。假设寄存器位数为M,时钟频率为ClockFreq,那么可以表示的最大时间为(2M-1)/ClockFreq,达到最大值就会回转重新从0开始,例如,以寄存器33位,90KHz为例,最大值为(233-1)/90000,约95,443秒,26.5小时。为了使得专用时钟的计数时间是单调递增的,在进行计数时间时需要处理上述回转情况,即在进行计数时间时需要考虑回转次数。It should be noted here that the dedicated clock in this step generates pulses and counts through hardware, and the corresponding counting time can be obtained by dividing the counted value by the frequency value. Clock hardware typically uses a limited number of register bits to store clock counts. Assuming that the number of registers is M and the clock frequency is Clock Freq , then the maximum time that can be expressed is (2 M -1)/Clock Freq , and when the maximum value is reached, it will turn around and start from 0 again. For example, a register with 33 bits and 90KHz is For example, the maximum value is (2 33 -1)/90000, about 95,443 seconds, 26.5 hours. In order to make the counting time of the special clock increase monotonically, the above-mentioned rotation situation needs to be dealt with when counting the time, that is, the number of rotations needs to be considered when counting the time.
步骤a2、如果当前的上一时钟计数值Wctr_pre为预设初始值,则更新上一时钟计数值Wctr_pre为当前的时钟计数值Wctr_curr。Step a2. If the current previous clock count value W ctr_pre is a preset initial value, update the previous clock count value W ctr_pre to the current clock count value W ctr_curr .
本步骤,用于在首次获取计数时间时,将上一时钟计数值Wctr_pre更新为当前的时钟计数值Wctr_curr。This step is used to update the previous clock count value W ctr_pre to the current clock count value W ctr_curr when the count time is acquired for the first time.
具体地,所述Wctr_pre的初始值可由本领域技术人员根据实际需要设置,例如可以是零,但不限于此。Specifically, the initial value of W ctr_pre can be set by those skilled in the art according to actual needs, for example, it can be zero, but it is not limited thereto.
步骤a3、如果满足Wctr_curr<Wctr_pre,则将当前的回转次数加一。Step a3. If W ctr_curr <W ctr_pre is satisfied, add one to the current number of revolutions.
所述回转次数的初始值为0。The initial value of the number of revolutions is 0.
这里,如果Wctr_curr<Wctr_pre,则说明当前发生了计数回转,故需要对回转次数加一。Here, if W ctr_curr < W ctr_pre , it means that a counting rotation has occurred currently, so it is necessary to add one to the number of rotations.
步骤a4、按照Wctr_accu=Wctr_curr+N×Wctr_max,计算时钟累积计数Wctr_accu。Step a4 , according to W ctr_accu =W ctr_curr +N×W ctr_max , calculate clock accumulation count W ctr_accu .
其中,N为当前的回转次数;更新上一时钟计数值Wctr_pre为当前的时钟计数值Wctr_curr;Wctr_max为所述专用时钟的最大时钟计数值。Wherein, N is the current number of revolutions; the updated previous clock count value W ctr_pre is the current clock count value W ctr_curr ; W ctr_max is the maximum clock count value of the dedicated clock.
这里,在计算时钟累积计数Wctr_accu时,考虑了当前的回转次数,因此,可以保障专用时钟的计数时间是单调递增的。Here, when calculating the accumulated clock count W ctr_accu , the current number of revolutions is taken into account, so it can be guaranteed that the counting time of the dedicated clock is monotonically increasing.
步骤a5、将所述时钟累积计数Wctr_accu与所述专用时钟的当前时钟频率相除,得到所述专用时钟的当前计数时间。Step a5: Divide the clock cumulative count W ctr_accu by the current clock frequency of the dedicated clock to obtain the current counting time of the dedicated clock.
所述数据帧的显示时间戳(Presentation Time Stamp,PTS)具体可以采用现有的计算方法,即按照Framepts=(n-1)×Frameduration,计算得到数据帧的显示时间戳Framepts,n为音频数据帧或视频数据帧的编号,该编号是同类型数据帧的编号,即表示第n个音频数据帧或第n个视频数据帧。以视频帧数据为例,第一视频帧的显示时间戳为0,后续视频帧通过Frameduration进行累加。比如,对于60fps的视频,Frameduration为16.667ms,第一视频帧的Framepts为0ms,第二视频帧Framepts为16.667ms,第N帧Frame_pts为(N-1)×16.667ms,因此,Framepts是一个从0递增的时间数值。这样,可以通过将显示时间戳Framepts和同样从零开始递增的播放流逝时间相比较,获知待渲染数据帧到达渲染器的时机是否和播放速度相匹配。The presentation time stamp (Presentation Time Stamp, PTS) of the data frame can specifically adopt the existing calculation method, that is, calculate the presentation time stamp Frame pts of the data frame according to Frame pts = (n-1) × Frame duration , n is the number of the audio data frame or the video data frame, and the number is the number of the same type of data frame, which means the nth audio data frame or the nth video data frame. Taking video frame data as an example, the display timestamp of the first video frame is 0, and subsequent video frames are accumulated through Frame duration . For example, for a 60fps video, the Frame duration is 16.667ms, the Frame pts of the first video frame is 0ms, the Frame pts of the second video frame is 16.667ms, and the Nth frame Frame_pts is (N-1)×16.667ms, therefore, Frame pts is a time value incrementing from 0. In this way, by comparing the display time stamp Frame pts with the playback elapsed time that also increments from zero, it can be known whether the time when the data frame to be rendered arrives at the renderer matches the playback speed.
具体地,步骤101中将待渲染数据帧的显示时间戳与相应类型数据的播放流逝时间相比较,根据比较结果来进行渲染同步控制。Specifically, in
为了获得较好的平滑播放效果,在一种实施方式中,可以采用下述方法进行渲染同步控制:In order to obtain a better smooth playback effect, in an implementation manner, the following method may be used for rendering synchronization control:
当待渲染数据帧到达渲染器时,如果满足Framepts≤STCelapsed≤Framepts+Dmax,则基于当前待渲染数据帧进行渲染;其中,STCelapsed为当前的所述播放流逝时间,Framepts为当前待渲染数据帧的显示时间戳,Dmax为预设的最大允许延迟显示时间;0≤Dmax≤Frameduration;Frameduration为单个数据帧的显示时长;When the data frame to be rendered arrives at the renderer, if Frame pts ≤ STC elapsed ≤ Frame pts + D max is satisfied, rendering is performed based on the current data frame to be rendered; where, STC elapsed is the current elapsed playback time, and Frame pts is The display timestamp of the current data frame to be rendered, D max is the preset maximum allowed delay display time; 0≤D max ≤Frame duration ; Frame duration is the display duration of a single data frame;
如果满足STCelapsed<Framepts,则等待时间△t之后基于当前待渲染数据帧进行渲染,△t=Framepts-STCelapsed;If STC elapsed <Frame pts is satisfied, render based on the current data frame to be rendered after the waiting time △t, △t=Frame pts -STC elapsed ;
如果满足STCelapsed>Framepts+Dmax,则丢弃当前待渲染数据帧。If STC elapsed >Frame pts +D max is satisfied, the current data frame to be rendered is discarded.
利用上述方法可以分别实现对音频帧数据的平滑播放,以及对视频帧数据的平滑播放。其中,如果满足Framepts≤STCelapsed≤Framepts+Dmax,说明当前时刻满足平滑播放的要求,正适合对待渲染数据帧进行渲染,因此,将立即基于当前待渲染数据帧进行渲染。Using the method above, the smooth playback of audio frame data and the smooth playback of video frame data can be realized respectively. Among them, if Frame pts ≤ STC elapsed ≤ Frame pts +D max is satisfied, it means that the current moment meets the requirements of smooth playback and is suitable for rendering the data frame to be rendered. Therefore, rendering will be performed based on the current data frame to be rendered immediately.
所述Dmax满足:0≤Dmax≤Frameduration,具体可由本领域技术人员根据实际的平滑要求设置Dmax的合适取值,较佳地,为了在满足画面平滑显示的同时减少对数据帧的丢弃,可以设置Dmax=Frameduration。The D max satisfies: 0 ≤ D max ≤ Frame duration . Specifically, those skilled in the art can set an appropriate value of D max according to the actual smoothing requirements. Preferably, in order to meet the smooth display of the screen while reducing the impact on the data frame For discarding, D max =Frame duration can be set.
如果满足STCelapsed<Framepts,则说明当前待渲染数据帧早于平滑播放的速度到达渲染器,所以需要等待一定间隔(即Framepts-STCelapsed)之后,才能基于当前待渲染数据帧进行渲染,以达到平滑播放的效果。If STC elapsed < Frame pts is satisfied, it means that the current data frame to be rendered reaches the renderer earlier than the speed of smooth playback, so it is necessary to wait for a certain interval (ie Frame pts -STC elapsed ) before rendering based on the current data frame to be rendered. In order to achieve the effect of smooth playback.
如果满足STCelapsed>Framepts+Dmax,则说明当前待渲染数据帧晚于平滑播放的速度到达渲染器,这样,当前待渲染数据帧错过了满足平滑播放要求时所对应的播放时刻,因此,需要丢弃当前待渲染数据帧。If STC elapsed >Frame pts +D max is satisfied, it means that the current data frame to be rendered arrives at the renderer later than the speed of smooth playback. In this way, the current data frame to be rendered has missed the playback moment corresponding to the smooth playback requirement. Therefore, The current data frame to be rendered needs to be discarded.
上述方法中,以Framepts≤STCelapsed≤Framepts+Dmax为当前适合立即渲染的时机,使得播放终端的专用时钟与源端时钟之间允许有一定可容忍的误差,而不需要与源端编码时钟精度完全一致,精度达到毫秒及以上精度,也即时钟频率大于等于1KHz,即可实现平滑的音视频播放,从而可以降低专用时钟的精度要求,进而降低专用时钟的功耗和生产成本,提高了方法的可应用性。In the above method, Frame pts ≤ STC elapsed ≤ Frame pts + D max is currently suitable for immediate rendering, so that there is a certain tolerable error between the dedicated clock of the playback terminal and the source clock, and there is no need to communicate with the source The accuracy of the encoding clock is exactly the same, and the accuracy reaches milliseconds and above, that is, the clock frequency is greater than or equal to 1KHz, and smooth audio and video playback can be realized, which can reduce the accuracy requirements of the dedicated clock, thereby reducing the power consumption and production cost of the dedicated clock. The applicability of the method is improved.
步骤102、在所述音视频播放过程中,所述播放终端基于源端时间对所述专用时钟进行同步调整控制,以匹配源端时间。
本步骤,为了保障上述步骤101中基于播放终端的专用时钟进行渲染同步控制的准确性,在音视频播放过程中,基于源端时间对所述专用时钟进行同步调整控制,以匹配源端时间,即实现专用时钟与音视频源端的编码时钟相匹配。In this step, in order to ensure the accuracy of rendering synchronization control based on the dedicated clock of the playback terminal in the
这里,由于播放终端的专用时钟是在渲染环节进行同步的参考时钟,而每个数据帧有一定的显示时长,使得数据帧的播放时刻具有一定的可容忍的浮动范围,这样,对播放终端的专用时钟的精度要求不需要像源端的编码时钟一样具有很高精度要求,只需要确保专用时钟与源端时钟之间的时间误差不影响人眼观看体验即可,因此,通过在渲染环节利用播放终端的专用时钟进行同步调整,并在播放过程中对该专用时钟进行同步调整控制,以使专用时钟与源端时钟相匹配,可以实现播放终端和源端时钟的解耦,进而可以降低播放终端专用时钟的实现成本。Here, since the dedicated clock of the playback terminal is a reference clock for synchronization in the rendering process, and each data frame has a certain display duration, the playback time of the data frame has a certain tolerable floating range. The precision requirements of the dedicated clock do not need to be as high-precision as the encoding clock at the source. It is only necessary to ensure that the time error between the dedicated clock and the source clock does not affect the viewing experience of the human eye. Therefore, by using playback in the rendering link The dedicated clock of the terminal is adjusted synchronously, and the dedicated clock is adjusted and controlled synchronously during the playback process, so that the dedicated clock matches the source clock, which can realize the decoupling of the playback terminal and the source clock, thereby reducing the cost of the playback terminal. Implementation cost of a dedicated clock.
较佳地,为了使得专用时钟能够与源端时钟较好地同步,在一种实施方式中,如图3所示,可以采用下述方法定时地对播放终端的专用时钟进行同步调整控制:Preferably, in order to enable the dedicated clock to be better synchronized with the source clock, in one embodiment, as shown in Figure 3, the following method can be used to periodically adjust and control the dedicated clock of the playback terminal:
步骤1021、在预设的同步调整时刻到达时,所述播放终端获取当前的源端时间SrcTimecurr和所述专用时钟当前的计数时间STCcurr。
其中,所述计数时间STCcurr和所述源端时间SrcTimecurr均为单调递增值,以使得后续步骤基于这两个参数分别计算出的相对时间也均为递增值。Wherein, both the counting time STC curr and the source time SrcTime curr are monotonically increasing values, so that the relative times calculated in subsequent steps based on these two parameters are also increasing values.
本步骤中,在每个同步调整时刻到达时,需要同时获取当前的源端时间SrcTimecurr和专用时钟当前的计数时间,以便在后续步骤中进一步基于当前获得的这两个时间,确定出当前专用时钟相对于音视频源端时钟的时间误差,进而根据该时间误差确定是否需要对专用时钟进行同步调整,以使专用时钟的时间与源端时间相匹配。In this step, when each synchronization adjustment time arrives, it is necessary to obtain the current source time SrcTime curr and the current counting time of the dedicated clock at the same time, so that the current dedicated clock can be further determined based on the two currently obtained times in subsequent steps. The time error of the clock relative to the clock of the audio and video source end, and then determine whether the dedicated clock needs to be adjusted synchronously according to the time error, so that the time of the dedicated clock matches the time of the source end.
在实际应用中,本领域技术人员可以根据实际的定时调整策略设置同步调整时刻,比如,可以按照预设的同步调整周期确定同步调整时刻。对于该同步调整周期,若设置太久,无法满足同步调整的及时性,若设置太短,则会产生太多的控制开销,具体可由本领域技术人员考虑实际的专用时钟与源端时钟的误差时间累积速率,按照满足同步调整及时性的同时,尽量减少控制开销的策略,设置合适的周期长度,如10s,但不限于此。In practical applications, those skilled in the art can set the synchronization adjustment time according to the actual timing adjustment strategy, for example, the synchronization adjustment time can be determined according to the preset synchronization adjustment cycle. For the synchronization adjustment period, if the setting is too long, the timeliness of the synchronization adjustment cannot be satisfied; if the setting is too short, too much control overhead will be generated. Specifically, the error between the actual dedicated clock and the source clock can be considered by those skilled in the art The time accumulation rate, according to the strategy of minimizing the control overhead while satisfying the timeliness of synchronization adjustment, sets an appropriate cycle length, such as 10s, but not limited to this.
这里,对于专用时钟当前的计数时间,可以采用与上述步骤101中相同的方法获取,在此不再赘述。Here, the current counting time of the dedicated clock can be obtained by the same method as that in
需要说明的是,所述源端时间将由源端定时发送给播放终端,这样,播放终端可以从源端信号中解析得到所述源端时间。It should be noted that the source time will be sent to the playback terminal at regular intervals by the source, so that the playback terminal can obtain the source time by parsing the source signal.
步骤1022、计算所述计数时间STCcurr与第二初始时间STCinit的差值,得到第一相对时间STCdiff;计算所述源端时间SrcTimecurr与第三初始时间SrcTimeinit的差值,得到第二相对时间SrcTimediff。Step 1022: Calculate the difference between the counting time STC curr and the second initial time STC init to obtain the first relative time STC diff ; calculate the difference between the source time SrcTime curr and the third initial time SrcTime init to obtain the first relative time STC diff Two relative time SrcTime diff .
其中,所述第二初始时间STCinit为第一个同步调整时刻到达时获取的所述计数时间;所述第三初始时间SrcTimeinit为第一个同步调整时刻到达时获取的所述源端时间。Wherein, the second initial time STC init is the counting time obtained when the first synchronization adjustment moment arrives; the third initial time SrcTime init is the source time obtained when the first synchronization adjustment moment arrives .
本步骤中,第一相对时间STCdiff表示当前获取的专用时钟的计数时间与第一个同步调整时刻到达时获取的计数时间之间的时间间隔,第二相对时间SrcTimediff表示当前获取的源端时间与第一个同步调整时刻到达时获取的源端时间之间的时间间隔。第一相对时间和第二相对时间的差值可以反映出专用时钟是否与源端时钟相匹配。In this step, the first relative time STC diff represents the time interval between the currently obtained counting time of the dedicated clock and the counting time obtained when the first synchronization adjustment moment arrives, and the second relative time SrcTime diff represents the currently obtained source The time interval between the time and the source time obtained when the first synchronization adjustment moment arrives. The difference between the first relative time and the second relative time may reflect whether the dedicated clock matches the source clock.
步骤1023、计算所述第一相对时间STCdiff和第二相对时间SrcTimediff的差值,得到所述专用时钟相对于音视频源端时钟的时间误差Timeerror。
这里,如果专用时钟与源端时钟相匹配,则第一相对时间和第二相对时间的差值(即时间误差Timeerror)会较小,反之,两者的差值会很大。Here, if the dedicated clock matches the source clock, the difference between the first relative time and the second relative time (that is, the time error Time error ) will be small; otherwise, the difference between the two will be large.
步骤1024、如果所述时间误差Timeerror大于预设的最大误差阈值,则按照预设的第一频率微调步长,减小所述专用时钟的输出频率;所述最大误差阈值大于零;
如果所述时间误差Timeerror小于预设的最小误差阈值,则按照预设的第二频率微调步长,增大所述专用时钟的输出频率;所述最小误差阈值小于零。If the time error Time error is smaller than a preset minimum error threshold, fine-tune the step according to a preset second frequency to increase the output frequency of the dedicated clock; the minimum error threshold is smaller than zero.
这里,如果时间误差Timeerror大于预设的最大误差阈值,且该最大误差阈值大于零,说明专用时钟相对于源端时钟较快,此时,需要减少专用时钟的输出频率,使得专用时钟计时减缓,以使专用时钟与源端时钟相匹配。如果时间误差Timeerror小于预设的最小误差阈值,用该最小误差阈值小于零,则说明专用时钟相对于源端时钟较慢,此时,需要增大专用时钟的输出频率,使得专用时钟计时加快,以使专用时钟与源端时钟相匹配。如果时间误差Timeerror在所述最小误差阈值和所述最大误差阈值之间时,则说明当前专用时钟与源端时钟相匹配,不需要对专用时钟的频率进行调整。Here, if the time error Time error is greater than the preset maximum error threshold, and the maximum error threshold is greater than zero, it means that the dedicated clock is faster than the source clock. At this time, the output frequency of the dedicated clock needs to be reduced to slow down the timing of the dedicated clock. , so that the dedicated clock matches the source clock. If the time error Time error is less than the preset minimum error threshold, and the minimum error threshold is less than zero, it means that the dedicated clock is slower than the source clock. At this time, the output frequency of the dedicated clock needs to be increased to speed up the timing of the dedicated clock. , so that the dedicated clock matches the source clock. If the time error Time error is between the minimum error threshold and the maximum error threshold, it means that the current dedicated clock matches the source clock, and the frequency of the dedicated clock does not need to be adjusted.
具体地,所述第一频率微调步长用于控制每次对所述专用时钟的输出频率减小的幅度,所述第二频率微调步长用于控制每次对所述专用时钟的输出频率增大的幅度,具体地,本领域技术人员可以根据实际调整的收敛速度需求,设置所述第一频率微调步长和所述第二频率微调步长的取值。Specifically, the first frequency fine-tuning step is used to control the magnitude of the reduction of the output frequency of the dedicated clock each time, and the second frequency fine-tuning step is used to control the output frequency of the dedicated clock each time The magnitude of the increase, specifically, those skilled in the art can set the values of the first frequency fine-tuning step size and the second frequency fine-tuning step size according to the actual adjusted convergence speed requirements.
对于所述最小误差阈值和最大误差阈值,本领域技术人员可以根据实际应用中对专用时钟与源端时钟的匹配程度要求进行设置。较佳地,所最小误差阈值和最大误差阈值的绝对值相同,但不限于此。As for the minimum error threshold and the maximum error threshold, those skilled in the art can set them according to the matching degree requirements of the dedicated clock and the source clock in practical applications. Preferably, the minimum error threshold and the maximum error threshold have the same absolute value, but not limited thereto.
由上述方法实施例可以看出,上述音视频播放方法在音视频播放过程中,基于源端时间对播放终端的专用时钟进行同步调整控制,可以确保播放终端的专用时钟和源端的编码时钟相匹配,并在渲染处理环节,基于待渲染数据帧的显示时间戳、以及基于播放终端的专用时钟获得相应类型数据的播放流逝时间,进行渲染同步控制。如此,一方面可以利用与源端时间相匹配的专用时钟,实现平滑播放,另一方面,通过在渲染环节进行同步,可以满足直播等实时性要求高的音视频播放需求。另外,基于源端时间对播放终端的专用时钟进行同步调整控制,可以实现源端时钟与播放端时钟之间的解耦,并且,渲染处理环节对时钟精度的要求低于源端的编码时钟精度要求,允许存在音视频渲染能够容忍的误差,如此,播放端的时钟频率不需要和源端时钟一样高频,从而可以降低播放端专用时钟的实现成本和功耗。It can be seen from the above method embodiments that the above audio and video playback method performs synchronous adjustment and control on the dedicated clock of the playback terminal based on the source end time during the audio and video playback process, so as to ensure that the dedicated clock of the playback terminal matches the encoding clock of the source end , and in the rendering process, based on the display time stamp of the data frame to be rendered and the playback elapsed time of the corresponding type of data obtained based on the dedicated clock of the playback terminal, the rendering synchronization control is performed. In this way, on the one hand, a dedicated clock that matches the source time can be used to achieve smooth playback. On the other hand, by synchronizing in the rendering process, it can meet the audio and video playback needs with high real-time requirements such as live broadcast. In addition, the synchronous adjustment and control of the dedicated clock of the playback terminal based on the source time can realize the decoupling between the source clock and the playback clock, and the rendering processing link has lower requirements for clock accuracy than the encoding clock accuracy requirements of the source. , tolerable errors in audio and video rendering are allowed. In this way, the clock frequency of the playback end does not need to be as high as the source clock, thereby reducing the implementation cost and power consumption of the dedicated clock at the playback end.
与上述音视频播放方法实施例相对应,本发明实施例还公开了一种音视频播放装置,如图4所示,该装置至少包括:渲染控制单元401、专用时钟402和时钟同步单元403;其中,Corresponding to the embodiment of the above audio and video playback method, the embodiment of the present invention also discloses an audio and video playback device, as shown in FIG. 4 , the device at least includes: a
所述渲染控制单元401,用于在音视频播放过程中,基于待渲染数据帧的显示时间戳和相应类型数据的播放流逝时间,进行渲染同步控制,所述播放流逝时间基于播放终端的专用时钟获得。The
所述时钟同步单元403,用于在所述音视频播放过程中,基于源端时间对所述专用时钟进行同步调整控制,以匹配源端时间。The
在一种实施方式中,所述渲染控制单元401,具体用于进行所述渲染同步控制,包括:In one implementation manner, the
当待渲染数据帧到达渲染器时,如果满足Framepts≤STCelapsed≤Framepts+Dmax,则基于当前待渲染数据帧进行渲染;其中,STCelapsed为当前的所述播放流逝时间,Framepts为当前待渲染数据帧的显示时间戳,Dmax为预设的最大允许延迟显示时间;0≤Dmax≤Frameduration;Frameduration为单个数据帧的显示时长;When the data frame to be rendered arrives at the renderer, if Frame pts ≤ STC elapsed ≤ Frame pts + D max is satisfied, rendering is performed based on the current data frame to be rendered; where, STC elapsed is the current elapsed playback time, and Frame pts is The display timestamp of the current data frame to be rendered, D max is the preset maximum allowed delay display time; 0≤D max ≤Frame duration ; Frame duration is the display duration of a single data frame;
如果满足STCelapsed<Framepts,则等待时间△t之后基于当前待渲染数据帧进行渲染,△t=Framepts-STCelapsed;If STC elapsed <Frame pts is satisfied, render based on the current data frame to be rendered after the waiting time △t, △t=Frame pts -STC elapsed ;
如果满足STCelapsed>Framepts+Dmax,则丢弃当前待渲染数据帧。If STC elapsed >Frame pts +D max is satisfied, the current data frame to be rendered is discarded.
在一种实施方式中,所述渲染控制单元401,具体用于获取所述播放流逝时间,包括:In one implementation manner, the
当所述待渲染数据帧到达渲染器时,获取所述专用时钟当前的计数时间;其中,所述专用时钟的计数时间为单调递增值;When the data frame to be rendered arrives at the renderer, obtain the current counting time of the dedicated clock; wherein, the counting time of the dedicated clock is a monotonically increasing value;
计算所述计数时间与第一初始时间的差值,得到所述播放流逝时间;所述第一初始时间为所述音视频播放的首个数据帧到达渲染器时获取的所述计数时间。Calculate the difference between the counted time and the first initial time to obtain the elapsed playback time; the first initial time is the counted time acquired when the first data frame played by the audio and video arrives at the renderer.
在一种实施方式中,所述时钟同步单元402,具体用于对所述专用时钟进行同步调整控制,包括:In one implementation manner, the
在预设的同步调整时刻到达时,获取当前的源端时间SrcTimecurr和所述专用时钟当前的计数时间STCcurr,其中,所述计数时间STCcurr和所述源端时间SrcTimecurr均为单调递增值;When the preset synchronization adjustment time arrives, obtain the current source time SrcTime curr and the current counting time STC curr of the dedicated clock, wherein both the counting time STC curr and the source time SrcTime curr are monotonically increasing value;
计算所述计数时间STCcurr与第二初始时间STCinit的差值,得到第一相对时间STCdiff;计算所述源端时间SrcTimecurr与第三初始时间SrcTimeinit的差值,得到第二相对时间SrcTimediff;其中,所述第二初始时间STCinit为第一个同步调整时刻到达时获取的所述计数时间;所述第三初始时间SrcTimeinit为第一个同步调整时刻到达时获取的所述源端时间;Calculate the difference between the counting time STC curr and the second initial time STC init to obtain the first relative time STC diff ; calculate the difference between the source time SrcTime curr and the third initial time SrcTime init to obtain the second relative time SrcTime diff ; wherein, the second initial time STC init is the counting time obtained when the first synchronization adjustment moment arrives; the third initial time SrcTime init is the count time obtained when the first synchronization adjustment moment arrives source time;
计算所述第一相对时间STCdiff和第二相对时间SrcTimediff的差值,得到所述专用时钟相对于音视频源端时钟的时间误差Timeerror;Calculate the difference between the first relative time STC diff and the second relative time SrcTime diff to obtain the time error Time error of the dedicated clock relative to the audio and video source clock;
如果所述时间误差Timeerror大于预设的最大误差阈值,则按照预设的第一频率微调步长,减小所述专用时钟的输出频率;所述最大误差阈值大于零;If the time error Time error is greater than a preset maximum error threshold, fine-tune the step size according to the preset first frequency to reduce the output frequency of the dedicated clock; the maximum error threshold is greater than zero;
如果所述时间误差Timeerror小于预设的最小误差阈值,则按照预设的第二频率微调步长,增大所述专用时钟的输出频率;所述最小误差阈值小于零。If the time error Time error is smaller than a preset minimum error threshold, fine-tune the step according to a preset second frequency to increase the output frequency of the dedicated clock; the minimum error threshold is smaller than zero.
在一种实施方式中,所述装置进一步包括专用计时单元404;In one embodiment, the device further includes a
所述计时单元404,用于根据所述渲染控制单元或所述时钟同步单元的时间获取指令,确定所述专用时钟当前的计数时间,并反馈给相应单元;其中,确定所述专用时钟当前的计数时间包括:The
从所述专用时钟获取当前的时钟计数值Wctr_curr;Obtain the current clock count value W ctr_curr from the dedicated clock;
如果当前的上一时钟计数值Wctr_pre为预设初始值,则更新上一时钟计数值Wctr_pre为当前的时钟计数值Wctr_curr;If the current last clock count value W ctr_pre is a preset initial value, then update the last clock count value W ctr_pre to the current clock count value W ctr_curr ;
如果满足Wctr_curr<Wctr_pre,则将当前的回转次数加一;所述回转次数的初始值为0;If W ctr_curr <W ctr_pre is satisfied, add one to the current number of revolutions; the initial value of the number of revolutions is 0;
按照Wctr_accu=Wctr_curr+N×Wctr_max,计算时钟累积计数Wctr_accu;其中,N为当前的回转次数;更新上一时钟计数值Wctr_pre为当前的时钟计数值Wctr_curr;Wctr_max为所述专用时钟的最大时钟计数值;According to W ctr_accu =W ctr_curr +N×W ctr_max , calculate clock accumulative count W ctr_accu ; wherein, N is the current number of revolutions; updating the last clock count value W ctr_pre is the current clock count value W ctr_curr ; W ctr_max is the The maximum clock count value of the dedicated clock;
将所述时钟累积计数Wctr_accu与所述专用时钟的当前时钟频率相除,得到所述专用时钟的当前计数时间。The clock cumulative count W ctr_accu is divided by the current clock frequency of the dedicated clock to obtain the current counting time of the dedicated clock.
与上述音视频播放方法实施例相对应,本发明实施例还公开了一种音视频播放设备,包括处理器和存储器;Corresponding to the above audio and video playback method embodiments, the embodiment of the present invention also discloses an audio and video playback device, including a processor and a memory;
所述存储器中存储有可被所述处理器执行的应用程序,用于使得所述处理器执行如上所述的音视频播放方法。An application program that can be executed by the processor is stored in the memory, and is used to make the processor execute the above-mentioned audio and video playing method.
其中,存储器具体可以实施为电可擦可编程只读存储器(EEPROM)、快闪存储器(Flash memory)、可编程程序只读存储器(PROM)等多种存储介质。处理器可以实施为包括一或多个中央处理器或一或多个现场可编程门阵列,其中现场可编程门阵列集成一或多个中央处理器核。具体地,中央处理器或中央处理器核可以实施为CPU或MCU。Wherein, the memory may specifically be implemented as various storage media such as electrically erasable programmable read-only memory (EEPROM), flash memory (Flash memory), and programmable program read-only memory (PROM). A processor may be implemented to include one or more central processing units or one or more field programmable gate arrays integrating one or more central processing unit cores. Specifically, the central processing unit or central processing unit core may be implemented as a CPU or an MCU.
需要说明的是,上述各流程和各结构图中不是所有的步骤和模块都是必须的,可以根据实际的需要忽略某些步骤或模块。各步骤的执行顺序不是固定的,可以根据需要进行调整。各模块的划分仅仅是为了便于描述采用的功能上的划分,实际实现时,一个模块可以分由多个模块实现,多个模块的功能也可以由同一个模块实现,这些模块可以位于同一个设备中,也可以位于不同的设备中。It should be noted that not all steps and modules in the above-mentioned processes and structure diagrams are necessary, and some steps or modules can be ignored according to actual needs. The execution order of each step is not fixed and can be adjusted as needed. The division of each module is only to facilitate the description of the functional division adopted. In actual implementation, one module can be divided into multiple modules, and the functions of multiple modules can also be realized by the same module. These modules can be located in the same device. , or on a different device.
各实施方式中的硬件模块可以以机械方式或电子方式实现。例如,一个硬件模块可以包括专门设计的永久性电路或逻辑器件(如专用处理器,如FPGA或ASIC)用于完成特定的操作。硬件模块也可以包括由软件临时配置的可编程逻辑器件或电路(如包括通用处理器或其它可编程处理器)用于执行特定操作。至于具体采用机械方式,或是采用专用的永久性电路,或是采用临时配置的电路(如由软件进行配置)来实现硬件模块,可以根据成本和时间上的考虑来决定。The hardware modules in the various embodiments may be implemented mechanically or electronically. For example, a hardware module may include specially designed permanent circuits or logic devices (such as special-purpose processors, such as FPGAs or ASICs) to perform specific operations. Hardware modules may also include programmable logic devices or circuits (eg, including general-purpose processors or other programmable processors) temporarily configured by software to perform particular operations. As for implementing the hardware module in a mechanical way, using a dedicated permanent circuit, or using a temporarily configured circuit (such as configured by software) to realize the hardware module, it can be decided according to cost and time considerations.
本发明实施例还公开了一种计算机可读存储介质,其中存储有计算机可读指令,该计算机可读指令用于执行如上所述的音视频播放方法。The embodiment of the present invention also discloses a computer-readable storage medium, in which computer-readable instructions are stored, and the computer-readable instructions are used to execute the above-mentioned audio and video playing method.
具体地,可以提供配有存储介质的系统或者装置,在该存储介质上存储着实现上述实施例中任一实施方式的功能的软件程序代码,且使该系统或者装置的计算机(或CPU或MPU)读出并执行存储在存储介质中的程序代码。此外,还可以通过基于程序代码的指令使计算机上操作的操作系统等来完成部分或者全部的实际操作。还可以将从存储介质读出的程序代码写到插入计算机内的扩展板中所设置的存储器中或者写到与计算机相连接的扩展单元中设置的存储器中,随后基于程序代码的指令使安装在扩展板或者扩展单元上的CPU等来执行部分和全部实际操作,从而实现上述实施方式中任一实施方式的功能。Specifically, a system or device equipped with a storage medium may be provided, on which the software program code for realizing the functions of any implementation manner in the above-mentioned embodiments is stored, and the computer (or CPU or MPU of the system or device) ) to read and execute the program code stored in the storage medium. In addition, an operating system or the like operated on a computer may also complete part or all of the actual operations through instructions based on program codes. It is also possible to write the program code read from the storage medium into the memory set in the expansion board inserted into the computer or into the memory set in the expansion unit connected to the computer, and then based on the instructions of the program code, the memory installed in the The expansion board or the CPU on the expansion unit executes part or all of the actual operations, so as to realize the functions of any one of the above-mentioned implementation manners.
用于提供程序代码的存储介质实施方式包括软盘、硬盘、磁光盘、光盘(如CD-ROM、CD-R、CD-RW、DVD-ROM、DVD-RAM、DVD-RW、DVD+RW)、磁带、非易失性存储卡和ROM。可选择地,可以由通信网络从服务器计算机或云上下载程序代码。Embodiments of storage media for providing program codes include floppy disks, hard disks, magneto-optical disks, optical disks (such as CD-ROM, CD-R, CD-RW, DVD-ROM, DVD-RAM, DVD-RW, DVD+RW), Tape, non-volatile memory card, and ROM. Alternatively, the program code can be downloaded from a server computer or cloud by a communication network.
在本文中,“示意性”表示“充当实例、例子或说明”,不应将在本文中被描述为“示意性”的任何图示、实施方式解释为一种更优选的或更具优点的技术方案。为使图面简洁,各图中的只示意性地表示出了与本发明相关部分,而并不代表其作为产品的实际结构。另外,以使图面简洁便于理解,在有些图中具有相同结构或功能的部件,仅示意性地绘示了其中的一个,或仅标出了其中的一个。在本文中,“一个”并不表示将本发明相关部分的数量限制为“仅此一个”,并且“一个”不表示排除本发明相关部分的数量“多于一个”的情形。在本文中,“上”、“下”、“前”、“后”、“左”、“右”、“内”、“外”等仅用于表示相关部分之间的相对位置关系,而非限定这些相关部分的绝对位置。In this article, "schematic" means "serving as an example, example or illustration", and any illustration or implementation described as "schematic" should not be interpreted as a more preferred or more advantageous Technical solutions. In order to make the drawings concise, the figures in each figure only schematically show the relevant parts of the present invention, and do not represent the actual structure of the product. In addition, to make the drawings concise and easy to understand, in some drawings, only one of the components having the same structure or function is schematically shown, or only one of them is marked. Herein, "one" does not mean limiting the number of relevant parts of the present invention to "only one", and "one" does not mean excluding the case that the number of relevant parts of the present invention is "more than one". In this article, "upper", "lower", "front", "rear", "left", "right", "inner", "outer", etc. are only used to indicate the relative positional relationship between related parts, and The absolute positions of these relative parts are not limited.
以上所述,仅为本发明的较佳实施例而已,并非用于限定本发明的保护范围。凡在本发明的精神和原则之内,所作的任何修改、等同替换、改进等,均应包含在本发明的保护范围之内。The above descriptions are only preferred embodiments of the present invention, and are not intended to limit the protection scope of the present invention. Any modifications, equivalent replacements, improvements, etc. made within the spirit and principles of the present invention shall be included within the protection scope of the present invention.
Claims (8)
Priority Applications (2)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202110635135.5A CN113382300B (en) | 2021-06-08 | 2021-06-08 | Audio and video playing method and device |
PCT/KR2022/008070 WO2022260423A1 (en) | 2021-06-08 | 2022-06-08 | Audio or video playing method and apparatus |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202110635135.5A CN113382300B (en) | 2021-06-08 | 2021-06-08 | Audio and video playing method and device |
Publications (2)
Publication Number | Publication Date |
---|---|
CN113382300A CN113382300A (en) | 2021-09-10 |
CN113382300B true CN113382300B (en) | 2023-03-21 |
Family
ID=77576258
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN202110635135.5A Active CN113382300B (en) | 2021-06-08 | 2021-06-08 | Audio and video playing method and device |
Country Status (2)
Country | Link |
---|---|
CN (1) | CN113382300B (en) |
WO (1) | WO2022260423A1 (en) |
Families Citing this family (2)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN113382300B (en) * | 2021-06-08 | 2023-03-21 | 三星电子(中国)研发中心 | Audio and video playing method and device |
CN114189737B (en) * | 2021-12-06 | 2024-08-06 | 国微集团(深圳)有限公司 | Digital television rapid channel switching method and digital television |
Family Cites Families (9)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
US8234395B2 (en) * | 2003-07-28 | 2012-07-31 | Sonos, Inc. | System and method for synchronizing operations among a plurality of independently clocked digital data processing devices |
JP5837074B2 (en) * | 2010-09-22 | 2015-12-24 | トムソン ライセンシングThomson Licensing | Method and corresponding apparatus for processing multimedia flows |
CN103747332B (en) * | 2013-12-25 | 2018-08-10 | 乐视致新电子科技(天津)有限公司 | A kind of smoothing processing method and device of video |
GB2536318B (en) * | 2015-09-09 | 2018-02-14 | Imagination Tech Ltd | Synchronising devices |
US10098082B2 (en) * | 2015-12-16 | 2018-10-09 | Sonos, Inc. | Synchronization of content between networked devices |
CN105898504A (en) * | 2016-04-26 | 2016-08-24 | 乐视控股(北京)有限公司 | Audio and video synchronization method and apparatus |
CN108243350B (en) * | 2016-12-26 | 2020-05-05 | 深圳市中兴微电子技术有限公司 | A method and device for synchronous processing of audio and video |
CN107509100A (en) * | 2017-09-15 | 2017-12-22 | 深圳国微技术有限公司 | Audio and video synchronization method, system, computer installation and computer-readable recording medium |
CN113382300B (en) * | 2021-06-08 | 2023-03-21 | 三星电子(中国)研发中心 | Audio and video playing method and device |
-
2021
- 2021-06-08 CN CN202110635135.5A patent/CN113382300B/en active Active
-
2022
- 2022-06-08 WO PCT/KR2022/008070 patent/WO2022260423A1/en not_active Ceased
Also Published As
Publication number | Publication date |
---|---|
CN113382300A (en) | 2021-09-10 |
WO2022260423A1 (en) | 2022-12-15 |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
CN109714634B (en) | Decoding synchronization method, device and equipment for live data stream | |
CN101889451B (en) | System and method for reducing media stream delay by independent decoder clock | |
JP7313445B2 (en) | Dynamic shortening in replacement content playback to help align the end of replacement content with the end of replaced content | |
US7471337B2 (en) | Method of audio-video synchronization | |
US11503366B2 (en) | Dynamic playout of transition frames while transitioning between play out of media streams | |
WO2017067489A1 (en) | Set-top box audio-visual synchronization method, device and storage medium | |
CN110581973B (en) | Data playback method and device, terminal equipment and storage medium | |
US20090116814A1 (en) | Reproducer, portable telephone, and reproducing method | |
CN113382300B (en) | Audio and video playing method and device | |
CN108243350B (en) | A method and device for synchronous processing of audio and video | |
US8655143B2 (en) | Supplementary buffer construction in real-time applications without increasing channel change delay | |
CA2792106C (en) | Method and system for inhibiting audio-video synchronization delay | |
CN101836458A (en) | System and method for starting to present audio and video as soon as possible | |
US10057654B2 (en) | Selection and alignment of video segments for adaptive streaming | |
JP2001094943A (en) | Synchronization method and synchronization device for mpeg decoder | |
CN106331820B (en) | Audio and video synchronization processing method and device | |
US20170078730A1 (en) | Content output device and program | |
CN102413335A (en) | Device and method for manually adjusting program sound and picture synchronization | |
US9742966B2 (en) | Data processing system | |
CN105847990A (en) | Media file playing method and apparatus | |
CN116320573A (en) | Audio and video synchronization method, device and equipment | |
US8331459B2 (en) | Method and apparatus for smooth digital media playback | |
EP0735782A2 (en) | Motion picture play apparatus capable of returning from trick play to normal play | |
KR102769929B1 (en) | Method and apparatus for minimizing initial screen output delay in channel selection of digital broadcasting receiver | |
JP2002281498A (en) | Reception reproducing device |
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 |