From 18459db8f135f06fbeedeea1eb811a9493b01a7d Mon Sep 17 00:00:00 2001 From: xiongziliang <771730766@qq.com> Date: Sat, 24 Oct 2020 23:32:23 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=AF=E6=8C=81ehome=E6=8E=A8=E6=B5=81?= =?UTF-8?q?=EF=BC=9A#514?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Rtp/RtpSplitter.cpp | 46 +++++++++++++++++++++++++++++++++++------ src/Rtp/RtpSplitter.h | 12 ++++++----- 2 files changed, 47 insertions(+), 11 deletions(-) diff --git a/src/Rtp/RtpSplitter.cpp b/src/Rtp/RtpSplitter.cpp index 653c89ac..74b20c2e 100644 --- a/src/Rtp/RtpSplitter.cpp +++ b/src/Rtp/RtpSplitter.cpp @@ -9,18 +9,57 @@ */ #if defined(ENABLE_RTPPROXY) +#include +#include #include "RtpSplitter.h" namespace mediakit{ -RtpSplitter::RtpSplitter() {} +static const char kEHOME_MAGIC[] = "\x01\x00\x01\x00"; +static const int kEHOME_OFFSET = 256; +RtpSplitter::RtpSplitter() {} RtpSplitter::~RtpSplitter() {} +int64_t RtpSplitter::onRecvHeader(const char *data,uint64_t len){ + //忽略偏移量 + data += _offset; + len -= _offset; + + if (_offset == kEHOME_OFFSET + 4 && len > 12 && data[12] == '\r') { + //这是ehome,移除第12个字节 + memmove((char *) data + 1, data, 12); + data += 1; + len -= 1; + } + onRtpPacket(data, len); + return 0; +} + +static bool isEhome(const char *data, int len){ + if (len < 4) { + return false; + } + return memcmp(data, kEHOME_MAGIC, sizeof(kEHOME_MAGIC) - 1) == 0; +} + const char *RtpSplitter::onSearchPacketTail(const char *data, int len) { if (len < 4) { //数据不够 return nullptr; } + + if (isEhome(data, len)) { + //是ehome协议 + if (len < kEHOME_OFFSET + 4) { + //数据不够 + return nullptr; + } + //忽略ehome私有头后是rtsp样式的rtp,多4个字节, + _offset = kEHOME_OFFSET + 4; + //忽略ehome私有头 + return onSearchPacketTail_l(data + kEHOME_OFFSET + 2, len - kEHOME_OFFSET - 2); + } + if (data[0] == '$') { //可能是4个字节的rtp头 _offset = 4; @@ -42,10 +81,5 @@ const char *RtpSplitter::onSearchPacketTail_l(const char *data, int len) { return data + 2 + length; } -int64_t RtpSplitter::onRecvHeader(const char *data, uint64_t len) { - onRtpPacket(data + _offset, len - _offset); - return 0; -} - }//namespace mediakit #endif//defined(ENABLE_RTPPROXY) \ No newline at end of file diff --git a/src/Rtp/RtpSplitter.h b/src/Rtp/RtpSplitter.h index fd3f7370..d81cdd0e 100644 --- a/src/Rtp/RtpSplitter.h +++ b/src/Rtp/RtpSplitter.h @@ -19,18 +19,20 @@ namespace mediakit{ class RtpSplitter : public HttpRequestSplitter{ public: RtpSplitter(); - virtual ~RtpSplitter(); + ~RtpSplitter() override; protected: /** * 收到rtp包回调 + * @param data RTP包数据指针 + * @param len RTP包数据长度 */ - virtual void onRtpPacket(const char *data,uint64_t len) = 0; + 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; + int64_t onRecvHeader(const char *data, uint64_t len) override; + const char *onSearchPacketTail(const char *data, int len) override; + const char *onSearchPacketTail_l(const char *data, int len); private: int _offset = 0;