diff options
author | Clément Bœsch <ubitux@gmail.com> | 2012-06-17 13:43:09 +0400 |
---|---|---|
committer | Clément Bœsch <ubitux@gmail.com> | 2012-06-29 22:20:02 +0400 |
commit | d948893dbd963a268e2fc093b3d09b5037560974 (patch) | |
tree | 3cfd72744f9c1e92493a0740e47f36590e5e8817 /libavformat/subtitles.c | |
parent | e301f2f8c6f59485cb22fc468bafcfaa419c5267 (diff) |
lavf/subtitles: add some SMIL helpers.
This is needed for SAMI and RealText demuxers.
Diffstat (limited to 'libavformat/subtitles.c')
-rw-r--r-- | libavformat/subtitles.c | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/libavformat/subtitles.c b/libavformat/subtitles.c index f1b2dc0f48..12045262eb 100644 --- a/libavformat/subtitles.c +++ b/libavformat/subtitles.c @@ -20,6 +20,7 @@ #include "avformat.h" #include "subtitles.h" +#include "libavutil/avstring.h" AVPacket *ff_subtitles_queue_insert(FFDemuxSubtitlesQueue *q, const uint8_t *event, int len, int merge) @@ -99,3 +100,46 @@ void ff_subtitles_queue_clean(FFDemuxSubtitlesQueue *q) av_freep(&q->subs); q->nb_subs = q->allocated_size = q->current_sub_idx = 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; +} + +const char *ff_smil_get_attr_ptr(const char *s, const char *attr) +{ + int in_quotes = 0; + const int len = strlen(attr); + + while (*s) { + while (*s) { + if (!in_quotes && isspace(*s)) + break; + in_quotes ^= *s == '"'; // XXX: support escaping? + s++; + } + while (isspace(*s)) + s++; + if (!av_strncasecmp(s, attr, len) && s[len] == '=') + return s + len + 1 + (s[len + 1] == '"'); + } + return NULL; +} |