static void id3v2_read_ttag(AVFormatContext *s, int taglen, const char *key)
{
char *q, dst[512];
- int len, dstlen = sizeof(dst);
+ int len, dstlen = sizeof(dst) - 1;
unsigned genre;
- if(dstlen > 0)
- dst[0]= 0;
+ dst[0]= 0;
if(taglen < 1)
return;
taglen--; /* account for encoding type byte */
- dstlen--; /* Leave space for zero terminator */
switch(get_byte(s->pb)) { /* encoding type */
}
if (!strcmp(key, "genre")
- && sscanf(dst, "(%d)", &genre) == 1 && genre <= ID3v1_GENRE_MAX)
+ && (sscanf(dst, "(%d)", &genre) == 1 || sscanf(dst, "%d", &genre) == 1)
+ && genre <= ID3v1_GENRE_MAX)
av_strlcpy(dst, id3v1_genre_str[genre], sizeof(dst));
if (*dst)
if (first_frames>=3) return AVPROBE_SCORE_MAX/2+1;
else if(max_frames>500)return AVPROBE_SCORE_MAX/2;
else if(max_frames>=3) return AVPROBE_SCORE_MAX/4;
+ else if(buf0!=p->buf) return AVPROBE_SCORE_MAX/4-1;
else if(max_frames>=1) return 1;
else return 0;
}
}
#if CONFIG_MP2_MUXER || CONFIG_MP3_MUXER
-static void id3v1_create_tag(AVFormatContext *s, uint8_t *buf)
+static int id3v1_set_string(AVFormatContext *s, const char *key,
+ uint8_t *buf, int buf_size)
{
- int v, i;
+ AVMetadataTag *tag;
+ if ((tag = av_metadata_get(s->metadata, key, NULL, 0)))
+ strncpy(buf, tag->value, buf_size);
+ return !!tag;
+}
+
+static int id3v1_create_tag(AVFormatContext *s, uint8_t *buf)
+{
+ AVMetadataTag *tag;
+ int i, count = 0;
memset(buf, 0, ID3v1_TAG_SIZE); /* fail safe */
buf[0] = 'T';
buf[1] = 'A';
buf[2] = 'G';
- strncpy(buf + 3, s->title, 30);
- strncpy(buf + 33, s->author, 30);
- strncpy(buf + 63, s->album, 30);
- v = s->year;
- if (v > 0) {
- for(i = 0;i < 4; i++) {
- buf[96 - i] = '0' + (v % 10);
- v = v / 10;
- }
- }
- strncpy(buf + 97, s->comment, 30);
- if (s->track != 0) {
+ count += id3v1_set_string(s, "title", buf + 3, 30);
+ count += id3v1_set_string(s, "author", buf + 33, 30);
+ count += id3v1_set_string(s, "album", buf + 63, 30);
+ count += id3v1_set_string(s, "year", buf + 93, 4);
+ count += id3v1_set_string(s, "comment", buf + 97, 30);
+ if ((tag = av_metadata_get(s->metadata, "track", NULL, 0))) {
buf[125] = 0;
- buf[126] = s->track;
+ buf[126] = atoi(tag->value);
+ count++;
}
- for(i = 0; i <= ID3v1_GENRE_MAX; i++) {
- if (!strcasecmp(s->genre, id3v1_genre_str[i])) {
- buf[127] = i;
- break;
+ if ((tag = av_metadata_get(s->metadata, "genre", NULL, 0))) {
+ for(i = 0; i <= ID3v1_GENRE_MAX; i++) {
+ if (!strcasecmp(tag->value, id3v1_genre_str[i])) {
+ buf[127] = i;
+ count++;
+ break;
+ }
}
}
+ return count;
}
/* simple formats */
static int mp3_write_header(struct AVFormatContext *s)
{
+ AVMetadataTag *title, *author, *album, *genre, *copyright, *track, *year;
int totlen = 0;
- char tracktxt[10];
- char yeartxt[10];
-
- if(s->track)
- snprintf(tracktxt, sizeof(tracktxt), "%d", s->track);
- if(s->year)
- snprintf( yeartxt, sizeof(yeartxt) , "%d", s->year );
-
- if(s->title[0]) totlen += 11 + strlen(s->title);
- if(s->author[0]) totlen += 11 + strlen(s->author);
- if(s->album[0]) totlen += 11 + strlen(s->album);
- if(s->genre[0]) totlen += 11 + strlen(s->genre);
- if(s->copyright[0]) totlen += 11 + strlen(s->copyright);
- if(s->track) totlen += 11 + strlen(tracktxt);
- if(s->year) totlen += 11 + strlen(yeartxt);
+
+ title = av_metadata_get(s->metadata, "title", NULL, 0);
+ author = av_metadata_get(s->metadata, "author", NULL, 0);
+ album = av_metadata_get(s->metadata, "album", NULL, 0);
+ genre = av_metadata_get(s->metadata, "genre", NULL, 0);
+ copyright = av_metadata_get(s->metadata, "copyright", NULL, 0);
+ track = av_metadata_get(s->metadata, "track", NULL, 0);
+ year = av_metadata_get(s->metadata, "year", NULL, 0);
+
+ if(title) totlen += 11 + strlen(title->value);
+ if(author) totlen += 11 + strlen(author->value);
+ if(album) totlen += 11 + strlen(album->value);
+ if(genre) totlen += 11 + strlen(genre->value);
+ if(copyright) totlen += 11 + strlen(copyright->value);
+ if(track) totlen += 11 + strlen(track->value);
+ if(year) totlen += 11 + strlen(year->value);
if(!(s->streams[0]->codec->flags & CODEC_FLAG_BITEXACT))
totlen += strlen(LIBAVFORMAT_IDENT) + 11;
id3v2_put_size(s, totlen);
- if(s->title[0]) id3v2_put_ttag(s, s->title, MKBETAG('T', 'I', 'T', '2'));
- if(s->author[0]) id3v2_put_ttag(s, s->author, MKBETAG('T', 'P', 'E', '1'));
- if(s->album[0]) id3v2_put_ttag(s, s->album, MKBETAG('T', 'A', 'L', 'B'));
- if(s->genre[0]) id3v2_put_ttag(s, s->genre, MKBETAG('T', 'C', 'O', 'N'));
- if(s->copyright[0]) id3v2_put_ttag(s, s->copyright, MKBETAG('T', 'C', 'O', 'P'));
- if(s->track) id3v2_put_ttag(s, tracktxt, MKBETAG('T', 'R', 'C', 'K'));
- if(s->year) id3v2_put_ttag(s, yeartxt, MKBETAG('T', 'Y', 'E', 'R'));
+ if(title) id3v2_put_ttag(s, title->value, MKBETAG('T', 'I', 'T', '2'));
+ if(author) id3v2_put_ttag(s, author->value, MKBETAG('T', 'P', 'E', '1'));
+ if(album) id3v2_put_ttag(s, album->value, MKBETAG('T', 'A', 'L', 'B'));
+ if(genre) id3v2_put_ttag(s, genre->value, MKBETAG('T', 'C', 'O', 'N'));
+ if(copyright) id3v2_put_ttag(s, copyright->value, MKBETAG('T', 'C', 'O', 'P'));
+ if(track) id3v2_put_ttag(s, track->value, MKBETAG('T', 'R', 'C', 'K'));
+ if(year) id3v2_put_ttag(s, year->value, MKBETAG('T', 'Y', 'E', 'R'));
if(!(s->streams[0]->codec->flags & CODEC_FLAG_BITEXACT))
id3v2_put_ttag(s, LIBAVFORMAT_IDENT, MKBETAG('T', 'E', 'N', 'C'));
return 0;
uint8_t buf[ID3v1_TAG_SIZE];
/* write the id3v1 tag */
- if (s->title[0] != '\0') {
- id3v1_create_tag(s, buf);
+ if (id3v1_create_tag(s, buf) > 0) {
put_buffer(s->pb, buf, ID3v1_TAG_SIZE);
put_flush_packet(s->pb);
}
#if CONFIG_MP3_DEMUXER
AVInputFormat mp3_demuxer = {
"mp3",
- NULL_IF_CONFIG_SMALL("MPEG audio"),
+ NULL_IF_CONFIG_SMALL("MPEG audio layer 2/3"),
0,
mp3_read_probe,
mp3_read_header,