3 * Copyright (c) 2003 Fabrice Bellard
5 * This file is part of FFmpeg.
7 * FFmpeg is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * FFmpeg is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with FFmpeg; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23 #include "libavcodec/avcodec.h"
25 const char * const ff_id3v1_genre_str
[ID3v1_GENRE_MAX
+ 1] = {
59 [33] = "Instrumental",
72 [46] = "Instrumental Pop",
73 [47] = "Instrumental Rock",
77 [51] = "Techno-Industrial",
82 [56] = "Southern Rock",
87 [61] = "Christian Rap",
90 [64] = "Native American",
104 [78] = "Rock & Roll",
108 [82] = "National Folk",
110 [84] = "Fast Fusion",
117 [91] = "Gothic Rock",
118 [92] = "Progressive Rock",
119 [93] = "Psychedelic Rock",
120 [94] = "Symphonic Rock",
124 [98] = "Easy Listening",
130 [104] = "Chamber Music",
133 [107] = "Booty Bass",
135 [109] = "Porn Groove",
143 [117] = "Power Ballad",
144 [118] = "Rhythmic Soul",
150 [124] = "Euro-House",
151 [125] = "Dance Hall",
154 static void get_string(AVFormatContext
*s
, const char *key
,
155 const uint8_t *buf
, int buf_size
)
161 for(i
= 0; i
< buf_size
; i
++) {
165 if ((q
- str
) >= sizeof(str
) - 1)
172 av_metadata_set(&s
->metadata
, key
, str
);
178 * @param buf ID3v1_TAG_SIZE long buffer containing the tag
180 static int parse_tag(AVFormatContext
*s
, const uint8_t *buf
)
185 if (!(buf
[0] == 'T' &&
189 get_string(s
, "title", buf
+ 3, 30);
190 get_string(s
, "author", buf
+ 33, 30);
191 get_string(s
, "album", buf
+ 63, 30);
192 get_string(s
, "year", buf
+ 93, 4);
193 get_string(s
, "comment", buf
+ 97, 30);
194 if (buf
[125] == 0 && buf
[126] != 0) {
195 snprintf(str
, sizeof(str
), "%d", buf
[126]);
196 av_metadata_set(&s
->metadata
, "track", str
);
199 if (genre
<= ID3v1_GENRE_MAX
)
200 av_metadata_set(&s
->metadata
, "genre", ff_id3v1_genre_str
[genre
]);
204 void ff_id3v1_read(AVFormatContext
*s
)
207 uint8_t buf
[ID3v1_TAG_SIZE
];
209 if (!url_is_streamed(s
->pb
)) {
210 /* XXX: change that */
211 filesize
= url_fsize(s
->pb
);
212 if (filesize
> 128) {
213 url_fseek(s
->pb
, filesize
- 128, SEEK_SET
);
214 ret
= get_buffer(s
->pb
, buf
, ID3v1_TAG_SIZE
);
215 if (ret
== ID3v1_TAG_SIZE
) {
218 url_fseek(s
->pb
, 0, SEEK_SET
);