summaryrefslogtreecommitdiffstats
path: root/player
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2014-04-09 19:15:23 +0200
committerwm4 <wm4@nowhere>2014-04-09 19:15:23 +0200
commit5f65a5cfea020dc0e3f718da48a937f29eb1993b (patch)
treee1992642765f8a7f7d1492e796db7fd240e17860 /player
parent6ac98c042f16d6b6a6f370905345678b42adf9e8 (diff)
downloadmpv-5f65a5cfea020dc0e3f718da48a937f29eb1993b.tar.bz2
mpv-5f65a5cfea020dc0e3f718da48a937f29eb1993b.tar.xz
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.
Diffstat (limited to 'player')
-rw-r--r--player/command.c29
1 files changed, 29 insertions, 0 deletions
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,