command: change demuxer-cache-state property to return multiple ranges

Even if the demuxer cache does not multiple ranges yet. This is to
reduce the pain should caching of multiple ranges ever be implemented.

Also change it from the sub properties stuff to return a mpv_node
directly, which is less roundabout. Sub-property access won't work
anymore, though.

Remove the seekable-start/-end fields as well, as they're redundant with
the ranges.

All this would normally be considered an API change, but since it's been
only a few days with no known users, change it immediately.

This adds some node.c helpers as well, as the code would be too damn
fugly otherwise.
This commit is contained in:
wm4 2017-10-26 22:26:43 +02:00
parent 22fa498bf9
commit f08ec22567
4 changed files with 57 additions and 26 deletions

View File

@ -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

View File

@ -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;
}

View File

@ -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

View File

@ -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,