Commit 473c316d authored by hpi1's avatar hpi1

added bd_get_main_title()

parent 02f87179
- 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
......
......@@ -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;
......
......@@ -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;
......
......@@ -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);
......
......@@ -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;
......
......@@ -211,6 +211,16 @@ void bd_get_version(int *major, int *minor, int *micro);
*/
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
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment