From 448f6fa3c701ce7f4ea72f299588bad7d1cfe20c Mon Sep 17 00:00:00 2001 From: xiongziliang <771730766@qq.com> Date: Thu, 5 Mar 2020 11:36:31 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96rtp=E4=BB=A3=E7=90=86?= =?UTF-8?q?=E8=B6=85=E6=97=B6=E7=AE=A1=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Rtp/RtpSelector.cpp | 20 ++++++++++++++++---- src/Rtp/RtpSelector.h | 3 ++- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/src/Rtp/RtpSelector.cpp b/src/Rtp/RtpSelector.cpp index e30d4af3..f475159e 100644 --- a/src/Rtp/RtpSelector.cpp +++ b/src/Rtp/RtpSelector.cpp @@ -32,10 +32,6 @@ namespace mediakit{ INSTANCE_IMP(RtpSelector); bool RtpSelector::inputRtp(const char *data, int data_len,const struct sockaddr *addr,uint32_t *dts_out) { - if(_last_rtp_time.elapsedTime() > 3000){ - _last_rtp_time.resetTime(); - onManager(); - } uint32_t ssrc = 0; if(!getSSRC(data,data_len,ssrc)){ WarnL << "get ssrc from rtp failed:" << data_len; @@ -67,10 +63,26 @@ RtpProcess::Ptr RtpSelector::getProcess(uint32_t ssrc,bool makeNew) { if(!ref){ ref = std::make_shared(ssrc,shared_from_this()); ref->attachEvent(); + createTimer(); } return ref->getProcess(); } +void RtpSelector::createTimer() { + if (!_timer) { + //创建超时管理定时器 + weak_ptr weakSelf = shared_from_this(); + _timer = std::make_shared(3.0, [weakSelf] { + auto strongSelf = weakSelf.lock(); + if (!strongSelf) { + return false; + } + strongSelf->onManager(); + return true; + }, EventPollerPool::Instance().getPoller()); + } +} + void RtpSelector::delProcess(uint32_t ssrc,const RtpProcess *ptr) { lock_guard lck(_mtx_map); auto it = _map_rtp_process.find(ssrc); diff --git a/src/Rtp/RtpSelector.h b/src/Rtp/RtpSelector.h index f1b4b97f..9edaca54 100644 --- a/src/Rtp/RtpSelector.h +++ b/src/Rtp/RtpSelector.h @@ -69,10 +69,11 @@ public: void delProcess(uint32_t ssrc,const RtpProcess *ptr); private: void onManager(); + void createTimer(); private: unordered_map _map_rtp_process; recursive_mutex _mtx_map; - Ticker _last_rtp_time; + Timer::Ptr _timer; }; }//namespace mediakit