androidmedia: Allow the application to provide the Java VM
authorSebastian Dröge <sebastian@centricular.com>
Thu, 18 Jun 2015 12:38:04 +0000 (14:38 +0200)
committerSebastian Dröge <sebastian@centricular.com>
Thu, 18 Jun 2015 12:38:04 +0000 (14:38 +0200)
In JNI_OnLoad() we will already get the Java VM passed and could
just directly use that. gstreamer_android-1.0.c will now provide
this to us.

Reason for this is that apparently not all Android system are
providing the JNI functions to get the currently running Java VMs, so
we would fail to get. With this we will always be able to get the Java
VM on such systems.

sys/androidmedia/gstjniutils.c
sys/androidmedia/gstjniutils.h

index 1583e147250747bdb0882db18e454633c93ba776..b21ae51e3525e903dfcdfc2949b71e41c59b1e57 100644 (file)
@@ -628,6 +628,11 @@ gst_amc_jni_initialize_java_vm (void)
   jsize n_vms;
   gint ret;
 
+  if (java_vm) {
+    GST_DEBUG ("Java VM already provided by the application");
+    return TRUE;
+  }
+
   /* Returns TRUE if we can safely
    * a) get the current VMs and
    * b) start a VM if none is started yet
@@ -757,6 +762,14 @@ gst_amc_jni_initialize_internal (gpointer data)
   return gst_amc_jni_initialize_java_vm ()? GINT_TO_POINTER (1) : NULL;
 }
 
+/* Allow the application to set the Java VM */
+void
+gst_amc_jni_set_java_vm (JavaVM * vm)
+{
+  GST_DEBUG ("Application provides Java VM %p", vm);
+  java_vm = vm;
+}
+
 gboolean
 gst_amc_jni_initialize (void)
 {
index ef0f14b0b58bed3d4407f96f3fd2fbebc1f20f28..a6bc68ac22fb9b6c1147a959fccbed844ce4ccf1 100644 (file)
@@ -99,6 +99,8 @@ void gst_amc_jni_set_error                   (JNIEnv * env,
                                               gint code,
                                               const gchar * format, ...);
 
+void gst_amc_jni_set_java_vm                 (JavaVM *java_vm);
+
 gboolean gst_amc_jni_initialize              (void);
 
 gboolean gst_amc_jni_is_vm_started           (void);