Darwin在转发流过程中对推送端断开的处理问题

2024-02-22 03:58

本文主要是介绍Darwin在转发流过程中对推送端断开的处理问题,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

      最近在做项目的过程中遇到一个问题,在用Darwin Streaming Server中的QTSSReflectorModule模块做为流转发和分发服务,用live555的DarwinInjector类做为模拟设备

进行流推送时,如果按照正常RTSP推送流程:Announce、Setup、Play…、Teardown,Darwin能较好地完成流的转发,但是假如设备在不正常工作,例如网络异常断开,设备断电等中断了数据流的推送,而缺少了<设备->服务器>的Teardown过程,这样与此路推送相关的RTSPSession、RTPSession以及ReflectorSession等都需要等到配置的“rtp_timeout”时间后、RTPSession超时才能析构所有相关转发对象。先分析下原因:

      RTSPSession在创建RTPSession时

[cpp]  view plain copy
在CODE上查看代码片 派生到我的代码片
  1. // Set the current RTSP session for this RTP session.  
  2. // We do this here because we need to make sure the SessionMutex  
  3. // is grabbed while we do this. Only do this if the RTSP session  
  4. // is still alive, of course.  
  5. if (this->IsLiveSession())  
  6.     fRTPSession->UpdateRTSPSession(this);  

[cpp]  view plain copy
在CODE上查看代码片 派生到我的代码片
  1. void RTPSessionInterface::UpdateRTSPSession(RTSPSessionInterface* inNewRTSPSession)  
  2. {     
  3.     if (inNewRTSPSession != fRTSPSession)  
  4.     {  
  5.         // If there was an old session, let it know that we are done  
  6.         if (fRTSPSession != NULL)  
  7.             fRTSPSession->DecrementObjectHolderCount();  
  8.           
  9.         // Increment this count to prevent the RTSP session from being deleted  
  10.         fRTSPSession = inNewRTSPSession;  
  11.         fRTSPSession->IncrementObjectHolderCount();  
  12.     }  
  13. }  

IncrementObjectHolderCount()增加了fRTPSession对RTSPSession的引用,而对应的DecrementObjectHolderCount()在RTPSession::Teardown()中执行,由于RTSPSession拥有很好的对象保护机制,只有当对当前RTSPSession的引用数为0时
[cpp]  view plain copy
在CODE上查看代码片 派生到我的代码片
  1. // Only delete if it is ok to delete!  
  2. if (fObjectHolders == 0)  
  3.     return -1;  


RTSPSession自身才能调用Task::Run(){return -1;} delete,所以在RTSPSession注销之前,必须等待RTPSession注销,而且RTPSession没有等到Teardown命令,就只能等超时,而这个超时时间不能定,及时几秒钟对于转发实时流来说也是不合理的。

解决办法:

在RTSPSession:Run()函数中的

[cpp]  view plain copy
在CODE上查看代码片 派生到我的代码片
  1. while(IsLiveSession())  
  2. {  
  3.       switch(){case:}  
  4. }  


状态机外加入代码及时析构RTPSession

[cpp]  view plain copy
在CODE上查看代码片 派生到我的代码片
  1. // Make absolutely sure there are no resources being occupied by the session  
  2. // at this point.  
  3. this->CleanupRequest();  
  4.   
  5.   
  6. //Kill与RTSPSession相关的RTPSession  
  7. if(!IsLiveSession()){  
  8. OSRefTable* theMap = QTSServerInterface::GetServer()->GetRTPSessionMap();  
  9. OSRef* theRef = theMap->Resolve(&fLastRTPSessionIDPtr);  
  10. if (theRef != NULL){  
  11.     fRTPSession = (RTPSession*)theRef->GetObject();  
  12.     if(fRTPSession) fRTPSession->Teardown();  
  13.     theMap->Release(fRTPSession->GetRef());  
  14.     fRTPSession = NULL;  
  15.     }   
  16. }     
  17. // Only delete if it is ok to delete!      
  18. if (fObjectHolders == 0)        return -1;     
  19. // If we are here because of a timeout, but we can't delete because someone      
  20. // is holding onto a reference to this session, just reschedule the timeout.     
  21. // At this point, however, the session is DEAD.     
  22. return 0;  


注意 this->CleanupRequest();在前,

这样就能在RTSPSession判断fObjectHolders之前将附属的RTPSession析构,进而析构RTSPSession.
由于工作比较忙,写的可能在思路上不是很清楚,欢迎指正!

/--------------------------------------割了------------------------------------/

在上段代码中可以加入一个补充条件进行代码的优化,并且CleanupRequest()必须在此之后!

[cpp]  view plain copy
在CODE上查看代码片 派生到我的代码片
  1. //fObjectHolders--    
  2. if(!IsLiveSession()&& fObjectHolders > 0){    
  3. OSRefTable* theMap = QTSServerInterface::GetServer()->GetRTPSessionMap();    
  4. OSRef* theRef = theMap->Resolve(&fLastRTPSessionIDPtr);    
  5. if (theRef != NULL){    
  6.     fRTPSession = (RTPSession*)theRef->GetObject();    
  7.     if(fRTPSession) fRTPSession->Teardown();    
  8.     theMap->Release(fRTPSession->GetRef());    
  9.     fRTPSession = NULL;    
  10.     }     
  11. }      
  12.   
  13.    // Make absolutely sure there are no resources being occupied by the session  
  14.    // at this point.  
  15.    this->CleanupRequest();  
  16.   
  17.    // Only delete if it is ok to delete!  
  18.    if (fObjectHolders == 0)  
  19.        return -1;  

这篇关于Darwin在转发流过程中对推送端断开的处理问题的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/734056

相关文章

JavaScript中的reduce方法执行过程、使用场景及进阶用法

《JavaScript中的reduce方法执行过程、使用场景及进阶用法》:本文主要介绍JavaScript中的reduce方法执行过程、使用场景及进阶用法的相关资料,reduce是JavaScri... 目录1. 什么是reduce2. reduce语法2.1 语法2.2 参数说明3. reduce执行过程

mybatis和mybatis-plus设置值为null不起作用问题及解决

《mybatis和mybatis-plus设置值为null不起作用问题及解决》Mybatis-Plus的FieldStrategy主要用于控制新增、更新和查询时对空值的处理策略,通过配置不同的策略类型... 目录MyBATis-plusFieldStrategy作用FieldStrategy类型每种策略的作

linux下多个硬盘划分到同一挂载点问题

《linux下多个硬盘划分到同一挂载点问题》在Linux系统中,将多个硬盘划分到同一挂载点需要通过逻辑卷管理(LVM)来实现,首先,需要将物理存储设备(如硬盘分区)创建为物理卷,然后,将这些物理卷组成... 目录linux下多个硬盘划分到同一挂载点需要明确的几个概念硬盘插上默认的是非lvm总结Linux下多

Python Jupyter Notebook导包报错问题及解决

《PythonJupyterNotebook导包报错问题及解决》在conda环境中安装包后,JupyterNotebook导入时出现ImportError,可能是由于包版本不对应或版本太高,解决方... 目录问题解决方法重新安装Jupyter NoteBook 更改Kernel总结问题在conda上安装了

pip install jupyterlab失败的原因问题及探索

《pipinstalljupyterlab失败的原因问题及探索》在学习Yolo模型时,尝试安装JupyterLab但遇到错误,错误提示缺少Rust和Cargo编译环境,因为pywinpty包需要它... 目录背景问题解决方案总结背景最近在学习Yolo模型,然后其中要下载jupyter(有点LSVmu像一个

redis群集简单部署过程

《redis群集简单部署过程》文章介绍了Redis,一个高性能的键值存储系统,其支持多种数据结构和命令,它还讨论了Redis的服务器端架构、数据存储和获取、协议和命令、高可用性方案、缓存机制以及监控和... 目录Redis介绍1. 基本概念2. 服务器端3. 存储和获取数据4. 协议和命令5. 高可用性6.

解决jupyterLab打开后出现Config option `template_path`not recognized by `ExporterCollapsibleHeadings`问题

《解决jupyterLab打开后出现Configoption`template_path`notrecognizedby`ExporterCollapsibleHeadings`问题》在Ju... 目录jupyterLab打开后出现“templandroidate_path”相关问题这是 tensorflo

如何解决Pycharm编辑内容时有光标的问题

《如何解决Pycharm编辑内容时有光标的问题》文章介绍了如何在PyCharm中配置VimEmulator插件,包括检查插件是否已安装、下载插件以及安装IdeaVim插件的步骤... 目录Pycharm编辑内容时有光标1.如果Vim Emulator前面有对勾2.www.chinasem.cn如果tools工

最长公共子序列问题的深度分析与Java实现方式

《最长公共子序列问题的深度分析与Java实现方式》本文详细介绍了最长公共子序列(LCS)问题,包括其概念、暴力解法、动态规划解法,并提供了Java代码实现,暴力解法虽然简单,但在大数据处理中效率较低,... 目录最长公共子序列问题概述问题理解与示例分析暴力解法思路与示例代码动态规划解法DP 表的构建与意义动

Java多线程父线程向子线程传值问题及解决

《Java多线程父线程向子线程传值问题及解决》文章总结了5种解决父子之间数据传递困扰的解决方案,包括ThreadLocal+TaskDecorator、UserUtils、CustomTaskDeco... 目录1 背景2 ThreadLocal+TaskDecorator3 RequestContextH