From 34cfe9d89b19b3080bf62168803a8cb239c03c4c Mon Sep 17 00:00:00 2001 From: Ripose Date: Mon, 12 Jul 2021 11:29:59 -0700 Subject: [PATCH] command: add secondary-sub-start and secondary-sub-end properties Adds secondary-sub-start and secondary-sub-end properties by setting the current_track index in the m_property's priv variable which later gets accessed in get_times. Also adds a test of the secondary subtitle time properties in tests/subtimes.js bound to 'T'. --- DOCS/man/input.rst | 6 ++++++ player/command.c | 15 +++++++++++---- test/subtimes.js | 8 ++++++++ 3 files changed, 25 insertions(+), 4 deletions(-) diff --git a/DOCS/man/input.rst b/DOCS/man/input.rst index 66f7dbdace..acb1f0bf75 100644 --- a/DOCS/man/input.rst +++ b/DOCS/man/input.rst @@ -2636,12 +2636,18 @@ Property list subtitles, returns the first start time. If no current subtitle is present null is returned instead. +``secondary-sub-start`` + Same as ``sub-start``, but for the secondary subtitles. + ``sub-end`` The current subtitle end time (in seconds). If there's multiple current subtitles, return the last end time. If no current subtitle is present, or if it's present but has unknown or incorrect duration, null is returned instead. +``secondary-sub-end`` + Same as ``sub-end``, but for the secondary subtitles. + ``playlist-pos`` (RW) Current position on playlist. The first entry is on position 0. Writing to this property may start playback at the new position. diff --git a/player/command.c b/player/command.c index 051d83b14d..f4dd93c5d0 100644 --- a/player/command.c +++ b/player/command.c @@ -2873,7 +2873,8 @@ static struct sd_times get_times(void *ctx, struct m_property *prop, { struct sd_times res = { .start = MP_NOPTS_VALUE, .end = MP_NOPTS_VALUE }; MPContext *mpctx = ctx; - struct track *track = mpctx->current_track[0][STREAM_SUB]; + int track_ind = *(int *)prop->priv; + struct track *track = mpctx->current_track[track_ind][STREAM_SUB]; struct dec_sub *sub = track ? track->d_sub : NULL; double pts = mpctx->playback_pts; if (!sub || pts == MP_NOPTS_VALUE) @@ -3674,8 +3675,14 @@ static const struct m_property mp_properties_base[] = { .priv = (void *)&(const int){SD_TEXT_TYPE_PLAIN}}, {"sub-text-ass", mp_property_sub_text, .priv = (void *)&(const int){SD_TEXT_TYPE_ASS}}, - {"sub-start", mp_property_sub_start}, - {"sub-end", mp_property_sub_end}, + {"sub-start", mp_property_sub_start, + .priv = (void *)&(const int){0}}, + {"secondary-sub-start", mp_property_sub_start, + .priv = (void *)&(const int){1}}, + {"sub-end", mp_property_sub_end, + .priv = (void *)&(const int){0}}, + {"secondary-sub-end", mp_property_sub_end, + .priv = (void *)&(const int){1}}, {"vf", mp_property_vf}, {"af", mp_property_af}, @@ -3755,7 +3762,7 @@ static const char *const *const mp_event_property_change[] = { "estimated-display-fps", "vsync-jitter", "sub-text", "secondary-sub-text", "audio-bitrate", "video-bitrate", "sub-bitrate", "decoder-frame-drop-count", "frame-drop-count", "video-frame-info", "vf-metadata", "af-metadata", - "sub-start", "sub-end"), + "sub-start", "sub-end", "secondary-sub-start", "secondary-sub-end"), E(MP_EVENT_DURATION_UPDATE, "duration"), E(MPV_EVENT_VIDEO_RECONFIG, "video-out-params", "video-params", "video-format", "video-codec", "video-bitrate", "dwidth", "dheight", diff --git a/test/subtimes.js b/test/subtimes.js index 7821e0b5c0..be6940ad3b 100644 --- a/test/subtimes.js +++ b/test/subtimes.js @@ -5,3 +5,11 @@ function subtimes() { } mp.add_key_binding("t", "subtimes", subtimes); + +function secondary_subtimes() { + mp.msg.info("secondary-sub-start: " + mp.get_property_number("secondary-sub-start")); + mp.msg.info("secondary-sub-end: " + mp.get_property_number("secondary-sub-end")); + mp.msg.info("secondary-sub-text: " + mp.get_property_native("secondary-sub-text")); +} + +mp.add_key_binding("T", "secondary_subtimes", secondary_subtimes); \ No newline at end of file