优化rtp代理超时管理

This commit is contained in:
xiongziliang 2020-03-05 11:36:31 +08:00
parent c77f82f02c
commit 448f6fa3c7
2 changed files with 18 additions and 5 deletions

View File

@ -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<RtpProcessHelper>(ssrc,shared_from_this());
ref->attachEvent();
createTimer();
}
return ref->getProcess();
}
void RtpSelector::createTimer() {
if (!_timer) {
//创建超时管理定时器
weak_ptr<RtpSelector> weakSelf = shared_from_this();
_timer = std::make_shared<Timer>(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<decltype(_mtx_map)> lck(_mtx_map);
auto it = _map_rtp_process.find(ssrc);

View File

@ -69,10 +69,11 @@ public:
void delProcess(uint32_t ssrc,const RtpProcess *ptr);
private:
void onManager();
void createTimer();
private:
unordered_map<uint32_t,RtpProcessHelper::Ptr> _map_rtp_process;
recursive_mutex _mtx_map;
Ticker _last_rtp_time;
Timer::Ptr _timer;
};
}//namespace mediakit