Commit 448f6fa3 by xiongziliang

优化rtp代理超时管理

parent c77f82f0
...@@ -32,10 +32,6 @@ namespace mediakit{ ...@@ -32,10 +32,6 @@ namespace mediakit{
INSTANCE_IMP(RtpSelector); INSTANCE_IMP(RtpSelector);
bool RtpSelector::inputRtp(const char *data, int data_len,const struct sockaddr *addr,uint32_t *dts_out) { 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; uint32_t ssrc = 0;
if(!getSSRC(data,data_len,ssrc)){ if(!getSSRC(data,data_len,ssrc)){
WarnL << "get ssrc from rtp failed:" << data_len; WarnL << "get ssrc from rtp failed:" << data_len;
...@@ -67,10 +63,26 @@ RtpProcess::Ptr RtpSelector::getProcess(uint32_t ssrc,bool makeNew) { ...@@ -67,10 +63,26 @@ RtpProcess::Ptr RtpSelector::getProcess(uint32_t ssrc,bool makeNew) {
if(!ref){ if(!ref){
ref = std::make_shared<RtpProcessHelper>(ssrc,shared_from_this()); ref = std::make_shared<RtpProcessHelper>(ssrc,shared_from_this());
ref->attachEvent(); ref->attachEvent();
createTimer();
} }
return ref->getProcess(); 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) { void RtpSelector::delProcess(uint32_t ssrc,const RtpProcess *ptr) {
lock_guard<decltype(_mtx_map)> lck(_mtx_map); lock_guard<decltype(_mtx_map)> lck(_mtx_map);
auto it = _map_rtp_process.find(ssrc); auto it = _map_rtp_process.find(ssrc);
......
...@@ -69,10 +69,11 @@ public: ...@@ -69,10 +69,11 @@ public:
void delProcess(uint32_t ssrc,const RtpProcess *ptr); void delProcess(uint32_t ssrc,const RtpProcess *ptr);
private: private:
void onManager(); void onManager();
void createTimer();
private: private:
unordered_map<uint32_t,RtpProcessHelper::Ptr> _map_rtp_process; unordered_map<uint32_t,RtpProcessHelper::Ptr> _map_rtp_process;
recursive_mutex _mtx_map; recursive_mutex _mtx_map;
Ticker _last_rtp_time; Timer::Ptr _timer;
}; };
}//namespace mediakit }//namespace mediakit
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论