[Android] libvlcjni: move android surface stuff to vout.c
Sébastien Toque
git at videolan.org
Sun Jul 28 12:04:36 CEST 2013
vlc-ports/android | branch: master | Sébastien Toque <xilasz at gmail.com> | Sun Jul 28 11:46:11 2013 +0200| [c1336a966d517f6b2ef041fc01abe08589e36baf] | committer: Sébastien Toque
libvlcjni: move android surface stuff to vout.c
> http://git.videolan.org/gitweb.cgi/vlc-ports/android.git/?a=commit;h=c1336a966d517f6b2ef041fc01abe08589e36baf
---
vlc-android/jni/Android.mk | 2 +-
vlc-android/jni/libvlcjni.c | 72 +------------------------------
vlc-android/jni/vout.c | 98 +++++++++++++++++++++++++++++++++++++++++++
3 files changed, 101 insertions(+), 71 deletions(-)
diff --git a/vlc-android/jni/Android.mk b/vlc-android/jni/Android.mk
index 12c9fb0..55ea452 100644
--- a/vlc-android/jni/Android.mk
+++ b/vlc-android/jni/Android.mk
@@ -3,7 +3,7 @@ include $(CLEAR_VARS)
LOCAL_MODULE := libvlcjni
-LOCAL_SRC_FILES := libvlcjni.c libvlcjni-util.c libvlcjni-track.c aout.c
+LOCAL_SRC_FILES := libvlcjni.c libvlcjni-util.c libvlcjni-track.c aout.c vout.c
LOCAL_SRC_FILES += thumbnailer.c pthread-condattr.c pthread-rwlocks.c pthread-once.c eventfd.c sem.c
LOCAL_SRC_FILES += pipe2.c
LOCAL_SRC_FILES += wchar/wcpcpy.c
diff --git a/vlc-android/jni/libvlcjni.c b/vlc-android/jni/libvlcjni.c
index 179c798..85e020d 100644
--- a/vlc-android/jni/libvlcjni.c
+++ b/vlc-android/jni/libvlcjni.c
@@ -103,41 +103,8 @@ JavaVM *myVm;
static jobject eventHandlerInstance = NULL;
-static pthread_mutex_t vout_android_lock;
-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);
- return vout_android_surf;
-}
-
-jobject jni_LockAndGetAndroidJavaSurface() {
- pthread_mutex_lock(&vout_android_lock);
- return vout_android_java_surf;
-}
-
-void jni_UnlockAndroidSurface() {
- pthread_mutex_unlock(&vout_android_lock);
-}
-
-void jni_SetAndroidSurfaceSize(int width, int height, int sar_num, int sar_den)
-{
- if (vout_android_gui == NULL)
- return;
-
- JNIEnv *p_env;
-
- (*myVm)->AttachCurrentThread (myVm, &p_env, NULL);
- jclass cls = (*p_env)->GetObjectClass (p_env, vout_android_gui);
- jmethodID methodId = (*p_env)->GetMethodID (p_env, cls, "setSurfaceSize", "(IIII)V");
-
- (*p_env)->CallVoidMethod (p_env, vout_android_gui, methodId, width, height, sar_num, sar_den);
-
- (*p_env)->DeleteLocalRef(p_env, cls);
- (*myVm)->DetachCurrentThread (myVm);
-}
+/** vout lock declared in vout.c */
+extern pthread_mutex_t vout_android_lock;
static void vlc_event_callback(const libvlc_event_t *ev, void *data)
{
@@ -236,41 +203,6 @@ void JNI_OnUnload(JavaVM* vm, void* reserved) {
pthread_mutex_destroy(&vout_android_lock);
}
-void Java_org_videolan_libvlc_LibVLC_attachSurface(JNIEnv *env, jobject thiz, jobject surf, jobject gui, jint width, jint height) {
- jclass clz;
- jfieldID fid;
-
- pthread_mutex_lock(&vout_android_lock);
- clz = (*env)->GetObjectClass(env, surf);
- fid = (*env)->GetFieldID(env, clz, "mSurface", "I");
- if (fid == NULL) {
- jthrowable exp = (*env)->ExceptionOccurred(env);
- if (exp) {
- (*env)->DeleteLocalRef(env, exp);
- (*env)->ExceptionClear(env);
- }
- fid = (*env)->GetFieldID(env, clz, "mNativeSurface", "I");
- }
- vout_android_surf = (void*)(*env)->GetIntField(env, surf, fid);
- (*env)->DeleteLocalRef(env, clz);
-
- vout_android_gui = (*env)->NewGlobalRef(env, gui);
- vout_android_java_surf = (*env)->NewGlobalRef(env, surf);
- pthread_mutex_unlock(&vout_android_lock);
-}
-
-void Java_org_videolan_libvlc_LibVLC_detachSurface(JNIEnv *env, jobject thiz) {
- pthread_mutex_lock(&vout_android_lock);
- vout_android_surf = NULL;
- if (vout_android_gui != NULL)
- (*env)->DeleteGlobalRef(env, vout_android_gui);
- if (vout_android_java_surf != NULL)
- (*env)->DeleteGlobalRef(env, vout_android_java_surf);
- vout_android_gui = NULL;
- vout_android_java_surf = NULL;
- pthread_mutex_unlock(&vout_android_lock);
-}
-
// FIXME: use atomics
static bool verbosity;
diff --git a/vlc-android/jni/vout.c b/vlc-android/jni/vout.c
new file mode 100644
index 0000000..0dd8058
--- /dev/null
+++ b/vlc-android/jni/vout.c
@@ -0,0 +1,98 @@
+/*****************************************************************************
+ * vout.c
+ *****************************************************************************
+ * Copyright © 2010-2013 VLC authors and VideoLAN
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 2.1 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ *****************************************************************************/
+
+#include <vlc/vlc.h>
+#include <vlc_common.h>
+
+#include <jni.h>
+
+/** Unique Java VM instance, as defined in libvlcjni.c */
+extern JavaVM *myVm;
+
+pthread_mutex_t vout_android_lock;
+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);
+ return vout_android_surf;
+}
+
+jobject jni_LockAndGetAndroidJavaSurface() {
+ pthread_mutex_lock(&vout_android_lock);
+ return vout_android_java_surf;
+}
+
+void jni_UnlockAndroidSurface() {
+ pthread_mutex_unlock(&vout_android_lock);
+}
+
+void jni_SetAndroidSurfaceSize(int width, int height, int sar_num, int sar_den)
+{
+ if (vout_android_gui == NULL)
+ return;
+
+ JNIEnv *p_env;
+
+ (*myVm)->AttachCurrentThread (myVm, &p_env, NULL);
+ jclass cls = (*p_env)->GetObjectClass (p_env, vout_android_gui);
+ jmethodID methodId = (*p_env)->GetMethodID (p_env, cls, "setSurfaceSize", "(IIII)V");
+
+ (*p_env)->CallVoidMethod (p_env, vout_android_gui, methodId, width, height, sar_num, sar_den);
+
+ (*p_env)->DeleteLocalRef(p_env, cls);
+ (*myVm)->DetachCurrentThread (myVm);
+}
+
+void Java_org_videolan_libvlc_LibVLC_attachSurface(JNIEnv *env, jobject thiz, jobject surf, jobject gui, jint width, jint height) {
+ jclass clz;
+ jfieldID fid;
+
+ pthread_mutex_lock(&vout_android_lock);
+ clz = (*env)->GetObjectClass(env, surf);
+ fid = (*env)->GetFieldID(env, clz, "mSurface", "I");
+ if (fid == NULL) {
+ jthrowable exp = (*env)->ExceptionOccurred(env);
+ if (exp) {
+ (*env)->DeleteLocalRef(env, exp);
+ (*env)->ExceptionClear(env);
+ }
+ fid = (*env)->GetFieldID(env, clz, "mNativeSurface", "I");
+ }
+ vout_android_surf = (void*)(*env)->GetIntField(env, surf, fid);
+ (*env)->DeleteLocalRef(env, clz);
+
+ vout_android_gui = (*env)->NewGlobalRef(env, gui);
+ vout_android_java_surf = (*env)->NewGlobalRef(env, surf);
+ pthread_mutex_unlock(&vout_android_lock);
+}
+
+void Java_org_videolan_libvlc_LibVLC_detachSurface(JNIEnv *env, jobject thiz) {
+ pthread_mutex_lock(&vout_android_lock);
+ vout_android_surf = NULL;
+ if (vout_android_gui != NULL)
+ (*env)->DeleteGlobalRef(env, vout_android_gui);
+ if (vout_android_java_surf != NULL)
+ (*env)->DeleteGlobalRef(env, vout_android_java_surf);
+ vout_android_gui = NULL;
+ vout_android_java_surf = NULL;
+ pthread_mutex_unlock(&vout_android_lock);
+}
More information about the Android
mailing list