Commit 9d98535c authored by Aurelien Jacobs's avatar Aurelien Jacobs

use new metadata API in the mp3 demuxer

Originally committed as revision 16953 to svn://svn.ffmpeg.org/ffmpeg/trunk
parent 5ea7ce88
...@@ -167,10 +167,11 @@ static unsigned int id3v2_get_size(ByteIOContext *s, int len) ...@@ -167,10 +167,11 @@ static unsigned int id3v2_get_size(ByteIOContext *s, int len)
return v; return v;
} }
static void id3v2_read_ttag(AVFormatContext *s, int taglen, char *dst, int dstlen) static void id3v2_read_ttag(AVFormatContext *s, int taglen, const char *key)
{ {
char *q; char *q, dst[512];
int len; int len, dstlen = sizeof(dst);
unsigned genre;
if(dstlen > 0) if(dstlen > 0)
dst[0]= 0; dst[0]= 0;
...@@ -197,6 +198,13 @@ static void id3v2_read_ttag(AVFormatContext *s, int taglen, char *dst, int dstle ...@@ -197,6 +198,13 @@ static void id3v2_read_ttag(AVFormatContext *s, int taglen, char *dst, int dstle
dst[len] = 0; dst[len] = 0;
break; break;
} }
if (!strcmp(key, "genre")
&& sscanf(dst, "(%d)", &genre) == 1 && genre <= ID3v1_GENRE_MAX)
av_strlcpy(dst, id3v1_genre_str[genre], sizeof(dst));
if (*dst)
av_metadata_set(&s->metadata, key, dst);
} }
/** /**
...@@ -211,7 +219,6 @@ static void id3v2_parse(AVFormatContext *s, int len, uint8_t version, uint8_t fl ...@@ -211,7 +219,6 @@ static void id3v2_parse(AVFormatContext *s, int len, uint8_t version, uint8_t fl
int isv34, tlen; int isv34, tlen;
uint32_t tag; uint32_t tag;
int64_t next; int64_t next;
char tmp[16];
int taghdrlen; int taghdrlen;
const char *reason; const char *reason;
...@@ -263,28 +270,27 @@ static void id3v2_parse(AVFormatContext *s, int len, uint8_t version, uint8_t fl ...@@ -263,28 +270,27 @@ static void id3v2_parse(AVFormatContext *s, int len, uint8_t version, uint8_t fl
switch(tag) { switch(tag) {
case MKBETAG('T', 'I', 'T', '2'): case MKBETAG('T', 'I', 'T', '2'):
case MKBETAG(0, 'T', 'T', '2'): case MKBETAG(0, 'T', 'T', '2'):
id3v2_read_ttag(s, tlen, s->title, sizeof(s->title)); id3v2_read_ttag(s, tlen, "title");
break; break;
case MKBETAG('T', 'P', 'E', '1'): case MKBETAG('T', 'P', 'E', '1'):
case MKBETAG(0, 'T', 'P', '1'): case MKBETAG(0, 'T', 'P', '1'):
id3v2_read_ttag(s, tlen, s->author, sizeof(s->author)); id3v2_read_ttag(s, tlen, "author");
break; break;
case MKBETAG('T', 'A', 'L', 'B'): case MKBETAG('T', 'A', 'L', 'B'):
case MKBETAG(0, 'T', 'A', 'L'): case MKBETAG(0, 'T', 'A', 'L'):
id3v2_read_ttag(s, tlen, s->album, sizeof(s->album)); id3v2_read_ttag(s, tlen, "album");
break; break;
case MKBETAG('T', 'C', 'O', 'N'): case MKBETAG('T', 'C', 'O', 'N'):
case MKBETAG(0, 'T', 'C', 'O'): case MKBETAG(0, 'T', 'C', 'O'):
id3v2_read_ttag(s, tlen, s->genre, sizeof(s->genre)); id3v2_read_ttag(s, tlen, "genre");
break; break;
case MKBETAG('T', 'C', 'O', 'P'): case MKBETAG('T', 'C', 'O', 'P'):
case MKBETAG(0, 'T', 'C', 'R'): case MKBETAG(0, 'T', 'C', 'R'):
id3v2_read_ttag(s, tlen, s->copyright, sizeof(s->copyright)); id3v2_read_ttag(s, tlen, "copyright");
break; break;
case MKBETAG('T', 'R', 'C', 'K'): case MKBETAG('T', 'R', 'C', 'K'):
case MKBETAG(0, 'T', 'R', 'K'): case MKBETAG(0, 'T', 'R', 'K'):
id3v2_read_ttag(s, tlen, tmp, sizeof(tmp)); id3v2_read_ttag(s, tlen, "track");
s->track = atoi(tmp);
break; break;
case 0: case 0:
/* padding, skip to end */ /* padding, skip to end */
...@@ -305,22 +311,25 @@ static void id3v2_parse(AVFormatContext *s, int len, uint8_t version, uint8_t fl ...@@ -305,22 +311,25 @@ static void id3v2_parse(AVFormatContext *s, int len, uint8_t version, uint8_t fl
url_fskip(s->pb, len); url_fskip(s->pb, len);
} }
static void id3v1_get_string(char *str, int str_size, static void id3v1_get_string(AVFormatContext *s, const char *key,
const uint8_t *buf, int buf_size) const uint8_t *buf, int buf_size)
{ {
int i, c; int i, c;
char *q; char *q, str[512];
q = str; q = str;
for(i = 0; i < buf_size; i++) { for(i = 0; i < buf_size; i++) {
c = buf[i]; c = buf[i];
if (c == '\0') if (c == '\0')
break; break;
if ((q - str) >= str_size - 1) if ((q - str) >= sizeof(str) - 1)
break; break;
*q++ = c; *q++ = c;
} }
*q = '\0'; *q = '\0';
if (*str)
av_metadata_set(&s->metadata, key, str);
} }
/* 'buf' must be ID3v1_TAG_SIZE byte long */ /* 'buf' must be ID3v1_TAG_SIZE byte long */
...@@ -333,17 +342,18 @@ static int id3v1_parse_tag(AVFormatContext *s, const uint8_t *buf) ...@@ -333,17 +342,18 @@ static int id3v1_parse_tag(AVFormatContext *s, const uint8_t *buf)
buf[1] == 'A' && buf[1] == 'A' &&
buf[2] == 'G')) buf[2] == 'G'))
return -1; return -1;
id3v1_get_string(s->title, sizeof(s->title), buf + 3, 30); id3v1_get_string(s, "title", buf + 3, 30);
id3v1_get_string(s->author, sizeof(s->author), buf + 33, 30); id3v1_get_string(s, "author", buf + 33, 30);
id3v1_get_string(s->album, sizeof(s->album), buf + 63, 30); id3v1_get_string(s, "album", buf + 63, 30);
id3v1_get_string(str, sizeof(str), buf + 93, 4); id3v1_get_string(s, "year", buf + 93, 4);
s->year = atoi(str); id3v1_get_string(s, "comment", buf + 97, 30);
id3v1_get_string(s->comment, sizeof(s->comment), buf + 97, 30); if (buf[125] == 0 && buf[126] != 0) {
if (buf[125] == 0 && buf[126] != 0) snprintf(str, sizeof(str), "%d", buf[126]);
s->track = buf[126]; av_metadata_set(&s->metadata, "track", str);
}
genre = buf[127]; genre = buf[127];
if (genre <= ID3v1_GENRE_MAX) if (genre <= ID3v1_GENRE_MAX)
av_strlcpy(s->genre, id3v1_genre_str[genre], sizeof(s->genre)); av_metadata_set(&s->metadata, "genre", id3v1_genre_str[genre]);
return 0; return 0;
} }
......
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