📄 sdp.cxx
字号:
// $Id: sdp.cxx,v 1.3 1999/08/31 01:53:27 cullen Exp $/*This library is free software; you can redistribute it and/or modifyit under the terms of the GNU Lesser General Public License aspublished by the Free Software Foundation; either version 2 of theLicense, or (at your option) any later version.This library is distributed in the hope that it will be useful, butWITHOUT ANY WARRANTY; without even the implied warranty ofMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNULesser General Public License for more details.You should have received a copy of the GNU Lesser General PublicLicense along with this library; if not; write to the Free SoftwareFoundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307USA.*/// $Log: sdp.cxx,v $// Revision 1.3 1999/08/31 01:53:27 cullen// Cullen check in some code from Luan that has things needed to compile//// Revision 1.8 1999/07/23 23:57:25 bogawa//// the mgcp/examples/gateway Makefile was changed to use the new make file system.//// improve the global makefiles. Now, most targets use these makefiles// which should simplify the lives of the users, we hope.//// Key features include support for nested object directories as well as// a more coherent install strategy (so that installs are less likely to// produce error messages)//// in addition, the code was cleaned up to add a few new features and to// remove some warnings.//// Revision 1.7 1999/07/12 23:35:33 bogawa//// fix for the sdp.//// Revision 1.6 1999/06/30 06:09:08 bogawa//// update copyright and license//// Revision 1.5 1999/06/29 23:42:03 bogawa//// Updated copyright notice.//// Revision 1.4 1999/06/28 21:30:37 bogawa//// Update to the latest version of the MGCP stack.//// Revision 1.3 1999/06/09 08:16:44 bogawa//// Add copyright notices.//// Revision 1.2 1999/06/09 01:04:59 bogawa//// Changes to make the new structure compile correctly, and to allow the// code to use the new hardware structure. gateway1 is now using the// new structure fully, while gateway2 is using it partially (actually// not very much).//// A future version should be much cleaner.//// implement simple session description protocol#include <assert.h>#include "sdp.hxx"#include "mstring.h"#include <strstream>std::mstring* SDPDescriptor::encode(){ ostrstream s(buf, 1024); buf[0] = '\0'; // encode the puppy s << "v=" << protocolVersion << "\r\n"; s << "o=" << username << " " << sessionId << " " << version << " "; if(networkType == NetworkTypeInternet) { s << "IN "; } else { s << "unknown "; } if(addressType == AddressTypeIPV4) { s << "IP4 "; } else { s << "unknown "; } s << address << "\r\n"; s << "s=" << sessionName << "\r\n"; s << "c="; if(networkType == NetworkTypeInternet) { s << "IN "; } else { s << "unknown "; } if(addressType == AddressTypeIPV4) { s << "IP4 "; } else { s << "unknown "; } s << address << "\r\n"; s << "m=" ; if(mediaType == MediaTypeAudio) { s << "audio "; } s << port << " "; if(transportType == TransportTypeRTP) { s << "RTP/AVP"; } std::vector <int>::iterator iter; iter = formatList.begin(); assert (iter != formatList.end()); while(iter != formatList.end()) { s << " " << static_cast<int>(*iter); ++iter; } s << "\r\n" << '\0'; myEncoding = s.str(); return &myEncoding;}bool SDPDescriptor::decode(const std::mstring& buffer){ std::vector<std::mstring> lines; buffer.split(&lines, "\n", "", 0, std::mstring::sep_single); return decode(lines);}bool SDPDescriptor::decode(const std::vector<std::mstring>& parms){ std::vector<std::mstring> lines(parms); return decode(lines);}bool SDPDescriptor::decode(std::vector<std::mstring>& lines){ if(lines.size() <= 3) { // no good -- return false; } std::vector<std::mstring>::iterator linecount; linecount = lines.begin(); { // lines[0] is the version line -- ignore linecount->rtrimc('\r'); if(*linecount != "v=0") { // no good return false; } ++linecount; linecount->rtrimc('\r'); if(((*linecount).find("o=")) != 0) { // match on this line is BAD return false; } // parse line 1 for the proper stuff (*linecount).erase(0, 2); std::vector<std::mstring> optionsList; linecount->split(&optionsList, " ", ""); if(optionsList.size() < 6) { // not enough parameters return false; } username = optionsList[0]; sessionId = atoi(optionsList[1].c_str()); version = atoi(optionsList[2].c_str()); if(optionsList[3] == "IN") { networkType = NetworkTypeInternet; } else { // bad! return false; } if(optionsList[4] == "IP4") { addressType = AddressTypeIPV4; } else { return false; } address = optionsList[5].c_str(); // parse the session name ++linecount; linecount->rtrimc('\r'); if(((*linecount).find("s=")) != 0) { return false; } sessionName = (*linecount).substr(2, (*linecount).length() - 2); ++linecount; while((linecount != lines.end()) && ((*linecount).find("m=") != 0)) { linecount->rtrimc('\r'); // pre media-channel items if((*linecount).find("c=") == 0) { // this is a c= line std::vector<std::mstring> cList; linecount->split(&cList, " ", ""); // actually we'll ignore this... ? } ++linecount; } // media channel items while(linecount != lines.end()) { linecount->rtrimc('\r'); if((*linecount).find("m=") == 0) { // this is a m= line std::vector<std::mstring> mList; linecount->split(&mList, " ", ""); if(mList.size() < 4) { assert(0); return false; } std::vector<std::mstring>::iterator mListIter; mListIter = mList.begin(); if(*mListIter == "audio") { mediaType = MediaTypeAudio; } ++mListIter; // xxx needs splitting help port = atoi((*mListIter).c_str()); ++mListIter; if(*mListIter == "RTP/AVP") { transportType = TransportTypeRTP; } else if(*mListIter == "UDP") { transportType = TransportTypeUDP; } ++mListIter; formatList.clear(); while(mListIter != mList.end()) { // these are all format list items formatList.push_back(atoi((*mListIter).c_str())); ++mListIter; } assert(formatList.size() != 0); } ++linecount; } } isValid = true; return true;};
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -