00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "id3v1.h"
00023 #include "libavcodec/avcodec.h"
00024
00025 const char * const ff_id3v1_genre_str[ID3v1_GENRE_MAX + 1] = {
00026 [0] = "Blues",
00027 [1] = "Classic Rock",
00028 [2] = "Country",
00029 [3] = "Dance",
00030 [4] = "Disco",
00031 [5] = "Funk",
00032 [6] = "Grunge",
00033 [7] = "Hip-Hop",
00034 [8] = "Jazz",
00035 [9] = "Metal",
00036 [10] = "New Age",
00037 [11] = "Oldies",
00038 [12] = "Other",
00039 [13] = "Pop",
00040 [14] = "R&B",
00041 [15] = "Rap",
00042 [16] = "Reggae",
00043 [17] = "Rock",
00044 [18] = "Techno",
00045 [19] = "Industrial",
00046 [20] = "Alternative",
00047 [21] = "Ska",
00048 [22] = "Death Metal",
00049 [23] = "Pranks",
00050 [24] = "Soundtrack",
00051 [25] = "Euro-Techno",
00052 [26] = "Ambient",
00053 [27] = "Trip-Hop",
00054 [28] = "Vocal",
00055 [29] = "Jazz+Funk",
00056 [30] = "Fusion",
00057 [31] = "Trance",
00058 [32] = "Classical",
00059 [33] = "Instrumental",
00060 [34] = "Acid",
00061 [35] = "House",
00062 [36] = "Game",
00063 [37] = "Sound Clip",
00064 [38] = "Gospel",
00065 [39] = "Noise",
00066 [40] = "AlternRock",
00067 [41] = "Bass",
00068 [42] = "Soul",
00069 [43] = "Punk",
00070 [44] = "Space",
00071 [45] = "Meditative",
00072 [46] = "Instrumental Pop",
00073 [47] = "Instrumental Rock",
00074 [48] = "Ethnic",
00075 [49] = "Gothic",
00076 [50] = "Darkwave",
00077 [51] = "Techno-Industrial",
00078 [52] = "Electronic",
00079 [53] = "Pop-Folk",
00080 [54] = "Eurodance",
00081 [55] = "Dream",
00082 [56] = "Southern Rock",
00083 [57] = "Comedy",
00084 [58] = "Cult",
00085 [59] = "Gangsta",
00086 [60] = "Top 40",
00087 [61] = "Christian Rap",
00088 [62] = "Pop/Funk",
00089 [63] = "Jungle",
00090 [64] = "Native American",
00091 [65] = "Cabaret",
00092 [66] = "New Wave",
00093 [67] = "Psychadelic",
00094 [68] = "Rave",
00095 [69] = "Showtunes",
00096 [70] = "Trailer",
00097 [71] = "Lo-Fi",
00098 [72] = "Tribal",
00099 [73] = "Acid Punk",
00100 [74] = "Acid Jazz",
00101 [75] = "Polka",
00102 [76] = "Retro",
00103 [77] = "Musical",
00104 [78] = "Rock & Roll",
00105 [79] = "Hard Rock",
00106 [80] = "Folk",
00107 [81] = "Folk-Rock",
00108 [82] = "National Folk",
00109 [83] = "Swing",
00110 [84] = "Fast Fusion",
00111 [85] = "Bebob",
00112 [86] = "Latin",
00113 [87] = "Revival",
00114 [88] = "Celtic",
00115 [89] = "Bluegrass",
00116 [90] = "Avantgarde",
00117 [91] = "Gothic Rock",
00118 [92] = "Progressive Rock",
00119 [93] = "Psychedelic Rock",
00120 [94] = "Symphonic Rock",
00121 [95] = "Slow Rock",
00122 [96] = "Big Band",
00123 [97] = "Chorus",
00124 [98] = "Easy Listening",
00125 [99] = "Acoustic",
00126 [100] = "Humour",
00127 [101] = "Speech",
00128 [102] = "Chanson",
00129 [103] = "Opera",
00130 [104] = "Chamber Music",
00131 [105] = "Sonata",
00132 [106] = "Symphony",
00133 [107] = "Booty Bass",
00134 [108] = "Primus",
00135 [109] = "Porn Groove",
00136 [110] = "Satire",
00137 [111] = "Slow Jam",
00138 [112] = "Club",
00139 [113] = "Tango",
00140 [114] = "Samba",
00141 [115] = "Folklore",
00142 [116] = "Ballad",
00143 [117] = "Power Ballad",
00144 [118] = "Rhythmic Soul",
00145 [119] = "Freestyle",
00146 [120] = "Duet",
00147 [121] = "Punk Rock",
00148 [122] = "Drum Solo",
00149 [123] = "A capella",
00150 [124] = "Euro-House",
00151 [125] = "Dance Hall",
00152 [126] = "Goa",
00153 [127] = "Drum & Bass",
00154 [128] = "Club-House",
00155 [129] = "Hardcore",
00156 [130] = "Terror",
00157 [131] = "Indie",
00158 [132] = "BritPop",
00159 [133] = "Negerpunk",
00160 [134] = "Polsk Punk",
00161 [135] = "Beat",
00162 [136] = "Christian Gangsta",
00163 [137] = "Heavy Metal",
00164 [138] = "Black Metal",
00165 [139] = "Crossover",
00166 [140] = "Contemporary Christian",
00167 [141] = "Christian Rock",
00168 [142] = "Merengue",
00169 [143] = "Salsa",
00170 [144] = "Thrash Metal",
00171 [145] = "Anime",
00172 [146] = "JPop",
00173 [147] = "SynthPop",
00174 };
00175
00176 static void get_string(AVFormatContext *s, const char *key,
00177 const uint8_t *buf, int buf_size)
00178 {
00179 int i, c;
00180 char *q, str[512];
00181
00182 q = str;
00183 for(i = 0; i < buf_size; i++) {
00184 c = buf[i];
00185 if (c == '\0')
00186 break;
00187 if ((q - str) >= sizeof(str) - 1)
00188 break;
00189 *q++ = c;
00190 }
00191 *q = '\0';
00192
00193 if (*str)
00194 av_metadata_set2(&s->metadata, key, str, 0);
00195 }
00196
00202 static int parse_tag(AVFormatContext *s, const uint8_t *buf)
00203 {
00204 char str[5];
00205 int genre;
00206
00207 if (!(buf[0] == 'T' &&
00208 buf[1] == 'A' &&
00209 buf[2] == 'G'))
00210 return -1;
00211 get_string(s, "title", buf + 3, 30);
00212 get_string(s, "artist", buf + 33, 30);
00213 get_string(s, "album", buf + 63, 30);
00214 get_string(s, "date", buf + 93, 4);
00215 get_string(s, "comment", buf + 97, 30);
00216 if (buf[125] == 0 && buf[126] != 0) {
00217 snprintf(str, sizeof(str), "%d", buf[126]);
00218 av_metadata_set2(&s->metadata, "track", str, 0);
00219 }
00220 genre = buf[127];
00221 if (genre <= ID3v1_GENRE_MAX)
00222 av_metadata_set2(&s->metadata, "genre", ff_id3v1_genre_str[genre], 0);
00223 return 0;
00224 }
00225
00226 void ff_id3v1_read(AVFormatContext *s)
00227 {
00228 int ret, filesize;
00229 uint8_t buf[ID3v1_TAG_SIZE];
00230
00231 if (!url_is_streamed(s->pb)) {
00232
00233 filesize = avio_size(s->pb);
00234 if (filesize > 128) {
00235 avio_seek(s->pb, filesize - 128, SEEK_SET);
00236 ret = avio_read(s->pb, buf, ID3v1_TAG_SIZE);
00237 if (ret == ID3v1_TAG_SIZE) {
00238 parse_tag(s, buf);
00239 }
00240 avio_seek(s->pb, 0, SEEK_SET);
00241 }
00242 }
00243 }