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.

697 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(buf0!=p->buf) return AVPROBE_SCORE_MAX/4-1;
  358. else if(max_frames>=1) return 1;
  359. else return 0;
  360. }
  361. /**
  362. * Try to find Xing/Info/VBRI tags and compute duration from info therein
  363. */
  364. static int mp3_parse_vbr_tags(AVFormatContext *s, AVStream *st, int64_t base)
  365. {
  366. uint32_t v, spf;
  367. int frames = -1; /* Total number of frames in file */
  368. const int64_t xing_offtbl[2][2] = {{32, 17}, {17,9}};
  369. MPADecodeHeader c;
  370. int vbrtag_size = 0;
  371. v = get_be32(s->pb);
  372. if(ff_mpa_check_header(v) < 0)
  373. return -1;
  374. if (ff_mpegaudio_decode_header(&c, v) == 0)
  375. vbrtag_size = c.frame_size;
  376. if(c.layer != 3)
  377. return -1;
  378. /* Check for Xing / Info tag */
  379. url_fseek(s->pb, xing_offtbl[c.lsf == 1][c.nb_channels == 1], SEEK_CUR);
  380. v = get_be32(s->pb);
  381. if(v == MKBETAG('X', 'i', 'n', 'g') || v == MKBETAG('I', 'n', 'f', 'o')) {
  382. v = get_be32(s->pb);
  383. if(v & 0x1)
  384. frames = get_be32(s->pb);
  385. }
  386. /* Check for VBRI tag (always 32 bytes after end of mpegaudio header) */
  387. url_fseek(s->pb, base + 4 + 32, SEEK_SET);
  388. v = get_be32(s->pb);
  389. if(v == MKBETAG('V', 'B', 'R', 'I')) {
  390. /* Check tag version */
  391. if(get_be16(s->pb) == 1) {
  392. /* skip delay, quality and total bytes */
  393. url_fseek(s->pb, 8, SEEK_CUR);
  394. frames = get_be32(s->pb);
  395. }
  396. }
  397. if(frames < 0)
  398. return -1;
  399. /* Skip the vbr tag frame */
  400. url_fseek(s->pb, base + vbrtag_size, SEEK_SET);
  401. spf = c.lsf ? 576 : 1152; /* Samples per frame, layer 3 */
  402. st->duration = av_rescale_q(frames, (AVRational){spf, c.sample_rate},
  403. st->time_base);
  404. return 0;
  405. }
  406. static int mp3_read_header(AVFormatContext *s,
  407. AVFormatParameters *ap)
  408. {
  409. AVStream *st;
  410. uint8_t buf[ID3v1_TAG_SIZE];
  411. int len, ret, filesize;
  412. int64_t off;
  413. st = av_new_stream(s, 0);
  414. if (!st)
  415. return AVERROR(ENOMEM);
  416. st->codec->codec_type = CODEC_TYPE_AUDIO;
  417. st->codec->codec_id = CODEC_ID_MP3;
  418. st->need_parsing = AVSTREAM_PARSE_FULL;
  419. st->start_time = 0;
  420. /* try to get the TAG */
  421. if (!url_is_streamed(s->pb)) {
  422. /* XXX: change that */
  423. filesize = url_fsize(s->pb);
  424. if (filesize > 128) {
  425. url_fseek(s->pb, filesize - 128, SEEK_SET);
  426. ret = get_buffer(s->pb, buf, ID3v1_TAG_SIZE);
  427. if (ret == ID3v1_TAG_SIZE) {
  428. id3v1_parse_tag(s, buf);
  429. }
  430. url_fseek(s->pb, 0, SEEK_SET);
  431. }
  432. }
  433. /* if ID3v2 header found, skip it */
  434. ret = get_buffer(s->pb, buf, ID3v2_HEADER_SIZE);
  435. if (ret != ID3v2_HEADER_SIZE)
  436. return -1;
  437. if (ff_id3v2_match(buf)) {
  438. /* parse ID3v2 header */
  439. len = ((buf[6] & 0x7f) << 21) |
  440. ((buf[7] & 0x7f) << 14) |
  441. ((buf[8] & 0x7f) << 7) |
  442. (buf[9] & 0x7f);
  443. id3v2_parse(s, len, buf[3], buf[5]);
  444. } else {
  445. url_fseek(s->pb, 0, SEEK_SET);
  446. }
  447. off = url_ftell(s->pb);
  448. if (mp3_parse_vbr_tags(s, st, off) < 0)
  449. url_fseek(s->pb, off, SEEK_SET);
  450. /* the parameters will be extracted from the compressed bitstream */
  451. return 0;
  452. }
  453. #define MP3_PACKET_SIZE 1024
  454. static int mp3_read_packet(AVFormatContext *s, AVPacket *pkt)
  455. {
  456. int ret, size;
  457. // AVStream *st = s->streams[0];
  458. size= MP3_PACKET_SIZE;
  459. ret= av_get_packet(s->pb, pkt, size);
  460. pkt->stream_index = 0;
  461. if (ret <= 0) {
  462. return AVERROR(EIO);
  463. }
  464. /* note: we need to modify the packet size here to handle the last
  465. packet */
  466. pkt->size = ret;
  467. return ret;
  468. }
  469. #if CONFIG_MP2_MUXER || CONFIG_MP3_MUXER
  470. static int id3v1_set_string(AVFormatContext *s, const char *key,
  471. uint8_t *buf, int buf_size)
  472. {
  473. AVMetadataTag *tag;
  474. if ((tag = av_metadata_get(s->metadata, key, NULL, 0)))
  475. strncpy(buf, tag->value, buf_size);
  476. return !!tag;
  477. }
  478. static int id3v1_create_tag(AVFormatContext *s, uint8_t *buf)
  479. {
  480. AVMetadataTag *tag;
  481. int i, count = 0;
  482. memset(buf, 0, ID3v1_TAG_SIZE); /* fail safe */
  483. buf[0] = 'T';
  484. buf[1] = 'A';
  485. buf[2] = 'G';
  486. count += id3v1_set_string(s, "title", buf + 3, 30);
  487. count += id3v1_set_string(s, "author", buf + 33, 30);
  488. count += id3v1_set_string(s, "album", buf + 63, 30);
  489. count += id3v1_set_string(s, "year", buf + 93, 4);
  490. count += id3v1_set_string(s, "comment", buf + 97, 30);
  491. if ((tag = av_metadata_get(s->metadata, "track", NULL, 0))) {
  492. buf[125] = 0;
  493. buf[126] = atoi(tag->value);
  494. count++;
  495. }
  496. if ((tag = av_metadata_get(s->metadata, "genre", NULL, 0))) {
  497. for(i = 0; i <= ID3v1_GENRE_MAX; i++) {
  498. if (!strcasecmp(tag->value, id3v1_genre_str[i])) {
  499. buf[127] = i;
  500. count++;
  501. break;
  502. }
  503. }
  504. }
  505. return count;
  506. }
  507. /* simple formats */
  508. static void id3v2_put_size(AVFormatContext *s, int size)
  509. {
  510. put_byte(s->pb, size >> 21 & 0x7f);
  511. put_byte(s->pb, size >> 14 & 0x7f);
  512. put_byte(s->pb, size >> 7 & 0x7f);
  513. put_byte(s->pb, size & 0x7f);
  514. }
  515. static void id3v2_put_ttag(AVFormatContext *s, const char *string, uint32_t tag)
  516. {
  517. int len = strlen(string);
  518. put_be32(s->pb, tag);
  519. id3v2_put_size(s, len + 1);
  520. put_be16(s->pb, 0);
  521. put_byte(s->pb, 3); /* UTF-8 */
  522. put_buffer(s->pb, string, len);
  523. }
  524. /**
  525. * Write an ID3v2.4 header at beginning of stream
  526. */
  527. static int mp3_write_header(struct AVFormatContext *s)
  528. {
  529. AVMetadataTag *title, *author, *album, *genre, *copyright, *track, *year;
  530. int totlen = 0;
  531. title = av_metadata_get(s->metadata, "title", NULL, 0);
  532. author = av_metadata_get(s->metadata, "author", NULL, 0);
  533. album = av_metadata_get(s->metadata, "album", NULL, 0);
  534. genre = av_metadata_get(s->metadata, "genre", NULL, 0);
  535. copyright = av_metadata_get(s->metadata, "copyright", NULL, 0);
  536. track = av_metadata_get(s->metadata, "track", NULL, 0);
  537. year = av_metadata_get(s->metadata, "year", NULL, 0);
  538. if(title) totlen += 11 + strlen(title->value);
  539. if(author) totlen += 11 + strlen(author->value);
  540. if(album) totlen += 11 + strlen(album->value);
  541. if(genre) totlen += 11 + strlen(genre->value);
  542. if(copyright) totlen += 11 + strlen(copyright->value);
  543. if(track) totlen += 11 + strlen(track->value);
  544. if(year) totlen += 11 + strlen(year->value);
  545. if(!(s->streams[0]->codec->flags & CODEC_FLAG_BITEXACT))
  546. totlen += strlen(LIBAVFORMAT_IDENT) + 11;
  547. if(totlen == 0)
  548. return 0;
  549. put_be32(s->pb, MKBETAG('I', 'D', '3', 0x04)); /* ID3v2.4 */
  550. put_byte(s->pb, 0);
  551. put_byte(s->pb, 0); /* flags */
  552. id3v2_put_size(s, totlen);
  553. if(title) id3v2_put_ttag(s, title->value, MKBETAG('T', 'I', 'T', '2'));
  554. if(author) id3v2_put_ttag(s, author->value, MKBETAG('T', 'P', 'E', '1'));
  555. if(album) id3v2_put_ttag(s, album->value, MKBETAG('T', 'A', 'L', 'B'));
  556. if(genre) id3v2_put_ttag(s, genre->value, MKBETAG('T', 'C', 'O', 'N'));
  557. if(copyright) id3v2_put_ttag(s, copyright->value, MKBETAG('T', 'C', 'O', 'P'));
  558. if(track) id3v2_put_ttag(s, track->value, MKBETAG('T', 'R', 'C', 'K'));
  559. if(year) id3v2_put_ttag(s, year->value, MKBETAG('T', 'Y', 'E', 'R'));
  560. if(!(s->streams[0]->codec->flags & CODEC_FLAG_BITEXACT))
  561. id3v2_put_ttag(s, LIBAVFORMAT_IDENT, MKBETAG('T', 'E', 'N', 'C'));
  562. return 0;
  563. }
  564. static int mp3_write_packet(struct AVFormatContext *s, AVPacket *pkt)
  565. {
  566. put_buffer(s->pb, pkt->data, pkt->size);
  567. put_flush_packet(s->pb);
  568. return 0;
  569. }
  570. static int mp3_write_trailer(struct AVFormatContext *s)
  571. {
  572. uint8_t buf[ID3v1_TAG_SIZE];
  573. /* write the id3v1 tag */
  574. if (id3v1_create_tag(s, buf) > 0) {
  575. put_buffer(s->pb, buf, ID3v1_TAG_SIZE);
  576. put_flush_packet(s->pb);
  577. }
  578. return 0;
  579. }
  580. #endif /* CONFIG_MP2_MUXER || CONFIG_MP3_MUXER */
  581. #if CONFIG_MP3_DEMUXER
  582. AVInputFormat mp3_demuxer = {
  583. "mp3",
  584. NULL_IF_CONFIG_SMALL("MPEG audio layer 2/3"),
  585. 0,
  586. mp3_read_probe,
  587. mp3_read_header,
  588. mp3_read_packet,
  589. .flags= AVFMT_GENERIC_INDEX,
  590. .extensions = "mp2,mp3,m2a", /* XXX: use probe */
  591. };
  592. #endif
  593. #if CONFIG_MP2_MUXER
  594. AVOutputFormat mp2_muxer = {
  595. "mp2",
  596. NULL_IF_CONFIG_SMALL("MPEG audio layer 2"),
  597. "audio/x-mpeg",
  598. "mp2,m2a",
  599. 0,
  600. CODEC_ID_MP2,
  601. CODEC_ID_NONE,
  602. NULL,
  603. mp3_write_packet,
  604. mp3_write_trailer,
  605. };
  606. #endif
  607. #if CONFIG_MP3_MUXER
  608. AVOutputFormat mp3_muxer = {
  609. "mp3",
  610. NULL_IF_CONFIG_SMALL("MPEG audio layer 3"),
  611. "audio/x-mpeg",
  612. "mp3",
  613. 0,
  614. CODEC_ID_MP3,
  615. CODEC_ID_NONE,
  616. mp3_write_header,
  617. mp3_write_packet,
  618. mp3_write_trailer,
  619. };
  620. #endif