Mercurial > libavformat.hg
annotate id3v2.c @ 5235:bf1b8e6b3a84 libavformat
100l, typo
author | bcoudurier |
---|---|
date | Sat, 26 Sep 2009 21:06:18 +0000 |
parents | d2e3bc991df4 |
children | 1403c88b1ce7 |
rev | line source |
---|---|
4221
55f448c99135
Factorise id3v2 header parsing from mp3.c to be shared
superdump
parents:
diff
changeset
|
1 /* |
55f448c99135
Factorise id3v2 header parsing from mp3.c to be shared
superdump
parents:
diff
changeset
|
2 * ID3v2 header parser |
55f448c99135
Factorise id3v2 header parsing from mp3.c to be shared
superdump
parents:
diff
changeset
|
3 * Copyright (c) 2003 Fabrice Bellard |
55f448c99135
Factorise id3v2 header parsing from mp3.c to be shared
superdump
parents:
diff
changeset
|
4 * |
55f448c99135
Factorise id3v2 header parsing from mp3.c to be shared
superdump
parents:
diff
changeset
|
5 * This file is part of FFmpeg. |
55f448c99135
Factorise id3v2 header parsing from mp3.c to be shared
superdump
parents:
diff
changeset
|
6 * |
55f448c99135
Factorise id3v2 header parsing from mp3.c to be shared
superdump
parents:
diff
changeset
|
7 * FFmpeg is free software; you can redistribute it and/or |
55f448c99135
Factorise id3v2 header parsing from mp3.c to be shared
superdump
parents:
diff
changeset
|
8 * modify it under the terms of the GNU Lesser General Public |
55f448c99135
Factorise id3v2 header parsing from mp3.c to be shared
superdump
parents:
diff
changeset
|
9 * License as published by the Free Software Foundation; either |
55f448c99135
Factorise id3v2 header parsing from mp3.c to be shared
superdump
parents:
diff
changeset
|
10 * version 2.1 of the License, or (at your option) any later version. |
55f448c99135
Factorise id3v2 header parsing from mp3.c to be shared
superdump
parents:
diff
changeset
|
11 * |
55f448c99135
Factorise id3v2 header parsing from mp3.c to be shared
superdump
parents:
diff
changeset
|
12 * FFmpeg is distributed in the hope that it will be useful, |
55f448c99135
Factorise id3v2 header parsing from mp3.c to be shared
superdump
parents:
diff
changeset
|
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
55f448c99135
Factorise id3v2 header parsing from mp3.c to be shared
superdump
parents:
diff
changeset
|
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
55f448c99135
Factorise id3v2 header parsing from mp3.c to be shared
superdump
parents:
diff
changeset
|
15 * Lesser General Public License for more details. |
55f448c99135
Factorise id3v2 header parsing from mp3.c to be shared
superdump
parents:
diff
changeset
|
16 * |
55f448c99135
Factorise id3v2 header parsing from mp3.c to be shared
superdump
parents:
diff
changeset
|
17 * You should have received a copy of the GNU Lesser General Public |
55f448c99135
Factorise id3v2 header parsing from mp3.c to be shared
superdump
parents:
diff
changeset
|
18 * License along with FFmpeg; if not, write to the Free Software |
55f448c99135
Factorise id3v2 header parsing from mp3.c to be shared
superdump
parents:
diff
changeset
|
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
55f448c99135
Factorise id3v2 header parsing from mp3.c to be shared
superdump
parents:
diff
changeset
|
20 */ |
55f448c99135
Factorise id3v2 header parsing from mp3.c to be shared
superdump
parents:
diff
changeset
|
21 |
55f448c99135
Factorise id3v2 header parsing from mp3.c to be shared
superdump
parents:
diff
changeset
|
22 #include "id3v2.h" |
5016
eb6dd7717805
Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents:
4254
diff
changeset
|
23 #include "id3v1.h" |
eb6dd7717805
Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents:
4254
diff
changeset
|
24 #include "libavutil/avstring.h" |
4221
55f448c99135
Factorise id3v2 header parsing from mp3.c to be shared
superdump
parents:
diff
changeset
|
25 |
55f448c99135
Factorise id3v2 header parsing from mp3.c to be shared
superdump
parents:
diff
changeset
|
26 int ff_id3v2_match(const uint8_t *buf) |
55f448c99135
Factorise id3v2 header parsing from mp3.c to be shared
superdump
parents:
diff
changeset
|
27 { |
5017
1763f7d0d8d0
cosmetics: Reformat to K&R and prettyprint newly created files.
diego
parents:
5016
diff
changeset
|
28 return buf[0] == 'I' && |
1763f7d0d8d0
cosmetics: Reformat to K&R and prettyprint newly created files.
diego
parents:
5016
diff
changeset
|
29 buf[1] == 'D' && |
1763f7d0d8d0
cosmetics: Reformat to K&R and prettyprint newly created files.
diego
parents:
5016
diff
changeset
|
30 buf[2] == '3' && |
1763f7d0d8d0
cosmetics: Reformat to K&R and prettyprint newly created files.
diego
parents:
5016
diff
changeset
|
31 buf[3] != 0xff && |
1763f7d0d8d0
cosmetics: Reformat to K&R and prettyprint newly created files.
diego
parents:
5016
diff
changeset
|
32 buf[4] != 0xff && |
1763f7d0d8d0
cosmetics: Reformat to K&R and prettyprint newly created files.
diego
parents:
5016
diff
changeset
|
33 (buf[6] & 0x80) == 0 && |
1763f7d0d8d0
cosmetics: Reformat to K&R and prettyprint newly created files.
diego
parents:
5016
diff
changeset
|
34 (buf[7] & 0x80) == 0 && |
1763f7d0d8d0
cosmetics: Reformat to K&R and prettyprint newly created files.
diego
parents:
5016
diff
changeset
|
35 (buf[8] & 0x80) == 0 && |
5018
2d29b49bae3e
cosmetics: Prettyprint one more line to have columns line up.
diego
parents:
5017
diff
changeset
|
36 (buf[9] & 0x80) == 0; |
4221
55f448c99135
Factorise id3v2 header parsing from mp3.c to be shared
superdump
parents:
diff
changeset
|
37 } |
4254 | 38 |
39 int ff_id3v2_tag_len(const uint8_t * buf) | |
40 { | |
41 int len = ((buf[6] & 0x7f) << 21) + | |
5017
1763f7d0d8d0
cosmetics: Reformat to K&R and prettyprint newly created files.
diego
parents:
5016
diff
changeset
|
42 ((buf[7] & 0x7f) << 14) + |
1763f7d0d8d0
cosmetics: Reformat to K&R and prettyprint newly created files.
diego
parents:
5016
diff
changeset
|
43 ((buf[8] & 0x7f) << 7) + |
1763f7d0d8d0
cosmetics: Reformat to K&R and prettyprint newly created files.
diego
parents:
5016
diff
changeset
|
44 (buf[9] & 0x7f) + |
1763f7d0d8d0
cosmetics: Reformat to K&R and prettyprint newly created files.
diego
parents:
5016
diff
changeset
|
45 ID3v2_HEADER_SIZE; |
4254 | 46 if (buf[5] & 0x10) |
47 len += ID3v2_HEADER_SIZE; | |
48 return len; | |
49 } | |
5016
eb6dd7717805
Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents:
4254
diff
changeset
|
50 |
5045
9ed3c88ed9ba
Move id3v1/id3v2 handling code from mp3.c to id3v[12].c.
diego
parents:
5018
diff
changeset
|
51 void ff_id3v2_read(AVFormatContext *s) |
9ed3c88ed9ba
Move id3v1/id3v2 handling code from mp3.c to id3v[12].c.
diego
parents:
5018
diff
changeset
|
52 { |
9ed3c88ed9ba
Move id3v1/id3v2 handling code from mp3.c to id3v[12].c.
diego
parents:
5018
diff
changeset
|
53 int len, ret; |
9ed3c88ed9ba
Move id3v1/id3v2 handling code from mp3.c to id3v[12].c.
diego
parents:
5018
diff
changeset
|
54 uint8_t buf[ID3v2_HEADER_SIZE]; |
9ed3c88ed9ba
Move id3v1/id3v2 handling code from mp3.c to id3v[12].c.
diego
parents:
5018
diff
changeset
|
55 |
9ed3c88ed9ba
Move id3v1/id3v2 handling code from mp3.c to id3v[12].c.
diego
parents:
5018
diff
changeset
|
56 ret = get_buffer(s->pb, buf, ID3v2_HEADER_SIZE); |
9ed3c88ed9ba
Move id3v1/id3v2 handling code from mp3.c to id3v[12].c.
diego
parents:
5018
diff
changeset
|
57 if (ret != ID3v2_HEADER_SIZE) |
9ed3c88ed9ba
Move id3v1/id3v2 handling code from mp3.c to id3v[12].c.
diego
parents:
5018
diff
changeset
|
58 return; |
9ed3c88ed9ba
Move id3v1/id3v2 handling code from mp3.c to id3v[12].c.
diego
parents:
5018
diff
changeset
|
59 if (ff_id3v2_match(buf)) { |
9ed3c88ed9ba
Move id3v1/id3v2 handling code from mp3.c to id3v[12].c.
diego
parents:
5018
diff
changeset
|
60 /* parse ID3v2 header */ |
9ed3c88ed9ba
Move id3v1/id3v2 handling code from mp3.c to id3v[12].c.
diego
parents:
5018
diff
changeset
|
61 len = ((buf[6] & 0x7f) << 21) | |
9ed3c88ed9ba
Move id3v1/id3v2 handling code from mp3.c to id3v[12].c.
diego
parents:
5018
diff
changeset
|
62 ((buf[7] & 0x7f) << 14) | |
9ed3c88ed9ba
Move id3v1/id3v2 handling code from mp3.c to id3v[12].c.
diego
parents:
5018
diff
changeset
|
63 ((buf[8] & 0x7f) << 7) | |
9ed3c88ed9ba
Move id3v1/id3v2 handling code from mp3.c to id3v[12].c.
diego
parents:
5018
diff
changeset
|
64 (buf[9] & 0x7f); |
9ed3c88ed9ba
Move id3v1/id3v2 handling code from mp3.c to id3v[12].c.
diego
parents:
5018
diff
changeset
|
65 ff_id3v2_parse(s, len, buf[3], buf[5]); |
9ed3c88ed9ba
Move id3v1/id3v2 handling code from mp3.c to id3v[12].c.
diego
parents:
5018
diff
changeset
|
66 } else { |
9ed3c88ed9ba
Move id3v1/id3v2 handling code from mp3.c to id3v[12].c.
diego
parents:
5018
diff
changeset
|
67 url_fseek(s->pb, 0, SEEK_SET); |
9ed3c88ed9ba
Move id3v1/id3v2 handling code from mp3.c to id3v[12].c.
diego
parents:
5018
diff
changeset
|
68 } |
9ed3c88ed9ba
Move id3v1/id3v2 handling code from mp3.c to id3v[12].c.
diego
parents:
5018
diff
changeset
|
69 } |
9ed3c88ed9ba
Move id3v1/id3v2 handling code from mp3.c to id3v[12].c.
diego
parents:
5018
diff
changeset
|
70 |
5016
eb6dd7717805
Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents:
4254
diff
changeset
|
71 static unsigned int get_size(ByteIOContext *s, int len) |
eb6dd7717805
Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents:
4254
diff
changeset
|
72 { |
5017
1763f7d0d8d0
cosmetics: Reformat to K&R and prettyprint newly created files.
diego
parents:
5016
diff
changeset
|
73 int v = 0; |
1763f7d0d8d0
cosmetics: Reformat to K&R and prettyprint newly created files.
diego
parents:
5016
diff
changeset
|
74 while (len--) |
1763f7d0d8d0
cosmetics: Reformat to K&R and prettyprint newly created files.
diego
parents:
5016
diff
changeset
|
75 v = (v << 7) + (get_byte(s) & 0x7F); |
5016
eb6dd7717805
Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents:
4254
diff
changeset
|
76 return v; |
eb6dd7717805
Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents:
4254
diff
changeset
|
77 } |
eb6dd7717805
Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents:
4254
diff
changeset
|
78 |
eb6dd7717805
Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents:
4254
diff
changeset
|
79 static void read_ttag(AVFormatContext *s, int taglen, const char *key) |
eb6dd7717805
Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents:
4254
diff
changeset
|
80 { |
eb6dd7717805
Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents:
4254
diff
changeset
|
81 char *q, dst[512]; |
eb6dd7717805
Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents:
4254
diff
changeset
|
82 int len, dstlen = sizeof(dst) - 1; |
eb6dd7717805
Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents:
4254
diff
changeset
|
83 unsigned genre; |
5231 | 84 unsigned int (*get)(ByteIOContext*) = get_be16; |
5016
eb6dd7717805
Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents:
4254
diff
changeset
|
85 |
5017
1763f7d0d8d0
cosmetics: Reformat to K&R and prettyprint newly created files.
diego
parents:
5016
diff
changeset
|
86 dst[0] = 0; |
1763f7d0d8d0
cosmetics: Reformat to K&R and prettyprint newly created files.
diego
parents:
5016
diff
changeset
|
87 if (taglen < 1) |
5016
eb6dd7717805
Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents:
4254
diff
changeset
|
88 return; |
eb6dd7717805
Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents:
4254
diff
changeset
|
89 |
eb6dd7717805
Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents:
4254
diff
changeset
|
90 taglen--; /* account for encoding type byte */ |
eb6dd7717805
Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents:
4254
diff
changeset
|
91 |
5017
1763f7d0d8d0
cosmetics: Reformat to K&R and prettyprint newly created files.
diego
parents:
5016
diff
changeset
|
92 switch (get_byte(s->pb)) { /* encoding type */ |
5016
eb6dd7717805
Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents:
4254
diff
changeset
|
93 |
eb6dd7717805
Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents:
4254
diff
changeset
|
94 case 0: /* ISO-8859-1 (0 - 255 maps directly into unicode) */ |
eb6dd7717805
Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents:
4254
diff
changeset
|
95 q = dst; |
5229
4a01407f678d
id3v2: check for enough space to write full UTF-8 characters.
diego
parents:
5077
diff
changeset
|
96 while (taglen-- && q - dst < dstlen - 7) { |
5016
eb6dd7717805
Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents:
4254
diff
changeset
|
97 uint8_t tmp; |
5229
4a01407f678d
id3v2: check for enough space to write full UTF-8 characters.
diego
parents:
5077
diff
changeset
|
98 PUT_UTF8(get_byte(s->pb), tmp, *q++ = tmp;) |
5016
eb6dd7717805
Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents:
4254
diff
changeset
|
99 } |
5230 | 100 *q = 0; |
5016
eb6dd7717805
Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents:
4254
diff
changeset
|
101 break; |
eb6dd7717805
Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents:
4254
diff
changeset
|
102 |
5231 | 103 case 1: /* UTF-16 with BOM */ |
104 taglen -= 2; | |
105 switch (get_be16(s->pb)) { | |
106 case 0xfffe: | |
107 get = get_le16; | |
108 case 0xfeff: | |
109 break; | |
110 default: | |
111 av_log(s, AV_LOG_ERROR, "Incorrect BOM value in tag %s.\n", key); | |
112 return; | |
113 } | |
114 // fall-through | |
115 | |
116 case 2: /* UTF-16BE without BOM */ | |
117 q = dst; | |
118 while (taglen > 1 && q - dst < dstlen - 7) { | |
119 uint32_t ch; | |
120 uint8_t tmp; | |
121 | |
122 GET_UTF16(ch, ((taglen -= 2) >= 0 ? get(s->pb) : 0), break;) | |
123 PUT_UTF8(ch, tmp, *q++ = tmp;) | |
124 } | |
125 *q = 0; | |
126 break; | |
127 | |
5016
eb6dd7717805
Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents:
4254
diff
changeset
|
128 case 3: /* UTF-8 */ |
5017
1763f7d0d8d0
cosmetics: Reformat to K&R and prettyprint newly created files.
diego
parents:
5016
diff
changeset
|
129 len = FFMIN(taglen, dstlen - 1); |
5016
eb6dd7717805
Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents:
4254
diff
changeset
|
130 get_buffer(s->pb, dst, len); |
eb6dd7717805
Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents:
4254
diff
changeset
|
131 dst[len] = 0; |
eb6dd7717805
Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents:
4254
diff
changeset
|
132 break; |
5231 | 133 default: |
134 av_log(s, AV_LOG_WARNING, "Unknown encoding in tag %s\n.", key); | |
5016
eb6dd7717805
Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents:
4254
diff
changeset
|
135 } |
eb6dd7717805
Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents:
4254
diff
changeset
|
136 |
eb6dd7717805
Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents:
4254
diff
changeset
|
137 if (!strcmp(key, "genre") |
eb6dd7717805
Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents:
4254
diff
changeset
|
138 && (sscanf(dst, "(%d)", &genre) == 1 || sscanf(dst, "%d", &genre) == 1) |
eb6dd7717805
Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents:
4254
diff
changeset
|
139 && genre <= ID3v1_GENRE_MAX) |
eb6dd7717805
Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents:
4254
diff
changeset
|
140 av_strlcpy(dst, ff_id3v1_genre_str[genre], sizeof(dst)); |
eb6dd7717805
Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents:
4254
diff
changeset
|
141 |
eb6dd7717805
Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents:
4254
diff
changeset
|
142 if (*dst) |
eb6dd7717805
Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents:
4254
diff
changeset
|
143 av_metadata_set(&s->metadata, key, dst); |
eb6dd7717805
Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents:
4254
diff
changeset
|
144 } |
eb6dd7717805
Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents:
4254
diff
changeset
|
145 |
eb6dd7717805
Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents:
4254
diff
changeset
|
146 void ff_id3v2_parse(AVFormatContext *s, int len, uint8_t version, uint8_t flags) |
eb6dd7717805
Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents:
4254
diff
changeset
|
147 { |
eb6dd7717805
Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents:
4254
diff
changeset
|
148 int isv34, tlen; |
eb6dd7717805
Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents:
4254
diff
changeset
|
149 uint32_t tag; |
eb6dd7717805
Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents:
4254
diff
changeset
|
150 int64_t next; |
eb6dd7717805
Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents:
4254
diff
changeset
|
151 int taghdrlen; |
eb6dd7717805
Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents:
4254
diff
changeset
|
152 const char *reason; |
eb6dd7717805
Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents:
4254
diff
changeset
|
153 |
5017
1763f7d0d8d0
cosmetics: Reformat to K&R and prettyprint newly created files.
diego
parents:
5016
diff
changeset
|
154 switch (version) { |
5016
eb6dd7717805
Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents:
4254
diff
changeset
|
155 case 2: |
5017
1763f7d0d8d0
cosmetics: Reformat to K&R and prettyprint newly created files.
diego
parents:
5016
diff
changeset
|
156 if (flags & 0x40) { |
5016
eb6dd7717805
Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents:
4254
diff
changeset
|
157 reason = "compression"; |
eb6dd7717805
Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents:
4254
diff
changeset
|
158 goto error; |
eb6dd7717805
Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents:
4254
diff
changeset
|
159 } |
eb6dd7717805
Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents:
4254
diff
changeset
|
160 isv34 = 0; |
eb6dd7717805
Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents:
4254
diff
changeset
|
161 taghdrlen = 6; |
eb6dd7717805
Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents:
4254
diff
changeset
|
162 break; |
eb6dd7717805
Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents:
4254
diff
changeset
|
163 |
eb6dd7717805
Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents:
4254
diff
changeset
|
164 case 3: |
eb6dd7717805
Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents:
4254
diff
changeset
|
165 case 4: |
eb6dd7717805
Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents:
4254
diff
changeset
|
166 isv34 = 1; |
eb6dd7717805
Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents:
4254
diff
changeset
|
167 taghdrlen = 10; |
eb6dd7717805
Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents:
4254
diff
changeset
|
168 break; |
eb6dd7717805
Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents:
4254
diff
changeset
|
169 |
eb6dd7717805
Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents:
4254
diff
changeset
|
170 default: |
eb6dd7717805
Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents:
4254
diff
changeset
|
171 reason = "version"; |
eb6dd7717805
Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents:
4254
diff
changeset
|
172 goto error; |
eb6dd7717805
Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents:
4254
diff
changeset
|
173 } |
eb6dd7717805
Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents:
4254
diff
changeset
|
174 |
5017
1763f7d0d8d0
cosmetics: Reformat to K&R and prettyprint newly created files.
diego
parents:
5016
diff
changeset
|
175 if (flags & 0x80) { |
5016
eb6dd7717805
Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents:
4254
diff
changeset
|
176 reason = "unsynchronization"; |
eb6dd7717805
Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents:
4254
diff
changeset
|
177 goto error; |
eb6dd7717805
Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents:
4254
diff
changeset
|
178 } |
eb6dd7717805
Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents:
4254
diff
changeset
|
179 |
5017
1763f7d0d8d0
cosmetics: Reformat to K&R and prettyprint newly created files.
diego
parents:
5016
diff
changeset
|
180 if (isv34 && flags & 0x40) /* Extended header present, just skip over it */ |
5016
eb6dd7717805
Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents:
4254
diff
changeset
|
181 url_fskip(s->pb, get_size(s->pb, 4)); |
eb6dd7717805
Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents:
4254
diff
changeset
|
182 |
5017
1763f7d0d8d0
cosmetics: Reformat to K&R and prettyprint newly created files.
diego
parents:
5016
diff
changeset
|
183 while (len >= taghdrlen) { |
1763f7d0d8d0
cosmetics: Reformat to K&R and prettyprint newly created files.
diego
parents:
5016
diff
changeset
|
184 if (isv34) { |
5016
eb6dd7717805
Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents:
4254
diff
changeset
|
185 tag = get_be32(s->pb); |
5076
e07fb352a12c
id3v2.4.0 uses syncsafe integers for sizes of frames.
michael
parents:
5073
diff
changeset
|
186 if(version==3){ |
5077 | 187 tlen = get_be32(s->pb); |
5076
e07fb352a12c
id3v2.4.0 uses syncsafe integers for sizes of frames.
michael
parents:
5073
diff
changeset
|
188 }else |
e07fb352a12c
id3v2.4.0 uses syncsafe integers for sizes of frames.
michael
parents:
5073
diff
changeset
|
189 tlen = get_size(s->pb, 4); |
5016
eb6dd7717805
Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents:
4254
diff
changeset
|
190 get_be16(s->pb); /* flags */ |
eb6dd7717805
Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents:
4254
diff
changeset
|
191 } else { |
eb6dd7717805
Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents:
4254
diff
changeset
|
192 tag = get_be24(s->pb); |
5073 | 193 tlen = get_be24(s->pb); |
5016
eb6dd7717805
Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents:
4254
diff
changeset
|
194 } |
eb6dd7717805
Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents:
4254
diff
changeset
|
195 len -= taghdrlen + tlen; |
eb6dd7717805
Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents:
4254
diff
changeset
|
196 |
5017
1763f7d0d8d0
cosmetics: Reformat to K&R and prettyprint newly created files.
diego
parents:
5016
diff
changeset
|
197 if (len < 0) |
5016
eb6dd7717805
Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents:
4254
diff
changeset
|
198 break; |
eb6dd7717805
Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents:
4254
diff
changeset
|
199 |
eb6dd7717805
Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents:
4254
diff
changeset
|
200 next = url_ftell(s->pb) + tlen; |
eb6dd7717805
Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents:
4254
diff
changeset
|
201 |
5017
1763f7d0d8d0
cosmetics: Reformat to K&R and prettyprint newly created files.
diego
parents:
5016
diff
changeset
|
202 switch (tag) { |
5016
eb6dd7717805
Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents:
4254
diff
changeset
|
203 case MKBETAG('T', 'I', 'T', '2'): |
eb6dd7717805
Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents:
4254
diff
changeset
|
204 case MKBETAG(0, 'T', 'T', '2'): |
eb6dd7717805
Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents:
4254
diff
changeset
|
205 read_ttag(s, tlen, "title"); |
eb6dd7717805
Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents:
4254
diff
changeset
|
206 break; |
eb6dd7717805
Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents:
4254
diff
changeset
|
207 case MKBETAG('T', 'P', 'E', '1'): |
eb6dd7717805
Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents:
4254
diff
changeset
|
208 case MKBETAG(0, 'T', 'P', '1'): |
eb6dd7717805
Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents:
4254
diff
changeset
|
209 read_ttag(s, tlen, "author"); |
eb6dd7717805
Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents:
4254
diff
changeset
|
210 break; |
eb6dd7717805
Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents:
4254
diff
changeset
|
211 case MKBETAG('T', 'A', 'L', 'B'): |
eb6dd7717805
Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents:
4254
diff
changeset
|
212 case MKBETAG(0, 'T', 'A', 'L'): |
eb6dd7717805
Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents:
4254
diff
changeset
|
213 read_ttag(s, tlen, "album"); |
eb6dd7717805
Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents:
4254
diff
changeset
|
214 break; |
eb6dd7717805
Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents:
4254
diff
changeset
|
215 case MKBETAG('T', 'C', 'O', 'N'): |
eb6dd7717805
Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents:
4254
diff
changeset
|
216 case MKBETAG(0, 'T', 'C', 'O'): |
eb6dd7717805
Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents:
4254
diff
changeset
|
217 read_ttag(s, tlen, "genre"); |
eb6dd7717805
Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents:
4254
diff
changeset
|
218 break; |
eb6dd7717805
Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents:
4254
diff
changeset
|
219 case MKBETAG('T', 'C', 'O', 'P'): |
eb6dd7717805
Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents:
4254
diff
changeset
|
220 case MKBETAG(0, 'T', 'C', 'R'): |
eb6dd7717805
Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents:
4254
diff
changeset
|
221 read_ttag(s, tlen, "copyright"); |
eb6dd7717805
Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents:
4254
diff
changeset
|
222 break; |
eb6dd7717805
Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents:
4254
diff
changeset
|
223 case MKBETAG('T', 'R', 'C', 'K'): |
eb6dd7717805
Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents:
4254
diff
changeset
|
224 case MKBETAG(0, 'T', 'R', 'K'): |
eb6dd7717805
Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents:
4254
diff
changeset
|
225 read_ttag(s, tlen, "track"); |
eb6dd7717805
Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents:
4254
diff
changeset
|
226 break; |
eb6dd7717805
Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents:
4254
diff
changeset
|
227 case 0: |
eb6dd7717805
Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents:
4254
diff
changeset
|
228 /* padding, skip to end */ |
eb6dd7717805
Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents:
4254
diff
changeset
|
229 url_fskip(s->pb, len); |
eb6dd7717805
Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents:
4254
diff
changeset
|
230 len = 0; |
eb6dd7717805
Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents:
4254
diff
changeset
|
231 continue; |
eb6dd7717805
Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents:
4254
diff
changeset
|
232 } |
eb6dd7717805
Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents:
4254
diff
changeset
|
233 /* Skip to end of tag */ |
eb6dd7717805
Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents:
4254
diff
changeset
|
234 url_fseek(s->pb, next, SEEK_SET); |
eb6dd7717805
Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents:
4254
diff
changeset
|
235 } |
eb6dd7717805
Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents:
4254
diff
changeset
|
236 |
5017
1763f7d0d8d0
cosmetics: Reformat to K&R and prettyprint newly created files.
diego
parents:
5016
diff
changeset
|
237 if (version == 4 && flags & 0x10) /* Footer preset, always 10 bytes, skip over it */ |
5016
eb6dd7717805
Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents:
4254
diff
changeset
|
238 url_fskip(s->pb, 10); |
eb6dd7717805
Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents:
4254
diff
changeset
|
239 return; |
eb6dd7717805
Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents:
4254
diff
changeset
|
240 |
eb6dd7717805
Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents:
4254
diff
changeset
|
241 error: |
eb6dd7717805
Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents:
4254
diff
changeset
|
242 av_log(s, AV_LOG_INFO, "ID3v2.%d tag skipped, cannot handle %s\n", version, reason); |
eb6dd7717805
Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents:
4254
diff
changeset
|
243 url_fskip(s->pb, len); |
eb6dd7717805
Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents:
4254
diff
changeset
|
244 } |