lavf: move CodecMime from matroska.h to internal.h
[libav.git] / libavformat / id3v2.c
CommitLineData
2ea512a6
AC
1/*
2 * ID3v2 header parser
3 * Copyright (c) 2003 Fabrice Bellard
4 *
2912e87a 5 * This file is part of Libav.
2ea512a6 6 *
2912e87a 7 * Libav is free software; you can redistribute it and/or
2ea512a6
AC
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
2912e87a 12 * Libav is distributed in the hope that it will be useful,
2ea512a6
AC
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
2912e87a 18 * License along with Libav; if not, write to the Free Software
2ea512a6
AC
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21
22#include "id3v2.h"
75411182
PD
23#include "id3v1.h"
24#include "libavutil/avstring.h"
3a1350e8 25#include "libavutil/intreadwrite.h"
d2d67e42 26#include "libavutil/dict.h"
e731b8d8 27#include "avio_internal.h"
2ea512a6 28
3b78c180
DB
29const AVMetadataConv ff_id3v2_34_metadata_conv[] = {
30 { "TALB", "album"},
31 { "TCOM", "composer"},
32 { "TCON", "genre"},
33 { "TCOP", "copyright"},
34 { "TENC", "encoded_by"},
35 { "TIT2", "title"},
36 { "TLAN", "language"},
37 { "TPE1", "artist"},
38 { "TPE2", "album_artist"},
39 { "TPE3", "performer"},
40 { "TPOS", "disc"},
41 { "TPUB", "publisher"},
42 { "TRCK", "track"},
43 { "TSSE", "encoder"},
44 { 0 }
45};
46
47const AVMetadataConv ff_id3v2_4_metadata_conv[] = {
48 { "TDRL", "date"},
49 { "TDRC", "date"},
50 { "TDEN", "creation_time"},
51 { "TSOA", "album-sort"},
52 { "TSOP", "artist-sort"},
53 { "TSOT", "title-sort"},
54 { 0 }
55};
56
c4a37885 57static const AVMetadataConv id3v2_2_metadata_conv[] = {
3b78c180
DB
58 { "TAL", "album"},
59 { "TCO", "genre"},
60 { "TT2", "title"},
61 { "TEN", "encoded_by"},
62 { "TP1", "artist"},
63 { "TP2", "album_artist"},
64 { "TP3", "performer"},
65 { "TRK", "track"},
66 { 0 }
67};
68
69
70const char ff_id3v2_tags[][4] = {
71 "TALB", "TBPM", "TCOM", "TCON", "TCOP", "TDLY", "TENC", "TEXT",
72 "TFLT", "TIT1", "TIT2", "TIT3", "TKEY", "TLAN", "TLEN", "TMED",
73 "TOAL", "TOFN", "TOLY", "TOPE", "TOWN", "TPE1", "TPE2", "TPE3",
74 "TPE4", "TPOS", "TPUB", "TRCK", "TRSN", "TRSO", "TSRC", "TSSE",
75 { 0 },
76};
77
78const char ff_id3v2_4_tags[][4] = {
79 "TDEN", "TDOR", "TDRC", "TDRL", "TDTG", "TIPL", "TMCL", "TMOO",
80 "TPRO", "TSOA", "TSOP", "TSOT", "TSST",
81 { 0 },
82};
83
84const char ff_id3v2_3_tags[][4] = {
85 "TDAT", "TIME", "TORY", "TRDA", "TSIZ", "TYER",
86 { 0 },
87};
88
3a1350e8 89int ff_id3v2_match(const uint8_t *buf, const char * magic)
2ea512a6 90{
3a1350e8
MK
91 return buf[0] == magic[0] &&
92 buf[1] == magic[1] &&
93 buf[2] == magic[2] &&
7d7b8c32
DB
94 buf[3] != 0xff &&
95 buf[4] != 0xff &&
96 (buf[6] & 0x80) == 0 &&
97 (buf[7] & 0x80) == 0 &&
98 (buf[8] & 0x80) == 0 &&
1d4b1bf2 99 (buf[9] & 0x80) == 0;
2ea512a6 100}
ac3ef4a4
AC
101
102int ff_id3v2_tag_len(const uint8_t * buf)
103{
104 int len = ((buf[6] & 0x7f) << 21) +
7d7b8c32
DB
105 ((buf[7] & 0x7f) << 14) +
106 ((buf[8] & 0x7f) << 7) +
107 (buf[9] & 0x7f) +
108 ID3v2_HEADER_SIZE;
ac3ef4a4
AC
109 if (buf[5] & 0x10)
110 len += ID3v2_HEADER_SIZE;
111 return len;
112}
75411182 113
ae628ec1 114static unsigned int get_size(AVIOContext *s, int len)
75411182 115{
7d7b8c32
DB
116 int v = 0;
117 while (len--)
b7effd4e 118 v = (v << 7) + (avio_r8(s) & 0x7F);
75411182
PD
119 return v;
120}
121
7a019dff
DG
122/**
123 * Free GEOB type extra metadata.
124 */
ec22979a 125static void free_geobtag(void *obj)
75411182 126{
ec22979a 127 ID3v2ExtraMetaGEOB *geob = obj;
7a019dff
DG
128 av_free(geob->mime_type);
129 av_free(geob->file_name);
130 av_free(geob->description);
131 av_free(geob->data);
132 av_free(geob);
133}
75411182 134
7a019dff
DG
135/**
136 * Decode characters to UTF-8 according to encoding type. The decoded buffer is
d2961e4e
AK
137 * always null terminated. Stop reading when either *maxread bytes are read from
138 * pb or U+0000 character is found.
7a019dff
DG
139 *
140 * @param dst Pointer where the address of the buffer with the decoded bytes is
141 * stored. Buffer must be freed by caller.
7a019dff
DG
142 * @param maxread Pointer to maximum number of characters to read from the
143 * AVIOContext. After execution the value is decremented by the number of bytes
144 * actually read.
da9cea77 145 * @returns 0 if no error occurred, dst is uninitialized on error
7a019dff
DG
146 */
147static int decode_str(AVFormatContext *s, AVIOContext *pb, int encoding,
d2961e4e 148 uint8_t **dst, int *maxread)
7a019dff 149{
d2961e4e 150 int ret;
7a019dff
DG
151 uint8_t tmp;
152 uint32_t ch = 1;
153 int left = *maxread;
154 unsigned int (*get)(AVIOContext*) = avio_rb16;
155 AVIOContext *dynbuf;
75411182 156
7a019dff
DG
157 if ((ret = avio_open_dyn_buf(&dynbuf)) < 0) {
158 av_log(s, AV_LOG_ERROR, "Error opening memory stream\n");
159 return ret;
160 }
75411182 161
7a019dff 162 switch (encoding) {
75411182 163
d66eff36 164 case ID3v2_ENCODING_ISO8859:
d2961e4e 165 while (left && ch) {
7a019dff
DG
166 ch = avio_r8(pb);
167 PUT_UTF8(ch, tmp, avio_w8(dynbuf, tmp);)
168 left--;
75411182 169 }
75411182
PD
170 break;
171
d66eff36 172 case ID3v2_ENCODING_UTF16BOM:
7a019dff
DG
173 if ((left -= 2) < 0) {
174 av_log(s, AV_LOG_ERROR, "Cannot read BOM value, input too short\n");
60df6b00 175 avio_close_dyn_buf(dynbuf, dst);
7a019dff
DG
176 av_freep(dst);
177 return AVERROR_INVALIDDATA;
178 }
b7effd4e 179 switch (avio_rb16(pb)) {
20c68378 180 case 0xfffe:
b7effd4e 181 get = avio_rl16;
20c68378
AK
182 case 0xfeff:
183 break;
184 default:
7a019dff 185 av_log(s, AV_LOG_ERROR, "Incorrect BOM value\n");
60df6b00 186 avio_close_dyn_buf(dynbuf, dst);
7a019dff
DG
187 av_freep(dst);
188 *maxread = left;
189 return AVERROR_INVALIDDATA;
20c68378
AK
190 }
191 // fall-through
192
d66eff36 193 case ID3v2_ENCODING_UTF16BE:
d2961e4e 194 while ((left > 1) && ch) {
7a019dff
DG
195 GET_UTF16(ch, ((left -= 2) >= 0 ? get(pb) : 0), break;)
196 PUT_UTF8(ch, tmp, avio_w8(dynbuf, tmp);)
20c68378 197 }
7a019dff
DG
198 if (left < 0)
199 left += 2; /* did not read last char from pb */
20c68378
AK
200 break;
201
d66eff36 202 case ID3v2_ENCODING_UTF8:
d2961e4e 203 while (left && ch) {
7a019dff
DG
204 ch = avio_r8(pb);
205 avio_w8(dynbuf, ch);
206 left--;
207 }
75411182 208 break;
20c68378 209 default:
7a019dff
DG
210 av_log(s, AV_LOG_WARNING, "Unknown encoding\n");
211 }
212
213 if (ch)
214 avio_w8(dynbuf, 0);
215
60df6b00 216 avio_close_dyn_buf(dynbuf, dst);
7a019dff
DG
217 *maxread = left;
218
219 return 0;
220}
221
222/**
223 * Parse a text tag.
224 */
225static void read_ttag(AVFormatContext *s, AVIOContext *pb, int taglen, const char *key)
226{
227 uint8_t *dst;
d2961e4e 228 int encoding, dict_flags = AV_DICT_DONT_OVERWRITE;
7a019dff
DG
229 unsigned genre;
230
231 if (taglen < 1)
232 return;
233
d2961e4e 234 encoding = avio_r8(pb);
7a019dff
DG
235 taglen--; /* account for encoding type byte */
236
d2961e4e 237 if (decode_str(s, pb, encoding, &dst, &taglen) < 0) {
7a019dff
DG
238 av_log(s, AV_LOG_ERROR, "Error reading frame %s, skipped\n", key);
239 return;
75411182
PD
240 }
241
41770abf 242 if (!(strcmp(key, "TCON") && strcmp(key, "TCO"))
75411182 243 && (sscanf(dst, "(%d)", &genre) == 1 || sscanf(dst, "%d", &genre) == 1)
d2961e4e
AK
244 && genre <= ID3v1_GENRE_MAX) {
245 av_freep(&dst);
246 dst = ff_id3v1_genre_str[genre];
247 } else if (!(strcmp(key, "TXXX") && strcmp(key, "TXX"))) {
248 /* dst now contains the key, need to get value */
41770abf 249 key = dst;
d2961e4e
AK
250 if (decode_str(s, pb, encoding, &dst, &taglen) < 0) {
251 av_log(s, AV_LOG_ERROR, "Error reading frame %s, skipped\n", key);
252 av_freep(&key);
253 return;
254 }
255 dict_flags |= AV_DICT_DONT_STRDUP_VAL | AV_DICT_DONT_STRDUP_KEY;
41770abf
AK
256 }
257 else if (*dst)
d2961e4e 258 dict_flags |= AV_DICT_DONT_STRDUP_VAL;
7a019dff 259
d2961e4e
AK
260 if (dst)
261 av_dict_set(&s->metadata, key, dst, dict_flags);
7a019dff
DG
262}
263
264/**
265 * Parse GEOB tag into a ID3v2ExtraMetaGEOB struct.
266 */
267static void read_geobtag(AVFormatContext *s, AVIOContext *pb, int taglen, char *tag, ID3v2ExtraMeta **extra_meta)
268{
269 ID3v2ExtraMetaGEOB *geob_data = NULL;
270 ID3v2ExtraMeta *new_extra = NULL;
271 char encoding;
272 unsigned int len;
273
274 if (taglen < 1)
275 return;
276
277 geob_data = av_mallocz(sizeof(ID3v2ExtraMetaGEOB));
278 if (!geob_data) {
279 av_log(s, AV_LOG_ERROR, "Failed to alloc %zu bytes\n", sizeof(ID3v2ExtraMetaGEOB));
280 return;
281 }
282
283 new_extra = av_mallocz(sizeof(ID3v2ExtraMeta));
284 if (!new_extra) {
285 av_log(s, AV_LOG_ERROR, "Failed to alloc %zu bytes\n", sizeof(ID3v2ExtraMeta));
286 goto fail;
287 }
288
289 /* read encoding type byte */
290 encoding = avio_r8(pb);
291 taglen--;
292
293 /* read MIME type (always ISO-8859) */
d2961e4e 294 if (decode_str(s, pb, ID3v2_ENCODING_ISO8859, &geob_data->mime_type, &taglen) < 0
7a019dff
DG
295 || taglen <= 0)
296 goto fail;
297
298 /* read file name */
d2961e4e 299 if (decode_str(s, pb, encoding, &geob_data->file_name, &taglen) < 0
7a019dff
DG
300 || taglen <= 0)
301 goto fail;
302
303 /* read content description */
d2961e4e 304 if (decode_str(s, pb, encoding, &geob_data->description, &taglen) < 0
7a019dff
DG
305 || taglen < 0)
306 goto fail;
307
308 if (taglen) {
309 /* save encapsulated binary data */
310 geob_data->data = av_malloc(taglen);
311 if (!geob_data->data) {
312 av_log(s, AV_LOG_ERROR, "Failed to alloc %d bytes\n", taglen);
313 goto fail;
314 }
315 if ((len = avio_read(pb, geob_data->data, taglen)) < taglen)
316 av_log(s, AV_LOG_WARNING, "Error reading GEOB frame, data truncated.\n");
317 geob_data->datasize = len;
318 } else {
319 geob_data->data = NULL;
320 geob_data->datasize = 0;
321 }
322
323 /* add data to the list */
324 new_extra->tag = "GEOB";
325 new_extra->data = geob_data;
326 new_extra->next = *extra_meta;
327 *extra_meta = new_extra;
328
329 return;
330
331fail:
332 av_log(s, AV_LOG_ERROR, "Error reading frame %s, skipped\n", tag);
333 free_geobtag(geob_data);
334 av_free(new_extra);
335 return;
75411182
PD
336}
337
56e2ac6b
AK
338static int is_number(const char *str)
339{
340 while (*str >= '0' && *str <= '9') str++;
341 return !*str;
342}
343
d2d67e42 344static AVDictionaryEntry* get_date_tag(AVDictionary *m, const char *tag)
56e2ac6b 345{
d2d67e42
AK
346 AVDictionaryEntry *t;
347 if ((t = av_dict_get(m, tag, NULL, AV_DICT_MATCH_CASE)) &&
56e2ac6b
AK
348 strlen(t->value) == 4 && is_number(t->value))
349 return t;
350 return NULL;
351}
352
d2d67e42 353static void merge_date(AVDictionary **m)
56e2ac6b 354{
d2d67e42 355 AVDictionaryEntry *t;
56e2ac6b
AK
356 char date[17] = {0}; // YYYY-MM-DD hh:mm
357
358 if (!(t = get_date_tag(*m, "TYER")) &&
359 !(t = get_date_tag(*m, "TYE")))
360 return;
361 av_strlcpy(date, t->value, 5);
d2d67e42
AK
362 av_dict_set(m, "TYER", NULL, 0);
363 av_dict_set(m, "TYE", NULL, 0);
56e2ac6b
AK
364
365 if (!(t = get_date_tag(*m, "TDAT")) &&
366 !(t = get_date_tag(*m, "TDA")))
367 goto finish;
368 snprintf(date + 4, sizeof(date) - 4, "-%.2s-%.2s", t->value + 2, t->value);
d2d67e42
AK
369 av_dict_set(m, "TDAT", NULL, 0);
370 av_dict_set(m, "TDA", NULL, 0);
56e2ac6b
AK
371
372 if (!(t = get_date_tag(*m, "TIME")) &&
373 !(t = get_date_tag(*m, "TIM")))
374 goto finish;
375 snprintf(date + 10, sizeof(date) - 10, " %.2s:%.2s", t->value, t->value + 2);
d2d67e42
AK
376 av_dict_set(m, "TIME", NULL, 0);
377 av_dict_set(m, "TIM", NULL, 0);
56e2ac6b
AK
378
379finish:
380 if (date[0])
d2d67e42 381 av_dict_set(m, "date", date, 0);
56e2ac6b
AK
382}
383
c4a37885
DB
384typedef struct ID3v2EMFunc {
385 const char *tag3;
386 const char *tag4;
387 void (*read)(AVFormatContext*, AVIOContext*, int, char*, ID3v2ExtraMeta **);
ec22979a 388 void (*free)(void *obj);
c4a37885
DB
389} ID3v2EMFunc;
390
391static const ID3v2EMFunc id3v2_extra_meta_funcs[] = {
3b78c180
DB
392 { "GEO", "GEOB", read_geobtag, free_geobtag },
393 { NULL }
394};
395
7a019dff
DG
396/**
397 * Get the corresponding ID3v2EMFunc struct for a tag.
398 * @param isv34 Determines if v2.2 or v2.3/4 strings are used
399 * @return A pointer to the ID3v2EMFunc struct if found, NULL otherwise.
400 */
401static const ID3v2EMFunc *get_extra_meta_func(const char *tag, int isv34)
402{
403 int i = 0;
c4a37885 404 while (id3v2_extra_meta_funcs[i].tag3) {
7a019dff 405 if (!memcmp(tag,
c4a37885
DB
406 (isv34 ? id3v2_extra_meta_funcs[i].tag4 :
407 id3v2_extra_meta_funcs[i].tag3),
7a019dff 408 (isv34 ? 4 : 3)))
c4a37885 409 return &id3v2_extra_meta_funcs[i];
7a019dff
DG
410 i++;
411 }
412 return NULL;
413}
414
415static void ff_id3v2_parse(AVFormatContext *s, int len, uint8_t version, uint8_t flags, ID3v2ExtraMeta **extra_meta)
75411182 416{
18bbe9df 417 int isv34, tlen, unsync;
41770abf 418 char tag[5];
bca6dee3 419 int64_t next, end = avio_tell(s->pb) + len;
75411182 420 int taghdrlen;
eb1e7f78 421 const char *reason = NULL;
ae628ec1 422 AVIOContext pb;
7a019dff 423 AVIOContext *pbx;
18bbe9df
AK
424 unsigned char *buffer = NULL;
425 int buffer_size = 0;
c780b543 426 const ID3v2EMFunc *extra_func;
75411182 427
7d7b8c32 428 switch (version) {
75411182 429 case 2:
7d7b8c32 430 if (flags & 0x40) {
75411182
PD
431 reason = "compression";
432 goto error;
433 }
434 isv34 = 0;
435 taghdrlen = 6;
436 break;
437
438 case 3:
439 case 4:
440 isv34 = 1;
441 taghdrlen = 10;
442 break;
443
444 default:
445 reason = "version";
446 goto error;
447 }
448
18bbe9df 449 unsync = flags & 0x80;
75411182 450
7d7b8c32 451 if (isv34 && flags & 0x40) /* Extended header present, just skip over it */
45a8a02a 452 avio_skip(s->pb, get_size(s->pb, 4));
75411182 453
7d7b8c32 454 while (len >= taghdrlen) {
40a5dd2f 455 unsigned int tflags = 0;
18bbe9df
AK
456 int tunsync = 0;
457
7d7b8c32 458 if (isv34) {
b7effd4e 459 avio_read(s->pb, tag, 4);
41770abf 460 tag[4] = 0;
3fd5a75b 461 if(version==3){
b7effd4e 462 tlen = avio_rb32(s->pb);
3fd5a75b
MN
463 }else
464 tlen = get_size(s->pb, 4);
b7effd4e 465 tflags = avio_rb16(s->pb);
7a07d158 466 tunsync = tflags & ID3v2_FLAG_UNSYNCH;
75411182 467 } else {
b7effd4e 468 avio_read(s->pb, tag, 3);
41770abf 469 tag[3] = 0;
b7effd4e 470 tlen = avio_rb24(s->pb);
75411182 471 }
1e18d32d 472 if (tlen < 0 || tlen > len - taghdrlen) {
c5f4c0fd 473 av_log(s, AV_LOG_WARNING, "Invalid size in frame %s, skipping the rest of tag.\n", tag);
75411182 474 break;
c5f4c0fd
AK
475 }
476 len -= taghdrlen + tlen;
a2704c97 477 next = avio_tell(s->pb) + tlen;
75411182 478
1e18d32d
AK
479 if (!tlen) {
480 if (tag[0])
481 av_log(s, AV_LOG_DEBUG, "Invalid empty frame %s, skipping.\n", tag);
482 continue;
483 }
484
a152c77f 485 if (tflags & ID3v2_FLAG_DATALEN) {
b7effd4e 486 avio_rb32(s->pb);
a152c77f
AK
487 tlen -= 4;
488 }
489
407d3d5a
AK
490 if (tflags & (ID3v2_FLAG_ENCRYPTION | ID3v2_FLAG_COMPRESSION)) {
491 av_log(s, AV_LOG_WARNING, "Skipping encrypted/compressed ID3v2 frame %s.\n", tag);
45a8a02a 492 avio_skip(s->pb, tlen);
7a019dff 493 /* check for text tag or supported special meta tag */
c780b543 494 } else if (tag[0] == 'T' || (extra_meta && (extra_func = get_extra_meta_func(tag, isv34)))) {
18bbe9df
AK
495 if (unsync || tunsync) {
496 int i, j;
497 av_fast_malloc(&buffer, &buffer_size, tlen);
86f86877
AC
498 if (!buffer) {
499 av_log(s, AV_LOG_ERROR, "Failed to alloc %d bytes\n", tlen);
500 goto seek;
501 }
18bbe9df 502 for (i = 0, j = 0; i < tlen; i++, j++) {
b7effd4e 503 buffer[j] = avio_r8(s->pb);
18bbe9df
AK
504 if (j > 0 && !buffer[j] && buffer[j - 1] == 0xff) {
505 /* Unsynchronised byte, skip it */
506 j--;
507 }
508 }
e731b8d8 509 ffio_init_context(&pb, buffer, j, 0, NULL, NULL, NULL, NULL);
7a019dff
DG
510 tlen = j;
511 pbx = &pb; // read from sync buffer
18bbe9df 512 } else {
7a019dff 513 pbx = s->pb; // read straight from input
18bbe9df 514 }
7a019dff
DG
515 if (tag[0] == 'T')
516 /* parse text tag */
517 read_ttag(s, pbx, tlen, tag);
518 else
519 /* parse special meta tag */
c780b543 520 extra_func->read(s, pbx, tlen, tag, extra_meta);
18bbe9df 521 }
2e3ca1ff
JM
522 else if (!tag[0]) {
523 if (tag[1])
524 av_log(s, AV_LOG_WARNING, "invalid frame id, assuming padding");
45a8a02a 525 avio_skip(s->pb, tlen);
2e3ca1ff
JM
526 break;
527 }
75411182 528 /* Skip to end of tag */
86f86877 529seek:
6b4aa5da 530 avio_seek(s->pb, next, SEEK_SET);
75411182
PD
531 }
532
7d7b8c32 533 if (version == 4 && flags & 0x10) /* Footer preset, always 10 bytes, skip over it */
bca6dee3 534 end += 10;
18bbe9df 535
eb1e7f78
AK
536 error:
537 if (reason)
538 av_log(s, AV_LOG_INFO, "ID3v2.%d tag skipped, cannot handle %s\n", version, reason);
bca6dee3 539 avio_seek(s->pb, end, SEEK_SET);
18bbe9df 540 av_free(buffer);
75411182 541 return;
75411182 542}
6378b062 543
7a019dff 544void ff_id3v2_read_all(AVFormatContext *s, const char *magic, ID3v2ExtraMeta **extra_meta)
46a2da76
AK
545{
546 int len, ret;
547 uint8_t buf[ID3v2_HEADER_SIZE];
548 int found_header;
549 int64_t off;
550
551 do {
552 /* save the current offset in case there's nothing to read/skip */
a2704c97 553 off = avio_tell(s->pb);
b7effd4e 554 ret = avio_read(s->pb, buf, ID3v2_HEADER_SIZE);
46a2da76 555 if (ret != ID3v2_HEADER_SIZE)
f7fcd6a2 556 break;
46a2da76
AK
557 found_header = ff_id3v2_match(buf, magic);
558 if (found_header) {
559 /* parse ID3v2 header */
560 len = ((buf[6] & 0x7f) << 21) |
561 ((buf[7] & 0x7f) << 14) |
562 ((buf[8] & 0x7f) << 7) |
563 (buf[9] & 0x7f);
7a019dff 564 ff_id3v2_parse(s, len, buf[3], buf[5], extra_meta);
46a2da76 565 } else {
6b4aa5da 566 avio_seek(s->pb, off, SEEK_SET);
46a2da76
AK
567 }
568 } while (found_header);
cb6bc576 569 ff_metadata_conv(&s->metadata, NULL, ff_id3v2_34_metadata_conv);
c4a37885 570 ff_metadata_conv(&s->metadata, NULL, id3v2_2_metadata_conv);
cb6bc576 571 ff_metadata_conv(&s->metadata, NULL, ff_id3v2_4_metadata_conv);
56e2ac6b 572 merge_date(&s->metadata);
46a2da76
AK
573}
574
7a019dff
DG
575void ff_id3v2_read(AVFormatContext *s, const char *magic)
576{
577 ff_id3v2_read_all(s, magic, NULL);
578}
579
580void ff_id3v2_free_extra_meta(ID3v2ExtraMeta **extra_meta)
581{
582 ID3v2ExtraMeta *current = *extra_meta, *next;
c780b543 583 const ID3v2EMFunc *extra_func;
7a019dff
DG
584
585 while (current) {
c780b543
AK
586 if ((extra_func = get_extra_meta_func(current->tag, 1)))
587 extra_func->free(current->data);
7a019dff
DG
588 next = current->next;
589 av_freep(&current);
590 current = next;
591 }
592}