summaryrefslogtreecommitdiff
path: root/libavformat/srtdec.c
diff options
context:
space:
mode:
authorwm4 <nfxjfg@googlemail.com>2014-09-02 20:52:07 +0200
committerClément Bœsch <u@pkh.me>2014-09-05 23:13:07 +0200
commitd658ef18e3d1ebe63a64f404ac4646890ecf02c9 (patch)
tree914ba72abb4caa1ea91dd805493d3e7fa6b9339c /libavformat/srtdec.c
parent3e8426170ce005c111dfcae7982e18b647b7383f (diff)
avformat/srtdec: UTF-16 support
Diffstat (limited to 'libavformat/srtdec.c')
-rw-r--r--libavformat/srtdec.c25
1 files changed, 14 insertions, 11 deletions
diff --git a/libavformat/srtdec.c b/libavformat/srtdec.c
index 53182cda92..b63d3444d3 100644
--- a/libavformat/srtdec.c
+++ b/libavformat/srtdec.c
@@ -31,20 +31,21 @@ typedef struct {
static int srt_probe(AVProbeData *p)
{
- const unsigned char *ptr = p->buf;
int i, v, num = 0;
+ FFTextReader tr;
- if (AV_RB24(ptr) == 0xEFBBBF)
- ptr += 3; /* skip UTF-8 BOM */
+ ff_text_init_buf(&tr, p->buf, p->buf_size);
- while (*ptr == '\r' || *ptr == '\n')
- ptr++;
+ while (ff_text_peek_r8(&tr) == '\r' || ff_text_peek_r8(&tr) == '\n')
+ ff_text_r8(&tr);
for (i=0; i<2; i++) {
+ char buf[128];
+ if (ff_subtitles_read_line(&tr, buf, sizeof(buf)) < 0)
+ break;
if ((num == i || num + 1 == i)
- && sscanf(ptr, "%*d:%*2d:%*2d%*1[,.]%*3d --> %*d:%*2d:%*2d%*1[,.]%3d", &v) == 1)
+ && sscanf(buf, "%*d:%*2d:%*2d%*1[,.]%*3d --> %*d:%*2d:%*2d%*1[,.]%3d", &v) == 1)
return AVPROBE_SCORE_MAX;
- num = atoi(ptr);
- ptr += ff_subtitles_next_line(ptr);
+ num = atoi(buf);
}
return 0;
}
@@ -79,6 +80,8 @@ static int srt_read_header(AVFormatContext *s)
AVBPrint buf;
AVStream *st = avformat_new_stream(s, NULL);
int res = 0;
+ FFTextReader tr;
+ ff_text_init_avio(&tr, s->pb);
if (!st)
return AVERROR(ENOMEM);
@@ -88,11 +91,11 @@ static int srt_read_header(AVFormatContext *s)
av_bprint_init(&buf, 0, AV_BPRINT_SIZE_UNLIMITED);
- while (!avio_feof(s->pb)) {
- ff_subtitles_read_chunk(s->pb, &buf);
+ while (!ff_text_eof(&tr)) {
+ ff_subtitles_read_text_chunk(&tr, &buf);
if (buf.len) {
- int64_t pos = avio_tell(s->pb);
+ int64_t pos = ff_text_pos(&tr);
int64_t pts;
int duration;
const char *ptr = buf.str;