diff --git a/sflphone-common/src/sip/sdp.cpp b/sflphone-common/src/sip/sdp.cpp index 32ebd088cb4b24c3af9a6adc8322ccbb13a87faa..fe99ba7a5e4ba489ac7d68e1743a3a6365ac575f 100644 --- a/sflphone-common/src/sip/sdp.cpp +++ b/sflphone-common/src/sip/sdp.cpp @@ -136,27 +136,48 @@ void Sdp::setActiveRemoteSdpSession (const pjmedia_sdp_session *sdp) getRemoteSdpTelephoneEventFromOffer(sdp); } -AudioCodec* Sdp::getSessionMedia (void) +bool Sdp::hasSessionMedia(void) { + std::vector<sdpMedia *> mediaList = getSessionMediaList(); + bool listNotEmpty; - int nb_media; - int nb_codec; + if(mediaList.size() > 0) { + listNotEmpty = true; + } + else { + listNotEmpty = false; + } + + return listNotEmpty; +} + +AudioCodec* Sdp::getSessionMedia (void) throw(SdpException) +{ + + int nbMedia; + int nbCodec; sfl::Codec *codec = NULL; - std::vector<sdpMedia*> media_list; + std::vector<sdpMedia *> mediaList; _debug ("SDP: Get session media"); - media_list = getSessionMediaList (); - nb_media = media_list.size(); + mediaList = getSessionMediaList (); + nbMedia = mediaList.size(); - if (nb_media > 0) { - nb_codec = media_list[0]->get_media_codec_list().size(); + if(nbMedia <= 0) { + _error("SDP: Error: No media in session description"); + throw SdpException("No media description for this SDP"); + } - if (nb_codec > 0) { - codec = media_list[0]->get_media_codec_list() [0]; - } + nbCodec = mediaList[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"); } + codec = mediaList[0]->get_media_codec_list() [0]; + return static_cast<AudioCodec *>(codec); } diff --git a/sflphone-common/src/sip/sdp.h b/sflphone-common/src/sip/sdp.h index 16675c77f21c329759b8e4606ae09c42af4da49e..250a7c7088a528a00bc0568f6055c8f8e0f0dd44 100644 --- a/sflphone-common/src/sip/sdp.h +++ b/sflphone-common/src/sip/sdp.h @@ -149,10 +149,15 @@ class Sdp } + /** + * Return wether or not the media have been determined for this sdp session + */ + bool hasSessionMedia(void); + /** * Return the codec of the first media after negociation */ - AudioCodec* getSessionMedia (void); + AudioCodec* getSessionMedia (void) throw(SdpException); /* * On building an invite outside a dialog, build the local offer and create the diff --git a/sflphone-common/src/sip/sipvoiplink.cpp b/sflphone-common/src/sip/sipvoiplink.cpp index c4213876158c02cc1546f83a54d0346f3f6d78f2..f5766adec284b87b9f8c4853b8a75a3b801d01c7 100644 --- a/sflphone-common/src/sip/sipvoiplink.cpp +++ b/sflphone-common/src/sip/sipvoiplink.cpp @@ -1347,20 +1347,31 @@ std::string SIPVoIPLink::getCurrentCodecName() { - SIPCall *call; + SIPCall *call = NULL; sfl::Codec *ac = NULL; std::string name = ""; call = getSIPCall (Manager::instance().getCurrentCallId()); + if(call == NULL) { + _error("UserAgent: Error: No current call"); + // return empty string + return name; + } + - if (call) { + if(call->getLocalSDP()->hasSessionMedia()) { ac = call->getLocalSDP()->getSessionMedia(); } + else { + return name; + } - if (ac) { - name = ac->getMimeSubtype(); + if (ac == NULL) { + _error("UserAgent: Error: No codec initialized for this session"); } + name = ac->getMimeSubtype(); + return name; }