mirror of
https://github.com/ZLMediaKit/ZLMediaKit.git
synced 2024-11-23 03:10:04 +08:00
支持ehome推流:#514
This commit is contained in:
parent
38a002646d
commit
18459db8f1
@ -9,18 +9,57 @@
|
||||
*/
|
||||
|
||||
#if defined(ENABLE_RTPPROXY)
|
||||
#include <netinet/in.h>
|
||||
#include <string.h>
|
||||
#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)
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user