]> sjero.net Git - linphone/commitdiff
Set external port equal to local port the first time
authorYann Diorcet <yann.diorcet@belledonne-communications.com>
Mon, 7 Jan 2013 15:08:09 +0000 (16:08 +0100)
committerYann Diorcet <yann.diorcet@belledonne-communications.com>
Mon, 7 Jan 2013 15:08:09 +0000 (16:08 +0100)
coreapi/callbacks.c
coreapi/linphonecall.c
coreapi/linphonecore.c
coreapi/private.h
coreapi/upnp.c

index 4eec5be3d1d30df77e3dcd40b66cda37d6df3c6c..3a21e5a6d5fb4aa1e1c8fcdde3cf0db2efaef987 100644 (file)
@@ -432,7 +432,7 @@ static void call_accept_update(LinphoneCore *lc, LinphoneCall *call){
                linphone_core_update_upnp_from_remote_media_description(call, rmd);
                linphone_core_update_local_media_description_from_upnp(call->localdesc,call->upnp_session);
        }
-#endif
+#endif //BUILD_UPNP
        sal_call_accept(call->op);
        md=sal_call_get_final_media_description(call->op);
        if (md && !sal_media_description_empty(md))
index ec76311a6c4fcab9f1816b40d5a16c33e48b7d2e..d8de9659cd9d3185cba9489c52da733fcc12f9b5 100644 (file)
@@ -287,7 +287,7 @@ void linphone_call_make_local_media_description(LinphoneCore *lc, LinphoneCall *
        if(call->upnp_session != NULL) {
                linphone_core_update_local_media_description_from_upnp(md, call->upnp_session);
        }
-#endif
+#endif  //BUILD_UPNP
        linphone_address_destroy(addr);
        call->localdesc=md;
        if (old_md) sal_media_description_unref(old_md);
index 7abce8e9612dbad29ad1df3b6d9d3b4b59fceb0f..1da9ad5cd3165b04ad5e9d45b35a88a95db946e1 100644 (file)
@@ -1219,7 +1219,7 @@ static void linphone_core_init (LinphoneCore * lc, const LinphoneCoreVTable *vta
 #endif
 #ifdef BUILD_UPNP
        upnp_context_init(lc);
-#endif
+#endif  //BUILD_UPNP
        if (lc->vtable.display_status)
                lc->vtable.display_status(lc,_("Ready"));
        lc->auto_net_state_mon=lc->sip_conf.auto_net_state_mon;
@@ -1320,7 +1320,7 @@ void linphone_core_get_local_ip(LinphoneCore *lc, const char *dest, char *result
                strncpy(result,ip,LINPHONE_IPADDR_SIZE);
                return;
        }
-#endif
+#endif  //BUILD_UPNP
        if (linphone_core_get_local_ip_for(lc->sip_conf.ipv6_enabled ? AF_INET6 : AF_INET,dest,result)==0)
                return;
        /*else fallback to SAL routine that will attempt to find the most realistic interface */
@@ -2504,7 +2504,7 @@ LinphoneCall * linphone_core_invite_address_with_params(LinphoneCore *lc, const
                } else {
                        defer = TRUE;
                }
-#endif
+#endif //BUILD_UPNP
        }
 
        if (call->dest_proxy==NULL && lc->sip_conf.ping_with_options==TRUE){
@@ -2661,7 +2661,7 @@ int linphone_core_start_update_call(LinphoneCore *lc, LinphoneCall *call){
        if(call->upnp_session != NULL) {
                linphone_core_update_local_media_description_from_upnp(call->localdesc, call->upnp_session);
        }
-#endif
+#endif //BUILD_UPNP
        if (call->params.in_conference){
                subject="Conference";
        }else{
@@ -2780,7 +2780,7 @@ int linphone_core_start_accept_call_update(LinphoneCore *lc, LinphoneCall *call)
        if(call->upnp_session != NULL) {
                linphone_core_update_local_media_description_from_upnp(call->localdesc, call->upnp_session);
        }
-#endif
+#endif //BUILD_UPNP
        sal_call_set_local_media_description(call->op,call->localdesc);
        sal_call_accept(call->op);
        md=sal_call_get_final_media_description(call->op);
@@ -3164,7 +3164,7 @@ int linphone_core_pause_call(LinphoneCore *lc, LinphoneCall *call)
        if(call->upnp_session != NULL) {
                linphone_core_update_local_media_description_from_upnp(call->localdesc, call->upnp_session);
        }
-#endif
+#endif //BUILD_UPNP
        if (sal_media_description_has_dir(call->resultdesc,SalStreamSendRecv)){
                sal_media_description_set_dir(call->localdesc,SalStreamSendOnly);
                subject="Call on hold";
@@ -3249,7 +3249,7 @@ int linphone_core_resume_call(LinphoneCore *lc, LinphoneCall *the_call)
        if(call->upnp_session != NULL) {
                linphone_core_update_local_media_description_from_upnp(call->localdesc, call->upnp_session);
        }
-#endif
+#endif //BUILD_UPNP
        sal_call_set_local_media_description(call->op,call->localdesc);
        sal_media_description_set_dir(call->localdesc,SalStreamSendRecv);
        if (call->params.in_conference && !call->current_params.in_conference) subject="Conference";
@@ -4980,7 +4980,7 @@ static void linphone_core_uninit(LinphoneCore *lc)
 
 #ifdef BUILD_UPNP
        upnp_context_uninit(lc);
-#endif
+#endif  //BUILD_UPNP
 
        ms_list_for_each(lc->call_logs,(void (*)(void*))linphone_call_log_destroy);
        lc->call_logs=ms_list_free(lc->call_logs);
index d4abf16ca2eed60eff517aeeb750fe9242b56ce7..b2b724d837f544548625f523ec020c9ad0d73d58 100644 (file)
@@ -42,7 +42,7 @@ extern "C" {
 #include "mediastreamer2/msconference.h"
 #ifdef BUILD_UPNP
 #include "upnp.h"
-#endif
+#endif  //BUILD_UPNP
 
 #ifndef LIBLINPHONE_VERSION
 #define LIBLINPHONE_VERSION LINPHONE_VERSION
index 94072a4fc9d3a3cdf3be32970d8e91c0d47dbd3e..530bf1bf17ea3f503d27e30415bdf34afb3f620d 100644 (file)
@@ -132,6 +132,7 @@ void linphone_upnp_igd_callback(void *cookie, upnp_igd_event event, void *arg) {
        case UPNP_IGD_PORT_MAPPING_ADD_FAILURE:
                mapping = (upnp_igd_port_mapping *) arg;
                port_mapping = (UpnpPortBinding*) mapping->cookie;
+               port_mapping->external_port = -1; //Force a new random port
                if(upnp_context_send_add_port_binding(lc, port_mapping) != 0) {
                        upnp_port_binding_log(ORTP_ERROR, "Can't add port binding", port_mapping);
                }
@@ -188,6 +189,7 @@ int upnp_context_init(LinphoneCore *lc) {
                lupnp->sip_udp = upnp_port_binding_new();
                lupnp->sip_udp->protocol = UPNP_IGD_IP_PROTOCOL_UDP;
                lupnp->sip_udp->local_port = transport.udp_port;
+               lupnp->sip_udp->external_port = transport.udp_port;
        } else {
                lupnp->sip_udp = NULL;
        }
@@ -195,6 +197,7 @@ int upnp_context_init(LinphoneCore *lc) {
                lupnp->sip_tcp = upnp_port_binding_new();
                lupnp->sip_tcp->protocol = UPNP_IGD_IP_PROTOCOL_TCP;
                lupnp->sip_tcp->local_port = transport.tcp_port;
+               lupnp->sip_tcp->external_port = transport.tcp_port;
        } else {
                lupnp->sip_tcp = NULL;
        }
@@ -202,6 +205,7 @@ int upnp_context_init(LinphoneCore *lc) {
                lupnp->sip_tls = upnp_port_binding_new();
                lupnp->sip_tls->protocol = UPNP_IGD_IP_PROTOCOL_TCP;
                lupnp->sip_tls->local_port = transport.tls_port;
+               lupnp->sip_tls->external_port = transport.tls_port;
        } else {
                lupnp->sip_tls = NULL;
        }
@@ -257,7 +261,6 @@ int upnp_context_send_add_port_binding(LinphoneCore *lc, UpnpPortBinding *port)
        upnp_igd_port_mapping mapping;
        int ret;
        if(port->state == LinphoneUpnpStateIdle) {
-               port->external_port = -1;
                port->retry = 0;
                port->state = LinphoneUpnpStateAdding;
        } else if(port->state != LinphoneUpnpStateAdding) {
@@ -272,7 +275,7 @@ int upnp_context_send_add_port_binding(LinphoneCore *lc, UpnpPortBinding *port)
                mapping.local_port = port->local_port;
                mapping.local_host = port->local_addr;
                if(port->external_port == -1)
-                       mapping.remote_port = rand()%1024 + 1024; // TODO: use better method
+                       mapping.remote_port = rand()%(0xffff - 1024) + 1024; // TODO: use better method
                else
                        mapping.remote_port = port->external_port;
                mapping.remote_host = "";
@@ -339,9 +342,11 @@ int linphone_core_update_upnp_audio_video(LinphoneCall *call, bool_t audio, bool
                strncpy(call->upnp_session->audio->rtp->local_addr, local_addr, LINPHONE_IPADDR_SIZE);
                strncpy(call->upnp_session->audio->rtp->external_addr, external_addr, LINPHONE_IPADDR_SIZE);
                call->upnp_session->audio->rtp->local_port = call->audio_port;
+               call->upnp_session->audio->rtp->external_port = call->audio_port;
                strncpy(call->upnp_session->audio->rtcp->local_addr, local_addr, LINPHONE_IPADDR_SIZE);
                strncpy(call->upnp_session->audio->rtcp->external_addr, external_addr, LINPHONE_IPADDR_SIZE);
                call->upnp_session->audio->rtcp->local_port = call->audio_port+1;
+               call->upnp_session->audio->rtcp->external_port = call->audio_port+1;
                if(call->upnp_session->audio->rtp->state == LinphoneUpnpStateIdle && audio) {
                        // Add audio port binding
                        upnp_context_send_add_port_binding(lc, call->upnp_session->audio->rtp);
@@ -363,9 +368,11 @@ int linphone_core_update_upnp_audio_video(LinphoneCall *call, bool_t audio, bool
                strncpy(call->upnp_session->video->rtp->local_addr, local_addr, LINPHONE_IPADDR_SIZE);
                strncpy(call->upnp_session->video->rtp->external_addr, external_addr, LINPHONE_IPADDR_SIZE);
                call->upnp_session->video->rtp->local_port = call->video_port;
+               call->upnp_session->video->rtp->external_port = call->video_port;
                strncpy(call->upnp_session->video->rtcp->local_addr, local_addr, LINPHONE_IPADDR_SIZE);
                strncpy(call->upnp_session->video->rtcp->external_addr, external_addr, LINPHONE_IPADDR_SIZE);
                call->upnp_session->video->rtcp->local_port = call->video_port+1;
+               call->upnp_session->video->rtcp->external_port = call->video_port+1;
                if(call->upnp_session->video->rtp->state == LinphoneUpnpStateIdle && video) {
                        // Add video port binding
                        upnp_context_send_add_port_binding(lc, call->upnp_session->video->rtp);