📄 sdp2session.cxx
字号:
} // SdpSession::addressTypeString///voidSdpSession::encodeOrigin (ostrstream& s){ s << "o=" << username << ' ' << sessionId << ' ' << version << ' ' << networkTypeString() << ' ' << addressTypeString() << ' ' << address << "\r\n";} // SdpSession::encodeOrigin///voidSdpSession::encodeSessionName (ostrstream& s){ s << "s=" << sessionName << "\r\n";} // SdpSession::encodeSessionName///voidSdpSession::encodeSessionInformation (ostrstream& s){ if (sessionInfo.length() > 0) { s << "i=" << sessionInfo << "\r\n"; }} // SdpSession::encodeSessionInformation///voidSdpSession::encodeURI (ostrstream& s){ if (uriInfo.length() > 0) { s << "u=" << uriInfo << "\r\n"; }} // SdpSession::encodeURI///voidSdpSession::encodeEmailAddress (ostrstream& s){ list<Data>::iterator iter = emailList.begin(); while (iter != emailList.end()) { s << "e=" << *iter << "\r\n"; ++iter; }} // SdpSession::encodeEmailAddress///voidSdpSession::encodePhoneNumber (ostrstream& s){ list <Data>::iterator iter = phoneList.begin(); while (iter != phoneList.end()) { s << "p=" << *iter << "\r\n"; ++iter; }} // SdpSession::encodePhoneNumber///voidSdpSession::encodeTime (ostrstream& s){ list < SdpTime > ::iterator iter = sdpTimeList.begin(); while (iter != sdpTimeList.end()) { iter->encode (s); ++iter; }} // SdpSession::encodeTime///voidSdpSession::encodeTimeZoneAdjustment (ostrstream& s){ if (zoneAdjustmentList.size() > 0) { list <SdpZoneAdjustment>::iterator iter; iter = zoneAdjustmentList.begin(); s << "z=" << (*iter).getAdjustmentTime() << ' ' << (*iter).getOffset(); ++iter; while (iter != zoneAdjustmentList.end()) { s << ' ' << (*iter).getAdjustmentTime() << ' ' << (*iter).getOffset(); ++iter; } s << "\r\n"; }} // SdpSession::encodeTimeZoneAdjustment///voidSdpSession::encodeMedia (ostrstream& s){ list < SdpMedia* > ::iterator mediaIterator = mediaList.begin(); while (mediaIterator != mediaList.end()) { (*mediaIterator)->encode (s); ++mediaIterator; }} // SdpSession::encodeMedia///voidSdpSession::setConnection (const SdpConnection& conn){ if (!connection) { connection = new SdpConnection; } *connection = conn;} // SdpSession::setConnection///SdpConnection*SdpSession::getConnection (){ return connection;} // SdpSession::getConnection///static const int SdpTextPayloadLength = 2024;///DataSdpSession::encode(){ buf[0] = '\0'; ostrstream s (buf, SdpTextPayloadLength); if (!isValid) { //TODO throw SdpExceptionInvalid ("Invalid SDP" , __FILE__, __LINE__ ); // or // throw SDPExceptions (InvalidContent); } else { // Encoding order is important // v=0 by default - no other value as of now encodeVersion (s); // o= owner/creator and session identifier encodeOrigin (s); // s= session name encodeSessionName (s); // i=* session information encodeSessionInformation (s); // u=* URI of description encodeURI (s); // e=* email address encodeEmailAddress (s); // p=* phone number encodePhoneNumber (s); // c=* connection information (not required if included in all media) if (connection) { connection->encode (s); } // b=* bandwidth information if (bandwidth) { bandwidth->encode (s); } // Time Description encodeTime (s); // z=* time zone adjustment encodeTimeZoneAdjustment (s); // k=* encryption key if ( encryptkey ) { encryptkey->encode(s); } // a=* zero or more session attribute lines if (attribute) { attribute->encode (s); } // Media Description encodeMedia (s); } s << ends; return s.str();} // SdpSession::encodebool SdpSession::decode(Data buffer){ list <Data> lines; while(buffer.length() > 0) { bool mFail=true; //If CRLF is found mFail will be set to false Data tmp = buffer.getLine(&mFail); if(tmp.length()) lines.push_back(tmp); //See if no more lines if(mFail) { //No CRLF found, take the remaining buffer as the //line if(buffer.length()) lines.push_back(buffer); break; } } bool result = decode(lines); return result;}bool SdpSession::decode(list <Data>& lines){ cpLog(LOG_DEBUG, "number of lines: %d" , lines.size()); if (lines.size() < 3) { cpLog( LOG_ERR, "Sdp decode fail, too few lines" ); isValid = false; return false; } sdpTimeList.clear(); list<Data>::iterator linecount; linecount = lines.begin(); { // lines[0] is the version line -- ignore Data s = (*linecount); if (!((*linecount) == "v=0\r" || (*linecount) == "v=0")) if (!(s == "v=0")) { // no good cpLog(LOG_ERR, "SDP: did not find version in:%s", (*linecount).logData()); return false; } ++linecount; while (linecount != lines.end()) { // this switch parses lines as they come if ((*linecount)[0] == 'o') { cpLog(LOG_DEBUG, "got o= line" ) ; // this is the options line -- do we care about it? // parse line 1 for the proper stuff s = (*linecount); s.parse("="); deque<Data> optionsList; split(optionsList, s, " "); if (optionsList.size() < 6) { // not enough parameters cpLog( LOG_ERR, "Parameter count < 6: %s", (*linecount).logData() ); if ( linecount != lines.end() ) { ++linecount; } continue; } username = optionsList[0]; LocalScopeAllocator localSession; LocalScopeAllocator localVersion; sessionId = atoi(optionsList[1].getData(localSession)); version = atoi(optionsList[2].getData(localVersion)); if (optionsList[3] == SdpNetworkTypeIN) { networkType = NetworkTypeInternet; } else { cpLog( LOG_ERR, "Unknown network type %s", optionsList[3].logData() ); if ( linecount != lines.end() ) { ++linecount; } continue; } if (optionsList[4] == SdpAddressTypeIP4) { addressType = AddressTypeIPV4; } else if (optionsList[4] == SdpAddressTypeIP6) { addressType = AddressTypeIPV6; } else { cpLog( LOG_ERR, "Unknown address type %s", optionsList[4].logData() ); if ( linecount != lines.end() ) { ++linecount; } continue; } LocalScopeAllocator lAddress; address = optionsList[5].getData(lAddress); } else if ((*linecount)[0] == 's') { cpLog(LOG_DEBUG, "got s= line" ) ; s = (*linecount); s.parse("="); sessionName = s; } else if((*linecount)[0] == 'i') { cpLog(LOG_DEBUG, "got i= line") ; s = (*linecount); s.parse("="); sessionInfo = s; } else if((*linecount)[0] == 'u') { cpLog(LOG_DEBUG, "got u= line") ; s = (*linecount); s.parse("="); uriInfo = s; } else if((*linecount)[0] == 'e') { // Collect all email addresses while ((linecount != lines.end()) && ((*linecount)[0] == 'e')) { cpLog(LOG_DEBUG, "Session: got %s", (*linecount).logData()); s = (*linecount); s.parse("=");// s = (*linecount);// s.erase(0, 2);// chomp (&s); emailList.push_back(s); ++linecount; } if (linecount != lines.end()) { // Not done yet, adjust line position --linecount; } } else if((*linecount)[0] == 'p') { // Collect all phone numbers while ((linecount != lines.end()) && ((*linecount)[0] == 'p')) { cpLog(LOG_DEBUG, "Session: got %s", (*linecount).logData()); s = (*linecount); s.parse("=");// s = (*linecount);// s.erase(0, 2);// chomp (&s); phoneList.push_back(s); ++linecount; } if (linecount != lines.end()) { // adjust line position for the next description --linecount; } } else if ((*linecount)[0] == 'c') { cpLog(LOG_DEBUG, "got c= line") ; // this is a c= line s = (*linecount); s.parse("=");// s = (*linecount);// s.erase(0, 2);// chomp (&s); //create the connection object, and store details there. try { if (!connection) { connection = new SdpConnection(s); assert (connection); } else { SdpConnection conn (s); (*connection) = conn; } } catch (SdpExceptions& exp) { switch (exp.value) { case UNKNOWN_NETTYPE : return false; break; case UNKNOWN_ADDRTYPE : return false; break; case PARAM_NUMERR : return false; break; default: // Unknown exception assert(0); break; } } } else if ((*linecount)[0] == 't') { // Collect all Time Descriptions while ((linecount != lines.end()) && ((*linecount)[0] == 't')) { cpLog(LOG_DEBUG_STACK, "Session: got %s", (*linecount).logData()); list<Data> timeDescriptionLines; // Holding place for a // Time Description timeDescriptionLines.push_back ((*linecount)); ++linecount; // Get the optional "r=" line
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -