From e19ffa02aa370cbc3b559f85b286ea09b06ab29b Mon Sep 17 00:00:00 2001 From: wm4 Date: Sat, 1 Jun 2013 19:54:18 +0200 Subject: sub: turn subassconvert_ functions into sub converters This means subassconvert.c is split in sd_srt.c and sd_microdvd.c. Now this code is involved in the sub conversion chain like sd_movtext is. The invocation of the converter in sd_ass.c is removed. This requires some other changes to make the new sub converter code work with loading external subtitles. Until now, subtitles loaded via subreader.c was assumed to be in plaintext, or for some formats, in ASS (except in -no-ass mode). Then these were added to an ASS_Track. Change this so that subtitles are always in their original format (as far as decoders/converters for them are available), and turn every sub event read by subreader.c as packet to the dec_sub.c subtitle chain. This removes differences between external/demuxed and -ass/-no-ass code paths further. --- sub/sd_srt.c | 34 +++++++++++++++++++++++++++++++--- 1 file changed, 31 insertions(+), 3 deletions(-) (limited to 'sub/sd_srt.c') diff --git a/sub/sd_srt.c b/sub/sd_srt.c index fd1d252924..ec4768a598 100644 --- a/sub/sd_srt.c +++ b/sub/sd_srt.c @@ -25,11 +25,11 @@ #include #include #include +#include #include "core/mp_msg.h" -#include "subassconvert.h" #include "core/bstr.h" -#include "libavutil/common.h" +#include "sd.h" struct line { char *buf; @@ -273,7 +273,7 @@ static int read_attr(char **s, struct bstr *attr, struct bstr *val) return 0; } -void subassconvert_subrip(const char *orig, char *dest, int dest_buffer_size) +static void convert_subrip(const char *orig, char *dest, int dest_buffer_size) { /* line is not const to avoid warnings with strtol, etc. * orig content won't be changed */ @@ -436,3 +436,31 @@ void subassconvert_subrip(const char *orig, char *dest, int dest_buffer_size) } new_line.buf[new_line.len] = 0; } + +static bool supports_format(const char *format) +{ + return format && (strcmp(format, "subrip") == 0 || + strcmp(format, "text") == 0); +} + +static int init(struct sd *sd) +{ + sd->output_codec = "ass-text"; + return 0; +} + +static void decode(struct sd *sd, struct demux_packet *packet) +{ + char dest[SD_MAX_LINE_LEN]; + // Assume input buffer is padded with 0 + convert_subrip(packet->buffer, dest, sizeof(dest)); + sd_conv_add_packet(sd, dest, strlen(dest), packet->pts, packet->duration); +} + +const struct sd_functions sd_srt = { + .supports_format = supports_format, + .init = init, + .decode = decode, + .get_converted = sd_conv_def_get_converted, + .reset = sd_conv_def_reset, +}; -- cgit v1.2.3