diff --git a/stream/cache.c b/stream/cache.c index fafd76a4ab..edfe3ef4ab 100644 --- a/stream/cache.c +++ b/stream/cache.c @@ -102,6 +102,9 @@ struct priv { int64_t reads; // number of actual read attempts performed int64_t read_filepos; // client read position (mirrors cache->pos) + + int64_t eof_pos; + int control; // requested STREAM_CTRL_... or CACHE_CTRL_... void *control_arg; // temporary for executing STREAM_CTRLs int control_res; @@ -277,8 +280,10 @@ done: s->eof = len <= 0; s->idle = s->eof; s->reads++; - if (s->eof) + if (s->eof) { + s->eof_pos = stream_tell(s->stream); MP_TRACE(s, "EOF reached.\n"); + } pthread_cond_signal(&s->wakeup); @@ -352,7 +357,7 @@ static void update_cached_controls(struct priv *s) talloc_free(s->stream_metadata); s->stream_metadata = talloc_steal(s, tags); } - s->stream_size = -1; + s->stream_size = s->eof_pos; if (stream_control(s->stream, STREAM_CTRL_GET_SIZE, &i64) == STREAM_OK) s->stream_size = i64; s->has_avseek = stream_control(s->stream, STREAM_CTRL_HAS_AVSEEK, NULL) > 0; @@ -610,6 +615,7 @@ int stream_cache_init(stream_t *cache, stream_t *stream, struct priv *s = talloc_zero(NULL, struct priv); s->log = cache->log; + s->eof_pos = -1; cache_drop_contents(s);