[libbluray-devel] Synchronize BD-J overlay buffer/callback change and overlay draw

hpi1 git at videolan.org
Thu Nov 6 13:05:11 CET 2014


libbluray | branch: master | hpi1 <hpi1 at anonymous.org> | Thu Nov  6 12:52:58 2014 +0200| [40a00c3f202a942de8427d40991b91ff7480ef26] | committer: hpi1

Synchronize BD-J overlay buffer/callback change and overlay draw

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

 src/libbluray/bdj/bdj.c                           |    2 --
 src/libbluray/bdj/bdj.h                           |    2 --
 src/libbluray/bdj/bdj_private.h                   |    3 --
 src/libbluray/bdj/native/org_videolan_Libbluray.c |    6 +++-
 src/libbluray/bluray.c                            |   37 ++++++++++++++-------
 src/libbluray/bluray_internal.h                   |    4 +++
 6 files changed, 34 insertions(+), 20 deletions(-)

diff --git a/src/libbluray/bdj/bdj.c b/src/libbluray/bdj/bdj.c
index 1b147e4..6b23add 100644
--- a/src/libbluray/bdj/bdj.c
+++ b/src/libbluray/bdj/bdj.c
@@ -485,7 +485,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 bd_argb_buffer_s *buf,
                  const char *bdj_disc_id, BDJ_STORAGE *storage)
 {
     BD_DEBUG(DBG_BDJ, "bdj_open()\n");
@@ -509,7 +508,6 @@ BDJAVA* bdj_open(const char *path, struct bluray *bd,
     BDJAVA* bdjava = calloc(1, sizeof(BDJAVA));
     bdjava->bd = bd;
     bdjava->h_libjvm = jvm_lib;
-    bdjava->buf = buf;
     bdjava->jvm = jvm;
 
     if (debug_mask & DBG_JNI) {
diff --git a/src/libbluray/bdj/bdj.h b/src/libbluray/bdj/bdj.h
index 6a20808..7226932 100644
--- a/src/libbluray/bdj/bdj.h
+++ b/src/libbluray/bdj/bdj.h
@@ -54,10 +54,8 @@ typedef struct {
 typedef struct bdjava_s BDJAVA;
 
 struct bluray;
-struct bd_argb_buffer_s;
 
 BD_PRIVATE BDJAVA* bdj_open(const char *path, struct bluray *bd,
-                            struct bd_argb_buffer_s *buf,
                             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);
diff --git a/src/libbluray/bdj/bdj_private.h b/src/libbluray/bdj/bdj_private.h
index e8730c1..c48095b 100644
--- a/src/libbluray/bdj/bdj_private.h
+++ b/src/libbluray/bdj/bdj_private.h
@@ -25,13 +25,10 @@
 #include <jni.h>
 
 struct bluray;
-struct bd_argb_buffer_s;
 
 struct bdjava_s {
     struct bluray      *bd;
 
-    struct bd_argb_buffer_s *buf;
-
     // JVM library
     void *h_libjvm;
 
diff --git a/src/libbluray/bdj/native/org_videolan_Libbluray.c b/src/libbluray/bdj/native/org_videolan_Libbluray.c
index 7a62b19..c0ca8e5 100644
--- a/src/libbluray/bdj/native/org_videolan_Libbluray.c
+++ b/src/libbluray/bdj/native/org_videolan_Libbluray.c
@@ -520,7 +520,11 @@ JNIEXPORT void JNICALL Java_org_videolan_Libbluray_updateGraphicN(JNIEnv * env,
         return;
     }
 
-    _updateGraphic(env, bdj->bd, width, height, rgbArray, x0, y0, x1, y1, bdj->buf);
+    BD_ARGB_BUFFER *buf = bd_lock_osd_buffer(bdj->bd);
+
+    _updateGraphic(env, bdj->bd, width, height, rgbArray, x0, y0, x1, y1, buf);
+
+    bd_unlock_osd_buffer(bdj->bd);
 }
 
 #define CC (char*)(uintptr_t)  /* cast a literal from (const char*) */
diff --git a/src/libbluray/bluray.c b/src/libbluray/bluray.c
index 6af9add..fed52f8 100644
--- a/src/libbluray/bluray.c
+++ b/src/libbluray/bluray.c
@@ -179,9 +179,12 @@ struct bluray {
     uint64_t gc_wakeup_pos;   /* stream position of gc_wakeup_time */
 
     /* ARGB overlay output */
+#ifdef USING_BDJAVA
     void                *argb_overlay_proc_handle;
     bd_argb_overlay_proc_f argb_overlay_proc;
     BD_ARGB_BUFFER      *argb_buffer;
+    BD_MUTEX             argb_buffer_mutex;
+#endif
 };
 
 /* Stream Packet Number = byte offset / 192. Avoid 64-bit division. */
@@ -1178,6 +1181,17 @@ int bd_reg_write(BLURAY *bd, int psr, int reg, uint32_t value, uint32_t psr_valu
 #endif
 
 #ifdef USING_BDJAVA
+BD_ARGB_BUFFER *bd_lock_osd_buffer(BLURAY *bd)
+{
+    bd_mutex_lock(&bd->argb_buffer_mutex);
+    return bd->argb_buffer;
+}
+
+void bd_unlock_osd_buffer(BLURAY *bd)
+{
+    bd_mutex_unlock(&bd->argb_buffer_mutex);
+}
+
 /*
  * handle graphics updates from BD-J layer
  */
@@ -1258,7 +1272,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->argb_buffer, bd->disc_info.bdj_disc_id, bd->bdjstorage);
+        bd->bdjava = bdj_open(bd->device_path, bd, bd->disc_info.bdj_disc_id, bd->bdjstorage);
         if (!bd->bdjava) {
             return 0;
         }
@@ -1424,6 +1438,9 @@ BLURAY *bd_open(const char* device_path, const char* keyfile_path)
     _fill_disc_info(bd);
 
     bd_mutex_init(&bd->mutex);
+#ifdef USING_BDJAVA
+    bd_mutex_init(&bd->argb_buffer_mutex);
+#endif
 
     BD_DEBUG(DBG_BLURAY, "BLURAY initialized!\n");
 
@@ -1462,6 +1479,9 @@ void bd_close(BLURAY *bd)
     _storage_free(bd);
 
     bd_mutex_destroy(&bd->mutex);
+#ifdef USING_BDJAVA
+    bd_mutex_destroy(&bd->argb_buffer_mutex);
+#endif
 
     BD_DEBUG(DBG_BLURAY, "BLURAY destroyed!\n");
 
@@ -3425,26 +3445,19 @@ void bd_register_overlay_proc(BLURAY *bd, void *handle, bd_overlay_proc_f func)
 
 void bd_register_argb_overlay_proc(BLURAY *bd, void *handle, bd_argb_overlay_proc_f func, BD_ARGB_BUFFER *buf)
 {
+#ifdef USING_BDJAVA
     if (!bd) {
         return;
     }
 
-    bd_mutex_lock(&bd->mutex);
-
-    if (bd->argb_overlay_proc && bd->title_type == title_bdj) {
-        /* function can't be changed when BD-J is running */
-        bd_mutex_unlock(&bd->mutex);
-        BD_DEBUG(DBG_BLURAY | DBG_CRIT, "bd_register_argb_overlay_proc(): ARGB handler already registered and BD-J running !\n");
-        return;
-    }
-
-    _close_bdj(bd);
+    bd_mutex_lock(&bd->argb_buffer_mutex);
 
     bd->argb_overlay_proc        = func;
     bd->argb_overlay_proc_handle = handle;
     bd->argb_buffer              = buf;
 
-    bd_mutex_unlock(&bd->mutex);
+    bd_mutex_unlock(&bd->argb_buffer_mutex);
+#endif
 }
 
 int bd_get_sound_effect(BLURAY *bd, unsigned sound_id, BLURAY_SOUND_EFFECT *effect)
diff --git a/src/libbluray/bluray_internal.h b/src/libbluray/bluray_internal.h
index ca89031..d69650b 100644
--- a/src/libbluray/bluray_internal.h
+++ b/src/libbluray/bluray_internal.h
@@ -45,6 +45,10 @@ BD_PRIVATE int bd_play_playlist_at(BLURAY *bd, int playlist, int playitem, int p
 
 /* BD-J overlay */
 
+struct bd_argb_buffer_s;
+BD_PRIVATE struct bd_argb_buffer_s *bd_lock_osd_buffer(struct bluray *bd);
+BD_PRIVATE void                     bd_unlock_osd_buffer(struct bluray *bd);
+
 BD_PRIVATE void  bd_bdj_osd_cb(struct bluray *bd, const unsigned *img, int w, int h,
                                int x0, int y0, int x1, int y1);
 



More information about the libbluray-devel mailing list