mirror of
https://github.com/mpv-player/mpv
synced 2024-08-24 07:21:49 +02:00
sub: various minor subtitle related changes
Just pushing some code around.
This commit is contained in:
parent
28116b8a79
commit
f7b9b92179
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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);
|
||||
|
14
sub/sd_ass.c
14
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);
|
||||
|
@ -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;
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user