一、首先看一下如何在发起去电的sip请求中添加自定义的消息头
增加自定义头消息发方法,so已经提供了native方法,
发起呼叫的示例如下:
LinphoneCallParams params = lc.createCallParams(null);
if(!TextUtils.isEmpty(extraData)){
params.addCustomHeader("x-extraData",extraData);
}
lc.inviteAddressWithParams(lAddress, params);
extraData是待增加的头消息。
addCustomHeader(key,value)在native下的实现如下: native接口申明全部在linphonecore_jni.cc
extern "C" void Java_org_linphone_core_LinphoneCallParamsImpl_addCustomHeader(JNIEnv *env, jobject thiz, jlong lcp, jstring jheader_name, jstring jheader_value){
const char* header_name = GetStringUTFChars(env, jheader_name);
const char* header_value = GetStringUTFChars(env, jheader_value);
linphone_call_params_add_custom_header((LinphoneCallParams*)lcp,header_name,header_value);
ReleaseStringUTFChars(env, jheader_name, header_name);
ReleaseStringUTFChars(env, jheader_value, header_value);
}
linphone_call_params_add_custom_header(),位于call_params.c中;
void linphone_call_params_add_custom_header(LinphoneCallParams *params, const char *header_name, const char *header_value){
params->custom_headers=sal_custom_header_append(params->custom_headers,header_name,header_value);
}
使用了sal_custon_header_append()来将传入的head_key/value构建成call中使用的结构体
SalCustomHeader *sal_custom_header_append(SalCustomHeader *ch, const char *name, const char *value){
belle_sip_message_t *msg=(belle_sip_message_t*)ch;
belle_sip_header_t *h;
if (msg==NULL){
msg=(belle_sip_message_t*)belle_sip_request_new();
belle_sip_object_ref(msg);
}
h=belle_sip_header_create(name,value);
if (h==NULL){
belle_sip_error("Fail to parse custom header.");
return (SalCustomHeader*)msg;
}
belle_sip_message_add_header(msg,h);
return (SalCustomHeader*)msg;
}
这是一个追加消息头的过程,
params下的custom_headers链表,如果不存在,则在这里先进行初始化belle_sip_request_new(),
通过belle_sip_header_create(name,value)生成一个belle_sip_header_t* 结构体h;
- 通过belle_sip_message_add_header(msg,h)将生成的h追加到msg后面,最后返回;
总结下添加过程:
添加的自定义头消息的key-value,首先被保存在LinphoneCallParam对象中,存放在params->custom_headers中了,custom_headers是一个链表结构
二、分析是如何将LinphoneCallParam中配置的参数,加载到发起呼叫的SIP请求中。
发起呼叫是通过 inviteAddressWithParams(LinphoneAddress address, LinphoneCallParams params)来实现的
native实现在linphonecore.c line3387。
LinphoneCall * linphone_core_invite_address_with_params(LinphoneCore *lc, const LinphoneAddress *addr, const LinphoneCallParams *params){
ms_message("linphone_core_invite_address_with_params playcard = %s, captcard = %s",lc->sound_conf.play_sndcard->desc->driver_type,lc->sound_conf.capt_sndcard->desc->driver_type);
const char *from=NULL;
LinphoneProxyConfig *proxy=NULL;
LinphoneAddres