首先是jni入口:
linphonecore_jni.cc -> linphone_core_invite_address_with_params()
然后到linphonecore:
linphone_core_invite_address_with_params()
这里会判断是否到达最大通话数:
linphone_core_can_we_add_call(LinphoneCore *lc)
没有的话会创建一个LinphoneCall:
linphonecall.c -> linphone_call_init_common() // 一些基本的初始化,设置audio和video的rtp及rtcp本地端口 ```
创建完成call后,将call添加进calls中,然后将这个call设置为current_call:
``` lc->current_call=call; ```
紧接着设置状态:
``` linphone_call_set_state (call,LinphoneCallOutgoingInit,"Starting outgoing call"); ```
再接着就会初始化媒体流了:
``` linphone_call_init_media_streams(call) ```
这里会初始化audio和video媒体流,我这里只看audio:
``` linphone_call_init_audio_stream() //这里初始化语音数据流 ```
语音数据流初始化会调用到mediastreamer2模块:
``` audiostream.c -> audio_stream_new2(...) ```
创建rtpsession及一系列初始化:
``` mediastream.c -> create_duplex_rtpsession(...) ```
这里就会调用到oRTP模块:
``` rtpsession.c -> rtp_session_new(...) ```
创建完rtpsession后会进行一系列设置,比如:
``` rtpsession_inet.c -> rtp_session_set_local_addr(...) // 设置rtp本地地址 ```
这里依次创建rtp和rtcp的socket,本地端口大于0则使用传进来的端口,否则由系统分配。
创建完rtpsession后,mediastreamer2模块才会创建audiastream:
``` obj=audio_stream_new_with_sessions(&sessions); ```
添加发送的filter:
``` stream->ms.rtpsend=ms_filter_new(MS_RTP_SEND_ID); ```
为stream注册rtp事件队列:
``` rtp_session_register_event_queue(stream->ms.sessions.rtp_session,stream->ms.evq); ```
添加回声消除filter,其它初始化:
stream->ec=ms_filter_new_from_desc(ec_desc);
stream->play_dtmfs=TRUE;
stream->use_gc=FALSE;
stream->use_agc=FALSE;
stream->use_ng=FALSE;
stream->features=AUDIO_STREAM_FEATURE_ALL;
初始化完成了oRTP和mediastreamer2,再次回到``` linphone_call_init_media_streams() ```
如果是随机端口 再重新取一次本地端口号:
if (call->media_ports[0].rtp_port==-1){
port_config_set_random_choosed(call,0,audiostream->ms.sessions.rtp_session);
}
接着,如果支持回声限制,则根据配置信息设置一些相关参数:
``` audio_stream_set_echo_canceller_params(audiostream,len,delay,framesize); ```
是否支持获取控制,以便不获取噪声,有个噪声的gateway要设置:
int enabled=lp_config_get_int(lc->config,"sound","noisegate",0);
audio_stream_enable_noise_gate(audiostream,enabled);
发起呼叫:
``` linphonecall.c -> linphone_core_start_invite(lc,call,NULL); ```
设置本地媒体格式描述:
``` linphonecall.c -> linphone_call_make_local_media_description_with_params() ```
真正呼叫,发送invite请求:
``` sal_op_call.c -> sal_call(call->op,from,real_url) ```
```sal_op_call_fill_cbs(op); // 设置事件回调 ```
设置状态LinphoneCallOutgoingProgress:
``` linphone_call_set_state(call,LinphoneCallOutgoingProgress,"Outgoing call in progress"); ```
至此,呼叫请求已发出,等待服务端响应。
处理响应
``` sal_op_call.c -> call_process_response() ```
收到100 Trying,不处理
收到180 Ringing(或183):
``` callbacks.c -> call_ringing() // 播放铃声 ```
没有sdp就播放本地铃声,设置状态LinphoneCallOutgoingRinging
有就播放彩铃,设置状态LinphoneCallOutgoingEarlyMedia
收到200 OK:
``` callbacks.c -> call_accepted() ```
设置状态LinphoneCallConnected
收到ACK:
``` callbacks.c ->call_ack() ```
设置状态LinphoneCallStreamsRunning
通话建立,呼叫流程结束。