本文主要是介绍视频监控安防平台-GB28181-exosip协议栈系统刷新订阅,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
视频监控安防平台-GB28181-exosip协议栈刷新订阅
由于之前的sip协议栈是自己写的所以对发送订阅消息和相应规定都是自己组装,这次尝试使用exosip来进行订阅,发现不能单纯的调用订阅,必须调用协议栈里面的初始化订阅和刷新订阅,理解好之后,构造代码测试,发现还是不通,以为是协议栈不支持刷新订阅,就一步一步的调试,跟到协议栈内部发现不是这么简单,是exosip协议栈有问题,明明根据sid找到相应的订阅信息,但是返回的时候还是null, 发现是协议栈的问题,修改协议栈源码,重新编译。那么采用exosip刷新订阅的问题就迎刃而解。
下面讲解下解决问题的思路:
采用eXosip_subscribe_build_refresh_request来进行刷新订阅,在调试代码的发现eXosip_subscribe_dialog_find这个函数返回出来的jd == NULL始终是错误的,下面就跟到int eXosip_subscribe_dialog_find(int sid, eXosip_subscribe_t ** js, eXosip_dialog_t ** jd)这个函数,发现通过 sid能找到相应的eXosip_subscribe_t,问题出现在
if ((*js)->s_id == sid)
return OSIP_SUCCESS;
不难看出找到sid之后直接返回成功,那么现在就是解决问题,需要把eXosip_dialog_t ** jd这个参数返回出去,下面就是修改源码:
//if ((*js)->s_id == sid)
//return OSIP_SUCCESS;
// modify by songxw 2017-12-01
if ((*js)->s_id == sid)
{
*jd = (*js)->s_dialogs;
return OSIP_SUCCESS;
}
红色部分为修改内容。这样刷新订阅就没问题了。
下面粘贴下订阅和刷新订阅的代码,提供一段系统目录订阅的函数:
//send subscribe
int CSExtRegister::SendSubSribe(void)
{//构建目录订阅代码string strSubXml = "";TCatalogSubscriReq CatalogSubscriReq;CatalogSubscriReq.nSn = GetSipBodySN();CatalogSubscriReq.strDevId = Username;CatalogSubscriReq.strBeginTime = "";CatalogSubscriReq.strEndTime = ""; BuildMsg(E_PT_CATALOG_SUBCRI_REQ,&CatalogSubscriReq, strSubXml, E_TRANPRO_SUBSCRIBE);int iRet = -1;osip_message_t* pSubScribeMsg = NULL; if (m_SubCatalogTid <= 0){//构建to地址char PToStr[128] = "";sprintf(PToStr,"sip:%s@%s:%d", Username, EpReg.TvsAddr.OutIpAddr, EpReg.TvsAddr.OutPort);char Proxy[SIP_AOR_MAX_SIZE+1] = "";snprintf(Proxy,SIP_AOR_MAX_SIZE, "sip:%s@%s:%d",Username, EpReg.TvsAddr.OutIpAddr, EpReg.TvsAddr.OutPort);char Contact[SIP_AOR_MAX_SIZE+1] = "";snprintf(Contact, SIP_AOR_MAX_SIZE, "sip:%s@%s:%d", CSBase::m_SipSvrPubID, CSBase::m_MyIpAddr, CSBase::m_MyPort);//第一次构造subscribeiRet = eXosip_subscribe_build_initial_request(&pSubScribeMsg, PToStr, CSBase::m_From, Proxy, "presence", m_SubCatalogTime);if (iRet != OSIP_SUCCESS || pSubScribeMsg == NULL){DBGPrint(M_SipUA, ERROR_LEVEL, "%s: build initial subscribe error for <%s>, iRet<%d>!", __FUNCTION__, Username, iRet);return -1;}osip_message_set_content_type(pSubScribeMsg, "Application/MANSCDP+xml");osip_message_set_body(pSubScribeMsg, strSubXml.c_str(), strlen(strSubXml.c_str()));//osip_message_set_contact(pSubScribeMsg, TmpBuf);m_SubCatalogTid = eXosip_subscribe_send_initial_request(pSubScribeMsg);if (m_SubCatalogTid <= 0){DBGPrint(M_SipUA, ERROR_LEVEL, "%s: send subscribe error for <%s>, m_SubCatalogTid<%d>!", __FUNCTION__, Username, m_SubCatalogTid); return -1;}}else{//刷新构建subscrbeiRet = eXosip_subscribe_build_refresh_request(m_SubCatalogTid, &pSubScribeMsg);if (iRet != OSIP_SUCCESS || pSubScribeMsg == NULL){DBGPrint(M_SipUA, ERROR_LEVEL, "%s: build refresh subscribe error for <%s>, iRet<%d>!", __FUNCTION__, Username, iRet);return -1;}char TmpBuf[CLIP_BUFFER_SIZE+1] = {0};snprintf(TmpBuf, CLIP_BUFFER_SIZE, "%d", m_SubCatalogTime);osip_message_set_expires(pSubScribeMsg, TmpBuf);osip_message_set_content_type(pSubScribeMsg, "Application/MANSCDP+xml");osip_message_set_body(pSubScribeMsg, strSubXml.c_str(), strlen(strSubXml.c_str()));if (eXosip_subscribe_send_refresh_request(m_SubCatalogTid, pSubScribeMsg) != OSIP_SUCCESS){DBGPrint(M_SipUA, ERROR_LEVEL, "%s: send refresh subscribe error for <%s>, iRet<%d>!", __FUNCTION__, Username, iRet);return -1;}}return 0;
}
这篇关于视频监控安防平台-GB28181-exosip协议栈系统刷新订阅的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!