From ec7bc388d1d87c5a2d64dde85628d49e25a9f8fd Mon Sep 17 00:00:00 2001 From: wm4 Date: Mon, 6 Oct 2014 22:33:21 +0200 Subject: [PATCH] matroska: look for all known matroska file extensions For segment linking (this mechanism matches file extensions to avoid opening files which are most likely not Matroska files in order to speed up scanning). --- player/timeline/tl_matroska.c | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/player/timeline/tl_matroska.c b/player/timeline/tl_matroska.c index 5e69610bd4..6f64ae8484 100644 --- a/player/timeline/tl_matroska.c +++ b/player/timeline/tl_matroska.c @@ -21,6 +21,8 @@ #include #include #include +#include +#include #include #include #include @@ -59,7 +61,20 @@ static int cmp_entry(const void *pa, const void *pb) return 0; } -static char **find_files(const char *original_file, const char *suffix) +static bool test_matroska_ext(const char *filename) +{ + static const char *const exts[] = {".mkv", ".mka", ".mks", ".mk3d", NULL}; + for (int n = 0; exts[n]; n++) { + const char *suffix = exts[n]; + int offset = strlen(filename) - strlen(suffix); + // name must end with suffix + if (offset > 0 && strcasecmp(filename + offset, suffix) == 0) + return true; + } + return false; +} + +static char **find_files(const char *original_file) { void *tmpmem = talloc_new(NULL); char *basename = mp_basename(original_file); @@ -75,9 +90,7 @@ static char **find_files(const char *original_file, const char *suffix) struct dirent *ep; int num_results = 0; while ((ep = readdir(dp))) { - int suffix_offset = strlen(ep->d_name) - strlen(suffix); - // name must end with suffix - if (suffix_offset < 0 || strcmp(ep->d_name + suffix_offset, suffix)) + if (!test_matroska_ext(ep->d_name)) continue; // don't list the original name if (!strcmp(ep->d_name, basename)) @@ -269,7 +282,7 @@ static int find_ordered_chapter_sources(struct MPContext *mpctx, } else { MP_INFO(mpctx, "Will scan other files in the " "same directory to find referenced sources.\n"); - filenames = find_files(main_filename, ".mkv"); + filenames = find_files(main_filename); num_filenames = MP_TALLOC_ELEMS(filenames); talloc_steal(tmp, filenames); }