[libbluray-devel] added bd_get_main_title()

hpi1 git at videolan.org
Mon Oct 14 10:06:09 CEST 2013


libbluray | branch: master | hpi1 <hpi1 at anonymous.org> | Mon Oct 14 10:43:07 2013 +0300| [473c316dc03b5c6fbb8073a5fb04f0f9b28a913a] | committer: hpi1

added bd_get_main_title()

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

 ChangeLog                        |    2 +
 src/examples/list_titles.c       |    6 ++-
 src/libbluray/bdnav/navigation.c |   80 +++++---------------------------------
 src/libbluray/bdnav/navigation.h |    3 +-
 src/libbluray/bluray.c           |   14 +++++++
 src/libbluray/bluray.h           |   10 +++++
 6 files changed, 42 insertions(+), 73 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 37f8e3d..55abbfb 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,5 @@
+- Added bd_get_main_title()
+
 2013-09-11: Version 0.4.0
 - Fixed slide shows: always cut reads at clip end boundary
 - Fixed logging with non-default mask
diff --git a/src/examples/list_titles.c b/src/examples/list_titles.c
index e3c53af..0d4f1fa 100644
--- a/src/examples/list_titles.c
+++ b/src/examples/list_titles.c
@@ -46,7 +46,7 @@ static void _usage(char *cmd)
 int main(int argc, char *argv[])
 {
     BLURAY *bd;
-    int count, ii, opt;
+    int count, ii, opt, main_title;
     unsigned int seconds = 0;
     unsigned int flags = TITLES_RELEVANT;
     char *bd_dir = NULL;
@@ -84,6 +84,10 @@ int main(int argc, char *argv[])
     bd = bd_open(bd_dir, NULL);
 
     count = bd_get_titles(bd, flags, seconds);
+    main_title = bd_get_main_title(bd);
+    if (main_title >= 0) {
+        printf("Main title: %d\n", main_title + 1);
+    }
     for (ii = 0; ii < count; ii++)
     {
         BLURAY_TITLE_INFO* ti;
diff --git a/src/libbluray/bdnav/navigation.c b/src/libbluray/bdnav/navigation.c
index c8dc307..ab1890d 100644
--- a/src/libbluray/bdnav/navigation.c
+++ b/src/libbluray/bdnav/navigation.c
@@ -190,6 +190,15 @@ NAV_TITLE_LIST* nav_get_title_list(const char *root, uint32_t flags, uint32_t mi
                 title_list->title_info = tmp;
             }
             pl_list[ii] = pl;
+
+            /* main title guessing */
+            if (_filter_dup(pl_list, ii, pl) &&
+                _filter_repeats(pl, 2)) {
+                if (_pl_duration(pl_list[ii]) >= _pl_duration(pl_list[title_list->main_title_idx])) {
+                    title_list->main_title_idx = ii;
+                }
+            }
+
             strncpy(title_list->title_info[ii].name, ent.d_name, 11);
             title_list->title_info[ii].name[10] = '\0';
             title_list->title_info[ii].ref = ii;
@@ -214,77 +223,6 @@ void nav_free_title_list(NAV_TITLE_LIST *title_list)
     X_FREE(title_list);
 }
 
-char* nav_find_main_title(const char *root)
-{
-    BD_DIR_H *dir;
-    BD_DIRENT ent;
-    char *path = NULL;
-    MPLS_PL **pl_list = NULL;
-    MPLS_PL **tmp = NULL;
-    MPLS_PL *pl = NULL;
-    unsigned count, ii, jj, pl_list_size = 0;
-    int res;
-    char longest[11];
-
-    BD_DEBUG(DBG_NAV, "Root: %s:\n", root);
-    path = str_printf("%s" DIR_SEP "BDMV" DIR_SEP "PLAYLIST", root);
-
-    dir = dir_open(path);
-    if (dir == NULL) {
-        fprintf(stderr, "Failed to open dir: %s\n", path);
-        X_FREE(path);
-        return NULL;
-    }
-    X_FREE(path);
-
-    ii = jj = 0;
-    for (res = dir_read(dir, &ent); !res; res = dir_read(dir, &ent)) {
-
-        if (ent.d_name[0] == '.') {
-            continue;
-        }
-        path = str_printf("%s" DIR_SEP "BDMV" DIR_SEP "PLAYLIST" DIR_SEP "%s",
-                          root, ent.d_name);
-
-        if (ii >= pl_list_size) {
-            pl_list_size += 100;
-            tmp = realloc(pl_list, pl_list_size * sizeof(MPLS_PL*));
-            if (tmp == NULL) {
-                X_FREE(path);
-                break;
-            }
-            pl_list = tmp;
-        }
-        pl = mpls_parse(path);
-        X_FREE(path);
-        if (pl != NULL) {
-            if (_filter_dup(pl_list, ii, pl) &&
-                _filter_repeats(pl, 2)) {
-                pl_list[ii] = pl;
-                if (_pl_duration(pl_list[ii]) >= _pl_duration(pl_list[jj])) {
-                    strncpy(longest, ent.d_name, 11);
-                    longest[10] = '\0';
-                    jj = ii;
-                }
-                ii++;
-            } else {
-                mpls_free(pl);
-            }
-        }
-    }
-    dir_close(dir);
-
-    count = ii;
-    for (ii = 0; ii < count; ii++) {
-        mpls_free(pl_list[ii]);
-    }
-    if (count > 0) {
-        return str_dup(longest);
-    } else {
-        return NULL;
-    }
-}
-
 uint8_t nav_lookup_aspect(NAV_CLIP *clip, int pid)
 {
     CLPI_PROG *progs;
diff --git a/src/libbluray/bdnav/navigation.h b/src/libbluray/bdnav/navigation.h
index 497e903..c6c8939 100644
--- a/src/libbluray/bdnav/navigation.h
+++ b/src/libbluray/bdnav/navigation.h
@@ -133,10 +133,11 @@ struct nav_title_list_s
 {
     unsigned int     count;
     NAV_TITLE_INFO  *title_info;
+
+    unsigned int     main_title_idx;
 };
 
 BD_PRIVATE uint8_t nav_lookup_aspect(NAV_CLIP *clip, int pid);
-BD_PRIVATE char* nav_find_main_title(const char *root);
 BD_PRIVATE NAV_TITLE* nav_title_open(const char *root, const char *playlist, unsigned angle);
 BD_PRIVATE void nav_title_close(NAV_TITLE *title);
 BD_PRIVATE NAV_CLIP* nav_next_clip(NAV_TITLE *title, NAV_CLIP *clip);
diff --git a/src/libbluray/bluray.c b/src/libbluray/bluray.c
index 4324a21..c3d23de 100644
--- a/src/libbluray/bluray.c
+++ b/src/libbluray/bluray.c
@@ -2080,6 +2080,20 @@ uint32_t bd_get_titles(BLURAY *bd, uint8_t flags, uint32_t min_title_length)
     return bd->title_list->count;
 }
 
+int bd_get_main_title(BLURAY *bd)
+{
+    if (bd->title_type != title_undef) {
+        BD_DEBUG(DBG_CRIT | DBG_BLURAY, "bd_get_main_title() can't be used with BluRay menus\n");
+    }
+
+    if (bd->title_list == NULL) {
+        BD_DEBUG(DBG_BLURAY | DBG_CRIT, "Title list not yet read!\n");
+        return -1;
+    }
+
+    return bd->title_list->main_title_idx;
+}
+
 static void _copy_streams(NAV_CLIP *clip, BLURAY_STREAM_INFO *streams, MPLS_STREAM *si, int count)
 {
     int ii;
diff --git a/src/libbluray/bluray.h b/src/libbluray/bluray.h
index b494731..cca42fe 100644
--- a/src/libbluray/bluray.h
+++ b/src/libbluray/bluray.h
@@ -213,6 +213,16 @@ uint32_t bd_get_titles(BLURAY *bd, uint8_t flags, uint32_t min_title_length);
 
 /**
  *
+ *  Get main title
+ *  Returned number is an index to the list created by bd_get_titles()
+ *
+ * @param bd  BLURAY object
+ * @return title index of main title, -1 on error
+ */
+int bd_get_main_title(BLURAY *bd);
+
+/**
+ *
  *  Get information about a title
  *
  * @param bd  BLURAY object



More information about the libbluray-devel mailing list