[libbluray-devel] disc: support unmounted discs with libmmbd

npzacs git at videolan.org
Sun Jul 3 12:48:43 CEST 2016


libbluray | branch: master | npzacs <npzacs at gmail.com> | Sun Jul  3 13:47:15 2016 +0300| [a8ea94802b040ecbad69f581c50a08513bc389b3] | committer: npzacs

disc: support unmounted discs with libmmbd

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

 src/libbluray/disc/aacs.c   |   10 ++++++++++
 src/libbluray/disc/bdplus.c |   18 ++++++++++++++++--
 src/libbluray/disc/bdplus.h |    2 +-
 src/libbluray/disc/dec.c    |    2 +-
 4 files changed, 28 insertions(+), 4 deletions(-)

diff --git a/src/libbluray/disc/aacs.c b/src/libbluray/disc/aacs.c
index e44b5a7..1c8984d 100644
--- a/src/libbluray/disc/aacs.c
+++ b/src/libbluray/disc/aacs.c
@@ -30,6 +30,7 @@
 #include "util/strutl.h"
 
 #include <stdlib.h>
+#include <string.h>
 
 
 struct bd_aacs {
@@ -181,6 +182,15 @@ int libaacs_open(BD_AACS *p, const char *device,
     } else if (open2) {
         BD_DEBUG(DBG_BLURAY, "Using old aacs_open2(), no UDF support available\n");
         p->aacs = open2(device, keyfile_path, &error_code);
+
+        /* libmmbd needs dev: for devices */
+        if (!p->aacs && p->impl_id == IMPL_LIBMMBD && !strncmp(device, "/dev/", 5)) {
+            char *tmp_device = str_printf("dev:%s", device);
+            if (tmp_device) {
+                p->aacs = open2(tmp_device, keyfile_path, &error_code);
+                X_FREE(tmp_device);
+            }
+        }
     } else if (open) {
         BD_DEBUG(DBG_BLURAY, "Using old aacs_open(), no verbose error reporting available\n");
         p->aacs = open(device, keyfile_path);
diff --git a/src/libbluray/disc/bdplus.c b/src/libbluray/disc/bdplus.c
index 1ec3bc2..8afe980 100644
--- a/src/libbluray/disc/bdplus.c
+++ b/src/libbluray/disc/bdplus.c
@@ -30,6 +30,7 @@
 #include "util/strutl.h"
 
 #include <stdlib.h>
+#include <string.h>
 
 
 struct bd_bdplus {
@@ -166,7 +167,7 @@ BD_BDPLUS *libbdplus_load()
     return _load(0);
 }
 
-int libbdplus_init(BD_BDPLUS *p, const char *root,
+int libbdplus_init(BD_BDPLUS *p, const char *root, const char *device,
                    void *file_open_handle, void *file_open_fp,
                    const uint8_t *vid, const uint8_t *mk)
 {
@@ -183,7 +184,7 @@ int libbdplus_init(BD_BDPLUS *p, const char *root,
     if (mk == NULL && p->impl_id == IMPL_LIBBDPLUS) {
         BD_BDPLUS *p2 = _load(IMPL_LIBMMBD);
         if (p2) {
-            if (!libbdplus_init(p2, root, file_open_handle, file_open_fp, vid, mk)) {
+            if (!libbdplus_init(p2, root, device, file_open_handle, file_open_fp, vid, mk)) {
                 /* succeed - swap implementations */
                 _unload(p);
                 *p = *p2;
@@ -206,10 +207,23 @@ int libbdplus_init(BD_BDPLUS *p, const char *root,
     }
 
     if (set_fopen) {
+        /* New libbdplus. Use libbluray for file I/O */
         p->bdplus = bdplus_init(NULL, NULL, vid);
         set_fopen(p->bdplus, file_open_handle, file_open_fp);
     } else if (root) {
+        /* Old libbdplus or libmmbd. Disc is mounted. */
         p->bdplus = bdplus_init(root, NULL, vid);
+    } else if (device) {
+        /* Unmounted device */
+        if (p->impl_id == IMPL_LIBMMBD && !strncmp(device, "/dev/", 5)) {
+            char *tmp = str_printf("dev:%s", device);
+            if (tmp) {
+                p->bdplus = bdplus_init(tmp, NULL, vid);
+                X_FREE(tmp);
+            }
+        } else {
+            BD_DEBUG(DBG_BLURAY | DBG_CRIT, "Too old libbdplus detected. Disc must be mounted first.\n");
+        }
     }
 
     if (!p->bdplus) {
diff --git a/src/libbluray/disc/bdplus.h b/src/libbluray/disc/bdplus.h
index 6589d88..88e940c 100644
--- a/src/libbluray/disc/bdplus.h
+++ b/src/libbluray/disc/bdplus.h
@@ -30,7 +30,7 @@ typedef struct bd_bdplus BD_BDPLUS;
 BD_PRIVATE int  libbdplus_required(void *have_file_handle, int (*have_file)(void *, const char *, const char *));
 BD_PRIVATE BD_BDPLUS *libbdplus_load(void);
 BD_PRIVATE int  libbdplus_is_mmbd(BD_BDPLUS *);
-BD_PRIVATE int  libbdplus_init(BD_BDPLUS *p, const char *root,
+BD_PRIVATE int  libbdplus_init(BD_BDPLUS *p, const char *root, const char *device,
                                void *open_file_handle, void *open_file_fp,
                                const uint8_t *vid, const uint8_t *mk);
 BD_PRIVATE void libbdplus_unload(BD_BDPLUS **p);
diff --git a/src/libbluray/disc/dec.c b/src/libbluray/disc/dec.c
index ebe2c39..e2d9ef9 100644
--- a/src/libbluray/disc/dec.c
+++ b/src/libbluray/disc/dec.c
@@ -219,7 +219,7 @@ static int _libbdplus_init(BD_DEC *dec, struct dec_dev *dev,
         return 0;
     }
 
-    if (libbdplus_init(dec->bdplus, dev->root, dev->file_open_bdrom_handle, (void*)dev->pf_file_open_bdrom, vid, mk)) {
+    if (libbdplus_init(dec->bdplus, dev->root, dev->device, dev->file_open_bdrom_handle, (void*)dev->pf_file_open_bdrom, vid, mk)) {
         BD_DEBUG(DBG_BLURAY | DBG_CRIT, "bdplus_init() failed\n");
 
         i->bdplus_handled = 0;



More information about the libbluray-devel mailing list