static MPLS_PL* _process_file(char *name, MPLS_PL *pl_list[], int pl_count) { MPLS_PL *pl; pl = mpls_parse(name); if (pl == NULL) { fprintf(stderr, "Parse failed: %s\n", name); return NULL; } if (seconds) { if (!_filter_short(pl, seconds)) { mpls_free(pl); return NULL; } } if (repeats) { if (!_filter_repeats(pl, repeats)) { mpls_free(pl); return NULL; } } if (dups) { if (!_filter_dup(pl_list, pl_count, pl)) { mpls_free(pl); return NULL; } } if (verbose) { indent_printf(0, "%s -- Num Clips: %3d , Duration: minutes %4u:%02u", basename(name), pl->list_count, _pl_duration(pl) / (45000 * 60), (_pl_duration(pl) / 45000) % 60); } else { indent_printf(0, "%s -- Duration: minutes %4u:%02u", basename(name), _pl_duration(pl) / (45000 * 60), (_pl_duration(pl) / 45000) % 60); } if (playlist_info) { _show_details(pl, 1); } if (chapter_marks) { _show_marks(pl, 1); } if (pip_metadata) { _show_pip_metadata(pl, 1); } if (clip_list) { _show_clip_list(pl, 1); } if (sub_paths) { _show_sub_paths(pl, 1); _show_sub_paths_ss(pl, 1); } return pl; }
NAV_TITLE* nav_title_open(const char *root, const char *playlist) { NAV_TITLE *title = NULL; char *path; unsigned ii, ss, chapters = 0; uint32_t pos = 0; uint32_t time = 0; title = calloc(1, sizeof(NAV_TITLE)); if (title == NULL) { return NULL; } title->root = (char*)malloc(strlen(root) + 1); strcpy(title->root, root); strncpy(title->name, playlist, 11); title->name[10] = '\0'; path = str_printf("%s" DIR_SEP "BDMV" DIR_SEP "PLAYLIST" DIR_SEP "%s", root, playlist); title->angle_count = 0; title->angle = 0; title->pl = mpls_parse(path, 0); if (title->pl == NULL) { BD_DEBUG(DBG_NAV, "Fail: Playlist parse %s\n", path); X_FREE(title); X_FREE(path); return NULL; } X_FREE(path); // Find length in packets and end_pkt for each clip title->clip_list.count = title->pl->list_count; title->clip_list.clip = calloc(title->pl->list_count, sizeof(NAV_CLIP)); title->packets = 0; for (ii = 0; ii < title->pl->list_count; ii++) { MPLS_PI *pi; NAV_CLIP *clip; pi = &title->pl->play_item[ii]; clip = &title->clip_list.clip[ii]; _fill_clip(title, pi->clip, pi->connection_condition, pi->in_time, pi->out_time, clip, ii, &pos, &time); } // sub paths // Find length in packets and end_pkt for each clip if (title->pl->sub_count > 0) { title->sub_path_count = title->pl->sub_count; title->sub_path = calloc(title->sub_path_count, sizeof(NAV_SUB_PATH)); for (ss = 0; ss < title->sub_path_count; ss++) { NAV_SUB_PATH *sub_path = &title->sub_path[ss]; sub_path->type = title->pl->sub_path[ss].type; sub_path->clip_list.count = title->pl->sub_path[ss].sub_playitem_count; sub_path->clip_list.clip = calloc(sub_path->clip_list.count, sizeof(NAV_CLIP)); pos = time = 0; for (ii = 0; ii < sub_path->clip_list.count; ii++) { MPLS_SUB_PI *pi = &title->pl->sub_path[ss].sub_play_item[ii]; NAV_CLIP *clip = &sub_path->clip_list.clip[ii]; _fill_clip(title, pi->clip, pi->connection_condition, pi->in_time, pi->out_time, clip, ii, &pos, &time); } } } // Count the number of "entry" marks (skipping "link" marks) // This is the the number of chapters for (ii = 0; ii < title->pl->mark_count; ii++) { if (title->pl->play_mark[ii].mark_type == BD_MARK_ENTRY) { chapters++; } } title->chap_list.count = chapters; title->chap_list.mark = calloc(chapters, sizeof(NAV_MARK)); title->mark_list.count = title->pl->mark_count; title->mark_list.mark = calloc(title->pl->mark_count, sizeof(NAV_MARK)); _extrapolate_title(title); return title; }
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, 0); 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) { char *str = (char*)malloc(strlen(longest) + 1); strcpy(str, longest); return str; } else { return NULL; } }
NAV_TITLE_LIST* nav_get_title_list(const char *root, uint32_t flags) { BD_DIR_H *dir; BD_DIRENT ent; char *path = NULL; MPLS_PL **pl_list = NULL; MPLS_PL *pl = NULL; unsigned int ii, pl_list_size = 0; int res; NAV_TITLE_LIST *title_list; unsigned int title_info_alloc = 100; title_list = calloc(1, sizeof(NAV_TITLE_LIST)); title_list->title_info = calloc(title_info_alloc, sizeof(NAV_TITLE_INFO)); 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) { BD_DEBUG(DBG_NAV, "Failed to open dir: %s\n", path); X_FREE(path); X_FREE(title_list); return NULL; } X_FREE(path); ii = 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) { MPLS_PL **tmp = NULL; 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, 0); X_FREE(path); if (pl != NULL) { if ((flags & TITLES_FILTER_DUP_TITLE) && !_filter_dup(pl_list, ii, pl)) { mpls_free(pl); continue; } if ((flags & TITLES_FILTER_DUP_CLIP) && !_filter_repeats(pl, 2)) { mpls_free(pl); continue; } if (ii >= title_info_alloc) { NAV_TITLE_INFO *tmp = NULL; title_info_alloc += 100; tmp = realloc(title_list->title_info, title_info_alloc * sizeof(NAV_TITLE_INFO)); if (tmp == NULL) { break; } title_list->title_info = tmp; } pl_list[ii] = pl; 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; title_list->title_info[ii].mpls_id = atoi(ent.d_name); title_list->title_info[ii].duration = _pl_duration(pl_list[ii]); ii++; } } dir_close(dir); title_list->count = ii; for (ii = 0; ii < title_list->count; ii++) { mpls_free(pl_list[ii]); } return title_list; }
static MPLS_PL * bd_title_filter(BLURAY *bd, uint32_t count, BLURAY_TITLE_MPLS_ID *title, int is_dir, char *filepath, int *title_id, int *mpls_id) { MPLS_PL *pl = NULL, *pl_tmp = NULL; MPLS_PI *pi = NULL, *pi_tmp = NULL; int chapter_count, chapter_count_tmp; char *path = NULL; int ii; for (ii = 0; ii < count; ii++) { if (is_dir == 1) { path = str_printf("%s/BDMV/PLAYLIST/%05d.mpls", filepath, title[ii].mpls_id); } else { path = str_printf("/BDMV/PLAYLIST/%05d.mpls", title[ii].mpls_id); } if (pl == NULL) { pl = mpls_parse(path, 0, bd_get_udfdata(bd)); if (pl != NULL) { pi = &pl->play_item[0]; *title_id = (int)title[ii].title_id; *mpls_id = (int)title[ii].mpls_id; chapter_count = bd_get_chapters(pl); } } else { pl_tmp = mpls_parse(path, 0, bd_get_udfdata(bd)); if (pl_tmp != NULL) { pi_tmp = &pl_tmp->play_item[0]; chapter_count_tmp = bd_get_chapters(pl_tmp); mp_msg("filter playlist 1: c: %d, v: %d, a: %d, s: %d, d: %d\n", chapter_count, pi->stn.num_video, pi->stn.num_audio, pi->stn.num_pg, _pl_duration(pl)/45000); mp_msg("filter playlist 2: c: %d, v: %d, a: %d, s: %d, d: %d\n", chapter_count_tmp, pi_tmp->stn.num_video, pi_tmp->stn.num_audio, pi_tmp->stn.num_pg, _pl_duration(pl_tmp)/45000); if ( ((pi_tmp->stn.num_pg > 0) && (pi->stn.num_pg > pi_tmp->stn.num_pg)) && \ ((pi_tmp->stn.num_audio > 0) && (pi_tmp->stn.num_audio >= pi->stn.num_audio - 1)) && \ (chapter_count_tmp >= chapter_count) ) { mpls_free(pl); pl = pl_tmp; pi = &pl->play_item[0]; chapter_count = chapter_count_tmp; *title_id = (int)title[ii].title_id; *mpls_id = (int)title[ii].mpls_id; } else { #if 1 //Barry 2011-07-13 fix mantis: 5192 if ((_pl_duration(pl)/45000) > 60000) { mpls_free(pl); pl = pl_tmp; pi = &pl->play_item[0]; chapter_count = chapter_count_tmp; *title_id = (int)title[ii].title_id; *mpls_id = (int)title[ii].mpls_id; } else #endif mpls_free(pl_tmp); } } } if (path != NULL) free(path); } return pl; }