[libbluray-devel] Add BD-J organization and disc ID to BLURAY_DISC_INFO

hpi1 git at videolan.org
Thu Nov 6 11:32:17 CET 2014


libbluray | branch: master | hpi1 <hpi1 at anonymous.org> | Thu Nov  6 12:31:25 2014 +0200| [82bd7fa9e55f5863bb5f560ea1453cc6cd00b6f5] | committer: hpi1

Add BD-J organization and disc ID to BLURAY_DISC_INFO

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

 src/examples/bd_info.c           |    2 ++
 src/libbluray/bdj/bdj.c          |   18 ++++++------------
 src/libbluray/bdj/bdj.h          |    2 +-
 src/libbluray/bdnav/bdid_parse.c |   32 ++++++++++++++++----------------
 src/libbluray/bdnav/bdid_parse.h |    2 +-
 src/libbluray/bluray.c           |   15 ++++++++++++++-
 src/libbluray/bluray.h           |    3 +++
 7 files changed, 43 insertions(+), 31 deletions(-)

diff --git a/src/examples/bd_info.c b/src/examples/bd_info.c
index 0eb564d..3e4eca6 100644
--- a/src/examples/bd_info.c
+++ b/src/examples/bd_info.c
@@ -182,6 +182,8 @@ int main(int argc, char *argv[])
                 printf("Java VM found       : %s\n", _yes_no(info->libjvm_detected));
                 printf("BD-J handled        : %s\n", _yes_no(info->bdj_handled));
             }
+            printf("BD-J organization ID: %s\n", info->bdj_org_id);
+            printf("BD-J disc ID        : %s\n", info->bdj_disc_id);
         }
     }
 
diff --git a/src/libbluray/bdj/bdj.c b/src/libbluray/bdj/bdj.c
index 47e6f60..4b5cd28 100644
--- a/src/libbluray/bdj/bdj.c
+++ b/src/libbluray/bdj/bdj.c
@@ -33,8 +33,6 @@
 #include "util/macro.h"
 #include "util/logging.h"
 
-#include "libbluray/register.h"
-#include "libbluray/bdnav/bdid_parse.h"
 #include "libbluray/bdnav/index_parse.h"
 
 #include <jni.h>
@@ -343,7 +341,7 @@ static int _get_method(JNIEnv *env, jclass *cls, jmethodID *method_id,
     return 1;
 }
 
-static int _bdj_init(BDJAVA *bdjava, JNIEnv *env)
+static int _bdj_init(BDJAVA *bdjava, JNIEnv *env, const char *bdj_disc_id)
 {
     if (!bdj_register_native_methods(env)) {
         BD_DEBUG(DBG_BDJ | DBG_CRIT, "Couldn't register native methods.\n");
@@ -357,11 +355,9 @@ static int _bdj_init(BDJAVA *bdjava, JNIEnv *env)
         return 0;
     }
 
-    char* id_path = str_printf("%s/CERTIFICATE/id.bdmv", bdjava->path);
-    BDID_DATA *id  = bdid_parse(id_path);
+    const char *disc_id = (bdj_disc_id && bdj_disc_id[0]) ? bdj_disc_id : "00000000000000000000000000000000";
     jlong param_bdjava_ptr = (jlong)(intptr_t) bdjava;
-    jstring param_disc_id = (*env)->NewStringUTF(env,
-                                                 id ? id->disc_id : "00000000000000000000000000000000");
+    jstring param_disc_id = (*env)->NewStringUTF(env, disc_id);
     jstring param_disc_root = (*env)->NewStringUTF(env, bdjava->path);
     (*env)->CallStaticVoidMethod(env, init_class, init_id,
                                  param_bdjava_ptr, param_disc_id, param_disc_root);
@@ -375,9 +371,6 @@ static int _bdj_init(BDJAVA *bdjava, JNIEnv *env)
     (*env)->DeleteLocalRef(env, param_disc_id);
     (*env)->DeleteLocalRef(env, param_disc_root);
 
-    X_FREE(id_path);
-    bdid_free(&id);
-
     return 1;
 }
 
@@ -493,7 +486,8 @@ static int _create_jvm(void *jvm_lib, const char *java_home, JNIEnv **env, JavaV
 }
 
 BDJAVA* bdj_open(const char *path, struct bluray *bd,
-                 bdj_overlay_cb osd_cb, struct bd_argb_buffer_s *buf, BDJ_STORAGE *storage)
+                 bdj_overlay_cb osd_cb, struct bd_argb_buffer_s *buf,
+                 const char *bdj_disc_id, BDJ_STORAGE *storage)
 {
     BD_DEBUG(DBG_BDJ, "bdj_open()\n");
 
@@ -526,7 +520,7 @@ BDJAVA* bdj_open(const char *path, struct bluray *bd,
         BD_DEBUG(DBG_BDJ, "Java version: %d.%d\n", version >> 16, version & 0xffff);
     }
 
-    if (!_bdj_init(bdjava, env)) {
+    if (!_bdj_init(bdjava, env, bdj_disc_id)) {
         bdj_close(bdjava);
         return NULL;
     }
diff --git a/src/libbluray/bdj/bdj.h b/src/libbluray/bdj/bdj.h
index 721c02f..0c6b134 100644
--- a/src/libbluray/bdj/bdj.h
+++ b/src/libbluray/bdj/bdj.h
@@ -61,7 +61,7 @@ typedef void (*bdj_overlay_cb)(struct bluray *, const unsigned *, int, int,
 
 BD_PRIVATE BDJAVA* bdj_open(const char *path, struct bluray *bd,
                             bdj_overlay_cb osd_cb, struct bd_argb_buffer_s *buf,
-                            BDJ_STORAGE *storage);
+                            const char *bdj_disc_id, BDJ_STORAGE *storage);
 BD_PRIVATE void bdj_close(BDJAVA *bdjava);
 BD_PRIVATE int  bdj_process_event(BDJAVA *bdjava, unsigned ev, unsigned param);
 BD_PRIVATE int  bdj_get_uo_mask(BDJAVA *bdjava);
diff --git a/src/libbluray/bdnav/bdid_parse.c b/src/libbluray/bdnav/bdid_parse.c
index 26874da..743b30c 100644
--- a/src/libbluray/bdnav/bdid_parse.c
+++ b/src/libbluray/bdnav/bdid_parse.c
@@ -17,14 +17,15 @@
  * <http://www.gnu.org/licenses/>.
  */
 
+#include "bdid_parse.h"
+
 #include "file/file.h"
 #include "util/bits.h"
 #include "util/logging.h"
 #include "util/macro.h"
-#include "bdid_parse.h"
+#include "util/strutl.h"
 
 #include <stdlib.h>
-#include <string.h>
 
 #define BDID_SIG1  ('B' << 24 | 'D' << 16 | 'I' << 8 | 'D')
 #define BDID_SIG2A ('0' << 24 | '2' << 16 | '0' << 8 | '0')
@@ -93,23 +94,22 @@ static BDID_DATA *_bdid_parse(const char *file_name)
     return NULL;
 }
 
-BDID_DATA *bdid_parse(const char *file_name)
+BDID_DATA *bdid_parse(const char *disc_root)
 {
-    BDID_DATA *bdid = _bdid_parse(file_name);
-
-    /* if failed, try backup file */
-    if (!bdid) {
-        size_t len   = strlen(file_name);
-        char *backup = malloc(len + 8);
-
-        strcpy(backup, file_name);
-        strcpy(backup + len - 7, "BACKUP" DIR_SEP "id.bdmv");
-
-        bdid = _bdid_parse(backup);
-
-        X_FREE(backup);
+    BDID_DATA *bdid;
+    char *file;
+
+    file = str_printf("%s" DIR_SEP "CERTIFICATE" DIR_SEP "id.bdmv", disc_root);
+    bdid = _bdid_parse(file);
+    X_FREE(file);
+    if (bdid) {
+      return bdid;
     }
 
+    /* if failed, try backup file */
+    file = str_printf("%s" DIR_SEP "CERTIFICATE" DIR_SEP "BACKUP" DIR_SEP "bdid.bdmv", disc_root);
+    bdid = _bdid_parse(file);
+    X_FREE(file);
     return bdid;
 }
 
diff --git a/src/libbluray/bdnav/bdid_parse.h b/src/libbluray/bdnav/bdid_parse.h
index a83d386..291e339 100644
--- a/src/libbluray/bdnav/bdid_parse.h
+++ b/src/libbluray/bdnav/bdid_parse.h
@@ -30,7 +30,7 @@ typedef struct bdid_s {
 } BDID_DATA;
 
 
-BD_PRIVATE BDID_DATA* bdid_parse(const char *path); /* parse id.bdmv */
+BD_PRIVATE BDID_DATA* bdid_parse(const char *disc_root); /* parse id.bdmv */
 BD_PRIVATE void       bdid_free(BDID_DATA **p);
 
 #endif // _BDID_PARSE_H_
diff --git a/src/libbluray/bluray.c b/src/libbluray/bluray.c
index 02c2554..d2f84bd 100644
--- a/src/libbluray/bluray.c
+++ b/src/libbluray/bluray.c
@@ -32,6 +32,7 @@
 #include "util/logging.h"
 #include "util/strutl.h"
 #include "util/mutex.h"
+#include "bdnav/bdid_parse.h"
 #include "bdnav/navigation.h"
 #include "bdnav/index_parse.h"
 #include "bdnav/meta_parse.h"
@@ -971,6 +972,9 @@ static void _fill_disc_info(BLURAY *bd)
 
     array_free((void**)&bd->titles);
 
+    memset(bd->disc_info.bdj_org_id,  0, sizeof(bd->disc_info.bdj_org_id));
+    memset(bd->disc_info.bdj_disc_id, 0, sizeof(bd->disc_info.bdj_disc_id));
+
     INDX_ROOT *index = indx_parse(bd->device_path);
     if (index) {
         INDX_PLAY_ITEM *pi;
@@ -1091,6 +1095,15 @@ static void _fill_disc_info(BLURAY *bd)
 
         indx_free(&index);
     }
+
+    if (bd->disc_info.bdj_detected) {
+        BDID_DATA *bdid = bdid_parse(bd->device_path); /* parse id.bdmv */
+        if (bdid) {
+            memcpy(bd->disc_info.bdj_org_id,  bdid->org_id,  sizeof(bd->disc_info.bdj_org_id));
+            memcpy(bd->disc_info.bdj_disc_id, bdid->disc_id, sizeof(bd->disc_info.bdj_disc_id));
+            bdid_free(&bdid);
+        }
+    }
 }
 
 /*
@@ -1245,7 +1258,7 @@ static int _start_bdj(BLURAY *bd, unsigned title)
 {
 #ifdef USING_BDJAVA
     if (bd->bdjava == NULL) {
-        bd->bdjava = bdj_open(bd->device_path, bd, _bdj_osd_cb, bd->argb_buffer, bd->bdjstorage);
+        bd->bdjava = bdj_open(bd->device_path, bd, _bdj_osd_cb, bd->argb_buffer, bd->disc_info.bdj_disc_id, bd->bdjstorage);
         if (!bd->bdjava) {
             return 0;
         }
diff --git a/src/libbluray/bluray.h b/src/libbluray/bluray.h
index 34366d9..1434ba0 100644
--- a/src/libbluray/bluray.h
+++ b/src/libbluray/bluray.h
@@ -530,6 +530,9 @@ typedef struct {
     const BLURAY_TITLE  *first_play;     /* titles[N+1].   NULL if not present on the disc. */
     const BLURAY_TITLE  *top_menu;       /* titles[0]. NULL if not present on the disc. */
 
+    char bdj_org_id[9];      /* (BD-J) disc organization ID */
+    char bdj_disc_id[33];    /* (BD-J) disc ID */
+
 } BLURAY_DISC_INFO;
 
 /**



More information about the libbluray-devel mailing list