[FFmpeg-devel] [PATCH 1/5] id3v2: use an enum for encodings instead of magic numbers.
Anton Khirnov
anton
Fri Jan 21 14:53:45 CET 2011
---
libavformat/id3v2.c | 10 +++++-----
libavformat/id3v2.h | 7 +++++++
2 files changed, 12 insertions(+), 5 deletions(-)
diff --git a/libavformat/id3v2.c b/libavformat/id3v2.c
index 67a50e2..bbe9d52 100644
--- a/libavformat/id3v2.c
+++ b/libavformat/id3v2.c
@@ -65,7 +65,7 @@ static unsigned int get_size(ByteIOContext *s, int len)
* Return number of bytes read from pb or a negative number on error.
*/
static int decode_string(AVFormatContext *s, ByteIOContext *pb, char *dst, int dstlen,
- int maxlen, int encoding)
+ int maxlen, enum ID3v2Encoding encoding)
{
int len;
int bytes_read = 0;
@@ -74,7 +74,7 @@ static int decode_string(AVFormatContext *s, ByteIOContext *pb, char *dst, int d
switch (encoding) { /* encoding type */
- case 0: /* ISO-8859-1 (0 - 255 maps directly into unicode) */
+ case ID3v2_ENCODING_ISO8859:
q = dst;
while (bytes_read++ < maxlen && q - dst < dstlen - 7) {
uint8_t tmp;
@@ -83,7 +83,7 @@ static int decode_string(AVFormatContext *s, ByteIOContext *pb, char *dst, int d
*q = 0;
break;
- case 1: /* UTF-16 with BOM */
+ case ID3v2_ENCODING_UTF16BOM:
bytes_read += 2;
switch (get_be16(pb)) {
case 0xfffe:
@@ -96,7 +96,7 @@ static int decode_string(AVFormatContext *s, ByteIOContext *pb, char *dst, int d
}
// fall-through
- case 2: /* UTF-16BE without BOM */
+ case ID3v2_ENCODING_UTF16BE:
q = dst;
while (bytes_read + 1 < maxlen && q - dst < dstlen - 7) {
uint32_t ch;
@@ -108,7 +108,7 @@ static int decode_string(AVFormatContext *s, ByteIOContext *pb, char *dst, int d
*q = 0;
break;
- case 3: /* UTF-8 */
+ case ID3v2_ENCODING_UTF8:
len = FFMIN(maxlen, dstlen);
get_buffer(pb, dst, len);
dst[len] = 0;
diff --git a/libavformat/id3v2.h b/libavformat/id3v2.h
index 25ee53e..3f89aca 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,
+ ID3v2_ENCODING_UTF16BOM,
+ ID3v2_ENCODING_UTF16BE,
+ ID3v2_ENCODING_UTF8,
+};
+
/**
* Detect ID3v2 Header.
* @param buf must be ID3v2_HEADER_SIZE byte long
--
1.7.2.3
More information about the ffmpeg-devel
mailing list