Mercurial > libavformat.hg
annotate id3v2.c @ 6348:c709176da1ad libavformat
Preserve status reason
It is used to provide meaningful error messages.
author | lu_zero |
---|---|
date | Fri, 06 Aug 2010 10:26:30 +0000 |
parents | f5fec1ab4925 |
children | dd54b36d1b8c |
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" |
6121
81614e9b541b
Generalize ID3v2 functions to support ID3v2-like ID headers with a
cehoyos
parents:
5982
diff
changeset
|
25 #include "libavutil/intreadwrite.h" |
4221
55f448c99135
Factorise id3v2 header parsing from mp3.c to be shared
superdump
parents:
diff
changeset
|
26 |
6121
81614e9b541b
Generalize ID3v2 functions to support ID3v2-like ID headers with a
cehoyos
parents:
5982
diff
changeset
|
27 int ff_id3v2_match(const uint8_t *buf, const char * magic) |
4221
55f448c99135
Factorise id3v2 header parsing from mp3.c to be shared
superdump
parents:
diff
changeset
|
28 { |
6121
81614e9b541b
Generalize ID3v2 functions to support ID3v2-like ID headers with a
cehoyos
parents:
5982
diff
changeset
|
29 return buf[0] == magic[0] && |
81614e9b541b
Generalize ID3v2 functions to support ID3v2-like ID headers with a
cehoyos
parents:
5982
diff
changeset
|
30 buf[1] == magic[1] && |
81614e9b541b
Generalize ID3v2 functions to support ID3v2-like ID headers with a
cehoyos
parents:
5982
diff
changeset
|
31 buf[2] == magic[2] && |
5017
1763f7d0d8d0
cosmetics: Reformat to K&R and prettyprint newly created files.
diego
parents:
5016
diff
changeset
|
32 buf[3] != 0xff && |
1763f7d0d8d0
cosmetics: Reformat to K&R and prettyprint newly created files.
diego
parents:
5016
diff
changeset
|
33 buf[4] != 0xff && |
1763f7d0d8d0
cosmetics: Reformat to K&R and prettyprint newly created files.
diego
parents:
5016
diff
changeset
|
34 (buf[6] & 0x80) == 0 && |
1763f7d0d8d0
cosmetics: Reformat to K&R and prettyprint newly created files.
diego
parents:
5016
diff
changeset
|
35 (buf[7] & 0x80) == 0 && |
1763f7d0d8d0
cosmetics: Reformat to K&R and prettyprint newly created files.
diego
parents:
5016
diff
changeset
|
36 (buf[8] & 0x80) == 0 && |
5018
2d29b49bae3e
cosmetics: Prettyprint one more line to have columns line up.
diego
parents:
5017
diff
changeset
|
37 (buf[9] & 0x80) == 0; |
4221
55f448c99135
Factorise id3v2 header parsing from mp3.c to be shared
superdump
parents:
diff
changeset
|
38 } |
4254 | 39 |
40 int ff_id3v2_tag_len(const uint8_t * buf) | |
41 { | |
42 int len = ((buf[6] & 0x7f) << 21) + | |
5017
1763f7d0d8d0
cosmetics: Reformat to K&R and prettyprint newly created files.
diego
parents:
5016
diff
changeset
|
43 ((buf[7] & 0x7f) << 14) + |
1763f7d0d8d0
cosmetics: Reformat to K&R and prettyprint newly created files.
diego
parents:
5016
diff
changeset
|
44 ((buf[8] & 0x7f) << 7) + |
1763f7d0d8d0
cosmetics: Reformat to K&R and prettyprint newly created files.
diego
parents:
5016
diff
changeset
|
45 (buf[9] & 0x7f) + |
1763f7d0d8d0
cosmetics: Reformat to K&R and prettyprint newly created files.
diego
parents:
5016
diff
changeset
|
46 ID3v2_HEADER_SIZE; |
4254 | 47 if (buf[5] & 0x10) |
48 len += ID3v2_HEADER_SIZE; | |
49 return len; | |
50 } | |
5016
eb6dd7717805
Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents:
4254
diff
changeset
|
51 |
6121
81614e9b541b
Generalize ID3v2 functions to support ID3v2-like ID headers with a
cehoyos
parents:
5982
diff
changeset
|
52 void ff_id3v2_read(AVFormatContext *s, const char *magic) |
5045
9ed3c88ed9ba
Move id3v1/id3v2 handling code from mp3.c to id3v[12].c.
diego
parents:
5018
diff
changeset
|
53 { |
9ed3c88ed9ba
Move id3v1/id3v2 handling code from mp3.c to id3v[12].c.
diego
parents:
5018
diff
changeset
|
54 int len, ret; |
9ed3c88ed9ba
Move id3v1/id3v2 handling code from mp3.c to id3v[12].c.
diego
parents:
5018
diff
changeset
|
55 uint8_t buf[ID3v2_HEADER_SIZE]; |
9ed3c88ed9ba
Move id3v1/id3v2 handling code from mp3.c to id3v[12].c.
diego
parents:
5018
diff
changeset
|
56 |
9ed3c88ed9ba
Move id3v1/id3v2 handling code from mp3.c to id3v[12].c.
diego
parents:
5018
diff
changeset
|
57 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
|
58 if (ret != ID3v2_HEADER_SIZE) |
9ed3c88ed9ba
Move id3v1/id3v2 handling code from mp3.c to id3v[12].c.
diego
parents:
5018
diff
changeset
|
59 return; |
6121
81614e9b541b
Generalize ID3v2 functions to support ID3v2-like ID headers with a
cehoyos
parents:
5982
diff
changeset
|
60 if (ff_id3v2_match(buf, magic)) { |
5045
9ed3c88ed9ba
Move id3v1/id3v2 handling code from mp3.c to id3v[12].c.
diego
parents:
5018
diff
changeset
|
61 /* parse ID3v2 header */ |
9ed3c88ed9ba
Move id3v1/id3v2 handling code from mp3.c to id3v[12].c.
diego
parents:
5018
diff
changeset
|
62 len = ((buf[6] & 0x7f) << 21) | |
9ed3c88ed9ba
Move id3v1/id3v2 handling code from mp3.c to id3v[12].c.
diego
parents:
5018
diff
changeset
|
63 ((buf[7] & 0x7f) << 14) | |
9ed3c88ed9ba
Move id3v1/id3v2 handling code from mp3.c to id3v[12].c.
diego
parents:
5018
diff
changeset
|
64 ((buf[8] & 0x7f) << 7) | |
9ed3c88ed9ba
Move id3v1/id3v2 handling code from mp3.c to id3v[12].c.
diego
parents:
5018
diff
changeset
|
65 (buf[9] & 0x7f); |
9ed3c88ed9ba
Move id3v1/id3v2 handling code from mp3.c to id3v[12].c.
diego
parents:
5018
diff
changeset
|
66 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
|
67 } else { |
9ed3c88ed9ba
Move id3v1/id3v2 handling code from mp3.c to id3v[12].c.
diego
parents:
5018
diff
changeset
|
68 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
|
69 } |
9ed3c88ed9ba
Move id3v1/id3v2 handling code from mp3.c to id3v[12].c.
diego
parents:
5018
diff
changeset
|
70 } |
9ed3c88ed9ba
Move id3v1/id3v2 handling code from mp3.c to id3v[12].c.
diego
parents:
5018
diff
changeset
|
71 |
5016
eb6dd7717805
Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents:
4254
diff
changeset
|
72 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
|
73 { |
5017
1763f7d0d8d0
cosmetics: Reformat to K&R and prettyprint newly created files.
diego
parents:
5016
diff
changeset
|
74 int v = 0; |
1763f7d0d8d0
cosmetics: Reformat to K&R and prettyprint newly created files.
diego
parents:
5016
diff
changeset
|
75 while (len--) |
1763f7d0d8d0
cosmetics: Reformat to K&R and prettyprint newly created files.
diego
parents:
5016
diff
changeset
|
76 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
|
77 return v; |
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 |
eb6dd7717805
Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents:
4254
diff
changeset
|
80 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
|
81 { |
eb6dd7717805
Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents:
4254
diff
changeset
|
82 char *q, dst[512]; |
5265
79be5a6fd62f
id3v2: Export all text information frames with correct names.
ramiro
parents:
5264
diff
changeset
|
83 const char *val = NULL; |
5016
eb6dd7717805
Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents:
4254
diff
changeset
|
84 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
|
85 unsigned genre; |
5231 | 86 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
|
87 |
5017
1763f7d0d8d0
cosmetics: Reformat to K&R and prettyprint newly created files.
diego
parents:
5016
diff
changeset
|
88 dst[0] = 0; |
1763f7d0d8d0
cosmetics: Reformat to K&R and prettyprint newly created files.
diego
parents:
5016
diff
changeset
|
89 if (taglen < 1) |
5016
eb6dd7717805
Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents:
4254
diff
changeset
|
90 return; |
eb6dd7717805
Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents:
4254
diff
changeset
|
91 |
eb6dd7717805
Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents:
4254
diff
changeset
|
92 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
|
93 |
5017
1763f7d0d8d0
cosmetics: Reformat to K&R and prettyprint newly created files.
diego
parents:
5016
diff
changeset
|
94 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
|
95 |
eb6dd7717805
Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents:
4254
diff
changeset
|
96 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
|
97 q = dst; |
5229
4a01407f678d
id3v2: check for enough space to write full UTF-8 characters.
diego
parents:
5077
diff
changeset
|
98 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
|
99 uint8_t tmp; |
5229
4a01407f678d
id3v2: check for enough space to write full UTF-8 characters.
diego
parents:
5077
diff
changeset
|
100 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
|
101 } |
5230 | 102 *q = 0; |
5016
eb6dd7717805
Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents:
4254
diff
changeset
|
103 break; |
eb6dd7717805
Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents:
4254
diff
changeset
|
104 |
5231 | 105 case 1: /* UTF-16 with BOM */ |
106 taglen -= 2; | |
107 switch (get_be16(s->pb)) { | |
108 case 0xfffe: | |
109 get = get_le16; | |
110 case 0xfeff: | |
111 break; | |
112 default: | |
113 av_log(s, AV_LOG_ERROR, "Incorrect BOM value in tag %s.\n", key); | |
114 return; | |
115 } | |
116 // fall-through | |
117 | |
118 case 2: /* UTF-16BE without BOM */ | |
119 q = dst; | |
120 while (taglen > 1 && q - dst < dstlen - 7) { | |
121 uint32_t ch; | |
122 uint8_t tmp; | |
123 | |
124 GET_UTF16(ch, ((taglen -= 2) >= 0 ? get(s->pb) : 0), break;) | |
125 PUT_UTF8(ch, tmp, *q++ = tmp;) | |
126 } | |
127 *q = 0; | |
128 break; | |
129 | |
5016
eb6dd7717805
Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents:
4254
diff
changeset
|
130 case 3: /* UTF-8 */ |
5980 | 131 len = FFMIN(taglen, dstlen); |
5016
eb6dd7717805
Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents:
4254
diff
changeset
|
132 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
|
133 dst[len] = 0; |
eb6dd7717805
Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents:
4254
diff
changeset
|
134 break; |
5231 | 135 default: |
136 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
|
137 } |
eb6dd7717805
Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents:
4254
diff
changeset
|
138 |
5265
79be5a6fd62f
id3v2: Export all text information frames with correct names.
ramiro
parents:
5264
diff
changeset
|
139 if (!(strcmp(key, "TCON") && strcmp(key, "TCO")) |
5016
eb6dd7717805
Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents:
4254
diff
changeset
|
140 && (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
|
141 && genre <= ID3v1_GENRE_MAX) |
5265
79be5a6fd62f
id3v2: Export all text information frames with correct names.
ramiro
parents:
5264
diff
changeset
|
142 val = ff_id3v1_genre_str[genre]; |
79be5a6fd62f
id3v2: Export all text information frames with correct names.
ramiro
parents:
5264
diff
changeset
|
143 else if (!(strcmp(key, "TXXX") && strcmp(key, "TXX"))) { |
79be5a6fd62f
id3v2: Export all text information frames with correct names.
ramiro
parents:
5264
diff
changeset
|
144 /* dst now contains two 0-terminated strings */ |
79be5a6fd62f
id3v2: Export all text information frames with correct names.
ramiro
parents:
5264
diff
changeset
|
145 dst[dstlen] = 0; |
79be5a6fd62f
id3v2: Export all text information frames with correct names.
ramiro
parents:
5264
diff
changeset
|
146 len = strlen(dst); |
79be5a6fd62f
id3v2: Export all text information frames with correct names.
ramiro
parents:
5264
diff
changeset
|
147 key = dst; |
79be5a6fd62f
id3v2: Export all text information frames with correct names.
ramiro
parents:
5264
diff
changeset
|
148 val = dst + FFMIN(len + 1, dstlen); |
79be5a6fd62f
id3v2: Export all text information frames with correct names.
ramiro
parents:
5264
diff
changeset
|
149 } |
79be5a6fd62f
id3v2: Export all text information frames with correct names.
ramiro
parents:
5264
diff
changeset
|
150 else if (*dst) |
79be5a6fd62f
id3v2: Export all text information frames with correct names.
ramiro
parents:
5264
diff
changeset
|
151 val = dst; |
5016
eb6dd7717805
Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents:
4254
diff
changeset
|
152 |
5265
79be5a6fd62f
id3v2: Export all text information frames with correct names.
ramiro
parents:
5264
diff
changeset
|
153 if (val) |
5982
f74198942337
Mark av_metadata_set() as deprecated, and use av_metadata_set2()
stefano
parents:
5980
diff
changeset
|
154 av_metadata_set2(&s->metadata, key, val, 0); |
5016
eb6dd7717805
Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents:
4254
diff
changeset
|
155 } |
eb6dd7717805
Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents:
4254
diff
changeset
|
156 |
eb6dd7717805
Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents:
4254
diff
changeset
|
157 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
|
158 { |
eb6dd7717805
Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents:
4254
diff
changeset
|
159 int isv34, tlen; |
5265
79be5a6fd62f
id3v2: Export all text information frames with correct names.
ramiro
parents:
5264
diff
changeset
|
160 char tag[5]; |
5016
eb6dd7717805
Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents:
4254
diff
changeset
|
161 int64_t next; |
eb6dd7717805
Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents:
4254
diff
changeset
|
162 int taghdrlen; |
eb6dd7717805
Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents:
4254
diff
changeset
|
163 const char *reason; |
eb6dd7717805
Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents:
4254
diff
changeset
|
164 |
5017
1763f7d0d8d0
cosmetics: Reformat to K&R and prettyprint newly created files.
diego
parents:
5016
diff
changeset
|
165 switch (version) { |
5016
eb6dd7717805
Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents:
4254
diff
changeset
|
166 case 2: |
5017
1763f7d0d8d0
cosmetics: Reformat to K&R and prettyprint newly created files.
diego
parents:
5016
diff
changeset
|
167 if (flags & 0x40) { |
5016
eb6dd7717805
Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents:
4254
diff
changeset
|
168 reason = "compression"; |
eb6dd7717805
Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents:
4254
diff
changeset
|
169 goto error; |
eb6dd7717805
Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents:
4254
diff
changeset
|
170 } |
eb6dd7717805
Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents:
4254
diff
changeset
|
171 isv34 = 0; |
eb6dd7717805
Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents:
4254
diff
changeset
|
172 taghdrlen = 6; |
eb6dd7717805
Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents:
4254
diff
changeset
|
173 break; |
eb6dd7717805
Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents:
4254
diff
changeset
|
174 |
eb6dd7717805
Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents:
4254
diff
changeset
|
175 case 3: |
eb6dd7717805
Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents:
4254
diff
changeset
|
176 case 4: |
eb6dd7717805
Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents:
4254
diff
changeset
|
177 isv34 = 1; |
eb6dd7717805
Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents:
4254
diff
changeset
|
178 taghdrlen = 10; |
eb6dd7717805
Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents:
4254
diff
changeset
|
179 break; |
eb6dd7717805
Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents:
4254
diff
changeset
|
180 |
eb6dd7717805
Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents:
4254
diff
changeset
|
181 default: |
eb6dd7717805
Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents:
4254
diff
changeset
|
182 reason = "version"; |
eb6dd7717805
Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents:
4254
diff
changeset
|
183 goto error; |
eb6dd7717805
Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents:
4254
diff
changeset
|
184 } |
eb6dd7717805
Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents:
4254
diff
changeset
|
185 |
5017
1763f7d0d8d0
cosmetics: Reformat to K&R and prettyprint newly created files.
diego
parents:
5016
diff
changeset
|
186 if (flags & 0x80) { |
5016
eb6dd7717805
Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents:
4254
diff
changeset
|
187 reason = "unsynchronization"; |
eb6dd7717805
Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents:
4254
diff
changeset
|
188 goto error; |
eb6dd7717805
Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents:
4254
diff
changeset
|
189 } |
eb6dd7717805
Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents:
4254
diff
changeset
|
190 |
5017
1763f7d0d8d0
cosmetics: Reformat to K&R and prettyprint newly created files.
diego
parents:
5016
diff
changeset
|
191 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
|
192 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
|
193 |
5017
1763f7d0d8d0
cosmetics: Reformat to K&R and prettyprint newly created files.
diego
parents:
5016
diff
changeset
|
194 while (len >= taghdrlen) { |
1763f7d0d8d0
cosmetics: Reformat to K&R and prettyprint newly created files.
diego
parents:
5016
diff
changeset
|
195 if (isv34) { |
5265
79be5a6fd62f
id3v2: Export all text information frames with correct names.
ramiro
parents:
5264
diff
changeset
|
196 get_buffer(s->pb, tag, 4); |
79be5a6fd62f
id3v2: Export all text information frames with correct names.
ramiro
parents:
5264
diff
changeset
|
197 tag[4] = 0; |
5076
e07fb352a12c
id3v2.4.0 uses syncsafe integers for sizes of frames.
michael
parents:
5073
diff
changeset
|
198 if(version==3){ |
5077 | 199 tlen = get_be32(s->pb); |
5076
e07fb352a12c
id3v2.4.0 uses syncsafe integers for sizes of frames.
michael
parents:
5073
diff
changeset
|
200 }else |
e07fb352a12c
id3v2.4.0 uses syncsafe integers for sizes of frames.
michael
parents:
5073
diff
changeset
|
201 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
|
202 get_be16(s->pb); /* flags */ |
eb6dd7717805
Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents:
4254
diff
changeset
|
203 } else { |
5265
79be5a6fd62f
id3v2: Export all text information frames with correct names.
ramiro
parents:
5264
diff
changeset
|
204 get_buffer(s->pb, tag, 3); |
79be5a6fd62f
id3v2: Export all text information frames with correct names.
ramiro
parents:
5264
diff
changeset
|
205 tag[3] = 0; |
5073 | 206 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
|
207 } |
eb6dd7717805
Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents:
4254
diff
changeset
|
208 len -= taghdrlen + tlen; |
eb6dd7717805
Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents:
4254
diff
changeset
|
209 |
5017
1763f7d0d8d0
cosmetics: Reformat to K&R and prettyprint newly created files.
diego
parents:
5016
diff
changeset
|
210 if (len < 0) |
5016
eb6dd7717805
Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents:
4254
diff
changeset
|
211 break; |
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 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
|
214 |
5265
79be5a6fd62f
id3v2: Export all text information frames with correct names.
ramiro
parents:
5264
diff
changeset
|
215 if (tag[0] == 'T') |
79be5a6fd62f
id3v2: Export all text information frames with correct names.
ramiro
parents:
5264
diff
changeset
|
216 read_ttag(s, tlen, tag); |
5286 | 217 else if (!tag[0]) { |
218 if (tag[1]) | |
219 av_log(s, AV_LOG_WARNING, "invalid frame id, assuming padding"); | |
6333 | 220 url_fskip(s->pb, tlen); |
5286 | 221 break; |
222 } | |
5016
eb6dd7717805
Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents:
4254
diff
changeset
|
223 /* Skip to end of tag */ |
eb6dd7717805
Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents:
4254
diff
changeset
|
224 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
|
225 } |
eb6dd7717805
Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents:
4254
diff
changeset
|
226 |
6333 | 227 if (len > 0) { |
228 /* Skip padding */ | |
229 url_fskip(s->pb, len); | |
230 } | |
5017
1763f7d0d8d0
cosmetics: Reformat to K&R and prettyprint newly created files.
diego
parents:
5016
diff
changeset
|
231 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
|
232 url_fskip(s->pb, 10); |
eb6dd7717805
Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents:
4254
diff
changeset
|
233 return; |
eb6dd7717805
Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents:
4254
diff
changeset
|
234 |
eb6dd7717805
Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents:
4254
diff
changeset
|
235 error: |
eb6dd7717805
Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents:
4254
diff
changeset
|
236 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
|
237 url_fskip(s->pb, len); |
eb6dd7717805
Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents:
4254
diff
changeset
|
238 } |
5236
1403c88b1ce7
Add id3v2 metadata conversion table and use it in mp3 muxer.
cehoyos
parents:
5231
diff
changeset
|
239 |
1403c88b1ce7
Add id3v2 metadata conversion table and use it in mp3 muxer.
cehoyos
parents:
5231
diff
changeset
|
240 const AVMetadataConv ff_id3v2_metadata_conv[] = { |
1403c88b1ce7
Add id3v2 metadata conversion table and use it in mp3 muxer.
cehoyos
parents:
5231
diff
changeset
|
241 { "TALB", "album"}, |
5449
82a3916eacbd
More entries for ff_id3v2_metadata_conv from ffmbc.
michael
parents:
5448
diff
changeset
|
242 { "TAL", "album"}, |
5236
1403c88b1ce7
Add id3v2 metadata conversion table and use it in mp3 muxer.
cehoyos
parents:
5231
diff
changeset
|
243 { "TCOM", "composer"}, |
1403c88b1ce7
Add id3v2 metadata conversion table and use it in mp3 muxer.
cehoyos
parents:
5231
diff
changeset
|
244 { "TCON", "genre"}, |
5449
82a3916eacbd
More entries for ff_id3v2_metadata_conv from ffmbc.
michael
parents:
5448
diff
changeset
|
245 { "TCO", "genre"}, |
5236
1403c88b1ce7
Add id3v2 metadata conversion table and use it in mp3 muxer.
cehoyos
parents:
5231
diff
changeset
|
246 { "TCOP", "copyright"}, |
1403c88b1ce7
Add id3v2 metadata conversion table and use it in mp3 muxer.
cehoyos
parents:
5231
diff
changeset
|
247 { "TDRL", "date"}, |
5618
27fd77f20a89
Add a list of generic tags and change demuxers to follow it.
pross
parents:
5449
diff
changeset
|
248 { "TDRC", "date"}, |
27fd77f20a89
Add a list of generic tags and change demuxers to follow it.
pross
parents:
5449
diff
changeset
|
249 { "TENC", "encoded_by"}, |
27fd77f20a89
Add a list of generic tags and change demuxers to follow it.
pross
parents:
5449
diff
changeset
|
250 { "TEN", "encoded_by"}, |
5236
1403c88b1ce7
Add id3v2 metadata conversion table and use it in mp3 muxer.
cehoyos
parents:
5231
diff
changeset
|
251 { "TIT2", "title"}, |
5449
82a3916eacbd
More entries for ff_id3v2_metadata_conv from ffmbc.
michael
parents:
5448
diff
changeset
|
252 { "TT2", "title"}, |
5236
1403c88b1ce7
Add id3v2 metadata conversion table and use it in mp3 muxer.
cehoyos
parents:
5231
diff
changeset
|
253 { "TLAN", "language"}, |
5448 | 254 { "TPE1", "artist"}, |
5449
82a3916eacbd
More entries for ff_id3v2_metadata_conv from ffmbc.
michael
parents:
5448
diff
changeset
|
255 { "TP1", "artist"}, |
5618
27fd77f20a89
Add a list of generic tags and change demuxers to follow it.
pross
parents:
5449
diff
changeset
|
256 { "TPE2", "album_artist"}, |
27fd77f20a89
Add a list of generic tags and change demuxers to follow it.
pross
parents:
5449
diff
changeset
|
257 { "TP2", "album_artist"}, |
27fd77f20a89
Add a list of generic tags and change demuxers to follow it.
pross
parents:
5449
diff
changeset
|
258 { "TPE3", "performer"}, |
27fd77f20a89
Add a list of generic tags and change demuxers to follow it.
pross
parents:
5449
diff
changeset
|
259 { "TP3", "performer"}, |
5236
1403c88b1ce7
Add id3v2 metadata conversion table and use it in mp3 muxer.
cehoyos
parents:
5231
diff
changeset
|
260 { "TPOS", "disc"}, |
1403c88b1ce7
Add id3v2 metadata conversion table and use it in mp3 muxer.
cehoyos
parents:
5231
diff
changeset
|
261 { "TPUB", "publisher"}, |
1403c88b1ce7
Add id3v2 metadata conversion table and use it in mp3 muxer.
cehoyos
parents:
5231
diff
changeset
|
262 { "TRCK", "track"}, |
5449
82a3916eacbd
More entries for ff_id3v2_metadata_conv from ffmbc.
michael
parents:
5448
diff
changeset
|
263 { "TRK", "track"}, |
5618
27fd77f20a89
Add a list of generic tags and change demuxers to follow it.
pross
parents:
5449
diff
changeset
|
264 { "TSOA", "album-sort"}, |
27fd77f20a89
Add a list of generic tags and change demuxers to follow it.
pross
parents:
5449
diff
changeset
|
265 { "TSOP", "artist-sort"}, |
27fd77f20a89
Add a list of generic tags and change demuxers to follow it.
pross
parents:
5449
diff
changeset
|
266 { "TSOT", "title-sort"}, |
27fd77f20a89
Add a list of generic tags and change demuxers to follow it.
pross
parents:
5449
diff
changeset
|
267 { "TSSE", "encoder"}, |
5236
1403c88b1ce7
Add id3v2 metadata conversion table and use it in mp3 muxer.
cehoyos
parents:
5231
diff
changeset
|
268 { 0 } |
1403c88b1ce7
Add id3v2 metadata conversion table and use it in mp3 muxer.
cehoyos
parents:
5231
diff
changeset
|
269 }; |
5264 | 270 |
271 const char ff_id3v2_tags[][4] = { | |
272 "TALB", "TBPM", "TCOM", "TCON", "TCOP", "TDEN", "TDLY", "TDOR", "TDRC", | |
273 "TDRL", "TDTG", "TENC", "TEXT", "TFLT", "TIPL", "TIT1", "TIT2", "TIT3", | |
274 "TKEY", "TLAN", "TLEN", "TMCL", "TMED", "TMOO", "TOAL", "TOFN", "TOLY", | |
275 "TOPE", "TOWN", "TPE1", "TPE2", "TPE3", "TPE4", "TPOS", "TPRO", "TPUB", | |
276 "TRCK", "TRSN", "TRSO", "TSOA", "TSOP", "TSOT", "TSRC", "TSSE", "TSST", | |
277 { 0 }, | |
278 }; |