[FFmpeg-devel] [PATCH 1/3] lavf/subtitles: add some SMIL helpers.
Nicolas George
nicolas.george at normalesup.org
Sun Jun 17 15:16:19 CEST 2012
Le decadi 30 prairial, an CCXX, Clément Bœsch a écrit :
> 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;
> +}
Unless I am mistaken, ff_smil_get_attr_ptr(s, "x") will find the "index"
too.
> 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
> + */
I find that comment rather obscure. Especially since it looks like you are
scanning for what is called, in HTML, an attribute and not a tag.
> +char *ff_smil_get_attr_ptr(const char *s, const char *tag);
> +
> #endif /* AVFORMAT_SUBTITLES_H */
Regards,
--
Nicolas George
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: Digital signature
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20120617/56bf54fc/attachment.asc>
More information about the ffmpeg-devel
mailing list