summaryrefslogtreecommitdiffstats
path: root/stream
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2014-07-12 19:16:53 +0200
committerAlessandro Ghedini <alessandro@ghedini.me>2014-07-13 15:06:46 +0200
commitbd0b661183d2a57ab13cacaa2aac31c645444d61 (patch)
treeedb072319e83d139487e283871b614ae2fd1d0f0 /stream
parent0989d8358ca8e9ce7d1e5576adaf1555d472abf9 (diff)
downloadmpv-bd0b661183d2a57ab13cacaa2aac31c645444d61.tar.bz2
mpv-bd0b661183d2a57ab13cacaa2aac31c645444d61.tar.xz
cache_file: fix operation if stream size is unknown
Happens when playing from a pipe. Note that seeking forward doesn't work. It would be possible to create a workaround for that by reading and skipping data until the target position is reached (and writing the skipped data into the cache file), but I'm not sure about that. Fixes #928. CC: @mpv-player/stable
Diffstat (limited to 'stream')
-rw-r--r--stream/cache_file.c5
1 files changed, 3 insertions, 2 deletions
diff --git a/stream/cache_file.c b/stream/cache_file.c
index dfdd8390dc..cd1d5ca64d 100644
--- a/stream/cache_file.c
+++ b/stream/cache_file.c
@@ -66,7 +66,7 @@ static int fill_buffer(stream_t *s, char *buffer, int max_len)
if (s->pos >= p->size - BLOCK_SIZE) {
int64_t new_size = -1;
stream_control(s, STREAM_CTRL_GET_SIZE, &new_size);
- if (new_size != p->size)
+ if (p->size >= 0 && new_size != p->size)
set_bit(p, BLOCK_ALIGN(p->size), 0);
p->size = MPMIN(p->max_size, new_size);
}
@@ -94,7 +94,8 @@ static int fill_buffer(stream_t *s, char *buffer, int max_len)
// align/limit to blocks
max_len = MPMIN(max_len, BLOCK_SIZE - (s->pos % BLOCK_SIZE));
// Limit to max. known file size
- max_len = MPMIN(max_len, p->size - s->pos);
+ if (p->size >= 0)
+ max_len = MPMIN(max_len, p->size - s->pos);
return fread(buffer, 1, max_len, p->cache_file);
}