From 8a51bd2d9e7a9998d6771f87e649928a80f867c0 Mon Sep 17 00:00:00 2001 From: xia-chu <771730766@qq.com> Date: Sun, 11 Apr 2021 20:35:00 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9Ertp=20ssrc=E5=BC=82=E5=B8=B8?= =?UTF-8?q?=E5=A4=84=E7=90=86=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Rtsp/RtpReceiver.cpp | 18 ++++++++++++++---- src/Rtsp/RtpReceiver.h | 1 + 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/src/Rtsp/RtpReceiver.cpp b/src/Rtsp/RtpReceiver.cpp index 711ce9e8..c33c2b5a 100644 --- a/src/Rtsp/RtpReceiver.cpp +++ b/src/Rtsp/RtpReceiver.cpp @@ -53,12 +53,22 @@ bool RtpReceiver::handleOneRtp(int index, TrackType type, int sample_rate, uint8 auto ssrc = ntohl(header->ssrc); if (!_ssrc[index]) { - //保存SSRC至track对象 + //记录并锁定ssrc _ssrc[index] = ssrc; - } else if (_ssrc[index] != ssrc) { + _ssrc_alive[index].resetTime(); + } else if (_ssrc[index] == ssrc) { + //ssrc匹配正确,刷新计时器 + _ssrc_alive[index].resetTime(); + } else { //ssrc错误 - WarnL << "ssrc错误:" << ssrc << " != " << _ssrc[index]; - return false; + if (_ssrc_alive[index].elapsedTime() < 10 * 1000) { + //接受正确ssrc的rtp在10秒内,那么我们认为存在多路rtp,忽略掉ssrc不匹配的rtp + WarnL << "ssrc比匹配,rtp已丢弃:" << ssrc << " != " << _ssrc[index]; + return false; + } + InfoL << "rtp流ssrc切换:" << _ssrc[index] << " -> " << ssrc; + _ssrc[index] = ssrc; + _ssrc_alive[index].resetTime(); } auto rtp = RtpPacket::create(); diff --git a/src/Rtsp/RtpReceiver.h b/src/Rtsp/RtpReceiver.h index 99cba9d3..f8d2fde9 100644 --- a/src/Rtsp/RtpReceiver.h +++ b/src/Rtsp/RtpReceiver.h @@ -198,6 +198,7 @@ protected: private: uint32_t _ssrc[2] = {0, 0}; + Ticker _ssrc_alive[2]; //rtp排序缓存,根据seq排序 PacketSortor _rtp_sortor[2]; };