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.

698 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);
  168. unsigned genre;
  169. if(dstlen > 0)
  170. dst[0]= 0;
  171. if(taglen < 1)
  172. return;
  173. taglen--; /* account for encoding type byte */
  174. dstlen--; /* Leave space for zero terminator */
  175. switch(get_byte(s->pb)) { /* encoding type */
  176. case 0: /* ISO-8859-1 (0 - 255 maps directly into unicode) */
  177. q = dst;
  178. while(taglen--) {
  179. uint8_t tmp;
  180. PUT_UTF8(get_byte(s->pb), tmp, if (q - dst < dstlen - 1) *q++ = tmp;)
  181. }
  182. *q = '\0';
  183. break;
  184. case 3: /* UTF-8 */
  185. len = FFMIN(taglen, dstlen-1);
  186. get_buffer(s->pb, dst, len);
  187. dst[len] = 0;
  188. break;
  189. }
  190. if (!strcmp(key, "genre")
  191. && sscanf(dst, "(%d)", &genre) == 1 && genre <= ID3v1_GENRE_MAX)
  192. av_strlcpy(dst, id3v1_genre_str[genre], sizeof(dst));
  193. if (*dst)
  194. av_metadata_set(&s->metadata, key, dst);
  195. }
  196. /**
  197. * ID3v2 parser
  198. *
  199. * Handles ID3v2.2, 2.3 and 2.4.
  200. *
  201. */
  202. static void id3v2_parse(AVFormatContext *s, int len, uint8_t version, uint8_t flags)
  203. {
  204. int isv34, tlen;
  205. uint32_t tag;
  206. int64_t next;
  207. int taghdrlen;
  208. const char *reason;
  209. switch(version) {
  210. case 2:
  211. if(flags & 0x40) {
  212. reason = "compression";
  213. goto error;
  214. }
  215. isv34 = 0;
  216. taghdrlen = 6;
  217. break;
  218. case 3:
  219. case 4:
  220. isv34 = 1;
  221. taghdrlen = 10;
  222. break;
  223. default:
  224. reason = "version";
  225. goto error;
  226. }
  227. if(flags & 0x80) {
  228. reason = "unsynchronization";
  229. goto error;
  230. }
  231. if(isv34 && flags & 0x40) /* Extended header present, just skip over it */
  232. url_fskip(s->pb, id3v2_get_size(s->pb, 4));
  233. while(len >= taghdrlen) {
  234. if(isv34) {
  235. tag = get_be32(s->pb);
  236. tlen = id3v2_get_size(s->pb, 4);
  237. get_be16(s->pb); /* flags */
  238. } else {
  239. tag = get_be24(s->pb);
  240. tlen = id3v2_get_size(s->pb, 3);
  241. }
  242. len -= taghdrlen + tlen;
  243. if(len < 0)
  244. break;
  245. next = url_ftell(s->pb) + tlen;
  246. switch(tag) {
  247. case MKBETAG('T', 'I', 'T', '2'):
  248. case MKBETAG(0, 'T', 'T', '2'):
  249. id3v2_read_ttag(s, tlen, "title");
  250. break;
  251. case MKBETAG('T', 'P', 'E', '1'):
  252. case MKBETAG(0, 'T', 'P', '1'):
  253. id3v2_read_ttag(s, tlen, "author");
  254. break;
  255. case MKBETAG('T', 'A', 'L', 'B'):
  256. case MKBETAG(0, 'T', 'A', 'L'):
  257. id3v2_read_ttag(s, tlen, "album");
  258. break;
  259. case MKBETAG('T', 'C', 'O', 'N'):
  260. case MKBETAG(0, 'T', 'C', 'O'):
  261. id3v2_read_ttag(s, tlen, "genre");
  262. break;
  263. case MKBETAG('T', 'C', 'O', 'P'):
  264. case MKBETAG(0, 'T', 'C', 'R'):
  265. id3v2_read_ttag(s, tlen, "copyright");
  266. break;
  267. case MKBETAG('T', 'R', 'C', 'K'):
  268. case MKBETAG(0, 'T', 'R', 'K'):
  269. id3v2_read_ttag(s, tlen, "track");
  270. break;
  271. case 0:
  272. /* padding, skip to end */
  273. url_fskip(s->pb, len);
  274. len = 0;
  275. continue;
  276. }
  277. /* Skip to end of tag */
  278. url_fseek(s->pb, next, SEEK_SET);
  279. }
  280. if(version == 4 && flags & 0x10) /* Footer preset, always 10 bytes, skip over it */
  281. url_fskip(s->pb, 10);
  282. return;
  283. error:
  284. av_log(s, AV_LOG_INFO, "ID3v2.%d tag skipped, cannot handle %s\n", version, reason);
  285. url_fskip(s->pb, len);
  286. }
  287. static void id3v1_get_string(AVFormatContext *s, const char *key,
  288. const uint8_t *buf, int buf_size)
  289. {
  290. int i, c;
  291. char *q, str[512];
  292. q = str;
  293. for(i = 0; i < buf_size; i++) {
  294. c = buf[i];
  295. if (c == '\0')
  296. break;
  297. if ((q - str) >= sizeof(str) - 1)
  298. break;
  299. *q++ = c;
  300. }
  301. *q = '\0';
  302. if (*str)
  303. av_metadata_set(&s->metadata, key, str);
  304. }
  305. /* 'buf' must be ID3v1_TAG_SIZE byte long */
  306. static int id3v1_parse_tag(AVFormatContext *s, const uint8_t *buf)
  307. {
  308. char str[5];
  309. int genre;
  310. if (!(buf[0] == 'T' &&
  311. buf[1] == 'A' &&
  312. buf[2] == 'G'))
  313. return -1;
  314. id3v1_get_string(s, "title", buf + 3, 30);
  315. id3v1_get_string(s, "author", buf + 33, 30);
  316. id3v1_get_string(s, "album", buf + 63, 30);
  317. id3v1_get_string(s, "year", buf + 93, 4);
  318. id3v1_get_string(s, "comment", buf + 97, 30);
  319. if (buf[125] == 0 && buf[126] != 0) {
  320. snprintf(str, sizeof(str), "%d", buf[126]);
  321. av_metadata_set(&s->metadata, "track", str);
  322. }
  323. genre = buf[127];
  324. if (genre <= ID3v1_GENRE_MAX)
  325. av_metadata_set(&s->metadata, "genre", id3v1_genre_str[genre]);
  326. return 0;
  327. }
  328. /* mp3 read */
  329. static int mp3_read_probe(AVProbeData *p)
  330. {
  331. int max_frames, first_frames = 0;
  332. int fsize, frames, sample_rate;
  333. uint32_t header;
  334. uint8_t *buf, *buf0, *buf2, *end;
  335. AVCodecContext avctx;
  336. buf0 = p->buf;
  337. if(ff_id3v2_match(buf0)) {
  338. buf0 += ff_id3v2_tag_len(buf0);
  339. }
  340. max_frames = 0;
  341. buf = buf0;
  342. end = p->buf + p->buf_size - sizeof(uint32_t);
  343. for(; buf < end; buf= buf2+1) {
  344. buf2 = buf;
  345. for(frames = 0; buf2 < end; frames++) {
  346. header = AV_RB32(buf2);
  347. fsize = ff_mpa_decode_header(&avctx, header, &sample_rate, &sample_rate, &sample_rate, &sample_rate);
  348. if(fsize < 0)
  349. break;
  350. buf2 += fsize;
  351. }
  352. max_frames = FFMAX(max_frames, frames);
  353. if(buf == buf0)
  354. first_frames= frames;
  355. }
  356. if (first_frames>=3) return AVPROBE_SCORE_MAX/2+1;
  357. else if(max_frames>500)return AVPROBE_SCORE_MAX/2;
  358. else if(max_frames>=3) return AVPROBE_SCORE_MAX/4;
  359. else if(max_frames>=1) return 1;
  360. else return 0;
  361. }
  362. /**
  363. * Try to find Xing/Info/VBRI tags and compute duration from info therein
  364. */
  365. static int mp3_parse_vbr_tags(AVFormatContext *s, AVStream *st, int64_t base)
  366. {
  367. uint32_t v, spf;
  368. int frames = -1; /* Total number of frames in file */
  369. const int64_t xing_offtbl[2][2] = {{32, 17}, {17,9}};
  370. MPADecodeHeader c;
  371. int vbrtag_size = 0;
  372. v = get_be32(s->pb);
  373. if(ff_mpa_check_header(v) < 0)
  374. return -1;
  375. if (ff_mpegaudio_decode_header(&c, v) == 0)
  376. vbrtag_size = c.frame_size;
  377. if(c.layer != 3)
  378. return -1;
  379. /* Check for Xing / Info tag */
  380. url_fseek(s->pb, xing_offtbl[c.lsf == 1][c.nb_channels == 1], SEEK_CUR);
  381. v = get_be32(s->pb);
  382. if(v == MKBETAG('X', 'i', 'n', 'g') || v == MKBETAG('I', 'n', 'f', 'o')) {
  383. v = get_be32(s->pb);
  384. if(v & 0x1)
  385. frames = get_be32(s->pb);
  386. }
  387. /* Check for VBRI tag (always 32 bytes after end of mpegaudio header) */
  388. url_fseek(s->pb, base + 4 + 32, SEEK_SET);
  389. v = get_be32(s->pb);
  390. if(v == MKBETAG('V', 'B', 'R', 'I')) {
  391. /* Check tag version */
  392. if(get_be16(s->pb) == 1) {
  393. /* skip delay, quality and total bytes */
  394. url_fseek(s->pb, 8, SEEK_CUR);
  395. frames = get_be32(s->pb);
  396. }
  397. }
  398. if(frames < 0)
  399. return -1;
  400. /* Skip the vbr tag frame */
  401. url_fseek(s->pb, base + vbrtag_size, SEEK_SET);
  402. spf = c.lsf ? 576 : 1152; /* Samples per frame, layer 3 */
  403. st->duration = av_rescale_q(frames, (AVRational){spf, c.sample_rate},
  404. st->time_base);
  405. return 0;
  406. }
  407. static int mp3_read_header(AVFormatContext *s,
  408. AVFormatParameters *ap)
  409. {
  410. AVStream *st;
  411. uint8_t buf[ID3v1_TAG_SIZE];
  412. int len, ret, filesize;
  413. int64_t off;
  414. st = av_new_stream(s, 0);
  415. if (!st)
  416. return AVERROR(ENOMEM);
  417. st->codec->codec_type = CODEC_TYPE_AUDIO;
  418. st->codec->codec_id = CODEC_ID_MP3;
  419. st->need_parsing = AVSTREAM_PARSE_FULL;
  420. st->start_time = 0;
  421. /* try to get the TAG */
  422. if (!url_is_streamed(s->pb)) {
  423. /* XXX: change that */
  424. filesize = url_fsize(s->pb);
  425. if (filesize > 128) {
  426. url_fseek(s->pb, filesize - 128, SEEK_SET);
  427. ret = get_buffer(s->pb, buf, ID3v1_TAG_SIZE);
  428. if (ret == ID3v1_TAG_SIZE) {
  429. id3v1_parse_tag(s, buf);
  430. }
  431. url_fseek(s->pb, 0, SEEK_SET);
  432. }
  433. }
  434. /* if ID3v2 header found, skip it */
  435. ret = get_buffer(s->pb, buf, ID3v2_HEADER_SIZE);
  436. if (ret != ID3v2_HEADER_SIZE)
  437. return -1;
  438. if (ff_id3v2_match(buf)) {
  439. /* parse ID3v2 header */
  440. len = ((buf[6] & 0x7f) << 21) |
  441. ((buf[7] & 0x7f) << 14) |
  442. ((buf[8] & 0x7f) << 7) |
  443. (buf[9] & 0x7f);
  444. id3v2_parse(s, len, buf[3], buf[5]);
  445. } else {
  446. url_fseek(s->pb, 0, SEEK_SET);
  447. }
  448. off = url_ftell(s->pb);
  449. if (mp3_parse_vbr_tags(s, st, off) < 0)
  450. url_fseek(s->pb, off, SEEK_SET);
  451. /* the parameters will be extracted from the compressed bitstream */
  452. return 0;
  453. }
  454. #define MP3_PACKET_SIZE 1024
  455. static int mp3_read_packet(AVFormatContext *s, AVPacket *pkt)
  456. {
  457. int ret, size;
  458. // AVStream *st = s->streams[0];
  459. size= MP3_PACKET_SIZE;
  460. ret= av_get_packet(s->pb, pkt, size);
  461. pkt->stream_index = 0;
  462. if (ret <= 0) {
  463. return AVERROR(EIO);
  464. }
  465. /* note: we need to modify the packet size here to handle the last
  466. packet */
  467. pkt->size = ret;
  468. return ret;
  469. }
  470. #if CONFIG_MP2_MUXER || CONFIG_MP3_MUXER
  471. static int id3v1_set_string(AVFormatContext *s, const char *key,
  472. uint8_t *buf, int buf_size)
  473. {
  474. AVMetadataTag *tag;
  475. if ((tag = av_metadata_get(s->metadata, key, NULL, 0)))
  476. strncpy(buf, tag->value, buf_size);
  477. return !!tag;
  478. }
  479. static int id3v1_create_tag(AVFormatContext *s, uint8_t *buf)
  480. {
  481. AVMetadataTag *tag;
  482. int i, count = 0;
  483. memset(buf, 0, ID3v1_TAG_SIZE); /* fail safe */
  484. buf[0] = 'T';
  485. buf[1] = 'A';
  486. buf[2] = 'G';
  487. count += id3v1_set_string(s, "title", buf + 3, 30);
  488. count += id3v1_set_string(s, "author", buf + 33, 30);
  489. count += id3v1_set_string(s, "album", buf + 63, 30);
  490. count += id3v1_set_string(s, "year", buf + 93, 4);
  491. count += id3v1_set_string(s, "comment", buf + 97, 30);
  492. if ((tag = av_metadata_get(s->metadata, "track", NULL, 0))) {
  493. buf[125] = 0;
  494. buf[126] = atoi(tag->value);
  495. count++;
  496. }
  497. if ((tag = av_metadata_get(s->metadata, "genre", NULL, 0))) {
  498. for(i = 0; i <= ID3v1_GENRE_MAX; i++) {
  499. if (!strcasecmp(tag->value, id3v1_genre_str[i])) {
  500. buf[127] = i;
  501. count++;
  502. break;
  503. }
  504. }
  505. }
  506. return count;
  507. }
  508. /* simple formats */
  509. static void id3v2_put_size(AVFormatContext *s, int size)
  510. {
  511. put_byte(s->pb, size >> 21 & 0x7f);
  512. put_byte(s->pb, size >> 14 & 0x7f);
  513. put_byte(s->pb, size >> 7 & 0x7f);
  514. put_byte(s->pb, size & 0x7f);
  515. }
  516. static void id3v2_put_ttag(AVFormatContext *s, const char *string, uint32_t tag)
  517. {
  518. int len = strlen(string);
  519. put_be32(s->pb, tag);
  520. id3v2_put_size(s, len + 1);
  521. put_be16(s->pb, 0);
  522. put_byte(s->pb, 3); /* UTF-8 */
  523. put_buffer(s->pb, string, len);
  524. }
  525. /**
  526. * Write an ID3v2.4 header at beginning of stream
  527. */
  528. static int mp3_write_header(struct AVFormatContext *s)
  529. {
  530. AVMetadataTag *title, *author, *album, *genre, *copyright, *track, *year;
  531. int totlen = 0;
  532. title = av_metadata_get(s->metadata, "title", NULL, 0);
  533. author = av_metadata_get(s->metadata, "author", NULL, 0);
  534. album = av_metadata_get(s->metadata, "album", NULL, 0);
  535. genre = av_metadata_get(s->metadata, "genre", NULL, 0);
  536. copyright = av_metadata_get(s->metadata, "copyright", NULL, 0);
  537. track = av_metadata_get(s->metadata, "track", NULL, 0);
  538. year = av_metadata_get(s->metadata, "year", NULL, 0);
  539. if(title) totlen += 11 + strlen(title->value);
  540. if(author) totlen += 11 + strlen(author->value);
  541. if(album) totlen += 11 + strlen(album->value);
  542. if(genre) totlen += 11 + strlen(genre->value);
  543. if(copyright) totlen += 11 + strlen(copyright->value);
  544. if(track) totlen += 11 + strlen(track->value);
  545. if(year) totlen += 11 + strlen(year->value);
  546. if(!(s->streams[0]->codec->flags & CODEC_FLAG_BITEXACT))
  547. totlen += strlen(LIBAVFORMAT_IDENT) + 11;
  548. if(totlen == 0)
  549. return 0;
  550. put_be32(s->pb, MKBETAG('I', 'D', '3', 0x04)); /* ID3v2.4 */
  551. put_byte(s->pb, 0);
  552. put_byte(s->pb, 0); /* flags */
  553. id3v2_put_size(s, totlen);
  554. if(title) id3v2_put_ttag(s, title->value, MKBETAG('T', 'I', 'T', '2'));
  555. if(author) id3v2_put_ttag(s, author->value, MKBETAG('T', 'P', 'E', '1'));
  556. if(album) id3v2_put_ttag(s, album->value, MKBETAG('T', 'A', 'L', 'B'));
  557. if(genre) id3v2_put_ttag(s, genre->value, MKBETAG('T', 'C', 'O', 'N'));
  558. if(copyright) id3v2_put_ttag(s, copyright->value, MKBETAG('T', 'C', 'O', 'P'));
  559. if(track) id3v2_put_ttag(s, track->value, MKBETAG('T', 'R', 'C', 'K'));
  560. if(year) id3v2_put_ttag(s, year->value, MKBETAG('T', 'Y', 'E', 'R'));
  561. if(!(s->streams[0]->codec->flags & CODEC_FLAG_BITEXACT))
  562. id3v2_put_ttag(s, LIBAVFORMAT_IDENT, MKBETAG('T', 'E', 'N', 'C'));
  563. return 0;
  564. }
  565. static int mp3_write_packet(struct AVFormatContext *s, AVPacket *pkt)
  566. {
  567. put_buffer(s->pb, pkt->data, pkt->size);
  568. put_flush_packet(s->pb);
  569. return 0;
  570. }
  571. static int mp3_write_trailer(struct AVFormatContext *s)
  572. {
  573. uint8_t buf[ID3v1_TAG_SIZE];
  574. /* write the id3v1 tag */
  575. if (id3v1_create_tag(s, buf) > 0) {
  576. put_buffer(s->pb, buf, ID3v1_TAG_SIZE);
  577. put_flush_packet(s->pb);
  578. }
  579. return 0;
  580. }
  581. #endif /* CONFIG_MP2_MUXER || CONFIG_MP3_MUXER */
  582. #if CONFIG_MP3_DEMUXER
  583. AVInputFormat mp3_demuxer = {
  584. "mp3",
  585. NULL_IF_CONFIG_SMALL("MPEG audio"),
  586. 0,
  587. mp3_read_probe,
  588. mp3_read_header,
  589. mp3_read_packet,
  590. .flags= AVFMT_GENERIC_INDEX,
  591. .extensions = "mp2,mp3,m2a", /* XXX: use probe */
  592. };
  593. #endif
  594. #if CONFIG_MP2_MUXER
  595. AVOutputFormat mp2_muxer = {
  596. "mp2",
  597. NULL_IF_CONFIG_SMALL("MPEG audio layer 2"),
  598. "audio/x-mpeg",
  599. "mp2,m2a",
  600. 0,
  601. CODEC_ID_MP2,
  602. CODEC_ID_NONE,
  603. NULL,
  604. mp3_write_packet,
  605. mp3_write_trailer,
  606. };
  607. #endif
  608. #if CONFIG_MP3_MUXER
  609. AVOutputFormat mp3_muxer = {
  610. "mp3",
  611. NULL_IF_CONFIG_SMALL("MPEG audio layer 3"),
  612. "audio/x-mpeg",
  613. "mp3",
  614. 0,
  615. CODEC_ID_MP3,
  616. CODEC_ID_NONE,
  617. mp3_write_header,
  618. mp3_write_packet,
  619. mp3_write_trailer,
  620. };
  621. #endif