summaryrefslogtreecommitdiffstats
path: root/stream
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2015-03-04 12:07:04 +0100
committerwm4 <wm4@nowhere>2015-03-04 17:28:42 +0100
commit3cd394995f812aba93166febd1032e3f4208d49b (patch)
treed9db82022ec8c73b34ed6094fe4b396c111f086e /stream
parent771cb349325661d86edab6b1cac46d4ecf765a16 (diff)
downloadmpv-3cd394995f812aba93166febd1032e3f4208d49b.tar.bz2
mpv-3cd394995f812aba93166febd1032e3f4208d49b.tar.xz
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.
Diffstat (limited to 'stream')
-rw-r--r--stream/cache.c10
1 files changed, 8 insertions, 2 deletions
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);