[FFmpeg-devel] [PATCH 1/3] lavf/subtitles: add some SMIL helpers.

Clément Bœsch ubitux at gmail.com
Sun Jun 17 11:57:33 CEST 2012


This is needed for SAMI and RealText demuxers.
---
 libavformat/subtitles.c |   35 +++++++++++++++++++++++++++++++++++
 libavformat/subtitles.h |   13 +++++++++++++
 2 files changed, 48 insertions(+)

diff --git a/libavformat/subtitles.c b/libavformat/subtitles.c
index 5e3cdee..39e18f8 100644
--- a/libavformat/subtitles.c
+++ b/libavformat/subtitles.c
@@ -20,6 +20,7 @@
 
 #include "avformat.h"
 #include "subtitles.h"
+#include "libavutil/avstring.h"
 
 FFDemuxSubEntry *ff_subtitles_queue_insert_event(FFDemuxSubtitlesQueue *q,
                                                  const uint8_t *event, int len,
@@ -105,3 +106,37 @@ void ff_subtitles_queue_free(FFDemuxSubtitlesQueue *q)
     av_freep(&q->subs);
     q->nsub = q->allocated_size = 0;
 }
+
+int ff_smil_extract_next_chunk(AVIOContext *pb, AVBPrint *buf, char *c)
+{
+    int i = 0;
+    char end_chr;
+
+    if (!*c) // cached char?
+        *c = avio_r8(pb);
+    if (!*c)
+        return 0;
+
+    end_chr = *c == '<' ? '>' : '<';
+    do {
+        av_bprint_chars(buf, *c, 1);
+        *c = avio_r8(pb);
+        i++;
+    } while (*c != end_chr && *c);
+    if (end_chr == '>') {
+        av_bprint_chars(buf, '>', 1);
+        *c = 0;
+    }
+    return i;
+}
+
+char *ff_smil_get_attr_ptr(const char *s, const char *tag)
+{
+    char *p = av_stristr(s, tag);
+    if (p) {
+        p += strlen(tag);
+        if (*p == '=') p++;
+        if (*p == '"') p++;
+    }
+    return p;
+}
diff --git a/libavformat/subtitles.h b/libavformat/subtitles.h
index c098131..be875cd 100644
--- a/libavformat/subtitles.h
+++ b/libavformat/subtitles.h
@@ -23,6 +23,7 @@
 
 #include <stdint.h>
 #include "avformat.h"
+#include "libavutil/bprint.h"
 
 typedef struct {
     uint8_t *event;         ///< allocated subtitle line, zero terminated
@@ -67,4 +68,16 @@ int ff_subtitles_queue_read_packet(FFDemuxSubtitlesQueue *q,
  */
 void ff_subtitles_queue_free(FFDemuxSubtitlesQueue *q);
 
+/**
+ * SMIL helper to load next chunk ("<...>" or untagged content) in buf
+ *
+ * @param c cached character, to avoid a backward seek
+ */
+int ff_smil_extract_next_chunk(AVIOContext *pb, AVBPrint *buf, char *c);
+
+/**
+ * SMIL helper to point on the value of a given tag
+ */
+char *ff_smil_get_attr_ptr(const char *s, const char *tag);
+
 #endif /* AVFORMAT_SUBTITLES_H */
-- 
1.7.10.4



More information about the ffmpeg-devel mailing list