[FFmpeg-devel] [PATCH v2 4/6] avformat/realtextdec: UTF-16 support

wm4 nfxjfg at googlemail.com
Thu Sep 4 22:40:25 CEST 2014


Also remove ff_smil_extract_next_chunk - this was the last user of it.
---
No changes.
---
 libavformat/realtextdec.c | 17 ++++++++++-------
 libavformat/subtitles.c   |  9 ---------
 libavformat/subtitles.h   |  5 -----
 3 files changed, 10 insertions(+), 21 deletions(-)

diff --git a/libavformat/realtextdec.c b/libavformat/realtextdec.c
index e1225d5..19af108 100644
--- a/libavformat/realtextdec.c
+++ b/libavformat/realtextdec.c
@@ -37,11 +37,12 @@ typedef struct {
 
 static int realtext_probe(AVProbeData *p)
 {
-    const unsigned char *ptr = p->buf;
+    char buf[7];
+    FFTextReader tr;
+    ff_text_init_buf(&tr, p->buf, p->buf_size);
+    ff_text_read(&tr, buf, sizeof(buf));
 
-    if (AV_RB24(ptr) == 0xEFBBBF)
-        ptr += 3;  /* skip UTF-8 BOM */
-    return !av_strncasecmp(ptr, "<window", 7) ? AVPROBE_SCORE_EXTENSION : 0;
+    return !av_strncasecmp(buf, "<window", 7) ? AVPROBE_SCORE_EXTENSION : 0;
 }
 
 static int read_ts(const char *s)
@@ -63,6 +64,8 @@ static int realtext_read_header(AVFormatContext *s)
     AVBPrint buf;
     char c = 0;
     int res = 0, duration = read_ts("60"); // default duration is 60 seconds
+    FFTextReader tr;
+    ff_text_init_avio(&tr, s->pb);
 
     if (!st)
         return AVERROR(ENOMEM);
@@ -72,10 +75,10 @@ static int realtext_read_header(AVFormatContext *s)
 
     av_bprint_init(&buf, 0, AV_BPRINT_SIZE_UNLIMITED);
 
-    while (!avio_feof(s->pb)) {
+    while (!ff_text_eof(&tr)) {
         AVPacket *sub;
-        const int64_t pos = avio_tell(s->pb) - (c != 0);
-        int n = ff_smil_extract_next_chunk(s->pb, &buf, &c);
+        const int64_t pos = ff_text_pos(&tr) - (c != 0);
+        int n = ff_smil_extract_next_text_chunk(&tr, &buf, &c);
 
         if (n == 0)
             break;
diff --git a/libavformat/subtitles.c b/libavformat/subtitles.c
index d650504..3069477 100644
--- a/libavformat/subtitles.c
+++ b/libavformat/subtitles.c
@@ -295,15 +295,6 @@ int ff_smil_extract_next_text_chunk(FFTextReader *tr, AVBPrint *buf, char *c)
     return i;
 }
 
-int ff_smil_extract_next_chunk(AVIOContext *pb, AVBPrint *buf, char *c)
-{
-    FFTextReader tr;
-    tr.buf_pos = tr.buf_len = 0;
-    tr.type = 0;
-    tr.pb = pb;
-    return ff_smil_extract_next_text_chunk(&tr, buf, c);
-}
-
 const char *ff_smil_get_attr_ptr(const char *s, const char *attr)
 {
     int in_quotes = 0;
diff --git a/libavformat/subtitles.h b/libavformat/subtitles.h
index 3ef0bfc..b1608bf 100644
--- a/libavformat/subtitles.h
+++ b/libavformat/subtitles.h
@@ -147,11 +147,6 @@ void ff_subtitles_queue_clean(FFDemuxSubtitlesQueue *q);
  *
  * @param c cached character, to avoid a backward seek
  */
-int ff_smil_extract_next_chunk(AVIOContext *pb, AVBPrint *buf, char *c);
-
-/**
- * As ff_smil_extract_next_chunk(), but with FFTextReader.
- */
 int ff_smil_extract_next_text_chunk(FFTextReader *tr, AVBPrint *buf, char *c);
 
 /**
-- 
2.1.0



More information about the ffmpeg-devel mailing list