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);