Commit 41770abf authored by Anton Khirnov's avatar Anton Khirnov Committed by Ramiro Polla

id3v2: Export all text information frames with correct names.

Patch by Anton Khirnov <wyskas at gmail dot com>

Originally committed as revision 20171 to svn://svn.ffmpeg.org/ffmpeg/trunk
parent 078d89a2
...@@ -79,6 +79,7 @@ static unsigned int get_size(ByteIOContext *s, int len) ...@@ -79,6 +79,7 @@ static unsigned int get_size(ByteIOContext *s, int len)
static void read_ttag(AVFormatContext *s, int taglen, const char *key) static void read_ttag(AVFormatContext *s, int taglen, const char *key)
{ {
char *q, dst[512]; char *q, dst[512];
const char *val = NULL;
int len, dstlen = sizeof(dst) - 1; int len, dstlen = sizeof(dst) - 1;
unsigned genre; unsigned genre;
unsigned int (*get)(ByteIOContext*) = get_be16; unsigned int (*get)(ByteIOContext*) = get_be16;
...@@ -134,19 +135,28 @@ static void read_ttag(AVFormatContext *s, int taglen, const char *key) ...@@ -134,19 +135,28 @@ static void read_ttag(AVFormatContext *s, int taglen, const char *key)
av_log(s, AV_LOG_WARNING, "Unknown encoding in tag %s\n.", key); 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) && (sscanf(dst, "(%d)", &genre) == 1 || sscanf(dst, "%d", &genre) == 1)
&& genre <= ID3v1_GENRE_MAX) && 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) if (val)
av_metadata_set(&s->metadata, key, dst); av_metadata_set(&s->metadata, key, val);
} }
void ff_id3v2_parse(AVFormatContext *s, int len, uint8_t version, uint8_t flags) void ff_id3v2_parse(AVFormatContext *s, int len, uint8_t version, uint8_t flags)
{ {
int isv34, tlen; int isv34, tlen;
uint32_t tag; char tag[5];
int64_t next; int64_t next;
int taghdrlen; int taghdrlen;
const char *reason; const char *reason;
...@@ -182,14 +192,16 @@ void ff_id3v2_parse(AVFormatContext *s, int len, uint8_t version, uint8_t flags) ...@@ -182,14 +192,16 @@ void ff_id3v2_parse(AVFormatContext *s, int len, uint8_t version, uint8_t flags)
while (len >= taghdrlen) { while (len >= taghdrlen) {
if (isv34) { if (isv34) {
tag = get_be32(s->pb); get_buffer(s->pb, tag, 4);
tag[4] = 0;
if(version==3){ if(version==3){
tlen = get_be32(s->pb); tlen = get_be32(s->pb);
}else }else
tlen = get_size(s->pb, 4); tlen = get_size(s->pb, 4);
get_be16(s->pb); /* flags */ get_be16(s->pb); /* flags */
} else { } else {
tag = get_be24(s->pb); get_buffer(s->pb, tag, 3);
tag[3] = 0;
tlen = get_be24(s->pb); tlen = get_be24(s->pb);
} }
len -= taghdrlen + tlen; len -= taghdrlen + tlen;
...@@ -199,37 +211,9 @@ void ff_id3v2_parse(AVFormatContext *s, int len, uint8_t version, uint8_t flags) ...@@ -199,37 +211,9 @@ void ff_id3v2_parse(AVFormatContext *s, int len, uint8_t version, uint8_t flags)
next = url_ftell(s->pb) + tlen; next = url_ftell(s->pb) + tlen;
switch (tag) { if (tag[0] == 'T')
case MKBETAG('T', 'I', 'T', '2'): read_ttag(s, tlen, tag);
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 */
url_fskip(s->pb, len);
len = 0;
continue;
}
/* Skip to end of tag */ /* Skip to end of tag */
url_fseek(s->pb, next, SEEK_SET); url_fseek(s->pb, next, SEEK_SET);
} }
......
...@@ -183,6 +183,7 @@ AVInputFormat mp3_demuxer = { ...@@ -183,6 +183,7 @@ AVInputFormat mp3_demuxer = {
mp3_read_packet, mp3_read_packet,
.flags= AVFMT_GENERIC_INDEX, .flags= AVFMT_GENERIC_INDEX,
.extensions = "mp2,mp3,m2a", /* XXX: use probe */ .extensions = "mp2,mp3,m2a", /* XXX: use probe */
.metadata_conv = ff_id3v2_metadata_conv,
}; };
#endif #endif
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment