mirror of https://github.com/mpv-player/mpv
sd_ass: remove dead code
With the FFmpeg subtitle decoder used for _all_ non-ASS text subtitle format, this code is simply unused now. Ironically, the FFmpeg subtitle decoder does not handle things correctly in a bunch of cases. Should it turn out they actually matter, they will have to hack back. The extend_event one is a candidate, although even though there were allegedly files which need it, I couldn't get samples from the user who originally reported such files. As such, extend_event was only confirmed to handle trailing events with no (endless) duration like with MicroDVD and LRC, but FFmpeg "fudges" these anyway, so no special handling is needed. This code also had logic to handle seeking with muxed srt subtitles, which made the sub-seek command work. But this has been broken before this commit already. Currently, seeking with muxed srt subs will clear all subtitles, as the broken FFmpeg ASS format output by the libavcodec subtitle converters does not check for duplicates. Since the subtitles are all cleared, ass_step_sub() can not work properly and sub-seek can not seek to already seen subtitles.
This commit is contained in:
parent
74c11f0c84
commit
04af005c35
|
@ -303,8 +303,6 @@ static void add_sub_list(struct dec_sub *sub, struct packet_list *subs)
|
|||
struct sd *sd = sub_get_last_sd(sub);
|
||||
assert(sd);
|
||||
|
||||
sd->no_remove_duplicates = true;
|
||||
|
||||
for (int n = 0; n < subs->num_packets; n++)
|
||||
decode_chain_recode(sub, subs->packets[n]);
|
||||
|
||||
|
@ -314,8 +312,6 @@ static void add_sub_list(struct dec_sub *sub, struct packet_list *subs)
|
|||
// but this is obviously unwanted in this case.
|
||||
if (sd->driver->fix_events)
|
||||
sd->driver->fix_events(sd);
|
||||
|
||||
sd->no_remove_duplicates = false;
|
||||
}
|
||||
|
||||
static void add_packet(struct packet_list *subs, struct demux_packet *pkt)
|
||||
|
|
4
sub/sd.h
4
sub/sd.h
|
@ -39,10 +39,6 @@ struct sd {
|
|||
struct ass_renderer *ass_renderer;
|
||||
pthread_mutex_t *ass_lock;
|
||||
|
||||
// If false, try to remove multiple subtitles.
|
||||
// (Only for decoders which have accept_packets_in_advance set.)
|
||||
bool no_remove_duplicates;
|
||||
|
||||
// Set by sub converter
|
||||
const char *output_codec;
|
||||
char *output_extradata;
|
||||
|
|
64
sub/sd_ass.c
64
sub/sd_ass.c
|
@ -43,7 +43,6 @@ struct sd_ass_priv {
|
|||
bool on_top;
|
||||
struct sub_bitmap *parts;
|
||||
bool flush_on_seek;
|
||||
int extend_event;
|
||||
char last_text[500];
|
||||
struct mp_image_params video_params;
|
||||
struct mp_image_params last_params;
|
||||
|
@ -79,12 +78,9 @@ static void mp_ass_add_default_styles(ASS_Track *track, struct MPOpts *opts)
|
|||
|
||||
static bool supports_format(const char *format)
|
||||
{
|
||||
// ass-text is produced by converters and the subreader.c ssa parser; this
|
||||
// format has ASS tags, but doesn't start with any prelude, nor does it
|
||||
// have extradata.
|
||||
// "ssa" is used for the FFmpeg subtitle converter output
|
||||
return format && (strcmp(format, "ass") == 0 ||
|
||||
strcmp(format, "ssa") == 0 ||
|
||||
strcmp(format, "ass-text") == 0);
|
||||
strcmp(format, "ssa") == 0);
|
||||
}
|
||||
|
||||
static int init(struct sd *sd)
|
||||
|
@ -96,7 +92,6 @@ static int init(struct sd *sd)
|
|||
struct sd_ass_priv *ctx = talloc_zero(NULL, struct sd_ass_priv);
|
||||
sd->priv = ctx;
|
||||
|
||||
ctx->extend_event = -1;
|
||||
ctx->is_converted = sd->converted_from != NULL;
|
||||
|
||||
pthread_mutex_lock(sd->ass_lock);
|
||||
|
@ -139,59 +134,16 @@ static void decode(struct sd *sd, struct demux_packet *packet)
|
|||
{
|
||||
struct sd_ass_priv *ctx = sd->priv;
|
||||
ASS_Track *track = ctx->ass_track;
|
||||
long long ipts = packet->pts * 1000 + 0.5;
|
||||
long long iduration = packet->duration * 1000 + 0.5;
|
||||
if (strcmp(sd->codec, "ass") == 0) {
|
||||
long long ipts = lrint(packet->pts * 1000);
|
||||
long long iduration = lrint(packet->duration * 1000);
|
||||
ass_process_chunk(track, packet->buffer, packet->len, ipts, iduration);
|
||||
return;
|
||||
} else if (strcmp(sd->codec, "ssa") == 0) {
|
||||
// broken ffmpeg ASS packet format
|
||||
} else {
|
||||
// "ssa" codec ID
|
||||
ctx->flush_on_seek = true;
|
||||
ass_process_data(track, packet->buffer, packet->len);
|
||||
return;
|
||||
}
|
||||
|
||||
// plaintext subs
|
||||
if (packet->pts == MP_NOPTS_VALUE) {
|
||||
MP_WARN(sd, "Subtitle without pts, ignored\n");
|
||||
return;
|
||||
}
|
||||
if (ctx->extend_event >= 0 && ctx->extend_event < track->n_events) {
|
||||
ASS_Event *event = &track->events[ctx->extend_event];
|
||||
if (event->Start <= ipts)
|
||||
event->Duration = ipts - event->Start;
|
||||
ctx->extend_event = -1;
|
||||
}
|
||||
|
||||
unsigned char *text = packet->buffer;
|
||||
if (!sd->no_remove_duplicates) {
|
||||
for (int i = 0; i < track->n_events; i++) {
|
||||
if (track->events[i].Start == ipts
|
||||
&& (track->events[i].Duration == iduration)
|
||||
&& strcmp(track->events[i].Text, text) == 0)
|
||||
return; // We've already added this subtitle
|
||||
}
|
||||
}
|
||||
int eid = ass_alloc_event(track);
|
||||
ASS_Event *event = track->events + eid;
|
||||
|
||||
if (packet->duration == 0) {
|
||||
MP_WARN(sd, "Subtitle without duration or "
|
||||
"duration set to 0 at pts %f.\n", packet->pts);
|
||||
}
|
||||
if (packet->duration < 0) {
|
||||
// Assume unknown duration. The FFmpeg API is very unclear about this.
|
||||
MP_WARN(sd, "Assuming subtitle without duration at pts %f\n", packet->pts);
|
||||
// _If_ there's a next subtitle, the duration will be adjusted again.
|
||||
// If not, show it forever.
|
||||
iduration = INT_MAX;
|
||||
ctx->extend_event = eid;
|
||||
}
|
||||
|
||||
event->Start = ipts;
|
||||
event->Duration = iduration;
|
||||
event->Style = track->default_style;
|
||||
event->Text = strdup(text);
|
||||
}
|
||||
|
||||
static void configure_ass(struct sd *sd, struct mp_osd_res *dim,
|
||||
|
@ -533,10 +485,8 @@ static void fix_events(struct sd *sd)
|
|||
static void reset(struct sd *sd)
|
||||
{
|
||||
struct sd_ass_priv *ctx = sd->priv;
|
||||
if (ctx->flush_on_seek || sd->opts->sub_clear_on_seek) {
|
||||
if (ctx->flush_on_seek || sd->opts->sub_clear_on_seek)
|
||||
ass_flush_events(ctx->ass_track);
|
||||
ctx->extend_event = -1;
|
||||
}
|
||||
ctx->flush_on_seek = false;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue