From 6ddd420f1ce2fa2cdaa8b496de347846c0d6ce9f Mon Sep 17 00:00:00 2001 From: ziyue <1213642868@qq.com> Date: Wed, 14 Jul 2021 21:39:30 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dwebrtc=20rtx=E5=8C=85?= =?UTF-8?q?=E8=AE=A1=E5=85=A5receiver=20report=E7=BB=9F=E8=AE=A1=E5=AF=BC?= =?UTF-8?q?=E8=87=B4simulcast=E6=8E=A8=E6=B5=81=E5=A4=B1=E6=95=88=E7=9A=84?= =?UTF-8?q?=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 | 2 +- src/Rtsp/RtpReceiver.cpp | 19 ++++++++----------- src/Rtsp/RtpReceiver.h | 4 ++-- webrtc/WebRtcTransport.cpp | 19 ++++++------------- 4 files changed, 17 insertions(+), 27 deletions(-) diff --git a/src/Rtp/GB28181Process.cpp b/src/Rtp/GB28181Process.cpp index c4dc8c24..42f004d2 100644 --- a/src/Rtp/GB28181Process.cpp +++ b/src/Rtp/GB28181Process.cpp @@ -36,7 +36,7 @@ public: ~RtpReceiverImp() override = default; bool inputRtp(TrackType type, uint8_t *ptr, size_t len){ - return RtpTrack::inputRtp(type, _sample_rate, ptr, len); + return RtpTrack::inputRtp(type, _sample_rate, ptr, len).operator bool(); } private: diff --git a/src/Rtsp/RtpReceiver.cpp b/src/Rtsp/RtpReceiver.cpp index 29311ef3..64639b8d 100644 --- a/src/Rtsp/RtpReceiver.cpp +++ b/src/Rtsp/RtpReceiver.cpp @@ -31,18 +31,18 @@ void RtpTrack::clear() { PacketSortor::clear(); } -bool RtpTrack::inputRtp(TrackType type, int sample_rate, uint8_t *ptr, size_t len) { +RtpPacket::Ptr RtpTrack::inputRtp(TrackType type, int sample_rate, uint8_t *ptr, size_t len) { if (len < RtpPacket::kRtpHeaderSize) { WarnL << "rtp包太小:" << len; - return false; + return nullptr; } if (len > RTP_MAX_SIZE) { WarnL << "超大的rtp包:" << len << " > " << RTP_MAX_SIZE; - return false; + return nullptr; } if (!sample_rate) { //无法把时间戳转换成毫秒 - return false; + return nullptr; } RtpHeader *header = (RtpHeader *) ptr; if (header->version != RtpPacket::kRtpVersion) { @@ -50,7 +50,7 @@ bool RtpTrack::inputRtp(TrackType type, int sample_rate, uint8_t *ptr, size_t le } if (!header->getPayloadSize(len)) { //无有效负载的rtp包 - return false; + return nullptr; } //比对缓存ssrc @@ -68,7 +68,7 @@ bool RtpTrack::inputRtp(TrackType type, int sample_rate, uint8_t *ptr, size_t le if (_ssrc_alive.elapsedTime() < 3 * 1000) { //接受正确ssrc的rtp在10秒内,那么我们认为存在多路rtp,忽略掉ssrc不匹配的rtp WarnL << "ssrc不匹配,rtp已丢弃:" << ssrc << " != " << _ssrc; - return false; + return nullptr; } InfoL << "rtp流ssrc切换:" << _ssrc << " -> " << ssrc; _ssrc = ssrc; @@ -90,14 +90,11 @@ bool RtpTrack::inputRtp(TrackType type, int sample_rate, uint8_t *ptr, size_t le data[3] = len & 0xFF; //拷贝rtp memcpy(&data[4], ptr, len); - //设置ntp时间戳 rtp->ntp_stamp = _ntp_stamp.getNtpStamp(ntohl(rtp->getHeader()->stamp), sample_rate); - onBeforeRtpSorted(rtp); - auto seq = rtp->getSeq(); - sortPacket(seq, std::move(rtp)); - return true; + sortPacket(rtp->getSeq(), rtp); + return rtp; } void RtpTrack::setNtpStamp(uint32_t rtp_stamp, uint32_t sample_rate, uint64_t ntp_stamp_ms){ diff --git a/src/Rtsp/RtpReceiver.h b/src/Rtsp/RtpReceiver.h index 3097f81d..fda96de6 100644 --- a/src/Rtsp/RtpReceiver.h +++ b/src/Rtsp/RtpReceiver.h @@ -175,7 +175,7 @@ public: void clear(); uint32_t getSSRC() const; - bool inputRtp(TrackType type, int sample_rate, uint8_t *ptr, size_t len); + RtpPacket::Ptr inputRtp(TrackType type, int sample_rate, uint8_t *ptr, size_t len); void setNtpStamp(uint32_t rtp_stamp, uint32_t sample_rate, uint64_t ntp_stamp_ms); protected: @@ -236,7 +236,7 @@ public: * @return 解析成功返回true */ bool handleOneRtp(int index, TrackType type, int sample_rate, uint8_t *ptr, size_t len){ - return _track[index].inputRtp(type, sample_rate, ptr, len); + return _track[index].inputRtp(type, sample_rate, ptr, len).operator bool(); } /** diff --git a/webrtc/WebRtcTransport.cpp b/webrtc/WebRtcTransport.cpp index b15911f8..ac30ab8a 100644 --- a/webrtc/WebRtcTransport.cpp +++ b/webrtc/WebRtcTransport.cpp @@ -594,14 +594,15 @@ public: ~RtpChannel() override = default; - bool inputRtp(TrackType type, int sample_rate, uint8_t *ptr, size_t len, bool is_rtx){ - if (!is_rtx) { - RtpHeader *rtp = (RtpHeader *) ptr; - auto seq = ntohs(rtp->seq); + RtpPacket::Ptr inputRtp(TrackType type, int sample_rate, uint8_t *ptr, size_t len, bool is_rtx) { + auto rtp = RtpTrack::inputRtp(type, sample_rate, ptr, len); + if (!is_rtx && rtp) { //统计rtp接受情况,便于生成nack rtcp包 + auto seq = rtp->getSeq(); _nack_ctx.received(seq); + _rtcp_context.onRtp(seq, rtp->getStamp(), rtp->ntp_stamp, sample_rate, len); } - return RtpTrack::inputRtp(type, sample_rate, ptr, len); + return rtp; } Buffer::Ptr createRtcpRR(RtcpHeader *sr, uint32_t ssrc) { @@ -609,14 +610,6 @@ public: return _rtcp_context.createRtcpRR(ssrc, getSSRC()); } -protected: - void onBeforeRtpSorted(const RtpPacket::Ptr &rtp) override { - //统计rtp收到的情况,好做rr汇报 - _rtcp_context.onRtp(rtp->getSeq(), rtp->getStamp(), rtp->ntp_stamp, rtp->sample_rate, - rtp->size() - RtpPacket::kRtpTcpHeaderSize); - RtpTrackImp::onBeforeRtpSorted(rtp); - } - private: NackContext _nack_ctx; RtcpContext _rtcp_context{true};