summaryrefslogtreecommitdiffstats
path: root/player
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2014-10-06 22:33:21 +0200
committerwm4 <wm4@nowhere>2014-10-06 22:33:21 +0200
commitec7bc388d1d87c5a2d64dde85628d49e25a9f8fd (patch)
tree366b3313b85cf298091900113269cd5dd38b136a /player
parenta9e6ba1b9a8756e7c6163f74b3c57ff794a624b6 (diff)
downloadmpv-ec7bc388d1d87c5a2d64dde85628d49e25a9f8fd.tar.bz2
mpv-ec7bc388d1d87c5a2d64dde85628d49e25a9f8fd.tar.xz
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).
Diffstat (limited to 'player')
-rw-r--r--player/timeline/tl_matroska.c23
1 files 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 <inttypes.h>
#include <assert.h>
#include <dirent.h>
+#include <string.h>
+#include <strings.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
@@ -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);
}