summaryrefslogtreecommitdiffstats
path: root/stream/cache.c
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2014-05-24 14:04:09 +0200
committerwm4 <wm4@nowhere>2014-05-24 16:17:51 +0200
commita4d487f5b2930611bf908243510d6f0351ebcf58 (patch)
tree000fc31412c31ea60ef0b7c59af087e6402b4541 /stream/cache.c
parente3c20bf3505679641f247471603ad298d04036bd (diff)
downloadmpv-a4d487f5b2930611bf908243510d6f0351ebcf58.tar.bz2
mpv-a4d487f5b2930611bf908243510d6f0351ebcf58.tar.xz
stream: don't use end_pos
Stop using it in most places, and prefer STREAM_CTRL_GET_SIZE. The advantage is that always the correct size will be used. There can be no doubt anymore whether the end_pos value is outdated (as it happens often with files that are being downloaded). Some streams still use end_pos. They don't change size, and it's easier to emulate STREAM_CTRL_GET_SIZE using end_pos, instead of adding a STREAM_CTRL_GET_SIZE implementation to these streams. Make sure int64_t is always used for STREAM_CTRL_GET_SIZE (it was uint64_t before). Remove the seek flags mess, and replace them with a seekable flag. Every stream must set it consistently now, and an assertion in stream.c checks this. Don't distinguish between streams that can only be forward or backwards seeked, since we have no such stream types.
Diffstat (limited to 'stream/cache.c')
-rw-r--r--stream/cache.c16
1 files changed, 10 insertions, 6 deletions
diff --git a/stream/cache.c b/stream/cache.c
index ad1277fb85..bd9712e341 100644
--- a/stream/cache.c
+++ b/stream/cache.c
@@ -364,6 +364,7 @@ static int resize_cache(struct priv *s, int64_t size)
static void update_cached_controls(struct priv *s)
{
unsigned int ui;
+ int64_t i64;
double d;
char **m;
char *t;
@@ -388,8 +389,9 @@ static void update_cached_controls(struct priv *s)
talloc_free(s->disc_name);
s->disc_name = talloc_steal(s, t);
}
- stream_update_size(s->stream);
- s->stream_size = s->stream->end_pos;
+ s->stream_size = -1;
+ if (stream_control(s->stream, STREAM_CTRL_GET_SIZE, &i64) == STREAM_OK)
+ s->stream_size = i64;
}
// the core might call these every frame, so cache them...
@@ -410,10 +412,13 @@ static int cache_get_cached_control(stream_t *cache, int cmd, void *arg)
*(double *)arg = s->stream_time_length;
return s->stream_time_length ? STREAM_OK : STREAM_UNSUPPORTED;
case STREAM_CTRL_GET_START_TIME:
+ if (s->stream_start_time == MP_NOPTS_VALUE)
+ return STREAM_UNSUPPORTED;
*(double *)arg = s->stream_start_time;
- return s->stream_start_time !=
- MP_NOPTS_VALUE ? STREAM_OK : STREAM_UNSUPPORTED;
+ return STREAM_OK;
case STREAM_CTRL_GET_SIZE:
+ if (s->stream_size < 0)
+ return STREAM_UNSUPPORTED;
*(int64_t *)arg = s->stream_size;
return STREAM_OK;
case STREAM_CTRL_MANAGES_TIMELINE:
@@ -692,8 +697,7 @@ int stream_cache_init(stream_t *cache, stream_t *stream,
if (min > s->buffer_size - FILL_LIMIT)
min = s->buffer_size - FILL_LIMIT;
- s->seekable = (stream->flags & MP_STREAM_SEEK) == MP_STREAM_SEEK &&
- stream->end_pos > 0;
+ s->seekable = stream->seekable;
if (pthread_create(&s->cache_thread, NULL, cache_thread, s) != 0) {
MP_ERR(s, "Starting cache process/thread failed: %s.\n",