[FFmpeg-devel] [PATCH 1/6] id3v2: use an enum for encodings instead of magic numbers.

Måns Rullgård mans
Fri Jan 21 19:40:03 CET 2011


Anton Khirnov <anton at khirnov.net> writes:

> From 38bbbde3d9c3b464f74eb975e6305eacc5c10808 Mon Sep 17 00:00:00 2001
> From: Anton Khirnov <anton at khirnov.net>
> Date: Wed, 19 Jan 2011 10:13:25 +0100
> Subject: [PATCH] id3v2: use an enum for encodings instead of magic numbers.
>
> ---
>  libavformat/id3v2.c |    8 ++++----
>  libavformat/id3v2.h |    7 +++++++
>  2 files changed, 11 insertions(+), 4 deletions(-)
>
> diff --git a/libavformat/id3v2.c b/libavformat/id3v2.c
> index 95ec0b0..62eee15 100644
> --- a/libavformat/id3v2.c
> +++ b/libavformat/id3v2.c
> @@ -74,7 +74,7 @@ static void read_ttag(AVFormatContext *s, ByteIOContext *pb, int taglen, const c
>  
>      switch (get_byte(pb)) { /* encoding type */
>  
> -    case 0:  /* ISO-8859-1 (0 - 255 maps directly into unicode) */
> +    case ID3v2_ENCODING_ISO8859:
>          q = dst;
>          while (taglen-- && q - dst < dstlen - 7) {
>              uint8_t tmp;
> @@ -83,7 +83,7 @@ static void read_ttag(AVFormatContext *s, ByteIOContext *pb, int taglen, const c
>          *q = 0;
>          break;
>  
> -    case 1:  /* UTF-16 with BOM */
> +    case ID3v2_ENCODING_UTF16BOM:
>          taglen -= 2;
>          switch (get_be16(pb)) {
>          case 0xfffe:
> @@ -96,7 +96,7 @@ static void read_ttag(AVFormatContext *s, ByteIOContext *pb, int taglen, const c
>          }
>          // fall-through
>  
> -    case 2:  /* UTF-16BE without BOM */
> +    case ID3v2_ENCODING_UTF16BE:
>          q = dst;
>          while (taglen > 1 && q - dst < dstlen - 7) {
>              uint32_t ch;
> @@ -108,7 +108,7 @@ static void read_ttag(AVFormatContext *s, ByteIOContext *pb, int taglen, const c
>          *q = 0;
>          break;
>  
> -    case 3:  /* UTF-8 */
> +    case ID3v2_ENCODING_UTF8:
>          len = FFMIN(taglen, dstlen);
>          get_buffer(pb, dst, len);
>          dst[len] = 0;
> diff --git a/libavformat/id3v2.h b/libavformat/id3v2.h
> index 25ee53e..c2e1add 100644
> --- a/libavformat/id3v2.h
> +++ b/libavformat/id3v2.h
> @@ -38,6 +38,13 @@
>  #define ID3v2_FLAG_ENCRYPTION  0x0004
>  #define ID3v2_FLAG_COMPRESSION 0x0008
>  
> +enum ID3v2Encoding {
> +    ID3v2_ENCODING_ISO8859  = 0,
> +    ID3v2_ENCODING_UTF16BOM = 1,
> +    ID3v2_ENCODING_UTF16BE  = 2,
> +    ID3v2_ENCODING_UTF8     = 3,
> +};
> +
>  /**
>   * Detect ID3v2 Header.
>   * @param buf   must be ID3v2_HEADER_SIZE byte long
> -- 
> 1.7.2.3

OK, pushing.

-- 
M?ns Rullg?rd
mans at mansr.com



More information about the ffmpeg-devel mailing list