diff --git a/src/Rtsp/RtspSession.cpp b/src/Rtsp/RtspSession.cpp index f62e66f4..c0b49472 100644 --- a/src/Rtsp/RtspSession.cpp +++ b/src/Rtsp/RtspSession.cpp @@ -913,7 +913,13 @@ inline void RtspSession::send_NotAcceptable() { sendRtspResponse("406 Not Acceptable",{"Connection","Close"}); } -void RtspSession::onRtpSorted(const RtpPacket::Ptr &rtp, int) { +void RtspSession::onRtpSorted(const RtpPacket::Ptr &rtp, int track_idx) { + if (_start_stamp[track_idx] == -1) { + //记录起始时间戳 + _start_stamp[track_idx] = rtp->timeStamp; + } + //时间戳增量 + rtp->timeStamp -= _start_stamp[track_idx]; _push_src->onWrite(rtp, false); } @@ -937,8 +943,7 @@ inline void RtspSession::onRcvPeerUdpData(int interleaved, const Buffer::Ptr &bu _udp_connected_flags.emplace(interleaved); _rtcp_socks[(interleaved - 1) / 2]->setSendPeerAddr(&addr); } - onRtcpPacket((interleaved - 1) / 2, _sdp_track[(interleaved - 1) / 2], (unsigned char *) buf->data(), - buf->size()); + onRtcpPacket((interleaved - 1) / 2, _sdp_track[(interleaved - 1) / 2], (unsigned char *) buf->data(), buf->size()); } } diff --git a/src/Rtsp/RtspSession.h b/src/Rtsp/RtspSession.h index 2436efb6..47e9d5da 100644 --- a/src/Rtsp/RtspSession.h +++ b/src/Rtsp/RtspSession.h @@ -157,6 +157,8 @@ private: Rtsp::eRtpType _rtp_type = Rtsp::RTP_Invalid; //收到的seq,回复时一致 int _cseq = 0; + //rtsp推流起始时间戳,目的是为了同步 + int64_t _start_stamp[2] = {-1, -1}; //消耗的总流量 uint64_t _bytes_usage = 0; //ContentBase