[vlc-commits] android: get JavaVM* from JNI_OnLoad

Thomas Guillem git at videolan.org
Wed Feb 24 09:37:00 CET 2016


vlc | branch: master | Thomas Guillem <thomas at gllm.fr> | Tue Feb 23 16:16:28 2016 +0100| [38463fd56495a56be4abf4ff435715161677d344] | committer: Thomas Guillem

android: get JavaVM* from JNI_OnLoad

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.

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=38463fd56495a56be4abf4ff435715161677d344
---

 include/vlc/libvlc_media_player.h |    2 --
 lib/media_player.c                |    3 --
 src/Makefile.am                   |    2 +-
 src/android/specific.c            |   64 +++++++++++++++++++++++++++++++++++++
 4 files changed, 65 insertions(+), 6 deletions(-)

diff --git a/include/vlc/libvlc_media_player.h b/include/vlc/libvlc_media_player.h
index f92ca11..f384dcb 100644
--- a/include/vlc/libvlc_media_player.h
+++ b/include/vlc/libvlc_media_player.h
@@ -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 );
 
 /**
diff --git a/lib/media_player.c b/lib/media_player.c
index 58b2de9..53bc374 100644
--- a/lib/media_player.c
+++ b/lib/media_player.c
@@ -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,12 +1171,10 @@ 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;
diff --git a/src/Makefile.am b/src/Makefile.am
index c21dd78..5ee185f 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -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
index 0000000..bd4844e
--- /dev/null
+++ b/src/android/specific.c
@@ -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);
+}



More information about the vlc-commits mailing list