说明
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)
不找了, 这个次要的. ~_~