summaryrefslogtreecommitdiffstats
path: root/player
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2017-10-26 22:26:43 +0200
committerwm4 <wm4@nowhere>2017-10-26 22:31:04 +0200
commitf08ec22567f309edb69184558cacb9af6115e985 (patch)
tree41052a82b1b90b6caf1ad13cea5f346a230b0fe0 /player
parent22fa498bf9968e622e7d6326006c3f321a3bf2e4 (diff)
downloadmpv-f08ec22567f309edb69184558cacb9af6115e985.tar.bz2
mpv-f08ec22567f309edb69184558cacb9af6115e985.tar.xz
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.
Diffstat (limited to 'player')
-rw-r--r--player/command.c47
1 files changed, 27 insertions, 20 deletions
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,