From e3364e9029a2f42266aa4a5d5c17ef82dca01a0f Mon Sep 17 00:00:00 2001 From: xiongziliang <771730766@qq.com> Date: Sun, 18 Oct 2020 21:39:22 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Rtp/RtpSession.cpp | 4 ++-- src/Rtp/RtpSplitter.cpp | 12 +++++++----- src/Rtp/RtpSplitter.h | 3 +++ 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/src/Rtp/RtpSession.cpp b/src/Rtp/RtpSession.cpp index 72037b5e..c7a7c809 100644 --- a/src/Rtp/RtpSession.cpp +++ b/src/Rtp/RtpSession.cpp @@ -59,7 +59,7 @@ void RtpSession::onManager() { void RtpSession::onRtpPacket(const char *data, uint64_t len) { if (!_process) { uint32_t ssrc; - if (!RtpSelector::getSSRC(data + 2, len - 2, ssrc)) { + if (!RtpSelector::getSSRC(data, len, ssrc)) { return; } if (_stream_id.empty()) { @@ -70,7 +70,7 @@ void RtpSession::onRtpPacket(const char *data, uint64_t len) { _process = RtpSelector::Instance().getProcess(_stream_id, true); _process->setListener(dynamic_pointer_cast(shared_from_this())); } - _process->inputRtp(getSock(), data + 2, len - 2, &addr); + _process->inputRtp(getSock(), data, len, &addr); _ticker.resetTime(); } diff --git a/src/Rtp/RtpSplitter.cpp b/src/Rtp/RtpSplitter.cpp index 7c90b3dc..653c89ac 100644 --- a/src/Rtp/RtpSplitter.cpp +++ b/src/Rtp/RtpSplitter.cpp @@ -17,20 +17,22 @@ RtpSplitter::RtpSplitter() {} RtpSplitter::~RtpSplitter() {} const char *RtpSplitter::onSearchPacketTail(const char *data, int len) { + if (len < 4) { + //数据不够 + return nullptr; + } if (data[0] == '$') { //可能是4个字节的rtp头 + _offset = 4; return onSearchPacketTail_l(data + 2, len - 2); } //两个字节的rtp头 + _offset = 2; return onSearchPacketTail_l(data, len); } const char *RtpSplitter::onSearchPacketTail_l(const char *data, int len) { //这是rtp包 - if (len < 2) { - //数据不够 - return nullptr; - } uint16_t length = (((uint8_t *) data)[0] << 8) | ((uint8_t *) data)[1]; if (len < length + 2) { //数据不够 @@ -41,7 +43,7 @@ const char *RtpSplitter::onSearchPacketTail_l(const char *data, int len) { } int64_t RtpSplitter::onRecvHeader(const char *data, uint64_t len) { - onRtpPacket(data,len); + onRtpPacket(data + _offset, len - _offset); return 0; } diff --git a/src/Rtp/RtpSplitter.h b/src/Rtp/RtpSplitter.h index 7e8d61de..fd3f7370 100644 --- a/src/Rtp/RtpSplitter.h +++ b/src/Rtp/RtpSplitter.h @@ -31,6 +31,9 @@ protected: const char *onSearchPacketTail(const char *data,int len) override ; const char *onSearchPacketTail_l(const char *data,int len); int64_t onRecvHeader(const char *data,uint64_t len) override; + +private: + int _offset = 0; }; }//namespace mediakit