[libbluray-devel] Improved updating of application-allocated ARGB frame buffer.

hpi1 git at videolan.org
Fri Nov 8 13:37:54 CET 2013


libbluray | branch: master | hpi1 <hpi1 at anonymous.org> | Fri Nov  8 14:31:48 2013 +0200| [47933877b5112f35d163e4440d57b53352871a3c] | committer: hpi1

Improved updating of application-allocated ARGB frame buffer.

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

 src/libbluray/bdj/native/org_videolan_Libbluray.c |   22 +++++++++++++++++----
 src/libbluray/bluray.c                            |    6 +++++-
 src/libbluray/decoders/overlay.h                  |    6 ++++--
 3 files changed, 27 insertions(+), 7 deletions(-)

diff --git a/src/libbluray/bdj/native/org_videolan_Libbluray.c b/src/libbluray/bdj/native/org_videolan_Libbluray.c
index a69f31c..cfd68cd 100644
--- a/src/libbluray/bdj/native/org_videolan_Libbluray.c
+++ b/src/libbluray/bdj/native/org_videolan_Libbluray.c
@@ -428,10 +428,24 @@ JNIEXPORT void JNICALL Java_org_videolan_Libbluray_updateGraphicN(JNIEnv * env,
         }
 
         /* check buffer size */
-        if (bdj->buf->width != width || bdj->buf->height != height) {
-            BD_DEBUG(DBG_BDJ | DBG_CRIT, "Incorrect ARGB frame buffer size (is: %dx%d expect: %dx%d)\n",
+        if (bdj->buf->width < width || bdj->buf->height < height) {
+            /* assume buffer is only for the dirty arrea */
+            BD_DEBUG(DBG_BDJ, "ARGB frame buffer size is smaller than BD-J frame buffer size (app: %dx%d BD-J: %dx%d)\n",
                      bdj->buf->width, bdj->buf->height, width, height);
-        }
+
+            if (bdj->buf->width < (x1 - x0 + 1) || bdj->buf->height < (y1 - y0 + 1)) {
+                BD_DEBUG(DBG_BDJ | DBG_CRIT, "ARGB frame buffer size is smaller than dirty area\n");
+                if (bdj->buf->unlock) {
+                    bdj->buf->unlock(bdj->buf);
+                }
+                return;
+            }
+
+            dst = (jint*)bdj->buf->buf[BD_OVERLAY_IG];
+
+        } else {
+
+            dst = (jint*)bdj->buf->buf[BD_OVERLAY_IG] + y0 * bdj->buf->width + x0;
 
         /* clip */
         if (y1 >= bdj->buf->height) {
@@ -442,11 +456,11 @@ JNIEXPORT void JNICALL Java_org_videolan_Libbluray_updateGraphicN(JNIEnv * env,
             BD_DEBUG(DBG_BDJ | DBG_CRIT, "Cropping %d pixels from right\n", x1 - bdj->buf->width);
             x1 = bdj->buf->width - 1;
         }
+        }
 
         /* copy */
 
         offset = y0 * width + x0;
-        dst    = (jint*)bdj->buf->buf[BD_OVERLAY_IG] + y0 * bdj->buf->width + x0;
 
         for (y = y0; y <= y1; y++) {
             (*env)->GetIntArrayRegion(env, rgbArray, offset, x1 - x0 + 1, dst);
diff --git a/src/libbluray/bluray.c b/src/libbluray/bluray.c
index 9d67820..b248e4e 100644
--- a/src/libbluray/bluray.c
+++ b/src/libbluray/bluray.c
@@ -1015,7 +1015,11 @@ static void _bdj_osd_cb(BLURAY *bd, const unsigned *img, int w, int h,
     }
 
     /* pass only changed region */
-    aov.argb   = img + x0 + y0 * w;
+    if (bd->argb_buffer->width < w || bd->argb_buffer->height < h) {
+        aov.argb   = img;
+    } else {
+        aov.argb   = img + x0 + y0 * w;
+    }
     aov.stride = w;
     aov.x      = x0;
     aov.y      = y0;
diff --git a/src/libbluray/decoders/overlay.h b/src/libbluray/decoders/overlay.h
index 757becd..6a31218 100644
--- a/src/libbluray/decoders/overlay.h
+++ b/src/libbluray/decoders/overlay.h
@@ -176,18 +176,20 @@ typedef struct bd_argb_buffer_s {
     /* ARGB frame buffers
      * - Allocated by application (BD_ARGB_OVERLAY_INIT).
      * - Buffer can be freed after BD_ARGB_OVERLAY_CLOSE.
-     * - buffer can be replaced while overlay callback is executed.
+     * - buffer can be replaced in overlay callback or lock().
      */
 
     uint32_t *buf[2]; /* [0] - PG plane, [1] - IG plane */
 
     /* size of buffers
      * - Set by application
+     * - If the buffer size is smaller than the size requested in BD_ARGB_OVERLAY_INIT,
+     *   the buffer points only to the dirty area.
      */
     int width;
     int height;
 
-    /* dirty area of buffers
+    /* dirty area of frame buffers
      * - Updated by library before lock() call.
      * - Reset after each BD_ARGB_OVERLAY_FLUSH.
      */



More information about the libbluray-devel mailing list