From c42ee1dc5d4b2aa1db638f5b4a23f80e949892f1 Mon Sep 17 00:00:00 2001 From: xiongziliang <771730766@qq.com> Date: Fri, 29 Nov 2019 09:54:48 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E6=97=B6=E9=97=B4=E6=88=B3?= =?UTF-8?q?=E8=A6=86=E7=9B=96=E9=80=BB=E8=BE=91:#148?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/MediaFile/Stamp.cpp | 7 +++++-- src/MediaFile/Stamp.h | 1 + src/Rtmp/RtmpSession.cpp | 2 +- src/Rtsp/RtspSession.cpp | 2 +- 4 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/MediaFile/Stamp.cpp b/src/MediaFile/Stamp.cpp index ab77a1bf..4474fe45 100644 --- a/src/MediaFile/Stamp.cpp +++ b/src/MediaFile/Stamp.cpp @@ -60,8 +60,11 @@ void Stamp::revise(int64_t dts, int64_t pts, int64_t &dts_out, int64_t &pts_out, //pts和dts的差值 int pts_dts_diff = pts - dts; - //相对时间戳 - _relativeStamp += deltaStamp(modifyStamp ? _ticker.elapsedTime() : dts); + if(_last_dts != dts){ + //时间戳发生变更 + _relativeStamp += deltaStamp(modifyStamp ? _ticker.elapsedTime() : dts); + _last_dts = dts; + } dts_out = _relativeStamp; //////////////以下是播放时间戳的计算////////////////// diff --git a/src/MediaFile/Stamp.h b/src/MediaFile/Stamp.h index 82458fda..09e77338 100644 --- a/src/MediaFile/Stamp.h +++ b/src/MediaFile/Stamp.h @@ -84,6 +84,7 @@ public: int64_t getRelativeStamp() const ; private: int64_t _relativeStamp = 0; + int64_t _last_dts = -1; SmoothTicker _ticker; }; diff --git a/src/Rtmp/RtmpSession.cpp b/src/Rtmp/RtmpSession.cpp index e946d275..671ff101 100644 --- a/src/Rtmp/RtmpSession.cpp +++ b/src/Rtmp/RtmpSession.cpp @@ -493,7 +493,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, true); + _stamp[chunkData.typeId % 2].revise(chunkData.timeStamp, chunkData.timeStamp, 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 c06e204a..cb138308 100644 --- a/src/Rtsp/RtspSession.cpp +++ b/src/Rtsp/RtspSession.cpp @@ -940,7 +940,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, true); + _stamp[trackidx].revise(rtppt->timeStamp, rtppt->timeStamp, dts_out, dts_out, true); rtppt->timeStamp = dts_out; } _pushSrc->onWrite(rtppt, false);