]> git.sesse.net Git - ffmpeg/blobdiff - libavformat/au.c
au: set stream start time and packet durations
[ffmpeg] / libavformat / au.c
index 5499c6bd75bb607a5692377523e5631a7585a7b2..670ec79e5928108affddf22476fc83cda65f4109 100644 (file)
@@ -57,6 +57,8 @@ static int au_probe(AVProbeData *p)
         return 0;
 }
 
+#define BLOCK_SIZE 1024
+
 /* au input */
 static int au_read_header(AVFormatContext *s)
 {
@@ -79,10 +81,15 @@ static int au_read_header(AVFormatContext *s)
     rate = avio_rb32(pb);
     channels = avio_rb32(pb);
 
+    if (size > 24) {
+        /* skip unused data */
+        avio_skip(pb, size - 24);
+    }
+
     codec = ff_codec_get_id(codec_au_tags, id);
 
     if (codec == AV_CODEC_ID_NONE) {
-        av_log_ask_for_sample(s, "unknown or unsupported codec tag: %d\n", id);
+        av_log_ask_for_sample(s, "unknown or unsupported codec tag: %u\n", id);
         return AVERROR_PATCHWELCOME;
     }
 
@@ -92,14 +99,14 @@ static int au_read_header(AVFormatContext *s)
         return AVERROR_PATCHWELCOME;
     }
 
-    if (channels == 0 || channels > 64) {
-        av_log(s, AV_LOG_ERROR, "Invalid number of channels %d\n", channels);
+    if (channels == 0 || channels >= INT_MAX / (BLOCK_SIZE * bps >> 3)) {
+        av_log(s, AV_LOG_ERROR, "Invalid number of channels %u\n", channels);
         return AVERROR_INVALIDDATA;
     }
 
-    if (size >= 24) {
-        /* skip unused data */
-        avio_skip(pb, size - 24);
+    if (rate == 0 || rate > INT_MAX) {
+        av_log(s, AV_LOG_ERROR, "Invalid sample rate: %u\n", rate);
+        return AVERROR_INVALIDDATA;
     }
 
     /* now we are ready: build format streams */
@@ -111,27 +118,26 @@ static int au_read_header(AVFormatContext *s)
     st->codec->codec_id = codec;
     st->codec->channels = channels;
     st->codec->sample_rate = rate;
+    st->codec->bit_rate    = channels * rate * bps;
+    st->codec->block_align = channels * bps >> 3;
+
+    st->start_time = 0;
     avpriv_set_pts_info(st, 64, 1, rate);
     return 0;
 }
 
-#define BLOCK_SIZE 1024
-
 static int au_read_packet(AVFormatContext *s,
                           AVPacket *pkt)
 {
     int ret;
 
-    ret= av_get_packet(s->pb, pkt, BLOCK_SIZE *
-                       s->streams[0]->codec->channels *
-                       av_get_bits_per_sample(s->streams[0]->codec->codec_id) >> 3);
+    ret = av_get_packet(s->pb, pkt, BLOCK_SIZE *
+                        s->streams[0]->codec->block_align);
     if (ret < 0)
         return ret;
     pkt->stream_index = 0;
+    pkt->duration     = ret / s->streams[0]->codec->block_align;
 
-    /* note: we need to modify the packet size here to handle the last
-       packet */
-    pkt->size = ret;
     return 0;
 }