From b4f24544bbfdd2bec765db08f5d745fadeb4d111 Mon Sep 17 00:00:00 2001 From: wm4 Date: Thu, 31 Jul 2014 04:19:41 +0200 Subject: client API: make "cache" property and similar observable Achieve this by polling. Will be used by the OSC. Basically a bad hack - but the point is that the mpv core itself is in the best position to improve this later. --- libmpv/client.h | 1 + player/command.c | 1 + player/command.h | 3 +++ player/core.h | 1 + player/playloop.c | 12 ++++++++++++ 5 files changed, 18 insertions(+) diff --git a/libmpv/client.h b/libmpv/client.h index 9abba6434b..69bc77c0ac 100644 --- a/libmpv/client.h +++ b/libmpv/client.h @@ -983,6 +983,7 @@ typedef enum mpv_event_id { * Happens when the current chapter changes. */ MPV_EVENT_CHAPTER_CHANGE = 23 + // Internal note: adjust INTERNAL_EVENT_BASE when adding new events. } mpv_event_id; /** diff --git a/player/command.c b/player/command.c index eedbc0bbc7..27fcadcb29 100644 --- a/player/command.c +++ b/player/command.c @@ -2792,6 +2792,7 @@ static const char *const *const mp_event_property_change[] = { "samplerate", "channels", "audio"), E(MPV_EVENT_METADATA_UPDATE, "metadata"), E(MPV_EVENT_CHAPTER_CHANGE, "chapter", "chapter-metadata"), + E(MP_EVENT_CACHE_UPDATE, "cache", "cache-free", "cache-used"), }; #undef E diff --git a/player/command.h b/player/command.h index 846067b3bf..c9a07ff733 100644 --- a/player/command.h +++ b/player/command.h @@ -39,4 +39,7 @@ int mp_find_property_index(const char *property); void mp_notify(struct MPContext *mpctx, int event, void *arg); void mp_notify_property(struct MPContext *mpctx, const char *property); +#define INTERNAL_EVENT_BASE 24 +#define MP_EVENT_CACHE_UPDATE (INTERNAL_EVENT_BASE + 0) + #endif /* MPLAYER_COMMAND_H */ diff --git a/player/core.h b/player/core.h index 6b3cf55f8b..dd5d975038 100644 --- a/player/core.h +++ b/player/core.h @@ -306,6 +306,7 @@ typedef struct MPContext { double next_heartbeat; double last_idle_tick; + double next_cache_update; double sleeptime; // number of seconds to sleep before next iteration diff --git a/player/playloop.c b/player/playloop.c index 90d46cc178..b1d3efeecf 100644 --- a/player/playloop.c +++ b/player/playloop.c @@ -541,6 +541,18 @@ static void handle_pause_on_low_cache(struct MPContext *mpctx) opts->pause = prev_paused_user; } } + // Also update cache properties. + if (cache_kb > 0 || mpctx->next_cache_update > 0) { + double now = mp_time_sec(); + if (mpctx->next_cache_update <= now) { + mpctx->next_cache_update = cache_kb > 0 ? now + 0.25 : 0; + mp_notify(mpctx, MP_EVENT_CACHE_UPDATE, NULL); + } + if (mpctx->next_cache_update > 0) { + mpctx->sleeptime = + MPMIN(mpctx->sleeptime, mpctx->next_cache_update - now); + } + } } static void handle_heartbeat_cmd(struct MPContext *mpctx) -- cgit v1.2.3