]> sjero.net Git - linphone/commitdiff
implement sending of early media
authorSimon Morlat <simon.morlat@linphone.org>
Sun, 26 Sep 2010 11:02:05 +0000 (13:02 +0200)
committerSimon Morlat <simon.morlat@linphone.org>
Sun, 26 Sep 2010 11:02:05 +0000 (13:02 +0200)
coreapi/callbacks.c
coreapi/linphonecall.c
coreapi/linphonecore.c
coreapi/linphonecore.h
coreapi/offeranswer.c
coreapi/private.h
coreapi/sal.c
coreapi/sal.h
coreapi/sal_eXosip2.c
mediastreamer2

index 7c8533759df5004f985780a070a7df5f3cd56843..ffb0f2b25643b58727239b17dca2acdbfa1767eb 100644 (file)
@@ -23,6 +23,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 #include "linphonecore.h"
 #include "private.h"
 #include "mediastreamer2/mediastream.h"
+#include "lpconfig.h"
 
 static void register_failure(SalOp *op, SalError error, SalReason reason, const char *details);
 
@@ -41,6 +42,7 @@ static void call_received(SalOp *h){
        const char *from,*to;
        char *tmp;
        LinphoneAddress *from_parsed;
+       bool_t early_media=lp_config_get_int(lc->config,"sip","send_early_media",0);
 
        /* first check if we can answer successfully to this invite */
        if (lc->presence_mode==LinphoneStatusBusy ||
@@ -116,9 +118,12 @@ static void call_received(SalOp *h){
        }else{
                /*TODO : play a tone within the context of the current call */
        }
-       sal_call_notify_ringing(h);
+       sal_call_notify_ringing(h,early_media);
 #if !(__IPHONE_OS_VERSION_MIN_REQUIRED >= 40000)
        linphone_call_init_media_streams(call);
+       if (early_media){
+               linphone_call_start_early_media (call);
+       }
 #endif
        ms_free(barmesg);
        ms_free(tmp);
index acc18bfe23e55bfeefd712ea96de78a3cc3da00d..daf512264406e2ab96ba0f961723d828fa8b8fe1 100644 (file)
@@ -30,6 +30,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 #include "mediastreamer2/mediastream.h"
 #include "mediastreamer2/msvolume.h"
 #include "mediastreamer2/msequalizer.h"
+#include "mediastreamer2/msfileplayer.h"
 
 static MSWebCam *get_nowebcam_device(){
        return ms_web_cam_manager_get_cam(ms_web_cam_manager_get(),"StaticImage: Static picture");
@@ -53,9 +54,11 @@ SalMediaDescription *create_local_media_description(LinphoneCore *lc,
                LinphoneCall *call, bool_t with_video, bool_t only_one_codec){
        MSList *l;
        PayloadType *pt;
-       const char *username=(call->dir==LinphoneCallOutgoing) ?
-                                       linphone_address_get_username(call->log->from): linphone_address_get_username(call->log->to);
+       const char *me=linphone_core_get_identity(lc);
+       LinphoneAddress *addr=linphone_address_new(me);
+       const char *username=linphone_address_get_username (addr);
        SalMediaDescription *md=sal_media_description_new();
+
        md->nstreams=1;
        strncpy(md->addr,call->localip,sizeof(md->addr));
        strncpy(md->username,username,sizeof(md->username));
@@ -84,6 +87,7 @@ SalMediaDescription *create_local_media_description(LinphoneCore *lc,
                if (lc->dw_video_bw)
                        md->streams[1].bandwidth=lc->dw_video_bw;
        }
+       linphone_address_destroy(addr);
        return md;
 }
 
@@ -159,7 +163,6 @@ LinphoneCall * linphone_call_new_outgoing(struct _LinphoneCore *lc, LinphoneAddr
 
 LinphoneCall * linphone_call_new_incoming(LinphoneCore *lc, LinphoneAddress *from, LinphoneAddress *to, SalOp *op){
        LinphoneCall *call=ms_new0(LinphoneCall,1);
-       LinphoneAddress *me=linphone_core_get_primary_contact_parsed(lc);
        char *to_str;
        char *from_str;
 
@@ -191,7 +194,6 @@ LinphoneCall * linphone_call_new_incoming(LinphoneCore *lc, LinphoneAddress *fro
        if (linphone_core_get_firewall_policy(call->core)==LinphonePolicyUseStun)
                linphone_core_run_stun_tests(call->core,call);
        discover_mtu(lc,linphone_address_get_domain(from));
-       linphone_address_destroy(me);
        return call;
 }
 
@@ -675,7 +677,14 @@ static RtpProfile *make_profile(LinphoneCore *lc, const SalMediaDescription *md,
        return prof;
 }
 
-void linphone_call_start_media_streams(LinphoneCall *call){
+static void setup_ring_player(LinphoneCore *lc, LinphoneCall *call){
+       const char *ringfile=lc->sound_conf.remote_ring;
+       int pause_time=3000;
+       audio_stream_play(call->audiostream,ringfile);
+       ms_filter_call_method(call->audiostream->soundread,MS_FILE_PLAYER_LOOP,&pause_time);
+}
+
+static void _linphone_call_start_media_streams(LinphoneCall *call, bool_t send_early_media){
        LinphoneCore *lc=call->core;
        LinphoneAddress *me=linphone_core_get_primary_contact_parsed(lc);
        const char *tool="linphone-" LINPHONE_VERSION;
@@ -714,7 +723,7 @@ void linphone_call_start_media_streams(LinphoneCall *call){
                                if (stream->port==0 || stream->dir==SalStreamRecvOnly){
                                        captcard=NULL;
                                        playfile=NULL;
-                               }else if (stream->dir==SalStreamSendOnly){
+                               }else if (stream->dir==SalStreamSendOnly || send_early_media){
                                        playcard=NULL;
                                        captcard=NULL;
                                        recfile=NULL;
@@ -738,12 +747,13 @@ void linphone_call_start_media_streams(LinphoneCall *call){
                                        captcard,
                                        linphone_core_echo_cancellation_enabled(lc));
                                post_configure_audio_streams(call);
+                               if (send_early_media) setup_ring_player(lc,call);
                                audio_stream_set_rtcp_information(call->audiostream, cname, tool);
                        }else ms_warning("No audio stream accepted ?");
                }
        }
 #ifdef VIDEO_ENABLED
-       {
+       if (!send_early_media){
                const SalStreamDescription *stream=sal_media_description_find_stream(call->resultdesc,
                                                        SalProtoRtpAvp,SalVideo);
                used_pt=-1;
@@ -804,6 +814,13 @@ void linphone_call_start_media_streams(LinphoneCall *call){
 }
 
 
+void linphone_call_start_media_streams(LinphoneCall *call){
+       _linphone_call_start_media_streams(call,FALSE);
+}
+
+void linphone_call_start_early_media(LinphoneCall *call){
+       _linphone_call_start_media_streams(call,TRUE);
+}
 
 static void linphone_call_log_fill_stats(LinphoneCallLog *log, AudioStream *st){
        audio_stream_get_local_rtp_stats (st,&log->local_stats);
index 384943a93ae5f6adca64d26f05ca002fffe86395..45af43724668f71a995683d852c265403a939af0 100644 (file)
@@ -1792,7 +1792,7 @@ LinphoneAddress * linphone_core_interpret_url(LinphoneCore *lc, const char *url)
 /**
  * Returns the default identity SIP address.
  *
- * @ingroup proxiesb
+ * @ingroup proxies
  * This is an helper function:
  *
  * If no default proxy is set, this will return the primary contact (
@@ -2231,6 +2231,12 @@ int linphone_core_accept_call(LinphoneCore *lc, LinphoneCall *call)
                sal_op_set_contact(call->op,contact);
 #if __IPHONE_OS_VERSION_MIN_REQUIRED >= 40000
        linphone_call_init_media_streams(call);
+#else
+       if (call->audiostream!=NULL && call->audiostream->ticker!=NULL){
+               /*case where we sent early media*/
+               linphone_call_stop_media_streams (call);
+               linphone_call_init_media_streams (call);
+       }
 #endif
        sal_call_accept(call->op);
        if (lc->vtable.display_status!=NULL)
index d360f83df032acbd36ff15d148e80f76f0d5e727..12ca8675de41a339f9e2a1f45b72dbada14a501d 100644 (file)
@@ -591,6 +591,8 @@ int linphone_core_set_primary_contact(LinphoneCore *lc, const char *contact);
 
 const char *linphone_core_get_primary_contact(LinphoneCore *lc);
 
+const char * linphone_core_get_identity(LinphoneCore *lc);
+
 void linphone_core_set_guess_hostname(LinphoneCore *lc, bool_t val);
 bool_t linphone_core_get_guess_hostname(LinphoneCore *lc);
 
index ac5ea1d7a9ff2f2a3a2db8686c9368d6434e6530..baf84287ad8387535823b09b5ab67ed7323b35d0 100644 (file)
@@ -168,7 +168,7 @@ int offer_answer_initiate_outgoing(const SalMediaDescription *local_offer,
     for(i=0,j=0;i<local_offer->nstreams;++i){
                ms_message("Processing for stream %i",i);
                ls=&local_offer->streams[i];
-               rs=sal_media_description_find_stream(remote_answer,ls->proto,ls->type);
+               rs=sal_media_description_find_stream((SalMediaDescription*)remote_answer,ls->proto,ls->type);
        if (rs) {
                        initiate_outgoing(ls,rs,&result->streams[j]);
                        ++j;
@@ -194,7 +194,7 @@ int offer_answer_initiate_incoming(const SalMediaDescription *local_capabilities
     for(i=0,j=0;i<remote_offer->nstreams;++i){
                rs=&remote_offer->streams[i];
                ms_message("Processing for stream %i",i);
-               ls=sal_media_description_find_stream(local_capabilities,rs->proto,rs->type);
+               ls=sal_media_description_find_stream((SalMediaDescription*)local_capabilities,rs->proto,rs->type);
                if (ls){
                initiate_incoming(ls,rs,&result->streams[j]);
                        ++j;
index eb5a26c884fbce9dc54327fc27735a1c861f5ce8..7b6b999deb37f967b2eb48028d65007c1aa7e434 100644 (file)
@@ -183,7 +183,7 @@ void linphone_core_text_received(LinphoneCore *lc, const char *from, const char
 
 void linphone_call_init_media_streams(LinphoneCall *call);
 void linphone_call_start_media_streams(LinphoneCall *call);
-void linphone_call_set_media_streams_dir(LinphoneCall *call, SalStreamDir dir);
+void linphone_call_start_early_media(LinphoneCall *call);
 void linphone_call_stop_media_streams(LinphoneCall *call);
 
 const char * linphone_core_get_identity(LinphoneCore *lc);
index ca5b4d815bada807207bf77bf5e9e306f156757d..3c8801ad8e8a592c4281de657c77cf2cf7bfe61e 100644 (file)
@@ -52,11 +52,11 @@ void sal_media_description_unref(SalMediaDescription *md){
        }
 }
 
-const SalStreamDescription *sal_media_description_find_stream(const SalMediaDescription *md,
+SalStreamDescription *sal_media_description_find_stream(SalMediaDescription *md,
     SalMediaProto proto, SalStreamType type){
        int i;
        for(i=0;i<md->nstreams;++i){
-               const SalStreamDescription *ss=&md->streams[i];
+               SalStreamDescription *ss=&md->streams[i];
                if (ss->proto==proto && ss->type==type) return ss;
        }
        return NULL;
index 835232d0395a41fc04e4427b3123105dbfc9edec..ea1799ef70f4358858a89aca0f0e316aa5901c8a 100644 (file)
@@ -128,7 +128,7 @@ void sal_media_description_ref(SalMediaDescription *md);
 void sal_media_description_unref(SalMediaDescription *md);
 bool_t sal_media_description_empty(const SalMediaDescription *md);
 bool_t sal_media_description_has_dir(const SalMediaDescription *md, SalStreamDir dir);
-const SalStreamDescription *sal_media_description_find_stream(const SalMediaDescription *md,
+SalStreamDescription *sal_media_description_find_stream(SalMediaDescription *md,
     SalMediaProto proto, SalStreamType type);
 void sal_media_description_set_dir(SalMediaDescription *md, SalStreamDir stream_dir);
 
@@ -272,7 +272,7 @@ void *sal_op_get_user_pointer(const SalOp *op);
 /*Call API*/
 int sal_call_set_local_media_description(SalOp *h, SalMediaDescription *desc);
 int sal_call(SalOp *h, const char *from, const char *to);
-int sal_call_notify_ringing(SalOp *h);
+int sal_call_notify_ringing(SalOp *h, bool_t early_media);
 /*accept an incoming call or, during a call accept a reINVITE*/
 int sal_call_accept(SalOp*h);
 int sal_call_decline(SalOp *h, SalReason reason, const char *redirection /*optional*/);
index 9e08d10feb21726d797fa1f47a32e678079adc58..2ac94f089fa901e43ada62e4936046f9639c7019 100644 (file)
@@ -503,10 +503,31 @@ int sal_call(SalOp *h, const char *from, const char *to){
        return 0;
 }
 
-int sal_call_notify_ringing(SalOp *h){
-       eXosip_lock();
-       eXosip_call_send_answer(h->tid,180,NULL);
-       eXosip_unlock();
+int sal_call_notify_ringing(SalOp *h, bool_t early_media){
+       osip_message_t *msg;
+       int err;
+       
+       /*if early media send also 180 and 183 */
+       if (early_media && h->sdp_answer){
+               msg=NULL;
+               eXosip_lock();
+               err=eXosip_call_build_answer(h->tid,180,&msg);
+               if (msg){
+                       set_sdp(msg,h->sdp_answer);
+                       eXosip_call_send_answer(h->tid,180,msg);
+               }
+               msg=NULL;
+               err=eXosip_call_build_answer(h->tid,183,&msg);
+               if (msg){
+                       set_sdp(msg,h->sdp_answer);
+                       eXosip_call_send_answer(h->tid,183,msg);
+               }
+               eXosip_unlock();
+       }else{
+               eXosip_lock();
+               eXosip_call_send_answer(h->tid,180,NULL);
+               eXosip_unlock();
+       }
        return 0;
 }
 
index f2ddc59ed02f26ff828243fa400abae925b6f730..0d788c476c01c0894959fa2a85b43bbcac5dcb3a 160000 (submodule)
@@ -1 +1 @@
-Subproject commit f2ddc59ed02f26ff828243fa400abae925b6f730
+Subproject commit 0d788c476c01c0894959fa2a85b43bbcac5dcb3a