summaryrefslogtreecommitdiffstats
path: root/stream
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2016-03-29 11:29:52 +0200
committerwm4 <wm4@nowhere>2016-03-29 11:29:52 +0200
commit57506b27ed0d567c11bd932cf758318fb3b2079c (patch)
treef9bfbdf9ca316546f6de72d16b837411cb95e423 /stream
parente1264d397613b0dac86757d6fd3a4a3494e16868 (diff)
downloadmpv-57506b27ed0d567c11bd932cf758318fb3b2079c.tar.bz2
mpv-57506b27ed0d567c11bd932cf758318fb3b2079c.tar.xz
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.
Diffstat (limited to 'stream')
-rw-r--r--stream/cache.c33
-rw-r--r--stream/stream.h13
2 files changed, 23 insertions, 23 deletions
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 <assert.h>
#include <pthread.h>
#include <time.h>
+#include <math.h>
#include <sys/time.h>
#include <libavutil/common.h>
@@ -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);
diff --git a/stream/stream.h b/stream/stream.h
index e6964c2020..21e497e563 100644
--- a/stream/stream.h
+++ b/stream/stream.h
@@ -67,11 +67,8 @@ enum stream_ctrl {
STREAM_CTRL_GET_SIZE = 1,
// Cache
- STREAM_CTRL_GET_CACHE_SIZE,
+ STREAM_CTRL_GET_CACHE_INFO,
STREAM_CTRL_SET_CACHE_SIZE,
- STREAM_CTRL_GET_CACHE_FILL,
- STREAM_CTRL_GET_CACHE_IDLE,
- STREAM_CTRL_GET_CACHE_SPEED,
STREAM_CTRL_SET_READAHEAD,
// stream_memory.c
@@ -122,6 +119,14 @@ enum stream_ctrl {
STREAM_CTRL_SET_CURRENT_TITLE,
};
+// for STREAM_CTRL_GET_CACHE_INFO
+struct stream_cache_info {
+ int64_t size;
+ int64_t fill;
+ bool idle;
+ int64_t speed;
+};
+
struct stream_lang_req {
int type; // STREAM_AUDIO, STREAM_SUB
int id;