Linphone android去电增加自定义SIP消息头的流程分析

本文详细分析了如何在Linphone Android中为去电请求添加自定义SIP消息头,包括native方法的实现、LinphoneCallParam参数的加载到SIP请求的过程,以及在Java层如何获取和读取这些自定义头消息。
摘要由CSDN通过智能技术生成

一、首先看一下如何在发起去电的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;
}

这是一个追加消息头的过程,

  1. params下的custom_headers链表,如果不存在,则在这里先进行初始化belle_sip_request_new(),

  2. 通过belle_sip_header_create(name,value)生成一个belle_sip_header_t* 结构体h;

  3. 通过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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值