From: Yann Diorcet Date: Fri, 21 Dec 2012 09:11:06 +0000 (+0100) Subject: Starting uPNP integration X-Git-Url: http://sjero.net/git/?p=linphone;a=commitdiff_plain;h=8026b597a768480a062b0cb43dcee6db84f8c939 Starting uPNP integration --- diff --git a/coreapi/Makefile.am b/coreapi/Makefile.am index 822c0b83..c5abd036 100644 --- a/coreapi/Makefile.am +++ b/coreapi/Makefile.am @@ -50,7 +50,7 @@ liblinphone_la_SOURCES=\ $(GITVERSION_FILE) if BUILD_UPNP -liblinphone_la_SOURCES+=upnp.c +liblinphone_la_SOURCES+=upnp.c upnp.h endif if BUILD_WIZARD diff --git a/coreapi/linphonecall.c b/coreapi/linphonecall.c index 5a18a052..6c8b4a74 100644 --- a/coreapi/linphonecall.c +++ b/coreapi/linphonecall.c @@ -449,6 +449,11 @@ LinphoneCall * linphone_call_new_outgoing(struct _LinphoneCore *lc, LinphoneAddr if (linphone_core_get_firewall_policy(call->core) == LinphonePolicyUseStun) { call->ping_time=linphone_core_run_stun_tests(call->core,call); } +#ifdef BUILD_UPNP + if (linphone_core_get_firewall_policy(call->core) == LinphonePolicyUseUpnp) { + call->upnp_session = upnp_session_new(); + } +#endif //BUILD_UPNP call->camera_active=params->has_video; discover_mtu(lc,linphone_address_get_domain (to)); diff --git a/coreapi/linphonecore.c b/coreapi/linphonecore.c index e52fff00..8619552f 100644 --- a/coreapi/linphonecore.c +++ b/coreapi/linphonecore.c @@ -1217,6 +1217,9 @@ static void linphone_core_init (LinphoneCore * lc, const LinphoneCoreVTable *vta #ifdef TUNNEL_ENABLED lc->tunnel=linphone_core_tunnel_new(lc); if (lc->tunnel) linphone_tunnel_configure(lc->tunnel); +#endif +#ifdef BUILD_UPNP + upnp_context_init(lc); #endif if (lc->vtable.display_status) lc->vtable.display_status(lc,_("Ready")); @@ -4901,6 +4904,9 @@ static void linphone_core_uninit(LinphoneCore *lc) #ifdef TUNNEL_ENABLED if (lc->tunnel) linphone_tunnel_destroy(lc->tunnel); #endif +#ifdef BUILD_UPNP + upnp_context_uninit(lc); +#endif } static void set_network_reachable(LinphoneCore* lc,bool_t isReachable, time_t curtime){ diff --git a/coreapi/linphonecore.h b/coreapi/linphonecore.h index f1a9174c..b4c25380 100644 --- a/coreapi/linphonecore.h +++ b/coreapi/linphonecore.h @@ -885,7 +885,8 @@ typedef enum _LinphoneFirewallPolicy{ LinphonePolicyNoFirewall, LinphonePolicyUseNatAddress, LinphonePolicyUseStun, - LinphonePolicyUseIce + LinphonePolicyUseIce, + LinphonePolicyUseUpnp, } LinphoneFirewallPolicy; typedef enum _LinphoneWaitingState{ diff --git a/coreapi/private.h b/coreapi/private.h index f69eb2ff..6af7e09e 100644 --- a/coreapi/private.h +++ b/coreapi/private.h @@ -28,9 +28,11 @@ extern "C" { #endif #include "linphonecore.h" +#include "linphonefriend.h" #include "linphone_tunnel.h" #include "linphonecore_utils.h" #include "sal.h" +#include "sipsetup.h" #ifdef HAVE_CONFIG_H #include "config.h" @@ -39,7 +41,7 @@ extern "C" { #include "mediastreamer2/mediastream.h" #include "mediastreamer2/msconference.h" #ifdef BUILD_UPNP -#include "mediastreamer2/upnp_igd.h" +#include "upnp.h" #endif #ifndef LIBLINPHONE_VERSION @@ -148,6 +150,9 @@ struct _LinphoneCall OrtpEvQueue *videostream_app_evq; CallCallbackObj nextVideoFrameDecoded; LinphoneCallStats stats[2]; +#ifdef BUILD_UPNP + UpnpSession *upnp_session; +#endif //BUILD_UPNP IceSession *ice_session; LinphoneChatMessage* pending_message; int ping_time; @@ -572,15 +577,15 @@ struct _LinphoneCore char* device_id; MSList *last_recv_msg_ids; #ifdef BUILD_UPNP - upnp_igd_context *upnp_igd_ctxt; -#endif + UpnpContext upnp; +#endif //BUILD_UPNP }; LinphoneTunnel *linphone_core_tunnel_new(LinphoneCore *lc); void linphone_tunnel_destroy(LinphoneTunnel *tunnel); void linphone_tunnel_configure(LinphoneTunnel *tunnel); void linphone_tunnel_enable_logs_with_handler(LinphoneTunnel *tunnel, bool_t enabled, OrtpLogFunc logHandler); - + bool_t linphone_core_can_we_add_call(LinphoneCore *lc); int linphone_core_add_call( LinphoneCore *lc, LinphoneCall *call); int linphone_core_del_call( LinphoneCore *lc, LinphoneCall *call); diff --git a/coreapi/upnp.c b/coreapi/upnp.c index 31fb5c5f..34622bf5 100644 --- a/coreapi/upnp.c +++ b/coreapi/upnp.c @@ -17,8 +17,8 @@ along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ +#include "upnp.h" #include "private.h" -#include "mediastreamer2/upnp_igd.h" /* Convert uPnP IGD logs to ortp logs */ void linphone_upnp_igd_print(void *cookie, upnp_igd_print_level level, const char *fmt, va_list list) { @@ -36,16 +36,41 @@ void linphone_upnp_igd_print(void *cookie, upnp_igd_print_level level, const cha default: break; } - ortp_logv(level, fmt, list); + ortp_logv(ortp_level, fmt, list); } void linphone_upnp_igd_callback(void *cookie, upnp_igd_event event, void *arg) { + LinphoneCore *lc = (LinphoneCore *)cookie; + UpnpContext *lupnp = &lc->upnp; + switch(event) { + case UPNP_IGD_EXTERNAL_IPADDRESS_CHANGED: + case UPNP_IGD_NAT_ENABLED_CHANGED: + case UPNP_IGD_CONNECTION_STATUS_CHANGED: + break; + + default: + break; + } } -int linphone_upnp_init(LinphoneCore *lc) { - lc->upnp_igd_ctxt = NULL; +int upnp_context_init(LinphoneCore *lc) { + UpnpContext *lupnp = &lc->upnp; + lupnp->upnp_igd_ctxt = NULL; + lupnp->upnp_igd_ctxt = upnp_igd_create(linphone_upnp_igd_callback, linphone_upnp_igd_print, lc); + if(lupnp->upnp_igd_ctxt == NULL) { + ms_error("Can't create uPnP IGD context"); + return -1; + } return 0; } -void linphone_upnp_destroy(LinphoneCore *lc) { +void upnp_context_uninit(LinphoneCore *lc) { + UpnpContext *lupnp = &lc->upnp; + if(lupnp->upnp_igd_ctxt != NULL) { + upnp_igd_destroy(lupnp->upnp_igd_ctxt); + } +} + +UpnpSession* upnp_session_new() { + return NULL; } diff --git a/coreapi/upnp.h b/coreapi/upnp.h new file mode 100644 index 00000000..c5ff5eca --- /dev/null +++ b/coreapi/upnp.h @@ -0,0 +1,38 @@ +/* +linphone +Copyright (C) 2012 Belledonne Communications SARL + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation; either version 2 +of the License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +*/ + +#ifndef LINPHONE_UPNP_H +#define LINPHONE_UPNP_H + +#include "mediastreamer2/upnp_igd.h" +#include "linphonecore.h" + +typedef struct _UpnpSession { + +} UpnpSession; + +typedef struct _UpnpContext { + upnp_igd_context *upnp_igd_ctxt; +} UpnpContext; + +UpnpSession* upnp_session_new(); +int upnp_context_init(LinphoneCore *lc); +void upnp_context_uninit(LinphoneCore *lc); + +#endif //LINPHONE_UPNP_H diff --git a/mediastreamer2 b/mediastreamer2 index 2093868a..a1f11352 160000 --- a/mediastreamer2 +++ b/mediastreamer2 @@ -1 +1 @@ -Subproject commit 2093868ac68ffe62310cd0ad20b58ffa6860d7e3 +Subproject commit a1f113529f506aa178765cf70773db80e5768139