From 7865f2c360d7c11a25cd3c8375b977dad6d4381b Mon Sep 17 00:00:00 2001 From: taotaobujue Date: Wed, 15 Nov 2023 11:02:12 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dudp=E5=8D=95=E7=AB=AF?= =?UTF-8?q?=E5=8F=A3=E6=A8=A1=E5=BC=8F=E4=B8=8Brtp=E9=89=B4=E6=9D=83?= =?UTF-8?q?=E5=A4=B1=E8=B4=A5=E5=90=8E=E6=97=A0=E6=B3=95=E5=85=B3=E9=97=AD?= =?UTF-8?q?=E6=B5=81=E7=9A=84=E9=97=AE=E9=A2=98(#2985)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 如果rtp推流鉴权失败,在udp模式下延时断开连接,等待超时自动关闭,防止频繁创建销毁RtpSession对象, tcp模式则立即断开链接。 --- src/Rtp/RtpProcess.cpp | 4 ++++ src/Rtp/RtpProcess.h | 1 + src/Rtp/RtpSession.cpp | 11 +++++++++-- 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/Rtp/RtpProcess.cpp b/src/Rtp/RtpProcess.cpp index 5e61ccf4..3855f411 100644 --- a/src/Rtp/RtpProcess.cpp +++ b/src/Rtp/RtpProcess.cpp @@ -79,6 +79,9 @@ bool RtpProcess::inputRtp(bool is_udp, const Socket::Ptr &sock, const char *data WarnP(this) << "Not rtp packet"; return false; } + if (!_auth_err.empty()) { + throw toolkit::SockException(toolkit::Err_other, _auth_err); + } if (_sock != sock) { // 第一次运行本函数 bool first = !_sock; @@ -260,6 +263,7 @@ void RtpProcess::emitOnPublish() { strong_self->doCachedFunc(); InfoP(strong_self) << "允许RTP推流"; } else { + strong_self->_auth_err = err; WarnP(strong_self) << "禁止RTP推流:" << err; } }); diff --git a/src/Rtp/RtpProcess.h b/src/Rtp/RtpProcess.h index 860be01c..3e87620a 100644 --- a/src/Rtp/RtpProcess.h +++ b/src/Rtp/RtpProcess.h @@ -94,6 +94,7 @@ private: private: bool _only_audio = false; + std::string _auth_err; uint64_t _dts = 0; uint64_t _total_bytes = 0; std::unique_ptr _addr; diff --git a/src/Rtp/RtpSession.cpp b/src/Rtp/RtpSession.cpp index 82f3c72a..70c8dc7a 100644 --- a/src/Rtp/RtpSession.cpp +++ b/src/Rtp/RtpSession.cpp @@ -139,8 +139,15 @@ void RtpSession::onRtpPacket(const char *data, size_t len) { } else { throw; } - } catch (...) { - throw; + } catch (std::exception &ex) { + if (!_is_udp) { + // tcp情况下立即断开连接 + throw; + } + // udp情况下延时断开连接(等待超时自动关闭),防止频繁创建销毁RtpSession对象 + WarnP(this) << ex.what(); + _delay_close = true; + return; } _ticker.resetTime(); }