]> sjero.net Git - linphone/commitdiff
Fix uPnP context destroy
authorYann Diorcet <yann.diorcet@belledonne-communications.com>
Mon, 25 Feb 2013 09:37:01 +0000 (10:37 +0100)
committerYann Diorcet <yann.diorcet@belledonne-communications.com>
Mon, 25 Feb 2013 09:37:01 +0000 (10:37 +0100)
coreapi/upnp.c
mediastreamer2

index e9ce18df7661c469167e44309895a3764bc5fdee..400cc7e2a02defe9e078c8e9e12c070d12b3a53b 100644 (file)
@@ -93,6 +93,7 @@ void linphone_upnp_update_port_binding(UpnpContext *lupnp, UpnpPortBinding **por
 void linphone_upnp_port_binding_log(int level, const char *msg, const UpnpPortBinding *port);
 void linphone_upnp_port_binding_release(UpnpPortBinding *port);
 void linphone_upnp_update_config(UpnpContext *lupnp);
+void linphone_upnp_update_proxy(UpnpContext *lupnp, bool_t force);
 
 // Configuration
 MSList *linphone_upnp_config_list_port_bindings(struct _LpConfig *lpc);
@@ -310,12 +311,17 @@ void linphone_upnp_context_destroy(UpnpContext *lupnp) {
        }
 
        if(lupnp->upnp_igd_ctxt != NULL) {
+               // upnp_igd_destroy is synchronous so the callbacks will be called in the same thread.
+               // So release the mutex before upnp_igd_destroy call. 
+               ms_mutex_unlock(&lupnp->mutex);
                upnp_igd_destroy(lupnp->upnp_igd_ctxt);
+               ms_mutex_lock(&lupnp->mutex);
                lupnp->upnp_igd_ctxt = NULL;
        }
 
-       /* Run one more time configuration update */
+       /* Run one more time configuration update and proxy */
        linphone_upnp_update_config(lupnp);
+       linphone_upnp_update_proxy(lupnp, TRUE);
 
        /* Release port bindings */
        if(lupnp->sip_udp != NULL) {
@@ -858,23 +864,11 @@ void linphone_upnp_update_config(UpnpContext* lupnp) {
        lupnp->removing_configs = ms_list_free(lupnp->removing_configs);
 }
 
-bool_t linphone_core_upnp_hook(void *data) {
-       LCSipTransports transport;
+void linphone_upnp_update_proxy(UpnpContext* lupnp, bool_t force) {
        LinphoneUpnpState ready_state;
        const MSList *item;
-       time_t now = time(NULL);
-       UpnpContext *lupnp = (UpnpContext *)data;
-
-       ms_mutex_lock(&lupnp->mutex);
-
-       /* Update ports */
-       if(lupnp->state == LinphoneUpnpStateOk) {
-               linphone_core_get_sip_transports(lupnp->lc, &transport);
-               linphone_upnp_update_port_binding(lupnp, &lupnp->sip_udp, UPNP_IGD_IP_PROTOCOL_UDP, transport.udp_port, UPNP_CORE_RETRY_DELAY);
-               linphone_upnp_update_port_binding(lupnp, &lupnp->sip_tcp, UPNP_IGD_IP_PROTOCOL_TCP, transport.tcp_port, UPNP_CORE_RETRY_DELAY);
-               linphone_upnp_update_port_binding(lupnp, &lupnp->sip_tls, UPNP_IGD_IP_PROTOCOL_TCP, transport.tls_port, UPNP_CORE_RETRY_DELAY);
-       }
-
+       time_t now = (force)? (lupnp->last_ready_check + UPNP_CORE_READY_CHECK) : time(NULL);
+       
        /* Refresh registers if we are ready */
        if(now - lupnp->last_ready_check >= UPNP_CORE_READY_CHECK) {
                lupnp->last_ready_check = now;
@@ -896,7 +890,23 @@ bool_t linphone_core_upnp_hook(void *data) {
                        lupnp->last_ready_state = ready_state;
                }
        }
-                       
+}
+
+bool_t linphone_core_upnp_hook(void *data) {
+       LCSipTransports transport;
+       UpnpContext *lupnp = (UpnpContext *)data;
+
+       ms_mutex_lock(&lupnp->mutex);
+
+       /* Update ports */
+       if(lupnp->state == LinphoneUpnpStateOk) {
+               linphone_core_get_sip_transports(lupnp->lc, &transport);
+               linphone_upnp_update_port_binding(lupnp, &lupnp->sip_udp, UPNP_IGD_IP_PROTOCOL_UDP, transport.udp_port, UPNP_CORE_RETRY_DELAY);
+               linphone_upnp_update_port_binding(lupnp, &lupnp->sip_tcp, UPNP_IGD_IP_PROTOCOL_TCP, transport.tcp_port, UPNP_CORE_RETRY_DELAY);
+               linphone_upnp_update_port_binding(lupnp, &lupnp->sip_tls, UPNP_IGD_IP_PROTOCOL_TCP, transport.tls_port, UPNP_CORE_RETRY_DELAY);
+       }
+
+       linphone_upnp_update_proxy(lupnp, FALSE);       
        linphone_upnp_update_config(lupnp);
 
        ms_mutex_unlock(&lupnp->mutex);
index 4ed2e518cf79c62fe8df7f23ce99e0fbfe2e799d..c48f1a31d850ed9a1b607985d2a250a8ca048547 160000 (submodule)
@@ -1 +1 @@
-Subproject commit 4ed2e518cf79c62fe8df7f23ce99e0fbfe2e799d
+Subproject commit c48f1a31d850ed9a1b607985d2a250a8ca048547