summaryrefslogtreecommitdiffstats
path: root/demux/demux_playlist.c
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2014-05-06 20:09:46 +0200
committerwm4 <wm4@nowhere>2014-05-06 20:09:46 +0200
commit8bb61f97b435b0ee4a28369ad5a01b1f17d3ef76 (patch)
tree41b66f3d5cea002e3d02c54e8e7fc1dce04bd660 /demux/demux_playlist.c
parentb7669d533b20787bbe4daafffe39ee781605d6c9 (diff)
downloadmpv-8bb61f97b435b0ee4a28369ad5a01b1f17d3ef76.tar.bz2
mpv-8bb61f97b435b0ee4a28369ad5a01b1f17d3ef76.tar.xz
demux_playlist: allow recognizing format by mime type
This commit just adds basic support. The following commit will add actual mime types.
Diffstat (limited to 'demux/demux_playlist.c')
-rw-r--r--demux/demux_playlist.c21
1 files changed, 21 insertions, 0 deletions
diff --git a/demux/demux_playlist.c b/demux/demux_playlist.c
index 2f4fb130ef..01c4cae619 100644
--- a/demux/demux_playlist.c
+++ b/demux/demux_playlist.c
@@ -155,8 +155,12 @@ static int parse_txt(struct pl_parser *p)
struct pl_format {
const char *name;
int (*parse)(struct pl_parser *p);
+ const char **mime_types;
};
+#define MIME_TYPES(...) \
+ .mime_types = (const char*[]){__VA_ARGS__, NULL}
+
static const struct pl_format formats[] = {
{"m3u", parse_m3u},
{"ini", parse_ref_init},
@@ -165,12 +169,28 @@ static const struct pl_format formats[] = {
{"txt", parse_txt},
};
+static bool check_mimetype(struct stream *s, const char **list)
+{
+ if (s->mime_type) {
+ for (int n = 0; list && list[n]; n++) {
+ if (strcmp(s->mime_type, list[n]) == 0)
+ return true;
+ }
+ }
+ return false;
+}
+
static const struct pl_format *probe_pl(struct pl_parser *p)
{
int64_t start = stream_tell(p->s);
for (int n = 0; n < MP_ARRAY_SIZE(formats); n++) {
const struct pl_format *fmt = &formats[n];
stream_seek(p->s, start);
+ if (check_mimetype(p->s, fmt->mime_types)) {
+ MP_VERBOSE(p, "forcing format by mime-type.\n");
+ p->force = true;
+ return fmt;
+ }
if (fmt->parse(p) >= 0)
return fmt;
}
@@ -187,6 +207,7 @@ static int open_file(struct demuxer *demuxer, enum demux_check check)
bstr probe_buf = stream_peek(demuxer->stream, PROBE_SIZE);
p->s = open_memory_stream(probe_buf.start, probe_buf.len);
+ p->s->mime_type = demuxer->stream->mime_type;
p->utf16 = stream_skip_bom(p->s);
p->force = force;
p->probing = true;