]> sjero.net Git - linphone/blobdiff - coreapi/sal_eXosip2_sdp.c
Set UTC time in received chat messages.
[linphone] / coreapi / sal_eXosip2_sdp.c
index 8c917570fbf0fee07d86c38f2f0f000cf28859bd..debd8550f63e35fb288286946d6e17616ce4041a 100644 (file)
@@ -18,12 +18,13 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 */
 
 
+#include "ortp/port.h"
 #include "ortp/b64.h"
 #include "ortp/ortp_srtp.h"
 #include "sal.h"
 #include <eXosip2/eXosip.h>
 
-#define keywordcmp(key,b) strncmp(key,b,sizeof(key))
+#define keywordcmp(key,b) strcmp(key,b)
 
 #ifdef FOR_LATER
 
@@ -144,7 +145,8 @@ static sdp_message_t *create_generic_sdp(const SalMediaDescription *desc)
                          osip_strdup ("IN"), inet6 ? osip_strdup("IP6") : osip_strdup ("IP4"),
                          osip_strdup (desc->addr));
        sdp_message_s_name_set (local, osip_strdup ("Talk"));
-       if(!sal_media_description_has_dir (desc,SalStreamSendOnly))
+       /* Do not set the c= line to 0.0.0.0 if there is an ICE session. */
+       if((desc->ice_ufrag[0] != '\0') || !sal_media_description_has_dir (desc,SalStreamSendOnly))
        {
                sdp_message_c_connection_add (local, -1,
                                osip_strdup ("IN"), inet6 ? osip_strdup ("IP6") : osip_strdup ("IP4"),
@@ -278,10 +280,6 @@ static void add_line(sdp_message_t *msg, int lineno, const SalStreamDescription
        rtcp_addr=desc->rtcp_addr;
        rtp_port=desc->rtp_port;
        rtcp_port=desc->rtcp_port;
-       if (desc->candidates[0].addr[0]!='\0'){
-               rtp_addr=desc->candidates[0].addr;
-               rtp_port=desc->candidates[0].port;
-       }
 
        if (desc->proto == SalProtoRtpSavp) {
                int i;
@@ -383,10 +381,12 @@ static void add_line(sdp_message_t *msg, int lineno, const SalStreamDescription
        if (desc->ice_mismatch == TRUE) {
                sdp_message_a_attribute_add(msg, lineno, osip_strdup("ice-mismatch"), NULL);
        } else {
-               if (desc->ice_pwd[0] != '\0') sdp_message_a_attribute_add(msg, lineno, osip_strdup("ice-pwd"), osip_strdup(desc->ice_pwd));
-               if (desc->ice_ufrag[0] != '\0') sdp_message_a_attribute_add(msg, lineno, osip_strdup("ice-ufrag"), osip_strdup(desc->ice_ufrag));
-               add_ice_candidates(msg, lineno, desc);
-               add_ice_remote_candidates(msg, lineno, desc);
+               if (desc->rtp_port != 0) {
+                       if (desc->ice_pwd[0] != '\0') sdp_message_a_attribute_add(msg, lineno, osip_strdup("ice-pwd"), osip_strdup(desc->ice_pwd));
+                       if (desc->ice_ufrag[0] != '\0') sdp_message_a_attribute_add(msg, lineno, osip_strdup("ice-ufrag"), osip_strdup(desc->ice_ufrag));
+                       add_ice_candidates(msg, lineno, desc);
+                       add_ice_remote_candidates(msg, lineno, desc);
+               }
        }
 }
 
@@ -394,7 +394,7 @@ static void add_line(sdp_message_t *msg, int lineno, const SalStreamDescription
 sdp_message_t *media_description_to_sdp(const SalMediaDescription *desc){
        int i;
        sdp_message_t *msg=create_generic_sdp(desc);
-       for(i=0;i<desc->nstreams;++i){
+       for(i=0;i<desc->n_total_streams;++i){
                add_line(msg,i,&desc->streams[i]);
        }
        return msg;
@@ -434,10 +434,17 @@ static int payload_type_fill_from_rtpmap(PayloadType *pt, const char *rtpmap){
 int sdp_to_media_description(sdp_message_t *msg, SalMediaDescription *desc){
        int i,j;
        const char *mtype,*proto,*rtp_port,*rtp_addr,*number;
+       const char *sess;
        sdp_bandwidth_t *sbw=NULL;
        sdp_attribute_t *attr;
        int nb_ice_candidates;
 
+       /* Get session information. */
+       sess = sdp_message_o_sess_id_get(msg);
+       if (sess) desc->session_id = strtoul(sess, NULL, 10);
+       sess = sdp_message_o_sess_version_get(msg);
+       if (sess) desc->session_ver = strtoul(sess, NULL, 10);
+
        rtp_addr=sdp_message_c_addr_get (msg, -1, 0);
        if (rtp_addr)
                strncpy(desc->addr,rtp_addr,sizeof(desc->addr));
@@ -456,6 +463,8 @@ int sdp_to_media_description(sdp_message_t *msg, SalMediaDescription *desc){
                }
        }
 
+       desc->n_active_streams = 0;
+
        /* for each m= line */
        for (i=0; !sdp_message_endof_media (msg, i) && i<SAL_MEDIA_DESCRIPTION_MAX_STREAMS; i++)
        {
@@ -479,6 +488,8 @@ int sdp_to_media_description(sdp_message_t *msg, SalMediaDescription *desc){
                        strncpy(stream->rtp_addr,rtp_addr,sizeof(stream->rtp_addr));
                if (rtp_port)
                        stream->rtp_port=atoi(rtp_port);
+               if (stream->rtp_port > 0)
+                       desc->n_active_streams++;
                
                stream->ptime=_sdp_message_get_a_ptime(msg,i);
                if (strcasecmp("audio", mtype) == 0){
@@ -513,7 +524,7 @@ int sdp_to_media_description(sdp_message_t *msg, SalMediaDescription *desc){
 
                /* Get media specific RTCP attribute */
                stream->rtcp_port = stream->rtp_port + 1;
-               snprintf(stream->rtcp_addr, sizeof(stream->rtcp_addr), stream->rtp_addr);
+               snprintf(stream->rtcp_addr, sizeof(stream->rtcp_addr), "%s", stream->rtp_addr);
                for (j = 0; ((attr = sdp_message_attribute_get(msg, i, j)) != NULL); j++) {
                        if ((keywordcmp("rtcp", attr->a_att_field) == 0) && (attr->a_att_value != NULL)) {
                                char tmp[256];
@@ -602,6 +613,6 @@ int sdp_to_media_description(sdp_message_t *msg, SalMediaDescription *desc){
                        }
                }
        }
-       desc->nstreams=i;
+       desc->n_total_streams=i;
        return 0;
 }