Mercurial > libavformat.hg
annotate id3v2.c @ 6479:3e7384f85f1d libavformat
tcp: Check both wfds and efds when waiting for the result from connect
On windows, a connection failure doesn't trigger wfds as it does on unix.
This fixes issue 2237, based on code by yeyingxian.
author | mstorsjo |
---|---|
date | Tue, 21 Sep 2010 20:17:34 +0000 |
parents | 1a62da965733 |
children |
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]; |
6473
1a62da965733
Read all id3v2 tags at the beginning of mp3 files.
cehoyos
parents:
6386
diff
changeset
|
56 int found_header; |
1a62da965733
Read all id3v2 tags at the beginning of mp3 files.
cehoyos
parents:
6386
diff
changeset
|
57 int64_t off; |
5045
9ed3c88ed9ba
Move id3v1/id3v2 handling code from mp3.c to id3v[12].c.
diego
parents:
5018
diff
changeset
|
58 |
6473
1a62da965733
Read all id3v2 tags at the beginning of mp3 files.
cehoyos
parents:
6386
diff
changeset
|
59 do { |
1a62da965733
Read all id3v2 tags at the beginning of mp3 files.
cehoyos
parents:
6386
diff
changeset
|
60 /* save the current offset in case there's nothing to read/skip */ |
1a62da965733
Read all id3v2 tags at the beginning of mp3 files.
cehoyos
parents:
6386
diff
changeset
|
61 off = url_ftell(s->pb); |
5045
9ed3c88ed9ba
Move id3v1/id3v2 handling code from mp3.c to id3v[12].c.
diego
parents:
5018
diff
changeset
|
62 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
|
63 if (ret != ID3v2_HEADER_SIZE) |
9ed3c88ed9ba
Move id3v1/id3v2 handling code from mp3.c to id3v[12].c.
diego
parents:
5018
diff
changeset
|
64 return; |
6473
1a62da965733
Read all id3v2 tags at the beginning of mp3 files.
cehoyos
parents:
6386
diff
changeset
|
65 found_header = ff_id3v2_match(buf, magic); |
1a62da965733
Read all id3v2 tags at the beginning of mp3 files.
cehoyos
parents:
6386
diff
changeset
|
66 if (found_header) { |
5045
9ed3c88ed9ba
Move id3v1/id3v2 handling code from mp3.c to id3v[12].c.
diego
parents:
5018
diff
changeset
|
67 /* parse ID3v2 header */ |
9ed3c88ed9ba
Move id3v1/id3v2 handling code from mp3.c to id3v[12].c.
diego
parents:
5018
diff
changeset
|
68 len = ((buf[6] & 0x7f) << 21) | |
9ed3c88ed9ba
Move id3v1/id3v2 handling code from mp3.c to id3v[12].c.
diego
parents:
5018
diff
changeset
|
69 ((buf[7] & 0x7f) << 14) | |
9ed3c88ed9ba
Move id3v1/id3v2 handling code from mp3.c to id3v[12].c.
diego
parents:
5018
diff
changeset
|
70 ((buf[8] & 0x7f) << 7) | |
9ed3c88ed9ba
Move id3v1/id3v2 handling code from mp3.c to id3v[12].c.
diego
parents:
5018
diff
changeset
|
71 (buf[9] & 0x7f); |
9ed3c88ed9ba
Move id3v1/id3v2 handling code from mp3.c to id3v[12].c.
diego
parents:
5018
diff
changeset
|
72 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
|
73 } else { |
6473
1a62da965733
Read all id3v2 tags at the beginning of mp3 files.
cehoyos
parents:
6386
diff
changeset
|
74 url_fseek(s->pb, off, SEEK_SET); |
5045
9ed3c88ed9ba
Move id3v1/id3v2 handling code from mp3.c to id3v[12].c.
diego
parents:
5018
diff
changeset
|
75 } |
6473
1a62da965733
Read all id3v2 tags at the beginning of mp3 files.
cehoyos
parents:
6386
diff
changeset
|
76 } while (found_header); |
5045
9ed3c88ed9ba
Move id3v1/id3v2 handling code from mp3.c to id3v[12].c.
diego
parents:
5018
diff
changeset
|
77 } |
9ed3c88ed9ba
Move id3v1/id3v2 handling code from mp3.c to id3v[12].c.
diego
parents:
5018
diff
changeset
|
78 |
5016
eb6dd7717805
Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents:
4254
diff
changeset
|
79 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
|
80 { |
5017
1763f7d0d8d0
cosmetics: Reformat to K&R and prettyprint newly created files.
diego
parents:
5016
diff
changeset
|
81 int v = 0; |
1763f7d0d8d0
cosmetics: Reformat to K&R and prettyprint newly created files.
diego
parents:
5016
diff
changeset
|
82 while (len--) |
1763f7d0d8d0
cosmetics: Reformat to K&R and prettyprint newly created files.
diego
parents:
5016
diff
changeset
|
83 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
|
84 return v; |
eb6dd7717805
Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents:
4254
diff
changeset
|
85 } |
eb6dd7717805
Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents:
4254
diff
changeset
|
86 |
6386 | 87 static void read_ttag(AVFormatContext *s, ByteIOContext *pb, int taglen, const char *key) |
5016
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 char *q, dst[512]; |
5265
79be5a6fd62f
id3v2: Export all text information frames with correct names.
ramiro
parents:
5264
diff
changeset
|
90 const char *val = NULL; |
5016
eb6dd7717805
Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents:
4254
diff
changeset
|
91 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
|
92 unsigned genre; |
5231 | 93 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
|
94 |
5017
1763f7d0d8d0
cosmetics: Reformat to K&R and prettyprint newly created files.
diego
parents:
5016
diff
changeset
|
95 dst[0] = 0; |
1763f7d0d8d0
cosmetics: Reformat to K&R and prettyprint newly created files.
diego
parents:
5016
diff
changeset
|
96 if (taglen < 1) |
5016
eb6dd7717805
Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents:
4254
diff
changeset
|
97 return; |
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 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
|
100 |
6386 | 101 switch (get_byte(pb)) { /* encoding type */ |
5016
eb6dd7717805
Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents:
4254
diff
changeset
|
102 |
eb6dd7717805
Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents:
4254
diff
changeset
|
103 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
|
104 q = dst; |
5229
4a01407f678d
id3v2: check for enough space to write full UTF-8 characters.
diego
parents:
5077
diff
changeset
|
105 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
|
106 uint8_t tmp; |
6386 | 107 PUT_UTF8(get_byte(pb), tmp, *q++ = tmp;) |
5016
eb6dd7717805
Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents:
4254
diff
changeset
|
108 } |
5230 | 109 *q = 0; |
5016
eb6dd7717805
Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents:
4254
diff
changeset
|
110 break; |
eb6dd7717805
Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents:
4254
diff
changeset
|
111 |
5231 | 112 case 1: /* UTF-16 with BOM */ |
113 taglen -= 2; | |
6386 | 114 switch (get_be16(pb)) { |
5231 | 115 case 0xfffe: |
116 get = get_le16; | |
117 case 0xfeff: | |
118 break; | |
119 default: | |
120 av_log(s, AV_LOG_ERROR, "Incorrect BOM value in tag %s.\n", key); | |
121 return; | |
122 } | |
123 // fall-through | |
124 | |
125 case 2: /* UTF-16BE without BOM */ | |
126 q = dst; | |
127 while (taglen > 1 && q - dst < dstlen - 7) { | |
128 uint32_t ch; | |
129 uint8_t tmp; | |
130 | |
6386 | 131 GET_UTF16(ch, ((taglen -= 2) >= 0 ? get(pb) : 0), break;) |
5231 | 132 PUT_UTF8(ch, tmp, *q++ = tmp;) |
133 } | |
134 *q = 0; | |
135 break; | |
136 | |
5016
eb6dd7717805
Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents:
4254
diff
changeset
|
137 case 3: /* UTF-8 */ |
5980 | 138 len = FFMIN(taglen, dstlen); |
6386 | 139 get_buffer(pb, dst, len); |
5016
eb6dd7717805
Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents:
4254
diff
changeset
|
140 dst[len] = 0; |
eb6dd7717805
Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents:
4254
diff
changeset
|
141 break; |
5231 | 142 default: |
143 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
|
144 } |
eb6dd7717805
Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents:
4254
diff
changeset
|
145 |
5265
79be5a6fd62f
id3v2: Export all text information frames with correct names.
ramiro
parents:
5264
diff
changeset
|
146 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
|
147 && (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
|
148 && genre <= ID3v1_GENRE_MAX) |
5265
79be5a6fd62f
id3v2: Export all text information frames with correct names.
ramiro
parents:
5264
diff
changeset
|
149 val = ff_id3v1_genre_str[genre]; |
79be5a6fd62f
id3v2: Export all text information frames with correct names.
ramiro
parents:
5264
diff
changeset
|
150 else if (!(strcmp(key, "TXXX") && strcmp(key, "TXX"))) { |
79be5a6fd62f
id3v2: Export all text information frames with correct names.
ramiro
parents:
5264
diff
changeset
|
151 /* dst now contains two 0-terminated strings */ |
79be5a6fd62f
id3v2: Export all text information frames with correct names.
ramiro
parents:
5264
diff
changeset
|
152 dst[dstlen] = 0; |
79be5a6fd62f
id3v2: Export all text information frames with correct names.
ramiro
parents:
5264
diff
changeset
|
153 len = strlen(dst); |
79be5a6fd62f
id3v2: Export all text information frames with correct names.
ramiro
parents:
5264
diff
changeset
|
154 key = dst; |
79be5a6fd62f
id3v2: Export all text information frames with correct names.
ramiro
parents:
5264
diff
changeset
|
155 val = dst + FFMIN(len + 1, dstlen); |
79be5a6fd62f
id3v2: Export all text information frames with correct names.
ramiro
parents:
5264
diff
changeset
|
156 } |
79be5a6fd62f
id3v2: Export all text information frames with correct names.
ramiro
parents:
5264
diff
changeset
|
157 else if (*dst) |
79be5a6fd62f
id3v2: Export all text information frames with correct names.
ramiro
parents:
5264
diff
changeset
|
158 val = dst; |
5016
eb6dd7717805
Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents:
4254
diff
changeset
|
159 |
5265
79be5a6fd62f
id3v2: Export all text information frames with correct names.
ramiro
parents:
5264
diff
changeset
|
160 if (val) |
5982
f74198942337
Mark av_metadata_set() as deprecated, and use av_metadata_set2()
stefano
parents:
5980
diff
changeset
|
161 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
|
162 } |
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 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
|
165 { |
6386 | 166 int isv34, tlen, unsync; |
5265
79be5a6fd62f
id3v2: Export all text information frames with correct names.
ramiro
parents:
5264
diff
changeset
|
167 char tag[5]; |
5016
eb6dd7717805
Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents:
4254
diff
changeset
|
168 int64_t next; |
eb6dd7717805
Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents:
4254
diff
changeset
|
169 int taghdrlen; |
eb6dd7717805
Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents:
4254
diff
changeset
|
170 const char *reason; |
6386 | 171 ByteIOContext pb; |
172 unsigned char *buffer = NULL; | |
173 int buffer_size = 0; | |
5016
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 switch (version) { |
5016
eb6dd7717805
Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents:
4254
diff
changeset
|
176 case 2: |
5017
1763f7d0d8d0
cosmetics: Reformat to K&R and prettyprint newly created files.
diego
parents:
5016
diff
changeset
|
177 if (flags & 0x40) { |
5016
eb6dd7717805
Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents:
4254
diff
changeset
|
178 reason = "compression"; |
eb6dd7717805
Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents:
4254
diff
changeset
|
179 goto error; |
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 isv34 = 0; |
eb6dd7717805
Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents:
4254
diff
changeset
|
182 taghdrlen = 6; |
eb6dd7717805
Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents:
4254
diff
changeset
|
183 break; |
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 case 3: |
eb6dd7717805
Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents:
4254
diff
changeset
|
186 case 4: |
eb6dd7717805
Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents:
4254
diff
changeset
|
187 isv34 = 1; |
eb6dd7717805
Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents:
4254
diff
changeset
|
188 taghdrlen = 10; |
eb6dd7717805
Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents:
4254
diff
changeset
|
189 break; |
eb6dd7717805
Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents:
4254
diff
changeset
|
190 |
eb6dd7717805
Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents:
4254
diff
changeset
|
191 default: |
eb6dd7717805
Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents:
4254
diff
changeset
|
192 reason = "version"; |
eb6dd7717805
Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents:
4254
diff
changeset
|
193 goto error; |
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 |
6386 | 196 unsync = flags & 0x80; |
5016
eb6dd7717805
Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents:
4254
diff
changeset
|
197 |
5017
1763f7d0d8d0
cosmetics: Reformat to K&R and prettyprint newly created files.
diego
parents:
5016
diff
changeset
|
198 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
|
199 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
|
200 |
5017
1763f7d0d8d0
cosmetics: Reformat to K&R and prettyprint newly created files.
diego
parents:
5016
diff
changeset
|
201 while (len >= taghdrlen) { |
6386 | 202 unsigned int tflags; |
203 int tunsync = 0; | |
204 | |
5017
1763f7d0d8d0
cosmetics: Reformat to K&R and prettyprint newly created files.
diego
parents:
5016
diff
changeset
|
205 if (isv34) { |
5265
79be5a6fd62f
id3v2: Export all text information frames with correct names.
ramiro
parents:
5264
diff
changeset
|
206 get_buffer(s->pb, tag, 4); |
79be5a6fd62f
id3v2: Export all text information frames with correct names.
ramiro
parents:
5264
diff
changeset
|
207 tag[4] = 0; |
5076
e07fb352a12c
id3v2.4.0 uses syncsafe integers for sizes of frames.
michael
parents:
5073
diff
changeset
|
208 if(version==3){ |
5077 | 209 tlen = get_be32(s->pb); |
5076
e07fb352a12c
id3v2.4.0 uses syncsafe integers for sizes of frames.
michael
parents:
5073
diff
changeset
|
210 }else |
e07fb352a12c
id3v2.4.0 uses syncsafe integers for sizes of frames.
michael
parents:
5073
diff
changeset
|
211 tlen = get_size(s->pb, 4); |
6386 | 212 tflags = get_be16(s->pb); |
213 tunsync = tflags & 0x02; | |
5016
eb6dd7717805
Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents:
4254
diff
changeset
|
214 } else { |
5265
79be5a6fd62f
id3v2: Export all text information frames with correct names.
ramiro
parents:
5264
diff
changeset
|
215 get_buffer(s->pb, tag, 3); |
79be5a6fd62f
id3v2: Export all text information frames with correct names.
ramiro
parents:
5264
diff
changeset
|
216 tag[3] = 0; |
5073 | 217 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
|
218 } |
eb6dd7717805
Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents:
4254
diff
changeset
|
219 len -= taghdrlen + tlen; |
eb6dd7717805
Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents:
4254
diff
changeset
|
220 |
5017
1763f7d0d8d0
cosmetics: Reformat to K&R and prettyprint newly created files.
diego
parents:
5016
diff
changeset
|
221 if (len < 0) |
5016
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 |
eb6dd7717805
Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents:
4254
diff
changeset
|
224 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
|
225 |
6386 | 226 if (tag[0] == 'T') { |
227 if (unsync || tunsync) { | |
228 int i, j; | |
229 av_fast_malloc(&buffer, &buffer_size, tlen); | |
230 for (i = 0, j = 0; i < tlen; i++, j++) { | |
231 buffer[j] = get_byte(s->pb); | |
232 if (j > 0 && !buffer[j] && buffer[j - 1] == 0xff) { | |
233 /* Unsynchronised byte, skip it */ | |
234 j--; | |
235 } | |
236 } | |
237 init_put_byte(&pb, buffer, j, 0, NULL, NULL, NULL, NULL); | |
238 read_ttag(s, &pb, j, tag); | |
239 } else { | |
240 read_ttag(s, s->pb, tlen, tag); | |
241 } | |
242 } | |
5286 | 243 else if (!tag[0]) { |
244 if (tag[1]) | |
245 av_log(s, AV_LOG_WARNING, "invalid frame id, assuming padding"); | |
6333 | 246 url_fskip(s->pb, tlen); |
5286 | 247 break; |
248 } | |
5016
eb6dd7717805
Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents:
4254
diff
changeset
|
249 /* Skip to end of tag */ |
eb6dd7717805
Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents:
4254
diff
changeset
|
250 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
|
251 } |
eb6dd7717805
Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents:
4254
diff
changeset
|
252 |
6333 | 253 if (len > 0) { |
254 /* Skip padding */ | |
255 url_fskip(s->pb, len); | |
256 } | |
5017
1763f7d0d8d0
cosmetics: Reformat to K&R and prettyprint newly created files.
diego
parents:
5016
diff
changeset
|
257 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
|
258 url_fskip(s->pb, 10); |
6386 | 259 |
260 av_free(buffer); | |
5016
eb6dd7717805
Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents:
4254
diff
changeset
|
261 return; |
eb6dd7717805
Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents:
4254
diff
changeset
|
262 |
eb6dd7717805
Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents:
4254
diff
changeset
|
263 error: |
eb6dd7717805
Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents:
4254
diff
changeset
|
264 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
|
265 url_fskip(s->pb, len); |
6386 | 266 av_free(buffer); |
5016
eb6dd7717805
Move id3v2 parsing code from mp3.c to id3v2.h and id3v2.c.
diego
parents:
4254
diff
changeset
|
267 } |
5236
1403c88b1ce7
Add id3v2 metadata conversion table and use it in mp3 muxer.
cehoyos
parents:
5231
diff
changeset
|
268 |
1403c88b1ce7
Add id3v2 metadata conversion table and use it in mp3 muxer.
cehoyos
parents:
5231
diff
changeset
|
269 const AVMetadataConv ff_id3v2_metadata_conv[] = { |
1403c88b1ce7
Add id3v2 metadata conversion table and use it in mp3 muxer.
cehoyos
parents:
5231
diff
changeset
|
270 { "TALB", "album"}, |
5449
82a3916eacbd
More entries for ff_id3v2_metadata_conv from ffmbc.
michael
parents:
5448
diff
changeset
|
271 { "TAL", "album"}, |
5236
1403c88b1ce7
Add id3v2 metadata conversion table and use it in mp3 muxer.
cehoyos
parents:
5231
diff
changeset
|
272 { "TCOM", "composer"}, |
1403c88b1ce7
Add id3v2 metadata conversion table and use it in mp3 muxer.
cehoyos
parents:
5231
diff
changeset
|
273 { "TCON", "genre"}, |
5449
82a3916eacbd
More entries for ff_id3v2_metadata_conv from ffmbc.
michael
parents:
5448
diff
changeset
|
274 { "TCO", "genre"}, |
5236
1403c88b1ce7
Add id3v2 metadata conversion table and use it in mp3 muxer.
cehoyos
parents:
5231
diff
changeset
|
275 { "TCOP", "copyright"}, |
1403c88b1ce7
Add id3v2 metadata conversion table and use it in mp3 muxer.
cehoyos
parents:
5231
diff
changeset
|
276 { "TDRL", "date"}, |
5618
27fd77f20a89
Add a list of generic tags and change demuxers to follow it.
pross
parents:
5449
diff
changeset
|
277 { "TDRC", "date"}, |
27fd77f20a89
Add a list of generic tags and change demuxers to follow it.
pross
parents:
5449
diff
changeset
|
278 { "TENC", "encoded_by"}, |
27fd77f20a89
Add a list of generic tags and change demuxers to follow it.
pross
parents:
5449
diff
changeset
|
279 { "TEN", "encoded_by"}, |
5236
1403c88b1ce7
Add id3v2 metadata conversion table and use it in mp3 muxer.
cehoyos
parents:
5231
diff
changeset
|
280 { "TIT2", "title"}, |
5449
82a3916eacbd
More entries for ff_id3v2_metadata_conv from ffmbc.
michael
parents:
5448
diff
changeset
|
281 { "TT2", "title"}, |
5236
1403c88b1ce7
Add id3v2 metadata conversion table and use it in mp3 muxer.
cehoyos
parents:
5231
diff
changeset
|
282 { "TLAN", "language"}, |
5448 | 283 { "TPE1", "artist"}, |
5449
82a3916eacbd
More entries for ff_id3v2_metadata_conv from ffmbc.
michael
parents:
5448
diff
changeset
|
284 { "TP1", "artist"}, |
5618
27fd77f20a89
Add a list of generic tags and change demuxers to follow it.
pross
parents:
5449
diff
changeset
|
285 { "TPE2", "album_artist"}, |
27fd77f20a89
Add a list of generic tags and change demuxers to follow it.
pross
parents:
5449
diff
changeset
|
286 { "TP2", "album_artist"}, |
27fd77f20a89
Add a list of generic tags and change demuxers to follow it.
pross
parents:
5449
diff
changeset
|
287 { "TPE3", "performer"}, |
27fd77f20a89
Add a list of generic tags and change demuxers to follow it.
pross
parents:
5449
diff
changeset
|
288 { "TP3", "performer"}, |
5236
1403c88b1ce7
Add id3v2 metadata conversion table and use it in mp3 muxer.
cehoyos
parents:
5231
diff
changeset
|
289 { "TPOS", "disc"}, |
1403c88b1ce7
Add id3v2 metadata conversion table and use it in mp3 muxer.
cehoyos
parents:
5231
diff
changeset
|
290 { "TPUB", "publisher"}, |
1403c88b1ce7
Add id3v2 metadata conversion table and use it in mp3 muxer.
cehoyos
parents:
5231
diff
changeset
|
291 { "TRCK", "track"}, |
5449
82a3916eacbd
More entries for ff_id3v2_metadata_conv from ffmbc.
michael
parents:
5448
diff
changeset
|
292 { "TRK", "track"}, |
5618
27fd77f20a89
Add a list of generic tags and change demuxers to follow it.
pross
parents:
5449
diff
changeset
|
293 { "TSOA", "album-sort"}, |
27fd77f20a89
Add a list of generic tags and change demuxers to follow it.
pross
parents:
5449
diff
changeset
|
294 { "TSOP", "artist-sort"}, |
27fd77f20a89
Add a list of generic tags and change demuxers to follow it.
pross
parents:
5449
diff
changeset
|
295 { "TSOT", "title-sort"}, |
27fd77f20a89
Add a list of generic tags and change demuxers to follow it.
pross
parents:
5449
diff
changeset
|
296 { "TSSE", "encoder"}, |
5236
1403c88b1ce7
Add id3v2 metadata conversion table and use it in mp3 muxer.
cehoyos
parents:
5231
diff
changeset
|
297 { 0 } |
1403c88b1ce7
Add id3v2 metadata conversion table and use it in mp3 muxer.
cehoyos
parents:
5231
diff
changeset
|
298 }; |
5264 | 299 |
300 const char ff_id3v2_tags[][4] = { | |
301 "TALB", "TBPM", "TCOM", "TCON", "TCOP", "TDEN", "TDLY", "TDOR", "TDRC", | |
302 "TDRL", "TDTG", "TENC", "TEXT", "TFLT", "TIPL", "TIT1", "TIT2", "TIT3", | |
303 "TKEY", "TLAN", "TLEN", "TMCL", "TMED", "TMOO", "TOAL", "TOFN", "TOLY", | |
304 "TOPE", "TOWN", "TPE1", "TPE2", "TPE3", "TPE4", "TPOS", "TPRO", "TPUB", | |
305 "TRCK", "TRSN", "TRSO", "TSOA", "TSOP", "TSOT", "TSRC", "TSSE", "TSST", | |
306 { 0 }, | |
307 }; |