From 57506b27ed0d567c11bd932cf758318fb3b2079c Mon Sep 17 00:00:00 2001 From: wm4 Date: Tue, 29 Mar 2016 11:29:52 +0200 Subject: cache: use a single STREAM_CTRL for various cache info Instead of having a separate for each, which also requires separate additional caching in the demuxer. (The demuxer adds an indirection, since STREAM_CTRLs are not thread-safe.) Since this includes the cache speed, this should fix #3003. --- stream/cache.c | 33 ++++++++++++++------------------- 1 file changed, 14 insertions(+), 19 deletions(-) (limited to 'stream/cache.c') diff --git a/stream/cache.c b/stream/cache.c index 7fd53c7a6a..0ed371806d 100644 --- a/stream/cache.c +++ b/stream/cache.c @@ -42,6 +42,7 @@ #include #include #include +#include #include #include @@ -401,17 +402,13 @@ static int cache_get_cached_control(stream_t *cache, int cmd, void *arg) { struct priv *s = cache->priv; switch (cmd) { - case STREAM_CTRL_GET_CACHE_SIZE: - *(int64_t *)arg = s->buffer_size - s->back_size; - return STREAM_OK; - case STREAM_CTRL_GET_CACHE_FILL: - *(int64_t *)arg = s->max_filepos - s->read_filepos; - return STREAM_OK; - case STREAM_CTRL_GET_CACHE_IDLE: - *(int *)arg = s->idle; - return STREAM_OK; - case STREAM_CTRL_GET_CACHE_SPEED: - *(double *)arg = s->speed; + case STREAM_CTRL_GET_CACHE_INFO: + *(struct stream_cache_info *)arg = (struct stream_cache_info) { + .size = s->buffer_size - s->back_size, + .fill = s->max_filepos - s->read_filepos, + .idle = s->idle, + .speed = llrint(s->speed), + }; return STREAM_OK; case STREAM_CTRL_SET_READAHEAD: s->enable_readahead = *(int *)arg; @@ -712,17 +709,15 @@ int stream_cache_init(stream_t *cache, stream_t *stream, for (;;) { if (mp_cancel_test(cache->cancel)) return -1; - int64_t fill; - int idle; - if (stream_control(s->cache, STREAM_CTRL_GET_CACHE_FILL, &fill) < 0) - break; - if (stream_control(s->cache, STREAM_CTRL_GET_CACHE_IDLE, &idle) < 0) + struct stream_cache_info info; + if (stream_control(s->cache, STREAM_CTRL_GET_CACHE_INFO, &info) < 0) break; MP_INFO(s, "\rCache fill: %5.2f%% " - "(%" PRId64 " bytes) ", 100.0 * fill / s->buffer_size, fill); - if (fill >= min) + "(%" PRId64 " bytes) ", 100.0 * info.fill / s->buffer_size, + info.fill); + if (info.fill >= min) break; - if (idle) + if (info.idle) break; // file is smaller than prefill size // Wake up if the cache is done reading some data (or on timeout/abort) pthread_mutex_lock(&s->mutex); -- cgit v1.2.3