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