Commit b775dbba authored by Thomas Guillem's avatar Thomas Guillem

build: fix ODR violation

This commit fixes the regression introduced by
b9df5331 that switched to the c++ static
runtime and caused exceptions to be uncaught.

As https://developer.android.com/ndk/guides/cpp-support.html#static_runtimes
explains it, one process should *NEVER* link with more than one shared
libraries that link with the c++ static library.

To fix this issue: libmla and libvlc are now static and linked together as
libvlcjni.so with the c++ static library.
parent 94885318
...@@ -408,13 +408,8 @@ NDK_LIB_DIR="${NDK_TOOLCHAIN_DIR}/${TARGET_TUPLE}/lib" ...@@ -408,13 +408,8 @@ NDK_LIB_DIR="${NDK_TOOLCHAIN_DIR}/${TARGET_TUPLE}/lib"
if [ "${PLATFORM_SHORT_ARCH}" = "x86_64" -o "${PLATFORM_SHORT_ARCH}" = "mips64" ];then if [ "${PLATFORM_SHORT_ARCH}" = "x86_64" -o "${PLATFORM_SHORT_ARCH}" = "mips64" ];then
NDK_LIB_DIR="${NDK_LIB_DIR}64" NDK_LIB_DIR="${NDK_LIB_DIR}64"
fi fi
NDK_LIB_UNWIND=""
if [ "${ANDROID_ABI}" = "armeabi-v7a" ];then
NDK_LIB_DIR="${NDK_LIB_DIR}/armv7-a"
NDK_LIB_UNWIND="-lunwind"
fi
EXTRA_LDFLAGS="${EXTRA_LDFLAGS} -L${NDK_LIB_DIR} -lc++abi ${NDK_LIB_UNWIND} -lc++_static" EXTRA_LDFLAGS="${EXTRA_LDFLAGS} -L${NDK_LIB_DIR} -lc++abi -lc++_static"
VLC_LDFLAGS="${EXTRA_LDFLAGS}" VLC_LDFLAGS="${EXTRA_LDFLAGS}"
# Release or not? # Release or not?
...@@ -706,45 +701,6 @@ if [ "${CHROME_OS}" != "1" ];then ...@@ -706,45 +701,6 @@ if [ "${CHROME_OS}" != "1" ];then
LIBANW_LIBS="$LIBANW_LIBS libanw.21" LIBANW_LIBS="$LIBANW_LIBS libanw.21"
fi fi
echo "Building NDK"
if [ $ON_WINDOWS -eq 1 ]; then
OSCMD=.cmd
fi
$ANDROID_NDK/ndk-build$OSCMD -C libvlc \
APP_STL="c++_static" \
LOCAL_CPP_FEATURES="rtti exceptions" \
VLC_SRC_DIR="$VLC_SRC_DIR" \
VLC_BUILD_DIR="$VLC_SRC_DIR/$VLC_BUILD_DIR" \
VLC_CONTRIB="$VLC_CONTRIB" \
VLC_CONTRIB_LDFLAGS="$VLC_CONTRIB_LDFLAGS" \
VLC_MODULES="$VLC_MODULES" \
VLC_LDFLAGS="$VLC_LDFLAGS" \
APP_BUILD_SCRIPT=jni/Android.mk \
APP_PLATFORM=android-${ANDROID_API} \
APP_ABI=${ANDROID_ABI} \
TARGET_TUPLE=$TARGET_TUPLE \
NDK_PROJECT_PATH=jni \
NDK_TOOLCHAIN_VERSION=clang \
NDK_DEBUG=${NDK_DEBUG}
checkfail "ndk-build failed for libvlc"
$ANDROID_NDK/ndk-build$OSCMD -C libvlc \
VLC_SRC_DIR="$VLC_SRC_DIR" \
ANDROID_SYS_HEADERS="$ANDROID_SYS_HEADERS" \
LIBIOMX_LIBS="$LIBIOMX_LIBS" \
LIBANW_LIBS="$LIBANW_LIBS" \
APP_BUILD_SCRIPT=private_libs/Android.mk \
APP_PLATFORM=android-${ANDROID_API} \
APP_ABI=${ANDROID_ABI} \
TARGET_TUPLE=$TARGET_TUPLE \
NDK_PROJECT_PATH=private_libs \
NDK_TOOLCHAIN_VERSION=clang
checkfail "ndk-build failed for private libs"
################ ################
# MEDIALIBRARY # # MEDIALIBRARY #
################ ################
...@@ -881,27 +837,61 @@ checkfail "medialibrary: make failed" ...@@ -881,27 +837,61 @@ checkfail "medialibrary: make failed"
cd ${SRC_DIR} cd ${SRC_DIR}
echo -e "ndk-build medialibrary" MEDIALIBRARY_LDLIBS="-L${MEDIALIBRARY_BUILD_DIR}/build-android-$ANDROID_ABI/.libs -lmedialibrary \
MEDIALIBRARY_LDLIBS="-L$SRC_DIR/libvlc/jni/libs/$ANDROID_ABI -lvlc \
-L${MEDIALIBRARY_BUILD_DIR}/build-android-$ANDROID_ABI/.libs -lmedialibrary \
-L$SRC_DIR/vlc/contrib/contrib-android-$TARGET_TUPLE/jpeg/.libs -ljpeg \ -L$SRC_DIR/vlc/contrib/contrib-android-$TARGET_TUPLE/jpeg/.libs -ljpeg \
-L$MEDIALIBRARY_MODULE_DIR/$SQLITE_RELEASE/build-$ANDROID_ABI/.libs -lsqlite3 \ -L$MEDIALIBRARY_MODULE_DIR/$SQLITE_RELEASE/build-$ANDROID_ABI/.libs -lsqlite3"
-L${NDK_LIB_DIR} -lc++abi ${NDK_LIB_UNWIND} -lc++_static"
$ANDROID_NDK/ndk-build -C medialibrary \ if [ $ON_WINDOWS -eq 1 ]; then
OSCMD=.cmd
fi
###########
# LINKING #
###########
echo -e "ndk-build vlc"
$ANDROID_NDK/ndk-build$OSCMD -C libvlc \
APP_STL="c++_static" \ APP_STL="c++_static" \
ANDROID_SYS_HEADERS="$ANDROID_SYS_HEADERS" \ APP_CPPFLAGS="-frtti -fexceptions" \
VLC_SRC_DIR="$VLC_SRC_DIR" \
VLC_BUILD_DIR="$VLC_SRC_DIR/$VLC_BUILD_DIR" \
VLC_CONTRIB="$VLC_CONTRIB" \
VLC_CONTRIB_LDFLAGS="$VLC_CONTRIB_LDFLAGS" \
VLC_MODULES="$VLC_MODULES" \
VLC_LDFLAGS="$VLC_LDFLAGS" \
MEDIALIBRARY_LDLIBS="${MEDIALIBRARY_LDLIBS}" \
MEDIALIBRARY_INCLUDE_DIR=${MEDIALIBRARY_BUILD_DIR}/include \
APP_BUILD_SCRIPT=jni/Android.mk \ APP_BUILD_SCRIPT=jni/Android.mk \
APP_PLATFORM=android-${ANDROID_API} \ APP_PLATFORM=android-${ANDROID_API} \
APP_ABI=${ANDROID_ABI} \ APP_ABI=${ANDROID_ABI} \
LOCAL_CPP_FEATURES="rtti exceptions" \
TARGET_TUPLE=$TARGET_TUPLE \
NDK_PROJECT_PATH=jni \ NDK_PROJECT_PATH=jni \
NDK_TOOLCHAIN_VERSION=clang \ NDK_TOOLCHAIN_VERSION=clang \
NDK_DEBUG=${NDK_DEBUG} \ NDK_DEBUG=${NDK_DEBUG}
MEDIALIBRARY_LDLIBS="${MEDIALIBRARY_LDLIBS}" \
MEDIALIBRARY_INCLUDE_DIR=${MEDIALIBRARY_BUILD_DIR}/include $ANDROID_NDK/ndk-build$OSCMD -C libvlc \
APP_BUILD_SCRIPT=jni/loader/Android.mk \
APP_PLATFORM=android-${ANDROID_API} \
APP_ABI=${ANDROID_ABI} \
NDK_PROJECT_PATH=jni/loader \
NDK_TOOLCHAIN_VERSION=clang
checkfail "ndk-build failed for libvlc"
$ANDROID_NDK/ndk-build$OSCMD -C libvlc \
VLC_SRC_DIR="$VLC_SRC_DIR" \
ANDROID_SYS_HEADERS="$ANDROID_SYS_HEADERS" \
LIBIOMX_LIBS="$LIBIOMX_LIBS" \
LIBANW_LIBS="$LIBANW_LIBS" \
APP_BUILD_SCRIPT=private_libs/Android.mk \
APP_PLATFORM=android-${ANDROID_API} \
APP_ABI=${ANDROID_ABI} \
TARGET_TUPLE=$TARGET_TUPLE \
NDK_PROJECT_PATH=private_libs \
NDK_TOOLCHAIN_VERSION=clang
checkfail "ndk-build failed for private libs"
checkfail "ndk-build failed" checkfail "ndk-build failed"
...@@ -913,4 +903,3 @@ OUT_DBG_DIR=.dbg/${ANDROID_ABI} ...@@ -913,4 +903,3 @@ OUT_DBG_DIR=.dbg/${ANDROID_ABI}
mkdir -p $OUT_DBG_DIR mkdir -p $OUT_DBG_DIR
cp -a libvlc/jni/obj/local/${ANDROID_ABI}/*.so ${OUT_DBG_DIR} cp -a libvlc/jni/obj/local/${ANDROID_ABI}/*.so ${OUT_DBG_DIR}
cp -a libvlc/private_libs/obj/local/${ANDROID_ABI}/*.so ${OUT_DBG_DIR} cp -a libvlc/private_libs/obj/local/${ANDROID_ABI}/*.so ${OUT_DBG_DIR}
cp -a medialibrary/jni/obj/local/${ANDROID_ABI}/*.so ${OUT_DBG_DIR}
...@@ -9,7 +9,7 @@ android { ...@@ -9,7 +9,7 @@ android {
sourceSets { sourceSets {
main { main {
jni.srcDirs = [] // Prevent gradle from building native code with ndk; we have our own Makefile for it. jni.srcDirs = [] // Prevent gradle from building native code with ndk; we have our own Makefile for it.
jniLibs.srcDirs = [ 'jni/libs', 'private_libs/libs' ] // Where generated .so files are placed. jniLibs.srcDirs = [ 'jni/libs', 'jni/loader/libs', 'private_libs/libs' ] // Where generated .so files are placed.
manifest.srcFile 'AndroidManifest.xml' manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src'] java.srcDirs = ['src']
resources.srcDirs = ['src'] resources.srcDirs = ['src']
......
LOCAL_PATH := $(call my-dir) LOCAL_PATH := $(call my-dir)
MEDIALIBRARY_JNI_DIR := $(LOCAL_PATH)/../../medialibrary/jni
# libvlc jni static library
include $(CLEAR_VARS) include $(CLEAR_VARS)
LOCAL_MODULE := libvlc LOCAL_MODULE := vlcjni_static
ARCH=$(APP_ABI) LOCAL_SRC_FILES := libvlcjni.c
LOCAL_SRC_FILES += libvlcjni-modules.c libvlcjni-symbols.c dummy.cpp LOCAL_SRC_FILES += libvlcjni-mediaplayer.c
LOCAL_SRC_FILES += libvlcjni-vlcobject.c
LOCAL_SRC_FILES += libvlcjni-media.c libvlcjni-medialist.c libvlcjni-mediadiscoverer.c
LOCAL_SRC_FILES += libvlcjni-dialog.c
LOCAL_SRC_FILES += thumbnailer.c
LOCAL_SRC_FILES += std_logger.c
LOCAL_C_INCLUDES := $(VLC_SRC_DIR)/include $(MEDIALIBRARY_JNI_DIR) $(LOCAL_PATH)/loader
LOCAL_CFLAGS := -std=c11
include $(BUILD_STATIC_LIBRARY)
# libvlc dynamic library
include $(CLEAR_VARS)
LOCAL_MODULE := vlcjni
LOCAL_SRC_FILES := libvlcjni-modules.c libvlcjni-symbols.c
LOCAL_LDFLAGS := -L$(VLC_CONTRIB)/lib LOCAL_LDFLAGS := -L$(VLC_CONTRIB)/lib
LOCAL_LDLIBS := \ LOCAL_LDLIBS := \
$(VLC_MODULES) \ $(VLC_MODULES) \
...@@ -17,31 +33,13 @@ LOCAL_LDLIBS := \ ...@@ -17,31 +33,13 @@ LOCAL_LDLIBS := \
-lavcodec -lebml \ -lavcodec -lebml \
-llua \ -llua \
-lgcrypt -lgpg-error \ -lgcrypt -lgpg-error \
$(VLC_LDFLAGS) $(MEDIALIBRARY_LDLIBS) \
$(VLC_LDFLAGS) \
-llog
LOCAL_WHOLE_STATIC_LIBRARIES := libvlcjni_static libmla
include $(BUILD_SHARED_LIBRARY) include $(BUILD_SHARED_LIBRARY)
include $(CLEAR_VARS) JNILOADER_INCLUDES := $(LOCAL_PATH)/loader
LOCAL_MODULE := libvlcjni $(call import-add-path, $(MEDIALIBRARY_JNI_DIR))
$(call import-module, .)
LOCAL_SRC_FILES := libvlcjni.c
LOCAL_SRC_FILES += libvlcjni-mediaplayer.c
LOCAL_SRC_FILES += libvlcjni-vlcobject.c
LOCAL_SRC_FILES += libvlcjni-media.c libvlcjni-medialist.c libvlcjni-mediadiscoverer.c
LOCAL_SRC_FILES += libvlcjni-dialog.c
LOCAL_SRC_FILES += thumbnailer.c
LOCAL_SRC_FILES += std_logger.c
LOCAL_LDLIBS := -llog
LOCAL_C_INCLUDES := $(VLC_SRC_DIR)/include
ARCH=$(APP_ABI)
LOCAL_CFLAGS := -std=c11
ifeq ($(ARCH), armeabi-v7a)
LOCAL_CFLAGS += -DHAVE_ARMEABI_V7A
endif
LOCAL_SHARED_LIBRARIES:= libvlc
include $(BUILD_SHARED_LIBRARY)
/* Force ndk build system to link with c++_shared and install it */
...@@ -30,7 +30,7 @@ ...@@ -30,7 +30,7 @@
#include <vlc/vlc.h> #include <vlc/vlc.h>
#include <jni.h> #include "jniloader.h"
#include <android/api-level.h> #include <android/api-level.h>
...@@ -40,8 +40,6 @@ ...@@ -40,8 +40,6 @@
struct fields fields; struct fields fields;
#define VLC_JNI_VERSION JNI_VERSION_1_2
#define THREAD_NAME "libvlcjni" #define THREAD_NAME "libvlcjni"
JNIEnv *jni_get_env(const char *name); JNIEnv *jni_get_env(const char *name);
...@@ -99,15 +97,10 @@ JNIEnv *jni_get_env(const char *name) ...@@ -99,15 +97,10 @@ JNIEnv *jni_get_env(const char *name)
static std_logger *p_std_logger = NULL; static std_logger *p_std_logger = NULL;
#endif #endif
jint JNI_OnLoad(JavaVM *vm, void *reserved) int VLCJNI_OnLoad(JavaVM *vm, JNIEnv* env)
{ {
JNIEnv* env = NULL;
// Keep a reference on the Java VM.
myVm = vm; myVm = vm;
if ((*vm)->GetEnv(vm, (void**) &env, VLC_JNI_VERSION) != JNI_OK)
return -1;
/* Create a TSD area and setup a destroy callback when a thread that /* Create a TSD area and setup a destroy callback when a thread that
* previously set the jni_env_key is canceled or exited */ * previously set the jni_env_key is canceled or exited */
if (pthread_key_create(&jni_env_key, jni_detach_thread) != 0) if (pthread_key_create(&jni_env_key, jni_detach_thread) != 0)
...@@ -327,17 +320,11 @@ jint JNI_OnLoad(JavaVM *vm, void *reserved) ...@@ -327,17 +320,11 @@ jint JNI_OnLoad(JavaVM *vm, void *reserved)
#undef GET_CLASS #undef GET_CLASS
#undef GET_ID #undef GET_ID
LOGD("JNI interface loaded."); return 0;
return VLC_JNI_VERSION;
} }
void JNI_OnUnload(JavaVM* vm, void* reserved) void VLCJNI_OnUnload(JavaVM *vm, JNIEnv *env)
{ {
JNIEnv* env = NULL;
if ((*vm)->GetEnv(vm, (void**) &env, VLC_JNI_VERSION) != JNI_OK)
return;
(*env)->DeleteGlobalRef(env, fields.IllegalStateException.clazz); (*env)->DeleteGlobalRef(env, fields.IllegalStateException.clazz);
(*env)->DeleteGlobalRef(env, fields.IllegalArgumentException.clazz); (*env)->DeleteGlobalRef(env, fields.IllegalArgumentException.clazz);
(*env)->DeleteGlobalRef(env, fields.String.clazz); (*env)->DeleteGlobalRef(env, fields.String.clazz);
......
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := jniloader
LOCAL_SRC_FILES := jniloader.c
LOCAL_LDFLAGS := -ldl -llog
include $(BUILD_SHARED_LIBRARY)
/*****************************************************************************
* jniloader.c
*****************************************************************************
* Copyright © 2017 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.
*****************************************************************************/
#include <dlfcn.h>
#include <stdbool.h>
#include <android/log.h>
#include "jniloader.h"
#define LOG_TAG "VLC"
#define LOGE(...) __android_log_print(ANDROID_LOG_ERROR,LOG_TAG,__VA_ARGS__)
static void *handle;
static bool has_ml;
/* jniloader.so is a shared C library used to receive JNI_OnLoad callback.
* Indeed, as JNI_OnLoad is already implemented in VLC core for its internal
* configuration, we can't have an other JNI_OnLoad implementation inside the
* libvlcjni.so.
*/
int JNI_OnLoad(JavaVM* vm, void* reserved)
{
JNIEnv *env;
if ((*vm)->GetEnv(vm, (void**) &env, VLC_JNI_VERSION) != JNI_OK)
{
LOGE("GetEnv failed");
return -1;
}
handle = dlopen("libvlcjni.so", RTLD_LAZY);
if (!handle)
{
LOGE("could not link libvlcjni.so");
return -1;
}
int (*load)(JavaVM *, JNIEnv*);
load = dlsym(handle, "VLCJNI_OnLoad");
if (!load || load(vm, env) != 0)
{
if (!load)
LOGE("could not find VLCJNI_OnLoad");
else
LOGE("VLCJNI_OnLoad failed");
return -1;
}
/* MediaLibraryJNI_OnLoad is not mandatory */
load = dlsym(handle, "MediaLibraryJNI_OnLoad");
if (load && load(vm, env) != 0)
{
LOGE("MediaLibraryJNI_OnLoad failed");
return -1;
}
has_ml = !!load;
return VLC_JNI_VERSION;
}
void JNI_OnUnload(JavaVM *vm, void *reserved)
{
JNIEnv* env;
if ((*vm)->GetEnv(vm, (void**) &env, VLC_JNI_VERSION) != JNI_OK)
return;
void (*unload)(JavaVM *, JNIEnv*);
if (has_ml)
{
unload = dlsym(handle, "MediaLibraryJNI_OnUnload");
if (unload)
unload(vm, env);
else
LOGE("could not find MediaLibraryJNI_OnUnload");
}
unload = dlsym(handle, "VLCJNI_OnUnload");
if (unload)
unload(vm, env);
else
LOGE("could not find VLCJNI_OnUnload");
dlclose(handle);
}
/*****************************************************************************
* jniloader.h
*****************************************************************************
* Copyright © 2017 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.
*****************************************************************************/
#include <jni.h>
#define VLC_JNI_VERSION JNI_VERSION_1_2
#ifdef __cplusplus
extern "C" {
#endif
int MediaLibraryJNI_OnLoad(JavaVM *vm, JNIEnv *env);
void MediaLibraryJNI_OnUnload(JavaVM *vm, JNIEnv *env);
int VLCJNI_OnLoad(JavaVM *vm, JNIEnv *env);
void VLCJNI_OnUnload(JavaVM *vm, JNIEnv *env);
#ifdef __cplusplus
}
#endif
...@@ -187,8 +187,8 @@ public class LibVLC extends VLCObject<LibVLC.Event> { ...@@ -187,8 +187,8 @@ public class LibVLC extends VLCObject<LibVLC.Event> {
} }
try { try {
System.loadLibrary("vlc");
System.loadLibrary("vlcjni"); System.loadLibrary("vlcjni");
System.loadLibrary("jniloader");
} catch (UnsatisfiedLinkError ule) { } catch (UnsatisfiedLinkError ule) {
Log.e(TAG, "Can't load vlcjni library: " + ule); Log.e(TAG, "Can't load vlcjni library: " + ule);
/// FIXME Alert user /// FIXME Alert user
......
LOCAL_PATH := $(call my-dir) LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_SRC_FILES := medialibrary.cpp AndroidMediaLibrary.cpp AndroidDeviceLister.cpp utils.cpp LOCAL_SRC_FILES := medialibrary.cpp AndroidMediaLibrary.cpp AndroidDeviceLister.cpp utils.cpp
LOCAL_MODULE := mla LOCAL_MODULE := mla
LOCAL_MODULE_FILENAME := libmla LOCAL_C_INCLUDES := $(MEDIALIBRARY_INCLUDE_DIR) $(JNILOADER_INCLUDES)
LOCAL_LDLIBS := $(MEDIALIBRARY_LDLIBS) -llog LOCAL_CFLAGS := $(MEDIALIBRARY_CFLAGS)
LOCAL_C_INCLUDES := $(MEDIALIBRARY_INCLUDE_DIR) include $(BUILD_STATIC_LIBRARY)
include $(BUILD_SHARED_LIBRARY)
#include "AndroidMediaLibrary.h" #include "AndroidMediaLibrary.h"
#define LOG_TAG "VLC/JNI/AndroidMediaLibrary" #define LOG_TAG "VLC/JNI/AndroidMediaLibrary"
#include "log.h" #include "log.h"
#include "jniloader.h"
#define FLAG_MEDIA_UPDATED_AUDIO 1 << 0 #define FLAG_MEDIA_UPDATED_AUDIO 1 << 0
#define FLAG_MEDIA_UPDATED_AUDIO_EMPTY 1 << 1 #define FLAG_MEDIA_UPDATED_AUDIO_EMPTY 1 << 1
......
#include <stdlib.h> #include <stdlib.h>
#include <string> #include <string>
#include <jni.h> #include "jniloader.h"
#include <medialibrary/IDeviceLister.h> #include <medialibrary/IDeviceLister.h>
#define LOG_TAG "VLC/JNI/MediaLibrary" #define LOG_TAG "VLC/JNI/MediaLibrary"
#include "log.h" #include "log.h"
...@@ -844,15 +844,11 @@ static void jni_detach_thread(void *data) ...@@ -844,15 +844,11 @@ static void jni_detach_thread(void *data)
myVm->DetachCurrentThread(); myVm->DetachCurrentThread();
} }
jint JNI_OnLoad(JavaVM *vm, void *reserved) extern "C" {
int MediaLibraryJNI_OnLoad(JavaVM *vm, JNIEnv* env)
{ {
JNIEnv* env = NULL;
// Keep a reference on the Java VM.
myVm = vm; myVm = vm;
if (vm->GetEnv((void**) &env, VLC_JNI_VERSION) != JNI_OK)
return -1;
#define GET_CLASS(clazz, str, b_globlal) do { \ #define GET_CLASS(clazz, str, b_globlal) do { \
(clazz) = env->FindClass((str)); \ (clazz) = env->FindClass((str)); \
if (!(clazz)) { \ if (!(clazz)) { \
...@@ -1080,25 +1076,17 @@ jint JNI_OnLoad(JavaVM *vm, void *reserved) ...@@ -1080,25 +1076,17 @@ jint JNI_OnLoad(JavaVM *vm, void *reserved)
#undef GET_CLASS #undef GET_CLASS
#undef GET_ID #undef GET_ID
LOGD("JNI interface loaded."); return 0;
return VLC_JNI_VERSION;
} }
void JNI_OnUnload(JavaVM* vm, void* reserved) void MediaLibraryJNI_OnUnload(JavaVM *vm, JNIEnv* env)
{ {
LOGD("JNI interface unloaded.");
JNIEnv* env = NULL;
if (vm->GetEnv((void**) &env, VLC_JNI_VERSION) != JNI_OK)
return;
env->DeleteGlobalRef(ml_fields.IllegalArgumentException.clazz); env->DeleteGlobalRef(ml_fields.IllegalArgumentException.clazz);
env->DeleteGlobalRef(ml_fields.IllegalStateException.clazz); env->DeleteGlobalRef(ml_fields.IllegalStateException.clazz);
env->DeleteGlobalRef(ml_fields.MediaLibrary.clazz); env->DeleteGlobalRef(ml_fields.MediaLibrary.clazz);
env->DeleteGlobalRef(ml_fields.MediaWrapper.clazz); env->DeleteGlobalRef(ml_fields.MediaWrapper.clazz);
} }
}
static inline void throw_IllegalStateException(JNIEnv *env, const char *p_error) static inline void throw_IllegalStateException(JNIEnv *env, const char *p_error)
{ {
......
...@@ -24,8 +24,6 @@ ...@@ -24,8 +24,6 @@
#include <medialibrary/Types.h> #include <medialibrary/Types.h>
#include <medialibrary/IMediaLibrary.h> #include <medialibrary/IMediaLibrary.h>
#define VLC_JNI_VERSION JNI_VERSION_1_2
struct fields { struct fields {
jint SDK_INT; jint SDK_INT;
struct IllegalStateException { struct IllegalStateException {
......
...@@ -69,7 +69,6 @@ public class Medialibrary { ...@@ -69,7 +69,6 @@ public class Medialibrary {
static { static {
LibVLC.loadLibraries(); LibVLC.loadLibraries();
System.loadLibrary("mla");
} }
private static class MedialibraryHolder { private static class MedialibraryHolder {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment