Commit 9567e2bf authored by Yann Diorcet's avatar Yann Diorcet
Browse files

Working sip upnp

parent 806203ca
......@@ -416,6 +416,11 @@ static void call_accept_update(LinphoneCore *lc, LinphoneCall *call){
linphone_core_update_ice_from_remote_media_description(call,rmd);
linphone_core_update_local_media_description_from_ice(call->localdesc,call->ice_session);
}
#ifdef BUILD_UPNP
if(call->upnp_session != NULL) {
linphone_core_update_local_media_description_from_upnp(call->localdesc,call->upnp_session);
}
#endif
sal_call_accept(call->op);
md=sal_call_get_final_media_description(call->op);
if (md && !sal_media_description_empty(md))
......
......@@ -283,6 +283,11 @@ void linphone_call_make_local_media_description(LinphoneCore *lc, LinphoneCall *
linphone_core_update_local_media_description_from_ice(md, call->ice_session);
linphone_core_update_ice_state_in_call_stats(call);
}
#ifdef BUILD_UPNP
if(call->upnp_session != NULL) {
linphone_core_update_local_media_description_from_upnp(md, call->upnp_session);
}
#endif
linphone_address_destroy(addr);
call->localdesc=md;
if (old_md) sal_media_description_unref(old_md);
......@@ -439,7 +444,7 @@ LinphoneCall * linphone_call_new_outgoing(struct _LinphoneCore *lc, LinphoneAddr
call->op=sal_op_new(lc->sal);
sal_op_set_user_pointer(call->op,call);
call->core=lc;
linphone_core_get_local_ip(lc,linphone_address_get_domain(to),call->localip);
linphone_core_get_public_ip(lc,linphone_address_get_domain(to),call->localip);
linphone_call_init_common(call,from,to);
call->params=*params;
if (linphone_core_get_firewall_policy(call->core) == LinphonePolicyUseIce) {
......@@ -486,7 +491,7 @@ LinphoneCall * linphone_call_new_incoming(LinphoneCore *lc, LinphoneAddress *fro
}
linphone_address_clean(from);
linphone_core_get_local_ip(lc,linphone_address_get_domain(from),call->localip);
linphone_core_get_public_ip(lc,linphone_address_get_domain(from),call->localip);
linphone_call_init_common(call, from, to);
call->log->call_id=ms_strdup(sal_op_get_call_id(op)); /*must be known at that time*/
linphone_core_init_default_params(lc, &call->params);
......@@ -1693,7 +1698,7 @@ void linphone_call_delete_ice_session(LinphoneCall *call){
#ifdef BUILD_UPNP
void linphone_call_delete_upnp_session(LinphoneCall *call){
if(call->upnp_session!=NULL) {
upnp_session_destroy(call->upnp_session);
upnp_session_destroy(call);
call->upnp_session=NULL;
}
}
......
......@@ -66,7 +66,6 @@ static void linphone_core_free_hooks(LinphoneCore *lc);
#include "enum.h"
const char *linphone_core_get_nat_address_resolved(LinphoneCore *lc);
void linphone_core_get_local_ip(LinphoneCore *lc, const char *dest, char *result);
static void toggle_video_preview(LinphoneCore *lc, bool_t val);
/* relative path where is stored local ring*/
......@@ -1307,13 +1306,20 @@ int linphone_core_set_primary_contact(LinphoneCore *lc, const char *contact)
/*result must be an array of chars at least LINPHONE_IPADDR_SIZE */
void linphone_core_get_local_ip(LinphoneCore *lc, const char *dest, char *result){
void linphone_core_get_public_ip(LinphoneCore *lc, const char *dest, char *result){
const char *ip;
if (linphone_core_get_firewall_policy(lc)==LinphonePolicyUseNatAddress
&& (ip=linphone_core_get_nat_address_resolved(lc))!=NULL){
strncpy(result,ip,LINPHONE_IPADDR_SIZE);
return;
}
#ifdef BUILD_UPNP
else if (linphone_core_get_firewall_policy(lc)==LinphonePolicyUseUpnp
&& lc->upnp.state == LinphoneUpnpStateOk) {
ip = upnp_igd_get_external_ipaddress(lc->upnp.upnp_igd_ctxt);
strncpy(result,ip,LINPHONE_IPADDR_SIZE);
}
#endif
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 */
......@@ -1334,7 +1340,7 @@ static void update_primary_contact(LinphoneCore *lc){
ms_error("Could not parse identity contact !");
url=linphone_address_new("sip:unknown@unkwownhost");
}
linphone_core_get_local_ip(lc, NULL, tmp);
linphone_core_get_public_ip(lc, NULL, tmp);
if (strcmp(tmp,"127.0.0.1")==0 || strcmp(tmp,"::1")==0 ){
ms_warning("Local loopback network only !");
lc->sip_conf.loopback_only=TRUE;
......@@ -2006,7 +2012,7 @@ void linphone_core_iterate(LinphoneCore *lc){
linphone_call_stop_media_streams_for_ice_gathering(call);
}
if (call->upnp_session != NULL) {
ms_warning("uPnP mapping has not finished yet, proceeded with the call withoutt uPnP anyway.");
ms_warning("uPnP mapping has not finished yet, proceeded with the call without uPnP anyway.");
linphone_call_delete_upnp_session(call);
}
linphone_core_start_invite(lc,call);
......@@ -2639,9 +2645,14 @@ void linphone_core_notify_incoming_call(LinphoneCore *lc, LinphoneCall *call){
int linphone_core_start_update_call(LinphoneCore *lc, LinphoneCall *call){
const char *subject;
call->camera_active=call->params.has_video;
if (call->ice_session != NULL)
if (call->ice_session != NULL) {
linphone_core_update_local_media_description_from_ice(call->localdesc, call->ice_session);
}
#ifdef BUILD_UPNP
if(call->upnp_session != NULL) {
linphone_core_update_local_media_description_from_upnp(call->localdesc, call->upnp_session);
}
#endif
if (call->params.in_conference){
subject="Conference";
}else{
......@@ -2756,6 +2767,11 @@ int linphone_core_start_accept_call_update(LinphoneCore *lc, LinphoneCall *call)
}
linphone_core_update_local_media_description_from_ice(call->localdesc, call->ice_session);
}
#ifdef BUILD_UPNP
if(call->upnp_session != NULL) {
linphone_core_update_local_media_description_from_upnp(call->localdesc, call->upnp_session);
}
#endif
sal_call_set_local_media_description(call->op,call->localdesc);
sal_call_accept(call->op);
md=sal_call_get_final_media_description(call->op);
......@@ -3124,8 +3140,14 @@ int linphone_core_pause_call(LinphoneCore *lc, LinphoneCall *call)
return -1;
}
linphone_call_make_local_media_description(lc,call);
if (call->ice_session != NULL)
if (call->ice_session != NULL) {
linphone_core_update_local_media_description_from_ice(call->localdesc, call->ice_session);
}
#ifdef BUILD_UPNP
if(call->upnp_session != NULL) {
linphone_core_update_local_media_description_from_upnp(call->localdesc, call->upnp_session);
}
#endif
if (sal_media_description_has_dir(call->resultdesc,SalStreamSendRecv)){
sal_media_description_set_dir(call->localdesc,SalStreamSendOnly);
subject="Call on hold";
......@@ -3203,8 +3225,14 @@ int linphone_core_resume_call(LinphoneCore *lc, LinphoneCall *the_call)
if (call->audiostream) audio_stream_play(call->audiostream, NULL);
linphone_call_make_local_media_description(lc,the_call);
if (call->ice_session != NULL)
if (call->ice_session != NULL) {
linphone_core_update_local_media_description_from_ice(call->localdesc, call->ice_session);
}
#ifdef BUILD_UPNP
if(call->upnp_session != NULL) {
linphone_core_update_local_media_description_from_upnp(call->localdesc, call->upnp_session);
}
#endif
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";
......
......@@ -206,7 +206,7 @@ int set_lock_file();
int get_lock_file();
int remove_lock_file();
void check_sound_device(LinphoneCore *lc);
void linphone_core_get_local_ip(LinphoneCore *lc, const char *to, char *result);
void linphone_core_get_public_ip(LinphoneCore *lc, const char *to, char *result);
bool_t host_has_ipv6_network();
bool_t lp_spawn_command_line_sync(const char *command, char **result,int *command_ret);
......@@ -593,6 +593,9 @@ int linphone_core_del_call( LinphoneCore *lc, LinphoneCall *call);
int linphone_core_set_as_current_call(LinphoneCore *lc, LinphoneCall *call);
int linphone_core_get_calls_nb(const LinphoneCore *lc);
void linphone_core_add_iterate_hook(LinphoneCore *lc, LinphoneCoreIterateHook hook, void *hook_data);
void linphone_core_remove_iterate_hook(LinphoneCore *lc, LinphoneCoreIterateHook hook, void *hook_data);
void linphone_core_set_state(LinphoneCore *lc, LinphoneGlobalState gstate, const char *message);
void linphone_call_make_local_media_description(LinphoneCore *lc, LinphoneCall *call);
void linphone_core_update_streams(LinphoneCore *lc, LinphoneCall *call, SalMediaDescription *new_md);
......
......@@ -268,7 +268,7 @@ static char *guess_contact_for_register(LinphoneProxyConfig *obj){
LCSipTransports tr;
LinphoneAddress *contact;
linphone_core_get_local_ip(obj->lc,host,localip);
linphone_core_get_public_ip(obj->lc,host,localip);
contact=linphone_address_new(obj->reg_identity);
linphone_address_set_domain (contact,localip);
linphone_address_set_port_int(contact,linphone_core_get_sip_port(obj->lc));
......@@ -427,7 +427,7 @@ static dial_plan_t const dial_plans[]={
{"Congo Democratic Republic" ,"CD" , "243" , 9 , "00" },
{"Cook Islands" ,"CK" , "682" , 5 , "00" },
{"Costa Rica" ,"CR" , "506" , 8 , "00" },
{"Cte d'Ivoire" ,"AD" , "225" , 8 , "00" },
{"Cte d'Ivoire" ,"AD" , "225" , 8 , "00" },
{"Croatia" ,"HR" , "385" , 9 , "00" },
{"Cuba" ,"CU" , "53" , 8 , "119" },
{"Cyprus" ,"CY" , "357" , 8 , "00" },
......@@ -545,7 +545,7 @@ static dial_plan_t const dial_plans[]={
{"Portugal" ,"PT" , "351" , 9 , "00" },
{"Puerto Rico" ,"PR" , "1" , 10 , "011" },
{"Qatar" ,"QA" , "974" , 8 , "00" },
{"Runion Island" ,"RE" , "262" , 9 , "011" },
{"Runion Island" ,"RE" , "262" , 9 , "011" },
{"Romania" ,"RO" , "40" , 9 , "00" },
{"Russian Federation" ,"RU" , "7" , 10 , "8" },
{"Rwanda" ,"RW" , "250" , 9 , "00" },
......@@ -556,7 +556,7 @@ static dial_plan_t const dial_plans[]={
{"Saint Vincent and the Grenadines","VC" , "1" , 10 , "011" },
{"Samoa" ,"WS" , "685" , 7 , "0" },
{"San Marino" ,"SM" , "378" , 10 , "00" },
{"So Tom and Prncipe" ,"ST" , "239" , 7 , "00" },
{"So Tom and Prncipe" ,"ST" , "239" , 7 , "00" },
{"Saudi Arabia" ,"SA" , "966" , 9 , "00" },
{"Senegal" ,"SN" , "221" , 9 , "00" },
{"Serbia" ,"RS" , "381" , 9 , "00" },
......
This diff is collapsed.
......@@ -22,33 +22,42 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "mediastreamer2/upnp_igd.h"
#include "linphonecore.h"
#include "sal.h"
typedef enum {
UPNP_Idle,
UPNP_Pending,
UPNP_Ok,
UPNP_Ko,
LinphoneUpnpStateIdle,
LinphoneUpnpStatePending,
LinphoneUpnpStateAdding, // Only used by port binding
LinphoneUpnpStateRemoving, // Only used by port binding
LinphoneUpnpStateNotAvailable, // Only used by uPnP context
LinphoneUpnpStateOk,
LinphoneUpnpStateKo,
} UpnpState;
typedef struct _UpnpSession UpnpSession;
typedef struct _UpnpPortBinding {
ms_mutex_t mutex;
UpnpState state;
upnp_igd_ip_protocol protocol;
char local_addr[LINPHONE_IPADDR_SIZE];
int local_port;
int remote_port;
char external_addr[LINPHONE_IPADDR_SIZE];
int external_port;
int retry;
int ref;
} UpnpPortBinding;
struct _UpnpSession {
UpnpPortBinding *audio_rtp;
UpnpPortBinding *audio_rtcp;
UpnpPortBinding *video_rtp;
UpnpPortBinding *video_rtcp;
typedef struct _UpnpStream {
UpnpPortBinding *rtp;
UpnpPortBinding *rtcp;
UpnpState state;
};
} UpnpStream;
typedef struct _UpnpSession {
UpnpStream *audio;
UpnpStream *video;
UpnpState state;
} UpnpSession;
typedef struct _UpnpContext {
upnp_igd_context *upnp_igd_ctxt;
......@@ -56,15 +65,17 @@ typedef struct _UpnpContext {
UpnpPortBinding *sip_tls;
UpnpPortBinding *sip_udp;
UpnpState state;
MSList *pending_bindinds;
UpnpState old_state;
MSList *pending_configs;
ms_mutex_t mutex;
} UpnpContext;
void linphone_core_update_local_media_description_from_upnp(SalMediaDescription *desc, UpnpSession *session);
int linphone_core_update_upnp(LinphoneCore *lc, LinphoneCall *call);
int upnp_call_process(LinphoneCall *call);
UpnpSession* upnp_session_new();
void upnp_session_destroy(UpnpSession* session);
void upnp_session_destroy(LinphoneCall* call);
int upnp_context_init(LinphoneCore *lc);
void upnp_context_uninit(LinphoneCore *lc);
......
mediastreamer2 @ 34de96d6
Subproject commit 39998cb245606b904a77e093db168057f87bf8b0
Subproject commit 34de96d6b33f58b248f7d46e9c25edb11e6a5426
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment