diff --git a/coreapi/linphonecore_jni.cc b/coreapi/linphonecore_jni.cc index 759311661..8e794716a 100644 --- a/coreapi/linphonecore_jni.cc +++ b/coreapi/linphonecore_jni.cc @@ -6204,4 +6204,28 @@ extern "C" jobject Java_org_linphone_core_LinphoneChatRoomImpl_getCall(JNIEnv* e extern "C" jlong Java_org_linphone_core_LinphoneChatRoomImpl_getChar(JNIEnv* env ,jobject thiz, jlong ptr) { return linphone_chat_room_get_char((LinphoneChatRoom *)ptr); -} \ No newline at end of file +} + +static void _next_video_frame_decoded_callback(LinphoneCall *call, void *user_data) { + JNIEnv *env = 0; + jint result = jvm->AttachCurrentThread(&env,NULL); + + if (result != 0) { + ms_error("cannot attach VM\n"); + return; + } + + jobject listener = (jobject) user_data; + jclass clazz = (jclass) env->GetObjectClass(listener); + jmethodID method = env->GetMethodID(clazz, "onNextVideoFrameDecoded","(Lorg/linphone/core/LinphoneCall;)V"); + env->DeleteLocalRef(clazz); + + jobject jcall = getCall(env, call); + env->CallVoidMethod(listener, method, jcall); +} + +JNIEXPORT void JNICALL Java_org_linphone_core_LinphoneCallImpl_setListener(JNIEnv* env, jobject thiz, jlong ptr, jobject jlistener) { + jobject listener = env->NewGlobalRef(jlistener); + LinphoneCall *call = (LinphoneCall *)ptr; + linphone_call_set_next_video_frame_decoded_callback(call, _next_video_frame_decoded_callback, listener); +} diff --git a/java/common/org/linphone/core/LinphoneCall.java b/java/common/org/linphone/core/LinphoneCall.java index 1d65abaff..ad10b96b1 100644 --- a/java/common/org/linphone/core/LinphoneCall.java +++ b/java/common/org/linphone/core/LinphoneCall.java @@ -26,6 +26,13 @@ import java.util.Vector; */ public interface LinphoneCall { + /** + * LinphoneCall listener + */ + interface LinphoneCallListener { + void onNextVideoFrameDecoded(LinphoneCall call); + } + /** * Linphone call states * @@ -365,6 +372,9 @@ public interface LinphoneCall { * @return LinphoneChatRoom where messaging can take place. */ public LinphoneChatRoom getChatRoom() ; - + /** + * Set the callbacks associated with the LinphoneCall. + */ + void setListener(LinphoneCall.LinphoneCallListener listener); } diff --git a/java/impl/org/linphone/core/LinphoneCallImpl.java b/java/impl/org/linphone/core/LinphoneCallImpl.java index 10b3575df..f04ce86d8 100644 --- a/java/impl/org/linphone/core/LinphoneCallImpl.java +++ b/java/impl/org/linphone/core/LinphoneCallImpl.java @@ -44,6 +44,7 @@ class LinphoneCallImpl implements LinphoneCall { private native float getCurrentQuality(long nativePtr); private native float getAverageQuality(long nativePtr); private native boolean mediaInProgress(long nativePtr); + private native void setListener(long ptr, LinphoneCallListener listener); /* * This method must always be called from JNI, nothing else. @@ -261,4 +262,8 @@ class LinphoneCallImpl implements LinphoneCall { return new LinphoneChatRoomImpl(getChatRoom(nativePtr)); } + @Override + public void setListener(LinphoneCallListener listener) { + setListener(nativePtr, listener); + } }