From 5f65a5cfea020dc0e3f718da48a937f29eb1993b Mon Sep 17 00:00:00 2001 From: wm4 Date: Wed, 9 Apr 2014 19:15:23 +0200 Subject: cache: allow resizing at runtime The only tricky part is keeping the cache contents, which is made simple by allocating the new cache while still keeping the old cache around, and then copying the old data. To explain the "Don't use this when playing DVD or Bluray." comment: the cache also associates timestamps to blocks of bytes, but throws away the timestamps on seek. Thus you will experience strange behavior after resizing the cache until the old cached region is exhausted. --- player/command.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'player') diff --git a/player/command.c b/player/command.c index 9921a055f5..a0adfb2ea3 100644 --- a/player/command.c +++ b/player/command.c @@ -939,6 +939,34 @@ static int mp_property_cache(m_option_t *prop, int action, void *arg, return m_property_int_ro(prop, action, arg, cache); } +static int mp_property_cache_size(m_option_t *prop, int action, void *arg, + void *ctx) +{ + MPContext *mpctx = ctx; + if (!mpctx->stream) + return M_PROPERTY_UNAVAILABLE; + switch (action) { + case M_PROPERTY_GET: { + int64_t size = -1; + stream_control(mpctx->stream, STREAM_CTRL_GET_CACHE_SIZE, &size); + if (size <= 0) + break; + *(int *)arg = size / 1024; + return M_PROPERTY_OK; + } + case M_PROPERTY_SET: { + int64_t size = *(int *)arg * 1024LL; + int r = stream_control(mpctx->stream, STREAM_CTRL_SET_CACHE_SIZE, &size); + if (r == STREAM_UNSUPPORTED) + break; + if (r == STREAM_OK) + return M_PROPERTY_OK; + return M_PROPERTY_ERROR; + } + } + return M_PROPERTY_NOT_IMPLEMENTED; +} + static int mp_property_clock(m_option_t *prop, int action, void *arg, MPContext *mpctx) { @@ -2150,6 +2178,7 @@ static const m_option_t mp_properties[] = { M_PROPERTY("chapter-metadata", mp_property_chapter_metadata), M_OPTION_PROPERTY_CUSTOM("pause", mp_property_pause), { "cache", mp_property_cache, CONF_TYPE_INT }, + { "cache-size", mp_property_cache_size, CONF_TYPE_INT, M_OPT_MIN, 0 }, M_OPTION_PROPERTY("pts-association-mode"), M_OPTION_PROPERTY("hr-seek"), { "clock", mp_property_clock, CONF_TYPE_STRING, -- cgit v1.2.3