[libbluray-devel] disc: split disc_open()

hpi1 git at videolan.org
Fri Mar 20 13:43:39 CET 2015


libbluray | branch: master | hpi1 <hpi1 at anonymous.org> | Fri Mar 20 13:22:52 2015 +0200| [ed345b0c4784efbdaeaff37370b92c260b2c3669] | committer: hpi1

disc: split disc_open()

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

 src/libbluray/disc/disc.c |   35 ++++++++++++++++++++++++-----------
 1 file changed, 24 insertions(+), 11 deletions(-)

diff --git a/src/libbluray/disc/disc.c b/src/libbluray/disc/disc.c
index d3a280a..2c904d0 100644
--- a/src/libbluray/disc/disc.c
+++ b/src/libbluray/disc/disc.c
@@ -201,31 +201,44 @@ static BD_DIR_H *_combine_dirs(BD_DIR_H *ovl, BD_DIR_H *rom)
  * disc open / close
  */
 
-BD_DISC *disc_open(const char *device_path,
-                   struct bd_enc_info *enc_info,
-                   const char *keyfile_path,
-                   void *regs, void *psr_read, void *psr_write)
+static BD_DISC *_disc_init()
 {
     BD_DISC *p = calloc(1, sizeof(BD_DISC));
-
     if (p) {
+        bd_mutex_init(&p->ovl_mutex);
+
+        /* default file access functions */
+        p->fs_handle          = (void*)p;
+        p->pf_file_open_bdrom = _bdrom_open_path;
+        p->pf_dir_open_bdrom  = _bdrom_open_dir;
+    }
+    return p;
+}
 
+static void _set_paths(BD_DISC *p, const char *device_path)
+{
+    if (device_path) {
         char *disc_root = mount_get_mountpoint(device_path);
 
         /* make sure path ends to slash */
-        if (disc_root[0] && disc_root[strlen(disc_root) - 1] == DIR_SEP_CHAR) {
+        if (!disc_root || (disc_root[0] && disc_root[strlen(disc_root) - 1] == DIR_SEP_CHAR)) {
             p->disc_root = disc_root;
         } else {
             p->disc_root = str_printf("%s%c", disc_root, DIR_SEP_CHAR);
             X_FREE(disc_root);
         }
+    }
+}
 
-        bd_mutex_init(&p->ovl_mutex);
+BD_DISC *disc_open(const char *device_path,
+                   struct bd_enc_info *enc_info,
+                   const char *keyfile_path,
+                   void *regs, void *psr_read, void *psr_write)
+{
+    BD_DISC *p = _disc_init();
 
-        /* default file access functions */
-        p->fs_handle          = (void*)p;
-        p->pf_file_open_bdrom = _bdrom_open_path;
-        p->pf_dir_open_bdrom  = _bdrom_open_dir;
+    if (p) {
+        _set_paths(p, device_path);
 
 #ifdef ENABLE_UDF
         /* check if disc root directory can be opened. If not, treat it as device/image file. */



More information about the libbluray-devel mailing list