From 3cd394995f812aba93166febd1032e3f4208d49b Mon Sep 17 00:00:00 2001 From: wm4 Date: Wed, 4 Mar 2015 12:07:04 +0100 Subject: cache: assume file size from EOF position If we're caching a stream with unknown size, and we reach EOF, then consider the EOF position the file size. Typically makes sense when reading from a pipe or a http connection that did not send a size. --- stream/cache.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'stream') 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); -- cgit v1.2.3