]> git.sesse.net Git - ffmpeg/blobdiff - libavformat/au.c
Binary text decoder
[ffmpeg] / libavformat / au.c
index 23365c47342d6551d4aae58fdf1c43386424558d..477bcdb67f3914fae0cfa195bb33f469b84584e2 100644 (file)
@@ -120,7 +120,7 @@ static int au_probe(AVProbeData *p)
 static int au_read_header(AVFormatContext *s,
                           AVFormatParameters *ap)
 {
-    int size;
+    int size, bps, data_size = 0;
     unsigned int tag;
     AVIOContext *pb = s->pb;
     unsigned int id, channels, rate;
@@ -132,7 +132,12 @@ static int au_read_header(AVFormatContext *s,
     if (tag != MKTAG('.', 's', 'n', 'd'))
         return -1;
     size = avio_rb32(pb); /* header size */
-    avio_rb32(pb); /* data size */
+    data_size = avio_rb32(pb); /* data size in bytes */
+
+    if (data_size < 0 && data_size != AU_UNKNOWN_SIZE) {
+        av_log(s, AV_LOG_ERROR, "Invalid negative data size '%d' found\n", data_size);
+        return AVERROR_INVALIDDATA;
+    }
 
     id = avio_rb32(pb);
     rate = avio_rb32(pb);
@@ -140,7 +145,7 @@ static int au_read_header(AVFormatContext *s,
 
     codec = ff_codec_get_id(codec_au_tags, id);
 
-    if (!av_get_bits_per_sample(codec)) {
+    if (!(bps = av_get_bits_per_sample(codec))) {
         av_log_ask_for_sample(s, "could not determine bits per sample\n");
         return AVERROR_INVALIDDATA;
     }
@@ -159,6 +164,8 @@ static int au_read_header(AVFormatContext *s,
     st->codec->codec_id = codec;
     st->codec->channels = channels;
     st->codec->sample_rate = rate;
+    if (data_size != AU_UNKNOWN_SIZE)
+    st->duration = (((int64_t)data_size)<<3) / (st->codec->channels * bps);
     av_set_pts_info(st, 64, 1, rate);
     return 0;
 }
@@ -185,30 +192,27 @@ static int au_read_packet(AVFormatContext *s,
 
 #if CONFIG_AU_DEMUXER
 AVInputFormat ff_au_demuxer = {
-    "au",
-    NULL_IF_CONFIG_SMALL("SUN AU format"),
-    0,
-    au_probe,
-    au_read_header,
-    au_read_packet,
-    NULL,
-    pcm_read_seek,
+    .name           = "au",
+    .long_name      = NULL_IF_CONFIG_SMALL("SUN AU format"),
+    .read_probe     = au_probe,
+    .read_header    = au_read_header,
+    .read_packet    = au_read_packet,
+    .read_seek      = pcm_read_seek,
     .codec_tag= (const AVCodecTag* const []){codec_au_tags, 0},
 };
 #endif
 
 #if CONFIG_AU_MUXER
 AVOutputFormat ff_au_muxer = {
-    "au",
-    NULL_IF_CONFIG_SMALL("SUN AU format"),
-    "audio/basic",
-    "au",
-    0,
-    CODEC_ID_PCM_S16BE,
-    CODEC_ID_NONE,
-    au_write_header,
-    au_write_packet,
-    au_write_trailer,
+    .name              = "au",
+    .long_name         = NULL_IF_CONFIG_SMALL("SUN AU format"),
+    .mime_type         = "audio/basic",
+    .extensions        = "au",
+    .audio_codec       = CODEC_ID_PCM_S16BE,
+    .video_codec       = CODEC_ID_NONE,
+    .write_header      = au_write_header,
+    .write_packet      = au_write_packet,
+    .write_trailer     = au_write_trailer,
     .codec_tag= (const AVCodecTag* const []){codec_au_tags, 0},
 };
 #endif //CONFIG_AU_MUXER