diff options
Diffstat (limited to 'stream')
-rw-r--r-- | stream/stream.c | 14 | ||||
-rw-r--r-- | stream/stream.h | 4 | ||||
-rw-r--r-- | stream/stream_libarchive.c | 2 |
3 files changed, 10 insertions, 10 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; } } diff --git a/stream/stream.h b/stream/stream.h index 4a38d28109..d054e54914 100644 --- a/stream/stream.h +++ b/stream/stream.h @@ -121,7 +121,7 @@ typedef struct stream { void (*close)(struct stream *s); int64_t pos; - int eof; + int eof; // valid only after read calls that returned a short result int mode; //STREAM_READ or STREAM_WRITE void *priv; // used for DVD, TV, RTSP etc char *url; // filename/url (possibly including protocol prefix) @@ -194,7 +194,7 @@ inline static int64_t stream_tell(stream_t *s) return s->pos + s->buf_cur - s->buf_end; } -bool stream_skip(stream_t *s, int64_t len); +bool stream_seek_skip(stream_t *s, int64_t pos); bool stream_seek(stream_t *s, int64_t pos); int stream_read(stream_t *s, void *mem, int total); int stream_read_partial(stream_t *s, void *buf, int buf_size); diff --git a/stream/stream_libarchive.c b/stream/stream_libarchive.c index ab8fda0f34..e3109dfb0a 100644 --- a/stream/stream_libarchive.c +++ b/stream/stream_libarchive.c @@ -84,7 +84,7 @@ static int64_t skip_cb(struct archive *arch, void *priv, int64_t request) if (!volume_seek(vol)) return -1; int64_t old = stream_tell(vol->src); - stream_skip(vol->src, request); + stream_seek_skip(vol->src, old + request); return stream_tell(vol->src) - old; } |