android: get JavaVM* from JNI_OnLoad
authorThomas Guillem <thomas@gllm.fr>
Tue, 23 Feb 2016 15:16:28 +0000 (16:16 +0100)
committerThomas Guillem <thomas@gllm.fr>
Wed, 24 Feb 2016 08:47:48 +0000 (09:47 +0100)
And set the JavaVM* in a libvlc var option.

This will allow android modules to access a JNIEnv* even when the parent is a
not a libvlc_media_player. This will be used for the android Keystore module
for example.

Furthermore, this simplify the libvlc API when setting an android context.

include/vlc/libvlc_media_player.h
lib/media_player.c
src/Makefile.am
src/android/specific.c [new file with mode: 0644]

index f92ca11..f384dcb 100644 (file)
@@ -548,13 +548,11 @@ LIBVLC_API void *libvlc_media_player_get_hwnd ( libvlc_media_player_t *p_mi );
  * \version LibVLC 3.0.0 and later.
  *
  * \param p_mi the media player
- * \param p_jvm the Java VM of the android process.
  * \param p_awindow_handler org.videolan.libvlc.IAWindowNativeHandler jobject
  *        implemented by the org.videolan.libvlc.MediaPlayer class from the
  *        libvlc-android project.
  */
 LIBVLC_API void libvlc_media_player_set_android_context( libvlc_media_player_t *p_mi,
-                                                         void *p_jvm,
                                                          void *p_awindow_handler );
 
 /**
index 58b2de9..b278c6f 100644 (file)
@@ -593,7 +593,6 @@ libvlc_media_player_new( libvlc_instance_t *instance )
     var_Create (mp, "drawable-nsobject", VLC_VAR_ADDRESS);
 #endif
 #ifdef __ANDROID__
-    var_Create (mp, "android-jvm", VLC_VAR_ADDRESS);
     var_Create (mp, "drawable-androidwindow", VLC_VAR_ADDRESS);
 #endif
 #ifdef HAVE_EVAS
@@ -1172,15 +1171,13 @@ void *libvlc_media_player_get_hwnd( libvlc_media_player_t *p_mi )
  * set_android_context
  **************************************************************************/
 void libvlc_media_player_set_android_context( libvlc_media_player_t *p_mi,
-                                              void *p_jvm,
                                               void *p_awindow_handler )
 {
     assert (p_mi != NULL);
 #ifdef __ANDROID__
-    var_SetAddress (p_mi, "android-jvm", p_jvm);
     var_SetAddress (p_mi, "drawable-androidwindow", p_awindow_handler);
 #else
-    (void) p_jvm; (void) p_awindow_handler;
+    (void) p_awindow_handler;
     libvlc_printerr ("can't set android context: ANDROID build required");
     assert(false);
     var_SetString (p_mi, "vout", "none");
index c21dd78..5ee185f 100644 (file)
@@ -269,7 +269,7 @@ SOURCES_libvlc_android = \
        posix/timer.c \
        posix/linux_cpu.c \
        posix/linux_specific.c \
-       posix/specific.c \
+       android/specific.c \
        posix/rand.c \
        $(NULL)
 
diff --git a/src/android/specific.c b/src/android/specific.c
new file mode 100644 (file)
index 0000000..bd4844e
--- /dev/null
@@ -0,0 +1,64 @@
+/*****************************************************************************
+ * specific.c: stubs for Android OS-specific initialization
+ *****************************************************************************
+ * Copyright © 2016 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.
+ *****************************************************************************/
+
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include <assert.h>
+
+#include <vlc_common.h>
+#include "../libvlc.h"
+
+#include <jni.h>
+
+static JavaVM *s_jvm = NULL;
+
+/* This function is called when the libvlcore dynamic library is loaded via the
+ * java.lang.System.loadLibrary method. Therefore, s_jvm will be already set
+ * when libvlc_InternalInit is called. */
+jint
+JNI_OnLoad(JavaVM *vm, void *reserved)
+{
+    (void) reserved;
+    s_jvm = vm;
+    return JNI_VERSION_1_2;
+}
+
+void
+JNI_OnUnload(JavaVM* vm, void* reserved)
+{
+    (void) vm;
+    (void) reserved;
+}
+
+void
+system_Init(void)
+{
+}
+
+void
+system_Configure(libvlc_int_t *p_libvlc, int i_argc, const char *const pp_argv[])
+{
+    (void)i_argc; (void)pp_argv;
+    assert(s_jvm != NULL);
+    var_Create(p_libvlc, "android-jvm", VLC_VAR_ADDRESS);
+    var_SetAddress(p_libvlc, "android-jvm", s_jvm);
+}