]> git.sesse.net Git - ffmpeg/blobdiff - libavformat/mp3.c
add common codecs uls
[ffmpeg] / libavformat / mp3.c
index ddc27dea6f8d7dfde8da834ed1bff27f7e6b0183..7b1a147a59ec8bd4a2170a7ee90c3dc14e502f58 100644 (file)
@@ -1,4 +1,4 @@
-/* 
+/*
  * MP3 encoder and decoder
  * Copyright (c) 2003 Fabrice Bellard.
  *
@@ -14,7 +14,7 @@
  *
  * You should have received a copy of the GNU Lesser General Public
  * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 #include "avformat.h"
 
@@ -166,7 +166,7 @@ static int id3_match(const uint8_t *buf)
             (buf[9] & 0x80) == 0);
 }
 
-static void id3_get_string(char *str, int str_size, 
+static void id3_get_string(char *str, int str_size,
                            const uint8_t *buf, int buf_size)
 {
     int i, c;
@@ -189,7 +189,7 @@ static int id3_parse_tag(AVFormatContext *s, const uint8_t *buf)
 {
     char str[5];
     int genre;
-    
+
     if (!(buf[0] == 'T' &&
           buf[1] == 'A' &&
           buf[2] == 'G'))
@@ -240,6 +240,32 @@ static void id3_create_tag(AVFormatContext *s, uint8_t *buf)
 }
 
 /* mp3 read */
+
+static int mp3_read_probe(AVProbeData *p)
+{
+    int d;
+
+    if(p->buf_size < 4)
+        return 0;
+
+    if(p->buf[0] == 'I' && p->buf[1] == 'D' && p->buf[2] == '3' &&
+       p->buf[3] < 5)
+        return AVPROBE_SCORE_MAX;
+
+    if(p->buf[0] != 0xff)
+        return 0;
+
+    d = p->buf[1];
+    if((d & 0xe0) != 0xe0 || ((d & 0x18) == 0x08 || (d & 0x06) == 0))
+        return 0;
+
+    d = p->buf[2];
+    if((d & 0xf0) == 0xf0 || (d & 0x0c) == 0x0c)
+        return 0;
+
+    return AVPROBE_SCORE_MAX;
+}
+
 static int mp3_read_header(AVFormatContext *s,
                            AVFormatParameters *ap)
 {
@@ -251,10 +277,10 @@ static int mp3_read_header(AVFormatContext *s,
     if (!st)
         return AVERROR_NOMEM;
 
-    st->codec.codec_type = CODEC_TYPE_AUDIO;
-    st->codec.codec_id = CODEC_ID_MP3;
+    st->codec->codec_type = CODEC_TYPE_AUDIO;
+    st->codec->codec_id = CODEC_ID_MP3;
     st->need_parsing = 1;
-    
+
     /* try to get the TAG */
     if (!url_is_streamed(&s->pb)) {
         /* XXX: change that */
@@ -294,7 +320,7 @@ static int mp3_read_packet(AVFormatContext *s, AVPacket *pkt)
 {
     int ret, size;
     //    AVStream *st = s->streams[0];
-    
+
     size= MP3_PACKET_SIZE;
 
     ret= av_get_packet(&s->pb, pkt, size);
@@ -314,7 +340,7 @@ static int mp3_read_close(AVFormatContext *s)
     return 0;
 }
 
-#ifdef CONFIG_ENCODERS
+#ifdef CONFIG_MUXERS
 /* simple formats */
 static int mp3_write_header(struct AVFormatContext *s)
 {
@@ -340,28 +366,29 @@ static int mp3_write_trailer(struct AVFormatContext *s)
     }
     return 0;
 }
-#endif //CONFIG_ENCODERS
+#endif //CONFIG_MUXERS
 
-AVInputFormat mp3_iformat = {
+#ifdef CONFIG_MP3_DEMUXER
+AVInputFormat mp3_demuxer = {
     "mp3",
     "MPEG audio",
     0,
-    NULL,
+    mp3_read_probe,
     mp3_read_header,
     mp3_read_packet,
     mp3_read_close,
-    .extensions = "mp2,mp3", /* XXX: use probe */
+    .extensions = "mp2,mp3,m2a", /* XXX: use probe */
 };
-
-#ifdef CONFIG_ENCODERS
-AVOutputFormat mp2_oformat = {
+#endif
+#ifdef CONFIG_MP2_MUXER
+AVOutputFormat mp2_muxer = {
     "mp2",
     "MPEG audio layer 2",
     "audio/x-mpeg",
 #ifdef CONFIG_MP3LAME
-    "mp2",
+    "mp2,m2a",
 #else
-    "mp2,mp3",
+    "mp2,mp3,m2a",
 #endif
     0,
     CODEC_ID_MP2,
@@ -370,9 +397,9 @@ AVOutputFormat mp2_oformat = {
     mp3_write_packet,
     mp3_write_trailer,
 };
-
-#ifdef CONFIG_MP3LAME
-AVOutputFormat mp3_oformat = {
+#endif
+#ifdef CONFIG_MP3_MUXER
+AVOutputFormat mp3_muxer = {
     "mp3",
     "MPEG audio layer 3",
     "audio/x-mpeg",
@@ -385,16 +412,3 @@ AVOutputFormat mp3_oformat = {
     mp3_write_trailer,
 };
 #endif
-#endif //CONFIG_ENCODERS
-
-int mp3_init(void)
-{
-    av_register_input_format(&mp3_iformat);
-#ifdef CONFIG_ENCODERS
-    av_register_output_format(&mp2_oformat);
-#ifdef CONFIG_MP3LAME
-    av_register_output_format(&mp3_oformat);
-#endif    
-#endif //CONFIG_ENCODERS
-    return 0;
-}