From 08386b958cd40c2aee2cdd13aea7bf63b3fdb41b Mon Sep 17 00:00:00 2001 From: xiongziliang <771730766@qq.com> Date: Sat, 12 Oct 2019 22:44:16 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A6=86=E7=9B=96=E6=97=B6=E9=97=B4=E6=88=B3?= =?UTF-8?q?=E9=9C=80=E8=A6=81=E6=98=8E=E7=A1=AE=E5=8F=82=E6=95=B0=E6=8C=87?= =?UTF-8?q?=E5=AE=9A=EF=BC=8C=E9=98=B2=E6=AD=A2=E8=AF=AF=E5=88=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/MediaFile/Stamp.cpp | 11 ++++------- src/MediaFile/Stamp.h | 3 ++- src/Rtmp/RtmpSession.cpp | 2 +- src/Rtsp/RtspSession.cpp | 2 +- 4 files changed, 8 insertions(+), 10 deletions(-) diff --git a/src/MediaFile/Stamp.cpp b/src/MediaFile/Stamp.cpp index e053c122..ab77a1bf 100644 --- a/src/MediaFile/Stamp.cpp +++ b/src/MediaFile/Stamp.cpp @@ -51,12 +51,9 @@ void DeltaStamp::setPlayBack(bool playback) { _playback = playback; } -void Stamp::revise(int64_t dts, int64_t pts, int64_t &dts_out, int64_t &pts_out) { - if(!dts && !pts){ - //没有时间戳,我们生成时间戳 - pts = dts = _ticker.elapsedTime(); - }else if(!pts){ - //只是没有播放时间戳,使其赋值为解码时间戳 +void Stamp::revise(int64_t dts, int64_t pts, int64_t &dts_out, int64_t &pts_out,bool modifyStamp) { + if(!pts){ + //没有播放时间戳,使其赋值为解码时间戳 pts = dts; } @@ -64,7 +61,7 @@ void Stamp::revise(int64_t dts, int64_t pts, int64_t &dts_out, int64_t &pts_out) int pts_dts_diff = pts - dts; //相对时间戳 - _relativeStamp += deltaStamp(dts); + _relativeStamp += deltaStamp(modifyStamp ? _ticker.elapsedTime() : dts); dts_out = _relativeStamp; //////////////以下是播放时间戳的计算////////////////// diff --git a/src/MediaFile/Stamp.h b/src/MediaFile/Stamp.h index 23a427f3..82458fda 100644 --- a/src/MediaFile/Stamp.h +++ b/src/MediaFile/Stamp.h @@ -67,8 +67,9 @@ public: * @param pts 输入pts,如果为0则等于dts * @param dts_out 输出dts * @param pts_out 输出pts + * @param modifyStamp 是否用系统时间戳覆盖 */ - void revise(int64_t dts, int64_t pts, int64_t &dts_out, int64_t &pts_out); + void revise(int64_t dts, int64_t pts, int64_t &dts_out, int64_t &pts_out,bool modifyStamp = false); /** * 再设置相对时间戳,用于seek用 diff --git a/src/Rtmp/RtmpSession.cpp b/src/Rtmp/RtmpSession.cpp index 3b4a1663..2cd38528 100644 --- a/src/Rtmp/RtmpSession.cpp +++ b/src/Rtmp/RtmpSession.cpp @@ -486,7 +486,7 @@ void RtmpSession::onRtmpChunk(RtmpPacket &chunkData) { GET_CONFIG(bool,rtmp_modify_stamp,Rtmp::kModifyStamp); if(rtmp_modify_stamp){ int64_t dts_out; - _stamp[chunkData.typeId % 2].revise(0, 0, dts_out, dts_out); + _stamp[chunkData.typeId % 2].revise(0, 0, dts_out, dts_out, true); chunkData.timeStamp = dts_out; } if(!_metadata_got && !chunkData.isCfgFrame()){ diff --git a/src/Rtsp/RtspSession.cpp b/src/Rtsp/RtspSession.cpp index aa10aa84..efd0dc7e 100644 --- a/src/Rtsp/RtspSession.cpp +++ b/src/Rtsp/RtspSession.cpp @@ -932,7 +932,7 @@ void RtspSession::onRtpSorted(const RtpPacket::Ptr &rtppt, int trackidx) { GET_CONFIG(bool,modify_stamp,Rtsp::kModifyStamp); if(modify_stamp){ int64_t dts_out; - _stamp[trackidx].revise(0, 0, dts_out, dts_out); + _stamp[trackidx].revise(0, 0, dts_out, dts_out, true); rtppt->timeStamp = dts_out; } _pushSrc->onWrite(rtppt, false);