/* this callback is called when an incoming re-INVITE modifies the session*/ static void call_updating(SalOp *op){ LinphoneCore *lc=(LinphoneCore *)sal_get_user_pointer(sal_op_get_sal(op)); LinphoneCall *call=(LinphoneCall*)sal_op_get_user_pointer(op); LinphoneCallState prevstate=LinphoneCallIdle; SalMediaDescription *md; md=sal_call_get_final_media_description(op); if (md && !sal_media_description_empty(md)) { if (sal_media_description_has_dir(call->localdesc,SalStreamSendRecv)){ ms_message("Our local status is SalStreamSendRecv"); if (sal_media_description_has_dir (md,SalStreamRecvOnly) || sal_media_description_has_dir(md,SalStreamInactive)){ /* we are being paused */ if(lc->vtable.display_status) lc->vtable.display_status(lc,_("We are being paused...")); linphone_call_set_state (call,LinphoneCallPausedByRemote,"Call paused by remote"); }else if (!sal_media_description_has_dir(call->resultdesc,SalStreamSendRecv) && sal_media_description_has_dir(md,SalStreamSendRecv)){ if(lc->vtable.display_status) lc->vtable.display_status(lc,_("We have been resumed...")); linphone_call_set_state (call,LinphoneCallStreamsRunning,"Connected (streams running)"); lc->current_call=call; }else{ prevstate=call->state; linphone_call_set_state(call, LinphoneCallUpdatedByRemote,"Call updated by remote"); } } /*accept the modification (sends a 200Ok)*/ sal_call_accept(op); linphone_core_update_streams (lc,call,md); if (prevstate!=LinphoneCallIdle){ linphone_call_set_state (call,prevstate,"Connected (streams running)"); } } }
static void call_ack(SalOp *op){ LinphoneCore *lc=(LinphoneCore *)sal_get_user_pointer(sal_op_get_sal(op)); LinphoneCall *call=(LinphoneCall*)sal_op_get_user_pointer(op); if (call==NULL){ ms_warning("No call to be ACK'd"); return ; } if (call->media_pending){ SalMediaDescription *md=sal_call_get_final_media_description(op); if (md && !sal_media_description_empty(md)){ if (call->state==LinphoneCallStreamsRunning){ /*media was running before, the remote as acceted a call modification (that is a reinvite made by us. We must notify the application this reinvite was accepted*/ linphone_call_set_state(call, LinphoneCallUpdated, "Call updated"); } linphone_core_update_streams (lc,call,md); linphone_call_set_state (call,LinphoneCallStreamsRunning,"Connected (streams running)"); }else{ /*send a bye*/ ms_error("Incompatible SDP response received in ACK, need to abort the call"); linphone_core_abort_call(lc,call,"No codec intersection"); return; } } }
static void call_paused_by_remote(LinphoneCore *lc, LinphoneCall *call){ call_accept_update(lc,call); /* we are being paused */ if(lc->vtable.display_status) lc->vtable.display_status(lc,_("We are paused by other party.")); linphone_call_set_state (call,LinphoneCallPausedByRemote,"Call paused by remote"); }
static void refer_received(Sal *sal, SalOp *op, const char *referto){ LinphoneCore *lc=(LinphoneCore *)sal_get_user_pointer(sal); LinphoneCall *call=(LinphoneCall*)sal_op_get_user_pointer(op); if (call){ if (call->refer_to!=NULL){ ms_free(call->refer_to); } call->refer_to=ms_strdup(referto); call->refer_pending=TRUE; linphone_call_set_state(call,LinphoneCallRefered,"Refered"); if (lc->vtable.display_status){ char *msg=ms_strdup_printf(_("We are transferred to %s"),referto); lc->vtable.display_status(lc,msg); ms_free(msg); } if (call->state!=LinphoneCallPaused){ ms_message("Automatically pausing current call to accept transfer."); linphone_core_pause_call(lc,call); } linphone_core_start_refered_call(lc,call); sal_call_accept_refer(op); }else if (lc->vtable.refer_received){ lc->vtable.refer_received(lc,referto); sal_call_accept_refer(op); } }
static void call_ringing(SalOp *h){ LinphoneCore *lc=(LinphoneCore *)sal_get_user_pointer(sal_op_get_sal(h)); LinphoneCall *call=(LinphoneCall*)sal_op_get_user_pointer(h); SalMediaDescription *md; if (call==NULL) return; if (lc->vtable.display_status) lc->vtable.display_status(lc,_("Remote ringing.")); md=sal_call_get_final_media_description(h); if (md==NULL){ if (lc->ringstream && lc->dmfs_playing_start_time!=0){ ring_stop(lc->ringstream); lc->ringstream=NULL; lc->dmfs_playing_start_time=0; } if (lc->ringstream!=NULL) return; /*already ringing !*/ if (lc->sound_conf.play_sndcard!=NULL){ MSSndCard *ringcard=lc->sound_conf.lsd_card ? lc->sound_conf.lsd_card : lc->sound_conf.play_sndcard; lc->ringstream=ring_start(lc->sound_conf.remote_ring,2000,ringcard); } ms_message("Remote ringing..."); if (lc->vtable.display_status) lc->vtable.display_status(lc,_("Remote ringing...")); linphone_call_set_state(call,LinphoneCallOutgoingRinging,"Remote ringing"); }else{ /*accept early media */ if (call->audiostream && call->audiostream->ticker!=NULL){ /*streams already started */ ms_message("Early media already started."); return; } if (lc->vtable.show) lc->vtable.show(lc); if (lc->vtable.display_status) lc->vtable.display_status(lc,_("Early media.")); linphone_call_set_state(call,LinphoneCallOutgoingEarlyMedia,"Early media"); if (lc->ringstream!=NULL){ ring_stop(lc->ringstream); lc->ringstream=NULL; } ms_message("Doing early media..."); linphone_core_update_streams (lc,call,md); } }
static void call_ringing(SalOp *h){ LinphoneCore *lc=(LinphoneCore *)sal_get_user_pointer(sal_op_get_sal(h)); LinphoneCall *call=(LinphoneCall*)sal_op_get_user_pointer(h); SalMediaDescription *md; if (call==NULL) return; /*set privacy*/ call->current_params.privacy=(LinphonePrivacyMask)sal_op_get_privacy(call->op); if (lc->vtable.display_status) lc->vtable.display_status(lc,_("Remote ringing.")); md=sal_call_get_final_media_description(h); if (md==NULL){ linphone_core_stop_dtmf_stream(lc); if (lc->ringstream!=NULL) return;/*already ringing !*/ if (lc->sound_conf.play_sndcard!=NULL){ MSSndCard *ringcard=lc->sound_conf.lsd_card ? lc->sound_conf.lsd_card : lc->sound_conf.play_sndcard; if (call->localdesc->streams[0].max_rate>0) ms_snd_card_set_preferred_sample_rate(ringcard, call->localdesc->streams[0].max_rate); /*we release sound before playing ringback tone*/ if (call->audiostream) audio_stream_unprepare_sound(call->audiostream); lc->ringstream=ring_start(lc->sound_conf.remote_ring,2000,ringcard); } ms_message("Remote ringing..."); if (lc->vtable.display_status) lc->vtable.display_status(lc,_("Remote ringing...")); linphone_call_set_state(call,LinphoneCallOutgoingRinging,"Remote ringing"); }else{ /*accept early media */ if (call->audiostream && audio_stream_started(call->audiostream)){ /*streams already started */ ms_message("Early media already started."); return; } if (lc->vtable.show) lc->vtable.show(lc); if (lc->vtable.display_status) lc->vtable.display_status(lc,_("Early media.")); linphone_call_set_state(call,LinphoneCallOutgoingEarlyMedia,"Early media"); linphone_core_stop_ringing(lc); ms_message("Doing early media..."); linphone_core_update_streams(lc,call,md); } }
static void call_updated_by_remote(LinphoneCore *lc, LinphoneCall *call){ /*first check if media capabilities are compatible*/ SalMediaDescription* md; linphone_call_make_local_media_description(lc,call); sal_call_set_local_media_description(call->op,call->localdesc); md=sal_call_get_final_media_description(call->op); if (md && (sal_media_description_empty(md) || linphone_core_incompatible_security(lc,md))){ sal_call_decline(call->op,SalReasonNotAcceptable,NULL); return; } if(lc->vtable.display_status) lc->vtable.display_status(lc,_("Call is updated by remote.")); call->defer_update=FALSE; linphone_call_set_state(call, LinphoneCallUpdatedByRemote,"Call updated by remote"); if (call->defer_update==FALSE){ linphone_core_accept_call_update(lc,call,NULL); } }
static void call_ack(SalOp *op){ LinphoneCore *lc=(LinphoneCore *)sal_get_user_pointer(sal_op_get_sal(op)); LinphoneCall *call=(LinphoneCall*)sal_op_get_user_pointer(op); if (call==NULL){ ms_warning("No call to be ACK'd"); return ; } if (call->expect_media_in_ack){ SalMediaDescription *md=sal_call_get_final_media_description(op); if (md && !sal_media_description_empty(md)){ linphone_core_update_streams(lc,call,md); linphone_call_set_state (call,LinphoneCallStreamsRunning,"Connected (streams running)"); }else{ /*send a bye*/ ms_error("Incompatible SDP response received in ACK, need to abort the call"); linphone_core_abort_call(lc,call,"No codec intersection"); return; } } }
static void call_terminated(SalOp *op, const char *from){ LinphoneCore *lc=(LinphoneCore *)sal_get_user_pointer(sal_op_get_sal(op)); LinphoneCall *call=(LinphoneCall*)sal_op_get_user_pointer(op); if (call==NULL) return; switch(linphone_call_get_state(call)){ case LinphoneCallEnd: case LinphoneCallError: ms_warning("call_terminated: ignoring."); return; break; case LinphoneCallIncomingReceived: case LinphoneCallIncomingEarlyMedia: call->reason=LinphoneReasonNotAnswered; break; default: break; } ms_message("Current call terminated..."); if (call->refer_pending){ linphone_core_start_refered_call(lc,call,NULL); } //we stop the call only if we have this current call or if we are in call if (lc->ringstream!=NULL && ( (ms_list_size(lc->calls) == 1) || linphone_core_in_call(lc) )) { linphone_core_stop_ringing(lc); } linphone_call_stop_media_streams(call); if (lc->vtable.show!=NULL) lc->vtable.show(lc); if (lc->vtable.display_status!=NULL) lc->vtable.display_status(lc,_("Call terminated.")); #ifdef BUILD_UPNP linphone_call_delete_upnp_session(call); #endif //BUILD_UPNP linphone_call_set_state(call, LinphoneCallEnd,"Call ended"); }
static void call_terminated(SalOp *op, const char *from){ LinphoneCore *lc=(LinphoneCore *)sal_get_user_pointer(sal_op_get_sal(op)); LinphoneCall *call=(LinphoneCall*)sal_op_get_user_pointer(op); if (call==NULL) return; if (linphone_call_get_state(call)==LinphoneCallEnd || linphone_call_get_state(call)==LinphoneCallError){ ms_warning("call_terminated: ignoring."); return; } ms_message("Current call terminated..."); //we stop the call only if we have this current call or if we are in call if (lc->ringstream!=NULL && ( (ms_list_size(lc->calls) == 1) || linphone_core_in_call(lc) )) { ring_stop(lc->ringstream); lc->ringstream=NULL; } linphone_call_stop_media_streams(call); if (lc->vtable.show!=NULL) lc->vtable.show(lc); if (lc->vtable.display_status!=NULL) lc->vtable.display_status(lc,_("Call terminated.")); linphone_call_set_state(call, LinphoneCallEnd,"Call ended"); }
static void call_resumed(LinphoneCore *lc, LinphoneCall *call){ call_accept_update(lc,call); if(lc->vtable.display_status) lc->vtable.display_status(lc,_("We have been resumed.")); linphone_call_set_state(call,LinphoneCallStreamsRunning,"Connected (streams running)"); }
/* * could be reach : * - when the call is accepted * - when a request is accepted (pause, resume) */ static void call_accepted(SalOp *op){ LinphoneCore *lc=(LinphoneCore *)sal_get_user_pointer(sal_op_get_sal(op)); LinphoneCall *call=(LinphoneCall*)sal_op_get_user_pointer(op); SalMediaDescription *md; if (call==NULL){ ms_warning("No call to accept."); return ; } /*set privacy*/ call->current_params.privacy=(LinphonePrivacyMask)sal_op_get_privacy(call->op); /* Handle remote ICE attributes if any. */ if (call->ice_session != NULL) { linphone_core_update_ice_from_remote_media_description(call, sal_call_get_remote_media_description(op)); } #ifdef BUILD_UPNP if (call->upnp_session != NULL) { linphone_core_update_upnp_from_remote_media_description(call, sal_call_get_remote_media_description(op)); } #endif //BUILD_UPNP md=sal_call_get_final_media_description(op); if (md) /*make sure re-invite will not propose video again*/ call->params.has_video &= linphone_core_media_description_contains_video_stream(md); if (call->state==LinphoneCallOutgoingProgress || call->state==LinphoneCallOutgoingRinging || call->state==LinphoneCallOutgoingEarlyMedia){ linphone_call_set_state(call,LinphoneCallConnected,"Connected"); if (call->referer) linphone_core_notify_refer_state(lc,call->referer,call); } if (md && !sal_media_description_empty(md) && !linphone_core_incompatible_security(lc,md)){ linphone_call_update_remote_session_id_and_ver(call); if (sal_media_description_has_dir(md,SalStreamSendOnly) || sal_media_description_has_dir(md,SalStreamInactive)){ if (lc->vtable.display_status){ char *tmp=linphone_call_get_remote_address_as_string (call); char *msg=ms_strdup_printf(_("Call with %s is paused."),tmp); lc->vtable.display_status(lc,msg); ms_free(tmp); ms_free(msg); } linphone_core_update_streams (lc,call,md); linphone_call_set_state(call,LinphoneCallPaused,"Call paused"); if (call->refer_pending) linphone_core_start_refered_call(lc,call,NULL); }else if (sal_media_description_has_dir(md,SalStreamRecvOnly)){ /*we are put on hold when the call is initially accepted */ if (lc->vtable.display_status){ char *tmp=linphone_call_get_remote_address_as_string (call); char *msg=ms_strdup_printf(_("Call answered by %s - on hold."),tmp); lc->vtable.display_status(lc,msg); ms_free(tmp); ms_free(msg); } linphone_core_update_streams (lc,call,md); linphone_call_set_state(call,LinphoneCallPausedByRemote,"Call paused by remote"); }else{ if (call->state!=LinphoneCallUpdating){ if (call->state==LinphoneCallResuming){ if (lc->vtable.display_status){ lc->vtable.display_status(lc,_("Call resumed.")); } }else{ if (lc->vtable.display_status){ char *tmp=linphone_call_get_remote_address_as_string (call); char *msg=ms_strdup_printf(_("Call answered by %s."),tmp); lc->vtable.display_status(lc,msg); ms_free(tmp); ms_free(msg); } } } linphone_core_update_streams(lc,call,md); /*also reflect the change if the "wished" params, in order to avoid to propose SAVP or video again * further in the call, for example during pause,resume, conferencing reINVITEs*/ linphone_call_fix_call_parameters(call); if (!call->current_params.in_conference) lc->current_call=call; linphone_call_set_state(call, LinphoneCallStreamsRunning, "Streams running"); } }else{ /*send a bye*/ ms_error("Incompatible SDP offer received in 200Ok, need to abort the call"); linphone_core_abort_call(lc,call,_("Incompatible, check codecs or security settings...")); } }
static void call_failure(SalOp *op, SalError error, SalReason sr, const char *details, int code){ LinphoneCore *lc=(LinphoneCore *)sal_get_user_pointer(sal_op_get_sal(op)); char *msg486=_("User is busy."); char *msg480=_("User is temporarily unavailable."); /*char *retrymsg=_("%s. Retry after %i minute(s).");*/ char *msg600=_("User does not want to be disturbed."); char *msg603=_("Call declined."); const char *msg=details; LinphoneCall *call=(LinphoneCall*)sal_op_get_user_pointer(op); if (call==NULL){ ms_warning("Call faillure reported on already cleaned call ?"); return ; } if (lc->vtable.show) lc->vtable.show(lc); if (error==SalErrorNoResponse){ msg=_("No response."); if (lc->vtable.display_status) lc->vtable.display_status(lc,msg); }else if (error==SalErrorProtocol){ msg=details ? details : _("Protocol error."); if (lc->vtable.display_status) lc->vtable.display_status(lc, msg); }else if (error==SalErrorFailure){ switch(sr){ case SalReasonDeclined: msg=msg603; if (lc->vtable.display_status) lc->vtable.display_status(lc,msg603); break; case SalReasonBusy: msg=msg486; if (lc->vtable.display_status) lc->vtable.display_status(lc,msg486); break; case SalReasonRedirect: msg=_("Redirected"); if (lc->vtable.display_status) lc->vtable.display_status(lc,msg); break; case SalReasonTemporarilyUnavailable: msg=msg480; if (lc->vtable.display_status) lc->vtable.display_status(lc,msg480); break; case SalReasonNotFound: msg=_("Not found"); if (lc->vtable.display_status) lc->vtable.display_status(lc,msg); break; case SalReasonDoNotDisturb: msg=msg600; if (lc->vtable.display_status) lc->vtable.display_status(lc,msg600); break; case SalReasonMedia: msg=_("No common codecs"); if (lc->vtable.display_status) lc->vtable.display_status(lc,msg); break; default: if (lc->vtable.display_status) lc->vtable.display_status(lc,_("Call failed.")); } } if (lc->ringstream!=NULL) { ring_stop(lc->ringstream); lc->ringstream=NULL; } linphone_call_stop_media_streams (call); if (sr!=SalReasonDeclined) linphone_call_set_state(call,LinphoneCallError,msg); else{ call->reason=LinphoneReasonDeclined; linphone_call_set_state(call,LinphoneCallEnd,"Call declined."); } }
/* * could be reach : * - when the call is accepted * - when a request is accepted (pause, resume) */ static void call_accepted(SalOp *op){ LinphoneCore *lc=(LinphoneCore *)sal_get_user_pointer(sal_op_get_sal(op)); LinphoneCall *call=(LinphoneCall*)sal_op_get_user_pointer(op); SalMediaDescription *md; if (call==NULL){ ms_warning("No call to accept."); return ; } md=sal_call_get_final_media_description(op); if (call->state==LinphoneCallOutgoingProgress || call->state==LinphoneCallOutgoingRinging || call->state==LinphoneCallOutgoingEarlyMedia){ linphone_call_set_state(call,LinphoneCallConnected,"Connected"); } if (md && !sal_media_description_empty(md)){ if (sal_media_description_has_dir(md,SalStreamSendOnly) || sal_media_description_has_dir(md,SalStreamInactive)){ if (lc->vtable.display_status){ char *tmp=linphone_call_get_remote_address_as_string (call); char *msg=ms_strdup_printf(_("Call with %s is paused."),tmp); lc->vtable.display_status(lc,msg); ms_free(tmp); ms_free(msg); } linphone_core_update_streams (lc,call,md); linphone_call_set_state(call,LinphoneCallPaused,"Call paused"); }else if (sal_media_description_has_dir(md,SalStreamRecvOnly)){ /*we are put on hold when the call is initially accepted */ if (lc->vtable.display_status){ char *tmp=linphone_call_get_remote_address_as_string (call); char *msg=ms_strdup_printf(_("Call answered by %s - on hold."),tmp); lc->vtable.display_status(lc,msg); ms_free(tmp); ms_free(msg); } linphone_core_update_streams (lc,call,md); linphone_call_set_state(call,LinphoneCallPausedByRemote,"Call paused by remote"); }else{ if (call->state==LinphoneCallStreamsRunning){ /*media was running before, the remote as acceted a call modification (that is a reinvite made by us. We must notify the application this reinvite was accepted*/ linphone_call_set_state(call, LinphoneCallUpdated, "Call updated"); }else{ if (call->state==LinphoneCallResuming){ if (lc->vtable.display_status){ lc->vtable.display_status(lc,_("Call resumed.")); } }else{ if (lc->vtable.display_status){ char *tmp=linphone_call_get_remote_address_as_string (call); char *msg=ms_strdup_printf(_("Call answered by %s."),tmp); lc->vtable.display_status(lc,msg); ms_free(tmp); ms_free(msg); } } } linphone_core_update_streams (lc,call,md); linphone_call_set_state(call, LinphoneCallStreamsRunning, "Streams running"); lc->current_call=call; } }else{ /*send a bye*/ ms_error("Incompatible SDP offer received in 200Ok, need to abort the call"); linphone_core_abort_call(lc,call,"No codec intersection"); } }
static void call_failure(SalOp *op, SalError error, SalReason sr, const char *details, int code){ LinphoneCore *lc=(LinphoneCore *)sal_get_user_pointer(sal_op_get_sal(op)); char *msg486=_("User is busy."); char *msg480=_("User is temporarily unavailable."); /*char *retrymsg=_("%s. Retry after %i minute(s).");*/ char *msg600=_("User does not want to be disturbed."); char *msg603=_("Call declined."); const char *msg=details; LinphoneCall *call=(LinphoneCall*)sal_op_get_user_pointer(op); LinphoneCall *referer=call->referer; if (call==NULL){ ms_warning("Call faillure reported on already terminated call."); return ; } if (lc->vtable.show) lc->vtable.show(lc); if (error==SalErrorNoResponse){ msg=_("No response."); if (lc->vtable.display_status) lc->vtable.display_status(lc,msg); }else if (error==SalErrorProtocol){ msg=details ? details : _("Protocol error."); if (lc->vtable.display_status) lc->vtable.display_status(lc, msg); }else if (error==SalErrorFailure){ switch(sr){ case SalReasonDeclined: msg=msg603; if (lc->vtable.display_status) lc->vtable.display_status(lc,msg603); break; case SalReasonBusy: msg=msg486; if (lc->vtable.display_status) lc->vtable.display_status(lc,msg486); break; case SalReasonRedirect: { ms_error("case SalReasonRedirect"); linphone_call_stop_media_streams(call); if ( call->state==LinphoneCallOutgoingInit || call->state==LinphoneCallOutgoingProgress || call->state==LinphoneCallOutgoingRinging /*push case*/ || call->state==LinphoneCallOutgoingEarlyMedia){ LinphoneAddress* redirection_to = (LinphoneAddress*)sal_op_get_remote_contact_address(call->op); if( redirection_to ){ char* url = linphone_address_as_string(redirection_to); ms_error("Redirecting call [%p] to %s",call, url); ms_free(url); linphone_call_create_op(call); linphone_core_start_invite(lc, call, redirection_to); return; } } msg=_("Redirected"); if (lc->vtable.display_status) lc->vtable.display_status(lc,msg); } break; case SalReasonTemporarilyUnavailable: msg=msg480; if (lc->vtable.display_status) lc->vtable.display_status(lc,msg480); break; case SalReasonNotFound: if (lc->vtable.display_status) lc->vtable.display_status(lc,msg); break; case SalReasonDoNotDisturb: msg=msg600; if (lc->vtable.display_status) lc->vtable.display_status(lc,msg600); break; case SalReasonUnsupportedContent: /*<this is for compatibility: linphone sent 415 because of SDP offer answer failure*/ case SalReasonNotAcceptable: //media_encryption_mandatory if (call->params.media_encryption == LinphoneMediaEncryptionSRTP && !linphone_core_is_media_encryption_mandatory(lc)) { int i; ms_message("Outgoing call [%p] failed with SRTP (SAVP) enabled",call); linphone_call_stop_media_streams(call); if ( call->state==LinphoneCallOutgoingInit || call->state==LinphoneCallOutgoingProgress || call->state==LinphoneCallOutgoingRinging /*push case*/ || call->state==LinphoneCallOutgoingEarlyMedia){ ms_message("Retrying call [%p] with AVP",call); /* clear SRTP local params */ call->params.media_encryption = LinphoneMediaEncryptionNone; for(i=0; i<call->localdesc->n_active_streams; i++) { call->localdesc->streams[i].proto = SalProtoRtpAvp; memset(call->localdesc->streams[i].crypto, 0, sizeof(call->localdesc->streams[i].crypto)); } linphone_core_restart_invite(lc, call); return; } } msg=_("Incompatible media parameters."); if (lc->vtable.display_status) lc->vtable.display_status(lc,msg); break; case SalReasonRequestPending: /*restore previous state, the application will decide to resubmit the action if relevant*/ call->reason=linphone_reason_from_sal(sr); linphone_call_set_state(call,call->prevstate,msg); return; break; default: if (lc->vtable.display_status) lc->vtable.display_status(lc,_("Call failed.")); } } /*some call error are not fatal*/ switch (call->state) { case LinphoneCallUpdating: case LinphoneCallPausing: case LinphoneCallResuming: ms_message("Call error on state [%s], restoring previous state",linphone_call_state_to_string(call->prevstate)); call->reason=linphone_reason_from_sal(sr); linphone_call_set_state(call, call->prevstate,details); return; default: break; /*nothing to do*/ } linphone_core_stop_ringing(lc); linphone_call_stop_media_streams(call); #ifdef BUILD_UPNP linphone_call_delete_upnp_session(call); #endif //BUILD_UPNP call->reason=linphone_reason_from_sal(sr); if (sr==SalReasonDeclined){ linphone_call_set_state(call,LinphoneCallEnd,"Call declined."); }else{ linphone_call_set_state(call,LinphoneCallError,details); if (sr==SalReasonBusy) linphone_core_play_named_tone(lc,LinphoneToneBusy); } if (referer){ /*notify referer of the failure*/ linphone_core_notify_refer_state(lc,referer,call); /*schedule automatic resume of the call. This must be done only after the notifications are completed due to dialog serialization of requests.*/ linphone_core_queue_task(lc,(belle_sip_source_func_t)resume_call_after_failed_transfer,linphone_call_ref(referer),"Automatic call resuming after failed transfer"); } }
static void call_released(SalOp *op){ LinphoneCall *call=(LinphoneCall*)sal_op_get_user_pointer(op); if (call!=NULL){ linphone_call_set_state(call,LinphoneCallReleased,"Call released"); }else ms_error("call_released() for already destroyed call ?"); }
static void call_received(SalOp *h){ LinphoneCore *lc=(LinphoneCore *)sal_get_user_pointer(sal_op_get_sal(h)); char *barmesg; LinphoneCall *call; const char *from,*to; char *tmp; LinphoneAddress *from_parsed; LinphoneAddress *from_addr, *to_addr; SalMediaDescription *md; bool_t propose_early_media=lp_config_get_int(lc->config,"sip","incoming_calls_early_media",FALSE); const char *ringback_tone=linphone_core_get_remote_ringback_tone (lc); /* first check if we can answer successfully to this invite */ if (lc->presence_mode==LinphoneStatusBusy || lc->presence_mode==LinphoneStatusOffline || lc->presence_mode==LinphoneStatusDoNotDisturb || lc->presence_mode==LinphoneStatusMoved){ if (lc->presence_mode==LinphoneStatusBusy ) sal_call_decline(h,SalReasonBusy,NULL); else if (lc->presence_mode==LinphoneStatusOffline) sal_call_decline(h,SalReasonTemporarilyUnavailable,NULL); else if (lc->presence_mode==LinphoneStatusDoNotDisturb) sal_call_decline(h,SalReasonTemporarilyUnavailable,NULL); else if (lc->alt_contact!=NULL && lc->presence_mode==LinphoneStatusMoved) sal_call_decline(h,SalReasonRedirect,lc->alt_contact); sal_op_release(h); return; } if (!linphone_core_can_we_add_call(lc)){/*busy*/ sal_call_decline(h,SalReasonBusy,NULL); sal_op_release(h); return; } from=sal_op_get_from(h); to=sal_op_get_to(h); from_addr=linphone_address_new(from); to_addr=linphone_address_new(to); if (is_duplicate_call(lc,from_addr,to_addr)){ ms_warning("Receiving duplicated call, refusing this one."); sal_call_decline(h,SalReasonBusy,NULL); linphone_address_destroy(from_addr); linphone_address_destroy(to_addr); return; } call=linphone_call_new_incoming(lc,from_addr,to_addr,h); sal_call_set_local_media_description(h,call->localdesc); md=sal_call_get_final_media_description(h); if (md && sal_media_description_empty(md)){ sal_call_decline(h,SalReasonMedia,NULL); linphone_call_unref(call); return; } /* the call is acceptable so we can now add it to our list */ linphone_core_add_call(lc,call); from_parsed=linphone_address_new(sal_op_get_from(h)); linphone_address_clean(from_parsed); tmp=linphone_address_as_string(from_parsed); linphone_address_destroy(from_parsed); barmesg=ortp_strdup_printf("%s %s%s",tmp,_("is contacting you"), (sal_call_autoanswer_asked(h)) ?_(" and asked autoanswer."):_(".")); if (lc->vtable.show) lc->vtable.show(lc); if (lc->vtable.display_status) lc->vtable.display_status(lc,barmesg); /* play the ring if this is the only call*/ if (lc->sound_conf.ring_sndcard!=NULL && ms_list_size(lc->calls)==1){ lc->current_call=call; if (lc->ringstream && lc->dmfs_playing_start_time!=0){ ring_stop(lc->ringstream); lc->ringstream=NULL; lc->dmfs_playing_start_time=0; } if(lc->ringstream==NULL && lc->sound_conf.local_ring){ MSSndCard *ringcard=lc->sound_conf.lsd_card ?lc->sound_conf.lsd_card : lc->sound_conf.ring_sndcard; ms_message("Starting local ring..."); lc->ringstream=ring_start(lc->sound_conf.local_ring,2000,ringcard); } else { ms_message("the local ring is already started"); } }else{ /*TODO : play a tone within the context of the current call */ } linphone_call_ref(call); /*prevent the call from being destroyed while we are notifying, if the user declines within the state callback */ linphone_call_set_state(call,LinphoneCallIncomingReceived,"Incoming call"); if (call->state==LinphoneCallIncomingReceived){ sal_call_notify_ringing(h,propose_early_media || ringback_tone!=NULL); if (propose_early_media || ringback_tone!=NULL){ linphone_call_set_state(call,LinphoneCallIncomingEarlyMedia,"Incoming call early media"); linphone_core_update_streams(lc,call,md); } if (sal_call_get_replaces(call->op)!=NULL && lp_config_get_int(lc->config,"sip","auto_answer_replacing_calls",1)){ linphone_core_accept_call(lc,call); } } linphone_call_unref(call); ms_free(barmesg); ms_free(tmp); }