[libbluray-devel] API: add functions to read files from VFS.

hpi1 git at videolan.org
Wed Aug 12 10:08:38 CEST 2015


libbluray | branch: master | hpi1 <hpi1 at anonymous.org> | Wed Aug 12 10:53:53 2015 +0300| [75f2ac72ef1483f48eab9f5a68782d5c7c846185] | committer: hpi1

API: add functions to read files from VFS.

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

 src/libbluray/bluray.c    |   41 ++++++++++++++++++++++++++++++++++++++++-
 src/libbluray/bluray.h    |   32 ++++++++++++++++++++++++++++++++
 src/libbluray/disc/disc.c |    6 +++++-
 3 files changed, 77 insertions(+), 2 deletions(-)

diff --git a/src/libbluray/bluray.c b/src/libbluray/bluray.c
index 8a61e94..458b79b 100644
--- a/src/libbluray/bluray.c
+++ b/src/libbluray/bluray.c
@@ -3575,7 +3575,37 @@ int bd_get_sound_effect(BLURAY *bd, unsigned sound_id, BLURAY_SOUND_EFFECT *effe
 }
 
 /*
- *
+ * Direct file access
+ */
+
+static int _bd_read_file(BLURAY *bd, const char *dir, const char *file, void **data, int64_t *size)
+{
+    if (!bd || !bd->disc || !file || !data || !size) {
+        BD_DEBUG(DBG_CRIT, "Invalid arguments for bd_read_file()\n");
+        return 0;
+    }
+
+    *data = NULL;
+    *size = (int64_t)disc_read_file(bd->disc, dir, file, (uint8_t**)data);
+    if (!*data || *size < 0) {
+        BD_DEBUG(DBG_BLURAY, "bd_read_file() failed\n");
+        X_FREE(*data);
+        return 0;
+    }
+
+    BD_DEBUG(DBG_CRIT, "bd_read_file(): read %"PRId64" bytes from %s"DIR_SEP"%s\n",
+             *size, dir, file);
+    return 1;
+}
+
+int bd_read_file(BLURAY *bd, const char *path, void **data, int64_t *size)
+{
+    return _bd_read_file(bd, NULL, path, data, size);
+}
+
+
+/*
+ * Metadata
  */
 
 const struct meta_dl *bd_get_meta(BLURAY *bd)
@@ -3612,6 +3642,15 @@ const struct meta_dl *bd_get_meta(BLURAY *bd)
     return meta;
 }
 
+int bd_get_meta_file(BLURAY *bd, const char *name, void **data, int64_t *size)
+{
+    return _bd_read_file(bd, DIR_SEP "BDMV" DIR_SEP "META" DIR_SEP "DL", name, data, size);
+}
+
+/*
+ * Database access
+ */
+
 struct clpi_cl *bd_get_clpi(BLURAY *bd, unsigned clip_ref)
 {
     if (bd->title && clip_ref < bd->title->clip_list.count) {
diff --git a/src/libbluray/bluray.h b/src/libbluray/bluray.h
index 6ade74b..50e7e00 100644
--- a/src/libbluray/bluray.h
+++ b/src/libbluray/bluray.h
@@ -355,12 +355,29 @@ const BLURAY_DISC_INFO *bd_get_disc_info(BLURAY *bd);
  *  If information is provided in multiple languages, currently
  *  selected language (BLURAY_PLAYER_SETTING_MENU_LANG) is used.
  *
+ *  Referenced thumbnail images should be read with bd_get_meta_file().
+ *
  * @param bd  BLURAY object
  * @return META_DL (disclib) object, NULL on error
  */
 struct meta_dl;
 const struct meta_dl *bd_get_meta(BLURAY *bd);
 
+/**
+ *
+ *  Read metadata file from BluRay disc.
+ *
+ *  Allocate large enough memory block and read file contents.
+ *  Caller must free the memory block with free().
+ *
+ * @param bd  BLURAY object
+ * @param file_name  name of metadata file
+ * @param data  where to store pointer to file data
+ * @param size  where to store file size
+ * @return 1 on success, 0 on error
+ */
+int bd_get_meta_file(BLURAY *bd, const char *file_name, void **data, int64_t *size);
+
 
 /*
  * Title selection without on-disc menus
@@ -1001,6 +1018,21 @@ void bd_free_bdjo(struct bdjo_data *);
 int  bd_start_bdj(BLURAY *bd, const char* start_object); // start BD-J from the specified BD-J object (should be a 5 character string)
 void bd_stop_bdj(BLURAY *bd); // shutdown BD-J and clean up resources
 
+/**
+ *
+ *  Read a file from BluRay Virtual File System.
+ *
+ *  Allocate large enough memory block and read file contents.
+ *  Caller must free the memory block with free().
+ *
+ * @param bd  BLURAY object
+ * @param file_name  path to the file (relative to disc root)
+ * @param data  where to store pointer to allocated data
+ * @param size  where to store file size
+ * @return 1 on success, 0 on error
+ */
+int bd_read_file(BLURAY *, const char *path, void **data, int64_t *size);
+
 
 #ifdef __cplusplus
 }
diff --git a/src/libbluray/disc/disc.c b/src/libbluray/disc/disc.c
index 32295f2..d808b1c 100644
--- a/src/libbluray/disc/disc.c
+++ b/src/libbluray/disc/disc.c
@@ -399,7 +399,11 @@ size_t disc_read_file(BD_DISC *disc, const char *dir, const char *file,
 
     *data = NULL;
 
-    fp = disc_open_file(disc, dir, file);
+    if (dir) {
+        fp = disc_open_file(disc, dir, file);
+    } else {
+        fp = disc_open_path(disc, file);
+    }
     if (!fp) {
         return 0;
     }



More information about the libbluray-devel mailing list