From f7b9b92179333e5bf399cbb6289b66ed3439445c Mon Sep 17 00:00:00 2001 From: wm4 Date: Sat, 1 Jun 2013 19:40:09 +0200 Subject: sub: various minor subtitle related changes Just pushing some code around. --- core/mplayer.c | 21 ++++++++++----------- sub/dec_sub.c | 20 -------------------- sub/dec_sub.h | 4 ---- sub/sd_ass.c | 14 ++++++++++++++ sub/sd_lavc.c | 13 +++++-------- sub/sd_spu.c | 6 ++++++ 6 files changed, 35 insertions(+), 43 deletions(-) diff --git a/core/mplayer.c b/core/mplayer.c index c832aa1fcb..285f19c8ac 100644 --- a/core/mplayer.c +++ b/core/mplayer.c @@ -1833,10 +1833,6 @@ static void update_subtitles(struct MPContext *mpctx, double refpts_tl) { struct MPOpts *opts = &mpctx->opts; struct sh_sub *sh_sub = mpctx->sh_sub; - struct demux_stream *d_sub = sh_sub ? sh_sub->ds : NULL; - unsigned char *packet = NULL; - int len; - const char *type = sh_sub ? sh_sub->gsh->codec : NULL; struct track *track = mpctx->current_track[STREAM_SUB]; if (!track) @@ -1849,12 +1845,16 @@ static void update_subtitles(struct MPContext *mpctx, double refpts_tl) double curpts_s = refpts_tl - mpctx->osd->sub_offset; double refpts_s = refpts_tl - video_offset; - if (d_sub && sh_sub && sh_sub->active) { + if (sh_sub && sh_sub->active) { + struct demux_stream *d_sub = sh_sub->ds; + const char *type = sh_sub->gsh->codec; bool non_interleaved = is_non_interleaved(mpctx, track); - if (non_interleaved) - ds_get_next_pts(d_sub); - while (d_sub->first) { + while (1) { + if (non_interleaved) + ds_get_next_pts(d_sub); + if (!d_sub->first) + break; double subpts_s = ds_get_next_pts(d_sub); if (subpts_s == MP_NOPTS_VALUE) { // Try old method of getting PTS. This is only needed in the @@ -1882,7 +1882,8 @@ static void update_subtitles(struct MPContext *mpctx, double refpts_tl) break; } double duration = d_sub->first->duration; - len = ds_get_packet_sub(d_sub, &packet); + unsigned char *packet = NULL; + int len = ds_get_packet_sub(d_sub, &packet); mp_dbg(MSGT_CPLAYER, MSGL_V, "Sub: c_pts=%5.3f s_pts=%5.3f " "duration=%5.3f len=%d\n", curpts_s, subpts_s, duration, len); @@ -1893,8 +1894,6 @@ static void update_subtitles(struct MPContext *mpctx, double refpts_tl) packet += 2; } sub_decode(sh_sub, mpctx->osd, packet, len, subpts_s, duration); - if (non_interleaved) - ds_get_next_pts(d_sub); } } diff --git a/sub/dec_sub.c b/sub/dec_sub.c index 36ba25edd2..2cc02efb79 100644 --- a/sub/dec_sub.c +++ b/sub/dec_sub.c @@ -40,26 +40,6 @@ static const struct sd_functions *sd_list[] = { NULL }; -bool is_text_sub(const char *t) -{ - return t && (is_ass_sub(t) || - strcmp(t, "text") == 0 || - strcmp(t, "subrip") == 0 || - strcmp(t, "mov_text") == 0); -} - -bool is_ass_sub(const char *t) -{ - return t && (strcmp(t, "ass") == 0 || - strcmp(t, "ssa") == 0); -} - -bool is_dvd_sub(const char *t) -{ - return t && (strcmp(t, "dvd_subtitle") == 0 || - strcmp(t, "dvd_subtitle_mpg") == 0); -} - void sub_init(struct sh_sub *sh, struct osd_state *osd) { sh->sd_driver = NULL; diff --git a/sub/dec_sub.h b/sub/dec_sub.h index 52fa05eebc..263df19bc0 100644 --- a/sub/dec_sub.h +++ b/sub/dec_sub.h @@ -10,10 +10,6 @@ struct sh_sub; struct ass_track; struct MPOpts; -bool is_text_sub(const char *t); -bool is_ass_sub(const char *t); -bool is_dvd_sub(const char *t); - bool sub_accept_packets_in_advance(struct sh_sub *sh); void sub_decode(struct sh_sub *sh, struct osd_state *osd, void *data, int data_len, double pts, double duration); diff --git a/sub/sd_ass.c b/sub/sd_ass.c index 3dfbbd05fb..02d0ed15bf 100644 --- a/sub/sd_ass.c +++ b/sub/sd_ass.c @@ -43,6 +43,20 @@ struct sd_ass_priv { char last_text[500]; }; +static bool is_ass_sub(const char *t) +{ + return t && (strcmp(t, "ass") == 0 || + strcmp(t, "ssa") == 0); +} + +static bool is_text_sub(const char *t) +{ + return t && (is_ass_sub(t) || + strcmp(t, "text") == 0 || + strcmp(t, "subrip") == 0 || + strcmp(t, "mov_text") == 0); +} + static bool supports_format(const char *format) { return is_text_sub(format); diff --git a/sub/sd_lavc.c b/sub/sd_lavc.c index 4e1d80d8ce..4c7dfd12a5 100644 --- a/sub/sd_lavc.c +++ b/sub/sd_lavc.c @@ -43,21 +43,18 @@ struct sd_lavc_priv { static bool supports_format(const char *format) { - // lavc dvdsubdec doesn't read color/resolution on Libav 9.1 and below, - // so fall back to sd_spu in this case. Never use sd_spu with new ffmpeg; - // spudec can't handle ffmpeg .idx demuxing (added to lavc in 54.79.100). -#if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(54, 40, 0) - if (is_dvd_sub(format)) - return false; -#endif - enum AVCodecID cid = mp_codec_to_av_codec_id(format); // Supported codecs must be known to decode to paletted bitmaps switch (cid) { case AV_CODEC_ID_DVB_SUBTITLE: case AV_CODEC_ID_HDMV_PGS_SUBTITLE: case AV_CODEC_ID_XSUB: + // lavc dvdsubdec doesn't read color/resolution on Libav 9.1 and below, + // so fall back to sd_spu in this case. Never use sd_spu with new ffmpeg; + // spudec can't handle ffmpeg .idx demuxing (added to lavc in 54.79.100). +#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(54, 40, 0) case AV_CODEC_ID_DVD_SUBTITLE: +#endif return true; default: return false; diff --git a/sub/sd_spu.c b/sub/sd_spu.c index fc4e4701dc..8b87b7a0dc 100644 --- a/sub/sd_spu.c +++ b/sub/sd_spu.c @@ -29,6 +29,12 @@ struct sd_spu_priv { void *spudec; }; +static bool is_dvd_sub(const char *t) +{ + return t && (strcmp(t, "dvd_subtitle") == 0 || + strcmp(t, "dvd_subtitle_mpg") == 0); +} + static bool supports_format(const char *format) { return is_dvd_sub(format); -- cgit v1.2.3