diff options
-rw-r--r-- | DOCS/man/input.rst | 18 | ||||
-rw-r--r-- | misc/node.c | 15 | ||||
-rw-r--r-- | misc/node.h | 3 | ||||
-rw-r--r-- | player/command.c | 47 |
4 files changed, 57 insertions, 26 deletions
diff --git a/DOCS/man/input.rst b/DOCS/man/input.rst index 2f0cd74c94..f591d695ef 100644 --- a/DOCS/man/input.rst +++ b/DOCS/man/input.rst @@ -1259,10 +1259,14 @@ Property list filled to the requested amount, and is currently not reading more data. ``demuxer-cache-state`` - Various undocumented things. Some fields are documented: + Various undocumented or half-documented things. - ``demuxer-cache-state/seekable-start``, ``demuxer-cache-state/seekable-end`` - Seekable range within demuxer cache. Unavailable if not possible. + Each entry in ``seekable-ranges`` represents a region in the demuxer cache + that can be seeked to. If there are multiple demuxers active, this only + returns information about the "main" demuxer, but might be changed in + future to return unified information about all demuxers. There is currently + only at most 1 range. Should the player implement caching for multiple + ranges, the order of the ranges will be unspecified and arbitrary. When querying the property with the client API using ``MPV_FORMAT_NODE``, or with Lua ``mp.get_property_native``, this will return a mpv_node with @@ -1270,9 +1274,11 @@ Property list :: - MPV_FORMAT_NODE_ARRAY - "seekable-start" MPV_FORMAT_DOUBLE - "seekable-end" MPV_FORMAT_DOUBLE + MPV_FORMAT_NODE_MAP + "seekable-ranges" MPV_FORMAT_NODE_ARRAY + MPV_FORMAT_NODE_MAP + "start" MPV_FORMAT_DOUBLE + "end" MPV_FORMAT_DOUBLE ``demuxer-via-network`` Returns ``yes`` if the stream demuxed via the main demuxer is most likely diff --git a/misc/node.c b/misc/node.c index 1ea8ea7da5..73e95e61b0 100644 --- a/misc/node.c +++ b/misc/node.c @@ -63,3 +63,18 @@ void node_map_add_string(struct mpv_node *dst, const char *key, const char *val) entry->format = MPV_FORMAT_STRING; entry->u.string = talloc_strdup(dst->u.list, val); } + +void node_map_add_int64(struct mpv_node *dst, const char *key, int64_t v) +{ + node_map_add(dst, key, MPV_FORMAT_INT64)->u.int64 = v; +} + +void node_map_add_double(struct mpv_node *dst, const char *key, double v) +{ + node_map_add(dst, key, MPV_FORMAT_DOUBLE)->u.double_ = v; +} + +void node_map_add_flag(struct mpv_node *dst, const char *key, bool v) +{ + node_map_add(dst, key, MPV_FORMAT_FLAG)->u.flag = v; +} diff --git a/misc/node.h b/misc/node.h index c3b4501dc8..a1bdab0ae1 100644 --- a/misc/node.h +++ b/misc/node.h @@ -7,5 +7,8 @@ void node_init(struct mpv_node *dst, int format, struct mpv_node *parent); struct mpv_node *node_array_add(struct mpv_node *dst, int format); struct mpv_node *node_map_add(struct mpv_node *dst, const char *key, int format); void node_map_add_string(struct mpv_node *dst, const char *key, const char *val); +void node_map_add_int64(struct mpv_node *dst, const char *key, int64_t v); +void node_map_add_double(struct mpv_node *dst, const char *key, double v); +void node_map_add_flag(struct mpv_node *dst, const char *key, bool v); #endif diff --git a/player/command.c b/player/command.c index a6ffe3256e..5a75681bd1 100644 --- a/player/command.c +++ b/player/command.c @@ -1723,32 +1723,39 @@ static int mp_property_demuxer_cache_state(void *ctx, struct m_property *prop, if (!mpctx->demuxer) return M_PROPERTY_UNAVAILABLE; + if (action == M_PROPERTY_GET_TYPE) { + *(struct m_option *)arg = (struct m_option){.type = CONF_TYPE_NODE}; + return M_PROPERTY_OK; + } + if (action != M_PROPERTY_GET) + return M_PROPERTY_NOT_IMPLEMENTED; + struct demux_ctrl_reader_state s; if (demux_control(mpctx->demuxer, DEMUXER_CTRL_GET_READER_STATE, &s) < 1) return M_PROPERTY_UNAVAILABLE; - bool seek_ok = s.ts_min != MP_NOPTS_VALUE && - s.ts_max != MP_NOPTS_VALUE && - s.seekable; + struct mpv_node *r = (struct mpv_node *)arg; + node_init(r, MPV_FORMAT_NODE_MAP, NULL); - struct m_sub_property props[] = { - {"seekable-start", SUB_PROP_PTS(s.ts_min), - .unavailable = !seek_ok}, - {"seekable-end", SUB_PROP_PTS(s.ts_max), - .unavailable = !seek_ok}, - {"cache-start", SUB_PROP_PTS(s.ts_start), - .unavailable = s.ts_start == MP_NOPTS_VALUE}, - {"cache-end", SUB_PROP_PTS(s.ts_max), - .unavailable = s.ts_max == MP_NOPTS_VALUE}, - {"reader-pts", SUB_PROP_PTS(s.ts_reader), - .unavailable = s.ts_reader == MP_NOPTS_VALUE}, - {"eof", SUB_PROP_FLAG(s.eof)}, - {"underrun", SUB_PROP_FLAG(s.underrun)}, - {"idle", SUB_PROP_FLAG(s.idle)}, - {0} - }; + struct mpv_node *ranges = + node_map_add(r, "seekable-ranges", MPV_FORMAT_NODE_ARRAY); + if (s.ts_min != MP_NOPTS_VALUE && s.ts_max != MP_NOPTS_VALUE && s.seekable) { + struct mpv_node *sub = node_array_add(ranges, MPV_FORMAT_NODE_MAP); + node_map_add_double(sub, "start", s.ts_min); + node_map_add_double(sub, "end", s.ts_max); + } - return m_property_read_sub(props, action, arg); + if (s.ts_start != MP_NOPTS_VALUE) + node_map_add_double(r, "cache-end", s.ts_max); + + if (s.ts_reader != MP_NOPTS_VALUE) + node_map_add_double(r, "reader-pts", s.ts_reader); + + node_map_add_flag(r, "eof", s.eof); + node_map_add_flag(r, "underrun", s.underrun); + node_map_add_flag(r, "idle", s.idle); + + return M_PROPERTY_OK; } static int mp_property_demuxer_start_time(void *ctx, struct m_property *prop, |