summaryrefslogtreecommitdiffstats
path: root/stream/stream.c
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2019-11-14 12:59:14 +0100
committerwm4 <wm4@nowhere>2019-11-14 12:59:14 +0100
commitac7f67b3f23a63e463fb881d960bc8f31a230292 (patch)
tree5d40b4c6a9df371dde1317b2a758b50f7df68439 /stream/stream.c
parentdcc3c2eb3877f9876cc218b1e5f1187b81036c49 (diff)
downloadmpv-ac7f67b3f23a63e463fb881d960bc8f31a230292.tar.bz2
mpv-ac7f67b3f23a63e463fb881d960bc8f31a230292.tar.xz
demux_mkv, stream: attempt to improve behavior in unseekable streams
stream_skip() semantics were kind of bad, especially after the recent change to the stream code. Forward stream_skip() calls could still trigger a seek and fail, even if it was supposed to actually skip data. (Maybe the idea that stream_skip() should try to seek is worthless in the first place.) Rename it to stream_seek_skip() (takes absolute position now because I think that's better), and make it always skip if the stream is marked as forward. While we're at it, make EOF detection more robust. I guess s->eof shouldn't exist at all, since it's valid only "sometimes". It should be removed... but not today. A 1-byte stream_read_peek() call is good to get the s->eof flag set to a correct value.
Diffstat (limited to 'stream/stream.c')
-rw-r--r--stream/stream.c14
1 files changed, 7 insertions, 7 deletions
diff --git a/stream/stream.c b/stream/stream.c
index 7fd6700cdd..271e268a1c 100644
--- a/stream/stream.c
+++ b/stream/stream.c
@@ -692,13 +692,13 @@ bool stream_seek(stream_t *s, int64_t pos)
return stream_seek_unbuffered(s, pos);
}
-bool stream_skip(stream_t *s, int64_t len)
+// Like stream_seek(), but strictly prefer skipping data instead of failing, if
+// it's a forward-seek.
+bool stream_seek_skip(stream_t *s, int64_t pos)
{
- if (!stream_seek(s, stream_tell(s) + len))
- return false;
- // Make sure s->eof is set correctly, even if a seek happened.
- stream_read_more(s, 1);
- return true;
+ return !s->seekable && pos > stream_tell(s)
+ ? stream_skip_read(s, pos - stream_tell(s))
+ : stream_seek(s, pos);
}
int stream_control(stream_t *s, int cmd, void *arg)
@@ -732,7 +732,7 @@ int stream_skip_bom(struct stream *s)
bstr data = {buf, len};
for (int n = 0; n < 3; n++) {
if (bstr_startswith0(data, bom[n])) {
- stream_skip(s, strlen(bom[n]));
+ stream_seek_skip(s, stream_tell(s) + strlen(bom[n]));
return n;
}
}