From 3f60548df472d01387784601526e378d8ffb4659 Mon Sep 17 00:00:00 2001 From: wm4 Date: Thu, 3 Mar 2016 18:48:56 +0100 Subject: sub: pass all attachments to the subtitle decoder Commit 8d4a179c made subtitle decoders pick up fonts strictly from the same source file (i.e. the same demuxer). It breaks some fucked up use-case, and 2 people on this earth complained about the change because of this. Add it back. This copies all attached fonts on each subtitle init. I considered converting attachments to use refcounting, but it'd probably be much more complex. Since it's slightly harder to get a list of active demuxers with duplicate removed, the prev_demuxer variable serves as a hack to achieve almost the same thing, except in weird corner cases. (In which fonts could be added twice.) --- sub/sd_ass.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'sub/sd_ass.c') diff --git a/sub/sd_ass.c b/sub/sd_ass.c index 5c56d3e0df..4426c2ebab 100644 --- a/sub/sd_ass.c +++ b/sub/sd_ass.c @@ -117,10 +117,10 @@ static void add_subtitle_fonts(struct sd *sd) { struct sd_ass_priv *ctx = sd->priv; struct MPOpts *opts = sd->opts; - if (!opts->ass_enabled || !sd->demuxer) + if (!opts->ass_enabled || !sd->attachments) return; - for (int i = 0; i < sd->demuxer->num_attachments; i++) { - struct demux_attachment *f = &sd->demuxer->attachments[i]; + for (int i = 0; i < sd->attachments->num_entries; i++) { + struct demux_attachment *f = &sd->attachments->entries[i]; if (opts->use_embedded_fonts && attachment_is_font(sd->log, f)) ass_add_font(ctx->ass_library, f->name, f->data, f->data_size); } -- cgit v1.2.3 From 740b7013ba827ce5a9d48138af5bd2e8f5d54710 Mon Sep 17 00:00:00 2001 From: wm4 Date: Sat, 5 Mar 2016 00:13:30 +0100 Subject: sd_ass: always handle subtitles with unknown duration Deals with broken mkv subtitle tracks generated by tvheadend. The subs are srt, but without packet durations. We need this logic for CCs anyway. CCs in particular will be unaffected by this change because they are also marked with unknown duration. It could be that there are actual demuxers outputting CCs - in this case, we rely on the fact that they don't set a (meaningless) packet duration (or we'd have to work that around). --- sub/sd_ass.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'sub/sd_ass.c') diff --git a/sub/sd_ass.c b/sub/sd_ass.c index 4426c2ebab..59336ff0ec 100644 --- a/sub/sd_ass.c +++ b/sub/sd_ass.c @@ -238,6 +238,8 @@ static bool check_packet_seen(struct sd *sd, int64_t pos) return false; } +#define UNKNOWN_DURATION (INT_MAX / 1000) + static void decode(struct sd *sd, struct demux_packet *packet) { struct sd_ass_priv *ctx = sd->priv; @@ -246,13 +248,22 @@ static void decode(struct sd *sd, struct demux_packet *packet) if (!sd->opts->sub_clear_on_seek && packet->pos >= 0 && check_packet_seen(sd, packet->pos)) return; + if (packet->duration < 0) { + if (!ctx->duration_unknown) { + MP_WARN(sd, "Subtitle with unknown duration.\n"); + ctx->duration_unknown = true; + } + packet->duration = UNKNOWN_DURATION; + } char **r = lavc_conv_decode(ctx->converter, packet); for (int n = 0; r && r[n]; n++) ass_process_data(track, r[n], strlen(r[n])); if (ctx->duration_unknown) { for (int n = 0; n < track->n_events - 1; n++) { - track->events[n].Duration = track->events[n + 1].Start - - track->events[n].Start; + if (track->events[n].Duration == UNKNOWN_DURATION * 1000) { + track->events[n].Duration = track->events[n + 1].Start - + track->events[n].Start; + } } } } else { @@ -440,6 +451,7 @@ static void get_bitmaps(struct sd *sd, struct mp_osd_res dim, double pts, long long ts = find_timestamp(sd, pts); if (ctx->duration_unknown && pts != MP_NOPTS_VALUE) { mp_ass_flush_old_events(track, ts); + ctx->num_seen_packets = 0; } if (no_ass) fill_plaintext(sd, pts); -- cgit v1.2.3 From a714f8e928ba01c595d4ac6812e2e611d3899f09 Mon Sep 17 00:00:00 2001 From: wm4 Date: Sat, 5 Mar 2016 12:45:54 +0100 Subject: sd_ass: always clear subtitles on seek if duration unknown Although there is logic to prune subtitles as soon as they get too old in this mode, this is not done for the _currently_ shown subtitles. Thus explicitly clearing subtitles on seek is required to avoid duplicate subtitles in certain cases when seeking. --- sub/sd_ass.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'sub/sd_ass.c') diff --git a/sub/sd_ass.c b/sub/sd_ass.c index 59336ff0ec..f8c9abebb2 100644 --- a/sub/sd_ass.c +++ b/sub/sd_ass.c @@ -609,7 +609,7 @@ static void fill_plaintext(struct sd *sd, double pts) static void reset(struct sd *sd) { struct sd_ass_priv *ctx = sd->priv; - if (sd->opts->sub_clear_on_seek) { + if (sd->opts->sub_clear_on_seek || ctx->duration_unknown) { ass_flush_events(ctx->ass_track); ctx->num_seen_packets = 0; } -- cgit v1.2.3 From 05b2cd08dcaddb9ea6224f3ad3a32e1d967d0a98 Mon Sep 17 00:00:00 2001 From: wm4 Date: Sun, 6 Mar 2016 14:50:36 +0100 Subject: sub: make preloading more robust Subtitles can be preloaded, which means they're fully read and copied into ASS_Track. This in turn is mainly for the sake of being able to do subtitle seeking (when it comes down to it, subtitle seeking is the cause for most trouble here). Commit a714f8e92 broke preloaded subtitles which have events with unknown duration, such as some MicroDVD samples. The event list gets cleared on every seek, so the property of being preloaded obviously gets lost. Fix this by moving most of the preloading logic to dec_sub.c. If the subtitle list gets cleared, they are not considered preloaded anymore, and the logic for demuxed subtitles is used. As another minor thing, preloadeding subtitles did neither disable the demux stream, nor did it discard packets. Thus you could get queue overflows in theory (harmless, but annoying). Fix this by explicitly discarding packets in preloaded mode. In summary, now the only difference between preloaded and normal demuxing are: 1. a seek is issued, and all packets are read on start 2. during playback, discard the packets instead of feeding them to the subtitle decoder This is still petty annoying. It would be nice if maintaining the subtitle index (and maybe a subtitle packet cache for instant subtitle presentation when seeking back) could be maintained in the demuxer instead. Half of all file formats with interleaved subtitles have this anyway (mp4, mkv muxed with newer mkvmerge). --- sub/sd_ass.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'sub/sd_ass.c') diff --git a/sub/sd_ass.c b/sub/sd_ass.c index f8c9abebb2..23f0c882f8 100644 --- a/sub/sd_ass.c +++ b/sub/sd_ass.c @@ -452,6 +452,7 @@ static void get_bitmaps(struct sd *sd, struct mp_osd_res dim, double pts, if (ctx->duration_unknown && pts != MP_NOPTS_VALUE) { mp_ass_flush_old_events(track, ts); ctx->num_seen_packets = 0; + sd->preload_ok = false; } if (no_ass) fill_plaintext(sd, pts); @@ -612,6 +613,7 @@ static void reset(struct sd *sd) if (sd->opts->sub_clear_on_seek || ctx->duration_unknown) { ass_flush_events(ctx->ass_track); ctx->num_seen_packets = 0; + sd->preload_ok = false; } if (ctx->converter) lavc_conv_reset(ctx->converter); -- cgit v1.2.3 From f5bfe01932b2895ad9b9faa8c04d8a1466dbeeb0 Mon Sep 17 00:00:00 2001 From: wm4 Date: Tue, 8 Mar 2016 20:49:33 +0100 Subject: osd: refactor how mp_ass_render_frame() is called Instead of passing an explicit cache to the function, the res parameter is used. Also, instead of replacing its contents, sub bitmaps are now appended to it (all assuming the format doesn't actually change). This is preparation for the following commits. --- sub/sd_ass.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'sub/sd_ass.c') diff --git a/sub/sd_ass.c b/sub/sd_ass.c index 23f0c882f8..788b78f3a4 100644 --- a/sub/sd_ass.c +++ b/sub/sd_ass.c @@ -44,7 +44,7 @@ struct sd_ass_priv { bool is_converted; struct lavc_conv *converter; bool on_top; - struct sub_bitmap *parts; + struct sub_bitmaps part_cache; char last_text[500]; struct mp_image_params video_params; struct mp_image_params last_params; @@ -454,13 +454,19 @@ static void get_bitmaps(struct sd *sd, struct mp_osd_res dim, double pts, ctx->num_seen_packets = 0; sd->preload_ok = false; } + if (no_ass) fill_plaintext(sd, pts); - mp_ass_render_frame(renderer, track, ts, &ctx->parts, res); - talloc_steal(ctx, ctx->parts); + + ctx->part_cache.change_id = 0; + ctx->part_cache.num_parts = 0; + mp_ass_render_frame(renderer, track, ts, &ctx->part_cache); + talloc_steal(ctx, ctx->part_cache.parts); if (!converted) - mangle_colors(sd, res); + mangle_colors(sd, &ctx->part_cache); + + *res = ctx->part_cache; } struct buf { -- cgit v1.2.3