[FFmpeg-devel] [PATCH] id3v2 unsynchronisation support

Michael Niedermayer michaelni
Sun Jul 25 13:14:24 CEST 2010


On Sun, Jul 25, 2010 at 11:14:03AM +1000, Alexander Kojevnikov wrote:
> On 24 July 2010 22:09, Reimar D?ffinger <Reimar.Doeffinger at gmx.de> wrote:
> > On Sat, Jul 24, 2010 at 09:58:10PM +1000, Alexander Kojevnikov wrote:
> >> On a side note, I'm seeing bogus "value computed is not used" warnings
> >> with this code (gcc 4.5.0), should something be done about them?
> >
> > They aren't bogus, it must be (*len)--, not *len--;
> > Or *len -= 1;
> > Or whatever other method.
> 
> Fixed.
> 
> >> + ? ?int byte;
> >
> > This can now be moved into the blocks where it is used.
> 
> Done.
> 
> >> - ? ? ? ?while (taglen-- && q - dst < dstlen - 7) {
> >> + ? ? ? ?byte = 0;
> >
> > Since there is no need to initialize it to 0.
> 
> Fixed in both places.

>  avio.h    |    3 +++
>  aviobuf.c |   13 +++++++++++++
>  2 files changed, 16 insertions(+)
> 1db99476a2cd27b16e3809201e44a8d7fa43d075  0001-aviobuf-add-peek_byte.patch
> From 0954eaad440b887a1608434441cfba39da9e6ba2 Mon Sep 17 00:00:00 2001
> From: Alexander Kojevnikov <alexander at kojevnikov.com>
> Date: Sun, 25 Jul 2010 11:08:03 +1000
> Subject: [PATCH 1/2] aviobuf: add peek_byte()
> 
> ---
>  libavformat/avio.h    |    3 +++
>  libavformat/aviobuf.c |   13 +++++++++++++
>  2 files changed, 16 insertions(+), 0 deletions(-)
> 
> diff --git a/libavformat/avio.h b/libavformat/avio.h
> index 3df9fad..caef9df 100644
> --- a/libavformat/avio.h
> +++ b/libavformat/avio.h
> @@ -420,6 +420,9 @@ int get_partial_buffer(ByteIOContext *s, unsigned char *buf, int size);
>  
>  /** @note return 0 if EOF, so you cannot use it if EOF handling is
>      necessary */
> +int peek_byte(ByteIOContext *s);
> +/** @note return 0 if EOF, so you cannot use it if EOF handling is
> +    necessary */
>  int get_byte(ByteIOContext *s);
>  unsigned int get_le24(ByteIOContext *s);
>  unsigned int get_le32(ByteIOContext *s);
> diff --git a/libavformat/aviobuf.c b/libavformat/aviobuf.c
> index 941691a..87d632a 100644
> --- a/libavformat/aviobuf.c
> +++ b/libavformat/aviobuf.c
> @@ -387,6 +387,19 @@ void init_checksum(ByteIOContext *s,
>      }
>  }
>  
> +int peek_byte(ByteIOContext *s)
> +{
> +    if (s->buf_ptr < s->buf_end) {
> +        return *s->buf_ptr;
> +    } else {
> +        fill_buffer(s);
> +        if (s->buf_ptr < s->buf_end)
> +            return *s->buf_ptr;
> +        else
> +            return 0;
> +    }

if(s->buf_ptr >= s->buf_end)
    fill_buffer(s);

if (s->buf_ptr < s->buf_end){
    return *s->buf_ptr;
}else
    return -1;



> +}
> +
>  /* XXX: put an inline version */
>  int get_byte(ByteIOContext *s)
>  {
> -- 
> 1.7.2
> 

>  id3v2.c |   75 ++++++++++++++++++++++++++++++++++++++++++++++++++++------------
>  1 file changed, 62 insertions(+), 13 deletions(-)
> 32a995088c6a42a5c54537a92e7768072a35a76c  0002-id3v2-unsynchronisation-support.patch
> From ef7189e1c5b0b4f1f471b49594f26ff392a9d270 Mon Sep 17 00:00:00 2001
> From: Alexander Kojevnikov <alexander at kojevnikov.com>
> Date: Sun, 25 Jul 2010 11:08:12 +1000
> Subject: [PATCH 2/2] id3v2: unsynchronisation support
> 
> ---
>  libavformat/id3v2.c |   75 ++++++++++++++++++++++++++++++++++++++++++---------
>  1 files changed, 62 insertions(+), 13 deletions(-)
> 
> diff --git a/libavformat/id3v2.c b/libavformat/id3v2.c
> index 7e4a16f..38c272a 100644
> --- a/libavformat/id3v2.c
> +++ b/libavformat/id3v2.c
> @@ -77,13 +77,39 @@ static unsigned int get_size(ByteIOContext *s, int len)
>      return v;
>  }
>  
> -static void read_ttag(AVFormatContext *s, int taglen, const char *key)
> +static int get_byte_resync(ByteIOContext *s, int *len)
> +{
> +    int val;
> +
> +    if (*len <= 0)
> +        return 0;
> +    val = get_byte(s);
> +    (*len)--;
> +    if (val == 0xff && *len > 0 && !peek_byte(s)) {
> +        get_byte(s);
> +        (*len)--;
> +    }
> +    return val;
> +}
> +
> +static unsigned int get_resync(ByteIOContext *s, int *len, int le)
> +{
> +    int val1, val2;
> +
> +    val1 = get_byte_resync(s, len);
> +    val2 = get_byte_resync(s, len);
> +
> +    return le ? val1 | (unsigned) val2 << 8 : (unsigned) val1 << 8 | val2;
> +}
> +
> +static void read_ttag(AVFormatContext *s, int taglen, const char *key, int resync)
>  {
>      char *q, dst[512];
>      const char *val = NULL;
>      int len, dstlen = sizeof(dst) - 1;
>      unsigned genre;
>      unsigned int (*get)(ByteIOContext*) = get_be16;
> +    int le = 0;
>  
>      dst[0] = 0;
>      if (taglen < 1)
> @@ -95,9 +121,16 @@ static void read_ttag(AVFormatContext *s, int taglen, const char *key)
>  
>      case 0:  /* ISO-8859-1 (0 - 255 maps directly into unicode) */
>          q = dst;
> -        while (taglen-- && q - dst < dstlen - 7) {
> +        while (taglen && q - dst < dstlen - 7) {
>              uint8_t tmp;
> -            PUT_UTF8(get_byte(s->pb), tmp, *q++ = tmp;)
> +            int byte;
> +            if (resync) {
> +                byte = get_byte_resync(s->pb, &taglen);
> +            } else {
> +                byte = get_byte(s->pb);
> +                taglen--;
> +            }
> +            PUT_UTF8(byte, tmp, *q++ = tmp;)
>          }
>          *q = 0;
>          break;
> @@ -107,6 +140,7 @@ static void read_ttag(AVFormatContext *s, int taglen, const char *key)
>          switch (get_be16(s->pb)) {
>          case 0xfffe:
>              get = get_le16;
> +            le = 1;
>          case 0xfeff:
>              break;
>          default:
> @@ -121,16 +155,30 @@ static void read_ttag(AVFormatContext *s, int taglen, const char *key)
>              uint32_t ch;
>              uint8_t tmp;
>  
> -            GET_UTF16(ch, ((taglen -= 2) >= 0 ? get(s->pb) : 0), break;)
> +            if (resync) {
> +                GET_UTF16(ch, get_resync(s->pb, &taglen, le), break;)
> +            } else {
> +                GET_UTF16(ch, ((taglen -= 2) >= 0 ? get(s->pb) : 0), break;)
> +            }
>              PUT_UTF8(ch, tmp, *q++ = tmp;)
>          }
>          *q = 0;
>          break;
>  
>      case 3:  /* UTF-8 */
> +        q = dst;
>          len = FFMIN(taglen, dstlen);
> -        get_buffer(s->pb, dst, len);
> -        dst[len] = 0;
> +        while (len) {
> +            int byte;
> +            if (resync) {
> +                byte = get_byte_resync(s->pb, &len);
> +            } else {
> +                byte = get_byte(s->pb);
> +                len--;
> +            }
> +            *q++ = byte;
> +        }
> +        *q = 0;
>          break;
>      default:
>          av_log(s, AV_LOG_WARNING, "Unknown encoding in tag %s\n.", key);

is this simpler than unescaping the buffer and keeping the same reading
code?


[...]
-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

Old school: Use the lowest level language in which you can solve the problem
            conveniently.
New school: Use the highest level language in which the latest supercomputer
            can solve the problem without the user falling asleep waiting.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 190 bytes
Desc: Digital signature
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20100725/1f7ded90/attachment.pgp>



More information about the ffmpeg-devel mailing list