ps rtp推流支持4个字节的头

This commit is contained in:
xiongziliang 2020-08-15 09:48:27 +08:00
parent d986b1d36c
commit 62da32477e
2 changed files with 17 additions and 9 deletions

View File

@ -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;
}

View File

@ -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;
};