From a23c0e4f202b043a08db2bf232863c195f5c94d2 Mon Sep 17 00:00:00 2001 From: Sylvain Berfini Date: Wed, 29 Nov 2017 15:28:49 +0100 Subject: [PATCH] Fixed issue with refs for video surfaces in JNI layer --- wrappers/java/genwrapper.py | 9 +++++- wrappers/java/jni.mustache | 61 ++++++++++++++++++++++++++++++++++++- 2 files changed, 68 insertions(+), 2 deletions(-) diff --git a/wrappers/java/genwrapper.py b/wrappers/java/genwrapper.py index eba6ab482..c68127c11 100755 --- a/wrappers/java/genwrapper.py +++ b/wrappers/java/genwrapper.py @@ -358,7 +358,11 @@ class JavaTranslator(object): return methodDict def translate_jni_method(self, className, _method, static=False): - methodDict = {} + jni_blacklist = ['linphone_call_set_native_video_window_id',\ + 'linphone_core_set_native_preview_window_id',\ + 'linphone_core_set_native_video_window_id'] + + methodDict = {'notEmpty': True} methodDict['classCName'] = 'Linphone' + className.to_camel_case() methodDict['className'] = className.to_camel_case() methodDict['classImplName'] = className.to_camel_case() + 'Impl' @@ -378,6 +382,9 @@ class JavaTranslator(object): methodDict['isRealObjectArray'] = False methodDict['isStringObjectArray'] = False methodDict['c_type_return'] = self.translate_as_c_base_type(_method.returnType) + + if methodDict['c_name'] in jni_blacklist: + return {'notEmpty': False} if methodDict['hasListReturn']: if type(_method.returnType) is AbsApi.BaseType and _method.returnType.name == 'string_array': diff --git a/wrappers/java/jni.mustache b/wrappers/java/jni.mustache index 8513e753c..a6e855736 100644 --- a/wrappers/java/jni.mustache +++ b/wrappers/java/jni.mustache @@ -419,6 +419,7 @@ jobject Java_{{jni_package}}FactoryImpl_createCore(JNIEnv *env, jobject thiz, jo ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// {{#methods}} +{{#notEmpty}} {{return}} {{name}}({{params}}) { {{#notStatic}}{{classCName}} *cptr = ({{classCName}}*)ptr;{{/notStatic}}{{#strings}} const char* c_{{string}} = GetStringUTFChars(env, {{string}}); @@ -482,9 +483,67 @@ jobject Java_{{jni_package}}FactoryImpl_createCore(JNIEnv *env, jobject thiz, jo env->ReleaseByteArrayElements({{bytesargname}}, (jbyte*)c_{{bytesargname}}, JNI_ABORT); {{/bytes}}{{#hasReturn}}return jni_result;{{/hasReturn}}{{#hasListReturn}}return jni_list_result;{{/hasListReturn}} } - +{{/notEmpty}} {{/methods}} +////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +// Manually wrapped +////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + +void Java_org_linphone_core_CallImpl_setNativeVideoWindowId(JNIEnv *env, jobject thiz, jlong ptr, jobject id) { + LinphoneCall *cptr = (LinphoneCall*)ptr; + jobject oldWindow = (jobject) linphone_call_get_native_video_window_id(cptr); + if (oldWindow == id) { + ms_warning("Java_org_linphone_core_CallImpl_setNativeVideoWindowId(): new id (%p) is the same as the current one, skipping...", id); + return; + } + if (id != NULL) { + id = env->NewGlobalRef(id); + ms_message("Java_org_linphone_core_CallImpl_setNativeVideoWindowId(): NewGlobalRef(%p)", id); + } else ms_message("Java_org_linphone_core_CallImpl_setNativeVideoWindowId(): setting to NULL"); + linphone_call_set_native_video_window_id(cptr, (void *)id); + if (oldWindow != NULL) { + ms_message("Java_org_linphone_core_CallImpl_setNativeVideoWindowId(): DeleteGlobalRef(%p)", oldWindow); + env->DeleteGlobalRef(oldWindow); + } +} + +void Java_org_linphone_core_CoreImpl_setNativePreviewWindowId(JNIEnv *env, jobject thiz, jlong ptr, jobject id) { + LinphoneCore *cptr = (LinphoneCore*)ptr; + jobject oldWindow = (jobject) linphone_core_get_native_video_window_id(cptr); + if (oldWindow == id) { + ms_warning("Java_org_linphone_core_CoreImpl_setNativePreviewWindowId(): new id (%p) is the same as the current one, skipping...", id); + return; + } + if (id != NULL) { + id = env->NewGlobalRef(id); + ms_message("Java_org_linphone_core_CoreImpl_setNativePreviewWindowId(): NewGlobalRef(%p)", id); + } else ms_message("Java_org_linphone_core_CoreImpl_setNativePreviewWindowId(): setting to NULL"); + linphone_core_set_native_preview_window_id(cptr, (void *)id); + if (oldWindow != NULL) { + ms_message("Java_org_linphone_core_CoreImpl_setNativePreviewWindowId(): DeleteGlobalRef(%p)", oldWindow); + env->DeleteGlobalRef(oldWindow); + } +} + +void Java_org_linphone_core_CoreImpl_setNativeVideoWindowId(JNIEnv *env, jobject thiz, jlong ptr, jobject id) { + LinphoneCore *cptr = (LinphoneCore*)ptr; + jobject oldWindow = (jobject) linphone_core_get_native_preview_window_id(cptr); + if (oldWindow == id) { + ms_warning("Java_org_linphone_core_CoreImpl_setNativeVideoWindowId(): new id (%p) is the same as the current one, skipping...", id); + return; + } + if (id != NULL) { + id = env->NewGlobalRef(id); + ms_message("Java_org_linphone_core_CoreImpl_setNativeVideoWindowId(): NewGlobalRef(%p)", id); + } else ms_message("Java_org_linphone_core_CoreImpl_setNativeVideoWindowId(): setting to NULL"); + linphone_core_set_native_video_window_id(cptr, (void *)id); + if (oldWindow != NULL) { + ms_message("Java_org_linphone_core_CoreImpl_setNativeVideoWindowId(): DeleteGlobalRef(%p)", oldWindow); + env->DeleteGlobalRef(oldWindow); + } +} + #ifdef __cplusplus } #endif \ No newline at end of file