From 466fc6d4d18ac1751527ccfff8f3c39eb3ff1e4b Mon Sep 17 00:00:00 2001 From: wm4 Date: Tue, 2 Oct 2012 23:28:18 +0200 Subject: [PATCH] sub: make it easier to set DVD sub decoding with sd_lavc With this commit, the player will still use spudec.c (the "old" DVD sub decoder), rather than ffmpeg. But it brings the changes needed to enable this down to a single line change: --- a/mplayer.c +++ b/mplayer.c @@ -1988,7 +1988,7 @@ static void reinit_subs(struct MPContext *mpctx) #endif vo_osd_changed(OSDTYPE_SUBTITLE); } else if (track->stream) { - if (mpctx->sh_sub->type == 'v') + if (mpctx->sh_sub->type == 'v' && false) init_vo_spudec(mpctx); else sub_init(mpctx->sh_sub, mpctx->osd); Also, copy the DVD resolution heuristics from spudec.c (from the spudec_new_scaled() function). I'm not sure if this is correct or even needed, but the sd_lavc codd explicitly reverted back to spudec with code carrying this comment: // Assume resolution heuristics only work for PGS and DVB so it seems likely that the required heuristics were missing, and that the spudec heuristics may make the DVD compatibility situation at least as good as with spudec. Note that it's unlikely that we enable sd_lavc for DVD subs by default, as there are other problems in combination with direct DVD playback. --- mplayer.c | 4 +++- sub/dec_sub.c | 2 +- sub/sd_lavc.c | 29 ++++++++++++++++++++++------- 3 files changed, 26 insertions(+), 9 deletions(-) diff --git a/mplayer.c b/mplayer.c index 6fe8c649c4..a885fac8ca 100644 --- a/mplayer.c +++ b/mplayer.c @@ -1795,7 +1795,9 @@ static void update_subtitles(struct MPContext *mpctx, double refpts_tl) } // DVD sub: - if (track->vobsub_id_plus_one || type == 'v') { + if ((track->vobsub_id_plus_one || type == 'v') + && !(sh_sub && sh_sub->active)) + { int timestamp; // Get a sub packet from the demuxer (or the vobsub.c thing, which // should be a demuxer, but isn't). diff --git a/sub/dec_sub.c b/sub/dec_sub.c index 31b06b9b80..b5ffa81511 100644 --- a/sub/dec_sub.c +++ b/sub/dec_sub.c @@ -39,7 +39,7 @@ void sub_init(struct sh_sub *sh, struct osd_state *osd) if (opts->ass_enabled && is_text_sub(sh->type)) sh->sd_driver = &sd_ass; #endif - if (strchr("bpx", sh->type)) + if (strchr("bpxv", sh->type)) sh->sd_driver = &sd_lavc; if (sh->sd_driver) { if (sh->sd_driver->init(sh, osd) < 0) diff --git a/sub/sd_lavc.c b/sub/sd_lavc.c index 39e4891fb1..b0dde50a00 100644 --- a/sub/sd_lavc.c +++ b/sub/sd_lavc.c @@ -77,6 +77,26 @@ static void old_avsub_to_spudec(AVSubtitleRect **rects, int num_rects, spudec_packet_send(vo_spudec, packet, pts, endpts); } +static void guess_resolution(char type, int *w, int *h) +{ + if (type == 'v') { + /* XXX Although the video frame is some size, the SPU frame is + always maximum size i.e. 720 wide and 576 or 480 high */ + // For HD files in MKV the VobSub resolution can be higher though, + // see largeres_vobsub.mkv + if (*w <= 720 && *h <= 576) { + *w = 720; + *h = (*h == 480 || *h == 240) ? 480 : 576; + } + } else { + // Hope that PGS subs set these and 720/576 works for dvb subs + if (!*w) + *w = 720; + if (!*h) + *h = 576; + } +} + static int init(struct sh_sub *sh, struct osd_state *osd) { if (sh->initialized) @@ -158,8 +178,7 @@ static void decode(struct sh_sub *sh, struct osd_state *osd, void *data, if (sub.num_rects > 0) { switch (sub.rects[0]->type) { case SUBTITLE_BITMAP: - // Assume resolution heuristics only work for PGS and DVB - if (!osd->support_rgba || sh->type != 'p' && sh->type != 'b') { + if (!osd->support_rgba) { if (!vo_spudec) vo_spudec = spudec_new_scaled(NULL, ctx->width, ctx->height, NULL, 0); @@ -214,13 +233,9 @@ static void get_bitmaps(struct sh_sub *sh, struct osd_state *osd, priv->outbitmaps = talloc_memdup(priv, priv->inbitmaps, talloc_get_size(priv->inbitmaps)); bool pos_changed = false; - // Hope that PGS subs set these and 720/576 works for dvb subs int inw = priv->avctx->width; - if (!inw) - inw = 720; int inh = priv->avctx->height; - if (!inh) - inh = 576; + guess_resolution(sh->type, &inw, &inh); struct mp_eosd_res *d = &osd->dim; double xscale = (double) (d->w - d->ml - d->mr) / inw; double yscale = (double) (d->h - d->mt - d->mb) / inh;