📄 sdphandler.cxx
字号:
/* ==================================================================== * The Vovida Software License, Version 1.0 * * Copyright (c) 2000 Vovida Networks, Inc. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The names "VOCAL", "Vovida Open Communication Application Library", * and "Vovida Open Communication Application Library (VOCAL)" must * not be used to endorse or promote products derived from this * software without prior written permission. For written * permission, please contact vocal@vovida.org. * * 4. Products derived from this software may not be called "VOCAL", nor * may "VOCAL" appear in their name, without prior written * permission of Vovida Networks, Inc. * * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND * NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL VOVIDA * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH * DAMAGE. * * ==================================================================== * * This software consists of voluntary contributions made by Vovida * Networks, Inc. and many individuals on behalf of Vovida Networks, * Inc. For more information on Vovida Networks, Inc., please see * <http://www.vovida.org/>. * */static const char* const SdpHandler_cxx_Version = "$Id: SdpHandler.cxx,v 1.16 2002/12/06 19:52:52 sprajpat Exp $";#include "SdpHandler.hxx"#include "UaConfiguration.hxx"#include "UaDevice.hxx"#include "Sdp2Session.hxx"#include "Sdp2Connection.hxx"#include "Sdp2Media.hxx"using namespace Vocal;using Vocal::SDP::SdpSession;using Vocal::SDP::SdpConnection;using Vocal::SDP::SdpMedia;using Vocal::SDP::MediaAttributes;using Vocal::SDP::ValueAttribute;using Vocal::SDP::SdpRtpMapAttribute;void addSdpToMsg( SipMsg& msg, Data rtpRate, int rtpPort ){ // add an appropriate SDP object to this message Sptr<SipSdp> sipSdp; sipSdp.dynamicCast ( msg.getContentData( 0 ) ); if ( sipSdp != 0 ) { SdpSession sdpDesc = sipSdp->getSdpDescriptor(); list < SdpMedia* > mediaList; mediaList = sdpDesc.getMediaList(); list < SdpMedia* > ::iterator mediaIterator = mediaList.begin(); MediaAttributes* mediaAttrib; mediaAttrib = (*mediaIterator)->getMediaAttributes(); (*mediaIterator)->getStringFormatList()->clear(); if ( mediaAttrib == 0 ) { mediaAttrib = new MediaAttributes(); assert( mediaAttrib ); (*mediaIterator)->setMediaAttributes( mediaAttrib ); } ValueAttribute* attrib = new ValueAttribute(); attrib->setAttribute( "ptime" ); LocalScopeAllocator lo; attrib->setValue( rtpRate.getData(lo) ); //add the rtpmap attribute for the default codec SdpRtpMapAttribute* rtpMapAttrib = new SdpRtpMapAttribute(); rtpMapAttrib->setPayloadType( 0 ); rtpMapAttrib->setEncodingName( "PCMU" ); rtpMapAttrib->setClockRate( 8000 ); (*mediaIterator)->addFormat( rtpMapAttrib->getPayloadType() ); //add the rtpmap attribute for the dtmf in rtp SdpRtpMapAttribute* rtpMapEventAttrib = new SdpRtpMapAttribute(); rtpMapEventAttrib->setPayloadType( 100 ); rtpMapEventAttrib->setEncodingName( "telephone-event" ); rtpMapEventAttrib->setClockRate( 8000 ); // add the value attribute for telephone-event ValueAttribute* eventAttrib = new ValueAttribute(); eventAttrib->setAttribute( "fmtp" ); eventAttrib->setValue( "100 0-11" ); // add the value attribute just created to the media attribute object mediaAttrib->addValueAttribute( attrib ); mediaAttrib->addmap( rtpMapAttrib ); (*mediaIterator)->addFormat( rtpMapEventAttrib->getPayloadType() ); mediaAttrib->addmap( rtpMapEventAttrib ); mediaAttrib->addValueAttribute( eventAttrib ); sipSdp->setSdpDescriptor( sdpDesc ); sipSdp->setRtpPort( rtpPort ); // if the NAT address is set, do something with it if(UaConfiguration::instance()->getNATAddress() != "") { Data host = UaConfiguration::instance()->getNATAddress(); cpLog( LOG_DEBUG, "Replace connection address with NAT firewall WAN address %s", host.logData() ); setHost(*sipSdp, host); } } else { // could not add the SDP for some reason cpLog(LOG_ERR, "could not add SDP to this object"); }}intgetRtpPacketSize ( SipSdp& remoteSdp ){ Data rtpPacketSize; SdpSession sdpDesc = remoteSdp.getSdpDescriptor(); // declare the media list pointer list < SdpMedia* > mediaList; // get the media list pointer from the session object mediaList = sdpDesc.getMediaList(); if( mediaList.size() == 0 ) { cpLog( LOG_DEBUG, "No remote media in 180/183 SDP" ); return -1; } else // mediaList != 0 { // declare the media list iterator and assign it to the // first media object on the list list < SdpMedia* > ::iterator mediaIterator = mediaList.begin(); if( mediaIterator == mediaList.end() ) { cpLog( LOG_ERR, "No remote media in 180/183 SDP" ); return -1; } else // We have remote media in 180/183 SDP { vector< Data >* formatList = (*mediaIterator)->getStringFormatList(); if ( formatList != 0 && (*formatList)[0] == "0" ) { cpLog( LOG_DEBUG, "Getting media attribute format"); // declare the media attribute list pointer MediaAttributes* mediaAttrib; // get the media attribute list pointer from the media // object pointed by the iterator mediaAttrib = (*mediaIterator)->getMediaAttributes(); if ( mediaAttrib != 0 ) { vector < ValueAttribute* > * valueAttribList = mediaAttrib->getValueAttributes(); vector < ValueAttribute* > ::iterator attribIterator = valueAttribList->begin(); while ( attribIterator != valueAttribList->end() ) { char* attribName = (*attribIterator)->getAttribute(); if ( strcmp(attribName, "ptime") == 0 ) { rtpPacketSize = (*attribIterator)->getValue(); return rtpPacketSize.convertInt(); break; } attribIterator++; } } } else { return -1; } } } // end 'else // mediaList != 0' return -1;}voidsetRtpPacketSize(SipSdp& sipSdp, int packetSize){ char buf[10]; sprintf(buf, "%d", packetSize); Data rtpPacketSize = buf; // add rtpPacketSize to sipSdp SdpSession sdpDesc = sipSdp.getSdpDescriptor(); // get the media list pointer from the session object list < SdpMedia* > mediaList; mediaList = sdpDesc.getMediaList(); // declare the media list iterator and assign it to the // first media object on the list list < SdpMedia* > ::iterator mediaIterator; mediaIterator = mediaList.begin(); // get the media attribute list pointer from the media // object pointed by the iterator MediaAttributes* mediaAttrib; mediaAttrib = (*mediaIterator)->getMediaAttributes(); if ( mediaAttrib != 0 ) { vector < ValueAttribute* > * valueAttribList = mediaAttrib->getValueAttributes(); vector < ValueAttribute* > ::iterator attribIterator = valueAttribList->begin(); LocalScopeAllocator lo; while ( attribIterator != valueAttribList->end() ) { char* attribName = (*attribIterator)->getAttribute(); if ( strcmp(attribName, "ptime") == 0 ) { (*attribIterator)->setValue(rtpPacketSize.getData(lo)); return; break; } attribIterator++; } } else { return; }}voidsetHost(SipSdp& sipSdp, Data hostAddr){ // set IP address and port SdpConnection connection; LocalScopeAllocator lo; connection.setUnicast(hostAddr.getData(lo)); if(hostAddr.find(":") != Data::npos) { connection.setAddressType(SDP::AddressTypeIPV6); sipSdp.setAddressType(SDP::AddressTypeIPV6); } sipSdp.setConnAddress(connection); sipSdp.setAddress( hostAddr );}voidsetStandardSdp(SipSdp& sipSdp, Data hostAddr, int port){ setupMedia(sipSdp, hostAddr, port); // do the media stuff SdpSession sdpDesc = sipSdp.getSdpDescriptor(); // declare the media list pointer list < SdpMedia* > mediaList; // get the media list pointer from the session object mediaList = sdpDesc.getMediaList(); // declare the media list iterator and assign it to the first media //object on the list list < SdpMedia* > ::iterator mediaIterator = mediaList.begin(); vector < Data > * formatList = (*mediaIterator)->getStringFormatList(); if ( formatList != 0 ) { formatList->clear(); } //using the default codec (*mediaIterator)->addFormat( 0 ); setUlaw(sipSdp, 8000); setRtpPacketSize(sipSdp, UaConfiguration::instance()->getNetworkRtpRate());}voidsetUlaw(SdpSession& sdpDesc, int rate){ // declare the media list pointer list < SdpMedia* > mediaList; // get the media list pointer from the session object mediaList = sdpDesc.getMediaList(); // declare the media list iterator and assign it to the first media //object on the list assert(mediaList.size() != 0); list < SdpMedia* > ::iterator mediaIterator = mediaList.begin(); assert(mediaIterator != mediaList.end()); vector < Data > * formatList = (*mediaIterator)->getStringFormatList(); if ( formatList != 0 ) { formatList->clear(); } //using the default codec (*mediaIterator)->addFormat( 0 ); SdpMedia* media = 0; media = *mediaIterator; // declare the media attribute list pointer MediaAttributes* mediaAttrib; // get the media attribute list pointer from the media object pointed //by the iterator mediaAttrib = (*mediaIterator)->getMediaAttributes(); if ( mediaAttrib == 0 ) { mediaAttrib = new MediaAttributes(); media->setMediaAttributes(mediaAttrib); } // get, then set, the media attribute mediaAttrib->flushValueAttributes(); mediaAttrib->flushrtpmap(); // create the new value attribute object ValueAttribute* attrib = new ValueAttribute(); // set the attribute and its value attrib->setAttribute("ptime"); LocalScopeAllocator lo; attrib->setValue( Data( UaConfiguration::instance()->getNetworkRtpRate() ).getData(lo) ); //add the rtpmap attribute for the default codec SdpRtpMapAttribute* rtpMapAttrib = new SdpRtpMapAttribute(); rtpMapAttrib->setPayloadType(0); rtpMapAttrib->setEncodingName("PCMU"); rtpMapAttrib->setClockRate(rate); // add the value attribute just created to the media attribute object mediaAttrib->addValueAttribute(attrib); mediaAttrib->addmap(rtpMapAttrib);}voidsetUlaw(SipSdp& sipSdp, int rate){ // do the media stuff SdpSession sdpDesc = sipSdp.getSdpDescriptor(); setUlaw(sdpDesc, rate); sipSdp.setSdpDescriptor(sdpDesc);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -