diff options
author | wm4 <wm4@nowhere> | 2016-03-29 11:29:52 +0200 |
---|---|---|
committer | wm4 <wm4@nowhere> | 2016-03-29 11:29:52 +0200 |
commit | 57506b27ed0d567c11bd932cf758318fb3b2079c (patch) | |
tree | f9bfbdf9ca316546f6de72d16b837411cb95e423 /player | |
parent | e1264d397613b0dac86757d6fd3a4a3494e16868 (diff) | |
download | mpv-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 'player')
-rw-r--r-- | player/command.c | 48 | ||||
-rw-r--r-- | player/misc.c | 19 | ||||
-rw-r--r-- | player/osd.c | 12 | ||||
-rw-r--r-- | player/playloop.c | 5 |
4 files changed, 38 insertions, 46 deletions
diff --git a/player/command.c b/player/command.c index 8ca22eb946..4f6cb1b0ff 100644 --- a/player/command.c +++ b/player/command.c @@ -1370,11 +1370,11 @@ static int mp_property_cache_size(void *ctx, struct m_property *prop, switch (action) { case M_PROPERTY_GET: case M_PROPERTY_PRINT: { - int64_t size = -1; - demux_stream_control(demuxer, STREAM_CTRL_GET_CACHE_SIZE, &size); - if (size <= 0) + struct stream_cache_info info = {0}; + demux_stream_control(demuxer, STREAM_CTRL_GET_CACHE_INFO, &info); + if (info.size <= 0) break; - return property_int_kb_size(size / 1024, action, arg); + return property_int_kb_size(info.size / 1024, action, arg); } case M_PROPERTY_GET_TYPE: *(struct m_option *)arg = (struct m_option){ @@ -1403,11 +1403,11 @@ static int mp_property_cache_used(void *ctx, struct m_property *prop, if (!mpctx->demuxer) return M_PROPERTY_UNAVAILABLE; - int64_t size = -1; - demux_stream_control(mpctx->demuxer, STREAM_CTRL_GET_CACHE_FILL, &size); - if (size < 0) + struct stream_cache_info info = {0}; + demux_stream_control(mpctx->demuxer, STREAM_CTRL_GET_CACHE_INFO, &info); + if (info.size <= 0) return M_PROPERTY_UNAVAILABLE; - return property_int_kb_size(size / 1024, action, arg); + return property_int_kb_size(info.fill / 1024, action, arg); } static int mp_property_cache_free(void *ctx, struct m_property *prop, @@ -1417,17 +1417,12 @@ static int mp_property_cache_free(void *ctx, struct m_property *prop, if (!mpctx->demuxer) return M_PROPERTY_UNAVAILABLE; - int64_t size_used = -1; - demux_stream_control(mpctx->demuxer, STREAM_CTRL_GET_CACHE_FILL, &size_used); - if (size_used < 0) + struct stream_cache_info info = {0}; + demux_stream_control(mpctx->demuxer, STREAM_CTRL_GET_CACHE_INFO, &info); + if (info.size <= 0) return M_PROPERTY_UNAVAILABLE; - int64_t size = -1; - demux_stream_control(mpctx->demuxer, STREAM_CTRL_GET_CACHE_SIZE, &size); - if (size <= 0) - return M_PROPERTY_UNAVAILABLE; - - return property_int_kb_size((size - size_used) / 1024, action, arg); + return property_int_kb_size((info.size - info.fill) / 1024, action, arg); } static int mp_property_cache_speed(void *ctx, struct m_property *prop, @@ -1437,29 +1432,28 @@ static int mp_property_cache_speed(void *ctx, struct m_property *prop, if (!mpctx->demuxer) return M_PROPERTY_UNAVAILABLE; - double f_speed = -1; - demux_stream_control(mpctx->demuxer, STREAM_CTRL_GET_CACHE_SPEED, &f_speed); - if (f_speed < 0) + struct stream_cache_info info = {0}; + demux_stream_control(mpctx->demuxer, STREAM_CTRL_GET_CACHE_INFO, &info); + if (info.size <= 0) return M_PROPERTY_UNAVAILABLE; - int64_t speed = llrint(f_speed); if (action == M_PROPERTY_PRINT) { - *(char **)arg = talloc_strdup_append(format_file_size(speed), "/s"); + *(char **)arg = talloc_strdup_append(format_file_size(info.speed), "/s"); return M_PROPERTY_OK; } - return m_property_int64_ro(action, arg, speed); + return m_property_int64_ro(action, arg, info.speed); } static int mp_property_cache_idle(void *ctx, struct m_property *prop, int action, void *arg) { MPContext *mpctx = ctx; - int idle = -1; + struct stream_cache_info info = {0}; if (mpctx->demuxer) - demux_stream_control(mpctx->demuxer, STREAM_CTRL_GET_CACHE_IDLE, &idle); - if (idle < 0) + demux_stream_control(mpctx->demuxer, STREAM_CTRL_GET_CACHE_INFO, &info); + if (info.size <= 0) return M_PROPERTY_UNAVAILABLE; - return m_property_flag_ro(action, arg, !!idle); + return m_property_flag_ro(action, arg, info.idle); } static int mp_property_demuxer_cache_duration(void *ctx, struct m_property *prop, diff --git a/player/misc.c b/player/misc.c index d68ad1db3e..f14f5a43e3 100644 --- a/player/misc.c +++ b/player/misc.c @@ -95,23 +95,20 @@ double get_play_end_pts(struct MPContext *mpctx) float mp_get_cache_percent(struct MPContext *mpctx) { - if (mpctx->demuxer) { - int64_t size = -1; - int64_t fill = -1; - demux_stream_control(mpctx->demuxer, STREAM_CTRL_GET_CACHE_SIZE, &size); - demux_stream_control(mpctx->demuxer, STREAM_CTRL_GET_CACHE_FILL, &fill); - if (size > 0 && fill >= 0) - return fill / (size / 100.0); - } + struct stream_cache_info info = {0}; + if (mpctx->demuxer) + demux_stream_control(mpctx->demuxer, STREAM_CTRL_GET_CACHE_INFO, &info); + if (info.size > 0 && info.fill >= 0) + return info.fill / (info.size / 100.0); return -1; } bool mp_get_cache_idle(struct MPContext *mpctx) { - int idle = 0; + struct stream_cache_info info = {0}; if (mpctx->demuxer) - demux_stream_control(mpctx->demuxer, STREAM_CTRL_GET_CACHE_IDLE, &idle); - return idle; + demux_stream_control(mpctx->demuxer, STREAM_CTRL_GET_CACHE_INFO, &info); + return info.idle; } void update_vo_playback_state(struct MPContext *mpctx) diff --git a/player/osd.c b/player/osd.c index 1baf9fb45e..8c6d8a3af1 100644 --- a/player/osd.c +++ b/player/osd.c @@ -257,9 +257,9 @@ static void print_status(struct MPContext *mpctx) } if (mpctx->demuxer) { - int64_t fill = -1; - demux_stream_control(mpctx->demuxer, STREAM_CTRL_GET_CACHE_FILL, &fill); - if (fill >= 0) { + struct stream_cache_info info = {0}; + demux_stream_control(mpctx->demuxer, STREAM_CTRL_GET_CACHE_INFO, &info); + if (info.fill >= 0) { saddf(&line, " Cache: "); struct demux_ctrl_reader_state s = {.ts_duration = -1}; @@ -270,10 +270,10 @@ static void print_status(struct MPContext *mpctx) } else { saddf(&line, "%2ds", (int)s.ts_duration); } - if (fill >= 1024 * 1024) { - saddf(&line, "+%lldMB", (long long)(fill / 1024 / 1024)); + if (info.fill >= 1024 * 1024) { + saddf(&line, "+%lldMB", (long long)(info.fill / 1024 / 1024)); } else { - saddf(&line, "+%lldKB", (long long)(fill / 1024)); + saddf(&line, "+%lldKB", (long long)(info.fill / 1024)); } } } diff --git a/player/playloop.c b/player/playloop.c index 63234812d4..fcbb86ac04 100644 --- a/player/playloop.c +++ b/player/playloop.c @@ -522,8 +522,9 @@ static void handle_pause_on_low_cache(struct MPContext *mpctx) if (!mpctx->demuxer) return; - int idle = -1; - demux_stream_control(mpctx->demuxer, STREAM_CTRL_GET_CACHE_IDLE, &idle); + struct stream_cache_info info = {0}; + demux_stream_control(mpctx->demuxer, STREAM_CTRL_GET_CACHE_INFO, &info); + int idle = info.size > 0 ? info.idle : -1; struct demux_ctrl_reader_state s = {.idle = true, .ts_duration = -1}; demux_control(mpctx->demuxer, DEMUXER_CTRL_GET_READER_STATE, &s); |