cache: adjust stream position if necessary

Until now, this could never happen, because new data was simply always
appended to the end of the cache. But for making stream cache resizing
easier, doing it this way seems advantageous. It also makes it harder to
make the internal state inconsistent. (Before this change it could
happen that cache and stream position went out of sync if the read
position was adjusted "inappropriately".)
This commit is contained in:
wm4 2014-04-09 19:06:21 +02:00
parent 80392efaea
commit a967152498
1 changed files with 6 additions and 1 deletions

View File

@ -252,10 +252,15 @@ static bool cache_fill(struct priv *s)
"cached range: %"PRId64"-%"PRId64".\n", read,
s->min_filepos, s->max_filepos);
cache_drop_contents(s);
stream_seek(s->stream, read);
}
}
if (stream_tell(s->stream) != s->max_filepos) {
MP_VERBOSE(s, "Seeking underlying stream: %"PRId64" -> %"PRId64"\n",
stream_tell(s->stream), s->max_filepos);
stream_seek(s->stream, s->max_filepos);
}
// number of buffer bytes which should be preserved in backwards direction
int64_t back = mp_clipi64(read - s->min_filepos, 0, s->back_size);