[libbluray-devel] disc: simplify passing file system access functions

hpi1 git at videolan.org
Sun Feb 21 17:56:52 CET 2016


libbluray | branch: master | hpi1 <hpi1 at anonymous.org> | Sun Jan 31 16:50:09 2016 +0200| [0db59294fed0e47b54ece79e6e3534dba578bf15] | committer: hpi1

disc: simplify passing file system access functions

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

 src/libbluray/bluray.c    |   10 +++++-----
 src/libbluray/disc/disc.c |   12 ++++++++----
 src/libbluray/disc/disc.h |   15 +++++++++++++--
 3 files changed, 26 insertions(+), 11 deletions(-)

diff --git a/src/libbluray/bluray.c b/src/libbluray/bluray.c
index aad7a85..f030f53 100644
--- a/src/libbluray/bluray.c
+++ b/src/libbluray/bluray.c
@@ -1423,8 +1423,7 @@ BLURAY *bd_init(void)
 
 static int _bd_open(BLURAY *bd,
                     const char *device_path, const char *keyfile_path,
-                    void *read_blocks_handle,
-                    int (*read_blocks)(void *handle, void *buf, int lba, int num_blocks))
+                    fs_access *p_fs)
 {
     BD_ENC_INFO enc_info;
 
@@ -1436,7 +1435,7 @@ static int _bd_open(BLURAY *bd,
         return 0;
     }
 
-    bd->disc = disc_open(device_path, read_blocks_handle, read_blocks,
+    bd->disc = disc_open(device_path, p_fs,
                          &enc_info, keyfile_path,
                          (void*)bd->regs, (void*)bd_psr_read, (void*)bd_psr_write);
 
@@ -1456,7 +1455,7 @@ int bd_open_disc(BLURAY *bd, const char *device_path, const char *keyfile_path)
         return 0;
     }
 
-    return _bd_open(bd, device_path, keyfile_path, NULL, NULL);
+    return _bd_open(bd, device_path, keyfile_path, NULL);
 }
 
 int bd_open_stream(BLURAY *bd,
@@ -1467,7 +1466,8 @@ int bd_open_stream(BLURAY *bd,
         return 0;
     }
 
-    return _bd_open(bd, NULL, NULL, read_blocks_handle, read_blocks);
+    fs_access fs = { read_blocks_handle, read_blocks, NULL, NULL };
+    return _bd_open(bd, NULL, NULL, &fs);
 }
 
 BLURAY *bd_open(const char *device_path, const char *keyfile_path)
diff --git a/src/libbluray/disc/disc.c b/src/libbluray/disc/disc.c
index 0880fa9..82283f7 100644
--- a/src/libbluray/disc/disc.c
+++ b/src/libbluray/disc/disc.c
@@ -249,8 +249,7 @@ static void _set_paths(BD_DISC *p, const char *device_path)
 }
 
 BD_DISC *disc_open(const char *device_path,
-                   void *read_blocks_handle,
-                   int (*read_blocks)(void *handle, void *buf, int lba, int num_blocks),
+                   fs_access *p_fs,
                    struct bd_enc_info *enc_info,
                    const char *keyfile_path,
                    void *regs, void *psr_read, void *psr_write)
@@ -258,13 +257,19 @@ BD_DISC *disc_open(const char *device_path,
     BD_DISC *p = _disc_init();
 
     if (p) {
+        if (p_fs && p_fs->open_dir) {
+            p->fs_handle          = p_fs->fs_handle;
+            p->pf_file_open_bdrom = p_fs->open_file;
+            p->pf_dir_open_bdrom  = p_fs->open_dir;
+        }
+
         _set_paths(p, device_path);
 
 #ifdef ENABLE_UDF
         /* check if disc root directory can be opened. If not, treat it as device/image file. */
         BD_DIR_H *dp_img = device_path ? dir_open(device_path) : NULL;
         if (!dp_img) {
-            void *udf = udf_image_open(device_path, read_blocks_handle, read_blocks);
+            void *udf = udf_image_open(device_path, p_fs ? p_fs->fs_handle : NULL, p_fs ? p_fs->read_blocks : NULL);
             if (!udf) {
                 BD_DEBUG(DBG_FILE | DBG_CRIT, "failed opening UDF image %s\n", device_path);
             } else {
@@ -283,7 +288,6 @@ BD_DISC *disc_open(const char *device_path,
             BD_DEBUG(DBG_FILE, "%s does not seem to be image file or device node\n", device_path);
         }
 #else
-        (void)read_blocks_handle;
         (void)read_blocks;
 #endif
 
diff --git a/src/libbluray/disc/disc.h b/src/libbluray/disc/disc.h
index 8bbde7b..13f91d1 100644
--- a/src/libbluray/disc/disc.h
+++ b/src/libbluray/disc/disc.h
@@ -29,6 +29,18 @@ struct bd_file_s;
 struct bd_dir_s;
 struct bd_enc_info;
 
+/* application provided file system access (optional) */
+typedef struct fs_access {
+    void *fs_handle;
+
+    /* method 1: block (device) access */
+    int (*read_blocks)(void *fs_handle, void *buf, int lba, int num_blocks);
+
+    /* method 2: file access */
+    struct bd_dir_s  *(*open_dir) (void *fs_handle, const char *rel_path);
+    struct bd_file_s *(*open_file)(void *fs_handle, const char *rel_path);
+} fs_access;
+
 /*
  * BluRay Virtual File System
  *
@@ -38,8 +50,7 @@ struct bd_enc_info;
 typedef struct bd_disc BD_DISC;
 
 BD_PRIVATE BD_DISC *disc_open(const char *device_path,
-                              void *read_blocks_handle,
-                              int (*read_blocks)(void *handle, void *buf, int lba, int num_blocks),
+                              fs_access *p_fs,
                               struct bd_enc_info *enc_info,
                               const char *keyfile_path,
                               void *regs, void *psr_read, void *psr_write);



More information about the libbluray-devel mailing list