[libbluray-devel] bdj: read index on demand

hpi1 git at videolan.org
Thu Mar 27 14:56:45 CET 2014


libbluray | branch: master | hpi1 <hpi1 at anonymous.org> | Thu Mar 27 13:04:58 2014 +0200| [83d4fc32e45b9294c63ee3902cf1eed204488566] | committer: hpi1

bdj: read index on demand

This makes BD-J module interface simpler, if it is moved to separate process.

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

 src/libbluray/bdj/bdj.c                           |    3 +--
 src/libbluray/bdj/bdj.h                           |    2 --
 src/libbluray/bdj/native/org_videolan_Libbluray.c |   23 ++++++++++++++++++++-
 src/libbluray/bluray.c                            |    2 +-
 4 files changed, 24 insertions(+), 6 deletions(-)

diff --git a/src/libbluray/bdj/bdj.c b/src/libbluray/bdj/bdj.c
index 46fc66f..53a8737 100644
--- a/src/libbluray/bdj/bdj.c
+++ b/src/libbluray/bdj/bdj.c
@@ -448,7 +448,6 @@ static int _create_jvm(void *jvm_lib, const char *java_home, JNIEnv **env, JavaV
 }
 
 BDJAVA* bdj_open(const char *path, struct bluray *bd,
-                 struct indx_root_s *index,
                  bdj_overlay_cb osd_cb, struct bd_argb_buffer_s *buf)
 {
     BD_DEBUG(DBG_BDJ, "bdj_open()\n");
@@ -471,7 +470,6 @@ BDJAVA* bdj_open(const char *path, struct bluray *bd,
 
     BDJAVA* bdjava = calloc(1, sizeof(BDJAVA));
     bdjava->bd = bd;
-    bdjava->index = index;
     bdjava->path = path;
     bdjava->h_libjvm = jvm_lib;
     bdjava->osd_cb = osd_cb;
@@ -536,6 +534,7 @@ void bdj_close(BDJAVA *bdjava)
         dl_dlclose(bdjava->h_libjvm);
     }
 
+    indx_free(&bdjava->index);
     X_FREE(bdjava);
 }
 
diff --git a/src/libbluray/bdj/bdj.h b/src/libbluray/bdj/bdj.h
index e921b55..b589718 100644
--- a/src/libbluray/bdj/bdj.h
+++ b/src/libbluray/bdj/bdj.h
@@ -49,14 +49,12 @@ typedef enum {
 typedef struct bdjava_s BDJAVA;
 
 struct bluray;
-struct indx_root_s;
 struct bd_argb_buffer_s;
 
 typedef void (*bdj_overlay_cb)(struct bluray *, const unsigned *, int, int,
                                int, int, int, int);
 
 BD_PRIVATE BDJAVA* bdj_open(const char *path, struct bluray *bd,
-                            struct indx_root_s *index,
                             bdj_overlay_cb osd_cb, struct bd_argb_buffer_s *buf);
 BD_PRIVATE void bdj_close(BDJAVA *bdjava);
 BD_PRIVATE int  bdj_process_event(BDJAVA *bdjava, unsigned ev, unsigned param);
diff --git a/src/libbluray/bdj/native/org_videolan_Libbluray.c b/src/libbluray/bdj/native/org_videolan_Libbluray.c
index f6c27e9..b186661 100644
--- a/src/libbluray/bdj/native/org_videolan_Libbluray.c
+++ b/src/libbluray/bdj/native/org_videolan_Libbluray.c
@@ -121,6 +121,18 @@ static jobject _make_playlist_info(JNIEnv* env, BLURAY_TITLE_INFO* ti)
             ti->playlist, ti->duration, ti->angle_count, marks, clips);
 }
 
+static int _read_index(BDJAVA *bdj)
+{
+    if (!bdj) {
+        return 0;
+    }
+
+    if (!bdj->index) {
+        bdj->index = indx_parse(bdj->path);
+    }
+
+    return !!bdj->index;
+}
 
 JNIEXPORT jobject JNICALL Java_org_videolan_Libbluray_getTitleInfoN
   (JNIEnv * env, jclass cls, jlong np, jint title)
@@ -129,6 +141,10 @@ JNIEXPORT jobject JNICALL Java_org_videolan_Libbluray_getTitleInfoN
 
     BD_DEBUG(DBG_JNI, "getTitleInfoN(%d)\n", (int)title);
 
+    if (!_read_index(bdj)) {
+        return NULL;
+    }
+
     if (title == 65535) {
         if (bdj->index->first_play.object_type == indx_object_type_hdmv)
             return _make_title_info(env, 65535, indx_object_type_hdmv,
@@ -163,7 +179,7 @@ JNIEXPORT jobject JNICALL Java_org_videolan_Libbluray_getTitleInfoN
                                     bdj->index->titles[title - 1].bdj.name,
                                     -1);
     }
-        return NULL;
+    return NULL;
 }
 
 JNIEXPORT jobject JNICALL Java_org_videolan_Libbluray_getPlaylistInfoN
@@ -214,6 +230,11 @@ JNIEXPORT void JNICALL Java_org_videolan_Libbluray_setUOMaskN(JNIEnv * env,
 JNIEXPORT jint JNICALL Java_org_videolan_Libbluray_getTitlesN(JNIEnv * env,
                                                               jclass cls, jlong np) {
     BDJAVA* bdj = (BDJAVA*)(intptr_t)np;
+
+    if (!_read_index(bdj)) {
+        return 0;
+    }
+
     return bdj->index->num_titles;
 }
 
diff --git a/src/libbluray/bluray.c b/src/libbluray/bluray.c
index 76a535f..0603033 100644
--- a/src/libbluray/bluray.c
+++ b/src/libbluray/bluray.c
@@ -1204,7 +1204,7 @@ static int _start_bdj(BLURAY *bd, unsigned title)
 {
 #ifdef USING_BDJAVA
     if (bd->bdjava == NULL) {
-        bd->bdjava = bdj_open(bd->device_path, bd, bd->index, _bdj_osd_cb, bd->argb_buffer);
+        bd->bdjava = bdj_open(bd->device_path, bd, _bdj_osd_cb, bd->argb_buffer);
         if (!bd->bdjava) {
             return 0;
         }



More information about the libbluray-devel mailing list