Replace 5 with AOT_SBR when referring to the MPEG-4 audio object type.
[FFMpeg-mirror/lagarith.git] / libavformat / id3v1.c
blob7281974182231de2f6e40d8a6009d930d63b557f
1 /*
2 * ID3v1 header parser
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
22 #include "id3v1.h"
23 #include "libavcodec/avcodec.h"
25 const char *ff_id3v1_genre_str[ID3v1_GENRE_MAX + 1] = {
26 [0] = "Blues",
27 [1] = "Classic Rock",
28 [2] = "Country",
29 [3] = "Dance",
30 [4] = "Disco",
31 [5] = "Funk",
32 [6] = "Grunge",
33 [7] = "Hip-Hop",
34 [8] = "Jazz",
35 [9] = "Metal",
36 [10] = "New Age",
37 [11] = "Oldies",
38 [12] = "Other",
39 [13] = "Pop",
40 [14] = "R&B",
41 [15] = "Rap",
42 [16] = "Reggae",
43 [17] = "Rock",
44 [18] = "Techno",
45 [19] = "Industrial",
46 [20] = "Alternative",
47 [21] = "Ska",
48 [22] = "Death Metal",
49 [23] = "Pranks",
50 [24] = "Soundtrack",
51 [25] = "Euro-Techno",
52 [26] = "Ambient",
53 [27] = "Trip-Hop",
54 [28] = "Vocal",
55 [29] = "Jazz+Funk",
56 [30] = "Fusion",
57 [31] = "Trance",
58 [32] = "Classical",
59 [33] = "Instrumental",
60 [34] = "Acid",
61 [35] = "House",
62 [36] = "Game",
63 [37] = "Sound Clip",
64 [38] = "Gospel",
65 [39] = "Noise",
66 [40] = "AlternRock",
67 [41] = "Bass",
68 [42] = "Soul",
69 [43] = "Punk",
70 [44] = "Space",
71 [45] = "Meditative",
72 [46] = "Instrumental Pop",
73 [47] = "Instrumental Rock",
74 [48] = "Ethnic",
75 [49] = "Gothic",
76 [50] = "Darkwave",
77 [51] = "Techno-Industrial",
78 [52] = "Electronic",
79 [53] = "Pop-Folk",
80 [54] = "Eurodance",
81 [55] = "Dream",
82 [56] = "Southern Rock",
83 [57] = "Comedy",
84 [58] = "Cult",
85 [59] = "Gangsta",
86 [60] = "Top 40",
87 [61] = "Christian Rap",
88 [62] = "Pop/Funk",
89 [63] = "Jungle",
90 [64] = "Native American",
91 [65] = "Cabaret",
92 [66] = "New Wave",
93 [67] = "Psychadelic",
94 [68] = "Rave",
95 [69] = "Showtunes",
96 [70] = "Trailer",
97 [71] = "Lo-Fi",
98 [72] = "Tribal",
99 [73] = "Acid Punk",
100 [74] = "Acid Jazz",
101 [75] = "Polka",
102 [76] = "Retro",
103 [77] = "Musical",
104 [78] = "Rock & Roll",
105 [79] = "Hard Rock",
106 [80] = "Folk",
107 [81] = "Folk-Rock",
108 [82] = "National Folk",
109 [83] = "Swing",
110 [84] = "Fast Fusion",
111 [85] = "Bebob",
112 [86] = "Latin",
113 [87] = "Revival",
114 [88] = "Celtic",
115 [89] = "Bluegrass",
116 [90] = "Avantgarde",
117 [91] = "Gothic Rock",
118 [92] = "Progressive Rock",
119 [93] = "Psychedelic Rock",
120 [94] = "Symphonic Rock",
121 [95] = "Slow Rock",
122 [96] = "Big Band",
123 [97] = "Chorus",
124 [98] = "Easy Listening",
125 [99] = "Acoustic",
126 [100] = "Humour",
127 [101] = "Speech",
128 [102] = "Chanson",
129 [103] = "Opera",
130 [104] = "Chamber Music",
131 [105] = "Sonata",
132 [106] = "Symphony",
133 [107] = "Booty Bass",
134 [108] = "Primus",
135 [109] = "Porn Groove",
136 [110] = "Satire",
137 [111] = "Slow Jam",
138 [112] = "Club",
139 [113] = "Tango",
140 [114] = "Samba",
141 [115] = "Folklore",
142 [116] = "Ballad",
143 [117] = "Power Ballad",
144 [118] = "Rhythmic Soul",
145 [119] = "Freestyle",
146 [120] = "Duet",
147 [121] = "Punk Rock",
148 [122] = "Drum Solo",
149 [123] = "A capella",
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)
157 int i, c;
158 char *q, str[512];
160 q = str;
161 for(i = 0; i < buf_size; i++) {
162 c = buf[i];
163 if (c == '\0')
164 break;
165 if ((q - str) >= sizeof(str) - 1)
166 break;
167 *q++ = c;
169 *q = '\0';
171 if (*str)
172 av_metadata_set(&s->metadata, key, str);
176 * Parse an ID3v1 tag
178 * @param buf ID3v1_TAG_SIZE long buffer containing the tag
180 static int parse_tag(AVFormatContext *s, const uint8_t *buf)
182 char str[5];
183 int genre;
185 if (!(buf[0] == 'T' &&
186 buf[1] == 'A' &&
187 buf[2] == 'G'))
188 return -1;
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);
198 genre = buf[127];
199 if (genre <= ID3v1_GENRE_MAX)
200 av_metadata_set(&s->metadata, "genre", ff_id3v1_genre_str[genre]);
201 return 0;
204 void ff_id3v1_read(AVFormatContext *s)
206 int ret, filesize;
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) {
216 parse_tag(s, buf);
218 url_fseek(s->pb, 0, SEEK_SET);