summaryrefslogtreecommitdiffstats
path: root/player
diff options
context:
space:
mode:
authorGuido Cella <guido@guidocella.xyz>2021-08-10 22:11:53 +0200
committerDudemanguy <random342@airmail.cc>2021-08-11 18:15:35 +0000
commitb6ebd1a15e4541f0b02e9ebd3a1095e349d71b9d (patch)
tree926b643c2a0405b036ed9176d24259b35aa65173 /player
parentf25d446b0351c2c5cdd1a4f73146d8034ba30445 (diff)
downloadmpv-b6ebd1a15e4541f0b02e9ebd3a1095e349d71b9d.tar.bz2
mpv-b6ebd1a15e4541f0b02e9ebd3a1095e349d71b9d.tar.xz
sub: align ytdl-hook secondary subs to the top
29e15e6248 prefixed youtube-dl's subs url with an edl prefix to not download them until they're selected, which is useful when there are many sub languages. But this prefix broke the alignment of secondary subs, which would overlap the primary subs instead of always being placed at the top. This can be tested with --sub-file='edl://!no_clip;!delay_open,media_type=sub;secondary_sub.srt' When a sub is added, sub.c:reinit_sub() is called. This calls in init_subdec() -> dec_sub.c:sub_create() -> init_decoder() -> sd_ass:init(). Then reinit_sub() calls sub_control(track->d_sub, SD_CTRL_SET_TOP, &(bool){!!order}) which sets sd_ass_priv.on_top = true for secondary subs. But for EDL subs the real sub is initialized again when in dec_sub.c:sub_read_packets() is_new_segment() returns true and update_segment() is called, or when sub_get_bitmaps() calls update_segment(). update_segment() then calls init_decoder(), which calls sd_ass:init(), so sd_ass_priv is reinitialized, and its on_top property is left false. This commit sets it to true again. For URLs that need to be downloaded it seems that the update_segment() call that reinitializes sd_ass_priv is always the one in sub_read_packets(), but with local subs sub_get_bitmaps() is usually called earlier (though there shouldn't be a reason to use the EDL URL for local subs), so I added the order parameter to sub_create(), rather than adding it to all of update_segment(), sub_read_packets() and sub_get_bitmaps(). Also removes the cast to bool in the other sub_control call, since sub/sd_ass.c:control already casts arg to bool when cmd is SD_CTRL_SET_TOP.
Diffstat (limited to 'player')
-rw-r--r--player/sub.c5
1 files changed, 3 insertions, 2 deletions
diff --git a/player/sub.c b/player/sub.c
index 148109bdc9..50f3fbe2b4 100644
--- a/player/sub.c
+++ b/player/sub.c
@@ -171,7 +171,8 @@ static bool init_subdec(struct MPContext *mpctx, struct track *track)
return false;
track->d_sub = sub_create(mpctx->global, track->stream,
- get_all_attachments(mpctx));
+ get_all_attachments(mpctx),
+ get_order(mpctx, track));
if (!track->d_sub)
return false;
@@ -199,7 +200,7 @@ void reinit_sub(struct MPContext *mpctx, struct track *track)
sub_select(track->d_sub, true);
int order = get_order(mpctx, track);
osd_set_sub(mpctx->osd, order, track->d_sub);
- sub_control(track->d_sub, SD_CTRL_SET_TOP, &(bool){!!order});
+ sub_control(track->d_sub, SD_CTRL_SET_TOP, &order);
if (mpctx->playback_initialized)
update_subtitles(mpctx, mpctx->playback_pts);