From 41c09757a7c710ed4714e860bff1d720f50def6b Mon Sep 17 00:00:00 2001 From: xiongziliang <771730766@qq.com> Date: Sat, 21 Aug 2021 18:52:52 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A7=A3=E5=86=B3GB28181=E6=8E=A8=E6=B5=81?= =?UTF-8?q?=E6=97=A0ntp=E6=97=B6=E9=97=B4=E6=88=B3=E5=AF=BC=E8=87=B4?= =?UTF-8?q?=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Rtp/GB28181Process.cpp | 5 ++++- src/Rtsp/RtpReceiver.cpp | 12 +++++++++--- src/Rtsp/RtpReceiver.h | 2 ++ 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/src/Rtp/GB28181Process.cpp b/src/Rtp/GB28181Process.cpp index c3fb9942..82f7a6f3 100644 --- a/src/Rtp/GB28181Process.cpp +++ b/src/Rtp/GB28181Process.cpp @@ -27,10 +27,13 @@ static inline bool checkTS(const uint8_t *packet, size_t bytes){ class RtpReceiverImp : public RtpTrackImp { public: using Ptr = std::shared_ptr; - RtpReceiverImp(int sample_rate, RtpTrackImp::OnSorted cb, RtpTrackImp::BeforeSorted cb_before = nullptr){ + + RtpReceiverImp(int sample_rate, RtpTrackImp::OnSorted cb, RtpTrackImp::BeforeSorted cb_before = nullptr) { _sample_rate = sample_rate; setOnSorted(std::move(cb)); setBeforeSorted(std::move(cb_before)); + //GB28181推流不支持ntp时间戳 + setNtpStamp(0, 0, 0); } ~RtpReceiverImp() override = default; diff --git a/src/Rtsp/RtpReceiver.cpp b/src/Rtsp/RtpReceiver.cpp index 643cbd9a..635fb117 100644 --- a/src/Rtsp/RtpReceiver.cpp +++ b/src/Rtsp/RtpReceiver.cpp @@ -89,14 +89,20 @@ RtpPacket::Ptr RtpTrack::inputRtp(TrackType type, int sample_rate, uint8_t *ptr, data[3] = len & 0xFF; //拷贝rtp memcpy(&data[4], ptr, len); - //设置ntp时间戳 - rtp->ntp_stamp = _ntp_stamp.getNtpStamp(ntohl(rtp->getHeader()->stamp), sample_rate); + if (_disable_ntp) { + //不支持ntp时间戳,例如国标推流,那么直接使用rtp时间戳 + rtp->ntp_stamp = rtp->getStamp() * uint64_t(1000) / sample_rate; + } else { + //设置ntp时间戳 + rtp->ntp_stamp = _ntp_stamp.getNtpStamp(ntohl(rtp->getHeader()->stamp), sample_rate); + } onBeforeRtpSorted(rtp); sortPacket(rtp->getSeq(), rtp); return rtp; } -void RtpTrack::setNtpStamp(uint32_t rtp_stamp, uint32_t sample_rate, uint64_t ntp_stamp_ms){ +void RtpTrack::setNtpStamp(uint32_t rtp_stamp, uint32_t sample_rate, uint64_t ntp_stamp_ms) { + _disable_ntp = rtp_stamp == 0 && sample_rate == 0 && ntp_stamp_ms == 0; _ntp_stamp.setNtpStamp(rtp_stamp, sample_rate, ntp_stamp_ms); } diff --git a/src/Rtsp/RtpReceiver.h b/src/Rtsp/RtpReceiver.h index 64794376..3862fea2 100644 --- a/src/Rtsp/RtpReceiver.h +++ b/src/Rtsp/RtpReceiver.h @@ -183,6 +183,7 @@ protected: virtual void onBeforeRtpSorted(const RtpPacket::Ptr &rtp) {} private: + bool _disable_ntp = false; uint32_t _ssrc = 0; Ticker _ssrc_alive; NtpStamp _ntp_stamp; @@ -241,6 +242,7 @@ public: /** * 设置ntp时间戳,在收到rtcp sender report时设置 + * 如果rtp_stamp/sample_rate/ntp_stamp_ms都为0,那么采用rtp时间戳为ntp时间戳 * @param index track下标索引 * @param rtp_stamp rtp时间戳 * @param sample_rate 时间戳采样率