From: Yann Diorcet Date: Mon, 25 Feb 2013 09:37:01 +0000 (+0100) Subject: Fix uPnP context destroy X-Git-Url: http://sjero.net/git/?p=linphone;a=commitdiff_plain;h=a30721377ac0859f1d15837cc67d6e73686203c9 Fix uPnP context destroy --- diff --git a/coreapi/upnp.c b/coreapi/upnp.c index e9ce18df..400cc7e2 100644 --- a/coreapi/upnp.c +++ b/coreapi/upnp.c @@ -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); diff --git a/mediastreamer2 b/mediastreamer2 index 4ed2e518..c48f1a31 160000 --- a/mediastreamer2 +++ b/mediastreamer2 @@ -1 +1 @@ -Subproject commit 4ed2e518cf79c62fe8df7f23ce99e0fbfe2e799d +Subproject commit c48f1a31d850ed9a1b607985d2a250a8ca048547