mirror of
https://github.com/mpv-player/mpv
synced 2025-03-18 17:40:30 +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:
parent
84f7e213ab
commit
22274f7982
@ -318,8 +318,8 @@ static int open_internal(const stream_info_t *sinfo, struct stream *underlying,
|
||||
if (s->seek && !(s->flags & MP_STREAM_SEEK))
|
||||
s->flags |= MP_STREAM_SEEK;
|
||||
|
||||
if (s->flags & MP_STREAM_FAST_SKIPPING)
|
||||
s->flags |= MP_STREAM_SEEK_FW;
|
||||
if (!(s->flags & MP_STREAM_SEEK))
|
||||
s->end_pos = 0;
|
||||
|
||||
s->uncached_type = s->type;
|
||||
|
||||
@ -387,7 +387,7 @@ static int stream_reconnect(stream_t *s)
|
||||
#define RECONNECT_SLEEP_MS 1000
|
||||
if (!s->streaming)
|
||||
return 0;
|
||||
if (!s->end_pos || !s->seek || !(s->flags & MP_STREAM_SEEK))
|
||||
if (!(s->flags & MP_STREAM_SEEK_FW))
|
||||
return 0;
|
||||
int64_t pos = s->pos;
|
||||
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)
|
||||
{
|
||||
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");
|
||||
return 0;
|
||||
}
|
||||
@ -630,7 +630,7 @@ static int stream_seek_long(stream_t *s, int64_t pos)
|
||||
s->eof = 0;
|
||||
|
||||
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 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
|
||||
" (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
|
||||
} else if (stream_seek_unbuffered(s, newpos) >= 0) {
|
||||
return 0;
|
||||
@ -711,6 +713,8 @@ int stream_control(stream_t *s, int cmd, void *arg)
|
||||
|
||||
void stream_update_size(stream_t *s)
|
||||
{
|
||||
if (!(s->flags & MP_STREAM_SEEK))
|
||||
return;
|
||||
uint64_t size;
|
||||
if (stream_control(s, STREAM_CTRL_GET_SIZE, &size) == STREAM_OK) {
|
||||
if (size > s->end_pos)
|
||||
|
Loading…
Reference in New Issue
Block a user