[FFmpeg-devel] [PATCH v5 2/2] libavformat/webp: add WebP demuxer

Carl Eugen Hoyos ceffmpeg at gmail.com
Sat Sep 12 16:41:28 EEST 2020


Am Fr., 11. Sept. 2020 um 08:36 Uhr schrieb Josef Zlomek <josef at pex.com>:

This is not the requested review, I am just curious about the
behaviour:

> +static int webp_probe(const AVProbeData *p)
> +{
> +    const uint8_t *b = p->buf;
> +
> +    if (AV_RB32(b)     == MKBETAG('R', 'I', 'F', 'F') &&
> +        AV_RB32(b + 8) == MKBETAG('W', 'E', 'B', 'P'))
> +        return AVPROBE_SCORE_MAX;

What happens if you pipe several (not animated) webp images
through your new demuxer?
Does it behave like the existing pipe demuxer?

> +static int ensure_seekback(AVFormatContext *s, int64_t bytes)
> +{
> +    WebPDemuxContext *wdc = s->priv_data;
> +    AVIOContext      *pb  = s->pb;
> +    int ret;
> +
> +    int64_t pos = avio_tell(pb);
> +    if (pos < 0)
> +        return pos;
> +
> +    if (pos + bytes <= wdc->seekback_buffer_end)
> +        return 0;
> +
> +    if ((ret = ffio_ensure_seekback(pb, bytes)) < 0)
> +        return ret;
> +
> +    wdc->seekback_buffer_end = pos + bytes;
> +    return 0;
> +}
> +
> +static int resync(AVFormatContext *s, int seek_to_start)
> +{
> +    WebPDemuxContext *wdc = s->priv_data;
> +    AVIOContext      *pb  = s->pb;
> +    int ret;
> +    int i;
> +    uint64_t state = 0;
> +
> +    // ensure seek back for the file header and the first chunk header
> +    if ((ret = ensure_seekback(s, 12 + 8)) < 0)
> +        return ret;
> +
> +    for (i = 0; i < 12; i++) {
> +        state = (state << 8) | avio_r8(pb);

> +        if (i == 11) {
> +            if ((uint32_t) state == MKBETAG('W', 'E', 'B', 'P'))

The cast looks really ugly: Why is it necessary?

Carl Eugen


More information about the ffmpeg-devel mailing list