int main(int argc, char *argv[]) { RingStream *r; const char *file; MSSndCard *sc; const char * card_id=NULL; MSFactory *factory; ortp_init(); ortp_set_log_level_mask(ORTP_LOG_DOMAIN, ORTP_MESSAGE|ORTP_WARNING|ORTP_ERROR|ORTP_FATAL); factory = ms_factory_new_with_voip(); if (argc>1) { file=argv[1]; } else file="/usr/share/sounds/linphone/rings/oldphone.wav"; if (argc>2) { card_id=argv[2]; } sc=ms_snd_card_manager_get_card(ms_factory_get_snd_card_manager(factory),card_id); #ifdef __linux if (sc==NULL) sc = ms_alsa_card_new_custom(card_id, card_id); #endif r=ring_start(factory, file,2000,sc); ms_sleep(10); ring_stop(r); ms_factory_destroy(factory); return 0; }
void linphone_core_update_streams(LinphoneCore *lc, LinphoneCall *call, SalMediaDescription *new_md){ SalMediaDescription *oldmd=call->resultdesc; if (lc->ringstream!=NULL){ ring_stop(lc->ringstream); lc->ringstream=NULL; } if (new_md!=NULL){ sal_media_description_ref(new_md); call->media_pending=FALSE; }else{ call->media_pending=TRUE; } call->resultdesc=new_md; if (call->audiostream && call->audiostream->ticker){ /* we already started media: check if we really need to restart it*/ if (oldmd){ if (!media_parameters_changed(call,oldmd,new_md) && !call->playing_ringbacktone){ sal_media_description_unref(oldmd); if (call->all_muted){ ms_message("Early media finished, unmuting inputs..."); /*we were in early media, now we want to enable real media */ linphone_call_enable_camera (call,linphone_call_camera_enabled (call)); if (call->audiostream) linphone_core_mute_mic (lc, linphone_core_is_mic_muted(lc)); #ifdef VIDEO_ENABLED if (call->videostream && call->camera_active) video_stream_change_camera(call->videostream,lc->video_conf.device ); #endif } ms_message("No need to restart streams, SDP is unchanged."); return; }else{ ms_message("Media descriptions are different, need to restart the streams."); } } linphone_call_stop_media_streams (call); linphone_call_init_media_streams (call); } if (oldmd) sal_media_description_unref(oldmd); if (new_md) { bool_t all_muted=FALSE; bool_t send_ringbacktone=FALSE; if (call->audiostream==NULL){ /*this happens after pausing the call locally. The streams is destroyed and then we wait the 200Ok to recreate it*/ linphone_call_init_media_streams (call); } if (call->state==LinphoneCallIncomingEarlyMedia && linphone_core_get_remote_ringback_tone (lc)!=NULL){ send_ringbacktone=TRUE; } if (call->state==LinphoneCallIncomingEarlyMedia || (call->state==LinphoneCallOutgoingEarlyMedia && !call->params.real_early_media)){ all_muted=TRUE; } linphone_call_start_media_streams(call,all_muted,send_ringbacktone); } }
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); } }
/** * On call state used to automatically ringback. */ PJ_DECL(void) css_on_call_state(pjsua_call_id call_id, pjsip_event *e) { pjsua_call_info call_info; pjsua_call_get_info(call_id, &call_info); if (call_info.state == PJSIP_INV_STATE_DISCONNECTED) { /* Stop all ringback for this call */ ring_stop(call_id); PJ_LOG( 3, (THIS_FILE, "Call %d is DISCONNECTED [reason=%d (%s)]", call_id, call_info.last_status, call_info.last_status_text.ptr)); } else { if (call_info.state == PJSIP_INV_STATE_EARLY) { int code; pj_str_t reason; pjsip_msg *msg; /* This can only occur because of TX or RX message */ pj_assert(e->type == PJSIP_EVENT_TSX_STATE); if (e->body.tsx_state.type == PJSIP_EVENT_RX_MSG) { msg = e->body.tsx_state.src.rdata->msg_info.msg; } else { msg = e->body.tsx_state.src.tdata->msg; } code = msg->line.status.code; reason = msg->line.status.reason; /* Start ringback for 180 for UAC unless there's SDP in 180 */ if (call_info.role == PJSIP_ROLE_UAC && code == 180 && msg->body == NULL && call_info.media_status == PJSUA_CALL_MEDIA_NONE) { ringback_start(); } PJ_LOG( 3, (THIS_FILE, "Call %d state changed to %s (%d %.*s)", call_id, call_info.state_text.ptr, code, (int)reason.slen, reason.ptr)); } else { PJ_LOG( 3, (THIS_FILE, "Call %d state changed to %s", call_id, call_info.state_text.ptr)); } } }
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"); }
/** * On call media state used to automatically ringback. */ PJ_DECL(void) css_on_call_media_state(pjsua_call_id call_id){ ring_stop(call_id); }
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."); } }
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); }