From 8bb61f97b435b0ee4a28369ad5a01b1f17d3ef76 Mon Sep 17 00:00:00 2001 From: wm4 Date: Tue, 6 May 2014 20:09:46 +0200 Subject: demux_playlist: allow recognizing format by mime type This commit just adds basic support. The following commit will add actual mime types. --- demux/demux_playlist.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) 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; -- cgit v1.2.3