[Android] [PATCH 2/2] jni: add functions in order to pass events to the core.
Felix Abecassis
felix.abecassis at gmail.com
Tue Jan 7 16:27:50 CET 2014
---
vlc-android/jni/vout.c | 32 ++++++++++++++++++++++++++++++++
1 file changed, 32 insertions(+)
diff --git a/vlc-android/jni/vout.c b/vlc-android/jni/vout.c
index 51eace1..94dcf4b 100644
--- a/vlc-android/jni/vout.c
+++ b/vlc-android/jni/vout.c
@@ -26,12 +26,24 @@
/** Unique Java VM instance, as defined in libvlcjni.c */
extern JavaVM *myVm;
+/* Warning: do not explicitly set the values of the enum fields */
+enum
+{
+ VOUT_ANDROID_EVENT_NONE = 0,
+ VOUT_ANDROID_EVENT_SURFACE_ATTACHED,
+ VOUT_ANDROID_EVENT_SURFACE_DETACHED,
+ VOUT_ANDROID_EVENT_COUNT
+};
+
pthread_mutex_t vout_android_lock;
pthread_cond_t vout_android_surf_attached;
static void *vout_android_surf = NULL;
static void *vout_android_gui = NULL;
static jobject vout_android_java_surf = NULL;
static jobject vout_android_frame = NULL;
+/* The entry corresponding to an event is set to "true" if this event
+ is currenly active. */
+static bool vout_android_event_active[VOUT_ANDROID_EVENT_COUNT];
void *jni_LockAndGetAndroidSurface() {
pthread_mutex_lock(&vout_android_lock);
@@ -94,6 +106,8 @@ void Java_org_videolan_libvlc_LibVLC_attachSurface(JNIEnv *env, jobject thiz, jo
vout_android_gui = (*env)->NewGlobalRef(env, gui);
vout_android_java_surf = (*env)->NewGlobalRef(env, surf);
vout_android_frame = (*env)->NewGlobalRef(env, frame);
+ vout_android_event_active[VOUT_ANDROID_EVENT_SURFACE_ATTACHED] = true;
+
pthread_cond_signal(&vout_android_surf_attached);
pthread_mutex_unlock(&vout_android_lock);
}
@@ -107,6 +121,8 @@ void Java_org_videolan_libvlc_LibVLC_detachSurface(JNIEnv *env, jobject thiz) {
(*env)->DeleteGlobalRef(env, vout_android_java_surf);
vout_android_gui = NULL;
vout_android_java_surf = NULL;
+ vout_android_event_active[VOUT_ANDROID_EVENT_SURFACE_DETACHED] = true;
+
pthread_mutex_unlock(&vout_android_lock);
}
@@ -125,3 +141,19 @@ void jni_GetFrameDimensions(int *width, int *height)
(*myVm)->DetachCurrentThread(myVm);
}
+
+bool jni_IsEventSurfaceAttached() {
+ if (vout_android_event_active[VOUT_ANDROID_EVENT_SURFACE_ATTACHED]) {
+ vout_android_event_active[VOUT_ANDROID_EVENT_SURFACE_ATTACHED] = false;
+ return true;
+ }
+ return false;
+}
+
+bool jni_IsEventSurfaceDetached() {
+ if (vout_android_event_active[VOUT_ANDROID_EVENT_SURFACE_DETACHED]) {
+ vout_android_event_active[VOUT_ANDROID_EVENT_SURFACE_DETACHED] = false;
+ return true;
+ }
+ return false;
+}
--
1.8.3.2
More information about the Android
mailing list