summaryrefslogtreecommitdiff
path: root/libavformat/assdec.c
diff options
context:
space:
mode:
authorwm4 <nfxjfg@googlemail.com>2014-09-02 20:48:45 +0200
committerClément Bœsch <u@pkh.me>2014-09-05 23:13:07 +0200
commit3e8426170ce005c111dfcae7982e18b647b7383f (patch)
tree2c99e5e08a455bba9b3b411134118d0d2c693c49 /libavformat/assdec.c
parentdcb29d37d4ffedc84e44df99f8d22ecf27e0f2cd (diff)
avformat/assdec: UTF-16 support
Use the UTF-16 BOM to detect UTF-16 encoding. Convert the file contents to UTF-8 on the fly using FFTextReader, which acts as converting wrapper around AVIOContext. It also can work on a static buffer, needed for format probing. The FFTextReader wrapper now also takes care of skipping the UTF-8 BOM. Fix Ticket #3496.
Diffstat (limited to 'libavformat/assdec.c')
-rw-r--r--libavformat/assdec.c19
1 files changed, 12 insertions, 7 deletions
diff --git a/libavformat/assdec.c b/libavformat/assdec.c
index bb953c7276..a5f792aee4 100644
--- a/libavformat/assdec.c
+++ b/libavformat/assdec.c
@@ -33,10 +33,13 @@ typedef struct ASSContext {
static int ass_probe(AVProbeData *p)
{
- const char *header = "[Script Info]";
+ char buf[13];
+ FFTextReader tr;
+ ff_text_init_buf(&tr, p->buf, p->buf_size);
- if (!memcmp(p->buf, header, strlen(header)) ||
- !memcmp(p->buf + 3, header, strlen(header)))
+ ff_text_read(&tr, buf, sizeof(buf));
+
+ if (!memcmp(buf, "[Script Info]", 13))
return AVPROBE_SCORE_MAX;
return 0;
@@ -66,13 +69,13 @@ static int read_ts(const uint8_t *p, int64_t *start, int *duration)
return -1;
}
-static int64_t get_line(AVBPrint *buf, AVIOContext *pb)
+static int64_t get_line(AVBPrint *buf, FFTextReader *tr)
{
- int64_t pos = avio_tell(pb);
+ int64_t pos = ff_text_pos(tr);
av_bprint_clear(buf);
for (;;) {
- char c = avio_r8(pb);
+ char c = ff_text_r8(tr);
if (!c)
break;
av_bprint_chars(buf, c, 1);
@@ -88,6 +91,8 @@ static int ass_read_header(AVFormatContext *s)
AVBPrint header, line;
int header_remaining, res = 0;
AVStream *st;
+ FFTextReader tr;
+ ff_text_init_avio(&tr, s->pb);
st = avformat_new_stream(s, NULL);
if (!st)
@@ -102,7 +107,7 @@ static int ass_read_header(AVFormatContext *s)
av_bprint_init(&line, 0, AV_BPRINT_SIZE_UNLIMITED);
for (;;) {
- int64_t pos = get_line(&line, s->pb);
+ int64_t pos = get_line(&line, &tr);
if (!line.str[0]) // EOF
break;