From 89a57148934ec7f150a6170ac1313f6f5c636596 Mon Sep 17 00:00:00 2001 From: Uoti Urpala Date: Sat, 25 Aug 2012 21:22:39 +0300 Subject: subs: always use sub decoder framework for libass rendering Remove subtitle selection code setting osd->ass_track directly and vf_ass/vf_vo code rendering the track directly with libass. Instead, do track selection and rendering with dec_sub.c functions. Before, mpctx->set_of_ass_tracks[] contained bare libass tracks generated from external subtitle files. For use with dec_sub.c, it now contains struct sh_sub instances with decoder already initialized. This commit breaks the sub_step command ('g' and 'y' keys) for libass-rendered subtitles. It could be fixed, but it's so useless - especially as with the existing implementation there's no practical way to get subtitle delay back to normal after using it - that I didn't bother. Conflicts: command.c mp_core.h mplayer.c --- sub/sd_ass.c | 53 +++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 43 insertions(+), 10 deletions(-) (limited to 'sub/sd_ass.c') diff --git a/sub/sd_ass.c b/sub/sd_ass.c index f54c18e805..72dee06018 100644 --- a/sub/sd_ass.c +++ b/sub/sd_ass.c @@ -23,6 +23,7 @@ #include "talloc.h" +#include "options.h" #include "mpcommon.h" #include "mp_msg.h" #include "libmpdemux/stheader.h" @@ -33,6 +34,7 @@ struct sd_ass_priv { struct ass_track *ass_track; + bool vsfilter_aspect; bool incomplete_event; }; @@ -61,9 +63,7 @@ static int init(struct sh_sub *sh, struct osd_state *osd) ctx->ass_track = mp_ass_default_track(osd->ass_library, sh->opts); } - assert(osd->ass_track == NULL); - osd->ass_track = ctx->ass_track; - osd->vsfilter_aspect = sh->type == 'a'; + ctx->vsfilter_aspect = sh->type == 'a'; return 0; } @@ -125,6 +125,25 @@ static void decode(struct sh_sub *sh, struct osd_state *osd, void *data, event->Text = strdup(buf); } +static void get_bitmaps(struct sh_sub *sh, struct osd_state *osd, + struct sub_bitmaps *res) +{ + struct sd_ass_priv *ctx = sh->context; + struct MPOpts *opts = osd->opts; + + if (osd->sub_pts == MP_NOPTS_VALUE) + return; + + double scale = osd->normal_scale; + if (ctx->vsfilter_aspect && opts->ass_vsfilter_aspect_compat) + scale = osd->vsfilter_scale; + ASS_Renderer *renderer = osd->ass_renderer; + mp_ass_configure(renderer, opts, &osd->dim, osd->unscaled); + ass_set_aspect_ratio(renderer, scale, 1); + res->imgs = ass_render_frame(renderer, ctx->ass_track, + osd->sub_pts * 1000 + .5, &res->changed); +} + static void reset(struct sh_sub *sh, struct osd_state *osd) { struct sd_ass_priv *ctx = sh->context; @@ -133,12 +152,6 @@ static void reset(struct sh_sub *sh, struct osd_state *osd) ctx->incomplete_event = false; } -static void switch_off(struct sh_sub *sh, struct osd_state *osd) -{ - reset(sh, osd); - osd->ass_track = NULL; -} - static void uninit(struct sh_sub *sh) { struct sd_ass_priv *ctx = sh->context; @@ -150,7 +163,27 @@ static void uninit(struct sh_sub *sh) const struct sd_functions sd_ass = { .init = init, .decode = decode, + .get_bitmaps = get_bitmaps, .reset = reset, - .switch_off = switch_off, + .switch_off = reset, .uninit = uninit, }; + + +struct sh_sub *sd_ass_create_from_track(struct ass_track *track, + bool vsfilter_aspect, + struct MPOpts *opts) +{ + struct sh_sub *sh = talloc(NULL, struct sh_sub); + *sh = (struct sh_sub) { + .opts = opts, + .type = 'a', + .sd_driver = &sd_ass, + .context = talloc_struct(sh, struct sd_ass_priv, { + .ass_track = track, + .vsfilter_aspect = vsfilter_aspect, + }), + .initialized = true, + }; + return sh; +} -- cgit v1.2.3