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.

696 lines
18KB

  1. /*
  2. * MP3 muxer and demuxer
  3. * Copyright (c) 2003 Fabrice Bellard
  4. *
  5. * This file is part of FFmpeg.
  6. *
  7. * FFmpeg is free software; you can redistribute it and/or
  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. *
  12. * FFmpeg is distributed in the hope that it will be useful,
  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
  18. * License along with FFmpeg; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  20. */
  21. #include <strings.h>
  22. #include "libavutil/avstring.h"
  23. #include "libavcodec/mpegaudio.h"
  24. #include "libavcodec/mpegaudiodecheader.h"
  25. #include "avformat.h"
  26. #include "id3v2.h"
  27. #define ID3v1_TAG_SIZE 128
  28. #define ID3v1_GENRE_MAX 125
  29. static const char * const id3v1_genre_str[ID3v1_GENRE_MAX + 1] = {
  30. [0] = "Blues",
  31. [1] = "Classic Rock",
  32. [2] = "Country",
  33. [3] = "Dance",
  34. [4] = "Disco",
  35. [5] = "Funk",
  36. [6] = "Grunge",
  37. [7] = "Hip-Hop",
  38. [8] = "Jazz",
  39. [9] = "Metal",
  40. [10] = "New Age",
  41. [11] = "Oldies",
  42. [12] = "Other",
  43. [13] = "Pop",
  44. [14] = "R&B",
  45. [15] = "Rap",
  46. [16] = "Reggae",
  47. [17] = "Rock",
  48. [18] = "Techno",
  49. [19] = "Industrial",
  50. [20] = "Alternative",
  51. [21] = "Ska",
  52. [22] = "Death Metal",
  53. [23] = "Pranks",
  54. [24] = "Soundtrack",
  55. [25] = "Euro-Techno",
  56. [26] = "Ambient",
  57. [27] = "Trip-Hop",
  58. [28] = "Vocal",
  59. [29] = "Jazz+Funk",
  60. [30] = "Fusion",
  61. [31] = "Trance",
  62. [32] = "Classical",
  63. [33] = "Instrumental",
  64. [34] = "Acid",
  65. [35] = "House",
  66. [36] = "Game",
  67. [37] = "Sound Clip",
  68. [38] = "Gospel",
  69. [39] = "Noise",
  70. [40] = "AlternRock",
  71. [41] = "Bass",
  72. [42] = "Soul",
  73. [43] = "Punk",
  74. [44] = "Space",
  75. [45] = "Meditative",
  76. [46] = "Instrumental Pop",
  77. [47] = "Instrumental Rock",
  78. [48] = "Ethnic",
  79. [49] = "Gothic",
  80. [50] = "Darkwave",
  81. [51] = "Techno-Industrial",
  82. [52] = "Electronic",
  83. [53] = "Pop-Folk",
  84. [54] = "Eurodance",
  85. [55] = "Dream",
  86. [56] = "Southern Rock",
  87. [57] = "Comedy",
  88. [58] = "Cult",
  89. [59] = "Gangsta",
  90. [60] = "Top 40",
  91. [61] = "Christian Rap",
  92. [62] = "Pop/Funk",
  93. [63] = "Jungle",
  94. [64] = "Native American",
  95. [65] = "Cabaret",
  96. [66] = "New Wave",
  97. [67] = "Psychadelic",
  98. [68] = "Rave",
  99. [69] = "Showtunes",
  100. [70] = "Trailer",
  101. [71] = "Lo-Fi",
  102. [72] = "Tribal",
  103. [73] = "Acid Punk",
  104. [74] = "Acid Jazz",
  105. [75] = "Polka",
  106. [76] = "Retro",
  107. [77] = "Musical",
  108. [78] = "Rock & Roll",
  109. [79] = "Hard Rock",
  110. [80] = "Folk",
  111. [81] = "Folk-Rock",
  112. [82] = "National Folk",
  113. [83] = "Swing",
  114. [84] = "Fast Fusion",
  115. [85] = "Bebob",
  116. [86] = "Latin",
  117. [87] = "Revival",
  118. [88] = "Celtic",
  119. [89] = "Bluegrass",
  120. [90] = "Avantgarde",
  121. [91] = "Gothic Rock",
  122. [92] = "Progressive Rock",
  123. [93] = "Psychedelic Rock",
  124. [94] = "Symphonic Rock",
  125. [95] = "Slow Rock",
  126. [96] = "Big Band",
  127. [97] = "Chorus",
  128. [98] = "Easy Listening",
  129. [99] = "Acoustic",
  130. [100] = "Humour",
  131. [101] = "Speech",
  132. [102] = "Chanson",
  133. [103] = "Opera",
  134. [104] = "Chamber Music",
  135. [105] = "Sonata",
  136. [106] = "Symphony",
  137. [107] = "Booty Bass",
  138. [108] = "Primus",
  139. [109] = "Porn Groove",
  140. [110] = "Satire",
  141. [111] = "Slow Jam",
  142. [112] = "Club",
  143. [113] = "Tango",
  144. [114] = "Samba",
  145. [115] = "Folklore",
  146. [116] = "Ballad",
  147. [117] = "Power Ballad",
  148. [118] = "Rhythmic Soul",
  149. [119] = "Freestyle",
  150. [120] = "Duet",
  151. [121] = "Punk Rock",
  152. [122] = "Drum Solo",
  153. [123] = "A capella",
  154. [124] = "Euro-House",
  155. [125] = "Dance Hall",
  156. };
  157. static unsigned int id3v2_get_size(ByteIOContext *s, int len)
  158. {
  159. int v=0;
  160. while(len--)
  161. v= (v<<7) + (get_byte(s)&0x7F);
  162. return v;
  163. }
  164. static void id3v2_read_ttag(AVFormatContext *s, int taglen, const char *key)
  165. {
  166. char *q, dst[512];
  167. int len, dstlen = sizeof(dst) - 1;
  168. unsigned genre;
  169. dst[0]= 0;
  170. if(taglen < 1)
  171. return;
  172. taglen--; /* account for encoding type byte */
  173. switch(get_byte(s->pb)) { /* encoding type */
  174. case 0: /* ISO-8859-1 (0 - 255 maps directly into unicode) */
  175. q = dst;
  176. while(taglen--) {
  177. uint8_t tmp;
  178. PUT_UTF8(get_byte(s->pb), tmp, if (q - dst < dstlen - 1) *q++ = tmp;)
  179. }
  180. *q = '\0';
  181. break;
  182. case 3: /* UTF-8 */
  183. len = FFMIN(taglen, dstlen-1);
  184. get_buffer(s->pb, dst, len);
  185. dst[len] = 0;
  186. break;
  187. }
  188. if (!strcmp(key, "genre")
  189. && sscanf(dst, "(%d)", &genre) == 1 && genre <= ID3v1_GENRE_MAX)
  190. av_strlcpy(dst, id3v1_genre_str[genre], sizeof(dst));
  191. if (*dst)
  192. av_metadata_set(&s->metadata, key, dst);
  193. }
  194. /**
  195. * ID3v2 parser
  196. *
  197. * Handles ID3v2.2, 2.3 and 2.4.
  198. *
  199. */
  200. static void id3v2_parse(AVFormatContext *s, int len, uint8_t version, uint8_t flags)
  201. {
  202. int isv34, tlen;
  203. uint32_t tag;
  204. int64_t next;
  205. int taghdrlen;
  206. const char *reason;
  207. switch(version) {
  208. case 2:
  209. if(flags & 0x40) {
  210. reason = "compression";
  211. goto error;
  212. }
  213. isv34 = 0;
  214. taghdrlen = 6;
  215. break;
  216. case 3:
  217. case 4:
  218. isv34 = 1;
  219. taghdrlen = 10;
  220. break;
  221. default:
  222. reason = "version";
  223. goto error;
  224. }
  225. if(flags & 0x80) {
  226. reason = "unsynchronization";
  227. goto error;
  228. }
  229. if(isv34 && flags & 0x40) /* Extended header present, just skip over it */
  230. url_fskip(s->pb, id3v2_get_size(s->pb, 4));
  231. while(len >= taghdrlen) {
  232. if(isv34) {
  233. tag = get_be32(s->pb);
  234. tlen = id3v2_get_size(s->pb, 4);
  235. get_be16(s->pb); /* flags */
  236. } else {
  237. tag = get_be24(s->pb);
  238. tlen = id3v2_get_size(s->pb, 3);
  239. }
  240. len -= taghdrlen + tlen;
  241. if(len < 0)
  242. break;
  243. next = url_ftell(s->pb) + tlen;
  244. switch(tag) {
  245. case MKBETAG('T', 'I', 'T', '2'):
  246. case MKBETAG(0, 'T', 'T', '2'):
  247. id3v2_read_ttag(s, tlen, "title");
  248. break;
  249. case MKBETAG('T', 'P', 'E', '1'):
  250. case MKBETAG(0, 'T', 'P', '1'):
  251. id3v2_read_ttag(s, tlen, "author");
  252. break;
  253. case MKBETAG('T', 'A', 'L', 'B'):
  254. case MKBETAG(0, 'T', 'A', 'L'):
  255. id3v2_read_ttag(s, tlen, "album");
  256. break;
  257. case MKBETAG('T', 'C', 'O', 'N'):
  258. case MKBETAG(0, 'T', 'C', 'O'):
  259. id3v2_read_ttag(s, tlen, "genre");
  260. break;
  261. case MKBETAG('T', 'C', 'O', 'P'):
  262. case MKBETAG(0, 'T', 'C', 'R'):
  263. id3v2_read_ttag(s, tlen, "copyright");
  264. break;
  265. case MKBETAG('T', 'R', 'C', 'K'):
  266. case MKBETAG(0, 'T', 'R', 'K'):
  267. id3v2_read_ttag(s, tlen, "track");
  268. break;
  269. case 0:
  270. /* padding, skip to end */
  271. url_fskip(s->pb, len);
  272. len = 0;
  273. continue;
  274. }
  275. /* Skip to end of tag */
  276. url_fseek(s->pb, next, SEEK_SET);
  277. }
  278. if(version == 4 && flags & 0x10) /* Footer preset, always 10 bytes, skip over it */
  279. url_fskip(s->pb, 10);
  280. return;
  281. error:
  282. av_log(s, AV_LOG_INFO, "ID3v2.%d tag skipped, cannot handle %s\n", version, reason);
  283. url_fskip(s->pb, len);
  284. }
  285. static void id3v1_get_string(AVFormatContext *s, const char *key,
  286. const uint8_t *buf, int buf_size)
  287. {
  288. int i, c;
  289. char *q, str[512];
  290. q = str;
  291. for(i = 0; i < buf_size; i++) {
  292. c = buf[i];
  293. if (c == '\0')
  294. break;
  295. if ((q - str) >= sizeof(str) - 1)
  296. break;
  297. *q++ = c;
  298. }
  299. *q = '\0';
  300. if (*str)
  301. av_metadata_set(&s->metadata, key, str);
  302. }
  303. /* 'buf' must be ID3v1_TAG_SIZE byte long */
  304. static int id3v1_parse_tag(AVFormatContext *s, const uint8_t *buf)
  305. {
  306. char str[5];
  307. int genre;
  308. if (!(buf[0] == 'T' &&
  309. buf[1] == 'A' &&
  310. buf[2] == 'G'))
  311. return -1;
  312. id3v1_get_string(s, "title", buf + 3, 30);
  313. id3v1_get_string(s, "author", buf + 33, 30);
  314. id3v1_get_string(s, "album", buf + 63, 30);
  315. id3v1_get_string(s, "year", buf + 93, 4);
  316. id3v1_get_string(s, "comment", buf + 97, 30);
  317. if (buf[125] == 0 && buf[126] != 0) {
  318. snprintf(str, sizeof(str), "%d", buf[126]);
  319. av_metadata_set(&s->metadata, "track", str);
  320. }
  321. genre = buf[127];
  322. if (genre <= ID3v1_GENRE_MAX)
  323. av_metadata_set(&s->metadata, "genre", id3v1_genre_str[genre]);
  324. return 0;
  325. }
  326. /* mp3 read */
  327. static int mp3_read_probe(AVProbeData *p)
  328. {
  329. int max_frames, first_frames = 0;
  330. int fsize, frames, sample_rate;
  331. uint32_t header;
  332. uint8_t *buf, *buf0, *buf2, *end;
  333. AVCodecContext avctx;
  334. buf0 = p->buf;
  335. if(ff_id3v2_match(buf0)) {
  336. buf0 += ff_id3v2_tag_len(buf0);
  337. }
  338. max_frames = 0;
  339. buf = buf0;
  340. end = p->buf + p->buf_size - sizeof(uint32_t);
  341. for(; buf < end; buf= buf2+1) {
  342. buf2 = buf;
  343. for(frames = 0; buf2 < end; frames++) {
  344. header = AV_RB32(buf2);
  345. fsize = ff_mpa_decode_header(&avctx, header, &sample_rate, &sample_rate, &sample_rate, &sample_rate);
  346. if(fsize < 0)
  347. break;
  348. buf2 += fsize;
  349. }
  350. max_frames = FFMAX(max_frames, frames);
  351. if(buf == buf0)
  352. first_frames= frames;
  353. }
  354. if (first_frames>=3) return AVPROBE_SCORE_MAX/2+1;
  355. else if(max_frames>500)return AVPROBE_SCORE_MAX/2;
  356. else if(max_frames>=3) return AVPROBE_SCORE_MAX/4;
  357. else if(max_frames>=1) return 1;
  358. else return 0;
  359. }
  360. /**
  361. * Try to find Xing/Info/VBRI tags and compute duration from info therein
  362. */
  363. static int mp3_parse_vbr_tags(AVFormatContext *s, AVStream *st, int64_t base)
  364. {
  365. uint32_t v, spf;
  366. int frames = -1; /* Total number of frames in file */
  367. const int64_t xing_offtbl[2][2] = {{32, 17}, {17,9}};
  368. MPADecodeHeader c;
  369. int vbrtag_size = 0;
  370. v = get_be32(s->pb);
  371. if(ff_mpa_check_header(v) < 0)
  372. return -1;
  373. if (ff_mpegaudio_decode_header(&c, v) == 0)
  374. vbrtag_size = c.frame_size;
  375. if(c.layer != 3)
  376. return -1;
  377. /* Check for Xing / Info tag */
  378. url_fseek(s->pb, xing_offtbl[c.lsf == 1][c.nb_channels == 1], SEEK_CUR);
  379. v = get_be32(s->pb);
  380. if(v == MKBETAG('X', 'i', 'n', 'g') || v == MKBETAG('I', 'n', 'f', 'o')) {
  381. v = get_be32(s->pb);
  382. if(v & 0x1)
  383. frames = get_be32(s->pb);
  384. }
  385. /* Check for VBRI tag (always 32 bytes after end of mpegaudio header) */
  386. url_fseek(s->pb, base + 4 + 32, SEEK_SET);
  387. v = get_be32(s->pb);
  388. if(v == MKBETAG('V', 'B', 'R', 'I')) {
  389. /* Check tag version */
  390. if(get_be16(s->pb) == 1) {
  391. /* skip delay, quality and total bytes */
  392. url_fseek(s->pb, 8, SEEK_CUR);
  393. frames = get_be32(s->pb);
  394. }
  395. }
  396. if(frames < 0)
  397. return -1;
  398. /* Skip the vbr tag frame */
  399. url_fseek(s->pb, base + vbrtag_size, SEEK_SET);
  400. spf = c.lsf ? 576 : 1152; /* Samples per frame, layer 3 */
  401. st->duration = av_rescale_q(frames, (AVRational){spf, c.sample_rate},
  402. st->time_base);
  403. return 0;
  404. }
  405. static int mp3_read_header(AVFormatContext *s,
  406. AVFormatParameters *ap)
  407. {
  408. AVStream *st;
  409. uint8_t buf[ID3v1_TAG_SIZE];
  410. int len, ret, filesize;
  411. int64_t off;
  412. st = av_new_stream(s, 0);
  413. if (!st)
  414. return AVERROR(ENOMEM);
  415. st->codec->codec_type = CODEC_TYPE_AUDIO;
  416. st->codec->codec_id = CODEC_ID_MP3;
  417. st->need_parsing = AVSTREAM_PARSE_FULL;
  418. st->start_time = 0;
  419. /* try to get the TAG */
  420. if (!url_is_streamed(s->pb)) {
  421. /* XXX: change that */
  422. filesize = url_fsize(s->pb);
  423. if (filesize > 128) {
  424. url_fseek(s->pb, filesize - 128, SEEK_SET);
  425. ret = get_buffer(s->pb, buf, ID3v1_TAG_SIZE);
  426. if (ret == ID3v1_TAG_SIZE) {
  427. id3v1_parse_tag(s, buf);
  428. }
  429. url_fseek(s->pb, 0, SEEK_SET);
  430. }
  431. }
  432. /* if ID3v2 header found, skip it */
  433. ret = get_buffer(s->pb, buf, ID3v2_HEADER_SIZE);
  434. if (ret != ID3v2_HEADER_SIZE)
  435. return -1;
  436. if (ff_id3v2_match(buf)) {
  437. /* parse ID3v2 header */
  438. len = ((buf[6] & 0x7f) << 21) |
  439. ((buf[7] & 0x7f) << 14) |
  440. ((buf[8] & 0x7f) << 7) |
  441. (buf[9] & 0x7f);
  442. id3v2_parse(s, len, buf[3], buf[5]);
  443. } else {
  444. url_fseek(s->pb, 0, SEEK_SET);
  445. }
  446. off = url_ftell(s->pb);
  447. if (mp3_parse_vbr_tags(s, st, off) < 0)
  448. url_fseek(s->pb, off, SEEK_SET);
  449. /* the parameters will be extracted from the compressed bitstream */
  450. return 0;
  451. }
  452. #define MP3_PACKET_SIZE 1024
  453. static int mp3_read_packet(AVFormatContext *s, AVPacket *pkt)
  454. {
  455. int ret, size;
  456. // AVStream *st = s->streams[0];
  457. size= MP3_PACKET_SIZE;
  458. ret= av_get_packet(s->pb, pkt, size);
  459. pkt->stream_index = 0;
  460. if (ret <= 0) {
  461. return AVERROR(EIO);
  462. }
  463. /* note: we need to modify the packet size here to handle the last
  464. packet */
  465. pkt->size = ret;
  466. return ret;
  467. }
  468. #if CONFIG_MP2_MUXER || CONFIG_MP3_MUXER
  469. static int id3v1_set_string(AVFormatContext *s, const char *key,
  470. uint8_t *buf, int buf_size)
  471. {
  472. AVMetadataTag *tag;
  473. if ((tag = av_metadata_get(s->metadata, key, NULL, 0)))
  474. strncpy(buf, tag->value, buf_size);
  475. return !!tag;
  476. }
  477. static int id3v1_create_tag(AVFormatContext *s, uint8_t *buf)
  478. {
  479. AVMetadataTag *tag;
  480. int i, count = 0;
  481. memset(buf, 0, ID3v1_TAG_SIZE); /* fail safe */
  482. buf[0] = 'T';
  483. buf[1] = 'A';
  484. buf[2] = 'G';
  485. count += id3v1_set_string(s, "title", buf + 3, 30);
  486. count += id3v1_set_string(s, "author", buf + 33, 30);
  487. count += id3v1_set_string(s, "album", buf + 63, 30);
  488. count += id3v1_set_string(s, "year", buf + 93, 4);
  489. count += id3v1_set_string(s, "comment", buf + 97, 30);
  490. if ((tag = av_metadata_get(s->metadata, "track", NULL, 0))) {
  491. buf[125] = 0;
  492. buf[126] = atoi(tag->value);
  493. count++;
  494. }
  495. if ((tag = av_metadata_get(s->metadata, "genre", NULL, 0))) {
  496. for(i = 0; i <= ID3v1_GENRE_MAX; i++) {
  497. if (!strcasecmp(tag->value, id3v1_genre_str[i])) {
  498. buf[127] = i;
  499. count++;
  500. break;
  501. }
  502. }
  503. }
  504. return count;
  505. }
  506. /* simple formats */
  507. static void id3v2_put_size(AVFormatContext *s, int size)
  508. {
  509. put_byte(s->pb, size >> 21 & 0x7f);
  510. put_byte(s->pb, size >> 14 & 0x7f);
  511. put_byte(s->pb, size >> 7 & 0x7f);
  512. put_byte(s->pb, size & 0x7f);
  513. }
  514. static void id3v2_put_ttag(AVFormatContext *s, const char *string, uint32_t tag)
  515. {
  516. int len = strlen(string);
  517. put_be32(s->pb, tag);
  518. id3v2_put_size(s, len + 1);
  519. put_be16(s->pb, 0);
  520. put_byte(s->pb, 3); /* UTF-8 */
  521. put_buffer(s->pb, string, len);
  522. }
  523. /**
  524. * Write an ID3v2.4 header at beginning of stream
  525. */
  526. static int mp3_write_header(struct AVFormatContext *s)
  527. {
  528. AVMetadataTag *title, *author, *album, *genre, *copyright, *track, *year;
  529. int totlen = 0;
  530. title = av_metadata_get(s->metadata, "title", NULL, 0);
  531. author = av_metadata_get(s->metadata, "author", NULL, 0);
  532. album = av_metadata_get(s->metadata, "album", NULL, 0);
  533. genre = av_metadata_get(s->metadata, "genre", NULL, 0);
  534. copyright = av_metadata_get(s->metadata, "copyright", NULL, 0);
  535. track = av_metadata_get(s->metadata, "track", NULL, 0);
  536. year = av_metadata_get(s->metadata, "year", NULL, 0);
  537. if(title) totlen += 11 + strlen(title->value);
  538. if(author) totlen += 11 + strlen(author->value);
  539. if(album) totlen += 11 + strlen(album->value);
  540. if(genre) totlen += 11 + strlen(genre->value);
  541. if(copyright) totlen += 11 + strlen(copyright->value);
  542. if(track) totlen += 11 + strlen(track->value);
  543. if(year) totlen += 11 + strlen(year->value);
  544. if(!(s->streams[0]->codec->flags & CODEC_FLAG_BITEXACT))
  545. totlen += strlen(LIBAVFORMAT_IDENT) + 11;
  546. if(totlen == 0)
  547. return 0;
  548. put_be32(s->pb, MKBETAG('I', 'D', '3', 0x04)); /* ID3v2.4 */
  549. put_byte(s->pb, 0);
  550. put_byte(s->pb, 0); /* flags */
  551. id3v2_put_size(s, totlen);
  552. if(title) id3v2_put_ttag(s, title->value, MKBETAG('T', 'I', 'T', '2'));
  553. if(author) id3v2_put_ttag(s, author->value, MKBETAG('T', 'P', 'E', '1'));
  554. if(album) id3v2_put_ttag(s, album->value, MKBETAG('T', 'A', 'L', 'B'));
  555. if(genre) id3v2_put_ttag(s, genre->value, MKBETAG('T', 'C', 'O', 'N'));
  556. if(copyright) id3v2_put_ttag(s, copyright->value, MKBETAG('T', 'C', 'O', 'P'));
  557. if(track) id3v2_put_ttag(s, track->value, MKBETAG('T', 'R', 'C', 'K'));
  558. if(year) id3v2_put_ttag(s, year->value, MKBETAG('T', 'Y', 'E', 'R'));
  559. if(!(s->streams[0]->codec->flags & CODEC_FLAG_BITEXACT))
  560. id3v2_put_ttag(s, LIBAVFORMAT_IDENT, MKBETAG('T', 'E', 'N', 'C'));
  561. return 0;
  562. }
  563. static int mp3_write_packet(struct AVFormatContext *s, AVPacket *pkt)
  564. {
  565. put_buffer(s->pb, pkt->data, pkt->size);
  566. put_flush_packet(s->pb);
  567. return 0;
  568. }
  569. static int mp3_write_trailer(struct AVFormatContext *s)
  570. {
  571. uint8_t buf[ID3v1_TAG_SIZE];
  572. /* write the id3v1 tag */
  573. if (id3v1_create_tag(s, buf) > 0) {
  574. put_buffer(s->pb, buf, ID3v1_TAG_SIZE);
  575. put_flush_packet(s->pb);
  576. }
  577. return 0;
  578. }
  579. #endif /* CONFIG_MP2_MUXER || CONFIG_MP3_MUXER */
  580. #if CONFIG_MP3_DEMUXER
  581. AVInputFormat mp3_demuxer = {
  582. "mp3",
  583. NULL_IF_CONFIG_SMALL("MPEG audio"),
  584. 0,
  585. mp3_read_probe,
  586. mp3_read_header,
  587. mp3_read_packet,
  588. .flags= AVFMT_GENERIC_INDEX,
  589. .extensions = "mp2,mp3,m2a", /* XXX: use probe */
  590. };
  591. #endif
  592. #if CONFIG_MP2_MUXER
  593. AVOutputFormat mp2_muxer = {
  594. "mp2",
  595. NULL_IF_CONFIG_SMALL("MPEG audio layer 2"),
  596. "audio/x-mpeg",
  597. "mp2,m2a",
  598. 0,
  599. CODEC_ID_MP2,
  600. CODEC_ID_NONE,
  601. NULL,
  602. mp3_write_packet,
  603. mp3_write_trailer,
  604. };
  605. #endif
  606. #if CONFIG_MP3_MUXER
  607. AVOutputFormat mp3_muxer = {
  608. "mp3",
  609. NULL_IF_CONFIG_SMALL("MPEG audio layer 3"),
  610. "audio/x-mpeg",
  611. "mp3",
  612. 0,
  613. CODEC_ID_MP3,
  614. CODEC_ID_NONE,
  615. mp3_write_header,
  616. mp3_write_packet,
  617. mp3_write_trailer,
  618. };
  619. #endif