1
0
mirror of https://github.com/mpv-player/mpv synced 2025-03-23 20:00:56 +00:00

stream: more consistent checks for whether stream is seekable

Never check s->seek (except in init), because it'd have to check
s->flags anyway. Also, for fast skippable streams (like pipes), don't
set the bit that indicates support for seek forward.

Make sure s->end_pos is always 0 for unseekable streams. Lots of code
outside of stream.c uses this to check seeking support.
This commit is contained in:
wm4 2013-11-03 17:46:36 +01:00
parent 84f7e213ab
commit 22274f7982

View File

@ -318,8 +318,8 @@ static int open_internal(const stream_info_t *sinfo, struct stream *underlying,
if (s->seek && !(s->flags & MP_STREAM_SEEK)) if (s->seek && !(s->flags & MP_STREAM_SEEK))
s->flags |= MP_STREAM_SEEK; s->flags |= MP_STREAM_SEEK;
if (s->flags & MP_STREAM_FAST_SKIPPING) if (!(s->flags & MP_STREAM_SEEK))
s->flags |= MP_STREAM_SEEK_FW; s->end_pos = 0;
s->uncached_type = s->type; s->uncached_type = s->type;
@ -387,7 +387,7 @@ static int stream_reconnect(stream_t *s)
#define RECONNECT_SLEEP_MS 1000 #define RECONNECT_SLEEP_MS 1000
if (!s->streaming) if (!s->streaming)
return 0; return 0;
if (!s->end_pos || !s->seek || !(s->flags & MP_STREAM_SEEK)) if (!(s->flags & MP_STREAM_SEEK_FW))
return 0; return 0;
int64_t pos = s->pos; int64_t pos = s->pos;
for (int retry = 0; retry < MAX_RECONNECT_RETRIES; retry++) { for (int retry = 0; retry < MAX_RECONNECT_RETRIES; retry++) {
@ -603,7 +603,7 @@ static int stream_skip_read(struct stream *s, int64_t len)
static int stream_seek_unbuffered(stream_t *s, int64_t newpos) static int stream_seek_unbuffered(stream_t *s, int64_t newpos)
{ {
if (newpos != s->pos) { if (newpos != s->pos) {
if (!s->seek || !(s->flags & MP_STREAM_SEEK)) { if (newpos > s->pos && !(s->flags & MP_STREAM_SEEK_FW)) {
mp_tmsg(MSGT_STREAM, MSGL_ERR, "Can not seek in this stream\n"); mp_tmsg(MSGT_STREAM, MSGL_ERR, "Can not seek in this stream\n");
return 0; return 0;
} }
@ -630,7 +630,7 @@ static int stream_seek_long(stream_t *s, int64_t pos)
s->eof = 0; s->eof = 0;
if (s->mode == STREAM_WRITE) { if (s->mode == STREAM_WRITE) {
if (!s->seek || !s->seek(s, pos)) if (!(s->flags & MP_STREAM_SEEK) || !s->seek(s, pos))
return 0; return 0;
return 1; return 1;
} }
@ -642,7 +642,9 @@ static int stream_seek_long(stream_t *s, int64_t pos)
mp_msg(MSGT_STREAM, MSGL_DBG3, "Seek from %" PRId64 " to %" PRId64 mp_msg(MSGT_STREAM, MSGL_DBG3, "Seek from %" PRId64 " to %" PRId64
" (with offset %d)\n", s->pos, pos, (int)(pos - newpos)); " (with offset %d)\n", s->pos, pos, (int)(pos - newpos));
if (!s->seek && (s->flags & MP_STREAM_FAST_SKIPPING) && pos >= s->pos) { if (pos >= s->pos && !(s->flags & MP_STREAM_SEEK) &&
(s->flags & MP_STREAM_FAST_SKIPPING))
{
// skipping is handled by generic code below // skipping is handled by generic code below
} else if (stream_seek_unbuffered(s, newpos) >= 0) { } else if (stream_seek_unbuffered(s, newpos) >= 0) {
return 0; return 0;
@ -711,6 +713,8 @@ int stream_control(stream_t *s, int cmd, void *arg)
void stream_update_size(stream_t *s) void stream_update_size(stream_t *s)
{ {
if (!(s->flags & MP_STREAM_SEEK))
return;
uint64_t size; uint64_t size;
if (stream_control(s, STREAM_CTRL_GET_SIZE, &size) == STREAM_OK) { if (stream_control(s, STREAM_CTRL_GET_SIZE, &size) == STREAM_OK) {
if (size > s->end_pos) if (size > s->end_pos)