From 62da32477eb988514615ee06c5f6ced9fc4185fe Mon Sep 17 00:00:00 2001 From: xiongziliang <771730766@qq.com> Date: Sat, 15 Aug 2020 09:48:27 +0800 Subject: [PATCH] =?UTF-8?q?ps=20rtp=E6=8E=A8=E6=B5=81=E6=94=AF=E6=8C=814?= =?UTF-8?q?=E4=B8=AA=E5=AD=97=E8=8A=82=E7=9A=84=E5=A4=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Rtp/RtpSplitter.cpp | 21 ++++++++++++++------- src/Rtp/RtpSplitter.h | 5 +++-- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/src/Rtp/RtpSplitter.cpp b/src/Rtp/RtpSplitter.cpp index 01414f20..7c90b3dc 100644 --- a/src/Rtp/RtpSplitter.cpp +++ b/src/Rtp/RtpSplitter.cpp @@ -12,20 +12,27 @@ #include "RtpSplitter.h" namespace mediakit{ -RtpSplitter::RtpSplitter() { -} +RtpSplitter::RtpSplitter() {} -RtpSplitter::~RtpSplitter() { -} +RtpSplitter::~RtpSplitter() {} const char *RtpSplitter::onSearchPacketTail(const char *data, int len) { + if (data[0] == '$') { + //可能是4个字节的rtp头 + return onSearchPacketTail_l(data + 2, len - 2); + } + //两个字节的rtp头 + return onSearchPacketTail_l(data, len); +} + +const char *RtpSplitter::onSearchPacketTail_l(const char *data, int len) { //这是rtp包 - if(len < 2){ + if (len < 2) { //数据不够 return nullptr; } - uint16_t length = (((uint8_t *)data)[0] << 8) | ((uint8_t *)data)[1]; - if(len < length + 2){ + uint16_t length = (((uint8_t *) data)[0] << 8) | ((uint8_t *) data)[1]; + if (len < length + 2) { //数据不够 return nullptr; } diff --git a/src/Rtp/RtpSplitter.h b/src/Rtp/RtpSplitter.h index 45776b01..7e8d61de 100644 --- a/src/Rtp/RtpSplitter.h +++ b/src/Rtp/RtpSplitter.h @@ -20,15 +20,16 @@ class RtpSplitter : public HttpRequestSplitter{ public: RtpSplitter(); virtual ~RtpSplitter(); + protected: /** * 收到rtp包回调 - * @param data - * @param len */ virtual void onRtpPacket(const char *data,uint64_t len) = 0; + 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; };