diff options
author | Matthieu Bouron <matthieu.bouron@gmail.com> | 2015-04-13 23:40:43 +0200 |
---|---|---|
committer | Sebastian Dröge <sebastian@centricular.com> | 2015-05-04 09:39:42 +0200 |
commit | 7222aa4529c4066b771d2fa0a25f56f59df56e53 (patch) | |
tree | 9cb9e1e14cc7a116777d687c72bd7d1b7e33fc07 /data/ndk-build | |
parent | fd7f655c132c07e6a34cad04f8caf0567448c818 (diff) |
gst-android: Add gst_android_get_{context|class_loader} functions
https://bugzilla.gnome.org/show_bug.cgi?id=748688
Diffstat (limited to 'data/ndk-build')
-rw-r--r-- | data/ndk-build/gstreamer_android-1.0.c.in | 82 |
1 files changed, 82 insertions, 0 deletions
diff --git a/data/ndk-build/gstreamer_android-1.0.c.in b/data/ndk-build/gstreamer_android-1.0.c.in index fee27e45..d1a9f796 100644 --- a/data/ndk-build/gstreamer_android-1.0.c.in +++ b/data/ndk-build/gstreamer_android-1.0.c.in @@ -3,6 +3,8 @@ #include <gio/gio.h> #include <android/log.h> +static jobject _context = NULL; +static jobject _class_loader = NULL; static GstClockTime _priv_gst_info_start_time; #define GST_G_IO_MODULE_DECLARE(name) \ @@ -359,6 +361,59 @@ get_application_dirs (JNIEnv * env, jobject context, gchar ** cache_dir, return TRUE; } +jobject +gst_android_get_application_context () +{ + return _context; +} + +jobject +gst_android_get_application_class_loader () +{ + return _class_loader; +} + +static gboolean +init (JNIEnv *env, jobject context) +{ + jclass context_cls = NULL; + jmethodID get_class_loader_id = 0; + + jobject class_loader = NULL; + + context_cls = (*env)->GetObjectClass (env, context); + if (!context_cls) { + return FALSE; + } + + get_class_loader_id = (*env)->GetMethodID (env, context_cls, + "getClassLoader", "()Ljava/lang/ClassLoader;"); + if ((*env)->ExceptionCheck (env)) { + (*env)->ExceptionDescribe (env); + (*env)->ExceptionClear (env); + return FALSE; + } + + class_loader = (*env)->CallObjectMethod (env, context, get_class_loader_id); + if ((*env)->ExceptionCheck (env)) { + (*env)->ExceptionDescribe (env); + (*env)->ExceptionClear (env); + return FALSE; + } + + if (_context) { + (*env)->DeleteGlobalRef (env, _context); + } + _context = (*env)->NewGlobalRef (env, context); + + if (_class_loader) { + (*env)->DeleteGlobalRef (env, _class_loader); + } + _class_loader = (*env)->NewGlobalRef (env, class_loader); + + return TRUE; +} + static void gst_android_init (JNIEnv * env, jobject gstreamer, jobject context) { @@ -367,6 +422,11 @@ gst_android_init (JNIEnv * env, jobject gstreamer, jobject context) gchar *registry; GError *error = NULL; + if (!init (env, context)) { + __android_log_print (ANDROID_LOG_INFO, "GStreamer", + "GStreamer failed to initialize"); + } + if (gst_is_initialized ()) { __android_log_print (ANDROID_LOG_INFO, "GStreamer", "GStreamer already initialized"); @@ -469,3 +529,25 @@ JNI_OnLoad (JavaVM * vm, void * reserved) return JNI_VERSION_1_4; } + +void +JNI_OnUnload (JavaVM * vm, void * reversed) +{ + JNIEnv *env = NULL; + + if ((*vm)->GetEnv (vm, (void **) &env, JNI_VERSION_1_4) != JNI_OK) { + __android_log_print (ANDROID_LOG_ERROR, "GStreamer", + "Could not retrieve JNIEnv"); + return; + } + + if (_context) { + (*env)->DeleteGlobalRef (env, _context); + _context = NULL; + } + + if (_class_loader) { + (*env)->DeleteGlobalRef (env, _class_loader); + _class_loader = NULL; + } +} |