[Android] JNI vout: wait for the surface to be attached so as to return a valid surface to the vout.
Adrien Maglo
git at videolan.org
Fri Nov 8 14:14:17 CET 2013
vlc-ports/android | branch: master | Adrien Maglo <magsoft at videolan.org> | Wed Nov 6 15:49:29 2013 +0100| [3bf343d98d83f0e94c89169426590eca58cb0133] | committer: Adrien Maglo
JNI vout: wait for the surface to be attached so as to return a valid surface to the vout.
> http://git.videolan.org/gitweb.cgi/vlc-ports/android.git/?a=commit;h=3bf343d98d83f0e94c89169426590eca58cb0133
---
vlc-android/jni/libvlcjni.c | 3 +++
vlc-android/jni/vout.c | 8 ++++++++
2 files changed, 11 insertions(+)
diff --git a/vlc-android/jni/libvlcjni.c b/vlc-android/jni/libvlcjni.c
index 29ffcb9..03660ff 100644
--- a/vlc-android/jni/libvlcjni.c
+++ b/vlc-android/jni/libvlcjni.c
@@ -103,6 +103,7 @@ static jobject eventHandlerInstance = NULL;
/** vout lock declared in vout.c */
extern pthread_mutex_t vout_android_lock;
+extern pthread_cond_t vout_android_surf_attached;
static void vlc_event_callback(const libvlc_event_t *ev, void *data)
{
@@ -193,6 +194,7 @@ jint JNI_OnLoad(JavaVM *vm, void *reserved)
myVm = vm;
pthread_mutex_init(&vout_android_lock, NULL);
+ pthread_cond_init(&vout_android_surf_attached, NULL);
LOGD("JNI interface loaded.");
return JNI_VERSION_1_2;
@@ -200,6 +202,7 @@ jint JNI_OnLoad(JavaVM *vm, void *reserved)
void JNI_OnUnload(JavaVM* vm, void* reserved) {
pthread_mutex_destroy(&vout_android_lock);
+ pthread_cond_destroy(&vout_android_surf_attached);
}
// FIXME: use atomics
diff --git a/vlc-android/jni/vout.c b/vlc-android/jni/vout.c
index 777d7d4..d32ece8 100644
--- a/vlc-android/jni/vout.c
+++ b/vlc-android/jni/vout.c
@@ -27,17 +27,22 @@
extern JavaVM *myVm;
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;
void *jni_LockAndGetAndroidSurface() {
pthread_mutex_lock(&vout_android_lock);
+ while (vout_android_surf == NULL)
+ pthread_cond_wait(&vout_android_surf_attached, &vout_android_lock);
return vout_android_surf;
}
jobject jni_LockAndGetAndroidJavaSurface() {
pthread_mutex_lock(&vout_android_lock);
+ while (vout_android_java_surf == NULL)
+ pthread_cond_wait(&vout_android_surf_attached, &vout_android_lock);
return vout_android_java_surf;
}
@@ -63,6 +68,7 @@ void jni_SetAndroidSurfaceSize(int width, int height, int visible_width, int vis
}
void Java_org_videolan_libvlc_LibVLC_attachSurface(JNIEnv *env, jobject thiz, jobject surf, jobject gui, jint width, jint height) {
+ pthread_mutex_lock(&vout_android_lock);
jclass clz;
jfieldID fid;
@@ -86,6 +92,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);
+ pthread_cond_signal(&vout_android_surf_attached);
+ pthread_mutex_unlock(&vout_android_lock);
}
void Java_org_videolan_libvlc_LibVLC_detachSurface(JNIEnv *env, jobject thiz) {
More information about the Android
mailing list