📄 callagent.cxx
字号:
return; } assert(remoteSdp != 0); Data S_host; if((UaConfiguration::instance().getValue(NATAddressIPTag)).length()) { S_host = UaConfiguration::instance().getValue(NATAddressIPTag); } else { S_host = theSystem.gethostAddress(); } //Create a session#ifdef USE_MPEGLIB SipSdp localSdp; SdpSession localS = MediaController::instance().createSession(); localSdp.setSdpDescriptor(localS); int video = atoi(UaConfiguration::instance().getValue(VideoTag).c_str()); //Even if video mode is on, when running in command line mode force the //non-video option if(video && (!UaCommandLine::instance()->getIntOpt("cmdline"))) { //Offer Video also, Would be nice to move to the Libmedia library when the //library integrate the MPEG4 codec. For now encoding/decoding happens //deep down in MPEG4IP Sptr<VideoDevice> vDevice; vDevice.dynamicCast(UaFacade::instance().getMediaDevice(getId())); assert(vDevice != 0); vDevice->setupSession(remoteSdp->getSdpDescriptor(), localSdp.getSdpDescriptor()); }#else SipSdp localSdp; SdpSession localS = MediaController::instance().createSession(remoteSdp->getSdpDescriptor()); setHost(localS, S_host); localSdp.setSdpDescriptor(localS);#endif statusMsg->setContentData(&localSdp, 0); myInvokee->sendMsg(statusMsg); UaFacade::instance().postInfo(statusMsg); } catch(CInvalidStateException& e) { cpLog(LOG_ERR, "Invalid state transition:%s", e.getDescription().c_str()); }}voidCallAgent::stopCall(){ myState->end(*this);}voidCallAgent::setDeleted(){ myActiveFlg = false; cpLog(LOG_DEBUG, "CallAgent::setDeleted:%d", getId()); CallDB::instance().removeCallData(*myInvokee); UaCallControl::instance().removeAgent(getId(), 1000);}voidCallAgent::sendBusy(){ Sptr<SipCommand> sCommand; sCommand.dynamicCast(myInvokee->getRequest()); Sptr<StatusMsg> sMsg = new StatusMsg(*sCommand, 486); myInvokee->sendMsg(sMsg); UaFacade::instance().postInfo(sMsg); myState->cancel(*this); myState->end(*this); }voidCallAgent::doAuthentication(Sptr<StatusMsg> sMsg){ //User has been challenged, send the inviate with Authorization header Data user = UaConfiguration::instance().getValue(UserNameTag); Data password = UaConfiguration::instance().getValue(PasswordTag); Sptr<SipCommand> sCommand; sCommand.dynamicCast(myInvokee->getRequest()); SipCSeq cSeq = sCommand->getCSeq(); cSeq.incrCSeq(); sCommand->setCSeq(cSeq); assert(sCommand != 0); authenticateMessage(*sMsg,*sCommand, user, password); placeCall();}voidCallAgent::processHold(){ cpLog(LOG_DEBUG, "in CallAgent::processHold this should be invoke in UAC Hold"); Sptr<InviteMsg> inviteMsg; inviteMsg.dynamicCast(myInvokee->getRequest()); SipFrom fom = inviteMsg->getFrom(); SipContact cont = inviteMsg->getContact(0); Sptr<BaseUrl> cUrl = cont.getUrl(); Sptr<SipUrl> mcUrl; mcUrl.dynamicCast(cUrl); SipTo to = inviteMsg->getTo(); cpLog(LOG_DEBUG, "CallAgent::processHold() Contact host is %s",mcUrl->getHost().logData()); cpLog(LOG_DEBUG, "CallAgent::processHold() System host is %s",theSystem.gethostAddress()); if(mcUrl->getHost() != theSystem.gethostAddress()){ SipFrom from = inviteMsg->getFrom(); from.setDisplayName(""); Sptr<BaseUrl> bUrl = to.getUrl(); Sptr<SipUrl> mUrl; mUrl.dynamicCast(bUrl); assert(mUrl != 0); cpLog(LOG_DEBUG, "CallAgent::processHold() From url is %s", mUrl->encode().logData()); from.setUrl(mUrl); inviteMsg->setFrom(from); // To Sptr<BaseUrl> bUrl1 = fom.getUrl(); to.setUser(fom.getUser()); to.setDisplayName(fom.getDisplayName()); Sptr<SipUrl> mUrl1; mUrl1.dynamicCast(bUrl1); assert(mUrl1 != 0); to.setUrl(mUrl1); inviteMsg->setTo(to); cpLog(LOG_DEBUG, "CallAgent::processHold() To is %s", to.encode().logData()); cpLog(LOG_DEBUG, "CallAgent::processHold() From is %s", from.encode().logData()); } else { //do nothing since We are UAC before, we don't need to flip // TO & FROM }// SipCSeq localseq = myInvokee->getLocalCSeq();// localseq.incrCSeq();// myInvokee->setLocalCSeq(localseq);// inviteMsg->setCSeq(localseq); Sptr<SipSdp> sipSdp; sipSdp.dynamicCast ( inviteMsg->getContentData( 0 ) ); assert(sipSdp != 0); unsigned int sId = myInvokee->getLocalSdp()->getSdpDescriptor().getSessionId(); SdpSession localSdp = MediaController::instance().getSdp(sId, VSDP_SND); sipSdp->setSdpDescriptor(localSdp); cpLog(LOG_DEBUG, "CallAgent::processHold() is Sending re-invite %s",inviteMsg->encode().logData()); myInvokee->sendMsg(inviteMsg); }voidCallAgent::processResume(){ cpLog(LOG_DEBUG, "CallAgent::processResume() this should be invoke in UAC Resume "); Sptr<InviteMsg> inviteMsg; inviteMsg.dynamicCast(myInvokee->getRequest());// SipCSeq localseq = myInvokee->getLocalCSeq();// localseq.incrCSeq();// myInvokee->setLocalCSeq(localseq);// inviteMsg->setCSeq(localseq); Sptr<SipSdp> sipSdp; sipSdp.dynamicCast ( inviteMsg->getContentData( 0 ) ); assert(sipSdp != 0); unsigned int sId = myInvokee->getLocalSdp()->getSdpDescriptor().getSessionId(); SdpSession localSdp = MediaController::instance().getSdp(sId); sipSdp->setSdpDescriptor(localSdp); cpLog(LOG_DEBUG, "Sending InviteMsg %s",inviteMsg->encode().logData() ); myInvokee->sendMsg(inviteMsg); //placeCall(); }voidCallAgent::doResume(Sptr<SipMsg>& msg){ cpLog(LOG_DEBUG, "CallAgent::doResume() this should be invoke in UAC Resume "); cpLog(LOG_DEBUG, "CallAgent::processHold() Response is %s",msg->encode().logData()); myState->inCall(*this); Sptr<StatusMsg> smsg; smsg.dynamicCast(msg); cpLog(LOG_DEBUG, "CallAgent::processHold() is Sending re-invite %s",msg->encode().logData()); Sptr<SipSdp> remoteSdp; remoteSdp.dynamicCast(smsg->getContentData(0)); myInvokee->setRemoteSdp(remoteSdp); assert(remoteSdp != 0); unsigned int sId = myInvokee->getLocalSdp()->getSdpDescriptor().getSessionId(); MediaController::instance().resumeSession(sId, remoteSdp->getSdpDescriptor());}voidCallAgent::dohold(){ cpLog(LOG_DEBUG, "CallAgent::dohold() this should be invoke in UAC Hold"); //UAC just stop the Media since recevied 200 OK for RE-INVITE unsigned int sId = myInvokee->getLocalSdp()->getSdpDescriptor().getSessionId(); MediaController::instance().suspendSession(sId); myState->inHold(*this);}voidCallAgent::requestResume(Sptr<SipMsg>& msg){ try{ Sptr<SipCommand> sCommand; sCommand.dynamicCast(myInvokee->getRequest()); assert(sCommand != 0); Sptr<SipSdp> remoteSdp; remoteSdp.dynamicCast(sCommand->getContentData(0)); assert(remoteSdp != 0); Sptr<StatusMsg> statusMsg = doholdresume200OKstuff(msg, remoteSdp->getSdpDescriptor()); myInvokee->sendMsg(statusMsg); int sessionId = myInvokee->getLocalSdp()->getSdpDescriptor().getSessionId(); MediaController::instance().resumeSession(sessionId, remoteSdp->getSdpDescriptor()); myState->inCall(*this); } catch(CInvalidStateException& e) { cpLog(LOG_ERR, "Invalid state transition:%s", e.getDescription().c_str()); }}voidCallAgent::reqResume(Sptr<SipMsg>& msg){ cpLog(LOG_DEBUG, "CallAgent::reqResume() this should be invoke in UAS Resume"); try { Sptr<SipCommand> sCommand; sCommand.dynamicCast(myInvokee->getRequest()); assert(sCommand != 0); Sptr<SipSdp> remoteSdp; remoteSdp.dynamicCast(sCommand->getContentData(0)); assert(remoteSdp != 0); Sptr<StatusMsg> statusMsg = doholdresume200OKstuff(msg, remoteSdp->getSdpDescriptor()); myInvokee->sendMsg(statusMsg); int sessionId = myInvokee->getLocalSdp()->getSdpDescriptor().getSessionId(); MediaController::instance().resumeSession(sessionId, remoteSdp->getSdpDescriptor()); strstream str; str << "INCALL " << ends; UaFacade::instance().postMsg(str.str()); myState->inCall(*this); } catch(CInvalidStateException& e) { cpLog(LOG_ERR, "Invalid state transition:%s", e.getDescription().c_str()); }}voidCallAgent::hold(UaBase& agent, const Sptr<SipMsg>& msg){ cpLog(LOG_DEBUG, "CallAgent::hold() this should be invoke in UAS Hold"); try { Sptr<SipCommand> sCommand; sCommand.dynamicCast(myInvokee->getRequest()); assert(sCommand != 0); Sptr<SipSdp> remoteSdp; remoteSdp.dynamicCast(sCommand->getContentData(0)); assert(remoteSdp != 0); Sptr<StatusMsg> statusMsg = doholdresume200OKstuff(msg, remoteSdp->getSdpDescriptor()); myInvokee->sendMsg(statusMsg); unsigned int sId = myInvokee->getLocalSdp()->getSdpDescriptor().getSessionId(); MediaController::instance().suspendSession(sId); strstream str; str << "R_HOLD " << ends; UaFacade::instance().postMsg(str.str()); UaFacade::instance().postInfo(statusMsg); myState->inHold(*this); } catch(CInvalidStateException& e) { cpLog(LOG_ERR, "Invalid state transition:%s", e.getDescription().c_str()); }}voidCallAgent::startSession(SdpSession& localSdp, SdpSession& remoteSdp){ Sptr<MediaDevice> mDevice; unsigned sessionId = localSdp.getSessionId(); MediaController::instance().addToSession(localSdp, remoteSdp); mDevice = UaFacade::instance().getMediaDevice(getId()); MediaController::instance().addDeviceToSession(sessionId, mDevice); if(UaFacade::instance().getMode() == CALL_MODE_ANNON) { Sptr<FileMediaDevice> mFDevice; mFDevice.dynamicCast(mDevice); string toUser = myInvokee->getRequest()->getTo().getUser().logData(); toUser += ".wav"; mFDevice->setFileToPlay(toUser); MediaController::instance().startSession(sessionId, VSDP_SND); } else if(UaFacade::instance().getMode() == CALL_MODE_VMAIL) {#ifdef USE_VM Data caller, called, sReason; Sptr<SipMsg> sMsg = myInvokee->getRequest(); cpLog(LOG_DEBUG, "******* INVITE:%s", sMsg->encode().c_str()); caller = sMsg->getFrom().getUser(); if(sMsg->getNumDiversion()) { SipDiversion sDiversion = sMsg->getDiversion(); Sptr<SipUrl> sUrl; sUrl.dynamicCast(sDiversion.getUrl()); if(sUrl != 0) { called = sUrl->getUserValue(); } sReason = sDiversion.getReason(); } else { called = sMsg->getTo().getUser(); } Sptr<VmcpDevice> vDevice; vDevice.dynamicCast(mDevice); assert(vDevice != 0); vDevice->provideCallInfo(caller, called, sReason); MediaController::instance().startSession(sessionId);#endif } else { MediaController::instance().startSession(sessionId); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -