Commit e3364e90 by xiongziliang

优化代码

parent 51fcaeda
...@@ -59,7 +59,7 @@ void RtpSession::onManager() { ...@@ -59,7 +59,7 @@ void RtpSession::onManager() {
void RtpSession::onRtpPacket(const char *data, uint64_t len) { void RtpSession::onRtpPacket(const char *data, uint64_t len) {
if (!_process) { if (!_process) {
uint32_t ssrc; uint32_t ssrc;
if (!RtpSelector::getSSRC(data + 2, len - 2, ssrc)) { if (!RtpSelector::getSSRC(data, len, ssrc)) {
return; return;
} }
if (_stream_id.empty()) { if (_stream_id.empty()) {
...@@ -70,7 +70,7 @@ void RtpSession::onRtpPacket(const char *data, uint64_t len) { ...@@ -70,7 +70,7 @@ void RtpSession::onRtpPacket(const char *data, uint64_t len) {
_process = RtpSelector::Instance().getProcess(_stream_id, true); _process = RtpSelector::Instance().getProcess(_stream_id, true);
_process->setListener(dynamic_pointer_cast<RtpSession>(shared_from_this())); _process->setListener(dynamic_pointer_cast<RtpSession>(shared_from_this()));
} }
_process->inputRtp(getSock(), data + 2, len - 2, &addr); _process->inputRtp(getSock(), data, len, &addr);
_ticker.resetTime(); _ticker.resetTime();
} }
......
...@@ -17,20 +17,22 @@ RtpSplitter::RtpSplitter() {} ...@@ -17,20 +17,22 @@ RtpSplitter::RtpSplitter() {}
RtpSplitter::~RtpSplitter() {} RtpSplitter::~RtpSplitter() {}
const char *RtpSplitter::onSearchPacketTail(const char *data, int len) { const char *RtpSplitter::onSearchPacketTail(const char *data, int len) {
if (len < 4) {
//数据不够
return nullptr;
}
if (data[0] == '$') { if (data[0] == '$') {
//可能是4个字节的rtp头 //可能是4个字节的rtp头
_offset = 4;
return onSearchPacketTail_l(data + 2, len - 2); return onSearchPacketTail_l(data + 2, len - 2);
} }
//两个字节的rtp头 //两个字节的rtp头
_offset = 2;
return onSearchPacketTail_l(data, len); return onSearchPacketTail_l(data, len);
} }
const char *RtpSplitter::onSearchPacketTail_l(const char *data, int len) { const char *RtpSplitter::onSearchPacketTail_l(const char *data, int len) {
//这是rtp包 //这是rtp包
if (len < 2) {
//数据不够
return nullptr;
}
uint16_t length = (((uint8_t *) data)[0] << 8) | ((uint8_t *) data)[1]; uint16_t length = (((uint8_t *) data)[0] << 8) | ((uint8_t *) data)[1];
if (len < length + 2) { if (len < length + 2) {
//数据不够 //数据不够
...@@ -41,7 +43,7 @@ const char *RtpSplitter::onSearchPacketTail_l(const char *data, int len) { ...@@ -41,7 +43,7 @@ const char *RtpSplitter::onSearchPacketTail_l(const char *data, int len) {
} }
int64_t RtpSplitter::onRecvHeader(const char *data, uint64_t len) { int64_t RtpSplitter::onRecvHeader(const char *data, uint64_t len) {
onRtpPacket(data,len); onRtpPacket(data + _offset, len - _offset);
return 0; return 0;
} }
......
...@@ -31,6 +31,9 @@ protected: ...@@ -31,6 +31,9 @@ protected:
const char *onSearchPacketTail(const char *data,int len) override ; const char *onSearchPacketTail(const char *data,int len) override ;
const char *onSearchPacketTail_l(const char *data,int len); 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;
private:
int _offset = 0;
}; };
}//namespace mediakit }//namespace mediakit
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论