annotate id3v1.c @ 5397:6016c9643d95 libavformat

slif aka "SoftLab MPEG-2 I-frames Codec" support. Flipping one bit still is popular it seems as a means to create a new codec. fixes issue1469.
author michael
date Tue, 01 Dec 2009 02:07:46 +0000
parents eb33b7205b3c
children 1c7cdbafd33c
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 858
diff changeset
1 /*
5016
eb6dd7717805 Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents: 4900
diff changeset
2 * ID3v1 header parser
4251
77e0c7511d41 cosmetics: Remove pointless period after copyright statement non-sentences.
diego
parents: 4221
diff changeset
3 * Copyright (c) 2003 Fabrice Bellard
234
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
4 *
1358
0899bfe4105c Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 1321
diff changeset
5 * This file is part of FFmpeg.
0899bfe4105c Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 1321
diff changeset
6 *
0899bfe4105c Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 1321
diff changeset
7 * FFmpeg is free software; you can redistribute it and/or
234
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
8 * modify it under the terms of the GNU Lesser General Public
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
9 * License as published by the Free Software Foundation; either
1358
0899bfe4105c Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 1321
diff changeset
10 * version 2.1 of the License, or (at your option) any later version.
234
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
11 *
1358
0899bfe4105c Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 1321
diff changeset
12 * FFmpeg is distributed in the hope that it will be useful,
234
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
15 * Lesser General Public License for more details.
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
16 *
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
17 * You should have received a copy of the GNU Lesser General Public
1358
0899bfe4105c Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 1321
diff changeset
18 * License along with FFmpeg; if not, write to the Free Software
896
edbe5c3717f9 Update licensing information: The FSF changed postal address.
diego
parents: 885
diff changeset
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
234
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
20 */
3286
6f61c3b36632 Use full path for #includes from another directory.
diego
parents: 3278
diff changeset
21
5016
eb6dd7717805 Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents: 4900
diff changeset
22 #include "id3v1.h"
5045
9ed3c88ed9ba Move id3v1/id3v2 handling code from mp3.c to id3v[12].c.
diego
parents: 5017
diff changeset
23 #include "libavcodec/avcodec.h"
234
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
24
5160
eb33b7205b3c ff_id3v1_genre_str table should be const.
reimar
parents: 5045
diff changeset
25 const char * const ff_id3v1_genre_str[ID3v1_GENRE_MAX + 1] = {
5017
1763f7d0d8d0 cosmetics: Reformat to K&R and prettyprint newly created files.
diego
parents: 5016
diff changeset
26 [0] = "Blues",
1763f7d0d8d0 cosmetics: Reformat to K&R and prettyprint newly created files.
diego
parents: 5016
diff changeset
27 [1] = "Classic Rock",
1763f7d0d8d0 cosmetics: Reformat to K&R and prettyprint newly created files.
diego
parents: 5016
diff changeset
28 [2] = "Country",
1763f7d0d8d0 cosmetics: Reformat to K&R and prettyprint newly created files.
diego
parents: 5016
diff changeset
29 [3] = "Dance",
1763f7d0d8d0 cosmetics: Reformat to K&R and prettyprint newly created files.
diego
parents: 5016
diff changeset
30 [4] = "Disco",
1763f7d0d8d0 cosmetics: Reformat to K&R and prettyprint newly created files.
diego
parents: 5016
diff changeset
31 [5] = "Funk",
1763f7d0d8d0 cosmetics: Reformat to K&R and prettyprint newly created files.
diego
parents: 5016
diff changeset
32 [6] = "Grunge",
1763f7d0d8d0 cosmetics: Reformat to K&R and prettyprint newly created files.
diego
parents: 5016
diff changeset
33 [7] = "Hip-Hop",
1763f7d0d8d0 cosmetics: Reformat to K&R and prettyprint newly created files.
diego
parents: 5016
diff changeset
34 [8] = "Jazz",
1763f7d0d8d0 cosmetics: Reformat to K&R and prettyprint newly created files.
diego
parents: 5016
diff changeset
35 [9] = "Metal",
1763f7d0d8d0 cosmetics: Reformat to K&R and prettyprint newly created files.
diego
parents: 5016
diff changeset
36 [10] = "New Age",
1763f7d0d8d0 cosmetics: Reformat to K&R and prettyprint newly created files.
diego
parents: 5016
diff changeset
37 [11] = "Oldies",
1763f7d0d8d0 cosmetics: Reformat to K&R and prettyprint newly created files.
diego
parents: 5016
diff changeset
38 [12] = "Other",
1763f7d0d8d0 cosmetics: Reformat to K&R and prettyprint newly created files.
diego
parents: 5016
diff changeset
39 [13] = "Pop",
1763f7d0d8d0 cosmetics: Reformat to K&R and prettyprint newly created files.
diego
parents: 5016
diff changeset
40 [14] = "R&B",
1763f7d0d8d0 cosmetics: Reformat to K&R and prettyprint newly created files.
diego
parents: 5016
diff changeset
41 [15] = "Rap",
1763f7d0d8d0 cosmetics: Reformat to K&R and prettyprint newly created files.
diego
parents: 5016
diff changeset
42 [16] = "Reggae",
1763f7d0d8d0 cosmetics: Reformat to K&R and prettyprint newly created files.
diego
parents: 5016
diff changeset
43 [17] = "Rock",
1763f7d0d8d0 cosmetics: Reformat to K&R and prettyprint newly created files.
diego
parents: 5016
diff changeset
44 [18] = "Techno",
1763f7d0d8d0 cosmetics: Reformat to K&R and prettyprint newly created files.
diego
parents: 5016
diff changeset
45 [19] = "Industrial",
1763f7d0d8d0 cosmetics: Reformat to K&R and prettyprint newly created files.
diego
parents: 5016
diff changeset
46 [20] = "Alternative",
1763f7d0d8d0 cosmetics: Reformat to K&R and prettyprint newly created files.
diego
parents: 5016
diff changeset
47 [21] = "Ska",
1763f7d0d8d0 cosmetics: Reformat to K&R and prettyprint newly created files.
diego
parents: 5016
diff changeset
48 [22] = "Death Metal",
1763f7d0d8d0 cosmetics: Reformat to K&R and prettyprint newly created files.
diego
parents: 5016
diff changeset
49 [23] = "Pranks",
1763f7d0d8d0 cosmetics: Reformat to K&R and prettyprint newly created files.
diego
parents: 5016
diff changeset
50 [24] = "Soundtrack",
1763f7d0d8d0 cosmetics: Reformat to K&R and prettyprint newly created files.
diego
parents: 5016
diff changeset
51 [25] = "Euro-Techno",
1763f7d0d8d0 cosmetics: Reformat to K&R and prettyprint newly created files.
diego
parents: 5016
diff changeset
52 [26] = "Ambient",
1763f7d0d8d0 cosmetics: Reformat to K&R and prettyprint newly created files.
diego
parents: 5016
diff changeset
53 [27] = "Trip-Hop",
1763f7d0d8d0 cosmetics: Reformat to K&R and prettyprint newly created files.
diego
parents: 5016
diff changeset
54 [28] = "Vocal",
1763f7d0d8d0 cosmetics: Reformat to K&R and prettyprint newly created files.
diego
parents: 5016
diff changeset
55 [29] = "Jazz+Funk",
1763f7d0d8d0 cosmetics: Reformat to K&R and prettyprint newly created files.
diego
parents: 5016
diff changeset
56 [30] = "Fusion",
1763f7d0d8d0 cosmetics: Reformat to K&R and prettyprint newly created files.
diego
parents: 5016
diff changeset
57 [31] = "Trance",
1763f7d0d8d0 cosmetics: Reformat to K&R and prettyprint newly created files.
diego
parents: 5016
diff changeset
58 [32] = "Classical",
1763f7d0d8d0 cosmetics: Reformat to K&R and prettyprint newly created files.
diego
parents: 5016
diff changeset
59 [33] = "Instrumental",
1763f7d0d8d0 cosmetics: Reformat to K&R and prettyprint newly created files.
diego
parents: 5016
diff changeset
60 [34] = "Acid",
1763f7d0d8d0 cosmetics: Reformat to K&R and prettyprint newly created files.
diego
parents: 5016
diff changeset
61 [35] = "House",
1763f7d0d8d0 cosmetics: Reformat to K&R and prettyprint newly created files.
diego
parents: 5016
diff changeset
62 [36] = "Game",
1763f7d0d8d0 cosmetics: Reformat to K&R and prettyprint newly created files.
diego
parents: 5016
diff changeset
63 [37] = "Sound Clip",
1763f7d0d8d0 cosmetics: Reformat to K&R and prettyprint newly created files.
diego
parents: 5016
diff changeset
64 [38] = "Gospel",
1763f7d0d8d0 cosmetics: Reformat to K&R and prettyprint newly created files.
diego
parents: 5016
diff changeset
65 [39] = "Noise",
1763f7d0d8d0 cosmetics: Reformat to K&R and prettyprint newly created files.
diego
parents: 5016
diff changeset
66 [40] = "AlternRock",
1763f7d0d8d0 cosmetics: Reformat to K&R and prettyprint newly created files.
diego
parents: 5016
diff changeset
67 [41] = "Bass",
1763f7d0d8d0 cosmetics: Reformat to K&R and prettyprint newly created files.
diego
parents: 5016
diff changeset
68 [42] = "Soul",
1763f7d0d8d0 cosmetics: Reformat to K&R and prettyprint newly created files.
diego
parents: 5016
diff changeset
69 [43] = "Punk",
1763f7d0d8d0 cosmetics: Reformat to K&R and prettyprint newly created files.
diego
parents: 5016
diff changeset
70 [44] = "Space",
1763f7d0d8d0 cosmetics: Reformat to K&R and prettyprint newly created files.
diego
parents: 5016
diff changeset
71 [45] = "Meditative",
1763f7d0d8d0 cosmetics: Reformat to K&R and prettyprint newly created files.
diego
parents: 5016
diff changeset
72 [46] = "Instrumental Pop",
1763f7d0d8d0 cosmetics: Reformat to K&R and prettyprint newly created files.
diego
parents: 5016
diff changeset
73 [47] = "Instrumental Rock",
1763f7d0d8d0 cosmetics: Reformat to K&R and prettyprint newly created files.
diego
parents: 5016
diff changeset
74 [48] = "Ethnic",
1763f7d0d8d0 cosmetics: Reformat to K&R and prettyprint newly created files.
diego
parents: 5016
diff changeset
75 [49] = "Gothic",
1763f7d0d8d0 cosmetics: Reformat to K&R and prettyprint newly created files.
diego
parents: 5016
diff changeset
76 [50] = "Darkwave",
1763f7d0d8d0 cosmetics: Reformat to K&R and prettyprint newly created files.
diego
parents: 5016
diff changeset
77 [51] = "Techno-Industrial",
1763f7d0d8d0 cosmetics: Reformat to K&R and prettyprint newly created files.
diego
parents: 5016
diff changeset
78 [52] = "Electronic",
1763f7d0d8d0 cosmetics: Reformat to K&R and prettyprint newly created files.
diego
parents: 5016
diff changeset
79 [53] = "Pop-Folk",
1763f7d0d8d0 cosmetics: Reformat to K&R and prettyprint newly created files.
diego
parents: 5016
diff changeset
80 [54] = "Eurodance",
1763f7d0d8d0 cosmetics: Reformat to K&R and prettyprint newly created files.
diego
parents: 5016
diff changeset
81 [55] = "Dream",
1763f7d0d8d0 cosmetics: Reformat to K&R and prettyprint newly created files.
diego
parents: 5016
diff changeset
82 [56] = "Southern Rock",
1763f7d0d8d0 cosmetics: Reformat to K&R and prettyprint newly created files.
diego
parents: 5016
diff changeset
83 [57] = "Comedy",
1763f7d0d8d0 cosmetics: Reformat to K&R and prettyprint newly created files.
diego
parents: 5016
diff changeset
84 [58] = "Cult",
1763f7d0d8d0 cosmetics: Reformat to K&R and prettyprint newly created files.
diego
parents: 5016
diff changeset
85 [59] = "Gangsta",
1763f7d0d8d0 cosmetics: Reformat to K&R and prettyprint newly created files.
diego
parents: 5016
diff changeset
86 [60] = "Top 40",
1763f7d0d8d0 cosmetics: Reformat to K&R and prettyprint newly created files.
diego
parents: 5016
diff changeset
87 [61] = "Christian Rap",
1763f7d0d8d0 cosmetics: Reformat to K&R and prettyprint newly created files.
diego
parents: 5016
diff changeset
88 [62] = "Pop/Funk",
1763f7d0d8d0 cosmetics: Reformat to K&R and prettyprint newly created files.
diego
parents: 5016
diff changeset
89 [63] = "Jungle",
1763f7d0d8d0 cosmetics: Reformat to K&R and prettyprint newly created files.
diego
parents: 5016
diff changeset
90 [64] = "Native American",
1763f7d0d8d0 cosmetics: Reformat to K&R and prettyprint newly created files.
diego
parents: 5016
diff changeset
91 [65] = "Cabaret",
1763f7d0d8d0 cosmetics: Reformat to K&R and prettyprint newly created files.
diego
parents: 5016
diff changeset
92 [66] = "New Wave",
1763f7d0d8d0 cosmetics: Reformat to K&R and prettyprint newly created files.
diego
parents: 5016
diff changeset
93 [67] = "Psychadelic",
1763f7d0d8d0 cosmetics: Reformat to K&R and prettyprint newly created files.
diego
parents: 5016
diff changeset
94 [68] = "Rave",
1763f7d0d8d0 cosmetics: Reformat to K&R and prettyprint newly created files.
diego
parents: 5016
diff changeset
95 [69] = "Showtunes",
1763f7d0d8d0 cosmetics: Reformat to K&R and prettyprint newly created files.
diego
parents: 5016
diff changeset
96 [70] = "Trailer",
1763f7d0d8d0 cosmetics: Reformat to K&R and prettyprint newly created files.
diego
parents: 5016
diff changeset
97 [71] = "Lo-Fi",
1763f7d0d8d0 cosmetics: Reformat to K&R and prettyprint newly created files.
diego
parents: 5016
diff changeset
98 [72] = "Tribal",
1763f7d0d8d0 cosmetics: Reformat to K&R and prettyprint newly created files.
diego
parents: 5016
diff changeset
99 [73] = "Acid Punk",
1763f7d0d8d0 cosmetics: Reformat to K&R and prettyprint newly created files.
diego
parents: 5016
diff changeset
100 [74] = "Acid Jazz",
1763f7d0d8d0 cosmetics: Reformat to K&R and prettyprint newly created files.
diego
parents: 5016
diff changeset
101 [75] = "Polka",
1763f7d0d8d0 cosmetics: Reformat to K&R and prettyprint newly created files.
diego
parents: 5016
diff changeset
102 [76] = "Retro",
1763f7d0d8d0 cosmetics: Reformat to K&R and prettyprint newly created files.
diego
parents: 5016
diff changeset
103 [77] = "Musical",
1763f7d0d8d0 cosmetics: Reformat to K&R and prettyprint newly created files.
diego
parents: 5016
diff changeset
104 [78] = "Rock & Roll",
1763f7d0d8d0 cosmetics: Reformat to K&R and prettyprint newly created files.
diego
parents: 5016
diff changeset
105 [79] = "Hard Rock",
1763f7d0d8d0 cosmetics: Reformat to K&R and prettyprint newly created files.
diego
parents: 5016
diff changeset
106 [80] = "Folk",
1763f7d0d8d0 cosmetics: Reformat to K&R and prettyprint newly created files.
diego
parents: 5016
diff changeset
107 [81] = "Folk-Rock",
1763f7d0d8d0 cosmetics: Reformat to K&R and prettyprint newly created files.
diego
parents: 5016
diff changeset
108 [82] = "National Folk",
1763f7d0d8d0 cosmetics: Reformat to K&R and prettyprint newly created files.
diego
parents: 5016
diff changeset
109 [83] = "Swing",
1763f7d0d8d0 cosmetics: Reformat to K&R and prettyprint newly created files.
diego
parents: 5016
diff changeset
110 [84] = "Fast Fusion",
1763f7d0d8d0 cosmetics: Reformat to K&R and prettyprint newly created files.
diego
parents: 5016
diff changeset
111 [85] = "Bebob",
1763f7d0d8d0 cosmetics: Reformat to K&R and prettyprint newly created files.
diego
parents: 5016
diff changeset
112 [86] = "Latin",
1763f7d0d8d0 cosmetics: Reformat to K&R and prettyprint newly created files.
diego
parents: 5016
diff changeset
113 [87] = "Revival",
1763f7d0d8d0 cosmetics: Reformat to K&R and prettyprint newly created files.
diego
parents: 5016
diff changeset
114 [88] = "Celtic",
1763f7d0d8d0 cosmetics: Reformat to K&R and prettyprint newly created files.
diego
parents: 5016
diff changeset
115 [89] = "Bluegrass",
1763f7d0d8d0 cosmetics: Reformat to K&R and prettyprint newly created files.
diego
parents: 5016
diff changeset
116 [90] = "Avantgarde",
1763f7d0d8d0 cosmetics: Reformat to K&R and prettyprint newly created files.
diego
parents: 5016
diff changeset
117 [91] = "Gothic Rock",
1763f7d0d8d0 cosmetics: Reformat to K&R and prettyprint newly created files.
diego
parents: 5016
diff changeset
118 [92] = "Progressive Rock",
1763f7d0d8d0 cosmetics: Reformat to K&R and prettyprint newly created files.
diego
parents: 5016
diff changeset
119 [93] = "Psychedelic Rock",
1763f7d0d8d0 cosmetics: Reformat to K&R and prettyprint newly created files.
diego
parents: 5016
diff changeset
120 [94] = "Symphonic Rock",
1763f7d0d8d0 cosmetics: Reformat to K&R and prettyprint newly created files.
diego
parents: 5016
diff changeset
121 [95] = "Slow Rock",
1763f7d0d8d0 cosmetics: Reformat to K&R and prettyprint newly created files.
diego
parents: 5016
diff changeset
122 [96] = "Big Band",
1763f7d0d8d0 cosmetics: Reformat to K&R and prettyprint newly created files.
diego
parents: 5016
diff changeset
123 [97] = "Chorus",
1763f7d0d8d0 cosmetics: Reformat to K&R and prettyprint newly created files.
diego
parents: 5016
diff changeset
124 [98] = "Easy Listening",
1763f7d0d8d0 cosmetics: Reformat to K&R and prettyprint newly created files.
diego
parents: 5016
diff changeset
125 [99] = "Acoustic",
234
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
126 [100] = "Humour",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
127 [101] = "Speech",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
128 [102] = "Chanson",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
129 [103] = "Opera",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
130 [104] = "Chamber Music",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
131 [105] = "Sonata",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
132 [106] = "Symphony",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
133 [107] = "Booty Bass",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
134 [108] = "Primus",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
135 [109] = "Porn Groove",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
136 [110] = "Satire",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
137 [111] = "Slow Jam",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
138 [112] = "Club",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
139 [113] = "Tango",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
140 [114] = "Samba",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
141 [115] = "Folklore",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
142 [116] = "Ballad",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
143 [117] = "Power Ballad",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
144 [118] = "Rhythmic Soul",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
145 [119] = "Freestyle",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
146 [120] = "Duet",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
147 [121] = "Punk Rock",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
148 [122] = "Drum Solo",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
149 [123] = "A capella",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
150 [124] = "Euro-House",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
151 [125] = "Dance Hall",
b99548e3ab84 ID3 parsing and generation in MP3 format
bellard
parents:
diff changeset
152 };
5045
9ed3c88ed9ba Move id3v1/id3v2 handling code from mp3.c to id3v[12].c.
diego
parents: 5017
diff changeset
153
9ed3c88ed9ba Move id3v1/id3v2 handling code from mp3.c to id3v[12].c.
diego
parents: 5017
diff changeset
154 static void get_string(AVFormatContext *s, const char *key,
9ed3c88ed9ba Move id3v1/id3v2 handling code from mp3.c to id3v[12].c.
diego
parents: 5017
diff changeset
155 const uint8_t *buf, int buf_size)
9ed3c88ed9ba Move id3v1/id3v2 handling code from mp3.c to id3v[12].c.
diego
parents: 5017
diff changeset
156 {
9ed3c88ed9ba Move id3v1/id3v2 handling code from mp3.c to id3v[12].c.
diego
parents: 5017
diff changeset
157 int i, c;
9ed3c88ed9ba Move id3v1/id3v2 handling code from mp3.c to id3v[12].c.
diego
parents: 5017
diff changeset
158 char *q, str[512];
9ed3c88ed9ba Move id3v1/id3v2 handling code from mp3.c to id3v[12].c.
diego
parents: 5017
diff changeset
159
9ed3c88ed9ba Move id3v1/id3v2 handling code from mp3.c to id3v[12].c.
diego
parents: 5017
diff changeset
160 q = str;
9ed3c88ed9ba Move id3v1/id3v2 handling code from mp3.c to id3v[12].c.
diego
parents: 5017
diff changeset
161 for(i = 0; i < buf_size; i++) {
9ed3c88ed9ba Move id3v1/id3v2 handling code from mp3.c to id3v[12].c.
diego
parents: 5017
diff changeset
162 c = buf[i];
9ed3c88ed9ba Move id3v1/id3v2 handling code from mp3.c to id3v[12].c.
diego
parents: 5017
diff changeset
163 if (c == '\0')
9ed3c88ed9ba Move id3v1/id3v2 handling code from mp3.c to id3v[12].c.
diego
parents: 5017
diff changeset
164 break;
9ed3c88ed9ba Move id3v1/id3v2 handling code from mp3.c to id3v[12].c.
diego
parents: 5017
diff changeset
165 if ((q - str) >= sizeof(str) - 1)
9ed3c88ed9ba Move id3v1/id3v2 handling code from mp3.c to id3v[12].c.
diego
parents: 5017
diff changeset
166 break;
9ed3c88ed9ba Move id3v1/id3v2 handling code from mp3.c to id3v[12].c.
diego
parents: 5017
diff changeset
167 *q++ = c;
9ed3c88ed9ba Move id3v1/id3v2 handling code from mp3.c to id3v[12].c.
diego
parents: 5017
diff changeset
168 }
9ed3c88ed9ba Move id3v1/id3v2 handling code from mp3.c to id3v[12].c.
diego
parents: 5017
diff changeset
169 *q = '\0';
9ed3c88ed9ba Move id3v1/id3v2 handling code from mp3.c to id3v[12].c.
diego
parents: 5017
diff changeset
170
9ed3c88ed9ba Move id3v1/id3v2 handling code from mp3.c to id3v[12].c.
diego
parents: 5017
diff changeset
171 if (*str)
9ed3c88ed9ba Move id3v1/id3v2 handling code from mp3.c to id3v[12].c.
diego
parents: 5017
diff changeset
172 av_metadata_set(&s->metadata, key, str);
9ed3c88ed9ba Move id3v1/id3v2 handling code from mp3.c to id3v[12].c.
diego
parents: 5017
diff changeset
173 }
9ed3c88ed9ba Move id3v1/id3v2 handling code from mp3.c to id3v[12].c.
diego
parents: 5017
diff changeset
174
9ed3c88ed9ba Move id3v1/id3v2 handling code from mp3.c to id3v[12].c.
diego
parents: 5017
diff changeset
175 /**
9ed3c88ed9ba Move id3v1/id3v2 handling code from mp3.c to id3v[12].c.
diego
parents: 5017
diff changeset
176 * Parse an ID3v1 tag
9ed3c88ed9ba Move id3v1/id3v2 handling code from mp3.c to id3v[12].c.
diego
parents: 5017
diff changeset
177 *
9ed3c88ed9ba Move id3v1/id3v2 handling code from mp3.c to id3v[12].c.
diego
parents: 5017
diff changeset
178 * @param buf ID3v1_TAG_SIZE long buffer containing the tag
9ed3c88ed9ba Move id3v1/id3v2 handling code from mp3.c to id3v[12].c.
diego
parents: 5017
diff changeset
179 */
9ed3c88ed9ba Move id3v1/id3v2 handling code from mp3.c to id3v[12].c.
diego
parents: 5017
diff changeset
180 static int parse_tag(AVFormatContext *s, const uint8_t *buf)
9ed3c88ed9ba Move id3v1/id3v2 handling code from mp3.c to id3v[12].c.
diego
parents: 5017
diff changeset
181 {
9ed3c88ed9ba Move id3v1/id3v2 handling code from mp3.c to id3v[12].c.
diego
parents: 5017
diff changeset
182 char str[5];
9ed3c88ed9ba Move id3v1/id3v2 handling code from mp3.c to id3v[12].c.
diego
parents: 5017
diff changeset
183 int genre;
9ed3c88ed9ba Move id3v1/id3v2 handling code from mp3.c to id3v[12].c.
diego
parents: 5017
diff changeset
184
9ed3c88ed9ba Move id3v1/id3v2 handling code from mp3.c to id3v[12].c.
diego
parents: 5017
diff changeset
185 if (!(buf[0] == 'T' &&
9ed3c88ed9ba Move id3v1/id3v2 handling code from mp3.c to id3v[12].c.
diego
parents: 5017
diff changeset
186 buf[1] == 'A' &&
9ed3c88ed9ba Move id3v1/id3v2 handling code from mp3.c to id3v[12].c.
diego
parents: 5017
diff changeset
187 buf[2] == 'G'))
9ed3c88ed9ba Move id3v1/id3v2 handling code from mp3.c to id3v[12].c.
diego
parents: 5017
diff changeset
188 return -1;
9ed3c88ed9ba Move id3v1/id3v2 handling code from mp3.c to id3v[12].c.
diego
parents: 5017
diff changeset
189 get_string(s, "title", buf + 3, 30);
9ed3c88ed9ba Move id3v1/id3v2 handling code from mp3.c to id3v[12].c.
diego
parents: 5017
diff changeset
190 get_string(s, "author", buf + 33, 30);
9ed3c88ed9ba Move id3v1/id3v2 handling code from mp3.c to id3v[12].c.
diego
parents: 5017
diff changeset
191 get_string(s, "album", buf + 63, 30);
9ed3c88ed9ba Move id3v1/id3v2 handling code from mp3.c to id3v[12].c.
diego
parents: 5017
diff changeset
192 get_string(s, "year", buf + 93, 4);
9ed3c88ed9ba Move id3v1/id3v2 handling code from mp3.c to id3v[12].c.
diego
parents: 5017
diff changeset
193 get_string(s, "comment", buf + 97, 30);
9ed3c88ed9ba Move id3v1/id3v2 handling code from mp3.c to id3v[12].c.
diego
parents: 5017
diff changeset
194 if (buf[125] == 0 && buf[126] != 0) {
9ed3c88ed9ba Move id3v1/id3v2 handling code from mp3.c to id3v[12].c.
diego
parents: 5017
diff changeset
195 snprintf(str, sizeof(str), "%d", buf[126]);
9ed3c88ed9ba Move id3v1/id3v2 handling code from mp3.c to id3v[12].c.
diego
parents: 5017
diff changeset
196 av_metadata_set(&s->metadata, "track", str);
9ed3c88ed9ba Move id3v1/id3v2 handling code from mp3.c to id3v[12].c.
diego
parents: 5017
diff changeset
197 }
9ed3c88ed9ba Move id3v1/id3v2 handling code from mp3.c to id3v[12].c.
diego
parents: 5017
diff changeset
198 genre = buf[127];
9ed3c88ed9ba Move id3v1/id3v2 handling code from mp3.c to id3v[12].c.
diego
parents: 5017
diff changeset
199 if (genre <= ID3v1_GENRE_MAX)
9ed3c88ed9ba Move id3v1/id3v2 handling code from mp3.c to id3v[12].c.
diego
parents: 5017
diff changeset
200 av_metadata_set(&s->metadata, "genre", ff_id3v1_genre_str[genre]);
9ed3c88ed9ba Move id3v1/id3v2 handling code from mp3.c to id3v[12].c.
diego
parents: 5017
diff changeset
201 return 0;
9ed3c88ed9ba Move id3v1/id3v2 handling code from mp3.c to id3v[12].c.
diego
parents: 5017
diff changeset
202 }
9ed3c88ed9ba Move id3v1/id3v2 handling code from mp3.c to id3v[12].c.
diego
parents: 5017
diff changeset
203
9ed3c88ed9ba Move id3v1/id3v2 handling code from mp3.c to id3v[12].c.
diego
parents: 5017
diff changeset
204 void ff_id3v1_read(AVFormatContext *s)
9ed3c88ed9ba Move id3v1/id3v2 handling code from mp3.c to id3v[12].c.
diego
parents: 5017
diff changeset
205 {
9ed3c88ed9ba Move id3v1/id3v2 handling code from mp3.c to id3v[12].c.
diego
parents: 5017
diff changeset
206 int ret, filesize;
9ed3c88ed9ba Move id3v1/id3v2 handling code from mp3.c to id3v[12].c.
diego
parents: 5017
diff changeset
207 uint8_t buf[ID3v1_TAG_SIZE];
9ed3c88ed9ba Move id3v1/id3v2 handling code from mp3.c to id3v[12].c.
diego
parents: 5017
diff changeset
208
9ed3c88ed9ba Move id3v1/id3v2 handling code from mp3.c to id3v[12].c.
diego
parents: 5017
diff changeset
209 if (!url_is_streamed(s->pb)) {
9ed3c88ed9ba Move id3v1/id3v2 handling code from mp3.c to id3v[12].c.
diego
parents: 5017
diff changeset
210 /* XXX: change that */
9ed3c88ed9ba Move id3v1/id3v2 handling code from mp3.c to id3v[12].c.
diego
parents: 5017
diff changeset
211 filesize = url_fsize(s->pb);
9ed3c88ed9ba Move id3v1/id3v2 handling code from mp3.c to id3v[12].c.
diego
parents: 5017
diff changeset
212 if (filesize > 128) {
9ed3c88ed9ba Move id3v1/id3v2 handling code from mp3.c to id3v[12].c.
diego
parents: 5017
diff changeset
213 url_fseek(s->pb, filesize - 128, SEEK_SET);
9ed3c88ed9ba Move id3v1/id3v2 handling code from mp3.c to id3v[12].c.
diego
parents: 5017
diff changeset
214 ret = get_buffer(s->pb, buf, ID3v1_TAG_SIZE);
9ed3c88ed9ba Move id3v1/id3v2 handling code from mp3.c to id3v[12].c.
diego
parents: 5017
diff changeset
215 if (ret == ID3v1_TAG_SIZE) {
9ed3c88ed9ba Move id3v1/id3v2 handling code from mp3.c to id3v[12].c.
diego
parents: 5017
diff changeset
216 parse_tag(s, buf);
9ed3c88ed9ba Move id3v1/id3v2 handling code from mp3.c to id3v[12].c.
diego
parents: 5017
diff changeset
217 }
9ed3c88ed9ba Move id3v1/id3v2 handling code from mp3.c to id3v[12].c.
diego
parents: 5017
diff changeset
218 url_fseek(s->pb, 0, SEEK_SET);
9ed3c88ed9ba Move id3v1/id3v2 handling code from mp3.c to id3v[12].c.
diego
parents: 5017
diff changeset
219 }
9ed3c88ed9ba Move id3v1/id3v2 handling code from mp3.c to id3v[12].c.
diego
parents: 5017
diff changeset
220 }
9ed3c88ed9ba Move id3v1/id3v2 handling code from mp3.c to id3v[12].c.
diego
parents: 5017
diff changeset
221 }