summaryrefslogtreecommitdiffstats
path: root/stream
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2013-08-25 20:40:21 +0200
committerwm4 <wm4@nowhere>2013-08-26 10:09:45 +0200
commit8be9c49fcd8b23463199036eda5fc290ded6d078 (patch)
tree285f8a1cdcd89c8da9f8a50631a1af5176a783b1 /stream
parentddc973344685b8fee1d7b00e23ba93692d56d7c9 (diff)
downloadmpv-8be9c49fcd8b23463199036eda5fc290ded6d078.tar.bz2
mpv-8be9c49fcd8b23463199036eda5fc290ded6d078.tar.xz
core: add a playlist demuxer
Modeled after the old playlist_parser.c, but actually new code, and it works a bit differently. Demuxers (and sometimes streams) are the component that should be used to open files and to determine the file format. This was already done for subtitles, but playlists still use a separate code path.
Diffstat (limited to 'stream')
-rw-r--r--stream/stream.c18
-rw-r--r--stream/stream.h2
2 files changed, 20 insertions, 0 deletions
diff --git a/stream/stream.c b/stream/stream.c
index b17b7fc19a..4650535890 100644
--- a/stream/stream.c
+++ b/stream/stream.c
@@ -742,6 +742,7 @@ static int stream_enable_cache(stream_t **stream, int64_t size, int64_t min,
cache->url = talloc_strdup(cache, orig->url);
cache->mime_type = talloc_strdup(cache, orig->mime_type);
cache->lavf_type = talloc_strdup(cache, orig->lavf_type);
+ cache->safe_origin = orig->safe_origin;
cache->opts = orig->opts;
cache->start_pos = orig->start_pos;
cache->end_pos = orig->end_pos;
@@ -862,6 +863,8 @@ unsigned char *stream_read_line(stream_t *s, unsigned char *mem, int max,
int len;
const unsigned char *end;
unsigned char *ptr = mem;
+ if (utf16 == -1)
+ utf16 = 0;
if (max < 1)
return NULL;
max--; // reserve one for 0-termination
@@ -891,6 +894,21 @@ unsigned char *stream_read_line(stream_t *s, unsigned char *mem, int max,
return mem;
}
+static const char *bom[3] = {"\xEF\xBB\xBF", "\xFF\xFE", "\xFE\xFF"};
+
+// Return utf16 argument for stream_read_line
+int stream_skip_bom(struct stream *s)
+{
+ bstr data = stream_peek(s, 4);
+ for (int n = 0; n < 3; n++) {
+ if (bstr_startswith0(data, bom[n])) {
+ stream_skip(s, strlen(bom[n]));
+ return n;
+ }
+ }
+ return -1; // default to 8 bit codepages
+}
+
// Read the rest of the stream into memory (current pos to EOF), and return it.
// talloc_ctx: used as talloc parent for the returned allocation
// max_size: must be set to >0. If the file is larger than that, it is treated
diff --git a/stream/stream.h b/stream/stream.h
index f19ab4203f..27043206c9 100644
--- a/stream/stream.h
+++ b/stream/stream.h
@@ -150,6 +150,7 @@ typedef struct stream {
char *mime_type; // when HTTP streaming is used
char *demuxer; // request demuxer to be used
char *lavf_type; // name of expected demuxer type for lavf
+ bool safe_origin; // used for playlists that can be opened safely
struct MPOpts *opts;
FILE *capture_file;
@@ -208,6 +209,7 @@ inline static uint64_t stream_read_qword(stream_t *s)
unsigned char *stream_read_line(stream_t *s, unsigned char *mem, int max,
int utf16);
+int stream_skip_bom(struct stream *s);
inline static int stream_eof(stream_t *s)
{