annotate id3v2.c @ 5133:1df917933244 libavformat

Do not use internals of ByteIOContext during APE tags parsing. Patch by Matti Hamalainen, mail = reverse("if.kmao.stneduts@ialamahm") Thread: [PATCH] 2/6 Fix broken APE tag key handling
author kostya
date Tue, 11 Aug 2009 16:55:49 +0000
parents 696b27c2791a
children 4a01407f678d
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
d05b13327b07 Fix probing of files with ID3v2 tags. Discussed at
alexc
parents: 4221
diff changeset
38
d05b13327b07 Fix probing of files with ID3v2 tags. Discussed at
alexc
parents: 4221
diff changeset
39 int ff_id3v2_tag_len(const uint8_t * buf)
d05b13327b07 Fix probing of files with ID3v2 tags. Discussed at
alexc
parents: 4221
diff changeset
40 {
d05b13327b07 Fix probing of files with ID3v2 tags. Discussed at
alexc
parents: 4221
diff changeset
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
d05b13327b07 Fix probing of files with ID3v2 tags. Discussed at
alexc
parents: 4221
diff changeset
46 if (buf[5] & 0x10)
d05b13327b07 Fix probing of files with ID3v2 tags. Discussed at
alexc
parents: 4221
diff changeset
47 len += ID3v2_HEADER_SIZE;
d05b13327b07 Fix probing of files with ID3v2 tags. Discussed at
alexc
parents: 4221
diff changeset
48 return len;
d05b13327b07 Fix probing of files with ID3v2 tags. Discussed at
alexc
parents: 4221
diff changeset
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;
eb6dd7717805 Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents: 4254
diff changeset
84
5017
1763f7d0d8d0 cosmetics: Reformat to K&R and prettyprint newly created files.
diego
parents: 5016
diff changeset
85 dst[0] = 0;
1763f7d0d8d0 cosmetics: Reformat to K&R and prettyprint newly created files.
diego
parents: 5016
diff changeset
86 if (taglen < 1)
5016
eb6dd7717805 Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents: 4254
diff changeset
87 return;
eb6dd7717805 Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents: 4254
diff changeset
88
eb6dd7717805 Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents: 4254
diff changeset
89 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
90
5017
1763f7d0d8d0 cosmetics: Reformat to K&R and prettyprint newly created files.
diego
parents: 5016
diff changeset
91 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
92
eb6dd7717805 Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents: 4254
diff changeset
93 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
94 q = dst;
5017
1763f7d0d8d0 cosmetics: Reformat to K&R and prettyprint newly created files.
diego
parents: 5016
diff changeset
95 while (taglen--) {
5016
eb6dd7717805 Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents: 4254
diff changeset
96 uint8_t tmp;
eb6dd7717805 Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents: 4254
diff changeset
97 PUT_UTF8(get_byte(s->pb), tmp, if (q - dst < dstlen - 1) *q++ = tmp;)
eb6dd7717805 Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents: 4254
diff changeset
98 }
eb6dd7717805 Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents: 4254
diff changeset
99 *q = '\0';
eb6dd7717805 Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents: 4254
diff changeset
100 break;
eb6dd7717805 Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents: 4254
diff changeset
101
eb6dd7717805 Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents: 4254
diff changeset
102 case 3: /* UTF-8 */
5017
1763f7d0d8d0 cosmetics: Reformat to K&R and prettyprint newly created files.
diego
parents: 5016
diff changeset
103 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
104 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
105 dst[len] = 0;
eb6dd7717805 Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents: 4254
diff changeset
106 break;
eb6dd7717805 Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents: 4254
diff changeset
107 }
eb6dd7717805 Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents: 4254
diff changeset
108
eb6dd7717805 Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents: 4254
diff changeset
109 if (!strcmp(key, "genre")
eb6dd7717805 Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents: 4254
diff changeset
110 && (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
111 && genre <= ID3v1_GENRE_MAX)
eb6dd7717805 Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents: 4254
diff changeset
112 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
113
eb6dd7717805 Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents: 4254
diff changeset
114 if (*dst)
eb6dd7717805 Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents: 4254
diff changeset
115 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
116 }
eb6dd7717805 Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents: 4254
diff changeset
117
eb6dd7717805 Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents: 4254
diff changeset
118 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
119 {
eb6dd7717805 Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents: 4254
diff changeset
120 int isv34, tlen;
eb6dd7717805 Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents: 4254
diff changeset
121 uint32_t tag;
eb6dd7717805 Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents: 4254
diff changeset
122 int64_t next;
eb6dd7717805 Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents: 4254
diff changeset
123 int taghdrlen;
eb6dd7717805 Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents: 4254
diff changeset
124 const char *reason;
eb6dd7717805 Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents: 4254
diff changeset
125
5017
1763f7d0d8d0 cosmetics: Reformat to K&R and prettyprint newly created files.
diego
parents: 5016
diff changeset
126 switch (version) {
5016
eb6dd7717805 Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents: 4254
diff changeset
127 case 2:
5017
1763f7d0d8d0 cosmetics: Reformat to K&R and prettyprint newly created files.
diego
parents: 5016
diff changeset
128 if (flags & 0x40) {
5016
eb6dd7717805 Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents: 4254
diff changeset
129 reason = "compression";
eb6dd7717805 Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents: 4254
diff changeset
130 goto error;
eb6dd7717805 Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents: 4254
diff changeset
131 }
eb6dd7717805 Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents: 4254
diff changeset
132 isv34 = 0;
eb6dd7717805 Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents: 4254
diff changeset
133 taghdrlen = 6;
eb6dd7717805 Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents: 4254
diff changeset
134 break;
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 case 3:
eb6dd7717805 Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents: 4254
diff changeset
137 case 4:
eb6dd7717805 Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents: 4254
diff changeset
138 isv34 = 1;
eb6dd7717805 Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents: 4254
diff changeset
139 taghdrlen = 10;
eb6dd7717805 Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents: 4254
diff changeset
140 break;
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 default:
eb6dd7717805 Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents: 4254
diff changeset
143 reason = "version";
eb6dd7717805 Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents: 4254
diff changeset
144 goto error;
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
5017
1763f7d0d8d0 cosmetics: Reformat to K&R and prettyprint newly created files.
diego
parents: 5016
diff changeset
147 if (flags & 0x80) {
5016
eb6dd7717805 Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents: 4254
diff changeset
148 reason = "unsynchronization";
eb6dd7717805 Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents: 4254
diff changeset
149 goto error;
eb6dd7717805 Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents: 4254
diff changeset
150 }
eb6dd7717805 Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents: 4254
diff changeset
151
5017
1763f7d0d8d0 cosmetics: Reformat to K&R and prettyprint newly created files.
diego
parents: 5016
diff changeset
152 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
153 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
154
5017
1763f7d0d8d0 cosmetics: Reformat to K&R and prettyprint newly created files.
diego
parents: 5016
diff changeset
155 while (len >= taghdrlen) {
1763f7d0d8d0 cosmetics: Reformat to K&R and prettyprint newly created files.
diego
parents: 5016
diff changeset
156 if (isv34) {
5016
eb6dd7717805 Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents: 4254
diff changeset
157 tag = get_be32(s->pb);
5076
e07fb352a12c id3v2.4.0 uses syncsafe integers for sizes of frames.
michael
parents: 5073
diff changeset
158 if(version==3){
5077
michael
parents: 5076
diff changeset
159 tlen = get_be32(s->pb);
5076
e07fb352a12c id3v2.4.0 uses syncsafe integers for sizes of frames.
michael
parents: 5073
diff changeset
160 }else
e07fb352a12c id3v2.4.0 uses syncsafe integers for sizes of frames.
michael
parents: 5073
diff changeset
161 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
162 get_be16(s->pb); /* flags */
eb6dd7717805 Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents: 4254
diff changeset
163 } else {
eb6dd7717805 Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents: 4254
diff changeset
164 tag = get_be24(s->pb);
5073
2216af3795e1 Fix id3v2.2 frame size parsing.
michael
parents: 5072
diff changeset
165 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
166 }
eb6dd7717805 Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents: 4254
diff changeset
167 len -= taghdrlen + tlen;
eb6dd7717805 Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents: 4254
diff changeset
168
5017
1763f7d0d8d0 cosmetics: Reformat to K&R and prettyprint newly created files.
diego
parents: 5016
diff changeset
169 if (len < 0)
5016
eb6dd7717805 Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents: 4254
diff changeset
170 break;
eb6dd7717805 Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents: 4254
diff changeset
171
eb6dd7717805 Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents: 4254
diff changeset
172 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
173
5017
1763f7d0d8d0 cosmetics: Reformat to K&R and prettyprint newly created files.
diego
parents: 5016
diff changeset
174 switch (tag) {
5016
eb6dd7717805 Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents: 4254
diff changeset
175 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
176 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
177 read_ttag(s, tlen, "title");
eb6dd7717805 Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents: 4254
diff changeset
178 break;
eb6dd7717805 Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents: 4254
diff changeset
179 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
180 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
181 read_ttag(s, tlen, "author");
eb6dd7717805 Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents: 4254
diff changeset
182 break;
eb6dd7717805 Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents: 4254
diff changeset
183 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
184 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
185 read_ttag(s, tlen, "album");
eb6dd7717805 Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents: 4254
diff changeset
186 break;
eb6dd7717805 Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents: 4254
diff changeset
187 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
188 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
189 read_ttag(s, tlen, "genre");
eb6dd7717805 Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents: 4254
diff changeset
190 break;
eb6dd7717805 Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents: 4254
diff changeset
191 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
192 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
193 read_ttag(s, tlen, "copyright");
eb6dd7717805 Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents: 4254
diff changeset
194 break;
eb6dd7717805 Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents: 4254
diff changeset
195 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
196 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
197 read_ttag(s, tlen, "track");
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 case 0:
eb6dd7717805 Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents: 4254
diff changeset
200 /* padding, skip to end */
eb6dd7717805 Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents: 4254
diff changeset
201 url_fskip(s->pb, len);
eb6dd7717805 Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents: 4254
diff changeset
202 len = 0;
eb6dd7717805 Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents: 4254
diff changeset
203 continue;
eb6dd7717805 Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents: 4254
diff changeset
204 }
eb6dd7717805 Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents: 4254
diff changeset
205 /* Skip to end of tag */
eb6dd7717805 Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents: 4254
diff changeset
206 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
207 }
eb6dd7717805 Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents: 4254
diff changeset
208
5017
1763f7d0d8d0 cosmetics: Reformat to K&R and prettyprint newly created files.
diego
parents: 5016
diff changeset
209 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
210 url_fskip(s->pb, 10);
eb6dd7717805 Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents: 4254
diff changeset
211 return;
eb6dd7717805 Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents: 4254
diff changeset
212
eb6dd7717805 Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents: 4254
diff changeset
213 error:
eb6dd7717805 Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents: 4254
diff changeset
214 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
215 url_fskip(s->pb, len);
eb6dd7717805 Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents: 4254
diff changeset
216 }