/** * Returns the call object this call is replacing, if any. * Call replacement can occur during call transfers. * By default, the core automatically terminates the replaced call and accept the new one. * This function allows the application to know whether a new incoming call is a one that replaces another one. **/ LinphoneCall *linphone_call_get_replaced_call(LinphoneCall *call){ SalOp *op=sal_call_get_replaces(call->op); if (op){ return (LinphoneCall*)sal_op_get_user_pointer(op); } return NULL; }
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); }