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.
This commit is contained in:
wm4 2015-03-04 12:07:04 +01:00
parent 771cb34932
commit 3cd394995f
1 changed files with 8 additions and 2 deletions

View File

@ -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);