static void read_ttag(AVFormatContext *s, int taglen, const char *key)
{
char *q, dst[512];
+ const char *val = NULL;
int len, dstlen = sizeof(dst) - 1;
unsigned genre;
+ unsigned int (*get)(ByteIOContext*) = get_be16;
dst[0] = 0;
if (taglen < 1)
*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")
+ if (!(strcmp(key, "TCON") && strcmp(key, "TCO"))
&& (sscanf(dst, "(%d)", &genre) == 1 || sscanf(dst, "%d", &genre) == 1)
&& genre <= ID3v1_GENRE_MAX)
- av_strlcpy(dst, ff_id3v1_genre_str[genre], sizeof(dst));
+ val = ff_id3v1_genre_str[genre];
+ else if (!(strcmp(key, "TXXX") && strcmp(key, "TXX"))) {
+ /* dst now contains two 0-terminated strings */
+ dst[dstlen] = 0;
+ len = strlen(dst);
+ key = dst;
+ val = dst + FFMIN(len + 1, dstlen);
+ }
+ else if (*dst)
+ val = dst;
- if (*dst)
- av_metadata_set(&s->metadata, key, dst);
+ if (val)
+ av_metadata_set(&s->metadata, key, val);
}
void ff_id3v2_parse(AVFormatContext *s, int len, uint8_t version, uint8_t flags)
{
int isv34, tlen;
- uint32_t tag;
+ char tag[5];
int64_t next;
int taghdrlen;
const char *reason;
while (len >= taghdrlen) {
if (isv34) {
- tag = get_be32(s->pb);
+ get_buffer(s->pb, tag, 4);
+ tag[4] = 0;
if(version==3){
tlen = get_be32(s->pb);
}else
tlen = get_size(s->pb, 4);
get_be16(s->pb); /* flags */
} else {
- tag = get_be24(s->pb);
+ get_buffer(s->pb, tag, 3);
+ tag[3] = 0;
tlen = get_be24(s->pb);
}
len -= taghdrlen + tlen;
next = url_ftell(s->pb) + tlen;
- switch (tag) {
- case MKBETAG('T', 'I', 'T', '2'):
- case MKBETAG(0, 'T', 'T', '2'):
- read_ttag(s, tlen, "title");
- break;
- case MKBETAG('T', 'P', 'E', '1'):
- case MKBETAG(0, 'T', 'P', '1'):
- read_ttag(s, tlen, "author");
- break;
- case MKBETAG('T', 'A', 'L', 'B'):
- case MKBETAG(0, 'T', 'A', 'L'):
- read_ttag(s, tlen, "album");
- break;
- case MKBETAG('T', 'C', 'O', 'N'):
- case MKBETAG(0, 'T', 'C', 'O'):
- read_ttag(s, tlen, "genre");
- break;
- case MKBETAG('T', 'C', 'O', 'P'):
- case MKBETAG(0, 'T', 'C', 'R'):
- read_ttag(s, tlen, "copyright");
- break;
- case MKBETAG('T', 'R', 'C', 'K'):
- case MKBETAG(0, 'T', 'R', 'K'):
- read_ttag(s, tlen, "track");
- break;
- case 0:
- /* padding, skip to end */
+ if (tag[0] == 'T')
+ read_ttag(s, tlen, tag);
+ else if (!tag[0]) {
+ if (tag[1])
+ av_log(s, AV_LOG_WARNING, "invalid frame id, assuming padding");
url_fskip(s->pb, len);
- len = 0;
- continue;
+ break;
}
/* Skip to end of tag */
url_fseek(s->pb, next, SEEK_SET);
av_log(s, AV_LOG_INFO, "ID3v2.%d tag skipped, cannot handle %s\n", version, reason);
url_fskip(s->pb, len);
}
+
+const AVMetadataConv ff_id3v2_metadata_conv[] = {
+ { "TALB", "album"},
+ { "TAL", "album"},
+ { "TCOM", "composer"},
+ { "TCON", "genre"},
+ { "TCO", "genre"},
+ { "TCOP", "copyright"},
+ { "TDRL", "date"},
+ { "TENC", "encoder"},
+ { "TEN", "encoder"},
+ { "TIT2", "title"},
+ { "TT2", "title"},
+ { "TLAN", "language"},
+ { "TPE1", "artist"},
+ { "TP1", "artist"},
+ { "TPOS", "disc"},
+ { "TPUB", "publisher"},
+ { "TRCK", "track"},
+ { "TRK", "track"},
+ { "TSOA", "albumsort"},
+ { "TSOP", "authorsort"},
+ { "TSOT", "titlesort"},
+ { 0 }
+};
+
+const char ff_id3v2_tags[][4] = {
+ "TALB", "TBPM", "TCOM", "TCON", "TCOP", "TDEN", "TDLY", "TDOR", "TDRC",
+ "TDRL", "TDTG", "TENC", "TEXT", "TFLT", "TIPL", "TIT1", "TIT2", "TIT3",
+ "TKEY", "TLAN", "TLEN", "TMCL", "TMED", "TMOO", "TOAL", "TOFN", "TOLY",
+ "TOPE", "TOWN", "TPE1", "TPE2", "TPE3", "TPE4", "TPOS", "TPRO", "TPUB",
+ "TRCK", "TRSN", "TRSO", "TSOA", "TSOP", "TSOT", "TSRC", "TSSE", "TSST",
+ { 0 },
+};