Commit c192381c authored by Simon Morlat's avatar Simon Morlat

implement sending of early media

parent 7e2ea826
......@@ -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);
......
......@@ -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);
......
......@@ -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)
......
......@@ -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);
......
......@@ -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;
......
......@@ -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);
......
......@@ -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;
......
......@@ -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*/);
......
......@@ -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;
}
......
mediastreamer2 @ 0d788c47
Subproject commit f2ddc59ed02f26ff828243fa400abae925b6f730
Subproject commit 0d788c476c01c0894959fa2a85b43bbcac5dcb3a
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