兼容ssrc为0的rtp推流

This commit is contained in:
xiongziliang 2020-02-23 12:16:20 +08:00
parent 618b028da4
commit f76109c629
4 changed files with 14 additions and 11 deletions

@ -1 +1 @@
Subproject commit 1f87bc42900e88d5443fb63bfb82523a2ac3ea33 Subproject commit 34b42499ce9ee055b5c7cac9a270239984d0e839

View File

@ -36,8 +36,8 @@ bool RtpSelector::inputRtp(const char *data, int data_len,const struct sockaddr
_last_rtp_time.resetTime(); _last_rtp_time.resetTime();
onManager(); onManager();
} }
auto ssrc = getSSRC(data,data_len); uint32_t ssrc = 0;
if(!ssrc){ if(!getSSRC(data,data_len,ssrc)){
WarnL << "get ssrc from rtp failed:" << data_len; WarnL << "get ssrc from rtp failed:" << data_len;
return false; return false;
} }
@ -48,12 +48,13 @@ bool RtpSelector::inputRtp(const char *data, int data_len,const struct sockaddr
return false; return false;
} }
uint32_t RtpSelector::getSSRC(const char *data, int data_len) { bool RtpSelector::getSSRC(const char *data,int data_len, uint32_t &ssrc){
if(data_len < 12){ if(data_len < 12){
return 0; return false;
} }
uint32_t *ssrc_ptr = (uint32_t *)(data + 8); uint32_t *ssrc_ptr = (uint32_t *)(data + 8);
return ntohl(*ssrc_ptr); ssrc = ntohl(*ssrc_ptr);
return true;
} }
RtpProcess::Ptr RtpSelector::getProcess(uint32_t ssrc,bool makeNew) { RtpProcess::Ptr RtpSelector::getProcess(uint32_t ssrc,bool makeNew) {

View File

@ -42,7 +42,7 @@ public:
static RtpSelector &Instance(); static RtpSelector &Instance();
bool inputRtp(const char *data,int data_len,const struct sockaddr *addr ,uint32_t *dts_out = nullptr ); bool inputRtp(const char *data,int data_len,const struct sockaddr *addr ,uint32_t *dts_out = nullptr );
static uint32_t getSSRC(const char *data,int data_len); static bool getSSRC(const char *data,int data_len, uint32_t &ssrc);
RtpProcess::Ptr getProcess(uint32_t ssrc,bool makeNew); RtpProcess::Ptr getProcess(uint32_t ssrc,bool makeNew);
void delProcess(uint32_t ssrc,const RtpProcess *ptr); void delProcess(uint32_t ssrc,const RtpProcess *ptr);
private: private:

View File

@ -36,7 +36,7 @@ RtpSession::RtpSession(const Socket::Ptr &sock) : TcpSession(sock) {
} }
RtpSession::~RtpSession() { RtpSession::~RtpSession() {
DebugP(this); DebugP(this);
if(_ssrc){ if(_process){
RtpSelector::Instance().delProcess(_ssrc,_process.get()); RtpSelector::Instance().delProcess(_ssrc,_process.get());
} }
} }
@ -66,8 +66,10 @@ void RtpSession::onManager() {
} }
void RtpSession::onRtpPacket(const char *data, uint64_t len) { void RtpSession::onRtpPacket(const char *data, uint64_t len) {
if(!_ssrc){ if (!_process) {
_ssrc = RtpSelector::getSSRC(data + 2,len - 2); if (!RtpSelector::getSSRC(data + 2, len - 2, _ssrc)) {
return;
}
_process = RtpSelector::Instance().getProcess(_ssrc, true); _process = RtpSelector::Instance().getProcess(_ssrc, true);
} }
_process->inputRtp(data + 2, len - 2, &addr); _process->inputRtp(data + 2, len - 2, &addr);