⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sdp2media.cxx

📁 SIP(Session Initiation Protocol)是由IETF定义
💻 CXX
📖 第 1 页 / 共 2 页
字号:
/* ==================================================================== * 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 SdpMedia_cxx_Version =    "$Id: Sdp2Media.cxx,v 1.3 2002/03/15 01:56:03 sprajpat Exp $";#include "global.h"#include "Data.hxx"#include "support.hxx"#include "Sdp2Exceptions.hxx"#include "Sdp2Media.hxx"using Vocal::SDP::SdpMedia;using Vocal::SDP::TransportType;using Vocal::SDP::SdpMediaType;const int SdpMedia::MaxFormatIntValue = 15;///SdpMedia::SdpMedia(){    mediaType = MediaTypeAudio;    mediaTypeString = "audio";    port = -1;    numPorts = 0;    transportType = TransportTypeRTP;    formatList.clear();    formatList.push_back( "0" );    formatListInt.clear();    formatListInt.push_back( 0 );    mediaAttrib = 0;    connection = 0;    bandwidth = 0;    encryptkey = 0;    mediaInfo = "";}    // SdpMedia::SdpMedia///SdpMedia::SdpMedia (list<Data>& mediaDetails){    //initialize all pointers    bandwidth = 0;    mediaAttrib = 0;    connection = 0;    encryptkey = 0;    list<Data>::iterator linecount;    linecount = mediaDetails.begin();    //print Media details    list<Data>::iterator tempcount;    tempcount = mediaDetails.begin();    while (tempcount != mediaDetails.end())    {        cpLog(LOG_DEBUG_STACK, "SdpMedia: %s", (*tempcount).logData());        tempcount++;    }    while (linecount != mediaDetails.end())    {        if ((*linecount)[0] == 'm')        {            Data lineStr = (*linecount);	    lineStr.parse("=");            list<Data> mList;	    bool finished = false;	    while(!finished) 	    {		Data x = lineStr.parse(" ", &finished);		if(finished)		{		    x = lineStr;		}		mList.push_back(x);	    }            if (mList.size() < 4)            {                cpLog(LOG_ERR, "SdpMedia: m= size < 4");                throw SdpExceptions(PARAM_NUMERR);            }            else	    {                cpLog(LOG_DEBUG_STACK, "SdpMedia: m= size >4");	    }            //parse media items.            list<Data>::iterator mListIter;            mListIter = mList.begin();            mediaTypeString = *mListIter;            if (mediaTypeString == Data("audio"))            {                mediaType = MediaTypeAudio;                cpLog(LOG_DEBUG_STACK, "Found m=audio");            }            else if (mediaTypeString == Data("video"))            {                mediaType = MediaTypeVideo;                cpLog(LOG_DEBUG_STACK, "Found m=video");            }            else            {                mediaType = MediaTypeUnknown;                cpLog( LOG_DEBUG_STACK, "Found m=%s", mediaTypeString.logData() );            }            ++mListIter;            /** port may be <port>/<num of ports>                So, split mListIter again on /  */            Data portDetails = (*mListIter);            list<Data> portList;	    finished = false;	    while(!finished) 	    {		Data x = portDetails.parse("/", &finished);		if(finished)		{		    x = portDetails;		}		portList.push_back(x);	    }	    if(portList.begin() != portList.end())	    {		LocalScopeAllocator lPort;		port = strtol((*portList.begin()).getData(lPort), (char**)NULL, 10);		cpLog(LOG_DEBUG_STACK, "SDP port: %d " , port);	    }            if (portList.size() == 2)            {                //contains the number of ports.		LocalScopeAllocator lNumPorts;                numPorts = atoi((++portList.begin())->getData(lNumPorts));            }            else            {                numPorts = 0;            }            ++mListIter;            if (*mListIter == SdpMediaTransportRTPAVP)            {                transportType = TransportTypeRTP;            }            else if (*mListIter == SdpMediaTransportUDP)            {                transportType = TransportTypeUDP;            }            //handle the format list.            formatList.clear();            formatListInt.clear();            char format[ MaxFormatIntValue+1 ];            format[ MaxFormatIntValue ] = '\0';            char* endPtr = 0;            int formatInt = 0;            ++mListIter;            while (mListIter != mList.end())            {                //these are all format list items                cpLog( LOG_DEBUG_STACK, "Media format: %s", (*mListIter).logData() );                formatList.push_back( *mListIter );		LocalScopeAllocator lItem;                strncpy( format, (*mListIter).getData(lItem), MaxFormatIntValue );                formatInt = strtol( format, &endPtr, 10 );                if( endPtr == format )    // Format is not an integer                {                    cpLog( LOG_DEBUG, "Non-integer media format: %s", (*mListIter).logData() );                }                else                      // Format is an integer                {                    cpLog( LOG_DEBUG, "Integer media format: %d", formatInt );                    formatListInt.push_back( formatInt );                }                ++mListIter;            }        }// if line = m.        else if ((*linecount)[0] == 'a')        {            try            {                if (!mediaAttrib)                {                    //create the MediaAttribute object.                    mediaAttrib = new MediaAttributes();                    assert(mediaAttrib);                }                Data attrib = (*linecount);		attrib.parse("=");		//                chomp (&attrib);                mediaAttrib->setAttribute(attrib);            }            catch (SdpExceptions& )            {                throw SdpExceptions(FAILED);            }        }        else if ((*linecount)[0] == 'b')        {            try            {                Data bw = (*linecount);		bw.parse("=");//                bw.erase(0, 2);//                chomp (&bw);                cpLog(LOG_DEBUG_STACK, "Bandwidth, before sending to C'tor:%s", bw.logData());                bandwidth = new SdpBandwidth(bw);                assert(bandwidth);            }            catch (SdpExceptions& )            {                throw SdpExceptions(FAILED);            }        }        else if ((*linecount)[0] == 'k')        {            try            {                if (encryptkey)                {                    delete encryptkey;                    encryptkey = 0;                }                Data key = (*linecount);		key.parse("=");//                key.erase(0, 2);//                chomp (&key);                cpLog(LOG_DEBUG, "Encryption key, before sending to C'tor:%s", key.logData());                encryptkey = new SdpEncryptkey(key);                assert(encryptkey);            }            catch (SdpExceptions& )            {                throw SdpExceptions(FAILED);            }        }        else if ((*linecount)[0] == 'c')        {            try            {                Data conn = (*linecount);		conn.parse("=");//                conn.erase(0, 2);//                chomp (&conn);                connection = new SdpConnection(conn);                assert(connection);            }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -