1
0
mirror of https://github.com/mpv-player/mpv synced 2024-12-24 15:52:25 +00:00

sub: be more flexible about changes to how subtitles are rendered

For example, if --force-window is used, and video is switched off during
playback, then you need to redecide the rendering method to get subs
displayed correctly.

Do this by moving the state setup code into a function, and call it on
every frame.
This commit is contained in:
wm4 2014-10-31 23:43:22 +01:00
parent 0afc99b33f
commit 13d408fe8d

View File

@ -193,6 +193,36 @@ void reset_subtitle_state(struct MPContext *mpctx)
reset_subtitles(mpctx, 1); reset_subtitles(mpctx, 1);
} }
static void update_sub_state(struct MPContext *mpctx, int order,
struct osd_sub_state *out_state)
{
struct MPOpts *opts = mpctx->opts;
struct track *track = mpctx->current_track[order][STREAM_SUB];
struct dec_sub *dec_sub = mpctx->d_sub[order];
int obj = order ? OSDTYPE_SUB2 : OSDTYPE_SUB;
assert(track);
struct osd_sub_state state = {
.dec_sub = dec_sub,
// Decides whether to use OSD path or normal subtitle rendering path.
.render_bitmap_subs = opts->ass_enabled || !sub_has_get_text(dec_sub),
.video_offset = get_track_video_offset(mpctx, track),
};
// Secondary subs are rendered with the "text" renderer to transform them
// to toptitles.
if (order == 1 && sub_has_get_text(dec_sub))
state.render_bitmap_subs = false;
if (!mpctx->current_track[0][STREAM_VIDEO])
state.render_bitmap_subs = false;
osd_set_sub(mpctx->osd, obj, &state);
if (out_state)
*out_state = state;
}
static void update_subtitle(struct MPContext *mpctx, int order) static void update_subtitle(struct MPContext *mpctx, int order)
{ {
struct MPOpts *opts = mpctx->opts; struct MPOpts *opts = mpctx->opts;
@ -212,9 +242,7 @@ static void update_subtitle(struct MPContext *mpctx, int order)
} }
struct osd_sub_state state; struct osd_sub_state state;
osd_get_sub(mpctx->osd, obj, &state); update_sub_state(mpctx, order, &state);
state.video_offset = get_track_video_offset(mpctx, track);
osd_set_sub(mpctx->osd, obj, &state);
double refpts_s = mpctx->playback_pts - state.video_offset; double refpts_s = mpctx->playback_pts - state.video_offset;
double curpts_s = refpts_s - opts->sub_delay; double curpts_s = refpts_s - opts->sub_delay;
@ -294,9 +322,7 @@ static void reinit_subdec(struct MPContext *mpctx, struct track *track,
void reinit_subs(struct MPContext *mpctx, int order) void reinit_subs(struct MPContext *mpctx, int order)
{ {
struct MPOpts *opts = mpctx->opts;
struct track *track = mpctx->current_track[order][STREAM_SUB]; struct track *track = mpctx->current_track[order][STREAM_SUB];
int obj = order ? OSDTYPE_SUB2 : OSDTYPE_SUB;
assert(!mpctx->d_sub[order]); assert(!mpctx->d_sub[order]);
@ -313,19 +339,5 @@ void reinit_subs(struct MPContext *mpctx, int order)
struct dec_sub *dec_sub = mpctx->d_sub[order]; struct dec_sub *dec_sub = mpctx->d_sub[order];
reinit_subdec(mpctx, track, dec_sub); reinit_subdec(mpctx, track, dec_sub);
struct osd_sub_state state = { update_sub_state(mpctx, order, NULL);
.dec_sub = dec_sub,
// Decides whether to use OSD path or normal subtitle rendering path.
.render_bitmap_subs = opts->ass_enabled || !sub_has_get_text(dec_sub),
};
// Secondary subs are rendered with the "text" renderer to transform them
// to toptitles.
if (order == 1 && sub_has_get_text(dec_sub))
state.render_bitmap_subs = false;
if (!mpctx->current_track[0][STREAM_VIDEO])
state.render_bitmap_subs = false;
osd_set_sub(mpctx->osd, obj, &state);
} }