static void _findMetaXMLfiles(META_ROOT *meta, BD_DISC *disc) { BD_DIR_H *dir; BD_DIRENT ent; dir = disc_open_dir(disc, "BDMV" DIR_SEP "META" DIR_SEP "DL"); if (dir == NULL) { BD_DEBUG(DBG_DIR, "Failed to open meta dir BDMV/META/DL/\n"); return; } int res; for (res = dir_read(dir, &ent); !res; res = dir_read(dir, &ent)) { if (ent.d_name[0] == '.') continue; else if (strncasecmp(ent.d_name, "bdmt_", 5) == 0) { META_DL *new_dl_entries = realloc(meta->dl_entries, ((meta->dl_count + 1)*sizeof(META_DL))); if (new_dl_entries) { uint8_t i = meta->dl_count; meta->dl_count++; meta->dl_entries = new_dl_entries; memset(&meta->dl_entries[i], 0, sizeof(meta->dl_entries[i])); meta->dl_entries[i].filename = str_dup(ent.d_name); strncpy(meta->dl_entries[i].language_code, ent.d_name+5,3); meta->dl_entries[i].language_code[3] = '\0'; str_tolower(meta->dl_entries[i].language_code); } } } dir_close(dir); }
JNIEXPORT jobjectArray JNICALL Java_org_videolan_Libbluray_listBdFilesN(JNIEnv * env, jclass cls, jlong np, jstring jpath, jboolean onlyBdRom) { BLURAY *bd = (BLURAY*)(intptr_t)np; BD_DISC *disc = bd_get_disc(bd); const char *path = (*env)->GetStringUTFChars(env, jpath, NULL); if (!path) { BD_DEBUG(DBG_JNI | DBG_CRIT, "listBdFilesN() failed: no path\n"); return NULL; } BD_DEBUG(DBG_JNI, "listBdFilesN(%s)\n", path); /* open directory stream */ BD_DIR_H *dp; if (onlyBdRom) { dp = disc_open_bdrom_dir(disc, path); } else { dp = disc_open_dir(disc, path); } if (!dp) { BD_DEBUG(DBG_JNI, "failed opening directory %s\n", path); (*env)->ReleaseStringUTFChars(env, jpath, path); return NULL; } (*env)->ReleaseStringUTFChars(env, jpath, path); /* count files and create java strings (java array size must be known when it is created) */ jstring *files = NULL; unsigned count = 0; unsigned allocated = 0; BD_DIRENT ent; while (!dir_read(dp, &ent)) { if (strcmp(ent.d_name, ".") && strcmp(ent.d_name, "..")) { if (allocated <= count) { allocated += 512; jstring *tmp = realloc(files, sizeof(*files) * allocated); if (!tmp) { BD_DEBUG(DBG_JNI | DBG_CRIT, "failed allocating memory for %u directory entries\n", allocated); break; } files = tmp; } files[count] = (*env)->NewStringUTF(env, ent.d_name); count++; } } dir_close(dp); /* allocate java array */ jobjectArray arr = bdj_make_array(env, "java/lang/String", count); if (!arr) { BD_DEBUG(DBG_JNI | DBG_CRIT, "failed creating array [%d]\n", count); } else { /* populate files to array */ unsigned ii; for (ii = 0; ii < count; ii++) { (*env)->SetObjectArrayElement(env, arr, ii, files[ii]); } } X_FREE(files); return arr; }
NAV_TITLE_LIST* nav_get_title_list(BD_DISC *disc, uint32_t flags, uint32_t min_title_length) { BD_DIR_H *dir; BD_DIRENT ent; 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; dir = disc_open_dir(disc, "BDMV" DIR_SEP "PLAYLIST"); if (dir == NULL) { return NULL; } title_list = calloc(1, sizeof(NAV_TITLE_LIST)); title_list->title_info = calloc(title_info_alloc, sizeof(NAV_TITLE_INFO)); ii = 0; for (res = dir_read(dir, &ent); !res; res = dir_read(dir, &ent)) { if (ent.d_name[0] == '.') { continue; } 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) { break; } pl_list = tmp; } pl = mpls_get(disc, ent.d_name); 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 (min_title_length > 0 && _pl_duration(pl) < min_title_length*45000) { 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; /* main title guessing */ if (_filter_dup(pl_list, ii, pl) && _filter_repeats(pl, 2)) { if (_pl_guess_main_title(pl_list[ii], pl_list[title_list->main_title_idx]) <= 0) { 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; 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]); } X_FREE(pl_list); return title_list; }