From d864e7084be3c1e65a8500fd927a1f31483bef7b Mon Sep 17 00:00:00 2001 From: xiongziliang <771730766@qq.com> Date: Tue, 3 Sep 2019 17:20:56 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8Drtmp=E7=82=B9=E6=92=AD?= =?UTF-8?q?=E7=A7=BB=E5=8A=A8=E6=97=B6=E9=97=B4=E8=BD=B4=E7=9B=B8=E5=85=B3?= =?UTF-8?q?bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/MediaFile/Stamp.cpp | 6 +++++- src/MediaFile/Stamp.h | 15 +++++++++++++++ src/Rtmp/RtmpSession.cpp | 2 ++ 3 files changed, 22 insertions(+), 1 deletion(-) 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);