首页 > 其他分享 >linphone-TunnelConfigImpl文件对应的JNI层文件分析

linphone-TunnelConfigImpl文件对应的JNI层文件分析

时间:2023-05-29 14:36:25浏览次数:47  
标签:文件 tunnel void TunnelConfigImpl LinphoneTunnelConfig JNI linphone config port


说明

native函数

private native String getHost(long nativePtr);
    private native void setHost(long nativePtr, String host);
    private native int getPort(long nativePtr);
    private native void setPort(long nativePtr, int port);
    private native int getRemoteUdpMirrorPort(long nativePtr);
    private native void setRemoteUdpMirrorPort(long nativePtr, int remoteUdpMirrorPort);
    private native int getDelay(long nativePtr);
    private native void setDelay(long nativePtr, int delay);
    private native void enableSip(long nativePtr, boolean enabled);
    private native void destroy(long nativePtr);

具体的函数分析

native String getHost(long nativePtr)

具体函数实现

/*
 * Class:     org_linphone_core_TunnelConfigImpl
 * Method:    getHost
 * Signature: (J)Ljava/lang/String;
 */
JNIEXPORT jstring JNICALL Java_org_linphone_core_TunnelConfigImpl_getHost(JNIEnv *env, jobject obj, jlong ptr){
    LinphoneTunnelConfig *cfg = (LinphoneTunnelConfig *)ptr;
    const char *host = linphone_tunnel_config_get_host(cfg);
    if (host){
        return env->NewStringUTF(host);
    }
    return NULL;
}

LinphoneTunnelConfig

submodules/linphone/coreapi/linphone_tunnel_config.c:struct _LinphoneTunnelConfig {

这里只找到结构体_LinphoneTunnelConfig, 无名之中我感觉这个可定跟LinphoneTunnelConfig有莫大的关系. 待我来查一下.

struct _LinphoneTunnelConfig {
    belle_sip_object_t base;
    char *host;
    int port;
    int remote_udp_mirror_port;
    int delay;
    void *user_data;
};

grep -r “_LinphoneTunnelConfig”我就说了么,肯定有关系:

submodules/linphone/coreapi/linphone_tunnel.h:typedef struct _LinphoneTunnelConfig LinphoneTunnelConfig;
submodules/linphone/coreapi/linphone_tunnel_config.c:struct _LinphoneTunnelConfig {

发现没有, 要分析的话, 还是要分析_LinphoneTunnelConfig, 这里有这个结构体的实现. 看上面那个结构体实现吧.

这里belle_sip_object_t base; 引起了我的注意, 看看这个belle_sip_object_t到底是什么东西. 好吧, 没有找到, 反正就是一个类型, 像struct结构体类型啊, typedef定义的啊, define定义的啊.

linphone_tunnel_config_get_host

submodules/linphone/coreapi/linphone_tunnel.h:LINPHONE_PUBLIC const char *linphone_tunnel_config_get_host(const LinphoneTunnelConfig *tunnel);

submodules/linphone/coreapi/linphone_tunnel_config.c:const char *linphone_tunnel_config_get_host(const LinphoneTunnelConfig *tunnel) {

这里直接看它的实现

const char *linphone_tunnel_config_get_host(const LinphoneTunnelConfig *tunnel) {
    return tunnel->host;
}

一下就找到了根真没意思.~~~~好吧, 我专门挑了一个简单的类, 后面又复杂的, 准备下班后的晚上进行分析那些复杂的, 因为比较专注, 周末时间, 还是一些简单的类吧, 毕竟自己的自控能力没有这么强悍.

native void setHost(long nativePtr, String host)

/*
 * Class:     org_linphone_core_TunnelConfigImpl
 * Method:    setHost
 * Signature: (JLjava/lang/String;)V
 */
JNIEXPORT void JNICALL Java_org_linphone_core_TunnelConfigImpl_setHost(JNIEnv *env, jobject obj, jlong ptr, jstring jstr){
    LinphoneTunnelConfig *cfg = (LinphoneTunnelConfig *)ptr;
    const char* host = jstr ? env->GetStringUTFChars(jstr, NULL) : NULL;
    linphone_tunnel_config_set_host(cfg, host);
    if (jstr) env->ReleaseStringUTFChars(jstr, host);
}

linphone_tunnel_config_set_host

submodules/linphone/coreapi/linphone_tunnel.h:LINPHONE_PUBLIC void linphone_tunnel_config_set_host(LinphoneTunnelConfig *tunnel, const char *host);

submodules/linphone/coreapi/linphone_tunnel_config.c:void linphone_tunnel_config_set_host(LinphoneTunnelConfig *tunnel, const char *host) {
void linphone_tunnel_config_set_host(LinphoneTunnelConfig *tunnel, const char *host) {
    if(tunnel->host != NULL) {
        ms_free(tunnel->host);
        tunnel->host = NULL;
    }
    if(host != NULL && strlen(host)) {
        tunnel->host = ms_strdup(host);
    }
}

这里不禁让我想到, 这个设置是存在哪里呢? 看看我能不能分析到, 分析到最好了, 如果不能分析到, 也无所谓. 等到了第四个阶段再分析也不迟, 毕竟这才是第二个阶段.
对于ms_strdup我只找到了这个函数
>>> _strdup函数——将字符串存入内存中<<<

这个函数应该跟那个ms_strdupd差不多, 就是把字符串引入内存. 看来这个host就存在内存里, 应该是在linphone启动或者打电话的时候创建的.

native int getPort(long nativePtr)

/*
 * Class:     org_linphone_core_TunnelConfigImpl
 * Method:    getPort
 * Signature: (J)I
 */
JNIEXPORT jint JNICALL Java_org_linphone_core_TunnelConfigImpl_getPort(JNIEnv *env, jobject jobj, jlong ptr){
    LinphoneTunnelConfig *cfg = (LinphoneTunnelConfig *)ptr;
    return linphone_tunnel_config_get_port(cfg);
}

刚才突然看到这句话,让我脑子灵光一现, ptr是long类型的, 这个LinphoneTunnelConfig是个结构体.

LinphoneTunnelConfig *cfg = (LinphoneTunnelConfig *)ptr

不行我得回头看看这个ptr在java层是怎样传过来的, 传的到底是什么,一定要搞个明白.

private native int getPort(long nativePtr);

就是那个很重要的nativePtr. 这个nativePtr原来不是简单的long行, 二是代表了内存中一连串的数据啊. 不禁又给我头上打了深深的一棒槌.

linphone_tunnel_config_get_port

submodules/linphone/coreapi/linphone_tunnel.h:LINPHONE_PUBLIC int linphone_tunnel_config_get_port(const LinphoneTunnelConfig *tunnel);

submodules/linphone/coreapi/linphone_tunnel_config.c:int linphone_tunnel_config_get_port(const LinphoneTunnelConfig *tunnel) {
int linphone_tunnel_config_get_port(const LinphoneTunnelConfig *tunnel) {
    return tunnel->port;
}

好吧, 逻辑跟前几个函数差不多.

native void setPort(long nativePtr, int port)

/*
 * Class:     org_linphone_core_TunnelConfigImpl
 * Method:    setPort
 * Signature: (JI)V
 */
JNIEXPORT void JNICALL Java_org_linphone_core_TunnelConfigImpl_setPort(JNIEnv *env, jobject jobj, jlong ptr, jint port){
    LinphoneTunnelConfig *cfg = (LinphoneTunnelConfig *)ptr;
    linphone_tunnel_config_set_port(cfg, port);
}

linphone_tunnel_config_set_port

void linphone_tunnel_config_set_port(LinphoneTunnelConfig *tunnel, int port) {
    tunnel->port = port;
}

这个没有ms_strdup啊. 难道是因为这个port是int整型的吗?

native int getRemoteUdpMirrorPort(long nativePtr)

/*
 * Class:     org_linphone_core_TunnelConfigImpl
 * Method:    getRemoteUdpMirrorPort
 * Signature: (J)I
 */
JNIEXPORT jint JNICALL Java_org_linphone_core_TunnelConfigImpl_getRemoteUdpMirrorPort(JNIEnv *env, jobject jobj, jlong ptr){
    LinphoneTunnelConfig *cfg = (LinphoneTunnelConfig *)ptr;
    return linphone_tunnel_config_get_remote_udp_mirror_port(cfg);
}

ms_strdup

这里为啥要说它呢, 上面都说过了, 因为上面没找到, 这才找到, 所以必须要说一下.

submodules/linphone/mediastreamer2/include/mediastreamer2/mscommon.h:#define ms_strdup  ortp_strdup

ortp_strdup

submodules/linphone/oRTP/include/ortp/port.h:ORTP_PUBLIC char * ortp_strdup(const char *tmp);
submodules/linphone/oRTP/include/ortp/port.h:ORTP_PUBLIC char *ortp_strdup_printf(const char *fmt,...);
submodules/linphone/oRTP/include/ortp/port.h:ORTP_PUBLIC char *ortp_strdup_vprintf(const char *fmt, va_list ap);

一搜一大串, 我也是兴奋的不行不行的.

submodules/linphone/mediastreamer2/src/ortp-deps/port.c:char * ortp_strdup(const char *tmp){
char * ortp_strdup(const char *tmp){
    size_t sz;
    char *ret;
    if (tmp==NULL)
      return NULL;
    sz=strlen(tmp)+1;
    ret=(char*)ortp_malloc(sz);
    strcpy(ret,tmp);
    ret[sz-1]='\0';
    return ret;
}

哇塞, 真是豁然开朗啊.

ortp_malloc

submodules/linphone/oRTP/src/port.c:void* ortp_malloc(size_t sz){

submodules/linphone/oRTP/include/ortp/port.h:ORTP_PUBLIC void* ortp_malloc(size_t sz);
submodules/linphone/oRTP/include/ortp/port.h:ORTP_PUBLIC void* ortp_malloc0(size_t sz);

submodules/linphone/oRTP/include/ortp/port.h:#define ortp_new(type,count)   (type*)ortp_malloc(sizeof(type)*(count))
submodules/linphone/oRTP/include/ortp/port.h:#define ortp_new0(type,count)  (type*)ortp_malloc0(sizeof(type)*(count))

submodules/linphone/mediastreamer2/src/ortp-deps/port.c:void* ortp_malloc(size_t sz){
submodules/linphone/mediastreamer2/src/ortp-deps/port.c:void * ortp_malloc0(size_t size){

submodules/linphone/mediastreamer2/include/mediastreamer2/mscommon.h:#define ms_malloc  ortp_malloc
submodules/linphone/mediastreamer2/include/mediastreamer2/mscommon.h:#define ms_malloc0 ortp_malloc0

我恨我有这么强的好奇心. 不过还好.

linphone_tunnel_config_get_remote_udp_mirror_port

submodules/linphone/coreapi/linphone_tunnel.h:LINPHONE_PUBLIC int linphone_tunnel_config_get_remote_udp_mirror_port(const LinphoneTunnelConfig *tunnel);

submodules/linphone/coreapi/linphone_tunnel_config.c:int linphone_tunnel_config_get_remote_udp_mirror_port(const LinphoneTunnelConfig *tunnel) {
int linphone_tunnel_config_get_remote_udp_mirror_port(const LinphoneTunnelConfig *tunnel) {
    return tunnel->remote_udp_mirror_port;
}

native void setRemoteUdpMirrorPort(long nativePtr, int remoteUdpMirrorPort)

/*
 * Class:     org_linphone_core_TunnelConfigImpl
 * Method:    setRemoteUdpMirrorPort
 * Signature: (JI)V
 */
JNIEXPORT void JNICALL Java_org_linphone_core_TunnelConfigImpl_setRemoteUdpMirrorPort(JNIEnv *env, jobject jobj, jlong ptr, jint port){
     LinphoneTunnelConfig *cfg = (LinphoneTunnelConfig *)ptr;
     linphone_tunnel_config_set_remote_udp_mirror_port(cfg, port);
}

linphone_tunnel_config_set_remote_udp_mirror_port

submodules/linphone/coreapi/linphone_tunnel.h:LINPHONE_PUBLIC void linphone_tunnel_config_set_remote_udp_mirror_port(LinphoneTunnelConfig *tunnel, int remote_udp_mirror_port);

submodules/linphone/coreapi/linphone_tunnel_config.c:void linphone_tunnel_config_set_remote_udp_mirror_port(LinphoneTunnelConfig *tunnel, int remote_udp_mirror_port) {
void linphone_tunnel_config_set_remote_udp_mirror_port(LinphoneTunnelConfig *tunnel, int remote_udp_mirror_port) {
    tunnel->remote_udp_mirror_port = remote_udp_mirror_port;
}

native int getDelay(long nativePtr)

/*
 * Class:     org_linphone_core_TunnelConfigImpl
 * Method:    getDelay
 * Signature: (J)I
 */
JNIEXPORT jint JNICALL Java_org_linphone_core_TunnelConfigImpl_getDelay(JNIEnv *env, jobject jobj, jlong ptr){
     LinphoneTunnelConfig *cfg = (LinphoneTunnelConfig *)ptr;
     return linphone_tunnel_config_get_delay(cfg);
}

linphone_tunnel_config_get_delay

submodules/linphone/coreapi/linphone_tunnel.h:LINPHONE_PUBLIC int linphone_tunnel_config_get_delay(const LinphoneTunnelConfig *tunnel);

submodules/linphone/coreapi/linphone_tunnel_config.c:int linphone_tunnel_config_get_delay(const LinphoneTunnelConfig *tunnel) {
int linphone_tunnel_config_get_delay(const LinphoneTunnelConfig *tunnel) {
    return tunnel->delay;
}

native void setDelay(long nativePtr, int delay)

/*
 * Class:     org_linphone_core_TunnelConfigImpl
 * Method:    setDelay
 * Signature: (JI)I
 */
JNIEXPORT void JNICALL Java_org_linphone_core_TunnelConfigImpl_setDelay(JNIEnv *env, jobject jobj, jlong ptr, jint delay){
    LinphoneTunnelConfig *cfg = (LinphoneTunnelConfig *)ptr;
    linphone_tunnel_config_set_delay(cfg, delay);
}

linphone_tunnel_config_set_delay

submodules/linphone/coreapi/linphone_tunnel.h:LINPHONE_PUBLIC void linphone_tunnel_config_set_delay(LinphoneTunnelConfig *tunnel, int delay);

submodules/linphone/coreapi/linphone_tunnel_config.c:void linphone_tunnel_config_set_delay(LinphoneTunnelConfig *tunnel, int delay) {
void linphone_tunnel_config_set_delay(LinphoneTunnelConfig *tunnel, int delay) {
    tunnel->delay = delay;
}

native void enableSip(long nativePtr, boolean enabled)

extern "C" void Java_org_linphone_core_LinphoneCoreImpl_tunnelEnableSip(JNIEnv *env, jobject thiz, jlong pCore, jboolean enable) {
    LinphoneTunnel *tunnel = ((LinphoneCore *)pCore)->tunnel;
    if(tunnel != NULL) {
        linphone_tunnel_enable_sip(tunnel, (bool_t)enable);
    }
}

这个是不是错了? 反正我没找到其它的,就它吧.

submodules/linphone/coreapi/linphone_tunnel.h:LINPHONE_PUBLIC void linphone_tunnel_enable_sip(LinphoneTunnel *tunnel, bool_t enable);

submodules/linphone/coreapi/linphone_tunnel.cc:void linphone_tunnel_enable_sip(LinphoneTunnel *tunnel, bool_t enable) {

linphone_tunnel_enable_sip

肯定是找错了

submodules/linphone/coreapi/linphone_tunnel.h:LINPHONE_PUBLIC void linphone_tunnel_enable_sip(LinphoneTunnel *tunnel, bool_t enable);

native void destroy(long nativePtr)

不找了, 这个次要的. ~_~


标签:文件,tunnel,void,TunnelConfigImpl,LinphoneTunnelConfig,JNI,linphone,config,port
From: https://blog.51cto.com/u_11797608/6370707

相关文章

  • linphone-LinphoneService.java文件分析
    说明主要是处理接听电话的逻辑,监听linphone拨打电话的状态逻辑。官方注释/****Linphoneservice,reactingtoIncomingcalls,...<br/>**Rolesinclude:<ul>*<li>InitializingLinphoneManager</li>*<li>StartingClibLinphonethroughLinphoneManage......
  • linphone-LinphoneCallParams.java文件分析
    说明专门作为Audio和Video的参数功能设置视频的带宽设置音频的带宽设置媒体的加密数据(encryption)设置是否允许低带宽设置RecordFile设置Sdp设置会话名称等是否允许多个rtp请求UML类图LinphoneCallParamsImpl.javapackageorg.linphone.core;importorg.linphone.core.LinphoneCor......
  • linphone-CallManager.java文件分析
    说明进行会话的管理,重新加入会话等功能创建会话重新进入Video重新设置参数更新会话UML类图CallManger.javapackageorg.linphone;importorg.linphone.core.LinphoneAddress;importorg.linphone.core.LinphoneCall;importorg.linphone.core.LinphoneCallParams;importorg.l......
  • linphone-PayloadType.java文件分析
    说明这个类主要是设置一些类型的参数,如MIME,RATE,FMTP等功能设置MIME设置RATE设置FMTUML类图PayloadType.javapackageorg.linphone.core;publicinterfacePayloadType{/***Obtaintheregisteredmime-type(actuallysubmime)ofthePayloadType.Forexample:......
  • linphone-LinphoneProxyConfig.java文件分析
    说明这个是linphone的纯配置文件,可能需要保存到文件中,是长久的数据.如何保存c/c++分析.功能设置Identity设置Address设置Proxy设置register设置Domain设置Dial设置Route设置Route设置Expires设置AVPF设置Realm设置ContactParameters设置PublichExpiresUML类图LinphoneProxyConfi......
  • linphone-LinphonePreferences.java文件分析
    说明这个文件比较长,主要是对于linphone的配置文件等设置。对于前面文章中文件的调用。其中大多数是对底层的调用设置。功能设置用户信息设置端口号设置显示名称设置密码设置代理设置编码设置编码速率设置DMTF等设置加密解密设置是否使用ipv6设置tunnel设置相机等UML类图LinphonePre......
  • JNI-记录一个内存泄露的问题
    android:channelisunrecoverablybrokenandwillbedisposed记录一个关于内存泄漏的问题:RT,在停止播放音乐时,每过一段时间就会报05-2510:52:21.125491-528/system_processE/InputDispatcher:channel'4a8b59f4activity.MainActivity(server)'~Channelisun......
  • linphone-NetworkManger.java文件分析
    功能InterceptnetworkstatechangesandupdatelinphonecorethroughLinphoneManger翻译拦截网络状态的变化,并通过LinphoneManger更新linphone核心内容。NetworkManager.java/**......
  • linphone-KeepAliveReceiver.java文件分析
    说明Purposeofthisreceiveristodisablekeepaliveswhenscreenisoff解释这个接收器的目的是屏幕关闭的时候进行保活。<—翻译的准确性,等更加深刻的分析源码时更正,或者读者自己在下面评论也可以。介绍此类为接收器,接收外部传来的广播。KeepAliveReceiver.java/**Purpos......
  • linphone-BootReceiver.java文件分析
    说明这是个在android发送开机广播的时候调用的类功能主要就是为了在开机的时候启动LinphoneService开启后台服务。其中有一个.linphonerc的文件,这个文件应该是LpConfig的对应的配置文件。如果有错请更正。BootReceiver.javapublicclassBootReceiverextendsBroadcastReceiver{......