]> git.sesse.net Git - ffmpeg/blobdiff - libavformat/au.c
fixing title on PSP (0x60 != 'a') someone needs a 10x10km ascii table ...
[ffmpeg] / libavformat / au.c
index b584d8d4f53f895f01175b254e9ab30c8952422b..2d603f5f77c85561a1dab381c9e18095c6e2bdaf 100644 (file)
@@ -1,4 +1,4 @@
-/* 
+/*
  * AU encoder and decoder
  * Copyright (c) 2001 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
  */
 
 /*
@@ -29,7 +29,7 @@
 #include "avi.h"
 
 /* if we don't know the size in advance */
-#define AU_UNKOWN_SIZE ((UINT32)(~0))
+#define AU_UNKOWN_SIZE ((uint32_t)(~0))
 
 /* The ffmpeg codecs we support, and the IDs they have in the file */
 static const CodecTag codec_au_tags[] = {
@@ -39,20 +39,20 @@ static const CodecTag codec_au_tags[] = {
     { 0, 0 },
 };
 
+#ifdef CONFIG_MUXERS
 /* AUDIO_FILE header */
 static int put_au_header(ByteIOContext *pb, AVCodecContext *enc)
 {
-    int tag;
-
-    tag = codec_get_tag(codec_au_tags, enc->codec_id);
-    if (tag == 0)
+    if(!enc->codec_tag)
+       enc->codec_tag = codec_get_tag(codec_au_tags, enc->codec_id);
+    if(!enc->codec_tag)
         return -1;
     put_tag(pb, ".snd");       /* magic number */
     put_be32(pb, 24);           /* header size */
     put_be32(pb, AU_UNKOWN_SIZE); /* data size */
-    put_be32(pb, (UINT32)tag);     /* codec ID */
+    put_be32(pb, (uint32_t)enc->codec_tag);     /* codec ID */
     put_be32(pb, enc->sample_rate);
-    put_be32(pb, (UINT32)enc->channels);
+    put_be32(pb, (uint32_t)enc->channels);
     return 0;
 }
 
@@ -63,7 +63,7 @@ static int au_write_header(AVFormatContext *s)
     s->priv_data = NULL;
 
     /* format header */
-    if (put_au_header(pb, &s->streams[0]->codec) < 0) {
+    if (put_au_header(pb, s->streams[0]->codec) < 0) {
         return -1;
     }
 
@@ -72,11 +72,10 @@ static int au_write_header(AVFormatContext *s)
     return 0;
 }
 
-static int au_write_packet(AVFormatContext *s, int stream_index_ptr,
-                           UINT8 *buf, int size, int force_pts)
+static int au_write_packet(AVFormatContext *s, AVPacket *pkt)
 {
     ByteIOContext *pb = &s->pb;
-    put_buffer(pb, buf, size);
+    put_buffer(pb, pkt->data, pkt->size);
     return 0;
 }
 
@@ -90,7 +89,7 @@ static int au_write_trailer(AVFormatContext *s)
         /* update file size */
         file_size = url_ftell(pb);
         url_fseek(pb, 8, SEEK_SET);
-        put_be32(pb, (UINT32)(file_size - 24));
+        put_be32(pb, (uint32_t)(file_size - 24));
         url_fseek(pb, file_size, SEEK_SET);
 
         put_flush_packet(pb);
@@ -98,6 +97,7 @@ static int au_write_trailer(AVFormatContext *s)
 
     return 0;
 }
+#endif //CONFIG_MUXERS
 
 static int au_probe(AVProbeData *p)
 {
@@ -113,7 +113,7 @@ static int au_probe(AVProbeData *p)
 
 /* au input */
 static int au_read_header(AVFormatContext *s,
-                           AVFormatParameters *ap)
+                          AVFormatParameters *ap)
 {
     int size;
     unsigned int tag;
@@ -127,11 +127,11 @@ static int au_read_header(AVFormatContext *s,
         return -1;
     size = get_be32(pb); /* header size */
     get_be32(pb); /* data size */
-    
+
     id = get_be32(pb);
     rate = get_be32(pb);
     channels = get_be32(pb);
-    
+
     codec = codec_get_id(codec_au_tags, id);
 
     if (size >= 24) {
@@ -140,21 +140,15 @@ static int au_read_header(AVFormatContext *s,
     }
 
     /* now we are ready: build format streams */
-    st = av_malloc(sizeof(AVStream));
+    st = av_new_stream(s, 0);
     if (!st)
         return -1;
-    avcodec_get_context_defaults(&st->codec);
-
-    s->nb_streams = 1;
-    s->streams[0] = st;
-
-    st->id = 0;
-    
-    st->codec.codec_type = CODEC_TYPE_AUDIO;
-    st->codec.codec_tag = id;
-    st->codec.codec_id = codec;
-    st->codec.channels = channels;
-    st->codec.sample_rate = rate;
+    st->codec->codec_type = CODEC_TYPE_AUDIO;
+    st->codec->codec_tag = id;
+    st->codec->codec_id = codec;
+    st->codec->channels = channels;
+    st->codec->sample_rate = rate;
+    av_set_pts_info(st, 64, 1, rate);
     return 0;
 }
 
@@ -166,14 +160,12 @@ static int au_read_packet(AVFormatContext *s,
     int ret;
 
     if (url_feof(&s->pb))
-        return -EIO;
-    if (av_new_packet(pkt, MAX_SIZE))
-        return -EIO;
+        return AVERROR_IO;
+    ret= av_get_packet(&s->pb, pkt, MAX_SIZE);
+    if (ret < 0)
+        return AVERROR_IO;
     pkt->stream_index = 0;
 
-    ret = get_buffer(&s->pb, pkt->data, pkt->size);
-    if (ret < 0)
-        av_free_packet(pkt);
     /* note: we need to modify the packet size here to handle the last
        packet */
     pkt->size = ret;
@@ -193,8 +185,10 @@ static AVInputFormat au_iformat = {
     au_read_header,
     au_read_packet,
     au_read_close,
+    pcm_read_seek,
 };
 
+#ifdef CONFIG_MUXERS
 static AVOutputFormat au_oformat = {
     "au",
     "SUN AU Format",
@@ -207,10 +201,13 @@ static AVOutputFormat au_oformat = {
     au_write_packet,
     au_write_trailer,
 };
+#endif //CONFIG_MUXERS
 
 int au_init(void)
 {
     av_register_input_format(&au_iformat);
+#ifdef CONFIG_MUXERS
     av_register_output_format(&au_oformat);
+#endif //CONFIG_MUXERS
     return 0;
 }