From 00f01afec7736125f7e19efb16b3e98970d5c0dc Mon Sep 17 00:00:00 2001 From: ziyue <1213642868@qq.com> Date: Fri, 24 Sep 2021 11:29:04 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dwebrtc=E7=9B=B8=E5=85=B3?= =?UTF-8?q?=E6=BC=8F=E6=B4=9E:#1110?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- webrtc/WebRtcTransport.cpp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/webrtc/WebRtcTransport.cpp b/webrtc/WebRtcTransport.cpp index daaf1f76..10ee5ad6 100644 --- a/webrtc/WebRtcTransport.cpp +++ b/webrtc/WebRtcTransport.cpp @@ -243,6 +243,10 @@ bool is_rtcp(char *buf) { return ((header->pt >= 64) && (header->pt < 96)); } +static string getPeerAddress(RTC::TransportTuple *tuple){ + return SockUtil::inet_ntoa(((struct sockaddr_in *)tuple)->sin_addr) + ":" + to_string(ntohs(((struct sockaddr_in *)tuple)->sin_port)); +} + void WebRtcTransport::inputSockData(char *buf, int len, RTC::TransportTuple *tuple) { if (RTC::StunPacket::IsStun((const uint8_t *) buf, len)) { std::unique_ptr packet(RTC::StunPacket::Parse((const uint8_t *) buf, len)); @@ -258,12 +262,20 @@ void WebRtcTransport::inputSockData(char *buf, int len, RTC::TransportTuple *tup return; } if (is_rtp(buf)) { + if (!_srtp_session_recv) { + WarnL << "received rtp packet when dtls not completed from:" << getPeerAddress(tuple); + return; + } if (_srtp_session_recv->DecryptSrtp((uint8_t *) buf, &len)) { onRtp(buf, len); } return; } if (is_rtcp(buf)) { + if (!_srtp_session_recv) { + WarnL << "received rtcp packet when dtls not completed from:" << getPeerAddress(tuple); + return; + } if (_srtp_session_recv->DecryptSrtcp((uint8_t *) buf, &len)) { onRtcp(buf, len); } @@ -382,6 +394,8 @@ void WebRtcTransportImp::onSendSockData(const char *buf, size_t len, struct sock } auto ptr = BufferRaw::create(); ptr->assign(buf, len); + //一次性发送一帧的rtp数据,提高网络io性能 + _session->setSendFlushFlag(flush); _session->send(std::move(ptr)); }