diff options
author | wm4 <wm4@nowhere> | 2013-06-01 19:54:18 +0200 |
---|---|---|
committer | wm4 <wm4@nowhere> | 2013-06-03 22:40:02 +0200 |
commit | e19ffa02aa370cbc3b559f85b286ea09b06ab29b (patch) | |
tree | 3335cdcc8664d9e3b98631fe8128b138c095069a /sub/sd_srt.c | |
parent | 14dd95154820d4ec9afb5200335177b011233049 (diff) | |
download | mpv-e19ffa02aa370cbc3b559f85b286ea09b06ab29b.tar.bz2 mpv-e19ffa02aa370cbc3b559f85b286ea09b06ab29b.tar.xz |
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.
Diffstat (limited to 'sub/sd_srt.c')
-rw-r--r-- | sub/sd_srt.c | 34 |
1 files changed, 31 insertions, 3 deletions
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 <stdarg.h> #include <stdbool.h> #include <ctype.h> +#include <libavutil/common.h> #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, +}; |