summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2015-03-04 12:07:04 +0100
committerDiogo Franco (Kovensky) <diogomfranco@gmail.com>2015-03-05 10:47:36 +0900
commit7ee8237e66401c6a3834d41230e9e999b5e26007 (patch)
tree048ca5b60f7d562ead76deb0544041733cd558ea
parent6fc0b4e24bddf0ad5c4813d194bd0cc27d96f44b (diff)
downloadmpv-7ee8237e66401c6a3834d41230e9e999b5e26007.tar.bz2
mpv-7ee8237e66401c6a3834d41230e9e999b5e26007.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. (cherry picked from commit 3cd394995f812aba93166febd1032e3f4208d49b)
-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);