Darwin在转发流过程中对推送端断开的处理问题
来源:互联网 发布:网络电视直播大全 编辑:程序博客网 时间:2024/05/19 02:05
最近在做项目的过程中遇到一个问题,在用Darwin Streaming Server中的QTSSReflectorModule模块做为流转发和分发服务,用live555的DarwinInjector类做为模拟设备
进行流推送时,如果按照正常RTSP推送流程:Announce、Setup、Play…、Teardown,Darwin能较好地完成流的转发,但是假如设备在不正常工作,例如网络异常断开,设备断电等中断了数据流的推送,而缺少了<设备->服务器>的Teardown过程,这样与此路推送相关的RTSPSession、RTPSession以及ReflectorSession等都需要等到配置的“rtp_timeout”时间后、RTPSession超时才能析构所有相关转发对象。先分析下原因:
RTSPSession在创建RTPSession时
// Set the current RTSP session for this RTP session. // We do this here because we need to make sure the SessionMutex // is grabbed while we do this. Only do this if the RTSP session // is still alive, of course. if (this->IsLiveSession()) fRTPSession->UpdateRTSPSession(this);
void RTPSessionInterface::UpdateRTSPSession(RTSPSessionInterface* inNewRTSPSession){ if (inNewRTSPSession != fRTSPSession) { // If there was an old session, let it know that we are done if (fRTSPSession != NULL) fRTSPSession->DecrementObjectHolderCount(); // Increment this count to prevent the RTSP session from being deleted fRTSPSession = inNewRTSPSession; fRTSPSession->IncrementObjectHolderCount(); }}
IncrementObjectHolderCount()增加了fRTPSession对RTSPSession的引用,而对应的DecrementObjectHolderCount()在RTPSession::Teardown()中执行,由于RTSPSession拥有很好的对象保护机制,只有当对当前RTSPSession的引用数为0时
// Only delete if it is ok to delete! if (fObjectHolders == 0) return -1;
RTSPSession自身才能调用Task::Run(){return -1;} delete,所以在RTSPSession注销之前,必须等待RTPSession注销,而且RTPSession没有等到Teardown命令,就只能等超时,而这个超时时间不能定,及时几秒钟对于转发实时流来说也是不合理的。
解决办法:
在RTSPSession:Run()函数中的
while(IsLiveSession()){ switch(){case:}}
状态机外加入代码及时析构RTPSession
// Make absolutely sure there are no resources being occupied by the session// at this point.this->CleanupRequest();//Kill与RTSPSession相关的RTPSessionif(!IsLiveSession()){OSRefTable* theMap = QTSServerInterface::GetServer()->GetRTPSessionMap();OSRef* theRef = theMap->Resolve(&fLastRTPSessionIDPtr);if (theRef != NULL){fRTPSession = (RTPSession*)theRef->GetObject();if(fRTPSession) fRTPSession->Teardown();theMap->Release(fRTPSession->GetRef());fRTPSession = NULL;} }// Only delete if it is ok to delete! if (fObjectHolders == 0) return -1; // If we are here because of a timeout, but we can't delete because someone // is holding onto a reference to this session, just reschedule the timeout. // At this point, however, the session is DEAD. return 0;
注意 this->CleanupRequest();在前,
这样就能在RTSPSession判断fObjectHolders之前将附属的RTPSession析构,进而析构RTSPSession.
由于工作比较忙,写的可能在思路上不是很清楚,欢迎指正!
/--------------------------------------割了------------------------------------/
在上段代码中可以加入一个补充条件进行代码的优化,并且CleanupRequest()必须在此之后!
//fObjectHolders-- if(!IsLiveSession()&& fObjectHolders > 0){ OSRefTable* theMap = QTSServerInterface::GetServer()->GetRTPSessionMap(); OSRef* theRef = theMap->Resolve(&fLastRTPSessionIDPtr); if (theRef != NULL){ fRTPSession = (RTPSession*)theRef->GetObject(); if(fRTPSession) fRTPSession->Teardown(); theMap->Release(fRTPSession->GetRef()); fRTPSession = NULL; } } // Make absolutely sure there are no resources being occupied by the session // at this point. this->CleanupRequest(); // Only delete if it is ok to delete! if (fObjectHolders == 0) return -1;------------------------------------------------------------
本文转自www.easydarwin.org,更多开源流媒体解决方案,请关注我们的微信:EasyDarwin
- Darwin在转发流过程中对推送端断开的处理问题
- Darwin在转发流过程中对推送端断开的处理问题
- 在openwrt中对https 数据的转发到 云端
- 关于 darwin 转发服务器收集的资料
- Darwin Streaming Server中RTSP请求的处理过程(Darwin流媒体服务器解析2)
- mysql自动断开连接的问题处理
- 在重定向,转发中关于路径问题的总结
- 在C#中利用Keep-Alive处理Socket网络异常断开的方法
- 在C#中利用Keep-Alive处理Socket网络异常断开的方法
- 在C#中利用Keep-Alive处理Socket网络异常断开的方法
- 在C#中利用Keep-Alive处理Socket网络异常断开的方法
- 在C#中利用Keep-Alive处理Socket网络异常断开的方法
- 在C#中利用Keep-Alive处理Socket网络异常断开的方法
- 在C#中利用Keep-Alive处理Socket网络异常断开的方法
- 在C#中利用Keep-Alive处理Socket网络异常断开的方法
- 在C#中利用Keep-Alive处理Socket网络异常断开的方法
- 在C#中利用Keep-Alive处理Socket网络异常断开的方法
- 在c#中利用keep-alive处理socket网络异常断开的方法
- Request对象
- [Web前端]CSS实现“不可选择,不可复制”面临的问题
- 临终的悲剧——————抢救最后一口气
- 简单的斐波那契数列程序
- WPF 入门
- Darwin在转发流过程中对推送端断开的处理问题
- Ubuntu 12.04 LTS下环境变量设置
- 心得6--XML编程(CRUD)--DOM4J精讲
- modelDriven
- Android中px与dip,sp与dip等的转换工具类
- DOM4J实例,详细解说怎么用DOM4J编程
- Android List divider显示不出来的问题
- 文本去重之SimHash算法
- 将电脑本地的文件拷贝到android虚拟机的虚拟存储卡(sdcard)