From f76109c629dfcfe2fba48352dd25c0b28bacedb4 Mon Sep 17 00:00:00 2001 From: xiongziliang <771730766@qq.com> Date: Sun, 23 Feb 2020 12:16:20 +0800 Subject: [PATCH] =?UTF-8?q?=E5=85=BC=E5=AE=B9ssrc=E4=B8=BA0=E7=9A=84rtp?= =?UTF-8?q?=E6=8E=A8=E6=B5=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 3rdpart/ZLToolKit | 2 +- src/Rtp/RtpSelector.cpp | 11 ++++++----- src/Rtp/RtpSelector.h | 2 +- src/Rtp/RtpSession.cpp | 10 ++++++---- 4 files changed, 14 insertions(+), 11 deletions(-) diff --git a/3rdpart/ZLToolKit b/3rdpart/ZLToolKit index 1f87bc42..34b42499 160000 --- a/3rdpart/ZLToolKit +++ b/3rdpart/ZLToolKit @@ -1 +1 @@ -Subproject commit 1f87bc42900e88d5443fb63bfb82523a2ac3ea33 +Subproject commit 34b42499ce9ee055b5c7cac9a270239984d0e839 diff --git a/src/Rtp/RtpSelector.cpp b/src/Rtp/RtpSelector.cpp index f57081d2..bc8e7924 100644 --- a/src/Rtp/RtpSelector.cpp +++ b/src/Rtp/RtpSelector.cpp @@ -36,8 +36,8 @@ bool RtpSelector::inputRtp(const char *data, int data_len,const struct sockaddr _last_rtp_time.resetTime(); onManager(); } - auto ssrc = getSSRC(data,data_len); - if(!ssrc){ + uint32_t ssrc = 0; + if(!getSSRC(data,data_len,ssrc)){ WarnL << "get ssrc from rtp failed:" << data_len; return false; } @@ -48,12 +48,13 @@ bool RtpSelector::inputRtp(const char *data, int data_len,const struct sockaddr 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){ - return 0; + return false; } 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) { diff --git a/src/Rtp/RtpSelector.h b/src/Rtp/RtpSelector.h index bbbd9665..a701a83d 100644 --- a/src/Rtp/RtpSelector.h +++ b/src/Rtp/RtpSelector.h @@ -42,7 +42,7 @@ public: static RtpSelector &Instance(); 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); void delProcess(uint32_t ssrc,const RtpProcess *ptr); private: diff --git a/src/Rtp/RtpSession.cpp b/src/Rtp/RtpSession.cpp index c765997f..f807a85d 100644 --- a/src/Rtp/RtpSession.cpp +++ b/src/Rtp/RtpSession.cpp @@ -36,7 +36,7 @@ RtpSession::RtpSession(const Socket::Ptr &sock) : TcpSession(sock) { } RtpSession::~RtpSession() { DebugP(this); - if(_ssrc){ + if(_process){ RtpSelector::Instance().delProcess(_ssrc,_process.get()); } } @@ -66,11 +66,13 @@ void RtpSession::onManager() { } void RtpSession::onRtpPacket(const char *data, uint64_t len) { - if(!_ssrc){ - _ssrc = RtpSelector::getSSRC(data + 2,len - 2); + if (!_process) { + if (!RtpSelector::getSSRC(data + 2, len - 2, _ssrc)) { + return; + } _process = RtpSelector::Instance().getProcess(_ssrc, true); } - _process->inputRtp(data + 2,len - 2,&addr); + _process->inputRtp(data + 2, len - 2, &addr); _ticker.resetTime(); }