BDJAVA* bdj_open(const char *path, struct bluray *bd, const char *bdj_disc_id, BDJ_STORAGE *storage) { BD_DEBUG(DBG_BDJ, "bdj_open()\n"); const char *jar_file = _find_libbluray_jar(storage); if (!jar_file) { BD_DEBUG(DBG_BDJ | DBG_CRIT, "BD-J start failed: " BDJ_JARFILE " not found.\n"); return NULL; } #if defined(__APPLE__) && !defined(HAVE_BDJ_J2ME) /* On macOS we need to load libjli to workaround a bug where the wrong * version would be used: https://bugs.openjdk.java.net/browse/JDK-7131356 */ void* jli_lib = _load_jli_macos(); if (!jli_lib) { BD_DEBUG(DBG_BDJ, "Wasn't able to load JLI\n"); } #endif // first load the jvm using dlopen const char *java_home = NULL; void* jvm_lib = _load_jvm(&java_home); if (!jvm_lib) { BD_DEBUG(DBG_BDJ | DBG_CRIT, "Wasn't able to load JVM\n"); return 0; } BDJAVA* bdjava = calloc(1, sizeof(BDJAVA)); if (!bdjava) { dl_dlclose(jvm_lib); return NULL; } JNIEnv* env = NULL; JavaVM *jvm = NULL; if (!_find_jvm(jvm_lib, &env, &jvm) && !_create_jvm(jvm_lib, java_home, jar_file, &env, &jvm)) { X_FREE(bdjava); dl_dlclose(jvm_lib); return NULL; } #if defined(__APPLE__) && !defined(HAVE_BDJ_J2ME) bdjava->h_libjli = jli_lib; #endif bdjava->h_libjvm = jvm_lib; bdjava->jvm = jvm; if (debug_mask & DBG_JNI) { int version = (int)(*env)->GetVersion(env); BD_DEBUG(DBG_BDJ, "Java version: %d.%d\n", version >> 16, version & 0xffff); }
void bdj_close(BDJAVA *bdjava) { JNIEnv *env; int attach; jclass shutdown_class; jmethodID shutdown_id; if (!bdjava) { return; } if ((*bdjava->jvm)->GetEnv(bdjava->jvm, (void**)&env, JNI_VERSION_1_6) != JNI_OK) { (*bdjava->jvm)->AttachCurrentThread(bdjava->jvm, (void**)&env, NULL); attach = 1; } if (bdj_get_method(env, &shutdown_class, &shutdown_id, "org/videolan/Libbluray", "shutdown", "()V")) { (*env)->CallStaticVoidMethod(env, shutdown_class, shutdown_id); (*env)->DeleteLocalRef(env, shutdown_class); } if (attach) { (*bdjava->jvm)->DetachCurrentThread(bdjava->jvm); } (*bdjava->jvm)->DestroyJavaVM(bdjava->jvm); dl_dlclose(bdjava->h_libjvm); X_FREE(bdjava); }
static void _unload(BD_AACS *p) { _libaacs_close(p); if (p->h_libaacs) { dl_dlclose(p->h_libaacs); } }
void libaacs_unload(BD_AACS **p) { if (p && *p) { _libaacs_close(*p); if ((*p)->h_libaacs) { dl_dlclose((*p)->h_libaacs); } X_FREE(*p); } }
void libbdplus_unload(BD_BDPLUS **p) { if (p && *p) { _libbdplus_close(*p); if ((*p)->h_libbdplus) { dl_dlclose((*p)->h_libbdplus); } X_FREE(*p); } }
int bdj_jvm_available(BDJ_STORAGE *storage) { const char *java_home; void* jvm_lib = _load_jvm(&java_home); if (!jvm_lib) { BD_DEBUG(DBG_BDJ | DBG_CRIT, "BD-J check: Failed to load JVM library\n"); return 0; } dl_dlclose(jvm_lib); if (!_find_libbluray_jar(storage)) { BD_DEBUG(DBG_BDJ | DBG_CRIT, "BD-J check: Failed to load libbluray.jar\n"); return 1; } BD_DEBUG(DBG_BDJ, "BD-J check: OK\n"); return 2; }
BDJAVA* bdj_open(const char *path, struct bluray *bd, const char *bdj_disc_id, BDJ_STORAGE *storage) { BD_DEBUG(DBG_BDJ, "bdj_open()\n"); const char *jar_file = _find_libbluray_jar(storage); if (!jar_file) { BD_DEBUG(DBG_BDJ | DBG_CRIT, "BD-J start failed: " BDJ_JARFILE " not found.\n"); return NULL; } // first load the jvm using dlopen const char *java_home = NULL; void* jvm_lib = _load_jvm(&java_home); if (!jvm_lib) { BD_DEBUG(DBG_BDJ | DBG_CRIT, "Wasn't able to load JVM\n"); return 0; } JNIEnv* env = NULL; JavaVM *jvm = NULL; if (!_find_jvm(jvm_lib, &env, &jvm) && !_create_jvm(jvm_lib, java_home, jar_file, &env, &jvm)) { dl_dlclose(jvm_lib); return NULL; } BDJAVA* bdjava = calloc(1, sizeof(BDJAVA)); bdjava->h_libjvm = jvm_lib; bdjava->jvm = jvm; if (debug_mask & DBG_JNI) { int version = (int)(*env)->GetVersion(env); BD_DEBUG(DBG_BDJ, "Java version: %d.%d\n", version >> 16, version & 0xffff); }
BDJAVA* bdj_open(const char *path, struct bluray *bd, struct bd_registers_s *registers, struct indx_root_s *index) { // first load the jvm using dlopen void* jvm_lib = _load_jvm(); if (!jvm_lib) { BD_DEBUG(DBG_BDJ | DBG_CRIT, "Wasn't able to load libjvm.so\n"); return NULL; } fptr_JNI_CreateJavaVM JNI_CreateJavaVM_fp = (fptr_JNI_CreateJavaVM)dl_dlsym(jvm_lib, "JNI_CreateJavaVM"); if (JNI_CreateJavaVM_fp == NULL) { dl_dlclose(jvm_lib); BD_DEBUG(DBG_BDJ | DBG_CRIT, "Couldn't find symbol JNI_CreateJavaVM.\n"); return NULL; } BDJAVA* bdjava = calloc(1, sizeof(BDJAVA)); bdjava->bd = bd; bdjava->reg = registers; bdjava->index = index; bdjava->path = path; bdjava->h_libjvm = jvm_lib; JavaVMInitArgs args; // check if overriding the classpath const char* classpath = getenv("LIBBLURAY_CP"); if (classpath == NULL) classpath = BDJ_CLASSPATH; // determine classpath char* classpath_opt = str_printf("-Djava.class.path=%s", classpath); // determine bluray.vfs.root char* vfs_opt; vfs_opt = str_printf("-Dbluray.vfs.root=%s", path); JavaVMOption* option = calloc(1, sizeof(JavaVMOption) * 9); int n = 0; option[n++].optionString = classpath_opt; option[n++].optionString = vfs_opt; args.version = JNI_VERSION_1_6; args.nOptions = n; args.options = option; args.ignoreUnrecognized = JNI_FALSE; // don't ignore unrecognized options JNIEnv* env = NULL; int result = JNI_CreateJavaVM_fp(&bdjava->jvm, (void**) &env, &args); free(option); free(classpath_opt); free(vfs_opt); if (result != JNI_OK || !env) { bdj_close(bdjava); BD_DEBUG(DBG_BDJ | DBG_CRIT, "Failed to create new Java VM.\n"); return NULL; } if (!_bdj_init(bdjava, env)) { bdj_close(bdjava); return NULL; } return bdjava; }