Skip to content
Snippets Groups Projects
Commit 15c3df51 authored by Emmanuel Milou's avatar Emmanuel Milou
Browse files

Build the SDP session with the right codecs

parent b7a3ff08
Branches
No related tags found
No related merge requests found
...@@ -43,6 +43,7 @@ Sdp::SIPCallInvite(pjsip_rx_data *rdata) ...@@ -43,6 +43,7 @@ Sdp::SIPCallInvite(pjsip_rx_data *rdata)
// 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 negociation
pjmedia_sdp_session* remote_sdp = getRemoteSDPFromRequest(rdata); pjmedia_sdp_session* remote_sdp = getRemoteSDPFromRequest(rdata);
if (remote_sdp == 0) { if (remote_sdp == 0) {
_debug ("Failed to retrieve the remote sdp offer in the rdata struct to begin the negociation\n");
return false; return false;
} }
...@@ -57,6 +58,9 @@ Sdp::SIPCallInvite(pjsip_rx_data *rdata) ...@@ -57,6 +58,9 @@ Sdp::SIPCallInvite(pjsip_rx_data *rdata)
_localSDP->time.start = _localSDP->time.stop = 0; _localSDP->time.start = _localSDP->time.stop = 0;
sdpAddMediaDescription(); sdpAddMediaDescription();
// DEBUG
toString ();
status = pjmedia_sdp_validate( _localSDP ); status = pjmedia_sdp_validate( _localSDP );
if (status != PJ_SUCCESS) { if (status != PJ_SUCCESS) {
_debug("Can not generate valid local sdp\n"); _debug("Can not generate valid local sdp\n");
...@@ -201,6 +205,8 @@ void Sdp::sdpAddConnectionInfo( void ) ...@@ -201,6 +205,8 @@ void Sdp::sdpAddConnectionInfo( void )
void Sdp::sdpAddMediaDescription() void Sdp::sdpAddMediaDescription()
{ {
pjmedia_sdp_media* med; pjmedia_sdp_media* med;
pjmedia_sdp_attr *attr; pjmedia_sdp_attr *attr;
pjmedia_sdp_rtpmap rtpMap; pjmedia_sdp_rtpmap rtpMap;
...@@ -219,11 +225,13 @@ void Sdp::sdpAddMediaDescription() ...@@ -219,11 +225,13 @@ void Sdp::sdpAddMediaDescription()
itr = _codecMap.getActiveCodecs().begin(); itr = _codecMap.getActiveCodecs().begin();
int count = _codecMap.getActiveCodecs().size(); int count = _codecMap.getActiveCodecs().size();
_debug ("Add media description %i\n", count);
med->desc.fmt_count = count; med->desc.fmt_count = count;
int i = 0; int i = 0;
while(itr != _codecMap.getActiveCodecs().end()) { while(itr != _codecMap.getActiveCodecs().end()) {
_debug ("First media description\n");
std::ostringstream format; std::ostringstream format;
format << *itr; format << *itr;
pj_strdup2(_pool, &med->desc.fmt[i], format.str().data()); pj_strdup2(_pool, &med->desc.fmt[i], format.str().data());
...@@ -280,8 +288,7 @@ bool Sdp::startNegociation() ...@@ -280,8 +288,7 @@ bool Sdp::startNegociation()
return (status == PJ_SUCCESS); return (status == PJ_SUCCESS);
} }
bool Sdp::createInitialOffer() bool Sdp::createLocalOffer (void) {
{
pj_status_t status; pj_status_t status;
// Have to do some stuff here with the SDP // Have to do some stuff here with the SDP
...@@ -302,6 +309,16 @@ bool Sdp::createInitialOffer() ...@@ -302,6 +309,16 @@ bool Sdp::createInitialOffer()
return false; return false;
} }
}
bool Sdp::createInitialOffer()
{
pj_status_t status;
createLocalOffer ();
_debug("Before create negociator!\n"); _debug("Before create negociator!\n");
// Create the SDP negociator instance with local offer // Create the SDP negociator instance with local offer
status = pjmedia_sdp_neg_create_w_local_offer( _pool, _localSDP, &_negociator); status = pjmedia_sdp_neg_create_w_local_offer( _pool, _localSDP, &_negociator);
...@@ -325,7 +342,7 @@ int Sdp::receiving_initial_offer( pjmedia_sdp_session* remote ) ...@@ -325,7 +342,7 @@ int Sdp::receiving_initial_offer( pjmedia_sdp_session* remote )
// pjmedia_sdp_neg_create_w_remote_offer with the remote offer, and by providing the local offer ( optional ) // pjmedia_sdp_neg_create_w_remote_offer with the remote offer, and by providing the local offer ( optional )
// Build the local offer to respond // Build the local offer to respond
createInitialOffer(); createLocalOffer();
status = pjmedia_sdp_neg_create_w_remote_offer( _pool, status = pjmedia_sdp_neg_create_w_remote_offer( _pool,
getLocalSDPSession(), remote, &_negociator ); getLocalSDPSession(), remote, &_negociator );
...@@ -336,3 +353,34 @@ int Sdp::receiving_initial_offer( pjmedia_sdp_session* remote ) ...@@ -336,3 +353,34 @@ int Sdp::receiving_initial_offer( pjmedia_sdp_session* remote )
} }
void Sdp::toString (void) {
std::ostringstream sdp;
sdp << "origin= " << _localSDP->origin.user.ptr << "\n";
sdp << "origin.id= " << _localSDP->origin.id << "\n";
sdp << "origin.version= " << _localSDP->origin.version<< "\n";
sdp << "origin.net_type= " << _localSDP->origin.net_type.ptr<< "\n";
sdp << "origin.addr_type= " << _localSDP->origin.addr_type.ptr<< "\n";
sdp << "name=" << _localSDP->name.ptr<< "\n";
sdp << "conn.net_type=" << _localSDP->conn->net_type.ptr<< "\n";
sdp << "conn.addr_type=" << _localSDP->conn->addr_type.ptr<< "\n";
sdp << "conn.addr=" << _localSDP->conn->addr.ptr<< "\n";
sdp << "start=" <<_localSDP->time.start<< "\n";
sdp << "stop=" <<_localSDP->time.stop<< "\n";
sdp << "attr_count=" << _localSDP->attr_count << "\n";
sdp << "media_count=" << _localSDP->media_count << "\n";
sdp << "m=" << _localSDP->media[0]->desc.media.ptr << "\n";
sdp << "port=" << _localSDP->media[0]->desc.port << "\n";
sdp << "transport=" << _localSDP->media[0]->desc.transport.ptr << "\n";
sdp << "fmt_count=" << _localSDP->media[0]->desc.fmt_count << "\n";
sdp << "fmt=" << _localSDP->media[0]->desc.fmt[0].ptr << "\n";
_debug ("LOCAL SDP: \n%s\n", sdp.str().c_str());
}
...@@ -70,6 +70,8 @@ class Sdp { ...@@ -70,6 +70,8 @@ class Sdp {
*/ */
bool createInitialOffer(); bool createInitialOffer();
bool createLocalOffer ();
/** /**
* Set internal codec Map: initialization only, not protected * Set internal codec Map: initialization only, not protected
* @param map The codec map * @param map The codec map
...@@ -95,6 +97,8 @@ class Sdp { ...@@ -95,6 +97,8 @@ class Sdp {
int receiving_initial_offer( pjmedia_sdp_session* remote ); int receiving_initial_offer( pjmedia_sdp_session* remote );
void toString (void);
private: private:
/** /**
* Set the audio codec used. [not protected] * Set the audio codec used. [not protected]
......
...@@ -25,6 +25,8 @@ ...@@ -25,6 +25,8 @@
#include "sipaccount.h" #include "sipaccount.h"
#include "audio/audiortp.h" #include "audio/audiortp.h"
#define CAN_REINVITE 1
/**************** EXTERN VARIABLES AND FUNCTIONS (callbacks) **************************/ /**************** EXTERN VARIABLES AND FUNCTIONS (callbacks) **************************/
int getModId(); int getModId();
...@@ -430,6 +432,7 @@ SIPVoIPLink::newOutgoingCall(const CallID& id, const std::string& toUrl) ...@@ -430,6 +432,7 @@ SIPVoIPLink::newOutgoingCall(const CallID& id, const std::string& toUrl)
_debug("Try to make a call to: %s with call ID: %s\n", toUrl.data(), id.data()); _debug("Try to make a call to: %s with call ID: %s\n", toUrl.data(), id.data());
// we have to add the codec before using it in SIPOutgoingInvite... // we have to add the codec before using it in SIPOutgoingInvite...
call->setCodecMap(Manager::instance().getCodecDescriptorMap()); call->setCodecMap(Manager::instance().getCodecDescriptorMap());
call->getLocalSDP()->setCodecMap(Manager::instance().getCodecDescriptorMap());
if ( SIPOutgoingInvite(call) ) { if ( SIPOutgoingInvite(call) ) {
call->setConnectionState(Call::Progressing); call->setConnectionState(Call::Progressing);
call->setState(Call::Active); call->setState(Call::Active);
...@@ -929,6 +932,8 @@ SIPVoIPLink::SIPStartCall(SIPCall* call, const std::string& subject UNUSED) ...@@ -929,6 +932,8 @@ SIPVoIPLink::SIPStartCall(SIPCall* call, const std::string& subject UNUSED)
// Building the local SDP offer // Building the local SDP offer
call->getLocalSDP()->createInitialOffer(); call->getLocalSDP()->createInitialOffer();
call->getLocalSDP()->toString ();
// Create the invite session for this call // Create the invite session for this call
pjsip_inv_session *inv; pjsip_inv_session *inv;
status = pjsip_inv_create_uac(dialog, call->getLocalSDP()->getLocalSDPSession(), 0, &inv); status = pjsip_inv_create_uac(dialog, call->getLocalSDP()->getLocalSDPSession(), 0, &inv);
...@@ -2322,6 +2327,9 @@ void SIPVoIPLink::setStunServer( const std::string &server ) ...@@ -2322,6 +2327,9 @@ void SIPVoIPLink::setStunServer( const std::string &server )
PJ_UNUSED_ARG( inv ); PJ_UNUSED_ARG( inv );
#ifdef CAN_REINVITE #ifdef CAN_REINVITE
_debug ("reinvite SIP\n");
SIPCall *call; SIPCall *call;
pj_status_t status; pj_status_t status;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment