📄 sdp2media.cxx
字号:
catch (SdpExceptions& ) { throw SdpExceptions(FAILED); } } else if ((*linecount)[0] == 'i') { Data info = (*linecount); info.parse("=");// info.erase(0, 2);// chomp (&info); mediaInfo = info; } else if ((*linecount)[0] == '\r' || (*linecount)[0] == '\n' ) { //TODO make sure this is ok cpLog( LOG_DEBUG_STACK, "Empty line" ); } else { cpLog(LOG_ERR, "Unknown field in the media portion %s", (*linecount).logData()); throw SdpExceptions(UNKNOWN_FIELD); } linecount++; } // while} // SdpMedia::SdpMedia(list<Data>& mediaDetails)///const SdpMedia&SdpMedia::operator=(SdpMedia& newMedia){ mediaType = newMedia.mediaType; mediaTypeString = newMedia.mediaTypeString; port = newMedia.port; numPorts = newMedia.numPorts; transportType = newMedia.transportType; mediaInfo = newMedia.mediaInfo; cpLog(LOG_DEBUG_STACK, "Copied media, port, numPorts, transportType"); vector < Data > * newFormatList = newMedia.getStringFormatList(); assert(newFormatList); formatList = *newFormatList; vector < int > * newIntFormatList = newMedia.getFormatList(); if( newIntFormatList != 0 ) { formatListInt = *(newMedia.getFormatList()); } else { formatListInt.clear(); } cpLog(LOG_DEBUG_STACK, "SdpMedia: copied the format list"); if (newMedia.mediaAttrib) { if (!mediaAttrib) { mediaAttrib = new MediaAttributes; assert(mediaAttrib); } *(mediaAttrib) = *(newMedia.mediaAttrib); //copy parent details.// *((SdpAttributes*)(mediaAttrib)) = *((SdpAttributes*)(newMedia.mediaAttrib)); cpLog(LOG_DEBUG_STACK, "SdpMedia: Copied Media attributes"); } else //if not defined now, but previously defined, remove previous definition. { if (mediaAttrib) { delete mediaAttrib; mediaAttrib = 0; } } if (newMedia.connection) { if (!connection) { connection = new SdpConnection; assert(connection); } *(connection) = *(newMedia.connection); cpLog(LOG_DEBUG_STACK, "SdpMedia: copied connection"); } else { if (connection) { delete connection; connection = 0; } } if (newMedia.bandwidth) { if (!bandwidth) { bandwidth = new SdpBandwidth; assert(bandwidth); } *(bandwidth) = *(newMedia.bandwidth); cpLog(LOG_DEBUG_STACK, "SdpMedia:copied bandwidth"); } else { if (bandwidth) { delete bandwidth; bandwidth = 0; } } if (newMedia.encryptkey) { if (!encryptkey) { encryptkey = new SdpEncryptkey; assert(encryptkey); } *(encryptkey) = *(newMedia.encryptkey); cpLog(LOG_DEBUG, "SdpEncryptkey:copied encryptkey"); } else { if (encryptkey) { delete encryptkey; encryptkey = 0; } } return *(this);}///DataSdpMedia::transportTypeString (){ Data s; switch (transportType) { case TransportTypeRTP: { s = SdpMediaTransportRTPAVP; break; } case TransportTypeUDP: { s = SdpMediaTransportUDP; break; } default: { //TODO Throw some exception break; } } return s;} // SdpMedia::transportTypeString///voidSdpMedia::encodeMediaAnnouncement (ostrstream& s){ s << "m=" << mediaTypeString << ' ' << port; if (numPorts > 0) { s << '/' << numPorts; } s << ' ' << transportTypeString(); vector < Data > ::iterator iter = formatList.begin(); while (iter != formatList.end()) { s << ' ' << *iter; ++iter; } s << "\r\n";} // SdpMedia::encodeMediaAnnouncement///voidSdpMedia::setTransportType(TransportType newtransport){ //TODO relax these checks? switch (newtransport) { case TransportTypeRTP: if (((port > 1023) && (port < 65536)) && (0 == (port % 2))) transportType = newtransport; else cpLog(LOG_ERR, "for RTP, port: %d should be within 1024 - 65536 and even", port); break; case TransportTypeUDP: if ((port > 1023) && (port < 65536)) transportType = newtransport; else cpLog(LOG_ERR, "for UDP, port: %d should be within 1024 - 65536", port); break; default: cpLog(LOG_ERR, "Unknown transport type %d", newtransport); }}///void SdpMedia::addFormat( Data fmt ){ formatList.push_back( fmt ); char format[ MaxFormatIntValue+1 ]; format[ MaxFormatIntValue ] = '\0'; LocalScopeAllocator lFormat; strncpy( format, fmt.getData(lFormat), MaxFormatIntValue ); char* endPtr = 0; int formatInt = 0; formatInt = strtol( format, &endPtr, 10 ); if( endPtr != format ) // Format is an integer { formatListInt.push_back( formatInt ); }}///voidSdpMedia::encode (ostrstream& s){ // m= media name and transport address encodeMediaAnnouncement (s); // i=* media title if (mediaInfo.length() > 0) { s << "i=" << mediaInfo << "\r\n"; } // c=* connection information (not required if included at session-level) if (connection) { connection->encode (s); } // b=* bandwidth information if (bandwidth) { bandwidth->encode (s); } // k=* encryption key if (encryptkey) { encryptkey->encode (s); } // a=* zero or more session attribute lines if (mediaAttrib) { mediaAttrib->encode (s); }} // SdpMedia::encodevoidSdpMedia::setMediaType( SdpMediaType newType ){ switch( newType ) { case MediaTypeAudio: { mediaTypeString = "audio"; } break; case MediaTypeVideo: { mediaTypeString = "video"; } break; default: { cpLog( LOG_ERR, "Unknown media type %d", newType ); mediaTypeString = "unknown"; } }} // SdpMedia::setMediaTypevoidSdpMedia::setMediaType( Data newType ){ mediaTypeString = newType; if( newType == "audio" ) { mediaType = MediaTypeAudio; } else if( newType == "video" ) { mediaType = MediaTypeVideo; } else { mediaType = MediaTypeUnknown; }} // SdpMedia::setMediaType
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -