/*
linphone
-Copyright (C) 2010 Belledonne Communications SARL
+Copyright (C) 2010 Belledonne Communications SARL
(simon.morlat@linphone.org)
This program is free software; you can redistribute it and/or
LinphoneAddress *addr=linphone_address_new(me);
const char *username=linphone_address_get_username (addr);
SalMediaDescription *md=sal_media_description_new();
-
+
md->session_id=session_id;
md->session_ver=session_ver;
md->nstreams=1;
strncpy(md->addr,call->localip,sizeof(md->addr));
strncpy(md->username,username,sizeof(md->username));
md->bandwidth=linphone_core_get_download_bandwidth(lc);
-
+
/*set audio capabilities */
strncpy(md->streams[0].addr,call->localip,sizeof(md->streams[0].addr));
md->streams[0].port=call->audio_port;
pt=payload_type_clone(rtp_profile_get_payload_from_mime(&av_profile,"telephone-event"));
l=ms_list_append(l,pt);
md->streams[0].payloads=l;
-
+
if (call->params.has_video){
md->nstreams++;
if (port_offset==-1) return;
call->audio_port=linphone_core_get_audio_port(call->core)+port_offset;
call->video_port=linphone_core_get_video_port(call->core)+port_offset;
-
+
}
static void discover_mtu(LinphoneCore *lc, const char *remote){
sal_ping(call->ping_op,linphone_core_find_best_identity(lc,from,NULL),from_str);
ms_free(from_str);
}
-
+
linphone_address_clean(from);
linphone_core_get_local_ip(lc,linphone_address_get_domain(from),call->localip);
linphone_call_init_common(call, from, to);
static void linphone_call_set_terminated(LinphoneCall *call){
LinphoneCore *lc=call->core;
-
+
linphone_core_update_allocated_audio_bandwidth(lc);
call->owns_call_log=FALSE;
linphone_call_log_completed(call);
-
-
+
+
if (call == lc->current_call){
ms_message("Resetting the current call");
lc->current_call=NULL;
if (linphone_core_del_call(lc,call) != 0){
ms_error("Could not remove the call from the list !!!");
}
-
+
if (ms_list_size(lc->calls)==0)
linphone_core_notify_all_friends(lc,lc->presence_mode);
-
+
}
const char *linphone_call_state_to_string(LinphoneCallState cs){
if (cstate == LinphoneCallConnected) {
call->log->status=LinphoneCallSuccess;
}
-
+
if (lc->vtable.call_state_changed)
lc->vtable.call_state_changed(lc,call,cstate,message);
if (cstate==LinphoneCallReleased){
* executed yet.
* Pending transfers are executed when this call is being paused or closed,
* locally or by remote endpoint.
- * If the call is already paused while receiving the transfer request, the
+ * If the call is already paused while receiving the transfer request, the
* transfer immediately occurs.
**/
bool_t linphone_call_has_transfer_pending(const LinphoneCall *call){
return cp->real_early_media;
}
+/**
+ * Returns true if the call is part of the locally managed conference.
+**/
+bool_t linphone_call_params_local_conference_mode(const LinphoneCallParams *cp){
+ return cp->in_conference;
+}
+
/**
* Refine bandwidth settings for this call by setting a bandwidth limit for audio streams.
* As a consequence, codecs whose bitrates are not compatible with this limit won't be used.
LinphoneCore *lc=call->core;
SalMediaDescription *md=call->localdesc;
AudioStream *audiostream;
-
+
call->audiostream=audiostream=audio_stream_new(md->streams[0].port,linphone_core_ipv6_enabled(lc));
if (linphone_core_echo_limiter_enabled(lc)){
const char *type=lp_config_get_string(lc->config,"sound","el_type","mic");
int enabled=lp_config_get_int(lc->config,"sound","noisegate",0);
audio_stream_enable_noise_gate(audiostream,enabled);
}
-
+
if (lc->a_rtp)
rtp_session_set_transports(audiostream->session,lc->a_rtp,lc->a_rtcp);
}
}
-
-static void post_configure_audio_streams(LinphoneCall*call){
- AudioStream *st=call->audiostream;
- LinphoneCore *lc=call->core;
+void _post_configure_audio_stream(AudioStream *st, LinphoneCore *lc, bool_t muted){
float mic_gain=lp_config_get_float(lc->config,"sound","mic_gain",1);
float thres = 0;
float recv_gain;
float ng_thres=lp_config_get_float(lc->config,"sound","ng_thres",0.05);
float ng_floorgain=lp_config_get_float(lc->config,"sound","ng_floorgain",0);
int dc_removal=lp_config_get_int(lc->config,"sound","dc_removal",0);
-
- if (!call->audio_muted)
+
+ if (!muted)
audio_stream_set_mic_gain(st,mic_gain);
- else
+ else
audio_stream_set_mic_gain(st,0);
recv_gain = lc->sound_conf.soft_play_lev;
ms_filter_call_method(st->volrecv,MS_VOLUME_SET_NOISE_GATE_FLOORGAIN,&floorgain);
}
parametrize_equalizer(lc,st);
+}
+
+static void post_configure_audio_streams(LinphoneCall*call){
+ AudioStream *st=call->audiostream;
+ LinphoneCore *lc=call->core;
+ _post_configure_audio_stream(st,lc,call->audio_muted);
if (lc->vtable.dtmf_received!=NULL){
/* replace by our default action*/
audio_stream_play_received_dtmfs(call->audiostream,FALSE);
LinphoneCore *lc=call->core;
int up_ptime=0;
*used_pt=-1;
-
+
for(elem=desc->payloads;elem!=NULL;elem=elem->next){
PayloadType *pt=(PayloadType*)elem->data;
int number;
-
+
if ((pt->flags & PAYLOAD_TYPE_FLAG_CAN_SEND) && first) {
if (desc->type==SalAudio){
linphone_core_update_allocated_audio_bandwidth_in_call(call,pt);
remote_bw=get_video_bandwidth(remote_bw,call->audio_bw);
}
}
-
- if (desc->type==SalAudio){
+
+ if (desc->type==SalAudio){
bw=get_min_bandwidth(call->audio_bw,remote_bw);
}else bw=get_min_bandwidth(get_video_bandwidth(linphone_core_get_upload_bandwidth (lc),call->audio_bw),remote_bw);
if (bw>0) pt->normal_bitrate=bw*1000;
ms_filter_call_method(call->audiostream->soundread,MS_FILE_PLAYER_LOOP,&pause_time);
}
+#define LINPHONE_RTCP_SDES_TOOL "Linphone-" LINPHONE_VERSION
+
+static void linphone_call_start_audio_stream(LinphoneCall *call, const char *cname, bool_t muted, bool_t send_ringbacktone, bool_t use_arc){
+ LinphoneCore *lc=call->core;
+ int jitt_comp=lc->rtp_conf.audio_jitt_comp;
+ int used_pt=-1;
+ const SalStreamDescription *stream=sal_media_description_find_stream(call->resultdesc,
+ SalProtoRtpAvp,SalAudio);
+
+ if (stream && stream->dir!=SalStreamInactive && stream->port!=0){
+ MSSndCard *playcard=lc->sound_conf.lsd_card ?
+ lc->sound_conf.lsd_card : lc->sound_conf.play_sndcard;
+ MSSndCard *captcard=lc->sound_conf.capt_sndcard;
+ const char *playfile=lc->play_file;
+ const char *recfile=lc->rec_file;
+ call->audio_profile=make_profile(call,call->resultdesc,stream,&used_pt);
+ bool_t use_ec;
+
+ if (used_pt!=-1){
+ if (playcard==NULL) {
+ ms_warning("No card defined for playback !");
+ }
+ if (captcard==NULL) {
+ ms_warning("No card defined for capture !");
+ }
+ /*Replace soundcard filters by inactive file players or recorders
+ when placed in recvonly or sendonly mode*/
+ if (stream->port==0 || stream->dir==SalStreamRecvOnly){
+ captcard=NULL;
+ playfile=NULL;
+ }else if (stream->dir==SalStreamSendOnly){
+ playcard=NULL;
+ captcard=NULL;
+ recfile=NULL;
+ /*And we will eventually play "playfile" if set by the user*/
+ /*playfile=NULL;*/
+ }
+ if (send_ringbacktone){
+ captcard=NULL;
+ playfile=NULL;/* it is setup later*/
+ }
+ /*if playfile are supplied don't use soundcards*/
+ if (lc->use_files) {
+ captcard=NULL;
+ playcard=NULL;
+ }
+ if (call->params.in_conference){
+ /* first create the graph without soundcard resources*/
+ captcard=playcard=NULL;
+ }
+ use_ec=captcard==NULL ? FALSE : linphone_core_echo_cancellation_enabled(lc);
+
+ audio_stream_enable_adaptive_bitrate_control(call->audiostream,use_arc);
+ audio_stream_start_full(
+ call->audiostream,
+ call->audio_profile,
+ stream->addr[0]!='\0' ? stream->addr : call->resultdesc->addr,
+ stream->port,
+ stream->port+1,
+ used_pt,
+ jitt_comp,
+ playfile,
+ recfile,
+ playcard,
+ captcard,
+ use_ec
+ );
+ post_configure_audio_streams(call);
+ if (muted && !send_ringbacktone){
+ audio_stream_set_mic_gain(call->audiostream,0);
+ }
+ if (stream->dir==SalStreamSendOnly && playfile!=NULL){
+ int pause_time=500;
+ ms_filter_call_method(call->audiostream->soundread,MS_FILE_PLAYER_LOOP,&pause_time);
+ }
+ if (send_ringbacktone){
+ setup_ring_player(lc,call);
+ }
+ audio_stream_set_rtcp_information(call->audiostream, cname, LINPHONE_RTCP_SDES_TOOL);
+ if (call->params.in_conference){
+ /*transform the graph to connect it to the conference filter */
+ linphone_call_add_to_conf(call);
+ }
+ }else ms_warning("No audio stream accepted ?");
+ }
+}
+
+static void linphone_call_start_video_stream(LinphoneCall *call, const char *cname,bool_t all_inputs_muted){
+#ifdef VIDEO_ENABLED
+ LinphoneCore *lc=call->core;
+ int used_pt=-1;
+ const SalStreamDescription *vstream=sal_media_description_find_stream(call->resultdesc,
+ SalProtoRtpAvp,SalVideo);
+ /* shutdown preview */
+ if (lc->previewstream!=NULL) {
+ video_preview_stop(lc->previewstream);
+ lc->previewstream=NULL;
+ }
+ call->current_params.has_video=FALSE;
+ if (vstream && vstream->dir!=SalStreamInactive && vstream->port!=0) {
+ const char *addr=vstream->addr[0]!='\0' ? vstream->addr : call->resultdesc->addr;
+ call->video_profile=make_profile(call,call->resultdesc,vstream,&used_pt);
+ if (used_pt!=-1){
+ VideoStreamDir dir=VideoStreamSendRecv;
+ MSWebCam *cam=lc->video_conf.device;
+ bool_t is_inactive=FALSE;
+
+ call->current_params.has_video=TRUE;
+
+ video_stream_set_sent_video_size(call->videostream,linphone_core_get_preferred_video_size(lc));
+ video_stream_enable_self_view(call->videostream,lc->video_conf.selfview);
+ if (lc->video_window_id!=0)
+ video_stream_set_native_window_id(call->videostream,lc->video_window_id);
+ if (lc->preview_window_id!=0)
+ video_stream_set_native_preview_window_id (call->videostream,lc->preview_window_id);
+ video_stream_use_preview_video_window (call->videostream,lc->use_preview_window);
+
+ if (vstream->dir==SalStreamSendOnly && lc->video_conf.capture ){
+ cam=get_nowebcam_device();
+ dir=VideoStreamSendOnly;
+ }else if (vstream->dir==SalStreamRecvOnly && lc->video_conf.display ){
+ dir=VideoStreamRecvOnly;
+ }else if (vstream->dir==SalStreamSendRecv){
+ if (lc->video_conf.display && lc->video_conf.capture)
+ dir=VideoStreamSendRecv;
+ else if (lc->video_conf.display)
+ dir=VideoStreamRecvOnly;
+ else
+ dir=VideoStreamSendOnly;
+ }else{
+ ms_warning("video stream is inactive.");
+ /*either inactive or incompatible with local capabilities*/
+ is_inactive=TRUE;
+ }
+ if (call->camera_active==FALSE || all_inputs_muted){
+ cam=get_nowebcam_device();
+ }
+ if (!is_inactive){
+ video_stream_set_direction (call->videostream, dir);
+ ms_message("%s lc rotation:%d\n", __FUNCTION__, lc->device_rotation);
+ video_stream_set_device_rotation(call->videostream, lc->device_rotation);
+ video_stream_start(call->videostream,
+ call->video_profile, addr, vstream->port,
+ vstream->port+1,
+ used_pt, lc->rtp_conf.audio_jitt_comp, cam);
+ video_stream_set_rtcp_information(call->videostream, cname,LINPHONE_RTCP_SDES_TOOL);
+ }
+ }else ms_warning("No video stream accepted.");
+ }else{
+ ms_warning("No valid video stream defined.");
+ }
+#endif
+}
void linphone_call_start_media_streams(LinphoneCall *call, bool_t all_inputs_muted, bool_t send_ringbacktone){
LinphoneCore *lc=call->core;
LinphoneAddress *me=linphone_core_get_primary_contact_parsed(lc);
- const char *tool="linphone-" LINPHONE_VERSION;
char *cname;
- int used_pt=-1;
+ bool_t use_arc;
#ifdef VIDEO_ENABLED
const SalStreamDescription *vstream=sal_media_description_find_stream(call->resultdesc,
SalProtoRtpAvp,SalVideo);
#endif
- bool_t use_arc=linphone_core_adaptive_rate_control_enabled(lc);
-
+
if(call->audiostream == NULL)
{
ms_fatal("start_media_stream() called without prior init !");
return;
}
call->current_params = call->params;
- /* adjust rtp jitter compensation. It must be at least the latency of the sound card */
- int jitt_comp=MAX(lc->sound_conf.latency,lc->rtp_conf.audio_jitt_comp);
-
if (call->media_start_time==0) call->media_start_time=time(NULL);
-
cname=linphone_address_as_string_uri_only(me);
- {
- const SalStreamDescription *stream=sal_media_description_find_stream(call->resultdesc,
- SalProtoRtpAvp,SalAudio);
- if (stream && stream->dir!=SalStreamInactive && stream->port!=0){
- MSSndCard *playcard=lc->sound_conf.lsd_card ?
- lc->sound_conf.lsd_card : lc->sound_conf.play_sndcard;
- MSSndCard *captcard=lc->sound_conf.capt_sndcard;
- const char *playfile=lc->play_file;
- const char *recfile=lc->rec_file;
- call->audio_profile=make_profile(call,call->resultdesc,stream,&used_pt);
- bool_t use_ec,use_arc_audio=use_arc;
-
- if (used_pt!=-1){
- if (playcard==NULL) {
- ms_warning("No card defined for playback !");
- }
- if (captcard==NULL) {
- ms_warning("No card defined for capture !");
- }
- /*Replace soundcard filters by inactive file players or recorders
- when placed in recvonly or sendonly mode*/
- if (stream->port==0 || stream->dir==SalStreamRecvOnly){
- captcard=NULL;
- playfile=NULL;
- }else if (stream->dir==SalStreamSendOnly){
- playcard=NULL;
- captcard=NULL;
- recfile=NULL;
- /*And we will eventually play "playfile" if set by the user*/
- /*playfile=NULL;*/
- }
- if (send_ringbacktone){
- captcard=NULL;
- playfile=NULL;/* it is setup later*/
- }
- /*if playfile are supplied don't use soundcards*/
- if (lc->use_files) {
- captcard=NULL;
- playcard=NULL;
- }
- use_ec=captcard==NULL ? FALSE : linphone_core_echo_cancellation_enabled(lc);
-#if defined(VIDEO_ENABLED)
- if (vstream && vstream->dir!=SalStreamInactive && vstream->payloads!=NULL){
- /*when video is used, do not make adaptive rate control on audio, it is stupid.*/
- use_arc_audio=FALSE;
- #if defined(ANDROID)
- /*On android we have to disable the echo canceller to preserve CPU for video codecs */
- use_ec=FALSE;
- #endif
- }
-#endif
- audio_stream_enable_adaptive_bitrate_control(call->audiostream,use_arc_audio);
- audio_stream_start_full(
- call->audiostream,
- call->audio_profile,
- stream->addr[0]!='\0' ? stream->addr : call->resultdesc->addr,
- stream->port,
- stream->port+1,
- used_pt,
- jitt_comp,
- playfile,
- recfile,
- playcard,
- captcard,
- use_ec
- );
- post_configure_audio_streams(call);
- if (all_inputs_muted && !send_ringbacktone){
- audio_stream_set_mic_gain(call->audiostream,0);
- }
- if (stream->dir==SalStreamSendOnly && playfile!=NULL){
- int pause_time=500;
- ms_filter_call_method(call->audiostream->soundread,MS_FILE_PLAYER_LOOP,&pause_time);
- }
- if (send_ringbacktone){
- setup_ring_player(lc,call);
- }
- audio_stream_set_rtcp_information(call->audiostream, cname, tool);
- }else ms_warning("No audio stream accepted ?");
- }
- }
-#ifdef VIDEO_ENABLED
- {
- used_pt=-1;
- /* shutdown preview */
- if (lc->previewstream!=NULL) {
- video_preview_stop(lc->previewstream);
- lc->previewstream=NULL;
- }
- call->current_params.has_video=FALSE;
- if (vstream && vstream->dir!=SalStreamInactive && vstream->port!=0) {
- const char *addr=vstream->addr[0]!='\0' ? vstream->addr : call->resultdesc->addr;
- call->video_profile=make_profile(call,call->resultdesc,vstream,&used_pt);
- if (used_pt!=-1){
- VideoStreamDir dir=VideoStreamSendRecv;
- MSWebCam *cam=lc->video_conf.device;
- bool_t is_inactive=FALSE;
-
- call->current_params.has_video=TRUE;
-
- video_stream_set_sent_video_size(call->videostream,linphone_core_get_preferred_video_size(lc));
- video_stream_enable_self_view(call->videostream,lc->video_conf.selfview);
- if (lc->video_window_id!=0)
- video_stream_set_native_window_id(call->videostream,lc->video_window_id);
- if (lc->preview_window_id!=0)
- video_stream_set_native_preview_window_id (call->videostream,lc->preview_window_id);
- video_stream_use_preview_video_window (call->videostream,lc->use_preview_window);
-
- if (vstream->dir==SalStreamSendOnly && lc->video_conf.capture ){
- cam=get_nowebcam_device();
- dir=VideoStreamSendOnly;
- }else if (vstream->dir==SalStreamRecvOnly && lc->video_conf.display ){
- dir=VideoStreamRecvOnly;
- }else if (vstream->dir==SalStreamSendRecv){
- if (lc->video_conf.display && lc->video_conf.capture)
- dir=VideoStreamSendRecv;
- else if (lc->video_conf.display)
- dir=VideoStreamRecvOnly;
- else
- dir=VideoStreamSendOnly;
- }else{
- ms_warning("video stream is inactive.");
- /*either inactive or incompatible with local capabilities*/
- is_inactive=TRUE;
- }
- if (call->camera_active==FALSE || all_inputs_muted){
- cam=get_nowebcam_device();
- }
- if (!is_inactive){
- video_stream_set_direction (call->videostream, dir);
-ms_message("%s lc rotation:%d\n", __FUNCTION__, lc->device_rotation);
- video_stream_set_device_rotation(call->videostream, lc->device_rotation);
- video_stream_start(call->videostream,
- call->video_profile, addr, vstream->port,
- vstream->port+1,
- used_pt, jitt_comp, cam);
- video_stream_set_rtcp_information(call->videostream, cname,tool);
- }
- }else ms_warning("No video stream accepted.");
- }else{
- ms_warning("No valid video stream defined.");
- }
+#if defined(VIDEO_ENABLED)
+ if (vstream && vstream->dir!=SalStreamInactive && vstream->payloads!=NULL){
+ /*when video is used, do not make adaptive rate control on audio, it is stupid.*/
+ use_arc=FALSE;
}
#endif
+ linphone_call_start_audio_stream(call,cname,all_inputs_muted,send_ringbacktone,use_arc);
+ linphone_call_start_video_stream(call,cname,all_inputs_muted);
+
call->all_muted=all_inputs_muted;
call->playing_ringbacktone=send_ringbacktone;
call->up_bw=linphone_core_get_upload_bandwidth(lc);
-
+
if (ortp_zrtp_available()) {
OrtpZrtpParams params;
params.zid=get_hexa_zrtp_identifier(lc);
}
}
linphone_call_log_fill_stats (call->log,call->audiostream);
+ if (call->endpoint){
+ linphone_call_remove_from_conf(call);
+ }
audio_stream_stop(call->audiostream);
call->audiostream=NULL;
}
call->videostream=NULL;
}
ms_event_queue_skip(call->core->msevq);
-
+
#endif
if (call->audio_profile){
rtp_profile_clear_all(call->audio_profile);
/**
* @addtogroup call_misc
* @{
-**/
+**/
/**
* Returns the measured sound volume played locally (received from remote)
- * It is expressed in dbm0.
+ * It is expressed in dbm0.
**/
float linphone_call_get_play_volume(LinphoneCall *call){
AudioStream *st=call->audiostream;
float vol=0;
ms_filter_call_method(st->volsend,MS_VOLUME_GET,&vol);
return vol;
-
+
}
return LINPHONE_VOLUME_DB_LOWEST;
}
/**
* Returns the measured sound volume recorded locally (sent to remote)
- * It is expressed in dbm0.
+ * It is expressed in dbm0.
**/
float linphone_call_get_record_volume(LinphoneCall *call){
AudioStream *st=call->audiostream;
float vol=0;
ms_filter_call_method(st->volrecv,MS_VOLUME_GET,&vol);
return vol;
-
+
}
return LINPHONE_VOLUME_DB_LOWEST;
}
* 1-2 = very poor quality <br>
* 0-1 = can't be worse, mostly unusable <br>
*
- * @returns The function returns -1 if no quality measurement is available, for example if no
+ * @returns The function returns -1 if no quality measurement is available, for example if no
* active audio stream exist. Otherwise it returns the quality rating.
**/
float linphone_call_get_current_quality(LinphoneCall *call){
{
snprintf(temp,sizeof(temp),"Remote end %s seems to have disconnected, the call is going to be closed.",from);
free(from);
- }
+ }
else
{
snprintf(temp,sizeof(temp),"Remote end seems to have disconnected, the call is going to be closed.");
void linphone_call_background_tasks(LinphoneCall *call, bool_t one_second_elapsed){
int disconnect_timeout = linphone_core_get_nortp_timeout(call->core);
bool_t disconnected=FALSE;
-
+
if (call->state==LinphoneCallStreamsRunning && one_second_elapsed){
RtpSession *as=NULL,*vs=NULL;
float audio_load=0, video_load=0;
}
}
}
- if (one_second_elapsed && call->audiostream!=NULL && disconnect_timeout>0 )
+ if (call->state==LinphoneCallStreamsRunning && one_second_elapsed && call->audiostream!=NULL && disconnect_timeout>0 )
disconnected=!audio_stream_alive(call->audiostream,disconnect_timeout);
if (disconnected)
linphone_core_disconnected(call->core,call);
void linphone_call_log_completed(LinphoneCall *call){
LinphoneCore *lc=call->core;
-
+
call->log->duration=time(NULL)-call->start_time;
-
+
if (call->log->status==LinphoneCallMissed){
char *info;
lc->missed_calls++;
}
call_logs_write_to_config_file(lc);
}
+
+