From d658ef18e3d1ebe63a64f404ac4646890ecf02c9 Mon Sep 17 00:00:00 2001 From: wm4 Date: Tue, 2 Sep 2014 20:52:07 +0200 Subject: avformat/srtdec: UTF-16 support --- libavformat/subtitles.h | 34 +++++++++++++++++++++++++++++++--- 1 file changed, 31 insertions(+), 3 deletions(-) (limited to 'libavformat/subtitles.h') diff --git a/libavformat/subtitles.h b/libavformat/subtitles.h index 38502d6f86..cf8c408486 100644 --- a/libavformat/subtitles.h +++ b/libavformat/subtitles.h @@ -22,6 +22,7 @@ #define AVFORMAT_SUBTITLES_H #include +#include #include "avformat.h" #include "libavutil/bprint.h" @@ -80,6 +81,16 @@ int64_t ff_text_pos(FFTextReader *r); */ int ff_text_r8(FFTextReader *r); +/** + * Return non-zero if EOF was reached. + */ +int ff_text_eof(FFTextReader *r); + +/** + * Like ff_text_r8(), but don't remove the byte from the buffer. + */ +int ff_text_peek_r8(FFTextReader *r); + /** * Read the given number of bytes (in UTF-8). On error or EOF, \0 bytes are * written. @@ -144,19 +155,24 @@ int ff_smil_extract_next_chunk(AVIOContext *pb, AVBPrint *buf, char *c); const char *ff_smil_get_attr_ptr(const char *s, const char *attr); /** - * @brief Read a subtitles chunk. + * @brief Same as ff_subtitles_read_text_chunk(), but read from an AVIOContext. + */ +void ff_subtitles_read_chunk(AVIOContext *pb, AVBPrint *buf); + +/** + * @brief Read a subtitles chunk from FFTextReader. * * A chunk is defined by a multiline "event", ending with a second line break. * The trailing line breaks are trimmed. CRLF are supported. * Example: "foo\r\nbar\r\n\r\nnext" will print "foo\r\nbar" into buf, and pb * will focus on the 'n' of the "next" string. * - * @param pb I/O context + * @param tr I/O context * @param buf an initialized buf where the chunk is written * * @note buf is cleared before writing into it. */ -void ff_subtitles_read_chunk(AVIOContext *pb, AVBPrint *buf); +void ff_subtitles_read_text_chunk(FFTextReader *tr, AVBPrint *buf); /** * Get the number of characters to increment to jump to the next line, or to @@ -177,4 +193,16 @@ static av_always_inline int ff_subtitles_next_line(const char *ptr) return n; } +/** + * Read a line of text. Discards line ending characters. + * The function handles the following line breaks schemes: + * LF, CRLF (MS), or standalone CR (old MacOS). + * + * Returns the number of bytes written to buf. Always writes a terminating 0, + * similar as with snprintf. + * + * @note returns a negative error code if a \0 byte is found + */ +ptrdiff_t ff_subtitles_read_line(FFTextReader *tr, char *buf, size_t size); + #endif /* AVFORMAT_SUBTITLES_H */ -- cgit v1.2.3