[Android] libvlcjni: move jni helpers to util

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:00:26 2013 +0200| [d12dad60b01557191d13d17e5a26c4c470b801d3] | committer: Sébastien Toque

libvlcjni: move jni helpers to util

> http://git.videolan.org/gitweb.cgi/vlc-ports/android.git/?a=commit;h=d12dad60b01557191d13d17e5a26c4c470b801d3
---

 vlc-android/jni/libvlcjni-util.c |   76 ++++++++++++++++++++++++++++++++++++++
 vlc-android/jni/libvlcjni.c      |   76 --------------------------------------
 vlc-android/jni/utils.h          |   12 ++++++
 3 files changed, 88 insertions(+), 76 deletions(-)

diff --git a/vlc-android/jni/libvlcjni-util.c b/vlc-android/jni/libvlcjni-util.c
index 12920d8..37e880b 100644
--- a/vlc-android/jni/libvlcjni-util.c
+++ b/vlc-android/jni/libvlcjni-util.c
@@ -39,6 +39,82 @@ static bool buffer_logging;
 /** Unique Java VM instance, as defined in libvlcjni.c */
 extern JavaVM *myVm;
 
+jint getInt(JNIEnv *env, jobject thiz, const char* field) {
+    jclass clazz = (*env)->GetObjectClass(env, thiz);
+    jfieldID fieldMP = (*env)->GetFieldID(env, clazz,
+                                          field, "I");
+    return (*env)->GetIntField(env, thiz, fieldMP);
+}
+void setInt(JNIEnv *env, jobject item, const char* field, jint value) {
+    jclass cls;
+    jfieldID fieldId;
+
+    /* Get a reference to item's class */
+    cls = (*env)->GetObjectClass(env, item);
+
+    /* Look for the instance field s in cls */
+    fieldId = (*env)->GetFieldID(env, cls, field, "I");
+    if (fieldId == NULL)
+        return;
+
+    (*env)->SetIntField(env, item, fieldId, value);
+}
+
+jlong getLong(JNIEnv *env, jobject thiz, const char* field) {
+    jclass clazz = (*env)->GetObjectClass(env, thiz);
+    jfieldID fieldMP = (*env)->GetFieldID(env, clazz,
+                                          field, "J");
+    return (*env)->GetLongField(env, thiz, fieldMP);
+}
+void setLong(JNIEnv *env, jobject item, const char* field, jlong value) {
+    jclass cls;
+    jfieldID fieldId;
+
+    /* Get a reference to item's class */
+    cls = (*env)->GetObjectClass(env, item);
+
+    /* Look for the instance field s in cls */
+    fieldId = (*env)->GetFieldID(env, cls, field, "J");
+    if (fieldId == NULL)
+        return;
+
+    (*env)->SetLongField(env, item, fieldId, value);
+}
+
+void setFloat(JNIEnv *env, jobject item, const char* field, jfloat value) {
+    jclass cls;
+    jfieldID fieldId;
+
+    /* Get a reference to item's class */
+    cls = (*env)->GetObjectClass(env, item);
+
+    /* Look for the instance field s in cls */
+    fieldId = (*env)->GetFieldID(env, cls, field, "F");
+    if (fieldId == NULL)
+        return;
+
+    (*env)->SetFloatField(env, item, fieldId, value);
+}
+void setString(JNIEnv *env, jobject item, const char* field, const char* text) {
+    jclass cls;
+    jfieldID fieldId;
+    jstring jstr;
+
+    /* Get a reference to item's class */
+    cls = (*env)->GetObjectClass(env, item);
+
+    /* Look for the instance field s in cls */
+    fieldId = (*env)->GetFieldID(env, cls, field, "Ljava/lang/String;");
+    if (fieldId == NULL)
+        return;
+
+    /* Create a new string and overwrite the instance field */
+    jstr = (*env)->NewStringUTF(env, text);
+    if (jstr == NULL)
+        return;
+    (*env)->SetObjectField(env, item, fieldId, jstr);
+}
+
 static void debug_buffer_log(void *data, int level, const char *fmt, va_list ap)
 {
     bool isAttached = false;
diff --git a/vlc-android/jni/libvlcjni.c b/vlc-android/jni/libvlcjni.c
index a98f9d0..e122176 100644
--- a/vlc-android/jni/libvlcjni.c
+++ b/vlc-android/jni/libvlcjni.c
@@ -42,82 +42,6 @@
 #define LOG_TAG "VLC/JNI/main"
 #include "log.h"
 
-static jint getInt(JNIEnv *env, jobject thiz, const char* field) {
-    jclass clazz = (*env)->GetObjectClass(env, thiz);
-    jfieldID fieldMP = (*env)->GetFieldID(env, clazz,
-                                          field, "I");
-    return (*env)->GetIntField(env, thiz, fieldMP);
-}
-static void setInt(JNIEnv *env, jobject item, const char* field, jint value) {
-    jclass cls;
-    jfieldID fieldId;
-
-    /* Get a reference to item's class */
-    cls = (*env)->GetObjectClass(env, item);
-
-    /* Look for the instance field s in cls */
-    fieldId = (*env)->GetFieldID(env, cls, field, "I");
-    if (fieldId == NULL)
-        return;
-
-    (*env)->SetIntField(env, item, fieldId, value);
-}
-
-static jlong getLong(JNIEnv *env, jobject thiz, const char* field) {
-    jclass clazz = (*env)->GetObjectClass(env, thiz);
-    jfieldID fieldMP = (*env)->GetFieldID(env, clazz,
-                                          field, "J");
-    return (*env)->GetLongField(env, thiz, fieldMP);
-}
-static void setLong(JNIEnv *env, jobject item, const char* field, jlong value) {
-    jclass cls;
-    jfieldID fieldId;
-
-    /* Get a reference to item's class */
-    cls = (*env)->GetObjectClass(env, item);
-
-    /* Look for the instance field s in cls */
-    fieldId = (*env)->GetFieldID(env, cls, field, "J");
-    if (fieldId == NULL)
-        return;
-
-    (*env)->SetLongField(env, item, fieldId, value);
-}
-
-static void setFloat(JNIEnv *env, jobject item, const char* field, jfloat value) {
-    jclass cls;
-    jfieldID fieldId;
-
-    /* Get a reference to item's class */
-    cls = (*env)->GetObjectClass(env, item);
-
-    /* Look for the instance field s in cls */
-    fieldId = (*env)->GetFieldID(env, cls, field, "F");
-    if (fieldId == NULL)
-        return;
-
-    (*env)->SetFloatField(env, item, fieldId, value);
-}
-static void setString(JNIEnv *env, jobject item, const char* field, const char* text) {
-    jclass cls;
-    jfieldID fieldId;
-    jstring jstr;
-
-    /* Get a reference to item's class */
-    cls = (*env)->GetObjectClass(env, item);
-
-    /* Look for the instance field s in cls */
-    fieldId = (*env)->GetFieldID(env, cls, field, "Ljava/lang/String;");
-    if (fieldId == NULL)
-        return;
-
-    /* Create a new string and overwrite the instance field */
-    jstr = (*env)->NewStringUTF(env, text);
-    if (jstr == NULL)
-        return;
-    (*env)->SetObjectField(env, item, fieldId, jstr);
-}
-
 struct length_change_monitor {
     pthread_mutex_t doneMutex;
     pthread_cond_t doneCondVar;
diff --git a/vlc-android/jni/utils.h b/vlc-android/jni/utils.h
index 31120bd..59644a1 100644
--- a/vlc-android/jni/utils.h
+++ b/vlc-android/jni/utils.h
@@ -23,6 +23,18 @@
 
 libvlc_media_t *new_media(jlong instance, JNIEnv *env, jobject thiz, jstring fileLocation, bool noOmx, bool noVideo);
 
+jint getInt(JNIEnv *env, jobject thiz, const char* field);
+
+void setInt(JNIEnv *env, jobject item, const char* field, jint value);
+
+jlong getLong(JNIEnv *env, jobject thiz, const char* field);
+
+void setLong(JNIEnv *env, jobject item, const char* field, jlong value);
+
+void setFloat(JNIEnv *env, jobject item, const char* field, jfloat value);
+
+void setString(JNIEnv *env, jobject item, const char* field, const char* text);
+
 void debug_log(void *data, int level, const libvlc_log_t *ctx, const char *fmt, va_list ap);
 
 #endif // LIBVLCJNI_UTILS_H



More information about the Android mailing list