diff --git a/src/MediaFile/Stamp.cpp b/src/MediaFile/Stamp.cpp index 57045733..cf89e6e4 100644 --- a/src/MediaFile/Stamp.cpp +++ b/src/MediaFile/Stamp.cpp @@ -49,7 +49,7 @@ void Stamp::revise(uint32_t dts, uint32_t pts, int64_t &dts_out, int64_t &pts_ou //相对时间戳 dts_out = dts - _start_dts; - if(dts_out < _dts_inc){ + if(dts_out < _dts_inc && !_playback){ //本次相对时间戳竟然小于上次? if(dts_out < 0 || _dts_inc - dts_out > 0xFFFF){ //时间戳回环,保证下次相对时间戳与本次相对合理增长 @@ -77,4 +77,8 @@ void Stamp::revise(uint32_t dts, uint32_t pts, int64_t &dts_out, int64_t &pts_ou } } +void Stamp::setPlayBack(bool playback) { + _playback = playback; +} + }//namespace mediakit \ No newline at end of file diff --git a/src/MediaFile/Stamp.h b/src/MediaFile/Stamp.h index 4e6241b1..8616f8a7 100644 --- a/src/MediaFile/Stamp.h +++ b/src/MediaFile/Stamp.h @@ -39,8 +39,23 @@ class Stamp { public: Stamp() = default; ~Stamp() = default; + + /** + * 设置回放模式,回放模式时间戳可以回退 + * @param playback 是否为回放模式 + */ + void setPlayBack(bool playback = true); + + /** + * 修正时间戳 + * @param dts 输入dts,如果为0则根据系统时间戳生成 + * @param pts 输入pts,如果为0则等于dts + * @param dts_out 输出dts + * @param pts_out 输出pts + */ void revise(uint32_t dts, uint32_t pts, int64_t &dts_out, int64_t &pts_out); private: + bool _playback = false; int64_t _start_dts = 0; int64_t _dts_inc = 0; bool _first = true; diff --git a/src/Rtmp/RtmpSession.cpp b/src/Rtmp/RtmpSession.cpp index b1a045b1..024b1c65 100644 --- a/src/Rtmp/RtmpSession.cpp +++ b/src/Rtmp/RtmpSession.cpp @@ -464,6 +464,8 @@ void RtmpSession::onCmd_seek(AMFDecoder &dec) { InfoP(this) << "rtmp seekTo(ms):" << milliSeconds; auto stongSrc = _pPlayerSrc.lock(); if (stongSrc) { + _stamp[0].setPlayBack(); + _stamp[1].setPlayBack(); stongSrc->seekTo(milliSeconds); } AMFValue status(AMF_OBJECT);