Added an extra parameter to SDPSession::updateFormats() allowing it to add or remove media.

Use the SDPSession::updateFormats() method in SIP instead of reimplementing it.


git-svn-id: http://voip.null.ro/svn/yate@2873 acf43c95-373e-0410-b603-e72c3f656dc1
This commit is contained in:
paulc 2009-10-20 22:54:56 +00:00
parent 221cbb9019
commit 3624562f55
3 changed files with 53 additions and 35 deletions

View File

@ -490,12 +490,42 @@ MimeSdpBody* SDPSession::createPasstroughSDP(NamedList& msg, bool update)
}
// Update media format lists from parameters
void SDPSession::updateFormats(const NamedList& msg)
void SDPSession::updateFormats(const NamedList& msg, bool changeMedia)
{
if (!m_rtpMedia)
return;
unsigned int n = msg.length();
for (unsigned int i = 0; i < n; i++) {
unsigned int i;
if (changeMedia) {
// check if any media is to be removed
for (i = 0; i < n; i++) {
const NamedString* p = msg.getParam(i);
if (!p)
continue;
// search for media_MEDIANAME parameters
String tmp = p->name();
if (!tmp.startSkip("media",false))
continue;
if (tmp && (tmp[0] != '_'))
continue;
// only check for explicit disabled media
if (p->toBoolean(true))
continue;
if (tmp.null())
tmp = "audio";
else
tmp = tmp.substr(1);
SDPMedia* rtp = static_cast<SDPMedia*>(m_rtpMedia->operator[](tmp));
if (!rtp)
continue;
Debug(m_parser,DebugNote,"Removing disabled media '%s' [%p]",
tmp.c_str(),this);
m_rtpMedia->remove(rtp,false);
mediaChanged(*rtp);
TelEngine::destruct(rtp);
}
}
for (i = 0; i < n; i++) {
const NamedString* p = msg.getParam(i);
if (!p)
continue;
@ -505,14 +535,29 @@ void SDPSession::updateFormats(const NamedList& msg)
continue;
if (tmp && (tmp[0] != '_'))
continue;
const char* trans = 0;
// make sure we don't re-add explicitely disabled media
if (changeMedia && msg.getBoolValue("media"+tmp,true))
trans = msg.getValue("transport"+tmp);
if (tmp.null())
tmp = "audio";
else
tmp = tmp.substr(1);
SDPMedia* rtp = static_cast<SDPMedia*>(m_rtpMedia->operator[](tmp));
if (rtp && rtp->update(*p))
Debug(m_parser,DebugNote,"Formats for '%s' changed to '%s' [%p]",
tmp.c_str(),p->c_str(),this);
if (rtp) {
if (rtp->update(*p))
Debug(m_parser,DebugNote,"Formats for '%s' changed to '%s' [%p]",
tmp.c_str(),p->c_str(),this);
}
else if (*p) {
Debug(m_parser,DebugNote,"Got formats '%s' for absent media '%s' [%p]",
p->c_str(),tmp.c_str(),this);
if (trans) {
rtp = new SDPMedia(tmp,trans,p->c_str());
m_rtpMedia->append(rtp);
mediaChanged(*rtp);
}
}
}
}

View File

@ -489,8 +489,9 @@ public:
/**
* Update media format lists from parameters
* @param msg Parameter list
* @param changeMedia True to update media list if required
*/
void updateFormats(const NamedList& msg);
void updateFormats(const NamedList& msg, bool changeMedia = false);
/**
* Add raw SDP forwarding parameter from body if SDP forward is enabled

View File

@ -335,7 +335,6 @@ private:
bool processTransaction2(SIPEvent* ev, const SIPMessage* msg, int code);
SIPMessage* createDlgMsg(const char* method, const char* uri = 0);
bool emitPRACK(const SIPMessage* msg);
void updateFormats(const Message& msg);
bool startClientReInvite(Message& msg);
// Build the 'call.route' and NOTIFY messages needed by the transfer thread
bool initTransfer(Message*& msg, SIPMessage*& sipNotify, const SIPMessage* sipRefer,
@ -2930,7 +2929,7 @@ bool YateSIPConnection::msgAnswered(Message& msg)
{
Lock lock(driver());
if (m_tr && (m_tr->getState() == SIPTransaction::Process)) {
updateFormats(msg);
updateFormats(msg,true);
SIPMessage* m = new SIPMessage(m_tr->initialMessage(), 200);
copySipHeaders(*m,msg);
MimeSdpBody* sdp = createPasstroughSDP(msg);
@ -3228,33 +3227,6 @@ void YateSIPConnection::callRejected(const char* error, const char* reason, cons
setReason(reason,code);
}
// Update media format lists from a message
void YateSIPConnection::updateFormats(const Message& msg)
{
if (!m_rtpMedia)
return;
unsigned int n = msg.length();
for (unsigned int i = 0; i < n; i++) {
const NamedString* p = msg.getParam(i);
if (!p)
continue;
// search for formats_MEDIANAME parameters
String tmp = p->name();
if (!tmp.startSkip("formats",false))
continue;
if (tmp && (tmp[0] != '_'))
continue;
if (tmp.null())
tmp = "audio";
else
tmp = tmp.substr(1);
SDPMedia* rtp = static_cast<SDPMedia*>(m_rtpMedia->operator[](tmp));
if (rtp && rtp->update(*p))
Debug(this,DebugNote,"Formats for '%s' changed to '%s'",tmp.c_str(),p->c_str());
}
}
// Start a client reINVITE transaction
bool YateSIPConnection::startClientReInvite(Message& msg)
{