You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

672 lines
19KB

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