From 687b552db186af66e97c58792b2db40294e92bad Mon Sep 17 00:00:00 2001 From: wm4 Date: Fri, 18 Dec 2015 01:54:14 +0100 Subject: sub: remove subtitle filter chain concept It was stupid. The only thing that still effectively used it was sd_lavc_conv - all other "filters" were the subtitle decoder/renderers for text (sd_ass) and bitmap (sd_lavc) subtitles. While having a subtitle filter chain was interesting (and actually worked in almost the same way as the audio/video ones), I didn't manage to use it in a meaningful way, and I couldn't e.g. factor secondary features like fixing subtitle timing into filters. Refactor the shit and drop unneeded things as it goes. --- sub/sd_ass.c | 45 ++++++++++++++++++++++++++++++--------------- 1 file changed, 30 insertions(+), 15 deletions(-) (limited to 'sub/sd_ass.c') diff --git a/sub/sd_ass.c b/sub/sd_ass.c index dc045996cd..baf35b5d30 100644 --- a/sub/sd_ass.c +++ b/sub/sd_ass.c @@ -40,6 +40,7 @@ struct sd_ass_priv { struct ass_track *ass_track; struct ass_track *shadow_track; // for --sub-ass=no rendering bool is_converted; + struct lavc_conv *converter; bool on_top; struct sub_bitmap *parts; char last_text[500]; @@ -79,21 +80,31 @@ static void mp_ass_add_default_styles(ASS_Track *track, struct MPOpts *opts) static bool supports_format(const char *format) { - // "ssa" is used for the FFmpeg subtitle converter output - return format && (strcmp(format, "ass") == 0 || - strcmp(format, "ssa") == 0); + return (format && strcmp(format, "ass") == 0) || + lavc_conv_supports_format(format); } static int init(struct sd *sd) { struct MPOpts *opts = sd->opts; - if (!sd->ass_library || !sd->ass_renderer || !sd->ass_lock || !sd->codec) + if (!sd->ass_library || !sd->ass_renderer || !sd->ass_lock) return -1; - struct sd_ass_priv *ctx = talloc_zero(NULL, struct sd_ass_priv); + struct sd_ass_priv *ctx = talloc_zero(sd, struct sd_ass_priv); sd->priv = ctx; - ctx->is_converted = sd->converted_from != NULL; + char *extradata = sd->sh->extradata; + int extradata_size = sd->sh->extradata_size; + + if (strcmp(sd->sh->codec, "ass") != 0) { + ctx->is_converted = true; + ctx->converter = lavc_conv_create(sd->log, sd->sh->codec, extradata, + extradata_size); + if (!ctx->converter) + return -1; + extradata = lavc_conv_get_extradata(ctx->converter); + extradata_size = extradata ? strlen(extradata) : 0; + } pthread_mutex_lock(sd->ass_lock); @@ -106,10 +117,8 @@ static int init(struct sd *sd) ctx->shadow_track->PlayResY = 288; mp_ass_add_default_styles(ctx->shadow_track, opts); - if (sd->extradata) { - ass_process_codec_private(ctx->ass_track, sd->extradata, - sd->extradata_len); - } + if (extradata) + ass_process_codec_private(ctx->ass_track, extradata, extradata_size); mp_ass_add_default_styles(ctx->ass_track, opts); @@ -158,15 +167,18 @@ static void decode(struct sd *sd, struct demux_packet *packet) { struct sd_ass_priv *ctx = sd->priv; ASS_Track *track = ctx->ass_track; - if (strcmp(sd->codec, "ass") == 0) { + if (ctx->converter) { + if (check_packet_seen(sd, packet->pos)) + return; + 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])); + } else { // Note that for this packet format, libass has an internal mechanism // for discarding duplicate (already seen) packets. ass_process_chunk(track, packet->buffer, packet->len, lrint(packet->pts * 1000), lrint(packet->duration * 1000)); - } else { - if (!check_packet_seen(sd, packet->pos)) - ass_process_data(track, packet->buffer, packet->len); } } @@ -505,14 +517,17 @@ static void reset(struct sd *sd) struct sd_ass_priv *ctx = sd->priv; if (sd->opts->sub_clear_on_seek) ass_flush_events(ctx->ass_track); + if (ctx->converter) + lavc_conv_reset(ctx->converter); } static void uninit(struct sd *sd) { struct sd_ass_priv *ctx = sd->priv; + if (ctx->converter) + lavc_conv_uninit(ctx->converter); ass_free_track(ctx->ass_track); - talloc_free(ctx); } static int control(struct sd *sd, enum sd_ctrl cmd, void *arg) -- cgit v1.2.3