changeset 5231:d2e3bc991df4 libavformat

id3v2: Add support for UTF-16 encoding. patch by Anton Khirnov, wyskas gmail com
author diego
date Wed, 23 Sep 2009 18:22:00 +0000
parents 0d26775e9f47
children ee0eaff74dd3
files id3v2.c
diffstat 1 files changed, 28 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/id3v2.c	Wed Sep 23 18:10:29 2009 +0000
+++ b/id3v2.c	Wed Sep 23 18:22:00 2009 +0000
@@ -81,6 +81,7 @@
     char *q, dst[512];
     int len, dstlen = sizeof(dst) - 1;
     unsigned genre;
+    unsigned int (*get)(ByteIOContext*) = get_be16;
 
     dst[0] = 0;
     if (taglen < 1)
@@ -99,11 +100,38 @@
         *q = 0;
         break;
 
+    case 1:  /* UTF-16 with BOM */
+        taglen -= 2;
+        switch (get_be16(s->pb)) {
+        case 0xfffe:
+            get = get_le16;
+        case 0xfeff:
+            break;
+        default:
+            av_log(s, AV_LOG_ERROR, "Incorrect BOM value in tag %s.\n", key);
+            return;
+        }
+        // fall-through
+
+    case 2:  /* UTF-16BE without BOM */
+        q = dst;
+        while (taglen > 1 && q - dst < dstlen - 7) {
+            uint32_t ch;
+            uint8_t tmp;
+
+            GET_UTF16(ch, ((taglen -= 2) >= 0 ? get(s->pb) : 0), break;)
+            PUT_UTF8(ch, tmp, *q++ = tmp;)
+        }
+        *q = 0;
+        break;
+
     case 3:  /* UTF-8 */
         len = FFMIN(taglen, dstlen - 1);
         get_buffer(s->pb, dst, len);
         dst[len] = 0;
         break;
+    default:
+        av_log(s, AV_LOG_WARNING, "Unknown encoding in tag %s\n.", key);
     }
 
     if (!strcmp(key, "genre")