[libbluray-devel] Splitted bdj_open() and bdj_close()

hpi1 git at videolan.org
Fri Sep 14 14:46:09 CEST 2012


libbluray | branch: master | hpi1 <hpi1 at anonymous.org> | Fri Sep 14 13:54:09 2012 +0300| [a4b66e6cdab0ec97cd5c4e92322a3c9d54e7793d] | committer: hpi1

Splitted bdj_open() and bdj_close()

> http://git.videolan.org/gitweb.cgi/libbluray.git/?a=commit;h=a4b66e6cdab0ec97cd5c4e92322a3c9d54e7793d
---

 src/libbluray/bdj/bdj.c |   46 +++++++++++++++++-----------------
 src/libbluray/bdj/bdj.h |    6 +++--
 src/libbluray/bluray.c  |   63 ++++++++++++++++++++++++++++++++---------------
 3 files changed, 70 insertions(+), 45 deletions(-)

diff --git a/src/libbluray/bdj/bdj.c b/src/libbluray/bdj/bdj.c
index 096dff2..18c805a 100644
--- a/src/libbluray/bdj/bdj.c
+++ b/src/libbluray/bdj/bdj.c
@@ -36,10 +36,9 @@
 
 typedef jint (JNICALL * fptr_JNI_CreateJavaVM) (JavaVM **pvm, void **penv,void *args);
 
-int bdj_start(JNIEnv* env, const char* path, jobject bdjo, BDJAVA* bdjava);
 void* load_jvm();
 
-BDJAVA* bdj_open(const char *path, const char *start,
+BDJAVA* bdj_open(const char *path,
                  struct bluray *bd, struct bd_registers_s *registers,
                  struct indx_root_s *index)
 {
@@ -92,28 +91,13 @@ BDJAVA* bdj_open(const char *path, const char *start,
         return NULL;
     }
 
-    // determine path of bdjo file to load
-    char* bdjo_path = str_printf("%s%s/%s.bdjo", path, BDJ_BDJO_PATH, start);
-    jobject bdjo = bdjo_read(bdjava->env, bdjo_path);
-    free(bdjo_path);
-
-    if (!bdjo) {
-        free(bdjava);
-        BD_DEBUG(DBG_BDJ | DBG_CRIT, "Failed to load BDJO file.\n");
-        return NULL;
-    }
-
-    if (bdj_start(bdjava->env, path, bdjo, bdjava) == BDJ_ERROR) {
-        free(bdjava);
-        BD_DEBUG(DBG_BDJ | DBG_CRIT, "Failed to start BDJ program.\n");
-        return NULL;
-    }
-
     return bdjava;
 }
 
-int bdj_start(JNIEnv* env, const char* path, jobject bdjo, BDJAVA* bdjava)
+int bdj_start(BDJAVA *bdjava, const char *start)
 {
+    JNIEnv* env = bdjava->env;
+
     jclass init_class = (*env)->FindClass(env, "org/videolan/BDJLoader");
 
     if (init_class == NULL) {
@@ -129,7 +113,18 @@ int bdj_start(JNIEnv* env, const char* path, jobject bdjo, BDJAVA* bdjava)
         return BDJ_ERROR;
     }
 
-    jstring param_base_dir = (*env)->NewStringUTF(env, path);
+    // determine path of bdjo file to load
+    char* bdjo_path = str_printf("%s%s/%s.bdjo", bdjava->path, BDJ_BDJO_PATH, start);
+    jobject bdjo = bdjo_read(bdjava->env, bdjo_path);
+    free(bdjo_path);
+
+    if (!bdjo) {
+        free(bdjava);
+        BD_DEBUG(DBG_BDJ | DBG_CRIT, "Failed to load BDJO file.\n");
+        return BDJ_ERROR;
+    }
+
+    jstring param_base_dir = (*env)->NewStringUTF(env, bdjava->path);
     jlong param_bdjava_ptr = (jlong)(intptr_t)bdjava;
 
     (*env)->CallStaticVoidMethod(env, init_class, load_id, param_base_dir, bdjo,
@@ -138,16 +133,21 @@ int bdj_start(JNIEnv* env, const char* path, jobject bdjo, BDJAVA* bdjava)
     return BDJ_SUCCESS;
 }
 
-void bdj_close(BDJAVA *bdjava)
+void bdj_stop(BDJAVA *bdjava)
 {
     JNIEnv* env = bdjava->env;
-    JavaVM* jvm = bdjava->jvm;
 
     jclass init_class = (*env)->FindClass(env, "org/videolan/BDJLoader");
     jmethodID shutdown_id = (*env)->GetStaticMethodID(env, init_class,
             "Shutdown", "()V");
     (*env)->CallStaticVoidMethod(env, init_class, shutdown_id);
 
+}
+
+void bdj_close(BDJAVA *bdjava)
+{
+    JavaVM* jvm = bdjava->jvm;
+
     (*jvm)->DestroyJavaVM(jvm);
 
     free(bdjava);
diff --git a/src/libbluray/bdj/bdj.h b/src/libbluray/bdj/bdj.h
index 4f14cd2..2c86fc5 100644
--- a/src/libbluray/bdj/bdj.h
+++ b/src/libbluray/bdj/bdj.h
@@ -28,8 +28,10 @@ struct bluray;
 struct bd_registers_s;
 struct indx_root_s;
 
-BDJAVA* bdj_open(const char *path, const char *start,
-                 struct bluray *bd, struct bd_registers_s *registers, struct indx_root_s *index);
+BDJAVA* bdj_open(const char *path, struct bluray *bd,
+                 struct bd_registers_s *registers, struct indx_root_s *index);
+int bdj_start(BDJAVA *bdjava, const char *start);
+void bdj_stop(BDJAVA *bdjava);
 void bdj_close(BDJAVA *bdjava);
 
 void bdj_send_event(BDJAVA *bdjava, int type, int keyCode);
diff --git a/src/libbluray/bluray.c b/src/libbluray/bluray.c
index 4236eb3..d02b915 100644
--- a/src/libbluray/bluray.c
+++ b/src/libbluray/bluray.c
@@ -984,6 +984,45 @@ static void _fill_disc_info(BLURAY *bd)
     }
 }
 
+/*
+ * bdj
+ */
+
+static int _start_bdj(BLURAY *bd, const char *start)
+{
+#ifdef USING_BDJAVA
+    if (bd->bdjava == NULL) {
+        bd->bdjava = bdj_open(bd->device_path, bd, bd->regs, bd->index);
+        if (!bd->bdjava) {
+            return 0;
+        }
+    }
+    return bdj_start(bd->bdjava, start);
+#else
+    BD_DEBUG(DBG_BLURAY | DBG_CRIT, "Title %s.bdjo: BD-J not compiled in (%p)\n", start, bd);
+    return 0;
+#endif
+}
+
+static void _stop_bdj(BLURAY *bd)
+{
+#ifdef USING_BDJAVA
+    if (bd->bdjava != NULL) {
+        bdj_stop(bd->bdjava);
+    }
+#endif
+}
+
+static void _close_bdj(BLURAY *bd)
+{
+#ifdef USING_BDJAVA
+    if (bd->bdjava != NULL) {
+        bdj_close(bd->bdjava);
+        bd->bdjava = NULL;
+    }
+#endif
+}
+
 #ifdef HAVE_MNTENT_H
 /*
  * Replace device node (/dev/sr0) by mount point
@@ -1094,7 +1133,7 @@ BLURAY *bd_open(const char* device_path, const char* keyfile_path)
 
 void bd_close(BLURAY *bd)
 {
-    bd_stop_bdj(bd);
+    _close_bdj(bd);
 
     _libaacs_unload(bd);
 
@@ -2006,33 +2045,17 @@ int bd_set_player_setting_str(BLURAY *bd, uint32_t idx, const char *s)
 }
 
 /*
- * bdj
+ * BD-J testing
  */
 
 int bd_start_bdj(BLURAY *bd, const char *start_object)
 {
-#ifdef USING_BDJAVA
-    if (bd->bdjava == NULL) {
-        bd->bdjava = bdj_open(bd->device_path, start_object, bd, bd->regs, bd->index);
-        return !!bd->bdjava;
-    } else {
-        BD_DEBUG(DBG_BLURAY | DBG_CRIT, "BD-J is already running (%p)\n", bd);
-        return 1;
-    }
-#else
-    BD_DEBUG(DBG_BLURAY | DBG_CRIT, "%s.bdjo: BD-J not compiled in (%p)\n", start_object, bd);
-#endif
-    return 0;
+    return _start_bdj(bd, start_object);
 }
 
 void bd_stop_bdj(BLURAY *bd)
 {
-#ifdef USING_BDJAVA
-    if (bd->bdjava != NULL) {
-        bdj_close((BDJAVA*)bd->bdjava);
-        bd->bdjava = NULL;
-    }
-#endif
+    _close_bdj(bd);
 }
 
 /*



More information about the libbluray-devel mailing list