summaryrefslogtreecommitdiffstats
path: root/stream/stream_dvd_common.c
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2014-09-25 23:38:23 +0200
committerwm4 <wm4@nowhere>2014-09-25 23:54:18 +0200
commitd191de856486174faec188ad142ef3ff1b347bd4 (patch)
tree0bf66226ecea6a704b9d204cf465b35a7b9c318b /stream/stream_dvd_common.c
parentd8f993705c8403c527990cce961073c91143d1e7 (diff)
downloadmpv-d191de856486174faec188ad142ef3ff1b347bd4.tar.bz2
mpv-d191de856486174faec188ad142ef3ff1b347bd4.tar.xz
stream_dvd: better .ifo probing
stream_dvd.c includes a pseudo-protocol that recognizes .IFO files, and plays them using libdvdread. This was relatively lazy, and could perhaps easily trigger with files that just had the .ifo extension. Make the checks stricter, and even probe the file header. Apparently the first bytes in an .ifo file are always "DVDVIDEO-VTS", so check for this. Refuse to load the main "video_ts.ifo". The plan is to use stream_dvdnav for it. This also removes at least 1 memory leak.
Diffstat (limited to 'stream/stream_dvd_common.c')
-rw-r--r--stream/stream_dvd_common.c29
1 files changed, 29 insertions, 0 deletions
diff --git a/stream/stream_dvd_common.c b/stream/stream_dvd_common.c
index a9a6895384..99e9067621 100644
--- a/stream/stream_dvd_common.c
+++ b/stream/stream_dvd_common.c
@@ -21,6 +21,9 @@
#include <unistd.h>
#include <stdio.h>
#include <string.h>
+#include <strings.h>
+#include <assert.h>
+
#include <libavutil/intreadwrite.h>
#include "config.h"
@@ -42,6 +45,7 @@
#include "osdep/io.h"
#include "common/msg.h"
+#include "misc/bstr.h"
#include "stream_dvd_common.h"
const char * const dvd_audio_stream_types[8] = { "ac3","unknown","mpeg1","mpeg2ext","lpcm","unknown","dts" };
@@ -134,3 +138,28 @@ int mp_dvdtimetomsec(dvd_time_t *dt)
msec += (((dt->frame_u & 0x30) >> 3) * 5 + (dt->frame_u & 0x0f)) * 100000 / framerate;
return msec;
}
+
+// Check if this is likely to be an .ifo or similar file.
+int dvd_probe(const char *path, const char *ext, const char *sig)
+{
+ if (!bstr_case_endswith(bstr0(path), bstr0(ext)))
+ return false;
+
+ FILE *temp = fopen(path, "rb");
+ if (!temp)
+ return false;
+
+ bool r = false;
+
+ char data[50];
+
+ assert(strlen(sig) <= sizeof(data));
+
+ if (fread(data, 50, 1, temp) == 1) {
+ if (memcmp(data, sig, strlen(sig)) == 0)
+ r = true;
+ }
+
+ fclose(temp);
+ return r;
+}