From 20900d15b966485f38285418764716443c224357 Mon Sep 17 00:00:00 2001 From: Tristan Matthews <tristan.matthews@savoirfairelinux.com> Date: Tue, 28 Jun 2011 13:46:02 -0400 Subject: [PATCH] * #6288: cleanup in sdp.cpp/h --- sflphone-common/src/sip/sdp.cpp | 329 ++++++++++-------------- sflphone-common/src/sip/sdp.h | 162 +++++------- sflphone-common/src/sip/sipvoiplink.cpp | 24 +- sflphone-common/test/sdptest.cpp | 18 +- 4 files changed, 215 insertions(+), 318 deletions(-) diff --git a/sflphone-common/src/sip/sdp.cpp b/sflphone-common/src/sip/sdp.cpp index 92be7e3afa..79c86f7f89 100644 --- a/sflphone-common/src/sip/sdp.cpp +++ b/sflphone-common/src/sip/sdp.cpp @@ -51,25 +51,21 @@ static const pj_str_t STR_TELEPHONE_EVENT = { (char*) "telephone-event", 15}; Sdp::Sdp (pj_pool_t *pool) - : memPool (pool) - , negociator (NULL) - , localSession (NULL) - , remoteSession(NULL) - , activeLocalSession (NULL) - , activeRemoteSession (NULL) - , localAudioMediaCap() - , sessionAudioMedia (0) - , localIpAddr ("") - , remoteIpAddr ("") - , localAudioPort (0) - , remoteAudioPort (0) - , zrtpHelloHash ("") - , srtpCrypto() - , telephoneEventPayload(101) // same as asterisk -{ -} - -Sdp::~Sdp() + : memPool_(pool) + , negotiator_(NULL) + , localSession_(NULL) + , remoteSession_(NULL) + , activeLocalSession_(NULL) + , activeRemoteSession_(NULL) + , localAudioMediaCap_() + , sessionAudioMedia_(0) + , localIpAddr_("") + , remoteIpAddr_("") + , localAudioPort_(0) + , remoteAudioPort_(0) + , zrtpHelloHash_("") + , srtpCrypto_() + , telephoneEventPayload_(101) // same as asterisk { } @@ -77,7 +73,7 @@ void Sdp::setActiveLocalSdpSession (const pjmedia_sdp_session *sdp) { int nb_media, nb_codecs; - int i,j, port; + int port; pjmedia_sdp_media *current; sdpMedia *media = NULL; std::string type, dir; @@ -87,69 +83,61 @@ void Sdp::setActiveLocalSdpSession (const pjmedia_sdp_session *sdp) _debug ("SDP: Set active local SDP session"); - activeLocalSession = (pjmedia_sdp_session*) sdp; + activeLocalSession_ = (pjmedia_sdp_session*) sdp; codecs_list = Manager::instance().getAudioCodecFactory().getCodecsMap(); // retrieve the media information - nb_media = activeLocalSession->media_count; + nb_media = activeLocalSession_->media_count; - for (i=0; i<nb_media ; i++) { + for (int i = 0; i < nb_media ; i++) { // Retrieve the media - current = activeLocalSession->media[i]; + current = activeLocalSession_->media[i]; type = current->desc.media.ptr; port = current->desc.port; media = new sdpMedia (type, port); // Retrieve the payload nb_codecs = current->desc.fmt_count; // Must be one - for (j=0 ; j<nb_codecs ; j++) { - attribute = pjmedia_sdp_media_find_attr (current, &STR_RTPMAP, NULL); + for (int j = 0; j < nb_codecs; j++) { + attribute = pjmedia_sdp_media_find_attr(current, &STR_RTPMAP, NULL); // pj_strtoul(attribute->pt) if (!attribute) + { + delete media; return; + } - pjmedia_sdp_attr_to_rtpmap (memPool, attribute, &rtpmap); + pjmedia_sdp_attr_to_rtpmap (memPool_, attribute, &rtpmap); CodecsMap::iterator iter = codecs_list.find ( (AudioCodecType) pj_strtoul (&rtpmap->pt)); - if (iter==codecs_list.end()) + if (iter == codecs_list.end()) + { + delete media; return; + } media->add_codec (iter->second); } - sessionAudioMedia.push_back (media); + sessionAudioMedia_.push_back (media); } } void Sdp::setActiveRemoteSdpSession (const pjmedia_sdp_session *sdp) { - - std::string type, dir; - CodecsMap codecs_list; - _debug ("SDP: Set negotiated SDP"); - activeRemoteSession = (pjmedia_sdp_session*) sdp; + activeRemoteSession_ = (pjmedia_sdp_session*) sdp; getRemoteSdpTelephoneEventFromOffer(sdp); } -bool Sdp::hasSessionMedia(void) +bool Sdp::hasSessionMedia(void) const { - std::vector<sdpMedia *> mediaList = getSessionMediaList(); - bool listNotEmpty; - - if(mediaList.size() > 0) { - listNotEmpty = true; - } - else { - listNotEmpty = false; - } - - return listNotEmpty; + return not sessionAudioMedia_.empty(); } sfl::AudioCodec* Sdp::getSessionMedia (void) throw(SdpException) @@ -162,22 +150,21 @@ sfl::AudioCodec* Sdp::getSessionMedia (void) throw(SdpException) _debug ("SDP: Get session media"); - mediaList = getSessionMediaList (); - nbMedia = mediaList.size(); + nbMedia = sessionAudioMedia_.size(); - if(nbMedia <= 0) { - _error("SDP: Error: No media in session description"); - throw SdpException("No media description for this SDP"); + if (nbMedia <= 0) { + _error("SDP: Error: No media in session description"); + throw SdpException("No media description for this SDP"); } - nbCodec = mediaList[0]->get_media_codec_list().size(); + nbCodec = sessionAudioMedia_[0]->get_media_codec_list().size(); if (nbCodec <= 0) { - _error("SDP: Error: No codec description for this media"); - throw SdpException("No codec description for this media"); + _error("SDP: Error: No codec description for this media"); + throw SdpException("No codec description for this media"); } - codec = mediaList[0]->get_media_codec_list() [0]; + codec = sessionAudioMedia_[0]->get_media_codec_list()[0]; return static_cast<sfl::AudioCodec *>(codec); } @@ -192,20 +179,20 @@ void Sdp::setMediaDescriptorLine (sdpMedia *media, pjmedia_sdp_media** p_med) int count, i; std::string tmp; - med = PJ_POOL_ZALLOC_T (memPool, pjmedia_sdp_media); + med = PJ_POOL_ZALLOC_T (memPool_, pjmedia_sdp_media); // Get the right media format - pj_strdup (memPool, &med->desc.media, + pj_strdup (memPool_, &med->desc.media, (media->get_media_type() == MIME_TYPE_AUDIO) ? &STR_AUDIO : &STR_VIDEO); med->desc.port_count = 1; med->desc.port = media->get_port(); // in case of sdes, media are tagged as "RTP/SAVP", RTP/AVP elsewhere - if (srtpCrypto.empty()) { - pj_strdup (memPool, &med->desc.transport, &STR_RTP_AVP); + if (srtpCrypto_.empty()) { + pj_strdup (memPool_, &med->desc.transport, &STR_RTP_AVP); } else { - pj_strdup (memPool, &med->desc.transport, &STR_RTP_SAVP); + pj_strdup (memPool_, &med->desc.transport, &STR_RTP_SAVP); } // Media format ( RTP payload ) @@ -218,7 +205,7 @@ void Sdp::setMediaDescriptorLine (sdpMedia *media, pjmedia_sdp_media** p_med) codec = media->get_media_codec_list() [i]; tmp = this->convertIntToString (codec->getPayloadType ()); _debug ("%s", tmp.c_str()); - pj_strdup2 (memPool, &med->desc.fmt[i], tmp.c_str()); + pj_strdup2 (memPool_, &med->desc.fmt[i], tmp.c_str()); // Add a rtpmap field for each codec // We could add one only for dynamic payloads because the codecs with static RTP payloads @@ -236,21 +223,21 @@ void Sdp::setMediaDescriptorLine (sdpMedia *media, pjmedia_sdp_media** p_med) rtpmap.param.slen = 0; - pjmedia_sdp_rtpmap_to_attr (memPool, &rtpmap, &attr); + pjmedia_sdp_rtpmap_to_attr (memPool_, &rtpmap, &attr); med->attr[med->attr_count++] = attr; } // Add the direction stream - attr = (pjmedia_sdp_attr*) pj_pool_zalloc (memPool, sizeof (pjmedia_sdp_attr)); + attr = (pjmedia_sdp_attr*) pj_pool_zalloc (memPool_, sizeof (pjmedia_sdp_attr)); - pj_strdup2 (memPool, &attr->name, media->get_stream_direction_str().c_str()); + pj_strdup2 (memPool_, &attr->name, media->get_stream_direction_str().c_str()); med->attr[ med->attr_count++] = attr; - if (!zrtpHelloHash.empty()) { + if (!zrtpHelloHash_.empty()) { try { - addZrtpAttribute (med,zrtpHelloHash); + addZrtpAttribute (med, zrtpHelloHash_); } catch (...) { throw; } @@ -266,13 +253,13 @@ void Sdp::setTelephoneEventRtpmap(pjmedia_sdp_media *med) pjmedia_sdp_attr *attr_rtpmap = NULL; pjmedia_sdp_attr *attr_fmtp = NULL; - attr_rtpmap = static_cast<pjmedia_sdp_attr *>(pj_pool_zalloc(memPool, sizeof(pjmedia_sdp_attr))); + attr_rtpmap = static_cast<pjmedia_sdp_attr *>(pj_pool_zalloc(memPool_, sizeof(pjmedia_sdp_attr))); attr_rtpmap->name = pj_str((char *) "rtpmap"); attr_rtpmap->value = pj_str((char *) "101 telephone-event/8000"); med->attr[med->attr_count++] = attr_rtpmap; - attr_fmtp = static_cast<pjmedia_sdp_attr *>(pj_pool_zalloc(memPool, sizeof(pjmedia_sdp_attr))); + attr_fmtp = static_cast<pjmedia_sdp_attr *>(pj_pool_zalloc(memPool_, sizeof(pjmedia_sdp_attr))); attr_fmtp->name = pj_str((char *) "fmtp"); attr_fmtp->value = pj_str((char *) "101 0-15"); @@ -288,7 +275,7 @@ void Sdp::setLocalMediaCapabilities (CodecOrder selectedCodecs) CodecsMap::iterator iter; // Clean it first - localAudioMediaCap.clear(); + localAudioMediaCap_.clear(); _debug ("SDP: Fetch local media capabilities. Local extern audio port: %i" , getLocalPublishedAudioPort()); @@ -313,7 +300,7 @@ void Sdp::setLocalMediaCapabilities (CodecOrder selectedCodecs) } } - localAudioMediaCap.push_back (audio); + localAudioMediaCap_.push_back (audio); } int Sdp::createLocalSession (CodecOrder selectedCodecs) @@ -328,8 +315,8 @@ int Sdp::createLocalSession (CodecOrder selectedCodecs) // Reference: RFC 4566 [5] /* Create and initialize basic SDP session */ - localSession = PJ_POOL_ZALLOC_T (memPool, pjmedia_sdp_session); - localSession->conn = PJ_POOL_ZALLOC_T (memPool, pjmedia_sdp_conn); + localSession_ = PJ_POOL_ZALLOC_T (memPool_, pjmedia_sdp_session); + localSession_->conn = PJ_POOL_ZALLOC_T (memPool_, pjmedia_sdp_conn); /* Initialize the fields of the struct */ addProtocol(); @@ -339,16 +326,16 @@ int Sdp::createLocalSession (CodecOrder selectedCodecs) addTiming(); addAudioMediaDescription(); - if (!srtpCrypto.empty()) { - addSdesAttribute (srtpCrypto); + if (!srtpCrypto_.empty()) { + addSdesAttribute (srtpCrypto_); } memset(buffer, 0, 1000); - pjmedia_sdp_print(getLocalSdpSession(), buffer, 1000); + pjmedia_sdp_print(localSession_, buffer, 1000); _debug("SDP: Local SDP Session:\n%s", buffer); // Validate the sdp session - return pjmedia_sdp_validate (localSession); + return pjmedia_sdp_validate (localSession_); } @@ -366,21 +353,21 @@ int Sdp::createOffer (CodecOrder selectedCodecs) return status; } - // Create the SDP negociator instance with local offer - status = pjmedia_sdp_neg_create_w_local_offer (memPool, getLocalSdpSession(), &negociator); + // Create the SDP negotiator_ instance with local offer + status = pjmedia_sdp_neg_create_w_local_offer (memPool_, localSession_, &negotiator_); if (status != PJ_SUCCESS) { - _error ("SDP: Error: Failed to create an initial SDP negociator"); + _error ("SDP: Error: Failed to create an initial SDP negotiator"); return status; } - state = pjmedia_sdp_neg_get_state (negociator); + state = pjmedia_sdp_neg_get_state (negotiator_); PJ_ASSERT_RETURN (status == PJ_SUCCESS, 1); return PJ_SUCCESS; } -int Sdp::recieveOffer (const pjmedia_sdp_session* remote, CodecOrder selectedCodecs) +int Sdp::receiveOffer (const pjmedia_sdp_session* remote, CodecOrder selectedCodecs) { char buffer[1000]; @@ -397,7 +384,7 @@ int Sdp::recieveOffer (const pjmedia_sdp_session* remote, CodecOrder selectedCod _debug("SDP: Remote SDP Session:\n%s", buffer); // If called for the first time - if(localSession == NULL) { + if(localSession_ == NULL) { // Build the local offer to respond status = createLocalSession (selectedCodecs); if (status != PJ_SUCCESS) { @@ -406,9 +393,10 @@ int Sdp::recieveOffer (const pjmedia_sdp_session* remote, CodecOrder selectedCod } } - remoteSession = pjmedia_sdp_session_clone (memPool, remote); + remoteSession_ = pjmedia_sdp_session_clone (memPool_, remote); - status = pjmedia_sdp_neg_create_w_remote_offer (memPool, getLocalSdpSession(), getRemoteSdpSession(), &negociator); + status = pjmedia_sdp_neg_create_w_remote_offer (memPool_, localSession_, + remoteSession_, &negotiator_); PJ_ASSERT_RETURN (status == PJ_SUCCESS, 1); @@ -419,17 +407,17 @@ int Sdp::receivingAnswerAfterInitialOffer(const pjmedia_sdp_session* remote) { pj_status_t status; - if(pjmedia_sdp_neg_get_state(negociator) != PJMEDIA_SDP_NEG_STATE_LOCAL_OFFER) { + if(pjmedia_sdp_neg_get_state(negotiator_) != PJMEDIA_SDP_NEG_STATE_LOCAL_OFFER) { _warn("SDP: Session not in a valid state for receiving answer"); } - status = pjmedia_sdp_neg_set_remote_answer(memPool, negociator, remote); + status = pjmedia_sdp_neg_set_remote_answer(memPool_, negotiator_, remote); if(status != PJ_SUCCESS) { _warn("SDP: Error: Could not set SDP remote answer"); } - if(pjmedia_sdp_neg_get_state(negociator) != PJMEDIA_SDP_NEG_STATE_WAIT_NEGO) { + if(pjmedia_sdp_neg_get_state(negotiator_) != PJMEDIA_SDP_NEG_STATE_WAIT_NEGO) { _warn("SDP: Session not in a valid state after receiving answer"); } @@ -440,17 +428,17 @@ int Sdp::generateAnswerAfterInitialOffer(void) { pj_status_t status; - if(pjmedia_sdp_neg_get_state(negociator) != PJMEDIA_SDP_NEG_STATE_REMOTE_OFFER) { + if(pjmedia_sdp_neg_get_state(negotiator_) != PJMEDIA_SDP_NEG_STATE_REMOTE_OFFER) { _warn("SDP: Session not in a valid state for generating answer"); } - status = pjmedia_sdp_neg_set_local_answer (memPool, negociator, localSession); + status = pjmedia_sdp_neg_set_local_answer (memPool_, negotiator_, localSession_); if(status != PJ_SUCCESS) { _warn("SDP: Error: could not set SDP local answer"); } - if(pjmedia_sdp_neg_get_state(negociator) != PJMEDIA_SDP_NEG_STATE_WAIT_NEGO) { + if(pjmedia_sdp_neg_get_state(negotiator_) != PJMEDIA_SDP_NEG_STATE_WAIT_NEGO) { _warn("SDP: Session not in a valid state after generating answer"); } @@ -458,7 +446,7 @@ int Sdp::generateAnswerAfterInitialOffer(void) } -pj_status_t Sdp::startNegociation() +pj_status_t Sdp::startNegotiation() { pj_status_t status; const pjmedia_sdp_session *active_local; @@ -466,27 +454,27 @@ pj_status_t Sdp::startNegociation() _debug ("SDP: Start negotiation"); - if(negociator == NULL) { - _error("SDP: Error: Negociator is NULL in SDP session"); + if(negotiator_ == NULL) { + _error("SDP: Error: negotiator is NULL in SDP session"); } - if(pjmedia_sdp_neg_get_state(negociator) != PJMEDIA_SDP_NEG_STATE_WAIT_NEGO) { - _warn("SDP: Warning: negociator not in wright state for negotiation"); + if(pjmedia_sdp_neg_get_state(negotiator_) != PJMEDIA_SDP_NEG_STATE_WAIT_NEGO) { + _warn("SDP: Warning: negotiator not in wright state for negotiation"); } - status = pjmedia_sdp_neg_negotiate (memPool, negociator, 0); + status = pjmedia_sdp_neg_negotiate (memPool_, negotiator_, 0); if(status != PJ_SUCCESS) { return status; } - status = pjmedia_sdp_neg_get_active_local(negociator, &active_local); + status = pjmedia_sdp_neg_get_active_local(negotiator_, &active_local); if(status != PJ_SUCCESS) { _error("SDP: Could not retrieve local active session"); } setActiveLocalSdpSession(active_local); - status = pjmedia_sdp_neg_get_active_remote(negociator, &active_remote); + status = pjmedia_sdp_neg_get_active_remote(negotiator_, &active_remote); if(status != PJ_SUCCESS) { _error("SDP: Could not retrieve remote active session"); } @@ -499,45 +487,43 @@ pj_status_t Sdp::startNegociation() void Sdp::updateInternalState() { // Populate internal field - setMediaTransportInfoFromRemoteSdp (activeRemoteSession); + setMediaTransportInfoFromRemoteSdp (activeRemoteSession_); } void Sdp::addProtocol (void) { - - this->localSession->origin.version = 0; + localSession_->origin.version = 0; } void Sdp::addOrigin (void) { - pj_time_val tv; pj_gettimeofday (&tv); - this->localSession->origin.user = pj_str (pj_gethostname()->ptr); + localSession_->origin.user = pj_str (pj_gethostname()->ptr); // Use Network Time Protocol format timestamp to ensure uniqueness. - this->localSession->origin.id = tv.sec + 2208988800UL; + localSession_->origin.id = tv.sec + 2208988800UL; // The type of network ( IN for INternet ) - this->localSession->origin.net_type = STR_IN; + localSession_->origin.net_type = STR_IN; // The type of address - this->localSession->origin.addr_type = STR_IP4; + localSession_->origin.addr_type = STR_IP4; // The address of the machine from which the session was created - this->localSession->origin.addr = pj_str ( (char*) localIpAddr.c_str()); + localSession_->origin.addr = pj_str ( (char*) localIpAddr_.c_str()); } void Sdp::addSessionName (void) { - this->localSession->name = STR_SDP_NAME; + localSession_->name = STR_SDP_NAME; } void Sdp::addConnectionInfo (void) { - this->localSession->conn->net_type = localSession->origin.net_type; - this->localSession->conn->addr_type = localSession->origin.addr_type; - this->localSession->conn->addr = localSession->origin.addr; + localSession_->conn->net_type = localSession_->origin.net_type; + localSession_->conn->addr_type = localSession_->origin.addr_type; + localSession_->conn->addr = localSession_->origin.addr; } @@ -548,17 +534,17 @@ void Sdp::addTiming (void) // As the session is created and destroyed through an external signaling mean (SIP), the line // should have a value of "0 0". - this->localSession->time.start = this->localSession->time.stop = 0; + localSession_->time.start = localSession_->time.stop = 0; } void Sdp::addAttributes() { pjmedia_sdp_attr *a; - this->localSession->attr_count = 1; - a = PJ_POOL_ZALLOC_T (memPool, pjmedia_sdp_attr); + localSession_->attr_count = 1; + a = PJ_POOL_ZALLOC_T (memPool_, pjmedia_sdp_attr); a->name=STR_SENDRECV; - localSession->attr[0] = a; + localSession_->attr[0] = a; } @@ -567,19 +553,18 @@ void Sdp::addAudioMediaDescription() pjmedia_sdp_media* med; int nb_media, i; - med = PJ_POOL_ZALLOC_T (memPool, pjmedia_sdp_media); - nb_media = getLocalMediaCap().size(); + med = PJ_POOL_ZALLOC_T (memPool_, pjmedia_sdp_media); + nb_media = localAudioMediaCap_.size(); // For DTMF RTP events - localSession->media_count = nb_media; + localSession_->media_count = nb_media; for (i=0; i<nb_media; i++) { - setMediaDescriptorLine (getLocalMediaCap() [i], &med); - localSession->media[i] = med; + setMediaDescriptorLine (localAudioMediaCap_[i], &med); + localSession_->media[i] = med; } - - } + void Sdp::addSdesAttribute (std::vector<std::string>& crypto) throw (SdpException) { @@ -591,9 +576,9 @@ void Sdp::addSdesAttribute (std::vector<std::string>& crypto) throw (SdpExceptio while (iter != crypto.end()) { // the attribute to add to sdp - pjmedia_sdp_attr *attribute = (pjmedia_sdp_attr*) pj_pool_zalloc (memPool, sizeof (pjmedia_sdp_attr)); + pjmedia_sdp_attr *attribute = (pjmedia_sdp_attr*) pj_pool_zalloc (memPool_, sizeof (pjmedia_sdp_attr)); - attribute->name = pj_strdup3 (memPool, "crypto"); + attribute->name = pj_strdup3 (memPool_, "crypto"); // _debug("crypto from sdp: %s", crypto.c_str()); @@ -602,16 +587,16 @@ void Sdp::addSdesAttribute (std::vector<std::string>& crypto) throw (SdpExceptio "%.*s", (int) (*iter).size(), (*iter).c_str()); attribute->value.slen = len; - attribute->value.ptr = (char*) pj_pool_alloc (memPool, attribute->value.slen+1); + attribute->value.ptr = (char*) pj_pool_alloc (memPool_, attribute->value.slen+1); pj_memcpy (attribute->value.ptr, tempbuf, attribute->value.slen+1); // get number of media for this SDP - int media_count = localSession->media_count; + int media_count = localSession_->media_count; // add crypto attribute to media for (int i = 0; i < media_count; i++) { - if (pjmedia_sdp_media_add_attr (localSession->media[i], attribute) != PJ_SUCCESS) { + if (pjmedia_sdp_media_add_attr (localSession_->media[i], attribute) != PJ_SUCCESS) { // if(pjmedia_sdp_attr_add(&(_local_offer->attr_count), _local_offer->attr, attribute) != PJ_SUCCESS){ throw SdpException ("Could not add sdes attribute to media"); } @@ -629,9 +614,9 @@ void Sdp::addZrtpAttribute (pjmedia_sdp_media* media, std::string hash) throw (S char tempbuf[256]; int len; - attribute = (pjmedia_sdp_attr*) pj_pool_zalloc (memPool, sizeof (pjmedia_sdp_attr)); + attribute = (pjmedia_sdp_attr*) pj_pool_zalloc (memPool_, sizeof (pjmedia_sdp_attr)); - attribute->name = pj_strdup3 (memPool, "zrtp-hash"); + attribute->name = pj_strdup3 (memPool_, "zrtp-hash"); /* Format: ":version value" */ len = pj_ansi_snprintf (tempbuf, sizeof (tempbuf), @@ -642,7 +627,7 @@ void Sdp::addZrtpAttribute (pjmedia_sdp_media* media, std::string hash) throw (S hash.c_str()); attribute->value.slen = len; - attribute->value.ptr = (char*) pj_pool_alloc (memPool, attribute->value.slen+1); + attribute->value.ptr = (char*) pj_pool_alloc (memPool_, attribute->value.slen+1); pj_memcpy (attribute->value.ptr, tempbuf, attribute->value.slen+1); if (pjmedia_sdp_media_add_attr (media, attribute) != PJ_SUCCESS) { @@ -650,39 +635,23 @@ void Sdp::addZrtpAttribute (pjmedia_sdp_media* media, std::string hash) throw (S } } -std::string Sdp::mediaToString (void) -{ - int size, i; - std::ostringstream res; - - size = localAudioMediaCap.size(); - - for (i = 0; i < size ; i++) { - res << localAudioMediaCap[i]->to_string(); - } - - res << std::endl; - - return res.str(); -} - void Sdp::cleanSessionMedia() { _info ("SDP: Clean session media"); - if (sessionAudioMedia.size() > 0) { + if (not sessionAudioMedia_.empty()) { - std::vector<sdpMedia *>::iterator iter = sessionAudioMedia.begin(); + std::vector<sdpMedia *>::iterator iter = sessionAudioMedia_.begin(); sdpMedia *media; - while (iter != sessionAudioMedia.end()) { + while (iter != sessionAudioMedia_.end()) { _debug ("delete media"); media = *iter; delete media; iter++; } - sessionAudioMedia.clear(); + sessionAudioMedia_.clear(); } } @@ -691,56 +660,19 @@ void Sdp::cleanLocalMediaCapabilities() { _info ("SDP: Clean local media capabilities"); - if (localAudioMediaCap.size() > 0) { + if (localAudioMediaCap_.size() > 0) { - std::vector<sdpMedia *>::iterator iter = localAudioMediaCap.begin(); + std::vector<sdpMedia *>::iterator iter = localAudioMediaCap_.begin(); sdpMedia *media; - while (iter != localAudioMediaCap.end()) { + while (iter != localAudioMediaCap_.end()) { media = *iter; delete media; iter++; } - localAudioMediaCap.clear(); - } -} - -void Sdp::toString (void) -{ - - std::ostringstream sdp; - int count, i; - - sdp << "origin= " << localSession->origin.user.ptr << "\n"; - sdp << "origin.id= " << localSession->origin.id << "\n"; - sdp << "origin.version= " << localSession->origin.version<< "\n"; - sdp << "origin.net_type= " << localSession->origin.net_type.ptr<< "\n"; - sdp << "origin.addr_type= " << localSession->origin.addr_type.ptr<< "\n"; - - sdp << "name=" << localSession->name.ptr<< "\n"; - - sdp << "conn.net_type=" << localSession->conn->net_type.ptr<< "\n"; - sdp << "conn.addr_type=" << localSession->conn->addr_type.ptr<< "\n"; - sdp << "conn.addr=" << localSession->conn->addr.ptr<< "\n"; - - sdp << "start=" <<localSession->time.start<< "\n"; - sdp << "stop=" <<localSession->time.stop<< "\n"; - - sdp << "attr_count=" << localSession->attr_count << "\n"; - sdp << "media_count=" << localSession->media_count << "\n"; - sdp << "m=" << localSession->media[0]->desc.media.ptr << " "; - sdp << localSession->media[0]->desc.port << " "; - sdp << localSession->media[0]->desc.transport.ptr << " "; - count = localSession->media[0]->desc.fmt_count; - - for (i=0; i<count; i++) { - sdp << localSession->media[0]->desc.fmt[i].ptr << " "; + localAudioMediaCap_.clear(); } - - sdp << "\n"; - - _debug ("LOCAL SDP: \n%s", sdp.str().c_str()); } void Sdp::setPortToAllMedia (int port) @@ -751,11 +683,10 @@ void Sdp::setPortToAllMedia (int port) setLocalPublishedAudioPort (port); - medias = getLocalMediaCap (); - size = medias.size(); + size = localAudioMediaCap_.size(); for (i=0; i<size; i++) { - medias[i]->set_port (port); + localAudioMediaCap_[i]->set_port (port); } } @@ -763,14 +694,14 @@ void Sdp::addAttributeToLocalAudioMedia(std::string attr) { pjmedia_sdp_attr *attribute; - attribute = pjmedia_sdp_attr_create (memPool, attr.c_str(), NULL); + attribute = pjmedia_sdp_attr_create (memPool_, attr.c_str(), NULL); - pjmedia_sdp_media_add_attr (getLocalSdpSession()->media[0], attribute); + pjmedia_sdp_media_add_attr (localSession_->media[0], attribute); } void Sdp::removeAttributeFromLocalAudioMedia(std::string attr) { - pjmedia_sdp_media_remove_all_attr (getLocalSdpSession()->media[0], attr.c_str()); + pjmedia_sdp_media_remove_all_attr (localSession_->media[0], attr.c_str()); } @@ -873,9 +804,9 @@ void Sdp::getRemoteSdpTelephoneEventFromOffer(const pjmedia_sdp_session *remote_ if(attribute != NULL) { - pjmedia_sdp_attr_to_rtpmap (memPool, attribute, &rtpmap); + pjmedia_sdp_attr_to_rtpmap (memPool_, attribute, &rtpmap); - telephoneEventPayload = pj_strtoul (&rtpmap->pt); + telephoneEventPayload_ = pj_strtoul (&rtpmap->pt); } } diff --git a/sflphone-common/src/sip/sdp.h b/sflphone-common/src/sip/sdp.h index 7534d409dd..fe1675ba6b 100644 --- a/sflphone-common/src/sip/sdp.h +++ b/sflphone-common/src/sip/sdp.h @@ -68,7 +68,6 @@ class SdpException : public std::exception }; typedef std::vector<std::string> CryptoOffer; -typedef std::vector<sdpMedia *> SdpMediaList; class Sdp { @@ -82,24 +81,11 @@ class Sdp */ Sdp (pj_pool_t *pool); - /* Class destructor */ - ~Sdp(); - - /* - * Read accessor. Get the list of the local media capabilities. - * - * @return std::vector<sdpMedia*> the vector containing the different media - */ - std::vector<sdpMedia *> getLocalMediaCap (void) { - return localAudioMediaCap; - } - - /** * Accessor for the internal memory pool */ pj_pool_t *getMemoryPool (void) const { - return memPool; + return memPool_; } /** @@ -108,7 +94,7 @@ class Sdp * @return The structure that describes a SDP session */ pjmedia_sdp_session *getLocalSdpSession (void) { - return localSession; + return localSession_; } /** @@ -117,70 +103,70 @@ class Sdp * @return The structure that describe the SDP session */ pjmedia_sdp_session *getRemoteSdpSession(void) { - return remoteSession; + return remoteSession_; } /** - * Set the negociated sdp offer from the sip payload. + * Set the negotiated sdp offer from the sip payload. * - * @param sdp the negociated offer + * @param sdp the negotiated offer */ void setActiveLocalSdpSession (const pjmedia_sdp_session *sdp); /** - * read accessor. Return the negociated local session + * read accessor. Return the negotiated local session * - * @return pjmedia_sdp_session The negociated offer + * @return pjmedia_sdp_session The negotiated offer */ pjmedia_sdp_session* getActiveLocalSdpSession (void) { - return activeLocalSession; + return activeLocalSession_; } /** - * Retrieve the negociated sdp offer from the sip payload. + * Retrieve the negotiated sdp offer from the sip payload. * - * @param sdp the negociated offer + * @param sdp the negotiated offer */ void setActiveRemoteSdpSession (const pjmedia_sdp_session *sdp); /** - * read accessor. Return the negociated offer + * read accessor. Return the negotiated offer * - * @return pjmedia_sdp_session The negociated offer + * @return pjmedia_sdp_session The negotiated offer */ pjmedia_sdp_session* getActiveRemoteSdpSession (void) { - return activeRemoteSession; + return activeRemoteSession_; } /** - * Return wether or not the media have been determined for this sdp session - */ - bool hasSessionMedia(void); + * Return whether or not the media have been determined for this sdp session + */ + bool hasSessionMedia(void) const; /** - * Return the codec of the first media after negociation + * Return the codec of the first media after negotiation */ sfl::AudioCodec* getSessionMedia (void) throw(SdpException); /* * On building an invite outside a dialog, build the local offer and create the - * SDP negociator instance with it. + * SDP negotiator instance with it. */ int createOffer (CodecOrder selectedCodecs); /* * On receiving an invite outside a dialog, build the local offer and create the - * SDP negociator instance with the remote offer. + * SDP negotiator instance with the remote offer. * * @param remote The remote offer */ - int recieveOffer (const pjmedia_sdp_session* remote, CodecOrder selectedCodecs); + int receiveOffer (const pjmedia_sdp_session* remote, CodecOrder selectedCodecs); /* * On receiving a message, check if it contains SDP and negotiate. Should be used for * SDP answer and offer but currently is only used for answer. - * SDP negociator instance with the remote offer. + * SDP negotiator instance with the remote offer. * * @param inv The the invitation * @param rdata The remote data @@ -193,12 +179,12 @@ class Sdp int generateAnswerAfterInitialOffer(void); /** - * Start the sdp negociation. + * Start the sdp negotiation. * * @return pj_status_t 0 on success * 1 otherwise */ - pj_status_t startNegociation (void); + pj_status_t startNegotiation (void); /** * Update internal state after negotiation @@ -215,12 +201,6 @@ class Sdp */ void cleanLocalMediaCapabilities (void); - /** - * Return a string description of the media added to the session, - * ie the local media capabilities - */ - std::string mediaToString (void); - /* * Attribute the specified port to every medias provided * This is valid only because we are using one media @@ -230,33 +210,32 @@ class Sdp */ void setPortToAllMedia (int port); - /* * Write accessor. Set the local IP address that will be used in the sdp session */ - void setLocalIP (std::string ip_addr) { - localIpAddr = ip_addr; + void setLocalIP (const std::string &ip_addr) { + localIpAddr_ = ip_addr; } /* * Read accessor. Get the local IP address */ - std::string getLocalIP (void) { - return localIpAddr; + std::string getLocalIP (void) const { + return localIpAddr_; } /** * @param Set the published audio port */ void setLocalPublishedAudioPort (int port) { - localAudioPort = port; + localAudioPort_ = port; } /** * @return The published audio port */ - int getLocalPublishedAudioPort (void) { - return localAudioPort; + int getLocalPublishedAudioPort (void) const { + return localAudioPort_; } /** @@ -264,7 +243,7 @@ class Sdp * @param ip The remote IP address */ void setRemoteIP (const std::string& ip) { - remoteIpAddr = ip; + remoteIpAddr_ = ip; } /** @@ -272,7 +251,7 @@ class Sdp * @return const std:string The remote IP address */ const std::string& getRemoteIP() { - return remoteIpAddr; + return remoteIpAddr_; } /** @@ -280,22 +259,23 @@ class Sdp * @param port The remote audio port */ void setRemoteAudioPort (unsigned int port) { - remoteAudioPort = port; + remoteAudioPort_ = port; } /** * Return audio port at destination [mutex protected] * @return unsigned int The remote audio port */ - unsigned int getRemoteAudioPort() { - return remoteAudioPort; + unsigned int getRemoteAudioPort() const { + return remoteAudioPort_; } + /** * Get media list for this session */ - SdpMediaList getSessionMediaList (void) { - return sessionAudioMedia; + std::vector<sdpMedia *> getSessionMediaList (void) const { + return sessionAudioMedia_; } /** @@ -308,7 +288,6 @@ class Sdp */ void removeAttributeFromLocalAudioMedia(std::string); - /** * Get SRTP master key * @param remote sdp session @@ -321,7 +300,7 @@ class Sdp * @param mk The Master Key of a srtp session. */ void setLocalSdpCrypto (const std::vector<std::string> lc) { - srtpCrypto = lc; + srtpCrypto_ = lc; } /** @@ -331,99 +310,91 @@ class Sdp * @param hash The hello hash of a rtp session. (Only audio at the moment) */ void setZrtpHash (const std::string& hash) { - zrtpHelloHash = hash; + zrtpHelloHash_ = hash; } - - unsigned int getTelephoneEventType() { - return telephoneEventPayload; + unsigned int getTelephoneEventType() const { + return telephoneEventPayload_; } - - /** - * Print internal state info - */ - void toString (void); - - private: /** * The pool to allocate memory, ownership to SipCall * SDP should not release the pool itself */ - pj_pool_t *memPool; + pj_pool_t *memPool_; - /** negociator */ - pjmedia_sdp_neg *negociator; + /** negotiator */ + pjmedia_sdp_neg *negotiator_; /** * Local SDP */ - pjmedia_sdp_session *localSession; + pjmedia_sdp_session *localSession_; /** * Remote SDP */ - pjmedia_sdp_session *remoteSession; + pjmedia_sdp_session *remoteSession_; /** - * The negociated SDP remote session - * Explanation: each endpoint's offer is negociated, and a new sdp offer results from this - * negociation, with the compatible media from each part + * The negotiated SDP remote session + * Explanation: each endpoint's offer is negotiated, and a new sdp offer results from this + * negotiation, with the compatible media from each part */ - pjmedia_sdp_session *activeLocalSession; + pjmedia_sdp_session *activeLocalSession_; /** - * The negociated SDP remote session - * Explanation: each endpoint's offer is negociated, and a new sdp offer results from this - * negociation, with the compatible media from each part + * The negotiated SDP remote session + * Explanation: each endpoint's offer is negotiated, and a new sdp offer results from this + * negotiation, with the compatible media from each part */ - pjmedia_sdp_session *activeRemoteSession; + pjmedia_sdp_session *activeRemoteSession_; /** * Codec Map used for offer */ - SdpMediaList localAudioMediaCap; + std::vector<sdpMedia *> localAudioMediaCap_; /** - * The media that will be used by the session (after the SDP negociation) + * The media that will be used by the session (after the SDP negotiation) */ - SdpMediaList sessionAudioMedia; + std::vector<sdpMedia *> sessionAudioMedia_; /** * IP address */ - std::string localIpAddr; + std::string localIpAddr_; /** * Remote's IP address */ - std::string remoteIpAddr; + std::string remoteIpAddr_; /** * Local audio port */ - int localAudioPort; + int localAudioPort_; /** * Remote audio port */ - unsigned int remoteAudioPort; + unsigned int remoteAudioPort_; /** * Zrtp hello hash */ - std::string zrtpHelloHash; + std::string zrtpHelloHash_; /** * "a=crypto" sdes local attributes obtained from AudioSrtpSession */ - std::vector<std::string> srtpCrypto; + std::vector<std::string> srtpCrypto_; /** * Payload type for dtmf telephone event */ - unsigned int telephoneEventPayload; + unsigned int telephoneEventPayload_; Sdp (const Sdp&); //No Copy Constructor @@ -482,7 +453,6 @@ class Sdp */ void addTiming (void); - /* * Optional field: Session information ("s=") * Provides textual information about the session. @@ -557,8 +527,6 @@ class Sdp void getRemoteSdpTelephoneEventFromOffer(const pjmedia_sdp_session *remote_sdp); void getRemoteSdpMediaFromOffer (const pjmedia_sdp_session* remote_sdp, pjmedia_sdp_media** r_media); - - }; diff --git a/sflphone-common/src/sip/sipvoiplink.cpp b/sflphone-common/src/sip/sipvoiplink.cpp index 70138bd3ae..4175b0c440 100644 --- a/sflphone-common/src/sip/sipvoiplink.cpp +++ b/sflphone-common/src/sip/sipvoiplink.cpp @@ -764,7 +764,7 @@ SIPVoIPLink::answer (const CallID& id) throw (VoipLinkException) if (status == PJ_SUCCESS) { - _debug ("UserAgent: SDP Negociation success! : call %s ", call->getCallId().c_str()); + _debug ("UserAgent: SDP negotiation success! : call %s ", call->getCallId().c_str()); // Create and send a 200(OK) response if((status = pjsip_inv_answer (inv_session, PJSIP_SC_OK, NULL, NULL, &tdata)) != PJ_SUCCESS) { throw VoipLinkException("Could not init invite request answer (200 OK)"); @@ -778,7 +778,7 @@ SIPVoIPLink::answer (const CallID& id) throw (VoipLinkException) return true; } else { - // Create and send a 488/Not acceptable because the SDP negociation failed + // Create and send a 488/Not acceptable because the SDP negotiation failed if((status = pjsip_inv_answer (inv_session, PJSIP_SC_NOT_ACCEPTABLE_HERE, NULL, NULL, &tdata)) != PJ_SUCCESS) { throw VoipLinkException("Could not init invite answer (488 not acceptable here)"); } @@ -786,7 +786,7 @@ SIPVoIPLink::answer (const CallID& id) throw (VoipLinkException) throw VoipLinkException("Could not init invite request answer (488 NOT ACCEPTABLE HERE)"); } // Terminate the call - _debug ("UserAgent: SDP Negociation failed, terminate call %s ", call->getCallId().c_str()); + _debug ("UserAgent: SDP negotiation failed, terminate call %s ", call->getCallId().c_str()); if(call->getAudioRtp()) { throw VoipLinkException("No audio rtp session for this call"); @@ -3329,8 +3329,8 @@ void sdp_request_offer_cb (pjsip_inv_session *inv, const pjmedia_sdp_session *of SIPAccount *account = dynamic_cast<SIPAccount *> (Manager::instance().getAccount (accId)); - status = call->getLocalSDP()->recieveOffer (offer, account->getActiveCodecs ()); - call->getLocalSDP()->startNegociation(); + status = call->getLocalSDP()->receiveOffer (offer, account->getActiveCodecs ()); + call->getLocalSDP()->startNegotiation(); status = pjsip_inv_set_sdp_answer (call->getInvSession(), call->getLocalSDP()->getLocalSdpSession()); @@ -3397,7 +3397,7 @@ void sdp_media_update_cb (pjsip_inv_session *inv, pj_status_t status) call = reinterpret_cast<SIPCall *> (inv->mod_data[getModId()]); if (call == NULL) { - _debug ("UserAgent: Call declined by peer, SDP negociation stopped"); + _debug ("UserAgent: Call declined by peer, SDP negotiation stopped"); return; } @@ -3470,7 +3470,7 @@ void sdp_media_update_cb (pjsip_inv_session *inv, pj_status_t status) sfl::SdesNegotiator sdesnego (localCapabilities, crypto_offer); if (sdesnego.negotiate()) { - _debug ("UserAgent: SDES negociation successfull"); + _debug ("UserAgent: SDES negotiation successfull"); nego_success = true; _debug ("UserAgent: Set remote cryptographic context"); @@ -3492,7 +3492,7 @@ void sdp_media_update_cb (pjsip_inv_session *inv, pj_status_t status) // We did not found any crypto context for this media // @TODO if SRTPONLY, CallFail - _debug ("UserAgent: Did not found any crypto or negociation failed but Sdes enabled"); + _debug ("UserAgent: Did not found any crypto or negotiation failed but Sdes enabled"); call->getAudioRtp()->stop(); call->getAudioRtp()->setSrtpEnabled (false); @@ -3972,7 +3972,7 @@ transaction_request_cb (pjsip_rx_data *rdata) // Set the codec map, IP, peer number and so on... for the SIPCall object setCallMediaLocal (call, addrToUse); - // We retrieve the remote sdp offer in the rdata struct to begin the negociation + // We retrieve the remote sdp offer in the rdata struct to begin the negotiation call->getLocalSDP()->setLocalIP (addrSdp); // Init audio rtp session @@ -4017,7 +4017,7 @@ transaction_request_cb (pjsip_rx_data *rdata) sfl::SdesNegotiator sdesnego (localCapabilities, crypto_offer); if (sdesnego.negotiate()) { - _debug ("UserAgent: SDES negociation successfull \n"); + _debug ("UserAgent: SDES negotiation successfull \n"); nego_success = true; try { @@ -4033,7 +4033,7 @@ transaction_request_cb (pjsip_rx_data *rdata) } - status = call->getLocalSDP()->recieveOffer (r_sdp, account->getActiveCodecs ()); + status = call->getLocalSDP()->receiveOffer (r_sdp, account->getActiveCodecs ()); if (status!=PJ_SUCCESS) { delete call; call = NULL; @@ -4687,8 +4687,6 @@ bool setCallMediaLocal (SIPCall* call, const std::string &localIP) account = dynamic_cast<SIPAccount *> (Manager::instance().getAccount (account_id)); - - // Setting Audio unsigned int callLocalAudioPort = RANDOM_LOCAL_PORT; unsigned int callLocalExternAudioPort = callLocalAudioPort; diff --git a/sflphone-common/test/sdptest.cpp b/sflphone-common/test/sdptest.cpp index d548e8a3a6..b85102feff 100644 --- a/sflphone-common/test/sdptest.cpp +++ b/sflphone-common/test/sdptest.cpp @@ -144,7 +144,7 @@ void SDPTest::testInitialOfferFirstCodec () _session->receivingAnswerAfterInitialOffer(remoteAnswer); - _session->startNegociation(); + _session->startNegotiation(); _session->updateInternalState(); @@ -177,9 +177,9 @@ void SDPTest::testInitialAnswerFirstCodec () _session->setLocalIP("127.0.0.1"); _session->setLocalPublishedAudioPort(49567); - _session->recieveOffer(remoteOffer, codecSelection); + _session->receiveOffer(remoteOffer, codecSelection); - _session->startNegociation(); + _session->startNegotiation(); _session->updateInternalState(); @@ -217,7 +217,7 @@ void SDPTest::testInitialOfferLastCodec () _session->receivingAnswerAfterInitialOffer(remoteAnswer); - _session->startNegociation(); + _session->startNegotiation(); _session->updateInternalState(); @@ -250,9 +250,9 @@ void SDPTest::testInitialAnswerLastCodec () _session->setLocalIP("127.0.0.1"); _session->setLocalPublishedAudioPort(49567); - _session->recieveOffer(remoteOffer, codecSelection); + _session->receiveOffer(remoteOffer, codecSelection); - _session->startNegociation(); + _session->startNegotiation(); _session->updateInternalState(); @@ -292,7 +292,7 @@ void SDPTest::testReinvite () _session->receivingAnswerAfterInitialOffer(remoteAnswer); - _session->startNegociation(); + _session->startNegotiation(); _session->updateInternalState(); @@ -304,9 +304,9 @@ void SDPTest::testReinvite () pjmedia_sdp_parse(_testPool, (char*)sdp_reinvite, strlen(sdp_reinvite), &reinviteOffer); - _session->recieveOffer(reinviteOffer, codecSelection); + _session->receiveOffer(reinviteOffer, codecSelection); - _session->startNegociation(); + _session->startNegotiation(); _session->updateInternalState(); -- GitLab