Skip to content

Commit

Permalink
command: add secondary-sub-start and secondary-sub-end properties
Browse files Browse the repository at this point in the history
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'.
  • Loading branch information
ripose-jp authored and Dudemanguy committed Jul 12, 2021
1 parent 383acd4 commit 34cfe9d
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 4 deletions.
6 changes: 6 additions & 0 deletions DOCS/man/input.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
15 changes: 11 additions & 4 deletions player/command.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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},
Expand Down Expand Up @@ -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",
Expand Down
8 changes: 8 additions & 0 deletions test/subtimes.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

0 comments on commit 34cfe9d

Please sign in to comment.