[FFmpeg-devel] [PATCH] id3v2 unsynchronisation support

Reimar Döffinger Reimar.Doeffinger
Wed Jul 21 19:23:31 CEST 2010


On Wed, Jul 21, 2010 at 11:27:17AM +1000, Alexander Kojevnikov wrote:
> > Unsynchronisation is a scheme to avoid false synchronisation bytes in
> > the tag. It works by replacing all 11111111 111xxxxx bytes with
> > 11111111 00000000 111xxxxx. Which means that during decoding all
> > 11111111 00000000 sequences should be replaced with 11111111.

What an unbelievably ugly (if not actually stupid) scheme.
Just replacing 0xff by 0xff 0x00 always would have avoided
the need for look-ahead/buffering the last byte.

> Index: libavformat/id3v2.c
> ===================================================================
> --- libavformat/id3v2.c	(revision 24278)
> +++ libavformat/id3v2.c	(working copy)
> @@ -77,13 +77,41 @@
>      return v;
>  }
>  
> -static void read_ttag(AVFormatContext *s, int taglen, const char *key)
> +static int get_byte_resync (ByteIOContext *s, int prev, int *len)
>  {
> +    int val;
> +
> +    if (--*len < 0)
> +        return 0;
> +    val = get_byte (s);
> +    if (prev == 0xff && !val) {
> +        if (--*len < 0)
> +            return 0;
> +        val = get_byte (s);
> +    }
> +    return val;
> +}

I think instead a peek_byte function should be added that returns
the next byte, eliminating the need to keep a state here.
I think there should be some more ways to simplify this,
it seems too much code for what it does...



More information about the ffmpeg-devel mailing list